aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/6lowpan/nhc.c2
-rw-r--r--net/8021q/vlan.c18
-rw-r--r--net/8021q/vlan_dev.c26
-rw-r--r--net/8021q/vlan_netlink.c11
-rw-r--r--net/Kconfig7
-rw-r--r--net/appletalk/ddp.c8
-rw-r--r--net/atm/clip.c4
-rw-r--r--net/atm/ioctl.c16
-rw-r--r--net/atm/lec.c10
-rw-r--r--net/atm/pvc.c1
-rw-r--r--net/atm/svc.c1
-rw-r--r--net/ax25/af_ax25.c13
-rw-r--r--net/batman-adv/Kconfig24
-rw-r--r--net/batman-adv/Makefile15
-rw-r--r--net/batman-adv/bat_algo.c12
-rw-r--r--net/batman-adv/bat_algo.h12
-rw-r--r--net/batman-adv/bat_iv_ogm.c12
-rw-r--r--net/batman-adv/bat_iv_ogm.h12
-rw-r--r--net/batman-adv/bat_v.c12
-rw-r--r--net/batman-adv/bat_v.h12
-rw-r--r--net/batman-adv/bat_v_elp.c12
-rw-r--r--net/batman-adv/bat_v_elp.h12
-rw-r--r--net/batman-adv/bat_v_ogm.c12
-rw-r--r--net/batman-adv/bat_v_ogm.h12
-rw-r--r--net/batman-adv/bitarray.c12
-rw-r--r--net/batman-adv/bitarray.h12
-rw-r--r--net/batman-adv/bridge_loop_avoidance.c13
-rw-r--r--net/batman-adv/bridge_loop_avoidance.h12
-rw-r--r--net/batman-adv/debugfs.c12
-rw-r--r--net/batman-adv/debugfs.h12
-rw-r--r--net/batman-adv/distributed-arp-table.c40
-rw-r--r--net/batman-adv/distributed-arp-table.h12
-rw-r--r--net/batman-adv/fragmentation.c12
-rw-r--r--net/batman-adv/fragmentation.h12
-rw-r--r--net/batman-adv/gateway_client.c13
-rw-r--r--net/batman-adv/gateway_client.h12
-rw-r--r--net/batman-adv/gateway_common.c12
-rw-r--r--net/batman-adv/gateway_common.h12
-rw-r--r--net/batman-adv/hard-interface.c12
-rw-r--r--net/batman-adv/hard-interface.h12
-rw-r--r--net/batman-adv/hash.c12
-rw-r--r--net/batman-adv/hash.h12
-rw-r--r--net/batman-adv/icmp_socket.c14
-rw-r--r--net/batman-adv/icmp_socket.h12
-rw-r--r--net/batman-adv/log.c14
-rw-r--r--net/batman-adv/log.h12
-rw-r--r--net/batman-adv/main.c86
-rw-r--r--net/batman-adv/main.h16
-rw-r--r--net/batman-adv/multicast.c222
-rw-r--r--net/batman-adv/multicast.h30
-rw-r--r--net/batman-adv/netlink.c60
-rw-r--r--net/batman-adv/netlink.h12
-rw-r--r--net/batman-adv/network-coding.c12
-rw-r--r--net/batman-adv/network-coding.h12
-rw-r--r--net/batman-adv/originator.c12
-rw-r--r--net/batman-adv/originator.h12
-rw-r--r--net/batman-adv/routing.c12
-rw-r--r--net/batman-adv/routing.h12
-rw-r--r--net/batman-adv/send.c12
-rw-r--r--net/batman-adv/send.h12
-rw-r--r--net/batman-adv/soft-interface.c20
-rw-r--r--net/batman-adv/soft-interface.h12
-rw-r--r--net/batman-adv/sysfs.c128
-rw-r--r--net/batman-adv/sysfs.h50
-rw-r--r--net/batman-adv/tp_meter.c12
-rw-r--r--net/batman-adv/tp_meter.h12
-rw-r--r--net/batman-adv/trace.c12
-rw-r--r--net/batman-adv/trace.h12
-rw-r--r--net/batman-adv/translation-table.c17
-rw-r--r--net/batman-adv/translation-table.h16
-rw-r--r--net/batman-adv/tvlv.c12
-rw-r--r--net/batman-adv/tvlv.h12
-rw-r--r--net/batman-adv/types.h23
-rw-r--r--net/bluetooth/af_bluetooth.c8
-rw-r--r--net/bluetooth/amp.c1
-rw-r--r--net/bluetooth/hci_conn.c8
-rw-r--r--net/bluetooth/hci_core.c7
-rw-r--r--net/bluetooth/hci_event.c14
-rw-r--r--net/bluetooth/hci_request.c5
-rw-r--r--net/bluetooth/hci_request.h1
-rw-r--r--net/bluetooth/hidp/sock.c1
-rw-r--r--net/bluetooth/l2cap_core.c9
-rw-r--r--net/bluetooth/l2cap_sock.c8
-rw-r--r--net/bluetooth/mgmt.c11
-rw-r--r--net/bluetooth/rfcomm/sock.c1
-rw-r--r--net/bluetooth/sco.c5
-rw-r--r--net/bluetooth/smp.c1
-rw-r--r--net/bpf/Makefile2
-rw-r--r--net/bpf/test_run.c203
-rw-r--r--net/bridge/br.c14
-rw-r--r--net/bridge/br_arp_nd_proxy.c19
-rw-r--r--net/bridge/br_fdb.c1
-rw-r--r--net/bridge/br_forward.c15
-rw-r--r--net/bridge/br_if.c15
-rw-r--r--net/bridge/br_input.c100
-rw-r--r--net/bridge/br_mdb.c21
-rw-r--r--net/bridge/br_multicast.c30
-rw-r--r--net/bridge/br_netlink.c18
-rw-r--r--net/bridge/br_netlink_tunnel.c6
-rw-r--r--net/bridge/br_private.h35
-rw-r--r--net/bridge/br_stp_if.c3
-rw-r--r--net/bridge/br_vlan.c215
-rw-r--r--net/bridge/br_vlan_tunnel.c1
-rw-r--r--net/bridge/netfilter/ebtable_broute.c63
-rw-r--r--net/bridge/netfilter/ebtables.c14
-rw-r--r--net/caif/caif_dev.c12
-rw-r--r--net/can/af_can.c6
-rw-r--r--net/can/bcm.c1
-rw-r--r--net/can/gw.c4
-rw-r--r--net/can/raw.c1
-rw-r--r--net/ceph/osd_client.c2
-rw-r--r--net/ceph/pagevec.c2
-rw-r--r--net/compat.c57
-rw-r--r--net/core/Makefile1
-rw-r--r--net/core/bpf_sk_storage.c804
-rw-r--r--net/core/datagram.c29
-rw-r--r--net/core/datagram.h15
-rw-r--r--net/core/dev.c104
-rw-r--r--net/core/dev_ioctl.c3
-rw-r--r--net/core/devlink.c422
-rw-r--r--net/core/drop_monitor.c3
-rw-r--r--net/core/dst.c17
-rw-r--r--net/core/ethtool.c2
-rw-r--r--net/core/failover.c6
-rw-r--r--net/core/fib_rules.c12
-rw-r--r--net/core/filter.c581
-rw-r--r--net/core/flow_dissector.c133
-rw-r--r--net/core/gen_stats.c2
-rw-r--r--net/core/lwt_bpf.c10
-rw-r--r--net/core/lwtunnel.c9
-rw-r--r--net/core/neighbour.c43
-rw-r--r--net/core/net-procfs.c2
-rw-r--r--net/core/net-sysfs.c24
-rw-r--r--net/core/net_namespace.c21
-rw-r--r--net/core/netpoll.c6
-rw-r--r--net/core/netprio_cgroup.c2
-rw-r--r--net/core/pktgen.c2
-rw-r--r--net/core/ptp_classifier.c7
-rw-r--r--net/core/rtnetlink.c166
-rw-r--r--net/core/skbuff.c86
-rw-r--r--net/core/sock.c60
-rw-r--r--net/core/sock_reuseport.c2
-rw-r--r--net/core/sysctl_net_core.c8
-rw-r--r--net/dcb/dcbnl.c130
-rw-r--r--net/dccp/ipv4.c1
-rw-r--r--net/dccp/ipv6.c1
-rw-r--r--net/dccp/proto.c3
-rw-r--r--net/decnet/af_decnet.c2
-rw-r--r--net/decnet/dn_dev.c8
-rw-r--r--net/decnet/dn_fib.c10
-rw-r--r--net/decnet/dn_route.c4
-rw-r--r--net/decnet/dn_table.c3
-rw-r--r--net/dns_resolver/dns_query.c2
-rw-r--r--net/dsa/Kconfig109
-rw-r--r--net/dsa/Makefile22
-rw-r--r--net/dsa/dsa.c177
-rw-r--r--net/dsa/dsa2.c64
-rw-r--r--net/dsa/dsa_priv.h50
-rw-r--r--net/dsa/legacy.c745
-rw-r--r--net/dsa/port.c87
-rw-r--r--net/dsa/slave.c141
-rw-r--r--net/dsa/switch.c31
-rw-r--r--net/dsa/tag_8021q.c222
-rw-r--r--net/dsa/tag_brcm.c41
-rw-r--r--net/dsa/tag_dsa.c15
-rw-r--r--net/dsa/tag_edsa.c15
-rw-r--r--net/dsa/tag_gswip.c9
-rw-r--r--net/dsa/tag_ksz.c29
-rw-r--r--net/dsa/tag_lan9303.c20
-rw-r--r--net/dsa/tag_mtk.c18
-rw-r--r--net/dsa/tag_qca.c19
-rw-r--r--net/dsa/tag_sja1105.c131
-rw-r--r--net/dsa/tag_trailer.c15
-rw-r--r--net/ethernet/eth.c16
-rw-r--r--net/hsr/Makefile1
-rw-r--r--net/hsr/hsr_debugfs.c119
-rw-r--r--net/hsr/hsr_device.c66
-rw-r--r--net/hsr/hsr_device.h6
-rw-r--r--net/hsr/hsr_forward.c97
-rw-r--r--net/hsr/hsr_forward.h6
-rw-r--r--net/hsr/hsr_framereg.c127
-rw-r--r--net/hsr/hsr_framereg.h18
-rw-r--r--net/hsr/hsr_main.c16
-rw-r--r--net/hsr/hsr_main.h64
-rw-r--r--net/hsr/hsr_netlink.c64
-rw-r--r--net/hsr/hsr_netlink.h6
-rw-r--r--net/hsr/hsr_slave.c19
-rw-r--r--net/hsr/hsr_slave.h7
-rw-r--r--net/ieee802154/ieee802154.h2
-rw-r--r--net/ieee802154/netlink.c1
-rw-r--r--net/ieee802154/nl802154.c139
-rw-r--r--net/ieee802154/socket.c6
-rw-r--r--net/ipv4/Kconfig29
-rw-r--r--net/ipv4/Makefile3
-rw-r--r--net/ipv4/af_inet.c15
-rw-r--r--net/ipv4/bpfilter/sockopt.c3
-rw-r--r--net/ipv4/devinet.c27
-rw-r--r--net/ipv4/esp4.c20
-rw-r--r--net/ipv4/esp4_offload.c58
-rw-r--r--net/ipv4/fib_frontend.c89
-rw-r--r--net/ipv4/fib_lookup.h1
-rw-r--r--net/ipv4/fib_semantics.c1000
-rw-r--r--net/ipv4/fib_trie.c33
-rw-r--r--net/ipv4/fou.c157
-rw-r--r--net/ipv4/inet_connection_sock.c4
-rw-r--r--net/ipv4/ip_forward.c2
-rw-r--r--net/ipv4/ip_input.c11
-rw-r--r--net/ipv4/ip_output.c21
-rw-r--r--net/ipv4/ip_tunnel_core.c8
-rw-r--r--net/ipv4/ip_vti.c75
-rw-r--r--net/ipv4/ipmr.c21
-rw-r--r--net/ipv4/ipmr_base.c5
-rw-r--r--net/ipv4/netfilter/Kconfig20
-rw-r--r--net/ipv4/netfilter/Makefile2
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c2
-rw-r--r--net/ipv4/netfilter/nf_nat_h323.c2
-rw-r--r--net/ipv4/netfilter/nf_nat_pptp.c2
-rw-r--r--net/ipv4/netfilter/nft_chain_route_ipv4.c89
-rw-r--r--net/ipv4/raw.c4
-rw-r--r--net/ipv4/route.c259
-rw-r--r--net/ipv4/syncookies.c17
-rw-r--r--net/ipv4/sysctl_net_ipv4.c14
-rw-r--r--net/ipv4/tcp.c61
-rw-r--r--net/ipv4/tcp_dctcp.c45
-rw-r--r--net/ipv4/tcp_input.c137
-rw-r--r--net/ipv4/tcp_ipv4.c24
-rw-r--r--net/ipv4/tcp_metrics.c17
-rw-r--r--net/ipv4/tcp_minisocks.c5
-rw-r--r--net/ipv4/tcp_output.c19
-rw-r--r--net/ipv4/tcp_timer.c3
-rw-r--r--net/ipv4/udp.c19
-rw-r--r--net/ipv4/udp_offload.c16
-rw-r--r--net/ipv4/xfrm4_mode_beet.c155
-rw-r--r--net/ipv4/xfrm4_mode_transport.c114
-rw-r--r--net/ipv4/xfrm4_mode_tunnel.c152
-rw-r--r--net/ipv4/xfrm4_output.c27
-rw-r--r--net/ipv4/xfrm4_policy.c134
-rw-r--r--net/ipv4/xfrm4_protocol.c3
-rw-r--r--net/ipv6/Kconfig35
-rw-r--r--net/ipv6/Makefile4
-rw-r--r--net/ipv6/addrconf.c65
-rw-r--r--net/ipv6/addrconf_core.c40
-rw-r--r--net/ipv6/addrlabel.c14
-rw-r--r--net/ipv6/af_inet6.c24
-rw-r--r--net/ipv6/esp6_offload.c48
-rw-r--r--net/ipv6/fib6_rules.c53
-rw-r--r--net/ipv6/icmp.c59
-rw-r--r--net/ipv6/ila/ila_lwt.c3
-rw-r--r--net/ipv6/ila/ila_main.c9
-rw-r--r--net/ipv6/ip6_fib.c54
-rw-r--r--net/ipv6/ip6_flowlabel.c22
-rw-r--r--net/ipv6/ip6_input.c12
-rw-r--r--net/ipv6/ip6_output.c2
-rw-r--r--net/ipv6/ip6_vti.c6
-rw-r--r--net/ipv6/ip6mr.c1
-rw-r--r--net/ipv6/ndisc.c25
-rw-r--r--net/ipv6/netfilter/Kconfig19
-rw-r--r--net/ipv6/netfilter/Makefile2
-rw-r--r--net/ipv6/netfilter/ip6t_MASQUERADE.c81
-rw-r--r--net/ipv6/netfilter/nft_chain_route_ipv6.c91
-rw-r--r--net/ipv6/output_core.c30
-rw-r--r--net/ipv6/raw.c1
-rw-r--r--net/ipv6/route.c1221
-rw-r--r--net/ipv6/seg6.c9
-rw-r--r--net/ipv6/seg6_iptunnel.c4
-rw-r--r--net/ipv6/seg6_local.c11
-rw-r--r--net/ipv6/sit.c2
-rw-r--r--net/ipv6/tcp_ipv6.c62
-rw-r--r--net/ipv6/udp.c17
-rw-r--r--net/ipv6/xfrm6_mode_beet.c131
-rw-r--r--net/ipv6/xfrm6_mode_ro.c85
-rw-r--r--net/ipv6/xfrm6_mode_transport.c121
-rw-r--r--net/ipv6/xfrm6_mode_tunnel.c151
-rw-r--r--net/ipv6/xfrm6_output.c36
-rw-r--r--net/ipv6/xfrm6_policy.c126
-rw-r--r--net/ipv6/xfrm6_protocol.c3
-rw-r--r--net/ipv6/xfrm6_tunnel.c6
-rw-r--r--net/key/af_key.c4
-rw-r--r--net/l2tp/l2tp_core.c13
-rw-r--r--net/l2tp/l2tp_ip.c1
-rw-r--r--net/l2tp/l2tp_ip6.c1
-rw-r--r--net/l2tp/l2tp_netlink.c23
-rw-r--r--net/l2tp/l2tp_ppp.c3
-rw-r--r--net/llc/af_llc.c3
-rw-r--r--net/mac80211/cfg.c46
-rw-r--r--net/mac80211/debugfs.c54
-rw-r--r--net/mac80211/debugfs_netdev.c2
-rw-r--r--net/mac80211/driver-ops.c21
-rw-r--r--net/mac80211/driver-ops.h8
-rw-r--r--net/mac80211/ht.c5
-rw-r--r--net/mac80211/ieee80211_i.h9
-rw-r--r--net/mac80211/iface.c20
-rw-r--r--net/mac80211/key.c96
-rw-r--r--net/mac80211/key.h2
-rw-r--r--net/mac80211/main.c16
-rw-r--r--net/mac80211/mesh.h2
-rw-r--r--net/mac80211/mesh_hwmp.c34
-rw-r--r--net/mac80211/mesh_pathtbl.c4
-rw-r--r--net/mac80211/mlme.c3
-rw-r--r--net/mac80211/rc80211_minstrel_ht.c124
-rw-r--r--net/mac80211/rc80211_minstrel_ht.h2
-rw-r--r--net/mac80211/rx.c84
-rw-r--r--net/mac80211/sta_info.c15
-rw-r--r--net/mac80211/tdls.c2
-rw-r--r--net/mac80211/trace.h30
-rw-r--r--net/mac80211/trace_msg.h7
-rw-r--r--net/mac80211/tx.c166
-rw-r--r--net/mac80211/util.c162
-rw-r--r--net/mac80211/wme.c82
-rw-r--r--net/mac80211/wme.h2
-rw-r--r--net/mpls/af_mpls.c32
-rw-r--r--net/mpls/mpls_iptunnel.c16
-rw-r--r--net/ncsi/ncsi-netlink.c29
-rw-r--r--net/ncsi/ncsi-rsp.c6
-rw-r--r--net/netfilter/Kconfig19
-rw-r--r--net/netfilter/Makefile4
-rw-r--r--net/netfilter/core.c3
-rw-r--r--net/netfilter/ipset/ip_set_bitmap_gen.h14
-rw-r--r--net/netfilter/ipset/ip_set_core.c36
-rw-r--r--net/netfilter/ipset/ip_set_hash_gen.h14
-rw-r--r--net/netfilter/ipset/ip_set_list_set.c14
-rw-r--r--net/netfilter/ipvs/ip_vs_core.c2
-rw-r--r--net/netfilter/ipvs/ip_vs_ctl.c87
-rw-r--r--net/netfilter/ipvs/ip_vs_xmit.c84
-rw-r--r--net/netfilter/nf_conntrack_amanda.c8
-rw-r--r--net/netfilter/nf_conntrack_core.c43
-rw-r--r--net/netfilter/nf_conntrack_expect.c2
-rw-r--r--net/netfilter/nf_conntrack_ftp.c18
-rw-r--r--net/netfilter/nf_conntrack_h323_asn1.c2
-rw-r--r--net/netfilter/nf_conntrack_h323_main.c11
-rw-r--r--net/netfilter/nf_conntrack_helper.c86
-rw-r--r--net/netfilter/nf_conntrack_irc.c6
-rw-r--r--net/netfilter/nf_conntrack_netlink.c137
-rw-r--r--net/netfilter/nf_conntrack_proto.c2
-rw-r--r--net/netfilter/nf_conntrack_proto_dccp.c6
-rw-r--r--net/netfilter/nf_conntrack_proto_icmp.c93
-rw-r--r--net/netfilter/nf_conntrack_proto_icmpv6.c52
-rw-r--r--net/netfilter/nf_conntrack_proto_sctp.c6
-rw-r--r--net/netfilter/nf_conntrack_proto_tcp.c6
-rw-r--r--net/netfilter/nf_conntrack_sane.c12
-rw-r--r--net/netfilter/nf_conntrack_sip.c30
-rw-r--r--net/netfilter/nf_conntrack_standalone.c48
-rw-r--r--net/netfilter/nf_conntrack_tftp.c18
-rw-r--r--net/netfilter/nf_conntrack_timeout.c89
-rw-r--r--net/netfilter/nf_flow_table_core.c34
-rw-r--r--net/netfilter/nf_flow_table_ip.c16
-rw-r--r--net/netfilter/nf_internals.h3
-rw-r--r--net/netfilter/nf_nat_amanda.c9
-rw-r--r--net/netfilter/nf_nat_core.c34
-rw-r--r--net/netfilter/nf_nat_ftp.c9
-rw-r--r--net/netfilter/nf_nat_irc.c9
-rw-r--r--net/netfilter/nf_nat_masquerade.c104
-rw-r--r--net/netfilter/nf_nat_proto.c59
-rw-r--r--net/netfilter/nf_nat_sip.c9
-rw-r--r--net/netfilter/nf_nat_tftp.c9
-rw-r--r--net/netfilter/nf_queue.c1
-rw-r--r--net/netfilter/nf_tables_api.c155
-rw-r--r--net/netfilter/nf_tables_set_core.c1
-rw-r--r--net/netfilter/nfnetlink.c15
-rw-r--r--net/netfilter/nfnetlink_acct.c4
-rw-r--r--net/netfilter/nfnetlink_cthelper.c29
-rw-r--r--net/netfilter/nfnetlink_cttimeout.c11
-rw-r--r--net/netfilter/nfnetlink_log.c2
-rw-r--r--net/netfilter/nfnetlink_osf.c14
-rw-r--r--net/netfilter/nfnetlink_queue.c9
-rw-r--r--net/netfilter/nft_chain_nat.c36
-rw-r--r--net/netfilter/nft_chain_route.c169
-rw-r--r--net/netfilter/nft_compat.c4
-rw-r--r--net/netfilter/nft_ct.c18
-rw-r--r--net/netfilter/nft_dynset.c17
-rw-r--r--net/netfilter/nft_flow_offload.c4
-rw-r--r--net/netfilter/nft_masq.c83
-rw-r--r--net/netfilter/nft_nat.c58
-rw-r--r--net/netfilter/nft_osf.c30
-rw-r--r--net/netfilter/nft_redir.c63
-rw-r--r--net/netfilter/nft_tunnel.c27
-rw-r--r--net/netfilter/x_tables.c3
-rw-r--r--net/netfilter/xt_CT.c93
-rw-r--r--net/netfilter/xt_MASQUERADE.c (renamed from net/ipv4/netfilter/ipt_MASQUERADE.c)84
-rw-r--r--net/netfilter/xt_connlabel.c2
-rw-r--r--net/netfilter/xt_hashlimit.c3
-rw-r--r--net/netfilter/xt_time.c23
-rw-r--r--net/netlabel/netlabel_calipso.c9
-rw-r--r--net/netlabel/netlabel_cipso_v4.c59
-rw-r--r--net/netlabel/netlabel_mgmt.c25
-rw-r--r--net/netlabel/netlabel_unlabeled.c17
-rw-r--r--net/netlink/af_netlink.c3
-rw-r--r--net/netlink/genetlink.c52
-rw-r--r--net/netrom/af_netrom.c90
-rw-r--r--net/netrom/nr_loopback.c2
-rw-r--r--net/netrom/nr_route.c2
-rw-r--r--net/netrom/sysctl_net_netrom.c5
-rw-r--r--net/nfc/netlink.c55
-rw-r--r--net/openvswitch/actions.c48
-rw-r--r--net/openvswitch/conntrack.c97
-rw-r--r--net/openvswitch/datapath.c48
-rw-r--r--net/openvswitch/flow_netlink.c245
-rw-r--r--net/openvswitch/meter.c23
-rw-r--r--net/openvswitch/vport-vxlan.c6
-rw-r--r--net/openvswitch/vport.c2
-rw-r--r--net/packet/af_packet.c85
-rw-r--r--net/packet/diag.c2
-rw-r--r--net/phonet/pn_netlink.c8
-rw-r--r--net/psample/psample.c1
-rw-r--r--net/qrtr/qrtr.c14
-rw-r--r--net/rds/af_rds.c3
-rw-r--r--net/rds/bind.c2
-rw-r--r--net/rds/ib_fmr.c11
-rw-r--r--net/rds/ib_rdma.c3
-rw-r--r--net/rds/ib_recv.c8
-rw-r--r--net/rds/info.c2
-rw-r--r--net/rds/rdma.c3
-rw-r--r--net/rds/tcp.c2
-rw-r--r--net/rfkill/core.c2
-rw-r--r--net/rose/af_rose.c7
-rw-r--r--net/rose/rose_loopback.c27
-rw-r--r--net/rxrpc/af_rxrpc.c17
-rw-r--r--net/rxrpc/ar-internal.h1
-rw-r--r--net/rxrpc/call_object.c32
-rw-r--r--net/rxrpc/conn_event.c11
-rw-r--r--net/rxrpc/input.c30
-rw-r--r--net/rxrpc/local_object.c5
-rw-r--r--net/rxrpc/peer_event.c5
-rw-r--r--net/rxrpc/sendmsg.c21
-rw-r--r--net/sched/act_api.c40
-rw-r--r--net/sched/act_bpf.c3
-rw-r--r--net/sched/act_connmark.c4
-rw-r--r--net/sched/act_csum.c3
-rw-r--r--net/sched/act_gact.c3
-rw-r--r--net/sched/act_ife.c10
-rw-r--r--net/sched/act_ipt.c3
-rw-r--r--net/sched/act_mirred.c3
-rw-r--r--net/sched/act_nat.c3
-rw-r--r--net/sched/act_pedit.c13
-rw-r--r--net/sched/act_police.c55
-rw-r--r--net/sched/act_sample.c3
-rw-r--r--net/sched/act_simple.c3
-rw-r--r--net/sched/act_skbedit.c3
-rw-r--r--net/sched/act_skbmod.c3
-rw-r--r--net/sched/act_tunnel_key.c17
-rw-r--r--net/sched/act_vlan.c3
-rw-r--r--net/sched/cls_api.c39
-rw-r--r--net/sched/cls_basic.c6
-rw-r--r--net/sched/cls_bpf.c9
-rw-r--r--net/sched/cls_cgroup.c9
-rw-r--r--net/sched/cls_flow.c5
-rw-r--r--net/sched/cls_flower.c620
-rw-r--r--net/sched/cls_fw.c5
-rw-r--r--net/sched/cls_matchall.c65
-rw-r--r--net/sched/cls_route.c5
-rw-r--r--net/sched/cls_rsvp.h5
-rw-r--r--net/sched/cls_tcindex.c5
-rw-r--r--net/sched/cls_u32.c7
-rw-r--r--net/sched/em_ipt.c4
-rw-r--r--net/sched/em_meta.c3
-rw-r--r--net/sched/ematch.c7
-rw-r--r--net/sched/sch_api.c36
-rw-r--r--net/sched/sch_atm.c5
-rw-r--r--net/sched/sch_cake.c13
-rw-r--r--net/sched/sch_cbq.c10
-rw-r--r--net/sched/sch_cbs.c103
-rw-r--r--net/sched/sch_choke.c5
-rw-r--r--net/sched/sch_codel.c5
-rw-r--r--net/sched/sch_drr.c5
-rw-r--r--net/sched/sch_dsmark.c10
-rw-r--r--net/sched/sch_etf.c5
-rw-r--r--net/sched/sch_fq.c115
-rw-r--r--net/sched/sch_fq_codel.c6
-rw-r--r--net/sched/sch_generic.c72
-rw-r--r--net/sched/sch_gred.c25
-rw-r--r--net/sched/sch_hfsc.c5
-rw-r--r--net/sched/sch_hhf.c5
-rw-r--r--net/sched/sch_htb.c19
-rw-r--r--net/sched/sch_ingress.c2
-rw-r--r--net/sched/sch_mqprio.c9
-rw-r--r--net/sched/sch_netem.c7
-rw-r--r--net/sched/sch_pie.c5
-rw-r--r--net/sched/sch_qfq.c6
-rw-r--r--net/sched/sch_red.c5
-rw-r--r--net/sched/sch_sfb.c5
-rw-r--r--net/sched/sch_taprio.c747
-rw-r--r--net/sched/sch_tbf.c5
-rw-r--r--net/sctp/auth.c1
-rw-r--r--net/sctp/ipv6.c1
-rw-r--r--net/sctp/protocol.c1
-rw-r--r--net/sctp/sm_make_chunk.c2
-rw-r--r--net/sctp/sm_sideeffect.c29
-rw-r--r--net/sctp/sm_statefuns.c41
-rw-r--r--net/sctp/socket.c13
-rw-r--r--net/sctp/stream_interleave.c60
-rw-r--r--net/sctp/ulpevent.c19
-rw-r--r--net/sctp/ulpqueue.c53
-rw-r--r--net/smc/af_smc.c413
-rw-r--r--net/smc/smc.h11
-rw-r--r--net/smc/smc_clc.c10
-rw-r--r--net/smc/smc_clc.h20
-rw-r--r--net/smc/smc_close.c25
-rw-r--r--net/smc/smc_close.h1
-rw-r--r--net/smc/smc_core.c93
-rw-r--r--net/smc/smc_core.h25
-rw-r--r--net/smc/smc_ism.c5
-rw-r--r--net/smc/smc_pnet.c59
-rw-r--r--net/smc/smc_pnet.h7
-rw-r--r--net/socket.c85
-rw-r--r--net/strparser/strparser.c28
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c71
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_crypto.c2
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_mech.c1
-rw-r--r--net/sunrpc/auth_unix.c9
-rw-r--r--net/sunrpc/cache.c3
-rw-r--r--net/sunrpc/clnt.c139
-rw-r--r--net/sunrpc/debugfs.c2
-rw-r--r--net/sunrpc/rpc_pipe.c11
-rw-r--r--net/sunrpc/rpcb_clnt.c12
-rw-r--r--net/sunrpc/sched.c158
-rw-r--r--net/sunrpc/socklib.c2
-rw-r--r--net/sunrpc/xprt.c154
-rw-r--r--net/sunrpc/xprtrdma/backchannel.c120
-rw-r--r--net/sunrpc/xprtrdma/frwr_ops.c63
-rw-r--r--net/sunrpc/xprtrdma/rpc_rdma.c115
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_backchannel.c2
-rw-r--r--net/sunrpc/xprtrdma/transport.c105
-rw-r--r--net/sunrpc/xprtrdma/verbs.c338
-rw-r--r--net/sunrpc/xprtrdma/xprt_rdma.h121
-rw-r--r--net/sunrpc/xprtsock.c9
-rw-r--r--net/tipc/bcast.c275
-rw-r--r--net/tipc/bcast.h12
-rw-r--r--net/tipc/bearer.c50
-rw-r--r--net/tipc/core.c2
-rw-r--r--net/tipc/core.h3
-rw-r--r--net/tipc/group.c2
-rw-r--r--net/tipc/link.c327
-rw-r--r--net/tipc/link.h2
-rw-r--r--net/tipc/monitor.c4
-rw-r--r--net/tipc/msg.h62
-rw-r--r--net/tipc/name_table.c7
-rw-r--r--net/tipc/net.c8
-rw-r--r--net/tipc/netlink.c51
-rw-r--r--net/tipc/netlink_compat.c88
-rw-r--r--net/tipc/node.c119
-rw-r--r--net/tipc/node.h8
-rw-r--r--net/tipc/socket.c29
-rw-r--r--net/tipc/sysctl.c8
-rw-r--r--net/tipc/udp_media.c27
-rw-r--r--net/tls/tls_device.c105
-rw-r--r--net/tls/tls_device_fallback.c16
-rw-r--r--net/tls/tls_main.c60
-rw-r--r--net/tls/tls_sw.c121
-rw-r--r--net/unix/af_unix.c6
-rw-r--r--net/wimax/stack.c9
-rw-r--r--net/wireless/lib80211_crypt_tkip.c1
-rw-r--r--net/wireless/nl80211.c941
-rw-r--r--net/wireless/pmsr.c30
-rw-r--r--net/wireless/rdev-ops.h29
-rw-r--r--net/wireless/reg.c67
-rw-r--r--net/wireless/scan.c176
-rw-r--r--net/wireless/trace.h87
-rw-r--r--net/wireless/util.c27
-rw-r--r--net/wireless/wext-compat.c3
-rw-r--r--net/x25/af_x25.c27
-rw-r--r--net/xdp/xdp_umem.c4
-rw-r--r--net/xdp/xsk_queue.h56
-rw-r--r--net/xfrm/Kconfig8
-rw-r--r--net/xfrm/xfrm_device.c63
-rw-r--r--net/xfrm/xfrm_inout.h38
-rw-r--r--net/xfrm/xfrm_input.c299
-rw-r--r--net/xfrm/xfrm_interface.c23
-rw-r--r--net/xfrm/xfrm_output.c381
-rw-r--r--net/xfrm/xfrm_policy.c282
-rw-r--r--net/xfrm/xfrm_state.c218
-rw-r--r--net/xfrm/xfrm_user.c26
571 files changed, 16157 insertions, 10563 deletions
diff --git a/net/6lowpan/nhc.c b/net/6lowpan/nhc.c
index 4fa2fdda174d..9e56fb98f33c 100644
--- a/net/6lowpan/nhc.c
+++ b/net/6lowpan/nhc.c
@@ -18,7 +18,7 @@
18#include "nhc.h" 18#include "nhc.h"
19 19
20static struct rb_root rb_root = RB_ROOT; 20static struct rb_root rb_root = RB_ROOT;
21static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX]; 21static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX + 1];
22static DEFINE_SPINLOCK(lowpan_nhc_lock); 22static DEFINE_SPINLOCK(lowpan_nhc_lock);
23 23
24static int lowpan_nhc_insert(struct lowpan_nhc *nhc) 24static int lowpan_nhc_insert(struct lowpan_nhc *nhc)
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index dc4411165e43..1f99678751df 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -75,6 +75,14 @@ static int vlan_group_prealloc_vid(struct vlan_group *vg,
75 return 0; 75 return 0;
76} 76}
77 77
78static void vlan_stacked_transfer_operstate(const struct net_device *rootdev,
79 struct net_device *dev,
80 struct vlan_dev_priv *vlan)
81{
82 if (!(vlan->flags & VLAN_FLAG_BRIDGE_BINDING))
83 netif_stacked_transfer_operstate(rootdev, dev);
84}
85
78void unregister_vlan_dev(struct net_device *dev, struct list_head *head) 86void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
79{ 87{
80 struct vlan_dev_priv *vlan = vlan_dev_priv(dev); 88 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
@@ -180,7 +188,7 @@ int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack)
180 /* Account for reference in struct vlan_dev_priv */ 188 /* Account for reference in struct vlan_dev_priv */
181 dev_hold(real_dev); 189 dev_hold(real_dev);
182 190
183 netif_stacked_transfer_operstate(real_dev, dev); 191 vlan_stacked_transfer_operstate(real_dev, dev, vlan);
184 linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */ 192 linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */
185 193
186 /* So, got the sucker initialized, now lets place 194 /* So, got the sucker initialized, now lets place
@@ -399,7 +407,8 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
399 case NETDEV_CHANGE: 407 case NETDEV_CHANGE:
400 /* Propagate real device state to vlan devices */ 408 /* Propagate real device state to vlan devices */
401 vlan_group_for_each_dev(grp, i, vlandev) 409 vlan_group_for_each_dev(grp, i, vlandev)
402 netif_stacked_transfer_operstate(dev, vlandev); 410 vlan_stacked_transfer_operstate(dev, vlandev,
411 vlan_dev_priv(vlandev));
403 break; 412 break;
404 413
405 case NETDEV_CHANGEADDR: 414 case NETDEV_CHANGEADDR:
@@ -446,7 +455,8 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
446 dev_close_many(&close_list, false); 455 dev_close_many(&close_list, false);
447 456
448 list_for_each_entry_safe(vlandev, tmp, &close_list, close_list) { 457 list_for_each_entry_safe(vlandev, tmp, &close_list, close_list) {
449 netif_stacked_transfer_operstate(dev, vlandev); 458 vlan_stacked_transfer_operstate(dev, vlandev,
459 vlan_dev_priv(vlandev));
450 list_del_init(&vlandev->close_list); 460 list_del_init(&vlandev->close_list);
451 } 461 }
452 list_del(&close_list); 462 list_del(&close_list);
@@ -463,7 +473,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
463 if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING)) 473 if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
464 dev_change_flags(vlandev, flgs | IFF_UP, 474 dev_change_flags(vlandev, flgs | IFF_UP,
465 extack); 475 extack);
466 netif_stacked_transfer_operstate(dev, vlandev); 476 vlan_stacked_transfer_operstate(dev, vlandev, vlan);
467 } 477 }
468 break; 478 break;
469 479
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 8d77b6ee4477..2a9a60733594 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -223,7 +223,8 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask)
223 u32 old_flags = vlan->flags; 223 u32 old_flags = vlan->flags;
224 224
225 if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP | 225 if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
226 VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP)) 226 VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP |
227 VLAN_FLAG_BRIDGE_BINDING))
227 return -EINVAL; 228 return -EINVAL;
228 229
229 vlan->flags = (old_flags & ~mask) | (flags & mask); 230 vlan->flags = (old_flags & ~mask) | (flags & mask);
@@ -296,7 +297,8 @@ static int vlan_dev_open(struct net_device *dev)
296 if (vlan->flags & VLAN_FLAG_MVRP) 297 if (vlan->flags & VLAN_FLAG_MVRP)
297 vlan_mvrp_request_join(dev); 298 vlan_mvrp_request_join(dev);
298 299
299 if (netif_carrier_ok(real_dev)) 300 if (netif_carrier_ok(real_dev) &&
301 !(vlan->flags & VLAN_FLAG_BRIDGE_BINDING))
300 netif_carrier_on(dev); 302 netif_carrier_on(dev);
301 return 0; 303 return 0;
302 304
@@ -326,7 +328,8 @@ static int vlan_dev_stop(struct net_device *dev)
326 if (!ether_addr_equal(dev->dev_addr, real_dev->dev_addr)) 328 if (!ether_addr_equal(dev->dev_addr, real_dev->dev_addr))
327 dev_uc_del(real_dev, dev->dev_addr); 329 dev_uc_del(real_dev, dev->dev_addr);
328 330
329 netif_carrier_off(dev); 331 if (!(vlan->flags & VLAN_FLAG_BRIDGE_BINDING))
332 netif_carrier_off(dev);
330 return 0; 333 return 0;
331} 334}
332 335
@@ -367,10 +370,12 @@ static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
367 ifrr.ifr_ifru = ifr->ifr_ifru; 370 ifrr.ifr_ifru = ifr->ifr_ifru;
368 371
369 switch (cmd) { 372 switch (cmd) {
373 case SIOCSHWTSTAMP:
374 if (!net_eq(dev_net(dev), &init_net))
375 break;
370 case SIOCGMIIPHY: 376 case SIOCGMIIPHY:
371 case SIOCGMIIREG: 377 case SIOCGMIIREG:
372 case SIOCSMIIREG: 378 case SIOCSMIIREG:
373 case SIOCSHWTSTAMP:
374 case SIOCGHWTSTAMP: 379 case SIOCGHWTSTAMP:
375 if (netif_device_present(real_dev) && ops->ndo_do_ioctl) 380 if (netif_device_present(real_dev) && ops->ndo_do_ioctl)
376 err = ops->ndo_do_ioctl(real_dev, &ifrr, cmd); 381 err = ops->ndo_do_ioctl(real_dev, &ifrr, cmd);
@@ -550,7 +555,8 @@ static const struct net_device_ops vlan_netdev_ops;
550 555
551static int vlan_dev_init(struct net_device *dev) 556static int vlan_dev_init(struct net_device *dev)
552{ 557{
553 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev; 558 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
559 struct net_device *real_dev = vlan->real_dev;
554 560
555 netif_carrier_off(dev); 561 netif_carrier_off(dev);
556 562
@@ -561,6 +567,9 @@ static int vlan_dev_init(struct net_device *dev)
561 (1<<__LINK_STATE_DORMANT))) | 567 (1<<__LINK_STATE_DORMANT))) |
562 (1<<__LINK_STATE_PRESENT); 568 (1<<__LINK_STATE_PRESENT);
563 569
570 if (vlan->flags & VLAN_FLAG_BRIDGE_BINDING)
571 dev->state |= (1 << __LINK_STATE_NOCARRIER);
572
564 dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG | 573 dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG |
565 NETIF_F_FRAGLIST | NETIF_F_GSO_SOFTWARE | 574 NETIF_F_FRAGLIST | NETIF_F_GSO_SOFTWARE |
566 NETIF_F_GSO_ENCAP_ALL | 575 NETIF_F_GSO_ENCAP_ALL |
@@ -591,8 +600,7 @@ static int vlan_dev_init(struct net_device *dev)
591#endif 600#endif
592 601
593 dev->needed_headroom = real_dev->needed_headroom; 602 dev->needed_headroom = real_dev->needed_headroom;
594 if (vlan_hw_offload_capable(real_dev->features, 603 if (vlan_hw_offload_capable(real_dev->features, vlan->vlan_proto)) {
595 vlan_dev_priv(dev)->vlan_proto)) {
596 dev->header_ops = &vlan_passthru_header_ops; 604 dev->header_ops = &vlan_passthru_header_ops;
597 dev->hard_header_len = real_dev->hard_header_len; 605 dev->hard_header_len = real_dev->hard_header_len;
598 } else { 606 } else {
@@ -606,8 +614,8 @@ static int vlan_dev_init(struct net_device *dev)
606 614
607 vlan_dev_set_lockdep_class(dev, vlan_dev_get_lock_subclass(dev)); 615 vlan_dev_set_lockdep_class(dev, vlan_dev_get_lock_subclass(dev));
608 616
609 vlan_dev_priv(dev)->vlan_pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats); 617 vlan->vlan_pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
610 if (!vlan_dev_priv(dev)->vlan_pcpu_stats) 618 if (!vlan->vlan_pcpu_stats)
611 return -ENOMEM; 619 return -ENOMEM;
612 620
613 return 0; 621 return 0;
diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
index 9b60c1e399e2..24eebbc92364 100644
--- a/net/8021q/vlan_netlink.c
+++ b/net/8021q/vlan_netlink.c
@@ -35,8 +35,8 @@ static inline int vlan_validate_qos_map(struct nlattr *attr)
35{ 35{
36 if (!attr) 36 if (!attr)
37 return 0; 37 return 0;
38 return nla_validate_nested(attr, IFLA_VLAN_QOS_MAX, vlan_map_policy, 38 return nla_validate_nested_deprecated(attr, IFLA_VLAN_QOS_MAX,
39 NULL); 39 vlan_map_policy, NULL);
40} 40}
41 41
42static int vlan_validate(struct nlattr *tb[], struct nlattr *data[], 42static int vlan_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -84,7 +84,8 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[],
84 flags = nla_data(data[IFLA_VLAN_FLAGS]); 84 flags = nla_data(data[IFLA_VLAN_FLAGS]);
85 if ((flags->flags & flags->mask) & 85 if ((flags->flags & flags->mask) &
86 ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP | 86 ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
87 VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP)) { 87 VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP |
88 VLAN_FLAG_BRIDGE_BINDING)) {
88 NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN flags"); 89 NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN flags");
89 return -EINVAL; 90 return -EINVAL;
90 } 91 }
@@ -226,7 +227,7 @@ static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
226 goto nla_put_failure; 227 goto nla_put_failure;
227 } 228 }
228 if (vlan->nr_ingress_mappings) { 229 if (vlan->nr_ingress_mappings) {
229 nest = nla_nest_start(skb, IFLA_VLAN_INGRESS_QOS); 230 nest = nla_nest_start_noflag(skb, IFLA_VLAN_INGRESS_QOS);
230 if (nest == NULL) 231 if (nest == NULL)
231 goto nla_put_failure; 232 goto nla_put_failure;
232 233
@@ -244,7 +245,7 @@ static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
244 } 245 }
245 246
246 if (vlan->nr_egress_mappings) { 247 if (vlan->nr_egress_mappings) {
247 nest = nla_nest_start(skb, IFLA_VLAN_EGRESS_QOS); 248 nest = nla_nest_start_noflag(skb, IFLA_VLAN_EGRESS_QOS);
248 if (nest == NULL) 249 if (nest == NULL)
249 goto nla_put_failure; 250 goto nla_put_failure;
250 251
diff --git a/net/Kconfig b/net/Kconfig
index 1efe1f9ee492..3e8fdd688329 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -429,11 +429,8 @@ config NET_SOCK_MSG
429 with the help of BPF programs. 429 with the help of BPF programs.
430 430
431config NET_DEVLINK 431config NET_DEVLINK
432 bool "Network physical/parent device Netlink interface" 432 bool
433 help 433 default n
434 Network physical/parent device Netlink interface provides
435 infrastructure to support access to physical chip-wide config and
436 monitoring.
437 434
438config PAGE_POOL 435config PAGE_POOL
439 bool 436 bool
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index 709d2542f729..a2555023c654 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -1806,12 +1806,6 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1806 rc = put_user(amount, (int __user *)argp); 1806 rc = put_user(amount, (int __user *)argp);
1807 break; 1807 break;
1808 } 1808 }
1809 case SIOCGSTAMP:
1810 rc = sock_get_timestamp(sk, argp);
1811 break;
1812 case SIOCGSTAMPNS:
1813 rc = sock_get_timestampns(sk, argp);
1814 break;
1815 /* Routing */ 1809 /* Routing */
1816 case SIOCADDRT: 1810 case SIOCADDRT:
1817 case SIOCDELRT: 1811 case SIOCDELRT:
@@ -1871,6 +1865,7 @@ static const struct proto_ops atalk_dgram_ops = {
1871 .getname = atalk_getname, 1865 .getname = atalk_getname,
1872 .poll = datagram_poll, 1866 .poll = datagram_poll,
1873 .ioctl = atalk_ioctl, 1867 .ioctl = atalk_ioctl,
1868 .gettstamp = sock_gettstamp,
1874#ifdef CONFIG_COMPAT 1869#ifdef CONFIG_COMPAT
1875 .compat_ioctl = atalk_compat_ioctl, 1870 .compat_ioctl = atalk_compat_ioctl,
1876#endif 1871#endif
@@ -1920,6 +1915,7 @@ static int __init atalk_init(void)
1920 ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv); 1915 ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
1921 if (!ddp_dl) { 1916 if (!ddp_dl) {
1922 pr_crit("Unable to register DDP with SNAP.\n"); 1917 pr_crit("Unable to register DDP with SNAP.\n");
1918 rc = -ENOMEM;
1923 goto out_sock; 1919 goto out_sock;
1924 } 1920 }
1925 1921
diff --git a/net/atm/clip.c b/net/atm/clip.c
index d795b9c5aea4..b9e67e589a7b 100644
--- a/net/atm/clip.c
+++ b/net/atm/clip.c
@@ -345,8 +345,8 @@ static netdev_tx_t clip_start_xmit(struct sk_buff *skb,
345 return NETDEV_TX_OK; 345 return NETDEV_TX_OK;
346 } 346 }
347 rt = (struct rtable *) dst; 347 rt = (struct rtable *) dst;
348 if (rt->rt_gateway) 348 if (rt->rt_gw_family == AF_INET)
349 daddr = &rt->rt_gateway; 349 daddr = &rt->rt_gw4;
350 else 350 else
351 daddr = &ip_hdr(skb)->daddr; 351 daddr = &ip_hdr(skb)->daddr;
352 n = dst_neigh_lookup(dst, daddr); 352 n = dst_neigh_lookup(dst, daddr);
diff --git a/net/atm/ioctl.c b/net/atm/ioctl.c
index 2ff0e5e470e3..d955b683aa7c 100644
--- a/net/atm/ioctl.c
+++ b/net/atm/ioctl.c
@@ -81,22 +81,6 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,
81 (int __user *)argp) ? -EFAULT : 0; 81 (int __user *)argp) ? -EFAULT : 0;
82 goto done; 82 goto done;
83 } 83 }
84 case SIOCGSTAMP: /* borrowed from IP */
85#ifdef CONFIG_COMPAT
86 if (compat)
87 error = compat_sock_get_timestamp(sk, argp);
88 else
89#endif
90 error = sock_get_timestamp(sk, argp);
91 goto done;
92 case SIOCGSTAMPNS: /* borrowed from IP */
93#ifdef CONFIG_COMPAT
94 if (compat)
95 error = compat_sock_get_timestampns(sk, argp);
96 else
97#endif
98 error = sock_get_timestampns(sk, argp);
99 goto done;
100 case ATM_SETSC: 84 case ATM_SETSC:
101 net_warn_ratelimited("ATM_SETSC is obsolete; used by %s:%d\n", 85 net_warn_ratelimited("ATM_SETSC is obsolete; used by %s:%d\n",
102 current->comm, task_pid_nr(current)); 86 current->comm, task_pid_nr(current));
diff --git a/net/atm/lec.c b/net/atm/lec.c
index d7f5cf5b7594..a0311493b01b 100644
--- a/net/atm/lec.c
+++ b/net/atm/lec.c
@@ -710,7 +710,10 @@ static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
710 710
711static int lec_mcast_attach(struct atm_vcc *vcc, int arg) 711static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
712{ 712{
713 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg]) 713 if (arg < 0 || arg >= MAX_LEC_ITF)
714 return -EINVAL;
715 arg = array_index_nospec(arg, MAX_LEC_ITF);
716 if (!dev_lec[arg])
714 return -EINVAL; 717 return -EINVAL;
715 vcc->proto_data = dev_lec[arg]; 718 vcc->proto_data = dev_lec[arg];
716 return lec_mcast_make(netdev_priv(dev_lec[arg]), vcc); 719 return lec_mcast_make(netdev_priv(dev_lec[arg]), vcc);
@@ -723,11 +726,10 @@ static int lecd_attach(struct atm_vcc *vcc, int arg)
723 struct lec_priv *priv; 726 struct lec_priv *priv;
724 727
725 if (arg < 0) 728 if (arg < 0)
726 i = 0; 729 arg = 0;
727 else
728 i = arg;
729 if (arg >= MAX_LEC_ITF) 730 if (arg >= MAX_LEC_ITF)
730 return -EINVAL; 731 return -EINVAL;
732 i = array_index_nospec(arg, MAX_LEC_ITF);
731 if (!dev_lec[i]) { 733 if (!dev_lec[i]) {
732 int size; 734 int size;
733 735
diff --git a/net/atm/pvc.c b/net/atm/pvc.c
index 2cb10af16afc..02bd2a436bdf 100644
--- a/net/atm/pvc.c
+++ b/net/atm/pvc.c
@@ -118,6 +118,7 @@ static const struct proto_ops pvc_proto_ops = {
118#ifdef CONFIG_COMPAT 118#ifdef CONFIG_COMPAT
119 .compat_ioctl = vcc_compat_ioctl, 119 .compat_ioctl = vcc_compat_ioctl,
120#endif 120#endif
121 .gettstamp = sock_gettstamp,
121 .listen = sock_no_listen, 122 .listen = sock_no_listen,
122 .shutdown = pvc_shutdown, 123 .shutdown = pvc_shutdown,
123 .setsockopt = pvc_setsockopt, 124 .setsockopt = pvc_setsockopt,
diff --git a/net/atm/svc.c b/net/atm/svc.c
index 2f91b766ac42..908cbb8654f5 100644
--- a/net/atm/svc.c
+++ b/net/atm/svc.c
@@ -641,6 +641,7 @@ static const struct proto_ops svc_proto_ops = {
641#ifdef CONFIG_COMPAT 641#ifdef CONFIG_COMPAT
642 .compat_ioctl = svc_compat_ioctl, 642 .compat_ioctl = svc_compat_ioctl,
643#endif 643#endif
644 .gettstamp = sock_gettstamp,
644 .listen = svc_listen, 645 .listen = svc_listen,
645 .shutdown = svc_shutdown, 646 .shutdown = svc_shutdown,
646 .setsockopt = svc_setsockopt, 647 .setsockopt = svc_setsockopt,
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index 5d01edf8d819..012c0b6fc4f6 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -1714,14 +1714,6 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1714 break; 1714 break;
1715 } 1715 }
1716 1716
1717 case SIOCGSTAMP:
1718 res = sock_get_timestamp(sk, argp);
1719 break;
1720
1721 case SIOCGSTAMPNS:
1722 res = sock_get_timestampns(sk, argp);
1723 break;
1724
1725 case SIOCAX25ADDUID: /* Add a uid to the uid/call map table */ 1717 case SIOCAX25ADDUID: /* Add a uid to the uid/call map table */
1726 case SIOCAX25DELUID: /* Delete a uid from the uid/call map table */ 1718 case SIOCAX25DELUID: /* Delete a uid from the uid/call map table */
1727 case SIOCAX25GETUID: { 1719 case SIOCAX25GETUID: {
@@ -1888,8 +1880,8 @@ static int ax25_info_show(struct seq_file *seq, void *v)
1888 * magic dev src_addr dest_addr,digi1,digi2,.. st vs vr va t1 t1 t2 t2 t3 t3 idle idle n2 n2 rtt window paclen Snd-Q Rcv-Q inode 1880 * magic dev src_addr dest_addr,digi1,digi2,.. st vs vr va t1 t1 t2 t2 t3 t3 idle idle n2 n2 rtt window paclen Snd-Q Rcv-Q inode
1889 */ 1881 */
1890 1882
1891 seq_printf(seq, "%8.8lx %s %s%s ", 1883 seq_printf(seq, "%p %s %s%s ",
1892 (long) ax25, 1884 ax25,
1893 ax25->ax25_dev == NULL? "???" : ax25->ax25_dev->dev->name, 1885 ax25->ax25_dev == NULL? "???" : ax25->ax25_dev->dev->name,
1894 ax2asc(buf, &ax25->source_addr), 1886 ax2asc(buf, &ax25->source_addr),
1895 ax25->iamdigi? "*":""); 1887 ax25->iamdigi? "*":"");
@@ -1950,6 +1942,7 @@ static const struct proto_ops ax25_proto_ops = {
1950 .getname = ax25_getname, 1942 .getname = ax25_getname,
1951 .poll = datagram_poll, 1943 .poll = datagram_poll,
1952 .ioctl = ax25_ioctl, 1944 .ioctl = ax25_ioctl,
1945 .gettstamp = sock_gettstamp,
1953 .listen = ax25_listen, 1946 .listen = ax25_listen,
1954 .shutdown = ax25_shutdown, 1947 .shutdown = ax25_shutdown,
1955 .setsockopt = ax25_setsockopt, 1948 .setsockopt = ax25_setsockopt,
diff --git a/net/batman-adv/Kconfig b/net/batman-adv/Kconfig
index a31db5e9ac8e..a3d188dfbe75 100644
--- a/net/batman-adv/Kconfig
+++ b/net/batman-adv/Kconfig
@@ -2,18 +2,6 @@
2# Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2# Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3# 3#
4# Marek Lindner, Simon Wunderlich 4# Marek Lindner, Simon Wunderlich
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of version 2 of the GNU General Public
8# License as published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, see <http://www.gnu.org/licenses/>.
17 5
18# 6#
19# B.A.T.M.A.N meshing protocol 7# B.A.T.M.A.N meshing protocol
@@ -109,6 +97,18 @@ config BATMAN_ADV_DEBUG
109 buffer. The output is controlled via the batadv netdev specific 97 buffer. The output is controlled via the batadv netdev specific
110 log_level setting. 98 log_level setting.
111 99
100config BATMAN_ADV_SYSFS
101 bool "batman-adv sysfs entries"
102 depends on BATMAN_ADV
103 default y
104 help
105 Say Y here if you want to enable batman-adv device configuration and
106 status interface through sysfs attributes. It is replaced by the
107 batadv generic netlink family but still used by various userspace
108 tools and scripts.
109
110 If unsure, say Y.
111
112config BATMAN_ADV_TRACING 112config BATMAN_ADV_TRACING
113 bool "B.A.T.M.A.N. tracing support" 113 bool "B.A.T.M.A.N. tracing support"
114 depends on BATMAN_ADV 114 depends on BATMAN_ADV
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile
index a887ecc3efa1..fd63e116d9ff 100644
--- a/net/batman-adv/Makefile
+++ b/net/batman-adv/Makefile
@@ -2,19 +2,6 @@
2# Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2# Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3# 3#
4# Marek Lindner, Simon Wunderlich 4# Marek Lindner, Simon Wunderlich
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of version 2 of the GNU General Public
8# License as published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, see <http://www.gnu.org/licenses/>.
17#
18 5
19obj-$(CONFIG_BATMAN_ADV) += batman-adv.o 6obj-$(CONFIG_BATMAN_ADV) += batman-adv.o
20batman-adv-y += bat_algo.o 7batman-adv-y += bat_algo.o
@@ -41,7 +28,7 @@ batman-adv-y += originator.o
41batman-adv-y += routing.o 28batman-adv-y += routing.o
42batman-adv-y += send.o 29batman-adv-y += send.o
43batman-adv-y += soft-interface.o 30batman-adv-y += soft-interface.o
44batman-adv-y += sysfs.o 31batman-adv-$(CONFIG_BATMAN_ADV_SYSFS) += sysfs.o
45batman-adv-$(CONFIG_BATMAN_ADV_TRACING) += trace.o 32batman-adv-$(CONFIG_BATMAN_ADV_TRACING) += trace.o
46batman-adv-y += tp_meter.o 33batman-adv-y += tp_meter.o
47batman-adv-y += translation-table.o 34batman-adv-y += translation-table.o
diff --git a/net/batman-adv/bat_algo.c b/net/batman-adv/bat_algo.c
index 7b7e15641fef..fa39eaaab9d7 100644
--- a/net/batman-adv/bat_algo.c
+++ b/net/batman-adv/bat_algo.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "main.h" 7#include "main.h"
diff --git a/net/batman-adv/bat_algo.h b/net/batman-adv/bat_algo.h
index 25e7bb51928c..cb7d57d16c9d 100644
--- a/net/batman-adv/bat_algo.h
+++ b/net/batman-adv/bat_algo.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Linus Lüssing 4 * Marek Lindner, Linus Lüssing
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_BAT_ALGO_H_ 7#ifndef _NET_BATMAN_ADV_BAT_ALGO_H_
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index de61091af666..bd4138ddf7e0 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "bat_iv_ogm.h" 7#include "bat_iv_ogm.h"
diff --git a/net/batman-adv/bat_iv_ogm.h b/net/batman-adv/bat_iv_ogm.h
index 785f6666273c..c7a9ba305bfc 100644
--- a/net/batman-adv/bat_iv_ogm.h
+++ b/net/batman-adv/bat_iv_ogm.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_BAT_IV_OGM_H_ 7#ifndef _NET_BATMAN_ADV_BAT_IV_OGM_H_
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index 445594ed58af..231b4aab4d8d 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Linus Lüssing, Marek Lindner 4 * Linus Lüssing, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "bat_v.h" 7#include "bat_v.h"
diff --git a/net/batman-adv/bat_v.h b/net/batman-adv/bat_v.h
index 465a4fc23354..37833db098e6 100644
--- a/net/batman-adv/bat_v.h
+++ b/net/batman-adv/bat_v.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Linus Lüssing 4 * Marek Lindner, Linus Lüssing
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_BAT_V_H_ 7#ifndef _NET_BATMAN_ADV_BAT_V_H_
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index d5df0114f08a..2614a9caee00 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Linus Lüssing, Marek Lindner 4 * Linus Lüssing, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "bat_v_elp.h" 7#include "bat_v_elp.h"
diff --git a/net/batman-adv/bat_v_elp.h b/net/batman-adv/bat_v_elp.h
index 75f189ee4a1c..bb3d40f73bfe 100644
--- a/net/batman-adv/bat_v_elp.h
+++ b/net/batman-adv/bat_v_elp.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Linus Lüssing, Marek Lindner 4 * Linus Lüssing, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_BAT_V_ELP_H_ 7#ifndef _NET_BATMAN_ADV_BAT_V_ELP_H_
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index c9698ad41854..fad95ef64e01 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Antonio Quartulli 4 * Antonio Quartulli
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "bat_v_ogm.h" 7#include "bat_v_ogm.h"
diff --git a/net/batman-adv/bat_v_ogm.h b/net/batman-adv/bat_v_ogm.h
index f67cf7ee06b2..616bf2ea8755 100644
--- a/net/batman-adv/bat_v_ogm.h
+++ b/net/batman-adv/bat_v_ogm.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Antonio Quartulli 4 * Antonio Quartulli
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_BAT_V_OGM_H_ 7#ifndef _NET_BATMAN_ADV_BAT_V_OGM_H_
diff --git a/net/batman-adv/bitarray.c b/net/batman-adv/bitarray.c
index 63e134e763e3..7f04a6acf14e 100644
--- a/net/batman-adv/bitarray.c
+++ b/net/batman-adv/bitarray.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Simon Wunderlich, Marek Lindner 4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "bitarray.h" 7#include "bitarray.h"
diff --git a/net/batman-adv/bitarray.h b/net/batman-adv/bitarray.h
index f3a05ad9afad..84ad2d2b6ac9 100644
--- a/net/batman-adv/bitarray.h
+++ b/net/batman-adv/bitarray.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Simon Wunderlich, Marek Lindner 4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_BITARRAY_H_ 7#ifndef _NET_BATMAN_ADV_BITARRAY_H_
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 4fb01108e5f5..663a53b6d36e 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Simon Wunderlich 4 * Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "bridge_loop_avoidance.h" 7#include "bridge_loop_avoidance.h"
@@ -59,7 +47,6 @@
59#include "netlink.h" 47#include "netlink.h"
60#include "originator.h" 48#include "originator.h"
61#include "soft-interface.h" 49#include "soft-interface.h"
62#include "sysfs.h"
63#include "translation-table.h" 50#include "translation-table.h"
64 51
65static const u8 batadv_announce_mac[4] = {0x43, 0x05, 0x43, 0x05}; 52static const u8 batadv_announce_mac[4] = {0x43, 0x05, 0x43, 0x05};
diff --git a/net/batman-adv/bridge_loop_avoidance.h b/net/batman-adv/bridge_loop_avoidance.h
index 31771c751efb..012d72c8d064 100644
--- a/net/batman-adv/bridge_loop_avoidance.h
+++ b/net/batman-adv/bridge_loop_avoidance.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Simon Wunderlich 4 * Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_BLA_H_ 7#ifndef _NET_BATMAN_ADV_BLA_H_
diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c
index 3b9d1ad2f467..d38d70ccdd5a 100644
--- a/net/batman-adv/debugfs.c
+++ b/net/batman-adv/debugfs.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "debugfs.h" 7#include "debugfs.h"
diff --git a/net/batman-adv/debugfs.h b/net/batman-adv/debugfs.h
index c0b8694041ec..7fac680cf740 100644
--- a/net/batman-adv/debugfs.h
+++ b/net/batman-adv/debugfs.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_DEBUGFS_H_ 7#ifndef _NET_BATMAN_ADV_DEBUGFS_H_
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 310a4f353008..b0af3a11d406 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Antonio Quartulli 4 * Antonio Quartulli
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "distributed-arp-table.h" 7#include "distributed-arp-table.h"
@@ -667,7 +655,7 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst,
667} 655}
668 656
669/** 657/**
670 * batadv_dat_send_data() - send a payload to the selected candidates 658 * batadv_dat_forward_data() - copy and send payload to the selected candidates
671 * @bat_priv: the bat priv with all the soft interface information 659 * @bat_priv: the bat priv with all the soft interface information
672 * @skb: payload to send 660 * @skb: payload to send
673 * @ip: the DHT key 661 * @ip: the DHT key
@@ -680,9 +668,9 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst,
680 * Return: true if the packet is sent to at least one candidate, false 668 * Return: true if the packet is sent to at least one candidate, false
681 * otherwise. 669 * otherwise.
682 */ 670 */
683static bool batadv_dat_send_data(struct batadv_priv *bat_priv, 671static bool batadv_dat_forward_data(struct batadv_priv *bat_priv,
684 struct sk_buff *skb, __be32 ip, 672 struct sk_buff *skb, __be32 ip,
685 unsigned short vid, int packet_subtype) 673 unsigned short vid, int packet_subtype)
686{ 674{
687 int i; 675 int i;
688 bool ret = false; 676 bool ret = false;
@@ -1277,8 +1265,8 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
1277 ret = true; 1265 ret = true;
1278 } else { 1266 } else {
1279 /* Send the request to the DHT */ 1267 /* Send the request to the DHT */
1280 ret = batadv_dat_send_data(bat_priv, skb, ip_dst, vid, 1268 ret = batadv_dat_forward_data(bat_priv, skb, ip_dst, vid,
1281 BATADV_P_DAT_DHT_GET); 1269 BATADV_P_DAT_DHT_GET);
1282 } 1270 }
1283out: 1271out:
1284 if (dat_entry) 1272 if (dat_entry)
@@ -1392,8 +1380,10 @@ void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
1392 /* Send the ARP reply to the candidates for both the IP addresses that 1380 /* Send the ARP reply to the candidates for both the IP addresses that
1393 * the node obtained from the ARP reply 1381 * the node obtained from the ARP reply
1394 */ 1382 */
1395 batadv_dat_send_data(bat_priv, skb, ip_src, vid, BATADV_P_DAT_DHT_PUT); 1383 batadv_dat_forward_data(bat_priv, skb, ip_src, vid,
1396 batadv_dat_send_data(bat_priv, skb, ip_dst, vid, BATADV_P_DAT_DHT_PUT); 1384 BATADV_P_DAT_DHT_PUT);
1385 batadv_dat_forward_data(bat_priv, skb, ip_dst, vid,
1386 BATADV_P_DAT_DHT_PUT);
1397} 1387}
1398 1388
1399/** 1389/**
@@ -1444,7 +1434,6 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
1444 hw_src, &ip_src, hw_dst, &ip_dst, 1434 hw_src, &ip_src, hw_dst, &ip_dst,
1445 dat_entry->mac_addr, &dat_entry->ip); 1435 dat_entry->mac_addr, &dat_entry->ip);
1446 dropped = true; 1436 dropped = true;
1447 goto out;
1448 } 1437 }
1449 1438
1450 /* Update our internal cache with both the IP addresses the node got 1439 /* Update our internal cache with both the IP addresses the node got
@@ -1453,6 +1442,9 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
1453 batadv_dat_entry_add(bat_priv, ip_src, hw_src, vid); 1442 batadv_dat_entry_add(bat_priv, ip_src, hw_src, vid);
1454 batadv_dat_entry_add(bat_priv, ip_dst, hw_dst, vid); 1443 batadv_dat_entry_add(bat_priv, ip_dst, hw_dst, vid);
1455 1444
1445 if (dropped)
1446 goto out;
1447
1456 /* If BLA is enabled, only forward ARP replies if we have claimed the 1448 /* If BLA is enabled, only forward ARP replies if we have claimed the
1457 * source of the ARP reply or if no one else of the same backbone has 1449 * source of the ARP reply or if no one else of the same backbone has
1458 * already claimed that client. This prevents that different gateways 1450 * already claimed that client. This prevents that different gateways
@@ -1708,8 +1700,10 @@ static void batadv_dat_put_dhcp(struct batadv_priv *bat_priv, u8 *chaddr,
1708 batadv_dat_entry_add(bat_priv, yiaddr, chaddr, vid); 1700 batadv_dat_entry_add(bat_priv, yiaddr, chaddr, vid);
1709 batadv_dat_entry_add(bat_priv, ip_dst, hw_dst, vid); 1701 batadv_dat_entry_add(bat_priv, ip_dst, hw_dst, vid);
1710 1702
1711 batadv_dat_send_data(bat_priv, skb, yiaddr, vid, BATADV_P_DAT_DHT_PUT); 1703 batadv_dat_forward_data(bat_priv, skb, yiaddr, vid,
1712 batadv_dat_send_data(bat_priv, skb, ip_dst, vid, BATADV_P_DAT_DHT_PUT); 1704 BATADV_P_DAT_DHT_PUT);
1705 batadv_dat_forward_data(bat_priv, skb, ip_dst, vid,
1706 BATADV_P_DAT_DHT_PUT);
1713 1707
1714 consume_skb(skb); 1708 consume_skb(skb);
1715 1709
diff --git a/net/batman-adv/distributed-arp-table.h b/net/batman-adv/distributed-arp-table.h
index 68c0ff321acd..110c27447d70 100644
--- a/net/batman-adv/distributed-arp-table.h
+++ b/net/batman-adv/distributed-arp-table.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Antonio Quartulli 4 * Antonio Quartulli
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ 7#ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
index b506d15b8230..385fccdcf69d 100644
--- a/net/batman-adv/fragmentation.c
+++ b/net/batman-adv/fragmentation.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Martin Hundebøll <martin@hundeboll.net> 4 * Martin Hundebøll <martin@hundeboll.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "fragmentation.h" 7#include "fragmentation.h"
diff --git a/net/batman-adv/fragmentation.h b/net/batman-adv/fragmentation.h
index abdac26579bf..d6074ba2ada7 100644
--- a/net/batman-adv/fragmentation.h
+++ b/net/batman-adv/fragmentation.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2013-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Martin Hundebøll <martin@hundeboll.net> 4 * Martin Hundebøll <martin@hundeboll.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_FRAGMENTATION_H_ 7#ifndef _NET_BATMAN_ADV_FRAGMENTATION_H_
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index f5811f61aa92..47df4c678988 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "gateway_client.h" 7#include "gateway_client.h"
@@ -53,7 +41,6 @@
53#include "originator.h" 41#include "originator.h"
54#include "routing.h" 42#include "routing.h"
55#include "soft-interface.h" 43#include "soft-interface.h"
56#include "sysfs.h"
57#include "translation-table.h" 44#include "translation-table.h"
58 45
59/* These are the offsets of the "hw type" and "hw address length" in the dhcp 46/* These are the offsets of the "hw type" and "hw address length" in the dhcp
diff --git a/net/batman-adv/gateway_client.h b/net/batman-adv/gateway_client.h
index b5732c8be81a..0e14026feebd 100644
--- a/net/batman-adv/gateway_client.h
+++ b/net/batman-adv/gateway_client.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ 7#ifndef _NET_BATMAN_ADV_GATEWAY_CLIENT_H_
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
index e064de45e22c..dac097f9be03 100644
--- a/net/batman-adv/gateway_common.c
+++ b/net/batman-adv/gateway_common.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "gateway_common.h" 7#include "gateway_common.h"
diff --git a/net/batman-adv/gateway_common.h b/net/batman-adv/gateway_common.h
index 128467a0fb89..5cf50736c635 100644
--- a/net/batman-adv/gateway_common.h
+++ b/net/batman-adv/gateway_common.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_GATEWAY_COMMON_H_ 7#ifndef _NET_BATMAN_ADV_GATEWAY_COMMON_H_
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 96ef7c70b4d9..79d1731b8306 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "hard-interface.h" 7#include "hard-interface.h"
diff --git a/net/batman-adv/hard-interface.h b/net/batman-adv/hard-interface.h
index 48de28c83401..c8ef6aa0e865 100644
--- a/net/batman-adv/hard-interface.h
+++ b/net/batman-adv/hard-interface.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_ 7#ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 56a08ce193d5..a9d4e176f4de 100644
--- a/net/batman-adv/hash.c
+++ b/net/batman-adv/hash.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Simon Wunderlich, Marek Lindner 4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "hash.h" 7#include "hash.h"
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index 37507b6d4006..ceef171f7f98 100644
--- a/net/batman-adv/hash.h
+++ b/net/batman-adv/hash.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Simon Wunderlich, Marek Lindner 4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_HASH_H_ 7#ifndef _NET_BATMAN_ADV_HASH_H_
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c
index 9859ababb82e..0a91c8661357 100644
--- a/net/batman-adv/icmp_socket.c
+++ b/net/batman-adv/icmp_socket.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "icmp_socket.h" 7#include "icmp_socket.h"
@@ -77,7 +65,7 @@ static int batadv_socket_open(struct inode *inode, struct file *file)
77 65
78 batadv_debugfs_deprecated(file, ""); 66 batadv_debugfs_deprecated(file, "");
79 67
80 nonseekable_open(inode, file); 68 stream_open(inode, file);
81 69
82 socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL); 70 socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL);
83 if (!socket_client) { 71 if (!socket_client) {
diff --git a/net/batman-adv/icmp_socket.h b/net/batman-adv/icmp_socket.h
index 5f8926522ff0..35eecbfd2e65 100644
--- a/net/batman-adv/icmp_socket.h
+++ b/net/batman-adv/icmp_socket.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_ICMP_SOCKET_H_ 7#ifndef _NET_BATMAN_ADV_ICMP_SOCKET_H_
diff --git a/net/batman-adv/log.c b/net/batman-adv/log.c
index 3e610df8debf..f79ebd5b46e9 100644
--- a/net/batman-adv/log.c
+++ b/net/batman-adv/log.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "log.h" 7#include "log.h"
@@ -102,7 +90,7 @@ static int batadv_log_open(struct inode *inode, struct file *file)
102 batadv_debugfs_deprecated(file, 90 batadv_debugfs_deprecated(file,
103 "Use tracepoint batadv:batadv_dbg instead\n"); 91 "Use tracepoint batadv:batadv_dbg instead\n");
104 92
105 nonseekable_open(inode, file); 93 stream_open(inode, file);
106 file->private_data = inode->i_private; 94 file->private_data = inode->i_private;
107 return 0; 95 return 0;
108} 96}
diff --git a/net/batman-adv/log.h b/net/batman-adv/log.h
index 660e9bcc85a2..5504637e63d8 100644
--- a/net/batman-adv/log.h
+++ b/net/batman-adv/log.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_LOG_H_ 7#ifndef _NET_BATMAN_ADV_LOG_H_
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 75750870cf04..4a89177def64 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "main.h" 7#include "main.h"
@@ -22,6 +10,7 @@
22#include <linux/build_bug.h> 10#include <linux/build_bug.h>
23#include <linux/byteorder/generic.h> 11#include <linux/byteorder/generic.h>
24#include <linux/crc32c.h> 12#include <linux/crc32c.h>
13#include <linux/device.h>
25#include <linux/errno.h> 14#include <linux/errno.h>
26#include <linux/genetlink.h> 15#include <linux/genetlink.h>
27#include <linux/gfp.h> 16#include <linux/gfp.h>
@@ -31,6 +20,7 @@
31#include <linux/ip.h> 20#include <linux/ip.h>
32#include <linux/ipv6.h> 21#include <linux/ipv6.h>
33#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/kobject.h>
34#include <linux/kref.h> 24#include <linux/kref.h>
35#include <linux/list.h> 25#include <linux/list.h>
36#include <linux/module.h> 26#include <linux/module.h>
@@ -40,6 +30,7 @@
40#include <linux/rcupdate.h> 30#include <linux/rcupdate.h>
41#include <linux/seq_file.h> 31#include <linux/seq_file.h>
42#include <linux/skbuff.h> 32#include <linux/skbuff.h>
33#include <linux/slab.h>
43#include <linux/spinlock.h> 34#include <linux/spinlock.h>
44#include <linux/stddef.h> 35#include <linux/stddef.h>
45#include <linux/string.h> 36#include <linux/string.h>
@@ -84,6 +75,22 @@ struct workqueue_struct *batadv_event_workqueue;
84 75
85static void batadv_recv_handler_init(void); 76static void batadv_recv_handler_init(void);
86 77
78#define BATADV_UEV_TYPE_VAR "BATTYPE="
79#define BATADV_UEV_ACTION_VAR "BATACTION="
80#define BATADV_UEV_DATA_VAR "BATDATA="
81
82static char *batadv_uev_action_str[] = {
83 "add",
84 "del",
85 "change",
86 "loopdetect",
87};
88
89static char *batadv_uev_type_str[] = {
90 "gw",
91 "bla",
92};
93
87static int __init batadv_init(void) 94static int __init batadv_init(void)
88{ 95{
89 int ret; 96 int ret;
@@ -161,6 +168,7 @@ int batadv_mesh_init(struct net_device *soft_iface)
161 spin_lock_init(&bat_priv->tt.commit_lock); 168 spin_lock_init(&bat_priv->tt.commit_lock);
162 spin_lock_init(&bat_priv->gw.list_lock); 169 spin_lock_init(&bat_priv->gw.list_lock);
163#ifdef CONFIG_BATMAN_ADV_MCAST 170#ifdef CONFIG_BATMAN_ADV_MCAST
171 spin_lock_init(&bat_priv->mcast.mla_lock);
164 spin_lock_init(&bat_priv->mcast.want_lists_lock); 172 spin_lock_init(&bat_priv->mcast.want_lists_lock);
165#endif 173#endif
166 spin_lock_init(&bat_priv->tvlv.container_list_lock); 174 spin_lock_init(&bat_priv->tvlv.container_list_lock);
@@ -678,6 +686,60 @@ bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid)
678 return ap_isolation_enabled; 686 return ap_isolation_enabled;
679} 687}
680 688
689/**
690 * batadv_throw_uevent() - Send an uevent with batman-adv specific env data
691 * @bat_priv: the bat priv with all the soft interface information
692 * @type: subsystem type of event. Stored in uevent's BATTYPE
693 * @action: action type of event. Stored in uevent's BATACTION
694 * @data: string with additional information to the event (ignored for
695 * BATADV_UEV_DEL). Stored in uevent's BATDATA
696 *
697 * Return: 0 on success or negative error number in case of failure
698 */
699int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
700 enum batadv_uev_action action, const char *data)
701{
702 int ret = -ENOMEM;
703 struct kobject *bat_kobj;
704 char *uevent_env[4] = { NULL, NULL, NULL, NULL };
705
706 bat_kobj = &bat_priv->soft_iface->dev.kobj;
707
708 uevent_env[0] = kasprintf(GFP_ATOMIC,
709 "%s%s", BATADV_UEV_TYPE_VAR,
710 batadv_uev_type_str[type]);
711 if (!uevent_env[0])
712 goto out;
713
714 uevent_env[1] = kasprintf(GFP_ATOMIC,
715 "%s%s", BATADV_UEV_ACTION_VAR,
716 batadv_uev_action_str[action]);
717 if (!uevent_env[1])
718 goto out;
719
720 /* If the event is DEL, ignore the data field */
721 if (action != BATADV_UEV_DEL) {
722 uevent_env[2] = kasprintf(GFP_ATOMIC,
723 "%s%s", BATADV_UEV_DATA_VAR, data);
724 if (!uevent_env[2])
725 goto out;
726 }
727
728 ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
729out:
730 kfree(uevent_env[0]);
731 kfree(uevent_env[1]);
732 kfree(uevent_env[2]);
733
734 if (ret)
735 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
736 "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
737 batadv_uev_type_str[type],
738 batadv_uev_action_str[action],
739 (action == BATADV_UEV_DEL ? "NULL" : data), ret);
740 return ret;
741}
742
681module_init(batadv_init); 743module_init(batadv_init);
682module_exit(batadv_exit); 744module_exit(batadv_exit);
683 745
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 3ed669d7dc6b..c59afcba31e0 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_MAIN_H_ 7#ifndef _NET_BATMAN_ADV_MAIN_H_
@@ -25,7 +13,7 @@
25#define BATADV_DRIVER_DEVICE "batman-adv" 13#define BATADV_DRIVER_DEVICE "batman-adv"
26 14
27#ifndef BATADV_SOURCE_VERSION 15#ifndef BATADV_SOURCE_VERSION
28#define BATADV_SOURCE_VERSION "2019.1" 16#define BATADV_SOURCE_VERSION "2019.2"
29#endif 17#endif
30 18
31/* B.A.T.M.A.N. parameters */ 19/* B.A.T.M.A.N. parameters */
@@ -394,5 +382,7 @@ static inline void batadv_add_counter(struct batadv_priv *bat_priv, size_t idx,
394 382
395unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len); 383unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len);
396bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid); 384bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid);
385int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
386 enum batadv_uev_action action, const char *data);
397 387
398#endif /* _NET_BATMAN_ADV_MAIN_H_ */ 388#endif /* _NET_BATMAN_ADV_MAIN_H_ */
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index f91b1b6265cf..ec54e236e345 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2014-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2014-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Linus Lüssing 4 * Linus Lüssing
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "multicast.h" 7#include "multicast.h"
@@ -66,6 +54,7 @@
66#include "hash.h" 54#include "hash.h"
67#include "log.h" 55#include "log.h"
68#include "netlink.h" 56#include "netlink.h"
57#include "send.h"
69#include "soft-interface.h" 58#include "soft-interface.h"
70#include "translation-table.h" 59#include "translation-table.h"
71#include "tvlv.h" 60#include "tvlv.h"
@@ -325,8 +314,6 @@ static void batadv_mcast_mla_list_free(struct hlist_head *mcast_list)
325 * translation table except the ones listed in the given mcast_list. 314 * translation table except the ones listed in the given mcast_list.
326 * 315 *
327 * If mcast_list is NULL then all are retracted. 316 * If mcast_list is NULL then all are retracted.
328 *
329 * Do not call outside of the mcast worker! (or cancel mcast worker first)
330 */ 317 */
331static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv, 318static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,
332 struct hlist_head *mcast_list) 319 struct hlist_head *mcast_list)
@@ -334,8 +321,6 @@ static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,
334 struct batadv_hw_addr *mcast_entry; 321 struct batadv_hw_addr *mcast_entry;
335 struct hlist_node *tmp; 322 struct hlist_node *tmp;
336 323
337 WARN_ON(delayed_work_pending(&bat_priv->mcast.work));
338
339 hlist_for_each_entry_safe(mcast_entry, tmp, &bat_priv->mcast.mla_list, 324 hlist_for_each_entry_safe(mcast_entry, tmp, &bat_priv->mcast.mla_list,
340 list) { 325 list) {
341 if (mcast_list && 326 if (mcast_list &&
@@ -359,8 +344,6 @@ static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,
359 * 344 *
360 * Adds multicast listener announcements from the given mcast_list to the 345 * Adds multicast listener announcements from the given mcast_list to the
361 * translation table if they have not been added yet. 346 * translation table if they have not been added yet.
362 *
363 * Do not call outside of the mcast worker! (or cancel mcast worker first)
364 */ 347 */
365static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv, 348static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv,
366 struct hlist_head *mcast_list) 349 struct hlist_head *mcast_list)
@@ -368,8 +351,6 @@ static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv,
368 struct batadv_hw_addr *mcast_entry; 351 struct batadv_hw_addr *mcast_entry;
369 struct hlist_node *tmp; 352 struct hlist_node *tmp;
370 353
371 WARN_ON(delayed_work_pending(&bat_priv->mcast.work));
372
373 if (!mcast_list) 354 if (!mcast_list)
374 return; 355 return;
375 356
@@ -658,7 +639,10 @@ static void batadv_mcast_mla_update(struct work_struct *work)
658 priv_mcast = container_of(delayed_work, struct batadv_priv_mcast, work); 639 priv_mcast = container_of(delayed_work, struct batadv_priv_mcast, work);
659 bat_priv = container_of(priv_mcast, struct batadv_priv, mcast); 640 bat_priv = container_of(priv_mcast, struct batadv_priv, mcast);
660 641
642 spin_lock(&bat_priv->mcast.mla_lock);
661 __batadv_mcast_mla_update(bat_priv); 643 __batadv_mcast_mla_update(bat_priv);
644 spin_unlock(&bat_priv->mcast.mla_lock);
645
662 batadv_mcast_start_timer(bat_priv); 646 batadv_mcast_start_timer(bat_priv);
663} 647}
664 648
@@ -991,6 +975,7 @@ batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,
991{ 975{
992 int ret, tt_count, ip_count, unsnoop_count, total_count; 976 int ret, tt_count, ip_count, unsnoop_count, total_count;
993 bool is_unsnoopable = false; 977 bool is_unsnoopable = false;
978 unsigned int mcast_fanout;
994 struct ethhdr *ethhdr; 979 struct ethhdr *ethhdr;
995 980
996 ret = batadv_mcast_forw_mode_check(bat_priv, skb, &is_unsnoopable); 981 ret = batadv_mcast_forw_mode_check(bat_priv, skb, &is_unsnoopable);
@@ -1025,8 +1010,203 @@ batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,
1025 case 0: 1010 case 0:
1026 return BATADV_FORW_NONE; 1011 return BATADV_FORW_NONE;
1027 default: 1012 default:
1028 return BATADV_FORW_ALL; 1013 mcast_fanout = atomic_read(&bat_priv->multicast_fanout);
1014
1015 if (!unsnoop_count && total_count <= mcast_fanout)
1016 return BATADV_FORW_SOME;
1017 }
1018
1019 return BATADV_FORW_ALL;
1020}
1021
1022/**
1023 * batadv_mcast_forw_tt() - forwards a packet to multicast listeners
1024 * @bat_priv: the bat priv with all the soft interface information
1025 * @skb: the multicast packet to transmit
1026 * @vid: the vlan identifier
1027 *
1028 * Sends copies of a frame with multicast destination to any multicast
1029 * listener registered in the translation table. A transmission is performed
1030 * via a batman-adv unicast packet for each such destination node.
1031 *
1032 * Return: NET_XMIT_DROP on memory allocation failure, NET_XMIT_SUCCESS
1033 * otherwise.
1034 */
1035static int
1036batadv_mcast_forw_tt(struct batadv_priv *bat_priv, struct sk_buff *skb,
1037 unsigned short vid)
1038{
1039 int ret = NET_XMIT_SUCCESS;
1040 struct sk_buff *newskb;
1041
1042 struct batadv_tt_orig_list_entry *orig_entry;
1043
1044 struct batadv_tt_global_entry *tt_global;
1045 const u8 *addr = eth_hdr(skb)->h_dest;
1046
1047 tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
1048 if (!tt_global)
1049 goto out;
1050
1051 rcu_read_lock();
1052 hlist_for_each_entry_rcu(orig_entry, &tt_global->orig_list, list) {
1053 newskb = skb_copy(skb, GFP_ATOMIC);
1054 if (!newskb) {
1055 ret = NET_XMIT_DROP;
1056 break;
1057 }
1058
1059 batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0,
1060 orig_entry->orig_node, vid);
1061 }
1062 rcu_read_unlock();
1063
1064 batadv_tt_global_entry_put(tt_global);
1065
1066out:
1067 return ret;
1068}
1069
1070/**
1071 * batadv_mcast_forw_want_all_ipv4() - forward to nodes with want-all-ipv4
1072 * @bat_priv: the bat priv with all the soft interface information
1073 * @skb: the multicast packet to transmit
1074 * @vid: the vlan identifier
1075 *
1076 * Sends copies of a frame with multicast destination to any node with a
1077 * BATADV_MCAST_WANT_ALL_IPV4 flag set. A transmission is performed via a
1078 * batman-adv unicast packet for each such destination node.
1079 *
1080 * Return: NET_XMIT_DROP on memory allocation failure, NET_XMIT_SUCCESS
1081 * otherwise.
1082 */
1083static int
1084batadv_mcast_forw_want_all_ipv4(struct batadv_priv *bat_priv,
1085 struct sk_buff *skb, unsigned short vid)
1086{
1087 struct batadv_orig_node *orig_node;
1088 int ret = NET_XMIT_SUCCESS;
1089 struct sk_buff *newskb;
1090
1091 rcu_read_lock();
1092 hlist_for_each_entry_rcu(orig_node,
1093 &bat_priv->mcast.want_all_ipv4_list,
1094 mcast_want_all_ipv4_node) {
1095 newskb = skb_copy(skb, GFP_ATOMIC);
1096 if (!newskb) {
1097 ret = NET_XMIT_DROP;
1098 break;
1099 }
1100
1101 batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0,
1102 orig_node, vid);
1029 } 1103 }
1104 rcu_read_unlock();
1105 return ret;
1106}
1107
1108/**
1109 * batadv_mcast_forw_want_all_ipv6() - forward to nodes with want-all-ipv6
1110 * @bat_priv: the bat priv with all the soft interface information
1111 * @skb: The multicast packet to transmit
1112 * @vid: the vlan identifier
1113 *
1114 * Sends copies of a frame with multicast destination to any node with a
1115 * BATADV_MCAST_WANT_ALL_IPV6 flag set. A transmission is performed via a
1116 * batman-adv unicast packet for each such destination node.
1117 *
1118 * Return: NET_XMIT_DROP on memory allocation failure, NET_XMIT_SUCCESS
1119 * otherwise.
1120 */
1121static int
1122batadv_mcast_forw_want_all_ipv6(struct batadv_priv *bat_priv,
1123 struct sk_buff *skb, unsigned short vid)
1124{
1125 struct batadv_orig_node *orig_node;
1126 int ret = NET_XMIT_SUCCESS;
1127 struct sk_buff *newskb;
1128
1129 rcu_read_lock();
1130 hlist_for_each_entry_rcu(orig_node,
1131 &bat_priv->mcast.want_all_ipv6_list,
1132 mcast_want_all_ipv6_node) {
1133 newskb = skb_copy(skb, GFP_ATOMIC);
1134 if (!newskb) {
1135 ret = NET_XMIT_DROP;
1136 break;
1137 }
1138
1139 batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0,
1140 orig_node, vid);
1141 }
1142 rcu_read_unlock();
1143 return ret;
1144}
1145
1146/**
1147 * batadv_mcast_forw_want_all() - forward packet to nodes in a want-all list
1148 * @bat_priv: the bat priv with all the soft interface information
1149 * @skb: the multicast packet to transmit
1150 * @vid: the vlan identifier
1151 *
1152 * Sends copies of a frame with multicast destination to any node with a
1153 * BATADV_MCAST_WANT_ALL_IPV4 or BATADV_MCAST_WANT_ALL_IPV6 flag set. A
1154 * transmission is performed via a batman-adv unicast packet for each such
1155 * destination node.
1156 *
1157 * Return: NET_XMIT_DROP on memory allocation failure or if the protocol family
1158 * is neither IPv4 nor IPv6. NET_XMIT_SUCCESS otherwise.
1159 */
1160static int
1161batadv_mcast_forw_want_all(struct batadv_priv *bat_priv,
1162 struct sk_buff *skb, unsigned short vid)
1163{
1164 switch (ntohs(eth_hdr(skb)->h_proto)) {
1165 case ETH_P_IP:
1166 return batadv_mcast_forw_want_all_ipv4(bat_priv, skb, vid);
1167 case ETH_P_IPV6:
1168 return batadv_mcast_forw_want_all_ipv6(bat_priv, skb, vid);
1169 default:
1170 /* we shouldn't be here... */
1171 return NET_XMIT_DROP;
1172 }
1173}
1174
1175/**
1176 * batadv_mcast_forw_send() - send packet to any detected multicast recpient
1177 * @bat_priv: the bat priv with all the soft interface information
1178 * @skb: the multicast packet to transmit
1179 * @vid: the vlan identifier
1180 *
1181 * Sends copies of a frame with multicast destination to any node that signaled
1182 * interest in it, that is either via the translation table or the according
1183 * want-all flags. A transmission is performed via a batman-adv unicast packet
1184 * for each such destination node.
1185 *
1186 * The given skb is consumed/freed.
1187 *
1188 * Return: NET_XMIT_DROP on memory allocation failure or if the protocol family
1189 * is neither IPv4 nor IPv6. NET_XMIT_SUCCESS otherwise.
1190 */
1191int batadv_mcast_forw_send(struct batadv_priv *bat_priv, struct sk_buff *skb,
1192 unsigned short vid)
1193{
1194 int ret;
1195
1196 ret = batadv_mcast_forw_tt(bat_priv, skb, vid);
1197 if (ret != NET_XMIT_SUCCESS) {
1198 kfree_skb(skb);
1199 return ret;
1200 }
1201
1202 ret = batadv_mcast_forw_want_all(bat_priv, skb, vid);
1203 if (ret != NET_XMIT_SUCCESS) {
1204 kfree_skb(skb);
1205 return ret;
1206 }
1207
1208 consume_skb(skb);
1209 return ret;
1030} 1210}
1031 1211
1032/** 1212/**
diff --git a/net/batman-adv/multicast.h b/net/batman-adv/multicast.h
index 466013fe88af..653b9b76fabe 100644
--- a/net/batman-adv/multicast.h
+++ b/net/batman-adv/multicast.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2014-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2014-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Linus Lüssing 4 * Linus Lüssing
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_MULTICAST_H_ 7#ifndef _NET_BATMAN_ADV_MULTICAST_H_
@@ -36,6 +24,13 @@ enum batadv_forw_mode {
36 BATADV_FORW_ALL, 24 BATADV_FORW_ALL,
37 25
38 /** 26 /**
27 * @BATADV_FORW_SOME: forward the packet to some nodes (currently via
28 * a multicast-to-unicast conversion and the BATMAN unicast routing
29 * protocol)
30 */
31 BATADV_FORW_SOME,
32
33 /**
39 * @BATADV_FORW_SINGLE: forward the packet to a single node (currently 34 * @BATADV_FORW_SINGLE: forward the packet to a single node (currently
40 * via the BATMAN unicast routing protocol) 35 * via the BATMAN unicast routing protocol)
41 */ 36 */
@@ -51,6 +46,9 @@ enum batadv_forw_mode
51batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb, 46batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,
52 struct batadv_orig_node **mcast_single_orig); 47 struct batadv_orig_node **mcast_single_orig);
53 48
49int batadv_mcast_forw_send(struct batadv_priv *bat_priv, struct sk_buff *skb,
50 unsigned short vid);
51
54void batadv_mcast_init(struct batadv_priv *bat_priv); 52void batadv_mcast_init(struct batadv_priv *bat_priv);
55 53
56int batadv_mcast_flags_seq_print_text(struct seq_file *seq, void *offset); 54int batadv_mcast_flags_seq_print_text(struct seq_file *seq, void *offset);
@@ -73,6 +71,14 @@ batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb,
73 return BATADV_FORW_ALL; 71 return BATADV_FORW_ALL;
74} 72}
75 73
74static inline int
75batadv_mcast_forw_send(struct batadv_priv *bat_priv, struct sk_buff *skb,
76 unsigned short vid)
77{
78 kfree_skb(skb);
79 return NET_XMIT_DROP;
80}
81
76static inline int batadv_mcast_init(struct batadv_priv *bat_priv) 82static inline int batadv_mcast_init(struct batadv_priv *bat_priv)
77{ 83{
78 return 0; 84 return 0;
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index 67a58da2e6a0..a67720fad46c 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2016-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2016-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Matthias Schiffer 4 * Matthias Schiffer
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "netlink.h" 7#include "netlink.h"
@@ -157,6 +145,7 @@ static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
157 [BATADV_ATTR_HOP_PENALTY] = { .type = NLA_U8 }, 145 [BATADV_ATTR_HOP_PENALTY] = { .type = NLA_U8 },
158 [BATADV_ATTR_LOG_LEVEL] = { .type = NLA_U32 }, 146 [BATADV_ATTR_LOG_LEVEL] = { .type = NLA_U32 },
159 [BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED] = { .type = NLA_U8 }, 147 [BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED] = { .type = NLA_U8 },
148 [BATADV_ATTR_MULTICAST_FANOUT] = { .type = NLA_U32 },
160 [BATADV_ATTR_NETWORK_CODING_ENABLED] = { .type = NLA_U8 }, 149 [BATADV_ATTR_NETWORK_CODING_ENABLED] = { .type = NLA_U8 },
161 [BATADV_ATTR_ORIG_INTERVAL] = { .type = NLA_U32 }, 150 [BATADV_ATTR_ORIG_INTERVAL] = { .type = NLA_U32 },
162 [BATADV_ATTR_ELP_INTERVAL] = { .type = NLA_U32 }, 151 [BATADV_ATTR_ELP_INTERVAL] = { .type = NLA_U32 },
@@ -353,6 +342,10 @@ static int batadv_netlink_mesh_fill(struct sk_buff *msg,
353 if (nla_put_u8(msg, BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED, 342 if (nla_put_u8(msg, BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED,
354 !atomic_read(&bat_priv->multicast_mode))) 343 !atomic_read(&bat_priv->multicast_mode)))
355 goto nla_put_failure; 344 goto nla_put_failure;
345
346 if (nla_put_u32(msg, BATADV_ATTR_MULTICAST_FANOUT,
347 atomic_read(&bat_priv->multicast_fanout)))
348 goto nla_put_failure;
356#endif /* CONFIG_BATMAN_ADV_MCAST */ 349#endif /* CONFIG_BATMAN_ADV_MCAST */
357 350
358#ifdef CONFIG_BATMAN_ADV_NC 351#ifdef CONFIG_BATMAN_ADV_NC
@@ -592,6 +585,12 @@ static int batadv_netlink_set_mesh(struct sk_buff *skb, struct genl_info *info)
592 585
593 atomic_set(&bat_priv->multicast_mode, !nla_get_u8(attr)); 586 atomic_set(&bat_priv->multicast_mode, !nla_get_u8(attr));
594 } 587 }
588
589 if (info->attrs[BATADV_ATTR_MULTICAST_FANOUT]) {
590 attr = info->attrs[BATADV_ATTR_MULTICAST_FANOUT];
591
592 atomic_set(&bat_priv->multicast_fanout, nla_get_u32(attr));
593 }
595#endif /* CONFIG_BATMAN_ADV_MCAST */ 594#endif /* CONFIG_BATMAN_ADV_MCAST */
596 595
597#ifdef CONFIG_BATMAN_ADV_NC 596#ifdef CONFIG_BATMAN_ADV_NC
@@ -1344,35 +1343,35 @@ static void batadv_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
1344static const struct genl_ops batadv_netlink_ops[] = { 1343static const struct genl_ops batadv_netlink_ops[] = {
1345 { 1344 {
1346 .cmd = BATADV_CMD_GET_MESH, 1345 .cmd = BATADV_CMD_GET_MESH,
1346 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1347 /* can be retrieved by unprivileged users */ 1347 /* can be retrieved by unprivileged users */
1348 .policy = batadv_netlink_policy,
1349 .doit = batadv_netlink_get_mesh, 1348 .doit = batadv_netlink_get_mesh,
1350 .internal_flags = BATADV_FLAG_NEED_MESH, 1349 .internal_flags = BATADV_FLAG_NEED_MESH,
1351 }, 1350 },
1352 { 1351 {
1353 .cmd = BATADV_CMD_TP_METER, 1352 .cmd = BATADV_CMD_TP_METER,
1353 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1354 .flags = GENL_ADMIN_PERM, 1354 .flags = GENL_ADMIN_PERM,
1355 .policy = batadv_netlink_policy,
1356 .doit = batadv_netlink_tp_meter_start, 1355 .doit = batadv_netlink_tp_meter_start,
1357 .internal_flags = BATADV_FLAG_NEED_MESH, 1356 .internal_flags = BATADV_FLAG_NEED_MESH,
1358 }, 1357 },
1359 { 1358 {
1360 .cmd = BATADV_CMD_TP_METER_CANCEL, 1359 .cmd = BATADV_CMD_TP_METER_CANCEL,
1360 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1361 .flags = GENL_ADMIN_PERM, 1361 .flags = GENL_ADMIN_PERM,
1362 .policy = batadv_netlink_policy,
1363 .doit = batadv_netlink_tp_meter_cancel, 1362 .doit = batadv_netlink_tp_meter_cancel,
1364 .internal_flags = BATADV_FLAG_NEED_MESH, 1363 .internal_flags = BATADV_FLAG_NEED_MESH,
1365 }, 1364 },
1366 { 1365 {
1367 .cmd = BATADV_CMD_GET_ROUTING_ALGOS, 1366 .cmd = BATADV_CMD_GET_ROUTING_ALGOS,
1367 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1368 .flags = GENL_ADMIN_PERM, 1368 .flags = GENL_ADMIN_PERM,
1369 .policy = batadv_netlink_policy,
1370 .dumpit = batadv_algo_dump, 1369 .dumpit = batadv_algo_dump,
1371 }, 1370 },
1372 { 1371 {
1373 .cmd = BATADV_CMD_GET_HARDIF, 1372 .cmd = BATADV_CMD_GET_HARDIF,
1373 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1374 /* can be retrieved by unprivileged users */ 1374 /* can be retrieved by unprivileged users */
1375 .policy = batadv_netlink_policy,
1376 .dumpit = batadv_netlink_dump_hardif, 1375 .dumpit = batadv_netlink_dump_hardif,
1377 .doit = batadv_netlink_get_hardif, 1376 .doit = batadv_netlink_get_hardif,
1378 .internal_flags = BATADV_FLAG_NEED_MESH | 1377 .internal_flags = BATADV_FLAG_NEED_MESH |
@@ -1380,85 +1379,85 @@ static const struct genl_ops batadv_netlink_ops[] = {
1380 }, 1379 },
1381 { 1380 {
1382 .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, 1381 .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL,
1382 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1383 .flags = GENL_ADMIN_PERM, 1383 .flags = GENL_ADMIN_PERM,
1384 .policy = batadv_netlink_policy,
1385 .dumpit = batadv_tt_local_dump, 1384 .dumpit = batadv_tt_local_dump,
1386 }, 1385 },
1387 { 1386 {
1388 .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, 1387 .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL,
1388 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1389 .flags = GENL_ADMIN_PERM, 1389 .flags = GENL_ADMIN_PERM,
1390 .policy = batadv_netlink_policy,
1391 .dumpit = batadv_tt_global_dump, 1390 .dumpit = batadv_tt_global_dump,
1392 }, 1391 },
1393 { 1392 {
1394 .cmd = BATADV_CMD_GET_ORIGINATORS, 1393 .cmd = BATADV_CMD_GET_ORIGINATORS,
1394 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1395 .flags = GENL_ADMIN_PERM, 1395 .flags = GENL_ADMIN_PERM,
1396 .policy = batadv_netlink_policy,
1397 .dumpit = batadv_orig_dump, 1396 .dumpit = batadv_orig_dump,
1398 }, 1397 },
1399 { 1398 {
1400 .cmd = BATADV_CMD_GET_NEIGHBORS, 1399 .cmd = BATADV_CMD_GET_NEIGHBORS,
1400 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1401 .flags = GENL_ADMIN_PERM, 1401 .flags = GENL_ADMIN_PERM,
1402 .policy = batadv_netlink_policy,
1403 .dumpit = batadv_hardif_neigh_dump, 1402 .dumpit = batadv_hardif_neigh_dump,
1404 }, 1403 },
1405 { 1404 {
1406 .cmd = BATADV_CMD_GET_GATEWAYS, 1405 .cmd = BATADV_CMD_GET_GATEWAYS,
1406 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1407 .flags = GENL_ADMIN_PERM, 1407 .flags = GENL_ADMIN_PERM,
1408 .policy = batadv_netlink_policy,
1409 .dumpit = batadv_gw_dump, 1408 .dumpit = batadv_gw_dump,
1410 }, 1409 },
1411 { 1410 {
1412 .cmd = BATADV_CMD_GET_BLA_CLAIM, 1411 .cmd = BATADV_CMD_GET_BLA_CLAIM,
1412 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1413 .flags = GENL_ADMIN_PERM, 1413 .flags = GENL_ADMIN_PERM,
1414 .policy = batadv_netlink_policy,
1415 .dumpit = batadv_bla_claim_dump, 1414 .dumpit = batadv_bla_claim_dump,
1416 }, 1415 },
1417 { 1416 {
1418 .cmd = BATADV_CMD_GET_BLA_BACKBONE, 1417 .cmd = BATADV_CMD_GET_BLA_BACKBONE,
1418 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1419 .flags = GENL_ADMIN_PERM, 1419 .flags = GENL_ADMIN_PERM,
1420 .policy = batadv_netlink_policy,
1421 .dumpit = batadv_bla_backbone_dump, 1420 .dumpit = batadv_bla_backbone_dump,
1422 }, 1421 },
1423 { 1422 {
1424 .cmd = BATADV_CMD_GET_DAT_CACHE, 1423 .cmd = BATADV_CMD_GET_DAT_CACHE,
1424 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1425 .flags = GENL_ADMIN_PERM, 1425 .flags = GENL_ADMIN_PERM,
1426 .policy = batadv_netlink_policy,
1427 .dumpit = batadv_dat_cache_dump, 1426 .dumpit = batadv_dat_cache_dump,
1428 }, 1427 },
1429 { 1428 {
1430 .cmd = BATADV_CMD_GET_MCAST_FLAGS, 1429 .cmd = BATADV_CMD_GET_MCAST_FLAGS,
1430 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1431 .flags = GENL_ADMIN_PERM, 1431 .flags = GENL_ADMIN_PERM,
1432 .policy = batadv_netlink_policy,
1433 .dumpit = batadv_mcast_flags_dump, 1432 .dumpit = batadv_mcast_flags_dump,
1434 }, 1433 },
1435 { 1434 {
1436 .cmd = BATADV_CMD_SET_MESH, 1435 .cmd = BATADV_CMD_SET_MESH,
1436 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1437 .flags = GENL_ADMIN_PERM, 1437 .flags = GENL_ADMIN_PERM,
1438 .policy = batadv_netlink_policy,
1439 .doit = batadv_netlink_set_mesh, 1438 .doit = batadv_netlink_set_mesh,
1440 .internal_flags = BATADV_FLAG_NEED_MESH, 1439 .internal_flags = BATADV_FLAG_NEED_MESH,
1441 }, 1440 },
1442 { 1441 {
1443 .cmd = BATADV_CMD_SET_HARDIF, 1442 .cmd = BATADV_CMD_SET_HARDIF,
1443 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1444 .flags = GENL_ADMIN_PERM, 1444 .flags = GENL_ADMIN_PERM,
1445 .policy = batadv_netlink_policy,
1446 .doit = batadv_netlink_set_hardif, 1445 .doit = batadv_netlink_set_hardif,
1447 .internal_flags = BATADV_FLAG_NEED_MESH | 1446 .internal_flags = BATADV_FLAG_NEED_MESH |
1448 BATADV_FLAG_NEED_HARDIF, 1447 BATADV_FLAG_NEED_HARDIF,
1449 }, 1448 },
1450 { 1449 {
1451 .cmd = BATADV_CMD_GET_VLAN, 1450 .cmd = BATADV_CMD_GET_VLAN,
1451 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1452 /* can be retrieved by unprivileged users */ 1452 /* can be retrieved by unprivileged users */
1453 .policy = batadv_netlink_policy,
1454 .doit = batadv_netlink_get_vlan, 1453 .doit = batadv_netlink_get_vlan,
1455 .internal_flags = BATADV_FLAG_NEED_MESH | 1454 .internal_flags = BATADV_FLAG_NEED_MESH |
1456 BATADV_FLAG_NEED_VLAN, 1455 BATADV_FLAG_NEED_VLAN,
1457 }, 1456 },
1458 { 1457 {
1459 .cmd = BATADV_CMD_SET_VLAN, 1458 .cmd = BATADV_CMD_SET_VLAN,
1459 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1460 .flags = GENL_ADMIN_PERM, 1460 .flags = GENL_ADMIN_PERM,
1461 .policy = batadv_netlink_policy,
1462 .doit = batadv_netlink_set_vlan, 1461 .doit = batadv_netlink_set_vlan,
1463 .internal_flags = BATADV_FLAG_NEED_MESH | 1462 .internal_flags = BATADV_FLAG_NEED_MESH |
1464 BATADV_FLAG_NEED_VLAN, 1463 BATADV_FLAG_NEED_VLAN,
@@ -1470,6 +1469,7 @@ struct genl_family batadv_netlink_family __ro_after_init = {
1470 .name = BATADV_NL_NAME, 1469 .name = BATADV_NL_NAME,
1471 .version = 1, 1470 .version = 1,
1472 .maxattr = BATADV_ATTR_MAX, 1471 .maxattr = BATADV_ATTR_MAX,
1472 .policy = batadv_netlink_policy,
1473 .netnsok = true, 1473 .netnsok = true,
1474 .pre_doit = batadv_pre_doit, 1474 .pre_doit = batadv_pre_doit,
1475 .post_doit = batadv_post_doit, 1475 .post_doit = batadv_post_doit,
diff --git a/net/batman-adv/netlink.h b/net/batman-adv/netlink.h
index 7273368544fc..d1e0681b8743 100644
--- a/net/batman-adv/netlink.h
+++ b/net/batman-adv/netlink.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2016-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2016-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Matthias Schiffer 4 * Matthias Schiffer
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_NETLINK_H_ 7#ifndef _NET_BATMAN_ADV_NETLINK_H_
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 278762bd94c6..c5e7906045f3 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2012-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2012-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Martin Hundebøll, Jeppe Ledet-Pedersen 4 * Martin Hundebøll, Jeppe Ledet-Pedersen
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "network-coding.h" 7#include "network-coding.h"
diff --git a/net/batman-adv/network-coding.h b/net/batman-adv/network-coding.h
index 96ef0a511fc7..74f56113a5d0 100644
--- a/net/batman-adv/network-coding.h
+++ b/net/batman-adv/network-coding.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2012-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2012-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Martin Hundebøll, Jeppe Ledet-Pedersen 4 * Martin Hundebøll, Jeppe Ledet-Pedersen
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_NETWORK_CODING_H_ 7#ifndef _NET_BATMAN_ADV_NETWORK_CODING_H_
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index e5cdf89ef63c..45db798a7297 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2009-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "originator.h" 7#include "originator.h"
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index dca1e4a34ec6..3829e26f9c5d 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_ORIGINATOR_H_ 7#ifndef _NET_BATMAN_ADV_ORIGINATOR_H_
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index cae0e5dd0768..f0f864820dea 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "routing.h" 7#include "routing.h"
diff --git a/net/batman-adv/routing.h b/net/batman-adv/routing.h
index 0102d69d345c..b96c6d06d188 100644
--- a/net/batman-adv/routing.h
+++ b/net/batman-adv/routing.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_ROUTING_H_ 7#ifndef _NET_BATMAN_ADV_ROUTING_H_
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 66a8b3e44501..3ce5f7bad369 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "send.h" 7#include "send.h"
diff --git a/net/batman-adv/send.h b/net/batman-adv/send.h
index 1f6132922e60..5921ee4e107c 100644
--- a/net/batman-adv/send.h
+++ b/net/batman-adv/send.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_SEND_H_ 7#ifndef _NET_BATMAN_ADV_SEND_H_
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 2e367230376b..a7677e1d000f 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "soft-interface.h" 7#include "soft-interface.h"
@@ -209,7 +197,7 @@ static netdev_tx_t batadv_interface_tx(struct sk_buff *skb,
209 unsigned short vid; 197 unsigned short vid;
210 u32 seqno; 198 u32 seqno;
211 int gw_mode; 199 int gw_mode;
212 enum batadv_forw_mode forw_mode; 200 enum batadv_forw_mode forw_mode = BATADV_FORW_SINGLE;
213 struct batadv_orig_node *mcast_single_orig = NULL; 201 struct batadv_orig_node *mcast_single_orig = NULL;
214 int network_offset = ETH_HLEN; 202 int network_offset = ETH_HLEN;
215 __be16 proto; 203 __be16 proto;
@@ -317,7 +305,8 @@ send:
317 if (forw_mode == BATADV_FORW_NONE) 305 if (forw_mode == BATADV_FORW_NONE)
318 goto dropped; 306 goto dropped;
319 307
320 if (forw_mode == BATADV_FORW_SINGLE) 308 if (forw_mode == BATADV_FORW_SINGLE ||
309 forw_mode == BATADV_FORW_SOME)
321 do_bcast = false; 310 do_bcast = false;
322 } 311 }
323 } 312 }
@@ -377,6 +366,8 @@ send:
377 ret = batadv_send_skb_unicast(bat_priv, skb, 366 ret = batadv_send_skb_unicast(bat_priv, skb,
378 BATADV_UNICAST, 0, 367 BATADV_UNICAST, 0,
379 mcast_single_orig, vid); 368 mcast_single_orig, vid);
369 } else if (forw_mode == BATADV_FORW_SOME) {
370 ret = batadv_mcast_forw_send(bat_priv, skb, vid);
380 } else { 371 } else {
381 if (batadv_dat_snoop_outgoing_arp_request(bat_priv, 372 if (batadv_dat_snoop_outgoing_arp_request(bat_priv,
382 skb)) 373 skb))
@@ -818,6 +809,7 @@ static int batadv_softif_init_late(struct net_device *dev)
818 bat_priv->mcast.querier_ipv6.shadowing = false; 809 bat_priv->mcast.querier_ipv6.shadowing = false;
819 bat_priv->mcast.flags = BATADV_NO_FLAGS; 810 bat_priv->mcast.flags = BATADV_NO_FLAGS;
820 atomic_set(&bat_priv->multicast_mode, 1); 811 atomic_set(&bat_priv->multicast_mode, 1);
812 atomic_set(&bat_priv->multicast_fanout, 16);
821 atomic_set(&bat_priv->mcast.num_want_all_unsnoopables, 0); 813 atomic_set(&bat_priv->mcast.num_want_all_unsnoopables, 0);
822 atomic_set(&bat_priv->mcast.num_want_all_ipv4, 0); 814 atomic_set(&bat_priv->mcast.num_want_all_ipv4, 0);
823 atomic_set(&bat_priv->mcast.num_want_all_ipv6, 0); 815 atomic_set(&bat_priv->mcast.num_want_all_ipv6, 0);
diff --git a/net/batman-adv/soft-interface.h b/net/batman-adv/soft-interface.h
index 538bb661878c..275442a7acb6 100644
--- a/net/batman-adv/soft-interface.h
+++ b/net/batman-adv/soft-interface.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_SOFT_INTERFACE_H_ 7#ifndef _NET_BATMAN_ADV_SOFT_INTERFACE_H_
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index 208655cf6717..80fc3253c336 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -2,23 +2,12 @@
2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "sysfs.h" 7#include "sysfs.h"
20#include "main.h" 8#include "main.h"
21 9
10#include <asm/current.h>
22#include <linux/atomic.h> 11#include <linux/atomic.h>
23#include <linux/compiler.h> 12#include <linux/compiler.h>
24#include <linux/device.h> 13#include <linux/device.h>
@@ -34,6 +23,7 @@
34#include <linux/rculist.h> 23#include <linux/rculist.h>
35#include <linux/rcupdate.h> 24#include <linux/rcupdate.h>
36#include <linux/rtnetlink.h> 25#include <linux/rtnetlink.h>
26#include <linux/sched.h>
37#include <linux/slab.h> 27#include <linux/slab.h>
38#include <linux/stddef.h> 28#include <linux/stddef.h>
39#include <linux/string.h> 29#include <linux/string.h>
@@ -52,6 +42,16 @@
52#include "network-coding.h" 42#include "network-coding.h"
53#include "soft-interface.h" 43#include "soft-interface.h"
54 44
45/**
46 * batadv_sysfs_deprecated() - Log use of deprecated batadv sysfs access
47 * @attr: attribute which was accessed
48 */
49static void batadv_sysfs_deprecated(struct attribute *attr)
50{
51 pr_warn_ratelimited(DEPRECATED "%s (pid %d) Use of sysfs file \"%s\".\nUse batadv genl family instead",
52 current->comm, task_pid_nr(current), attr->name);
53}
54
55static struct net_device *batadv_kobj_to_netdev(struct kobject *obj) 55static struct net_device *batadv_kobj_to_netdev(struct kobject *obj)
56{ 56{
57 struct device *dev = container_of(obj->parent, struct device, kobj); 57 struct device *dev = container_of(obj->parent, struct device, kobj);
@@ -114,22 +114,6 @@ batadv_kobj_to_vlan(struct batadv_priv *bat_priv, struct kobject *obj)
114 return vlan; 114 return vlan;
115} 115}
116 116
117#define BATADV_UEV_TYPE_VAR "BATTYPE="
118#define BATADV_UEV_ACTION_VAR "BATACTION="
119#define BATADV_UEV_DATA_VAR "BATDATA="
120
121static char *batadv_uev_action_str[] = {
122 "add",
123 "del",
124 "change",
125 "loopdetect",
126};
127
128static char *batadv_uev_type_str[] = {
129 "gw",
130 "bla",
131};
132
133/* Use this, if you have customized show and store functions for vlan attrs */ 117/* Use this, if you have customized show and store functions for vlan attrs */
134#define BATADV_ATTR_VLAN(_name, _mode, _show, _store) \ 118#define BATADV_ATTR_VLAN(_name, _mode, _show, _store) \
135struct batadv_attribute batadv_attr_vlan_##_name = { \ 119struct batadv_attribute batadv_attr_vlan_##_name = { \
@@ -157,6 +141,7 @@ ssize_t batadv_store_##_name(struct kobject *kobj, \
157 struct batadv_priv *bat_priv = netdev_priv(net_dev); \ 141 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
158 ssize_t length; \ 142 ssize_t length; \
159 \ 143 \
144 batadv_sysfs_deprecated(attr); \
160 length = __batadv_store_bool_attr(buff, count, _post_func, attr,\ 145 length = __batadv_store_bool_attr(buff, count, _post_func, attr,\
161 &bat_priv->_name, net_dev); \ 146 &bat_priv->_name, net_dev); \
162 \ 147 \
@@ -171,6 +156,7 @@ ssize_t batadv_show_##_name(struct kobject *kobj, \
171{ \ 156{ \
172 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \ 157 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
173 \ 158 \
159 batadv_sysfs_deprecated(attr); \
174 return sprintf(buff, "%s\n", \ 160 return sprintf(buff, "%s\n", \
175 atomic_read(&bat_priv->_name) == 0 ? \ 161 atomic_read(&bat_priv->_name) == 0 ? \
176 "disabled" : "enabled"); \ 162 "disabled" : "enabled"); \
@@ -194,6 +180,7 @@ ssize_t batadv_store_##_name(struct kobject *kobj, \
194 struct batadv_priv *bat_priv = netdev_priv(net_dev); \ 180 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
195 ssize_t length; \ 181 ssize_t length; \
196 \ 182 \
183 batadv_sysfs_deprecated(attr); \
197 length = __batadv_store_uint_attr(buff, count, _min, _max, \ 184 length = __batadv_store_uint_attr(buff, count, _min, _max, \
198 _post_func, attr, \ 185 _post_func, attr, \
199 &bat_priv->_var, net_dev, \ 186 &bat_priv->_var, net_dev, \
@@ -210,6 +197,7 @@ ssize_t batadv_show_##_name(struct kobject *kobj, \
210{ \ 197{ \
211 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \ 198 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
212 \ 199 \
200 batadv_sysfs_deprecated(attr); \
213 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_var)); \ 201 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_var)); \
214} \ 202} \
215 203
@@ -234,6 +222,7 @@ ssize_t batadv_store_vlan_##_name(struct kobject *kobj, \
234 attr, &vlan->_name, \ 222 attr, &vlan->_name, \
235 bat_priv->soft_iface); \ 223 bat_priv->soft_iface); \
236 \ 224 \
225 batadv_sysfs_deprecated(attr); \
237 if (vlan->vid) \ 226 if (vlan->vid) \
238 batadv_netlink_notify_vlan(bat_priv, vlan); \ 227 batadv_netlink_notify_vlan(bat_priv, vlan); \
239 else \ 228 else \
@@ -254,6 +243,7 @@ ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \
254 atomic_read(&vlan->_name) == 0 ? \ 243 atomic_read(&vlan->_name) == 0 ? \
255 "disabled" : "enabled"); \ 244 "disabled" : "enabled"); \
256 \ 245 \
246 batadv_sysfs_deprecated(attr); \
257 batadv_softif_vlan_put(vlan); \ 247 batadv_softif_vlan_put(vlan); \
258 return res; \ 248 return res; \
259} 249}
@@ -275,6 +265,7 @@ ssize_t batadv_store_##_name(struct kobject *kobj, \
275 struct batadv_priv *bat_priv; \ 265 struct batadv_priv *bat_priv; \
276 ssize_t length; \ 266 ssize_t length; \
277 \ 267 \
268 batadv_sysfs_deprecated(attr); \
278 hard_iface = batadv_hardif_get_by_netdev(net_dev); \ 269 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
279 if (!hard_iface) \ 270 if (!hard_iface) \
280 return 0; \ 271 return 0; \
@@ -302,6 +293,7 @@ ssize_t batadv_show_##_name(struct kobject *kobj, \
302 struct batadv_hard_iface *hard_iface; \ 293 struct batadv_hard_iface *hard_iface; \
303 ssize_t length; \ 294 ssize_t length; \
304 \ 295 \
296 batadv_sysfs_deprecated(attr); \
305 hard_iface = batadv_hardif_get_by_netdev(net_dev); \ 297 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
306 if (!hard_iface) \ 298 if (!hard_iface) \
307 return 0; \ 299 return 0; \
@@ -446,6 +438,7 @@ static ssize_t batadv_show_bat_algo(struct kobject *kobj,
446{ 438{
447 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); 439 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
448 440
441 batadv_sysfs_deprecated(attr);
449 return sprintf(buff, "%s\n", bat_priv->algo_ops->name); 442 return sprintf(buff, "%s\n", bat_priv->algo_ops->name);
450} 443}
451 444
@@ -462,6 +455,8 @@ static ssize_t batadv_show_gw_mode(struct kobject *kobj, struct attribute *attr,
462 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); 455 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
463 int bytes_written; 456 int bytes_written;
464 457
458 batadv_sysfs_deprecated(attr);
459
465 /* GW mode is not available if the routing algorithm in use does not 460 /* GW mode is not available if the routing algorithm in use does not
466 * implement the GW API 461 * implement the GW API
467 */ 462 */
@@ -496,6 +491,8 @@ static ssize_t batadv_store_gw_mode(struct kobject *kobj,
496 char *curr_gw_mode_str; 491 char *curr_gw_mode_str;
497 int gw_mode_tmp = -1; 492 int gw_mode_tmp = -1;
498 493
494 batadv_sysfs_deprecated(attr);
495
499 /* toggling GW mode is allowed only if the routing algorithm in use 496 /* toggling GW mode is allowed only if the routing algorithm in use
500 * provides the GW API 497 * provides the GW API
501 */ 498 */
@@ -570,6 +567,8 @@ static ssize_t batadv_show_gw_sel_class(struct kobject *kobj,
570{ 567{
571 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); 568 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
572 569
570 batadv_sysfs_deprecated(attr);
571
573 /* GW selection class is not available if the routing algorithm in use 572 /* GW selection class is not available if the routing algorithm in use
574 * does not implement the GW API 573 * does not implement the GW API
575 */ 574 */
@@ -590,6 +589,8 @@ static ssize_t batadv_store_gw_sel_class(struct kobject *kobj,
590 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); 589 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
591 ssize_t length; 590 ssize_t length;
592 591
592 batadv_sysfs_deprecated(attr);
593
593 /* setting the GW selection class is allowed only if the routing 594 /* setting the GW selection class is allowed only if the routing
594 * algorithm in use implements the GW API 595 * algorithm in use implements the GW API
595 */ 596 */
@@ -620,6 +621,8 @@ static ssize_t batadv_show_gw_bwidth(struct kobject *kobj,
620 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); 621 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
621 u32 down, up; 622 u32 down, up;
622 623
624 batadv_sysfs_deprecated(attr);
625
623 down = atomic_read(&bat_priv->gw.bandwidth_down); 626 down = atomic_read(&bat_priv->gw.bandwidth_down);
624 up = atomic_read(&bat_priv->gw.bandwidth_up); 627 up = atomic_read(&bat_priv->gw.bandwidth_up);
625 628
@@ -635,6 +638,8 @@ static ssize_t batadv_store_gw_bwidth(struct kobject *kobj,
635 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); 638 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
636 ssize_t length; 639 ssize_t length;
637 640
641 batadv_sysfs_deprecated(attr);
642
638 if (buff[count - 1] == '\n') 643 if (buff[count - 1] == '\n')
639 buff[count - 1] = '\0'; 644 buff[count - 1] = '\0';
640 645
@@ -659,6 +664,7 @@ static ssize_t batadv_show_isolation_mark(struct kobject *kobj,
659{ 664{
660 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); 665 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
661 666
667 batadv_sysfs_deprecated(attr);
662 return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark, 668 return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark,
663 bat_priv->isolation_mark_mask); 669 bat_priv->isolation_mark_mask);
664} 670}
@@ -682,6 +688,8 @@ static ssize_t batadv_store_isolation_mark(struct kobject *kobj,
682 u32 mark, mask; 688 u32 mark, mask;
683 char *mask_ptr; 689 char *mask_ptr;
684 690
691 batadv_sysfs_deprecated(attr);
692
685 /* parse the mask if it has been specified, otherwise assume the mask is 693 /* parse the mask if it has been specified, otherwise assume the mask is
686 * the biggest possible 694 * the biggest possible
687 */ 695 */
@@ -937,6 +945,8 @@ static ssize_t batadv_show_mesh_iface(struct kobject *kobj,
937 ssize_t length; 945 ssize_t length;
938 const char *ifname; 946 const char *ifname;
939 947
948 batadv_sysfs_deprecated(attr);
949
940 hard_iface = batadv_hardif_get_by_netdev(net_dev); 950 hard_iface = batadv_hardif_get_by_netdev(net_dev);
941 if (!hard_iface) 951 if (!hard_iface)
942 return 0; 952 return 0;
@@ -1041,6 +1051,8 @@ static ssize_t batadv_store_mesh_iface(struct kobject *kobj,
1041 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); 1051 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
1042 struct batadv_store_mesh_work *store_work; 1052 struct batadv_store_mesh_work *store_work;
1043 1053
1054 batadv_sysfs_deprecated(attr);
1055
1044 if (buff[count - 1] == '\n') 1056 if (buff[count - 1] == '\n')
1045 buff[count - 1] = '\0'; 1057 buff[count - 1] = '\0';
1046 1058
@@ -1072,6 +1084,8 @@ static ssize_t batadv_show_iface_status(struct kobject *kobj,
1072 struct batadv_hard_iface *hard_iface; 1084 struct batadv_hard_iface *hard_iface;
1073 ssize_t length; 1085 ssize_t length;
1074 1086
1087 batadv_sysfs_deprecated(attr);
1088
1075 hard_iface = batadv_hardif_get_by_netdev(net_dev); 1089 hard_iface = batadv_hardif_get_by_netdev(net_dev);
1076 if (!hard_iface) 1090 if (!hard_iface)
1077 return 0; 1091 return 0;
@@ -1123,6 +1137,8 @@ static ssize_t batadv_store_throughput_override(struct kobject *kobj,
1123 u32 old_tp_override; 1137 u32 old_tp_override;
1124 bool ret; 1138 bool ret;
1125 1139
1140 batadv_sysfs_deprecated(attr);
1141
1126 hard_iface = batadv_hardif_get_by_netdev(net_dev); 1142 hard_iface = batadv_hardif_get_by_netdev(net_dev);
1127 if (!hard_iface) 1143 if (!hard_iface)
1128 return -EINVAL; 1144 return -EINVAL;
@@ -1165,6 +1181,8 @@ static ssize_t batadv_show_throughput_override(struct kobject *kobj,
1165 struct batadv_hard_iface *hard_iface; 1181 struct batadv_hard_iface *hard_iface;
1166 u32 tp_override; 1182 u32 tp_override;
1167 1183
1184 batadv_sysfs_deprecated(attr);
1185
1168 hard_iface = batadv_hardif_get_by_netdev(net_dev); 1186 hard_iface = batadv_hardif_get_by_netdev(net_dev);
1169 if (!hard_iface) 1187 if (!hard_iface)
1170 return -EINVAL; 1188 return -EINVAL;
@@ -1250,57 +1268,3 @@ void batadv_sysfs_del_hardif(struct kobject **hardif_obj)
1250 kobject_put(*hardif_obj); 1268 kobject_put(*hardif_obj);
1251 *hardif_obj = NULL; 1269 *hardif_obj = NULL;
1252} 1270}
1253
1254/**
1255 * batadv_throw_uevent() - Send an uevent with batman-adv specific env data
1256 * @bat_priv: the bat priv with all the soft interface information
1257 * @type: subsystem type of event. Stored in uevent's BATTYPE
1258 * @action: action type of event. Stored in uevent's BATACTION
1259 * @data: string with additional information to the event (ignored for
1260 * BATADV_UEV_DEL). Stored in uevent's BATDATA
1261 *
1262 * Return: 0 on success or negative error number in case of failure
1263 */
1264int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
1265 enum batadv_uev_action action, const char *data)
1266{
1267 int ret = -ENOMEM;
1268 struct kobject *bat_kobj;
1269 char *uevent_env[4] = { NULL, NULL, NULL, NULL };
1270
1271 bat_kobj = &bat_priv->soft_iface->dev.kobj;
1272
1273 uevent_env[0] = kasprintf(GFP_ATOMIC,
1274 "%s%s", BATADV_UEV_TYPE_VAR,
1275 batadv_uev_type_str[type]);
1276 if (!uevent_env[0])
1277 goto out;
1278
1279 uevent_env[1] = kasprintf(GFP_ATOMIC,
1280 "%s%s", BATADV_UEV_ACTION_VAR,
1281 batadv_uev_action_str[action]);
1282 if (!uevent_env[1])
1283 goto out;
1284
1285 /* If the event is DEL, ignore the data field */
1286 if (action != BATADV_UEV_DEL) {
1287 uevent_env[2] = kasprintf(GFP_ATOMIC,
1288 "%s%s", BATADV_UEV_DATA_VAR, data);
1289 if (!uevent_env[2])
1290 goto out;
1291 }
1292
1293 ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
1294out:
1295 kfree(uevent_env[0]);
1296 kfree(uevent_env[1]);
1297 kfree(uevent_env[2]);
1298
1299 if (ret)
1300 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1301 "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
1302 batadv_uev_type_str[type],
1303 batadv_uev_action_str[action],
1304 (action == BATADV_UEV_DEL ? "NULL" : data), ret);
1305 return ret;
1306}
diff --git a/net/batman-adv/sysfs.h b/net/batman-adv/sysfs.h
index 705ffbe763f4..83fa808b1871 100644
--- a/net/batman-adv/sysfs.h
+++ b/net/batman-adv/sysfs.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner 4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_SYSFS_H_ 7#ifndef _NET_BATMAN_ADV_SYSFS_H_
@@ -57,6 +45,8 @@ struct batadv_attribute {
57 char *buf, size_t count); 45 char *buf, size_t count);
58}; 46};
59 47
48#ifdef CONFIG_BATMAN_ADV_SYSFS
49
60int batadv_sysfs_add_meshif(struct net_device *dev); 50int batadv_sysfs_add_meshif(struct net_device *dev);
61void batadv_sysfs_del_meshif(struct net_device *dev); 51void batadv_sysfs_del_meshif(struct net_device *dev);
62int batadv_sysfs_add_hardif(struct kobject **hardif_obj, 52int batadv_sysfs_add_hardif(struct kobject **hardif_obj,
@@ -66,7 +56,39 @@ int batadv_sysfs_add_vlan(struct net_device *dev,
66 struct batadv_softif_vlan *vlan); 56 struct batadv_softif_vlan *vlan);
67void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv, 57void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv,
68 struct batadv_softif_vlan *vlan); 58 struct batadv_softif_vlan *vlan);
69int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, 59
70 enum batadv_uev_action action, const char *data); 60#else
61
62static inline int batadv_sysfs_add_meshif(struct net_device *dev)
63{
64 return 0;
65}
66
67static inline void batadv_sysfs_del_meshif(struct net_device *dev)
68{
69}
70
71static inline int batadv_sysfs_add_hardif(struct kobject **hardif_obj,
72 struct net_device *dev)
73{
74 return 0;
75}
76
77static inline void batadv_sysfs_del_hardif(struct kobject **hardif_obj)
78{
79}
80
81static inline int batadv_sysfs_add_vlan(struct net_device *dev,
82 struct batadv_softif_vlan *vlan)
83{
84 return 0;
85}
86
87static inline void batadv_sysfs_del_vlan(struct batadv_priv *bat_priv,
88 struct batadv_softif_vlan *vlan)
89{
90}
91
92#endif
71 93
72#endif /* _NET_BATMAN_ADV_SYSFS_H_ */ 94#endif /* _NET_BATMAN_ADV_SYSFS_H_ */
diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c
index 500109bbd551..820392146249 100644
--- a/net/batman-adv/tp_meter.c
+++ b/net/batman-adv/tp_meter.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2012-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2012-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Edo Monticelli, Antonio Quartulli 4 * Edo Monticelli, Antonio Quartulli
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "tp_meter.h" 7#include "tp_meter.h"
diff --git a/net/batman-adv/tp_meter.h b/net/batman-adv/tp_meter.h
index 6b4d0f733896..604b3799c972 100644
--- a/net/batman-adv/tp_meter.h
+++ b/net/batman-adv/tp_meter.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2012-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2012-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Edo Monticelli, Antonio Quartulli 4 * Edo Monticelli, Antonio Quartulli
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_TP_METER_H_ 7#ifndef _NET_BATMAN_ADV_TP_METER_H_
diff --git a/net/batman-adv/trace.c b/net/batman-adv/trace.c
index f77c917ed20d..3cedd2c36528 100644
--- a/net/batman-adv/trace.c
+++ b/net/batman-adv/trace.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Sven Eckelmann 4 * Sven Eckelmann
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#define CREATE_TRACE_POINTS 7#define CREATE_TRACE_POINTS
diff --git a/net/batman-adv/trace.h b/net/batman-adv/trace.h
index 5e5579051400..d8f764521c0b 100644
--- a/net/batman-adv/trace.h
+++ b/net/batman-adv/trace.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Sven Eckelmann 4 * Sven Eckelmann
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#if !defined(_NET_BATMAN_ADV_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ) 7#if !defined(_NET_BATMAN_ADV_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 26c4e2493ddf..1ddfd5e011ee 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich, Antonio Quartulli 4 * Marek Lindner, Simon Wunderlich, Antonio Quartulli
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "translation-table.h" 7#include "translation-table.h"
@@ -205,7 +193,7 @@ batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
205 * Return: a pointer to the corresponding tt_global_entry struct if the client 193 * Return: a pointer to the corresponding tt_global_entry struct if the client
206 * is found, NULL otherwise. 194 * is found, NULL otherwise.
207 */ 195 */
208static struct batadv_tt_global_entry * 196struct batadv_tt_global_entry *
209batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr, 197batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
210 unsigned short vid) 198 unsigned short vid)
211{ 199{
@@ -300,8 +288,7 @@ static void batadv_tt_global_entry_release(struct kref *ref)
300 * possibly release it 288 * possibly release it
301 * @tt_global_entry: tt_global_entry to be free'd 289 * @tt_global_entry: tt_global_entry to be free'd
302 */ 290 */
303static void 291void batadv_tt_global_entry_put(struct batadv_tt_global_entry *tt_global_entry)
304batadv_tt_global_entry_put(struct batadv_tt_global_entry *tt_global_entry)
305{ 292{
306 kref_put(&tt_global_entry->common.refcount, 293 kref_put(&tt_global_entry->common.refcount,
307 batadv_tt_global_entry_release); 294 batadv_tt_global_entry_release);
diff --git a/net/batman-adv/translation-table.h b/net/batman-adv/translation-table.h
index 61bca75e5911..c8c48d62a430 100644
--- a/net/batman-adv/translation-table.h
+++ b/net/batman-adv/translation-table.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich, Antonio Quartulli 4 * Marek Lindner, Simon Wunderlich, Antonio Quartulli
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ 7#ifndef _NET_BATMAN_ADV_TRANSLATION_TABLE_H_
@@ -41,6 +29,10 @@ int batadv_tt_global_dump(struct sk_buff *msg, struct netlink_callback *cb);
41void batadv_tt_global_del_orig(struct batadv_priv *bat_priv, 29void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
42 struct batadv_orig_node *orig_node, 30 struct batadv_orig_node *orig_node,
43 s32 match_vid, const char *message); 31 s32 match_vid, const char *message);
32struct batadv_tt_global_entry *
33batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
34 unsigned short vid);
35void batadv_tt_global_entry_put(struct batadv_tt_global_entry *tt_global_entry);
44int batadv_tt_global_hash_count(struct batadv_priv *bat_priv, 36int batadv_tt_global_hash_count(struct batadv_priv *bat_priv,
45 const u8 *addr, unsigned short vid); 37 const u8 *addr, unsigned short vid);
46struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv, 38struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 7e947b01919d..aae63f0d21eb 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#include "main.h" 7#include "main.h"
diff --git a/net/batman-adv/tvlv.h b/net/batman-adv/tvlv.h
index c0f033b1acb8..114ac01e06af 100644
--- a/net/batman-adv/tvlv.h
+++ b/net/batman-adv/tvlv.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_TVLV_H_ 7#ifndef _NET_BATMAN_ADV_TVLV_H_
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index a21b34ed6548..74b644738a36 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -2,18 +2,6 @@
2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 2/* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors:
3 * 3 *
4 * Marek Lindner, Simon Wunderlich 4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */ 5 */
18 6
19#ifndef _NET_BATMAN_ADV_TYPES_H_ 7#ifndef _NET_BATMAN_ADV_TYPES_H_
@@ -1224,6 +1212,11 @@ struct batadv_priv_mcast {
1224 unsigned char bridged:1; 1212 unsigned char bridged:1;
1225 1213
1226 /** 1214 /**
1215 * @mla_lock: a lock protecting mla_list and mla_flags
1216 */
1217 spinlock_t mla_lock;
1218
1219 /**
1227 * @num_want_all_unsnoopables: number of nodes wanting unsnoopable IP 1220 * @num_want_all_unsnoopables: number of nodes wanting unsnoopable IP
1228 * traffic 1221 * traffic
1229 */ 1222 */
@@ -1565,6 +1558,12 @@ struct batadv_priv {
1565 * node's sender/originating side 1558 * node's sender/originating side
1566 */ 1559 */
1567 atomic_t multicast_mode; 1560 atomic_t multicast_mode;
1561
1562 /**
1563 * @multicast_fanout: Maximum number of packet copies to generate for a
1564 * multicast-to-unicast conversion
1565 */
1566 atomic_t multicast_fanout;
1568#endif 1567#endif
1569 1568
1570 /** @orig_interval: OGM broadcast interval in milliseconds */ 1569 /** @orig_interval: OGM broadcast interval in milliseconds */
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 8d12198eaa94..94ddf19998c7 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -521,14 +521,6 @@ int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
521 err = put_user(amount, (int __user *) arg); 521 err = put_user(amount, (int __user *) arg);
522 break; 522 break;
523 523
524 case SIOCGSTAMP:
525 err = sock_get_timestamp(sk, (struct timeval __user *) arg);
526 break;
527
528 case SIOCGSTAMPNS:
529 err = sock_get_timestampns(sk, (struct timespec __user *) arg);
530 break;
531
532 default: 524 default:
533 err = -ENOIOCTLCMD; 525 err = -ENOIOCTLCMD;
534 break; 526 break;
diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c
index 78bec8df8525..aaa39409eeb7 100644
--- a/net/bluetooth/amp.c
+++ b/net/bluetooth/amp.c
@@ -161,7 +161,6 @@ static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
161 } 161 }
162 162
163 shash->tfm = tfm; 163 shash->tfm = tfm;
164 shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
165 164
166 ret = crypto_shash_digest(shash, plaintext, psize, output); 165 ret = crypto_shash_digest(shash, plaintext, psize, output);
167 166
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index bd4978ce8c45..3cf0764d5793 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1276,6 +1276,14 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
1276 !test_bit(HCI_CONN_ENCRYPT, &conn->flags)) 1276 !test_bit(HCI_CONN_ENCRYPT, &conn->flags))
1277 return 0; 1277 return 0;
1278 1278
1279 /* The minimum encryption key size needs to be enforced by the
1280 * host stack before establishing any L2CAP connections. The
1281 * specification in theory allows a minimum of 1, but to align
1282 * BR/EDR and LE transports, a minimum of 7 is chosen.
1283 */
1284 if (conn->enc_key_size < HCI_MIN_ENC_KEY_SIZE)
1285 return 0;
1286
1279 return 1; 1287 return 1;
1280} 1288}
1281 1289
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d6b2540ba7f8..b81bf53c5ac4 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1460,8 +1460,6 @@ static int hci_dev_do_open(struct hci_dev *hdev)
1460 hdev->set_bdaddr) 1460 hdev->set_bdaddr)
1461 ret = hdev->set_bdaddr(hdev, 1461 ret = hdev->set_bdaddr(hdev,
1462 &hdev->public_addr); 1462 &hdev->public_addr);
1463 else
1464 ret = -EADDRNOTAVAIL;
1465 } 1463 }
1466 1464
1467setup_failed: 1465setup_failed:
@@ -4383,6 +4381,9 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status,
4383 return; 4381 return;
4384 } 4382 }
4385 4383
4384 /* If we reach this point this event matches the last command sent */
4385 hci_dev_clear_flag(hdev, HCI_CMD_PENDING);
4386
4386 /* If the command succeeded and there's still more commands in 4387 /* If the command succeeded and there's still more commands in
4387 * this request the request is not yet complete. 4388 * this request the request is not yet complete.
4388 */ 4389 */
@@ -4493,6 +4494,8 @@ static void hci_cmd_work(struct work_struct *work)
4493 4494
4494 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); 4495 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL);
4495 if (hdev->sent_cmd) { 4496 if (hdev->sent_cmd) {
4497 if (hci_req_status_pend(hdev))
4498 hci_dev_set_flag(hdev, HCI_CMD_PENDING);
4496 atomic_dec(&hdev->cmd_cnt); 4499 atomic_dec(&hdev->cmd_cnt);
4497 hci_send_frame(hdev, skb); 4500 hci_send_frame(hdev, skb);
4498 if (test_bit(HCI_RESET, &hdev->flags)) 4501 if (test_bit(HCI_RESET, &hdev->flags))
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 609fd6871c5a..9e4fcf406d9c 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3404,6 +3404,12 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
3404 hci_req_cmd_complete(hdev, *opcode, *status, req_complete, 3404 hci_req_cmd_complete(hdev, *opcode, *status, req_complete,
3405 req_complete_skb); 3405 req_complete_skb);
3406 3406
3407 if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) {
3408 bt_dev_err(hdev,
3409 "unexpected event for opcode 0x%4.4x", *opcode);
3410 return;
3411 }
3412
3407 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) 3413 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q))
3408 queue_work(hdev->workqueue, &hdev->cmd_work); 3414 queue_work(hdev->workqueue, &hdev->cmd_work);
3409} 3415}
@@ -3511,6 +3517,12 @@ static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb,
3511 hci_req_cmd_complete(hdev, *opcode, ev->status, req_complete, 3517 hci_req_cmd_complete(hdev, *opcode, ev->status, req_complete,
3512 req_complete_skb); 3518 req_complete_skb);
3513 3519
3520 if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) {
3521 bt_dev_err(hdev,
3522 "unexpected event for opcode 0x%4.4x", *opcode);
3523 return;
3524 }
3525
3514 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) 3526 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q))
3515 queue_work(hdev->workqueue, &hdev->cmd_work); 3527 queue_work(hdev->workqueue, &hdev->cmd_work);
3516} 3528}
@@ -5433,7 +5445,7 @@ static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
5433 ev->data, ev->length); 5445 ev->data, ev->length);
5434 } 5446 }
5435 5447
5436 ptr += sizeof(*ev) + ev->length + 1; 5448 ptr += sizeof(*ev) + ev->length;
5437 } 5449 }
5438 5450
5439 hci_dev_unlock(hdev); 5451 hci_dev_unlock(hdev);
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index ca73d36cc149..e9a95ed65491 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -46,6 +46,11 @@ void hci_req_purge(struct hci_request *req)
46 skb_queue_purge(&req->cmd_q); 46 skb_queue_purge(&req->cmd_q);
47} 47}
48 48
49bool hci_req_status_pend(struct hci_dev *hdev)
50{
51 return hdev->req_status == HCI_REQ_PEND;
52}
53
49static int req_run(struct hci_request *req, hci_req_complete_t complete, 54static int req_run(struct hci_request *req, hci_req_complete_t complete,
50 hci_req_complete_skb_t complete_skb) 55 hci_req_complete_skb_t complete_skb)
51{ 56{
diff --git a/net/bluetooth/hci_request.h b/net/bluetooth/hci_request.h
index 692cc8b13368..55b2050cc9ff 100644
--- a/net/bluetooth/hci_request.h
+++ b/net/bluetooth/hci_request.h
@@ -37,6 +37,7 @@ struct hci_request {
37 37
38void hci_req_init(struct hci_request *req, struct hci_dev *hdev); 38void hci_req_init(struct hci_request *req, struct hci_dev *hdev);
39void hci_req_purge(struct hci_request *req); 39void hci_req_purge(struct hci_request *req);
40bool hci_req_status_pend(struct hci_dev *hdev);
40int hci_req_run(struct hci_request *req, hci_req_complete_t complete); 41int hci_req_run(struct hci_request *req, hci_req_complete_t complete);
41int hci_req_run_skb(struct hci_request *req, hci_req_complete_skb_t complete); 42int hci_req_run_skb(struct hci_request *req, hci_req_complete_skb_t complete);
42void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, 43void hci_req_add(struct hci_request *req, u16 opcode, u32 plen,
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index 9f85a1943be9..2151913892ce 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -75,6 +75,7 @@ static int do_hidp_sock_ioctl(struct socket *sock, unsigned int cmd, void __user
75 sockfd_put(csock); 75 sockfd_put(csock);
76 return err; 76 return err;
77 } 77 }
78 ca.name[sizeof(ca.name)-1] = 0;
78 79
79 err = hidp_connection_add(&ca, csock, isock); 80 err = hidp_connection_add(&ca, csock, isock);
80 if (!err && copy_to_user(argp, &ca, sizeof(ca))) 81 if (!err && copy_to_user(argp, &ca, sizeof(ca)))
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index f17e393b43b4..b53acd6c9a3d 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -510,12 +510,12 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan)
510} 510}
511EXPORT_SYMBOL_GPL(l2cap_chan_set_defaults); 511EXPORT_SYMBOL_GPL(l2cap_chan_set_defaults);
512 512
513static void l2cap_le_flowctl_init(struct l2cap_chan *chan) 513static void l2cap_le_flowctl_init(struct l2cap_chan *chan, u16 tx_credits)
514{ 514{
515 chan->sdu = NULL; 515 chan->sdu = NULL;
516 chan->sdu_last_frag = NULL; 516 chan->sdu_last_frag = NULL;
517 chan->sdu_len = 0; 517 chan->sdu_len = 0;
518 chan->tx_credits = 0; 518 chan->tx_credits = tx_credits;
519 /* Derive MPS from connection MTU to stop HCI fragmentation */ 519 /* Derive MPS from connection MTU to stop HCI fragmentation */
520 chan->mps = min_t(u16, chan->imtu, chan->conn->mtu - L2CAP_HDR_SIZE); 520 chan->mps = min_t(u16, chan->imtu, chan->conn->mtu - L2CAP_HDR_SIZE);
521 /* Give enough credits for a full packet */ 521 /* Give enough credits for a full packet */
@@ -1281,7 +1281,7 @@ static void l2cap_le_connect(struct l2cap_chan *chan)
1281 if (test_and_set_bit(FLAG_LE_CONN_REQ_SENT, &chan->flags)) 1281 if (test_and_set_bit(FLAG_LE_CONN_REQ_SENT, &chan->flags))
1282 return; 1282 return;
1283 1283
1284 l2cap_le_flowctl_init(chan); 1284 l2cap_le_flowctl_init(chan, 0);
1285 1285
1286 req.psm = chan->psm; 1286 req.psm = chan->psm;
1287 req.scid = cpu_to_le16(chan->scid); 1287 req.scid = cpu_to_le16(chan->scid);
@@ -5532,11 +5532,10 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
5532 chan->dcid = scid; 5532 chan->dcid = scid;
5533 chan->omtu = mtu; 5533 chan->omtu = mtu;
5534 chan->remote_mps = mps; 5534 chan->remote_mps = mps;
5535 chan->tx_credits = __le16_to_cpu(req->credits);
5536 5535
5537 __l2cap_chan_add(conn, chan); 5536 __l2cap_chan_add(conn, chan);
5538 5537
5539 l2cap_le_flowctl_init(chan); 5538 l2cap_le_flowctl_init(chan, __le16_to_cpu(req->credits));
5540 5539
5541 dcid = chan->scid; 5540 dcid = chan->scid;
5542 credits = chan->rx_credits; 5541 credits = chan->rx_credits;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index a3a2cd55e23a..a7be8b59b3c2 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -791,10 +791,13 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
791 791
792 conn = chan->conn; 792 conn = chan->conn;
793 793
794 /*change security for LE channels */ 794 /* change security for LE channels */
795 if (chan->scid == L2CAP_CID_ATT) { 795 if (chan->scid == L2CAP_CID_ATT) {
796 if (smp_conn_security(conn->hcon, sec.level)) 796 if (smp_conn_security(conn->hcon, sec.level)) {
797 err = -EINVAL;
797 break; 798 break;
799 }
800
798 set_bit(FLAG_PENDING_SECURITY, &chan->flags); 801 set_bit(FLAG_PENDING_SECURITY, &chan->flags);
799 sk->sk_state = BT_CONFIG; 802 sk->sk_state = BT_CONFIG;
800 chan->state = BT_CONFIG; 803 chan->state = BT_CONFIG;
@@ -1655,6 +1658,7 @@ static const struct proto_ops l2cap_sock_ops = {
1655 .recvmsg = l2cap_sock_recvmsg, 1658 .recvmsg = l2cap_sock_recvmsg,
1656 .poll = bt_sock_poll, 1659 .poll = bt_sock_poll,
1657 .ioctl = bt_sock_ioctl, 1660 .ioctl = bt_sock_ioctl,
1661 .gettstamp = sock_gettstamp,
1658 .mmap = sock_no_mmap, 1662 .mmap = sock_no_mmap,
1659 .socketpair = sock_no_socketpair, 1663 .socketpair = sock_no_socketpair,
1660 .shutdown = l2cap_sock_shutdown, 1664 .shutdown = l2cap_sock_shutdown,
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 2457f408d17d..150114e33b20 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2301,8 +2301,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
2301 MGMT_STATUS_INVALID_PARAMS); 2301 MGMT_STATUS_INVALID_PARAMS);
2302 } 2302 }
2303 2303
2304 expected_len = sizeof(*cp) + key_count * 2304 expected_len = struct_size(cp, keys, key_count);
2305 sizeof(struct mgmt_link_key_info);
2306 if (expected_len != len) { 2305 if (expected_len != len) {
2307 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", 2306 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes",
2308 expected_len, len); 2307 expected_len, len);
@@ -5030,7 +5029,7 @@ static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data,
5030 MGMT_STATUS_INVALID_PARAMS); 5029 MGMT_STATUS_INVALID_PARAMS);
5031 } 5030 }
5032 5031
5033 expected_len = sizeof(*cp) + irk_count * sizeof(struct mgmt_irk_info); 5032 expected_len = struct_size(cp, irks, irk_count);
5034 if (expected_len != len) { 5033 if (expected_len != len) {
5035 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", 5034 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes",
5036 expected_len, len); 5035 expected_len, len);
@@ -5112,8 +5111,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
5112 MGMT_STATUS_INVALID_PARAMS); 5111 MGMT_STATUS_INVALID_PARAMS);
5113 } 5112 }
5114 5113
5115 expected_len = sizeof(*cp) + key_count * 5114 expected_len = struct_size(cp, keys, key_count);
5116 sizeof(struct mgmt_ltk_info);
5117 if (expected_len != len) { 5115 if (expected_len != len) {
5118 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", 5116 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes",
5119 expected_len, len); 5117 expected_len, len);
@@ -5847,8 +5845,7 @@ static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data,
5847 MGMT_STATUS_INVALID_PARAMS); 5845 MGMT_STATUS_INVALID_PARAMS);
5848 } 5846 }
5849 5847
5850 expected_len = sizeof(*cp) + param_count * 5848 expected_len = struct_size(cp, params, param_count);
5851 sizeof(struct mgmt_conn_param);
5852 if (expected_len != len) { 5849 if (expected_len != len) {
5853 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", 5850 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes",
5854 expected_len, len); 5851 expected_len, len);
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index b1f49fcc0478..90bb53aa4bee 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -1039,6 +1039,7 @@ static const struct proto_ops rfcomm_sock_ops = {
1039 .setsockopt = rfcomm_sock_setsockopt, 1039 .setsockopt = rfcomm_sock_setsockopt,
1040 .getsockopt = rfcomm_sock_getsockopt, 1040 .getsockopt = rfcomm_sock_getsockopt,
1041 .ioctl = rfcomm_sock_ioctl, 1041 .ioctl = rfcomm_sock_ioctl,
1042 .gettstamp = sock_gettstamp,
1042 .poll = bt_sock_poll, 1043 .poll = bt_sock_poll,
1043 .socketpair = sock_no_socketpair, 1044 .socketpair = sock_no_socketpair,
1044 .mmap = sock_no_mmap 1045 .mmap = sock_no_mmap
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 9a580999ca57..b91d6b440fdf 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -523,12 +523,12 @@ static int sco_sock_bind(struct socket *sock, struct sockaddr *addr,
523 struct sock *sk = sock->sk; 523 struct sock *sk = sock->sk;
524 int err = 0; 524 int err = 0;
525 525
526 BT_DBG("sk %p %pMR", sk, &sa->sco_bdaddr);
527
528 if (!addr || addr_len < sizeof(struct sockaddr_sco) || 526 if (!addr || addr_len < sizeof(struct sockaddr_sco) ||
529 addr->sa_family != AF_BLUETOOTH) 527 addr->sa_family != AF_BLUETOOTH)
530 return -EINVAL; 528 return -EINVAL;
531 529
530 BT_DBG("sk %p %pMR", sk, &sa->sco_bdaddr);
531
532 lock_sock(sk); 532 lock_sock(sk);
533 533
534 if (sk->sk_state != BT_OPEN) { 534 if (sk->sk_state != BT_OPEN) {
@@ -1190,6 +1190,7 @@ static const struct proto_ops sco_sock_ops = {
1190 .recvmsg = sco_sock_recvmsg, 1190 .recvmsg = sco_sock_recvmsg,
1191 .poll = bt_sock_poll, 1191 .poll = bt_sock_poll,
1192 .ioctl = bt_sock_ioctl, 1192 .ioctl = bt_sock_ioctl,
1193 .gettstamp = sock_gettstamp,
1193 .mmap = sock_no_mmap, 1194 .mmap = sock_no_mmap,
1194 .socketpair = sock_no_socketpair, 1195 .socketpair = sock_no_socketpair,
1195 .shutdown = sco_sock_shutdown, 1196 .shutdown = sco_sock_shutdown,
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 621146d04c03..e68c715f8d37 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -183,7 +183,6 @@ static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m,
183 } 183 }
184 184
185 desc->tfm = tfm; 185 desc->tfm = tfm;
186 desc->flags = 0;
187 186
188 /* Swap key and message from LSB to MSB */ 187 /* Swap key and message from LSB to MSB */
189 swap_buf(k, tmp, 16); 188 swap_buf(k, tmp, 16);
diff --git a/net/bpf/Makefile b/net/bpf/Makefile
index 27b2992a0692..b0ca361742e4 100644
--- a/net/bpf/Makefile
+++ b/net/bpf/Makefile
@@ -1 +1 @@
obj-y := test_run.o obj-$(CONFIG_BPF_SYSCALL) := test_run.o
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index fab142b796ef..33e0dc168c16 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -10,9 +10,13 @@
10#include <linux/etherdevice.h> 10#include <linux/etherdevice.h>
11#include <linux/filter.h> 11#include <linux/filter.h>
12#include <linux/sched/signal.h> 12#include <linux/sched/signal.h>
13#include <net/bpf_sk_storage.h>
13#include <net/sock.h> 14#include <net/sock.h>
14#include <net/tcp.h> 15#include <net/tcp.h>
15 16
17#define CREATE_TRACE_POINTS
18#include <trace/events/bpf_test_run.h>
19
16static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat, 20static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,
17 u32 *retval, u32 *time) 21 u32 *retval, u32 *time)
18{ 22{
@@ -100,6 +104,7 @@ static int bpf_test_finish(const union bpf_attr *kattr,
100 if (err != -ENOSPC) 104 if (err != -ENOSPC)
101 err = 0; 105 err = 0;
102out: 106out:
107 trace_bpf_test_finish(&err);
103 return err; 108 return err;
104} 109}
105 110
@@ -123,12 +128,126 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 size,
123 return data; 128 return data;
124} 129}
125 130
131static void *bpf_ctx_init(const union bpf_attr *kattr, u32 max_size)
132{
133 void __user *data_in = u64_to_user_ptr(kattr->test.ctx_in);
134 void __user *data_out = u64_to_user_ptr(kattr->test.ctx_out);
135 u32 size = kattr->test.ctx_size_in;
136 void *data;
137 int err;
138
139 if (!data_in && !data_out)
140 return NULL;
141
142 data = kzalloc(max_size, GFP_USER);
143 if (!data)
144 return ERR_PTR(-ENOMEM);
145
146 if (data_in) {
147 err = bpf_check_uarg_tail_zero(data_in, max_size, size);
148 if (err) {
149 kfree(data);
150 return ERR_PTR(err);
151 }
152
153 size = min_t(u32, max_size, size);
154 if (copy_from_user(data, data_in, size)) {
155 kfree(data);
156 return ERR_PTR(-EFAULT);
157 }
158 }
159 return data;
160}
161
162static int bpf_ctx_finish(const union bpf_attr *kattr,
163 union bpf_attr __user *uattr, const void *data,
164 u32 size)
165{
166 void __user *data_out = u64_to_user_ptr(kattr->test.ctx_out);
167 int err = -EFAULT;
168 u32 copy_size = size;
169
170 if (!data || !data_out)
171 return 0;
172
173 if (copy_size > kattr->test.ctx_size_out) {
174 copy_size = kattr->test.ctx_size_out;
175 err = -ENOSPC;
176 }
177
178 if (copy_to_user(data_out, data, copy_size))
179 goto out;
180 if (copy_to_user(&uattr->test.ctx_size_out, &size, sizeof(size)))
181 goto out;
182 if (err != -ENOSPC)
183 err = 0;
184out:
185 return err;
186}
187
188/**
189 * range_is_zero - test whether buffer is initialized
190 * @buf: buffer to check
191 * @from: check from this position
192 * @to: check up until (excluding) this position
193 *
194 * This function returns true if the there is a non-zero byte
195 * in the buf in the range [from,to).
196 */
197static inline bool range_is_zero(void *buf, size_t from, size_t to)
198{
199 return !memchr_inv((u8 *)buf + from, 0, to - from);
200}
201
202static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
203{
204 struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb;
205
206 if (!__skb)
207 return 0;
208
209 /* make sure the fields we don't use are zeroed */
210 if (!range_is_zero(__skb, 0, offsetof(struct __sk_buff, priority)))
211 return -EINVAL;
212
213 /* priority is allowed */
214
215 if (!range_is_zero(__skb, offsetof(struct __sk_buff, priority) +
216 FIELD_SIZEOF(struct __sk_buff, priority),
217 offsetof(struct __sk_buff, cb)))
218 return -EINVAL;
219
220 /* cb is allowed */
221
222 if (!range_is_zero(__skb, offsetof(struct __sk_buff, cb) +
223 FIELD_SIZEOF(struct __sk_buff, cb),
224 sizeof(struct __sk_buff)))
225 return -EINVAL;
226
227 skb->priority = __skb->priority;
228 memcpy(&cb->data, __skb->cb, QDISC_CB_PRIV_LEN);
229
230 return 0;
231}
232
233static void convert_skb_to___skb(struct sk_buff *skb, struct __sk_buff *__skb)
234{
235 struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb;
236
237 if (!__skb)
238 return;
239
240 __skb->priority = skb->priority;
241 memcpy(__skb->cb, &cb->data, QDISC_CB_PRIV_LEN);
242}
243
126int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, 244int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
127 union bpf_attr __user *uattr) 245 union bpf_attr __user *uattr)
128{ 246{
129 bool is_l2 = false, is_direct_pkt_access = false; 247 bool is_l2 = false, is_direct_pkt_access = false;
130 u32 size = kattr->test.data_size_in; 248 u32 size = kattr->test.data_size_in;
131 u32 repeat = kattr->test.repeat; 249 u32 repeat = kattr->test.repeat;
250 struct __sk_buff *ctx = NULL;
132 u32 retval, duration; 251 u32 retval, duration;
133 int hh_len = ETH_HLEN; 252 int hh_len = ETH_HLEN;
134 struct sk_buff *skb; 253 struct sk_buff *skb;
@@ -141,6 +260,12 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
141 if (IS_ERR(data)) 260 if (IS_ERR(data))
142 return PTR_ERR(data); 261 return PTR_ERR(data);
143 262
263 ctx = bpf_ctx_init(kattr, sizeof(struct __sk_buff));
264 if (IS_ERR(ctx)) {
265 kfree(data);
266 return PTR_ERR(ctx);
267 }
268
144 switch (prog->type) { 269 switch (prog->type) {
145 case BPF_PROG_TYPE_SCHED_CLS: 270 case BPF_PROG_TYPE_SCHED_CLS:
146 case BPF_PROG_TYPE_SCHED_ACT: 271 case BPF_PROG_TYPE_SCHED_ACT:
@@ -158,6 +283,7 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
158 sk = kzalloc(sizeof(struct sock), GFP_USER); 283 sk = kzalloc(sizeof(struct sock), GFP_USER);
159 if (!sk) { 284 if (!sk) {
160 kfree(data); 285 kfree(data);
286 kfree(ctx);
161 return -ENOMEM; 287 return -ENOMEM;
162 } 288 }
163 sock_net_set(sk, current->nsproxy->net_ns); 289 sock_net_set(sk, current->nsproxy->net_ns);
@@ -166,6 +292,7 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
166 skb = build_skb(data, 0); 292 skb = build_skb(data, 0);
167 if (!skb) { 293 if (!skb) {
168 kfree(data); 294 kfree(data);
295 kfree(ctx);
169 kfree(sk); 296 kfree(sk);
170 return -ENOMEM; 297 return -ENOMEM;
171 } 298 }
@@ -180,32 +307,38 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
180 __skb_push(skb, hh_len); 307 __skb_push(skb, hh_len);
181 if (is_direct_pkt_access) 308 if (is_direct_pkt_access)
182 bpf_compute_data_pointers(skb); 309 bpf_compute_data_pointers(skb);
310 ret = convert___skb_to_skb(skb, ctx);
311 if (ret)
312 goto out;
183 ret = bpf_test_run(prog, skb, repeat, &retval, &duration); 313 ret = bpf_test_run(prog, skb, repeat, &retval, &duration);
184 if (ret) { 314 if (ret)
185 kfree_skb(skb); 315 goto out;
186 kfree(sk);
187 return ret;
188 }
189 if (!is_l2) { 316 if (!is_l2) {
190 if (skb_headroom(skb) < hh_len) { 317 if (skb_headroom(skb) < hh_len) {
191 int nhead = HH_DATA_ALIGN(hh_len - skb_headroom(skb)); 318 int nhead = HH_DATA_ALIGN(hh_len - skb_headroom(skb));
192 319
193 if (pskb_expand_head(skb, nhead, 0, GFP_USER)) { 320 if (pskb_expand_head(skb, nhead, 0, GFP_USER)) {
194 kfree_skb(skb); 321 ret = -ENOMEM;
195 kfree(sk); 322 goto out;
196 return -ENOMEM;
197 } 323 }
198 } 324 }
199 memset(__skb_push(skb, hh_len), 0, hh_len); 325 memset(__skb_push(skb, hh_len), 0, hh_len);
200 } 326 }
327 convert_skb_to___skb(skb, ctx);
201 328
202 size = skb->len; 329 size = skb->len;
203 /* bpf program can never convert linear skb to non-linear */ 330 /* bpf program can never convert linear skb to non-linear */
204 if (WARN_ON_ONCE(skb_is_nonlinear(skb))) 331 if (WARN_ON_ONCE(skb_is_nonlinear(skb)))
205 size = skb_headlen(skb); 332 size = skb_headlen(skb);
206 ret = bpf_test_finish(kattr, uattr, skb->data, size, retval, duration); 333 ret = bpf_test_finish(kattr, uattr, skb->data, size, retval, duration);
334 if (!ret)
335 ret = bpf_ctx_finish(kattr, uattr, ctx,
336 sizeof(struct __sk_buff));
337out:
207 kfree_skb(skb); 338 kfree_skb(skb);
339 bpf_sk_storage_free(sk);
208 kfree(sk); 340 kfree(sk);
341 kfree(ctx);
209 return ret; 342 return ret;
210} 343}
211 344
@@ -220,6 +353,9 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
220 void *data; 353 void *data;
221 int ret; 354 int ret;
222 355
356 if (kattr->test.ctx_in || kattr->test.ctx_out)
357 return -EINVAL;
358
223 data = bpf_test_init(kattr, size, XDP_PACKET_HEADROOM + NET_IP_ALIGN, 0); 359 data = bpf_test_init(kattr, size, XDP_PACKET_HEADROOM + NET_IP_ALIGN, 0);
224 if (IS_ERR(data)) 360 if (IS_ERR(data))
225 return PTR_ERR(data); 361 return PTR_ERR(data);
@@ -249,13 +385,12 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
249 union bpf_attr __user *uattr) 385 union bpf_attr __user *uattr)
250{ 386{
251 u32 size = kattr->test.data_size_in; 387 u32 size = kattr->test.data_size_in;
388 struct bpf_flow_dissector ctx = {};
252 u32 repeat = kattr->test.repeat; 389 u32 repeat = kattr->test.repeat;
253 struct bpf_flow_keys flow_keys; 390 struct bpf_flow_keys flow_keys;
254 u64 time_start, time_spent = 0; 391 u64 time_start, time_spent = 0;
255 struct bpf_skb_data_end *cb; 392 const struct ethhdr *eth;
256 u32 retval, duration; 393 u32 retval, duration;
257 struct sk_buff *skb;
258 struct sock *sk;
259 void *data; 394 void *data;
260 int ret; 395 int ret;
261 u32 i; 396 u32 i;
@@ -263,46 +398,31 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
263 if (prog->type != BPF_PROG_TYPE_FLOW_DISSECTOR) 398 if (prog->type != BPF_PROG_TYPE_FLOW_DISSECTOR)
264 return -EINVAL; 399 return -EINVAL;
265 400
266 data = bpf_test_init(kattr, size, NET_SKB_PAD + NET_IP_ALIGN, 401 if (kattr->test.ctx_in || kattr->test.ctx_out)
267 SKB_DATA_ALIGN(sizeof(struct skb_shared_info))); 402 return -EINVAL;
268 if (IS_ERR(data))
269 return PTR_ERR(data);
270
271 sk = kzalloc(sizeof(*sk), GFP_USER);
272 if (!sk) {
273 kfree(data);
274 return -ENOMEM;
275 }
276 sock_net_set(sk, current->nsproxy->net_ns);
277 sock_init_data(NULL, sk);
278 403
279 skb = build_skb(data, 0); 404 if (size < ETH_HLEN)
280 if (!skb) { 405 return -EINVAL;
281 kfree(data);
282 kfree(sk);
283 return -ENOMEM;
284 }
285 skb->sk = sk;
286 406
287 skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN); 407 data = bpf_test_init(kattr, size, 0, 0);
288 __skb_put(skb, size); 408 if (IS_ERR(data))
289 skb->protocol = eth_type_trans(skb, 409 return PTR_ERR(data);
290 current->nsproxy->net_ns->loopback_dev);
291 skb_reset_network_header(skb);
292 410
293 cb = (struct bpf_skb_data_end *)skb->cb; 411 eth = (struct ethhdr *)data;
294 cb->qdisc_cb.flow_keys = &flow_keys;
295 412
296 if (!repeat) 413 if (!repeat)
297 repeat = 1; 414 repeat = 1;
298 415
416 ctx.flow_keys = &flow_keys;
417 ctx.data = data;
418 ctx.data_end = (__u8 *)data + size;
419
299 rcu_read_lock(); 420 rcu_read_lock();
300 preempt_disable(); 421 preempt_disable();
301 time_start = ktime_get_ns(); 422 time_start = ktime_get_ns();
302 for (i = 0; i < repeat; i++) { 423 for (i = 0; i < repeat; i++) {
303 retval = __skb_flow_bpf_dissect(prog, skb, 424 retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN,
304 &flow_keys_dissector, 425 size);
305 &flow_keys);
306 426
307 if (signal_pending(current)) { 427 if (signal_pending(current)) {
308 preempt_enable(); 428 preempt_enable();
@@ -335,7 +455,6 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
335 retval, duration); 455 retval, duration);
336 456
337out: 457out:
338 kfree_skb(skb); 458 kfree(data);
339 kfree(sk);
340 return ret; 459 return ret;
341} 460}
diff --git a/net/bridge/br.c b/net/bridge/br.c
index a5174e5001d8..3c8e4b38f054 100644
--- a/net/bridge/br.c
+++ b/net/bridge/br.c
@@ -40,10 +40,13 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
40 bool changed_addr; 40 bool changed_addr;
41 int err; 41 int err;
42 42
43 /* register of bridge completed, add sysfs entries */ 43 if (dev->priv_flags & IFF_EBRIDGE) {
44 if ((dev->priv_flags & IFF_EBRIDGE) && event == NETDEV_REGISTER) { 44 if (event == NETDEV_REGISTER) {
45 br_sysfs_addbr(dev); 45 /* register of bridge completed, add sysfs entries */
46 return NOTIFY_DONE; 46 br_sysfs_addbr(dev);
47 return NOTIFY_DONE;
48 }
49 br_vlan_bridge_event(dev, event, ptr);
47 } 50 }
48 51
49 /* not a port of a bridge */ 52 /* not a port of a bridge */
@@ -126,6 +129,9 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
126 break; 129 break;
127 } 130 }
128 131
132 if (event != NETDEV_UNREGISTER)
133 br_vlan_port_event(p, event);
134
129 /* Events that may cause spanning tree to refresh */ 135 /* Events that may cause spanning tree to refresh */
130 if (!notified && (event == NETDEV_CHANGEADDR || event == NETDEV_UP || 136 if (!notified && (event == NETDEV_CHANGEADDR || event == NETDEV_UP ||
131 event == NETDEV_CHANGE || event == NETDEV_DOWN)) 137 event == NETDEV_CHANGE || event == NETDEV_DOWN))
diff --git a/net/bridge/br_arp_nd_proxy.c b/net/bridge/br_arp_nd_proxy.c
index 6b78e6351719..15116752365a 100644
--- a/net/bridge/br_arp_nd_proxy.c
+++ b/net/bridge/br_arp_nd_proxy.c
@@ -21,6 +21,7 @@
21#include <linux/if_vlan.h> 21#include <linux/if_vlan.h>
22#include <linux/inetdevice.h> 22#include <linux/inetdevice.h>
23#include <net/addrconf.h> 23#include <net/addrconf.h>
24#include <net/ipv6_stubs.h>
24#if IS_ENABLED(CONFIG_IPV6) 25#if IS_ENABLED(CONFIG_IPV6)
25#include <net/ip6_checksum.h> 26#include <net/ip6_checksum.h>
26#endif 27#endif
@@ -130,7 +131,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
130 u8 *arpptr, *sha; 131 u8 *arpptr, *sha;
131 __be32 sip, tip; 132 __be32 sip, tip;
132 133
133 BR_INPUT_SKB_CB(skb)->proxyarp_replied = false; 134 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 0;
134 135
135 if ((dev->flags & IFF_NOARP) || 136 if ((dev->flags & IFF_NOARP) ||
136 !pskb_may_pull(skb, arp_hdr_len(dev))) 137 !pskb_may_pull(skb, arp_hdr_len(dev)))
@@ -160,7 +161,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
160 return; 161 return;
161 if (ipv4_is_zeronet(sip) || sip == tip) { 162 if (ipv4_is_zeronet(sip) || sip == tip) {
162 /* prevent flooding to neigh suppress ports */ 163 /* prevent flooding to neigh suppress ports */
163 BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; 164 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 1;
164 return; 165 return;
165 } 166 }
166 } 167 }
@@ -180,7 +181,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
180 /* its our local ip, so don't proxy reply 181 /* its our local ip, so don't proxy reply
181 * and don't forward to neigh suppress ports 182 * and don't forward to neigh suppress ports
182 */ 183 */
183 BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; 184 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 1;
184 return; 185 return;
185 } 186 }
186 187
@@ -216,7 +217,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
216 */ 217 */
217 if (replied || 218 if (replied ||
218 br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) 219 br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED))
219 BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; 220 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 1;
220 } 221 }
221 222
222 neigh_release(n); 223 neigh_release(n);
@@ -392,7 +393,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
392 struct ipv6hdr *iphdr; 393 struct ipv6hdr *iphdr;
393 struct neighbour *n; 394 struct neighbour *n;
394 395
395 BR_INPUT_SKB_CB(skb)->proxyarp_replied = false; 396 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 0;
396 397
397 if (p && (p->flags & BR_NEIGH_SUPPRESS)) 398 if (p && (p->flags & BR_NEIGH_SUPPRESS))
398 return; 399 return;
@@ -400,7 +401,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
400 if (msg->icmph.icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT && 401 if (msg->icmph.icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT &&
401 !msg->icmph.icmp6_solicited) { 402 !msg->icmph.icmp6_solicited) {
402 /* prevent flooding to neigh suppress ports */ 403 /* prevent flooding to neigh suppress ports */
403 BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; 404 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 1;
404 return; 405 return;
405 } 406 }
406 407
@@ -413,7 +414,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
413 414
414 if (ipv6_addr_any(saddr) || !ipv6_addr_cmp(saddr, daddr)) { 415 if (ipv6_addr_any(saddr) || !ipv6_addr_cmp(saddr, daddr)) {
415 /* prevent flooding to neigh suppress ports */ 416 /* prevent flooding to neigh suppress ports */
416 BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; 417 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 1;
417 return; 418 return;
418 } 419 }
419 420
@@ -431,7 +432,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
431 /* its our own ip, so don't proxy reply 432 /* its our own ip, so don't proxy reply
432 * and don't forward to arp suppress ports 433 * and don't forward to arp suppress ports
433 */ 434 */
434 BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; 435 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 1;
435 return; 436 return;
436 } 437 }
437 438
@@ -464,7 +465,7 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
464 */ 465 */
465 if (replied || 466 if (replied ||
466 br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) 467 br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED))
467 BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; 468 BR_INPUT_SKB_CB(skb)->proxyarp_replied = 1;
468 } 469 }
469 neigh_release(n); 470 neigh_release(n);
470 } 471 }
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 00573cc46c98..b1c91f66d79c 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -33,7 +33,6 @@ static const struct rhashtable_params br_fdb_rht_params = {
33 .key_offset = offsetof(struct net_bridge_fdb_entry, key), 33 .key_offset = offsetof(struct net_bridge_fdb_entry, key),
34 .key_len = sizeof(struct net_bridge_fdb_key), 34 .key_len = sizeof(struct net_bridge_fdb_key),
35 .automatic_shrinking = true, 35 .automatic_shrinking = true,
36 .locks_mul = 1,
37}; 36};
38 37
39static struct kmem_cache *br_fdb_cache __read_mostly; 38static struct kmem_cache *br_fdb_cache __read_mostly;
diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index 48ddc60b4fbd..82225b8b54f5 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -173,6 +173,7 @@ static struct net_bridge_port *maybe_deliver(
173 struct net_bridge_port *prev, struct net_bridge_port *p, 173 struct net_bridge_port *prev, struct net_bridge_port *p,
174 struct sk_buff *skb, bool local_orig) 174 struct sk_buff *skb, bool local_orig)
175{ 175{
176 u8 igmp_type = br_multicast_igmp_type(skb);
176 int err; 177 int err;
177 178
178 if (!should_deliver(p, skb)) 179 if (!should_deliver(p, skb))
@@ -184,8 +185,9 @@ static struct net_bridge_port *maybe_deliver(
184 err = deliver_clone(prev, skb, local_orig); 185 err = deliver_clone(prev, skb, local_orig);
185 if (err) 186 if (err)
186 return ERR_PTR(err); 187 return ERR_PTR(err);
187
188out: 188out:
189 br_multicast_count(p->br, p, skb, igmp_type, BR_MCAST_DIR_TX);
190
189 return p; 191 return p;
190} 192}
191 193
@@ -193,7 +195,6 @@ out:
193void br_flood(struct net_bridge *br, struct sk_buff *skb, 195void br_flood(struct net_bridge *br, struct sk_buff *skb,
194 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig) 196 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig)
195{ 197{
196 u8 igmp_type = br_multicast_igmp_type(skb);
197 struct net_bridge_port *prev = NULL; 198 struct net_bridge_port *prev = NULL;
198 struct net_bridge_port *p; 199 struct net_bridge_port *p;
199 200
@@ -226,9 +227,6 @@ void br_flood(struct net_bridge *br, struct sk_buff *skb,
226 prev = maybe_deliver(prev, p, skb, local_orig); 227 prev = maybe_deliver(prev, p, skb, local_orig);
227 if (IS_ERR(prev)) 228 if (IS_ERR(prev))
228 goto out; 229 goto out;
229 if (prev == p)
230 br_multicast_count(p->br, p, skb, igmp_type,
231 BR_MCAST_DIR_TX);
232 } 230 }
233 231
234 if (!prev) 232 if (!prev)
@@ -277,7 +275,6 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
277 bool local_rcv, bool local_orig) 275 bool local_rcv, bool local_orig)
278{ 276{
279 struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev; 277 struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev;
280 u8 igmp_type = br_multicast_igmp_type(skb);
281 struct net_bridge *br = netdev_priv(dev); 278 struct net_bridge *br = netdev_priv(dev);
282 struct net_bridge_port *prev = NULL; 279 struct net_bridge_port *prev = NULL;
283 struct net_bridge_port_group *p; 280 struct net_bridge_port_group *p;
@@ -304,13 +301,9 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst,
304 } 301 }
305 302
306 prev = maybe_deliver(prev, port, skb, local_orig); 303 prev = maybe_deliver(prev, port, skb, local_orig);
307delivered:
308 if (IS_ERR(prev)) 304 if (IS_ERR(prev))
309 goto out; 305 goto out;
310 if (prev == port) 306delivered:
311 br_multicast_count(port->br, port, skb, igmp_type,
312 BR_MCAST_DIR_TX);
313
314 if ((unsigned long)lport >= (unsigned long)port) 307 if ((unsigned long)lport >= (unsigned long)port)
315 p = rcu_dereference(p->next); 308 p = rcu_dereference(p->next);
316 if ((unsigned long)rport >= (unsigned long)port) 309 if ((unsigned long)rport >= (unsigned long)port)
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 41f0a696a65f..6d4a24a7534b 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -179,7 +179,7 @@ int nbp_backup_change(struct net_bridge_port *p,
179 ASSERT_RTNL(); 179 ASSERT_RTNL();
180 180
181 if (backup_dev) { 181 if (backup_dev) {
182 if (!br_port_exists(backup_dev)) 182 if (!netif_is_bridge_port(backup_dev))
183 return -ENOENT; 183 return -ENOENT;
184 184
185 backup_p = br_port_get_rtnl(backup_dev); 185 backup_p = br_port_get_rtnl(backup_dev);
@@ -602,13 +602,15 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
602 call_netdevice_notifiers(NETDEV_JOIN, dev); 602 call_netdevice_notifiers(NETDEV_JOIN, dev);
603 603
604 err = dev_set_allmulti(dev, 1); 604 err = dev_set_allmulti(dev, 1);
605 if (err) 605 if (err) {
606 goto put_back; 606 kfree(p); /* kobject not yet init'd, manually free */
607 goto err1;
608 }
607 609
608 err = kobject_init_and_add(&p->kobj, &brport_ktype, &(dev->dev.kobj), 610 err = kobject_init_and_add(&p->kobj, &brport_ktype, &(dev->dev.kobj),
609 SYSFS_BRIDGE_PORT_ATTR); 611 SYSFS_BRIDGE_PORT_ATTR);
610 if (err) 612 if (err)
611 goto err1; 613 goto err2;
612 614
613 err = br_sysfs_addif(p); 615 err = br_sysfs_addif(p);
614 if (err) 616 if (err)
@@ -700,12 +702,9 @@ err3:
700 sysfs_remove_link(br->ifobj, p->dev->name); 702 sysfs_remove_link(br->ifobj, p->dev->name);
701err2: 703err2:
702 kobject_put(&p->kobj); 704 kobject_put(&p->kobj);
703 p = NULL; /* kobject_put frees */
704err1:
705 dev_set_allmulti(dev, -1); 705 dev_set_allmulti(dev, -1);
706put_back: 706err1:
707 dev_put(dev); 707 dev_put(dev);
708 kfree(p);
709 return err; 708 return err;
710} 709}
711 710
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index 5ea7e56119c1..014af7efef25 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -16,6 +16,9 @@
16#include <linux/netdevice.h> 16#include <linux/netdevice.h>
17#include <linux/etherdevice.h> 17#include <linux/etherdevice.h>
18#include <linux/netfilter_bridge.h> 18#include <linux/netfilter_bridge.h>
19#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
20#include <net/netfilter/nf_queue.h>
21#endif
19#include <linux/neighbour.h> 22#include <linux/neighbour.h>
20#include <net/arp.h> 23#include <net/arp.h>
21#include <linux/export.h> 24#include <linux/export.h>
@@ -23,10 +26,6 @@
23#include "br_private.h" 26#include "br_private.h"
24#include "br_private_tunnel.h" 27#include "br_private_tunnel.h"
25 28
26/* Hook for brouter */
27br_should_route_hook_t __rcu *br_should_route_hook __read_mostly;
28EXPORT_SYMBOL(br_should_route_hook);
29
30static int 29static int
31br_netif_receive_skb(struct net *net, struct sock *sk, struct sk_buff *skb) 30br_netif_receive_skb(struct net *net, struct sock *sk, struct sk_buff *skb)
32{ 31{
@@ -197,13 +196,63 @@ static void __br_handle_local_finish(struct sk_buff *skb)
197/* note: already called with rcu_read_lock */ 196/* note: already called with rcu_read_lock */
198static int br_handle_local_finish(struct net *net, struct sock *sk, struct sk_buff *skb) 197static int br_handle_local_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
199{ 198{
200 struct net_bridge_port *p = br_port_get_rcu(skb->dev);
201
202 __br_handle_local_finish(skb); 199 __br_handle_local_finish(skb);
203 200
204 BR_INPUT_SKB_CB(skb)->brdev = p->br->dev; 201 /* return 1 to signal the okfn() was called so it's ok to use the skb */
205 br_pass_frame_up(skb); 202 return 1;
206 return 0; 203}
204
205static int nf_hook_bridge_pre(struct sk_buff *skb, struct sk_buff **pskb)
206{
207#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
208 struct nf_hook_entries *e = NULL;
209 struct nf_hook_state state;
210 unsigned int verdict, i;
211 struct net *net;
212 int ret;
213
214 net = dev_net(skb->dev);
215#ifdef HAVE_JUMP_LABEL
216 if (!static_key_false(&nf_hooks_needed[NFPROTO_BRIDGE][NF_BR_PRE_ROUTING]))
217 goto frame_finish;
218#endif
219
220 e = rcu_dereference(net->nf.hooks_bridge[NF_BR_PRE_ROUTING]);
221 if (!e)
222 goto frame_finish;
223
224 nf_hook_state_init(&state, NF_BR_PRE_ROUTING,
225 NFPROTO_BRIDGE, skb->dev, NULL, NULL,
226 net, br_handle_frame_finish);
227
228 for (i = 0; i < e->num_hook_entries; i++) {
229 verdict = nf_hook_entry_hookfn(&e->hooks[i], skb, &state);
230 switch (verdict & NF_VERDICT_MASK) {
231 case NF_ACCEPT:
232 if (BR_INPUT_SKB_CB(skb)->br_netfilter_broute) {
233 *pskb = skb;
234 return RX_HANDLER_PASS;
235 }
236 break;
237 case NF_DROP:
238 kfree_skb(skb);
239 return RX_HANDLER_CONSUMED;
240 case NF_QUEUE:
241 ret = nf_queue(skb, &state, e, i, verdict);
242 if (ret == 1)
243 continue;
244 return RX_HANDLER_CONSUMED;
245 default: /* STOLEN */
246 return RX_HANDLER_CONSUMED;
247 }
248 }
249frame_finish:
250 net = dev_net(skb->dev);
251 br_handle_frame_finish(net, NULL, skb);
252#else
253 br_handle_frame_finish(dev_net(skb->dev), NULL, skb);
254#endif
255 return RX_HANDLER_CONSUMED;
207} 256}
208 257
209/* 258/*
@@ -215,7 +264,6 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
215 struct net_bridge_port *p; 264 struct net_bridge_port *p;
216 struct sk_buff *skb = *pskb; 265 struct sk_buff *skb = *pskb;
217 const unsigned char *dest = eth_hdr(skb)->h_dest; 266 const unsigned char *dest = eth_hdr(skb)->h_dest;
218 br_should_route_hook_t *rhook;
219 267
220 if (unlikely(skb->pkt_type == PACKET_LOOPBACK)) 268 if (unlikely(skb->pkt_type == PACKET_LOOPBACK))
221 return RX_HANDLER_PASS; 269 return RX_HANDLER_PASS;
@@ -227,6 +275,8 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
227 if (!skb) 275 if (!skb)
228 return RX_HANDLER_CONSUMED; 276 return RX_HANDLER_CONSUMED;
229 277
278 memset(skb->cb, 0, sizeof(struct br_input_skb_cb));
279
230 p = br_port_get_rcu(skb->dev); 280 p = br_port_get_rcu(skb->dev);
231 if (p->flags & BR_VLAN_TUNNEL) { 281 if (p->flags & BR_VLAN_TUNNEL) {
232 if (br_handle_ingress_vlan_tunnel(skb, p, 282 if (br_handle_ingress_vlan_tunnel(skb, p,
@@ -280,32 +330,28 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
280 goto forward; 330 goto forward;
281 } 331 }
282 332
283 /* Deliver packet to local host only */ 333 /* The else clause should be hit when nf_hook():
284 NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, dev_net(skb->dev), 334 * - returns < 0 (drop/error)
285 NULL, skb, skb->dev, NULL, br_handle_local_finish); 335 * - returns = 0 (stolen/nf_queue)
286 return RX_HANDLER_CONSUMED; 336 * Thus return 1 from the okfn() to signal the skb is ok to pass
337 */
338 if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN,
339 dev_net(skb->dev), NULL, skb, skb->dev, NULL,
340 br_handle_local_finish) == 1) {
341 return RX_HANDLER_PASS;
342 } else {
343 return RX_HANDLER_CONSUMED;
344 }
287 } 345 }
288 346
289forward: 347forward:
290 switch (p->state) { 348 switch (p->state) {
291 case BR_STATE_FORWARDING: 349 case BR_STATE_FORWARDING:
292 rhook = rcu_dereference(br_should_route_hook);
293 if (rhook) {
294 if ((*rhook)(skb)) {
295 *pskb = skb;
296 return RX_HANDLER_PASS;
297 }
298 dest = eth_hdr(skb)->h_dest;
299 }
300 /* fall through */
301 case BR_STATE_LEARNING: 350 case BR_STATE_LEARNING:
302 if (ether_addr_equal(p->br->dev->dev_addr, dest)) 351 if (ether_addr_equal(p->br->dev->dev_addr, dest))
303 skb->pkt_type = PACKET_HOST; 352 skb->pkt_type = PACKET_HOST;
304 353
305 NF_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, 354 return nf_hook_bridge_pre(skb, pskb);
306 dev_net(skb->dev), NULL, skb, skb->dev, NULL,
307 br_handle_frame_finish);
308 break;
309 default: 355 default:
310drop: 356drop:
311 kfree_skb(skb); 357 kfree_skb(skb);
diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
index f69c8d91dc81..bf6acd34234d 100644
--- a/net/bridge/br_mdb.c
+++ b/net/bridge/br_mdb.c
@@ -26,14 +26,14 @@ static int br_rports_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
26 if (!br->multicast_router || hlist_empty(&br->router_list)) 26 if (!br->multicast_router || hlist_empty(&br->router_list))
27 return 0; 27 return 0;
28 28
29 nest = nla_nest_start(skb, MDBA_ROUTER); 29 nest = nla_nest_start_noflag(skb, MDBA_ROUTER);
30 if (nest == NULL) 30 if (nest == NULL)
31 return -EMSGSIZE; 31 return -EMSGSIZE;
32 32
33 hlist_for_each_entry_rcu(p, &br->router_list, rlist) { 33 hlist_for_each_entry_rcu(p, &br->router_list, rlist) {
34 if (!p) 34 if (!p)
35 continue; 35 continue;
36 port_nest = nla_nest_start(skb, MDBA_ROUTER_PORT); 36 port_nest = nla_nest_start_noflag(skb, MDBA_ROUTER_PORT);
37 if (!port_nest) 37 if (!port_nest)
38 goto fail; 38 goto fail;
39 if (nla_put_nohdr(skb, sizeof(u32), &p->dev->ifindex) || 39 if (nla_put_nohdr(skb, sizeof(u32), &p->dev->ifindex) ||
@@ -86,7 +86,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
86 if (!br_opt_get(br, BROPT_MULTICAST_ENABLED)) 86 if (!br_opt_get(br, BROPT_MULTICAST_ENABLED))
87 return 0; 87 return 0;
88 88
89 nest = nla_nest_start(skb, MDBA_MDB); 89 nest = nla_nest_start_noflag(skb, MDBA_MDB);
90 if (nest == NULL) 90 if (nest == NULL)
91 return -EMSGSIZE; 91 return -EMSGSIZE;
92 92
@@ -98,7 +98,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
98 if (idx < s_idx) 98 if (idx < s_idx)
99 goto skip; 99 goto skip;
100 100
101 nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY); 101 nest2 = nla_nest_start_noflag(skb, MDBA_MDB_ENTRY);
102 if (!nest2) { 102 if (!nest2) {
103 err = -EMSGSIZE; 103 err = -EMSGSIZE;
104 break; 104 break;
@@ -124,7 +124,8 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
124 e.addr.u.ip6 = p->addr.u.ip6; 124 e.addr.u.ip6 = p->addr.u.ip6;
125#endif 125#endif
126 e.addr.proto = p->addr.proto; 126 e.addr.proto = p->addr.proto;
127 nest_ent = nla_nest_start(skb, MDBA_MDB_ENTRY_INFO); 127 nest_ent = nla_nest_start_noflag(skb,
128 MDBA_MDB_ENTRY_INFO);
128 if (!nest_ent) { 129 if (!nest_ent) {
129 nla_nest_cancel(skb, nest2); 130 nla_nest_cancel(skb, nest2);
130 err = -EMSGSIZE; 131 err = -EMSGSIZE;
@@ -248,10 +249,10 @@ static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
248 memset(bpm, 0, sizeof(*bpm)); 249 memset(bpm, 0, sizeof(*bpm));
249 bpm->family = AF_BRIDGE; 250 bpm->family = AF_BRIDGE;
250 bpm->ifindex = dev->ifindex; 251 bpm->ifindex = dev->ifindex;
251 nest = nla_nest_start(skb, MDBA_MDB); 252 nest = nla_nest_start_noflag(skb, MDBA_MDB);
252 if (nest == NULL) 253 if (nest == NULL)
253 goto cancel; 254 goto cancel;
254 nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY); 255 nest2 = nla_nest_start_noflag(skb, MDBA_MDB_ENTRY);
255 if (nest2 == NULL) 256 if (nest2 == NULL)
256 goto end; 257 goto end;
257 258
@@ -444,7 +445,7 @@ static int nlmsg_populate_rtr_fill(struct sk_buff *skb,
444 memset(bpm, 0, sizeof(*bpm)); 445 memset(bpm, 0, sizeof(*bpm));
445 bpm->family = AF_BRIDGE; 446 bpm->family = AF_BRIDGE;
446 bpm->ifindex = dev->ifindex; 447 bpm->ifindex = dev->ifindex;
447 nest = nla_nest_start(skb, MDBA_ROUTER); 448 nest = nla_nest_start_noflag(skb, MDBA_ROUTER);
448 if (!nest) 449 if (!nest)
449 goto cancel; 450 goto cancel;
450 451
@@ -529,8 +530,8 @@ static int br_mdb_parse(struct sk_buff *skb, struct nlmsghdr *nlh,
529 struct net_device *dev; 530 struct net_device *dev;
530 int err; 531 int err;
531 532
532 err = nlmsg_parse(nlh, sizeof(*bpm), tb, MDBA_SET_ENTRY_MAX, NULL, 533 err = nlmsg_parse_deprecated(nlh, sizeof(*bpm), tb,
533 NULL); 534 MDBA_SET_ENTRY_MAX, NULL, NULL);
534 if (err < 0) 535 if (err < 0)
535 return err; 536 return err;
536 537
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 02da21d771c9..c2a30f79a9d0 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -44,7 +44,6 @@ static const struct rhashtable_params br_mdb_rht_params = {
44 .key_offset = offsetof(struct net_bridge_mdb_entry, addr), 44 .key_offset = offsetof(struct net_bridge_mdb_entry, addr),
45 .key_len = sizeof(struct br_ip), 45 .key_len = sizeof(struct br_ip),
46 .automatic_shrinking = true, 46 .automatic_shrinking = true,
47 .locks_mul = 1,
48}; 47};
49 48
50static void br_multicast_start_querier(struct net_bridge *br, 49static void br_multicast_start_querier(struct net_bridge *br,
@@ -65,23 +64,6 @@ static void br_ip6_multicast_leave_group(struct net_bridge *br,
65 __u16 vid, const unsigned char *src); 64 __u16 vid, const unsigned char *src);
66#endif 65#endif
67 66
68static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b)
69{
70 if (a->proto != b->proto)
71 return 0;
72 if (a->vid != b->vid)
73 return 0;
74 switch (a->proto) {
75 case htons(ETH_P_IP):
76 return a->u.ip4 == b->u.ip4;
77#if IS_ENABLED(CONFIG_IPV6)
78 case htons(ETH_P_IPV6):
79 return ipv6_addr_equal(&a->u.ip6, &b->u.ip6);
80#endif
81 }
82 return 0;
83}
84
85static struct net_bridge_mdb_entry *br_mdb_ip_get_rcu(struct net_bridge *br, 67static struct net_bridge_mdb_entry *br_mdb_ip_get_rcu(struct net_bridge *br,
86 struct br_ip *dst) 68 struct br_ip *dst)
87{ 69{
@@ -517,7 +499,7 @@ struct net_bridge_port_group *br_multicast_new_port_group(
517 if (src) 499 if (src)
518 memcpy(p->eth_addr, src, ETH_ALEN); 500 memcpy(p->eth_addr, src, ETH_ALEN);
519 else 501 else
520 memset(p->eth_addr, 0xff, ETH_ALEN); 502 eth_broadcast_addr(p->eth_addr);
521 503
522 return p; 504 return p;
523} 505}
@@ -2031,7 +2013,8 @@ static void br_multicast_start_querier(struct net_bridge *br,
2031 2013
2032 __br_multicast_open(br, query); 2014 __br_multicast_open(br, query);
2033 2015
2034 list_for_each_entry(port, &br->port_list, list) { 2016 rcu_read_lock();
2017 list_for_each_entry_rcu(port, &br->port_list, list) {
2035 if (port->state == BR_STATE_DISABLED || 2018 if (port->state == BR_STATE_DISABLED ||
2036 port->state == BR_STATE_BLOCKING) 2019 port->state == BR_STATE_BLOCKING)
2037 continue; 2020 continue;
@@ -2043,6 +2026,7 @@ static void br_multicast_start_querier(struct net_bridge *br,
2043 br_multicast_enable(&port->ip6_own_query); 2026 br_multicast_enable(&port->ip6_own_query);
2044#endif 2027#endif
2045 } 2028 }
2029 rcu_read_unlock();
2046} 2030}
2047 2031
2048int br_multicast_toggle(struct net_bridge *br, unsigned long val) 2032int br_multicast_toggle(struct net_bridge *br, unsigned long val)
@@ -2192,7 +2176,7 @@ int br_multicast_list_adjacent(struct net_device *dev,
2192 int count = 0; 2176 int count = 0;
2193 2177
2194 rcu_read_lock(); 2178 rcu_read_lock();
2195 if (!br_ip_list || !br_port_exists(dev)) 2179 if (!br_ip_list || !netif_is_bridge_port(dev))
2196 goto unlock; 2180 goto unlock;
2197 2181
2198 port = br_port_get_rcu(dev); 2182 port = br_port_get_rcu(dev);
@@ -2239,7 +2223,7 @@ bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto)
2239 bool ret = false; 2223 bool ret = false;
2240 2224
2241 rcu_read_lock(); 2225 rcu_read_lock();
2242 if (!br_port_exists(dev)) 2226 if (!netif_is_bridge_port(dev))
2243 goto unlock; 2227 goto unlock;
2244 2228
2245 port = br_port_get_rcu(dev); 2229 port = br_port_get_rcu(dev);
@@ -2275,7 +2259,7 @@ bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto)
2275 bool ret = false; 2259 bool ret = false;
2276 2260
2277 rcu_read_lock(); 2261 rcu_read_lock();
2278 if (!br_port_exists(dev)) 2262 if (!netif_is_bridge_port(dev))
2279 goto unlock; 2263 goto unlock;
2280 2264
2281 port = br_port_get_rcu(dev); 2265 port = br_port_get_rcu(dev);
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 9c07591b0232..a5acad29cd4f 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -102,7 +102,7 @@ static size_t br_get_link_af_size_filtered(const struct net_device *dev,
102 size_t vinfo_sz = 0; 102 size_t vinfo_sz = 0;
103 103
104 rcu_read_lock(); 104 rcu_read_lock();
105 if (br_port_exists(dev)) { 105 if (netif_is_bridge_port(dev)) {
106 p = br_port_get_rcu(dev); 106 p = br_port_get_rcu(dev);
107 vg = nbp_vlan_group_rcu(p); 107 vg = nbp_vlan_group_rcu(p);
108 } else if (dev->priv_flags & IFF_EBRIDGE) { 108 } else if (dev->priv_flags & IFF_EBRIDGE) {
@@ -413,9 +413,9 @@ static int br_fill_ifinfo(struct sk_buff *skb,
413 goto nla_put_failure; 413 goto nla_put_failure;
414 414
415 if (event == RTM_NEWLINK && port) { 415 if (event == RTM_NEWLINK && port) {
416 struct nlattr *nest 416 struct nlattr *nest;
417 = nla_nest_start(skb, IFLA_PROTINFO | NLA_F_NESTED);
418 417
418 nest = nla_nest_start(skb, IFLA_PROTINFO);
419 if (nest == NULL || br_port_fill_attrs(skb, port) < 0) 419 if (nest == NULL || br_port_fill_attrs(skb, port) < 0)
420 goto nla_put_failure; 420 goto nla_put_failure;
421 nla_nest_end(skb, nest); 421 nla_nest_end(skb, nest);
@@ -439,7 +439,7 @@ static int br_fill_ifinfo(struct sk_buff *skb,
439 rcu_read_unlock(); 439 rcu_read_unlock();
440 goto done; 440 goto done;
441 } 441 }
442 af = nla_nest_start(skb, IFLA_AF_SPEC); 442 af = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
443 if (!af) { 443 if (!af) {
444 rcu_read_unlock(); 444 rcu_read_unlock();
445 goto nla_put_failure; 445 goto nla_put_failure;
@@ -880,8 +880,10 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags,
880 880
881 if (p && protinfo) { 881 if (p && protinfo) {
882 if (protinfo->nla_type & NLA_F_NESTED) { 882 if (protinfo->nla_type & NLA_F_NESTED) {
883 err = nla_parse_nested(tb, IFLA_BRPORT_MAX, protinfo, 883 err = nla_parse_nested_deprecated(tb, IFLA_BRPORT_MAX,
884 br_port_policy, NULL); 884 protinfo,
885 br_port_policy,
886 NULL);
885 if (err) 887 if (err)
886 return err; 888 return err;
887 889
@@ -1441,7 +1443,7 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
1441 nla_put_u8(skb, IFLA_BR_VLAN_STATS_ENABLED, 1443 nla_put_u8(skb, IFLA_BR_VLAN_STATS_ENABLED,
1442 br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) || 1444 br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) ||
1443 nla_put_u8(skb, IFLA_BR_VLAN_STATS_PER_PORT, 1445 nla_put_u8(skb, IFLA_BR_VLAN_STATS_PER_PORT,
1444 br_opt_get(br, IFLA_BR_VLAN_STATS_PER_PORT))) 1446 br_opt_get(br, BROPT_VLAN_STATS_PER_PORT)))
1445 return -EMSGSIZE; 1447 return -EMSGSIZE;
1446#endif 1448#endif
1447#ifdef CONFIG_BRIDGE_IGMP_SNOOPING 1449#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
@@ -1569,7 +1571,7 @@ static int br_fill_linkxstats(struct sk_buff *skb,
1569 return -EINVAL; 1571 return -EINVAL;
1570 } 1572 }
1571 1573
1572 nest = nla_nest_start(skb, LINK_XSTATS_TYPE_BRIDGE); 1574 nest = nla_nest_start_noflag(skb, LINK_XSTATS_TYPE_BRIDGE);
1573 if (!nest) 1575 if (!nest)
1574 return -EMSGSIZE; 1576 return -EMSGSIZE;
1575 1577
diff --git a/net/bridge/br_netlink_tunnel.c b/net/bridge/br_netlink_tunnel.c
index da8cb99fd259..34629d558709 100644
--- a/net/bridge/br_netlink_tunnel.c
+++ b/net/bridge/br_netlink_tunnel.c
@@ -97,7 +97,7 @@ static int br_fill_vlan_tinfo(struct sk_buff *skb, u16 vid,
97 __be32 tid = tunnel_id_to_key32(tunnel_id); 97 __be32 tid = tunnel_id_to_key32(tunnel_id);
98 struct nlattr *tmap; 98 struct nlattr *tmap;
99 99
100 tmap = nla_nest_start(skb, IFLA_BRIDGE_VLAN_TUNNEL_INFO); 100 tmap = nla_nest_start_noflag(skb, IFLA_BRIDGE_VLAN_TUNNEL_INFO);
101 if (!tmap) 101 if (!tmap)
102 return -EMSGSIZE; 102 return -EMSGSIZE;
103 if (nla_put_u32(skb, IFLA_BRIDGE_VLAN_TUNNEL_ID, 103 if (nla_put_u32(skb, IFLA_BRIDGE_VLAN_TUNNEL_ID,
@@ -230,8 +230,8 @@ int br_parse_vlan_tunnel_info(struct nlattr *attr,
230 230
231 memset(tinfo, 0, sizeof(*tinfo)); 231 memset(tinfo, 0, sizeof(*tinfo));
232 232
233 err = nla_parse_nested(tb, IFLA_BRIDGE_VLAN_TUNNEL_MAX, attr, 233 err = nla_parse_nested_deprecated(tb, IFLA_BRIDGE_VLAN_TUNNEL_MAX,
234 vlan_tunnel_policy, NULL); 234 attr, vlan_tunnel_policy, NULL);
235 if (err < 0) 235 if (err < 0)
236 return err; 236 return err;
237 237
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 00deef7fc1f3..334a8c496b50 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -288,8 +288,6 @@ struct net_bridge_port {
288#define br_auto_port(p) ((p)->flags & BR_AUTO_MASK) 288#define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
289#define br_promisc_port(p) ((p)->flags & BR_PROMISC) 289#define br_promisc_port(p) ((p)->flags & BR_PROMISC)
290 290
291#define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT)
292
293static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev) 291static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
294{ 292{
295 return rcu_dereference(dev->rx_handler_data); 293 return rcu_dereference(dev->rx_handler_data);
@@ -297,13 +295,13 @@ static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *d
297 295
298static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev) 296static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
299{ 297{
300 return br_port_exists(dev) ? 298 return netif_is_bridge_port(dev) ?
301 rtnl_dereference(dev->rx_handler_data) : NULL; 299 rtnl_dereference(dev->rx_handler_data) : NULL;
302} 300}
303 301
304static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev) 302static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
305{ 303{
306 return br_port_exists(dev) ? 304 return netif_is_bridge_port(dev) ?
307 rcu_dereference_rtnl(dev->rx_handler_data) : NULL; 305 rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
308} 306}
309 307
@@ -323,6 +321,7 @@ enum net_bridge_opts {
323 BROPT_MTU_SET_BY_USER, 321 BROPT_MTU_SET_BY_USER,
324 BROPT_VLAN_STATS_PER_PORT, 322 BROPT_VLAN_STATS_PER_PORT,
325 BROPT_NO_LL_LEARN, 323 BROPT_NO_LL_LEARN,
324 BROPT_VLAN_BRIDGE_BINDING,
326}; 325};
327 326
328struct net_bridge { 327struct net_bridge {
@@ -427,15 +426,16 @@ struct br_input_skb_cb {
427 struct net_device *brdev; 426 struct net_device *brdev;
428 427
429#ifdef CONFIG_BRIDGE_IGMP_SNOOPING 428#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
430 int igmp; 429 u8 igmp;
431 int mrouters_only; 430 u8 mrouters_only:1;
432#endif 431#endif
433 432 u8 proxyarp_replied:1;
434 bool proxyarp_replied; 433 u8 src_port_isolated:1;
435 bool src_port_isolated;
436
437#ifdef CONFIG_BRIDGE_VLAN_FILTERING 434#ifdef CONFIG_BRIDGE_VLAN_FILTERING
438 bool vlan_filtered; 435 u8 vlan_filtered:1;
436#endif
437#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
438 u8 br_netfilter_broute:1;
439#endif 439#endif
440 440
441#ifdef CONFIG_NET_SWITCHDEV 441#ifdef CONFIG_NET_SWITCHDEV
@@ -896,6 +896,9 @@ int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack);
896int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask); 896int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
897void br_vlan_get_stats(const struct net_bridge_vlan *v, 897void br_vlan_get_stats(const struct net_bridge_vlan *v,
898 struct br_vlan_stats *stats); 898 struct br_vlan_stats *stats);
899void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
900void br_vlan_bridge_event(struct net_device *dev, unsigned long event,
901 void *ptr);
899 902
900static inline struct net_bridge_vlan_group *br_vlan_group( 903static inline struct net_bridge_vlan_group *br_vlan_group(
901 const struct net_bridge *br) 904 const struct net_bridge *br)
@@ -1079,6 +1082,16 @@ static inline void br_vlan_get_stats(const struct net_bridge_vlan *v,
1079 struct br_vlan_stats *stats) 1082 struct br_vlan_stats *stats)
1080{ 1083{
1081} 1084}
1085
1086static inline void br_vlan_port_event(struct net_bridge_port *p,
1087 unsigned long event)
1088{
1089}
1090
1091static inline void br_vlan_bridge_event(struct net_device *dev,
1092 unsigned long event, void *ptr)
1093{
1094}
1082#endif 1095#endif
1083 1096
1084struct nf_br_ops { 1097struct nf_br_ops {
diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
index 808e2b914015..8d65ae5210e0 100644
--- a/net/bridge/br_stp_if.c
+++ b/net/bridge/br_stp_if.c
@@ -117,7 +117,8 @@ void br_stp_disable_port(struct net_bridge_port *p)
117 del_timer(&p->forward_delay_timer); 117 del_timer(&p->forward_delay_timer);
118 del_timer(&p->hold_timer); 118 del_timer(&p->hold_timer);
119 119
120 br_fdb_delete_by_port(br, p, 0, 0); 120 if (!rcu_access_pointer(p->backup_port))
121 br_fdb_delete_by_port(br, p, 0, 0);
121 br_multicast_disable_port(p); 122 br_multicast_disable_port(p);
122 123
123 br_configuration_update(br); 124 br_configuration_update(br);
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 96abf8feb9dc..2db63997f313 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -7,6 +7,8 @@
7#include "br_private.h" 7#include "br_private.h"
8#include "br_private_tunnel.h" 8#include "br_private_tunnel.h"
9 9
10static void nbp_vlan_set_vlan_dev_state(struct net_bridge_port *p, u16 vid);
11
10static inline int br_vlan_cmp(struct rhashtable_compare_arg *arg, 12static inline int br_vlan_cmp(struct rhashtable_compare_arg *arg,
11 const void *ptr) 13 const void *ptr)
12{ 14{
@@ -21,7 +23,6 @@ static const struct rhashtable_params br_vlan_rht_params = {
21 .key_offset = offsetof(struct net_bridge_vlan, vid), 23 .key_offset = offsetof(struct net_bridge_vlan, vid),
22 .key_len = sizeof(u16), 24 .key_len = sizeof(u16),
23 .nelem_hint = 3, 25 .nelem_hint = 3,
24 .locks_mul = 1,
25 .max_size = VLAN_N_VID, 26 .max_size = VLAN_N_VID,
26 .obj_cmpfn = br_vlan_cmp, 27 .obj_cmpfn = br_vlan_cmp,
27 .automatic_shrinking = true, 28 .automatic_shrinking = true,
@@ -294,6 +295,9 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags,
294 295
295 __vlan_add_list(v); 296 __vlan_add_list(v);
296 __vlan_add_flags(v, flags); 297 __vlan_add_flags(v, flags);
298
299 if (p)
300 nbp_vlan_set_vlan_dev_state(p, v->vid);
297out: 301out:
298 return err; 302 return err;
299 303
@@ -358,6 +362,7 @@ static int __vlan_del(struct net_bridge_vlan *v)
358 rhashtable_remove_fast(&vg->vlan_hash, &v->vnode, 362 rhashtable_remove_fast(&vg->vlan_hash, &v->vnode,
359 br_vlan_rht_params); 363 br_vlan_rht_params);
360 __vlan_del_list(v); 364 __vlan_del_list(v);
365 nbp_vlan_set_vlan_dev_state(p, v->vid);
361 call_rcu(&v->rcu, nbp_vlan_rcu_free); 366 call_rcu(&v->rcu, nbp_vlan_rcu_free);
362 } 367 }
363 368
@@ -1265,3 +1270,211 @@ int br_vlan_get_info(const struct net_device *dev, u16 vid,
1265 return 0; 1270 return 0;
1266} 1271}
1267EXPORT_SYMBOL_GPL(br_vlan_get_info); 1272EXPORT_SYMBOL_GPL(br_vlan_get_info);
1273
1274static int br_vlan_is_bind_vlan_dev(const struct net_device *dev)
1275{
1276 return is_vlan_dev(dev) &&
1277 !!(vlan_dev_priv(dev)->flags & VLAN_FLAG_BRIDGE_BINDING);
1278}
1279
1280static int br_vlan_is_bind_vlan_dev_fn(struct net_device *dev,
1281 __always_unused void *data)
1282{
1283 return br_vlan_is_bind_vlan_dev(dev);
1284}
1285
1286static bool br_vlan_has_upper_bind_vlan_dev(struct net_device *dev)
1287{
1288 int found;
1289
1290 rcu_read_lock();
1291 found = netdev_walk_all_upper_dev_rcu(dev, br_vlan_is_bind_vlan_dev_fn,
1292 NULL);
1293 rcu_read_unlock();
1294
1295 return !!found;
1296}
1297
1298struct br_vlan_bind_walk_data {
1299 u16 vid;
1300 struct net_device *result;
1301};
1302
1303static int br_vlan_match_bind_vlan_dev_fn(struct net_device *dev,
1304 void *data_in)
1305{
1306 struct br_vlan_bind_walk_data *data = data_in;
1307 int found = 0;
1308
1309 if (br_vlan_is_bind_vlan_dev(dev) &&
1310 vlan_dev_priv(dev)->vlan_id == data->vid) {
1311 data->result = dev;
1312 found = 1;
1313 }
1314
1315 return found;
1316}
1317
1318static struct net_device *
1319br_vlan_get_upper_bind_vlan_dev(struct net_device *dev, u16 vid)
1320{
1321 struct br_vlan_bind_walk_data data = {
1322 .vid = vid,
1323 };
1324
1325 rcu_read_lock();
1326 netdev_walk_all_upper_dev_rcu(dev, br_vlan_match_bind_vlan_dev_fn,
1327 &data);
1328 rcu_read_unlock();
1329
1330 return data.result;
1331}
1332
1333static bool br_vlan_is_dev_up(const struct net_device *dev)
1334{
1335 return !!(dev->flags & IFF_UP) && netif_oper_up(dev);
1336}
1337
1338static void br_vlan_set_vlan_dev_state(const struct net_bridge *br,
1339 struct net_device *vlan_dev)
1340{
1341 u16 vid = vlan_dev_priv(vlan_dev)->vlan_id;
1342 struct net_bridge_vlan_group *vg;
1343 struct net_bridge_port *p;
1344 bool has_carrier = false;
1345
1346 if (!netif_carrier_ok(br->dev)) {
1347 netif_carrier_off(vlan_dev);
1348 return;
1349 }
1350
1351 list_for_each_entry(p, &br->port_list, list) {
1352 vg = nbp_vlan_group(p);
1353 if (br_vlan_find(vg, vid) && br_vlan_is_dev_up(p->dev)) {
1354 has_carrier = true;
1355 break;
1356 }
1357 }
1358
1359 if (has_carrier)
1360 netif_carrier_on(vlan_dev);
1361 else
1362 netif_carrier_off(vlan_dev);
1363}
1364
1365static void br_vlan_set_all_vlan_dev_state(struct net_bridge_port *p)
1366{
1367 struct net_bridge_vlan_group *vg = nbp_vlan_group(p);
1368 struct net_bridge_vlan *vlan;
1369 struct net_device *vlan_dev;
1370
1371 list_for_each_entry(vlan, &vg->vlan_list, vlist) {
1372 vlan_dev = br_vlan_get_upper_bind_vlan_dev(p->br->dev,
1373 vlan->vid);
1374 if (vlan_dev) {
1375 if (br_vlan_is_dev_up(p->dev)) {
1376 if (netif_carrier_ok(p->br->dev))
1377 netif_carrier_on(vlan_dev);
1378 } else {
1379 br_vlan_set_vlan_dev_state(p->br, vlan_dev);
1380 }
1381 }
1382 }
1383}
1384
1385static void br_vlan_upper_change(struct net_device *dev,
1386 struct net_device *upper_dev,
1387 bool linking)
1388{
1389 struct net_bridge *br = netdev_priv(dev);
1390
1391 if (!br_vlan_is_bind_vlan_dev(upper_dev))
1392 return;
1393
1394 if (linking) {
1395 br_vlan_set_vlan_dev_state(br, upper_dev);
1396 br_opt_toggle(br, BROPT_VLAN_BRIDGE_BINDING, true);
1397 } else {
1398 br_opt_toggle(br, BROPT_VLAN_BRIDGE_BINDING,
1399 br_vlan_has_upper_bind_vlan_dev(dev));
1400 }
1401}
1402
1403struct br_vlan_link_state_walk_data {
1404 struct net_bridge *br;
1405};
1406
1407static int br_vlan_link_state_change_fn(struct net_device *vlan_dev,
1408 void *data_in)
1409{
1410 struct br_vlan_link_state_walk_data *data = data_in;
1411
1412 if (br_vlan_is_bind_vlan_dev(vlan_dev))
1413 br_vlan_set_vlan_dev_state(data->br, vlan_dev);
1414
1415 return 0;
1416}
1417
1418static void br_vlan_link_state_change(struct net_device *dev,
1419 struct net_bridge *br)
1420{
1421 struct br_vlan_link_state_walk_data data = {
1422 .br = br
1423 };
1424
1425 rcu_read_lock();
1426 netdev_walk_all_upper_dev_rcu(dev, br_vlan_link_state_change_fn,
1427 &data);
1428 rcu_read_unlock();
1429}
1430
1431/* Must be protected by RTNL. */
1432static void nbp_vlan_set_vlan_dev_state(struct net_bridge_port *p, u16 vid)
1433{
1434 struct net_device *vlan_dev;
1435
1436 if (!br_opt_get(p->br, BROPT_VLAN_BRIDGE_BINDING))
1437 return;
1438
1439 vlan_dev = br_vlan_get_upper_bind_vlan_dev(p->br->dev, vid);
1440 if (vlan_dev)
1441 br_vlan_set_vlan_dev_state(p->br, vlan_dev);
1442}
1443
1444/* Must be protected by RTNL. */
1445void br_vlan_bridge_event(struct net_device *dev, unsigned long event,
1446 void *ptr)
1447{
1448 struct netdev_notifier_changeupper_info *info;
1449 struct net_bridge *br;
1450
1451 switch (event) {
1452 case NETDEV_CHANGEUPPER:
1453 info = ptr;
1454 br_vlan_upper_change(dev, info->upper_dev, info->linking);
1455 break;
1456
1457 case NETDEV_CHANGE:
1458 case NETDEV_UP:
1459 br = netdev_priv(dev);
1460 if (!br_opt_get(br, BROPT_VLAN_BRIDGE_BINDING))
1461 return;
1462 br_vlan_link_state_change(dev, br);
1463 break;
1464 }
1465}
1466
1467/* Must be protected by RTNL. */
1468void br_vlan_port_event(struct net_bridge_port *p, unsigned long event)
1469{
1470 if (!br_opt_get(p->br, BROPT_VLAN_BRIDGE_BINDING))
1471 return;
1472
1473 switch (event) {
1474 case NETDEV_CHANGE:
1475 case NETDEV_DOWN:
1476 case NETDEV_UP:
1477 br_vlan_set_all_vlan_dev_state(p);
1478 break;
1479 }
1480}
diff --git a/net/bridge/br_vlan_tunnel.c b/net/bridge/br_vlan_tunnel.c
index 6d2c4eed2dc8..758151863669 100644
--- a/net/bridge/br_vlan_tunnel.c
+++ b/net/bridge/br_vlan_tunnel.c
@@ -34,7 +34,6 @@ static const struct rhashtable_params br_vlan_tunnel_rht_params = {
34 .key_offset = offsetof(struct net_bridge_vlan, tinfo.tunnel_id), 34 .key_offset = offsetof(struct net_bridge_vlan, tinfo.tunnel_id),
35 .key_len = sizeof(__be64), 35 .key_len = sizeof(__be64),
36 .nelem_hint = 3, 36 .nelem_hint = 3,
37 .locks_mul = 1,
38 .obj_cmpfn = br_vlan_tunid_cmp, 37 .obj_cmpfn = br_vlan_tunid_cmp,
39 .automatic_shrinking = true, 38 .automatic_shrinking = true,
40}; 39};
diff --git a/net/bridge/netfilter/ebtable_broute.c b/net/bridge/netfilter/ebtable_broute.c
index 276b60262981..ec2652a459da 100644
--- a/net/bridge/netfilter/ebtable_broute.c
+++ b/net/bridge/netfilter/ebtable_broute.c
@@ -15,6 +15,8 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/if_bridge.h> 16#include <linux/if_bridge.h>
17 17
18#include "../br_private.h"
19
18/* EBT_ACCEPT means the frame will be bridged 20/* EBT_ACCEPT means the frame will be bridged
19 * EBT_DROP means the frame will be routed 21 * EBT_DROP means the frame will be routed
20 */ 22 */
@@ -48,30 +50,63 @@ static const struct ebt_table broute_table = {
48 .me = THIS_MODULE, 50 .me = THIS_MODULE,
49}; 51};
50 52
51static int ebt_broute(struct sk_buff *skb) 53static unsigned int ebt_broute(void *priv, struct sk_buff *skb,
54 const struct nf_hook_state *s)
52{ 55{
56 struct net_bridge_port *p = br_port_get_rcu(skb->dev);
53 struct nf_hook_state state; 57 struct nf_hook_state state;
58 unsigned char *dest;
54 int ret; 59 int ret;
55 60
61 if (!p || p->state != BR_STATE_FORWARDING)
62 return NF_ACCEPT;
63
56 nf_hook_state_init(&state, NF_BR_BROUTING, 64 nf_hook_state_init(&state, NF_BR_BROUTING,
57 NFPROTO_BRIDGE, skb->dev, NULL, NULL, 65 NFPROTO_BRIDGE, s->in, NULL, NULL,
58 dev_net(skb->dev), NULL); 66 s->net, NULL);
59 67
60 ret = ebt_do_table(skb, &state, state.net->xt.broute_table); 68 ret = ebt_do_table(skb, &state, state.net->xt.broute_table);
61 if (ret == NF_DROP) 69
62 return 1; /* route it */ 70 if (ret != NF_DROP)
63 return 0; /* bridge it */ 71 return ret;
72
73 /* DROP in ebtables -t broute means that the
74 * skb should be routed, not bridged.
75 * This is awkward, but can't be changed for compatibility
76 * reasons.
77 *
78 * We map DROP to ACCEPT and set the ->br_netfilter_broute flag.
79 */
80 BR_INPUT_SKB_CB(skb)->br_netfilter_broute = 1;
81
82 /* undo PACKET_HOST mangling done in br_input in case the dst
83 * address matches the logical bridge but not the port.
84 */
85 dest = eth_hdr(skb)->h_dest;
86 if (skb->pkt_type == PACKET_HOST &&
87 !ether_addr_equal(skb->dev->dev_addr, dest) &&
88 ether_addr_equal(p->br->dev->dev_addr, dest))
89 skb->pkt_type = PACKET_OTHERHOST;
90
91 return NF_ACCEPT;
64} 92}
65 93
94static const struct nf_hook_ops ebt_ops_broute = {
95 .hook = ebt_broute,
96 .pf = NFPROTO_BRIDGE,
97 .hooknum = NF_BR_PRE_ROUTING,
98 .priority = NF_BR_PRI_FIRST,
99};
100
66static int __net_init broute_net_init(struct net *net) 101static int __net_init broute_net_init(struct net *net)
67{ 102{
68 return ebt_register_table(net, &broute_table, NULL, 103 return ebt_register_table(net, &broute_table, &ebt_ops_broute,
69 &net->xt.broute_table); 104 &net->xt.broute_table);
70} 105}
71 106
72static void __net_exit broute_net_exit(struct net *net) 107static void __net_exit broute_net_exit(struct net *net)
73{ 108{
74 ebt_unregister_table(net, net->xt.broute_table, NULL); 109 ebt_unregister_table(net, net->xt.broute_table, &ebt_ops_broute);
75} 110}
76 111
77static struct pernet_operations broute_net_ops = { 112static struct pernet_operations broute_net_ops = {
@@ -81,21 +116,11 @@ static struct pernet_operations broute_net_ops = {
81 116
82static int __init ebtable_broute_init(void) 117static int __init ebtable_broute_init(void)
83{ 118{
84 int ret; 119 return register_pernet_subsys(&broute_net_ops);
85
86 ret = register_pernet_subsys(&broute_net_ops);
87 if (ret < 0)
88 return ret;
89 /* see br_input.c */
90 RCU_INIT_POINTER(br_should_route_hook,
91 (br_should_route_hook_t *)ebt_broute);
92 return 0;
93} 120}
94 121
95static void __exit ebtable_broute_fini(void) 122static void __exit ebtable_broute_fini(void)
96{ 123{
97 RCU_INIT_POINTER(br_should_route_hook, NULL);
98 synchronize_net();
99 unregister_pernet_subsys(&broute_net_ops); 124 unregister_pernet_subsys(&broute_net_ops);
100} 125}
101 126
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index eb15891f8b9f..6b07e4978eb3 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1221,10 +1221,6 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,
1221 mutex_unlock(&ebt_mutex); 1221 mutex_unlock(&ebt_mutex);
1222 1222
1223 WRITE_ONCE(*res, table); 1223 WRITE_ONCE(*res, table);
1224
1225 if (!ops)
1226 return 0;
1227
1228 ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks)); 1224 ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
1229 if (ret) { 1225 if (ret) {
1230 __ebt_unregister_table(net, table); 1226 __ebt_unregister_table(net, table);
@@ -1248,8 +1244,7 @@ out:
1248void ebt_unregister_table(struct net *net, struct ebt_table *table, 1244void ebt_unregister_table(struct net *net, struct ebt_table *table,
1249 const struct nf_hook_ops *ops) 1245 const struct nf_hook_ops *ops)
1250{ 1246{
1251 if (ops) 1247 nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
1252 nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks));
1253 __ebt_unregister_table(net, table); 1248 __ebt_unregister_table(net, table);
1254} 1249}
1255 1250
@@ -2032,7 +2027,8 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32,
2032 if (match_kern) 2027 if (match_kern)
2033 match_kern->match_size = ret; 2028 match_kern->match_size = ret;
2034 2029
2035 if (WARN_ON(type == EBT_COMPAT_TARGET && size_left)) 2030 /* rule should have no remaining data after target */
2031 if (type == EBT_COMPAT_TARGET && size_left)
2036 return -EINVAL; 2032 return -EINVAL;
2037 2033
2038 match32 = (struct compat_ebt_entry_mwt *) buf; 2034 match32 = (struct compat_ebt_entry_mwt *) buf;
@@ -2157,7 +2153,9 @@ static int compat_copy_entries(unsigned char *data, unsigned int size_user,
2157 if (ret < 0) 2153 if (ret < 0)
2158 return ret; 2154 return ret;
2159 2155
2160 WARN_ON(size_remaining); 2156 if (size_remaining)
2157 return -EINVAL;
2158
2161 return state->buf_kern_offset; 2159 return state->buf_kern_offset;
2162} 2160}
2163 2161
diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
index 711d7156efd8..6c6e01963aac 100644
--- a/net/caif/caif_dev.c
+++ b/net/caif/caif_dev.c
@@ -186,15 +186,19 @@ static int transmit(struct cflayer *layer, struct cfpkt *pkt)
186 goto noxoff; 186 goto noxoff;
187 187
188 if (likely(!netif_queue_stopped(caifd->netdev))) { 188 if (likely(!netif_queue_stopped(caifd->netdev))) {
189 struct Qdisc *sch;
190
189 /* If we run with a TX queue, check if the queue is too long*/ 191 /* If we run with a TX queue, check if the queue is too long*/
190 txq = netdev_get_tx_queue(skb->dev, 0); 192 txq = netdev_get_tx_queue(skb->dev, 0);
191 qlen = qdisc_qlen(rcu_dereference_bh(txq->qdisc)); 193 sch = rcu_dereference_bh(txq->qdisc);
192 194 if (likely(qdisc_is_empty(sch)))
193 if (likely(qlen == 0))
194 goto noxoff; 195 goto noxoff;
195 196
197 /* can check for explicit qdisc len value only !NOLOCK,
198 * always set flow off otherwise
199 */
196 high = (caifd->netdev->tx_queue_len * q_high) / 100; 200 high = (caifd->netdev->tx_queue_len * q_high) / 100;
197 if (likely(qlen < high)) 201 if (!(sch->flags & TCQ_F_NOLOCK) && likely(sch->q.qlen < high))
198 goto noxoff; 202 goto noxoff;
199 } 203 }
200 204
diff --git a/net/can/af_can.c b/net/can/af_can.c
index 1684ba5b51eb..e8fd5dc1780a 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -89,13 +89,7 @@ static atomic_t skbcounter = ATOMIC_INIT(0);
89 89
90int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 90int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
91{ 91{
92 struct sock *sk = sock->sk;
93
94 switch (cmd) { 92 switch (cmd) {
95
96 case SIOCGSTAMP:
97 return sock_get_timestamp(sk, (struct timeval __user *)arg);
98
99 default: 93 default:
100 return -ENOIOCTLCMD; 94 return -ENOIOCTLCMD;
101 } 95 }
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 79bb8afa9c0c..a34ee52f19ea 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -1689,6 +1689,7 @@ static const struct proto_ops bcm_ops = {
1689 .getname = sock_no_getname, 1689 .getname = sock_no_getname,
1690 .poll = datagram_poll, 1690 .poll = datagram_poll,
1691 .ioctl = can_ioctl, /* use can_ioctl() from af_can.c */ 1691 .ioctl = can_ioctl, /* use can_ioctl() from af_can.c */
1692 .gettstamp = sock_gettstamp,
1692 .listen = sock_no_listen, 1693 .listen = sock_no_listen,
1693 .shutdown = sock_no_shutdown, 1694 .shutdown = sock_no_shutdown,
1694 .setsockopt = sock_no_setsockopt, 1695 .setsockopt = sock_no_setsockopt,
diff --git a/net/can/gw.c b/net/can/gw.c
index 53859346dc9a..5275ddf580bc 100644
--- a/net/can/gw.c
+++ b/net/can/gw.c
@@ -662,8 +662,8 @@ static int cgw_parse_attr(struct nlmsghdr *nlh, struct cf_mod *mod,
662 /* initialize modification & checksum data space */ 662 /* initialize modification & checksum data space */
663 memset(mod, 0, sizeof(*mod)); 663 memset(mod, 0, sizeof(*mod));
664 664
665 err = nlmsg_parse(nlh, sizeof(struct rtcanmsg), tb, CGW_MAX, 665 err = nlmsg_parse_deprecated(nlh, sizeof(struct rtcanmsg), tb,
666 cgw_policy, NULL); 666 CGW_MAX, cgw_policy, NULL);
667 if (err < 0) 667 if (err < 0)
668 return err; 668 return err;
669 669
diff --git a/net/can/raw.c b/net/can/raw.c
index c70207537488..afcbff063a67 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -846,6 +846,7 @@ static const struct proto_ops raw_ops = {
846 .getname = raw_getname, 846 .getname = raw_getname,
847 .poll = datagram_poll, 847 .poll = datagram_poll,
848 .ioctl = can_ioctl, /* use can_ioctl() from af_can.c */ 848 .ioctl = can_ioctl, /* use can_ioctl() from af_can.c */
849 .gettstamp = sock_gettstamp,
849 .listen = sock_no_listen, 850 .listen = sock_no_listen,
850 .shutdown = sock_no_shutdown, 851 .shutdown = sock_no_shutdown,
851 .setsockopt = raw_setsockopt, 852 .setsockopt = raw_setsockopt,
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index fa9530dd876e..6f739de28918 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -2398,7 +2398,7 @@ static void finish_request(struct ceph_osd_request *req)
2398 2398
2399static void __complete_request(struct ceph_osd_request *req) 2399static void __complete_request(struct ceph_osd_request *req)
2400{ 2400{
2401 dout("%s req %p tid %llu cb %pf result %d\n", __func__, req, 2401 dout("%s req %p tid %llu cb %ps result %d\n", __func__, req,
2402 req->r_tid, req->r_callback, req->r_result); 2402 req->r_tid, req->r_callback, req->r_result);
2403 2403
2404 if (req->r_callback) 2404 if (req->r_callback)
diff --git a/net/ceph/pagevec.c b/net/ceph/pagevec.c
index d3736f5bffec..74cafc0142ea 100644
--- a/net/ceph/pagevec.c
+++ b/net/ceph/pagevec.c
@@ -27,7 +27,7 @@ struct page **ceph_get_direct_page_vector(const void __user *data,
27 while (got < num_pages) { 27 while (got < num_pages) {
28 rc = get_user_pages_fast( 28 rc = get_user_pages_fast(
29 (unsigned long)data + ((unsigned long)got * PAGE_SIZE), 29 (unsigned long)data + ((unsigned long)got * PAGE_SIZE),
30 num_pages - got, write_page, pages + got); 30 num_pages - got, write_page ? FOLL_WRITE : 0, pages + got);
31 if (rc < 0) 31 if (rc < 0)
32 break; 32 break;
33 BUG_ON(rc == 0); 33 BUG_ON(rc == 0);
diff --git a/net/compat.c b/net/compat.c
index eeea5eb71639..a031bd333092 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -395,63 +395,6 @@ COMPAT_SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname,
395 return __compat_sys_setsockopt(fd, level, optname, optval, optlen); 395 return __compat_sys_setsockopt(fd, level, optname, optval, optlen);
396} 396}
397 397
398int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp)
399{
400 struct compat_timeval __user *ctv;
401 int err;
402 struct timeval tv;
403
404 if (COMPAT_USE_64BIT_TIME)
405 return sock_get_timestamp(sk, userstamp);
406
407 ctv = (struct compat_timeval __user *) userstamp;
408 err = -ENOENT;
409 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
410 tv = ktime_to_timeval(sock_read_timestamp(sk));
411
412 if (tv.tv_sec == -1)
413 return err;
414 if (tv.tv_sec == 0) {
415 ktime_t kt = ktime_get_real();
416 sock_write_timestamp(sk, kt);
417 tv = ktime_to_timeval(kt);
418 }
419 err = 0;
420 if (put_user(tv.tv_sec, &ctv->tv_sec) ||
421 put_user(tv.tv_usec, &ctv->tv_usec))
422 err = -EFAULT;
423 return err;
424}
425EXPORT_SYMBOL(compat_sock_get_timestamp);
426
427int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp)
428{
429 struct compat_timespec __user *ctv;
430 int err;
431 struct timespec ts;
432
433 if (COMPAT_USE_64BIT_TIME)
434 return sock_get_timestampns (sk, userstamp);
435
436 ctv = (struct compat_timespec __user *) userstamp;
437 err = -ENOENT;
438 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
439 ts = ktime_to_timespec(sock_read_timestamp(sk));
440 if (ts.tv_sec == -1)
441 return err;
442 if (ts.tv_sec == 0) {
443 ktime_t kt = ktime_get_real();
444 sock_write_timestamp(sk, kt);
445 ts = ktime_to_timespec(kt);
446 }
447 err = 0;
448 if (put_user(ts.tv_sec, &ctv->tv_sec) ||
449 put_user(ts.tv_nsec, &ctv->tv_nsec))
450 err = -EFAULT;
451 return err;
452}
453EXPORT_SYMBOL(compat_sock_get_timestampns);
454
455static int __compat_sys_getsockopt(int fd, int level, int optname, 398static int __compat_sys_getsockopt(int fd, int level, int optname,
456 char __user *optval, 399 char __user *optval,
457 int __user *optlen) 400 int __user *optlen)
diff --git a/net/core/Makefile b/net/core/Makefile
index f97d6254e564..a104dc8faafc 100644
--- a/net/core/Makefile
+++ b/net/core/Makefile
@@ -34,3 +34,4 @@ obj-$(CONFIG_HWBM) += hwbm.o
34obj-$(CONFIG_NET_DEVLINK) += devlink.o 34obj-$(CONFIG_NET_DEVLINK) += devlink.o
35obj-$(CONFIG_GRO_CELLS) += gro_cells.o 35obj-$(CONFIG_GRO_CELLS) += gro_cells.o
36obj-$(CONFIG_FAILOVER) += failover.o 36obj-$(CONFIG_FAILOVER) += failover.o
37obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o
diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
new file mode 100644
index 000000000000..cc9597a87770
--- /dev/null
+++ b/net/core/bpf_sk_storage.c
@@ -0,0 +1,804 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2019 Facebook */
3#include <linux/rculist.h>
4#include <linux/list.h>
5#include <linux/hash.h>
6#include <linux/types.h>
7#include <linux/spinlock.h>
8#include <linux/bpf.h>
9#include <net/bpf_sk_storage.h>
10#include <net/sock.h>
11#include <uapi/linux/btf.h>
12
13static atomic_t cache_idx;
14
15struct bucket {
16 struct hlist_head list;
17 raw_spinlock_t lock;
18};
19
20/* Thp map is not the primary owner of a bpf_sk_storage_elem.
21 * Instead, the sk->sk_bpf_storage is.
22 *
23 * The map (bpf_sk_storage_map) is for two purposes
24 * 1. Define the size of the "sk local storage". It is
25 * the map's value_size.
26 *
27 * 2. Maintain a list to keep track of all elems such
28 * that they can be cleaned up during the map destruction.
29 *
30 * When a bpf local storage is being looked up for a
31 * particular sk, the "bpf_map" pointer is actually used
32 * as the "key" to search in the list of elem in
33 * sk->sk_bpf_storage.
34 *
35 * Hence, consider sk->sk_bpf_storage is the mini-map
36 * with the "bpf_map" pointer as the searching key.
37 */
38struct bpf_sk_storage_map {
39 struct bpf_map map;
40 /* Lookup elem does not require accessing the map.
41 *
42 * Updating/Deleting requires a bucket lock to
43 * link/unlink the elem from the map. Having
44 * multiple buckets to improve contention.
45 */
46 struct bucket *buckets;
47 u32 bucket_log;
48 u16 elem_size;
49 u16 cache_idx;
50};
51
52struct bpf_sk_storage_data {
53 /* smap is used as the searching key when looking up
54 * from sk->sk_bpf_storage.
55 *
56 * Put it in the same cacheline as the data to minimize
57 * the number of cachelines access during the cache hit case.
58 */
59 struct bpf_sk_storage_map __rcu *smap;
60 u8 data[0] __aligned(8);
61};
62
63/* Linked to bpf_sk_storage and bpf_sk_storage_map */
64struct bpf_sk_storage_elem {
65 struct hlist_node map_node; /* Linked to bpf_sk_storage_map */
66 struct hlist_node snode; /* Linked to bpf_sk_storage */
67 struct bpf_sk_storage __rcu *sk_storage;
68 struct rcu_head rcu;
69 /* 8 bytes hole */
70 /* The data is stored in aother cacheline to minimize
71 * the number of cachelines access during a cache hit.
72 */
73 struct bpf_sk_storage_data sdata ____cacheline_aligned;
74};
75
76#define SELEM(_SDATA) container_of((_SDATA), struct bpf_sk_storage_elem, sdata)
77#define SDATA(_SELEM) (&(_SELEM)->sdata)
78#define BPF_SK_STORAGE_CACHE_SIZE 16
79
80struct bpf_sk_storage {
81 struct bpf_sk_storage_data __rcu *cache[BPF_SK_STORAGE_CACHE_SIZE];
82 struct hlist_head list; /* List of bpf_sk_storage_elem */
83 struct sock *sk; /* The sk that owns the the above "list" of
84 * bpf_sk_storage_elem.
85 */
86 struct rcu_head rcu;
87 raw_spinlock_t lock; /* Protect adding/removing from the "list" */
88};
89
90static struct bucket *select_bucket(struct bpf_sk_storage_map *smap,
91 struct bpf_sk_storage_elem *selem)
92{
93 return &smap->buckets[hash_ptr(selem, smap->bucket_log)];
94}
95
96static int omem_charge(struct sock *sk, unsigned int size)
97{
98 /* same check as in sock_kmalloc() */
99 if (size <= sysctl_optmem_max &&
100 atomic_read(&sk->sk_omem_alloc) + size < sysctl_optmem_max) {
101 atomic_add(size, &sk->sk_omem_alloc);
102 return 0;
103 }
104
105 return -ENOMEM;
106}
107
108static bool selem_linked_to_sk(const struct bpf_sk_storage_elem *selem)
109{
110 return !hlist_unhashed(&selem->snode);
111}
112
113static bool selem_linked_to_map(const struct bpf_sk_storage_elem *selem)
114{
115 return !hlist_unhashed(&selem->map_node);
116}
117
118static struct bpf_sk_storage_elem *selem_alloc(struct bpf_sk_storage_map *smap,
119 struct sock *sk, void *value,
120 bool charge_omem)
121{
122 struct bpf_sk_storage_elem *selem;
123
124 if (charge_omem && omem_charge(sk, smap->elem_size))
125 return NULL;
126
127 selem = kzalloc(smap->elem_size, GFP_ATOMIC | __GFP_NOWARN);
128 if (selem) {
129 if (value)
130 memcpy(SDATA(selem)->data, value, smap->map.value_size);
131 return selem;
132 }
133
134 if (charge_omem)
135 atomic_sub(smap->elem_size, &sk->sk_omem_alloc);
136
137 return NULL;
138}
139
140/* sk_storage->lock must be held and selem->sk_storage == sk_storage.
141 * The caller must ensure selem->smap is still valid to be
142 * dereferenced for its smap->elem_size and smap->cache_idx.
143 */
144static bool __selem_unlink_sk(struct bpf_sk_storage *sk_storage,
145 struct bpf_sk_storage_elem *selem,
146 bool uncharge_omem)
147{
148 struct bpf_sk_storage_map *smap;
149 bool free_sk_storage;
150 struct sock *sk;
151
152 smap = rcu_dereference(SDATA(selem)->smap);
153 sk = sk_storage->sk;
154
155 /* All uncharging on sk->sk_omem_alloc must be done first.
156 * sk may be freed once the last selem is unlinked from sk_storage.
157 */
158 if (uncharge_omem)
159 atomic_sub(smap->elem_size, &sk->sk_omem_alloc);
160
161 free_sk_storage = hlist_is_singular_node(&selem->snode,
162 &sk_storage->list);
163 if (free_sk_storage) {
164 atomic_sub(sizeof(struct bpf_sk_storage), &sk->sk_omem_alloc);
165 sk_storage->sk = NULL;
166 /* After this RCU_INIT, sk may be freed and cannot be used */
167 RCU_INIT_POINTER(sk->sk_bpf_storage, NULL);
168
169 /* sk_storage is not freed now. sk_storage->lock is
170 * still held and raw_spin_unlock_bh(&sk_storage->lock)
171 * will be done by the caller.
172 *
173 * Although the unlock will be done under
174 * rcu_read_lock(), it is more intutivie to
175 * read if kfree_rcu(sk_storage, rcu) is done
176 * after the raw_spin_unlock_bh(&sk_storage->lock).
177 *
178 * Hence, a "bool free_sk_storage" is returned
179 * to the caller which then calls the kfree_rcu()
180 * after unlock.
181 */
182 }
183 hlist_del_init_rcu(&selem->snode);
184 if (rcu_access_pointer(sk_storage->cache[smap->cache_idx]) ==
185 SDATA(selem))
186 RCU_INIT_POINTER(sk_storage->cache[smap->cache_idx], NULL);
187
188 kfree_rcu(selem, rcu);
189
190 return free_sk_storage;
191}
192
193static void selem_unlink_sk(struct bpf_sk_storage_elem *selem)
194{
195 struct bpf_sk_storage *sk_storage;
196 bool free_sk_storage = false;
197
198 if (unlikely(!selem_linked_to_sk(selem)))
199 /* selem has already been unlinked from sk */
200 return;
201
202 sk_storage = rcu_dereference(selem->sk_storage);
203 raw_spin_lock_bh(&sk_storage->lock);
204 if (likely(selem_linked_to_sk(selem)))
205 free_sk_storage = __selem_unlink_sk(sk_storage, selem, true);
206 raw_spin_unlock_bh(&sk_storage->lock);
207
208 if (free_sk_storage)
209 kfree_rcu(sk_storage, rcu);
210}
211
212/* sk_storage->lock must be held and sk_storage->list cannot be empty */
213static void __selem_link_sk(struct bpf_sk_storage *sk_storage,
214 struct bpf_sk_storage_elem *selem)
215{
216 RCU_INIT_POINTER(selem->sk_storage, sk_storage);
217 hlist_add_head(&selem->snode, &sk_storage->list);
218}
219
220static void selem_unlink_map(struct bpf_sk_storage_elem *selem)
221{
222 struct bpf_sk_storage_map *smap;
223 struct bucket *b;
224
225 if (unlikely(!selem_linked_to_map(selem)))
226 /* selem has already be unlinked from smap */
227 return;
228
229 smap = rcu_dereference(SDATA(selem)->smap);
230 b = select_bucket(smap, selem);
231 raw_spin_lock_bh(&b->lock);
232 if (likely(selem_linked_to_map(selem)))
233 hlist_del_init_rcu(&selem->map_node);
234 raw_spin_unlock_bh(&b->lock);
235}
236
237static void selem_link_map(struct bpf_sk_storage_map *smap,
238 struct bpf_sk_storage_elem *selem)
239{
240 struct bucket *b = select_bucket(smap, selem);
241
242 raw_spin_lock_bh(&b->lock);
243 RCU_INIT_POINTER(SDATA(selem)->smap, smap);
244 hlist_add_head_rcu(&selem->map_node, &b->list);
245 raw_spin_unlock_bh(&b->lock);
246}
247
248static void selem_unlink(struct bpf_sk_storage_elem *selem)
249{
250 /* Always unlink from map before unlinking from sk_storage
251 * because selem will be freed after successfully unlinked from
252 * the sk_storage.
253 */
254 selem_unlink_map(selem);
255 selem_unlink_sk(selem);
256}
257
258static struct bpf_sk_storage_data *
259__sk_storage_lookup(struct bpf_sk_storage *sk_storage,
260 struct bpf_sk_storage_map *smap,
261 bool cacheit_lockit)
262{
263 struct bpf_sk_storage_data *sdata;
264 struct bpf_sk_storage_elem *selem;
265
266 /* Fast path (cache hit) */
267 sdata = rcu_dereference(sk_storage->cache[smap->cache_idx]);
268 if (sdata && rcu_access_pointer(sdata->smap) == smap)
269 return sdata;
270
271 /* Slow path (cache miss) */
272 hlist_for_each_entry_rcu(selem, &sk_storage->list, snode)
273 if (rcu_access_pointer(SDATA(selem)->smap) == smap)
274 break;
275
276 if (!selem)
277 return NULL;
278
279 sdata = SDATA(selem);
280 if (cacheit_lockit) {
281 /* spinlock is needed to avoid racing with the
282 * parallel delete. Otherwise, publishing an already
283 * deleted sdata to the cache will become a use-after-free
284 * problem in the next __sk_storage_lookup().
285 */
286 raw_spin_lock_bh(&sk_storage->lock);
287 if (selem_linked_to_sk(selem))
288 rcu_assign_pointer(sk_storage->cache[smap->cache_idx],
289 sdata);
290 raw_spin_unlock_bh(&sk_storage->lock);
291 }
292
293 return sdata;
294}
295
296static struct bpf_sk_storage_data *
297sk_storage_lookup(struct sock *sk, struct bpf_map *map, bool cacheit_lockit)
298{
299 struct bpf_sk_storage *sk_storage;
300 struct bpf_sk_storage_map *smap;
301
302 sk_storage = rcu_dereference(sk->sk_bpf_storage);
303 if (!sk_storage)
304 return NULL;
305
306 smap = (struct bpf_sk_storage_map *)map;
307 return __sk_storage_lookup(sk_storage, smap, cacheit_lockit);
308}
309
310static int check_flags(const struct bpf_sk_storage_data *old_sdata,
311 u64 map_flags)
312{
313 if (old_sdata && (map_flags & ~BPF_F_LOCK) == BPF_NOEXIST)
314 /* elem already exists */
315 return -EEXIST;
316
317 if (!old_sdata && (map_flags & ~BPF_F_LOCK) == BPF_EXIST)
318 /* elem doesn't exist, cannot update it */
319 return -ENOENT;
320
321 return 0;
322}
323
324static int sk_storage_alloc(struct sock *sk,
325 struct bpf_sk_storage_map *smap,
326 struct bpf_sk_storage_elem *first_selem)
327{
328 struct bpf_sk_storage *prev_sk_storage, *sk_storage;
329 int err;
330
331 err = omem_charge(sk, sizeof(*sk_storage));
332 if (err)
333 return err;
334
335 sk_storage = kzalloc(sizeof(*sk_storage), GFP_ATOMIC | __GFP_NOWARN);
336 if (!sk_storage) {
337 err = -ENOMEM;
338 goto uncharge;
339 }
340 INIT_HLIST_HEAD(&sk_storage->list);
341 raw_spin_lock_init(&sk_storage->lock);
342 sk_storage->sk = sk;
343
344 __selem_link_sk(sk_storage, first_selem);
345 selem_link_map(smap, first_selem);
346 /* Publish sk_storage to sk. sk->sk_lock cannot be acquired.
347 * Hence, atomic ops is used to set sk->sk_bpf_storage
348 * from NULL to the newly allocated sk_storage ptr.
349 *
350 * From now on, the sk->sk_bpf_storage pointer is protected
351 * by the sk_storage->lock. Hence, when freeing
352 * the sk->sk_bpf_storage, the sk_storage->lock must
353 * be held before setting sk->sk_bpf_storage to NULL.
354 */
355 prev_sk_storage = cmpxchg((struct bpf_sk_storage **)&sk->sk_bpf_storage,
356 NULL, sk_storage);
357 if (unlikely(prev_sk_storage)) {
358 selem_unlink_map(first_selem);
359 err = -EAGAIN;
360 goto uncharge;
361
362 /* Note that even first_selem was linked to smap's
363 * bucket->list, first_selem can be freed immediately
364 * (instead of kfree_rcu) because
365 * bpf_sk_storage_map_free() does a
366 * synchronize_rcu() before walking the bucket->list.
367 * Hence, no one is accessing selem from the
368 * bucket->list under rcu_read_lock().
369 */
370 }
371
372 return 0;
373
374uncharge:
375 kfree(sk_storage);
376 atomic_sub(sizeof(*sk_storage), &sk->sk_omem_alloc);
377 return err;
378}
379
380/* sk cannot be going away because it is linking new elem
381 * to sk->sk_bpf_storage. (i.e. sk->sk_refcnt cannot be 0).
382 * Otherwise, it will become a leak (and other memory issues
383 * during map destruction).
384 */
385static struct bpf_sk_storage_data *sk_storage_update(struct sock *sk,
386 struct bpf_map *map,
387 void *value,
388 u64 map_flags)
389{
390 struct bpf_sk_storage_data *old_sdata = NULL;
391 struct bpf_sk_storage_elem *selem;
392 struct bpf_sk_storage *sk_storage;
393 struct bpf_sk_storage_map *smap;
394 int err;
395
396 /* BPF_EXIST and BPF_NOEXIST cannot be both set */
397 if (unlikely((map_flags & ~BPF_F_LOCK) > BPF_EXIST) ||
398 /* BPF_F_LOCK can only be used in a value with spin_lock */
399 unlikely((map_flags & BPF_F_LOCK) && !map_value_has_spin_lock(map)))
400 return ERR_PTR(-EINVAL);
401
402 smap = (struct bpf_sk_storage_map *)map;
403 sk_storage = rcu_dereference(sk->sk_bpf_storage);
404 if (!sk_storage || hlist_empty(&sk_storage->list)) {
405 /* Very first elem for this sk */
406 err = check_flags(NULL, map_flags);
407 if (err)
408 return ERR_PTR(err);
409
410 selem = selem_alloc(smap, sk, value, true);
411 if (!selem)
412 return ERR_PTR(-ENOMEM);
413
414 err = sk_storage_alloc(sk, smap, selem);
415 if (err) {
416 kfree(selem);
417 atomic_sub(smap->elem_size, &sk->sk_omem_alloc);
418 return ERR_PTR(err);
419 }
420
421 return SDATA(selem);
422 }
423
424 if ((map_flags & BPF_F_LOCK) && !(map_flags & BPF_NOEXIST)) {
425 /* Hoping to find an old_sdata to do inline update
426 * such that it can avoid taking the sk_storage->lock
427 * and changing the lists.
428 */
429 old_sdata = __sk_storage_lookup(sk_storage, smap, false);
430 err = check_flags(old_sdata, map_flags);
431 if (err)
432 return ERR_PTR(err);
433 if (old_sdata && selem_linked_to_sk(SELEM(old_sdata))) {
434 copy_map_value_locked(map, old_sdata->data,
435 value, false);
436 return old_sdata;
437 }
438 }
439
440 raw_spin_lock_bh(&sk_storage->lock);
441
442 /* Recheck sk_storage->list under sk_storage->lock */
443 if (unlikely(hlist_empty(&sk_storage->list))) {
444 /* A parallel del is happening and sk_storage is going
445 * away. It has just been checked before, so very
446 * unlikely. Return instead of retry to keep things
447 * simple.
448 */
449 err = -EAGAIN;
450 goto unlock_err;
451 }
452
453 old_sdata = __sk_storage_lookup(sk_storage, smap, false);
454 err = check_flags(old_sdata, map_flags);
455 if (err)
456 goto unlock_err;
457
458 if (old_sdata && (map_flags & BPF_F_LOCK)) {
459 copy_map_value_locked(map, old_sdata->data, value, false);
460 selem = SELEM(old_sdata);
461 goto unlock;
462 }
463
464 /* sk_storage->lock is held. Hence, we are sure
465 * we can unlink and uncharge the old_sdata successfully
466 * later. Hence, instead of charging the new selem now
467 * and then uncharge the old selem later (which may cause
468 * a potential but unnecessary charge failure), avoid taking
469 * a charge at all here (the "!old_sdata" check) and the
470 * old_sdata will not be uncharged later during __selem_unlink_sk().
471 */
472 selem = selem_alloc(smap, sk, value, !old_sdata);
473 if (!selem) {
474 err = -ENOMEM;
475 goto unlock_err;
476 }
477
478 /* First, link the new selem to the map */
479 selem_link_map(smap, selem);
480
481 /* Second, link (and publish) the new selem to sk_storage */
482 __selem_link_sk(sk_storage, selem);
483
484 /* Third, remove old selem, SELEM(old_sdata) */
485 if (old_sdata) {
486 selem_unlink_map(SELEM(old_sdata));
487 __selem_unlink_sk(sk_storage, SELEM(old_sdata), false);
488 }
489
490unlock:
491 raw_spin_unlock_bh(&sk_storage->lock);
492 return SDATA(selem);
493
494unlock_err:
495 raw_spin_unlock_bh(&sk_storage->lock);
496 return ERR_PTR(err);
497}
498
499static int sk_storage_delete(struct sock *sk, struct bpf_map *map)
500{
501 struct bpf_sk_storage_data *sdata;
502
503 sdata = sk_storage_lookup(sk, map, false);
504 if (!sdata)
505 return -ENOENT;
506
507 selem_unlink(SELEM(sdata));
508
509 return 0;
510}
511
512/* Called by __sk_destruct() */
513void bpf_sk_storage_free(struct sock *sk)
514{
515 struct bpf_sk_storage_elem *selem;
516 struct bpf_sk_storage *sk_storage;
517 bool free_sk_storage = false;
518 struct hlist_node *n;
519
520 rcu_read_lock();
521 sk_storage = rcu_dereference(sk->sk_bpf_storage);
522 if (!sk_storage) {
523 rcu_read_unlock();
524 return;
525 }
526
527 /* Netiher the bpf_prog nor the bpf-map's syscall
528 * could be modifying the sk_storage->list now.
529 * Thus, no elem can be added-to or deleted-from the
530 * sk_storage->list by the bpf_prog or by the bpf-map's syscall.
531 *
532 * It is racing with bpf_sk_storage_map_free() alone
533 * when unlinking elem from the sk_storage->list and
534 * the map's bucket->list.
535 */
536 raw_spin_lock_bh(&sk_storage->lock);
537 hlist_for_each_entry_safe(selem, n, &sk_storage->list, snode) {
538 /* Always unlink from map before unlinking from
539 * sk_storage.
540 */
541 selem_unlink_map(selem);
542 free_sk_storage = __selem_unlink_sk(sk_storage, selem, true);
543 }
544 raw_spin_unlock_bh(&sk_storage->lock);
545 rcu_read_unlock();
546
547 if (free_sk_storage)
548 kfree_rcu(sk_storage, rcu);
549}
550
551static void bpf_sk_storage_map_free(struct bpf_map *map)
552{
553 struct bpf_sk_storage_elem *selem;
554 struct bpf_sk_storage_map *smap;
555 struct bucket *b;
556 unsigned int i;
557
558 smap = (struct bpf_sk_storage_map *)map;
559
560 synchronize_rcu();
561
562 /* bpf prog and the userspace can no longer access this map
563 * now. No new selem (of this map) can be added
564 * to the sk->sk_bpf_storage or to the map bucket's list.
565 *
566 * The elem of this map can be cleaned up here
567 * or
568 * by bpf_sk_storage_free() during __sk_destruct().
569 */
570 for (i = 0; i < (1U << smap->bucket_log); i++) {
571 b = &smap->buckets[i];
572
573 rcu_read_lock();
574 /* No one is adding to b->list now */
575 while ((selem = hlist_entry_safe(rcu_dereference_raw(hlist_first_rcu(&b->list)),
576 struct bpf_sk_storage_elem,
577 map_node))) {
578 selem_unlink(selem);
579 cond_resched_rcu();
580 }
581 rcu_read_unlock();
582 }
583
584 /* bpf_sk_storage_free() may still need to access the map.
585 * e.g. bpf_sk_storage_free() has unlinked selem from the map
586 * which then made the above while((selem = ...)) loop
587 * exited immediately.
588 *
589 * However, the bpf_sk_storage_free() still needs to access
590 * the smap->elem_size to do the uncharging in
591 * __selem_unlink_sk().
592 *
593 * Hence, wait another rcu grace period for the
594 * bpf_sk_storage_free() to finish.
595 */
596 synchronize_rcu();
597
598 kvfree(smap->buckets);
599 kfree(map);
600}
601
602static int bpf_sk_storage_map_alloc_check(union bpf_attr *attr)
603{
604 if (attr->map_flags != BPF_F_NO_PREALLOC || attr->max_entries ||
605 attr->key_size != sizeof(int) || !attr->value_size ||
606 /* Enforce BTF for userspace sk dumping */
607 !attr->btf_key_type_id || !attr->btf_value_type_id)
608 return -EINVAL;
609
610 if (!capable(CAP_SYS_ADMIN))
611 return -EPERM;
612
613 if (attr->value_size >= KMALLOC_MAX_SIZE -
614 MAX_BPF_STACK - sizeof(struct bpf_sk_storage_elem) ||
615 /* U16_MAX is much more than enough for sk local storage
616 * considering a tcp_sock is ~2k.
617 */
618 attr->value_size > U16_MAX - sizeof(struct bpf_sk_storage_elem))
619 return -E2BIG;
620
621 return 0;
622}
623
624static struct bpf_map *bpf_sk_storage_map_alloc(union bpf_attr *attr)
625{
626 struct bpf_sk_storage_map *smap;
627 unsigned int i;
628 u32 nbuckets;
629 u64 cost;
630
631 smap = kzalloc(sizeof(*smap), GFP_USER | __GFP_NOWARN);
632 if (!smap)
633 return ERR_PTR(-ENOMEM);
634 bpf_map_init_from_attr(&smap->map, attr);
635
636 smap->bucket_log = ilog2(roundup_pow_of_two(num_possible_cpus()));
637 nbuckets = 1U << smap->bucket_log;
638 smap->buckets = kvcalloc(sizeof(*smap->buckets), nbuckets,
639 GFP_USER | __GFP_NOWARN);
640 if (!smap->buckets) {
641 kfree(smap);
642 return ERR_PTR(-ENOMEM);
643 }
644 cost = sizeof(*smap->buckets) * nbuckets + sizeof(*smap);
645
646 for (i = 0; i < nbuckets; i++) {
647 INIT_HLIST_HEAD(&smap->buckets[i].list);
648 raw_spin_lock_init(&smap->buckets[i].lock);
649 }
650
651 smap->elem_size = sizeof(struct bpf_sk_storage_elem) + attr->value_size;
652 smap->cache_idx = (unsigned int)atomic_inc_return(&cache_idx) %
653 BPF_SK_STORAGE_CACHE_SIZE;
654 smap->map.pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT;
655
656 return &smap->map;
657}
658
659static int notsupp_get_next_key(struct bpf_map *map, void *key,
660 void *next_key)
661{
662 return -ENOTSUPP;
663}
664
665static int bpf_sk_storage_map_check_btf(const struct bpf_map *map,
666 const struct btf *btf,
667 const struct btf_type *key_type,
668 const struct btf_type *value_type)
669{
670 u32 int_data;
671
672 if (BTF_INFO_KIND(key_type->info) != BTF_KIND_INT)
673 return -EINVAL;
674
675 int_data = *(u32 *)(key_type + 1);
676 if (BTF_INT_BITS(int_data) != 32 || BTF_INT_OFFSET(int_data))
677 return -EINVAL;
678
679 return 0;
680}
681
682static void *bpf_fd_sk_storage_lookup_elem(struct bpf_map *map, void *key)
683{
684 struct bpf_sk_storage_data *sdata;
685 struct socket *sock;
686 int fd, err;
687
688 fd = *(int *)key;
689 sock = sockfd_lookup(fd, &err);
690 if (sock) {
691 sdata = sk_storage_lookup(sock->sk, map, true);
692 sockfd_put(sock);
693 return sdata ? sdata->data : NULL;
694 }
695
696 return ERR_PTR(err);
697}
698
699static int bpf_fd_sk_storage_update_elem(struct bpf_map *map, void *key,
700 void *value, u64 map_flags)
701{
702 struct bpf_sk_storage_data *sdata;
703 struct socket *sock;
704 int fd, err;
705
706 fd = *(int *)key;
707 sock = sockfd_lookup(fd, &err);
708 if (sock) {
709 sdata = sk_storage_update(sock->sk, map, value, map_flags);
710 sockfd_put(sock);
711 return PTR_ERR_OR_ZERO(sdata);
712 }
713
714 return err;
715}
716
717static int bpf_fd_sk_storage_delete_elem(struct bpf_map *map, void *key)
718{
719 struct socket *sock;
720 int fd, err;
721
722 fd = *(int *)key;
723 sock = sockfd_lookup(fd, &err);
724 if (sock) {
725 err = sk_storage_delete(sock->sk, map);
726 sockfd_put(sock);
727 return err;
728 }
729
730 return err;
731}
732
733BPF_CALL_4(bpf_sk_storage_get, struct bpf_map *, map, struct sock *, sk,
734 void *, value, u64, flags)
735{
736 struct bpf_sk_storage_data *sdata;
737
738 if (flags > BPF_SK_STORAGE_GET_F_CREATE)
739 return (unsigned long)NULL;
740
741 sdata = sk_storage_lookup(sk, map, true);
742 if (sdata)
743 return (unsigned long)sdata->data;
744
745 if (flags == BPF_SK_STORAGE_GET_F_CREATE &&
746 /* Cannot add new elem to a going away sk.
747 * Otherwise, the new elem may become a leak
748 * (and also other memory issues during map
749 * destruction).
750 */
751 refcount_inc_not_zero(&sk->sk_refcnt)) {
752 sdata = sk_storage_update(sk, map, value, BPF_NOEXIST);
753 /* sk must be a fullsock (guaranteed by verifier),
754 * so sock_gen_put() is unnecessary.
755 */
756 sock_put(sk);
757 return IS_ERR(sdata) ?
758 (unsigned long)NULL : (unsigned long)sdata->data;
759 }
760
761 return (unsigned long)NULL;
762}
763
764BPF_CALL_2(bpf_sk_storage_delete, struct bpf_map *, map, struct sock *, sk)
765{
766 if (refcount_inc_not_zero(&sk->sk_refcnt)) {
767 int err;
768
769 err = sk_storage_delete(sk, map);
770 sock_put(sk);
771 return err;
772 }
773
774 return -ENOENT;
775}
776
777const struct bpf_map_ops sk_storage_map_ops = {
778 .map_alloc_check = bpf_sk_storage_map_alloc_check,
779 .map_alloc = bpf_sk_storage_map_alloc,
780 .map_free = bpf_sk_storage_map_free,
781 .map_get_next_key = notsupp_get_next_key,
782 .map_lookup_elem = bpf_fd_sk_storage_lookup_elem,
783 .map_update_elem = bpf_fd_sk_storage_update_elem,
784 .map_delete_elem = bpf_fd_sk_storage_delete_elem,
785 .map_check_btf = bpf_sk_storage_map_check_btf,
786};
787
788const struct bpf_func_proto bpf_sk_storage_get_proto = {
789 .func = bpf_sk_storage_get,
790 .gpl_only = false,
791 .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL,
792 .arg1_type = ARG_CONST_MAP_PTR,
793 .arg2_type = ARG_PTR_TO_SOCKET,
794 .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL,
795 .arg4_type = ARG_ANYTHING,
796};
797
798const struct bpf_func_proto bpf_sk_storage_delete_proto = {
799 .func = bpf_sk_storage_delete,
800 .gpl_only = false,
801 .ret_type = RET_INTEGER,
802 .arg1_type = ARG_CONST_MAP_PTR,
803 .arg2_type = ARG_PTR_TO_SOCKET,
804};
diff --git a/net/core/datagram.c b/net/core/datagram.c
index e657289db4ac..45a162ef5e02 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -61,6 +61,8 @@
61#include <trace/events/skb.h> 61#include <trace/events/skb.h>
62#include <net/busy_poll.h> 62#include <net/busy_poll.h>
63 63
64#include "datagram.h"
65
64/* 66/*
65 * Is a socket 'connection oriented' ? 67 * Is a socket 'connection oriented' ?
66 */ 68 */
@@ -165,7 +167,7 @@ struct sk_buff *__skb_try_recv_from_queue(struct sock *sk,
165 unsigned int flags, 167 unsigned int flags,
166 void (*destructor)(struct sock *sk, 168 void (*destructor)(struct sock *sk,
167 struct sk_buff *skb), 169 struct sk_buff *skb),
168 int *peeked, int *off, int *err, 170 int *off, int *err,
169 struct sk_buff **last) 171 struct sk_buff **last)
170{ 172{
171 bool peek_at_off = false; 173 bool peek_at_off = false;
@@ -192,7 +194,6 @@ struct sk_buff *__skb_try_recv_from_queue(struct sock *sk,
192 return NULL; 194 return NULL;
193 } 195 }
194 } 196 }
195 *peeked = 1;
196 refcount_inc(&skb->users); 197 refcount_inc(&skb->users);
197 } else { 198 } else {
198 __skb_unlink(skb, queue); 199 __skb_unlink(skb, queue);
@@ -210,7 +211,6 @@ struct sk_buff *__skb_try_recv_from_queue(struct sock *sk,
210 * @sk: socket 211 * @sk: socket
211 * @flags: MSG\_ flags 212 * @flags: MSG\_ flags
212 * @destructor: invoked under the receive lock on successful dequeue 213 * @destructor: invoked under the receive lock on successful dequeue
213 * @peeked: returns non-zero if this packet has been seen before
214 * @off: an offset in bytes to peek skb from. Returns an offset 214 * @off: an offset in bytes to peek skb from. Returns an offset
215 * within an skb where data actually starts 215 * within an skb where data actually starts
216 * @err: error code returned 216 * @err: error code returned
@@ -244,7 +244,7 @@ struct sk_buff *__skb_try_recv_from_queue(struct sock *sk,
244struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags, 244struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags,
245 void (*destructor)(struct sock *sk, 245 void (*destructor)(struct sock *sk,
246 struct sk_buff *skb), 246 struct sk_buff *skb),
247 int *peeked, int *off, int *err, 247 int *off, int *err,
248 struct sk_buff **last) 248 struct sk_buff **last)
249{ 249{
250 struct sk_buff_head *queue = &sk->sk_receive_queue; 250 struct sk_buff_head *queue = &sk->sk_receive_queue;
@@ -258,7 +258,6 @@ struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags,
258 if (error) 258 if (error)
259 goto no_packet; 259 goto no_packet;
260 260
261 *peeked = 0;
262 do { 261 do {
263 /* Again only user level code calls this function, so nothing 262 /* Again only user level code calls this function, so nothing
264 * interrupt level will suddenly eat the receive_queue. 263 * interrupt level will suddenly eat the receive_queue.
@@ -268,7 +267,7 @@ struct sk_buff *__skb_try_recv_datagram(struct sock *sk, unsigned int flags,
268 */ 267 */
269 spin_lock_irqsave(&queue->lock, cpu_flags); 268 spin_lock_irqsave(&queue->lock, cpu_flags);
270 skb = __skb_try_recv_from_queue(sk, queue, flags, destructor, 269 skb = __skb_try_recv_from_queue(sk, queue, flags, destructor,
271 peeked, off, &error, last); 270 off, &error, last);
272 spin_unlock_irqrestore(&queue->lock, cpu_flags); 271 spin_unlock_irqrestore(&queue->lock, cpu_flags);
273 if (error) 272 if (error)
274 goto no_packet; 273 goto no_packet;
@@ -292,7 +291,7 @@ EXPORT_SYMBOL(__skb_try_recv_datagram);
292struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned int flags, 291struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned int flags,
293 void (*destructor)(struct sock *sk, 292 void (*destructor)(struct sock *sk,
294 struct sk_buff *skb), 293 struct sk_buff *skb),
295 int *peeked, int *off, int *err) 294 int *off, int *err)
296{ 295{
297 struct sk_buff *skb, *last; 296 struct sk_buff *skb, *last;
298 long timeo; 297 long timeo;
@@ -300,8 +299,8 @@ struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned int flags,
300 timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); 299 timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
301 300
302 do { 301 do {
303 skb = __skb_try_recv_datagram(sk, flags, destructor, peeked, 302 skb = __skb_try_recv_datagram(sk, flags, destructor, off, err,
304 off, err, &last); 303 &last);
305 if (skb) 304 if (skb)
306 return skb; 305 return skb;
307 306
@@ -317,10 +316,10 @@ EXPORT_SYMBOL(__skb_recv_datagram);
317struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned int flags, 316struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned int flags,
318 int noblock, int *err) 317 int noblock, int *err)
319{ 318{
320 int peeked, off = 0; 319 int off = 0;
321 320
322 return __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0), 321 return __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
323 NULL, &peeked, &off, err); 322 NULL, &off, err);
324} 323}
325EXPORT_SYMBOL(skb_recv_datagram); 324EXPORT_SYMBOL(skb_recv_datagram);
326 325
@@ -408,10 +407,10 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
408} 407}
409EXPORT_SYMBOL(skb_kill_datagram); 408EXPORT_SYMBOL(skb_kill_datagram);
410 409
411int __skb_datagram_iter(const struct sk_buff *skb, int offset, 410static int __skb_datagram_iter(const struct sk_buff *skb, int offset,
412 struct iov_iter *to, int len, bool fault_short, 411 struct iov_iter *to, int len, bool fault_short,
413 size_t (*cb)(const void *, size_t, void *, struct iov_iter *), 412 size_t (*cb)(const void *, size_t, void *,
414 void *data) 413 struct iov_iter *), void *data)
415{ 414{
416 int start = skb_headlen(skb); 415 int start = skb_headlen(skb);
417 int i, copy = start - offset, start_off = offset, n; 416 int i, copy = start - offset, start_off = offset, n;
diff --git a/net/core/datagram.h b/net/core/datagram.h
new file mode 100644
index 000000000000..bcfb75bfa3b2
--- /dev/null
+++ b/net/core/datagram.h
@@ -0,0 +1,15 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef _NET_CORE_DATAGRAM_H_
4#define _NET_CORE_DATAGRAM_H_
5
6#include <linux/types.h>
7
8struct sock;
9struct sk_buff;
10struct iov_iter;
11
12int __zerocopy_sg_from_iter(struct sock *sk, struct sk_buff *skb,
13 struct iov_iter *from, size_t length);
14
15#endif /* _NET_CORE_DATAGRAM_H_ */
diff --git a/net/core/dev.c b/net/core/dev.c
index fdcff29df915..108ac8137b9b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -131,7 +131,6 @@
131#include <trace/events/napi.h> 131#include <trace/events/napi.h>
132#include <trace/events/net.h> 132#include <trace/events/net.h>
133#include <trace/events/skb.h> 133#include <trace/events/skb.h>
134#include <linux/pci.h>
135#include <linux/inetdevice.h> 134#include <linux/inetdevice.h>
136#include <linux/cpu_rmap.h> 135#include <linux/cpu_rmap.h>
137#include <linux/static_key.h> 136#include <linux/static_key.h>
@@ -146,6 +145,7 @@
146#include <net/udp_tunnel.h> 145#include <net/udp_tunnel.h>
147#include <linux/net_namespace.h> 146#include <linux/net_namespace.h>
148#include <linux/indirect_call_wrapper.h> 147#include <linux/indirect_call_wrapper.h>
148#include <net/devlink.h>
149 149
150#include "net-sysfs.h" 150#include "net-sysfs.h"
151 151
@@ -1184,7 +1184,21 @@ int dev_change_name(struct net_device *dev, const char *newname)
1184 BUG_ON(!dev_net(dev)); 1184 BUG_ON(!dev_net(dev));
1185 1185
1186 net = dev_net(dev); 1186 net = dev_net(dev);
1187 if (dev->flags & IFF_UP) 1187
1188 /* Some auto-enslaved devices e.g. failover slaves are
1189 * special, as userspace might rename the device after
1190 * the interface had been brought up and running since
1191 * the point kernel initiated auto-enslavement. Allow
1192 * live name change even when these slave devices are
1193 * up and running.
1194 *
1195 * Typically, users of these auto-enslaving devices
1196 * don't actually care about slave name change, as
1197 * they are supposed to operate on master interface
1198 * directly.
1199 */
1200 if (dev->flags & IFF_UP &&
1201 likely(!(dev->priv_flags & IFF_LIVE_RENAME_OK)))
1188 return -EBUSY; 1202 return -EBUSY;
1189 1203
1190 write_seqcount_begin(&devnet_rename_seq); 1204 write_seqcount_begin(&devnet_rename_seq);
@@ -3468,6 +3482,15 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
3468 if (unlikely(test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) { 3482 if (unlikely(test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) {
3469 __qdisc_drop(skb, &to_free); 3483 __qdisc_drop(skb, &to_free);
3470 rc = NET_XMIT_DROP; 3484 rc = NET_XMIT_DROP;
3485 } else if ((q->flags & TCQ_F_CAN_BYPASS) && q->empty &&
3486 qdisc_run_begin(q)) {
3487 qdisc_bstats_cpu_update(q, skb);
3488
3489 if (sch_direct_xmit(skb, q, dev, txq, NULL, true))
3490 __qdisc_run(q);
3491
3492 qdisc_run_end(q);
3493 rc = NET_XMIT_SUCCESS;
3471 } else { 3494 } else {
3472 rc = q->enqueue(skb, q, &to_free) & NET_XMIT_MASK; 3495 rc = q->enqueue(skb, q, &to_free) & NET_XMIT_MASK;
3473 qdisc_run(q); 3496 qdisc_run(q);
@@ -3556,9 +3579,6 @@ static void skb_update_prio(struct sk_buff *skb)
3556#define skb_update_prio(skb) 3579#define skb_update_prio(skb)
3557#endif 3580#endif
3558 3581
3559DEFINE_PER_CPU(int, xmit_recursion);
3560EXPORT_SYMBOL(xmit_recursion);
3561
3562/** 3582/**
3563 * dev_loopback_xmit - loop back @skb 3583 * dev_loopback_xmit - loop back @skb
3564 * @net: network namespace this loopback is happening in 3584 * @net: network namespace this loopback is happening in
@@ -3689,23 +3709,21 @@ get_cpus_map:
3689} 3709}
3690 3710
3691u16 dev_pick_tx_zero(struct net_device *dev, struct sk_buff *skb, 3711u16 dev_pick_tx_zero(struct net_device *dev, struct sk_buff *skb,
3692 struct net_device *sb_dev, 3712 struct net_device *sb_dev)
3693 select_queue_fallback_t fallback)
3694{ 3713{
3695 return 0; 3714 return 0;
3696} 3715}
3697EXPORT_SYMBOL(dev_pick_tx_zero); 3716EXPORT_SYMBOL(dev_pick_tx_zero);
3698 3717
3699u16 dev_pick_tx_cpu_id(struct net_device *dev, struct sk_buff *skb, 3718u16 dev_pick_tx_cpu_id(struct net_device *dev, struct sk_buff *skb,
3700 struct net_device *sb_dev, 3719 struct net_device *sb_dev)
3701 select_queue_fallback_t fallback)
3702{ 3720{
3703 return (u16)raw_smp_processor_id() % dev->real_num_tx_queues; 3721 return (u16)raw_smp_processor_id() % dev->real_num_tx_queues;
3704} 3722}
3705EXPORT_SYMBOL(dev_pick_tx_cpu_id); 3723EXPORT_SYMBOL(dev_pick_tx_cpu_id);
3706 3724
3707static u16 __netdev_pick_tx(struct net_device *dev, struct sk_buff *skb, 3725u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
3708 struct net_device *sb_dev) 3726 struct net_device *sb_dev)
3709{ 3727{
3710 struct sock *sk = skb->sk; 3728 struct sock *sk = skb->sk;
3711 int queue_index = sk_tx_queue_get(sk); 3729 int queue_index = sk_tx_queue_get(sk);
@@ -3729,10 +3747,11 @@ static u16 __netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
3729 3747
3730 return queue_index; 3748 return queue_index;
3731} 3749}
3750EXPORT_SYMBOL(netdev_pick_tx);
3732 3751
3733struct netdev_queue *netdev_pick_tx(struct net_device *dev, 3752struct netdev_queue *netdev_core_pick_tx(struct net_device *dev,
3734 struct sk_buff *skb, 3753 struct sk_buff *skb,
3735 struct net_device *sb_dev) 3754 struct net_device *sb_dev)
3736{ 3755{
3737 int queue_index = 0; 3756 int queue_index = 0;
3738 3757
@@ -3747,10 +3766,9 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev,
3747 const struct net_device_ops *ops = dev->netdev_ops; 3766 const struct net_device_ops *ops = dev->netdev_ops;
3748 3767
3749 if (ops->ndo_select_queue) 3768 if (ops->ndo_select_queue)
3750 queue_index = ops->ndo_select_queue(dev, skb, sb_dev, 3769 queue_index = ops->ndo_select_queue(dev, skb, sb_dev);
3751 __netdev_pick_tx);
3752 else 3770 else
3753 queue_index = __netdev_pick_tx(dev, skb, sb_dev); 3771 queue_index = netdev_pick_tx(dev, skb, sb_dev);
3754 3772
3755 queue_index = netdev_cap_txqueue(dev, queue_index); 3773 queue_index = netdev_cap_txqueue(dev, queue_index);
3756 } 3774 }
@@ -3824,7 +3842,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
3824 else 3842 else
3825 skb_dst_force(skb); 3843 skb_dst_force(skb);
3826 3844
3827 txq = netdev_pick_tx(dev, skb, sb_dev); 3845 txq = netdev_core_pick_tx(dev, skb, sb_dev);
3828 q = rcu_dereference_bh(txq->qdisc); 3846 q = rcu_dereference_bh(txq->qdisc);
3829 3847
3830 trace_net_dev_queue(skb); 3848 trace_net_dev_queue(skb);
@@ -3849,8 +3867,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
3849 int cpu = smp_processor_id(); /* ok because BHs are off */ 3867 int cpu = smp_processor_id(); /* ok because BHs are off */
3850 3868
3851 if (txq->xmit_lock_owner != cpu) { 3869 if (txq->xmit_lock_owner != cpu) {
3852 if (unlikely(__this_cpu_read(xmit_recursion) > 3870 if (dev_xmit_recursion())
3853 XMIT_RECURSION_LIMIT))
3854 goto recursion_alert; 3871 goto recursion_alert;
3855 3872
3856 skb = validate_xmit_skb(skb, dev, &again); 3873 skb = validate_xmit_skb(skb, dev, &again);
@@ -3860,9 +3877,9 @@ static int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
3860 HARD_TX_LOCK(dev, txq, cpu); 3877 HARD_TX_LOCK(dev, txq, cpu);
3861 3878
3862 if (!netif_xmit_stopped(txq)) { 3879 if (!netif_xmit_stopped(txq)) {
3863 __this_cpu_inc(xmit_recursion); 3880 dev_xmit_recursion_inc();
3864 skb = dev_hard_start_xmit(skb, dev, txq, &rc); 3881 skb = dev_hard_start_xmit(skb, dev, txq, &rc);
3865 __this_cpu_dec(xmit_recursion); 3882 dev_xmit_recursion_dec();
3866 if (dev_xmit_complete(rc)) { 3883 if (dev_xmit_complete(rc)) {
3867 HARD_TX_UNLOCK(dev, txq); 3884 HARD_TX_UNLOCK(dev, txq);
3868 goto out; 3885 goto out;
@@ -3975,9 +3992,9 @@ EXPORT_SYMBOL(rps_sock_flow_table);
3975u32 rps_cpu_mask __read_mostly; 3992u32 rps_cpu_mask __read_mostly;
3976EXPORT_SYMBOL(rps_cpu_mask); 3993EXPORT_SYMBOL(rps_cpu_mask);
3977 3994
3978struct static_key rps_needed __read_mostly; 3995struct static_key_false rps_needed __read_mostly;
3979EXPORT_SYMBOL(rps_needed); 3996EXPORT_SYMBOL(rps_needed);
3980struct static_key rfs_needed __read_mostly; 3997struct static_key_false rfs_needed __read_mostly;
3981EXPORT_SYMBOL(rfs_needed); 3998EXPORT_SYMBOL(rfs_needed);
3982 3999
3983static struct rps_dev_flow * 4000static struct rps_dev_flow *
@@ -4429,7 +4446,7 @@ void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog)
4429 bool free_skb = true; 4446 bool free_skb = true;
4430 int cpu, rc; 4447 int cpu, rc;
4431 4448
4432 txq = netdev_pick_tx(dev, skb, NULL); 4449 txq = netdev_core_pick_tx(dev, skb, NULL);
4433 cpu = smp_processor_id(); 4450 cpu = smp_processor_id();
4434 HARD_TX_LOCK(dev, txq, cpu); 4451 HARD_TX_LOCK(dev, txq, cpu);
4435 if (!netif_xmit_stopped(txq)) { 4452 if (!netif_xmit_stopped(txq)) {
@@ -4503,7 +4520,7 @@ static int netif_rx_internal(struct sk_buff *skb)
4503 } 4520 }
4504 4521
4505#ifdef CONFIG_RPS 4522#ifdef CONFIG_RPS
4506 if (static_key_false(&rps_needed)) { 4523 if (static_branch_unlikely(&rps_needed)) {
4507 struct rps_dev_flow voidflow, *rflow = &voidflow; 4524 struct rps_dev_flow voidflow, *rflow = &voidflow;
4508 int cpu; 4525 int cpu;
4509 4526
@@ -4970,7 +4987,8 @@ static int __netif_receive_skb_one_core(struct sk_buff *skb, bool pfmemalloc)
4970 4987
4971 ret = __netif_receive_skb_core(skb, pfmemalloc, &pt_prev); 4988 ret = __netif_receive_skb_core(skb, pfmemalloc, &pt_prev);
4972 if (pt_prev) 4989 if (pt_prev)
4973 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev); 4990 ret = INDIRECT_CALL_INET(pt_prev->func, ipv6_rcv, ip_rcv, skb,
4991 skb->dev, pt_prev, orig_dev);
4974 return ret; 4992 return ret;
4975} 4993}
4976 4994
@@ -5016,7 +5034,8 @@ static inline void __netif_receive_skb_list_ptype(struct list_head *head,
5016 else 5034 else
5017 list_for_each_entry_safe(skb, next, head, list) { 5035 list_for_each_entry_safe(skb, next, head, list) {
5018 skb_list_del_init(skb); 5036 skb_list_del_init(skb);
5019 pt_prev->func(skb, skb->dev, pt_prev, orig_dev); 5037 INDIRECT_CALL_INET(pt_prev->func, ipv6_rcv, ip_rcv, skb,
5038 skb->dev, pt_prev, orig_dev);
5020 } 5039 }
5021} 5040}
5022 5041
@@ -5174,7 +5193,7 @@ static int netif_receive_skb_internal(struct sk_buff *skb)
5174 5193
5175 rcu_read_lock(); 5194 rcu_read_lock();
5176#ifdef CONFIG_RPS 5195#ifdef CONFIG_RPS
5177 if (static_key_false(&rps_needed)) { 5196 if (static_branch_unlikely(&rps_needed)) {
5178 struct rps_dev_flow voidflow, *rflow = &voidflow; 5197 struct rps_dev_flow voidflow, *rflow = &voidflow;
5179 int cpu = get_rps_cpu(skb->dev, skb, &rflow); 5198 int cpu = get_rps_cpu(skb->dev, skb, &rflow);
5180 5199
@@ -5222,7 +5241,7 @@ static void netif_receive_skb_list_internal(struct list_head *head)
5222 5241
5223 rcu_read_lock(); 5242 rcu_read_lock();
5224#ifdef CONFIG_RPS 5243#ifdef CONFIG_RPS
5225 if (static_key_false(&rps_needed)) { 5244 if (static_branch_unlikely(&rps_needed)) {
5226 list_for_each_entry_safe(skb, next, head, list) { 5245 list_for_each_entry_safe(skb, next, head, list) {
5227 struct rps_dev_flow voidflow, *rflow = &voidflow; 5246 struct rps_dev_flow voidflow, *rflow = &voidflow;
5228 int cpu = get_rps_cpu(skb->dev, skb, &rflow); 5247 int cpu = get_rps_cpu(skb->dev, skb, &rflow);
@@ -7872,10 +7891,14 @@ int dev_get_phys_port_name(struct net_device *dev,
7872 char *name, size_t len) 7891 char *name, size_t len)
7873{ 7892{
7874 const struct net_device_ops *ops = dev->netdev_ops; 7893 const struct net_device_ops *ops = dev->netdev_ops;
7894 int err;
7875 7895
7876 if (!ops->ndo_get_phys_port_name) 7896 if (ops->ndo_get_phys_port_name) {
7877 return -EOPNOTSUPP; 7897 err = ops->ndo_get_phys_port_name(dev, name, len);
7878 return ops->ndo_get_phys_port_name(dev, name, len); 7898 if (err != -EOPNOTSUPP)
7899 return err;
7900 }
7901 return devlink_compat_phys_port_name_get(dev, name, len);
7879} 7902}
7880EXPORT_SYMBOL(dev_get_phys_port_name); 7903EXPORT_SYMBOL(dev_get_phys_port_name);
7881 7904
@@ -7895,14 +7918,21 @@ int dev_get_port_parent_id(struct net_device *dev,
7895 struct netdev_phys_item_id first = { }; 7918 struct netdev_phys_item_id first = { };
7896 struct net_device *lower_dev; 7919 struct net_device *lower_dev;
7897 struct list_head *iter; 7920 struct list_head *iter;
7898 int err = -EOPNOTSUPP; 7921 int err;
7899 7922
7900 if (ops->ndo_get_port_parent_id) 7923 if (ops->ndo_get_port_parent_id) {
7901 return ops->ndo_get_port_parent_id(dev, ppid); 7924 err = ops->ndo_get_port_parent_id(dev, ppid);
7925 if (err != -EOPNOTSUPP)
7926 return err;
7927 }
7902 7928
7903 if (!recurse) 7929 err = devlink_compat_switch_id_get(dev, ppid);
7930 if (!err || err != -EOPNOTSUPP)
7904 return err; 7931 return err;
7905 7932
7933 if (!recurse)
7934 return -EOPNOTSUPP;
7935
7906 netdev_for_each_lower_dev(dev, lower_dev, iter) { 7936 netdev_for_each_lower_dev(dev, lower_dev, iter) {
7907 err = dev_get_port_parent_id(lower_dev, ppid, recurse); 7937 err = dev_get_port_parent_id(lower_dev, ppid, recurse);
7908 if (err) 7938 if (err)
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 31380fd5a4e2..5163d900bb4f 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -366,7 +366,8 @@ EXPORT_SYMBOL(dev_load);
366 * dev_ioctl - network device ioctl 366 * dev_ioctl - network device ioctl
367 * @net: the applicable net namespace 367 * @net: the applicable net namespace
368 * @cmd: command to issue 368 * @cmd: command to issue
369 * @arg: pointer to a struct ifreq in user space 369 * @ifr: pointer to a struct ifreq in user space
370 * @need_copyout: whether or not copy_to_user() should be called
370 * 371 *
371 * Issue ioctl functions to devices. This is normally called by the 372 * Issue ioctl functions to devices. This is normally called by the
372 * user space syscall interfaces but can sometimes be useful for 373 * user space syscall interfaces but can sometimes be useful for
diff --git a/net/core/devlink.c b/net/core/devlink.c
index da0a29f30885..d43bc52b8840 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -19,6 +19,8 @@
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/list.h> 20#include <linux/list.h>
21#include <linux/netdevice.h> 21#include <linux/netdevice.h>
22#include <linux/spinlock.h>
23#include <linux/refcount.h>
22#include <rdma/ib_verbs.h> 24#include <rdma/ib_verbs.h>
23#include <net/netlink.h> 25#include <net/netlink.h>
24#include <net/genetlink.h> 26#include <net/genetlink.h>
@@ -543,12 +545,14 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
543 goto nla_put_failure; 545 goto nla_put_failure;
544 if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, devlink_port->index)) 546 if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, devlink_port->index))
545 goto nla_put_failure; 547 goto nla_put_failure;
548
549 spin_lock(&devlink_port->type_lock);
546 if (nla_put_u16(msg, DEVLINK_ATTR_PORT_TYPE, devlink_port->type)) 550 if (nla_put_u16(msg, DEVLINK_ATTR_PORT_TYPE, devlink_port->type))
547 goto nla_put_failure; 551 goto nla_put_failure_type_locked;
548 if (devlink_port->desired_type != DEVLINK_PORT_TYPE_NOTSET && 552 if (devlink_port->desired_type != DEVLINK_PORT_TYPE_NOTSET &&
549 nla_put_u16(msg, DEVLINK_ATTR_PORT_DESIRED_TYPE, 553 nla_put_u16(msg, DEVLINK_ATTR_PORT_DESIRED_TYPE,
550 devlink_port->desired_type)) 554 devlink_port->desired_type))
551 goto nla_put_failure; 555 goto nla_put_failure_type_locked;
552 if (devlink_port->type == DEVLINK_PORT_TYPE_ETH) { 556 if (devlink_port->type == DEVLINK_PORT_TYPE_ETH) {
553 struct net_device *netdev = devlink_port->type_dev; 557 struct net_device *netdev = devlink_port->type_dev;
554 558
@@ -557,7 +561,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
557 netdev->ifindex) || 561 netdev->ifindex) ||
558 nla_put_string(msg, DEVLINK_ATTR_PORT_NETDEV_NAME, 562 nla_put_string(msg, DEVLINK_ATTR_PORT_NETDEV_NAME,
559 netdev->name))) 563 netdev->name)))
560 goto nla_put_failure; 564 goto nla_put_failure_type_locked;
561 } 565 }
562 if (devlink_port->type == DEVLINK_PORT_TYPE_IB) { 566 if (devlink_port->type == DEVLINK_PORT_TYPE_IB) {
563 struct ib_device *ibdev = devlink_port->type_dev; 567 struct ib_device *ibdev = devlink_port->type_dev;
@@ -565,14 +569,17 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
565 if (ibdev && 569 if (ibdev &&
566 nla_put_string(msg, DEVLINK_ATTR_PORT_IBDEV_NAME, 570 nla_put_string(msg, DEVLINK_ATTR_PORT_IBDEV_NAME,
567 ibdev->name)) 571 ibdev->name))
568 goto nla_put_failure; 572 goto nla_put_failure_type_locked;
569 } 573 }
574 spin_unlock(&devlink_port->type_lock);
570 if (devlink_nl_port_attrs_put(msg, devlink_port)) 575 if (devlink_nl_port_attrs_put(msg, devlink_port))
571 goto nla_put_failure; 576 goto nla_put_failure;
572 577
573 genlmsg_end(msg, hdr); 578 genlmsg_end(msg, hdr);
574 return 0; 579 return 0;
575 580
581nla_put_failure_type_locked:
582 spin_unlock(&devlink_port->type_lock);
576nla_put_failure: 583nla_put_failure:
577 genlmsg_cancel(msg, hdr); 584 genlmsg_cancel(msg, hdr);
578 return -EMSGSIZE; 585 return -EMSGSIZE;
@@ -1041,14 +1048,15 @@ out:
1041 1048
1042static int devlink_sb_pool_set(struct devlink *devlink, unsigned int sb_index, 1049static int devlink_sb_pool_set(struct devlink *devlink, unsigned int sb_index,
1043 u16 pool_index, u32 size, 1050 u16 pool_index, u32 size,
1044 enum devlink_sb_threshold_type threshold_type) 1051 enum devlink_sb_threshold_type threshold_type,
1052 struct netlink_ext_ack *extack)
1045 1053
1046{ 1054{
1047 const struct devlink_ops *ops = devlink->ops; 1055 const struct devlink_ops *ops = devlink->ops;
1048 1056
1049 if (ops->sb_pool_set) 1057 if (ops->sb_pool_set)
1050 return ops->sb_pool_set(devlink, sb_index, pool_index, 1058 return ops->sb_pool_set(devlink, sb_index, pool_index,
1051 size, threshold_type); 1059 size, threshold_type, extack);
1052 return -EOPNOTSUPP; 1060 return -EOPNOTSUPP;
1053} 1061}
1054 1062
@@ -1076,7 +1084,8 @@ static int devlink_nl_cmd_sb_pool_set_doit(struct sk_buff *skb,
1076 1084
1077 size = nla_get_u32(info->attrs[DEVLINK_ATTR_SB_POOL_SIZE]); 1085 size = nla_get_u32(info->attrs[DEVLINK_ATTR_SB_POOL_SIZE]);
1078 return devlink_sb_pool_set(devlink, devlink_sb->index, 1086 return devlink_sb_pool_set(devlink, devlink_sb->index,
1079 pool_index, size, threshold_type); 1087 pool_index, size, threshold_type,
1088 info->extack);
1080} 1089}
1081 1090
1082static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg, 1091static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg,
@@ -1237,14 +1246,15 @@ out:
1237 1246
1238static int devlink_sb_port_pool_set(struct devlink_port *devlink_port, 1247static int devlink_sb_port_pool_set(struct devlink_port *devlink_port,
1239 unsigned int sb_index, u16 pool_index, 1248 unsigned int sb_index, u16 pool_index,
1240 u32 threshold) 1249 u32 threshold,
1250 struct netlink_ext_ack *extack)
1241 1251
1242{ 1252{
1243 const struct devlink_ops *ops = devlink_port->devlink->ops; 1253 const struct devlink_ops *ops = devlink_port->devlink->ops;
1244 1254
1245 if (ops->sb_port_pool_set) 1255 if (ops->sb_port_pool_set)
1246 return ops->sb_port_pool_set(devlink_port, sb_index, 1256 return ops->sb_port_pool_set(devlink_port, sb_index,
1247 pool_index, threshold); 1257 pool_index, threshold, extack);
1248 return -EOPNOTSUPP; 1258 return -EOPNOTSUPP;
1249} 1259}
1250 1260
@@ -1267,7 +1277,7 @@ static int devlink_nl_cmd_sb_port_pool_set_doit(struct sk_buff *skb,
1267 1277
1268 threshold = nla_get_u32(info->attrs[DEVLINK_ATTR_SB_THRESHOLD]); 1278 threshold = nla_get_u32(info->attrs[DEVLINK_ATTR_SB_THRESHOLD]);
1269 return devlink_sb_port_pool_set(devlink_port, devlink_sb->index, 1279 return devlink_sb_port_pool_set(devlink_port, devlink_sb->index,
1270 pool_index, threshold); 1280 pool_index, threshold, info->extack);
1271} 1281}
1272 1282
1273static int 1283static int
@@ -1466,7 +1476,8 @@ out:
1466static int devlink_sb_tc_pool_bind_set(struct devlink_port *devlink_port, 1476static int devlink_sb_tc_pool_bind_set(struct devlink_port *devlink_port,
1467 unsigned int sb_index, u16 tc_index, 1477 unsigned int sb_index, u16 tc_index,
1468 enum devlink_sb_pool_type pool_type, 1478 enum devlink_sb_pool_type pool_type,
1469 u16 pool_index, u32 threshold) 1479 u16 pool_index, u32 threshold,
1480 struct netlink_ext_ack *extack)
1470 1481
1471{ 1482{
1472 const struct devlink_ops *ops = devlink_port->devlink->ops; 1483 const struct devlink_ops *ops = devlink_port->devlink->ops;
@@ -1474,7 +1485,7 @@ static int devlink_sb_tc_pool_bind_set(struct devlink_port *devlink_port,
1474 if (ops->sb_tc_pool_bind_set) 1485 if (ops->sb_tc_pool_bind_set)
1475 return ops->sb_tc_pool_bind_set(devlink_port, sb_index, 1486 return ops->sb_tc_pool_bind_set(devlink_port, sb_index,
1476 tc_index, pool_type, 1487 tc_index, pool_type,
1477 pool_index, threshold); 1488 pool_index, threshold, extack);
1478 return -EOPNOTSUPP; 1489 return -EOPNOTSUPP;
1479} 1490}
1480 1491
@@ -1509,7 +1520,7 @@ static int devlink_nl_cmd_sb_tc_pool_bind_set_doit(struct sk_buff *skb,
1509 threshold = nla_get_u32(info->attrs[DEVLINK_ATTR_SB_THRESHOLD]); 1520 threshold = nla_get_u32(info->attrs[DEVLINK_ATTR_SB_THRESHOLD]);
1510 return devlink_sb_tc_pool_bind_set(devlink_port, devlink_sb->index, 1521 return devlink_sb_tc_pool_bind_set(devlink_port, devlink_sb->index,
1511 tc_index, pool_type, 1522 tc_index, pool_type,
1512 pool_index, threshold); 1523 pool_index, threshold, info->extack);
1513} 1524}
1514 1525
1515static int devlink_nl_cmd_sb_occ_snapshot_doit(struct sk_buff *skb, 1526static int devlink_nl_cmd_sb_occ_snapshot_doit(struct sk_buff *skb,
@@ -1661,7 +1672,7 @@ int devlink_dpipe_match_put(struct sk_buff *skb,
1661 struct devlink_dpipe_field *field = &header->fields[match->field_id]; 1672 struct devlink_dpipe_field *field = &header->fields[match->field_id];
1662 struct nlattr *match_attr; 1673 struct nlattr *match_attr;
1663 1674
1664 match_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_MATCH); 1675 match_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_DPIPE_MATCH);
1665 if (!match_attr) 1676 if (!match_attr)
1666 return -EMSGSIZE; 1677 return -EMSGSIZE;
1667 1678
@@ -1686,7 +1697,8 @@ static int devlink_dpipe_matches_put(struct devlink_dpipe_table *table,
1686{ 1697{
1687 struct nlattr *matches_attr; 1698 struct nlattr *matches_attr;
1688 1699
1689 matches_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_TABLE_MATCHES); 1700 matches_attr = nla_nest_start_noflag(skb,
1701 DEVLINK_ATTR_DPIPE_TABLE_MATCHES);
1690 if (!matches_attr) 1702 if (!matches_attr)
1691 return -EMSGSIZE; 1703 return -EMSGSIZE;
1692 1704
@@ -1708,7 +1720,7 @@ int devlink_dpipe_action_put(struct sk_buff *skb,
1708 struct devlink_dpipe_field *field = &header->fields[action->field_id]; 1720 struct devlink_dpipe_field *field = &header->fields[action->field_id];
1709 struct nlattr *action_attr; 1721 struct nlattr *action_attr;
1710 1722
1711 action_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_ACTION); 1723 action_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_DPIPE_ACTION);
1712 if (!action_attr) 1724 if (!action_attr)
1713 return -EMSGSIZE; 1725 return -EMSGSIZE;
1714 1726
@@ -1733,7 +1745,8 @@ static int devlink_dpipe_actions_put(struct devlink_dpipe_table *table,
1733{ 1745{
1734 struct nlattr *actions_attr; 1746 struct nlattr *actions_attr;
1735 1747
1736 actions_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_TABLE_ACTIONS); 1748 actions_attr = nla_nest_start_noflag(skb,
1749 DEVLINK_ATTR_DPIPE_TABLE_ACTIONS);
1737 if (!actions_attr) 1750 if (!actions_attr)
1738 return -EMSGSIZE; 1751 return -EMSGSIZE;
1739 1752
@@ -1755,7 +1768,7 @@ static int devlink_dpipe_table_put(struct sk_buff *skb,
1755 u64 table_size; 1768 u64 table_size;
1756 1769
1757 table_size = table->table_ops->size_get(table->priv); 1770 table_size = table->table_ops->size_get(table->priv);
1758 table_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_TABLE); 1771 table_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_DPIPE_TABLE);
1759 if (!table_attr) 1772 if (!table_attr)
1760 return -EMSGSIZE; 1773 return -EMSGSIZE;
1761 1774
@@ -1835,7 +1848,7 @@ start_again:
1835 1848
1836 if (devlink_nl_put_handle(skb, devlink)) 1849 if (devlink_nl_put_handle(skb, devlink))
1837 goto nla_put_failure; 1850 goto nla_put_failure;
1838 tables_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_TABLES); 1851 tables_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_DPIPE_TABLES);
1839 if (!tables_attr) 1852 if (!tables_attr)
1840 goto nla_put_failure; 1853 goto nla_put_failure;
1841 1854
@@ -1936,8 +1949,8 @@ static int devlink_dpipe_action_values_put(struct sk_buff *skb,
1936 int err; 1949 int err;
1937 1950
1938 for (i = 0; i < values_count; i++) { 1951 for (i = 0; i < values_count; i++) {
1939 action_attr = nla_nest_start(skb, 1952 action_attr = nla_nest_start_noflag(skb,
1940 DEVLINK_ATTR_DPIPE_ACTION_VALUE); 1953 DEVLINK_ATTR_DPIPE_ACTION_VALUE);
1941 if (!action_attr) 1954 if (!action_attr)
1942 return -EMSGSIZE; 1955 return -EMSGSIZE;
1943 err = devlink_dpipe_action_value_put(skb, &values[i]); 1956 err = devlink_dpipe_action_value_put(skb, &values[i]);
@@ -1973,8 +1986,8 @@ static int devlink_dpipe_match_values_put(struct sk_buff *skb,
1973 int err; 1986 int err;
1974 1987
1975 for (i = 0; i < values_count; i++) { 1988 for (i = 0; i < values_count; i++) {
1976 match_attr = nla_nest_start(skb, 1989 match_attr = nla_nest_start_noflag(skb,
1977 DEVLINK_ATTR_DPIPE_MATCH_VALUE); 1990 DEVLINK_ATTR_DPIPE_MATCH_VALUE);
1978 if (!match_attr) 1991 if (!match_attr)
1979 return -EMSGSIZE; 1992 return -EMSGSIZE;
1980 err = devlink_dpipe_match_value_put(skb, &values[i]); 1993 err = devlink_dpipe_match_value_put(skb, &values[i]);
@@ -1995,7 +2008,7 @@ static int devlink_dpipe_entry_put(struct sk_buff *skb,
1995 struct nlattr *entry_attr, *matches_attr, *actions_attr; 2008 struct nlattr *entry_attr, *matches_attr, *actions_attr;
1996 int err; 2009 int err;
1997 2010
1998 entry_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_ENTRY); 2011 entry_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_DPIPE_ENTRY);
1999 if (!entry_attr) 2012 if (!entry_attr)
2000 return -EMSGSIZE; 2013 return -EMSGSIZE;
2001 2014
@@ -2007,8 +2020,8 @@ static int devlink_dpipe_entry_put(struct sk_buff *skb,
2007 entry->counter, DEVLINK_ATTR_PAD)) 2020 entry->counter, DEVLINK_ATTR_PAD))
2008 goto nla_put_failure; 2021 goto nla_put_failure;
2009 2022
2010 matches_attr = nla_nest_start(skb, 2023 matches_attr = nla_nest_start_noflag(skb,
2011 DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES); 2024 DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES);
2012 if (!matches_attr) 2025 if (!matches_attr)
2013 goto nla_put_failure; 2026 goto nla_put_failure;
2014 2027
@@ -2020,8 +2033,8 @@ static int devlink_dpipe_entry_put(struct sk_buff *skb,
2020 } 2033 }
2021 nla_nest_end(skb, matches_attr); 2034 nla_nest_end(skb, matches_attr);
2022 2035
2023 actions_attr = nla_nest_start(skb, 2036 actions_attr = nla_nest_start_noflag(skb,
2024 DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES); 2037 DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES);
2025 if (!actions_attr) 2038 if (!actions_attr)
2026 goto nla_put_failure; 2039 goto nla_put_failure;
2027 2040
@@ -2078,8 +2091,8 @@ int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
2078 devlink = dump_ctx->info->user_ptr[0]; 2091 devlink = dump_ctx->info->user_ptr[0];
2079 if (devlink_nl_put_handle(dump_ctx->skb, devlink)) 2092 if (devlink_nl_put_handle(dump_ctx->skb, devlink))
2080 goto nla_put_failure; 2093 goto nla_put_failure;
2081 dump_ctx->nest = nla_nest_start(dump_ctx->skb, 2094 dump_ctx->nest = nla_nest_start_noflag(dump_ctx->skb,
2082 DEVLINK_ATTR_DPIPE_ENTRIES); 2095 DEVLINK_ATTR_DPIPE_ENTRIES);
2083 if (!dump_ctx->nest) 2096 if (!dump_ctx->nest)
2084 goto nla_put_failure; 2097 goto nla_put_failure;
2085 return 0; 2098 return 0;
@@ -2189,7 +2202,8 @@ static int devlink_dpipe_fields_put(struct sk_buff *skb,
2189 2202
2190 for (i = 0; i < header->fields_count; i++) { 2203 for (i = 0; i < header->fields_count; i++) {
2191 field = &header->fields[i]; 2204 field = &header->fields[i];
2192 field_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_FIELD); 2205 field_attr = nla_nest_start_noflag(skb,
2206 DEVLINK_ATTR_DPIPE_FIELD);
2193 if (!field_attr) 2207 if (!field_attr)
2194 return -EMSGSIZE; 2208 return -EMSGSIZE;
2195 if (nla_put_string(skb, DEVLINK_ATTR_DPIPE_FIELD_NAME, field->name) || 2209 if (nla_put_string(skb, DEVLINK_ATTR_DPIPE_FIELD_NAME, field->name) ||
@@ -2212,7 +2226,7 @@ static int devlink_dpipe_header_put(struct sk_buff *skb,
2212 struct nlattr *fields_attr, *header_attr; 2226 struct nlattr *fields_attr, *header_attr;
2213 int err; 2227 int err;
2214 2228
2215 header_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_HEADER); 2229 header_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_DPIPE_HEADER);
2216 if (!header_attr) 2230 if (!header_attr)
2217 return -EMSGSIZE; 2231 return -EMSGSIZE;
2218 2232
@@ -2221,7 +2235,8 @@ static int devlink_dpipe_header_put(struct sk_buff *skb,
2221 nla_put_u8(skb, DEVLINK_ATTR_DPIPE_HEADER_GLOBAL, header->global)) 2235 nla_put_u8(skb, DEVLINK_ATTR_DPIPE_HEADER_GLOBAL, header->global))
2222 goto nla_put_failure; 2236 goto nla_put_failure;
2223 2237
2224 fields_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_HEADER_FIELDS); 2238 fields_attr = nla_nest_start_noflag(skb,
2239 DEVLINK_ATTR_DPIPE_HEADER_FIELDS);
2225 if (!fields_attr) 2240 if (!fields_attr)
2226 goto nla_put_failure; 2241 goto nla_put_failure;
2227 2242
@@ -2268,7 +2283,7 @@ start_again:
2268 2283
2269 if (devlink_nl_put_handle(skb, devlink)) 2284 if (devlink_nl_put_handle(skb, devlink))
2270 goto nla_put_failure; 2285 goto nla_put_failure;
2271 headers_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_HEADERS); 2286 headers_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_DPIPE_HEADERS);
2272 if (!headers_attr) 2287 if (!headers_attr)
2273 goto nla_put_failure; 2288 goto nla_put_failure;
2274 2289
@@ -2492,7 +2507,7 @@ static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
2492 struct nlattr *child_resource_attr; 2507 struct nlattr *child_resource_attr;
2493 struct nlattr *resource_attr; 2508 struct nlattr *resource_attr;
2494 2509
2495 resource_attr = nla_nest_start(skb, DEVLINK_ATTR_RESOURCE); 2510 resource_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_RESOURCE);
2496 if (!resource_attr) 2511 if (!resource_attr)
2497 return -EMSGSIZE; 2512 return -EMSGSIZE;
2498 2513
@@ -2516,7 +2531,8 @@ static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb,
2516 resource->size_valid)) 2531 resource->size_valid))
2517 goto nla_put_failure; 2532 goto nla_put_failure;
2518 2533
2519 child_resource_attr = nla_nest_start(skb, DEVLINK_ATTR_RESOURCE_LIST); 2534 child_resource_attr = nla_nest_start_noflag(skb,
2535 DEVLINK_ATTR_RESOURCE_LIST);
2520 if (!child_resource_attr) 2536 if (!child_resource_attr)
2521 goto nla_put_failure; 2537 goto nla_put_failure;
2522 2538
@@ -2567,7 +2583,8 @@ start_again:
2567 if (devlink_nl_put_handle(skb, devlink)) 2583 if (devlink_nl_put_handle(skb, devlink))
2568 goto nla_put_failure; 2584 goto nla_put_failure;
2569 2585
2570 resources_attr = nla_nest_start(skb, DEVLINK_ATTR_RESOURCE_LIST); 2586 resources_attr = nla_nest_start_noflag(skb,
2587 DEVLINK_ATTR_RESOURCE_LIST);
2571 if (!resources_attr) 2588 if (!resources_attr)
2572 goto nla_put_failure; 2589 goto nla_put_failure;
2573 2590
@@ -2821,7 +2838,8 @@ devlink_nl_param_value_fill_one(struct sk_buff *msg,
2821{ 2838{
2822 struct nlattr *param_value_attr; 2839 struct nlattr *param_value_attr;
2823 2840
2824 param_value_attr = nla_nest_start(msg, DEVLINK_ATTR_PARAM_VALUE); 2841 param_value_attr = nla_nest_start_noflag(msg,
2842 DEVLINK_ATTR_PARAM_VALUE);
2825 if (!param_value_attr) 2843 if (!param_value_attr)
2826 goto nla_put_failure; 2844 goto nla_put_failure;
2827 2845
@@ -2912,7 +2930,7 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
2912 if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, port_index)) 2930 if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, port_index))
2913 goto genlmsg_cancel; 2931 goto genlmsg_cancel;
2914 2932
2915 param_attr = nla_nest_start(msg, DEVLINK_ATTR_PARAM); 2933 param_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PARAM);
2916 if (!param_attr) 2934 if (!param_attr)
2917 goto genlmsg_cancel; 2935 goto genlmsg_cancel;
2918 if (nla_put_string(msg, DEVLINK_ATTR_PARAM_NAME, param->name)) 2936 if (nla_put_string(msg, DEVLINK_ATTR_PARAM_NAME, param->name))
@@ -2926,7 +2944,8 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
2926 if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, nla_type)) 2944 if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, nla_type))
2927 goto param_nest_cancel; 2945 goto param_nest_cancel;
2928 2946
2929 param_values_list = nla_nest_start(msg, DEVLINK_ATTR_PARAM_VALUES_LIST); 2947 param_values_list = nla_nest_start_noflag(msg,
2948 DEVLINK_ATTR_PARAM_VALUES_LIST);
2930 if (!param_values_list) 2949 if (!param_values_list)
2931 goto param_nest_cancel; 2950 goto param_nest_cancel;
2932 2951
@@ -3326,7 +3345,7 @@ static int devlink_nl_region_snapshot_id_put(struct sk_buff *msg,
3326 struct nlattr *snap_attr; 3345 struct nlattr *snap_attr;
3327 int err; 3346 int err;
3328 3347
3329 snap_attr = nla_nest_start(msg, DEVLINK_ATTR_REGION_SNAPSHOT); 3348 snap_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_REGION_SNAPSHOT);
3330 if (!snap_attr) 3349 if (!snap_attr)
3331 return -EINVAL; 3350 return -EINVAL;
3332 3351
@@ -3350,7 +3369,8 @@ static int devlink_nl_region_snapshots_id_put(struct sk_buff *msg,
3350 struct nlattr *snapshots_attr; 3369 struct nlattr *snapshots_attr;
3351 int err; 3370 int err;
3352 3371
3353 snapshots_attr = nla_nest_start(msg, DEVLINK_ATTR_REGION_SNAPSHOTS); 3372 snapshots_attr = nla_nest_start_noflag(msg,
3373 DEVLINK_ATTR_REGION_SNAPSHOTS);
3354 if (!snapshots_attr) 3374 if (!snapshots_attr)
3355 return -EINVAL; 3375 return -EINVAL;
3356 3376
@@ -3566,7 +3586,7 @@ static int devlink_nl_cmd_region_read_chunk_fill(struct sk_buff *msg,
3566 struct nlattr *chunk_attr; 3586 struct nlattr *chunk_attr;
3567 int err; 3587 int err;
3568 3588
3569 chunk_attr = nla_nest_start(msg, DEVLINK_ATTR_REGION_CHUNK); 3589 chunk_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_REGION_CHUNK);
3570 if (!chunk_attr) 3590 if (!chunk_attr)
3571 return -EINVAL; 3591 return -EINVAL;
3572 3592
@@ -3640,7 +3660,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
3640 struct netlink_callback *cb) 3660 struct netlink_callback *cb)
3641{ 3661{
3642 u64 ret_offset, start_offset, end_offset = 0; 3662 u64 ret_offset, start_offset, end_offset = 0;
3643 const struct genl_ops *ops = cb->data;
3644 struct devlink_region *region; 3663 struct devlink_region *region;
3645 struct nlattr *chunks_attr; 3664 struct nlattr *chunks_attr;
3646 const char *region_name; 3665 const char *region_name;
@@ -3656,8 +3675,10 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
3656 if (!attrs) 3675 if (!attrs)
3657 return -ENOMEM; 3676 return -ENOMEM;
3658 3677
3659 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + devlink_nl_family.hdrsize, 3678 err = nlmsg_parse_deprecated(cb->nlh,
3660 attrs, DEVLINK_ATTR_MAX, ops->policy, cb->extack); 3679 GENL_HDRLEN + devlink_nl_family.hdrsize,
3680 attrs, DEVLINK_ATTR_MAX,
3681 devlink_nl_family.policy, cb->extack);
3661 if (err) 3682 if (err)
3662 goto out_free; 3683 goto out_free;
3663 3684
@@ -3699,7 +3720,7 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
3699 if (err) 3720 if (err)
3700 goto nla_put_failure; 3721 goto nla_put_failure;
3701 3722
3702 chunks_attr = nla_nest_start(skb, DEVLINK_ATTR_REGION_CHUNKS); 3723 chunks_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_REGION_CHUNKS);
3703 if (!chunks_attr) { 3724 if (!chunks_attr) {
3704 err = -EMSGSIZE; 3725 err = -EMSGSIZE;
3705 goto nla_put_failure; 3726 goto nla_put_failure;
@@ -3775,7 +3796,7 @@ static int devlink_info_version_put(struct devlink_info_req *req, int attr,
3775 struct nlattr *nest; 3796 struct nlattr *nest;
3776 int err; 3797 int err;
3777 3798
3778 nest = nla_nest_start(req->msg, attr); 3799 nest = nla_nest_start_noflag(req->msg, attr);
3779 if (!nest) 3800 if (!nest)
3780 return -EMSGSIZE; 3801 return -EMSGSIZE;
3781 3802
@@ -4303,7 +4324,7 @@ devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
4303 int i = 0; 4324 int i = 0;
4304 int err; 4325 int err;
4305 4326
4306 fmsg_nlattr = nla_nest_start(skb, DEVLINK_ATTR_FMSG); 4327 fmsg_nlattr = nla_nest_start_noflag(skb, DEVLINK_ATTR_FMSG);
4307 if (!fmsg_nlattr) 4328 if (!fmsg_nlattr)
4308 return -EMSGSIZE; 4329 return -EMSGSIZE;
4309 4330
@@ -4412,6 +4433,7 @@ struct devlink_health_reporter {
4412 u64 error_count; 4433 u64 error_count;
4413 u64 recovery_count; 4434 u64 recovery_count;
4414 u64 last_recovery_ts; 4435 u64 last_recovery_ts;
4436 refcount_t refcount;
4415}; 4437};
4416 4438
4417void * 4439void *
@@ -4427,6 +4449,7 @@ devlink_health_reporter_find_by_name(struct devlink *devlink,
4427{ 4449{
4428 struct devlink_health_reporter *reporter; 4450 struct devlink_health_reporter *reporter;
4429 4451
4452 lockdep_assert_held(&devlink->reporters_lock);
4430 list_for_each_entry(reporter, &devlink->reporter_list, list) 4453 list_for_each_entry(reporter, &devlink->reporter_list, list)
4431 if (!strcmp(reporter->ops->name, reporter_name)) 4454 if (!strcmp(reporter->ops->name, reporter_name))
4432 return reporter; 4455 return reporter;
@@ -4450,7 +4473,7 @@ devlink_health_reporter_create(struct devlink *devlink,
4450{ 4473{
4451 struct devlink_health_reporter *reporter; 4474 struct devlink_health_reporter *reporter;
4452 4475
4453 mutex_lock(&devlink->lock); 4476 mutex_lock(&devlink->reporters_lock);
4454 if (devlink_health_reporter_find_by_name(devlink, ops->name)) { 4477 if (devlink_health_reporter_find_by_name(devlink, ops->name)) {
4455 reporter = ERR_PTR(-EEXIST); 4478 reporter = ERR_PTR(-EEXIST);
4456 goto unlock; 4479 goto unlock;
@@ -4474,9 +4497,10 @@ devlink_health_reporter_create(struct devlink *devlink,
4474 reporter->graceful_period = graceful_period; 4497 reporter->graceful_period = graceful_period;
4475 reporter->auto_recover = auto_recover; 4498 reporter->auto_recover = auto_recover;
4476 mutex_init(&reporter->dump_lock); 4499 mutex_init(&reporter->dump_lock);
4500 refcount_set(&reporter->refcount, 1);
4477 list_add_tail(&reporter->list, &devlink->reporter_list); 4501 list_add_tail(&reporter->list, &devlink->reporter_list);
4478unlock: 4502unlock:
4479 mutex_unlock(&devlink->lock); 4503 mutex_unlock(&devlink->reporters_lock);
4480 return reporter; 4504 return reporter;
4481} 4505}
4482EXPORT_SYMBOL_GPL(devlink_health_reporter_create); 4506EXPORT_SYMBOL_GPL(devlink_health_reporter_create);
@@ -4489,9 +4513,12 @@ EXPORT_SYMBOL_GPL(devlink_health_reporter_create);
4489void 4513void
4490devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) 4514devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
4491{ 4515{
4492 mutex_lock(&reporter->devlink->lock); 4516 mutex_lock(&reporter->devlink->reporters_lock);
4493 list_del(&reporter->list); 4517 list_del(&reporter->list);
4494 mutex_unlock(&reporter->devlink->lock); 4518 mutex_unlock(&reporter->devlink->reporters_lock);
4519 while (refcount_read(&reporter->refcount) > 1)
4520 msleep(100);
4521 mutex_destroy(&reporter->dump_lock);
4495 if (reporter->dump_fmsg) 4522 if (reporter->dump_fmsg)
4496 devlink_fmsg_free(reporter->dump_fmsg); 4523 devlink_fmsg_free(reporter->dump_fmsg);
4497 kfree(reporter); 4524 kfree(reporter);
@@ -4627,6 +4654,7 @@ static struct devlink_health_reporter *
4627devlink_health_reporter_get_from_info(struct devlink *devlink, 4654devlink_health_reporter_get_from_info(struct devlink *devlink,
4628 struct genl_info *info) 4655 struct genl_info *info)
4629{ 4656{
4657 struct devlink_health_reporter *reporter;
4630 char *reporter_name; 4658 char *reporter_name;
4631 4659
4632 if (!info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]) 4660 if (!info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME])
@@ -4634,7 +4662,18 @@ devlink_health_reporter_get_from_info(struct devlink *devlink,
4634 4662
4635 reporter_name = 4663 reporter_name =
4636 nla_data(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]); 4664 nla_data(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]);
4637 return devlink_health_reporter_find_by_name(devlink, reporter_name); 4665 mutex_lock(&devlink->reporters_lock);
4666 reporter = devlink_health_reporter_find_by_name(devlink, reporter_name);
4667 if (reporter)
4668 refcount_inc(&reporter->refcount);
4669 mutex_unlock(&devlink->reporters_lock);
4670 return reporter;
4671}
4672
4673static void
4674devlink_health_reporter_put(struct devlink_health_reporter *reporter)
4675{
4676 refcount_dec(&reporter->refcount);
4638} 4677}
4639 4678
4640static int 4679static int
@@ -4654,7 +4693,8 @@ devlink_nl_health_reporter_fill(struct sk_buff *msg,
4654 if (devlink_nl_put_handle(msg, devlink)) 4693 if (devlink_nl_put_handle(msg, devlink))
4655 goto genlmsg_cancel; 4694 goto genlmsg_cancel;
4656 4695
4657 reporter_attr = nla_nest_start(msg, DEVLINK_ATTR_HEALTH_REPORTER); 4696 reporter_attr = nla_nest_start_noflag(msg,
4697 DEVLINK_ATTR_HEALTH_REPORTER);
4658 if (!reporter_attr) 4698 if (!reporter_attr)
4659 goto genlmsg_cancel; 4699 goto genlmsg_cancel;
4660 if (nla_put_string(msg, DEVLINK_ATTR_HEALTH_REPORTER_NAME, 4700 if (nla_put_string(msg, DEVLINK_ATTR_HEALTH_REPORTER_NAME,
@@ -4708,8 +4748,10 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
4708 return -EINVAL; 4748 return -EINVAL;
4709 4749
4710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4750 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4711 if (!msg) 4751 if (!msg) {
4712 return -ENOMEM; 4752 err = -ENOMEM;
4753 goto out;
4754 }
4713 4755
4714 err = devlink_nl_health_reporter_fill(msg, devlink, reporter, 4756 err = devlink_nl_health_reporter_fill(msg, devlink, reporter,
4715 DEVLINK_CMD_HEALTH_REPORTER_GET, 4757 DEVLINK_CMD_HEALTH_REPORTER_GET,
@@ -4717,10 +4759,13 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
4717 0); 4759 0);
4718 if (err) { 4760 if (err) {
4719 nlmsg_free(msg); 4761 nlmsg_free(msg);
4720 return err; 4762 goto out;
4721 } 4763 }
4722 4764
4723 return genlmsg_reply(msg, info); 4765 err = genlmsg_reply(msg, info);
4766out:
4767 devlink_health_reporter_put(reporter);
4768 return err;
4724} 4769}
4725 4770
4726static int 4771static int
@@ -4737,7 +4782,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
4737 list_for_each_entry(devlink, &devlink_list, list) { 4782 list_for_each_entry(devlink, &devlink_list, list) {
4738 if (!net_eq(devlink_net(devlink), sock_net(msg->sk))) 4783 if (!net_eq(devlink_net(devlink), sock_net(msg->sk)))
4739 continue; 4784 continue;
4740 mutex_lock(&devlink->lock); 4785 mutex_lock(&devlink->reporters_lock);
4741 list_for_each_entry(reporter, &devlink->reporter_list, 4786 list_for_each_entry(reporter, &devlink->reporter_list,
4742 list) { 4787 list) {
4743 if (idx < start) { 4788 if (idx < start) {
@@ -4751,12 +4796,12 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
4751 cb->nlh->nlmsg_seq, 4796 cb->nlh->nlmsg_seq,
4752 NLM_F_MULTI); 4797 NLM_F_MULTI);
4753 if (err) { 4798 if (err) {
4754 mutex_unlock(&devlink->lock); 4799 mutex_unlock(&devlink->reporters_lock);
4755 goto out; 4800 goto out;
4756 } 4801 }
4757 idx++; 4802 idx++;
4758 } 4803 }
4759 mutex_unlock(&devlink->lock); 4804 mutex_unlock(&devlink->reporters_lock);
4760 } 4805 }
4761out: 4806out:
4762 mutex_unlock(&devlink_mutex); 4807 mutex_unlock(&devlink_mutex);
@@ -4771,6 +4816,7 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
4771{ 4816{
4772 struct devlink *devlink = info->user_ptr[0]; 4817 struct devlink *devlink = info->user_ptr[0];
4773 struct devlink_health_reporter *reporter; 4818 struct devlink_health_reporter *reporter;
4819 int err;
4774 4820
4775 reporter = devlink_health_reporter_get_from_info(devlink, info); 4821 reporter = devlink_health_reporter_get_from_info(devlink, info);
4776 if (!reporter) 4822 if (!reporter)
@@ -4778,8 +4824,10 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
4778 4824
4779 if (!reporter->ops->recover && 4825 if (!reporter->ops->recover &&
4780 (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] || 4826 (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] ||
4781 info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])) 4827 info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])) {
4782 return -EOPNOTSUPP; 4828 err = -EOPNOTSUPP;
4829 goto out;
4830 }
4783 4831
4784 if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD]) 4832 if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD])
4785 reporter->graceful_period = 4833 reporter->graceful_period =
@@ -4789,7 +4837,11 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
4789 reporter->auto_recover = 4837 reporter->auto_recover =
4790 nla_get_u8(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]); 4838 nla_get_u8(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER]);
4791 4839
4840 devlink_health_reporter_put(reporter);
4792 return 0; 4841 return 0;
4842out:
4843 devlink_health_reporter_put(reporter);
4844 return err;
4793} 4845}
4794 4846
4795static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb, 4847static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,
@@ -4797,12 +4849,16 @@ static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,
4797{ 4849{
4798 struct devlink *devlink = info->user_ptr[0]; 4850 struct devlink *devlink = info->user_ptr[0];
4799 struct devlink_health_reporter *reporter; 4851 struct devlink_health_reporter *reporter;
4852 int err;
4800 4853
4801 reporter = devlink_health_reporter_get_from_info(devlink, info); 4854 reporter = devlink_health_reporter_get_from_info(devlink, info);
4802 if (!reporter) 4855 if (!reporter)
4803 return -EINVAL; 4856 return -EINVAL;
4804 4857
4805 return devlink_health_reporter_recover(reporter, NULL); 4858 err = devlink_health_reporter_recover(reporter, NULL);
4859
4860 devlink_health_reporter_put(reporter);
4861 return err;
4806} 4862}
4807 4863
4808static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb, 4864static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
@@ -4817,12 +4873,16 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
4817 if (!reporter) 4873 if (!reporter)
4818 return -EINVAL; 4874 return -EINVAL;
4819 4875
4820 if (!reporter->ops->diagnose) 4876 if (!reporter->ops->diagnose) {
4877 devlink_health_reporter_put(reporter);
4821 return -EOPNOTSUPP; 4878 return -EOPNOTSUPP;
4879 }
4822 4880
4823 fmsg = devlink_fmsg_alloc(); 4881 fmsg = devlink_fmsg_alloc();
4824 if (!fmsg) 4882 if (!fmsg) {
4883 devlink_health_reporter_put(reporter);
4825 return -ENOMEM; 4884 return -ENOMEM;
4885 }
4826 4886
4827 err = devlink_fmsg_obj_nest_start(fmsg); 4887 err = devlink_fmsg_obj_nest_start(fmsg);
4828 if (err) 4888 if (err)
@@ -4841,6 +4901,7 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
4841 4901
4842out: 4902out:
4843 devlink_fmsg_free(fmsg); 4903 devlink_fmsg_free(fmsg);
4904 devlink_health_reporter_put(reporter);
4844 return err; 4905 return err;
4845} 4906}
4846 4907
@@ -4855,8 +4916,10 @@ static int devlink_nl_cmd_health_reporter_dump_get_doit(struct sk_buff *skb,
4855 if (!reporter) 4916 if (!reporter)
4856 return -EINVAL; 4917 return -EINVAL;
4857 4918
4858 if (!reporter->ops->dump) 4919 if (!reporter->ops->dump) {
4920 devlink_health_reporter_put(reporter);
4859 return -EOPNOTSUPP; 4921 return -EOPNOTSUPP;
4922 }
4860 4923
4861 mutex_lock(&reporter->dump_lock); 4924 mutex_lock(&reporter->dump_lock);
4862 err = devlink_health_do_dump(reporter, NULL); 4925 err = devlink_health_do_dump(reporter, NULL);
@@ -4868,6 +4931,7 @@ static int devlink_nl_cmd_health_reporter_dump_get_doit(struct sk_buff *skb,
4868 4931
4869out: 4932out:
4870 mutex_unlock(&reporter->dump_lock); 4933 mutex_unlock(&reporter->dump_lock);
4934 devlink_health_reporter_put(reporter);
4871 return err; 4935 return err;
4872} 4936}
4873 4937
@@ -4882,12 +4946,15 @@ devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb,
4882 if (!reporter) 4946 if (!reporter)
4883 return -EINVAL; 4947 return -EINVAL;
4884 4948
4885 if (!reporter->ops->dump) 4949 if (!reporter->ops->dump) {
4950 devlink_health_reporter_put(reporter);
4886 return -EOPNOTSUPP; 4951 return -EOPNOTSUPP;
4952 }
4887 4953
4888 mutex_lock(&reporter->dump_lock); 4954 mutex_lock(&reporter->dump_lock);
4889 devlink_health_dump_clear(reporter); 4955 devlink_health_dump_clear(reporter);
4890 mutex_unlock(&reporter->dump_lock); 4956 mutex_unlock(&reporter->dump_lock);
4957 devlink_health_reporter_put(reporter);
4891 return 0; 4958 return 0;
4892} 4959}
4893 4960
@@ -4926,293 +4993,297 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
4926static const struct genl_ops devlink_nl_ops[] = { 4993static const struct genl_ops devlink_nl_ops[] = {
4927 { 4994 {
4928 .cmd = DEVLINK_CMD_GET, 4995 .cmd = DEVLINK_CMD_GET,
4996 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4929 .doit = devlink_nl_cmd_get_doit, 4997 .doit = devlink_nl_cmd_get_doit,
4930 .dumpit = devlink_nl_cmd_get_dumpit, 4998 .dumpit = devlink_nl_cmd_get_dumpit,
4931 .policy = devlink_nl_policy,
4932 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 4999 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
4933 /* can be retrieved by unprivileged users */ 5000 /* can be retrieved by unprivileged users */
4934 }, 5001 },
4935 { 5002 {
4936 .cmd = DEVLINK_CMD_PORT_GET, 5003 .cmd = DEVLINK_CMD_PORT_GET,
5004 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4937 .doit = devlink_nl_cmd_port_get_doit, 5005 .doit = devlink_nl_cmd_port_get_doit,
4938 .dumpit = devlink_nl_cmd_port_get_dumpit, 5006 .dumpit = devlink_nl_cmd_port_get_dumpit,
4939 .policy = devlink_nl_policy,
4940 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, 5007 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
4941 /* can be retrieved by unprivileged users */ 5008 /* can be retrieved by unprivileged users */
4942 }, 5009 },
4943 { 5010 {
4944 .cmd = DEVLINK_CMD_PORT_SET, 5011 .cmd = DEVLINK_CMD_PORT_SET,
5012 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4945 .doit = devlink_nl_cmd_port_set_doit, 5013 .doit = devlink_nl_cmd_port_set_doit,
4946 .policy = devlink_nl_policy,
4947 .flags = GENL_ADMIN_PERM, 5014 .flags = GENL_ADMIN_PERM,
4948 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, 5015 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
4949 }, 5016 },
4950 { 5017 {
4951 .cmd = DEVLINK_CMD_PORT_SPLIT, 5018 .cmd = DEVLINK_CMD_PORT_SPLIT,
5019 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4952 .doit = devlink_nl_cmd_port_split_doit, 5020 .doit = devlink_nl_cmd_port_split_doit,
4953 .policy = devlink_nl_policy,
4954 .flags = GENL_ADMIN_PERM, 5021 .flags = GENL_ADMIN_PERM,
4955 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5022 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
4956 DEVLINK_NL_FLAG_NO_LOCK, 5023 DEVLINK_NL_FLAG_NO_LOCK,
4957 }, 5024 },
4958 { 5025 {
4959 .cmd = DEVLINK_CMD_PORT_UNSPLIT, 5026 .cmd = DEVLINK_CMD_PORT_UNSPLIT,
5027 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4960 .doit = devlink_nl_cmd_port_unsplit_doit, 5028 .doit = devlink_nl_cmd_port_unsplit_doit,
4961 .policy = devlink_nl_policy,
4962 .flags = GENL_ADMIN_PERM, 5029 .flags = GENL_ADMIN_PERM,
4963 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5030 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
4964 DEVLINK_NL_FLAG_NO_LOCK, 5031 DEVLINK_NL_FLAG_NO_LOCK,
4965 }, 5032 },
4966 { 5033 {
4967 .cmd = DEVLINK_CMD_SB_GET, 5034 .cmd = DEVLINK_CMD_SB_GET,
5035 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4968 .doit = devlink_nl_cmd_sb_get_doit, 5036 .doit = devlink_nl_cmd_sb_get_doit,
4969 .dumpit = devlink_nl_cmd_sb_get_dumpit, 5037 .dumpit = devlink_nl_cmd_sb_get_dumpit,
4970 .policy = devlink_nl_policy,
4971 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5038 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
4972 DEVLINK_NL_FLAG_NEED_SB, 5039 DEVLINK_NL_FLAG_NEED_SB,
4973 /* can be retrieved by unprivileged users */ 5040 /* can be retrieved by unprivileged users */
4974 }, 5041 },
4975 { 5042 {
4976 .cmd = DEVLINK_CMD_SB_POOL_GET, 5043 .cmd = DEVLINK_CMD_SB_POOL_GET,
5044 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4977 .doit = devlink_nl_cmd_sb_pool_get_doit, 5045 .doit = devlink_nl_cmd_sb_pool_get_doit,
4978 .dumpit = devlink_nl_cmd_sb_pool_get_dumpit, 5046 .dumpit = devlink_nl_cmd_sb_pool_get_dumpit,
4979 .policy = devlink_nl_policy,
4980 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5047 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
4981 DEVLINK_NL_FLAG_NEED_SB, 5048 DEVLINK_NL_FLAG_NEED_SB,
4982 /* can be retrieved by unprivileged users */ 5049 /* can be retrieved by unprivileged users */
4983 }, 5050 },
4984 { 5051 {
4985 .cmd = DEVLINK_CMD_SB_POOL_SET, 5052 .cmd = DEVLINK_CMD_SB_POOL_SET,
5053 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4986 .doit = devlink_nl_cmd_sb_pool_set_doit, 5054 .doit = devlink_nl_cmd_sb_pool_set_doit,
4987 .policy = devlink_nl_policy,
4988 .flags = GENL_ADMIN_PERM, 5055 .flags = GENL_ADMIN_PERM,
4989 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5056 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
4990 DEVLINK_NL_FLAG_NEED_SB, 5057 DEVLINK_NL_FLAG_NEED_SB,
4991 }, 5058 },
4992 { 5059 {
4993 .cmd = DEVLINK_CMD_SB_PORT_POOL_GET, 5060 .cmd = DEVLINK_CMD_SB_PORT_POOL_GET,
5061 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
4994 .doit = devlink_nl_cmd_sb_port_pool_get_doit, 5062 .doit = devlink_nl_cmd_sb_port_pool_get_doit,
4995 .dumpit = devlink_nl_cmd_sb_port_pool_get_dumpit, 5063 .dumpit = devlink_nl_cmd_sb_port_pool_get_dumpit,
4996 .policy = devlink_nl_policy,
4997 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT | 5064 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT |
4998 DEVLINK_NL_FLAG_NEED_SB, 5065 DEVLINK_NL_FLAG_NEED_SB,
4999 /* can be retrieved by unprivileged users */ 5066 /* can be retrieved by unprivileged users */
5000 }, 5067 },
5001 { 5068 {
5002 .cmd = DEVLINK_CMD_SB_PORT_POOL_SET, 5069 .cmd = DEVLINK_CMD_SB_PORT_POOL_SET,
5070 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5003 .doit = devlink_nl_cmd_sb_port_pool_set_doit, 5071 .doit = devlink_nl_cmd_sb_port_pool_set_doit,
5004 .policy = devlink_nl_policy,
5005 .flags = GENL_ADMIN_PERM, 5072 .flags = GENL_ADMIN_PERM,
5006 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT | 5073 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT |
5007 DEVLINK_NL_FLAG_NEED_SB, 5074 DEVLINK_NL_FLAG_NEED_SB,
5008 }, 5075 },
5009 { 5076 {
5010 .cmd = DEVLINK_CMD_SB_TC_POOL_BIND_GET, 5077 .cmd = DEVLINK_CMD_SB_TC_POOL_BIND_GET,
5078 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5011 .doit = devlink_nl_cmd_sb_tc_pool_bind_get_doit, 5079 .doit = devlink_nl_cmd_sb_tc_pool_bind_get_doit,
5012 .dumpit = devlink_nl_cmd_sb_tc_pool_bind_get_dumpit, 5080 .dumpit = devlink_nl_cmd_sb_tc_pool_bind_get_dumpit,
5013 .policy = devlink_nl_policy,
5014 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT | 5081 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT |
5015 DEVLINK_NL_FLAG_NEED_SB, 5082 DEVLINK_NL_FLAG_NEED_SB,
5016 /* can be retrieved by unprivileged users */ 5083 /* can be retrieved by unprivileged users */
5017 }, 5084 },
5018 { 5085 {
5019 .cmd = DEVLINK_CMD_SB_TC_POOL_BIND_SET, 5086 .cmd = DEVLINK_CMD_SB_TC_POOL_BIND_SET,
5087 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5020 .doit = devlink_nl_cmd_sb_tc_pool_bind_set_doit, 5088 .doit = devlink_nl_cmd_sb_tc_pool_bind_set_doit,
5021 .policy = devlink_nl_policy,
5022 .flags = GENL_ADMIN_PERM, 5089 .flags = GENL_ADMIN_PERM,
5023 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT | 5090 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT |
5024 DEVLINK_NL_FLAG_NEED_SB, 5091 DEVLINK_NL_FLAG_NEED_SB,
5025 }, 5092 },
5026 { 5093 {
5027 .cmd = DEVLINK_CMD_SB_OCC_SNAPSHOT, 5094 .cmd = DEVLINK_CMD_SB_OCC_SNAPSHOT,
5095 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5028 .doit = devlink_nl_cmd_sb_occ_snapshot_doit, 5096 .doit = devlink_nl_cmd_sb_occ_snapshot_doit,
5029 .policy = devlink_nl_policy,
5030 .flags = GENL_ADMIN_PERM, 5097 .flags = GENL_ADMIN_PERM,
5031 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5098 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5032 DEVLINK_NL_FLAG_NEED_SB, 5099 DEVLINK_NL_FLAG_NEED_SB,
5033 }, 5100 },
5034 { 5101 {
5035 .cmd = DEVLINK_CMD_SB_OCC_MAX_CLEAR, 5102 .cmd = DEVLINK_CMD_SB_OCC_MAX_CLEAR,
5103 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5036 .doit = devlink_nl_cmd_sb_occ_max_clear_doit, 5104 .doit = devlink_nl_cmd_sb_occ_max_clear_doit,
5037 .policy = devlink_nl_policy,
5038 .flags = GENL_ADMIN_PERM, 5105 .flags = GENL_ADMIN_PERM,
5039 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5106 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5040 DEVLINK_NL_FLAG_NEED_SB, 5107 DEVLINK_NL_FLAG_NEED_SB,
5041 }, 5108 },
5042 { 5109 {
5043 .cmd = DEVLINK_CMD_ESWITCH_GET, 5110 .cmd = DEVLINK_CMD_ESWITCH_GET,
5111 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5044 .doit = devlink_nl_cmd_eswitch_get_doit, 5112 .doit = devlink_nl_cmd_eswitch_get_doit,
5045 .policy = devlink_nl_policy,
5046 .flags = GENL_ADMIN_PERM, 5113 .flags = GENL_ADMIN_PERM,
5047 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5114 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5048 }, 5115 },
5049 { 5116 {
5050 .cmd = DEVLINK_CMD_ESWITCH_SET, 5117 .cmd = DEVLINK_CMD_ESWITCH_SET,
5118 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5051 .doit = devlink_nl_cmd_eswitch_set_doit, 5119 .doit = devlink_nl_cmd_eswitch_set_doit,
5052 .policy = devlink_nl_policy,
5053 .flags = GENL_ADMIN_PERM, 5120 .flags = GENL_ADMIN_PERM,
5054 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5121 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5055 DEVLINK_NL_FLAG_NO_LOCK, 5122 DEVLINK_NL_FLAG_NO_LOCK,
5056 }, 5123 },
5057 { 5124 {
5058 .cmd = DEVLINK_CMD_DPIPE_TABLE_GET, 5125 .cmd = DEVLINK_CMD_DPIPE_TABLE_GET,
5126 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5059 .doit = devlink_nl_cmd_dpipe_table_get, 5127 .doit = devlink_nl_cmd_dpipe_table_get,
5060 .policy = devlink_nl_policy,
5061 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5128 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5062 /* can be retrieved by unprivileged users */ 5129 /* can be retrieved by unprivileged users */
5063 }, 5130 },
5064 { 5131 {
5065 .cmd = DEVLINK_CMD_DPIPE_ENTRIES_GET, 5132 .cmd = DEVLINK_CMD_DPIPE_ENTRIES_GET,
5133 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5066 .doit = devlink_nl_cmd_dpipe_entries_get, 5134 .doit = devlink_nl_cmd_dpipe_entries_get,
5067 .policy = devlink_nl_policy,
5068 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5135 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5069 /* can be retrieved by unprivileged users */ 5136 /* can be retrieved by unprivileged users */
5070 }, 5137 },
5071 { 5138 {
5072 .cmd = DEVLINK_CMD_DPIPE_HEADERS_GET, 5139 .cmd = DEVLINK_CMD_DPIPE_HEADERS_GET,
5140 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5073 .doit = devlink_nl_cmd_dpipe_headers_get, 5141 .doit = devlink_nl_cmd_dpipe_headers_get,
5074 .policy = devlink_nl_policy,
5075 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5142 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5076 /* can be retrieved by unprivileged users */ 5143 /* can be retrieved by unprivileged users */
5077 }, 5144 },
5078 { 5145 {
5079 .cmd = DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET, 5146 .cmd = DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET,
5147 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5080 .doit = devlink_nl_cmd_dpipe_table_counters_set, 5148 .doit = devlink_nl_cmd_dpipe_table_counters_set,
5081 .policy = devlink_nl_policy,
5082 .flags = GENL_ADMIN_PERM, 5149 .flags = GENL_ADMIN_PERM,
5083 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5150 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5084 }, 5151 },
5085 { 5152 {
5086 .cmd = DEVLINK_CMD_RESOURCE_SET, 5153 .cmd = DEVLINK_CMD_RESOURCE_SET,
5154 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5087 .doit = devlink_nl_cmd_resource_set, 5155 .doit = devlink_nl_cmd_resource_set,
5088 .policy = devlink_nl_policy,
5089 .flags = GENL_ADMIN_PERM, 5156 .flags = GENL_ADMIN_PERM,
5090 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5157 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5091 }, 5158 },
5092 { 5159 {
5093 .cmd = DEVLINK_CMD_RESOURCE_DUMP, 5160 .cmd = DEVLINK_CMD_RESOURCE_DUMP,
5161 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5094 .doit = devlink_nl_cmd_resource_dump, 5162 .doit = devlink_nl_cmd_resource_dump,
5095 .policy = devlink_nl_policy,
5096 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5163 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5097 /* can be retrieved by unprivileged users */ 5164 /* can be retrieved by unprivileged users */
5098 }, 5165 },
5099 { 5166 {
5100 .cmd = DEVLINK_CMD_RELOAD, 5167 .cmd = DEVLINK_CMD_RELOAD,
5168 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5101 .doit = devlink_nl_cmd_reload, 5169 .doit = devlink_nl_cmd_reload,
5102 .policy = devlink_nl_policy,
5103 .flags = GENL_ADMIN_PERM, 5170 .flags = GENL_ADMIN_PERM,
5104 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5171 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5105 DEVLINK_NL_FLAG_NO_LOCK, 5172 DEVLINK_NL_FLAG_NO_LOCK,
5106 }, 5173 },
5107 { 5174 {
5108 .cmd = DEVLINK_CMD_PARAM_GET, 5175 .cmd = DEVLINK_CMD_PARAM_GET,
5176 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5109 .doit = devlink_nl_cmd_param_get_doit, 5177 .doit = devlink_nl_cmd_param_get_doit,
5110 .dumpit = devlink_nl_cmd_param_get_dumpit, 5178 .dumpit = devlink_nl_cmd_param_get_dumpit,
5111 .policy = devlink_nl_policy,
5112 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5179 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5113 /* can be retrieved by unprivileged users */ 5180 /* can be retrieved by unprivileged users */
5114 }, 5181 },
5115 { 5182 {
5116 .cmd = DEVLINK_CMD_PARAM_SET, 5183 .cmd = DEVLINK_CMD_PARAM_SET,
5184 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5117 .doit = devlink_nl_cmd_param_set_doit, 5185 .doit = devlink_nl_cmd_param_set_doit,
5118 .policy = devlink_nl_policy,
5119 .flags = GENL_ADMIN_PERM, 5186 .flags = GENL_ADMIN_PERM,
5120 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5187 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5121 }, 5188 },
5122 { 5189 {
5123 .cmd = DEVLINK_CMD_PORT_PARAM_GET, 5190 .cmd = DEVLINK_CMD_PORT_PARAM_GET,
5191 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5124 .doit = devlink_nl_cmd_port_param_get_doit, 5192 .doit = devlink_nl_cmd_port_param_get_doit,
5125 .dumpit = devlink_nl_cmd_port_param_get_dumpit, 5193 .dumpit = devlink_nl_cmd_port_param_get_dumpit,
5126 .policy = devlink_nl_policy,
5127 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, 5194 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
5128 /* can be retrieved by unprivileged users */ 5195 /* can be retrieved by unprivileged users */
5129 }, 5196 },
5130 { 5197 {
5131 .cmd = DEVLINK_CMD_PORT_PARAM_SET, 5198 .cmd = DEVLINK_CMD_PORT_PARAM_SET,
5199 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5132 .doit = devlink_nl_cmd_port_param_set_doit, 5200 .doit = devlink_nl_cmd_port_param_set_doit,
5133 .policy = devlink_nl_policy,
5134 .flags = GENL_ADMIN_PERM, 5201 .flags = GENL_ADMIN_PERM,
5135 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, 5202 .internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
5136 }, 5203 },
5137 { 5204 {
5138 .cmd = DEVLINK_CMD_REGION_GET, 5205 .cmd = DEVLINK_CMD_REGION_GET,
5206 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5139 .doit = devlink_nl_cmd_region_get_doit, 5207 .doit = devlink_nl_cmd_region_get_doit,
5140 .dumpit = devlink_nl_cmd_region_get_dumpit, 5208 .dumpit = devlink_nl_cmd_region_get_dumpit,
5141 .policy = devlink_nl_policy,
5142 .flags = GENL_ADMIN_PERM, 5209 .flags = GENL_ADMIN_PERM,
5143 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5210 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5144 }, 5211 },
5145 { 5212 {
5146 .cmd = DEVLINK_CMD_REGION_DEL, 5213 .cmd = DEVLINK_CMD_REGION_DEL,
5214 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5147 .doit = devlink_nl_cmd_region_del, 5215 .doit = devlink_nl_cmd_region_del,
5148 .policy = devlink_nl_policy,
5149 .flags = GENL_ADMIN_PERM, 5216 .flags = GENL_ADMIN_PERM,
5150 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5217 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5151 }, 5218 },
5152 { 5219 {
5153 .cmd = DEVLINK_CMD_REGION_READ, 5220 .cmd = DEVLINK_CMD_REGION_READ,
5221 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5154 .dumpit = devlink_nl_cmd_region_read_dumpit, 5222 .dumpit = devlink_nl_cmd_region_read_dumpit,
5155 .policy = devlink_nl_policy,
5156 .flags = GENL_ADMIN_PERM, 5223 .flags = GENL_ADMIN_PERM,
5157 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5224 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5158 }, 5225 },
5159 { 5226 {
5160 .cmd = DEVLINK_CMD_INFO_GET, 5227 .cmd = DEVLINK_CMD_INFO_GET,
5228 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5161 .doit = devlink_nl_cmd_info_get_doit, 5229 .doit = devlink_nl_cmd_info_get_doit,
5162 .dumpit = devlink_nl_cmd_info_get_dumpit, 5230 .dumpit = devlink_nl_cmd_info_get_dumpit,
5163 .policy = devlink_nl_policy,
5164 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5231 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5165 /* can be retrieved by unprivileged users */ 5232 /* can be retrieved by unprivileged users */
5166 }, 5233 },
5167 { 5234 {
5168 .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, 5235 .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET,
5236 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5169 .doit = devlink_nl_cmd_health_reporter_get_doit, 5237 .doit = devlink_nl_cmd_health_reporter_get_doit,
5170 .dumpit = devlink_nl_cmd_health_reporter_get_dumpit, 5238 .dumpit = devlink_nl_cmd_health_reporter_get_dumpit,
5171 .policy = devlink_nl_policy, 5239 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5172 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5240 DEVLINK_NL_FLAG_NO_LOCK,
5173 /* can be retrieved by unprivileged users */ 5241 /* can be retrieved by unprivileged users */
5174 }, 5242 },
5175 { 5243 {
5176 .cmd = DEVLINK_CMD_HEALTH_REPORTER_SET, 5244 .cmd = DEVLINK_CMD_HEALTH_REPORTER_SET,
5245 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5177 .doit = devlink_nl_cmd_health_reporter_set_doit, 5246 .doit = devlink_nl_cmd_health_reporter_set_doit,
5178 .policy = devlink_nl_policy,
5179 .flags = GENL_ADMIN_PERM, 5247 .flags = GENL_ADMIN_PERM,
5180 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5248 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5249 DEVLINK_NL_FLAG_NO_LOCK,
5181 }, 5250 },
5182 { 5251 {
5183 .cmd = DEVLINK_CMD_HEALTH_REPORTER_RECOVER, 5252 .cmd = DEVLINK_CMD_HEALTH_REPORTER_RECOVER,
5253 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5184 .doit = devlink_nl_cmd_health_reporter_recover_doit, 5254 .doit = devlink_nl_cmd_health_reporter_recover_doit,
5185 .policy = devlink_nl_policy,
5186 .flags = GENL_ADMIN_PERM, 5255 .flags = GENL_ADMIN_PERM,
5187 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5256 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5257 DEVLINK_NL_FLAG_NO_LOCK,
5188 }, 5258 },
5189 { 5259 {
5190 .cmd = DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 5260 .cmd = DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE,
5261 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5191 .doit = devlink_nl_cmd_health_reporter_diagnose_doit, 5262 .doit = devlink_nl_cmd_health_reporter_diagnose_doit,
5192 .policy = devlink_nl_policy,
5193 .flags = GENL_ADMIN_PERM, 5263 .flags = GENL_ADMIN_PERM,
5194 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5264 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5265 DEVLINK_NL_FLAG_NO_LOCK,
5195 }, 5266 },
5196 { 5267 {
5197 .cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET, 5268 .cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
5269 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5198 .doit = devlink_nl_cmd_health_reporter_dump_get_doit, 5270 .doit = devlink_nl_cmd_health_reporter_dump_get_doit,
5199 .policy = devlink_nl_policy,
5200 .flags = GENL_ADMIN_PERM, 5271 .flags = GENL_ADMIN_PERM,
5201 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5272 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5202 DEVLINK_NL_FLAG_NO_LOCK, 5273 DEVLINK_NL_FLAG_NO_LOCK,
5203 }, 5274 },
5204 { 5275 {
5205 .cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR, 5276 .cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
5277 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5206 .doit = devlink_nl_cmd_health_reporter_dump_clear_doit, 5278 .doit = devlink_nl_cmd_health_reporter_dump_clear_doit,
5207 .policy = devlink_nl_policy,
5208 .flags = GENL_ADMIN_PERM, 5279 .flags = GENL_ADMIN_PERM,
5209 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK | 5280 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
5210 DEVLINK_NL_FLAG_NO_LOCK, 5281 DEVLINK_NL_FLAG_NO_LOCK,
5211 }, 5282 },
5212 { 5283 {
5213 .cmd = DEVLINK_CMD_FLASH_UPDATE, 5284 .cmd = DEVLINK_CMD_FLASH_UPDATE,
5285 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5214 .doit = devlink_nl_cmd_flash_update, 5286 .doit = devlink_nl_cmd_flash_update,
5215 .policy = devlink_nl_policy,
5216 .flags = GENL_ADMIN_PERM, 5287 .flags = GENL_ADMIN_PERM,
5217 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK, 5288 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
5218 }, 5289 },
@@ -5222,6 +5293,7 @@ static struct genl_family devlink_nl_family __ro_after_init = {
5222 .name = DEVLINK_GENL_NAME, 5293 .name = DEVLINK_GENL_NAME,
5223 .version = DEVLINK_GENL_VERSION, 5294 .version = DEVLINK_GENL_VERSION,
5224 .maxattr = DEVLINK_ATTR_MAX, 5295 .maxattr = DEVLINK_ATTR_MAX,
5296 .policy = devlink_nl_policy,
5225 .netnsok = true, 5297 .netnsok = true,
5226 .pre_doit = devlink_nl_pre_doit, 5298 .pre_doit = devlink_nl_pre_doit,
5227 .post_doit = devlink_nl_post_doit, 5299 .post_doit = devlink_nl_post_doit,
@@ -5261,6 +5333,7 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size)
5261 INIT_LIST_HEAD(&devlink->region_list); 5333 INIT_LIST_HEAD(&devlink->region_list);
5262 INIT_LIST_HEAD(&devlink->reporter_list); 5334 INIT_LIST_HEAD(&devlink->reporter_list);
5263 mutex_init(&devlink->lock); 5335 mutex_init(&devlink->lock);
5336 mutex_init(&devlink->reporters_lock);
5264 return devlink; 5337 return devlink;
5265} 5338}
5266EXPORT_SYMBOL_GPL(devlink_alloc); 5339EXPORT_SYMBOL_GPL(devlink_alloc);
@@ -5303,6 +5376,8 @@ EXPORT_SYMBOL_GPL(devlink_unregister);
5303 */ 5376 */
5304void devlink_free(struct devlink *devlink) 5377void devlink_free(struct devlink *devlink)
5305{ 5378{
5379 mutex_destroy(&devlink->reporters_lock);
5380 mutex_destroy(&devlink->lock);
5306 WARN_ON(!list_empty(&devlink->reporter_list)); 5381 WARN_ON(!list_empty(&devlink->reporter_list));
5307 WARN_ON(!list_empty(&devlink->region_list)); 5382 WARN_ON(!list_empty(&devlink->region_list));
5308 WARN_ON(!list_empty(&devlink->param_list)); 5383 WARN_ON(!list_empty(&devlink->param_list));
@@ -5340,6 +5415,7 @@ int devlink_port_register(struct devlink *devlink,
5340 devlink_port->devlink = devlink; 5415 devlink_port->devlink = devlink;
5341 devlink_port->index = port_index; 5416 devlink_port->index = port_index;
5342 devlink_port->registered = true; 5417 devlink_port->registered = true;
5418 spin_lock_init(&devlink_port->type_lock);
5343 list_add_tail(&devlink_port->list, &devlink->port_list); 5419 list_add_tail(&devlink_port->list, &devlink->port_list);
5344 INIT_LIST_HEAD(&devlink_port->param_list); 5420 INIT_LIST_HEAD(&devlink_port->param_list);
5345 mutex_unlock(&devlink->lock); 5421 mutex_unlock(&devlink->lock);
@@ -5368,8 +5444,12 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port,
5368 enum devlink_port_type type, 5444 enum devlink_port_type type,
5369 void *type_dev) 5445 void *type_dev)
5370{ 5446{
5447 if (WARN_ON(!devlink_port->registered))
5448 return;
5449 spin_lock(&devlink_port->type_lock);
5371 devlink_port->type = type; 5450 devlink_port->type = type;
5372 devlink_port->type_dev = type_dev; 5451 devlink_port->type_dev = type_dev;
5452 spin_unlock(&devlink_port->type_lock);
5373 devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW); 5453 devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);
5374} 5454}
5375 5455
@@ -5382,8 +5462,39 @@ static void __devlink_port_type_set(struct devlink_port *devlink_port,
5382void devlink_port_type_eth_set(struct devlink_port *devlink_port, 5462void devlink_port_type_eth_set(struct devlink_port *devlink_port,
5383 struct net_device *netdev) 5463 struct net_device *netdev)
5384{ 5464{
5385 return __devlink_port_type_set(devlink_port, 5465 const struct net_device_ops *ops = netdev->netdev_ops;
5386 DEVLINK_PORT_TYPE_ETH, netdev); 5466
5467 /* If driver registers devlink port, it should set devlink port
5468 * attributes accordingly so the compat functions are called
5469 * and the original ops are not used.
5470 */
5471 if (ops->ndo_get_phys_port_name) {
5472 /* Some drivers use the same set of ndos for netdevs
5473 * that have devlink_port registered and also for
5474 * those who don't. Make sure that ndo_get_phys_port_name
5475 * returns -EOPNOTSUPP here in case it is defined.
5476 * Warn if not.
5477 */
5478 char name[IFNAMSIZ];
5479 int err;
5480
5481 err = ops->ndo_get_phys_port_name(netdev, name, sizeof(name));
5482 WARN_ON(err != -EOPNOTSUPP);
5483 }
5484 if (ops->ndo_get_port_parent_id) {
5485 /* Some drivers use the same set of ndos for netdevs
5486 * that have devlink_port registered and also for
5487 * those who don't. Make sure that ndo_get_port_parent_id
5488 * returns -EOPNOTSUPP here in case it is defined.
5489 * Warn if not.
5490 */
5491 struct netdev_phys_item_id ppid;
5492 int err;
5493
5494 err = ops->ndo_get_port_parent_id(netdev, &ppid);
5495 WARN_ON(err != -EOPNOTSUPP);
5496 }
5497 __devlink_port_type_set(devlink_port, DEVLINK_PORT_TYPE_ETH, netdev);
5387} 5498}
5388EXPORT_SYMBOL_GPL(devlink_port_type_eth_set); 5499EXPORT_SYMBOL_GPL(devlink_port_type_eth_set);
5389 5500
@@ -5396,8 +5507,7 @@ EXPORT_SYMBOL_GPL(devlink_port_type_eth_set);
5396void devlink_port_type_ib_set(struct devlink_port *devlink_port, 5507void devlink_port_type_ib_set(struct devlink_port *devlink_port,
5397 struct ib_device *ibdev) 5508 struct ib_device *ibdev)
5398{ 5509{
5399 return __devlink_port_type_set(devlink_port, 5510 __devlink_port_type_set(devlink_port, DEVLINK_PORT_TYPE_IB, ibdev);
5400 DEVLINK_PORT_TYPE_IB, ibdev);
5401} 5511}
5402EXPORT_SYMBOL_GPL(devlink_port_type_ib_set); 5512EXPORT_SYMBOL_GPL(devlink_port_type_ib_set);
5403 5513
@@ -5408,8 +5518,7 @@ EXPORT_SYMBOL_GPL(devlink_port_type_ib_set);
5408 */ 5518 */
5409void devlink_port_type_clear(struct devlink_port *devlink_port) 5519void devlink_port_type_clear(struct devlink_port *devlink_port)
5410{ 5520{
5411 return __devlink_port_type_set(devlink_port, 5521 __devlink_port_type_set(devlink_port, DEVLINK_PORT_TYPE_NOTSET, NULL);
5412 DEVLINK_PORT_TYPE_NOTSET, NULL);
5413} 5522}
5414EXPORT_SYMBOL_GPL(devlink_port_type_clear); 5523EXPORT_SYMBOL_GPL(devlink_port_type_clear);
5415 5524
@@ -5423,25 +5532,40 @@ EXPORT_SYMBOL_GPL(devlink_port_type_clear);
5423 * @split: indicates if this is split port 5532 * @split: indicates if this is split port
5424 * @split_subport_number: if the port is split, this is the number 5533 * @split_subport_number: if the port is split, this is the number
5425 * of subport. 5534 * of subport.
5535 * @switch_id: if the port is part of switch, this is buffer with ID,
5536 * otwerwise this is NULL
5537 * @switch_id_len: length of the switch_id buffer
5426 */ 5538 */
5427void devlink_port_attrs_set(struct devlink_port *devlink_port, 5539void devlink_port_attrs_set(struct devlink_port *devlink_port,
5428 enum devlink_port_flavour flavour, 5540 enum devlink_port_flavour flavour,
5429 u32 port_number, bool split, 5541 u32 port_number, bool split,
5430 u32 split_subport_number) 5542 u32 split_subport_number,
5543 const unsigned char *switch_id,
5544 unsigned char switch_id_len)
5431{ 5545{
5432 struct devlink_port_attrs *attrs = &devlink_port->attrs; 5546 struct devlink_port_attrs *attrs = &devlink_port->attrs;
5433 5547
5548 if (WARN_ON(devlink_port->registered))
5549 return;
5434 attrs->set = true; 5550 attrs->set = true;
5435 attrs->flavour = flavour; 5551 attrs->flavour = flavour;
5436 attrs->port_number = port_number; 5552 attrs->port_number = port_number;
5437 attrs->split = split; 5553 attrs->split = split;
5438 attrs->split_subport_number = split_subport_number; 5554 attrs->split_subport_number = split_subport_number;
5439 devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW); 5555 if (switch_id) {
5556 attrs->switch_port = true;
5557 if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
5558 switch_id_len = MAX_PHYS_ITEM_ID_LEN;
5559 memcpy(attrs->switch_id.id, switch_id, switch_id_len);
5560 attrs->switch_id.id_len = switch_id_len;
5561 } else {
5562 attrs->switch_port = false;
5563 }
5440} 5564}
5441EXPORT_SYMBOL_GPL(devlink_port_attrs_set); 5565EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
5442 5566
5443int devlink_port_get_phys_port_name(struct devlink_port *devlink_port, 5567static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
5444 char *name, size_t len) 5568 char *name, size_t len)
5445{ 5569{
5446 struct devlink_port_attrs *attrs = &devlink_port->attrs; 5570 struct devlink_port_attrs *attrs = &devlink_port->attrs;
5447 int n = 0; 5571 int n = 0;
@@ -5471,7 +5595,6 @@ int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
5471 5595
5472 return 0; 5596 return 0;
5473} 5597}
5474EXPORT_SYMBOL_GPL(devlink_port_get_phys_port_name);
5475 5598
5476int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, 5599int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
5477 u32 size, u16 ingress_pools_count, 5600 u32 size, u16 ingress_pools_count,
@@ -6447,17 +6570,15 @@ void devlink_compat_running_version(struct net_device *dev,
6447 dev_hold(dev); 6570 dev_hold(dev);
6448 rtnl_unlock(); 6571 rtnl_unlock();
6449 6572
6450 mutex_lock(&devlink_mutex);
6451 devlink = netdev_to_devlink(dev); 6573 devlink = netdev_to_devlink(dev);
6452 if (!devlink || !devlink->ops->info_get) 6574 if (!devlink || !devlink->ops->info_get)
6453 goto unlock_list; 6575 goto out;
6454 6576
6455 mutex_lock(&devlink->lock); 6577 mutex_lock(&devlink->lock);
6456 __devlink_compat_running_version(devlink, buf, len); 6578 __devlink_compat_running_version(devlink, buf, len);
6457 mutex_unlock(&devlink->lock); 6579 mutex_unlock(&devlink->lock);
6458unlock_list:
6459 mutex_unlock(&devlink_mutex);
6460 6580
6581out:
6461 rtnl_lock(); 6582 rtnl_lock();
6462 dev_put(dev); 6583 dev_put(dev);
6463} 6584}
@@ -6465,28 +6586,65 @@ unlock_list:
6465int devlink_compat_flash_update(struct net_device *dev, const char *file_name) 6586int devlink_compat_flash_update(struct net_device *dev, const char *file_name)
6466{ 6587{
6467 struct devlink *devlink; 6588 struct devlink *devlink;
6468 int ret = -EOPNOTSUPP; 6589 int ret;
6469 6590
6470 dev_hold(dev); 6591 dev_hold(dev);
6471 rtnl_unlock(); 6592 rtnl_unlock();
6472 6593
6473 mutex_lock(&devlink_mutex);
6474 devlink = netdev_to_devlink(dev); 6594 devlink = netdev_to_devlink(dev);
6475 if (!devlink || !devlink->ops->flash_update) 6595 if (!devlink || !devlink->ops->flash_update) {
6476 goto unlock_list; 6596 ret = -EOPNOTSUPP;
6597 goto out;
6598 }
6477 6599
6478 mutex_lock(&devlink->lock); 6600 mutex_lock(&devlink->lock);
6479 ret = devlink->ops->flash_update(devlink, file_name, NULL, NULL); 6601 ret = devlink->ops->flash_update(devlink, file_name, NULL, NULL);
6480 mutex_unlock(&devlink->lock); 6602 mutex_unlock(&devlink->lock);
6481unlock_list:
6482 mutex_unlock(&devlink_mutex);
6483 6603
6604out:
6484 rtnl_lock(); 6605 rtnl_lock();
6485 dev_put(dev); 6606 dev_put(dev);
6486 6607
6487 return ret; 6608 return ret;
6488} 6609}
6489 6610
6611int devlink_compat_phys_port_name_get(struct net_device *dev,
6612 char *name, size_t len)
6613{
6614 struct devlink_port *devlink_port;
6615
6616 /* RTNL mutex is held here which ensures that devlink_port
6617 * instance cannot disappear in the middle. No need to take
6618 * any devlink lock as only permanent values are accessed.
6619 */
6620 ASSERT_RTNL();
6621
6622 devlink_port = netdev_to_devlink_port(dev);
6623 if (!devlink_port)
6624 return -EOPNOTSUPP;
6625
6626 return __devlink_port_phys_port_name_get(devlink_port, name, len);
6627}
6628
6629int devlink_compat_switch_id_get(struct net_device *dev,
6630 struct netdev_phys_item_id *ppid)
6631{
6632 struct devlink_port *devlink_port;
6633
6634 /* RTNL mutex is held here which ensures that devlink_port
6635 * instance cannot disappear in the middle. No need to take
6636 * any devlink lock as only permanent values are accessed.
6637 */
6638 ASSERT_RTNL();
6639 devlink_port = netdev_to_devlink_port(dev);
6640 if (!devlink_port || !devlink_port->attrs.switch_port)
6641 return -EOPNOTSUPP;
6642
6643 memcpy(ppid, &devlink_port->attrs.switch_id, sizeof(*ppid));
6644
6645 return 0;
6646}
6647
6490static int __init devlink_init(void) 6648static int __init devlink_init(void)
6491{ 6649{
6492 return genl_register_family(&devlink_nl_family); 6650 return genl_register_family(&devlink_nl_family);
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index c7785efeea57..d4ce0542acfa 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -355,14 +355,17 @@ out:
355static const struct genl_ops dropmon_ops[] = { 355static const struct genl_ops dropmon_ops[] = {
356 { 356 {
357 .cmd = NET_DM_CMD_CONFIG, 357 .cmd = NET_DM_CMD_CONFIG,
358 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
358 .doit = net_dm_cmd_config, 359 .doit = net_dm_cmd_config,
359 }, 360 },
360 { 361 {
361 .cmd = NET_DM_CMD_START, 362 .cmd = NET_DM_CMD_START,
363 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
362 .doit = net_dm_cmd_trace, 364 .doit = net_dm_cmd_trace,
363 }, 365 },
364 { 366 {
365 .cmd = NET_DM_CMD_STOP, 367 .cmd = NET_DM_CMD_STOP,
368 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
366 .doit = net_dm_cmd_trace, 369 .doit = net_dm_cmd_trace,
367 }, 370 },
368}; 371};
diff --git a/net/core/dst.c b/net/core/dst.c
index a263309df115..1f13d90cd0e4 100644
--- a/net/core/dst.c
+++ b/net/core/dst.c
@@ -26,23 +26,6 @@
26#include <net/dst.h> 26#include <net/dst.h>
27#include <net/dst_metadata.h> 27#include <net/dst_metadata.h>
28 28
29/*
30 * Theory of operations:
31 * 1) We use a list, protected by a spinlock, to add
32 * new entries from both BH and non-BH context.
33 * 2) In order to keep spinlock held for a small delay,
34 * we use a second list where are stored long lived
35 * entries, that are handled by the garbage collect thread
36 * fired by a workqueue.
37 * 3) This list is guarded by a mutex,
38 * so that the gc_task and dst_dev_event() can be synchronized.
39 */
40
41/*
42 * We want to keep lock & list close together
43 * to dirty as few cache lines as possible in __dst_free().
44 * As this is not a very strong hint, we dont force an alignment on SMP.
45 */
46int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb) 29int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb)
47{ 30{
48 kfree_skb(skb); 31 kfree_skb(skb);
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 36ed619faf36..4a593853cbf2 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -136,6 +136,7 @@ static const char
136phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = { 136phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
137 [ETHTOOL_ID_UNSPEC] = "Unspec", 137 [ETHTOOL_ID_UNSPEC] = "Unspec",
138 [ETHTOOL_PHY_DOWNSHIFT] = "phy-downshift", 138 [ETHTOOL_PHY_DOWNSHIFT] = "phy-downshift",
139 [ETHTOOL_PHY_FAST_LINK_DOWN] = "phy-fast-link-down",
139}; 140};
140 141
141static int ethtool_get_features(struct net_device *dev, void __user *useraddr) 142static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
@@ -2446,6 +2447,7 @@ static int ethtool_phy_tunable_valid(const struct ethtool_tunable *tuna)
2446{ 2447{
2447 switch (tuna->id) { 2448 switch (tuna->id) {
2448 case ETHTOOL_PHY_DOWNSHIFT: 2449 case ETHTOOL_PHY_DOWNSHIFT:
2450 case ETHTOOL_PHY_FAST_LINK_DOWN:
2449 if (tuna->len != sizeof(u8) || 2451 if (tuna->len != sizeof(u8) ||
2450 tuna->type_id != ETHTOOL_TUNABLE_U8) 2452 tuna->type_id != ETHTOOL_TUNABLE_U8)
2451 return -EINVAL; 2453 return -EINVAL;
diff --git a/net/core/failover.c b/net/core/failover.c
index 4a92a98ccce9..b5cd3c727285 100644
--- a/net/core/failover.c
+++ b/net/core/failover.c
@@ -80,14 +80,14 @@ static int failover_slave_register(struct net_device *slave_dev)
80 goto err_upper_link; 80 goto err_upper_link;
81 } 81 }
82 82
83 slave_dev->priv_flags |= IFF_FAILOVER_SLAVE; 83 slave_dev->priv_flags |= (IFF_FAILOVER_SLAVE | IFF_LIVE_RENAME_OK);
84 84
85 if (fops && fops->slave_register && 85 if (fops && fops->slave_register &&
86 !fops->slave_register(slave_dev, failover_dev)) 86 !fops->slave_register(slave_dev, failover_dev))
87 return NOTIFY_OK; 87 return NOTIFY_OK;
88 88
89 netdev_upper_dev_unlink(slave_dev, failover_dev); 89 netdev_upper_dev_unlink(slave_dev, failover_dev);
90 slave_dev->priv_flags &= ~IFF_FAILOVER_SLAVE; 90 slave_dev->priv_flags &= ~(IFF_FAILOVER_SLAVE | IFF_LIVE_RENAME_OK);
91err_upper_link: 91err_upper_link:
92 netdev_rx_handler_unregister(slave_dev); 92 netdev_rx_handler_unregister(slave_dev);
93done: 93done:
@@ -121,7 +121,7 @@ int failover_slave_unregister(struct net_device *slave_dev)
121 121
122 netdev_rx_handler_unregister(slave_dev); 122 netdev_rx_handler_unregister(slave_dev);
123 netdev_upper_dev_unlink(slave_dev, failover_dev); 123 netdev_upper_dev_unlink(slave_dev, failover_dev);
124 slave_dev->priv_flags &= ~IFF_FAILOVER_SLAVE; 124 slave_dev->priv_flags &= ~(IFF_FAILOVER_SLAVE | IFF_LIVE_RENAME_OK);
125 125
126 if (fops && fops->slave_unregister && 126 if (fops && fops->slave_unregister &&
127 !fops->slave_unregister(slave_dev, failover_dev)) 127 !fops->slave_unregister(slave_dev, failover_dev))
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index ffbb827723a2..43f0115cce9c 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -746,7 +746,8 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
746 goto errout; 746 goto errout;
747 } 747 }
748 748
749 err = nlmsg_parse(nlh, sizeof(*frh), tb, FRA_MAX, ops->policy, extack); 749 err = nlmsg_parse_deprecated(nlh, sizeof(*frh), tb, FRA_MAX,
750 ops->policy, extack);
750 if (err < 0) { 751 if (err < 0) {
751 NL_SET_ERR_MSG(extack, "Error parsing msg"); 752 NL_SET_ERR_MSG(extack, "Error parsing msg");
752 goto errout; 753 goto errout;
@@ -756,9 +757,9 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
756 if (err) 757 if (err)
757 goto errout; 758 goto errout;
758 759
759 if ((nlh->nlmsg_flags & NLM_F_EXCL) && 760 if (rule_exists(ops, frh, tb, rule)) {
760 rule_exists(ops, frh, tb, rule)) { 761 if (nlh->nlmsg_flags & NLM_F_EXCL)
761 err = -EEXIST; 762 err = -EEXIST;
762 goto errout_free; 763 goto errout_free;
763 } 764 }
764 765
@@ -853,7 +854,8 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
853 goto errout; 854 goto errout;
854 } 855 }
855 856
856 err = nlmsg_parse(nlh, sizeof(*frh), tb, FRA_MAX, ops->policy, extack); 857 err = nlmsg_parse_deprecated(nlh, sizeof(*frh), tb, FRA_MAX,
858 ops->policy, extack);
857 if (err < 0) { 859 if (err < 0) {
858 NL_SET_ERR_MSG(extack, "Error parsing msg"); 860 NL_SET_ERR_MSG(extack, "Error parsing msg");
859 goto errout; 861 goto errout;
diff --git a/net/core/filter.c b/net/core/filter.c
index fc92ebc4e200..55bfc941d17a 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -74,6 +74,8 @@
74#include <net/seg6.h> 74#include <net/seg6.h>
75#include <net/seg6_local.h> 75#include <net/seg6_local.h>
76#include <net/lwtunnel.h> 76#include <net/lwtunnel.h>
77#include <net/ipv6_stubs.h>
78#include <net/bpf_sk_storage.h>
77 79
78/** 80/**
79 * sk_filter_trim_cap - run a packet through a socket filter 81 * sk_filter_trim_cap - run a packet through a socket filter
@@ -1729,6 +1731,40 @@ static const struct bpf_func_proto bpf_skb_load_bytes_proto = {
1729 .arg4_type = ARG_CONST_SIZE, 1731 .arg4_type = ARG_CONST_SIZE,
1730}; 1732};
1731 1733
1734BPF_CALL_4(bpf_flow_dissector_load_bytes,
1735 const struct bpf_flow_dissector *, ctx, u32, offset,
1736 void *, to, u32, len)
1737{
1738 void *ptr;
1739
1740 if (unlikely(offset > 0xffff))
1741 goto err_clear;
1742
1743 if (unlikely(!ctx->skb))
1744 goto err_clear;
1745
1746 ptr = skb_header_pointer(ctx->skb, offset, len, to);
1747 if (unlikely(!ptr))
1748 goto err_clear;
1749 if (ptr != to)
1750 memcpy(to, ptr, len);
1751
1752 return 0;
1753err_clear:
1754 memset(to, 0, len);
1755 return -EFAULT;
1756}
1757
1758static const struct bpf_func_proto bpf_flow_dissector_load_bytes_proto = {
1759 .func = bpf_flow_dissector_load_bytes,
1760 .gpl_only = false,
1761 .ret_type = RET_INTEGER,
1762 .arg1_type = ARG_PTR_TO_CTX,
1763 .arg2_type = ARG_ANYTHING,
1764 .arg3_type = ARG_PTR_TO_UNINIT_MEM,
1765 .arg4_type = ARG_CONST_SIZE,
1766};
1767
1732BPF_CALL_5(bpf_skb_load_bytes_relative, const struct sk_buff *, skb, 1768BPF_CALL_5(bpf_skb_load_bytes_relative, const struct sk_buff *, skb,
1733 u32, offset, void *, to, u32, len, u32, start_header) 1769 u32, offset, void *, to, u32, len, u32, start_header)
1734{ 1770{
@@ -2015,7 +2051,7 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)
2015{ 2051{
2016 int ret; 2052 int ret;
2017 2053
2018 if (unlikely(__this_cpu_read(xmit_recursion) > XMIT_RECURSION_LIMIT)) { 2054 if (dev_xmit_recursion()) {
2019 net_crit_ratelimited("bpf: recursion limit reached on datapath, buggy bpf program?\n"); 2055 net_crit_ratelimited("bpf: recursion limit reached on datapath, buggy bpf program?\n");
2020 kfree_skb(skb); 2056 kfree_skb(skb);
2021 return -ENETDOWN; 2057 return -ENETDOWN;
@@ -2023,9 +2059,9 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)
2023 2059
2024 skb->dev = dev; 2060 skb->dev = dev;
2025 2061
2026 __this_cpu_inc(xmit_recursion); 2062 dev_xmit_recursion_inc();
2027 ret = dev_queue_xmit(skb); 2063 ret = dev_queue_xmit(skb);
2028 __this_cpu_dec(xmit_recursion); 2064 dev_xmit_recursion_dec();
2029 2065
2030 return ret; 2066 return ret;
2031} 2067}
@@ -2963,42 +2999,128 @@ static u32 bpf_skb_net_base_len(const struct sk_buff *skb)
2963 } 2999 }
2964} 3000}
2965 3001
2966static int bpf_skb_net_grow(struct sk_buff *skb, u32 len_diff) 3002#define BPF_F_ADJ_ROOM_ENCAP_L3_MASK (BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 | \
3003 BPF_F_ADJ_ROOM_ENCAP_L3_IPV6)
3004
3005#define BPF_F_ADJ_ROOM_MASK (BPF_F_ADJ_ROOM_FIXED_GSO | \
3006 BPF_F_ADJ_ROOM_ENCAP_L3_MASK | \
3007 BPF_F_ADJ_ROOM_ENCAP_L4_GRE | \
3008 BPF_F_ADJ_ROOM_ENCAP_L4_UDP | \
3009 BPF_F_ADJ_ROOM_ENCAP_L2( \
3010 BPF_ADJ_ROOM_ENCAP_L2_MASK))
3011
3012static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
3013 u64 flags)
2967{ 3014{
2968 u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb); 3015 u8 inner_mac_len = flags >> BPF_ADJ_ROOM_ENCAP_L2_SHIFT;
3016 bool encap = flags & BPF_F_ADJ_ROOM_ENCAP_L3_MASK;
3017 u16 mac_len = 0, inner_net = 0, inner_trans = 0;
3018 unsigned int gso_type = SKB_GSO_DODGY;
2969 int ret; 3019 int ret;
2970 3020
2971 if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) 3021 if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) {
2972 return -ENOTSUPP; 3022 /* udp gso_size delineates datagrams, only allow if fixed */
3023 if (!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) ||
3024 !(flags & BPF_F_ADJ_ROOM_FIXED_GSO))
3025 return -ENOTSUPP;
3026 }
2973 3027
2974 ret = skb_cow(skb, len_diff); 3028 ret = skb_cow_head(skb, len_diff);
2975 if (unlikely(ret < 0)) 3029 if (unlikely(ret < 0))
2976 return ret; 3030 return ret;
2977 3031
3032 if (encap) {
3033 if (skb->protocol != htons(ETH_P_IP) &&
3034 skb->protocol != htons(ETH_P_IPV6))
3035 return -ENOTSUPP;
3036
3037 if (flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 &&
3038 flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV6)
3039 return -EINVAL;
3040
3041 if (flags & BPF_F_ADJ_ROOM_ENCAP_L4_GRE &&
3042 flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP)
3043 return -EINVAL;
3044
3045 if (skb->encapsulation)
3046 return -EALREADY;
3047
3048 mac_len = skb->network_header - skb->mac_header;
3049 inner_net = skb->network_header;
3050 if (inner_mac_len > len_diff)
3051 return -EINVAL;
3052 inner_trans = skb->transport_header;
3053 }
3054
2978 ret = bpf_skb_net_hdr_push(skb, off, len_diff); 3055 ret = bpf_skb_net_hdr_push(skb, off, len_diff);
2979 if (unlikely(ret < 0)) 3056 if (unlikely(ret < 0))
2980 return ret; 3057 return ret;
2981 3058
3059 if (encap) {
3060 skb->inner_mac_header = inner_net - inner_mac_len;
3061 skb->inner_network_header = inner_net;
3062 skb->inner_transport_header = inner_trans;
3063 skb_set_inner_protocol(skb, skb->protocol);
3064
3065 skb->encapsulation = 1;
3066 skb_set_network_header(skb, mac_len);
3067
3068 if (flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP)
3069 gso_type |= SKB_GSO_UDP_TUNNEL;
3070 else if (flags & BPF_F_ADJ_ROOM_ENCAP_L4_GRE)
3071 gso_type |= SKB_GSO_GRE;
3072 else if (flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV6)
3073 gso_type |= SKB_GSO_IPXIP6;
3074 else if (flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV4)
3075 gso_type |= SKB_GSO_IPXIP4;
3076
3077 if (flags & BPF_F_ADJ_ROOM_ENCAP_L4_GRE ||
3078 flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP) {
3079 int nh_len = flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV6 ?
3080 sizeof(struct ipv6hdr) :
3081 sizeof(struct iphdr);
3082
3083 skb_set_transport_header(skb, mac_len + nh_len);
3084 }
3085
3086 /* Match skb->protocol to new outer l3 protocol */
3087 if (skb->protocol == htons(ETH_P_IP) &&
3088 flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV6)
3089 skb->protocol = htons(ETH_P_IPV6);
3090 else if (skb->protocol == htons(ETH_P_IPV6) &&
3091 flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV4)
3092 skb->protocol = htons(ETH_P_IP);
3093 }
3094
2982 if (skb_is_gso(skb)) { 3095 if (skb_is_gso(skb)) {
2983 struct skb_shared_info *shinfo = skb_shinfo(skb); 3096 struct skb_shared_info *shinfo = skb_shinfo(skb);
2984 3097
2985 /* Due to header grow, MSS needs to be downgraded. */ 3098 /* Due to header grow, MSS needs to be downgraded. */
2986 skb_decrease_gso_size(shinfo, len_diff); 3099 if (!(flags & BPF_F_ADJ_ROOM_FIXED_GSO))
3100 skb_decrease_gso_size(shinfo, len_diff);
3101
2987 /* Header must be checked, and gso_segs recomputed. */ 3102 /* Header must be checked, and gso_segs recomputed. */
2988 shinfo->gso_type |= SKB_GSO_DODGY; 3103 shinfo->gso_type |= gso_type;
2989 shinfo->gso_segs = 0; 3104 shinfo->gso_segs = 0;
2990 } 3105 }
2991 3106
2992 return 0; 3107 return 0;
2993} 3108}
2994 3109
2995static int bpf_skb_net_shrink(struct sk_buff *skb, u32 len_diff) 3110static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff,
3111 u64 flags)
2996{ 3112{
2997 u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb);
2998 int ret; 3113 int ret;
2999 3114
3000 if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) 3115 if (flags & ~BPF_F_ADJ_ROOM_FIXED_GSO)
3001 return -ENOTSUPP; 3116 return -EINVAL;
3117
3118 if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) {
3119 /* udp gso_size delineates datagrams, only allow if fixed */
3120 if (!(skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) ||
3121 !(flags & BPF_F_ADJ_ROOM_FIXED_GSO))
3122 return -ENOTSUPP;
3123 }
3002 3124
3003 ret = skb_unclone(skb, GFP_ATOMIC); 3125 ret = skb_unclone(skb, GFP_ATOMIC);
3004 if (unlikely(ret < 0)) 3126 if (unlikely(ret < 0))
@@ -3012,7 +3134,9 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 len_diff)
3012 struct skb_shared_info *shinfo = skb_shinfo(skb); 3134 struct skb_shared_info *shinfo = skb_shinfo(skb);
3013 3135
3014 /* Due to header shrink, MSS can be upgraded. */ 3136 /* Due to header shrink, MSS can be upgraded. */
3015 skb_increase_gso_size(shinfo, len_diff); 3137 if (!(flags & BPF_F_ADJ_ROOM_FIXED_GSO))
3138 skb_increase_gso_size(shinfo, len_diff);
3139
3016 /* Header must be checked, and gso_segs recomputed. */ 3140 /* Header must be checked, and gso_segs recomputed. */
3017 shinfo->gso_type |= SKB_GSO_DODGY; 3141 shinfo->gso_type |= SKB_GSO_DODGY;
3018 shinfo->gso_segs = 0; 3142 shinfo->gso_segs = 0;
@@ -3027,49 +3151,50 @@ static u32 __bpf_skb_max_len(const struct sk_buff *skb)
3027 SKB_MAX_ALLOC; 3151 SKB_MAX_ALLOC;
3028} 3152}
3029 3153
3030static int bpf_skb_adjust_net(struct sk_buff *skb, s32 len_diff) 3154BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *, skb, s32, len_diff,
3155 u32, mode, u64, flags)
3031{ 3156{
3032 bool trans_same = skb->transport_header == skb->network_header;
3033 u32 len_cur, len_diff_abs = abs(len_diff); 3157 u32 len_cur, len_diff_abs = abs(len_diff);
3034 u32 len_min = bpf_skb_net_base_len(skb); 3158 u32 len_min = bpf_skb_net_base_len(skb);
3035 u32 len_max = __bpf_skb_max_len(skb); 3159 u32 len_max = __bpf_skb_max_len(skb);
3036 __be16 proto = skb->protocol; 3160 __be16 proto = skb->protocol;
3037 bool shrink = len_diff < 0; 3161 bool shrink = len_diff < 0;
3162 u32 off;
3038 int ret; 3163 int ret;
3039 3164
3165 if (unlikely(flags & ~BPF_F_ADJ_ROOM_MASK))
3166 return -EINVAL;
3040 if (unlikely(len_diff_abs > 0xfffU)) 3167 if (unlikely(len_diff_abs > 0xfffU))
3041 return -EFAULT; 3168 return -EFAULT;
3042 if (unlikely(proto != htons(ETH_P_IP) && 3169 if (unlikely(proto != htons(ETH_P_IP) &&
3043 proto != htons(ETH_P_IPV6))) 3170 proto != htons(ETH_P_IPV6)))
3044 return -ENOTSUPP; 3171 return -ENOTSUPP;
3045 3172
3173 off = skb_mac_header_len(skb);
3174 switch (mode) {
3175 case BPF_ADJ_ROOM_NET:
3176 off += bpf_skb_net_base_len(skb);
3177 break;
3178 case BPF_ADJ_ROOM_MAC:
3179 break;
3180 default:
3181 return -ENOTSUPP;
3182 }
3183
3046 len_cur = skb->len - skb_network_offset(skb); 3184 len_cur = skb->len - skb_network_offset(skb);
3047 if (skb_transport_header_was_set(skb) && !trans_same)
3048 len_cur = skb_network_header_len(skb);
3049 if ((shrink && (len_diff_abs >= len_cur || 3185 if ((shrink && (len_diff_abs >= len_cur ||
3050 len_cur - len_diff_abs < len_min)) || 3186 len_cur - len_diff_abs < len_min)) ||
3051 (!shrink && (skb->len + len_diff_abs > len_max && 3187 (!shrink && (skb->len + len_diff_abs > len_max &&
3052 !skb_is_gso(skb)))) 3188 !skb_is_gso(skb))))
3053 return -ENOTSUPP; 3189 return -ENOTSUPP;
3054 3190
3055 ret = shrink ? bpf_skb_net_shrink(skb, len_diff_abs) : 3191 ret = shrink ? bpf_skb_net_shrink(skb, off, len_diff_abs, flags) :
3056 bpf_skb_net_grow(skb, len_diff_abs); 3192 bpf_skb_net_grow(skb, off, len_diff_abs, flags);
3057 3193
3058 bpf_compute_data_pointers(skb); 3194 bpf_compute_data_pointers(skb);
3059 return ret; 3195 return ret;
3060} 3196}
3061 3197
3062BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *, skb, s32, len_diff,
3063 u32, mode, u64, flags)
3064{
3065 if (unlikely(flags))
3066 return -EINVAL;
3067 if (likely(mode == BPF_ADJ_ROOM_NET))
3068 return bpf_skb_adjust_net(skb, len_diff);
3069
3070 return -ENOTSUPP;
3071}
3072
3073static const struct bpf_func_proto bpf_skb_adjust_room_proto = { 3198static const struct bpf_func_proto bpf_skb_adjust_room_proto = {
3074 .func = bpf_skb_adjust_room, 3199 .func = bpf_skb_adjust_room,
3075 .gpl_only = false, 3200 .gpl_only = false,
@@ -4355,8 +4480,7 @@ BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,
4355 if (!IS_ENABLED(CONFIG_INET) || !sk_fullsock(sk)) 4480 if (!IS_ENABLED(CONFIG_INET) || !sk_fullsock(sk))
4356 return -EINVAL; 4481 return -EINVAL;
4357 4482
4358 if (val) 4483 tcp_sk(sk)->bpf_sock_ops_cb_flags = val;
4359 tcp_sk(sk)->bpf_sock_ops_cb_flags = val;
4360 4484
4361 return argval & (~BPF_SOCK_OPS_ALL_CB_FLAGS); 4485 return argval & (~BPF_SOCK_OPS_ALL_CB_FLAGS);
4362} 4486}
@@ -4383,6 +4507,8 @@ BPF_CALL_3(bpf_bind, struct bpf_sock_addr_kern *, ctx, struct sockaddr *, addr,
4383 * Only binding to IP is supported. 4507 * Only binding to IP is supported.
4384 */ 4508 */
4385 err = -EINVAL; 4509 err = -EINVAL;
4510 if (addr_len < offsetofend(struct sockaddr, sa_family))
4511 return err;
4386 if (addr->sa_family == AF_INET) { 4512 if (addr->sa_family == AF_INET) {
4387 if (addr_len < sizeof(struct sockaddr_in)) 4513 if (addr_len < sizeof(struct sockaddr_in))
4388 return err; 4514 return err;
@@ -4480,11 +4606,11 @@ static int bpf_fib_set_fwd_params(struct bpf_fib_lookup *params,
4480static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params, 4606static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
4481 u32 flags, bool check_mtu) 4607 u32 flags, bool check_mtu)
4482{ 4608{
4609 struct fib_nh_common *nhc;
4483 struct in_device *in_dev; 4610 struct in_device *in_dev;
4484 struct neighbour *neigh; 4611 struct neighbour *neigh;
4485 struct net_device *dev; 4612 struct net_device *dev;
4486 struct fib_result res; 4613 struct fib_result res;
4487 struct fib_nh *nh;
4488 struct flowi4 fl4; 4614 struct flowi4 fl4;
4489 int err; 4615 int err;
4490 u32 mtu; 4616 u32 mtu;
@@ -4557,22 +4683,33 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
4557 return BPF_FIB_LKUP_RET_FRAG_NEEDED; 4683 return BPF_FIB_LKUP_RET_FRAG_NEEDED;
4558 } 4684 }
4559 4685
4560 nh = &res.fi->fib_nh[res.nh_sel]; 4686 nhc = res.nhc;
4561 4687
4562 /* do not handle lwt encaps right now */ 4688 /* do not handle lwt encaps right now */
4563 if (nh->nh_lwtstate) 4689 if (nhc->nhc_lwtstate)
4564 return BPF_FIB_LKUP_RET_UNSUPP_LWT; 4690 return BPF_FIB_LKUP_RET_UNSUPP_LWT;
4565 4691
4566 dev = nh->nh_dev; 4692 dev = nhc->nhc_dev;
4567 if (nh->nh_gw)
4568 params->ipv4_dst = nh->nh_gw;
4569 4693
4570 params->rt_metric = res.fi->fib_priority; 4694 params->rt_metric = res.fi->fib_priority;
4571 4695
4572 /* xdp and cls_bpf programs are run in RCU-bh so 4696 /* xdp and cls_bpf programs are run in RCU-bh so
4573 * rcu_read_lock_bh is not needed here 4697 * rcu_read_lock_bh is not needed here
4574 */ 4698 */
4575 neigh = __ipv4_neigh_lookup_noref(dev, (__force u32)params->ipv4_dst); 4699 if (likely(nhc->nhc_gw_family != AF_INET6)) {
4700 if (nhc->nhc_gw_family)
4701 params->ipv4_dst = nhc->nhc_gw.ipv4;
4702
4703 neigh = __ipv4_neigh_lookup_noref(dev,
4704 (__force u32)params->ipv4_dst);
4705 } else {
4706 struct in6_addr *dst = (struct in6_addr *)params->ipv6_dst;
4707
4708 params->family = AF_INET6;
4709 *dst = nhc->nhc_gw.ipv6;
4710 neigh = __ipv6_neigh_lookup_noref_stub(dev, dst);
4711 }
4712
4576 if (!neigh) 4713 if (!neigh)
4577 return BPF_FIB_LKUP_RET_NO_NEIGH; 4714 return BPF_FIB_LKUP_RET_NO_NEIGH;
4578 4715
@@ -4586,13 +4723,13 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
4586{ 4723{
4587 struct in6_addr *src = (struct in6_addr *) params->ipv6_src; 4724 struct in6_addr *src = (struct in6_addr *) params->ipv6_src;
4588 struct in6_addr *dst = (struct in6_addr *) params->ipv6_dst; 4725 struct in6_addr *dst = (struct in6_addr *) params->ipv6_dst;
4726 struct fib6_result res = {};
4589 struct neighbour *neigh; 4727 struct neighbour *neigh;
4590 struct net_device *dev; 4728 struct net_device *dev;
4591 struct inet6_dev *idev; 4729 struct inet6_dev *idev;
4592 struct fib6_info *f6i;
4593 struct flowi6 fl6; 4730 struct flowi6 fl6;
4594 int strict = 0; 4731 int strict = 0;
4595 int oif; 4732 int oif, err;
4596 u32 mtu; 4733 u32 mtu;
4597 4734
4598 /* link local addresses are never forwarded */ 4735 /* link local addresses are never forwarded */
@@ -4634,61 +4771,57 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
4634 if (unlikely(!tb)) 4771 if (unlikely(!tb))
4635 return BPF_FIB_LKUP_RET_NOT_FWDED; 4772 return BPF_FIB_LKUP_RET_NOT_FWDED;
4636 4773
4637 f6i = ipv6_stub->fib6_table_lookup(net, tb, oif, &fl6, strict); 4774 err = ipv6_stub->fib6_table_lookup(net, tb, oif, &fl6, &res,
4775 strict);
4638 } else { 4776 } else {
4639 fl6.flowi6_mark = 0; 4777 fl6.flowi6_mark = 0;
4640 fl6.flowi6_secid = 0; 4778 fl6.flowi6_secid = 0;
4641 fl6.flowi6_tun_key.tun_id = 0; 4779 fl6.flowi6_tun_key.tun_id = 0;
4642 fl6.flowi6_uid = sock_net_uid(net, NULL); 4780 fl6.flowi6_uid = sock_net_uid(net, NULL);
4643 4781
4644 f6i = ipv6_stub->fib6_lookup(net, oif, &fl6, strict); 4782 err = ipv6_stub->fib6_lookup(net, oif, &fl6, &res, strict);
4645 } 4783 }
4646 4784
4647 if (unlikely(IS_ERR_OR_NULL(f6i) || f6i == net->ipv6.fib6_null_entry)) 4785 if (unlikely(err || IS_ERR_OR_NULL(res.f6i) ||
4786 res.f6i == net->ipv6.fib6_null_entry))
4648 return BPF_FIB_LKUP_RET_NOT_FWDED; 4787 return BPF_FIB_LKUP_RET_NOT_FWDED;
4649 4788
4650 if (unlikely(f6i->fib6_flags & RTF_REJECT)) { 4789 switch (res.fib6_type) {
4651 switch (f6i->fib6_type) { 4790 /* only unicast is forwarded */
4652 case RTN_BLACKHOLE: 4791 case RTN_UNICAST:
4653 return BPF_FIB_LKUP_RET_BLACKHOLE; 4792 break;
4654 case RTN_UNREACHABLE: 4793 case RTN_BLACKHOLE:
4655 return BPF_FIB_LKUP_RET_UNREACHABLE; 4794 return BPF_FIB_LKUP_RET_BLACKHOLE;
4656 case RTN_PROHIBIT: 4795 case RTN_UNREACHABLE:
4657 return BPF_FIB_LKUP_RET_PROHIBIT; 4796 return BPF_FIB_LKUP_RET_UNREACHABLE;
4658 default: 4797 case RTN_PROHIBIT:
4659 return BPF_FIB_LKUP_RET_NOT_FWDED; 4798 return BPF_FIB_LKUP_RET_PROHIBIT;
4660 } 4799 default:
4661 }
4662
4663 if (f6i->fib6_type != RTN_UNICAST)
4664 return BPF_FIB_LKUP_RET_NOT_FWDED; 4800 return BPF_FIB_LKUP_RET_NOT_FWDED;
4801 }
4665 4802
4666 if (f6i->fib6_nsiblings && fl6.flowi6_oif == 0) 4803 ipv6_stub->fib6_select_path(net, &res, &fl6, fl6.flowi6_oif,
4667 f6i = ipv6_stub->fib6_multipath_select(net, f6i, &fl6, 4804 fl6.flowi6_oif != 0, NULL, strict);
4668 fl6.flowi6_oif, NULL,
4669 strict);
4670 4805
4671 if (check_mtu) { 4806 if (check_mtu) {
4672 mtu = ipv6_stub->ip6_mtu_from_fib6(f6i, dst, src); 4807 mtu = ipv6_stub->ip6_mtu_from_fib6(&res, dst, src);
4673 if (params->tot_len > mtu) 4808 if (params->tot_len > mtu)
4674 return BPF_FIB_LKUP_RET_FRAG_NEEDED; 4809 return BPF_FIB_LKUP_RET_FRAG_NEEDED;
4675 } 4810 }
4676 4811
4677 if (f6i->fib6_nh.nh_lwtstate) 4812 if (res.nh->fib_nh_lws)
4678 return BPF_FIB_LKUP_RET_UNSUPP_LWT; 4813 return BPF_FIB_LKUP_RET_UNSUPP_LWT;
4679 4814
4680 if (f6i->fib6_flags & RTF_GATEWAY) 4815 if (res.nh->fib_nh_gw_family)
4681 *dst = f6i->fib6_nh.nh_gw; 4816 *dst = res.nh->fib_nh_gw6;
4682 4817
4683 dev = f6i->fib6_nh.nh_dev; 4818 dev = res.nh->fib_nh_dev;
4684 params->rt_metric = f6i->fib6_metric; 4819 params->rt_metric = res.f6i->fib6_metric;
4685 4820
4686 /* xdp and cls_bpf programs are run in RCU-bh so rcu_read_lock_bh is 4821 /* xdp and cls_bpf programs are run in RCU-bh so rcu_read_lock_bh is
4687 * not needed here. Can not use __ipv6_neigh_lookup_noref here 4822 * not needed here.
4688 * because we need to get nd_tbl via the stub
4689 */ 4823 */
4690 neigh = ___neigh_lookup_noref(ipv6_stub->nd_tbl, neigh_key_eq128, 4824 neigh = __ipv6_neigh_lookup_noref_stub(dev, dst);
4691 ndisc_hashfn, dst, dev);
4692 if (!neigh) 4825 if (!neigh)
4693 return BPF_FIB_LKUP_RET_NO_NEIGH; 4826 return BPF_FIB_LKUP_RET_NO_NEIGH;
4694 4827
@@ -5156,15 +5289,15 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
5156 return sk; 5289 return sk;
5157} 5290}
5158 5291
5159/* bpf_sk_lookup performs the core lookup for different types of sockets, 5292/* bpf_skc_lookup performs the core lookup for different types of sockets,
5160 * taking a reference on the socket if it doesn't have the flag SOCK_RCU_FREE. 5293 * taking a reference on the socket if it doesn't have the flag SOCK_RCU_FREE.
5161 * Returns the socket as an 'unsigned long' to simplify the casting in the 5294 * Returns the socket as an 'unsigned long' to simplify the casting in the
5162 * callers to satisfy BPF_CALL declarations. 5295 * callers to satisfy BPF_CALL declarations.
5163 */ 5296 */
5164static unsigned long 5297static struct sock *
5165__bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len, 5298__bpf_skc_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
5166 struct net *caller_net, u32 ifindex, u8 proto, u64 netns_id, 5299 struct net *caller_net, u32 ifindex, u8 proto, u64 netns_id,
5167 u64 flags) 5300 u64 flags)
5168{ 5301{
5169 struct sock *sk = NULL; 5302 struct sock *sk = NULL;
5170 u8 family = AF_UNSPEC; 5303 u8 family = AF_UNSPEC;
@@ -5192,15 +5325,27 @@ __bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
5192 put_net(net); 5325 put_net(net);
5193 } 5326 }
5194 5327
5328out:
5329 return sk;
5330}
5331
5332static struct sock *
5333__bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
5334 struct net *caller_net, u32 ifindex, u8 proto, u64 netns_id,
5335 u64 flags)
5336{
5337 struct sock *sk = __bpf_skc_lookup(skb, tuple, len, caller_net,
5338 ifindex, proto, netns_id, flags);
5339
5195 if (sk) 5340 if (sk)
5196 sk = sk_to_full_sk(sk); 5341 sk = sk_to_full_sk(sk);
5197out: 5342
5198 return (unsigned long) sk; 5343 return sk;
5199} 5344}
5200 5345
5201static unsigned long 5346static struct sock *
5202bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len, 5347bpf_skc_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
5203 u8 proto, u64 netns_id, u64 flags) 5348 u8 proto, u64 netns_id, u64 flags)
5204{ 5349{
5205 struct net *caller_net; 5350 struct net *caller_net;
5206 int ifindex; 5351 int ifindex;
@@ -5213,14 +5358,47 @@ bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
5213 ifindex = 0; 5358 ifindex = 0;
5214 } 5359 }
5215 5360
5216 return __bpf_sk_lookup(skb, tuple, len, caller_net, ifindex, 5361 return __bpf_skc_lookup(skb, tuple, len, caller_net, ifindex, proto,
5217 proto, netns_id, flags); 5362 netns_id, flags);
5218} 5363}
5219 5364
5365static struct sock *
5366bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len,
5367 u8 proto, u64 netns_id, u64 flags)
5368{
5369 struct sock *sk = bpf_skc_lookup(skb, tuple, len, proto, netns_id,
5370 flags);
5371
5372 if (sk)
5373 sk = sk_to_full_sk(sk);
5374
5375 return sk;
5376}
5377
5378BPF_CALL_5(bpf_skc_lookup_tcp, struct sk_buff *, skb,
5379 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
5380{
5381 return (unsigned long)bpf_skc_lookup(skb, tuple, len, IPPROTO_TCP,
5382 netns_id, flags);
5383}
5384
5385static const struct bpf_func_proto bpf_skc_lookup_tcp_proto = {
5386 .func = bpf_skc_lookup_tcp,
5387 .gpl_only = false,
5388 .pkt_access = true,
5389 .ret_type = RET_PTR_TO_SOCK_COMMON_OR_NULL,
5390 .arg1_type = ARG_PTR_TO_CTX,
5391 .arg2_type = ARG_PTR_TO_MEM,
5392 .arg3_type = ARG_CONST_SIZE,
5393 .arg4_type = ARG_ANYTHING,
5394 .arg5_type = ARG_ANYTHING,
5395};
5396
5220BPF_CALL_5(bpf_sk_lookup_tcp, struct sk_buff *, skb, 5397BPF_CALL_5(bpf_sk_lookup_tcp, struct sk_buff *, skb,
5221 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags) 5398 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
5222{ 5399{
5223 return bpf_sk_lookup(skb, tuple, len, IPPROTO_TCP, netns_id, flags); 5400 return (unsigned long)bpf_sk_lookup(skb, tuple, len, IPPROTO_TCP,
5401 netns_id, flags);
5224} 5402}
5225 5403
5226static const struct bpf_func_proto bpf_sk_lookup_tcp_proto = { 5404static const struct bpf_func_proto bpf_sk_lookup_tcp_proto = {
@@ -5238,7 +5416,8 @@ static const struct bpf_func_proto bpf_sk_lookup_tcp_proto = {
5238BPF_CALL_5(bpf_sk_lookup_udp, struct sk_buff *, skb, 5416BPF_CALL_5(bpf_sk_lookup_udp, struct sk_buff *, skb,
5239 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags) 5417 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
5240{ 5418{
5241 return bpf_sk_lookup(skb, tuple, len, IPPROTO_UDP, netns_id, flags); 5419 return (unsigned long)bpf_sk_lookup(skb, tuple, len, IPPROTO_UDP,
5420 netns_id, flags);
5242} 5421}
5243 5422
5244static const struct bpf_func_proto bpf_sk_lookup_udp_proto = { 5423static const struct bpf_func_proto bpf_sk_lookup_udp_proto = {
@@ -5273,8 +5452,9 @@ BPF_CALL_5(bpf_xdp_sk_lookup_udp, struct xdp_buff *, ctx,
5273 struct net *caller_net = dev_net(ctx->rxq->dev); 5452 struct net *caller_net = dev_net(ctx->rxq->dev);
5274 int ifindex = ctx->rxq->dev->ifindex; 5453 int ifindex = ctx->rxq->dev->ifindex;
5275 5454
5276 return __bpf_sk_lookup(NULL, tuple, len, caller_net, ifindex, 5455 return (unsigned long)__bpf_sk_lookup(NULL, tuple, len, caller_net,
5277 IPPROTO_UDP, netns_id, flags); 5456 ifindex, IPPROTO_UDP, netns_id,
5457 flags);
5278} 5458}
5279 5459
5280static const struct bpf_func_proto bpf_xdp_sk_lookup_udp_proto = { 5460static const struct bpf_func_proto bpf_xdp_sk_lookup_udp_proto = {
@@ -5289,14 +5469,38 @@ static const struct bpf_func_proto bpf_xdp_sk_lookup_udp_proto = {
5289 .arg5_type = ARG_ANYTHING, 5469 .arg5_type = ARG_ANYTHING,
5290}; 5470};
5291 5471
5472BPF_CALL_5(bpf_xdp_skc_lookup_tcp, struct xdp_buff *, ctx,
5473 struct bpf_sock_tuple *, tuple, u32, len, u32, netns_id, u64, flags)
5474{
5475 struct net *caller_net = dev_net(ctx->rxq->dev);
5476 int ifindex = ctx->rxq->dev->ifindex;
5477
5478 return (unsigned long)__bpf_skc_lookup(NULL, tuple, len, caller_net,
5479 ifindex, IPPROTO_TCP, netns_id,
5480 flags);
5481}
5482
5483static const struct bpf_func_proto bpf_xdp_skc_lookup_tcp_proto = {
5484 .func = bpf_xdp_skc_lookup_tcp,
5485 .gpl_only = false,
5486 .pkt_access = true,
5487 .ret_type = RET_PTR_TO_SOCK_COMMON_OR_NULL,
5488 .arg1_type = ARG_PTR_TO_CTX,
5489 .arg2_type = ARG_PTR_TO_MEM,
5490 .arg3_type = ARG_CONST_SIZE,
5491 .arg4_type = ARG_ANYTHING,
5492 .arg5_type = ARG_ANYTHING,
5493};
5494
5292BPF_CALL_5(bpf_xdp_sk_lookup_tcp, struct xdp_buff *, ctx, 5495BPF_CALL_5(bpf_xdp_sk_lookup_tcp, struct xdp_buff *, ctx,
5293 struct bpf_sock_tuple *, tuple, u32, len, u32, netns_id, u64, flags) 5496 struct bpf_sock_tuple *, tuple, u32, len, u32, netns_id, u64, flags)
5294{ 5497{
5295 struct net *caller_net = dev_net(ctx->rxq->dev); 5498 struct net *caller_net = dev_net(ctx->rxq->dev);
5296 int ifindex = ctx->rxq->dev->ifindex; 5499 int ifindex = ctx->rxq->dev->ifindex;
5297 5500
5298 return __bpf_sk_lookup(NULL, tuple, len, caller_net, ifindex, 5501 return (unsigned long)__bpf_sk_lookup(NULL, tuple, len, caller_net,
5299 IPPROTO_TCP, netns_id, flags); 5502 ifindex, IPPROTO_TCP, netns_id,
5503 flags);
5300} 5504}
5301 5505
5302static const struct bpf_func_proto bpf_xdp_sk_lookup_tcp_proto = { 5506static const struct bpf_func_proto bpf_xdp_sk_lookup_tcp_proto = {
@@ -5311,11 +5515,31 @@ static const struct bpf_func_proto bpf_xdp_sk_lookup_tcp_proto = {
5311 .arg5_type = ARG_ANYTHING, 5515 .arg5_type = ARG_ANYTHING,
5312}; 5516};
5313 5517
5518BPF_CALL_5(bpf_sock_addr_skc_lookup_tcp, struct bpf_sock_addr_kern *, ctx,
5519 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
5520{
5521 return (unsigned long)__bpf_skc_lookup(NULL, tuple, len,
5522 sock_net(ctx->sk), 0,
5523 IPPROTO_TCP, netns_id, flags);
5524}
5525
5526static const struct bpf_func_proto bpf_sock_addr_skc_lookup_tcp_proto = {
5527 .func = bpf_sock_addr_skc_lookup_tcp,
5528 .gpl_only = false,
5529 .ret_type = RET_PTR_TO_SOCK_COMMON_OR_NULL,
5530 .arg1_type = ARG_PTR_TO_CTX,
5531 .arg2_type = ARG_PTR_TO_MEM,
5532 .arg3_type = ARG_CONST_SIZE,
5533 .arg4_type = ARG_ANYTHING,
5534 .arg5_type = ARG_ANYTHING,
5535};
5536
5314BPF_CALL_5(bpf_sock_addr_sk_lookup_tcp, struct bpf_sock_addr_kern *, ctx, 5537BPF_CALL_5(bpf_sock_addr_sk_lookup_tcp, struct bpf_sock_addr_kern *, ctx,
5315 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags) 5538 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
5316{ 5539{
5317 return __bpf_sk_lookup(NULL, tuple, len, sock_net(ctx->sk), 0, 5540 return (unsigned long)__bpf_sk_lookup(NULL, tuple, len,
5318 IPPROTO_TCP, netns_id, flags); 5541 sock_net(ctx->sk), 0, IPPROTO_TCP,
5542 netns_id, flags);
5319} 5543}
5320 5544
5321static const struct bpf_func_proto bpf_sock_addr_sk_lookup_tcp_proto = { 5545static const struct bpf_func_proto bpf_sock_addr_sk_lookup_tcp_proto = {
@@ -5332,8 +5556,9 @@ static const struct bpf_func_proto bpf_sock_addr_sk_lookup_tcp_proto = {
5332BPF_CALL_5(bpf_sock_addr_sk_lookup_udp, struct bpf_sock_addr_kern *, ctx, 5556BPF_CALL_5(bpf_sock_addr_sk_lookup_udp, struct bpf_sock_addr_kern *, ctx,
5333 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags) 5557 struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
5334{ 5558{
5335 return __bpf_sk_lookup(NULL, tuple, len, sock_net(ctx->sk), 0, 5559 return (unsigned long)__bpf_sk_lookup(NULL, tuple, len,
5336 IPPROTO_UDP, netns_id, flags); 5560 sock_net(ctx->sk), 0, IPPROTO_UDP,
5561 netns_id, flags);
5337} 5562}
5338 5563
5339static const struct bpf_func_proto bpf_sock_addr_sk_lookup_udp_proto = { 5564static const struct bpf_func_proto bpf_sock_addr_sk_lookup_udp_proto = {
@@ -5461,6 +5686,74 @@ static const struct bpf_func_proto bpf_skb_ecn_set_ce_proto = {
5461 .ret_type = RET_INTEGER, 5686 .ret_type = RET_INTEGER,
5462 .arg1_type = ARG_PTR_TO_CTX, 5687 .arg1_type = ARG_PTR_TO_CTX,
5463}; 5688};
5689
5690BPF_CALL_5(bpf_tcp_check_syncookie, struct sock *, sk, void *, iph, u32, iph_len,
5691 struct tcphdr *, th, u32, th_len)
5692{
5693#ifdef CONFIG_SYN_COOKIES
5694 u32 cookie;
5695 int ret;
5696
5697 if (unlikely(th_len < sizeof(*th)))
5698 return -EINVAL;
5699
5700 /* sk_listener() allows TCP_NEW_SYN_RECV, which makes no sense here. */
5701 if (sk->sk_protocol != IPPROTO_TCP || sk->sk_state != TCP_LISTEN)
5702 return -EINVAL;
5703
5704 if (!sock_net(sk)->ipv4.sysctl_tcp_syncookies)
5705 return -EINVAL;
5706
5707 if (!th->ack || th->rst || th->syn)
5708 return -ENOENT;
5709
5710 if (tcp_synq_no_recent_overflow(sk))
5711 return -ENOENT;
5712
5713 cookie = ntohl(th->ack_seq) - 1;
5714
5715 switch (sk->sk_family) {
5716 case AF_INET:
5717 if (unlikely(iph_len < sizeof(struct iphdr)))
5718 return -EINVAL;
5719
5720 ret = __cookie_v4_check((struct iphdr *)iph, th, cookie);
5721 break;
5722
5723#if IS_BUILTIN(CONFIG_IPV6)
5724 case AF_INET6:
5725 if (unlikely(iph_len < sizeof(struct ipv6hdr)))
5726 return -EINVAL;
5727
5728 ret = __cookie_v6_check((struct ipv6hdr *)iph, th, cookie);
5729 break;
5730#endif /* CONFIG_IPV6 */
5731
5732 default:
5733 return -EPROTONOSUPPORT;
5734 }
5735
5736 if (ret > 0)
5737 return 0;
5738
5739 return -ENOENT;
5740#else
5741 return -ENOTSUPP;
5742#endif
5743}
5744
5745static const struct bpf_func_proto bpf_tcp_check_syncookie_proto = {
5746 .func = bpf_tcp_check_syncookie,
5747 .gpl_only = true,
5748 .pkt_access = true,
5749 .ret_type = RET_INTEGER,
5750 .arg1_type = ARG_PTR_TO_SOCK_COMMON,
5751 .arg2_type = ARG_PTR_TO_MEM,
5752 .arg3_type = ARG_CONST_SIZE,
5753 .arg4_type = ARG_PTR_TO_MEM,
5754 .arg5_type = ARG_CONST_SIZE,
5755};
5756
5464#endif /* CONFIG_INET */ 5757#endif /* CONFIG_INET */
5465 5758
5466bool bpf_helper_changes_pkt_data(void *func) 5759bool bpf_helper_changes_pkt_data(void *func)
@@ -5586,6 +5879,8 @@ sock_addr_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5586 return &bpf_sock_addr_sk_lookup_udp_proto; 5879 return &bpf_sock_addr_sk_lookup_udp_proto;
5587 case BPF_FUNC_sk_release: 5880 case BPF_FUNC_sk_release:
5588 return &bpf_sk_release_proto; 5881 return &bpf_sk_release_proto;
5882 case BPF_FUNC_skc_lookup_tcp:
5883 return &bpf_sock_addr_skc_lookup_tcp_proto;
5589#endif /* CONFIG_INET */ 5884#endif /* CONFIG_INET */
5590 default: 5885 default:
5591 return bpf_base_func_proto(func_id); 5886 return bpf_base_func_proto(func_id);
@@ -5609,6 +5904,9 @@ sk_filter_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5609 } 5904 }
5610} 5905}
5611 5906
5907const struct bpf_func_proto bpf_sk_storage_get_proto __weak;
5908const struct bpf_func_proto bpf_sk_storage_delete_proto __weak;
5909
5612static const struct bpf_func_proto * 5910static const struct bpf_func_proto *
5613cg_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) 5911cg_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5614{ 5912{
@@ -5617,6 +5915,10 @@ cg_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5617 return &bpf_get_local_storage_proto; 5915 return &bpf_get_local_storage_proto;
5618 case BPF_FUNC_sk_fullsock: 5916 case BPF_FUNC_sk_fullsock:
5619 return &bpf_sk_fullsock_proto; 5917 return &bpf_sk_fullsock_proto;
5918 case BPF_FUNC_sk_storage_get:
5919 return &bpf_sk_storage_get_proto;
5920 case BPF_FUNC_sk_storage_delete:
5921 return &bpf_sk_storage_delete_proto;
5620#ifdef CONFIG_INET 5922#ifdef CONFIG_INET
5621 case BPF_FUNC_tcp_sock: 5923 case BPF_FUNC_tcp_sock:
5622 return &bpf_tcp_sock_proto; 5924 return &bpf_tcp_sock_proto;
@@ -5698,6 +6000,10 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5698 return &bpf_skb_fib_lookup_proto; 6000 return &bpf_skb_fib_lookup_proto;
5699 case BPF_FUNC_sk_fullsock: 6001 case BPF_FUNC_sk_fullsock:
5700 return &bpf_sk_fullsock_proto; 6002 return &bpf_sk_fullsock_proto;
6003 case BPF_FUNC_sk_storage_get:
6004 return &bpf_sk_storage_get_proto;
6005 case BPF_FUNC_sk_storage_delete:
6006 return &bpf_sk_storage_delete_proto;
5701#ifdef CONFIG_XFRM 6007#ifdef CONFIG_XFRM
5702 case BPF_FUNC_skb_get_xfrm_state: 6008 case BPF_FUNC_skb_get_xfrm_state:
5703 return &bpf_skb_get_xfrm_state_proto; 6009 return &bpf_skb_get_xfrm_state_proto;
@@ -5719,6 +6025,12 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5719 return &bpf_tcp_sock_proto; 6025 return &bpf_tcp_sock_proto;
5720 case BPF_FUNC_get_listener_sock: 6026 case BPF_FUNC_get_listener_sock:
5721 return &bpf_get_listener_sock_proto; 6027 return &bpf_get_listener_sock_proto;
6028 case BPF_FUNC_skc_lookup_tcp:
6029 return &bpf_skc_lookup_tcp_proto;
6030 case BPF_FUNC_tcp_check_syncookie:
6031 return &bpf_tcp_check_syncookie_proto;
6032 case BPF_FUNC_skb_ecn_set_ce:
6033 return &bpf_skb_ecn_set_ce_proto;
5722#endif 6034#endif
5723 default: 6035 default:
5724 return bpf_base_func_proto(func_id); 6036 return bpf_base_func_proto(func_id);
@@ -5754,6 +6066,10 @@ xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5754 return &bpf_xdp_sk_lookup_tcp_proto; 6066 return &bpf_xdp_sk_lookup_tcp_proto;
5755 case BPF_FUNC_sk_release: 6067 case BPF_FUNC_sk_release:
5756 return &bpf_sk_release_proto; 6068 return &bpf_sk_release_proto;
6069 case BPF_FUNC_skc_lookup_tcp:
6070 return &bpf_xdp_skc_lookup_tcp_proto;
6071 case BPF_FUNC_tcp_check_syncookie:
6072 return &bpf_tcp_check_syncookie_proto;
5757#endif 6073#endif
5758 default: 6074 default:
5759 return bpf_base_func_proto(func_id); 6075 return bpf_base_func_proto(func_id);
@@ -5846,6 +6162,8 @@ sk_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5846 return &bpf_sk_lookup_udp_proto; 6162 return &bpf_sk_lookup_udp_proto;
5847 case BPF_FUNC_sk_release: 6163 case BPF_FUNC_sk_release:
5848 return &bpf_sk_release_proto; 6164 return &bpf_sk_release_proto;
6165 case BPF_FUNC_skc_lookup_tcp:
6166 return &bpf_skc_lookup_tcp_proto;
5849#endif 6167#endif
5850 default: 6168 default:
5851 return bpf_base_func_proto(func_id); 6169 return bpf_base_func_proto(func_id);
@@ -5857,7 +6175,7 @@ flow_dissector_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
5857{ 6175{
5858 switch (func_id) { 6176 switch (func_id) {
5859 case BPF_FUNC_skb_load_bytes: 6177 case BPF_FUNC_skb_load_bytes:
5860 return &bpf_skb_load_bytes_proto; 6178 return &bpf_flow_dissector_load_bytes_proto;
5861 default: 6179 default:
5862 return bpf_base_func_proto(func_id); 6180 return bpf_base_func_proto(func_id);
5863 } 6181 }
@@ -5984,9 +6302,7 @@ static bool bpf_skb_is_valid_access(int off, int size, enum bpf_access_type type
5984 return false; 6302 return false;
5985 break; 6303 break;
5986 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys): 6304 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys):
5987 if (size != sizeof(__u64)) 6305 return false;
5988 return false;
5989 break;
5990 case bpf_ctx_range(struct __sk_buff, tstamp): 6306 case bpf_ctx_range(struct __sk_buff, tstamp):
5991 if (size != sizeof(__u64)) 6307 if (size != sizeof(__u64))
5992 return false; 6308 return false;
@@ -6021,7 +6337,6 @@ static bool sk_filter_is_valid_access(int off, int size,
6021 case bpf_ctx_range(struct __sk_buff, data): 6337 case bpf_ctx_range(struct __sk_buff, data):
6022 case bpf_ctx_range(struct __sk_buff, data_meta): 6338 case bpf_ctx_range(struct __sk_buff, data_meta):
6023 case bpf_ctx_range(struct __sk_buff, data_end): 6339 case bpf_ctx_range(struct __sk_buff, data_end):
6024 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys):
6025 case bpf_ctx_range_till(struct __sk_buff, family, local_port): 6340 case bpf_ctx_range_till(struct __sk_buff, family, local_port):
6026 case bpf_ctx_range(struct __sk_buff, tstamp): 6341 case bpf_ctx_range(struct __sk_buff, tstamp):
6027 case bpf_ctx_range(struct __sk_buff, wire_len): 6342 case bpf_ctx_range(struct __sk_buff, wire_len):
@@ -6048,7 +6363,6 @@ static bool cg_skb_is_valid_access(int off, int size,
6048 switch (off) { 6363 switch (off) {
6049 case bpf_ctx_range(struct __sk_buff, tc_classid): 6364 case bpf_ctx_range(struct __sk_buff, tc_classid):
6050 case bpf_ctx_range(struct __sk_buff, data_meta): 6365 case bpf_ctx_range(struct __sk_buff, data_meta):
6051 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys):
6052 case bpf_ctx_range(struct __sk_buff, wire_len): 6366 case bpf_ctx_range(struct __sk_buff, wire_len):
6053 return false; 6367 return false;
6054 case bpf_ctx_range(struct __sk_buff, data): 6368 case bpf_ctx_range(struct __sk_buff, data):
@@ -6094,7 +6408,6 @@ static bool lwt_is_valid_access(int off, int size,
6094 case bpf_ctx_range(struct __sk_buff, tc_classid): 6408 case bpf_ctx_range(struct __sk_buff, tc_classid):
6095 case bpf_ctx_range_till(struct __sk_buff, family, local_port): 6409 case bpf_ctx_range_till(struct __sk_buff, family, local_port):
6096 case bpf_ctx_range(struct __sk_buff, data_meta): 6410 case bpf_ctx_range(struct __sk_buff, data_meta):
6097 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys):
6098 case bpf_ctx_range(struct __sk_buff, tstamp): 6411 case bpf_ctx_range(struct __sk_buff, tstamp):
6099 case bpf_ctx_range(struct __sk_buff, wire_len): 6412 case bpf_ctx_range(struct __sk_buff, wire_len):
6100 return false; 6413 return false;
@@ -6337,7 +6650,6 @@ static bool tc_cls_act_is_valid_access(int off, int size,
6337 case bpf_ctx_range(struct __sk_buff, data_end): 6650 case bpf_ctx_range(struct __sk_buff, data_end):
6338 info->reg_type = PTR_TO_PACKET_END; 6651 info->reg_type = PTR_TO_PACKET_END;
6339 break; 6652 break;
6340 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys):
6341 case bpf_ctx_range_till(struct __sk_buff, family, local_port): 6653 case bpf_ctx_range_till(struct __sk_buff, family, local_port):
6342 return false; 6654 return false;
6343 } 6655 }
@@ -6539,7 +6851,6 @@ static bool sk_skb_is_valid_access(int off, int size,
6539 switch (off) { 6851 switch (off) {
6540 case bpf_ctx_range(struct __sk_buff, tc_classid): 6852 case bpf_ctx_range(struct __sk_buff, tc_classid):
6541 case bpf_ctx_range(struct __sk_buff, data_meta): 6853 case bpf_ctx_range(struct __sk_buff, data_meta):
6542 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys):
6543 case bpf_ctx_range(struct __sk_buff, tstamp): 6854 case bpf_ctx_range(struct __sk_buff, tstamp):
6544 case bpf_ctx_range(struct __sk_buff, wire_len): 6855 case bpf_ctx_range(struct __sk_buff, wire_len):
6545 return false; 6856 return false;
@@ -6613,24 +6924,65 @@ static bool flow_dissector_is_valid_access(int off, int size,
6613 const struct bpf_prog *prog, 6924 const struct bpf_prog *prog,
6614 struct bpf_insn_access_aux *info) 6925 struct bpf_insn_access_aux *info)
6615{ 6926{
6927 const int size_default = sizeof(__u32);
6928
6929 if (off < 0 || off >= sizeof(struct __sk_buff))
6930 return false;
6931
6616 if (type == BPF_WRITE) 6932 if (type == BPF_WRITE)
6617 return false; 6933 return false;
6618 6934
6619 switch (off) { 6935 switch (off) {
6620 case bpf_ctx_range(struct __sk_buff, data): 6936 case bpf_ctx_range(struct __sk_buff, data):
6937 if (size != size_default)
6938 return false;
6621 info->reg_type = PTR_TO_PACKET; 6939 info->reg_type = PTR_TO_PACKET;
6622 break; 6940 return true;
6623 case bpf_ctx_range(struct __sk_buff, data_end): 6941 case bpf_ctx_range(struct __sk_buff, data_end):
6942 if (size != size_default)
6943 return false;
6624 info->reg_type = PTR_TO_PACKET_END; 6944 info->reg_type = PTR_TO_PACKET_END;
6625 break; 6945 return true;
6626 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys): 6946 case bpf_ctx_range_ptr(struct __sk_buff, flow_keys):
6947 if (size != sizeof(__u64))
6948 return false;
6627 info->reg_type = PTR_TO_FLOW_KEYS; 6949 info->reg_type = PTR_TO_FLOW_KEYS;
6628 break; 6950 return true;
6629 default: 6951 default:
6630 return false; 6952 return false;
6631 } 6953 }
6954}
6632 6955
6633 return bpf_skb_is_valid_access(off, size, type, prog, info); 6956static u32 flow_dissector_convert_ctx_access(enum bpf_access_type type,
6957 const struct bpf_insn *si,
6958 struct bpf_insn *insn_buf,
6959 struct bpf_prog *prog,
6960 u32 *target_size)
6961
6962{
6963 struct bpf_insn *insn = insn_buf;
6964
6965 switch (si->off) {
6966 case offsetof(struct __sk_buff, data):
6967 *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_flow_dissector, data),
6968 si->dst_reg, si->src_reg,
6969 offsetof(struct bpf_flow_dissector, data));
6970 break;
6971
6972 case offsetof(struct __sk_buff, data_end):
6973 *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_flow_dissector, data_end),
6974 si->dst_reg, si->src_reg,
6975 offsetof(struct bpf_flow_dissector, data_end));
6976 break;
6977
6978 case offsetof(struct __sk_buff, flow_keys):
6979 *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_flow_dissector, flow_keys),
6980 si->dst_reg, si->src_reg,
6981 offsetof(struct bpf_flow_dissector, flow_keys));
6982 break;
6983 }
6984
6985 return insn - insn_buf;
6634} 6986}
6635 6987
6636static u32 bpf_convert_ctx_access(enum bpf_access_type type, 6988static u32 bpf_convert_ctx_access(enum bpf_access_type type,
@@ -6937,15 +7289,6 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
6937 skc_num, 2, target_size)); 7289 skc_num, 2, target_size));
6938 break; 7290 break;
6939 7291
6940 case offsetof(struct __sk_buff, flow_keys):
6941 off = si->off;
6942 off -= offsetof(struct __sk_buff, flow_keys);
6943 off += offsetof(struct sk_buff, cb);
6944 off += offsetof(struct qdisc_skb_cb, flow_keys);
6945 *insn++ = BPF_LDX_MEM(BPF_SIZEOF(void *), si->dst_reg,
6946 si->src_reg, off);
6947 break;
6948
6949 case offsetof(struct __sk_buff, tstamp): 7292 case offsetof(struct __sk_buff, tstamp):
6950 BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, tstamp) != 8); 7293 BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, tstamp) != 8);
6951 7294
@@ -7950,7 +8293,7 @@ const struct bpf_prog_ops sk_msg_prog_ops = {
7950const struct bpf_verifier_ops flow_dissector_verifier_ops = { 8293const struct bpf_verifier_ops flow_dissector_verifier_ops = {
7951 .get_func_proto = flow_dissector_func_proto, 8294 .get_func_proto = flow_dissector_func_proto,
7952 .is_valid_access = flow_dissector_is_valid_access, 8295 .is_valid_access = flow_dissector_is_valid_access,
7953 .convert_ctx_access = bpf_convert_ctx_access, 8296 .convert_ctx_access = flow_dissector_convert_ctx_access,
7954}; 8297};
7955 8298
7956const struct bpf_prog_ops flow_dissector_prog_ops = { 8299const struct bpf_prog_ops flow_dissector_prog_ops = {
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 94a450b2191a..548f39dde307 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -65,6 +65,45 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
65} 65}
66EXPORT_SYMBOL(skb_flow_dissector_init); 66EXPORT_SYMBOL(skb_flow_dissector_init);
67 67
68int skb_flow_dissector_prog_query(const union bpf_attr *attr,
69 union bpf_attr __user *uattr)
70{
71 __u32 __user *prog_ids = u64_to_user_ptr(attr->query.prog_ids);
72 u32 prog_id, prog_cnt = 0, flags = 0;
73 struct bpf_prog *attached;
74 struct net *net;
75
76 if (attr->query.query_flags)
77 return -EINVAL;
78
79 net = get_net_ns_by_fd(attr->query.target_fd);
80 if (IS_ERR(net))
81 return PTR_ERR(net);
82
83 rcu_read_lock();
84 attached = rcu_dereference(net->flow_dissector_prog);
85 if (attached) {
86 prog_cnt = 1;
87 prog_id = attached->aux->id;
88 }
89 rcu_read_unlock();
90
91 put_net(net);
92
93 if (copy_to_user(&uattr->query.attach_flags, &flags, sizeof(flags)))
94 return -EFAULT;
95 if (copy_to_user(&uattr->query.prog_cnt, &prog_cnt, sizeof(prog_cnt)))
96 return -EFAULT;
97
98 if (!attr->query.prog_cnt || !prog_ids || !prog_cnt)
99 return 0;
100
101 if (copy_to_user(prog_ids, &prog_id, sizeof(u32)))
102 return -EFAULT;
103
104 return 0;
105}
106
68int skb_flow_dissector_bpf_prog_attach(const union bpf_attr *attr, 107int skb_flow_dissector_bpf_prog_attach(const union bpf_attr *attr,
69 struct bpf_prog *prog) 108 struct bpf_prog *prog)
70{ 109{
@@ -683,50 +722,32 @@ static void __skb_flow_bpf_to_target(const struct bpf_flow_keys *flow_keys,
683 } 722 }
684} 723}
685 724
686bool __skb_flow_bpf_dissect(struct bpf_prog *prog, 725bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
687 const struct sk_buff *skb, 726 __be16 proto, int nhoff, int hlen)
688 struct flow_dissector *flow_dissector,
689 struct bpf_flow_keys *flow_keys)
690{ 727{
691 struct bpf_skb_data_end cb_saved; 728 struct bpf_flow_keys *flow_keys = ctx->flow_keys;
692 struct bpf_skb_data_end *cb;
693 u32 result; 729 u32 result;
694 730
695 /* Note that even though the const qualifier is discarded
696 * throughout the execution of the BPF program, all changes(the
697 * control block) are reverted after the BPF program returns.
698 * Therefore, __skb_flow_dissect does not alter the skb.
699 */
700
701 cb = (struct bpf_skb_data_end *)skb->cb;
702
703 /* Save Control Block */
704 memcpy(&cb_saved, cb, sizeof(cb_saved));
705 memset(cb, 0, sizeof(*cb));
706
707 /* Pass parameters to the BPF program */ 731 /* Pass parameters to the BPF program */
708 memset(flow_keys, 0, sizeof(*flow_keys)); 732 memset(flow_keys, 0, sizeof(*flow_keys));
709 cb->qdisc_cb.flow_keys = flow_keys; 733 flow_keys->n_proto = proto;
710 flow_keys->n_proto = skb->protocol; 734 flow_keys->nhoff = nhoff;
711 flow_keys->nhoff = skb_network_offset(skb);
712 flow_keys->thoff = flow_keys->nhoff; 735 flow_keys->thoff = flow_keys->nhoff;
713 736
714 bpf_compute_data_pointers((struct sk_buff *)skb); 737 preempt_disable();
715 result = BPF_PROG_RUN(prog, skb); 738 result = BPF_PROG_RUN(prog, ctx);
739 preempt_enable();
716 740
717 /* Restore state */ 741 flow_keys->nhoff = clamp_t(u16, flow_keys->nhoff, nhoff, hlen);
718 memcpy(cb, &cb_saved, sizeof(cb_saved));
719
720 flow_keys->nhoff = clamp_t(u16, flow_keys->nhoff,
721 skb_network_offset(skb), skb->len);
722 flow_keys->thoff = clamp_t(u16, flow_keys->thoff, 742 flow_keys->thoff = clamp_t(u16, flow_keys->thoff,
723 flow_keys->nhoff, skb->len); 743 flow_keys->nhoff, hlen);
724 744
725 return result == BPF_OK; 745 return result == BPF_OK;
726} 746}
727 747
728/** 748/**
729 * __skb_flow_dissect - extract the flow_keys struct and return it 749 * __skb_flow_dissect - extract the flow_keys struct and return it
750 * @net: associated network namespace, derived from @skb if NULL
730 * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified 751 * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified
731 * @flow_dissector: list of keys to dissect 752 * @flow_dissector: list of keys to dissect
732 * @target_container: target structure to put dissected values into 753 * @target_container: target structure to put dissected values into
@@ -734,6 +755,8 @@ bool __skb_flow_bpf_dissect(struct bpf_prog *prog,
734 * @proto: protocol for which to get the flow, if @data is NULL use skb->protocol 755 * @proto: protocol for which to get the flow, if @data is NULL use skb->protocol
735 * @nhoff: network header offset, if @data is NULL use skb_network_offset(skb) 756 * @nhoff: network header offset, if @data is NULL use skb_network_offset(skb)
736 * @hlen: packet header length, if @data is NULL use skb_headlen(skb) 757 * @hlen: packet header length, if @data is NULL use skb_headlen(skb)
758 * @flags: flags that control the dissection process, e.g.
759 * FLOW_DISSECTOR_F_STOP_AT_L3.
737 * 760 *
738 * The function will try to retrieve individual keys into target specified 761 * The function will try to retrieve individual keys into target specified
739 * by flow_dissector from either the skbuff or a raw buffer specified by the 762 * by flow_dissector from either the skbuff or a raw buffer specified by the
@@ -741,7 +764,8 @@ bool __skb_flow_bpf_dissect(struct bpf_prog *prog,
741 * 764 *
742 * Caller must take care of zeroing target container memory. 765 * Caller must take care of zeroing target container memory.
743 */ 766 */
744bool __skb_flow_dissect(const struct sk_buff *skb, 767bool __skb_flow_dissect(const struct net *net,
768 const struct sk_buff *skb,
745 struct flow_dissector *flow_dissector, 769 struct flow_dissector *flow_dissector,
746 void *target_container, 770 void *target_container,
747 void *data, __be16 proto, int nhoff, int hlen, 771 void *data, __be16 proto, int nhoff, int hlen,
@@ -754,6 +778,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
754 struct flow_dissector_key_icmp *key_icmp; 778 struct flow_dissector_key_icmp *key_icmp;
755 struct flow_dissector_key_tags *key_tags; 779 struct flow_dissector_key_tags *key_tags;
756 struct flow_dissector_key_vlan *key_vlan; 780 struct flow_dissector_key_vlan *key_vlan;
781 struct bpf_prog *attached = NULL;
757 enum flow_dissect_ret fdret; 782 enum flow_dissect_ret fdret;
758 enum flow_dissector_key_id dissector_vlan = FLOW_DISSECTOR_KEY_MAX; 783 enum flow_dissector_key_id dissector_vlan = FLOW_DISSECTOR_KEY_MAX;
759 int num_hdrs = 0; 784 int num_hdrs = 0;
@@ -796,22 +821,39 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
796 target_container); 821 target_container);
797 822
798 if (skb) { 823 if (skb) {
799 struct bpf_flow_keys flow_keys; 824 if (!net) {
800 struct bpf_prog *attached = NULL; 825 if (skb->dev)
826 net = dev_net(skb->dev);
827 else if (skb->sk)
828 net = sock_net(skb->sk);
829 }
830 }
801 831
832 WARN_ON_ONCE(!net);
833 if (net) {
802 rcu_read_lock(); 834 rcu_read_lock();
803 835 attached = rcu_dereference(net->flow_dissector_prog);
804 if (skb->dev)
805 attached = rcu_dereference(dev_net(skb->dev)->flow_dissector_prog);
806 else if (skb->sk)
807 attached = rcu_dereference(sock_net(skb->sk)->flow_dissector_prog);
808 else
809 WARN_ON_ONCE(1);
810 836
811 if (attached) { 837 if (attached) {
812 ret = __skb_flow_bpf_dissect(attached, skb, 838 struct bpf_flow_keys flow_keys;
813 flow_dissector, 839 struct bpf_flow_dissector ctx = {
814 &flow_keys); 840 .flow_keys = &flow_keys,
841 .data = data,
842 .data_end = data + hlen,
843 };
844 __be16 n_proto = proto;
845
846 if (skb) {
847 ctx.skb = skb;
848 /* we can't use 'proto' in the skb case
849 * because it might be set to skb->vlan_proto
850 * which has been pulled from the data
851 */
852 n_proto = skb->protocol;
853 }
854
855 ret = bpf_flow_dissect(attached, &ctx, n_proto, nhoff,
856 hlen);
815 __skb_flow_bpf_to_target(&flow_keys, flow_dissector, 857 __skb_flow_bpf_to_target(&flow_keys, flow_dissector,
816 target_container); 858 target_container);
817 rcu_read_unlock(); 859 rcu_read_unlock();
@@ -1408,8 +1450,8 @@ u32 __skb_get_hash_symmetric(const struct sk_buff *skb)
1408 __flow_hash_secret_init(); 1450 __flow_hash_secret_init();
1409 1451
1410 memset(&keys, 0, sizeof(keys)); 1452 memset(&keys, 0, sizeof(keys));
1411 __skb_flow_dissect(skb, &flow_keys_dissector_symmetric, &keys, 1453 __skb_flow_dissect(NULL, skb, &flow_keys_dissector_symmetric,
1412 NULL, 0, 0, 0, 1454 &keys, NULL, 0, 0, 0,
1413 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL); 1455 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
1414 1456
1415 return __flow_hash_from_keys(&keys, hashrnd); 1457 return __flow_hash_from_keys(&keys, hashrnd);
@@ -1510,7 +1552,8 @@ u32 skb_get_poff(const struct sk_buff *skb)
1510{ 1552{
1511 struct flow_keys_basic keys; 1553 struct flow_keys_basic keys;
1512 1554
1513 if (!skb_flow_dissect_flow_keys_basic(skb, &keys, NULL, 0, 0, 0, 0)) 1555 if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys,
1556 NULL, 0, 0, 0, 0))
1514 return 0; 1557 return 0;
1515 1558
1516 return __skb_get_poff(skb, skb->data, &keys, skb_headlen(skb)); 1559 return __skb_get_poff(skb, skb->data, &keys, skb_headlen(skb));
diff --git a/net/core/gen_stats.c b/net/core/gen_stats.c
index ac679f74ba47..9bf1b9ad1780 100644
--- a/net/core/gen_stats.c
+++ b/net/core/gen_stats.c
@@ -291,6 +291,7 @@ __gnet_stats_copy_queue_cpu(struct gnet_stats_queue *qstats,
291 for_each_possible_cpu(i) { 291 for_each_possible_cpu(i) {
292 const struct gnet_stats_queue *qcpu = per_cpu_ptr(q, i); 292 const struct gnet_stats_queue *qcpu = per_cpu_ptr(q, i);
293 293
294 qstats->qlen = 0;
294 qstats->backlog += qcpu->backlog; 295 qstats->backlog += qcpu->backlog;
295 qstats->drops += qcpu->drops; 296 qstats->drops += qcpu->drops;
296 qstats->requeues += qcpu->requeues; 297 qstats->requeues += qcpu->requeues;
@@ -306,6 +307,7 @@ void __gnet_stats_copy_queue(struct gnet_stats_queue *qstats,
306 if (cpu) { 307 if (cpu) {
307 __gnet_stats_copy_queue_cpu(qstats, cpu); 308 __gnet_stats_copy_queue_cpu(qstats, cpu);
308 } else { 309 } else {
310 qstats->qlen = q->qlen;
309 qstats->backlog = q->backlog; 311 qstats->backlog = q->backlog;
310 qstats->drops = q->drops; 312 qstats->drops = q->drops;
311 qstats->requeues = q->requeues; 313 qstats->requeues = q->requeues;
diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
index 126d31ff5ee3..1c94f529f4a1 100644
--- a/net/core/lwt_bpf.c
+++ b/net/core/lwt_bpf.c
@@ -18,6 +18,7 @@
18#include <net/lwtunnel.h> 18#include <net/lwtunnel.h>
19#include <net/gre.h> 19#include <net/gre.h>
20#include <net/ip6_route.h> 20#include <net/ip6_route.h>
21#include <net/ipv6_stubs.h>
21 22
22struct bpf_lwt_prog { 23struct bpf_lwt_prog {
23 struct bpf_prog *prog; 24 struct bpf_prog *prog;
@@ -342,8 +343,8 @@ static int bpf_parse_prog(struct nlattr *attr, struct bpf_lwt_prog *prog,
342 int ret; 343 int ret;
343 u32 fd; 344 u32 fd;
344 345
345 ret = nla_parse_nested(tb, LWT_BPF_PROG_MAX, attr, bpf_prog_policy, 346 ret = nla_parse_nested_deprecated(tb, LWT_BPF_PROG_MAX, attr,
346 NULL); 347 bpf_prog_policy, NULL);
347 if (ret < 0) 348 if (ret < 0)
348 return ret; 349 return ret;
349 350
@@ -384,7 +385,8 @@ static int bpf_build_state(struct nlattr *nla,
384 if (family != AF_INET && family != AF_INET6) 385 if (family != AF_INET && family != AF_INET6)
385 return -EAFNOSUPPORT; 386 return -EAFNOSUPPORT;
386 387
387 ret = nla_parse_nested(tb, LWT_BPF_MAX, nla, bpf_nl_policy, extack); 388 ret = nla_parse_nested_deprecated(tb, LWT_BPF_MAX, nla, bpf_nl_policy,
389 extack);
388 if (ret < 0) 390 if (ret < 0)
389 return ret; 391 return ret;
390 392
@@ -452,7 +454,7 @@ static int bpf_fill_lwt_prog(struct sk_buff *skb, int attr,
452 if (!prog->prog) 454 if (!prog->prog)
453 return 0; 455 return 0;
454 456
455 nest = nla_nest_start(skb, attr); 457 nest = nla_nest_start_noflag(skb, attr);
456 if (!nest) 458 if (!nest)
457 return -EMSGSIZE; 459 return -EMSGSIZE;
458 460
diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c
index 19b557bd294b..69e249fbc02f 100644
--- a/net/core/lwtunnel.c
+++ b/net/core/lwtunnel.c
@@ -26,7 +26,7 @@
26#include <net/lwtunnel.h> 26#include <net/lwtunnel.h>
27#include <net/rtnetlink.h> 27#include <net/rtnetlink.h>
28#include <net/ip6_fib.h> 28#include <net/ip6_fib.h>
29#include <net/nexthop.h> 29#include <net/rtnh.h>
30 30
31#ifdef CONFIG_MODULES 31#ifdef CONFIG_MODULES
32 32
@@ -223,7 +223,8 @@ void lwtstate_free(struct lwtunnel_state *lws)
223} 223}
224EXPORT_SYMBOL_GPL(lwtstate_free); 224EXPORT_SYMBOL_GPL(lwtstate_free);
225 225
226int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate) 226int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate,
227 int encap_attr, int encap_type_attr)
227{ 228{
228 const struct lwtunnel_encap_ops *ops; 229 const struct lwtunnel_encap_ops *ops;
229 struct nlattr *nest; 230 struct nlattr *nest;
@@ -236,7 +237,7 @@ int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate)
236 lwtstate->type > LWTUNNEL_ENCAP_MAX) 237 lwtstate->type > LWTUNNEL_ENCAP_MAX)
237 return 0; 238 return 0;
238 239
239 nest = nla_nest_start(skb, RTA_ENCAP); 240 nest = nla_nest_start_noflag(skb, encap_attr);
240 if (!nest) 241 if (!nest)
241 return -EMSGSIZE; 242 return -EMSGSIZE;
242 243
@@ -250,7 +251,7 @@ int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate)
250 if (ret) 251 if (ret)
251 goto nla_put_failure; 252 goto nla_put_failure;
252 nla_nest_end(skb, nest); 253 nla_nest_end(skb, nest);
253 ret = nla_put_u16(skb, RTA_ENCAP_TYPE, lwtstate->type); 254 ret = nla_put_u16(skb, encap_type_attr, lwtstate->type);
254 if (ret) 255 if (ret)
255 goto nla_put_failure; 256 goto nla_put_failure;
256 257
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 30f6fd8f68e0..dfa871061f14 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -31,6 +31,7 @@
31#include <linux/times.h> 31#include <linux/times.h>
32#include <net/net_namespace.h> 32#include <net/net_namespace.h>
33#include <net/neighbour.h> 33#include <net/neighbour.h>
34#include <net/arp.h>
34#include <net/dst.h> 35#include <net/dst.h>
35#include <net/sock.h> 36#include <net/sock.h>
36#include <net/netevent.h> 37#include <net/netevent.h>
@@ -663,6 +664,8 @@ out:
663out_tbl_unlock: 664out_tbl_unlock:
664 write_unlock_bh(&tbl->lock); 665 write_unlock_bh(&tbl->lock);
665out_neigh_release: 666out_neigh_release:
667 if (!exempt_from_gc)
668 atomic_dec(&tbl->gc_entries);
666 neigh_release(n); 669 neigh_release(n);
667 goto out; 670 goto out;
668} 671}
@@ -1862,7 +1865,8 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
1862 int err; 1865 int err;
1863 1866
1864 ASSERT_RTNL(); 1867 ASSERT_RTNL();
1865 err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, nda_policy, extack); 1868 err = nlmsg_parse_deprecated(nlh, sizeof(*ndm), tb, NDA_MAX,
1869 nda_policy, extack);
1866 if (err < 0) 1870 if (err < 0)
1867 goto out; 1871 goto out;
1868 1872
@@ -1920,6 +1924,11 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
1920 goto out; 1924 goto out;
1921 } 1925 }
1922 1926
1927 if (tbl->allow_add && !tbl->allow_add(dev, extack)) {
1928 err = -EINVAL;
1929 goto out;
1930 }
1931
1923 neigh = neigh_lookup(tbl, dst, dev); 1932 neigh = neigh_lookup(tbl, dst, dev);
1924 if (neigh == NULL) { 1933 if (neigh == NULL) {
1925 bool exempt_from_gc; 1934 bool exempt_from_gc;
@@ -1974,7 +1983,7 @@ static int neightbl_fill_parms(struct sk_buff *skb, struct neigh_parms *parms)
1974{ 1983{
1975 struct nlattr *nest; 1984 struct nlattr *nest;
1976 1985
1977 nest = nla_nest_start(skb, NDTA_PARMS); 1986 nest = nla_nest_start_noflag(skb, NDTA_PARMS);
1978 if (nest == NULL) 1987 if (nest == NULL)
1979 return -ENOBUFS; 1988 return -ENOBUFS;
1980 1989
@@ -2176,8 +2185,8 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh,
2176 bool found = false; 2185 bool found = false;
2177 int err, tidx; 2186 int err, tidx;
2178 2187
2179 err = nlmsg_parse(nlh, sizeof(*ndtmsg), tb, NDTA_MAX, 2188 err = nlmsg_parse_deprecated(nlh, sizeof(*ndtmsg), tb, NDTA_MAX,
2180 nl_neightbl_policy, extack); 2189 nl_neightbl_policy, extack);
2181 if (err < 0) 2190 if (err < 0)
2182 goto errout; 2191 goto errout;
2183 2192
@@ -2214,8 +2223,9 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh,
2214 struct neigh_parms *p; 2223 struct neigh_parms *p;
2215 int i, ifindex = 0; 2224 int i, ifindex = 0;
2216 2225
2217 err = nla_parse_nested(tbp, NDTPA_MAX, tb[NDTA_PARMS], 2226 err = nla_parse_nested_deprecated(tbp, NDTPA_MAX,
2218 nl_ntbl_parm_policy, extack); 2227 tb[NDTA_PARMS],
2228 nl_ntbl_parm_policy, extack);
2219 if (err < 0) 2229 if (err < 0)
2220 goto errout_tbl_lock; 2230 goto errout_tbl_lock;
2221 2231
@@ -2655,11 +2665,12 @@ static int neigh_valid_dump_req(const struct nlmsghdr *nlh,
2655 return -EINVAL; 2665 return -EINVAL;
2656 } 2666 }
2657 2667
2658 err = nlmsg_parse_strict(nlh, sizeof(struct ndmsg), tb, NDA_MAX, 2668 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct ndmsg),
2659 nda_policy, extack); 2669 tb, NDA_MAX, nda_policy,
2670 extack);
2660 } else { 2671 } else {
2661 err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX, 2672 err = nlmsg_parse_deprecated(nlh, sizeof(struct ndmsg), tb,
2662 nda_policy, extack); 2673 NDA_MAX, nda_policy, extack);
2663 } 2674 }
2664 if (err < 0) 2675 if (err < 0)
2665 return err; 2676 return err;
@@ -2759,8 +2770,8 @@ static int neigh_valid_get_req(const struct nlmsghdr *nlh,
2759 return -EINVAL; 2770 return -EINVAL;
2760 } 2771 }
2761 2772
2762 err = nlmsg_parse_strict(nlh, sizeof(struct ndmsg), tb, NDA_MAX, 2773 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct ndmsg), tb,
2763 nda_policy, extack); 2774 NDA_MAX, nda_policy, extack);
2764 if (err < 0) 2775 if (err < 0)
2765 return err; 2776 return err;
2766 2777
@@ -2982,7 +2993,13 @@ int neigh_xmit(int index, struct net_device *dev,
2982 if (!tbl) 2993 if (!tbl)
2983 goto out; 2994 goto out;
2984 rcu_read_lock_bh(); 2995 rcu_read_lock_bh();
2985 neigh = __neigh_lookup_noref(tbl, addr, dev); 2996 if (index == NEIGH_ARP_TABLE) {
2997 u32 key = *((u32 *)addr);
2998
2999 neigh = __ipv4_neigh_lookup_noref(dev, key);
3000 } else {
3001 neigh = __neigh_lookup_noref(tbl, addr, dev);
3002 }
2986 if (!neigh) 3003 if (!neigh)
2987 neigh = __neigh_create(tbl, addr, dev, false); 3004 neigh = __neigh_create(tbl, addr, dev, false);
2988 err = PTR_ERR(neigh); 3005 err = PTR_ERR(neigh);
diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
index 63881f72ef71..36347933ec3a 100644
--- a/net/core/net-procfs.c
+++ b/net/core/net-procfs.c
@@ -258,7 +258,7 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
258 else 258 else
259 seq_printf(seq, "%04x", ntohs(pt->type)); 259 seq_printf(seq, "%04x", ntohs(pt->type));
260 260
261 seq_printf(seq, " %-8s %pf\n", 261 seq_printf(seq, " %-8s %ps\n",
262 pt->dev ? pt->dev->name : "", pt->func); 262 pt->dev ? pt->dev->name : "", pt->func);
263 } 263 }
264 264
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index f8f94303a1f5..d9c4360257ce 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -754,9 +754,9 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue,
754 rcu_assign_pointer(queue->rps_map, map); 754 rcu_assign_pointer(queue->rps_map, map);
755 755
756 if (map) 756 if (map)
757 static_key_slow_inc(&rps_needed); 757 static_branch_inc(&rps_needed);
758 if (old_map) 758 if (old_map)
759 static_key_slow_dec(&rps_needed); 759 static_branch_dec(&rps_needed);
760 760
761 mutex_unlock(&rps_map_mutex); 761 mutex_unlock(&rps_map_mutex);
762 762
@@ -863,6 +863,7 @@ static struct attribute *rx_queue_default_attrs[] __ro_after_init = {
863#endif 863#endif
864 NULL 864 NULL
865}; 865};
866ATTRIBUTE_GROUPS(rx_queue_default);
866 867
867static void rx_queue_release(struct kobject *kobj) 868static void rx_queue_release(struct kobject *kobj)
868{ 869{
@@ -911,7 +912,7 @@ static void rx_queue_get_ownership(struct kobject *kobj,
911static struct kobj_type rx_queue_ktype __ro_after_init = { 912static struct kobj_type rx_queue_ktype __ro_after_init = {
912 .sysfs_ops = &rx_queue_sysfs_ops, 913 .sysfs_ops = &rx_queue_sysfs_ops,
913 .release = rx_queue_release, 914 .release = rx_queue_release,
914 .default_attrs = rx_queue_default_attrs, 915 .default_groups = rx_queue_default_groups,
915 .namespace = rx_queue_namespace, 916 .namespace = rx_queue_namespace,
916 .get_ownership = rx_queue_get_ownership, 917 .get_ownership = rx_queue_get_ownership,
917}; 918};
@@ -1416,6 +1417,7 @@ static struct attribute *netdev_queue_default_attrs[] __ro_after_init = {
1416#endif 1417#endif
1417 NULL 1418 NULL
1418}; 1419};
1420ATTRIBUTE_GROUPS(netdev_queue_default);
1419 1421
1420static void netdev_queue_release(struct kobject *kobj) 1422static void netdev_queue_release(struct kobject *kobj)
1421{ 1423{
@@ -1448,7 +1450,7 @@ static void netdev_queue_get_ownership(struct kobject *kobj,
1448static struct kobj_type netdev_queue_ktype __ro_after_init = { 1450static struct kobj_type netdev_queue_ktype __ro_after_init = {
1449 .sysfs_ops = &netdev_queue_sysfs_ops, 1451 .sysfs_ops = &netdev_queue_sysfs_ops,
1450 .release = netdev_queue_release, 1452 .release = netdev_queue_release,
1451 .default_attrs = netdev_queue_default_attrs, 1453 .default_groups = netdev_queue_default_groups,
1452 .namespace = netdev_queue_namespace, 1454 .namespace = netdev_queue_namespace,
1453 .get_ownership = netdev_queue_get_ownership, 1455 .get_ownership = netdev_queue_get_ownership,
1454}; 1456};
@@ -1747,20 +1749,16 @@ int netdev_register_kobject(struct net_device *ndev)
1747 1749
1748 error = device_add(dev); 1750 error = device_add(dev);
1749 if (error) 1751 if (error)
1750 goto error_put_device; 1752 return error;
1751 1753
1752 error = register_queue_kobjects(ndev); 1754 error = register_queue_kobjects(ndev);
1753 if (error) 1755 if (error) {
1754 goto error_device_del; 1756 device_del(dev);
1757 return error;
1758 }
1755 1759
1756 pm_runtime_set_memalloc_noio(dev, true); 1760 pm_runtime_set_memalloc_noio(dev, true);
1757 1761
1758 return 0;
1759
1760error_device_del:
1761 device_del(dev);
1762error_put_device:
1763 put_device(dev);
1764 return error; 1762 return error;
1765} 1763}
1766 1764
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 7e6dcc625701..711b161505ac 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -682,8 +682,8 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
682 struct net *peer; 682 struct net *peer;
683 int nsid, err; 683 int nsid, err;
684 684
685 err = nlmsg_parse(nlh, sizeof(struct rtgenmsg), tb, NETNSA_MAX, 685 err = nlmsg_parse_deprecated(nlh, sizeof(struct rtgenmsg), tb,
686 rtnl_net_policy, extack); 686 NETNSA_MAX, rtnl_net_policy, extack);
687 if (err < 0) 687 if (err < 0)
688 return err; 688 return err;
689 if (!tb[NETNSA_NSID]) { 689 if (!tb[NETNSA_NSID]) {
@@ -787,11 +787,13 @@ static int rtnl_net_valid_getid_req(struct sk_buff *skb,
787 int i, err; 787 int i, err;
788 788
789 if (!netlink_strict_get_check(skb)) 789 if (!netlink_strict_get_check(skb))
790 return nlmsg_parse(nlh, sizeof(struct rtgenmsg), tb, NETNSA_MAX, 790 return nlmsg_parse_deprecated(nlh, sizeof(struct rtgenmsg),
791 rtnl_net_policy, extack); 791 tb, NETNSA_MAX, rtnl_net_policy,
792 extack);
792 793
793 err = nlmsg_parse_strict(nlh, sizeof(struct rtgenmsg), tb, NETNSA_MAX, 794 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct rtgenmsg), tb,
794 rtnl_net_policy, extack); 795 NETNSA_MAX, rtnl_net_policy,
796 extack);
795 if (err) 797 if (err)
796 return err; 798 return err;
797 799
@@ -839,7 +841,7 @@ static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh,
839 peer = get_net_ns_by_fd(nla_get_u32(tb[NETNSA_FD])); 841 peer = get_net_ns_by_fd(nla_get_u32(tb[NETNSA_FD]));
840 nla = tb[NETNSA_FD]; 842 nla = tb[NETNSA_FD];
841 } else if (tb[NETNSA_NSID]) { 843 } else if (tb[NETNSA_NSID]) {
842 peer = get_net_ns_by_id(net, nla_get_u32(tb[NETNSA_NSID])); 844 peer = get_net_ns_by_id(net, nla_get_s32(tb[NETNSA_NSID]));
843 if (!peer) 845 if (!peer)
844 peer = ERR_PTR(-ENOENT); 846 peer = ERR_PTR(-ENOENT);
845 nla = tb[NETNSA_NSID]; 847 nla = tb[NETNSA_NSID];
@@ -929,8 +931,9 @@ static int rtnl_valid_dump_net_req(const struct nlmsghdr *nlh, struct sock *sk,
929 struct nlattr *tb[NETNSA_MAX + 1]; 931 struct nlattr *tb[NETNSA_MAX + 1];
930 int err, i; 932 int err, i;
931 933
932 err = nlmsg_parse_strict(nlh, sizeof(struct rtgenmsg), tb, NETNSA_MAX, 934 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct rtgenmsg), tb,
933 rtnl_net_policy, extack); 935 NETNSA_MAX, rtnl_net_policy,
936 extack);
934 if (err < 0) 937 if (err < 0)
935 return err; 938 return err;
936 939
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 361aabffb8c0..a0f05416657b 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -149,7 +149,7 @@ static void poll_one_napi(struct napi_struct *napi)
149 * indicate that we are clearing the Tx path only. 149 * indicate that we are clearing the Tx path only.
150 */ 150 */
151 work = napi->poll(napi, 0); 151 work = napi->poll(napi, 0);
152 WARN_ONCE(work, "%pF exceeded budget in poll\n", napi->poll); 152 WARN_ONCE(work, "%pS exceeded budget in poll\n", napi->poll);
153 trace_napi_poll(napi, work, 0); 153 trace_napi_poll(napi, work, 0);
154 154
155 clear_bit(NAPI_STATE_NPSVC, &napi->state); 155 clear_bit(NAPI_STATE_NPSVC, &napi->state);
@@ -323,7 +323,7 @@ void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
323 if (skb_queue_len(&npinfo->txq) == 0 && !netpoll_owner_active(dev)) { 323 if (skb_queue_len(&npinfo->txq) == 0 && !netpoll_owner_active(dev)) {
324 struct netdev_queue *txq; 324 struct netdev_queue *txq;
325 325
326 txq = netdev_pick_tx(dev, skb, NULL); 326 txq = netdev_core_pick_tx(dev, skb, NULL);
327 327
328 /* try until next clock tick */ 328 /* try until next clock tick */
329 for (tries = jiffies_to_usecs(1)/USEC_PER_POLL; 329 for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
@@ -346,7 +346,7 @@ void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
346 } 346 }
347 347
348 WARN_ONCE(!irqs_disabled(), 348 WARN_ONCE(!irqs_disabled(),
349 "netpoll_send_skb_on_dev(): %s enabled interrupts in poll (%pF)\n", 349 "netpoll_send_skb_on_dev(): %s enabled interrupts in poll (%pS)\n",
350 dev->name, dev->netdev_ops->ndo_start_xmit); 350 dev->name, dev->netdev_ops->ndo_start_xmit);
351 351
352 } 352 }
diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index b9057478d69c..7e3d0d99dfae 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -301,6 +301,4 @@ static int __init init_cgroup_netprio(void)
301 register_netdevice_notifier(&netprio_device_notifier); 301 register_netdevice_notifier(&netprio_device_notifier);
302 return 0; 302 return 0;
303} 303}
304
305subsys_initcall(init_cgroup_netprio); 304subsys_initcall(init_cgroup_netprio);
306MODULE_LICENSE("GPL v2");
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index f3f5a78cd062..319ad5490fb3 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -2521,7 +2521,7 @@ static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
2521 skb->_skb_refdst = (unsigned long)&pkt_dev->xdst.u.dst | SKB_DST_NOREF; 2521 skb->_skb_refdst = (unsigned long)&pkt_dev->xdst.u.dst | SKB_DST_NOREF;
2522 2522
2523 rcu_read_lock_bh(); 2523 rcu_read_lock_bh();
2524 err = x->outer_mode->output(x, skb); 2524 err = pktgen_xfrm_outer_mode_output(x, skb);
2525 rcu_read_unlock_bh(); 2525 rcu_read_unlock_bh();
2526 if (err) { 2526 if (err) {
2527 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR); 2527 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR);
diff --git a/net/core/ptp_classifier.c b/net/core/ptp_classifier.c
index 703cf76aa7c2..7109c168b5e0 100644
--- a/net/core/ptp_classifier.c
+++ b/net/core/ptp_classifier.c
@@ -185,9 +185,10 @@ void __init ptp_classifier_init(void)
185 { 0x16, 0, 0, 0x00000000 }, 185 { 0x16, 0, 0, 0x00000000 },
186 { 0x06, 0, 0, 0x00000000 }, 186 { 0x06, 0, 0, 0x00000000 },
187 }; 187 };
188 struct sock_fprog_kern ptp_prog = { 188 struct sock_fprog_kern ptp_prog;
189 .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter, 189
190 }; 190 ptp_prog.len = ARRAY_SIZE(ptp_filter);
191 ptp_prog.filter = ptp_filter;
191 192
192 BUG_ON(bpf_prog_create(&ptp_insns, &ptp_prog)); 193 BUG_ON(bpf_prog_create(&ptp_insns, &ptp_prog));
193} 194}
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a51cab95ba64..2bd12afb9297 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -634,7 +634,7 @@ static int rtnl_link_slave_info_fill(struct sk_buff *skb,
634 if (nla_put_string(skb, IFLA_INFO_SLAVE_KIND, ops->kind) < 0) 634 if (nla_put_string(skb, IFLA_INFO_SLAVE_KIND, ops->kind) < 0)
635 return -EMSGSIZE; 635 return -EMSGSIZE;
636 if (ops->fill_slave_info) { 636 if (ops->fill_slave_info) {
637 slave_data = nla_nest_start(skb, IFLA_INFO_SLAVE_DATA); 637 slave_data = nla_nest_start_noflag(skb, IFLA_INFO_SLAVE_DATA);
638 if (!slave_data) 638 if (!slave_data)
639 return -EMSGSIZE; 639 return -EMSGSIZE;
640 err = ops->fill_slave_info(skb, master_dev, dev); 640 err = ops->fill_slave_info(skb, master_dev, dev);
@@ -666,7 +666,7 @@ static int rtnl_link_info_fill(struct sk_buff *skb,
666 return err; 666 return err;
667 } 667 }
668 if (ops->fill_info) { 668 if (ops->fill_info) {
669 data = nla_nest_start(skb, IFLA_INFO_DATA); 669 data = nla_nest_start_noflag(skb, IFLA_INFO_DATA);
670 if (data == NULL) 670 if (data == NULL)
671 return -EMSGSIZE; 671 return -EMSGSIZE;
672 err = ops->fill_info(skb, dev); 672 err = ops->fill_info(skb, dev);
@@ -686,7 +686,7 @@ static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev)
686 struct nlattr *linkinfo; 686 struct nlattr *linkinfo;
687 int err = -EMSGSIZE; 687 int err = -EMSGSIZE;
688 688
689 linkinfo = nla_nest_start(skb, IFLA_LINKINFO); 689 linkinfo = nla_nest_start_noflag(skb, IFLA_LINKINFO);
690 if (linkinfo == NULL) 690 if (linkinfo == NULL)
691 goto out; 691 goto out;
692 692
@@ -755,7 +755,7 @@ int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
755 struct nlattr *mx; 755 struct nlattr *mx;
756 int i, valid = 0; 756 int i, valid = 0;
757 757
758 mx = nla_nest_start(skb, RTA_METRICS); 758 mx = nla_nest_start_noflag(skb, RTA_METRICS);
759 if (mx == NULL) 759 if (mx == NULL)
760 return -ENOBUFS; 760 return -ENOBUFS;
761 761
@@ -1036,12 +1036,12 @@ static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
1036 int vf; 1036 int vf;
1037 int err; 1037 int err;
1038 1038
1039 vf_ports = nla_nest_start(skb, IFLA_VF_PORTS); 1039 vf_ports = nla_nest_start_noflag(skb, IFLA_VF_PORTS);
1040 if (!vf_ports) 1040 if (!vf_ports)
1041 return -EMSGSIZE; 1041 return -EMSGSIZE;
1042 1042
1043 for (vf = 0; vf < dev_num_vf(dev->dev.parent); vf++) { 1043 for (vf = 0; vf < dev_num_vf(dev->dev.parent); vf++) {
1044 vf_port = nla_nest_start(skb, IFLA_VF_PORT); 1044 vf_port = nla_nest_start_noflag(skb, IFLA_VF_PORT);
1045 if (!vf_port) 1045 if (!vf_port)
1046 goto nla_put_failure; 1046 goto nla_put_failure;
1047 if (nla_put_u32(skb, IFLA_PORT_VF, vf)) 1047 if (nla_put_u32(skb, IFLA_PORT_VF, vf))
@@ -1070,7 +1070,7 @@ static int rtnl_port_self_fill(struct sk_buff *skb, struct net_device *dev)
1070 struct nlattr *port_self; 1070 struct nlattr *port_self;
1071 int err; 1071 int err;
1072 1072
1073 port_self = nla_nest_start(skb, IFLA_PORT_SELF); 1073 port_self = nla_nest_start_noflag(skb, IFLA_PORT_SELF);
1074 if (!port_self) 1074 if (!port_self)
1075 return -EMSGSIZE; 1075 return -EMSGSIZE;
1076 1076
@@ -1247,7 +1247,7 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
1247 vf_linkstate.link_state = ivi.linkstate; 1247 vf_linkstate.link_state = ivi.linkstate;
1248 vf_rss_query_en.setting = ivi.rss_query_en; 1248 vf_rss_query_en.setting = ivi.rss_query_en;
1249 vf_trust.setting = ivi.trusted; 1249 vf_trust.setting = ivi.trusted;
1250 vf = nla_nest_start(skb, IFLA_VF_INFO); 1250 vf = nla_nest_start_noflag(skb, IFLA_VF_INFO);
1251 if (!vf) 1251 if (!vf)
1252 goto nla_put_vfinfo_failure; 1252 goto nla_put_vfinfo_failure;
1253 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) || 1253 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
@@ -1266,7 +1266,7 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
1266 nla_put(skb, IFLA_VF_TRUST, 1266 nla_put(skb, IFLA_VF_TRUST,
1267 sizeof(vf_trust), &vf_trust)) 1267 sizeof(vf_trust), &vf_trust))
1268 goto nla_put_vf_failure; 1268 goto nla_put_vf_failure;
1269 vfvlanlist = nla_nest_start(skb, IFLA_VF_VLAN_LIST); 1269 vfvlanlist = nla_nest_start_noflag(skb, IFLA_VF_VLAN_LIST);
1270 if (!vfvlanlist) 1270 if (!vfvlanlist)
1271 goto nla_put_vf_failure; 1271 goto nla_put_vf_failure;
1272 if (nla_put(skb, IFLA_VF_VLAN_INFO, sizeof(vf_vlan_info), 1272 if (nla_put(skb, IFLA_VF_VLAN_INFO, sizeof(vf_vlan_info),
@@ -1279,7 +1279,7 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
1279 if (dev->netdev_ops->ndo_get_vf_stats) 1279 if (dev->netdev_ops->ndo_get_vf_stats)
1280 dev->netdev_ops->ndo_get_vf_stats(dev, vfs_num, 1280 dev->netdev_ops->ndo_get_vf_stats(dev, vfs_num,
1281 &vf_stats); 1281 &vf_stats);
1282 vfstats = nla_nest_start(skb, IFLA_VF_STATS); 1282 vfstats = nla_nest_start_noflag(skb, IFLA_VF_STATS);
1283 if (!vfstats) 1283 if (!vfstats)
1284 goto nla_put_vf_failure; 1284 goto nla_put_vf_failure;
1285 if (nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_PACKETS, 1285 if (nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_PACKETS,
@@ -1329,7 +1329,7 @@ static noinline_for_stack int rtnl_fill_vf(struct sk_buff *skb,
1329 if (!dev->netdev_ops->ndo_get_vf_config) 1329 if (!dev->netdev_ops->ndo_get_vf_config)
1330 return 0; 1330 return 0;
1331 1331
1332 vfinfo = nla_nest_start(skb, IFLA_VFINFO_LIST); 1332 vfinfo = nla_nest_start_noflag(skb, IFLA_VFINFO_LIST);
1333 if (!vfinfo) 1333 if (!vfinfo)
1334 return -EMSGSIZE; 1334 return -EMSGSIZE;
1335 1335
@@ -1414,7 +1414,7 @@ static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
1414 int err; 1414 int err;
1415 u8 mode; 1415 u8 mode;
1416 1416
1417 xdp = nla_nest_start(skb, IFLA_XDP); 1417 xdp = nla_nest_start_noflag(skb, IFLA_XDP);
1418 if (!xdp) 1418 if (!xdp)
1419 return -EMSGSIZE; 1419 return -EMSGSIZE;
1420 1420
@@ -1541,7 +1541,7 @@ static int rtnl_fill_link_af(struct sk_buff *skb,
1541 const struct rtnl_af_ops *af_ops; 1541 const struct rtnl_af_ops *af_ops;
1542 struct nlattr *af_spec; 1542 struct nlattr *af_spec;
1543 1543
1544 af_spec = nla_nest_start(skb, IFLA_AF_SPEC); 1544 af_spec = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
1545 if (!af_spec) 1545 if (!af_spec)
1546 return -EMSGSIZE; 1546 return -EMSGSIZE;
1547 1547
@@ -1552,7 +1552,7 @@ static int rtnl_fill_link_af(struct sk_buff *skb,
1552 if (!af_ops->fill_link_af) 1552 if (!af_ops->fill_link_af)
1553 continue; 1553 continue;
1554 1554
1555 af = nla_nest_start(skb, af_ops->family); 1555 af = nla_nest_start_noflag(skb, af_ops->family);
1556 if (!af) 1556 if (!af)
1557 return -EMSGSIZE; 1557 return -EMSGSIZE;
1558 1558
@@ -1797,8 +1797,7 @@ static const struct rtnl_link_ops *linkinfo_to_kind_ops(const struct nlattr *nla
1797 const struct rtnl_link_ops *ops = NULL; 1797 const struct rtnl_link_ops *ops = NULL;
1798 struct nlattr *linfo[IFLA_INFO_MAX + 1]; 1798 struct nlattr *linfo[IFLA_INFO_MAX + 1];
1799 1799
1800 if (nla_parse_nested(linfo, IFLA_INFO_MAX, nla, 1800 if (nla_parse_nested_deprecated(linfo, IFLA_INFO_MAX, nla, ifla_info_policy, NULL) < 0)
1801 ifla_info_policy, NULL) < 0)
1802 return NULL; 1801 return NULL;
1803 1802
1804 if (linfo[IFLA_INFO_KIND]) { 1803 if (linfo[IFLA_INFO_KIND]) {
@@ -1897,8 +1896,9 @@ static int rtnl_valid_dump_ifinfo_req(const struct nlmsghdr *nlh,
1897 return -EINVAL; 1896 return -EINVAL;
1898 } 1897 }
1899 1898
1900 return nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFLA_MAX, 1899 return nlmsg_parse_deprecated_strict(nlh, sizeof(*ifm), tb,
1901 ifla_policy, extack); 1900 IFLA_MAX, ifla_policy,
1901 extack);
1902 } 1902 }
1903 1903
1904 /* A hack to preserve kernel<->userspace interface. 1904 /* A hack to preserve kernel<->userspace interface.
@@ -1911,7 +1911,8 @@ static int rtnl_valid_dump_ifinfo_req(const struct nlmsghdr *nlh,
1911 hdrlen = nlmsg_len(nlh) < sizeof(struct ifinfomsg) ? 1911 hdrlen = nlmsg_len(nlh) < sizeof(struct ifinfomsg) ?
1912 sizeof(struct rtgenmsg) : sizeof(struct ifinfomsg); 1912 sizeof(struct rtgenmsg) : sizeof(struct ifinfomsg);
1913 1913
1914 return nlmsg_parse(nlh, hdrlen, tb, IFLA_MAX, ifla_policy, extack); 1914 return nlmsg_parse_deprecated(nlh, hdrlen, tb, IFLA_MAX, ifla_policy,
1915 extack);
1915} 1916}
1916 1917
1917static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) 1918static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
@@ -2019,7 +2020,8 @@ out_err:
2019int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len, 2020int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
2020 struct netlink_ext_ack *exterr) 2021 struct netlink_ext_ack *exterr)
2021{ 2022{
2022 return nla_parse(tb, IFLA_MAX, head, len, ifla_policy, exterr); 2023 return nla_parse_deprecated(tb, IFLA_MAX, head, len, ifla_policy,
2024 exterr);
2023} 2025}
2024EXPORT_SYMBOL(rtnl_nla_parse_ifla); 2026EXPORT_SYMBOL(rtnl_nla_parse_ifla);
2025 2027
@@ -2564,8 +2566,10 @@ static int do_setlink(const struct sk_buff *skb,
2564 err = -EINVAL; 2566 err = -EINVAL;
2565 goto errout; 2567 goto errout;
2566 } 2568 }
2567 err = nla_parse_nested(vfinfo, IFLA_VF_MAX, attr, 2569 err = nla_parse_nested_deprecated(vfinfo, IFLA_VF_MAX,
2568 ifla_vf_policy, NULL); 2570 attr,
2571 ifla_vf_policy,
2572 NULL);
2569 if (err < 0) 2573 if (err < 0)
2570 goto errout; 2574 goto errout;
2571 err = do_setvfinfo(dev, vfinfo); 2575 err = do_setvfinfo(dev, vfinfo);
@@ -2592,8 +2596,10 @@ static int do_setlink(const struct sk_buff *skb,
2592 err = -EINVAL; 2596 err = -EINVAL;
2593 goto errout; 2597 goto errout;
2594 } 2598 }
2595 err = nla_parse_nested(port, IFLA_PORT_MAX, attr, 2599 err = nla_parse_nested_deprecated(port, IFLA_PORT_MAX,
2596 ifla_port_policy, NULL); 2600 attr,
2601 ifla_port_policy,
2602 NULL);
2597 if (err < 0) 2603 if (err < 0)
2598 goto errout; 2604 goto errout;
2599 if (!port[IFLA_PORT_VF]) { 2605 if (!port[IFLA_PORT_VF]) {
@@ -2612,9 +2618,9 @@ static int do_setlink(const struct sk_buff *skb,
2612 if (tb[IFLA_PORT_SELF]) { 2618 if (tb[IFLA_PORT_SELF]) {
2613 struct nlattr *port[IFLA_PORT_MAX+1]; 2619 struct nlattr *port[IFLA_PORT_MAX+1];
2614 2620
2615 err = nla_parse_nested(port, IFLA_PORT_MAX, 2621 err = nla_parse_nested_deprecated(port, IFLA_PORT_MAX,
2616 tb[IFLA_PORT_SELF], ifla_port_policy, 2622 tb[IFLA_PORT_SELF],
2617 NULL); 2623 ifla_port_policy, NULL);
2618 if (err < 0) 2624 if (err < 0)
2619 goto errout; 2625 goto errout;
2620 2626
@@ -2661,8 +2667,9 @@ static int do_setlink(const struct sk_buff *skb,
2661 struct nlattr *xdp[IFLA_XDP_MAX + 1]; 2667 struct nlattr *xdp[IFLA_XDP_MAX + 1];
2662 u32 xdp_flags = 0; 2668 u32 xdp_flags = 0;
2663 2669
2664 err = nla_parse_nested(xdp, IFLA_XDP_MAX, tb[IFLA_XDP], 2670 err = nla_parse_nested_deprecated(xdp, IFLA_XDP_MAX,
2665 ifla_xdp_policy, NULL); 2671 tb[IFLA_XDP],
2672 ifla_xdp_policy, NULL);
2666 if (err < 0) 2673 if (err < 0)
2667 goto errout; 2674 goto errout;
2668 2675
@@ -2716,8 +2723,8 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh,
2716 struct nlattr *tb[IFLA_MAX+1]; 2723 struct nlattr *tb[IFLA_MAX+1];
2717 char ifname[IFNAMSIZ]; 2724 char ifname[IFNAMSIZ];
2718 2725
2719 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy, 2726 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFLA_MAX,
2720 extack); 2727 ifla_policy, extack);
2721 if (err < 0) 2728 if (err < 0)
2722 goto errout; 2729 goto errout;
2723 2730
@@ -2813,7 +2820,8 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
2813 int err; 2820 int err;
2814 int netnsid = -1; 2821 int netnsid = -1;
2815 2822
2816 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy, extack); 2823 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFLA_MAX,
2824 ifla_policy, extack);
2817 if (err < 0) 2825 if (err < 0)
2818 return err; 2826 return err;
2819 2827
@@ -2990,7 +2998,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
2990#ifdef CONFIG_MODULES 2998#ifdef CONFIG_MODULES
2991replay: 2999replay:
2992#endif 3000#endif
2993 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy, extack); 3001 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFLA_MAX,
3002 ifla_policy, extack);
2994 if (err < 0) 3003 if (err < 0)
2995 return err; 3004 return err;
2996 3005
@@ -3024,9 +3033,9 @@ replay:
3024 return err; 3033 return err;
3025 3034
3026 if (tb[IFLA_LINKINFO]) { 3035 if (tb[IFLA_LINKINFO]) {
3027 err = nla_parse_nested(linkinfo, IFLA_INFO_MAX, 3036 err = nla_parse_nested_deprecated(linkinfo, IFLA_INFO_MAX,
3028 tb[IFLA_LINKINFO], ifla_info_policy, 3037 tb[IFLA_LINKINFO],
3029 NULL); 3038 ifla_info_policy, NULL);
3030 if (err < 0) 3039 if (err < 0)
3031 return err; 3040 return err;
3032 } else 3041 } else
@@ -3046,9 +3055,9 @@ replay:
3046 return -EINVAL; 3055 return -EINVAL;
3047 3056
3048 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) { 3057 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
3049 err = nla_parse_nested(attr, ops->maxtype, 3058 err = nla_parse_nested_deprecated(attr, ops->maxtype,
3050 linkinfo[IFLA_INFO_DATA], 3059 linkinfo[IFLA_INFO_DATA],
3051 ops->policy, extack); 3060 ops->policy, extack);
3052 if (err < 0) 3061 if (err < 0)
3053 return err; 3062 return err;
3054 data = attr; 3063 data = attr;
@@ -3067,9 +3076,11 @@ replay:
3067 3076
3068 if (m_ops->slave_maxtype && 3077 if (m_ops->slave_maxtype &&
3069 linkinfo[IFLA_INFO_SLAVE_DATA]) { 3078 linkinfo[IFLA_INFO_SLAVE_DATA]) {
3070 err = nla_parse_nested(slave_attr, m_ops->slave_maxtype, 3079 err = nla_parse_nested_deprecated(slave_attr,
3071 linkinfo[IFLA_INFO_SLAVE_DATA], 3080 m_ops->slave_maxtype,
3072 m_ops->slave_policy, extack); 3081 linkinfo[IFLA_INFO_SLAVE_DATA],
3082 m_ops->slave_policy,
3083 extack);
3073 if (err < 0) 3084 if (err < 0)
3074 return err; 3085 return err;
3075 slave_data = slave_attr; 3086 slave_data = slave_attr;
@@ -3250,8 +3261,8 @@ static int rtnl_valid_getlink_req(struct sk_buff *skb,
3250 } 3261 }
3251 3262
3252 if (!netlink_strict_get_check(skb)) 3263 if (!netlink_strict_get_check(skb))
3253 return nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy, 3264 return nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFLA_MAX,
3254 extack); 3265 ifla_policy, extack);
3255 3266
3256 ifm = nlmsg_data(nlh); 3267 ifm = nlmsg_data(nlh);
3257 if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || 3268 if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags ||
@@ -3260,8 +3271,8 @@ static int rtnl_valid_getlink_req(struct sk_buff *skb,
3260 return -EINVAL; 3271 return -EINVAL;
3261 } 3272 }
3262 3273
3263 err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy, 3274 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*ifm), tb, IFLA_MAX,
3264 extack); 3275 ifla_policy, extack);
3265 if (err) 3276 if (err)
3266 return err; 3277 return err;
3267 3278
@@ -3366,7 +3377,7 @@ static u16 rtnl_calcit(struct sk_buff *skb, struct nlmsghdr *nlh)
3366 hdrlen = nlmsg_len(nlh) < sizeof(struct ifinfomsg) ? 3377 hdrlen = nlmsg_len(nlh) < sizeof(struct ifinfomsg) ?
3367 sizeof(struct rtgenmsg) : sizeof(struct ifinfomsg); 3378 sizeof(struct rtgenmsg) : sizeof(struct ifinfomsg);
3368 3379
3369 if (nlmsg_parse(nlh, hdrlen, tb, IFLA_MAX, ifla_policy, NULL) >= 0) { 3380 if (nlmsg_parse_deprecated(nlh, hdrlen, tb, IFLA_MAX, ifla_policy, NULL) >= 0) {
3370 if (tb[IFLA_EXT_MASK]) 3381 if (tb[IFLA_EXT_MASK])
3371 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]); 3382 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
3372 } 3383 }
@@ -3569,7 +3580,7 @@ errout:
3569 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err); 3580 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
3570} 3581}
3571 3582
3572/** 3583/*
3573 * ndo_dflt_fdb_add - default netdevice operation to add an FDB entry 3584 * ndo_dflt_fdb_add - default netdevice operation to add an FDB entry
3574 */ 3585 */
3575int ndo_dflt_fdb_add(struct ndmsg *ndm, 3586int ndo_dflt_fdb_add(struct ndmsg *ndm,
@@ -3639,7 +3650,8 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
3639 u16 vid; 3650 u16 vid;
3640 int err; 3651 int err;
3641 3652
3642 err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL, extack); 3653 err = nlmsg_parse_deprecated(nlh, sizeof(*ndm), tb, NDA_MAX, NULL,
3654 extack);
3643 if (err < 0) 3655 if (err < 0)
3644 return err; 3656 return err;
3645 3657
@@ -3708,7 +3720,7 @@ out:
3708 return err; 3720 return err;
3709} 3721}
3710 3722
3711/** 3723/*
3712 * ndo_dflt_fdb_del - default netdevice operation to delete an FDB entry 3724 * ndo_dflt_fdb_del - default netdevice operation to delete an FDB entry
3713 */ 3725 */
3714int ndo_dflt_fdb_del(struct ndmsg *ndm, 3726int ndo_dflt_fdb_del(struct ndmsg *ndm,
@@ -3749,7 +3761,8 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
3749 if (!netlink_capable(skb, CAP_NET_ADMIN)) 3761 if (!netlink_capable(skb, CAP_NET_ADMIN))
3750 return -EPERM; 3762 return -EPERM;
3751 3763
3752 err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL, extack); 3764 err = nlmsg_parse_deprecated(nlh, sizeof(*ndm), tb, NDA_MAX, NULL,
3765 extack);
3753 if (err < 0) 3766 if (err < 0)
3754 return err; 3767 return err;
3755 3768
@@ -3847,8 +3860,11 @@ skip:
3847 3860
3848/** 3861/**
3849 * ndo_dflt_fdb_dump - default netdevice operation to dump an FDB table. 3862 * ndo_dflt_fdb_dump - default netdevice operation to dump an FDB table.
3850 * @nlh: netlink message header 3863 * @skb: socket buffer to store message in
3864 * @cb: netlink callback
3851 * @dev: netdevice 3865 * @dev: netdevice
3866 * @filter_dev: ignored
3867 * @idx: the number of FDB table entries dumped is added to *@idx
3852 * 3868 *
3853 * Default netdevice operation to dump the existing unicast address list. 3869 * Default netdevice operation to dump the existing unicast address list.
3854 * Returns number of addresses from list put in skb. 3870 * Returns number of addresses from list put in skb.
@@ -3895,8 +3911,8 @@ static int valid_fdb_dump_strict(const struct nlmsghdr *nlh,
3895 return -EINVAL; 3911 return -EINVAL;
3896 } 3912 }
3897 3913
3898 err = nlmsg_parse_strict(nlh, sizeof(struct ndmsg), tb, NDA_MAX, 3914 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct ndmsg), tb,
3899 NULL, extack); 3915 NDA_MAX, NULL, extack);
3900 if (err < 0) 3916 if (err < 0)
3901 return err; 3917 return err;
3902 3918
@@ -3948,8 +3964,9 @@ static int valid_fdb_dump_legacy(const struct nlmsghdr *nlh,
3948 nla_attr_size(sizeof(u32)))) { 3964 nla_attr_size(sizeof(u32)))) {
3949 struct ifinfomsg *ifm; 3965 struct ifinfomsg *ifm;
3950 3966
3951 err = nlmsg_parse(nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX, 3967 err = nlmsg_parse_deprecated(nlh, sizeof(struct ifinfomsg),
3952 ifla_policy, extack); 3968 tb, IFLA_MAX, ifla_policy,
3969 extack);
3953 if (err < 0) { 3970 if (err < 0) {
3954 return -EINVAL; 3971 return -EINVAL;
3955 } else if (err == 0) { 3972 } else if (err == 0) {
@@ -4088,8 +4105,8 @@ static int valid_fdb_get_strict(const struct nlmsghdr *nlh,
4088 return -EINVAL; 4105 return -EINVAL;
4089 } 4106 }
4090 4107
4091 err = nlmsg_parse_strict(nlh, sizeof(struct ndmsg), tb, NDA_MAX, 4108 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct ndmsg), tb,
4092 nda_policy, extack); 4109 NDA_MAX, nda_policy, extack);
4093 if (err < 0) 4110 if (err < 0)
4094 return err; 4111 return err;
4095 4112
@@ -4270,7 +4287,7 @@ int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4270 nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev)))) 4287 nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))))
4271 goto nla_put_failure; 4288 goto nla_put_failure;
4272 4289
4273 br_afspec = nla_nest_start(skb, IFLA_AF_SPEC); 4290 br_afspec = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
4274 if (!br_afspec) 4291 if (!br_afspec)
4275 goto nla_put_failure; 4292 goto nla_put_failure;
4276 4293
@@ -4294,7 +4311,7 @@ int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4294 } 4311 }
4295 nla_nest_end(skb, br_afspec); 4312 nla_nest_end(skb, br_afspec);
4296 4313
4297 protinfo = nla_nest_start(skb, IFLA_PROTINFO | NLA_F_NESTED); 4314 protinfo = nla_nest_start(skb, IFLA_PROTINFO);
4298 if (!protinfo) 4315 if (!protinfo)
4299 goto nla_put_failure; 4316 goto nla_put_failure;
4300 4317
@@ -4351,11 +4368,14 @@ static int valid_bridge_getlink_req(const struct nlmsghdr *nlh,
4351 return -EINVAL; 4368 return -EINVAL;
4352 } 4369 }
4353 4370
4354 err = nlmsg_parse_strict(nlh, sizeof(struct ifinfomsg), tb, 4371 err = nlmsg_parse_deprecated_strict(nlh,
4355 IFLA_MAX, ifla_policy, extack); 4372 sizeof(struct ifinfomsg),
4373 tb, IFLA_MAX, ifla_policy,
4374 extack);
4356 } else { 4375 } else {
4357 err = nlmsg_parse(nlh, sizeof(struct ifinfomsg), tb, 4376 err = nlmsg_parse_deprecated(nlh, sizeof(struct ifinfomsg),
4358 IFLA_MAX, ifla_policy, extack); 4377 tb, IFLA_MAX, ifla_policy,
4378 extack);
4359 } 4379 }
4360 if (err < 0) 4380 if (err < 0)
4361 return err; 4381 return err;
@@ -4773,8 +4793,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4773 4793
4774 if (ops && ops->fill_linkxstats) { 4794 if (ops && ops->fill_linkxstats) {
4775 *idxattr = IFLA_STATS_LINK_XSTATS; 4795 *idxattr = IFLA_STATS_LINK_XSTATS;
4776 attr = nla_nest_start(skb, 4796 attr = nla_nest_start_noflag(skb,
4777 IFLA_STATS_LINK_XSTATS); 4797 IFLA_STATS_LINK_XSTATS);
4778 if (!attr) 4798 if (!attr)
4779 goto nla_put_failure; 4799 goto nla_put_failure;
4780 4800
@@ -4796,8 +4816,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4796 ops = master->rtnl_link_ops; 4816 ops = master->rtnl_link_ops;
4797 if (ops && ops->fill_linkxstats) { 4817 if (ops && ops->fill_linkxstats) {
4798 *idxattr = IFLA_STATS_LINK_XSTATS_SLAVE; 4818 *idxattr = IFLA_STATS_LINK_XSTATS_SLAVE;
4799 attr = nla_nest_start(skb, 4819 attr = nla_nest_start_noflag(skb,
4800 IFLA_STATS_LINK_XSTATS_SLAVE); 4820 IFLA_STATS_LINK_XSTATS_SLAVE);
4801 if (!attr) 4821 if (!attr)
4802 goto nla_put_failure; 4822 goto nla_put_failure;
4803 4823
@@ -4812,7 +4832,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4812 if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS, 4832 if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS,
4813 *idxattr)) { 4833 *idxattr)) {
4814 *idxattr = IFLA_STATS_LINK_OFFLOAD_XSTATS; 4834 *idxattr = IFLA_STATS_LINK_OFFLOAD_XSTATS;
4815 attr = nla_nest_start(skb, IFLA_STATS_LINK_OFFLOAD_XSTATS); 4835 attr = nla_nest_start_noflag(skb,
4836 IFLA_STATS_LINK_OFFLOAD_XSTATS);
4816 if (!attr) 4837 if (!attr)
4817 goto nla_put_failure; 4838 goto nla_put_failure;
4818 4839
@@ -4831,7 +4852,7 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4831 struct rtnl_af_ops *af_ops; 4852 struct rtnl_af_ops *af_ops;
4832 4853
4833 *idxattr = IFLA_STATS_AF_SPEC; 4854 *idxattr = IFLA_STATS_AF_SPEC;
4834 attr = nla_nest_start(skb, IFLA_STATS_AF_SPEC); 4855 attr = nla_nest_start_noflag(skb, IFLA_STATS_AF_SPEC);
4835 if (!attr) 4856 if (!attr)
4836 goto nla_put_failure; 4857 goto nla_put_failure;
4837 4858
@@ -4841,7 +4862,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
4841 struct nlattr *af; 4862 struct nlattr *af;
4842 int err; 4863 int err;
4843 4864
4844 af = nla_nest_start(skb, af_ops->family); 4865 af = nla_nest_start_noflag(skb,
4866 af_ops->family);
4845 if (!af) { 4867 if (!af) {
4846 rcu_read_unlock(); 4868 rcu_read_unlock();
4847 goto nla_put_failure; 4869 goto nla_put_failure;
@@ -4948,7 +4970,7 @@ static int rtnl_valid_stats_req(const struct nlmsghdr *nlh, bool strict_check,
4948{ 4970{
4949 struct if_stats_msg *ifsm; 4971 struct if_stats_msg *ifsm;
4950 4972
4951 if (nlh->nlmsg_len < sizeof(*ifsm)) { 4973 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifsm))) {
4952 NL_SET_ERR_MSG(extack, "Invalid header for stats dump"); 4974 NL_SET_ERR_MSG(extack, "Invalid header for stats dump");
4953 return -EINVAL; 4975 return -EINVAL;
4954 } 4976 }
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ef2cd5712098..e89be6282693 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -77,6 +77,8 @@
77#include <linux/capability.h> 77#include <linux/capability.h>
78#include <linux/user_namespace.h> 78#include <linux/user_namespace.h>
79 79
80#include "datagram.h"
81
80struct kmem_cache *skbuff_head_cache __ro_after_init; 82struct kmem_cache *skbuff_head_cache __ro_after_init;
81static struct kmem_cache *skbuff_fclone_cache __ro_after_init; 83static struct kmem_cache *skbuff_fclone_cache __ro_after_init;
82#ifdef CONFIG_SKB_EXTENSIONS 84#ifdef CONFIG_SKB_EXTENSIONS
@@ -256,6 +258,33 @@ nodata:
256} 258}
257EXPORT_SYMBOL(__alloc_skb); 259EXPORT_SYMBOL(__alloc_skb);
258 260
261/* Caller must provide SKB that is memset cleared */
262static struct sk_buff *__build_skb_around(struct sk_buff *skb,
263 void *data, unsigned int frag_size)
264{
265 struct skb_shared_info *shinfo;
266 unsigned int size = frag_size ? : ksize(data);
267
268 size -= SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
269
270 /* Assumes caller memset cleared SKB */
271 skb->truesize = SKB_TRUESIZE(size);
272 refcount_set(&skb->users, 1);
273 skb->head = data;
274 skb->data = data;
275 skb_reset_tail_pointer(skb);
276 skb->end = skb->tail + size;
277 skb->mac_header = (typeof(skb->mac_header))~0U;
278 skb->transport_header = (typeof(skb->transport_header))~0U;
279
280 /* make sure we initialize shinfo sequentially */
281 shinfo = skb_shinfo(skb);
282 memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
283 atomic_set(&shinfo->dataref, 1);
284
285 return skb;
286}
287
259/** 288/**
260 * __build_skb - build a network buffer 289 * __build_skb - build a network buffer
261 * @data: data buffer provided by caller 290 * @data: data buffer provided by caller
@@ -277,32 +306,15 @@ EXPORT_SYMBOL(__alloc_skb);
277 */ 306 */
278struct sk_buff *__build_skb(void *data, unsigned int frag_size) 307struct sk_buff *__build_skb(void *data, unsigned int frag_size)
279{ 308{
280 struct skb_shared_info *shinfo;
281 struct sk_buff *skb; 309 struct sk_buff *skb;
282 unsigned int size = frag_size ? : ksize(data);
283 310
284 skb = kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC); 311 skb = kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC);
285 if (!skb) 312 if (unlikely(!skb))
286 return NULL; 313 return NULL;
287 314
288 size -= SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
289
290 memset(skb, 0, offsetof(struct sk_buff, tail)); 315 memset(skb, 0, offsetof(struct sk_buff, tail));
291 skb->truesize = SKB_TRUESIZE(size);
292 refcount_set(&skb->users, 1);
293 skb->head = data;
294 skb->data = data;
295 skb_reset_tail_pointer(skb);
296 skb->end = skb->tail + size;
297 skb->mac_header = (typeof(skb->mac_header))~0U;
298 skb->transport_header = (typeof(skb->transport_header))~0U;
299
300 /* make sure we initialize shinfo sequentially */
301 shinfo = skb_shinfo(skb);
302 memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
303 atomic_set(&shinfo->dataref, 1);
304 316
305 return skb; 317 return __build_skb_around(skb, data, frag_size);
306} 318}
307 319
308/* build_skb() is wrapper over __build_skb(), that specifically 320/* build_skb() is wrapper over __build_skb(), that specifically
@@ -323,6 +335,29 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
323} 335}
324EXPORT_SYMBOL(build_skb); 336EXPORT_SYMBOL(build_skb);
325 337
338/**
339 * build_skb_around - build a network buffer around provided skb
340 * @skb: sk_buff provide by caller, must be memset cleared
341 * @data: data buffer provided by caller
342 * @frag_size: size of data, or 0 if head was kmalloced
343 */
344struct sk_buff *build_skb_around(struct sk_buff *skb,
345 void *data, unsigned int frag_size)
346{
347 if (unlikely(!skb))
348 return NULL;
349
350 skb = __build_skb_around(skb, data, frag_size);
351
352 if (skb && frag_size) {
353 skb->head_frag = 1;
354 if (page_is_pfmemalloc(virt_to_head_page(data)))
355 skb->pfmemalloc = 1;
356 }
357 return skb;
358}
359EXPORT_SYMBOL(build_skb_around);
360
326#define NAPI_SKB_CACHE_SIZE 64 361#define NAPI_SKB_CACHE_SIZE 64
327 362
328struct napi_alloc_cache { 363struct napi_alloc_cache {
@@ -1105,9 +1140,6 @@ void sock_zerocopy_put_abort(struct ubuf_info *uarg, bool have_uref)
1105} 1140}
1106EXPORT_SYMBOL_GPL(sock_zerocopy_put_abort); 1141EXPORT_SYMBOL_GPL(sock_zerocopy_put_abort);
1107 1142
1108extern int __zerocopy_sg_from_iter(struct sock *sk, struct sk_buff *skb,
1109 struct iov_iter *from, size_t length);
1110
1111int skb_zerocopy_iter_dgram(struct sk_buff *skb, struct msghdr *msg, int len) 1143int skb_zerocopy_iter_dgram(struct sk_buff *skb, struct msghdr *msg, int len)
1112{ 1144{
1113 return __zerocopy_sg_from_iter(skb->sk, skb, &msg->msg_iter, len); 1145 return __zerocopy_sg_from_iter(skb->sk, skb, &msg->msg_iter, len);
@@ -5083,7 +5115,8 @@ EXPORT_SYMBOL_GPL(skb_gso_validate_mac_len);
5083 5115
5084static struct sk_buff *skb_reorder_vlan_header(struct sk_buff *skb) 5116static struct sk_buff *skb_reorder_vlan_header(struct sk_buff *skb)
5085{ 5117{
5086 int mac_len; 5118 int mac_len, meta_len;
5119 void *meta;
5087 5120
5088 if (skb_cow(skb, skb_headroom(skb)) < 0) { 5121 if (skb_cow(skb, skb_headroom(skb)) < 0) {
5089 kfree_skb(skb); 5122 kfree_skb(skb);
@@ -5095,6 +5128,13 @@ static struct sk_buff *skb_reorder_vlan_header(struct sk_buff *skb)
5095 memmove(skb_mac_header(skb) + VLAN_HLEN, skb_mac_header(skb), 5128 memmove(skb_mac_header(skb) + VLAN_HLEN, skb_mac_header(skb),
5096 mac_len - VLAN_HLEN - ETH_TLEN); 5129 mac_len - VLAN_HLEN - ETH_TLEN);
5097 } 5130 }
5131
5132 meta_len = skb_metadata_len(skb);
5133 if (meta_len) {
5134 meta = skb_metadata_end(skb) - meta_len;
5135 memmove(meta + VLAN_HLEN, meta, meta_len);
5136 }
5137
5098 skb->mac_header += VLAN_HLEN; 5138 skb->mac_header += VLAN_HLEN;
5099 return skb; 5139 return skb;
5100} 5140}
diff --git a/net/core/sock.c b/net/core/sock.c
index 782343bb925b..75b1c950b49f 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -137,6 +137,7 @@
137 137
138#include <linux/filter.h> 138#include <linux/filter.h>
139#include <net/sock_reuseport.h> 139#include <net/sock_reuseport.h>
140#include <net/bpf_sk_storage.h>
140 141
141#include <trace/events/sock.h> 142#include <trace/events/sock.h>
142 143
@@ -348,7 +349,7 @@ static int sock_get_timeout(long timeo, void *optval, bool old_timeval)
348 tv.tv_usec = ((timeo % HZ) * USEC_PER_SEC) / HZ; 349 tv.tv_usec = ((timeo % HZ) * USEC_PER_SEC) / HZ;
349 } 350 }
350 351
351 if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) { 352 if (old_timeval && in_compat_syscall() && !COMPAT_USE_64BIT_TIME) {
352 struct old_timeval32 tv32 = { tv.tv_sec, tv.tv_usec }; 353 struct old_timeval32 tv32 = { tv.tv_sec, tv.tv_usec };
353 *(struct old_timeval32 *)optval = tv32; 354 *(struct old_timeval32 *)optval = tv32;
354 return sizeof(tv32); 355 return sizeof(tv32);
@@ -372,7 +373,7 @@ static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen, bool
372{ 373{
373 struct __kernel_sock_timeval tv; 374 struct __kernel_sock_timeval tv;
374 375
375 if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) { 376 if (old_timeval && in_compat_syscall() && !COMPAT_USE_64BIT_TIME) {
376 struct old_timeval32 tv32; 377 struct old_timeval32 tv32;
377 378
378 if (optlen < sizeof(tv32)) 379 if (optlen < sizeof(tv32))
@@ -1709,6 +1710,10 @@ static void __sk_destruct(struct rcu_head *head)
1709 1710
1710 sock_disable_timestamp(sk, SK_FLAGS_TIMESTAMP); 1711 sock_disable_timestamp(sk, SK_FLAGS_TIMESTAMP);
1711 1712
1713#ifdef CONFIG_BPF_SYSCALL
1714 bpf_sk_storage_free(sk);
1715#endif
1716
1712 if (atomic_read(&sk->sk_omem_alloc)) 1717 if (atomic_read(&sk->sk_omem_alloc))
1713 pr_debug("%s: optmem leakage (%d bytes) detected\n", 1718 pr_debug("%s: optmem leakage (%d bytes) detected\n",
1714 __func__, atomic_read(&sk->sk_omem_alloc)); 1719 __func__, atomic_read(&sk->sk_omem_alloc));
@@ -2977,39 +2982,44 @@ bool lock_sock_fast(struct sock *sk)
2977} 2982}
2978EXPORT_SYMBOL(lock_sock_fast); 2983EXPORT_SYMBOL(lock_sock_fast);
2979 2984
2980int sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp) 2985int sock_gettstamp(struct socket *sock, void __user *userstamp,
2986 bool timeval, bool time32)
2981{ 2987{
2982 struct timeval tv; 2988 struct sock *sk = sock->sk;
2989 struct timespec64 ts;
2983 2990
2984 sock_enable_timestamp(sk, SOCK_TIMESTAMP); 2991 sock_enable_timestamp(sk, SOCK_TIMESTAMP);
2985 tv = ktime_to_timeval(sock_read_timestamp(sk)); 2992 ts = ktime_to_timespec64(sock_read_timestamp(sk));
2986 if (tv.tv_sec == -1) 2993 if (ts.tv_sec == -1)
2987 return -ENOENT; 2994 return -ENOENT;
2988 if (tv.tv_sec == 0) { 2995 if (ts.tv_sec == 0) {
2989 ktime_t kt = ktime_get_real(); 2996 ktime_t kt = ktime_get_real();
2990 sock_write_timestamp(sk, kt); 2997 sock_write_timestamp(sk, kt);;
2991 tv = ktime_to_timeval(kt); 2998 ts = ktime_to_timespec64(kt);
2992 } 2999 }
2993 return copy_to_user(userstamp, &tv, sizeof(tv)) ? -EFAULT : 0;
2994}
2995EXPORT_SYMBOL(sock_get_timestamp);
2996 3000
2997int sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp) 3001 if (timeval)
2998{ 3002 ts.tv_nsec /= 1000;
2999 struct timespec ts;
3000 3003
3001 sock_enable_timestamp(sk, SOCK_TIMESTAMP); 3004#ifdef CONFIG_COMPAT_32BIT_TIME
3002 ts = ktime_to_timespec(sock_read_timestamp(sk)); 3005 if (time32)
3003 if (ts.tv_sec == -1) 3006 return put_old_timespec32(&ts, userstamp);
3004 return -ENOENT; 3007#endif
3005 if (ts.tv_sec == 0) { 3008#ifdef CONFIG_SPARC64
3006 ktime_t kt = ktime_get_real(); 3009 /* beware of padding in sparc64 timeval */
3007 sock_write_timestamp(sk, kt); 3010 if (timeval && !in_compat_syscall()) {
3008 ts = ktime_to_timespec(sk->sk_stamp); 3011 struct __kernel_old_timeval __user tv = {
3012 .tv_sec = ts.tv_sec,
3013 .tv_usec = ts.tv_nsec,
3014 };
3015 if (copy_to_user(userstamp, &tv, sizeof(tv)))
3016 return -EFAULT;
3017 return 0;
3009 } 3018 }
3010 return copy_to_user(userstamp, &ts, sizeof(ts)) ? -EFAULT : 0; 3019#endif
3020 return put_timespec64(&ts, userstamp);
3011} 3021}
3012EXPORT_SYMBOL(sock_get_timestampns); 3022EXPORT_SYMBOL(sock_gettstamp);
3013 3023
3014void sock_enable_timestamp(struct sock *sk, int flag) 3024void sock_enable_timestamp(struct sock *sk, int flag)
3015{ 3025{
diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index d8fe3e549373..dc4aefdf2a08 100644
--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -144,6 +144,8 @@ static void reuseport_free_rcu(struct rcu_head *head)
144 * reuseport_add_sock - Add a socket to the reuseport group of another. 144 * reuseport_add_sock - Add a socket to the reuseport group of another.
145 * @sk: New socket to add to the group. 145 * @sk: New socket to add to the group.
146 * @sk2: Socket belonging to the existing reuseport group. 146 * @sk2: Socket belonging to the existing reuseport group.
147 * @bind_inany: Whether or not the group is bound to a local INANY address.
148 *
147 * May return ENOMEM and not add socket to group under memory pressure. 149 * May return ENOMEM and not add socket to group under memory pressure.
148 */ 150 */
149int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany) 151int reuseport_add_sock(struct sock *sk, struct sock *sk2, bool bind_inany)
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 84bf2861f45f..1a2685694abd 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -95,12 +95,12 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
95 if (sock_table != orig_sock_table) { 95 if (sock_table != orig_sock_table) {
96 rcu_assign_pointer(rps_sock_flow_table, sock_table); 96 rcu_assign_pointer(rps_sock_flow_table, sock_table);
97 if (sock_table) { 97 if (sock_table) {
98 static_key_slow_inc(&rps_needed); 98 static_branch_inc(&rps_needed);
99 static_key_slow_inc(&rfs_needed); 99 static_branch_inc(&rfs_needed);
100 } 100 }
101 if (orig_sock_table) { 101 if (orig_sock_table) {
102 static_key_slow_dec(&rps_needed); 102 static_branch_dec(&rps_needed);
103 static_key_slow_dec(&rfs_needed); 103 static_branch_dec(&rfs_needed);
104 synchronize_rcu(); 104 synchronize_rcu();
105 vfree(orig_sock_table); 105 vfree(orig_sock_table);
106 } 106 }
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index a556cd708885..ceff9d22deea 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -241,12 +241,13 @@ static int dcbnl_getpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
241 if (!netdev->dcbnl_ops->getpfccfg) 241 if (!netdev->dcbnl_ops->getpfccfg)
242 return -EOPNOTSUPP; 242 return -EOPNOTSUPP;
243 243
244 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX, 244 ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX,
245 tb[DCB_ATTR_PFC_CFG], dcbnl_pfc_up_nest, NULL); 245 tb[DCB_ATTR_PFC_CFG],
246 dcbnl_pfc_up_nest, NULL);
246 if (ret) 247 if (ret)
247 return ret; 248 return ret;
248 249
249 nest = nla_nest_start(skb, DCB_ATTR_PFC_CFG); 250 nest = nla_nest_start_noflag(skb, DCB_ATTR_PFC_CFG);
250 if (!nest) 251 if (!nest)
251 return -EMSGSIZE; 252 return -EMSGSIZE;
252 253
@@ -299,12 +300,13 @@ static int dcbnl_getcap(struct net_device *netdev, struct nlmsghdr *nlh,
299 if (!netdev->dcbnl_ops->getcap) 300 if (!netdev->dcbnl_ops->getcap)
300 return -EOPNOTSUPP; 301 return -EOPNOTSUPP;
301 302
302 ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP], 303 ret = nla_parse_nested_deprecated(data, DCB_CAP_ATTR_MAX,
303 dcbnl_cap_nest, NULL); 304 tb[DCB_ATTR_CAP], dcbnl_cap_nest,
305 NULL);
304 if (ret) 306 if (ret)
305 return ret; 307 return ret;
306 308
307 nest = nla_nest_start(skb, DCB_ATTR_CAP); 309 nest = nla_nest_start_noflag(skb, DCB_ATTR_CAP);
308 if (!nest) 310 if (!nest)
309 return -EMSGSIZE; 311 return -EMSGSIZE;
310 312
@@ -343,12 +345,13 @@ static int dcbnl_getnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
343 if (!netdev->dcbnl_ops->getnumtcs) 345 if (!netdev->dcbnl_ops->getnumtcs)
344 return -EOPNOTSUPP; 346 return -EOPNOTSUPP;
345 347
346 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS], 348 ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX,
347 dcbnl_numtcs_nest, NULL); 349 tb[DCB_ATTR_NUMTCS],
350 dcbnl_numtcs_nest, NULL);
348 if (ret) 351 if (ret)
349 return ret; 352 return ret;
350 353
351 nest = nla_nest_start(skb, DCB_ATTR_NUMTCS); 354 nest = nla_nest_start_noflag(skb, DCB_ATTR_NUMTCS);
352 if (!nest) 355 if (!nest)
353 return -EMSGSIZE; 356 return -EMSGSIZE;
354 357
@@ -388,8 +391,9 @@ static int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
388 if (!netdev->dcbnl_ops->setnumtcs) 391 if (!netdev->dcbnl_ops->setnumtcs)
389 return -EOPNOTSUPP; 392 return -EOPNOTSUPP;
390 393
391 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS], 394 ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX,
392 dcbnl_numtcs_nest, NULL); 395 tb[DCB_ATTR_NUMTCS],
396 dcbnl_numtcs_nest, NULL);
393 if (ret) 397 if (ret)
394 return ret; 398 return ret;
395 399
@@ -447,8 +451,9 @@ static int dcbnl_getapp(struct net_device *netdev, struct nlmsghdr *nlh,
447 if (!tb[DCB_ATTR_APP]) 451 if (!tb[DCB_ATTR_APP])
448 return -EINVAL; 452 return -EINVAL;
449 453
450 ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP], 454 ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX,
451 dcbnl_app_nest, NULL); 455 tb[DCB_ATTR_APP], dcbnl_app_nest,
456 NULL);
452 if (ret) 457 if (ret)
453 return ret; 458 return ret;
454 459
@@ -479,7 +484,7 @@ static int dcbnl_getapp(struct net_device *netdev, struct nlmsghdr *nlh,
479 up = dcb_getapp(netdev, &app); 484 up = dcb_getapp(netdev, &app);
480 } 485 }
481 486
482 app_nest = nla_nest_start(skb, DCB_ATTR_APP); 487 app_nest = nla_nest_start_noflag(skb, DCB_ATTR_APP);
483 if (!app_nest) 488 if (!app_nest)
484 return -EMSGSIZE; 489 return -EMSGSIZE;
485 490
@@ -515,8 +520,9 @@ static int dcbnl_setapp(struct net_device *netdev, struct nlmsghdr *nlh,
515 if (!tb[DCB_ATTR_APP]) 520 if (!tb[DCB_ATTR_APP])
516 return -EINVAL; 521 return -EINVAL;
517 522
518 ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP], 523 ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX,
519 dcbnl_app_nest, NULL); 524 tb[DCB_ATTR_APP], dcbnl_app_nest,
525 NULL);
520 if (ret) 526 if (ret)
521 return ret; 527 return ret;
522 528
@@ -573,12 +579,13 @@ static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
573 !netdev->dcbnl_ops->getpgbwgcfgrx) 579 !netdev->dcbnl_ops->getpgbwgcfgrx)
574 return -EOPNOTSUPP; 580 return -EOPNOTSUPP;
575 581
576 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX, tb[DCB_ATTR_PG_CFG], 582 ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX,
577 dcbnl_pg_nest, NULL); 583 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest,
584 NULL);
578 if (ret) 585 if (ret)
579 return ret; 586 return ret;
580 587
581 pg_nest = nla_nest_start(skb, DCB_ATTR_PG_CFG); 588 pg_nest = nla_nest_start_noflag(skb, DCB_ATTR_PG_CFG);
582 if (!pg_nest) 589 if (!pg_nest)
583 return -EMSGSIZE; 590 return -EMSGSIZE;
584 591
@@ -593,12 +600,13 @@ static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
593 data = pg_tb[DCB_PG_ATTR_TC_ALL]; 600 data = pg_tb[DCB_PG_ATTR_TC_ALL];
594 else 601 else
595 data = pg_tb[i]; 602 data = pg_tb[i];
596 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX, data, 603 ret = nla_parse_nested_deprecated(param_tb,
597 dcbnl_tc_param_nest, NULL); 604 DCB_TC_ATTR_PARAM_MAX, data,
605 dcbnl_tc_param_nest, NULL);
598 if (ret) 606 if (ret)
599 goto err_pg; 607 goto err_pg;
600 608
601 param_nest = nla_nest_start(skb, i); 609 param_nest = nla_nest_start_noflag(skb, i);
602 if (!param_nest) 610 if (!param_nest)
603 goto err_pg; 611 goto err_pg;
604 612
@@ -730,8 +738,9 @@ static int dcbnl_setpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
730 if (!netdev->dcbnl_ops->setpfccfg) 738 if (!netdev->dcbnl_ops->setpfccfg)
731 return -EOPNOTSUPP; 739 return -EOPNOTSUPP;
732 740
733 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX, 741 ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX,
734 tb[DCB_ATTR_PFC_CFG], dcbnl_pfc_up_nest, NULL); 742 tb[DCB_ATTR_PFC_CFG],
743 dcbnl_pfc_up_nest, NULL);
735 if (ret) 744 if (ret)
736 return ret; 745 return ret;
737 746
@@ -786,8 +795,9 @@ static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
786 !netdev->dcbnl_ops->setpgbwgcfgrx) 795 !netdev->dcbnl_ops->setpgbwgcfgrx)
787 return -EOPNOTSUPP; 796 return -EOPNOTSUPP;
788 797
789 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX, tb[DCB_ATTR_PG_CFG], 798 ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX,
790 dcbnl_pg_nest, NULL); 799 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest,
800 NULL);
791 if (ret) 801 if (ret)
792 return ret; 802 return ret;
793 803
@@ -795,8 +805,10 @@ static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
795 if (!pg_tb[i]) 805 if (!pg_tb[i])
796 continue; 806 continue;
797 807
798 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX, 808 ret = nla_parse_nested_deprecated(param_tb,
799 pg_tb[i], dcbnl_tc_param_nest, NULL); 809 DCB_TC_ATTR_PARAM_MAX,
810 pg_tb[i],
811 dcbnl_tc_param_nest, NULL);
800 if (ret) 812 if (ret)
801 return ret; 813 return ret;
802 814
@@ -884,12 +896,13 @@ static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
884 !netdev->dcbnl_ops->getbcncfg) 896 !netdev->dcbnl_ops->getbcncfg)
885 return -EOPNOTSUPP; 897 return -EOPNOTSUPP;
886 898
887 ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX, tb[DCB_ATTR_BCN], 899 ret = nla_parse_nested_deprecated(bcn_tb, DCB_BCN_ATTR_MAX,
888 dcbnl_bcn_nest, NULL); 900 tb[DCB_ATTR_BCN], dcbnl_bcn_nest,
901 NULL);
889 if (ret) 902 if (ret)
890 return ret; 903 return ret;
891 904
892 bcn_nest = nla_nest_start(skb, DCB_ATTR_BCN); 905 bcn_nest = nla_nest_start_noflag(skb, DCB_ATTR_BCN);
893 if (!bcn_nest) 906 if (!bcn_nest)
894 return -EMSGSIZE; 907 return -EMSGSIZE;
895 908
@@ -943,8 +956,9 @@ static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
943 !netdev->dcbnl_ops->setbcnrp) 956 !netdev->dcbnl_ops->setbcnrp)
944 return -EOPNOTSUPP; 957 return -EOPNOTSUPP;
945 958
946 ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX, tb[DCB_ATTR_BCN], 959 ret = nla_parse_nested_deprecated(data, DCB_BCN_ATTR_MAX,
947 dcbnl_pfc_up_nest, NULL); 960 tb[DCB_ATTR_BCN], dcbnl_pfc_up_nest,
961 NULL);
948 if (ret) 962 if (ret)
949 return ret; 963 return ret;
950 964
@@ -1002,7 +1016,7 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
1002 */ 1016 */
1003 err = -EMSGSIZE; 1017 err = -EMSGSIZE;
1004 1018
1005 app = nla_nest_start(skb, app_nested_type); 1019 app = nla_nest_start_noflag(skb, app_nested_type);
1006 if (!app) 1020 if (!app)
1007 goto nla_put_failure; 1021 goto nla_put_failure;
1008 1022
@@ -1036,7 +1050,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
1036 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) 1050 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
1037 return -EMSGSIZE; 1051 return -EMSGSIZE;
1038 1052
1039 ieee = nla_nest_start(skb, DCB_ATTR_IEEE); 1053 ieee = nla_nest_start_noflag(skb, DCB_ATTR_IEEE);
1040 if (!ieee) 1054 if (!ieee)
1041 return -EMSGSIZE; 1055 return -EMSGSIZE;
1042 1056
@@ -1106,7 +1120,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
1106 return -EMSGSIZE; 1120 return -EMSGSIZE;
1107 } 1121 }
1108 1122
1109 app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE); 1123 app = nla_nest_start_noflag(skb, DCB_ATTR_IEEE_APP_TABLE);
1110 if (!app) 1124 if (!app)
1111 return -EMSGSIZE; 1125 return -EMSGSIZE;
1112 1126
@@ -1174,13 +1188,13 @@ static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
1174 u8 pgid, up_map, prio, tc_pct; 1188 u8 pgid, up_map, prio, tc_pct;
1175 const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops; 1189 const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
1176 int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG; 1190 int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG;
1177 struct nlattr *pg = nla_nest_start(skb, i); 1191 struct nlattr *pg = nla_nest_start_noflag(skb, i);
1178 1192
1179 if (!pg) 1193 if (!pg)
1180 return -EMSGSIZE; 1194 return -EMSGSIZE;
1181 1195
1182 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { 1196 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
1183 struct nlattr *tc_nest = nla_nest_start(skb, i); 1197 struct nlattr *tc_nest = nla_nest_start_noflag(skb, i);
1184 1198
1185 if (!tc_nest) 1199 if (!tc_nest)
1186 return -EMSGSIZE; 1200 return -EMSGSIZE;
@@ -1231,7 +1245,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1231 1245
1232 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) 1246 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
1233 goto nla_put_failure; 1247 goto nla_put_failure;
1234 cee = nla_nest_start(skb, DCB_ATTR_CEE); 1248 cee = nla_nest_start_noflag(skb, DCB_ATTR_CEE);
1235 if (!cee) 1249 if (!cee)
1236 goto nla_put_failure; 1250 goto nla_put_failure;
1237 1251
@@ -1250,7 +1264,8 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1250 1264
1251 /* local pfc */ 1265 /* local pfc */
1252 if (ops->getpfccfg) { 1266 if (ops->getpfccfg) {
1253 struct nlattr *pfc_nest = nla_nest_start(skb, DCB_ATTR_CEE_PFC); 1267 struct nlattr *pfc_nest = nla_nest_start_noflag(skb,
1268 DCB_ATTR_CEE_PFC);
1254 1269
1255 if (!pfc_nest) 1270 if (!pfc_nest)
1256 goto nla_put_failure; 1271 goto nla_put_failure;
@@ -1265,14 +1280,14 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1265 1280
1266 /* local app */ 1281 /* local app */
1267 spin_lock_bh(&dcb_lock); 1282 spin_lock_bh(&dcb_lock);
1268 app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE); 1283 app = nla_nest_start_noflag(skb, DCB_ATTR_CEE_APP_TABLE);
1269 if (!app) 1284 if (!app)
1270 goto dcb_unlock; 1285 goto dcb_unlock;
1271 1286
1272 list_for_each_entry(itr, &dcb_app_list, list) { 1287 list_for_each_entry(itr, &dcb_app_list, list) {
1273 if (itr->ifindex == netdev->ifindex) { 1288 if (itr->ifindex == netdev->ifindex) {
1274 struct nlattr *app_nest = nla_nest_start(skb, 1289 struct nlattr *app_nest = nla_nest_start_noflag(skb,
1275 DCB_ATTR_APP); 1290 DCB_ATTR_APP);
1276 if (!app_nest) 1291 if (!app_nest)
1277 goto dcb_unlock; 1292 goto dcb_unlock;
1278 1293
@@ -1305,7 +1320,8 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1305 1320
1306 /* features flags */ 1321 /* features flags */
1307 if (ops->getfeatcfg) { 1322 if (ops->getfeatcfg) {
1308 struct nlattr *feat = nla_nest_start(skb, DCB_ATTR_CEE_FEAT); 1323 struct nlattr *feat = nla_nest_start_noflag(skb,
1324 DCB_ATTR_CEE_FEAT);
1309 if (!feat) 1325 if (!feat)
1310 goto nla_put_failure; 1326 goto nla_put_failure;
1311 1327
@@ -1429,8 +1445,9 @@ static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
1429 if (!tb[DCB_ATTR_IEEE]) 1445 if (!tb[DCB_ATTR_IEEE])
1430 return -EINVAL; 1446 return -EINVAL;
1431 1447
1432 err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX, tb[DCB_ATTR_IEEE], 1448 err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX,
1433 dcbnl_ieee_policy, NULL); 1449 tb[DCB_ATTR_IEEE],
1450 dcbnl_ieee_policy, NULL);
1434 if (err) 1451 if (err)
1435 return err; 1452 return err;
1436 1453
@@ -1529,8 +1546,9 @@ static int dcbnl_ieee_del(struct net_device *netdev, struct nlmsghdr *nlh,
1529 if (!tb[DCB_ATTR_IEEE]) 1546 if (!tb[DCB_ATTR_IEEE])
1530 return -EINVAL; 1547 return -EINVAL;
1531 1548
1532 err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX, tb[DCB_ATTR_IEEE], 1549 err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX,
1533 dcbnl_ieee_policy, NULL); 1550 tb[DCB_ATTR_IEEE],
1551 dcbnl_ieee_policy, NULL);
1534 if (err) 1552 if (err)
1535 return err; 1553 return err;
1536 1554
@@ -1602,12 +1620,13 @@ static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
1602 if (!tb[DCB_ATTR_FEATCFG]) 1620 if (!tb[DCB_ATTR_FEATCFG])
1603 return -EINVAL; 1621 return -EINVAL;
1604 1622
1605 ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, 1623 ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX,
1606 tb[DCB_ATTR_FEATCFG], dcbnl_featcfg_nest, NULL); 1624 tb[DCB_ATTR_FEATCFG],
1625 dcbnl_featcfg_nest, NULL);
1607 if (ret) 1626 if (ret)
1608 return ret; 1627 return ret;
1609 1628
1610 nest = nla_nest_start(skb, DCB_ATTR_FEATCFG); 1629 nest = nla_nest_start_noflag(skb, DCB_ATTR_FEATCFG);
1611 if (!nest) 1630 if (!nest)
1612 return -EMSGSIZE; 1631 return -EMSGSIZE;
1613 1632
@@ -1646,8 +1665,9 @@ static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
1646 if (!tb[DCB_ATTR_FEATCFG]) 1665 if (!tb[DCB_ATTR_FEATCFG])
1647 return -EINVAL; 1666 return -EINVAL;
1648 1667
1649 ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, 1668 ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX,
1650 tb[DCB_ATTR_FEATCFG], dcbnl_featcfg_nest, NULL); 1669 tb[DCB_ATTR_FEATCFG],
1670 dcbnl_featcfg_nest, NULL);
1651 1671
1652 if (ret) 1672 if (ret)
1653 goto err; 1673 goto err;
@@ -1736,8 +1756,8 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
1736 if ((nlh->nlmsg_type == RTM_SETDCB) && !netlink_capable(skb, CAP_NET_ADMIN)) 1756 if ((nlh->nlmsg_type == RTM_SETDCB) && !netlink_capable(skb, CAP_NET_ADMIN))
1737 return -EPERM; 1757 return -EPERM;
1738 1758
1739 ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX, 1759 ret = nlmsg_parse_deprecated(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
1740 dcbnl_rtnl_policy, extack); 1760 dcbnl_rtnl_policy, extack);
1741 if (ret < 0) 1761 if (ret < 0)
1742 return ret; 1762 return ret;
1743 1763
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 26a21d97b6b0..004535e4c070 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -991,6 +991,7 @@ static const struct proto_ops inet_dccp_ops = {
991 /* FIXME: work on tcp_poll to rename it to inet_csk_poll */ 991 /* FIXME: work on tcp_poll to rename it to inet_csk_poll */
992 .poll = dccp_poll, 992 .poll = dccp_poll,
993 .ioctl = inet_ioctl, 993 .ioctl = inet_ioctl,
994 .gettstamp = sock_gettstamp,
994 /* FIXME: work on inet_listen to rename it to sock_common_listen */ 995 /* FIXME: work on inet_listen to rename it to sock_common_listen */
995 .listen = inet_dccp_listen, 996 .listen = inet_dccp_listen,
996 .shutdown = inet_shutdown, 997 .shutdown = inet_shutdown,
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 57d84e9b7b6f..c4e4d1301062 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -1075,6 +1075,7 @@ static const struct proto_ops inet6_dccp_ops = {
1075 .getname = inet6_getname, 1075 .getname = inet6_getname,
1076 .poll = dccp_poll, 1076 .poll = dccp_poll,
1077 .ioctl = inet6_ioctl, 1077 .ioctl = inet6_ioctl,
1078 .gettstamp = sock_gettstamp,
1078 .listen = inet_dccp_listen, 1079 .listen = inet_dccp_listen,
1079 .shutdown = inet_shutdown, 1080 .shutdown = inet_shutdown,
1080 .setsockopt = sock_common_setsockopt, 1081 .setsockopt = sock_common_setsockopt,
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 0e2f71ab8367..5dd85ec51bfe 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -263,7 +263,6 @@ int dccp_disconnect(struct sock *sk, int flags)
263 struct inet_connection_sock *icsk = inet_csk(sk); 263 struct inet_connection_sock *icsk = inet_csk(sk);
264 struct inet_sock *inet = inet_sk(sk); 264 struct inet_sock *inet = inet_sk(sk);
265 struct dccp_sock *dp = dccp_sk(sk); 265 struct dccp_sock *dp = dccp_sk(sk);
266 int err = 0;
267 const int old_state = sk->sk_state; 266 const int old_state = sk->sk_state;
268 267
269 if (old_state != DCCP_CLOSED) 268 if (old_state != DCCP_CLOSED)
@@ -307,7 +306,7 @@ int dccp_disconnect(struct sock *sk, int flags)
307 WARN_ON(inet->inet_num && !icsk->icsk_bind_hash); 306 WARN_ON(inet->inet_num && !icsk->icsk_bind_hash);
308 307
309 sk->sk_error_report(sk); 308 sk->sk_error_report(sk);
310 return err; 309 return 0;
311} 310}
312 311
313EXPORT_SYMBOL_GPL(dccp_disconnect); 312EXPORT_SYMBOL_GPL(dccp_disconnect);
diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
index bdccc46a2921..c1fa4785c4c2 100644
--- a/net/decnet/af_decnet.c
+++ b/net/decnet/af_decnet.c
@@ -444,7 +444,7 @@ static void dn_destruct(struct sock *sk)
444 skb_queue_purge(&scp->other_xmit_queue); 444 skb_queue_purge(&scp->other_xmit_queue);
445 skb_queue_purge(&scp->other_receive_queue); 445 skb_queue_purge(&scp->other_receive_queue);
446 446
447 dst_release(rcu_dereference_check(sk->sk_dst_cache, 1)); 447 dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
448} 448}
449 449
450static unsigned long dn_memory_pressure; 450static unsigned long dn_memory_pressure;
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 0962f9201baa..cca7ae712995 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -583,8 +583,8 @@ static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
583 if (!net_eq(net, &init_net)) 583 if (!net_eq(net, &init_net))
584 goto errout; 584 goto errout;
585 585
586 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, dn_ifa_policy, 586 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
587 extack); 587 dn_ifa_policy, extack);
588 if (err < 0) 588 if (err < 0)
589 goto errout; 589 goto errout;
590 590
@@ -629,8 +629,8 @@ static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
629 if (!net_eq(net, &init_net)) 629 if (!net_eq(net, &init_net))
630 return -EINVAL; 630 return -EINVAL;
631 631
632 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, dn_ifa_policy, 632 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
633 extack); 633 dn_ifa_policy, extack);
634 if (err < 0) 634 if (err < 0)
635 return err; 635 return err;
636 636
diff --git a/net/decnet/dn_fib.c b/net/decnet/dn_fib.c
index 6cd3737593a6..77fbf8e9df4b 100644
--- a/net/decnet/dn_fib.c
+++ b/net/decnet/dn_fib.c
@@ -42,7 +42,7 @@
42#include <net/dn_fib.h> 42#include <net/dn_fib.h>
43#include <net/dn_neigh.h> 43#include <net/dn_neigh.h>
44#include <net/dn_dev.h> 44#include <net/dn_dev.h>
45#include <net/nexthop.h> 45#include <net/rtnh.h>
46 46
47#define RT_MIN_TABLE 1 47#define RT_MIN_TABLE 1
48 48
@@ -517,8 +517,8 @@ static int dn_fib_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
517 if (!net_eq(net, &init_net)) 517 if (!net_eq(net, &init_net))
518 return -EINVAL; 518 return -EINVAL;
519 519
520 err = nlmsg_parse(nlh, sizeof(*r), attrs, RTA_MAX, rtm_dn_policy, 520 err = nlmsg_parse_deprecated(nlh, sizeof(*r), attrs, RTA_MAX,
521 extack); 521 rtm_dn_policy, extack);
522 if (err < 0) 522 if (err < 0)
523 return err; 523 return err;
524 524
@@ -544,8 +544,8 @@ static int dn_fib_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
544 if (!net_eq(net, &init_net)) 544 if (!net_eq(net, &init_net))
545 return -EINVAL; 545 return -EINVAL;
546 546
547 err = nlmsg_parse(nlh, sizeof(*r), attrs, RTA_MAX, rtm_dn_policy, 547 err = nlmsg_parse_deprecated(nlh, sizeof(*r), attrs, RTA_MAX,
548 extack); 548 rtm_dn_policy, extack);
549 if (err < 0) 549 if (err < 0)
550 return err; 550 return err;
551 551
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 950613ee7881..664584763c36 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1651,8 +1651,8 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
1651 if (!net_eq(net, &init_net)) 1651 if (!net_eq(net, &init_net))
1652 return -EINVAL; 1652 return -EINVAL;
1653 1653
1654 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_dn_policy, 1654 err = nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
1655 extack); 1655 rtm_dn_policy, extack);
1656 if (err < 0) 1656 if (err < 0)
1657 return err; 1657 return err;
1658 1658
diff --git a/net/decnet/dn_table.c b/net/decnet/dn_table.c
index f0710b5d037d..33fefb0aebca 100644
--- a/net/decnet/dn_table.c
+++ b/net/decnet/dn_table.c
@@ -348,7 +348,8 @@ static int dn_fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
348 struct rtnexthop *nhp; 348 struct rtnexthop *nhp;
349 struct nlattr *mp_head; 349 struct nlattr *mp_head;
350 350
351 if (!(mp_head = nla_nest_start(skb, RTA_MULTIPATH))) 351 mp_head = nla_nest_start_noflag(skb, RTA_MULTIPATH);
352 if (!mp_head)
352 goto errout; 353 goto errout;
353 354
354 for_nexthops(fi) { 355 for_nexthops(fi) {
diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index 76338c38738a..19aa32fc1802 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -94,8 +94,6 @@ int dns_query(const char *type, const char *name, size_t namelen,
94 desclen += typelen + 1; 94 desclen += typelen + 1;
95 } 95 }
96 96
97 if (!namelen)
98 namelen = strnlen(name, 256);
99 if (namelen < 3 || namelen > 255) 97 if (namelen < 3 || namelen > 255)
100 return -EINVAL; 98 return -EINVAL;
101 desclen += namelen + 1; 99 desclen += namelen + 1;
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index fab49132345f..cf855352a440 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -4,60 +4,117 @@ config HAVE_NET_DSA
4 4
5# Drivers must select NET_DSA and the appropriate tagging format 5# Drivers must select NET_DSA and the appropriate tagging format
6 6
7config NET_DSA 7menuconfig NET_DSA
8 tristate "Distributed Switch Architecture" 8 tristate "Distributed Switch Architecture"
9 depends on HAVE_NET_DSA 9 depends on HAVE_NET_DSA
10 depends on BRIDGE || BRIDGE=n 10 depends on BRIDGE || BRIDGE=n
11 select NET_SWITCHDEV 11 select NET_SWITCHDEV
12 select PHYLINK 12 select PHYLINK
13 select NET_DEVLINK
13 ---help--- 14 ---help---
14 Say Y if you want to enable support for the hardware switches supported 15 Say Y if you want to enable support for the hardware switches supported
15 by the Distributed Switch Architecture. 16 by the Distributed Switch Architecture.
16 17
17if NET_DSA 18if NET_DSA
18 19
19config NET_DSA_LEGACY 20# tagging formats
20 bool "Support for older platform device and Device Tree registration" 21config NET_DSA_TAG_8021Q
21 default y 22 tristate "Tag driver for switches using custom 802.1Q VLAN headers"
22 ---help--- 23 select VLAN_8021Q
23 Say Y if you want to enable support for the older platform device and 24 help
24 deprecated Device Tree binding registration. 25 Unlike the other tagging protocols, the 802.1Q config option simply
26 provides helpers for other tagging implementations that might rely on
27 VLAN in one way or another. It is not a complete solution.
25 28
26 This feature is scheduled for removal in 4.17. 29 Drivers which use these helpers should select this as dependency.
30
31config NET_DSA_TAG_BRCM_COMMON
32 tristate
33 default n
27 34
28# tagging formats
29config NET_DSA_TAG_BRCM 35config NET_DSA_TAG_BRCM
30 bool 36 tristate "Tag driver for Broadcom switches using in-frame headers"
37 select NET_DSA_TAG_BRCM_COMMON
38 help
39 Say Y if you want to enable support for tagging frames for the
40 Broadcom switches which place the tag after the MAC source address.
41
31 42
32config NET_DSA_TAG_BRCM_PREPEND 43config NET_DSA_TAG_BRCM_PREPEND
33 bool 44 tristate "Tag driver for Broadcom switches using prepended headers"
45 select NET_DSA_TAG_BRCM_COMMON
46 help
47 Say Y if you want to enable support for tagging frames for the
48 Broadcom switches which places the tag before the Ethernet header
49 (prepended).
50
51config NET_DSA_TAG_GSWIP
52 tristate "Tag driver for Lantiq / Intel GSWIP switches"
53 help
54 Say Y or M if you want to enable support for tagging frames for the
55 Lantiq / Intel GSWIP switches.
34 56
35config NET_DSA_TAG_DSA 57config NET_DSA_TAG_DSA
36 bool 58 tristate "Tag driver for Marvell switches using DSA headers"
59 help
60 Say Y or M if you want to enable support for tagging frames for the
61 Marvell switches which use DSA headers.
37 62
38config NET_DSA_TAG_EDSA 63config NET_DSA_TAG_EDSA
39 bool 64 tristate "Tag driver for Marvell switches using EtherType DSA headers"
65 help
66 Say Y or M if you want to enable support for tagging frames for the
67 Marvell switches which use EtherType DSA headers.
40 68
41config NET_DSA_TAG_GSWIP 69config NET_DSA_TAG_MTK
42 bool 70 tristate "Tag driver for Mediatek switches"
71 help
72 Say Y or M if you want to enable support for tagging frames for
73 Mediatek switches.
74
75config NET_DSA_TAG_KSZ_COMMON
76 tristate
77 default n
43 78
44config NET_DSA_TAG_KSZ 79config NET_DSA_TAG_KSZ
45 bool 80 tristate "Tag driver for Microchip 9893 family of switches"
81 select NET_DSA_TAG_KSZ_COMMON
82 help
83 Say Y if you want to enable support for tagging frames for the
84 Microchip 9893 family of switches.
46 85
47config NET_DSA_TAG_KSZ9477 86config NET_DSA_TAG_KSZ9477
48 bool 87 tristate "Tag driver for Microchip 9477 family of switches"
49 select NET_DSA_TAG_KSZ 88 select NET_DSA_TAG_KSZ_COMMON
89 help
90 Say Y if you want to enable support for tagging frames for the
91 Microchip 9477 family of switches.
50 92
51config NET_DSA_TAG_LAN9303 93config NET_DSA_TAG_QCA
52 bool 94 tristate "Tag driver for Qualcomm Atheros QCA8K switches"
95 help
96 Say Y or M if you want to enable support for tagging frames for
97 the Qualcomm Atheros QCA8K switches.
53 98
54config NET_DSA_TAG_MTK 99config NET_DSA_TAG_LAN9303
55 bool 100 tristate "Tag driver for SMSC/Microchip LAN9303 family of switches"
101 help
102 Say Y or M if you want to enable support for tagging frames for the
103 SMSC/Microchip LAN9303 family of switches.
104
105config NET_DSA_TAG_SJA1105
106 tristate "Tag driver for NXP SJA1105 switches"
107 select NET_DSA_TAG_8021Q
108 help
109 Say Y or M if you want to enable support for tagging frames with the
110 NXP SJA1105 switch family. Both the native tagging protocol (which
111 is only for link-local traffic) as well as non-native tagging (based
112 on a custom 802.1Q VLAN header) are available.
56 113
57config NET_DSA_TAG_TRAILER 114config NET_DSA_TAG_TRAILER
58 bool 115 tristate "Tag driver for switches using a trailer tag"
59 116 help
60config NET_DSA_TAG_QCA 117 Say Y or M if you want to enable support for tagging frames at
61 bool 118 with a trailed. e.g. Marvell 88E6060.
62 119
63endif 120endif
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 6e721f7a2947..c342f54715ba 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -2,16 +2,16 @@
2# the core 2# the core
3obj-$(CONFIG_NET_DSA) += dsa_core.o 3obj-$(CONFIG_NET_DSA) += dsa_core.o
4dsa_core-y += dsa.o dsa2.o master.o port.o slave.o switch.o 4dsa_core-y += dsa.o dsa2.o master.o port.o slave.o switch.o
5dsa_core-$(CONFIG_NET_DSA_LEGACY) += legacy.o
6 5
7# tagging formats 6# tagging formats
8dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o 7obj-$(CONFIG_NET_DSA_TAG_8021Q) += tag_8021q.o
9dsa_core-$(CONFIG_NET_DSA_TAG_BRCM_PREPEND) += tag_brcm.o 8obj-$(CONFIG_NET_DSA_TAG_BRCM_COMMON) += tag_brcm.o
10dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o 9obj-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
11dsa_core-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o 10obj-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o
12dsa_core-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o 11obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o
13dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o 12obj-$(CONFIG_NET_DSA_TAG_KSZ_COMMON) += tag_ksz.o
14dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o 13obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
15dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o 14obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
16dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o 15obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
17dsa_core-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o 16obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o
17obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 36de4f2a3366..1fc782fab393 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -27,6 +27,9 @@
27 27
28#include "dsa_priv.h" 28#include "dsa_priv.h"
29 29
30static LIST_HEAD(dsa_tag_drivers_list);
31static DEFINE_MUTEX(dsa_tag_drivers_lock);
32
30static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb, 33static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
31 struct net_device *dev) 34 struct net_device *dev)
32{ 35{
@@ -35,106 +38,103 @@ static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
35} 38}
36 39
37static const struct dsa_device_ops none_ops = { 40static const struct dsa_device_ops none_ops = {
41 .name = "none",
42 .proto = DSA_TAG_PROTO_NONE,
38 .xmit = dsa_slave_notag_xmit, 43 .xmit = dsa_slave_notag_xmit,
39 .rcv = NULL, 44 .rcv = NULL,
40}; 45};
41 46
42const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = { 47DSA_TAG_DRIVER(none_ops);
43#ifdef CONFIG_NET_DSA_TAG_BRCM
44 [DSA_TAG_PROTO_BRCM] = &brcm_netdev_ops,
45#endif
46#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
47 [DSA_TAG_PROTO_BRCM_PREPEND] = &brcm_prepend_netdev_ops,
48#endif
49#ifdef CONFIG_NET_DSA_TAG_DSA
50 [DSA_TAG_PROTO_DSA] = &dsa_netdev_ops,
51#endif
52#ifdef CONFIG_NET_DSA_TAG_EDSA
53 [DSA_TAG_PROTO_EDSA] = &edsa_netdev_ops,
54#endif
55#ifdef CONFIG_NET_DSA_TAG_GSWIP
56 [DSA_TAG_PROTO_GSWIP] = &gswip_netdev_ops,
57#endif
58#ifdef CONFIG_NET_DSA_TAG_KSZ9477
59 [DSA_TAG_PROTO_KSZ9477] = &ksz9477_netdev_ops,
60 [DSA_TAG_PROTO_KSZ9893] = &ksz9893_netdev_ops,
61#endif
62#ifdef CONFIG_NET_DSA_TAG_LAN9303
63 [DSA_TAG_PROTO_LAN9303] = &lan9303_netdev_ops,
64#endif
65#ifdef CONFIG_NET_DSA_TAG_MTK
66 [DSA_TAG_PROTO_MTK] = &mtk_netdev_ops,
67#endif
68#ifdef CONFIG_NET_DSA_TAG_QCA
69 [DSA_TAG_PROTO_QCA] = &qca_netdev_ops,
70#endif
71#ifdef CONFIG_NET_DSA_TAG_TRAILER
72 [DSA_TAG_PROTO_TRAILER] = &trailer_netdev_ops,
73#endif
74 [DSA_TAG_PROTO_NONE] = &none_ops,
75};
76 48
77const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops) 49static void dsa_tag_driver_register(struct dsa_tag_driver *dsa_tag_driver,
50 struct module *owner)
51{
52 dsa_tag_driver->owner = owner;
53
54 mutex_lock(&dsa_tag_drivers_lock);
55 list_add_tail(&dsa_tag_driver->list, &dsa_tag_drivers_list);
56 mutex_unlock(&dsa_tag_drivers_lock);
57}
58
59void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
60 unsigned int count, struct module *owner)
78{ 61{
79 const char *protocol_name[DSA_TAG_LAST] = {
80#ifdef CONFIG_NET_DSA_TAG_BRCM
81 [DSA_TAG_PROTO_BRCM] = "brcm",
82#endif
83#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
84 [DSA_TAG_PROTO_BRCM_PREPEND] = "brcm-prepend",
85#endif
86#ifdef CONFIG_NET_DSA_TAG_DSA
87 [DSA_TAG_PROTO_DSA] = "dsa",
88#endif
89#ifdef CONFIG_NET_DSA_TAG_EDSA
90 [DSA_TAG_PROTO_EDSA] = "edsa",
91#endif
92#ifdef CONFIG_NET_DSA_TAG_GSWIP
93 [DSA_TAG_PROTO_GSWIP] = "gswip",
94#endif
95#ifdef CONFIG_NET_DSA_TAG_KSZ9477
96 [DSA_TAG_PROTO_KSZ9477] = "ksz9477",
97 [DSA_TAG_PROTO_KSZ9893] = "ksz9893",
98#endif
99#ifdef CONFIG_NET_DSA_TAG_LAN9303
100 [DSA_TAG_PROTO_LAN9303] = "lan9303",
101#endif
102#ifdef CONFIG_NET_DSA_TAG_MTK
103 [DSA_TAG_PROTO_MTK] = "mtk",
104#endif
105#ifdef CONFIG_NET_DSA_TAG_QCA
106 [DSA_TAG_PROTO_QCA] = "qca",
107#endif
108#ifdef CONFIG_NET_DSA_TAG_TRAILER
109 [DSA_TAG_PROTO_TRAILER] = "trailer",
110#endif
111 [DSA_TAG_PROTO_NONE] = "none",
112 };
113 unsigned int i; 62 unsigned int i;
114 63
115 BUILD_BUG_ON(ARRAY_SIZE(protocol_name) != DSA_TAG_LAST); 64 for (i = 0; i < count; i++)
65 dsa_tag_driver_register(dsa_tag_driver_array[i], owner);
66}
116 67
117 for (i = 0; i < ARRAY_SIZE(dsa_device_ops); i++) 68static void dsa_tag_driver_unregister(struct dsa_tag_driver *dsa_tag_driver)
118 if (ops == dsa_device_ops[i]) 69{
119 return protocol_name[i]; 70 mutex_lock(&dsa_tag_drivers_lock);
71 list_del(&dsa_tag_driver->list);
72 mutex_unlock(&dsa_tag_drivers_lock);
73}
74EXPORT_SYMBOL_GPL(dsa_tag_drivers_register);
120 75
121 return protocol_name[DSA_TAG_PROTO_NONE]; 76void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
77 unsigned int count)
78{
79 unsigned int i;
80
81 for (i = 0; i < count; i++)
82 dsa_tag_driver_unregister(dsa_tag_driver_array[i]);
83}
84EXPORT_SYMBOL_GPL(dsa_tag_drivers_unregister);
85
86const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
87{
88 return ops->name;
122}; 89};
123 90
124const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol) 91const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol)
125{ 92{
93 struct dsa_tag_driver *dsa_tag_driver;
126 const struct dsa_device_ops *ops; 94 const struct dsa_device_ops *ops;
95 char module_name[128];
96 bool found = false;
97
98 snprintf(module_name, 127, "%s%d", DSA_TAG_DRIVER_ALIAS,
99 tag_protocol);
100
101 request_module(module_name);
102
103 mutex_lock(&dsa_tag_drivers_lock);
104 list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) {
105 ops = dsa_tag_driver->ops;
106 if (ops->proto == tag_protocol) {
107 found = true;
108 break;
109 }
110 }
127 111
128 if (tag_protocol >= DSA_TAG_LAST) 112 if (found) {
129 return ERR_PTR(-EINVAL); 113 if (!try_module_get(dsa_tag_driver->owner))
130 ops = dsa_device_ops[tag_protocol]; 114 ops = ERR_PTR(-ENOPROTOOPT);
115 } else {
116 ops = ERR_PTR(-ENOPROTOOPT);
117 }
131 118
132 if (!ops) 119 mutex_unlock(&dsa_tag_drivers_lock);
133 return ERR_PTR(-ENOPROTOOPT);
134 120
135 return ops; 121 return ops;
136} 122}
137 123
124void dsa_tag_driver_put(const struct dsa_device_ops *ops)
125{
126 struct dsa_tag_driver *dsa_tag_driver;
127
128 mutex_lock(&dsa_tag_drivers_lock);
129 list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) {
130 if (dsa_tag_driver->ops == ops) {
131 module_put(dsa_tag_driver->owner);
132 break;
133 }
134 }
135 mutex_unlock(&dsa_tag_drivers_lock);
136}
137
138static int dev_is_class(struct device *dev, void *class) 138static int dev_is_class(struct device *dev, void *class)
139{ 139{
140 if (dev->class != NULL && !strcmp(dev->class->name, class)) 140 if (dev->class != NULL && !strcmp(dev->class->name, class))
@@ -344,23 +344,28 @@ static int __init dsa_init_module(void)
344 344
345 rc = dsa_slave_register_notifier(); 345 rc = dsa_slave_register_notifier();
346 if (rc) 346 if (rc)
347 return rc; 347 goto register_notifier_fail;
348
349 rc = dsa_legacy_register();
350 if (rc)
351 return rc;
352 348
353 dev_add_pack(&dsa_pack_type); 349 dev_add_pack(&dsa_pack_type);
354 350
351 dsa_tag_driver_register(&DSA_TAG_DRIVER_NAME(none_ops),
352 THIS_MODULE);
353
355 return 0; 354 return 0;
355
356register_notifier_fail:
357 destroy_workqueue(dsa_owq);
358
359 return rc;
356} 360}
357module_init(dsa_init_module); 361module_init(dsa_init_module);
358 362
359static void __exit dsa_cleanup_module(void) 363static void __exit dsa_cleanup_module(void)
360{ 364{
365 dsa_tag_driver_unregister(&DSA_TAG_DRIVER_NAME(none_ops));
366
361 dsa_slave_unregister_notifier(); 367 dsa_slave_unregister_notifier();
362 dev_remove_pack(&dsa_pack_type); 368 dev_remove_pack(&dsa_pack_type);
363 dsa_legacy_unregister();
364 destroy_workqueue(dsa_owq); 369 destroy_workqueue(dsa_owq);
365} 370}
366module_exit(dsa_cleanup_module); 371module_exit(dsa_cleanup_module);
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index c00ee464afc7..3b5f434cad3f 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -18,6 +18,7 @@
18#include <linux/rtnetlink.h> 18#include <linux/rtnetlink.h>
19#include <linux/of.h> 19#include <linux/of.h>
20#include <linux/of_net.h> 20#include <linux/of_net.h>
21#include <net/devlink.h>
21 22
22#include "dsa_priv.h" 23#include "dsa_priv.h"
23 24
@@ -257,14 +258,39 @@ static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)
257 258
258static int dsa_port_setup(struct dsa_port *dp) 259static int dsa_port_setup(struct dsa_port *dp)
259{ 260{
261 enum devlink_port_flavour flavour;
260 struct dsa_switch *ds = dp->ds; 262 struct dsa_switch *ds = dp->ds;
261 int err = 0; 263 struct dsa_switch_tree *dst = ds->dst;
264 int err;
265
266 if (dp->type == DSA_PORT_TYPE_UNUSED)
267 return 0;
262 268
263 memset(&dp->devlink_port, 0, sizeof(dp->devlink_port)); 269 memset(&dp->devlink_port, 0, sizeof(dp->devlink_port));
270 dp->mac = of_get_mac_address(dp->dn);
264 271
265 if (dp->type != DSA_PORT_TYPE_UNUSED) 272 switch (dp->type) {
266 err = devlink_port_register(ds->devlink, &dp->devlink_port, 273 case DSA_PORT_TYPE_CPU:
267 dp->index); 274 flavour = DEVLINK_PORT_FLAVOUR_CPU;
275 break;
276 case DSA_PORT_TYPE_DSA:
277 flavour = DEVLINK_PORT_FLAVOUR_DSA;
278 break;
279 case DSA_PORT_TYPE_USER: /* fall-through */
280 default:
281 flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
282 break;
283 }
284
285 /* dp->index is used now as port_number. However
286 * CPU and DSA ports should have separate numbering
287 * independent from front panel port numbers.
288 */
289 devlink_port_attrs_set(&dp->devlink_port, flavour,
290 dp->index, false, 0,
291 (const char *) &dst->index, sizeof(dst->index));
292 err = devlink_port_register(ds->devlink, &dp->devlink_port,
293 dp->index);
268 if (err) 294 if (err)
269 return err; 295 return err;
270 296
@@ -272,13 +298,6 @@ static int dsa_port_setup(struct dsa_port *dp)
272 case DSA_PORT_TYPE_UNUSED: 298 case DSA_PORT_TYPE_UNUSED:
273 break; 299 break;
274 case DSA_PORT_TYPE_CPU: 300 case DSA_PORT_TYPE_CPU:
275 /* dp->index is used now as port_number. However
276 * CPU ports should have separate numbering
277 * independent from front panel port numbers.
278 */
279 devlink_port_attrs_set(&dp->devlink_port,
280 DEVLINK_PORT_FLAVOUR_CPU,
281 dp->index, false, 0);
282 err = dsa_port_link_register_of(dp); 301 err = dsa_port_link_register_of(dp);
283 if (err) { 302 if (err) {
284 dev_err(ds->dev, "failed to setup link for port %d.%d\n", 303 dev_err(ds->dev, "failed to setup link for port %d.%d\n",
@@ -287,13 +306,6 @@ static int dsa_port_setup(struct dsa_port *dp)
287 } 306 }
288 break; 307 break;
289 case DSA_PORT_TYPE_DSA: 308 case DSA_PORT_TYPE_DSA:
290 /* dp->index is used now as port_number. However
291 * DSA ports should have separate numbering
292 * independent from front panel port numbers.
293 */
294 devlink_port_attrs_set(&dp->devlink_port,
295 DEVLINK_PORT_FLAVOUR_DSA,
296 dp->index, false, 0);
297 err = dsa_port_link_register_of(dp); 309 err = dsa_port_link_register_of(dp);
298 if (err) { 310 if (err) {
299 dev_err(ds->dev, "failed to setup link for port %d.%d\n", 311 dev_err(ds->dev, "failed to setup link for port %d.%d\n",
@@ -302,9 +314,6 @@ static int dsa_port_setup(struct dsa_port *dp)
302 } 314 }
303 break; 315 break;
304 case DSA_PORT_TYPE_USER: 316 case DSA_PORT_TYPE_USER:
305 devlink_port_attrs_set(&dp->devlink_port,
306 DEVLINK_PORT_FLAVOUR_PHYSICAL,
307 dp->index, false, 0);
308 err = dsa_slave_create(dp); 317 err = dsa_slave_create(dp);
309 if (err) 318 if (err)
310 dev_err(ds->dev, "failed to create slave for port %d.%d\n", 319 dev_err(ds->dev, "failed to create slave for port %d.%d\n",
@@ -326,6 +335,8 @@ static void dsa_port_teardown(struct dsa_port *dp)
326 case DSA_PORT_TYPE_UNUSED: 335 case DSA_PORT_TYPE_UNUSED:
327 break; 336 break;
328 case DSA_PORT_TYPE_CPU: 337 case DSA_PORT_TYPE_CPU:
338 dsa_tag_driver_put(dp->tag_ops);
339 /* fall-through */
329 case DSA_PORT_TYPE_DSA: 340 case DSA_PORT_TYPE_DSA:
330 dsa_port_link_unregister_of(dp); 341 dsa_port_link_unregister_of(dp);
331 break; 342 break;
@@ -360,14 +371,14 @@ static int dsa_switch_setup(struct dsa_switch *ds)
360 if (err) 371 if (err)
361 return err; 372 return err;
362 373
363 err = ds->ops->setup(ds);
364 if (err < 0)
365 return err;
366
367 err = dsa_switch_register_notifier(ds); 374 err = dsa_switch_register_notifier(ds);
368 if (err) 375 if (err)
369 return err; 376 return err;
370 377
378 err = ds->ops->setup(ds);
379 if (err < 0)
380 return err;
381
371 if (!ds->slave_mii_bus && ds->ops->phy_read) { 382 if (!ds->slave_mii_bus && ds->ops->phy_read) {
372 ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev); 383 ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
373 if (!ds->slave_mii_bus) 384 if (!ds->slave_mii_bus)
@@ -568,13 +579,14 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master)
568 enum dsa_tag_protocol tag_protocol; 579 enum dsa_tag_protocol tag_protocol;
569 580
570 tag_protocol = ds->ops->get_tag_protocol(ds, dp->index); 581 tag_protocol = ds->ops->get_tag_protocol(ds, dp->index);
571 tag_ops = dsa_resolve_tag_protocol(tag_protocol); 582 tag_ops = dsa_tag_driver_get(tag_protocol);
572 if (IS_ERR(tag_ops)) { 583 if (IS_ERR(tag_ops)) {
573 dev_warn(ds->dev, "No tagger for this switch\n"); 584 dev_warn(ds->dev, "No tagger for this switch\n");
574 return PTR_ERR(tag_ops); 585 return PTR_ERR(tag_ops);
575 } 586 }
576 587
577 dp->type = DSA_PORT_TYPE_CPU; 588 dp->type = DSA_PORT_TYPE_CPU;
589 dp->filter = tag_ops->filter;
578 dp->rcv = tag_ops->rcv; 590 dp->rcv = tag_ops->rcv;
579 dp->tag_ops = tag_ops; 591 dp->tag_ops = tag_ops;
580 dp->master = master; 592 dp->master = master;
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 093b7d145eb1..8f1222324646 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -84,22 +84,12 @@ struct dsa_slave_priv {
84}; 84};
85 85
86/* dsa.c */ 86/* dsa.c */
87const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol); 87const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol);
88void dsa_tag_driver_put(const struct dsa_device_ops *ops);
89
88bool dsa_schedule_work(struct work_struct *work); 90bool dsa_schedule_work(struct work_struct *work);
89const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops); 91const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
90 92
91/* legacy.c */
92#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
93int dsa_legacy_register(void);
94void dsa_legacy_unregister(void);
95#else
96static inline int dsa_legacy_register(void)
97{
98 return 0;
99}
100
101static inline void dsa_legacy_unregister(void) { }
102#endif
103int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], 93int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
104 struct net_device *dev, 94 struct net_device *dev,
105 const unsigned char *addr, u16 vid, 95 const unsigned char *addr, u16 vid,
@@ -169,6 +159,8 @@ int dsa_port_vlan_add(struct dsa_port *dp,
169 struct switchdev_trans *trans); 159 struct switchdev_trans *trans);
170int dsa_port_vlan_del(struct dsa_port *dp, 160int dsa_port_vlan_del(struct dsa_port *dp,
171 const struct switchdev_obj_port_vlan *vlan); 161 const struct switchdev_obj_port_vlan *vlan);
162int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags);
163int dsa_port_vid_del(struct dsa_port *dp, u16 vid);
172int dsa_port_link_register_of(struct dsa_port *dp); 164int dsa_port_link_register_of(struct dsa_port *dp);
173void dsa_port_link_unregister_of(struct dsa_port *dp); 165void dsa_port_link_unregister_of(struct dsa_port *dp);
174 166
@@ -182,6 +174,8 @@ int dsa_slave_resume(struct net_device *slave_dev);
182int dsa_slave_register_notifier(void); 174int dsa_slave_register_notifier(void);
183void dsa_slave_unregister_notifier(void); 175void dsa_slave_unregister_notifier(void);
184 176
177void *dsa_defer_xmit(struct sk_buff *skb, struct net_device *dev);
178
185static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev) 179static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
186{ 180{
187 struct dsa_slave_priv *p = netdev_priv(dev); 181 struct dsa_slave_priv *p = netdev_priv(dev);
@@ -200,34 +194,4 @@ dsa_slave_to_master(const struct net_device *dev)
200/* switch.c */ 194/* switch.c */
201int dsa_switch_register_notifier(struct dsa_switch *ds); 195int dsa_switch_register_notifier(struct dsa_switch *ds);
202void dsa_switch_unregister_notifier(struct dsa_switch *ds); 196void dsa_switch_unregister_notifier(struct dsa_switch *ds);
203
204/* tag_brcm.c */
205extern const struct dsa_device_ops brcm_netdev_ops;
206extern const struct dsa_device_ops brcm_prepend_netdev_ops;
207
208/* tag_dsa.c */
209extern const struct dsa_device_ops dsa_netdev_ops;
210
211/* tag_edsa.c */
212extern const struct dsa_device_ops edsa_netdev_ops;
213
214/* tag_gswip.c */
215extern const struct dsa_device_ops gswip_netdev_ops;
216
217/* tag_ksz.c */
218extern const struct dsa_device_ops ksz9477_netdev_ops;
219extern const struct dsa_device_ops ksz9893_netdev_ops;
220
221/* tag_lan9303.c */
222extern const struct dsa_device_ops lan9303_netdev_ops;
223
224/* tag_mtk.c */
225extern const struct dsa_device_ops mtk_netdev_ops;
226
227/* tag_qca.c */
228extern const struct dsa_device_ops qca_netdev_ops;
229
230/* tag_trailer.c */
231extern const struct dsa_device_ops trailer_netdev_ops;
232
233#endif 197#endif
diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
deleted file mode 100644
index cb42939db776..000000000000
--- a/net/dsa/legacy.c
+++ /dev/null
@@ -1,745 +0,0 @@
1/*
2 * net/dsa/legacy.c - Hardware switch handling
3 * Copyright (c) 2008-2009 Marvell Semiconductor
4 * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/device.h>
13#include <linux/list.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
16#include <linux/module.h>
17#include <linux/of.h>
18#include <linux/of_mdio.h>
19#include <linux/of_platform.h>
20#include <linux/of_net.h>
21#include <linux/netdevice.h>
22#include <linux/sysfs.h>
23#include <linux/phy_fixed.h>
24#include <linux/etherdevice.h>
25
26#include "dsa_priv.h"
27
28/* switch driver registration ***********************************************/
29static DEFINE_MUTEX(dsa_switch_drivers_mutex);
30static LIST_HEAD(dsa_switch_drivers);
31
32void register_switch_driver(struct dsa_switch_driver *drv)
33{
34 mutex_lock(&dsa_switch_drivers_mutex);
35 list_add_tail(&drv->list, &dsa_switch_drivers);
36 mutex_unlock(&dsa_switch_drivers_mutex);
37}
38EXPORT_SYMBOL_GPL(register_switch_driver);
39
40void unregister_switch_driver(struct dsa_switch_driver *drv)
41{
42 mutex_lock(&dsa_switch_drivers_mutex);
43 list_del_init(&drv->list);
44 mutex_unlock(&dsa_switch_drivers_mutex);
45}
46EXPORT_SYMBOL_GPL(unregister_switch_driver);
47
48static const struct dsa_switch_ops *
49dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
50 const char **_name, void **priv)
51{
52 const struct dsa_switch_ops *ret;
53 struct list_head *list;
54 const char *name;
55
56 ret = NULL;
57 name = NULL;
58
59 mutex_lock(&dsa_switch_drivers_mutex);
60 list_for_each(list, &dsa_switch_drivers) {
61 const struct dsa_switch_ops *ops;
62 struct dsa_switch_driver *drv;
63
64 drv = list_entry(list, struct dsa_switch_driver, list);
65 ops = drv->ops;
66
67 name = ops->probe(parent, host_dev, sw_addr, priv);
68 if (name != NULL) {
69 ret = ops;
70 break;
71 }
72 }
73 mutex_unlock(&dsa_switch_drivers_mutex);
74
75 *_name = name;
76
77 return ret;
78}
79
80/* basic switch operations **************************************************/
81static int dsa_cpu_dsa_setups(struct dsa_switch *ds)
82{
83 int ret, port;
84
85 for (port = 0; port < ds->num_ports; port++) {
86 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
87 continue;
88
89 ret = dsa_port_link_register_of(&ds->ports[port]);
90 if (ret)
91 return ret;
92 }
93 return 0;
94}
95
96static int dsa_switch_setup_one(struct dsa_switch *ds,
97 struct net_device *master)
98{
99 const struct dsa_switch_ops *ops = ds->ops;
100 struct dsa_switch_tree *dst = ds->dst;
101 struct dsa_chip_data *cd = ds->cd;
102 bool valid_name_found = false;
103 int index = ds->index;
104 struct dsa_port *dp;
105 int i, ret;
106
107 /*
108 * Validate supplied switch configuration.
109 */
110 for (i = 0; i < ds->num_ports; i++) {
111 char *name;
112
113 dp = &ds->ports[i];
114
115 name = cd->port_names[i];
116 if (name == NULL)
117 continue;
118 dp->name = name;
119
120 if (!strcmp(name, "cpu")) {
121 if (dst->cpu_dp) {
122 netdev_err(master,
123 "multiple cpu ports?!\n");
124 return -EINVAL;
125 }
126 dst->cpu_dp = &ds->ports[i];
127 dst->cpu_dp->master = master;
128 dp->type = DSA_PORT_TYPE_CPU;
129 } else if (!strcmp(name, "dsa")) {
130 dp->type = DSA_PORT_TYPE_DSA;
131 } else {
132 dp->type = DSA_PORT_TYPE_USER;
133 }
134 valid_name_found = true;
135 }
136
137 if (!valid_name_found && i == ds->num_ports)
138 return -EINVAL;
139
140 /* Make the built-in MII bus mask match the number of ports,
141 * switch drivers can override this later
142 */
143 ds->phys_mii_mask |= dsa_user_ports(ds);
144
145 /*
146 * If the CPU connects to this switch, set the switch tree
147 * tagging protocol to the preferred tagging format of this
148 * switch.
149 */
150 if (dst->cpu_dp->ds == ds) {
151 const struct dsa_device_ops *tag_ops;
152 enum dsa_tag_protocol tag_protocol;
153
154 tag_protocol = ops->get_tag_protocol(ds, dst->cpu_dp->index);
155 tag_ops = dsa_resolve_tag_protocol(tag_protocol);
156 if (IS_ERR(tag_ops))
157 return PTR_ERR(tag_ops);
158
159 dst->cpu_dp->tag_ops = tag_ops;
160
161 /* Few copies for faster access in master receive hot path */
162 dst->cpu_dp->rcv = dst->cpu_dp->tag_ops->rcv;
163 dst->cpu_dp->dst = dst;
164 }
165
166 memcpy(ds->rtable, cd->rtable, sizeof(ds->rtable));
167
168 /*
169 * Do basic register setup.
170 */
171 ret = ops->setup(ds);
172 if (ret < 0)
173 return ret;
174
175 ret = dsa_switch_register_notifier(ds);
176 if (ret)
177 return ret;
178
179 if (!ds->slave_mii_bus && ops->phy_read) {
180 ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
181 if (!ds->slave_mii_bus)
182 return -ENOMEM;
183 dsa_slave_mii_bus_init(ds);
184
185 ret = mdiobus_register(ds->slave_mii_bus);
186 if (ret < 0)
187 return ret;
188 }
189
190 /*
191 * Create network devices for physical switch ports.
192 */
193 for (i = 0; i < ds->num_ports; i++) {
194 ds->ports[i].dn = cd->port_dn[i];
195 ds->ports[i].cpu_dp = dst->cpu_dp;
196
197 if (!dsa_is_user_port(ds, i))
198 continue;
199
200 ret = dsa_slave_create(&ds->ports[i]);
201 if (ret < 0)
202 netdev_err(master, "[%d]: can't create dsa slave device for port %d(%s): %d\n",
203 index, i, cd->port_names[i], ret);
204 }
205
206 /* Perform configuration of the CPU and DSA ports */
207 ret = dsa_cpu_dsa_setups(ds);
208 if (ret < 0)
209 netdev_err(master, "[%d] : can't configure CPU and DSA ports\n",
210 index);
211
212 return 0;
213}
214
215static struct dsa_switch *
216dsa_switch_setup(struct dsa_switch_tree *dst, struct net_device *master,
217 int index, struct device *parent, struct device *host_dev)
218{
219 struct dsa_chip_data *cd = dst->pd->chip + index;
220 const struct dsa_switch_ops *ops;
221 struct dsa_switch *ds;
222 int ret;
223 const char *name;
224 void *priv;
225
226 /*
227 * Probe for switch model.
228 */
229 ops = dsa_switch_probe(parent, host_dev, cd->sw_addr, &name, &priv);
230 if (!ops) {
231 netdev_err(master, "[%d]: could not detect attached switch\n",
232 index);
233 return ERR_PTR(-EINVAL);
234 }
235 netdev_info(master, "[%d]: detected a %s switch\n",
236 index, name);
237
238
239 /*
240 * Allocate and initialise switch state.
241 */
242 ds = dsa_switch_alloc(parent, DSA_MAX_PORTS);
243 if (!ds)
244 return ERR_PTR(-ENOMEM);
245
246 ds->dst = dst;
247 ds->index = index;
248 ds->cd = cd;
249 ds->ops = ops;
250 ds->priv = priv;
251
252 ret = dsa_switch_setup_one(ds, master);
253 if (ret)
254 return ERR_PTR(ret);
255
256 return ds;
257}
258
259static void dsa_switch_destroy(struct dsa_switch *ds)
260{
261 int port;
262
263 /* Destroy network devices for physical switch ports. */
264 for (port = 0; port < ds->num_ports; port++) {
265 if (!dsa_is_user_port(ds, port))
266 continue;
267
268 if (!ds->ports[port].slave)
269 continue;
270
271 dsa_slave_destroy(ds->ports[port].slave);
272 }
273
274 /* Disable configuration of the CPU and DSA ports */
275 for (port = 0; port < ds->num_ports; port++) {
276 if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
277 continue;
278 dsa_port_link_unregister_of(&ds->ports[port]);
279 }
280
281 if (ds->slave_mii_bus && ds->ops->phy_read)
282 mdiobus_unregister(ds->slave_mii_bus);
283
284 dsa_switch_unregister_notifier(ds);
285}
286
287/* platform driver init and cleanup *****************************************/
288static int dev_is_class(struct device *dev, void *class)
289{
290 if (dev->class != NULL && !strcmp(dev->class->name, class))
291 return 1;
292
293 return 0;
294}
295
296static struct device *dev_find_class(struct device *parent, char *class)
297{
298 if (dev_is_class(parent, class)) {
299 get_device(parent);
300 return parent;
301 }
302
303 return device_find_child(parent, class, dev_is_class);
304}
305
306struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev)
307{
308 struct device *d;
309
310 d = dev_find_class(dev, "mdio_bus");
311 if (d != NULL) {
312 struct mii_bus *bus;
313
314 bus = to_mii_bus(d);
315 put_device(d);
316
317 return bus;
318 }
319
320 return NULL;
321}
322EXPORT_SYMBOL_GPL(dsa_host_dev_to_mii_bus);
323
324#ifdef CONFIG_OF
325static int dsa_of_setup_routing_table(struct dsa_platform_data *pd,
326 struct dsa_chip_data *cd,
327 int chip_index, int port_index,
328 struct device_node *link)
329{
330 const __be32 *reg;
331 int link_sw_addr;
332 struct device_node *parent_sw;
333 int len;
334
335 parent_sw = of_get_parent(link);
336 if (!parent_sw)
337 return -EINVAL;
338
339 reg = of_get_property(parent_sw, "reg", &len);
340 if (!reg || (len != sizeof(*reg) * 2))
341 return -EINVAL;
342
343 /*
344 * Get the destination switch number from the second field of its 'reg'
345 * property, i.e. for "reg = <0x19 1>" sw_addr is '1'.
346 */
347 link_sw_addr = be32_to_cpup(reg + 1);
348
349 if (link_sw_addr >= pd->nr_chips)
350 return -EINVAL;
351
352 cd->rtable[link_sw_addr] = port_index;
353
354 return 0;
355}
356
357static int dsa_of_probe_links(struct dsa_platform_data *pd,
358 struct dsa_chip_data *cd,
359 int chip_index, int port_index,
360 struct device_node *port,
361 const char *port_name)
362{
363 struct device_node *link;
364 int link_index;
365 int ret;
366
367 for (link_index = 0;; link_index++) {
368 link = of_parse_phandle(port, "link", link_index);
369 if (!link)
370 break;
371
372 if (!strcmp(port_name, "dsa") && pd->nr_chips > 1) {
373 ret = dsa_of_setup_routing_table(pd, cd, chip_index,
374 port_index, link);
375 if (ret)
376 return ret;
377 }
378 }
379 return 0;
380}
381
382static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
383{
384 int i;
385 int port_index;
386
387 for (i = 0; i < pd->nr_chips; i++) {
388 port_index = 0;
389 while (port_index < DSA_MAX_PORTS) {
390 kfree(pd->chip[i].port_names[port_index]);
391 port_index++;
392 }
393
394 /* Drop our reference to the MDIO bus device */
395 put_device(pd->chip[i].host_dev);
396 }
397 kfree(pd->chip);
398}
399
400static int dsa_of_probe(struct device *dev)
401{
402 struct device_node *np = dev->of_node;
403 struct device_node *child, *mdio, *ethernet, *port;
404 struct mii_bus *mdio_bus, *mdio_bus_switch;
405 struct net_device *ethernet_dev;
406 struct dsa_platform_data *pd;
407 struct dsa_chip_data *cd;
408 const char *port_name;
409 int chip_index, port_index;
410 const unsigned int *sw_addr, *port_reg;
411 u32 eeprom_len;
412 int ret;
413
414 mdio = of_parse_phandle(np, "dsa,mii-bus", 0);
415 if (!mdio)
416 return -EINVAL;
417
418 mdio_bus = of_mdio_find_bus(mdio);
419 if (!mdio_bus)
420 return -EPROBE_DEFER;
421
422 ethernet = of_parse_phandle(np, "dsa,ethernet", 0);
423 if (!ethernet) {
424 ret = -EINVAL;
425 goto out_put_mdio;
426 }
427
428 ethernet_dev = of_find_net_device_by_node(ethernet);
429 if (!ethernet_dev) {
430 ret = -EPROBE_DEFER;
431 goto out_put_mdio;
432 }
433
434 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
435 if (!pd) {
436 ret = -ENOMEM;
437 goto out_put_ethernet;
438 }
439
440 dev->platform_data = pd;
441 pd->of_netdev = ethernet_dev;
442 pd->nr_chips = of_get_available_child_count(np);
443 if (pd->nr_chips > DSA_MAX_SWITCHES)
444 pd->nr_chips = DSA_MAX_SWITCHES;
445
446 pd->chip = kcalloc(pd->nr_chips, sizeof(struct dsa_chip_data),
447 GFP_KERNEL);
448 if (!pd->chip) {
449 ret = -ENOMEM;
450 goto out_free;
451 }
452
453 chip_index = -1;
454 for_each_available_child_of_node(np, child) {
455 int i;
456
457 chip_index++;
458 cd = &pd->chip[chip_index];
459
460 cd->of_node = child;
461
462 /* Initialize the routing table */
463 for (i = 0; i < DSA_MAX_SWITCHES; ++i)
464 cd->rtable[i] = DSA_RTABLE_NONE;
465
466 /* When assigning the host device, increment its refcount */
467 cd->host_dev = get_device(&mdio_bus->dev);
468
469 sw_addr = of_get_property(child, "reg", NULL);
470 if (!sw_addr)
471 continue;
472
473 cd->sw_addr = be32_to_cpup(sw_addr);
474 if (cd->sw_addr >= PHY_MAX_ADDR)
475 continue;
476
477 if (!of_property_read_u32(child, "eeprom-length", &eeprom_len))
478 cd->eeprom_len = eeprom_len;
479
480 mdio = of_parse_phandle(child, "mii-bus", 0);
481 if (mdio) {
482 mdio_bus_switch = of_mdio_find_bus(mdio);
483 if (!mdio_bus_switch) {
484 ret = -EPROBE_DEFER;
485 goto out_free_chip;
486 }
487
488 /* Drop the mdio_bus device ref, replacing the host
489 * device with the mdio_bus_switch device, keeping
490 * the refcount from of_mdio_find_bus() above.
491 */
492 put_device(cd->host_dev);
493 cd->host_dev = &mdio_bus_switch->dev;
494 }
495
496 for_each_available_child_of_node(child, port) {
497 port_reg = of_get_property(port, "reg", NULL);
498 if (!port_reg)
499 continue;
500
501 port_index = be32_to_cpup(port_reg);
502 if (port_index >= DSA_MAX_PORTS)
503 break;
504
505 port_name = of_get_property(port, "label", NULL);
506 if (!port_name)
507 continue;
508
509 cd->port_dn[port_index] = port;
510
511 cd->port_names[port_index] = kstrdup(port_name,
512 GFP_KERNEL);
513 if (!cd->port_names[port_index]) {
514 ret = -ENOMEM;
515 goto out_free_chip;
516 }
517
518 ret = dsa_of_probe_links(pd, cd, chip_index,
519 port_index, port, port_name);
520 if (ret)
521 goto out_free_chip;
522
523 }
524 }
525
526 /* The individual chips hold their own refcount on the mdio bus,
527 * so drop ours */
528 put_device(&mdio_bus->dev);
529
530 return 0;
531
532out_free_chip:
533 dsa_of_free_platform_data(pd);
534out_free:
535 kfree(pd);
536 dev->platform_data = NULL;
537out_put_ethernet:
538 put_device(&ethernet_dev->dev);
539out_put_mdio:
540 put_device(&mdio_bus->dev);
541 return ret;
542}
543
544static void dsa_of_remove(struct device *dev)
545{
546 struct dsa_platform_data *pd = dev->platform_data;
547
548 if (!dev->of_node)
549 return;
550
551 dsa_of_free_platform_data(pd);
552 put_device(&pd->of_netdev->dev);
553 kfree(pd);
554}
555#else
556static inline int dsa_of_probe(struct device *dev)
557{
558 return 0;
559}
560
561static inline void dsa_of_remove(struct device *dev)
562{
563}
564#endif
565
566static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
567 struct device *parent, struct dsa_platform_data *pd)
568{
569 int i;
570 unsigned configured = 0;
571
572 dst->pd = pd;
573
574 for (i = 0; i < pd->nr_chips; i++) {
575 struct dsa_switch *ds;
576
577 ds = dsa_switch_setup(dst, dev, i, parent, pd->chip[i].host_dev);
578 if (IS_ERR(ds)) {
579 netdev_err(dev, "[%d]: couldn't create dsa switch instance (error %ld)\n",
580 i, PTR_ERR(ds));
581 continue;
582 }
583
584 dst->ds[i] = ds;
585
586 ++configured;
587 }
588
589 /*
590 * If no switch was found, exit cleanly
591 */
592 if (!configured)
593 return -EPROBE_DEFER;
594
595 return dsa_master_setup(dst->cpu_dp->master, dst->cpu_dp);
596}
597
598static int dsa_probe(struct platform_device *pdev)
599{
600 struct dsa_platform_data *pd = pdev->dev.platform_data;
601 struct net_device *dev;
602 struct dsa_switch_tree *dst;
603 int ret;
604
605 if (pdev->dev.of_node) {
606 ret = dsa_of_probe(&pdev->dev);
607 if (ret)
608 return ret;
609
610 pd = pdev->dev.platform_data;
611 }
612
613 if (pd == NULL || (pd->netdev == NULL && pd->of_netdev == NULL))
614 return -EINVAL;
615
616 if (pd->of_netdev) {
617 dev = pd->of_netdev;
618 dev_hold(dev);
619 } else {
620 dev = dsa_dev_to_net_device(pd->netdev);
621 }
622 if (dev == NULL) {
623 ret = -EPROBE_DEFER;
624 goto out;
625 }
626
627 if (dev->dsa_ptr != NULL) {
628 dev_put(dev);
629 ret = -EEXIST;
630 goto out;
631 }
632
633 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
634 if (dst == NULL) {
635 dev_put(dev);
636 ret = -ENOMEM;
637 goto out;
638 }
639
640 platform_set_drvdata(pdev, dst);
641
642 ret = dsa_setup_dst(dst, dev, &pdev->dev, pd);
643 if (ret) {
644 dev_put(dev);
645 goto out;
646 }
647
648 return 0;
649
650out:
651 dsa_of_remove(&pdev->dev);
652
653 return ret;
654}
655
656static void dsa_remove_dst(struct dsa_switch_tree *dst)
657{
658 int i;
659
660 dsa_master_teardown(dst->cpu_dp->master);
661
662 for (i = 0; i < dst->pd->nr_chips; i++) {
663 struct dsa_switch *ds = dst->ds[i];
664
665 if (ds)
666 dsa_switch_destroy(ds);
667 }
668
669 dev_put(dst->cpu_dp->master);
670}
671
672static int dsa_remove(struct platform_device *pdev)
673{
674 struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
675
676 dsa_remove_dst(dst);
677 dsa_of_remove(&pdev->dev);
678
679 return 0;
680}
681
682static void dsa_shutdown(struct platform_device *pdev)
683{
684}
685
686#ifdef CONFIG_PM_SLEEP
687static int dsa_suspend(struct device *d)
688{
689 struct dsa_switch_tree *dst = dev_get_drvdata(d);
690 int i, ret = 0;
691
692 for (i = 0; i < dst->pd->nr_chips; i++) {
693 struct dsa_switch *ds = dst->ds[i];
694
695 if (ds != NULL)
696 ret = dsa_switch_suspend(ds);
697 }
698
699 return ret;
700}
701
702static int dsa_resume(struct device *d)
703{
704 struct dsa_switch_tree *dst = dev_get_drvdata(d);
705 int i, ret = 0;
706
707 for (i = 0; i < dst->pd->nr_chips; i++) {
708 struct dsa_switch *ds = dst->ds[i];
709
710 if (ds != NULL)
711 ret = dsa_switch_resume(ds);
712 }
713
714 return ret;
715}
716#endif
717
718static SIMPLE_DEV_PM_OPS(dsa_pm_ops, dsa_suspend, dsa_resume);
719
720static const struct of_device_id dsa_of_match_table[] = {
721 { .compatible = "marvell,dsa", },
722 {}
723};
724MODULE_DEVICE_TABLE(of, dsa_of_match_table);
725
726static struct platform_driver dsa_driver = {
727 .probe = dsa_probe,
728 .remove = dsa_remove,
729 .shutdown = dsa_shutdown,
730 .driver = {
731 .name = "dsa",
732 .of_match_table = dsa_of_match_table,
733 .pm = &dsa_pm_ops,
734 },
735};
736
737int dsa_legacy_register(void)
738{
739 return platform_driver_register(&dsa_driver);
740}
741
742void dsa_legacy_unregister(void)
743{
744 platform_driver_unregister(&dsa_driver);
745}
diff --git a/net/dsa/port.c b/net/dsa/port.c
index caeef4c99dc0..ed8ba9daa3ba 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -154,19 +154,67 @@ void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br)
154 dsa_port_set_state_now(dp, BR_STATE_FORWARDING); 154 dsa_port_set_state_now(dp, BR_STATE_FORWARDING);
155} 155}
156 156
157static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp,
158 bool vlan_filtering)
159{
160 struct dsa_switch *ds = dp->ds;
161 int i;
162
163 if (!ds->vlan_filtering_is_global)
164 return true;
165
166 /* For cases where enabling/disabling VLAN awareness is global to the
167 * switch, we need to handle the case where multiple bridges span
168 * different ports of the same switch device and one of them has a
169 * different setting than what is being requested.
170 */
171 for (i = 0; i < ds->num_ports; i++) {
172 struct net_device *other_bridge;
173
174 other_bridge = dsa_to_port(ds, i)->bridge_dev;
175 if (!other_bridge)
176 continue;
177 /* If it's the same bridge, it also has same
178 * vlan_filtering setting => no need to check
179 */
180 if (other_bridge == dp->bridge_dev)
181 continue;
182 if (br_vlan_enabled(other_bridge) != vlan_filtering) {
183 dev_err(ds->dev, "VLAN filtering is a global setting\n");
184 return false;
185 }
186 }
187 return true;
188}
189
157int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, 190int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
158 struct switchdev_trans *trans) 191 struct switchdev_trans *trans)
159{ 192{
160 struct dsa_switch *ds = dp->ds; 193 struct dsa_switch *ds = dp->ds;
194 int err;
161 195
162 /* bridge skips -EOPNOTSUPP, so skip the prepare phase */ 196 /* bridge skips -EOPNOTSUPP, so skip the prepare phase */
163 if (switchdev_trans_ph_prepare(trans)) 197 if (switchdev_trans_ph_prepare(trans))
164 return 0; 198 return 0;
165 199
166 if (ds->ops->port_vlan_filtering) 200 if (!ds->ops->port_vlan_filtering)
167 return ds->ops->port_vlan_filtering(ds, dp->index, 201 return 0;
168 vlan_filtering); 202
203 if (!dsa_port_can_apply_vlan_filtering(dp, vlan_filtering))
204 return -EINVAL;
205
206 if (dsa_port_is_vlan_filtering(dp) == vlan_filtering)
207 return 0;
208
209 err = ds->ops->port_vlan_filtering(ds, dp->index,
210 vlan_filtering);
211 if (err)
212 return err;
169 213
214 if (ds->vlan_filtering_is_global)
215 ds->vlan_filtering = vlan_filtering;
216 else
217 dp->vlan_filtering = vlan_filtering;
170 return 0; 218 return 0;
171} 219}
172 220
@@ -322,6 +370,39 @@ int dsa_port_vlan_del(struct dsa_port *dp,
322 return 0; 370 return 0;
323} 371}
324 372
373int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags)
374{
375 struct switchdev_obj_port_vlan vlan = {
376 .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
377 .flags = flags,
378 .vid_begin = vid,
379 .vid_end = vid,
380 };
381 struct switchdev_trans trans;
382 int err;
383
384 trans.ph_prepare = true;
385 err = dsa_port_vlan_add(dp, &vlan, &trans);
386 if (err == -EOPNOTSUPP)
387 return 0;
388
389 trans.ph_prepare = false;
390 return dsa_port_vlan_add(dp, &vlan, &trans);
391}
392EXPORT_SYMBOL(dsa_port_vid_add);
393
394int dsa_port_vid_del(struct dsa_port *dp, u16 vid)
395{
396 struct switchdev_obj_port_vlan vlan = {
397 .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
398 .vid_begin = vid,
399 .vid_end = vid,
400 };
401
402 return dsa_port_vlan_del(dp, &vlan);
403}
404EXPORT_SYMBOL(dsa_port_vid_del);
405
325static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) 406static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp)
326{ 407{
327 struct device_node *phy_dn; 408 struct device_node *phy_dn;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 093eef6f2599..9892ca1f6859 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -120,6 +120,9 @@ static int dsa_slave_close(struct net_device *dev)
120 struct net_device *master = dsa_slave_to_master(dev); 120 struct net_device *master = dsa_slave_to_master(dev);
121 struct dsa_port *dp = dsa_slave_to_port(dev); 121 struct dsa_port *dp = dsa_slave_to_port(dev);
122 122
123 cancel_work_sync(&dp->xmit_work);
124 skb_queue_purge(&dp->xmit_queue);
125
123 phylink_stop(dp->pl); 126 phylink_stop(dp->pl);
124 127
125 dsa_port_disable(dp); 128 dsa_port_disable(dp);
@@ -379,6 +382,13 @@ static int dsa_slave_get_port_parent_id(struct net_device *dev,
379 struct dsa_switch *ds = dp->ds; 382 struct dsa_switch *ds = dp->ds;
380 struct dsa_switch_tree *dst = ds->dst; 383 struct dsa_switch_tree *dst = ds->dst;
381 384
385 /* For non-legacy ports, devlink is used and it takes
386 * care of the name generation. This ndo implementation
387 * should be removed with legacy support.
388 */
389 if (dp->ds->devlink)
390 return -EOPNOTSUPP;
391
382 ppid->id_len = sizeof(dst->index); 392 ppid->id_len = sizeof(dst->index);
383 memcpy(&ppid->id, &dst->index, ppid->id_len); 393 memcpy(&ppid->id, &dst->index, ppid->id_len);
384 394
@@ -423,6 +433,24 @@ static void dsa_skb_tx_timestamp(struct dsa_slave_priv *p,
423 kfree_skb(clone); 433 kfree_skb(clone);
424} 434}
425 435
436netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev)
437{
438 /* SKB for netpoll still need to be mangled with the protocol-specific
439 * tag to be successfully transmitted
440 */
441 if (unlikely(netpoll_tx_running(dev)))
442 return dsa_slave_netpoll_send_skb(dev, skb);
443
444 /* Queue the SKB for transmission on the parent interface, but
445 * do not modify its EtherType
446 */
447 skb->dev = dsa_slave_to_master(dev);
448 dev_queue_xmit(skb);
449
450 return NETDEV_TX_OK;
451}
452EXPORT_SYMBOL_GPL(dsa_enqueue_skb);
453
426static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) 454static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
427{ 455{
428 struct dsa_slave_priv *p = netdev_priv(dev); 456 struct dsa_slave_priv *p = netdev_priv(dev);
@@ -435,6 +463,8 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
435 s->tx_bytes += skb->len; 463 s->tx_bytes += skb->len;
436 u64_stats_update_end(&s->syncp); 464 u64_stats_update_end(&s->syncp);
437 465
466 DSA_SKB_CB(skb)->deferred_xmit = false;
467
438 /* Identify PTP protocol packets, clone them, and pass them to the 468 /* Identify PTP protocol packets, clone them, and pass them to the
439 * switch driver 469 * switch driver
440 */ 470 */
@@ -445,23 +475,37 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
445 */ 475 */
446 nskb = p->xmit(skb, dev); 476 nskb = p->xmit(skb, dev);
447 if (!nskb) { 477 if (!nskb) {
448 kfree_skb(skb); 478 if (!DSA_SKB_CB(skb)->deferred_xmit)
479 kfree_skb(skb);
449 return NETDEV_TX_OK; 480 return NETDEV_TX_OK;
450 } 481 }
451 482
452 /* SKB for netpoll still need to be mangled with the protocol-specific 483 return dsa_enqueue_skb(nskb, dev);
453 * tag to be successfully transmitted 484}
454 */
455 if (unlikely(netpoll_tx_running(dev)))
456 return dsa_slave_netpoll_send_skb(dev, nskb);
457 485
458 /* Queue the SKB for transmission on the parent interface, but 486void *dsa_defer_xmit(struct sk_buff *skb, struct net_device *dev)
459 * do not modify its EtherType 487{
460 */ 488 struct dsa_port *dp = dsa_slave_to_port(dev);
461 nskb->dev = dsa_slave_to_master(dev);
462 dev_queue_xmit(nskb);
463 489
464 return NETDEV_TX_OK; 490 DSA_SKB_CB(skb)->deferred_xmit = true;
491
492 skb_queue_tail(&dp->xmit_queue, skb);
493 schedule_work(&dp->xmit_work);
494 return NULL;
495}
496EXPORT_SYMBOL_GPL(dsa_defer_xmit);
497
498static void dsa_port_xmit_work(struct work_struct *work)
499{
500 struct dsa_port *dp = container_of(work, struct dsa_port, xmit_work);
501 struct dsa_switch *ds = dp->ds;
502 struct sk_buff *skb;
503
504 if (unlikely(!ds->ops->port_deferred_xmit))
505 return;
506
507 while ((skb = skb_dequeue(&dp->xmit_queue)) != NULL)
508 ds->ops->port_deferred_xmit(ds, dp->index, skb);
465} 509}
466 510
467/* ethtool operations *******************************************************/ 511/* ethtool operations *******************************************************/
@@ -736,6 +780,13 @@ static int dsa_slave_get_phys_port_name(struct net_device *dev,
736{ 780{
737 struct dsa_port *dp = dsa_slave_to_port(dev); 781 struct dsa_port *dp = dsa_slave_to_port(dev);
738 782
783 /* For non-legacy ports, devlink is used and it takes
784 * care of the name generation. This ndo implementation
785 * should be removed with legacy support.
786 */
787 if (dp->ds->devlink)
788 return -EOPNOTSUPP;
789
739 if (snprintf(name, len, "p%d", dp->index) >= len) 790 if (snprintf(name, len, "p%d", dp->index) >= len)
740 return -EINVAL; 791 return -EINVAL;
741 792
@@ -764,27 +815,25 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev,
764 struct dsa_mall_tc_entry *mall_tc_entry; 815 struct dsa_mall_tc_entry *mall_tc_entry;
765 __be16 protocol = cls->common.protocol; 816 __be16 protocol = cls->common.protocol;
766 struct dsa_switch *ds = dp->ds; 817 struct dsa_switch *ds = dp->ds;
767 struct net_device *to_dev; 818 struct flow_action_entry *act;
768 const struct tc_action *a;
769 struct dsa_port *to_dp; 819 struct dsa_port *to_dp;
770 int err = -EOPNOTSUPP; 820 int err = -EOPNOTSUPP;
771 821
772 if (!ds->ops->port_mirror_add) 822 if (!ds->ops->port_mirror_add)
773 return err; 823 return err;
774 824
775 if (!tcf_exts_has_one_action(cls->exts)) 825 if (!flow_offload_has_one_action(&cls->rule->action))
776 return err; 826 return err;
777 827
778 a = tcf_exts_first_action(cls->exts); 828 act = &cls->rule->action.entries[0];
779 829
780 if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) { 830 if (act->id == FLOW_ACTION_MIRRED && protocol == htons(ETH_P_ALL)) {
781 struct dsa_mall_mirror_tc_entry *mirror; 831 struct dsa_mall_mirror_tc_entry *mirror;
782 832
783 to_dev = tcf_mirred_dev(a); 833 if (!act->dev)
784 if (!to_dev)
785 return -EINVAL; 834 return -EINVAL;
786 835
787 if (!dsa_slave_dev_check(to_dev)) 836 if (!dsa_slave_dev_check(act->dev))
788 return -EOPNOTSUPP; 837 return -EOPNOTSUPP;
789 838
790 mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL); 839 mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
@@ -795,7 +844,7 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev,
795 mall_tc_entry->type = DSA_PORT_MALL_MIRROR; 844 mall_tc_entry->type = DSA_PORT_MALL_MIRROR;
796 mirror = &mall_tc_entry->mirror; 845 mirror = &mall_tc_entry->mirror;
797 846
798 to_dp = dsa_slave_to_port(to_dev); 847 to_dp = dsa_slave_to_port(act->dev);
799 848
800 mirror->to_local_port = to_dp->index; 849 mirror->to_local_port = to_dp->index;
801 mirror->ingress = ingress; 850 mirror->ingress = ingress;
@@ -987,13 +1036,6 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
987 u16 vid) 1036 u16 vid)
988{ 1037{
989 struct dsa_port *dp = dsa_slave_to_port(dev); 1038 struct dsa_port *dp = dsa_slave_to_port(dev);
990 struct switchdev_obj_port_vlan vlan = {
991 .vid_begin = vid,
992 .vid_end = vid,
993 /* This API only allows programming tagged, non-PVID VIDs */
994 .flags = 0,
995 };
996 struct switchdev_trans trans;
997 struct bridge_vlan_info info; 1039 struct bridge_vlan_info info;
998 int ret; 1040 int ret;
999 1041
@@ -1010,25 +1052,14 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,
1010 return -EBUSY; 1052 return -EBUSY;
1011 } 1053 }
1012 1054
1013 trans.ph_prepare = true; 1055 /* This API only allows programming tagged, non-PVID VIDs */
1014 ret = dsa_port_vlan_add(dp, &vlan, &trans); 1056 return dsa_port_vid_add(dp, vid, 0);
1015 if (ret == -EOPNOTSUPP)
1016 return 0;
1017
1018 trans.ph_prepare = false;
1019 return dsa_port_vlan_add(dp, &vlan, &trans);
1020} 1057}
1021 1058
1022static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, 1059static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
1023 u16 vid) 1060 u16 vid)
1024{ 1061{
1025 struct dsa_port *dp = dsa_slave_to_port(dev); 1062 struct dsa_port *dp = dsa_slave_to_port(dev);
1026 struct switchdev_obj_port_vlan vlan = {
1027 .vid_begin = vid,
1028 .vid_end = vid,
1029 /* This API only allows programming tagged, non-PVID VIDs */
1030 .flags = 0,
1031 };
1032 struct bridge_vlan_info info; 1063 struct bridge_vlan_info info;
1033 int ret; 1064 int ret;
1034 1065
@@ -1045,7 +1076,7 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
1045 return -EBUSY; 1076 return -EBUSY;
1046 } 1077 }
1047 1078
1048 ret = dsa_port_vlan_del(dp, &vlan); 1079 ret = dsa_port_vid_del(dp, vid);
1049 if (ret == -EOPNOTSUPP) 1080 if (ret == -EOPNOTSUPP)
1050 ret = 0; 1081 ret = 0;
1051 1082
@@ -1096,6 +1127,13 @@ int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
1096 return dsa_port_fdb_del(dp, addr, vid); 1127 return dsa_port_fdb_del(dp, addr, vid);
1097} 1128}
1098 1129
1130static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev)
1131{
1132 struct dsa_port *dp = dsa_slave_to_port(dev);
1133
1134 return dp->ds->devlink ? &dp->devlink_port : NULL;
1135}
1136
1099static const struct net_device_ops dsa_slave_netdev_ops = { 1137static const struct net_device_ops dsa_slave_netdev_ops = {
1100 .ndo_open = dsa_slave_open, 1138 .ndo_open = dsa_slave_open,
1101 .ndo_stop = dsa_slave_close, 1139 .ndo_stop = dsa_slave_close,
@@ -1119,6 +1157,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
1119 .ndo_get_port_parent_id = dsa_slave_get_port_parent_id, 1157 .ndo_get_port_parent_id = dsa_slave_get_port_parent_id,
1120 .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid, 1158 .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid,
1121 .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid, 1159 .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid,
1160 .ndo_get_devlink_port = dsa_slave_get_devlink_port,
1122}; 1161};
1123 1162
1124static struct device_type dsa_type = { 1163static struct device_type dsa_type = {
@@ -1283,9 +1322,9 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
1283 phy_flags = ds->ops->get_phy_flags(ds, dp->index); 1322 phy_flags = ds->ops->get_phy_flags(ds, dp->index);
1284 1323
1285 ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags); 1324 ret = phylink_of_phy_connect(dp->pl, port_dn, phy_flags);
1286 if (ret == -ENODEV) { 1325 if (ret == -ENODEV && ds->slave_mii_bus) {
1287 /* We could not connect to a designated PHY or SFP, so use the 1326 /* We could not connect to a designated PHY or SFP, so try to
1288 * switch internal MDIO bus instead 1327 * use the switch internal MDIO bus instead
1289 */ 1328 */
1290 ret = dsa_slave_phy_connect(slave_dev, dp->index); 1329 ret = dsa_slave_phy_connect(slave_dev, dp->index);
1291 if (ret) { 1330 if (ret) {
@@ -1297,7 +1336,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
1297 } 1336 }
1298 } 1337 }
1299 1338
1300 return 0; 1339 return ret;
1301} 1340}
1302 1341
1303static struct lock_class_key dsa_slave_netdev_xmit_lock_key; 1342static struct lock_class_key dsa_slave_netdev_xmit_lock_key;
@@ -1316,6 +1355,9 @@ int dsa_slave_suspend(struct net_device *slave_dev)
1316 if (!netif_running(slave_dev)) 1355 if (!netif_running(slave_dev))
1317 return 0; 1356 return 0;
1318 1357
1358 cancel_work_sync(&dp->xmit_work);
1359 skb_queue_purge(&dp->xmit_queue);
1360
1319 netif_device_detach(slave_dev); 1361 netif_device_detach(slave_dev);
1320 1362
1321 rtnl_lock(); 1363 rtnl_lock();
@@ -1378,7 +1420,10 @@ int dsa_slave_create(struct dsa_port *port)
1378 NETIF_F_HW_VLAN_CTAG_FILTER; 1420 NETIF_F_HW_VLAN_CTAG_FILTER;
1379 slave_dev->hw_features |= NETIF_F_HW_TC; 1421 slave_dev->hw_features |= NETIF_F_HW_TC;
1380 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; 1422 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
1381 eth_hw_addr_inherit(slave_dev, master); 1423 if (!IS_ERR_OR_NULL(port->mac))
1424 ether_addr_copy(slave_dev->dev_addr, port->mac);
1425 else
1426 eth_hw_addr_inherit(slave_dev, master);
1382 slave_dev->priv_flags |= IFF_NO_QUEUE; 1427 slave_dev->priv_flags |= IFF_NO_QUEUE;
1383 slave_dev->netdev_ops = &dsa_slave_netdev_ops; 1428 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
1384 slave_dev->min_mtu = 0; 1429 slave_dev->min_mtu = 0;
@@ -1400,6 +1445,8 @@ int dsa_slave_create(struct dsa_port *port)
1400 } 1445 }
1401 p->dp = port; 1446 p->dp = port;
1402 INIT_LIST_HEAD(&p->mall_tc_list); 1447 INIT_LIST_HEAD(&p->mall_tc_list);
1448 INIT_WORK(&port->xmit_work, dsa_port_xmit_work);
1449 skb_queue_head_init(&port->xmit_queue);
1403 p->xmit = cpu_dp->tag_ops->xmit; 1450 p->xmit = cpu_dp->tag_ops->xmit;
1404 port->slave = slave_dev; 1451 port->slave = slave_dev;
1405 1452
diff --git a/net/dsa/switch.c b/net/dsa/switch.c
index e1fae969aa73..7d8cd9bc0ecc 100644
--- a/net/dsa/switch.c
+++ b/net/dsa/switch.c
@@ -10,6 +10,7 @@
10 * (at your option) any later version. 10 * (at your option) any later version.
11 */ 11 */
12 12
13#include <linux/if_bridge.h>
13#include <linux/netdevice.h> 14#include <linux/netdevice.h>
14#include <linux/notifier.h> 15#include <linux/notifier.h>
15#include <linux/if_vlan.h> 16#include <linux/if_vlan.h>
@@ -71,6 +72,9 @@ static int dsa_switch_bridge_join(struct dsa_switch *ds,
71static int dsa_switch_bridge_leave(struct dsa_switch *ds, 72static int dsa_switch_bridge_leave(struct dsa_switch *ds,
72 struct dsa_notifier_bridge_info *info) 73 struct dsa_notifier_bridge_info *info)
73{ 74{
75 bool unset_vlan_filtering = br_vlan_enabled(info->br);
76 int err, i;
77
74 if (ds->index == info->sw_index && ds->ops->port_bridge_leave) 78 if (ds->index == info->sw_index && ds->ops->port_bridge_leave)
75 ds->ops->port_bridge_leave(ds, info->port, info->br); 79 ds->ops->port_bridge_leave(ds, info->port, info->br);
76 80
@@ -78,6 +82,31 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds,
78 ds->ops->crosschip_bridge_leave(ds, info->sw_index, info->port, 82 ds->ops->crosschip_bridge_leave(ds, info->sw_index, info->port,
79 info->br); 83 info->br);
80 84
85 /* If the bridge was vlan_filtering, the bridge core doesn't trigger an
86 * event for changing vlan_filtering setting upon slave ports leaving
87 * it. That is a good thing, because that lets us handle it and also
88 * handle the case where the switch's vlan_filtering setting is global
89 * (not per port). When that happens, the correct moment to trigger the
90 * vlan_filtering callback is only when the last port left this bridge.
91 */
92 if (unset_vlan_filtering && ds->vlan_filtering_is_global) {
93 for (i = 0; i < ds->num_ports; i++) {
94 if (i == info->port)
95 continue;
96 if (dsa_to_port(ds, i)->bridge_dev == info->br) {
97 unset_vlan_filtering = false;
98 break;
99 }
100 }
101 }
102 if (unset_vlan_filtering) {
103 struct switchdev_trans trans = {0};
104
105 err = dsa_port_vlan_filtering(&ds->ports[info->port],
106 false, &trans);
107 if (err && err != EOPNOTSUPP)
108 return err;
109 }
81 return 0; 110 return 0;
82} 111}
83 112
@@ -196,7 +225,7 @@ static int dsa_port_vlan_check(struct dsa_switch *ds, int port,
196 if (!dp->bridge_dev) 225 if (!dp->bridge_dev)
197 return err; 226 return err;
198 227
199 /* dsa_slave_vlan_rx_{add,kill}_vid() cannot use the prepare pharse and 228 /* dsa_slave_vlan_rx_{add,kill}_vid() cannot use the prepare phase and
200 * already checks whether there is an overlapping bridge VLAN entry 229 * already checks whether there is an overlapping bridge VLAN entry
201 * with the same VID, so here we only need to check that if we are 230 * with the same VID, so here we only need to check that if we are
202 * adding a bridge VLAN entry there is not an overlapping VLAN device 231 * adding a bridge VLAN entry there is not an overlapping VLAN device
diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c
new file mode 100644
index 000000000000..8ae48c7e1e76
--- /dev/null
+++ b/net/dsa/tag_8021q.c
@@ -0,0 +1,222 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com>
3 *
4 * This module is not a complete tagger implementation. It only provides
5 * primitives for taggers that rely on 802.1Q VLAN tags to use. The
6 * dsa_8021q_netdev_ops is registered for API compliance and not used
7 * directly by callers.
8 */
9#include <linux/if_bridge.h>
10#include <linux/if_vlan.h>
11
12#include "dsa_priv.h"
13
14/* Allocating two VLAN tags per port - one for the RX VID and
15 * the other for the TX VID - see below
16 */
17#define DSA_8021Q_VID_RANGE (DSA_MAX_SWITCHES * DSA_MAX_PORTS)
18#define DSA_8021Q_VID_BASE (VLAN_N_VID - 2 * DSA_8021Q_VID_RANGE - 1)
19#define DSA_8021Q_RX_VID_BASE (DSA_8021Q_VID_BASE)
20#define DSA_8021Q_TX_VID_BASE (DSA_8021Q_VID_BASE + DSA_8021Q_VID_RANGE)
21
22/* Returns the VID to be inserted into the frame from xmit for switch steering
23 * instructions on egress. Encodes switch ID and port ID.
24 */
25u16 dsa_8021q_tx_vid(struct dsa_switch *ds, int port)
26{
27 return DSA_8021Q_TX_VID_BASE + (DSA_MAX_PORTS * ds->index) + port;
28}
29EXPORT_SYMBOL_GPL(dsa_8021q_tx_vid);
30
31/* Returns the VID that will be installed as pvid for this switch port, sent as
32 * tagged egress towards the CPU port and decoded by the rcv function.
33 */
34u16 dsa_8021q_rx_vid(struct dsa_switch *ds, int port)
35{
36 return DSA_8021Q_RX_VID_BASE + (DSA_MAX_PORTS * ds->index) + port;
37}
38EXPORT_SYMBOL_GPL(dsa_8021q_rx_vid);
39
40/* Returns the decoded switch ID from the RX VID. */
41int dsa_8021q_rx_switch_id(u16 vid)
42{
43 return ((vid - DSA_8021Q_RX_VID_BASE) / DSA_MAX_PORTS);
44}
45EXPORT_SYMBOL_GPL(dsa_8021q_rx_switch_id);
46
47/* Returns the decoded port ID from the RX VID. */
48int dsa_8021q_rx_source_port(u16 vid)
49{
50 return ((vid - DSA_8021Q_RX_VID_BASE) % DSA_MAX_PORTS);
51}
52EXPORT_SYMBOL_GPL(dsa_8021q_rx_source_port);
53
54/* RX VLAN tagging (left) and TX VLAN tagging (right) setup shown for a single
55 * front-panel switch port (here swp0).
56 *
57 * Port identification through VLAN (802.1Q) tags has different requirements
58 * for it to work effectively:
59 * - On RX (ingress from network): each front-panel port must have a pvid
60 * that uniquely identifies it, and the egress of this pvid must be tagged
61 * towards the CPU port, so that software can recover the source port based
62 * on the VID in the frame. But this would only work for standalone ports;
63 * if bridged, this VLAN setup would break autonomous forwarding and would
64 * force all switched traffic to pass through the CPU. So we must also make
65 * the other front-panel ports members of this VID we're adding, albeit
66 * we're not making it their PVID (they'll still have their own).
67 * By the way - just because we're installing the same VID in multiple
68 * switch ports doesn't mean that they'll start to talk to one another, even
69 * while not bridged: the final forwarding decision is still an AND between
70 * the L2 forwarding information (which is limiting forwarding in this case)
71 * and the VLAN-based restrictions (of which there are none in this case,
72 * since all ports are members).
73 * - On TX (ingress from CPU and towards network) we are faced with a problem.
74 * If we were to tag traffic (from within DSA) with the port's pvid, all
75 * would be well, assuming the switch ports were standalone. Frames would
76 * have no choice but to be directed towards the correct front-panel port.
77 * But because we also want the RX VLAN to not break bridging, then
78 * inevitably that means that we have to give them a choice (of what
79 * front-panel port to go out on), and therefore we cannot steer traffic
80 * based on the RX VID. So what we do is simply install one more VID on the
81 * front-panel and CPU ports, and profit off of the fact that steering will
82 * work just by virtue of the fact that there is only one other port that's
83 * a member of the VID we're tagging the traffic with - the desired one.
84 *
85 * So at the end, each front-panel port will have one RX VID (also the PVID),
86 * the RX VID of all other front-panel ports, and one TX VID. Whereas the CPU
87 * port will have the RX and TX VIDs of all front-panel ports, and on top of
88 * that, is also tagged-input and tagged-output (VLAN trunk).
89 *
90 * CPU port CPU port
91 * +-------------+-----+-------------+ +-------------+-----+-------------+
92 * | RX VID | | | | TX VID | | |
93 * | of swp0 | | | | of swp0 | | |
94 * | +-----+ | | +-----+ |
95 * | ^ T | | | Tagged |
96 * | | | | | ingress |
97 * | +-------+---+---+-------+ | | +-----------+ |
98 * | | | | | | | | Untagged |
99 * | | U v U v U v | | v egress |
100 * | +-----+ +-----+ +-----+ +-----+ | | +-----+ +-----+ +-----+ +-----+ |
101 * | | | | | | | | | | | | | | | | | | | |
102 * | |PVID | | | | | | | | | | | | | | | | | |
103 * +-+-----+-+-----+-+-----+-+-----+-+ +-+-----+-+-----+-+-----+-+-----+-+
104 * swp0 swp1 swp2 swp3 swp0 swp1 swp2 swp3
105 */
106int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int port, bool enabled)
107{
108 int upstream = dsa_upstream_port(ds, port);
109 struct dsa_port *dp = &ds->ports[port];
110 struct dsa_port *upstream_dp = &ds->ports[upstream];
111 u16 rx_vid = dsa_8021q_rx_vid(ds, port);
112 u16 tx_vid = dsa_8021q_tx_vid(ds, port);
113 int i, err;
114
115 /* The CPU port is implicitly configured by
116 * configuring the front-panel ports
117 */
118 if (!dsa_is_user_port(ds, port))
119 return 0;
120
121 /* Add this user port's RX VID to the membership list of all others
122 * (including itself). This is so that bridging will not be hindered.
123 * L2 forwarding rules still take precedence when there are no VLAN
124 * restrictions, so there are no concerns about leaking traffic.
125 */
126 for (i = 0; i < ds->num_ports; i++) {
127 struct dsa_port *other_dp = &ds->ports[i];
128 u16 flags;
129
130 if (i == upstream)
131 /* CPU port needs to see this port's RX VID
132 * as tagged egress.
133 */
134 flags = 0;
135 else if (i == port)
136 /* The RX VID is pvid on this port */
137 flags = BRIDGE_VLAN_INFO_UNTAGGED |
138 BRIDGE_VLAN_INFO_PVID;
139 else
140 /* The RX VID is a regular VLAN on all others */
141 flags = BRIDGE_VLAN_INFO_UNTAGGED;
142
143 if (enabled)
144 err = dsa_port_vid_add(other_dp, rx_vid, flags);
145 else
146 err = dsa_port_vid_del(other_dp, rx_vid);
147 if (err) {
148 dev_err(ds->dev, "Failed to apply RX VID %d to port %d: %d\n",
149 rx_vid, port, err);
150 return err;
151 }
152 }
153 /* Finally apply the TX VID on this port and on the CPU port */
154 if (enabled)
155 err = dsa_port_vid_add(dp, tx_vid, BRIDGE_VLAN_INFO_UNTAGGED);
156 else
157 err = dsa_port_vid_del(dp, tx_vid);
158 if (err) {
159 dev_err(ds->dev, "Failed to apply TX VID %d on port %d: %d\n",
160 tx_vid, port, err);
161 return err;
162 }
163 if (enabled)
164 err = dsa_port_vid_add(upstream_dp, tx_vid, 0);
165 else
166 err = dsa_port_vid_del(upstream_dp, tx_vid);
167 if (err) {
168 dev_err(ds->dev, "Failed to apply TX VID %d on port %d: %d\n",
169 tx_vid, upstream, err);
170 return err;
171 }
172
173 return 0;
174}
175EXPORT_SYMBOL_GPL(dsa_port_setup_8021q_tagging);
176
177struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
178 u16 tpid, u16 tci)
179{
180 /* skb->data points at skb_mac_header, which
181 * is fine for vlan_insert_tag.
182 */
183 return vlan_insert_tag(skb, htons(tpid), tci);
184}
185EXPORT_SYMBOL_GPL(dsa_8021q_xmit);
186
187struct sk_buff *dsa_8021q_rcv(struct sk_buff *skb, struct net_device *netdev,
188 struct packet_type *pt, u16 *tpid, u16 *tci)
189{
190 struct vlan_ethhdr *tag;
191
192 if (unlikely(!pskb_may_pull(skb, VLAN_HLEN)))
193 return NULL;
194
195 tag = vlan_eth_hdr(skb);
196 *tpid = ntohs(tag->h_vlan_proto);
197 *tci = ntohs(tag->h_vlan_TCI);
198
199 /* skb->data points in the middle of the VLAN tag,
200 * after tpid and before tci. This is because so far,
201 * ETH_HLEN (DMAC, SMAC, EtherType) bytes were pulled.
202 * There are 2 bytes of VLAN tag left in skb->data, and upper
203 * layers expect the 'real' EtherType to be consumed as well.
204 * Coincidentally, a VLAN header is also of the same size as
205 * the number of bytes that need to be pulled.
206 */
207 skb_pull_rcsum(skb, VLAN_HLEN);
208
209 return skb;
210}
211EXPORT_SYMBOL_GPL(dsa_8021q_rcv);
212
213static const struct dsa_device_ops dsa_8021q_netdev_ops = {
214 .name = "8021q",
215 .proto = DSA_TAG_PROTO_8021Q,
216 .overhead = VLAN_HLEN,
217};
218
219MODULE_LICENSE("GPL v2");
220MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_8021Q);
221
222module_dsa_tag_driver(dsa_8021q_netdev_ops);
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 4aa1d368a5ae..9c3114179690 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -1,12 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * Broadcom tag support 3 * Broadcom tag support
3 * 4 *
4 * Copyright (C) 2014 Broadcom Corporation 5 * Copyright (C) 2014 Broadcom Corporation
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */ 6 */
11 7
12#include <linux/etherdevice.h> 8#include <linux/etherdevice.h>
@@ -59,6 +55,9 @@
59#define BRCM_EG_TC_MASK 0x7 55#define BRCM_EG_TC_MASK 0x7
60#define BRCM_EG_PID_MASK 0x1f 56#define BRCM_EG_PID_MASK 0x1f
61 57
58#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) || \
59 IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
60
62static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb, 61static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
63 struct net_device *dev, 62 struct net_device *dev,
64 unsigned int offset) 63 unsigned int offset)
@@ -143,8 +142,9 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
143 142
144 return skb; 143 return skb;
145} 144}
145#endif
146 146
147#ifdef CONFIG_NET_DSA_TAG_BRCM 147#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM)
148static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, 148static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb,
149 struct net_device *dev) 149 struct net_device *dev)
150{ 150{
@@ -171,14 +171,19 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
171 return nskb; 171 return nskb;
172} 172}
173 173
174const struct dsa_device_ops brcm_netdev_ops = { 174static const struct dsa_device_ops brcm_netdev_ops = {
175 .name = "brcm",
176 .proto = DSA_TAG_PROTO_BRCM,
175 .xmit = brcm_tag_xmit, 177 .xmit = brcm_tag_xmit,
176 .rcv = brcm_tag_rcv, 178 .rcv = brcm_tag_rcv,
177 .overhead = BRCM_TAG_LEN, 179 .overhead = BRCM_TAG_LEN,
178}; 180};
181
182DSA_TAG_DRIVER(brcm_netdev_ops);
183MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM);
179#endif 184#endif
180 185
181#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND 186#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
182static struct sk_buff *brcm_tag_xmit_prepend(struct sk_buff *skb, 187static struct sk_buff *brcm_tag_xmit_prepend(struct sk_buff *skb,
183 struct net_device *dev) 188 struct net_device *dev)
184{ 189{
@@ -194,9 +199,27 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
194 return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN); 199 return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
195} 200}
196 201
197const struct dsa_device_ops brcm_prepend_netdev_ops = { 202static const struct dsa_device_ops brcm_prepend_netdev_ops = {
203 .name = "brcm-prepend",
204 .proto = DSA_TAG_PROTO_BRCM_PREPEND,
198 .xmit = brcm_tag_xmit_prepend, 205 .xmit = brcm_tag_xmit_prepend,
199 .rcv = brcm_tag_rcv_prepend, 206 .rcv = brcm_tag_rcv_prepend,
200 .overhead = BRCM_TAG_LEN, 207 .overhead = BRCM_TAG_LEN,
201}; 208};
209
210DSA_TAG_DRIVER(brcm_prepend_netdev_ops);
211MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND);
202#endif 212#endif
213
214static struct dsa_tag_driver *dsa_tag_driver_array[] = {
215#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM)
216 &DSA_TAG_DRIVER_NAME(brcm_netdev_ops),
217#endif
218#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
219 &DSA_TAG_DRIVER_NAME(brcm_prepend_netdev_ops),
220#endif
221};
222
223module_dsa_tag_drivers(dsa_tag_driver_array);
224
225MODULE_LICENSE("GPL");
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index 67ff3fae18d8..7ddec9794477 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -1,11 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * net/dsa/tag_dsa.c - (Non-ethertype) DSA tagging 3 * net/dsa/tag_dsa.c - (Non-ethertype) DSA tagging
3 * Copyright (c) 2008-2009 Marvell Semiconductor 4 * Copyright (c) 2008-2009 Marvell Semiconductor
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */ 5 */
10 6
11#include <linux/etherdevice.h> 7#include <linux/etherdevice.h>
@@ -154,9 +150,16 @@ static int dsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
154 return 0; 150 return 0;
155} 151}
156 152
157const struct dsa_device_ops dsa_netdev_ops = { 153static const struct dsa_device_ops dsa_netdev_ops = {
154 .name = "dsa",
155 .proto = DSA_TAG_PROTO_DSA,
158 .xmit = dsa_xmit, 156 .xmit = dsa_xmit,
159 .rcv = dsa_rcv, 157 .rcv = dsa_rcv,
160 .flow_dissect = dsa_tag_flow_dissect, 158 .flow_dissect = dsa_tag_flow_dissect,
161 .overhead = DSA_HLEN, 159 .overhead = DSA_HLEN,
162}; 160};
161
162MODULE_LICENSE("GPL");
163MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_DSA);
164
165module_dsa_tag_driver(dsa_netdev_ops);
diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c
index 234585ec116e..e8eaa804ccb9 100644
--- a/net/dsa/tag_edsa.c
+++ b/net/dsa/tag_edsa.c
@@ -1,11 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * net/dsa/tag_edsa.c - Ethertype DSA tagging 3 * net/dsa/tag_edsa.c - Ethertype DSA tagging
3 * Copyright (c) 2008-2009 Marvell Semiconductor 4 * Copyright (c) 2008-2009 Marvell Semiconductor
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */ 5 */
10 6
11#include <linux/etherdevice.h> 7#include <linux/etherdevice.h>
@@ -173,9 +169,16 @@ static int edsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
173 return 0; 169 return 0;
174} 170}
175 171
176const struct dsa_device_ops edsa_netdev_ops = { 172static const struct dsa_device_ops edsa_netdev_ops = {
173 .name = "edsa",
174 .proto = DSA_TAG_PROTO_EDSA,
177 .xmit = edsa_xmit, 175 .xmit = edsa_xmit,
178 .rcv = edsa_rcv, 176 .rcv = edsa_rcv,
179 .flow_dissect = edsa_tag_flow_dissect, 177 .flow_dissect = edsa_tag_flow_dissect,
180 .overhead = EDSA_HLEN, 178 .overhead = EDSA_HLEN,
181}; 179};
180
181MODULE_LICENSE("GPL");
182MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_EDSA);
183
184module_dsa_tag_driver(edsa_netdev_ops);
diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c
index cb6f82ffe5eb..b678160bbd66 100644
--- a/net/dsa/tag_gswip.c
+++ b/net/dsa/tag_gswip.c
@@ -103,8 +103,15 @@ static struct sk_buff *gswip_tag_rcv(struct sk_buff *skb,
103 return skb; 103 return skb;
104} 104}
105 105
106const struct dsa_device_ops gswip_netdev_ops = { 106static const struct dsa_device_ops gswip_netdev_ops = {
107 .name = "gwsip",
108 .proto = DSA_TAG_PROTO_GSWIP,
107 .xmit = gswip_tag_xmit, 109 .xmit = gswip_tag_xmit,
108 .rcv = gswip_tag_rcv, 110 .rcv = gswip_tag_rcv,
109 .overhead = GSWIP_RX_HEADER_LEN, 111 .overhead = GSWIP_RX_HEADER_LEN,
110}; 112};
113
114MODULE_LICENSE("GPL");
115MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_GSWIP);
116
117module_dsa_tag_driver(gswip_netdev_ops);
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index de246c93d3bb..b4872b87d4a6 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -1,11 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling 3 * net/dsa/tag_ksz.c - Microchip KSZ Switch tag format handling
3 * Copyright (c) 2017 Microchip Technology 4 * Copyright (c) 2017 Microchip Technology
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */ 5 */
10 6
11#include <linux/etherdevice.h> 7#include <linux/etherdevice.h>
@@ -137,12 +133,17 @@ static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
137 return ksz_common_rcv(skb, dev, port, len); 133 return ksz_common_rcv(skb, dev, port, len);
138} 134}
139 135
140const struct dsa_device_ops ksz9477_netdev_ops = { 136static const struct dsa_device_ops ksz9477_netdev_ops = {
137 .name = "ksz9477",
138 .proto = DSA_TAG_PROTO_KSZ9477,
141 .xmit = ksz9477_xmit, 139 .xmit = ksz9477_xmit,
142 .rcv = ksz9477_rcv, 140 .rcv = ksz9477_rcv,
143 .overhead = KSZ9477_INGRESS_TAG_LEN, 141 .overhead = KSZ9477_INGRESS_TAG_LEN,
144}; 142};
145 143
144DSA_TAG_DRIVER(ksz9477_netdev_ops);
145MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9477);
146
146#define KSZ9893_TAIL_TAG_OVERRIDE BIT(5) 147#define KSZ9893_TAIL_TAG_OVERRIDE BIT(5)
147#define KSZ9893_TAIL_TAG_LOOKUP BIT(6) 148#define KSZ9893_TAIL_TAG_LOOKUP BIT(6)
148 149
@@ -170,8 +171,22 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
170 return nskb; 171 return nskb;
171} 172}
172 173
173const struct dsa_device_ops ksz9893_netdev_ops = { 174static const struct dsa_device_ops ksz9893_netdev_ops = {
175 .name = "ksz9893",
176 .proto = DSA_TAG_PROTO_KSZ9893,
174 .xmit = ksz9893_xmit, 177 .xmit = ksz9893_xmit,
175 .rcv = ksz9477_rcv, 178 .rcv = ksz9477_rcv,
176 .overhead = KSZ_INGRESS_TAG_LEN, 179 .overhead = KSZ_INGRESS_TAG_LEN,
177}; 180};
181
182DSA_TAG_DRIVER(ksz9893_netdev_ops);
183MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_KSZ9893);
184
185static struct dsa_tag_driver *dsa_tag_driver_array[] = {
186 &DSA_TAG_DRIVER_NAME(ksz9477_netdev_ops),
187 &DSA_TAG_DRIVER_NAME(ksz9893_netdev_ops),
188};
189
190module_dsa_tag_drivers(dsa_tag_driver_array);
191
192MODULE_LICENSE("GPL");
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index f48889e46ff7..eb0e7a32e53d 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -1,15 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2017 Pengutronix, Juergen Borleis <jbe@pengutronix.de> 3 * Copyright (C) 2017 Pengutronix, Juergen Borleis <jbe@pengutronix.de>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2, 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 */ 4 */
14#include <linux/dsa/lan9303.h> 5#include <linux/dsa/lan9303.h>
15#include <linux/etherdevice.h> 6#include <linux/etherdevice.h>
@@ -137,8 +128,15 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
137 return skb; 128 return skb;
138} 129}
139 130
140const struct dsa_device_ops lan9303_netdev_ops = { 131static const struct dsa_device_ops lan9303_netdev_ops = {
132 .name = "lan9303",
133 .proto = DSA_TAG_PROTO_LAN9303,
141 .xmit = lan9303_xmit, 134 .xmit = lan9303_xmit,
142 .rcv = lan9303_rcv, 135 .rcv = lan9303_rcv,
143 .overhead = LAN9303_TAG_LEN, 136 .overhead = LAN9303_TAG_LEN,
144}; 137};
138
139MODULE_LICENSE("GPL");
140MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_LAN9303);
141
142module_dsa_tag_driver(lan9303_netdev_ops);
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index f39f4dfeda34..b5705cba8318 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -1,15 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Mediatek DSA Tag support 3 * Mediatek DSA Tag support
3 * Copyright (C) 2017 Landen Chao <landen.chao@mediatek.com> 4 * Copyright (C) 2017 Landen Chao <landen.chao@mediatek.com>
4 * Sean Wang <sean.wang@mediatek.com> 5 * Sean Wang <sean.wang@mediatek.com>
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 and
7 * only version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */ 6 */
14 7
15#include <linux/etherdevice.h> 8#include <linux/etherdevice.h>
@@ -105,9 +98,16 @@ static int mtk_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
105 return 0; 98 return 0;
106} 99}
107 100
108const struct dsa_device_ops mtk_netdev_ops = { 101static const struct dsa_device_ops mtk_netdev_ops = {
102 .name = "mtk",
103 .proto = DSA_TAG_PROTO_MTK,
109 .xmit = mtk_tag_xmit, 104 .xmit = mtk_tag_xmit,
110 .rcv = mtk_tag_rcv, 105 .rcv = mtk_tag_rcv,
111 .flow_dissect = mtk_tag_flow_dissect, 106 .flow_dissect = mtk_tag_flow_dissect,
112 .overhead = MTK_HDR_LEN, 107 .overhead = MTK_HDR_LEN,
113}; 108};
109
110MODULE_LICENSE("GPL");
111MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MTK);
112
113module_dsa_tag_driver(mtk_netdev_ops);
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index 85c22ada4744..c95885215525 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -1,14 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (c) 2015, The Linux Foundation. All rights reserved. 3 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
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 and
6 * only version 2 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 */ 4 */
13 5
14#include <linux/etherdevice.h> 6#include <linux/etherdevice.h>
@@ -107,9 +99,16 @@ static int qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
107 return 0; 99 return 0;
108} 100}
109 101
110const struct dsa_device_ops qca_netdev_ops = { 102static const struct dsa_device_ops qca_netdev_ops = {
103 .name = "qca",
104 .proto = DSA_TAG_PROTO_QCA,
111 .xmit = qca_tag_xmit, 105 .xmit = qca_tag_xmit,
112 .rcv = qca_tag_rcv, 106 .rcv = qca_tag_rcv,
113 .flow_dissect = qca_tag_flow_dissect, 107 .flow_dissect = qca_tag_flow_dissect,
114 .overhead = QCA_HDR_LEN, 108 .overhead = QCA_HDR_LEN,
115}; 109};
110
111MODULE_LICENSE("GPL");
112MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_QCA);
113
114module_dsa_tag_driver(qca_netdev_ops);
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
new file mode 100644
index 000000000000..969402c7dbf1
--- /dev/null
+++ b/net/dsa/tag_sja1105.c
@@ -0,0 +1,131 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com>
3 */
4#include <linux/if_vlan.h>
5#include <linux/dsa/sja1105.h>
6#include <linux/dsa/8021q.h>
7#include <linux/packing.h>
8#include "dsa_priv.h"
9
10/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */
11static inline bool sja1105_is_link_local(const struct sk_buff *skb)
12{
13 const struct ethhdr *hdr = eth_hdr(skb);
14 u64 dmac = ether_addr_to_u64(hdr->h_dest);
15
16 if ((dmac & SJA1105_LINKLOCAL_FILTER_A_MASK) ==
17 SJA1105_LINKLOCAL_FILTER_A)
18 return true;
19 if ((dmac & SJA1105_LINKLOCAL_FILTER_B_MASK) ==
20 SJA1105_LINKLOCAL_FILTER_B)
21 return true;
22 return false;
23}
24
25/* This is the first time the tagger sees the frame on RX.
26 * Figure out if we can decode it, and if we can, annotate skb->cb with how we
27 * plan to do that, so we don't need to check again in the rcv function.
28 */
29static bool sja1105_filter(const struct sk_buff *skb, struct net_device *dev)
30{
31 if (sja1105_is_link_local(skb)) {
32 SJA1105_SKB_CB(skb)->type = SJA1105_FRAME_TYPE_LINK_LOCAL;
33 return true;
34 }
35 if (!dsa_port_is_vlan_filtering(dev->dsa_ptr)) {
36 SJA1105_SKB_CB(skb)->type = SJA1105_FRAME_TYPE_NORMAL;
37 return true;
38 }
39 return false;
40}
41
42static struct sk_buff *sja1105_xmit(struct sk_buff *skb,
43 struct net_device *netdev)
44{
45 struct dsa_port *dp = dsa_slave_to_port(netdev);
46 struct dsa_switch *ds = dp->ds;
47 u16 tx_vid = dsa_8021q_tx_vid(ds, dp->index);
48 u8 pcp = skb->priority;
49
50 /* Transmitting management traffic does not rely upon switch tagging,
51 * but instead SPI-installed management routes. Part 2 of this
52 * is the .port_deferred_xmit driver callback.
53 */
54 if (unlikely(sja1105_is_link_local(skb)))
55 return dsa_defer_xmit(skb, netdev);
56
57 /* If we are under a vlan_filtering bridge, IP termination on
58 * switch ports based on 802.1Q tags is simply too brittle to
59 * be passable. So just defer to the dsa_slave_notag_xmit
60 * implementation.
61 */
62 if (dsa_port_is_vlan_filtering(dp))
63 return skb;
64
65 return dsa_8021q_xmit(skb, netdev, ETH_P_SJA1105,
66 ((pcp << VLAN_PRIO_SHIFT) | tx_vid));
67}
68
69static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
70 struct net_device *netdev,
71 struct packet_type *pt)
72{
73 struct ethhdr *hdr = eth_hdr(skb);
74 u64 source_port, switch_id;
75 struct sk_buff *nskb;
76 u16 tpid, vid, tci;
77 bool is_tagged;
78
79 nskb = dsa_8021q_rcv(skb, netdev, pt, &tpid, &tci);
80 is_tagged = (nskb && tpid == ETH_P_SJA1105);
81
82 skb->priority = (tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
83 vid = tci & VLAN_VID_MASK;
84
85 skb->offload_fwd_mark = 1;
86
87 if (SJA1105_SKB_CB(skb)->type == SJA1105_FRAME_TYPE_LINK_LOCAL) {
88 /* Management traffic path. Switch embeds the switch ID and
89 * port ID into bytes of the destination MAC, courtesy of
90 * the incl_srcpt options.
91 */
92 source_port = hdr->h_dest[3];
93 switch_id = hdr->h_dest[4];
94 /* Clear the DMAC bytes that were mangled by the switch */
95 hdr->h_dest[3] = 0;
96 hdr->h_dest[4] = 0;
97 } else {
98 /* Normal traffic path. */
99 source_port = dsa_8021q_rx_source_port(vid);
100 switch_id = dsa_8021q_rx_switch_id(vid);
101 }
102
103 skb->dev = dsa_master_find_slave(netdev, switch_id, source_port);
104 if (!skb->dev) {
105 netdev_warn(netdev, "Couldn't decode source port\n");
106 return NULL;
107 }
108
109 /* Delete/overwrite fake VLAN header, DSA expects to not find
110 * it there, see dsa_switch_rcv: skb_push(skb, ETH_HLEN).
111 */
112 if (is_tagged)
113 memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - VLAN_HLEN,
114 ETH_HLEN - VLAN_HLEN);
115
116 return skb;
117}
118
119static struct dsa_device_ops sja1105_netdev_ops = {
120 .name = "sja1105",
121 .proto = DSA_TAG_PROTO_SJA1105,
122 .xmit = sja1105_xmit,
123 .rcv = sja1105_rcv,
124 .filter = sja1105_filter,
125 .overhead = VLAN_HLEN,
126};
127
128MODULE_LICENSE("GPL v2");
129MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_SJA1105);
130
131module_dsa_tag_driver(sja1105_netdev_ops);
diff --git a/net/dsa/tag_trailer.c b/net/dsa/tag_trailer.c
index b40756ed6e57..4f8ab62f0208 100644
--- a/net/dsa/tag_trailer.c
+++ b/net/dsa/tag_trailer.c
@@ -1,11 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * net/dsa/tag_trailer.c - Trailer tag format handling 3 * net/dsa/tag_trailer.c - Trailer tag format handling
3 * Copyright (c) 2008-2009 Marvell Semiconductor 4 * Copyright (c) 2008-2009 Marvell Semiconductor
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */ 5 */
10 6
11#include <linux/etherdevice.h> 7#include <linux/etherdevice.h>
@@ -81,8 +77,15 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
81 return skb; 77 return skb;
82} 78}
83 79
84const struct dsa_device_ops trailer_netdev_ops = { 80static const struct dsa_device_ops trailer_netdev_ops = {
81 .name = "trailer",
82 .proto = DSA_TAG_PROTO_TRAILER,
85 .xmit = trailer_xmit, 83 .xmit = trailer_xmit,
86 .rcv = trailer_rcv, 84 .rcv = trailer_rcv,
87 .overhead = 4, 85 .overhead = 4,
88}; 86};
87
88MODULE_LICENSE("GPL");
89MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_TRAILER);
90
91module_dsa_tag_driver(trailer_netdev_ops);
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index f7a3d7a171c7..4b2b222377ac 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -119,13 +119,14 @@ EXPORT_SYMBOL(eth_header);
119 119
120/** 120/**
121 * eth_get_headlen - determine the length of header for an ethernet frame 121 * eth_get_headlen - determine the length of header for an ethernet frame
122 * @dev: pointer to network device
122 * @data: pointer to start of frame 123 * @data: pointer to start of frame
123 * @len: total length of frame 124 * @len: total length of frame
124 * 125 *
125 * Make a best effort attempt to pull the length for all of the headers for 126 * Make a best effort attempt to pull the length for all of the headers for
126 * a given frame in a linear buffer. 127 * a given frame in a linear buffer.
127 */ 128 */
128u32 eth_get_headlen(void *data, unsigned int len) 129u32 eth_get_headlen(const struct net_device *dev, void *data, unsigned int len)
129{ 130{
130 const unsigned int flags = FLOW_DISSECTOR_F_PARSE_1ST_FRAG; 131 const unsigned int flags = FLOW_DISSECTOR_F_PARSE_1ST_FRAG;
131 const struct ethhdr *eth = (const struct ethhdr *)data; 132 const struct ethhdr *eth = (const struct ethhdr *)data;
@@ -136,8 +137,9 @@ u32 eth_get_headlen(void *data, unsigned int len)
136 return len; 137 return len;
137 138
138 /* parse any remaining L2/L3 headers, check for L4 */ 139 /* parse any remaining L2/L3 headers, check for L4 */
139 if (!skb_flow_dissect_flow_keys_basic(NULL, &keys, data, eth->h_proto, 140 if (!skb_flow_dissect_flow_keys_basic(dev_net(dev), NULL, &keys, data,
140 sizeof(*eth), len, flags)) 141 eth->h_proto, sizeof(*eth),
142 len, flags))
141 return max_t(u32, keys.control.thoff, sizeof(*eth)); 143 return max_t(u32, keys.control.thoff, sizeof(*eth));
142 144
143 /* parse for any L4 headers */ 145 /* parse for any L4 headers */
@@ -183,8 +185,12 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
183 * at all, so we check here whether one of those tagging 185 * at all, so we check here whether one of those tagging
184 * variants has been configured on the receiving interface, 186 * variants has been configured on the receiving interface,
185 * and if so, set skb->protocol without looking at the packet. 187 * and if so, set skb->protocol without looking at the packet.
188 * The DSA tagging protocol may be able to decode some but not all
189 * traffic (for example only for management). In that case give it the
190 * option to filter the packets from which it can decode source port
191 * information.
186 */ 192 */
187 if (unlikely(netdev_uses_dsa(dev))) 193 if (unlikely(netdev_uses_dsa(dev)) && dsa_can_decode(skb, dev))
188 return htons(ETH_P_XDSA); 194 return htons(ETH_P_XDSA);
189 195
190 if (likely(eth_proto_is_802_3(eth->h_proto))) 196 if (likely(eth_proto_is_802_3(eth->h_proto)))
@@ -554,7 +560,7 @@ int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
554 addr = NULL; 560 addr = NULL;
555 if (dp) 561 if (dp)
556 addr = of_get_mac_address(dp); 562 addr = of_get_mac_address(dp);
557 if (!addr) 563 if (IS_ERR_OR_NULL(addr))
558 addr = arch_get_platform_mac_address(); 564 addr = arch_get_platform_mac_address();
559 565
560 if (!addr) 566 if (!addr)
diff --git a/net/hsr/Makefile b/net/hsr/Makefile
index 9ae972a820f4..e45757fc477f 100644
--- a/net/hsr/Makefile
+++ b/net/hsr/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_HSR) += hsr.o
6 6
7hsr-y := hsr_main.o hsr_framereg.o hsr_device.o \ 7hsr-y := hsr_main.o hsr_framereg.o hsr_device.o \
8 hsr_netlink.o hsr_slave.o hsr_forward.o 8 hsr_netlink.o hsr_slave.o hsr_forward.o
9hsr-$(CONFIG_DEBUG_FS) += hsr_debugfs.o
diff --git a/net/hsr/hsr_debugfs.c b/net/hsr/hsr_debugfs.c
new file mode 100644
index 000000000000..94447974a3c0
--- /dev/null
+++ b/net/hsr/hsr_debugfs.c
@@ -0,0 +1,119 @@
1/*
2 * hsr_debugfs code
3 * Copyright (C) 2019 Texas Instruments Incorporated
4 *
5 * Author(s):
6 * Murali Karicheri <m-karicheri2@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17#include <linux/module.h>
18#include <linux/errno.h>
19#include <linux/debugfs.h>
20#include "hsr_main.h"
21#include "hsr_framereg.h"
22
23static void print_mac_address(struct seq_file *sfp, unsigned char *mac)
24{
25 seq_printf(sfp, "%02x:%02x:%02x:%02x:%02x:%02x:",
26 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
27}
28
29/* hsr_node_table_show - Formats and prints node_table entries */
30static int
31hsr_node_table_show(struct seq_file *sfp, void *data)
32{
33 struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
34 struct hsr_node *node;
35
36 seq_puts(sfp, "Node Table entries\n");
37 seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], ");
38 seq_puts(sfp, "time_in[B], Address-B port\n");
39 rcu_read_lock();
40 list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
41 /* skip self node */
42 if (hsr_addr_is_self(priv, node->macaddress_A))
43 continue;
44 print_mac_address(sfp, &node->macaddress_A[0]);
45 seq_puts(sfp, " ");
46 print_mac_address(sfp, &node->macaddress_B[0]);
47 seq_printf(sfp, "0x%lx, ", node->time_in[HSR_PT_SLAVE_A]);
48 seq_printf(sfp, "0x%lx ", node->time_in[HSR_PT_SLAVE_B]);
49 seq_printf(sfp, "0x%x\n", node->addr_B_port);
50 }
51 rcu_read_unlock();
52 return 0;
53}
54
55/* hsr_node_table_open - Open the node_table file
56 *
57 * Description:
58 * This routine opens a debugfs file node_table of specific hsr device
59 */
60static int
61hsr_node_table_open(struct inode *inode, struct file *filp)
62{
63 return single_open(filp, hsr_node_table_show, inode->i_private);
64}
65
66static const struct file_operations hsr_fops = {
67 .owner = THIS_MODULE,
68 .open = hsr_node_table_open,
69 .read = seq_read,
70 .llseek = seq_lseek,
71 .release = single_release,
72};
73
74/* hsr_debugfs_init - create hsr node_table file for dumping
75 * the node table
76 *
77 * Description:
78 * When debugfs is configured this routine sets up the node_table file per
79 * hsr device for dumping the node_table entries
80 */
81int hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
82{
83 int rc = -1;
84 struct dentry *de = NULL;
85
86 de = debugfs_create_dir(hsr_dev->name, NULL);
87 if (!de) {
88 pr_err("Cannot create hsr debugfs root\n");
89 return rc;
90 }
91
92 priv->node_tbl_root = de;
93
94 de = debugfs_create_file("node_table", S_IFREG | 0444,
95 priv->node_tbl_root, priv,
96 &hsr_fops);
97 if (!de) {
98 pr_err("Cannot create hsr node_table directory\n");
99 return rc;
100 }
101 priv->node_tbl_file = de;
102
103 return 0;
104}
105
106/* hsr_debugfs_term - Tear down debugfs intrastructure
107 *
108 * Description:
109 * When Debufs is configured this routine removes debugfs file system
110 * elements that are specific to hsr
111 */
112void
113hsr_debugfs_term(struct hsr_priv *priv)
114{
115 debugfs_remove(priv->node_tbl_file);
116 priv->node_tbl_file = NULL;
117 debugfs_remove(priv->node_tbl_root);
118 priv->node_tbl_root = NULL;
119}
diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index a97bf326b231..15c72065df79 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -1,10 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 * 6 *
@@ -23,7 +19,6 @@
23#include "hsr_main.h" 19#include "hsr_main.h"
24#include "hsr_forward.h" 20#include "hsr_forward.h"
25 21
26
27static bool is_admin_up(struct net_device *dev) 22static bool is_admin_up(struct net_device *dev)
28{ 23{
29 return dev && (dev->flags & IFF_UP); 24 return dev && (dev->flags & IFF_UP);
@@ -68,7 +63,7 @@ static bool hsr_check_carrier(struct hsr_port *master)
68 63
69 rcu_read_lock(); 64 rcu_read_lock();
70 hsr_for_each_port(master->hsr, port) 65 hsr_for_each_port(master->hsr, port)
71 if ((port->type != HSR_PT_MASTER) && is_slave_up(port->dev)) { 66 if (port->type != HSR_PT_MASTER && is_slave_up(port->dev)) {
72 has_carrier = true; 67 has_carrier = true;
73 break; 68 break;
74 } 69 }
@@ -82,7 +77,6 @@ static bool hsr_check_carrier(struct hsr_port *master)
82 return has_carrier; 77 return has_carrier;
83} 78}
84 79
85
86static void hsr_check_announce(struct net_device *hsr_dev, 80static void hsr_check_announce(struct net_device *hsr_dev,
87 unsigned char old_operstate) 81 unsigned char old_operstate)
88{ 82{
@@ -90,15 +84,14 @@ static void hsr_check_announce(struct net_device *hsr_dev,
90 84
91 hsr = netdev_priv(hsr_dev); 85 hsr = netdev_priv(hsr_dev);
92 86
93 if ((hsr_dev->operstate == IF_OPER_UP) 87 if (hsr_dev->operstate == IF_OPER_UP && old_operstate != IF_OPER_UP) {
94 && (old_operstate != IF_OPER_UP)) {
95 /* Went up */ 88 /* Went up */
96 hsr->announce_count = 0; 89 hsr->announce_count = 0;
97 mod_timer(&hsr->announce_timer, 90 mod_timer(&hsr->announce_timer,
98 jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL)); 91 jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL));
99 } 92 }
100 93
101 if ((hsr_dev->operstate != IF_OPER_UP) && (old_operstate == IF_OPER_UP)) 94 if (hsr_dev->operstate != IF_OPER_UP && old_operstate == IF_OPER_UP)
102 /* Went down */ 95 /* Went down */
103 del_timer(&hsr->announce_timer); 96 del_timer(&hsr->announce_timer);
104} 97}
@@ -136,7 +129,6 @@ int hsr_get_max_mtu(struct hsr_priv *hsr)
136 return mtu_max - HSR_HLEN; 129 return mtu_max - HSR_HLEN;
137} 130}
138 131
139
140static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu) 132static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu)
141{ 133{
142 struct hsr_priv *hsr; 134 struct hsr_priv *hsr;
@@ -191,14 +183,12 @@ static int hsr_dev_open(struct net_device *dev)
191 return 0; 183 return 0;
192} 184}
193 185
194
195static int hsr_dev_close(struct net_device *dev) 186static int hsr_dev_close(struct net_device *dev)
196{ 187{
197 /* Nothing to do here. */ 188 /* Nothing to do here. */
198 return 0; 189 return 0;
199} 190}
200 191
201
202static netdev_features_t hsr_features_recompute(struct hsr_priv *hsr, 192static netdev_features_t hsr_features_recompute(struct hsr_priv *hsr,
203 netdev_features_t features) 193 netdev_features_t features)
204{ 194{
@@ -231,7 +221,6 @@ static netdev_features_t hsr_fix_features(struct net_device *dev,
231 return hsr_features_recompute(hsr, features); 221 return hsr_features_recompute(hsr, features);
232} 222}
233 223
234
235static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev) 224static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
236{ 225{
237 struct hsr_priv *hsr = netdev_priv(dev); 226 struct hsr_priv *hsr = netdev_priv(dev);
@@ -244,14 +233,13 @@ static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
244 return NETDEV_TX_OK; 233 return NETDEV_TX_OK;
245} 234}
246 235
247
248static const struct header_ops hsr_header_ops = { 236static const struct header_ops hsr_header_ops = {
249 .create = eth_header, 237 .create = eth_header,
250 .parse = eth_header_parse, 238 .parse = eth_header_parse,
251}; 239};
252 240
253static void send_hsr_supervision_frame(struct hsr_port *master, 241static void send_hsr_supervision_frame(struct hsr_port *master,
254 u8 type, u8 hsrVer) 242 u8 type, u8 hsr_ver)
255{ 243{
256 struct sk_buff *skb; 244 struct sk_buff *skb;
257 int hlen, tlen; 245 int hlen, tlen;
@@ -262,39 +250,38 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
262 250
263 hlen = LL_RESERVED_SPACE(master->dev); 251 hlen = LL_RESERVED_SPACE(master->dev);
264 tlen = master->dev->needed_tailroom; 252 tlen = master->dev->needed_tailroom;
265 skb = dev_alloc_skb( 253 skb = dev_alloc_skb(sizeof(struct hsr_tag) +
266 sizeof(struct hsr_tag) + 254 sizeof(struct hsr_sup_tag) +
267 sizeof(struct hsr_sup_tag) + 255 sizeof(struct hsr_sup_payload) + hlen + tlen);
268 sizeof(struct hsr_sup_payload) + hlen + tlen);
269 256
270 if (skb == NULL) 257 if (!skb)
271 return; 258 return;
272 259
273 skb_reserve(skb, hlen); 260 skb_reserve(skb, hlen);
274 261
275 skb->dev = master->dev; 262 skb->dev = master->dev;
276 skb->protocol = htons(hsrVer ? ETH_P_HSR : ETH_P_PRP); 263 skb->protocol = htons(hsr_ver ? ETH_P_HSR : ETH_P_PRP);
277 skb->priority = TC_PRIO_CONTROL; 264 skb->priority = TC_PRIO_CONTROL;
278 265
279 if (dev_hard_header(skb, skb->dev, (hsrVer ? ETH_P_HSR : ETH_P_PRP), 266 if (dev_hard_header(skb, skb->dev, (hsr_ver ? ETH_P_HSR : ETH_P_PRP),
280 master->hsr->sup_multicast_addr, 267 master->hsr->sup_multicast_addr,
281 skb->dev->dev_addr, skb->len) <= 0) 268 skb->dev->dev_addr, skb->len) <= 0)
282 goto out; 269 goto out;
283 skb_reset_mac_header(skb); 270 skb_reset_mac_header(skb);
284 271
285 if (hsrVer > 0) { 272 if (hsr_ver > 0) {
286 hsr_tag = skb_put(skb, sizeof(struct hsr_tag)); 273 hsr_tag = skb_put(skb, sizeof(struct hsr_tag));
287 hsr_tag->encap_proto = htons(ETH_P_PRP); 274 hsr_tag->encap_proto = htons(ETH_P_PRP);
288 set_hsr_tag_LSDU_size(hsr_tag, HSR_V1_SUP_LSDUSIZE); 275 set_hsr_tag_LSDU_size(hsr_tag, HSR_V1_SUP_LSDUSIZE);
289 } 276 }
290 277
291 hsr_stag = skb_put(skb, sizeof(struct hsr_sup_tag)); 278 hsr_stag = skb_put(skb, sizeof(struct hsr_sup_tag));
292 set_hsr_stag_path(hsr_stag, (hsrVer ? 0x0 : 0xf)); 279 set_hsr_stag_path(hsr_stag, (hsr_ver ? 0x0 : 0xf));
293 set_hsr_stag_HSR_Ver(hsr_stag, hsrVer); 280 set_hsr_stag_HSR_ver(hsr_stag, hsr_ver);
294 281
295 /* From HSRv1 on we have separate supervision sequence numbers. */ 282 /* From HSRv1 on we have separate supervision sequence numbers. */
296 spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags); 283 spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags);
297 if (hsrVer > 0) { 284 if (hsr_ver > 0) {
298 hsr_stag->sequence_nr = htons(master->hsr->sup_sequence_nr); 285 hsr_stag->sequence_nr = htons(master->hsr->sup_sequence_nr);
299 hsr_tag->sequence_nr = htons(master->hsr->sequence_nr); 286 hsr_tag->sequence_nr = htons(master->hsr->sequence_nr);
300 master->hsr->sup_sequence_nr++; 287 master->hsr->sup_sequence_nr++;
@@ -305,13 +292,14 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
305 } 292 }
306 spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags); 293 spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags);
307 294
308 hsr_stag->HSR_TLV_Type = type; 295 hsr_stag->HSR_TLV_type = type;
309 /* TODO: Why 12 in HSRv0? */ 296 /* TODO: Why 12 in HSRv0? */
310 hsr_stag->HSR_TLV_Length = hsrVer ? sizeof(struct hsr_sup_payload) : 12; 297 hsr_stag->HSR_TLV_length =
298 hsr_ver ? sizeof(struct hsr_sup_payload) : 12;
311 299
312 /* Payload: MacAddressA */ 300 /* Payload: MacAddressA */
313 hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload)); 301 hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload));
314 ether_addr_copy(hsr_sp->MacAddressA, master->dev->dev_addr); 302 ether_addr_copy(hsr_sp->macaddress_A, master->dev->dev_addr);
315 303
316 if (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN)) 304 if (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN))
317 return; 305 return;
@@ -324,7 +312,6 @@ out:
324 kfree_skb(skb); 312 kfree_skb(skb);
325} 313}
326 314
327
328/* Announce (supervision frame) timer function 315/* Announce (supervision frame) timer function
329 */ 316 */
330static void hsr_announce(struct timer_list *t) 317static void hsr_announce(struct timer_list *t)
@@ -338,15 +325,15 @@ static void hsr_announce(struct timer_list *t)
338 rcu_read_lock(); 325 rcu_read_lock();
339 master = hsr_port_get_hsr(hsr, HSR_PT_MASTER); 326 master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
340 327
341 if (hsr->announce_count < 3 && hsr->protVersion == 0) { 328 if (hsr->announce_count < 3 && hsr->prot_version == 0) {
342 send_hsr_supervision_frame(master, HSR_TLV_ANNOUNCE, 329 send_hsr_supervision_frame(master, HSR_TLV_ANNOUNCE,
343 hsr->protVersion); 330 hsr->prot_version);
344 hsr->announce_count++; 331 hsr->announce_count++;
345 332
346 interval = msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL); 333 interval = msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL);
347 } else { 334 } else {
348 send_hsr_supervision_frame(master, HSR_TLV_LIFE_CHECK, 335 send_hsr_supervision_frame(master, HSR_TLV_LIFE_CHECK,
349 hsr->protVersion); 336 hsr->prot_version);
350 337
351 interval = msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL); 338 interval = msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL);
352 } 339 }
@@ -357,7 +344,6 @@ static void hsr_announce(struct timer_list *t)
357 rcu_read_unlock(); 344 rcu_read_unlock();
358} 345}
359 346
360
361/* According to comments in the declaration of struct net_device, this function 347/* According to comments in the declaration of struct net_device, this function
362 * is "Called from unregister, can be used to call free_netdev". Ok then... 348 * is "Called from unregister, can be used to call free_netdev". Ok then...
363 */ 349 */
@@ -368,6 +354,8 @@ static void hsr_dev_destroy(struct net_device *hsr_dev)
368 354
369 hsr = netdev_priv(hsr_dev); 355 hsr = netdev_priv(hsr_dev);
370 356
357 hsr_debugfs_term(hsr);
358
371 rtnl_lock(); 359 rtnl_lock();
372 hsr_for_each_port(hsr, port) 360 hsr_for_each_port(hsr, port)
373 hsr_del_port(port); 361 hsr_del_port(port);
@@ -423,7 +411,6 @@ void hsr_dev_setup(struct net_device *dev)
423 dev->features |= NETIF_F_NETNS_LOCAL; 411 dev->features |= NETIF_F_NETNS_LOCAL;
424} 412}
425 413
426
427/* Return true if dev is a HSR master; return false otherwise. 414/* Return true if dev is a HSR master; return false otherwise.
428 */ 415 */
429inline bool is_hsr_master(struct net_device *dev) 416inline bool is_hsr_master(struct net_device *dev)
@@ -467,7 +454,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
467 ether_addr_copy(hsr->sup_multicast_addr, def_multicast_addr); 454 ether_addr_copy(hsr->sup_multicast_addr, def_multicast_addr);
468 hsr->sup_multicast_addr[ETH_ALEN - 1] = multicast_spec; 455 hsr->sup_multicast_addr[ETH_ALEN - 1] = multicast_spec;
469 456
470 hsr->protVersion = protocol_version; 457 hsr->prot_version = protocol_version;
471 458
472 /* FIXME: should I modify the value of these? 459 /* FIXME: should I modify the value of these?
473 * 460 *
@@ -498,6 +485,9 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
498 goto fail; 485 goto fail;
499 486
500 mod_timer(&hsr->prune_timer, jiffies + msecs_to_jiffies(PRUNE_PERIOD)); 487 mod_timer(&hsr->prune_timer, jiffies + msecs_to_jiffies(PRUNE_PERIOD));
488 res = hsr_debugfs_init(hsr, hsr_dev);
489 if (res)
490 goto fail;
501 491
502 return 0; 492 return 0;
503 493
diff --git a/net/hsr/hsr_device.h b/net/hsr/hsr_device.h
index 9975e31bbb82..6d7759c4f5f9 100644
--- a/net/hsr/hsr_device.h
+++ b/net/hsr/hsr_device.h
@@ -1,10 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 6 */
diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
index 04b5450c5a55..ddd9605bad04 100644
--- a/net/hsr/hsr_forward.c
+++ b/net/hsr/hsr_forward.c
@@ -1,10 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 6 */
@@ -17,7 +13,6 @@
17#include "hsr_main.h" 13#include "hsr_main.h"
18#include "hsr_framereg.h" 14#include "hsr_framereg.h"
19 15
20
21struct hsr_node; 16struct hsr_node;
22 17
23struct hsr_frame_info { 18struct hsr_frame_info {
@@ -32,7 +27,6 @@ struct hsr_frame_info {
32 bool is_local_exclusive; 27 bool is_local_exclusive;
33}; 28};
34 29
35
36/* The uses I can see for these HSR supervision frames are: 30/* The uses I can see for these HSR supervision frames are:
37 * 1) Use the frames that are sent after node initialization ("HSR_TLV.Type = 31 * 1) Use the frames that are sent after node initialization ("HSR_TLV.Type =
38 * 22") to reset any sequence_nr counters belonging to that node. Useful if 32 * 22") to reset any sequence_nr counters belonging to that node. Useful if
@@ -50,46 +44,45 @@ struct hsr_frame_info {
50 */ 44 */
51static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb) 45static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb)
52{ 46{
53 struct ethhdr *ethHdr; 47 struct ethhdr *eth_hdr;
54 struct hsr_sup_tag *hsrSupTag; 48 struct hsr_sup_tag *hsr_sup_tag;
55 struct hsrv1_ethhdr_sp *hsrV1Hdr; 49 struct hsrv1_ethhdr_sp *hsr_V1_hdr;
56 50
57 WARN_ON_ONCE(!skb_mac_header_was_set(skb)); 51 WARN_ON_ONCE(!skb_mac_header_was_set(skb));
58 ethHdr = (struct ethhdr *) skb_mac_header(skb); 52 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
59 53
60 /* Correct addr? */ 54 /* Correct addr? */
61 if (!ether_addr_equal(ethHdr->h_dest, 55 if (!ether_addr_equal(eth_hdr->h_dest,
62 hsr->sup_multicast_addr)) 56 hsr->sup_multicast_addr))
63 return false; 57 return false;
64 58
65 /* Correct ether type?. */ 59 /* Correct ether type?. */
66 if (!(ethHdr->h_proto == htons(ETH_P_PRP) 60 if (!(eth_hdr->h_proto == htons(ETH_P_PRP) ||
67 || ethHdr->h_proto == htons(ETH_P_HSR))) 61 eth_hdr->h_proto == htons(ETH_P_HSR)))
68 return false; 62 return false;
69 63
70 /* Get the supervision header from correct location. */ 64 /* Get the supervision header from correct location. */
71 if (ethHdr->h_proto == htons(ETH_P_HSR)) { /* Okay HSRv1. */ 65 if (eth_hdr->h_proto == htons(ETH_P_HSR)) { /* Okay HSRv1. */
72 hsrV1Hdr = (struct hsrv1_ethhdr_sp *) skb_mac_header(skb); 66 hsr_V1_hdr = (struct hsrv1_ethhdr_sp *)skb_mac_header(skb);
73 if (hsrV1Hdr->hsr.encap_proto != htons(ETH_P_PRP)) 67 if (hsr_V1_hdr->hsr.encap_proto != htons(ETH_P_PRP))
74 return false; 68 return false;
75 69
76 hsrSupTag = &hsrV1Hdr->hsr_sup; 70 hsr_sup_tag = &hsr_V1_hdr->hsr_sup;
77 } else { 71 } else {
78 hsrSupTag = &((struct hsrv0_ethhdr_sp *) skb_mac_header(skb))->hsr_sup; 72 hsr_sup_tag =
73 &((struct hsrv0_ethhdr_sp *)skb_mac_header(skb))->hsr_sup;
79 } 74 }
80 75
81 if ((hsrSupTag->HSR_TLV_Type != HSR_TLV_ANNOUNCE) && 76 if (hsr_sup_tag->HSR_TLV_type != HSR_TLV_ANNOUNCE &&
82 (hsrSupTag->HSR_TLV_Type != HSR_TLV_LIFE_CHECK)) 77 hsr_sup_tag->HSR_TLV_type != HSR_TLV_LIFE_CHECK)
83 return false; 78 return false;
84 if ((hsrSupTag->HSR_TLV_Length != 12) && 79 if (hsr_sup_tag->HSR_TLV_length != 12 &&
85 (hsrSupTag->HSR_TLV_Length != 80 hsr_sup_tag->HSR_TLV_length != sizeof(struct hsr_sup_payload))
86 sizeof(struct hsr_sup_payload)))
87 return false; 81 return false;
88 82
89 return true; 83 return true;
90} 84}
91 85
92
93static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in, 86static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in,
94 struct hsr_frame_info *frame) 87 struct hsr_frame_info *frame)
95{ 88{
@@ -100,7 +93,7 @@ static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in,
100 skb_pull(skb_in, HSR_HLEN); 93 skb_pull(skb_in, HSR_HLEN);
101 skb = __pskb_copy(skb_in, skb_headroom(skb_in) - HSR_HLEN, GFP_ATOMIC); 94 skb = __pskb_copy(skb_in, skb_headroom(skb_in) - HSR_HLEN, GFP_ATOMIC);
102 skb_push(skb_in, HSR_HLEN); 95 skb_push(skb_in, HSR_HLEN);
103 if (skb == NULL) 96 if (!skb)
104 return NULL; 97 return NULL;
105 98
106 skb_reset_mac_header(skb); 99 skb_reset_mac_header(skb);
@@ -108,7 +101,7 @@ static struct sk_buff *create_stripped_skb(struct sk_buff *skb_in,
108 if (skb->ip_summed == CHECKSUM_PARTIAL) 101 if (skb->ip_summed == CHECKSUM_PARTIAL)
109 skb->csum_start -= HSR_HLEN; 102 skb->csum_start -= HSR_HLEN;
110 103
111 copylen = 2*ETH_ALEN; 104 copylen = 2 * ETH_ALEN;
112 if (frame->is_vlan) 105 if (frame->is_vlan)
113 copylen += VLAN_HLEN; 106 copylen += VLAN_HLEN;
114 src = skb_mac_header(skb_in); 107 src = skb_mac_header(skb_in);
@@ -127,9 +120,8 @@ static struct sk_buff *frame_get_stripped_skb(struct hsr_frame_info *frame,
127 return skb_clone(frame->skb_std, GFP_ATOMIC); 120 return skb_clone(frame->skb_std, GFP_ATOMIC);
128} 121}
129 122
130
131static void hsr_fill_tag(struct sk_buff *skb, struct hsr_frame_info *frame, 123static void hsr_fill_tag(struct sk_buff *skb, struct hsr_frame_info *frame,
132 struct hsr_port *port, u8 protoVersion) 124 struct hsr_port *port, u8 proto_version)
133{ 125{
134 struct hsr_ethhdr *hsr_ethhdr; 126 struct hsr_ethhdr *hsr_ethhdr;
135 int lane_id; 127 int lane_id;
@@ -144,13 +136,13 @@ static void hsr_fill_tag(struct sk_buff *skb, struct hsr_frame_info *frame,
144 if (frame->is_vlan) 136 if (frame->is_vlan)
145 lsdu_size -= 4; 137 lsdu_size -= 4;
146 138
147 hsr_ethhdr = (struct hsr_ethhdr *) skb_mac_header(skb); 139 hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
148 140
149 set_hsr_tag_path(&hsr_ethhdr->hsr_tag, lane_id); 141 set_hsr_tag_path(&hsr_ethhdr->hsr_tag, lane_id);
150 set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, lsdu_size); 142 set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, lsdu_size);
151 hsr_ethhdr->hsr_tag.sequence_nr = htons(frame->sequence_nr); 143 hsr_ethhdr->hsr_tag.sequence_nr = htons(frame->sequence_nr);
152 hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto; 144 hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto;
153 hsr_ethhdr->ethhdr.h_proto = htons(protoVersion ? 145 hsr_ethhdr->ethhdr.h_proto = htons(proto_version ?
154 ETH_P_HSR : ETH_P_PRP); 146 ETH_P_HSR : ETH_P_PRP);
155} 147}
156 148
@@ -164,7 +156,7 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o,
164 156
165 /* Create the new skb with enough headroom to fit the HSR tag */ 157 /* Create the new skb with enough headroom to fit the HSR tag */
166 skb = __pskb_copy(skb_o, skb_headroom(skb_o) + HSR_HLEN, GFP_ATOMIC); 158 skb = __pskb_copy(skb_o, skb_headroom(skb_o) + HSR_HLEN, GFP_ATOMIC);
167 if (skb == NULL) 159 if (!skb)
168 return NULL; 160 return NULL;
169 skb_reset_mac_header(skb); 161 skb_reset_mac_header(skb);
170 162
@@ -180,7 +172,7 @@ static struct sk_buff *create_tagged_skb(struct sk_buff *skb_o,
180 memmove(dst, src, movelen); 172 memmove(dst, src, movelen);
181 skb_reset_mac_header(skb); 173 skb_reset_mac_header(skb);
182 174
183 hsr_fill_tag(skb, frame, port, port->hsr->protVersion); 175 hsr_fill_tag(skb, frame, port, port->hsr->prot_version);
184 176
185 return skb; 177 return skb;
186} 178}
@@ -194,7 +186,7 @@ static struct sk_buff *frame_get_tagged_skb(struct hsr_frame_info *frame,
194 if (frame->skb_hsr) 186 if (frame->skb_hsr)
195 return skb_clone(frame->skb_hsr, GFP_ATOMIC); 187 return skb_clone(frame->skb_hsr, GFP_ATOMIC);
196 188
197 if ((port->type != HSR_PT_SLAVE_A) && (port->type != HSR_PT_SLAVE_B)) { 189 if (port->type != HSR_PT_SLAVE_A && port->type != HSR_PT_SLAVE_B) {
198 WARN_ONCE(1, "HSR: Bug: trying to create a tagged frame for a non-ring port"); 190 WARN_ONCE(1, "HSR: Bug: trying to create a tagged frame for a non-ring port");
199 return NULL; 191 return NULL;
200 } 192 }
@@ -202,7 +194,6 @@ static struct sk_buff *frame_get_tagged_skb(struct hsr_frame_info *frame,
202 return create_tagged_skb(frame->skb_std, frame, port); 194 return create_tagged_skb(frame->skb_std, frame, port);
203} 195}
204 196
205
206static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, 197static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
207 struct hsr_node *node_src) 198 struct hsr_node *node_src)
208{ 199{
@@ -237,7 +228,6 @@ static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
237 return dev_queue_xmit(skb); 228 return dev_queue_xmit(skb);
238} 229}
239 230
240
241/* Forward the frame through all devices except: 231/* Forward the frame through all devices except:
242 * - Back through the receiving device 232 * - Back through the receiving device
243 * - If it's a HSR frame: through a device where it has passed before 233 * - If it's a HSR frame: through a device where it has passed before
@@ -260,11 +250,11 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
260 continue; 250 continue;
261 251
262 /* Don't deliver locally unless we should */ 252 /* Don't deliver locally unless we should */
263 if ((port->type == HSR_PT_MASTER) && !frame->is_local_dest) 253 if (port->type == HSR_PT_MASTER && !frame->is_local_dest)
264 continue; 254 continue;
265 255
266 /* Deliver frames directly addressed to us to master only */ 256 /* Deliver frames directly addressed to us to master only */
267 if ((port->type != HSR_PT_MASTER) && frame->is_local_exclusive) 257 if (port->type != HSR_PT_MASTER && frame->is_local_exclusive)
268 continue; 258 continue;
269 259
270 /* Don't send frame over port where it has been sent before */ 260 /* Don't send frame over port where it has been sent before */
@@ -272,7 +262,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
272 frame->sequence_nr)) 262 frame->sequence_nr))
273 continue; 263 continue;
274 264
275 if (frame->is_supervision && (port->type == HSR_PT_MASTER)) { 265 if (frame->is_supervision && port->type == HSR_PT_MASTER) {
276 hsr_handle_sup_frame(frame->skb_hsr, 266 hsr_handle_sup_frame(frame->skb_hsr,
277 frame->node_src, 267 frame->node_src,
278 frame->port_rcv); 268 frame->port_rcv);
@@ -283,7 +273,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
283 skb = frame_get_tagged_skb(frame, port); 273 skb = frame_get_tagged_skb(frame, port);
284 else 274 else
285 skb = frame_get_stripped_skb(frame, port); 275 skb = frame_get_stripped_skb(frame, port);
286 if (skb == NULL) { 276 if (!skb) {
287 /* FIXME: Record the dropped frame? */ 277 /* FIXME: Record the dropped frame? */
288 continue; 278 continue;
289 } 279 }
@@ -296,7 +286,6 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
296 } 286 }
297} 287}
298 288
299
300static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb, 289static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb,
301 struct hsr_frame_info *frame) 290 struct hsr_frame_info *frame)
302{ 291{
@@ -307,16 +296,15 @@ static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb,
307 frame->is_local_exclusive = false; 296 frame->is_local_exclusive = false;
308 } 297 }
309 298
310 if ((skb->pkt_type == PACKET_HOST) || 299 if (skb->pkt_type == PACKET_HOST ||
311 (skb->pkt_type == PACKET_MULTICAST) || 300 skb->pkt_type == PACKET_MULTICAST ||
312 (skb->pkt_type == PACKET_BROADCAST)) { 301 skb->pkt_type == PACKET_BROADCAST) {
313 frame->is_local_dest = true; 302 frame->is_local_dest = true;
314 } else { 303 } else {
315 frame->is_local_dest = false; 304 frame->is_local_dest = false;
316 } 305 }
317} 306}
318 307
319
320static int hsr_fill_frame_info(struct hsr_frame_info *frame, 308static int hsr_fill_frame_info(struct hsr_frame_info *frame,
321 struct sk_buff *skb, struct hsr_port *port) 309 struct sk_buff *skb, struct hsr_port *port)
322{ 310{
@@ -325,18 +313,18 @@ static int hsr_fill_frame_info(struct hsr_frame_info *frame,
325 313
326 frame->is_supervision = is_supervision_frame(port->hsr, skb); 314 frame->is_supervision = is_supervision_frame(port->hsr, skb);
327 frame->node_src = hsr_get_node(port, skb, frame->is_supervision); 315 frame->node_src = hsr_get_node(port, skb, frame->is_supervision);
328 if (frame->node_src == NULL) 316 if (!frame->node_src)
329 return -1; /* Unknown node and !is_supervision, or no mem */ 317 return -1; /* Unknown node and !is_supervision, or no mem */
330 318
331 ethhdr = (struct ethhdr *) skb_mac_header(skb); 319 ethhdr = (struct ethhdr *)skb_mac_header(skb);
332 frame->is_vlan = false; 320 frame->is_vlan = false;
333 if (ethhdr->h_proto == htons(ETH_P_8021Q)) { 321 if (ethhdr->h_proto == htons(ETH_P_8021Q)) {
334 frame->is_vlan = true; 322 frame->is_vlan = true;
335 /* FIXME: */ 323 /* FIXME: */
336 WARN_ONCE(1, "HSR: VLAN not yet supported"); 324 WARN_ONCE(1, "HSR: VLAN not yet supported");
337 } 325 }
338 if (ethhdr->h_proto == htons(ETH_P_PRP) 326 if (ethhdr->h_proto == htons(ETH_P_PRP) ||
339 || ethhdr->h_proto == htons(ETH_P_HSR)) { 327 ethhdr->h_proto == htons(ETH_P_HSR)) {
340 frame->skb_std = NULL; 328 frame->skb_std = NULL;
341 frame->skb_hsr = skb; 329 frame->skb_hsr = skb;
342 frame->sequence_nr = hsr_get_skb_sequence_nr(skb); 330 frame->sequence_nr = hsr_get_skb_sequence_nr(skb);
@@ -371,10 +359,17 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
371 goto out_drop; 359 goto out_drop;
372 hsr_register_frame_in(frame.node_src, port, frame.sequence_nr); 360 hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
373 hsr_forward_do(&frame); 361 hsr_forward_do(&frame);
362 /* Gets called for ingress frames as well as egress from master port.
363 * So check and increment stats for master port only here.
364 */
365 if (port->type == HSR_PT_MASTER) {
366 port->dev->stats.tx_packets++;
367 port->dev->stats.tx_bytes += skb->len;
368 }
374 369
375 if (frame.skb_hsr != NULL) 370 if (frame.skb_hsr)
376 kfree_skb(frame.skb_hsr); 371 kfree_skb(frame.skb_hsr);
377 if (frame.skb_std != NULL) 372 if (frame.skb_std)
378 kfree_skb(frame.skb_std); 373 kfree_skb(frame.skb_std);
379 return; 374 return;
380 375
diff --git a/net/hsr/hsr_forward.h b/net/hsr/hsr_forward.h
index 5c5bc4b6b75f..51a69295566c 100644
--- a/net/hsr/hsr_forward.h
+++ b/net/hsr/hsr_forward.h
@@ -1,10 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 6 */
diff --git a/net/hsr/hsr_framereg.c b/net/hsr/hsr_framereg.c
index 9af16cb68f76..9fa9abd83018 100644
--- a/net/hsr/hsr_framereg.c
+++ b/net/hsr/hsr_framereg.c
@@ -1,10 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 * 6 *
@@ -22,23 +18,8 @@
22#include "hsr_framereg.h" 18#include "hsr_framereg.h"
23#include "hsr_netlink.h" 19#include "hsr_netlink.h"
24 20
25
26struct hsr_node {
27 struct list_head mac_list;
28 unsigned char MacAddressA[ETH_ALEN];
29 unsigned char MacAddressB[ETH_ALEN];
30 /* Local slave through which AddrB frames are received from this node */
31 enum hsr_port_type AddrB_port;
32 unsigned long time_in[HSR_PT_PORTS];
33 bool time_in_stale[HSR_PT_PORTS];
34 u16 seq_out[HSR_PT_PORTS];
35 struct rcu_head rcu_head;
36};
37
38
39/* TODO: use hash lists for mac addresses (linux/jhash.h)? */ 21/* TODO: use hash lists for mac addresses (linux/jhash.h)? */
40 22
41
42/* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b, 23/* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b,
43 * false otherwise. 24 * false otherwise.
44 */ 25 */
@@ -47,16 +28,16 @@ static bool seq_nr_after(u16 a, u16 b)
47 /* Remove inconsistency where 28 /* Remove inconsistency where
48 * seq_nr_after(a, b) == seq_nr_before(a, b) 29 * seq_nr_after(a, b) == seq_nr_before(a, b)
49 */ 30 */
50 if ((int) b - a == 32768) 31 if ((int)b - a == 32768)
51 return false; 32 return false;
52 33
53 return (((s16) (b - a)) < 0); 34 return (((s16)(b - a)) < 0);
54} 35}
36
55#define seq_nr_before(a, b) seq_nr_after((b), (a)) 37#define seq_nr_before(a, b) seq_nr_after((b), (a))
56#define seq_nr_after_or_eq(a, b) (!seq_nr_before((a), (b))) 38#define seq_nr_after_or_eq(a, b) (!seq_nr_before((a), (b)))
57#define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b))) 39#define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b)))
58 40
59
60bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr) 41bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr)
61{ 42{
62 struct hsr_node *node; 43 struct hsr_node *node;
@@ -68,9 +49,9 @@ bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr)
68 return false; 49 return false;
69 } 50 }
70 51
71 if (ether_addr_equal(addr, node->MacAddressA)) 52 if (ether_addr_equal(addr, node->macaddress_A))
72 return true; 53 return true;
73 if (ether_addr_equal(addr, node->MacAddressB)) 54 if (ether_addr_equal(addr, node->macaddress_B))
74 return true; 55 return true;
75 56
76 return false; 57 return false;
@@ -78,20 +59,19 @@ bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr)
78 59
79/* Search for mac entry. Caller must hold rcu read lock. 60/* Search for mac entry. Caller must hold rcu read lock.
80 */ 61 */
81static struct hsr_node *find_node_by_AddrA(struct list_head *node_db, 62static struct hsr_node *find_node_by_addr_A(struct list_head *node_db,
82 const unsigned char addr[ETH_ALEN]) 63 const unsigned char addr[ETH_ALEN])
83{ 64{
84 struct hsr_node *node; 65 struct hsr_node *node;
85 66
86 list_for_each_entry_rcu(node, node_db, mac_list) { 67 list_for_each_entry_rcu(node, node_db, mac_list) {
87 if (ether_addr_equal(node->MacAddressA, addr)) 68 if (ether_addr_equal(node->macaddress_A, addr))
88 return node; 69 return node;
89 } 70 }
90 71
91 return NULL; 72 return NULL;
92} 73}
93 74
94
95/* Helper for device init; the self_node_db is used in hsr_rcv() to recognize 75/* Helper for device init; the self_node_db is used in hsr_rcv() to recognize
96 * frames from self that's been looped over the HSR ring. 76 * frames from self that's been looped over the HSR ring.
97 */ 77 */
@@ -105,12 +85,12 @@ int hsr_create_self_node(struct list_head *self_node_db,
105 if (!node) 85 if (!node)
106 return -ENOMEM; 86 return -ENOMEM;
107 87
108 ether_addr_copy(node->MacAddressA, addr_a); 88 ether_addr_copy(node->macaddress_A, addr_a);
109 ether_addr_copy(node->MacAddressB, addr_b); 89 ether_addr_copy(node->macaddress_B, addr_b);
110 90
111 rcu_read_lock(); 91 rcu_read_lock();
112 oldnode = list_first_or_null_rcu(self_node_db, 92 oldnode = list_first_or_null_rcu(self_node_db,
113 struct hsr_node, mac_list); 93 struct hsr_node, mac_list);
114 if (oldnode) { 94 if (oldnode) {
115 list_replace_rcu(&oldnode->mac_list, &node->mac_list); 95 list_replace_rcu(&oldnode->mac_list, &node->mac_list);
116 rcu_read_unlock(); 96 rcu_read_unlock();
@@ -137,7 +117,7 @@ void hsr_del_node(struct list_head *self_node_db)
137 } 117 }
138} 118}
139 119
140/* Allocate an hsr_node and add it to node_db. 'addr' is the node's AddressA; 120/* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A;
141 * seq_out is used to initialize filtering of outgoing duplicate frames 121 * seq_out is used to initialize filtering of outgoing duplicate frames
142 * originating from the newly added node. 122 * originating from the newly added node.
143 */ 123 */
@@ -152,7 +132,7 @@ struct hsr_node *hsr_add_node(struct list_head *node_db, unsigned char addr[],
152 if (!node) 132 if (!node)
153 return NULL; 133 return NULL;
154 134
155 ether_addr_copy(node->MacAddressA, addr); 135 ether_addr_copy(node->macaddress_A, addr);
156 136
157 /* We are only interested in time diffs here, so use current jiffies 137 /* We are only interested in time diffs here, so use current jiffies
158 * as initialization. (0 could trigger an spurious ring error warning). 138 * as initialization. (0 could trigger an spurious ring error warning).
@@ -181,19 +161,19 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb,
181 if (!skb_mac_header_was_set(skb)) 161 if (!skb_mac_header_was_set(skb))
182 return NULL; 162 return NULL;
183 163
184 ethhdr = (struct ethhdr *) skb_mac_header(skb); 164 ethhdr = (struct ethhdr *)skb_mac_header(skb);
185 165
186 list_for_each_entry_rcu(node, node_db, mac_list) { 166 list_for_each_entry_rcu(node, node_db, mac_list) {
187 if (ether_addr_equal(node->MacAddressA, ethhdr->h_source)) 167 if (ether_addr_equal(node->macaddress_A, ethhdr->h_source))
188 return node; 168 return node;
189 if (ether_addr_equal(node->MacAddressB, ethhdr->h_source)) 169 if (ether_addr_equal(node->macaddress_B, ethhdr->h_source))
190 return node; 170 return node;
191 } 171 }
192 172
193 /* Everyone may create a node entry, connected node to a HSR device. */ 173 /* Everyone may create a node entry, connected node to a HSR device. */
194 174
195 if (ethhdr->h_proto == htons(ETH_P_PRP) 175 if (ethhdr->h_proto == htons(ETH_P_PRP) ||
196 || ethhdr->h_proto == htons(ETH_P_HSR)) { 176 ethhdr->h_proto == htons(ETH_P_HSR)) {
197 /* Use the existing sequence_nr from the tag as starting point 177 /* Use the existing sequence_nr from the tag as starting point
198 * for filtering duplicate frames. 178 * for filtering duplicate frames.
199 */ 179 */
@@ -210,8 +190,8 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb,
210 return hsr_add_node(node_db, ethhdr->h_source, seq_out); 190 return hsr_add_node(node_db, ethhdr->h_source, seq_out);
211} 191}
212 192
213/* Use the Supervision frame's info about an eventual MacAddressB for merging 193/* Use the Supervision frame's info about an eventual macaddress_B for merging
214 * nodes that has previously had their MacAddressB registered as a separate 194 * nodes that has previously had their macaddress_B registered as a separate
215 * node. 195 * node.
216 */ 196 */
217void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr, 197void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr,
@@ -223,7 +203,7 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr,
223 struct list_head *node_db; 203 struct list_head *node_db;
224 int i; 204 int i;
225 205
226 ethhdr = (struct ethhdr *) skb_mac_header(skb); 206 ethhdr = (struct ethhdr *)skb_mac_header(skb);
227 207
228 /* Leave the ethernet header. */ 208 /* Leave the ethernet header. */
229 skb_pull(skb, sizeof(struct ethhdr)); 209 skb_pull(skb, sizeof(struct ethhdr));
@@ -235,14 +215,14 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr,
235 /* And leave the HSR sup tag. */ 215 /* And leave the HSR sup tag. */
236 skb_pull(skb, sizeof(struct hsr_sup_tag)); 216 skb_pull(skb, sizeof(struct hsr_sup_tag));
237 217
238 hsr_sp = (struct hsr_sup_payload *) skb->data; 218 hsr_sp = (struct hsr_sup_payload *)skb->data;
239 219
240 /* Merge node_curr (registered on MacAddressB) into node_real */ 220 /* Merge node_curr (registered on macaddress_B) into node_real */
241 node_db = &port_rcv->hsr->node_db; 221 node_db = &port_rcv->hsr->node_db;
242 node_real = find_node_by_AddrA(node_db, hsr_sp->MacAddressA); 222 node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A);
243 if (!node_real) 223 if (!node_real)
244 /* No frame received from AddrA of this node yet */ 224 /* No frame received from AddrA of this node yet */
245 node_real = hsr_add_node(node_db, hsr_sp->MacAddressA, 225 node_real = hsr_add_node(node_db, hsr_sp->macaddress_A,
246 HSR_SEQNR_START - 1); 226 HSR_SEQNR_START - 1);
247 if (!node_real) 227 if (!node_real)
248 goto done; /* No mem */ 228 goto done; /* No mem */
@@ -250,17 +230,18 @@ void hsr_handle_sup_frame(struct sk_buff *skb, struct hsr_node *node_curr,
250 /* Node has already been merged */ 230 /* Node has already been merged */
251 goto done; 231 goto done;
252 232
253 ether_addr_copy(node_real->MacAddressB, ethhdr->h_source); 233 ether_addr_copy(node_real->macaddress_B, ethhdr->h_source);
254 for (i = 0; i < HSR_PT_PORTS; i++) { 234 for (i = 0; i < HSR_PT_PORTS; i++) {
255 if (!node_curr->time_in_stale[i] && 235 if (!node_curr->time_in_stale[i] &&
256 time_after(node_curr->time_in[i], node_real->time_in[i])) { 236 time_after(node_curr->time_in[i], node_real->time_in[i])) {
257 node_real->time_in[i] = node_curr->time_in[i]; 237 node_real->time_in[i] = node_curr->time_in[i];
258 node_real->time_in_stale[i] = node_curr->time_in_stale[i]; 238 node_real->time_in_stale[i] =
239 node_curr->time_in_stale[i];
259 } 240 }
260 if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i])) 241 if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i]))
261 node_real->seq_out[i] = node_curr->seq_out[i]; 242 node_real->seq_out[i] = node_curr->seq_out[i];
262 } 243 }
263 node_real->AddrB_port = port_rcv->type; 244 node_real->addr_B_port = port_rcv->type;
264 245
265 list_del_rcu(&node_curr->mac_list); 246 list_del_rcu(&node_curr->mac_list);
266 kfree_rcu(node_curr, rcu_head); 247 kfree_rcu(node_curr, rcu_head);
@@ -269,11 +250,10 @@ done:
269 skb_push(skb, sizeof(struct hsrv1_ethhdr_sp)); 250 skb_push(skb, sizeof(struct hsrv1_ethhdr_sp));
270} 251}
271 252
272
273/* 'skb' is a frame meant for this host, that is to be passed to upper layers. 253/* 'skb' is a frame meant for this host, that is to be passed to upper layers.
274 * 254 *
275 * If the frame was sent by a node's B interface, replace the source 255 * If the frame was sent by a node's B interface, replace the source
276 * address with that node's "official" address (MacAddressA) so that upper 256 * address with that node's "official" address (macaddress_A) so that upper
277 * layers recognize where it came from. 257 * layers recognize where it came from.
278 */ 258 */
279void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb) 259void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb)
@@ -283,7 +263,7 @@ void hsr_addr_subst_source(struct hsr_node *node, struct sk_buff *skb)
283 return; 263 return;
284 } 264 }
285 265
286 memcpy(&eth_hdr(skb)->h_source, node->MacAddressA, ETH_ALEN); 266 memcpy(&eth_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN);
287} 267}
288 268
289/* 'skb' is a frame meant for another host. 269/* 'skb' is a frame meant for another host.
@@ -308,18 +288,18 @@ void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,
308 if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest)) 288 if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest))
309 return; 289 return;
310 290
311 node_dst = find_node_by_AddrA(&port->hsr->node_db, eth_hdr(skb)->h_dest); 291 node_dst = find_node_by_addr_A(&port->hsr->node_db,
292 eth_hdr(skb)->h_dest);
312 if (!node_dst) { 293 if (!node_dst) {
313 WARN_ONCE(1, "%s: Unknown node\n", __func__); 294 WARN_ONCE(1, "%s: Unknown node\n", __func__);
314 return; 295 return;
315 } 296 }
316 if (port->type != node_dst->AddrB_port) 297 if (port->type != node_dst->addr_B_port)
317 return; 298 return;
318 299
319 ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->MacAddressB); 300 ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B);
320} 301}
321 302
322
323void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port, 303void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,
324 u16 sequence_nr) 304 u16 sequence_nr)
325{ 305{
@@ -352,7 +332,6 @@ int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node,
352 return 0; 332 return 0;
353} 333}
354 334
355
356static struct hsr_port *get_late_port(struct hsr_priv *hsr, 335static struct hsr_port *get_late_port(struct hsr_priv *hsr,
357 struct hsr_node *node) 336 struct hsr_node *node)
358{ 337{
@@ -373,7 +352,6 @@ static struct hsr_port *get_late_port(struct hsr_priv *hsr,
373 return NULL; 352 return NULL;
374} 353}
375 354
376
377/* Remove stale sequence_nr records. Called by timer every 355/* Remove stale sequence_nr records. Called by timer every
378 * HSR_LIFE_CHECK_INTERVAL (two seconds or so). 356 * HSR_LIFE_CHECK_INTERVAL (two seconds or so).
379 */ 357 */
@@ -392,9 +370,9 @@ void hsr_prune_nodes(struct timer_list *t)
392 time_b = node->time_in[HSR_PT_SLAVE_B]; 370 time_b = node->time_in[HSR_PT_SLAVE_B];
393 371
394 /* Check for timestamps old enough to risk wrap-around */ 372 /* Check for timestamps old enough to risk wrap-around */
395 if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET/2)) 373 if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET / 2))
396 node->time_in_stale[HSR_PT_SLAVE_A] = true; 374 node->time_in_stale[HSR_PT_SLAVE_A] = true;
397 if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET/2)) 375 if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET / 2))
398 node->time_in_stale[HSR_PT_SLAVE_B] = true; 376 node->time_in_stale[HSR_PT_SLAVE_B] = true;
399 377
400 /* Get age of newest frame from node. 378 /* Get age of newest frame from node.
@@ -409,26 +387,29 @@ void hsr_prune_nodes(struct timer_list *t)
409 387
410 /* Warn of ring error only as long as we get frames at all */ 388 /* Warn of ring error only as long as we get frames at all */
411 if (time_is_after_jiffies(timestamp + 389 if (time_is_after_jiffies(timestamp +
412 msecs_to_jiffies(1.5*MAX_SLAVE_DIFF))) { 390 msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) {
413 rcu_read_lock(); 391 rcu_read_lock();
414 port = get_late_port(hsr, node); 392 port = get_late_port(hsr, node);
415 if (port != NULL) 393 if (port)
416 hsr_nl_ringerror(hsr, node->MacAddressA, port); 394 hsr_nl_ringerror(hsr, node->macaddress_A, port);
417 rcu_read_unlock(); 395 rcu_read_unlock();
418 } 396 }
419 397
420 /* Prune old entries */ 398 /* Prune old entries */
421 if (time_is_before_jiffies(timestamp + 399 if (time_is_before_jiffies(timestamp +
422 msecs_to_jiffies(HSR_NODE_FORGET_TIME))) { 400 msecs_to_jiffies(HSR_NODE_FORGET_TIME))) {
423 hsr_nl_nodedown(hsr, node->MacAddressA); 401 hsr_nl_nodedown(hsr, node->macaddress_A);
424 list_del_rcu(&node->mac_list); 402 list_del_rcu(&node->mac_list);
425 /* Note that we need to free this entry later: */ 403 /* Note that we need to free this entry later: */
426 kfree_rcu(node, rcu_head); 404 kfree_rcu(node, rcu_head);
427 } 405 }
428 } 406 }
429 rcu_read_unlock(); 407 rcu_read_unlock();
430}
431 408
409 /* Restart timer */
410 mod_timer(&hsr->prune_timer,
411 jiffies + msecs_to_jiffies(PRUNE_PERIOD));
412}
432 413
433void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos, 414void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
434 unsigned char addr[ETH_ALEN]) 415 unsigned char addr[ETH_ALEN])
@@ -439,20 +420,19 @@ void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
439 node = list_first_or_null_rcu(&hsr->node_db, 420 node = list_first_or_null_rcu(&hsr->node_db,
440 struct hsr_node, mac_list); 421 struct hsr_node, mac_list);
441 if (node) 422 if (node)
442 ether_addr_copy(addr, node->MacAddressA); 423 ether_addr_copy(addr, node->macaddress_A);
443 return node; 424 return node;
444 } 425 }
445 426
446 node = _pos; 427 node = _pos;
447 list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) { 428 list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) {
448 ether_addr_copy(addr, node->MacAddressA); 429 ether_addr_copy(addr, node->macaddress_A);
449 return node; 430 return node;
450 } 431 }
451 432
452 return NULL; 433 return NULL;
453} 434}
454 435
455
456int hsr_get_node_data(struct hsr_priv *hsr, 436int hsr_get_node_data(struct hsr_priv *hsr,
457 const unsigned char *addr, 437 const unsigned char *addr,
458 unsigned char addr_b[ETH_ALEN], 438 unsigned char addr_b[ETH_ALEN],
@@ -466,15 +446,14 @@ int hsr_get_node_data(struct hsr_priv *hsr,
466 struct hsr_port *port; 446 struct hsr_port *port;
467 unsigned long tdiff; 447 unsigned long tdiff;
468 448
469
470 rcu_read_lock(); 449 rcu_read_lock();
471 node = find_node_by_AddrA(&hsr->node_db, addr); 450 node = find_node_by_addr_A(&hsr->node_db, addr);
472 if (!node) { 451 if (!node) {
473 rcu_read_unlock(); 452 rcu_read_unlock();
474 return -ENOENT; /* No such entry */ 453 return -ENOENT; /* No such entry */
475 } 454 }
476 455
477 ether_addr_copy(addr_b, node->MacAddressB); 456 ether_addr_copy(addr_b, node->macaddress_B);
478 457
479 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A]; 458 tdiff = jiffies - node->time_in[HSR_PT_SLAVE_A];
480 if (node->time_in_stale[HSR_PT_SLAVE_A]) 459 if (node->time_in_stale[HSR_PT_SLAVE_A])
@@ -500,8 +479,8 @@ int hsr_get_node_data(struct hsr_priv *hsr,
500 *if1_seq = node->seq_out[HSR_PT_SLAVE_B]; 479 *if1_seq = node->seq_out[HSR_PT_SLAVE_B];
501 *if2_seq = node->seq_out[HSR_PT_SLAVE_A]; 480 *if2_seq = node->seq_out[HSR_PT_SLAVE_A];
502 481
503 if (node->AddrB_port != HSR_PT_NONE) { 482 if (node->addr_B_port != HSR_PT_NONE) {
504 port = hsr_port_get_hsr(hsr, node->AddrB_port); 483 port = hsr_port_get_hsr(hsr, node->addr_B_port);
505 *addr_b_ifindex = port->dev->ifindex; 484 *addr_b_ifindex = port->dev->ifindex;
506 } else { 485 } else {
507 *addr_b_ifindex = -1; 486 *addr_b_ifindex = -1;
diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
index 531fd3dfcac1..a3bdcdab469d 100644
--- a/net/hsr/hsr_framereg.h
+++ b/net/hsr/hsr_framereg.h
@@ -1,10 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 6 */
@@ -52,4 +48,16 @@ int hsr_get_node_data(struct hsr_priv *hsr,
52 int *if2_age, 48 int *if2_age,
53 u16 *if2_seq); 49 u16 *if2_seq);
54 50
51struct hsr_node {
52 struct list_head mac_list;
53 unsigned char macaddress_A[ETH_ALEN];
54 unsigned char macaddress_B[ETH_ALEN];
55 /* Local slave through which AddrB frames are received from this node */
56 enum hsr_port_type addr_B_port;
57 unsigned long time_in[HSR_PT_PORTS];
58 bool time_in_stale[HSR_PT_PORTS];
59 u16 seq_out[HSR_PT_PORTS];
60 struct rcu_head rcu_head;
61};
62
55#endif /* __HSR_FRAMEREG_H */ 63#endif /* __HSR_FRAMEREG_H */
diff --git a/net/hsr/hsr_main.c b/net/hsr/hsr_main.c
index cd37d0011b42..b9988a662ee1 100644
--- a/net/hsr/hsr_main.c
+++ b/net/hsr/hsr_main.c
@@ -1,10 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 6 */
@@ -19,7 +15,6 @@
19#include "hsr_framereg.h" 15#include "hsr_framereg.h"
20#include "hsr_slave.h" 16#include "hsr_slave.h"
21 17
22
23static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event, 18static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
24 void *ptr) 19 void *ptr)
25{ 20{
@@ -31,12 +26,12 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
31 26
32 dev = netdev_notifier_info_to_dev(ptr); 27 dev = netdev_notifier_info_to_dev(ptr);
33 port = hsr_port_get_rtnl(dev); 28 port = hsr_port_get_rtnl(dev);
34 if (port == NULL) { 29 if (!port) {
35 if (!is_hsr_master(dev)) 30 if (!is_hsr_master(dev))
36 return NOTIFY_DONE; /* Not an HSR device */ 31 return NOTIFY_DONE; /* Not an HSR device */
37 hsr = netdev_priv(dev); 32 hsr = netdev_priv(dev);
38 port = hsr_port_get_hsr(hsr, HSR_PT_MASTER); 33 port = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
39 if (port == NULL) { 34 if (!port) {
40 /* Resend of notification concerning removed device? */ 35 /* Resend of notification concerning removed device? */
41 return NOTIFY_DONE; 36 return NOTIFY_DONE;
42 } 37 }
@@ -63,7 +58,8 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
63 58
64 if (port->type == HSR_PT_SLAVE_A) { 59 if (port->type == HSR_PT_SLAVE_A) {
65 ether_addr_copy(master->dev->dev_addr, dev->dev_addr); 60 ether_addr_copy(master->dev->dev_addr, dev->dev_addr);
66 call_netdevice_notifiers(NETDEV_CHANGEADDR, master->dev); 61 call_netdevice_notifiers(NETDEV_CHANGEADDR,
62 master->dev);
67 } 63 }
68 64
69 /* Make sure we recognize frames from ourselves in hsr_rcv() */ 65 /* Make sure we recognize frames from ourselves in hsr_rcv() */
@@ -97,7 +93,6 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
97 return NOTIFY_DONE; 93 return NOTIFY_DONE;
98} 94}
99 95
100
101struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt) 96struct hsr_port *hsr_port_get_hsr(struct hsr_priv *hsr, enum hsr_port_type pt)
102{ 97{
103 struct hsr_port *port; 98 struct hsr_port *port;
@@ -112,7 +107,6 @@ static struct notifier_block hsr_nb = {
112 .notifier_call = hsr_netdev_notify, /* Slave event notifications */ 107 .notifier_call = hsr_netdev_notify, /* Slave event notifications */
113}; 108};
114 109
115
116static int __init hsr_init(void) 110static int __init hsr_init(void)
117{ 111{
118 int res; 112 int res;
diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h
index 9b9909e89e9e..96fac696a1e1 100644
--- a/net/hsr/hsr_main.h
+++ b/net/hsr/hsr_main.h
@@ -1,10 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 6 */
@@ -15,7 +11,6 @@
15#include <linux/netdevice.h> 11#include <linux/netdevice.h>
16#include <linux/list.h> 12#include <linux/list.h>
17 13
18
19/* Time constants as specified in the HSR specification (IEC-62439-3 2010) 14/* Time constants as specified in the HSR specification (IEC-62439-3 2010)
20 * Table 8. 15 * Table 8.
21 * All values in milliseconds. 16 * All values in milliseconds.
@@ -24,7 +19,6 @@
24#define HSR_NODE_FORGET_TIME 60000 /* ms */ 19#define HSR_NODE_FORGET_TIME 60000 /* ms */
25#define HSR_ANNOUNCE_INTERVAL 100 /* ms */ 20#define HSR_ANNOUNCE_INTERVAL 100 /* ms */
26 21
27
28/* By how much may slave1 and slave2 timestamps of latest received frame from 22/* By how much may slave1 and slave2 timestamps of latest received frame from
29 * each node differ before we notify of communication problem? 23 * each node differ before we notify of communication problem?
30 */ 24 */
@@ -32,17 +26,14 @@
32#define HSR_SEQNR_START (USHRT_MAX - 1024) 26#define HSR_SEQNR_START (USHRT_MAX - 1024)
33#define HSR_SUP_SEQNR_START (HSR_SEQNR_START / 2) 27#define HSR_SUP_SEQNR_START (HSR_SEQNR_START / 2)
34 28
35
36/* How often shall we check for broken ring and remove node entries older than 29/* How often shall we check for broken ring and remove node entries older than
37 * HSR_NODE_FORGET_TIME? 30 * HSR_NODE_FORGET_TIME?
38 */ 31 */
39#define PRUNE_PERIOD 3000 /* ms */ 32#define PRUNE_PERIOD 3000 /* ms */
40 33
41
42#define HSR_TLV_ANNOUNCE 22 34#define HSR_TLV_ANNOUNCE 22
43#define HSR_TLV_LIFE_CHECK 23 35#define HSR_TLV_LIFE_CHECK 23
44 36
45
46/* HSR Tag. 37/* HSR Tag.
47 * As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB, 38 * As defined in IEC-62439-3:2010, the HSR tag is really { ethertype = 0x88FB,
48 * path, LSDU_size, sequence Nr }. But we let eth_header() create { h_dest, 39 * path, LSDU_size, sequence Nr }. But we let eth_header() create { h_dest,
@@ -83,15 +74,14 @@ static inline u16 get_hsr_tag_LSDU_size(struct hsr_tag *ht)
83 74
84static inline void set_hsr_tag_path(struct hsr_tag *ht, u16 path) 75static inline void set_hsr_tag_path(struct hsr_tag *ht, u16 path)
85{ 76{
86 ht->path_and_LSDU_size = htons( 77 ht->path_and_LSDU_size =
87 (ntohs(ht->path_and_LSDU_size) & 0x0FFF) | (path << 12)); 78 htons((ntohs(ht->path_and_LSDU_size) & 0x0FFF) | (path << 12));
88} 79}
89 80
90static inline void set_hsr_tag_LSDU_size(struct hsr_tag *ht, u16 LSDU_size) 81static inline void set_hsr_tag_LSDU_size(struct hsr_tag *ht, u16 LSDU_size)
91{ 82{
92 ht->path_and_LSDU_size = htons( 83 ht->path_and_LSDU_size = htons((ntohs(ht->path_and_LSDU_size) &
93 (ntohs(ht->path_and_LSDU_size) & 0xF000) | 84 0xF000) | (LSDU_size & 0x0FFF));
94 (LSDU_size & 0x0FFF));
95} 85}
96 86
97struct hsr_ethhdr { 87struct hsr_ethhdr {
@@ -99,39 +89,38 @@ struct hsr_ethhdr {
99 struct hsr_tag hsr_tag; 89 struct hsr_tag hsr_tag;
100} __packed; 90} __packed;
101 91
102
103/* HSR Supervision Frame data types. 92/* HSR Supervision Frame data types.
104 * Field names as defined in the IEC:2010 standard for HSR. 93 * Field names as defined in the IEC:2010 standard for HSR.
105 */ 94 */
106struct hsr_sup_tag { 95struct hsr_sup_tag {
107 __be16 path_and_HSR_Ver; 96 __be16 path_and_HSR_ver;
108 __be16 sequence_nr; 97 __be16 sequence_nr;
109 __u8 HSR_TLV_Type; 98 __u8 HSR_TLV_type;
110 __u8 HSR_TLV_Length; 99 __u8 HSR_TLV_length;
111} __packed; 100} __packed;
112 101
113struct hsr_sup_payload { 102struct hsr_sup_payload {
114 unsigned char MacAddressA[ETH_ALEN]; 103 unsigned char macaddress_A[ETH_ALEN];
115} __packed; 104} __packed;
116 105
117static inline u16 get_hsr_stag_path(struct hsr_sup_tag *hst) 106static inline u16 get_hsr_stag_path(struct hsr_sup_tag *hst)
118{ 107{
119 return get_hsr_tag_path((struct hsr_tag *) hst); 108 return get_hsr_tag_path((struct hsr_tag *)hst);
120} 109}
121 110
122static inline u16 get_hsr_stag_HSR_ver(struct hsr_sup_tag *hst) 111static inline u16 get_hsr_stag_HSR_ver(struct hsr_sup_tag *hst)
123{ 112{
124 return get_hsr_tag_LSDU_size((struct hsr_tag *) hst); 113 return get_hsr_tag_LSDU_size((struct hsr_tag *)hst);
125} 114}
126 115
127static inline void set_hsr_stag_path(struct hsr_sup_tag *hst, u16 path) 116static inline void set_hsr_stag_path(struct hsr_sup_tag *hst, u16 path)
128{ 117{
129 set_hsr_tag_path((struct hsr_tag *) hst, path); 118 set_hsr_tag_path((struct hsr_tag *)hst, path);
130} 119}
131 120
132static inline void set_hsr_stag_HSR_Ver(struct hsr_sup_tag *hst, u16 HSR_Ver) 121static inline void set_hsr_stag_HSR_ver(struct hsr_sup_tag *hst, u16 HSR_ver)
133{ 122{
134 set_hsr_tag_LSDU_size((struct hsr_tag *) hst, HSR_Ver); 123 set_hsr_tag_LSDU_size((struct hsr_tag *)hst, HSR_ver);
135} 124}
136 125
137struct hsrv0_ethhdr_sp { 126struct hsrv0_ethhdr_sp {
@@ -145,7 +134,6 @@ struct hsrv1_ethhdr_sp {
145 struct hsr_sup_tag hsr_sup; 134 struct hsr_sup_tag hsr_sup;
146} __packed; 135} __packed;
147 136
148
149enum hsr_port_type { 137enum hsr_port_type {
150 HSR_PT_NONE = 0, /* Must be 0, used by framereg */ 138 HSR_PT_NONE = 0, /* Must be 0, used by framereg */
151 HSR_PT_SLAVE_A, 139 HSR_PT_SLAVE_A,
@@ -171,10 +159,14 @@ struct hsr_priv {
171 struct timer_list prune_timer; 159 struct timer_list prune_timer;
172 int announce_count; 160 int announce_count;
173 u16 sequence_nr; 161 u16 sequence_nr;
174 u16 sup_sequence_nr; /* For HSRv1 separate seq_nr for supervision */ 162 u16 sup_sequence_nr; /* For HSRv1 separate seq_nr for supervision */
175 u8 protVersion; /* Indicate if HSRv0 or HSRv1. */ 163 u8 prot_version; /* Indicate if HSRv0 or HSRv1. */
176 spinlock_t seqnr_lock; /* locking for sequence_nr */ 164 spinlock_t seqnr_lock; /* locking for sequence_nr */
177 unsigned char sup_multicast_addr[ETH_ALEN]; 165 unsigned char sup_multicast_addr[ETH_ALEN];
166#ifdef CONFIG_DEBUG_FS
167 struct dentry *node_tbl_root;
168 struct dentry *node_tbl_file;
169#endif
178}; 170};
179 171
180#define hsr_for_each_port(hsr, port) \ 172#define hsr_for_each_port(hsr, port) \
@@ -187,8 +179,22 @@ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb)
187{ 179{
188 struct hsr_ethhdr *hsr_ethhdr; 180 struct hsr_ethhdr *hsr_ethhdr;
189 181
190 hsr_ethhdr = (struct hsr_ethhdr *) skb_mac_header(skb); 182 hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
191 return ntohs(hsr_ethhdr->hsr_tag.sequence_nr); 183 return ntohs(hsr_ethhdr->hsr_tag.sequence_nr);
192} 184}
193 185
186#if IS_ENABLED(CONFIG_DEBUG_FS)
187int hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev);
188void hsr_debugfs_term(struct hsr_priv *priv);
189#else
190static inline int hsr_debugfs_init(struct hsr_priv *priv,
191 struct net_device *hsr_dev)
192{
193 return 0;
194}
195
196static inline void hsr_debugfs_term(struct hsr_priv *priv)
197{}
198#endif
199
194#endif /* __HSR_PRIVATE_H */ 200#endif /* __HSR_PRIVATE_H */
diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
index b9cce0fd5696..8f8337f893ba 100644
--- a/net/hsr/hsr_netlink.c
+++ b/net/hsr/hsr_netlink.c
@@ -1,10 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 * 6 *
@@ -28,7 +24,6 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = {
28 [IFLA_HSR_SEQ_NR] = { .type = NLA_U16 }, 24 [IFLA_HSR_SEQ_NR] = { .type = NLA_U16 },
29}; 25};
30 26
31
32/* Here, it seems a netdevice has already been allocated for us, and the 27/* Here, it seems a netdevice has already been allocated for us, and the
33 * hsr_dev_setup routine has been executed. Nice! 28 * hsr_dev_setup routine has been executed. Nice!
34 */ 29 */
@@ -47,12 +42,14 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
47 netdev_info(dev, "HSR: Slave1 device not specified\n"); 42 netdev_info(dev, "HSR: Slave1 device not specified\n");
48 return -EINVAL; 43 return -EINVAL;
49 } 44 }
50 link[0] = __dev_get_by_index(src_net, nla_get_u32(data[IFLA_HSR_SLAVE1])); 45 link[0] = __dev_get_by_index(src_net,
46 nla_get_u32(data[IFLA_HSR_SLAVE1]));
51 if (!data[IFLA_HSR_SLAVE2]) { 47 if (!data[IFLA_HSR_SLAVE2]) {
52 netdev_info(dev, "HSR: Slave2 device not specified\n"); 48 netdev_info(dev, "HSR: Slave2 device not specified\n");
53 return -EINVAL; 49 return -EINVAL;
54 } 50 }
55 link[1] = __dev_get_by_index(src_net, nla_get_u32(data[IFLA_HSR_SLAVE2])); 51 link[1] = __dev_get_by_index(src_net,
52 nla_get_u32(data[IFLA_HSR_SLAVE2]));
56 53
57 if (!link[0] || !link[1]) 54 if (!link[0] || !link[1])
58 return -ENODEV; 55 return -ENODEV;
@@ -119,8 +116,6 @@ static struct rtnl_link_ops hsr_link_ops __read_mostly = {
119 .fill_info = hsr_fill_info, 116 .fill_info = hsr_fill_info,
120}; 117};
121 118
122
123
124/* attribute policy */ 119/* attribute policy */
125static const struct nla_policy hsr_genl_policy[HSR_A_MAX + 1] = { 120static const struct nla_policy hsr_genl_policy[HSR_A_MAX + 1] = {
126 [HSR_A_NODE_ADDR] = { .len = ETH_ALEN }, 121 [HSR_A_NODE_ADDR] = { .len = ETH_ALEN },
@@ -138,8 +133,6 @@ static const struct genl_multicast_group hsr_mcgrps[] = {
138 { .name = "hsr-network", }, 133 { .name = "hsr-network", },
139}; 134};
140 135
141
142
143/* This is called if for some node with MAC address addr, we only get frames 136/* This is called if for some node with MAC address addr, we only get frames
144 * over one of the slave interfaces. This would indicate an open network ring 137 * over one of the slave interfaces. This would indicate an open network ring
145 * (i.e. a link has failed somewhere). 138 * (i.e. a link has failed somewhere).
@@ -156,7 +149,8 @@ void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN],
156 if (!skb) 149 if (!skb)
157 goto fail; 150 goto fail;
158 151
159 msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0, HSR_C_RING_ERROR); 152 msg_head = genlmsg_put(skb, 0, 0, &hsr_genl_family, 0,
153 HSR_C_RING_ERROR);
160 if (!msg_head) 154 if (!msg_head)
161 goto nla_put_failure; 155 goto nla_put_failure;
162 156
@@ -201,7 +195,6 @@ void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN])
201 if (!msg_head) 195 if (!msg_head)
202 goto nla_put_failure; 196 goto nla_put_failure;
203 197
204
205 res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr); 198 res = nla_put(skb, HSR_A_NODE_ADDR, ETH_ALEN, addr);
206 if (res < 0) 199 if (res < 0)
207 goto nla_put_failure; 200 goto nla_put_failure;
@@ -221,7 +214,6 @@ fail:
221 rcu_read_unlock(); 214 rcu_read_unlock();
222} 215}
223 216
224
225/* HSR_C_GET_NODE_STATUS lets userspace query the internal HSR node table 217/* HSR_C_GET_NODE_STATUS lets userspace query the internal HSR node table
226 * about the status of a specific node in the network, defined by its MAC 218 * about the status of a specific node in the network, defined by its MAC
227 * address. 219 * address.
@@ -260,15 +252,13 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
260 goto invalid; 252 goto invalid;
261 253
262 hsr_dev = __dev_get_by_index(genl_info_net(info), 254 hsr_dev = __dev_get_by_index(genl_info_net(info),
263 nla_get_u32(info->attrs[HSR_A_IFINDEX])); 255 nla_get_u32(info->attrs[HSR_A_IFINDEX]));
264 if (!hsr_dev) 256 if (!hsr_dev)
265 goto invalid; 257 goto invalid;
266 if (!is_hsr_master(hsr_dev)) 258 if (!is_hsr_master(hsr_dev))
267 goto invalid; 259 goto invalid;
268 260
269
270 /* Send reply */ 261 /* Send reply */
271
272 skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); 262 skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
273 if (!skb_out) { 263 if (!skb_out) {
274 res = -ENOMEM; 264 res = -ENOMEM;
@@ -276,8 +266,8 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
276 } 266 }
277 267
278 msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid, 268 msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
279 info->snd_seq, &hsr_genl_family, 0, 269 info->snd_seq, &hsr_genl_family, 0,
280 HSR_C_SET_NODE_STATUS); 270 HSR_C_SET_NODE_STATUS);
281 if (!msg_head) { 271 if (!msg_head) {
282 res = -ENOMEM; 272 res = -ENOMEM;
283 goto nla_put_failure; 273 goto nla_put_failure;
@@ -289,28 +279,30 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
289 279
290 hsr = netdev_priv(hsr_dev); 280 hsr = netdev_priv(hsr_dev);
291 res = hsr_get_node_data(hsr, 281 res = hsr_get_node_data(hsr,
292 (unsigned char *) nla_data(info->attrs[HSR_A_NODE_ADDR]), 282 (unsigned char *)
293 hsr_node_addr_b, 283 nla_data(info->attrs[HSR_A_NODE_ADDR]),
294 &addr_b_ifindex, 284 hsr_node_addr_b,
295 &hsr_node_if1_age, 285 &addr_b_ifindex,
296 &hsr_node_if1_seq, 286 &hsr_node_if1_age,
297 &hsr_node_if2_age, 287 &hsr_node_if1_seq,
298 &hsr_node_if2_seq); 288 &hsr_node_if2_age,
289 &hsr_node_if2_seq);
299 if (res < 0) 290 if (res < 0)
300 goto nla_put_failure; 291 goto nla_put_failure;
301 292
302 res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, 293 res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN,
303 nla_data(info->attrs[HSR_A_NODE_ADDR])); 294 nla_data(info->attrs[HSR_A_NODE_ADDR]));
304 if (res < 0) 295 if (res < 0)
305 goto nla_put_failure; 296 goto nla_put_failure;
306 297
307 if (addr_b_ifindex > -1) { 298 if (addr_b_ifindex > -1) {
308 res = nla_put(skb_out, HSR_A_NODE_ADDR_B, ETH_ALEN, 299 res = nla_put(skb_out, HSR_A_NODE_ADDR_B, ETH_ALEN,
309 hsr_node_addr_b); 300 hsr_node_addr_b);
310 if (res < 0) 301 if (res < 0)
311 goto nla_put_failure; 302 goto nla_put_failure;
312 303
313 res = nla_put_u32(skb_out, HSR_A_ADDR_B_IFINDEX, addr_b_ifindex); 304 res = nla_put_u32(skb_out, HSR_A_ADDR_B_IFINDEX,
305 addr_b_ifindex);
314 if (res < 0) 306 if (res < 0)
315 goto nla_put_failure; 307 goto nla_put_failure;
316 } 308 }
@@ -392,9 +384,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
392 if (!is_hsr_master(hsr_dev)) 384 if (!is_hsr_master(hsr_dev))
393 goto invalid; 385 goto invalid;
394 386
395
396 /* Send reply */ 387 /* Send reply */
397
398 skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); 388 skb_out = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
399 if (!skb_out) { 389 if (!skb_out) {
400 res = -ENOMEM; 390 res = -ENOMEM;
@@ -402,8 +392,8 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
402 } 392 }
403 393
404 msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid, 394 msg_head = genlmsg_put(skb_out, NETLINK_CB(skb_in).portid,
405 info->snd_seq, &hsr_genl_family, 0, 395 info->snd_seq, &hsr_genl_family, 0,
406 HSR_C_SET_NODE_LIST); 396 HSR_C_SET_NODE_LIST);
407 if (!msg_head) { 397 if (!msg_head) {
408 res = -ENOMEM; 398 res = -ENOMEM;
409 goto nla_put_failure; 399 goto nla_put_failure;
@@ -444,19 +434,18 @@ fail:
444 return res; 434 return res;
445} 435}
446 436
447
448static const struct genl_ops hsr_ops[] = { 437static const struct genl_ops hsr_ops[] = {
449 { 438 {
450 .cmd = HSR_C_GET_NODE_STATUS, 439 .cmd = HSR_C_GET_NODE_STATUS,
440 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
451 .flags = 0, 441 .flags = 0,
452 .policy = hsr_genl_policy,
453 .doit = hsr_get_node_status, 442 .doit = hsr_get_node_status,
454 .dumpit = NULL, 443 .dumpit = NULL,
455 }, 444 },
456 { 445 {
457 .cmd = HSR_C_GET_NODE_LIST, 446 .cmd = HSR_C_GET_NODE_LIST,
447 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
458 .flags = 0, 448 .flags = 0,
459 .policy = hsr_genl_policy,
460 .doit = hsr_get_node_list, 449 .doit = hsr_get_node_list,
461 .dumpit = NULL, 450 .dumpit = NULL,
462 }, 451 },
@@ -467,6 +456,7 @@ static struct genl_family hsr_genl_family __ro_after_init = {
467 .name = "HSR", 456 .name = "HSR",
468 .version = 1, 457 .version = 1,
469 .maxattr = HSR_A_MAX, 458 .maxattr = HSR_A_MAX,
459 .policy = hsr_genl_policy,
470 .module = THIS_MODULE, 460 .module = THIS_MODULE,
471 .ops = hsr_ops, 461 .ops = hsr_ops,
472 .n_ops = ARRAY_SIZE(hsr_ops), 462 .n_ops = ARRAY_SIZE(hsr_ops),
diff --git a/net/hsr/hsr_netlink.h b/net/hsr/hsr_netlink.h
index 3f6b95b5b6b8..1121bb192a18 100644
--- a/net/hsr/hsr_netlink.h
+++ b/net/hsr/hsr_netlink.h
@@ -1,10 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 6 */
diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
index 56080da4aa77..88b6705ded83 100644
--- a/net/hsr/hsr_slave.c
+++ b/net/hsr/hsr_slave.c
@@ -1,10 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s): 4 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 5 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 6 */
@@ -18,7 +14,6 @@
18#include "hsr_forward.h" 14#include "hsr_forward.h"
19#include "hsr_framereg.h" 15#include "hsr_framereg.h"
20 16
21
22static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb) 17static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
23{ 18{
24 struct sk_buff *skb = *pskb; 19 struct sk_buff *skb = *pskb;
@@ -61,12 +56,11 @@ bool hsr_port_exists(const struct net_device *dev)
61 return rcu_access_pointer(dev->rx_handler) == hsr_handle_frame; 56 return rcu_access_pointer(dev->rx_handler) == hsr_handle_frame;
62} 57}
63 58
64
65static int hsr_check_dev_ok(struct net_device *dev) 59static int hsr_check_dev_ok(struct net_device *dev)
66{ 60{
67 /* Don't allow HSR on non-ethernet like devices */ 61 /* Don't allow HSR on non-ethernet like devices */
68 if ((dev->flags & IFF_LOOPBACK) || (dev->type != ARPHRD_ETHER) || 62 if ((dev->flags & IFF_LOOPBACK) || dev->type != ARPHRD_ETHER ||
69 (dev->addr_len != ETH_ALEN)) { 63 dev->addr_len != ETH_ALEN) {
70 netdev_info(dev, "Cannot use loopback or non-ethernet device as HSR slave.\n"); 64 netdev_info(dev, "Cannot use loopback or non-ethernet device as HSR slave.\n");
71 return -EINVAL; 65 return -EINVAL;
72 } 66 }
@@ -99,7 +93,6 @@ static int hsr_check_dev_ok(struct net_device *dev)
99 return 0; 93 return 0;
100} 94}
101 95
102
103/* Setup device to be added to the HSR bridge. */ 96/* Setup device to be added to the HSR bridge. */
104static int hsr_portdev_setup(struct net_device *dev, struct hsr_port *port) 97static int hsr_portdev_setup(struct net_device *dev, struct hsr_port *port)
105{ 98{
@@ -143,11 +136,11 @@ int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
143 } 136 }
144 137
145 port = hsr_port_get_hsr(hsr, type); 138 port = hsr_port_get_hsr(hsr, type);
146 if (port != NULL) 139 if (port)
147 return -EBUSY; /* This port already exists */ 140 return -EBUSY; /* This port already exists */
148 141
149 port = kzalloc(sizeof(*port), GFP_KERNEL); 142 port = kzalloc(sizeof(*port), GFP_KERNEL);
150 if (port == NULL) 143 if (!port)
151 return -ENOMEM; 144 return -ENOMEM;
152 145
153 if (type != HSR_PT_MASTER) { 146 if (type != HSR_PT_MASTER) {
@@ -184,7 +177,7 @@ void hsr_del_port(struct hsr_port *port)
184 list_del_rcu(&port->port_list); 177 list_del_rcu(&port->port_list);
185 178
186 if (port != master) { 179 if (port != master) {
187 if (master != NULL) { 180 if (master) {
188 netdev_update_features(master->dev); 181 netdev_update_features(master->dev);
189 dev_set_mtu(master->dev, hsr_get_max_mtu(hsr)); 182 dev_set_mtu(master->dev, hsr_get_max_mtu(hsr));
190 } 183 }
diff --git a/net/hsr/hsr_slave.h b/net/hsr/hsr_slave.h
index 3ccfbf71c92e..64b549529592 100644
--- a/net/hsr/hsr_slave.h
+++ b/net/hsr/hsr_slave.h
@@ -1,11 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* Copyright 2011-2014 Autronica Fire and Security AS 2/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 3 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation; either version 2 of the License, or (at your option)
6 * any later version.
7 *
8 * Author(s):
9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se 4 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 5 */
11 6
diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h
index a5d7515b7f62..bc147bc8e36a 100644
--- a/net/ieee802154/ieee802154.h
+++ b/net/ieee802154/ieee802154.h
@@ -20,7 +20,6 @@ void ieee802154_nl_exit(void);
20#define IEEE802154_OP(_cmd, _func) \ 20#define IEEE802154_OP(_cmd, _func) \
21 { \ 21 { \
22 .cmd = _cmd, \ 22 .cmd = _cmd, \
23 .policy = ieee802154_policy, \
24 .doit = _func, \ 23 .doit = _func, \
25 .dumpit = NULL, \ 24 .dumpit = NULL, \
26 .flags = GENL_ADMIN_PERM, \ 25 .flags = GENL_ADMIN_PERM, \
@@ -29,7 +28,6 @@ void ieee802154_nl_exit(void);
29#define IEEE802154_DUMP(_cmd, _func, _dump) \ 28#define IEEE802154_DUMP(_cmd, _func, _dump) \
30 { \ 29 { \
31 .cmd = _cmd, \ 30 .cmd = _cmd, \
32 .policy = ieee802154_policy, \
33 .doit = _func, \ 31 .doit = _func, \
34 .dumpit = _dump, \ 32 .dumpit = _dump, \
35 } 33 }
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c
index 96636e3b7aa9..098d67439b6d 100644
--- a/net/ieee802154/netlink.c
+++ b/net/ieee802154/netlink.c
@@ -136,6 +136,7 @@ struct genl_family nl802154_family __ro_after_init = {
136 .name = IEEE802154_NL_NAME, 136 .name = IEEE802154_NL_NAME,
137 .version = 1, 137 .version = 1,
138 .maxattr = IEEE802154_ATTR_MAX, 138 .maxattr = IEEE802154_ATTR_MAX,
139 .policy = ieee802154_policy,
139 .module = THIS_MODULE, 140 .module = THIS_MODULE,
140 .ops = ieee802154_ops, 141 .ops = ieee802154_ops,
141 .n_ops = ARRAY_SIZE(ieee802154_ops), 142 .n_ops = ARRAY_SIZE(ieee802154_ops),
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 99f6c254ea77..e4c4174f9efb 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -247,9 +247,11 @@ nl802154_prepare_wpan_dev_dump(struct sk_buff *skb,
247 rtnl_lock(); 247 rtnl_lock();
248 248
249 if (!cb->args[0]) { 249 if (!cb->args[0]) {
250 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl802154_fam.hdrsize, 250 err = nlmsg_parse_deprecated(cb->nlh,
251 genl_family_attrbuf(&nl802154_fam), 251 GENL_HDRLEN + nl802154_fam.hdrsize,
252 nl802154_fam.maxattr, nl802154_policy, NULL); 252 genl_family_attrbuf(&nl802154_fam),
253 nl802154_fam.maxattr,
254 nl802154_policy, NULL);
253 if (err) 255 if (err)
254 goto out_unlock; 256 goto out_unlock;
255 257
@@ -312,7 +314,7 @@ static inline void *nl802154hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
312static int 314static int
313nl802154_put_flags(struct sk_buff *msg, int attr, u32 mask) 315nl802154_put_flags(struct sk_buff *msg, int attr, u32 mask)
314{ 316{
315 struct nlattr *nl_flags = nla_nest_start(msg, attr); 317 struct nlattr *nl_flags = nla_nest_start_noflag(msg, attr);
316 int i; 318 int i;
317 319
318 if (!nl_flags) 320 if (!nl_flags)
@@ -338,7 +340,7 @@ nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
338 struct nlattr *nl_page; 340 struct nlattr *nl_page;
339 unsigned long page; 341 unsigned long page;
340 342
341 nl_page = nla_nest_start(msg, NL802154_ATTR_CHANNELS_SUPPORTED); 343 nl_page = nla_nest_start_noflag(msg, NL802154_ATTR_CHANNELS_SUPPORTED);
342 if (!nl_page) 344 if (!nl_page)
343 return -ENOBUFS; 345 return -ENOBUFS;
344 346
@@ -360,11 +362,11 @@ nl802154_put_capabilities(struct sk_buff *msg,
360 struct nlattr *nl_caps, *nl_channels; 362 struct nlattr *nl_caps, *nl_channels;
361 int i; 363 int i;
362 364
363 nl_caps = nla_nest_start(msg, NL802154_ATTR_WPAN_PHY_CAPS); 365 nl_caps = nla_nest_start_noflag(msg, NL802154_ATTR_WPAN_PHY_CAPS);
364 if (!nl_caps) 366 if (!nl_caps)
365 return -ENOBUFS; 367 return -ENOBUFS;
366 368
367 nl_channels = nla_nest_start(msg, NL802154_CAP_ATTR_CHANNELS); 369 nl_channels = nla_nest_start_noflag(msg, NL802154_CAP_ATTR_CHANNELS);
368 if (!nl_channels) 370 if (!nl_channels)
369 return -ENOBUFS; 371 return -ENOBUFS;
370 372
@@ -380,8 +382,8 @@ nl802154_put_capabilities(struct sk_buff *msg,
380 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_ED_LEVEL) { 382 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_ED_LEVEL) {
381 struct nlattr *nl_ed_lvls; 383 struct nlattr *nl_ed_lvls;
382 384
383 nl_ed_lvls = nla_nest_start(msg, 385 nl_ed_lvls = nla_nest_start_noflag(msg,
384 NL802154_CAP_ATTR_CCA_ED_LEVELS); 386 NL802154_CAP_ATTR_CCA_ED_LEVELS);
385 if (!nl_ed_lvls) 387 if (!nl_ed_lvls)
386 return -ENOBUFS; 388 return -ENOBUFS;
387 389
@@ -396,7 +398,8 @@ nl802154_put_capabilities(struct sk_buff *msg,
396 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER) { 398 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER) {
397 struct nlattr *nl_tx_pwrs; 399 struct nlattr *nl_tx_pwrs;
398 400
399 nl_tx_pwrs = nla_nest_start(msg, NL802154_CAP_ATTR_TX_POWERS); 401 nl_tx_pwrs = nla_nest_start_noflag(msg,
402 NL802154_CAP_ATTR_TX_POWERS);
400 if (!nl_tx_pwrs) 403 if (!nl_tx_pwrs)
401 return -ENOBUFS; 404 return -ENOBUFS;
402 405
@@ -504,7 +507,7 @@ static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
504 if (nl802154_put_capabilities(msg, rdev)) 507 if (nl802154_put_capabilities(msg, rdev))
505 goto nla_put_failure; 508 goto nla_put_failure;
506 509
507 nl_cmds = nla_nest_start(msg, NL802154_ATTR_SUPPORTED_COMMANDS); 510 nl_cmds = nla_nest_start_noflag(msg, NL802154_ATTR_SUPPORTED_COMMANDS);
508 if (!nl_cmds) 511 if (!nl_cmds)
509 goto nla_put_failure; 512 goto nla_put_failure;
510 513
@@ -561,8 +564,10 @@ static int nl802154_dump_wpan_phy_parse(struct sk_buff *skb,
561 struct nl802154_dump_wpan_phy_state *state) 564 struct nl802154_dump_wpan_phy_state *state)
562{ 565{
563 struct nlattr **tb = genl_family_attrbuf(&nl802154_fam); 566 struct nlattr **tb = genl_family_attrbuf(&nl802154_fam);
564 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl802154_fam.hdrsize, tb, 567 int ret = nlmsg_parse_deprecated(cb->nlh,
565 nl802154_fam.maxattr, nl802154_policy, NULL); 568 GENL_HDRLEN + nl802154_fam.hdrsize,
569 tb, nl802154_fam.maxattr,
570 nl802154_policy, NULL);
566 571
567 /* TODO check if we can handle error here, 572 /* TODO check if we can handle error here,
568 * we have no backward compatibility 573 * we have no backward compatibility
@@ -693,7 +698,8 @@ ieee802154_llsec_send_key_id(struct sk_buff *msg,
693 698
694 switch (desc->mode) { 699 switch (desc->mode) {
695 case NL802154_KEY_ID_MODE_IMPLICIT: 700 case NL802154_KEY_ID_MODE_IMPLICIT:
696 nl_dev_addr = nla_nest_start(msg, NL802154_KEY_ID_ATTR_IMPLICIT); 701 nl_dev_addr = nla_nest_start_noflag(msg,
702 NL802154_KEY_ID_ATTR_IMPLICIT);
697 if (!nl_dev_addr) 703 if (!nl_dev_addr)
698 return -ENOBUFS; 704 return -ENOBUFS;
699 705
@@ -768,7 +774,7 @@ static int nl802154_get_llsec_params(struct sk_buff *msg,
768 params.frame_counter)) 774 params.frame_counter))
769 return -ENOBUFS; 775 return -ENOBUFS;
770 776
771 nl_key_id = nla_nest_start(msg, NL802154_ATTR_SEC_OUT_KEY_ID); 777 nl_key_id = nla_nest_start_noflag(msg, NL802154_ATTR_SEC_OUT_KEY_ID);
772 if (!nl_key_id) 778 if (!nl_key_id)
773 return -ENOBUFS; 779 return -ENOBUFS;
774 780
@@ -1306,8 +1312,7 @@ ieee802154_llsec_parse_dev_addr(struct nlattr *nla,
1306{ 1312{
1307 struct nlattr *attrs[NL802154_DEV_ADDR_ATTR_MAX + 1]; 1313 struct nlattr *attrs[NL802154_DEV_ADDR_ATTR_MAX + 1];
1308 1314
1309 if (!nla || nla_parse_nested(attrs, NL802154_DEV_ADDR_ATTR_MAX, nla, 1315 if (!nla || nla_parse_nested_deprecated(attrs, NL802154_DEV_ADDR_ATTR_MAX, nla, nl802154_dev_addr_policy, NULL))
1310 nl802154_dev_addr_policy, NULL))
1311 return -EINVAL; 1316 return -EINVAL;
1312 1317
1313 if (!attrs[NL802154_DEV_ADDR_ATTR_PAN_ID] || 1318 if (!attrs[NL802154_DEV_ADDR_ATTR_PAN_ID] ||
@@ -1346,8 +1351,7 @@ ieee802154_llsec_parse_key_id(struct nlattr *nla,
1346{ 1351{
1347 struct nlattr *attrs[NL802154_KEY_ID_ATTR_MAX + 1]; 1352 struct nlattr *attrs[NL802154_KEY_ID_ATTR_MAX + 1];
1348 1353
1349 if (!nla || nla_parse_nested(attrs, NL802154_KEY_ID_ATTR_MAX, nla, 1354 if (!nla || nla_parse_nested_deprecated(attrs, NL802154_KEY_ID_ATTR_MAX, nla, nl802154_key_id_policy, NULL))
1350 nl802154_key_id_policy, NULL))
1351 return -EINVAL; 1355 return -EINVAL;
1352 1356
1353 if (!attrs[NL802154_KEY_ID_ATTR_MODE]) 1357 if (!attrs[NL802154_KEY_ID_ATTR_MODE])
@@ -1455,11 +1459,11 @@ static int nl802154_send_key(struct sk_buff *msg, u32 cmd, u32 portid,
1455 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex)) 1459 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex))
1456 goto nla_put_failure; 1460 goto nla_put_failure;
1457 1461
1458 nl_key = nla_nest_start(msg, NL802154_ATTR_SEC_KEY); 1462 nl_key = nla_nest_start_noflag(msg, NL802154_ATTR_SEC_KEY);
1459 if (!nl_key) 1463 if (!nl_key)
1460 goto nla_put_failure; 1464 goto nla_put_failure;
1461 1465
1462 nl_key_id = nla_nest_start(msg, NL802154_KEY_ATTR_ID); 1466 nl_key_id = nla_nest_start_noflag(msg, NL802154_KEY_ATTR_ID);
1463 if (!nl_key_id) 1467 if (!nl_key_id)
1464 goto nla_put_failure; 1468 goto nla_put_failure;
1465 1469
@@ -1562,9 +1566,7 @@ static int nl802154_add_llsec_key(struct sk_buff *skb, struct genl_info *info)
1562 struct ieee802154_llsec_key_id id = { }; 1566 struct ieee802154_llsec_key_id id = { };
1563 u32 commands[NL802154_CMD_FRAME_NR_IDS / 32] = { }; 1567 u32 commands[NL802154_CMD_FRAME_NR_IDS / 32] = { };
1564 1568
1565 if (nla_parse_nested(attrs, NL802154_KEY_ATTR_MAX, 1569 if (nla_parse_nested_deprecated(attrs, NL802154_KEY_ATTR_MAX, info->attrs[NL802154_ATTR_SEC_KEY], nl802154_key_policy, info->extack))
1566 info->attrs[NL802154_ATTR_SEC_KEY],
1567 nl802154_key_policy, info->extack))
1568 return -EINVAL; 1570 return -EINVAL;
1569 1571
1570 if (!attrs[NL802154_KEY_ATTR_USAGE_FRAMES] || 1572 if (!attrs[NL802154_KEY_ATTR_USAGE_FRAMES] ||
@@ -1612,9 +1614,7 @@ static int nl802154_del_llsec_key(struct sk_buff *skb, struct genl_info *info)
1612 struct nlattr *attrs[NL802154_KEY_ATTR_MAX + 1]; 1614 struct nlattr *attrs[NL802154_KEY_ATTR_MAX + 1];
1613 struct ieee802154_llsec_key_id id; 1615 struct ieee802154_llsec_key_id id;
1614 1616
1615 if (nla_parse_nested(attrs, NL802154_KEY_ATTR_MAX, 1617 if (nla_parse_nested_deprecated(attrs, NL802154_KEY_ATTR_MAX, info->attrs[NL802154_ATTR_SEC_KEY], nl802154_key_policy, info->extack))
1616 info->attrs[NL802154_ATTR_SEC_KEY],
1617 nl802154_key_policy, info->extack))
1618 return -EINVAL; 1618 return -EINVAL;
1619 1619
1620 if (ieee802154_llsec_parse_key_id(attrs[NL802154_KEY_ATTR_ID], &id) < 0) 1620 if (ieee802154_llsec_parse_key_id(attrs[NL802154_KEY_ATTR_ID], &id) < 0)
@@ -1639,7 +1639,7 @@ static int nl802154_send_device(struct sk_buff *msg, u32 cmd, u32 portid,
1639 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex)) 1639 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex))
1640 goto nla_put_failure; 1640 goto nla_put_failure;
1641 1641
1642 nl_device = nla_nest_start(msg, NL802154_ATTR_SEC_DEVICE); 1642 nl_device = nla_nest_start_noflag(msg, NL802154_ATTR_SEC_DEVICE);
1643 if (!nl_device) 1643 if (!nl_device)
1644 goto nla_put_failure; 1644 goto nla_put_failure;
1645 1645
@@ -1728,8 +1728,7 @@ ieee802154_llsec_parse_device(struct nlattr *nla,
1728{ 1728{
1729 struct nlattr *attrs[NL802154_DEV_ATTR_MAX + 1]; 1729 struct nlattr *attrs[NL802154_DEV_ATTR_MAX + 1];
1730 1730
1731 if (!nla || nla_parse_nested(attrs, NL802154_DEV_ATTR_MAX, 1731 if (!nla || nla_parse_nested_deprecated(attrs, NL802154_DEV_ATTR_MAX, nla, nl802154_dev_policy, NULL))
1732 nla, nl802154_dev_policy, NULL))
1733 return -EINVAL; 1732 return -EINVAL;
1734 1733
1735 memset(dev, 0, sizeof(*dev)); 1734 memset(dev, 0, sizeof(*dev));
@@ -1780,9 +1779,7 @@ static int nl802154_del_llsec_dev(struct sk_buff *skb, struct genl_info *info)
1780 struct nlattr *attrs[NL802154_DEV_ATTR_MAX + 1]; 1779 struct nlattr *attrs[NL802154_DEV_ATTR_MAX + 1];
1781 __le64 extended_addr; 1780 __le64 extended_addr;
1782 1781
1783 if (nla_parse_nested(attrs, NL802154_DEV_ATTR_MAX, 1782 if (nla_parse_nested_deprecated(attrs, NL802154_DEV_ATTR_MAX, info->attrs[NL802154_ATTR_SEC_DEVICE], nl802154_dev_policy, info->extack))
1784 info->attrs[NL802154_ATTR_SEC_DEVICE],
1785 nl802154_dev_policy, info->extack))
1786 return -EINVAL; 1783 return -EINVAL;
1787 1784
1788 if (!attrs[NL802154_DEV_ATTR_EXTENDED_ADDR]) 1785 if (!attrs[NL802154_DEV_ATTR_EXTENDED_ADDR])
@@ -1808,7 +1805,7 @@ static int nl802154_send_devkey(struct sk_buff *msg, u32 cmd, u32 portid,
1808 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex)) 1805 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex))
1809 goto nla_put_failure; 1806 goto nla_put_failure;
1810 1807
1811 nl_devkey = nla_nest_start(msg, NL802154_ATTR_SEC_DEVKEY); 1808 nl_devkey = nla_nest_start_noflag(msg, NL802154_ATTR_SEC_DEVKEY);
1812 if (!nl_devkey) 1809 if (!nl_devkey)
1813 goto nla_put_failure; 1810 goto nla_put_failure;
1814 1811
@@ -1818,7 +1815,7 @@ static int nl802154_send_devkey(struct sk_buff *msg, u32 cmd, u32 portid,
1818 devkey->frame_counter)) 1815 devkey->frame_counter))
1819 goto nla_put_failure; 1816 goto nla_put_failure;
1820 1817
1821 nl_key_id = nla_nest_start(msg, NL802154_DEVKEY_ATTR_ID); 1818 nl_key_id = nla_nest_start_noflag(msg, NL802154_DEVKEY_ATTR_ID);
1822 if (!nl_key_id) 1819 if (!nl_key_id)
1823 goto nla_put_failure; 1820 goto nla_put_failure;
1824 1821
@@ -1908,9 +1905,7 @@ static int nl802154_add_llsec_devkey(struct sk_buff *skb, struct genl_info *info
1908 __le64 extended_addr; 1905 __le64 extended_addr;
1909 1906
1910 if (!info->attrs[NL802154_ATTR_SEC_DEVKEY] || 1907 if (!info->attrs[NL802154_ATTR_SEC_DEVKEY] ||
1911 nla_parse_nested(attrs, NL802154_DEVKEY_ATTR_MAX, 1908 nla_parse_nested_deprecated(attrs, NL802154_DEVKEY_ATTR_MAX, info->attrs[NL802154_ATTR_SEC_DEVKEY], nl802154_devkey_policy, info->extack) < 0)
1912 info->attrs[NL802154_ATTR_SEC_DEVKEY],
1913 nl802154_devkey_policy, info->extack) < 0)
1914 return -EINVAL; 1909 return -EINVAL;
1915 1910
1916 if (!attrs[NL802154_DEVKEY_ATTR_FRAME_COUNTER] || 1911 if (!attrs[NL802154_DEVKEY_ATTR_FRAME_COUNTER] ||
@@ -1940,9 +1935,7 @@ static int nl802154_del_llsec_devkey(struct sk_buff *skb, struct genl_info *info
1940 struct ieee802154_llsec_device_key key; 1935 struct ieee802154_llsec_device_key key;
1941 __le64 extended_addr; 1936 __le64 extended_addr;
1942 1937
1943 if (nla_parse_nested(attrs, NL802154_DEVKEY_ATTR_MAX, 1938 if (nla_parse_nested_deprecated(attrs, NL802154_DEVKEY_ATTR_MAX, info->attrs[NL802154_ATTR_SEC_DEVKEY], nl802154_devkey_policy, info->extack))
1944 info->attrs[NL802154_ATTR_SEC_DEVKEY],
1945 nl802154_devkey_policy, info->extack))
1946 return -EINVAL; 1939 return -EINVAL;
1947 1940
1948 if (!attrs[NL802154_DEVKEY_ATTR_EXTENDED_ADDR]) 1941 if (!attrs[NL802154_DEVKEY_ATTR_EXTENDED_ADDR])
@@ -1976,7 +1969,7 @@ static int nl802154_send_seclevel(struct sk_buff *msg, u32 cmd, u32 portid,
1976 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex)) 1969 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex))
1977 goto nla_put_failure; 1970 goto nla_put_failure;
1978 1971
1979 nl_seclevel = nla_nest_start(msg, NL802154_ATTR_SEC_LEVEL); 1972 nl_seclevel = nla_nest_start_noflag(msg, NL802154_ATTR_SEC_LEVEL);
1980 if (!nl_seclevel) 1973 if (!nl_seclevel)
1981 goto nla_put_failure; 1974 goto nla_put_failure;
1982 1975
@@ -2062,8 +2055,7 @@ llsec_parse_seclevel(struct nlattr *nla, struct ieee802154_llsec_seclevel *sl)
2062{ 2055{
2063 struct nlattr *attrs[NL802154_SECLEVEL_ATTR_MAX + 1]; 2056 struct nlattr *attrs[NL802154_SECLEVEL_ATTR_MAX + 1];
2064 2057
2065 if (!nla || nla_parse_nested(attrs, NL802154_SECLEVEL_ATTR_MAX, 2058 if (!nla || nla_parse_nested_deprecated(attrs, NL802154_SECLEVEL_ATTR_MAX, nla, nl802154_seclevel_policy, NULL))
2066 nla, nl802154_seclevel_policy, NULL))
2067 return -EINVAL; 2059 return -EINVAL;
2068 2060
2069 memset(sl, 0, sizeof(*sl)); 2061 memset(sl, 0, sizeof(*sl));
@@ -2217,131 +2209,131 @@ static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
2217static const struct genl_ops nl802154_ops[] = { 2209static const struct genl_ops nl802154_ops[] = {
2218 { 2210 {
2219 .cmd = NL802154_CMD_GET_WPAN_PHY, 2211 .cmd = NL802154_CMD_GET_WPAN_PHY,
2212 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2220 .doit = nl802154_get_wpan_phy, 2213 .doit = nl802154_get_wpan_phy,
2221 .dumpit = nl802154_dump_wpan_phy, 2214 .dumpit = nl802154_dump_wpan_phy,
2222 .done = nl802154_dump_wpan_phy_done, 2215 .done = nl802154_dump_wpan_phy_done,
2223 .policy = nl802154_policy,
2224 /* can be retrieved by unprivileged users */ 2216 /* can be retrieved by unprivileged users */
2225 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | 2217 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2226 NL802154_FLAG_NEED_RTNL, 2218 NL802154_FLAG_NEED_RTNL,
2227 }, 2219 },
2228 { 2220 {
2229 .cmd = NL802154_CMD_GET_INTERFACE, 2221 .cmd = NL802154_CMD_GET_INTERFACE,
2222 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2230 .doit = nl802154_get_interface, 2223 .doit = nl802154_get_interface,
2231 .dumpit = nl802154_dump_interface, 2224 .dumpit = nl802154_dump_interface,
2232 .policy = nl802154_policy,
2233 /* can be retrieved by unprivileged users */ 2225 /* can be retrieved by unprivileged users */
2234 .internal_flags = NL802154_FLAG_NEED_WPAN_DEV | 2226 .internal_flags = NL802154_FLAG_NEED_WPAN_DEV |
2235 NL802154_FLAG_NEED_RTNL, 2227 NL802154_FLAG_NEED_RTNL,
2236 }, 2228 },
2237 { 2229 {
2238 .cmd = NL802154_CMD_NEW_INTERFACE, 2230 .cmd = NL802154_CMD_NEW_INTERFACE,
2231 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2239 .doit = nl802154_new_interface, 2232 .doit = nl802154_new_interface,
2240 .policy = nl802154_policy,
2241 .flags = GENL_ADMIN_PERM, 2233 .flags = GENL_ADMIN_PERM,
2242 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | 2234 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2243 NL802154_FLAG_NEED_RTNL, 2235 NL802154_FLAG_NEED_RTNL,
2244 }, 2236 },
2245 { 2237 {
2246 .cmd = NL802154_CMD_DEL_INTERFACE, 2238 .cmd = NL802154_CMD_DEL_INTERFACE,
2239 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2247 .doit = nl802154_del_interface, 2240 .doit = nl802154_del_interface,
2248 .policy = nl802154_policy,
2249 .flags = GENL_ADMIN_PERM, 2241 .flags = GENL_ADMIN_PERM,
2250 .internal_flags = NL802154_FLAG_NEED_WPAN_DEV | 2242 .internal_flags = NL802154_FLAG_NEED_WPAN_DEV |
2251 NL802154_FLAG_NEED_RTNL, 2243 NL802154_FLAG_NEED_RTNL,
2252 }, 2244 },
2253 { 2245 {
2254 .cmd = NL802154_CMD_SET_CHANNEL, 2246 .cmd = NL802154_CMD_SET_CHANNEL,
2247 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2255 .doit = nl802154_set_channel, 2248 .doit = nl802154_set_channel,
2256 .policy = nl802154_policy,
2257 .flags = GENL_ADMIN_PERM, 2249 .flags = GENL_ADMIN_PERM,
2258 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | 2250 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2259 NL802154_FLAG_NEED_RTNL, 2251 NL802154_FLAG_NEED_RTNL,
2260 }, 2252 },
2261 { 2253 {
2262 .cmd = NL802154_CMD_SET_CCA_MODE, 2254 .cmd = NL802154_CMD_SET_CCA_MODE,
2255 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2263 .doit = nl802154_set_cca_mode, 2256 .doit = nl802154_set_cca_mode,
2264 .policy = nl802154_policy,
2265 .flags = GENL_ADMIN_PERM, 2257 .flags = GENL_ADMIN_PERM,
2266 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | 2258 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2267 NL802154_FLAG_NEED_RTNL, 2259 NL802154_FLAG_NEED_RTNL,
2268 }, 2260 },
2269 { 2261 {
2270 .cmd = NL802154_CMD_SET_CCA_ED_LEVEL, 2262 .cmd = NL802154_CMD_SET_CCA_ED_LEVEL,
2263 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2271 .doit = nl802154_set_cca_ed_level, 2264 .doit = nl802154_set_cca_ed_level,
2272 .policy = nl802154_policy,
2273 .flags = GENL_ADMIN_PERM, 2265 .flags = GENL_ADMIN_PERM,
2274 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | 2266 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2275 NL802154_FLAG_NEED_RTNL, 2267 NL802154_FLAG_NEED_RTNL,
2276 }, 2268 },
2277 { 2269 {
2278 .cmd = NL802154_CMD_SET_TX_POWER, 2270 .cmd = NL802154_CMD_SET_TX_POWER,
2271 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2279 .doit = nl802154_set_tx_power, 2272 .doit = nl802154_set_tx_power,
2280 .policy = nl802154_policy,
2281 .flags = GENL_ADMIN_PERM, 2273 .flags = GENL_ADMIN_PERM,
2282 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | 2274 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2283 NL802154_FLAG_NEED_RTNL, 2275 NL802154_FLAG_NEED_RTNL,
2284 }, 2276 },
2285 { 2277 {
2286 .cmd = NL802154_CMD_SET_WPAN_PHY_NETNS, 2278 .cmd = NL802154_CMD_SET_WPAN_PHY_NETNS,
2279 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2287 .doit = nl802154_wpan_phy_netns, 2280 .doit = nl802154_wpan_phy_netns,
2288 .policy = nl802154_policy,
2289 .flags = GENL_ADMIN_PERM, 2281 .flags = GENL_ADMIN_PERM,
2290 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | 2282 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2291 NL802154_FLAG_NEED_RTNL, 2283 NL802154_FLAG_NEED_RTNL,
2292 }, 2284 },
2293 { 2285 {
2294 .cmd = NL802154_CMD_SET_PAN_ID, 2286 .cmd = NL802154_CMD_SET_PAN_ID,
2287 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2295 .doit = nl802154_set_pan_id, 2288 .doit = nl802154_set_pan_id,
2296 .policy = nl802154_policy,
2297 .flags = GENL_ADMIN_PERM, 2289 .flags = GENL_ADMIN_PERM,
2298 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2290 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2299 NL802154_FLAG_NEED_RTNL, 2291 NL802154_FLAG_NEED_RTNL,
2300 }, 2292 },
2301 { 2293 {
2302 .cmd = NL802154_CMD_SET_SHORT_ADDR, 2294 .cmd = NL802154_CMD_SET_SHORT_ADDR,
2295 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2303 .doit = nl802154_set_short_addr, 2296 .doit = nl802154_set_short_addr,
2304 .policy = nl802154_policy,
2305 .flags = GENL_ADMIN_PERM, 2297 .flags = GENL_ADMIN_PERM,
2306 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2298 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2307 NL802154_FLAG_NEED_RTNL, 2299 NL802154_FLAG_NEED_RTNL,
2308 }, 2300 },
2309 { 2301 {
2310 .cmd = NL802154_CMD_SET_BACKOFF_EXPONENT, 2302 .cmd = NL802154_CMD_SET_BACKOFF_EXPONENT,
2303 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2311 .doit = nl802154_set_backoff_exponent, 2304 .doit = nl802154_set_backoff_exponent,
2312 .policy = nl802154_policy,
2313 .flags = GENL_ADMIN_PERM, 2305 .flags = GENL_ADMIN_PERM,
2314 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2306 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2315 NL802154_FLAG_NEED_RTNL, 2307 NL802154_FLAG_NEED_RTNL,
2316 }, 2308 },
2317 { 2309 {
2318 .cmd = NL802154_CMD_SET_MAX_CSMA_BACKOFFS, 2310 .cmd = NL802154_CMD_SET_MAX_CSMA_BACKOFFS,
2311 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2319 .doit = nl802154_set_max_csma_backoffs, 2312 .doit = nl802154_set_max_csma_backoffs,
2320 .policy = nl802154_policy,
2321 .flags = GENL_ADMIN_PERM, 2313 .flags = GENL_ADMIN_PERM,
2322 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2314 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2323 NL802154_FLAG_NEED_RTNL, 2315 NL802154_FLAG_NEED_RTNL,
2324 }, 2316 },
2325 { 2317 {
2326 .cmd = NL802154_CMD_SET_MAX_FRAME_RETRIES, 2318 .cmd = NL802154_CMD_SET_MAX_FRAME_RETRIES,
2319 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2327 .doit = nl802154_set_max_frame_retries, 2320 .doit = nl802154_set_max_frame_retries,
2328 .policy = nl802154_policy,
2329 .flags = GENL_ADMIN_PERM, 2321 .flags = GENL_ADMIN_PERM,
2330 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2322 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2331 NL802154_FLAG_NEED_RTNL, 2323 NL802154_FLAG_NEED_RTNL,
2332 }, 2324 },
2333 { 2325 {
2334 .cmd = NL802154_CMD_SET_LBT_MODE, 2326 .cmd = NL802154_CMD_SET_LBT_MODE,
2327 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2335 .doit = nl802154_set_lbt_mode, 2328 .doit = nl802154_set_lbt_mode,
2336 .policy = nl802154_policy,
2337 .flags = GENL_ADMIN_PERM, 2329 .flags = GENL_ADMIN_PERM,
2338 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2330 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2339 NL802154_FLAG_NEED_RTNL, 2331 NL802154_FLAG_NEED_RTNL,
2340 }, 2332 },
2341 { 2333 {
2342 .cmd = NL802154_CMD_SET_ACKREQ_DEFAULT, 2334 .cmd = NL802154_CMD_SET_ACKREQ_DEFAULT,
2335 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2343 .doit = nl802154_set_ackreq_default, 2336 .doit = nl802154_set_ackreq_default,
2344 .policy = nl802154_policy,
2345 .flags = GENL_ADMIN_PERM, 2337 .flags = GENL_ADMIN_PERM,
2346 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2338 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2347 NL802154_FLAG_NEED_RTNL, 2339 NL802154_FLAG_NEED_RTNL,
@@ -2349,33 +2341,33 @@ static const struct genl_ops nl802154_ops[] = {
2349#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL 2341#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
2350 { 2342 {
2351 .cmd = NL802154_CMD_SET_SEC_PARAMS, 2343 .cmd = NL802154_CMD_SET_SEC_PARAMS,
2344 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2352 .doit = nl802154_set_llsec_params, 2345 .doit = nl802154_set_llsec_params,
2353 .policy = nl802154_policy,
2354 .flags = GENL_ADMIN_PERM, 2346 .flags = GENL_ADMIN_PERM,
2355 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2347 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2356 NL802154_FLAG_NEED_RTNL, 2348 NL802154_FLAG_NEED_RTNL,
2357 }, 2349 },
2358 { 2350 {
2359 .cmd = NL802154_CMD_GET_SEC_KEY, 2351 .cmd = NL802154_CMD_GET_SEC_KEY,
2352 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2360 /* TODO .doit by matching key id? */ 2353 /* TODO .doit by matching key id? */
2361 .dumpit = nl802154_dump_llsec_key, 2354 .dumpit = nl802154_dump_llsec_key,
2362 .policy = nl802154_policy,
2363 .flags = GENL_ADMIN_PERM, 2355 .flags = GENL_ADMIN_PERM,
2364 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2356 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2365 NL802154_FLAG_NEED_RTNL, 2357 NL802154_FLAG_NEED_RTNL,
2366 }, 2358 },
2367 { 2359 {
2368 .cmd = NL802154_CMD_NEW_SEC_KEY, 2360 .cmd = NL802154_CMD_NEW_SEC_KEY,
2361 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2369 .doit = nl802154_add_llsec_key, 2362 .doit = nl802154_add_llsec_key,
2370 .policy = nl802154_policy,
2371 .flags = GENL_ADMIN_PERM, 2363 .flags = GENL_ADMIN_PERM,
2372 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2364 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2373 NL802154_FLAG_NEED_RTNL, 2365 NL802154_FLAG_NEED_RTNL,
2374 }, 2366 },
2375 { 2367 {
2376 .cmd = NL802154_CMD_DEL_SEC_KEY, 2368 .cmd = NL802154_CMD_DEL_SEC_KEY,
2369 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2377 .doit = nl802154_del_llsec_key, 2370 .doit = nl802154_del_llsec_key,
2378 .policy = nl802154_policy,
2379 .flags = GENL_ADMIN_PERM, 2371 .flags = GENL_ADMIN_PERM,
2380 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2372 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2381 NL802154_FLAG_NEED_RTNL, 2373 NL802154_FLAG_NEED_RTNL,
@@ -2383,25 +2375,25 @@ static const struct genl_ops nl802154_ops[] = {
2383 /* TODO unique identifier must short+pan OR extended_addr */ 2375 /* TODO unique identifier must short+pan OR extended_addr */
2384 { 2376 {
2385 .cmd = NL802154_CMD_GET_SEC_DEV, 2377 .cmd = NL802154_CMD_GET_SEC_DEV,
2378 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2386 /* TODO .doit by matching extended_addr? */ 2379 /* TODO .doit by matching extended_addr? */
2387 .dumpit = nl802154_dump_llsec_dev, 2380 .dumpit = nl802154_dump_llsec_dev,
2388 .policy = nl802154_policy,
2389 .flags = GENL_ADMIN_PERM, 2381 .flags = GENL_ADMIN_PERM,
2390 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2382 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2391 NL802154_FLAG_NEED_RTNL, 2383 NL802154_FLAG_NEED_RTNL,
2392 }, 2384 },
2393 { 2385 {
2394 .cmd = NL802154_CMD_NEW_SEC_DEV, 2386 .cmd = NL802154_CMD_NEW_SEC_DEV,
2387 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2395 .doit = nl802154_add_llsec_dev, 2388 .doit = nl802154_add_llsec_dev,
2396 .policy = nl802154_policy,
2397 .flags = GENL_ADMIN_PERM, 2389 .flags = GENL_ADMIN_PERM,
2398 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2390 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2399 NL802154_FLAG_NEED_RTNL, 2391 NL802154_FLAG_NEED_RTNL,
2400 }, 2392 },
2401 { 2393 {
2402 .cmd = NL802154_CMD_DEL_SEC_DEV, 2394 .cmd = NL802154_CMD_DEL_SEC_DEV,
2395 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2403 .doit = nl802154_del_llsec_dev, 2396 .doit = nl802154_del_llsec_dev,
2404 .policy = nl802154_policy,
2405 .flags = GENL_ADMIN_PERM, 2397 .flags = GENL_ADMIN_PERM,
2406 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2398 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2407 NL802154_FLAG_NEED_RTNL, 2399 NL802154_FLAG_NEED_RTNL,
@@ -2409,51 +2401,51 @@ static const struct genl_ops nl802154_ops[] = {
2409 /* TODO remove complete devkey, put it as nested? */ 2401 /* TODO remove complete devkey, put it as nested? */
2410 { 2402 {
2411 .cmd = NL802154_CMD_GET_SEC_DEVKEY, 2403 .cmd = NL802154_CMD_GET_SEC_DEVKEY,
2404 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2412 /* TODO doit by matching ??? */ 2405 /* TODO doit by matching ??? */
2413 .dumpit = nl802154_dump_llsec_devkey, 2406 .dumpit = nl802154_dump_llsec_devkey,
2414 .policy = nl802154_policy,
2415 .flags = GENL_ADMIN_PERM, 2407 .flags = GENL_ADMIN_PERM,
2416 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2408 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2417 NL802154_FLAG_NEED_RTNL, 2409 NL802154_FLAG_NEED_RTNL,
2418 }, 2410 },
2419 { 2411 {
2420 .cmd = NL802154_CMD_NEW_SEC_DEVKEY, 2412 .cmd = NL802154_CMD_NEW_SEC_DEVKEY,
2413 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2421 .doit = nl802154_add_llsec_devkey, 2414 .doit = nl802154_add_llsec_devkey,
2422 .policy = nl802154_policy,
2423 .flags = GENL_ADMIN_PERM, 2415 .flags = GENL_ADMIN_PERM,
2424 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2416 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2425 NL802154_FLAG_NEED_RTNL, 2417 NL802154_FLAG_NEED_RTNL,
2426 }, 2418 },
2427 { 2419 {
2428 .cmd = NL802154_CMD_DEL_SEC_DEVKEY, 2420 .cmd = NL802154_CMD_DEL_SEC_DEVKEY,
2421 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2429 .doit = nl802154_del_llsec_devkey, 2422 .doit = nl802154_del_llsec_devkey,
2430 .policy = nl802154_policy,
2431 .flags = GENL_ADMIN_PERM, 2423 .flags = GENL_ADMIN_PERM,
2432 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2424 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2433 NL802154_FLAG_NEED_RTNL, 2425 NL802154_FLAG_NEED_RTNL,
2434 }, 2426 },
2435 { 2427 {
2436 .cmd = NL802154_CMD_GET_SEC_LEVEL, 2428 .cmd = NL802154_CMD_GET_SEC_LEVEL,
2429 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2437 /* TODO .doit by matching frame_type? */ 2430 /* TODO .doit by matching frame_type? */
2438 .dumpit = nl802154_dump_llsec_seclevel, 2431 .dumpit = nl802154_dump_llsec_seclevel,
2439 .policy = nl802154_policy,
2440 .flags = GENL_ADMIN_PERM, 2432 .flags = GENL_ADMIN_PERM,
2441 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2433 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2442 NL802154_FLAG_NEED_RTNL, 2434 NL802154_FLAG_NEED_RTNL,
2443 }, 2435 },
2444 { 2436 {
2445 .cmd = NL802154_CMD_NEW_SEC_LEVEL, 2437 .cmd = NL802154_CMD_NEW_SEC_LEVEL,
2438 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2446 .doit = nl802154_add_llsec_seclevel, 2439 .doit = nl802154_add_llsec_seclevel,
2447 .policy = nl802154_policy,
2448 .flags = GENL_ADMIN_PERM, 2440 .flags = GENL_ADMIN_PERM,
2449 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2441 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2450 NL802154_FLAG_NEED_RTNL, 2442 NL802154_FLAG_NEED_RTNL,
2451 }, 2443 },
2452 { 2444 {
2453 .cmd = NL802154_CMD_DEL_SEC_LEVEL, 2445 .cmd = NL802154_CMD_DEL_SEC_LEVEL,
2446 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2454 /* TODO match frame_type only? */ 2447 /* TODO match frame_type only? */
2455 .doit = nl802154_del_llsec_seclevel, 2448 .doit = nl802154_del_llsec_seclevel,
2456 .policy = nl802154_policy,
2457 .flags = GENL_ADMIN_PERM, 2449 .flags = GENL_ADMIN_PERM,
2458 .internal_flags = NL802154_FLAG_NEED_NETDEV | 2450 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2459 NL802154_FLAG_NEED_RTNL, 2451 NL802154_FLAG_NEED_RTNL,
@@ -2466,6 +2458,7 @@ static struct genl_family nl802154_fam __ro_after_init = {
2466 .hdrsize = 0, /* no private header */ 2458 .hdrsize = 0, /* no private header */
2467 .version = 1, /* no particular meaning now */ 2459 .version = 1, /* no particular meaning now */
2468 .maxattr = NL802154_ATTR_MAX, 2460 .maxattr = NL802154_ATTR_MAX,
2461 .policy = nl802154_policy,
2469 .netnsok = true, 2462 .netnsok = true,
2470 .pre_doit = nl802154_pre_doit, 2463 .pre_doit = nl802154_pre_doit,
2471 .post_doit = nl802154_post_doit, 2464 .post_doit = nl802154_post_doit,
diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c
index bc6b912603f1..ce2dfb997537 100644
--- a/net/ieee802154/socket.c
+++ b/net/ieee802154/socket.c
@@ -164,10 +164,6 @@ static int ieee802154_sock_ioctl(struct socket *sock, unsigned int cmd,
164 struct sock *sk = sock->sk; 164 struct sock *sk = sock->sk;
165 165
166 switch (cmd) { 166 switch (cmd) {
167 case SIOCGSTAMP:
168 return sock_get_timestamp(sk, (struct timeval __user *)arg);
169 case SIOCGSTAMPNS:
170 return sock_get_timestampns(sk, (struct timespec __user *)arg);
171 case SIOCGIFADDR: 167 case SIOCGIFADDR:
172 case SIOCSIFADDR: 168 case SIOCSIFADDR:
173 return ieee802154_dev_ioctl(sk, (struct ifreq __user *)arg, 169 return ieee802154_dev_ioctl(sk, (struct ifreq __user *)arg,
@@ -426,6 +422,7 @@ static const struct proto_ops ieee802154_raw_ops = {
426 .getname = sock_no_getname, 422 .getname = sock_no_getname,
427 .poll = datagram_poll, 423 .poll = datagram_poll,
428 .ioctl = ieee802154_sock_ioctl, 424 .ioctl = ieee802154_sock_ioctl,
425 .gettstamp = sock_gettstamp,
429 .listen = sock_no_listen, 426 .listen = sock_no_listen,
430 .shutdown = sock_no_shutdown, 427 .shutdown = sock_no_shutdown,
431 .setsockopt = sock_common_setsockopt, 428 .setsockopt = sock_common_setsockopt,
@@ -988,6 +985,7 @@ static const struct proto_ops ieee802154_dgram_ops = {
988 .getname = sock_no_getname, 985 .getname = sock_no_getname,
989 .poll = datagram_poll, 986 .poll = datagram_poll,
990 .ioctl = ieee802154_sock_ioctl, 987 .ioctl = ieee802154_sock_ioctl,
988 .gettstamp = sock_gettstamp,
991 .listen = sock_no_listen, 989 .listen = sock_no_listen,
992 .shutdown = sock_no_shutdown, 990 .shutdown = sock_no_shutdown,
993 .setsockopt = sock_common_setsockopt, 991 .setsockopt = sock_common_setsockopt,
diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig
index 32cae39cdff6..8108e97d4285 100644
--- a/net/ipv4/Kconfig
+++ b/net/ipv4/Kconfig
@@ -304,7 +304,7 @@ config NET_IPVTI
304 tristate "Virtual (secure) IP: tunneling" 304 tristate "Virtual (secure) IP: tunneling"
305 select INET_TUNNEL 305 select INET_TUNNEL
306 select NET_IP_TUNNEL 306 select NET_IP_TUNNEL
307 depends on INET_XFRM_MODE_TUNNEL 307 select XFRM
308 ---help--- 308 ---help---
309 Tunneling means encapsulating data of one protocol type within 309 Tunneling means encapsulating data of one protocol type within
310 another protocol and sending it over a channel that understands the 310 another protocol and sending it over a channel that understands the
@@ -396,33 +396,6 @@ config INET_TUNNEL
396 tristate 396 tristate
397 default n 397 default n
398 398
399config INET_XFRM_MODE_TRANSPORT
400 tristate "IP: IPsec transport mode"
401 default y
402 select XFRM
403 ---help---
404 Support for IPsec transport mode.
405
406 If unsure, say Y.
407
408config INET_XFRM_MODE_TUNNEL
409 tristate "IP: IPsec tunnel mode"
410 default y
411 select XFRM
412 ---help---
413 Support for IPsec tunnel mode.
414
415 If unsure, say Y.
416
417config INET_XFRM_MODE_BEET
418 tristate "IP: IPsec BEET mode"
419 default y
420 select XFRM
421 ---help---
422 Support for IPsec BEET mode.
423
424 If unsure, say Y.
425
426config INET_DIAG 399config INET_DIAG
427 tristate "INET: socket monitoring interface" 400 tristate "INET: socket monitoring interface"
428 default y 401 default y
diff --git a/net/ipv4/Makefile b/net/ipv4/Makefile
index 58629314eae9..000a61994c8f 100644
--- a/net/ipv4/Makefile
+++ b/net/ipv4/Makefile
@@ -37,10 +37,7 @@ obj-$(CONFIG_INET_ESP) += esp4.o
37obj-$(CONFIG_INET_ESP_OFFLOAD) += esp4_offload.o 37obj-$(CONFIG_INET_ESP_OFFLOAD) += esp4_offload.o
38obj-$(CONFIG_INET_IPCOMP) += ipcomp.o 38obj-$(CONFIG_INET_IPCOMP) += ipcomp.o
39obj-$(CONFIG_INET_XFRM_TUNNEL) += xfrm4_tunnel.o 39obj-$(CONFIG_INET_XFRM_TUNNEL) += xfrm4_tunnel.o
40obj-$(CONFIG_INET_XFRM_MODE_BEET) += xfrm4_mode_beet.o
41obj-$(CONFIG_INET_TUNNEL) += tunnel4.o 40obj-$(CONFIG_INET_TUNNEL) += tunnel4.o
42obj-$(CONFIG_INET_XFRM_MODE_TRANSPORT) += xfrm4_mode_transport.o
43obj-$(CONFIG_INET_XFRM_MODE_TUNNEL) += xfrm4_mode_tunnel.o
44obj-$(CONFIG_IP_PNP) += ipconfig.o 41obj-$(CONFIG_IP_PNP) += ipconfig.o
45obj-$(CONFIG_NETFILTER) += netfilter.o netfilter/ 42obj-$(CONFIG_NETFILTER) += netfilter.o netfilter/
46obj-$(CONFIG_INET_DIAG) += inet_diag.o 43obj-$(CONFIG_INET_DIAG) += inet_diag.o
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index eab3ebde981e..5183a2daba64 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -136,6 +136,10 @@ void inet_sock_destruct(struct sock *sk)
136 struct inet_sock *inet = inet_sk(sk); 136 struct inet_sock *inet = inet_sk(sk);
137 137
138 __skb_queue_purge(&sk->sk_receive_queue); 138 __skb_queue_purge(&sk->sk_receive_queue);
139 if (sk->sk_rx_skb_cache) {
140 __kfree_skb(sk->sk_rx_skb_cache);
141 sk->sk_rx_skb_cache = NULL;
142 }
139 __skb_queue_purge(&sk->sk_error_queue); 143 __skb_queue_purge(&sk->sk_error_queue);
140 144
141 sk_mem_reclaim(sk); 145 sk_mem_reclaim(sk);
@@ -156,7 +160,7 @@ void inet_sock_destruct(struct sock *sk)
156 WARN_ON(sk->sk_forward_alloc); 160 WARN_ON(sk->sk_forward_alloc);
157 161
158 kfree(rcu_dereference_protected(inet->inet_opt, 1)); 162 kfree(rcu_dereference_protected(inet->inet_opt, 1));
159 dst_release(rcu_dereference_check(sk->sk_dst_cache, 1)); 163 dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
160 dst_release(sk->sk_rx_dst); 164 dst_release(sk->sk_rx_dst);
161 sk_refcnt_debug_dec(sk); 165 sk_refcnt_debug_dec(sk);
162} 166}
@@ -911,12 +915,6 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
911 struct rtentry rt; 915 struct rtentry rt;
912 916
913 switch (cmd) { 917 switch (cmd) {
914 case SIOCGSTAMP:
915 err = sock_get_timestamp(sk, (struct timeval __user *)arg);
916 break;
917 case SIOCGSTAMPNS:
918 err = sock_get_timestampns(sk, (struct timespec __user *)arg);
919 break;
920 case SIOCADDRT: 918 case SIOCADDRT:
921 case SIOCDELRT: 919 case SIOCDELRT:
922 if (copy_from_user(&rt, p, sizeof(struct rtentry))) 920 if (copy_from_user(&rt, p, sizeof(struct rtentry)))
@@ -988,6 +986,7 @@ const struct proto_ops inet_stream_ops = {
988 .getname = inet_getname, 986 .getname = inet_getname,
989 .poll = tcp_poll, 987 .poll = tcp_poll,
990 .ioctl = inet_ioctl, 988 .ioctl = inet_ioctl,
989 .gettstamp = sock_gettstamp,
991 .listen = inet_listen, 990 .listen = inet_listen,
992 .shutdown = inet_shutdown, 991 .shutdown = inet_shutdown,
993 .setsockopt = sock_common_setsockopt, 992 .setsockopt = sock_common_setsockopt,
@@ -1023,6 +1022,7 @@ const struct proto_ops inet_dgram_ops = {
1023 .getname = inet_getname, 1022 .getname = inet_getname,
1024 .poll = udp_poll, 1023 .poll = udp_poll,
1025 .ioctl = inet_ioctl, 1024 .ioctl = inet_ioctl,
1025 .gettstamp = sock_gettstamp,
1026 .listen = sock_no_listen, 1026 .listen = sock_no_listen,
1027 .shutdown = inet_shutdown, 1027 .shutdown = inet_shutdown,
1028 .setsockopt = sock_common_setsockopt, 1028 .setsockopt = sock_common_setsockopt,
@@ -1055,6 +1055,7 @@ static const struct proto_ops inet_sockraw_ops = {
1055 .getname = inet_getname, 1055 .getname = inet_getname,
1056 .poll = datagram_poll, 1056 .poll = datagram_poll,
1057 .ioctl = inet_ioctl, 1057 .ioctl = inet_ioctl,
1058 .gettstamp = sock_gettstamp,
1058 .listen = sock_no_listen, 1059 .listen = sock_no_listen,
1059 .shutdown = inet_shutdown, 1060 .shutdown = inet_shutdown,
1060 .setsockopt = sock_common_setsockopt, 1061 .setsockopt = sock_common_setsockopt,
diff --git a/net/ipv4/bpfilter/sockopt.c b/net/ipv4/bpfilter/sockopt.c
index 1e976bb93d99..15427163a041 100644
--- a/net/ipv4/bpfilter/sockopt.c
+++ b/net/ipv4/bpfilter/sockopt.c
@@ -77,5 +77,4 @@ static int __init bpfilter_sockopt_init(void)
77 77
78 return 0; 78 return 0;
79} 79}
80 80device_initcall(bpfilter_sockopt_init);
81module_init(bpfilter_sockopt_init);
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index eb514f312e6f..701c5d113a34 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -621,8 +621,8 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
621 621
622 ASSERT_RTNL(); 622 ASSERT_RTNL();
623 623
624 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy, 624 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
625 extack); 625 ifa_ipv4_policy, extack);
626 if (err < 0) 626 if (err < 0)
627 goto errout; 627 goto errout;
628 628
@@ -793,8 +793,8 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
793 struct in_device *in_dev; 793 struct in_device *in_dev;
794 int err; 794 int err;
795 795
796 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy, 796 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
797 extack); 797 ifa_ipv4_policy, extack);
798 if (err < 0) 798 if (err < 0)
799 goto errout; 799 goto errout;
800 800
@@ -1689,8 +1689,8 @@ static int inet_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,
1689 fillargs->flags |= NLM_F_DUMP_FILTERED; 1689 fillargs->flags |= NLM_F_DUMP_FILTERED;
1690 } 1690 }
1691 1691
1692 err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFA_MAX, 1692 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*ifm), tb, IFA_MAX,
1693 ifa_ipv4_policy, extack); 1693 ifa_ipv4_policy, extack);
1694 if (err < 0) 1694 if (err < 0)
1695 return err; 1695 return err;
1696 1696
@@ -1906,7 +1906,8 @@ static int inet_validate_link_af(const struct net_device *dev,
1906 if (dev && !__in_dev_get_rcu(dev)) 1906 if (dev && !__in_dev_get_rcu(dev))
1907 return -EAFNOSUPPORT; 1907 return -EAFNOSUPPORT;
1908 1908
1909 err = nla_parse_nested(tb, IFLA_INET_MAX, nla, inet_af_policy, NULL); 1909 err = nla_parse_nested_deprecated(tb, IFLA_INET_MAX, nla,
1910 inet_af_policy, NULL);
1910 if (err < 0) 1911 if (err < 0)
1911 return err; 1912 return err;
1912 1913
@@ -1934,7 +1935,7 @@ static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla)
1934 if (!in_dev) 1935 if (!in_dev)
1935 return -EAFNOSUPPORT; 1936 return -EAFNOSUPPORT;
1936 1937
1937 if (nla_parse_nested(tb, IFLA_INET_MAX, nla, NULL, NULL) < 0) 1938 if (nla_parse_nested_deprecated(tb, IFLA_INET_MAX, nla, NULL, NULL) < 0)
1938 BUG(); 1939 BUG();
1939 1940
1940 if (tb[IFLA_INET_CONF]) { 1941 if (tb[IFLA_INET_CONF]) {
@@ -2076,11 +2077,13 @@ static int inet_netconf_valid_get_req(struct sk_buff *skb,
2076 } 2077 }
2077 2078
2078 if (!netlink_strict_get_check(skb)) 2079 if (!netlink_strict_get_check(skb))
2079 return nlmsg_parse(nlh, sizeof(struct netconfmsg), tb, 2080 return nlmsg_parse_deprecated(nlh, sizeof(struct netconfmsg),
2080 NETCONFA_MAX, devconf_ipv4_policy, extack); 2081 tb, NETCONFA_MAX,
2082 devconf_ipv4_policy, extack);
2081 2083
2082 err = nlmsg_parse_strict(nlh, sizeof(struct netconfmsg), tb, 2084 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct netconfmsg),
2083 NETCONFA_MAX, devconf_ipv4_policy, extack); 2085 tb, NETCONFA_MAX,
2086 devconf_ipv4_policy, extack);
2084 if (err) 2087 if (err)
2085 return err; 2088 return err;
2086 2089
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 10e809b296ec..fb065a8937ea 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -226,7 +226,7 @@ static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto)
226 tail[plen - 1] = proto; 226 tail[plen - 1] = proto;
227} 227}
228 228
229static void esp_output_udp_encap(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp) 229static int esp_output_udp_encap(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp)
230{ 230{
231 int encap_type; 231 int encap_type;
232 struct udphdr *uh; 232 struct udphdr *uh;
@@ -234,6 +234,7 @@ static void esp_output_udp_encap(struct xfrm_state *x, struct sk_buff *skb, stru
234 __be16 sport, dport; 234 __be16 sport, dport;
235 struct xfrm_encap_tmpl *encap = x->encap; 235 struct xfrm_encap_tmpl *encap = x->encap;
236 struct ip_esp_hdr *esph = esp->esph; 236 struct ip_esp_hdr *esph = esp->esph;
237 unsigned int len;
237 238
238 spin_lock_bh(&x->lock); 239 spin_lock_bh(&x->lock);
239 sport = encap->encap_sport; 240 sport = encap->encap_sport;
@@ -241,11 +242,14 @@ static void esp_output_udp_encap(struct xfrm_state *x, struct sk_buff *skb, stru
241 encap_type = encap->encap_type; 242 encap_type = encap->encap_type;
242 spin_unlock_bh(&x->lock); 243 spin_unlock_bh(&x->lock);
243 244
245 len = skb->len + esp->tailen - skb_transport_offset(skb);
246 if (len + sizeof(struct iphdr) >= IP_MAX_MTU)
247 return -EMSGSIZE;
248
244 uh = (struct udphdr *)esph; 249 uh = (struct udphdr *)esph;
245 uh->source = sport; 250 uh->source = sport;
246 uh->dest = dport; 251 uh->dest = dport;
247 uh->len = htons(skb->len + esp->tailen 252 uh->len = htons(len);
248 - skb_transport_offset(skb));
249 uh->check = 0; 253 uh->check = 0;
250 254
251 switch (encap_type) { 255 switch (encap_type) {
@@ -262,6 +266,8 @@ static void esp_output_udp_encap(struct xfrm_state *x, struct sk_buff *skb, stru
262 266
263 *skb_mac_header(skb) = IPPROTO_UDP; 267 *skb_mac_header(skb) = IPPROTO_UDP;
264 esp->esph = esph; 268 esp->esph = esph;
269
270 return 0;
265} 271}
266 272
267int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp) 273int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp)
@@ -275,8 +281,12 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
275 int tailen = esp->tailen; 281 int tailen = esp->tailen;
276 282
277 /* this is non-NULL only with UDP Encapsulation */ 283 /* this is non-NULL only with UDP Encapsulation */
278 if (x->encap) 284 if (x->encap) {
279 esp_output_udp_encap(x, skb, esp); 285 int err = esp_output_udp_encap(x, skb, esp);
286
287 if (err < 0)
288 return err;
289 }
280 290
281 if (!skb_cloned(skb)) { 291 if (!skb_cloned(skb)) {
282 if (tailen <= skb_tailroom(skb)) { 292 if (tailen <= skb_tailroom(skb)) {
diff --git a/net/ipv4/esp4_offload.c b/net/ipv4/esp4_offload.c
index 8756e0e790d2..8edcfa66d1e5 100644
--- a/net/ipv4/esp4_offload.c
+++ b/net/ipv4/esp4_offload.c
@@ -52,13 +52,13 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head,
52 goto out; 52 goto out;
53 53
54 if (sp->len == XFRM_MAX_DEPTH) 54 if (sp->len == XFRM_MAX_DEPTH)
55 goto out; 55 goto out_reset;
56 56
57 x = xfrm_state_lookup(dev_net(skb->dev), skb->mark, 57 x = xfrm_state_lookup(dev_net(skb->dev), skb->mark,
58 (xfrm_address_t *)&ip_hdr(skb)->daddr, 58 (xfrm_address_t *)&ip_hdr(skb)->daddr,
59 spi, IPPROTO_ESP, AF_INET); 59 spi, IPPROTO_ESP, AF_INET);
60 if (!x) 60 if (!x)
61 goto out; 61 goto out_reset;
62 62
63 sp->xvec[sp->len++] = x; 63 sp->xvec[sp->len++] = x;
64 sp->olen++; 64 sp->olen++;
@@ -66,7 +66,7 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head,
66 xo = xfrm_offload(skb); 66 xo = xfrm_offload(skb);
67 if (!xo) { 67 if (!xo) {
68 xfrm_state_put(x); 68 xfrm_state_put(x);
69 goto out; 69 goto out_reset;
70 } 70 }
71 } 71 }
72 72
@@ -82,6 +82,8 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head,
82 xfrm_input(skb, IPPROTO_ESP, spi, -2); 82 xfrm_input(skb, IPPROTO_ESP, spi, -2);
83 83
84 return ERR_PTR(-EINPROGRESS); 84 return ERR_PTR(-EINPROGRESS);
85out_reset:
86 secpath_reset(skb);
85out: 87out:
86 skb_push(skb, offset); 88 skb_push(skb, offset);
87 NAPI_GRO_CB(skb)->same_flow = 0; 89 NAPI_GRO_CB(skb)->same_flow = 0;
@@ -107,6 +109,44 @@ static void esp4_gso_encap(struct xfrm_state *x, struct sk_buff *skb)
107 xo->proto = proto; 109 xo->proto = proto;
108} 110}
109 111
112static struct sk_buff *xfrm4_tunnel_gso_segment(struct xfrm_state *x,
113 struct sk_buff *skb,
114 netdev_features_t features)
115{
116 __skb_push(skb, skb->mac_len);
117 return skb_mac_gso_segment(skb, features);
118}
119
120static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
121 struct sk_buff *skb,
122 netdev_features_t features)
123{
124 const struct net_offload *ops;
125 struct sk_buff *segs = ERR_PTR(-EINVAL);
126 struct xfrm_offload *xo = xfrm_offload(skb);
127
128 skb->transport_header += x->props.header_len;
129 ops = rcu_dereference(inet_offloads[xo->proto]);
130 if (likely(ops && ops->callbacks.gso_segment))
131 segs = ops->callbacks.gso_segment(skb, features);
132
133 return segs;
134}
135
136static struct sk_buff *xfrm4_outer_mode_gso_segment(struct xfrm_state *x,
137 struct sk_buff *skb,
138 netdev_features_t features)
139{
140 switch (x->outer_mode.encap) {
141 case XFRM_MODE_TUNNEL:
142 return xfrm4_tunnel_gso_segment(x, skb, features);
143 case XFRM_MODE_TRANSPORT:
144 return xfrm4_transport_gso_segment(x, skb, features);
145 }
146
147 return ERR_PTR(-EOPNOTSUPP);
148}
149
110static struct sk_buff *esp4_gso_segment(struct sk_buff *skb, 150static struct sk_buff *esp4_gso_segment(struct sk_buff *skb,
111 netdev_features_t features) 151 netdev_features_t features)
112{ 152{
@@ -138,14 +178,16 @@ static struct sk_buff *esp4_gso_segment(struct sk_buff *skb,
138 178
139 skb->encap_hdr_csum = 1; 179 skb->encap_hdr_csum = 1;
140 180
141 if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev) 181 if ((!(skb->dev->gso_partial_features & NETIF_F_HW_ESP) &&
182 !(features & NETIF_F_HW_ESP)) || x->xso.dev != skb->dev)
142 esp_features = features & ~(NETIF_F_SG | NETIF_F_CSUM_MASK); 183 esp_features = features & ~(NETIF_F_SG | NETIF_F_CSUM_MASK);
143 else if (!(features & NETIF_F_HW_ESP_TX_CSUM)) 184 else if (!(features & NETIF_F_HW_ESP_TX_CSUM) &&
185 !(skb->dev->gso_partial_features & NETIF_F_HW_ESP_TX_CSUM))
144 esp_features = features & ~NETIF_F_CSUM_MASK; 186 esp_features = features & ~NETIF_F_CSUM_MASK;
145 187
146 xo->flags |= XFRM_GSO_SEGMENT; 188 xo->flags |= XFRM_GSO_SEGMENT;
147 189
148 return x->outer_mode->gso_segment(x, skb, esp_features); 190 return xfrm4_outer_mode_gso_segment(x, skb, esp_features);
149} 191}
150 192
151static int esp_input_tail(struct xfrm_state *x, struct sk_buff *skb) 193static int esp_input_tail(struct xfrm_state *x, struct sk_buff *skb)
@@ -181,7 +223,9 @@ static int esp_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features_
181 if (!xo) 223 if (!xo)
182 return -EINVAL; 224 return -EINVAL;
183 225
184 if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev) { 226 if ((!(features & NETIF_F_HW_ESP) &&
227 !(skb->dev->gso_partial_features & NETIF_F_HW_ESP)) ||
228 x->xso.dev != skb->dev) {
185 xo->flags |= CRYPTO_FALLBACK; 229 xo->flags |= CRYPTO_FALLBACK;
186 hw_offload = false; 230 hw_offload = false;
187 } 231 }
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index ed14ec245584..b298255f6fdb 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -307,7 +307,7 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)
307 .flowi4_mark = vmark ? skb->mark : 0, 307 .flowi4_mark = vmark ? skb->mark : 0,
308 }; 308 };
309 if (!fib_lookup(net, &fl4, &res, 0)) 309 if (!fib_lookup(net, &fl4, &res, 0))
310 return FIB_RES_PREFSRC(net, res); 310 return fib_result_prefsrc(net, &res);
311 } else { 311 } else {
312 scope = RT_SCOPE_LINK; 312 scope = RT_SCOPE_LINK;
313 } 313 }
@@ -324,16 +324,16 @@ bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev)
324 for (ret = 0; ret < fi->fib_nhs; ret++) { 324 for (ret = 0; ret < fi->fib_nhs; ret++) {
325 struct fib_nh *nh = &fi->fib_nh[ret]; 325 struct fib_nh *nh = &fi->fib_nh[ret];
326 326
327 if (nh->nh_dev == dev) { 327 if (nh->fib_nh_dev == dev) {
328 dev_match = true; 328 dev_match = true;
329 break; 329 break;
330 } else if (l3mdev_master_ifindex_rcu(nh->nh_dev) == dev->ifindex) { 330 } else if (l3mdev_master_ifindex_rcu(nh->fib_nh_dev) == dev->ifindex) {
331 dev_match = true; 331 dev_match = true;
332 break; 332 break;
333 } 333 }
334 } 334 }
335#else 335#else
336 if (fi->fib_nh[0].nh_dev == dev) 336 if (fi->fib_nh[0].fib_nh_dev == dev)
337 dev_match = true; 337 dev_match = true;
338#endif 338#endif
339 339
@@ -390,7 +390,7 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
390 390
391 dev_match = fib_info_nh_uses_dev(res.fi, dev); 391 dev_match = fib_info_nh_uses_dev(res.fi, dev);
392 if (dev_match) { 392 if (dev_match) {
393 ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST; 393 ret = FIB_RES_NHC(res)->nhc_scope >= RT_SCOPE_HOST;
394 return ret; 394 return ret;
395 } 395 }
396 if (no_addr) 396 if (no_addr)
@@ -402,7 +402,7 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
402 ret = 0; 402 ret = 0;
403 if (fib_lookup(net, &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE) == 0) { 403 if (fib_lookup(net, &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE) == 0) {
404 if (res.type == RTN_UNICAST) 404 if (res.type == RTN_UNICAST)
405 ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST; 405 ret = FIB_RES_NHC(res)->nhc_scope >= RT_SCOPE_HOST;
406 } 406 }
407 return ret; 407 return ret;
408 408
@@ -558,7 +558,8 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
558 if (rt->rt_gateway.sa_family == AF_INET && addr) { 558 if (rt->rt_gateway.sa_family == AF_INET && addr) {
559 unsigned int addr_type; 559 unsigned int addr_type;
560 560
561 cfg->fc_gw = addr; 561 cfg->fc_gw4 = addr;
562 cfg->fc_gw_family = AF_INET;
562 addr_type = inet_addr_type_table(net, addr, cfg->fc_table); 563 addr_type = inet_addr_type_table(net, addr, cfg->fc_table);
563 if (rt->rt_flags & RTF_GATEWAY && 564 if (rt->rt_flags & RTF_GATEWAY &&
564 addr_type == RTN_UNICAST) 565 addr_type == RTN_UNICAST)
@@ -568,7 +569,7 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
568 if (cmd == SIOCDELRT) 569 if (cmd == SIOCDELRT)
569 return 0; 570 return 0;
570 571
571 if (rt->rt_flags & RTF_GATEWAY && !cfg->fc_gw) 572 if (rt->rt_flags & RTF_GATEWAY && !cfg->fc_gw_family)
572 return -EINVAL; 573 return -EINVAL;
573 574
574 if (cfg->fc_scope == RT_SCOPE_NOWHERE) 575 if (cfg->fc_scope == RT_SCOPE_NOWHERE)
@@ -664,16 +665,61 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = {
664 [RTA_DPORT] = { .type = NLA_U16 }, 665 [RTA_DPORT] = { .type = NLA_U16 },
665}; 666};
666 667
668int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla,
669 struct netlink_ext_ack *extack)
670{
671 struct rtvia *via;
672 int alen;
673
674 if (nla_len(nla) < offsetof(struct rtvia, rtvia_addr)) {
675 NL_SET_ERR_MSG(extack, "Invalid attribute length for RTA_VIA");
676 return -EINVAL;
677 }
678
679 via = nla_data(nla);
680 alen = nla_len(nla) - offsetof(struct rtvia, rtvia_addr);
681
682 switch (via->rtvia_family) {
683 case AF_INET:
684 if (alen != sizeof(__be32)) {
685 NL_SET_ERR_MSG(extack, "Invalid IPv4 address in RTA_VIA");
686 return -EINVAL;
687 }
688 cfg->fc_gw_family = AF_INET;
689 cfg->fc_gw4 = *((__be32 *)via->rtvia_addr);
690 break;
691 case AF_INET6:
692#ifdef CONFIG_IPV6
693 if (alen != sizeof(struct in6_addr)) {
694 NL_SET_ERR_MSG(extack, "Invalid IPv6 address in RTA_VIA");
695 return -EINVAL;
696 }
697 cfg->fc_gw_family = AF_INET6;
698 cfg->fc_gw6 = *((struct in6_addr *)via->rtvia_addr);
699#else
700 NL_SET_ERR_MSG(extack, "IPv6 support not enabled in kernel");
701 return -EINVAL;
702#endif
703 break;
704 default:
705 NL_SET_ERR_MSG(extack, "Unsupported address family in RTA_VIA");
706 return -EINVAL;
707 }
708
709 return 0;
710}
711
667static int rtm_to_fib_config(struct net *net, struct sk_buff *skb, 712static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
668 struct nlmsghdr *nlh, struct fib_config *cfg, 713 struct nlmsghdr *nlh, struct fib_config *cfg,
669 struct netlink_ext_ack *extack) 714 struct netlink_ext_ack *extack)
670{ 715{
716 bool has_gw = false, has_via = false;
671 struct nlattr *attr; 717 struct nlattr *attr;
672 int err, remaining; 718 int err, remaining;
673 struct rtmsg *rtm; 719 struct rtmsg *rtm;
674 720
675 err = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipv4_policy, 721 err = nlmsg_validate_deprecated(nlh, sizeof(*rtm), RTA_MAX,
676 extack); 722 rtm_ipv4_policy, extack);
677 if (err < 0) 723 if (err < 0)
678 goto errout; 724 goto errout;
679 725
@@ -708,12 +754,17 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
708 cfg->fc_oif = nla_get_u32(attr); 754 cfg->fc_oif = nla_get_u32(attr);
709 break; 755 break;
710 case RTA_GATEWAY: 756 case RTA_GATEWAY:
711 cfg->fc_gw = nla_get_be32(attr); 757 has_gw = true;
758 cfg->fc_gw4 = nla_get_be32(attr);
759 if (cfg->fc_gw4)
760 cfg->fc_gw_family = AF_INET;
712 break; 761 break;
713 case RTA_VIA: 762 case RTA_VIA:
714 NL_SET_ERR_MSG(extack, "IPv4 does not support RTA_VIA attribute"); 763 has_via = true;
715 err = -EINVAL; 764 err = fib_gw_from_via(cfg, attr, extack);
716 goto errout; 765 if (err)
766 goto errout;
767 break;
717 case RTA_PRIORITY: 768 case RTA_PRIORITY:
718 cfg->fc_priority = nla_get_u32(attr); 769 cfg->fc_priority = nla_get_u32(attr);
719 break; 770 break;
@@ -752,6 +803,12 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
752 } 803 }
753 } 804 }
754 805
806 if (has_gw && has_via) {
807 NL_SET_ERR_MSG(extack,
808 "Nexthop configuration can not contain both GATEWAY and VIA");
809 goto errout;
810 }
811
755 return 0; 812 return 0;
756errout: 813errout:
757 return err; 814 return err;
@@ -839,8 +896,8 @@ int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
839 filter->rt_type = rtm->rtm_type; 896 filter->rt_type = rtm->rtm_type;
840 filter->table_id = rtm->rtm_table; 897 filter->table_id = rtm->rtm_table;
841 898
842 err = nlmsg_parse_strict(nlh, sizeof(*rtm), tb, RTA_MAX, 899 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX,
843 rtm_ipv4_policy, extack); 900 rtm_ipv4_policy, extack);
844 if (err < 0) 901 if (err < 0)
845 return err; 902 return err;
846 903
diff --git a/net/ipv4/fib_lookup.h b/net/ipv4/fib_lookup.h
index e6ff282bb7f4..7945f0534db7 100644
--- a/net/ipv4/fib_lookup.h
+++ b/net/ipv4/fib_lookup.h
@@ -45,6 +45,7 @@ static inline void fib_result_assign(struct fib_result *res,
45{ 45{
46 /* we used to play games with refcounts, but we now use RCU */ 46 /* we used to play games with refcounts, but we now use RCU */
47 res->fi = fi; 47 res->fi = fi;
48 res->nhc = fib_info_nhc(fi, 0);
48} 49}
49 50
50struct fib_prop { 51struct fib_prop {
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 8e185b5a2bf6..d3da6a10f86f 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -41,10 +41,12 @@
41#include <net/tcp.h> 41#include <net/tcp.h>
42#include <net/sock.h> 42#include <net/sock.h>
43#include <net/ip_fib.h> 43#include <net/ip_fib.h>
44#include <net/ip6_fib.h>
44#include <net/netlink.h> 45#include <net/netlink.h>
45#include <net/nexthop.h> 46#include <net/rtnh.h>
46#include <net/lwtunnel.h> 47#include <net/lwtunnel.h>
47#include <net/fib_notifier.h> 48#include <net/fib_notifier.h>
49#include <net/addrconf.h>
48 50
49#include "fib_lookup.h" 51#include "fib_lookup.h"
50 52
@@ -157,12 +159,12 @@ static void rt_fibinfo_free(struct rtable __rcu **rtp)
157 dst_release_immediate(&rt->dst); 159 dst_release_immediate(&rt->dst);
158} 160}
159 161
160static void free_nh_exceptions(struct fib_nh *nh) 162static void free_nh_exceptions(struct fib_nh_common *nhc)
161{ 163{
162 struct fnhe_hash_bucket *hash; 164 struct fnhe_hash_bucket *hash;
163 int i; 165 int i;
164 166
165 hash = rcu_dereference_protected(nh->nh_exceptions, 1); 167 hash = rcu_dereference_protected(nhc->nhc_exceptions, 1);
166 if (!hash) 168 if (!hash)
167 return; 169 return;
168 for (i = 0; i < FNHE_HASH_SIZE; i++) { 170 for (i = 0; i < FNHE_HASH_SIZE; i++) {
@@ -204,18 +206,34 @@ static void rt_fibinfo_free_cpus(struct rtable __rcu * __percpu *rtp)
204 free_percpu(rtp); 206 free_percpu(rtp);
205} 207}
206 208
209void fib_nh_common_release(struct fib_nh_common *nhc)
210{
211 if (nhc->nhc_dev)
212 dev_put(nhc->nhc_dev);
213
214 lwtstate_put(nhc->nhc_lwtstate);
215 rt_fibinfo_free_cpus(nhc->nhc_pcpu_rth_output);
216 rt_fibinfo_free(&nhc->nhc_rth_input);
217 free_nh_exceptions(nhc);
218}
219EXPORT_SYMBOL_GPL(fib_nh_common_release);
220
221void fib_nh_release(struct net *net, struct fib_nh *fib_nh)
222{
223#ifdef CONFIG_IP_ROUTE_CLASSID
224 if (fib_nh->nh_tclassid)
225 net->ipv4.fib_num_tclassid_users--;
226#endif
227 fib_nh_common_release(&fib_nh->nh_common);
228}
229
207/* Release a nexthop info record */ 230/* Release a nexthop info record */
208static void free_fib_info_rcu(struct rcu_head *head) 231static void free_fib_info_rcu(struct rcu_head *head)
209{ 232{
210 struct fib_info *fi = container_of(head, struct fib_info, rcu); 233 struct fib_info *fi = container_of(head, struct fib_info, rcu);
211 234
212 change_nexthops(fi) { 235 change_nexthops(fi) {
213 if (nexthop_nh->nh_dev) 236 fib_nh_release(fi->fib_net, nexthop_nh);
214 dev_put(nexthop_nh->nh_dev);
215 lwtstate_put(nexthop_nh->nh_lwtstate);
216 free_nh_exceptions(nexthop_nh);
217 rt_fibinfo_free_cpus(nexthop_nh->nh_pcpu_rth_output);
218 rt_fibinfo_free(&nexthop_nh->nh_rth_input);
219 } endfor_nexthops(fi); 237 } endfor_nexthops(fi);
220 238
221 ip_fib_metrics_put(fi->fib_metrics); 239 ip_fib_metrics_put(fi->fib_metrics);
@@ -230,12 +248,7 @@ void free_fib_info(struct fib_info *fi)
230 return; 248 return;
231 } 249 }
232 fib_info_cnt--; 250 fib_info_cnt--;
233#ifdef CONFIG_IP_ROUTE_CLASSID 251
234 change_nexthops(fi) {
235 if (nexthop_nh->nh_tclassid)
236 fi->fib_net->ipv4.fib_num_tclassid_users--;
237 } endfor_nexthops(fi);
238#endif
239 call_rcu(&fi->rcu, free_fib_info_rcu); 252 call_rcu(&fi->rcu, free_fib_info_rcu);
240} 253}
241EXPORT_SYMBOL_GPL(free_fib_info); 254EXPORT_SYMBOL_GPL(free_fib_info);
@@ -248,7 +261,7 @@ void fib_release_info(struct fib_info *fi)
248 if (fi->fib_prefsrc) 261 if (fi->fib_prefsrc)
249 hlist_del(&fi->fib_lhash); 262 hlist_del(&fi->fib_lhash);
250 change_nexthops(fi) { 263 change_nexthops(fi) {
251 if (!nexthop_nh->nh_dev) 264 if (!nexthop_nh->fib_nh_dev)
252 continue; 265 continue;
253 hlist_del(&nexthop_nh->nh_hash); 266 hlist_del(&nexthop_nh->nh_hash);
254 } endfor_nexthops(fi) 267 } endfor_nexthops(fi)
@@ -263,18 +276,27 @@ static inline int nh_comp(const struct fib_info *fi, const struct fib_info *ofi)
263 const struct fib_nh *onh = ofi->fib_nh; 276 const struct fib_nh *onh = ofi->fib_nh;
264 277
265 for_nexthops(fi) { 278 for_nexthops(fi) {
266 if (nh->nh_oif != onh->nh_oif || 279 if (nh->fib_nh_oif != onh->fib_nh_oif ||
267 nh->nh_gw != onh->nh_gw || 280 nh->fib_nh_gw_family != onh->fib_nh_gw_family ||
268 nh->nh_scope != onh->nh_scope || 281 nh->fib_nh_scope != onh->fib_nh_scope ||
269#ifdef CONFIG_IP_ROUTE_MULTIPATH 282#ifdef CONFIG_IP_ROUTE_MULTIPATH
270 nh->nh_weight != onh->nh_weight || 283 nh->fib_nh_weight != onh->fib_nh_weight ||
271#endif 284#endif
272#ifdef CONFIG_IP_ROUTE_CLASSID 285#ifdef CONFIG_IP_ROUTE_CLASSID
273 nh->nh_tclassid != onh->nh_tclassid || 286 nh->nh_tclassid != onh->nh_tclassid ||
274#endif 287#endif
275 lwtunnel_cmp_encap(nh->nh_lwtstate, onh->nh_lwtstate) || 288 lwtunnel_cmp_encap(nh->fib_nh_lws, onh->fib_nh_lws) ||
276 ((nh->nh_flags ^ onh->nh_flags) & ~RTNH_COMPARE_MASK)) 289 ((nh->fib_nh_flags ^ onh->fib_nh_flags) & ~RTNH_COMPARE_MASK))
290 return -1;
291
292 if (nh->fib_nh_gw_family == AF_INET &&
293 nh->fib_nh_gw4 != onh->fib_nh_gw4)
277 return -1; 294 return -1;
295
296 if (nh->fib_nh_gw_family == AF_INET6 &&
297 ipv6_addr_cmp(&nh->fib_nh_gw6, &onh->fib_nh_gw6))
298 return -1;
299
278 onh++; 300 onh++;
279 } endfor_nexthops(fi); 301 } endfor_nexthops(fi);
280 return 0; 302 return 0;
@@ -298,7 +320,7 @@ static inline unsigned int fib_info_hashfn(const struct fib_info *fi)
298 val ^= (__force u32)fi->fib_prefsrc; 320 val ^= (__force u32)fi->fib_prefsrc;
299 val ^= fi->fib_priority; 321 val ^= fi->fib_priority;
300 for_nexthops(fi) { 322 for_nexthops(fi) {
301 val ^= fib_devindex_hashfn(nh->nh_oif); 323 val ^= fib_devindex_hashfn(nh->fib_nh_oif);
302 } endfor_nexthops(fi) 324 } endfor_nexthops(fi)
303 325
304 return (val ^ (val >> 7) ^ (val >> 12)) & mask; 326 return (val ^ (val >> 7) ^ (val >> 12)) & mask;
@@ -347,9 +369,9 @@ int ip_fib_check_default(__be32 gw, struct net_device *dev)
347 hash = fib_devindex_hashfn(dev->ifindex); 369 hash = fib_devindex_hashfn(dev->ifindex);
348 head = &fib_info_devhash[hash]; 370 head = &fib_info_devhash[hash];
349 hlist_for_each_entry(nh, head, nh_hash) { 371 hlist_for_each_entry(nh, head, nh_hash) {
350 if (nh->nh_dev == dev && 372 if (nh->fib_nh_dev == dev &&
351 nh->nh_gw == gw && 373 nh->fib_nh_gw4 == gw &&
352 !(nh->nh_flags & RTNH_F_DEAD)) { 374 !(nh->fib_nh_flags & RTNH_F_DEAD)) {
353 spin_unlock(&fib_info_lock); 375 spin_unlock(&fib_info_lock);
354 return 0; 376 return 0;
355 } 377 }
@@ -384,10 +406,10 @@ static inline size_t fib_nlmsg_size(struct fib_info *fi)
384 406
385 /* grab encap info */ 407 /* grab encap info */
386 for_nexthops(fi) { 408 for_nexthops(fi) {
387 if (nh->nh_lwtstate) { 409 if (nh->fib_nh_lws) {
388 /* RTA_ENCAP_TYPE */ 410 /* RTA_ENCAP_TYPE */
389 nh_encapsize += lwtunnel_get_encap_size( 411 nh_encapsize += lwtunnel_get_encap_size(
390 nh->nh_lwtstate); 412 nh->fib_nh_lws);
391 /* RTA_ENCAP */ 413 /* RTA_ENCAP */
392 nh_encapsize += nla_total_size(2); 414 nh_encapsize += nla_total_size(2);
393 } 415 }
@@ -435,10 +457,18 @@ static int fib_detect_death(struct fib_info *fi, int order,
435 struct fib_info **last_resort, int *last_idx, 457 struct fib_info **last_resort, int *last_idx,
436 int dflt) 458 int dflt)
437{ 459{
460 const struct fib_nh_common *nhc = fib_info_nhc(fi, 0);
438 struct neighbour *n; 461 struct neighbour *n;
439 int state = NUD_NONE; 462 int state = NUD_NONE;
440 463
441 n = neigh_lookup(&arp_tbl, &fi->fib_nh[0].nh_gw, fi->fib_dev); 464 if (likely(nhc->nhc_gw_family == AF_INET))
465 n = neigh_lookup(&arp_tbl, &nhc->nhc_gw.ipv4, nhc->nhc_dev);
466 else if (nhc->nhc_gw_family == AF_INET6)
467 n = neigh_lookup(ipv6_stub->nd_tbl, &nhc->nhc_gw.ipv6,
468 nhc->nhc_dev);
469 else
470 n = NULL;
471
442 if (n) { 472 if (n) {
443 state = n->nud_state; 473 state = n->nud_state;
444 neigh_release(n); 474 neigh_release(n);
@@ -457,6 +487,75 @@ static int fib_detect_death(struct fib_info *fi, int order,
457 return 1; 487 return 1;
458} 488}
459 489
490int fib_nh_common_init(struct fib_nh_common *nhc, struct nlattr *encap,
491 u16 encap_type, void *cfg, gfp_t gfp_flags,
492 struct netlink_ext_ack *extack)
493{
494 int err;
495
496 nhc->nhc_pcpu_rth_output = alloc_percpu_gfp(struct rtable __rcu *,
497 gfp_flags);
498 if (!nhc->nhc_pcpu_rth_output)
499 return -ENOMEM;
500
501 if (encap) {
502 struct lwtunnel_state *lwtstate;
503
504 if (encap_type == LWTUNNEL_ENCAP_NONE) {
505 NL_SET_ERR_MSG(extack, "LWT encap type not specified");
506 err = -EINVAL;
507 goto lwt_failure;
508 }
509 err = lwtunnel_build_state(encap_type, encap, nhc->nhc_family,
510 cfg, &lwtstate, extack);
511 if (err)
512 goto lwt_failure;
513
514 nhc->nhc_lwtstate = lwtstate_get(lwtstate);
515 }
516
517 return 0;
518
519lwt_failure:
520 rt_fibinfo_free_cpus(nhc->nhc_pcpu_rth_output);
521 nhc->nhc_pcpu_rth_output = NULL;
522 return err;
523}
524EXPORT_SYMBOL_GPL(fib_nh_common_init);
525
526int fib_nh_init(struct net *net, struct fib_nh *nh,
527 struct fib_config *cfg, int nh_weight,
528 struct netlink_ext_ack *extack)
529{
530 int err;
531
532 nh->fib_nh_family = AF_INET;
533
534 err = fib_nh_common_init(&nh->nh_common, cfg->fc_encap,
535 cfg->fc_encap_type, cfg, GFP_KERNEL, extack);
536 if (err)
537 return err;
538
539 nh->fib_nh_oif = cfg->fc_oif;
540 nh->fib_nh_gw_family = cfg->fc_gw_family;
541 if (cfg->fc_gw_family == AF_INET)
542 nh->fib_nh_gw4 = cfg->fc_gw4;
543 else if (cfg->fc_gw_family == AF_INET6)
544 nh->fib_nh_gw6 = cfg->fc_gw6;
545
546 nh->fib_nh_flags = cfg->fc_flags;
547
548#ifdef CONFIG_IP_ROUTE_CLASSID
549 nh->nh_tclassid = cfg->fc_flow;
550 if (nh->nh_tclassid)
551 net->ipv4.fib_num_tclassid_users++;
552#endif
553#ifdef CONFIG_IP_ROUTE_MULTIPATH
554 nh->fib_nh_weight = nh_weight;
555#endif
556 return 0;
557}
558
460#ifdef CONFIG_IP_ROUTE_MULTIPATH 559#ifdef CONFIG_IP_ROUTE_MULTIPATH
461 560
462static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining, 561static int fib_count_nexthops(struct rtnexthop *rtnh, int remaining,
@@ -483,11 +582,15 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
483 int remaining, struct fib_config *cfg, 582 int remaining, struct fib_config *cfg,
484 struct netlink_ext_ack *extack) 583 struct netlink_ext_ack *extack)
485{ 584{
585 struct net *net = fi->fib_net;
586 struct fib_config fib_cfg;
486 int ret; 587 int ret;
487 588
488 change_nexthops(fi) { 589 change_nexthops(fi) {
489 int attrlen; 590 int attrlen;
490 591
592 memset(&fib_cfg, 0, sizeof(fib_cfg));
593
491 if (!rtnh_ok(rtnh, remaining)) { 594 if (!rtnh_ok(rtnh, remaining)) {
492 NL_SET_ERR_MSG(extack, 595 NL_SET_ERR_MSG(extack,
493 "Invalid nexthop configuration - extra data after nexthop"); 596 "Invalid nexthop configuration - extra data after nexthop");
@@ -500,56 +603,73 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
500 return -EINVAL; 603 return -EINVAL;
501 } 604 }
502 605
503 nexthop_nh->nh_flags = 606 fib_cfg.fc_flags = (cfg->fc_flags & ~0xFF) | rtnh->rtnh_flags;
504 (cfg->fc_flags & ~0xFF) | rtnh->rtnh_flags; 607 fib_cfg.fc_oif = rtnh->rtnh_ifindex;
505 nexthop_nh->nh_oif = rtnh->rtnh_ifindex;
506 nexthop_nh->nh_weight = rtnh->rtnh_hops + 1;
507 608
508 attrlen = rtnh_attrlen(rtnh); 609 attrlen = rtnh_attrlen(rtnh);
509 if (attrlen > 0) { 610 if (attrlen > 0) {
510 struct nlattr *nla, *attrs = rtnh_attrs(rtnh); 611 struct nlattr *nla, *nlav, *attrs = rtnh_attrs(rtnh);
511 612
512 nla = nla_find(attrs, attrlen, RTA_GATEWAY); 613 nla = nla_find(attrs, attrlen, RTA_GATEWAY);
513 nexthop_nh->nh_gw = nla ? nla_get_in_addr(nla) : 0; 614 nlav = nla_find(attrs, attrlen, RTA_VIA);
514#ifdef CONFIG_IP_ROUTE_CLASSID 615 if (nla && nlav) {
515 nla = nla_find(attrs, attrlen, RTA_FLOW); 616 NL_SET_ERR_MSG(extack,
516 nexthop_nh->nh_tclassid = nla ? nla_get_u32(nla) : 0; 617 "Nexthop configuration can not contain both GATEWAY and VIA");
517 if (nexthop_nh->nh_tclassid) 618 return -EINVAL;
518 fi->fib_net->ipv4.fib_num_tclassid_users++; 619 }
519#endif
520 nla = nla_find(attrs, attrlen, RTA_ENCAP);
521 if (nla) { 620 if (nla) {
522 struct lwtunnel_state *lwtstate; 621 fib_cfg.fc_gw4 = nla_get_in_addr(nla);
523 struct nlattr *nla_entype; 622 if (fib_cfg.fc_gw4)
524 623 fib_cfg.fc_gw_family = AF_INET;
525 nla_entype = nla_find(attrs, attrlen, 624 } else if (nlav) {
526 RTA_ENCAP_TYPE); 625 ret = fib_gw_from_via(&fib_cfg, nlav, extack);
527 if (!nla_entype) {
528 NL_SET_BAD_ATTR(extack, nla);
529 NL_SET_ERR_MSG(extack,
530 "Encap type is missing");
531 goto err_inval;
532 }
533
534 ret = lwtunnel_build_state(nla_get_u16(
535 nla_entype),
536 nla, AF_INET, cfg,
537 &lwtstate, extack);
538 if (ret) 626 if (ret)
539 goto errout; 627 goto errout;
540 nexthop_nh->nh_lwtstate =
541 lwtstate_get(lwtstate);
542 } 628 }
629
630 nla = nla_find(attrs, attrlen, RTA_FLOW);
631 if (nla)
632 fib_cfg.fc_flow = nla_get_u32(nla);
633
634 fib_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP);
635 nla = nla_find(attrs, attrlen, RTA_ENCAP_TYPE);
636 if (nla)
637 fib_cfg.fc_encap_type = nla_get_u16(nla);
543 } 638 }
544 639
640 ret = fib_nh_init(net, nexthop_nh, &fib_cfg,
641 rtnh->rtnh_hops + 1, extack);
642 if (ret)
643 goto errout;
644
545 rtnh = rtnh_next(rtnh, &remaining); 645 rtnh = rtnh_next(rtnh, &remaining);
546 } endfor_nexthops(fi); 646 } endfor_nexthops(fi);
547 647
548 return 0;
549
550err_inval:
551 ret = -EINVAL; 648 ret = -EINVAL;
552 649 if (cfg->fc_oif && fi->fib_nh->fib_nh_oif != cfg->fc_oif) {
650 NL_SET_ERR_MSG(extack,
651 "Nexthop device index does not match RTA_OIF");
652 goto errout;
653 }
654 if (cfg->fc_gw_family) {
655 if (cfg->fc_gw_family != fi->fib_nh->fib_nh_gw_family ||
656 (cfg->fc_gw_family == AF_INET &&
657 fi->fib_nh->fib_nh_gw4 != cfg->fc_gw4) ||
658 (cfg->fc_gw_family == AF_INET6 &&
659 ipv6_addr_cmp(&fi->fib_nh->fib_nh_gw6, &cfg->fc_gw6))) {
660 NL_SET_ERR_MSG(extack,
661 "Nexthop gateway does not match RTA_GATEWAY or RTA_VIA");
662 goto errout;
663 }
664 }
665#ifdef CONFIG_IP_ROUTE_CLASSID
666 if (cfg->fc_flow && fi->fib_nh->nh_tclassid != cfg->fc_flow) {
667 NL_SET_ERR_MSG(extack,
668 "Nexthop class id does not match RTA_FLOW");
669 goto errout;
670 }
671#endif
672 ret = 0;
553errout: 673errout:
554 return ret; 674 return ret;
555} 675}
@@ -558,49 +678,51 @@ static void fib_rebalance(struct fib_info *fi)
558{ 678{
559 int total; 679 int total;
560 int w; 680 int w;
561 struct in_device *in_dev;
562 681
563 if (fi->fib_nhs < 2) 682 if (fi->fib_nhs < 2)
564 return; 683 return;
565 684
566 total = 0; 685 total = 0;
567 for_nexthops(fi) { 686 for_nexthops(fi) {
568 if (nh->nh_flags & RTNH_F_DEAD) 687 if (nh->fib_nh_flags & RTNH_F_DEAD)
569 continue; 688 continue;
570 689
571 in_dev = __in_dev_get_rtnl(nh->nh_dev); 690 if (ip_ignore_linkdown(nh->fib_nh_dev) &&
572 691 nh->fib_nh_flags & RTNH_F_LINKDOWN)
573 if (in_dev &&
574 IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) &&
575 nh->nh_flags & RTNH_F_LINKDOWN)
576 continue; 692 continue;
577 693
578 total += nh->nh_weight; 694 total += nh->fib_nh_weight;
579 } endfor_nexthops(fi); 695 } endfor_nexthops(fi);
580 696
581 w = 0; 697 w = 0;
582 change_nexthops(fi) { 698 change_nexthops(fi) {
583 int upper_bound; 699 int upper_bound;
584 700
585 in_dev = __in_dev_get_rtnl(nexthop_nh->nh_dev); 701 if (nexthop_nh->fib_nh_flags & RTNH_F_DEAD) {
586
587 if (nexthop_nh->nh_flags & RTNH_F_DEAD) {
588 upper_bound = -1; 702 upper_bound = -1;
589 } else if (in_dev && 703 } else if (ip_ignore_linkdown(nexthop_nh->fib_nh_dev) &&
590 IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) && 704 nexthop_nh->fib_nh_flags & RTNH_F_LINKDOWN) {
591 nexthop_nh->nh_flags & RTNH_F_LINKDOWN) {
592 upper_bound = -1; 705 upper_bound = -1;
593 } else { 706 } else {
594 w += nexthop_nh->nh_weight; 707 w += nexthop_nh->fib_nh_weight;
595 upper_bound = DIV_ROUND_CLOSEST_ULL((u64)w << 31, 708 upper_bound = DIV_ROUND_CLOSEST_ULL((u64)w << 31,
596 total) - 1; 709 total) - 1;
597 } 710 }
598 711
599 atomic_set(&nexthop_nh->nh_upper_bound, upper_bound); 712 atomic_set(&nexthop_nh->fib_nh_upper_bound, upper_bound);
600 } endfor_nexthops(fi); 713 } endfor_nexthops(fi);
601} 714}
602#else /* CONFIG_IP_ROUTE_MULTIPATH */ 715#else /* CONFIG_IP_ROUTE_MULTIPATH */
603 716
717static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
718 int remaining, struct fib_config *cfg,
719 struct netlink_ext_ack *extack)
720{
721 NL_SET_ERR_MSG(extack, "Multipath support not enabled in kernel");
722
723 return -EINVAL;
724}
725
604#define fib_rebalance(fi) do { } while (0) 726#define fib_rebalance(fi) do { } while (0)
605 727
606#endif /* CONFIG_IP_ROUTE_MULTIPATH */ 728#endif /* CONFIG_IP_ROUTE_MULTIPATH */
@@ -620,7 +742,7 @@ static int fib_encap_match(u16 encap_type,
620 ret = lwtunnel_build_state(encap_type, encap, AF_INET, 742 ret = lwtunnel_build_state(encap_type, encap, AF_INET,
621 cfg, &lwtstate, extack); 743 cfg, &lwtstate, extack);
622 if (!ret) { 744 if (!ret) {
623 result = lwtunnel_cmp_encap(lwtstate, nh->nh_lwtstate); 745 result = lwtunnel_cmp_encap(lwtstate, nh->fib_nh_lws);
624 lwtstate_free(lwtstate); 746 lwtstate_free(lwtstate);
625 } 747 }
626 748
@@ -638,7 +760,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
638 if (cfg->fc_priority && cfg->fc_priority != fi->fib_priority) 760 if (cfg->fc_priority && cfg->fc_priority != fi->fib_priority)
639 return 1; 761 return 1;
640 762
641 if (cfg->fc_oif || cfg->fc_gw) { 763 if (cfg->fc_oif || cfg->fc_gw_family) {
642 if (cfg->fc_encap) { 764 if (cfg->fc_encap) {
643 if (fib_encap_match(cfg->fc_encap_type, cfg->fc_encap, 765 if (fib_encap_match(cfg->fc_encap_type, cfg->fc_encap,
644 fi->fib_nh, cfg, extack)) 766 fi->fib_nh, cfg, extack))
@@ -649,10 +771,20 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
649 cfg->fc_flow != fi->fib_nh->nh_tclassid) 771 cfg->fc_flow != fi->fib_nh->nh_tclassid)
650 return 1; 772 return 1;
651#endif 773#endif
652 if ((!cfg->fc_oif || cfg->fc_oif == fi->fib_nh->nh_oif) && 774 if ((cfg->fc_oif && cfg->fc_oif != fi->fib_nh->fib_nh_oif) ||
653 (!cfg->fc_gw || cfg->fc_gw == fi->fib_nh->nh_gw)) 775 (cfg->fc_gw_family &&
654 return 0; 776 cfg->fc_gw_family != fi->fib_nh->fib_nh_gw_family))
655 return 1; 777 return 1;
778
779 if (cfg->fc_gw_family == AF_INET &&
780 cfg->fc_gw4 != fi->fib_nh->fib_nh_gw4)
781 return 1;
782
783 if (cfg->fc_gw_family == AF_INET6 &&
784 ipv6_addr_cmp(&cfg->fc_gw6, &fi->fib_nh->fib_nh_gw6))
785 return 1;
786
787 return 0;
656 } 788 }
657 789
658#ifdef CONFIG_IP_ROUTE_MULTIPATH 790#ifdef CONFIG_IP_ROUTE_MULTIPATH
@@ -668,16 +800,48 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
668 if (!rtnh_ok(rtnh, remaining)) 800 if (!rtnh_ok(rtnh, remaining))
669 return -EINVAL; 801 return -EINVAL;
670 802
671 if (rtnh->rtnh_ifindex && rtnh->rtnh_ifindex != nh->nh_oif) 803 if (rtnh->rtnh_ifindex && rtnh->rtnh_ifindex != nh->fib_nh_oif)
672 return 1; 804 return 1;
673 805
674 attrlen = rtnh_attrlen(rtnh); 806 attrlen = rtnh_attrlen(rtnh);
675 if (attrlen > 0) { 807 if (attrlen > 0) {
676 struct nlattr *nla, *attrs = rtnh_attrs(rtnh); 808 struct nlattr *nla, *nlav, *attrs = rtnh_attrs(rtnh);
677 809
678 nla = nla_find(attrs, attrlen, RTA_GATEWAY); 810 nla = nla_find(attrs, attrlen, RTA_GATEWAY);
679 if (nla && nla_get_in_addr(nla) != nh->nh_gw) 811 nlav = nla_find(attrs, attrlen, RTA_VIA);
680 return 1; 812 if (nla && nlav) {
813 NL_SET_ERR_MSG(extack,
814 "Nexthop configuration can not contain both GATEWAY and VIA");
815 return -EINVAL;
816 }
817
818 if (nla) {
819 if (nh->fib_nh_gw_family != AF_INET ||
820 nla_get_in_addr(nla) != nh->fib_nh_gw4)
821 return 1;
822 } else if (nlav) {
823 struct fib_config cfg2;
824 int err;
825
826 err = fib_gw_from_via(&cfg2, nlav, extack);
827 if (err)
828 return err;
829
830 switch (nh->fib_nh_gw_family) {
831 case AF_INET:
832 if (cfg2.fc_gw_family != AF_INET ||
833 cfg2.fc_gw4 != nh->fib_nh_gw4)
834 return 1;
835 break;
836 case AF_INET6:
837 if (cfg2.fc_gw_family != AF_INET6 ||
838 ipv6_addr_cmp(&cfg2.fc_gw6,
839 &nh->fib_nh_gw6))
840 return 1;
841 break;
842 }
843 }
844
681#ifdef CONFIG_IP_ROUTE_CLASSID 845#ifdef CONFIG_IP_ROUTE_CLASSID
682 nla = nla_find(attrs, attrlen, RTA_FLOW); 846 nla = nla_find(attrs, attrlen, RTA_FLOW);
683 if (nla && nla_get_u32(nla) != nh->nh_tclassid) 847 if (nla && nla_get_u32(nla) != nh->nh_tclassid)
@@ -731,6 +895,30 @@ bool fib_metrics_match(struct fib_config *cfg, struct fib_info *fi)
731 return true; 895 return true;
732} 896}
733 897
898static int fib_check_nh_v6_gw(struct net *net, struct fib_nh *nh,
899 u32 table, struct netlink_ext_ack *extack)
900{
901 struct fib6_config cfg = {
902 .fc_table = table,
903 .fc_flags = nh->fib_nh_flags | RTF_GATEWAY,
904 .fc_ifindex = nh->fib_nh_oif,
905 .fc_gateway = nh->fib_nh_gw6,
906 };
907 struct fib6_nh fib6_nh = {};
908 int err;
909
910 err = ipv6_stub->fib6_nh_init(net, &fib6_nh, &cfg, GFP_KERNEL, extack);
911 if (!err) {
912 nh->fib_nh_dev = fib6_nh.fib_nh_dev;
913 dev_hold(nh->fib_nh_dev);
914 nh->fib_nh_oif = nh->fib_nh_dev->ifindex;
915 nh->fib_nh_scope = RT_SCOPE_LINK;
916
917 ipv6_stub->fib6_nh_release(&fib6_nh);
918 }
919
920 return err;
921}
734 922
735/* 923/*
736 * Picture 924 * Picture
@@ -775,133 +963,152 @@ bool fib_metrics_match(struct fib_config *cfg, struct fib_info *fi)
775 * | 963 * |
776 * |-> {local prefix} (terminal node) 964 * |-> {local prefix} (terminal node)
777 */ 965 */
778static int fib_check_nh(struct fib_config *cfg, struct fib_nh *nh, 966static int fib_check_nh_v4_gw(struct net *net, struct fib_nh *nh, u32 table,
779 struct netlink_ext_ack *extack) 967 u8 scope, struct netlink_ext_ack *extack)
780{ 968{
781 int err = 0;
782 struct net *net;
783 struct net_device *dev; 969 struct net_device *dev;
970 struct fib_result res;
971 int err;
784 972
785 net = cfg->fc_nlinfo.nl_net; 973 if (nh->fib_nh_flags & RTNH_F_ONLINK) {
786 if (nh->nh_gw) { 974 unsigned int addr_type;
787 struct fib_result res;
788
789 if (nh->nh_flags & RTNH_F_ONLINK) {
790 unsigned int addr_type;
791 975
792 if (cfg->fc_scope >= RT_SCOPE_LINK) { 976 if (scope >= RT_SCOPE_LINK) {
793 NL_SET_ERR_MSG(extack, 977 NL_SET_ERR_MSG(extack, "Nexthop has invalid scope");
794 "Nexthop has invalid scope"); 978 return -EINVAL;
795 return -EINVAL;
796 }
797 dev = __dev_get_by_index(net, nh->nh_oif);
798 if (!dev) {
799 NL_SET_ERR_MSG(extack, "Nexthop device required for onlink");
800 return -ENODEV;
801 }
802 if (!(dev->flags & IFF_UP)) {
803 NL_SET_ERR_MSG(extack,
804 "Nexthop device is not up");
805 return -ENETDOWN;
806 }
807 addr_type = inet_addr_type_dev_table(net, dev, nh->nh_gw);
808 if (addr_type != RTN_UNICAST) {
809 NL_SET_ERR_MSG(extack,
810 "Nexthop has invalid gateway");
811 return -EINVAL;
812 }
813 if (!netif_carrier_ok(dev))
814 nh->nh_flags |= RTNH_F_LINKDOWN;
815 nh->nh_dev = dev;
816 dev_hold(dev);
817 nh->nh_scope = RT_SCOPE_LINK;
818 return 0;
819 } 979 }
820 rcu_read_lock(); 980 dev = __dev_get_by_index(net, nh->fib_nh_oif);
821 { 981 if (!dev) {
822 struct fib_table *tbl = NULL; 982 NL_SET_ERR_MSG(extack, "Nexthop device required for onlink");
823 struct flowi4 fl4 = { 983 return -ENODEV;
824 .daddr = nh->nh_gw,
825 .flowi4_scope = cfg->fc_scope + 1,
826 .flowi4_oif = nh->nh_oif,
827 .flowi4_iif = LOOPBACK_IFINDEX,
828 };
829
830 /* It is not necessary, but requires a bit of thinking */
831 if (fl4.flowi4_scope < RT_SCOPE_LINK)
832 fl4.flowi4_scope = RT_SCOPE_LINK;
833
834 if (cfg->fc_table)
835 tbl = fib_get_table(net, cfg->fc_table);
836
837 if (tbl)
838 err = fib_table_lookup(tbl, &fl4, &res,
839 FIB_LOOKUP_IGNORE_LINKSTATE |
840 FIB_LOOKUP_NOREF);
841
842 /* on error or if no table given do full lookup. This
843 * is needed for example when nexthops are in the local
844 * table rather than the given table
845 */
846 if (!tbl || err) {
847 err = fib_lookup(net, &fl4, &res,
848 FIB_LOOKUP_IGNORE_LINKSTATE);
849 }
850
851 if (err) {
852 NL_SET_ERR_MSG(extack,
853 "Nexthop has invalid gateway");
854 rcu_read_unlock();
855 return err;
856 }
857 } 984 }
858 err = -EINVAL; 985 if (!(dev->flags & IFF_UP)) {
859 if (res.type != RTN_UNICAST && res.type != RTN_LOCAL) { 986 NL_SET_ERR_MSG(extack, "Nexthop device is not up");
860 NL_SET_ERR_MSG(extack, "Nexthop has invalid gateway"); 987 return -ENETDOWN;
861 goto out;
862 } 988 }
863 nh->nh_scope = res.scope; 989 addr_type = inet_addr_type_dev_table(net, dev, nh->fib_nh_gw4);
864 nh->nh_oif = FIB_RES_OIF(res); 990 if (addr_type != RTN_UNICAST) {
865 nh->nh_dev = dev = FIB_RES_DEV(res); 991 NL_SET_ERR_MSG(extack, "Nexthop has invalid gateway");
866 if (!dev) { 992 return -EINVAL;
867 NL_SET_ERR_MSG(extack,
868 "No egress device for nexthop gateway");
869 goto out;
870 } 993 }
871 dev_hold(dev);
872 if (!netif_carrier_ok(dev)) 994 if (!netif_carrier_ok(dev))
873 nh->nh_flags |= RTNH_F_LINKDOWN; 995 nh->fib_nh_flags |= RTNH_F_LINKDOWN;
874 err = (dev->flags & IFF_UP) ? 0 : -ENETDOWN; 996 nh->fib_nh_dev = dev;
875 } else { 997 dev_hold(dev);
876 struct in_device *in_dev; 998 nh->fib_nh_scope = RT_SCOPE_LINK;
877 999 return 0;
878 if (nh->nh_flags & (RTNH_F_PERVASIVE | RTNH_F_ONLINK)) { 1000 }
879 NL_SET_ERR_MSG(extack, 1001 rcu_read_lock();
880 "Invalid flags for nexthop - PERVASIVE and ONLINK can not be set"); 1002 {
881 return -EINVAL; 1003 struct fib_table *tbl = NULL;
1004 struct flowi4 fl4 = {
1005 .daddr = nh->fib_nh_gw4,
1006 .flowi4_scope = scope + 1,
1007 .flowi4_oif = nh->fib_nh_oif,
1008 .flowi4_iif = LOOPBACK_IFINDEX,
1009 };
1010
1011 /* It is not necessary, but requires a bit of thinking */
1012 if (fl4.flowi4_scope < RT_SCOPE_LINK)
1013 fl4.flowi4_scope = RT_SCOPE_LINK;
1014
1015 if (table)
1016 tbl = fib_get_table(net, table);
1017
1018 if (tbl)
1019 err = fib_table_lookup(tbl, &fl4, &res,
1020 FIB_LOOKUP_IGNORE_LINKSTATE |
1021 FIB_LOOKUP_NOREF);
1022
1023 /* on error or if no table given do full lookup. This
1024 * is needed for example when nexthops are in the local
1025 * table rather than the given table
1026 */
1027 if (!tbl || err) {
1028 err = fib_lookup(net, &fl4, &res,
1029 FIB_LOOKUP_IGNORE_LINKSTATE);
882 } 1030 }
883 rcu_read_lock(); 1031
884 err = -ENODEV; 1032 if (err) {
885 in_dev = inetdev_by_index(net, nh->nh_oif); 1033 NL_SET_ERR_MSG(extack, "Nexthop has invalid gateway");
886 if (!in_dev)
887 goto out;
888 err = -ENETDOWN;
889 if (!(in_dev->dev->flags & IFF_UP)) {
890 NL_SET_ERR_MSG(extack, "Device for nexthop is not up");
891 goto out; 1034 goto out;
892 } 1035 }
893 nh->nh_dev = in_dev->dev;
894 dev_hold(nh->nh_dev);
895 nh->nh_scope = RT_SCOPE_HOST;
896 if (!netif_carrier_ok(nh->nh_dev))
897 nh->nh_flags |= RTNH_F_LINKDOWN;
898 err = 0;
899 } 1036 }
1037
1038 err = -EINVAL;
1039 if (res.type != RTN_UNICAST && res.type != RTN_LOCAL) {
1040 NL_SET_ERR_MSG(extack, "Nexthop has invalid gateway");
1041 goto out;
1042 }
1043 nh->fib_nh_scope = res.scope;
1044 nh->fib_nh_oif = FIB_RES_OIF(res);
1045 nh->fib_nh_dev = dev = FIB_RES_DEV(res);
1046 if (!dev) {
1047 NL_SET_ERR_MSG(extack,
1048 "No egress device for nexthop gateway");
1049 goto out;
1050 }
1051 dev_hold(dev);
1052 if (!netif_carrier_ok(dev))
1053 nh->fib_nh_flags |= RTNH_F_LINKDOWN;
1054 err = (dev->flags & IFF_UP) ? 0 : -ENETDOWN;
900out: 1055out:
901 rcu_read_unlock(); 1056 rcu_read_unlock();
902 return err; 1057 return err;
903} 1058}
904 1059
1060static int fib_check_nh_nongw(struct net *net, struct fib_nh *nh,
1061 struct netlink_ext_ack *extack)
1062{
1063 struct in_device *in_dev;
1064 int err;
1065
1066 if (nh->fib_nh_flags & (RTNH_F_PERVASIVE | RTNH_F_ONLINK)) {
1067 NL_SET_ERR_MSG(extack,
1068 "Invalid flags for nexthop - PERVASIVE and ONLINK can not be set");
1069 return -EINVAL;
1070 }
1071
1072 rcu_read_lock();
1073
1074 err = -ENODEV;
1075 in_dev = inetdev_by_index(net, nh->fib_nh_oif);
1076 if (!in_dev)
1077 goto out;
1078 err = -ENETDOWN;
1079 if (!(in_dev->dev->flags & IFF_UP)) {
1080 NL_SET_ERR_MSG(extack, "Device for nexthop is not up");
1081 goto out;
1082 }
1083
1084 nh->fib_nh_dev = in_dev->dev;
1085 dev_hold(nh->fib_nh_dev);
1086 nh->fib_nh_scope = RT_SCOPE_HOST;
1087 if (!netif_carrier_ok(nh->fib_nh_dev))
1088 nh->fib_nh_flags |= RTNH_F_LINKDOWN;
1089 err = 0;
1090out:
1091 rcu_read_unlock();
1092 return err;
1093}
1094
1095static int fib_check_nh(struct fib_config *cfg, struct fib_nh *nh,
1096 struct netlink_ext_ack *extack)
1097{
1098 struct net *net = cfg->fc_nlinfo.nl_net;
1099 u32 table = cfg->fc_table;
1100 int err;
1101
1102 if (nh->fib_nh_gw_family == AF_INET)
1103 err = fib_check_nh_v4_gw(net, nh, table, cfg->fc_scope, extack);
1104 else if (nh->fib_nh_gw_family == AF_INET6)
1105 err = fib_check_nh_v6_gw(net, nh, table, extack);
1106 else
1107 err = fib_check_nh_nongw(net, nh, extack);
1108
1109 return err;
1110}
1111
905static inline unsigned int fib_laddr_hashfn(__be32 val) 1112static inline unsigned int fib_laddr_hashfn(__be32 val)
906{ 1113{
907 unsigned int mask = (fib_info_hash_size - 1); 1114 unsigned int mask = (fib_info_hash_size - 1);
@@ -986,14 +1193,29 @@ static void fib_info_hash_move(struct hlist_head *new_info_hash,
986 1193
987__be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh) 1194__be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
988{ 1195{
989 nh->nh_saddr = inet_select_addr(nh->nh_dev, 1196 nh->nh_saddr = inet_select_addr(nh->fib_nh_dev,
990 nh->nh_gw, 1197 nh->fib_nh_gw4,
991 nh->nh_parent->fib_scope); 1198 nh->nh_parent->fib_scope);
992 nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid); 1199 nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
993 1200
994 return nh->nh_saddr; 1201 return nh->nh_saddr;
995} 1202}
996 1203
1204__be32 fib_result_prefsrc(struct net *net, struct fib_result *res)
1205{
1206 struct fib_nh_common *nhc = res->nhc;
1207 struct fib_nh *nh;
1208
1209 if (res->fi->fib_prefsrc)
1210 return res->fi->fib_prefsrc;
1211
1212 nh = container_of(nhc, struct fib_nh, nh_common);
1213 if (nh->nh_saddr_genid == atomic_read(&net->ipv4.dev_addr_genid))
1214 return nh->nh_saddr;
1215
1216 return fib_info_update_nh_saddr(net, nh);
1217}
1218
997static bool fib_valid_prefsrc(struct fib_config *cfg, __be32 fib_prefsrc) 1219static bool fib_valid_prefsrc(struct fib_config *cfg, __be32 fib_prefsrc)
998{ 1220{
999 if (cfg->fc_type != RTN_LOCAL || !cfg->fc_dst || 1221 if (cfg->fc_type != RTN_LOCAL || !cfg->fc_dst ||
@@ -1096,72 +1318,18 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
1096 fi->fib_nhs = nhs; 1318 fi->fib_nhs = nhs;
1097 change_nexthops(fi) { 1319 change_nexthops(fi) {
1098 nexthop_nh->nh_parent = fi; 1320 nexthop_nh->nh_parent = fi;
1099 nexthop_nh->nh_pcpu_rth_output = alloc_percpu(struct rtable __rcu *);
1100 if (!nexthop_nh->nh_pcpu_rth_output)
1101 goto failure;
1102 } endfor_nexthops(fi) 1321 } endfor_nexthops(fi)
1103 1322
1104 if (cfg->fc_mp) { 1323 if (cfg->fc_mp)
1105#ifdef CONFIG_IP_ROUTE_MULTIPATH
1106 err = fib_get_nhs(fi, cfg->fc_mp, cfg->fc_mp_len, cfg, extack); 1324 err = fib_get_nhs(fi, cfg->fc_mp, cfg->fc_mp_len, cfg, extack);
1107 if (err != 0) 1325 else
1108 goto failure; 1326 err = fib_nh_init(net, fi->fib_nh, cfg, 1, extack);
1109 if (cfg->fc_oif && fi->fib_nh->nh_oif != cfg->fc_oif) {
1110 NL_SET_ERR_MSG(extack,
1111 "Nexthop device index does not match RTA_OIF");
1112 goto err_inval;
1113 }
1114 if (cfg->fc_gw && fi->fib_nh->nh_gw != cfg->fc_gw) {
1115 NL_SET_ERR_MSG(extack,
1116 "Nexthop gateway does not match RTA_GATEWAY");
1117 goto err_inval;
1118 }
1119#ifdef CONFIG_IP_ROUTE_CLASSID
1120 if (cfg->fc_flow && fi->fib_nh->nh_tclassid != cfg->fc_flow) {
1121 NL_SET_ERR_MSG(extack,
1122 "Nexthop class id does not match RTA_FLOW");
1123 goto err_inval;
1124 }
1125#endif
1126#else
1127 NL_SET_ERR_MSG(extack,
1128 "Multipath support not enabled in kernel");
1129 goto err_inval;
1130#endif
1131 } else {
1132 struct fib_nh *nh = fi->fib_nh;
1133
1134 if (cfg->fc_encap) {
1135 struct lwtunnel_state *lwtstate;
1136
1137 if (cfg->fc_encap_type == LWTUNNEL_ENCAP_NONE) {
1138 NL_SET_ERR_MSG(extack,
1139 "LWT encap type not specified");
1140 goto err_inval;
1141 }
1142 err = lwtunnel_build_state(cfg->fc_encap_type,
1143 cfg->fc_encap, AF_INET, cfg,
1144 &lwtstate, extack);
1145 if (err)
1146 goto failure;
1147 1327
1148 nh->nh_lwtstate = lwtstate_get(lwtstate); 1328 if (err != 0)
1149 } 1329 goto failure;
1150 nh->nh_oif = cfg->fc_oif;
1151 nh->nh_gw = cfg->fc_gw;
1152 nh->nh_flags = cfg->fc_flags;
1153#ifdef CONFIG_IP_ROUTE_CLASSID
1154 nh->nh_tclassid = cfg->fc_flow;
1155 if (nh->nh_tclassid)
1156 fi->fib_net->ipv4.fib_num_tclassid_users++;
1157#endif
1158#ifdef CONFIG_IP_ROUTE_MULTIPATH
1159 nh->nh_weight = 1;
1160#endif
1161 }
1162 1330
1163 if (fib_props[cfg->fc_type].error) { 1331 if (fib_props[cfg->fc_type].error) {
1164 if (cfg->fc_gw || cfg->fc_oif || cfg->fc_mp) { 1332 if (cfg->fc_gw_family || cfg->fc_oif || cfg->fc_mp) {
1165 NL_SET_ERR_MSG(extack, 1333 NL_SET_ERR_MSG(extack,
1166 "Gateway, device and multipath can not be specified for this route type"); 1334 "Gateway, device and multipath can not be specified for this route type");
1167 goto err_inval; 1335 goto err_inval;
@@ -1195,15 +1363,15 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
1195 "Route with host scope can not have multiple nexthops"); 1363 "Route with host scope can not have multiple nexthops");
1196 goto err_inval; 1364 goto err_inval;
1197 } 1365 }
1198 if (nh->nh_gw) { 1366 if (nh->fib_nh_gw_family) {
1199 NL_SET_ERR_MSG(extack, 1367 NL_SET_ERR_MSG(extack,
1200 "Route with host scope can not have a gateway"); 1368 "Route with host scope can not have a gateway");
1201 goto err_inval; 1369 goto err_inval;
1202 } 1370 }
1203 nh->nh_scope = RT_SCOPE_NOWHERE; 1371 nh->fib_nh_scope = RT_SCOPE_NOWHERE;
1204 nh->nh_dev = dev_get_by_index(net, fi->fib_nh->nh_oif); 1372 nh->fib_nh_dev = dev_get_by_index(net, fi->fib_nh->fib_nh_oif);
1205 err = -ENODEV; 1373 err = -ENODEV;
1206 if (!nh->nh_dev) 1374 if (!nh->fib_nh_dev)
1207 goto failure; 1375 goto failure;
1208 } else { 1376 } else {
1209 int linkdown = 0; 1377 int linkdown = 0;
@@ -1212,7 +1380,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
1212 err = fib_check_nh(cfg, nexthop_nh, extack); 1380 err = fib_check_nh(cfg, nexthop_nh, extack);
1213 if (err != 0) 1381 if (err != 0)
1214 goto failure; 1382 goto failure;
1215 if (nexthop_nh->nh_flags & RTNH_F_LINKDOWN) 1383 if (nexthop_nh->fib_nh_flags & RTNH_F_LINKDOWN)
1216 linkdown++; 1384 linkdown++;
1217 } endfor_nexthops(fi) 1385 } endfor_nexthops(fi)
1218 if (linkdown == fi->fib_nhs) 1386 if (linkdown == fi->fib_nhs)
@@ -1226,6 +1394,8 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
1226 1394
1227 change_nexthops(fi) { 1395 change_nexthops(fi) {
1228 fib_info_update_nh_saddr(net, nexthop_nh); 1396 fib_info_update_nh_saddr(net, nexthop_nh);
1397 if (nexthop_nh->fib_nh_gw_family == AF_INET6)
1398 fi->fib_nh_is_v6 = true;
1229 } endfor_nexthops(fi) 1399 } endfor_nexthops(fi)
1230 1400
1231 fib_rebalance(fi); 1401 fib_rebalance(fi);
@@ -1254,9 +1424,9 @@ link_it:
1254 struct hlist_head *head; 1424 struct hlist_head *head;
1255 unsigned int hash; 1425 unsigned int hash;
1256 1426
1257 if (!nexthop_nh->nh_dev) 1427 if (!nexthop_nh->fib_nh_dev)
1258 continue; 1428 continue;
1259 hash = fib_devindex_hashfn(nexthop_nh->nh_dev->ifindex); 1429 hash = fib_devindex_hashfn(nexthop_nh->fib_nh_dev->ifindex);
1260 head = &fib_info_devhash[hash]; 1430 head = &fib_info_devhash[hash];
1261 hlist_add_head(&nexthop_nh->nh_hash, head); 1431 hlist_add_head(&nexthop_nh->nh_hash, head);
1262 } endfor_nexthops(fi) 1432 } endfor_nexthops(fi)
@@ -1275,6 +1445,141 @@ failure:
1275 return ERR_PTR(err); 1445 return ERR_PTR(err);
1276} 1446}
1277 1447
1448int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc,
1449 unsigned char *flags, bool skip_oif)
1450{
1451 if (nhc->nhc_flags & RTNH_F_DEAD)
1452 *flags |= RTNH_F_DEAD;
1453
1454 if (nhc->nhc_flags & RTNH_F_LINKDOWN) {
1455 *flags |= RTNH_F_LINKDOWN;
1456
1457 rcu_read_lock();
1458 switch (nhc->nhc_family) {
1459 case AF_INET:
1460 if (ip_ignore_linkdown(nhc->nhc_dev))
1461 *flags |= RTNH_F_DEAD;
1462 break;
1463 case AF_INET6:
1464 if (ip6_ignore_linkdown(nhc->nhc_dev))
1465 *flags |= RTNH_F_DEAD;
1466 break;
1467 }
1468 rcu_read_unlock();
1469 }
1470
1471 switch (nhc->nhc_gw_family) {
1472 case AF_INET:
1473 if (nla_put_in_addr(skb, RTA_GATEWAY, nhc->nhc_gw.ipv4))
1474 goto nla_put_failure;
1475 break;
1476 case AF_INET6:
1477 /* if gateway family does not match nexthop family
1478 * gateway is encoded as RTA_VIA
1479 */
1480 if (nhc->nhc_gw_family != nhc->nhc_family) {
1481 int alen = sizeof(struct in6_addr);
1482 struct nlattr *nla;
1483 struct rtvia *via;
1484
1485 nla = nla_reserve(skb, RTA_VIA, alen + 2);
1486 if (!nla)
1487 goto nla_put_failure;
1488
1489 via = nla_data(nla);
1490 via->rtvia_family = AF_INET6;
1491 memcpy(via->rtvia_addr, &nhc->nhc_gw.ipv6, alen);
1492 } else if (nla_put_in6_addr(skb, RTA_GATEWAY,
1493 &nhc->nhc_gw.ipv6) < 0) {
1494 goto nla_put_failure;
1495 }
1496 break;
1497 }
1498
1499 *flags |= (nhc->nhc_flags & RTNH_F_ONLINK);
1500 if (nhc->nhc_flags & RTNH_F_OFFLOAD)
1501 *flags |= RTNH_F_OFFLOAD;
1502
1503 if (!skip_oif && nhc->nhc_dev &&
1504 nla_put_u32(skb, RTA_OIF, nhc->nhc_dev->ifindex))
1505 goto nla_put_failure;
1506
1507 if (nhc->nhc_lwtstate &&
1508 lwtunnel_fill_encap(skb, nhc->nhc_lwtstate,
1509 RTA_ENCAP, RTA_ENCAP_TYPE) < 0)
1510 goto nla_put_failure;
1511
1512 return 0;
1513
1514nla_put_failure:
1515 return -EMSGSIZE;
1516}
1517EXPORT_SYMBOL_GPL(fib_nexthop_info);
1518
1519#if IS_ENABLED(CONFIG_IP_ROUTE_MULTIPATH) || IS_ENABLED(CONFIG_IPV6)
1520int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
1521 int nh_weight)
1522{
1523 const struct net_device *dev = nhc->nhc_dev;
1524 struct rtnexthop *rtnh;
1525 unsigned char flags = 0;
1526
1527 rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh));
1528 if (!rtnh)
1529 goto nla_put_failure;
1530
1531 rtnh->rtnh_hops = nh_weight - 1;
1532 rtnh->rtnh_ifindex = dev ? dev->ifindex : 0;
1533
1534 if (fib_nexthop_info(skb, nhc, &flags, true) < 0)
1535 goto nla_put_failure;
1536
1537 rtnh->rtnh_flags = flags;
1538
1539 /* length of rtnetlink header + attributes */
1540 rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh;
1541
1542 return 0;
1543
1544nla_put_failure:
1545 return -EMSGSIZE;
1546}
1547EXPORT_SYMBOL_GPL(fib_add_nexthop);
1548#endif
1549
1550#ifdef CONFIG_IP_ROUTE_MULTIPATH
1551static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi)
1552{
1553 struct nlattr *mp;
1554
1555 mp = nla_nest_start_noflag(skb, RTA_MULTIPATH);
1556 if (!mp)
1557 goto nla_put_failure;
1558
1559 for_nexthops(fi) {
1560 if (fib_add_nexthop(skb, &nh->nh_common, nh->fib_nh_weight) < 0)
1561 goto nla_put_failure;
1562#ifdef CONFIG_IP_ROUTE_CLASSID
1563 if (nh->nh_tclassid &&
1564 nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid))
1565 goto nla_put_failure;
1566#endif
1567 } endfor_nexthops(fi);
1568
1569 nla_nest_end(skb, mp);
1570
1571 return 0;
1572
1573nla_put_failure:
1574 return -EMSGSIZE;
1575}
1576#else
1577static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi)
1578{
1579 return 0;
1580}
1581#endif
1582
1278int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, 1583int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
1279 u32 tb_id, u8 type, __be32 dst, int dst_len, u8 tos, 1584 u32 tb_id, u8 type, __be32 dst, int dst_len, u8 tos,
1280 struct fib_info *fi, unsigned int flags) 1585 struct fib_info *fi, unsigned int flags)
@@ -1315,80 +1620,23 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
1315 nla_put_in_addr(skb, RTA_PREFSRC, fi->fib_prefsrc)) 1620 nla_put_in_addr(skb, RTA_PREFSRC, fi->fib_prefsrc))
1316 goto nla_put_failure; 1621 goto nla_put_failure;
1317 if (fi->fib_nhs == 1) { 1622 if (fi->fib_nhs == 1) {
1318 if (fi->fib_nh->nh_gw && 1623 struct fib_nh *nh = &fi->fib_nh[0];
1319 nla_put_in_addr(skb, RTA_GATEWAY, fi->fib_nh->nh_gw)) 1624 unsigned char flags = 0;
1320 goto nla_put_failure; 1625
1321 if (fi->fib_nh->nh_oif && 1626 if (fib_nexthop_info(skb, &nh->nh_common, &flags, false) < 0)
1322 nla_put_u32(skb, RTA_OIF, fi->fib_nh->nh_oif))
1323 goto nla_put_failure; 1627 goto nla_put_failure;
1324 if (fi->fib_nh->nh_flags & RTNH_F_LINKDOWN) { 1628
1325 struct in_device *in_dev; 1629 rtm->rtm_flags = flags;
1326
1327 rcu_read_lock();
1328 in_dev = __in_dev_get_rcu(fi->fib_nh->nh_dev);
1329 if (in_dev &&
1330 IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
1331 rtm->rtm_flags |= RTNH_F_DEAD;
1332 rcu_read_unlock();
1333 }
1334 if (fi->fib_nh->nh_flags & RTNH_F_OFFLOAD)
1335 rtm->rtm_flags |= RTNH_F_OFFLOAD;
1336#ifdef CONFIG_IP_ROUTE_CLASSID 1630#ifdef CONFIG_IP_ROUTE_CLASSID
1337 if (fi->fib_nh[0].nh_tclassid && 1631 if (nh->nh_tclassid &&
1338 nla_put_u32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid)) 1632 nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid))
1339 goto nla_put_failure; 1633 goto nla_put_failure;
1340#endif 1634#endif
1341 if (fi->fib_nh->nh_lwtstate && 1635 } else {
1342 lwtunnel_fill_encap(skb, fi->fib_nh->nh_lwtstate) < 0) 1636 if (fib_add_multipath(skb, fi) < 0)
1343 goto nla_put_failure; 1637 goto nla_put_failure;
1344 } 1638 }
1345#ifdef CONFIG_IP_ROUTE_MULTIPATH
1346 if (fi->fib_nhs > 1) {
1347 struct rtnexthop *rtnh;
1348 struct nlattr *mp;
1349 1639
1350 mp = nla_nest_start(skb, RTA_MULTIPATH);
1351 if (!mp)
1352 goto nla_put_failure;
1353
1354 for_nexthops(fi) {
1355 rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh));
1356 if (!rtnh)
1357 goto nla_put_failure;
1358
1359 rtnh->rtnh_flags = nh->nh_flags & 0xFF;
1360 if (nh->nh_flags & RTNH_F_LINKDOWN) {
1361 struct in_device *in_dev;
1362
1363 rcu_read_lock();
1364 in_dev = __in_dev_get_rcu(nh->nh_dev);
1365 if (in_dev &&
1366 IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
1367 rtnh->rtnh_flags |= RTNH_F_DEAD;
1368 rcu_read_unlock();
1369 }
1370 rtnh->rtnh_hops = nh->nh_weight - 1;
1371 rtnh->rtnh_ifindex = nh->nh_oif;
1372
1373 if (nh->nh_gw &&
1374 nla_put_in_addr(skb, RTA_GATEWAY, nh->nh_gw))
1375 goto nla_put_failure;
1376#ifdef CONFIG_IP_ROUTE_CLASSID
1377 if (nh->nh_tclassid &&
1378 nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid))
1379 goto nla_put_failure;
1380#endif
1381 if (nh->nh_lwtstate &&
1382 lwtunnel_fill_encap(skb, nh->nh_lwtstate) < 0)
1383 goto nla_put_failure;
1384
1385 /* length of rtnetlink header + attributes */
1386 rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *) rtnh;
1387 } endfor_nexthops(fi);
1388
1389 nla_nest_end(skb, mp);
1390 }
1391#endif
1392 nlmsg_end(skb, nlh); 1640 nlmsg_end(skb, nlh);
1393 return 0; 1641 return 0;
1394 1642
@@ -1427,28 +1675,26 @@ int fib_sync_down_addr(struct net_device *dev, __be32 local)
1427 return ret; 1675 return ret;
1428} 1676}
1429 1677
1430static int call_fib_nh_notifiers(struct fib_nh *fib_nh, 1678static int call_fib_nh_notifiers(struct fib_nh *nh,
1431 enum fib_event_type event_type) 1679 enum fib_event_type event_type)
1432{ 1680{
1433 struct in_device *in_dev = __in_dev_get_rtnl(fib_nh->nh_dev); 1681 bool ignore_link_down = ip_ignore_linkdown(nh->fib_nh_dev);
1434 struct fib_nh_notifier_info info = { 1682 struct fib_nh_notifier_info info = {
1435 .fib_nh = fib_nh, 1683 .fib_nh = nh,
1436 }; 1684 };
1437 1685
1438 switch (event_type) { 1686 switch (event_type) {
1439 case FIB_EVENT_NH_ADD: 1687 case FIB_EVENT_NH_ADD:
1440 if (fib_nh->nh_flags & RTNH_F_DEAD) 1688 if (nh->fib_nh_flags & RTNH_F_DEAD)
1441 break; 1689 break;
1442 if (IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) && 1690 if (ignore_link_down && nh->fib_nh_flags & RTNH_F_LINKDOWN)
1443 fib_nh->nh_flags & RTNH_F_LINKDOWN)
1444 break; 1691 break;
1445 return call_fib4_notifiers(dev_net(fib_nh->nh_dev), event_type, 1692 return call_fib4_notifiers(dev_net(nh->fib_nh_dev), event_type,
1446 &info.info); 1693 &info.info);
1447 case FIB_EVENT_NH_DEL: 1694 case FIB_EVENT_NH_DEL:
1448 if ((in_dev && IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) && 1695 if ((ignore_link_down && nh->fib_nh_flags & RTNH_F_LINKDOWN) ||
1449 fib_nh->nh_flags & RTNH_F_LINKDOWN) || 1696 (nh->fib_nh_flags & RTNH_F_DEAD))
1450 (fib_nh->nh_flags & RTNH_F_DEAD)) 1697 return call_fib4_notifiers(dev_net(nh->fib_nh_dev),
1451 return call_fib4_notifiers(dev_net(fib_nh->nh_dev),
1452 event_type, &info.info); 1698 event_type, &info.info);
1453 default: 1699 default:
1454 break; 1700 break;
@@ -1467,12 +1713,12 @@ static int call_fib_nh_notifiers(struct fib_nh *fib_nh,
1467 * - if the new MTU is greater than the PMTU, don't make any change 1713 * - if the new MTU is greater than the PMTU, don't make any change
1468 * - otherwise, unlock and set PMTU 1714 * - otherwise, unlock and set PMTU
1469 */ 1715 */
1470static void nh_update_mtu(struct fib_nh *nh, u32 new, u32 orig) 1716static void nh_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig)
1471{ 1717{
1472 struct fnhe_hash_bucket *bucket; 1718 struct fnhe_hash_bucket *bucket;
1473 int i; 1719 int i;
1474 1720
1475 bucket = rcu_dereference_protected(nh->nh_exceptions, 1); 1721 bucket = rcu_dereference_protected(nhc->nhc_exceptions, 1);
1476 if (!bucket) 1722 if (!bucket)
1477 return; 1723 return;
1478 1724
@@ -1502,8 +1748,8 @@ void fib_sync_mtu(struct net_device *dev, u32 orig_mtu)
1502 struct fib_nh *nh; 1748 struct fib_nh *nh;
1503 1749
1504 hlist_for_each_entry(nh, head, nh_hash) { 1750 hlist_for_each_entry(nh, head, nh_hash) {
1505 if (nh->nh_dev == dev) 1751 if (nh->fib_nh_dev == dev)
1506 nh_update_mtu(nh, dev->mtu, orig_mtu); 1752 nh_update_mtu(&nh->nh_common, dev->mtu, orig_mtu);
1507 } 1753 }
1508} 1754}
1509 1755
@@ -1530,22 +1776,22 @@ int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force)
1530 int dead; 1776 int dead;
1531 1777
1532 BUG_ON(!fi->fib_nhs); 1778 BUG_ON(!fi->fib_nhs);
1533 if (nh->nh_dev != dev || fi == prev_fi) 1779 if (nh->fib_nh_dev != dev || fi == prev_fi)
1534 continue; 1780 continue;
1535 prev_fi = fi; 1781 prev_fi = fi;
1536 dead = 0; 1782 dead = 0;
1537 change_nexthops(fi) { 1783 change_nexthops(fi) {
1538 if (nexthop_nh->nh_flags & RTNH_F_DEAD) 1784 if (nexthop_nh->fib_nh_flags & RTNH_F_DEAD)
1539 dead++; 1785 dead++;
1540 else if (nexthop_nh->nh_dev == dev && 1786 else if (nexthop_nh->fib_nh_dev == dev &&
1541 nexthop_nh->nh_scope != scope) { 1787 nexthop_nh->fib_nh_scope != scope) {
1542 switch (event) { 1788 switch (event) {
1543 case NETDEV_DOWN: 1789 case NETDEV_DOWN:
1544 case NETDEV_UNREGISTER: 1790 case NETDEV_UNREGISTER:
1545 nexthop_nh->nh_flags |= RTNH_F_DEAD; 1791 nexthop_nh->fib_nh_flags |= RTNH_F_DEAD;
1546 /* fall through */ 1792 /* fall through */
1547 case NETDEV_CHANGE: 1793 case NETDEV_CHANGE:
1548 nexthop_nh->nh_flags |= RTNH_F_LINKDOWN; 1794 nexthop_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
1549 break; 1795 break;
1550 } 1796 }
1551 call_fib_nh_notifiers(nexthop_nh, 1797 call_fib_nh_notifiers(nexthop_nh,
@@ -1554,7 +1800,7 @@ int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force)
1554 } 1800 }
1555#ifdef CONFIG_IP_ROUTE_MULTIPATH 1801#ifdef CONFIG_IP_ROUTE_MULTIPATH
1556 if (event == NETDEV_UNREGISTER && 1802 if (event == NETDEV_UNREGISTER &&
1557 nexthop_nh->nh_dev == dev) { 1803 nexthop_nh->fib_nh_dev == dev) {
1558 dead = fi->fib_nhs; 1804 dead = fi->fib_nhs;
1559 break; 1805 break;
1560 } 1806 }
@@ -1614,8 +1860,8 @@ static void fib_select_default(const struct flowi4 *flp, struct fib_result *res)
1614 if (next_fi->fib_scope != res->scope || 1860 if (next_fi->fib_scope != res->scope ||
1615 fa->fa_type != RTN_UNICAST) 1861 fa->fa_type != RTN_UNICAST)
1616 continue; 1862 continue;
1617 if (!next_fi->fib_nh[0].nh_gw || 1863 if (!next_fi->fib_nh[0].fib_nh_gw4 ||
1618 next_fi->fib_nh[0].nh_scope != RT_SCOPE_LINK) 1864 next_fi->fib_nh[0].fib_nh_scope != RT_SCOPE_LINK)
1619 continue; 1865 continue;
1620 1866
1621 fib_alias_accessed(fa); 1867 fib_alias_accessed(fa);
@@ -1658,7 +1904,7 @@ out:
1658 * Dead device goes up. We wake up dead nexthops. 1904 * Dead device goes up. We wake up dead nexthops.
1659 * It takes sense only on multipath routes. 1905 * It takes sense only on multipath routes.
1660 */ 1906 */
1661int fib_sync_up(struct net_device *dev, unsigned int nh_flags) 1907int fib_sync_up(struct net_device *dev, unsigned char nh_flags)
1662{ 1908{
1663 struct fib_info *prev_fi; 1909 struct fib_info *prev_fi;
1664 unsigned int hash; 1910 unsigned int hash;
@@ -1686,24 +1932,24 @@ int fib_sync_up(struct net_device *dev, unsigned int nh_flags)
1686 int alive; 1932 int alive;
1687 1933
1688 BUG_ON(!fi->fib_nhs); 1934 BUG_ON(!fi->fib_nhs);
1689 if (nh->nh_dev != dev || fi == prev_fi) 1935 if (nh->fib_nh_dev != dev || fi == prev_fi)
1690 continue; 1936 continue;
1691 1937
1692 prev_fi = fi; 1938 prev_fi = fi;
1693 alive = 0; 1939 alive = 0;
1694 change_nexthops(fi) { 1940 change_nexthops(fi) {
1695 if (!(nexthop_nh->nh_flags & nh_flags)) { 1941 if (!(nexthop_nh->fib_nh_flags & nh_flags)) {
1696 alive++; 1942 alive++;
1697 continue; 1943 continue;
1698 } 1944 }
1699 if (!nexthop_nh->nh_dev || 1945 if (!nexthop_nh->fib_nh_dev ||
1700 !(nexthop_nh->nh_dev->flags & IFF_UP)) 1946 !(nexthop_nh->fib_nh_dev->flags & IFF_UP))
1701 continue; 1947 continue;
1702 if (nexthop_nh->nh_dev != dev || 1948 if (nexthop_nh->fib_nh_dev != dev ||
1703 !__in_dev_get_rtnl(dev)) 1949 !__in_dev_get_rtnl(dev))
1704 continue; 1950 continue;
1705 alive++; 1951 alive++;
1706 nexthop_nh->nh_flags &= ~nh_flags; 1952 nexthop_nh->fib_nh_flags &= ~nh_flags;
1707 call_fib_nh_notifiers(nexthop_nh, FIB_EVENT_NH_ADD); 1953 call_fib_nh_notifiers(nexthop_nh, FIB_EVENT_NH_ADD);
1708 } endfor_nexthops(fi) 1954 } endfor_nexthops(fi)
1709 1955
@@ -1723,13 +1969,19 @@ static bool fib_good_nh(const struct fib_nh *nh)
1723{ 1969{
1724 int state = NUD_REACHABLE; 1970 int state = NUD_REACHABLE;
1725 1971
1726 if (nh->nh_scope == RT_SCOPE_LINK) { 1972 if (nh->fib_nh_scope == RT_SCOPE_LINK) {
1727 struct neighbour *n; 1973 struct neighbour *n;
1728 1974
1729 rcu_read_lock_bh(); 1975 rcu_read_lock_bh();
1730 1976
1731 n = __ipv4_neigh_lookup_noref(nh->nh_dev, 1977 if (likely(nh->fib_nh_gw_family == AF_INET))
1732 (__force u32)nh->nh_gw); 1978 n = __ipv4_neigh_lookup_noref(nh->fib_nh_dev,
1979 (__force u32)nh->fib_nh_gw4);
1980 else if (nh->fib_nh_gw_family == AF_INET6)
1981 n = __ipv6_neigh_lookup_noref_stub(nh->fib_nh_dev,
1982 &nh->fib_nh_gw6);
1983 else
1984 n = NULL;
1733 if (n) 1985 if (n)
1734 state = n->nud_state; 1986 state = n->nud_state;
1735 1987
@@ -1745,20 +1997,22 @@ void fib_select_multipath(struct fib_result *res, int hash)
1745 struct net *net = fi->fib_net; 1997 struct net *net = fi->fib_net;
1746 bool first = false; 1998 bool first = false;
1747 1999
1748 for_nexthops(fi) { 2000 change_nexthops(fi) {
1749 if (net->ipv4.sysctl_fib_multipath_use_neigh) { 2001 if (net->ipv4.sysctl_fib_multipath_use_neigh) {
1750 if (!fib_good_nh(nh)) 2002 if (!fib_good_nh(nexthop_nh))
1751 continue; 2003 continue;
1752 if (!first) { 2004 if (!first) {
1753 res->nh_sel = nhsel; 2005 res->nh_sel = nhsel;
2006 res->nhc = &nexthop_nh->nh_common;
1754 first = true; 2007 first = true;
1755 } 2008 }
1756 } 2009 }
1757 2010
1758 if (hash > atomic_read(&nh->nh_upper_bound)) 2011 if (hash > atomic_read(&nexthop_nh->fib_nh_upper_bound))
1759 continue; 2012 continue;
1760 2013
1761 res->nh_sel = nhsel; 2014 res->nh_sel = nhsel;
2015 res->nhc = &nexthop_nh->nh_common;
1762 return; 2016 return;
1763 } endfor_nexthops(fi); 2017 } endfor_nexthops(fi);
1764} 2018}
@@ -1785,5 +2039,5 @@ void fib_select_path(struct net *net, struct fib_result *res,
1785 2039
1786check_saddr: 2040check_saddr:
1787 if (!fl4->saddr) 2041 if (!fl4->saddr)
1788 fl4->saddr = FIB_RES_PREFSRC(net, *res); 2042 fl4->saddr = fib_result_prefsrc(net, res);
1789} 2043}
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index a573e37e0615..334f723bdf80 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -183,14 +183,16 @@ struct trie {
183}; 183};
184 184
185static struct key_vector *resize(struct trie *t, struct key_vector *tn); 185static struct key_vector *resize(struct trie *t, struct key_vector *tn);
186static size_t tnode_free_size; 186static unsigned int tnode_free_size;
187 187
188/* 188/*
189 * synchronize_rcu after call_rcu for that many pages; it should be especially 189 * synchronize_rcu after call_rcu for outstanding dirty memory; it should be
190 * useful before resizing the root node with PREEMPT_NONE configs; the value was 190 * especially useful before resizing the root node with PREEMPT_NONE configs;
191 * obtained experimentally, aiming to avoid visible slowdown. 191 * the value was obtained experimentally, aiming to avoid visible slowdown.
192 */ 192 */
193static const int sync_pages = 128; 193unsigned int sysctl_fib_sync_mem = 512 * 1024;
194unsigned int sysctl_fib_sync_mem_min = 64 * 1024;
195unsigned int sysctl_fib_sync_mem_max = 64 * 1024 * 1024;
194 196
195static struct kmem_cache *fn_alias_kmem __ro_after_init; 197static struct kmem_cache *fn_alias_kmem __ro_after_init;
196static struct kmem_cache *trie_leaf_kmem __ro_after_init; 198static struct kmem_cache *trie_leaf_kmem __ro_after_init;
@@ -504,7 +506,7 @@ static void tnode_free(struct key_vector *tn)
504 tn = container_of(head, struct tnode, rcu)->kv; 506 tn = container_of(head, struct tnode, rcu)->kv;
505 } 507 }
506 508
507 if (tnode_free_size >= PAGE_SIZE * sync_pages) { 509 if (tnode_free_size >= sysctl_fib_sync_mem) {
508 tnode_free_size = 0; 510 tnode_free_size = 0;
509 synchronize_rcu(); 511 synchronize_rcu();
510 } 512 }
@@ -1468,19 +1470,17 @@ found:
1468 if (fi->fib_flags & RTNH_F_DEAD) 1470 if (fi->fib_flags & RTNH_F_DEAD)
1469 continue; 1471 continue;
1470 for (nhsel = 0; nhsel < fi->fib_nhs; nhsel++) { 1472 for (nhsel = 0; nhsel < fi->fib_nhs; nhsel++) {
1471 const struct fib_nh *nh = &fi->fib_nh[nhsel]; 1473 struct fib_nh_common *nhc = fib_info_nhc(fi, nhsel);
1472 struct in_device *in_dev = __in_dev_get_rcu(nh->nh_dev);
1473 1474
1474 if (nh->nh_flags & RTNH_F_DEAD) 1475 if (nhc->nhc_flags & RTNH_F_DEAD)
1475 continue; 1476 continue;
1476 if (in_dev && 1477 if (ip_ignore_linkdown(nhc->nhc_dev) &&
1477 IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) && 1478 nhc->nhc_flags & RTNH_F_LINKDOWN &&
1478 nh->nh_flags & RTNH_F_LINKDOWN &&
1479 !(fib_flags & FIB_LOOKUP_IGNORE_LINKSTATE)) 1479 !(fib_flags & FIB_LOOKUP_IGNORE_LINKSTATE))
1480 continue; 1480 continue;
1481 if (!(flp->flowi4_flags & FLOWI_FLAG_SKIP_NH_OIF)) { 1481 if (!(flp->flowi4_flags & FLOWI_FLAG_SKIP_NH_OIF)) {
1482 if (flp->flowi4_oif && 1482 if (flp->flowi4_oif &&
1483 flp->flowi4_oif != nh->nh_oif) 1483 flp->flowi4_oif != nhc->nhc_oif)
1484 continue; 1484 continue;
1485 } 1485 }
1486 1486
@@ -1490,6 +1490,7 @@ found:
1490 res->prefix = htonl(n->key); 1490 res->prefix = htonl(n->key);
1491 res->prefixlen = KEYLENGTH - fa->fa_slen; 1491 res->prefixlen = KEYLENGTH - fa->fa_slen;
1492 res->nh_sel = nhsel; 1492 res->nh_sel = nhsel;
1493 res->nhc = nhc;
1493 res->type = fa->fa_type; 1494 res->type = fa->fa_type;
1494 res->scope = fi->fib_scope; 1495 res->scope = fi->fib_scope;
1495 res->fi = fi; 1496 res->fi = fi;
@@ -1498,7 +1499,7 @@ found:
1498#ifdef CONFIG_IP_FIB_TRIE_STATS 1499#ifdef CONFIG_IP_FIB_TRIE_STATS
1499 this_cpu_inc(stats->semantic_match_passed); 1500 this_cpu_inc(stats->semantic_match_passed);
1500#endif 1501#endif
1501 trace_fib_table_lookup(tb->tb_id, flp, nh, err); 1502 trace_fib_table_lookup(tb->tb_id, flp, nhc, err);
1502 1503
1503 return err; 1504 return err;
1504 } 1505 }
@@ -2651,7 +2652,7 @@ static unsigned int fib_flag_trans(int type, __be32 mask, const struct fib_info
2651 2652
2652 if (type == RTN_UNREACHABLE || type == RTN_PROHIBIT) 2653 if (type == RTN_UNREACHABLE || type == RTN_PROHIBIT)
2653 flags = RTF_REJECT; 2654 flags = RTF_REJECT;
2654 if (fi && fi->fib_nh->nh_gw) 2655 if (fi && fi->fib_nh->fib_nh_gw4)
2655 flags |= RTF_GATEWAY; 2656 flags |= RTF_GATEWAY;
2656 if (mask == htonl(0xFFFFFFFF)) 2657 if (mask == htonl(0xFFFFFFFF))
2657 flags |= RTF_HOST; 2658 flags |= RTF_HOST;
@@ -2702,7 +2703,7 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)
2702 "%d\t%08X\t%d\t%u\t%u", 2703 "%d\t%08X\t%d\t%u\t%u",
2703 fi->fib_dev ? fi->fib_dev->name : "*", 2704 fi->fib_dev ? fi->fib_dev->name : "*",
2704 prefix, 2705 prefix,
2705 fi->fib_nh->nh_gw, flags, 0, 0, 2706 fi->fib_nh->fib_nh_gw4, flags, 0, 0,
2706 fi->fib_priority, 2707 fi->fib_priority,
2707 mask, 2708 mask,
2708 (fi->fib_advmss ? 2709 (fi->fib_advmss ?
diff --git a/net/ipv4/fou.c b/net/ipv4/fou.c
index 79e98e21cdd7..ca95051317ed 100644
--- a/net/ipv4/fou.c
+++ b/net/ipv4/fou.c
@@ -121,6 +121,7 @@ static int gue_udp_recv(struct sock *sk, struct sk_buff *skb)
121 struct guehdr *guehdr; 121 struct guehdr *guehdr;
122 void *data; 122 void *data;
123 u16 doffset = 0; 123 u16 doffset = 0;
124 u8 proto_ctype;
124 125
125 if (!fou) 126 if (!fou)
126 return 1; 127 return 1;
@@ -136,7 +137,7 @@ static int gue_udp_recv(struct sock *sk, struct sk_buff *skb)
136 break; 137 break;
137 138
138 case 1: { 139 case 1: {
139 /* Direct encasulation of IPv4 or IPv6 */ 140 /* Direct encapsulation of IPv4 or IPv6 */
140 141
141 int prot; 142 int prot;
142 143
@@ -170,9 +171,7 @@ static int gue_udp_recv(struct sock *sk, struct sk_buff *skb)
170 /* guehdr may change after pull */ 171 /* guehdr may change after pull */
171 guehdr = (struct guehdr *)&udp_hdr(skb)[1]; 172 guehdr = (struct guehdr *)&udp_hdr(skb)[1];
172 173
173 hdrlen = sizeof(struct guehdr) + optlen; 174 if (validate_gue_flags(guehdr, optlen))
174
175 if (guehdr->version != 0 || validate_gue_flags(guehdr, optlen))
176 goto drop; 175 goto drop;
177 176
178 hdrlen = sizeof(struct guehdr) + optlen; 177 hdrlen = sizeof(struct guehdr) + optlen;
@@ -212,13 +211,14 @@ static int gue_udp_recv(struct sock *sk, struct sk_buff *skb)
212 if (unlikely(guehdr->control)) 211 if (unlikely(guehdr->control))
213 return gue_control_message(skb, guehdr); 212 return gue_control_message(skb, guehdr);
214 213
214 proto_ctype = guehdr->proto_ctype;
215 __skb_pull(skb, sizeof(struct udphdr) + hdrlen); 215 __skb_pull(skb, sizeof(struct udphdr) + hdrlen);
216 skb_reset_transport_header(skb); 216 skb_reset_transport_header(skb);
217 217
218 if (iptunnel_pull_offloads(skb)) 218 if (iptunnel_pull_offloads(skb))
219 goto drop; 219 goto drop;
220 220
221 return -guehdr->proto_ctype; 221 return -proto_ctype;
222 222
223drop: 223drop:
224 kfree_skb(skb); 224 kfree_skb(skb);
@@ -499,15 +499,45 @@ out_unlock:
499 return err; 499 return err;
500} 500}
501 501
502static int fou_add_to_port_list(struct net *net, struct fou *fou) 502static bool fou_cfg_cmp(struct fou *fou, struct fou_cfg *cfg)
503{
504 struct sock *sk = fou->sock->sk;
505 struct udp_port_cfg *udp_cfg = &cfg->udp_config;
506
507 if (fou->family != udp_cfg->family ||
508 fou->port != udp_cfg->local_udp_port ||
509 sk->sk_dport != udp_cfg->peer_udp_port ||
510 sk->sk_bound_dev_if != udp_cfg->bind_ifindex)
511 return false;
512
513 if (fou->family == AF_INET) {
514 if (sk->sk_rcv_saddr != udp_cfg->local_ip.s_addr ||
515 sk->sk_daddr != udp_cfg->peer_ip.s_addr)
516 return false;
517 else
518 return true;
519#if IS_ENABLED(CONFIG_IPV6)
520 } else {
521 if (ipv6_addr_cmp(&sk->sk_v6_rcv_saddr, &udp_cfg->local_ip6) ||
522 ipv6_addr_cmp(&sk->sk_v6_daddr, &udp_cfg->peer_ip6))
523 return false;
524 else
525 return true;
526#endif
527 }
528
529 return false;
530}
531
532static int fou_add_to_port_list(struct net *net, struct fou *fou,
533 struct fou_cfg *cfg)
503{ 534{
504 struct fou_net *fn = net_generic(net, fou_net_id); 535 struct fou_net *fn = net_generic(net, fou_net_id);
505 struct fou *fout; 536 struct fou *fout;
506 537
507 mutex_lock(&fn->fou_lock); 538 mutex_lock(&fn->fou_lock);
508 list_for_each_entry(fout, &fn->fou_list, list) { 539 list_for_each_entry(fout, &fn->fou_list, list) {
509 if (fou->port == fout->port && 540 if (fou_cfg_cmp(fout, cfg)) {
510 fou->family == fout->family) {
511 mutex_unlock(&fn->fou_lock); 541 mutex_unlock(&fn->fou_lock);
512 return -EALREADY; 542 return -EALREADY;
513 } 543 }
@@ -585,7 +615,7 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
585 615
586 sk->sk_allocation = GFP_ATOMIC; 616 sk->sk_allocation = GFP_ATOMIC;
587 617
588 err = fou_add_to_port_list(net, fou); 618 err = fou_add_to_port_list(net, fou, cfg);
589 if (err) 619 if (err)
590 goto error; 620 goto error;
591 621
@@ -605,14 +635,12 @@ error:
605static int fou_destroy(struct net *net, struct fou_cfg *cfg) 635static int fou_destroy(struct net *net, struct fou_cfg *cfg)
606{ 636{
607 struct fou_net *fn = net_generic(net, fou_net_id); 637 struct fou_net *fn = net_generic(net, fou_net_id);
608 __be16 port = cfg->udp_config.local_udp_port;
609 u8 family = cfg->udp_config.family;
610 int err = -EINVAL; 638 int err = -EINVAL;
611 struct fou *fou; 639 struct fou *fou;
612 640
613 mutex_lock(&fn->fou_lock); 641 mutex_lock(&fn->fou_lock);
614 list_for_each_entry(fou, &fn->fou_list, list) { 642 list_for_each_entry(fou, &fn->fou_list, list) {
615 if (fou->port == port && fou->family == family) { 643 if (fou_cfg_cmp(fou, cfg)) {
616 fou_release(fou); 644 fou_release(fou);
617 err = 0; 645 err = 0;
618 break; 646 break;
@@ -626,16 +654,27 @@ static int fou_destroy(struct net *net, struct fou_cfg *cfg)
626static struct genl_family fou_nl_family; 654static struct genl_family fou_nl_family;
627 655
628static const struct nla_policy fou_nl_policy[FOU_ATTR_MAX + 1] = { 656static const struct nla_policy fou_nl_policy[FOU_ATTR_MAX + 1] = {
629 [FOU_ATTR_PORT] = { .type = NLA_U16, }, 657 [FOU_ATTR_PORT] = { .type = NLA_U16, },
630 [FOU_ATTR_AF] = { .type = NLA_U8, }, 658 [FOU_ATTR_AF] = { .type = NLA_U8, },
631 [FOU_ATTR_IPPROTO] = { .type = NLA_U8, }, 659 [FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
632 [FOU_ATTR_TYPE] = { .type = NLA_U8, }, 660 [FOU_ATTR_TYPE] = { .type = NLA_U8, },
633 [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, }, 661 [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
662 [FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, },
663 [FOU_ATTR_PEER_V4] = { .type = NLA_U32, },
664 [FOU_ATTR_LOCAL_V6] = { .type = sizeof(struct in6_addr), },
665 [FOU_ATTR_PEER_V6] = { .type = sizeof(struct in6_addr), },
666 [FOU_ATTR_PEER_PORT] = { .type = NLA_U16, },
667 [FOU_ATTR_IFINDEX] = { .type = NLA_S32, },
634}; 668};
635 669
636static int parse_nl_config(struct genl_info *info, 670static int parse_nl_config(struct genl_info *info,
637 struct fou_cfg *cfg) 671 struct fou_cfg *cfg)
638{ 672{
673 bool has_local = false, has_peer = false;
674 struct nlattr *attr;
675 int ifindex;
676 __be16 port;
677
639 memset(cfg, 0, sizeof(*cfg)); 678 memset(cfg, 0, sizeof(*cfg));
640 679
641 cfg->udp_config.family = AF_INET; 680 cfg->udp_config.family = AF_INET;
@@ -657,8 +696,7 @@ static int parse_nl_config(struct genl_info *info,
657 } 696 }
658 697
659 if (info->attrs[FOU_ATTR_PORT]) { 698 if (info->attrs[FOU_ATTR_PORT]) {
660 __be16 port = nla_get_be16(info->attrs[FOU_ATTR_PORT]); 699 port = nla_get_be16(info->attrs[FOU_ATTR_PORT]);
661
662 cfg->udp_config.local_udp_port = port; 700 cfg->udp_config.local_udp_port = port;
663 } 701 }
664 702
@@ -671,6 +709,52 @@ static int parse_nl_config(struct genl_info *info,
671 if (info->attrs[FOU_ATTR_REMCSUM_NOPARTIAL]) 709 if (info->attrs[FOU_ATTR_REMCSUM_NOPARTIAL])
672 cfg->flags |= FOU_F_REMCSUM_NOPARTIAL; 710 cfg->flags |= FOU_F_REMCSUM_NOPARTIAL;
673 711
712 if (cfg->udp_config.family == AF_INET) {
713 if (info->attrs[FOU_ATTR_LOCAL_V4]) {
714 attr = info->attrs[FOU_ATTR_LOCAL_V4];
715 cfg->udp_config.local_ip.s_addr = nla_get_in_addr(attr);
716 has_local = true;
717 }
718
719 if (info->attrs[FOU_ATTR_PEER_V4]) {
720 attr = info->attrs[FOU_ATTR_PEER_V4];
721 cfg->udp_config.peer_ip.s_addr = nla_get_in_addr(attr);
722 has_peer = true;
723 }
724#if IS_ENABLED(CONFIG_IPV6)
725 } else {
726 if (info->attrs[FOU_ATTR_LOCAL_V6]) {
727 attr = info->attrs[FOU_ATTR_LOCAL_V6];
728 cfg->udp_config.local_ip6 = nla_get_in6_addr(attr);
729 has_local = true;
730 }
731
732 if (info->attrs[FOU_ATTR_PEER_V6]) {
733 attr = info->attrs[FOU_ATTR_PEER_V6];
734 cfg->udp_config.peer_ip6 = nla_get_in6_addr(attr);
735 has_peer = true;
736 }
737#endif
738 }
739
740 if (has_peer) {
741 if (info->attrs[FOU_ATTR_PEER_PORT]) {
742 port = nla_get_be16(info->attrs[FOU_ATTR_PEER_PORT]);
743 cfg->udp_config.peer_udp_port = port;
744 } else {
745 return -EINVAL;
746 }
747 }
748
749 if (info->attrs[FOU_ATTR_IFINDEX]) {
750 if (!has_local)
751 return -EINVAL;
752
753 ifindex = nla_get_s32(info->attrs[FOU_ATTR_IFINDEX]);
754
755 cfg->udp_config.bind_ifindex = ifindex;
756 }
757
674 return 0; 758 return 0;
675} 759}
676 760
@@ -702,15 +786,37 @@ static int fou_nl_cmd_rm_port(struct sk_buff *skb, struct genl_info *info)
702 786
703static int fou_fill_info(struct fou *fou, struct sk_buff *msg) 787static int fou_fill_info(struct fou *fou, struct sk_buff *msg)
704{ 788{
789 struct sock *sk = fou->sock->sk;
790
705 if (nla_put_u8(msg, FOU_ATTR_AF, fou->sock->sk->sk_family) || 791 if (nla_put_u8(msg, FOU_ATTR_AF, fou->sock->sk->sk_family) ||
706 nla_put_be16(msg, FOU_ATTR_PORT, fou->port) || 792 nla_put_be16(msg, FOU_ATTR_PORT, fou->port) ||
793 nla_put_be16(msg, FOU_ATTR_PEER_PORT, sk->sk_dport) ||
707 nla_put_u8(msg, FOU_ATTR_IPPROTO, fou->protocol) || 794 nla_put_u8(msg, FOU_ATTR_IPPROTO, fou->protocol) ||
708 nla_put_u8(msg, FOU_ATTR_TYPE, fou->type)) 795 nla_put_u8(msg, FOU_ATTR_TYPE, fou->type) ||
796 nla_put_s32(msg, FOU_ATTR_IFINDEX, sk->sk_bound_dev_if))
709 return -1; 797 return -1;
710 798
711 if (fou->flags & FOU_F_REMCSUM_NOPARTIAL) 799 if (fou->flags & FOU_F_REMCSUM_NOPARTIAL)
712 if (nla_put_flag(msg, FOU_ATTR_REMCSUM_NOPARTIAL)) 800 if (nla_put_flag(msg, FOU_ATTR_REMCSUM_NOPARTIAL))
713 return -1; 801 return -1;
802
803 if (fou->sock->sk->sk_family == AF_INET) {
804 if (nla_put_in_addr(msg, FOU_ATTR_LOCAL_V4, sk->sk_rcv_saddr))
805 return -1;
806
807 if (nla_put_in_addr(msg, FOU_ATTR_PEER_V4, sk->sk_daddr))
808 return -1;
809#if IS_ENABLED(CONFIG_IPV6)
810 } else {
811 if (nla_put_in6_addr(msg, FOU_ATTR_LOCAL_V6,
812 &sk->sk_v6_rcv_saddr))
813 return -1;
814
815 if (nla_put_in6_addr(msg, FOU_ATTR_PEER_V6, &sk->sk_v6_daddr))
816 return -1;
817#endif
818 }
819
714 return 0; 820 return 0;
715} 821}
716 822
@@ -763,7 +869,7 @@ static int fou_nl_cmd_get_port(struct sk_buff *skb, struct genl_info *info)
763 ret = -ESRCH; 869 ret = -ESRCH;
764 mutex_lock(&fn->fou_lock); 870 mutex_lock(&fn->fou_lock);
765 list_for_each_entry(fout, &fn->fou_list, list) { 871 list_for_each_entry(fout, &fn->fou_list, list) {
766 if (port == fout->port && family == fout->family) { 872 if (fou_cfg_cmp(fout, &cfg)) {
767 ret = fou_dump_info(fout, info->snd_portid, 873 ret = fou_dump_info(fout, info->snd_portid,
768 info->snd_seq, 0, msg, 874 info->snd_seq, 0, msg,
769 info->genlhdr->cmd); 875 info->genlhdr->cmd);
@@ -807,21 +913,21 @@ static int fou_nl_dump(struct sk_buff *skb, struct netlink_callback *cb)
807static const struct genl_ops fou_nl_ops[] = { 913static const struct genl_ops fou_nl_ops[] = {
808 { 914 {
809 .cmd = FOU_CMD_ADD, 915 .cmd = FOU_CMD_ADD,
916 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
810 .doit = fou_nl_cmd_add_port, 917 .doit = fou_nl_cmd_add_port,
811 .policy = fou_nl_policy,
812 .flags = GENL_ADMIN_PERM, 918 .flags = GENL_ADMIN_PERM,
813 }, 919 },
814 { 920 {
815 .cmd = FOU_CMD_DEL, 921 .cmd = FOU_CMD_DEL,
922 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
816 .doit = fou_nl_cmd_rm_port, 923 .doit = fou_nl_cmd_rm_port,
817 .policy = fou_nl_policy,
818 .flags = GENL_ADMIN_PERM, 924 .flags = GENL_ADMIN_PERM,
819 }, 925 },
820 { 926 {
821 .cmd = FOU_CMD_GET, 927 .cmd = FOU_CMD_GET,
928 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
822 .doit = fou_nl_cmd_get_port, 929 .doit = fou_nl_cmd_get_port,
823 .dumpit = fou_nl_dump, 930 .dumpit = fou_nl_dump,
824 .policy = fou_nl_policy,
825 }, 931 },
826}; 932};
827 933
@@ -830,6 +936,7 @@ static struct genl_family fou_nl_family __ro_after_init = {
830 .name = FOU_GENL_NAME, 936 .name = FOU_GENL_NAME,
831 .version = FOU_GENL_VERSION, 937 .version = FOU_GENL_VERSION,
832 .maxattr = FOU_ATTR_MAX, 938 .maxattr = FOU_ATTR_MAX,
939 .policy = fou_nl_policy,
833 .netnsok = true, 940 .netnsok = true,
834 .module = THIS_MODULE, 941 .module = THIS_MODULE,
835 .ops = fou_nl_ops, 942 .ops = fou_nl_ops,
@@ -1033,7 +1140,7 @@ static int gue_err(struct sk_buff *skb, u32 info)
1033 case 0: /* Full GUE header present */ 1140 case 0: /* Full GUE header present */
1034 break; 1141 break;
1035 case 1: { 1142 case 1: {
1036 /* Direct encasulation of IPv4 or IPv6 */ 1143 /* Direct encapsulation of IPv4 or IPv6 */
1037 skb_set_transport_header(skb, -(int)sizeof(struct icmphdr)); 1144 skb_set_transport_header(skb, -(int)sizeof(struct icmphdr));
1038 1145
1039 switch (((struct iphdr *)guehdr)->version) { 1146 switch (((struct iphdr *)guehdr)->version) {
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 6ea523d71947..a175e3e7ae97 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -564,7 +564,7 @@ struct dst_entry *inet_csk_route_req(const struct sock *sk,
564 rt = ip_route_output_flow(net, fl4, sk); 564 rt = ip_route_output_flow(net, fl4, sk);
565 if (IS_ERR(rt)) 565 if (IS_ERR(rt))
566 goto no_route; 566 goto no_route;
567 if (opt && opt->opt.is_strictroute && rt->rt_uses_gateway) 567 if (opt && opt->opt.is_strictroute && rt->rt_gw_family)
568 goto route_err; 568 goto route_err;
569 rcu_read_unlock(); 569 rcu_read_unlock();
570 return &rt->dst; 570 return &rt->dst;
@@ -602,7 +602,7 @@ struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,
602 rt = ip_route_output_flow(net, fl4, sk); 602 rt = ip_route_output_flow(net, fl4, sk);
603 if (IS_ERR(rt)) 603 if (IS_ERR(rt))
604 goto no_route; 604 goto no_route;
605 if (opt && opt->opt.is_strictroute && rt->rt_uses_gateway) 605 if (opt && opt->opt.is_strictroute && rt->rt_gw_family)
606 goto route_err; 606 goto route_err;
607 return &rt->dst; 607 return &rt->dst;
608 608
diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c
index 00ec819f949b..06f6f280b9ff 100644
--- a/net/ipv4/ip_forward.c
+++ b/net/ipv4/ip_forward.c
@@ -123,7 +123,7 @@ int ip_forward(struct sk_buff *skb)
123 123
124 rt = skb_rtable(skb); 124 rt = skb_rtable(skb);
125 125
126 if (opt->is_strictroute && rt->rt_uses_gateway) 126 if (opt->is_strictroute && rt->rt_gw_family)
127 goto sr_failed; 127 goto sr_failed;
128 128
129 IPCB(skb)->flags |= IPSKB_FORWARDED; 129 IPCB(skb)->flags |= IPSKB_FORWARDED;
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index 1132d6d1796a..ed97724c5e33 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -130,6 +130,7 @@
130#include <linux/inetdevice.h> 130#include <linux/inetdevice.h>
131#include <linux/netdevice.h> 131#include <linux/netdevice.h>
132#include <linux/etherdevice.h> 132#include <linux/etherdevice.h>
133#include <linux/indirect_call_wrapper.h>
133 134
134#include <net/snmp.h> 135#include <net/snmp.h>
135#include <net/ip.h> 136#include <net/ip.h>
@@ -188,6 +189,8 @@ bool ip_call_ra_chain(struct sk_buff *skb)
188 return false; 189 return false;
189} 190}
190 191
192INDIRECT_CALLABLE_DECLARE(int udp_rcv(struct sk_buff *));
193INDIRECT_CALLABLE_DECLARE(int tcp_v4_rcv(struct sk_buff *));
191void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol) 194void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol)
192{ 195{
193 const struct net_protocol *ipprot; 196 const struct net_protocol *ipprot;
@@ -205,7 +208,8 @@ resubmit:
205 } 208 }
206 nf_reset(skb); 209 nf_reset(skb);
207 } 210 }
208 ret = ipprot->handler(skb); 211 ret = INDIRECT_CALL_2(ipprot->handler, tcp_v4_rcv, udp_rcv,
212 skb);
209 if (ret < 0) { 213 if (ret < 0) {
210 protocol = -ret; 214 protocol = -ret;
211 goto resubmit; 215 goto resubmit;
@@ -305,6 +309,8 @@ drop:
305 return true; 309 return true;
306} 310}
307 311
312INDIRECT_CALLABLE_DECLARE(int udp_v4_early_demux(struct sk_buff *));
313INDIRECT_CALLABLE_DECLARE(int tcp_v4_early_demux(struct sk_buff *));
308static int ip_rcv_finish_core(struct net *net, struct sock *sk, 314static int ip_rcv_finish_core(struct net *net, struct sock *sk,
309 struct sk_buff *skb, struct net_device *dev) 315 struct sk_buff *skb, struct net_device *dev)
310{ 316{
@@ -322,7 +328,8 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
322 328
323 ipprot = rcu_dereference(inet_protos[protocol]); 329 ipprot = rcu_dereference(inet_protos[protocol]);
324 if (ipprot && (edemux = READ_ONCE(ipprot->early_demux))) { 330 if (ipprot && (edemux = READ_ONCE(ipprot->early_demux))) {
325 err = edemux(skb); 331 err = INDIRECT_CALL_2(edemux, tcp_v4_early_demux,
332 udp_v4_early_demux, skb);
326 if (unlikely(err)) 333 if (unlikely(err))
327 goto drop_error; 334 goto drop_error;
328 /* must reload iph, skb->head might have changed */ 335 /* must reload iph, skb->head might have changed */
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index c80188875f39..ac880beda8a7 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -188,7 +188,7 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
188 struct net_device *dev = dst->dev; 188 struct net_device *dev = dst->dev;
189 unsigned int hh_len = LL_RESERVED_SPACE(dev); 189 unsigned int hh_len = LL_RESERVED_SPACE(dev);
190 struct neighbour *neigh; 190 struct neighbour *neigh;
191 u32 nexthop; 191 bool is_v6gw = false;
192 192
193 if (rt->rt_type == RTN_MULTICAST) { 193 if (rt->rt_type == RTN_MULTICAST) {
194 IP_UPD_PO_STATS(net, IPSTATS_MIB_OUTMCAST, skb->len); 194 IP_UPD_PO_STATS(net, IPSTATS_MIB_OUTMCAST, skb->len);
@@ -218,16 +218,13 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
218 } 218 }
219 219
220 rcu_read_lock_bh(); 220 rcu_read_lock_bh();
221 nexthop = (__force u32) rt_nexthop(rt, ip_hdr(skb)->daddr); 221 neigh = ip_neigh_for_gw(rt, skb, &is_v6gw);
222 neigh = __ipv4_neigh_lookup_noref(dev, nexthop);
223 if (unlikely(!neigh))
224 neigh = __neigh_create(&arp_tbl, &nexthop, dev, false);
225 if (!IS_ERR(neigh)) { 222 if (!IS_ERR(neigh)) {
226 int res; 223 int res;
227 224
228 sock_confirm_neigh(skb, neigh); 225 sock_confirm_neigh(skb, neigh);
229 res = neigh_output(neigh, skb); 226 /* if crossing protocols, can not use the cached header */
230 227 res = neigh_output(neigh, skb, is_v6gw);
231 rcu_read_unlock_bh(); 228 rcu_read_unlock_bh();
232 return res; 229 return res;
233 } 230 }
@@ -472,7 +469,7 @@ int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
472 skb_dst_set_noref(skb, &rt->dst); 469 skb_dst_set_noref(skb, &rt->dst);
473 470
474packet_routed: 471packet_routed:
475 if (inet_opt && inet_opt->opt.is_strictroute && rt->rt_uses_gateway) 472 if (inet_opt && inet_opt->opt.is_strictroute && rt->rt_gw_family)
476 goto no_route; 473 goto no_route;
477 474
478 /* OK, we know where to send it, allocate and build IP header. */ 475 /* OK, we know where to send it, allocate and build IP header. */
@@ -519,6 +516,7 @@ static void ip_copy_metadata(struct sk_buff *to, struct sk_buff *from)
519 to->pkt_type = from->pkt_type; 516 to->pkt_type = from->pkt_type;
520 to->priority = from->priority; 517 to->priority = from->priority;
521 to->protocol = from->protocol; 518 to->protocol = from->protocol;
519 to->skb_iif = from->skb_iif;
522 skb_dst_drop(to); 520 skb_dst_drop(to);
523 skb_dst_copy(to, from); 521 skb_dst_copy(to, from);
524 to->dev = from->dev; 522 to->dev = from->dev;
@@ -693,11 +691,8 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
693 return 0; 691 return 0;
694 } 692 }
695 693
696 while (frag) { 694 kfree_skb_list(frag);
697 skb = frag->next; 695
698 kfree_skb(frag);
699 frag = skb;
700 }
701 IP_INC_STATS(net, IPSTATS_MIB_FRAGFAILS); 696 IP_INC_STATS(net, IPSTATS_MIB_FRAGFAILS);
702 return err; 697 return err;
703 698
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index c3f3d28d1087..30c1c264bdfc 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -239,8 +239,8 @@ static int ip_tun_build_state(struct nlattr *attr,
239 struct nlattr *tb[LWTUNNEL_IP_MAX + 1]; 239 struct nlattr *tb[LWTUNNEL_IP_MAX + 1];
240 int err; 240 int err;
241 241
242 err = nla_parse_nested(tb, LWTUNNEL_IP_MAX, attr, ip_tun_policy, 242 err = nla_parse_nested_deprecated(tb, LWTUNNEL_IP_MAX, attr,
243 extack); 243 ip_tun_policy, extack);
244 if (err < 0) 244 if (err < 0)
245 return err; 245 return err;
246 246
@@ -356,8 +356,8 @@ static int ip6_tun_build_state(struct nlattr *attr,
356 struct nlattr *tb[LWTUNNEL_IP6_MAX + 1]; 356 struct nlattr *tb[LWTUNNEL_IP6_MAX + 1];
357 int err; 357 int err;
358 358
359 err = nla_parse_nested(tb, LWTUNNEL_IP6_MAX, attr, ip6_tun_policy, 359 err = nla_parse_nested_deprecated(tb, LWTUNNEL_IP6_MAX, attr,
360 extack); 360 ip6_tun_policy, extack);
361 if (err < 0) 361 if (err < 0)
362 return err; 362 return err;
363 363
diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index 68a21bf75dd0..254a42e83ff9 100644
--- a/net/ipv4/ip_vti.c
+++ b/net/ipv4/ip_vti.c
@@ -50,7 +50,7 @@ static unsigned int vti_net_id __read_mostly;
50static int vti_tunnel_init(struct net_device *dev); 50static int vti_tunnel_init(struct net_device *dev);
51 51
52static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi, 52static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
53 int encap_type) 53 int encap_type, bool update_skb_dev)
54{ 54{
55 struct ip_tunnel *tunnel; 55 struct ip_tunnel *tunnel;
56 const struct iphdr *iph = ip_hdr(skb); 56 const struct iphdr *iph = ip_hdr(skb);
@@ -65,6 +65,9 @@ static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
65 65
66 XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel; 66 XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
67 67
68 if (update_skb_dev)
69 skb->dev = tunnel->dev;
70
68 return xfrm_input(skb, nexthdr, spi, encap_type); 71 return xfrm_input(skb, nexthdr, spi, encap_type);
69 } 72 }
70 73
@@ -74,47 +77,28 @@ drop:
74 return 0; 77 return 0;
75} 78}
76 79
77static int vti_input_ipip(struct sk_buff *skb, int nexthdr, __be32 spi, 80static int vti_input_proto(struct sk_buff *skb, int nexthdr, __be32 spi,
78 int encap_type) 81 int encap_type)
79{ 82{
80 struct ip_tunnel *tunnel; 83 return vti_input(skb, nexthdr, spi, encap_type, false);
81 const struct iphdr *iph = ip_hdr(skb);
82 struct net *net = dev_net(skb->dev);
83 struct ip_tunnel_net *itn = net_generic(net, vti_net_id);
84
85 tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
86 iph->saddr, iph->daddr, 0);
87 if (tunnel) {
88 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
89 goto drop;
90
91 XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
92
93 skb->dev = tunnel->dev;
94
95 return xfrm_input(skb, nexthdr, spi, encap_type);
96 }
97
98 return -EINVAL;
99drop:
100 kfree_skb(skb);
101 return 0;
102} 84}
103 85
104static int vti_rcv(struct sk_buff *skb) 86static int vti_rcv(struct sk_buff *skb, __be32 spi, bool update_skb_dev)
105{ 87{
106 XFRM_SPI_SKB_CB(skb)->family = AF_INET; 88 XFRM_SPI_SKB_CB(skb)->family = AF_INET;
107 XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr); 89 XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
108 90
109 return vti_input(skb, ip_hdr(skb)->protocol, 0, 0); 91 return vti_input(skb, ip_hdr(skb)->protocol, spi, 0, update_skb_dev);
110} 92}
111 93
112static int vti_rcv_ipip(struct sk_buff *skb) 94static int vti_rcv_proto(struct sk_buff *skb)
113{ 95{
114 XFRM_SPI_SKB_CB(skb)->family = AF_INET; 96 return vti_rcv(skb, 0, false);
115 XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr); 97}
116 98
117 return vti_input_ipip(skb, ip_hdr(skb)->protocol, ip_hdr(skb)->saddr, 0); 99static int vti_rcv_tunnel(struct sk_buff *skb)
100{
101 return vti_rcv(skb, ip_hdr(skb)->saddr, true);
118} 102}
119 103
120static int vti_rcv_cb(struct sk_buff *skb, int err) 104static int vti_rcv_cb(struct sk_buff *skb, int err)
@@ -123,7 +107,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
123 struct net_device *dev; 107 struct net_device *dev;
124 struct pcpu_sw_netstats *tstats; 108 struct pcpu_sw_netstats *tstats;
125 struct xfrm_state *x; 109 struct xfrm_state *x;
126 struct xfrm_mode *inner_mode; 110 const struct xfrm_mode *inner_mode;
127 struct ip_tunnel *tunnel = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4; 111 struct ip_tunnel *tunnel = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4;
128 u32 orig_mark = skb->mark; 112 u32 orig_mark = skb->mark;
129 int ret; 113 int ret;
@@ -142,7 +126,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
142 126
143 x = xfrm_input_state(skb); 127 x = xfrm_input_state(skb);
144 128
145 inner_mode = x->inner_mode; 129 inner_mode = &x->inner_mode;
146 130
147 if (x->sel.family == AF_UNSPEC) { 131 if (x->sel.family == AF_UNSPEC) {
148 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol); 132 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
@@ -153,7 +137,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
153 } 137 }
154 } 138 }
155 139
156 family = inner_mode->afinfo->family; 140 family = inner_mode->family;
157 141
158 skb->mark = be32_to_cpu(tunnel->parms.i_key); 142 skb->mark = be32_to_cpu(tunnel->parms.i_key);
159 ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family); 143 ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
@@ -447,31 +431,31 @@ static void __net_init vti_fb_tunnel_init(struct net_device *dev)
447} 431}
448 432
449static struct xfrm4_protocol vti_esp4_protocol __read_mostly = { 433static struct xfrm4_protocol vti_esp4_protocol __read_mostly = {
450 .handler = vti_rcv, 434 .handler = vti_rcv_proto,
451 .input_handler = vti_input, 435 .input_handler = vti_input_proto,
452 .cb_handler = vti_rcv_cb, 436 .cb_handler = vti_rcv_cb,
453 .err_handler = vti4_err, 437 .err_handler = vti4_err,
454 .priority = 100, 438 .priority = 100,
455}; 439};
456 440
457static struct xfrm4_protocol vti_ah4_protocol __read_mostly = { 441static struct xfrm4_protocol vti_ah4_protocol __read_mostly = {
458 .handler = vti_rcv, 442 .handler = vti_rcv_proto,
459 .input_handler = vti_input, 443 .input_handler = vti_input_proto,
460 .cb_handler = vti_rcv_cb, 444 .cb_handler = vti_rcv_cb,
461 .err_handler = vti4_err, 445 .err_handler = vti4_err,
462 .priority = 100, 446 .priority = 100,
463}; 447};
464 448
465static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = { 449static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = {
466 .handler = vti_rcv, 450 .handler = vti_rcv_proto,
467 .input_handler = vti_input, 451 .input_handler = vti_input_proto,
468 .cb_handler = vti_rcv_cb, 452 .cb_handler = vti_rcv_cb,
469 .err_handler = vti4_err, 453 .err_handler = vti4_err,
470 .priority = 100, 454 .priority = 100,
471}; 455};
472 456
473static struct xfrm_tunnel ipip_handler __read_mostly = { 457static struct xfrm_tunnel ipip_handler __read_mostly = {
474 .handler = vti_rcv_ipip, 458 .handler = vti_rcv_tunnel,
475 .err_handler = vti4_err, 459 .err_handler = vti4_err,
476 .priority = 0, 460 .priority = 0,
477}; 461};
@@ -646,10 +630,8 @@ static int __init vti_init(void)
646 630
647 msg = "ipip tunnel"; 631 msg = "ipip tunnel";
648 err = xfrm4_tunnel_register(&ipip_handler, AF_INET); 632 err = xfrm4_tunnel_register(&ipip_handler, AF_INET);
649 if (err < 0) { 633 if (err < 0)
650 pr_info("%s: cant't register tunnel\n",__func__);
651 goto xfrm_tunnel_failed; 634 goto xfrm_tunnel_failed;
652 }
653 635
654 msg = "netlink interface"; 636 msg = "netlink interface";
655 err = rtnl_link_register(&vti_link_ops); 637 err = rtnl_link_register(&vti_link_ops);
@@ -659,9 +641,9 @@ static int __init vti_init(void)
659 return err; 641 return err;
660 642
661rtnl_link_failed: 643rtnl_link_failed:
662 xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
663xfrm_tunnel_failed:
664 xfrm4_tunnel_deregister(&ipip_handler, AF_INET); 644 xfrm4_tunnel_deregister(&ipip_handler, AF_INET);
645xfrm_tunnel_failed:
646 xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
665xfrm_proto_comp_failed: 647xfrm_proto_comp_failed:
666 xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH); 648 xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
667xfrm_proto_ah_failed: 649xfrm_proto_ah_failed:
@@ -676,6 +658,7 @@ pernet_dev_failed:
676static void __exit vti_fini(void) 658static void __exit vti_fini(void)
677{ 659{
678 rtnl_link_unregister(&vti_link_ops); 660 rtnl_link_unregister(&vti_link_ops);
661 xfrm4_tunnel_deregister(&ipip_handler, AF_INET);
679 xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP); 662 xfrm4_protocol_deregister(&vti_ipcomp4_protocol, IPPROTO_COMP);
680 xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH); 663 xfrm4_protocol_deregister(&vti_ah4_protocol, IPPROTO_AH);
681 xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP); 664 xfrm4_protocol_deregister(&vti_esp4_protocol, IPPROTO_ESP);
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 2c931120c494..2c61e10a60e3 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -66,7 +66,7 @@
66#include <net/netlink.h> 66#include <net/netlink.h>
67#include <net/fib_rules.h> 67#include <net/fib_rules.h>
68#include <linux/netconf.h> 68#include <linux/netconf.h>
69#include <net/nexthop.h> 69#include <net/rtnh.h>
70 70
71#include <linux/nospec.h> 71#include <linux/nospec.h>
72 72
@@ -373,7 +373,6 @@ static const struct rhashtable_params ipmr_rht_params = {
373 .key_offset = offsetof(struct mfc_cache, cmparg), 373 .key_offset = offsetof(struct mfc_cache, cmparg),
374 .key_len = sizeof(struct mfc_cache_cmp_arg), 374 .key_len = sizeof(struct mfc_cache_cmp_arg),
375 .nelem_hint = 3, 375 .nelem_hint = 3,
376 .locks_mul = 1,
377 .obj_cmpfn = ipmr_hash_cmp, 376 .obj_cmpfn = ipmr_hash_cmp,
378 .automatic_shrinking = true, 377 .automatic_shrinking = true,
379}; 378};
@@ -2499,8 +2498,8 @@ static int ipmr_rtm_valid_getroute_req(struct sk_buff *skb,
2499 } 2498 }
2500 2499
2501 if (!netlink_strict_get_check(skb)) 2500 if (!netlink_strict_get_check(skb))
2502 return nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, 2501 return nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
2503 rtm_ipv4_policy, extack); 2502 rtm_ipv4_policy, extack);
2504 2503
2505 rtm = nlmsg_data(nlh); 2504 rtm = nlmsg_data(nlh);
2506 if ((rtm->rtm_src_len && rtm->rtm_src_len != 32) || 2505 if ((rtm->rtm_src_len && rtm->rtm_src_len != 32) ||
@@ -2511,8 +2510,8 @@ static int ipmr_rtm_valid_getroute_req(struct sk_buff *skb,
2511 return -EINVAL; 2510 return -EINVAL;
2512 } 2511 }
2513 2512
2514 err = nlmsg_parse_strict(nlh, sizeof(*rtm), tb, RTA_MAX, 2513 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX,
2515 rtm_ipv4_policy, extack); 2514 rtm_ipv4_policy, extack);
2516 if (err) 2515 if (err)
2517 return err; 2516 return err;
2518 2517
@@ -2675,8 +2674,8 @@ static int rtm_to_ipmr_mfcc(struct net *net, struct nlmsghdr *nlh,
2675 struct rtmsg *rtm; 2674 struct rtmsg *rtm;
2676 int ret, rem; 2675 int ret, rem;
2677 2676
2678 ret = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipmr_policy, 2677 ret = nlmsg_validate_deprecated(nlh, sizeof(*rtm), RTA_MAX,
2679 extack); 2678 rtm_ipmr_policy, extack);
2680 if (ret < 0) 2679 if (ret < 0)
2681 goto out; 2680 goto out;
2682 rtm = nlmsg_data(nlh); 2681 rtm = nlmsg_data(nlh);
@@ -2784,7 +2783,7 @@ static bool ipmr_fill_vif(struct mr_table *mrt, u32 vifid, struct sk_buff *skb)
2784 return true; 2783 return true;
2785 2784
2786 vif = &mrt->vif_table[vifid]; 2785 vif = &mrt->vif_table[vifid];
2787 vif_nest = nla_nest_start(skb, IPMRA_VIF); 2786 vif_nest = nla_nest_start_noflag(skb, IPMRA_VIF);
2788 if (!vif_nest) 2787 if (!vif_nest)
2789 return false; 2788 return false;
2790 if (nla_put_u32(skb, IPMRA_VIFA_IFINDEX, vif->dev->ifindex) || 2789 if (nla_put_u32(skb, IPMRA_VIFA_IFINDEX, vif->dev->ifindex) ||
@@ -2868,7 +2867,7 @@ static int ipmr_rtm_dumplink(struct sk_buff *skb, struct netlink_callback *cb)
2868 memset(hdr, 0, sizeof(*hdr)); 2867 memset(hdr, 0, sizeof(*hdr));
2869 hdr->ifi_family = RTNL_FAMILY_IPMR; 2868 hdr->ifi_family = RTNL_FAMILY_IPMR;
2870 2869
2871 af = nla_nest_start(skb, IFLA_AF_SPEC); 2870 af = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
2872 if (!af) { 2871 if (!af) {
2873 nlmsg_cancel(skb, nlh); 2872 nlmsg_cancel(skb, nlh);
2874 goto out; 2873 goto out;
@@ -2879,7 +2878,7 @@ static int ipmr_rtm_dumplink(struct sk_buff *skb, struct netlink_callback *cb)
2879 goto out; 2878 goto out;
2880 } 2879 }
2881 2880
2882 vifs = nla_nest_start(skb, IPMRA_TABLE_VIFS); 2881 vifs = nla_nest_start_noflag(skb, IPMRA_TABLE_VIFS);
2883 if (!vifs) { 2882 if (!vifs) {
2884 nla_nest_end(skb, af); 2883 nla_nest_end(skb, af);
2885 nlmsg_end(skb, nlh); 2884 nlmsg_end(skb, nlh);
diff --git a/net/ipv4/ipmr_base.c b/net/ipv4/ipmr_base.c
index 3e614cc824f7..ea48bd15a575 100644
--- a/net/ipv4/ipmr_base.c
+++ b/net/ipv4/ipmr_base.c
@@ -228,7 +228,7 @@ int mr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
228 if (c->mfc_flags & MFC_OFFLOAD) 228 if (c->mfc_flags & MFC_OFFLOAD)
229 rtm->rtm_flags |= RTNH_F_OFFLOAD; 229 rtm->rtm_flags |= RTNH_F_OFFLOAD;
230 230
231 mp_attr = nla_nest_start(skb, RTA_MULTIPATH); 231 mp_attr = nla_nest_start_noflag(skb, RTA_MULTIPATH);
232 if (!mp_attr) 232 if (!mp_attr)
233 return -EMSGSIZE; 233 return -EMSGSIZE;
234 234
@@ -335,8 +335,6 @@ next_entry2:
335 } 335 }
336 spin_unlock_bh(lock); 336 spin_unlock_bh(lock);
337 err = 0; 337 err = 0;
338 e = 0;
339
340out: 338out:
341 cb->args[1] = e; 339 cb->args[1] = e;
342 return err; 340 return err;
@@ -374,6 +372,7 @@ int mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
374 err = mr_table_dump(mrt, skb, cb, fill, lock, filter); 372 err = mr_table_dump(mrt, skb, cb, fill, lock, filter);
375 if (err < 0) 373 if (err < 0)
376 break; 374 break;
375 cb->args[1] = 0;
377next_table: 376next_table:
378 t++; 377 t++;
379 } 378 }
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index c98391d49200..1412b029f37f 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -27,14 +27,6 @@ config NF_TABLES_IPV4
27 27
28if NF_TABLES_IPV4 28if NF_TABLES_IPV4
29 29
30config NFT_CHAIN_ROUTE_IPV4
31 tristate "IPv4 nf_tables route chain support"
32 help
33 This option enables the "route" chain for IPv4 in nf_tables. This
34 chain type is used to force packet re-routing after mangling header
35 fields such as the source, destination, type of service and
36 the packet mark.
37
38config NFT_REJECT_IPV4 30config NFT_REJECT_IPV4
39 select NF_REJECT_IPV4 31 select NF_REJECT_IPV4
40 default NFT_REJECT 32 default NFT_REJECT
@@ -232,16 +224,10 @@ if IP_NF_NAT
232 224
233config IP_NF_TARGET_MASQUERADE 225config IP_NF_TARGET_MASQUERADE
234 tristate "MASQUERADE target support" 226 tristate "MASQUERADE target support"
235 select NF_NAT_MASQUERADE 227 select NETFILTER_XT_TARGET_MASQUERADE
236 default m if NETFILTER_ADVANCED=n
237 help 228 help
238 Masquerading is a special case of NAT: all outgoing connections are 229 This is a backwards-compat option for the user's convenience
239 changed to seem to come from a particular interface's address, and 230 (e.g. when running oldconfig). It selects NETFILTER_XT_TARGET_MASQUERADE.
240 if the interface goes down, those connections are lost. This is
241 only useful for dialup accounts with dynamic IP address (ie. your IP
242 address will be different on next dialup).
243
244 To compile it as a module, choose M here. If unsure, say N.
245 231
246config IP_NF_TARGET_NETMAP 232config IP_NF_TARGET_NETMAP
247 tristate "NETMAP target support" 233 tristate "NETMAP target support"
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
index e241f5188ebe..c50e0ec095d2 100644
--- a/net/ipv4/netfilter/Makefile
+++ b/net/ipv4/netfilter/Makefile
@@ -24,7 +24,6 @@ nf_nat_snmp_basic-y := nf_nat_snmp_basic.asn1.o nf_nat_snmp_basic_main.o
24$(obj)/nf_nat_snmp_basic_main.o: $(obj)/nf_nat_snmp_basic.asn1.h 24$(obj)/nf_nat_snmp_basic_main.o: $(obj)/nf_nat_snmp_basic.asn1.h
25obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o 25obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o
26 26
27obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o
28obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o 27obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o
29obj-$(CONFIG_NFT_FIB_IPV4) += nft_fib_ipv4.o 28obj-$(CONFIG_NFT_FIB_IPV4) += nft_fib_ipv4.o
30obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o 29obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o
@@ -49,7 +48,6 @@ obj-$(CONFIG_IP_NF_MATCH_RPFILTER) += ipt_rpfilter.o
49# targets 48# targets
50obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o 49obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o
51obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o 50obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
52obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
53obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o 51obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
54obj-$(CONFIG_IP_NF_TARGET_SYNPROXY) += ipt_SYNPROXY.o 52obj-$(CONFIG_IP_NF_TARGET_SYNPROXY) += ipt_SYNPROXY.o
55 53
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 835d50b279f5..a2a88ab07f7b 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -56,7 +56,7 @@ struct clusterip_config {
56#endif 56#endif
57 enum clusterip_hashmode hash_mode; /* which hashing mode */ 57 enum clusterip_hashmode hash_mode; /* which hashing mode */
58 u_int32_t hash_initval; /* hash initialization */ 58 u_int32_t hash_initval; /* hash initialization */
59 struct rcu_head rcu; /* for call_rcu_bh */ 59 struct rcu_head rcu; /* for call_rcu */
60 struct net *net; /* netns for pernet list */ 60 struct net *net; /* netns for pernet list */
61 char ifname[IFNAMSIZ]; /* device ifname */ 61 char ifname[IFNAMSIZ]; /* device ifname */
62}; 62};
diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
index 4e6b53ab6c33..7875c98072eb 100644
--- a/net/ipv4/netfilter/nf_nat_h323.c
+++ b/net/ipv4/netfilter/nf_nat_h323.c
@@ -631,4 +631,4 @@ module_exit(fini);
631MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>"); 631MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
632MODULE_DESCRIPTION("H.323 NAT helper"); 632MODULE_DESCRIPTION("H.323 NAT helper");
633MODULE_LICENSE("GPL"); 633MODULE_LICENSE("GPL");
634MODULE_ALIAS("ip_nat_h323"); 634MODULE_ALIAS_NF_NAT_HELPER("h323");
diff --git a/net/ipv4/netfilter/nf_nat_pptp.c b/net/ipv4/netfilter/nf_nat_pptp.c
index 68b4d450391b..e17b4ee7604c 100644
--- a/net/ipv4/netfilter/nf_nat_pptp.c
+++ b/net/ipv4/netfilter/nf_nat_pptp.c
@@ -37,7 +37,7 @@
37MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL");
38MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); 38MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
39MODULE_DESCRIPTION("Netfilter NAT helper module for PPTP"); 39MODULE_DESCRIPTION("Netfilter NAT helper module for PPTP");
40MODULE_ALIAS("ip_nat_pptp"); 40MODULE_ALIAS_NF_NAT_HELPER("pptp");
41 41
42static void pptp_nat_expected(struct nf_conn *ct, 42static void pptp_nat_expected(struct nf_conn *ct,
43 struct nf_conntrack_expect *exp) 43 struct nf_conntrack_expect *exp)
diff --git a/net/ipv4/netfilter/nft_chain_route_ipv4.c b/net/ipv4/netfilter/nft_chain_route_ipv4.c
deleted file mode 100644
index 7d82934c46f4..000000000000
--- a/net/ipv4/netfilter/nft_chain_route_ipv4.c
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2012 Pablo Neira Ayuso <pablo@netfilter.org>
4 *
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
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/list.h>
13#include <linux/skbuff.h>
14#include <linux/netlink.h>
15#include <linux/netfilter.h>
16#include <linux/netfilter_ipv4.h>
17#include <linux/netfilter/nfnetlink.h>
18#include <linux/netfilter/nf_tables.h>
19#include <net/netfilter/nf_tables.h>
20#include <net/netfilter/nf_tables_ipv4.h>
21#include <net/route.h>
22#include <net/ip.h>
23
24static unsigned int nf_route_table_hook(void *priv,
25 struct sk_buff *skb,
26 const struct nf_hook_state *state)
27{
28 unsigned int ret;
29 struct nft_pktinfo pkt;
30 u32 mark;
31 __be32 saddr, daddr;
32 u_int8_t tos;
33 const struct iphdr *iph;
34 int err;
35
36 nft_set_pktinfo(&pkt, skb, state);
37 nft_set_pktinfo_ipv4(&pkt, skb);
38
39 mark = skb->mark;
40 iph = ip_hdr(skb);
41 saddr = iph->saddr;
42 daddr = iph->daddr;
43 tos = iph->tos;
44
45 ret = nft_do_chain(&pkt, priv);
46 if (ret != NF_DROP && ret != NF_STOLEN) {
47 iph = ip_hdr(skb);
48
49 if (iph->saddr != saddr ||
50 iph->daddr != daddr ||
51 skb->mark != mark ||
52 iph->tos != tos) {
53 err = ip_route_me_harder(state->net, skb, RTN_UNSPEC);
54 if (err < 0)
55 ret = NF_DROP_ERR(err);
56 }
57 }
58 return ret;
59}
60
61static const struct nft_chain_type nft_chain_route_ipv4 = {
62 .name = "route",
63 .type = NFT_CHAIN_T_ROUTE,
64 .family = NFPROTO_IPV4,
65 .owner = THIS_MODULE,
66 .hook_mask = (1 << NF_INET_LOCAL_OUT),
67 .hooks = {
68 [NF_INET_LOCAL_OUT] = nf_route_table_hook,
69 },
70};
71
72static int __init nft_chain_route_init(void)
73{
74 nft_register_chain_type(&nft_chain_route_ipv4);
75
76 return 0;
77}
78
79static void __exit nft_chain_route_exit(void)
80{
81 nft_unregister_chain_type(&nft_chain_route_ipv4);
82}
83
84module_init(nft_chain_route_init);
85module_exit(nft_chain_route_exit);
86
87MODULE_LICENSE("GPL");
88MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
89MODULE_ALIAS_NFT_CHAIN(AF_INET, "route");
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index c55a5432cf37..dc91c27bb788 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -173,6 +173,7 @@ static int icmp_filter(const struct sock *sk, const struct sk_buff *skb)
173static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash) 173static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash)
174{ 174{
175 int sdif = inet_sdif(skb); 175 int sdif = inet_sdif(skb);
176 int dif = inet_iif(skb);
176 struct sock *sk; 177 struct sock *sk;
177 struct hlist_head *head; 178 struct hlist_head *head;
178 int delivered = 0; 179 int delivered = 0;
@@ -185,8 +186,7 @@ static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash)
185 186
186 net = dev_net(skb->dev); 187 net = dev_net(skb->dev);
187 sk = __raw_v4_lookup(net, __sk_head(head), iph->protocol, 188 sk = __raw_v4_lookup(net, __sk_head(head), iph->protocol,
188 iph->saddr, iph->daddr, 189 iph->saddr, iph->daddr, dif, sdif);
189 skb->dev->ifindex, sdif);
190 190
191 while (sk) { 191 while (sk) {
192 delivered = 1; 192 delivered = 1;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index a5da63e5faa2..11ddc276776e 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -434,37 +434,46 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
434 struct sk_buff *skb, 434 struct sk_buff *skb,
435 const void *daddr) 435 const void *daddr)
436{ 436{
437 const struct rtable *rt = container_of(dst, struct rtable, dst);
437 struct net_device *dev = dst->dev; 438 struct net_device *dev = dst->dev;
438 const __be32 *pkey = daddr;
439 const struct rtable *rt;
440 struct neighbour *n; 439 struct neighbour *n;
441 440
442 rt = (const struct rtable *) dst; 441 rcu_read_lock_bh();
443 if (rt->rt_gateway) 442
444 pkey = (const __be32 *) &rt->rt_gateway; 443 if (likely(rt->rt_gw_family == AF_INET)) {
445 else if (skb) 444 n = ip_neigh_gw4(dev, rt->rt_gw4);
446 pkey = &ip_hdr(skb)->daddr; 445 } else if (rt->rt_gw_family == AF_INET6) {
446 n = ip_neigh_gw6(dev, &rt->rt_gw6);
447 } else {
448 __be32 pkey;
449
450 pkey = skb ? ip_hdr(skb)->daddr : *((__be32 *) daddr);
451 n = ip_neigh_gw4(dev, pkey);
452 }
453
454 if (n && !refcount_inc_not_zero(&n->refcnt))
455 n = NULL;
447 456
448 n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey); 457 rcu_read_unlock_bh();
449 if (n) 458
450 return n; 459 return n;
451 return neigh_create(&arp_tbl, pkey, dev);
452} 460}
453 461
454static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr) 462static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)
455{ 463{
464 const struct rtable *rt = container_of(dst, struct rtable, dst);
456 struct net_device *dev = dst->dev; 465 struct net_device *dev = dst->dev;
457 const __be32 *pkey = daddr; 466 const __be32 *pkey = daddr;
458 const struct rtable *rt;
459 467
460 rt = (const struct rtable *)dst; 468 if (rt->rt_gw_family == AF_INET) {
461 if (rt->rt_gateway) 469 pkey = (const __be32 *)&rt->rt_gw4;
462 pkey = (const __be32 *)&rt->rt_gateway; 470 } else if (rt->rt_gw_family == AF_INET6) {
463 else if (!daddr || 471 return __ipv6_confirm_neigh_stub(dev, &rt->rt_gw6);
472 } else if (!daddr ||
464 (rt->rt_flags & 473 (rt->rt_flags &
465 (RTCF_MULTICAST | RTCF_BROADCAST | RTCF_LOCAL))) 474 (RTCF_MULTICAST | RTCF_BROADCAST | RTCF_LOCAL))) {
466 return; 475 return;
467 476 }
468 __ipv4_confirm_neigh(dev, *(__force u32 *)pkey); 477 __ipv4_confirm_neigh(dev, *(__force u32 *)pkey);
469} 478}
470 479
@@ -500,15 +509,17 @@ EXPORT_SYMBOL(ip_idents_reserve);
500 509
501void __ip_select_ident(struct net *net, struct iphdr *iph, int segs) 510void __ip_select_ident(struct net *net, struct iphdr *iph, int segs)
502{ 511{
503 static u32 ip_idents_hashrnd __read_mostly;
504 u32 hash, id; 512 u32 hash, id;
505 513
506 net_get_random_once(&ip_idents_hashrnd, sizeof(ip_idents_hashrnd)); 514 /* Note the following code is not safe, but this is okay. */
515 if (unlikely(siphash_key_is_zero(&net->ipv4.ip_id_key)))
516 get_random_bytes(&net->ipv4.ip_id_key,
517 sizeof(net->ipv4.ip_id_key));
507 518
508 hash = jhash_3words((__force u32)iph->daddr, 519 hash = siphash_3u32((__force u32)iph->daddr,
509 (__force u32)iph->saddr, 520 (__force u32)iph->saddr,
510 iph->protocol ^ net_hash_mix(net), 521 iph->protocol,
511 ip_idents_hashrnd); 522 &net->ipv4.ip_id_key);
512 id = ip_idents_reserve(hash, segs); 523 id = ip_idents_reserve(hash, segs);
513 iph->id = htons(id); 524 iph->id = htons(id);
514} 525}
@@ -627,13 +638,14 @@ static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnh
627 638
628 if (fnhe->fnhe_gw) { 639 if (fnhe->fnhe_gw) {
629 rt->rt_flags |= RTCF_REDIRECTED; 640 rt->rt_flags |= RTCF_REDIRECTED;
630 rt->rt_gateway = fnhe->fnhe_gw; 641 rt->rt_gw_family = AF_INET;
631 rt->rt_uses_gateway = 1; 642 rt->rt_gw4 = fnhe->fnhe_gw;
632 } 643 }
633} 644}
634 645
635static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw, 646static void update_or_create_fnhe(struct fib_nh_common *nhc, __be32 daddr,
636 u32 pmtu, bool lock, unsigned long expires) 647 __be32 gw, u32 pmtu, bool lock,
648 unsigned long expires)
637{ 649{
638 struct fnhe_hash_bucket *hash; 650 struct fnhe_hash_bucket *hash;
639 struct fib_nh_exception *fnhe; 651 struct fib_nh_exception *fnhe;
@@ -642,17 +654,17 @@ static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw,
642 unsigned int i; 654 unsigned int i;
643 int depth; 655 int depth;
644 656
645 genid = fnhe_genid(dev_net(nh->nh_dev)); 657 genid = fnhe_genid(dev_net(nhc->nhc_dev));
646 hval = fnhe_hashfun(daddr); 658 hval = fnhe_hashfun(daddr);
647 659
648 spin_lock_bh(&fnhe_lock); 660 spin_lock_bh(&fnhe_lock);
649 661
650 hash = rcu_dereference(nh->nh_exceptions); 662 hash = rcu_dereference(nhc->nhc_exceptions);
651 if (!hash) { 663 if (!hash) {
652 hash = kcalloc(FNHE_HASH_SIZE, sizeof(*hash), GFP_ATOMIC); 664 hash = kcalloc(FNHE_HASH_SIZE, sizeof(*hash), GFP_ATOMIC);
653 if (!hash) 665 if (!hash)
654 goto out_unlock; 666 goto out_unlock;
655 rcu_assign_pointer(nh->nh_exceptions, hash); 667 rcu_assign_pointer(nhc->nhc_exceptions, hash);
656 } 668 }
657 669
658 hash += hval; 670 hash += hval;
@@ -704,13 +716,13 @@ static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw,
704 * stale, so anyone caching it rechecks if this exception 716 * stale, so anyone caching it rechecks if this exception
705 * applies to them. 717 * applies to them.
706 */ 718 */
707 rt = rcu_dereference(nh->nh_rth_input); 719 rt = rcu_dereference(nhc->nhc_rth_input);
708 if (rt) 720 if (rt)
709 rt->dst.obsolete = DST_OBSOLETE_KILL; 721 rt->dst.obsolete = DST_OBSOLETE_KILL;
710 722
711 for_each_possible_cpu(i) { 723 for_each_possible_cpu(i) {
712 struct rtable __rcu **prt; 724 struct rtable __rcu **prt;
713 prt = per_cpu_ptr(nh->nh_pcpu_rth_output, i); 725 prt = per_cpu_ptr(nhc->nhc_pcpu_rth_output, i);
714 rt = rcu_dereference(*prt); 726 rt = rcu_dereference(*prt);
715 if (rt) 727 if (rt)
716 rt->dst.obsolete = DST_OBSOLETE_KILL; 728 rt->dst.obsolete = DST_OBSOLETE_KILL;
@@ -745,7 +757,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow
745 return; 757 return;
746 } 758 }
747 759
748 if (rt->rt_gateway != old_gw) 760 if (rt->rt_gw_family != AF_INET || rt->rt_gw4 != old_gw)
749 return; 761 return;
750 762
751 in_dev = __in_dev_get_rcu(dev); 763 in_dev = __in_dev_get_rcu(dev);
@@ -776,9 +788,9 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow
776 neigh_event_send(n, NULL); 788 neigh_event_send(n, NULL);
777 } else { 789 } else {
778 if (fib_lookup(net, fl4, &res, 0) == 0) { 790 if (fib_lookup(net, fl4, &res, 0) == 0) {
779 struct fib_nh *nh = &FIB_RES_NH(res); 791 struct fib_nh_common *nhc = FIB_RES_NHC(res);
780 792
781 update_or_create_fnhe(nh, fl4->daddr, new_gw, 793 update_or_create_fnhe(nhc, fl4->daddr, new_gw,
782 0, false, 794 0, false,
783 jiffies + ip_rt_gc_timeout); 795 jiffies + ip_rt_gc_timeout);
784 } 796 }
@@ -1025,9 +1037,9 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
1025 1037
1026 rcu_read_lock(); 1038 rcu_read_lock();
1027 if (fib_lookup(dev_net(dst->dev), fl4, &res, 0) == 0) { 1039 if (fib_lookup(dev_net(dst->dev), fl4, &res, 0) == 0) {
1028 struct fib_nh *nh = &FIB_RES_NH(res); 1040 struct fib_nh_common *nhc = FIB_RES_NHC(res);
1029 1041
1030 update_or_create_fnhe(nh, fl4->daddr, 0, mtu, lock, 1042 update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock,
1031 jiffies + ip_rt_mtu_expires); 1043 jiffies + ip_rt_mtu_expires);
1032 } 1044 }
1033 rcu_read_unlock(); 1045 rcu_read_unlock();
@@ -1176,18 +1188,46 @@ static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie)
1176 * 1188 *
1177 * When a PMTU/redirect information update invalidates a route, 1189 * When a PMTU/redirect information update invalidates a route,
1178 * this is indicated by setting obsolete to DST_OBSOLETE_KILL or 1190 * this is indicated by setting obsolete to DST_OBSOLETE_KILL or
1179 * DST_OBSOLETE_DEAD by dst_free(). 1191 * DST_OBSOLETE_DEAD.
1180 */ 1192 */
1181 if (dst->obsolete != DST_OBSOLETE_FORCE_CHK || rt_is_expired(rt)) 1193 if (dst->obsolete != DST_OBSOLETE_FORCE_CHK || rt_is_expired(rt))
1182 return NULL; 1194 return NULL;
1183 return dst; 1195 return dst;
1184} 1196}
1185 1197
1198static void ipv4_send_dest_unreach(struct sk_buff *skb)
1199{
1200 struct ip_options opt;
1201 int res;
1202
1203 /* Recompile ip options since IPCB may not be valid anymore.
1204 * Also check we have a reasonable ipv4 header.
1205 */
1206 if (!pskb_network_may_pull(skb, sizeof(struct iphdr)) ||
1207 ip_hdr(skb)->version != 4 || ip_hdr(skb)->ihl < 5)
1208 return;
1209
1210 memset(&opt, 0, sizeof(opt));
1211 if (ip_hdr(skb)->ihl > 5) {
1212 if (!pskb_network_may_pull(skb, ip_hdr(skb)->ihl * 4))
1213 return;
1214 opt.optlen = ip_hdr(skb)->ihl * 4 - sizeof(struct iphdr);
1215
1216 rcu_read_lock();
1217 res = __ip_options_compile(dev_net(skb->dev), &opt, skb, NULL);
1218 rcu_read_unlock();
1219
1220 if (res)
1221 return;
1222 }
1223 __icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0, &opt);
1224}
1225
1186static void ipv4_link_failure(struct sk_buff *skb) 1226static void ipv4_link_failure(struct sk_buff *skb)
1187{ 1227{
1188 struct rtable *rt; 1228 struct rtable *rt;
1189 1229
1190 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0); 1230 ipv4_send_dest_unreach(skb);
1191 1231
1192 rt = skb_rtable(skb); 1232 rt = skb_rtable(skb);
1193 if (rt) 1233 if (rt)
@@ -1233,7 +1273,7 @@ void ip_rt_get_source(u8 *addr, struct sk_buff *skb, struct rtable *rt)
1233 1273
1234 rcu_read_lock(); 1274 rcu_read_lock();
1235 if (fib_lookup(dev_net(rt->dst.dev), &fl4, &res, 0) == 0) 1275 if (fib_lookup(dev_net(rt->dst.dev), &fl4, &res, 0) == 0)
1236 src = FIB_RES_PREFSRC(dev_net(rt->dst.dev), res); 1276 src = fib_result_prefsrc(dev_net(rt->dst.dev), &res);
1237 else 1277 else
1238 src = inet_select_addr(rt->dst.dev, 1278 src = inet_select_addr(rt->dst.dev,
1239 rt_nexthop(rt, iph->daddr), 1279 rt_nexthop(rt, iph->daddr),
@@ -1276,7 +1316,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst)
1276 mtu = READ_ONCE(dst->dev->mtu); 1316 mtu = READ_ONCE(dst->dev->mtu);
1277 1317
1278 if (unlikely(ip_mtu_locked(dst))) { 1318 if (unlikely(ip_mtu_locked(dst))) {
1279 if (rt->rt_uses_gateway && mtu > 576) 1319 if (rt->rt_gw_family && mtu > 576)
1280 mtu = 576; 1320 mtu = 576;
1281 } 1321 }
1282 1322
@@ -1285,7 +1325,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst)
1285 return mtu - lwtunnel_headroom(dst->lwtstate, mtu); 1325 return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
1286} 1326}
1287 1327
1288static void ip_del_fnhe(struct fib_nh *nh, __be32 daddr) 1328static void ip_del_fnhe(struct fib_nh_common *nhc, __be32 daddr)
1289{ 1329{
1290 struct fnhe_hash_bucket *hash; 1330 struct fnhe_hash_bucket *hash;
1291 struct fib_nh_exception *fnhe, __rcu **fnhe_p; 1331 struct fib_nh_exception *fnhe, __rcu **fnhe_p;
@@ -1293,7 +1333,7 @@ static void ip_del_fnhe(struct fib_nh *nh, __be32 daddr)
1293 1333
1294 spin_lock_bh(&fnhe_lock); 1334 spin_lock_bh(&fnhe_lock);
1295 1335
1296 hash = rcu_dereference_protected(nh->nh_exceptions, 1336 hash = rcu_dereference_protected(nhc->nhc_exceptions,
1297 lockdep_is_held(&fnhe_lock)); 1337 lockdep_is_held(&fnhe_lock));
1298 hash += hval; 1338 hash += hval;
1299 1339
@@ -1319,9 +1359,10 @@ static void ip_del_fnhe(struct fib_nh *nh, __be32 daddr)
1319 spin_unlock_bh(&fnhe_lock); 1359 spin_unlock_bh(&fnhe_lock);
1320} 1360}
1321 1361
1322static struct fib_nh_exception *find_exception(struct fib_nh *nh, __be32 daddr) 1362static struct fib_nh_exception *find_exception(struct fib_nh_common *nhc,
1363 __be32 daddr)
1323{ 1364{
1324 struct fnhe_hash_bucket *hash = rcu_dereference(nh->nh_exceptions); 1365 struct fnhe_hash_bucket *hash = rcu_dereference(nhc->nhc_exceptions);
1325 struct fib_nh_exception *fnhe; 1366 struct fib_nh_exception *fnhe;
1326 u32 hval; 1367 u32 hval;
1327 1368
@@ -1335,7 +1376,7 @@ static struct fib_nh_exception *find_exception(struct fib_nh *nh, __be32 daddr)
1335 if (fnhe->fnhe_daddr == daddr) { 1376 if (fnhe->fnhe_daddr == daddr) {
1336 if (fnhe->fnhe_expires && 1377 if (fnhe->fnhe_expires &&
1337 time_after(jiffies, fnhe->fnhe_expires)) { 1378 time_after(jiffies, fnhe->fnhe_expires)) {
1338 ip_del_fnhe(nh, daddr); 1379 ip_del_fnhe(nhc, daddr);
1339 break; 1380 break;
1340 } 1381 }
1341 return fnhe; 1382 return fnhe;
@@ -1352,9 +1393,9 @@ static struct fib_nh_exception *find_exception(struct fib_nh *nh, __be32 daddr)
1352 1393
1353u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr) 1394u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr)
1354{ 1395{
1396 struct fib_nh_common *nhc = res->nhc;
1397 struct net_device *dev = nhc->nhc_dev;
1355 struct fib_info *fi = res->fi; 1398 struct fib_info *fi = res->fi;
1356 struct fib_nh *nh = &fi->fib_nh[res->nh_sel];
1357 struct net_device *dev = nh->nh_dev;
1358 u32 mtu = 0; 1399 u32 mtu = 0;
1359 1400
1360 if (dev_net(dev)->ipv4.sysctl_ip_fwd_use_pmtu || 1401 if (dev_net(dev)->ipv4.sysctl_ip_fwd_use_pmtu ||
@@ -1364,7 +1405,7 @@ u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr)
1364 if (likely(!mtu)) { 1405 if (likely(!mtu)) {
1365 struct fib_nh_exception *fnhe; 1406 struct fib_nh_exception *fnhe;
1366 1407
1367 fnhe = find_exception(nh, daddr); 1408 fnhe = find_exception(nhc, daddr);
1368 if (fnhe && !time_after_eq(jiffies, fnhe->fnhe_expires)) 1409 if (fnhe && !time_after_eq(jiffies, fnhe->fnhe_expires))
1369 mtu = fnhe->fnhe_pmtu; 1410 mtu = fnhe->fnhe_pmtu;
1370 } 1411 }
@@ -1372,7 +1413,7 @@ u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr)
1372 if (likely(!mtu)) 1413 if (likely(!mtu))
1373 mtu = min(READ_ONCE(dev->mtu), IP_MAX_MTU); 1414 mtu = min(READ_ONCE(dev->mtu), IP_MAX_MTU);
1374 1415
1375 return mtu - lwtunnel_headroom(nh->nh_lwtstate, mtu); 1416 return mtu - lwtunnel_headroom(nhc->nhc_lwtstate, mtu);
1376} 1417}
1377 1418
1378static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe, 1419static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
@@ -1403,8 +1444,10 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
1403 orig = NULL; 1444 orig = NULL;
1404 } 1445 }
1405 fill_route_from_fnhe(rt, fnhe); 1446 fill_route_from_fnhe(rt, fnhe);
1406 if (!rt->rt_gateway) 1447 if (!rt->rt_gw4) {
1407 rt->rt_gateway = daddr; 1448 rt->rt_gw4 = daddr;
1449 rt->rt_gw_family = AF_INET;
1450 }
1408 1451
1409 if (do_cache) { 1452 if (do_cache) {
1410 dst_hold(&rt->dst); 1453 dst_hold(&rt->dst);
@@ -1423,15 +1466,15 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
1423 return ret; 1466 return ret;
1424} 1467}
1425 1468
1426static bool rt_cache_route(struct fib_nh *nh, struct rtable *rt) 1469static bool rt_cache_route(struct fib_nh_common *nhc, struct rtable *rt)
1427{ 1470{
1428 struct rtable *orig, *prev, **p; 1471 struct rtable *orig, *prev, **p;
1429 bool ret = true; 1472 bool ret = true;
1430 1473
1431 if (rt_is_input_route(rt)) { 1474 if (rt_is_input_route(rt)) {
1432 p = (struct rtable **)&nh->nh_rth_input; 1475 p = (struct rtable **)&nhc->nhc_rth_input;
1433 } else { 1476 } else {
1434 p = (struct rtable **)raw_cpu_ptr(nh->nh_pcpu_rth_output); 1477 p = (struct rtable **)raw_cpu_ptr(nhc->nhc_pcpu_rth_output);
1435 } 1478 }
1436 orig = *p; 1479 orig = *p;
1437 1480
@@ -1527,30 +1570,42 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
1527 bool cached = false; 1570 bool cached = false;
1528 1571
1529 if (fi) { 1572 if (fi) {
1530 struct fib_nh *nh = &FIB_RES_NH(*res); 1573 struct fib_nh_common *nhc = FIB_RES_NHC(*res);
1531 1574
1532 if (nh->nh_gw && nh->nh_scope == RT_SCOPE_LINK) { 1575 if (nhc->nhc_gw_family && nhc->nhc_scope == RT_SCOPE_LINK) {
1533 rt->rt_gateway = nh->nh_gw; 1576 rt->rt_gw_family = nhc->nhc_gw_family;
1534 rt->rt_uses_gateway = 1; 1577 /* only INET and INET6 are supported */
1578 if (likely(nhc->nhc_gw_family == AF_INET))
1579 rt->rt_gw4 = nhc->nhc_gw.ipv4;
1580 else
1581 rt->rt_gw6 = nhc->nhc_gw.ipv6;
1535 } 1582 }
1583
1536 ip_dst_init_metrics(&rt->dst, fi->fib_metrics); 1584 ip_dst_init_metrics(&rt->dst, fi->fib_metrics);
1537 1585
1538#ifdef CONFIG_IP_ROUTE_CLASSID 1586#ifdef CONFIG_IP_ROUTE_CLASSID
1539 rt->dst.tclassid = nh->nh_tclassid; 1587 {
1588 struct fib_nh *nh;
1589
1590 nh = container_of(nhc, struct fib_nh, nh_common);
1591 rt->dst.tclassid = nh->nh_tclassid;
1592 }
1540#endif 1593#endif
1541 rt->dst.lwtstate = lwtstate_get(nh->nh_lwtstate); 1594 rt->dst.lwtstate = lwtstate_get(nhc->nhc_lwtstate);
1542 if (unlikely(fnhe)) 1595 if (unlikely(fnhe))
1543 cached = rt_bind_exception(rt, fnhe, daddr, do_cache); 1596 cached = rt_bind_exception(rt, fnhe, daddr, do_cache);
1544 else if (do_cache) 1597 else if (do_cache)
1545 cached = rt_cache_route(nh, rt); 1598 cached = rt_cache_route(nhc, rt);
1546 if (unlikely(!cached)) { 1599 if (unlikely(!cached)) {
1547 /* Routes we intend to cache in nexthop exception or 1600 /* Routes we intend to cache in nexthop exception or
1548 * FIB nexthop have the DST_NOCACHE bit clear. 1601 * FIB nexthop have the DST_NOCACHE bit clear.
1549 * However, if we are unsuccessful at storing this 1602 * However, if we are unsuccessful at storing this
1550 * route into the cache we really need to set it. 1603 * route into the cache we really need to set it.
1551 */ 1604 */
1552 if (!rt->rt_gateway) 1605 if (!rt->rt_gw4) {
1553 rt->rt_gateway = daddr; 1606 rt->rt_gw_family = AF_INET;
1607 rt->rt_gw4 = daddr;
1608 }
1554 rt_add_uncached_list(rt); 1609 rt_add_uncached_list(rt);
1555 } 1610 }
1556 } else 1611 } else
@@ -1583,8 +1638,8 @@ struct rtable *rt_dst_alloc(struct net_device *dev,
1583 rt->rt_iif = 0; 1638 rt->rt_iif = 0;
1584 rt->rt_pmtu = 0; 1639 rt->rt_pmtu = 0;
1585 rt->rt_mtu_locked = 0; 1640 rt->rt_mtu_locked = 0;
1586 rt->rt_gateway = 0; 1641 rt->rt_gw_family = 0;
1587 rt->rt_uses_gateway = 0; 1642 rt->rt_gw4 = 0;
1588 INIT_LIST_HEAD(&rt->rt_uncached); 1643 INIT_LIST_HEAD(&rt->rt_uncached);
1589 1644
1590 rt->dst.output = ip_output; 1645 rt->dst.output = ip_output;
@@ -1697,6 +1752,8 @@ static int __mkroute_input(struct sk_buff *skb,
1697 struct in_device *in_dev, 1752 struct in_device *in_dev,
1698 __be32 daddr, __be32 saddr, u32 tos) 1753 __be32 daddr, __be32 saddr, u32 tos)
1699{ 1754{
1755 struct fib_nh_common *nhc = FIB_RES_NHC(*res);
1756 struct net_device *dev = nhc->nhc_dev;
1700 struct fib_nh_exception *fnhe; 1757 struct fib_nh_exception *fnhe;
1701 struct rtable *rth; 1758 struct rtable *rth;
1702 int err; 1759 int err;
@@ -1705,7 +1762,7 @@ static int __mkroute_input(struct sk_buff *skb,
1705 u32 itag = 0; 1762 u32 itag = 0;
1706 1763
1707 /* get a working reference to the output device */ 1764 /* get a working reference to the output device */
1708 out_dev = __in_dev_get_rcu(FIB_RES_DEV(*res)); 1765 out_dev = __in_dev_get_rcu(dev);
1709 if (!out_dev) { 1766 if (!out_dev) {
1710 net_crit_ratelimited("Bug in ip_route_input_slow(). Please report.\n"); 1767 net_crit_ratelimited("Bug in ip_route_input_slow(). Please report.\n");
1711 return -EINVAL; 1768 return -EINVAL;
@@ -1722,10 +1779,14 @@ static int __mkroute_input(struct sk_buff *skb,
1722 1779
1723 do_cache = res->fi && !itag; 1780 do_cache = res->fi && !itag;
1724 if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) && 1781 if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) &&
1725 skb->protocol == htons(ETH_P_IP) && 1782 skb->protocol == htons(ETH_P_IP)) {
1726 (IN_DEV_SHARED_MEDIA(out_dev) || 1783 __be32 gw;
1727 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res)))) 1784
1728 IPCB(skb)->flags |= IPSKB_DOREDIRECT; 1785 gw = nhc->nhc_gw_family == AF_INET ? nhc->nhc_gw.ipv4 : 0;
1786 if (IN_DEV_SHARED_MEDIA(out_dev) ||
1787 inet_addr_onlink(out_dev, saddr, gw))
1788 IPCB(skb)->flags |= IPSKB_DOREDIRECT;
1789 }
1729 1790
1730 if (skb->protocol != htons(ETH_P_IP)) { 1791 if (skb->protocol != htons(ETH_P_IP)) {
1731 /* Not IP (i.e. ARP). Do not create route, if it is 1792 /* Not IP (i.e. ARP). Do not create route, if it is
@@ -1742,12 +1803,12 @@ static int __mkroute_input(struct sk_buff *skb,
1742 } 1803 }
1743 } 1804 }
1744 1805
1745 fnhe = find_exception(&FIB_RES_NH(*res), daddr); 1806 fnhe = find_exception(nhc, daddr);
1746 if (do_cache) { 1807 if (do_cache) {
1747 if (fnhe) 1808 if (fnhe)
1748 rth = rcu_dereference(fnhe->fnhe_rth_input); 1809 rth = rcu_dereference(fnhe->fnhe_rth_input);
1749 else 1810 else
1750 rth = rcu_dereference(FIB_RES_NH(*res).nh_rth_input); 1811 rth = rcu_dereference(nhc->nhc_rth_input);
1751 if (rt_cache_valid(rth)) { 1812 if (rt_cache_valid(rth)) {
1752 skb_dst_set_noref(skb, &rth->dst); 1813 skb_dst_set_noref(skb, &rth->dst);
1753 goto out; 1814 goto out;
@@ -2041,7 +2102,9 @@ local_input:
2041 do_cache = false; 2102 do_cache = false;
2042 if (res->fi) { 2103 if (res->fi) {
2043 if (!itag) { 2104 if (!itag) {
2044 rth = rcu_dereference(FIB_RES_NH(*res).nh_rth_input); 2105 struct fib_nh_common *nhc = FIB_RES_NHC(*res);
2106
2107 rth = rcu_dereference(nhc->nhc_rth_input);
2045 if (rt_cache_valid(rth)) { 2108 if (rt_cache_valid(rth)) {
2046 skb_dst_set_noref(skb, &rth->dst); 2109 skb_dst_set_noref(skb, &rth->dst);
2047 err = 0; 2110 err = 0;
@@ -2071,16 +2134,16 @@ local_input:
2071 } 2134 }
2072 2135
2073 if (do_cache) { 2136 if (do_cache) {
2074 struct fib_nh *nh = &FIB_RES_NH(*res); 2137 struct fib_nh_common *nhc = FIB_RES_NHC(*res);
2075 2138
2076 rth->dst.lwtstate = lwtstate_get(nh->nh_lwtstate); 2139 rth->dst.lwtstate = lwtstate_get(nhc->nhc_lwtstate);
2077 if (lwtunnel_input_redirect(rth->dst.lwtstate)) { 2140 if (lwtunnel_input_redirect(rth->dst.lwtstate)) {
2078 WARN_ON(rth->dst.input == lwtunnel_input); 2141 WARN_ON(rth->dst.input == lwtunnel_input);
2079 rth->dst.lwtstate->orig_input = rth->dst.input; 2142 rth->dst.lwtstate->orig_input = rth->dst.input;
2080 rth->dst.input = lwtunnel_input; 2143 rth->dst.input = lwtunnel_input;
2081 } 2144 }
2082 2145
2083 if (unlikely(!rt_cache_route(nh, rth))) 2146 if (unlikely(!rt_cache_route(nhc, rth)))
2084 rt_add_uncached_list(rth); 2147 rt_add_uncached_list(rth);
2085 } 2148 }
2086 skb_dst_set(skb, &rth->dst); 2149 skb_dst_set(skb, &rth->dst);
@@ -2251,10 +2314,10 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
2251 fnhe = NULL; 2314 fnhe = NULL;
2252 do_cache &= fi != NULL; 2315 do_cache &= fi != NULL;
2253 if (fi) { 2316 if (fi) {
2317 struct fib_nh_common *nhc = FIB_RES_NHC(*res);
2254 struct rtable __rcu **prth; 2318 struct rtable __rcu **prth;
2255 struct fib_nh *nh = &FIB_RES_NH(*res);
2256 2319
2257 fnhe = find_exception(nh, fl4->daddr); 2320 fnhe = find_exception(nhc, fl4->daddr);
2258 if (!do_cache) 2321 if (!do_cache)
2259 goto add; 2322 goto add;
2260 if (fnhe) { 2323 if (fnhe) {
@@ -2262,12 +2325,12 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
2262 } else { 2325 } else {
2263 if (unlikely(fl4->flowi4_flags & 2326 if (unlikely(fl4->flowi4_flags &
2264 FLOWI_FLAG_KNOWN_NH && 2327 FLOWI_FLAG_KNOWN_NH &&
2265 !(nh->nh_gw && 2328 !(nhc->nhc_gw_family &&
2266 nh->nh_scope == RT_SCOPE_LINK))) { 2329 nhc->nhc_scope == RT_SCOPE_LINK))) {
2267 do_cache = false; 2330 do_cache = false;
2268 goto add; 2331 goto add;
2269 } 2332 }
2270 prth = raw_cpu_ptr(nh->nh_pcpu_rth_output); 2333 prth = raw_cpu_ptr(nhc->nhc_pcpu_rth_output);
2271 } 2334 }
2272 rth = rcu_dereference(*prth); 2335 rth = rcu_dereference(*prth);
2273 if (rt_cache_valid(rth) && dst_hold_safe(&rth->dst)) 2336 if (rt_cache_valid(rth) && dst_hold_safe(&rth->dst))
@@ -2572,8 +2635,11 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or
2572 rt->rt_genid = rt_genid_ipv4(net); 2635 rt->rt_genid = rt_genid_ipv4(net);
2573 rt->rt_flags = ort->rt_flags; 2636 rt->rt_flags = ort->rt_flags;
2574 rt->rt_type = ort->rt_type; 2637 rt->rt_type = ort->rt_type;
2575 rt->rt_gateway = ort->rt_gateway; 2638 rt->rt_gw_family = ort->rt_gw_family;
2576 rt->rt_uses_gateway = ort->rt_uses_gateway; 2639 if (rt->rt_gw_family == AF_INET)
2640 rt->rt_gw4 = ort->rt_gw4;
2641 else if (rt->rt_gw_family == AF_INET6)
2642 rt->rt_gw6 = ort->rt_gw6;
2577 2643
2578 INIT_LIST_HEAD(&rt->rt_uncached); 2644 INIT_LIST_HEAD(&rt->rt_uncached);
2579 } 2645 }
@@ -2652,9 +2718,22 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
2652 if (nla_put_in_addr(skb, RTA_PREFSRC, fl4->saddr)) 2718 if (nla_put_in_addr(skb, RTA_PREFSRC, fl4->saddr))
2653 goto nla_put_failure; 2719 goto nla_put_failure;
2654 } 2720 }
2655 if (rt->rt_uses_gateway && 2721 if (rt->rt_gw_family == AF_INET &&
2656 nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gateway)) 2722 nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gw4)) {
2657 goto nla_put_failure; 2723 goto nla_put_failure;
2724 } else if (rt->rt_gw_family == AF_INET6) {
2725 int alen = sizeof(struct in6_addr);
2726 struct nlattr *nla;
2727 struct rtvia *via;
2728
2729 nla = nla_reserve(skb, RTA_VIA, alen + 2);
2730 if (!nla)
2731 goto nla_put_failure;
2732
2733 via = nla_data(nla);
2734 via->rtvia_family = AF_INET6;
2735 memcpy(via->rtvia_addr, &rt->rt_gw6, alen);
2736 }
2658 2737
2659 expires = rt->dst.expires; 2738 expires = rt->dst.expires;
2660 if (expires) { 2739 if (expires) {
@@ -2791,8 +2870,8 @@ static int inet_rtm_valid_getroute_req(struct sk_buff *skb,
2791 } 2870 }
2792 2871
2793 if (!netlink_strict_get_check(skb)) 2872 if (!netlink_strict_get_check(skb))
2794 return nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, 2873 return nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
2795 rtm_ipv4_policy, extack); 2874 rtm_ipv4_policy, extack);
2796 2875
2797 rtm = nlmsg_data(nlh); 2876 rtm = nlmsg_data(nlh);
2798 if ((rtm->rtm_src_len && rtm->rtm_src_len != 32) || 2877 if ((rtm->rtm_src_len && rtm->rtm_src_len != 32) ||
@@ -2810,8 +2889,8 @@ static int inet_rtm_valid_getroute_req(struct sk_buff *skb,
2810 return -EINVAL; 2889 return -EINVAL;
2811 } 2890 }
2812 2891
2813 err = nlmsg_parse_strict(nlh, sizeof(*rtm), tb, RTA_MAX, 2892 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX,
2814 rtm_ipv4_policy, extack); 2893 rtm_ipv4_policy, extack);
2815 if (err) 2894 if (err)
2816 return err; 2895 return err;
2817 2896
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index e531344611a0..008545f63667 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -216,16 +216,15 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb,
216 refcount_set(&req->rsk_refcnt, 1); 216 refcount_set(&req->rsk_refcnt, 1);
217 tcp_sk(child)->tsoffset = tsoff; 217 tcp_sk(child)->tsoffset = tsoff;
218 sock_rps_save_rxhash(child, skb); 218 sock_rps_save_rxhash(child, skb);
219 if (!inet_csk_reqsk_queue_add(sk, req, child)) { 219 if (inet_csk_reqsk_queue_add(sk, req, child))
220 bh_unlock_sock(child); 220 return child;
221 sock_put(child); 221
222 child = NULL; 222 bh_unlock_sock(child);
223 reqsk_put(req); 223 sock_put(child);
224 }
225 } else {
226 reqsk_free(req);
227 } 224 }
228 return child; 225 __reqsk_free(req);
226
227 return NULL;
229} 228}
230EXPORT_SYMBOL(tcp_get_cookie_sock); 229EXPORT_SYMBOL(tcp_get_cookie_sock);
231 230
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index ba0fc4b18465..875867b64d6a 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -49,6 +49,7 @@ static int ip_ping_group_range_min[] = { 0, 0 };
49static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX }; 49static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
50static int comp_sack_nr_max = 255; 50static int comp_sack_nr_max = 255;
51static u32 u32_max_div_HZ = UINT_MAX / HZ; 51static u32 u32_max_div_HZ = UINT_MAX / HZ;
52static int one_day_secs = 24 * 3600;
52 53
53/* obsolete */ 54/* obsolete */
54static int sysctl_tcp_low_latency __read_mostly; 55static int sysctl_tcp_low_latency __read_mostly;
@@ -549,6 +550,15 @@ static struct ctl_table ipv4_table[] = {
549 .mode = 0644, 550 .mode = 0644,
550 .proc_handler = proc_doulongvec_minmax, 551 .proc_handler = proc_doulongvec_minmax,
551 }, 552 },
553 {
554 .procname = "fib_sync_mem",
555 .data = &sysctl_fib_sync_mem,
556 .maxlen = sizeof(sysctl_fib_sync_mem),
557 .mode = 0644,
558 .proc_handler = proc_douintvec_minmax,
559 .extra1 = &sysctl_fib_sync_mem_min,
560 .extra2 = &sysctl_fib_sync_mem_max,
561 },
552 { } 562 { }
553}; 563};
554 564
@@ -1151,7 +1161,9 @@ static struct ctl_table ipv4_net_table[] = {
1151 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen, 1161 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1152 .maxlen = sizeof(int), 1162 .maxlen = sizeof(int),
1153 .mode = 0644, 1163 .mode = 0644,
1154 .proc_handler = proc_dointvec 1164 .proc_handler = proc_dointvec_minmax,
1165 .extra1 = &zero,
1166 .extra2 = &one_day_secs
1155 }, 1167 },
1156 { 1168 {
1157 .procname = "tcp_autocorking", 1169 .procname = "tcp_autocorking",
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 6baa6dc1b13b..1fa15beb8380 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -457,18 +457,6 @@ void tcp_init_sock(struct sock *sk)
457} 457}
458EXPORT_SYMBOL(tcp_init_sock); 458EXPORT_SYMBOL(tcp_init_sock);
459 459
460void tcp_init_transfer(struct sock *sk, int bpf_op)
461{
462 struct inet_connection_sock *icsk = inet_csk(sk);
463
464 tcp_mtup_init(sk);
465 icsk->icsk_af_ops->rebuild_header(sk);
466 tcp_init_metrics(sk);
467 tcp_call_bpf(sk, bpf_op, 0, NULL);
468 tcp_init_congestion_control(sk);
469 tcp_init_buffer_space(sk);
470}
471
472static void tcp_tx_timestamp(struct sock *sk, u16 tsflags) 460static void tcp_tx_timestamp(struct sock *sk, u16 tsflags)
473{ 461{
474 struct sk_buff *skb = tcp_write_queue_tail(sk); 462 struct sk_buff *skb = tcp_write_queue_tail(sk);
@@ -865,6 +853,18 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
865{ 853{
866 struct sk_buff *skb; 854 struct sk_buff *skb;
867 855
856 if (likely(!size)) {
857 skb = sk->sk_tx_skb_cache;
858 if (skb && !skb_cloned(skb)) {
859 skb->truesize = SKB_TRUESIZE(skb_end_offset(skb));
860 sk->sk_tx_skb_cache = NULL;
861 pskb_trim(skb, 0);
862 INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
863 skb_shinfo(skb)->tx_flags = 0;
864 memset(TCP_SKB_CB(skb), 0, sizeof(struct tcp_skb_cb));
865 return skb;
866 }
867 }
868 /* The TCP header must be at least 32-bit aligned. */ 868 /* The TCP header must be at least 32-bit aligned. */
869 size = ALIGN(size, 4); 869 size = ALIGN(size, 4);
870 870
@@ -1098,30 +1098,6 @@ int tcp_sendpage(struct sock *sk, struct page *page, int offset,
1098} 1098}
1099EXPORT_SYMBOL(tcp_sendpage); 1099EXPORT_SYMBOL(tcp_sendpage);
1100 1100
1101/* Do not bother using a page frag for very small frames.
1102 * But use this heuristic only for the first skb in write queue.
1103 *
1104 * Having no payload in skb->head allows better SACK shifting
1105 * in tcp_shift_skb_data(), reducing sack/rack overhead, because
1106 * write queue has less skbs.
1107 * Each skb can hold up to MAX_SKB_FRAGS * 32Kbytes, or ~0.5 MB.
1108 * This also speeds up tso_fragment(), since it wont fallback
1109 * to tcp_fragment().
1110 */
1111static int linear_payload_sz(bool first_skb)
1112{
1113 if (first_skb)
1114 return SKB_WITH_OVERHEAD(2048 - MAX_TCP_HEADER);
1115 return 0;
1116}
1117
1118static int select_size(bool first_skb, bool zc)
1119{
1120 if (zc)
1121 return 0;
1122 return linear_payload_sz(first_skb);
1123}
1124
1125void tcp_free_fastopen_req(struct tcp_sock *tp) 1101void tcp_free_fastopen_req(struct tcp_sock *tp)
1126{ 1102{
1127 if (tp->fastopen_req) { 1103 if (tp->fastopen_req) {
@@ -1272,7 +1248,6 @@ restart:
1272 1248
1273 if (copy <= 0 || !tcp_skb_can_collapse_to(skb)) { 1249 if (copy <= 0 || !tcp_skb_can_collapse_to(skb)) {
1274 bool first_skb; 1250 bool first_skb;
1275 int linear;
1276 1251
1277new_segment: 1252new_segment:
1278 if (!sk_stream_memory_free(sk)) 1253 if (!sk_stream_memory_free(sk))
@@ -1283,8 +1258,7 @@ new_segment:
1283 goto restart; 1258 goto restart;
1284 } 1259 }
1285 first_skb = tcp_rtx_and_write_queues_empty(sk); 1260 first_skb = tcp_rtx_and_write_queues_empty(sk);
1286 linear = select_size(first_skb, zc); 1261 skb = sk_stream_alloc_skb(sk, 0, sk->sk_allocation,
1287 skb = sk_stream_alloc_skb(sk, linear, sk->sk_allocation,
1288 first_skb); 1262 first_skb);
1289 if (!skb) 1263 if (!skb)
1290 goto wait_for_memory; 1264 goto wait_for_memory;
@@ -2552,6 +2526,11 @@ void tcp_write_queue_purge(struct sock *sk)
2552 sk_wmem_free_skb(sk, skb); 2526 sk_wmem_free_skb(sk, skb);
2553 } 2527 }
2554 tcp_rtx_queue_purge(sk); 2528 tcp_rtx_queue_purge(sk);
2529 skb = sk->sk_tx_skb_cache;
2530 if (skb) {
2531 __kfree_skb(skb);
2532 sk->sk_tx_skb_cache = NULL;
2533 }
2555 INIT_LIST_HEAD(&tcp_sk(sk)->tsorted_sent_queue); 2534 INIT_LIST_HEAD(&tcp_sk(sk)->tsorted_sent_queue);
2556 sk_mem_reclaim(sk); 2535 sk_mem_reclaim(sk);
2557 tcp_clear_all_retrans_hints(tcp_sk(sk)); 2536 tcp_clear_all_retrans_hints(tcp_sk(sk));
@@ -2587,6 +2566,10 @@ int tcp_disconnect(struct sock *sk, int flags)
2587 2566
2588 tcp_clear_xmit_timers(sk); 2567 tcp_clear_xmit_timers(sk);
2589 __skb_queue_purge(&sk->sk_receive_queue); 2568 __skb_queue_purge(&sk->sk_receive_queue);
2569 if (sk->sk_rx_skb_cache) {
2570 __kfree_skb(sk->sk_rx_skb_cache);
2571 sk->sk_rx_skb_cache = NULL;
2572 }
2590 tp->copied_seq = tp->rcv_nxt; 2573 tp->copied_seq = tp->rcv_nxt;
2591 tp->urg_data = 0; 2574 tp->urg_data = 0;
2592 tcp_write_queue_purge(sk); 2575 tcp_write_queue_purge(sk);
diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
index 359da68d7c06..477cb4aa456c 100644
--- a/net/ipv4/tcp_dctcp.c
+++ b/net/ipv4/tcp_dctcp.c
@@ -49,9 +49,8 @@
49#define DCTCP_MAX_ALPHA 1024U 49#define DCTCP_MAX_ALPHA 1024U
50 50
51struct dctcp { 51struct dctcp {
52 u32 acked_bytes_ecn; 52 u32 old_delivered;
53 u32 acked_bytes_total; 53 u32 old_delivered_ce;
54 u32 prior_snd_una;
55 u32 prior_rcv_nxt; 54 u32 prior_rcv_nxt;
56 u32 dctcp_alpha; 55 u32 dctcp_alpha;
57 u32 next_seq; 56 u32 next_seq;
@@ -73,8 +72,8 @@ static void dctcp_reset(const struct tcp_sock *tp, struct dctcp *ca)
73{ 72{
74 ca->next_seq = tp->snd_nxt; 73 ca->next_seq = tp->snd_nxt;
75 74
76 ca->acked_bytes_ecn = 0; 75 ca->old_delivered = tp->delivered;
77 ca->acked_bytes_total = 0; 76 ca->old_delivered_ce = tp->delivered_ce;
78} 77}
79 78
80static void dctcp_init(struct sock *sk) 79static void dctcp_init(struct sock *sk)
@@ -86,7 +85,6 @@ static void dctcp_init(struct sock *sk)
86 sk->sk_state == TCP_CLOSE)) { 85 sk->sk_state == TCP_CLOSE)) {
87 struct dctcp *ca = inet_csk_ca(sk); 86 struct dctcp *ca = inet_csk_ca(sk);
88 87
89 ca->prior_snd_una = tp->snd_una;
90 ca->prior_rcv_nxt = tp->rcv_nxt; 88 ca->prior_rcv_nxt = tp->rcv_nxt;
91 89
92 ca->dctcp_alpha = min(dctcp_alpha_on_init, DCTCP_MAX_ALPHA); 90 ca->dctcp_alpha = min(dctcp_alpha_on_init, DCTCP_MAX_ALPHA);
@@ -118,37 +116,25 @@ static void dctcp_update_alpha(struct sock *sk, u32 flags)
118{ 116{
119 const struct tcp_sock *tp = tcp_sk(sk); 117 const struct tcp_sock *tp = tcp_sk(sk);
120 struct dctcp *ca = inet_csk_ca(sk); 118 struct dctcp *ca = inet_csk_ca(sk);
121 u32 acked_bytes = tp->snd_una - ca->prior_snd_una;
122
123 /* If ack did not advance snd_una, count dupack as MSS size.
124 * If ack did update window, do not count it at all.
125 */
126 if (acked_bytes == 0 && !(flags & CA_ACK_WIN_UPDATE))
127 acked_bytes = inet_csk(sk)->icsk_ack.rcv_mss;
128 if (acked_bytes) {
129 ca->acked_bytes_total += acked_bytes;
130 ca->prior_snd_una = tp->snd_una;
131
132 if (flags & CA_ACK_ECE)
133 ca->acked_bytes_ecn += acked_bytes;
134 }
135 119
136 /* Expired RTT */ 120 /* Expired RTT */
137 if (!before(tp->snd_una, ca->next_seq)) { 121 if (!before(tp->snd_una, ca->next_seq)) {
138 u64 bytes_ecn = ca->acked_bytes_ecn; 122 u32 delivered_ce = tp->delivered_ce - ca->old_delivered_ce;
139 u32 alpha = ca->dctcp_alpha; 123 u32 alpha = ca->dctcp_alpha;
140 124
141 /* alpha = (1 - g) * alpha + g * F */ 125 /* alpha = (1 - g) * alpha + g * F */
142 126
143 alpha -= min_not_zero(alpha, alpha >> dctcp_shift_g); 127 alpha -= min_not_zero(alpha, alpha >> dctcp_shift_g);
144 if (bytes_ecn) { 128 if (delivered_ce) {
129 u32 delivered = tp->delivered - ca->old_delivered;
130
145 /* If dctcp_shift_g == 1, a 32bit value would overflow 131 /* If dctcp_shift_g == 1, a 32bit value would overflow
146 * after 8 Mbytes. 132 * after 8 M packets.
147 */ 133 */
148 bytes_ecn <<= (10 - dctcp_shift_g); 134 delivered_ce <<= (10 - dctcp_shift_g);
149 do_div(bytes_ecn, max(1U, ca->acked_bytes_total)); 135 delivered_ce /= max(1U, delivered);
150 136
151 alpha = min(alpha + (u32)bytes_ecn, DCTCP_MAX_ALPHA); 137 alpha = min(alpha + delivered_ce, DCTCP_MAX_ALPHA);
152 } 138 }
153 /* dctcp_alpha can be read from dctcp_get_info() without 139 /* dctcp_alpha can be read from dctcp_get_info() without
154 * synchro, so we ask compiler to not use dctcp_alpha 140 * synchro, so we ask compiler to not use dctcp_alpha
@@ -200,6 +186,7 @@ static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
200 union tcp_cc_info *info) 186 union tcp_cc_info *info)
201{ 187{
202 const struct dctcp *ca = inet_csk_ca(sk); 188 const struct dctcp *ca = inet_csk_ca(sk);
189 const struct tcp_sock *tp = tcp_sk(sk);
203 190
204 /* Fill it also in case of VEGASINFO due to req struct limits. 191 /* Fill it also in case of VEGASINFO due to req struct limits.
205 * We can still correctly retrieve it later. 192 * We can still correctly retrieve it later.
@@ -211,8 +198,10 @@ static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
211 info->dctcp.dctcp_enabled = 1; 198 info->dctcp.dctcp_enabled = 1;
212 info->dctcp.dctcp_ce_state = (u16) ca->ce_state; 199 info->dctcp.dctcp_ce_state = (u16) ca->ce_state;
213 info->dctcp.dctcp_alpha = ca->dctcp_alpha; 200 info->dctcp.dctcp_alpha = ca->dctcp_alpha;
214 info->dctcp.dctcp_ab_ecn = ca->acked_bytes_ecn; 201 info->dctcp.dctcp_ab_ecn = tp->mss_cache *
215 info->dctcp.dctcp_ab_tot = ca->acked_bytes_total; 202 (tp->delivered_ce - ca->old_delivered_ce);
203 info->dctcp.dctcp_ab_tot = tp->mss_cache *
204 (tp->delivered - ca->old_delivered);
216 } 205 }
217 206
218 *attr = INET_DIAG_DCTCPINFO; 207 *attr = INET_DIAG_DCTCPINFO;
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 5def3c48870e..20f6fac5882e 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -77,7 +77,7 @@
77#include <asm/unaligned.h> 77#include <asm/unaligned.h>
78#include <linux/errqueue.h> 78#include <linux/errqueue.h>
79#include <trace/events/tcp.h> 79#include <trace/events/tcp.h>
80#include <linux/static_key.h> 80#include <linux/jump_label_ratelimit.h>
81#include <net/busy_poll.h> 81#include <net/busy_poll.h>
82 82
83int sysctl_tcp_max_orphans __read_mostly = NR_FILE; 83int sysctl_tcp_max_orphans __read_mostly = NR_FILE;
@@ -113,22 +113,28 @@ int sysctl_tcp_max_orphans __read_mostly = NR_FILE;
113#define REXMIT_NEW 2 /* FRTO-style transmit of unsent/new packets */ 113#define REXMIT_NEW 2 /* FRTO-style transmit of unsent/new packets */
114 114
115#if IS_ENABLED(CONFIG_TLS_DEVICE) 115#if IS_ENABLED(CONFIG_TLS_DEVICE)
116static DEFINE_STATIC_KEY_FALSE(clean_acked_data_enabled); 116static DEFINE_STATIC_KEY_DEFERRED_FALSE(clean_acked_data_enabled, HZ);
117 117
118void clean_acked_data_enable(struct inet_connection_sock *icsk, 118void clean_acked_data_enable(struct inet_connection_sock *icsk,
119 void (*cad)(struct sock *sk, u32 ack_seq)) 119 void (*cad)(struct sock *sk, u32 ack_seq))
120{ 120{
121 icsk->icsk_clean_acked = cad; 121 icsk->icsk_clean_acked = cad;
122 static_branch_inc(&clean_acked_data_enabled); 122 static_branch_inc(&clean_acked_data_enabled.key);
123} 123}
124EXPORT_SYMBOL_GPL(clean_acked_data_enable); 124EXPORT_SYMBOL_GPL(clean_acked_data_enable);
125 125
126void clean_acked_data_disable(struct inet_connection_sock *icsk) 126void clean_acked_data_disable(struct inet_connection_sock *icsk)
127{ 127{
128 static_branch_dec(&clean_acked_data_enabled); 128 static_branch_slow_dec_deferred(&clean_acked_data_enabled);
129 icsk->icsk_clean_acked = NULL; 129 icsk->icsk_clean_acked = NULL;
130} 130}
131EXPORT_SYMBOL_GPL(clean_acked_data_disable); 131EXPORT_SYMBOL_GPL(clean_acked_data_disable);
132
133void clean_acked_data_flush(void)
134{
135 static_key_deferred_flush(&clean_acked_data_enabled);
136}
137EXPORT_SYMBOL_GPL(clean_acked_data_flush);
132#endif 138#endif
133 139
134static void tcp_gro_dev_warn(struct sock *sk, const struct sk_buff *skb, 140static void tcp_gro_dev_warn(struct sock *sk, const struct sk_buff *skb,
@@ -402,11 +408,12 @@ static int __tcp_grow_window(const struct sock *sk, const struct sk_buff *skb)
402static void tcp_grow_window(struct sock *sk, const struct sk_buff *skb) 408static void tcp_grow_window(struct sock *sk, const struct sk_buff *skb)
403{ 409{
404 struct tcp_sock *tp = tcp_sk(sk); 410 struct tcp_sock *tp = tcp_sk(sk);
411 int room;
412
413 room = min_t(int, tp->window_clamp, tcp_space(sk)) - tp->rcv_ssthresh;
405 414
406 /* Check #1 */ 415 /* Check #1 */
407 if (tp->rcv_ssthresh < tp->window_clamp && 416 if (room > 0 && !tcp_under_memory_pressure(sk)) {
408 (int)tp->rcv_ssthresh < tcp_space(sk) &&
409 !tcp_under_memory_pressure(sk)) {
410 int incr; 417 int incr;
411 418
412 /* Check #2. Increase window, if skb with such overhead 419 /* Check #2. Increase window, if skb with such overhead
@@ -419,8 +426,7 @@ static void tcp_grow_window(struct sock *sk, const struct sk_buff *skb)
419 426
420 if (incr) { 427 if (incr) {
421 incr = max_t(int, incr, 2 * skb->len); 428 incr = max_t(int, incr, 2 * skb->len);
422 tp->rcv_ssthresh = min(tp->rcv_ssthresh + incr, 429 tp->rcv_ssthresh += min(room, incr);
423 tp->window_clamp);
424 inet_csk(sk)->icsk_ack.quick |= 1; 430 inet_csk(sk)->icsk_ack.quick |= 1;
425 } 431 }
426 } 432 }
@@ -2252,7 +2258,7 @@ static bool tcp_skb_spurious_retrans(const struct tcp_sock *tp,
2252 */ 2258 */
2253static inline bool tcp_packet_delayed(const struct tcp_sock *tp) 2259static inline bool tcp_packet_delayed(const struct tcp_sock *tp)
2254{ 2260{
2255 return !tp->retrans_stamp || 2261 return tp->retrans_stamp &&
2256 tcp_tsopt_ecr_before(tp, tp->retrans_stamp); 2262 tcp_tsopt_ecr_before(tp, tp->retrans_stamp);
2257} 2263}
2258 2264
@@ -3521,7 +3527,7 @@ static void tcp_xmit_recovery(struct sock *sk, int rexmit)
3521{ 3527{
3522 struct tcp_sock *tp = tcp_sk(sk); 3528 struct tcp_sock *tp = tcp_sk(sk);
3523 3529
3524 if (rexmit == REXMIT_NONE) 3530 if (rexmit == REXMIT_NONE || sk->sk_state == TCP_SYN_SENT)
3525 return; 3531 return;
3526 3532
3527 if (unlikely(rexmit == 2)) { 3533 if (unlikely(rexmit == 2)) {
@@ -3598,7 +3604,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
3598 icsk->icsk_retransmits = 0; 3604 icsk->icsk_retransmits = 0;
3599 3605
3600#if IS_ENABLED(CONFIG_TLS_DEVICE) 3606#if IS_ENABLED(CONFIG_TLS_DEVICE)
3601 if (static_branch_unlikely(&clean_acked_data_enabled)) 3607 if (static_branch_unlikely(&clean_acked_data_enabled.key))
3602 if (icsk->icsk_clean_acked) 3608 if (icsk->icsk_clean_acked)
3603 icsk->icsk_clean_acked(sk, ack); 3609 icsk->icsk_clean_acked(sk, ack);
3604#endif 3610#endif
@@ -5647,6 +5653,32 @@ discard:
5647} 5653}
5648EXPORT_SYMBOL(tcp_rcv_established); 5654EXPORT_SYMBOL(tcp_rcv_established);
5649 5655
5656void tcp_init_transfer(struct sock *sk, int bpf_op)
5657{
5658 struct inet_connection_sock *icsk = inet_csk(sk);
5659 struct tcp_sock *tp = tcp_sk(sk);
5660
5661 tcp_mtup_init(sk);
5662 icsk->icsk_af_ops->rebuild_header(sk);
5663 tcp_init_metrics(sk);
5664
5665 /* Initialize the congestion window to start the transfer.
5666 * Cut cwnd down to 1 per RFC5681 if SYN or SYN-ACK has been
5667 * retransmitted. In light of RFC6298 more aggressive 1sec
5668 * initRTO, we only reset cwnd when more than 1 SYN/SYN-ACK
5669 * retransmission has occurred.
5670 */
5671 if (tp->total_retrans > 1 && tp->undo_marker)
5672 tp->snd_cwnd = 1;
5673 else
5674 tp->snd_cwnd = tcp_init_cwnd(tp, __sk_dst_get(sk));
5675 tp->snd_cwnd_stamp = tcp_jiffies32;
5676
5677 tcp_call_bpf(sk, bpf_op, 0, NULL);
5678 tcp_init_congestion_control(sk);
5679 tcp_init_buffer_space(sk);
5680}
5681
5650void tcp_finish_connect(struct sock *sk, struct sk_buff *skb) 5682void tcp_finish_connect(struct sock *sk, struct sk_buff *skb)
5651{ 5683{
5652 struct tcp_sock *tp = tcp_sk(sk); 5684 struct tcp_sock *tp = tcp_sk(sk);
@@ -5748,6 +5780,21 @@ static void smc_check_reset_syn(struct tcp_sock *tp)
5748#endif 5780#endif
5749} 5781}
5750 5782
5783static void tcp_try_undo_spurious_syn(struct sock *sk)
5784{
5785 struct tcp_sock *tp = tcp_sk(sk);
5786 u32 syn_stamp;
5787
5788 /* undo_marker is set when SYN or SYNACK times out. The timeout is
5789 * spurious if the ACK's timestamp option echo value matches the
5790 * original SYN timestamp.
5791 */
5792 syn_stamp = tp->retrans_stamp;
5793 if (tp->undo_marker && syn_stamp && tp->rx_opt.saw_tstamp &&
5794 syn_stamp == tp->rx_opt.rcv_tsecr)
5795 tp->undo_marker = 0;
5796}
5797
5751static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, 5798static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
5752 const struct tcphdr *th) 5799 const struct tcphdr *th)
5753{ 5800{
@@ -5815,6 +5862,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
5815 tcp_ecn_rcv_synack(tp, th); 5862 tcp_ecn_rcv_synack(tp, th);
5816 5863
5817 tcp_init_wl(tp, TCP_SKB_CB(skb)->seq); 5864 tcp_init_wl(tp, TCP_SKB_CB(skb)->seq);
5865 tcp_try_undo_spurious_syn(sk);
5818 tcp_ack(sk, skb, FLAG_SLOWPATH); 5866 tcp_ack(sk, skb, FLAG_SLOWPATH);
5819 5867
5820 /* Ok.. it's good. Set up sequence numbers and 5868 /* Ok.. it's good. Set up sequence numbers and
@@ -5973,6 +6021,27 @@ reset_and_undo:
5973 return 1; 6021 return 1;
5974} 6022}
5975 6023
6024static void tcp_rcv_synrecv_state_fastopen(struct sock *sk)
6025{
6026 tcp_try_undo_loss(sk, false);
6027 inet_csk(sk)->icsk_retransmits = 0;
6028
6029 /* Once we leave TCP_SYN_RECV or TCP_FIN_WAIT_1,
6030 * we no longer need req so release it.
6031 */
6032 reqsk_fastopen_remove(sk, tcp_sk(sk)->fastopen_rsk, false);
6033
6034 /* Re-arm the timer because data may have been sent out.
6035 * This is similar to the regular data transmission case
6036 * when new data has just been ack'ed.
6037 *
6038 * (TFO) - we could try to be more aggressive and
6039 * retransmitting any data sooner based on when they
6040 * are sent out.
6041 */
6042 tcp_rearm_rto(sk);
6043}
6044
5976/* 6045/*
5977 * This function implements the receiving procedure of RFC 793 for 6046 * This function implements the receiving procedure of RFC 793 for
5978 * all states except ESTABLISHED and TIME_WAIT. 6047 * all states except ESTABLISHED and TIME_WAIT.
@@ -6069,22 +6138,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
6069 if (!tp->srtt_us) 6138 if (!tp->srtt_us)
6070 tcp_synack_rtt_meas(sk, req); 6139 tcp_synack_rtt_meas(sk, req);
6071 6140
6072 /* Once we leave TCP_SYN_RECV, we no longer need req
6073 * so release it.
6074 */
6075 if (req) { 6141 if (req) {
6076 inet_csk(sk)->icsk_retransmits = 0; 6142 tcp_rcv_synrecv_state_fastopen(sk);
6077 reqsk_fastopen_remove(sk, req, false);
6078 /* Re-arm the timer because data may have been sent out.
6079 * This is similar to the regular data transmission case
6080 * when new data has just been ack'ed.
6081 *
6082 * (TFO) - we could try to be more aggressive and
6083 * retransmitting any data sooner based on when they
6084 * are sent out.
6085 */
6086 tcp_rearm_rto(sk);
6087 } else { 6143 } else {
6144 tcp_try_undo_spurious_syn(sk);
6145 tp->retrans_stamp = 0;
6088 tcp_init_transfer(sk, BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB); 6146 tcp_init_transfer(sk, BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB);
6089 tp->copied_seq = tp->rcv_nxt; 6147 tp->copied_seq = tp->rcv_nxt;
6090 } 6148 }
@@ -6119,16 +6177,9 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
6119 case TCP_FIN_WAIT1: { 6177 case TCP_FIN_WAIT1: {
6120 int tmo; 6178 int tmo;
6121 6179
6122 /* If we enter the TCP_FIN_WAIT1 state and we are a 6180 if (req)
6123 * Fast Open socket and this is the first acceptable 6181 tcp_rcv_synrecv_state_fastopen(sk);
6124 * ACK we have received, this would have acknowledged 6182
6125 * our SYNACK so stop the SYNACK timer.
6126 */
6127 if (req) {
6128 /* We no longer need the request sock. */
6129 reqsk_fastopen_remove(sk, req, false);
6130 tcp_rearm_rto(sk);
6131 }
6132 if (tp->snd_una != tp->write_seq) 6183 if (tp->snd_una != tp->write_seq)
6133 break; 6184 break;
6134 6185
@@ -6263,6 +6314,11 @@ static inline void pr_drop_req(struct request_sock *req, __u16 port, int family)
6263 * congestion control: Linux DCTCP asserts ECT on all packets, 6314 * congestion control: Linux DCTCP asserts ECT on all packets,
6264 * including SYN, which is most optimal solution; however, 6315 * including SYN, which is most optimal solution; however,
6265 * others, such as FreeBSD do not. 6316 * others, such as FreeBSD do not.
6317 *
6318 * Exception: At least one of the reserved bits of the TCP header (th->res1) is
6319 * set, indicating the use of a future TCP extension (such as AccECN). See
6320 * RFC8311 §4.3 which updates RFC3168 to allow the development of such
6321 * extensions.
6266 */ 6322 */
6267static void tcp_ecn_create_request(struct request_sock *req, 6323static void tcp_ecn_create_request(struct request_sock *req,
6268 const struct sk_buff *skb, 6324 const struct sk_buff *skb,
@@ -6282,7 +6338,7 @@ static void tcp_ecn_create_request(struct request_sock *req,
6282 ecn_ok_dst = dst_feature(dst, DST_FEATURE_ECN_MASK); 6338 ecn_ok_dst = dst_feature(dst, DST_FEATURE_ECN_MASK);
6283 ecn_ok = net->ipv4.sysctl_tcp_ecn || ecn_ok_dst; 6339 ecn_ok = net->ipv4.sysctl_tcp_ecn || ecn_ok_dst;
6284 6340
6285 if ((!ect && ecn_ok) || tcp_ca_needs_ecn(listen_sk) || 6341 if (((!ect || th->res1) && ecn_ok) || tcp_ca_needs_ecn(listen_sk) ||
6286 (ecn_ok_dst & DST_FEATURE_ECN_CA) || 6342 (ecn_ok_dst & DST_FEATURE_ECN_CA) ||
6287 tcp_bpf_ca_needs_ecn((struct sock *)req)) 6343 tcp_bpf_ca_needs_ecn((struct sock *)req))
6288 inet_rsk(req)->ecn_ok = 1; 6344 inet_rsk(req)->ecn_ok = 1;
@@ -6298,7 +6354,7 @@ static void tcp_openreq_init(struct request_sock *req,
6298 req->cookie_ts = 0; 6354 req->cookie_ts = 0;
6299 tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq; 6355 tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq;
6300 tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1; 6356 tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1;
6301 tcp_rsk(req)->snt_synack = tcp_clock_us(); 6357 tcp_rsk(req)->snt_synack = 0;
6302 tcp_rsk(req)->last_oow_ack_time = 0; 6358 tcp_rsk(req)->last_oow_ack_time = 0;
6303 req->mss = rx_opt->mss_clamp; 6359 req->mss = rx_opt->mss_clamp;
6304 req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; 6360 req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0;
@@ -6502,8 +6558,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
6502 reqsk_fastopen_remove(fastopen_sk, req, false); 6558 reqsk_fastopen_remove(fastopen_sk, req, false);
6503 bh_unlock_sock(fastopen_sk); 6559 bh_unlock_sock(fastopen_sk);
6504 sock_put(fastopen_sk); 6560 sock_put(fastopen_sk);
6505 reqsk_put(req); 6561 goto drop_and_free;
6506 goto drop;
6507 } 6562 }
6508 sk->sk_data_ready(sk); 6563 sk->sk_data_ready(sk);
6509 bh_unlock_sock(fastopen_sk); 6564 bh_unlock_sock(fastopen_sk);
@@ -6527,7 +6582,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
6527drop_and_release: 6582drop_and_release:
6528 dst_release(dst); 6583 dst_release(dst);
6529drop_and_free: 6584drop_and_free:
6530 reqsk_free(req); 6585 __reqsk_free(req);
6531drop: 6586drop:
6532 tcp_listendrop(sk); 6587 tcp_listendrop(sk);
6533 return 0; 6588 return 0;
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 2f8039a26b08..af81e4a6a8d8 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1673,7 +1673,9 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb)
1673 if (TCP_SKB_CB(tail)->end_seq != TCP_SKB_CB(skb)->seq || 1673 if (TCP_SKB_CB(tail)->end_seq != TCP_SKB_CB(skb)->seq ||
1674 TCP_SKB_CB(tail)->ip_dsfield != TCP_SKB_CB(skb)->ip_dsfield || 1674 TCP_SKB_CB(tail)->ip_dsfield != TCP_SKB_CB(skb)->ip_dsfield ||
1675 ((TCP_SKB_CB(tail)->tcp_flags | 1675 ((TCP_SKB_CB(tail)->tcp_flags |
1676 TCP_SKB_CB(skb)->tcp_flags) & TCPHDR_URG) || 1676 TCP_SKB_CB(skb)->tcp_flags) & (TCPHDR_SYN | TCPHDR_RST | TCPHDR_URG)) ||
1677 !((TCP_SKB_CB(tail)->tcp_flags &
1678 TCP_SKB_CB(skb)->tcp_flags) & TCPHDR_ACK) ||
1677 ((TCP_SKB_CB(tail)->tcp_flags ^ 1679 ((TCP_SKB_CB(tail)->tcp_flags ^
1678 TCP_SKB_CB(skb)->tcp_flags) & (TCPHDR_ECE | TCPHDR_CWR)) || 1680 TCP_SKB_CB(skb)->tcp_flags) & (TCPHDR_ECE | TCPHDR_CWR)) ||
1679#ifdef CONFIG_TLS_DEVICE 1681#ifdef CONFIG_TLS_DEVICE
@@ -1692,6 +1694,15 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb)
1692 if (after(TCP_SKB_CB(skb)->ack_seq, TCP_SKB_CB(tail)->ack_seq)) 1694 if (after(TCP_SKB_CB(skb)->ack_seq, TCP_SKB_CB(tail)->ack_seq))
1693 TCP_SKB_CB(tail)->ack_seq = TCP_SKB_CB(skb)->ack_seq; 1695 TCP_SKB_CB(tail)->ack_seq = TCP_SKB_CB(skb)->ack_seq;
1694 1696
1697 /* We have to update both TCP_SKB_CB(tail)->tcp_flags and
1698 * thtail->fin, so that the fast path in tcp_rcv_established()
1699 * is not entered if we append a packet with a FIN.
1700 * SYN, RST, URG are not present.
1701 * ACK is set on both packets.
1702 * PSH : we do not really care in TCP stack,
1703 * at least for 'GRO' packets.
1704 */
1705 thtail->fin |= th->fin;
1695 TCP_SKB_CB(tail)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags; 1706 TCP_SKB_CB(tail)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags;
1696 1707
1697 if (TCP_SKB_CB(skb)->has_rxtstamp) { 1708 if (TCP_SKB_CB(skb)->has_rxtstamp) {
@@ -1774,6 +1785,7 @@ static void tcp_v4_fill_cb(struct sk_buff *skb, const struct iphdr *iph,
1774int tcp_v4_rcv(struct sk_buff *skb) 1785int tcp_v4_rcv(struct sk_buff *skb)
1775{ 1786{
1776 struct net *net = dev_net(skb->dev); 1787 struct net *net = dev_net(skb->dev);
1788 struct sk_buff *skb_to_free;
1777 int sdif = inet_sdif(skb); 1789 int sdif = inet_sdif(skb);
1778 const struct iphdr *iph; 1790 const struct iphdr *iph;
1779 const struct tcphdr *th; 1791 const struct tcphdr *th;
@@ -1905,11 +1917,17 @@ process:
1905 tcp_segs_in(tcp_sk(sk), skb); 1917 tcp_segs_in(tcp_sk(sk), skb);
1906 ret = 0; 1918 ret = 0;
1907 if (!sock_owned_by_user(sk)) { 1919 if (!sock_owned_by_user(sk)) {
1920 skb_to_free = sk->sk_rx_skb_cache;
1921 sk->sk_rx_skb_cache = NULL;
1908 ret = tcp_v4_do_rcv(sk, skb); 1922 ret = tcp_v4_do_rcv(sk, skb);
1909 } else if (tcp_add_backlog(sk, skb)) { 1923 } else {
1910 goto discard_and_relse; 1924 if (tcp_add_backlog(sk, skb))
1925 goto discard_and_relse;
1926 skb_to_free = NULL;
1911 } 1927 }
1912 bh_unlock_sock(sk); 1928 bh_unlock_sock(sk);
1929 if (skb_to_free)
1930 __kfree_skb(skb_to_free);
1913 1931
1914put_and_return: 1932put_and_return:
1915 if (refcounted) 1933 if (refcounted)
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index b467a7cabf40..c4848e7a0aad 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -512,16 +512,6 @@ reset:
512 512
513 inet_csk(sk)->icsk_rto = TCP_TIMEOUT_FALLBACK; 513 inet_csk(sk)->icsk_rto = TCP_TIMEOUT_FALLBACK;
514 } 514 }
515 /* Cut cwnd down to 1 per RFC5681 if SYN or SYN-ACK has been
516 * retransmitted. In light of RFC6298 more aggressive 1sec
517 * initRTO, we only reset cwnd when more than 1 SYN/SYN-ACK
518 * retransmission has occurred.
519 */
520 if (tp->total_retrans > 1)
521 tp->snd_cwnd = 1;
522 else
523 tp->snd_cwnd = tcp_init_cwnd(tp, dst);
524 tp->snd_cwnd_stamp = tcp_jiffies32;
525} 515}
526 516
527bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst) 517bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst)
@@ -658,7 +648,7 @@ static int tcp_metrics_fill_info(struct sk_buff *msg,
658 { 648 {
659 int n = 0; 649 int n = 0;
660 650
661 nest = nla_nest_start(msg, TCP_METRICS_ATTR_VALS); 651 nest = nla_nest_start_noflag(msg, TCP_METRICS_ATTR_VALS);
662 if (!nest) 652 if (!nest)
663 goto nla_put_failure; 653 goto nla_put_failure;
664 for (i = 0; i < TCP_METRIC_MAX_KERNEL + 1; i++) { 654 for (i = 0; i < TCP_METRIC_MAX_KERNEL + 1; i++) {
@@ -951,14 +941,14 @@ static int tcp_metrics_nl_cmd_del(struct sk_buff *skb, struct genl_info *info)
951static const struct genl_ops tcp_metrics_nl_ops[] = { 941static const struct genl_ops tcp_metrics_nl_ops[] = {
952 { 942 {
953 .cmd = TCP_METRICS_CMD_GET, 943 .cmd = TCP_METRICS_CMD_GET,
944 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
954 .doit = tcp_metrics_nl_cmd_get, 945 .doit = tcp_metrics_nl_cmd_get,
955 .dumpit = tcp_metrics_nl_dump, 946 .dumpit = tcp_metrics_nl_dump,
956 .policy = tcp_metrics_nl_policy,
957 }, 947 },
958 { 948 {
959 .cmd = TCP_METRICS_CMD_DEL, 949 .cmd = TCP_METRICS_CMD_DEL,
950 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
960 .doit = tcp_metrics_nl_cmd_del, 951 .doit = tcp_metrics_nl_cmd_del,
961 .policy = tcp_metrics_nl_policy,
962 .flags = GENL_ADMIN_PERM, 952 .flags = GENL_ADMIN_PERM,
963 }, 953 },
964}; 954};
@@ -968,6 +958,7 @@ static struct genl_family tcp_metrics_nl_family __ro_after_init = {
968 .name = TCP_METRICS_GENL_NAME, 958 .name = TCP_METRICS_GENL_NAME,
969 .version = TCP_METRICS_GENL_VERSION, 959 .version = TCP_METRICS_GENL_VERSION,
970 .maxattr = TCP_METRICS_ATTR_MAX, 960 .maxattr = TCP_METRICS_ATTR_MAX,
961 .policy = tcp_metrics_nl_policy,
971 .netnsok = true, 962 .netnsok = true,
972 .module = THIS_MODULE, 963 .module = THIS_MODULE,
973 .ops = tcp_metrics_nl_ops, 964 .ops = tcp_metrics_nl_ops,
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 79900f783e0d..9c2a0d36fb20 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -522,6 +522,11 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
522 newtp->rx_opt.ts_recent_stamp = 0; 522 newtp->rx_opt.ts_recent_stamp = 0;
523 newtp->tcp_header_len = sizeof(struct tcphdr); 523 newtp->tcp_header_len = sizeof(struct tcphdr);
524 } 524 }
525 if (req->num_timeout) {
526 newtp->undo_marker = treq->snt_isn;
527 newtp->retrans_stamp = div_u64(treq->snt_synack,
528 USEC_PER_SEC / TCP_TS_HZ);
529 }
525 newtp->tsoffset = treq->ts_off; 530 newtp->tsoffset = treq->ts_off;
526#ifdef CONFIG_TCP_MD5SIG 531#ifdef CONFIG_TCP_MD5SIG
527 newtp->md5sig_info = NULL; /*XXX*/ 532 newtp->md5sig_info = NULL; /*XXX*/
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 4522579aaca2..0c4ed66dc1bf 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -52,12 +52,8 @@ void tcp_mstamp_refresh(struct tcp_sock *tp)
52{ 52{
53 u64 val = tcp_clock_ns(); 53 u64 val = tcp_clock_ns();
54 54
55 if (val > tp->tcp_clock_cache) 55 tp->tcp_clock_cache = val;
56 tp->tcp_clock_cache = val; 56 tp->tcp_mstamp = div_u64(val, NSEC_PER_USEC);
57
58 val = div_u64(val, NSEC_PER_USEC);
59 if (val > tp->tcp_mstamp)
60 tp->tcp_mstamp = val;
61} 57}
62 58
63static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle, 59static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
@@ -3092,7 +3088,6 @@ void tcp_send_fin(struct sock *sk)
3092 tskb = skb_rb_last(&sk->tcp_rtx_queue); 3088 tskb = skb_rb_last(&sk->tcp_rtx_queue);
3093 3089
3094 if (tskb) { 3090 if (tskb) {
3095coalesce:
3096 TCP_SKB_CB(tskb)->tcp_flags |= TCPHDR_FIN; 3091 TCP_SKB_CB(tskb)->tcp_flags |= TCPHDR_FIN;
3097 TCP_SKB_CB(tskb)->end_seq++; 3092 TCP_SKB_CB(tskb)->end_seq++;
3098 tp->write_seq++; 3093 tp->write_seq++;
@@ -3108,11 +3103,9 @@ coalesce:
3108 } 3103 }
3109 } else { 3104 } else {
3110 skb = alloc_skb_fclone(MAX_TCP_HEADER, sk->sk_allocation); 3105 skb = alloc_skb_fclone(MAX_TCP_HEADER, sk->sk_allocation);
3111 if (unlikely(!skb)) { 3106 if (unlikely(!skb))
3112 if (tskb)
3113 goto coalesce;
3114 return; 3107 return;
3115 } 3108
3116 INIT_LIST_HEAD(&skb->tcp_tsorted_anchor); 3109 INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
3117 skb_reserve(skb, MAX_TCP_HEADER); 3110 skb_reserve(skb, MAX_TCP_HEADER);
3118 sk_forced_mem_schedule(sk, skb->truesize); 3111 sk_forced_mem_schedule(sk, skb->truesize);
@@ -3254,7 +3247,11 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,
3254 skb->skb_mstamp_ns = cookie_init_timestamp(req); 3247 skb->skb_mstamp_ns = cookie_init_timestamp(req);
3255 else 3248 else
3256#endif 3249#endif
3250 {
3257 skb->skb_mstamp_ns = tcp_clock_ns(); 3251 skb->skb_mstamp_ns = tcp_clock_ns();
3252 if (!tcp_rsk(req)->snt_synack) /* Timestamp first SYNACK */
3253 tcp_rsk(req)->snt_synack = tcp_skb_timestamp_us(skb);
3254 }
3258 3255
3259#ifdef CONFIG_TCP_MD5SIG 3256#ifdef CONFIG_TCP_MD5SIG
3260 rcu_read_lock(); 3257 rcu_read_lock();
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index f0c86398e6a7..2ac23da42dd2 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -393,6 +393,9 @@ static void tcp_fastopen_synack_timer(struct sock *sk)
393 tcp_write_err(sk); 393 tcp_write_err(sk);
394 return; 394 return;
395 } 395 }
396 /* Lower cwnd after certain SYNACK timeout like tcp_init_transfer() */
397 if (icsk->icsk_retransmits == 1)
398 tcp_enter_loss(sk);
396 /* XXX (TFO) - Unlike regular SYN-ACK retransmit, we ignore error 399 /* XXX (TFO) - Unlike regular SYN-ACK retransmit, we ignore error
397 * returned from rtx_syn_ack() to make it more persistent like 400 * returned from rtx_syn_ack() to make it more persistent like
398 * regular retransmit because if the child socket has been accepted 401 * regular retransmit because if the child socket has been accepted
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 372fdc5381a9..3c58ba02af7d 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1631,7 +1631,7 @@ int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
1631EXPORT_SYMBOL(udp_ioctl); 1631EXPORT_SYMBOL(udp_ioctl);
1632 1632
1633struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags, 1633struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
1634 int noblock, int *peeked, int *off, int *err) 1634 int noblock, int *off, int *err)
1635{ 1635{
1636 struct sk_buff_head *sk_queue = &sk->sk_receive_queue; 1636 struct sk_buff_head *sk_queue = &sk->sk_receive_queue;
1637 struct sk_buff_head *queue; 1637 struct sk_buff_head *queue;
@@ -1650,13 +1650,11 @@ struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
1650 break; 1650 break;
1651 1651
1652 error = -EAGAIN; 1652 error = -EAGAIN;
1653 *peeked = 0;
1654 do { 1653 do {
1655 spin_lock_bh(&queue->lock); 1654 spin_lock_bh(&queue->lock);
1656 skb = __skb_try_recv_from_queue(sk, queue, flags, 1655 skb = __skb_try_recv_from_queue(sk, queue, flags,
1657 udp_skb_destructor, 1656 udp_skb_destructor,
1658 peeked, off, err, 1657 off, err, &last);
1659 &last);
1660 if (skb) { 1658 if (skb) {
1661 spin_unlock_bh(&queue->lock); 1659 spin_unlock_bh(&queue->lock);
1662 return skb; 1660 return skb;
@@ -1677,8 +1675,7 @@ struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
1677 1675
1678 skb = __skb_try_recv_from_queue(sk, queue, flags, 1676 skb = __skb_try_recv_from_queue(sk, queue, flags,
1679 udp_skb_dtor_locked, 1677 udp_skb_dtor_locked,
1680 peeked, off, err, 1678 off, err, &last);
1681 &last);
1682 spin_unlock(&sk_queue->lock); 1679 spin_unlock(&sk_queue->lock);
1683 spin_unlock_bh(&queue->lock); 1680 spin_unlock_bh(&queue->lock);
1684 if (skb) 1681 if (skb)
@@ -1713,8 +1710,7 @@ int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock,
1713 DECLARE_SOCKADDR(struct sockaddr_in *, sin, msg->msg_name); 1710 DECLARE_SOCKADDR(struct sockaddr_in *, sin, msg->msg_name);
1714 struct sk_buff *skb; 1711 struct sk_buff *skb;
1715 unsigned int ulen, copied; 1712 unsigned int ulen, copied;
1716 int peeked, peeking, off; 1713 int off, err, peeking = flags & MSG_PEEK;
1717 int err;
1718 int is_udplite = IS_UDPLITE(sk); 1714 int is_udplite = IS_UDPLITE(sk);
1719 bool checksum_valid = false; 1715 bool checksum_valid = false;
1720 1716
@@ -1722,9 +1718,8 @@ int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock,
1722 return ip_recv_error(sk, msg, len, addr_len); 1718 return ip_recv_error(sk, msg, len, addr_len);
1723 1719
1724try_again: 1720try_again:
1725 peeking = flags & MSG_PEEK;
1726 off = sk_peek_offset(sk, flags); 1721 off = sk_peek_offset(sk, flags);
1727 skb = __skb_recv_udp(sk, flags, noblock, &peeked, &off, &err); 1722 skb = __skb_recv_udp(sk, flags, noblock, &off, &err);
1728 if (!skb) 1723 if (!skb)
1729 return err; 1724 return err;
1730 1725
@@ -1762,7 +1757,7 @@ try_again:
1762 } 1757 }
1763 1758
1764 if (unlikely(err)) { 1759 if (unlikely(err)) {
1765 if (!peeked) { 1760 if (!peeking) {
1766 atomic_inc(&sk->sk_drops); 1761 atomic_inc(&sk->sk_drops);
1767 UDP_INC_STATS(sock_net(sk), 1762 UDP_INC_STATS(sock_net(sk),
1768 UDP_MIB_INERRORS, is_udplite); 1763 UDP_MIB_INERRORS, is_udplite);
@@ -1771,7 +1766,7 @@ try_again:
1771 return err; 1766 return err;
1772 } 1767 }
1773 1768
1774 if (!peeked) 1769 if (!peeking)
1775 UDP_INC_STATS(sock_net(sk), 1770 UDP_INC_STATS(sock_net(sk),
1776 UDP_MIB_INDATAGRAMS, is_udplite); 1771 UDP_MIB_INDATAGRAMS, is_udplite);
1777 1772
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 64f9715173ac..065334b41d57 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -352,6 +352,7 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
352 struct sk_buff *pp = NULL; 352 struct sk_buff *pp = NULL;
353 struct udphdr *uh2; 353 struct udphdr *uh2;
354 struct sk_buff *p; 354 struct sk_buff *p;
355 unsigned int ulen;
355 356
356 /* requires non zero csum, for symmetry with GSO */ 357 /* requires non zero csum, for symmetry with GSO */
357 if (!uh->check) { 358 if (!uh->check) {
@@ -359,6 +360,12 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
359 return NULL; 360 return NULL;
360 } 361 }
361 362
363 /* Do not deal with padded or malicious packets, sorry ! */
364 ulen = ntohs(uh->len);
365 if (ulen <= sizeof(*uh) || ulen != skb_gro_len(skb)) {
366 NAPI_GRO_CB(skb)->flush = 1;
367 return NULL;
368 }
362 /* pull encapsulating udp header */ 369 /* pull encapsulating udp header */
363 skb_gro_pull(skb, sizeof(struct udphdr)); 370 skb_gro_pull(skb, sizeof(struct udphdr));
364 skb_gro_postpull_rcsum(skb, uh, sizeof(struct udphdr)); 371 skb_gro_postpull_rcsum(skb, uh, sizeof(struct udphdr));
@@ -377,13 +384,14 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
377 384
378 /* Terminate the flow on len mismatch or if it grow "too much". 385 /* Terminate the flow on len mismatch or if it grow "too much".
379 * Under small packet flood GRO count could elsewhere grow a lot 386 * Under small packet flood GRO count could elsewhere grow a lot
380 * leading to execessive truesize values 387 * leading to excessive truesize values.
388 * On len mismatch merge the first packet shorter than gso_size,
389 * otherwise complete the GRO packet.
381 */ 390 */
382 if (!skb_gro_receive(p, skb) && 391 if (ulen > ntohs(uh2->len) || skb_gro_receive(p, skb) ||
392 ulen != ntohs(uh2->len) ||
383 NAPI_GRO_CB(p)->count >= UDP_GRO_CNT_MAX) 393 NAPI_GRO_CB(p)->count >= UDP_GRO_CNT_MAX)
384 pp = p; 394 pp = p;
385 else if (uh->len != uh2->len)
386 pp = p;
387 395
388 return pp; 396 return pp;
389 } 397 }
diff --git a/net/ipv4/xfrm4_mode_beet.c b/net/ipv4/xfrm4_mode_beet.c
deleted file mode 100644
index 856d2dfdb44b..000000000000
--- a/net/ipv4/xfrm4_mode_beet.c
+++ /dev/null
@@ -1,155 +0,0 @@
1/*
2 * xfrm4_mode_beet.c - BEET mode encapsulation for IPv4.
3 *
4 * Copyright (c) 2006 Diego Beltrami <diego.beltrami@gmail.com>
5 * Miika Komu <miika@iki.fi>
6 * Herbert Xu <herbert@gondor.apana.org.au>
7 * Abhinav Pathak <abhinav.pathak@hiit.fi>
8 * Jeff Ahrenholz <ahrenholz@gmail.com>
9 */
10
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/skbuff.h>
15#include <linux/stringify.h>
16#include <net/dst.h>
17#include <net/ip.h>
18#include <net/xfrm.h>
19
20static void xfrm4_beet_make_header(struct sk_buff *skb)
21{
22 struct iphdr *iph = ip_hdr(skb);
23
24 iph->ihl = 5;
25 iph->version = 4;
26
27 iph->protocol = XFRM_MODE_SKB_CB(skb)->protocol;
28 iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
29
30 iph->id = XFRM_MODE_SKB_CB(skb)->id;
31 iph->frag_off = XFRM_MODE_SKB_CB(skb)->frag_off;
32 iph->ttl = XFRM_MODE_SKB_CB(skb)->ttl;
33}
34
35/* Add encapsulation header.
36 *
37 * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
38 */
39static int xfrm4_beet_output(struct xfrm_state *x, struct sk_buff *skb)
40{
41 struct ip_beet_phdr *ph;
42 struct iphdr *top_iph;
43 int hdrlen, optlen;
44
45 hdrlen = 0;
46 optlen = XFRM_MODE_SKB_CB(skb)->optlen;
47 if (unlikely(optlen))
48 hdrlen += IPV4_BEET_PHMAXLEN - (optlen & 4);
49
50 skb_set_network_header(skb, -x->props.header_len -
51 hdrlen + (XFRM_MODE_SKB_CB(skb)->ihl - sizeof(*top_iph)));
52 if (x->sel.family != AF_INET6)
53 skb->network_header += IPV4_BEET_PHMAXLEN;
54 skb->mac_header = skb->network_header +
55 offsetof(struct iphdr, protocol);
56 skb->transport_header = skb->network_header + sizeof(*top_iph);
57
58 xfrm4_beet_make_header(skb);
59
60 ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdrlen);
61
62 top_iph = ip_hdr(skb);
63
64 if (unlikely(optlen)) {
65 BUG_ON(optlen < 0);
66
67 ph->padlen = 4 - (optlen & 4);
68 ph->hdrlen = optlen / 8;
69 ph->nexthdr = top_iph->protocol;
70 if (ph->padlen)
71 memset(ph + 1, IPOPT_NOP, ph->padlen);
72
73 top_iph->protocol = IPPROTO_BEETPH;
74 top_iph->ihl = sizeof(struct iphdr) / 4;
75 }
76
77 top_iph->saddr = x->props.saddr.a4;
78 top_iph->daddr = x->id.daddr.a4;
79
80 return 0;
81}
82
83static int xfrm4_beet_input(struct xfrm_state *x, struct sk_buff *skb)
84{
85 struct iphdr *iph;
86 int optlen = 0;
87 int err = -EINVAL;
88
89 if (unlikely(XFRM_MODE_SKB_CB(skb)->protocol == IPPROTO_BEETPH)) {
90 struct ip_beet_phdr *ph;
91 int phlen;
92
93 if (!pskb_may_pull(skb, sizeof(*ph)))
94 goto out;
95
96 ph = (struct ip_beet_phdr *)skb->data;
97
98 phlen = sizeof(*ph) + ph->padlen;
99 optlen = ph->hdrlen * 8 + (IPV4_BEET_PHMAXLEN - phlen);
100 if (optlen < 0 || optlen & 3 || optlen > 250)
101 goto out;
102
103 XFRM_MODE_SKB_CB(skb)->protocol = ph->nexthdr;
104
105 if (!pskb_may_pull(skb, phlen))
106 goto out;
107 __skb_pull(skb, phlen);
108 }
109
110 skb_push(skb, sizeof(*iph));
111 skb_reset_network_header(skb);
112 skb_mac_header_rebuild(skb);
113
114 xfrm4_beet_make_header(skb);
115
116 iph = ip_hdr(skb);
117
118 iph->ihl += optlen / 4;
119 iph->tot_len = htons(skb->len);
120 iph->daddr = x->sel.daddr.a4;
121 iph->saddr = x->sel.saddr.a4;
122 iph->check = 0;
123 iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
124 err = 0;
125out:
126 return err;
127}
128
129static struct xfrm_mode xfrm4_beet_mode = {
130 .input2 = xfrm4_beet_input,
131 .input = xfrm_prepare_input,
132 .output2 = xfrm4_beet_output,
133 .output = xfrm4_prepare_output,
134 .owner = THIS_MODULE,
135 .encap = XFRM_MODE_BEET,
136 .flags = XFRM_MODE_FLAG_TUNNEL,
137};
138
139static int __init xfrm4_beet_init(void)
140{
141 return xfrm_register_mode(&xfrm4_beet_mode, AF_INET);
142}
143
144static void __exit xfrm4_beet_exit(void)
145{
146 int err;
147
148 err = xfrm_unregister_mode(&xfrm4_beet_mode, AF_INET);
149 BUG_ON(err);
150}
151
152module_init(xfrm4_beet_init);
153module_exit(xfrm4_beet_exit);
154MODULE_LICENSE("GPL");
155MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_BEET);
diff --git a/net/ipv4/xfrm4_mode_transport.c b/net/ipv4/xfrm4_mode_transport.c
deleted file mode 100644
index 1ad2c2c4e250..000000000000
--- a/net/ipv4/xfrm4_mode_transport.c
+++ /dev/null
@@ -1,114 +0,0 @@
1/*
2 * xfrm4_mode_transport.c - Transport mode encapsulation for IPv4.
3 *
4 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
5 */
6
7#include <linux/init.h>
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/skbuff.h>
11#include <linux/stringify.h>
12#include <net/dst.h>
13#include <net/ip.h>
14#include <net/xfrm.h>
15#include <net/protocol.h>
16
17/* Add encapsulation header.
18 *
19 * The IP header will be moved forward to make space for the encapsulation
20 * header.
21 */
22static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb)
23{
24 struct iphdr *iph = ip_hdr(skb);
25 int ihl = iph->ihl * 4;
26
27 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
28
29 skb_set_network_header(skb, -x->props.header_len);
30 skb->mac_header = skb->network_header +
31 offsetof(struct iphdr, protocol);
32 skb->transport_header = skb->network_header + ihl;
33 __skb_pull(skb, ihl);
34 memmove(skb_network_header(skb), iph, ihl);
35 return 0;
36}
37
38/* Remove encapsulation header.
39 *
40 * The IP header will be moved over the top of the encapsulation header.
41 *
42 * On entry, skb->h shall point to where the IP header should be and skb->nh
43 * shall be set to where the IP header currently is. skb->data shall point
44 * to the start of the payload.
45 */
46static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
47{
48 int ihl = skb->data - skb_transport_header(skb);
49
50 if (skb->transport_header != skb->network_header) {
51 memmove(skb_transport_header(skb),
52 skb_network_header(skb), ihl);
53 skb->network_header = skb->transport_header;
54 }
55 ip_hdr(skb)->tot_len = htons(skb->len + ihl);
56 skb_reset_transport_header(skb);
57 return 0;
58}
59
60static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
61 struct sk_buff *skb,
62 netdev_features_t features)
63{
64 const struct net_offload *ops;
65 struct sk_buff *segs = ERR_PTR(-EINVAL);
66 struct xfrm_offload *xo = xfrm_offload(skb);
67
68 skb->transport_header += x->props.header_len;
69 ops = rcu_dereference(inet_offloads[xo->proto]);
70 if (likely(ops && ops->callbacks.gso_segment))
71 segs = ops->callbacks.gso_segment(skb, features);
72
73 return segs;
74}
75
76static void xfrm4_transport_xmit(struct xfrm_state *x, struct sk_buff *skb)
77{
78 struct xfrm_offload *xo = xfrm_offload(skb);
79
80 skb_reset_mac_len(skb);
81 pskb_pull(skb, skb->mac_len + sizeof(struct iphdr) + x->props.header_len);
82
83 if (xo->flags & XFRM_GSO_SEGMENT) {
84 skb_reset_transport_header(skb);
85 skb->transport_header -= x->props.header_len;
86 }
87}
88
89static struct xfrm_mode xfrm4_transport_mode = {
90 .input = xfrm4_transport_input,
91 .output = xfrm4_transport_output,
92 .gso_segment = xfrm4_transport_gso_segment,
93 .xmit = xfrm4_transport_xmit,
94 .owner = THIS_MODULE,
95 .encap = XFRM_MODE_TRANSPORT,
96};
97
98static int __init xfrm4_transport_init(void)
99{
100 return xfrm_register_mode(&xfrm4_transport_mode, AF_INET);
101}
102
103static void __exit xfrm4_transport_exit(void)
104{
105 int err;
106
107 err = xfrm_unregister_mode(&xfrm4_transport_mode, AF_INET);
108 BUG_ON(err);
109}
110
111module_init(xfrm4_transport_init);
112module_exit(xfrm4_transport_exit);
113MODULE_LICENSE("GPL");
114MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_TRANSPORT);
diff --git a/net/ipv4/xfrm4_mode_tunnel.c b/net/ipv4/xfrm4_mode_tunnel.c
deleted file mode 100644
index 2a9764bd1719..000000000000
--- a/net/ipv4/xfrm4_mode_tunnel.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/*
2 * xfrm4_mode_tunnel.c - Tunnel mode encapsulation for IPv4.
3 *
4 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
5 */
6
7#include <linux/gfp.h>
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/skbuff.h>
12#include <linux/stringify.h>
13#include <net/dst.h>
14#include <net/inet_ecn.h>
15#include <net/ip.h>
16#include <net/xfrm.h>
17
18static inline void ipip_ecn_decapsulate(struct sk_buff *skb)
19{
20 struct iphdr *inner_iph = ipip_hdr(skb);
21
22 if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
23 IP_ECN_set_ce(inner_iph);
24}
25
26/* Add encapsulation header.
27 *
28 * The top IP header will be constructed per RFC 2401.
29 */
30static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
31{
32 struct dst_entry *dst = skb_dst(skb);
33 struct iphdr *top_iph;
34 int flags;
35
36 skb_set_inner_network_header(skb, skb_network_offset(skb));
37 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
38
39 skb_set_network_header(skb, -x->props.header_len);
40 skb->mac_header = skb->network_header +
41 offsetof(struct iphdr, protocol);
42 skb->transport_header = skb->network_header + sizeof(*top_iph);
43 top_iph = ip_hdr(skb);
44
45 top_iph->ihl = 5;
46 top_iph->version = 4;
47
48 top_iph->protocol = xfrm_af2proto(skb_dst(skb)->ops->family);
49
50 /* DS disclosing depends on XFRM_SA_XFLAG_DONT_ENCAP_DSCP */
51 if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
52 top_iph->tos = 0;
53 else
54 top_iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
55 top_iph->tos = INET_ECN_encapsulate(top_iph->tos,
56 XFRM_MODE_SKB_CB(skb)->tos);
57
58 flags = x->props.flags;
59 if (flags & XFRM_STATE_NOECN)
60 IP_ECN_clear(top_iph);
61
62 top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
63 0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));
64
65 top_iph->ttl = ip4_dst_hoplimit(xfrm_dst_child(dst));
66
67 top_iph->saddr = x->props.saddr.a4;
68 top_iph->daddr = x->id.daddr.a4;
69 ip_select_ident(dev_net(dst->dev), skb, NULL);
70
71 return 0;
72}
73
74static int xfrm4_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
75{
76 int err = -EINVAL;
77
78 if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPIP)
79 goto out;
80
81 if (!pskb_may_pull(skb, sizeof(struct iphdr)))
82 goto out;
83
84 err = skb_unclone(skb, GFP_ATOMIC);
85 if (err)
86 goto out;
87
88 if (x->props.flags & XFRM_STATE_DECAP_DSCP)
89 ipv4_copy_dscp(XFRM_MODE_SKB_CB(skb)->tos, ipip_hdr(skb));
90 if (!(x->props.flags & XFRM_STATE_NOECN))
91 ipip_ecn_decapsulate(skb);
92
93 skb_reset_network_header(skb);
94 skb_mac_header_rebuild(skb);
95 if (skb->mac_len)
96 eth_hdr(skb)->h_proto = skb->protocol;
97
98 err = 0;
99
100out:
101 return err;
102}
103
104static struct sk_buff *xfrm4_mode_tunnel_gso_segment(struct xfrm_state *x,
105 struct sk_buff *skb,
106 netdev_features_t features)
107{
108 __skb_push(skb, skb->mac_len);
109 return skb_mac_gso_segment(skb, features);
110}
111
112static void xfrm4_mode_tunnel_xmit(struct xfrm_state *x, struct sk_buff *skb)
113{
114 struct xfrm_offload *xo = xfrm_offload(skb);
115
116 if (xo->flags & XFRM_GSO_SEGMENT)
117 skb->transport_header = skb->network_header +
118 sizeof(struct iphdr);
119
120 skb_reset_mac_len(skb);
121 pskb_pull(skb, skb->mac_len + x->props.header_len);
122}
123
124static struct xfrm_mode xfrm4_tunnel_mode = {
125 .input2 = xfrm4_mode_tunnel_input,
126 .input = xfrm_prepare_input,
127 .output2 = xfrm4_mode_tunnel_output,
128 .output = xfrm4_prepare_output,
129 .gso_segment = xfrm4_mode_tunnel_gso_segment,
130 .xmit = xfrm4_mode_tunnel_xmit,
131 .owner = THIS_MODULE,
132 .encap = XFRM_MODE_TUNNEL,
133 .flags = XFRM_MODE_FLAG_TUNNEL,
134};
135
136static int __init xfrm4_mode_tunnel_init(void)
137{
138 return xfrm_register_mode(&xfrm4_tunnel_mode, AF_INET);
139}
140
141static void __exit xfrm4_mode_tunnel_exit(void)
142{
143 int err;
144
145 err = xfrm_unregister_mode(&xfrm4_tunnel_mode, AF_INET);
146 BUG_ON(err);
147}
148
149module_init(xfrm4_mode_tunnel_init);
150module_exit(xfrm4_mode_tunnel_exit);
151MODULE_LICENSE("GPL");
152MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_TUNNEL);
diff --git a/net/ipv4/xfrm4_output.c b/net/ipv4/xfrm4_output.c
index be980c195fc5..9bb8905088c7 100644
--- a/net/ipv4/xfrm4_output.c
+++ b/net/ipv4/xfrm4_output.c
@@ -58,21 +58,6 @@ int xfrm4_extract_output(struct xfrm_state *x, struct sk_buff *skb)
58 return xfrm4_extract_header(skb); 58 return xfrm4_extract_header(skb);
59} 59}
60 60
61int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
62{
63 int err;
64
65 err = xfrm_inner_extract_output(x, skb);
66 if (err)
67 return err;
68
69 IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
70 skb->protocol = htons(ETH_P_IP);
71
72 return x->outer_mode->output2(x, skb);
73}
74EXPORT_SYMBOL(xfrm4_prepare_output);
75
76int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb) 61int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb)
77{ 62{
78 memset(IPCB(skb), 0, sizeof(*IPCB(skb))); 63 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
@@ -87,6 +72,8 @@ int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb)
87static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb) 72static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
88{ 73{
89 struct xfrm_state *x = skb_dst(skb)->xfrm; 74 struct xfrm_state *x = skb_dst(skb)->xfrm;
75 const struct xfrm_state_afinfo *afinfo;
76 int ret = -EAFNOSUPPORT;
90 77
91#ifdef CONFIG_NETFILTER 78#ifdef CONFIG_NETFILTER
92 if (!x) { 79 if (!x) {
@@ -95,7 +82,15 @@ static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
95 } 82 }
96#endif 83#endif
97 84
98 return x->outer_mode->afinfo->output_finish(sk, skb); 85 rcu_read_lock();
86 afinfo = xfrm_state_afinfo_get_rcu(x->outer_mode.family);
87 if (likely(afinfo))
88 ret = afinfo->output_finish(sk, skb);
89 else
90 kfree_skb(skb);
91 rcu_read_unlock();
92
93 return ret;
99} 94}
100 95
101int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb) 96int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index d73a6d6652f6..cdef8f9a3b01 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -12,7 +12,6 @@
12#include <linux/err.h> 12#include <linux/err.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/inetdevice.h> 14#include <linux/inetdevice.h>
15#include <linux/if_tunnel.h>
16#include <net/dst.h> 15#include <net/dst.h>
17#include <net/xfrm.h> 16#include <net/xfrm.h>
18#include <net/ip.h> 17#include <net/ip.h>
@@ -69,17 +68,6 @@ static int xfrm4_get_saddr(struct net *net, int oif,
69 return 0; 68 return 0;
70} 69}
71 70
72static int xfrm4_get_tos(const struct flowi *fl)
73{
74 return IPTOS_RT_MASK & fl->u.ip4.flowi4_tos; /* Strip ECN bits */
75}
76
77static int xfrm4_init_path(struct xfrm_dst *path, struct dst_entry *dst,
78 int nfheader_len)
79{
80 return 0;
81}
82
83static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev, 71static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
84 const struct flowi *fl) 72 const struct flowi *fl)
85{ 73{
@@ -97,8 +85,11 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
97 xdst->u.rt.rt_flags = rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST | 85 xdst->u.rt.rt_flags = rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST |
98 RTCF_LOCAL); 86 RTCF_LOCAL);
99 xdst->u.rt.rt_type = rt->rt_type; 87 xdst->u.rt.rt_type = rt->rt_type;
100 xdst->u.rt.rt_gateway = rt->rt_gateway; 88 xdst->u.rt.rt_gw_family = rt->rt_gw_family;
101 xdst->u.rt.rt_uses_gateway = rt->rt_uses_gateway; 89 if (rt->rt_gw_family == AF_INET)
90 xdst->u.rt.rt_gw4 = rt->rt_gw4;
91 else if (rt->rt_gw_family == AF_INET6)
92 xdst->u.rt.rt_gw6 = rt->rt_gw6;
102 xdst->u.rt.rt_pmtu = rt->rt_pmtu; 93 xdst->u.rt.rt_pmtu = rt->rt_pmtu;
103 xdst->u.rt.rt_mtu_locked = rt->rt_mtu_locked; 94 xdst->u.rt.rt_mtu_locked = rt->rt_mtu_locked;
104 INIT_LIST_HEAD(&xdst->u.rt.rt_uncached); 95 INIT_LIST_HEAD(&xdst->u.rt.rt_uncached);
@@ -107,118 +98,6 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
107 return 0; 98 return 0;
108} 99}
109 100
110static void
111_decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
112{
113 const struct iphdr *iph = ip_hdr(skb);
114 u8 *xprth = skb_network_header(skb) + iph->ihl * 4;
115 struct flowi4 *fl4 = &fl->u.ip4;
116 int oif = 0;
117
118 if (skb_dst(skb))
119 oif = skb_dst(skb)->dev->ifindex;
120
121 memset(fl4, 0, sizeof(struct flowi4));
122 fl4->flowi4_mark = skb->mark;
123 fl4->flowi4_oif = reverse ? skb->skb_iif : oif;
124
125 if (!ip_is_fragment(iph)) {
126 switch (iph->protocol) {
127 case IPPROTO_UDP:
128 case IPPROTO_UDPLITE:
129 case IPPROTO_TCP:
130 case IPPROTO_SCTP:
131 case IPPROTO_DCCP:
132 if (xprth + 4 < skb->data ||
133 pskb_may_pull(skb, xprth + 4 - skb->data)) {
134 __be16 *ports;
135
136 xprth = skb_network_header(skb) + iph->ihl * 4;
137 ports = (__be16 *)xprth;
138
139 fl4->fl4_sport = ports[!!reverse];
140 fl4->fl4_dport = ports[!reverse];
141 }
142 break;
143
144 case IPPROTO_ICMP:
145 if (xprth + 2 < skb->data ||
146 pskb_may_pull(skb, xprth + 2 - skb->data)) {
147 u8 *icmp;
148
149 xprth = skb_network_header(skb) + iph->ihl * 4;
150 icmp = xprth;
151
152 fl4->fl4_icmp_type = icmp[0];
153 fl4->fl4_icmp_code = icmp[1];
154 }
155 break;
156
157 case IPPROTO_ESP:
158 if (xprth + 4 < skb->data ||
159 pskb_may_pull(skb, xprth + 4 - skb->data)) {
160 __be32 *ehdr;
161
162 xprth = skb_network_header(skb) + iph->ihl * 4;
163 ehdr = (__be32 *)xprth;
164
165 fl4->fl4_ipsec_spi = ehdr[0];
166 }
167 break;
168
169 case IPPROTO_AH:
170 if (xprth + 8 < skb->data ||
171 pskb_may_pull(skb, xprth + 8 - skb->data)) {
172 __be32 *ah_hdr;
173
174 xprth = skb_network_header(skb) + iph->ihl * 4;
175 ah_hdr = (__be32 *)xprth;
176
177 fl4->fl4_ipsec_spi = ah_hdr[1];
178 }
179 break;
180
181 case IPPROTO_COMP:
182 if (xprth + 4 < skb->data ||
183 pskb_may_pull(skb, xprth + 4 - skb->data)) {
184 __be16 *ipcomp_hdr;
185
186 xprth = skb_network_header(skb) + iph->ihl * 4;
187 ipcomp_hdr = (__be16 *)xprth;
188
189 fl4->fl4_ipsec_spi = htonl(ntohs(ipcomp_hdr[1]));
190 }
191 break;
192
193 case IPPROTO_GRE:
194 if (xprth + 12 < skb->data ||
195 pskb_may_pull(skb, xprth + 12 - skb->data)) {
196 __be16 *greflags;
197 __be32 *gre_hdr;
198
199 xprth = skb_network_header(skb) + iph->ihl * 4;
200 greflags = (__be16 *)xprth;
201 gre_hdr = (__be32 *)xprth;
202
203 if (greflags[0] & GRE_KEY) {
204 if (greflags[0] & GRE_CSUM)
205 gre_hdr++;
206 fl4->fl4_gre_key = gre_hdr[1];
207 }
208 }
209 break;
210
211 default:
212 fl4->fl4_ipsec_spi = 0;
213 break;
214 }
215 }
216 fl4->flowi4_proto = iph->protocol;
217 fl4->daddr = reverse ? iph->saddr : iph->daddr;
218 fl4->saddr = reverse ? iph->daddr : iph->saddr;
219 fl4->flowi4_tos = iph->tos;
220}
221
222static void xfrm4_update_pmtu(struct dst_entry *dst, struct sock *sk, 101static void xfrm4_update_pmtu(struct dst_entry *dst, struct sock *sk,
223 struct sk_buff *skb, u32 mtu) 102 struct sk_buff *skb, u32 mtu)
224{ 103{
@@ -271,9 +150,6 @@ static const struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
271 .dst_ops = &xfrm4_dst_ops_template, 150 .dst_ops = &xfrm4_dst_ops_template,
272 .dst_lookup = xfrm4_dst_lookup, 151 .dst_lookup = xfrm4_dst_lookup,
273 .get_saddr = xfrm4_get_saddr, 152 .get_saddr = xfrm4_get_saddr,
274 .decode_session = _decode_session4,
275 .get_tos = xfrm4_get_tos,
276 .init_path = xfrm4_init_path,
277 .fill_dst = xfrm4_fill_dst, 153 .fill_dst = xfrm4_fill_dst,
278 .blackhole_route = ipv4_blackhole_route, 154 .blackhole_route = ipv4_blackhole_route,
279}; 155};
diff --git a/net/ipv4/xfrm4_protocol.c b/net/ipv4/xfrm4_protocol.c
index 35c54865dc42..bcab48944c15 100644
--- a/net/ipv4/xfrm4_protocol.c
+++ b/net/ipv4/xfrm4_protocol.c
@@ -46,7 +46,7 @@ static inline struct xfrm4_protocol __rcu **proto_handlers(u8 protocol)
46 handler != NULL; \ 46 handler != NULL; \
47 handler = rcu_dereference(handler->next)) \ 47 handler = rcu_dereference(handler->next)) \
48 48
49int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err) 49static int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
50{ 50{
51 int ret; 51 int ret;
52 struct xfrm4_protocol *handler; 52 struct xfrm4_protocol *handler;
@@ -61,7 +61,6 @@ int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
61 61
62 return 0; 62 return 0;
63} 63}
64EXPORT_SYMBOL(xfrm4_rcv_cb);
65 64
66int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, 65int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
67 int encap_type) 66 int encap_type)
diff --git a/net/ipv6/Kconfig b/net/ipv6/Kconfig
index 613282c65a10..cd915e332c98 100644
--- a/net/ipv6/Kconfig
+++ b/net/ipv6/Kconfig
@@ -135,44 +135,11 @@ config INET6_TUNNEL
135 tristate 135 tristate
136 default n 136 default n
137 137
138config INET6_XFRM_MODE_TRANSPORT
139 tristate "IPv6: IPsec transport mode"
140 default IPV6
141 select XFRM
142 ---help---
143 Support for IPsec transport mode.
144
145 If unsure, say Y.
146
147config INET6_XFRM_MODE_TUNNEL
148 tristate "IPv6: IPsec tunnel mode"
149 default IPV6
150 select XFRM
151 ---help---
152 Support for IPsec tunnel mode.
153
154 If unsure, say Y.
155
156config INET6_XFRM_MODE_BEET
157 tristate "IPv6: IPsec BEET mode"
158 default IPV6
159 select XFRM
160 ---help---
161 Support for IPsec BEET mode.
162
163 If unsure, say Y.
164
165config INET6_XFRM_MODE_ROUTEOPTIMIZATION
166 tristate "IPv6: MIPv6 route optimization mode"
167 select XFRM
168 ---help---
169 Support for MIPv6 route optimization mode.
170
171config IPV6_VTI 138config IPV6_VTI
172tristate "Virtual (secure) IPv6: tunneling" 139tristate "Virtual (secure) IPv6: tunneling"
173 select IPV6_TUNNEL 140 select IPV6_TUNNEL
174 select NET_IP_TUNNEL 141 select NET_IP_TUNNEL
175 depends on INET6_XFRM_MODE_TUNNEL 142 select XFRM
176 ---help--- 143 ---help---
177 Tunneling means encapsulating data of one protocol type within 144 Tunneling means encapsulating data of one protocol type within
178 another protocol and sending it over a channel that understands the 145 another protocol and sending it over a channel that understands the
diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile
index e0026fa1261b..8ccf35514015 100644
--- a/net/ipv6/Makefile
+++ b/net/ipv6/Makefile
@@ -35,10 +35,6 @@ obj-$(CONFIG_INET6_ESP_OFFLOAD) += esp6_offload.o
35obj-$(CONFIG_INET6_IPCOMP) += ipcomp6.o 35obj-$(CONFIG_INET6_IPCOMP) += ipcomp6.o
36obj-$(CONFIG_INET6_XFRM_TUNNEL) += xfrm6_tunnel.o 36obj-$(CONFIG_INET6_XFRM_TUNNEL) += xfrm6_tunnel.o
37obj-$(CONFIG_INET6_TUNNEL) += tunnel6.o 37obj-$(CONFIG_INET6_TUNNEL) += tunnel6.o
38obj-$(CONFIG_INET6_XFRM_MODE_TRANSPORT) += xfrm6_mode_transport.o
39obj-$(CONFIG_INET6_XFRM_MODE_TUNNEL) += xfrm6_mode_tunnel.o
40obj-$(CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION) += xfrm6_mode_ro.o
41obj-$(CONFIG_INET6_XFRM_MODE_BEET) += xfrm6_mode_beet.o
42obj-$(CONFIG_IPV6_MIP6) += mip6.o 38obj-$(CONFIG_IPV6_MIP6) += mip6.o
43obj-$(CONFIG_IPV6_ILA) += ila/ 39obj-$(CONFIG_IPV6_ILA) += ila/
44obj-$(CONFIG_NETFILTER) += netfilter/ 40obj-$(CONFIG_NETFILTER) += netfilter/
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 4ae17a966ae3..f96d1de79509 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -173,7 +173,8 @@ static int addrconf_ifdown(struct net_device *dev, int how);
173static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, 173static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
174 int plen, 174 int plen,
175 const struct net_device *dev, 175 const struct net_device *dev,
176 u32 flags, u32 noflags); 176 u32 flags, u32 noflags,
177 bool no_gw);
177 178
178static void addrconf_dad_start(struct inet6_ifaddr *ifp); 179static void addrconf_dad_start(struct inet6_ifaddr *ifp);
179static void addrconf_dad_work(struct work_struct *w); 180static void addrconf_dad_work(struct work_struct *w);
@@ -610,11 +611,13 @@ static int inet6_netconf_valid_get_req(struct sk_buff *skb,
610 } 611 }
611 612
612 if (!netlink_strict_get_check(skb)) 613 if (!netlink_strict_get_check(skb))
613 return nlmsg_parse(nlh, sizeof(struct netconfmsg), tb, 614 return nlmsg_parse_deprecated(nlh, sizeof(struct netconfmsg),
614 NETCONFA_MAX, devconf_ipv6_policy, extack); 615 tb, NETCONFA_MAX,
616 devconf_ipv6_policy, extack);
615 617
616 err = nlmsg_parse_strict(nlh, sizeof(struct netconfmsg), tb, 618 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct netconfmsg),
617 NETCONFA_MAX, devconf_ipv6_policy, extack); 619 tb, NETCONFA_MAX,
620 devconf_ipv6_policy, extack);
618 if (err) 621 if (err)
619 return err; 622 return err;
620 623
@@ -1230,10 +1233,8 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_r
1230{ 1233{
1231 struct fib6_info *f6i; 1234 struct fib6_info *f6i;
1232 1235
1233 f6i = addrconf_get_prefix_route(&ifp->addr, 1236 f6i = addrconf_get_prefix_route(&ifp->addr, ifp->prefix_len,
1234 ifp->prefix_len, 1237 ifp->idev->dev, 0, RTF_DEFAULT, true);
1235 ifp->idev->dev,
1236 0, RTF_GATEWAY | RTF_DEFAULT);
1237 if (f6i) { 1238 if (f6i) {
1238 if (del_rt) 1239 if (del_rt)
1239 ip6_del_rt(dev_net(ifp->idev->dev), f6i); 1240 ip6_del_rt(dev_net(ifp->idev->dev), f6i);
@@ -2402,7 +2403,8 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, u32 metric,
2402static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, 2403static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
2403 int plen, 2404 int plen,
2404 const struct net_device *dev, 2405 const struct net_device *dev,
2405 u32 flags, u32 noflags) 2406 u32 flags, u32 noflags,
2407 bool no_gw)
2406{ 2408{
2407 struct fib6_node *fn; 2409 struct fib6_node *fn;
2408 struct fib6_info *rt = NULL; 2410 struct fib6_info *rt = NULL;
@@ -2419,7 +2421,9 @@ static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
2419 goto out; 2421 goto out;
2420 2422
2421 for_each_fib6_node_rt_rcu(fn) { 2423 for_each_fib6_node_rt_rcu(fn) {
2422 if (rt->fib6_nh.nh_dev->ifindex != dev->ifindex) 2424 if (rt->fib6_nh.fib_nh_dev->ifindex != dev->ifindex)
2425 continue;
2426 if (no_gw && rt->fib6_nh.fib_nh_gw_family)
2423 continue; 2427 continue;
2424 if ((rt->fib6_flags & flags) != flags) 2428 if ((rt->fib6_flags & flags) != flags)
2425 continue; 2429 continue;
@@ -2717,7 +2721,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
2717 pinfo->prefix_len, 2721 pinfo->prefix_len,
2718 dev, 2722 dev,
2719 RTF_ADDRCONF | RTF_PREFIX_RT, 2723 RTF_ADDRCONF | RTF_PREFIX_RT,
2720 RTF_GATEWAY | RTF_DEFAULT); 2724 RTF_DEFAULT, true);
2721 2725
2722 if (rt) { 2726 if (rt) {
2723 /* Autoconf prefix route */ 2727 /* Autoconf prefix route */
@@ -4563,8 +4567,8 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
4563 u32 ifa_flags; 4567 u32 ifa_flags;
4564 int err; 4568 int err;
4565 4569
4566 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy, 4570 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
4567 extack); 4571 ifa_ipv6_policy, extack);
4568 if (err < 0) 4572 if (err < 0)
4569 return err; 4573 return err;
4570 4574
@@ -4588,10 +4592,8 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp,
4588 struct fib6_info *f6i; 4592 struct fib6_info *f6i;
4589 u32 prio; 4593 u32 prio;
4590 4594
4591 f6i = addrconf_get_prefix_route(&ifp->addr, 4595 f6i = addrconf_get_prefix_route(&ifp->addr, ifp->prefix_len,
4592 ifp->prefix_len, 4596 ifp->idev->dev, 0, RTF_DEFAULT, true);
4593 ifp->idev->dev,
4594 0, RTF_GATEWAY | RTF_DEFAULT);
4595 if (!f6i) 4597 if (!f6i)
4596 return -ENOENT; 4598 return -ENOENT;
4597 4599
@@ -4729,8 +4731,8 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
4729 struct ifa6_config cfg; 4731 struct ifa6_config cfg;
4730 int err; 4732 int err;
4731 4733
4732 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy, 4734 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
4733 extack); 4735 ifa_ipv6_policy, extack);
4734 if (err < 0) 4736 if (err < 0)
4735 return err; 4737 return err;
4736 4738
@@ -5086,8 +5088,8 @@ static int inet6_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,
5086 fillargs->flags |= NLM_F_DUMP_FILTERED; 5088 fillargs->flags |= NLM_F_DUMP_FILTERED;
5087 } 5089 }
5088 5090
5089 err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFA_MAX, 5091 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*ifm), tb, IFA_MAX,
5090 ifa_ipv6_policy, extack); 5092 ifa_ipv6_policy, extack);
5091 if (err < 0) 5093 if (err < 0)
5092 return err; 5094 return err;
5093 5095
@@ -5237,11 +5239,11 @@ static int inet6_rtm_valid_getaddr_req(struct sk_buff *skb,
5237 } 5239 }
5238 5240
5239 if (!netlink_strict_get_check(skb)) 5241 if (!netlink_strict_get_check(skb))
5240 return nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, 5242 return nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
5241 ifa_ipv6_policy, extack); 5243 ifa_ipv6_policy, extack);
5242 5244
5243 err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFA_MAX, 5245 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*ifm), tb, IFA_MAX,
5244 ifa_ipv6_policy, extack); 5246 ifa_ipv6_policy, extack);
5245 if (err) 5247 if (err)
5246 return err; 5248 return err;
5247 5249
@@ -5667,8 +5669,8 @@ static int inet6_validate_link_af(const struct net_device *dev,
5667 if (dev && !__in6_dev_get(dev)) 5669 if (dev && !__in6_dev_get(dev))
5668 return -EAFNOSUPPORT; 5670 return -EAFNOSUPPORT;
5669 5671
5670 return nla_parse_nested(tb, IFLA_INET6_MAX, nla, inet6_af_policy, 5672 return nla_parse_nested_deprecated(tb, IFLA_INET6_MAX, nla,
5671 NULL); 5673 inet6_af_policy, NULL);
5672} 5674}
5673 5675
5674static int check_addr_gen_mode(int mode) 5676static int check_addr_gen_mode(int mode)
@@ -5700,7 +5702,7 @@ static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
5700 if (!idev) 5702 if (!idev)
5701 return -EAFNOSUPPORT; 5703 return -EAFNOSUPPORT;
5702 5704
5703 if (nla_parse_nested(tb, IFLA_INET6_MAX, nla, NULL, NULL) < 0) 5705 if (nla_parse_nested_deprecated(tb, IFLA_INET6_MAX, nla, NULL, NULL) < 0)
5704 BUG(); 5706 BUG();
5705 5707
5706 if (tb[IFLA_INET6_TOKEN]) { 5708 if (tb[IFLA_INET6_TOKEN]) {
@@ -5752,7 +5754,7 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
5752 nla_put_u8(skb, IFLA_OPERSTATE, 5754 nla_put_u8(skb, IFLA_OPERSTATE,
5753 netif_running(dev) ? dev->operstate : IF_OPER_DOWN)) 5755 netif_running(dev) ? dev->operstate : IF_OPER_DOWN))
5754 goto nla_put_failure; 5756 goto nla_put_failure;
5755 protoinfo = nla_nest_start(skb, IFLA_PROTINFO); 5757 protoinfo = nla_nest_start_noflag(skb, IFLA_PROTINFO);
5756 if (!protoinfo) 5758 if (!protoinfo)
5757 goto nla_put_failure; 5759 goto nla_put_failure;
5758 5760
@@ -5972,7 +5974,8 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
5972 struct fib6_info *rt; 5974 struct fib6_info *rt;
5973 5975
5974 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128, 5976 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128,
5975 ifp->idev->dev, 0, 0); 5977 ifp->idev->dev, 0, 0,
5978 false);
5976 if (rt) 5979 if (rt)
5977 ip6_del_rt(net, rt); 5980 ip6_del_rt(net, rt);
5978 } 5981 }
diff --git a/net/ipv6/addrconf_core.c b/net/ipv6/addrconf_core.c
index 6c79af056d9b..763a947e0d14 100644
--- a/net/ipv6/addrconf_core.c
+++ b/net/ipv6/addrconf_core.c
@@ -5,7 +5,7 @@
5 5
6#include <linux/export.h> 6#include <linux/export.h>
7#include <net/ipv6.h> 7#include <net/ipv6.h>
8#include <net/addrconf.h> 8#include <net/ipv6_stubs.h>
9#include <net/ip.h> 9#include <net/ip.h>
10 10
11/* if ipv6 module registers this function is used by xfrm to force all 11/* if ipv6 module registers this function is used by xfrm to force all
@@ -144,43 +144,53 @@ static struct fib6_table *eafnosupport_fib6_get_table(struct net *net, u32 id)
144 return NULL; 144 return NULL;
145} 145}
146 146
147static struct fib6_info * 147static int
148eafnosupport_fib6_table_lookup(struct net *net, struct fib6_table *table, 148eafnosupport_fib6_table_lookup(struct net *net, struct fib6_table *table,
149 int oif, struct flowi6 *fl6, int flags) 149 int oif, struct flowi6 *fl6,
150 struct fib6_result *res, int flags)
150{ 151{
151 return NULL; 152 return -EAFNOSUPPORT;
152} 153}
153 154
154static struct fib6_info * 155static int
155eafnosupport_fib6_lookup(struct net *net, int oif, struct flowi6 *fl6, 156eafnosupport_fib6_lookup(struct net *net, int oif, struct flowi6 *fl6,
156 int flags) 157 struct fib6_result *res, int flags)
157{ 158{
158 return NULL; 159 return -EAFNOSUPPORT;
159} 160}
160 161
161static struct fib6_info * 162static void
162eafnosupport_fib6_multipath_select(const struct net *net, struct fib6_info *f6i, 163eafnosupport_fib6_select_path(const struct net *net, struct fib6_result *res,
163 struct flowi6 *fl6, int oif, 164 struct flowi6 *fl6, int oif, bool have_oif_match,
164 const struct sk_buff *skb, int strict) 165 const struct sk_buff *skb, int strict)
165{ 166{
166 return f6i;
167} 167}
168 168
169static u32 169static u32
170eafnosupport_ip6_mtu_from_fib6(struct fib6_info *f6i, struct in6_addr *daddr, 170eafnosupport_ip6_mtu_from_fib6(const struct fib6_result *res,
171 struct in6_addr *saddr) 171 const struct in6_addr *daddr,
172 const struct in6_addr *saddr)
172{ 173{
173 return 0; 174 return 0;
174} 175}
175 176
177static int eafnosupport_fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
178 struct fib6_config *cfg, gfp_t gfp_flags,
179 struct netlink_ext_ack *extack)
180{
181 NL_SET_ERR_MSG(extack, "IPv6 support not enabled in kernel");
182 return -EAFNOSUPPORT;
183}
184
176const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) { 185const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) {
177 .ipv6_dst_lookup = eafnosupport_ipv6_dst_lookup, 186 .ipv6_dst_lookup = eafnosupport_ipv6_dst_lookup,
178 .ipv6_route_input = eafnosupport_ipv6_route_input, 187 .ipv6_route_input = eafnosupport_ipv6_route_input,
179 .fib6_get_table = eafnosupport_fib6_get_table, 188 .fib6_get_table = eafnosupport_fib6_get_table,
180 .fib6_table_lookup = eafnosupport_fib6_table_lookup, 189 .fib6_table_lookup = eafnosupport_fib6_table_lookup,
181 .fib6_lookup = eafnosupport_fib6_lookup, 190 .fib6_lookup = eafnosupport_fib6_lookup,
182 .fib6_multipath_select = eafnosupport_fib6_multipath_select, 191 .fib6_select_path = eafnosupport_fib6_select_path,
183 .ip6_mtu_from_fib6 = eafnosupport_ip6_mtu_from_fib6, 192 .ip6_mtu_from_fib6 = eafnosupport_ip6_mtu_from_fib6,
193 .fib6_nh_init = eafnosupport_fib6_nh_init,
184}; 194};
185EXPORT_SYMBOL_GPL(ipv6_stub); 195EXPORT_SYMBOL_GPL(ipv6_stub);
186 196
diff --git a/net/ipv6/addrlabel.c b/net/ipv6/addrlabel.c
index d43d076c98f5..642fc6ac13d2 100644
--- a/net/ipv6/addrlabel.c
+++ b/net/ipv6/addrlabel.c
@@ -383,8 +383,8 @@ static int ip6addrlbl_newdel(struct sk_buff *skb, struct nlmsghdr *nlh,
383 u32 label; 383 u32 label;
384 int err = 0; 384 int err = 0;
385 385
386 err = nlmsg_parse(nlh, sizeof(*ifal), tb, IFAL_MAX, ifal_policy, 386 err = nlmsg_parse_deprecated(nlh, sizeof(*ifal), tb, IFAL_MAX,
387 extack); 387 ifal_policy, extack);
388 if (err < 0) 388 if (err < 0)
389 return err; 389 return err;
390 390
@@ -476,7 +476,7 @@ static int ip6addrlbl_valid_dump_req(const struct nlmsghdr *nlh,
476 } 476 }
477 477
478 if (nlmsg_attrlen(nlh, sizeof(*ifal))) { 478 if (nlmsg_attrlen(nlh, sizeof(*ifal))) {
479 NL_SET_ERR_MSG_MOD(extack, "Invalid data after header for address label dump requewst"); 479 NL_SET_ERR_MSG_MOD(extack, "Invalid data after header for address label dump request");
480 return -EINVAL; 480 return -EINVAL;
481 } 481 }
482 482
@@ -537,8 +537,8 @@ static int ip6addrlbl_valid_get_req(struct sk_buff *skb,
537 } 537 }
538 538
539 if (!netlink_strict_get_check(skb)) 539 if (!netlink_strict_get_check(skb))
540 return nlmsg_parse(nlh, sizeof(*ifal), tb, IFAL_MAX, 540 return nlmsg_parse_deprecated(nlh, sizeof(*ifal), tb,
541 ifal_policy, extack); 541 IFAL_MAX, ifal_policy, extack);
542 542
543 ifal = nlmsg_data(nlh); 543 ifal = nlmsg_data(nlh);
544 if (ifal->__ifal_reserved || ifal->ifal_flags || ifal->ifal_seq) { 544 if (ifal->__ifal_reserved || ifal->ifal_flags || ifal->ifal_seq) {
@@ -546,8 +546,8 @@ static int ip6addrlbl_valid_get_req(struct sk_buff *skb,
546 return -EINVAL; 546 return -EINVAL;
547 } 547 }
548 548
549 err = nlmsg_parse_strict(nlh, sizeof(*ifal), tb, IFAL_MAX, 549 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*ifal), tb, IFAL_MAX,
550 ifal_policy, extack); 550 ifal_policy, extack);
551 if (err) 551 if (err)
552 return err; 552 return err;
553 553
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 2f45d2a3e3a3..c04ae282f4e4 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -56,6 +56,7 @@
56#include <net/transp_v6.h> 56#include <net/transp_v6.h>
57#include <net/ip6_route.h> 57#include <net/ip6_route.h>
58#include <net/addrconf.h> 58#include <net/addrconf.h>
59#include <net/ipv6_stubs.h>
59#include <net/ndisc.h> 60#include <net/ndisc.h>
60#ifdef CONFIG_IPV6_TUNNEL 61#ifdef CONFIG_IPV6_TUNNEL
61#include <net/ip6_tunnel.h> 62#include <net/ip6_tunnel.h>
@@ -546,12 +547,6 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
546 struct net *net = sock_net(sk); 547 struct net *net = sock_net(sk);
547 548
548 switch (cmd) { 549 switch (cmd) {
549 case SIOCGSTAMP:
550 return sock_get_timestamp(sk, (struct timeval __user *)arg);
551
552 case SIOCGSTAMPNS:
553 return sock_get_timestampns(sk, (struct timespec __user *)arg);
554
555 case SIOCADDRT: 550 case SIOCADDRT:
556 case SIOCDELRT: 551 case SIOCDELRT:
557 552
@@ -584,6 +579,7 @@ const struct proto_ops inet6_stream_ops = {
584 .getname = inet6_getname, 579 .getname = inet6_getname,
585 .poll = tcp_poll, /* ok */ 580 .poll = tcp_poll, /* ok */
586 .ioctl = inet6_ioctl, /* must change */ 581 .ioctl = inet6_ioctl, /* must change */
582 .gettstamp = sock_gettstamp,
587 .listen = inet_listen, /* ok */ 583 .listen = inet_listen, /* ok */
588 .shutdown = inet_shutdown, /* ok */ 584 .shutdown = inet_shutdown, /* ok */
589 .setsockopt = sock_common_setsockopt, /* ok */ 585 .setsockopt = sock_common_setsockopt, /* ok */
@@ -617,6 +613,7 @@ const struct proto_ops inet6_dgram_ops = {
617 .getname = inet6_getname, 613 .getname = inet6_getname,
618 .poll = udp_poll, /* ok */ 614 .poll = udp_poll, /* ok */
619 .ioctl = inet6_ioctl, /* must change */ 615 .ioctl = inet6_ioctl, /* must change */
616 .gettstamp = sock_gettstamp,
620 .listen = sock_no_listen, /* ok */ 617 .listen = sock_no_listen, /* ok */
621 .shutdown = inet_shutdown, /* ok */ 618 .shutdown = inet_shutdown, /* ok */
622 .setsockopt = sock_common_setsockopt, /* ok */ 619 .setsockopt = sock_common_setsockopt, /* ok */
@@ -847,6 +844,17 @@ static int __net_init inet6_net_init(struct net *net)
847 net->ipv6.sysctl.bindv6only = 0; 844 net->ipv6.sysctl.bindv6only = 0;
848 net->ipv6.sysctl.icmpv6_time = 1*HZ; 845 net->ipv6.sysctl.icmpv6_time = 1*HZ;
849 net->ipv6.sysctl.icmpv6_echo_ignore_all = 0; 846 net->ipv6.sysctl.icmpv6_echo_ignore_all = 0;
847 net->ipv6.sysctl.icmpv6_echo_ignore_multicast = 0;
848 net->ipv6.sysctl.icmpv6_echo_ignore_anycast = 0;
849
850 /* By default, rate limit error messages.
851 * Except for pmtu discovery, it would break it.
852 * proc_do_large_bitmap needs pointer to the bitmap.
853 */
854 bitmap_set(net->ipv6.sysctl.icmpv6_ratemask, 0, ICMPV6_ERRMSG_MAX + 1);
855 bitmap_clear(net->ipv6.sysctl.icmpv6_ratemask, ICMPV6_PKT_TOOBIG, 1);
856 net->ipv6.sysctl.icmpv6_ratemask_ptr = net->ipv6.sysctl.icmpv6_ratemask;
857
850 net->ipv6.sysctl.flowlabel_consistency = 1; 858 net->ipv6.sysctl.flowlabel_consistency = 1;
851 net->ipv6.sysctl.auto_flowlabels = IP6_DEFAULT_AUTO_FLOW_LABELS; 859 net->ipv6.sysctl.auto_flowlabels = IP6_DEFAULT_AUTO_FLOW_LABELS;
852 net->ipv6.sysctl.idgen_retries = 3; 860 net->ipv6.sysctl.idgen_retries = 3;
@@ -914,8 +922,10 @@ static const struct ipv6_stub ipv6_stub_impl = {
914 .fib6_get_table = fib6_get_table, 922 .fib6_get_table = fib6_get_table,
915 .fib6_table_lookup = fib6_table_lookup, 923 .fib6_table_lookup = fib6_table_lookup,
916 .fib6_lookup = fib6_lookup, 924 .fib6_lookup = fib6_lookup,
917 .fib6_multipath_select = fib6_multipath_select, 925 .fib6_select_path = fib6_select_path,
918 .ip6_mtu_from_fib6 = ip6_mtu_from_fib6, 926 .ip6_mtu_from_fib6 = ip6_mtu_from_fib6,
927 .fib6_nh_init = fib6_nh_init,
928 .fib6_nh_release = fib6_nh_release,
919 .udpv6_encap_enable = udpv6_encap_enable, 929 .udpv6_encap_enable = udpv6_encap_enable,
920 .ndisc_send_na = ndisc_send_na, 930 .ndisc_send_na = ndisc_send_na,
921 .nd_tbl = &nd_tbl, 931 .nd_tbl = &nd_tbl,
diff --git a/net/ipv6/esp6_offload.c b/net/ipv6/esp6_offload.c
index d46b4eb645c2..d453cf417b03 100644
--- a/net/ipv6/esp6_offload.c
+++ b/net/ipv6/esp6_offload.c
@@ -74,13 +74,13 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head,
74 goto out; 74 goto out;
75 75
76 if (sp->len == XFRM_MAX_DEPTH) 76 if (sp->len == XFRM_MAX_DEPTH)
77 goto out; 77 goto out_reset;
78 78
79 x = xfrm_state_lookup(dev_net(skb->dev), skb->mark, 79 x = xfrm_state_lookup(dev_net(skb->dev), skb->mark,
80 (xfrm_address_t *)&ipv6_hdr(skb)->daddr, 80 (xfrm_address_t *)&ipv6_hdr(skb)->daddr,
81 spi, IPPROTO_ESP, AF_INET6); 81 spi, IPPROTO_ESP, AF_INET6);
82 if (!x) 82 if (!x)
83 goto out; 83 goto out_reset;
84 84
85 sp->xvec[sp->len++] = x; 85 sp->xvec[sp->len++] = x;
86 sp->olen++; 86 sp->olen++;
@@ -88,7 +88,7 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head,
88 xo = xfrm_offload(skb); 88 xo = xfrm_offload(skb);
89 if (!xo) { 89 if (!xo) {
90 xfrm_state_put(x); 90 xfrm_state_put(x);
91 goto out; 91 goto out_reset;
92 } 92 }
93 } 93 }
94 94
@@ -109,6 +109,8 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head,
109 xfrm_input(skb, IPPROTO_ESP, spi, -2); 109 xfrm_input(skb, IPPROTO_ESP, spi, -2);
110 110
111 return ERR_PTR(-EINPROGRESS); 111 return ERR_PTR(-EINPROGRESS);
112out_reset:
113 secpath_reset(skb);
112out: 114out:
113 skb_push(skb, offset); 115 skb_push(skb, offset);
114 NAPI_GRO_CB(skb)->same_flow = 0; 116 NAPI_GRO_CB(skb)->same_flow = 0;
@@ -134,6 +136,44 @@ static void esp6_gso_encap(struct xfrm_state *x, struct sk_buff *skb)
134 xo->proto = proto; 136 xo->proto = proto;
135} 137}
136 138
139static struct sk_buff *xfrm6_tunnel_gso_segment(struct xfrm_state *x,
140 struct sk_buff *skb,
141 netdev_features_t features)
142{
143 __skb_push(skb, skb->mac_len);
144 return skb_mac_gso_segment(skb, features);
145}
146
147static struct sk_buff *xfrm6_transport_gso_segment(struct xfrm_state *x,
148 struct sk_buff *skb,
149 netdev_features_t features)
150{
151 const struct net_offload *ops;
152 struct sk_buff *segs = ERR_PTR(-EINVAL);
153 struct xfrm_offload *xo = xfrm_offload(skb);
154
155 skb->transport_header += x->props.header_len;
156 ops = rcu_dereference(inet6_offloads[xo->proto]);
157 if (likely(ops && ops->callbacks.gso_segment))
158 segs = ops->callbacks.gso_segment(skb, features);
159
160 return segs;
161}
162
163static struct sk_buff *xfrm6_outer_mode_gso_segment(struct xfrm_state *x,
164 struct sk_buff *skb,
165 netdev_features_t features)
166{
167 switch (x->outer_mode.encap) {
168 case XFRM_MODE_TUNNEL:
169 return xfrm6_tunnel_gso_segment(x, skb, features);
170 case XFRM_MODE_TRANSPORT:
171 return xfrm6_transport_gso_segment(x, skb, features);
172 }
173
174 return ERR_PTR(-EOPNOTSUPP);
175}
176
137static struct sk_buff *esp6_gso_segment(struct sk_buff *skb, 177static struct sk_buff *esp6_gso_segment(struct sk_buff *skb,
138 netdev_features_t features) 178 netdev_features_t features)
139{ 179{
@@ -172,7 +212,7 @@ static struct sk_buff *esp6_gso_segment(struct sk_buff *skb,
172 212
173 xo->flags |= XFRM_GSO_SEGMENT; 213 xo->flags |= XFRM_GSO_SEGMENT;
174 214
175 return x->outer_mode->gso_segment(x, skb, esp_features); 215 return xfrm6_outer_mode_gso_segment(x, skb, esp_features);
176} 216}
177 217
178static int esp6_input_tail(struct xfrm_state *x, struct sk_buff *skb) 218static int esp6_input_tail(struct xfrm_state *x, struct sk_buff *skb)
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index f590446595d8..06d1b7763600 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -61,16 +61,16 @@ unsigned int fib6_rules_seq_read(struct net *net)
61} 61}
62 62
63/* called with rcu lock held; no reference taken on fib6_info */ 63/* called with rcu lock held; no reference taken on fib6_info */
64struct fib6_info *fib6_lookup(struct net *net, int oif, struct flowi6 *fl6, 64int fib6_lookup(struct net *net, int oif, struct flowi6 *fl6,
65 int flags) 65 struct fib6_result *res, int flags)
66{ 66{
67 struct fib6_info *f6i;
68 int err; 67 int err;
69 68
70 if (net->ipv6.fib6_has_custom_rules) { 69 if (net->ipv6.fib6_has_custom_rules) {
71 struct fib_lookup_arg arg = { 70 struct fib_lookup_arg arg = {
72 .lookup_ptr = fib6_table_lookup, 71 .lookup_ptr = fib6_table_lookup,
73 .lookup_data = &oif, 72 .lookup_data = &oif,
73 .result = res,
74 .flags = FIB_LOOKUP_NOREF, 74 .flags = FIB_LOOKUP_NOREF,
75 }; 75 };
76 76
@@ -78,19 +78,15 @@ struct fib6_info *fib6_lookup(struct net *net, int oif, struct flowi6 *fl6,
78 78
79 err = fib_rules_lookup(net->ipv6.fib6_rules_ops, 79 err = fib_rules_lookup(net->ipv6.fib6_rules_ops,
80 flowi6_to_flowi(fl6), flags, &arg); 80 flowi6_to_flowi(fl6), flags, &arg);
81 if (err)
82 return ERR_PTR(err);
83
84 f6i = arg.result ? : net->ipv6.fib6_null_entry;
85 } else { 81 } else {
86 f6i = fib6_table_lookup(net, net->ipv6.fib6_local_tbl, 82 err = fib6_table_lookup(net, net->ipv6.fib6_local_tbl, oif,
87 oif, fl6, flags); 83 fl6, res, flags);
88 if (!f6i || f6i == net->ipv6.fib6_null_entry) 84 if (err || res->f6i == net->ipv6.fib6_null_entry)
89 f6i = fib6_table_lookup(net, net->ipv6.fib6_main_tbl, 85 err = fib6_table_lookup(net, net->ipv6.fib6_main_tbl,
90 oif, fl6, flags); 86 oif, fl6, res, flags);
91 } 87 }
92 88
93 return f6i; 89 return err;
94} 90}
95 91
96struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6, 92struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
@@ -98,9 +94,11 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
98 int flags, pol_lookup_t lookup) 94 int flags, pol_lookup_t lookup)
99{ 95{
100 if (net->ipv6.fib6_has_custom_rules) { 96 if (net->ipv6.fib6_has_custom_rules) {
97 struct fib6_result res = {};
101 struct fib_lookup_arg arg = { 98 struct fib_lookup_arg arg = {
102 .lookup_ptr = lookup, 99 .lookup_ptr = lookup,
103 .lookup_data = skb, 100 .lookup_data = skb,
101 .result = &res,
104 .flags = FIB_LOOKUP_NOREF, 102 .flags = FIB_LOOKUP_NOREF,
105 }; 103 };
106 104
@@ -110,8 +108,8 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
110 fib_rules_lookup(net->ipv6.fib6_rules_ops, 108 fib_rules_lookup(net->ipv6.fib6_rules_ops,
111 flowi6_to_flowi(fl6), flags, &arg); 109 flowi6_to_flowi(fl6), flags, &arg);
112 110
113 if (arg.result) 111 if (res.rt6)
114 return arg.result; 112 return &res.rt6->dst;
115 } else { 113 } else {
116 struct rt6_info *rt; 114 struct rt6_info *rt;
117 115
@@ -157,11 +155,11 @@ static int fib6_rule_saddr(struct net *net, struct fib_rule *rule, int flags,
157static int fib6_rule_action_alt(struct fib_rule *rule, struct flowi *flp, 155static int fib6_rule_action_alt(struct fib_rule *rule, struct flowi *flp,
158 int flags, struct fib_lookup_arg *arg) 156 int flags, struct fib_lookup_arg *arg)
159{ 157{
158 struct fib6_result *res = arg->result;
160 struct flowi6 *flp6 = &flp->u.ip6; 159 struct flowi6 *flp6 = &flp->u.ip6;
161 struct net *net = rule->fr_net; 160 struct net *net = rule->fr_net;
162 struct fib6_table *table; 161 struct fib6_table *table;
163 struct fib6_info *f6i; 162 int err, *oif;
164 int err = -EAGAIN, *oif;
165 u32 tb_id; 163 u32 tb_id;
166 164
167 switch (rule->action) { 165 switch (rule->action) {
@@ -182,14 +180,12 @@ static int fib6_rule_action_alt(struct fib_rule *rule, struct flowi *flp,
182 return -EAGAIN; 180 return -EAGAIN;
183 181
184 oif = (int *)arg->lookup_data; 182 oif = (int *)arg->lookup_data;
185 f6i = fib6_table_lookup(net, table, *oif, flp6, flags); 183 err = fib6_table_lookup(net, table, *oif, flp6, res, flags);
186 if (f6i != net->ipv6.fib6_null_entry) { 184 if (!err && res->f6i != net->ipv6.fib6_null_entry)
187 err = fib6_rule_saddr(net, rule, flags, flp6, 185 err = fib6_rule_saddr(net, rule, flags, flp6,
188 fib6_info_nh_dev(f6i)); 186 res->nh->fib_nh_dev);
189 187 else
190 if (likely(!err)) 188 err = -EAGAIN;
191 arg->result = f6i;
192 }
193 189
194 return err; 190 return err;
195} 191}
@@ -197,6 +193,7 @@ static int fib6_rule_action_alt(struct fib_rule *rule, struct flowi *flp,
197static int __fib6_rule_action(struct fib_rule *rule, struct flowi *flp, 193static int __fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
198 int flags, struct fib_lookup_arg *arg) 194 int flags, struct fib_lookup_arg *arg)
199{ 195{
196 struct fib6_result *res = arg->result;
200 struct flowi6 *flp6 = &flp->u.ip6; 197 struct flowi6 *flp6 = &flp->u.ip6;
201 struct rt6_info *rt = NULL; 198 struct rt6_info *rt = NULL;
202 struct fib6_table *table; 199 struct fib6_table *table;
@@ -251,7 +248,7 @@ again:
251discard_pkt: 248discard_pkt:
252 dst_hold(&rt->dst); 249 dst_hold(&rt->dst);
253out: 250out:
254 arg->result = rt; 251 res->rt6 = rt;
255 return err; 252 return err;
256} 253}
257 254
@@ -266,9 +263,13 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
266 263
267static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg) 264static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg)
268{ 265{
269 struct rt6_info *rt = (struct rt6_info *) arg->result; 266 struct fib6_result *res = arg->result;
267 struct rt6_info *rt = res->rt6;
270 struct net_device *dev = NULL; 268 struct net_device *dev = NULL;
271 269
270 if (!rt)
271 return false;
272
272 if (rt->rt6i_idev) 273 if (rt->rt6i_idev)
273 dev = rt->rt6i_idev->dev; 274 dev = rt->rt6i_idev->dev;
274 275
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index 802faa2fcc0e..afb915807cd0 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -168,22 +168,21 @@ static bool is_ineligible(const struct sk_buff *skb)
168 return false; 168 return false;
169} 169}
170 170
171static bool icmpv6_mask_allow(int type) 171static bool icmpv6_mask_allow(struct net *net, int type)
172{ 172{
173 /* Informational messages are not limited. */ 173 if (type > ICMPV6_MSG_MAX)
174 if (type & ICMPV6_INFOMSG_MASK)
175 return true; 174 return true;
176 175
177 /* Do not limit pmtu discovery, it would break it. */ 176 /* Limit if icmp type is set in ratemask. */
178 if (type == ICMPV6_PKT_TOOBIG) 177 if (!test_bit(type, net->ipv6.sysctl.icmpv6_ratemask))
179 return true; 178 return true;
180 179
181 return false; 180 return false;
182} 181}
183 182
184static bool icmpv6_global_allow(int type) 183static bool icmpv6_global_allow(struct net *net, int type)
185{ 184{
186 if (icmpv6_mask_allow(type)) 185 if (icmpv6_mask_allow(net, type))
187 return true; 186 return true;
188 187
189 if (icmp_global_allow()) 188 if (icmp_global_allow())
@@ -202,7 +201,7 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type,
202 struct dst_entry *dst; 201 struct dst_entry *dst;
203 bool res = false; 202 bool res = false;
204 203
205 if (icmpv6_mask_allow(type)) 204 if (icmpv6_mask_allow(net, type))
206 return true; 205 return true;
207 206
208 /* 207 /*
@@ -511,7 +510,7 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
511 local_bh_disable(); 510 local_bh_disable();
512 511
513 /* Check global sysctl_icmp_msgs_per_sec ratelimit */ 512 /* Check global sysctl_icmp_msgs_per_sec ratelimit */
514 if (!(skb->dev->flags&IFF_LOOPBACK) && !icmpv6_global_allow(type)) 513 if (!(skb->dev->flags & IFF_LOOPBACK) && !icmpv6_global_allow(net, type))
515 goto out_bh_enable; 514 goto out_bh_enable;
516 515
517 mip6_addr_swap(skb); 516 mip6_addr_swap(skb);
@@ -683,12 +682,20 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
683 struct dst_entry *dst; 682 struct dst_entry *dst;
684 struct ipcm6_cookie ipc6; 683 struct ipcm6_cookie ipc6;
685 u32 mark = IP6_REPLY_MARK(net, skb->mark); 684 u32 mark = IP6_REPLY_MARK(net, skb->mark);
685 bool acast;
686
687 if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) &&
688 net->ipv6.sysctl.icmpv6_echo_ignore_multicast)
689 return;
686 690
687 saddr = &ipv6_hdr(skb)->daddr; 691 saddr = &ipv6_hdr(skb)->daddr;
688 692
693 acast = ipv6_anycast_destination(skb_dst(skb), saddr);
694 if (acast && net->ipv6.sysctl.icmpv6_echo_ignore_anycast)
695 return;
696
689 if (!ipv6_unicast_destination(skb) && 697 if (!ipv6_unicast_destination(skb) &&
690 !(net->ipv6.sysctl.anycast_src_echo_reply && 698 !(net->ipv6.sysctl.anycast_src_echo_reply && acast))
691 ipv6_anycast_destination(skb_dst(skb), saddr)))
692 saddr = NULL; 699 saddr = NULL;
693 700
694 memcpy(&tmp_hdr, icmph, sizeof(tmp_hdr)); 701 memcpy(&tmp_hdr, icmph, sizeof(tmp_hdr));
@@ -723,6 +730,11 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
723 if (IS_ERR(dst)) 730 if (IS_ERR(dst))
724 goto out; 731 goto out;
725 732
733 /* Check the ratelimit */
734 if ((!(skb->dev->flags & IFF_LOOPBACK) && !icmpv6_global_allow(net, ICMPV6_ECHO_REPLY)) ||
735 !icmpv6_xrlim_allow(sk, ICMPV6_ECHO_REPLY, &fl6))
736 goto out_dst_release;
737
726 idev = __in6_dev_get(skb->dev); 738 idev = __in6_dev_get(skb->dev);
727 739
728 msg.skb = skb; 740 msg.skb = skb;
@@ -743,6 +755,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
743 icmpv6_push_pending_frames(sk, &fl6, &tmp_hdr, 755 icmpv6_push_pending_frames(sk, &fl6, &tmp_hdr,
744 skb->len + sizeof(struct icmp6hdr)); 756 skb->len + sizeof(struct icmp6hdr));
745 } 757 }
758out_dst_release:
746 dst_release(dst); 759 dst_release(dst);
747out: 760out:
748 icmpv6_xmit_unlock(sk); 761 icmpv6_xmit_unlock(sk);
@@ -1115,6 +1128,27 @@ static struct ctl_table ipv6_icmp_table_template[] = {
1115 .mode = 0644, 1128 .mode = 0644,
1116 .proc_handler = proc_dointvec, 1129 .proc_handler = proc_dointvec,
1117 }, 1130 },
1131 {
1132 .procname = "echo_ignore_multicast",
1133 .data = &init_net.ipv6.sysctl.icmpv6_echo_ignore_multicast,
1134 .maxlen = sizeof(int),
1135 .mode = 0644,
1136 .proc_handler = proc_dointvec,
1137 },
1138 {
1139 .procname = "echo_ignore_anycast",
1140 .data = &init_net.ipv6.sysctl.icmpv6_echo_ignore_anycast,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
1143 .proc_handler = proc_dointvec,
1144 },
1145 {
1146 .procname = "ratemask",
1147 .data = &init_net.ipv6.sysctl.icmpv6_ratemask_ptr,
1148 .maxlen = ICMPV6_MSG_MAX + 1,
1149 .mode = 0644,
1150 .proc_handler = proc_do_large_bitmap,
1151 },
1118 { }, 1152 { },
1119}; 1153};
1120 1154
@@ -1129,6 +1163,9 @@ struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
1129 if (table) { 1163 if (table) {
1130 table[0].data = &net->ipv6.sysctl.icmpv6_time; 1164 table[0].data = &net->ipv6.sysctl.icmpv6_time;
1131 table[1].data = &net->ipv6.sysctl.icmpv6_echo_ignore_all; 1165 table[1].data = &net->ipv6.sysctl.icmpv6_echo_ignore_all;
1166 table[2].data = &net->ipv6.sysctl.icmpv6_echo_ignore_multicast;
1167 table[3].data = &net->ipv6.sysctl.icmpv6_echo_ignore_anycast;
1168 table[4].data = &net->ipv6.sysctl.icmpv6_ratemask_ptr;
1132 } 1169 }
1133 return table; 1170 return table;
1134} 1171}
diff --git a/net/ipv6/ila/ila_lwt.c b/net/ipv6/ila/ila_lwt.c
index 3d56a2fb6f86..422dcc691f71 100644
--- a/net/ipv6/ila/ila_lwt.c
+++ b/net/ipv6/ila/ila_lwt.c
@@ -146,7 +146,8 @@ static int ila_build_state(struct nlattr *nla,
146 if (family != AF_INET6) 146 if (family != AF_INET6)
147 return -EINVAL; 147 return -EINVAL;
148 148
149 ret = nla_parse_nested(tb, ILA_ATTR_MAX, nla, ila_nl_policy, extack); 149 ret = nla_parse_nested_deprecated(tb, ILA_ATTR_MAX, nla,
150 ila_nl_policy, extack);
150 if (ret < 0) 151 if (ret < 0)
151 return ret; 152 return ret;
152 153
diff --git a/net/ipv6/ila/ila_main.c b/net/ipv6/ila/ila_main.c
index 18fac76b9520..257d2b681246 100644
--- a/net/ipv6/ila/ila_main.c
+++ b/net/ipv6/ila/ila_main.c
@@ -16,29 +16,29 @@ static const struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = {
16static const struct genl_ops ila_nl_ops[] = { 16static const struct genl_ops ila_nl_ops[] = {
17 { 17 {
18 .cmd = ILA_CMD_ADD, 18 .cmd = ILA_CMD_ADD,
19 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
19 .doit = ila_xlat_nl_cmd_add_mapping, 20 .doit = ila_xlat_nl_cmd_add_mapping,
20 .policy = ila_nl_policy,
21 .flags = GENL_ADMIN_PERM, 21 .flags = GENL_ADMIN_PERM,
22 }, 22 },
23 { 23 {
24 .cmd = ILA_CMD_DEL, 24 .cmd = ILA_CMD_DEL,
25 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
25 .doit = ila_xlat_nl_cmd_del_mapping, 26 .doit = ila_xlat_nl_cmd_del_mapping,
26 .policy = ila_nl_policy,
27 .flags = GENL_ADMIN_PERM, 27 .flags = GENL_ADMIN_PERM,
28 }, 28 },
29 { 29 {
30 .cmd = ILA_CMD_FLUSH, 30 .cmd = ILA_CMD_FLUSH,
31 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
31 .doit = ila_xlat_nl_cmd_flush, 32 .doit = ila_xlat_nl_cmd_flush,
32 .policy = ila_nl_policy,
33 .flags = GENL_ADMIN_PERM, 33 .flags = GENL_ADMIN_PERM,
34 }, 34 },
35 { 35 {
36 .cmd = ILA_CMD_GET, 36 .cmd = ILA_CMD_GET,
37 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
37 .doit = ila_xlat_nl_cmd_get_mapping, 38 .doit = ila_xlat_nl_cmd_get_mapping,
38 .start = ila_xlat_nl_dump_start, 39 .start = ila_xlat_nl_dump_start,
39 .dumpit = ila_xlat_nl_dump, 40 .dumpit = ila_xlat_nl_dump,
40 .done = ila_xlat_nl_dump_done, 41 .done = ila_xlat_nl_dump_done,
41 .policy = ila_nl_policy,
42 }, 42 },
43}; 43};
44 44
@@ -49,6 +49,7 @@ struct genl_family ila_nl_family __ro_after_init = {
49 .name = ILA_GENL_NAME, 49 .name = ILA_GENL_NAME,
50 .version = ILA_GENL_VERSION, 50 .version = ILA_GENL_VERSION,
51 .maxattr = ILA_ATTR_MAX, 51 .maxattr = ILA_ATTR_MAX,
52 .policy = ila_nl_policy,
52 .netnsok = true, 53 .netnsok = true,
53 .parallel_ops = true, 54 .parallel_ops = true,
54 .module = THIS_MODULE, 55 .module = THIS_MODULE,
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 6613d8dbb0e5..08e0390e001c 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -162,7 +162,7 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags)
162 } 162 }
163 163
164 INIT_LIST_HEAD(&f6i->fib6_siblings); 164 INIT_LIST_HEAD(&f6i->fib6_siblings);
165 atomic_inc(&f6i->fib6_ref); 165 refcount_set(&f6i->fib6_ref, 1);
166 166
167 return f6i; 167 return f6i;
168} 168}
@@ -175,10 +175,7 @@ void fib6_info_destroy_rcu(struct rcu_head *head)
175 WARN_ON(f6i->fib6_node); 175 WARN_ON(f6i->fib6_node);
176 176
177 bucket = rcu_dereference_protected(f6i->rt6i_exception_bucket, 1); 177 bucket = rcu_dereference_protected(f6i->rt6i_exception_bucket, 1);
178 if (bucket) { 178 kfree(bucket);
179 f6i->rt6i_exception_bucket = NULL;
180 kfree(bucket);
181 }
182 179
183 if (f6i->rt6i_pcpu) { 180 if (f6i->rt6i_pcpu) {
184 int cpu; 181 int cpu;
@@ -199,10 +196,7 @@ void fib6_info_destroy_rcu(struct rcu_head *head)
199 free_percpu(f6i->rt6i_pcpu); 196 free_percpu(f6i->rt6i_pcpu);
200 } 197 }
201 198
202 lwtstate_put(f6i->fib6_nh.nh_lwtstate); 199 fib6_nh_release(&f6i->fib6_nh);
203
204 if (f6i->fib6_nh.nh_dev)
205 dev_put(f6i->fib6_nh.nh_dev);
206 200
207 ip_fib_metrics_put(f6i->fib6_metrics); 201 ip_fib_metrics_put(f6i->fib6_metrics);
208 202
@@ -357,10 +351,11 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
357} 351}
358 352
359/* called with rcu lock held; no reference taken on fib6_info */ 353/* called with rcu lock held; no reference taken on fib6_info */
360struct fib6_info *fib6_lookup(struct net *net, int oif, struct flowi6 *fl6, 354int fib6_lookup(struct net *net, int oif, struct flowi6 *fl6,
361 int flags) 355 struct fib6_result *res, int flags)
362{ 356{
363 return fib6_table_lookup(net, net->ipv6.fib6_main_tbl, oif, fl6, flags); 357 return fib6_table_lookup(net, net->ipv6.fib6_main_tbl, oif, fl6,
358 res, flags);
364} 359}
365 360
366static void __net_init fib6_tables_init(struct net *net) 361static void __net_init fib6_tables_init(struct net *net)
@@ -851,8 +846,8 @@ insert_above:
851 846
852 RCU_INIT_POINTER(in->parent, pn); 847 RCU_INIT_POINTER(in->parent, pn);
853 in->leaf = fn->leaf; 848 in->leaf = fn->leaf;
854 atomic_inc(&rcu_dereference_protected(in->leaf, 849 fib6_info_hold(rcu_dereference_protected(in->leaf,
855 lockdep_is_held(&table->tb6_lock))->fib6_ref); 850 lockdep_is_held(&table->tb6_lock)));
856 851
857 /* update parent pointer */ 852 /* update parent pointer */
858 if (dir) 853 if (dir)
@@ -921,9 +916,7 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i,
921 if (pcpu_rt) { 916 if (pcpu_rt) {
922 struct fib6_info *from; 917 struct fib6_info *from;
923 918
924 from = rcu_dereference_protected(pcpu_rt->from, 919 from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL);
925 lockdep_is_held(&table->tb6_lock));
926 rcu_assign_pointer(pcpu_rt->from, NULL);
927 fib6_info_release(from); 920 fib6_info_release(from);
928 } 921 }
929 } 922 }
@@ -934,7 +927,7 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
934{ 927{
935 struct fib6_table *table = rt->fib6_table; 928 struct fib6_table *table = rt->fib6_table;
936 929
937 if (atomic_read(&rt->fib6_ref) != 1) { 930 if (refcount_read(&rt->fib6_ref) != 1) {
938 /* This route is used as dummy address holder in some split 931 /* This route is used as dummy address holder in some split
939 * nodes. It is not leaked, but it still holds other resources, 932 * nodes. It is not leaked, but it still holds other resources,
940 * which must be released in time. So, scan ascendant nodes 933 * which must be released in time. So, scan ascendant nodes
@@ -947,7 +940,7 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
947 struct fib6_info *new_leaf; 940 struct fib6_info *new_leaf;
948 if (!(fn->fn_flags & RTN_RTINFO) && leaf == rt) { 941 if (!(fn->fn_flags & RTN_RTINFO) && leaf == rt) {
949 new_leaf = fib6_find_prefix(net, table, fn); 942 new_leaf = fib6_find_prefix(net, table, fn);
950 atomic_inc(&new_leaf->fib6_ref); 943 fib6_info_hold(new_leaf);
951 944
952 rcu_assign_pointer(fn->leaf, new_leaf); 945 rcu_assign_pointer(fn->leaf, new_leaf);
953 fib6_info_release(rt); 946 fib6_info_release(rt);
@@ -1113,7 +1106,7 @@ add:
1113 return err; 1106 return err;
1114 1107
1115 rcu_assign_pointer(rt->fib6_next, iter); 1108 rcu_assign_pointer(rt->fib6_next, iter);
1116 atomic_inc(&rt->fib6_ref); 1109 fib6_info_hold(rt);
1117 rcu_assign_pointer(rt->fib6_node, fn); 1110 rcu_assign_pointer(rt->fib6_node, fn);
1118 rcu_assign_pointer(*ins, rt); 1111 rcu_assign_pointer(*ins, rt);
1119 if (!info->skip_notify) 1112 if (!info->skip_notify)
@@ -1141,7 +1134,7 @@ add:
1141 if (err) 1134 if (err)
1142 return err; 1135 return err;
1143 1136
1144 atomic_inc(&rt->fib6_ref); 1137 fib6_info_hold(rt);
1145 rcu_assign_pointer(rt->fib6_node, fn); 1138 rcu_assign_pointer(rt->fib6_node, fn);
1146 rt->fib6_next = iter->fib6_next; 1139 rt->fib6_next = iter->fib6_next;
1147 rcu_assign_pointer(*ins, rt); 1140 rcu_assign_pointer(*ins, rt);
@@ -1283,7 +1276,7 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt,
1283 if (!sfn) 1276 if (!sfn)
1284 goto failure; 1277 goto failure;
1285 1278
1286 atomic_inc(&info->nl_net->ipv6.fib6_null_entry->fib6_ref); 1279 fib6_info_hold(info->nl_net->ipv6.fib6_null_entry);
1287 rcu_assign_pointer(sfn->leaf, 1280 rcu_assign_pointer(sfn->leaf,
1288 info->nl_net->ipv6.fib6_null_entry); 1281 info->nl_net->ipv6.fib6_null_entry);
1289 sfn->fn_flags = RTN_ROOT; 1282 sfn->fn_flags = RTN_ROOT;
@@ -1326,7 +1319,7 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt,
1326 rcu_assign_pointer(fn->leaf, 1319 rcu_assign_pointer(fn->leaf,
1327 info->nl_net->ipv6.fib6_null_entry); 1320 info->nl_net->ipv6.fib6_null_entry);
1328 } else { 1321 } else {
1329 atomic_inc(&rt->fib6_ref); 1322 fib6_info_hold(rt);
1330 rcu_assign_pointer(fn->leaf, rt); 1323 rcu_assign_pointer(fn->leaf, rt);
1331 } 1324 }
1332 } 1325 }
@@ -2297,6 +2290,7 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v)
2297{ 2290{
2298 struct fib6_info *rt = v; 2291 struct fib6_info *rt = v;
2299 struct ipv6_route_iter *iter = seq->private; 2292 struct ipv6_route_iter *iter = seq->private;
2293 unsigned int flags = rt->fib6_flags;
2300 const struct net_device *dev; 2294 const struct net_device *dev;
2301 2295
2302 seq_printf(seq, "%pi6 %02x ", &rt->fib6_dst.addr, rt->fib6_dst.plen); 2296 seq_printf(seq, "%pi6 %02x ", &rt->fib6_dst.addr, rt->fib6_dst.plen);
@@ -2306,15 +2300,17 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v)
2306#else 2300#else
2307 seq_puts(seq, "00000000000000000000000000000000 00 "); 2301 seq_puts(seq, "00000000000000000000000000000000 00 ");
2308#endif 2302#endif
2309 if (rt->fib6_flags & RTF_GATEWAY) 2303 if (rt->fib6_nh.fib_nh_gw_family) {
2310 seq_printf(seq, "%pi6", &rt->fib6_nh.nh_gw); 2304 flags |= RTF_GATEWAY;
2311 else 2305 seq_printf(seq, "%pi6", &rt->fib6_nh.fib_nh_gw6);
2306 } else {
2312 seq_puts(seq, "00000000000000000000000000000000"); 2307 seq_puts(seq, "00000000000000000000000000000000");
2308 }
2313 2309
2314 dev = rt->fib6_nh.nh_dev; 2310 dev = rt->fib6_nh.fib_nh_dev;
2315 seq_printf(seq, " %08x %08x %08x %08x %8s\n", 2311 seq_printf(seq, " %08x %08x %08x %08x %8s\n",
2316 rt->fib6_metric, atomic_read(&rt->fib6_ref), 0, 2312 rt->fib6_metric, refcount_read(&rt->fib6_ref), 0,
2317 rt->fib6_flags, dev ? dev->name : ""); 2313 flags, dev ? dev->name : "");
2318 iter->w.leaf = NULL; 2314 iter->w.leaf = NULL;
2319 return 0; 2315 return 0;
2320} 2316}
diff --git a/net/ipv6/ip6_flowlabel.c b/net/ipv6/ip6_flowlabel.c
index cb54a8a3c273..be5f3d7ceb96 100644
--- a/net/ipv6/ip6_flowlabel.c
+++ b/net/ipv6/ip6_flowlabel.c
@@ -94,15 +94,21 @@ static struct ip6_flowlabel *fl_lookup(struct net *net, __be32 label)
94 return fl; 94 return fl;
95} 95}
96 96
97static void fl_free_rcu(struct rcu_head *head)
98{
99 struct ip6_flowlabel *fl = container_of(head, struct ip6_flowlabel, rcu);
100
101 if (fl->share == IPV6_FL_S_PROCESS)
102 put_pid(fl->owner.pid);
103 kfree(fl->opt);
104 kfree(fl);
105}
106
97 107
98static void fl_free(struct ip6_flowlabel *fl) 108static void fl_free(struct ip6_flowlabel *fl)
99{ 109{
100 if (fl) { 110 if (fl)
101 if (fl->share == IPV6_FL_S_PROCESS) 111 call_rcu(&fl->rcu, fl_free_rcu);
102 put_pid(fl->owner.pid);
103 kfree(fl->opt);
104 kfree_rcu(fl, rcu);
105 }
106} 112}
107 113
108static void fl_release(struct ip6_flowlabel *fl) 114static void fl_release(struct ip6_flowlabel *fl)
@@ -633,9 +639,9 @@ recheck:
633 if (fl1->share == IPV6_FL_S_EXCL || 639 if (fl1->share == IPV6_FL_S_EXCL ||
634 fl1->share != fl->share || 640 fl1->share != fl->share ||
635 ((fl1->share == IPV6_FL_S_PROCESS) && 641 ((fl1->share == IPV6_FL_S_PROCESS) &&
636 (fl1->owner.pid == fl->owner.pid)) || 642 (fl1->owner.pid != fl->owner.pid)) ||
637 ((fl1->share == IPV6_FL_S_USER) && 643 ((fl1->share == IPV6_FL_S_USER) &&
638 uid_eq(fl1->owner.uid, fl->owner.uid))) 644 !uid_eq(fl1->owner.uid, fl->owner.uid)))
639 goto release; 645 goto release;
640 646
641 err = -ENOMEM; 647 err = -ENOMEM;
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index c7ed2b6d5a1d..b50b1af1f530 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -29,6 +29,7 @@
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#include <linux/slab.h>
32#include <linux/indirect_call_wrapper.h>
32 33
33#include <linux/netfilter.h> 34#include <linux/netfilter.h>
34#include <linux/netfilter_ipv6.h> 35#include <linux/netfilter_ipv6.h>
@@ -47,6 +48,8 @@
47#include <net/inet_ecn.h> 48#include <net/inet_ecn.h>
48#include <net/dst_metadata.h> 49#include <net/dst_metadata.h>
49 50
51INDIRECT_CALLABLE_DECLARE(void udp_v6_early_demux(struct sk_buff *));
52INDIRECT_CALLABLE_DECLARE(void tcp_v6_early_demux(struct sk_buff *));
50static void ip6_rcv_finish_core(struct net *net, struct sock *sk, 53static void ip6_rcv_finish_core(struct net *net, struct sock *sk,
51 struct sk_buff *skb) 54 struct sk_buff *skb)
52{ 55{
@@ -57,7 +60,8 @@ static void ip6_rcv_finish_core(struct net *net, struct sock *sk,
57 60
58 ipprot = rcu_dereference(inet6_protos[ipv6_hdr(skb)->nexthdr]); 61 ipprot = rcu_dereference(inet6_protos[ipv6_hdr(skb)->nexthdr]);
59 if (ipprot && (edemux = READ_ONCE(ipprot->early_demux))) 62 if (ipprot && (edemux = READ_ONCE(ipprot->early_demux)))
60 edemux(skb); 63 INDIRECT_CALL_2(edemux, tcp_v6_early_demux,
64 udp_v6_early_demux, skb);
61 } 65 }
62 if (!skb_valid_dst(skb)) 66 if (!skb_valid_dst(skb))
63 ip6_route_input(skb); 67 ip6_route_input(skb);
@@ -316,6 +320,9 @@ void ipv6_list_rcv(struct list_head *head, struct packet_type *pt,
316 ip6_sublist_rcv(&sublist, curr_dev, curr_net); 320 ip6_sublist_rcv(&sublist, curr_dev, curr_net);
317} 321}
318 322
323INDIRECT_CALLABLE_DECLARE(int udpv6_rcv(struct sk_buff *));
324INDIRECT_CALLABLE_DECLARE(int tcp_v6_rcv(struct sk_buff *));
325
319/* 326/*
320 * Deliver the packet to the host 327 * Deliver the packet to the host
321 */ 328 */
@@ -391,7 +398,8 @@ resubmit_final:
391 !xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) 398 !xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
392 goto discard; 399 goto discard;
393 400
394 ret = ipprot->handler(skb); 401 ret = INDIRECT_CALL_2(ipprot->handler, tcp_v6_rcv, udpv6_rcv,
402 skb);
395 if (ret > 0) { 403 if (ret > 0) {
396 if (ipprot->flags & INET6_PROTO_FINAL) { 404 if (ipprot->flags & INET6_PROTO_FINAL) {
397 /* Not an extension header, most likely UDP 405 /* Not an extension header, most likely UDP
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index e51f3c648b09..adef2236abe2 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -117,7 +117,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
117 neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false); 117 neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
118 if (!IS_ERR(neigh)) { 118 if (!IS_ERR(neigh)) {
119 sock_confirm_neigh(skb, neigh); 119 sock_confirm_neigh(skb, neigh);
120 ret = neigh_output(neigh, skb); 120 ret = neigh_output(neigh, skb, false);
121 rcu_read_unlock_bh(); 121 rcu_read_unlock_bh();
122 return ret; 122 return ret;
123 } 123 }
diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
index 8b6eefff2f7e..218a0dedc8f4 100644
--- a/net/ipv6/ip6_vti.c
+++ b/net/ipv6/ip6_vti.c
@@ -342,7 +342,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
342 struct net_device *dev; 342 struct net_device *dev;
343 struct pcpu_sw_netstats *tstats; 343 struct pcpu_sw_netstats *tstats;
344 struct xfrm_state *x; 344 struct xfrm_state *x;
345 struct xfrm_mode *inner_mode; 345 const struct xfrm_mode *inner_mode;
346 struct ip6_tnl *t = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6; 346 struct ip6_tnl *t = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6;
347 u32 orig_mark = skb->mark; 347 u32 orig_mark = skb->mark;
348 int ret; 348 int ret;
@@ -361,7 +361,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
361 361
362 x = xfrm_input_state(skb); 362 x = xfrm_input_state(skb);
363 363
364 inner_mode = x->inner_mode; 364 inner_mode = &x->inner_mode;
365 365
366 if (x->sel.family == AF_UNSPEC) { 366 if (x->sel.family == AF_UNSPEC) {
367 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol); 367 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
@@ -372,7 +372,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
372 } 372 }
373 } 373 }
374 374
375 family = inner_mode->afinfo->family; 375 family = inner_mode->family;
376 376
377 skb->mark = be32_to_cpu(t->parms.i_key); 377 skb->mark = be32_to_cpu(t->parms.i_key);
378 ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family); 378 ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index e4dd57976737..4e69847ed5be 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -355,7 +355,6 @@ static const struct rhashtable_params ip6mr_rht_params = {
355 .key_offset = offsetof(struct mfc6_cache, cmparg), 355 .key_offset = offsetof(struct mfc6_cache, cmparg),
356 .key_len = sizeof(struct mfc6_cache_cmp_arg), 356 .key_len = sizeof(struct mfc6_cache_cmp_arg),
357 .nelem_hint = 3, 357 .nelem_hint = 3,
358 .locks_mul = 1,
359 .obj_cmpfn = ip6mr_hash_cmp, 358 .obj_cmpfn = ip6mr_hash_cmp,
360 .automatic_shrinking = true, 359 .automatic_shrinking = true,
361}; 360};
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 659ecf4e4b3c..4c8e2ea8bf19 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -77,6 +77,8 @@ static u32 ndisc_hash(const void *pkey,
77 const struct net_device *dev, 77 const struct net_device *dev,
78 __u32 *hash_rnd); 78 __u32 *hash_rnd);
79static bool ndisc_key_eq(const struct neighbour *neigh, const void *pkey); 79static bool ndisc_key_eq(const struct neighbour *neigh, const void *pkey);
80static bool ndisc_allow_add(const struct net_device *dev,
81 struct netlink_ext_ack *extack);
80static int ndisc_constructor(struct neighbour *neigh); 82static int ndisc_constructor(struct neighbour *neigh);
81static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb); 83static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb);
82static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb); 84static void ndisc_error_report(struct neighbour *neigh, struct sk_buff *skb);
@@ -117,6 +119,7 @@ struct neigh_table nd_tbl = {
117 .pconstructor = pndisc_constructor, 119 .pconstructor = pndisc_constructor,
118 .pdestructor = pndisc_destructor, 120 .pdestructor = pndisc_destructor,
119 .proxy_redo = pndisc_redo, 121 .proxy_redo = pndisc_redo,
122 .allow_add = ndisc_allow_add,
120 .id = "ndisc_cache", 123 .id = "ndisc_cache",
121 .parms = { 124 .parms = {
122 .tbl = &nd_tbl, 125 .tbl = &nd_tbl,
@@ -392,6 +395,20 @@ static void pndisc_destructor(struct pneigh_entry *n)
392 ipv6_dev_mc_dec(dev, &maddr); 395 ipv6_dev_mc_dec(dev, &maddr);
393} 396}
394 397
398/* called with rtnl held */
399static bool ndisc_allow_add(const struct net_device *dev,
400 struct netlink_ext_ack *extack)
401{
402 struct inet6_dev *idev = __in6_dev_get(dev);
403
404 if (!idev || idev->cnf.disable_ipv6) {
405 NL_SET_ERR_MSG(extack, "IPv6 is disabled on this device");
406 return false;
407 }
408
409 return true;
410}
411
395static struct sk_buff *ndisc_alloc_skb(struct net_device *dev, 412static struct sk_buff *ndisc_alloc_skb(struct net_device *dev,
396 int len) 413 int len)
397{ 414{
@@ -1276,8 +1293,8 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1276 rt = rt6_get_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev); 1293 rt = rt6_get_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev);
1277 1294
1278 if (rt) { 1295 if (rt) {
1279 neigh = ip6_neigh_lookup(&rt->fib6_nh.nh_gw, 1296 neigh = ip6_neigh_lookup(&rt->fib6_nh.fib_nh_gw6,
1280 rt->fib6_nh.nh_dev, NULL, 1297 rt->fib6_nh.fib_nh_dev, NULL,
1281 &ipv6_hdr(skb)->saddr); 1298 &ipv6_hdr(skb)->saddr);
1282 if (!neigh) { 1299 if (!neigh) {
1283 ND_PRINTK(0, err, 1300 ND_PRINTK(0, err,
@@ -1306,8 +1323,8 @@ static void ndisc_router_discovery(struct sk_buff *skb)
1306 return; 1323 return;
1307 } 1324 }
1308 1325
1309 neigh = ip6_neigh_lookup(&rt->fib6_nh.nh_gw, 1326 neigh = ip6_neigh_lookup(&rt->fib6_nh.fib_nh_gw6,
1310 rt->fib6_nh.nh_dev, NULL, 1327 rt->fib6_nh.fib_nh_dev, NULL,
1311 &ipv6_hdr(skb)->saddr); 1328 &ipv6_hdr(skb)->saddr);
1312 if (!neigh) { 1329 if (!neigh) {
1313 ND_PRINTK(0, err, 1330 ND_PRINTK(0, err,
diff --git a/net/ipv6/netfilter/Kconfig b/net/ipv6/netfilter/Kconfig
index ddc99a1653aa..086fc669279e 100644
--- a/net/ipv6/netfilter/Kconfig
+++ b/net/ipv6/netfilter/Kconfig
@@ -23,14 +23,6 @@ config NF_TABLES_IPV6
23 23
24if NF_TABLES_IPV6 24if NF_TABLES_IPV6
25 25
26config NFT_CHAIN_ROUTE_IPV6
27 tristate "IPv6 nf_tables route chain support"
28 help
29 This option enables the "route" chain for IPv6 in nf_tables. This
30 chain type is used to force packet re-routing after mangling header
31 fields such as the source, destination, flowlabel, hop-limit and
32 the packet mark.
33
34config NFT_REJECT_IPV6 26config NFT_REJECT_IPV6
35 select NF_REJECT_IPV6 27 select NF_REJECT_IPV6
36 default NFT_REJECT 28 default NFT_REJECT
@@ -278,15 +270,10 @@ if IP6_NF_NAT
278 270
279config IP6_NF_TARGET_MASQUERADE 271config IP6_NF_TARGET_MASQUERADE
280 tristate "MASQUERADE target support" 272 tristate "MASQUERADE target support"
281 select NF_NAT_MASQUERADE 273 select NETFILTER_XT_TARGET_MASQUERADE
282 help 274 help
283 Masquerading is a special case of NAT: all outgoing connections are 275 This is a backwards-compat option for the user's convenience
284 changed to seem to come from a particular interface's address, and 276 (e.g. when running oldconfig). It selects NETFILTER_XT_TARGET_MASQUERADE.
285 if the interface goes down, those connections are lost. This is
286 only useful for dialup accounts with dynamic IP address (ie. your IP
287 address will be different on next dialup).
288
289 To compile it as a module, choose M here. If unsure, say N.
290 277
291config IP6_NF_TARGET_NPT 278config IP6_NF_TARGET_NPT
292 tristate "NPT (Network Prefix translation) target support" 279 tristate "NPT (Network Prefix translation) target support"
diff --git a/net/ipv6/netfilter/Makefile b/net/ipv6/netfilter/Makefile
index 3853c648ebaa..731a74c60dca 100644
--- a/net/ipv6/netfilter/Makefile
+++ b/net/ipv6/netfilter/Makefile
@@ -27,7 +27,6 @@ obj-$(CONFIG_NF_REJECT_IPV6) += nf_reject_ipv6.o
27obj-$(CONFIG_NF_DUP_IPV6) += nf_dup_ipv6.o 27obj-$(CONFIG_NF_DUP_IPV6) += nf_dup_ipv6.o
28 28
29# nf_tables 29# nf_tables
30obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o
31obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o 30obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o
32obj-$(CONFIG_NFT_DUP_IPV6) += nft_dup_ipv6.o 31obj-$(CONFIG_NFT_DUP_IPV6) += nft_dup_ipv6.o
33obj-$(CONFIG_NFT_FIB_IPV6) += nft_fib_ipv6.o 32obj-$(CONFIG_NFT_FIB_IPV6) += nft_fib_ipv6.o
@@ -47,7 +46,6 @@ obj-$(CONFIG_IP6_NF_MATCH_RT) += ip6t_rt.o
47obj-$(CONFIG_IP6_NF_MATCH_SRH) += ip6t_srh.o 46obj-$(CONFIG_IP6_NF_MATCH_SRH) += ip6t_srh.o
48 47
49# targets 48# targets
50obj-$(CONFIG_IP6_NF_TARGET_MASQUERADE) += ip6t_MASQUERADE.o
51obj-$(CONFIG_IP6_NF_TARGET_NPT) += ip6t_NPT.o 49obj-$(CONFIG_IP6_NF_TARGET_NPT) += ip6t_NPT.o
52obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o 50obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
53obj-$(CONFIG_IP6_NF_TARGET_SYNPROXY) += ip6t_SYNPROXY.o 51obj-$(CONFIG_IP6_NF_TARGET_SYNPROXY) += ip6t_SYNPROXY.o
diff --git a/net/ipv6/netfilter/ip6t_MASQUERADE.c b/net/ipv6/netfilter/ip6t_MASQUERADE.c
deleted file mode 100644
index 29c7f1915a96..000000000000
--- a/net/ipv6/netfilter/ip6t_MASQUERADE.c
+++ /dev/null
@@ -1,81 +0,0 @@
1/*
2 * Copyright (c) 2011 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 * Based on Rusty Russell's IPv6 MASQUERADE target. Development of IPv6
9 * NAT funded by Astaro.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/netdevice.h>
15#include <linux/ipv6.h>
16#include <linux/netfilter.h>
17#include <linux/netfilter_ipv6.h>
18#include <linux/netfilter/x_tables.h>
19#include <net/netfilter/nf_nat.h>
20#include <net/addrconf.h>
21#include <net/ipv6.h>
22#include <net/netfilter/ipv6/nf_nat_masquerade.h>
23
24static unsigned int
25masquerade_tg6(struct sk_buff *skb, const struct xt_action_param *par)
26{
27 return nf_nat_masquerade_ipv6(skb, par->targinfo, xt_out(par));
28}
29
30static int masquerade_tg6_checkentry(const struct xt_tgchk_param *par)
31{
32 const struct nf_nat_range2 *range = par->targinfo;
33
34 if (range->flags & NF_NAT_RANGE_MAP_IPS)
35 return -EINVAL;
36 return nf_ct_netns_get(par->net, par->family);
37}
38
39static void masquerade_tg6_destroy(const struct xt_tgdtor_param *par)
40{
41 nf_ct_netns_put(par->net, par->family);
42}
43
44static struct xt_target masquerade_tg6_reg __read_mostly = {
45 .name = "MASQUERADE",
46 .family = NFPROTO_IPV6,
47 .checkentry = masquerade_tg6_checkentry,
48 .destroy = masquerade_tg6_destroy,
49 .target = masquerade_tg6,
50 .targetsize = sizeof(struct nf_nat_range),
51 .table = "nat",
52 .hooks = 1 << NF_INET_POST_ROUTING,
53 .me = THIS_MODULE,
54};
55
56static int __init masquerade_tg6_init(void)
57{
58 int err;
59
60 err = xt_register_target(&masquerade_tg6_reg);
61 if (err)
62 return err;
63
64 err = nf_nat_masquerade_ipv6_register_notifier();
65 if (err)
66 xt_unregister_target(&masquerade_tg6_reg);
67
68 return err;
69}
70static void __exit masquerade_tg6_exit(void)
71{
72 nf_nat_masquerade_ipv6_unregister_notifier();
73 xt_unregister_target(&masquerade_tg6_reg);
74}
75
76module_init(masquerade_tg6_init);
77module_exit(masquerade_tg6_exit);
78
79MODULE_LICENSE("GPL");
80MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
81MODULE_DESCRIPTION("Xtables: automatic address SNAT");
diff --git a/net/ipv6/netfilter/nft_chain_route_ipv6.c b/net/ipv6/netfilter/nft_chain_route_ipv6.c
deleted file mode 100644
index da3f1f8cb325..000000000000
--- a/net/ipv6/netfilter/nft_chain_route_ipv6.c
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2012 Pablo Neira Ayuso <pablo@netfilter.org>
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Development of this code funded by Astaro AG (http://www.astaro.com/)
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/list.h>
15#include <linux/skbuff.h>
16#include <linux/netlink.h>
17#include <linux/netfilter.h>
18#include <linux/netfilter_ipv6.h>
19#include <linux/netfilter/nfnetlink.h>
20#include <linux/netfilter/nf_tables.h>
21#include <net/netfilter/nf_tables.h>
22#include <net/netfilter/nf_tables_ipv6.h>
23#include <net/route.h>
24
25static unsigned int nf_route_table_hook(void *priv,
26 struct sk_buff *skb,
27 const struct nf_hook_state *state)
28{
29 unsigned int ret;
30 struct nft_pktinfo pkt;
31 struct in6_addr saddr, daddr;
32 u_int8_t hop_limit;
33 u32 mark, flowlabel;
34 int err;
35
36 nft_set_pktinfo(&pkt, skb, state);
37 nft_set_pktinfo_ipv6(&pkt, skb);
38
39 /* save source/dest address, mark, hoplimit, flowlabel, priority */
40 memcpy(&saddr, &ipv6_hdr(skb)->saddr, sizeof(saddr));
41 memcpy(&daddr, &ipv6_hdr(skb)->daddr, sizeof(daddr));
42 mark = skb->mark;
43 hop_limit = ipv6_hdr(skb)->hop_limit;
44
45 /* flowlabel and prio (includes version, which shouldn't change either */
46 flowlabel = *((u32 *)ipv6_hdr(skb));
47
48 ret = nft_do_chain(&pkt, priv);
49 if (ret != NF_DROP && ret != NF_STOLEN &&
50 (memcmp(&ipv6_hdr(skb)->saddr, &saddr, sizeof(saddr)) ||
51 memcmp(&ipv6_hdr(skb)->daddr, &daddr, sizeof(daddr)) ||
52 skb->mark != mark ||
53 ipv6_hdr(skb)->hop_limit != hop_limit ||
54 flowlabel != *((u_int32_t *)ipv6_hdr(skb)))) {
55 err = ip6_route_me_harder(state->net, skb);
56 if (err < 0)
57 ret = NF_DROP_ERR(err);
58 }
59
60 return ret;
61}
62
63static const struct nft_chain_type nft_chain_route_ipv6 = {
64 .name = "route",
65 .type = NFT_CHAIN_T_ROUTE,
66 .family = NFPROTO_IPV6,
67 .owner = THIS_MODULE,
68 .hook_mask = (1 << NF_INET_LOCAL_OUT),
69 .hooks = {
70 [NF_INET_LOCAL_OUT] = nf_route_table_hook,
71 },
72};
73
74static int __init nft_chain_route_init(void)
75{
76 nft_register_chain_type(&nft_chain_route_ipv6);
77
78 return 0;
79}
80
81static void __exit nft_chain_route_exit(void)
82{
83 nft_unregister_chain_type(&nft_chain_route_ipv6);
84}
85
86module_init(nft_chain_route_init);
87module_exit(nft_chain_route_exit);
88
89MODULE_LICENSE("GPL");
90MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
91MODULE_ALIAS_NFT_CHAIN(AF_INET6, "route");
diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
index 4fe7c90962dd..868ae23dbae1 100644
--- a/net/ipv6/output_core.c
+++ b/net/ipv6/output_core.c
@@ -10,15 +10,25 @@
10#include <net/secure_seq.h> 10#include <net/secure_seq.h>
11#include <linux/netfilter.h> 11#include <linux/netfilter.h>
12 12
13static u32 __ipv6_select_ident(struct net *net, u32 hashrnd, 13static u32 __ipv6_select_ident(struct net *net,
14 const struct in6_addr *dst, 14 const struct in6_addr *dst,
15 const struct in6_addr *src) 15 const struct in6_addr *src)
16{ 16{
17 const struct {
18 struct in6_addr dst;
19 struct in6_addr src;
20 } __aligned(SIPHASH_ALIGNMENT) combined = {
21 .dst = *dst,
22 .src = *src,
23 };
17 u32 hash, id; 24 u32 hash, id;
18 25
19 hash = __ipv6_addr_jhash(dst, hashrnd); 26 /* Note the following code is not safe, but this is okay. */
20 hash = __ipv6_addr_jhash(src, hash); 27 if (unlikely(siphash_key_is_zero(&net->ipv4.ip_id_key)))
21 hash ^= net_hash_mix(net); 28 get_random_bytes(&net->ipv4.ip_id_key,
29 sizeof(net->ipv4.ip_id_key));
30
31 hash = siphash(&combined, sizeof(combined), &net->ipv4.ip_id_key);
22 32
23 /* Treat id of 0 as unset and if we get 0 back from ip_idents_reserve, 33 /* Treat id of 0 as unset and if we get 0 back from ip_idents_reserve,
24 * set the hight order instead thus minimizing possible future 34 * set the hight order instead thus minimizing possible future
@@ -41,7 +51,6 @@ static u32 __ipv6_select_ident(struct net *net, u32 hashrnd,
41 */ 51 */
42__be32 ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb) 52__be32 ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb)
43{ 53{
44 static u32 ip6_proxy_idents_hashrnd __read_mostly;
45 struct in6_addr buf[2]; 54 struct in6_addr buf[2];
46 struct in6_addr *addrs; 55 struct in6_addr *addrs;
47 u32 id; 56 u32 id;
@@ -53,11 +62,7 @@ __be32 ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb)
53 if (!addrs) 62 if (!addrs)
54 return 0; 63 return 0;
55 64
56 net_get_random_once(&ip6_proxy_idents_hashrnd, 65 id = __ipv6_select_ident(net, &addrs[1], &addrs[0]);
57 sizeof(ip6_proxy_idents_hashrnd));
58
59 id = __ipv6_select_ident(net, ip6_proxy_idents_hashrnd,
60 &addrs[1], &addrs[0]);
61 return htonl(id); 66 return htonl(id);
62} 67}
63EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident); 68EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident);
@@ -66,12 +71,9 @@ __be32 ipv6_select_ident(struct net *net,
66 const struct in6_addr *daddr, 71 const struct in6_addr *daddr,
67 const struct in6_addr *saddr) 72 const struct in6_addr *saddr)
68{ 73{
69 static u32 ip6_idents_hashrnd __read_mostly;
70 u32 id; 74 u32 id;
71 75
72 net_get_random_once(&ip6_idents_hashrnd, sizeof(ip6_idents_hashrnd)); 76 id = __ipv6_select_ident(net, daddr, saddr);
73
74 id = __ipv6_select_ident(net, ip6_idents_hashrnd, daddr, saddr);
75 return htonl(id); 77 return htonl(id);
76} 78}
77EXPORT_SYMBOL(ipv6_select_ident); 79EXPORT_SYMBOL(ipv6_select_ident);
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 5a426226c762..84dbe21b71e5 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -1356,6 +1356,7 @@ const struct proto_ops inet6_sockraw_ops = {
1356 .getname = inet6_getname, 1356 .getname = inet6_getname,
1357 .poll = datagram_poll, /* ok */ 1357 .poll = datagram_poll, /* ok */
1358 .ioctl = inet6_ioctl, /* must change */ 1358 .ioctl = inet6_ioctl, /* must change */
1359 .gettstamp = sock_gettstamp,
1359 .listen = sock_no_listen, /* ok */ 1360 .listen = sock_no_listen, /* ok */
1360 .shutdown = inet_shutdown, /* ok */ 1361 .shutdown = inet_shutdown, /* ok */
1361 .setsockopt = sock_common_setsockopt, /* ok */ 1362 .setsockopt = sock_common_setsockopt, /* ok */
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 0302e0eb07af..23a20d62daac 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -59,7 +59,7 @@
59#include <net/xfrm.h> 59#include <net/xfrm.h>
60#include <net/netevent.h> 60#include <net/netevent.h>
61#include <net/netlink.h> 61#include <net/netlink.h>
62#include <net/nexthop.h> 62#include <net/rtnh.h>
63#include <net/lwtunnel.h> 63#include <net/lwtunnel.h>
64#include <net/ip_tunnels.h> 64#include <net/ip_tunnels.h>
65#include <net/l3mdev.h> 65#include <net/l3mdev.h>
@@ -102,14 +102,15 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
102 struct sk_buff *skb, u32 mtu); 102 struct sk_buff *skb, u32 mtu);
103static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, 103static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk,
104 struct sk_buff *skb); 104 struct sk_buff *skb);
105static int rt6_score_route(struct fib6_info *rt, int oif, int strict); 105static int rt6_score_route(const struct fib6_nh *nh, u32 fib6_flags, int oif,
106 int strict);
106static size_t rt6_nlmsg_size(struct fib6_info *rt); 107static size_t rt6_nlmsg_size(struct fib6_info *rt);
107static int rt6_fill_node(struct net *net, struct sk_buff *skb, 108static int rt6_fill_node(struct net *net, struct sk_buff *skb,
108 struct fib6_info *rt, struct dst_entry *dst, 109 struct fib6_info *rt, struct dst_entry *dst,
109 struct in6_addr *dest, struct in6_addr *src, 110 struct in6_addr *dest, struct in6_addr *src,
110 int iif, int type, u32 portid, u32 seq, 111 int iif, int type, u32 portid, u32 seq,
111 unsigned int flags); 112 unsigned int flags);
112static struct rt6_info *rt6_find_cached_rt(struct fib6_info *rt, 113static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
113 struct in6_addr *daddr, 114 struct in6_addr *daddr,
114 struct in6_addr *saddr); 115 struct in6_addr *saddr);
115 116
@@ -295,7 +296,7 @@ static const struct fib6_info fib6_null_entry_template = {
295 .fib6_flags = (RTF_REJECT | RTF_NONEXTHOP), 296 .fib6_flags = (RTF_REJECT | RTF_NONEXTHOP),
296 .fib6_protocol = RTPROT_KERNEL, 297 .fib6_protocol = RTPROT_KERNEL,
297 .fib6_metric = ~(u32)0, 298 .fib6_metric = ~(u32)0,
298 .fib6_ref = ATOMIC_INIT(1), 299 .fib6_ref = REFCOUNT_INIT(1),
299 .fib6_type = RTN_UNREACHABLE, 300 .fib6_type = RTN_UNREACHABLE,
300 .fib6_metrics = (struct dst_metrics *)&dst_default_metrics, 301 .fib6_metrics = (struct dst_metrics *)&dst_default_metrics,
301}; 302};
@@ -379,11 +380,8 @@ static void ip6_dst_destroy(struct dst_entry *dst)
379 in6_dev_put(idev); 380 in6_dev_put(idev);
380 } 381 }
381 382
382 rcu_read_lock(); 383 from = xchg((__force struct fib6_info **)&rt->from, NULL);
383 from = rcu_dereference(rt->from);
384 rcu_assign_pointer(rt->from, NULL);
385 fib6_info_release(from); 384 fib6_info_release(from);
386 rcu_read_unlock();
387} 385}
388 386
389static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev, 387static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
@@ -427,13 +425,15 @@ static bool rt6_check_expired(const struct rt6_info *rt)
427 return false; 425 return false;
428} 426}
429 427
430struct fib6_info *fib6_multipath_select(const struct net *net, 428void fib6_select_path(const struct net *net, struct fib6_result *res,
431 struct fib6_info *match, 429 struct flowi6 *fl6, int oif, bool have_oif_match,
432 struct flowi6 *fl6, int oif, 430 const struct sk_buff *skb, int strict)
433 const struct sk_buff *skb,
434 int strict)
435{ 431{
436 struct fib6_info *sibling, *next_sibling; 432 struct fib6_info *sibling, *next_sibling;
433 struct fib6_info *match = res->f6i;
434
435 if (!match->fib6_nsiblings || have_oif_match)
436 goto out;
437 437
438 /* We might have already computed the hash for ICMPv6 errors. In such 438 /* We might have already computed the hash for ICMPv6 errors. In such
439 * case it will always be non-zero. Otherwise now is the time to do it. 439 * case it will always be non-zero. Otherwise now is the time to do it.
@@ -441,61 +441,89 @@ struct fib6_info *fib6_multipath_select(const struct net *net,
441 if (!fl6->mp_hash) 441 if (!fl6->mp_hash)
442 fl6->mp_hash = rt6_multipath_hash(net, fl6, skb, NULL); 442 fl6->mp_hash = rt6_multipath_hash(net, fl6, skb, NULL);
443 443
444 if (fl6->mp_hash <= atomic_read(&match->fib6_nh.nh_upper_bound)) 444 if (fl6->mp_hash <= atomic_read(&match->fib6_nh.fib_nh_upper_bound))
445 return match; 445 goto out;
446 446
447 list_for_each_entry_safe(sibling, next_sibling, &match->fib6_siblings, 447 list_for_each_entry_safe(sibling, next_sibling, &match->fib6_siblings,
448 fib6_siblings) { 448 fib6_siblings) {
449 const struct fib6_nh *nh = &sibling->fib6_nh;
449 int nh_upper_bound; 450 int nh_upper_bound;
450 451
451 nh_upper_bound = atomic_read(&sibling->fib6_nh.nh_upper_bound); 452 nh_upper_bound = atomic_read(&nh->fib_nh_upper_bound);
452 if (fl6->mp_hash > nh_upper_bound) 453 if (fl6->mp_hash > nh_upper_bound)
453 continue; 454 continue;
454 if (rt6_score_route(sibling, oif, strict) < 0) 455 if (rt6_score_route(nh, sibling->fib6_flags, oif, strict) < 0)
455 break; 456 break;
456 match = sibling; 457 match = sibling;
457 break; 458 break;
458 } 459 }
459 460
460 return match; 461out:
462 res->f6i = match;
463 res->nh = &match->fib6_nh;
461} 464}
462 465
463/* 466/*
464 * Route lookup. rcu_read_lock() should be held. 467 * Route lookup. rcu_read_lock() should be held.
465 */ 468 */
466 469
467static inline struct fib6_info *rt6_device_match(struct net *net, 470static bool __rt6_device_match(struct net *net, const struct fib6_nh *nh,
468 struct fib6_info *rt, 471 const struct in6_addr *saddr, int oif, int flags)
469 const struct in6_addr *saddr,
470 int oif,
471 int flags)
472{ 472{
473 struct fib6_info *sprt; 473 const struct net_device *dev;
474 474
475 if (!oif && ipv6_addr_any(saddr) && 475 if (nh->fib_nh_flags & RTNH_F_DEAD)
476 !(rt->fib6_nh.nh_flags & RTNH_F_DEAD)) 476 return false;
477 return rt;
478 477
479 for (sprt = rt; sprt; sprt = rcu_dereference(sprt->fib6_next)) { 478 dev = nh->fib_nh_dev;
480 const struct net_device *dev = sprt->fib6_nh.nh_dev; 479 if (oif) {
480 if (dev->ifindex == oif)
481 return true;
482 } else {
483 if (ipv6_chk_addr(net, saddr, dev,
484 flags & RT6_LOOKUP_F_IFACE))
485 return true;
486 }
481 487
482 if (sprt->fib6_nh.nh_flags & RTNH_F_DEAD) 488 return false;
483 continue; 489}
484 490
485 if (oif) { 491static void rt6_device_match(struct net *net, struct fib6_result *res,
486 if (dev->ifindex == oif) 492 const struct in6_addr *saddr, int oif, int flags)
487 return sprt; 493{
488 } else { 494 struct fib6_info *f6i = res->f6i;
489 if (ipv6_chk_addr(net, saddr, dev, 495 struct fib6_info *spf6i;
490 flags & RT6_LOOKUP_F_IFACE)) 496 struct fib6_nh *nh;
491 return sprt; 497
498 if (!oif && ipv6_addr_any(saddr)) {
499 nh = &f6i->fib6_nh;
500 if (!(nh->fib_nh_flags & RTNH_F_DEAD))
501 goto out;
502 }
503
504 for (spf6i = f6i; spf6i; spf6i = rcu_dereference(spf6i->fib6_next)) {
505 nh = &spf6i->fib6_nh;
506 if (__rt6_device_match(net, nh, saddr, oif, flags)) {
507 res->f6i = spf6i;
508 goto out;
492 } 509 }
493 } 510 }
494 511
495 if (oif && flags & RT6_LOOKUP_F_IFACE) 512 if (oif && flags & RT6_LOOKUP_F_IFACE) {
496 return net->ipv6.fib6_null_entry; 513 res->f6i = net->ipv6.fib6_null_entry;
514 nh = &res->f6i->fib6_nh;
515 goto out;
516 }
497 517
498 return rt->fib6_nh.nh_flags & RTNH_F_DEAD ? net->ipv6.fib6_null_entry : rt; 518 nh = &f6i->fib6_nh;
519 if (nh->fib_nh_flags & RTNH_F_DEAD) {
520 res->f6i = net->ipv6.fib6_null_entry;
521 nh = &res->f6i->fib6_nh;
522 }
523out:
524 res->nh = nh;
525 res->fib6_type = res->f6i->fib6_type;
526 res->fib6_flags = res->f6i->fib6_flags;
499} 527}
500 528
501#ifdef CONFIG_IPV6_ROUTER_PREF 529#ifdef CONFIG_IPV6_ROUTER_PREF
@@ -517,7 +545,7 @@ static void rt6_probe_deferred(struct work_struct *w)
517 kfree(work); 545 kfree(work);
518} 546}
519 547
520static void rt6_probe(struct fib6_info *rt) 548static void rt6_probe(struct fib6_nh *fib6_nh)
521{ 549{
522 struct __rt6_probe_work *work = NULL; 550 struct __rt6_probe_work *work = NULL;
523 const struct in6_addr *nh_gw; 551 const struct in6_addr *nh_gw;
@@ -533,11 +561,11 @@ static void rt6_probe(struct fib6_info *rt)
533 * Router Reachability Probe MUST be rate-limited 561 * Router Reachability Probe MUST be rate-limited
534 * to no more than one per minute. 562 * to no more than one per minute.
535 */ 563 */
536 if (!rt || !(rt->fib6_flags & RTF_GATEWAY)) 564 if (fib6_nh->fib_nh_gw_family)
537 return; 565 return;
538 566
539 nh_gw = &rt->fib6_nh.nh_gw; 567 nh_gw = &fib6_nh->fib_nh_gw6;
540 dev = rt->fib6_nh.nh_dev; 568 dev = fib6_nh->fib_nh_dev;
541 rcu_read_lock_bh(); 569 rcu_read_lock_bh();
542 idev = __in6_dev_get(dev); 570 idev = __in6_dev_get(dev);
543 neigh = __ipv6_neigh_lookup_noref(dev, nh_gw); 571 neigh = __ipv6_neigh_lookup_noref(dev, nh_gw);
@@ -554,13 +582,13 @@ static void rt6_probe(struct fib6_info *rt)
554 __neigh_set_probe_once(neigh); 582 __neigh_set_probe_once(neigh);
555 } 583 }
556 write_unlock(&neigh->lock); 584 write_unlock(&neigh->lock);
557 } else if (time_after(jiffies, rt->last_probe + 585 } else if (time_after(jiffies, fib6_nh->last_probe +
558 idev->cnf.rtr_probe_interval)) { 586 idev->cnf.rtr_probe_interval)) {
559 work = kmalloc(sizeof(*work), GFP_ATOMIC); 587 work = kmalloc(sizeof(*work), GFP_ATOMIC);
560 } 588 }
561 589
562 if (work) { 590 if (work) {
563 rt->last_probe = jiffies; 591 fib6_nh->last_probe = jiffies;
564 INIT_WORK(&work->work, rt6_probe_deferred); 592 INIT_WORK(&work->work, rt6_probe_deferred);
565 work->target = *nh_gw; 593 work->target = *nh_gw;
566 dev_hold(dev); 594 dev_hold(dev);
@@ -572,7 +600,7 @@ out:
572 rcu_read_unlock_bh(); 600 rcu_read_unlock_bh();
573} 601}
574#else 602#else
575static inline void rt6_probe(struct fib6_info *rt) 603static inline void rt6_probe(struct fib6_nh *fib6_nh)
576{ 604{
577} 605}
578#endif 606#endif
@@ -580,27 +608,14 @@ static inline void rt6_probe(struct fib6_info *rt)
580/* 608/*
581 * Default Router Selection (RFC 2461 6.3.6) 609 * Default Router Selection (RFC 2461 6.3.6)
582 */ 610 */
583static inline int rt6_check_dev(struct fib6_info *rt, int oif) 611static enum rt6_nud_state rt6_check_neigh(const struct fib6_nh *fib6_nh)
584{
585 const struct net_device *dev = rt->fib6_nh.nh_dev;
586
587 if (!oif || dev->ifindex == oif)
588 return 2;
589 return 0;
590}
591
592static inline enum rt6_nud_state rt6_check_neigh(struct fib6_info *rt)
593{ 612{
594 enum rt6_nud_state ret = RT6_NUD_FAIL_HARD; 613 enum rt6_nud_state ret = RT6_NUD_FAIL_HARD;
595 struct neighbour *neigh; 614 struct neighbour *neigh;
596 615
597 if (rt->fib6_flags & RTF_NONEXTHOP ||
598 !(rt->fib6_flags & RTF_GATEWAY))
599 return RT6_NUD_SUCCEED;
600
601 rcu_read_lock_bh(); 616 rcu_read_lock_bh();
602 neigh = __ipv6_neigh_lookup_noref(rt->fib6_nh.nh_dev, 617 neigh = __ipv6_neigh_lookup_noref(fib6_nh->fib_nh_dev,
603 &rt->fib6_nh.nh_gw); 618 &fib6_nh->fib_nh_gw6);
604 if (neigh) { 619 if (neigh) {
605 read_lock(&neigh->lock); 620 read_lock(&neigh->lock);
606 if (neigh->nud_state & NUD_VALID) 621 if (neigh->nud_state & NUD_VALID)
@@ -621,58 +636,44 @@ static inline enum rt6_nud_state rt6_check_neigh(struct fib6_info *rt)
621 return ret; 636 return ret;
622} 637}
623 638
624static int rt6_score_route(struct fib6_info *rt, int oif, int strict) 639static int rt6_score_route(const struct fib6_nh *nh, u32 fib6_flags, int oif,
640 int strict)
625{ 641{
626 int m; 642 int m = 0;
643
644 if (!oif || nh->fib_nh_dev->ifindex == oif)
645 m = 2;
627 646
628 m = rt6_check_dev(rt, oif);
629 if (!m && (strict & RT6_LOOKUP_F_IFACE)) 647 if (!m && (strict & RT6_LOOKUP_F_IFACE))
630 return RT6_NUD_FAIL_HARD; 648 return RT6_NUD_FAIL_HARD;
631#ifdef CONFIG_IPV6_ROUTER_PREF 649#ifdef CONFIG_IPV6_ROUTER_PREF
632 m |= IPV6_DECODE_PREF(IPV6_EXTRACT_PREF(rt->fib6_flags)) << 2; 650 m |= IPV6_DECODE_PREF(IPV6_EXTRACT_PREF(fib6_flags)) << 2;
633#endif 651#endif
634 if (strict & RT6_LOOKUP_F_REACHABLE) { 652 if ((strict & RT6_LOOKUP_F_REACHABLE) &&
635 int n = rt6_check_neigh(rt); 653 !(fib6_flags & RTF_NONEXTHOP) && nh->fib_nh_gw_family) {
654 int n = rt6_check_neigh(nh);
636 if (n < 0) 655 if (n < 0)
637 return n; 656 return n;
638 } 657 }
639 return m; 658 return m;
640} 659}
641 660
642/* called with rc_read_lock held */ 661static bool find_match(struct fib6_nh *nh, u32 fib6_flags,
643static inline bool fib6_ignore_linkdown(const struct fib6_info *f6i) 662 int oif, int strict, int *mpri, bool *do_rr)
644{ 663{
645 const struct net_device *dev = fib6_info_nh_dev(f6i); 664 bool match_do_rr = false;
646 bool rc = false; 665 bool rc = false;
647
648 if (dev) {
649 const struct inet6_dev *idev = __in6_dev_get(dev);
650
651 rc = !!idev->cnf.ignore_routes_with_linkdown;
652 }
653
654 return rc;
655}
656
657static struct fib6_info *find_match(struct fib6_info *rt, int oif, int strict,
658 int *mpri, struct fib6_info *match,
659 bool *do_rr)
660{
661 int m; 666 int m;
662 bool match_do_rr = false;
663 667
664 if (rt->fib6_nh.nh_flags & RTNH_F_DEAD) 668 if (nh->fib_nh_flags & RTNH_F_DEAD)
665 goto out; 669 goto out;
666 670
667 if (fib6_ignore_linkdown(rt) && 671 if (ip6_ignore_linkdown(nh->fib_nh_dev) &&
668 rt->fib6_nh.nh_flags & RTNH_F_LINKDOWN && 672 nh->fib_nh_flags & RTNH_F_LINKDOWN &&
669 !(strict & RT6_LOOKUP_F_IGNORE_LINKSTATE)) 673 !(strict & RT6_LOOKUP_F_IGNORE_LINKSTATE))
670 goto out; 674 goto out;
671 675
672 if (fib6_check_expired(rt)) 676 m = rt6_score_route(nh, fib6_flags, oif, strict);
673 goto out;
674
675 m = rt6_score_route(rt, oif, strict);
676 if (m == RT6_NUD_FAIL_DO_RR) { 677 if (m == RT6_NUD_FAIL_DO_RR) {
677 match_do_rr = true; 678 match_do_rr = true;
678 m = 0; /* lowest valid score */ 679 m = 0; /* lowest valid score */
@@ -681,67 +682,82 @@ static struct fib6_info *find_match(struct fib6_info *rt, int oif, int strict,
681 } 682 }
682 683
683 if (strict & RT6_LOOKUP_F_REACHABLE) 684 if (strict & RT6_LOOKUP_F_REACHABLE)
684 rt6_probe(rt); 685 rt6_probe(nh);
685 686
686 /* note that m can be RT6_NUD_FAIL_PROBE at this point */ 687 /* note that m can be RT6_NUD_FAIL_PROBE at this point */
687 if (m > *mpri) { 688 if (m > *mpri) {
688 *do_rr = match_do_rr; 689 *do_rr = match_do_rr;
689 *mpri = m; 690 *mpri = m;
690 match = rt; 691 rc = true;
691 } 692 }
692out: 693out:
693 return match; 694 return rc;
694} 695}
695 696
696static struct fib6_info *find_rr_leaf(struct fib6_node *fn, 697static void __find_rr_leaf(struct fib6_info *f6i_start,
697 struct fib6_info *leaf, 698 struct fib6_info *nomatch, u32 metric,
698 struct fib6_info *rr_head, 699 struct fib6_result *res, struct fib6_info **cont,
699 u32 metric, int oif, int strict, 700 int oif, int strict, bool *do_rr, int *mpri)
700 bool *do_rr)
701{ 701{
702 struct fib6_info *rt, *match, *cont; 702 struct fib6_info *f6i;
703 int mpri = -1;
704 703
705 match = NULL; 704 for (f6i = f6i_start;
706 cont = NULL; 705 f6i && f6i != nomatch;
707 for (rt = rr_head; rt; rt = rcu_dereference(rt->fib6_next)) { 706 f6i = rcu_dereference(f6i->fib6_next)) {
708 if (rt->fib6_metric != metric) { 707 struct fib6_nh *nh;
709 cont = rt; 708
710 break; 709 if (cont && f6i->fib6_metric != metric) {
710 *cont = f6i;
711 return;
711 } 712 }
712 713
713 match = find_match(rt, oif, strict, &mpri, match, do_rr); 714 if (fib6_check_expired(f6i))
714 } 715 continue;
715 716
716 for (rt = leaf; rt && rt != rr_head; 717 nh = &f6i->fib6_nh;
717 rt = rcu_dereference(rt->fib6_next)) { 718 if (find_match(nh, f6i->fib6_flags, oif, strict, mpri, do_rr)) {
718 if (rt->fib6_metric != metric) { 719 res->f6i = f6i;
719 cont = rt; 720 res->nh = nh;
720 break; 721 res->fib6_flags = f6i->fib6_flags;
722 res->fib6_type = f6i->fib6_type;
721 } 723 }
722
723 match = find_match(rt, oif, strict, &mpri, match, do_rr);
724 } 724 }
725}
726
727static void find_rr_leaf(struct fib6_node *fn, struct fib6_info *leaf,
728 struct fib6_info *rr_head, int oif, int strict,
729 bool *do_rr, struct fib6_result *res)
730{
731 u32 metric = rr_head->fib6_metric;
732 struct fib6_info *cont = NULL;
733 int mpri = -1;
725 734
726 if (match || !cont) 735 __find_rr_leaf(rr_head, NULL, metric, res, &cont,
727 return match; 736 oif, strict, do_rr, &mpri);
728 737
729 for (rt = cont; rt; rt = rcu_dereference(rt->fib6_next)) 738 __find_rr_leaf(leaf, rr_head, metric, res, &cont,
730 match = find_match(rt, oif, strict, &mpri, match, do_rr); 739 oif, strict, do_rr, &mpri);
731 740
732 return match; 741 if (res->f6i || !cont)
742 return;
743
744 __find_rr_leaf(cont, NULL, metric, res, NULL,
745 oif, strict, do_rr, &mpri);
733} 746}
734 747
735static struct fib6_info *rt6_select(struct net *net, struct fib6_node *fn, 748static void rt6_select(struct net *net, struct fib6_node *fn, int oif,
736 int oif, int strict) 749 struct fib6_result *res, int strict)
737{ 750{
738 struct fib6_info *leaf = rcu_dereference(fn->leaf); 751 struct fib6_info *leaf = rcu_dereference(fn->leaf);
739 struct fib6_info *match, *rt0; 752 struct fib6_info *rt0;
740 bool do_rr = false; 753 bool do_rr = false;
741 int key_plen; 754 int key_plen;
742 755
756 /* make sure this function or its helpers sets f6i */
757 res->f6i = NULL;
758
743 if (!leaf || leaf == net->ipv6.fib6_null_entry) 759 if (!leaf || leaf == net->ipv6.fib6_null_entry)
744 return net->ipv6.fib6_null_entry; 760 goto out;
745 761
746 rt0 = rcu_dereference(fn->rr_ptr); 762 rt0 = rcu_dereference(fn->rr_ptr);
747 if (!rt0) 763 if (!rt0)
@@ -758,11 +774,9 @@ static struct fib6_info *rt6_select(struct net *net, struct fib6_node *fn,
758 key_plen = rt0->fib6_src.plen; 774 key_plen = rt0->fib6_src.plen;
759#endif 775#endif
760 if (fn->fn_bit != key_plen) 776 if (fn->fn_bit != key_plen)
761 return net->ipv6.fib6_null_entry; 777 goto out;
762
763 match = find_rr_leaf(fn, leaf, rt0, rt0->fib6_metric, oif, strict,
764 &do_rr);
765 778
779 find_rr_leaf(fn, leaf, rt0, oif, strict, &do_rr, res);
766 if (do_rr) { 780 if (do_rr) {
767 struct fib6_info *next = rcu_dereference(rt0->fib6_next); 781 struct fib6_info *next = rcu_dereference(rt0->fib6_next);
768 782
@@ -779,12 +793,19 @@ static struct fib6_info *rt6_select(struct net *net, struct fib6_node *fn,
779 } 793 }
780 } 794 }
781 795
782 return match ? match : net->ipv6.fib6_null_entry; 796out:
797 if (!res->f6i) {
798 res->f6i = net->ipv6.fib6_null_entry;
799 res->nh = &res->f6i->fib6_nh;
800 res->fib6_flags = res->f6i->fib6_flags;
801 res->fib6_type = res->f6i->fib6_type;
802 }
783} 803}
784 804
785static bool rt6_is_gw_or_nonexthop(const struct fib6_info *rt) 805static bool rt6_is_gw_or_nonexthop(const struct fib6_result *res)
786{ 806{
787 return (rt->fib6_flags & (RTF_NONEXTHOP | RTF_GATEWAY)); 807 return (res->f6i->fib6_flags & RTF_NONEXTHOP) ||
808 res->nh->fib_nh_gw_family;
788} 809}
789 810
790#ifdef CONFIG_IPV6_ROUTE_INFO 811#ifdef CONFIG_IPV6_ROUTE_INFO
@@ -868,17 +889,17 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
868 */ 889 */
869 890
870/* called with rcu_lock held */ 891/* called with rcu_lock held */
871static struct net_device *ip6_rt_get_dev_rcu(struct fib6_info *rt) 892static struct net_device *ip6_rt_get_dev_rcu(const struct fib6_result *res)
872{ 893{
873 struct net_device *dev = rt->fib6_nh.nh_dev; 894 struct net_device *dev = res->nh->fib_nh_dev;
874 895
875 if (rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) { 896 if (res->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) {
876 /* for copies of local routes, dst->dev needs to be the 897 /* for copies of local routes, dst->dev needs to be the
877 * device if it is a master device, the master device if 898 * device if it is a master device, the master device if
878 * device is enslaved, and the loopback as the default 899 * device is enslaved, and the loopback as the default
879 */ 900 */
880 if (netif_is_l3_slave(dev) && 901 if (netif_is_l3_slave(dev) &&
881 !rt6_need_strict(&rt->fib6_dst.addr)) 902 !rt6_need_strict(&res->f6i->fib6_dst.addr))
882 dev = l3mdev_master_dev_rcu(dev); 903 dev = l3mdev_master_dev_rcu(dev);
883 else if (!netif_is_l3_master(dev)) 904 else if (!netif_is_l3_master(dev))
884 dev = dev_net(dev)->loopback_dev; 905 dev = dev_net(dev)->loopback_dev;
@@ -924,11 +945,11 @@ static unsigned short fib6_info_dst_flags(struct fib6_info *rt)
924 return flags; 945 return flags;
925} 946}
926 947
927static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort) 948static void ip6_rt_init_dst_reject(struct rt6_info *rt, u8 fib6_type)
928{ 949{
929 rt->dst.error = ip6_rt_type_to_error(ort->fib6_type); 950 rt->dst.error = ip6_rt_type_to_error(fib6_type);
930 951
931 switch (ort->fib6_type) { 952 switch (fib6_type) {
932 case RTN_BLACKHOLE: 953 case RTN_BLACKHOLE:
933 rt->dst.output = dst_discard_out; 954 rt->dst.output = dst_discard_out;
934 rt->dst.input = dst_discard; 955 rt->dst.input = dst_discard;
@@ -946,26 +967,28 @@ static void ip6_rt_init_dst_reject(struct rt6_info *rt, struct fib6_info *ort)
946 } 967 }
947} 968}
948 969
949static void ip6_rt_init_dst(struct rt6_info *rt, struct fib6_info *ort) 970static void ip6_rt_init_dst(struct rt6_info *rt, const struct fib6_result *res)
950{ 971{
951 if (ort->fib6_flags & RTF_REJECT) { 972 struct fib6_info *f6i = res->f6i;
952 ip6_rt_init_dst_reject(rt, ort); 973
974 if (res->fib6_flags & RTF_REJECT) {
975 ip6_rt_init_dst_reject(rt, res->fib6_type);
953 return; 976 return;
954 } 977 }
955 978
956 rt->dst.error = 0; 979 rt->dst.error = 0;
957 rt->dst.output = ip6_output; 980 rt->dst.output = ip6_output;
958 981
959 if (ort->fib6_type == RTN_LOCAL || ort->fib6_type == RTN_ANYCAST) { 982 if (res->fib6_type == RTN_LOCAL || res->fib6_type == RTN_ANYCAST) {
960 rt->dst.input = ip6_input; 983 rt->dst.input = ip6_input;
961 } else if (ipv6_addr_type(&ort->fib6_dst.addr) & IPV6_ADDR_MULTICAST) { 984 } else if (ipv6_addr_type(&f6i->fib6_dst.addr) & IPV6_ADDR_MULTICAST) {
962 rt->dst.input = ip6_mc_input; 985 rt->dst.input = ip6_mc_input;
963 } else { 986 } else {
964 rt->dst.input = ip6_forward; 987 rt->dst.input = ip6_forward;
965 } 988 }
966 989
967 if (ort->fib6_nh.nh_lwtstate) { 990 if (res->nh->fib_nh_lws) {
968 rt->dst.lwtstate = lwtstate_get(ort->fib6_nh.nh_lwtstate); 991 rt->dst.lwtstate = lwtstate_get(res->nh->fib_nh_lws);
969 lwtunnel_set_redirect(&rt->dst); 992 lwtunnel_set_redirect(&rt->dst);
970 } 993 }
971 994
@@ -980,20 +1003,25 @@ static void rt6_set_from(struct rt6_info *rt, struct fib6_info *from)
980 ip_dst_init_metrics(&rt->dst, from->fib6_metrics); 1003 ip_dst_init_metrics(&rt->dst, from->fib6_metrics);
981} 1004}
982 1005
983/* Caller must already hold reference to @ort */ 1006/* Caller must already hold reference to f6i in result */
984static void ip6_rt_copy_init(struct rt6_info *rt, struct fib6_info *ort) 1007static void ip6_rt_copy_init(struct rt6_info *rt, const struct fib6_result *res)
985{ 1008{
986 struct net_device *dev = fib6_info_nh_dev(ort); 1009 const struct fib6_nh *nh = res->nh;
1010 const struct net_device *dev = nh->fib_nh_dev;
1011 struct fib6_info *f6i = res->f6i;
987 1012
988 ip6_rt_init_dst(rt, ort); 1013 ip6_rt_init_dst(rt, res);
989 1014
990 rt->rt6i_dst = ort->fib6_dst; 1015 rt->rt6i_dst = f6i->fib6_dst;
991 rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; 1016 rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
992 rt->rt6i_gateway = ort->fib6_nh.nh_gw; 1017 rt->rt6i_flags = res->fib6_flags;
993 rt->rt6i_flags = ort->fib6_flags; 1018 if (nh->fib_nh_gw_family) {
994 rt6_set_from(rt, ort); 1019 rt->rt6i_gateway = nh->fib_nh_gw6;
1020 rt->rt6i_flags |= RTF_GATEWAY;
1021 }
1022 rt6_set_from(rt, f6i);
995#ifdef CONFIG_IPV6_SUBTREES 1023#ifdef CONFIG_IPV6_SUBTREES
996 rt->rt6i_src = ort->fib6_src; 1024 rt->rt6i_src = f6i->fib6_src;
997#endif 1025#endif
998} 1026}
999 1027
@@ -1015,14 +1043,13 @@ static struct fib6_node* fib6_backtrack(struct fib6_node *fn,
1015 } 1043 }
1016} 1044}
1017 1045
1018static bool ip6_hold_safe(struct net *net, struct rt6_info **prt, 1046static bool ip6_hold_safe(struct net *net, struct rt6_info **prt)
1019 bool null_fallback)
1020{ 1047{
1021 struct rt6_info *rt = *prt; 1048 struct rt6_info *rt = *prt;
1022 1049
1023 if (dst_hold_safe(&rt->dst)) 1050 if (dst_hold_safe(&rt->dst))
1024 return true; 1051 return true;
1025 if (null_fallback) { 1052 if (net) {
1026 rt = net->ipv6.ip6_null_entry; 1053 rt = net->ipv6.ip6_null_entry;
1027 dst_hold(&rt->dst); 1054 dst_hold(&rt->dst);
1028 } else { 1055 } else {
@@ -1033,22 +1060,24 @@ static bool ip6_hold_safe(struct net *net, struct rt6_info **prt,
1033} 1060}
1034 1061
1035/* called with rcu_lock held */ 1062/* called with rcu_lock held */
1036static struct rt6_info *ip6_create_rt_rcu(struct fib6_info *rt) 1063static struct rt6_info *ip6_create_rt_rcu(const struct fib6_result *res)
1037{ 1064{
1038 unsigned short flags = fib6_info_dst_flags(rt); 1065 struct net_device *dev = res->nh->fib_nh_dev;
1039 struct net_device *dev = rt->fib6_nh.nh_dev; 1066 struct fib6_info *f6i = res->f6i;
1067 unsigned short flags;
1040 struct rt6_info *nrt; 1068 struct rt6_info *nrt;
1041 1069
1042 if (!fib6_info_hold_safe(rt)) 1070 if (!fib6_info_hold_safe(f6i))
1043 goto fallback; 1071 goto fallback;
1044 1072
1073 flags = fib6_info_dst_flags(f6i);
1045 nrt = ip6_dst_alloc(dev_net(dev), dev, flags); 1074 nrt = ip6_dst_alloc(dev_net(dev), dev, flags);
1046 if (!nrt) { 1075 if (!nrt) {
1047 fib6_info_release(rt); 1076 fib6_info_release(f6i);
1048 goto fallback; 1077 goto fallback;
1049 } 1078 }
1050 1079
1051 ip6_rt_copy_init(nrt, rt); 1080 ip6_rt_copy_init(nrt, res);
1052 return nrt; 1081 return nrt;
1053 1082
1054fallback: 1083fallback:
@@ -1063,7 +1092,7 @@ static struct rt6_info *ip6_pol_route_lookup(struct net *net,
1063 const struct sk_buff *skb, 1092 const struct sk_buff *skb,
1064 int flags) 1093 int flags)
1065{ 1094{
1066 struct fib6_info *f6i; 1095 struct fib6_result res = {};
1067 struct fib6_node *fn; 1096 struct fib6_node *fn;
1068 struct rt6_info *rt; 1097 struct rt6_info *rt;
1069 1098
@@ -1073,37 +1102,38 @@ static struct rt6_info *ip6_pol_route_lookup(struct net *net,
1073 rcu_read_lock(); 1102 rcu_read_lock();
1074 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); 1103 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
1075restart: 1104restart:
1076 f6i = rcu_dereference(fn->leaf); 1105 res.f6i = rcu_dereference(fn->leaf);
1077 if (!f6i) { 1106 if (!res.f6i)
1078 f6i = net->ipv6.fib6_null_entry; 1107 res.f6i = net->ipv6.fib6_null_entry;
1079 } else { 1108 else
1080 f6i = rt6_device_match(net, f6i, &fl6->saddr, 1109 rt6_device_match(net, &res, &fl6->saddr, fl6->flowi6_oif,
1081 fl6->flowi6_oif, flags); 1110 flags);
1082 if (f6i->fib6_nsiblings && fl6->flowi6_oif == 0) 1111
1083 f6i = fib6_multipath_select(net, f6i, fl6, 1112 if (res.f6i == net->ipv6.fib6_null_entry) {
1084 fl6->flowi6_oif, skb,
1085 flags);
1086 }
1087 if (f6i == net->ipv6.fib6_null_entry) {
1088 fn = fib6_backtrack(fn, &fl6->saddr); 1113 fn = fib6_backtrack(fn, &fl6->saddr);
1089 if (fn) 1114 if (fn)
1090 goto restart; 1115 goto restart;
1116
1117 rt = net->ipv6.ip6_null_entry;
1118 dst_hold(&rt->dst);
1119 goto out;
1091 } 1120 }
1092 1121
1093 trace_fib6_table_lookup(net, f6i, table, fl6); 1122 fib6_select_path(net, &res, fl6, fl6->flowi6_oif,
1123 fl6->flowi6_oif != 0, skb, flags);
1094 1124
1095 /* Search through exception table */ 1125 /* Search through exception table */
1096 rt = rt6_find_cached_rt(f6i, &fl6->daddr, &fl6->saddr); 1126 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr);
1097 if (rt) { 1127 if (rt) {
1098 if (ip6_hold_safe(net, &rt, true)) 1128 if (ip6_hold_safe(net, &rt))
1099 dst_use_noref(&rt->dst, jiffies); 1129 dst_use_noref(&rt->dst, jiffies);
1100 } else if (f6i == net->ipv6.fib6_null_entry) {
1101 rt = net->ipv6.ip6_null_entry;
1102 dst_hold(&rt->dst);
1103 } else { 1130 } else {
1104 rt = ip6_create_rt_rcu(f6i); 1131 rt = ip6_create_rt_rcu(&res);
1105 } 1132 }
1106 1133
1134out:
1135 trace_fib6_table_lookup(net, &res, table, fl6);
1136
1107 rcu_read_unlock(); 1137 rcu_read_unlock();
1108 1138
1109 return rt; 1139 return rt;
@@ -1169,10 +1199,11 @@ int ip6_ins_rt(struct net *net, struct fib6_info *rt)
1169 return __ip6_ins_rt(rt, &info, NULL); 1199 return __ip6_ins_rt(rt, &info, NULL);
1170} 1200}
1171 1201
1172static struct rt6_info *ip6_rt_cache_alloc(struct fib6_info *ort, 1202static struct rt6_info *ip6_rt_cache_alloc(const struct fib6_result *res,
1173 const struct in6_addr *daddr, 1203 const struct in6_addr *daddr,
1174 const struct in6_addr *saddr) 1204 const struct in6_addr *saddr)
1175{ 1205{
1206 struct fib6_info *f6i = res->f6i;
1176 struct net_device *dev; 1207 struct net_device *dev;
1177 struct rt6_info *rt; 1208 struct rt6_info *rt;
1178 1209
@@ -1180,25 +1211,25 @@ static struct rt6_info *ip6_rt_cache_alloc(struct fib6_info *ort,
1180 * Clone the route. 1211 * Clone the route.
1181 */ 1212 */
1182 1213
1183 if (!fib6_info_hold_safe(ort)) 1214 if (!fib6_info_hold_safe(f6i))
1184 return NULL; 1215 return NULL;
1185 1216
1186 dev = ip6_rt_get_dev_rcu(ort); 1217 dev = ip6_rt_get_dev_rcu(res);
1187 rt = ip6_dst_alloc(dev_net(dev), dev, 0); 1218 rt = ip6_dst_alloc(dev_net(dev), dev, 0);
1188 if (!rt) { 1219 if (!rt) {
1189 fib6_info_release(ort); 1220 fib6_info_release(f6i);
1190 return NULL; 1221 return NULL;
1191 } 1222 }
1192 1223
1193 ip6_rt_copy_init(rt, ort); 1224 ip6_rt_copy_init(rt, res);
1194 rt->rt6i_flags |= RTF_CACHE; 1225 rt->rt6i_flags |= RTF_CACHE;
1195 rt->dst.flags |= DST_HOST; 1226 rt->dst.flags |= DST_HOST;
1196 rt->rt6i_dst.addr = *daddr; 1227 rt->rt6i_dst.addr = *daddr;
1197 rt->rt6i_dst.plen = 128; 1228 rt->rt6i_dst.plen = 128;
1198 1229
1199 if (!rt6_is_gw_or_nonexthop(ort)) { 1230 if (!rt6_is_gw_or_nonexthop(res)) {
1200 if (ort->fib6_dst.plen != 128 && 1231 if (f6i->fib6_dst.plen != 128 &&
1201 ipv6_addr_equal(&ort->fib6_dst.addr, daddr)) 1232 ipv6_addr_equal(&f6i->fib6_dst.addr, daddr))
1202 rt->rt6i_flags |= RTF_ANYCAST; 1233 rt->rt6i_flags |= RTF_ANYCAST;
1203#ifdef CONFIG_IPV6_SUBTREES 1234#ifdef CONFIG_IPV6_SUBTREES
1204 if (rt->rt6i_src.plen && saddr) { 1235 if (rt->rt6i_src.plen && saddr) {
@@ -1211,55 +1242,56 @@ static struct rt6_info *ip6_rt_cache_alloc(struct fib6_info *ort,
1211 return rt; 1242 return rt;
1212} 1243}
1213 1244
1214static struct rt6_info *ip6_rt_pcpu_alloc(struct fib6_info *rt) 1245static struct rt6_info *ip6_rt_pcpu_alloc(const struct fib6_result *res)
1215{ 1246{
1216 unsigned short flags = fib6_info_dst_flags(rt); 1247 struct fib6_info *f6i = res->f6i;
1248 unsigned short flags = fib6_info_dst_flags(f6i);
1217 struct net_device *dev; 1249 struct net_device *dev;
1218 struct rt6_info *pcpu_rt; 1250 struct rt6_info *pcpu_rt;
1219 1251
1220 if (!fib6_info_hold_safe(rt)) 1252 if (!fib6_info_hold_safe(f6i))
1221 return NULL; 1253 return NULL;
1222 1254
1223 rcu_read_lock(); 1255 rcu_read_lock();
1224 dev = ip6_rt_get_dev_rcu(rt); 1256 dev = ip6_rt_get_dev_rcu(res);
1225 pcpu_rt = ip6_dst_alloc(dev_net(dev), dev, flags); 1257 pcpu_rt = ip6_dst_alloc(dev_net(dev), dev, flags);
1226 rcu_read_unlock(); 1258 rcu_read_unlock();
1227 if (!pcpu_rt) { 1259 if (!pcpu_rt) {
1228 fib6_info_release(rt); 1260 fib6_info_release(f6i);
1229 return NULL; 1261 return NULL;
1230 } 1262 }
1231 ip6_rt_copy_init(pcpu_rt, rt); 1263 ip6_rt_copy_init(pcpu_rt, res);
1232 pcpu_rt->rt6i_flags |= RTF_PCPU; 1264 pcpu_rt->rt6i_flags |= RTF_PCPU;
1233 return pcpu_rt; 1265 return pcpu_rt;
1234} 1266}
1235 1267
1236/* It should be called with rcu_read_lock() acquired */ 1268/* It should be called with rcu_read_lock() acquired */
1237static struct rt6_info *rt6_get_pcpu_route(struct fib6_info *rt) 1269static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
1238{ 1270{
1239 struct rt6_info *pcpu_rt, **p; 1271 struct rt6_info *pcpu_rt, **p;
1240 1272
1241 p = this_cpu_ptr(rt->rt6i_pcpu); 1273 p = this_cpu_ptr(res->f6i->rt6i_pcpu);
1242 pcpu_rt = *p; 1274 pcpu_rt = *p;
1243 1275
1244 if (pcpu_rt) 1276 if (pcpu_rt)
1245 ip6_hold_safe(NULL, &pcpu_rt, false); 1277 ip6_hold_safe(NULL, &pcpu_rt);
1246 1278
1247 return pcpu_rt; 1279 return pcpu_rt;
1248} 1280}
1249 1281
1250static struct rt6_info *rt6_make_pcpu_route(struct net *net, 1282static struct rt6_info *rt6_make_pcpu_route(struct net *net,
1251 struct fib6_info *rt) 1283 const struct fib6_result *res)
1252{ 1284{
1253 struct rt6_info *pcpu_rt, *prev, **p; 1285 struct rt6_info *pcpu_rt, *prev, **p;
1254 1286
1255 pcpu_rt = ip6_rt_pcpu_alloc(rt); 1287 pcpu_rt = ip6_rt_pcpu_alloc(res);
1256 if (!pcpu_rt) { 1288 if (!pcpu_rt) {
1257 dst_hold(&net->ipv6.ip6_null_entry->dst); 1289 dst_hold(&net->ipv6.ip6_null_entry->dst);
1258 return net->ipv6.ip6_null_entry; 1290 return net->ipv6.ip6_null_entry;
1259 } 1291 }
1260 1292
1261 dst_hold(&pcpu_rt->dst); 1293 dst_hold(&pcpu_rt->dst);
1262 p = this_cpu_ptr(rt->rt6i_pcpu); 1294 p = this_cpu_ptr(res->f6i->rt6i_pcpu);
1263 prev = cmpxchg(p, NULL, pcpu_rt); 1295 prev = cmpxchg(p, NULL, pcpu_rt);
1264 BUG_ON(prev); 1296 BUG_ON(prev);
1265 1297
@@ -1288,9 +1320,7 @@ static void rt6_remove_exception(struct rt6_exception_bucket *bucket,
1288 /* purge completely the exception to allow releasing the held resources: 1320 /* purge completely the exception to allow releasing the held resources:
1289 * some [sk] cache may keep the dst around for unlimited time 1321 * some [sk] cache may keep the dst around for unlimited time
1290 */ 1322 */
1291 from = rcu_dereference_protected(rt6_ex->rt6i->from, 1323 from = xchg((__force struct fib6_info **)&rt6_ex->rt6i->from, NULL);
1292 lockdep_is_held(&rt6_exception_lock));
1293 rcu_assign_pointer(rt6_ex->rt6i->from, NULL);
1294 fib6_info_release(from); 1324 fib6_info_release(from);
1295 dst_dev_put(&rt6_ex->rt6i->dst); 1325 dst_dev_put(&rt6_ex->rt6i->dst);
1296 1326
@@ -1402,14 +1432,15 @@ __rt6_find_exception_rcu(struct rt6_exception_bucket **bucket,
1402 return NULL; 1432 return NULL;
1403} 1433}
1404 1434
1405static unsigned int fib6_mtu(const struct fib6_info *rt) 1435static unsigned int fib6_mtu(const struct fib6_result *res)
1406{ 1436{
1437 const struct fib6_nh *nh = res->nh;
1407 unsigned int mtu; 1438 unsigned int mtu;
1408 1439
1409 if (rt->fib6_pmtu) { 1440 if (res->f6i->fib6_pmtu) {
1410 mtu = rt->fib6_pmtu; 1441 mtu = res->f6i->fib6_pmtu;
1411 } else { 1442 } else {
1412 struct net_device *dev = fib6_info_nh_dev(rt); 1443 struct net_device *dev = nh->fib_nh_dev;
1413 struct inet6_dev *idev; 1444 struct inet6_dev *idev;
1414 1445
1415 rcu_read_lock(); 1446 rcu_read_lock();
@@ -1420,26 +1451,27 @@ static unsigned int fib6_mtu(const struct fib6_info *rt)
1420 1451
1421 mtu = min_t(unsigned int, mtu, IP6_MAX_MTU); 1452 mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
1422 1453
1423 return mtu - lwtunnel_headroom(rt->fib6_nh.nh_lwtstate, mtu); 1454 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu);
1424} 1455}
1425 1456
1426static int rt6_insert_exception(struct rt6_info *nrt, 1457static int rt6_insert_exception(struct rt6_info *nrt,
1427 struct fib6_info *ort) 1458 const struct fib6_result *res)
1428{ 1459{
1429 struct net *net = dev_net(nrt->dst.dev); 1460 struct net *net = dev_net(nrt->dst.dev);
1430 struct rt6_exception_bucket *bucket; 1461 struct rt6_exception_bucket *bucket;
1431 struct in6_addr *src_key = NULL; 1462 struct in6_addr *src_key = NULL;
1432 struct rt6_exception *rt6_ex; 1463 struct rt6_exception *rt6_ex;
1464 struct fib6_info *f6i = res->f6i;
1433 int err = 0; 1465 int err = 0;
1434 1466
1435 spin_lock_bh(&rt6_exception_lock); 1467 spin_lock_bh(&rt6_exception_lock);
1436 1468
1437 if (ort->exception_bucket_flushed) { 1469 if (f6i->exception_bucket_flushed) {
1438 err = -EINVAL; 1470 err = -EINVAL;
1439 goto out; 1471 goto out;
1440 } 1472 }
1441 1473
1442 bucket = rcu_dereference_protected(ort->rt6i_exception_bucket, 1474 bucket = rcu_dereference_protected(f6i->rt6i_exception_bucket,
1443 lockdep_is_held(&rt6_exception_lock)); 1475 lockdep_is_held(&rt6_exception_lock));
1444 if (!bucket) { 1476 if (!bucket) {
1445 bucket = kcalloc(FIB6_EXCEPTION_BUCKET_SIZE, sizeof(*bucket), 1477 bucket = kcalloc(FIB6_EXCEPTION_BUCKET_SIZE, sizeof(*bucket),
@@ -1448,24 +1480,24 @@ static int rt6_insert_exception(struct rt6_info *nrt,
1448 err = -ENOMEM; 1480 err = -ENOMEM;
1449 goto out; 1481 goto out;
1450 } 1482 }
1451 rcu_assign_pointer(ort->rt6i_exception_bucket, bucket); 1483 rcu_assign_pointer(f6i->rt6i_exception_bucket, bucket);
1452 } 1484 }
1453 1485
1454#ifdef CONFIG_IPV6_SUBTREES 1486#ifdef CONFIG_IPV6_SUBTREES
1455 /* rt6i_src.plen != 0 indicates ort is in subtree 1487 /* fib6_src.plen != 0 indicates f6i is in subtree
1456 * and exception table is indexed by a hash of 1488 * and exception table is indexed by a hash of
1457 * both rt6i_dst and rt6i_src. 1489 * both fib6_dst and fib6_src.
1458 * Otherwise, the exception table is indexed by 1490 * Otherwise, the exception table is indexed by
1459 * a hash of only rt6i_dst. 1491 * a hash of only fib6_dst.
1460 */ 1492 */
1461 if (ort->fib6_src.plen) 1493 if (f6i->fib6_src.plen)
1462 src_key = &nrt->rt6i_src.addr; 1494 src_key = &nrt->rt6i_src.addr;
1463#endif 1495#endif
1464 /* rt6_mtu_change() might lower mtu on ort. 1496 /* rt6_mtu_change() might lower mtu on f6i.
1465 * Only insert this exception route if its mtu 1497 * Only insert this exception route if its mtu
1466 * is less than ort's mtu value. 1498 * is less than f6i's mtu value.
1467 */ 1499 */
1468 if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(ort)) { 1500 if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) {
1469 err = -EINVAL; 1501 err = -EINVAL;
1470 goto out; 1502 goto out;
1471 } 1503 }
@@ -1494,9 +1526,9 @@ out:
1494 1526
1495 /* Update fn->fn_sernum to invalidate all cached dst */ 1527 /* Update fn->fn_sernum to invalidate all cached dst */
1496 if (!err) { 1528 if (!err) {
1497 spin_lock_bh(&ort->fib6_table->tb6_lock); 1529 spin_lock_bh(&f6i->fib6_table->tb6_lock);
1498 fib6_update_sernum(net, ort); 1530 fib6_update_sernum(net, f6i);
1499 spin_unlock_bh(&ort->fib6_table->tb6_lock); 1531 spin_unlock_bh(&f6i->fib6_table->tb6_lock);
1500 fib6_force_start_gc(net); 1532 fib6_force_start_gc(net);
1501 } 1533 }
1502 1534
@@ -1533,33 +1565,33 @@ out:
1533/* Find cached rt in the hash table inside passed in rt 1565/* Find cached rt in the hash table inside passed in rt
1534 * Caller has to hold rcu_read_lock() 1566 * Caller has to hold rcu_read_lock()
1535 */ 1567 */
1536static struct rt6_info *rt6_find_cached_rt(struct fib6_info *rt, 1568static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res,
1537 struct in6_addr *daddr, 1569 struct in6_addr *daddr,
1538 struct in6_addr *saddr) 1570 struct in6_addr *saddr)
1539{ 1571{
1540 struct rt6_exception_bucket *bucket; 1572 struct rt6_exception_bucket *bucket;
1541 struct in6_addr *src_key = NULL; 1573 struct in6_addr *src_key = NULL;
1542 struct rt6_exception *rt6_ex; 1574 struct rt6_exception *rt6_ex;
1543 struct rt6_info *res = NULL; 1575 struct rt6_info *ret = NULL;
1544 1576
1545 bucket = rcu_dereference(rt->rt6i_exception_bucket); 1577 bucket = rcu_dereference(res->f6i->rt6i_exception_bucket);
1546 1578
1547#ifdef CONFIG_IPV6_SUBTREES 1579#ifdef CONFIG_IPV6_SUBTREES
1548 /* rt6i_src.plen != 0 indicates rt is in subtree 1580 /* fib6i_src.plen != 0 indicates f6i is in subtree
1549 * and exception table is indexed by a hash of 1581 * and exception table is indexed by a hash of
1550 * both rt6i_dst and rt6i_src. 1582 * both fib6_dst and fib6_src.
1551 * Otherwise, the exception table is indexed by 1583 * Otherwise, the exception table is indexed by
1552 * a hash of only rt6i_dst. 1584 * a hash of only fib6_dst.
1553 */ 1585 */
1554 if (rt->fib6_src.plen) 1586 if (res->f6i->fib6_src.plen)
1555 src_key = saddr; 1587 src_key = saddr;
1556#endif 1588#endif
1557 rt6_ex = __rt6_find_exception_rcu(&bucket, daddr, src_key); 1589 rt6_ex = __rt6_find_exception_rcu(&bucket, daddr, src_key);
1558 1590
1559 if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i)) 1591 if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i))
1560 res = rt6_ex->rt6i; 1592 ret = rt6_ex->rt6i;
1561 1593
1562 return res; 1594 return ret;
1563} 1595}
1564 1596
1565/* Remove the passed in cached rt from the hash table that contains it */ 1597/* Remove the passed in cached rt from the hash table that contains it */
@@ -1807,11 +1839,10 @@ void rt6_age_exceptions(struct fib6_info *rt,
1807} 1839}
1808 1840
1809/* must be called with rcu lock held */ 1841/* must be called with rcu lock held */
1810struct fib6_info *fib6_table_lookup(struct net *net, struct fib6_table *table, 1842int fib6_table_lookup(struct net *net, struct fib6_table *table, int oif,
1811 int oif, struct flowi6 *fl6, int strict) 1843 struct flowi6 *fl6, struct fib6_result *res, int strict)
1812{ 1844{
1813 struct fib6_node *fn, *saved_fn; 1845 struct fib6_node *fn, *saved_fn;
1814 struct fib6_info *f6i;
1815 1846
1816 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); 1847 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
1817 saved_fn = fn; 1848 saved_fn = fn;
@@ -1820,8 +1851,8 @@ struct fib6_info *fib6_table_lookup(struct net *net, struct fib6_table *table,
1820 oif = 0; 1851 oif = 0;
1821 1852
1822redo_rt6_select: 1853redo_rt6_select:
1823 f6i = rt6_select(net, fn, oif, strict); 1854 rt6_select(net, fn, oif, res, strict);
1824 if (f6i == net->ipv6.fib6_null_entry) { 1855 if (res->f6i == net->ipv6.fib6_null_entry) {
1825 fn = fib6_backtrack(fn, &fl6->saddr); 1856 fn = fib6_backtrack(fn, &fl6->saddr);
1826 if (fn) 1857 if (fn)
1827 goto redo_rt6_select; 1858 goto redo_rt6_select;
@@ -1833,16 +1864,16 @@ redo_rt6_select:
1833 } 1864 }
1834 } 1865 }
1835 1866
1836 trace_fib6_table_lookup(net, f6i, table, fl6); 1867 trace_fib6_table_lookup(net, res, table, fl6);
1837 1868
1838 return f6i; 1869 return 0;
1839} 1870}
1840 1871
1841struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, 1872struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
1842 int oif, struct flowi6 *fl6, 1873 int oif, struct flowi6 *fl6,
1843 const struct sk_buff *skb, int flags) 1874 const struct sk_buff *skb, int flags)
1844{ 1875{
1845 struct fib6_info *f6i; 1876 struct fib6_result res = {};
1846 struct rt6_info *rt; 1877 struct rt6_info *rt;
1847 int strict = 0; 1878 int strict = 0;
1848 1879
@@ -1853,27 +1884,26 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
1853 1884
1854 rcu_read_lock(); 1885 rcu_read_lock();
1855 1886
1856 f6i = fib6_table_lookup(net, table, oif, fl6, strict); 1887 fib6_table_lookup(net, table, oif, fl6, &res, strict);
1857 if (f6i->fib6_nsiblings) 1888 if (res.f6i == net->ipv6.fib6_null_entry) {
1858 f6i = fib6_multipath_select(net, f6i, fl6, oif, skb, strict);
1859
1860 if (f6i == net->ipv6.fib6_null_entry) {
1861 rt = net->ipv6.ip6_null_entry; 1889 rt = net->ipv6.ip6_null_entry;
1862 rcu_read_unlock(); 1890 rcu_read_unlock();
1863 dst_hold(&rt->dst); 1891 dst_hold(&rt->dst);
1864 return rt; 1892 return rt;
1865 } 1893 }
1866 1894
1895 fib6_select_path(net, &res, fl6, oif, false, skb, strict);
1896
1867 /*Search through exception table */ 1897 /*Search through exception table */
1868 rt = rt6_find_cached_rt(f6i, &fl6->daddr, &fl6->saddr); 1898 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr);
1869 if (rt) { 1899 if (rt) {
1870 if (ip6_hold_safe(net, &rt, true)) 1900 if (ip6_hold_safe(net, &rt))
1871 dst_use_noref(&rt->dst, jiffies); 1901 dst_use_noref(&rt->dst, jiffies);
1872 1902
1873 rcu_read_unlock(); 1903 rcu_read_unlock();
1874 return rt; 1904 return rt;
1875 } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) && 1905 } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) &&
1876 !(f6i->fib6_flags & RTF_GATEWAY))) { 1906 !res.nh->fib_nh_gw_family)) {
1877 /* Create a RTF_CACHE clone which will not be 1907 /* Create a RTF_CACHE clone which will not be
1878 * owned by the fib6 tree. It is for the special case where 1908 * owned by the fib6 tree. It is for the special case where
1879 * the daddr in the skb during the neighbor look-up is different 1909 * the daddr in the skb during the neighbor look-up is different
@@ -1881,7 +1911,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
1881 */ 1911 */
1882 struct rt6_info *uncached_rt; 1912 struct rt6_info *uncached_rt;
1883 1913
1884 uncached_rt = ip6_rt_cache_alloc(f6i, &fl6->daddr, NULL); 1914 uncached_rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL);
1885 1915
1886 rcu_read_unlock(); 1916 rcu_read_unlock();
1887 1917
@@ -1903,10 +1933,10 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
1903 struct rt6_info *pcpu_rt; 1933 struct rt6_info *pcpu_rt;
1904 1934
1905 local_bh_disable(); 1935 local_bh_disable();
1906 pcpu_rt = rt6_get_pcpu_route(f6i); 1936 pcpu_rt = rt6_get_pcpu_route(&res);
1907 1937
1908 if (!pcpu_rt) 1938 if (!pcpu_rt)
1909 pcpu_rt = rt6_make_pcpu_route(net, f6i); 1939 pcpu_rt = rt6_make_pcpu_route(net, &res);
1910 1940
1911 local_bh_enable(); 1941 local_bh_enable();
1912 rcu_read_unlock(); 1942 rcu_read_unlock();
@@ -2325,15 +2355,23 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
2325 if (rt6->rt6i_flags & RTF_CACHE) 2355 if (rt6->rt6i_flags & RTF_CACHE)
2326 rt6_update_exception_stamp_rt(rt6); 2356 rt6_update_exception_stamp_rt(rt6);
2327 } else if (daddr) { 2357 } else if (daddr) {
2328 struct fib6_info *from; 2358 struct fib6_result res = {};
2329 struct rt6_info *nrt6; 2359 struct rt6_info *nrt6;
2330 2360
2331 rcu_read_lock(); 2361 rcu_read_lock();
2332 from = rcu_dereference(rt6->from); 2362 res.f6i = rcu_dereference(rt6->from);
2333 nrt6 = ip6_rt_cache_alloc(from, daddr, saddr); 2363 if (!res.f6i) {
2364 rcu_read_unlock();
2365 return;
2366 }
2367 res.nh = &res.f6i->fib6_nh;
2368 res.fib6_flags = res.f6i->fib6_flags;
2369 res.fib6_type = res.f6i->fib6_type;
2370
2371 nrt6 = ip6_rt_cache_alloc(&res, daddr, saddr);
2334 if (nrt6) { 2372 if (nrt6) {
2335 rt6_do_update_pmtu(nrt6, mtu); 2373 rt6_do_update_pmtu(nrt6, mtu);
2336 if (rt6_insert_exception(nrt6, from)) 2374 if (rt6_insert_exception(nrt6, &res))
2337 dst_release_immediate(&nrt6->dst); 2375 dst_release_immediate(&nrt6->dst);
2338 } 2376 }
2339 rcu_read_unlock(); 2377 rcu_read_unlock();
@@ -2406,6 +2444,36 @@ void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
2406 NULL); 2444 NULL);
2407} 2445}
2408 2446
2447static bool ip6_redirect_nh_match(const struct fib6_result *res,
2448 struct flowi6 *fl6,
2449 const struct in6_addr *gw,
2450 struct rt6_info **ret)
2451{
2452 const struct fib6_nh *nh = res->nh;
2453
2454 if (nh->fib_nh_flags & RTNH_F_DEAD || !nh->fib_nh_gw_family ||
2455 fl6->flowi6_oif != nh->fib_nh_dev->ifindex)
2456 return false;
2457
2458 /* rt_cache's gateway might be different from its 'parent'
2459 * in the case of an ip redirect.
2460 * So we keep searching in the exception table if the gateway
2461 * is different.
2462 */
2463 if (!ipv6_addr_equal(gw, &nh->fib_nh_gw6)) {
2464 struct rt6_info *rt_cache;
2465
2466 rt_cache = rt6_find_cached_rt(res, &fl6->daddr, &fl6->saddr);
2467 if (rt_cache &&
2468 ipv6_addr_equal(gw, &rt_cache->rt6i_gateway)) {
2469 *ret = rt_cache;
2470 return true;
2471 }
2472 return false;
2473 }
2474 return true;
2475}
2476
2409/* Handle redirects */ 2477/* Handle redirects */
2410struct ip6rd_flowi { 2478struct ip6rd_flowi {
2411 struct flowi6 fl6; 2479 struct flowi6 fl6;
@@ -2419,7 +2487,8 @@ static struct rt6_info *__ip6_route_redirect(struct net *net,
2419 int flags) 2487 int flags)
2420{ 2488{
2421 struct ip6rd_flowi *rdfl = (struct ip6rd_flowi *)fl6; 2489 struct ip6rd_flowi *rdfl = (struct ip6rd_flowi *)fl6;
2422 struct rt6_info *ret = NULL, *rt_cache; 2490 struct rt6_info *ret = NULL;
2491 struct fib6_result res = {};
2423 struct fib6_info *rt; 2492 struct fib6_info *rt;
2424 struct fib6_node *fn; 2493 struct fib6_node *fn;
2425 2494
@@ -2437,34 +2506,15 @@ static struct rt6_info *__ip6_route_redirect(struct net *net,
2437 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); 2506 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
2438restart: 2507restart:
2439 for_each_fib6_node_rt_rcu(fn) { 2508 for_each_fib6_node_rt_rcu(fn) {
2440 if (rt->fib6_nh.nh_flags & RTNH_F_DEAD) 2509 res.f6i = rt;
2441 continue; 2510 res.nh = &rt->fib6_nh;
2511
2442 if (fib6_check_expired(rt)) 2512 if (fib6_check_expired(rt))
2443 continue; 2513 continue;
2444 if (rt->fib6_flags & RTF_REJECT) 2514 if (rt->fib6_flags & RTF_REJECT)
2445 break; 2515 break;
2446 if (!(rt->fib6_flags & RTF_GATEWAY)) 2516 if (ip6_redirect_nh_match(&res, fl6, &rdfl->gateway, &ret))
2447 continue; 2517 goto out;
2448 if (fl6->flowi6_oif != rt->fib6_nh.nh_dev->ifindex)
2449 continue;
2450 /* rt_cache's gateway might be different from its 'parent'
2451 * in the case of an ip redirect.
2452 * So we keep searching in the exception table if the gateway
2453 * is different.
2454 */
2455 if (!ipv6_addr_equal(&rdfl->gateway, &rt->fib6_nh.nh_gw)) {
2456 rt_cache = rt6_find_cached_rt(rt,
2457 &fl6->daddr,
2458 &fl6->saddr);
2459 if (rt_cache &&
2460 ipv6_addr_equal(&rdfl->gateway,
2461 &rt_cache->rt6i_gateway)) {
2462 ret = rt_cache;
2463 break;
2464 }
2465 continue;
2466 }
2467 break;
2468 } 2518 }
2469 2519
2470 if (!rt) 2520 if (!rt)
@@ -2480,15 +2530,20 @@ restart:
2480 goto restart; 2530 goto restart;
2481 } 2531 }
2482 2532
2533 res.f6i = rt;
2534 res.nh = &rt->fib6_nh;
2483out: 2535out:
2484 if (ret) 2536 if (ret) {
2485 ip6_hold_safe(net, &ret, true); 2537 ip6_hold_safe(net, &ret);
2486 else 2538 } else {
2487 ret = ip6_create_rt_rcu(rt); 2539 res.fib6_flags = res.f6i->fib6_flags;
2540 res.fib6_type = res.f6i->fib6_type;
2541 ret = ip6_create_rt_rcu(&res);
2542 }
2488 2543
2489 rcu_read_unlock(); 2544 rcu_read_unlock();
2490 2545
2491 trace_fib6_table_lookup(net, rt, table, fl6); 2546 trace_fib6_table_lookup(net, &res, table, fl6);
2492 return ret; 2547 return ret;
2493}; 2548};
2494 2549
@@ -2606,12 +2661,15 @@ out:
2606 * based on ip6_dst_mtu_forward and exception logic of 2661 * based on ip6_dst_mtu_forward and exception logic of
2607 * rt6_find_cached_rt; called with rcu_read_lock 2662 * rt6_find_cached_rt; called with rcu_read_lock
2608 */ 2663 */
2609u32 ip6_mtu_from_fib6(struct fib6_info *f6i, struct in6_addr *daddr, 2664u32 ip6_mtu_from_fib6(const struct fib6_result *res,
2610 struct in6_addr *saddr) 2665 const struct in6_addr *daddr,
2666 const struct in6_addr *saddr)
2611{ 2667{
2612 struct rt6_exception_bucket *bucket; 2668 struct rt6_exception_bucket *bucket;
2669 const struct fib6_nh *nh = res->nh;
2670 struct fib6_info *f6i = res->f6i;
2671 const struct in6_addr *src_key;
2613 struct rt6_exception *rt6_ex; 2672 struct rt6_exception *rt6_ex;
2614 struct in6_addr *src_key;
2615 struct inet6_dev *idev; 2673 struct inet6_dev *idev;
2616 u32 mtu = 0; 2674 u32 mtu = 0;
2617 2675
@@ -2633,7 +2691,7 @@ u32 ip6_mtu_from_fib6(struct fib6_info *f6i, struct in6_addr *daddr,
2633 mtu = dst_metric_raw(&rt6_ex->rt6i->dst, RTAX_MTU); 2691 mtu = dst_metric_raw(&rt6_ex->rt6i->dst, RTAX_MTU);
2634 2692
2635 if (likely(!mtu)) { 2693 if (likely(!mtu)) {
2636 struct net_device *dev = fib6_info_nh_dev(f6i); 2694 struct net_device *dev = nh->fib_nh_dev;
2637 2695
2638 mtu = IPV6_MIN_MTU; 2696 mtu = IPV6_MIN_MTU;
2639 idev = __in6_dev_get(dev); 2697 idev = __in6_dev_get(dev);
@@ -2643,7 +2701,7 @@ u32 ip6_mtu_from_fib6(struct fib6_info *f6i, struct in6_addr *daddr,
2643 2701
2644 mtu = min_t(unsigned int, mtu, IP6_MAX_MTU); 2702 mtu = min_t(unsigned int, mtu, IP6_MAX_MTU);
2645out: 2703out:
2646 return mtu - lwtunnel_headroom(fib6_info_nh_lwt(f6i), mtu); 2704 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu);
2647} 2705}
2648 2706
2649struct dst_entry *icmp6_dst_alloc(struct net_device *dev, 2707struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
@@ -2899,17 +2957,143 @@ out:
2899 return err; 2957 return err;
2900} 2958}
2901 2959
2960static bool fib6_is_reject(u32 flags, struct net_device *dev, int addr_type)
2961{
2962 if ((flags & RTF_REJECT) ||
2963 (dev && (dev->flags & IFF_LOOPBACK) &&
2964 !(addr_type & IPV6_ADDR_LOOPBACK) &&
2965 !(flags & RTF_LOCAL)))
2966 return true;
2967
2968 return false;
2969}
2970
2971int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
2972 struct fib6_config *cfg, gfp_t gfp_flags,
2973 struct netlink_ext_ack *extack)
2974{
2975 struct net_device *dev = NULL;
2976 struct inet6_dev *idev = NULL;
2977 int addr_type;
2978 int err;
2979
2980 fib6_nh->fib_nh_family = AF_INET6;
2981
2982 err = -ENODEV;
2983 if (cfg->fc_ifindex) {
2984 dev = dev_get_by_index(net, cfg->fc_ifindex);
2985 if (!dev)
2986 goto out;
2987 idev = in6_dev_get(dev);
2988 if (!idev)
2989 goto out;
2990 }
2991
2992 if (cfg->fc_flags & RTNH_F_ONLINK) {
2993 if (!dev) {
2994 NL_SET_ERR_MSG(extack,
2995 "Nexthop device required for onlink");
2996 goto out;
2997 }
2998
2999 if (!(dev->flags & IFF_UP)) {
3000 NL_SET_ERR_MSG(extack, "Nexthop device is not up");
3001 err = -ENETDOWN;
3002 goto out;
3003 }
3004
3005 fib6_nh->fib_nh_flags |= RTNH_F_ONLINK;
3006 }
3007
3008 fib6_nh->fib_nh_weight = 1;
3009
3010 /* We cannot add true routes via loopback here,
3011 * they would result in kernel looping; promote them to reject routes
3012 */
3013 addr_type = ipv6_addr_type(&cfg->fc_dst);
3014 if (fib6_is_reject(cfg->fc_flags, dev, addr_type)) {
3015 /* hold loopback dev/idev if we haven't done so. */
3016 if (dev != net->loopback_dev) {
3017 if (dev) {
3018 dev_put(dev);
3019 in6_dev_put(idev);
3020 }
3021 dev = net->loopback_dev;
3022 dev_hold(dev);
3023 idev = in6_dev_get(dev);
3024 if (!idev) {
3025 err = -ENODEV;
3026 goto out;
3027 }
3028 }
3029 goto set_dev;
3030 }
3031
3032 if (cfg->fc_flags & RTF_GATEWAY) {
3033 err = ip6_validate_gw(net, cfg, &dev, &idev, extack);
3034 if (err)
3035 goto out;
3036
3037 fib6_nh->fib_nh_gw6 = cfg->fc_gateway;
3038 fib6_nh->fib_nh_gw_family = AF_INET6;
3039 }
3040
3041 err = -ENODEV;
3042 if (!dev)
3043 goto out;
3044
3045 if (idev->cnf.disable_ipv6) {
3046 NL_SET_ERR_MSG(extack, "IPv6 is disabled on nexthop device");
3047 err = -EACCES;
3048 goto out;
3049 }
3050
3051 if (!(dev->flags & IFF_UP) && !cfg->fc_ignore_dev_down) {
3052 NL_SET_ERR_MSG(extack, "Nexthop device is not up");
3053 err = -ENETDOWN;
3054 goto out;
3055 }
3056
3057 if (!(cfg->fc_flags & (RTF_LOCAL | RTF_ANYCAST)) &&
3058 !netif_carrier_ok(dev))
3059 fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
3060
3061 err = fib_nh_common_init(&fib6_nh->nh_common, cfg->fc_encap,
3062 cfg->fc_encap_type, cfg, gfp_flags, extack);
3063 if (err)
3064 goto out;
3065set_dev:
3066 fib6_nh->fib_nh_dev = dev;
3067 fib6_nh->fib_nh_oif = dev->ifindex;
3068 err = 0;
3069out:
3070 if (idev)
3071 in6_dev_put(idev);
3072
3073 if (err) {
3074 lwtstate_put(fib6_nh->fib_nh_lws);
3075 fib6_nh->fib_nh_lws = NULL;
3076 if (dev)
3077 dev_put(dev);
3078 }
3079
3080 return err;
3081}
3082
3083void fib6_nh_release(struct fib6_nh *fib6_nh)
3084{
3085 fib_nh_common_release(&fib6_nh->nh_common);
3086}
3087
2902static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg, 3088static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
2903 gfp_t gfp_flags, 3089 gfp_t gfp_flags,
2904 struct netlink_ext_ack *extack) 3090 struct netlink_ext_ack *extack)
2905{ 3091{
2906 struct net *net = cfg->fc_nlinfo.nl_net; 3092 struct net *net = cfg->fc_nlinfo.nl_net;
2907 struct fib6_info *rt = NULL; 3093 struct fib6_info *rt = NULL;
2908 struct net_device *dev = NULL;
2909 struct inet6_dev *idev = NULL;
2910 struct fib6_table *table; 3094 struct fib6_table *table;
2911 int addr_type;
2912 int err = -EINVAL; 3095 int err = -EINVAL;
3096 int addr_type;
2913 3097
2914 /* RTF_PCPU is an internal flag; can not be set by userspace */ 3098 /* RTF_PCPU is an internal flag; can not be set by userspace */
2915 if (cfg->fc_flags & RTF_PCPU) { 3099 if (cfg->fc_flags & RTF_PCPU) {
@@ -2943,33 +3127,6 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
2943 goto out; 3127 goto out;
2944 } 3128 }
2945#endif 3129#endif
2946 if (cfg->fc_ifindex) {
2947 err = -ENODEV;
2948 dev = dev_get_by_index(net, cfg->fc_ifindex);
2949 if (!dev)
2950 goto out;
2951 idev = in6_dev_get(dev);
2952 if (!idev)
2953 goto out;
2954 }
2955
2956 if (cfg->fc_metric == 0)
2957 cfg->fc_metric = IP6_RT_PRIO_USER;
2958
2959 if (cfg->fc_flags & RTNH_F_ONLINK) {
2960 if (!dev) {
2961 NL_SET_ERR_MSG(extack,
2962 "Nexthop device required for onlink");
2963 err = -ENODEV;
2964 goto out;
2965 }
2966
2967 if (!(dev->flags & IFF_UP)) {
2968 NL_SET_ERR_MSG(extack, "Nexthop device is not up");
2969 err = -ENETDOWN;
2970 goto out;
2971 }
2972 }
2973 3130
2974 err = -ENOBUFS; 3131 err = -ENOBUFS;
2975 if (cfg->fc_nlinfo.nlh && 3132 if (cfg->fc_nlinfo.nlh &&
@@ -3013,18 +3170,10 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
3013 cfg->fc_protocol = RTPROT_BOOT; 3170 cfg->fc_protocol = RTPROT_BOOT;
3014 rt->fib6_protocol = cfg->fc_protocol; 3171 rt->fib6_protocol = cfg->fc_protocol;
3015 3172
3016 addr_type = ipv6_addr_type(&cfg->fc_dst); 3173 rt->fib6_table = table;
3017 3174 rt->fib6_metric = cfg->fc_metric;
3018 if (cfg->fc_encap) { 3175 rt->fib6_type = cfg->fc_type;
3019 struct lwtunnel_state *lwtstate; 3176 rt->fib6_flags = cfg->fc_flags & ~RTF_GATEWAY;
3020
3021 err = lwtunnel_build_state(cfg->fc_encap_type,
3022 cfg->fc_encap, AF_INET6, cfg,
3023 &lwtstate, extack);
3024 if (err)
3025 goto out;
3026 rt->fib6_nh.nh_lwtstate = lwtstate_get(lwtstate);
3027 }
3028 3177
3029 ipv6_addr_prefix(&rt->fib6_dst.addr, &cfg->fc_dst, cfg->fc_dst_len); 3178 ipv6_addr_prefix(&rt->fib6_dst.addr, &cfg->fc_dst, cfg->fc_dst_len);
3030 rt->fib6_dst.plen = cfg->fc_dst_len; 3179 rt->fib6_dst.plen = cfg->fc_dst_len;
@@ -3035,62 +3184,20 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
3035 ipv6_addr_prefix(&rt->fib6_src.addr, &cfg->fc_src, cfg->fc_src_len); 3184 ipv6_addr_prefix(&rt->fib6_src.addr, &cfg->fc_src, cfg->fc_src_len);
3036 rt->fib6_src.plen = cfg->fc_src_len; 3185 rt->fib6_src.plen = cfg->fc_src_len;
3037#endif 3186#endif
3038 3187 err = fib6_nh_init(net, &rt->fib6_nh, cfg, gfp_flags, extack);
3039 rt->fib6_metric = cfg->fc_metric; 3188 if (err)
3040 rt->fib6_nh.nh_weight = 1; 3189 goto out;
3041
3042 rt->fib6_type = cfg->fc_type;
3043 3190
3044 /* We cannot add true routes via loopback here, 3191 /* We cannot add true routes via loopback here,
3045 they would result in kernel looping; promote them to reject routes 3192 * they would result in kernel looping; promote them to reject routes
3046 */ 3193 */
3047 if ((cfg->fc_flags & RTF_REJECT) || 3194 addr_type = ipv6_addr_type(&cfg->fc_dst);
3048 (dev && (dev->flags & IFF_LOOPBACK) && 3195 if (fib6_is_reject(cfg->fc_flags, rt->fib6_nh.fib_nh_dev, addr_type))
3049 !(addr_type & IPV6_ADDR_LOOPBACK) && 3196 rt->fib6_flags = RTF_REJECT | RTF_NONEXTHOP;
3050 !(cfg->fc_flags & RTF_LOCAL))) {
3051 /* hold loopback dev/idev if we haven't done so. */
3052 if (dev != net->loopback_dev) {
3053 if (dev) {
3054 dev_put(dev);
3055 in6_dev_put(idev);
3056 }
3057 dev = net->loopback_dev;
3058 dev_hold(dev);
3059 idev = in6_dev_get(dev);
3060 if (!idev) {
3061 err = -ENODEV;
3062 goto out;
3063 }
3064 }
3065 rt->fib6_flags = RTF_REJECT|RTF_NONEXTHOP;
3066 goto install_route;
3067 }
3068
3069 if (cfg->fc_flags & RTF_GATEWAY) {
3070 err = ip6_validate_gw(net, cfg, &dev, &idev, extack);
3071 if (err)
3072 goto out;
3073
3074 rt->fib6_nh.nh_gw = cfg->fc_gateway;
3075 }
3076
3077 err = -ENODEV;
3078 if (!dev)
3079 goto out;
3080
3081 if (idev->cnf.disable_ipv6) {
3082 NL_SET_ERR_MSG(extack, "IPv6 is disabled on nexthop device");
3083 err = -EACCES;
3084 goto out;
3085 }
3086
3087 if (!(dev->flags & IFF_UP)) {
3088 NL_SET_ERR_MSG(extack, "Nexthop device is not up");
3089 err = -ENETDOWN;
3090 goto out;
3091 }
3092 3197
3093 if (!ipv6_addr_any(&cfg->fc_prefsrc)) { 3198 if (!ipv6_addr_any(&cfg->fc_prefsrc)) {
3199 struct net_device *dev = fib6_info_nh_dev(rt);
3200
3094 if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) { 3201 if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) {
3095 NL_SET_ERR_MSG(extack, "Invalid source address"); 3202 NL_SET_ERR_MSG(extack, "Invalid source address");
3096 err = -EINVAL; 3203 err = -EINVAL;
@@ -3101,26 +3208,8 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
3101 } else 3208 } else
3102 rt->fib6_prefsrc.plen = 0; 3209 rt->fib6_prefsrc.plen = 0;
3103 3210
3104 rt->fib6_flags = cfg->fc_flags;
3105
3106install_route:
3107 if (!(rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) &&
3108 !netif_carrier_ok(dev))
3109 rt->fib6_nh.nh_flags |= RTNH_F_LINKDOWN;
3110 rt->fib6_nh.nh_flags |= (cfg->fc_flags & RTNH_F_ONLINK);
3111 rt->fib6_nh.nh_dev = dev;
3112 rt->fib6_table = table;
3113
3114 if (idev)
3115 in6_dev_put(idev);
3116
3117 return rt; 3211 return rt;
3118out: 3212out:
3119 if (dev)
3120 dev_put(dev);
3121 if (idev)
3122 in6_dev_put(idev);
3123
3124 fib6_info_release(rt); 3213 fib6_info_release(rt);
3125 return ERR_PTR(err); 3214 return ERR_PTR(err);
3126} 3215}
@@ -3261,10 +3350,16 @@ static int ip6_route_del(struct fib6_config *cfg,
3261 3350
3262 if (fn) { 3351 if (fn) {
3263 for_each_fib6_node_rt_rcu(fn) { 3352 for_each_fib6_node_rt_rcu(fn) {
3353 struct fib6_nh *nh;
3354
3264 if (cfg->fc_flags & RTF_CACHE) { 3355 if (cfg->fc_flags & RTF_CACHE) {
3356 struct fib6_result res = {
3357 .f6i = rt,
3358 };
3265 int rc; 3359 int rc;
3266 3360
3267 rt_cache = rt6_find_cached_rt(rt, &cfg->fc_dst, 3361 rt_cache = rt6_find_cached_rt(&res,
3362 &cfg->fc_dst,
3268 &cfg->fc_src); 3363 &cfg->fc_src);
3269 if (rt_cache) { 3364 if (rt_cache) {
3270 rc = ip6_del_cached_rt(rt_cache, cfg); 3365 rc = ip6_del_cached_rt(rt_cache, cfg);
@@ -3275,12 +3370,14 @@ static int ip6_route_del(struct fib6_config *cfg,
3275 } 3370 }
3276 continue; 3371 continue;
3277 } 3372 }
3373
3374 nh = &rt->fib6_nh;
3278 if (cfg->fc_ifindex && 3375 if (cfg->fc_ifindex &&
3279 (!rt->fib6_nh.nh_dev || 3376 (!nh->fib_nh_dev ||
3280 rt->fib6_nh.nh_dev->ifindex != cfg->fc_ifindex)) 3377 nh->fib_nh_dev->ifindex != cfg->fc_ifindex))
3281 continue; 3378 continue;
3282 if (cfg->fc_flags & RTF_GATEWAY && 3379 if (cfg->fc_flags & RTF_GATEWAY &&
3283 !ipv6_addr_equal(&cfg->fc_gateway, &rt->fib6_nh.nh_gw)) 3380 !ipv6_addr_equal(&cfg->fc_gateway, &nh->fib_nh_gw6))
3284 continue; 3381 continue;
3285 if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric) 3382 if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric)
3286 continue; 3383 continue;
@@ -3306,10 +3403,10 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu
3306{ 3403{
3307 struct netevent_redirect netevent; 3404 struct netevent_redirect netevent;
3308 struct rt6_info *rt, *nrt = NULL; 3405 struct rt6_info *rt, *nrt = NULL;
3406 struct fib6_result res = {};
3309 struct ndisc_options ndopts; 3407 struct ndisc_options ndopts;
3310 struct inet6_dev *in6_dev; 3408 struct inet6_dev *in6_dev;
3311 struct neighbour *neigh; 3409 struct neighbour *neigh;
3312 struct fib6_info *from;
3313 struct rd_msg *msg; 3410 struct rd_msg *msg;
3314 int optlen, on_link; 3411 int optlen, on_link;
3315 u8 *lladdr; 3412 u8 *lladdr;
@@ -3392,14 +3489,14 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu
3392 NDISC_REDIRECT, &ndopts); 3489 NDISC_REDIRECT, &ndopts);
3393 3490
3394 rcu_read_lock(); 3491 rcu_read_lock();
3395 from = rcu_dereference(rt->from); 3492 res.f6i = rcu_dereference(rt->from);
3396 /* This fib6_info_hold() is safe here because we hold reference to rt 3493 if (!res.f6i)
3397 * and rt already holds reference to fib6_info. 3494 goto out;
3398 */
3399 fib6_info_hold(from);
3400 rcu_read_unlock();
3401 3495
3402 nrt = ip6_rt_cache_alloc(from, &msg->dest, NULL); 3496 res.nh = &res.f6i->fib6_nh;
3497 res.fib6_flags = res.f6i->fib6_flags;
3498 res.fib6_type = res.f6i->fib6_type;
3499 nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL);
3403 if (!nrt) 3500 if (!nrt)
3404 goto out; 3501 goto out;
3405 3502
@@ -3409,11 +3506,8 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu
3409 3506
3410 nrt->rt6i_gateway = *(struct in6_addr *)neigh->primary_key; 3507 nrt->rt6i_gateway = *(struct in6_addr *)neigh->primary_key;
3411 3508
3412 /* No need to remove rt from the exception table if rt is 3509 /* rt6_insert_exception() will take care of duplicated exceptions */
3413 * a cached route because rt6_insert_exception() will 3510 if (rt6_insert_exception(nrt, &res)) {
3414 * takes care of it
3415 */
3416 if (rt6_insert_exception(nrt, from)) {
3417 dst_release_immediate(&nrt->dst); 3511 dst_release_immediate(&nrt->dst);
3418 goto out; 3512 goto out;
3419 } 3513 }
@@ -3425,7 +3519,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu
3425 call_netevent_notifiers(NETEVENT_REDIRECT, &netevent); 3519 call_netevent_notifiers(NETEVENT_REDIRECT, &netevent);
3426 3520
3427out: 3521out:
3428 fib6_info_release(from); 3522 rcu_read_unlock();
3429 neigh_release(neigh); 3523 neigh_release(neigh);
3430} 3524}
3431 3525
@@ -3451,11 +3545,12 @@ static struct fib6_info *rt6_get_route_info(struct net *net,
3451 goto out; 3545 goto out;
3452 3546
3453 for_each_fib6_node_rt_rcu(fn) { 3547 for_each_fib6_node_rt_rcu(fn) {
3454 if (rt->fib6_nh.nh_dev->ifindex != ifindex) 3548 if (rt->fib6_nh.fib_nh_dev->ifindex != ifindex)
3455 continue; 3549 continue;
3456 if ((rt->fib6_flags & (RTF_ROUTEINFO|RTF_GATEWAY)) != (RTF_ROUTEINFO|RTF_GATEWAY)) 3550 if (!(rt->fib6_flags & RTF_ROUTEINFO) ||
3551 !rt->fib6_nh.fib_nh_gw_family)
3457 continue; 3552 continue;
3458 if (!ipv6_addr_equal(&rt->fib6_nh.nh_gw, gwaddr)) 3553 if (!ipv6_addr_equal(&rt->fib6_nh.fib_nh_gw6, gwaddr))
3459 continue; 3554 continue;
3460 if (!fib6_info_hold_safe(rt)) 3555 if (!fib6_info_hold_safe(rt))
3461 continue; 3556 continue;
@@ -3513,9 +3608,11 @@ struct fib6_info *rt6_get_dflt_router(struct net *net,
3513 3608
3514 rcu_read_lock(); 3609 rcu_read_lock();
3515 for_each_fib6_node_rt_rcu(&table->tb6_root) { 3610 for_each_fib6_node_rt_rcu(&table->tb6_root) {
3516 if (dev == rt->fib6_nh.nh_dev && 3611 struct fib6_nh *nh = &rt->fib6_nh;
3612
3613 if (dev == nh->fib_nh_dev &&
3517 ((rt->fib6_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) && 3614 ((rt->fib6_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) &&
3518 ipv6_addr_equal(&rt->fib6_nh.nh_gw, addr)) 3615 ipv6_addr_equal(&nh->fib_nh_gw6, addr))
3519 break; 3616 break;
3520 } 3617 }
3521 if (rt && !fib6_info_hold_safe(rt)) 3618 if (rt && !fib6_info_hold_safe(rt))
@@ -3606,7 +3703,7 @@ static void rtmsg_to_fib6_config(struct net *net,
3606 .fc_table = l3mdev_fib_table_by_index(net, rtmsg->rtmsg_ifindex) ? 3703 .fc_table = l3mdev_fib_table_by_index(net, rtmsg->rtmsg_ifindex) ?
3607 : RT6_TABLE_MAIN, 3704 : RT6_TABLE_MAIN,
3608 .fc_ifindex = rtmsg->rtmsg_ifindex, 3705 .fc_ifindex = rtmsg->rtmsg_ifindex,
3609 .fc_metric = rtmsg->rtmsg_metric, 3706 .fc_metric = rtmsg->rtmsg_metric ? : IP6_RT_PRIO_USER,
3610 .fc_expires = rtmsg->rtmsg_info, 3707 .fc_expires = rtmsg->rtmsg_info,
3611 .fc_dst_len = rtmsg->rtmsg_dst_len, 3708 .fc_dst_len = rtmsg->rtmsg_dst_len,
3612 .fc_src_len = rtmsg->rtmsg_src_len, 3709 .fc_src_len = rtmsg->rtmsg_src_len,
@@ -3664,23 +3761,34 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg)
3664 3761
3665static int ip6_pkt_drop(struct sk_buff *skb, u8 code, int ipstats_mib_noroutes) 3762static int ip6_pkt_drop(struct sk_buff *skb, u8 code, int ipstats_mib_noroutes)
3666{ 3763{
3667 int type;
3668 struct dst_entry *dst = skb_dst(skb); 3764 struct dst_entry *dst = skb_dst(skb);
3765 struct net *net = dev_net(dst->dev);
3766 struct inet6_dev *idev;
3767 int type;
3768
3769 if (netif_is_l3_master(skb->dev) &&
3770 dst->dev == net->loopback_dev)
3771 idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif));
3772 else
3773 idev = ip6_dst_idev(dst);
3774
3669 switch (ipstats_mib_noroutes) { 3775 switch (ipstats_mib_noroutes) {
3670 case IPSTATS_MIB_INNOROUTES: 3776 case IPSTATS_MIB_INNOROUTES:
3671 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr); 3777 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr);
3672 if (type == IPV6_ADDR_ANY) { 3778 if (type == IPV6_ADDR_ANY) {
3673 IP6_INC_STATS(dev_net(dst->dev), 3779 IP6_INC_STATS(net, idev, IPSTATS_MIB_INADDRERRORS);
3674 __in6_dev_get_safely(skb->dev),
3675 IPSTATS_MIB_INADDRERRORS);
3676 break; 3780 break;
3677 } 3781 }
3678 /* FALLTHROUGH */ 3782 /* FALLTHROUGH */
3679 case IPSTATS_MIB_OUTNOROUTES: 3783 case IPSTATS_MIB_OUTNOROUTES:
3680 IP6_INC_STATS(dev_net(dst->dev), ip6_dst_idev(dst), 3784 IP6_INC_STATS(net, idev, ipstats_mib_noroutes);
3681 ipstats_mib_noroutes);
3682 break; 3785 break;
3683 } 3786 }
3787
3788 /* Start over by dropping the dst for l3mdev case */
3789 if (netif_is_l3_master(skb->dev))
3790 skb_dst_drop(skb);
3791
3684 icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0); 3792 icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0);
3685 kfree_skb(skb); 3793 kfree_skb(skb);
3686 return 0; 3794 return 0;
@@ -3717,36 +3825,26 @@ struct fib6_info *addrconf_f6i_alloc(struct net *net,
3717 const struct in6_addr *addr, 3825 const struct in6_addr *addr,
3718 bool anycast, gfp_t gfp_flags) 3826 bool anycast, gfp_t gfp_flags)
3719{ 3827{
3720 u32 tb_id; 3828 struct fib6_config cfg = {
3721 struct net_device *dev = idev->dev; 3829 .fc_table = l3mdev_fib_table(idev->dev) ? : RT6_TABLE_LOCAL,
3722 struct fib6_info *f6i; 3830 .fc_ifindex = idev->dev->ifindex,
3723 3831 .fc_flags = RTF_UP | RTF_ADDRCONF | RTF_NONEXTHOP,
3724 f6i = fib6_info_alloc(gfp_flags); 3832 .fc_dst = *addr,
3725 if (!f6i) 3833 .fc_dst_len = 128,
3726 return ERR_PTR(-ENOMEM); 3834 .fc_protocol = RTPROT_KERNEL,
3835 .fc_nlinfo.nl_net = net,
3836 .fc_ignore_dev_down = true,
3837 };
3727 3838
3728 f6i->fib6_metrics = ip_fib_metrics_init(net, NULL, 0, NULL);
3729 f6i->dst_nocount = true;
3730 f6i->dst_host = true;
3731 f6i->fib6_protocol = RTPROT_KERNEL;
3732 f6i->fib6_flags = RTF_UP | RTF_NONEXTHOP;
3733 if (anycast) { 3839 if (anycast) {
3734 f6i->fib6_type = RTN_ANYCAST; 3840 cfg.fc_type = RTN_ANYCAST;
3735 f6i->fib6_flags |= RTF_ANYCAST; 3841 cfg.fc_flags |= RTF_ANYCAST;
3736 } else { 3842 } else {
3737 f6i->fib6_type = RTN_LOCAL; 3843 cfg.fc_type = RTN_LOCAL;
3738 f6i->fib6_flags |= RTF_LOCAL; 3844 cfg.fc_flags |= RTF_LOCAL;
3739 } 3845 }
3740 3846
3741 f6i->fib6_nh.nh_gw = *addr; 3847 return ip6_route_info_create(&cfg, gfp_flags, NULL);
3742 dev_hold(dev);
3743 f6i->fib6_nh.nh_dev = dev;
3744 f6i->fib6_dst.addr = *addr;
3745 f6i->fib6_dst.plen = 128;
3746 tb_id = l3mdev_fib_table(idev->dev) ? : RT6_TABLE_LOCAL;
3747 f6i->fib6_table = fib6_get_table(net, tb_id);
3748
3749 return f6i;
3750} 3848}
3751 3849
3752/* remove deleted ip from prefsrc entries */ 3850/* remove deleted ip from prefsrc entries */
@@ -3762,7 +3860,7 @@ static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg)
3762 struct net *net = ((struct arg_dev_net_ip *)arg)->net; 3860 struct net *net = ((struct arg_dev_net_ip *)arg)->net;
3763 struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr; 3861 struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr;
3764 3862
3765 if (((void *)rt->fib6_nh.nh_dev == dev || !dev) && 3863 if (((void *)rt->fib6_nh.fib_nh_dev == dev || !dev) &&
3766 rt != net->ipv6.fib6_null_entry && 3864 rt != net->ipv6.fib6_null_entry &&
3767 ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) { 3865 ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) {
3768 spin_lock_bh(&rt6_exception_lock); 3866 spin_lock_bh(&rt6_exception_lock);
@@ -3784,7 +3882,7 @@ void rt6_remove_prefsrc(struct inet6_ifaddr *ifp)
3784 fib6_clean_all(net, fib6_remove_prefsrc, &adni); 3882 fib6_clean_all(net, fib6_remove_prefsrc, &adni);
3785} 3883}
3786 3884
3787#define RTF_RA_ROUTER (RTF_ADDRCONF | RTF_DEFAULT | RTF_GATEWAY) 3885#define RTF_RA_ROUTER (RTF_ADDRCONF | RTF_DEFAULT)
3788 3886
3789/* Remove routers and update dst entries when gateway turn into host. */ 3887/* Remove routers and update dst entries when gateway turn into host. */
3790static int fib6_clean_tohost(struct fib6_info *rt, void *arg) 3888static int fib6_clean_tohost(struct fib6_info *rt, void *arg)
@@ -3792,7 +3890,8 @@ static int fib6_clean_tohost(struct fib6_info *rt, void *arg)
3792 struct in6_addr *gateway = (struct in6_addr *)arg; 3890 struct in6_addr *gateway = (struct in6_addr *)arg;
3793 3891
3794 if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) && 3892 if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) &&
3795 ipv6_addr_equal(gateway, &rt->fib6_nh.nh_gw)) { 3893 rt->fib6_nh.fib_nh_gw_family &&
3894 ipv6_addr_equal(gateway, &rt->fib6_nh.fib_nh_gw6)) {
3796 return -1; 3895 return -1;
3797 } 3896 }
3798 3897
@@ -3813,7 +3912,7 @@ void rt6_clean_tohost(struct net *net, struct in6_addr *gateway)
3813struct arg_netdev_event { 3912struct arg_netdev_event {
3814 const struct net_device *dev; 3913 const struct net_device *dev;
3815 union { 3914 union {
3816 unsigned int nh_flags; 3915 unsigned char nh_flags;
3817 unsigned long event; 3916 unsigned long event;
3818 }; 3917 };
3819}; 3918};
@@ -3840,9 +3939,9 @@ static struct fib6_info *rt6_multipath_first_sibling(const struct fib6_info *rt)
3840 3939
3841static bool rt6_is_dead(const struct fib6_info *rt) 3940static bool rt6_is_dead(const struct fib6_info *rt)
3842{ 3941{
3843 if (rt->fib6_nh.nh_flags & RTNH_F_DEAD || 3942 if (rt->fib6_nh.fib_nh_flags & RTNH_F_DEAD ||
3844 (rt->fib6_nh.nh_flags & RTNH_F_LINKDOWN && 3943 (rt->fib6_nh.fib_nh_flags & RTNH_F_LINKDOWN &&
3845 fib6_ignore_linkdown(rt))) 3944 ip6_ignore_linkdown(rt->fib6_nh.fib_nh_dev)))
3846 return true; 3945 return true;
3847 3946
3848 return false; 3947 return false;
@@ -3854,11 +3953,11 @@ static int rt6_multipath_total_weight(const struct fib6_info *rt)
3854 int total = 0; 3953 int total = 0;
3855 3954
3856 if (!rt6_is_dead(rt)) 3955 if (!rt6_is_dead(rt))
3857 total += rt->fib6_nh.nh_weight; 3956 total += rt->fib6_nh.fib_nh_weight;
3858 3957
3859 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) { 3958 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) {
3860 if (!rt6_is_dead(iter)) 3959 if (!rt6_is_dead(iter))
3861 total += iter->fib6_nh.nh_weight; 3960 total += iter->fib6_nh.fib_nh_weight;
3862 } 3961 }
3863 3962
3864 return total; 3963 return total;
@@ -3869,11 +3968,11 @@ static void rt6_upper_bound_set(struct fib6_info *rt, int *weight, int total)
3869 int upper_bound = -1; 3968 int upper_bound = -1;
3870 3969
3871 if (!rt6_is_dead(rt)) { 3970 if (!rt6_is_dead(rt)) {
3872 *weight += rt->fib6_nh.nh_weight; 3971 *weight += rt->fib6_nh.fib_nh_weight;
3873 upper_bound = DIV_ROUND_CLOSEST_ULL((u64) (*weight) << 31, 3972 upper_bound = DIV_ROUND_CLOSEST_ULL((u64) (*weight) << 31,
3874 total) - 1; 3973 total) - 1;
3875 } 3974 }
3876 atomic_set(&rt->fib6_nh.nh_upper_bound, upper_bound); 3975 atomic_set(&rt->fib6_nh.fib_nh_upper_bound, upper_bound);
3877} 3976}
3878 3977
3879static void rt6_multipath_upper_bound_set(struct fib6_info *rt, int total) 3978static void rt6_multipath_upper_bound_set(struct fib6_info *rt, int total)
@@ -3916,8 +4015,9 @@ static int fib6_ifup(struct fib6_info *rt, void *p_arg)
3916 const struct arg_netdev_event *arg = p_arg; 4015 const struct arg_netdev_event *arg = p_arg;
3917 struct net *net = dev_net(arg->dev); 4016 struct net *net = dev_net(arg->dev);
3918 4017
3919 if (rt != net->ipv6.fib6_null_entry && rt->fib6_nh.nh_dev == arg->dev) { 4018 if (rt != net->ipv6.fib6_null_entry &&
3920 rt->fib6_nh.nh_flags &= ~arg->nh_flags; 4019 rt->fib6_nh.fib_nh_dev == arg->dev) {
4020 rt->fib6_nh.fib_nh_flags &= ~arg->nh_flags;
3921 fib6_update_sernum_upto_root(net, rt); 4021 fib6_update_sernum_upto_root(net, rt);
3922 rt6_multipath_rebalance(rt); 4022 rt6_multipath_rebalance(rt);
3923 } 4023 }
@@ -3925,7 +4025,7 @@ static int fib6_ifup(struct fib6_info *rt, void *p_arg)
3925 return 0; 4025 return 0;
3926} 4026}
3927 4027
3928void rt6_sync_up(struct net_device *dev, unsigned int nh_flags) 4028void rt6_sync_up(struct net_device *dev, unsigned char nh_flags)
3929{ 4029{
3930 struct arg_netdev_event arg = { 4030 struct arg_netdev_event arg = {
3931 .dev = dev, 4031 .dev = dev,
@@ -3945,10 +4045,10 @@ static bool rt6_multipath_uses_dev(const struct fib6_info *rt,
3945{ 4045{
3946 struct fib6_info *iter; 4046 struct fib6_info *iter;
3947 4047
3948 if (rt->fib6_nh.nh_dev == dev) 4048 if (rt->fib6_nh.fib_nh_dev == dev)
3949 return true; 4049 return true;
3950 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) 4050 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings)
3951 if (iter->fib6_nh.nh_dev == dev) 4051 if (iter->fib6_nh.fib_nh_dev == dev)
3952 return true; 4052 return true;
3953 4053
3954 return false; 4054 return false;
@@ -3969,12 +4069,12 @@ static unsigned int rt6_multipath_dead_count(const struct fib6_info *rt,
3969 struct fib6_info *iter; 4069 struct fib6_info *iter;
3970 unsigned int dead = 0; 4070 unsigned int dead = 0;
3971 4071
3972 if (rt->fib6_nh.nh_dev == down_dev || 4072 if (rt->fib6_nh.fib_nh_dev == down_dev ||
3973 rt->fib6_nh.nh_flags & RTNH_F_DEAD) 4073 rt->fib6_nh.fib_nh_flags & RTNH_F_DEAD)
3974 dead++; 4074 dead++;
3975 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) 4075 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings)
3976 if (iter->fib6_nh.nh_dev == down_dev || 4076 if (iter->fib6_nh.fib_nh_dev == down_dev ||
3977 iter->fib6_nh.nh_flags & RTNH_F_DEAD) 4077 iter->fib6_nh.fib_nh_flags & RTNH_F_DEAD)
3978 dead++; 4078 dead++;
3979 4079
3980 return dead; 4080 return dead;
@@ -3982,15 +4082,15 @@ static unsigned int rt6_multipath_dead_count(const struct fib6_info *rt,
3982 4082
3983static void rt6_multipath_nh_flags_set(struct fib6_info *rt, 4083static void rt6_multipath_nh_flags_set(struct fib6_info *rt,
3984 const struct net_device *dev, 4084 const struct net_device *dev,
3985 unsigned int nh_flags) 4085 unsigned char nh_flags)
3986{ 4086{
3987 struct fib6_info *iter; 4087 struct fib6_info *iter;
3988 4088
3989 if (rt->fib6_nh.nh_dev == dev) 4089 if (rt->fib6_nh.fib_nh_dev == dev)
3990 rt->fib6_nh.nh_flags |= nh_flags; 4090 rt->fib6_nh.fib_nh_flags |= nh_flags;
3991 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) 4091 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings)
3992 if (iter->fib6_nh.nh_dev == dev) 4092 if (iter->fib6_nh.fib_nh_dev == dev)
3993 iter->fib6_nh.nh_flags |= nh_flags; 4093 iter->fib6_nh.fib_nh_flags |= nh_flags;
3994} 4094}
3995 4095
3996/* called with write lock held for table with rt */ 4096/* called with write lock held for table with rt */
@@ -4005,12 +4105,12 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg)
4005 4105
4006 switch (arg->event) { 4106 switch (arg->event) {
4007 case NETDEV_UNREGISTER: 4107 case NETDEV_UNREGISTER:
4008 return rt->fib6_nh.nh_dev == dev ? -1 : 0; 4108 return rt->fib6_nh.fib_nh_dev == dev ? -1 : 0;
4009 case NETDEV_DOWN: 4109 case NETDEV_DOWN:
4010 if (rt->should_flush) 4110 if (rt->should_flush)
4011 return -1; 4111 return -1;
4012 if (!rt->fib6_nsiblings) 4112 if (!rt->fib6_nsiblings)
4013 return rt->fib6_nh.nh_dev == dev ? -1 : 0; 4113 return rt->fib6_nh.fib_nh_dev == dev ? -1 : 0;
4014 if (rt6_multipath_uses_dev(rt, dev)) { 4114 if (rt6_multipath_uses_dev(rt, dev)) {
4015 unsigned int count; 4115 unsigned int count;
4016 4116
@@ -4026,10 +4126,10 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg)
4026 } 4126 }
4027 return -2; 4127 return -2;
4028 case NETDEV_CHANGE: 4128 case NETDEV_CHANGE:
4029 if (rt->fib6_nh.nh_dev != dev || 4129 if (rt->fib6_nh.fib_nh_dev != dev ||
4030 rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) 4130 rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST))
4031 break; 4131 break;
4032 rt->fib6_nh.nh_flags |= RTNH_F_LINKDOWN; 4132 rt->fib6_nh.fib_nh_flags |= RTNH_F_LINKDOWN;
4033 rt6_multipath_rebalance(rt); 4133 rt6_multipath_rebalance(rt);
4034 break; 4134 break;
4035 } 4135 }
@@ -4085,7 +4185,7 @@ static int rt6_mtu_change_route(struct fib6_info *rt, void *p_arg)
4085 Since RFC 1981 doesn't include administrative MTU increase 4185 Since RFC 1981 doesn't include administrative MTU increase
4086 update PMTU increase is a MUST. (i.e. jumbo frame) 4186 update PMTU increase is a MUST. (i.e. jumbo frame)
4087 */ 4187 */
4088 if (rt->fib6_nh.nh_dev == arg->dev && 4188 if (rt->fib6_nh.fib_nh_dev == arg->dev &&
4089 !fib6_metric_locked(rt, RTAX_MTU)) { 4189 !fib6_metric_locked(rt, RTAX_MTU)) {
4090 u32 mtu = rt->fib6_pmtu; 4190 u32 mtu = rt->fib6_pmtu;
4091 4191
@@ -4139,8 +4239,8 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
4139 unsigned int pref; 4239 unsigned int pref;
4140 int err; 4240 int err;
4141 4241
4142 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy, 4242 err = nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
4143 extack); 4243 rtm_ipv6_policy, extack);
4144 if (err < 0) 4244 if (err < 0)
4145 goto errout; 4245 goto errout;
4146 4246
@@ -4376,7 +4476,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
4376 goto cleanup; 4476 goto cleanup;
4377 } 4477 }
4378 4478
4379 rt->fib6_nh.nh_weight = rtnh->rtnh_hops + 1; 4479 rt->fib6_nh.fib_nh_weight = rtnh->rtnh_hops + 1;
4380 4480
4381 err = ip6_route_info_append(info->nl_net, &rt6_nh_list, 4481 err = ip6_route_info_append(info->nl_net, &rt6_nh_list,
4382 rt, &r_cfg); 4482 rt, &r_cfg);
@@ -4526,6 +4626,9 @@ static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
4526 if (err < 0) 4626 if (err < 0)
4527 return err; 4627 return err;
4528 4628
4629 if (cfg.fc_metric == 0)
4630 cfg.fc_metric = IP6_RT_PRIO_USER;
4631
4529 if (cfg.fc_mp) 4632 if (cfg.fc_mp)
4530 return ip6_route_multipath_add(&cfg, extack); 4633 return ip6_route_multipath_add(&cfg, extack);
4531 else 4634 else
@@ -4540,7 +4643,7 @@ static size_t rt6_nlmsg_size(struct fib6_info *rt)
4540 nexthop_len = nla_total_size(0) /* RTA_MULTIPATH */ 4643 nexthop_len = nla_total_size(0) /* RTA_MULTIPATH */
4541 + NLA_ALIGN(sizeof(struct rtnexthop)) 4644 + NLA_ALIGN(sizeof(struct rtnexthop))
4542 + nla_total_size(16) /* RTA_GATEWAY */ 4645 + nla_total_size(16) /* RTA_GATEWAY */
4543 + lwtunnel_get_encap_size(rt->fib6_nh.nh_lwtstate); 4646 + lwtunnel_get_encap_size(rt->fib6_nh.fib_nh_lws);
4544 4647
4545 nexthop_len *= rt->fib6_nsiblings; 4648 nexthop_len *= rt->fib6_nsiblings;
4546 } 4649 }
@@ -4558,77 +4661,10 @@ static size_t rt6_nlmsg_size(struct fib6_info *rt)
4558 + nla_total_size(sizeof(struct rta_cacheinfo)) 4661 + nla_total_size(sizeof(struct rta_cacheinfo))
4559 + nla_total_size(TCP_CA_NAME_MAX) /* RTAX_CC_ALGO */ 4662 + nla_total_size(TCP_CA_NAME_MAX) /* RTAX_CC_ALGO */
4560 + nla_total_size(1) /* RTA_PREF */ 4663 + nla_total_size(1) /* RTA_PREF */
4561 + lwtunnel_get_encap_size(rt->fib6_nh.nh_lwtstate) 4664 + lwtunnel_get_encap_size(rt->fib6_nh.fib_nh_lws)
4562 + nexthop_len; 4665 + nexthop_len;
4563} 4666}
4564 4667
4565static int rt6_nexthop_info(struct sk_buff *skb, struct fib6_info *rt,
4566 unsigned int *flags, bool skip_oif)
4567{
4568 if (rt->fib6_nh.nh_flags & RTNH_F_DEAD)
4569 *flags |= RTNH_F_DEAD;
4570
4571 if (rt->fib6_nh.nh_flags & RTNH_F_LINKDOWN) {
4572 *flags |= RTNH_F_LINKDOWN;
4573
4574 rcu_read_lock();
4575 if (fib6_ignore_linkdown(rt))
4576 *flags |= RTNH_F_DEAD;
4577 rcu_read_unlock();
4578 }
4579
4580 if (rt->fib6_flags & RTF_GATEWAY) {
4581 if (nla_put_in6_addr(skb, RTA_GATEWAY, &rt->fib6_nh.nh_gw) < 0)
4582 goto nla_put_failure;
4583 }
4584
4585 *flags |= (rt->fib6_nh.nh_flags & RTNH_F_ONLINK);
4586 if (rt->fib6_nh.nh_flags & RTNH_F_OFFLOAD)
4587 *flags |= RTNH_F_OFFLOAD;
4588
4589 /* not needed for multipath encoding b/c it has a rtnexthop struct */
4590 if (!skip_oif && rt->fib6_nh.nh_dev &&
4591 nla_put_u32(skb, RTA_OIF, rt->fib6_nh.nh_dev->ifindex))
4592 goto nla_put_failure;
4593
4594 if (rt->fib6_nh.nh_lwtstate &&
4595 lwtunnel_fill_encap(skb, rt->fib6_nh.nh_lwtstate) < 0)
4596 goto nla_put_failure;
4597
4598 return 0;
4599
4600nla_put_failure:
4601 return -EMSGSIZE;
4602}
4603
4604/* add multipath next hop */
4605static int rt6_add_nexthop(struct sk_buff *skb, struct fib6_info *rt)
4606{
4607 const struct net_device *dev = rt->fib6_nh.nh_dev;
4608 struct rtnexthop *rtnh;
4609 unsigned int flags = 0;
4610
4611 rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh));
4612 if (!rtnh)
4613 goto nla_put_failure;
4614
4615 rtnh->rtnh_hops = rt->fib6_nh.nh_weight - 1;
4616 rtnh->rtnh_ifindex = dev ? dev->ifindex : 0;
4617
4618 if (rt6_nexthop_info(skb, rt, &flags, true) < 0)
4619 goto nla_put_failure;
4620
4621 rtnh->rtnh_flags = flags;
4622
4623 /* length of rtnetlink header + attributes */
4624 rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh;
4625
4626 return 0;
4627
4628nla_put_failure:
4629 return -EMSGSIZE;
4630}
4631
4632static int rt6_fill_node(struct net *net, struct sk_buff *skb, 4668static int rt6_fill_node(struct net *net, struct sk_buff *skb,
4633 struct fib6_info *rt, struct dst_entry *dst, 4669 struct fib6_info *rt, struct dst_entry *dst,
4634 struct in6_addr *dest, struct in6_addr *src, 4670 struct in6_addr *dest, struct in6_addr *src,
@@ -4741,23 +4777,30 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
4741 struct fib6_info *sibling, *next_sibling; 4777 struct fib6_info *sibling, *next_sibling;
4742 struct nlattr *mp; 4778 struct nlattr *mp;
4743 4779
4744 mp = nla_nest_start(skb, RTA_MULTIPATH); 4780 mp = nla_nest_start_noflag(skb, RTA_MULTIPATH);
4745 if (!mp) 4781 if (!mp)
4746 goto nla_put_failure; 4782 goto nla_put_failure;
4747 4783
4748 if (rt6_add_nexthop(skb, rt) < 0) 4784 if (fib_add_nexthop(skb, &rt->fib6_nh.nh_common,
4785 rt->fib6_nh.fib_nh_weight) < 0)
4749 goto nla_put_failure; 4786 goto nla_put_failure;
4750 4787
4751 list_for_each_entry_safe(sibling, next_sibling, 4788 list_for_each_entry_safe(sibling, next_sibling,
4752 &rt->fib6_siblings, fib6_siblings) { 4789 &rt->fib6_siblings, fib6_siblings) {
4753 if (rt6_add_nexthop(skb, sibling) < 0) 4790 if (fib_add_nexthop(skb, &sibling->fib6_nh.nh_common,
4791 sibling->fib6_nh.fib_nh_weight) < 0)
4754 goto nla_put_failure; 4792 goto nla_put_failure;
4755 } 4793 }
4756 4794
4757 nla_nest_end(skb, mp); 4795 nla_nest_end(skb, mp);
4758 } else { 4796 } else {
4759 if (rt6_nexthop_info(skb, rt, &rtm->rtm_flags, false) < 0) 4797 unsigned char nh_flags = 0;
4798
4799 if (fib_nexthop_info(skb, &rt->fib6_nh.nh_common,
4800 &nh_flags, false) < 0)
4760 goto nla_put_failure; 4801 goto nla_put_failure;
4802
4803 rtm->rtm_flags |= nh_flags;
4761 } 4804 }
4762 4805
4763 if (rt6_flags & RTF_EXPIRES) { 4806 if (rt6_flags & RTF_EXPIRES) {
@@ -4783,7 +4826,7 @@ nla_put_failure:
4783static bool fib6_info_uses_dev(const struct fib6_info *f6i, 4826static bool fib6_info_uses_dev(const struct fib6_info *f6i,
4784 const struct net_device *dev) 4827 const struct net_device *dev)
4785{ 4828{
4786 if (f6i->fib6_nh.nh_dev == dev) 4829 if (f6i->fib6_nh.fib_nh_dev == dev)
4787 return true; 4830 return true;
4788 4831
4789 if (f6i->fib6_nsiblings) { 4832 if (f6i->fib6_nsiblings) {
@@ -4791,7 +4834,7 @@ static bool fib6_info_uses_dev(const struct fib6_info *f6i,
4791 4834
4792 list_for_each_entry_safe(sibling, next_sibling, 4835 list_for_each_entry_safe(sibling, next_sibling,
4793 &f6i->fib6_siblings, fib6_siblings) { 4836 &f6i->fib6_siblings, fib6_siblings) {
4794 if (sibling->fib6_nh.nh_dev == dev) 4837 if (sibling->fib6_nh.fib_nh_dev == dev)
4795 return true; 4838 return true;
4796 } 4839 }
4797 } 4840 }
@@ -4843,8 +4886,8 @@ static int inet6_rtm_valid_getroute_req(struct sk_buff *skb,
4843 } 4886 }
4844 4887
4845 if (!netlink_strict_get_check(skb)) 4888 if (!netlink_strict_get_check(skb))
4846 return nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, 4889 return nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
4847 rtm_ipv6_policy, extack); 4890 rtm_ipv6_policy, extack);
4848 4891
4849 rtm = nlmsg_data(nlh); 4892 rtm = nlmsg_data(nlh);
4850 if ((rtm->rtm_src_len && rtm->rtm_src_len != 128) || 4893 if ((rtm->rtm_src_len && rtm->rtm_src_len != 128) ||
@@ -4860,8 +4903,8 @@ static int inet6_rtm_valid_getroute_req(struct sk_buff *skb,
4860 return -EINVAL; 4903 return -EINVAL;
4861 } 4904 }
4862 4905
4863 err = nlmsg_parse_strict(nlh, sizeof(*rtm), tb, RTA_MAX, 4906 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX,
4864 rtm_ipv6_policy, extack); 4907 rtm_ipv6_policy, extack);
4865 if (err) 4908 if (err)
4866 return err; 4909 return err;
4867 4910
@@ -5013,16 +5056,20 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
5013 5056
5014 rcu_read_lock(); 5057 rcu_read_lock();
5015 from = rcu_dereference(rt->from); 5058 from = rcu_dereference(rt->from);
5016 5059 if (from) {
5017 if (fibmatch) 5060 if (fibmatch)
5018 err = rt6_fill_node(net, skb, from, NULL, NULL, NULL, iif, 5061 err = rt6_fill_node(net, skb, from, NULL, NULL, NULL,
5019 RTM_NEWROUTE, NETLINK_CB(in_skb).portid, 5062 iif, RTM_NEWROUTE,
5020 nlh->nlmsg_seq, 0); 5063 NETLINK_CB(in_skb).portid,
5021 else 5064 nlh->nlmsg_seq, 0);
5022 err = rt6_fill_node(net, skb, from, dst, &fl6.daddr, 5065 else
5023 &fl6.saddr, iif, RTM_NEWROUTE, 5066 err = rt6_fill_node(net, skb, from, dst, &fl6.daddr,
5024 NETLINK_CB(in_skb).portid, nlh->nlmsg_seq, 5067 &fl6.saddr, iif, RTM_NEWROUTE,
5025 0); 5068 NETLINK_CB(in_skb).portid,
5069 nlh->nlmsg_seq, 0);
5070 } else {
5071 err = -ENETUNREACH;
5072 }
5026 rcu_read_unlock(); 5073 rcu_read_unlock();
5027 5074
5028 if (err < 0) { 5075 if (err < 0) {
@@ -5076,7 +5123,7 @@ static int ip6_route_dev_notify(struct notifier_block *this,
5076 return NOTIFY_OK; 5123 return NOTIFY_OK;
5077 5124
5078 if (event == NETDEV_REGISTER) { 5125 if (event == NETDEV_REGISTER) {
5079 net->ipv6.fib6_null_entry->fib6_nh.nh_dev = dev; 5126 net->ipv6.fib6_null_entry->fib6_nh.fib_nh_dev = dev;
5080 net->ipv6.ip6_null_entry->dst.dev = dev; 5127 net->ipv6.ip6_null_entry->dst.dev = dev;
5081 net->ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(dev); 5128 net->ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(dev);
5082#ifdef CONFIG_IPV6_MULTIPLE_TABLES 5129#ifdef CONFIG_IPV6_MULTIPLE_TABLES
@@ -5411,7 +5458,7 @@ void __init ip6_route_init_special_entries(void)
5411 /* Registering of the loopback is done before this portion of code, 5458 /* Registering of the loopback is done before this portion of code,
5412 * the loopback reference in rt6_info will not be taken, do it 5459 * the loopback reference in rt6_info will not be taken, do it
5413 * manually for init_net */ 5460 * manually for init_net */
5414 init_net.ipv6.fib6_null_entry->fib6_nh.nh_dev = init_net.loopback_dev; 5461 init_net.ipv6.fib6_null_entry->fib6_nh.fib_nh_dev = init_net.loopback_dev;
5415 init_net.ipv6.ip6_null_entry->dst.dev = init_net.loopback_dev; 5462 init_net.ipv6.ip6_null_entry->dst.dev = init_net.loopback_dev;
5416 init_net.ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); 5463 init_net.ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev);
5417 #ifdef CONFIG_IPV6_MULTIPLE_TABLES 5464 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c
index 9b2f272ca164..0c5479ef9b38 100644
--- a/net/ipv6/seg6.c
+++ b/net/ipv6/seg6.c
@@ -398,28 +398,28 @@ static struct pernet_operations ip6_segments_ops = {
398static const struct genl_ops seg6_genl_ops[] = { 398static const struct genl_ops seg6_genl_ops[] = {
399 { 399 {
400 .cmd = SEG6_CMD_SETHMAC, 400 .cmd = SEG6_CMD_SETHMAC,
401 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
401 .doit = seg6_genl_sethmac, 402 .doit = seg6_genl_sethmac,
402 .policy = seg6_genl_policy,
403 .flags = GENL_ADMIN_PERM, 403 .flags = GENL_ADMIN_PERM,
404 }, 404 },
405 { 405 {
406 .cmd = SEG6_CMD_DUMPHMAC, 406 .cmd = SEG6_CMD_DUMPHMAC,
407 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
407 .start = seg6_genl_dumphmac_start, 408 .start = seg6_genl_dumphmac_start,
408 .dumpit = seg6_genl_dumphmac, 409 .dumpit = seg6_genl_dumphmac,
409 .done = seg6_genl_dumphmac_done, 410 .done = seg6_genl_dumphmac_done,
410 .policy = seg6_genl_policy,
411 .flags = GENL_ADMIN_PERM, 411 .flags = GENL_ADMIN_PERM,
412 }, 412 },
413 { 413 {
414 .cmd = SEG6_CMD_SET_TUNSRC, 414 .cmd = SEG6_CMD_SET_TUNSRC,
415 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
415 .doit = seg6_genl_set_tunsrc, 416 .doit = seg6_genl_set_tunsrc,
416 .policy = seg6_genl_policy,
417 .flags = GENL_ADMIN_PERM, 417 .flags = GENL_ADMIN_PERM,
418 }, 418 },
419 { 419 {
420 .cmd = SEG6_CMD_GET_TUNSRC, 420 .cmd = SEG6_CMD_GET_TUNSRC,
421 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
421 .doit = seg6_genl_get_tunsrc, 422 .doit = seg6_genl_get_tunsrc,
422 .policy = seg6_genl_policy,
423 .flags = GENL_ADMIN_PERM, 423 .flags = GENL_ADMIN_PERM,
424 }, 424 },
425}; 425};
@@ -429,6 +429,7 @@ static struct genl_family seg6_genl_family __ro_after_init = {
429 .name = SEG6_GENL_NAME, 429 .name = SEG6_GENL_NAME,
430 .version = SEG6_GENL_VERSION, 430 .version = SEG6_GENL_VERSION,
431 .maxattr = SEG6_ATTR_MAX, 431 .maxattr = SEG6_ATTR_MAX,
432 .policy = seg6_genl_policy,
432 .netnsok = true, 433 .netnsok = true,
433 .parallel_ops = true, 434 .parallel_ops = true,
434 .ops = seg6_genl_ops, 435 .ops = seg6_genl_ops,
diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index ee5403cbe655..7a525fda8978 100644
--- a/net/ipv6/seg6_iptunnel.c
+++ b/net/ipv6/seg6_iptunnel.c
@@ -396,8 +396,8 @@ static int seg6_build_state(struct nlattr *nla,
396 if (family != AF_INET && family != AF_INET6) 396 if (family != AF_INET && family != AF_INET6)
397 return -EINVAL; 397 return -EINVAL;
398 398
399 err = nla_parse_nested(tb, SEG6_IPTUNNEL_MAX, nla, 399 err = nla_parse_nested_deprecated(tb, SEG6_IPTUNNEL_MAX, nla,
400 seg6_iptunnel_policy, extack); 400 seg6_iptunnel_policy, extack);
401 401
402 if (err < 0) 402 if (err < 0)
403 return err; 403 return err;
diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
index 60325dbfe88b..78155fdb8c36 100644
--- a/net/ipv6/seg6_local.c
+++ b/net/ipv6/seg6_local.c
@@ -823,8 +823,9 @@ static int parse_nla_bpf(struct nlattr **attrs, struct seg6_local_lwt *slwt)
823 int ret; 823 int ret;
824 u32 fd; 824 u32 fd;
825 825
826 ret = nla_parse_nested(tb, SEG6_LOCAL_BPF_PROG_MAX, 826 ret = nla_parse_nested_deprecated(tb, SEG6_LOCAL_BPF_PROG_MAX,
827 attrs[SEG6_LOCAL_BPF], bpf_prog_policy, NULL); 827 attrs[SEG6_LOCAL_BPF],
828 bpf_prog_policy, NULL);
828 if (ret < 0) 829 if (ret < 0)
829 return ret; 830 return ret;
830 831
@@ -853,7 +854,7 @@ static int put_nla_bpf(struct sk_buff *skb, struct seg6_local_lwt *slwt)
853 if (!slwt->bpf.prog) 854 if (!slwt->bpf.prog)
854 return 0; 855 return 0;
855 856
856 nest = nla_nest_start(skb, SEG6_LOCAL_BPF); 857 nest = nla_nest_start_noflag(skb, SEG6_LOCAL_BPF);
857 if (!nest) 858 if (!nest)
858 return -EMSGSIZE; 859 return -EMSGSIZE;
859 860
@@ -959,8 +960,8 @@ static int seg6_local_build_state(struct nlattr *nla, unsigned int family,
959 if (family != AF_INET6) 960 if (family != AF_INET6)
960 return -EINVAL; 961 return -EINVAL;
961 962
962 err = nla_parse_nested(tb, SEG6_LOCAL_MAX, nla, seg6_local_policy, 963 err = nla_parse_nested_deprecated(tb, SEG6_LOCAL_MAX, nla,
963 extack); 964 seg6_local_policy, extack);
964 965
965 if (err < 0) 966 if (err < 0)
966 return err; 967 return err;
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index b2109b74857d..971d60bf9640 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -1084,7 +1084,7 @@ static void ipip6_tunnel_bind_dev(struct net_device *dev)
1084 if (!tdev && tunnel->parms.link) 1084 if (!tdev && tunnel->parms.link)
1085 tdev = __dev_get_by_index(tunnel->net, tunnel->parms.link); 1085 tdev = __dev_get_by_index(tunnel->net, tunnel->parms.link);
1086 1086
1087 if (tdev) { 1087 if (tdev && !netif_is_l3_master(tdev)) {
1088 int t_hlen = tunnel->hlen + sizeof(struct iphdr); 1088 int t_hlen = tunnel->hlen + sizeof(struct iphdr);
1089 1089
1090 dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr); 1090 dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr);
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 44d431849d39..beaf28456301 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -43,6 +43,7 @@
43#include <linux/ipv6.h> 43#include <linux/ipv6.h>
44#include <linux/icmpv6.h> 44#include <linux/icmpv6.h>
45#include <linux/random.h> 45#include <linux/random.h>
46#include <linux/indirect_call_wrapper.h>
46 47
47#include <net/tcp.h> 48#include <net/tcp.h>
48#include <net/ndisc.h> 49#include <net/ndisc.h>
@@ -90,6 +91,18 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(const struct sock *sk,
90} 91}
91#endif 92#endif
92 93
94/* Helper returning the inet6 address from a given tcp socket.
95 * It can be used in TCP stack instead of inet6_sk(sk).
96 * This avoids a dereference and allow compiler optimizations.
97 * It is a specialized version of inet6_sk_generic().
98 */
99static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk)
100{
101 unsigned int offset = sizeof(struct tcp6_sock) - sizeof(struct ipv6_pinfo);
102
103 return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
104}
105
93static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) 106static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
94{ 107{
95 struct dst_entry *dst = skb_dst(skb); 108 struct dst_entry *dst = skb_dst(skb);
@@ -99,7 +112,7 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99 112
100 sk->sk_rx_dst = dst; 113 sk->sk_rx_dst = dst;
101 inet_sk(sk)->rx_dst_ifindex = skb->skb_iif; 114 inet_sk(sk)->rx_dst_ifindex = skb->skb_iif;
102 inet6_sk(sk)->rx_dst_cookie = rt6_get_cookie(rt); 115 tcp_inet6_sk(sk)->rx_dst_cookie = rt6_get_cookie(rt);
103 } 116 }
104} 117}
105 118
@@ -138,7 +151,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
138 struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr; 151 struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr;
139 struct inet_sock *inet = inet_sk(sk); 152 struct inet_sock *inet = inet_sk(sk);
140 struct inet_connection_sock *icsk = inet_csk(sk); 153 struct inet_connection_sock *icsk = inet_csk(sk);
141 struct ipv6_pinfo *np = inet6_sk(sk); 154 struct ipv6_pinfo *np = tcp_inet6_sk(sk);
142 struct tcp_sock *tp = tcp_sk(sk); 155 struct tcp_sock *tp = tcp_sk(sk);
143 struct in6_addr *saddr = NULL, *final_p, final; 156 struct in6_addr *saddr = NULL, *final_p, final;
144 struct ipv6_txoptions *opt; 157 struct ipv6_txoptions *opt;
@@ -390,7 +403,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
390 if (sk->sk_state == TCP_CLOSE) 403 if (sk->sk_state == TCP_CLOSE)
391 goto out; 404 goto out;
392 405
393 if (ipv6_hdr(skb)->hop_limit < inet6_sk(sk)->min_hopcount) { 406 if (ipv6_hdr(skb)->hop_limit < tcp_inet6_sk(sk)->min_hopcount) {
394 __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); 407 __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP);
395 goto out; 408 goto out;
396 } 409 }
@@ -405,7 +418,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
405 goto out; 418 goto out;
406 } 419 }
407 420
408 np = inet6_sk(sk); 421 np = tcp_inet6_sk(sk);
409 422
410 if (type == NDISC_REDIRECT) { 423 if (type == NDISC_REDIRECT) {
411 if (!sock_owned_by_user(sk)) { 424 if (!sock_owned_by_user(sk)) {
@@ -478,7 +491,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
478 enum tcp_synack_type synack_type) 491 enum tcp_synack_type synack_type)
479{ 492{
480 struct inet_request_sock *ireq = inet_rsk(req); 493 struct inet_request_sock *ireq = inet_rsk(req);
481 struct ipv6_pinfo *np = inet6_sk(sk); 494 struct ipv6_pinfo *np = tcp_inet6_sk(sk);
482 struct ipv6_txoptions *opt; 495 struct ipv6_txoptions *opt;
483 struct flowi6 *fl6 = &fl->u.ip6; 496 struct flowi6 *fl6 = &fl->u.ip6;
484 struct sk_buff *skb; 497 struct sk_buff *skb;
@@ -737,7 +750,7 @@ static void tcp_v6_init_req(struct request_sock *req,
737{ 750{
738 bool l3_slave = ipv6_l3mdev_skb(TCP_SKB_CB(skb)->header.h6.flags); 751 bool l3_slave = ipv6_l3mdev_skb(TCP_SKB_CB(skb)->header.h6.flags);
739 struct inet_request_sock *ireq = inet_rsk(req); 752 struct inet_request_sock *ireq = inet_rsk(req);
740 const struct ipv6_pinfo *np = inet6_sk(sk_listener); 753 const struct ipv6_pinfo *np = tcp_inet6_sk(sk_listener);
741 754
742 ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr; 755 ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr;
743 ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr; 756 ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
@@ -1066,9 +1079,8 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
1066{ 1079{
1067 struct inet_request_sock *ireq; 1080 struct inet_request_sock *ireq;
1068 struct ipv6_pinfo *newnp; 1081 struct ipv6_pinfo *newnp;
1069 const struct ipv6_pinfo *np = inet6_sk(sk); 1082 const struct ipv6_pinfo *np = tcp_inet6_sk(sk);
1070 struct ipv6_txoptions *opt; 1083 struct ipv6_txoptions *opt;
1071 struct tcp6_sock *newtcp6sk;
1072 struct inet_sock *newinet; 1084 struct inet_sock *newinet;
1073 struct tcp_sock *newtp; 1085 struct tcp_sock *newtp;
1074 struct sock *newsk; 1086 struct sock *newsk;
@@ -1088,11 +1100,10 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
1088 if (!newsk) 1100 if (!newsk)
1089 return NULL; 1101 return NULL;
1090 1102
1091 newtcp6sk = (struct tcp6_sock *)newsk; 1103 inet_sk(newsk)->pinet6 = tcp_inet6_sk(newsk);
1092 inet_sk(newsk)->pinet6 = &newtcp6sk->inet6;
1093 1104
1094 newinet = inet_sk(newsk); 1105 newinet = inet_sk(newsk);
1095 newnp = inet6_sk(newsk); 1106 newnp = tcp_inet6_sk(newsk);
1096 newtp = tcp_sk(newsk); 1107 newtp = tcp_sk(newsk);
1097 1108
1098 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1109 memcpy(newnp, np, sizeof(struct ipv6_pinfo));
@@ -1156,12 +1167,11 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
1156 ip6_dst_store(newsk, dst, NULL, NULL); 1167 ip6_dst_store(newsk, dst, NULL, NULL);
1157 inet6_sk_rx_dst_set(newsk, skb); 1168 inet6_sk_rx_dst_set(newsk, skb);
1158 1169
1159 newtcp6sk = (struct tcp6_sock *)newsk; 1170 inet_sk(newsk)->pinet6 = tcp_inet6_sk(newsk);
1160 inet_sk(newsk)->pinet6 = &newtcp6sk->inet6;
1161 1171
1162 newtp = tcp_sk(newsk); 1172 newtp = tcp_sk(newsk);
1163 newinet = inet_sk(newsk); 1173 newinet = inet_sk(newsk);
1164 newnp = inet6_sk(newsk); 1174 newnp = tcp_inet6_sk(newsk);
1165 1175
1166 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1176 memcpy(newnp, np, sizeof(struct ipv6_pinfo));
1167 1177
@@ -1276,9 +1286,9 @@ out:
1276 */ 1286 */
1277static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) 1287static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
1278{ 1288{
1279 struct ipv6_pinfo *np = inet6_sk(sk); 1289 struct ipv6_pinfo *np = tcp_inet6_sk(sk);
1280 struct tcp_sock *tp;
1281 struct sk_buff *opt_skb = NULL; 1290 struct sk_buff *opt_skb = NULL;
1291 struct tcp_sock *tp;
1282 1292
1283 /* Imagine: socket is IPv6. IPv4 packet arrives, 1293 /* Imagine: socket is IPv6. IPv4 packet arrives,
1284 goes to IPv4 receive handler and backlogged. 1294 goes to IPv4 receive handler and backlogged.
@@ -1426,8 +1436,9 @@ static void tcp_v6_fill_cb(struct sk_buff *skb, const struct ipv6hdr *hdr,
1426 skb->tstamp || skb_hwtstamps(skb)->hwtstamp; 1436 skb->tstamp || skb_hwtstamps(skb)->hwtstamp;
1427} 1437}
1428 1438
1429static int tcp_v6_rcv(struct sk_buff *skb) 1439INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
1430{ 1440{
1441 struct sk_buff *skb_to_free;
1431 int sdif = inet6_sdif(skb); 1442 int sdif = inet6_sdif(skb);
1432 const struct tcphdr *th; 1443 const struct tcphdr *th;
1433 const struct ipv6hdr *hdr; 1444 const struct ipv6hdr *hdr;
@@ -1524,7 +1535,7 @@ process:
1524 return 0; 1535 return 0;
1525 } 1536 }
1526 } 1537 }
1527 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) { 1538 if (hdr->hop_limit < tcp_inet6_sk(sk)->min_hopcount) {
1528 __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP); 1539 __NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP);
1529 goto discard_and_relse; 1540 goto discard_and_relse;
1530 } 1541 }
@@ -1554,12 +1565,17 @@ process:
1554 tcp_segs_in(tcp_sk(sk), skb); 1565 tcp_segs_in(tcp_sk(sk), skb);
1555 ret = 0; 1566 ret = 0;
1556 if (!sock_owned_by_user(sk)) { 1567 if (!sock_owned_by_user(sk)) {
1568 skb_to_free = sk->sk_rx_skb_cache;
1569 sk->sk_rx_skb_cache = NULL;
1557 ret = tcp_v6_do_rcv(sk, skb); 1570 ret = tcp_v6_do_rcv(sk, skb);
1558 } else if (tcp_add_backlog(sk, skb)) { 1571 } else {
1559 goto discard_and_relse; 1572 if (tcp_add_backlog(sk, skb))
1573 goto discard_and_relse;
1574 skb_to_free = NULL;
1560 } 1575 }
1561 bh_unlock_sock(sk); 1576 bh_unlock_sock(sk);
1562 1577 if (skb_to_free)
1578 __kfree_skb(skb_to_free);
1563put_and_return: 1579put_and_return:
1564 if (refcounted) 1580 if (refcounted)
1565 sock_put(sk); 1581 sock_put(sk);
@@ -1639,7 +1655,7 @@ do_time_wait:
1639 goto discard_it; 1655 goto discard_it;
1640} 1656}
1641 1657
1642static void tcp_v6_early_demux(struct sk_buff *skb) 1658INDIRECT_CALLABLE_SCOPE void tcp_v6_early_demux(struct sk_buff *skb)
1643{ 1659{
1644 const struct ipv6hdr *hdr; 1660 const struct ipv6hdr *hdr;
1645 const struct tcphdr *th; 1661 const struct tcphdr *th;
@@ -1669,7 +1685,7 @@ static void tcp_v6_early_demux(struct sk_buff *skb)
1669 struct dst_entry *dst = READ_ONCE(sk->sk_rx_dst); 1685 struct dst_entry *dst = READ_ONCE(sk->sk_rx_dst);
1670 1686
1671 if (dst) 1687 if (dst)
1672 dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie); 1688 dst = dst_check(dst, tcp_inet6_sk(sk)->rx_dst_cookie);
1673 if (dst && 1689 if (dst &&
1674 inet_sk(sk)->rx_dst_ifindex == skb->skb_iif) 1690 inet_sk(sk)->rx_dst_ifindex == skb->skb_iif)
1675 skb_dst_set_noref(skb, dst); 1691 skb_dst_set_noref(skb, dst);
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index b444483cdb2b..07fa579dfb96 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -36,6 +36,7 @@
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/indirect_call_wrapper.h>
39 40
40#include <net/addrconf.h> 41#include <net/addrconf.h>
41#include <net/ndisc.h> 42#include <net/ndisc.h>
@@ -285,8 +286,7 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
285 struct inet_sock *inet = inet_sk(sk); 286 struct inet_sock *inet = inet_sk(sk);
286 struct sk_buff *skb; 287 struct sk_buff *skb;
287 unsigned int ulen, copied; 288 unsigned int ulen, copied;
288 int peeked, peeking, off; 289 int off, err, peeking = flags & MSG_PEEK;
289 int err;
290 int is_udplite = IS_UDPLITE(sk); 290 int is_udplite = IS_UDPLITE(sk);
291 struct udp_mib __percpu *mib; 291 struct udp_mib __percpu *mib;
292 bool checksum_valid = false; 292 bool checksum_valid = false;
@@ -299,9 +299,8 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
299 return ipv6_recv_rxpmtu(sk, msg, len, addr_len); 299 return ipv6_recv_rxpmtu(sk, msg, len, addr_len);
300 300
301try_again: 301try_again:
302 peeking = flags & MSG_PEEK;
303 off = sk_peek_offset(sk, flags); 302 off = sk_peek_offset(sk, flags);
304 skb = __skb_recv_udp(sk, flags, noblock, &peeked, &off, &err); 303 skb = __skb_recv_udp(sk, flags, noblock, &off, &err);
305 if (!skb) 304 if (!skb)
306 return err; 305 return err;
307 306
@@ -340,14 +339,14 @@ try_again:
340 goto csum_copy_err; 339 goto csum_copy_err;
341 } 340 }
342 if (unlikely(err)) { 341 if (unlikely(err)) {
343 if (!peeked) { 342 if (!peeking) {
344 atomic_inc(&sk->sk_drops); 343 atomic_inc(&sk->sk_drops);
345 SNMP_INC_STATS(mib, UDP_MIB_INERRORS); 344 SNMP_INC_STATS(mib, UDP_MIB_INERRORS);
346 } 345 }
347 kfree_skb(skb); 346 kfree_skb(skb);
348 return err; 347 return err;
349 } 348 }
350 if (!peeked) 349 if (!peeking)
351 SNMP_INC_STATS(mib, UDP_MIB_INDATAGRAMS); 350 SNMP_INC_STATS(mib, UDP_MIB_INDATAGRAMS);
352 351
353 sock_recv_ts_and_drops(msg, sk, skb); 352 sock_recv_ts_and_drops(msg, sk, skb);
@@ -982,7 +981,7 @@ static struct sock *__udp6_lib_demux_lookup(struct net *net,
982 return NULL; 981 return NULL;
983} 982}
984 983
985static void udp_v6_early_demux(struct sk_buff *skb) 984INDIRECT_CALLABLE_SCOPE void udp_v6_early_demux(struct sk_buff *skb)
986{ 985{
987 struct net *net = dev_net(skb->dev); 986 struct net *net = dev_net(skb->dev);
988 const struct udphdr *uh; 987 const struct udphdr *uh;
@@ -1023,7 +1022,7 @@ static void udp_v6_early_demux(struct sk_buff *skb)
1023 } 1022 }
1024} 1023}
1025 1024
1026static __inline__ int udpv6_rcv(struct sk_buff *skb) 1025INDIRECT_CALLABLE_SCOPE int udpv6_rcv(struct sk_buff *skb)
1027{ 1026{
1028 return __udp6_lib_rcv(skb, &udp_table, IPPROTO_UDP); 1027 return __udp6_lib_rcv(skb, &udp_table, IPPROTO_UDP);
1029} 1028}
@@ -1047,6 +1046,8 @@ static void udp_v6_flush_pending_frames(struct sock *sk)
1047static int udpv6_pre_connect(struct sock *sk, struct sockaddr *uaddr, 1046static int udpv6_pre_connect(struct sock *sk, struct sockaddr *uaddr,
1048 int addr_len) 1047 int addr_len)
1049{ 1048{
1049 if (addr_len < offsetofend(struct sockaddr, sa_family))
1050 return -EINVAL;
1050 /* The following checks are replicated from __ip6_datagram_connect() 1051 /* The following checks are replicated from __ip6_datagram_connect()
1051 * and intended to prevent BPF program called below from accessing 1052 * and intended to prevent BPF program called below from accessing
1052 * bytes that are out of the bound specified by user in addr_len. 1053 * bytes that are out of the bound specified by user in addr_len.
diff --git a/net/ipv6/xfrm6_mode_beet.c b/net/ipv6/xfrm6_mode_beet.c
deleted file mode 100644
index 57fd314ec2b8..000000000000
--- a/net/ipv6/xfrm6_mode_beet.c
+++ /dev/null
@@ -1,131 +0,0 @@
1/*
2 * xfrm6_mode_beet.c - BEET mode encapsulation for IPv6.
3 *
4 * Copyright (c) 2006 Diego Beltrami <diego.beltrami@gmail.com>
5 * Miika Komu <miika@iki.fi>
6 * Herbert Xu <herbert@gondor.apana.org.au>
7 * Abhinav Pathak <abhinav.pathak@hiit.fi>
8 * Jeff Ahrenholz <ahrenholz@gmail.com>
9 */
10
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/skbuff.h>
15#include <linux/stringify.h>
16#include <net/dsfield.h>
17#include <net/dst.h>
18#include <net/inet_ecn.h>
19#include <net/ipv6.h>
20#include <net/xfrm.h>
21
22static void xfrm6_beet_make_header(struct sk_buff *skb)
23{
24 struct ipv6hdr *iph = ipv6_hdr(skb);
25
26 iph->version = 6;
27
28 memcpy(iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
29 sizeof(iph->flow_lbl));
30 iph->nexthdr = XFRM_MODE_SKB_CB(skb)->protocol;
31
32 ipv6_change_dsfield(iph, 0, XFRM_MODE_SKB_CB(skb)->tos);
33 iph->hop_limit = XFRM_MODE_SKB_CB(skb)->ttl;
34}
35
36/* Add encapsulation header.
37 *
38 * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
39 */
40static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb)
41{
42 struct ipv6hdr *top_iph;
43 struct ip_beet_phdr *ph;
44 int optlen, hdr_len;
45
46 hdr_len = 0;
47 optlen = XFRM_MODE_SKB_CB(skb)->optlen;
48 if (unlikely(optlen))
49 hdr_len += IPV4_BEET_PHMAXLEN - (optlen & 4);
50
51 skb_set_network_header(skb, -x->props.header_len - hdr_len);
52 if (x->sel.family != AF_INET6)
53 skb->network_header += IPV4_BEET_PHMAXLEN;
54 skb->mac_header = skb->network_header +
55 offsetof(struct ipv6hdr, nexthdr);
56 skb->transport_header = skb->network_header + sizeof(*top_iph);
57 ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdr_len);
58
59 xfrm6_beet_make_header(skb);
60
61 top_iph = ipv6_hdr(skb);
62 if (unlikely(optlen)) {
63
64 BUG_ON(optlen < 0);
65
66 ph->padlen = 4 - (optlen & 4);
67 ph->hdrlen = optlen / 8;
68 ph->nexthdr = top_iph->nexthdr;
69 if (ph->padlen)
70 memset(ph + 1, IPOPT_NOP, ph->padlen);
71
72 top_iph->nexthdr = IPPROTO_BEETPH;
73 }
74
75 top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
76 top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
77 return 0;
78}
79
80static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb)
81{
82 struct ipv6hdr *ip6h;
83 int size = sizeof(struct ipv6hdr);
84 int err;
85
86 err = skb_cow_head(skb, size + skb->mac_len);
87 if (err)
88 goto out;
89
90 __skb_push(skb, size);
91 skb_reset_network_header(skb);
92 skb_mac_header_rebuild(skb);
93
94 xfrm6_beet_make_header(skb);
95
96 ip6h = ipv6_hdr(skb);
97 ip6h->payload_len = htons(skb->len - size);
98 ip6h->daddr = x->sel.daddr.in6;
99 ip6h->saddr = x->sel.saddr.in6;
100 err = 0;
101out:
102 return err;
103}
104
105static struct xfrm_mode xfrm6_beet_mode = {
106 .input2 = xfrm6_beet_input,
107 .input = xfrm_prepare_input,
108 .output2 = xfrm6_beet_output,
109 .output = xfrm6_prepare_output,
110 .owner = THIS_MODULE,
111 .encap = XFRM_MODE_BEET,
112 .flags = XFRM_MODE_FLAG_TUNNEL,
113};
114
115static int __init xfrm6_beet_init(void)
116{
117 return xfrm_register_mode(&xfrm6_beet_mode, AF_INET6);
118}
119
120static void __exit xfrm6_beet_exit(void)
121{
122 int err;
123
124 err = xfrm_unregister_mode(&xfrm6_beet_mode, AF_INET6);
125 BUG_ON(err);
126}
127
128module_init(xfrm6_beet_init);
129module_exit(xfrm6_beet_exit);
130MODULE_LICENSE("GPL");
131MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_BEET);
diff --git a/net/ipv6/xfrm6_mode_ro.c b/net/ipv6/xfrm6_mode_ro.c
deleted file mode 100644
index da28e4407b8f..000000000000
--- a/net/ipv6/xfrm6_mode_ro.c
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * xfrm6_mode_ro.c - Route optimization mode for IPv6.
3 *
4 * Copyright (C)2003-2006 Helsinki University of Technology
5 * Copyright (C)2003-2006 USAGI/WIDE Project
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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20/*
21 * Authors:
22 * Noriaki TAKAMIYA @USAGI
23 * Masahide NAKAMURA @USAGI
24 */
25
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/skbuff.h>
30#include <linux/spinlock.h>
31#include <linux/stringify.h>
32#include <linux/time.h>
33#include <net/ipv6.h>
34#include <net/xfrm.h>
35
36/* Add route optimization header space.
37 *
38 * The IP header and mutable extension headers will be moved forward to make
39 * space for the route optimization header.
40 */
41static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
42{
43 struct ipv6hdr *iph;
44 u8 *prevhdr;
45 int hdr_len;
46
47 iph = ipv6_hdr(skb);
48
49 hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
50 if (hdr_len < 0)
51 return hdr_len;
52 skb_set_mac_header(skb, (prevhdr - x->props.header_len) - skb->data);
53 skb_set_network_header(skb, -x->props.header_len);
54 skb->transport_header = skb->network_header + hdr_len;
55 __skb_pull(skb, hdr_len);
56 memmove(ipv6_hdr(skb), iph, hdr_len);
57
58 x->lastused = ktime_get_real_seconds();
59
60 return 0;
61}
62
63static struct xfrm_mode xfrm6_ro_mode = {
64 .output = xfrm6_ro_output,
65 .owner = THIS_MODULE,
66 .encap = XFRM_MODE_ROUTEOPTIMIZATION,
67};
68
69static int __init xfrm6_ro_init(void)
70{
71 return xfrm_register_mode(&xfrm6_ro_mode, AF_INET6);
72}
73
74static void __exit xfrm6_ro_exit(void)
75{
76 int err;
77
78 err = xfrm_unregister_mode(&xfrm6_ro_mode, AF_INET6);
79 BUG_ON(err);
80}
81
82module_init(xfrm6_ro_init);
83module_exit(xfrm6_ro_exit);
84MODULE_LICENSE("GPL");
85MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_ROUTEOPTIMIZATION);
diff --git a/net/ipv6/xfrm6_mode_transport.c b/net/ipv6/xfrm6_mode_transport.c
deleted file mode 100644
index 3c29da5defe6..000000000000
--- a/net/ipv6/xfrm6_mode_transport.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/*
2 * xfrm6_mode_transport.c - Transport mode encapsulation for IPv6.
3 *
4 * Copyright (C) 2002 USAGI/WIDE Project
5 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
6 */
7
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/skbuff.h>
12#include <linux/stringify.h>
13#include <net/dst.h>
14#include <net/ipv6.h>
15#include <net/xfrm.h>
16#include <net/protocol.h>
17
18/* Add encapsulation header.
19 *
20 * The IP header and mutable extension headers will be moved forward to make
21 * space for the encapsulation header.
22 */
23static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
24{
25 struct ipv6hdr *iph;
26 u8 *prevhdr;
27 int hdr_len;
28
29 iph = ipv6_hdr(skb);
30 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
31
32 hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
33 if (hdr_len < 0)
34 return hdr_len;
35 skb_set_mac_header(skb, (prevhdr - x->props.header_len) - skb->data);
36 skb_set_network_header(skb, -x->props.header_len);
37 skb->transport_header = skb->network_header + hdr_len;
38 __skb_pull(skb, hdr_len);
39 memmove(ipv6_hdr(skb), iph, hdr_len);
40 return 0;
41}
42
43/* Remove encapsulation header.
44 *
45 * The IP header will be moved over the top of the encapsulation header.
46 *
47 * On entry, skb->h shall point to where the IP header should be and skb->nh
48 * shall be set to where the IP header currently is. skb->data shall point
49 * to the start of the payload.
50 */
51static int xfrm6_transport_input(struct xfrm_state *x, struct sk_buff *skb)
52{
53 int ihl = skb->data - skb_transport_header(skb);
54
55 if (skb->transport_header != skb->network_header) {
56 memmove(skb_transport_header(skb),
57 skb_network_header(skb), ihl);
58 skb->network_header = skb->transport_header;
59 }
60 ipv6_hdr(skb)->payload_len = htons(skb->len + ihl -
61 sizeof(struct ipv6hdr));
62 skb_reset_transport_header(skb);
63 return 0;
64}
65
66static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
67 struct sk_buff *skb,
68 netdev_features_t features)
69{
70 const struct net_offload *ops;
71 struct sk_buff *segs = ERR_PTR(-EINVAL);
72 struct xfrm_offload *xo = xfrm_offload(skb);
73
74 skb->transport_header += x->props.header_len;
75 ops = rcu_dereference(inet6_offloads[xo->proto]);
76 if (likely(ops && ops->callbacks.gso_segment))
77 segs = ops->callbacks.gso_segment(skb, features);
78
79 return segs;
80}
81
82static void xfrm6_transport_xmit(struct xfrm_state *x, struct sk_buff *skb)
83{
84 struct xfrm_offload *xo = xfrm_offload(skb);
85
86 skb_reset_mac_len(skb);
87 pskb_pull(skb, skb->mac_len + sizeof(struct ipv6hdr) + x->props.header_len);
88
89 if (xo->flags & XFRM_GSO_SEGMENT) {
90 skb_reset_transport_header(skb);
91 skb->transport_header -= x->props.header_len;
92 }
93}
94
95
96static struct xfrm_mode xfrm6_transport_mode = {
97 .input = xfrm6_transport_input,
98 .output = xfrm6_transport_output,
99 .gso_segment = xfrm4_transport_gso_segment,
100 .xmit = xfrm6_transport_xmit,
101 .owner = THIS_MODULE,
102 .encap = XFRM_MODE_TRANSPORT,
103};
104
105static int __init xfrm6_transport_init(void)
106{
107 return xfrm_register_mode(&xfrm6_transport_mode, AF_INET6);
108}
109
110static void __exit xfrm6_transport_exit(void)
111{
112 int err;
113
114 err = xfrm_unregister_mode(&xfrm6_transport_mode, AF_INET6);
115 BUG_ON(err);
116}
117
118module_init(xfrm6_transport_init);
119module_exit(xfrm6_transport_exit);
120MODULE_LICENSE("GPL");
121MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_TRANSPORT);
diff --git a/net/ipv6/xfrm6_mode_tunnel.c b/net/ipv6/xfrm6_mode_tunnel.c
deleted file mode 100644
index de1b0b8c53b0..000000000000
--- a/net/ipv6/xfrm6_mode_tunnel.c
+++ /dev/null
@@ -1,151 +0,0 @@
1/*
2 * xfrm6_mode_tunnel.c - Tunnel mode encapsulation for IPv6.
3 *
4 * Copyright (C) 2002 USAGI/WIDE Project
5 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
6 */
7
8#include <linux/gfp.h>
9#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/skbuff.h>
13#include <linux/stringify.h>
14#include <net/dsfield.h>
15#include <net/dst.h>
16#include <net/inet_ecn.h>
17#include <net/ip6_route.h>
18#include <net/ipv6.h>
19#include <net/xfrm.h>
20
21static inline void ipip6_ecn_decapsulate(struct sk_buff *skb)
22{
23 struct ipv6hdr *inner_iph = ipipv6_hdr(skb);
24
25 if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
26 IP6_ECN_set_ce(skb, inner_iph);
27}
28
29/* Add encapsulation header.
30 *
31 * The top IP header will be constructed per RFC 2401.
32 */
33static int xfrm6_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
34{
35 struct dst_entry *dst = skb_dst(skb);
36 struct ipv6hdr *top_iph;
37 int dsfield;
38
39 skb_set_inner_network_header(skb, skb_network_offset(skb));
40 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
41
42 skb_set_network_header(skb, -x->props.header_len);
43 skb->mac_header = skb->network_header +
44 offsetof(struct ipv6hdr, nexthdr);
45 skb->transport_header = skb->network_header + sizeof(*top_iph);
46 top_iph = ipv6_hdr(skb);
47
48 top_iph->version = 6;
49
50 memcpy(top_iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
51 sizeof(top_iph->flow_lbl));
52 top_iph->nexthdr = xfrm_af2proto(skb_dst(skb)->ops->family);
53
54 if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
55 dsfield = 0;
56 else
57 dsfield = XFRM_MODE_SKB_CB(skb)->tos;
58 dsfield = INET_ECN_encapsulate(dsfield, XFRM_MODE_SKB_CB(skb)->tos);
59 if (x->props.flags & XFRM_STATE_NOECN)
60 dsfield &= ~INET_ECN_MASK;
61 ipv6_change_dsfield(top_iph, 0, dsfield);
62 top_iph->hop_limit = ip6_dst_hoplimit(xfrm_dst_child(dst));
63 top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
64 top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
65 return 0;
66}
67
68#define for_each_input_rcu(head, handler) \
69 for (handler = rcu_dereference(head); \
70 handler != NULL; \
71 handler = rcu_dereference(handler->next))
72
73
74static int xfrm6_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
75{
76 int err = -EINVAL;
77
78 if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPV6)
79 goto out;
80 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
81 goto out;
82
83 err = skb_unclone(skb, GFP_ATOMIC);
84 if (err)
85 goto out;
86
87 if (x->props.flags & XFRM_STATE_DECAP_DSCP)
88 ipv6_copy_dscp(ipv6_get_dsfield(ipv6_hdr(skb)),
89 ipipv6_hdr(skb));
90 if (!(x->props.flags & XFRM_STATE_NOECN))
91 ipip6_ecn_decapsulate(skb);
92
93 skb_reset_network_header(skb);
94 skb_mac_header_rebuild(skb);
95 if (skb->mac_len)
96 eth_hdr(skb)->h_proto = skb->protocol;
97
98 err = 0;
99
100out:
101 return err;
102}
103
104static struct sk_buff *xfrm6_mode_tunnel_gso_segment(struct xfrm_state *x,
105 struct sk_buff *skb,
106 netdev_features_t features)
107{
108 __skb_push(skb, skb->mac_len);
109 return skb_mac_gso_segment(skb, features);
110}
111
112static void xfrm6_mode_tunnel_xmit(struct xfrm_state *x, struct sk_buff *skb)
113{
114 struct xfrm_offload *xo = xfrm_offload(skb);
115
116 if (xo->flags & XFRM_GSO_SEGMENT)
117 skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
118
119 skb_reset_mac_len(skb);
120 pskb_pull(skb, skb->mac_len + x->props.header_len);
121}
122
123static struct xfrm_mode xfrm6_tunnel_mode = {
124 .input2 = xfrm6_mode_tunnel_input,
125 .input = xfrm_prepare_input,
126 .output2 = xfrm6_mode_tunnel_output,
127 .output = xfrm6_prepare_output,
128 .gso_segment = xfrm6_mode_tunnel_gso_segment,
129 .xmit = xfrm6_mode_tunnel_xmit,
130 .owner = THIS_MODULE,
131 .encap = XFRM_MODE_TUNNEL,
132 .flags = XFRM_MODE_FLAG_TUNNEL,
133};
134
135static int __init xfrm6_mode_tunnel_init(void)
136{
137 return xfrm_register_mode(&xfrm6_tunnel_mode, AF_INET6);
138}
139
140static void __exit xfrm6_mode_tunnel_exit(void)
141{
142 int err;
143
144 err = xfrm_unregister_mode(&xfrm6_tunnel_mode, AF_INET6);
145 BUG_ON(err);
146}
147
148module_init(xfrm6_mode_tunnel_init);
149module_exit(xfrm6_mode_tunnel_exit);
150MODULE_LICENSE("GPL");
151MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_TUNNEL);
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c
index 6a74080005cf..8ad5e54eb8ca 100644
--- a/net/ipv6/xfrm6_output.c
+++ b/net/ipv6/xfrm6_output.c
@@ -111,21 +111,6 @@ int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb)
111 return xfrm6_extract_header(skb); 111 return xfrm6_extract_header(skb);
112} 112}
113 113
114int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
115{
116 int err;
117
118 err = xfrm_inner_extract_output(x, skb);
119 if (err)
120 return err;
121
122 skb->ignore_df = 1;
123 skb->protocol = htons(ETH_P_IPV6);
124
125 return x->outer_mode->output2(x, skb);
126}
127EXPORT_SYMBOL(xfrm6_prepare_output);
128
129int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb) 114int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb)
130{ 115{
131 memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); 116 memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
@@ -137,11 +122,28 @@ int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb)
137 return xfrm_output(sk, skb); 122 return xfrm_output(sk, skb);
138} 123}
139 124
125static int __xfrm6_output_state_finish(struct xfrm_state *x, struct sock *sk,
126 struct sk_buff *skb)
127{
128 const struct xfrm_state_afinfo *afinfo;
129 int ret = -EAFNOSUPPORT;
130
131 rcu_read_lock();
132 afinfo = xfrm_state_afinfo_get_rcu(x->outer_mode.family);
133 if (likely(afinfo))
134 ret = afinfo->output_finish(sk, skb);
135 else
136 kfree_skb(skb);
137 rcu_read_unlock();
138
139 return ret;
140}
141
140static int __xfrm6_output_finish(struct net *net, struct sock *sk, struct sk_buff *skb) 142static int __xfrm6_output_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
141{ 143{
142 struct xfrm_state *x = skb_dst(skb)->xfrm; 144 struct xfrm_state *x = skb_dst(skb)->xfrm;
143 145
144 return x->outer_mode->afinfo->output_finish(sk, skb); 146 return __xfrm6_output_state_finish(x, sk, skb);
145} 147}
146 148
147static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb) 149static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
@@ -183,7 +185,7 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
183 __xfrm6_output_finish); 185 __xfrm6_output_finish);
184 186
185skip_frag: 187skip_frag:
186 return x->outer_mode->afinfo->output_finish(sk, skb); 188 return __xfrm6_output_state_finish(x, sk, skb);
187} 189}
188 190
189int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb) 191int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index 769f8f78d3b8..699e0730ce8e 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -22,9 +22,6 @@
22#include <net/ipv6.h> 22#include <net/ipv6.h>
23#include <net/ip6_route.h> 23#include <net/ip6_route.h>
24#include <net/l3mdev.h> 24#include <net/l3mdev.h>
25#if IS_ENABLED(CONFIG_IPV6_MIP6)
26#include <net/mip6.h>
27#endif
28 25
29static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif, 26static struct dst_entry *xfrm6_dst_lookup(struct net *net, int tos, int oif,
30 const xfrm_address_t *saddr, 27 const xfrm_address_t *saddr,
@@ -71,24 +68,6 @@ static int xfrm6_get_saddr(struct net *net, int oif,
71 return 0; 68 return 0;
72} 69}
73 70
74static int xfrm6_get_tos(const struct flowi *fl)
75{
76 return 0;
77}
78
79static int xfrm6_init_path(struct xfrm_dst *path, struct dst_entry *dst,
80 int nfheader_len)
81{
82 if (dst->ops->family == AF_INET6) {
83 struct rt6_info *rt = (struct rt6_info *)dst;
84 path->path_cookie = rt6_get_cookie(rt);
85 }
86
87 path->u.rt6.rt6i_nfheader_len = nfheader_len;
88
89 return 0;
90}
91
92static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev, 71static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
93 const struct flowi *fl) 72 const struct flowi *fl)
94{ 73{
@@ -118,108 +97,6 @@ static int xfrm6_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
118 return 0; 97 return 0;
119} 98}
120 99
121static inline void
122_decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
123{
124 struct flowi6 *fl6 = &fl->u.ip6;
125 int onlyproto = 0;
126 const struct ipv6hdr *hdr = ipv6_hdr(skb);
127 u32 offset = sizeof(*hdr);
128 struct ipv6_opt_hdr *exthdr;
129 const unsigned char *nh = skb_network_header(skb);
130 u16 nhoff = IP6CB(skb)->nhoff;
131 int oif = 0;
132 u8 nexthdr;
133
134 if (!nhoff)
135 nhoff = offsetof(struct ipv6hdr, nexthdr);
136
137 nexthdr = nh[nhoff];
138
139 if (skb_dst(skb))
140 oif = skb_dst(skb)->dev->ifindex;
141
142 memset(fl6, 0, sizeof(struct flowi6));
143 fl6->flowi6_mark = skb->mark;
144 fl6->flowi6_oif = reverse ? skb->skb_iif : oif;
145
146 fl6->daddr = reverse ? hdr->saddr : hdr->daddr;
147 fl6->saddr = reverse ? hdr->daddr : hdr->saddr;
148
149 while (nh + offset + sizeof(*exthdr) < skb->data ||
150 pskb_may_pull(skb, nh + offset + sizeof(*exthdr) - skb->data)) {
151 nh = skb_network_header(skb);
152 exthdr = (struct ipv6_opt_hdr *)(nh + offset);
153
154 switch (nexthdr) {
155 case NEXTHDR_FRAGMENT:
156 onlyproto = 1;
157 /* fall through */
158 case NEXTHDR_ROUTING:
159 case NEXTHDR_HOP:
160 case NEXTHDR_DEST:
161 offset += ipv6_optlen(exthdr);
162 nexthdr = exthdr->nexthdr;
163 exthdr = (struct ipv6_opt_hdr *)(nh + offset);
164 break;
165
166 case IPPROTO_UDP:
167 case IPPROTO_UDPLITE:
168 case IPPROTO_TCP:
169 case IPPROTO_SCTP:
170 case IPPROTO_DCCP:
171 if (!onlyproto && (nh + offset + 4 < skb->data ||
172 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
173 __be16 *ports;
174
175 nh = skb_network_header(skb);
176 ports = (__be16 *)(nh + offset);
177 fl6->fl6_sport = ports[!!reverse];
178 fl6->fl6_dport = ports[!reverse];
179 }
180 fl6->flowi6_proto = nexthdr;
181 return;
182
183 case IPPROTO_ICMPV6:
184 if (!onlyproto && (nh + offset + 2 < skb->data ||
185 pskb_may_pull(skb, nh + offset + 2 - skb->data))) {
186 u8 *icmp;
187
188 nh = skb_network_header(skb);
189 icmp = (u8 *)(nh + offset);
190 fl6->fl6_icmp_type = icmp[0];
191 fl6->fl6_icmp_code = icmp[1];
192 }
193 fl6->flowi6_proto = nexthdr;
194 return;
195
196#if IS_ENABLED(CONFIG_IPV6_MIP6)
197 case IPPROTO_MH:
198 offset += ipv6_optlen(exthdr);
199 if (!onlyproto && (nh + offset + 3 < skb->data ||
200 pskb_may_pull(skb, nh + offset + 3 - skb->data))) {
201 struct ip6_mh *mh;
202
203 nh = skb_network_header(skb);
204 mh = (struct ip6_mh *)(nh + offset);
205 fl6->fl6_mh_type = mh->ip6mh_type;
206 }
207 fl6->flowi6_proto = nexthdr;
208 return;
209#endif
210
211 /* XXX Why are there these headers? */
212 case IPPROTO_AH:
213 case IPPROTO_ESP:
214 case IPPROTO_COMP:
215 default:
216 fl6->fl6_ipsec_spi = 0;
217 fl6->flowi6_proto = nexthdr;
218 return;
219 }
220 }
221}
222
223static void xfrm6_update_pmtu(struct dst_entry *dst, struct sock *sk, 100static void xfrm6_update_pmtu(struct dst_entry *dst, struct sock *sk,
224 struct sk_buff *skb, u32 mtu) 101 struct sk_buff *skb, u32 mtu)
225{ 102{
@@ -291,9 +168,6 @@ static const struct xfrm_policy_afinfo xfrm6_policy_afinfo = {
291 .dst_ops = &xfrm6_dst_ops_template, 168 .dst_ops = &xfrm6_dst_ops_template,
292 .dst_lookup = xfrm6_dst_lookup, 169 .dst_lookup = xfrm6_dst_lookup,
293 .get_saddr = xfrm6_get_saddr, 170 .get_saddr = xfrm6_get_saddr,
294 .decode_session = _decode_session6,
295 .get_tos = xfrm6_get_tos,
296 .init_path = xfrm6_init_path,
297 .fill_dst = xfrm6_fill_dst, 171 .fill_dst = xfrm6_fill_dst,
298 .blackhole_route = ip6_blackhole_route, 172 .blackhole_route = ip6_blackhole_route,
299}; 173};
diff --git a/net/ipv6/xfrm6_protocol.c b/net/ipv6/xfrm6_protocol.c
index cc979b702c89..aaacac7fdbce 100644
--- a/net/ipv6/xfrm6_protocol.c
+++ b/net/ipv6/xfrm6_protocol.c
@@ -46,7 +46,7 @@ static inline struct xfrm6_protocol __rcu **proto_handlers(u8 protocol)
46 handler != NULL; \ 46 handler != NULL; \
47 handler = rcu_dereference(handler->next)) \ 47 handler = rcu_dereference(handler->next)) \
48 48
49int xfrm6_rcv_cb(struct sk_buff *skb, u8 protocol, int err) 49static int xfrm6_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
50{ 50{
51 int ret; 51 int ret;
52 struct xfrm6_protocol *handler; 52 struct xfrm6_protocol *handler;
@@ -61,7 +61,6 @@ int xfrm6_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
61 61
62 return 0; 62 return 0;
63} 63}
64EXPORT_SYMBOL(xfrm6_rcv_cb);
65 64
66static int xfrm6_esp_rcv(struct sk_buff *skb) 65static int xfrm6_esp_rcv(struct sk_buff *skb)
67{ 66{
diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
index bc65db782bfb..d9e5f6808811 100644
--- a/net/ipv6/xfrm6_tunnel.c
+++ b/net/ipv6/xfrm6_tunnel.c
@@ -345,7 +345,7 @@ static void __net_exit xfrm6_tunnel_net_exit(struct net *net)
345 unsigned int i; 345 unsigned int i;
346 346
347 xfrm_flush_gc(); 347 xfrm_flush_gc();
348 xfrm_state_flush(net, IPSEC_PROTO_ANY, false, true); 348 xfrm_state_flush(net, 0, false, true);
349 349
350 for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++) 350 for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++)
351 WARN_ON_ONCE(!hlist_empty(&xfrm6_tn->spi_byaddr[i])); 351 WARN_ON_ONCE(!hlist_empty(&xfrm6_tn->spi_byaddr[i]));
@@ -402,6 +402,10 @@ static void __exit xfrm6_tunnel_fini(void)
402 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6); 402 xfrm6_tunnel_deregister(&xfrm6_tunnel_handler, AF_INET6);
403 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6); 403 xfrm_unregister_type(&xfrm6_tunnel_type, AF_INET6);
404 unregister_pernet_subsys(&xfrm6_tunnel_net_ops); 404 unregister_pernet_subsys(&xfrm6_tunnel_net_ops);
405 /* Someone maybe has gotten the xfrm6_tunnel_spi.
406 * So need to wait it.
407 */
408 rcu_barrier();
405 kmem_cache_destroy(xfrm6_tunnel_spi_kmem); 409 kmem_cache_destroy(xfrm6_tunnel_spi_kmem);
406} 410}
407 411
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 5651c29cb5bd..4af1e1d60b9f 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -1951,8 +1951,10 @@ parse_ipsecrequest(struct xfrm_policy *xp, struct sadb_x_ipsecrequest *rq)
1951 1951
1952 if (rq->sadb_x_ipsecrequest_mode == 0) 1952 if (rq->sadb_x_ipsecrequest_mode == 0)
1953 return -EINVAL; 1953 return -EINVAL;
1954 if (!xfrm_id_proto_valid(rq->sadb_x_ipsecrequest_proto))
1955 return -EINVAL;
1954 1956
1955 t->id.proto = rq->sadb_x_ipsecrequest_proto; /* XXX check proto */ 1957 t->id.proto = rq->sadb_x_ipsecrequest_proto;
1956 if ((mode = pfkey_mode_to_xfrm(rq->sadb_x_ipsecrequest_mode)) < 0) 1958 if ((mode = pfkey_mode_to_xfrm(rq->sadb_x_ipsecrequest_mode)) < 0)
1957 return -EINVAL; 1959 return -EINVAL;
1958 t->mode = mode; 1960 t->mode = mode;
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index fed6becc5daf..e4dec03a19fe 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -169,8 +169,8 @@ struct l2tp_tunnel *l2tp_tunnel_get(const struct net *net, u32 tunnel_id)
169 169
170 rcu_read_lock_bh(); 170 rcu_read_lock_bh();
171 list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) { 171 list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) {
172 if (tunnel->tunnel_id == tunnel_id) { 172 if (tunnel->tunnel_id == tunnel_id &&
173 l2tp_tunnel_inc_refcount(tunnel); 173 refcount_inc_not_zero(&tunnel->ref_count)) {
174 rcu_read_unlock_bh(); 174 rcu_read_unlock_bh();
175 175
176 return tunnel; 176 return tunnel;
@@ -190,8 +190,8 @@ struct l2tp_tunnel *l2tp_tunnel_get_nth(const struct net *net, int nth)
190 190
191 rcu_read_lock_bh(); 191 rcu_read_lock_bh();
192 list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) { 192 list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) {
193 if (++count > nth) { 193 if (++count > nth &&
194 l2tp_tunnel_inc_refcount(tunnel); 194 refcount_inc_not_zero(&tunnel->ref_count)) {
195 rcu_read_unlock_bh(); 195 rcu_read_unlock_bh();
196 return tunnel; 196 return tunnel;
197 } 197 }
@@ -909,7 +909,7 @@ int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
909{ 909{
910 struct l2tp_tunnel *tunnel; 910 struct l2tp_tunnel *tunnel;
911 911
912 tunnel = l2tp_tunnel(sk); 912 tunnel = rcu_dereference_sk_user_data(sk);
913 if (tunnel == NULL) 913 if (tunnel == NULL)
914 goto pass_up; 914 goto pass_up;
915 915
@@ -1735,7 +1735,8 @@ static __net_exit void l2tp_exit_net(struct net *net)
1735 } 1735 }
1736 rcu_read_unlock_bh(); 1736 rcu_read_unlock_bh();
1737 1737
1738 flush_workqueue(l2tp_wq); 1738 if (l2tp_wq)
1739 flush_workqueue(l2tp_wq);
1739 rcu_barrier(); 1740 rcu_barrier();
1740 1741
1741 for (hash = 0; hash < L2TP_HASH_SIZE_2; hash++) 1742 for (hash = 0; hash < L2TP_HASH_SIZE_2; hash++)
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index d4c60523c549..2cac910c1cd4 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -618,6 +618,7 @@ static const struct proto_ops l2tp_ip_ops = {
618 .getname = l2tp_ip_getname, 618 .getname = l2tp_ip_getname,
619 .poll = datagram_poll, 619 .poll = datagram_poll,
620 .ioctl = inet_ioctl, 620 .ioctl = inet_ioctl,
621 .gettstamp = sock_gettstamp,
621 .listen = sock_no_listen, 622 .listen = sock_no_listen,
622 .shutdown = inet_shutdown, 623 .shutdown = inet_shutdown,
623 .setsockopt = sock_common_setsockopt, 624 .setsockopt = sock_common_setsockopt,
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 37a69df17cab..4ec546cc1dd6 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -752,6 +752,7 @@ static const struct proto_ops l2tp_ip6_ops = {
752 .getname = l2tp_ip6_getname, 752 .getname = l2tp_ip6_getname,
753 .poll = datagram_poll, 753 .poll = datagram_poll,
754 .ioctl = inet6_ioctl, 754 .ioctl = inet6_ioctl,
755 .gettstamp = sock_gettstamp,
755 .listen = sock_no_listen, 756 .listen = sock_no_listen,
756 .shutdown = inet_shutdown, 757 .shutdown = inet_shutdown,
757 .setsockopt = sock_common_setsockopt, 758 .setsockopt = sock_common_setsockopt,
diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c
index edbd5d1fbcde..6acc7f869b0c 100644
--- a/net/l2tp/l2tp_netlink.c
+++ b/net/l2tp/l2tp_netlink.c
@@ -345,7 +345,7 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla
345 nla_put_u16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap)) 345 nla_put_u16(skb, L2TP_ATTR_ENCAP_TYPE, tunnel->encap))
346 goto nla_put_failure; 346 goto nla_put_failure;
347 347
348 nest = nla_nest_start(skb, L2TP_ATTR_STATS); 348 nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
349 if (nest == NULL) 349 if (nest == NULL)
350 goto nla_put_failure; 350 goto nla_put_failure;
351 351
@@ -742,7 +742,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl
742 session->reorder_timeout, L2TP_ATTR_PAD))) 742 session->reorder_timeout, L2TP_ATTR_PAD)))
743 goto nla_put_failure; 743 goto nla_put_failure;
744 744
745 nest = nla_nest_start(skb, L2TP_ATTR_STATS); 745 nest = nla_nest_start_noflag(skb, L2TP_ATTR_STATS);
746 if (nest == NULL) 746 if (nest == NULL)
747 goto nla_put_failure; 747 goto nla_put_failure;
748 748
@@ -915,58 +915,58 @@ static const struct nla_policy l2tp_nl_policy[L2TP_ATTR_MAX + 1] = {
915static const struct genl_ops l2tp_nl_ops[] = { 915static const struct genl_ops l2tp_nl_ops[] = {
916 { 916 {
917 .cmd = L2TP_CMD_NOOP, 917 .cmd = L2TP_CMD_NOOP,
918 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
918 .doit = l2tp_nl_cmd_noop, 919 .doit = l2tp_nl_cmd_noop,
919 .policy = l2tp_nl_policy,
920 /* can be retrieved by unprivileged users */ 920 /* can be retrieved by unprivileged users */
921 }, 921 },
922 { 922 {
923 .cmd = L2TP_CMD_TUNNEL_CREATE, 923 .cmd = L2TP_CMD_TUNNEL_CREATE,
924 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
924 .doit = l2tp_nl_cmd_tunnel_create, 925 .doit = l2tp_nl_cmd_tunnel_create,
925 .policy = l2tp_nl_policy,
926 .flags = GENL_ADMIN_PERM, 926 .flags = GENL_ADMIN_PERM,
927 }, 927 },
928 { 928 {
929 .cmd = L2TP_CMD_TUNNEL_DELETE, 929 .cmd = L2TP_CMD_TUNNEL_DELETE,
930 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
930 .doit = l2tp_nl_cmd_tunnel_delete, 931 .doit = l2tp_nl_cmd_tunnel_delete,
931 .policy = l2tp_nl_policy,
932 .flags = GENL_ADMIN_PERM, 932 .flags = GENL_ADMIN_PERM,
933 }, 933 },
934 { 934 {
935 .cmd = L2TP_CMD_TUNNEL_MODIFY, 935 .cmd = L2TP_CMD_TUNNEL_MODIFY,
936 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
936 .doit = l2tp_nl_cmd_tunnel_modify, 937 .doit = l2tp_nl_cmd_tunnel_modify,
937 .policy = l2tp_nl_policy,
938 .flags = GENL_ADMIN_PERM, 938 .flags = GENL_ADMIN_PERM,
939 }, 939 },
940 { 940 {
941 .cmd = L2TP_CMD_TUNNEL_GET, 941 .cmd = L2TP_CMD_TUNNEL_GET,
942 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
942 .doit = l2tp_nl_cmd_tunnel_get, 943 .doit = l2tp_nl_cmd_tunnel_get,
943 .dumpit = l2tp_nl_cmd_tunnel_dump, 944 .dumpit = l2tp_nl_cmd_tunnel_dump,
944 .policy = l2tp_nl_policy,
945 .flags = GENL_ADMIN_PERM, 945 .flags = GENL_ADMIN_PERM,
946 }, 946 },
947 { 947 {
948 .cmd = L2TP_CMD_SESSION_CREATE, 948 .cmd = L2TP_CMD_SESSION_CREATE,
949 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
949 .doit = l2tp_nl_cmd_session_create, 950 .doit = l2tp_nl_cmd_session_create,
950 .policy = l2tp_nl_policy,
951 .flags = GENL_ADMIN_PERM, 951 .flags = GENL_ADMIN_PERM,
952 }, 952 },
953 { 953 {
954 .cmd = L2TP_CMD_SESSION_DELETE, 954 .cmd = L2TP_CMD_SESSION_DELETE,
955 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
955 .doit = l2tp_nl_cmd_session_delete, 956 .doit = l2tp_nl_cmd_session_delete,
956 .policy = l2tp_nl_policy,
957 .flags = GENL_ADMIN_PERM, 957 .flags = GENL_ADMIN_PERM,
958 }, 958 },
959 { 959 {
960 .cmd = L2TP_CMD_SESSION_MODIFY, 960 .cmd = L2TP_CMD_SESSION_MODIFY,
961 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
961 .doit = l2tp_nl_cmd_session_modify, 962 .doit = l2tp_nl_cmd_session_modify,
962 .policy = l2tp_nl_policy,
963 .flags = GENL_ADMIN_PERM, 963 .flags = GENL_ADMIN_PERM,
964 }, 964 },
965 { 965 {
966 .cmd = L2TP_CMD_SESSION_GET, 966 .cmd = L2TP_CMD_SESSION_GET,
967 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
967 .doit = l2tp_nl_cmd_session_get, 968 .doit = l2tp_nl_cmd_session_get,
968 .dumpit = l2tp_nl_cmd_session_dump, 969 .dumpit = l2tp_nl_cmd_session_dump,
969 .policy = l2tp_nl_policy,
970 .flags = GENL_ADMIN_PERM, 970 .flags = GENL_ADMIN_PERM,
971 }, 971 },
972}; 972};
@@ -976,6 +976,7 @@ static struct genl_family l2tp_nl_family __ro_after_init = {
976 .version = L2TP_GENL_VERSION, 976 .version = L2TP_GENL_VERSION,
977 .hdrsize = 0, 977 .hdrsize = 0,
978 .maxattr = L2TP_ATTR_MAX, 978 .maxattr = L2TP_ATTR_MAX,
979 .policy = l2tp_nl_policy,
979 .netnsok = true, 980 .netnsok = true,
980 .module = THIS_MODULE, 981 .module = THIS_MODULE,
981 .ops = l2tp_nl_ops, 982 .ops = l2tp_nl_ops,
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index 04d9946dcdba..f36cae785e82 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -1070,7 +1070,6 @@ static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
1070{ 1070{
1071 struct pppol2tp_ioc_stats stats; 1071 struct pppol2tp_ioc_stats stats;
1072 struct l2tp_session *session; 1072 struct l2tp_session *session;
1073 int val;
1074 1073
1075 switch (cmd) { 1074 switch (cmd) {
1076 case PPPIOCGMRU: 1075 case PPPIOCGMRU:
@@ -1097,7 +1096,7 @@ static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
1097 if (!session->session_id && !session->peer_session_id) 1096 if (!session->session_id && !session->peer_session_id)
1098 return -ENOSYS; 1097 return -ENOSYS;
1099 1098
1100 if (get_user(val, (int __user *)arg)) 1099 if (!access_ok((int __user *)arg, sizeof(int)))
1101 return -EFAULT; 1100 return -EFAULT;
1102 break; 1101 break;
1103 1102
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index b99e73a7e7e0..2017b7d780f5 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -320,14 +320,13 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
320 struct llc_sap *sap; 320 struct llc_sap *sap;
321 int rc = -EINVAL; 321 int rc = -EINVAL;
322 322
323 dprintk("%s: binding %02X\n", __func__, addr->sllc_sap);
324
325 lock_sock(sk); 323 lock_sock(sk);
326 if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr))) 324 if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
327 goto out; 325 goto out;
328 rc = -EAFNOSUPPORT; 326 rc = -EAFNOSUPPORT;
329 if (unlikely(addr->sllc_family != AF_LLC)) 327 if (unlikely(addr->sllc_family != AF_LLC))
330 goto out; 328 goto out;
329 dprintk("%s: binding %02X\n", __func__, addr->sllc_sap);
331 rc = -ENODEV; 330 rc = -ENODEV;
332 rcu_read_lock(); 331 rcu_read_lock();
333 if (sk->sk_bound_dev_if) { 332 if (sk->sk_bound_dev_if) {
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 09dd1c2860fc..52e6a091b7e4 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -351,6 +351,36 @@ static int ieee80211_set_noack_map(struct wiphy *wiphy,
351 return 0; 351 return 0;
352} 352}
353 353
354static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
355 const u8 *mac_addr, u8 key_idx)
356{
357 struct ieee80211_local *local = sdata->local;
358 struct ieee80211_key *key;
359 struct sta_info *sta;
360 int ret = -EINVAL;
361
362 if (!wiphy_ext_feature_isset(local->hw.wiphy,
363 NL80211_EXT_FEATURE_EXT_KEY_ID))
364 return -EINVAL;
365
366 sta = sta_info_get_bss(sdata, mac_addr);
367
368 if (!sta)
369 return -EINVAL;
370
371 if (sta->ptk_idx == key_idx)
372 return 0;
373
374 mutex_lock(&local->key_mtx);
375 key = key_mtx_dereference(local, sta->ptk[key_idx]);
376
377 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
378 ret = ieee80211_set_tx_key(key);
379
380 mutex_unlock(&local->key_mtx);
381 return ret;
382}
383
354static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, 384static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
355 u8 key_idx, bool pairwise, const u8 *mac_addr, 385 u8 key_idx, bool pairwise, const u8 *mac_addr,
356 struct key_params *params) 386 struct key_params *params)
@@ -365,6 +395,9 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
365 if (!ieee80211_sdata_running(sdata)) 395 if (!ieee80211_sdata_running(sdata))
366 return -ENETDOWN; 396 return -ENETDOWN;
367 397
398 if (pairwise && params->mode == NL80211_KEY_SET_TX)
399 return ieee80211_set_tx(sdata, mac_addr, key_idx);
400
368 /* reject WEP and TKIP keys if WEP failed to initialize */ 401 /* reject WEP and TKIP keys if WEP failed to initialize */
369 switch (params->cipher) { 402 switch (params->cipher) {
370 case WLAN_CIPHER_SUITE_WEP40: 403 case WLAN_CIPHER_SUITE_WEP40:
@@ -396,6 +429,9 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
396 if (pairwise) 429 if (pairwise)
397 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE; 430 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
398 431
432 if (params->mode == NL80211_KEY_NO_TX)
433 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
434
399 mutex_lock(&local->sta_mtx); 435 mutex_lock(&local->sta_mtx);
400 436
401 if (mac_addr) { 437 if (mac_addr) {
@@ -1421,6 +1457,15 @@ static int sta_apply_parameters(struct ieee80211_local *local,
1421 if (params->listen_interval >= 0) 1457 if (params->listen_interval >= 0)
1422 sta->listen_interval = params->listen_interval; 1458 sta->listen_interval = params->listen_interval;
1423 1459
1460 if (params->sta_modify_mask & STATION_PARAM_APPLY_STA_TXPOWER) {
1461 sta->sta.txpwr.type = params->txpwr.type;
1462 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1463 sta->sta.txpwr.power = params->txpwr.power;
1464 ret = drv_sta_set_txpwr(local, sdata, sta);
1465 if (ret)
1466 return ret;
1467 }
1468
1424 if (params->supported_rates) { 1469 if (params->supported_rates) {
1425 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef, 1470 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1426 sband, params->supported_rates, 1471 sband, params->supported_rates,
@@ -3990,4 +4035,5 @@ const struct cfg80211_ops mac80211_config_ops = {
3990 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats, 4035 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
3991 .start_pmsr = ieee80211_start_pmsr, 4036 .start_pmsr = ieee80211_start_pmsr,
3992 .abort_pmsr = ieee80211_abort_pmsr, 4037 .abort_pmsr = ieee80211_abort_pmsr,
4038 .probe_mesh_link = ieee80211_probe_mesh_link,
3993}; 4039};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 2d43bc127043..0d462206eef6 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -150,6 +150,58 @@ static const struct file_operations aqm_ops = {
150 .llseek = default_llseek, 150 .llseek = default_llseek,
151}; 151};
152 152
153static ssize_t force_tx_status_read(struct file *file,
154 char __user *user_buf,
155 size_t count,
156 loff_t *ppos)
157{
158 struct ieee80211_local *local = file->private_data;
159 char buf[3];
160 int len = 0;
161
162 len = scnprintf(buf, sizeof(buf), "%d\n", (int)local->force_tx_status);
163
164 return simple_read_from_buffer(user_buf, count, ppos,
165 buf, len);
166}
167
168static ssize_t force_tx_status_write(struct file *file,
169 const char __user *user_buf,
170 size_t count,
171 loff_t *ppos)
172{
173 struct ieee80211_local *local = file->private_data;
174 char buf[3];
175 size_t len;
176
177 if (count > sizeof(buf))
178 return -EINVAL;
179
180 if (copy_from_user(buf, user_buf, count))
181 return -EFAULT;
182
183 buf[sizeof(buf) - 1] = '\0';
184 len = strlen(buf);
185 if (len > 0 && buf[len - 1] == '\n')
186 buf[len - 1] = 0;
187
188 if (buf[0] == '0' && buf[1] == '\0')
189 local->force_tx_status = 0;
190 else if (buf[0] == '1' && buf[1] == '\0')
191 local->force_tx_status = 1;
192 else
193 return -EINVAL;
194
195 return count;
196}
197
198static const struct file_operations force_tx_status_ops = {
199 .write = force_tx_status_write,
200 .read = force_tx_status_read,
201 .open = simple_open,
202 .llseek = default_llseek,
203};
204
153#ifdef CONFIG_PM 205#ifdef CONFIG_PM
154static ssize_t reset_write(struct file *file, const char __user *user_buf, 206static ssize_t reset_write(struct file *file, const char __user *user_buf,
155 size_t count, loff_t *ppos) 207 size_t count, loff_t *ppos)
@@ -221,6 +273,7 @@ static const char *hw_flag_names[] = {
221 FLAG(TX_STATUS_NO_AMPDU_LEN), 273 FLAG(TX_STATUS_NO_AMPDU_LEN),
222 FLAG(SUPPORTS_MULTI_BSSID), 274 FLAG(SUPPORTS_MULTI_BSSID),
223 FLAG(SUPPORTS_ONLY_HE_MULTI_BSSID), 275 FLAG(SUPPORTS_ONLY_HE_MULTI_BSSID),
276 FLAG(EXT_KEY_ID_NATIVE),
224#undef FLAG 277#undef FLAG
225}; 278};
226 279
@@ -382,6 +435,7 @@ void debugfs_hw_add(struct ieee80211_local *local)
382 DEBUGFS_ADD(hwflags); 435 DEBUGFS_ADD(hwflags);
383 DEBUGFS_ADD(user_power); 436 DEBUGFS_ADD(user_power);
384 DEBUGFS_ADD(power); 437 DEBUGFS_ADD(power);
438 DEBUGFS_ADD_MODE(force_tx_status, 0600);
385 439
386 if (local->ops->wake_tx_queue) 440 if (local->ops->wake_tx_queue)
387 DEBUGFS_ADD_MODE(aqm, 0600); 441 DEBUGFS_ADD_MODE(aqm, 0600);
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index cff0fb3578c9..deb3faf08337 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -841,7 +841,7 @@ void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
841 841
842 dir = sdata->vif.debugfs_dir; 842 dir = sdata->vif.debugfs_dir;
843 843
844 if (!dir) 844 if (IS_ERR_OR_NULL(dir))
845 return; 845 return;
846 846
847 sprintf(buf, "netdev:%s", sdata->name); 847 sprintf(buf, "netdev:%s", sdata->name);
diff --git a/net/mac80211/driver-ops.c b/net/mac80211/driver-ops.c
index bb886e7db47f..839c0022a29c 100644
--- a/net/mac80211/driver-ops.c
+++ b/net/mac80211/driver-ops.c
@@ -138,6 +138,27 @@ int drv_sta_state(struct ieee80211_local *local,
138 return ret; 138 return ret;
139} 139}
140 140
141__must_check
142int drv_sta_set_txpwr(struct ieee80211_local *local,
143 struct ieee80211_sub_if_data *sdata,
144 struct sta_info *sta)
145{
146 int ret = -EOPNOTSUPP;
147
148 might_sleep();
149
150 sdata = get_bss_sdata(sdata);
151 if (!check_sdata_in_driver(sdata))
152 return -EIO;
153
154 trace_drv_sta_set_txpwr(local, sdata, &sta->sta);
155 if (local->ops->sta_set_txpwr)
156 ret = local->ops->sta_set_txpwr(&local->hw, &sdata->vif,
157 &sta->sta);
158 trace_drv_return_int(local, ret);
159 return ret;
160}
161
141void drv_sta_rc_update(struct ieee80211_local *local, 162void drv_sta_rc_update(struct ieee80211_local *local,
142 struct ieee80211_sub_if_data *sdata, 163 struct ieee80211_sub_if_data *sdata,
143 struct ieee80211_sta *sta, u32 changed) 164 struct ieee80211_sta *sta, u32 changed)
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 28d022a3eee3..c2d8b5451a5e 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -529,6 +529,11 @@ int drv_sta_state(struct ieee80211_local *local,
529 enum ieee80211_sta_state old_state, 529 enum ieee80211_sta_state old_state,
530 enum ieee80211_sta_state new_state); 530 enum ieee80211_sta_state new_state);
531 531
532__must_check
533int drv_sta_set_txpwr(struct ieee80211_local *local,
534 struct ieee80211_sub_if_data *sdata,
535 struct sta_info *sta);
536
532void drv_sta_rc_update(struct ieee80211_local *local, 537void drv_sta_rc_update(struct ieee80211_local *local,
533 struct ieee80211_sub_if_data *sdata, 538 struct ieee80211_sub_if_data *sdata,
534 struct ieee80211_sta *sta, u32 changed); 539 struct ieee80211_sta *sta, u32 changed);
@@ -1195,6 +1200,9 @@ static inline void drv_wake_tx_queue(struct ieee80211_local *local,
1195{ 1200{
1196 struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->txq.vif); 1201 struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->txq.vif);
1197 1202
1203 if (local->in_reconfig)
1204 return;
1205
1198 if (!check_sdata_in_driver(sdata)) 1206 if (!check_sdata_in_driver(sdata))
1199 return; 1207 return;
1200 1208
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index e03c46ac8e4d..c62101857b9b 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -112,8 +112,9 @@ void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
112 IEEE80211_HT_CAP_TX_STBC); 112 IEEE80211_HT_CAP_TX_STBC);
113 113
114 /* Allow user to configure RX STBC bits */ 114 /* Allow user to configure RX STBC bits */
115 if (ht_capa_mask->cap_info & IEEE80211_HT_CAP_RX_STBC) 115 if (ht_capa_mask->cap_info & cpu_to_le16(IEEE80211_HT_CAP_RX_STBC))
116 ht_cap->cap |= ht_capa->cap_info & IEEE80211_HT_CAP_RX_STBC; 116 ht_cap->cap |= le16_to_cpu(ht_capa->cap_info) &
117 IEEE80211_HT_CAP_RX_STBC;
117 118
118 /* Allow user to decrease AMPDU factor */ 119 /* Allow user to decrease AMPDU factor */
119 if (ht_capa_mask->ampdu_params_info & 120 if (ht_capa_mask->ampdu_params_info &
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index e170f986d226..073a8235ae1b 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1269,7 +1269,7 @@ struct ieee80211_local {
1269 1269
1270 /* 1270 /*
1271 * Key mutex, protects sdata's key_list and sta_info's 1271 * Key mutex, protects sdata's key_list and sta_info's
1272 * key pointers (write access, they're RCU.) 1272 * key pointers and ptk_idx (write access, they're RCU.)
1273 */ 1273 */
1274 struct mutex key_mtx; 1274 struct mutex key_mtx;
1275 1275
@@ -1384,6 +1384,7 @@ struct ieee80211_local {
1384 struct dentry *rcdir; 1384 struct dentry *rcdir;
1385 struct dentry *keys; 1385 struct dentry *keys;
1386 } debugfs; 1386 } debugfs;
1387 bool force_tx_status;
1387#endif 1388#endif
1388 1389
1389 /* 1390 /*
@@ -1505,7 +1506,6 @@ struct ieee802_11_elems {
1505 const struct ieee80211_bss_max_idle_period_ie *max_idle_period_ie; 1506 const struct ieee80211_bss_max_idle_period_ie *max_idle_period_ie;
1506 const struct ieee80211_multiple_bssid_configuration *mbssid_config_ie; 1507 const struct ieee80211_multiple_bssid_configuration *mbssid_config_ie;
1507 const struct ieee80211_bssid_index *bssid_index; 1508 const struct ieee80211_bssid_index *bssid_index;
1508 const u8 *nontransmitted_bssid_profile;
1509 u8 max_bssid_indicator; 1509 u8 max_bssid_indicator;
1510 u8 dtim_count; 1510 u8 dtim_count;
1511 u8 dtim_period; 1511 u8 dtim_period;
@@ -1761,7 +1761,8 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1761 struct net_device *dev); 1761 struct net_device *dev);
1762void __ieee80211_subif_start_xmit(struct sk_buff *skb, 1762void __ieee80211_subif_start_xmit(struct sk_buff *skb,
1763 struct net_device *dev, 1763 struct net_device *dev,
1764 u32 info_flags); 1764 u32 info_flags,
1765 u32 ctrl_flags);
1765void ieee80211_purge_tx_queue(struct ieee80211_hw *hw, 1766void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
1766 struct sk_buff_head *skbs); 1767 struct sk_buff_head *skbs);
1767struct sk_buff * 1768struct sk_buff *
@@ -1778,6 +1779,8 @@ void ieee80211_clear_fast_xmit(struct sta_info *sta);
1778int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, 1779int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
1779 const u8 *buf, size_t len, 1780 const u8 *buf, size_t len,
1780 const u8 *dest, __be16 proto, bool unencrypted); 1781 const u8 *dest, __be16 proto, bool unencrypted);
1782int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
1783 const u8 *buf, size_t len);
1781 1784
1782/* HT */ 1785/* HT */
1783void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata, 1786void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 4a6ff1482a9f..410685d38c46 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1133,8 +1133,7 @@ static void ieee80211_uninit(struct net_device *dev)
1133 1133
1134static u16 ieee80211_netdev_select_queue(struct net_device *dev, 1134static u16 ieee80211_netdev_select_queue(struct net_device *dev,
1135 struct sk_buff *skb, 1135 struct sk_buff *skb,
1136 struct net_device *sb_dev, 1136 struct net_device *sb_dev)
1137 select_queue_fallback_t fallback)
1138{ 1137{
1139 return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb); 1138 return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
1140} 1139}
@@ -1179,8 +1178,7 @@ static const struct net_device_ops ieee80211_dataif_ops = {
1179 1178
1180static u16 ieee80211_monitor_select_queue(struct net_device *dev, 1179static u16 ieee80211_monitor_select_queue(struct net_device *dev,
1181 struct sk_buff *skb, 1180 struct sk_buff *skb,
1182 struct net_device *sb_dev, 1181 struct net_device *sb_dev)
1183 select_queue_fallback_t fallback)
1184{ 1182{
1185 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1183 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1186 struct ieee80211_local *local = sdata->local; 1184 struct ieee80211_local *local = sdata->local;
@@ -1227,6 +1225,7 @@ static void ieee80211_if_setup(struct net_device *dev)
1227static void ieee80211_if_setup_no_queue(struct net_device *dev) 1225static void ieee80211_if_setup_no_queue(struct net_device *dev)
1228{ 1226{
1229 ieee80211_if_setup(dev); 1227 ieee80211_if_setup(dev);
1228 dev->features |= NETIF_F_LLTX;
1230 dev->priv_flags |= IFF_NO_QUEUE; 1229 dev->priv_flags |= IFF_NO_QUEUE;
1231} 1230}
1232 1231
@@ -1764,13 +1763,13 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
1764 txq_size += sizeof(struct txq_info) + 1763 txq_size += sizeof(struct txq_info) +
1765 local->hw.txq_data_size; 1764 local->hw.txq_data_size;
1766 1765
1767 if (local->ops->wake_tx_queue) 1766 if (local->ops->wake_tx_queue) {
1768 if_setup = ieee80211_if_setup_no_queue; 1767 if_setup = ieee80211_if_setup_no_queue;
1769 else 1768 } else {
1770 if_setup = ieee80211_if_setup; 1769 if_setup = ieee80211_if_setup;
1771 1770 if (local->hw.queues >= IEEE80211_NUM_ACS)
1772 if (local->hw.queues >= IEEE80211_NUM_ACS) 1771 txqs = IEEE80211_NUM_ACS;
1773 txqs = IEEE80211_NUM_ACS; 1772 }
1774 1773
1775 ndev = alloc_netdev_mqs(size + txq_size, 1774 ndev = alloc_netdev_mqs(size + txq_size,
1776 name, name_assign_type, 1775 name, name_assign_type,
@@ -1908,6 +1907,9 @@ void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
1908 list_del_rcu(&sdata->list); 1907 list_del_rcu(&sdata->list);
1909 mutex_unlock(&sdata->local->iflist_mtx); 1908 mutex_unlock(&sdata->local->iflist_mtx);
1910 1909
1910 if (sdata->vif.txq)
1911 ieee80211_txq_purge(sdata->local, to_txq_info(sdata->vif.txq));
1912
1911 synchronize_rcu(); 1913 synchronize_rcu();
1912 1914
1913 if (sdata->dev) { 1915 if (sdata->dev) {
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 4700718e010f..20bf9db7a388 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -140,6 +140,12 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
140 * so clear that flag now to avoid trying to remove 140 * so clear that flag now to avoid trying to remove
141 * it again later. 141 * it again later.
142 */ 142 */
143 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
144 !(key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC |
145 IEEE80211_KEY_FLAG_PUT_MIC_SPACE |
146 IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
147 increment_tailroom_need_count(sdata);
148
143 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; 149 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
144 return -EINVAL; 150 return -EINVAL;
145 } 151 }
@@ -167,8 +173,10 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
167 * The driver doesn't know anything about VLAN interfaces. 173 * The driver doesn't know anything about VLAN interfaces.
168 * Hence, don't send GTKs for VLAN interfaces to the driver. 174 * Hence, don't send GTKs for VLAN interfaces to the driver.
169 */ 175 */
170 if (!(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE)) 176 if (!(key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
177 ret = 1;
171 goto out_unsupported; 178 goto out_unsupported;
179 }
172 } 180 }
173 181
174 ret = drv_set_key(key->local, SET_KEY, sdata, 182 ret = drv_set_key(key->local, SET_KEY, sdata,
@@ -177,9 +185,9 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
177 if (!ret) { 185 if (!ret) {
178 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; 186 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
179 187
180 if (!((key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC | 188 if (!(key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC |
181 IEEE80211_KEY_FLAG_PUT_MIC_SPACE)) || 189 IEEE80211_KEY_FLAG_PUT_MIC_SPACE |
182 (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM))) 190 IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
183 decrease_tailroom_need_count(sdata, 1); 191 decrease_tailroom_need_count(sdata, 1);
184 192
185 WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) && 193 WARN_ON((key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) &&
@@ -213,11 +221,8 @@ static int ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
213 /* all of these we can do in software - if driver can */ 221 /* all of these we can do in software - if driver can */
214 if (ret == 1) 222 if (ret == 1)
215 return 0; 223 return 0;
216 if (ieee80211_hw_check(&key->local->hw, SW_CRYPTO_CONTROL)) { 224 if (ieee80211_hw_check(&key->local->hw, SW_CRYPTO_CONTROL))
217 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
218 return 0;
219 return -EINVAL; 225 return -EINVAL;
220 }
221 return 0; 226 return 0;
222 default: 227 default:
223 return -EINVAL; 228 return -EINVAL;
@@ -243,9 +248,9 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
243 sta = key->sta; 248 sta = key->sta;
244 sdata = key->sdata; 249 sdata = key->sdata;
245 250
246 if (!((key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC | 251 if (!(key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC |
247 IEEE80211_KEY_FLAG_PUT_MIC_SPACE)) || 252 IEEE80211_KEY_FLAG_PUT_MIC_SPACE |
248 (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM))) 253 IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
249 increment_tailroom_need_count(sdata); 254 increment_tailroom_need_count(sdata);
250 255
251 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; 256 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
@@ -259,9 +264,24 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
259 sta ? sta->sta.addr : bcast_addr, ret); 264 sta ? sta->sta.addr : bcast_addr, ret);
260} 265}
261 266
267int ieee80211_set_tx_key(struct ieee80211_key *key)
268{
269 struct sta_info *sta = key->sta;
270 struct ieee80211_local *local = key->local;
271 struct ieee80211_key *old;
272
273 assert_key_lock(local);
274
275 old = key_mtx_dereference(local, sta->ptk[sta->ptk_idx]);
276 sta->ptk_idx = key->conf.keyidx;
277 ieee80211_check_fast_xmit(sta);
278
279 return 0;
280}
281
262static int ieee80211_hw_key_replace(struct ieee80211_key *old_key, 282static int ieee80211_hw_key_replace(struct ieee80211_key *old_key,
263 struct ieee80211_key *new_key, 283 struct ieee80211_key *new_key,
264 bool ptk0rekey) 284 bool pairwise)
265{ 285{
266 struct ieee80211_sub_if_data *sdata; 286 struct ieee80211_sub_if_data *sdata;
267 struct ieee80211_local *local; 287 struct ieee80211_local *local;
@@ -278,8 +298,9 @@ static int ieee80211_hw_key_replace(struct ieee80211_key *old_key,
278 assert_key_lock(old_key->local); 298 assert_key_lock(old_key->local);
279 sta = old_key->sta; 299 sta = old_key->sta;
280 300
281 /* PTK only using key ID 0 needs special handling on rekey */ 301 /* Unicast rekey without Extended Key ID needs special handling */
282 if (new_key && sta && ptk0rekey) { 302 if (new_key && sta && pairwise &&
303 rcu_access_pointer(sta->ptk[sta->ptk_idx]) == old_key) {
283 local = old_key->local; 304 local = old_key->local;
284 sdata = old_key->sdata; 305 sdata = old_key->sdata;
285 306
@@ -395,10 +416,6 @@ static int ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
395 416
396 if (old) { 417 if (old) {
397 idx = old->conf.keyidx; 418 idx = old->conf.keyidx;
398 /* TODO: proper implement and test "Extended Key ID for
399 * Individually Addressed Frames" from IEEE 802.11-2016.
400 * Till then always assume only key ID 0 is used for
401 * pairwise keys.*/
402 ret = ieee80211_hw_key_replace(old, new, pairwise); 419 ret = ieee80211_hw_key_replace(old, new, pairwise);
403 } else { 420 } else {
404 /* new must be provided in case old is not */ 421 /* new must be provided in case old is not */
@@ -415,15 +432,20 @@ static int ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
415 if (sta) { 432 if (sta) {
416 if (pairwise) { 433 if (pairwise) {
417 rcu_assign_pointer(sta->ptk[idx], new); 434 rcu_assign_pointer(sta->ptk[idx], new);
418 sta->ptk_idx = idx; 435 if (new &&
419 if (new) { 436 !(new->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)) {
437 sta->ptk_idx = idx;
420 clear_sta_flag(sta, WLAN_STA_BLOCK_BA); 438 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
421 ieee80211_check_fast_xmit(sta); 439 ieee80211_check_fast_xmit(sta);
422 } 440 }
423 } else { 441 } else {
424 rcu_assign_pointer(sta->gtk[idx], new); 442 rcu_assign_pointer(sta->gtk[idx], new);
425 } 443 }
426 if (new) 444 /* Only needed for transition from no key -> key.
445 * Still triggers unnecessary when using Extended Key ID
446 * and installing the second key ID the first time.
447 */
448 if (new && !old)
427 ieee80211_check_fast_rx(sta); 449 ieee80211_check_fast_rx(sta);
428 } else { 450 } else {
429 defunikey = old && 451 defunikey = old &&
@@ -739,16 +761,34 @@ int ieee80211_key_link(struct ieee80211_key *key,
739 * can cause warnings to appear. 761 * can cause warnings to appear.
740 */ 762 */
741 bool delay_tailroom = sdata->vif.type == NL80211_IFTYPE_STATION; 763 bool delay_tailroom = sdata->vif.type == NL80211_IFTYPE_STATION;
742 int ret; 764 int ret = -EOPNOTSUPP;
743 765
744 mutex_lock(&sdata->local->key_mtx); 766 mutex_lock(&sdata->local->key_mtx);
745 767
746 if (sta && pairwise) 768 if (sta && pairwise) {
769 struct ieee80211_key *alt_key;
770
747 old_key = key_mtx_dereference(sdata->local, sta->ptk[idx]); 771 old_key = key_mtx_dereference(sdata->local, sta->ptk[idx]);
748 else if (sta) 772 alt_key = key_mtx_dereference(sdata->local, sta->ptk[idx ^ 1]);
773
774 /* The rekey code assumes that the old and new key are using
775 * the same cipher. Enforce the assumption for pairwise keys.
776 */
777 if (key &&
778 ((alt_key && alt_key->conf.cipher != key->conf.cipher) ||
779 (old_key && old_key->conf.cipher != key->conf.cipher)))
780 goto out;
781 } else if (sta) {
749 old_key = key_mtx_dereference(sdata->local, sta->gtk[idx]); 782 old_key = key_mtx_dereference(sdata->local, sta->gtk[idx]);
750 else 783 } else {
751 old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]); 784 old_key = key_mtx_dereference(sdata->local, sdata->keys[idx]);
785 }
786
787 /* Non-pairwise keys must also not switch the cipher on rekey */
788 if (!pairwise) {
789 if (key && old_key && old_key->conf.cipher != key->conf.cipher)
790 goto out;
791 }
752 792
753 /* 793 /*
754 * Silently accept key re-installation without really installing the 794 * Silently accept key re-installation without really installing the
@@ -1188,9 +1228,9 @@ void ieee80211_remove_key(struct ieee80211_key_conf *keyconf)
1188 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { 1228 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
1189 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; 1229 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
1190 1230
1191 if (!((key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC | 1231 if (!(key->conf.flags & (IEEE80211_KEY_FLAG_GENERATE_MMIC |
1192 IEEE80211_KEY_FLAG_PUT_MIC_SPACE)) || 1232 IEEE80211_KEY_FLAG_PUT_MIC_SPACE |
1193 (key->conf.flags & IEEE80211_KEY_FLAG_RESERVE_TAILROOM))) 1233 IEEE80211_KEY_FLAG_RESERVE_TAILROOM)))
1194 increment_tailroom_need_count(key->sdata); 1234 increment_tailroom_need_count(key->sdata);
1195 } 1235 }
1196 1236
diff --git a/net/mac80211/key.h b/net/mac80211/key.h
index ebdb80b85dc3..f06fbd03d235 100644
--- a/net/mac80211/key.h
+++ b/net/mac80211/key.h
@@ -18,6 +18,7 @@
18 18
19#define NUM_DEFAULT_KEYS 4 19#define NUM_DEFAULT_KEYS 4
20#define NUM_DEFAULT_MGMT_KEYS 2 20#define NUM_DEFAULT_MGMT_KEYS 2
21#define INVALID_PTK_KEYIDX 2 /* Keyidx always pointing to a NULL key for PTK */
21 22
22struct ieee80211_local; 23struct ieee80211_local;
23struct ieee80211_sub_if_data; 24struct ieee80211_sub_if_data;
@@ -146,6 +147,7 @@ ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
146int ieee80211_key_link(struct ieee80211_key *key, 147int ieee80211_key_link(struct ieee80211_key *key,
147 struct ieee80211_sub_if_data *sdata, 148 struct ieee80211_sub_if_data *sdata,
148 struct sta_info *sta); 149 struct sta_info *sta);
150int ieee80211_set_tx_key(struct ieee80211_key *key);
149void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom); 151void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom);
150void ieee80211_key_free_unused(struct ieee80211_key *key); 152void ieee80211_key_free_unused(struct ieee80211_key *key);
151void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx, 153void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx,
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 800e67615e2a..2b608044ae23 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -1051,6 +1051,22 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1051 } 1051 }
1052 } 1052 }
1053 1053
1054 /* Enable Extended Key IDs when driver allowed it, or when it
1055 * supports neither HW crypto nor A-MPDUs
1056 */
1057 if ((!local->ops->set_key &&
1058 !ieee80211_hw_check(hw, AMPDU_AGGREGATION)) ||
1059 ieee80211_hw_check(&local->hw, EXT_KEY_ID_NATIVE))
1060 wiphy_ext_feature_set(local->hw.wiphy,
1061 NL80211_EXT_FEATURE_EXT_KEY_ID);
1062
1063 /* Mac80211 and therefore all cards only using SW crypto are able to
1064 * handle PTK rekeys correctly
1065 */
1066 if (!local->ops->set_key)
1067 wiphy_ext_feature_set(local->hw.wiphy,
1068 NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
1069
1054 /* 1070 /*
1055 * Calculate scan IE length -- we need this to alloc 1071 * Calculate scan IE length -- we need this to alloc
1056 * memory and to subtract from the driver limit. It 1072 * memory and to subtract from the driver limit. It
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index 574c3891c4b2..88535a2e62bc 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -278,6 +278,8 @@ mesh_path_add(struct ieee80211_sub_if_data *sdata, const u8 *dst);
278int mesh_path_add_gate(struct mesh_path *mpath); 278int mesh_path_add_gate(struct mesh_path *mpath);
279int mesh_path_send_to_gates(struct mesh_path *mpath); 279int mesh_path_send_to_gates(struct mesh_path *mpath);
280int mesh_gate_num(struct ieee80211_sub_if_data *sdata); 280int mesh_gate_num(struct ieee80211_sub_if_data *sdata);
281u32 airtime_link_metric_get(struct ieee80211_local *local,
282 struct sta_info *sta);
281 283
282/* Mesh plinks */ 284/* Mesh plinks */
283void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata, 285void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index f7517668e77a..bf8e13cd5fd1 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -318,8 +318,8 @@ void ieee80211s_update_metric(struct ieee80211_local *local,
318 cfg80211_calculate_bitrate(&rinfo)); 318 cfg80211_calculate_bitrate(&rinfo));
319} 319}
320 320
321static u32 airtime_link_metric_get(struct ieee80211_local *local, 321u32 airtime_link_metric_get(struct ieee80211_local *local,
322 struct sta_info *sta) 322 struct sta_info *sta)
323{ 323{
324 /* This should be adjusted for each device */ 324 /* This should be adjusted for each device */
325 int device_constant = 1 << ARITH_SHIFT; 325 int device_constant = 1 << ARITH_SHIFT;
@@ -1130,16 +1130,17 @@ int mesh_nexthop_resolve(struct ieee80211_sub_if_data *sdata,
1130 struct mesh_path *mpath; 1130 struct mesh_path *mpath;
1131 struct sk_buff *skb_to_free = NULL; 1131 struct sk_buff *skb_to_free = NULL;
1132 u8 *target_addr = hdr->addr3; 1132 u8 *target_addr = hdr->addr3;
1133 int err = 0;
1134 1133
1135 /* Nulls are only sent to peers for PS and should be pre-addressed */ 1134 /* Nulls are only sent to peers for PS and should be pre-addressed */
1136 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) 1135 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
1137 return 0; 1136 return 0;
1138 1137
1139 rcu_read_lock(); 1138 /* Allow injected packets to bypass mesh routing */
1140 err = mesh_nexthop_lookup(sdata, skb); 1139 if (info->control.flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP)
1141 if (!err) 1140 return 0;
1142 goto endlookup; 1141
1142 if (!mesh_nexthop_lookup(sdata, skb))
1143 return 0;
1143 1144
1144 /* no nexthop found, start resolving */ 1145 /* no nexthop found, start resolving */
1145 mpath = mesh_path_lookup(sdata, target_addr); 1146 mpath = mesh_path_lookup(sdata, target_addr);
@@ -1147,8 +1148,7 @@ int mesh_nexthop_resolve(struct ieee80211_sub_if_data *sdata,
1147 mpath = mesh_path_add(sdata, target_addr); 1148 mpath = mesh_path_add(sdata, target_addr);
1148 if (IS_ERR(mpath)) { 1149 if (IS_ERR(mpath)) {
1149 mesh_path_discard_frame(sdata, skb); 1150 mesh_path_discard_frame(sdata, skb);
1150 err = PTR_ERR(mpath); 1151 return PTR_ERR(mpath);
1151 goto endlookup;
1152 } 1152 }
1153 } 1153 }
1154 1154
@@ -1161,13 +1161,10 @@ int mesh_nexthop_resolve(struct ieee80211_sub_if_data *sdata,
1161 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; 1161 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1162 ieee80211_set_qos_hdr(sdata, skb); 1162 ieee80211_set_qos_hdr(sdata, skb);
1163 skb_queue_tail(&mpath->frame_queue, skb); 1163 skb_queue_tail(&mpath->frame_queue, skb);
1164 err = -ENOENT;
1165 if (skb_to_free) 1164 if (skb_to_free)
1166 mesh_path_discard_frame(sdata, skb_to_free); 1165 mesh_path_discard_frame(sdata, skb_to_free);
1167 1166
1168endlookup: 1167 return -ENOENT;
1169 rcu_read_unlock();
1170 return err;
1171} 1168}
1172 1169
1173/** 1170/**
@@ -1187,13 +1184,10 @@ int mesh_nexthop_lookup(struct ieee80211_sub_if_data *sdata,
1187 struct sta_info *next_hop; 1184 struct sta_info *next_hop;
1188 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1185 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1189 u8 *target_addr = hdr->addr3; 1186 u8 *target_addr = hdr->addr3;
1190 int err = -ENOENT;
1191 1187
1192 rcu_read_lock();
1193 mpath = mesh_path_lookup(sdata, target_addr); 1188 mpath = mesh_path_lookup(sdata, target_addr);
1194
1195 if (!mpath || !(mpath->flags & MESH_PATH_ACTIVE)) 1189 if (!mpath || !(mpath->flags & MESH_PATH_ACTIVE))
1196 goto endlookup; 1190 return -ENOENT;
1197 1191
1198 if (time_after(jiffies, 1192 if (time_after(jiffies,
1199 mpath->exp_time - 1193 mpath->exp_time -
@@ -1208,12 +1202,10 @@ int mesh_nexthop_lookup(struct ieee80211_sub_if_data *sdata,
1208 memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN); 1202 memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN);
1209 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); 1203 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
1210 ieee80211_mps_set_frame_flags(sdata, next_hop, hdr); 1204 ieee80211_mps_set_frame_flags(sdata, next_hop, hdr);
1211 err = 0; 1205 return 0;
1212 } 1206 }
1213 1207
1214endlookup: 1208 return -ENOENT;
1215 rcu_read_unlock();
1216 return err;
1217} 1209}
1218 1210
1219void mesh_path_timer(struct timer_list *t) 1211void mesh_path_timer(struct timer_list *t)
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index 95eb5064fa91..796b069ad251 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -23,7 +23,7 @@ static void mesh_path_free_rcu(struct mesh_table *tbl, struct mesh_path *mpath);
23static u32 mesh_table_hash(const void *addr, u32 len, u32 seed) 23static u32 mesh_table_hash(const void *addr, u32 len, u32 seed)
24{ 24{
25 /* Use last four bytes of hw addr as hash index */ 25 /* Use last four bytes of hw addr as hash index */
26 return jhash_1word(*(u32 *)(addr+2), seed); 26 return jhash_1word(__get_unaligned_cpu32((u8 *)addr + 2), seed);
27} 27}
28 28
29static const struct rhashtable_params mesh_rht_params = { 29static const struct rhashtable_params mesh_rht_params = {
@@ -217,7 +217,7 @@ static struct mesh_path *mpath_lookup(struct mesh_table *tbl, const u8 *dst,
217{ 217{
218 struct mesh_path *mpath; 218 struct mesh_path *mpath;
219 219
220 mpath = rhashtable_lookup_fast(&tbl->rhead, dst, mesh_rht_params); 220 mpath = rhashtable_lookup(&tbl->rhead, dst, mesh_rht_params);
221 221
222 if (mpath && mpath_expired(mpath)) { 222 if (mpath && mpath_expired(mpath)) {
223 spin_lock_bh(&mpath->state_lock); 223 spin_lock_bh(&mpath->state_lock);
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 2dbcf5d5512e..b7a9fe3d5fcb 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1188,9 +1188,6 @@ static void ieee80211_chswitch_work(struct work_struct *work)
1188 goto out; 1188 goto out;
1189 } 1189 }
1190 1190
1191 /* XXX: shouldn't really modify cfg80211-owned data! */
1192 ifmgd->associated->channel = sdata->csa_chandef.chan;
1193
1194 ifmgd->csa_waiting_bcn = true; 1191 ifmgd->csa_waiting_bcn = true;
1195 1192
1196 ieee80211_sta_reset_beacon_monitor(sdata); 1193 ieee80211_sta_reset_beacon_monitor(sdata);
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
index ccaf951e4e31..8b168724c5e7 100644
--- a/net/mac80211/rc80211_minstrel_ht.c
+++ b/net/mac80211/rc80211_minstrel_ht.c
@@ -51,8 +51,13 @@
51 MINSTREL_MAX_STREAMS * _sgi + \ 51 MINSTREL_MAX_STREAMS * _sgi + \
52 _streams - 1 52 _streams - 1
53 53
54#define _MAX(a, b) (((a)>(b))?(a):(b))
55
56#define GROUP_SHIFT(duration) \
57 _MAX(0, 16 - __builtin_clz(duration))
58
54/* MCS rate information for an MCS group */ 59/* MCS rate information for an MCS group */
55#define MCS_GROUP(_streams, _sgi, _ht40, _s) \ 60#define __MCS_GROUP(_streams, _sgi, _ht40, _s) \
56 [GROUP_IDX(_streams, _sgi, _ht40)] = { \ 61 [GROUP_IDX(_streams, _sgi, _ht40)] = { \
57 .streams = _streams, \ 62 .streams = _streams, \
58 .shift = _s, \ 63 .shift = _s, \
@@ -72,6 +77,13 @@
72 } \ 77 } \
73} 78}
74 79
80#define MCS_GROUP_SHIFT(_streams, _sgi, _ht40) \
81 GROUP_SHIFT(MCS_DURATION(_streams, _sgi, _ht40 ? 54 : 26))
82
83#define MCS_GROUP(_streams, _sgi, _ht40) \
84 __MCS_GROUP(_streams, _sgi, _ht40, \
85 MCS_GROUP_SHIFT(_streams, _sgi, _ht40))
86
75#define VHT_GROUP_IDX(_streams, _sgi, _bw) \ 87#define VHT_GROUP_IDX(_streams, _sgi, _bw) \
76 (MINSTREL_VHT_GROUP_0 + \ 88 (MINSTREL_VHT_GROUP_0 + \
77 MINSTREL_MAX_STREAMS * 2 * (_bw) + \ 89 MINSTREL_MAX_STREAMS * 2 * (_bw) + \
@@ -81,7 +93,7 @@
81#define BW2VBPS(_bw, r3, r2, r1) \ 93#define BW2VBPS(_bw, r3, r2, r1) \
82 (_bw == BW_80 ? r3 : _bw == BW_40 ? r2 : r1) 94 (_bw == BW_80 ? r3 : _bw == BW_40 ? r2 : r1)
83 95
84#define VHT_GROUP(_streams, _sgi, _bw, _s) \ 96#define __VHT_GROUP(_streams, _sgi, _bw, _s) \
85 [VHT_GROUP_IDX(_streams, _sgi, _bw)] = { \ 97 [VHT_GROUP_IDX(_streams, _sgi, _bw)] = { \
86 .streams = _streams, \ 98 .streams = _streams, \
87 .shift = _s, \ 99 .shift = _s, \
@@ -114,6 +126,14 @@
114 } \ 126 } \
115} 127}
116 128
129#define VHT_GROUP_SHIFT(_streams, _sgi, _bw) \
130 GROUP_SHIFT(MCS_DURATION(_streams, _sgi, \
131 BW2VBPS(_bw, 117, 54, 26)))
132
133#define VHT_GROUP(_streams, _sgi, _bw) \
134 __VHT_GROUP(_streams, _sgi, _bw, \
135 VHT_GROUP_SHIFT(_streams, _sgi, _bw))
136
117#define CCK_DURATION(_bitrate, _short, _len) \ 137#define CCK_DURATION(_bitrate, _short, _len) \
118 (1000 * (10 /* SIFS */ + \ 138 (1000 * (10 /* SIFS */ + \
119 (_short ? 72 + 24 : 144 + 48) + \ 139 (_short ? 72 + 24 : 144 + 48) + \
@@ -129,7 +149,7 @@
129 CCK_ACK_DURATION(55, _short) >> _s, \ 149 CCK_ACK_DURATION(55, _short) >> _s, \
130 CCK_ACK_DURATION(110, _short) >> _s 150 CCK_ACK_DURATION(110, _short) >> _s
131 151
132#define CCK_GROUP(_s) \ 152#define __CCK_GROUP(_s) \
133 [MINSTREL_CCK_GROUP] = { \ 153 [MINSTREL_CCK_GROUP] = { \
134 .streams = 1, \ 154 .streams = 1, \
135 .flags = 0, \ 155 .flags = 0, \
@@ -140,6 +160,12 @@
140 } \ 160 } \
141 } 161 }
142 162
163#define CCK_GROUP_SHIFT \
164 GROUP_SHIFT(CCK_ACK_DURATION(10, false))
165
166#define CCK_GROUP __CCK_GROUP(CCK_GROUP_SHIFT)
167
168
143static bool minstrel_vht_only = true; 169static bool minstrel_vht_only = true;
144module_param(minstrel_vht_only, bool, 0644); 170module_param(minstrel_vht_only, bool, 0644);
145MODULE_PARM_DESC(minstrel_vht_only, 171MODULE_PARM_DESC(minstrel_vht_only,
@@ -154,47 +180,57 @@ MODULE_PARM_DESC(minstrel_vht_only,
154 * BW -> SGI -> #streams 180 * BW -> SGI -> #streams
155 */ 181 */
156const struct mcs_group minstrel_mcs_groups[] = { 182const struct mcs_group minstrel_mcs_groups[] = {
157 MCS_GROUP(1, 0, BW_20, 5), 183 MCS_GROUP(1, 0, BW_20),
158 MCS_GROUP(2, 0, BW_20, 4), 184 MCS_GROUP(2, 0, BW_20),
159 MCS_GROUP(3, 0, BW_20, 4), 185 MCS_GROUP(3, 0, BW_20),
160 186 MCS_GROUP(4, 0, BW_20),
161 MCS_GROUP(1, 1, BW_20, 5), 187
162 MCS_GROUP(2, 1, BW_20, 4), 188 MCS_GROUP(1, 1, BW_20),
163 MCS_GROUP(3, 1, BW_20, 4), 189 MCS_GROUP(2, 1, BW_20),
164 190 MCS_GROUP(3, 1, BW_20),
165 MCS_GROUP(1, 0, BW_40, 4), 191 MCS_GROUP(4, 1, BW_20),
166 MCS_GROUP(2, 0, BW_40, 4), 192
167 MCS_GROUP(3, 0, BW_40, 4), 193 MCS_GROUP(1, 0, BW_40),
168 194 MCS_GROUP(2, 0, BW_40),
169 MCS_GROUP(1, 1, BW_40, 4), 195 MCS_GROUP(3, 0, BW_40),
170 MCS_GROUP(2, 1, BW_40, 4), 196 MCS_GROUP(4, 0, BW_40),
171 MCS_GROUP(3, 1, BW_40, 4), 197
172 198 MCS_GROUP(1, 1, BW_40),
173 CCK_GROUP(8), 199 MCS_GROUP(2, 1, BW_40),
174 200 MCS_GROUP(3, 1, BW_40),
175 VHT_GROUP(1, 0, BW_20, 5), 201 MCS_GROUP(4, 1, BW_40),
176 VHT_GROUP(2, 0, BW_20, 4), 202
177 VHT_GROUP(3, 0, BW_20, 4), 203 CCK_GROUP,
178 204
179 VHT_GROUP(1, 1, BW_20, 5), 205 VHT_GROUP(1, 0, BW_20),
180 VHT_GROUP(2, 1, BW_20, 4), 206 VHT_GROUP(2, 0, BW_20),
181 VHT_GROUP(3, 1, BW_20, 4), 207 VHT_GROUP(3, 0, BW_20),
182 208 VHT_GROUP(4, 0, BW_20),
183 VHT_GROUP(1, 0, BW_40, 4), 209
184 VHT_GROUP(2, 0, BW_40, 4), 210 VHT_GROUP(1, 1, BW_20),
185 VHT_GROUP(3, 0, BW_40, 4), 211 VHT_GROUP(2, 1, BW_20),
186 212 VHT_GROUP(3, 1, BW_20),
187 VHT_GROUP(1, 1, BW_40, 4), 213 VHT_GROUP(4, 1, BW_20),
188 VHT_GROUP(2, 1, BW_40, 4), 214
189 VHT_GROUP(3, 1, BW_40, 4), 215 VHT_GROUP(1, 0, BW_40),
190 216 VHT_GROUP(2, 0, BW_40),
191 VHT_GROUP(1, 0, BW_80, 4), 217 VHT_GROUP(3, 0, BW_40),
192 VHT_GROUP(2, 0, BW_80, 4), 218 VHT_GROUP(4, 0, BW_40),
193 VHT_GROUP(3, 0, BW_80, 4), 219
194 220 VHT_GROUP(1, 1, BW_40),
195 VHT_GROUP(1, 1, BW_80, 4), 221 VHT_GROUP(2, 1, BW_40),
196 VHT_GROUP(2, 1, BW_80, 4), 222 VHT_GROUP(3, 1, BW_40),
197 VHT_GROUP(3, 1, BW_80, 4), 223 VHT_GROUP(4, 1, BW_40),
224
225 VHT_GROUP(1, 0, BW_80),
226 VHT_GROUP(2, 0, BW_80),
227 VHT_GROUP(3, 0, BW_80),
228 VHT_GROUP(4, 0, BW_80),
229
230 VHT_GROUP(1, 1, BW_80),
231 VHT_GROUP(2, 1, BW_80),
232 VHT_GROUP(3, 1, BW_80),
233 VHT_GROUP(4, 1, BW_80),
198}; 234};
199 235
200static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly; 236static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES] __read_mostly;
diff --git a/net/mac80211/rc80211_minstrel_ht.h b/net/mac80211/rc80211_minstrel_ht.h
index 26b7a3244b47..f762e5ba7c2e 100644
--- a/net/mac80211/rc80211_minstrel_ht.h
+++ b/net/mac80211/rc80211_minstrel_ht.h
@@ -13,7 +13,7 @@
13 * The number of streams can be changed to 2 to reduce code 13 * The number of streams can be changed to 2 to reduce code
14 * size and memory footprint. 14 * size and memory footprint.
15 */ 15 */
16#define MINSTREL_MAX_STREAMS 3 16#define MINSTREL_MAX_STREAMS 4
17#define MINSTREL_HT_STREAM_GROUPS 4 /* BW(=2) * SGI(=2) */ 17#define MINSTREL_HT_STREAM_GROUPS 4 /* BW(=2) * SGI(=2) */
18#define MINSTREL_VHT_STREAM_GROUPS 6 /* BW(=3) * SGI(=2) */ 18#define MINSTREL_VHT_STREAM_GROUPS 6 /* BW(=3) * SGI(=2) */
19 19
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 7f8d93401ce0..25577ede2986 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1005,23 +1005,43 @@ static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
1005 return -1; 1005 return -1;
1006} 1006}
1007 1007
1008static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs, 1008static int ieee80211_get_keyid(struct sk_buff *skb,
1009 struct sk_buff *skb) 1009 const struct ieee80211_cipher_scheme *cs)
1010{ 1010{
1011 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1011 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1012 __le16 fc; 1012 __le16 fc;
1013 int hdrlen; 1013 int hdrlen;
1014 int minlen;
1015 u8 key_idx_off;
1016 u8 key_idx_shift;
1014 u8 keyid; 1017 u8 keyid;
1015 1018
1016 fc = hdr->frame_control; 1019 fc = hdr->frame_control;
1017 hdrlen = ieee80211_hdrlen(fc); 1020 hdrlen = ieee80211_hdrlen(fc);
1018 1021
1019 if (skb->len < hdrlen + cs->hdr_len) 1022 if (cs) {
1023 minlen = hdrlen + cs->hdr_len;
1024 key_idx_off = hdrlen + cs->key_idx_off;
1025 key_idx_shift = cs->key_idx_shift;
1026 } else {
1027 /* WEP, TKIP, CCMP and GCMP */
1028 minlen = hdrlen + IEEE80211_WEP_IV_LEN;
1029 key_idx_off = hdrlen + 3;
1030 key_idx_shift = 6;
1031 }
1032
1033 if (unlikely(skb->len < minlen))
1020 return -EINVAL; 1034 return -EINVAL;
1021 1035
1022 skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1); 1036 skb_copy_bits(skb, key_idx_off, &keyid, 1);
1023 keyid &= cs->key_idx_mask; 1037
1024 keyid >>= cs->key_idx_shift; 1038 if (cs)
1039 keyid &= cs->key_idx_mask;
1040 keyid >>= key_idx_shift;
1041
1042 /* cs could use more than the usual two bits for the keyid */
1043 if (unlikely(keyid >= NUM_DEFAULT_KEYS))
1044 return -EINVAL;
1025 1045
1026 return keyid; 1046 return keyid;
1027} 1047}
@@ -1568,7 +1588,15 @@ static void sta_ps_start(struct sta_info *sta)
1568 return; 1588 return;
1569 1589
1570 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) { 1590 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1571 if (txq_has_queue(sta->sta.txq[tid])) 1591 struct ieee80211_txq *txq = sta->sta.txq[tid];
1592 struct txq_info *txqi = to_txq_info(txq);
1593
1594 spin_lock(&local->active_txq_lock[txq->ac]);
1595 if (!list_empty(&txqi->schedule_order))
1596 list_del_init(&txqi->schedule_order);
1597 spin_unlock(&local->active_txq_lock[txq->ac]);
1598
1599 if (txq_has_queue(txq))
1572 set_bit(tid, &sta->txq_buffered_tids); 1600 set_bit(tid, &sta->txq_buffered_tids);
1573 else 1601 else
1574 clear_bit(tid, &sta->txq_buffered_tids); 1602 clear_bit(tid, &sta->txq_buffered_tids);
@@ -1852,9 +1880,9 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1852 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); 1880 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1853 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1881 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1854 int keyidx; 1882 int keyidx;
1855 int hdrlen;
1856 ieee80211_rx_result result = RX_DROP_UNUSABLE; 1883 ieee80211_rx_result result = RX_DROP_UNUSABLE;
1857 struct ieee80211_key *sta_ptk = NULL; 1884 struct ieee80211_key *sta_ptk = NULL;
1885 struct ieee80211_key *ptk_idx = NULL;
1858 int mmie_keyidx = -1; 1886 int mmie_keyidx = -1;
1859 __le16 fc; 1887 __le16 fc;
1860 const struct ieee80211_cipher_scheme *cs = NULL; 1888 const struct ieee80211_cipher_scheme *cs = NULL;
@@ -1892,21 +1920,24 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1892 1920
1893 if (rx->sta) { 1921 if (rx->sta) {
1894 int keyid = rx->sta->ptk_idx; 1922 int keyid = rx->sta->ptk_idx;
1923 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1895 1924
1896 if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) { 1925 if (ieee80211_has_protected(fc)) {
1897 cs = rx->sta->cipher_scheme; 1926 cs = rx->sta->cipher_scheme;
1898 keyid = ieee80211_get_cs_keyid(cs, rx->skb); 1927 keyid = ieee80211_get_keyid(rx->skb, cs);
1928
1899 if (unlikely(keyid < 0)) 1929 if (unlikely(keyid < 0))
1900 return RX_DROP_UNUSABLE; 1930 return RX_DROP_UNUSABLE;
1931
1932 ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
1901 } 1933 }
1902 sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1903 } 1934 }
1904 1935
1905 if (!ieee80211_has_protected(fc)) 1936 if (!ieee80211_has_protected(fc))
1906 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb); 1937 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1907 1938
1908 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) { 1939 if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1909 rx->key = sta_ptk; 1940 rx->key = ptk_idx ? ptk_idx : sta_ptk;
1910 if ((status->flag & RX_FLAG_DECRYPTED) && 1941 if ((status->flag & RX_FLAG_DECRYPTED) &&
1911 (status->flag & RX_FLAG_IV_STRIPPED)) 1942 (status->flag & RX_FLAG_IV_STRIPPED))
1912 return RX_CONTINUE; 1943 return RX_CONTINUE;
@@ -1966,8 +1997,6 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1966 } 1997 }
1967 return RX_CONTINUE; 1998 return RX_CONTINUE;
1968 } else { 1999 } else {
1969 u8 keyid;
1970
1971 /* 2000 /*
1972 * The device doesn't give us the IV so we won't be 2001 * The device doesn't give us the IV so we won't be
1973 * able to look up the key. That's ok though, we 2002 * able to look up the key. That's ok though, we
@@ -1981,23 +2010,10 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1981 (status->flag & RX_FLAG_IV_STRIPPED)) 2010 (status->flag & RX_FLAG_IV_STRIPPED))
1982 return RX_CONTINUE; 2011 return RX_CONTINUE;
1983 2012
1984 hdrlen = ieee80211_hdrlen(fc); 2013 keyidx = ieee80211_get_keyid(rx->skb, cs);
1985 2014
1986 if (cs) { 2015 if (unlikely(keyidx < 0))
1987 keyidx = ieee80211_get_cs_keyid(cs, rx->skb); 2016 return RX_DROP_UNUSABLE;
1988
1989 if (unlikely(keyidx < 0))
1990 return RX_DROP_UNUSABLE;
1991 } else {
1992 if (rx->skb->len < 8 + hdrlen)
1993 return RX_DROP_UNUSABLE; /* TODO: count this? */
1994 /*
1995 * no need to call ieee80211_wep_get_keyidx,
1996 * it verifies a bunch of things we've done already
1997 */
1998 skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
1999 keyidx = keyid >> 6;
2000 }
2001 2017
2002 /* check per-station GTK first, if multicast packet */ 2018 /* check per-station GTK first, if multicast packet */
2003 if (is_multicast_ether_addr(hdr->addr1) && rx->sta) 2019 if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
@@ -4042,12 +4058,8 @@ void ieee80211_check_fast_rx(struct sta_info *sta)
4042 case WLAN_CIPHER_SUITE_GCMP_256: 4058 case WLAN_CIPHER_SUITE_GCMP_256:
4043 break; 4059 break;
4044 default: 4060 default:
4045 /* we also don't want to deal with WEP or cipher scheme 4061 /* We also don't want to deal with
4046 * since those require looking up the key idx in the 4062 * WEP or cipher scheme.
4047 * frame, rather than assuming the PTK is used
4048 * (we need to revisit this once we implement the real
4049 * PTK index, which is now valid in the spec, but we
4050 * haven't implemented that part yet)
4051 */ 4063 */
4052 goto clear_rcu; 4064 goto clear_rcu;
4053 } 4065 }
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 11f058987a54..a4932ee3595c 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -347,6 +347,15 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
347 sta->sta.max_rx_aggregation_subframes = 347 sta->sta.max_rx_aggregation_subframes =
348 local->hw.max_rx_aggregation_subframes; 348 local->hw.max_rx_aggregation_subframes;
349 349
350 /* Extended Key ID needs to install keys for keyid 0 and 1 Rx-only.
351 * The Tx path starts to use a key as soon as the key slot ptk_idx
352 * references to is not NULL. To not use the initial Rx-only key
353 * prematurely for Tx initialize ptk_idx to an impossible PTK keyid
354 * which always will refer to a NULL key.
355 */
356 BUILD_BUG_ON(ARRAY_SIZE(sta->ptk) <= INVALID_PTK_KEYIDX);
357 sta->ptk_idx = INVALID_PTK_KEYIDX;
358
350 sta->local = local; 359 sta->local = local;
351 sta->sdata = sdata; 360 sta->sdata = sdata;
352 sta->rx_stats.last_rx = jiffies; 361 sta->rx_stats.last_rx = jiffies;
@@ -2373,6 +2382,12 @@ void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
2373 sinfo->filled |= 2382 sinfo->filled |=
2374 BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG); 2383 BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG);
2375 } 2384 }
2385
2386 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2387 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_LINK_METRIC);
2388 sinfo->airtime_link_metric =
2389 airtime_link_metric_get(local, sta);
2390 }
2376} 2391}
2377 2392
2378u32 sta_get_expected_throughput(struct sta_info *sta) 2393u32 sta_get_expected_throughput(struct sta_info *sta)
diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
index d30690d79a58..24c37f91ca46 100644
--- a/net/mac80211/tdls.c
+++ b/net/mac80211/tdls.c
@@ -1056,7 +1056,7 @@ ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev,
1056 1056
1057 /* disable bottom halves when entering the Tx path */ 1057 /* disable bottom halves when entering the Tx path */
1058 local_bh_disable(); 1058 local_bh_disable();
1059 __ieee80211_subif_start_xmit(skb, dev, flags); 1059 __ieee80211_subif_start_xmit(skb, dev, flags, 0);
1060 local_bh_enable(); 1060 local_bh_enable();
1061 1061
1062 return ret; 1062 return ret;
diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
index 8ba70d26b82e..3bb4459b52c7 100644
--- a/net/mac80211/trace.h
+++ b/net/mac80211/trace.h
@@ -828,6 +828,36 @@ TRACE_EVENT(drv_sta_state,
828 ) 828 )
829); 829);
830 830
831TRACE_EVENT(drv_sta_set_txpwr,
832 TP_PROTO(struct ieee80211_local *local,
833 struct ieee80211_sub_if_data *sdata,
834 struct ieee80211_sta *sta),
835
836 TP_ARGS(local, sdata, sta),
837
838 TP_STRUCT__entry(
839 LOCAL_ENTRY
840 VIF_ENTRY
841 STA_ENTRY
842 __field(s16, txpwr)
843 __field(u8, type)
844 ),
845
846 TP_fast_assign(
847 LOCAL_ASSIGN;
848 VIF_ASSIGN;
849 STA_ASSIGN;
850 __entry->txpwr = sta->txpwr.power;
851 __entry->type = sta->txpwr.type;
852 ),
853
854 TP_printk(
855 LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT " txpwr: %d type %d",
856 LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG,
857 __entry->txpwr, __entry->type
858 )
859);
860
831TRACE_EVENT(drv_sta_rc_update, 861TRACE_EVENT(drv_sta_rc_update,
832 TP_PROTO(struct ieee80211_local *local, 862 TP_PROTO(struct ieee80211_local *local,
833 struct ieee80211_sub_if_data *sdata, 863 struct ieee80211_sub_if_data *sdata,
diff --git a/net/mac80211/trace_msg.h b/net/mac80211/trace_msg.h
index 366b9e6f043e..40141df09f25 100644
--- a/net/mac80211/trace_msg.h
+++ b/net/mac80211/trace_msg.h
@@ -1,4 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Portions of this file
4 * Copyright (C) 2019 Intel Corporation
5 */
6
2#ifdef CONFIG_MAC80211_MESSAGE_TRACING 7#ifdef CONFIG_MAC80211_MESSAGE_TRACING
3 8
4#if !defined(__MAC80211_MSG_DRIVER_TRACE) || defined(TRACE_HEADER_MULTI_READ) 9#if !defined(__MAC80211_MSG_DRIVER_TRACE) || defined(TRACE_HEADER_MULTI_READ)
@@ -11,7 +16,7 @@
11#undef TRACE_SYSTEM 16#undef TRACE_SYSTEM
12#define TRACE_SYSTEM mac80211_msg 17#define TRACE_SYSTEM mac80211_msg
13 18
14#define MAX_MSG_LEN 100 19#define MAX_MSG_LEN 120
15 20
16DECLARE_EVENT_CLASS(mac80211_msg_event, 21DECLARE_EVENT_CLASS(mac80211_msg_event,
17 TP_PROTO(struct va_format *vaf), 22 TP_PROTO(struct va_format *vaf),
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 8a49a74c0a37..dd220b977025 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1399,11 +1399,15 @@ static void ieee80211_txq_enqueue(struct ieee80211_local *local,
1399{ 1399{
1400 struct fq *fq = &local->fq; 1400 struct fq *fq = &local->fq;
1401 struct fq_tin *tin = &txqi->tin; 1401 struct fq_tin *tin = &txqi->tin;
1402 u32 flow_idx = fq_flow_idx(fq, skb);
1402 1403
1403 ieee80211_set_skb_enqueue_time(skb); 1404 ieee80211_set_skb_enqueue_time(skb);
1404 fq_tin_enqueue(fq, tin, skb, 1405
1406 spin_lock_bh(&fq->lock);
1407 fq_tin_enqueue(fq, tin, flow_idx, skb,
1405 fq_skb_free_func, 1408 fq_skb_free_func,
1406 fq_flow_get_default_func); 1409 fq_flow_get_default_func);
1410 spin_unlock_bh(&fq->lock);
1407} 1411}
1408 1412
1409static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin, 1413static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
@@ -1590,7 +1594,6 @@ static bool ieee80211_queue_skb(struct ieee80211_local *local,
1590 struct sta_info *sta, 1594 struct sta_info *sta,
1591 struct sk_buff *skb) 1595 struct sk_buff *skb)
1592{ 1596{
1593 struct fq *fq = &local->fq;
1594 struct ieee80211_vif *vif; 1597 struct ieee80211_vif *vif;
1595 struct txq_info *txqi; 1598 struct txq_info *txqi;
1596 1599
@@ -1608,9 +1611,7 @@ static bool ieee80211_queue_skb(struct ieee80211_local *local,
1608 if (!txqi) 1611 if (!txqi)
1609 return false; 1612 return false;
1610 1613
1611 spin_lock_bh(&fq->lock);
1612 ieee80211_txq_enqueue(local, txqi, skb); 1614 ieee80211_txq_enqueue(local, txqi, skb);
1613 spin_unlock_bh(&fq->lock);
1614 1615
1615 schedule_and_wake_txq(local, txqi); 1616 schedule_and_wake_txq(local, txqi);
1616 1617
@@ -2431,6 +2432,7 @@ static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2431 * @sdata: virtual interface to build the header for 2432 * @sdata: virtual interface to build the header for
2432 * @skb: the skb to build the header in 2433 * @skb: the skb to build the header in
2433 * @info_flags: skb flags to set 2434 * @info_flags: skb flags to set
2435 * @ctrl_flags: info control flags to set
2434 * 2436 *
2435 * This function takes the skb with 802.3 header and reformats the header to 2437 * This function takes the skb with 802.3 header and reformats the header to
2436 * the appropriate IEEE 802.11 header based on which interface the packet is 2438 * the appropriate IEEE 802.11 header based on which interface the packet is
@@ -2446,7 +2448,7 @@ static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2446 */ 2448 */
2447static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, 2449static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2448 struct sk_buff *skb, u32 info_flags, 2450 struct sk_buff *skb, u32 info_flags,
2449 struct sta_info *sta) 2451 struct sta_info *sta, u32 ctrl_flags)
2450{ 2452{
2451 struct ieee80211_local *local = sdata->local; 2453 struct ieee80211_local *local = sdata->local;
2452 struct ieee80211_tx_info *info; 2454 struct ieee80211_tx_info *info;
@@ -2470,6 +2472,11 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2470 if (IS_ERR(sta)) 2472 if (IS_ERR(sta))
2471 sta = NULL; 2473 sta = NULL;
2472 2474
2475#ifdef CONFIG_MAC80211_DEBUGFS
2476 if (local->force_tx_status)
2477 info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2478#endif
2479
2473 /* convert Ethernet header to proper 802.11 header (based on 2480 /* convert Ethernet header to proper 802.11 header (based on
2474 * operation mode) */ 2481 * operation mode) */
2475 ethertype = (skb->data[12] << 8) | skb->data[13]; 2482 ethertype = (skb->data[12] << 8) | skb->data[13];
@@ -2600,6 +2607,13 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2600 goto free; 2607 goto free;
2601 } 2608 }
2602 band = chanctx_conf->def.chan->band; 2609 band = chanctx_conf->def.chan->band;
2610
2611 /* For injected frames, fill RA right away as nexthop lookup
2612 * will be skipped.
2613 */
2614 if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) &&
2615 is_zero_ether_addr(hdr.addr1))
2616 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2603 break; 2617 break;
2604#endif 2618#endif
2605 case NL80211_IFTYPE_STATION: 2619 case NL80211_IFTYPE_STATION:
@@ -2818,6 +2832,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2818 info->flags = info_flags; 2832 info->flags = info_flags;
2819 info->ack_frame_id = info_id; 2833 info->ack_frame_id = info_id;
2820 info->band = band; 2834 info->band = band;
2835 info->control.flags = ctrl_flags;
2821 2836
2822 return skb; 2837 return skb;
2823 free: 2838 free:
@@ -3000,23 +3015,15 @@ void ieee80211_check_fast_xmit(struct sta_info *sta)
3000 switch (build.key->conf.cipher) { 3015 switch (build.key->conf.cipher) {
3001 case WLAN_CIPHER_SUITE_CCMP: 3016 case WLAN_CIPHER_SUITE_CCMP:
3002 case WLAN_CIPHER_SUITE_CCMP_256: 3017 case WLAN_CIPHER_SUITE_CCMP_256:
3003 /* add fixed key ID */ 3018 if (gen_iv)
3004 if (gen_iv) {
3005 (build.hdr + build.hdr_len)[3] =
3006 0x20 | (build.key->conf.keyidx << 6);
3007 build.pn_offs = build.hdr_len; 3019 build.pn_offs = build.hdr_len;
3008 }
3009 if (gen_iv || iv_spc) 3020 if (gen_iv || iv_spc)
3010 build.hdr_len += IEEE80211_CCMP_HDR_LEN; 3021 build.hdr_len += IEEE80211_CCMP_HDR_LEN;
3011 break; 3022 break;
3012 case WLAN_CIPHER_SUITE_GCMP: 3023 case WLAN_CIPHER_SUITE_GCMP:
3013 case WLAN_CIPHER_SUITE_GCMP_256: 3024 case WLAN_CIPHER_SUITE_GCMP_256:
3014 /* add fixed key ID */ 3025 if (gen_iv)
3015 if (gen_iv) {
3016 (build.hdr + build.hdr_len)[3] =
3017 0x20 | (build.key->conf.keyidx << 6);
3018 build.pn_offs = build.hdr_len; 3026 build.pn_offs = build.hdr_len;
3019 }
3020 if (gen_iv || iv_spc) 3027 if (gen_iv || iv_spc)
3021 build.hdr_len += IEEE80211_GCMP_HDR_LEN; 3028 build.hdr_len += IEEE80211_GCMP_HDR_LEN;
3022 break; 3029 break;
@@ -3221,6 +3228,8 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3221 u8 max_subframes = sta->sta.max_amsdu_subframes; 3228 u8 max_subframes = sta->sta.max_amsdu_subframes;
3222 int max_frags = local->hw.max_tx_fragments; 3229 int max_frags = local->hw.max_tx_fragments;
3223 int max_amsdu_len = sta->sta.max_amsdu_len; 3230 int max_amsdu_len = sta->sta.max_amsdu_len;
3231 int orig_truesize;
3232 u32 flow_idx;
3224 __be16 len; 3233 __be16 len;
3225 void *data; 3234 void *data;
3226 bool ret = false; 3235 bool ret = false;
@@ -3249,6 +3258,8 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3249 max_amsdu_len = min_t(int, max_amsdu_len, 3258 max_amsdu_len = min_t(int, max_amsdu_len,
3250 sta->sta.max_tid_amsdu_len[tid]); 3259 sta->sta.max_tid_amsdu_len[tid]);
3251 3260
3261 flow_idx = fq_flow_idx(fq, skb);
3262
3252 spin_lock_bh(&fq->lock); 3263 spin_lock_bh(&fq->lock);
3253 3264
3254 /* TODO: Ideally aggregation should be done on dequeue to remain 3265 /* TODO: Ideally aggregation should be done on dequeue to remain
@@ -3256,11 +3267,13 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3256 */ 3267 */
3257 3268
3258 tin = &txqi->tin; 3269 tin = &txqi->tin;
3259 flow = fq_flow_classify(fq, tin, skb, fq_flow_get_default_func); 3270 flow = fq_flow_classify(fq, tin, flow_idx, skb,
3271 fq_flow_get_default_func);
3260 head = skb_peek_tail(&flow->queue); 3272 head = skb_peek_tail(&flow->queue);
3261 if (!head || skb_is_gso(head)) 3273 if (!head || skb_is_gso(head))
3262 goto out; 3274 goto out;
3263 3275
3276 orig_truesize = head->truesize;
3264 orig_len = head->len; 3277 orig_len = head->len;
3265 3278
3266 if (skb->len + head->len > max_amsdu_len) 3279 if (skb->len + head->len > max_amsdu_len)
@@ -3318,6 +3331,7 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3318 *frag_tail = skb; 3331 *frag_tail = skb;
3319 3332
3320out_recalc: 3333out_recalc:
3334 fq->memory_usage += head->truesize - orig_truesize;
3321 if (head->len != orig_len) { 3335 if (head->len != orig_len) {
3322 flow->backlog += head->len - orig_len; 3336 flow->backlog += head->len - orig_len;
3323 tin->backlog_bytes += head->len - orig_len; 3337 tin->backlog_bytes += head->len - orig_len;
@@ -3383,6 +3397,7 @@ static void ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata,
3383 pn = atomic64_inc_return(&key->conf.tx_pn); 3397 pn = atomic64_inc_return(&key->conf.tx_pn);
3384 crypto_hdr[0] = pn; 3398 crypto_hdr[0] = pn;
3385 crypto_hdr[1] = pn >> 8; 3399 crypto_hdr[1] = pn >> 8;
3400 crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6);
3386 crypto_hdr[4] = pn >> 16; 3401 crypto_hdr[4] = pn >> 16;
3387 crypto_hdr[5] = pn >> 24; 3402 crypto_hdr[5] = pn >> 24;
3388 crypto_hdr[6] = pn >> 32; 3403 crypto_hdr[6] = pn >> 32;
@@ -3475,6 +3490,11 @@ static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3475 (tid_tx ? IEEE80211_TX_CTL_AMPDU : 0); 3490 (tid_tx ? IEEE80211_TX_CTL_AMPDU : 0);
3476 info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT; 3491 info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT;
3477 3492
3493#ifdef CONFIG_MAC80211_DEBUGFS
3494 if (local->force_tx_status)
3495 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
3496#endif
3497
3478 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) { 3498 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3479 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 3499 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3480 *ieee80211_get_qos_ctl(hdr) = tid; 3500 *ieee80211_get_qos_ctl(hdr) = tid;
@@ -3530,6 +3550,7 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
3530 ieee80211_tx_result r; 3550 ieee80211_tx_result r;
3531 struct ieee80211_vif *vif = txq->vif; 3551 struct ieee80211_vif *vif = txq->vif;
3532 3552
3553begin:
3533 spin_lock_bh(&fq->lock); 3554 spin_lock_bh(&fq->lock);
3534 3555
3535 if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags) || 3556 if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags) ||
@@ -3546,11 +3567,12 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
3546 if (skb) 3567 if (skb)
3547 goto out; 3568 goto out;
3548 3569
3549begin:
3550 skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func); 3570 skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func);
3551 if (!skb) 3571 if (!skb)
3552 goto out; 3572 goto out;
3553 3573
3574 spin_unlock_bh(&fq->lock);
3575
3554 hdr = (struct ieee80211_hdr *)skb->data; 3576 hdr = (struct ieee80211_hdr *)skb->data;
3555 info = IEEE80211_SKB_CB(skb); 3577 info = IEEE80211_SKB_CB(skb);
3556 3578
@@ -3595,8 +3617,11 @@ begin:
3595 3617
3596 skb = __skb_dequeue(&tx.skbs); 3618 skb = __skb_dequeue(&tx.skbs);
3597 3619
3598 if (!skb_queue_empty(&tx.skbs)) 3620 if (!skb_queue_empty(&tx.skbs)) {
3621 spin_lock_bh(&fq->lock);
3599 skb_queue_splice_tail(&tx.skbs, &txqi->frags); 3622 skb_queue_splice_tail(&tx.skbs, &txqi->frags);
3623 spin_unlock_bh(&fq->lock);
3624 }
3600 } 3625 }
3601 3626
3602 if (skb_has_frag_list(skb) && 3627 if (skb_has_frag_list(skb) &&
@@ -3635,6 +3660,7 @@ begin:
3635 } 3660 }
3636 3661
3637 IEEE80211_SKB_CB(skb)->control.vif = vif; 3662 IEEE80211_SKB_CB(skb)->control.vif = vif;
3663 return skb;
3638 3664
3639out: 3665out:
3640 spin_unlock_bh(&fq->lock); 3666 spin_unlock_bh(&fq->lock);
@@ -3646,16 +3672,17 @@ EXPORT_SYMBOL(ieee80211_tx_dequeue);
3646struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac) 3672struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
3647{ 3673{
3648 struct ieee80211_local *local = hw_to_local(hw); 3674 struct ieee80211_local *local = hw_to_local(hw);
3675 struct ieee80211_txq *ret = NULL;
3649 struct txq_info *txqi = NULL; 3676 struct txq_info *txqi = NULL;
3650 3677
3651 lockdep_assert_held(&local->active_txq_lock[ac]); 3678 spin_lock_bh(&local->active_txq_lock[ac]);
3652 3679
3653 begin: 3680 begin:
3654 txqi = list_first_entry_or_null(&local->active_txqs[ac], 3681 txqi = list_first_entry_or_null(&local->active_txqs[ac],
3655 struct txq_info, 3682 struct txq_info,
3656 schedule_order); 3683 schedule_order);
3657 if (!txqi) 3684 if (!txqi)
3658 return NULL; 3685 goto out;
3659 3686
3660 if (txqi->txq.sta) { 3687 if (txqi->txq.sta) {
3661 struct sta_info *sta = container_of(txqi->txq.sta, 3688 struct sta_info *sta = container_of(txqi->txq.sta,
@@ -3672,24 +3699,30 @@ struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
3672 3699
3673 3700
3674 if (txqi->schedule_round == local->schedule_round[ac]) 3701 if (txqi->schedule_round == local->schedule_round[ac])
3675 return NULL; 3702 goto out;
3676 3703
3677 list_del_init(&txqi->schedule_order); 3704 list_del_init(&txqi->schedule_order);
3678 txqi->schedule_round = local->schedule_round[ac]; 3705 txqi->schedule_round = local->schedule_round[ac];
3679 return &txqi->txq; 3706 ret = &txqi->txq;
3707
3708out:
3709 spin_unlock_bh(&local->active_txq_lock[ac]);
3710 return ret;
3680} 3711}
3681EXPORT_SYMBOL(ieee80211_next_txq); 3712EXPORT_SYMBOL(ieee80211_next_txq);
3682 3713
3683void ieee80211_return_txq(struct ieee80211_hw *hw, 3714void __ieee80211_schedule_txq(struct ieee80211_hw *hw,
3684 struct ieee80211_txq *txq) 3715 struct ieee80211_txq *txq,
3716 bool force)
3685{ 3717{
3686 struct ieee80211_local *local = hw_to_local(hw); 3718 struct ieee80211_local *local = hw_to_local(hw);
3687 struct txq_info *txqi = to_txq_info(txq); 3719 struct txq_info *txqi = to_txq_info(txq);
3688 3720
3689 lockdep_assert_held(&local->active_txq_lock[txq->ac]); 3721 spin_lock_bh(&local->active_txq_lock[txq->ac]);
3690 3722
3691 if (list_empty(&txqi->schedule_order) && 3723 if (list_empty(&txqi->schedule_order) &&
3692 (!skb_queue_empty(&txqi->frags) || txqi->tin.backlog_packets)) { 3724 (force || !skb_queue_empty(&txqi->frags) ||
3725 txqi->tin.backlog_packets)) {
3693 /* If airtime accounting is active, always enqueue STAs at the 3726 /* If airtime accounting is active, always enqueue STAs at the
3694 * head of the list to ensure that they only get moved to the 3727 * head of the list to ensure that they only get moved to the
3695 * back by the airtime DRR scheduler once they have a negative 3728 * back by the airtime DRR scheduler once they have a negative
@@ -3706,20 +3739,10 @@ void ieee80211_return_txq(struct ieee80211_hw *hw,
3706 list_add_tail(&txqi->schedule_order, 3739 list_add_tail(&txqi->schedule_order,
3707 &local->active_txqs[txq->ac]); 3740 &local->active_txqs[txq->ac]);
3708 } 3741 }
3709}
3710EXPORT_SYMBOL(ieee80211_return_txq);
3711 3742
3712void ieee80211_schedule_txq(struct ieee80211_hw *hw,
3713 struct ieee80211_txq *txq)
3714 __acquires(txq_lock) __releases(txq_lock)
3715{
3716 struct ieee80211_local *local = hw_to_local(hw);
3717
3718 spin_lock_bh(&local->active_txq_lock[txq->ac]);
3719 ieee80211_return_txq(hw, txq);
3720 spin_unlock_bh(&local->active_txq_lock[txq->ac]); 3743 spin_unlock_bh(&local->active_txq_lock[txq->ac]);
3721} 3744}
3722EXPORT_SYMBOL(ieee80211_schedule_txq); 3745EXPORT_SYMBOL(__ieee80211_schedule_txq);
3723 3746
3724bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw, 3747bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
3725 struct ieee80211_txq *txq) 3748 struct ieee80211_txq *txq)
@@ -3729,7 +3752,7 @@ bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
3729 struct sta_info *sta; 3752 struct sta_info *sta;
3730 u8 ac = txq->ac; 3753 u8 ac = txq->ac;
3731 3754
3732 lockdep_assert_held(&local->active_txq_lock[ac]); 3755 spin_lock_bh(&local->active_txq_lock[ac]);
3733 3756
3734 if (!txqi->txq.sta) 3757 if (!txqi->txq.sta)
3735 goto out; 3758 goto out;
@@ -3759,40 +3782,35 @@ bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
3759 3782
3760 sta->airtime[ac].deficit += sta->airtime_weight; 3783 sta->airtime[ac].deficit += sta->airtime_weight;
3761 list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]); 3784 list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]);
3785 spin_unlock_bh(&local->active_txq_lock[ac]);
3762 3786
3763 return false; 3787 return false;
3764out: 3788out:
3765 if (!list_empty(&txqi->schedule_order)) 3789 if (!list_empty(&txqi->schedule_order))
3766 list_del_init(&txqi->schedule_order); 3790 list_del_init(&txqi->schedule_order);
3791 spin_unlock_bh(&local->active_txq_lock[ac]);
3767 3792
3768 return true; 3793 return true;
3769} 3794}
3770EXPORT_SYMBOL(ieee80211_txq_may_transmit); 3795EXPORT_SYMBOL(ieee80211_txq_may_transmit);
3771 3796
3772void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) 3797void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
3773 __acquires(txq_lock)
3774{ 3798{
3775 struct ieee80211_local *local = hw_to_local(hw); 3799 struct ieee80211_local *local = hw_to_local(hw);
3776 3800
3777 spin_lock_bh(&local->active_txq_lock[ac]); 3801 spin_lock_bh(&local->active_txq_lock[ac]);
3778 local->schedule_round[ac]++; 3802 local->schedule_round[ac]++;
3779}
3780EXPORT_SYMBOL(ieee80211_txq_schedule_start);
3781
3782void ieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)
3783 __releases(txq_lock)
3784{
3785 struct ieee80211_local *local = hw_to_local(hw);
3786
3787 spin_unlock_bh(&local->active_txq_lock[ac]); 3803 spin_unlock_bh(&local->active_txq_lock[ac]);
3788} 3804}
3789EXPORT_SYMBOL(ieee80211_txq_schedule_end); 3805EXPORT_SYMBOL(ieee80211_txq_schedule_start);
3790 3806
3791void __ieee80211_subif_start_xmit(struct sk_buff *skb, 3807void __ieee80211_subif_start_xmit(struct sk_buff *skb,
3792 struct net_device *dev, 3808 struct net_device *dev,
3793 u32 info_flags) 3809 u32 info_flags,
3810 u32 ctrl_flags)
3794{ 3811{
3795 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3812 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3813 struct ieee80211_local *local = sdata->local;
3796 struct sta_info *sta; 3814 struct sta_info *sta;
3797 struct sk_buff *next; 3815 struct sk_buff *next;
3798 3816
@@ -3806,7 +3824,15 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb,
3806 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) 3824 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
3807 goto out_free; 3825 goto out_free;
3808 3826
3809 if (!IS_ERR_OR_NULL(sta)) { 3827 if (IS_ERR(sta))
3828 sta = NULL;
3829
3830 if (local->ops->wake_tx_queue) {
3831 u16 queue = __ieee80211_select_queue(sdata, sta, skb);
3832 skb_set_queue_mapping(skb, queue);
3833 }
3834
3835 if (sta) {
3810 struct ieee80211_fast_tx *fast_tx; 3836 struct ieee80211_fast_tx *fast_tx;
3811 3837
3812 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift); 3838 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
@@ -3855,7 +3881,8 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb,
3855 skb->prev = NULL; 3881 skb->prev = NULL;
3856 skb->next = NULL; 3882 skb->next = NULL;
3857 3883
3858 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta); 3884 skb = ieee80211_build_hdr(sdata, skb, info_flags,
3885 sta, ctrl_flags);
3859 if (IS_ERR(skb)) 3886 if (IS_ERR(skb))
3860 goto out; 3887 goto out;
3861 3888
@@ -3995,9 +4022,9 @@ netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
3995 __skb_queue_head_init(&queue); 4022 __skb_queue_head_init(&queue);
3996 ieee80211_convert_to_unicast(skb, dev, &queue); 4023 ieee80211_convert_to_unicast(skb, dev, &queue);
3997 while ((skb = __skb_dequeue(&queue))) 4024 while ((skb = __skb_dequeue(&queue)))
3998 __ieee80211_subif_start_xmit(skb, dev, 0); 4025 __ieee80211_subif_start_xmit(skb, dev, 0, 0);
3999 } else { 4026 } else {
4000 __ieee80211_subif_start_xmit(skb, dev, 0); 4027 __ieee80211_subif_start_xmit(skb, dev, 0, 0);
4001 } 4028 }
4002 4029
4003 return NETDEV_TX_OK; 4030 return NETDEV_TX_OK;
@@ -4022,7 +4049,7 @@ ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
4022 goto out; 4049 goto out;
4023 } 4050 }
4024 4051
4025 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta); 4052 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta, 0);
4026 if (IS_ERR(skb)) 4053 if (IS_ERR(skb))
4027 goto out; 4054 goto out;
4028 4055
@@ -5059,7 +5086,36 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
5059 skb_reset_mac_header(skb); 5086 skb_reset_mac_header(skb);
5060 5087
5061 local_bh_disable(); 5088 local_bh_disable();
5062 __ieee80211_subif_start_xmit(skb, skb->dev, flags); 5089 __ieee80211_subif_start_xmit(skb, skb->dev, flags, 0);
5090 local_bh_enable();
5091
5092 return 0;
5093}
5094
5095int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
5096 const u8 *buf, size_t len)
5097{
5098 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5099 struct ieee80211_local *local = sdata->local;
5100 struct sk_buff *skb;
5101
5102 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len +
5103 30 + /* header size */
5104 18); /* 11s header size */
5105 if (!skb)
5106 return -ENOMEM;
5107
5108 skb_reserve(skb, local->hw.extra_tx_headroom);
5109 skb_put_data(skb, buf, len);
5110
5111 skb->dev = dev;
5112 skb->protocol = htons(ETH_P_802_3);
5113 skb_reset_network_header(skb);
5114 skb_reset_mac_header(skb);
5115
5116 local_bh_disable();
5117 __ieee80211_subif_start_xmit(skb, skb->dev, 0,
5118 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP);
5063 local_bh_enable(); 5119 local_bh_enable();
5064 5120
5065 return 0; 5121 return 0;
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 4c1655972565..cba4633cd6cf 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -894,10 +894,10 @@ EXPORT_SYMBOL(ieee80211_queue_delayed_work);
894static u32 894static u32
895_ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action, 895_ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
896 struct ieee802_11_elems *elems, 896 struct ieee802_11_elems *elems,
897 u64 filter, u32 crc, u8 *transmitter_bssid, 897 u64 filter, u32 crc,
898 u8 *bss_bssid) 898 const struct element *check_inherit)
899{ 899{
900 const struct element *elem, *sub; 900 const struct element *elem;
901 bool calc_crc = filter != 0; 901 bool calc_crc = filter != 0;
902 DECLARE_BITMAP(seen_elems, 256); 902 DECLARE_BITMAP(seen_elems, 256);
903 const u8 *ie; 903 const u8 *ie;
@@ -910,6 +910,11 @@ _ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
910 u8 elen = elem->datalen; 910 u8 elen = elem->datalen;
911 const u8 *pos = elem->data; 911 const u8 *pos = elem->data;
912 912
913 if (check_inherit &&
914 !cfg80211_is_element_inherited(elem,
915 check_inherit))
916 continue;
917
913 switch (id) { 918 switch (id) {
914 case WLAN_EID_SSID: 919 case WLAN_EID_SSID:
915 case WLAN_EID_SUPP_RATES: 920 case WLAN_EID_SUPP_RATES:
@@ -1208,57 +1213,6 @@ _ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
1208 if (elen >= sizeof(*elems->max_idle_period_ie)) 1213 if (elen >= sizeof(*elems->max_idle_period_ie))
1209 elems->max_idle_period_ie = (void *)pos; 1214 elems->max_idle_period_ie = (void *)pos;
1210 break; 1215 break;
1211 case WLAN_EID_MULTIPLE_BSSID:
1212 if (!bss_bssid || !transmitter_bssid || elen < 4)
1213 break;
1214
1215 elems->max_bssid_indicator = pos[0];
1216
1217 for_each_element(sub, pos + 1, elen - 1) {
1218 u8 sub_len = sub->datalen;
1219 u8 new_bssid[ETH_ALEN];
1220 const u8 *index;
1221
1222 /*
1223 * we only expect the "non-transmitted BSSID
1224 * profile" subelement (subelement id 0)
1225 */
1226 if (sub->id != 0 || sub->datalen < 4) {
1227 /* not a valid BSS profile */
1228 continue;
1229 }
1230
1231 if (sub->data[0] != WLAN_EID_NON_TX_BSSID_CAP ||
1232 sub->data[1] != 2) {
1233 /* The first element of the
1234 * Nontransmitted BSSID Profile is not
1235 * the Nontransmitted BSSID Capability
1236 * element.
1237 */
1238 continue;
1239 }
1240
1241 /* found a Nontransmitted BSSID Profile */
1242 index = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX,
1243 sub->data, sub_len);
1244 if (!index || index[1] < 1 || index[2] == 0) {
1245 /* Invalid MBSSID Index element */
1246 continue;
1247 }
1248
1249 cfg80211_gen_new_bssid(transmitter_bssid,
1250 pos[0],
1251 index[2],
1252 new_bssid);
1253 if (ether_addr_equal(new_bssid, bss_bssid)) {
1254 elems->nontransmitted_bssid_profile =
1255 (void *)sub;
1256 elems->bssid_index_len = index[1];
1257 elems->bssid_index = (void *)&index[2];
1258 break;
1259 }
1260 }
1261 break;
1262 case WLAN_EID_EXTENSION: 1216 case WLAN_EID_EXTENSION:
1263 if (pos[0] == WLAN_EID_EXT_HE_MU_EDCA && 1217 if (pos[0] == WLAN_EID_EXT_HE_MU_EDCA &&
1264 elen >= (sizeof(*elems->mu_edca_param_set) + 1)) { 1218 elen >= (sizeof(*elems->mu_edca_param_set) + 1)) {
@@ -1300,26 +1254,108 @@ _ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
1300 return crc; 1254 return crc;
1301} 1255}
1302 1256
1257static size_t ieee802_11_find_bssid_profile(const u8 *start, size_t len,
1258 struct ieee802_11_elems *elems,
1259 u8 *transmitter_bssid,
1260 u8 *bss_bssid,
1261 u8 *nontransmitted_profile)
1262{
1263 const struct element *elem, *sub;
1264 size_t profile_len = 0;
1265 bool found = false;
1266
1267 if (!bss_bssid || !transmitter_bssid)
1268 return profile_len;
1269
1270 for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, start, len) {
1271 if (elem->datalen < 2)
1272 continue;
1273
1274 for_each_element(sub, elem->data + 1, elem->datalen - 1) {
1275 u8 new_bssid[ETH_ALEN];
1276 const u8 *index;
1277
1278 if (sub->id != 0 || sub->datalen < 4) {
1279 /* not a valid BSS profile */
1280 continue;
1281 }
1282
1283 if (sub->data[0] != WLAN_EID_NON_TX_BSSID_CAP ||
1284 sub->data[1] != 2) {
1285 /* The first element of the
1286 * Nontransmitted BSSID Profile is not
1287 * the Nontransmitted BSSID Capability
1288 * element.
1289 */
1290 continue;
1291 }
1292
1293 memset(nontransmitted_profile, 0, len);
1294 profile_len = cfg80211_merge_profile(start, len,
1295 elem,
1296 sub,
1297 nontransmitted_profile,
1298 len);
1299
1300 /* found a Nontransmitted BSSID Profile */
1301 index = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX,
1302 nontransmitted_profile,
1303 profile_len);
1304 if (!index || index[1] < 1 || index[2] == 0) {
1305 /* Invalid MBSSID Index element */
1306 continue;
1307 }
1308
1309 cfg80211_gen_new_bssid(transmitter_bssid,
1310 elem->data[0],
1311 index[2],
1312 new_bssid);
1313 if (ether_addr_equal(new_bssid, bss_bssid)) {
1314 found = true;
1315 elems->bssid_index_len = index[1];
1316 elems->bssid_index = (void *)&index[2];
1317 break;
1318 }
1319 }
1320 }
1321
1322 return found ? profile_len : 0;
1323}
1324
1303u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action, 1325u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
1304 struct ieee802_11_elems *elems, 1326 struct ieee802_11_elems *elems,
1305 u64 filter, u32 crc, u8 *transmitter_bssid, 1327 u64 filter, u32 crc, u8 *transmitter_bssid,
1306 u8 *bss_bssid) 1328 u8 *bss_bssid)
1307{ 1329{
1330 const struct element *non_inherit = NULL;
1331 u8 *nontransmitted_profile;
1332 int nontransmitted_profile_len = 0;
1333
1308 memset(elems, 0, sizeof(*elems)); 1334 memset(elems, 0, sizeof(*elems));
1309 elems->ie_start = start; 1335 elems->ie_start = start;
1310 elems->total_len = len; 1336 elems->total_len = len;
1311 1337
1338 nontransmitted_profile = kmalloc(len, GFP_ATOMIC);
1339 if (nontransmitted_profile) {
1340 nontransmitted_profile_len =
1341 ieee802_11_find_bssid_profile(start, len, elems,
1342 transmitter_bssid,
1343 bss_bssid,
1344 nontransmitted_profile);
1345 non_inherit =
1346 cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
1347 nontransmitted_profile,
1348 nontransmitted_profile_len);
1349 }
1350
1312 crc = _ieee802_11_parse_elems_crc(start, len, action, elems, filter, 1351 crc = _ieee802_11_parse_elems_crc(start, len, action, elems, filter,
1313 crc, transmitter_bssid, bss_bssid); 1352 crc, non_inherit);
1314 1353
1315 /* Override with nontransmitted profile, if found */ 1354 /* Override with nontransmitted profile, if found */
1316 if (transmitter_bssid && elems->nontransmitted_bssid_profile) { 1355 if (nontransmitted_profile_len)
1317 const u8 *profile = elems->nontransmitted_bssid_profile; 1356 _ieee802_11_parse_elems_crc(nontransmitted_profile,
1318 1357 nontransmitted_profile_len,
1319 _ieee802_11_parse_elems_crc(&profile[2], profile[1], 1358 action, elems, 0, 0, NULL);
1320 action, elems, 0, 0,
1321 transmitter_bssid, bss_bssid);
1322 }
1323 1359
1324 if (elems->tim && !elems->parse_error) { 1360 if (elems->tim && !elems->parse_error) {
1325 const struct ieee80211_tim_ie *tim_ie = elems->tim; 1361 const struct ieee80211_tim_ie *tim_ie = elems->tim;
@@ -1339,6 +1375,8 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
1339 offsetofend(struct ieee80211_bssid_index, dtim_count)) 1375 offsetofend(struct ieee80211_bssid_index, dtim_count))
1340 elems->dtim_count = elems->bssid_index->dtim_count; 1376 elems->dtim_count = elems->bssid_index->dtim_count;
1341 1377
1378 kfree(nontransmitted_profile);
1379
1342 return crc; 1380 return crc;
1343} 1381}
1344 1382
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 5f7c96368b11..6a3187883c4b 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -141,6 +141,42 @@ u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata,
141 return ieee80211_downgrade_queue(sdata, NULL, skb); 141 return ieee80211_downgrade_queue(sdata, NULL, skb);
142} 142}
143 143
144u16 __ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
145 struct sta_info *sta, struct sk_buff *skb)
146{
147 struct mac80211_qos_map *qos_map;
148 bool qos;
149
150 /* all mesh/ocb stations are required to support WME */
151 if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
152 sdata->vif.type == NL80211_IFTYPE_OCB)
153 qos = true;
154 else if (sta)
155 qos = sta->sta.wme;
156 else
157 qos = false;
158
159 if (!qos) {
160 skb->priority = 0; /* required for correct WPA/11i MIC */
161 return IEEE80211_AC_BE;
162 }
163
164 if (skb->protocol == sdata->control_port_protocol) {
165 skb->priority = 7;
166 goto downgrade;
167 }
168
169 /* use the data classifier to determine what 802.1d tag the
170 * data frame has */
171 qos_map = rcu_dereference(sdata->qos_map);
172 skb->priority = cfg80211_classify8021d(skb, qos_map ?
173 &qos_map->qos_map : NULL);
174
175 downgrade:
176 return ieee80211_downgrade_queue(sdata, sta, skb);
177}
178
179
144/* Indicate which queue to use. */ 180/* Indicate which queue to use. */
145u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata, 181u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
146 struct sk_buff *skb) 182 struct sk_buff *skb)
@@ -148,10 +184,12 @@ u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
148 struct ieee80211_local *local = sdata->local; 184 struct ieee80211_local *local = sdata->local;
149 struct sta_info *sta = NULL; 185 struct sta_info *sta = NULL;
150 const u8 *ra = NULL; 186 const u8 *ra = NULL;
151 bool qos = false;
152 struct mac80211_qos_map *qos_map;
153 u16 ret; 187 u16 ret;
154 188
189 /* when using iTXQ, we can do this later */
190 if (local->ops->wake_tx_queue)
191 return 0;
192
155 if (local->hw.queues < IEEE80211_NUM_ACS || skb->len < 6) { 193 if (local->hw.queues < IEEE80211_NUM_ACS || skb->len < 6) {
156 skb->priority = 0; /* required for correct WPA/11i MIC */ 194 skb->priority = 0; /* required for correct WPA/11i MIC */
157 return 0; 195 return 0;
@@ -161,10 +199,8 @@ u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
161 switch (sdata->vif.type) { 199 switch (sdata->vif.type) {
162 case NL80211_IFTYPE_AP_VLAN: 200 case NL80211_IFTYPE_AP_VLAN:
163 sta = rcu_dereference(sdata->u.vlan.sta); 201 sta = rcu_dereference(sdata->u.vlan.sta);
164 if (sta) { 202 if (sta)
165 qos = sta->sta.wme;
166 break; 203 break;
167 }
168 /* fall through */ 204 /* fall through */
169 case NL80211_IFTYPE_AP: 205 case NL80211_IFTYPE_AP:
170 ra = skb->data; 206 ra = skb->data;
@@ -172,56 +208,26 @@ u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
172 case NL80211_IFTYPE_WDS: 208 case NL80211_IFTYPE_WDS:
173 ra = sdata->u.wds.remote_addr; 209 ra = sdata->u.wds.remote_addr;
174 break; 210 break;
175#ifdef CONFIG_MAC80211_MESH
176 case NL80211_IFTYPE_MESH_POINT:
177 qos = true;
178 break;
179#endif
180 case NL80211_IFTYPE_STATION: 211 case NL80211_IFTYPE_STATION:
181 /* might be a TDLS station */ 212 /* might be a TDLS station */
182 sta = sta_info_get(sdata, skb->data); 213 sta = sta_info_get(sdata, skb->data);
183 if (sta) 214 if (sta)
184 qos = sta->sta.wme; 215 break;
185 216
186 ra = sdata->u.mgd.bssid; 217 ra = sdata->u.mgd.bssid;
187 break; 218 break;
188 case NL80211_IFTYPE_ADHOC: 219 case NL80211_IFTYPE_ADHOC:
189 ra = skb->data; 220 ra = skb->data;
190 break; 221 break;
191 case NL80211_IFTYPE_OCB:
192 /* all stations are required to support WME */
193 qos = true;
194 break;
195 default: 222 default:
196 break; 223 break;
197 } 224 }
198 225
199 if (!sta && ra && !is_multicast_ether_addr(ra)) { 226 if (!sta && ra && !is_multicast_ether_addr(ra))
200 sta = sta_info_get(sdata, ra); 227 sta = sta_info_get(sdata, ra);
201 if (sta)
202 qos = sta->sta.wme;
203 }
204 228
205 if (!qos) { 229 ret = __ieee80211_select_queue(sdata, sta, skb);
206 skb->priority = 0; /* required for correct WPA/11i MIC */
207 ret = IEEE80211_AC_BE;
208 goto out;
209 }
210 230
211 if (skb->protocol == sdata->control_port_protocol) {
212 skb->priority = 7;
213 goto downgrade;
214 }
215
216 /* use the data classifier to determine what 802.1d tag the
217 * data frame has */
218 qos_map = rcu_dereference(sdata->qos_map);
219 skb->priority = cfg80211_classify8021d(skb, qos_map ?
220 &qos_map->qos_map : NULL);
221
222 downgrade:
223 ret = ieee80211_downgrade_queue(sdata, sta, skb);
224 out:
225 rcu_read_unlock(); 231 rcu_read_unlock();
226 return ret; 232 return ret;
227} 233}
diff --git a/net/mac80211/wme.h b/net/mac80211/wme.h
index 80151edc5195..b1b1439cb91b 100644
--- a/net/mac80211/wme.h
+++ b/net/mac80211/wme.h
@@ -16,6 +16,8 @@
16u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata, 16u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata,
17 struct sk_buff *skb, 17 struct sk_buff *skb,
18 struct ieee80211_hdr *hdr); 18 struct ieee80211_hdr *hdr);
19u16 __ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
20 struct sta_info *sta, struct sk_buff *skb);
19u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata, 21u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
20 struct sk_buff *skb); 22 struct sk_buff *skb);
21void ieee80211_set_qos_hdr(struct ieee80211_sub_if_data *sdata, 23void ieee80211_set_qos_hdr(struct ieee80211_sub_if_data *sdata,
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index f7c544592ec8..baa098291fb0 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -22,8 +22,8 @@
22#if IS_ENABLED(CONFIG_IPV6) 22#if IS_ENABLED(CONFIG_IPV6)
23#include <net/ipv6.h> 23#include <net/ipv6.h>
24#endif 24#endif
25#include <net/addrconf.h> 25#include <net/ipv6_stubs.h>
26#include <net/nexthop.h> 26#include <net/rtnh.h>
27#include "internal.h" 27#include "internal.h"
28 28
29/* max memory we will use for mpls_route */ 29/* max memory we will use for mpls_route */
@@ -1223,11 +1223,13 @@ static int mpls_netconf_valid_get_req(struct sk_buff *skb,
1223 } 1223 }
1224 1224
1225 if (!netlink_strict_get_check(skb)) 1225 if (!netlink_strict_get_check(skb))
1226 return nlmsg_parse(nlh, sizeof(struct netconfmsg), tb, 1226 return nlmsg_parse_deprecated(nlh, sizeof(struct netconfmsg),
1227 NETCONFA_MAX, devconf_mpls_policy, extack); 1227 tb, NETCONFA_MAX,
1228 devconf_mpls_policy, extack);
1228 1229
1229 err = nlmsg_parse_strict(nlh, sizeof(struct netconfmsg), tb, 1230 err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct netconfmsg),
1230 NETCONFA_MAX, devconf_mpls_policy, extack); 1231 tb, NETCONFA_MAX,
1232 devconf_mpls_policy, extack);
1231 if (err) 1233 if (err)
1232 return err; 1234 return err;
1233 1235
@@ -1788,8 +1790,8 @@ static int rtm_to_route_config(struct sk_buff *skb,
1788 int index; 1790 int index;
1789 int err; 1791 int err;
1790 1792
1791 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_mpls_policy, 1793 err = nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
1792 extack); 1794 rtm_mpls_policy, extack);
1793 if (err < 0) 1795 if (err < 0)
1794 goto errout; 1796 goto errout;
1795 1797
@@ -2017,7 +2019,7 @@ static int mpls_dump_route(struct sk_buff *skb, u32 portid, u32 seq, int event,
2017 u8 linkdown = 0; 2019 u8 linkdown = 0;
2018 u8 dead = 0; 2020 u8 dead = 0;
2019 2021
2020 mp = nla_nest_start(skb, RTA_MULTIPATH); 2022 mp = nla_nest_start_noflag(skb, RTA_MULTIPATH);
2021 if (!mp) 2023 if (!mp)
2022 goto nla_put_failure; 2024 goto nla_put_failure;
2023 2025
@@ -2106,8 +2108,8 @@ static int mpls_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
2106 cb->answer_flags = NLM_F_DUMP_FILTERED; 2108 cb->answer_flags = NLM_F_DUMP_FILTERED;
2107 } 2109 }
2108 2110
2109 err = nlmsg_parse_strict(nlh, sizeof(*rtm), tb, RTA_MAX, 2111 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX,
2110 rtm_mpls_policy, extack); 2112 rtm_mpls_policy, extack);
2111 if (err < 0) 2113 if (err < 0)
2112 return err; 2114 return err;
2113 2115
@@ -2290,8 +2292,8 @@ static int mpls_valid_getroute_req(struct sk_buff *skb,
2290 } 2292 }
2291 2293
2292 if (!netlink_strict_get_check(skb)) 2294 if (!netlink_strict_get_check(skb))
2293 return nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, 2295 return nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
2294 rtm_mpls_policy, extack); 2296 rtm_mpls_policy, extack);
2295 2297
2296 rtm = nlmsg_data(nlh); 2298 rtm = nlmsg_data(nlh);
2297 if ((rtm->rtm_dst_len && rtm->rtm_dst_len != 20) || 2299 if ((rtm->rtm_dst_len && rtm->rtm_dst_len != 20) ||
@@ -2306,8 +2308,8 @@ static int mpls_valid_getroute_req(struct sk_buff *skb,
2306 return -EINVAL; 2308 return -EINVAL;
2307 } 2309 }
2308 2310
2309 err = nlmsg_parse_strict(nlh, sizeof(*rtm), tb, RTA_MAX, 2311 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX,
2310 rtm_mpls_policy, extack); 2312 rtm_mpls_policy, extack);
2311 if (err) 2313 if (err)
2312 return err; 2314 return err;
2313 2315
diff --git a/net/mpls/mpls_iptunnel.c b/net/mpls/mpls_iptunnel.c
index f3a8557494d6..951b52d5835b 100644
--- a/net/mpls/mpls_iptunnel.c
+++ b/net/mpls/mpls_iptunnel.c
@@ -137,10 +137,14 @@ static int mpls_xmit(struct sk_buff *skb)
137 137
138 mpls_stats_inc_outucastpkts(out_dev, skb); 138 mpls_stats_inc_outucastpkts(out_dev, skb);
139 139
140 if (rt) 140 if (rt) {
141 err = neigh_xmit(NEIGH_ARP_TABLE, out_dev, &rt->rt_gateway, 141 if (rt->rt_gw_family == AF_INET)
142 skb); 142 err = neigh_xmit(NEIGH_ARP_TABLE, out_dev, &rt->rt_gw4,
143 else if (rt6) { 143 skb);
144 else if (rt->rt_gw_family == AF_INET6)
145 err = neigh_xmit(NEIGH_ND_TABLE, out_dev, &rt->rt_gw6,
146 skb);
147 } else if (rt6) {
144 if (ipv6_addr_v4mapped(&rt6->rt6i_gateway)) { 148 if (ipv6_addr_v4mapped(&rt6->rt6i_gateway)) {
145 /* 6PE (RFC 4798) */ 149 /* 6PE (RFC 4798) */
146 err = neigh_xmit(NEIGH_ARP_TABLE, out_dev, &rt6->rt6i_gateway.s6_addr32[3], 150 err = neigh_xmit(NEIGH_ARP_TABLE, out_dev, &rt6->rt6i_gateway.s6_addr32[3],
@@ -174,8 +178,8 @@ static int mpls_build_state(struct nlattr *nla,
174 u8 n_labels; 178 u8 n_labels;
175 int ret; 179 int ret;
176 180
177 ret = nla_parse_nested(tb, MPLS_IPTUNNEL_MAX, nla, 181 ret = nla_parse_nested_deprecated(tb, MPLS_IPTUNNEL_MAX, nla,
178 mpls_iptunnel_policy, extack); 182 mpls_iptunnel_policy, extack);
179 if (ret < 0) 183 if (ret < 0)
180 return ret; 184 return ret;
181 185
diff --git a/net/ncsi/ncsi-netlink.c b/net/ncsi/ncsi-netlink.c
index bad17bba8ba7..7fc4feddafa3 100644
--- a/net/ncsi/ncsi-netlink.c
+++ b/net/ncsi/ncsi-netlink.c
@@ -79,7 +79,7 @@ static int ncsi_write_channel_info(struct sk_buff *skb,
79 nla_put_u32(skb, NCSI_CHANNEL_ATTR_VERSION_MINOR, nc->version.alpha2); 79 nla_put_u32(skb, NCSI_CHANNEL_ATTR_VERSION_MINOR, nc->version.alpha2);
80 nla_put_string(skb, NCSI_CHANNEL_ATTR_VERSION_STR, nc->version.fw_name); 80 nla_put_string(skb, NCSI_CHANNEL_ATTR_VERSION_STR, nc->version.fw_name);
81 81
82 vid_nest = nla_nest_start(skb, NCSI_CHANNEL_ATTR_VLAN_LIST); 82 vid_nest = nla_nest_start_noflag(skb, NCSI_CHANNEL_ATTR_VLAN_LIST);
83 if (!vid_nest) 83 if (!vid_nest)
84 return -ENOMEM; 84 return -ENOMEM;
85 ncf = &nc->vlan_filter; 85 ncf = &nc->vlan_filter;
@@ -113,19 +113,19 @@ static int ncsi_write_package_info(struct sk_buff *skb,
113 NCSI_FOR_EACH_PACKAGE(ndp, np) { 113 NCSI_FOR_EACH_PACKAGE(ndp, np) {
114 if (np->id != id) 114 if (np->id != id)
115 continue; 115 continue;
116 pnest = nla_nest_start(skb, NCSI_PKG_ATTR); 116 pnest = nla_nest_start_noflag(skb, NCSI_PKG_ATTR);
117 if (!pnest) 117 if (!pnest)
118 return -ENOMEM; 118 return -ENOMEM;
119 nla_put_u32(skb, NCSI_PKG_ATTR_ID, np->id); 119 nla_put_u32(skb, NCSI_PKG_ATTR_ID, np->id);
120 if ((0x1 << np->id) == ndp->package_whitelist) 120 if ((0x1 << np->id) == ndp->package_whitelist)
121 nla_put_flag(skb, NCSI_PKG_ATTR_FORCED); 121 nla_put_flag(skb, NCSI_PKG_ATTR_FORCED);
122 cnest = nla_nest_start(skb, NCSI_PKG_ATTR_CHANNEL_LIST); 122 cnest = nla_nest_start_noflag(skb, NCSI_PKG_ATTR_CHANNEL_LIST);
123 if (!cnest) { 123 if (!cnest) {
124 nla_nest_cancel(skb, pnest); 124 nla_nest_cancel(skb, pnest);
125 return -ENOMEM; 125 return -ENOMEM;
126 } 126 }
127 NCSI_FOR_EACH_CHANNEL(np, nc) { 127 NCSI_FOR_EACH_CHANNEL(np, nc) {
128 nest = nla_nest_start(skb, NCSI_CHANNEL_ATTR); 128 nest = nla_nest_start_noflag(skb, NCSI_CHANNEL_ATTR);
129 if (!nest) { 129 if (!nest) {
130 nla_nest_cancel(skb, cnest); 130 nla_nest_cancel(skb, cnest);
131 nla_nest_cancel(skb, pnest); 131 nla_nest_cancel(skb, pnest);
@@ -187,7 +187,7 @@ static int ncsi_pkg_info_nl(struct sk_buff *msg, struct genl_info *info)
187 187
188 package_id = nla_get_u32(info->attrs[NCSI_ATTR_PACKAGE_ID]); 188 package_id = nla_get_u32(info->attrs[NCSI_ATTR_PACKAGE_ID]);
189 189
190 attr = nla_nest_start(skb, NCSI_ATTR_PACKAGE_LIST); 190 attr = nla_nest_start_noflag(skb, NCSI_ATTR_PACKAGE_LIST);
191 if (!attr) { 191 if (!attr) {
192 kfree_skb(skb); 192 kfree_skb(skb);
193 return -EMSGSIZE; 193 return -EMSGSIZE;
@@ -220,8 +220,8 @@ static int ncsi_pkg_info_all_nl(struct sk_buff *skb,
220 void *hdr; 220 void *hdr;
221 int rc; 221 int rc;
222 222
223 rc = genlmsg_parse(cb->nlh, &ncsi_genl_family, attrs, NCSI_ATTR_MAX, 223 rc = genlmsg_parse_deprecated(cb->nlh, &ncsi_genl_family, attrs, NCSI_ATTR_MAX,
224 ncsi_genl_policy, NULL); 224 ncsi_genl_policy, NULL);
225 if (rc) 225 if (rc)
226 return rc; 226 return rc;
227 227
@@ -250,7 +250,7 @@ static int ncsi_pkg_info_all_nl(struct sk_buff *skb,
250 goto err; 250 goto err;
251 } 251 }
252 252
253 attr = nla_nest_start(skb, NCSI_ATTR_PACKAGE_LIST); 253 attr = nla_nest_start_noflag(skb, NCSI_ATTR_PACKAGE_LIST);
254 if (!attr) { 254 if (!attr) {
255 rc = -EMSGSIZE; 255 rc = -EMSGSIZE;
256 goto err; 256 goto err;
@@ -723,38 +723,38 @@ static int ncsi_set_channel_mask_nl(struct sk_buff *msg,
723static const struct genl_ops ncsi_ops[] = { 723static const struct genl_ops ncsi_ops[] = {
724 { 724 {
725 .cmd = NCSI_CMD_PKG_INFO, 725 .cmd = NCSI_CMD_PKG_INFO,
726 .policy = ncsi_genl_policy, 726 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
727 .doit = ncsi_pkg_info_nl, 727 .doit = ncsi_pkg_info_nl,
728 .dumpit = ncsi_pkg_info_all_nl, 728 .dumpit = ncsi_pkg_info_all_nl,
729 .flags = 0, 729 .flags = 0,
730 }, 730 },
731 { 731 {
732 .cmd = NCSI_CMD_SET_INTERFACE, 732 .cmd = NCSI_CMD_SET_INTERFACE,
733 .policy = ncsi_genl_policy, 733 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
734 .doit = ncsi_set_interface_nl, 734 .doit = ncsi_set_interface_nl,
735 .flags = GENL_ADMIN_PERM, 735 .flags = GENL_ADMIN_PERM,
736 }, 736 },
737 { 737 {
738 .cmd = NCSI_CMD_CLEAR_INTERFACE, 738 .cmd = NCSI_CMD_CLEAR_INTERFACE,
739 .policy = ncsi_genl_policy, 739 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
740 .doit = ncsi_clear_interface_nl, 740 .doit = ncsi_clear_interface_nl,
741 .flags = GENL_ADMIN_PERM, 741 .flags = GENL_ADMIN_PERM,
742 }, 742 },
743 { 743 {
744 .cmd = NCSI_CMD_SEND_CMD, 744 .cmd = NCSI_CMD_SEND_CMD,
745 .policy = ncsi_genl_policy, 745 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
746 .doit = ncsi_send_cmd_nl, 746 .doit = ncsi_send_cmd_nl,
747 .flags = GENL_ADMIN_PERM, 747 .flags = GENL_ADMIN_PERM,
748 }, 748 },
749 { 749 {
750 .cmd = NCSI_CMD_SET_PACKAGE_MASK, 750 .cmd = NCSI_CMD_SET_PACKAGE_MASK,
751 .policy = ncsi_genl_policy, 751 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
752 .doit = ncsi_set_package_mask_nl, 752 .doit = ncsi_set_package_mask_nl,
753 .flags = GENL_ADMIN_PERM, 753 .flags = GENL_ADMIN_PERM,
754 }, 754 },
755 { 755 {
756 .cmd = NCSI_CMD_SET_CHANNEL_MASK, 756 .cmd = NCSI_CMD_SET_CHANNEL_MASK,
757 .policy = ncsi_genl_policy, 757 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
758 .doit = ncsi_set_channel_mask_nl, 758 .doit = ncsi_set_channel_mask_nl,
759 .flags = GENL_ADMIN_PERM, 759 .flags = GENL_ADMIN_PERM,
760 }, 760 },
@@ -764,6 +764,7 @@ static struct genl_family ncsi_genl_family __ro_after_init = {
764 .name = "NCSI", 764 .name = "NCSI",
765 .version = 0, 765 .version = 0,
766 .maxattr = NCSI_ATTR_MAX, 766 .maxattr = NCSI_ATTR_MAX,
767 .policy = ncsi_genl_policy,
767 .module = THIS_MODULE, 768 .module = THIS_MODULE,
768 .ops = ncsi_ops, 769 .ops = ncsi_ops,
769 .n_ops = ARRAY_SIZE(ncsi_ops), 770 .n_ops = ARRAY_SIZE(ncsi_ops),
diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index dc07fcc7938e..802db01e3075 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/netdevice.h> 13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
14#include <linux/skbuff.h> 15#include <linux/skbuff.h>
15 16
16#include <net/ncsi.h> 17#include <net/ncsi.h>
@@ -667,7 +668,10 @@ static int ncsi_rsp_handler_oem_bcm_gma(struct ncsi_request *nr)
667 ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 668 ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
668 memcpy(saddr.sa_data, &rsp->data[BCM_MAC_ADDR_OFFSET], ETH_ALEN); 669 memcpy(saddr.sa_data, &rsp->data[BCM_MAC_ADDR_OFFSET], ETH_ALEN);
669 /* Increase mac address by 1 for BMC's address */ 670 /* Increase mac address by 1 for BMC's address */
670 saddr.sa_data[ETH_ALEN - 1]++; 671 eth_addr_inc((u8 *)saddr.sa_data);
672 if (!is_valid_ether_addr((const u8 *)saddr.sa_data))
673 return -ENXIO;
674
671 ret = ops->ndo_set_mac_address(ndev, &saddr); 675 ret = ops->ndo_set_mac_address(ndev, &saddr);
672 if (ret < 0) 676 if (ret < 0)
673 netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n"); 677 netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n");
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 6548271209a0..02b281d3c167 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -404,11 +404,6 @@ config NF_NAT
404 forms of full Network Address Port Translation. This can be 404 forms of full Network Address Port Translation. This can be
405 controlled by iptables, ip6tables or nft. 405 controlled by iptables, ip6tables or nft.
406 406
407config NF_NAT_NEEDED
408 bool
409 depends on NF_NAT
410 default y
411
412config NF_NAT_AMANDA 407config NF_NAT_AMANDA
413 tristate 408 tristate
414 depends on NF_CONNTRACK && NF_NAT 409 depends on NF_CONNTRACK && NF_NAT
@@ -1002,6 +997,20 @@ config NETFILTER_XT_TARGET_REDIRECT
1002 997
1003 To compile it as a module, choose M here. If unsure, say N. 998 To compile it as a module, choose M here. If unsure, say N.
1004 999
1000config NETFILTER_XT_TARGET_MASQUERADE
1001 tristate "MASQUERADE target support"
1002 depends on NF_NAT
1003 default m if NETFILTER_ADVANCED=n
1004 select NF_NAT_MASQUERADE
1005 help
1006 Masquerading is a special case of NAT: all outgoing connections are
1007 changed to seem to come from a particular interface's address, and
1008 if the interface goes down, those connections are lost. This is
1009 only useful for dialup accounts with dynamic IP address (ie. your IP
1010 address will be different on next dialup).
1011
1012 To compile it as a module, choose M here. If unsure, say N.
1013
1005config NETFILTER_XT_TARGET_TEE 1014config NETFILTER_XT_TARGET_TEE
1006 tristate '"TEE" - packet cloning to alternate destination' 1015 tristate '"TEE" - packet cloning to alternate destination'
1007 depends on NETFILTER_ADVANCED 1016 depends on NETFILTER_ADVANCED
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index 4894a85cdd0b..72cca6b48960 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -77,7 +77,8 @@ obj-$(CONFIG_NF_DUP_NETDEV) += nf_dup_netdev.o
77nf_tables-objs := nf_tables_core.o nf_tables_api.o nft_chain_filter.o \ 77nf_tables-objs := nf_tables_core.o nf_tables_api.o nft_chain_filter.o \
78 nf_tables_trace.o nft_immediate.o nft_cmp.o nft_range.o \ 78 nf_tables_trace.o nft_immediate.o nft_cmp.o nft_range.o \
79 nft_bitwise.o nft_byteorder.o nft_payload.o nft_lookup.o \ 79 nft_bitwise.o nft_byteorder.o nft_payload.o nft_lookup.o \
80 nft_dynset.o nft_meta.o nft_rt.o nft_exthdr.o 80 nft_dynset.o nft_meta.o nft_rt.o nft_exthdr.o \
81 nft_chain_route.o
81 82
82nf_tables_set-objs := nf_tables_set_core.o \ 83nf_tables_set-objs := nf_tables_set_core.o \
83 nft_set_hash.o nft_set_bitmap.o nft_set_rbtree.o 84 nft_set_hash.o nft_set_bitmap.o nft_set_rbtree.o
@@ -147,6 +148,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o
147obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o 148obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o
148obj-$(CONFIG_NETFILTER_XT_TARGET_RATEEST) += xt_RATEEST.o 149obj-$(CONFIG_NETFILTER_XT_TARGET_RATEEST) += xt_RATEEST.o
149obj-$(CONFIG_NETFILTER_XT_TARGET_REDIRECT) += xt_REDIRECT.o 150obj-$(CONFIG_NETFILTER_XT_TARGET_REDIRECT) += xt_REDIRECT.o
151obj-$(CONFIG_NETFILTER_XT_TARGET_MASQUERADE) += xt_MASQUERADE.o
150obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o 152obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o
151obj-$(CONFIG_NETFILTER_XT_TARGET_TPROXY) += xt_TPROXY.o 153obj-$(CONFIG_NETFILTER_XT_TARGET_TPROXY) += xt_TPROXY.o
152obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o 154obj-$(CONFIG_NETFILTER_XT_TARGET_TCPMSS) += xt_TCPMSS.o
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 93aaec3a54ec..b96fd3f54705 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -23,6 +23,7 @@
23#include <linux/mm.h> 23#include <linux/mm.h>
24#include <linux/rcupdate.h> 24#include <linux/rcupdate.h>
25#include <net/net_namespace.h> 25#include <net/net_namespace.h>
26#include <net/netfilter/nf_queue.h>
26#include <net/sock.h> 27#include <net/sock.h>
27 28
28#include "nf_internals.h" 29#include "nf_internals.h"
@@ -162,7 +163,7 @@ nf_hook_entries_grow(const struct nf_hook_entries *old,
162 163
163static void hooks_validate(const struct nf_hook_entries *hooks) 164static void hooks_validate(const struct nf_hook_entries *hooks)
164{ 165{
165#ifdef CONFIG_DEBUG_KERNEL 166#ifdef CONFIG_DEBUG_MISC
166 struct nf_hook_ops **orig_ops; 167 struct nf_hook_ops **orig_ops;
167 int prio = INT_MIN; 168 int prio = INT_MIN;
168 size_t i = 0; 169 size_t i = 0;
diff --git a/net/netfilter/ipset/ip_set_bitmap_gen.h b/net/netfilter/ipset/ip_set_bitmap_gen.h
index 257ca393e6f2..38ef2ea838cb 100644
--- a/net/netfilter/ipset/ip_set_bitmap_gen.h
+++ b/net/netfilter/ipset/ip_set_bitmap_gen.h
@@ -99,7 +99,7 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)
99 struct nlattr *nested; 99 struct nlattr *nested;
100 size_t memsize = mtype_memsize(map, set->dsize) + set->ext_size; 100 size_t memsize = mtype_memsize(map, set->dsize) + set->ext_size;
101 101
102 nested = ipset_nest_start(skb, IPSET_ATTR_DATA); 102 nested = nla_nest_start(skb, IPSET_ATTR_DATA);
103 if (!nested) 103 if (!nested)
104 goto nla_put_failure; 104 goto nla_put_failure;
105 if (mtype_do_head(skb, map) || 105 if (mtype_do_head(skb, map) ||
@@ -109,7 +109,7 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)
109 goto nla_put_failure; 109 goto nla_put_failure;
110 if (unlikely(ip_set_put_flags(skb, set))) 110 if (unlikely(ip_set_put_flags(skb, set)))
111 goto nla_put_failure; 111 goto nla_put_failure;
112 ipset_nest_end(skb, nested); 112 nla_nest_end(skb, nested);
113 113
114 return 0; 114 return 0;
115nla_put_failure: 115nla_put_failure:
@@ -213,7 +213,7 @@ mtype_list(const struct ip_set *set,
213 u32 id, first = cb->args[IPSET_CB_ARG0]; 213 u32 id, first = cb->args[IPSET_CB_ARG0];
214 int ret = 0; 214 int ret = 0;
215 215
216 adt = ipset_nest_start(skb, IPSET_ATTR_ADT); 216 adt = nla_nest_start(skb, IPSET_ATTR_ADT);
217 if (!adt) 217 if (!adt)
218 return -EMSGSIZE; 218 return -EMSGSIZE;
219 /* Extensions may be replaced */ 219 /* Extensions may be replaced */
@@ -230,7 +230,7 @@ mtype_list(const struct ip_set *set,
230#endif 230#endif
231 ip_set_timeout_expired(ext_timeout(x, set)))) 231 ip_set_timeout_expired(ext_timeout(x, set))))
232 continue; 232 continue;
233 nested = ipset_nest_start(skb, IPSET_ATTR_DATA); 233 nested = nla_nest_start(skb, IPSET_ATTR_DATA);
234 if (!nested) { 234 if (!nested) {
235 if (id == first) { 235 if (id == first) {
236 nla_nest_cancel(skb, adt); 236 nla_nest_cancel(skb, adt);
@@ -244,9 +244,9 @@ mtype_list(const struct ip_set *set,
244 goto nla_put_failure; 244 goto nla_put_failure;
245 if (ip_set_put_extensions(skb, set, x, mtype_is_filled(x))) 245 if (ip_set_put_extensions(skb, set, x, mtype_is_filled(x)))
246 goto nla_put_failure; 246 goto nla_put_failure;
247 ipset_nest_end(skb, nested); 247 nla_nest_end(skb, nested);
248 } 248 }
249 ipset_nest_end(skb, adt); 249 nla_nest_end(skb, adt);
250 250
251 /* Set listing finished */ 251 /* Set listing finished */
252 cb->args[IPSET_CB_ARG0] = 0; 252 cb->args[IPSET_CB_ARG0] = 0;
@@ -259,7 +259,7 @@ nla_put_failure:
259 cb->args[IPSET_CB_ARG0] = 0; 259 cb->args[IPSET_CB_ARG0] = 0;
260 ret = -EMSGSIZE; 260 ret = -EMSGSIZE;
261 } 261 }
262 ipset_nest_end(skb, adt); 262 nla_nest_end(skb, adt);
263out: 263out:
264 rcu_read_unlock(); 264 rcu_read_unlock();
265 return ret; 265 return ret;
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 45a257695bef..3f4a4936f63c 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -299,8 +299,7 @@ ip_set_get_ipaddr4(struct nlattr *nla, __be32 *ipaddr)
299 299
300 if (unlikely(!flag_nested(nla))) 300 if (unlikely(!flag_nested(nla)))
301 return -IPSET_ERR_PROTOCOL; 301 return -IPSET_ERR_PROTOCOL;
302 if (nla_parse_nested(tb, IPSET_ATTR_IPADDR_MAX, nla, 302 if (nla_parse_nested_deprecated(tb, IPSET_ATTR_IPADDR_MAX, nla, ipaddr_policy, NULL))
303 ipaddr_policy, NULL))
304 return -IPSET_ERR_PROTOCOL; 303 return -IPSET_ERR_PROTOCOL;
305 if (unlikely(!ip_set_attr_netorder(tb, IPSET_ATTR_IPADDR_IPV4))) 304 if (unlikely(!ip_set_attr_netorder(tb, IPSET_ATTR_IPADDR_IPV4)))
306 return -IPSET_ERR_PROTOCOL; 305 return -IPSET_ERR_PROTOCOL;
@@ -318,8 +317,7 @@ ip_set_get_ipaddr6(struct nlattr *nla, union nf_inet_addr *ipaddr)
318 if (unlikely(!flag_nested(nla))) 317 if (unlikely(!flag_nested(nla)))
319 return -IPSET_ERR_PROTOCOL; 318 return -IPSET_ERR_PROTOCOL;
320 319
321 if (nla_parse_nested(tb, IPSET_ATTR_IPADDR_MAX, nla, 320 if (nla_parse_nested_deprecated(tb, IPSET_ATTR_IPADDR_MAX, nla, ipaddr_policy, NULL))
322 ipaddr_policy, NULL))
323 return -IPSET_ERR_PROTOCOL; 321 return -IPSET_ERR_PROTOCOL;
324 if (unlikely(!ip_set_attr_netorder(tb, IPSET_ATTR_IPADDR_IPV6))) 322 if (unlikely(!ip_set_attr_netorder(tb, IPSET_ATTR_IPADDR_IPV6)))
325 return -IPSET_ERR_PROTOCOL; 323 return -IPSET_ERR_PROTOCOL;
@@ -939,8 +937,7 @@ static int ip_set_create(struct net *net, struct sock *ctnl,
939 937
940 /* Without holding any locks, create private part. */ 938 /* Without holding any locks, create private part. */
941 if (attr[IPSET_ATTR_DATA] && 939 if (attr[IPSET_ATTR_DATA] &&
942 nla_parse_nested(tb, IPSET_ATTR_CREATE_MAX, attr[IPSET_ATTR_DATA], 940 nla_parse_nested_deprecated(tb, IPSET_ATTR_CREATE_MAX, attr[IPSET_ATTR_DATA], set->type->create_policy, NULL)) {
943 set->type->create_policy, NULL)) {
944 ret = -IPSET_ERR_PROTOCOL; 941 ret = -IPSET_ERR_PROTOCOL;
945 goto put_out; 942 goto put_out;
946 } 943 }
@@ -1298,8 +1295,9 @@ dump_init(struct netlink_callback *cb, struct ip_set_net *inst)
1298 ip_set_id_t index; 1295 ip_set_id_t index;
1299 1296
1300 /* Second pass, so parser can't fail */ 1297 /* Second pass, so parser can't fail */
1301 nla_parse(cda, IPSET_ATTR_CMD_MAX, attr, nlh->nlmsg_len - min_len, 1298 nla_parse_deprecated(cda, IPSET_ATTR_CMD_MAX, attr,
1302 ip_set_setname_policy, NULL); 1299 nlh->nlmsg_len - min_len, ip_set_setname_policy,
1300 NULL);
1303 1301
1304 cb->args[IPSET_CB_PROTO] = nla_get_u8(cda[IPSET_ATTR_PROTOCOL]); 1302 cb->args[IPSET_CB_PROTO] = nla_get_u8(cda[IPSET_ATTR_PROTOCOL]);
1305 if (cda[IPSET_ATTR_SETNAME]) { 1303 if (cda[IPSET_ATTR_SETNAME]) {
@@ -1546,8 +1544,9 @@ call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set,
1546 memcpy(&errmsg->msg, nlh, nlh->nlmsg_len); 1544 memcpy(&errmsg->msg, nlh, nlh->nlmsg_len);
1547 cmdattr = (void *)&errmsg->msg + min_len; 1545 cmdattr = (void *)&errmsg->msg + min_len;
1548 1546
1549 nla_parse(cda, IPSET_ATTR_CMD_MAX, cmdattr, 1547 nla_parse_deprecated(cda, IPSET_ATTR_CMD_MAX, cmdattr,
1550 nlh->nlmsg_len - min_len, ip_set_adt_policy, NULL); 1548 nlh->nlmsg_len - min_len,
1549 ip_set_adt_policy, NULL);
1551 1550
1552 errline = nla_data(cda[IPSET_ATTR_LINENO]); 1551 errline = nla_data(cda[IPSET_ATTR_LINENO]);
1553 1552
@@ -1592,9 +1591,7 @@ static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb,
1592 1591
1593 use_lineno = !!attr[IPSET_ATTR_LINENO]; 1592 use_lineno = !!attr[IPSET_ATTR_LINENO];
1594 if (attr[IPSET_ATTR_DATA]) { 1593 if (attr[IPSET_ATTR_DATA]) {
1595 if (nla_parse_nested(tb, IPSET_ATTR_ADT_MAX, 1594 if (nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, attr[IPSET_ATTR_DATA], set->type->adt_policy, NULL))
1596 attr[IPSET_ATTR_DATA],
1597 set->type->adt_policy, NULL))
1598 return -IPSET_ERR_PROTOCOL; 1595 return -IPSET_ERR_PROTOCOL;
1599 ret = call_ad(ctnl, skb, set, tb, IPSET_ADD, flags, 1596 ret = call_ad(ctnl, skb, set, tb, IPSET_ADD, flags,
1600 use_lineno); 1597 use_lineno);
@@ -1605,8 +1602,7 @@ static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb,
1605 memset(tb, 0, sizeof(tb)); 1602 memset(tb, 0, sizeof(tb));
1606 if (nla_type(nla) != IPSET_ATTR_DATA || 1603 if (nla_type(nla) != IPSET_ATTR_DATA ||
1607 !flag_nested(nla) || 1604 !flag_nested(nla) ||
1608 nla_parse_nested(tb, IPSET_ATTR_ADT_MAX, nla, 1605 nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, nla, set->type->adt_policy, NULL))
1609 set->type->adt_policy, NULL))
1610 return -IPSET_ERR_PROTOCOL; 1606 return -IPSET_ERR_PROTOCOL;
1611 ret = call_ad(ctnl, skb, set, tb, IPSET_ADD, 1607 ret = call_ad(ctnl, skb, set, tb, IPSET_ADD,
1612 flags, use_lineno); 1608 flags, use_lineno);
@@ -1647,9 +1643,7 @@ static int ip_set_udel(struct net *net, struct sock *ctnl, struct sk_buff *skb,
1647 1643
1648 use_lineno = !!attr[IPSET_ATTR_LINENO]; 1644 use_lineno = !!attr[IPSET_ATTR_LINENO];
1649 if (attr[IPSET_ATTR_DATA]) { 1645 if (attr[IPSET_ATTR_DATA]) {
1650 if (nla_parse_nested(tb, IPSET_ATTR_ADT_MAX, 1646 if (nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, attr[IPSET_ATTR_DATA], set->type->adt_policy, NULL))
1651 attr[IPSET_ATTR_DATA],
1652 set->type->adt_policy, NULL))
1653 return -IPSET_ERR_PROTOCOL; 1647 return -IPSET_ERR_PROTOCOL;
1654 ret = call_ad(ctnl, skb, set, tb, IPSET_DEL, flags, 1648 ret = call_ad(ctnl, skb, set, tb, IPSET_DEL, flags,
1655 use_lineno); 1649 use_lineno);
@@ -1660,8 +1654,7 @@ static int ip_set_udel(struct net *net, struct sock *ctnl, struct sk_buff *skb,
1660 memset(tb, 0, sizeof(*tb)); 1654 memset(tb, 0, sizeof(*tb));
1661 if (nla_type(nla) != IPSET_ATTR_DATA || 1655 if (nla_type(nla) != IPSET_ATTR_DATA ||
1662 !flag_nested(nla) || 1656 !flag_nested(nla) ||
1663 nla_parse_nested(tb, IPSET_ATTR_ADT_MAX, nla, 1657 nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, nla, set->type->adt_policy, NULL))
1664 set->type->adt_policy, NULL))
1665 return -IPSET_ERR_PROTOCOL; 1658 return -IPSET_ERR_PROTOCOL;
1666 ret = call_ad(ctnl, skb, set, tb, IPSET_DEL, 1659 ret = call_ad(ctnl, skb, set, tb, IPSET_DEL,
1667 flags, use_lineno); 1660 flags, use_lineno);
@@ -1692,8 +1685,7 @@ static int ip_set_utest(struct net *net, struct sock *ctnl, struct sk_buff *skb,
1692 if (!set) 1685 if (!set)
1693 return -ENOENT; 1686 return -ENOENT;
1694 1687
1695 if (nla_parse_nested(tb, IPSET_ATTR_ADT_MAX, attr[IPSET_ATTR_DATA], 1688 if (nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, attr[IPSET_ATTR_DATA], set->type->adt_policy, NULL))
1696 set->type->adt_policy, NULL))
1697 return -IPSET_ERR_PROTOCOL; 1689 return -IPSET_ERR_PROTOCOL;
1698 1690
1699 rcu_read_lock_bh(); 1691 rcu_read_lock_bh();
diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
index 2c9609929c71..01d51f775f12 100644
--- a/net/netfilter/ipset/ip_set_hash_gen.h
+++ b/net/netfilter/ipset/ip_set_hash_gen.h
@@ -1057,7 +1057,7 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)
1057 htable_bits = t->htable_bits; 1057 htable_bits = t->htable_bits;
1058 rcu_read_unlock_bh(); 1058 rcu_read_unlock_bh();
1059 1059
1060 nested = ipset_nest_start(skb, IPSET_ATTR_DATA); 1060 nested = nla_nest_start(skb, IPSET_ATTR_DATA);
1061 if (!nested) 1061 if (!nested)
1062 goto nla_put_failure; 1062 goto nla_put_failure;
1063 if (nla_put_net32(skb, IPSET_ATTR_HASHSIZE, 1063 if (nla_put_net32(skb, IPSET_ATTR_HASHSIZE,
@@ -1079,7 +1079,7 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)
1079 goto nla_put_failure; 1079 goto nla_put_failure;
1080 if (unlikely(ip_set_put_flags(skb, set))) 1080 if (unlikely(ip_set_put_flags(skb, set)))
1081 goto nla_put_failure; 1081 goto nla_put_failure;
1082 ipset_nest_end(skb, nested); 1082 nla_nest_end(skb, nested);
1083 1083
1084 return 0; 1084 return 0;
1085nla_put_failure: 1085nla_put_failure:
@@ -1124,7 +1124,7 @@ mtype_list(const struct ip_set *set,
1124 void *incomplete; 1124 void *incomplete;
1125 int i, ret = 0; 1125 int i, ret = 0;
1126 1126
1127 atd = ipset_nest_start(skb, IPSET_ATTR_ADT); 1127 atd = nla_nest_start(skb, IPSET_ATTR_ADT);
1128 if (!atd) 1128 if (!atd)
1129 return -EMSGSIZE; 1129 return -EMSGSIZE;
1130 1130
@@ -1150,7 +1150,7 @@ mtype_list(const struct ip_set *set,
1150 continue; 1150 continue;
1151 pr_debug("list hash %lu hbucket %p i %u, data %p\n", 1151 pr_debug("list hash %lu hbucket %p i %u, data %p\n",
1152 cb->args[IPSET_CB_ARG0], n, i, e); 1152 cb->args[IPSET_CB_ARG0], n, i, e);
1153 nested = ipset_nest_start(skb, IPSET_ATTR_DATA); 1153 nested = nla_nest_start(skb, IPSET_ATTR_DATA);
1154 if (!nested) { 1154 if (!nested) {
1155 if (cb->args[IPSET_CB_ARG0] == first) { 1155 if (cb->args[IPSET_CB_ARG0] == first) {
1156 nla_nest_cancel(skb, atd); 1156 nla_nest_cancel(skb, atd);
@@ -1163,10 +1163,10 @@ mtype_list(const struct ip_set *set,
1163 goto nla_put_failure; 1163 goto nla_put_failure;
1164 if (ip_set_put_extensions(skb, set, e, true)) 1164 if (ip_set_put_extensions(skb, set, e, true))
1165 goto nla_put_failure; 1165 goto nla_put_failure;
1166 ipset_nest_end(skb, nested); 1166 nla_nest_end(skb, nested);
1167 } 1167 }
1168 } 1168 }
1169 ipset_nest_end(skb, atd); 1169 nla_nest_end(skb, atd);
1170 /* Set listing finished */ 1170 /* Set listing finished */
1171 cb->args[IPSET_CB_ARG0] = 0; 1171 cb->args[IPSET_CB_ARG0] = 0;
1172 1172
@@ -1180,7 +1180,7 @@ nla_put_failure:
1180 cb->args[IPSET_CB_ARG0] = 0; 1180 cb->args[IPSET_CB_ARG0] = 0;
1181 ret = -EMSGSIZE; 1181 ret = -EMSGSIZE;
1182 } else { 1182 } else {
1183 ipset_nest_end(skb, atd); 1183 nla_nest_end(skb, atd);
1184 } 1184 }
1185out: 1185out:
1186 rcu_read_unlock(); 1186 rcu_read_unlock();
diff --git a/net/netfilter/ipset/ip_set_list_set.c b/net/netfilter/ipset/ip_set_list_set.c
index 8da228da53ae..4f894165cdcd 100644
--- a/net/netfilter/ipset/ip_set_list_set.c
+++ b/net/netfilter/ipset/ip_set_list_set.c
@@ -466,7 +466,7 @@ list_set_head(struct ip_set *set, struct sk_buff *skb)
466 struct nlattr *nested; 466 struct nlattr *nested;
467 size_t memsize = list_set_memsize(map, set->dsize) + set->ext_size; 467 size_t memsize = list_set_memsize(map, set->dsize) + set->ext_size;
468 468
469 nested = ipset_nest_start(skb, IPSET_ATTR_DATA); 469 nested = nla_nest_start(skb, IPSET_ATTR_DATA);
470 if (!nested) 470 if (!nested)
471 goto nla_put_failure; 471 goto nla_put_failure;
472 if (nla_put_net32(skb, IPSET_ATTR_SIZE, htonl(map->size)) || 472 if (nla_put_net32(skb, IPSET_ATTR_SIZE, htonl(map->size)) ||
@@ -476,7 +476,7 @@ list_set_head(struct ip_set *set, struct sk_buff *skb)
476 goto nla_put_failure; 476 goto nla_put_failure;
477 if (unlikely(ip_set_put_flags(skb, set))) 477 if (unlikely(ip_set_put_flags(skb, set)))
478 goto nla_put_failure; 478 goto nla_put_failure;
479 ipset_nest_end(skb, nested); 479 nla_nest_end(skb, nested);
480 480
481 return 0; 481 return 0;
482nla_put_failure: 482nla_put_failure:
@@ -494,7 +494,7 @@ list_set_list(const struct ip_set *set,
494 struct set_elem *e; 494 struct set_elem *e;
495 int ret = 0; 495 int ret = 0;
496 496
497 atd = ipset_nest_start(skb, IPSET_ATTR_ADT); 497 atd = nla_nest_start(skb, IPSET_ATTR_ADT);
498 if (!atd) 498 if (!atd)
499 return -EMSGSIZE; 499 return -EMSGSIZE;
500 500
@@ -506,7 +506,7 @@ list_set_list(const struct ip_set *set,
506 i++; 506 i++;
507 continue; 507 continue;
508 } 508 }
509 nested = ipset_nest_start(skb, IPSET_ATTR_DATA); 509 nested = nla_nest_start(skb, IPSET_ATTR_DATA);
510 if (!nested) 510 if (!nested)
511 goto nla_put_failure; 511 goto nla_put_failure;
512 ip_set_name_byindex(map->net, e->id, name); 512 ip_set_name_byindex(map->net, e->id, name);
@@ -514,11 +514,11 @@ list_set_list(const struct ip_set *set,
514 goto nla_put_failure; 514 goto nla_put_failure;
515 if (ip_set_put_extensions(skb, set, e, true)) 515 if (ip_set_put_extensions(skb, set, e, true))
516 goto nla_put_failure; 516 goto nla_put_failure;
517 ipset_nest_end(skb, nested); 517 nla_nest_end(skb, nested);
518 i++; 518 i++;
519 } 519 }
520 520
521 ipset_nest_end(skb, atd); 521 nla_nest_end(skb, atd);
522 /* Set listing finished */ 522 /* Set listing finished */
523 cb->args[IPSET_CB_ARG0] = 0; 523 cb->args[IPSET_CB_ARG0] = 0;
524 goto out; 524 goto out;
@@ -531,7 +531,7 @@ nla_put_failure:
531 ret = -EMSGSIZE; 531 ret = -EMSGSIZE;
532 } else { 532 } else {
533 cb->args[IPSET_CB_ARG0] = i; 533 cb->args[IPSET_CB_ARG0] = i;
534 ipset_nest_end(skb, atd); 534 nla_nest_end(skb, atd);
535 } 535 }
536out: 536out:
537 rcu_read_unlock(); 537 rcu_read_unlock();
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 43bbaa32b1d6..14457551bcb4 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -1678,7 +1678,7 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
1678 if (!cp) { 1678 if (!cp) {
1679 int v; 1679 int v;
1680 1680
1681 if (!sysctl_schedule_icmp(ipvs)) 1681 if (ipip || !sysctl_schedule_icmp(ipvs))
1682 return NF_ACCEPT; 1682 return NF_ACCEPT;
1683 1683
1684 if (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, &v, &cp, &ciph)) 1684 if (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, &v, &cp, &ciph))
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 053cd96b9c76..0e887159425c 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -831,6 +831,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
831 conn_flags = udest->conn_flags & IP_VS_CONN_F_DEST_MASK; 831 conn_flags = udest->conn_flags & IP_VS_CONN_F_DEST_MASK;
832 conn_flags |= IP_VS_CONN_F_INACTIVE; 832 conn_flags |= IP_VS_CONN_F_INACTIVE;
833 833
834 /* set the tunnel info */
835 dest->tun_type = udest->tun_type;
836 dest->tun_port = udest->tun_port;
837
834 /* set the IP_VS_CONN_F_NOOUTPUT flag if not masquerading/NAT */ 838 /* set the IP_VS_CONN_F_NOOUTPUT flag if not masquerading/NAT */
835 if ((conn_flags & IP_VS_CONN_F_FWD_MASK) != IP_VS_CONN_F_MASQ) { 839 if ((conn_flags & IP_VS_CONN_F_FWD_MASK) != IP_VS_CONN_F_MASQ) {
836 conn_flags |= IP_VS_CONN_F_NOOUTPUT; 840 conn_flags |= IP_VS_CONN_F_NOOUTPUT;
@@ -987,6 +991,13 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
987 return -ERANGE; 991 return -ERANGE;
988 } 992 }
989 993
994 if (udest->tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE) {
995 if (udest->tun_port == 0) {
996 pr_err("%s(): tunnel port is zero\n", __func__);
997 return -EINVAL;
998 }
999 }
1000
990 ip_vs_addr_copy(udest->af, &daddr, &udest->addr); 1001 ip_vs_addr_copy(udest->af, &daddr, &udest->addr);
991 1002
992 /* We use function that requires RCU lock */ 1003 /* We use function that requires RCU lock */
@@ -1051,6 +1062,13 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
1051 return -ERANGE; 1062 return -ERANGE;
1052 } 1063 }
1053 1064
1065 if (udest->tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE) {
1066 if (udest->tun_port == 0) {
1067 pr_err("%s(): tunnel port is zero\n", __func__);
1068 return -EINVAL;
1069 }
1070 }
1071
1054 ip_vs_addr_copy(udest->af, &daddr, &udest->addr); 1072 ip_vs_addr_copy(udest->af, &daddr, &udest->addr);
1055 1073
1056 /* We use function that requires RCU lock */ 1074 /* We use function that requires RCU lock */
@@ -2333,6 +2351,7 @@ static void ip_vs_copy_udest_compat(struct ip_vs_dest_user_kern *udest,
2333 udest->u_threshold = udest_compat->u_threshold; 2351 udest->u_threshold = udest_compat->u_threshold;
2334 udest->l_threshold = udest_compat->l_threshold; 2352 udest->l_threshold = udest_compat->l_threshold;
2335 udest->af = AF_INET; 2353 udest->af = AF_INET;
2354 udest->tun_type = IP_VS_CONN_F_TUNNEL_TYPE_IPIP;
2336} 2355}
2337 2356
2338static int 2357static int
@@ -2890,12 +2909,14 @@ static const struct nla_policy ip_vs_dest_policy[IPVS_DEST_ATTR_MAX + 1] = {
2890 [IPVS_DEST_ATTR_PERSIST_CONNS] = { .type = NLA_U32 }, 2909 [IPVS_DEST_ATTR_PERSIST_CONNS] = { .type = NLA_U32 },
2891 [IPVS_DEST_ATTR_STATS] = { .type = NLA_NESTED }, 2910 [IPVS_DEST_ATTR_STATS] = { .type = NLA_NESTED },
2892 [IPVS_DEST_ATTR_ADDR_FAMILY] = { .type = NLA_U16 }, 2911 [IPVS_DEST_ATTR_ADDR_FAMILY] = { .type = NLA_U16 },
2912 [IPVS_DEST_ATTR_TUN_TYPE] = { .type = NLA_U8 },
2913 [IPVS_DEST_ATTR_TUN_PORT] = { .type = NLA_U16 },
2893}; 2914};
2894 2915
2895static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type, 2916static int ip_vs_genl_fill_stats(struct sk_buff *skb, int container_type,
2896 struct ip_vs_kstats *kstats) 2917 struct ip_vs_kstats *kstats)
2897{ 2918{
2898 struct nlattr *nl_stats = nla_nest_start(skb, container_type); 2919 struct nlattr *nl_stats = nla_nest_start_noflag(skb, container_type);
2899 2920
2900 if (!nl_stats) 2921 if (!nl_stats)
2901 return -EMSGSIZE; 2922 return -EMSGSIZE;
@@ -2925,7 +2946,7 @@ nla_put_failure:
2925static int ip_vs_genl_fill_stats64(struct sk_buff *skb, int container_type, 2946static int ip_vs_genl_fill_stats64(struct sk_buff *skb, int container_type,
2926 struct ip_vs_kstats *kstats) 2947 struct ip_vs_kstats *kstats)
2927{ 2948{
2928 struct nlattr *nl_stats = nla_nest_start(skb, container_type); 2949 struct nlattr *nl_stats = nla_nest_start_noflag(skb, container_type);
2929 2950
2930 if (!nl_stats) 2951 if (!nl_stats)
2931 return -EMSGSIZE; 2952 return -EMSGSIZE;
@@ -2971,7 +2992,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
2971 struct ip_vs_kstats kstats; 2992 struct ip_vs_kstats kstats;
2972 char *sched_name; 2993 char *sched_name;
2973 2994
2974 nl_service = nla_nest_start(skb, IPVS_CMD_ATTR_SERVICE); 2995 nl_service = nla_nest_start_noflag(skb, IPVS_CMD_ATTR_SERVICE);
2975 if (!nl_service) 2996 if (!nl_service)
2976 return -EMSGSIZE; 2997 return -EMSGSIZE;
2977 2998
@@ -3095,8 +3116,7 @@ static int ip_vs_genl_parse_service(struct netns_ipvs *ipvs,
3095 3116
3096 /* Parse mandatory identifying service fields first */ 3117 /* Parse mandatory identifying service fields first */
3097 if (nla == NULL || 3118 if (nla == NULL ||
3098 nla_parse_nested(attrs, IPVS_SVC_ATTR_MAX, nla, 3119 nla_parse_nested_deprecated(attrs, IPVS_SVC_ATTR_MAX, nla, ip_vs_svc_policy, NULL))
3099 ip_vs_svc_policy, NULL))
3100 return -EINVAL; 3120 return -EINVAL;
3101 3121
3102 nla_af = attrs[IPVS_SVC_ATTR_AF]; 3122 nla_af = attrs[IPVS_SVC_ATTR_AF];
@@ -3182,7 +3202,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
3182 struct nlattr *nl_dest; 3202 struct nlattr *nl_dest;
3183 struct ip_vs_kstats kstats; 3203 struct ip_vs_kstats kstats;
3184 3204
3185 nl_dest = nla_nest_start(skb, IPVS_CMD_ATTR_DEST); 3205 nl_dest = nla_nest_start_noflag(skb, IPVS_CMD_ATTR_DEST);
3186 if (!nl_dest) 3206 if (!nl_dest)
3187 return -EMSGSIZE; 3207 return -EMSGSIZE;
3188 3208
@@ -3193,6 +3213,10 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
3193 IP_VS_CONN_F_FWD_MASK)) || 3213 IP_VS_CONN_F_FWD_MASK)) ||
3194 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT, 3214 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
3195 atomic_read(&dest->weight)) || 3215 atomic_read(&dest->weight)) ||
3216 nla_put_u8(skb, IPVS_DEST_ATTR_TUN_TYPE,
3217 dest->tun_type) ||
3218 nla_put_be16(skb, IPVS_DEST_ATTR_TUN_PORT,
3219 dest->tun_port) ||
3196 nla_put_u32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold) || 3220 nla_put_u32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold) ||
3197 nla_put_u32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold) || 3221 nla_put_u32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold) ||
3198 nla_put_u32(skb, IPVS_DEST_ATTR_ACTIVE_CONNS, 3222 nla_put_u32(skb, IPVS_DEST_ATTR_ACTIVE_CONNS,
@@ -3254,8 +3278,7 @@ static int ip_vs_genl_dump_dests(struct sk_buff *skb,
3254 mutex_lock(&__ip_vs_mutex); 3278 mutex_lock(&__ip_vs_mutex);
3255 3279
3256 /* Try to find the service for which to dump destinations */ 3280 /* Try to find the service for which to dump destinations */
3257 if (nlmsg_parse(cb->nlh, GENL_HDRLEN, attrs, IPVS_CMD_ATTR_MAX, 3281 if (nlmsg_parse_deprecated(cb->nlh, GENL_HDRLEN, attrs, IPVS_CMD_ATTR_MAX, ip_vs_cmd_policy, cb->extack))
3258 ip_vs_cmd_policy, cb->extack))
3259 goto out_err; 3282 goto out_err;
3260 3283
3261 3284
@@ -3291,8 +3314,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
3291 3314
3292 /* Parse mandatory identifying destination fields first */ 3315 /* Parse mandatory identifying destination fields first */
3293 if (nla == NULL || 3316 if (nla == NULL ||
3294 nla_parse_nested(attrs, IPVS_DEST_ATTR_MAX, nla, 3317 nla_parse_nested_deprecated(attrs, IPVS_DEST_ATTR_MAX, nla, ip_vs_dest_policy, NULL))
3295 ip_vs_dest_policy, NULL))
3296 return -EINVAL; 3318 return -EINVAL;
3297 3319
3298 nla_addr = attrs[IPVS_DEST_ATTR_ADDR]; 3320 nla_addr = attrs[IPVS_DEST_ATTR_ADDR];
@@ -3315,12 +3337,14 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
3315 /* If a full entry was requested, check for the additional fields */ 3337 /* If a full entry was requested, check for the additional fields */
3316 if (full_entry) { 3338 if (full_entry) {
3317 struct nlattr *nla_fwd, *nla_weight, *nla_u_thresh, 3339 struct nlattr *nla_fwd, *nla_weight, *nla_u_thresh,
3318 *nla_l_thresh; 3340 *nla_l_thresh, *nla_tun_type, *nla_tun_port;
3319 3341
3320 nla_fwd = attrs[IPVS_DEST_ATTR_FWD_METHOD]; 3342 nla_fwd = attrs[IPVS_DEST_ATTR_FWD_METHOD];
3321 nla_weight = attrs[IPVS_DEST_ATTR_WEIGHT]; 3343 nla_weight = attrs[IPVS_DEST_ATTR_WEIGHT];
3322 nla_u_thresh = attrs[IPVS_DEST_ATTR_U_THRESH]; 3344 nla_u_thresh = attrs[IPVS_DEST_ATTR_U_THRESH];
3323 nla_l_thresh = attrs[IPVS_DEST_ATTR_L_THRESH]; 3345 nla_l_thresh = attrs[IPVS_DEST_ATTR_L_THRESH];
3346 nla_tun_type = attrs[IPVS_DEST_ATTR_TUN_TYPE];
3347 nla_tun_port = attrs[IPVS_DEST_ATTR_TUN_PORT];
3324 3348
3325 if (!(nla_fwd && nla_weight && nla_u_thresh && nla_l_thresh)) 3349 if (!(nla_fwd && nla_weight && nla_u_thresh && nla_l_thresh))
3326 return -EINVAL; 3350 return -EINVAL;
@@ -3330,6 +3354,12 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
3330 udest->weight = nla_get_u32(nla_weight); 3354 udest->weight = nla_get_u32(nla_weight);
3331 udest->u_threshold = nla_get_u32(nla_u_thresh); 3355 udest->u_threshold = nla_get_u32(nla_u_thresh);
3332 udest->l_threshold = nla_get_u32(nla_l_thresh); 3356 udest->l_threshold = nla_get_u32(nla_l_thresh);
3357
3358 if (nla_tun_type)
3359 udest->tun_type = nla_get_u8(nla_tun_type);
3360
3361 if (nla_tun_port)
3362 udest->tun_port = nla_get_be16(nla_tun_port);
3333 } 3363 }
3334 3364
3335 return 0; 3365 return 0;
@@ -3340,7 +3370,7 @@ static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __u32 state,
3340{ 3370{
3341 struct nlattr *nl_daemon; 3371 struct nlattr *nl_daemon;
3342 3372
3343 nl_daemon = nla_nest_start(skb, IPVS_CMD_ATTR_DAEMON); 3373 nl_daemon = nla_nest_start_noflag(skb, IPVS_CMD_ATTR_DAEMON);
3344 if (!nl_daemon) 3374 if (!nl_daemon)
3345 return -EMSGSIZE; 3375 return -EMSGSIZE;
3346 3376
@@ -3528,9 +3558,7 @@ static int ip_vs_genl_set_daemon(struct sk_buff *skb, struct genl_info *info)
3528 struct nlattr *daemon_attrs[IPVS_DAEMON_ATTR_MAX + 1]; 3558 struct nlattr *daemon_attrs[IPVS_DAEMON_ATTR_MAX + 1];
3529 3559
3530 if (!info->attrs[IPVS_CMD_ATTR_DAEMON] || 3560 if (!info->attrs[IPVS_CMD_ATTR_DAEMON] ||
3531 nla_parse_nested(daemon_attrs, IPVS_DAEMON_ATTR_MAX, 3561 nla_parse_nested_deprecated(daemon_attrs, IPVS_DAEMON_ATTR_MAX, info->attrs[IPVS_CMD_ATTR_DAEMON], ip_vs_daemon_policy, info->extack))
3532 info->attrs[IPVS_CMD_ATTR_DAEMON],
3533 ip_vs_daemon_policy, info->extack))
3534 goto out; 3562 goto out;
3535 3563
3536 if (cmd == IPVS_CMD_NEW_DAEMON) 3564 if (cmd == IPVS_CMD_NEW_DAEMON)
@@ -3774,94 +3802,98 @@ out:
3774static const struct genl_ops ip_vs_genl_ops[] = { 3802static const struct genl_ops ip_vs_genl_ops[] = {
3775 { 3803 {
3776 .cmd = IPVS_CMD_NEW_SERVICE, 3804 .cmd = IPVS_CMD_NEW_SERVICE,
3805 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3777 .flags = GENL_ADMIN_PERM, 3806 .flags = GENL_ADMIN_PERM,
3778 .policy = ip_vs_cmd_policy,
3779 .doit = ip_vs_genl_set_cmd, 3807 .doit = ip_vs_genl_set_cmd,
3780 }, 3808 },
3781 { 3809 {
3782 .cmd = IPVS_CMD_SET_SERVICE, 3810 .cmd = IPVS_CMD_SET_SERVICE,
3811 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3783 .flags = GENL_ADMIN_PERM, 3812 .flags = GENL_ADMIN_PERM,
3784 .policy = ip_vs_cmd_policy,
3785 .doit = ip_vs_genl_set_cmd, 3813 .doit = ip_vs_genl_set_cmd,
3786 }, 3814 },
3787 { 3815 {
3788 .cmd = IPVS_CMD_DEL_SERVICE, 3816 .cmd = IPVS_CMD_DEL_SERVICE,
3817 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3789 .flags = GENL_ADMIN_PERM, 3818 .flags = GENL_ADMIN_PERM,
3790 .policy = ip_vs_cmd_policy,
3791 .doit = ip_vs_genl_set_cmd, 3819 .doit = ip_vs_genl_set_cmd,
3792 }, 3820 },
3793 { 3821 {
3794 .cmd = IPVS_CMD_GET_SERVICE, 3822 .cmd = IPVS_CMD_GET_SERVICE,
3823 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3795 .flags = GENL_ADMIN_PERM, 3824 .flags = GENL_ADMIN_PERM,
3796 .doit = ip_vs_genl_get_cmd, 3825 .doit = ip_vs_genl_get_cmd,
3797 .dumpit = ip_vs_genl_dump_services, 3826 .dumpit = ip_vs_genl_dump_services,
3798 .policy = ip_vs_cmd_policy,
3799 }, 3827 },
3800 { 3828 {
3801 .cmd = IPVS_CMD_NEW_DEST, 3829 .cmd = IPVS_CMD_NEW_DEST,
3830 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3802 .flags = GENL_ADMIN_PERM, 3831 .flags = GENL_ADMIN_PERM,
3803 .policy = ip_vs_cmd_policy,
3804 .doit = ip_vs_genl_set_cmd, 3832 .doit = ip_vs_genl_set_cmd,
3805 }, 3833 },
3806 { 3834 {
3807 .cmd = IPVS_CMD_SET_DEST, 3835 .cmd = IPVS_CMD_SET_DEST,
3836 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3808 .flags = GENL_ADMIN_PERM, 3837 .flags = GENL_ADMIN_PERM,
3809 .policy = ip_vs_cmd_policy,
3810 .doit = ip_vs_genl_set_cmd, 3838 .doit = ip_vs_genl_set_cmd,
3811 }, 3839 },
3812 { 3840 {
3813 .cmd = IPVS_CMD_DEL_DEST, 3841 .cmd = IPVS_CMD_DEL_DEST,
3842 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3814 .flags = GENL_ADMIN_PERM, 3843 .flags = GENL_ADMIN_PERM,
3815 .policy = ip_vs_cmd_policy,
3816 .doit = ip_vs_genl_set_cmd, 3844 .doit = ip_vs_genl_set_cmd,
3817 }, 3845 },
3818 { 3846 {
3819 .cmd = IPVS_CMD_GET_DEST, 3847 .cmd = IPVS_CMD_GET_DEST,
3848 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3820 .flags = GENL_ADMIN_PERM, 3849 .flags = GENL_ADMIN_PERM,
3821 .policy = ip_vs_cmd_policy,
3822 .dumpit = ip_vs_genl_dump_dests, 3850 .dumpit = ip_vs_genl_dump_dests,
3823 }, 3851 },
3824 { 3852 {
3825 .cmd = IPVS_CMD_NEW_DAEMON, 3853 .cmd = IPVS_CMD_NEW_DAEMON,
3854 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3826 .flags = GENL_ADMIN_PERM, 3855 .flags = GENL_ADMIN_PERM,
3827 .policy = ip_vs_cmd_policy,
3828 .doit = ip_vs_genl_set_daemon, 3856 .doit = ip_vs_genl_set_daemon,
3829 }, 3857 },
3830 { 3858 {
3831 .cmd = IPVS_CMD_DEL_DAEMON, 3859 .cmd = IPVS_CMD_DEL_DAEMON,
3860 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3832 .flags = GENL_ADMIN_PERM, 3861 .flags = GENL_ADMIN_PERM,
3833 .policy = ip_vs_cmd_policy,
3834 .doit = ip_vs_genl_set_daemon, 3862 .doit = ip_vs_genl_set_daemon,
3835 }, 3863 },
3836 { 3864 {
3837 .cmd = IPVS_CMD_GET_DAEMON, 3865 .cmd = IPVS_CMD_GET_DAEMON,
3866 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3838 .flags = GENL_ADMIN_PERM, 3867 .flags = GENL_ADMIN_PERM,
3839 .dumpit = ip_vs_genl_dump_daemons, 3868 .dumpit = ip_vs_genl_dump_daemons,
3840 }, 3869 },
3841 { 3870 {
3842 .cmd = IPVS_CMD_SET_CONFIG, 3871 .cmd = IPVS_CMD_SET_CONFIG,
3872 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3843 .flags = GENL_ADMIN_PERM, 3873 .flags = GENL_ADMIN_PERM,
3844 .policy = ip_vs_cmd_policy,
3845 .doit = ip_vs_genl_set_cmd, 3874 .doit = ip_vs_genl_set_cmd,
3846 }, 3875 },
3847 { 3876 {
3848 .cmd = IPVS_CMD_GET_CONFIG, 3877 .cmd = IPVS_CMD_GET_CONFIG,
3878 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3849 .flags = GENL_ADMIN_PERM, 3879 .flags = GENL_ADMIN_PERM,
3850 .doit = ip_vs_genl_get_cmd, 3880 .doit = ip_vs_genl_get_cmd,
3851 }, 3881 },
3852 { 3882 {
3853 .cmd = IPVS_CMD_GET_INFO, 3883 .cmd = IPVS_CMD_GET_INFO,
3884 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3854 .flags = GENL_ADMIN_PERM, 3885 .flags = GENL_ADMIN_PERM,
3855 .doit = ip_vs_genl_get_cmd, 3886 .doit = ip_vs_genl_get_cmd,
3856 }, 3887 },
3857 { 3888 {
3858 .cmd = IPVS_CMD_ZERO, 3889 .cmd = IPVS_CMD_ZERO,
3890 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3859 .flags = GENL_ADMIN_PERM, 3891 .flags = GENL_ADMIN_PERM,
3860 .policy = ip_vs_cmd_policy,
3861 .doit = ip_vs_genl_set_cmd, 3892 .doit = ip_vs_genl_set_cmd,
3862 }, 3893 },
3863 { 3894 {
3864 .cmd = IPVS_CMD_FLUSH, 3895 .cmd = IPVS_CMD_FLUSH,
3896 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3865 .flags = GENL_ADMIN_PERM, 3897 .flags = GENL_ADMIN_PERM,
3866 .doit = ip_vs_genl_set_cmd, 3898 .doit = ip_vs_genl_set_cmd,
3867 }, 3899 },
@@ -3872,6 +3904,7 @@ static struct genl_family ip_vs_genl_family __ro_after_init = {
3872 .name = IPVS_GENL_NAME, 3904 .name = IPVS_GENL_NAME,
3873 .version = IPVS_GENL_VERSION, 3905 .version = IPVS_GENL_VERSION,
3874 .maxattr = IPVS_CMD_ATTR_MAX, 3906 .maxattr = IPVS_CMD_ATTR_MAX,
3907 .policy = ip_vs_cmd_policy,
3875 .netnsok = true, /* Make ipvsadm to work on netns */ 3908 .netnsok = true, /* Make ipvsadm to work on netns */
3876 .module = THIS_MODULE, 3909 .module = THIS_MODULE,
3877 .ops = ip_vs_genl_ops, 3910 .ops = ip_vs_genl_ops,
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index 175349fcf91f..8d6f94b67772 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -32,6 +32,7 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/tcp.h> /* for tcphdr */ 33#include <linux/tcp.h> /* for tcphdr */
34#include <net/ip.h> 34#include <net/ip.h>
35#include <net/gue.h>
35#include <net/tcp.h> /* for csum_tcpudp_magic */ 36#include <net/tcp.h> /* for csum_tcpudp_magic */
36#include <net/udp.h> 37#include <net/udp.h>
37#include <net/icmp.h> /* for icmp_send */ 38#include <net/icmp.h> /* for icmp_send */
@@ -382,6 +383,10 @@ __ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
382 mtu = dst_mtu(&rt->dst); 383 mtu = dst_mtu(&rt->dst);
383 } else { 384 } else {
384 mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr); 385 mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr);
386 if (!dest)
387 goto err_put;
388 if (dest->tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE)
389 mtu -= sizeof(struct udphdr) + sizeof(struct guehdr);
385 if (mtu < 68) { 390 if (mtu < 68) {
386 IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__); 391 IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__);
387 goto err_put; 392 goto err_put;
@@ -533,6 +538,10 @@ __ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
533 mtu = dst_mtu(&rt->dst); 538 mtu = dst_mtu(&rt->dst);
534 else { 539 else {
535 mtu = dst_mtu(&rt->dst) - sizeof(struct ipv6hdr); 540 mtu = dst_mtu(&rt->dst) - sizeof(struct ipv6hdr);
541 if (!dest)
542 goto err_put;
543 if (dest->tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE)
544 mtu -= sizeof(struct udphdr) + sizeof(struct guehdr);
536 if (mtu < IPV6_MIN_MTU) { 545 if (mtu < IPV6_MIN_MTU) {
537 IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__, 546 IP_VS_DBG_RL("%s(): mtu less than %d\n", __func__,
538 IPV6_MIN_MTU); 547 IPV6_MIN_MTU);
@@ -989,6 +998,41 @@ static inline int __tun_gso_type_mask(int encaps_af, int orig_af)
989 } 998 }
990} 999}
991 1000
1001static int
1002ipvs_gue_encap(struct net *net, struct sk_buff *skb,
1003 struct ip_vs_conn *cp, __u8 *next_protocol)
1004{
1005 __be16 dport;
1006 __be16 sport = udp_flow_src_port(net, skb, 0, 0, false);
1007 struct udphdr *udph; /* Our new UDP header */
1008 struct guehdr *gueh; /* Our new GUE header */
1009
1010 skb_push(skb, sizeof(struct guehdr));
1011
1012 gueh = (struct guehdr *)skb->data;
1013
1014 gueh->control = 0;
1015 gueh->version = 0;
1016 gueh->hlen = 0;
1017 gueh->flags = 0;
1018 gueh->proto_ctype = *next_protocol;
1019
1020 skb_push(skb, sizeof(struct udphdr));
1021 skb_reset_transport_header(skb);
1022
1023 udph = udp_hdr(skb);
1024
1025 dport = cp->dest->tun_port;
1026 udph->dest = dport;
1027 udph->source = sport;
1028 udph->len = htons(skb->len);
1029 udph->check = 0;
1030
1031 *next_protocol = IPPROTO_UDP;
1032
1033 return 0;
1034}
1035
992/* 1036/*
993 * IP Tunneling transmitter 1037 * IP Tunneling transmitter
994 * 1038 *
@@ -1025,6 +1069,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1025 struct iphdr *iph; /* Our new IP header */ 1069 struct iphdr *iph; /* Our new IP header */
1026 unsigned int max_headroom; /* The extra header space needed */ 1070 unsigned int max_headroom; /* The extra header space needed */
1027 int ret, local; 1071 int ret, local;
1072 int tun_type, gso_type;
1028 1073
1029 EnterFunction(10); 1074 EnterFunction(10);
1030 1075
@@ -1046,6 +1091,11 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1046 */ 1091 */
1047 max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct iphdr); 1092 max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct iphdr);
1048 1093
1094 tun_type = cp->dest->tun_type;
1095
1096 if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE)
1097 max_headroom += sizeof(struct udphdr) + sizeof(struct guehdr);
1098
1049 /* We only care about the df field if sysctl_pmtu_disc(ipvs) is set */ 1099 /* We only care about the df field if sysctl_pmtu_disc(ipvs) is set */
1050 dfp = sysctl_pmtu_disc(ipvs) ? &df : NULL; 1100 dfp = sysctl_pmtu_disc(ipvs) ? &df : NULL;
1051 skb = ip_vs_prepare_tunneled_skb(skb, cp->af, max_headroom, 1101 skb = ip_vs_prepare_tunneled_skb(skb, cp->af, max_headroom,
@@ -1054,11 +1104,20 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1054 if (IS_ERR(skb)) 1104 if (IS_ERR(skb))
1055 goto tx_error; 1105 goto tx_error;
1056 1106
1057 if (iptunnel_handle_offloads(skb, __tun_gso_type_mask(AF_INET, cp->af))) 1107 gso_type = __tun_gso_type_mask(AF_INET, cp->af);
1108 if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE)
1109 gso_type |= SKB_GSO_UDP_TUNNEL;
1110
1111 if (iptunnel_handle_offloads(skb, gso_type))
1058 goto tx_error; 1112 goto tx_error;
1059 1113
1060 skb->transport_header = skb->network_header; 1114 skb->transport_header = skb->network_header;
1061 1115
1116 skb_set_inner_ipproto(skb, next_protocol);
1117
1118 if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE)
1119 ipvs_gue_encap(net, skb, cp, &next_protocol);
1120
1062 skb_push(skb, sizeof(struct iphdr)); 1121 skb_push(skb, sizeof(struct iphdr));
1063 skb_reset_network_header(skb); 1122 skb_reset_network_header(skb);
1064 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); 1123 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
@@ -1102,6 +1161,8 @@ int
1102ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1161ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1103 struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh) 1162 struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
1104{ 1163{
1164 struct netns_ipvs *ipvs = cp->ipvs;
1165 struct net *net = ipvs->net;
1105 struct rt6_info *rt; /* Route to the other host */ 1166 struct rt6_info *rt; /* Route to the other host */
1106 struct in6_addr saddr; /* Source for tunnel */ 1167 struct in6_addr saddr; /* Source for tunnel */
1107 struct net_device *tdev; /* Device to other host */ 1168 struct net_device *tdev; /* Device to other host */
@@ -1112,10 +1173,11 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1112 struct ipv6hdr *iph; /* Our new IP header */ 1173 struct ipv6hdr *iph; /* Our new IP header */
1113 unsigned int max_headroom; /* The extra header space needed */ 1174 unsigned int max_headroom; /* The extra header space needed */
1114 int ret, local; 1175 int ret, local;
1176 int tun_type, gso_type;
1115 1177
1116 EnterFunction(10); 1178 EnterFunction(10);
1117 1179
1118 local = __ip_vs_get_out_rt_v6(cp->ipvs, cp->af, skb, cp->dest, 1180 local = __ip_vs_get_out_rt_v6(ipvs, cp->af, skb, cp->dest,
1119 &cp->daddr.in6, 1181 &cp->daddr.in6,
1120 &saddr, ipvsh, 1, 1182 &saddr, ipvsh, 1,
1121 IP_VS_RT_MODE_LOCAL | 1183 IP_VS_RT_MODE_LOCAL |
@@ -1134,17 +1196,31 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1134 */ 1196 */
1135 max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct ipv6hdr); 1197 max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(struct ipv6hdr);
1136 1198
1199 tun_type = cp->dest->tun_type;
1200
1201 if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE)
1202 max_headroom += sizeof(struct udphdr) + sizeof(struct guehdr);
1203
1137 skb = ip_vs_prepare_tunneled_skb(skb, cp->af, max_headroom, 1204 skb = ip_vs_prepare_tunneled_skb(skb, cp->af, max_headroom,
1138 &next_protocol, &payload_len, 1205 &next_protocol, &payload_len,
1139 &dsfield, &ttl, NULL); 1206 &dsfield, &ttl, NULL);
1140 if (IS_ERR(skb)) 1207 if (IS_ERR(skb))
1141 goto tx_error; 1208 goto tx_error;
1142 1209
1143 if (iptunnel_handle_offloads(skb, __tun_gso_type_mask(AF_INET6, cp->af))) 1210 gso_type = __tun_gso_type_mask(AF_INET6, cp->af);
1211 if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE)
1212 gso_type |= SKB_GSO_UDP_TUNNEL;
1213
1214 if (iptunnel_handle_offloads(skb, gso_type))
1144 goto tx_error; 1215 goto tx_error;
1145 1216
1146 skb->transport_header = skb->network_header; 1217 skb->transport_header = skb->network_header;
1147 1218
1219 skb_set_inner_ipproto(skb, next_protocol);
1220
1221 if (tun_type == IP_VS_CONN_F_TUNNEL_TYPE_GUE)
1222 ipvs_gue_encap(net, skb, cp, &next_protocol);
1223
1148 skb_push(skb, sizeof(struct ipv6hdr)); 1224 skb_push(skb, sizeof(struct ipv6hdr));
1149 skb_reset_network_header(skb); 1225 skb_reset_network_header(skb);
1150 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); 1226 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
@@ -1167,7 +1243,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1167 1243
1168 ret = ip_vs_tunnel_xmit_prepare(skb, cp); 1244 ret = ip_vs_tunnel_xmit_prepare(skb, cp);
1169 if (ret == NF_ACCEPT) 1245 if (ret == NF_ACCEPT)
1170 ip6_local_out(cp->ipvs->net, skb->sk, skb); 1246 ip6_local_out(net, skb->sk, skb);
1171 else if (ret == NF_DROP) 1247 else if (ret == NF_DROP)
1172 kfree_skb(skb); 1248 kfree_skb(skb);
1173 1249
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
index f2681ec5b5f6..dbec6fca0d9e 100644
--- a/net/netfilter/nf_conntrack_amanda.c
+++ b/net/netfilter/nf_conntrack_amanda.c
@@ -28,11 +28,13 @@
28static unsigned int master_timeout __read_mostly = 300; 28static unsigned int master_timeout __read_mostly = 300;
29static char *ts_algo = "kmp"; 29static char *ts_algo = "kmp";
30 30
31#define HELPER_NAME "amanda"
32
31MODULE_AUTHOR("Brian J. Murrell <netfilter@interlinx.bc.ca>"); 33MODULE_AUTHOR("Brian J. Murrell <netfilter@interlinx.bc.ca>");
32MODULE_DESCRIPTION("Amanda connection tracking module"); 34MODULE_DESCRIPTION("Amanda connection tracking module");
33MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
34MODULE_ALIAS("ip_conntrack_amanda"); 36MODULE_ALIAS("ip_conntrack_amanda");
35MODULE_ALIAS_NFCT_HELPER("amanda"); 37MODULE_ALIAS_NFCT_HELPER(HELPER_NAME);
36 38
37module_param(master_timeout, uint, 0600); 39module_param(master_timeout, uint, 0600);
38MODULE_PARM_DESC(master_timeout, "timeout for the master connection"); 40MODULE_PARM_DESC(master_timeout, "timeout for the master connection");
@@ -179,13 +181,14 @@ static const struct nf_conntrack_expect_policy amanda_exp_policy = {
179 181
180static struct nf_conntrack_helper amanda_helper[2] __read_mostly = { 182static struct nf_conntrack_helper amanda_helper[2] __read_mostly = {
181 { 183 {
182 .name = "amanda", 184 .name = HELPER_NAME,
183 .me = THIS_MODULE, 185 .me = THIS_MODULE,
184 .help = amanda_help, 186 .help = amanda_help,
185 .tuple.src.l3num = AF_INET, 187 .tuple.src.l3num = AF_INET,
186 .tuple.src.u.udp.port = cpu_to_be16(10080), 188 .tuple.src.u.udp.port = cpu_to_be16(10080),
187 .tuple.dst.protonum = IPPROTO_UDP, 189 .tuple.dst.protonum = IPPROTO_UDP,
188 .expect_policy = &amanda_exp_policy, 190 .expect_policy = &amanda_exp_policy,
191 .nat_mod_name = NF_NAT_HELPER_NAME(HELPER_NAME),
189 }, 192 },
190 { 193 {
191 .name = "amanda", 194 .name = "amanda",
@@ -195,6 +198,7 @@ static struct nf_conntrack_helper amanda_helper[2] __read_mostly = {
195 .tuple.src.u.udp.port = cpu_to_be16(10080), 198 .tuple.src.u.udp.port = cpu_to_be16(10080),
196 .tuple.dst.protonum = IPPROTO_UDP, 199 .tuple.dst.protonum = IPPROTO_UDP,
197 .expect_policy = &amanda_exp_policy, 200 .expect_policy = &amanda_exp_policy,
201 .nat_mod_name = NF_NAT_HELPER_NAME(HELPER_NAME),
198 }, 202 },
199}; 203};
200 204
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 82bfbeef46af..2a714527cde1 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/random.h> 26#include <linux/random.h>
27#include <linux/jhash.h> 27#include <linux/jhash.h>
28#include <linux/siphash.h>
28#include <linux/err.h> 29#include <linux/err.h>
29#include <linux/percpu.h> 30#include <linux/percpu.h>
30#include <linux/moduleparam.h> 31#include <linux/moduleparam.h>
@@ -449,6 +450,40 @@ nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
449} 450}
450EXPORT_SYMBOL_GPL(nf_ct_invert_tuple); 451EXPORT_SYMBOL_GPL(nf_ct_invert_tuple);
451 452
453/* Generate a almost-unique pseudo-id for a given conntrack.
454 *
455 * intentionally doesn't re-use any of the seeds used for hash
456 * table location, we assume id gets exposed to userspace.
457 *
458 * Following nf_conn items do not change throughout lifetime
459 * of the nf_conn after it has been committed to main hash table:
460 *
461 * 1. nf_conn address
462 * 2. nf_conn->ext address
463 * 3. nf_conn->master address (normally NULL)
464 * 4. tuple
465 * 5. the associated net namespace
466 */
467u32 nf_ct_get_id(const struct nf_conn *ct)
468{
469 static __read_mostly siphash_key_t ct_id_seed;
470 unsigned long a, b, c, d;
471
472 net_get_random_once(&ct_id_seed, sizeof(ct_id_seed));
473
474 a = (unsigned long)ct;
475 b = (unsigned long)ct->master ^ net_hash_mix(nf_ct_net(ct));
476 c = (unsigned long)ct->ext;
477 d = (unsigned long)siphash(&ct->tuplehash, sizeof(ct->tuplehash),
478 &ct_id_seed);
479#ifdef CONFIG_64BIT
480 return siphash_4u64((u64)a, (u64)b, (u64)c, (u64)d, &ct_id_seed);
481#else
482 return siphash_4u32((u32)a, (u32)b, (u32)c, (u32)d, &ct_id_seed);
483#endif
484}
485EXPORT_SYMBOL_GPL(nf_ct_get_id);
486
452static void 487static void
453clean_from_lists(struct nf_conn *ct) 488clean_from_lists(struct nf_conn *ct)
454{ 489{
@@ -982,12 +1017,9 @@ __nf_conntrack_confirm(struct sk_buff *skb)
982 1017
983 /* set conntrack timestamp, if enabled. */ 1018 /* set conntrack timestamp, if enabled. */
984 tstamp = nf_conn_tstamp_find(ct); 1019 tstamp = nf_conn_tstamp_find(ct);
985 if (tstamp) { 1020 if (tstamp)
986 if (skb->tstamp == 0) 1021 tstamp->start = ktime_get_real_ns();
987 __net_timestamp(skb);
988 1022
989 tstamp->start = ktime_to_ns(skb->tstamp);
990 }
991 /* Since the lookup is lockless, hash insertion must be done after 1023 /* Since the lookup is lockless, hash insertion must be done after
992 * starting the timer and setting the CONFIRMED bit. The RCU barriers 1024 * starting the timer and setting the CONFIRMED bit. The RCU barriers
993 * guarantee that no other CPU can find the conntrack before the above 1025 * guarantee that no other CPU can find the conntrack before the above
@@ -1350,6 +1382,7 @@ __nf_conntrack_alloc(struct net *net,
1350 /* save hash for reusing when confirming */ 1382 /* save hash for reusing when confirming */
1351 *(unsigned long *)(&ct->tuplehash[IP_CT_DIR_REPLY].hnnode.pprev) = hash; 1383 *(unsigned long *)(&ct->tuplehash[IP_CT_DIR_REPLY].hnnode.pprev) = hash;
1352 ct->status = 0; 1384 ct->status = 0;
1385 ct->timeout = 0;
1353 write_pnet(&ct->ct_net, net); 1386 write_pnet(&ct->ct_net, net);
1354 memset(&ct->__nfct_init_offset[0], 0, 1387 memset(&ct->__nfct_init_offset[0], 0,
1355 offsetof(struct nf_conn, proto) - 1388 offsetof(struct nf_conn, proto) -
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 334d6e5b7762..59c18804a10a 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -336,7 +336,7 @@ void nf_ct_expect_init(struct nf_conntrack_expect *exp, unsigned int class,
336 336
337 exp->tuple.dst.u.all = *dst; 337 exp->tuple.dst.u.all = *dst;
338 338
339#ifdef CONFIG_NF_NAT_NEEDED 339#if IS_ENABLED(CONFIG_NF_NAT)
340 memset(&exp->saved_addr, 0, sizeof(exp->saved_addr)); 340 memset(&exp->saved_addr, 0, sizeof(exp->saved_addr));
341 memset(&exp->saved_proto, 0, sizeof(exp->saved_proto)); 341 memset(&exp->saved_proto, 0, sizeof(exp->saved_proto));
342#endif 342#endif
diff --git a/net/netfilter/nf_conntrack_ftp.c b/net/netfilter/nf_conntrack_ftp.c
index a11c304fb771..32aeac1c4760 100644
--- a/net/netfilter/nf_conntrack_ftp.c
+++ b/net/netfilter/nf_conntrack_ftp.c
@@ -29,11 +29,13 @@
29#include <net/netfilter/nf_conntrack_helper.h> 29#include <net/netfilter/nf_conntrack_helper.h>
30#include <linux/netfilter/nf_conntrack_ftp.h> 30#include <linux/netfilter/nf_conntrack_ftp.h>
31 31
32#define HELPER_NAME "ftp"
33
32MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
33MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>"); 35MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>");
34MODULE_DESCRIPTION("ftp connection tracking helper"); 36MODULE_DESCRIPTION("ftp connection tracking helper");
35MODULE_ALIAS("ip_conntrack_ftp"); 37MODULE_ALIAS("ip_conntrack_ftp");
36MODULE_ALIAS_NFCT_HELPER("ftp"); 38MODULE_ALIAS_NFCT_HELPER(HELPER_NAME);
37 39
38/* This is slow, but it's simple. --RR */ 40/* This is slow, but it's simple. --RR */
39static char *ftp_buffer; 41static char *ftp_buffer;
@@ -588,12 +590,14 @@ static int __init nf_conntrack_ftp_init(void)
588 /* FIXME should be configurable whether IPv4 and IPv6 FTP connections 590 /* FIXME should be configurable whether IPv4 and IPv6 FTP connections
589 are tracked or not - YK */ 591 are tracked or not - YK */
590 for (i = 0; i < ports_c; i++) { 592 for (i = 0; i < ports_c; i++) {
591 nf_ct_helper_init(&ftp[2 * i], AF_INET, IPPROTO_TCP, "ftp", 593 nf_ct_helper_init(&ftp[2 * i], AF_INET, IPPROTO_TCP,
592 FTP_PORT, ports[i], ports[i], &ftp_exp_policy, 594 HELPER_NAME, FTP_PORT, ports[i], ports[i],
593 0, help, nf_ct_ftp_from_nlattr, THIS_MODULE); 595 &ftp_exp_policy, 0, help,
594 nf_ct_helper_init(&ftp[2 * i + 1], AF_INET6, IPPROTO_TCP, "ftp", 596 nf_ct_ftp_from_nlattr, THIS_MODULE);
595 FTP_PORT, ports[i], ports[i], &ftp_exp_policy, 597 nf_ct_helper_init(&ftp[2 * i + 1], AF_INET6, IPPROTO_TCP,
596 0, help, nf_ct_ftp_from_nlattr, THIS_MODULE); 598 HELPER_NAME, FTP_PORT, ports[i], ports[i],
599 &ftp_exp_policy, 0, help,
600 nf_ct_ftp_from_nlattr, THIS_MODULE);
597 } 601 }
598 602
599 ret = nf_conntrack_helpers_register(ftp, ports_c * 2); 603 ret = nf_conntrack_helpers_register(ftp, ports_c * 2);
diff --git a/net/netfilter/nf_conntrack_h323_asn1.c b/net/netfilter/nf_conntrack_h323_asn1.c
index 1601275efe2d..4c2ef42e189c 100644
--- a/net/netfilter/nf_conntrack_h323_asn1.c
+++ b/net/netfilter/nf_conntrack_h323_asn1.c
@@ -172,7 +172,7 @@ static int nf_h323_error_boundary(struct bitstr *bs, size_t bytes, size_t bits)
172 if (bits % BITS_PER_BYTE > 0) 172 if (bits % BITS_PER_BYTE > 0)
173 bytes++; 173 bytes++;
174 174
175 if (*bs->cur + bytes > *bs->end) 175 if (bs->cur + bytes > bs->end)
176 return 1; 176 return 1;
177 177
178 return 0; 178 return 0;
diff --git a/net/netfilter/nf_conntrack_h323_main.c b/net/netfilter/nf_conntrack_h323_main.c
index 005589c6d0f6..12de40390e97 100644
--- a/net/netfilter/nf_conntrack_h323_main.c
+++ b/net/netfilter/nf_conntrack_h323_main.c
@@ -748,24 +748,19 @@ static int callforward_do_filter(struct net *net,
748 } 748 }
749 break; 749 break;
750 } 750 }
751#if IS_ENABLED(CONFIG_NF_CONNTRACK_IPV6) 751#if IS_ENABLED(CONFIG_IPV6)
752 case AF_INET6: { 752 case AF_INET6: {
753 const struct nf_ipv6_ops *v6ops;
754 struct rt6_info *rt1, *rt2; 753 struct rt6_info *rt1, *rt2;
755 struct flowi6 fl1, fl2; 754 struct flowi6 fl1, fl2;
756 755
757 v6ops = nf_get_ipv6_ops();
758 if (!v6ops)
759 return 0;
760
761 memset(&fl1, 0, sizeof(fl1)); 756 memset(&fl1, 0, sizeof(fl1));
762 fl1.daddr = src->in6; 757 fl1.daddr = src->in6;
763 758
764 memset(&fl2, 0, sizeof(fl2)); 759 memset(&fl2, 0, sizeof(fl2));
765 fl2.daddr = dst->in6; 760 fl2.daddr = dst->in6;
766 if (!v6ops->route(net, (struct dst_entry **)&rt1, 761 if (!nf_ip6_route(net, (struct dst_entry **)&rt1,
767 flowi6_to_flowi(&fl1), false)) { 762 flowi6_to_flowi(&fl1), false)) {
768 if (!v6ops->route(net, (struct dst_entry **)&rt2, 763 if (!nf_ip6_route(net, (struct dst_entry **)&rt2,
769 flowi6_to_flowi(&fl2), false)) { 764 flowi6_to_flowi(&fl2), false)) {
770 if (ipv6_addr_equal(rt6_nexthop(rt1, &fl1.daddr), 765 if (ipv6_addr_equal(rt6_nexthop(rt1, &fl1.daddr),
771 rt6_nexthop(rt2, &fl2.daddr)) && 766 rt6_nexthop(rt2, &fl2.daddr)) &&
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index 274baf1dab87..918df7f71c8f 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -42,6 +42,9 @@ module_param_named(nf_conntrack_helper, nf_ct_auto_assign_helper, bool, 0644);
42MODULE_PARM_DESC(nf_conntrack_helper, 42MODULE_PARM_DESC(nf_conntrack_helper,
43 "Enable automatic conntrack helper assignment (default 0)"); 43 "Enable automatic conntrack helper assignment (default 0)");
44 44
45static DEFINE_MUTEX(nf_ct_nat_helpers_mutex);
46static struct list_head nf_ct_nat_helpers __read_mostly;
47
45/* Stupid hash, but collision free for the default registrations of the 48/* Stupid hash, but collision free for the default registrations of the
46 * helpers currently in the kernel. */ 49 * helpers currently in the kernel. */
47static unsigned int helper_hash(const struct nf_conntrack_tuple *tuple) 50static unsigned int helper_hash(const struct nf_conntrack_tuple *tuple)
@@ -130,6 +133,70 @@ void nf_conntrack_helper_put(struct nf_conntrack_helper *helper)
130} 133}
131EXPORT_SYMBOL_GPL(nf_conntrack_helper_put); 134EXPORT_SYMBOL_GPL(nf_conntrack_helper_put);
132 135
136static struct nf_conntrack_nat_helper *
137nf_conntrack_nat_helper_find(const char *mod_name)
138{
139 struct nf_conntrack_nat_helper *cur;
140 bool found = false;
141
142 list_for_each_entry_rcu(cur, &nf_ct_nat_helpers, list) {
143 if (!strcmp(cur->mod_name, mod_name)) {
144 found = true;
145 break;
146 }
147 }
148 return found ? cur : NULL;
149}
150
151int
152nf_nat_helper_try_module_get(const char *name, u16 l3num, u8 protonum)
153{
154 struct nf_conntrack_helper *h;
155 struct nf_conntrack_nat_helper *nat;
156 char mod_name[NF_CT_HELPER_NAME_LEN];
157 int ret = 0;
158
159 rcu_read_lock();
160 h = __nf_conntrack_helper_find(name, l3num, protonum);
161 if (!h) {
162 rcu_read_unlock();
163 return -ENOENT;
164 }
165
166 nat = nf_conntrack_nat_helper_find(h->nat_mod_name);
167 if (!nat) {
168 snprintf(mod_name, sizeof(mod_name), "%s", h->nat_mod_name);
169 rcu_read_unlock();
170 request_module(mod_name);
171
172 rcu_read_lock();
173 nat = nf_conntrack_nat_helper_find(mod_name);
174 if (!nat) {
175 rcu_read_unlock();
176 return -ENOENT;
177 }
178 }
179
180 if (!try_module_get(nat->module))
181 ret = -ENOENT;
182
183 rcu_read_unlock();
184 return ret;
185}
186EXPORT_SYMBOL_GPL(nf_nat_helper_try_module_get);
187
188void nf_nat_helper_put(struct nf_conntrack_helper *helper)
189{
190 struct nf_conntrack_nat_helper *nat;
191
192 nat = nf_conntrack_nat_helper_find(helper->nat_mod_name);
193 if (WARN_ON_ONCE(!nat))
194 return;
195
196 module_put(nat->module);
197}
198EXPORT_SYMBOL_GPL(nf_nat_helper_put);
199
133struct nf_conn_help * 200struct nf_conn_help *
134nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp) 201nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
135{ 202{
@@ -430,6 +497,8 @@ void nf_ct_helper_init(struct nf_conntrack_helper *helper,
430 helper->help = help; 497 helper->help = help;
431 helper->from_nlattr = from_nlattr; 498 helper->from_nlattr = from_nlattr;
432 helper->me = module; 499 helper->me = module;
500 snprintf(helper->nat_mod_name, sizeof(helper->nat_mod_name),
501 NF_NAT_HELPER_PREFIX "%s", name);
433 502
434 if (spec_port == default_port) 503 if (spec_port == default_port)
435 snprintf(helper->name, sizeof(helper->name), "%s", name); 504 snprintf(helper->name, sizeof(helper->name), "%s", name);
@@ -466,6 +535,22 @@ void nf_conntrack_helpers_unregister(struct nf_conntrack_helper *helper,
466} 535}
467EXPORT_SYMBOL_GPL(nf_conntrack_helpers_unregister); 536EXPORT_SYMBOL_GPL(nf_conntrack_helpers_unregister);
468 537
538void nf_nat_helper_register(struct nf_conntrack_nat_helper *nat)
539{
540 mutex_lock(&nf_ct_nat_helpers_mutex);
541 list_add_rcu(&nat->list, &nf_ct_nat_helpers);
542 mutex_unlock(&nf_ct_nat_helpers_mutex);
543}
544EXPORT_SYMBOL_GPL(nf_nat_helper_register);
545
546void nf_nat_helper_unregister(struct nf_conntrack_nat_helper *nat)
547{
548 mutex_lock(&nf_ct_nat_helpers_mutex);
549 list_del_rcu(&nat->list);
550 mutex_unlock(&nf_ct_nat_helpers_mutex);
551}
552EXPORT_SYMBOL_GPL(nf_nat_helper_unregister);
553
469static const struct nf_ct_ext_type helper_extend = { 554static const struct nf_ct_ext_type helper_extend = {
470 .len = sizeof(struct nf_conn_help), 555 .len = sizeof(struct nf_conn_help),
471 .align = __alignof__(struct nf_conn_help), 556 .align = __alignof__(struct nf_conn_help),
@@ -493,6 +578,7 @@ int nf_conntrack_helper_init(void)
493 goto out_extend; 578 goto out_extend;
494 } 579 }
495 580
581 INIT_LIST_HEAD(&nf_ct_nat_helpers);
496 return 0; 582 return 0;
497out_extend: 583out_extend:
498 kvfree(nf_ct_helper_hash); 584 kvfree(nf_ct_helper_hash);
diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_irc.c
index 4099f4d79bae..79e5014b3b0d 100644
--- a/net/netfilter/nf_conntrack_irc.c
+++ b/net/netfilter/nf_conntrack_irc.c
@@ -42,11 +42,13 @@ unsigned int (*nf_nat_irc_hook)(struct sk_buff *skb,
42 struct nf_conntrack_expect *exp) __read_mostly; 42 struct nf_conntrack_expect *exp) __read_mostly;
43EXPORT_SYMBOL_GPL(nf_nat_irc_hook); 43EXPORT_SYMBOL_GPL(nf_nat_irc_hook);
44 44
45#define HELPER_NAME "irc"
46
45MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 47MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
46MODULE_DESCRIPTION("IRC (DCC) connection tracking helper"); 48MODULE_DESCRIPTION("IRC (DCC) connection tracking helper");
47MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
48MODULE_ALIAS("ip_conntrack_irc"); 50MODULE_ALIAS("ip_conntrack_irc");
49MODULE_ALIAS_NFCT_HELPER("irc"); 51MODULE_ALIAS_NFCT_HELPER(HELPER_NAME);
50 52
51module_param_array(ports, ushort, &ports_c, 0400); 53module_param_array(ports, ushort, &ports_c, 0400);
52MODULE_PARM_DESC(ports, "port numbers of IRC servers"); 54MODULE_PARM_DESC(ports, "port numbers of IRC servers");
@@ -259,7 +261,7 @@ static int __init nf_conntrack_irc_init(void)
259 ports[ports_c++] = IRC_PORT; 261 ports[ports_c++] = IRC_PORT;
260 262
261 for (i = 0; i < ports_c; i++) { 263 for (i = 0; i < ports_c; i++) {
262 nf_ct_helper_init(&irc[i], AF_INET, IPPROTO_TCP, "irc", 264 nf_ct_helper_init(&irc[i], AF_INET, IPPROTO_TCP, HELPER_NAME,
263 IRC_PORT, ports[i], i, &irc_exp_policy, 265 IRC_PORT, ports[i], i, &irc_exp_policy,
264 0, help, NULL, THIS_MODULE); 266 0, help, NULL, THIS_MODULE);
265 } 267 }
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 66c596d287a5..7db79c1b8084 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -29,6 +29,7 @@
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/siphash.h>
32 33
33#include <linux/netfilter.h> 34#include <linux/netfilter.h>
34#include <net/netlink.h> 35#include <net/netlink.h>
@@ -45,7 +46,7 @@
45#include <net/netfilter/nf_conntrack_timestamp.h> 46#include <net/netfilter/nf_conntrack_timestamp.h>
46#include <net/netfilter/nf_conntrack_labels.h> 47#include <net/netfilter/nf_conntrack_labels.h>
47#include <net/netfilter/nf_conntrack_synproxy.h> 48#include <net/netfilter/nf_conntrack_synproxy.h>
48#ifdef CONFIG_NF_NAT_NEEDED 49#if IS_ENABLED(CONFIG_NF_NAT)
49#include <net/netfilter/nf_nat.h> 50#include <net/netfilter/nf_nat.h>
50#include <net/netfilter/nf_nat_helper.h> 51#include <net/netfilter/nf_nat_helper.h>
51#endif 52#endif
@@ -62,7 +63,7 @@ static int ctnetlink_dump_tuples_proto(struct sk_buff *skb,
62 int ret = 0; 63 int ret = 0;
63 struct nlattr *nest_parms; 64 struct nlattr *nest_parms;
64 65
65 nest_parms = nla_nest_start(skb, CTA_TUPLE_PROTO | NLA_F_NESTED); 66 nest_parms = nla_nest_start(skb, CTA_TUPLE_PROTO);
66 if (!nest_parms) 67 if (!nest_parms)
67 goto nla_put_failure; 68 goto nla_put_failure;
68 if (nla_put_u8(skb, CTA_PROTO_NUM, tuple->dst.protonum)) 69 if (nla_put_u8(skb, CTA_PROTO_NUM, tuple->dst.protonum))
@@ -103,7 +104,7 @@ static int ctnetlink_dump_tuples_ip(struct sk_buff *skb,
103 int ret = 0; 104 int ret = 0;
104 struct nlattr *nest_parms; 105 struct nlattr *nest_parms;
105 106
106 nest_parms = nla_nest_start(skb, CTA_TUPLE_IP | NLA_F_NESTED); 107 nest_parms = nla_nest_start(skb, CTA_TUPLE_IP);
107 if (!nest_parms) 108 if (!nest_parms)
108 goto nla_put_failure; 109 goto nla_put_failure;
109 110
@@ -186,7 +187,7 @@ static int ctnetlink_dump_protoinfo(struct sk_buff *skb, struct nf_conn *ct)
186 if (!l4proto->to_nlattr) 187 if (!l4proto->to_nlattr)
187 return 0; 188 return 0;
188 189
189 nest_proto = nla_nest_start(skb, CTA_PROTOINFO | NLA_F_NESTED); 190 nest_proto = nla_nest_start(skb, CTA_PROTOINFO);
190 if (!nest_proto) 191 if (!nest_proto)
191 goto nla_put_failure; 192 goto nla_put_failure;
192 193
@@ -214,7 +215,7 @@ static int ctnetlink_dump_helpinfo(struct sk_buff *skb,
214 if (!helper) 215 if (!helper)
215 goto out; 216 goto out;
216 217
217 nest_helper = nla_nest_start(skb, CTA_HELP | NLA_F_NESTED); 218 nest_helper = nla_nest_start(skb, CTA_HELP);
218 if (!nest_helper) 219 if (!nest_helper)
219 goto nla_put_failure; 220 goto nla_put_failure;
220 if (nla_put_string(skb, CTA_HELP_NAME, helper->name)) 221 if (nla_put_string(skb, CTA_HELP_NAME, helper->name))
@@ -248,7 +249,7 @@ dump_counters(struct sk_buff *skb, struct nf_conn_acct *acct,
248 bytes = atomic64_read(&counter[dir].bytes); 249 bytes = atomic64_read(&counter[dir].bytes);
249 } 250 }
250 251
251 nest_count = nla_nest_start(skb, attr | NLA_F_NESTED); 252 nest_count = nla_nest_start(skb, attr);
252 if (!nest_count) 253 if (!nest_count)
253 goto nla_put_failure; 254 goto nla_put_failure;
254 255
@@ -292,7 +293,7 @@ ctnetlink_dump_timestamp(struct sk_buff *skb, const struct nf_conn *ct)
292 if (!tstamp) 293 if (!tstamp)
293 return 0; 294 return 0;
294 295
295 nest_count = nla_nest_start(skb, CTA_TIMESTAMP | NLA_F_NESTED); 296 nest_count = nla_nest_start(skb, CTA_TIMESTAMP);
296 if (!nest_count) 297 if (!nest_count)
297 goto nla_put_failure; 298 goto nla_put_failure;
298 299
@@ -336,7 +337,7 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)
336 return 0; 337 return 0;
337 338
338 ret = -1; 339 ret = -1;
339 nest_secctx = nla_nest_start(skb, CTA_SECCTX | NLA_F_NESTED); 340 nest_secctx = nla_nest_start(skb, CTA_SECCTX);
340 if (!nest_secctx) 341 if (!nest_secctx)
341 goto nla_put_failure; 342 goto nla_put_failure;
342 343
@@ -396,7 +397,7 @@ static int ctnetlink_dump_master(struct sk_buff *skb, const struct nf_conn *ct)
396 if (!(ct->status & IPS_EXPECTED)) 397 if (!(ct->status & IPS_EXPECTED))
397 return 0; 398 return 0;
398 399
399 nest_parms = nla_nest_start(skb, CTA_TUPLE_MASTER | NLA_F_NESTED); 400 nest_parms = nla_nest_start(skb, CTA_TUPLE_MASTER);
400 if (!nest_parms) 401 if (!nest_parms)
401 goto nla_put_failure; 402 goto nla_put_failure;
402 if (ctnetlink_dump_tuples(skb, master_tuple(ct)) < 0) 403 if (ctnetlink_dump_tuples(skb, master_tuple(ct)) < 0)
@@ -414,7 +415,7 @@ dump_ct_seq_adj(struct sk_buff *skb, const struct nf_ct_seqadj *seq, int type)
414{ 415{
415 struct nlattr *nest_parms; 416 struct nlattr *nest_parms;
416 417
417 nest_parms = nla_nest_start(skb, type | NLA_F_NESTED); 418 nest_parms = nla_nest_start(skb, type);
418 if (!nest_parms) 419 if (!nest_parms)
419 goto nla_put_failure; 420 goto nla_put_failure;
420 421
@@ -466,7 +467,7 @@ static int ctnetlink_dump_ct_synproxy(struct sk_buff *skb, struct nf_conn *ct)
466 if (!synproxy) 467 if (!synproxy)
467 return 0; 468 return 0;
468 469
469 nest_parms = nla_nest_start(skb, CTA_SYNPROXY | NLA_F_NESTED); 470 nest_parms = nla_nest_start(skb, CTA_SYNPROXY);
470 if (!nest_parms) 471 if (!nest_parms)
471 goto nla_put_failure; 472 goto nla_put_failure;
472 473
@@ -485,7 +486,9 @@ nla_put_failure:
485 486
486static int ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct) 487static int ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct)
487{ 488{
488 if (nla_put_be32(skb, CTA_ID, htonl((unsigned long)ct))) 489 __be32 id = (__force __be32)nf_ct_get_id(ct);
490
491 if (nla_put_be32(skb, CTA_ID, id))
489 goto nla_put_failure; 492 goto nla_put_failure;
490 return 0; 493 return 0;
491 494
@@ -525,7 +528,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
525 528
526 zone = nf_ct_zone(ct); 529 zone = nf_ct_zone(ct);
527 530
528 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED); 531 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG);
529 if (!nest_parms) 532 if (!nest_parms)
530 goto nla_put_failure; 533 goto nla_put_failure;
531 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0) 534 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
@@ -535,7 +538,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
535 goto nla_put_failure; 538 goto nla_put_failure;
536 nla_nest_end(skb, nest_parms); 539 nla_nest_end(skb, nest_parms);
537 540
538 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY | NLA_F_NESTED); 541 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY);
539 if (!nest_parms) 542 if (!nest_parms)
540 goto nla_put_failure; 543 goto nla_put_failure;
541 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0) 544 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0)
@@ -655,7 +658,7 @@ static size_t ctnetlink_nlmsg_size(const struct nf_conn *ct)
655 + nla_total_size(0) /* CTA_HELP */ 658 + nla_total_size(0) /* CTA_HELP */
656 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */ 659 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */
657 + ctnetlink_secctx_size(ct) 660 + ctnetlink_secctx_size(ct)
658#ifdef CONFIG_NF_NAT_NEEDED 661#if IS_ENABLED(CONFIG_NF_NAT)
659 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */ 662 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */
660 + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */ 663 + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */
661#endif 664#endif
@@ -717,7 +720,7 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
717 720
718 zone = nf_ct_zone(ct); 721 zone = nf_ct_zone(ct);
719 722
720 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED); 723 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG);
721 if (!nest_parms) 724 if (!nest_parms)
722 goto nla_put_failure; 725 goto nla_put_failure;
723 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0) 726 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
@@ -727,7 +730,7 @@ ctnetlink_conntrack_event(unsigned int events, struct nf_ct_event *item)
727 goto nla_put_failure; 730 goto nla_put_failure;
728 nla_nest_end(skb, nest_parms); 731 nla_nest_end(skb, nest_parms);
729 732
730 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY | NLA_F_NESTED); 733 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY);
731 if (!nest_parms) 734 if (!nest_parms)
732 goto nla_put_failure; 735 goto nla_put_failure;
733 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0) 736 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0)
@@ -1017,12 +1020,12 @@ static int ctnetlink_parse_tuple_ip(struct nlattr *attr,
1017 struct nlattr *tb[CTA_IP_MAX+1]; 1020 struct nlattr *tb[CTA_IP_MAX+1];
1018 int ret = 0; 1021 int ret = 0;
1019 1022
1020 ret = nla_parse_nested(tb, CTA_IP_MAX, attr, NULL, NULL); 1023 ret = nla_parse_nested_deprecated(tb, CTA_IP_MAX, attr, NULL, NULL);
1021 if (ret < 0) 1024 if (ret < 0)
1022 return ret; 1025 return ret;
1023 1026
1024 ret = nla_validate_nested(attr, CTA_IP_MAX, 1027 ret = nla_validate_nested_deprecated(attr, CTA_IP_MAX,
1025 cta_ip_nla_policy, NULL); 1028 cta_ip_nla_policy, NULL);
1026 if (ret) 1029 if (ret)
1027 return ret; 1030 return ret;
1028 1031
@@ -1049,8 +1052,8 @@ static int ctnetlink_parse_tuple_proto(struct nlattr *attr,
1049 struct nlattr *tb[CTA_PROTO_MAX+1]; 1052 struct nlattr *tb[CTA_PROTO_MAX+1];
1050 int ret = 0; 1053 int ret = 0;
1051 1054
1052 ret = nla_parse_nested(tb, CTA_PROTO_MAX, attr, proto_nla_policy, 1055 ret = nla_parse_nested_deprecated(tb, CTA_PROTO_MAX, attr,
1053 NULL); 1056 proto_nla_policy, NULL);
1054 if (ret < 0) 1057 if (ret < 0)
1055 return ret; 1058 return ret;
1056 1059
@@ -1062,8 +1065,9 @@ static int ctnetlink_parse_tuple_proto(struct nlattr *attr,
1062 l4proto = nf_ct_l4proto_find(tuple->dst.protonum); 1065 l4proto = nf_ct_l4proto_find(tuple->dst.protonum);
1063 1066
1064 if (likely(l4proto->nlattr_to_tuple)) { 1067 if (likely(l4proto->nlattr_to_tuple)) {
1065 ret = nla_validate_nested(attr, CTA_PROTO_MAX, 1068 ret = nla_validate_nested_deprecated(attr, CTA_PROTO_MAX,
1066 l4proto->nla_policy, NULL); 1069 l4proto->nla_policy,
1070 NULL);
1067 if (ret == 0) 1071 if (ret == 0)
1068 ret = l4proto->nlattr_to_tuple(tb, tuple); 1072 ret = l4proto->nlattr_to_tuple(tb, tuple);
1069 } 1073 }
@@ -1126,8 +1130,8 @@ ctnetlink_parse_tuple(const struct nlattr * const cda[],
1126 1130
1127 memset(tuple, 0, sizeof(*tuple)); 1131 memset(tuple, 0, sizeof(*tuple));
1128 1132
1129 err = nla_parse_nested(tb, CTA_TUPLE_MAX, cda[type], tuple_nla_policy, 1133 err = nla_parse_nested_deprecated(tb, CTA_TUPLE_MAX, cda[type],
1130 NULL); 1134 tuple_nla_policy, NULL);
1131 if (err < 0) 1135 if (err < 0)
1132 return err; 1136 return err;
1133 1137
@@ -1177,7 +1181,8 @@ static int ctnetlink_parse_help(const struct nlattr *attr, char **helper_name,
1177 int err; 1181 int err;
1178 struct nlattr *tb[CTA_HELP_MAX+1]; 1182 struct nlattr *tb[CTA_HELP_MAX+1];
1179 1183
1180 err = nla_parse_nested(tb, CTA_HELP_MAX, attr, help_nla_policy, NULL); 1184 err = nla_parse_nested_deprecated(tb, CTA_HELP_MAX, attr,
1185 help_nla_policy, NULL);
1181 if (err < 0) 1186 if (err < 0)
1182 return err; 1187 return err;
1183 1188
@@ -1251,7 +1256,7 @@ static int ctnetlink_del_conntrack(struct net *net, struct sock *ctnl,
1251 struct nf_conntrack_tuple tuple; 1256 struct nf_conntrack_tuple tuple;
1252 struct nf_conn *ct; 1257 struct nf_conn *ct;
1253 struct nfgenmsg *nfmsg = nlmsg_data(nlh); 1258 struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1254 u_int8_t u3 = nfmsg->nfgen_family; 1259 u_int8_t u3 = nfmsg->version ? nfmsg->nfgen_family : AF_UNSPEC;
1255 struct nf_conntrack_zone zone; 1260 struct nf_conntrack_zone zone;
1256 int err; 1261 int err;
1257 1262
@@ -1286,8 +1291,9 @@ static int ctnetlink_del_conntrack(struct net *net, struct sock *ctnl,
1286 } 1291 }
1287 1292
1288 if (cda[CTA_ID]) { 1293 if (cda[CTA_ID]) {
1289 u_int32_t id = ntohl(nla_get_be32(cda[CTA_ID])); 1294 __be32 id = nla_get_be32(cda[CTA_ID]);
1290 if (id != (u32)(unsigned long)ct) { 1295
1296 if (id != (__force __be32)nf_ct_get_id(ct)) {
1291 nf_ct_put(ct); 1297 nf_ct_put(ct);
1292 return -ENOENT; 1298 return -ENOENT;
1293 } 1299 }
@@ -1494,7 +1500,7 @@ static int ctnetlink_get_ct_unconfirmed(struct net *net, struct sock *ctnl,
1494 return -EOPNOTSUPP; 1500 return -EOPNOTSUPP;
1495} 1501}
1496 1502
1497#ifdef CONFIG_NF_NAT_NEEDED 1503#if IS_ENABLED(CONFIG_NF_NAT)
1498static int 1504static int
1499ctnetlink_parse_nat_setup(struct nf_conn *ct, 1505ctnetlink_parse_nat_setup(struct nf_conn *ct,
1500 enum nf_nat_manip_type manip, 1506 enum nf_nat_manip_type manip,
@@ -1586,7 +1592,7 @@ ctnetlink_change_status(struct nf_conn *ct, const struct nlattr * const cda[])
1586static int 1592static int
1587ctnetlink_setup_nat(struct nf_conn *ct, const struct nlattr * const cda[]) 1593ctnetlink_setup_nat(struct nf_conn *ct, const struct nlattr * const cda[])
1588{ 1594{
1589#ifdef CONFIG_NF_NAT_NEEDED 1595#if IS_ENABLED(CONFIG_NF_NAT)
1590 int ret; 1596 int ret;
1591 1597
1592 if (!cda[CTA_NAT_DST] && !cda[CTA_NAT_SRC]) 1598 if (!cda[CTA_NAT_DST] && !cda[CTA_NAT_SRC])
@@ -1717,8 +1723,8 @@ static int ctnetlink_change_protoinfo(struct nf_conn *ct,
1717 struct nlattr *tb[CTA_PROTOINFO_MAX+1]; 1723 struct nlattr *tb[CTA_PROTOINFO_MAX+1];
1718 int err = 0; 1724 int err = 0;
1719 1725
1720 err = nla_parse_nested(tb, CTA_PROTOINFO_MAX, attr, protoinfo_policy, 1726 err = nla_parse_nested_deprecated(tb, CTA_PROTOINFO_MAX, attr,
1721 NULL); 1727 protoinfo_policy, NULL);
1722 if (err < 0) 1728 if (err < 0)
1723 return err; 1729 return err;
1724 1730
@@ -1741,7 +1747,8 @@ static int change_seq_adj(struct nf_ct_seqadj *seq,
1741 int err; 1747 int err;
1742 struct nlattr *cda[CTA_SEQADJ_MAX+1]; 1748 struct nlattr *cda[CTA_SEQADJ_MAX+1];
1743 1749
1744 err = nla_parse_nested(cda, CTA_SEQADJ_MAX, attr, seqadj_policy, NULL); 1750 err = nla_parse_nested_deprecated(cda, CTA_SEQADJ_MAX, attr,
1751 seqadj_policy, NULL);
1745 if (err < 0) 1752 if (err < 0)
1746 return err; 1753 return err;
1747 1754
@@ -1818,8 +1825,9 @@ static int ctnetlink_change_synproxy(struct nf_conn *ct,
1818 if (!synproxy) 1825 if (!synproxy)
1819 return 0; 1826 return 0;
1820 1827
1821 err = nla_parse_nested(tb, CTA_SYNPROXY_MAX, cda[CTA_SYNPROXY], 1828 err = nla_parse_nested_deprecated(tb, CTA_SYNPROXY_MAX,
1822 synproxy_policy, NULL); 1829 cda[CTA_SYNPROXY], synproxy_policy,
1830 NULL);
1823 if (err < 0) 1831 if (err < 0)
1824 return err; 1832 return err;
1825 1833
@@ -2369,7 +2377,7 @@ ctnetlink_glue_build_size(const struct nf_conn *ct)
2369 + nla_total_size(0) /* CTA_HELP */ 2377 + nla_total_size(0) /* CTA_HELP */
2370 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */ 2378 + nla_total_size(NF_CT_HELPER_NAME_LEN) /* CTA_HELP_NAME */
2371 + ctnetlink_secctx_size(ct) 2379 + ctnetlink_secctx_size(ct)
2372#ifdef CONFIG_NF_NAT_NEEDED 2380#if IS_ENABLED(CONFIG_NF_NAT)
2373 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */ 2381 + 2 * nla_total_size(0) /* CTA_NAT_SEQ_ADJ_ORIG|REPL */
2374 + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */ 2382 + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */
2375#endif 2383#endif
@@ -2396,7 +2404,7 @@ static int __ctnetlink_glue_build(struct sk_buff *skb, struct nf_conn *ct)
2396 2404
2397 zone = nf_ct_zone(ct); 2405 zone = nf_ct_zone(ct);
2398 2406
2399 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG | NLA_F_NESTED); 2407 nest_parms = nla_nest_start(skb, CTA_TUPLE_ORIG);
2400 if (!nest_parms) 2408 if (!nest_parms)
2401 goto nla_put_failure; 2409 goto nla_put_failure;
2402 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0) 2410 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_ORIGINAL)) < 0)
@@ -2406,7 +2414,7 @@ static int __ctnetlink_glue_build(struct sk_buff *skb, struct nf_conn *ct)
2406 goto nla_put_failure; 2414 goto nla_put_failure;
2407 nla_nest_end(skb, nest_parms); 2415 nla_nest_end(skb, nest_parms);
2408 2416
2409 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY | NLA_F_NESTED); 2417 nest_parms = nla_nest_start(skb, CTA_TUPLE_REPLY);
2410 if (!nest_parms) 2418 if (!nest_parms)
2411 goto nla_put_failure; 2419 goto nla_put_failure;
2412 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0) 2420 if (ctnetlink_dump_tuples(skb, nf_ct_tuple(ct, IP_CT_DIR_REPLY)) < 0)
@@ -2468,7 +2476,7 @@ ctnetlink_glue_build(struct sk_buff *skb, struct nf_conn *ct,
2468{ 2476{
2469 struct nlattr *nest_parms; 2477 struct nlattr *nest_parms;
2470 2478
2471 nest_parms = nla_nest_start(skb, ct_attr | NLA_F_NESTED); 2479 nest_parms = nla_nest_start(skb, ct_attr);
2472 if (!nest_parms) 2480 if (!nest_parms)
2473 goto nla_put_failure; 2481 goto nla_put_failure;
2474 2482
@@ -2549,7 +2557,8 @@ ctnetlink_glue_parse(const struct nlattr *attr, struct nf_conn *ct)
2549 struct nlattr *cda[CTA_MAX+1]; 2557 struct nlattr *cda[CTA_MAX+1];
2550 int ret; 2558 int ret;
2551 2559
2552 ret = nla_parse_nested(cda, CTA_MAX, attr, ct_nla_policy, NULL); 2560 ret = nla_parse_nested_deprecated(cda, CTA_MAX, attr, ct_nla_policy,
2561 NULL);
2553 if (ret < 0) 2562 if (ret < 0)
2554 return ret; 2563 return ret;
2555 2564
@@ -2582,8 +2591,8 @@ ctnetlink_glue_attach_expect(const struct nlattr *attr, struct nf_conn *ct,
2582 struct nf_conntrack_expect *exp; 2591 struct nf_conntrack_expect *exp;
2583 int err; 2592 int err;
2584 2593
2585 err = nla_parse_nested(cda, CTA_EXPECT_MAX, attr, exp_nla_policy, 2594 err = nla_parse_nested_deprecated(cda, CTA_EXPECT_MAX, attr,
2586 NULL); 2595 exp_nla_policy, NULL);
2587 if (err < 0) 2596 if (err < 0)
2588 return err; 2597 return err;
2589 2598
@@ -2640,7 +2649,7 @@ static int ctnetlink_exp_dump_tuple(struct sk_buff *skb,
2640{ 2649{
2641 struct nlattr *nest_parms; 2650 struct nlattr *nest_parms;
2642 2651
2643 nest_parms = nla_nest_start(skb, type | NLA_F_NESTED); 2652 nest_parms = nla_nest_start(skb, type);
2644 if (!nest_parms) 2653 if (!nest_parms)
2645 goto nla_put_failure; 2654 goto nla_put_failure;
2646 if (ctnetlink_dump_tuples(skb, tuple) < 0) 2655 if (ctnetlink_dump_tuples(skb, tuple) < 0)
@@ -2667,7 +2676,7 @@ static int ctnetlink_exp_dump_mask(struct sk_buff *skb,
2667 m.src.u.all = mask->src.u.all; 2676 m.src.u.all = mask->src.u.all;
2668 m.dst.protonum = tuple->dst.protonum; 2677 m.dst.protonum = tuple->dst.protonum;
2669 2678
2670 nest_parms = nla_nest_start(skb, CTA_EXPECT_MASK | NLA_F_NESTED); 2679 nest_parms = nla_nest_start(skb, CTA_EXPECT_MASK);
2671 if (!nest_parms) 2680 if (!nest_parms)
2672 goto nla_put_failure; 2681 goto nla_put_failure;
2673 2682
@@ -2692,6 +2701,25 @@ nla_put_failure:
2692 2701
2693static const union nf_inet_addr any_addr; 2702static const union nf_inet_addr any_addr;
2694 2703
2704static __be32 nf_expect_get_id(const struct nf_conntrack_expect *exp)
2705{
2706 static __read_mostly siphash_key_t exp_id_seed;
2707 unsigned long a, b, c, d;
2708
2709 net_get_random_once(&exp_id_seed, sizeof(exp_id_seed));
2710
2711 a = (unsigned long)exp;
2712 b = (unsigned long)exp->helper;
2713 c = (unsigned long)exp->master;
2714 d = (unsigned long)siphash(&exp->tuple, sizeof(exp->tuple), &exp_id_seed);
2715
2716#ifdef CONFIG_64BIT
2717 return (__force __be32)siphash_4u64((u64)a, (u64)b, (u64)c, (u64)d, &exp_id_seed);
2718#else
2719 return (__force __be32)siphash_4u32((u32)a, (u32)b, (u32)c, (u32)d, &exp_id_seed);
2720#endif
2721}
2722
2695static int 2723static int
2696ctnetlink_exp_dump_expect(struct sk_buff *skb, 2724ctnetlink_exp_dump_expect(struct sk_buff *skb,
2697 const struct nf_conntrack_expect *exp) 2725 const struct nf_conntrack_expect *exp)
@@ -2699,7 +2727,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
2699 struct nf_conn *master = exp->master; 2727 struct nf_conn *master = exp->master;
2700 long timeout = ((long)exp->timeout.expires - (long)jiffies) / HZ; 2728 long timeout = ((long)exp->timeout.expires - (long)jiffies) / HZ;
2701 struct nf_conn_help *help; 2729 struct nf_conn_help *help;
2702#ifdef CONFIG_NF_NAT_NEEDED 2730#if IS_ENABLED(CONFIG_NF_NAT)
2703 struct nlattr *nest_parms; 2731 struct nlattr *nest_parms;
2704 struct nf_conntrack_tuple nat_tuple = {}; 2732 struct nf_conntrack_tuple nat_tuple = {};
2705#endif 2733#endif
@@ -2717,10 +2745,10 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
2717 CTA_EXPECT_MASTER) < 0) 2745 CTA_EXPECT_MASTER) < 0)
2718 goto nla_put_failure; 2746 goto nla_put_failure;
2719 2747
2720#ifdef CONFIG_NF_NAT_NEEDED 2748#if IS_ENABLED(CONFIG_NF_NAT)
2721 if (!nf_inet_addr_cmp(&exp->saved_addr, &any_addr) || 2749 if (!nf_inet_addr_cmp(&exp->saved_addr, &any_addr) ||
2722 exp->saved_proto.all) { 2750 exp->saved_proto.all) {
2723 nest_parms = nla_nest_start(skb, CTA_EXPECT_NAT | NLA_F_NESTED); 2751 nest_parms = nla_nest_start(skb, CTA_EXPECT_NAT);
2724 if (!nest_parms) 2752 if (!nest_parms)
2725 goto nla_put_failure; 2753 goto nla_put_failure;
2726 2754
@@ -2739,7 +2767,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
2739 } 2767 }
2740#endif 2768#endif
2741 if (nla_put_be32(skb, CTA_EXPECT_TIMEOUT, htonl(timeout)) || 2769 if (nla_put_be32(skb, CTA_EXPECT_TIMEOUT, htonl(timeout)) ||
2742 nla_put_be32(skb, CTA_EXPECT_ID, htonl((unsigned long)exp)) || 2770 nla_put_be32(skb, CTA_EXPECT_ID, nf_expect_get_id(exp)) ||
2743 nla_put_be32(skb, CTA_EXPECT_FLAGS, htonl(exp->flags)) || 2771 nla_put_be32(skb, CTA_EXPECT_FLAGS, htonl(exp->flags)) ||
2744 nla_put_be32(skb, CTA_EXPECT_CLASS, htonl(exp->class))) 2772 nla_put_be32(skb, CTA_EXPECT_CLASS, htonl(exp->class)))
2745 goto nla_put_failure; 2773 goto nla_put_failure;
@@ -3044,7 +3072,8 @@ static int ctnetlink_get_expect(struct net *net, struct sock *ctnl,
3044 3072
3045 if (cda[CTA_EXPECT_ID]) { 3073 if (cda[CTA_EXPECT_ID]) {
3046 __be32 id = nla_get_be32(cda[CTA_EXPECT_ID]); 3074 __be32 id = nla_get_be32(cda[CTA_EXPECT_ID]);
3047 if (ntohl(id) != (u32)(unsigned long)exp) { 3075
3076 if (id != nf_expect_get_id(exp)) {
3048 nf_ct_expect_put(exp); 3077 nf_ct_expect_put(exp);
3049 return -ENOENT; 3078 return -ENOENT;
3050 } 3079 }
@@ -3180,13 +3209,13 @@ ctnetlink_parse_expect_nat(const struct nlattr *attr,
3180 struct nf_conntrack_expect *exp, 3209 struct nf_conntrack_expect *exp,
3181 u_int8_t u3) 3210 u_int8_t u3)
3182{ 3211{
3183#ifdef CONFIG_NF_NAT_NEEDED 3212#if IS_ENABLED(CONFIG_NF_NAT)
3184 struct nlattr *tb[CTA_EXPECT_NAT_MAX+1]; 3213 struct nlattr *tb[CTA_EXPECT_NAT_MAX+1];
3185 struct nf_conntrack_tuple nat_tuple = {}; 3214 struct nf_conntrack_tuple nat_tuple = {};
3186 int err; 3215 int err;
3187 3216
3188 err = nla_parse_nested(tb, CTA_EXPECT_NAT_MAX, attr, 3217 err = nla_parse_nested_deprecated(tb, CTA_EXPECT_NAT_MAX, attr,
3189 exp_nat_nla_policy, NULL); 3218 exp_nat_nla_policy, NULL);
3190 if (err < 0) 3219 if (err < 0)
3191 return err; 3220 return err;
3192 3221
diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
index b9403a266a2e..37bb530d848f 100644
--- a/net/netfilter/nf_conntrack_proto.c
+++ b/net/netfilter/nf_conntrack_proto.c
@@ -55,7 +55,7 @@ void nf_l4proto_log_invalid(const struct sk_buff *skb,
55 struct va_format vaf; 55 struct va_format vaf;
56 va_list args; 56 va_list args;
57 57
58 if (net->ct.sysctl_log_invalid != protonum || 58 if (net->ct.sysctl_log_invalid != protonum &&
59 net->ct.sysctl_log_invalid != IPPROTO_RAW) 59 net->ct.sysctl_log_invalid != IPPROTO_RAW)
60 return; 60 return;
61 61
diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
index 6fca80587505..7491aa4c3566 100644
--- a/net/netfilter/nf_conntrack_proto_dccp.c
+++ b/net/netfilter/nf_conntrack_proto_dccp.c
@@ -598,7 +598,7 @@ static int dccp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
598 struct nlattr *nest_parms; 598 struct nlattr *nest_parms;
599 599
600 spin_lock_bh(&ct->lock); 600 spin_lock_bh(&ct->lock);
601 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_DCCP | NLA_F_NESTED); 601 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_DCCP);
602 if (!nest_parms) 602 if (!nest_parms)
603 goto nla_put_failure; 603 goto nla_put_failure;
604 if (nla_put_u8(skb, CTA_PROTOINFO_DCCP_STATE, ct->proto.dccp.state) || 604 if (nla_put_u8(skb, CTA_PROTOINFO_DCCP_STATE, ct->proto.dccp.state) ||
@@ -639,8 +639,8 @@ static int nlattr_to_dccp(struct nlattr *cda[], struct nf_conn *ct)
639 if (!attr) 639 if (!attr)
640 return 0; 640 return 0;
641 641
642 err = nla_parse_nested(tb, CTA_PROTOINFO_DCCP_MAX, attr, 642 err = nla_parse_nested_deprecated(tb, CTA_PROTOINFO_DCCP_MAX, attr,
643 dccp_nla_policy, NULL); 643 dccp_nla_policy, NULL);
644 if (err < 0) 644 if (err < 0)
645 return err; 645 return err;
646 646
diff --git a/net/netfilter/nf_conntrack_proto_icmp.c b/net/netfilter/nf_conntrack_proto_icmp.c
index 7df477996b16..9becac953587 100644
--- a/net/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/netfilter/nf_conntrack_proto_icmp.c
@@ -103,49 +103,94 @@ int nf_conntrack_icmp_packet(struct nf_conn *ct,
103 return NF_ACCEPT; 103 return NF_ACCEPT;
104} 104}
105 105
106/* Returns conntrack if it dealt with ICMP, and filled in skb fields */ 106/* Check inner header is related to any of the existing connections */
107static int 107int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,
108icmp_error_message(struct nf_conn *tmpl, struct sk_buff *skb, 108 unsigned int dataoff,
109 const struct nf_hook_state *state) 109 const struct nf_hook_state *state,
110 u8 l4proto, union nf_inet_addr *outer_daddr)
110{ 111{
111 struct nf_conntrack_tuple innertuple, origtuple; 112 struct nf_conntrack_tuple innertuple, origtuple;
112 const struct nf_conntrack_tuple_hash *h; 113 const struct nf_conntrack_tuple_hash *h;
113 const struct nf_conntrack_zone *zone; 114 const struct nf_conntrack_zone *zone;
114 enum ip_conntrack_info ctinfo; 115 enum ip_conntrack_info ctinfo;
115 struct nf_conntrack_zone tmp; 116 struct nf_conntrack_zone tmp;
117 union nf_inet_addr *ct_daddr;
118 enum ip_conntrack_dir dir;
119 struct nf_conn *ct;
116 120
117 WARN_ON(skb_nfct(skb)); 121 WARN_ON(skb_nfct(skb));
118 zone = nf_ct_zone_tmpl(tmpl, skb, &tmp); 122 zone = nf_ct_zone_tmpl(tmpl, skb, &tmp);
119 123
120 /* Are they talking about one of our connections? */ 124 /* Are they talking about one of our connections? */
121 if (!nf_ct_get_tuplepr(skb, 125 if (!nf_ct_get_tuplepr(skb, dataoff,
122 skb_network_offset(skb) + ip_hdrlen(skb) 126 state->pf, state->net, &origtuple))
123 + sizeof(struct icmphdr),
124 PF_INET, state->net, &origtuple)) {
125 pr_debug("icmp_error_message: failed to get tuple\n");
126 return -NF_ACCEPT; 127 return -NF_ACCEPT;
127 }
128 128
129 /* Ordinarily, we'd expect the inverted tupleproto, but it's 129 /* Ordinarily, we'd expect the inverted tupleproto, but it's
130 been preserved inside the ICMP. */ 130 been preserved inside the ICMP. */
131 if (!nf_ct_invert_tuple(&innertuple, &origtuple)) { 131 if (!nf_ct_invert_tuple(&innertuple, &origtuple))
132 pr_debug("icmp_error_message: no match\n");
133 return -NF_ACCEPT; 132 return -NF_ACCEPT;
134 }
135
136 ctinfo = IP_CT_RELATED;
137 133
138 h = nf_conntrack_find_get(state->net, zone, &innertuple); 134 h = nf_conntrack_find_get(state->net, zone, &innertuple);
139 if (!h) { 135 if (!h)
140 pr_debug("icmp_error_message: no match\n"); 136 return -NF_ACCEPT;
137
138 /* Consider: A -> T (=This machine) -> B
139 * Conntrack entry will look like this:
140 * Original: A->B
141 * Reply: B->T (SNAT case) OR A
142 *
143 * When this function runs, we got packet that looks like this:
144 * iphdr|icmphdr|inner_iphdr|l4header (tcp, udp, ..).
145 *
146 * Above nf_conntrack_find_get() makes lookup based on inner_hdr,
147 * so we should expect that destination of the found connection
148 * matches outer header destination address.
149 *
150 * In above example, we can consider these two cases:
151 * 1. Error coming in reply direction from B or M (middle box) to
152 * T (SNAT case) or A.
153 * Inner saddr will be B, dst will be T or A.
154 * The found conntrack will be reply tuple (B->T/A).
155 * 2. Error coming in original direction from A or M to B.
156 * Inner saddr will be A, inner daddr will be B.
157 * The found conntrack will be original tuple (A->B).
158 *
159 * In both cases, conntrack[dir].dst == inner.dst.
160 *
161 * A bogus packet could look like this:
162 * Inner: B->T
163 * Outer: B->X (other machine reachable by T).
164 *
165 * In this case, lookup yields connection A->B and will
166 * set packet from B->X as *RELATED*, even though no connection
167 * from X was ever seen.
168 */
169 ct = nf_ct_tuplehash_to_ctrack(h);
170 dir = NF_CT_DIRECTION(h);
171 ct_daddr = &ct->tuplehash[dir].tuple.dst.u3;
172 if (!nf_inet_addr_cmp(outer_daddr, ct_daddr)) {
173 if (state->pf == AF_INET) {
174 nf_l4proto_log_invalid(skb, state->net, state->pf,
175 l4proto,
176 "outer daddr %pI4 != inner %pI4",
177 &outer_daddr->ip, &ct_daddr->ip);
178 } else if (state->pf == AF_INET6) {
179 nf_l4proto_log_invalid(skb, state->net, state->pf,
180 l4proto,
181 "outer daddr %pI6 != inner %pI6",
182 &outer_daddr->ip6, &ct_daddr->ip6);
183 }
184 nf_ct_put(ct);
141 return -NF_ACCEPT; 185 return -NF_ACCEPT;
142 } 186 }
143 187
144 if (NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY) 188 ctinfo = IP_CT_RELATED;
189 if (dir == IP_CT_DIR_REPLY)
145 ctinfo += IP_CT_IS_REPLY; 190 ctinfo += IP_CT_IS_REPLY;
146 191
147 /* Update skb to refer to this connection */ 192 /* Update skb to refer to this connection */
148 nf_ct_set(skb, nf_ct_tuplehash_to_ctrack(h), ctinfo); 193 nf_ct_set(skb, ct, ctinfo);
149 return NF_ACCEPT; 194 return NF_ACCEPT;
150} 195}
151 196
@@ -162,11 +207,12 @@ int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
162 struct sk_buff *skb, unsigned int dataoff, 207 struct sk_buff *skb, unsigned int dataoff,
163 const struct nf_hook_state *state) 208 const struct nf_hook_state *state)
164{ 209{
210 union nf_inet_addr outer_daddr;
165 const struct icmphdr *icmph; 211 const struct icmphdr *icmph;
166 struct icmphdr _ih; 212 struct icmphdr _ih;
167 213
168 /* Not enough header? */ 214 /* Not enough header? */
169 icmph = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_ih), &_ih); 215 icmph = skb_header_pointer(skb, dataoff, sizeof(_ih), &_ih);
170 if (icmph == NULL) { 216 if (icmph == NULL) {
171 icmp_error_log(skb, state, "short packet"); 217 icmp_error_log(skb, state, "short packet");
172 return -NF_ACCEPT; 218 return -NF_ACCEPT;
@@ -199,7 +245,12 @@ int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
199 icmph->type != ICMP_REDIRECT) 245 icmph->type != ICMP_REDIRECT)
200 return NF_ACCEPT; 246 return NF_ACCEPT;
201 247
202 return icmp_error_message(tmpl, skb, state); 248 memset(&outer_daddr, 0, sizeof(outer_daddr));
249 outer_daddr.ip = ip_hdr(skb)->daddr;
250
251 dataoff += sizeof(*icmph);
252 return nf_conntrack_inet_error(tmpl, skb, dataoff, state,
253 IPPROTO_ICMP, &outer_daddr);
203} 254}
204 255
205#if IS_ENABLED(CONFIG_NF_CT_NETLINK) 256#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
diff --git a/net/netfilter/nf_conntrack_proto_icmpv6.c b/net/netfilter/nf_conntrack_proto_icmpv6.c
index bec4a3211658..c63ee3612855 100644
--- a/net/netfilter/nf_conntrack_proto_icmpv6.c
+++ b/net/netfilter/nf_conntrack_proto_icmpv6.c
@@ -123,51 +123,6 @@ int nf_conntrack_icmpv6_packet(struct nf_conn *ct,
123 return NF_ACCEPT; 123 return NF_ACCEPT;
124} 124}
125 125
126static int
127icmpv6_error_message(struct net *net, struct nf_conn *tmpl,
128 struct sk_buff *skb,
129 unsigned int icmp6off)
130{
131 struct nf_conntrack_tuple intuple, origtuple;
132 const struct nf_conntrack_tuple_hash *h;
133 enum ip_conntrack_info ctinfo;
134 struct nf_conntrack_zone tmp;
135
136 WARN_ON(skb_nfct(skb));
137
138 /* Are they talking about one of our connections? */
139 if (!nf_ct_get_tuplepr(skb,
140 skb_network_offset(skb)
141 + sizeof(struct ipv6hdr)
142 + sizeof(struct icmp6hdr),
143 PF_INET6, net, &origtuple)) {
144 pr_debug("icmpv6_error: Can't get tuple\n");
145 return -NF_ACCEPT;
146 }
147
148 /* Ordinarily, we'd expect the inverted tupleproto, but it's
149 been preserved inside the ICMP. */
150 if (!nf_ct_invert_tuple(&intuple, &origtuple)) {
151 pr_debug("icmpv6_error: Can't invert tuple\n");
152 return -NF_ACCEPT;
153 }
154
155 ctinfo = IP_CT_RELATED;
156
157 h = nf_conntrack_find_get(net, nf_ct_zone_tmpl(tmpl, skb, &tmp),
158 &intuple);
159 if (!h) {
160 pr_debug("icmpv6_error: no match\n");
161 return -NF_ACCEPT;
162 } else {
163 if (NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY)
164 ctinfo += IP_CT_IS_REPLY;
165 }
166
167 /* Update skb to refer to this connection */
168 nf_ct_set(skb, nf_ct_tuplehash_to_ctrack(h), ctinfo);
169 return NF_ACCEPT;
170}
171 126
172static void icmpv6_error_log(const struct sk_buff *skb, 127static void icmpv6_error_log(const struct sk_buff *skb,
173 const struct nf_hook_state *state, 128 const struct nf_hook_state *state,
@@ -182,6 +137,7 @@ int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
182 unsigned int dataoff, 137 unsigned int dataoff,
183 const struct nf_hook_state *state) 138 const struct nf_hook_state *state)
184{ 139{
140 union nf_inet_addr outer_daddr;
185 const struct icmp6hdr *icmp6h; 141 const struct icmp6hdr *icmp6h;
186 struct icmp6hdr _ih; 142 struct icmp6hdr _ih;
187 int type; 143 int type;
@@ -210,7 +166,11 @@ int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
210 if (icmp6h->icmp6_type >= 128) 166 if (icmp6h->icmp6_type >= 128)
211 return NF_ACCEPT; 167 return NF_ACCEPT;
212 168
213 return icmpv6_error_message(state->net, tmpl, skb, dataoff); 169 memcpy(&outer_daddr.ip6, &ipv6_hdr(skb)->daddr,
170 sizeof(outer_daddr.ip6));
171 dataoff += sizeof(*icmp6h);
172 return nf_conntrack_inet_error(tmpl, skb, dataoff, state,
173 IPPROTO_ICMPV6, &outer_daddr);
214} 174}
215 175
216#if IS_ENABLED(CONFIG_NF_CT_NETLINK) 176#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
diff --git a/net/netfilter/nf_conntrack_proto_sctp.c b/net/netfilter/nf_conntrack_proto_sctp.c
index a7818101ad80..5b8dde266412 100644
--- a/net/netfilter/nf_conntrack_proto_sctp.c
+++ b/net/netfilter/nf_conntrack_proto_sctp.c
@@ -520,7 +520,7 @@ static int sctp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
520 struct nlattr *nest_parms; 520 struct nlattr *nest_parms;
521 521
522 spin_lock_bh(&ct->lock); 522 spin_lock_bh(&ct->lock);
523 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_SCTP | NLA_F_NESTED); 523 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_SCTP);
524 if (!nest_parms) 524 if (!nest_parms)
525 goto nla_put_failure; 525 goto nla_put_failure;
526 526
@@ -563,8 +563,8 @@ static int nlattr_to_sctp(struct nlattr *cda[], struct nf_conn *ct)
563 if (!attr) 563 if (!attr)
564 return 0; 564 return 0;
565 565
566 err = nla_parse_nested(tb, CTA_PROTOINFO_SCTP_MAX, attr, 566 err = nla_parse_nested_deprecated(tb, CTA_PROTOINFO_SCTP_MAX, attr,
567 sctp_nla_policy, NULL); 567 sctp_nla_policy, NULL);
568 if (err < 0) 568 if (err < 0)
569 return err; 569 return err;
570 570
diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c
index a06875a466a4..7ba01d8ee165 100644
--- a/net/netfilter/nf_conntrack_proto_tcp.c
+++ b/net/netfilter/nf_conntrack_proto_tcp.c
@@ -1192,7 +1192,7 @@ static int tcp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
1192 struct nf_ct_tcp_flags tmp = {}; 1192 struct nf_ct_tcp_flags tmp = {};
1193 1193
1194 spin_lock_bh(&ct->lock); 1194 spin_lock_bh(&ct->lock);
1195 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_TCP | NLA_F_NESTED); 1195 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_TCP);
1196 if (!nest_parms) 1196 if (!nest_parms)
1197 goto nla_put_failure; 1197 goto nla_put_failure;
1198 1198
@@ -1248,8 +1248,8 @@ static int nlattr_to_tcp(struct nlattr *cda[], struct nf_conn *ct)
1248 if (!pattr) 1248 if (!pattr)
1249 return 0; 1249 return 0;
1250 1250
1251 err = nla_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, pattr, 1251 err = nla_parse_nested_deprecated(tb, CTA_PROTOINFO_TCP_MAX, pattr,
1252 tcp_nla_policy, NULL); 1252 tcp_nla_policy, NULL);
1253 if (err < 0) 1253 if (err < 0)
1254 return err; 1254 return err;
1255 1255
diff --git a/net/netfilter/nf_conntrack_sane.c b/net/netfilter/nf_conntrack_sane.c
index 5072ff96ab33..83306648dd0f 100644
--- a/net/netfilter/nf_conntrack_sane.c
+++ b/net/netfilter/nf_conntrack_sane.c
@@ -30,10 +30,12 @@
30#include <net/netfilter/nf_conntrack_expect.h> 30#include <net/netfilter/nf_conntrack_expect.h>
31#include <linux/netfilter/nf_conntrack_sane.h> 31#include <linux/netfilter/nf_conntrack_sane.h>
32 32
33#define HELPER_NAME "sane"
34
33MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
34MODULE_AUTHOR("Michal Schmidt <mschmidt@redhat.com>"); 36MODULE_AUTHOR("Michal Schmidt <mschmidt@redhat.com>");
35MODULE_DESCRIPTION("SANE connection tracking helper"); 37MODULE_DESCRIPTION("SANE connection tracking helper");
36MODULE_ALIAS_NFCT_HELPER("sane"); 38MODULE_ALIAS_NFCT_HELPER(HELPER_NAME);
37 39
38static char *sane_buffer; 40static char *sane_buffer;
39 41
@@ -195,12 +197,12 @@ static int __init nf_conntrack_sane_init(void)
195 /* FIXME should be configurable whether IPv4 and IPv6 connections 197 /* FIXME should be configurable whether IPv4 and IPv6 connections
196 are tracked or not - YK */ 198 are tracked or not - YK */
197 for (i = 0; i < ports_c; i++) { 199 for (i = 0; i < ports_c; i++) {
198 nf_ct_helper_init(&sane[2 * i], AF_INET, IPPROTO_TCP, "sane", 200 nf_ct_helper_init(&sane[2 * i], AF_INET, IPPROTO_TCP,
199 SANE_PORT, ports[i], ports[i], 201 HELPER_NAME, SANE_PORT, ports[i], ports[i],
200 &sane_exp_policy, 0, help, NULL, 202 &sane_exp_policy, 0, help, NULL,
201 THIS_MODULE); 203 THIS_MODULE);
202 nf_ct_helper_init(&sane[2 * i + 1], AF_INET6, IPPROTO_TCP, "sane", 204 nf_ct_helper_init(&sane[2 * i + 1], AF_INET6, IPPROTO_TCP,
203 SANE_PORT, ports[i], ports[i], 205 HELPER_NAME, SANE_PORT, ports[i], ports[i],
204 &sane_exp_policy, 0, help, NULL, 206 &sane_exp_policy, 0, help, NULL,
205 THIS_MODULE); 207 THIS_MODULE);
206 } 208 }
diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
index 39fcc1ed18f3..c30c883c370b 100644
--- a/net/netfilter/nf_conntrack_sip.c
+++ b/net/netfilter/nf_conntrack_sip.c
@@ -30,11 +30,13 @@
30#include <net/netfilter/nf_conntrack_zones.h> 30#include <net/netfilter/nf_conntrack_zones.h>
31#include <linux/netfilter/nf_conntrack_sip.h> 31#include <linux/netfilter/nf_conntrack_sip.h>
32 32
33#define HELPER_NAME "sip"
34
33MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
34MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>"); 36MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>");
35MODULE_DESCRIPTION("SIP connection tracking helper"); 37MODULE_DESCRIPTION("SIP connection tracking helper");
36MODULE_ALIAS("ip_conntrack_sip"); 38MODULE_ALIAS("ip_conntrack_sip");
37MODULE_ALIAS_NFCT_HELPER("sip"); 39MODULE_ALIAS_NFCT_HELPER(HELPER_NAME);
38 40
39#define MAX_PORTS 8 41#define MAX_PORTS 8
40static unsigned short ports[MAX_PORTS]; 42static unsigned short ports[MAX_PORTS];
@@ -928,7 +930,7 @@ static int set_expected_rtp_rtcp(struct sk_buff *skb, unsigned int protoff,
928 nfct_help(exp->master)->helper != nfct_help(ct)->helper || 930 nfct_help(exp->master)->helper != nfct_help(ct)->helper ||
929 exp->class != class) 931 exp->class != class)
930 break; 932 break;
931#ifdef CONFIG_NF_NAT_NEEDED 933#if IS_ENABLED(CONFIG_NF_NAT)
932 if (!direct_rtp && 934 if (!direct_rtp &&
933 (!nf_inet_addr_cmp(&exp->saved_addr, &exp->tuple.dst.u3) || 935 (!nf_inet_addr_cmp(&exp->saved_addr, &exp->tuple.dst.u3) ||
934 exp->saved_proto.udp.port != exp->tuple.dst.u.udp.port) && 936 exp->saved_proto.udp.port != exp->tuple.dst.u.udp.port) &&
@@ -1669,21 +1671,21 @@ static int __init nf_conntrack_sip_init(void)
1669 ports[ports_c++] = SIP_PORT; 1671 ports[ports_c++] = SIP_PORT;
1670 1672
1671 for (i = 0; i < ports_c; i++) { 1673 for (i = 0; i < ports_c; i++) {
1672 nf_ct_helper_init(&sip[4 * i], AF_INET, IPPROTO_UDP, "sip", 1674 nf_ct_helper_init(&sip[4 * i], AF_INET, IPPROTO_UDP,
1673 SIP_PORT, ports[i], i, sip_exp_policy, 1675 HELPER_NAME, SIP_PORT, ports[i], i,
1674 SIP_EXPECT_MAX, sip_help_udp, 1676 sip_exp_policy, SIP_EXPECT_MAX, sip_help_udp,
1675 NULL, THIS_MODULE); 1677 NULL, THIS_MODULE);
1676 nf_ct_helper_init(&sip[4 * i + 1], AF_INET, IPPROTO_TCP, "sip", 1678 nf_ct_helper_init(&sip[4 * i + 1], AF_INET, IPPROTO_TCP,
1677 SIP_PORT, ports[i], i, sip_exp_policy, 1679 HELPER_NAME, SIP_PORT, ports[i], i,
1678 SIP_EXPECT_MAX, sip_help_tcp, 1680 sip_exp_policy, SIP_EXPECT_MAX, sip_help_tcp,
1679 NULL, THIS_MODULE); 1681 NULL, THIS_MODULE);
1680 nf_ct_helper_init(&sip[4 * i + 2], AF_INET6, IPPROTO_UDP, "sip", 1682 nf_ct_helper_init(&sip[4 * i + 2], AF_INET6, IPPROTO_UDP,
1681 SIP_PORT, ports[i], i, sip_exp_policy, 1683 HELPER_NAME, SIP_PORT, ports[i], i,
1682 SIP_EXPECT_MAX, sip_help_udp, 1684 sip_exp_policy, SIP_EXPECT_MAX, sip_help_udp,
1683 NULL, THIS_MODULE); 1685 NULL, THIS_MODULE);
1684 nf_ct_helper_init(&sip[4 * i + 3], AF_INET6, IPPROTO_TCP, "sip", 1686 nf_ct_helper_init(&sip[4 * i + 3], AF_INET6, IPPROTO_TCP,
1685 SIP_PORT, ports[i], i, sip_exp_policy, 1687 HELPER_NAME, SIP_PORT, ports[i], i,
1686 SIP_EXPECT_MAX, sip_help_tcp, 1688 sip_exp_policy, SIP_EXPECT_MAX, sip_help_tcp,
1687 NULL, THIS_MODULE); 1689 NULL, THIS_MODULE);
1688 } 1690 }
1689 1691
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index c2ae14c720b4..e0d392cb3075 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -511,6 +511,8 @@ static void nf_conntrack_standalone_fini_proc(struct net *net)
511/* Log invalid packets of a given protocol */ 511/* Log invalid packets of a given protocol */
512static int log_invalid_proto_min __read_mostly; 512static int log_invalid_proto_min __read_mostly;
513static int log_invalid_proto_max __read_mostly = 255; 513static int log_invalid_proto_max __read_mostly = 255;
514static int zero;
515static int one = 1;
514 516
515/* size the user *wants to set */ 517/* size the user *wants to set */
516static unsigned int nf_conntrack_htable_size_user __read_mostly; 518static unsigned int nf_conntrack_htable_size_user __read_mostly;
@@ -624,9 +626,11 @@ static struct ctl_table nf_ct_sysctl_table[] = {
624 [NF_SYSCTL_CT_CHECKSUM] = { 626 [NF_SYSCTL_CT_CHECKSUM] = {
625 .procname = "nf_conntrack_checksum", 627 .procname = "nf_conntrack_checksum",
626 .data = &init_net.ct.sysctl_checksum, 628 .data = &init_net.ct.sysctl_checksum,
627 .maxlen = sizeof(unsigned int), 629 .maxlen = sizeof(int),
628 .mode = 0644, 630 .mode = 0644,
629 .proc_handler = proc_dointvec, 631 .proc_handler = proc_dointvec_minmax,
632 .extra1 = &zero,
633 .extra2 = &one,
630 }, 634 },
631 [NF_SYSCTL_CT_LOG_INVALID] = { 635 [NF_SYSCTL_CT_LOG_INVALID] = {
632 .procname = "nf_conntrack_log_invalid", 636 .procname = "nf_conntrack_log_invalid",
@@ -647,33 +651,41 @@ static struct ctl_table nf_ct_sysctl_table[] = {
647 [NF_SYSCTL_CT_ACCT] = { 651 [NF_SYSCTL_CT_ACCT] = {
648 .procname = "nf_conntrack_acct", 652 .procname = "nf_conntrack_acct",
649 .data = &init_net.ct.sysctl_acct, 653 .data = &init_net.ct.sysctl_acct,
650 .maxlen = sizeof(unsigned int), 654 .maxlen = sizeof(int),
651 .mode = 0644, 655 .mode = 0644,
652 .proc_handler = proc_dointvec, 656 .proc_handler = proc_dointvec_minmax,
657 .extra1 = &zero,
658 .extra2 = &one,
653 }, 659 },
654 [NF_SYSCTL_CT_HELPER] = { 660 [NF_SYSCTL_CT_HELPER] = {
655 .procname = "nf_conntrack_helper", 661 .procname = "nf_conntrack_helper",
656 .data = &init_net.ct.sysctl_auto_assign_helper, 662 .data = &init_net.ct.sysctl_auto_assign_helper,
657 .maxlen = sizeof(unsigned int), 663 .maxlen = sizeof(int),
658 .mode = 0644, 664 .mode = 0644,
659 .proc_handler = proc_dointvec, 665 .proc_handler = proc_dointvec_minmax,
666 .extra1 = &zero,
667 .extra2 = &one,
660 }, 668 },
661#ifdef CONFIG_NF_CONNTRACK_EVENTS 669#ifdef CONFIG_NF_CONNTRACK_EVENTS
662 [NF_SYSCTL_CT_EVENTS] = { 670 [NF_SYSCTL_CT_EVENTS] = {
663 .procname = "nf_conntrack_events", 671 .procname = "nf_conntrack_events",
664 .data = &init_net.ct.sysctl_events, 672 .data = &init_net.ct.sysctl_events,
665 .maxlen = sizeof(unsigned int), 673 .maxlen = sizeof(int),
666 .mode = 0644, 674 .mode = 0644,
667 .proc_handler = proc_dointvec, 675 .proc_handler = proc_dointvec_minmax,
676 .extra1 = &zero,
677 .extra2 = &one,
668 }, 678 },
669#endif 679#endif
670#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP 680#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
671 [NF_SYSCTL_CT_TIMESTAMP] = { 681 [NF_SYSCTL_CT_TIMESTAMP] = {
672 .procname = "nf_conntrack_timestamp", 682 .procname = "nf_conntrack_timestamp",
673 .data = &init_net.ct.sysctl_tstamp, 683 .data = &init_net.ct.sysctl_tstamp,
674 .maxlen = sizeof(unsigned int), 684 .maxlen = sizeof(int),
675 .mode = 0644, 685 .mode = 0644,
676 .proc_handler = proc_dointvec, 686 .proc_handler = proc_dointvec_minmax,
687 .extra1 = &zero,
688 .extra2 = &one,
677 }, 689 },
678#endif 690#endif
679 [NF_SYSCTL_CT_PROTO_TIMEOUT_GENERIC] = { 691 [NF_SYSCTL_CT_PROTO_TIMEOUT_GENERIC] = {
@@ -744,15 +756,19 @@ static struct ctl_table nf_ct_sysctl_table[] = {
744 }, 756 },
745 [NF_SYSCTL_CT_PROTO_TCP_LOOSE] = { 757 [NF_SYSCTL_CT_PROTO_TCP_LOOSE] = {
746 .procname = "nf_conntrack_tcp_loose", 758 .procname = "nf_conntrack_tcp_loose",
747 .maxlen = sizeof(unsigned int), 759 .maxlen = sizeof(int),
748 .mode = 0644, 760 .mode = 0644,
749 .proc_handler = proc_dointvec, 761 .proc_handler = proc_dointvec_minmax,
762 .extra1 = &zero,
763 .extra2 = &one,
750 }, 764 },
751 [NF_SYSCTL_CT_PROTO_TCP_LIBERAL] = { 765 [NF_SYSCTL_CT_PROTO_TCP_LIBERAL] = {
752 .procname = "nf_conntrack_tcp_be_liberal", 766 .procname = "nf_conntrack_tcp_be_liberal",
753 .maxlen = sizeof(unsigned int), 767 .maxlen = sizeof(int),
754 .mode = 0644, 768 .mode = 0644,
755 .proc_handler = proc_dointvec, 769 .proc_handler = proc_dointvec_minmax,
770 .extra1 = &zero,
771 .extra2 = &one,
756 }, 772 },
757 [NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS] = { 773 [NF_SYSCTL_CT_PROTO_TCP_MAX_RETRANS] = {
758 .procname = "nf_conntrack_tcp_max_retrans", 774 .procname = "nf_conntrack_tcp_max_retrans",
@@ -887,7 +903,9 @@ static struct ctl_table nf_ct_sysctl_table[] = {
887 .procname = "nf_conntrack_dccp_loose", 903 .procname = "nf_conntrack_dccp_loose",
888 .maxlen = sizeof(int), 904 .maxlen = sizeof(int),
889 .mode = 0644, 905 .mode = 0644,
890 .proc_handler = proc_dointvec, 906 .proc_handler = proc_dointvec_minmax,
907 .extra1 = &zero,
908 .extra2 = &one,
891 }, 909 },
892#endif 910#endif
893#ifdef CONFIG_NF_CT_PROTO_GRE 911#ifdef CONFIG_NF_CT_PROTO_GRE
diff --git a/net/netfilter/nf_conntrack_tftp.c b/net/netfilter/nf_conntrack_tftp.c
index 548b673b3625..6977cb91ae9a 100644
--- a/net/netfilter/nf_conntrack_tftp.c
+++ b/net/netfilter/nf_conntrack_tftp.c
@@ -20,11 +20,13 @@
20#include <net/netfilter/nf_conntrack_helper.h> 20#include <net/netfilter/nf_conntrack_helper.h>
21#include <linux/netfilter/nf_conntrack_tftp.h> 21#include <linux/netfilter/nf_conntrack_tftp.h>
22 22
23#define HELPER_NAME "tftp"
24
23MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>"); 25MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
24MODULE_DESCRIPTION("TFTP connection tracking helper"); 26MODULE_DESCRIPTION("TFTP connection tracking helper");
25MODULE_LICENSE("GPL"); 27MODULE_LICENSE("GPL");
26MODULE_ALIAS("ip_conntrack_tftp"); 28MODULE_ALIAS("ip_conntrack_tftp");
27MODULE_ALIAS_NFCT_HELPER("tftp"); 29MODULE_ALIAS_NFCT_HELPER(HELPER_NAME);
28 30
29#define MAX_PORTS 8 31#define MAX_PORTS 8
30static unsigned short ports[MAX_PORTS]; 32static unsigned short ports[MAX_PORTS];
@@ -119,12 +121,14 @@ static int __init nf_conntrack_tftp_init(void)
119 ports[ports_c++] = TFTP_PORT; 121 ports[ports_c++] = TFTP_PORT;
120 122
121 for (i = 0; i < ports_c; i++) { 123 for (i = 0; i < ports_c; i++) {
122 nf_ct_helper_init(&tftp[2 * i], AF_INET, IPPROTO_UDP, "tftp", 124 nf_ct_helper_init(&tftp[2 * i], AF_INET, IPPROTO_UDP,
123 TFTP_PORT, ports[i], i, &tftp_exp_policy, 125 HELPER_NAME, TFTP_PORT, ports[i], i,
124 0, tftp_help, NULL, THIS_MODULE); 126 &tftp_exp_policy, 0, tftp_help, NULL,
125 nf_ct_helper_init(&tftp[2 * i + 1], AF_INET6, IPPROTO_UDP, "tftp", 127 THIS_MODULE);
126 TFTP_PORT, ports[i], i, &tftp_exp_policy, 128 nf_ct_helper_init(&tftp[2 * i + 1], AF_INET6, IPPROTO_UDP,
127 0, tftp_help, NULL, THIS_MODULE); 129 HELPER_NAME, TFTP_PORT, ports[i], i,
130 &tftp_exp_policy, 0, tftp_help, NULL,
131 THIS_MODULE);
128 } 132 }
129 133
130 ret = nf_conntrack_helpers_register(tftp, ports_c * 2); 134 ret = nf_conntrack_helpers_register(tftp, ports_c * 2);
diff --git a/net/netfilter/nf_conntrack_timeout.c b/net/netfilter/nf_conntrack_timeout.c
index 91fbd183da2d..edac8ea4436d 100644
--- a/net/netfilter/nf_conntrack_timeout.c
+++ b/net/netfilter/nf_conntrack_timeout.c
@@ -48,6 +48,95 @@ void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout)
48} 48}
49EXPORT_SYMBOL_GPL(nf_ct_untimeout); 49EXPORT_SYMBOL_GPL(nf_ct_untimeout);
50 50
51static void __nf_ct_timeout_put(struct nf_ct_timeout *timeout)
52{
53 typeof(nf_ct_timeout_put_hook) timeout_put;
54
55 timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
56 if (timeout_put)
57 timeout_put(timeout);
58}
59
60int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
61 u8 l3num, u8 l4num, const char *timeout_name)
62{
63 typeof(nf_ct_timeout_find_get_hook) timeout_find_get;
64 struct nf_ct_timeout *timeout;
65 struct nf_conn_timeout *timeout_ext;
66 const char *errmsg = NULL;
67 int ret = 0;
68
69 rcu_read_lock();
70 timeout_find_get = rcu_dereference(nf_ct_timeout_find_get_hook);
71 if (!timeout_find_get) {
72 ret = -ENOENT;
73 errmsg = "Timeout policy base is empty";
74 goto out;
75 }
76
77 timeout = timeout_find_get(net, timeout_name);
78 if (!timeout) {
79 ret = -ENOENT;
80 pr_info_ratelimited("No such timeout policy \"%s\"\n",
81 timeout_name);
82 goto out;
83 }
84
85 if (timeout->l3num != l3num) {
86 ret = -EINVAL;
87 pr_info_ratelimited("Timeout policy `%s' can only be used by "
88 "L%d protocol number %d\n",
89 timeout_name, 3, timeout->l3num);
90 goto err_put_timeout;
91 }
92 /* Make sure the timeout policy matches any existing protocol tracker,
93 * otherwise default to generic.
94 */
95 if (timeout->l4proto->l4proto != l4num) {
96 ret = -EINVAL;
97 pr_info_ratelimited("Timeout policy `%s' can only be used by "
98 "L%d protocol number %d\n",
99 timeout_name, 4, timeout->l4proto->l4proto);
100 goto err_put_timeout;
101 }
102 timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC);
103 if (!timeout_ext) {
104 ret = -ENOMEM;
105 goto err_put_timeout;
106 }
107
108 rcu_read_unlock();
109 return ret;
110
111err_put_timeout:
112 __nf_ct_timeout_put(timeout);
113out:
114 rcu_read_unlock();
115 if (errmsg)
116 pr_info_ratelimited("%s\n", errmsg);
117 return ret;
118}
119EXPORT_SYMBOL_GPL(nf_ct_set_timeout);
120
121void nf_ct_destroy_timeout(struct nf_conn *ct)
122{
123 struct nf_conn_timeout *timeout_ext;
124 typeof(nf_ct_timeout_put_hook) timeout_put;
125
126 rcu_read_lock();
127 timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
128
129 if (timeout_put) {
130 timeout_ext = nf_ct_timeout_find(ct);
131 if (timeout_ext) {
132 timeout_put(timeout_ext->timeout);
133 RCU_INIT_POINTER(timeout_ext->timeout, NULL);
134 }
135 }
136 rcu_read_unlock();
137}
138EXPORT_SYMBOL_GPL(nf_ct_destroy_timeout);
139
51static const struct nf_ct_ext_type timeout_extend = { 140static const struct nf_ct_ext_type timeout_extend = {
52 .len = sizeof(struct nf_conn_timeout), 141 .len = sizeof(struct nf_conn_timeout),
53 .align = __alignof__(struct nf_conn_timeout), 142 .align = __alignof__(struct nf_conn_timeout),
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 7aabfd4b1e50..4469519a4879 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -185,14 +185,25 @@ static const struct rhashtable_params nf_flow_offload_rhash_params = {
185 185
186int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow) 186int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
187{ 187{
188 flow->timeout = (u32)jiffies; 188 int err;
189 189
190 rhashtable_insert_fast(&flow_table->rhashtable, 190 err = rhashtable_insert_fast(&flow_table->rhashtable,
191 &flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node, 191 &flow->tuplehash[0].node,
192 nf_flow_offload_rhash_params); 192 nf_flow_offload_rhash_params);
193 rhashtable_insert_fast(&flow_table->rhashtable, 193 if (err < 0)
194 &flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node, 194 return err;
195 nf_flow_offload_rhash_params); 195
196 err = rhashtable_insert_fast(&flow_table->rhashtable,
197 &flow->tuplehash[1].node,
198 nf_flow_offload_rhash_params);
199 if (err < 0) {
200 rhashtable_remove_fast(&flow_table->rhashtable,
201 &flow->tuplehash[0].node,
202 nf_flow_offload_rhash_params);
203 return err;
204 }
205
206 flow->timeout = (u32)jiffies;
196 return 0; 207 return 0;
197} 208}
198EXPORT_SYMBOL_GPL(flow_offload_add); 209EXPORT_SYMBOL_GPL(flow_offload_add);
@@ -232,6 +243,7 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
232{ 243{
233 struct flow_offload_tuple_rhash *tuplehash; 244 struct flow_offload_tuple_rhash *tuplehash;
234 struct flow_offload *flow; 245 struct flow_offload *flow;
246 struct flow_offload_entry *e;
235 int dir; 247 int dir;
236 248
237 tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple, 249 tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple,
@@ -244,6 +256,10 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
244 if (flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN)) 256 if (flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN))
245 return NULL; 257 return NULL;
246 258
259 e = container_of(flow, struct flow_offload_entry, flow);
260 if (unlikely(nf_ct_is_dying(e->ct)))
261 return NULL;
262
247 return tuplehash; 263 return tuplehash;
248} 264}
249EXPORT_SYMBOL_GPL(flow_offload_lookup); 265EXPORT_SYMBOL_GPL(flow_offload_lookup);
@@ -290,8 +306,10 @@ static inline bool nf_flow_has_expired(const struct flow_offload *flow)
290static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data) 306static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
291{ 307{
292 struct nf_flowtable *flow_table = data; 308 struct nf_flowtable *flow_table = data;
309 struct flow_offload_entry *e;
293 310
294 if (nf_flow_has_expired(flow) || 311 e = container_of(flow, struct flow_offload_entry, flow);
312 if (nf_flow_has_expired(flow) || nf_ct_is_dying(e->ct) ||
295 (flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN))) 313 (flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN)))
296 flow_offload_del(flow_table, flow); 314 flow_offload_del(flow_table, flow);
297} 315}
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index 1d291a51cd45..0d603e20b519 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -181,6 +181,9 @@ static int nf_flow_tuple_ip(struct sk_buff *skb, const struct net_device *dev,
181 iph->protocol != IPPROTO_UDP) 181 iph->protocol != IPPROTO_UDP)
182 return -1; 182 return -1;
183 183
184 if (iph->ttl <= 1)
185 return -1;
186
184 thoff = iph->ihl * 4; 187 thoff = iph->ihl * 4;
185 if (!pskb_may_pull(skb, thoff + sizeof(*ports))) 188 if (!pskb_may_pull(skb, thoff + sizeof(*ports)))
186 return -1; 189 return -1;
@@ -235,13 +238,10 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
235 if (tuplehash == NULL) 238 if (tuplehash == NULL)
236 return NF_ACCEPT; 239 return NF_ACCEPT;
237 240
238 outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.oifidx);
239 if (!outdev)
240 return NF_ACCEPT;
241
242 dir = tuplehash->tuple.dir; 241 dir = tuplehash->tuple.dir;
243 flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); 242 flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
244 rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache; 243 rt = (struct rtable *)flow->tuplehash[dir].tuple.dst_cache;
244 outdev = rt->dst.dev;
245 245
246 if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)) && 246 if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)) &&
247 (ip_hdr(skb)->frag_off & htons(IP_DF)) != 0) 247 (ip_hdr(skb)->frag_off & htons(IP_DF)) != 0)
@@ -411,6 +411,9 @@ static int nf_flow_tuple_ipv6(struct sk_buff *skb, const struct net_device *dev,
411 ip6h->nexthdr != IPPROTO_UDP) 411 ip6h->nexthdr != IPPROTO_UDP)
412 return -1; 412 return -1;
413 413
414 if (ip6h->hop_limit <= 1)
415 return -1;
416
414 thoff = sizeof(*ip6h); 417 thoff = sizeof(*ip6h);
415 if (!pskb_may_pull(skb, thoff + sizeof(*ports))) 418 if (!pskb_may_pull(skb, thoff + sizeof(*ports)))
416 return -1; 419 return -1;
@@ -452,13 +455,10 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
452 if (tuplehash == NULL) 455 if (tuplehash == NULL)
453 return NF_ACCEPT; 456 return NF_ACCEPT;
454 457
455 outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.oifidx);
456 if (!outdev)
457 return NF_ACCEPT;
458
459 dir = tuplehash->tuple.dir; 458 dir = tuplehash->tuple.dir;
460 flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); 459 flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
461 rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache; 460 rt = (struct rt6_info *)flow->tuplehash[dir].tuple.dst_cache;
461 outdev = rt->dst.dev;
462 462
463 if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu))) 463 if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
464 return NF_ACCEPT; 464 return NF_ACCEPT;
diff --git a/net/netfilter/nf_internals.h b/net/netfilter/nf_internals.h
index e15779fd58e3..d6c43902ebd7 100644
--- a/net/netfilter/nf_internals.h
+++ b/net/netfilter/nf_internals.h
@@ -7,9 +7,6 @@
7#include <linux/netdevice.h> 7#include <linux/netdevice.h>
8 8
9/* nf_queue.c */ 9/* nf_queue.c */
10int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,
11 const struct nf_hook_entries *entries, unsigned int index,
12 unsigned int verdict);
13void nf_queue_nf_hook_drop(struct net *net); 10void nf_queue_nf_hook_drop(struct net *net);
14 11
15/* nf_log.c */ 12/* nf_log.c */
diff --git a/net/netfilter/nf_nat_amanda.c b/net/netfilter/nf_nat_amanda.c
index e4d61a7a5258..4e59416ea709 100644
--- a/net/netfilter/nf_nat_amanda.c
+++ b/net/netfilter/nf_nat_amanda.c
@@ -19,10 +19,15 @@
19#include <net/netfilter/nf_nat_helper.h> 19#include <net/netfilter/nf_nat_helper.h>
20#include <linux/netfilter/nf_conntrack_amanda.h> 20#include <linux/netfilter/nf_conntrack_amanda.h>
21 21
22#define NAT_HELPER_NAME "amanda"
23
22MODULE_AUTHOR("Brian J. Murrell <netfilter@interlinx.bc.ca>"); 24MODULE_AUTHOR("Brian J. Murrell <netfilter@interlinx.bc.ca>");
23MODULE_DESCRIPTION("Amanda NAT helper"); 25MODULE_DESCRIPTION("Amanda NAT helper");
24MODULE_LICENSE("GPL"); 26MODULE_LICENSE("GPL");
25MODULE_ALIAS("ip_nat_amanda"); 27MODULE_ALIAS_NF_NAT_HELPER(NAT_HELPER_NAME);
28
29static struct nf_conntrack_nat_helper nat_helper_amanda =
30 NF_CT_NAT_HELPER_INIT(NAT_HELPER_NAME);
26 31
27static unsigned int help(struct sk_buff *skb, 32static unsigned int help(struct sk_buff *skb,
28 enum ip_conntrack_info ctinfo, 33 enum ip_conntrack_info ctinfo,
@@ -74,6 +79,7 @@ static unsigned int help(struct sk_buff *skb,
74 79
75static void __exit nf_nat_amanda_fini(void) 80static void __exit nf_nat_amanda_fini(void)
76{ 81{
82 nf_nat_helper_unregister(&nat_helper_amanda);
77 RCU_INIT_POINTER(nf_nat_amanda_hook, NULL); 83 RCU_INIT_POINTER(nf_nat_amanda_hook, NULL);
78 synchronize_rcu(); 84 synchronize_rcu();
79} 85}
@@ -81,6 +87,7 @@ static void __exit nf_nat_amanda_fini(void)
81static int __init nf_nat_amanda_init(void) 87static int __init nf_nat_amanda_init(void)
82{ 88{
83 BUG_ON(nf_nat_amanda_hook != NULL); 89 BUG_ON(nf_nat_amanda_hook != NULL);
90 nf_nat_helper_register(&nat_helper_amanda);
84 RCU_INIT_POINTER(nf_nat_amanda_hook, help); 91 RCU_INIT_POINTER(nf_nat_amanda_hook, help);
85 return 0; 92 return 0;
86} 93}
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index af7dc6537758..cd94481e6c07 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -415,9 +415,14 @@ static void nf_nat_l4proto_unique_tuple(struct nf_conntrack_tuple *tuple,
415 case IPPROTO_ICMPV6: 415 case IPPROTO_ICMPV6:
416 /* id is same for either direction... */ 416 /* id is same for either direction... */
417 keyptr = &tuple->src.u.icmp.id; 417 keyptr = &tuple->src.u.icmp.id;
418 min = range->min_proto.icmp.id; 418 if (!(range->flags & NF_NAT_RANGE_PROTO_SPECIFIED)) {
419 range_size = ntohs(range->max_proto.icmp.id) - 419 min = 0;
420 ntohs(range->min_proto.icmp.id) + 1; 420 range_size = 65536;
421 } else {
422 min = ntohs(range->min_proto.icmp.id);
423 range_size = ntohs(range->max_proto.icmp.id) -
424 ntohs(range->min_proto.icmp.id) + 1;
425 }
421 goto find_free_id; 426 goto find_free_id;
422#if IS_ENABLED(CONFIG_NF_CT_PROTO_GRE) 427#if IS_ENABLED(CONFIG_NF_CT_PROTO_GRE)
423 case IPPROTO_GRE: 428 case IPPROTO_GRE:
@@ -885,8 +890,8 @@ static int nfnetlink_parse_nat_proto(struct nlattr *attr,
885 struct nlattr *tb[CTA_PROTONAT_MAX+1]; 890 struct nlattr *tb[CTA_PROTONAT_MAX+1];
886 int err; 891 int err;
887 892
888 err = nla_parse_nested(tb, CTA_PROTONAT_MAX, attr, 893 err = nla_parse_nested_deprecated(tb, CTA_PROTONAT_MAX, attr,
889 protonat_nla_policy, NULL); 894 protonat_nla_policy, NULL);
890 if (err < 0) 895 if (err < 0)
891 return err; 896 return err;
892 897
@@ -944,7 +949,8 @@ nfnetlink_parse_nat(const struct nlattr *nat,
944 949
945 memset(range, 0, sizeof(*range)); 950 memset(range, 0, sizeof(*range));
946 951
947 err = nla_parse_nested(tb, CTA_NAT_MAX, nat, nat_nla_policy, NULL); 952 err = nla_parse_nested_deprecated(tb, CTA_NAT_MAX, nat,
953 nat_nla_policy, NULL);
948 if (err < 0) 954 if (err < 0)
949 return err; 955 return err;
950 956
@@ -1009,7 +1015,7 @@ static struct nf_ct_helper_expectfn follow_master_nat = {
1009 .expectfn = nf_nat_follow_master, 1015 .expectfn = nf_nat_follow_master,
1010}; 1016};
1011 1017
1012int nf_nat_register_fn(struct net *net, const struct nf_hook_ops *ops, 1018int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,
1013 const struct nf_hook_ops *orig_nat_ops, unsigned int ops_count) 1019 const struct nf_hook_ops *orig_nat_ops, unsigned int ops_count)
1014{ 1020{
1015 struct nat_net *nat_net = net_generic(net, nat_net_id); 1021 struct nat_net *nat_net = net_generic(net, nat_net_id);
@@ -1019,14 +1025,12 @@ int nf_nat_register_fn(struct net *net, const struct nf_hook_ops *ops,
1019 struct nf_hook_ops *nat_ops; 1025 struct nf_hook_ops *nat_ops;
1020 int i, ret; 1026 int i, ret;
1021 1027
1022 if (WARN_ON_ONCE(ops->pf >= ARRAY_SIZE(nat_net->nat_proto_net))) 1028 if (WARN_ON_ONCE(pf >= ARRAY_SIZE(nat_net->nat_proto_net)))
1023 return -EINVAL; 1029 return -EINVAL;
1024 1030
1025 nat_proto_net = &nat_net->nat_proto_net[ops->pf]; 1031 nat_proto_net = &nat_net->nat_proto_net[pf];
1026 1032
1027 for (i = 0; i < ops_count; i++) { 1033 for (i = 0; i < ops_count; i++) {
1028 if (WARN_ON(orig_nat_ops[i].pf != ops->pf))
1029 return -EINVAL;
1030 if (orig_nat_ops[i].hooknum == hooknum) { 1034 if (orig_nat_ops[i].hooknum == hooknum) {
1031 hooknum = i; 1035 hooknum = i;
1032 break; 1036 break;
@@ -1086,8 +1090,8 @@ int nf_nat_register_fn(struct net *net, const struct nf_hook_ops *ops,
1086 return ret; 1090 return ret;
1087} 1091}
1088 1092
1089void nf_nat_unregister_fn(struct net *net, const struct nf_hook_ops *ops, 1093void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,
1090 unsigned int ops_count) 1094 unsigned int ops_count)
1091{ 1095{
1092 struct nat_net *nat_net = net_generic(net, nat_net_id); 1096 struct nat_net *nat_net = net_generic(net, nat_net_id);
1093 struct nf_nat_hooks_net *nat_proto_net; 1097 struct nf_nat_hooks_net *nat_proto_net;
@@ -1096,10 +1100,10 @@ void nf_nat_unregister_fn(struct net *net, const struct nf_hook_ops *ops,
1096 int hooknum = ops->hooknum; 1100 int hooknum = ops->hooknum;
1097 int i; 1101 int i;
1098 1102
1099 if (ops->pf >= ARRAY_SIZE(nat_net->nat_proto_net)) 1103 if (pf >= ARRAY_SIZE(nat_net->nat_proto_net))
1100 return; 1104 return;
1101 1105
1102 nat_proto_net = &nat_net->nat_proto_net[ops->pf]; 1106 nat_proto_net = &nat_net->nat_proto_net[pf];
1103 1107
1104 mutex_lock(&nf_nat_proto_mutex); 1108 mutex_lock(&nf_nat_proto_mutex);
1105 if (WARN_ON(nat_proto_net->users == 0)) 1109 if (WARN_ON(nat_proto_net->users == 0))
diff --git a/net/netfilter/nf_nat_ftp.c b/net/netfilter/nf_nat_ftp.c
index 5063cbf1689c..0ea6b1bc52de 100644
--- a/net/netfilter/nf_nat_ftp.c
+++ b/net/netfilter/nf_nat_ftp.c
@@ -21,13 +21,18 @@
21#include <net/netfilter/nf_conntrack_expect.h> 21#include <net/netfilter/nf_conntrack_expect.h>
22#include <linux/netfilter/nf_conntrack_ftp.h> 22#include <linux/netfilter/nf_conntrack_ftp.h>
23 23
24#define NAT_HELPER_NAME "ftp"
25
24MODULE_LICENSE("GPL"); 26MODULE_LICENSE("GPL");
25MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>"); 27MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>");
26MODULE_DESCRIPTION("ftp NAT helper"); 28MODULE_DESCRIPTION("ftp NAT helper");
27MODULE_ALIAS("ip_nat_ftp"); 29MODULE_ALIAS_NF_NAT_HELPER(NAT_HELPER_NAME);
28 30
29/* FIXME: Time out? --RR */ 31/* FIXME: Time out? --RR */
30 32
33static struct nf_conntrack_nat_helper nat_helper_ftp =
34 NF_CT_NAT_HELPER_INIT(NAT_HELPER_NAME);
35
31static int nf_nat_ftp_fmt_cmd(struct nf_conn *ct, enum nf_ct_ftp_type type, 36static int nf_nat_ftp_fmt_cmd(struct nf_conn *ct, enum nf_ct_ftp_type type,
32 char *buffer, size_t buflen, 37 char *buffer, size_t buflen,
33 union nf_inet_addr *addr, u16 port) 38 union nf_inet_addr *addr, u16 port)
@@ -124,6 +129,7 @@ out:
124 129
125static void __exit nf_nat_ftp_fini(void) 130static void __exit nf_nat_ftp_fini(void)
126{ 131{
132 nf_nat_helper_unregister(&nat_helper_ftp);
127 RCU_INIT_POINTER(nf_nat_ftp_hook, NULL); 133 RCU_INIT_POINTER(nf_nat_ftp_hook, NULL);
128 synchronize_rcu(); 134 synchronize_rcu();
129} 135}
@@ -131,6 +137,7 @@ static void __exit nf_nat_ftp_fini(void)
131static int __init nf_nat_ftp_init(void) 137static int __init nf_nat_ftp_init(void)
132{ 138{
133 BUG_ON(nf_nat_ftp_hook != NULL); 139 BUG_ON(nf_nat_ftp_hook != NULL);
140 nf_nat_helper_register(&nat_helper_ftp);
134 RCU_INIT_POINTER(nf_nat_ftp_hook, nf_nat_ftp); 141 RCU_INIT_POINTER(nf_nat_ftp_hook, nf_nat_ftp);
135 return 0; 142 return 0;
136} 143}
diff --git a/net/netfilter/nf_nat_irc.c b/net/netfilter/nf_nat_irc.c
index 3aa35a43100d..d87cbe5e03ec 100644
--- a/net/netfilter/nf_nat_irc.c
+++ b/net/netfilter/nf_nat_irc.c
@@ -23,10 +23,15 @@
23#include <net/netfilter/nf_conntrack_expect.h> 23#include <net/netfilter/nf_conntrack_expect.h>
24#include <linux/netfilter/nf_conntrack_irc.h> 24#include <linux/netfilter/nf_conntrack_irc.h>
25 25
26#define NAT_HELPER_NAME "irc"
27
26MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); 28MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
27MODULE_DESCRIPTION("IRC (DCC) NAT helper"); 29MODULE_DESCRIPTION("IRC (DCC) NAT helper");
28MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
29MODULE_ALIAS("ip_nat_irc"); 31MODULE_ALIAS_NF_NAT_HELPER(NAT_HELPER_NAME);
32
33static struct nf_conntrack_nat_helper nat_helper_irc =
34 NF_CT_NAT_HELPER_INIT(NAT_HELPER_NAME);
30 35
31static unsigned int help(struct sk_buff *skb, 36static unsigned int help(struct sk_buff *skb,
32 enum ip_conntrack_info ctinfo, 37 enum ip_conntrack_info ctinfo,
@@ -96,6 +101,7 @@ static unsigned int help(struct sk_buff *skb,
96 101
97static void __exit nf_nat_irc_fini(void) 102static void __exit nf_nat_irc_fini(void)
98{ 103{
104 nf_nat_helper_unregister(&nat_helper_irc);
99 RCU_INIT_POINTER(nf_nat_irc_hook, NULL); 105 RCU_INIT_POINTER(nf_nat_irc_hook, NULL);
100 synchronize_rcu(); 106 synchronize_rcu();
101} 107}
@@ -103,6 +109,7 @@ static void __exit nf_nat_irc_fini(void)
103static int __init nf_nat_irc_init(void) 109static int __init nf_nat_irc_init(void)
104{ 110{
105 BUG_ON(nf_nat_irc_hook != NULL); 111 BUG_ON(nf_nat_irc_hook != NULL);
112 nf_nat_helper_register(&nat_helper_irc);
106 RCU_INIT_POINTER(nf_nat_irc_hook, help); 113 RCU_INIT_POINTER(nf_nat_irc_hook, help);
107 return 0; 114 return 0;
108} 115}
diff --git a/net/netfilter/nf_nat_masquerade.c b/net/netfilter/nf_nat_masquerade.c
index d85c4d902e7b..8e8a65d46345 100644
--- a/net/netfilter/nf_nat_masquerade.c
+++ b/net/netfilter/nf_nat_masquerade.c
@@ -7,12 +7,10 @@
7#include <linux/netfilter_ipv4.h> 7#include <linux/netfilter_ipv4.h>
8#include <linux/netfilter_ipv6.h> 8#include <linux/netfilter_ipv6.h>
9 9
10#include <net/netfilter/ipv4/nf_nat_masquerade.h> 10#include <net/netfilter/nf_nat_masquerade.h>
11#include <net/netfilter/ipv6/nf_nat_masquerade.h>
12 11
13static DEFINE_MUTEX(masq_mutex); 12static DEFINE_MUTEX(masq_mutex);
14static unsigned int masq_refcnt4 __read_mostly; 13static unsigned int masq_refcnt __read_mostly;
15static unsigned int masq_refcnt6 __read_mostly;
16 14
17unsigned int 15unsigned int
18nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum, 16nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum,
@@ -137,56 +135,6 @@ static struct notifier_block masq_inet_notifier = {
137 .notifier_call = masq_inet_event, 135 .notifier_call = masq_inet_event,
138}; 136};
139 137
140int nf_nat_masquerade_ipv4_register_notifier(void)
141{
142 int ret = 0;
143
144 mutex_lock(&masq_mutex);
145 if (WARN_ON_ONCE(masq_refcnt4 == UINT_MAX)) {
146 ret = -EOVERFLOW;
147 goto out_unlock;
148 }
149
150 /* check if the notifier was already set */
151 if (++masq_refcnt4 > 1)
152 goto out_unlock;
153
154 /* Register for device down reports */
155 ret = register_netdevice_notifier(&masq_dev_notifier);
156 if (ret)
157 goto err_dec;
158 /* Register IP address change reports */
159 ret = register_inetaddr_notifier(&masq_inet_notifier);
160 if (ret)
161 goto err_unregister;
162
163 mutex_unlock(&masq_mutex);
164 return ret;
165
166err_unregister:
167 unregister_netdevice_notifier(&masq_dev_notifier);
168err_dec:
169 masq_refcnt4--;
170out_unlock:
171 mutex_unlock(&masq_mutex);
172 return ret;
173}
174EXPORT_SYMBOL_GPL(nf_nat_masquerade_ipv4_register_notifier);
175
176void nf_nat_masquerade_ipv4_unregister_notifier(void)
177{
178 mutex_lock(&masq_mutex);
179 /* check if the notifier still has clients */
180 if (--masq_refcnt4 > 0)
181 goto out_unlock;
182
183 unregister_netdevice_notifier(&masq_dev_notifier);
184 unregister_inetaddr_notifier(&masq_inet_notifier);
185out_unlock:
186 mutex_unlock(&masq_mutex);
187}
188EXPORT_SYMBOL_GPL(nf_nat_masquerade_ipv4_unregister_notifier);
189
190#if IS_ENABLED(CONFIG_IPV6) 138#if IS_ENABLED(CONFIG_IPV6)
191static atomic_t v6_worker_count __read_mostly; 139static atomic_t v6_worker_count __read_mostly;
192 140
@@ -322,44 +270,68 @@ static struct notifier_block masq_inet6_notifier = {
322 .notifier_call = masq_inet6_event, 270 .notifier_call = masq_inet6_event,
323}; 271};
324 272
325int nf_nat_masquerade_ipv6_register_notifier(void) 273static int nf_nat_masquerade_ipv6_register_notifier(void)
274{
275 return register_inet6addr_notifier(&masq_inet6_notifier);
276}
277#else
278static inline int nf_nat_masquerade_ipv6_register_notifier(void) { return 0; }
279#endif
280
281int nf_nat_masquerade_inet_register_notifiers(void)
326{ 282{
327 int ret = 0; 283 int ret = 0;
328 284
329 mutex_lock(&masq_mutex); 285 mutex_lock(&masq_mutex);
330 if (WARN_ON_ONCE(masq_refcnt6 == UINT_MAX)) { 286 if (WARN_ON_ONCE(masq_refcnt == UINT_MAX)) {
331 ret = -EOVERFLOW; 287 ret = -EOVERFLOW;
332 goto out_unlock; 288 goto out_unlock;
333 } 289 }
334 290
335 /* check if the notifier is already set */ 291 /* check if the notifier was already set */
336 if (++masq_refcnt6 > 1) 292 if (++masq_refcnt > 1)
337 goto out_unlock; 293 goto out_unlock;
338 294
339 ret = register_inet6addr_notifier(&masq_inet6_notifier); 295 /* Register for device down reports */
296 ret = register_netdevice_notifier(&masq_dev_notifier);
340 if (ret) 297 if (ret)
341 goto err_dec; 298 goto err_dec;
299 /* Register IP address change reports */
300 ret = register_inetaddr_notifier(&masq_inet_notifier);
301 if (ret)
302 goto err_unregister;
303
304 ret = nf_nat_masquerade_ipv6_register_notifier();
305 if (ret)
306 goto err_unreg_inet;
342 307
343 mutex_unlock(&masq_mutex); 308 mutex_unlock(&masq_mutex);
344 return ret; 309 return ret;
310err_unreg_inet:
311 unregister_inetaddr_notifier(&masq_inet_notifier);
312err_unregister:
313 unregister_netdevice_notifier(&masq_dev_notifier);
345err_dec: 314err_dec:
346 masq_refcnt6--; 315 masq_refcnt--;
347out_unlock: 316out_unlock:
348 mutex_unlock(&masq_mutex); 317 mutex_unlock(&masq_mutex);
349 return ret; 318 return ret;
350} 319}
351EXPORT_SYMBOL_GPL(nf_nat_masquerade_ipv6_register_notifier); 320EXPORT_SYMBOL_GPL(nf_nat_masquerade_inet_register_notifiers);
352 321
353void nf_nat_masquerade_ipv6_unregister_notifier(void) 322void nf_nat_masquerade_inet_unregister_notifiers(void)
354{ 323{
355 mutex_lock(&masq_mutex); 324 mutex_lock(&masq_mutex);
356 /* check if the notifier still has clients */ 325 /* check if the notifiers still have clients */
357 if (--masq_refcnt6 > 0) 326 if (--masq_refcnt > 0)
358 goto out_unlock; 327 goto out_unlock;
359 328
329 unregister_netdevice_notifier(&masq_dev_notifier);
330 unregister_inetaddr_notifier(&masq_inet_notifier);
331#if IS_ENABLED(CONFIG_IPV6)
360 unregister_inet6addr_notifier(&masq_inet6_notifier); 332 unregister_inet6addr_notifier(&masq_inet6_notifier);
333#endif
361out_unlock: 334out_unlock:
362 mutex_unlock(&masq_mutex); 335 mutex_unlock(&masq_mutex);
363} 336}
364EXPORT_SYMBOL_GPL(nf_nat_masquerade_ipv6_unregister_notifier); 337EXPORT_SYMBOL_GPL(nf_nat_masquerade_inet_unregister_notifiers);
365#endif
diff --git a/net/netfilter/nf_nat_proto.c b/net/netfilter/nf_nat_proto.c
index 62743da3004f..84f5c90a7f21 100644
--- a/net/netfilter/nf_nat_proto.c
+++ b/net/netfilter/nf_nat_proto.c
@@ -725,7 +725,7 @@ nf_nat_ipv4_local_fn(void *priv, struct sk_buff *skb,
725 return ret; 725 return ret;
726} 726}
727 727
728static const struct nf_hook_ops nf_nat_ipv4_ops[] = { 728const struct nf_hook_ops nf_nat_ipv4_ops[] = {
729 /* Before packet filtering, change destination */ 729 /* Before packet filtering, change destination */
730 { 730 {
731 .hook = nf_nat_ipv4_in, 731 .hook = nf_nat_ipv4_in,
@@ -758,13 +758,14 @@ static const struct nf_hook_ops nf_nat_ipv4_ops[] = {
758 758
759int nf_nat_ipv4_register_fn(struct net *net, const struct nf_hook_ops *ops) 759int nf_nat_ipv4_register_fn(struct net *net, const struct nf_hook_ops *ops)
760{ 760{
761 return nf_nat_register_fn(net, ops, nf_nat_ipv4_ops, ARRAY_SIZE(nf_nat_ipv4_ops)); 761 return nf_nat_register_fn(net, ops->pf, ops, nf_nat_ipv4_ops,
762 ARRAY_SIZE(nf_nat_ipv4_ops));
762} 763}
763EXPORT_SYMBOL_GPL(nf_nat_ipv4_register_fn); 764EXPORT_SYMBOL_GPL(nf_nat_ipv4_register_fn);
764 765
765void nf_nat_ipv4_unregister_fn(struct net *net, const struct nf_hook_ops *ops) 766void nf_nat_ipv4_unregister_fn(struct net *net, const struct nf_hook_ops *ops)
766{ 767{
767 nf_nat_unregister_fn(net, ops, ARRAY_SIZE(nf_nat_ipv4_ops)); 768 nf_nat_unregister_fn(net, ops->pf, ops, ARRAY_SIZE(nf_nat_ipv4_ops));
768} 769}
769EXPORT_SYMBOL_GPL(nf_nat_ipv4_unregister_fn); 770EXPORT_SYMBOL_GPL(nf_nat_ipv4_unregister_fn);
770 771
@@ -925,20 +926,6 @@ nf_nat_ipv6_out(void *priv, struct sk_buff *skb,
925 return ret; 926 return ret;
926} 927}
927 928
928static int nat_route_me_harder(struct net *net, struct sk_buff *skb)
929{
930#ifdef CONFIG_IPV6_MODULE
931 const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
932
933 if (!v6_ops)
934 return -EHOSTUNREACH;
935
936 return v6_ops->route_me_harder(net, skb);
937#else
938 return ip6_route_me_harder(net, skb);
939#endif
940}
941
942static unsigned int 929static unsigned int
943nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb, 930nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb,
944 const struct nf_hook_state *state) 931 const struct nf_hook_state *state)
@@ -958,7 +945,7 @@ nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb,
958 945
959 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3, 946 if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3,
960 &ct->tuplehash[!dir].tuple.src.u3)) { 947 &ct->tuplehash[!dir].tuple.src.u3)) {
961 err = nat_route_me_harder(state->net, skb); 948 err = nf_ip6_route_me_harder(state->net, skb);
962 if (err < 0) 949 if (err < 0)
963 ret = NF_DROP_ERR(err); 950 ret = NF_DROP_ERR(err);
964 } 951 }
@@ -977,7 +964,7 @@ nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb,
977 return ret; 964 return ret;
978} 965}
979 966
980static const struct nf_hook_ops nf_nat_ipv6_ops[] = { 967const struct nf_hook_ops nf_nat_ipv6_ops[] = {
981 /* Before packet filtering, change destination */ 968 /* Before packet filtering, change destination */
982 { 969 {
983 .hook = nf_nat_ipv6_in, 970 .hook = nf_nat_ipv6_in,
@@ -1010,14 +997,44 @@ static const struct nf_hook_ops nf_nat_ipv6_ops[] = {
1010 997
1011int nf_nat_ipv6_register_fn(struct net *net, const struct nf_hook_ops *ops) 998int nf_nat_ipv6_register_fn(struct net *net, const struct nf_hook_ops *ops)
1012{ 999{
1013 return nf_nat_register_fn(net, ops, nf_nat_ipv6_ops, 1000 return nf_nat_register_fn(net, ops->pf, ops, nf_nat_ipv6_ops,
1014 ARRAY_SIZE(nf_nat_ipv6_ops)); 1001 ARRAY_SIZE(nf_nat_ipv6_ops));
1015} 1002}
1016EXPORT_SYMBOL_GPL(nf_nat_ipv6_register_fn); 1003EXPORT_SYMBOL_GPL(nf_nat_ipv6_register_fn);
1017 1004
1018void nf_nat_ipv6_unregister_fn(struct net *net, const struct nf_hook_ops *ops) 1005void nf_nat_ipv6_unregister_fn(struct net *net, const struct nf_hook_ops *ops)
1019{ 1006{
1020 nf_nat_unregister_fn(net, ops, ARRAY_SIZE(nf_nat_ipv6_ops)); 1007 nf_nat_unregister_fn(net, ops->pf, ops, ARRAY_SIZE(nf_nat_ipv6_ops));
1021} 1008}
1022EXPORT_SYMBOL_GPL(nf_nat_ipv6_unregister_fn); 1009EXPORT_SYMBOL_GPL(nf_nat_ipv6_unregister_fn);
1023#endif /* CONFIG_IPV6 */ 1010#endif /* CONFIG_IPV6 */
1011
1012#if defined(CONFIG_NF_TABLES_INET) && IS_ENABLED(CONFIG_NFT_NAT)
1013int nf_nat_inet_register_fn(struct net *net, const struct nf_hook_ops *ops)
1014{
1015 int ret;
1016
1017 if (WARN_ON_ONCE(ops->pf != NFPROTO_INET))
1018 return -EINVAL;
1019
1020 ret = nf_nat_register_fn(net, NFPROTO_IPV6, ops, nf_nat_ipv6_ops,
1021 ARRAY_SIZE(nf_nat_ipv6_ops));
1022 if (ret)
1023 return ret;
1024
1025 ret = nf_nat_register_fn(net, NFPROTO_IPV4, ops, nf_nat_ipv4_ops,
1026 ARRAY_SIZE(nf_nat_ipv4_ops));
1027 if (ret)
1028 nf_nat_ipv6_unregister_fn(net, ops);
1029
1030 return ret;
1031}
1032EXPORT_SYMBOL_GPL(nf_nat_inet_register_fn);
1033
1034void nf_nat_inet_unregister_fn(struct net *net, const struct nf_hook_ops *ops)
1035{
1036 nf_nat_unregister_fn(net, NFPROTO_IPV4, ops, ARRAY_SIZE(nf_nat_ipv4_ops));
1037 nf_nat_unregister_fn(net, NFPROTO_IPV6, ops, ARRAY_SIZE(nf_nat_ipv6_ops));
1038}
1039EXPORT_SYMBOL_GPL(nf_nat_inet_unregister_fn);
1040#endif /* NFT INET NAT */
diff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c
index aa1be643d7a0..464387b3600f 100644
--- a/net/netfilter/nf_nat_sip.c
+++ b/net/netfilter/nf_nat_sip.c
@@ -24,11 +24,15 @@
24#include <net/netfilter/nf_conntrack_seqadj.h> 24#include <net/netfilter/nf_conntrack_seqadj.h>
25#include <linux/netfilter/nf_conntrack_sip.h> 25#include <linux/netfilter/nf_conntrack_sip.h>
26 26
27#define NAT_HELPER_NAME "sip"
28
27MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
28MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>"); 30MODULE_AUTHOR("Christian Hentschel <chentschel@arnet.com.ar>");
29MODULE_DESCRIPTION("SIP NAT helper"); 31MODULE_DESCRIPTION("SIP NAT helper");
30MODULE_ALIAS("ip_nat_sip"); 32MODULE_ALIAS_NF_NAT_HELPER(NAT_HELPER_NAME);
31 33
34static struct nf_conntrack_nat_helper nat_helper_sip =
35 NF_CT_NAT_HELPER_INIT(NAT_HELPER_NAME);
32 36
33static unsigned int mangle_packet(struct sk_buff *skb, unsigned int protoff, 37static unsigned int mangle_packet(struct sk_buff *skb, unsigned int protoff,
34 unsigned int dataoff, 38 unsigned int dataoff,
@@ -656,8 +660,8 @@ static struct nf_ct_helper_expectfn sip_nat = {
656 660
657static void __exit nf_nat_sip_fini(void) 661static void __exit nf_nat_sip_fini(void)
658{ 662{
663 nf_nat_helper_unregister(&nat_helper_sip);
659 RCU_INIT_POINTER(nf_nat_sip_hooks, NULL); 664 RCU_INIT_POINTER(nf_nat_sip_hooks, NULL);
660
661 nf_ct_helper_expectfn_unregister(&sip_nat); 665 nf_ct_helper_expectfn_unregister(&sip_nat);
662 synchronize_rcu(); 666 synchronize_rcu();
663} 667}
@@ -675,6 +679,7 @@ static const struct nf_nat_sip_hooks sip_hooks = {
675static int __init nf_nat_sip_init(void) 679static int __init nf_nat_sip_init(void)
676{ 680{
677 BUG_ON(nf_nat_sip_hooks != NULL); 681 BUG_ON(nf_nat_sip_hooks != NULL);
682 nf_nat_helper_register(&nat_helper_sip);
678 RCU_INIT_POINTER(nf_nat_sip_hooks, &sip_hooks); 683 RCU_INIT_POINTER(nf_nat_sip_hooks, &sip_hooks);
679 nf_ct_helper_expectfn_register(&sip_nat); 684 nf_ct_helper_expectfn_register(&sip_nat);
680 return 0; 685 return 0;
diff --git a/net/netfilter/nf_nat_tftp.c b/net/netfilter/nf_nat_tftp.c
index 7f67e1d5310d..e633b3863e33 100644
--- a/net/netfilter/nf_nat_tftp.c
+++ b/net/netfilter/nf_nat_tftp.c
@@ -13,10 +13,15 @@
13#include <net/netfilter/nf_nat_helper.h> 13#include <net/netfilter/nf_nat_helper.h>
14#include <linux/netfilter/nf_conntrack_tftp.h> 14#include <linux/netfilter/nf_conntrack_tftp.h>
15 15
16#define NAT_HELPER_NAME "tftp"
17
16MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>"); 18MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
17MODULE_DESCRIPTION("TFTP NAT helper"); 19MODULE_DESCRIPTION("TFTP NAT helper");
18MODULE_LICENSE("GPL"); 20MODULE_LICENSE("GPL");
19MODULE_ALIAS("ip_nat_tftp"); 21MODULE_ALIAS_NF_NAT_HELPER(NAT_HELPER_NAME);
22
23static struct nf_conntrack_nat_helper nat_helper_tftp =
24 NF_CT_NAT_HELPER_INIT(NAT_HELPER_NAME);
20 25
21static unsigned int help(struct sk_buff *skb, 26static unsigned int help(struct sk_buff *skb,
22 enum ip_conntrack_info ctinfo, 27 enum ip_conntrack_info ctinfo,
@@ -37,6 +42,7 @@ static unsigned int help(struct sk_buff *skb,
37 42
38static void __exit nf_nat_tftp_fini(void) 43static void __exit nf_nat_tftp_fini(void)
39{ 44{
45 nf_nat_helper_unregister(&nat_helper_tftp);
40 RCU_INIT_POINTER(nf_nat_tftp_hook, NULL); 46 RCU_INIT_POINTER(nf_nat_tftp_hook, NULL);
41 synchronize_rcu(); 47 synchronize_rcu();
42} 48}
@@ -44,6 +50,7 @@ static void __exit nf_nat_tftp_fini(void)
44static int __init nf_nat_tftp_init(void) 50static int __init nf_nat_tftp_init(void)
45{ 51{
46 BUG_ON(nf_nat_tftp_hook != NULL); 52 BUG_ON(nf_nat_tftp_hook != NULL);
53 nf_nat_helper_register(&nat_helper_tftp);
47 RCU_INIT_POINTER(nf_nat_tftp_hook, help); 54 RCU_INIT_POINTER(nf_nat_tftp_hook, help);
48 return 0; 55 return 0;
49} 56}
diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c
index a36a77bae1d6..9dc1d6e04946 100644
--- a/net/netfilter/nf_queue.c
+++ b/net/netfilter/nf_queue.c
@@ -240,6 +240,7 @@ int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,
240 240
241 return 0; 241 return 0;
242} 242}
243EXPORT_SYMBOL_GPL(nf_queue);
243 244
244static unsigned int nf_iterate(struct sk_buff *skb, 245static unsigned int nf_iterate(struct sk_buff *skb,
245 struct nf_hook_state *state, 246 struct nf_hook_state *state,
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index ef7772e976cc..28241e82fd15 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -53,7 +53,6 @@ static const struct rhashtable_params nft_chain_ht_params = {
53 .hashfn = nft_chain_hash, 53 .hashfn = nft_chain_hash,
54 .obj_hashfn = nft_chain_hash_obj, 54 .obj_hashfn = nft_chain_hash_obj,
55 .obj_cmpfn = nft_chain_hash_cmp, 55 .obj_cmpfn = nft_chain_hash_cmp,
56 .locks_mul = 1,
57 .automatic_shrinking = true, 56 .automatic_shrinking = true,
58}; 57};
59 58
@@ -214,33 +213,33 @@ static int nft_deltable(struct nft_ctx *ctx)
214 return err; 213 return err;
215} 214}
216 215
217static int nft_trans_chain_add(struct nft_ctx *ctx, int msg_type) 216static struct nft_trans *nft_trans_chain_add(struct nft_ctx *ctx, int msg_type)
218{ 217{
219 struct nft_trans *trans; 218 struct nft_trans *trans;
220 219
221 trans = nft_trans_alloc(ctx, msg_type, sizeof(struct nft_trans_chain)); 220 trans = nft_trans_alloc(ctx, msg_type, sizeof(struct nft_trans_chain));
222 if (trans == NULL) 221 if (trans == NULL)
223 return -ENOMEM; 222 return ERR_PTR(-ENOMEM);
224 223
225 if (msg_type == NFT_MSG_NEWCHAIN) 224 if (msg_type == NFT_MSG_NEWCHAIN)
226 nft_activate_next(ctx->net, ctx->chain); 225 nft_activate_next(ctx->net, ctx->chain);
227 226
228 list_add_tail(&trans->list, &ctx->net->nft.commit_list); 227 list_add_tail(&trans->list, &ctx->net->nft.commit_list);
229 return 0; 228 return trans;
230} 229}
231 230
232static int nft_delchain(struct nft_ctx *ctx) 231static int nft_delchain(struct nft_ctx *ctx)
233{ 232{
234 int err; 233 struct nft_trans *trans;
235 234
236 err = nft_trans_chain_add(ctx, NFT_MSG_DELCHAIN); 235 trans = nft_trans_chain_add(ctx, NFT_MSG_DELCHAIN);
237 if (err < 0) 236 if (IS_ERR(trans))
238 return err; 237 return PTR_ERR(trans);
239 238
240 ctx->table->use--; 239 ctx->table->use--;
241 nft_deactivate_next(ctx->net, ctx->chain); 240 nft_deactivate_next(ctx->net, ctx->chain);
242 241
243 return err; 242 return 0;
244} 243}
245 244
246static void nft_rule_expr_activate(const struct nft_ctx *ctx, 245static void nft_rule_expr_activate(const struct nft_ctx *ctx,
@@ -1190,6 +1189,9 @@ static int nft_dump_stats(struct sk_buff *skb, struct nft_stats __percpu *stats)
1190 u64 pkts, bytes; 1189 u64 pkts, bytes;
1191 int cpu; 1190 int cpu;
1192 1191
1192 if (!stats)
1193 return 0;
1194
1193 memset(&total, 0, sizeof(total)); 1195 memset(&total, 0, sizeof(total));
1194 for_each_possible_cpu(cpu) { 1196 for_each_possible_cpu(cpu) {
1195 cpu_stats = per_cpu_ptr(stats, cpu); 1197 cpu_stats = per_cpu_ptr(stats, cpu);
@@ -1201,7 +1203,7 @@ static int nft_dump_stats(struct sk_buff *skb, struct nft_stats __percpu *stats)
1201 total.pkts += pkts; 1203 total.pkts += pkts;
1202 total.bytes += bytes; 1204 total.bytes += bytes;
1203 } 1205 }
1204 nest = nla_nest_start(skb, NFTA_CHAIN_COUNTERS); 1206 nest = nla_nest_start_noflag(skb, NFTA_CHAIN_COUNTERS);
1205 if (nest == NULL) 1207 if (nest == NULL)
1206 goto nla_put_failure; 1208 goto nla_put_failure;
1207 1209
@@ -1247,9 +1249,10 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
1247 if (nft_is_base_chain(chain)) { 1249 if (nft_is_base_chain(chain)) {
1248 const struct nft_base_chain *basechain = nft_base_chain(chain); 1250 const struct nft_base_chain *basechain = nft_base_chain(chain);
1249 const struct nf_hook_ops *ops = &basechain->ops; 1251 const struct nf_hook_ops *ops = &basechain->ops;
1252 struct nft_stats __percpu *stats;
1250 struct nlattr *nest; 1253 struct nlattr *nest;
1251 1254
1252 nest = nla_nest_start(skb, NFTA_CHAIN_HOOK); 1255 nest = nla_nest_start_noflag(skb, NFTA_CHAIN_HOOK);
1253 if (nest == NULL) 1256 if (nest == NULL)
1254 goto nla_put_failure; 1257 goto nla_put_failure;
1255 if (nla_put_be32(skb, NFTA_HOOK_HOOKNUM, htonl(ops->hooknum))) 1258 if (nla_put_be32(skb, NFTA_HOOK_HOOKNUM, htonl(ops->hooknum)))
@@ -1268,8 +1271,9 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
1268 if (nla_put_string(skb, NFTA_CHAIN_TYPE, basechain->type->name)) 1271 if (nla_put_string(skb, NFTA_CHAIN_TYPE, basechain->type->name))
1269 goto nla_put_failure; 1272 goto nla_put_failure;
1270 1273
1271 if (rcu_access_pointer(basechain->stats) && 1274 stats = rcu_dereference_check(basechain->stats,
1272 nft_dump_stats(skb, rcu_dereference(basechain->stats))) 1275 lockdep_commit_lock_is_held(net));
1276 if (nft_dump_stats(skb, stats))
1273 goto nla_put_failure; 1277 goto nla_put_failure;
1274 } 1278 }
1275 1279
@@ -1421,8 +1425,8 @@ static struct nft_stats __percpu *nft_stats_alloc(const struct nlattr *attr)
1421 struct nft_stats *stats; 1425 struct nft_stats *stats;
1422 int err; 1426 int err;
1423 1427
1424 err = nla_parse_nested(tb, NFTA_COUNTER_MAX, attr, nft_counter_policy, 1428 err = nla_parse_nested_deprecated(tb, NFTA_COUNTER_MAX, attr,
1425 NULL); 1429 nft_counter_policy, NULL);
1426 if (err < 0) 1430 if (err < 0)
1427 return ERR_PTR(err); 1431 return ERR_PTR(err);
1428 1432
@@ -1526,8 +1530,9 @@ static int nft_chain_parse_hook(struct net *net,
1526 lockdep_assert_held(&net->nft.commit_mutex); 1530 lockdep_assert_held(&net->nft.commit_mutex);
1527 lockdep_nfnl_nft_mutex_not_held(); 1531 lockdep_nfnl_nft_mutex_not_held();
1528 1532
1529 err = nla_parse_nested(ha, NFTA_HOOK_MAX, nla[NFTA_CHAIN_HOOK], 1533 err = nla_parse_nested_deprecated(ha, NFTA_HOOK_MAX,
1530 nft_hook_policy, NULL); 1534 nla[NFTA_CHAIN_HOOK],
1535 nft_hook_policy, NULL);
1531 if (err < 0) 1536 if (err < 0)
1532 return err; 1537 return err;
1533 1538
@@ -1545,7 +1550,7 @@ static int nft_chain_parse_hook(struct net *net,
1545 if (IS_ERR(type)) 1550 if (IS_ERR(type))
1546 return PTR_ERR(type); 1551 return PTR_ERR(type);
1547 } 1552 }
1548 if (!(type->hook_mask & (1 << hook->num))) 1553 if (hook->num > NF_MAX_HOOKS || !(type->hook_mask & (1 << hook->num)))
1549 return -EOPNOTSUPP; 1554 return -EOPNOTSUPP;
1550 1555
1551 if (type->type == NFT_CHAIN_T_NAT && 1556 if (type->type == NFT_CHAIN_T_NAT &&
@@ -1615,6 +1620,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
1615 struct nft_base_chain *basechain; 1620 struct nft_base_chain *basechain;
1616 struct nft_stats __percpu *stats; 1621 struct nft_stats __percpu *stats;
1617 struct net *net = ctx->net; 1622 struct net *net = ctx->net;
1623 struct nft_trans *trans;
1618 struct nft_chain *chain; 1624 struct nft_chain *chain;
1619 struct nft_rule **rules; 1625 struct nft_rule **rules;
1620 int err; 1626 int err;
@@ -1662,7 +1668,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
1662 ops->dev = hook.dev; 1668 ops->dev = hook.dev;
1663 1669
1664 chain->flags |= NFT_BASE_CHAIN; 1670 chain->flags |= NFT_BASE_CHAIN;
1665 basechain->policy = policy; 1671 basechain->policy = NF_ACCEPT;
1666 } else { 1672 } else {
1667 chain = kzalloc(sizeof(*chain), GFP_KERNEL); 1673 chain = kzalloc(sizeof(*chain), GFP_KERNEL);
1668 if (chain == NULL) 1674 if (chain == NULL)
@@ -1698,13 +1704,18 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
1698 if (err) 1704 if (err)
1699 goto err2; 1705 goto err2;
1700 1706
1701 err = nft_trans_chain_add(ctx, NFT_MSG_NEWCHAIN); 1707 trans = nft_trans_chain_add(ctx, NFT_MSG_NEWCHAIN);
1702 if (err < 0) { 1708 if (IS_ERR(trans)) {
1709 err = PTR_ERR(trans);
1703 rhltable_remove(&table->chains_ht, &chain->rhlhead, 1710 rhltable_remove(&table->chains_ht, &chain->rhlhead,
1704 nft_chain_ht_params); 1711 nft_chain_ht_params);
1705 goto err2; 1712 goto err2;
1706 } 1713 }
1707 1714
1715 nft_trans_chain_policy(trans) = -1;
1716 if (nft_is_base_chain(chain))
1717 nft_trans_chain_policy(trans) = policy;
1718
1708 table->use++; 1719 table->use++;
1709 list_add_tail_rcu(&chain->list, &table->chains); 1720 list_add_tail_rcu(&chain->list, &table->chains);
1710 1721
@@ -2060,7 +2071,8 @@ static int nf_tables_fill_expr_info(struct sk_buff *skb,
2060 goto nla_put_failure; 2071 goto nla_put_failure;
2061 2072
2062 if (expr->ops->dump) { 2073 if (expr->ops->dump) {
2063 struct nlattr *data = nla_nest_start(skb, NFTA_EXPR_DATA); 2074 struct nlattr *data = nla_nest_start_noflag(skb,
2075 NFTA_EXPR_DATA);
2064 if (data == NULL) 2076 if (data == NULL)
2065 goto nla_put_failure; 2077 goto nla_put_failure;
2066 if (expr->ops->dump(skb, expr) < 0) 2078 if (expr->ops->dump(skb, expr) < 0)
@@ -2079,7 +2091,7 @@ int nft_expr_dump(struct sk_buff *skb, unsigned int attr,
2079{ 2091{
2080 struct nlattr *nest; 2092 struct nlattr *nest;
2081 2093
2082 nest = nla_nest_start(skb, attr); 2094 nest = nla_nest_start_noflag(skb, attr);
2083 if (!nest) 2095 if (!nest)
2084 goto nla_put_failure; 2096 goto nla_put_failure;
2085 if (nf_tables_fill_expr_info(skb, expr) < 0) 2097 if (nf_tables_fill_expr_info(skb, expr) < 0)
@@ -2105,7 +2117,8 @@ static int nf_tables_expr_parse(const struct nft_ctx *ctx,
2105 struct nlattr *tb[NFTA_EXPR_MAX + 1]; 2117 struct nlattr *tb[NFTA_EXPR_MAX + 1];
2106 int err; 2118 int err;
2107 2119
2108 err = nla_parse_nested(tb, NFTA_EXPR_MAX, nla, nft_expr_policy, NULL); 2120 err = nla_parse_nested_deprecated(tb, NFTA_EXPR_MAX, nla,
2121 nft_expr_policy, NULL);
2109 if (err < 0) 2122 if (err < 0)
2110 return err; 2123 return err;
2111 2124
@@ -2114,8 +2127,9 @@ static int nf_tables_expr_parse(const struct nft_ctx *ctx,
2114 return PTR_ERR(type); 2127 return PTR_ERR(type);
2115 2128
2116 if (tb[NFTA_EXPR_DATA]) { 2129 if (tb[NFTA_EXPR_DATA]) {
2117 err = nla_parse_nested(info->tb, type->maxattr, 2130 err = nla_parse_nested_deprecated(info->tb, type->maxattr,
2118 tb[NFTA_EXPR_DATA], type->policy, NULL); 2131 tb[NFTA_EXPR_DATA],
2132 type->policy, NULL);
2119 if (err < 0) 2133 if (err < 0)
2120 goto err1; 2134 goto err1;
2121 } else 2135 } else
@@ -2290,7 +2304,7 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net,
2290 goto nla_put_failure; 2304 goto nla_put_failure;
2291 } 2305 }
2292 2306
2293 list = nla_nest_start(skb, NFTA_RULE_EXPRESSIONS); 2307 list = nla_nest_start_noflag(skb, NFTA_RULE_EXPRESSIONS);
2294 if (list == NULL) 2308 if (list == NULL)
2295 goto nla_put_failure; 2309 goto nla_put_failure;
2296 nft_rule_for_each_expr(expr, next, rule) { 2310 nft_rule_for_each_expr(expr, next, rule) {
@@ -3194,9 +3208,7 @@ static int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result)
3194 3208
3195static __be64 nf_jiffies64_to_msecs(u64 input) 3209static __be64 nf_jiffies64_to_msecs(u64 input)
3196{ 3210{
3197 u64 ms = jiffies64_to_nsecs(input); 3211 return cpu_to_be64(jiffies64_to_msecs(input));
3198
3199 return cpu_to_be64(div_u64(ms, NSEC_PER_MSEC));
3200} 3212}
3201 3213
3202static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx, 3214static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
@@ -3261,7 +3273,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
3261 if (nla_put(skb, NFTA_SET_USERDATA, set->udlen, set->udata)) 3273 if (nla_put(skb, NFTA_SET_USERDATA, set->udlen, set->udata))
3262 goto nla_put_failure; 3274 goto nla_put_failure;
3263 3275
3264 desc = nla_nest_start(skb, NFTA_SET_DESC); 3276 desc = nla_nest_start_noflag(skb, NFTA_SET_DESC);
3265 if (desc == NULL) 3277 if (desc == NULL)
3266 goto nla_put_failure; 3278 goto nla_put_failure;
3267 if (set->size && 3279 if (set->size &&
@@ -3439,15 +3451,14 @@ err:
3439 return err; 3451 return err;
3440} 3452}
3441 3453
3442static int nf_tables_set_desc_parse(const struct nft_ctx *ctx, 3454static int nf_tables_set_desc_parse(struct nft_set_desc *desc,
3443 struct nft_set_desc *desc,
3444 const struct nlattr *nla) 3455 const struct nlattr *nla)
3445{ 3456{
3446 struct nlattr *da[NFTA_SET_DESC_MAX + 1]; 3457 struct nlattr *da[NFTA_SET_DESC_MAX + 1];
3447 int err; 3458 int err;
3448 3459
3449 err = nla_parse_nested(da, NFTA_SET_DESC_MAX, nla, 3460 err = nla_parse_nested_deprecated(da, NFTA_SET_DESC_MAX, nla,
3450 nft_set_desc_policy, NULL); 3461 nft_set_desc_policy, NULL);
3451 if (err < 0) 3462 if (err < 0)
3452 return err; 3463 return err;
3453 3464
@@ -3566,7 +3577,7 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
3566 policy = ntohl(nla_get_be32(nla[NFTA_SET_POLICY])); 3577 policy = ntohl(nla_get_be32(nla[NFTA_SET_POLICY]));
3567 3578
3568 if (nla[NFTA_SET_DESC] != NULL) { 3579 if (nla[NFTA_SET_DESC] != NULL) {
3569 err = nf_tables_set_desc_parse(&ctx, &desc, nla[NFTA_SET_DESC]); 3580 err = nf_tables_set_desc_parse(&desc, nla[NFTA_SET_DESC]);
3570 if (err < 0) 3581 if (err < 0)
3571 return err; 3582 return err;
3572 } 3583 }
@@ -3786,8 +3797,8 @@ bind:
3786} 3797}
3787EXPORT_SYMBOL_GPL(nf_tables_bind_set); 3798EXPORT_SYMBOL_GPL(nf_tables_bind_set);
3788 3799
3789void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, 3800static void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
3790 struct nft_set_binding *binding, bool event) 3801 struct nft_set_binding *binding, bool event)
3791{ 3802{
3792 list_del_rcu(&binding->list); 3803 list_del_rcu(&binding->list);
3793 3804
@@ -3798,7 +3809,6 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set,
3798 GFP_KERNEL); 3809 GFP_KERNEL);
3799 } 3810 }
3800} 3811}
3801EXPORT_SYMBOL_GPL(nf_tables_unbind_set);
3802 3812
3803void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set, 3813void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
3804 struct nft_set_binding *binding, 3814 struct nft_set_binding *binding,
@@ -3913,7 +3923,7 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,
3913 unsigned char *b = skb_tail_pointer(skb); 3923 unsigned char *b = skb_tail_pointer(skb);
3914 struct nlattr *nest; 3924 struct nlattr *nest;
3915 3925
3916 nest = nla_nest_start(skb, NFTA_LIST_ELEM); 3926 nest = nla_nest_start_noflag(skb, NFTA_LIST_ELEM);
3917 if (nest == NULL) 3927 if (nest == NULL)
3918 goto nla_put_failure; 3928 goto nla_put_failure;
3919 3929
@@ -4057,7 +4067,7 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
4057 if (nla_put_string(skb, NFTA_SET_ELEM_LIST_SET, set->name)) 4067 if (nla_put_string(skb, NFTA_SET_ELEM_LIST_SET, set->name))
4058 goto nla_put_failure; 4068 goto nla_put_failure;
4059 4069
4060 nest = nla_nest_start(skb, NFTA_SET_ELEM_LIST_ELEMENTS); 4070 nest = nla_nest_start_noflag(skb, NFTA_SET_ELEM_LIST_ELEMENTS);
4061 if (nest == NULL) 4071 if (nest == NULL)
4062 goto nla_put_failure; 4072 goto nla_put_failure;
4063 4073
@@ -4129,7 +4139,7 @@ static int nf_tables_fill_setelem_info(struct sk_buff *skb,
4129 if (nla_put_string(skb, NFTA_SET_NAME, set->name)) 4139 if (nla_put_string(skb, NFTA_SET_NAME, set->name))
4130 goto nla_put_failure; 4140 goto nla_put_failure;
4131 4141
4132 nest = nla_nest_start(skb, NFTA_SET_ELEM_LIST_ELEMENTS); 4142 nest = nla_nest_start_noflag(skb, NFTA_SET_ELEM_LIST_ELEMENTS);
4133 if (nest == NULL) 4143 if (nest == NULL)
4134 goto nla_put_failure; 4144 goto nla_put_failure;
4135 4145
@@ -4174,8 +4184,8 @@ static int nft_get_set_elem(struct nft_ctx *ctx, struct nft_set *set,
4174 void *priv; 4184 void *priv;
4175 int err; 4185 int err;
4176 4186
4177 err = nla_parse_nested(nla, NFTA_SET_ELEM_MAX, attr, 4187 err = nla_parse_nested_deprecated(nla, NFTA_SET_ELEM_MAX, attr,
4178 nft_set_elem_policy, NULL); 4188 nft_set_elem_policy, NULL);
4179 if (err < 0) 4189 if (err < 0)
4180 return err; 4190 return err;
4181 4191
@@ -4406,8 +4416,8 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
4406 u8 ulen; 4416 u8 ulen;
4407 int err; 4417 int err;
4408 4418
4409 err = nla_parse_nested(nla, NFTA_SET_ELEM_MAX, attr, 4419 err = nla_parse_nested_deprecated(nla, NFTA_SET_ELEM_MAX, attr,
4410 nft_set_elem_policy, NULL); 4420 nft_set_elem_policy, NULL);
4411 if (err < 0) 4421 if (err < 0)
4412 return err; 4422 return err;
4413 4423
@@ -4700,8 +4710,8 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set,
4700 void *priv; 4710 void *priv;
4701 int err; 4711 int err;
4702 4712
4703 err = nla_parse_nested(nla, NFTA_SET_ELEM_MAX, attr, 4713 err = nla_parse_nested_deprecated(nla, NFTA_SET_ELEM_MAX, attr,
4704 nft_set_elem_policy, NULL); 4714 nft_set_elem_policy, NULL);
4705 if (err < 0) 4715 if (err < 0)
4706 goto err1; 4716 goto err1;
4707 4717
@@ -4975,8 +4985,8 @@ static struct nft_object *nft_obj_init(const struct nft_ctx *ctx,
4975 goto err1; 4985 goto err1;
4976 4986
4977 if (attr) { 4987 if (attr) {
4978 err = nla_parse_nested(tb, type->maxattr, attr, type->policy, 4988 err = nla_parse_nested_deprecated(tb, type->maxattr, attr,
4979 NULL); 4989 type->policy, NULL);
4980 if (err < 0) 4990 if (err < 0)
4981 goto err2; 4991 goto err2;
4982 } else { 4992 } else {
@@ -5019,7 +5029,7 @@ static int nft_object_dump(struct sk_buff *skb, unsigned int attr,
5019{ 5029{
5020 struct nlattr *nest; 5030 struct nlattr *nest;
5021 5031
5022 nest = nla_nest_start(skb, attr); 5032 nest = nla_nest_start_noflag(skb, attr);
5023 if (!nest) 5033 if (!nest)
5024 goto nla_put_failure; 5034 goto nla_put_failure;
5025 if (obj->ops->dump(skb, obj, reset) < 0) 5035 if (obj->ops->dump(skb, obj, reset) < 0)
@@ -5552,8 +5562,8 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx,
5552 int hooknum, priority; 5562 int hooknum, priority;
5553 int err, n = 0, i; 5563 int err, n = 0, i;
5554 5564
5555 err = nla_parse_nested(tb, NFTA_FLOWTABLE_HOOK_MAX, attr, 5565 err = nla_parse_nested_deprecated(tb, NFTA_FLOWTABLE_HOOK_MAX, attr,
5556 nft_flowtable_hook_policy, NULL); 5566 nft_flowtable_hook_policy, NULL);
5557 if (err < 0) 5567 if (err < 0)
5558 return err; 5568 return err;
5559 5569
@@ -5836,14 +5846,14 @@ static int nf_tables_fill_flowtable_info(struct sk_buff *skb, struct net *net,
5836 NFTA_FLOWTABLE_PAD)) 5846 NFTA_FLOWTABLE_PAD))
5837 goto nla_put_failure; 5847 goto nla_put_failure;
5838 5848
5839 nest = nla_nest_start(skb, NFTA_FLOWTABLE_HOOK); 5849 nest = nla_nest_start_noflag(skb, NFTA_FLOWTABLE_HOOK);
5840 if (!nest) 5850 if (!nest)
5841 goto nla_put_failure; 5851 goto nla_put_failure;
5842 if (nla_put_be32(skb, NFTA_FLOWTABLE_HOOK_NUM, htonl(flowtable->hooknum)) || 5852 if (nla_put_be32(skb, NFTA_FLOWTABLE_HOOK_NUM, htonl(flowtable->hooknum)) ||
5843 nla_put_be32(skb, NFTA_FLOWTABLE_HOOK_PRIORITY, htonl(flowtable->priority))) 5853 nla_put_be32(skb, NFTA_FLOWTABLE_HOOK_PRIORITY, htonl(flowtable->priority)))
5844 goto nla_put_failure; 5854 goto nla_put_failure;
5845 5855
5846 nest_devs = nla_nest_start(skb, NFTA_FLOWTABLE_HOOK_DEVS); 5856 nest_devs = nla_nest_start_noflag(skb, NFTA_FLOWTABLE_HOOK_DEVS);
5847 if (!nest_devs) 5857 if (!nest_devs)
5848 goto nla_put_failure; 5858 goto nla_put_failure;
5849 5859
@@ -6311,6 +6321,27 @@ static int nf_tables_validate(struct net *net)
6311 return 0; 6321 return 0;
6312} 6322}
6313 6323
6324/* a drop policy has to be deferred until all rules have been activated,
6325 * otherwise a large ruleset that contains a drop-policy base chain will
6326 * cause all packets to get dropped until the full transaction has been
6327 * processed.
6328 *
6329 * We defer the drop policy until the transaction has been finalized.
6330 */
6331static void nft_chain_commit_drop_policy(struct nft_trans *trans)
6332{
6333 struct nft_base_chain *basechain;
6334
6335 if (nft_trans_chain_policy(trans) != NF_DROP)
6336 return;
6337
6338 if (!nft_is_base_chain(trans->ctx.chain))
6339 return;
6340
6341 basechain = nft_base_chain(trans->ctx.chain);
6342 basechain->policy = NF_DROP;
6343}
6344
6314static void nft_chain_commit_update(struct nft_trans *trans) 6345static void nft_chain_commit_update(struct nft_trans *trans)
6315{ 6346{
6316 struct nft_base_chain *basechain; 6347 struct nft_base_chain *basechain;
@@ -6632,6 +6663,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
6632 nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN); 6663 nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN);
6633 /* trans destroyed after rcu grace period */ 6664 /* trans destroyed after rcu grace period */
6634 } else { 6665 } else {
6666 nft_chain_commit_drop_policy(trans);
6635 nft_clear(net, trans->ctx.chain); 6667 nft_clear(net, trans->ctx.chain);
6636 nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN); 6668 nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN);
6637 nft_trans_destroy(trans); 6669 nft_trans_destroy(trans);
@@ -7210,8 +7242,8 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
7210 struct nft_chain *chain; 7242 struct nft_chain *chain;
7211 int err; 7243 int err;
7212 7244
7213 err = nla_parse_nested(tb, NFTA_VERDICT_MAX, nla, nft_verdict_policy, 7245 err = nla_parse_nested_deprecated(tb, NFTA_VERDICT_MAX, nla,
7214 NULL); 7246 nft_verdict_policy, NULL);
7215 if (err < 0) 7247 if (err < 0)
7216 return err; 7248 return err;
7217 7249
@@ -7269,7 +7301,7 @@ int nft_verdict_dump(struct sk_buff *skb, int type, const struct nft_verdict *v)
7269{ 7301{
7270 struct nlattr *nest; 7302 struct nlattr *nest;
7271 7303
7272 nest = nla_nest_start(skb, type); 7304 nest = nla_nest_start_noflag(skb, type);
7273 if (!nest) 7305 if (!nest)
7274 goto nla_put_failure; 7306 goto nla_put_failure;
7275 7307
@@ -7341,7 +7373,8 @@ int nft_data_init(const struct nft_ctx *ctx,
7341 struct nlattr *tb[NFTA_DATA_MAX + 1]; 7373 struct nlattr *tb[NFTA_DATA_MAX + 1];
7342 int err; 7374 int err;
7343 7375
7344 err = nla_parse_nested(tb, NFTA_DATA_MAX, nla, nft_data_policy, NULL); 7376 err = nla_parse_nested_deprecated(tb, NFTA_DATA_MAX, nla,
7377 nft_data_policy, NULL);
7345 if (err < 0) 7378 if (err < 0)
7346 return err; 7379 return err;
7347 7380
@@ -7382,7 +7415,7 @@ int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data,
7382 struct nlattr *nest; 7415 struct nlattr *nest;
7383 int err; 7416 int err;
7384 7417
7385 nest = nla_nest_start(skb, attr); 7418 nest = nla_nest_start_noflag(skb, attr);
7386 if (nest == NULL) 7419 if (nest == NULL)
7387 return -1; 7420 return -1;
7388 7421
@@ -7534,6 +7567,7 @@ static int __init nf_tables_module_init(void)
7534 if (err < 0) 7567 if (err < 0)
7535 goto err5; 7568 goto err5;
7536 7569
7570 nft_chain_route_init();
7537 return err; 7571 return err;
7538err5: 7572err5:
7539 rhltable_destroy(&nft_objname_ht); 7573 rhltable_destroy(&nft_objname_ht);
@@ -7553,6 +7587,7 @@ static void __exit nf_tables_module_exit(void)
7553 nfnetlink_subsys_unregister(&nf_tables_subsys); 7587 nfnetlink_subsys_unregister(&nf_tables_subsys);
7554 unregister_netdevice_notifier(&nf_tables_flowtable_notifier); 7588 unregister_netdevice_notifier(&nf_tables_flowtable_notifier);
7555 nft_chain_filter_fini(); 7589 nft_chain_filter_fini();
7590 nft_chain_route_fini();
7556 unregister_pernet_subsys(&nf_tables_net_ops); 7591 unregister_pernet_subsys(&nf_tables_net_ops);
7557 cancel_work_sync(&trans_destroy_work); 7592 cancel_work_sync(&trans_destroy_work);
7558 rcu_barrier(); 7593 rcu_barrier();
diff --git a/net/netfilter/nf_tables_set_core.c b/net/netfilter/nf_tables_set_core.c
index 814789644bd3..a9fce8d10051 100644
--- a/net/netfilter/nf_tables_set_core.c
+++ b/net/netfilter/nf_tables_set_core.c
@@ -1,4 +1,5 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/module.h>
2#include <net/netfilter/nf_tables_core.h> 3#include <net/netfilter/nf_tables_core.h>
3 4
4static int __init nf_tables_set_module_init(void) 5static int __init nf_tables_set_module_init(void)
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index 916913454624..92077d459109 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -206,8 +206,9 @@ replay:
206 return -ENOMEM; 206 return -ENOMEM;
207 } 207 }
208 208
209 err = nla_parse(cda, ss->cb[cb_id].attr_count, attr, attrlen, 209 err = nla_parse_deprecated(cda, ss->cb[cb_id].attr_count,
210 ss->cb[cb_id].policy, extack); 210 attr, attrlen,
211 ss->cb[cb_id].policy, extack);
211 if (err < 0) { 212 if (err < 0) {
212 rcu_read_unlock(); 213 rcu_read_unlock();
213 return err; 214 return err;
@@ -421,8 +422,10 @@ replay:
421 goto ack; 422 goto ack;
422 } 423 }
423 424
424 err = nla_parse(cda, ss->cb[cb_id].attr_count, attr, 425 err = nla_parse_deprecated(cda,
425 attrlen, ss->cb[cb_id].policy, NULL); 426 ss->cb[cb_id].attr_count,
427 attr, attrlen,
428 ss->cb[cb_id].policy, NULL);
426 if (err < 0) 429 if (err < 0)
427 goto ack; 430 goto ack;
428 431
@@ -520,8 +523,8 @@ static void nfnetlink_rcv_skb_batch(struct sk_buff *skb, struct nlmsghdr *nlh)
520 if (skb->len < NLMSG_HDRLEN + sizeof(struct nfgenmsg)) 523 if (skb->len < NLMSG_HDRLEN + sizeof(struct nfgenmsg))
521 return; 524 return;
522 525
523 err = nla_parse(cda, NFNL_BATCH_MAX, attr, attrlen, nfnl_batch_policy, 526 err = nla_parse_deprecated(cda, NFNL_BATCH_MAX, attr, attrlen,
524 NULL); 527 nfnl_batch_policy, NULL);
525 if (err < 0) { 528 if (err < 0) {
526 netlink_ack(skb, nlh, err, NULL); 529 netlink_ack(skb, nlh, err, NULL);
527 return; 530 return;
diff --git a/net/netfilter/nfnetlink_acct.c b/net/netfilter/nfnetlink_acct.c
index 8fa8bf7c48e6..02c877432d71 100644
--- a/net/netfilter/nfnetlink_acct.c
+++ b/net/netfilter/nfnetlink_acct.c
@@ -248,8 +248,8 @@ static int nfnl_acct_start(struct netlink_callback *cb)
248 if (!attr) 248 if (!attr)
249 return 0; 249 return 0;
250 250
251 err = nla_parse_nested(tb, NFACCT_FILTER_MAX, attr, filter_policy, 251 err = nla_parse_nested_deprecated(tb, NFACCT_FILTER_MAX, attr,
252 NULL); 252 filter_policy, NULL);
253 if (err < 0) 253 if (err < 0)
254 return err; 254 return err;
255 255
diff --git a/net/netfilter/nfnetlink_cthelper.c b/net/netfilter/nfnetlink_cthelper.c
index e5d27b2e4eba..17eb473a626b 100644
--- a/net/netfilter/nfnetlink_cthelper.c
+++ b/net/netfilter/nfnetlink_cthelper.c
@@ -78,8 +78,8 @@ nfnl_cthelper_parse_tuple(struct nf_conntrack_tuple *tuple,
78 int err; 78 int err;
79 struct nlattr *tb[NFCTH_TUPLE_MAX+1]; 79 struct nlattr *tb[NFCTH_TUPLE_MAX+1];
80 80
81 err = nla_parse_nested(tb, NFCTH_TUPLE_MAX, attr, 81 err = nla_parse_nested_deprecated(tb, NFCTH_TUPLE_MAX, attr,
82 nfnl_cthelper_tuple_pol, NULL); 82 nfnl_cthelper_tuple_pol, NULL);
83 if (err < 0) 83 if (err < 0)
84 return err; 84 return err;
85 85
@@ -139,8 +139,8 @@ nfnl_cthelper_expect_policy(struct nf_conntrack_expect_policy *expect_policy,
139 int err; 139 int err;
140 struct nlattr *tb[NFCTH_POLICY_MAX+1]; 140 struct nlattr *tb[NFCTH_POLICY_MAX+1];
141 141
142 err = nla_parse_nested(tb, NFCTH_POLICY_MAX, attr, 142 err = nla_parse_nested_deprecated(tb, NFCTH_POLICY_MAX, attr,
143 nfnl_cthelper_expect_pol, NULL); 143 nfnl_cthelper_expect_pol, NULL);
144 if (err < 0) 144 if (err < 0)
145 return err; 145 return err;
146 146
@@ -176,8 +176,9 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper,
176 struct nlattr *tb[NFCTH_POLICY_SET_MAX+1]; 176 struct nlattr *tb[NFCTH_POLICY_SET_MAX+1];
177 unsigned int class_max; 177 unsigned int class_max;
178 178
179 ret = nla_parse_nested(tb, NFCTH_POLICY_SET_MAX, attr, 179 ret = nla_parse_nested_deprecated(tb, NFCTH_POLICY_SET_MAX, attr,
180 nfnl_cthelper_expect_policy_set, NULL); 180 nfnl_cthelper_expect_policy_set,
181 NULL);
181 if (ret < 0) 182 if (ret < 0)
182 return ret; 183 return ret;
183 184
@@ -289,8 +290,8 @@ nfnl_cthelper_update_policy_one(const struct nf_conntrack_expect_policy *policy,
289 struct nlattr *tb[NFCTH_POLICY_MAX + 1]; 290 struct nlattr *tb[NFCTH_POLICY_MAX + 1];
290 int err; 291 int err;
291 292
292 err = nla_parse_nested(tb, NFCTH_POLICY_MAX, attr, 293 err = nla_parse_nested_deprecated(tb, NFCTH_POLICY_MAX, attr,
293 nfnl_cthelper_expect_pol, NULL); 294 nfnl_cthelper_expect_pol, NULL);
294 if (err < 0) 295 if (err < 0)
295 return err; 296 return err;
296 297
@@ -361,8 +362,9 @@ static int nfnl_cthelper_update_policy(struct nf_conntrack_helper *helper,
361 unsigned int class_max; 362 unsigned int class_max;
362 int err; 363 int err;
363 364
364 err = nla_parse_nested(tb, NFCTH_POLICY_SET_MAX, attr, 365 err = nla_parse_nested_deprecated(tb, NFCTH_POLICY_SET_MAX, attr,
365 nfnl_cthelper_expect_policy_set, NULL); 366 nfnl_cthelper_expect_policy_set,
367 NULL);
366 if (err < 0) 368 if (err < 0)
367 return err; 369 return err;
368 370
@@ -462,7 +464,7 @@ nfnl_cthelper_dump_tuple(struct sk_buff *skb,
462{ 464{
463 struct nlattr *nest_parms; 465 struct nlattr *nest_parms;
464 466
465 nest_parms = nla_nest_start(skb, NFCTH_TUPLE | NLA_F_NESTED); 467 nest_parms = nla_nest_start(skb, NFCTH_TUPLE);
466 if (nest_parms == NULL) 468 if (nest_parms == NULL)
467 goto nla_put_failure; 469 goto nla_put_failure;
468 470
@@ -487,7 +489,7 @@ nfnl_cthelper_dump_policy(struct sk_buff *skb,
487 int i; 489 int i;
488 struct nlattr *nest_parms1, *nest_parms2; 490 struct nlattr *nest_parms1, *nest_parms2;
489 491
490 nest_parms1 = nla_nest_start(skb, NFCTH_POLICY | NLA_F_NESTED); 492 nest_parms1 = nla_nest_start(skb, NFCTH_POLICY);
491 if (nest_parms1 == NULL) 493 if (nest_parms1 == NULL)
492 goto nla_put_failure; 494 goto nla_put_failure;
493 495
@@ -496,8 +498,7 @@ nfnl_cthelper_dump_policy(struct sk_buff *skb,
496 goto nla_put_failure; 498 goto nla_put_failure;
497 499
498 for (i = 0; i < helper->expect_class_max + 1; i++) { 500 for (i = 0; i < helper->expect_class_max + 1; i++) {
499 nest_parms2 = nla_nest_start(skb, 501 nest_parms2 = nla_nest_start(skb, (NFCTH_POLICY_SET + i));
500 (NFCTH_POLICY_SET+i) | NLA_F_NESTED);
501 if (nest_parms2 == NULL) 502 if (nest_parms2 == NULL)
502 goto nla_put_failure; 503 goto nla_put_failure;
503 504
diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c
index c69b11ca5aad..427b411c5739 100644
--- a/net/netfilter/nfnetlink_cttimeout.c
+++ b/net/netfilter/nfnetlink_cttimeout.c
@@ -59,8 +59,11 @@ ctnl_timeout_parse_policy(void *timeout,
59 if (!tb) 59 if (!tb)
60 return -ENOMEM; 60 return -ENOMEM;
61 61
62 ret = nla_parse_nested(tb, l4proto->ctnl_timeout.nlattr_max, attr, 62 ret = nla_parse_nested_deprecated(tb,
63 l4proto->ctnl_timeout.nla_policy, NULL); 63 l4proto->ctnl_timeout.nlattr_max,
64 attr,
65 l4proto->ctnl_timeout.nla_policy,
66 NULL);
64 if (ret < 0) 67 if (ret < 0)
65 goto err; 68 goto err;
66 69
@@ -184,7 +187,7 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
184 htonl(refcount_read(&timeout->refcnt)))) 187 htonl(refcount_read(&timeout->refcnt))))
185 goto nla_put_failure; 188 goto nla_put_failure;
186 189
187 nest_parms = nla_nest_start(skb, CTA_TIMEOUT_DATA | NLA_F_NESTED); 190 nest_parms = nla_nest_start(skb, CTA_TIMEOUT_DATA);
188 if (!nest_parms) 191 if (!nest_parms)
189 goto nla_put_failure; 192 goto nla_put_failure;
190 193
@@ -401,7 +404,7 @@ cttimeout_default_fill_info(struct net *net, struct sk_buff *skb, u32 portid,
401 nla_put_u8(skb, CTA_TIMEOUT_L4PROTO, l4proto->l4proto)) 404 nla_put_u8(skb, CTA_TIMEOUT_L4PROTO, l4proto->l4proto))
402 goto nla_put_failure; 405 goto nla_put_failure;
403 406
404 nest_parms = nla_nest_start(skb, CTA_TIMEOUT_DATA | NLA_F_NESTED); 407 nest_parms = nla_nest_start(skb, CTA_TIMEOUT_DATA);
405 if (!nest_parms) 408 if (!nest_parms)
406 goto nla_put_failure; 409 goto nla_put_failure;
407 410
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index b1f9c5303f02..0b3347570265 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -540,7 +540,7 @@ __build_packet_message(struct nfnl_log_net *log,
540 goto nla_put_failure; 540 goto nla_put_failure;
541 } 541 }
542 542
543 if (skb->tstamp) { 543 if (hooknum <= NF_INET_FORWARD && skb->tstamp) {
544 struct nfulnl_msg_packet_timestamp ts; 544 struct nfulnl_msg_packet_timestamp ts;
545 struct timespec64 kts = ktime_to_timespec64(skb->tstamp); 545 struct timespec64 kts = ktime_to_timespec64(skb->tstamp);
546 ts.sec = cpu_to_be64(kts.tv_sec); 546 ts.sec = cpu_to_be64(kts.tv_sec);
diff --git a/net/netfilter/nfnetlink_osf.c b/net/netfilter/nfnetlink_osf.c
index 1f1d90c1716b..7b827bcb412c 100644
--- a/net/netfilter/nfnetlink_osf.c
+++ b/net/netfilter/nfnetlink_osf.c
@@ -255,9 +255,9 @@ nf_osf_match(const struct sk_buff *skb, u_int8_t family,
255} 255}
256EXPORT_SYMBOL_GPL(nf_osf_match); 256EXPORT_SYMBOL_GPL(nf_osf_match);
257 257
258const char *nf_osf_find(const struct sk_buff *skb, 258bool nf_osf_find(const struct sk_buff *skb,
259 const struct list_head *nf_osf_fingers, 259 const struct list_head *nf_osf_fingers,
260 const int ttl_check) 260 const int ttl_check, struct nf_osf_data *data)
261{ 261{
262 const struct iphdr *ip = ip_hdr(skb); 262 const struct iphdr *ip = ip_hdr(skb);
263 const struct nf_osf_user_finger *f; 263 const struct nf_osf_user_finger *f;
@@ -265,24 +265,24 @@ const char *nf_osf_find(const struct sk_buff *skb,
265 const struct nf_osf_finger *kf; 265 const struct nf_osf_finger *kf;
266 struct nf_osf_hdr_ctx ctx; 266 struct nf_osf_hdr_ctx ctx;
267 const struct tcphdr *tcp; 267 const struct tcphdr *tcp;
268 const char *genre = NULL;
269 268
270 memset(&ctx, 0, sizeof(ctx)); 269 memset(&ctx, 0, sizeof(ctx));
271 270
272 tcp = nf_osf_hdr_ctx_init(&ctx, skb, ip, opts); 271 tcp = nf_osf_hdr_ctx_init(&ctx, skb, ip, opts);
273 if (!tcp) 272 if (!tcp)
274 return NULL; 273 return false;
275 274
276 list_for_each_entry_rcu(kf, &nf_osf_fingers[ctx.df], finger_entry) { 275 list_for_each_entry_rcu(kf, &nf_osf_fingers[ctx.df], finger_entry) {
277 f = &kf->finger; 276 f = &kf->finger;
278 if (!nf_osf_match_one(skb, f, ttl_check, &ctx)) 277 if (!nf_osf_match_one(skb, f, ttl_check, &ctx))
279 continue; 278 continue;
280 279
281 genre = f->genre; 280 data->genre = f->genre;
281 data->version = f->version;
282 break; 282 break;
283 } 283 }
284 284
285 return genre; 285 return true;
286} 286}
287EXPORT_SYMBOL_GPL(nf_osf_find); 287EXPORT_SYMBOL_GPL(nf_osf_find);
288 288
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 0dcc3592d053..27dac47b29c2 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -351,7 +351,7 @@ static int nfqnl_put_bridge(struct nf_queue_entry *entry, struct sk_buff *skb)
351 if (skb_vlan_tag_present(entskb)) { 351 if (skb_vlan_tag_present(entskb)) {
352 struct nlattr *nest; 352 struct nlattr *nest;
353 353
354 nest = nla_nest_start(skb, NFQA_VLAN | NLA_F_NESTED); 354 nest = nla_nest_start(skb, NFQA_VLAN);
355 if (!nest) 355 if (!nest)
356 goto nla_put_failure; 356 goto nla_put_failure;
357 357
@@ -582,7 +582,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
582 if (nfqnl_put_bridge(entry, skb) < 0) 582 if (nfqnl_put_bridge(entry, skb) < 0)
583 goto nla_put_failure; 583 goto nla_put_failure;
584 584
585 if (entskb->tstamp) { 585 if (entry->state.hook <= NF_INET_FORWARD && entskb->tstamp) {
586 struct nfqnl_msg_packet_timestamp ts; 586 struct nfqnl_msg_packet_timestamp ts;
587 struct timespec64 kts = ktime_to_timespec64(entskb->tstamp); 587 struct timespec64 kts = ktime_to_timespec64(entskb->tstamp);
588 588
@@ -1139,8 +1139,9 @@ static int nfqa_parse_bridge(struct nf_queue_entry *entry,
1139 struct nlattr *tb[NFQA_VLAN_MAX + 1]; 1139 struct nlattr *tb[NFQA_VLAN_MAX + 1];
1140 int err; 1140 int err;
1141 1141
1142 err = nla_parse_nested(tb, NFQA_VLAN_MAX, nfqa[NFQA_VLAN], 1142 err = nla_parse_nested_deprecated(tb, NFQA_VLAN_MAX,
1143 nfqa_vlan_policy, NULL); 1143 nfqa[NFQA_VLAN],
1144 nfqa_vlan_policy, NULL);
1144 if (err < 0) 1145 if (err < 0)
1145 return err; 1146 return err;
1146 1147
diff --git a/net/netfilter/nft_chain_nat.c b/net/netfilter/nft_chain_nat.c
index ee4852088d50..2f89bde3c61c 100644
--- a/net/netfilter/nft_chain_nat.c
+++ b/net/netfilter/nft_chain_nat.c
@@ -74,6 +74,36 @@ static const struct nft_chain_type nft_chain_nat_ipv6 = {
74}; 74};
75#endif 75#endif
76 76
77#ifdef CONFIG_NF_TABLES_INET
78static int nft_nat_inet_reg(struct net *net, const struct nf_hook_ops *ops)
79{
80 return nf_nat_inet_register_fn(net, ops);
81}
82
83static void nft_nat_inet_unreg(struct net *net, const struct nf_hook_ops *ops)
84{
85 nf_nat_inet_unregister_fn(net, ops);
86}
87
88static const struct nft_chain_type nft_chain_nat_inet = {
89 .name = "nat",
90 .type = NFT_CHAIN_T_NAT,
91 .family = NFPROTO_INET,
92 .hook_mask = (1 << NF_INET_PRE_ROUTING) |
93 (1 << NF_INET_LOCAL_IN) |
94 (1 << NF_INET_LOCAL_OUT) |
95 (1 << NF_INET_POST_ROUTING),
96 .hooks = {
97 [NF_INET_PRE_ROUTING] = nft_nat_do_chain,
98 [NF_INET_LOCAL_IN] = nft_nat_do_chain,
99 [NF_INET_LOCAL_OUT] = nft_nat_do_chain,
100 [NF_INET_POST_ROUTING] = nft_nat_do_chain,
101 },
102 .ops_register = nft_nat_inet_reg,
103 .ops_unregister = nft_nat_inet_unreg,
104};
105#endif
106
77static int __init nft_chain_nat_init(void) 107static int __init nft_chain_nat_init(void)
78{ 108{
79#ifdef CONFIG_NF_TABLES_IPV6 109#ifdef CONFIG_NF_TABLES_IPV6
@@ -82,6 +112,9 @@ static int __init nft_chain_nat_init(void)
82#ifdef CONFIG_NF_TABLES_IPV4 112#ifdef CONFIG_NF_TABLES_IPV4
83 nft_register_chain_type(&nft_chain_nat_ipv4); 113 nft_register_chain_type(&nft_chain_nat_ipv4);
84#endif 114#endif
115#ifdef CONFIG_NF_TABLES_INET
116 nft_register_chain_type(&nft_chain_nat_inet);
117#endif
85 118
86 return 0; 119 return 0;
87} 120}
@@ -94,6 +127,9 @@ static void __exit nft_chain_nat_exit(void)
94#ifdef CONFIG_NF_TABLES_IPV6 127#ifdef CONFIG_NF_TABLES_IPV6
95 nft_unregister_chain_type(&nft_chain_nat_ipv6); 128 nft_unregister_chain_type(&nft_chain_nat_ipv6);
96#endif 129#endif
130#ifdef CONFIG_NF_TABLES_INET
131 nft_unregister_chain_type(&nft_chain_nat_inet);
132#endif
97} 133}
98 134
99module_init(nft_chain_nat_init); 135module_init(nft_chain_nat_init);
diff --git a/net/netfilter/nft_chain_route.c b/net/netfilter/nft_chain_route.c
new file mode 100644
index 000000000000..8826bbe71136
--- /dev/null
+++ b/net/netfilter/nft_chain_route.c
@@ -0,0 +1,169 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/skbuff.h>
4#include <linux/netfilter.h>
5#include <linux/netfilter_ipv4.h>
6#include <linux/netfilter_ipv6.h>
7#include <linux/netfilter/nfnetlink.h>
8#include <linux/netfilter/nf_tables.h>
9#include <net/netfilter/nf_tables.h>
10#include <net/netfilter/nf_tables_ipv4.h>
11#include <net/netfilter/nf_tables_ipv6.h>
12#include <net/route.h>
13#include <net/ip.h>
14
15#ifdef CONFIG_NF_TABLES_IPV4
16static unsigned int nf_route_table_hook4(void *priv,
17 struct sk_buff *skb,
18 const struct nf_hook_state *state)
19{
20 const struct iphdr *iph;
21 struct nft_pktinfo pkt;
22 __be32 saddr, daddr;
23 unsigned int ret;
24 u32 mark;
25 int err;
26 u8 tos;
27
28 nft_set_pktinfo(&pkt, skb, state);
29 nft_set_pktinfo_ipv4(&pkt, skb);
30
31 mark = skb->mark;
32 iph = ip_hdr(skb);
33 saddr = iph->saddr;
34 daddr = iph->daddr;
35 tos = iph->tos;
36
37 ret = nft_do_chain(&pkt, priv);
38 if (ret == NF_ACCEPT) {
39 iph = ip_hdr(skb);
40
41 if (iph->saddr != saddr ||
42 iph->daddr != daddr ||
43 skb->mark != mark ||
44 iph->tos != tos) {
45 err = ip_route_me_harder(state->net, skb, RTN_UNSPEC);
46 if (err < 0)
47 ret = NF_DROP_ERR(err);
48 }
49 }
50 return ret;
51}
52
53static const struct nft_chain_type nft_chain_route_ipv4 = {
54 .name = "route",
55 .type = NFT_CHAIN_T_ROUTE,
56 .family = NFPROTO_IPV4,
57 .hook_mask = (1 << NF_INET_LOCAL_OUT),
58 .hooks = {
59 [NF_INET_LOCAL_OUT] = nf_route_table_hook4,
60 },
61};
62#endif
63
64#ifdef CONFIG_NF_TABLES_IPV6
65static unsigned int nf_route_table_hook6(void *priv,
66 struct sk_buff *skb,
67 const struct nf_hook_state *state)
68{
69 struct in6_addr saddr, daddr;
70 struct nft_pktinfo pkt;
71 u32 mark, flowlabel;
72 unsigned int ret;
73 u8 hop_limit;
74 int err;
75
76 nft_set_pktinfo(&pkt, skb, state);
77 nft_set_pktinfo_ipv6(&pkt, skb);
78
79 /* save source/dest address, mark, hoplimit, flowlabel, priority */
80 memcpy(&saddr, &ipv6_hdr(skb)->saddr, sizeof(saddr));
81 memcpy(&daddr, &ipv6_hdr(skb)->daddr, sizeof(daddr));
82 mark = skb->mark;
83 hop_limit = ipv6_hdr(skb)->hop_limit;
84
85 /* flowlabel and prio (includes version, which shouldn't change either)*/
86 flowlabel = *((u32 *)ipv6_hdr(skb));
87
88 ret = nft_do_chain(&pkt, priv);
89 if (ret == NF_ACCEPT &&
90 (memcmp(&ipv6_hdr(skb)->saddr, &saddr, sizeof(saddr)) ||
91 memcmp(&ipv6_hdr(skb)->daddr, &daddr, sizeof(daddr)) ||
92 skb->mark != mark ||
93 ipv6_hdr(skb)->hop_limit != hop_limit ||
94 flowlabel != *((u32 *)ipv6_hdr(skb)))) {
95 err = nf_ip6_route_me_harder(state->net, skb);
96 if (err < 0)
97 ret = NF_DROP_ERR(err);
98 }
99
100 return ret;
101}
102
103static const struct nft_chain_type nft_chain_route_ipv6 = {
104 .name = "route",
105 .type = NFT_CHAIN_T_ROUTE,
106 .family = NFPROTO_IPV6,
107 .hook_mask = (1 << NF_INET_LOCAL_OUT),
108 .hooks = {
109 [NF_INET_LOCAL_OUT] = nf_route_table_hook6,
110 },
111};
112#endif
113
114#ifdef CONFIG_NF_TABLES_INET
115static unsigned int nf_route_table_inet(void *priv,
116 struct sk_buff *skb,
117 const struct nf_hook_state *state)
118{
119 struct nft_pktinfo pkt;
120
121 switch (state->pf) {
122 case NFPROTO_IPV4:
123 return nf_route_table_hook4(priv, skb, state);
124 case NFPROTO_IPV6:
125 return nf_route_table_hook6(priv, skb, state);
126 default:
127 nft_set_pktinfo(&pkt, skb, state);
128 break;
129 }
130
131 return nft_do_chain(&pkt, priv);
132}
133
134static const struct nft_chain_type nft_chain_route_inet = {
135 .name = "route",
136 .type = NFT_CHAIN_T_ROUTE,
137 .family = NFPROTO_INET,
138 .hook_mask = (1 << NF_INET_LOCAL_OUT),
139 .hooks = {
140 [NF_INET_LOCAL_OUT] = nf_route_table_inet,
141 },
142};
143#endif
144
145void __init nft_chain_route_init(void)
146{
147#ifdef CONFIG_NF_TABLES_IPV6
148 nft_register_chain_type(&nft_chain_route_ipv6);
149#endif
150#ifdef CONFIG_NF_TABLES_IPV4
151 nft_register_chain_type(&nft_chain_route_ipv4);
152#endif
153#ifdef CONFIG_NF_TABLES_INET
154 nft_register_chain_type(&nft_chain_route_inet);
155#endif
156}
157
158void __exit nft_chain_route_fini(void)
159{
160#ifdef CONFIG_NF_TABLES_IPV6
161 nft_unregister_chain_type(&nft_chain_route_ipv6);
162#endif
163#ifdef CONFIG_NF_TABLES_IPV4
164 nft_unregister_chain_type(&nft_chain_route_ipv4);
165#endif
166#ifdef CONFIG_NF_TABLES_INET
167 nft_unregister_chain_type(&nft_chain_route_inet);
168#endif
169}
diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
index 469f9da5073b..276f1f2d6de1 100644
--- a/net/netfilter/nft_compat.c
+++ b/net/netfilter/nft_compat.c
@@ -198,8 +198,8 @@ static int nft_parse_compat(const struct nlattr *attr, u16 *proto, bool *inv)
198 u32 flags; 198 u32 flags;
199 int err; 199 int err;
200 200
201 err = nla_parse_nested(tb, NFTA_RULE_COMPAT_MAX, attr, 201 err = nla_parse_nested_deprecated(tb, NFTA_RULE_COMPAT_MAX, attr,
202 nft_rule_compat_policy, NULL); 202 nft_rule_compat_policy, NULL);
203 if (err < 0) 203 if (err < 0)
204 return err; 204 return err;
205 205
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index 7b717fad6cdc..f043936763f3 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -178,6 +178,11 @@ static void nft_ct_get_eval(const struct nft_expr *expr,
178 return; 178 return;
179 } 179 }
180#endif 180#endif
181 case NFT_CT_ID:
182 if (!nf_ct_is_confirmed(ct))
183 goto err;
184 *dest = nf_ct_get_id(ct);
185 return;
181 default: 186 default:
182 break; 187 break;
183 } 188 }
@@ -479,6 +484,9 @@ static int nft_ct_get_init(const struct nft_ctx *ctx,
479 len = sizeof(u16); 484 len = sizeof(u16);
480 break; 485 break;
481#endif 486#endif
487 case NFT_CT_ID:
488 len = sizeof(u32);
489 break;
482 default: 490 default:
483 return -EOPNOTSUPP; 491 return -EOPNOTSUPP;
484 } 492 }
@@ -797,9 +805,11 @@ nft_ct_timeout_parse_policy(void *timeouts,
797 if (!tb) 805 if (!tb)
798 return -ENOMEM; 806 return -ENOMEM;
799 807
800 ret = nla_parse_nested(tb, l4proto->ctnl_timeout.nlattr_max, 808 ret = nla_parse_nested_deprecated(tb,
801 attr, l4proto->ctnl_timeout.nla_policy, 809 l4proto->ctnl_timeout.nlattr_max,
802 NULL); 810 attr,
811 l4proto->ctnl_timeout.nla_policy,
812 NULL);
803 if (ret < 0) 813 if (ret < 0)
804 goto err; 814 goto err;
805 815
@@ -928,7 +938,7 @@ static int nft_ct_timeout_obj_dump(struct sk_buff *skb,
928 nla_put_be16(skb, NFTA_CT_TIMEOUT_L3PROTO, htons(timeout->l3num))) 938 nla_put_be16(skb, NFTA_CT_TIMEOUT_L3PROTO, htons(timeout->l3num)))
929 return -1; 939 return -1;
930 940
931 nest_params = nla_nest_start(skb, NFTA_CT_TIMEOUT_DATA | NLA_F_NESTED); 941 nest_params = nla_nest_start(skb, NFTA_CT_TIMEOUT_DATA);
932 if (!nest_params) 942 if (!nest_params)
933 return -1; 943 return -1;
934 944
diff --git a/net/netfilter/nft_dynset.c b/net/netfilter/nft_dynset.c
index e461007558e8..8394560aa695 100644
--- a/net/netfilter/nft_dynset.c
+++ b/net/netfilter/nft_dynset.c
@@ -28,6 +28,23 @@ struct nft_dynset {
28 struct nft_set_binding binding; 28 struct nft_set_binding binding;
29}; 29};
30 30
31static int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src)
32{
33 int err;
34
35 if (src->ops->clone) {
36 dst->ops = src->ops;
37 err = src->ops->clone(dst, src);
38 if (err < 0)
39 return err;
40 } else {
41 memcpy(dst, src, src->ops->size);
42 }
43
44 __module_get(src->ops->type->owner);
45 return 0;
46}
47
31static void *nft_dynset_new(struct nft_set *set, const struct nft_expr *expr, 48static void *nft_dynset_new(struct nft_set *set, const struct nft_expr *expr,
32 struct nft_regs *regs) 49 struct nft_regs *regs)
33{ 50{
diff --git a/net/netfilter/nft_flow_offload.c b/net/netfilter/nft_flow_offload.c
index 6e6b9adf7d38..69d7a8439c7a 100644
--- a/net/netfilter/nft_flow_offload.c
+++ b/net/netfilter/nft_flow_offload.c
@@ -94,8 +94,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
94 if (help) 94 if (help)
95 goto out; 95 goto out;
96 96
97 if (ctinfo == IP_CT_NEW || 97 if (!nf_ct_is_confirmed(ct))
98 ctinfo == IP_CT_RELATED)
99 goto out; 98 goto out;
100 99
101 if (test_and_set_bit(IPS_OFFLOAD_BIT, &ct->status)) 100 if (test_and_set_bit(IPS_OFFLOAD_BIT, &ct->status))
@@ -113,6 +112,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
113 if (ret < 0) 112 if (ret < 0)
114 goto err_flow_add; 113 goto err_flow_add;
115 114
115 dst_release(route.tuple[!dir].dst);
116 return; 116 return;
117 117
118err_flow_add: 118err_flow_add:
diff --git a/net/netfilter/nft_masq.c b/net/netfilter/nft_masq.c
index bee156eaa400..86fd90085eaf 100644
--- a/net/netfilter/nft_masq.c
+++ b/net/netfilter/nft_masq.c
@@ -14,8 +14,7 @@
14#include <linux/netfilter/nf_tables.h> 14#include <linux/netfilter/nf_tables.h>
15#include <net/netfilter/nf_tables.h> 15#include <net/netfilter/nf_tables.h>
16#include <net/netfilter/nf_nat.h> 16#include <net/netfilter/nf_nat.h>
17#include <net/netfilter/ipv4/nf_nat_masquerade.h> 17#include <net/netfilter/nf_nat_masquerade.h>
18#include <net/netfilter/ipv6/nf_nat_masquerade.h>
19 18
20struct nft_masq { 19struct nft_masq {
21 u32 flags; 20 u32 flags;
@@ -196,28 +195,73 @@ static struct nft_expr_type nft_masq_ipv6_type __read_mostly = {
196 195
197static int __init nft_masq_module_init_ipv6(void) 196static int __init nft_masq_module_init_ipv6(void)
198{ 197{
199 int ret = nft_register_expr(&nft_masq_ipv6_type); 198 return nft_register_expr(&nft_masq_ipv6_type);
200
201 if (ret)
202 return ret;
203
204 ret = nf_nat_masquerade_ipv6_register_notifier();
205 if (ret < 0)
206 nft_unregister_expr(&nft_masq_ipv6_type);
207
208 return ret;
209} 199}
210 200
211static void nft_masq_module_exit_ipv6(void) 201static void nft_masq_module_exit_ipv6(void)
212{ 202{
213 nft_unregister_expr(&nft_masq_ipv6_type); 203 nft_unregister_expr(&nft_masq_ipv6_type);
214 nf_nat_masquerade_ipv6_unregister_notifier();
215} 204}
216#else 205#else
217static inline int nft_masq_module_init_ipv6(void) { return 0; } 206static inline int nft_masq_module_init_ipv6(void) { return 0; }
218static inline void nft_masq_module_exit_ipv6(void) {} 207static inline void nft_masq_module_exit_ipv6(void) {}
219#endif 208#endif
220 209
210#ifdef CONFIG_NF_TABLES_INET
211static void nft_masq_inet_eval(const struct nft_expr *expr,
212 struct nft_regs *regs,
213 const struct nft_pktinfo *pkt)
214{
215 switch (nft_pf(pkt)) {
216 case NFPROTO_IPV4:
217 return nft_masq_ipv4_eval(expr, regs, pkt);
218 case NFPROTO_IPV6:
219 return nft_masq_ipv6_eval(expr, regs, pkt);
220 }
221
222 WARN_ON_ONCE(1);
223}
224
225static void
226nft_masq_inet_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
227{
228 nf_ct_netns_put(ctx->net, NFPROTO_INET);
229}
230
231static struct nft_expr_type nft_masq_inet_type;
232static const struct nft_expr_ops nft_masq_inet_ops = {
233 .type = &nft_masq_inet_type,
234 .size = NFT_EXPR_SIZE(sizeof(struct nft_masq)),
235 .eval = nft_masq_inet_eval,
236 .init = nft_masq_init,
237 .destroy = nft_masq_inet_destroy,
238 .dump = nft_masq_dump,
239 .validate = nft_masq_validate,
240};
241
242static struct nft_expr_type nft_masq_inet_type __read_mostly = {
243 .family = NFPROTO_INET,
244 .name = "masq",
245 .ops = &nft_masq_inet_ops,
246 .policy = nft_masq_policy,
247 .maxattr = NFTA_MASQ_MAX,
248 .owner = THIS_MODULE,
249};
250
251static int __init nft_masq_module_init_inet(void)
252{
253 return nft_register_expr(&nft_masq_inet_type);
254}
255
256static void nft_masq_module_exit_inet(void)
257{
258 nft_unregister_expr(&nft_masq_inet_type);
259}
260#else
261static inline int nft_masq_module_init_inet(void) { return 0; }
262static inline void nft_masq_module_exit_inet(void) {}
263#endif
264
221static int __init nft_masq_module_init(void) 265static int __init nft_masq_module_init(void)
222{ 266{
223 int ret; 267 int ret;
@@ -226,15 +270,23 @@ static int __init nft_masq_module_init(void)
226 if (ret < 0) 270 if (ret < 0)
227 return ret; 271 return ret;
228 272
273 ret = nft_masq_module_init_inet();
274 if (ret < 0) {
275 nft_masq_module_exit_ipv6();
276 return ret;
277 }
278
229 ret = nft_register_expr(&nft_masq_ipv4_type); 279 ret = nft_register_expr(&nft_masq_ipv4_type);
230 if (ret < 0) { 280 if (ret < 0) {
281 nft_masq_module_exit_inet();
231 nft_masq_module_exit_ipv6(); 282 nft_masq_module_exit_ipv6();
232 return ret; 283 return ret;
233 } 284 }
234 285
235 ret = nf_nat_masquerade_ipv4_register_notifier(); 286 ret = nf_nat_masquerade_inet_register_notifiers();
236 if (ret < 0) { 287 if (ret < 0) {
237 nft_masq_module_exit_ipv6(); 288 nft_masq_module_exit_ipv6();
289 nft_masq_module_exit_inet();
238 nft_unregister_expr(&nft_masq_ipv4_type); 290 nft_unregister_expr(&nft_masq_ipv4_type);
239 return ret; 291 return ret;
240 } 292 }
@@ -245,8 +297,9 @@ static int __init nft_masq_module_init(void)
245static void __exit nft_masq_module_exit(void) 297static void __exit nft_masq_module_exit(void)
246{ 298{
247 nft_masq_module_exit_ipv6(); 299 nft_masq_module_exit_ipv6();
300 nft_masq_module_exit_inet();
248 nft_unregister_expr(&nft_masq_ipv4_type); 301 nft_unregister_expr(&nft_masq_ipv4_type);
249 nf_nat_masquerade_ipv4_unregister_notifier(); 302 nf_nat_masquerade_inet_unregister_notifiers();
250} 303}
251 304
252module_init(nft_masq_module_init); 305module_init(nft_masq_module_init);
diff --git a/net/netfilter/nft_nat.c b/net/netfilter/nft_nat.c
index e93aed9bda88..d90d421826aa 100644
--- a/net/netfilter/nft_nat.c
+++ b/net/netfilter/nft_nat.c
@@ -140,7 +140,7 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
140 return -EINVAL; 140 return -EINVAL;
141 141
142 family = ntohl(nla_get_be32(tb[NFTA_NAT_FAMILY])); 142 family = ntohl(nla_get_be32(tb[NFTA_NAT_FAMILY]));
143 if (family != ctx->family) 143 if (ctx->family != NFPROTO_INET && ctx->family != family)
144 return -EOPNOTSUPP; 144 return -EOPNOTSUPP;
145 145
146 switch (family) { 146 switch (family) {
@@ -278,13 +278,67 @@ static struct nft_expr_type nft_nat_type __read_mostly = {
278 .owner = THIS_MODULE, 278 .owner = THIS_MODULE,
279}; 279};
280 280
281#ifdef CONFIG_NF_TABLES_INET
282static void nft_nat_inet_eval(const struct nft_expr *expr,
283 struct nft_regs *regs,
284 const struct nft_pktinfo *pkt)
285{
286 const struct nft_nat *priv = nft_expr_priv(expr);
287
288 if (priv->family == nft_pf(pkt))
289 nft_nat_eval(expr, regs, pkt);
290}
291
292static const struct nft_expr_ops nft_nat_inet_ops = {
293 .type = &nft_nat_type,
294 .size = NFT_EXPR_SIZE(sizeof(struct nft_nat)),
295 .eval = nft_nat_inet_eval,
296 .init = nft_nat_init,
297 .destroy = nft_nat_destroy,
298 .dump = nft_nat_dump,
299 .validate = nft_nat_validate,
300};
301
302static struct nft_expr_type nft_inet_nat_type __read_mostly = {
303 .name = "nat",
304 .family = NFPROTO_INET,
305 .ops = &nft_nat_inet_ops,
306 .policy = nft_nat_policy,
307 .maxattr = NFTA_NAT_MAX,
308 .owner = THIS_MODULE,
309};
310
311static int nft_nat_inet_module_init(void)
312{
313 return nft_register_expr(&nft_inet_nat_type);
314}
315
316static void nft_nat_inet_module_exit(void)
317{
318 nft_unregister_expr(&nft_inet_nat_type);
319}
320#else
321static int nft_nat_inet_module_init(void) { return 0; }
322static void nft_nat_inet_module_exit(void) { }
323#endif
324
281static int __init nft_nat_module_init(void) 325static int __init nft_nat_module_init(void)
282{ 326{
283 return nft_register_expr(&nft_nat_type); 327 int ret = nft_nat_inet_module_init();
328
329 if (ret)
330 return ret;
331
332 ret = nft_register_expr(&nft_nat_type);
333 if (ret)
334 nft_nat_inet_module_exit();
335
336 return ret;
284} 337}
285 338
286static void __exit nft_nat_module_exit(void) 339static void __exit nft_nat_module_exit(void)
287{ 340{
341 nft_nat_inet_module_exit();
288 nft_unregister_expr(&nft_nat_type); 342 nft_unregister_expr(&nft_nat_type);
289} 343}
290 344
diff --git a/net/netfilter/nft_osf.c b/net/netfilter/nft_osf.c
index b13618c764ec..87b60d6617ef 100644
--- a/net/netfilter/nft_osf.c
+++ b/net/netfilter/nft_osf.c
@@ -7,11 +7,13 @@
7struct nft_osf { 7struct nft_osf {
8 enum nft_registers dreg:8; 8 enum nft_registers dreg:8;
9 u8 ttl; 9 u8 ttl;
10 u32 flags;
10}; 11};
11 12
12static const struct nla_policy nft_osf_policy[NFTA_OSF_MAX + 1] = { 13static const struct nla_policy nft_osf_policy[NFTA_OSF_MAX + 1] = {
13 [NFTA_OSF_DREG] = { .type = NLA_U32 }, 14 [NFTA_OSF_DREG] = { .type = NLA_U32 },
14 [NFTA_OSF_TTL] = { .type = NLA_U8 }, 15 [NFTA_OSF_TTL] = { .type = NLA_U8 },
16 [NFTA_OSF_FLAGS] = { .type = NLA_U32 },
15}; 17};
16 18
17static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, 19static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
@@ -20,9 +22,10 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
20 struct nft_osf *priv = nft_expr_priv(expr); 22 struct nft_osf *priv = nft_expr_priv(expr);
21 u32 *dest = &regs->data[priv->dreg]; 23 u32 *dest = &regs->data[priv->dreg];
22 struct sk_buff *skb = pkt->skb; 24 struct sk_buff *skb = pkt->skb;
25 char os_match[NFT_OSF_MAXGENRELEN + 1];
23 const struct tcphdr *tcp; 26 const struct tcphdr *tcp;
27 struct nf_osf_data data;
24 struct tcphdr _tcph; 28 struct tcphdr _tcph;
25 const char *os_name;
26 29
27 tcp = skb_header_pointer(skb, ip_hdrlen(skb), 30 tcp = skb_header_pointer(skb, ip_hdrlen(skb),
28 sizeof(struct tcphdr), &_tcph); 31 sizeof(struct tcphdr), &_tcph);
@@ -35,11 +38,17 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,
35 return; 38 return;
36 } 39 }
37 40
38 os_name = nf_osf_find(skb, nf_osf_fingers, priv->ttl); 41 if (!nf_osf_find(skb, nf_osf_fingers, priv->ttl, &data)) {
39 if (!os_name)
40 strncpy((char *)dest, "unknown", NFT_OSF_MAXGENRELEN); 42 strncpy((char *)dest, "unknown", NFT_OSF_MAXGENRELEN);
41 else 43 } else {
42 strncpy((char *)dest, os_name, NFT_OSF_MAXGENRELEN); 44 if (priv->flags & NFT_OSF_F_VERSION)
45 snprintf(os_match, NFT_OSF_MAXGENRELEN, "%s:%s",
46 data.genre, data.version);
47 else
48 strlcpy(os_match, data.genre, NFT_OSF_MAXGENRELEN);
49
50 strncpy((char *)dest, os_match, NFT_OSF_MAXGENRELEN);
51 }
43} 52}
44 53
45static int nft_osf_init(const struct nft_ctx *ctx, 54static int nft_osf_init(const struct nft_ctx *ctx,
@@ -47,6 +56,7 @@ static int nft_osf_init(const struct nft_ctx *ctx,
47 const struct nlattr * const tb[]) 56 const struct nlattr * const tb[])
48{ 57{
49 struct nft_osf *priv = nft_expr_priv(expr); 58 struct nft_osf *priv = nft_expr_priv(expr);
59 u32 flags;
50 int err; 60 int err;
51 u8 ttl; 61 u8 ttl;
52 62
@@ -57,6 +67,13 @@ static int nft_osf_init(const struct nft_ctx *ctx,
57 priv->ttl = ttl; 67 priv->ttl = ttl;
58 } 68 }
59 69
70 if (tb[NFTA_OSF_FLAGS]) {
71 flags = ntohl(nla_get_be32(tb[NFTA_OSF_FLAGS]));
72 if (flags != NFT_OSF_F_VERSION)
73 return -EINVAL;
74 priv->flags = flags;
75 }
76
60 priv->dreg = nft_parse_register(tb[NFTA_OSF_DREG]); 77 priv->dreg = nft_parse_register(tb[NFTA_OSF_DREG]);
61 err = nft_validate_register_store(ctx, priv->dreg, NULL, 78 err = nft_validate_register_store(ctx, priv->dreg, NULL,
62 NFT_DATA_VALUE, NFT_OSF_MAXGENRELEN); 79 NFT_DATA_VALUE, NFT_OSF_MAXGENRELEN);
@@ -73,6 +90,9 @@ static int nft_osf_dump(struct sk_buff *skb, const struct nft_expr *expr)
73 if (nla_put_u8(skb, NFTA_OSF_TTL, priv->ttl)) 90 if (nla_put_u8(skb, NFTA_OSF_TTL, priv->ttl))
74 goto nla_put_failure; 91 goto nla_put_failure;
75 92
93 if (nla_put_be32(skb, NFTA_OSF_FLAGS, ntohl(priv->flags)))
94 goto nla_put_failure;
95
76 if (nft_dump_register(skb, NFTA_OSF_DREG, priv->dreg)) 96 if (nft_dump_register(skb, NFTA_OSF_DREG, priv->dreg))
77 goto nla_put_failure; 97 goto nla_put_failure;
78 98
diff --git a/net/netfilter/nft_redir.c b/net/netfilter/nft_redir.c
index a340cd8a751b..da74fdc4a684 100644
--- a/net/netfilter/nft_redir.c
+++ b/net/netfilter/nft_redir.c
@@ -82,7 +82,7 @@ static int nft_redir_init(const struct nft_ctx *ctx,
82 return nf_ct_netns_get(ctx->net, ctx->family); 82 return nf_ct_netns_get(ctx->net, ctx->family);
83} 83}
84 84
85int nft_redir_dump(struct sk_buff *skb, const struct nft_expr *expr) 85static int nft_redir_dump(struct sk_buff *skb, const struct nft_expr *expr)
86{ 86{
87 const struct nft_redir *priv = nft_expr_priv(expr); 87 const struct nft_redir *priv = nft_expr_priv(expr);
88 88
@@ -202,6 +202,55 @@ static struct nft_expr_type nft_redir_ipv6_type __read_mostly = {
202}; 202};
203#endif 203#endif
204 204
205#ifdef CONFIG_NF_TABLES_INET
206static void nft_redir_inet_eval(const struct nft_expr *expr,
207 struct nft_regs *regs,
208 const struct nft_pktinfo *pkt)
209{
210 switch (nft_pf(pkt)) {
211 case NFPROTO_IPV4:
212 return nft_redir_ipv4_eval(expr, regs, pkt);
213 case NFPROTO_IPV6:
214 return nft_redir_ipv6_eval(expr, regs, pkt);
215 }
216
217 WARN_ON_ONCE(1);
218}
219
220static void
221nft_redir_inet_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
222{
223 nf_ct_netns_put(ctx->net, NFPROTO_INET);
224}
225
226static struct nft_expr_type nft_redir_inet_type;
227static const struct nft_expr_ops nft_redir_inet_ops = {
228 .type = &nft_redir_inet_type,
229 .size = NFT_EXPR_SIZE(sizeof(struct nft_redir)),
230 .eval = nft_redir_inet_eval,
231 .init = nft_redir_init,
232 .destroy = nft_redir_inet_destroy,
233 .dump = nft_redir_dump,
234 .validate = nft_redir_validate,
235};
236
237static struct nft_expr_type nft_redir_inet_type __read_mostly = {
238 .family = NFPROTO_INET,
239 .name = "redir",
240 .ops = &nft_redir_inet_ops,
241 .policy = nft_redir_policy,
242 .maxattr = NFTA_MASQ_MAX,
243 .owner = THIS_MODULE,
244};
245
246static int __init nft_redir_module_init_inet(void)
247{
248 return nft_register_expr(&nft_redir_inet_type);
249}
250#else
251static inline int nft_redir_module_init_inet(void) { return 0; }
252#endif
253
205static int __init nft_redir_module_init(void) 254static int __init nft_redir_module_init(void)
206{ 255{
207 int ret = nft_register_expr(&nft_redir_ipv4_type); 256 int ret = nft_register_expr(&nft_redir_ipv4_type);
@@ -217,6 +266,15 @@ static int __init nft_redir_module_init(void)
217 } 266 }
218#endif 267#endif
219 268
269 ret = nft_redir_module_init_inet();
270 if (ret < 0) {
271 nft_unregister_expr(&nft_redir_ipv4_type);
272#ifdef CONFIG_NF_TABLES_IPV6
273 nft_unregister_expr(&nft_redir_ipv6_type);
274#endif
275 return ret;
276 }
277
220 return ret; 278 return ret;
221} 279}
222 280
@@ -226,6 +284,9 @@ static void __exit nft_redir_module_exit(void)
226#ifdef CONFIG_NF_TABLES_IPV6 284#ifdef CONFIG_NF_TABLES_IPV6
227 nft_unregister_expr(&nft_redir_ipv6_type); 285 nft_unregister_expr(&nft_redir_ipv6_type);
228#endif 286#endif
287#ifdef CONFIG_NF_TABLES_INET
288 nft_unregister_expr(&nft_redir_inet_type);
289#endif
229} 290}
230 291
231module_init(nft_redir_module_init); 292module_init(nft_redir_module_init);
diff --git a/net/netfilter/nft_tunnel.c b/net/netfilter/nft_tunnel.c
index b113fcac94e1..3d4c2ae605a8 100644
--- a/net/netfilter/nft_tunnel.c
+++ b/net/netfilter/nft_tunnel.c
@@ -166,8 +166,8 @@ static int nft_tunnel_obj_ip_init(const struct nft_ctx *ctx,
166 struct nlattr *tb[NFTA_TUNNEL_KEY_IP_MAX + 1]; 166 struct nlattr *tb[NFTA_TUNNEL_KEY_IP_MAX + 1];
167 int err; 167 int err;
168 168
169 err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_IP_MAX, attr, 169 err = nla_parse_nested_deprecated(tb, NFTA_TUNNEL_KEY_IP_MAX, attr,
170 nft_tunnel_ip_policy, NULL); 170 nft_tunnel_ip_policy, NULL);
171 if (err < 0) 171 if (err < 0)
172 return err; 172 return err;
173 173
@@ -195,8 +195,8 @@ static int nft_tunnel_obj_ip6_init(const struct nft_ctx *ctx,
195 struct nlattr *tb[NFTA_TUNNEL_KEY_IP6_MAX + 1]; 195 struct nlattr *tb[NFTA_TUNNEL_KEY_IP6_MAX + 1];
196 int err; 196 int err;
197 197
198 err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_IP6_MAX, attr, 198 err = nla_parse_nested_deprecated(tb, NFTA_TUNNEL_KEY_IP6_MAX, attr,
199 nft_tunnel_ip6_policy, NULL); 199 nft_tunnel_ip6_policy, NULL);
200 if (err < 0) 200 if (err < 0)
201 return err; 201 return err;
202 202
@@ -231,8 +231,8 @@ static int nft_tunnel_obj_vxlan_init(const struct nlattr *attr,
231 struct nlattr *tb[NFTA_TUNNEL_KEY_VXLAN_MAX + 1]; 231 struct nlattr *tb[NFTA_TUNNEL_KEY_VXLAN_MAX + 1];
232 int err; 232 int err;
233 233
234 err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_VXLAN_MAX, attr, 234 err = nla_parse_nested_deprecated(tb, NFTA_TUNNEL_KEY_VXLAN_MAX, attr,
235 nft_tunnel_opts_vxlan_policy, NULL); 235 nft_tunnel_opts_vxlan_policy, NULL);
236 if (err < 0) 236 if (err < 0)
237 return err; 237 return err;
238 238
@@ -260,8 +260,9 @@ static int nft_tunnel_obj_erspan_init(const struct nlattr *attr,
260 uint8_t hwid, dir; 260 uint8_t hwid, dir;
261 int err, version; 261 int err, version;
262 262
263 err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_ERSPAN_MAX, attr, 263 err = nla_parse_nested_deprecated(tb, NFTA_TUNNEL_KEY_ERSPAN_MAX,
264 nft_tunnel_opts_erspan_policy, NULL); 264 attr, nft_tunnel_opts_erspan_policy,
265 NULL);
265 if (err < 0) 266 if (err < 0)
266 return err; 267 return err;
267 268
@@ -309,8 +310,8 @@ static int nft_tunnel_obj_opts_init(const struct nft_ctx *ctx,
309 struct nlattr *tb[NFTA_TUNNEL_KEY_OPTS_MAX + 1]; 310 struct nlattr *tb[NFTA_TUNNEL_KEY_OPTS_MAX + 1];
310 int err; 311 int err;
311 312
312 err = nla_parse_nested(tb, NFTA_TUNNEL_KEY_OPTS_MAX, attr, 313 err = nla_parse_nested_deprecated(tb, NFTA_TUNNEL_KEY_OPTS_MAX, attr,
313 nft_tunnel_opts_policy, NULL); 314 nft_tunnel_opts_policy, NULL);
314 if (err < 0) 315 if (err < 0)
315 return err; 316 return err;
316 317
@@ -437,7 +438,7 @@ static int nft_tunnel_ip_dump(struct sk_buff *skb, struct ip_tunnel_info *info)
437 struct nlattr *nest; 438 struct nlattr *nest;
438 439
439 if (info->mode & IP_TUNNEL_INFO_IPV6) { 440 if (info->mode & IP_TUNNEL_INFO_IPV6) {
440 nest = nla_nest_start(skb, NFTA_TUNNEL_KEY_IP6); 441 nest = nla_nest_start_noflag(skb, NFTA_TUNNEL_KEY_IP6);
441 if (!nest) 442 if (!nest)
442 return -1; 443 return -1;
443 444
@@ -448,7 +449,7 @@ static int nft_tunnel_ip_dump(struct sk_buff *skb, struct ip_tunnel_info *info)
448 449
449 nla_nest_end(skb, nest); 450 nla_nest_end(skb, nest);
450 } else { 451 } else {
451 nest = nla_nest_start(skb, NFTA_TUNNEL_KEY_IP); 452 nest = nla_nest_start_noflag(skb, NFTA_TUNNEL_KEY_IP);
452 if (!nest) 453 if (!nest)
453 return -1; 454 return -1;
454 455
@@ -468,7 +469,7 @@ static int nft_tunnel_opts_dump(struct sk_buff *skb,
468 struct nft_tunnel_opts *opts = &priv->opts; 469 struct nft_tunnel_opts *opts = &priv->opts;
469 struct nlattr *nest; 470 struct nlattr *nest;
470 471
471 nest = nla_nest_start(skb, NFTA_TUNNEL_KEY_OPTS); 472 nest = nla_nest_start_noflag(skb, NFTA_TUNNEL_KEY_OPTS);
472 if (!nest) 473 if (!nest)
473 return -1; 474 return -1;
474 475
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index e5e5c64df8d1..0a6656ed1534 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -227,7 +227,7 @@ xt_request_find_match(uint8_t nfproto, const char *name, uint8_t revision)
227EXPORT_SYMBOL_GPL(xt_request_find_match); 227EXPORT_SYMBOL_GPL(xt_request_find_match);
228 228
229/* Find target, grabs ref. Returns ERR_PTR() on error. */ 229/* Find target, grabs ref. Returns ERR_PTR() on error. */
230struct xt_target *xt_find_target(u8 af, const char *name, u8 revision) 230static struct xt_target *xt_find_target(u8 af, const char *name, u8 revision)
231{ 231{
232 struct xt_target *t; 232 struct xt_target *t;
233 int err = -ENOENT; 233 int err = -ENOENT;
@@ -255,7 +255,6 @@ struct xt_target *xt_find_target(u8 af, const char *name, u8 revision)
255 255
256 return ERR_PTR(err); 256 return ERR_PTR(err);
257} 257}
258EXPORT_SYMBOL(xt_find_target);
259 258
260struct xt_target *xt_request_find_target(u8 af, const char *name, u8 revision) 259struct xt_target *xt_request_find_target(u8 af, const char *name, u8 revision)
261{ 260{
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c
index 0fa863f57575..d59cb4730fac 100644
--- a/net/netfilter/xt_CT.c
+++ b/net/netfilter/xt_CT.c
@@ -103,85 +103,24 @@ xt_ct_set_helper(struct nf_conn *ct, const char *helper_name,
103 return 0; 103 return 0;
104} 104}
105 105
106#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
107static void __xt_ct_tg_timeout_put(struct nf_ct_timeout *timeout)
108{
109 typeof(nf_ct_timeout_put_hook) timeout_put;
110
111 timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
112 if (timeout_put)
113 timeout_put(timeout);
114}
115#endif
116
117static int 106static int
118xt_ct_set_timeout(struct nf_conn *ct, const struct xt_tgchk_param *par, 107xt_ct_set_timeout(struct nf_conn *ct, const struct xt_tgchk_param *par,
119 const char *timeout_name) 108 const char *timeout_name)
120{ 109{
121#ifdef CONFIG_NF_CONNTRACK_TIMEOUT 110#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
122 typeof(nf_ct_timeout_find_get_hook) timeout_find_get;
123 const struct nf_conntrack_l4proto *l4proto; 111 const struct nf_conntrack_l4proto *l4proto;
124 struct nf_ct_timeout *timeout;
125 struct nf_conn_timeout *timeout_ext;
126 const char *errmsg = NULL;
127 int ret = 0;
128 u8 proto; 112 u8 proto;
129 113
130 rcu_read_lock();
131 timeout_find_get = rcu_dereference(nf_ct_timeout_find_get_hook);
132 if (timeout_find_get == NULL) {
133 ret = -ENOENT;
134 errmsg = "Timeout policy base is empty";
135 goto out;
136 }
137
138 proto = xt_ct_find_proto(par); 114 proto = xt_ct_find_proto(par);
139 if (!proto) { 115 if (!proto) {
140 ret = -EINVAL; 116 pr_info_ratelimited("You must specify a L4 protocol and not "
141 errmsg = "You must specify a L4 protocol and not use inversions on it"; 117 "use inversions on it");
142 goto out; 118 return -EINVAL;
143 }
144
145 timeout = timeout_find_get(par->net, timeout_name);
146 if (timeout == NULL) {
147 ret = -ENOENT;
148 pr_info_ratelimited("No such timeout policy \"%s\"\n",
149 timeout_name);
150 goto out;
151 }
152
153 if (timeout->l3num != par->family) {
154 ret = -EINVAL;
155 pr_info_ratelimited("Timeout policy `%s' can only be used by L%d protocol number %d\n",
156 timeout_name, 3, timeout->l3num);
157 goto err_put_timeout;
158 } 119 }
159 /* Make sure the timeout policy matches any existing protocol tracker,
160 * otherwise default to generic.
161 */
162 l4proto = nf_ct_l4proto_find(proto); 120 l4proto = nf_ct_l4proto_find(proto);
163 if (timeout->l4proto->l4proto != l4proto->l4proto) { 121 return nf_ct_set_timeout(par->net, ct, par->family, l4proto->l4proto,
164 ret = -EINVAL; 122 timeout_name);
165 pr_info_ratelimited("Timeout policy `%s' can only be used by L%d protocol number %d\n",
166 timeout_name, 4, timeout->l4proto->l4proto);
167 goto err_put_timeout;
168 }
169 timeout_ext = nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC);
170 if (!timeout_ext) {
171 ret = -ENOMEM;
172 goto err_put_timeout;
173 }
174 123
175 rcu_read_unlock();
176 return ret;
177
178err_put_timeout:
179 __xt_ct_tg_timeout_put(timeout);
180out:
181 rcu_read_unlock();
182 if (errmsg)
183 pr_info_ratelimited("%s\n", errmsg);
184 return ret;
185#else 124#else
186 return -EOPNOTSUPP; 125 return -EOPNOTSUPP;
187#endif 126#endif
@@ -328,26 +267,6 @@ static int xt_ct_tg_check_v2(const struct xt_tgchk_param *par)
328 return xt_ct_tg_check(par, par->targinfo); 267 return xt_ct_tg_check(par, par->targinfo);
329} 268}
330 269
331static void xt_ct_destroy_timeout(struct nf_conn *ct)
332{
333#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
334 struct nf_conn_timeout *timeout_ext;
335 typeof(nf_ct_timeout_put_hook) timeout_put;
336
337 rcu_read_lock();
338 timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
339
340 if (timeout_put) {
341 timeout_ext = nf_ct_timeout_find(ct);
342 if (timeout_ext) {
343 timeout_put(timeout_ext->timeout);
344 RCU_INIT_POINTER(timeout_ext->timeout, NULL);
345 }
346 }
347 rcu_read_unlock();
348#endif
349}
350
351static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par, 270static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par,
352 struct xt_ct_target_info_v1 *info) 271 struct xt_ct_target_info_v1 *info)
353{ 272{
@@ -361,7 +280,7 @@ static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par,
361 280
362 nf_ct_netns_put(par->net, par->family); 281 nf_ct_netns_put(par->net, par->family);
363 282
364 xt_ct_destroy_timeout(ct); 283 nf_ct_destroy_timeout(ct);
365 nf_ct_put(info->ct); 284 nf_ct_put(info->ct);
366 } 285 }
367} 286}
diff --git a/net/ipv4/netfilter/ipt_MASQUERADE.c b/net/netfilter/xt_MASQUERADE.c
index fd3f9e8a74da..ece20d832adc 100644
--- a/net/ipv4/netfilter/ipt_MASQUERADE.c
+++ b/net/netfilter/xt_MASQUERADE.c
@@ -9,20 +9,10 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12#include <linux/types.h>
13#include <linux/inetdevice.h>
14#include <linux/ip.h>
15#include <linux/timer.h>
16#include <linux/module.h> 12#include <linux/module.h>
17#include <linux/netfilter.h>
18#include <net/protocol.h>
19#include <net/ip.h>
20#include <net/checksum.h>
21#include <net/route.h>
22#include <linux/netfilter_ipv4.h>
23#include <linux/netfilter/x_tables.h> 13#include <linux/netfilter/x_tables.h>
24#include <net/netfilter/nf_nat.h> 14#include <net/netfilter/nf_nat.h>
25#include <net/netfilter/ipv4/nf_nat_masquerade.h> 15#include <net/netfilter/nf_nat_masquerade.h>
26 16
27MODULE_LICENSE("GPL"); 17MODULE_LICENSE("GPL");
28MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 18MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
@@ -64,38 +54,78 @@ static void masquerade_tg_destroy(const struct xt_tgdtor_param *par)
64 nf_ct_netns_put(par->net, par->family); 54 nf_ct_netns_put(par->net, par->family);
65} 55}
66 56
67static struct xt_target masquerade_tg_reg __read_mostly = { 57#if IS_ENABLED(CONFIG_IPV6)
68 .name = "MASQUERADE", 58static unsigned int
69 .family = NFPROTO_IPV4, 59masquerade_tg6(struct sk_buff *skb, const struct xt_action_param *par)
70 .target = masquerade_tg, 60{
71 .targetsize = sizeof(struct nf_nat_ipv4_multi_range_compat), 61 return nf_nat_masquerade_ipv6(skb, par->targinfo, xt_out(par));
72 .table = "nat", 62}
73 .hooks = 1 << NF_INET_POST_ROUTING, 63
74 .checkentry = masquerade_tg_check, 64static int masquerade_tg6_checkentry(const struct xt_tgchk_param *par)
75 .destroy = masquerade_tg_destroy, 65{
76 .me = THIS_MODULE, 66 const struct nf_nat_range2 *range = par->targinfo;
67
68 if (range->flags & NF_NAT_RANGE_MAP_IPS)
69 return -EINVAL;
70
71 return nf_ct_netns_get(par->net, par->family);
72}
73#endif
74
75static struct xt_target masquerade_tg_reg[] __read_mostly = {
76 {
77#if IS_ENABLED(CONFIG_IPV6)
78 .name = "MASQUERADE",
79 .family = NFPROTO_IPV6,
80 .target = masquerade_tg6,
81 .targetsize = sizeof(struct nf_nat_range),
82 .table = "nat",
83 .hooks = 1 << NF_INET_POST_ROUTING,
84 .checkentry = masquerade_tg6_checkentry,
85 .destroy = masquerade_tg_destroy,
86 .me = THIS_MODULE,
87 }, {
88#endif
89 .name = "MASQUERADE",
90 .family = NFPROTO_IPV4,
91 .target = masquerade_tg,
92 .targetsize = sizeof(struct nf_nat_ipv4_multi_range_compat),
93 .table = "nat",
94 .hooks = 1 << NF_INET_POST_ROUTING,
95 .checkentry = masquerade_tg_check,
96 .destroy = masquerade_tg_destroy,
97 .me = THIS_MODULE,
98 }
77}; 99};
78 100
79static int __init masquerade_tg_init(void) 101static int __init masquerade_tg_init(void)
80{ 102{
81 int ret; 103 int ret;
82 104
83 ret = xt_register_target(&masquerade_tg_reg); 105 ret = xt_register_targets(masquerade_tg_reg,
106 ARRAY_SIZE(masquerade_tg_reg));
84 if (ret) 107 if (ret)
85 return ret; 108 return ret;
86 109
87 ret = nf_nat_masquerade_ipv4_register_notifier(); 110 ret = nf_nat_masquerade_inet_register_notifiers();
88 if (ret) 111 if (ret) {
89 xt_unregister_target(&masquerade_tg_reg); 112 xt_unregister_targets(masquerade_tg_reg,
113 ARRAY_SIZE(masquerade_tg_reg));
114 return ret;
115 }
90 116
91 return ret; 117 return ret;
92} 118}
93 119
94static void __exit masquerade_tg_exit(void) 120static void __exit masquerade_tg_exit(void)
95{ 121{
96 xt_unregister_target(&masquerade_tg_reg); 122 xt_unregister_targets(masquerade_tg_reg, ARRAY_SIZE(masquerade_tg_reg));
97 nf_nat_masquerade_ipv4_unregister_notifier(); 123 nf_nat_masquerade_inet_unregister_notifiers();
98} 124}
99 125
100module_init(masquerade_tg_init); 126module_init(masquerade_tg_init);
101module_exit(masquerade_tg_exit); 127module_exit(masquerade_tg_exit);
128#if IS_ENABLED(CONFIG_IPV6)
129MODULE_ALIAS("ip6t_MASQUERADE");
130#endif
131MODULE_ALIAS("ipt_MASQUERADE");
diff --git a/net/netfilter/xt_connlabel.c b/net/netfilter/xt_connlabel.c
index 4fa4efd24353..893374ac3758 100644
--- a/net/netfilter/xt_connlabel.c
+++ b/net/netfilter/xt_connlabel.c
@@ -15,7 +15,7 @@
15 15
16MODULE_LICENSE("GPL"); 16MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Florian Westphal <fw@strlen.de>"); 17MODULE_AUTHOR("Florian Westphal <fw@strlen.de>");
18MODULE_DESCRIPTION("Xtables: add/match connection trackling labels"); 18MODULE_DESCRIPTION("Xtables: add/match connection tracking labels");
19MODULE_ALIAS("ipt_connlabel"); 19MODULE_ALIAS("ipt_connlabel");
20MODULE_ALIAS("ip6t_connlabel"); 20MODULE_ALIAS("ip6t_connlabel");
21 21
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 8d86e39d6280..a30536b17ee1 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -288,8 +288,7 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg,
288 size = 16; 288 size = 16;
289 } 289 }
290 /* FIXME: don't use vmalloc() here or anywhere else -HW */ 290 /* FIXME: don't use vmalloc() here or anywhere else -HW */
291 hinfo = vmalloc(sizeof(struct xt_hashlimit_htable) + 291 hinfo = vmalloc(struct_size(hinfo, hash, size));
292 sizeof(struct hlist_head) * size);
293 if (hinfo == NULL) 292 if (hinfo == NULL)
294 return -ENOMEM; 293 return -ENOMEM;
295 *out_hinfo = hinfo; 294 *out_hinfo = hinfo;
diff --git a/net/netfilter/xt_time.c b/net/netfilter/xt_time.c
index c13bcd0ab491..8dbb4d48f2ed 100644
--- a/net/netfilter/xt_time.c
+++ b/net/netfilter/xt_time.c
@@ -163,19 +163,24 @@ time_mt(const struct sk_buff *skb, struct xt_action_param *par)
163 s64 stamp; 163 s64 stamp;
164 164
165 /* 165 /*
166 * We cannot use get_seconds() instead of __net_timestamp() here. 166 * We need real time here, but we can neither use skb->tstamp
167 * nor __net_timestamp().
168 *
169 * skb->tstamp and skb->skb_mstamp_ns overlap, however, they
170 * use different clock types (real vs monotonic).
171 *
167 * Suppose you have two rules: 172 * Suppose you have two rules:
168 * 1. match before 13:00 173 * 1. match before 13:00
169 * 2. match after 13:00 174 * 2. match after 13:00
175 *
170 * If you match against processing time (get_seconds) it 176 * If you match against processing time (get_seconds) it
171 * may happen that the same packet matches both rules if 177 * may happen that the same packet matches both rules if
172 * it arrived at the right moment before 13:00. 178 * it arrived at the right moment before 13:00, so it would be
179 * better to check skb->tstamp and set it via __net_timestamp()
180 * if needed. This however breaks outgoing packets tx timestamp,
181 * and causes them to get delayed forever by fq packet scheduler.
173 */ 182 */
174 if (skb->tstamp == 0) 183 stamp = get_seconds();
175 __net_timestamp((struct sk_buff *)skb);
176
177 stamp = ktime_to_ns(skb->tstamp);
178 stamp = div_s64(stamp, NSEC_PER_SEC);
179 184
180 if (info->flags & XT_TIME_LOCAL_TZ) 185 if (info->flags & XT_TIME_LOCAL_TZ)
181 /* Adjust for local timezone */ 186 /* Adjust for local timezone */
diff --git a/net/netlabel/netlabel_calipso.c b/net/netlabel/netlabel_calipso.c
index 4d748975117d..1de87172885d 100644
--- a/net/netlabel/netlabel_calipso.c
+++ b/net/netlabel/netlabel_calipso.c
@@ -321,29 +321,29 @@ static int netlbl_calipso_remove(struct sk_buff *skb, struct genl_info *info)
321static const struct genl_ops netlbl_calipso_ops[] = { 321static const struct genl_ops netlbl_calipso_ops[] = {
322 { 322 {
323 .cmd = NLBL_CALIPSO_C_ADD, 323 .cmd = NLBL_CALIPSO_C_ADD,
324 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
324 .flags = GENL_ADMIN_PERM, 325 .flags = GENL_ADMIN_PERM,
325 .policy = calipso_genl_policy,
326 .doit = netlbl_calipso_add, 326 .doit = netlbl_calipso_add,
327 .dumpit = NULL, 327 .dumpit = NULL,
328 }, 328 },
329 { 329 {
330 .cmd = NLBL_CALIPSO_C_REMOVE, 330 .cmd = NLBL_CALIPSO_C_REMOVE,
331 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
331 .flags = GENL_ADMIN_PERM, 332 .flags = GENL_ADMIN_PERM,
332 .policy = calipso_genl_policy,
333 .doit = netlbl_calipso_remove, 333 .doit = netlbl_calipso_remove,
334 .dumpit = NULL, 334 .dumpit = NULL,
335 }, 335 },
336 { 336 {
337 .cmd = NLBL_CALIPSO_C_LIST, 337 .cmd = NLBL_CALIPSO_C_LIST,
338 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
338 .flags = 0, 339 .flags = 0,
339 .policy = calipso_genl_policy,
340 .doit = netlbl_calipso_list, 340 .doit = netlbl_calipso_list,
341 .dumpit = NULL, 341 .dumpit = NULL,
342 }, 342 },
343 { 343 {
344 .cmd = NLBL_CALIPSO_C_LISTALL, 344 .cmd = NLBL_CALIPSO_C_LISTALL,
345 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
345 .flags = 0, 346 .flags = 0,
346 .policy = calipso_genl_policy,
347 .doit = NULL, 347 .doit = NULL,
348 .dumpit = netlbl_calipso_listall, 348 .dumpit = netlbl_calipso_listall,
349 }, 349 },
@@ -354,6 +354,7 @@ static struct genl_family netlbl_calipso_gnl_family __ro_after_init = {
354 .name = NETLBL_NLTYPE_CALIPSO_NAME, 354 .name = NETLBL_NLTYPE_CALIPSO_NAME,
355 .version = NETLBL_PROTO_VERSION, 355 .version = NETLBL_PROTO_VERSION,
356 .maxattr = NLBL_CALIPSO_A_MAX, 356 .maxattr = NLBL_CALIPSO_A_MAX,
357 .policy = calipso_genl_policy,
357 .module = THIS_MODULE, 358 .module = THIS_MODULE,
358 .ops = netlbl_calipso_ops, 359 .ops = netlbl_calipso_ops,
359 .n_ops = ARRAY_SIZE(netlbl_calipso_ops), 360 .n_ops = ARRAY_SIZE(netlbl_calipso_ops),
diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c
index 9aacf2da3d98..5d1121981d0b 100644
--- a/net/netlabel/netlabel_cipso_v4.c
+++ b/net/netlabel/netlabel_cipso_v4.c
@@ -99,9 +99,10 @@ static int netlbl_cipsov4_add_common(struct genl_info *info,
99 99
100 doi_def->doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]); 100 doi_def->doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]);
101 101
102 if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_TAGLST], 102 if (nla_validate_nested_deprecated(info->attrs[NLBL_CIPSOV4_A_TAGLST],
103 NLBL_CIPSOV4_A_MAX, 103 NLBL_CIPSOV4_A_MAX,
104 netlbl_cipsov4_genl_policy, NULL) != 0) 104 netlbl_cipsov4_genl_policy,
105 NULL) != 0)
105 return -EINVAL; 106 return -EINVAL;
106 107
107 nla_for_each_nested(nla, info->attrs[NLBL_CIPSOV4_A_TAGLST], nla_rem) 108 nla_for_each_nested(nla, info->attrs[NLBL_CIPSOV4_A_TAGLST], nla_rem)
@@ -146,9 +147,10 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
146 !info->attrs[NLBL_CIPSOV4_A_MLSLVLLST]) 147 !info->attrs[NLBL_CIPSOV4_A_MLSLVLLST])
147 return -EINVAL; 148 return -EINVAL;
148 149
149 if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], 150 if (nla_validate_nested_deprecated(info->attrs[NLBL_CIPSOV4_A_MLSLVLLST],
150 NLBL_CIPSOV4_A_MAX, 151 NLBL_CIPSOV4_A_MAX,
151 netlbl_cipsov4_genl_policy, NULL) != 0) 152 netlbl_cipsov4_genl_policy,
153 NULL) != 0)
152 return -EINVAL; 154 return -EINVAL;
153 155
154 doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL); 156 doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);
@@ -170,9 +172,10 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
170 info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], 172 info->attrs[NLBL_CIPSOV4_A_MLSLVLLST],
171 nla_a_rem) 173 nla_a_rem)
172 if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSLVL) { 174 if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSLVL) {
173 if (nla_validate_nested(nla_a, NLBL_CIPSOV4_A_MAX, 175 if (nla_validate_nested_deprecated(nla_a,
174 netlbl_cipsov4_genl_policy, 176 NLBL_CIPSOV4_A_MAX,
175 NULL) != 0) 177 netlbl_cipsov4_genl_policy,
178 NULL) != 0)
176 goto add_std_failure; 179 goto add_std_failure;
177 nla_for_each_nested(nla_b, nla_a, nla_b_rem) 180 nla_for_each_nested(nla_b, nla_a, nla_b_rem)
178 switch (nla_type(nla_b)) { 181 switch (nla_type(nla_b)) {
@@ -234,19 +237,20 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
234 } 237 }
235 238
236 if (info->attrs[NLBL_CIPSOV4_A_MLSCATLST]) { 239 if (info->attrs[NLBL_CIPSOV4_A_MLSCATLST]) {
237 if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_MLSCATLST], 240 if (nla_validate_nested_deprecated(info->attrs[NLBL_CIPSOV4_A_MLSCATLST],
238 NLBL_CIPSOV4_A_MAX, 241 NLBL_CIPSOV4_A_MAX,
239 netlbl_cipsov4_genl_policy, NULL) != 0) 242 netlbl_cipsov4_genl_policy,
243 NULL) != 0)
240 goto add_std_failure; 244 goto add_std_failure;
241 245
242 nla_for_each_nested(nla_a, 246 nla_for_each_nested(nla_a,
243 info->attrs[NLBL_CIPSOV4_A_MLSCATLST], 247 info->attrs[NLBL_CIPSOV4_A_MLSCATLST],
244 nla_a_rem) 248 nla_a_rem)
245 if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSCAT) { 249 if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSCAT) {
246 if (nla_validate_nested(nla_a, 250 if (nla_validate_nested_deprecated(nla_a,
247 NLBL_CIPSOV4_A_MAX, 251 NLBL_CIPSOV4_A_MAX,
248 netlbl_cipsov4_genl_policy, 252 netlbl_cipsov4_genl_policy,
249 NULL) != 0) 253 NULL) != 0)
250 goto add_std_failure; 254 goto add_std_failure;
251 nla_for_each_nested(nla_b, nla_a, nla_b_rem) 255 nla_for_each_nested(nla_b, nla_a, nla_b_rem)
252 switch (nla_type(nla_b)) { 256 switch (nla_type(nla_b)) {
@@ -498,7 +502,7 @@ list_start:
498 if (ret_val != 0) 502 if (ret_val != 0)
499 goto list_failure_lock; 503 goto list_failure_lock;
500 504
501 nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_TAGLST); 505 nla_a = nla_nest_start_noflag(ans_skb, NLBL_CIPSOV4_A_TAGLST);
502 if (nla_a == NULL) { 506 if (nla_a == NULL) {
503 ret_val = -ENOMEM; 507 ret_val = -ENOMEM;
504 goto list_failure_lock; 508 goto list_failure_lock;
@@ -517,7 +521,8 @@ list_start:
517 521
518 switch (doi_def->type) { 522 switch (doi_def->type) {
519 case CIPSO_V4_MAP_TRANS: 523 case CIPSO_V4_MAP_TRANS:
520 nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSLVLLST); 524 nla_a = nla_nest_start_noflag(ans_skb,
525 NLBL_CIPSOV4_A_MLSLVLLST);
521 if (nla_a == NULL) { 526 if (nla_a == NULL) {
522 ret_val = -ENOMEM; 527 ret_val = -ENOMEM;
523 goto list_failure_lock; 528 goto list_failure_lock;
@@ -529,7 +534,8 @@ list_start:
529 CIPSO_V4_INV_LVL) 534 CIPSO_V4_INV_LVL)
530 continue; 535 continue;
531 536
532 nla_b = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSLVL); 537 nla_b = nla_nest_start_noflag(ans_skb,
538 NLBL_CIPSOV4_A_MLSLVL);
533 if (nla_b == NULL) { 539 if (nla_b == NULL) {
534 ret_val = -ENOMEM; 540 ret_val = -ENOMEM;
535 goto list_retry; 541 goto list_retry;
@@ -548,7 +554,8 @@ list_start:
548 } 554 }
549 nla_nest_end(ans_skb, nla_a); 555 nla_nest_end(ans_skb, nla_a);
550 556
551 nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSCATLST); 557 nla_a = nla_nest_start_noflag(ans_skb,
558 NLBL_CIPSOV4_A_MLSCATLST);
552 if (nla_a == NULL) { 559 if (nla_a == NULL) {
553 ret_val = -ENOMEM; 560 ret_val = -ENOMEM;
554 goto list_retry; 561 goto list_retry;
@@ -560,7 +567,8 @@ list_start:
560 CIPSO_V4_INV_CAT) 567 CIPSO_V4_INV_CAT)
561 continue; 568 continue;
562 569
563 nla_b = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSCAT); 570 nla_b = nla_nest_start_noflag(ans_skb,
571 NLBL_CIPSOV4_A_MLSCAT);
564 if (nla_b == NULL) { 572 if (nla_b == NULL) {
565 ret_val = -ENOMEM; 573 ret_val = -ENOMEM;
566 goto list_retry; 574 goto list_retry;
@@ -733,29 +741,29 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info)
733static const struct genl_ops netlbl_cipsov4_ops[] = { 741static const struct genl_ops netlbl_cipsov4_ops[] = {
734 { 742 {
735 .cmd = NLBL_CIPSOV4_C_ADD, 743 .cmd = NLBL_CIPSOV4_C_ADD,
744 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
736 .flags = GENL_ADMIN_PERM, 745 .flags = GENL_ADMIN_PERM,
737 .policy = netlbl_cipsov4_genl_policy,
738 .doit = netlbl_cipsov4_add, 746 .doit = netlbl_cipsov4_add,
739 .dumpit = NULL, 747 .dumpit = NULL,
740 }, 748 },
741 { 749 {
742 .cmd = NLBL_CIPSOV4_C_REMOVE, 750 .cmd = NLBL_CIPSOV4_C_REMOVE,
751 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
743 .flags = GENL_ADMIN_PERM, 752 .flags = GENL_ADMIN_PERM,
744 .policy = netlbl_cipsov4_genl_policy,
745 .doit = netlbl_cipsov4_remove, 753 .doit = netlbl_cipsov4_remove,
746 .dumpit = NULL, 754 .dumpit = NULL,
747 }, 755 },
748 { 756 {
749 .cmd = NLBL_CIPSOV4_C_LIST, 757 .cmd = NLBL_CIPSOV4_C_LIST,
758 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
750 .flags = 0, 759 .flags = 0,
751 .policy = netlbl_cipsov4_genl_policy,
752 .doit = netlbl_cipsov4_list, 760 .doit = netlbl_cipsov4_list,
753 .dumpit = NULL, 761 .dumpit = NULL,
754 }, 762 },
755 { 763 {
756 .cmd = NLBL_CIPSOV4_C_LISTALL, 764 .cmd = NLBL_CIPSOV4_C_LISTALL,
765 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
757 .flags = 0, 766 .flags = 0,
758 .policy = netlbl_cipsov4_genl_policy,
759 .doit = NULL, 767 .doit = NULL,
760 .dumpit = netlbl_cipsov4_listall, 768 .dumpit = netlbl_cipsov4_listall,
761 }, 769 },
@@ -766,6 +774,7 @@ static struct genl_family netlbl_cipsov4_gnl_family __ro_after_init = {
766 .name = NETLBL_NLTYPE_CIPSOV4_NAME, 774 .name = NETLBL_NLTYPE_CIPSOV4_NAME,
767 .version = NETLBL_PROTO_VERSION, 775 .version = NETLBL_PROTO_VERSION,
768 .maxattr = NLBL_CIPSOV4_A_MAX, 776 .maxattr = NLBL_CIPSOV4_A_MAX,
777 .policy = netlbl_cipsov4_genl_policy,
769 .module = THIS_MODULE, 778 .module = THIS_MODULE,
770 .ops = netlbl_cipsov4_ops, 779 .ops = netlbl_cipsov4_ops,
771 .n_ops = ARRAY_SIZE(netlbl_cipsov4_ops), 780 .n_ops = ARRAY_SIZE(netlbl_cipsov4_ops),
diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c
index 21e0095b1d14..cae04f207782 100644
--- a/net/netlabel/netlabel_mgmt.c
+++ b/net/netlabel/netlabel_mgmt.c
@@ -315,7 +315,7 @@ static int netlbl_mgmt_listentry(struct sk_buff *skb,
315 315
316 switch (entry->def.type) { 316 switch (entry->def.type) {
317 case NETLBL_NLTYPE_ADDRSELECT: 317 case NETLBL_NLTYPE_ADDRSELECT:
318 nla_a = nla_nest_start(skb, NLBL_MGMT_A_SELECTORLIST); 318 nla_a = nla_nest_start_noflag(skb, NLBL_MGMT_A_SELECTORLIST);
319 if (nla_a == NULL) 319 if (nla_a == NULL)
320 return -ENOMEM; 320 return -ENOMEM;
321 321
@@ -323,7 +323,8 @@ static int netlbl_mgmt_listentry(struct sk_buff *skb,
323 struct netlbl_domaddr4_map *map4; 323 struct netlbl_domaddr4_map *map4;
324 struct in_addr addr_struct; 324 struct in_addr addr_struct;
325 325
326 nla_b = nla_nest_start(skb, NLBL_MGMT_A_ADDRSELECTOR); 326 nla_b = nla_nest_start_noflag(skb,
327 NLBL_MGMT_A_ADDRSELECTOR);
327 if (nla_b == NULL) 328 if (nla_b == NULL)
328 return -ENOMEM; 329 return -ENOMEM;
329 330
@@ -357,7 +358,8 @@ static int netlbl_mgmt_listentry(struct sk_buff *skb,
357 netlbl_af6list_foreach_rcu(iter6, &entry->def.addrsel->list6) { 358 netlbl_af6list_foreach_rcu(iter6, &entry->def.addrsel->list6) {
358 struct netlbl_domaddr6_map *map6; 359 struct netlbl_domaddr6_map *map6;
359 360
360 nla_b = nla_nest_start(skb, NLBL_MGMT_A_ADDRSELECTOR); 361 nla_b = nla_nest_start_noflag(skb,
362 NLBL_MGMT_A_ADDRSELECTOR);
361 if (nla_b == NULL) 363 if (nla_b == NULL)
362 return -ENOMEM; 364 return -ENOMEM;
363 365
@@ -772,57 +774,57 @@ version_failure:
772static const struct genl_ops netlbl_mgmt_genl_ops[] = { 774static const struct genl_ops netlbl_mgmt_genl_ops[] = {
773 { 775 {
774 .cmd = NLBL_MGMT_C_ADD, 776 .cmd = NLBL_MGMT_C_ADD,
777 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
775 .flags = GENL_ADMIN_PERM, 778 .flags = GENL_ADMIN_PERM,
776 .policy = netlbl_mgmt_genl_policy,
777 .doit = netlbl_mgmt_add, 779 .doit = netlbl_mgmt_add,
778 .dumpit = NULL, 780 .dumpit = NULL,
779 }, 781 },
780 { 782 {
781 .cmd = NLBL_MGMT_C_REMOVE, 783 .cmd = NLBL_MGMT_C_REMOVE,
784 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
782 .flags = GENL_ADMIN_PERM, 785 .flags = GENL_ADMIN_PERM,
783 .policy = netlbl_mgmt_genl_policy,
784 .doit = netlbl_mgmt_remove, 786 .doit = netlbl_mgmt_remove,
785 .dumpit = NULL, 787 .dumpit = NULL,
786 }, 788 },
787 { 789 {
788 .cmd = NLBL_MGMT_C_LISTALL, 790 .cmd = NLBL_MGMT_C_LISTALL,
791 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
789 .flags = 0, 792 .flags = 0,
790 .policy = netlbl_mgmt_genl_policy,
791 .doit = NULL, 793 .doit = NULL,
792 .dumpit = netlbl_mgmt_listall, 794 .dumpit = netlbl_mgmt_listall,
793 }, 795 },
794 { 796 {
795 .cmd = NLBL_MGMT_C_ADDDEF, 797 .cmd = NLBL_MGMT_C_ADDDEF,
798 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
796 .flags = GENL_ADMIN_PERM, 799 .flags = GENL_ADMIN_PERM,
797 .policy = netlbl_mgmt_genl_policy,
798 .doit = netlbl_mgmt_adddef, 800 .doit = netlbl_mgmt_adddef,
799 .dumpit = NULL, 801 .dumpit = NULL,
800 }, 802 },
801 { 803 {
802 .cmd = NLBL_MGMT_C_REMOVEDEF, 804 .cmd = NLBL_MGMT_C_REMOVEDEF,
805 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
803 .flags = GENL_ADMIN_PERM, 806 .flags = GENL_ADMIN_PERM,
804 .policy = netlbl_mgmt_genl_policy,
805 .doit = netlbl_mgmt_removedef, 807 .doit = netlbl_mgmt_removedef,
806 .dumpit = NULL, 808 .dumpit = NULL,
807 }, 809 },
808 { 810 {
809 .cmd = NLBL_MGMT_C_LISTDEF, 811 .cmd = NLBL_MGMT_C_LISTDEF,
812 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
810 .flags = 0, 813 .flags = 0,
811 .policy = netlbl_mgmt_genl_policy,
812 .doit = netlbl_mgmt_listdef, 814 .doit = netlbl_mgmt_listdef,
813 .dumpit = NULL, 815 .dumpit = NULL,
814 }, 816 },
815 { 817 {
816 .cmd = NLBL_MGMT_C_PROTOCOLS, 818 .cmd = NLBL_MGMT_C_PROTOCOLS,
819 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
817 .flags = 0, 820 .flags = 0,
818 .policy = netlbl_mgmt_genl_policy,
819 .doit = NULL, 821 .doit = NULL,
820 .dumpit = netlbl_mgmt_protocols, 822 .dumpit = netlbl_mgmt_protocols,
821 }, 823 },
822 { 824 {
823 .cmd = NLBL_MGMT_C_VERSION, 825 .cmd = NLBL_MGMT_C_VERSION,
826 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
824 .flags = 0, 827 .flags = 0,
825 .policy = netlbl_mgmt_genl_policy,
826 .doit = netlbl_mgmt_version, 828 .doit = netlbl_mgmt_version,
827 .dumpit = NULL, 829 .dumpit = NULL,
828 }, 830 },
@@ -833,6 +835,7 @@ static struct genl_family netlbl_mgmt_gnl_family __ro_after_init = {
833 .name = NETLBL_NLTYPE_MGMT_NAME, 835 .name = NETLBL_NLTYPE_MGMT_NAME,
834 .version = NETLBL_PROTO_VERSION, 836 .version = NETLBL_PROTO_VERSION,
835 .maxattr = NLBL_MGMT_A_MAX, 837 .maxattr = NLBL_MGMT_A_MAX,
838 .policy = netlbl_mgmt_genl_policy,
836 .module = THIS_MODULE, 839 .module = THIS_MODULE,
837 .ops = netlbl_mgmt_genl_ops, 840 .ops = netlbl_mgmt_genl_ops,
838 .n_ops = ARRAY_SIZE(netlbl_mgmt_genl_ops), 841 .n_ops = ARRAY_SIZE(netlbl_mgmt_genl_ops),
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c
index c92894c3e40a..b87dd34e1835 100644
--- a/net/netlabel/netlabel_unlabeled.c
+++ b/net/netlabel/netlabel_unlabeled.c
@@ -1317,57 +1317,57 @@ unlabel_staticlistdef_return:
1317static const struct genl_ops netlbl_unlabel_genl_ops[] = { 1317static const struct genl_ops netlbl_unlabel_genl_ops[] = {
1318 { 1318 {
1319 .cmd = NLBL_UNLABEL_C_STATICADD, 1319 .cmd = NLBL_UNLABEL_C_STATICADD,
1320 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1320 .flags = GENL_ADMIN_PERM, 1321 .flags = GENL_ADMIN_PERM,
1321 .policy = netlbl_unlabel_genl_policy,
1322 .doit = netlbl_unlabel_staticadd, 1322 .doit = netlbl_unlabel_staticadd,
1323 .dumpit = NULL, 1323 .dumpit = NULL,
1324 }, 1324 },
1325 { 1325 {
1326 .cmd = NLBL_UNLABEL_C_STATICREMOVE, 1326 .cmd = NLBL_UNLABEL_C_STATICREMOVE,
1327 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1327 .flags = GENL_ADMIN_PERM, 1328 .flags = GENL_ADMIN_PERM,
1328 .policy = netlbl_unlabel_genl_policy,
1329 .doit = netlbl_unlabel_staticremove, 1329 .doit = netlbl_unlabel_staticremove,
1330 .dumpit = NULL, 1330 .dumpit = NULL,
1331 }, 1331 },
1332 { 1332 {
1333 .cmd = NLBL_UNLABEL_C_STATICLIST, 1333 .cmd = NLBL_UNLABEL_C_STATICLIST,
1334 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1334 .flags = 0, 1335 .flags = 0,
1335 .policy = netlbl_unlabel_genl_policy,
1336 .doit = NULL, 1336 .doit = NULL,
1337 .dumpit = netlbl_unlabel_staticlist, 1337 .dumpit = netlbl_unlabel_staticlist,
1338 }, 1338 },
1339 { 1339 {
1340 .cmd = NLBL_UNLABEL_C_STATICADDDEF, 1340 .cmd = NLBL_UNLABEL_C_STATICADDDEF,
1341 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1341 .flags = GENL_ADMIN_PERM, 1342 .flags = GENL_ADMIN_PERM,
1342 .policy = netlbl_unlabel_genl_policy,
1343 .doit = netlbl_unlabel_staticadddef, 1343 .doit = netlbl_unlabel_staticadddef,
1344 .dumpit = NULL, 1344 .dumpit = NULL,
1345 }, 1345 },
1346 { 1346 {
1347 .cmd = NLBL_UNLABEL_C_STATICREMOVEDEF, 1347 .cmd = NLBL_UNLABEL_C_STATICREMOVEDEF,
1348 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1348 .flags = GENL_ADMIN_PERM, 1349 .flags = GENL_ADMIN_PERM,
1349 .policy = netlbl_unlabel_genl_policy,
1350 .doit = netlbl_unlabel_staticremovedef, 1350 .doit = netlbl_unlabel_staticremovedef,
1351 .dumpit = NULL, 1351 .dumpit = NULL,
1352 }, 1352 },
1353 { 1353 {
1354 .cmd = NLBL_UNLABEL_C_STATICLISTDEF, 1354 .cmd = NLBL_UNLABEL_C_STATICLISTDEF,
1355 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1355 .flags = 0, 1356 .flags = 0,
1356 .policy = netlbl_unlabel_genl_policy,
1357 .doit = NULL, 1357 .doit = NULL,
1358 .dumpit = netlbl_unlabel_staticlistdef, 1358 .dumpit = netlbl_unlabel_staticlistdef,
1359 }, 1359 },
1360 { 1360 {
1361 .cmd = NLBL_UNLABEL_C_ACCEPT, 1361 .cmd = NLBL_UNLABEL_C_ACCEPT,
1362 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1362 .flags = GENL_ADMIN_PERM, 1363 .flags = GENL_ADMIN_PERM,
1363 .policy = netlbl_unlabel_genl_policy,
1364 .doit = netlbl_unlabel_accept, 1364 .doit = netlbl_unlabel_accept,
1365 .dumpit = NULL, 1365 .dumpit = NULL,
1366 }, 1366 },
1367 { 1367 {
1368 .cmd = NLBL_UNLABEL_C_LIST, 1368 .cmd = NLBL_UNLABEL_C_LIST,
1369 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1369 .flags = 0, 1370 .flags = 0,
1370 .policy = netlbl_unlabel_genl_policy,
1371 .doit = netlbl_unlabel_list, 1371 .doit = netlbl_unlabel_list,
1372 .dumpit = NULL, 1372 .dumpit = NULL,
1373 }, 1373 },
@@ -1378,6 +1378,7 @@ static struct genl_family netlbl_unlabel_gnl_family __ro_after_init = {
1378 .name = NETLBL_NLTYPE_UNLABELED_NAME, 1378 .name = NETLBL_NLTYPE_UNLABELED_NAME,
1379 .version = NETLBL_PROTO_VERSION, 1379 .version = NETLBL_PROTO_VERSION,
1380 .maxattr = NLBL_UNLABEL_A_MAX, 1380 .maxattr = NLBL_UNLABEL_A_MAX,
1381 .policy = netlbl_unlabel_genl_policy,
1381 .module = THIS_MODULE, 1382 .module = THIS_MODULE,
1382 .ops = netlbl_unlabel_genl_ops, 1383 .ops = netlbl_unlabel_genl_ops,
1383 .n_ops = ARRAY_SIZE(netlbl_unlabel_genl_ops), 1384 .n_ops = ARRAY_SIZE(netlbl_unlabel_genl_ops),
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index f28e937320a3..216ab915dd54 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -988,7 +988,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
988 struct netlink_sock *nlk = nlk_sk(sk); 988 struct netlink_sock *nlk = nlk_sk(sk);
989 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr; 989 struct sockaddr_nl *nladdr = (struct sockaddr_nl *)addr;
990 int err = 0; 990 int err = 0;
991 unsigned long groups = nladdr->nl_groups; 991 unsigned long groups;
992 bool bound; 992 bool bound;
993 993
994 if (addr_len < sizeof(struct sockaddr_nl)) 994 if (addr_len < sizeof(struct sockaddr_nl))
@@ -996,6 +996,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
996 996
997 if (nladdr->nl_family != AF_NETLINK) 997 if (nladdr->nl_family != AF_NETLINK)
998 return -EINVAL; 998 return -EINVAL;
999 groups = nladdr->nl_groups;
999 1000
1000 /* Only superuser is allowed to listen multicasts */ 1001 /* Only superuser is allowed to listen multicasts */
1001 if (groups) { 1002 if (groups) {
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index f0ec068e1d02..efccd1ac9a66 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -362,8 +362,8 @@ int genl_register_family(struct genl_family *family)
362 } else 362 } else
363 family->attrbuf = NULL; 363 family->attrbuf = NULL;
364 364
365 family->id = idr_alloc(&genl_fam_idr, family, 365 family->id = idr_alloc_cyclic(&genl_fam_idr, family,
366 start, end + 1, GFP_KERNEL); 366 start, end + 1, GFP_KERNEL);
367 if (family->id < 0) { 367 if (family->id < 0) {
368 err = family->id; 368 err = family->id;
369 goto errout_free; 369 goto errout_free;
@@ -536,6 +536,28 @@ static int genl_family_rcv_msg(const struct genl_family *family,
536 if (ops->dumpit == NULL) 536 if (ops->dumpit == NULL)
537 return -EOPNOTSUPP; 537 return -EOPNOTSUPP;
538 538
539 if (!(ops->validate & GENL_DONT_VALIDATE_DUMP)) {
540 int hdrlen = GENL_HDRLEN + family->hdrsize;
541
542 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
543 return -EINVAL;
544
545 if (family->maxattr) {
546 unsigned int validate = NL_VALIDATE_STRICT;
547
548 if (ops->validate &
549 GENL_DONT_VALIDATE_DUMP_STRICT)
550 validate = NL_VALIDATE_LIBERAL;
551 rc = __nla_validate(nlmsg_attrdata(nlh, hdrlen),
552 nlmsg_attrlen(nlh, hdrlen),
553 family->maxattr,
554 family->policy,
555 validate, extack);
556 if (rc)
557 return rc;
558 }
559 }
560
539 if (!family->parallel_ops) { 561 if (!family->parallel_ops) {
540 struct netlink_dump_control c = { 562 struct netlink_dump_control c = {
541 .module = family->module, 563 .module = family->module,
@@ -577,8 +599,13 @@ static int genl_family_rcv_msg(const struct genl_family *family,
577 attrbuf = family->attrbuf; 599 attrbuf = family->attrbuf;
578 600
579 if (attrbuf) { 601 if (attrbuf) {
580 err = nlmsg_parse(nlh, hdrlen, attrbuf, family->maxattr, 602 enum netlink_validation validate = NL_VALIDATE_STRICT;
581 ops->policy, extack); 603
604 if (ops->validate & GENL_DONT_VALIDATE_STRICT)
605 validate = NL_VALIDATE_LIBERAL;
606
607 err = __nlmsg_parse(nlh, hdrlen, attrbuf, family->maxattr,
608 family->policy, validate, extack);
582 if (err < 0) 609 if (err < 0)
583 goto out; 610 goto out;
584 } 611 }
@@ -665,7 +692,7 @@ static int ctrl_fill_info(const struct genl_family *family, u32 portid, u32 seq,
665 struct nlattr *nla_ops; 692 struct nlattr *nla_ops;
666 int i; 693 int i;
667 694
668 nla_ops = nla_nest_start(skb, CTRL_ATTR_OPS); 695 nla_ops = nla_nest_start_noflag(skb, CTRL_ATTR_OPS);
669 if (nla_ops == NULL) 696 if (nla_ops == NULL)
670 goto nla_put_failure; 697 goto nla_put_failure;
671 698
@@ -678,10 +705,10 @@ static int ctrl_fill_info(const struct genl_family *family, u32 portid, u32 seq,
678 op_flags |= GENL_CMD_CAP_DUMP; 705 op_flags |= GENL_CMD_CAP_DUMP;
679 if (ops->doit) 706 if (ops->doit)
680 op_flags |= GENL_CMD_CAP_DO; 707 op_flags |= GENL_CMD_CAP_DO;
681 if (ops->policy) 708 if (family->policy)
682 op_flags |= GENL_CMD_CAP_HASPOL; 709 op_flags |= GENL_CMD_CAP_HASPOL;
683 710
684 nest = nla_nest_start(skb, i + 1); 711 nest = nla_nest_start_noflag(skb, i + 1);
685 if (nest == NULL) 712 if (nest == NULL)
686 goto nla_put_failure; 713 goto nla_put_failure;
687 714
@@ -699,7 +726,7 @@ static int ctrl_fill_info(const struct genl_family *family, u32 portid, u32 seq,
699 struct nlattr *nla_grps; 726 struct nlattr *nla_grps;
700 int i; 727 int i;
701 728
702 nla_grps = nla_nest_start(skb, CTRL_ATTR_MCAST_GROUPS); 729 nla_grps = nla_nest_start_noflag(skb, CTRL_ATTR_MCAST_GROUPS);
703 if (nla_grps == NULL) 730 if (nla_grps == NULL)
704 goto nla_put_failure; 731 goto nla_put_failure;
705 732
@@ -709,7 +736,7 @@ static int ctrl_fill_info(const struct genl_family *family, u32 portid, u32 seq,
709 736
710 grp = &family->mcgrps[i]; 737 grp = &family->mcgrps[i];
711 738
712 nest = nla_nest_start(skb, i + 1); 739 nest = nla_nest_start_noflag(skb, i + 1);
713 if (nest == NULL) 740 if (nest == NULL)
714 goto nla_put_failure; 741 goto nla_put_failure;
715 742
@@ -749,11 +776,11 @@ static int ctrl_fill_mcgrp_info(const struct genl_family *family,
749 nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id)) 776 nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id))
750 goto nla_put_failure; 777 goto nla_put_failure;
751 778
752 nla_grps = nla_nest_start(skb, CTRL_ATTR_MCAST_GROUPS); 779 nla_grps = nla_nest_start_noflag(skb, CTRL_ATTR_MCAST_GROUPS);
753 if (nla_grps == NULL) 780 if (nla_grps == NULL)
754 goto nla_put_failure; 781 goto nla_put_failure;
755 782
756 nest = nla_nest_start(skb, 1); 783 nest = nla_nest_start_noflag(skb, 1);
757 if (nest == NULL) 784 if (nest == NULL)
758 goto nla_put_failure; 785 goto nla_put_failure;
759 786
@@ -938,9 +965,9 @@ static int genl_ctrl_event(int event, const struct genl_family *family,
938static const struct genl_ops genl_ctrl_ops[] = { 965static const struct genl_ops genl_ctrl_ops[] = {
939 { 966 {
940 .cmd = CTRL_CMD_GETFAMILY, 967 .cmd = CTRL_CMD_GETFAMILY,
968 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
941 .doit = ctrl_getfamily, 969 .doit = ctrl_getfamily,
942 .dumpit = ctrl_dumpfamily, 970 .dumpit = ctrl_dumpfamily,
943 .policy = ctrl_policy,
944 }, 971 },
945}; 972};
946 973
@@ -958,6 +985,7 @@ static struct genl_family genl_ctrl __ro_after_init = {
958 .name = "nlctrl", 985 .name = "nlctrl",
959 .version = 0x2, 986 .version = 0x2,
960 .maxattr = CTRL_ATTR_MAX, 987 .maxattr = CTRL_ATTR_MAX,
988 .policy = ctrl_policy,
961 .netnsok = true, 989 .netnsok = true,
962}; 990};
963 991
diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index 1d3144d19903..167c09e1ea90 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -1199,7 +1199,6 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1199{ 1199{
1200 struct sock *sk = sock->sk; 1200 struct sock *sk = sock->sk;
1201 void __user *argp = (void __user *)arg; 1201 void __user *argp = (void __user *)arg;
1202 int ret;
1203 1202
1204 switch (cmd) { 1203 switch (cmd) {
1205 case TIOCOUTQ: { 1204 case TIOCOUTQ: {
@@ -1225,18 +1224,6 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1225 return put_user(amount, (int __user *)argp); 1224 return put_user(amount, (int __user *)argp);
1226 } 1225 }
1227 1226
1228 case SIOCGSTAMP:
1229 lock_sock(sk);
1230 ret = sock_get_timestamp(sk, argp);
1231 release_sock(sk);
1232 return ret;
1233
1234 case SIOCGSTAMPNS:
1235 lock_sock(sk);
1236 ret = sock_get_timestampns(sk, argp);
1237 release_sock(sk);
1238 return ret;
1239
1240 case SIOCGIFADDR: 1227 case SIOCGIFADDR:
1241 case SIOCSIFADDR: 1228 case SIOCSIFADDR:
1242 case SIOCGIFDSTADDR: 1229 case SIOCGIFDSTADDR:
@@ -1362,6 +1349,7 @@ static const struct proto_ops nr_proto_ops = {
1362 .getname = nr_getname, 1349 .getname = nr_getname,
1363 .poll = datagram_poll, 1350 .poll = datagram_poll,
1364 .ioctl = nr_ioctl, 1351 .ioctl = nr_ioctl,
1352 .gettstamp = sock_gettstamp,
1365 .listen = nr_listen, 1353 .listen = nr_listen,
1366 .shutdown = sock_no_shutdown, 1354 .shutdown = sock_no_shutdown,
1367 .setsockopt = nr_setsockopt, 1355 .setsockopt = nr_setsockopt,
@@ -1392,18 +1380,22 @@ static int __init nr_proto_init(void)
1392 int i; 1380 int i;
1393 int rc = proto_register(&nr_proto, 0); 1381 int rc = proto_register(&nr_proto, 0);
1394 1382
1395 if (rc != 0) 1383 if (rc)
1396 goto out; 1384 return rc;
1397 1385
1398 if (nr_ndevs > 0x7fffffff/sizeof(struct net_device *)) { 1386 if (nr_ndevs > 0x7fffffff/sizeof(struct net_device *)) {
1399 printk(KERN_ERR "NET/ROM: nr_proto_init - nr_ndevs parameter to large\n"); 1387 pr_err("NET/ROM: %s - nr_ndevs parameter too large\n",
1400 return -1; 1388 __func__);
1389 rc = -EINVAL;
1390 goto unregister_proto;
1401 } 1391 }
1402 1392
1403 dev_nr = kcalloc(nr_ndevs, sizeof(struct net_device *), GFP_KERNEL); 1393 dev_nr = kcalloc(nr_ndevs, sizeof(struct net_device *), GFP_KERNEL);
1404 if (dev_nr == NULL) { 1394 if (!dev_nr) {
1405 printk(KERN_ERR "NET/ROM: nr_proto_init - unable to allocate device array\n"); 1395 pr_err("NET/ROM: %s - unable to allocate device array\n",
1406 return -1; 1396 __func__);
1397 rc = -ENOMEM;
1398 goto unregister_proto;
1407 } 1399 }
1408 1400
1409 for (i = 0; i < nr_ndevs; i++) { 1401 for (i = 0; i < nr_ndevs; i++) {
@@ -1413,13 +1405,13 @@ static int __init nr_proto_init(void)
1413 sprintf(name, "nr%d", i); 1405 sprintf(name, "nr%d", i);
1414 dev = alloc_netdev(0, name, NET_NAME_UNKNOWN, nr_setup); 1406 dev = alloc_netdev(0, name, NET_NAME_UNKNOWN, nr_setup);
1415 if (!dev) { 1407 if (!dev) {
1416 printk(KERN_ERR "NET/ROM: nr_proto_init - unable to allocate device structure\n"); 1408 rc = -ENOMEM;
1417 goto fail; 1409 goto fail;
1418 } 1410 }
1419 1411
1420 dev->base_addr = i; 1412 dev->base_addr = i;
1421 if (register_netdev(dev)) { 1413 rc = register_netdev(dev);
1422 printk(KERN_ERR "NET/ROM: nr_proto_init - unable to register network device\n"); 1414 if (rc) {
1423 free_netdev(dev); 1415 free_netdev(dev);
1424 goto fail; 1416 goto fail;
1425 } 1417 }
@@ -1427,36 +1419,64 @@ static int __init nr_proto_init(void)
1427 dev_nr[i] = dev; 1419 dev_nr[i] = dev;
1428 } 1420 }
1429 1421
1430 if (sock_register(&nr_family_ops)) { 1422 rc = sock_register(&nr_family_ops);
1431 printk(KERN_ERR "NET/ROM: nr_proto_init - unable to register socket family\n"); 1423 if (rc)
1432 goto fail; 1424 goto fail;
1433 }
1434 1425
1435 register_netdevice_notifier(&nr_dev_notifier); 1426 rc = register_netdevice_notifier(&nr_dev_notifier);
1427 if (rc)
1428 goto out_sock;
1436 1429
1437 ax25_register_pid(&nr_pid); 1430 ax25_register_pid(&nr_pid);
1438 ax25_linkfail_register(&nr_linkfail_notifier); 1431 ax25_linkfail_register(&nr_linkfail_notifier);
1439 1432
1440#ifdef CONFIG_SYSCTL 1433#ifdef CONFIG_SYSCTL
1441 nr_register_sysctl(); 1434 rc = nr_register_sysctl();
1435 if (rc)
1436 goto out_sysctl;
1442#endif 1437#endif
1443 1438
1444 nr_loopback_init(); 1439 nr_loopback_init();
1445 1440
1446 proc_create_seq("nr", 0444, init_net.proc_net, &nr_info_seqops); 1441 rc = -ENOMEM;
1447 proc_create_seq("nr_neigh", 0444, init_net.proc_net, &nr_neigh_seqops); 1442 if (!proc_create_seq("nr", 0444, init_net.proc_net, &nr_info_seqops))
1448 proc_create_seq("nr_nodes", 0444, init_net.proc_net, &nr_node_seqops); 1443 goto proc_remove1;
1449out: 1444 if (!proc_create_seq("nr_neigh", 0444, init_net.proc_net,
1450 return rc; 1445 &nr_neigh_seqops))
1446 goto proc_remove2;
1447 if (!proc_create_seq("nr_nodes", 0444, init_net.proc_net,
1448 &nr_node_seqops))
1449 goto proc_remove3;
1450
1451 return 0;
1452
1453proc_remove3:
1454 remove_proc_entry("nr_neigh", init_net.proc_net);
1455proc_remove2:
1456 remove_proc_entry("nr", init_net.proc_net);
1457proc_remove1:
1458
1459 nr_loopback_clear();
1460 nr_rt_free();
1461
1462#ifdef CONFIG_SYSCTL
1463 nr_unregister_sysctl();
1464out_sysctl:
1465#endif
1466 ax25_linkfail_release(&nr_linkfail_notifier);
1467 ax25_protocol_release(AX25_P_NETROM);
1468 unregister_netdevice_notifier(&nr_dev_notifier);
1469out_sock:
1470 sock_unregister(PF_NETROM);
1451fail: 1471fail:
1452 while (--i >= 0) { 1472 while (--i >= 0) {
1453 unregister_netdev(dev_nr[i]); 1473 unregister_netdev(dev_nr[i]);
1454 free_netdev(dev_nr[i]); 1474 free_netdev(dev_nr[i]);
1455 } 1475 }
1456 kfree(dev_nr); 1476 kfree(dev_nr);
1477unregister_proto:
1457 proto_unregister(&nr_proto); 1478 proto_unregister(&nr_proto);
1458 rc = -1; 1479 return rc;
1459 goto out;
1460} 1480}
1461 1481
1462module_init(nr_proto_init); 1482module_init(nr_proto_init);
diff --git a/net/netrom/nr_loopback.c b/net/netrom/nr_loopback.c
index 215ad22a9647..93d13f019981 100644
--- a/net/netrom/nr_loopback.c
+++ b/net/netrom/nr_loopback.c
@@ -70,7 +70,7 @@ static void nr_loopback_timer(struct timer_list *unused)
70 } 70 }
71} 71}
72 72
73void __exit nr_loopback_clear(void) 73void nr_loopback_clear(void)
74{ 74{
75 del_timer_sync(&loopback_timer); 75 del_timer_sync(&loopback_timer);
76 skb_queue_purge(&loopback_queue); 76 skb_queue_purge(&loopback_queue);
diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index 6485f593e2f0..b76aa668a94b 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -953,7 +953,7 @@ const struct seq_operations nr_neigh_seqops = {
953/* 953/*
954 * Free all memory associated with the nodes and routes lists. 954 * Free all memory associated with the nodes and routes lists.
955 */ 955 */
956void __exit nr_rt_free(void) 956void nr_rt_free(void)
957{ 957{
958 struct nr_neigh *s = NULL; 958 struct nr_neigh *s = NULL;
959 struct nr_node *t = NULL; 959 struct nr_node *t = NULL;
diff --git a/net/netrom/sysctl_net_netrom.c b/net/netrom/sysctl_net_netrom.c
index ba1c368b3f18..771011b84270 100644
--- a/net/netrom/sysctl_net_netrom.c
+++ b/net/netrom/sysctl_net_netrom.c
@@ -146,9 +146,12 @@ static struct ctl_table nr_table[] = {
146 { } 146 { }
147}; 147};
148 148
149void __init nr_register_sysctl(void) 149int __init nr_register_sysctl(void)
150{ 150{
151 nr_table_header = register_net_sysctl(&init_net, "net/netrom", nr_table); 151 nr_table_header = register_net_sysctl(&init_net, "net/netrom", nr_table);
152 if (!nr_table_header)
153 return -ENOMEM;
154 return 0;
152} 155}
153 156
154void nr_unregister_sysctl(void) 157void nr_unregister_sysctl(void)
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 376181cc1def..04a8e47674ec 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -119,9 +119,10 @@ static struct nfc_dev *__get_device_from_cb(struct netlink_callback *cb)
119 int rc; 119 int rc;
120 u32 idx; 120 u32 idx;
121 121
122 rc = nlmsg_parse(cb->nlh, GENL_HDRLEN + nfc_genl_family.hdrsize, 122 rc = nlmsg_parse_deprecated(cb->nlh,
123 attrbuf, nfc_genl_family.maxattr, nfc_genl_policy, 123 GENL_HDRLEN + nfc_genl_family.hdrsize,
124 NULL); 124 attrbuf, nfc_genl_family.maxattr,
125 nfc_genl_policy, NULL);
125 if (rc < 0) 126 if (rc < 0)
126 return ERR_PTR(rc); 127 return ERR_PTR(rc);
127 128
@@ -392,7 +393,7 @@ int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)
392 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx)) 393 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
393 goto nla_put_failure; 394 goto nla_put_failure;
394 395
395 sdp_attr = nla_nest_start(msg, NFC_ATTR_LLC_SDP); 396 sdp_attr = nla_nest_start_noflag(msg, NFC_ATTR_LLC_SDP);
396 if (sdp_attr == NULL) { 397 if (sdp_attr == NULL) {
397 rc = -ENOMEM; 398 rc = -ENOMEM;
398 goto nla_put_failure; 399 goto nla_put_failure;
@@ -402,7 +403,7 @@ int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)
402 hlist_for_each_entry_safe(sdres, n, sdres_list, node) { 403 hlist_for_each_entry_safe(sdres, n, sdres_list, node) {
403 pr_debug("uri: %s, sap: %d\n", sdres->uri, sdres->sap); 404 pr_debug("uri: %s, sap: %d\n", sdres->uri, sdres->sap);
404 405
405 uri_attr = nla_nest_start(msg, i++); 406 uri_attr = nla_nest_start_noflag(msg, i++);
406 if (uri_attr == NULL) { 407 if (uri_attr == NULL) {
407 rc = -ENOMEM; 408 rc = -ENOMEM;
408 goto nla_put_failure; 409 goto nla_put_failure;
@@ -1177,8 +1178,9 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
1177 tlvs_len = 0; 1178 tlvs_len = 0;
1178 1179
1179 nla_for_each_nested(attr, info->attrs[NFC_ATTR_LLC_SDP], rem) { 1180 nla_for_each_nested(attr, info->attrs[NFC_ATTR_LLC_SDP], rem) {
1180 rc = nla_parse_nested(sdp_attrs, NFC_SDP_ATTR_MAX, attr, 1181 rc = nla_parse_nested_deprecated(sdp_attrs, NFC_SDP_ATTR_MAX,
1181 nfc_sdp_genl_policy, info->extack); 1182 attr, nfc_sdp_genl_policy,
1183 info->extack);
1182 1184
1183 if (rc != 0) { 1185 if (rc != 0) {
1184 rc = -EINVAL; 1186 rc = -EINVAL;
@@ -1667,102 +1669,102 @@ EXPORT_SYMBOL(nfc_vendor_cmd_reply);
1667static const struct genl_ops nfc_genl_ops[] = { 1669static const struct genl_ops nfc_genl_ops[] = {
1668 { 1670 {
1669 .cmd = NFC_CMD_GET_DEVICE, 1671 .cmd = NFC_CMD_GET_DEVICE,
1672 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1670 .doit = nfc_genl_get_device, 1673 .doit = nfc_genl_get_device,
1671 .dumpit = nfc_genl_dump_devices, 1674 .dumpit = nfc_genl_dump_devices,
1672 .done = nfc_genl_dump_devices_done, 1675 .done = nfc_genl_dump_devices_done,
1673 .policy = nfc_genl_policy,
1674 }, 1676 },
1675 { 1677 {
1676 .cmd = NFC_CMD_DEV_UP, 1678 .cmd = NFC_CMD_DEV_UP,
1679 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1677 .doit = nfc_genl_dev_up, 1680 .doit = nfc_genl_dev_up,
1678 .policy = nfc_genl_policy,
1679 }, 1681 },
1680 { 1682 {
1681 .cmd = NFC_CMD_DEV_DOWN, 1683 .cmd = NFC_CMD_DEV_DOWN,
1684 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1682 .doit = nfc_genl_dev_down, 1685 .doit = nfc_genl_dev_down,
1683 .policy = nfc_genl_policy,
1684 }, 1686 },
1685 { 1687 {
1686 .cmd = NFC_CMD_START_POLL, 1688 .cmd = NFC_CMD_START_POLL,
1689 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1687 .doit = nfc_genl_start_poll, 1690 .doit = nfc_genl_start_poll,
1688 .policy = nfc_genl_policy,
1689 }, 1691 },
1690 { 1692 {
1691 .cmd = NFC_CMD_STOP_POLL, 1693 .cmd = NFC_CMD_STOP_POLL,
1694 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1692 .doit = nfc_genl_stop_poll, 1695 .doit = nfc_genl_stop_poll,
1693 .policy = nfc_genl_policy,
1694 }, 1696 },
1695 { 1697 {
1696 .cmd = NFC_CMD_DEP_LINK_UP, 1698 .cmd = NFC_CMD_DEP_LINK_UP,
1699 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1697 .doit = nfc_genl_dep_link_up, 1700 .doit = nfc_genl_dep_link_up,
1698 .policy = nfc_genl_policy,
1699 }, 1701 },
1700 { 1702 {
1701 .cmd = NFC_CMD_DEP_LINK_DOWN, 1703 .cmd = NFC_CMD_DEP_LINK_DOWN,
1704 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1702 .doit = nfc_genl_dep_link_down, 1705 .doit = nfc_genl_dep_link_down,
1703 .policy = nfc_genl_policy,
1704 }, 1706 },
1705 { 1707 {
1706 .cmd = NFC_CMD_GET_TARGET, 1708 .cmd = NFC_CMD_GET_TARGET,
1709 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1707 .dumpit = nfc_genl_dump_targets, 1710 .dumpit = nfc_genl_dump_targets,
1708 .done = nfc_genl_dump_targets_done, 1711 .done = nfc_genl_dump_targets_done,
1709 .policy = nfc_genl_policy,
1710 }, 1712 },
1711 { 1713 {
1712 .cmd = NFC_CMD_LLC_GET_PARAMS, 1714 .cmd = NFC_CMD_LLC_GET_PARAMS,
1715 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1713 .doit = nfc_genl_llc_get_params, 1716 .doit = nfc_genl_llc_get_params,
1714 .policy = nfc_genl_policy,
1715 }, 1717 },
1716 { 1718 {
1717 .cmd = NFC_CMD_LLC_SET_PARAMS, 1719 .cmd = NFC_CMD_LLC_SET_PARAMS,
1720 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1718 .doit = nfc_genl_llc_set_params, 1721 .doit = nfc_genl_llc_set_params,
1719 .policy = nfc_genl_policy,
1720 }, 1722 },
1721 { 1723 {
1722 .cmd = NFC_CMD_LLC_SDREQ, 1724 .cmd = NFC_CMD_LLC_SDREQ,
1725 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1723 .doit = nfc_genl_llc_sdreq, 1726 .doit = nfc_genl_llc_sdreq,
1724 .policy = nfc_genl_policy,
1725 }, 1727 },
1726 { 1728 {
1727 .cmd = NFC_CMD_FW_DOWNLOAD, 1729 .cmd = NFC_CMD_FW_DOWNLOAD,
1730 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1728 .doit = nfc_genl_fw_download, 1731 .doit = nfc_genl_fw_download,
1729 .policy = nfc_genl_policy,
1730 }, 1732 },
1731 { 1733 {
1732 .cmd = NFC_CMD_ENABLE_SE, 1734 .cmd = NFC_CMD_ENABLE_SE,
1735 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1733 .doit = nfc_genl_enable_se, 1736 .doit = nfc_genl_enable_se,
1734 .policy = nfc_genl_policy,
1735 }, 1737 },
1736 { 1738 {
1737 .cmd = NFC_CMD_DISABLE_SE, 1739 .cmd = NFC_CMD_DISABLE_SE,
1740 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1738 .doit = nfc_genl_disable_se, 1741 .doit = nfc_genl_disable_se,
1739 .policy = nfc_genl_policy,
1740 }, 1742 },
1741 { 1743 {
1742 .cmd = NFC_CMD_GET_SE, 1744 .cmd = NFC_CMD_GET_SE,
1745 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1743 .dumpit = nfc_genl_dump_ses, 1746 .dumpit = nfc_genl_dump_ses,
1744 .done = nfc_genl_dump_ses_done, 1747 .done = nfc_genl_dump_ses_done,
1745 .policy = nfc_genl_policy,
1746 }, 1748 },
1747 { 1749 {
1748 .cmd = NFC_CMD_SE_IO, 1750 .cmd = NFC_CMD_SE_IO,
1751 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1749 .doit = nfc_genl_se_io, 1752 .doit = nfc_genl_se_io,
1750 .policy = nfc_genl_policy,
1751 }, 1753 },
1752 { 1754 {
1753 .cmd = NFC_CMD_ACTIVATE_TARGET, 1755 .cmd = NFC_CMD_ACTIVATE_TARGET,
1756 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1754 .doit = nfc_genl_activate_target, 1757 .doit = nfc_genl_activate_target,
1755 .policy = nfc_genl_policy,
1756 }, 1758 },
1757 { 1759 {
1758 .cmd = NFC_CMD_VENDOR, 1760 .cmd = NFC_CMD_VENDOR,
1761 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1759 .doit = nfc_genl_vendor_cmd, 1762 .doit = nfc_genl_vendor_cmd,
1760 .policy = nfc_genl_policy,
1761 }, 1763 },
1762 { 1764 {
1763 .cmd = NFC_CMD_DEACTIVATE_TARGET, 1765 .cmd = NFC_CMD_DEACTIVATE_TARGET,
1766 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1764 .doit = nfc_genl_deactivate_target, 1767 .doit = nfc_genl_deactivate_target,
1765 .policy = nfc_genl_policy,
1766 }, 1768 },
1767}; 1769};
1768 1770
@@ -1771,6 +1773,7 @@ static struct genl_family nfc_genl_family __ro_after_init = {
1771 .name = NFC_GENL_NAME, 1773 .name = NFC_GENL_NAME,
1772 .version = NFC_GENL_VERSION, 1774 .version = NFC_GENL_VERSION,
1773 .maxattr = NFC_ATTR_MAX, 1775 .maxattr = NFC_ATTR_MAX,
1776 .policy = nfc_genl_policy,
1774 .module = THIS_MODULE, 1777 .module = THIS_MODULE,
1775 .ops = nfc_genl_ops, 1778 .ops = nfc_genl_ops,
1776 .n_ops = ARRAY_SIZE(nfc_genl_ops), 1779 .n_ops = ARRAY_SIZE(nfc_genl_ops),
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index e47ebbbe71b8..2c151bb322c1 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -169,6 +169,10 @@ static int clone_execute(struct datapath *dp, struct sk_buff *skb,
169 const struct nlattr *actions, int len, 169 const struct nlattr *actions, int len,
170 bool last, bool clone_flow_key); 170 bool last, bool clone_flow_key);
171 171
172static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
173 struct sw_flow_key *key,
174 const struct nlattr *attr, int len);
175
172static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr, 176static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr,
173 __be16 ethertype) 177 __be16 ethertype)
174{ 178{
@@ -1213,6 +1217,40 @@ static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
1213 return clone_execute(dp, skb, key, recirc_id, NULL, 0, last, true); 1217 return clone_execute(dp, skb, key, recirc_id, NULL, 0, last, true);
1214} 1218}
1215 1219
1220static int execute_check_pkt_len(struct datapath *dp, struct sk_buff *skb,
1221 struct sw_flow_key *key,
1222 const struct nlattr *attr, bool last)
1223{
1224 const struct nlattr *actions, *cpl_arg;
1225 const struct check_pkt_len_arg *arg;
1226 int rem = nla_len(attr);
1227 bool clone_flow_key;
1228
1229 /* The first netlink attribute in 'attr' is always
1230 * 'OVS_CHECK_PKT_LEN_ATTR_ARG'.
1231 */
1232 cpl_arg = nla_data(attr);
1233 arg = nla_data(cpl_arg);
1234
1235 if (skb->len <= arg->pkt_len) {
1236 /* Second netlink attribute in 'attr' is always
1237 * 'OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL'.
1238 */
1239 actions = nla_next(cpl_arg, &rem);
1240 clone_flow_key = !arg->exec_for_lesser_equal;
1241 } else {
1242 /* Third netlink attribute in 'attr' is always
1243 * 'OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER'.
1244 */
1245 actions = nla_next(cpl_arg, &rem);
1246 actions = nla_next(actions, &rem);
1247 clone_flow_key = !arg->exec_for_greater;
1248 }
1249
1250 return clone_execute(dp, skb, key, 0, nla_data(actions),
1251 nla_len(actions), last, clone_flow_key);
1252}
1253
1216/* Execute a list of actions against 'skb'. */ 1254/* Execute a list of actions against 'skb'. */
1217static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, 1255static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
1218 struct sw_flow_key *key, 1256 struct sw_flow_key *key,
@@ -1374,6 +1412,16 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
1374 1412
1375 break; 1413 break;
1376 } 1414 }
1415
1416 case OVS_ACTION_ATTR_CHECK_PKT_LEN: {
1417 bool last = nla_is_last(a, rem);
1418
1419 err = execute_check_pkt_len(dp, skb, key, a, last);
1420 if (last)
1421 return err;
1422
1423 break;
1424 }
1377 } 1425 }
1378 1426
1379 if (unlikely(err)) { 1427 if (unlikely(err)) {
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 1b6896896fff..4c597a0bb168 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -24,11 +24,12 @@
24#include <net/netfilter/nf_conntrack_helper.h> 24#include <net/netfilter/nf_conntrack_helper.h>
25#include <net/netfilter/nf_conntrack_labels.h> 25#include <net/netfilter/nf_conntrack_labels.h>
26#include <net/netfilter/nf_conntrack_seqadj.h> 26#include <net/netfilter/nf_conntrack_seqadj.h>
27#include <net/netfilter/nf_conntrack_timeout.h>
27#include <net/netfilter/nf_conntrack_zones.h> 28#include <net/netfilter/nf_conntrack_zones.h>
28#include <net/netfilter/ipv6/nf_defrag_ipv6.h> 29#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
29#include <net/ipv6_frag.h> 30#include <net/ipv6_frag.h>
30 31
31#ifdef CONFIG_NF_NAT_NEEDED 32#if IS_ENABLED(CONFIG_NF_NAT)
32#include <net/netfilter/nf_nat.h> 33#include <net/netfilter/nf_nat.h>
33#endif 34#endif
34 35
@@ -73,7 +74,8 @@ struct ovs_conntrack_info {
73 u32 eventmask; /* Mask of 1 << IPCT_*. */ 74 u32 eventmask; /* Mask of 1 << IPCT_*. */
74 struct md_mark mark; 75 struct md_mark mark;
75 struct md_labels labels; 76 struct md_labels labels;
76#ifdef CONFIG_NF_NAT_NEEDED 77 char timeout[CTNL_TIMEOUT_NAME_MAX];
78#if IS_ENABLED(CONFIG_NF_NAT)
77 struct nf_nat_range2 range; /* Only present for SRC NAT and DST NAT. */ 79 struct nf_nat_range2 range; /* Only present for SRC NAT and DST NAT. */
78#endif 80#endif
79}; 81};
@@ -719,7 +721,7 @@ static bool skb_nfct_cached(struct net *net,
719 return ct_executed; 721 return ct_executed;
720} 722}
721 723
722#ifdef CONFIG_NF_NAT_NEEDED 724#if IS_ENABLED(CONFIG_NF_NAT)
723/* Modelled after nf_nat_ipv[46]_fn(). 725/* Modelled after nf_nat_ipv[46]_fn().
724 * range is only used for new, uninitialized NAT state. 726 * range is only used for new, uninitialized NAT state.
725 * Returns either NF_ACCEPT or NF_DROP. 727 * Returns either NF_ACCEPT or NF_DROP.
@@ -901,7 +903,7 @@ static int ovs_ct_nat(struct net *net, struct sw_flow_key *key,
901 903
902 return err; 904 return err;
903} 905}
904#else /* !CONFIG_NF_NAT_NEEDED */ 906#else /* !CONFIG_NF_NAT */
905static int ovs_ct_nat(struct net *net, struct sw_flow_key *key, 907static int ovs_ct_nat(struct net *net, struct sw_flow_key *key,
906 const struct ovs_conntrack_info *info, 908 const struct ovs_conntrack_info *info,
907 struct sk_buff *skb, struct nf_conn *ct, 909 struct sk_buff *skb, struct nf_conn *ct,
@@ -990,6 +992,12 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
990 GFP_ATOMIC); 992 GFP_ATOMIC);
991 if (err) 993 if (err)
992 return err; 994 return err;
995
996 /* helper installed, add seqadj if NAT is required */
997 if (info->nat && !nfct_seqadj(ct)) {
998 if (!nfct_seqadj_ext_add(ct))
999 return -EINVAL;
1000 }
993 } 1001 }
994 1002
995 /* Call the helper only if: 1003 /* Call the helper only if:
@@ -1299,6 +1307,7 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,
1299{ 1307{
1300 struct nf_conntrack_helper *helper; 1308 struct nf_conntrack_helper *helper;
1301 struct nf_conn_help *help; 1309 struct nf_conn_help *help;
1310 int ret = 0;
1302 1311
1303 helper = nf_conntrack_helper_try_module_get(name, info->family, 1312 helper = nf_conntrack_helper_try_module_get(name, info->family,
1304 key->ip.proto); 1313 key->ip.proto);
@@ -1313,16 +1322,24 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,
1313 return -ENOMEM; 1322 return -ENOMEM;
1314 } 1323 }
1315 1324
1325#if IS_ENABLED(CONFIG_NF_NAT)
1326 if (info->nat) {
1327 ret = nf_nat_helper_try_module_get(name, info->family,
1328 key->ip.proto);
1329 if (ret) {
1330 nf_conntrack_helper_put(helper);
1331 OVS_NLERR(log, "Failed to load \"%s\" NAT helper, error: %d",
1332 name, ret);
1333 return ret;
1334 }
1335 }
1336#endif
1316 rcu_assign_pointer(help->helper, helper); 1337 rcu_assign_pointer(help->helper, helper);
1317 info->helper = helper; 1338 info->helper = helper;
1318 1339 return ret;
1319 if (info->nat)
1320 request_module("ip_nat_%s", name);
1321
1322 return 0;
1323} 1340}
1324 1341
1325#ifdef CONFIG_NF_NAT_NEEDED 1342#if IS_ENABLED(CONFIG_NF_NAT)
1326static int parse_nat(const struct nlattr *attr, 1343static int parse_nat(const struct nlattr *attr,
1327 struct ovs_conntrack_info *info, bool log) 1344 struct ovs_conntrack_info *info, bool log)
1328{ 1345{
@@ -1459,12 +1476,14 @@ static const struct ovs_ct_len_tbl ovs_ct_attr_lens[OVS_CT_ATTR_MAX + 1] = {
1459 .maxlen = sizeof(struct md_labels) }, 1476 .maxlen = sizeof(struct md_labels) },
1460 [OVS_CT_ATTR_HELPER] = { .minlen = 1, 1477 [OVS_CT_ATTR_HELPER] = { .minlen = 1,
1461 .maxlen = NF_CT_HELPER_NAME_LEN }, 1478 .maxlen = NF_CT_HELPER_NAME_LEN },
1462#ifdef CONFIG_NF_NAT_NEEDED 1479#if IS_ENABLED(CONFIG_NF_NAT)
1463 /* NAT length is checked when parsing the nested attributes. */ 1480 /* NAT length is checked when parsing the nested attributes. */
1464 [OVS_CT_ATTR_NAT] = { .minlen = 0, .maxlen = INT_MAX }, 1481 [OVS_CT_ATTR_NAT] = { .minlen = 0, .maxlen = INT_MAX },
1465#endif 1482#endif
1466 [OVS_CT_ATTR_EVENTMASK] = { .minlen = sizeof(u32), 1483 [OVS_CT_ATTR_EVENTMASK] = { .minlen = sizeof(u32),
1467 .maxlen = sizeof(u32) }, 1484 .maxlen = sizeof(u32) },
1485 [OVS_CT_ATTR_TIMEOUT] = { .minlen = 1,
1486 .maxlen = CTNL_TIMEOUT_NAME_MAX },
1468}; 1487};
1469 1488
1470static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info, 1489static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
@@ -1537,7 +1556,7 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
1537 return -EINVAL; 1556 return -EINVAL;
1538 } 1557 }
1539 break; 1558 break;
1540#ifdef CONFIG_NF_NAT_NEEDED 1559#if IS_ENABLED(CONFIG_NF_NAT)
1541 case OVS_CT_ATTR_NAT: { 1560 case OVS_CT_ATTR_NAT: {
1542 int err = parse_nat(a, info, log); 1561 int err = parse_nat(a, info, log);
1543 1562
@@ -1550,6 +1569,15 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
1550 info->have_eventmask = true; 1569 info->have_eventmask = true;
1551 info->eventmask = nla_get_u32(a); 1570 info->eventmask = nla_get_u32(a);
1552 break; 1571 break;
1572#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
1573 case OVS_CT_ATTR_TIMEOUT:
1574 memcpy(info->timeout, nla_data(a), nla_len(a));
1575 if (!memchr(info->timeout, '\0', nla_len(a))) {
1576 OVS_NLERR(log, "Invalid conntrack helper");
1577 return -EINVAL;
1578 }
1579 break;
1580#endif
1553 1581
1554 default: 1582 default:
1555 OVS_NLERR(log, "Unknown conntrack attr (%d)", 1583 OVS_NLERR(log, "Unknown conntrack attr (%d)",
@@ -1631,6 +1659,14 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,
1631 OVS_NLERR(log, "Failed to allocate conntrack template"); 1659 OVS_NLERR(log, "Failed to allocate conntrack template");
1632 return -ENOMEM; 1660 return -ENOMEM;
1633 } 1661 }
1662
1663 if (ct_info.timeout[0]) {
1664 if (nf_ct_set_timeout(net, ct_info.ct, family, key->ip.proto,
1665 ct_info.timeout))
1666 pr_info_ratelimited("Failed to associated timeout "
1667 "policy `%s'\n", ct_info.timeout);
1668 }
1669
1634 if (helper) { 1670 if (helper) {
1635 err = ovs_ct_add_helper(&ct_info, helper, key, log); 1671 err = ovs_ct_add_helper(&ct_info, helper, key, log);
1636 if (err) 1672 if (err)
@@ -1650,13 +1686,13 @@ err_free_ct:
1650 return err; 1686 return err;
1651} 1687}
1652 1688
1653#ifdef CONFIG_NF_NAT_NEEDED 1689#if IS_ENABLED(CONFIG_NF_NAT)
1654static bool ovs_ct_nat_to_attr(const struct ovs_conntrack_info *info, 1690static bool ovs_ct_nat_to_attr(const struct ovs_conntrack_info *info,
1655 struct sk_buff *skb) 1691 struct sk_buff *skb)
1656{ 1692{
1657 struct nlattr *start; 1693 struct nlattr *start;
1658 1694
1659 start = nla_nest_start(skb, OVS_CT_ATTR_NAT); 1695 start = nla_nest_start_noflag(skb, OVS_CT_ATTR_NAT);
1660 if (!start) 1696 if (!start)
1661 return false; 1697 return false;
1662 1698
@@ -1723,7 +1759,7 @@ int ovs_ct_action_to_attr(const struct ovs_conntrack_info *ct_info,
1723{ 1759{
1724 struct nlattr *start; 1760 struct nlattr *start;
1725 1761
1726 start = nla_nest_start(skb, OVS_ACTION_ATTR_CT); 1762 start = nla_nest_start_noflag(skb, OVS_ACTION_ATTR_CT);
1727 if (!start) 1763 if (!start)
1728 return -EMSGSIZE; 1764 return -EMSGSIZE;
1729 1765
@@ -1751,8 +1787,12 @@ int ovs_ct_action_to_attr(const struct ovs_conntrack_info *ct_info,
1751 if (ct_info->have_eventmask && 1787 if (ct_info->have_eventmask &&
1752 nla_put_u32(skb, OVS_CT_ATTR_EVENTMASK, ct_info->eventmask)) 1788 nla_put_u32(skb, OVS_CT_ATTR_EVENTMASK, ct_info->eventmask))
1753 return -EMSGSIZE; 1789 return -EMSGSIZE;
1790 if (ct_info->timeout[0]) {
1791 if (nla_put_string(skb, OVS_CT_ATTR_TIMEOUT, ct_info->timeout))
1792 return -EMSGSIZE;
1793 }
1754 1794
1755#ifdef CONFIG_NF_NAT_NEEDED 1795#if IS_ENABLED(CONFIG_NF_NAT)
1756 if (ct_info->nat && !ovs_ct_nat_to_attr(ct_info, skb)) 1796 if (ct_info->nat && !ovs_ct_nat_to_attr(ct_info, skb))
1757 return -EMSGSIZE; 1797 return -EMSGSIZE;
1758#endif 1798#endif
@@ -1770,10 +1810,18 @@ void ovs_ct_free_action(const struct nlattr *a)
1770 1810
1771static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info) 1811static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info)
1772{ 1812{
1773 if (ct_info->helper) 1813 if (ct_info->helper) {
1814#if IS_ENABLED(CONFIG_NF_NAT)
1815 if (ct_info->nat)
1816 nf_nat_helper_put(ct_info->helper);
1817#endif
1774 nf_conntrack_helper_put(ct_info->helper); 1818 nf_conntrack_helper_put(ct_info->helper);
1775 if (ct_info->ct) 1819 }
1820 if (ct_info->ct) {
1821 if (ct_info->timeout[0])
1822 nf_ct_destroy_timeout(ct_info->ct);
1776 nf_ct_tmpl_free(ct_info->ct); 1823 nf_ct_tmpl_free(ct_info->ct);
1824 }
1777} 1825}
1778 1826
1779#if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT) 1827#if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
@@ -2126,7 +2174,11 @@ static int ovs_ct_limit_cmd_get(struct sk_buff *skb, struct genl_info *info)
2126 if (IS_ERR(reply)) 2174 if (IS_ERR(reply))
2127 return PTR_ERR(reply); 2175 return PTR_ERR(reply);
2128 2176
2129 nla_reply = nla_nest_start(reply, OVS_CT_LIMIT_ATTR_ZONE_LIMIT); 2177 nla_reply = nla_nest_start_noflag(reply, OVS_CT_LIMIT_ATTR_ZONE_LIMIT);
2178 if (!nla_reply) {
2179 err = -EMSGSIZE;
2180 goto exit_err;
2181 }
2130 2182
2131 if (a[OVS_CT_LIMIT_ATTR_ZONE_LIMIT]) { 2183 if (a[OVS_CT_LIMIT_ATTR_ZONE_LIMIT]) {
2132 err = ovs_ct_limit_get_zone_limit( 2184 err = ovs_ct_limit_get_zone_limit(
@@ -2152,20 +2204,20 @@ exit_err:
2152 2204
2153static struct genl_ops ct_limit_genl_ops[] = { 2205static struct genl_ops ct_limit_genl_ops[] = {
2154 { .cmd = OVS_CT_LIMIT_CMD_SET, 2206 { .cmd = OVS_CT_LIMIT_CMD_SET,
2207 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2155 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN 2208 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
2156 * privilege. */ 2209 * privilege. */
2157 .policy = ct_limit_policy,
2158 .doit = ovs_ct_limit_cmd_set, 2210 .doit = ovs_ct_limit_cmd_set,
2159 }, 2211 },
2160 { .cmd = OVS_CT_LIMIT_CMD_DEL, 2212 { .cmd = OVS_CT_LIMIT_CMD_DEL,
2213 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2161 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN 2214 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
2162 * privilege. */ 2215 * privilege. */
2163 .policy = ct_limit_policy,
2164 .doit = ovs_ct_limit_cmd_del, 2216 .doit = ovs_ct_limit_cmd_del,
2165 }, 2217 },
2166 { .cmd = OVS_CT_LIMIT_CMD_GET, 2218 { .cmd = OVS_CT_LIMIT_CMD_GET,
2219 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2167 .flags = 0, /* OK for unprivileged users. */ 2220 .flags = 0, /* OK for unprivileged users. */
2168 .policy = ct_limit_policy,
2169 .doit = ovs_ct_limit_cmd_get, 2221 .doit = ovs_ct_limit_cmd_get,
2170 }, 2222 },
2171}; 2223};
@@ -2179,6 +2231,7 @@ struct genl_family dp_ct_limit_genl_family __ro_after_init = {
2179 .name = OVS_CT_LIMIT_FAMILY, 2231 .name = OVS_CT_LIMIT_FAMILY,
2180 .version = OVS_CT_LIMIT_VERSION, 2232 .version = OVS_CT_LIMIT_VERSION,
2181 .maxattr = OVS_CT_LIMIT_ATTR_MAX, 2233 .maxattr = OVS_CT_LIMIT_ATTR_MAX,
2234 .policy = ct_limit_policy,
2182 .netnsok = true, 2235 .netnsok = true,
2183 .parallel_ops = true, 2236 .parallel_ops = true,
2184 .ops = ct_limit_genl_ops, 2237 .ops = ct_limit_genl_ops,
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index 9dd158ab51b3..dc9ff9367221 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -455,7 +455,8 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
455 upcall->dp_ifindex = dp_ifindex; 455 upcall->dp_ifindex = dp_ifindex;
456 456
457 err = ovs_nla_put_key(key, key, OVS_PACKET_ATTR_KEY, false, user_skb); 457 err = ovs_nla_put_key(key, key, OVS_PACKET_ATTR_KEY, false, user_skb);
458 BUG_ON(err); 458 if (err)
459 goto out;
459 460
460 if (upcall_info->userdata) 461 if (upcall_info->userdata)
461 __nla_put(user_skb, OVS_PACKET_ATTR_USERDATA, 462 __nla_put(user_skb, OVS_PACKET_ATTR_USERDATA,
@@ -463,19 +464,22 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
463 nla_data(upcall_info->userdata)); 464 nla_data(upcall_info->userdata));
464 465
465 if (upcall_info->egress_tun_info) { 466 if (upcall_info->egress_tun_info) {
466 nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_EGRESS_TUN_KEY); 467 nla = nla_nest_start_noflag(user_skb,
468 OVS_PACKET_ATTR_EGRESS_TUN_KEY);
467 if (!nla) { 469 if (!nla) {
468 err = -EMSGSIZE; 470 err = -EMSGSIZE;
469 goto out; 471 goto out;
470 } 472 }
471 err = ovs_nla_put_tunnel_info(user_skb, 473 err = ovs_nla_put_tunnel_info(user_skb,
472 upcall_info->egress_tun_info); 474 upcall_info->egress_tun_info);
473 BUG_ON(err); 475 if (err)
476 goto out;
477
474 nla_nest_end(user_skb, nla); 478 nla_nest_end(user_skb, nla);
475 } 479 }
476 480
477 if (upcall_info->actions_len) { 481 if (upcall_info->actions_len) {
478 nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_ACTIONS); 482 nla = nla_nest_start_noflag(user_skb, OVS_PACKET_ATTR_ACTIONS);
479 if (!nla) { 483 if (!nla) {
480 err = -EMSGSIZE; 484 err = -EMSGSIZE;
481 goto out; 485 goto out;
@@ -638,8 +642,8 @@ static const struct nla_policy packet_policy[OVS_PACKET_ATTR_MAX + 1] = {
638 642
639static const struct genl_ops dp_packet_genl_ops[] = { 643static const struct genl_ops dp_packet_genl_ops[] = {
640 { .cmd = OVS_PACKET_CMD_EXECUTE, 644 { .cmd = OVS_PACKET_CMD_EXECUTE,
645 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
641 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 646 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
642 .policy = packet_policy,
643 .doit = ovs_packet_cmd_execute 647 .doit = ovs_packet_cmd_execute
644 } 648 }
645}; 649};
@@ -649,6 +653,7 @@ static struct genl_family dp_packet_genl_family __ro_after_init = {
649 .name = OVS_PACKET_FAMILY, 653 .name = OVS_PACKET_FAMILY,
650 .version = OVS_PACKET_VERSION, 654 .version = OVS_PACKET_VERSION,
651 .maxattr = OVS_PACKET_ATTR_MAX, 655 .maxattr = OVS_PACKET_ATTR_MAX,
656 .policy = packet_policy,
652 .netnsok = true, 657 .netnsok = true,
653 .parallel_ops = true, 658 .parallel_ops = true,
654 .ops = dp_packet_genl_ops, 659 .ops = dp_packet_genl_ops,
@@ -776,7 +781,7 @@ static int ovs_flow_cmd_fill_actions(const struct sw_flow *flow,
776 * This can only fail for dump operations because the skb is always 781 * This can only fail for dump operations because the skb is always
777 * properly sized for single flows. 782 * properly sized for single flows.
778 */ 783 */
779 start = nla_nest_start(skb, OVS_FLOW_ATTR_ACTIONS); 784 start = nla_nest_start_noflag(skb, OVS_FLOW_ATTR_ACTIONS);
780 if (start) { 785 if (start) {
781 const struct sw_flow_actions *sf_acts; 786 const struct sw_flow_actions *sf_acts;
782 787
@@ -1374,8 +1379,8 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1374 u32 ufid_flags; 1379 u32 ufid_flags;
1375 int err; 1380 int err;
1376 1381
1377 err = genlmsg_parse(cb->nlh, &dp_flow_genl_family, a, 1382 err = genlmsg_parse_deprecated(cb->nlh, &dp_flow_genl_family, a,
1378 OVS_FLOW_ATTR_MAX, flow_policy, NULL); 1383 OVS_FLOW_ATTR_MAX, flow_policy, NULL);
1379 if (err) 1384 if (err)
1380 return err; 1385 return err;
1381 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]); 1386 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
@@ -1423,24 +1428,24 @@ static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = {
1423 1428
1424static const struct genl_ops dp_flow_genl_ops[] = { 1429static const struct genl_ops dp_flow_genl_ops[] = {
1425 { .cmd = OVS_FLOW_CMD_NEW, 1430 { .cmd = OVS_FLOW_CMD_NEW,
1431 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1426 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 1432 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1427 .policy = flow_policy,
1428 .doit = ovs_flow_cmd_new 1433 .doit = ovs_flow_cmd_new
1429 }, 1434 },
1430 { .cmd = OVS_FLOW_CMD_DEL, 1435 { .cmd = OVS_FLOW_CMD_DEL,
1436 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1431 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 1437 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1432 .policy = flow_policy,
1433 .doit = ovs_flow_cmd_del 1438 .doit = ovs_flow_cmd_del
1434 }, 1439 },
1435 { .cmd = OVS_FLOW_CMD_GET, 1440 { .cmd = OVS_FLOW_CMD_GET,
1441 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1436 .flags = 0, /* OK for unprivileged users. */ 1442 .flags = 0, /* OK for unprivileged users. */
1437 .policy = flow_policy,
1438 .doit = ovs_flow_cmd_get, 1443 .doit = ovs_flow_cmd_get,
1439 .dumpit = ovs_flow_cmd_dump 1444 .dumpit = ovs_flow_cmd_dump
1440 }, 1445 },
1441 { .cmd = OVS_FLOW_CMD_SET, 1446 { .cmd = OVS_FLOW_CMD_SET,
1447 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1442 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 1448 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1443 .policy = flow_policy,
1444 .doit = ovs_flow_cmd_set, 1449 .doit = ovs_flow_cmd_set,
1445 }, 1450 },
1446}; 1451};
@@ -1450,6 +1455,7 @@ static struct genl_family dp_flow_genl_family __ro_after_init = {
1450 .name = OVS_FLOW_FAMILY, 1455 .name = OVS_FLOW_FAMILY,
1451 .version = OVS_FLOW_VERSION, 1456 .version = OVS_FLOW_VERSION,
1452 .maxattr = OVS_FLOW_ATTR_MAX, 1457 .maxattr = OVS_FLOW_ATTR_MAX,
1458 .policy = flow_policy,
1453 .netnsok = true, 1459 .netnsok = true,
1454 .parallel_ops = true, 1460 .parallel_ops = true,
1455 .ops = dp_flow_genl_ops, 1461 .ops = dp_flow_genl_ops,
@@ -1816,24 +1822,24 @@ static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = {
1816 1822
1817static const struct genl_ops dp_datapath_genl_ops[] = { 1823static const struct genl_ops dp_datapath_genl_ops[] = {
1818 { .cmd = OVS_DP_CMD_NEW, 1824 { .cmd = OVS_DP_CMD_NEW,
1825 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1819 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 1826 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1820 .policy = datapath_policy,
1821 .doit = ovs_dp_cmd_new 1827 .doit = ovs_dp_cmd_new
1822 }, 1828 },
1823 { .cmd = OVS_DP_CMD_DEL, 1829 { .cmd = OVS_DP_CMD_DEL,
1830 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1824 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 1831 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1825 .policy = datapath_policy,
1826 .doit = ovs_dp_cmd_del 1832 .doit = ovs_dp_cmd_del
1827 }, 1833 },
1828 { .cmd = OVS_DP_CMD_GET, 1834 { .cmd = OVS_DP_CMD_GET,
1835 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1829 .flags = 0, /* OK for unprivileged users. */ 1836 .flags = 0, /* OK for unprivileged users. */
1830 .policy = datapath_policy,
1831 .doit = ovs_dp_cmd_get, 1837 .doit = ovs_dp_cmd_get,
1832 .dumpit = ovs_dp_cmd_dump 1838 .dumpit = ovs_dp_cmd_dump
1833 }, 1839 },
1834 { .cmd = OVS_DP_CMD_SET, 1840 { .cmd = OVS_DP_CMD_SET,
1841 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1835 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 1842 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
1836 .policy = datapath_policy,
1837 .doit = ovs_dp_cmd_set, 1843 .doit = ovs_dp_cmd_set,
1838 }, 1844 },
1839}; 1845};
@@ -1843,6 +1849,7 @@ static struct genl_family dp_datapath_genl_family __ro_after_init = {
1843 .name = OVS_DATAPATH_FAMILY, 1849 .name = OVS_DATAPATH_FAMILY,
1844 .version = OVS_DATAPATH_VERSION, 1850 .version = OVS_DATAPATH_VERSION,
1845 .maxattr = OVS_DP_ATTR_MAX, 1851 .maxattr = OVS_DP_ATTR_MAX,
1852 .policy = datapath_policy,
1846 .netnsok = true, 1853 .netnsok = true,
1847 .parallel_ops = true, 1854 .parallel_ops = true,
1848 .ops = dp_datapath_genl_ops, 1855 .ops = dp_datapath_genl_ops,
@@ -2259,24 +2266,24 @@ static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = {
2259 2266
2260static const struct genl_ops dp_vport_genl_ops[] = { 2267static const struct genl_ops dp_vport_genl_ops[] = {
2261 { .cmd = OVS_VPORT_CMD_NEW, 2268 { .cmd = OVS_VPORT_CMD_NEW,
2269 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2262 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 2270 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2263 .policy = vport_policy,
2264 .doit = ovs_vport_cmd_new 2271 .doit = ovs_vport_cmd_new
2265 }, 2272 },
2266 { .cmd = OVS_VPORT_CMD_DEL, 2273 { .cmd = OVS_VPORT_CMD_DEL,
2274 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2267 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 2275 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2268 .policy = vport_policy,
2269 .doit = ovs_vport_cmd_del 2276 .doit = ovs_vport_cmd_del
2270 }, 2277 },
2271 { .cmd = OVS_VPORT_CMD_GET, 2278 { .cmd = OVS_VPORT_CMD_GET,
2279 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2272 .flags = 0, /* OK for unprivileged users. */ 2280 .flags = 0, /* OK for unprivileged users. */
2273 .policy = vport_policy,
2274 .doit = ovs_vport_cmd_get, 2281 .doit = ovs_vport_cmd_get,
2275 .dumpit = ovs_vport_cmd_dump 2282 .dumpit = ovs_vport_cmd_dump
2276 }, 2283 },
2277 { .cmd = OVS_VPORT_CMD_SET, 2284 { .cmd = OVS_VPORT_CMD_SET,
2285 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2278 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ 2286 .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
2279 .policy = vport_policy,
2280 .doit = ovs_vport_cmd_set, 2287 .doit = ovs_vport_cmd_set,
2281 }, 2288 },
2282}; 2289};
@@ -2286,6 +2293,7 @@ struct genl_family dp_vport_genl_family __ro_after_init = {
2286 .name = OVS_VPORT_FAMILY, 2293 .name = OVS_VPORT_FAMILY,
2287 .version = OVS_VPORT_VERSION, 2294 .version = OVS_VPORT_VERSION,
2288 .maxattr = OVS_VPORT_ATTR_MAX, 2295 .maxattr = OVS_VPORT_ATTR_MAX,
2296 .policy = vport_policy,
2289 .netnsok = true, 2297 .netnsok = true,
2290 .parallel_ops = true, 2298 .parallel_ops = true,
2291 .ops = dp_vport_genl_ops, 2299 .ops = dp_vport_genl_ops,
diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c
index 4bdf5e3ac208..54eb80dd2dc6 100644
--- a/net/openvswitch/flow_netlink.c
+++ b/net/openvswitch/flow_netlink.c
@@ -91,6 +91,7 @@ static bool actions_may_change_flow(const struct nlattr *actions)
91 case OVS_ACTION_ATTR_SET: 91 case OVS_ACTION_ATTR_SET:
92 case OVS_ACTION_ATTR_SET_MASKED: 92 case OVS_ACTION_ATTR_SET_MASKED:
93 case OVS_ACTION_ATTR_METER: 93 case OVS_ACTION_ATTR_METER:
94 case OVS_ACTION_ATTR_CHECK_PKT_LEN:
94 default: 95 default:
95 return true; 96 return true;
96 } 97 }
@@ -403,6 +404,7 @@ static const struct ovs_len_tbl ovs_tunnel_key_lens[OVS_TUNNEL_KEY_ATTR_MAX + 1]
403 [OVS_TUNNEL_KEY_ATTR_IPV6_SRC] = { .len = sizeof(struct in6_addr) }, 404 [OVS_TUNNEL_KEY_ATTR_IPV6_SRC] = { .len = sizeof(struct in6_addr) },
404 [OVS_TUNNEL_KEY_ATTR_IPV6_DST] = { .len = sizeof(struct in6_addr) }, 405 [OVS_TUNNEL_KEY_ATTR_IPV6_DST] = { .len = sizeof(struct in6_addr) },
405 [OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS] = { .len = OVS_ATTR_VARIABLE }, 406 [OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS] = { .len = OVS_ATTR_VARIABLE },
407 [OVS_TUNNEL_KEY_ATTR_IPV4_INFO_BRIDGE] = { .len = 0 },
406}; 408};
407 409
408static const struct ovs_len_tbl 410static const struct ovs_len_tbl
@@ -666,6 +668,7 @@ static int ip_tun_from_nlattr(const struct nlattr *attr,
666 bool log) 668 bool log)
667{ 669{
668 bool ttl = false, ipv4 = false, ipv6 = false; 670 bool ttl = false, ipv4 = false, ipv6 = false;
671 bool info_bridge_mode = false;
669 __be16 tun_flags = 0; 672 __be16 tun_flags = 0;
670 int opts_type = 0; 673 int opts_type = 0;
671 struct nlattr *a; 674 struct nlattr *a;
@@ -782,6 +785,10 @@ static int ip_tun_from_nlattr(const struct nlattr *attr,
782 tun_flags |= TUNNEL_ERSPAN_OPT; 785 tun_flags |= TUNNEL_ERSPAN_OPT;
783 opts_type = type; 786 opts_type = type;
784 break; 787 break;
788 case OVS_TUNNEL_KEY_ATTR_IPV4_INFO_BRIDGE:
789 info_bridge_mode = true;
790 ipv4 = true;
791 break;
785 default: 792 default:
786 OVS_NLERR(log, "Unknown IP tunnel attribute %d", 793 OVS_NLERR(log, "Unknown IP tunnel attribute %d",
787 type); 794 type);
@@ -812,16 +819,29 @@ static int ip_tun_from_nlattr(const struct nlattr *attr,
812 OVS_NLERR(log, "IP tunnel dst address not specified"); 819 OVS_NLERR(log, "IP tunnel dst address not specified");
813 return -EINVAL; 820 return -EINVAL;
814 } 821 }
815 if (ipv4 && !match->key->tun_key.u.ipv4.dst) { 822 if (ipv4) {
816 OVS_NLERR(log, "IPv4 tunnel dst address is zero"); 823 if (info_bridge_mode) {
817 return -EINVAL; 824 if (match->key->tun_key.u.ipv4.src ||
825 match->key->tun_key.u.ipv4.dst ||
826 match->key->tun_key.tp_src ||
827 match->key->tun_key.tp_dst ||
828 match->key->tun_key.ttl ||
829 match->key->tun_key.tos ||
830 tun_flags & ~TUNNEL_KEY) {
831 OVS_NLERR(log, "IPv4 tun info is not correct");
832 return -EINVAL;
833 }
834 } else if (!match->key->tun_key.u.ipv4.dst) {
835 OVS_NLERR(log, "IPv4 tunnel dst address is zero");
836 return -EINVAL;
837 }
818 } 838 }
819 if (ipv6 && ipv6_addr_any(&match->key->tun_key.u.ipv6.dst)) { 839 if (ipv6 && ipv6_addr_any(&match->key->tun_key.u.ipv6.dst)) {
820 OVS_NLERR(log, "IPv6 tunnel dst address is zero"); 840 OVS_NLERR(log, "IPv6 tunnel dst address is zero");
821 return -EINVAL; 841 return -EINVAL;
822 } 842 }
823 843
824 if (!ttl) { 844 if (!ttl && !info_bridge_mode) {
825 OVS_NLERR(log, "IP tunnel TTL not specified."); 845 OVS_NLERR(log, "IP tunnel TTL not specified.");
826 return -EINVAL; 846 return -EINVAL;
827 } 847 }
@@ -836,7 +856,7 @@ static int vxlan_opt_to_nlattr(struct sk_buff *skb,
836 const struct vxlan_metadata *opts = tun_opts; 856 const struct vxlan_metadata *opts = tun_opts;
837 struct nlattr *nla; 857 struct nlattr *nla;
838 858
839 nla = nla_nest_start(skb, OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS); 859 nla = nla_nest_start_noflag(skb, OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS);
840 if (!nla) 860 if (!nla)
841 return -EMSGSIZE; 861 return -EMSGSIZE;
842 862
@@ -850,12 +870,17 @@ static int vxlan_opt_to_nlattr(struct sk_buff *skb,
850static int __ip_tun_to_nlattr(struct sk_buff *skb, 870static int __ip_tun_to_nlattr(struct sk_buff *skb,
851 const struct ip_tunnel_key *output, 871 const struct ip_tunnel_key *output,
852 const void *tun_opts, int swkey_tun_opts_len, 872 const void *tun_opts, int swkey_tun_opts_len,
853 unsigned short tun_proto) 873 unsigned short tun_proto, u8 mode)
854{ 874{
855 if (output->tun_flags & TUNNEL_KEY && 875 if (output->tun_flags & TUNNEL_KEY &&
856 nla_put_be64(skb, OVS_TUNNEL_KEY_ATTR_ID, output->tun_id, 876 nla_put_be64(skb, OVS_TUNNEL_KEY_ATTR_ID, output->tun_id,
857 OVS_TUNNEL_KEY_ATTR_PAD)) 877 OVS_TUNNEL_KEY_ATTR_PAD))
858 return -EMSGSIZE; 878 return -EMSGSIZE;
879
880 if (mode & IP_TUNNEL_INFO_BRIDGE)
881 return nla_put_flag(skb, OVS_TUNNEL_KEY_ATTR_IPV4_INFO_BRIDGE)
882 ? -EMSGSIZE : 0;
883
859 switch (tun_proto) { 884 switch (tun_proto) {
860 case AF_INET: 885 case AF_INET:
861 if (output->u.ipv4.src && 886 if (output->u.ipv4.src &&
@@ -918,17 +943,17 @@ static int __ip_tun_to_nlattr(struct sk_buff *skb,
918static int ip_tun_to_nlattr(struct sk_buff *skb, 943static int ip_tun_to_nlattr(struct sk_buff *skb,
919 const struct ip_tunnel_key *output, 944 const struct ip_tunnel_key *output,
920 const void *tun_opts, int swkey_tun_opts_len, 945 const void *tun_opts, int swkey_tun_opts_len,
921 unsigned short tun_proto) 946 unsigned short tun_proto, u8 mode)
922{ 947{
923 struct nlattr *nla; 948 struct nlattr *nla;
924 int err; 949 int err;
925 950
926 nla = nla_nest_start(skb, OVS_KEY_ATTR_TUNNEL); 951 nla = nla_nest_start_noflag(skb, OVS_KEY_ATTR_TUNNEL);
927 if (!nla) 952 if (!nla)
928 return -EMSGSIZE; 953 return -EMSGSIZE;
929 954
930 err = __ip_tun_to_nlattr(skb, output, tun_opts, swkey_tun_opts_len, 955 err = __ip_tun_to_nlattr(skb, output, tun_opts, swkey_tun_opts_len,
931 tun_proto); 956 tun_proto, mode);
932 if (err) 957 if (err)
933 return err; 958 return err;
934 959
@@ -942,7 +967,7 @@ int ovs_nla_put_tunnel_info(struct sk_buff *skb,
942 return __ip_tun_to_nlattr(skb, &tun_info->key, 967 return __ip_tun_to_nlattr(skb, &tun_info->key,
943 ip_tunnel_info_opts(tun_info), 968 ip_tunnel_info_opts(tun_info),
944 tun_info->options_len, 969 tun_info->options_len,
945 ip_tunnel_info_af(tun_info)); 970 ip_tunnel_info_af(tun_info), tun_info->mode);
946} 971}
947 972
948static int encode_vlan_from_nlattrs(struct sw_flow_match *match, 973static int encode_vlan_from_nlattrs(struct sw_flow_match *match,
@@ -1932,7 +1957,7 @@ static int nsh_key_to_nlattr(const struct ovs_key_nsh *nsh, bool is_mask,
1932{ 1957{
1933 struct nlattr *start; 1958 struct nlattr *start;
1934 1959
1935 start = nla_nest_start(skb, OVS_KEY_ATTR_NSH); 1960 start = nla_nest_start_noflag(skb, OVS_KEY_ATTR_NSH);
1936 if (!start) 1961 if (!start)
1937 return -EMSGSIZE; 1962 return -EMSGSIZE;
1938 1963
@@ -1980,7 +2005,7 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
1980 opts = TUN_METADATA_OPTS(output, swkey->tun_opts_len); 2005 opts = TUN_METADATA_OPTS(output, swkey->tun_opts_len);
1981 2006
1982 if (ip_tun_to_nlattr(skb, &output->tun_key, opts, 2007 if (ip_tun_to_nlattr(skb, &output->tun_key, opts,
1983 swkey->tun_opts_len, swkey->tun_proto)) 2008 swkey->tun_opts_len, swkey->tun_proto, 0))
1984 goto nla_put_failure; 2009 goto nla_put_failure;
1985 } 2010 }
1986 2011
@@ -2015,14 +2040,15 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
2015 if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) { 2040 if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
2016 if (ovs_nla_put_vlan(skb, &output->eth.vlan, is_mask)) 2041 if (ovs_nla_put_vlan(skb, &output->eth.vlan, is_mask))
2017 goto nla_put_failure; 2042 goto nla_put_failure;
2018 encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP); 2043 encap = nla_nest_start_noflag(skb, OVS_KEY_ATTR_ENCAP);
2019 if (!swkey->eth.vlan.tci) 2044 if (!swkey->eth.vlan.tci)
2020 goto unencap; 2045 goto unencap;
2021 2046
2022 if (swkey->eth.cvlan.tci || eth_type_vlan(swkey->eth.type)) { 2047 if (swkey->eth.cvlan.tci || eth_type_vlan(swkey->eth.type)) {
2023 if (ovs_nla_put_vlan(skb, &output->eth.cvlan, is_mask)) 2048 if (ovs_nla_put_vlan(skb, &output->eth.cvlan, is_mask))
2024 goto nla_put_failure; 2049 goto nla_put_failure;
2025 in_encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP); 2050 in_encap = nla_nest_start_noflag(skb,
2051 OVS_KEY_ATTR_ENCAP);
2026 if (!swkey->eth.cvlan.tci) 2052 if (!swkey->eth.cvlan.tci)
2027 goto unencap; 2053 goto unencap;
2028 } 2054 }
@@ -2201,7 +2227,7 @@ int ovs_nla_put_key(const struct sw_flow_key *swkey,
2201 int err; 2227 int err;
2202 struct nlattr *nla; 2228 struct nlattr *nla;
2203 2229
2204 nla = nla_nest_start(skb, attr); 2230 nla = nla_nest_start_noflag(skb, attr);
2205 if (!nla) 2231 if (!nla)
2206 return -EMSGSIZE; 2232 return -EMSGSIZE;
2207 err = __ovs_nla_put_key(swkey, output, is_mask, skb); 2233 err = __ovs_nla_put_key(swkey, output, is_mask, skb);
@@ -2605,6 +2631,8 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
2605 tun_info->mode = IP_TUNNEL_INFO_TX; 2631 tun_info->mode = IP_TUNNEL_INFO_TX;
2606 if (key.tun_proto == AF_INET6) 2632 if (key.tun_proto == AF_INET6)
2607 tun_info->mode |= IP_TUNNEL_INFO_IPV6; 2633 tun_info->mode |= IP_TUNNEL_INFO_IPV6;
2634 else if (key.tun_proto == AF_INET && key.tun_key.u.ipv4.dst == 0)
2635 tun_info->mode |= IP_TUNNEL_INFO_BRIDGE;
2608 tun_info->key = key.tun_key; 2636 tun_info->key = key.tun_key;
2609 2637
2610 /* We need to store the options in the action itself since 2638 /* We need to store the options in the action itself since
@@ -2826,8 +2854,8 @@ static int validate_userspace(const struct nlattr *attr)
2826 struct nlattr *a[OVS_USERSPACE_ATTR_MAX + 1]; 2854 struct nlattr *a[OVS_USERSPACE_ATTR_MAX + 1];
2827 int error; 2855 int error;
2828 2856
2829 error = nla_parse_nested(a, OVS_USERSPACE_ATTR_MAX, attr, 2857 error = nla_parse_nested_deprecated(a, OVS_USERSPACE_ATTR_MAX, attr,
2830 userspace_policy, NULL); 2858 userspace_policy, NULL);
2831 if (error) 2859 if (error)
2832 return error; 2860 return error;
2833 2861
@@ -2838,6 +2866,88 @@ static int validate_userspace(const struct nlattr *attr)
2838 return 0; 2866 return 0;
2839} 2867}
2840 2868
2869static const struct nla_policy cpl_policy[OVS_CHECK_PKT_LEN_ATTR_MAX + 1] = {
2870 [OVS_CHECK_PKT_LEN_ATTR_PKT_LEN] = {.type = NLA_U16 },
2871 [OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER] = {.type = NLA_NESTED },
2872 [OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL] = {.type = NLA_NESTED },
2873};
2874
2875static int validate_and_copy_check_pkt_len(struct net *net,
2876 const struct nlattr *attr,
2877 const struct sw_flow_key *key,
2878 struct sw_flow_actions **sfa,
2879 __be16 eth_type, __be16 vlan_tci,
2880 bool log, bool last)
2881{
2882 const struct nlattr *acts_if_greater, *acts_if_lesser_eq;
2883 struct nlattr *a[OVS_CHECK_PKT_LEN_ATTR_MAX + 1];
2884 struct check_pkt_len_arg arg;
2885 int nested_acts_start;
2886 int start, err;
2887
2888 err = nla_parse_deprecated_strict(a, OVS_CHECK_PKT_LEN_ATTR_MAX,
2889 nla_data(attr), nla_len(attr),
2890 cpl_policy, NULL);
2891 if (err)
2892 return err;
2893
2894 if (!a[OVS_CHECK_PKT_LEN_ATTR_PKT_LEN] ||
2895 !nla_get_u16(a[OVS_CHECK_PKT_LEN_ATTR_PKT_LEN]))
2896 return -EINVAL;
2897
2898 acts_if_lesser_eq = a[OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL];
2899 acts_if_greater = a[OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER];
2900
2901 /* Both the nested action should be present. */
2902 if (!acts_if_greater || !acts_if_lesser_eq)
2903 return -EINVAL;
2904
2905 /* validation done, copy the nested actions. */
2906 start = add_nested_action_start(sfa, OVS_ACTION_ATTR_CHECK_PKT_LEN,
2907 log);
2908 if (start < 0)
2909 return start;
2910
2911 arg.pkt_len = nla_get_u16(a[OVS_CHECK_PKT_LEN_ATTR_PKT_LEN]);
2912 arg.exec_for_lesser_equal =
2913 last || !actions_may_change_flow(acts_if_lesser_eq);
2914 arg.exec_for_greater =
2915 last || !actions_may_change_flow(acts_if_greater);
2916
2917 err = ovs_nla_add_action(sfa, OVS_CHECK_PKT_LEN_ATTR_ARG, &arg,
2918 sizeof(arg), log);
2919 if (err)
2920 return err;
2921
2922 nested_acts_start = add_nested_action_start(sfa,
2923 OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL, log);
2924 if (nested_acts_start < 0)
2925 return nested_acts_start;
2926
2927 err = __ovs_nla_copy_actions(net, acts_if_lesser_eq, key, sfa,
2928 eth_type, vlan_tci, log);
2929
2930 if (err)
2931 return err;
2932
2933 add_nested_action_end(*sfa, nested_acts_start);
2934
2935 nested_acts_start = add_nested_action_start(sfa,
2936 OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER, log);
2937 if (nested_acts_start < 0)
2938 return nested_acts_start;
2939
2940 err = __ovs_nla_copy_actions(net, acts_if_greater, key, sfa,
2941 eth_type, vlan_tci, log);
2942
2943 if (err)
2944 return err;
2945
2946 add_nested_action_end(*sfa, nested_acts_start);
2947 add_nested_action_end(*sfa, start);
2948 return 0;
2949}
2950
2841static int copy_action(const struct nlattr *from, 2951static int copy_action(const struct nlattr *from,
2842 struct sw_flow_actions **sfa, bool log) 2952 struct sw_flow_actions **sfa, bool log)
2843{ 2953{
@@ -2884,6 +2994,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
2884 [OVS_ACTION_ATTR_POP_NSH] = 0, 2994 [OVS_ACTION_ATTR_POP_NSH] = 0,
2885 [OVS_ACTION_ATTR_METER] = sizeof(u32), 2995 [OVS_ACTION_ATTR_METER] = sizeof(u32),
2886 [OVS_ACTION_ATTR_CLONE] = (u32)-1, 2996 [OVS_ACTION_ATTR_CLONE] = (u32)-1,
2997 [OVS_ACTION_ATTR_CHECK_PKT_LEN] = (u32)-1,
2887 }; 2998 };
2888 const struct ovs_action_push_vlan *vlan; 2999 const struct ovs_action_push_vlan *vlan;
2889 int type = nla_type(a); 3000 int type = nla_type(a);
@@ -3085,6 +3196,19 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
3085 break; 3196 break;
3086 } 3197 }
3087 3198
3199 case OVS_ACTION_ATTR_CHECK_PKT_LEN: {
3200 bool last = nla_is_last(a, rem);
3201
3202 err = validate_and_copy_check_pkt_len(net, a, key, sfa,
3203 eth_type,
3204 vlan_tci, log,
3205 last);
3206 if (err)
3207 return err;
3208 skip_copy = true;
3209 break;
3210 }
3211
3088 default: 3212 default:
3089 OVS_NLERR(log, "Unknown Action type %d", type); 3213 OVS_NLERR(log, "Unknown Action type %d", type);
3090 return -EINVAL; 3214 return -EINVAL;
@@ -3130,7 +3254,7 @@ static int sample_action_to_attr(const struct nlattr *attr,
3130 const struct sample_arg *arg; 3254 const struct sample_arg *arg;
3131 struct nlattr *actions; 3255 struct nlattr *actions;
3132 3256
3133 start = nla_nest_start(skb, OVS_ACTION_ATTR_SAMPLE); 3257 start = nla_nest_start_noflag(skb, OVS_ACTION_ATTR_SAMPLE);
3134 if (!start) 3258 if (!start)
3135 return -EMSGSIZE; 3259 return -EMSGSIZE;
3136 3260
@@ -3143,7 +3267,7 @@ static int sample_action_to_attr(const struct nlattr *attr,
3143 goto out; 3267 goto out;
3144 } 3268 }
3145 3269
3146 ac_start = nla_nest_start(skb, OVS_SAMPLE_ATTR_ACTIONS); 3270 ac_start = nla_nest_start_noflag(skb, OVS_SAMPLE_ATTR_ACTIONS);
3147 if (!ac_start) { 3271 if (!ac_start) {
3148 err = -EMSGSIZE; 3272 err = -EMSGSIZE;
3149 goto out; 3273 goto out;
@@ -3169,7 +3293,7 @@ static int clone_action_to_attr(const struct nlattr *attr,
3169 struct nlattr *start; 3293 struct nlattr *start;
3170 int err = 0, rem = nla_len(attr); 3294 int err = 0, rem = nla_len(attr);
3171 3295
3172 start = nla_nest_start(skb, OVS_ACTION_ATTR_CLONE); 3296 start = nla_nest_start_noflag(skb, OVS_ACTION_ATTR_CLONE);
3173 if (!start) 3297 if (!start)
3174 return -EMSGSIZE; 3298 return -EMSGSIZE;
3175 3299
@@ -3183,6 +3307,75 @@ static int clone_action_to_attr(const struct nlattr *attr,
3183 return err; 3307 return err;
3184} 3308}
3185 3309
3310static int check_pkt_len_action_to_attr(const struct nlattr *attr,
3311 struct sk_buff *skb)
3312{
3313 struct nlattr *start, *ac_start = NULL;
3314 const struct check_pkt_len_arg *arg;
3315 const struct nlattr *a, *cpl_arg;
3316 int err = 0, rem = nla_len(attr);
3317
3318 start = nla_nest_start_noflag(skb, OVS_ACTION_ATTR_CHECK_PKT_LEN);
3319 if (!start)
3320 return -EMSGSIZE;
3321
3322 /* The first nested attribute in 'attr' is always
3323 * 'OVS_CHECK_PKT_LEN_ATTR_ARG'.
3324 */
3325 cpl_arg = nla_data(attr);
3326 arg = nla_data(cpl_arg);
3327
3328 if (nla_put_u16(skb, OVS_CHECK_PKT_LEN_ATTR_PKT_LEN, arg->pkt_len)) {
3329 err = -EMSGSIZE;
3330 goto out;
3331 }
3332
3333 /* Second nested attribute in 'attr' is always
3334 * 'OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL'.
3335 */
3336 a = nla_next(cpl_arg, &rem);
3337 ac_start = nla_nest_start_noflag(skb,
3338 OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL);
3339 if (!ac_start) {
3340 err = -EMSGSIZE;
3341 goto out;
3342 }
3343
3344 err = ovs_nla_put_actions(nla_data(a), nla_len(a), skb);
3345 if (err) {
3346 nla_nest_cancel(skb, ac_start);
3347 goto out;
3348 } else {
3349 nla_nest_end(skb, ac_start);
3350 }
3351
3352 /* Third nested attribute in 'attr' is always
3353 * OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER.
3354 */
3355 a = nla_next(a, &rem);
3356 ac_start = nla_nest_start_noflag(skb,
3357 OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER);
3358 if (!ac_start) {
3359 err = -EMSGSIZE;
3360 goto out;
3361 }
3362
3363 err = ovs_nla_put_actions(nla_data(a), nla_len(a), skb);
3364 if (err) {
3365 nla_nest_cancel(skb, ac_start);
3366 goto out;
3367 } else {
3368 nla_nest_end(skb, ac_start);
3369 }
3370
3371 nla_nest_end(skb, start);
3372 return 0;
3373
3374out:
3375 nla_nest_cancel(skb, start);
3376 return err;
3377}
3378
3186static int set_action_to_attr(const struct nlattr *a, struct sk_buff *skb) 3379static int set_action_to_attr(const struct nlattr *a, struct sk_buff *skb)
3187{ 3380{
3188 const struct nlattr *ovs_key = nla_data(a); 3381 const struct nlattr *ovs_key = nla_data(a);
@@ -3195,14 +3388,14 @@ static int set_action_to_attr(const struct nlattr *a, struct sk_buff *skb)
3195 struct ovs_tunnel_info *ovs_tun = nla_data(ovs_key); 3388 struct ovs_tunnel_info *ovs_tun = nla_data(ovs_key);
3196 struct ip_tunnel_info *tun_info = &ovs_tun->tun_dst->u.tun_info; 3389 struct ip_tunnel_info *tun_info = &ovs_tun->tun_dst->u.tun_info;
3197 3390
3198 start = nla_nest_start(skb, OVS_ACTION_ATTR_SET); 3391 start = nla_nest_start_noflag(skb, OVS_ACTION_ATTR_SET);
3199 if (!start) 3392 if (!start)
3200 return -EMSGSIZE; 3393 return -EMSGSIZE;
3201 3394
3202 err = ip_tun_to_nlattr(skb, &tun_info->key, 3395 err = ip_tun_to_nlattr(skb, &tun_info->key,
3203 ip_tunnel_info_opts(tun_info), 3396 ip_tunnel_info_opts(tun_info),
3204 tun_info->options_len, 3397 tun_info->options_len,
3205 ip_tunnel_info_af(tun_info)); 3398 ip_tunnel_info_af(tun_info), tun_info->mode);
3206 if (err) 3399 if (err)
3207 return err; 3400 return err;
3208 nla_nest_end(skb, start); 3401 nla_nest_end(skb, start);
@@ -3227,7 +3420,7 @@ static int masked_set_action_to_set_action_attr(const struct nlattr *a,
3227 /* Revert the conversion we did from a non-masked set action to 3420 /* Revert the conversion we did from a non-masked set action to
3228 * masked set action. 3421 * masked set action.
3229 */ 3422 */
3230 nla = nla_nest_start(skb, OVS_ACTION_ATTR_SET); 3423 nla = nla_nest_start_noflag(skb, OVS_ACTION_ATTR_SET);
3231 if (!nla) 3424 if (!nla)
3232 return -EMSGSIZE; 3425 return -EMSGSIZE;
3233 3426
@@ -3277,6 +3470,12 @@ int ovs_nla_put_actions(const struct nlattr *attr, int len, struct sk_buff *skb)
3277 return err; 3470 return err;
3278 break; 3471 break;
3279 3472
3473 case OVS_ACTION_ATTR_CHECK_PKT_LEN:
3474 err = check_pkt_len_action_to_attr(a, skb);
3475 if (err)
3476 return err;
3477 break;
3478
3280 default: 3479 default:
3281 if (nla_put(skb, type, nla_len(a), nla_data(a))) 3480 if (nla_put(skb, type, nla_len(a), nla_data(a)))
3282 return -EMSGSIZE; 3481 return -EMSGSIZE;
diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c
index 43849d752a1e..bb67238f0340 100644
--- a/net/openvswitch/meter.c
+++ b/net/openvswitch/meter.c
@@ -127,7 +127,7 @@ static int ovs_meter_cmd_reply_stats(struct sk_buff *reply, u32 meter_id,
127 OVS_METER_ATTR_PAD)) 127 OVS_METER_ATTR_PAD))
128 goto error; 128 goto error;
129 129
130 nla = nla_nest_start(reply, OVS_METER_ATTR_BANDS); 130 nla = nla_nest_start_noflag(reply, OVS_METER_ATTR_BANDS);
131 if (!nla) 131 if (!nla)
132 goto error; 132 goto error;
133 133
@@ -136,7 +136,7 @@ static int ovs_meter_cmd_reply_stats(struct sk_buff *reply, u32 meter_id,
136 for (i = 0; i < meter->n_bands; ++i, ++band) { 136 for (i = 0; i < meter->n_bands; ++i, ++band) {
137 struct nlattr *band_nla; 137 struct nlattr *band_nla;
138 138
139 band_nla = nla_nest_start(reply, OVS_BAND_ATTR_UNSPEC); 139 band_nla = nla_nest_start_noflag(reply, OVS_BAND_ATTR_UNSPEC);
140 if (!band_nla || nla_put(reply, OVS_BAND_ATTR_STATS, 140 if (!band_nla || nla_put(reply, OVS_BAND_ATTR_STATS,
141 sizeof(struct ovs_flow_stats), 141 sizeof(struct ovs_flow_stats),
142 &band->stats)) 142 &band->stats))
@@ -166,11 +166,11 @@ static int ovs_meter_cmd_features(struct sk_buff *skb, struct genl_info *info)
166 nla_put_u32(reply, OVS_METER_ATTR_MAX_BANDS, DP_MAX_BANDS)) 166 nla_put_u32(reply, OVS_METER_ATTR_MAX_BANDS, DP_MAX_BANDS))
167 goto nla_put_failure; 167 goto nla_put_failure;
168 168
169 nla = nla_nest_start(reply, OVS_METER_ATTR_BANDS); 169 nla = nla_nest_start_noflag(reply, OVS_METER_ATTR_BANDS);
170 if (!nla) 170 if (!nla)
171 goto nla_put_failure; 171 goto nla_put_failure;
172 172
173 band_nla = nla_nest_start(reply, OVS_BAND_ATTR_UNSPEC); 173 band_nla = nla_nest_start_noflag(reply, OVS_BAND_ATTR_UNSPEC);
174 if (!band_nla) 174 if (!band_nla)
175 goto nla_put_failure; 175 goto nla_put_failure;
176 /* Currently only DROP band type is supported. */ 176 /* Currently only DROP band type is supported. */
@@ -227,9 +227,9 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
227 struct nlattr *attr[OVS_BAND_ATTR_MAX + 1]; 227 struct nlattr *attr[OVS_BAND_ATTR_MAX + 1];
228 u32 band_max_delta_t; 228 u32 band_max_delta_t;
229 229
230 err = nla_parse((struct nlattr **)&attr, OVS_BAND_ATTR_MAX, 230 err = nla_parse_deprecated((struct nlattr **)&attr,
231 nla_data(nla), nla_len(nla), band_policy, 231 OVS_BAND_ATTR_MAX, nla_data(nla),
232 NULL); 232 nla_len(nla), band_policy, NULL);
233 if (err) 233 if (err)
234 goto exit_free_meter; 234 goto exit_free_meter;
235 235
@@ -526,27 +526,27 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb,
526 526
527static struct genl_ops dp_meter_genl_ops[] = { 527static struct genl_ops dp_meter_genl_ops[] = {
528 { .cmd = OVS_METER_CMD_FEATURES, 528 { .cmd = OVS_METER_CMD_FEATURES,
529 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
529 .flags = 0, /* OK for unprivileged users. */ 530 .flags = 0, /* OK for unprivileged users. */
530 .policy = meter_policy,
531 .doit = ovs_meter_cmd_features 531 .doit = ovs_meter_cmd_features
532 }, 532 },
533 { .cmd = OVS_METER_CMD_SET, 533 { .cmd = OVS_METER_CMD_SET,
534 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
534 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN 535 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
535 * privilege. 536 * privilege.
536 */ 537 */
537 .policy = meter_policy,
538 .doit = ovs_meter_cmd_set, 538 .doit = ovs_meter_cmd_set,
539 }, 539 },
540 { .cmd = OVS_METER_CMD_GET, 540 { .cmd = OVS_METER_CMD_GET,
541 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
541 .flags = 0, /* OK for unprivileged users. */ 542 .flags = 0, /* OK for unprivileged users. */
542 .policy = meter_policy,
543 .doit = ovs_meter_cmd_get, 543 .doit = ovs_meter_cmd_get,
544 }, 544 },
545 { .cmd = OVS_METER_CMD_DEL, 545 { .cmd = OVS_METER_CMD_DEL,
546 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
546 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN 547 .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
547 * privilege. 548 * privilege.
548 */ 549 */
549 .policy = meter_policy,
550 .doit = ovs_meter_cmd_del 550 .doit = ovs_meter_cmd_del
551 }, 551 },
552}; 552};
@@ -560,6 +560,7 @@ struct genl_family dp_meter_genl_family __ro_after_init = {
560 .name = OVS_METER_FAMILY, 560 .name = OVS_METER_FAMILY,
561 .version = OVS_METER_VERSION, 561 .version = OVS_METER_VERSION,
562 .maxattr = OVS_METER_ATTR_MAX, 562 .maxattr = OVS_METER_ATTR_MAX,
563 .policy = meter_policy,
563 .netnsok = true, 564 .netnsok = true,
564 .parallel_ops = true, 565 .parallel_ops = true,
565 .ops = dp_meter_genl_ops, 566 .ops = dp_meter_genl_ops,
diff --git a/net/openvswitch/vport-vxlan.c b/net/openvswitch/vport-vxlan.c
index 8f16f11f7ad3..f3c54871f9e1 100644
--- a/net/openvswitch/vport-vxlan.c
+++ b/net/openvswitch/vport-vxlan.c
@@ -43,7 +43,7 @@ static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)
43 if (vxlan->cfg.flags & VXLAN_F_GBP) { 43 if (vxlan->cfg.flags & VXLAN_F_GBP) {
44 struct nlattr *exts; 44 struct nlattr *exts;
45 45
46 exts = nla_nest_start(skb, OVS_TUNNEL_ATTR_EXTENSION); 46 exts = nla_nest_start_noflag(skb, OVS_TUNNEL_ATTR_EXTENSION);
47 if (!exts) 47 if (!exts)
48 return -EMSGSIZE; 48 return -EMSGSIZE;
49 49
@@ -70,8 +70,8 @@ static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,
70 if (nla_len(attr) < sizeof(struct nlattr)) 70 if (nla_len(attr) < sizeof(struct nlattr))
71 return -EINVAL; 71 return -EINVAL;
72 72
73 err = nla_parse_nested(exts, OVS_VXLAN_EXT_MAX, attr, exts_policy, 73 err = nla_parse_nested_deprecated(exts, OVS_VXLAN_EXT_MAX, attr,
74 NULL); 74 exts_policy, NULL);
75 if (err < 0) 75 if (err < 0)
76 return err; 76 return err;
77 77
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 19f6765566e7..258ce3b7b452 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -319,7 +319,7 @@ int ovs_vport_get_options(const struct vport *vport, struct sk_buff *skb)
319 if (!vport->ops->get_options) 319 if (!vport->ops->get_options)
320 return 0; 320 return 0;
321 321
322 nla = nla_nest_start(skb, OVS_VPORT_ATTR_OPTIONS); 322 nla = nla_nest_start_noflag(skb, OVS_VPORT_ATTR_OPTIONS);
323 if (!nla) 323 if (!nla)
324 return -EMSGSIZE; 324 return -EMSGSIZE;
325 325
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 9419c5cf4de5..fbc775fbf712 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -275,24 +275,22 @@ static bool packet_use_direct_xmit(const struct packet_sock *po)
275 return po->xmit == packet_direct_xmit; 275 return po->xmit == packet_direct_xmit;
276} 276}
277 277
278static u16 __packet_pick_tx_queue(struct net_device *dev, struct sk_buff *skb,
279 struct net_device *sb_dev)
280{
281 return dev_pick_tx_cpu_id(dev, skb, sb_dev, NULL);
282}
283
284static u16 packet_pick_tx_queue(struct sk_buff *skb) 278static u16 packet_pick_tx_queue(struct sk_buff *skb)
285{ 279{
286 struct net_device *dev = skb->dev; 280 struct net_device *dev = skb->dev;
287 const struct net_device_ops *ops = dev->netdev_ops; 281 const struct net_device_ops *ops = dev->netdev_ops;
282 int cpu = raw_smp_processor_id();
288 u16 queue_index; 283 u16 queue_index;
289 284
285#ifdef CONFIG_XPS
286 skb->sender_cpu = cpu + 1;
287#endif
288 skb_record_rx_queue(skb, cpu % dev->real_num_tx_queues);
290 if (ops->ndo_select_queue) { 289 if (ops->ndo_select_queue) {
291 queue_index = ops->ndo_select_queue(dev, skb, NULL, 290 queue_index = ops->ndo_select_queue(dev, skb, NULL);
292 __packet_pick_tx_queue);
293 queue_index = netdev_cap_txqueue(dev, queue_index); 291 queue_index = netdev_cap_txqueue(dev, queue_index);
294 } else { 292 } else {
295 queue_index = __packet_pick_tx_queue(dev, skb, NULL); 293 queue_index = netdev_pick_tx(dev, skb, NULL);
296 } 294 }
297 295
298 return queue_index; 296 return queue_index;
@@ -2602,8 +2600,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2602 void *ph; 2600 void *ph;
2603 DECLARE_SOCKADDR(struct sockaddr_ll *, saddr, msg->msg_name); 2601 DECLARE_SOCKADDR(struct sockaddr_ll *, saddr, msg->msg_name);
2604 bool need_wait = !(msg->msg_flags & MSG_DONTWAIT); 2602 bool need_wait = !(msg->msg_flags & MSG_DONTWAIT);
2603 unsigned char *addr = NULL;
2605 int tp_len, size_max; 2604 int tp_len, size_max;
2606 unsigned char *addr;
2607 void *data; 2605 void *data;
2608 int len_sum = 0; 2606 int len_sum = 0;
2609 int status = TP_STATUS_AVAILABLE; 2607 int status = TP_STATUS_AVAILABLE;
@@ -2614,7 +2612,6 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2614 if (likely(saddr == NULL)) { 2612 if (likely(saddr == NULL)) {
2615 dev = packet_cached_dev_get(po); 2613 dev = packet_cached_dev_get(po);
2616 proto = po->num; 2614 proto = po->num;
2617 addr = NULL;
2618 } else { 2615 } else {
2619 err = -EINVAL; 2616 err = -EINVAL;
2620 if (msg->msg_namelen < sizeof(struct sockaddr_ll)) 2617 if (msg->msg_namelen < sizeof(struct sockaddr_ll))
@@ -2624,10 +2621,13 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2624 sll_addr))) 2621 sll_addr)))
2625 goto out; 2622 goto out;
2626 proto = saddr->sll_protocol; 2623 proto = saddr->sll_protocol;
2627 addr = saddr->sll_halen ? saddr->sll_addr : NULL;
2628 dev = dev_get_by_index(sock_net(&po->sk), saddr->sll_ifindex); 2624 dev = dev_get_by_index(sock_net(&po->sk), saddr->sll_ifindex);
2629 if (addr && dev && saddr->sll_halen < dev->addr_len) 2625 if (po->sk.sk_socket->type == SOCK_DGRAM) {
2630 goto out_put; 2626 if (dev && msg->msg_namelen < dev->addr_len +
2627 offsetof(struct sockaddr_ll, sll_addr))
2628 goto out_put;
2629 addr = saddr->sll_addr;
2630 }
2631 } 2631 }
2632 2632
2633 err = -ENXIO; 2633 err = -ENXIO;
@@ -2799,7 +2799,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2799 struct sk_buff *skb; 2799 struct sk_buff *skb;
2800 struct net_device *dev; 2800 struct net_device *dev;
2801 __be16 proto; 2801 __be16 proto;
2802 unsigned char *addr; 2802 unsigned char *addr = NULL;
2803 int err, reserve = 0; 2803 int err, reserve = 0;
2804 struct sockcm_cookie sockc; 2804 struct sockcm_cookie sockc;
2805 struct virtio_net_hdr vnet_hdr = { 0 }; 2805 struct virtio_net_hdr vnet_hdr = { 0 };
@@ -2816,7 +2816,6 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2816 if (likely(saddr == NULL)) { 2816 if (likely(saddr == NULL)) {
2817 dev = packet_cached_dev_get(po); 2817 dev = packet_cached_dev_get(po);
2818 proto = po->num; 2818 proto = po->num;
2819 addr = NULL;
2820 } else { 2819 } else {
2821 err = -EINVAL; 2820 err = -EINVAL;
2822 if (msg->msg_namelen < sizeof(struct sockaddr_ll)) 2821 if (msg->msg_namelen < sizeof(struct sockaddr_ll))
@@ -2824,10 +2823,13 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2824 if (msg->msg_namelen < (saddr->sll_halen + offsetof(struct sockaddr_ll, sll_addr))) 2823 if (msg->msg_namelen < (saddr->sll_halen + offsetof(struct sockaddr_ll, sll_addr)))
2825 goto out; 2824 goto out;
2826 proto = saddr->sll_protocol; 2825 proto = saddr->sll_protocol;
2827 addr = saddr->sll_halen ? saddr->sll_addr : NULL;
2828 dev = dev_get_by_index(sock_net(sk), saddr->sll_ifindex); 2826 dev = dev_get_by_index(sock_net(sk), saddr->sll_ifindex);
2829 if (addr && dev && saddr->sll_halen < dev->addr_len) 2827 if (sock->type == SOCK_DGRAM) {
2830 goto out_unlock; 2828 if (dev && msg->msg_namelen < dev->addr_len +
2829 offsetof(struct sockaddr_ll, sll_addr))
2830 goto out_unlock;
2831 addr = saddr->sll_addr;
2832 }
2831 } 2833 }
2832 2834
2833 err = -ENXIO; 2835 err = -ENXIO;
@@ -3344,20 +3346,29 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
3344 sock_recv_ts_and_drops(msg, sk, skb); 3346 sock_recv_ts_and_drops(msg, sk, skb);
3345 3347
3346 if (msg->msg_name) { 3348 if (msg->msg_name) {
3349 int copy_len;
3350
3347 /* If the address length field is there to be filled 3351 /* If the address length field is there to be filled
3348 * in, we fill it in now. 3352 * in, we fill it in now.
3349 */ 3353 */
3350 if (sock->type == SOCK_PACKET) { 3354 if (sock->type == SOCK_PACKET) {
3351 __sockaddr_check_size(sizeof(struct sockaddr_pkt)); 3355 __sockaddr_check_size(sizeof(struct sockaddr_pkt));
3352 msg->msg_namelen = sizeof(struct sockaddr_pkt); 3356 msg->msg_namelen = sizeof(struct sockaddr_pkt);
3357 copy_len = msg->msg_namelen;
3353 } else { 3358 } else {
3354 struct sockaddr_ll *sll = &PACKET_SKB_CB(skb)->sa.ll; 3359 struct sockaddr_ll *sll = &PACKET_SKB_CB(skb)->sa.ll;
3355 3360
3356 msg->msg_namelen = sll->sll_halen + 3361 msg->msg_namelen = sll->sll_halen +
3357 offsetof(struct sockaddr_ll, sll_addr); 3362 offsetof(struct sockaddr_ll, sll_addr);
3363 copy_len = msg->msg_namelen;
3364 if (msg->msg_namelen < sizeof(struct sockaddr_ll)) {
3365 memset(msg->msg_name +
3366 offsetof(struct sockaddr_ll, sll_addr),
3367 0, sizeof(sll->sll_addr));
3368 msg->msg_namelen = sizeof(struct sockaddr_ll);
3369 }
3358 } 3370 }
3359 memcpy(msg->msg_name, &PACKET_SKB_CB(skb)->sa, 3371 memcpy(msg->msg_name, &PACKET_SKB_CB(skb)->sa, copy_len);
3360 msg->msg_namelen);
3361 } 3372 }
3362 3373
3363 if (pkt_sk(sk)->auxdata) { 3374 if (pkt_sk(sk)->auxdata) {
@@ -4077,11 +4088,6 @@ static int packet_ioctl(struct socket *sock, unsigned int cmd,
4077 spin_unlock_bh(&sk->sk_receive_queue.lock); 4088 spin_unlock_bh(&sk->sk_receive_queue.lock);
4078 return put_user(amount, (int __user *)arg); 4089 return put_user(amount, (int __user *)arg);
4079 } 4090 }
4080 case SIOCGSTAMP:
4081 return sock_get_timestamp(sk, (struct timeval __user *)arg);
4082 case SIOCGSTAMPNS:
4083 return sock_get_timestampns(sk, (struct timespec __user *)arg);
4084
4085#ifdef CONFIG_INET 4091#ifdef CONFIG_INET
4086 case SIOCADDRT: 4092 case SIOCADDRT:
4087 case SIOCDELRT: 4093 case SIOCDELRT:
@@ -4457,6 +4463,7 @@ static const struct proto_ops packet_ops_spkt = {
4457 .getname = packet_getname_spkt, 4463 .getname = packet_getname_spkt,
4458 .poll = datagram_poll, 4464 .poll = datagram_poll,
4459 .ioctl = packet_ioctl, 4465 .ioctl = packet_ioctl,
4466 .gettstamp = sock_gettstamp,
4460 .listen = sock_no_listen, 4467 .listen = sock_no_listen,
4461 .shutdown = sock_no_shutdown, 4468 .shutdown = sock_no_shutdown,
4462 .setsockopt = sock_no_setsockopt, 4469 .setsockopt = sock_no_setsockopt,
@@ -4478,6 +4485,7 @@ static const struct proto_ops packet_ops = {
4478 .getname = packet_getname, 4485 .getname = packet_getname,
4479 .poll = packet_poll, 4486 .poll = packet_poll,
4480 .ioctl = packet_ioctl, 4487 .ioctl = packet_ioctl,
4488 .gettstamp = sock_gettstamp,
4481 .listen = sock_no_listen, 4489 .listen = sock_no_listen,
4482 .shutdown = sock_no_shutdown, 4490 .shutdown = sock_no_shutdown,
4483 .setsockopt = packet_setsockopt, 4491 .setsockopt = packet_setsockopt,
@@ -4590,14 +4598,29 @@ static void __exit packet_exit(void)
4590 4598
4591static int __init packet_init(void) 4599static int __init packet_init(void)
4592{ 4600{
4593 int rc = proto_register(&packet_proto, 0); 4601 int rc;
4594 4602
4595 if (rc != 0) 4603 rc = proto_register(&packet_proto, 0);
4604 if (rc)
4596 goto out; 4605 goto out;
4606 rc = sock_register(&packet_family_ops);
4607 if (rc)
4608 goto out_proto;
4609 rc = register_pernet_subsys(&packet_net_ops);
4610 if (rc)
4611 goto out_sock;
4612 rc = register_netdevice_notifier(&packet_netdev_notifier);
4613 if (rc)
4614 goto out_pernet;
4615
4616 return 0;
4597 4617
4598 sock_register(&packet_family_ops); 4618out_pernet:
4599 register_pernet_subsys(&packet_net_ops); 4619 unregister_pernet_subsys(&packet_net_ops);
4600 register_netdevice_notifier(&packet_netdev_notifier); 4620out_sock:
4621 sock_unregister(PF_PACKET);
4622out_proto:
4623 proto_unregister(&packet_proto);
4601out: 4624out:
4602 return rc; 4625 return rc;
4603} 4626}
diff --git a/net/packet/diag.c b/net/packet/diag.c
index 7ef1c881ae74..98abfd8644a4 100644
--- a/net/packet/diag.c
+++ b/net/packet/diag.c
@@ -39,7 +39,7 @@ static int pdiag_put_mclist(const struct packet_sock *po, struct sk_buff *nlskb)
39 struct nlattr *mca; 39 struct nlattr *mca;
40 struct packet_mclist *ml; 40 struct packet_mclist *ml;
41 41
42 mca = nla_nest_start(nlskb, PACKET_DIAG_MCLIST); 42 mca = nla_nest_start_noflag(nlskb, PACKET_DIAG_MCLIST);
43 if (!mca) 43 if (!mca)
44 return -EMSGSIZE; 44 return -EMSGSIZE;
45 45
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index 871eaf2cb85e..be92d936b5d5 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -79,8 +79,8 @@ static int addr_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
79 79
80 ASSERT_RTNL(); 80 ASSERT_RTNL();
81 81
82 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_phonet_policy, 82 err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
83 extack); 83 ifa_phonet_policy, extack);
84 if (err < 0) 84 if (err < 0)
85 return err; 85 return err;
86 86
@@ -246,8 +246,8 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
246 246
247 ASSERT_RTNL(); 247 ASSERT_RTNL();
248 248
249 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_phonet_policy, 249 err = nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
250 extack); 250 rtm_phonet_policy, extack);
251 if (err < 0) 251 if (err < 0)
252 return err; 252 return err;
253 253
diff --git a/net/psample/psample.c b/net/psample/psample.c
index 64f95624f219..a107b2405668 100644
--- a/net/psample/psample.c
+++ b/net/psample/psample.c
@@ -100,6 +100,7 @@ static int psample_nl_cmd_get_group_dumpit(struct sk_buff *msg,
100static const struct genl_ops psample_nl_ops[] = { 100static const struct genl_ops psample_nl_ops[] = {
101 { 101 {
102 .cmd = PSAMPLE_CMD_GET_GROUP, 102 .cmd = PSAMPLE_CMD_GET_GROUP,
103 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
103 .dumpit = psample_nl_cmd_get_group_dumpit, 104 .dumpit = psample_nl_cmd_get_group_dumpit,
104 /* can be retrieved by unprivileged users */ 105 /* can be retrieved by unprivileged users */
105 } 106 }
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index b37e6e0a1026..801872a2e7aa 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -728,12 +728,13 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
728 DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name); 728 DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name);
729 int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int, 729 int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int,
730 struct sockaddr_qrtr *, struct sockaddr_qrtr *); 730 struct sockaddr_qrtr *, struct sockaddr_qrtr *);
731 __le32 qrtr_type = cpu_to_le32(QRTR_TYPE_DATA);
731 struct qrtr_sock *ipc = qrtr_sk(sock->sk); 732 struct qrtr_sock *ipc = qrtr_sk(sock->sk);
732 struct sock *sk = sock->sk; 733 struct sock *sk = sock->sk;
733 struct qrtr_node *node; 734 struct qrtr_node *node;
734 struct sk_buff *skb; 735 struct sk_buff *skb;
736 u32 type = 0;
735 size_t plen; 737 size_t plen;
736 u32 type = QRTR_TYPE_DATA;
737 int rc; 738 int rc;
738 739
739 if (msg->msg_flags & ~(MSG_DONTWAIT)) 740 if (msg->msg_flags & ~(MSG_DONTWAIT))
@@ -807,8 +808,8 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
807 } 808 }
808 809
809 /* control messages already require the type as 'command' */ 810 /* control messages already require the type as 'command' */
810 skb_copy_bits(skb, 0, &type, 4); 811 skb_copy_bits(skb, 0, &qrtr_type, 4);
811 type = le32_to_cpu(type); 812 type = le32_to_cpu(qrtr_type);
812 } 813 }
813 814
814 rc = enqueue_fn(node, skb, type, &ipc->us, addr); 815 rc = enqueue_fn(node, skb, type, &ipc->us, addr);
@@ -968,9 +969,6 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
968 break; 969 break;
969 } 970 }
970 break; 971 break;
971 case SIOCGSTAMP:
972 rc = sock_get_timestamp(sk, argp);
973 break;
974 case SIOCADDRT: 972 case SIOCADDRT:
975 case SIOCDELRT: 973 case SIOCDELRT:
976 case SIOCSIFADDR: 974 case SIOCSIFADDR:
@@ -1033,6 +1031,7 @@ static const struct proto_ops qrtr_proto_ops = {
1033 .recvmsg = qrtr_recvmsg, 1031 .recvmsg = qrtr_recvmsg,
1034 .getname = qrtr_getname, 1032 .getname = qrtr_getname,
1035 .ioctl = qrtr_ioctl, 1033 .ioctl = qrtr_ioctl,
1034 .gettstamp = sock_gettstamp,
1036 .poll = datagram_poll, 1035 .poll = datagram_poll,
1037 .shutdown = sock_no_shutdown, 1036 .shutdown = sock_no_shutdown,
1038 .setsockopt = sock_no_setsockopt, 1037 .setsockopt = sock_no_setsockopt,
@@ -1093,7 +1092,8 @@ static int qrtr_addr_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
1093 1092
1094 ASSERT_RTNL(); 1093 ASSERT_RTNL();
1095 1094
1096 rc = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, qrtr_policy, extack); 1095 rc = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
1096 qrtr_policy, extack);
1097 if (rc < 0) 1097 if (rc < 0)
1098 return rc; 1098 return rc;
1099 1099
diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c
index d6cc97fbbbb0..2b969f99ef13 100644
--- a/net/rds/af_rds.c
+++ b/net/rds/af_rds.c
@@ -543,6 +543,9 @@ static int rds_connect(struct socket *sock, struct sockaddr *uaddr,
543 struct rds_sock *rs = rds_sk_to_rs(sk); 543 struct rds_sock *rs = rds_sk_to_rs(sk);
544 int ret = 0; 544 int ret = 0;
545 545
546 if (addr_len < offsetofend(struct sockaddr, sa_family))
547 return -EINVAL;
548
546 lock_sock(sk); 549 lock_sock(sk);
547 550
548 switch (uaddr->sa_family) { 551 switch (uaddr->sa_family) {
diff --git a/net/rds/bind.c b/net/rds/bind.c
index 17c9d9f0c848..0f4398e7f2a7 100644
--- a/net/rds/bind.c
+++ b/net/rds/bind.c
@@ -173,6 +173,8 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
173 /* We allow an RDS socket to be bound to either IPv4 or IPv6 173 /* We allow an RDS socket to be bound to either IPv4 or IPv6
174 * address. 174 * address.
175 */ 175 */
176 if (addr_len < offsetofend(struct sockaddr, sa_family))
177 return -EINVAL;
176 if (uaddr->sa_family == AF_INET) { 178 if (uaddr->sa_family == AF_INET) {
177 struct sockaddr_in *sin = (struct sockaddr_in *)uaddr; 179 struct sockaddr_in *sin = (struct sockaddr_in *)uaddr;
178 180
diff --git a/net/rds/ib_fmr.c b/net/rds/ib_fmr.c
index 31cf37da4510..93c0437e6a5f 100644
--- a/net/rds/ib_fmr.c
+++ b/net/rds/ib_fmr.c
@@ -44,6 +44,17 @@ struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *rds_ibdev, int npages)
44 else 44 else
45 pool = rds_ibdev->mr_1m_pool; 45 pool = rds_ibdev->mr_1m_pool;
46 46
47 if (atomic_read(&pool->dirty_count) >= pool->max_items / 10)
48 queue_delayed_work(rds_ib_mr_wq, &pool->flush_worker, 10);
49
50 /* Switch pools if one of the pool is reaching upper limit */
51 if (atomic_read(&pool->dirty_count) >= pool->max_items * 9 / 10) {
52 if (pool->pool_type == RDS_IB_MR_8K_POOL)
53 pool = rds_ibdev->mr_1m_pool;
54 else
55 pool = rds_ibdev->mr_8k_pool;
56 }
57
47 ibmr = rds_ib_try_reuse_ibmr(pool); 58 ibmr = rds_ib_try_reuse_ibmr(pool);
48 if (ibmr) 59 if (ibmr)
49 return ibmr; 60 return ibmr;
diff --git a/net/rds/ib_rdma.c b/net/rds/ib_rdma.c
index 63c8d107adcf..d664e9ade74d 100644
--- a/net/rds/ib_rdma.c
+++ b/net/rds/ib_rdma.c
@@ -454,9 +454,6 @@ struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *pool)
454 struct rds_ib_mr *ibmr = NULL; 454 struct rds_ib_mr *ibmr = NULL;
455 int iter = 0; 455 int iter = 0;
456 456
457 if (atomic_read(&pool->dirty_count) >= pool->max_items_soft / 10)
458 queue_delayed_work(rds_ib_mr_wq, &pool->flush_worker, 10);
459
460 while (1) { 457 while (1) {
461 ibmr = rds_ib_reuse_mr(pool); 458 ibmr = rds_ib_reuse_mr(pool);
462 if (ibmr) 459 if (ibmr)
diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index 70559854837e..8946c89d7392 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -772,7 +772,7 @@ static void rds_ib_cong_recv(struct rds_connection *conn,
772 unsigned long frag_off; 772 unsigned long frag_off;
773 unsigned long to_copy; 773 unsigned long to_copy;
774 unsigned long copied; 774 unsigned long copied;
775 uint64_t uncongested = 0; 775 __le64 uncongested = 0;
776 void *addr; 776 void *addr;
777 777
778 /* catch completely corrupt packets */ 778 /* catch completely corrupt packets */
@@ -789,7 +789,7 @@ static void rds_ib_cong_recv(struct rds_connection *conn,
789 copied = 0; 789 copied = 0;
790 790
791 while (copied < RDS_CONG_MAP_BYTES) { 791 while (copied < RDS_CONG_MAP_BYTES) {
792 uint64_t *src, *dst; 792 __le64 *src, *dst;
793 unsigned int k; 793 unsigned int k;
794 794
795 to_copy = min(RDS_FRAG_SIZE - frag_off, PAGE_SIZE - map_off); 795 to_copy = min(RDS_FRAG_SIZE - frag_off, PAGE_SIZE - map_off);
@@ -824,9 +824,7 @@ static void rds_ib_cong_recv(struct rds_connection *conn,
824 } 824 }
825 825
826 /* the congestion map is in little endian order */ 826 /* the congestion map is in little endian order */
827 uncongested = le64_to_cpu(uncongested); 827 rds_cong_map_updated(map, le64_to_cpu(uncongested));
828
829 rds_cong_map_updated(map, uncongested);
830} 828}
831 829
832static void rds_ib_process_recv(struct rds_connection *conn, 830static void rds_ib_process_recv(struct rds_connection *conn,
diff --git a/net/rds/info.c b/net/rds/info.c
index e367a97a18c8..03f6fd56d237 100644
--- a/net/rds/info.c
+++ b/net/rds/info.c
@@ -193,7 +193,7 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval,
193 ret = -ENOMEM; 193 ret = -ENOMEM;
194 goto out; 194 goto out;
195 } 195 }
196 ret = get_user_pages_fast(start, nr_pages, 1, pages); 196 ret = get_user_pages_fast(start, nr_pages, FOLL_WRITE, pages);
197 if (ret != nr_pages) { 197 if (ret != nr_pages) {
198 if (ret > 0) 198 if (ret > 0)
199 nr_pages = ret; 199 nr_pages = ret;
diff --git a/net/rds/rdma.c b/net/rds/rdma.c
index 182ab8430594..b340ed4fc43a 100644
--- a/net/rds/rdma.c
+++ b/net/rds/rdma.c
@@ -158,7 +158,8 @@ static int rds_pin_pages(unsigned long user_addr, unsigned int nr_pages,
158{ 158{
159 int ret; 159 int ret;
160 160
161 ret = get_user_pages_fast(user_addr, nr_pages, write, pages); 161 ret = get_user_pages_fast(user_addr, nr_pages, write ? FOLL_WRITE : 0,
162 pages);
162 163
163 if (ret >= 0 && ret < nr_pages) { 164 if (ret >= 0 && ret < nr_pages) {
164 while (ret--) 165 while (ret--)
diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index faf726e00e27..66121bc6f34e 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -551,7 +551,7 @@ static __net_init int rds_tcp_init_net(struct net *net)
551 tbl = kmemdup(rds_tcp_sysctl_table, 551 tbl = kmemdup(rds_tcp_sysctl_table,
552 sizeof(rds_tcp_sysctl_table), GFP_KERNEL); 552 sizeof(rds_tcp_sysctl_table), GFP_KERNEL);
553 if (!tbl) { 553 if (!tbl) {
554 pr_warn("could not set allocate syctl table\n"); 554 pr_warn("could not set allocate sysctl table\n");
555 return -ENOMEM; 555 return -ENOMEM;
556 } 556 }
557 rtn->ctl_table = tbl; 557 rtn->ctl_table = tbl;
diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index abca57040f37..742e186bfadb 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -1143,7 +1143,7 @@ static int rfkill_fop_open(struct inode *inode, struct file *file)
1143 1143
1144 file->private_data = data; 1144 file->private_data = data;
1145 1145
1146 return nonseekable_open(inode, file); 1146 return stream_open(inode, file);
1147 1147
1148 free: 1148 free:
1149 mutex_unlock(&data->mtx); 1149 mutex_unlock(&data->mtx);
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index c96f63ffe31e..e274bc6e1458 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -1301,12 +1301,6 @@ static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1301 return put_user(amount, (unsigned int __user *) argp); 1301 return put_user(amount, (unsigned int __user *) argp);
1302 } 1302 }
1303 1303
1304 case SIOCGSTAMP:
1305 return sock_get_timestamp(sk, (struct timeval __user *) argp);
1306
1307 case SIOCGSTAMPNS:
1308 return sock_get_timestampns(sk, (struct timespec __user *) argp);
1309
1310 case SIOCGIFADDR: 1304 case SIOCGIFADDR:
1311 case SIOCSIFADDR: 1305 case SIOCSIFADDR:
1312 case SIOCGIFDSTADDR: 1306 case SIOCGIFDSTADDR:
@@ -1474,6 +1468,7 @@ static const struct proto_ops rose_proto_ops = {
1474 .getname = rose_getname, 1468 .getname = rose_getname,
1475 .poll = datagram_poll, 1469 .poll = datagram_poll,
1476 .ioctl = rose_ioctl, 1470 .ioctl = rose_ioctl,
1471 .gettstamp = sock_gettstamp,
1477 .listen = rose_listen, 1472 .listen = rose_listen,
1478 .shutdown = sock_no_shutdown, 1473 .shutdown = sock_no_shutdown,
1479 .setsockopt = rose_setsockopt, 1474 .setsockopt = rose_setsockopt,
diff --git a/net/rose/rose_loopback.c b/net/rose/rose_loopback.c
index 7af4f99c4a93..094a6621f8e8 100644
--- a/net/rose/rose_loopback.c
+++ b/net/rose/rose_loopback.c
@@ -16,6 +16,7 @@
16#include <linux/init.h> 16#include <linux/init.h>
17 17
18static struct sk_buff_head loopback_queue; 18static struct sk_buff_head loopback_queue;
19#define ROSE_LOOPBACK_LIMIT 1000
19static struct timer_list loopback_timer; 20static struct timer_list loopback_timer;
20 21
21static void rose_set_loopback_timer(void); 22static void rose_set_loopback_timer(void);
@@ -35,29 +36,27 @@ static int rose_loopback_running(void)
35 36
36int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh) 37int rose_loopback_queue(struct sk_buff *skb, struct rose_neigh *neigh)
37{ 38{
38 struct sk_buff *skbn; 39 struct sk_buff *skbn = NULL;
39 40
40 skbn = skb_clone(skb, GFP_ATOMIC); 41 if (skb_queue_len(&loopback_queue) < ROSE_LOOPBACK_LIMIT)
42 skbn = skb_clone(skb, GFP_ATOMIC);
41 43
42 kfree_skb(skb); 44 if (skbn) {
43 45 consume_skb(skb);
44 if (skbn != NULL) {
45 skb_queue_tail(&loopback_queue, skbn); 46 skb_queue_tail(&loopback_queue, skbn);
46 47
47 if (!rose_loopback_running()) 48 if (!rose_loopback_running())
48 rose_set_loopback_timer(); 49 rose_set_loopback_timer();
50 } else {
51 kfree_skb(skb);
49 } 52 }
50 53
51 return 1; 54 return 1;
52} 55}
53 56
54
55static void rose_set_loopback_timer(void) 57static void rose_set_loopback_timer(void)
56{ 58{
57 del_timer(&loopback_timer); 59 mod_timer(&loopback_timer, jiffies + 10);
58
59 loopback_timer.expires = jiffies + 10;
60 add_timer(&loopback_timer);
61} 60}
62 61
63static void rose_loopback_timer(struct timer_list *unused) 62static void rose_loopback_timer(struct timer_list *unused)
@@ -68,8 +67,12 @@ static void rose_loopback_timer(struct timer_list *unused)
68 struct sock *sk; 67 struct sock *sk;
69 unsigned short frametype; 68 unsigned short frametype;
70 unsigned int lci_i, lci_o; 69 unsigned int lci_i, lci_o;
70 int count;
71 71
72 while ((skb = skb_dequeue(&loopback_queue)) != NULL) { 72 for (count = 0; count < ROSE_LOOPBACK_LIMIT; count++) {
73 skb = skb_dequeue(&loopback_queue);
74 if (!skb)
75 return;
73 if (skb->len < ROSE_MIN_LEN) { 76 if (skb->len < ROSE_MIN_LEN) {
74 kfree_skb(skb); 77 kfree_skb(skb);
75 continue; 78 continue;
@@ -106,6 +109,8 @@ static void rose_loopback_timer(struct timer_list *unused)
106 kfree_skb(skb); 109 kfree_skb(skb);
107 } 110 }
108 } 111 }
112 if (!skb_queue_empty(&loopback_queue))
113 mod_timer(&loopback_timer, jiffies + 1);
109} 114}
110 115
111void __exit rose_loopback_clear(void) 116void __exit rose_loopback_clear(void)
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
index 96f2952bbdfd..ae8c5d7f3bf1 100644
--- a/net/rxrpc/af_rxrpc.c
+++ b/net/rxrpc/af_rxrpc.c
@@ -135,7 +135,7 @@ static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len)
135 struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *)saddr; 135 struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *)saddr;
136 struct rxrpc_local *local; 136 struct rxrpc_local *local;
137 struct rxrpc_sock *rx = rxrpc_sk(sock->sk); 137 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
138 u16 service_id = srx->srx_service; 138 u16 service_id;
139 int ret; 139 int ret;
140 140
141 _enter("%p,%p,%d", rx, saddr, len); 141 _enter("%p,%p,%d", rx, saddr, len);
@@ -143,6 +143,7 @@ static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len)
143 ret = rxrpc_validate_address(rx, srx, len); 143 ret = rxrpc_validate_address(rx, srx, len);
144 if (ret < 0) 144 if (ret < 0)
145 goto error; 145 goto error;
146 service_id = srx->srx_service;
146 147
147 lock_sock(&rx->sk); 148 lock_sock(&rx->sk);
148 149
@@ -370,18 +371,22 @@ EXPORT_SYMBOL(rxrpc_kernel_end_call);
370 * rxrpc_kernel_check_life - Check to see whether a call is still alive 371 * rxrpc_kernel_check_life - Check to see whether a call is still alive
371 * @sock: The socket the call is on 372 * @sock: The socket the call is on
372 * @call: The call to check 373 * @call: The call to check
374 * @_life: Where to store the life value
373 * 375 *
374 * Allow a kernel service to find out whether a call is still alive - ie. we're 376 * Allow a kernel service to find out whether a call is still alive - ie. we're
375 * getting ACKs from the server. Returns a number representing the life state 377 * getting ACKs from the server. Passes back in *_life a number representing
376 * which can be compared to that returned by a previous call. 378 * the life state which can be compared to that returned by a previous call and
379 * return true if the call is still alive.
377 * 380 *
378 * If the life state stalls, rxrpc_kernel_probe_life() should be called and 381 * If the life state stalls, rxrpc_kernel_probe_life() should be called and
379 * then 2RTT waited. 382 * then 2RTT waited.
380 */ 383 */
381u32 rxrpc_kernel_check_life(const struct socket *sock, 384bool rxrpc_kernel_check_life(const struct socket *sock,
382 const struct rxrpc_call *call) 385 const struct rxrpc_call *call,
386 u32 *_life)
383{ 387{
384 return call->acks_latest; 388 *_life = call->acks_latest;
389 return call->state != RXRPC_CALL_COMPLETE;
385} 390}
386EXPORT_SYMBOL(rxrpc_kernel_check_life); 391EXPORT_SYMBOL(rxrpc_kernel_check_life);
387 392
diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index 4b1a534d290a..062ca9dc29b8 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -654,6 +654,7 @@ struct rxrpc_call {
654 u8 ackr_reason; /* reason to ACK */ 654 u8 ackr_reason; /* reason to ACK */
655 u16 ackr_skew; /* skew on packet being ACK'd */ 655 u16 ackr_skew; /* skew on packet being ACK'd */
656 rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 656 rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */
657 rxrpc_serial_t ackr_first_seq; /* first sequence number received */
657 rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */ 658 rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */
658 rxrpc_seq_t ackr_consumed; /* Highest packet shown consumed */ 659 rxrpc_seq_t ackr_consumed; /* Highest packet shown consumed */
659 rxrpc_seq_t ackr_seen; /* Highest packet shown seen */ 660 rxrpc_seq_t ackr_seen; /* Highest packet shown seen */
diff --git a/net/rxrpc/call_object.c b/net/rxrpc/call_object.c
index 8aa2937b069f..fe96881a334d 100644
--- a/net/rxrpc/call_object.c
+++ b/net/rxrpc/call_object.c
@@ -604,30 +604,30 @@ void rxrpc_destroy_all_calls(struct rxrpc_net *rxnet)
604 604
605 _enter(""); 605 _enter("");
606 606
607 if (list_empty(&rxnet->calls)) 607 if (!list_empty(&rxnet->calls)) {
608 return; 608 write_lock(&rxnet->call_lock);
609 609
610 write_lock(&rxnet->call_lock); 610 while (!list_empty(&rxnet->calls)) {
611 call = list_entry(rxnet->calls.next,
612 struct rxrpc_call, link);
613 _debug("Zapping call %p", call);
611 614
612 while (!list_empty(&rxnet->calls)) { 615 rxrpc_see_call(call);
613 call = list_entry(rxnet->calls.next, struct rxrpc_call, link); 616 list_del_init(&call->link);
614 _debug("Zapping call %p", call);
615 617
616 rxrpc_see_call(call); 618 pr_err("Call %p still in use (%d,%s,%lx,%lx)!\n",
617 list_del_init(&call->link); 619 call, atomic_read(&call->usage),
620 rxrpc_call_states[call->state],
621 call->flags, call->events);
618 622
619 pr_err("Call %p still in use (%d,%s,%lx,%lx)!\n", 623 write_unlock(&rxnet->call_lock);
620 call, atomic_read(&call->usage), 624 cond_resched();
621 rxrpc_call_states[call->state], 625 write_lock(&rxnet->call_lock);
622 call->flags, call->events); 626 }
623 627
624 write_unlock(&rxnet->call_lock); 628 write_unlock(&rxnet->call_lock);
625 cond_resched();
626 write_lock(&rxnet->call_lock);
627 } 629 }
628 630
629 write_unlock(&rxnet->call_lock);
630
631 atomic_dec(&rxnet->nr_calls); 631 atomic_dec(&rxnet->nr_calls);
632 wait_var_event(&rxnet->nr_calls, !atomic_read(&rxnet->nr_calls)); 632 wait_var_event(&rxnet->nr_calls, !atomic_read(&rxnet->nr_calls));
633} 633}
diff --git a/net/rxrpc/conn_event.c b/net/rxrpc/conn_event.c
index b6fca8ebb117..8d31fb4c51e1 100644
--- a/net/rxrpc/conn_event.c
+++ b/net/rxrpc/conn_event.c
@@ -153,7 +153,8 @@ static void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn,
153 * pass a connection-level abort onto all calls on that connection 153 * pass a connection-level abort onto all calls on that connection
154 */ 154 */
155static void rxrpc_abort_calls(struct rxrpc_connection *conn, 155static void rxrpc_abort_calls(struct rxrpc_connection *conn,
156 enum rxrpc_call_completion compl) 156 enum rxrpc_call_completion compl,
157 rxrpc_serial_t serial)
157{ 158{
158 struct rxrpc_call *call; 159 struct rxrpc_call *call;
159 int i; 160 int i;
@@ -173,6 +174,9 @@ static void rxrpc_abort_calls(struct rxrpc_connection *conn,
173 call->call_id, 0, 174 call->call_id, 0,
174 conn->abort_code, 175 conn->abort_code,
175 conn->error); 176 conn->error);
177 else
178 trace_rxrpc_rx_abort(call, serial,
179 conn->abort_code);
176 if (rxrpc_set_call_completion(call, compl, 180 if (rxrpc_set_call_completion(call, compl,
177 conn->abort_code, 181 conn->abort_code,
178 conn->error)) 182 conn->error))
@@ -213,8 +217,6 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
213 conn->state = RXRPC_CONN_LOCALLY_ABORTED; 217 conn->state = RXRPC_CONN_LOCALLY_ABORTED;
214 spin_unlock_bh(&conn->state_lock); 218 spin_unlock_bh(&conn->state_lock);
215 219
216 rxrpc_abort_calls(conn, RXRPC_CALL_LOCALLY_ABORTED);
217
218 msg.msg_name = &conn->params.peer->srx.transport; 220 msg.msg_name = &conn->params.peer->srx.transport;
219 msg.msg_namelen = conn->params.peer->srx.transport_len; 221 msg.msg_namelen = conn->params.peer->srx.transport_len;
220 msg.msg_control = NULL; 222 msg.msg_control = NULL;
@@ -242,6 +244,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
242 len = iov[0].iov_len + iov[1].iov_len; 244 len = iov[0].iov_len + iov[1].iov_len;
243 245
244 serial = atomic_inc_return(&conn->serial); 246 serial = atomic_inc_return(&conn->serial);
247 rxrpc_abort_calls(conn, RXRPC_CALL_LOCALLY_ABORTED, serial);
245 whdr.serial = htonl(serial); 248 whdr.serial = htonl(serial);
246 _proto("Tx CONN ABORT %%%u { %d }", serial, conn->abort_code); 249 _proto("Tx CONN ABORT %%%u { %d }", serial, conn->abort_code);
247 250
@@ -321,7 +324,7 @@ static int rxrpc_process_event(struct rxrpc_connection *conn,
321 conn->error = -ECONNABORTED; 324 conn->error = -ECONNABORTED;
322 conn->abort_code = abort_code; 325 conn->abort_code = abort_code;
323 conn->state = RXRPC_CONN_REMOTELY_ABORTED; 326 conn->state = RXRPC_CONN_REMOTELY_ABORTED;
324 rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED); 327 rxrpc_abort_calls(conn, RXRPC_CALL_REMOTELY_ABORTED, sp->hdr.serial);
325 return -ECONNABORTED; 328 return -ECONNABORTED;
326 329
327 case RXRPC_PACKET_TYPE_CHALLENGE: 330 case RXRPC_PACKET_TYPE_CHALLENGE:
diff --git a/net/rxrpc/input.c b/net/rxrpc/input.c
index 9128aa0e40aa..c2c35cf4e308 100644
--- a/net/rxrpc/input.c
+++ b/net/rxrpc/input.c
@@ -837,7 +837,7 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb,
837 u8 acks[RXRPC_MAXACKS]; 837 u8 acks[RXRPC_MAXACKS];
838 } buf; 838 } buf;
839 rxrpc_serial_t acked_serial; 839 rxrpc_serial_t acked_serial;
840 rxrpc_seq_t first_soft_ack, hard_ack; 840 rxrpc_seq_t first_soft_ack, hard_ack, prev_pkt;
841 int nr_acks, offset, ioffset; 841 int nr_acks, offset, ioffset;
842 842
843 _enter(""); 843 _enter("");
@@ -851,13 +851,14 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb,
851 851
852 acked_serial = ntohl(buf.ack.serial); 852 acked_serial = ntohl(buf.ack.serial);
853 first_soft_ack = ntohl(buf.ack.firstPacket); 853 first_soft_ack = ntohl(buf.ack.firstPacket);
854 prev_pkt = ntohl(buf.ack.previousPacket);
854 hard_ack = first_soft_ack - 1; 855 hard_ack = first_soft_ack - 1;
855 nr_acks = buf.ack.nAcks; 856 nr_acks = buf.ack.nAcks;
856 summary.ack_reason = (buf.ack.reason < RXRPC_ACK__INVALID ? 857 summary.ack_reason = (buf.ack.reason < RXRPC_ACK__INVALID ?
857 buf.ack.reason : RXRPC_ACK__INVALID); 858 buf.ack.reason : RXRPC_ACK__INVALID);
858 859
859 trace_rxrpc_rx_ack(call, sp->hdr.serial, acked_serial, 860 trace_rxrpc_rx_ack(call, sp->hdr.serial, acked_serial,
860 first_soft_ack, ntohl(buf.ack.previousPacket), 861 first_soft_ack, prev_pkt,
861 summary.ack_reason, nr_acks); 862 summary.ack_reason, nr_acks);
862 863
863 if (buf.ack.reason == RXRPC_ACK_PING_RESPONSE) 864 if (buf.ack.reason == RXRPC_ACK_PING_RESPONSE)
@@ -878,8 +879,9 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb,
878 rxrpc_propose_ack_respond_to_ack); 879 rxrpc_propose_ack_respond_to_ack);
879 } 880 }
880 881
881 /* Discard any out-of-order or duplicate ACKs. */ 882 /* Discard any out-of-order or duplicate ACKs (outside lock). */
882 if (before_eq(sp->hdr.serial, call->acks_latest)) 883 if (before(first_soft_ack, call->ackr_first_seq) ||
884 before(prev_pkt, call->ackr_prev_seq))
883 return; 885 return;
884 886
885 buf.info.rxMTU = 0; 887 buf.info.rxMTU = 0;
@@ -890,12 +892,16 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb,
890 892
891 spin_lock(&call->input_lock); 893 spin_lock(&call->input_lock);
892 894
893 /* Discard any out-of-order or duplicate ACKs. */ 895 /* Discard any out-of-order or duplicate ACKs (inside lock). */
894 if (before_eq(sp->hdr.serial, call->acks_latest)) 896 if (before(first_soft_ack, call->ackr_first_seq) ||
897 before(prev_pkt, call->ackr_prev_seq))
895 goto out; 898 goto out;
896 call->acks_latest_ts = skb->tstamp; 899 call->acks_latest_ts = skb->tstamp;
897 call->acks_latest = sp->hdr.serial; 900 call->acks_latest = sp->hdr.serial;
898 901
902 call->ackr_first_seq = first_soft_ack;
903 call->ackr_prev_seq = prev_pkt;
904
899 /* Parse rwind and mtu sizes if provided. */ 905 /* Parse rwind and mtu sizes if provided. */
900 if (buf.info.rxMTU) 906 if (buf.info.rxMTU)
901 rxrpc_input_ackinfo(call, skb, &buf.info); 907 rxrpc_input_ackinfo(call, skb, &buf.info);
@@ -1155,19 +1161,19 @@ int rxrpc_extract_header(struct rxrpc_skb_priv *sp, struct sk_buff *skb)
1155 * handle data received on the local endpoint 1161 * handle data received on the local endpoint
1156 * - may be called in interrupt context 1162 * - may be called in interrupt context
1157 * 1163 *
1158 * The socket is locked by the caller and this prevents the socket from being 1164 * [!] Note that as this is called from the encap_rcv hook, the socket is not
1159 * shut down and the local endpoint from going away, thus sk_user_data will not 1165 * held locked by the caller and nothing prevents sk_user_data on the UDP from
1160 * be cleared until this function returns. 1166 * being cleared in the middle of processing this function.
1161 * 1167 *
1162 * Called with the RCU read lock held from the IP layer via UDP. 1168 * Called with the RCU read lock held from the IP layer via UDP.
1163 */ 1169 */
1164int rxrpc_input_packet(struct sock *udp_sk, struct sk_buff *skb) 1170int rxrpc_input_packet(struct sock *udp_sk, struct sk_buff *skb)
1165{ 1171{
1172 struct rxrpc_local *local = rcu_dereference_sk_user_data(udp_sk);
1166 struct rxrpc_connection *conn; 1173 struct rxrpc_connection *conn;
1167 struct rxrpc_channel *chan; 1174 struct rxrpc_channel *chan;
1168 struct rxrpc_call *call = NULL; 1175 struct rxrpc_call *call = NULL;
1169 struct rxrpc_skb_priv *sp; 1176 struct rxrpc_skb_priv *sp;
1170 struct rxrpc_local *local = udp_sk->sk_user_data;
1171 struct rxrpc_peer *peer = NULL; 1177 struct rxrpc_peer *peer = NULL;
1172 struct rxrpc_sock *rx = NULL; 1178 struct rxrpc_sock *rx = NULL;
1173 unsigned int channel; 1179 unsigned int channel;
@@ -1175,6 +1181,10 @@ int rxrpc_input_packet(struct sock *udp_sk, struct sk_buff *skb)
1175 1181
1176 _enter("%p", udp_sk); 1182 _enter("%p", udp_sk);
1177 1183
1184 if (unlikely(!local)) {
1185 kfree_skb(skb);
1186 return 0;
1187 }
1178 if (skb->tstamp == 0) 1188 if (skb->tstamp == 0)
1179 skb->tstamp = ktime_get_real(); 1189 skb->tstamp = ktime_get_real();
1180 1190
diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c
index 15cf42d5b53a..b67dec945498 100644
--- a/net/rxrpc/local_object.c
+++ b/net/rxrpc/local_object.c
@@ -180,7 +180,7 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
180 /* Fall through and set IPv4 options too otherwise we don't get 180 /* Fall through and set IPv4 options too otherwise we don't get
181 * errors from IPv4 packets sent through the IPv6 socket. 181 * errors from IPv4 packets sent through the IPv6 socket.
182 */ 182 */
183 183 /* Fall through */
184 case AF_INET: 184 case AF_INET:
185 /* we want to receive ICMP errors */ 185 /* we want to receive ICMP errors */
186 opt = 1; 186 opt = 1;
@@ -304,7 +304,8 @@ nomem:
304 ret = -ENOMEM; 304 ret = -ENOMEM;
305sock_error: 305sock_error:
306 mutex_unlock(&rxnet->local_mutex); 306 mutex_unlock(&rxnet->local_mutex);
307 kfree(local); 307 if (local)
308 call_rcu(&local->rcu, rxrpc_local_rcu);
308 _leave(" = %d", ret); 309 _leave(" = %d", ret);
309 return ERR_PTR(ret); 310 return ERR_PTR(ret);
310 311
diff --git a/net/rxrpc/peer_event.c b/net/rxrpc/peer_event.c
index bc05af89fc38..6e84d878053c 100644
--- a/net/rxrpc/peer_event.c
+++ b/net/rxrpc/peer_event.c
@@ -157,6 +157,11 @@ void rxrpc_error_report(struct sock *sk)
157 157
158 _enter("%p{%d}", sk, local->debug_id); 158 _enter("%p{%d}", sk, local->debug_id);
159 159
160 /* Clear the outstanding error value on the socket so that it doesn't
161 * cause kernel_sendmsg() to return it later.
162 */
163 sock_error(sk);
164
160 skb = sock_dequeue_err_skb(sk); 165 skb = sock_dequeue_err_skb(sk);
161 if (!skb) { 166 if (!skb) {
162 _leave("UDP socket errqueue empty"); 167 _leave("UDP socket errqueue empty");
diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c
index 46c9312085b1..bec64deb7b0a 100644
--- a/net/rxrpc/sendmsg.c
+++ b/net/rxrpc/sendmsg.c
@@ -152,12 +152,13 @@ static void rxrpc_notify_end_tx(struct rxrpc_sock *rx, struct rxrpc_call *call,
152} 152}
153 153
154/* 154/*
155 * Queue a DATA packet for transmission, set the resend timeout and send the 155 * Queue a DATA packet for transmission, set the resend timeout and send
156 * packet immediately 156 * the packet immediately. Returns the error from rxrpc_send_data_packet()
157 * in case the caller wants to do something with it.
157 */ 158 */
158static void rxrpc_queue_packet(struct rxrpc_sock *rx, struct rxrpc_call *call, 159static int rxrpc_queue_packet(struct rxrpc_sock *rx, struct rxrpc_call *call,
159 struct sk_buff *skb, bool last, 160 struct sk_buff *skb, bool last,
160 rxrpc_notify_end_tx_t notify_end_tx) 161 rxrpc_notify_end_tx_t notify_end_tx)
161{ 162{
162 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 163 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
163 unsigned long now; 164 unsigned long now;
@@ -250,7 +251,8 @@ static void rxrpc_queue_packet(struct rxrpc_sock *rx, struct rxrpc_call *call,
250 251
251out: 252out:
252 rxrpc_free_skb(skb, rxrpc_skb_tx_freed); 253 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);
253 _leave(""); 254 _leave(" = %d", ret);
255 return ret;
254} 256}
255 257
256/* 258/*
@@ -423,9 +425,10 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
423 if (ret < 0) 425 if (ret < 0)
424 goto out; 426 goto out;
425 427
426 rxrpc_queue_packet(rx, call, skb, 428 ret = rxrpc_queue_packet(rx, call, skb,
427 !msg_data_left(msg) && !more, 429 !msg_data_left(msg) && !more,
428 notify_end_tx); 430 notify_end_tx);
431 /* Should check for failure here */
429 skb = NULL; 432 skb = NULL;
430 } 433 }
431 } while (msg_data_left(msg) > 0); 434 } while (msg_data_left(msg) > 0);
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 5a87e271d35a..683fcc00da49 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -242,7 +242,7 @@ static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
242 (unsigned long)p->tcfa_tm.lastuse)) 242 (unsigned long)p->tcfa_tm.lastuse))
243 continue; 243 continue;
244 244
245 nest = nla_nest_start(skb, n_i); 245 nest = nla_nest_start_noflag(skb, n_i);
246 if (!nest) { 246 if (!nest) {
247 index--; 247 index--;
248 goto nla_put_failure; 248 goto nla_put_failure;
@@ -299,7 +299,7 @@ static int tcf_del_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb,
299 struct tc_action *p; 299 struct tc_action *p;
300 unsigned long id = 1; 300 unsigned long id = 1;
301 301
302 nest = nla_nest_start(skb, 0); 302 nest = nla_nest_start_noflag(skb, 0);
303 if (nest == NULL) 303 if (nest == NULL)
304 goto nla_put_failure; 304 goto nla_put_failure;
305 if (nla_put_string(skb, TCA_KIND, ops->kind)) 305 if (nla_put_string(skb, TCA_KIND, ops->kind))
@@ -776,7 +776,7 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
776 } 776 }
777 rcu_read_unlock(); 777 rcu_read_unlock();
778 778
779 nest = nla_nest_start(skb, TCA_OPTIONS); 779 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
780 if (nest == NULL) 780 if (nest == NULL)
781 goto nla_put_failure; 781 goto nla_put_failure;
782 err = tcf_action_dump_old(skb, a, bind, ref); 782 err = tcf_action_dump_old(skb, a, bind, ref);
@@ -800,7 +800,7 @@ int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[],
800 800
801 for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) { 801 for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
802 a = actions[i]; 802 a = actions[i];
803 nest = nla_nest_start(skb, a->order); 803 nest = nla_nest_start_noflag(skb, a->order);
804 if (nest == NULL) 804 if (nest == NULL)
805 goto nla_put_failure; 805 goto nla_put_failure;
806 err = tcf_action_dump_1(skb, a, bind, ref); 806 err = tcf_action_dump_1(skb, a, bind, ref);
@@ -849,7 +849,8 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
849 int err; 849 int err;
850 850
851 if (name == NULL) { 851 if (name == NULL) {
852 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL, extack); 852 err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL,
853 extack);
853 if (err < 0) 854 if (err < 0)
854 goto err_out; 855 goto err_out;
855 err = -EINVAL; 856 err = -EINVAL;
@@ -964,7 +965,8 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
964 int err; 965 int err;
965 int i; 966 int i;
966 967
967 err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL, extack); 968 err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX_PRIO, nla, NULL,
969 extack);
968 if (err < 0) 970 if (err < 0)
969 return err; 971 return err;
970 972
@@ -1052,7 +1054,7 @@ static int tca_get_fill(struct sk_buff *skb, struct tc_action *actions[],
1052 t->tca__pad1 = 0; 1054 t->tca__pad1 = 0;
1053 t->tca__pad2 = 0; 1055 t->tca__pad2 = 0;
1054 1056
1055 nest = nla_nest_start(skb, TCA_ACT_TAB); 1057 nest = nla_nest_start_noflag(skb, TCA_ACT_TAB);
1056 if (!nest) 1058 if (!nest)
1057 goto out_nlmsg_trim; 1059 goto out_nlmsg_trim;
1058 1060
@@ -1099,7 +1101,7 @@ static struct tc_action *tcf_action_get_1(struct net *net, struct nlattr *nla,
1099 int index; 1101 int index;
1100 int err; 1102 int err;
1101 1103
1102 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL, extack); 1104 err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL, extack);
1103 if (err < 0) 1105 if (err < 0)
1104 goto err_out; 1106 goto err_out;
1105 1107
@@ -1153,7 +1155,7 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
1153 1155
1154 b = skb_tail_pointer(skb); 1156 b = skb_tail_pointer(skb);
1155 1157
1156 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL, extack); 1158 err = nla_parse_nested_deprecated(tb, TCA_ACT_MAX, nla, NULL, extack);
1157 if (err < 0) 1159 if (err < 0)
1158 goto err_out; 1160 goto err_out;
1159 1161
@@ -1176,7 +1178,7 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
1176 t->tca__pad1 = 0; 1178 t->tca__pad1 = 0;
1177 t->tca__pad2 = 0; 1179 t->tca__pad2 = 0;
1178 1180
1179 nest = nla_nest_start(skb, TCA_ACT_TAB); 1181 nest = nla_nest_start_noflag(skb, TCA_ACT_TAB);
1180 if (!nest) { 1182 if (!nest) {
1181 NL_SET_ERR_MSG(extack, "Failed to add new netlink message"); 1183 NL_SET_ERR_MSG(extack, "Failed to add new netlink message");
1182 goto out_module_put; 1184 goto out_module_put;
@@ -1282,7 +1284,8 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
1282 size_t attr_size = 0; 1284 size_t attr_size = 0;
1283 struct tc_action *actions[TCA_ACT_MAX_PRIO] = {}; 1285 struct tc_action *actions[TCA_ACT_MAX_PRIO] = {};
1284 1286
1285 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL, extack); 1287 ret = nla_parse_nested_deprecated(tb, TCA_ACT_MAX_PRIO, nla, NULL,
1288 extack);
1286 if (ret < 0) 1289 if (ret < 0)
1287 return ret; 1290 return ret;
1288 1291
@@ -1384,8 +1387,8 @@ static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n,
1384 !netlink_capable(skb, CAP_NET_ADMIN)) 1387 !netlink_capable(skb, CAP_NET_ADMIN))
1385 return -EPERM; 1388 return -EPERM;
1386 1389
1387 ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ROOT_MAX, NULL, 1390 ret = nlmsg_parse_deprecated(n, sizeof(struct tcamsg), tca,
1388 extack); 1391 TCA_ROOT_MAX, NULL, extack);
1389 if (ret < 0) 1392 if (ret < 0)
1390 return ret; 1393 return ret;
1391 1394
@@ -1436,13 +1439,12 @@ static struct nlattr *find_dump_kind(struct nlattr **nla)
1436 if (tb1 == NULL) 1439 if (tb1 == NULL)
1437 return NULL; 1440 return NULL;
1438 1441
1439 if (nla_parse(tb, TCA_ACT_MAX_PRIO, nla_data(tb1), 1442 if (nla_parse_deprecated(tb, TCA_ACT_MAX_PRIO, nla_data(tb1), NLMSG_ALIGN(nla_len(tb1)), NULL, NULL) < 0)
1440 NLMSG_ALIGN(nla_len(tb1)), NULL, NULL) < 0)
1441 return NULL; 1443 return NULL;
1442 1444
1443 if (tb[1] == NULL) 1445 if (tb[1] == NULL)
1444 return NULL; 1446 return NULL;
1445 if (nla_parse_nested(tb2, TCA_ACT_MAX, tb[1], NULL, NULL) < 0) 1447 if (nla_parse_nested_deprecated(tb2, TCA_ACT_MAX, tb[1], NULL, NULL) < 0)
1446 return NULL; 1448 return NULL;
1447 kind = tb2[TCA_ACT_KIND]; 1449 kind = tb2[TCA_ACT_KIND];
1448 1450
@@ -1466,8 +1468,8 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1466 u32 msecs_since = 0; 1468 u32 msecs_since = 0;
1467 u32 act_count = 0; 1469 u32 act_count = 0;
1468 1470
1469 ret = nlmsg_parse(cb->nlh, sizeof(struct tcamsg), tb, TCA_ROOT_MAX, 1471 ret = nlmsg_parse_deprecated(cb->nlh, sizeof(struct tcamsg), tb,
1470 tcaa_policy, cb->extack); 1472 TCA_ROOT_MAX, tcaa_policy, cb->extack);
1471 if (ret < 0) 1473 if (ret < 0)
1472 return ret; 1474 return ret;
1473 1475
@@ -1508,7 +1510,7 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1508 if (!count_attr) 1510 if (!count_attr)
1509 goto out_module_put; 1511 goto out_module_put;
1510 1512
1511 nest = nla_nest_start(skb, TCA_ACT_TAB); 1513 nest = nla_nest_start_noflag(skb, TCA_ACT_TAB);
1512 if (nest == NULL) 1514 if (nest == NULL)
1513 goto out_module_put; 1515 goto out_module_put;
1514 1516
diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c
index 3841156aa09f..a0c77faca04b 100644
--- a/net/sched/act_bpf.c
+++ b/net/sched/act_bpf.c
@@ -293,7 +293,8 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
293 if (!nla) 293 if (!nla)
294 return -EINVAL; 294 return -EINVAL;
295 295
296 ret = nla_parse_nested(tb, TCA_ACT_BPF_MAX, nla, act_bpf_policy, NULL); 296 ret = nla_parse_nested_deprecated(tb, TCA_ACT_BPF_MAX, nla,
297 act_bpf_policy, NULL);
297 if (ret < 0) 298 if (ret < 0)
298 return ret; 299 return ret;
299 300
diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c
index 32ae0cd6e31c..8838575cd536 100644
--- a/net/sched/act_connmark.c
+++ b/net/sched/act_connmark.c
@@ -111,8 +111,8 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
111 if (!nla) 111 if (!nla)
112 return -EINVAL; 112 return -EINVAL;
113 113
114 ret = nla_parse_nested(tb, TCA_CONNMARK_MAX, nla, connmark_policy, 114 ret = nla_parse_nested_deprecated(tb, TCA_CONNMARK_MAX, nla,
115 NULL); 115 connmark_policy, NULL);
116 if (ret < 0) 116 if (ret < 0)
117 return ret; 117 return ret;
118 118
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index 0c77e7bdf6d5..14bb525e355e 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -61,7 +61,8 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
61 if (nla == NULL) 61 if (nla == NULL)
62 return -EINVAL; 62 return -EINVAL;
63 63
64 err = nla_parse_nested(tb, TCA_CSUM_MAX, nla, csum_policy, NULL); 64 err = nla_parse_nested_deprecated(tb, TCA_CSUM_MAX, nla, csum_policy,
65 NULL);
65 if (err < 0) 66 if (err < 0)
66 return err; 67 return err;
67 68
diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
index e540e31069d7..75492b07f324 100644
--- a/net/sched/act_gact.c
+++ b/net/sched/act_gact.c
@@ -74,7 +74,8 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
74 if (nla == NULL) 74 if (nla == NULL)
75 return -EINVAL; 75 return -EINVAL;
76 76
77 err = nla_parse_nested(tb, TCA_GACT_MAX, nla, gact_policy, NULL); 77 err = nla_parse_nested_deprecated(tb, TCA_GACT_MAX, nla, gact_policy,
78 NULL);
78 if (err < 0) 79 if (err < 0)
79 return err; 80 return err;
80 81
diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index 31c6ffb6abe7..12489f60a979 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -387,7 +387,7 @@ static int dump_metalist(struct sk_buff *skb, struct tcf_ife_info *ife)
387 if (list_empty(&ife->metalist)) 387 if (list_empty(&ife->metalist))
388 return 0; 388 return 0;
389 389
390 nest = nla_nest_start(skb, TCA_IFE_METALST); 390 nest = nla_nest_start_noflag(skb, TCA_IFE_METALST);
391 if (!nest) 391 if (!nest)
392 goto out_nlmsg_trim; 392 goto out_nlmsg_trim;
393 393
@@ -486,7 +486,8 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
486 int ret = 0; 486 int ret = 0;
487 int err; 487 int err;
488 488
489 err = nla_parse_nested(tb, TCA_IFE_MAX, nla, ife_policy, NULL); 489 err = nla_parse_nested_deprecated(tb, TCA_IFE_MAX, nla, ife_policy,
490 NULL);
490 if (err < 0) 491 if (err < 0)
491 return err; 492 return err;
492 493
@@ -567,8 +568,9 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
567 INIT_LIST_HEAD(&ife->metalist); 568 INIT_LIST_HEAD(&ife->metalist);
568 569
569 if (tb[TCA_IFE_METALST]) { 570 if (tb[TCA_IFE_METALST]) {
570 err = nla_parse_nested(tb2, IFE_META_MAX, tb[TCA_IFE_METALST], 571 err = nla_parse_nested_deprecated(tb2, IFE_META_MAX,
571 NULL, NULL); 572 tb[TCA_IFE_METALST], NULL,
573 NULL);
572 if (err) 574 if (err)
573 goto metadata_parse_err; 575 goto metadata_parse_err;
574 err = populate_metalist(ife, tb2, exists, rtnl_held); 576 err = populate_metalist(ife, tb2, exists, rtnl_held);
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 04a0b5c61194..ae6e28ab1cd7 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -113,7 +113,8 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla,
113 if (nla == NULL) 113 if (nla == NULL)
114 return -EINVAL; 114 return -EINVAL;
115 115
116 err = nla_parse_nested(tb, TCA_IPT_MAX, nla, ipt_policy, NULL); 116 err = nla_parse_nested_deprecated(tb, TCA_IPT_MAX, nla, ipt_policy,
117 NULL);
117 if (err < 0) 118 if (err < 0)
118 return err; 119 return err;
119 120
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 17cc6bd4c57c..c329390342f4 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -111,7 +111,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
111 NL_SET_ERR_MSG_MOD(extack, "Mirred requires attributes to be passed"); 111 NL_SET_ERR_MSG_MOD(extack, "Mirred requires attributes to be passed");
112 return -EINVAL; 112 return -EINVAL;
113 } 113 }
114 ret = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy, extack); 114 ret = nla_parse_nested_deprecated(tb, TCA_MIRRED_MAX, nla,
115 mirred_policy, extack);
115 if (ret < 0) 116 if (ret < 0)
116 return ret; 117 return ret;
117 if (!tb[TCA_MIRRED_PARMS]) { 118 if (!tb[TCA_MIRRED_PARMS]) {
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index e91bb8eb81ec..51bd1ba02380 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -52,7 +52,8 @@ static int tcf_nat_init(struct net *net, struct nlattr *nla, struct nlattr *est,
52 if (nla == NULL) 52 if (nla == NULL)
53 return -EINVAL; 53 return -EINVAL;
54 54
55 err = nla_parse_nested(tb, TCA_NAT_MAX, nla, nat_policy, NULL); 55 err = nla_parse_nested_deprecated(tb, TCA_NAT_MAX, nla, nat_policy,
56 NULL);
56 if (err < 0) 57 if (err < 0)
57 return err; 58 return err;
58 59
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 287793abfaf9..d790c02b9c6c 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -70,8 +70,9 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla,
70 goto err_out; 70 goto err_out;
71 } 71 }
72 72
73 err = nla_parse_nested(tb, TCA_PEDIT_KEY_EX_MAX, ka, 73 err = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX,
74 pedit_key_ex_policy, NULL); 74 ka, pedit_key_ex_policy,
75 NULL);
75 if (err) 76 if (err)
76 goto err_out; 77 goto err_out;
77 78
@@ -108,14 +109,15 @@ err_out:
108static int tcf_pedit_key_ex_dump(struct sk_buff *skb, 109static int tcf_pedit_key_ex_dump(struct sk_buff *skb,
109 struct tcf_pedit_key_ex *keys_ex, int n) 110 struct tcf_pedit_key_ex *keys_ex, int n)
110{ 111{
111 struct nlattr *keys_start = nla_nest_start(skb, TCA_PEDIT_KEYS_EX); 112 struct nlattr *keys_start = nla_nest_start_noflag(skb,
113 TCA_PEDIT_KEYS_EX);
112 114
113 if (!keys_start) 115 if (!keys_start)
114 goto nla_failure; 116 goto nla_failure;
115 for (; n > 0; n--) { 117 for (; n > 0; n--) {
116 struct nlattr *key_start; 118 struct nlattr *key_start;
117 119
118 key_start = nla_nest_start(skb, TCA_PEDIT_KEY_EX); 120 key_start = nla_nest_start_noflag(skb, TCA_PEDIT_KEY_EX);
119 if (!key_start) 121 if (!key_start)
120 goto nla_failure; 122 goto nla_failure;
121 123
@@ -157,7 +159,8 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
157 return -EINVAL; 159 return -EINVAL;
158 } 160 }
159 161
160 err = nla_parse_nested(tb, TCA_PEDIT_MAX, nla, pedit_policy, NULL); 162 err = nla_parse_nested_deprecated(tb, TCA_PEDIT_MAX, nla,
163 pedit_policy, NULL);
161 if (err < 0) 164 if (err < 0)
162 return err; 165 return err;
163 166
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 2b8581f6ab51..61731944742a 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -22,42 +22,7 @@
22#include <net/act_api.h> 22#include <net/act_api.h>
23#include <net/netlink.h> 23#include <net/netlink.h>
24#include <net/pkt_cls.h> 24#include <net/pkt_cls.h>
25 25#include <net/tc_act/tc_police.h>
26struct tcf_police_params {
27 int tcfp_result;
28 u32 tcfp_ewma_rate;
29 s64 tcfp_burst;
30 u32 tcfp_mtu;
31 s64 tcfp_mtu_ptoks;
32 struct psched_ratecfg rate;
33 bool rate_present;
34 struct psched_ratecfg peak;
35 bool peak_present;
36 struct rcu_head rcu;
37};
38
39struct tcf_police {
40 struct tc_action common;
41 struct tcf_police_params __rcu *params;
42
43 spinlock_t tcfp_lock ____cacheline_aligned_in_smp;
44 s64 tcfp_toks;
45 s64 tcfp_ptoks;
46 s64 tcfp_t_c;
47};
48
49#define to_police(pc) ((struct tcf_police *)pc)
50
51/* old policer structure from before tc actions */
52struct tc_police_compat {
53 u32 index;
54 int action;
55 u32 limit;
56 u32 burst;
57 u32 mtu;
58 struct tc_ratespec rate;
59 struct tc_ratespec peakrate;
60};
61 26
62/* Each policer is serialized by its individual spinlock */ 27/* Each policer is serialized by its individual spinlock */
63 28
@@ -100,7 +65,8 @@ static int tcf_police_init(struct net *net, struct nlattr *nla,
100 if (nla == NULL) 65 if (nla == NULL)
101 return -EINVAL; 66 return -EINVAL;
102 67
103 err = nla_parse_nested(tb, TCA_POLICE_MAX, nla, police_policy, NULL); 68 err = nla_parse_nested_deprecated(tb, TCA_POLICE_MAX, nla,
69 police_policy, NULL);
104 if (err < 0) 70 if (err < 0)
105 return err; 71 return err;
106 72
@@ -316,6 +282,20 @@ static void tcf_police_cleanup(struct tc_action *a)
316 kfree_rcu(p, rcu); 282 kfree_rcu(p, rcu);
317} 283}
318 284
285static void tcf_police_stats_update(struct tc_action *a,
286 u64 bytes, u32 packets,
287 u64 lastuse, bool hw)
288{
289 struct tcf_police *police = to_police(a);
290 struct tcf_t *tm = &police->tcf_tm;
291
292 _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
293 if (hw)
294 _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
295 bytes, packets);
296 tm->lastuse = max_t(u64, tm->lastuse, lastuse);
297}
298
319static int tcf_police_dump(struct sk_buff *skb, struct tc_action *a, 299static int tcf_police_dump(struct sk_buff *skb, struct tc_action *a,
320 int bind, int ref) 300 int bind, int ref)
321{ 301{
@@ -379,6 +359,7 @@ static struct tc_action_ops act_police_ops = {
379 .kind = "police", 359 .kind = "police",
380 .id = TCA_ID_POLICE, 360 .id = TCA_ID_POLICE,
381 .owner = THIS_MODULE, 361 .owner = THIS_MODULE,
362 .stats_update = tcf_police_stats_update,
382 .act = tcf_police_act, 363 .act = tcf_police_act,
383 .dump = tcf_police_dump, 364 .dump = tcf_police_dump,
384 .init = tcf_police_init, 365 .init = tcf_police_init,
diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c
index 0f82d50ea232..b2faa43c1ac7 100644
--- a/net/sched/act_sample.c
+++ b/net/sched/act_sample.c
@@ -53,7 +53,8 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
53 53
54 if (!nla) 54 if (!nla)
55 return -EINVAL; 55 return -EINVAL;
56 ret = nla_parse_nested(tb, TCA_SAMPLE_MAX, nla, sample_policy, NULL); 56 ret = nla_parse_nested_deprecated(tb, TCA_SAMPLE_MAX, nla,
57 sample_policy, NULL);
57 if (ret < 0) 58 if (ret < 0)
58 return ret; 59 return ret;
59 if (!tb[TCA_SAMPLE_PARMS] || !tb[TCA_SAMPLE_RATE] || 60 if (!tb[TCA_SAMPLE_PARMS] || !tb[TCA_SAMPLE_RATE] ||
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index 23c8ca5615e5..ead480e6014c 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -104,7 +104,8 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
104 if (nla == NULL) 104 if (nla == NULL)
105 return -EINVAL; 105 return -EINVAL;
106 106
107 err = nla_parse_nested(tb, TCA_DEF_MAX, nla, simple_policy, NULL); 107 err = nla_parse_nested_deprecated(tb, TCA_DEF_MAX, nla, simple_policy,
108 NULL);
108 if (err < 0) 109 if (err < 0)
109 return err; 110 return err;
110 111
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index 7e1d261a31d2..7ec159b95364 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -114,7 +114,8 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
114 if (nla == NULL) 114 if (nla == NULL)
115 return -EINVAL; 115 return -EINVAL;
116 116
117 err = nla_parse_nested(tb, TCA_SKBEDIT_MAX, nla, skbedit_policy, NULL); 117 err = nla_parse_nested_deprecated(tb, TCA_SKBEDIT_MAX, nla,
118 skbedit_policy, NULL);
118 if (err < 0) 119 if (err < 0)
119 return err; 120 return err;
120 121
diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c
index 1d4c324d0a42..186ef98c828f 100644
--- a/net/sched/act_skbmod.c
+++ b/net/sched/act_skbmod.c
@@ -102,7 +102,8 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
102 if (!nla) 102 if (!nla)
103 return -EINVAL; 103 return -EINVAL;
104 104
105 err = nla_parse_nested(tb, TCA_SKBMOD_MAX, nla, skbmod_policy, NULL); 105 err = nla_parse_nested_deprecated(tb, TCA_SKBMOD_MAX, nla,
106 skbmod_policy, NULL);
106 if (err < 0) 107 if (err < 0)
107 return err; 108 return err;
108 109
diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index d5aaf90a3971..6a9070511ee8 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -76,8 +76,9 @@ tunnel_key_copy_geneve_opt(const struct nlattr *nla, void *dst, int dst_len,
76 int err, data_len, opt_len; 76 int err, data_len, opt_len;
77 u8 *data; 77 u8 *data;
78 78
79 err = nla_parse_nested(tb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX, 79 err = nla_parse_nested_deprecated(tb,
80 nla, geneve_opt_policy, extack); 80 TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX,
81 nla, geneve_opt_policy, extack);
81 if (err < 0) 82 if (err < 0)
82 return err; 83 return err;
83 84
@@ -125,8 +126,8 @@ static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,
125 int err, rem, opt_len, len = nla_len(nla), opts_len = 0; 126 int err, rem, opt_len, len = nla_len(nla), opts_len = 0;
126 const struct nlattr *attr, *head = nla_data(nla); 127 const struct nlattr *attr, *head = nla_data(nla);
127 128
128 err = nla_validate(head, len, TCA_TUNNEL_KEY_ENC_OPTS_MAX, 129 err = nla_validate_deprecated(head, len, TCA_TUNNEL_KEY_ENC_OPTS_MAX,
129 enc_opts_policy, extack); 130 enc_opts_policy, extack);
130 if (err) 131 if (err)
131 return err; 132 return err;
132 133
@@ -235,8 +236,8 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
235 return -EINVAL; 236 return -EINVAL;
236 } 237 }
237 238
238 err = nla_parse_nested(tb, TCA_TUNNEL_KEY_MAX, nla, tunnel_key_policy, 239 err = nla_parse_nested_deprecated(tb, TCA_TUNNEL_KEY_MAX, nla,
239 extack); 240 tunnel_key_policy, extack);
240 if (err < 0) { 241 if (err < 0) {
241 NL_SET_ERR_MSG(extack, "Failed to parse nested tunnel key attributes"); 242 NL_SET_ERR_MSG(extack, "Failed to parse nested tunnel key attributes");
242 return err; 243 return err;
@@ -426,7 +427,7 @@ static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
426 u8 *src = (u8 *)(info + 1); 427 u8 *src = (u8 *)(info + 1);
427 struct nlattr *start; 428 struct nlattr *start;
428 429
429 start = nla_nest_start(skb, TCA_TUNNEL_KEY_ENC_OPTS_GENEVE); 430 start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_GENEVE);
430 if (!start) 431 if (!start)
431 return -EMSGSIZE; 432 return -EMSGSIZE;
432 433
@@ -460,7 +461,7 @@ static int tunnel_key_opts_dump(struct sk_buff *skb,
460 if (!info->options_len) 461 if (!info->options_len)
461 return 0; 462 return 0;
462 463
463 start = nla_nest_start(skb, TCA_TUNNEL_KEY_ENC_OPTS); 464 start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS);
464 if (!start) 465 if (!start)
465 return -EMSGSIZE; 466 return -EMSGSIZE;
466 467
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index 0f40d0a74423..39bd9fa3e455 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -124,7 +124,8 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
124 if (!nla) 124 if (!nla)
125 return -EINVAL; 125 return -EINVAL;
126 126
127 err = nla_parse_nested(tb, TCA_VLAN_MAX, nla, vlan_policy, NULL); 127 err = nla_parse_nested_deprecated(tb, TCA_VLAN_MAX, nla, vlan_policy,
128 NULL);
128 if (err < 0) 129 if (err < 0)
129 return err; 130 return err;
130 131
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 99ae30c177c7..d4699156974a 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -37,6 +37,8 @@
37#include <net/tc_act/tc_tunnel_key.h> 37#include <net/tc_act/tc_tunnel_key.h>
38#include <net/tc_act/tc_csum.h> 38#include <net/tc_act/tc_csum.h>
39#include <net/tc_act/tc_gact.h> 39#include <net/tc_act/tc_gact.h>
40#include <net/tc_act/tc_police.h>
41#include <net/tc_act/tc_sample.h>
40#include <net/tc_act/tc_skbedit.h> 42#include <net/tc_act/tc_skbedit.h>
41 43
42extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1]; 44extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
@@ -2006,7 +2008,8 @@ static int tc_new_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
2006replay: 2008replay:
2007 tp_created = 0; 2009 tp_created = 0;
2008 2010
2009 err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, rtm_tca_policy, extack); 2011 err = nlmsg_parse_deprecated(n, sizeof(*t), tca, TCA_MAX,
2012 rtm_tca_policy, extack);
2010 if (err < 0) 2013 if (err < 0)
2011 return err; 2014 return err;
2012 2015
@@ -2217,7 +2220,8 @@ static int tc_del_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
2217 if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) 2220 if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
2218 return -EPERM; 2221 return -EPERM;
2219 2222
2220 err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, rtm_tca_policy, extack); 2223 err = nlmsg_parse_deprecated(n, sizeof(*t), tca, TCA_MAX,
2224 rtm_tca_policy, extack);
2221 if (err < 0) 2225 if (err < 0)
2222 return err; 2226 return err;
2223 2227
@@ -2366,7 +2370,8 @@ static int tc_get_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
2366 int err; 2370 int err;
2367 bool rtnl_held = false; 2371 bool rtnl_held = false;
2368 2372
2369 err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, rtm_tca_policy, extack); 2373 err = nlmsg_parse_deprecated(n, sizeof(*t), tca, TCA_MAX,
2374 rtm_tca_policy, extack);
2370 if (err < 0) 2375 if (err < 0)
2371 return err; 2376 return err;
2372 2377
@@ -2558,8 +2563,8 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
2558 if (nlmsg_len(cb->nlh) < sizeof(*tcm)) 2563 if (nlmsg_len(cb->nlh) < sizeof(*tcm))
2559 return skb->len; 2564 return skb->len;
2560 2565
2561 err = nlmsg_parse(cb->nlh, sizeof(*tcm), tca, TCA_MAX, NULL, 2566 err = nlmsg_parse_deprecated(cb->nlh, sizeof(*tcm), tca, TCA_MAX,
2562 cb->extack); 2567 NULL, cb->extack);
2563 if (err) 2568 if (err)
2564 return err; 2569 return err;
2565 2570
@@ -2806,7 +2811,8 @@ static int tc_ctl_chain(struct sk_buff *skb, struct nlmsghdr *n,
2806 return -EPERM; 2811 return -EPERM;
2807 2812
2808replay: 2813replay:
2809 err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, rtm_tca_policy, extack); 2814 err = nlmsg_parse_deprecated(n, sizeof(*t), tca, TCA_MAX,
2815 rtm_tca_policy, extack);
2810 if (err < 0) 2816 if (err < 0)
2811 return err; 2817 return err;
2812 2818
@@ -2937,8 +2943,8 @@ static int tc_dump_chain(struct sk_buff *skb, struct netlink_callback *cb)
2937 if (nlmsg_len(cb->nlh) < sizeof(*tcm)) 2943 if (nlmsg_len(cb->nlh) < sizeof(*tcm))
2938 return skb->len; 2944 return skb->len;
2939 2945
2940 err = nlmsg_parse(cb->nlh, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy, 2946 err = nlmsg_parse_deprecated(cb->nlh, sizeof(*tcm), tca, TCA_MAX,
2941 cb->extack); 2947 rtm_tca_policy, cb->extack);
2942 if (err) 2948 if (err)
2943 return err; 2949 return err;
2944 2950
@@ -3111,7 +3117,7 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
3111 * tc data even if iproute2 was newer - jhs 3117 * tc data even if iproute2 was newer - jhs
3112 */ 3118 */
3113 if (exts->type != TCA_OLD_COMPAT) { 3119 if (exts->type != TCA_OLD_COMPAT) {
3114 nest = nla_nest_start(skb, exts->action); 3120 nest = nla_nest_start_noflag(skb, exts->action);
3115 if (nest == NULL) 3121 if (nest == NULL)
3116 goto nla_put_failure; 3122 goto nla_put_failure;
3117 3123
@@ -3120,7 +3126,7 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
3120 nla_nest_end(skb, nest); 3126 nla_nest_end(skb, nest);
3121 } else if (exts->police) { 3127 } else if (exts->police) {
3122 struct tc_action *act = tcf_exts_first_act(exts); 3128 struct tc_action *act = tcf_exts_first_act(exts);
3123 nest = nla_nest_start(skb, exts->police); 3129 nest = nla_nest_start_noflag(skb, exts->police);
3124 if (nest == NULL || !act) 3130 if (nest == NULL || !act)
3125 goto nla_put_failure; 3131 goto nla_put_failure;
3126 if (tcf_action_dump_old(skb, act, 0, 0) < 0) 3132 if (tcf_action_dump_old(skb, act, 0, 0) < 0)
@@ -3229,7 +3235,6 @@ int tc_setup_flow_action(struct flow_action *flow_action,
3229 entry->tunnel = tcf_tunnel_info(act); 3235 entry->tunnel = tcf_tunnel_info(act);
3230 } else if (is_tcf_tunnel_release(act)) { 3236 } else if (is_tcf_tunnel_release(act)) {
3231 entry->id = FLOW_ACTION_TUNNEL_DECAP; 3237 entry->id = FLOW_ACTION_TUNNEL_DECAP;
3232 entry->tunnel = tcf_tunnel_info(act);
3233 } else if (is_tcf_pedit(act)) { 3238 } else if (is_tcf_pedit(act)) {
3234 for (k = 0; k < tcf_pedit_nkeys(act); k++) { 3239 for (k = 0; k < tcf_pedit_nkeys(act); k++) {
3235 switch (tcf_pedit_cmd(act, k)) { 3240 switch (tcf_pedit_cmd(act, k)) {
@@ -3254,6 +3259,18 @@ int tc_setup_flow_action(struct flow_action *flow_action,
3254 } else if (is_tcf_skbedit_mark(act)) { 3259 } else if (is_tcf_skbedit_mark(act)) {
3255 entry->id = FLOW_ACTION_MARK; 3260 entry->id = FLOW_ACTION_MARK;
3256 entry->mark = tcf_skbedit_mark(act); 3261 entry->mark = tcf_skbedit_mark(act);
3262 } else if (is_tcf_sample(act)) {
3263 entry->id = FLOW_ACTION_SAMPLE;
3264 entry->sample.psample_group =
3265 tcf_sample_psample_group(act);
3266 entry->sample.trunc_size = tcf_sample_trunc_size(act);
3267 entry->sample.truncate = tcf_sample_truncate(act);
3268 entry->sample.rate = tcf_sample_rate(act);
3269 } else if (is_tcf_police(act)) {
3270 entry->id = FLOW_ACTION_POLICE;
3271 entry->police.burst = tcf_police_tcfp_burst(act);
3272 entry->police.rate_bytes_ps =
3273 tcf_police_rate_bytes_ps(act);
3257 } else { 3274 } else {
3258 goto err_out; 3275 goto err_out;
3259 } 3276 }
diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c
index 687b0af67878..923863f3b0d8 100644
--- a/net/sched/cls_basic.c
+++ b/net/sched/cls_basic.c
@@ -185,8 +185,8 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
185 if (tca[TCA_OPTIONS] == NULL) 185 if (tca[TCA_OPTIONS] == NULL)
186 return -EINVAL; 186 return -EINVAL;
187 187
188 err = nla_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], 188 err = nla_parse_nested_deprecated(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS],
189 basic_policy, NULL); 189 basic_policy, NULL);
190 if (err < 0) 190 if (err < 0)
191 return err; 191 return err;
192 192
@@ -288,7 +288,7 @@ static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh,
288 288
289 t->tcm_handle = f->handle; 289 t->tcm_handle = f->handle;
290 290
291 nest = nla_nest_start(skb, TCA_OPTIONS); 291 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
292 if (nest == NULL) 292 if (nest == NULL)
293 goto nla_put_failure; 293 goto nla_put_failure;
294 294
diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
index b4ac58039cb1..27365ed3fe0b 100644
--- a/net/sched/cls_bpf.c
+++ b/net/sched/cls_bpf.c
@@ -157,8 +157,7 @@ static int cls_bpf_offload_cmd(struct tcf_proto *tp, struct cls_bpf_prog *prog,
157 skip_sw = prog && tc_skip_sw(prog->gen_flags); 157 skip_sw = prog && tc_skip_sw(prog->gen_flags);
158 obj = prog ?: oldprog; 158 obj = prog ?: oldprog;
159 159
160 tc_cls_common_offload_init(&cls_bpf.common, tp, obj->gen_flags, 160 tc_cls_common_offload_init(&cls_bpf.common, tp, obj->gen_flags, extack);
161 extack);
162 cls_bpf.command = TC_CLSBPF_OFFLOAD; 161 cls_bpf.command = TC_CLSBPF_OFFLOAD;
163 cls_bpf.exts = &obj->exts; 162 cls_bpf.exts = &obj->exts;
164 cls_bpf.prog = prog ? prog->filter : NULL; 163 cls_bpf.prog = prog ? prog->filter : NULL;
@@ -468,8 +467,8 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
468 if (tca[TCA_OPTIONS] == NULL) 467 if (tca[TCA_OPTIONS] == NULL)
469 return -EINVAL; 468 return -EINVAL;
470 469
471 ret = nla_parse_nested(tb, TCA_BPF_MAX, tca[TCA_OPTIONS], bpf_policy, 470 ret = nla_parse_nested_deprecated(tb, TCA_BPF_MAX, tca[TCA_OPTIONS],
472 NULL); 471 bpf_policy, NULL);
473 if (ret < 0) 472 if (ret < 0)
474 return ret; 473 return ret;
475 474
@@ -591,7 +590,7 @@ static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, void *fh,
591 590
592 cls_bpf_offload_update_stats(tp, prog); 591 cls_bpf_offload_update_stats(tp, prog);
593 592
594 nest = nla_nest_start(skb, TCA_OPTIONS); 593 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
595 if (nest == NULL) 594 if (nest == NULL)
596 goto nla_put_failure; 595 goto nla_put_failure;
597 596
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 4c1567854f95..35659127e5a3 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -32,6 +32,8 @@ static int cls_cgroup_classify(struct sk_buff *skb, const struct tcf_proto *tp,
32 struct cls_cgroup_head *head = rcu_dereference_bh(tp->root); 32 struct cls_cgroup_head *head = rcu_dereference_bh(tp->root);
33 u32 classid = task_get_classid(skb); 33 u32 classid = task_get_classid(skb);
34 34
35 if (unlikely(!head))
36 return -1;
35 if (!classid) 37 if (!classid)
36 return -1; 38 return -1;
37 if (!tcf_em_tree_match(skb, &head->ematches, NULL)) 39 if (!tcf_em_tree_match(skb, &head->ematches, NULL))
@@ -104,8 +106,9 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
104 goto errout; 106 goto errout;
105 new->handle = handle; 107 new->handle = handle;
106 new->tp = tp; 108 new->tp = tp;
107 err = nla_parse_nested(tb, TCA_CGROUP_MAX, tca[TCA_OPTIONS], 109 err = nla_parse_nested_deprecated(tb, TCA_CGROUP_MAX,
108 cgroup_policy, NULL); 110 tca[TCA_OPTIONS], cgroup_policy,
111 NULL);
109 if (err < 0) 112 if (err < 0)
110 goto errout; 113 goto errout;
111 114
@@ -176,7 +179,7 @@ static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, void *fh,
176 179
177 t->tcm_handle = head->handle; 180 t->tcm_handle = head->handle;
178 181
179 nest = nla_nest_start(skb, TCA_OPTIONS); 182 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
180 if (nest == NULL) 183 if (nest == NULL)
181 goto nla_put_failure; 184 goto nla_put_failure;
182 185
diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c
index eece1ee26930..7bb79ec5b176 100644
--- a/net/sched/cls_flow.c
+++ b/net/sched/cls_flow.c
@@ -408,7 +408,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
408 if (opt == NULL) 408 if (opt == NULL)
409 return -EINVAL; 409 return -EINVAL;
410 410
411 err = nla_parse_nested(tb, TCA_FLOW_MAX, opt, flow_policy, NULL); 411 err = nla_parse_nested_deprecated(tb, TCA_FLOW_MAX, opt, flow_policy,
412 NULL);
412 if (err < 0) 413 if (err < 0)
413 return err; 414 return err;
414 415
@@ -629,7 +630,7 @@ static int flow_dump(struct net *net, struct tcf_proto *tp, void *fh,
629 630
630 t->tcm_handle = f->handle; 631 t->tcm_handle = f->handle;
631 632
632 nest = nla_nest_start(skb, TCA_OPTIONS); 633 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
633 if (nest == NULL) 634 if (nest == NULL)
634 goto nla_put_failure; 635 goto nla_put_failure;
635 636
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index c04247b403ed..f6685fc53119 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -14,6 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/rhashtable.h> 15#include <linux/rhashtable.h>
16#include <linux/workqueue.h> 16#include <linux/workqueue.h>
17#include <linux/refcount.h>
17 18
18#include <linux/if_ether.h> 19#include <linux/if_ether.h>
19#include <linux/in6.h> 20#include <linux/in6.h>
@@ -75,6 +76,7 @@ struct fl_flow_mask {
75 struct list_head filters; 76 struct list_head filters;
76 struct rcu_work rwork; 77 struct rcu_work rwork;
77 struct list_head list; 78 struct list_head list;
79 refcount_t refcnt;
78}; 80};
79 81
80struct fl_flow_tmplt { 82struct fl_flow_tmplt {
@@ -86,7 +88,9 @@ struct fl_flow_tmplt {
86 88
87struct cls_fl_head { 89struct cls_fl_head {
88 struct rhashtable ht; 90 struct rhashtable ht;
91 spinlock_t masks_lock; /* Protect masks list */
89 struct list_head masks; 92 struct list_head masks;
93 struct list_head hw_filters;
90 struct rcu_work rwork; 94 struct rcu_work rwork;
91 struct idr handle_idr; 95 struct idr handle_idr;
92}; 96};
@@ -99,11 +103,18 @@ struct cls_fl_filter {
99 struct tcf_result res; 103 struct tcf_result res;
100 struct fl_flow_key key; 104 struct fl_flow_key key;
101 struct list_head list; 105 struct list_head list;
106 struct list_head hw_list;
102 u32 handle; 107 u32 handle;
103 u32 flags; 108 u32 flags;
104 u32 in_hw_count; 109 u32 in_hw_count;
105 struct rcu_work rwork; 110 struct rcu_work rwork;
106 struct net_device *hw_dev; 111 struct net_device *hw_dev;
112 /* Flower classifier is unlocked, which means that its reference counter
113 * can be changed concurrently without any kind of external
114 * synchronization. Use atomic reference counter to be concurrency-safe.
115 */
116 refcount_t refcnt;
117 bool deleted;
107}; 118};
108 119
109static const struct rhashtable_params mask_ht_params = { 120static const struct rhashtable_params mask_ht_params = {
@@ -304,7 +315,9 @@ static int fl_init(struct tcf_proto *tp)
304 if (!head) 315 if (!head)
305 return -ENOBUFS; 316 return -ENOBUFS;
306 317
318 spin_lock_init(&head->masks_lock);
307 INIT_LIST_HEAD_RCU(&head->masks); 319 INIT_LIST_HEAD_RCU(&head->masks);
320 INIT_LIST_HEAD(&head->hw_filters);
308 rcu_assign_pointer(tp->root, head); 321 rcu_assign_pointer(tp->root, head);
309 idr_init(&head->handle_idr); 322 idr_init(&head->handle_idr);
310 323
@@ -313,6 +326,7 @@ static int fl_init(struct tcf_proto *tp)
313 326
314static void fl_mask_free(struct fl_flow_mask *mask) 327static void fl_mask_free(struct fl_flow_mask *mask)
315{ 328{
329 WARN_ON(!list_empty(&mask->filters));
316 rhashtable_destroy(&mask->ht); 330 rhashtable_destroy(&mask->ht);
317 kfree(mask); 331 kfree(mask);
318} 332}
@@ -325,22 +339,32 @@ static void fl_mask_free_work(struct work_struct *work)
325 fl_mask_free(mask); 339 fl_mask_free(mask);
326} 340}
327 341
328static bool fl_mask_put(struct cls_fl_head *head, struct fl_flow_mask *mask, 342static bool fl_mask_put(struct cls_fl_head *head, struct fl_flow_mask *mask)
329 bool async)
330{ 343{
331 if (!list_empty(&mask->filters)) 344 if (!refcount_dec_and_test(&mask->refcnt))
332 return false; 345 return false;
333 346
334 rhashtable_remove_fast(&head->ht, &mask->ht_node, mask_ht_params); 347 rhashtable_remove_fast(&head->ht, &mask->ht_node, mask_ht_params);
348
349 spin_lock(&head->masks_lock);
335 list_del_rcu(&mask->list); 350 list_del_rcu(&mask->list);
336 if (async) 351 spin_unlock(&head->masks_lock);
337 tcf_queue_work(&mask->rwork, fl_mask_free_work); 352
338 else 353 tcf_queue_work(&mask->rwork, fl_mask_free_work);
339 fl_mask_free(mask);
340 354
341 return true; 355 return true;
342} 356}
343 357
358static struct cls_fl_head *fl_head_dereference(struct tcf_proto *tp)
359{
360 /* Flower classifier only changes root pointer during init and destroy.
361 * Users must obtain reference to tcf_proto instance before calling its
362 * API, so tp->root pointer is protected from concurrent call to
363 * fl_destroy() by reference counting.
364 */
365 return rcu_dereference_raw(tp->root);
366}
367
344static void __fl_destroy_filter(struct cls_fl_filter *f) 368static void __fl_destroy_filter(struct cls_fl_filter *f)
345{ 369{
346 tcf_exts_destroy(&f->exts); 370 tcf_exts_destroy(&f->exts);
@@ -353,37 +377,50 @@ static void fl_destroy_filter_work(struct work_struct *work)
353 struct cls_fl_filter *f = container_of(to_rcu_work(work), 377 struct cls_fl_filter *f = container_of(to_rcu_work(work),
354 struct cls_fl_filter, rwork); 378 struct cls_fl_filter, rwork);
355 379
356 rtnl_lock();
357 __fl_destroy_filter(f); 380 __fl_destroy_filter(f);
358 rtnl_unlock();
359} 381}
360 382
361static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f, 383static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f,
362 struct netlink_ext_ack *extack) 384 bool rtnl_held, struct netlink_ext_ack *extack)
363{ 385{
364 struct tc_cls_flower_offload cls_flower = {}; 386 struct tc_cls_flower_offload cls_flower = {};
365 struct tcf_block *block = tp->chain->block; 387 struct tcf_block *block = tp->chain->block;
366 388
389 if (!rtnl_held)
390 rtnl_lock();
391
367 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, extack); 392 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, extack);
368 cls_flower.command = TC_CLSFLOWER_DESTROY; 393 cls_flower.command = TC_CLSFLOWER_DESTROY;
369 cls_flower.cookie = (unsigned long) f; 394 cls_flower.cookie = (unsigned long) f;
370 395
371 tc_setup_cb_call(block, TC_SETUP_CLSFLOWER, &cls_flower, false); 396 tc_setup_cb_call(block, TC_SETUP_CLSFLOWER, &cls_flower, false);
397 spin_lock(&tp->lock);
398 list_del_init(&f->hw_list);
372 tcf_block_offload_dec(block, &f->flags); 399 tcf_block_offload_dec(block, &f->flags);
400 spin_unlock(&tp->lock);
401
402 if (!rtnl_held)
403 rtnl_unlock();
373} 404}
374 405
375static int fl_hw_replace_filter(struct tcf_proto *tp, 406static int fl_hw_replace_filter(struct tcf_proto *tp,
376 struct cls_fl_filter *f, 407 struct cls_fl_filter *f, bool rtnl_held,
377 struct netlink_ext_ack *extack) 408 struct netlink_ext_ack *extack)
378{ 409{
410 struct cls_fl_head *head = fl_head_dereference(tp);
379 struct tc_cls_flower_offload cls_flower = {}; 411 struct tc_cls_flower_offload cls_flower = {};
380 struct tcf_block *block = tp->chain->block; 412 struct tcf_block *block = tp->chain->block;
381 bool skip_sw = tc_skip_sw(f->flags); 413 bool skip_sw = tc_skip_sw(f->flags);
382 int err; 414 int err = 0;
415
416 if (!rtnl_held)
417 rtnl_lock();
383 418
384 cls_flower.rule = flow_rule_alloc(tcf_exts_num_actions(&f->exts)); 419 cls_flower.rule = flow_rule_alloc(tcf_exts_num_actions(&f->exts));
385 if (!cls_flower.rule) 420 if (!cls_flower.rule) {
386 return -ENOMEM; 421 err = -ENOMEM;
422 goto errout;
423 }
387 424
388 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, extack); 425 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, extack);
389 cls_flower.command = TC_CLSFLOWER_REPLACE; 426 cls_flower.command = TC_CLSFLOWER_REPLACE;
@@ -396,35 +433,51 @@ static int fl_hw_replace_filter(struct tcf_proto *tp,
396 err = tc_setup_flow_action(&cls_flower.rule->action, &f->exts); 433 err = tc_setup_flow_action(&cls_flower.rule->action, &f->exts);
397 if (err) { 434 if (err) {
398 kfree(cls_flower.rule); 435 kfree(cls_flower.rule);
399 if (skip_sw) { 436 if (skip_sw)
400 NL_SET_ERR_MSG_MOD(extack, "Failed to setup flow action"); 437 NL_SET_ERR_MSG_MOD(extack, "Failed to setup flow action");
401 return err; 438 else
402 } 439 err = 0;
403 return 0; 440 goto errout;
404 } 441 }
405 442
406 err = tc_setup_cb_call(block, TC_SETUP_CLSFLOWER, &cls_flower, skip_sw); 443 err = tc_setup_cb_call(block, TC_SETUP_CLSFLOWER, &cls_flower, skip_sw);
407 kfree(cls_flower.rule); 444 kfree(cls_flower.rule);
408 445
409 if (err < 0) { 446 if (err < 0) {
410 fl_hw_destroy_filter(tp, f, NULL); 447 fl_hw_destroy_filter(tp, f, true, NULL);
411 return err; 448 goto errout;
412 } else if (err > 0) { 449 } else if (err > 0) {
413 f->in_hw_count = err; 450 f->in_hw_count = err;
451 err = 0;
452 spin_lock(&tp->lock);
414 tcf_block_offload_inc(block, &f->flags); 453 tcf_block_offload_inc(block, &f->flags);
454 spin_unlock(&tp->lock);
415 } 455 }
416 456
417 if (skip_sw && !(f->flags & TCA_CLS_FLAGS_IN_HW)) 457 if (skip_sw && !(f->flags & TCA_CLS_FLAGS_IN_HW)) {
418 return -EINVAL; 458 err = -EINVAL;
459 goto errout;
460 }
419 461
420 return 0; 462 spin_lock(&tp->lock);
463 list_add(&f->hw_list, &head->hw_filters);
464 spin_unlock(&tp->lock);
465errout:
466 if (!rtnl_held)
467 rtnl_unlock();
468
469 return err;
421} 470}
422 471
423static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f) 472static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f,
473 bool rtnl_held)
424{ 474{
425 struct tc_cls_flower_offload cls_flower = {}; 475 struct tc_cls_flower_offload cls_flower = {};
426 struct tcf_block *block = tp->chain->block; 476 struct tcf_block *block = tp->chain->block;
427 477
478 if (!rtnl_held)
479 rtnl_lock();
480
428 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, NULL); 481 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, NULL);
429 cls_flower.command = TC_CLSFLOWER_STATS; 482 cls_flower.command = TC_CLSFLOWER_STATS;
430 cls_flower.cookie = (unsigned long) f; 483 cls_flower.cookie = (unsigned long) f;
@@ -435,27 +488,81 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f)
435 tcf_exts_stats_update(&f->exts, cls_flower.stats.bytes, 488 tcf_exts_stats_update(&f->exts, cls_flower.stats.bytes,
436 cls_flower.stats.pkts, 489 cls_flower.stats.pkts,
437 cls_flower.stats.lastused); 490 cls_flower.stats.lastused);
491
492 if (!rtnl_held)
493 rtnl_unlock();
438} 494}
439 495
440static bool __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f, 496static void __fl_put(struct cls_fl_filter *f)
441 struct netlink_ext_ack *extack)
442{ 497{
443 struct cls_fl_head *head = rtnl_dereference(tp->root); 498 if (!refcount_dec_and_test(&f->refcnt))
444 bool async = tcf_exts_get_net(&f->exts); 499 return;
445 bool last; 500
501 if (tcf_exts_get_net(&f->exts))
502 tcf_queue_work(&f->rwork, fl_destroy_filter_work);
503 else
504 __fl_destroy_filter(f);
505}
506
507static struct cls_fl_filter *__fl_get(struct cls_fl_head *head, u32 handle)
508{
509 struct cls_fl_filter *f;
446 510
511 rcu_read_lock();
512 f = idr_find(&head->handle_idr, handle);
513 if (f && !refcount_inc_not_zero(&f->refcnt))
514 f = NULL;
515 rcu_read_unlock();
516
517 return f;
518}
519
520static struct cls_fl_filter *fl_get_next_filter(struct tcf_proto *tp,
521 unsigned long *handle)
522{
523 struct cls_fl_head *head = fl_head_dereference(tp);
524 struct cls_fl_filter *f;
525
526 rcu_read_lock();
527 while ((f = idr_get_next_ul(&head->handle_idr, handle))) {
528 /* don't return filters that are being deleted */
529 if (refcount_inc_not_zero(&f->refcnt))
530 break;
531 ++(*handle);
532 }
533 rcu_read_unlock();
534
535 return f;
536}
537
538static int __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f,
539 bool *last, bool rtnl_held,
540 struct netlink_ext_ack *extack)
541{
542 struct cls_fl_head *head = fl_head_dereference(tp);
543
544 *last = false;
545
546 spin_lock(&tp->lock);
547 if (f->deleted) {
548 spin_unlock(&tp->lock);
549 return -ENOENT;
550 }
551
552 f->deleted = true;
553 rhashtable_remove_fast(&f->mask->ht, &f->ht_node,
554 f->mask->filter_ht_params);
447 idr_remove(&head->handle_idr, f->handle); 555 idr_remove(&head->handle_idr, f->handle);
448 list_del_rcu(&f->list); 556 list_del_rcu(&f->list);
449 last = fl_mask_put(head, f->mask, async); 557 spin_unlock(&tp->lock);
558
559 *last = fl_mask_put(head, f->mask);
450 if (!tc_skip_hw(f->flags)) 560 if (!tc_skip_hw(f->flags))
451 fl_hw_destroy_filter(tp, f, extack); 561 fl_hw_destroy_filter(tp, f, rtnl_held, extack);
452 tcf_unbind_filter(tp, &f->res); 562 tcf_unbind_filter(tp, &f->res);
453 if (async) 563 __fl_put(f);
454 tcf_queue_work(&f->rwork, fl_destroy_filter_work);
455 else
456 __fl_destroy_filter(f);
457 564
458 return last; 565 return 0;
459} 566}
460 567
461static void fl_destroy_sleepable(struct work_struct *work) 568static void fl_destroy_sleepable(struct work_struct *work)
@@ -472,13 +579,15 @@ static void fl_destroy_sleepable(struct work_struct *work)
472static void fl_destroy(struct tcf_proto *tp, bool rtnl_held, 579static void fl_destroy(struct tcf_proto *tp, bool rtnl_held,
473 struct netlink_ext_ack *extack) 580 struct netlink_ext_ack *extack)
474{ 581{
475 struct cls_fl_head *head = rtnl_dereference(tp->root); 582 struct cls_fl_head *head = fl_head_dereference(tp);
476 struct fl_flow_mask *mask, *next_mask; 583 struct fl_flow_mask *mask, *next_mask;
477 struct cls_fl_filter *f, *next; 584 struct cls_fl_filter *f, *next;
585 bool last;
478 586
479 list_for_each_entry_safe(mask, next_mask, &head->masks, list) { 587 list_for_each_entry_safe(mask, next_mask, &head->masks, list) {
480 list_for_each_entry_safe(f, next, &mask->filters, list) { 588 list_for_each_entry_safe(f, next, &mask->filters, list) {
481 if (__fl_delete(tp, f, extack)) 589 __fl_delete(tp, f, &last, rtnl_held, extack);
590 if (last)
482 break; 591 break;
483 } 592 }
484 } 593 }
@@ -488,11 +597,18 @@ static void fl_destroy(struct tcf_proto *tp, bool rtnl_held,
488 tcf_queue_work(&head->rwork, fl_destroy_sleepable); 597 tcf_queue_work(&head->rwork, fl_destroy_sleepable);
489} 598}
490 599
600static void fl_put(struct tcf_proto *tp, void *arg)
601{
602 struct cls_fl_filter *f = arg;
603
604 __fl_put(f);
605}
606
491static void *fl_get(struct tcf_proto *tp, u32 handle) 607static void *fl_get(struct tcf_proto *tp, u32 handle)
492{ 608{
493 struct cls_fl_head *head = rtnl_dereference(tp->root); 609 struct cls_fl_head *head = fl_head_dereference(tp);
494 610
495 return idr_find(&head->handle_idr, handle); 611 return __fl_get(head, handle);
496} 612}
497 613
498static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = { 614static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
@@ -768,8 +884,9 @@ static int fl_set_geneve_opt(const struct nlattr *nla, struct fl_flow_key *key,
768 return -EINVAL; 884 return -EINVAL;
769 } 885 }
770 886
771 err = nla_parse_nested(tb, TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX, 887 err = nla_parse_nested_deprecated(tb,
772 nla, geneve_opt_policy, extack); 888 TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX,
889 nla, geneve_opt_policy, extack);
773 if (err < 0) 890 if (err < 0)
774 return err; 891 return err;
775 892
@@ -831,18 +948,18 @@ static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key,
831 const struct nlattr *nla_enc_key, *nla_opt_key, *nla_opt_msk = NULL; 948 const struct nlattr *nla_enc_key, *nla_opt_key, *nla_opt_msk = NULL;
832 int err, option_len, key_depth, msk_depth = 0; 949 int err, option_len, key_depth, msk_depth = 0;
833 950
834 err = nla_validate_nested(tb[TCA_FLOWER_KEY_ENC_OPTS], 951 err = nla_validate_nested_deprecated(tb[TCA_FLOWER_KEY_ENC_OPTS],
835 TCA_FLOWER_KEY_ENC_OPTS_MAX, 952 TCA_FLOWER_KEY_ENC_OPTS_MAX,
836 enc_opts_policy, extack); 953 enc_opts_policy, extack);
837 if (err) 954 if (err)
838 return err; 955 return err;
839 956
840 nla_enc_key = nla_data(tb[TCA_FLOWER_KEY_ENC_OPTS]); 957 nla_enc_key = nla_data(tb[TCA_FLOWER_KEY_ENC_OPTS]);
841 958
842 if (tb[TCA_FLOWER_KEY_ENC_OPTS_MASK]) { 959 if (tb[TCA_FLOWER_KEY_ENC_OPTS_MASK]) {
843 err = nla_validate_nested(tb[TCA_FLOWER_KEY_ENC_OPTS_MASK], 960 err = nla_validate_nested_deprecated(tb[TCA_FLOWER_KEY_ENC_OPTS_MASK],
844 TCA_FLOWER_KEY_ENC_OPTS_MAX, 961 TCA_FLOWER_KEY_ENC_OPTS_MAX,
845 enc_opts_policy, extack); 962 enc_opts_policy, extack);
846 if (err) 963 if (err)
847 return err; 964 return err;
848 965
@@ -1227,12 +1344,18 @@ static struct fl_flow_mask *fl_create_new_mask(struct cls_fl_head *head,
1227 1344
1228 INIT_LIST_HEAD_RCU(&newmask->filters); 1345 INIT_LIST_HEAD_RCU(&newmask->filters);
1229 1346
1230 err = rhashtable_insert_fast(&head->ht, &newmask->ht_node, 1347 refcount_set(&newmask->refcnt, 1);
1231 mask_ht_params); 1348 err = rhashtable_replace_fast(&head->ht, &mask->ht_node,
1349 &newmask->ht_node, mask_ht_params);
1232 if (err) 1350 if (err)
1233 goto errout_destroy; 1351 goto errout_destroy;
1234 1352
1353 /* Wait until any potential concurrent users of mask are finished */
1354 synchronize_rcu();
1355
1356 spin_lock(&head->masks_lock);
1235 list_add_tail_rcu(&newmask->list, &head->masks); 1357 list_add_tail_rcu(&newmask->list, &head->masks);
1358 spin_unlock(&head->masks_lock);
1236 1359
1237 return newmask; 1360 return newmask;
1238 1361
@@ -1250,41 +1373,77 @@ static int fl_check_assign_mask(struct cls_fl_head *head,
1250 struct fl_flow_mask *mask) 1373 struct fl_flow_mask *mask)
1251{ 1374{
1252 struct fl_flow_mask *newmask; 1375 struct fl_flow_mask *newmask;
1376 int ret = 0;
1377
1378 rcu_read_lock();
1253 1379
1254 fnew->mask = rhashtable_lookup_fast(&head->ht, mask, mask_ht_params); 1380 /* Insert mask as temporary node to prevent concurrent creation of mask
1381 * with same key. Any concurrent lookups with same key will return
1382 * -EAGAIN because mask's refcnt is zero. It is safe to insert
1383 * stack-allocated 'mask' to masks hash table because we call
1384 * synchronize_rcu() before returning from this function (either in case
1385 * of error or after replacing it with heap-allocated mask in
1386 * fl_create_new_mask()).
1387 */
1388 fnew->mask = rhashtable_lookup_get_insert_fast(&head->ht,
1389 &mask->ht_node,
1390 mask_ht_params);
1255 if (!fnew->mask) { 1391 if (!fnew->mask) {
1256 if (fold) 1392 rcu_read_unlock();
1257 return -EINVAL; 1393
1394 if (fold) {
1395 ret = -EINVAL;
1396 goto errout_cleanup;
1397 }
1258 1398
1259 newmask = fl_create_new_mask(head, mask); 1399 newmask = fl_create_new_mask(head, mask);
1260 if (IS_ERR(newmask)) 1400 if (IS_ERR(newmask)) {
1261 return PTR_ERR(newmask); 1401 ret = PTR_ERR(newmask);
1402 goto errout_cleanup;
1403 }
1262 1404
1263 fnew->mask = newmask; 1405 fnew->mask = newmask;
1406 return 0;
1407 } else if (IS_ERR(fnew->mask)) {
1408 ret = PTR_ERR(fnew->mask);
1264 } else if (fold && fold->mask != fnew->mask) { 1409 } else if (fold && fold->mask != fnew->mask) {
1265 return -EINVAL; 1410 ret = -EINVAL;
1411 } else if (!refcount_inc_not_zero(&fnew->mask->refcnt)) {
1412 /* Mask was deleted concurrently, try again */
1413 ret = -EAGAIN;
1266 } 1414 }
1415 rcu_read_unlock();
1416 return ret;
1267 1417
1268 return 0; 1418errout_cleanup:
1419 rhashtable_remove_fast(&head->ht, &mask->ht_node,
1420 mask_ht_params);
1421 /* Wait until any potential concurrent users of mask are finished */
1422 synchronize_rcu();
1423 return ret;
1269} 1424}
1270 1425
1271static int fl_set_parms(struct net *net, struct tcf_proto *tp, 1426static int fl_set_parms(struct net *net, struct tcf_proto *tp,
1272 struct cls_fl_filter *f, struct fl_flow_mask *mask, 1427 struct cls_fl_filter *f, struct fl_flow_mask *mask,
1273 unsigned long base, struct nlattr **tb, 1428 unsigned long base, struct nlattr **tb,
1274 struct nlattr *est, bool ovr, 1429 struct nlattr *est, bool ovr,
1275 struct fl_flow_tmplt *tmplt, 1430 struct fl_flow_tmplt *tmplt, bool rtnl_held,
1276 struct netlink_ext_ack *extack) 1431 struct netlink_ext_ack *extack)
1277{ 1432{
1278 int err; 1433 int err;
1279 1434
1280 err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, true, 1435 err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, rtnl_held,
1281 extack); 1436 extack);
1282 if (err < 0) 1437 if (err < 0)
1283 return err; 1438 return err;
1284 1439
1285 if (tb[TCA_FLOWER_CLASSID]) { 1440 if (tb[TCA_FLOWER_CLASSID]) {
1286 f->res.classid = nla_get_u32(tb[TCA_FLOWER_CLASSID]); 1441 f->res.classid = nla_get_u32(tb[TCA_FLOWER_CLASSID]);
1442 if (!rtnl_held)
1443 rtnl_lock();
1287 tcf_bind_filter(tp, &f->res, base); 1444 tcf_bind_filter(tp, &f->res, base);
1445 if (!rtnl_held)
1446 rtnl_unlock();
1288 } 1447 }
1289 1448
1290 err = fl_set_key(net, tb, &f->key, &mask->key, extack); 1449 err = fl_set_key(net, tb, &f->key, &mask->key, extack);
@@ -1302,25 +1461,52 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp,
1302 return 0; 1461 return 0;
1303} 1462}
1304 1463
1464static int fl_ht_insert_unique(struct cls_fl_filter *fnew,
1465 struct cls_fl_filter *fold,
1466 bool *in_ht)
1467{
1468 struct fl_flow_mask *mask = fnew->mask;
1469 int err;
1470
1471 err = rhashtable_lookup_insert_fast(&mask->ht,
1472 &fnew->ht_node,
1473 mask->filter_ht_params);
1474 if (err) {
1475 *in_ht = false;
1476 /* It is okay if filter with same key exists when
1477 * overwriting.
1478 */
1479 return fold && err == -EEXIST ? 0 : err;
1480 }
1481
1482 *in_ht = true;
1483 return 0;
1484}
1485
1305static int fl_change(struct net *net, struct sk_buff *in_skb, 1486static int fl_change(struct net *net, struct sk_buff *in_skb,
1306 struct tcf_proto *tp, unsigned long base, 1487 struct tcf_proto *tp, unsigned long base,
1307 u32 handle, struct nlattr **tca, 1488 u32 handle, struct nlattr **tca,
1308 void **arg, bool ovr, bool rtnl_held, 1489 void **arg, bool ovr, bool rtnl_held,
1309 struct netlink_ext_ack *extack) 1490 struct netlink_ext_ack *extack)
1310{ 1491{
1311 struct cls_fl_head *head = rtnl_dereference(tp->root); 1492 struct cls_fl_head *head = fl_head_dereference(tp);
1312 struct cls_fl_filter *fold = *arg; 1493 struct cls_fl_filter *fold = *arg;
1313 struct cls_fl_filter *fnew; 1494 struct cls_fl_filter *fnew;
1314 struct fl_flow_mask *mask; 1495 struct fl_flow_mask *mask;
1315 struct nlattr **tb; 1496 struct nlattr **tb;
1497 bool in_ht;
1316 int err; 1498 int err;
1317 1499
1318 if (!tca[TCA_OPTIONS]) 1500 if (!tca[TCA_OPTIONS]) {
1319 return -EINVAL; 1501 err = -EINVAL;
1502 goto errout_fold;
1503 }
1320 1504
1321 mask = kzalloc(sizeof(struct fl_flow_mask), GFP_KERNEL); 1505 mask = kzalloc(sizeof(struct fl_flow_mask), GFP_KERNEL);
1322 if (!mask) 1506 if (!mask) {
1323 return -ENOBUFS; 1507 err = -ENOBUFS;
1508 goto errout_fold;
1509 }
1324 1510
1325 tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL); 1511 tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
1326 if (!tb) { 1512 if (!tb) {
@@ -1328,8 +1514,8 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
1328 goto errout_mask_alloc; 1514 goto errout_mask_alloc;
1329 } 1515 }
1330 1516
1331 err = nla_parse_nested(tb, TCA_FLOWER_MAX, tca[TCA_OPTIONS], 1517 err = nla_parse_nested_deprecated(tb, TCA_FLOWER_MAX,
1332 fl_policy, NULL); 1518 tca[TCA_OPTIONS], fl_policy, NULL);
1333 if (err < 0) 1519 if (err < 0)
1334 goto errout_tb; 1520 goto errout_tb;
1335 1521
@@ -1343,6 +1529,8 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
1343 err = -ENOBUFS; 1529 err = -ENOBUFS;
1344 goto errout_tb; 1530 goto errout_tb;
1345 } 1531 }
1532 INIT_LIST_HEAD(&fnew->hw_list);
1533 refcount_set(&fnew->refcnt, 1);
1346 1534
1347 err = tcf_exts_init(&fnew->exts, net, TCA_FLOWER_ACT, 0); 1535 err = tcf_exts_init(&fnew->exts, net, TCA_FLOWER_ACT, 0);
1348 if (err < 0) 1536 if (err < 0)
@@ -1358,7 +1546,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
1358 } 1546 }
1359 1547
1360 err = fl_set_parms(net, tp, fnew, mask, base, tb, tca[TCA_RATE], ovr, 1548 err = fl_set_parms(net, tp, fnew, mask, base, tb, tca[TCA_RATE], ovr,
1361 tp->chain->tmplt_priv, extack); 1549 tp->chain->tmplt_priv, rtnl_held, extack);
1362 if (err) 1550 if (err)
1363 goto errout; 1551 goto errout;
1364 1552
@@ -1366,169 +1554,247 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
1366 if (err) 1554 if (err)
1367 goto errout; 1555 goto errout;
1368 1556
1369 if (!handle) { 1557 err = fl_ht_insert_unique(fnew, fold, &in_ht);
1370 handle = 1;
1371 err = idr_alloc_u32(&head->handle_idr, fnew, &handle,
1372 INT_MAX, GFP_KERNEL);
1373 } else if (!fold) {
1374 /* user specifies a handle and it doesn't exist */
1375 err = idr_alloc_u32(&head->handle_idr, fnew, &handle,
1376 handle, GFP_KERNEL);
1377 }
1378 if (err) 1558 if (err)
1379 goto errout_mask; 1559 goto errout_mask;
1380 fnew->handle = handle;
1381
1382 if (!fold && __fl_lookup(fnew->mask, &fnew->mkey)) {
1383 err = -EEXIST;
1384 goto errout_idr;
1385 }
1386
1387 err = rhashtable_insert_fast(&fnew->mask->ht, &fnew->ht_node,
1388 fnew->mask->filter_ht_params);
1389 if (err)
1390 goto errout_idr;
1391 1560
1392 if (!tc_skip_hw(fnew->flags)) { 1561 if (!tc_skip_hw(fnew->flags)) {
1393 err = fl_hw_replace_filter(tp, fnew, extack); 1562 err = fl_hw_replace_filter(tp, fnew, rtnl_held, extack);
1394 if (err) 1563 if (err)
1395 goto errout_mask_ht; 1564 goto errout_ht;
1396 } 1565 }
1397 1566
1398 if (!tc_in_hw(fnew->flags)) 1567 if (!tc_in_hw(fnew->flags))
1399 fnew->flags |= TCA_CLS_FLAGS_NOT_IN_HW; 1568 fnew->flags |= TCA_CLS_FLAGS_NOT_IN_HW;
1400 1569
1570 spin_lock(&tp->lock);
1571
1572 /* tp was deleted concurrently. -EAGAIN will cause caller to lookup
1573 * proto again or create new one, if necessary.
1574 */
1575 if (tp->deleting) {
1576 err = -EAGAIN;
1577 goto errout_hw;
1578 }
1579
1401 if (fold) { 1580 if (fold) {
1581 /* Fold filter was deleted concurrently. Retry lookup. */
1582 if (fold->deleted) {
1583 err = -EAGAIN;
1584 goto errout_hw;
1585 }
1586
1587 fnew->handle = handle;
1588
1589 if (!in_ht) {
1590 struct rhashtable_params params =
1591 fnew->mask->filter_ht_params;
1592
1593 err = rhashtable_insert_fast(&fnew->mask->ht,
1594 &fnew->ht_node,
1595 params);
1596 if (err)
1597 goto errout_hw;
1598 in_ht = true;
1599 }
1600
1601 refcount_inc(&fnew->refcnt);
1402 rhashtable_remove_fast(&fold->mask->ht, 1602 rhashtable_remove_fast(&fold->mask->ht,
1403 &fold->ht_node, 1603 &fold->ht_node,
1404 fold->mask->filter_ht_params); 1604 fold->mask->filter_ht_params);
1405 if (!tc_skip_hw(fold->flags))
1406 fl_hw_destroy_filter(tp, fold, NULL);
1407 }
1408
1409 *arg = fnew;
1410
1411 if (fold) {
1412 idr_replace(&head->handle_idr, fnew, fnew->handle); 1605 idr_replace(&head->handle_idr, fnew, fnew->handle);
1413 list_replace_rcu(&fold->list, &fnew->list); 1606 list_replace_rcu(&fold->list, &fnew->list);
1607 fold->deleted = true;
1608
1609 spin_unlock(&tp->lock);
1610
1611 fl_mask_put(head, fold->mask);
1612 if (!tc_skip_hw(fold->flags))
1613 fl_hw_destroy_filter(tp, fold, rtnl_held, NULL);
1414 tcf_unbind_filter(tp, &fold->res); 1614 tcf_unbind_filter(tp, &fold->res);
1415 tcf_exts_get_net(&fold->exts); 1615 /* Caller holds reference to fold, so refcnt is always > 0
1416 tcf_queue_work(&fold->rwork, fl_destroy_filter_work); 1616 * after this.
1617 */
1618 refcount_dec(&fold->refcnt);
1619 __fl_put(fold);
1417 } else { 1620 } else {
1621 if (handle) {
1622 /* user specifies a handle and it doesn't exist */
1623 err = idr_alloc_u32(&head->handle_idr, fnew, &handle,
1624 handle, GFP_ATOMIC);
1625
1626 /* Filter with specified handle was concurrently
1627 * inserted after initial check in cls_api. This is not
1628 * necessarily an error if NLM_F_EXCL is not set in
1629 * message flags. Returning EAGAIN will cause cls_api to
1630 * try to update concurrently inserted rule.
1631 */
1632 if (err == -ENOSPC)
1633 err = -EAGAIN;
1634 } else {
1635 handle = 1;
1636 err = idr_alloc_u32(&head->handle_idr, fnew, &handle,
1637 INT_MAX, GFP_ATOMIC);
1638 }
1639 if (err)
1640 goto errout_hw;
1641
1642 refcount_inc(&fnew->refcnt);
1643 fnew->handle = handle;
1418 list_add_tail_rcu(&fnew->list, &fnew->mask->filters); 1644 list_add_tail_rcu(&fnew->list, &fnew->mask->filters);
1645 spin_unlock(&tp->lock);
1419 } 1646 }
1420 1647
1648 *arg = fnew;
1649
1421 kfree(tb); 1650 kfree(tb);
1422 kfree(mask); 1651 kfree(mask);
1423 return 0; 1652 return 0;
1424 1653
1425errout_mask_ht: 1654errout_ht:
1426 rhashtable_remove_fast(&fnew->mask->ht, &fnew->ht_node, 1655 spin_lock(&tp->lock);
1427 fnew->mask->filter_ht_params); 1656errout_hw:
1428 1657 fnew->deleted = true;
1429errout_idr: 1658 spin_unlock(&tp->lock);
1430 if (!fold) 1659 if (!tc_skip_hw(fnew->flags))
1431 idr_remove(&head->handle_idr, fnew->handle); 1660 fl_hw_destroy_filter(tp, fnew, rtnl_held, NULL);
1432 1661 if (in_ht)
1662 rhashtable_remove_fast(&fnew->mask->ht, &fnew->ht_node,
1663 fnew->mask->filter_ht_params);
1433errout_mask: 1664errout_mask:
1434 fl_mask_put(head, fnew->mask, false); 1665 fl_mask_put(head, fnew->mask);
1435
1436errout: 1666errout:
1437 tcf_exts_destroy(&fnew->exts); 1667 __fl_put(fnew);
1438 kfree(fnew);
1439errout_tb: 1668errout_tb:
1440 kfree(tb); 1669 kfree(tb);
1441errout_mask_alloc: 1670errout_mask_alloc:
1442 kfree(mask); 1671 kfree(mask);
1672errout_fold:
1673 if (fold)
1674 __fl_put(fold);
1443 return err; 1675 return err;
1444} 1676}
1445 1677
1446static int fl_delete(struct tcf_proto *tp, void *arg, bool *last, 1678static int fl_delete(struct tcf_proto *tp, void *arg, bool *last,
1447 bool rtnl_held, struct netlink_ext_ack *extack) 1679 bool rtnl_held, struct netlink_ext_ack *extack)
1448{ 1680{
1449 struct cls_fl_head *head = rtnl_dereference(tp->root); 1681 struct cls_fl_head *head = fl_head_dereference(tp);
1450 struct cls_fl_filter *f = arg; 1682 struct cls_fl_filter *f = arg;
1683 bool last_on_mask;
1684 int err = 0;
1451 1685
1452 rhashtable_remove_fast(&f->mask->ht, &f->ht_node, 1686 err = __fl_delete(tp, f, &last_on_mask, rtnl_held, extack);
1453 f->mask->filter_ht_params);
1454 __fl_delete(tp, f, extack);
1455 *last = list_empty(&head->masks); 1687 *last = list_empty(&head->masks);
1456 return 0; 1688 __fl_put(f);
1689
1690 return err;
1457} 1691}
1458 1692
1459static void fl_walk(struct tcf_proto *tp, struct tcf_walker *arg, 1693static void fl_walk(struct tcf_proto *tp, struct tcf_walker *arg,
1460 bool rtnl_held) 1694 bool rtnl_held)
1461{ 1695{
1462 struct cls_fl_head *head = rtnl_dereference(tp->root);
1463 struct cls_fl_filter *f; 1696 struct cls_fl_filter *f;
1464 1697
1465 arg->count = arg->skip; 1698 arg->count = arg->skip;
1466 1699
1467 while ((f = idr_get_next_ul(&head->handle_idr, 1700 while ((f = fl_get_next_filter(tp, &arg->cookie)) != NULL) {
1468 &arg->cookie)) != NULL) {
1469 if (arg->fn(tp, f, arg) < 0) { 1701 if (arg->fn(tp, f, arg) < 0) {
1702 __fl_put(f);
1470 arg->stop = 1; 1703 arg->stop = 1;
1471 break; 1704 break;
1472 } 1705 }
1473 arg->cookie = f->handle + 1; 1706 __fl_put(f);
1707 arg->cookie++;
1474 arg->count++; 1708 arg->count++;
1475 } 1709 }
1476} 1710}
1477 1711
1712static struct cls_fl_filter *
1713fl_get_next_hw_filter(struct tcf_proto *tp, struct cls_fl_filter *f, bool add)
1714{
1715 struct cls_fl_head *head = fl_head_dereference(tp);
1716
1717 spin_lock(&tp->lock);
1718 if (list_empty(&head->hw_filters)) {
1719 spin_unlock(&tp->lock);
1720 return NULL;
1721 }
1722
1723 if (!f)
1724 f = list_entry(&head->hw_filters, struct cls_fl_filter,
1725 hw_list);
1726 list_for_each_entry_continue(f, &head->hw_filters, hw_list) {
1727 if (!(add && f->deleted) && refcount_inc_not_zero(&f->refcnt)) {
1728 spin_unlock(&tp->lock);
1729 return f;
1730 }
1731 }
1732
1733 spin_unlock(&tp->lock);
1734 return NULL;
1735}
1736
1478static int fl_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb, 1737static int fl_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
1479 void *cb_priv, struct netlink_ext_ack *extack) 1738 void *cb_priv, struct netlink_ext_ack *extack)
1480{ 1739{
1481 struct cls_fl_head *head = rtnl_dereference(tp->root);
1482 struct tc_cls_flower_offload cls_flower = {}; 1740 struct tc_cls_flower_offload cls_flower = {};
1483 struct tcf_block *block = tp->chain->block; 1741 struct tcf_block *block = tp->chain->block;
1484 struct fl_flow_mask *mask; 1742 struct cls_fl_filter *f = NULL;
1485 struct cls_fl_filter *f;
1486 int err; 1743 int err;
1487 1744
1488 list_for_each_entry(mask, &head->masks, list) { 1745 /* hw_filters list can only be changed by hw offload functions after
1489 list_for_each_entry(f, &mask->filters, list) { 1746 * obtaining rtnl lock. Make sure it is not changed while reoffload is
1490 if (tc_skip_hw(f->flags)) 1747 * iterating it.
1491 continue; 1748 */
1492 1749 ASSERT_RTNL();
1493 cls_flower.rule = 1750
1494 flow_rule_alloc(tcf_exts_num_actions(&f->exts)); 1751 while ((f = fl_get_next_hw_filter(tp, f, add))) {
1495 if (!cls_flower.rule) 1752 cls_flower.rule =
1496 return -ENOMEM; 1753 flow_rule_alloc(tcf_exts_num_actions(&f->exts));
1497 1754 if (!cls_flower.rule) {
1498 tc_cls_common_offload_init(&cls_flower.common, tp, 1755 __fl_put(f);
1499 f->flags, extack); 1756 return -ENOMEM;
1500 cls_flower.command = add ? 1757 }
1501 TC_CLSFLOWER_REPLACE : TC_CLSFLOWER_DESTROY; 1758
1502 cls_flower.cookie = (unsigned long)f; 1759 tc_cls_common_offload_init(&cls_flower.common, tp, f->flags,
1503 cls_flower.rule->match.dissector = &mask->dissector; 1760 extack);
1504 cls_flower.rule->match.mask = &mask->key; 1761 cls_flower.command = add ?
1505 cls_flower.rule->match.key = &f->mkey; 1762 TC_CLSFLOWER_REPLACE : TC_CLSFLOWER_DESTROY;
1506 1763 cls_flower.cookie = (unsigned long)f;
1507 err = tc_setup_flow_action(&cls_flower.rule->action, 1764 cls_flower.rule->match.dissector = &f->mask->dissector;
1508 &f->exts); 1765 cls_flower.rule->match.mask = &f->mask->key;
1509 if (err) { 1766 cls_flower.rule->match.key = &f->mkey;
1510 kfree(cls_flower.rule); 1767
1511 if (tc_skip_sw(f->flags)) { 1768 err = tc_setup_flow_action(&cls_flower.rule->action, &f->exts);
1512 NL_SET_ERR_MSG_MOD(extack, "Failed to setup flow action"); 1769 if (err) {
1513 return err; 1770 kfree(cls_flower.rule);
1514 } 1771 if (tc_skip_sw(f->flags)) {
1515 continue; 1772 NL_SET_ERR_MSG_MOD(extack, "Failed to setup flow action");
1773 __fl_put(f);
1774 return err;
1516 } 1775 }
1776 goto next_flow;
1777 }
1517 1778
1518 cls_flower.classid = f->res.classid; 1779 cls_flower.classid = f->res.classid;
1519 1780
1520 err = cb(TC_SETUP_CLSFLOWER, &cls_flower, cb_priv); 1781 err = cb(TC_SETUP_CLSFLOWER, &cls_flower, cb_priv);
1521 kfree(cls_flower.rule); 1782 kfree(cls_flower.rule);
1522 1783
1523 if (err) { 1784 if (err) {
1524 if (add && tc_skip_sw(f->flags)) 1785 if (add && tc_skip_sw(f->flags)) {
1525 return err; 1786 __fl_put(f);
1526 continue; 1787 return err;
1527 } 1788 }
1528 1789 goto next_flow;
1529 tc_cls_offload_cnt_update(block, &f->in_hw_count,
1530 &f->flags, add);
1531 } 1790 }
1791
1792 spin_lock(&tp->lock);
1793 tc_cls_offload_cnt_update(block, &f->in_hw_count, &f->flags,
1794 add);
1795 spin_unlock(&tp->lock);
1796next_flow:
1797 __fl_put(f);
1532 } 1798 }
1533 1799
1534 return 0; 1800 return 0;
@@ -1587,8 +1853,8 @@ static void *fl_tmplt_create(struct net *net, struct tcf_chain *chain,
1587 tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL); 1853 tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
1588 if (!tb) 1854 if (!tb)
1589 return ERR_PTR(-ENOBUFS); 1855 return ERR_PTR(-ENOBUFS);
1590 err = nla_parse_nested(tb, TCA_FLOWER_MAX, tca[TCA_OPTIONS], 1856 err = nla_parse_nested_deprecated(tb, TCA_FLOWER_MAX,
1591 fl_policy, NULL); 1857 tca[TCA_OPTIONS], fl_policy, NULL);
1592 if (err) 1858 if (err)
1593 goto errout_tb; 1859 goto errout_tb;
1594 1860
@@ -1786,7 +2052,7 @@ static int fl_dump_key_geneve_opt(struct sk_buff *skb,
1786 struct nlattr *nest; 2052 struct nlattr *nest;
1787 int opt_off = 0; 2053 int opt_off = 0;
1788 2054
1789 nest = nla_nest_start(skb, TCA_FLOWER_KEY_ENC_OPTS_GENEVE); 2055 nest = nla_nest_start_noflag(skb, TCA_FLOWER_KEY_ENC_OPTS_GENEVE);
1790 if (!nest) 2056 if (!nest)
1791 goto nla_put_failure; 2057 goto nla_put_failure;
1792 2058
@@ -1822,7 +2088,7 @@ static int fl_dump_key_options(struct sk_buff *skb, int enc_opt_type,
1822 if (!enc_opts->len) 2088 if (!enc_opts->len)
1823 return 0; 2089 return 0;
1824 2090
1825 nest = nla_nest_start(skb, enc_opt_type); 2091 nest = nla_nest_start_noflag(skb, enc_opt_type);
1826 if (!nest) 2092 if (!nest)
1827 goto nla_put_failure; 2093 goto nla_put_failure;
1828 2094
@@ -2061,31 +2327,37 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
2061 struct cls_fl_filter *f = fh; 2327 struct cls_fl_filter *f = fh;
2062 struct nlattr *nest; 2328 struct nlattr *nest;
2063 struct fl_flow_key *key, *mask; 2329 struct fl_flow_key *key, *mask;
2330 bool skip_hw;
2064 2331
2065 if (!f) 2332 if (!f)
2066 return skb->len; 2333 return skb->len;
2067 2334
2068 t->tcm_handle = f->handle; 2335 t->tcm_handle = f->handle;
2069 2336
2070 nest = nla_nest_start(skb, TCA_OPTIONS); 2337 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
2071 if (!nest) 2338 if (!nest)
2072 goto nla_put_failure; 2339 goto nla_put_failure;
2073 2340
2341 spin_lock(&tp->lock);
2342
2074 if (f->res.classid && 2343 if (f->res.classid &&
2075 nla_put_u32(skb, TCA_FLOWER_CLASSID, f->res.classid)) 2344 nla_put_u32(skb, TCA_FLOWER_CLASSID, f->res.classid))
2076 goto nla_put_failure; 2345 goto nla_put_failure_locked;
2077 2346
2078 key = &f->key; 2347 key = &f->key;
2079 mask = &f->mask->key; 2348 mask = &f->mask->key;
2349 skip_hw = tc_skip_hw(f->flags);
2080 2350
2081 if (fl_dump_key(skb, net, key, mask)) 2351 if (fl_dump_key(skb, net, key, mask))
2082 goto nla_put_failure; 2352 goto nla_put_failure_locked;
2083
2084 if (!tc_skip_hw(f->flags))
2085 fl_hw_update_stats(tp, f);
2086 2353
2087 if (f->flags && nla_put_u32(skb, TCA_FLOWER_FLAGS, f->flags)) 2354 if (f->flags && nla_put_u32(skb, TCA_FLOWER_FLAGS, f->flags))
2088 goto nla_put_failure; 2355 goto nla_put_failure_locked;
2356
2357 spin_unlock(&tp->lock);
2358
2359 if (!skip_hw)
2360 fl_hw_update_stats(tp, f, rtnl_held);
2089 2361
2090 if (nla_put_u32(skb, TCA_FLOWER_IN_HW_COUNT, f->in_hw_count)) 2362 if (nla_put_u32(skb, TCA_FLOWER_IN_HW_COUNT, f->in_hw_count))
2091 goto nla_put_failure; 2363 goto nla_put_failure;
@@ -2100,6 +2372,8 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
2100 2372
2101 return skb->len; 2373 return skb->len;
2102 2374
2375nla_put_failure_locked:
2376 spin_unlock(&tp->lock);
2103nla_put_failure: 2377nla_put_failure:
2104 nla_nest_cancel(skb, nest); 2378 nla_nest_cancel(skb, nest);
2105 return -1; 2379 return -1;
@@ -2111,7 +2385,7 @@ static int fl_tmplt_dump(struct sk_buff *skb, struct net *net, void *tmplt_priv)
2111 struct fl_flow_key *key, *mask; 2385 struct fl_flow_key *key, *mask;
2112 struct nlattr *nest; 2386 struct nlattr *nest;
2113 2387
2114 nest = nla_nest_start(skb, TCA_OPTIONS); 2388 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
2115 if (!nest) 2389 if (!nest)
2116 goto nla_put_failure; 2390 goto nla_put_failure;
2117 2391
@@ -2144,6 +2418,7 @@ static struct tcf_proto_ops cls_fl_ops __read_mostly = {
2144 .init = fl_init, 2418 .init = fl_init,
2145 .destroy = fl_destroy, 2419 .destroy = fl_destroy,
2146 .get = fl_get, 2420 .get = fl_get,
2421 .put = fl_put,
2147 .change = fl_change, 2422 .change = fl_change,
2148 .delete = fl_delete, 2423 .delete = fl_delete,
2149 .walk = fl_walk, 2424 .walk = fl_walk,
@@ -2154,6 +2429,7 @@ static struct tcf_proto_ops cls_fl_ops __read_mostly = {
2154 .tmplt_destroy = fl_tmplt_destroy, 2429 .tmplt_destroy = fl_tmplt_destroy,
2155 .tmplt_dump = fl_tmplt_dump, 2430 .tmplt_dump = fl_tmplt_dump,
2156 .owner = THIS_MODULE, 2431 .owner = THIS_MODULE,
2432 .flags = TCF_PROTO_OPS_DOIT_UNLOCKED,
2157}; 2433};
2158 2434
2159static int __init cls_fl_init(void) 2435static int __init cls_fl_init(void)
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index ad036b00427d..1d0b39c3932f 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -263,7 +263,8 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
263 if (!opt) 263 if (!opt)
264 return handle ? -EINVAL : 0; /* Succeed if it is old method. */ 264 return handle ? -EINVAL : 0; /* Succeed if it is old method. */
265 265
266 err = nla_parse_nested(tb, TCA_FW_MAX, opt, fw_policy, NULL); 266 err = nla_parse_nested_deprecated(tb, TCA_FW_MAX, opt, fw_policy,
267 NULL);
267 if (err < 0) 268 if (err < 0)
268 return err; 269 return err;
269 270
@@ -402,7 +403,7 @@ static int fw_dump(struct net *net, struct tcf_proto *tp, void *fh,
402 if (!f->res.classid && !tcf_exts_has_actions(&f->exts)) 403 if (!f->res.classid && !tcf_exts_has_actions(&f->exts))
403 return skb->len; 404 return skb->len;
404 405
405 nest = nla_nest_start(skb, TCA_OPTIONS); 406 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
406 if (nest == NULL) 407 if (nest == NULL)
407 goto nla_put_failure; 408 goto nla_put_failure;
408 409
diff --git a/net/sched/cls_matchall.c b/net/sched/cls_matchall.c
index a13bc351a414..db42d97a2006 100644
--- a/net/sched/cls_matchall.c
+++ b/net/sched/cls_matchall.c
@@ -32,6 +32,9 @@ static int mall_classify(struct sk_buff *skb, const struct tcf_proto *tp,
32{ 32{
33 struct cls_mall_head *head = rcu_dereference_bh(tp->root); 33 struct cls_mall_head *head = rcu_dereference_bh(tp->root);
34 34
35 if (unlikely(!head))
36 return -1;
37
35 if (tc_skip_sw(head->flags)) 38 if (tc_skip_sw(head->flags))
36 return -1; 39 return -1;
37 40
@@ -89,12 +92,29 @@ static int mall_replace_hw_filter(struct tcf_proto *tp,
89 bool skip_sw = tc_skip_sw(head->flags); 92 bool skip_sw = tc_skip_sw(head->flags);
90 int err; 93 int err;
91 94
95 cls_mall.rule = flow_rule_alloc(tcf_exts_num_actions(&head->exts));
96 if (!cls_mall.rule)
97 return -ENOMEM;
98
92 tc_cls_common_offload_init(&cls_mall.common, tp, head->flags, extack); 99 tc_cls_common_offload_init(&cls_mall.common, tp, head->flags, extack);
93 cls_mall.command = TC_CLSMATCHALL_REPLACE; 100 cls_mall.command = TC_CLSMATCHALL_REPLACE;
94 cls_mall.exts = &head->exts;
95 cls_mall.cookie = cookie; 101 cls_mall.cookie = cookie;
96 102
103 err = tc_setup_flow_action(&cls_mall.rule->action, &head->exts);
104 if (err) {
105 kfree(cls_mall.rule);
106 mall_destroy_hw_filter(tp, head, cookie, NULL);
107 if (skip_sw)
108 NL_SET_ERR_MSG_MOD(extack, "Failed to setup flow action");
109 else
110 err = 0;
111
112 return err;
113 }
114
97 err = tc_setup_cb_call(block, TC_SETUP_CLSMATCHALL, &cls_mall, skip_sw); 115 err = tc_setup_cb_call(block, TC_SETUP_CLSMATCHALL, &cls_mall, skip_sw);
116 kfree(cls_mall.rule);
117
98 if (err < 0) { 118 if (err < 0) {
99 mall_destroy_hw_filter(tp, head, cookie, NULL); 119 mall_destroy_hw_filter(tp, head, cookie, NULL);
100 return err; 120 return err;
@@ -181,8 +201,8 @@ static int mall_change(struct net *net, struct sk_buff *in_skb,
181 if (head) 201 if (head)
182 return -EEXIST; 202 return -EEXIST;
183 203
184 err = nla_parse_nested(tb, TCA_MATCHALL_MAX, tca[TCA_OPTIONS], 204 err = nla_parse_nested_deprecated(tb, TCA_MATCHALL_MAX,
185 mall_policy, NULL); 205 tca[TCA_OPTIONS], mall_policy, NULL);
186 if (err < 0) 206 if (err < 0)
187 return err; 207 return err;
188 208
@@ -272,13 +292,28 @@ static int mall_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
272 if (tc_skip_hw(head->flags)) 292 if (tc_skip_hw(head->flags))
273 return 0; 293 return 0;
274 294
295 cls_mall.rule = flow_rule_alloc(tcf_exts_num_actions(&head->exts));
296 if (!cls_mall.rule)
297 return -ENOMEM;
298
275 tc_cls_common_offload_init(&cls_mall.common, tp, head->flags, extack); 299 tc_cls_common_offload_init(&cls_mall.common, tp, head->flags, extack);
276 cls_mall.command = add ? 300 cls_mall.command = add ?
277 TC_CLSMATCHALL_REPLACE : TC_CLSMATCHALL_DESTROY; 301 TC_CLSMATCHALL_REPLACE : TC_CLSMATCHALL_DESTROY;
278 cls_mall.exts = &head->exts;
279 cls_mall.cookie = (unsigned long)head; 302 cls_mall.cookie = (unsigned long)head;
280 303
304 err = tc_setup_flow_action(&cls_mall.rule->action, &head->exts);
305 if (err) {
306 kfree(cls_mall.rule);
307 if (add && tc_skip_sw(head->flags)) {
308 NL_SET_ERR_MSG_MOD(extack, "Failed to setup flow action");
309 return err;
310 }
311 return 0;
312 }
313
281 err = cb(TC_SETUP_CLSMATCHALL, &cls_mall, cb_priv); 314 err = cb(TC_SETUP_CLSMATCHALL, &cls_mall, cb_priv);
315 kfree(cls_mall.rule);
316
282 if (err) { 317 if (err) {
283 if (add && tc_skip_sw(head->flags)) 318 if (add && tc_skip_sw(head->flags))
284 return err; 319 return err;
@@ -290,6 +325,23 @@ static int mall_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
290 return 0; 325 return 0;
291} 326}
292 327
328static void mall_stats_hw_filter(struct tcf_proto *tp,
329 struct cls_mall_head *head,
330 unsigned long cookie)
331{
332 struct tc_cls_matchall_offload cls_mall = {};
333 struct tcf_block *block = tp->chain->block;
334
335 tc_cls_common_offload_init(&cls_mall.common, tp, head->flags, NULL);
336 cls_mall.command = TC_CLSMATCHALL_STATS;
337 cls_mall.cookie = cookie;
338
339 tc_setup_cb_call(block, TC_SETUP_CLSMATCHALL, &cls_mall, false);
340
341 tcf_exts_stats_update(&head->exts, cls_mall.stats.bytes,
342 cls_mall.stats.pkts, cls_mall.stats.lastused);
343}
344
293static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh, 345static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh,
294 struct sk_buff *skb, struct tcmsg *t, bool rtnl_held) 346 struct sk_buff *skb, struct tcmsg *t, bool rtnl_held)
295{ 347{
@@ -301,9 +353,12 @@ static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh,
301 if (!head) 353 if (!head)
302 return skb->len; 354 return skb->len;
303 355
356 if (!tc_skip_hw(head->flags))
357 mall_stats_hw_filter(tp, head, (unsigned long)head);
358
304 t->tcm_handle = head->handle; 359 t->tcm_handle = head->handle;
305 360
306 nest = nla_nest_start(skb, TCA_OPTIONS); 361 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
307 if (!nest) 362 if (!nest)
308 goto nla_put_failure; 363 goto nla_put_failure;
309 364
diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c
index f006af23b64a..eeff5bbfb912 100644
--- a/net/sched/cls_route.c
+++ b/net/sched/cls_route.c
@@ -484,7 +484,8 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
484 if (opt == NULL) 484 if (opt == NULL)
485 return handle ? -EINVAL : 0; 485 return handle ? -EINVAL : 0;
486 486
487 err = nla_parse_nested(tb, TCA_ROUTE4_MAX, opt, route4_policy, NULL); 487 err = nla_parse_nested_deprecated(tb, TCA_ROUTE4_MAX, opt,
488 route4_policy, NULL);
488 if (err < 0) 489 if (err < 0)
489 return err; 490 return err;
490 491
@@ -607,7 +608,7 @@ static int route4_dump(struct net *net, struct tcf_proto *tp, void *fh,
607 608
608 t->tcm_handle = f->handle; 609 t->tcm_handle = f->handle;
609 610
610 nest = nla_nest_start(skb, TCA_OPTIONS); 611 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
611 if (nest == NULL) 612 if (nest == NULL)
612 goto nla_put_failure; 613 goto nla_put_failure;
613 614
diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h
index 0719a21d9c41..a4688bb92f43 100644
--- a/net/sched/cls_rsvp.h
+++ b/net/sched/cls_rsvp.h
@@ -497,7 +497,8 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
497 if (opt == NULL) 497 if (opt == NULL)
498 return handle ? -EINVAL : 0; 498 return handle ? -EINVAL : 0;
499 499
500 err = nla_parse_nested(tb, TCA_RSVP_MAX, opt, rsvp_policy, NULL); 500 err = nla_parse_nested_deprecated(tb, TCA_RSVP_MAX, opt, rsvp_policy,
501 NULL);
501 if (err < 0) 502 if (err < 0)
502 return err; 503 return err;
503 504
@@ -706,7 +707,7 @@ static int rsvp_dump(struct net *net, struct tcf_proto *tp, void *fh,
706 707
707 t->tcm_handle = f->handle; 708 t->tcm_handle = f->handle;
708 709
709 nest = nla_nest_start(skb, TCA_OPTIONS); 710 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
710 if (nest == NULL) 711 if (nest == NULL)
711 goto nla_put_failure; 712 goto nla_put_failure;
712 713
diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c
index 24e0a62a65cc..9f4f4203c388 100644
--- a/net/sched/cls_tcindex.c
+++ b/net/sched/cls_tcindex.c
@@ -510,7 +510,8 @@ tcindex_change(struct net *net, struct sk_buff *in_skb,
510 if (!opt) 510 if (!opt)
511 return 0; 511 return 0;
512 512
513 err = nla_parse_nested(tb, TCA_TCINDEX_MAX, opt, tcindex_policy, NULL); 513 err = nla_parse_nested_deprecated(tb, TCA_TCINDEX_MAX, opt,
514 tcindex_policy, NULL);
514 if (err < 0) 515 if (err < 0)
515 return err; 516 return err;
516 517
@@ -601,7 +602,7 @@ static int tcindex_dump(struct net *net, struct tcf_proto *tp, void *fh,
601 tp, fh, skb, t, p, r); 602 tp, fh, skb, t, p, r);
602 pr_debug("p->perfect %p p->h %p\n", p->perfect, p->h); 603 pr_debug("p->perfect %p p->h %p\n", p->perfect, p->h);
603 604
604 nest = nla_nest_start(skb, TCA_OPTIONS); 605 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
605 if (nest == NULL) 606 if (nest == NULL)
606 goto nla_put_failure; 607 goto nla_put_failure;
607 608
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index 48e76a3acf8a..4b8710a266cc 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -847,7 +847,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
847 /* Similarly success statistics must be moved as pointers */ 847 /* Similarly success statistics must be moved as pointers */
848 new->pcpu_success = n->pcpu_success; 848 new->pcpu_success = n->pcpu_success;
849#endif 849#endif
850 memcpy(&new->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key)); 850 memcpy(&new->sel, s, struct_size(s, keys, s->nkeys));
851 851
852 if (tcf_exts_init(&new->exts, net, TCA_U32_ACT, TCA_U32_POLICE)) { 852 if (tcf_exts_init(&new->exts, net, TCA_U32_ACT, TCA_U32_POLICE)) {
853 kfree(new); 853 kfree(new);
@@ -884,7 +884,8 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
884 } 884 }
885 } 885 }
886 886
887 err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy, extack); 887 err = nla_parse_nested_deprecated(tb, TCA_U32_MAX, opt, u32_policy,
888 extack);
888 if (err < 0) 889 if (err < 0)
889 return err; 890 return err;
890 891
@@ -1294,7 +1295,7 @@ static int u32_dump(struct net *net, struct tcf_proto *tp, void *fh,
1294 1295
1295 t->tcm_handle = n->handle; 1296 t->tcm_handle = n->handle;
1296 1297
1297 nest = nla_nest_start(skb, TCA_OPTIONS); 1298 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
1298 if (nest == NULL) 1299 if (nest == NULL)
1299 goto nla_put_failure; 1300 goto nla_put_failure;
1300 1301
diff --git a/net/sched/em_ipt.c b/net/sched/em_ipt.c
index a5f34e930eff..60c26b8294b5 100644
--- a/net/sched/em_ipt.c
+++ b/net/sched/em_ipt.c
@@ -120,8 +120,8 @@ static int em_ipt_change(struct net *net, void *data, int data_len,
120 struct xt_match *match; 120 struct xt_match *match;
121 int mdata_len, ret; 121 int mdata_len, ret;
122 122
123 ret = nla_parse(tb, TCA_EM_IPT_MAX, data, data_len, em_ipt_policy, 123 ret = nla_parse_deprecated(tb, TCA_EM_IPT_MAX, data, data_len,
124 NULL); 124 em_ipt_policy, NULL);
125 if (ret < 0) 125 if (ret < 0)
126 return ret; 126 return ret;
127 127
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
index d6e97115500b..28dfa8f2a4ea 100644
--- a/net/sched/em_meta.c
+++ b/net/sched/em_meta.c
@@ -912,7 +912,8 @@ static int em_meta_change(struct net *net, void *data, int len,
912 struct tcf_meta_hdr *hdr; 912 struct tcf_meta_hdr *hdr;
913 struct meta_match *meta = NULL; 913 struct meta_match *meta = NULL;
914 914
915 err = nla_parse(tb, TCA_EM_META_MAX, data, len, meta_policy, NULL); 915 err = nla_parse_deprecated(tb, TCA_EM_META_MAX, data, len,
916 meta_policy, NULL);
916 if (err < 0) 917 if (err < 0)
917 goto errout; 918 goto errout;
918 919
diff --git a/net/sched/ematch.c b/net/sched/ematch.c
index 1331a4c2d8ff..7b86c2a44746 100644
--- a/net/sched/ematch.c
+++ b/net/sched/ematch.c
@@ -314,7 +314,8 @@ int tcf_em_tree_validate(struct tcf_proto *tp, struct nlattr *nla,
314 if (!nla) 314 if (!nla)
315 return 0; 315 return 0;
316 316
317 err = nla_parse_nested(tb, TCA_EMATCH_TREE_MAX, nla, em_policy, NULL); 317 err = nla_parse_nested_deprecated(tb, TCA_EMATCH_TREE_MAX, nla,
318 em_policy, NULL);
318 if (err < 0) 319 if (err < 0)
319 goto errout; 320 goto errout;
320 321
@@ -440,14 +441,14 @@ int tcf_em_tree_dump(struct sk_buff *skb, struct tcf_ematch_tree *tree, int tlv)
440 struct nlattr *top_start; 441 struct nlattr *top_start;
441 struct nlattr *list_start; 442 struct nlattr *list_start;
442 443
443 top_start = nla_nest_start(skb, tlv); 444 top_start = nla_nest_start_noflag(skb, tlv);
444 if (top_start == NULL) 445 if (top_start == NULL)
445 goto nla_put_failure; 446 goto nla_put_failure;
446 447
447 if (nla_put(skb, TCA_EMATCH_TREE_HDR, sizeof(tree->hdr), &tree->hdr)) 448 if (nla_put(skb, TCA_EMATCH_TREE_HDR, sizeof(tree->hdr), &tree->hdr))
448 goto nla_put_failure; 449 goto nla_put_failure;
449 450
450 list_start = nla_nest_start(skb, TCA_EMATCH_TREE_LIST); 451 list_start = nla_nest_start_noflag(skb, TCA_EMATCH_TREE_LIST);
451 if (list_start == NULL) 452 if (list_start == NULL)
452 goto nla_put_failure; 453 goto nla_put_failure;
453 454
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index fb8f138b9776..607e84d67c33 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -479,7 +479,8 @@ static struct qdisc_size_table *qdisc_get_stab(struct nlattr *opt,
479 u16 *tab = NULL; 479 u16 *tab = NULL;
480 int err; 480 int err;
481 481
482 err = nla_parse_nested(tb, TCA_STAB_MAX, opt, stab_policy, extack); 482 err = nla_parse_nested_deprecated(tb, TCA_STAB_MAX, opt, stab_policy,
483 extack);
483 if (err < 0) 484 if (err < 0)
484 return ERR_PTR(err); 485 return ERR_PTR(err);
485 if (!tb[TCA_STAB_BASE]) { 486 if (!tb[TCA_STAB_BASE]) {
@@ -542,7 +543,7 @@ static int qdisc_dump_stab(struct sk_buff *skb, struct qdisc_size_table *stab)
542{ 543{
543 struct nlattr *nest; 544 struct nlattr *nest;
544 545
545 nest = nla_nest_start(skb, TCA_STAB); 546 nest = nla_nest_start_noflag(skb, TCA_STAB);
546 if (nest == NULL) 547 if (nest == NULL)
547 goto nla_put_failure; 548 goto nla_put_failure;
548 if (nla_put(skb, TCA_STAB_BASE, sizeof(stab->szopts), &stab->szopts)) 549 if (nla_put(skb, TCA_STAB_BASE, sizeof(stab->szopts), &stab->szopts))
@@ -998,6 +999,19 @@ static void notify_and_destroy(struct net *net, struct sk_buff *skb,
998 qdisc_put(old); 999 qdisc_put(old);
999} 1000}
1000 1001
1002static void qdisc_clear_nolock(struct Qdisc *sch)
1003{
1004 sch->flags &= ~TCQ_F_NOLOCK;
1005 if (!(sch->flags & TCQ_F_CPUSTATS))
1006 return;
1007
1008 free_percpu(sch->cpu_bstats);
1009 free_percpu(sch->cpu_qstats);
1010 sch->cpu_bstats = NULL;
1011 sch->cpu_qstats = NULL;
1012 sch->flags &= ~TCQ_F_CPUSTATS;
1013}
1014
1001/* Graft qdisc "new" to class "classid" of qdisc "parent" or 1015/* Graft qdisc "new" to class "classid" of qdisc "parent" or
1002 * to device "dev". 1016 * to device "dev".
1003 * 1017 *
@@ -1076,7 +1090,7 @@ skip:
1076 /* Only support running class lockless if parent is lockless */ 1090 /* Only support running class lockless if parent is lockless */
1077 if (new && (new->flags & TCQ_F_NOLOCK) && 1091 if (new && (new->flags & TCQ_F_NOLOCK) &&
1078 parent && !(parent->flags & TCQ_F_NOLOCK)) 1092 parent && !(parent->flags & TCQ_F_NOLOCK))
1079 new->flags &= ~TCQ_F_NOLOCK; 1093 qdisc_clear_nolock(new);
1080 1094
1081 if (!cops || !cops->graft) 1095 if (!cops || !cops->graft)
1082 return -EOPNOTSUPP; 1096 return -EOPNOTSUPP;
@@ -1410,8 +1424,8 @@ static int tc_get_qdisc(struct sk_buff *skb, struct nlmsghdr *n,
1410 !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) 1424 !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
1411 return -EPERM; 1425 return -EPERM;
1412 1426
1413 err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy, 1427 err = nlmsg_parse_deprecated(n, sizeof(*tcm), tca, TCA_MAX,
1414 extack); 1428 rtm_tca_policy, extack);
1415 if (err < 0) 1429 if (err < 0)
1416 return err; 1430 return err;
1417 1431
@@ -1495,8 +1509,8 @@ static int tc_modify_qdisc(struct sk_buff *skb, struct nlmsghdr *n,
1495 1509
1496replay: 1510replay:
1497 /* Reinit, just in case something touches this. */ 1511 /* Reinit, just in case something touches this. */
1498 err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy, 1512 err = nlmsg_parse_deprecated(n, sizeof(*tcm), tca, TCA_MAX,
1499 extack); 1513 rtm_tca_policy, extack);
1500 if (err < 0) 1514 if (err < 0)
1501 return err; 1515 return err;
1502 1516
@@ -1730,8 +1744,8 @@ static int tc_dump_qdisc(struct sk_buff *skb, struct netlink_callback *cb)
1730 idx = 0; 1744 idx = 0;
1731 ASSERT_RTNL(); 1745 ASSERT_RTNL();
1732 1746
1733 err = nlmsg_parse(nlh, sizeof(struct tcmsg), tca, TCA_MAX, 1747 err = nlmsg_parse_deprecated(nlh, sizeof(struct tcmsg), tca, TCA_MAX,
1734 rtm_tca_policy, cb->extack); 1748 rtm_tca_policy, cb->extack);
1735 if (err < 0) 1749 if (err < 0)
1736 return err; 1750 return err;
1737 1751
@@ -1959,8 +1973,8 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n,
1959 !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) 1973 !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
1960 return -EPERM; 1974 return -EPERM;
1961 1975
1962 err = nlmsg_parse(n, sizeof(*tcm), tca, TCA_MAX, rtm_tca_policy, 1976 err = nlmsg_parse_deprecated(n, sizeof(*tcm), tca, TCA_MAX,
1963 extack); 1977 rtm_tca_policy, extack);
1964 if (err < 0) 1978 if (err < 0)
1965 return err; 1979 return err;
1966 1980
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c
index d714d3747bcb..ae506c7906cd 100644
--- a/net/sched/sch_atm.c
+++ b/net/sched/sch_atm.c
@@ -223,7 +223,8 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
223 if (opt == NULL) 223 if (opt == NULL)
224 return -EINVAL; 224 return -EINVAL;
225 225
226 error = nla_parse_nested(tb, TCA_ATM_MAX, opt, atm_policy, NULL); 226 error = nla_parse_nested_deprecated(tb, TCA_ATM_MAX, opt, atm_policy,
227 NULL);
227 if (error < 0) 228 if (error < 0)
228 return error; 229 return error;
229 230
@@ -609,7 +610,7 @@ static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
609 tcm->tcm_handle = flow->common.classid; 610 tcm->tcm_handle = flow->common.classid;
610 tcm->tcm_info = flow->q->handle; 611 tcm->tcm_info = flow->q->handle;
611 612
612 nest = nla_nest_start(skb, TCA_OPTIONS); 613 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
613 if (nest == NULL) 614 if (nest == NULL)
614 goto nla_put_failure; 615 goto nla_put_failure;
615 616
diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c
index 259d97bc2abd..53a80bc6b13a 100644
--- a/net/sched/sch_cake.c
+++ b/net/sched/sch_cake.c
@@ -2531,7 +2531,8 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt,
2531 if (!opt) 2531 if (!opt)
2532 return -EINVAL; 2532 return -EINVAL;
2533 2533
2534 err = nla_parse_nested(tb, TCA_CAKE_MAX, opt, cake_policy, extack); 2534 err = nla_parse_nested_deprecated(tb, TCA_CAKE_MAX, opt, cake_policy,
2535 extack);
2535 if (err < 0) 2536 if (err < 0)
2536 return err; 2537 return err;
2537 2538
@@ -2735,7 +2736,7 @@ static int cake_dump(struct Qdisc *sch, struct sk_buff *skb)
2735 struct cake_sched_data *q = qdisc_priv(sch); 2736 struct cake_sched_data *q = qdisc_priv(sch);
2736 struct nlattr *opts; 2737 struct nlattr *opts;
2737 2738
2738 opts = nla_nest_start(skb, TCA_OPTIONS); 2739 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
2739 if (!opts) 2740 if (!opts)
2740 goto nla_put_failure; 2741 goto nla_put_failure;
2741 2742
@@ -2806,7 +2807,7 @@ nla_put_failure:
2806 2807
2807static int cake_dump_stats(struct Qdisc *sch, struct gnet_dump *d) 2808static int cake_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
2808{ 2809{
2809 struct nlattr *stats = nla_nest_start(d->skb, TCA_STATS_APP); 2810 struct nlattr *stats = nla_nest_start_noflag(d->skb, TCA_STATS_APP);
2810 struct cake_sched_data *q = qdisc_priv(sch); 2811 struct cake_sched_data *q = qdisc_priv(sch);
2811 struct nlattr *tstats, *ts; 2812 struct nlattr *tstats, *ts;
2812 int i; 2813 int i;
@@ -2836,7 +2837,7 @@ static int cake_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
2836#undef PUT_STAT_U32 2837#undef PUT_STAT_U32
2837#undef PUT_STAT_U64 2838#undef PUT_STAT_U64
2838 2839
2839 tstats = nla_nest_start(d->skb, TCA_CAKE_STATS_TIN_STATS); 2840 tstats = nla_nest_start_noflag(d->skb, TCA_CAKE_STATS_TIN_STATS);
2840 if (!tstats) 2841 if (!tstats)
2841 goto nla_put_failure; 2842 goto nla_put_failure;
2842 2843
@@ -2853,7 +2854,7 @@ static int cake_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
2853 for (i = 0; i < q->tin_cnt; i++) { 2854 for (i = 0; i < q->tin_cnt; i++) {
2854 struct cake_tin_data *b = &q->tins[q->tin_order[i]]; 2855 struct cake_tin_data *b = &q->tins[q->tin_order[i]];
2855 2856
2856 ts = nla_nest_start(d->skb, i + 1); 2857 ts = nla_nest_start_noflag(d->skb, i + 1);
2857 if (!ts) 2858 if (!ts)
2858 goto nla_put_failure; 2859 goto nla_put_failure;
2859 2860
@@ -2973,7 +2974,7 @@ static int cake_dump_class_stats(struct Qdisc *sch, unsigned long cl,
2973 if (flow) { 2974 if (flow) {
2974 ktime_t now = ktime_get(); 2975 ktime_t now = ktime_get();
2975 2976
2976 stats = nla_nest_start(d->skb, TCA_STATS_APP); 2977 stats = nla_nest_start_noflag(d->skb, TCA_STATS_APP);
2977 if (!stats) 2978 if (!stats)
2978 return -1; 2979 return -1;
2979 2980
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 114b9048ea7e..ba4b33b74dd8 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -1149,7 +1149,8 @@ static int cbq_init(struct Qdisc *sch, struct nlattr *opt,
1149 return -EINVAL; 1149 return -EINVAL;
1150 } 1150 }
1151 1151
1152 err = nla_parse_nested(tb, TCA_CBQ_MAX, opt, cbq_policy, extack); 1152 err = nla_parse_nested_deprecated(tb, TCA_CBQ_MAX, opt, cbq_policy,
1153 extack);
1153 if (err < 0) 1154 if (err < 0)
1154 return err; 1155 return err;
1155 1156
@@ -1305,7 +1306,7 @@ static int cbq_dump(struct Qdisc *sch, struct sk_buff *skb)
1305 struct cbq_sched_data *q = qdisc_priv(sch); 1306 struct cbq_sched_data *q = qdisc_priv(sch);
1306 struct nlattr *nest; 1307 struct nlattr *nest;
1307 1308
1308 nest = nla_nest_start(skb, TCA_OPTIONS); 1309 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
1309 if (nest == NULL) 1310 if (nest == NULL)
1310 goto nla_put_failure; 1311 goto nla_put_failure;
1311 if (cbq_dump_attr(skb, &q->link) < 0) 1312 if (cbq_dump_attr(skb, &q->link) < 0)
@@ -1340,7 +1341,7 @@ cbq_dump_class(struct Qdisc *sch, unsigned long arg,
1340 tcm->tcm_handle = cl->common.classid; 1341 tcm->tcm_handle = cl->common.classid;
1341 tcm->tcm_info = cl->q->handle; 1342 tcm->tcm_info = cl->q->handle;
1342 1343
1343 nest = nla_nest_start(skb, TCA_OPTIONS); 1344 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
1344 if (nest == NULL) 1345 if (nest == NULL)
1345 goto nla_put_failure; 1346 goto nla_put_failure;
1346 if (cbq_dump_attr(skb, cl) < 0) 1347 if (cbq_dump_attr(skb, cl) < 0)
@@ -1473,7 +1474,8 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
1473 return -EINVAL; 1474 return -EINVAL;
1474 } 1475 }
1475 1476
1476 err = nla_parse_nested(tb, TCA_CBQ_MAX, opt, cbq_policy, extack); 1477 err = nla_parse_nested_deprecated(tb, TCA_CBQ_MAX, opt, cbq_policy,
1478 extack);
1477 if (err < 0) 1479 if (err < 0)
1478 return err; 1480 return err;
1479 1481
diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c
index c6a502933fe7..8077c846f5bf 100644
--- a/net/sched/sch_cbs.c
+++ b/net/sched/sch_cbs.c
@@ -61,16 +61,20 @@
61#include <linux/string.h> 61#include <linux/string.h>
62#include <linux/errno.h> 62#include <linux/errno.h>
63#include <linux/skbuff.h> 63#include <linux/skbuff.h>
64#include <net/netevent.h>
64#include <net/netlink.h> 65#include <net/netlink.h>
65#include <net/sch_generic.h> 66#include <net/sch_generic.h>
66#include <net/pkt_sched.h> 67#include <net/pkt_sched.h>
67 68
69static LIST_HEAD(cbs_list);
70static DEFINE_SPINLOCK(cbs_list_lock);
71
68#define BYTES_PER_KBIT (1000LL / 8) 72#define BYTES_PER_KBIT (1000LL / 8)
69 73
70struct cbs_sched_data { 74struct cbs_sched_data {
71 bool offload; 75 bool offload;
72 int queue; 76 int queue;
73 s64 port_rate; /* in bytes/s */ 77 atomic64_t port_rate; /* in bytes/s */
74 s64 last; /* timestamp in ns */ 78 s64 last; /* timestamp in ns */
75 s64 credits; /* in bytes */ 79 s64 credits; /* in bytes */
76 s32 locredit; /* in bytes */ 80 s32 locredit; /* in bytes */
@@ -82,6 +86,7 @@ struct cbs_sched_data {
82 struct sk_buff **to_free); 86 struct sk_buff **to_free);
83 struct sk_buff *(*dequeue)(struct Qdisc *sch); 87 struct sk_buff *(*dequeue)(struct Qdisc *sch);
84 struct Qdisc *qdisc; 88 struct Qdisc *qdisc;
89 struct list_head cbs_list;
85}; 90};
86 91
87static int cbs_child_enqueue(struct sk_buff *skb, struct Qdisc *sch, 92static int cbs_child_enqueue(struct sk_buff *skb, struct Qdisc *sch,
@@ -181,6 +186,11 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch)
181 s64 credits; 186 s64 credits;
182 int len; 187 int len;
183 188
189 if (atomic64_read(&q->port_rate) == -1) {
190 WARN_ONCE(1, "cbs: dequeue() called with unknown port rate.");
191 return NULL;
192 }
193
184 if (q->credits < 0) { 194 if (q->credits < 0) {
185 credits = timediff_to_credits(now - q->last, q->idleslope); 195 credits = timediff_to_credits(now - q->last, q->idleslope);
186 196
@@ -207,7 +217,8 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch)
207 /* As sendslope is a negative number, this will decrease the 217 /* As sendslope is a negative number, this will decrease the
208 * amount of q->credits. 218 * amount of q->credits.
209 */ 219 */
210 credits = credits_from_len(len, q->sendslope, q->port_rate); 220 credits = credits_from_len(len, q->sendslope,
221 atomic64_read(&q->port_rate));
211 credits += q->credits; 222 credits += q->credits;
212 223
213 q->credits = max_t(s64, credits, q->locredit); 224 q->credits = max_t(s64, credits, q->locredit);
@@ -294,6 +305,50 @@ static int cbs_enable_offload(struct net_device *dev, struct cbs_sched_data *q,
294 return 0; 305 return 0;
295} 306}
296 307
308static void cbs_set_port_rate(struct net_device *dev, struct cbs_sched_data *q)
309{
310 struct ethtool_link_ksettings ecmd;
311 int port_rate = -1;
312
313 if (!__ethtool_get_link_ksettings(dev, &ecmd) &&
314 ecmd.base.speed != SPEED_UNKNOWN)
315 port_rate = ecmd.base.speed * 1000 * BYTES_PER_KBIT;
316
317 atomic64_set(&q->port_rate, port_rate);
318 netdev_dbg(dev, "cbs: set %s's port_rate to: %lld, linkspeed: %d\n",
319 dev->name, (long long)atomic64_read(&q->port_rate),
320 ecmd.base.speed);
321}
322
323static int cbs_dev_notifier(struct notifier_block *nb, unsigned long event,
324 void *ptr)
325{
326 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
327 struct cbs_sched_data *q;
328 struct net_device *qdev;
329 bool found = false;
330
331 ASSERT_RTNL();
332
333 if (event != NETDEV_UP && event != NETDEV_CHANGE)
334 return NOTIFY_DONE;
335
336 spin_lock(&cbs_list_lock);
337 list_for_each_entry(q, &cbs_list, cbs_list) {
338 qdev = qdisc_dev(q->qdisc);
339 if (qdev == dev) {
340 found = true;
341 break;
342 }
343 }
344 spin_unlock(&cbs_list_lock);
345
346 if (found)
347 cbs_set_port_rate(dev, q);
348
349 return NOTIFY_DONE;
350}
351
297static int cbs_change(struct Qdisc *sch, struct nlattr *opt, 352static int cbs_change(struct Qdisc *sch, struct nlattr *opt,
298 struct netlink_ext_ack *extack) 353 struct netlink_ext_ack *extack)
299{ 354{
@@ -303,7 +358,8 @@ static int cbs_change(struct Qdisc *sch, struct nlattr *opt,
303 struct tc_cbs_qopt *qopt; 358 struct tc_cbs_qopt *qopt;
304 int err; 359 int err;
305 360
306 err = nla_parse_nested(tb, TCA_CBS_MAX, opt, cbs_policy, extack); 361 err = nla_parse_nested_deprecated(tb, TCA_CBS_MAX, opt, cbs_policy,
362 extack);
307 if (err < 0) 363 if (err < 0)
308 return err; 364 return err;
309 365
@@ -315,16 +371,7 @@ static int cbs_change(struct Qdisc *sch, struct nlattr *opt,
315 qopt = nla_data(tb[TCA_CBS_PARMS]); 371 qopt = nla_data(tb[TCA_CBS_PARMS]);
316 372
317 if (!qopt->offload) { 373 if (!qopt->offload) {
318 struct ethtool_link_ksettings ecmd; 374 cbs_set_port_rate(dev, q);
319 s64 link_speed;
320
321 if (!__ethtool_get_link_ksettings(dev, &ecmd))
322 link_speed = ecmd.base.speed;
323 else
324 link_speed = SPEED_1000;
325
326 q->port_rate = link_speed * 1000 * BYTES_PER_KBIT;
327
328 cbs_disable_offload(dev, q); 375 cbs_disable_offload(dev, q);
329 } else { 376 } else {
330 err = cbs_enable_offload(dev, q, qopt, extack); 377 err = cbs_enable_offload(dev, q, qopt, extack);
@@ -347,6 +394,7 @@ static int cbs_init(struct Qdisc *sch, struct nlattr *opt,
347{ 394{
348 struct cbs_sched_data *q = qdisc_priv(sch); 395 struct cbs_sched_data *q = qdisc_priv(sch);
349 struct net_device *dev = qdisc_dev(sch); 396 struct net_device *dev = qdisc_dev(sch);
397 int err;
350 398
351 if (!opt) { 399 if (!opt) {
352 NL_SET_ERR_MSG(extack, "Missing CBS qdisc options which are mandatory"); 400 NL_SET_ERR_MSG(extack, "Missing CBS qdisc options which are mandatory");
@@ -367,7 +415,17 @@ static int cbs_init(struct Qdisc *sch, struct nlattr *opt,
367 415
368 qdisc_watchdog_init(&q->watchdog, sch); 416 qdisc_watchdog_init(&q->watchdog, sch);
369 417
370 return cbs_change(sch, opt, extack); 418 err = cbs_change(sch, opt, extack);
419 if (err)
420 return err;
421
422 if (!q->offload) {
423 spin_lock(&cbs_list_lock);
424 list_add(&q->cbs_list, &cbs_list);
425 spin_unlock(&cbs_list_lock);
426 }
427
428 return 0;
371} 429}
372 430
373static void cbs_destroy(struct Qdisc *sch) 431static void cbs_destroy(struct Qdisc *sch)
@@ -375,8 +433,11 @@ static void cbs_destroy(struct Qdisc *sch)
375 struct cbs_sched_data *q = qdisc_priv(sch); 433 struct cbs_sched_data *q = qdisc_priv(sch);
376 struct net_device *dev = qdisc_dev(sch); 434 struct net_device *dev = qdisc_dev(sch);
377 435
378 qdisc_watchdog_cancel(&q->watchdog); 436 spin_lock(&cbs_list_lock);
437 list_del(&q->cbs_list);
438 spin_unlock(&cbs_list_lock);
379 439
440 qdisc_watchdog_cancel(&q->watchdog);
380 cbs_disable_offload(dev, q); 441 cbs_disable_offload(dev, q);
381 442
382 if (q->qdisc) 443 if (q->qdisc)
@@ -389,7 +450,7 @@ static int cbs_dump(struct Qdisc *sch, struct sk_buff *skb)
389 struct tc_cbs_qopt opt = { }; 450 struct tc_cbs_qopt opt = { };
390 struct nlattr *nest; 451 struct nlattr *nest;
391 452
392 nest = nla_nest_start(skb, TCA_OPTIONS); 453 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
393 if (!nest) 454 if (!nest)
394 goto nla_put_failure; 455 goto nla_put_failure;
395 456
@@ -487,14 +548,24 @@ static struct Qdisc_ops cbs_qdisc_ops __read_mostly = {
487 .owner = THIS_MODULE, 548 .owner = THIS_MODULE,
488}; 549};
489 550
551static struct notifier_block cbs_device_notifier = {
552 .notifier_call = cbs_dev_notifier,
553};
554
490static int __init cbs_module_init(void) 555static int __init cbs_module_init(void)
491{ 556{
557 int err = register_netdevice_notifier(&cbs_device_notifier);
558
559 if (err)
560 return err;
561
492 return register_qdisc(&cbs_qdisc_ops); 562 return register_qdisc(&cbs_qdisc_ops);
493} 563}
494 564
495static void __exit cbs_module_exit(void) 565static void __exit cbs_module_exit(void)
496{ 566{
497 unregister_qdisc(&cbs_qdisc_ops); 567 unregister_qdisc(&cbs_qdisc_ops);
568 unregister_netdevice_notifier(&cbs_device_notifier);
498} 569}
499module_init(cbs_module_init) 570module_init(cbs_module_init)
500module_exit(cbs_module_exit) 571module_exit(cbs_module_exit)
diff --git a/net/sched/sch_choke.c b/net/sched/sch_choke.c
index eafc0d17d174..370dbcf49e8b 100644
--- a/net/sched/sch_choke.c
+++ b/net/sched/sch_choke.c
@@ -358,7 +358,8 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt,
358 if (opt == NULL) 358 if (opt == NULL)
359 return -EINVAL; 359 return -EINVAL;
360 360
361 err = nla_parse_nested(tb, TCA_CHOKE_MAX, opt, choke_policy, NULL); 361 err = nla_parse_nested_deprecated(tb, TCA_CHOKE_MAX, opt,
362 choke_policy, NULL);
362 if (err < 0) 363 if (err < 0)
363 return err; 364 return err;
364 365
@@ -452,7 +453,7 @@ static int choke_dump(struct Qdisc *sch, struct sk_buff *skb)
452 .Scell_log = q->parms.Scell_log, 453 .Scell_log = q->parms.Scell_log,
453 }; 454 };
454 455
455 opts = nla_nest_start(skb, TCA_OPTIONS); 456 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
456 if (opts == NULL) 457 if (opts == NULL)
457 goto nla_put_failure; 458 goto nla_put_failure;
458 459
diff --git a/net/sched/sch_codel.c b/net/sched/sch_codel.c
index 17cd81f84b5d..25ef172c23df 100644
--- a/net/sched/sch_codel.c
+++ b/net/sched/sch_codel.c
@@ -141,7 +141,8 @@ static int codel_change(struct Qdisc *sch, struct nlattr *opt,
141 if (!opt) 141 if (!opt)
142 return -EINVAL; 142 return -EINVAL;
143 143
144 err = nla_parse_nested(tb, TCA_CODEL_MAX, opt, codel_policy, NULL); 144 err = nla_parse_nested_deprecated(tb, TCA_CODEL_MAX, opt,
145 codel_policy, NULL);
145 if (err < 0) 146 if (err < 0)
146 return err; 147 return err;
147 148
@@ -217,7 +218,7 @@ static int codel_dump(struct Qdisc *sch, struct sk_buff *skb)
217 struct codel_sched_data *q = qdisc_priv(sch); 218 struct codel_sched_data *q = qdisc_priv(sch);
218 struct nlattr *opts; 219 struct nlattr *opts;
219 220
220 opts = nla_nest_start(skb, TCA_OPTIONS); 221 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
221 if (opts == NULL) 222 if (opts == NULL)
222 goto nla_put_failure; 223 goto nla_put_failure;
223 224
diff --git a/net/sched/sch_drr.c b/net/sched/sch_drr.c
index 430df9a55ec4..ffcd6654c39d 100644
--- a/net/sched/sch_drr.c
+++ b/net/sched/sch_drr.c
@@ -70,7 +70,8 @@ static int drr_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
70 return -EINVAL; 70 return -EINVAL;
71 } 71 }
72 72
73 err = nla_parse_nested(tb, TCA_DRR_MAX, opt, drr_policy, extack); 73 err = nla_parse_nested_deprecated(tb, TCA_DRR_MAX, opt, drr_policy,
74 extack);
74 if (err < 0) 75 if (err < 0)
75 return err; 76 return err;
76 77
@@ -244,7 +245,7 @@ static int drr_dump_class(struct Qdisc *sch, unsigned long arg,
244 tcm->tcm_handle = cl->common.classid; 245 tcm->tcm_handle = cl->common.classid;
245 tcm->tcm_info = cl->qdisc->handle; 246 tcm->tcm_info = cl->qdisc->handle;
246 247
247 nest = nla_nest_start(skb, TCA_OPTIONS); 248 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
248 if (nest == NULL) 249 if (nest == NULL)
249 goto nla_put_failure; 250 goto nla_put_failure;
250 if (nla_put_u32(skb, TCA_DRR_QUANTUM, cl->quantum)) 251 if (nla_put_u32(skb, TCA_DRR_QUANTUM, cl->quantum))
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c
index 42471464ded3..3deeb06eaecf 100644
--- a/net/sched/sch_dsmark.c
+++ b/net/sched/sch_dsmark.c
@@ -132,7 +132,8 @@ static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent,
132 if (!opt) 132 if (!opt)
133 goto errout; 133 goto errout;
134 134
135 err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, dsmark_policy, NULL); 135 err = nla_parse_nested_deprecated(tb, TCA_DSMARK_MAX, opt,
136 dsmark_policy, NULL);
136 if (err < 0) 137 if (err < 0)
137 goto errout; 138 goto errout;
138 139
@@ -353,7 +354,8 @@ static int dsmark_init(struct Qdisc *sch, struct nlattr *opt,
353 if (err) 354 if (err)
354 return err; 355 return err;
355 356
356 err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, dsmark_policy, NULL); 357 err = nla_parse_nested_deprecated(tb, TCA_DSMARK_MAX, opt,
358 dsmark_policy, NULL);
357 if (err < 0) 359 if (err < 0)
358 goto errout; 360 goto errout;
359 361
@@ -432,7 +434,7 @@ static int dsmark_dump_class(struct Qdisc *sch, unsigned long cl,
432 tcm->tcm_handle = TC_H_MAKE(TC_H_MAJ(sch->handle), cl - 1); 434 tcm->tcm_handle = TC_H_MAKE(TC_H_MAJ(sch->handle), cl - 1);
433 tcm->tcm_info = p->q->handle; 435 tcm->tcm_info = p->q->handle;
434 436
435 opts = nla_nest_start(skb, TCA_OPTIONS); 437 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
436 if (opts == NULL) 438 if (opts == NULL)
437 goto nla_put_failure; 439 goto nla_put_failure;
438 if (nla_put_u8(skb, TCA_DSMARK_MASK, p->mv[cl - 1].mask) || 440 if (nla_put_u8(skb, TCA_DSMARK_MASK, p->mv[cl - 1].mask) ||
@@ -451,7 +453,7 @@ static int dsmark_dump(struct Qdisc *sch, struct sk_buff *skb)
451 struct dsmark_qdisc_data *p = qdisc_priv(sch); 453 struct dsmark_qdisc_data *p = qdisc_priv(sch);
452 struct nlattr *opts = NULL; 454 struct nlattr *opts = NULL;
453 455
454 opts = nla_nest_start(skb, TCA_OPTIONS); 456 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
455 if (opts == NULL) 457 if (opts == NULL)
456 goto nla_put_failure; 458 goto nla_put_failure;
457 if (nla_put_u16(skb, TCA_DSMARK_INDICES, p->indices)) 459 if (nla_put_u16(skb, TCA_DSMARK_INDICES, p->indices))
diff --git a/net/sched/sch_etf.c b/net/sched/sch_etf.c
index 1150f22983df..db0c2ba1d156 100644
--- a/net/sched/sch_etf.c
+++ b/net/sched/sch_etf.c
@@ -351,7 +351,8 @@ static int etf_init(struct Qdisc *sch, struct nlattr *opt,
351 return -EINVAL; 351 return -EINVAL;
352 } 352 }
353 353
354 err = nla_parse_nested(tb, TCA_ETF_MAX, opt, etf_policy, extack); 354 err = nla_parse_nested_deprecated(tb, TCA_ETF_MAX, opt, etf_policy,
355 extack);
355 if (err < 0) 356 if (err < 0)
356 return err; 357 return err;
357 358
@@ -460,7 +461,7 @@ static int etf_dump(struct Qdisc *sch, struct sk_buff *skb)
460 struct tc_etf_qopt opt = { }; 461 struct tc_etf_qopt opt = { };
461 struct nlattr *nest; 462 struct nlattr *nest;
462 463
463 nest = nla_nest_start(skb, TCA_OPTIONS); 464 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
464 if (!nest) 465 if (!nest)
465 goto nla_put_failure; 466 goto nla_put_failure;
466 467
diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c
index 1a662f2bb7bb..26a94e5cd5df 100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -54,10 +54,23 @@
54#include <net/tcp_states.h> 54#include <net/tcp_states.h>
55#include <net/tcp.h> 55#include <net/tcp.h>
56 56
57struct fq_skb_cb {
58 u64 time_to_send;
59};
60
61static inline struct fq_skb_cb *fq_skb_cb(struct sk_buff *skb)
62{
63 qdisc_cb_private_validate(skb, sizeof(struct fq_skb_cb));
64 return (struct fq_skb_cb *)qdisc_skb_cb(skb)->data;
65}
66
57/* 67/*
58 * Per flow structure, dynamically allocated 68 * Per flow structure, dynamically allocated.
69 * If packets have monotically increasing time_to_send, they are placed in O(1)
70 * in linear list (head,tail), otherwise are placed in a rbtree (t_root).
59 */ 71 */
60struct fq_flow { 72struct fq_flow {
73 struct rb_root t_root;
61 struct sk_buff *head; /* list of skbs for this flow : first skb */ 74 struct sk_buff *head; /* list of skbs for this flow : first skb */
62 union { 75 union {
63 struct sk_buff *tail; /* last skb in the list */ 76 struct sk_buff *tail; /* last skb in the list */
@@ -257,6 +270,17 @@ static struct fq_flow *fq_classify(struct sk_buff *skb, struct fq_sched_data *q)
257 */ 270 */
258 sk = (struct sock *)((hash << 1) | 1UL); 271 sk = (struct sock *)((hash << 1) | 1UL);
259 skb_orphan(skb); 272 skb_orphan(skb);
273 } else if (sk->sk_state == TCP_CLOSE) {
274 unsigned long hash = skb_get_hash(skb) & q->orphan_mask;
275 /*
276 * Sockets in TCP_CLOSE are non connected.
277 * Typical use case is UDP sockets, they can send packets
278 * with sendto() to many different destinations.
279 * We probably could use a generic bit advertising
280 * non connected sockets, instead of sk_state == TCP_CLOSE,
281 * if we care enough.
282 */
283 sk = (struct sock *)((hash << 1) | 1UL);
260 } 284 }
261 285
262 root = &q->fq_root[hash_ptr(sk, q->fq_trees_log)]; 286 root = &q->fq_root[hash_ptr(sk, q->fq_trees_log)];
@@ -277,7 +301,7 @@ static struct fq_flow *fq_classify(struct sk_buff *skb, struct fq_sched_data *q)
277 * It not, we need to refill credit with 301 * It not, we need to refill credit with
278 * initial quantum 302 * initial quantum
279 */ 303 */
280 if (unlikely(skb->sk && 304 if (unlikely(skb->sk == sk &&
281 f->socket_hash != sk->sk_hash)) { 305 f->socket_hash != sk->sk_hash)) {
282 f->credit = q->initial_quantum; 306 f->credit = q->initial_quantum;
283 f->socket_hash = sk->sk_hash; 307 f->socket_hash = sk->sk_hash;
@@ -298,9 +322,11 @@ static struct fq_flow *fq_classify(struct sk_buff *skb, struct fq_sched_data *q)
298 q->stat_allocation_errors++; 322 q->stat_allocation_errors++;
299 return &q->internal; 323 return &q->internal;
300 } 324 }
325 /* f->t_root is already zeroed after kmem_cache_zalloc() */
326
301 fq_flow_set_detached(f); 327 fq_flow_set_detached(f);
302 f->sk = sk; 328 f->sk = sk;
303 if (skb->sk) 329 if (skb->sk == sk)
304 f->socket_hash = sk->sk_hash; 330 f->socket_hash = sk->sk_hash;
305 f->credit = q->initial_quantum; 331 f->credit = q->initial_quantum;
306 332
@@ -312,14 +338,40 @@ static struct fq_flow *fq_classify(struct sk_buff *skb, struct fq_sched_data *q)
312 return f; 338 return f;
313} 339}
314 340
341static struct sk_buff *fq_peek(struct fq_flow *flow)
342{
343 struct sk_buff *skb = skb_rb_first(&flow->t_root);
344 struct sk_buff *head = flow->head;
345
346 if (!skb)
347 return head;
348
349 if (!head)
350 return skb;
351
352 if (fq_skb_cb(skb)->time_to_send < fq_skb_cb(head)->time_to_send)
353 return skb;
354 return head;
355}
356
357static void fq_erase_head(struct Qdisc *sch, struct fq_flow *flow,
358 struct sk_buff *skb)
359{
360 if (skb == flow->head) {
361 flow->head = skb->next;
362 } else {
363 rb_erase(&skb->rbnode, &flow->t_root);
364 skb->dev = qdisc_dev(sch);
365 }
366}
315 367
316/* remove one skb from head of flow queue */ 368/* remove one skb from head of flow queue */
317static struct sk_buff *fq_dequeue_head(struct Qdisc *sch, struct fq_flow *flow) 369static struct sk_buff *fq_dequeue_head(struct Qdisc *sch, struct fq_flow *flow)
318{ 370{
319 struct sk_buff *skb = flow->head; 371 struct sk_buff *skb = fq_peek(flow);
320 372
321 if (skb) { 373 if (skb) {
322 flow->head = skb->next; 374 fq_erase_head(sch, flow, skb);
323 skb_mark_not_on_list(skb); 375 skb_mark_not_on_list(skb);
324 flow->qlen--; 376 flow->qlen--;
325 qdisc_qstats_backlog_dec(sch, skb); 377 qdisc_qstats_backlog_dec(sch, skb);
@@ -330,15 +382,36 @@ static struct sk_buff *fq_dequeue_head(struct Qdisc *sch, struct fq_flow *flow)
330 382
331static void flow_queue_add(struct fq_flow *flow, struct sk_buff *skb) 383static void flow_queue_add(struct fq_flow *flow, struct sk_buff *skb)
332{ 384{
333 struct sk_buff *head = flow->head; 385 struct rb_node **p, *parent;
386 struct sk_buff *head, *aux;
334 387
335 skb->next = NULL; 388 fq_skb_cb(skb)->time_to_send = skb->tstamp ?: ktime_get_ns();
336 if (!head) 389
337 flow->head = skb; 390 head = flow->head;
338 else 391 if (!head ||
339 flow->tail->next = skb; 392 fq_skb_cb(skb)->time_to_send >= fq_skb_cb(flow->tail)->time_to_send) {
393 if (!head)
394 flow->head = skb;
395 else
396 flow->tail->next = skb;
397 flow->tail = skb;
398 skb->next = NULL;
399 return;
400 }
401
402 p = &flow->t_root.rb_node;
403 parent = NULL;
340 404
341 flow->tail = skb; 405 while (*p) {
406 parent = *p;
407 aux = rb_to_skb(parent);
408 if (fq_skb_cb(skb)->time_to_send >= fq_skb_cb(aux)->time_to_send)
409 p = &parent->rb_right;
410 else
411 p = &parent->rb_left;
412 }
413 rb_link_node(&skb->rbnode, parent, p);
414 rb_insert_color(&skb->rbnode, &flow->t_root);
342} 415}
343 416
344static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch, 417static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
@@ -450,9 +523,9 @@ begin:
450 goto begin; 523 goto begin;
451 } 524 }
452 525
453 skb = f->head; 526 skb = fq_peek(f);
454 if (skb) { 527 if (skb) {
455 u64 time_next_packet = max_t(u64, ktime_to_ns(skb->tstamp), 528 u64 time_next_packet = max_t(u64, fq_skb_cb(skb)->time_to_send,
456 f->time_next_packet); 529 f->time_next_packet);
457 530
458 if (now < time_next_packet) { 531 if (now < time_next_packet) {
@@ -533,6 +606,15 @@ out:
533 606
534static void fq_flow_purge(struct fq_flow *flow) 607static void fq_flow_purge(struct fq_flow *flow)
535{ 608{
609 struct rb_node *p = rb_first(&flow->t_root);
610
611 while (p) {
612 struct sk_buff *skb = rb_to_skb(p);
613
614 p = rb_next(p);
615 rb_erase(&skb->rbnode, &flow->t_root);
616 rtnl_kfree_skbs(skb, skb);
617 }
536 rtnl_kfree_skbs(flow->head, flow->tail); 618 rtnl_kfree_skbs(flow->head, flow->tail);
537 flow->head = NULL; 619 flow->head = NULL;
538 flow->qlen = 0; 620 flow->qlen = 0;
@@ -684,7 +766,8 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt,
684 if (!opt) 766 if (!opt)
685 return -EINVAL; 767 return -EINVAL;
686 768
687 err = nla_parse_nested(tb, TCA_FQ_MAX, opt, fq_policy, NULL); 769 err = nla_parse_nested_deprecated(tb, TCA_FQ_MAX, opt, fq_policy,
770 NULL);
688 if (err < 0) 771 if (err < 0)
689 return err; 772 return err;
690 773
@@ -823,7 +906,7 @@ static int fq_dump(struct Qdisc *sch, struct sk_buff *skb)
823 u64 ce_threshold = q->ce_threshold; 906 u64 ce_threshold = q->ce_threshold;
824 struct nlattr *opts; 907 struct nlattr *opts;
825 908
826 opts = nla_nest_start(skb, TCA_OPTIONS); 909 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
827 if (opts == NULL) 910 if (opts == NULL)
828 goto nla_put_failure; 911 goto nla_put_failure;
829 912
diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
index cd04d40c30b6..08d85370b97c 100644
--- a/net/sched/sch_fq_codel.c
+++ b/net/sched/sch_fq_codel.c
@@ -387,8 +387,8 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
387 if (!opt) 387 if (!opt)
388 return -EINVAL; 388 return -EINVAL;
389 389
390 err = nla_parse_nested(tb, TCA_FQ_CODEL_MAX, opt, fq_codel_policy, 390 err = nla_parse_nested_deprecated(tb, TCA_FQ_CODEL_MAX, opt,
391 NULL); 391 fq_codel_policy, NULL);
392 if (err < 0) 392 if (err < 0)
393 return err; 393 return err;
394 if (tb[TCA_FQ_CODEL_FLOWS]) { 394 if (tb[TCA_FQ_CODEL_FLOWS]) {
@@ -527,7 +527,7 @@ static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)
527 struct fq_codel_sched_data *q = qdisc_priv(sch); 527 struct fq_codel_sched_data *q = qdisc_priv(sch);
528 struct nlattr *opts; 528 struct nlattr *opts;
529 529
530 opts = nla_nest_start(skb, TCA_OPTIONS); 530 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
531 if (opts == NULL) 531 if (opts == NULL)
532 goto nla_put_failure; 532 goto nla_put_failure;
533 533
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index a117d9260558..cce1e9ee85af 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -32,6 +32,7 @@
32#include <net/pkt_sched.h> 32#include <net/pkt_sched.h>
33#include <net/dst.h> 33#include <net/dst.h>
34#include <trace/events/qdisc.h> 34#include <trace/events/qdisc.h>
35#include <trace/events/net.h>
35#include <net/xfrm.h> 36#include <net/xfrm.h>
36 37
37/* Qdisc to use by default */ 38/* Qdisc to use by default */
@@ -68,7 +69,7 @@ static inline struct sk_buff *__skb_dequeue_bad_txq(struct Qdisc *q)
68 skb = __skb_dequeue(&q->skb_bad_txq); 69 skb = __skb_dequeue(&q->skb_bad_txq);
69 if (qdisc_is_percpu_stats(q)) { 70 if (qdisc_is_percpu_stats(q)) {
70 qdisc_qstats_cpu_backlog_dec(q, skb); 71 qdisc_qstats_cpu_backlog_dec(q, skb);
71 qdisc_qstats_atomic_qlen_dec(q); 72 qdisc_qstats_cpu_qlen_dec(q);
72 } else { 73 } else {
73 qdisc_qstats_backlog_dec(q, skb); 74 qdisc_qstats_backlog_dec(q, skb);
74 q->q.qlen--; 75 q->q.qlen--;
@@ -108,7 +109,7 @@ static inline void qdisc_enqueue_skb_bad_txq(struct Qdisc *q,
108 109
109 if (qdisc_is_percpu_stats(q)) { 110 if (qdisc_is_percpu_stats(q)) {
110 qdisc_qstats_cpu_backlog_inc(q, skb); 111 qdisc_qstats_cpu_backlog_inc(q, skb);
111 qdisc_qstats_atomic_qlen_inc(q); 112 qdisc_qstats_cpu_qlen_inc(q);
112 } else { 113 } else {
113 qdisc_qstats_backlog_inc(q, skb); 114 qdisc_qstats_backlog_inc(q, skb);
114 q->q.qlen++; 115 q->q.qlen++;
@@ -118,52 +119,36 @@ static inline void qdisc_enqueue_skb_bad_txq(struct Qdisc *q,
118 spin_unlock(lock); 119 spin_unlock(lock);
119} 120}
120 121
121static inline int __dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q) 122static inline void dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q)
122{ 123{
123 while (skb) { 124 spinlock_t *lock = NULL;
124 struct sk_buff *next = skb->next;
125
126 __skb_queue_tail(&q->gso_skb, skb);
127 q->qstats.requeues++;
128 qdisc_qstats_backlog_inc(q, skb);
129 q->q.qlen++; /* it's still part of the queue */
130 125
131 skb = next; 126 if (q->flags & TCQ_F_NOLOCK) {
127 lock = qdisc_lock(q);
128 spin_lock(lock);
132 } 129 }
133 __netif_schedule(q);
134 130
135 return 0;
136}
137
138static inline int dev_requeue_skb_locked(struct sk_buff *skb, struct Qdisc *q)
139{
140 spinlock_t *lock = qdisc_lock(q);
141
142 spin_lock(lock);
143 while (skb) { 131 while (skb) {
144 struct sk_buff *next = skb->next; 132 struct sk_buff *next = skb->next;
145 133
146 __skb_queue_tail(&q->gso_skb, skb); 134 __skb_queue_tail(&q->gso_skb, skb);
147 135
148 qdisc_qstats_cpu_requeues_inc(q); 136 /* it's still part of the queue */
149 qdisc_qstats_cpu_backlog_inc(q, skb); 137 if (qdisc_is_percpu_stats(q)) {
150 qdisc_qstats_atomic_qlen_inc(q); 138 qdisc_qstats_cpu_requeues_inc(q);
139 qdisc_qstats_cpu_backlog_inc(q, skb);
140 qdisc_qstats_cpu_qlen_inc(q);
141 } else {
142 q->qstats.requeues++;
143 qdisc_qstats_backlog_inc(q, skb);
144 q->q.qlen++;
145 }
151 146
152 skb = next; 147 skb = next;
153 } 148 }
154 spin_unlock(lock); 149 if (lock)
155 150 spin_unlock(lock);
156 __netif_schedule(q); 151 __netif_schedule(q);
157
158 return 0;
159}
160
161static inline int dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q)
162{
163 if (q->flags & TCQ_F_NOLOCK)
164 return dev_requeue_skb_locked(skb, q);
165 else
166 return __dev_requeue_skb(skb, q);
167} 152}
168 153
169static void try_bulk_dequeue_skb(struct Qdisc *q, 154static void try_bulk_dequeue_skb(struct Qdisc *q,
@@ -252,7 +237,7 @@ static struct sk_buff *dequeue_skb(struct Qdisc *q, bool *validate,
252 skb = __skb_dequeue(&q->gso_skb); 237 skb = __skb_dequeue(&q->gso_skb);
253 if (qdisc_is_percpu_stats(q)) { 238 if (qdisc_is_percpu_stats(q)) {
254 qdisc_qstats_cpu_backlog_dec(q, skb); 239 qdisc_qstats_cpu_backlog_dec(q, skb);
255 qdisc_qstats_atomic_qlen_dec(q); 240 qdisc_qstats_cpu_qlen_dec(q);
256 } else { 241 } else {
257 qdisc_qstats_backlog_dec(q, skb); 242 qdisc_qstats_backlog_dec(q, skb);
258 q->q.qlen--; 243 q->q.qlen--;
@@ -457,6 +442,7 @@ static void dev_watchdog(struct timer_list *t)
457 } 442 }
458 443
459 if (some_queue_timedout) { 444 if (some_queue_timedout) {
445 trace_net_dev_xmit_timeout(dev, i);
460 WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit queue %u timed out\n", 446 WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit queue %u timed out\n",
461 dev->name, netdev_drivername(dev), i); 447 dev->name, netdev_drivername(dev), i);
462 dev->netdev_ops->ndo_tx_timeout(dev); 448 dev->netdev_ops->ndo_tx_timeout(dev);
@@ -645,11 +631,7 @@ static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc *qdisc,
645 if (unlikely(err)) 631 if (unlikely(err))
646 return qdisc_drop_cpu(skb, qdisc, to_free); 632 return qdisc_drop_cpu(skb, qdisc, to_free);
647 633
648 qdisc_qstats_atomic_qlen_inc(qdisc); 634 qdisc_update_stats_at_enqueue(qdisc, pkt_len);
649 /* Note: skb can not be used after skb_array_produce(),
650 * so we better not use qdisc_qstats_cpu_backlog_inc()
651 */
652 this_cpu_add(qdisc->cpu_qstats->backlog, pkt_len);
653 return NET_XMIT_SUCCESS; 635 return NET_XMIT_SUCCESS;
654} 636}
655 637
@@ -668,9 +650,9 @@ static struct sk_buff *pfifo_fast_dequeue(struct Qdisc *qdisc)
668 skb = __skb_array_consume(q); 650 skb = __skb_array_consume(q);
669 } 651 }
670 if (likely(skb)) { 652 if (likely(skb)) {
671 qdisc_qstats_cpu_backlog_dec(qdisc, skb); 653 qdisc_update_stats_at_dequeue(qdisc, skb);
672 qdisc_bstats_cpu_update(qdisc, skb); 654 } else {
673 qdisc_qstats_atomic_qlen_dec(qdisc); 655 qdisc->empty = true;
674 } 656 }
675 657
676 return skb; 658 return skb;
@@ -714,6 +696,7 @@ static void pfifo_fast_reset(struct Qdisc *qdisc)
714 struct gnet_stats_queue *q = per_cpu_ptr(qdisc->cpu_qstats, i); 696 struct gnet_stats_queue *q = per_cpu_ptr(qdisc->cpu_qstats, i);
715 697
716 q->backlog = 0; 698 q->backlog = 0;
699 q->qlen = 0;
717 } 700 }
718} 701}
719 702
@@ -880,6 +863,7 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
880 sch->enqueue = ops->enqueue; 863 sch->enqueue = ops->enqueue;
881 sch->dequeue = ops->dequeue; 864 sch->dequeue = ops->dequeue;
882 sch->dev_queue = dev_queue; 865 sch->dev_queue = dev_queue;
866 sch->empty = true;
883 dev_hold(dev); 867 dev_hold(dev);
884 refcount_set(&sch->refcnt, 1); 868 refcount_set(&sch->refcnt, 1);
885 869
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index 234afbf9115b..dfa657da100f 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -538,7 +538,8 @@ static void gred_vq_apply(struct gred_sched *table, const struct nlattr *entry)
538 struct nlattr *tb[TCA_GRED_VQ_MAX + 1]; 538 struct nlattr *tb[TCA_GRED_VQ_MAX + 1];
539 u32 dp; 539 u32 dp;
540 540
541 nla_parse_nested(tb, TCA_GRED_VQ_MAX, entry, gred_vq_policy, NULL); 541 nla_parse_nested_deprecated(tb, TCA_GRED_VQ_MAX, entry,
542 gred_vq_policy, NULL);
542 543
543 dp = nla_get_u32(tb[TCA_GRED_VQ_DP]); 544 dp = nla_get_u32(tb[TCA_GRED_VQ_DP]);
544 545
@@ -568,8 +569,8 @@ static int gred_vq_validate(struct gred_sched *table, u32 cdp,
568 int err; 569 int err;
569 u32 dp; 570 u32 dp;
570 571
571 err = nla_parse_nested(tb, TCA_GRED_VQ_MAX, entry, gred_vq_policy, 572 err = nla_parse_nested_deprecated(tb, TCA_GRED_VQ_MAX, entry,
572 extack); 573 gred_vq_policy, extack);
573 if (err < 0) 574 if (err < 0)
574 return err; 575 return err;
575 576
@@ -610,8 +611,8 @@ static int gred_vqs_validate(struct gred_sched *table, u32 cdp,
610 const struct nlattr *attr; 611 const struct nlattr *attr;
611 int rem, err; 612 int rem, err;
612 613
613 err = nla_validate_nested(vqs, TCA_GRED_VQ_ENTRY_MAX, 614 err = nla_validate_nested_deprecated(vqs, TCA_GRED_VQ_ENTRY_MAX,
614 gred_vqe_policy, extack); 615 gred_vqe_policy, extack);
615 if (err < 0) 616 if (err < 0)
616 return err; 617 return err;
617 618
@@ -650,7 +651,8 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt,
650 if (opt == NULL) 651 if (opt == NULL)
651 return -EINVAL; 652 return -EINVAL;
652 653
653 err = nla_parse_nested(tb, TCA_GRED_MAX, opt, gred_policy, extack); 654 err = nla_parse_nested_deprecated(tb, TCA_GRED_MAX, opt, gred_policy,
655 extack);
654 if (err < 0) 656 if (err < 0)
655 return err; 657 return err;
656 658
@@ -737,7 +739,8 @@ static int gred_init(struct Qdisc *sch, struct nlattr *opt,
737 if (!opt) 739 if (!opt)
738 return -EINVAL; 740 return -EINVAL;
739 741
740 err = nla_parse_nested(tb, TCA_GRED_MAX, opt, gred_policy, extack); 742 err = nla_parse_nested_deprecated(tb, TCA_GRED_MAX, opt, gred_policy,
743 extack);
741 if (err < 0) 744 if (err < 0)
742 return err; 745 return err;
743 746
@@ -772,7 +775,7 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
772 if (gred_offload_dump_stats(sch)) 775 if (gred_offload_dump_stats(sch))
773 goto nla_put_failure; 776 goto nla_put_failure;
774 777
775 opts = nla_nest_start(skb, TCA_OPTIONS); 778 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
776 if (opts == NULL) 779 if (opts == NULL)
777 goto nla_put_failure; 780 goto nla_put_failure;
778 if (nla_put(skb, TCA_GRED_DPS, sizeof(sopt), &sopt)) 781 if (nla_put(skb, TCA_GRED_DPS, sizeof(sopt), &sopt))
@@ -790,7 +793,7 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
790 goto nla_put_failure; 793 goto nla_put_failure;
791 794
792 /* Old style all-in-one dump of VQs */ 795 /* Old style all-in-one dump of VQs */
793 parms = nla_nest_start(skb, TCA_GRED_PARMS); 796 parms = nla_nest_start_noflag(skb, TCA_GRED_PARMS);
794 if (parms == NULL) 797 if (parms == NULL)
795 goto nla_put_failure; 798 goto nla_put_failure;
796 799
@@ -841,7 +844,7 @@ append_opt:
841 nla_nest_end(skb, parms); 844 nla_nest_end(skb, parms);
842 845
843 /* Dump the VQs again, in more structured way */ 846 /* Dump the VQs again, in more structured way */
844 vqs = nla_nest_start(skb, TCA_GRED_VQ_LIST); 847 vqs = nla_nest_start_noflag(skb, TCA_GRED_VQ_LIST);
845 if (!vqs) 848 if (!vqs)
846 goto nla_put_failure; 849 goto nla_put_failure;
847 850
@@ -852,7 +855,7 @@ append_opt:
852 if (!q) 855 if (!q)
853 continue; 856 continue;
854 857
855 vq = nla_nest_start(skb, TCA_GRED_VQ_ENTRY); 858 vq = nla_nest_start_noflag(skb, TCA_GRED_VQ_ENTRY);
856 if (!vq) 859 if (!vq)
857 goto nla_put_failure; 860 goto nla_put_failure;
858 861
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c
index d2ab463f22ae..433f2190960f 100644
--- a/net/sched/sch_hfsc.c
+++ b/net/sched/sch_hfsc.c
@@ -926,7 +926,8 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
926 if (opt == NULL) 926 if (opt == NULL)
927 return -EINVAL; 927 return -EINVAL;
928 928
929 err = nla_parse_nested(tb, TCA_HFSC_MAX, opt, hfsc_policy, NULL); 929 err = nla_parse_nested_deprecated(tb, TCA_HFSC_MAX, opt, hfsc_policy,
930 NULL);
930 if (err < 0) 931 if (err < 0)
931 return err; 932 return err;
932 933
@@ -1300,7 +1301,7 @@ hfsc_dump_class(struct Qdisc *sch, unsigned long arg, struct sk_buff *skb,
1300 if (cl->level == 0) 1301 if (cl->level == 0)
1301 tcm->tcm_info = cl->qdisc->handle; 1302 tcm->tcm_info = cl->qdisc->handle;
1302 1303
1303 nest = nla_nest_start(skb, TCA_OPTIONS); 1304 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
1304 if (nest == NULL) 1305 if (nest == NULL)
1305 goto nla_put_failure; 1306 goto nla_put_failure;
1306 if (hfsc_dump_curves(skb, cl) < 0) 1307 if (hfsc_dump_curves(skb, cl) < 0)
diff --git a/net/sched/sch_hhf.c b/net/sched/sch_hhf.c
index 9d6a47697406..a28e09b1609c 100644
--- a/net/sched/sch_hhf.c
+++ b/net/sched/sch_hhf.c
@@ -518,7 +518,8 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt,
518 if (!opt) 518 if (!opt)
519 return -EINVAL; 519 return -EINVAL;
520 520
521 err = nla_parse_nested(tb, TCA_HHF_MAX, opt, hhf_policy, NULL); 521 err = nla_parse_nested_deprecated(tb, TCA_HHF_MAX, opt, hhf_policy,
522 NULL);
522 if (err < 0) 523 if (err < 0)
523 return err; 524 return err;
524 525
@@ -654,7 +655,7 @@ static int hhf_dump(struct Qdisc *sch, struct sk_buff *skb)
654 struct hhf_sched_data *q = qdisc_priv(sch); 655 struct hhf_sched_data *q = qdisc_priv(sch);
655 struct nlattr *opts; 656 struct nlattr *opts;
656 657
657 opts = nla_nest_start(skb, TCA_OPTIONS); 658 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
658 if (opts == NULL) 659 if (opts == NULL)
659 goto nla_put_failure; 660 goto nla_put_failure;
660 661
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 2f9883b196e8..909370049fca 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -165,7 +165,8 @@ struct htb_sched {
165 165
166 /* non shaped skbs; let them go directly thru */ 166 /* non shaped skbs; let them go directly thru */
167 struct qdisc_skb_head direct_queue; 167 struct qdisc_skb_head direct_queue;
168 long direct_pkts; 168 u32 direct_pkts;
169 u32 overlimits;
169 170
170 struct qdisc_watchdog watchdog; 171 struct qdisc_watchdog watchdog;
171 172
@@ -533,8 +534,10 @@ htb_change_class_mode(struct htb_sched *q, struct htb_class *cl, s64 *diff)
533 if (new_mode == cl->cmode) 534 if (new_mode == cl->cmode)
534 return; 535 return;
535 536
536 if (new_mode == HTB_CANT_SEND) 537 if (new_mode == HTB_CANT_SEND) {
537 cl->overlimits++; 538 cl->overlimits++;
539 q->overlimits++;
540 }
538 541
539 if (cl->prio_activity) { /* not necessary: speed optimization */ 542 if (cl->prio_activity) { /* not necessary: speed optimization */
540 if (cl->cmode != HTB_CANT_SEND) 543 if (cl->cmode != HTB_CANT_SEND)
@@ -937,7 +940,6 @@ ok:
937 goto ok; 940 goto ok;
938 } 941 }
939 } 942 }
940 qdisc_qstats_overlimit(sch);
941 if (likely(next_event > q->now)) 943 if (likely(next_event > q->now))
942 qdisc_watchdog_schedule_ns(&q->watchdog, next_event); 944 qdisc_watchdog_schedule_ns(&q->watchdog, next_event);
943 else 945 else
@@ -1012,7 +1014,8 @@ static int htb_init(struct Qdisc *sch, struct nlattr *opt,
1012 if (err) 1014 if (err)
1013 return err; 1015 return err;
1014 1016
1015 err = nla_parse_nested(tb, TCA_HTB_MAX, opt, htb_policy, NULL); 1017 err = nla_parse_nested_deprecated(tb, TCA_HTB_MAX, opt, htb_policy,
1018 NULL);
1016 if (err < 0) 1019 if (err < 0)
1017 return err; 1020 return err;
1018 1021
@@ -1047,6 +1050,7 @@ static int htb_dump(struct Qdisc *sch, struct sk_buff *skb)
1047 struct nlattr *nest; 1050 struct nlattr *nest;
1048 struct tc_htb_glob gopt; 1051 struct tc_htb_glob gopt;
1049 1052
1053 sch->qstats.overlimits = q->overlimits;
1050 /* Its safe to not acquire qdisc lock. As we hold RTNL, 1054 /* Its safe to not acquire qdisc lock. As we hold RTNL,
1051 * no change can happen on the qdisc parameters. 1055 * no change can happen on the qdisc parameters.
1052 */ 1056 */
@@ -1057,7 +1061,7 @@ static int htb_dump(struct Qdisc *sch, struct sk_buff *skb)
1057 gopt.defcls = q->defcls; 1061 gopt.defcls = q->defcls;
1058 gopt.debug = 0; 1062 gopt.debug = 0;
1059 1063
1060 nest = nla_nest_start(skb, TCA_OPTIONS); 1064 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
1061 if (nest == NULL) 1065 if (nest == NULL)
1062 goto nla_put_failure; 1066 goto nla_put_failure;
1063 if (nla_put(skb, TCA_HTB_INIT, sizeof(gopt), &gopt) || 1067 if (nla_put(skb, TCA_HTB_INIT, sizeof(gopt), &gopt) ||
@@ -1086,7 +1090,7 @@ static int htb_dump_class(struct Qdisc *sch, unsigned long arg,
1086 if (!cl->level && cl->leaf.q) 1090 if (!cl->level && cl->leaf.q)
1087 tcm->tcm_info = cl->leaf.q->handle; 1091 tcm->tcm_info = cl->leaf.q->handle;
1088 1092
1089 nest = nla_nest_start(skb, TCA_OPTIONS); 1093 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
1090 if (nest == NULL) 1094 if (nest == NULL)
1091 goto nla_put_failure; 1095 goto nla_put_failure;
1092 1096
@@ -1310,7 +1314,8 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1310 if (!opt) 1314 if (!opt)
1311 goto failure; 1315 goto failure;
1312 1316
1313 err = nla_parse_nested(tb, TCA_HTB_MAX, opt, htb_policy, NULL); 1317 err = nla_parse_nested_deprecated(tb, TCA_HTB_MAX, opt, htb_policy,
1318 NULL);
1314 if (err < 0) 1319 if (err < 0)
1315 goto failure; 1320 goto failure;
1316 1321
diff --git a/net/sched/sch_ingress.c b/net/sched/sch_ingress.c
index ce3f55259d0d..0bac926b46c7 100644
--- a/net/sched/sch_ingress.c
+++ b/net/sched/sch_ingress.c
@@ -106,7 +106,7 @@ static int ingress_dump(struct Qdisc *sch, struct sk_buff *skb)
106{ 106{
107 struct nlattr *nest; 107 struct nlattr *nest;
108 108
109 nest = nla_nest_start(skb, TCA_OPTIONS); 109 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
110 if (nest == NULL) 110 if (nest == NULL)
111 goto nla_put_failure; 111 goto nla_put_failure;
112 112
diff --git a/net/sched/sch_mqprio.c b/net/sched/sch_mqprio.c
index ea0dc112b38d..d05086dc3866 100644
--- a/net/sched/sch_mqprio.c
+++ b/net/sched/sch_mqprio.c
@@ -125,8 +125,9 @@ static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
125 int nested_len = nla_len(nla) - NLA_ALIGN(len); 125 int nested_len = nla_len(nla) - NLA_ALIGN(len);
126 126
127 if (nested_len >= nla_attr_size(0)) 127 if (nested_len >= nla_attr_size(0))
128 return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len), 128 return nla_parse_deprecated(tb, maxtype,
129 nested_len, policy, NULL); 129 nla_data(nla) + NLA_ALIGN(len),
130 nested_len, policy, NULL);
130 131
131 memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); 132 memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
132 return 0; 133 return 0;
@@ -349,7 +350,7 @@ static int dump_rates(struct mqprio_sched *priv,
349 int i; 350 int i;
350 351
351 if (priv->flags & TC_MQPRIO_F_MIN_RATE) { 352 if (priv->flags & TC_MQPRIO_F_MIN_RATE) {
352 nest = nla_nest_start(skb, TCA_MQPRIO_MIN_RATE64); 353 nest = nla_nest_start_noflag(skb, TCA_MQPRIO_MIN_RATE64);
353 if (!nest) 354 if (!nest)
354 goto nla_put_failure; 355 goto nla_put_failure;
355 356
@@ -363,7 +364,7 @@ static int dump_rates(struct mqprio_sched *priv,
363 } 364 }
364 365
365 if (priv->flags & TC_MQPRIO_F_MAX_RATE) { 366 if (priv->flags & TC_MQPRIO_F_MAX_RATE) {
366 nest = nla_nest_start(skb, TCA_MQPRIO_MAX_RATE64); 367 nest = nla_nest_start_noflag(skb, TCA_MQPRIO_MAX_RATE64);
367 if (!nest) 368 if (!nest)
368 goto nla_put_failure; 369 goto nla_put_failure;
369 370
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index cc9d8133afcd..78aa76b0da2e 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -935,8 +935,9 @@ static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
935 } 935 }
936 936
937 if (nested_len >= nla_attr_size(0)) 937 if (nested_len >= nla_attr_size(0))
938 return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len), 938 return nla_parse_deprecated(tb, maxtype,
939 nested_len, policy, NULL); 939 nla_data(nla) + NLA_ALIGN(len),
940 nested_len, policy, NULL);
940 941
941 memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); 942 memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
942 return 0; 943 return 0;
@@ -1079,7 +1080,7 @@ static int dump_loss_model(const struct netem_sched_data *q,
1079{ 1080{
1080 struct nlattr *nest; 1081 struct nlattr *nest;
1081 1082
1082 nest = nla_nest_start(skb, TCA_NETEM_LOSS); 1083 nest = nla_nest_start_noflag(skb, TCA_NETEM_LOSS);
1083 if (nest == NULL) 1084 if (nest == NULL)
1084 goto nla_put_failure; 1085 goto nla_put_failure;
1085 1086
diff --git a/net/sched/sch_pie.c b/net/sched/sch_pie.c
index 1cc0c7b74aa3..8fa129d3943e 100644
--- a/net/sched/sch_pie.c
+++ b/net/sched/sch_pie.c
@@ -216,7 +216,8 @@ static int pie_change(struct Qdisc *sch, struct nlattr *opt,
216 if (!opt) 216 if (!opt)
217 return -EINVAL; 217 return -EINVAL;
218 218
219 err = nla_parse_nested(tb, TCA_PIE_MAX, opt, pie_policy, NULL); 219 err = nla_parse_nested_deprecated(tb, TCA_PIE_MAX, opt, pie_policy,
220 NULL);
220 if (err < 0) 221 if (err < 0)
221 return err; 222 return err;
222 223
@@ -491,7 +492,7 @@ static int pie_dump(struct Qdisc *sch, struct sk_buff *skb)
491 struct pie_sched_data *q = qdisc_priv(sch); 492 struct pie_sched_data *q = qdisc_priv(sch);
492 struct nlattr *opts; 493 struct nlattr *opts;
493 494
494 opts = nla_nest_start(skb, TCA_OPTIONS); 495 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
495 if (!opts) 496 if (!opts)
496 goto nla_put_failure; 497 goto nla_put_failure;
497 498
diff --git a/net/sched/sch_qfq.c b/net/sched/sch_qfq.c
index 1589364b54da..3f9e8b425ac6 100644
--- a/net/sched/sch_qfq.c
+++ b/net/sched/sch_qfq.c
@@ -410,8 +410,8 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
410 return -EINVAL; 410 return -EINVAL;
411 } 411 }
412 412
413 err = nla_parse_nested(tb, TCA_QFQ_MAX, tca[TCA_OPTIONS], qfq_policy, 413 err = nla_parse_nested_deprecated(tb, TCA_QFQ_MAX, tca[TCA_OPTIONS],
414 NULL); 414 qfq_policy, NULL);
415 if (err < 0) 415 if (err < 0)
416 return err; 416 return err;
417 417
@@ -619,7 +619,7 @@ static int qfq_dump_class(struct Qdisc *sch, unsigned long arg,
619 tcm->tcm_handle = cl->common.classid; 619 tcm->tcm_handle = cl->common.classid;
620 tcm->tcm_info = cl->qdisc->handle; 620 tcm->tcm_info = cl->qdisc->handle;
621 621
622 nest = nla_nest_start(skb, TCA_OPTIONS); 622 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
623 if (nest == NULL) 623 if (nest == NULL)
624 goto nla_put_failure; 624 goto nla_put_failure;
625 if (nla_put_u32(skb, TCA_QFQ_WEIGHT, cl->agg->class_weight) || 625 if (nla_put_u32(skb, TCA_QFQ_WEIGHT, cl->agg->class_weight) ||
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index 4e8c0abf6194..1e68a13bb66b 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -205,7 +205,8 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt,
205 if (opt == NULL) 205 if (opt == NULL)
206 return -EINVAL; 206 return -EINVAL;
207 207
208 err = nla_parse_nested(tb, TCA_RED_MAX, opt, red_policy, NULL); 208 err = nla_parse_nested_deprecated(tb, TCA_RED_MAX, opt, red_policy,
209 NULL);
209 if (err < 0) 210 if (err < 0)
210 return err; 211 return err;
211 212
@@ -318,7 +319,7 @@ static int red_dump(struct Qdisc *sch, struct sk_buff *skb)
318 if (err) 319 if (err)
319 goto nla_put_failure; 320 goto nla_put_failure;
320 321
321 opts = nla_nest_start(skb, TCA_OPTIONS); 322 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
322 if (opts == NULL) 323 if (opts == NULL)
323 goto nla_put_failure; 324 goto nla_put_failure;
324 if (nla_put(skb, TCA_RED_PARMS, sizeof(opt), &opt) || 325 if (nla_put(skb, TCA_RED_PARMS, sizeof(opt), &opt) ||
diff --git a/net/sched/sch_sfb.c b/net/sched/sch_sfb.c
index 2419fdb75966..b245d6a2068d 100644
--- a/net/sched/sch_sfb.c
+++ b/net/sched/sch_sfb.c
@@ -499,7 +499,8 @@ static int sfb_change(struct Qdisc *sch, struct nlattr *opt,
499 int err; 499 int err;
500 500
501 if (opt) { 501 if (opt) {
502 err = nla_parse_nested(tb, TCA_SFB_MAX, opt, sfb_policy, NULL); 502 err = nla_parse_nested_deprecated(tb, TCA_SFB_MAX, opt,
503 sfb_policy, NULL);
503 if (err < 0) 504 if (err < 0)
504 return -EINVAL; 505 return -EINVAL;
505 506
@@ -580,7 +581,7 @@ static int sfb_dump(struct Qdisc *sch, struct sk_buff *skb)
580 }; 581 };
581 582
582 sch->qstats.backlog = q->qdisc->qstats.backlog; 583 sch->qstats.backlog = q->qdisc->qstats.backlog;
583 opts = nla_nest_start(skb, TCA_OPTIONS); 584 opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
584 if (opts == NULL) 585 if (opts == NULL)
585 goto nla_put_failure; 586 goto nla_put_failure;
586 if (nla_put(skb, TCA_SFB_PARMS, sizeof(opt), &opt)) 587 if (nla_put(skb, TCA_SFB_PARMS, sizeof(opt), &opt))
diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index c7041999eb5d..9ecfb8f5902a 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -13,13 +13,18 @@
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/errno.h> 14#include <linux/errno.h>
15#include <linux/skbuff.h> 15#include <linux/skbuff.h>
16#include <linux/math64.h>
16#include <linux/module.h> 17#include <linux/module.h>
17#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19#include <linux/rcupdate.h>
18#include <net/netlink.h> 20#include <net/netlink.h>
19#include <net/pkt_sched.h> 21#include <net/pkt_sched.h>
20#include <net/pkt_cls.h> 22#include <net/pkt_cls.h>
21#include <net/sch_generic.h> 23#include <net/sch_generic.h>
22 24
25static LIST_HEAD(taprio_list);
26static DEFINE_SPINLOCK(taprio_list_lock);
27
23#define TAPRIO_ALL_GATES_OPEN -1 28#define TAPRIO_ALL_GATES_OPEN -1
24 29
25struct sched_entry { 30struct sched_entry {
@@ -37,24 +42,88 @@ struct sched_entry {
37 u8 command; 42 u8 command;
38}; 43};
39 44
45struct sched_gate_list {
46 struct rcu_head rcu;
47 struct list_head entries;
48 size_t num_entries;
49 ktime_t cycle_close_time;
50 s64 cycle_time;
51 s64 cycle_time_extension;
52 s64 base_time;
53};
54
40struct taprio_sched { 55struct taprio_sched {
41 struct Qdisc **qdiscs; 56 struct Qdisc **qdiscs;
42 struct Qdisc *root; 57 struct Qdisc *root;
43 s64 base_time;
44 int clockid; 58 int clockid;
45 int picos_per_byte; /* Using picoseconds because for 10Gbps+ 59 atomic64_t picos_per_byte; /* Using picoseconds because for 10Gbps+
46 * speeds it's sub-nanoseconds per byte 60 * speeds it's sub-nanoseconds per byte
47 */ 61 */
48 size_t num_entries;
49 62
50 /* Protects the update side of the RCU protected current_entry */ 63 /* Protects the update side of the RCU protected current_entry */
51 spinlock_t current_entry_lock; 64 spinlock_t current_entry_lock;
52 struct sched_entry __rcu *current_entry; 65 struct sched_entry __rcu *current_entry;
53 struct list_head entries; 66 struct sched_gate_list __rcu *oper_sched;
67 struct sched_gate_list __rcu *admin_sched;
54 ktime_t (*get_time)(void); 68 ktime_t (*get_time)(void);
55 struct hrtimer advance_timer; 69 struct hrtimer advance_timer;
70 struct list_head taprio_list;
56}; 71};
57 72
73static ktime_t sched_base_time(const struct sched_gate_list *sched)
74{
75 if (!sched)
76 return KTIME_MAX;
77
78 return ns_to_ktime(sched->base_time);
79}
80
81static void taprio_free_sched_cb(struct rcu_head *head)
82{
83 struct sched_gate_list *sched = container_of(head, struct sched_gate_list, rcu);
84 struct sched_entry *entry, *n;
85
86 if (!sched)
87 return;
88
89 list_for_each_entry_safe(entry, n, &sched->entries, list) {
90 list_del(&entry->list);
91 kfree(entry);
92 }
93
94 kfree(sched);
95}
96
97static void switch_schedules(struct taprio_sched *q,
98 struct sched_gate_list **admin,
99 struct sched_gate_list **oper)
100{
101 rcu_assign_pointer(q->oper_sched, *admin);
102 rcu_assign_pointer(q->admin_sched, NULL);
103
104 if (*oper)
105 call_rcu(&(*oper)->rcu, taprio_free_sched_cb);
106
107 *oper = *admin;
108 *admin = NULL;
109}
110
111static ktime_t get_cycle_time(struct sched_gate_list *sched)
112{
113 struct sched_entry *entry;
114 ktime_t cycle = 0;
115
116 if (sched->cycle_time != 0)
117 return sched->cycle_time;
118
119 list_for_each_entry(entry, &sched->entries, list)
120 cycle = ktime_add_ns(cycle, entry->interval);
121
122 sched->cycle_time = cycle;
123
124 return cycle;
125}
126
58static int taprio_enqueue(struct sk_buff *skb, struct Qdisc *sch, 127static int taprio_enqueue(struct sk_buff *skb, struct Qdisc *sch,
59 struct sk_buff **to_free) 128 struct sk_buff **to_free)
60{ 129{
@@ -85,7 +154,7 @@ static struct sk_buff *taprio_peek(struct Qdisc *sch)
85 154
86 rcu_read_lock(); 155 rcu_read_lock();
87 entry = rcu_dereference(q->current_entry); 156 entry = rcu_dereference(q->current_entry);
88 gate_mask = entry ? entry->gate_mask : -1; 157 gate_mask = entry ? entry->gate_mask : TAPRIO_ALL_GATES_OPEN;
89 rcu_read_unlock(); 158 rcu_read_unlock();
90 159
91 if (!gate_mask) 160 if (!gate_mask)
@@ -107,7 +176,7 @@ static struct sk_buff *taprio_peek(struct Qdisc *sch)
107 tc = netdev_get_prio_tc_map(dev, prio); 176 tc = netdev_get_prio_tc_map(dev, prio);
108 177
109 if (!(gate_mask & BIT(tc))) 178 if (!(gate_mask & BIT(tc)))
110 return NULL; 179 continue;
111 180
112 return skb; 181 return skb;
113 } 182 }
@@ -117,18 +186,30 @@ static struct sk_buff *taprio_peek(struct Qdisc *sch)
117 186
118static inline int length_to_duration(struct taprio_sched *q, int len) 187static inline int length_to_duration(struct taprio_sched *q, int len)
119{ 188{
120 return (len * q->picos_per_byte) / 1000; 189 return div_u64(len * atomic64_read(&q->picos_per_byte), 1000);
190}
191
192static void taprio_set_budget(struct taprio_sched *q, struct sched_entry *entry)
193{
194 atomic_set(&entry->budget,
195 div64_u64((u64)entry->interval * 1000,
196 atomic64_read(&q->picos_per_byte)));
121} 197}
122 198
123static struct sk_buff *taprio_dequeue(struct Qdisc *sch) 199static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
124{ 200{
125 struct taprio_sched *q = qdisc_priv(sch); 201 struct taprio_sched *q = qdisc_priv(sch);
126 struct net_device *dev = qdisc_dev(sch); 202 struct net_device *dev = qdisc_dev(sch);
203 struct sk_buff *skb = NULL;
127 struct sched_entry *entry; 204 struct sched_entry *entry;
128 struct sk_buff *skb;
129 u32 gate_mask; 205 u32 gate_mask;
130 int i; 206 int i;
131 207
208 if (atomic64_read(&q->picos_per_byte) == -1) {
209 WARN_ONCE(1, "taprio: dequeue() called with unknown picos per byte.");
210 return NULL;
211 }
212
132 rcu_read_lock(); 213 rcu_read_lock();
133 entry = rcu_dereference(q->current_entry); 214 entry = rcu_dereference(q->current_entry);
134 /* if there's no entry, it means that the schedule didn't 215 /* if there's no entry, it means that the schedule didn't
@@ -137,10 +218,9 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
137 * "AdminGateSates" 218 * "AdminGateSates"
138 */ 219 */
139 gate_mask = entry ? entry->gate_mask : TAPRIO_ALL_GATES_OPEN; 220 gate_mask = entry ? entry->gate_mask : TAPRIO_ALL_GATES_OPEN;
140 rcu_read_unlock();
141 221
142 if (!gate_mask) 222 if (!gate_mask)
143 return NULL; 223 goto done;
144 224
145 for (i = 0; i < dev->num_tx_queues; i++) { 225 for (i = 0; i < dev->num_tx_queues; i++) {
146 struct Qdisc *child = q->qdiscs[i]; 226 struct Qdisc *child = q->qdiscs[i];
@@ -171,39 +251,81 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
171 */ 251 */
172 if (gate_mask != TAPRIO_ALL_GATES_OPEN && 252 if (gate_mask != TAPRIO_ALL_GATES_OPEN &&
173 ktime_after(guard, entry->close_time)) 253 ktime_after(guard, entry->close_time))
174 return NULL; 254 continue;
175 255
176 /* ... and no budget. */ 256 /* ... and no budget. */
177 if (gate_mask != TAPRIO_ALL_GATES_OPEN && 257 if (gate_mask != TAPRIO_ALL_GATES_OPEN &&
178 atomic_sub_return(len, &entry->budget) < 0) 258 atomic_sub_return(len, &entry->budget) < 0)
179 return NULL; 259 continue;
180 260
181 skb = child->ops->dequeue(child); 261 skb = child->ops->dequeue(child);
182 if (unlikely(!skb)) 262 if (unlikely(!skb))
183 return NULL; 263 goto done;
184 264
185 qdisc_bstats_update(sch, skb); 265 qdisc_bstats_update(sch, skb);
186 qdisc_qstats_backlog_dec(sch, skb); 266 qdisc_qstats_backlog_dec(sch, skb);
187 sch->q.qlen--; 267 sch->q.qlen--;
188 268
189 return skb; 269 goto done;
190 } 270 }
191 271
192 return NULL; 272done:
273 rcu_read_unlock();
274
275 return skb;
193} 276}
194 277
195static bool should_restart_cycle(const struct taprio_sched *q, 278static bool should_restart_cycle(const struct sched_gate_list *oper,
196 const struct sched_entry *entry) 279 const struct sched_entry *entry)
197{ 280{
198 WARN_ON(!entry); 281 if (list_is_last(&entry->list, &oper->entries))
282 return true;
283
284 if (ktime_compare(entry->close_time, oper->cycle_close_time) == 0)
285 return true;
286
287 return false;
288}
289
290static bool should_change_schedules(const struct sched_gate_list *admin,
291 const struct sched_gate_list *oper,
292 ktime_t close_time)
293{
294 ktime_t next_base_time, extension_time;
295
296 if (!admin)
297 return false;
199 298
200 return list_is_last(&entry->list, &q->entries); 299 next_base_time = sched_base_time(admin);
300
301 /* This is the simple case, the close_time would fall after
302 * the next schedule base_time.
303 */
304 if (ktime_compare(next_base_time, close_time) <= 0)
305 return true;
306
307 /* This is the cycle_time_extension case, if the close_time
308 * plus the amount that can be extended would fall after the
309 * next schedule base_time, we can extend the current schedule
310 * for that amount.
311 */
312 extension_time = ktime_add_ns(close_time, oper->cycle_time_extension);
313
314 /* FIXME: the IEEE 802.1Q-2018 Specification isn't clear about
315 * how precisely the extension should be made. So after
316 * conformance testing, this logic may change.
317 */
318 if (ktime_compare(next_base_time, extension_time) <= 0)
319 return true;
320
321 return false;
201} 322}
202 323
203static enum hrtimer_restart advance_sched(struct hrtimer *timer) 324static enum hrtimer_restart advance_sched(struct hrtimer *timer)
204{ 325{
205 struct taprio_sched *q = container_of(timer, struct taprio_sched, 326 struct taprio_sched *q = container_of(timer, struct taprio_sched,
206 advance_timer); 327 advance_timer);
328 struct sched_gate_list *oper, *admin;
207 struct sched_entry *entry, *next; 329 struct sched_entry *entry, *next;
208 struct Qdisc *sch = q->root; 330 struct Qdisc *sch = q->root;
209 ktime_t close_time; 331 ktime_t close_time;
@@ -211,29 +333,49 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer)
211 spin_lock(&q->current_entry_lock); 333 spin_lock(&q->current_entry_lock);
212 entry = rcu_dereference_protected(q->current_entry, 334 entry = rcu_dereference_protected(q->current_entry,
213 lockdep_is_held(&q->current_entry_lock)); 335 lockdep_is_held(&q->current_entry_lock));
336 oper = rcu_dereference_protected(q->oper_sched,
337 lockdep_is_held(&q->current_entry_lock));
338 admin = rcu_dereference_protected(q->admin_sched,
339 lockdep_is_held(&q->current_entry_lock));
214 340
215 /* This is the case that it's the first time that the schedule 341 if (!oper)
216 * runs, so it only happens once per schedule. The first entry 342 switch_schedules(q, &admin, &oper);
217 * is pre-calculated during the schedule initialization. 343
344 /* This can happen in two cases: 1. this is the very first run
345 * of this function (i.e. we weren't running any schedule
346 * previously); 2. The previous schedule just ended. The first
347 * entry of all schedules are pre-calculated during the
348 * schedule initialization.
218 */ 349 */
219 if (unlikely(!entry)) { 350 if (unlikely(!entry || entry->close_time == oper->base_time)) {
220 next = list_first_entry(&q->entries, struct sched_entry, 351 next = list_first_entry(&oper->entries, struct sched_entry,
221 list); 352 list);
222 close_time = next->close_time; 353 close_time = next->close_time;
223 goto first_run; 354 goto first_run;
224 } 355 }
225 356
226 if (should_restart_cycle(q, entry)) 357 if (should_restart_cycle(oper, entry)) {
227 next = list_first_entry(&q->entries, struct sched_entry, 358 next = list_first_entry(&oper->entries, struct sched_entry,
228 list); 359 list);
229 else 360 oper->cycle_close_time = ktime_add_ns(oper->cycle_close_time,
361 oper->cycle_time);
362 } else {
230 next = list_next_entry(entry, list); 363 next = list_next_entry(entry, list);
364 }
231 365
232 close_time = ktime_add_ns(entry->close_time, next->interval); 366 close_time = ktime_add_ns(entry->close_time, next->interval);
367 close_time = min_t(ktime_t, close_time, oper->cycle_close_time);
368
369 if (should_change_schedules(admin, oper, close_time)) {
370 /* Set things so the next time this runs, the new
371 * schedule runs.
372 */
373 close_time = sched_base_time(admin);
374 switch_schedules(q, &admin, &oper);
375 }
233 376
234 next->close_time = close_time; 377 next->close_time = close_time;
235 atomic_set(&next->budget, 378 taprio_set_budget(q, next);
236 (next->interval * 1000) / q->picos_per_byte);
237 379
238first_run: 380first_run:
239 rcu_assign_pointer(q->current_entry, next); 381 rcu_assign_pointer(q->current_entry, next);
@@ -263,10 +405,12 @@ static const struct nla_policy taprio_policy[TCA_TAPRIO_ATTR_MAX + 1] = {
263 [TCA_TAPRIO_ATTR_PRIOMAP] = { 405 [TCA_TAPRIO_ATTR_PRIOMAP] = {
264 .len = sizeof(struct tc_mqprio_qopt) 406 .len = sizeof(struct tc_mqprio_qopt)
265 }, 407 },
266 [TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST] = { .type = NLA_NESTED }, 408 [TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST] = { .type = NLA_NESTED },
267 [TCA_TAPRIO_ATTR_SCHED_BASE_TIME] = { .type = NLA_S64 }, 409 [TCA_TAPRIO_ATTR_SCHED_BASE_TIME] = { .type = NLA_S64 },
268 [TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY] = { .type = NLA_NESTED }, 410 [TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY] = { .type = NLA_NESTED },
269 [TCA_TAPRIO_ATTR_SCHED_CLOCKID] = { .type = NLA_S32 }, 411 [TCA_TAPRIO_ATTR_SCHED_CLOCKID] = { .type = NLA_S32 },
412 [TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME] = { .type = NLA_S64 },
413 [TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION] = { .type = NLA_S64 },
270}; 414};
271 415
272static int fill_sched_entry(struct nlattr **tb, struct sched_entry *entry, 416static int fill_sched_entry(struct nlattr **tb, struct sched_entry *entry,
@@ -302,8 +446,8 @@ static int parse_sched_entry(struct nlattr *n, struct sched_entry *entry,
302 struct nlattr *tb[TCA_TAPRIO_SCHED_ENTRY_MAX + 1] = { }; 446 struct nlattr *tb[TCA_TAPRIO_SCHED_ENTRY_MAX + 1] = { };
303 int err; 447 int err;
304 448
305 err = nla_parse_nested(tb, TCA_TAPRIO_SCHED_ENTRY_MAX, n, 449 err = nla_parse_nested_deprecated(tb, TCA_TAPRIO_SCHED_ENTRY_MAX, n,
306 entry_policy, NULL); 450 entry_policy, NULL);
307 if (err < 0) { 451 if (err < 0) {
308 NL_SET_ERR_MSG(extack, "Could not parse nested entry"); 452 NL_SET_ERR_MSG(extack, "Could not parse nested entry");
309 return -EINVAL; 453 return -EINVAL;
@@ -314,70 +458,8 @@ static int parse_sched_entry(struct nlattr *n, struct sched_entry *entry,
314 return fill_sched_entry(tb, entry, extack); 458 return fill_sched_entry(tb, entry, extack);
315} 459}
316 460
317/* Returns the number of entries in case of success */
318static int parse_sched_single_entry(struct nlattr *n,
319 struct taprio_sched *q,
320 struct netlink_ext_ack *extack)
321{
322 struct nlattr *tb_entry[TCA_TAPRIO_SCHED_ENTRY_MAX + 1] = { };
323 struct nlattr *tb_list[TCA_TAPRIO_SCHED_MAX + 1] = { };
324 struct sched_entry *entry;
325 bool found = false;
326 u32 index;
327 int err;
328
329 err = nla_parse_nested(tb_list, TCA_TAPRIO_SCHED_MAX,
330 n, entry_list_policy, NULL);
331 if (err < 0) {
332 NL_SET_ERR_MSG(extack, "Could not parse nested entry");
333 return -EINVAL;
334 }
335
336 if (!tb_list[TCA_TAPRIO_SCHED_ENTRY]) {
337 NL_SET_ERR_MSG(extack, "Single-entry must include an entry");
338 return -EINVAL;
339 }
340
341 err = nla_parse_nested(tb_entry, TCA_TAPRIO_SCHED_ENTRY_MAX,
342 tb_list[TCA_TAPRIO_SCHED_ENTRY],
343 entry_policy, NULL);
344 if (err < 0) {
345 NL_SET_ERR_MSG(extack, "Could not parse nested entry");
346 return -EINVAL;
347 }
348
349 if (!tb_entry[TCA_TAPRIO_SCHED_ENTRY_INDEX]) {
350 NL_SET_ERR_MSG(extack, "Entry must specify an index\n");
351 return -EINVAL;
352 }
353
354 index = nla_get_u32(tb_entry[TCA_TAPRIO_SCHED_ENTRY_INDEX]);
355 if (index >= q->num_entries) {
356 NL_SET_ERR_MSG(extack, "Index for single entry exceeds number of entries in schedule");
357 return -EINVAL;
358 }
359
360 list_for_each_entry(entry, &q->entries, list) {
361 if (entry->index == index) {
362 found = true;
363 break;
364 }
365 }
366
367 if (!found) {
368 NL_SET_ERR_MSG(extack, "Could not find entry");
369 return -ENOENT;
370 }
371
372 err = fill_sched_entry(tb_entry, entry, extack);
373 if (err < 0)
374 return err;
375
376 return q->num_entries;
377}
378
379static int parse_sched_list(struct nlattr *list, 461static int parse_sched_list(struct nlattr *list,
380 struct taprio_sched *q, 462 struct sched_gate_list *sched,
381 struct netlink_ext_ack *extack) 463 struct netlink_ext_ack *extack)
382{ 464{
383 struct nlattr *n; 465 struct nlattr *n;
@@ -407,64 +489,42 @@ static int parse_sched_list(struct nlattr *list,
407 return err; 489 return err;
408 } 490 }
409 491
410 list_add_tail(&entry->list, &q->entries); 492 list_add_tail(&entry->list, &sched->entries);
411 i++; 493 i++;
412 } 494 }
413 495
414 q->num_entries = i; 496 sched->num_entries = i;
415 497
416 return i; 498 return i;
417} 499}
418 500
419/* Returns the number of entries in case of success */ 501static int parse_taprio_schedule(struct nlattr **tb,
420static int parse_taprio_opt(struct nlattr **tb, struct taprio_sched *q, 502 struct sched_gate_list *new,
421 struct netlink_ext_ack *extack) 503 struct netlink_ext_ack *extack)
422{ 504{
423 int err = 0; 505 int err = 0;
424 int clockid;
425 506
426 if (tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST] && 507 if (tb[TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY]) {
427 tb[TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY]) 508 NL_SET_ERR_MSG(extack, "Adding a single entry is not supported");
428 return -EINVAL; 509 return -ENOTSUPP;
429 510 }
430 if (tb[TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY] && q->num_entries == 0)
431 return -EINVAL;
432
433 if (q->clockid == -1 && !tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID])
434 return -EINVAL;
435 511
436 if (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME]) 512 if (tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME])
437 q->base_time = nla_get_s64( 513 new->base_time = nla_get_s64(tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME]);
438 tb[TCA_TAPRIO_ATTR_SCHED_BASE_TIME]);
439 514
440 if (tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]) { 515 if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION])
441 clockid = nla_get_s32(tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]); 516 new->cycle_time_extension = nla_get_s64(tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION]);
442 517
443 /* We only support static clockids and we don't allow 518 if (tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME])
444 * for it to be modified after the first init. 519 new->cycle_time = nla_get_s64(tb[TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME]);
445 */
446 if (clockid < 0 || (q->clockid != -1 && q->clockid != clockid))
447 return -EINVAL;
448
449 q->clockid = clockid;
450 }
451 520
452 if (tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST]) 521 if (tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST])
453 err = parse_sched_list( 522 err = parse_sched_list(
454 tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST], q, extack); 523 tb[TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST], new, extack);
455 else if (tb[TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY]) 524 if (err < 0)
456 err = parse_sched_single_entry( 525 return err;
457 tb[TCA_TAPRIO_ATTR_SCHED_SINGLE_ENTRY], q, extack);
458
459 /* parse_sched_* return the number of entries in the schedule,
460 * a schedule with zero entries is an error.
461 */
462 if (err == 0) {
463 NL_SET_ERR_MSG(extack, "The schedule should contain at least one entry");
464 return -EINVAL;
465 }
466 526
467 return err; 527 return 0;
468} 528}
469 529
470static int taprio_parse_mqprio_opt(struct net_device *dev, 530static int taprio_parse_mqprio_opt(struct net_device *dev,
@@ -473,11 +533,17 @@ static int taprio_parse_mqprio_opt(struct net_device *dev,
473{ 533{
474 int i, j; 534 int i, j;
475 535
476 if (!qopt) { 536 if (!qopt && !dev->num_tc) {
477 NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary"); 537 NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary");
478 return -EINVAL; 538 return -EINVAL;
479 } 539 }
480 540
541 /* If num_tc is already set, it means that the user already
542 * configured the mqprio part
543 */
544 if (dev->num_tc)
545 return 0;
546
481 /* Verify num_tc is not out of max range */ 547 /* Verify num_tc is not out of max range */
482 if (qopt->num_tc > TC_MAX_QUEUE) { 548 if (qopt->num_tc > TC_MAX_QUEUE) {
483 NL_SET_ERR_MSG(extack, "Number of traffic classes is outside valid range"); 549 NL_SET_ERR_MSG(extack, "Number of traffic classes is outside valid range");
@@ -523,76 +589,141 @@ static int taprio_parse_mqprio_opt(struct net_device *dev,
523 return 0; 589 return 0;
524} 590}
525 591
526static ktime_t taprio_get_start_time(struct Qdisc *sch) 592static int taprio_get_start_time(struct Qdisc *sch,
593 struct sched_gate_list *sched,
594 ktime_t *start)
527{ 595{
528 struct taprio_sched *q = qdisc_priv(sch); 596 struct taprio_sched *q = qdisc_priv(sch);
529 struct sched_entry *entry;
530 ktime_t now, base, cycle; 597 ktime_t now, base, cycle;
531 s64 n; 598 s64 n;
532 599
533 base = ns_to_ktime(q->base_time); 600 base = sched_base_time(sched);
534 cycle = 0; 601 now = q->get_time();
535
536 /* Calculate the cycle_time, by summing all the intervals.
537 */
538 list_for_each_entry(entry, &q->entries, list)
539 cycle = ktime_add_ns(cycle, entry->interval);
540 602
541 if (!cycle) 603 if (ktime_after(base, now)) {
542 return base; 604 *start = base;
605 return 0;
606 }
543 607
544 now = q->get_time(); 608 cycle = get_cycle_time(sched);
545 609
546 if (ktime_after(base, now)) 610 /* The qdisc is expected to have at least one sched_entry. Moreover,
547 return base; 611 * any entry must have 'interval' > 0. Thus if the cycle time is zero,
612 * something went really wrong. In that case, we should warn about this
613 * inconsistent state and return error.
614 */
615 if (WARN_ON(!cycle))
616 return -EFAULT;
548 617
549 /* Schedule the start time for the beginning of the next 618 /* Schedule the start time for the beginning of the next
550 * cycle. 619 * cycle.
551 */ 620 */
552 n = div64_s64(ktime_sub_ns(now, base), cycle); 621 n = div64_s64(ktime_sub_ns(now, base), cycle);
553 622 *start = ktime_add_ns(base, (n + 1) * cycle);
554 return ktime_add_ns(base, (n + 1) * cycle); 623 return 0;
555} 624}
556 625
557static void taprio_start_sched(struct Qdisc *sch, ktime_t start) 626static void setup_first_close_time(struct taprio_sched *q,
627 struct sched_gate_list *sched, ktime_t base)
558{ 628{
559 struct taprio_sched *q = qdisc_priv(sch);
560 struct sched_entry *first; 629 struct sched_entry *first;
561 unsigned long flags; 630 ktime_t cycle;
562 631
563 spin_lock_irqsave(&q->current_entry_lock, flags); 632 first = list_first_entry(&sched->entries,
633 struct sched_entry, list);
634
635 cycle = get_cycle_time(sched);
564 636
565 first = list_first_entry(&q->entries, struct sched_entry, 637 /* FIXME: find a better place to do this */
566 list); 638 sched->cycle_close_time = ktime_add_ns(base, cycle);
567 639
568 first->close_time = ktime_add_ns(start, first->interval); 640 first->close_time = ktime_add_ns(base, first->interval);
569 atomic_set(&first->budget, 641 taprio_set_budget(q, first);
570 (first->interval * 1000) / q->picos_per_byte);
571 rcu_assign_pointer(q->current_entry, NULL); 642 rcu_assign_pointer(q->current_entry, NULL);
643}
572 644
573 spin_unlock_irqrestore(&q->current_entry_lock, flags); 645static void taprio_start_sched(struct Qdisc *sch,
646 ktime_t start, struct sched_gate_list *new)
647{
648 struct taprio_sched *q = qdisc_priv(sch);
649 ktime_t expires;
650
651 expires = hrtimer_get_expires(&q->advance_timer);
652 if (expires == 0)
653 expires = KTIME_MAX;
654
655 /* If the new schedule starts before the next expiration, we
656 * reprogram it to the earliest one, so we change the admin
657 * schedule to the operational one at the right time.
658 */
659 start = min_t(ktime_t, start, expires);
574 660
575 hrtimer_start(&q->advance_timer, start, HRTIMER_MODE_ABS); 661 hrtimer_start(&q->advance_timer, start, HRTIMER_MODE_ABS);
576} 662}
577 663
664static void taprio_set_picos_per_byte(struct net_device *dev,
665 struct taprio_sched *q)
666{
667 struct ethtool_link_ksettings ecmd;
668 int picos_per_byte = -1;
669
670 if (!__ethtool_get_link_ksettings(dev, &ecmd) &&
671 ecmd.base.speed != SPEED_UNKNOWN)
672 picos_per_byte = div64_s64(NSEC_PER_SEC * 1000LL * 8,
673 ecmd.base.speed * 1000 * 1000);
674
675 atomic64_set(&q->picos_per_byte, picos_per_byte);
676 netdev_dbg(dev, "taprio: set %s's picos_per_byte to: %lld, linkspeed: %d\n",
677 dev->name, (long long)atomic64_read(&q->picos_per_byte),
678 ecmd.base.speed);
679}
680
681static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event,
682 void *ptr)
683{
684 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
685 struct net_device *qdev;
686 struct taprio_sched *q;
687 bool found = false;
688
689 ASSERT_RTNL();
690
691 if (event != NETDEV_UP && event != NETDEV_CHANGE)
692 return NOTIFY_DONE;
693
694 spin_lock(&taprio_list_lock);
695 list_for_each_entry(q, &taprio_list, taprio_list) {
696 qdev = qdisc_dev(q->root);
697 if (qdev == dev) {
698 found = true;
699 break;
700 }
701 }
702 spin_unlock(&taprio_list_lock);
703
704 if (found)
705 taprio_set_picos_per_byte(dev, q);
706
707 return NOTIFY_DONE;
708}
709
578static int taprio_change(struct Qdisc *sch, struct nlattr *opt, 710static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
579 struct netlink_ext_ack *extack) 711 struct netlink_ext_ack *extack)
580{ 712{
581 struct nlattr *tb[TCA_TAPRIO_ATTR_MAX + 1] = { }; 713 struct nlattr *tb[TCA_TAPRIO_ATTR_MAX + 1] = { };
714 struct sched_gate_list *oper, *admin, *new_admin;
582 struct taprio_sched *q = qdisc_priv(sch); 715 struct taprio_sched *q = qdisc_priv(sch);
583 struct net_device *dev = qdisc_dev(sch); 716 struct net_device *dev = qdisc_dev(sch);
584 struct tc_mqprio_qopt *mqprio = NULL; 717 struct tc_mqprio_qopt *mqprio = NULL;
585 struct ethtool_link_ksettings ecmd; 718 int i, err, clockid;
586 int i, err, size; 719 unsigned long flags;
587 s64 link_speed;
588 ktime_t start; 720 ktime_t start;
589 721
590 err = nla_parse_nested(tb, TCA_TAPRIO_ATTR_MAX, opt, 722 err = nla_parse_nested_deprecated(tb, TCA_TAPRIO_ATTR_MAX, opt,
591 taprio_policy, extack); 723 taprio_policy, extack);
592 if (err < 0) 724 if (err < 0)
593 return err; 725 return err;
594 726
595 err = -EINVAL;
596 if (tb[TCA_TAPRIO_ATTR_PRIOMAP]) 727 if (tb[TCA_TAPRIO_ATTR_PRIOMAP])
597 mqprio = nla_data(tb[TCA_TAPRIO_ATTR_PRIOMAP]); 728 mqprio = nla_data(tb[TCA_TAPRIO_ATTR_PRIOMAP]);
598 729
@@ -600,13 +731,78 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
600 if (err < 0) 731 if (err < 0)
601 return err; 732 return err;
602 733
603 /* A schedule with less than one entry is an error */ 734 new_admin = kzalloc(sizeof(*new_admin), GFP_KERNEL);
604 size = parse_taprio_opt(tb, q, extack); 735 if (!new_admin) {
605 if (size < 0) 736 NL_SET_ERR_MSG(extack, "Not enough memory for a new schedule");
606 return size; 737 return -ENOMEM;
738 }
739 INIT_LIST_HEAD(&new_admin->entries);
607 740
608 hrtimer_init(&q->advance_timer, q->clockid, HRTIMER_MODE_ABS); 741 rcu_read_lock();
609 q->advance_timer.function = advance_sched; 742 oper = rcu_dereference(q->oper_sched);
743 admin = rcu_dereference(q->admin_sched);
744 rcu_read_unlock();
745
746 if (mqprio && (oper || admin)) {
747 NL_SET_ERR_MSG(extack, "Changing the traffic mapping of a running schedule is not supported");
748 err = -ENOTSUPP;
749 goto free_sched;
750 }
751
752 err = parse_taprio_schedule(tb, new_admin, extack);
753 if (err < 0)
754 goto free_sched;
755
756 if (new_admin->num_entries == 0) {
757 NL_SET_ERR_MSG(extack, "There should be at least one entry in the schedule");
758 err = -EINVAL;
759 goto free_sched;
760 }
761
762 if (tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]) {
763 clockid = nla_get_s32(tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]);
764
765 /* We only support static clockids and we don't allow
766 * for it to be modified after the first init.
767 */
768 if (clockid < 0 ||
769 (q->clockid != -1 && q->clockid != clockid)) {
770 NL_SET_ERR_MSG(extack, "Changing the 'clockid' of a running schedule is not supported");
771 err = -ENOTSUPP;
772 goto free_sched;
773 }
774
775 q->clockid = clockid;
776 }
777
778 if (q->clockid == -1 && !tb[TCA_TAPRIO_ATTR_SCHED_CLOCKID]) {
779 NL_SET_ERR_MSG(extack, "Specifying a 'clockid' is mandatory");
780 err = -EINVAL;
781 goto free_sched;
782 }
783
784 taprio_set_picos_per_byte(dev, q);
785
786 /* Protects against enqueue()/dequeue() */
787 spin_lock_bh(qdisc_lock(sch));
788
789 if (!hrtimer_active(&q->advance_timer)) {
790 hrtimer_init(&q->advance_timer, q->clockid, HRTIMER_MODE_ABS);
791 q->advance_timer.function = advance_sched;
792 }
793
794 if (mqprio) {
795 netdev_set_num_tc(dev, mqprio->num_tc);
796 for (i = 0; i < mqprio->num_tc; i++)
797 netdev_set_tc_queue(dev, i,
798 mqprio->count[i],
799 mqprio->offset[i]);
800
801 /* Always use supplied priority mappings */
802 for (i = 0; i < TC_BITMASK + 1; i++)
803 netdev_set_prio_tc_map(dev, i,
804 mqprio->prio_tc_map[i]);
805 }
610 806
611 switch (q->clockid) { 807 switch (q->clockid) {
612 case CLOCK_REALTIME: 808 case CLOCK_REALTIME:
@@ -622,65 +818,52 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
622 q->get_time = ktime_get_clocktai; 818 q->get_time = ktime_get_clocktai;
623 break; 819 break;
624 default: 820 default:
625 return -ENOTSUPP; 821 NL_SET_ERR_MSG(extack, "Invalid 'clockid'");
822 err = -EINVAL;
823 goto unlock;
626 } 824 }
627 825
628 for (i = 0; i < dev->num_tx_queues; i++) { 826 err = taprio_get_start_time(sch, new_admin, &start);
629 struct netdev_queue *dev_queue; 827 if (err < 0) {
630 struct Qdisc *qdisc; 828 NL_SET_ERR_MSG(extack, "Internal error: failed get start time");
631 829 goto unlock;
632 dev_queue = netdev_get_tx_queue(dev, i); 830 }
633 qdisc = qdisc_create_dflt(dev_queue,
634 &pfifo_qdisc_ops,
635 TC_H_MAKE(TC_H_MAJ(sch->handle),
636 TC_H_MIN(i + 1)),
637 extack);
638 if (!qdisc)
639 return -ENOMEM;
640 831
641 if (i < dev->real_num_tx_queues) 832 setup_first_close_time(q, new_admin, start);
642 qdisc_hash_add(qdisc, false);
643 833
644 q->qdiscs[i] = qdisc; 834 /* Protects against advance_sched() */
645 } 835 spin_lock_irqsave(&q->current_entry_lock, flags);
646 836
647 if (mqprio) { 837 taprio_start_sched(sch, start, new_admin);
648 netdev_set_num_tc(dev, mqprio->num_tc);
649 for (i = 0; i < mqprio->num_tc; i++)
650 netdev_set_tc_queue(dev, i,
651 mqprio->count[i],
652 mqprio->offset[i]);
653 838
654 /* Always use supplied priority mappings */ 839 rcu_assign_pointer(q->admin_sched, new_admin);
655 for (i = 0; i < TC_BITMASK + 1; i++) 840 if (admin)
656 netdev_set_prio_tc_map(dev, i, 841 call_rcu(&admin->rcu, taprio_free_sched_cb);
657 mqprio->prio_tc_map[i]); 842 new_admin = NULL;
658 }
659 843
660 if (!__ethtool_get_link_ksettings(dev, &ecmd)) 844 spin_unlock_irqrestore(&q->current_entry_lock, flags);
661 link_speed = ecmd.base.speed;
662 else
663 link_speed = SPEED_1000;
664 845
665 q->picos_per_byte = div64_s64(NSEC_PER_SEC * 1000LL * 8, 846 err = 0;
666 link_speed * 1000 * 1000);
667 847
668 start = taprio_get_start_time(sch); 848unlock:
669 if (!start) 849 spin_unlock_bh(qdisc_lock(sch));
670 return 0;
671 850
672 taprio_start_sched(sch, start); 851free_sched:
852 kfree(new_admin);
673 853
674 return 0; 854 return err;
675} 855}
676 856
677static void taprio_destroy(struct Qdisc *sch) 857static void taprio_destroy(struct Qdisc *sch)
678{ 858{
679 struct taprio_sched *q = qdisc_priv(sch); 859 struct taprio_sched *q = qdisc_priv(sch);
680 struct net_device *dev = qdisc_dev(sch); 860 struct net_device *dev = qdisc_dev(sch);
681 struct sched_entry *entry, *n;
682 unsigned int i; 861 unsigned int i;
683 862
863 spin_lock(&taprio_list_lock);
864 list_del(&q->taprio_list);
865 spin_unlock(&taprio_list_lock);
866
684 hrtimer_cancel(&q->advance_timer); 867 hrtimer_cancel(&q->advance_timer);
685 868
686 if (q->qdiscs) { 869 if (q->qdiscs) {
@@ -693,10 +876,11 @@ static void taprio_destroy(struct Qdisc *sch)
693 876
694 netdev_set_num_tc(dev, 0); 877 netdev_set_num_tc(dev, 0);
695 878
696 list_for_each_entry_safe(entry, n, &q->entries, list) { 879 if (q->oper_sched)
697 list_del(&entry->list); 880 call_rcu(&q->oper_sched->rcu, taprio_free_sched_cb);
698 kfree(entry); 881
699 } 882 if (q->admin_sched)
883 call_rcu(&q->admin_sched->rcu, taprio_free_sched_cb);
700} 884}
701 885
702static int taprio_init(struct Qdisc *sch, struct nlattr *opt, 886static int taprio_init(struct Qdisc *sch, struct nlattr *opt,
@@ -704,12 +888,12 @@ static int taprio_init(struct Qdisc *sch, struct nlattr *opt,
704{ 888{
705 struct taprio_sched *q = qdisc_priv(sch); 889 struct taprio_sched *q = qdisc_priv(sch);
706 struct net_device *dev = qdisc_dev(sch); 890 struct net_device *dev = qdisc_dev(sch);
891 int i;
707 892
708 INIT_LIST_HEAD(&q->entries);
709 spin_lock_init(&q->current_entry_lock); 893 spin_lock_init(&q->current_entry_lock);
710 894
711 /* We may overwrite the configuration later */
712 hrtimer_init(&q->advance_timer, CLOCK_TAI, HRTIMER_MODE_ABS); 895 hrtimer_init(&q->advance_timer, CLOCK_TAI, HRTIMER_MODE_ABS);
896 q->advance_timer.function = advance_sched;
713 897
714 q->root = sch; 898 q->root = sch;
715 899
@@ -735,6 +919,29 @@ static int taprio_init(struct Qdisc *sch, struct nlattr *opt,
735 if (!opt) 919 if (!opt)
736 return -EINVAL; 920 return -EINVAL;
737 921
922 spin_lock(&taprio_list_lock);
923 list_add(&q->taprio_list, &taprio_list);
924 spin_unlock(&taprio_list_lock);
925
926 for (i = 0; i < dev->num_tx_queues; i++) {
927 struct netdev_queue *dev_queue;
928 struct Qdisc *qdisc;
929
930 dev_queue = netdev_get_tx_queue(dev, i);
931 qdisc = qdisc_create_dflt(dev_queue,
932 &pfifo_qdisc_ops,
933 TC_H_MAKE(TC_H_MAJ(sch->handle),
934 TC_H_MIN(i + 1)),
935 extack);
936 if (!qdisc)
937 return -ENOMEM;
938
939 if (i < dev->real_num_tx_queues)
940 qdisc_hash_add(qdisc, false);
941
942 q->qdiscs[i] = qdisc;
943 }
944
738 return taprio_change(sch, opt, extack); 945 return taprio_change(sch, opt, extack);
739} 946}
740 947
@@ -781,7 +988,7 @@ static int dump_entry(struct sk_buff *msg,
781{ 988{
782 struct nlattr *item; 989 struct nlattr *item;
783 990
784 item = nla_nest_start(msg, TCA_TAPRIO_SCHED_ENTRY); 991 item = nla_nest_start_noflag(msg, TCA_TAPRIO_SCHED_ENTRY);
785 if (!item) 992 if (!item)
786 return -ENOSPC; 993 return -ENOSPC;
787 994
@@ -806,15 +1013,55 @@ nla_put_failure:
806 return -1; 1013 return -1;
807} 1014}
808 1015
1016static int dump_schedule(struct sk_buff *msg,
1017 const struct sched_gate_list *root)
1018{
1019 struct nlattr *entry_list;
1020 struct sched_entry *entry;
1021
1022 if (nla_put_s64(msg, TCA_TAPRIO_ATTR_SCHED_BASE_TIME,
1023 root->base_time, TCA_TAPRIO_PAD))
1024 return -1;
1025
1026 if (nla_put_s64(msg, TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME,
1027 root->cycle_time, TCA_TAPRIO_PAD))
1028 return -1;
1029
1030 if (nla_put_s64(msg, TCA_TAPRIO_ATTR_SCHED_CYCLE_TIME_EXTENSION,
1031 root->cycle_time_extension, TCA_TAPRIO_PAD))
1032 return -1;
1033
1034 entry_list = nla_nest_start_noflag(msg,
1035 TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST);
1036 if (!entry_list)
1037 goto error_nest;
1038
1039 list_for_each_entry(entry, &root->entries, list) {
1040 if (dump_entry(msg, entry) < 0)
1041 goto error_nest;
1042 }
1043
1044 nla_nest_end(msg, entry_list);
1045 return 0;
1046
1047error_nest:
1048 nla_nest_cancel(msg, entry_list);
1049 return -1;
1050}
1051
809static int taprio_dump(struct Qdisc *sch, struct sk_buff *skb) 1052static int taprio_dump(struct Qdisc *sch, struct sk_buff *skb)
810{ 1053{
811 struct taprio_sched *q = qdisc_priv(sch); 1054 struct taprio_sched *q = qdisc_priv(sch);
812 struct net_device *dev = qdisc_dev(sch); 1055 struct net_device *dev = qdisc_dev(sch);
1056 struct sched_gate_list *oper, *admin;
813 struct tc_mqprio_qopt opt = { 0 }; 1057 struct tc_mqprio_qopt opt = { 0 };
814 struct nlattr *nest, *entry_list; 1058 struct nlattr *nest, *sched_nest;
815 struct sched_entry *entry;
816 unsigned int i; 1059 unsigned int i;
817 1060
1061 rcu_read_lock();
1062 oper = rcu_dereference(q->oper_sched);
1063 admin = rcu_dereference(q->admin_sched);
1064
818 opt.num_tc = netdev_get_num_tc(dev); 1065 opt.num_tc = netdev_get_num_tc(dev);
819 memcpy(opt.prio_tc_map, dev->prio_tc_map, sizeof(opt.prio_tc_map)); 1066 memcpy(opt.prio_tc_map, dev->prio_tc_map, sizeof(opt.prio_tc_map));
820 1067
@@ -823,36 +1070,45 @@ static int taprio_dump(struct Qdisc *sch, struct sk_buff *skb)
823 opt.offset[i] = dev->tc_to_txq[i].offset; 1070 opt.offset[i] = dev->tc_to_txq[i].offset;
824 } 1071 }
825 1072
826 nest = nla_nest_start(skb, TCA_OPTIONS); 1073 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
827 if (!nest) 1074 if (!nest)
828 return -ENOSPC; 1075 goto start_error;
829 1076
830 if (nla_put(skb, TCA_TAPRIO_ATTR_PRIOMAP, sizeof(opt), &opt)) 1077 if (nla_put(skb, TCA_TAPRIO_ATTR_PRIOMAP, sizeof(opt), &opt))
831 goto options_error; 1078 goto options_error;
832 1079
833 if (nla_put_s64(skb, TCA_TAPRIO_ATTR_SCHED_BASE_TIME, 1080 if (nla_put_s32(skb, TCA_TAPRIO_ATTR_SCHED_CLOCKID, q->clockid))
834 q->base_time, TCA_TAPRIO_PAD))
835 goto options_error; 1081 goto options_error;
836 1082
837 if (nla_put_s32(skb, TCA_TAPRIO_ATTR_SCHED_CLOCKID, q->clockid)) 1083 if (oper && dump_schedule(skb, oper))
838 goto options_error; 1084 goto options_error;
839 1085
840 entry_list = nla_nest_start(skb, TCA_TAPRIO_ATTR_SCHED_ENTRY_LIST); 1086 if (!admin)
841 if (!entry_list) 1087 goto done;
1088
1089 sched_nest = nla_nest_start_noflag(skb, TCA_TAPRIO_ATTR_ADMIN_SCHED);
1090 if (!sched_nest)
842 goto options_error; 1091 goto options_error;
843 1092
844 list_for_each_entry(entry, &q->entries, list) { 1093 if (dump_schedule(skb, admin))
845 if (dump_entry(skb, entry) < 0) 1094 goto admin_error;
846 goto options_error; 1095
847 } 1096 nla_nest_end(skb, sched_nest);
848 1097
849 nla_nest_end(skb, entry_list); 1098done:
1099 rcu_read_unlock();
850 1100
851 return nla_nest_end(skb, nest); 1101 return nla_nest_end(skb, nest);
852 1102
1103admin_error:
1104 nla_nest_cancel(skb, sched_nest);
1105
853options_error: 1106options_error:
854 nla_nest_cancel(skb, nest); 1107 nla_nest_cancel(skb, nest);
855 return -1; 1108
1109start_error:
1110 rcu_read_unlock();
1111 return -ENOSPC;
856} 1112}
857 1113
858static struct Qdisc *taprio_leaf(struct Qdisc *sch, unsigned long cl) 1114static struct Qdisc *taprio_leaf(struct Qdisc *sch, unsigned long cl)
@@ -939,6 +1195,7 @@ static struct Qdisc_ops taprio_qdisc_ops __read_mostly = {
939 .id = "taprio", 1195 .id = "taprio",
940 .priv_size = sizeof(struct taprio_sched), 1196 .priv_size = sizeof(struct taprio_sched),
941 .init = taprio_init, 1197 .init = taprio_init,
1198 .change = taprio_change,
942 .destroy = taprio_destroy, 1199 .destroy = taprio_destroy,
943 .peek = taprio_peek, 1200 .peek = taprio_peek,
944 .dequeue = taprio_dequeue, 1201 .dequeue = taprio_dequeue,
@@ -947,14 +1204,24 @@ static struct Qdisc_ops taprio_qdisc_ops __read_mostly = {
947 .owner = THIS_MODULE, 1204 .owner = THIS_MODULE,
948}; 1205};
949 1206
1207static struct notifier_block taprio_device_notifier = {
1208 .notifier_call = taprio_dev_notifier,
1209};
1210
950static int __init taprio_module_init(void) 1211static int __init taprio_module_init(void)
951{ 1212{
1213 int err = register_netdevice_notifier(&taprio_device_notifier);
1214
1215 if (err)
1216 return err;
1217
952 return register_qdisc(&taprio_qdisc_ops); 1218 return register_qdisc(&taprio_qdisc_ops);
953} 1219}
954 1220
955static void __exit taprio_module_exit(void) 1221static void __exit taprio_module_exit(void)
956{ 1222{
957 unregister_qdisc(&taprio_qdisc_ops); 1223 unregister_qdisc(&taprio_qdisc_ops);
1224 unregister_netdevice_notifier(&taprio_device_notifier);
958} 1225}
959 1226
960module_init(taprio_module_init); 1227module_init(taprio_module_init);
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index f71578dbb9e3..c09c0d855846 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -308,7 +308,8 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt,
308 s64 buffer, mtu; 308 s64 buffer, mtu;
309 u64 rate64 = 0, prate64 = 0; 309 u64 rate64 = 0, prate64 = 0;
310 310
311 err = nla_parse_nested(tb, TCA_TBF_MAX, opt, tbf_policy, NULL); 311 err = nla_parse_nested_deprecated(tb, TCA_TBF_MAX, opt, tbf_policy,
312 NULL);
312 if (err < 0) 313 if (err < 0)
313 return err; 314 return err;
314 315
@@ -448,7 +449,7 @@ static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)
448 struct tc_tbf_qopt opt; 449 struct tc_tbf_qopt opt;
449 450
450 sch->qstats.backlog = q->qdisc->qstats.backlog; 451 sch->qstats.backlog = q->qdisc->qstats.backlog;
451 nest = nla_nest_start(skb, TCA_OPTIONS); 452 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
452 if (nest == NULL) 453 if (nest == NULL)
453 goto nla_put_failure; 454 goto nla_put_failure;
454 455
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index 39d72e58b8e5..31569f4809f6 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -760,7 +760,6 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
760 SHASH_DESC_ON_STACK(desc, tfm); 760 SHASH_DESC_ON_STACK(desc, tfm);
761 761
762 desc->tfm = tfm; 762 desc->tfm = tfm;
763 desc->flags = 0;
764 crypto_shash_digest(desc, (u8 *)auth, 763 crypto_shash_digest(desc, (u8 *)auth,
765 end - (unsigned char *)auth, digest); 764 end - (unsigned char *)auth, digest);
766 shash_desc_zero(desc); 765 shash_desc_zero(desc);
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 6200cd2b4b99..188c47eb206e 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -1030,6 +1030,7 @@ static const struct proto_ops inet6_seqpacket_ops = {
1030 .getname = sctp_getname, 1030 .getname = sctp_getname,
1031 .poll = sctp_poll, 1031 .poll = sctp_poll,
1032 .ioctl = inet6_ioctl, 1032 .ioctl = inet6_ioctl,
1033 .gettstamp = sock_gettstamp,
1033 .listen = sctp_inet_listen, 1034 .listen = sctp_inet_listen,
1034 .shutdown = inet_shutdown, 1035 .shutdown = inet_shutdown,
1035 .setsockopt = sock_common_setsockopt, 1036 .setsockopt = sock_common_setsockopt,
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 951afdeea5e9..f0631bf486b6 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1026,6 +1026,7 @@ static const struct proto_ops inet_seqpacket_ops = {
1026 .getname = inet_getname, /* Semantics are different. */ 1026 .getname = inet_getname, /* Semantics are different. */
1027 .poll = sctp_poll, 1027 .poll = sctp_poll,
1028 .ioctl = inet_ioctl, 1028 .ioctl = inet_ioctl,
1029 .gettstamp = sock_gettstamp,
1029 .listen = sctp_inet_listen, 1030 .listen = sctp_inet_listen,
1030 .shutdown = inet_shutdown, /* Looks harmless. */ 1031 .shutdown = inet_shutdown, /* Looks harmless. */
1031 .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem */ 1032 .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem */
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index d05c57664e36..72e74503f9fc 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1684,7 +1684,6 @@ static struct sctp_cookie_param *sctp_pack_cookie(
1684 1684
1685 /* Sign the message. */ 1685 /* Sign the message. */
1686 desc->tfm = sctp_sk(ep->base.sk)->hmac; 1686 desc->tfm = sctp_sk(ep->base.sk)->hmac;
1687 desc->flags = 0;
1688 1687
1689 err = crypto_shash_setkey(desc->tfm, ep->secret_key, 1688 err = crypto_shash_setkey(desc->tfm, ep->secret_key,
1690 sizeof(ep->secret_key)) ?: 1689 sizeof(ep->secret_key)) ?:
@@ -1755,7 +1754,6 @@ struct sctp_association *sctp_unpack_cookie(
1755 int err; 1754 int err;
1756 1755
1757 desc->tfm = sctp_sk(ep->base.sk)->hmac; 1756 desc->tfm = sctp_sk(ep->base.sk)->hmac;
1758 desc->flags = 0;
1759 1757
1760 err = crypto_shash_setkey(desc->tfm, ep->secret_key, 1758 err = crypto_shash_setkey(desc->tfm, ep->secret_key,
1761 sizeof(ep->secret_key)) ?: 1759 sizeof(ep->secret_key)) ?:
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index 1d143bc3f73d..4aa03588f87b 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -1112,32 +1112,6 @@ static void sctp_cmd_send_msg(struct sctp_association *asoc,
1112} 1112}
1113 1113
1114 1114
1115/* Sent the next ASCONF packet currently stored in the association.
1116 * This happens after the ASCONF_ACK was succeffully processed.
1117 */
1118static void sctp_cmd_send_asconf(struct sctp_association *asoc)
1119{
1120 struct net *net = sock_net(asoc->base.sk);
1121
1122 /* Send the next asconf chunk from the addip chunk
1123 * queue.
1124 */
1125 if (!list_empty(&asoc->addip_chunk_list)) {
1126 struct list_head *entry = asoc->addip_chunk_list.next;
1127 struct sctp_chunk *asconf = list_entry(entry,
1128 struct sctp_chunk, list);
1129 list_del_init(entry);
1130
1131 /* Hold the chunk until an ASCONF_ACK is received. */
1132 sctp_chunk_hold(asconf);
1133 if (sctp_primitive_ASCONF(net, asoc, asconf))
1134 sctp_chunk_free(asconf);
1135 else
1136 asoc->addip_last_asconf = asconf;
1137 }
1138}
1139
1140
1141/* These three macros allow us to pull the debugging code out of the 1115/* These three macros allow us to pull the debugging code out of the
1142 * main flow of sctp_do_sm() to keep attention focused on the real 1116 * main flow of sctp_do_sm() to keep attention focused on the real
1143 * functionality there. 1117 * functionality there.
@@ -1783,9 +1757,6 @@ static int sctp_cmd_interpreter(enum sctp_event_type event_type,
1783 } 1757 }
1784 sctp_cmd_send_msg(asoc, cmd->obj.msg, gfp); 1758 sctp_cmd_send_msg(asoc, cmd->obj.msg, gfp);
1785 break; 1759 break;
1786 case SCTP_CMD_SEND_NEXT_ASCONF:
1787 sctp_cmd_send_asconf(asoc);
1788 break;
1789 case SCTP_CMD_PURGE_ASCONF_QUEUE: 1760 case SCTP_CMD_PURGE_ASCONF_QUEUE:
1790 sctp_asconf_queue_teardown(asoc); 1761 sctp_asconf_queue_teardown(asoc);
1791 break; 1762 break;
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index c9ae3404b1bb..e3f4abe6134e 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -3824,6 +3824,29 @@ enum sctp_disposition sctp_sf_do_asconf(struct net *net,
3824 return SCTP_DISPOSITION_CONSUME; 3824 return SCTP_DISPOSITION_CONSUME;
3825} 3825}
3826 3826
3827static enum sctp_disposition sctp_send_next_asconf(
3828 struct net *net,
3829 const struct sctp_endpoint *ep,
3830 struct sctp_association *asoc,
3831 const union sctp_subtype type,
3832 struct sctp_cmd_seq *commands)
3833{
3834 struct sctp_chunk *asconf;
3835 struct list_head *entry;
3836
3837 if (list_empty(&asoc->addip_chunk_list))
3838 return SCTP_DISPOSITION_CONSUME;
3839
3840 entry = asoc->addip_chunk_list.next;
3841 asconf = list_entry(entry, struct sctp_chunk, list);
3842
3843 list_del_init(entry);
3844 sctp_chunk_hold(asconf);
3845 asoc->addip_last_asconf = asconf;
3846
3847 return sctp_sf_do_prm_asconf(net, ep, asoc, type, asconf, commands);
3848}
3849
3827/* 3850/*
3828 * ADDIP Section 4.3 General rules for address manipulation 3851 * ADDIP Section 4.3 General rules for address manipulation
3829 * When building TLV parameters for the ASCONF Chunk that will add or 3852 * When building TLV parameters for the ASCONF Chunk that will add or
@@ -3915,14 +3938,10 @@ enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net,
3915 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); 3938 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3916 3939
3917 if (!sctp_process_asconf_ack((struct sctp_association *)asoc, 3940 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3918 asconf_ack)) { 3941 asconf_ack))
3919 /* Successfully processed ASCONF_ACK. We can 3942 return sctp_send_next_asconf(net, ep,
3920 * release the next asconf if we have one. 3943 (struct sctp_association *)asoc,
3921 */ 3944 type, commands);
3922 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_NEXT_ASCONF,
3923 SCTP_NULL());
3924 return SCTP_DISPOSITION_CONSUME;
3925 }
3926 3945
3927 abort = sctp_make_abort(asoc, asconf_ack, 3946 abort = sctp_make_abort(asoc, asconf_ack,
3928 sizeof(struct sctp_errhdr)); 3947 sizeof(struct sctp_errhdr));
@@ -6412,13 +6431,15 @@ static int sctp_eat_data(const struct sctp_association *asoc,
6412 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our 6431 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6413 * memory usage too much 6432 * memory usage too much
6414 */ 6433 */
6415 if (*sk->sk_prot_creator->memory_pressure) { 6434 if (sk_under_memory_pressure(sk)) {
6416 if (sctp_tsnmap_has_gap(map) && 6435 if (sctp_tsnmap_has_gap(map) &&
6417 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { 6436 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
6418 pr_debug("%s: under pressure, reneging for tsn:%u\n", 6437 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6419 __func__, tsn); 6438 __func__, tsn);
6420 deliver = SCTP_CMD_RENEGE; 6439 deliver = SCTP_CMD_RENEGE;
6421 } 6440 } else {
6441 sk_mem_reclaim(sk);
6442 }
6422 } 6443 }
6423 6444
6424 /* 6445 /*
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 9874e60c9b0d..e4e892cc5644 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1913,7 +1913,10 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
1913 if (sctp_wspace(asoc) < (int)msg_len) 1913 if (sctp_wspace(asoc) < (int)msg_len)
1914 sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc)); 1914 sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc));
1915 1915
1916 if (sctp_wspace(asoc) <= 0) { 1916 if (sk_under_memory_pressure(sk))
1917 sk_mem_reclaim(sk);
1918
1919 if (sctp_wspace(asoc) <= 0 || !sk_wmem_schedule(sk, msg_len)) {
1917 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); 1920 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
1918 err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len); 1921 err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
1919 if (err) 1922 if (err)
@@ -4847,7 +4850,8 @@ static int sctp_connect(struct sock *sk, struct sockaddr *addr,
4847 } 4850 }
4848 4851
4849 /* Validate addr_len before calling common connect/connectx routine. */ 4852 /* Validate addr_len before calling common connect/connectx routine. */
4850 af = sctp_get_af_specific(addr->sa_family); 4853 af = addr_len < offsetofend(struct sockaddr, sa_family) ? NULL :
4854 sctp_get_af_specific(addr->sa_family);
4851 if (!af || addr_len < af->sockaddr_len) { 4855 if (!af || addr_len < af->sockaddr_len) {
4852 err = -EINVAL; 4856 err = -EINVAL;
4853 } else { 4857 } else {
@@ -8930,7 +8934,10 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
8930 goto do_error; 8934 goto do_error;
8931 if (signal_pending(current)) 8935 if (signal_pending(current))
8932 goto do_interrupted; 8936 goto do_interrupted;
8933 if ((int)msg_len <= sctp_wspace(asoc)) 8937 if (sk_under_memory_pressure(sk))
8938 sk_mem_reclaim(sk);
8939 if ((int)msg_len <= sctp_wspace(asoc) &&
8940 sk_wmem_schedule(sk, msg_len))
8934 break; 8941 break;
8935 8942
8936 /* Let another process have a go. Since we are going 8943 /* Let another process have a go. Since we are going
diff --git a/net/sctp/stream_interleave.c b/net/sctp/stream_interleave.c
index 102c6fefe38c..25e0b7e5189c 100644
--- a/net/sctp/stream_interleave.c
+++ b/net/sctp/stream_interleave.c
@@ -484,14 +484,15 @@ static struct sctp_ulpevent *sctp_intl_order(struct sctp_ulpq *ulpq,
484} 484}
485 485
486static int sctp_enqueue_event(struct sctp_ulpq *ulpq, 486static int sctp_enqueue_event(struct sctp_ulpq *ulpq,
487 struct sctp_ulpevent *event) 487 struct sk_buff_head *skb_list)
488{ 488{
489 struct sk_buff *skb = sctp_event2skb(event);
490 struct sock *sk = ulpq->asoc->base.sk; 489 struct sock *sk = ulpq->asoc->base.sk;
491 struct sctp_sock *sp = sctp_sk(sk); 490 struct sctp_sock *sp = sctp_sk(sk);
492 struct sk_buff_head *skb_list; 491 struct sctp_ulpevent *event;
492 struct sk_buff *skb;
493 493
494 skb_list = (struct sk_buff_head *)skb->prev; 494 skb = __skb_peek(skb_list);
495 event = sctp_skb2event(skb);
495 496
496 if (sk->sk_shutdown & RCV_SHUTDOWN && 497 if (sk->sk_shutdown & RCV_SHUTDOWN &&
497 (sk->sk_shutdown & SEND_SHUTDOWN || 498 (sk->sk_shutdown & SEND_SHUTDOWN ||
@@ -858,19 +859,24 @@ static int sctp_ulpevent_idata(struct sctp_ulpq *ulpq,
858 859
859 if (!(event->msg_flags & SCTP_DATA_UNORDERED)) { 860 if (!(event->msg_flags & SCTP_DATA_UNORDERED)) {
860 event = sctp_intl_reasm(ulpq, event); 861 event = sctp_intl_reasm(ulpq, event);
861 if (event && event->msg_flags & MSG_EOR) { 862 if (event) {
862 skb_queue_head_init(&temp); 863 skb_queue_head_init(&temp);
863 __skb_queue_tail(&temp, sctp_event2skb(event)); 864 __skb_queue_tail(&temp, sctp_event2skb(event));
864 865
865 event = sctp_intl_order(ulpq, event); 866 if (event->msg_flags & MSG_EOR)
867 event = sctp_intl_order(ulpq, event);
866 } 868 }
867 } else { 869 } else {
868 event = sctp_intl_reasm_uo(ulpq, event); 870 event = sctp_intl_reasm_uo(ulpq, event);
871 if (event) {
872 skb_queue_head_init(&temp);
873 __skb_queue_tail(&temp, sctp_event2skb(event));
874 }
869 } 875 }
870 876
871 if (event) { 877 if (event) {
872 event_eor = (event->msg_flags & MSG_EOR) ? 1 : 0; 878 event_eor = (event->msg_flags & MSG_EOR) ? 1 : 0;
873 sctp_enqueue_event(ulpq, event); 879 sctp_enqueue_event(ulpq, &temp);
874 } 880 }
875 881
876 return event_eor; 882 return event_eor;
@@ -944,20 +950,27 @@ out:
944static void sctp_intl_start_pd(struct sctp_ulpq *ulpq, gfp_t gfp) 950static void sctp_intl_start_pd(struct sctp_ulpq *ulpq, gfp_t gfp)
945{ 951{
946 struct sctp_ulpevent *event; 952 struct sctp_ulpevent *event;
953 struct sk_buff_head temp;
947 954
948 if (!skb_queue_empty(&ulpq->reasm)) { 955 if (!skb_queue_empty(&ulpq->reasm)) {
949 do { 956 do {
950 event = sctp_intl_retrieve_first(ulpq); 957 event = sctp_intl_retrieve_first(ulpq);
951 if (event) 958 if (event) {
952 sctp_enqueue_event(ulpq, event); 959 skb_queue_head_init(&temp);
960 __skb_queue_tail(&temp, sctp_event2skb(event));
961 sctp_enqueue_event(ulpq, &temp);
962 }
953 } while (event); 963 } while (event);
954 } 964 }
955 965
956 if (!skb_queue_empty(&ulpq->reasm_uo)) { 966 if (!skb_queue_empty(&ulpq->reasm_uo)) {
957 do { 967 do {
958 event = sctp_intl_retrieve_first_uo(ulpq); 968 event = sctp_intl_retrieve_first_uo(ulpq);
959 if (event) 969 if (event) {
960 sctp_enqueue_event(ulpq, event); 970 skb_queue_head_init(&temp);
971 __skb_queue_tail(&temp, sctp_event2skb(event));
972 sctp_enqueue_event(ulpq, &temp);
973 }
961 } while (event); 974 } while (event);
962 } 975 }
963} 976}
@@ -1059,7 +1072,7 @@ static void sctp_intl_reap_ordered(struct sctp_ulpq *ulpq, __u16 sid)
1059 1072
1060 if (event) { 1073 if (event) {
1061 sctp_intl_retrieve_ordered(ulpq, event); 1074 sctp_intl_retrieve_ordered(ulpq, event);
1062 sctp_enqueue_event(ulpq, event); 1075 sctp_enqueue_event(ulpq, &temp);
1063 } 1076 }
1064} 1077}
1065 1078
@@ -1298,6 +1311,15 @@ static void sctp_handle_iftsn(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk)
1298 ntohl(skip->mid), skip->flags); 1311 ntohl(skip->mid), skip->flags);
1299} 1312}
1300 1313
1314static int do_ulpq_tail_event(struct sctp_ulpq *ulpq, struct sctp_ulpevent *event)
1315{
1316 struct sk_buff_head temp;
1317
1318 skb_queue_head_init(&temp);
1319 __skb_queue_tail(&temp, sctp_event2skb(event));
1320 return sctp_ulpq_tail_event(ulpq, &temp);
1321}
1322
1301static struct sctp_stream_interleave sctp_stream_interleave_0 = { 1323static struct sctp_stream_interleave sctp_stream_interleave_0 = {
1302 .data_chunk_len = sizeof(struct sctp_data_chunk), 1324 .data_chunk_len = sizeof(struct sctp_data_chunk),
1303 .ftsn_chunk_len = sizeof(struct sctp_fwdtsn_chunk), 1325 .ftsn_chunk_len = sizeof(struct sctp_fwdtsn_chunk),
@@ -1306,7 +1328,7 @@ static struct sctp_stream_interleave sctp_stream_interleave_0 = {
1306 .assign_number = sctp_chunk_assign_ssn, 1328 .assign_number = sctp_chunk_assign_ssn,
1307 .validate_data = sctp_validate_data, 1329 .validate_data = sctp_validate_data,
1308 .ulpevent_data = sctp_ulpq_tail_data, 1330 .ulpevent_data = sctp_ulpq_tail_data,
1309 .enqueue_event = sctp_ulpq_tail_event, 1331 .enqueue_event = do_ulpq_tail_event,
1310 .renege_events = sctp_ulpq_renege, 1332 .renege_events = sctp_ulpq_renege,
1311 .start_pd = sctp_ulpq_partial_delivery, 1333 .start_pd = sctp_ulpq_partial_delivery,
1312 .abort_pd = sctp_ulpq_abort_pd, 1334 .abort_pd = sctp_ulpq_abort_pd,
@@ -1317,6 +1339,16 @@ static struct sctp_stream_interleave sctp_stream_interleave_0 = {
1317 .handle_ftsn = sctp_handle_fwdtsn, 1339 .handle_ftsn = sctp_handle_fwdtsn,
1318}; 1340};
1319 1341
1342static int do_sctp_enqueue_event(struct sctp_ulpq *ulpq,
1343 struct sctp_ulpevent *event)
1344{
1345 struct sk_buff_head temp;
1346
1347 skb_queue_head_init(&temp);
1348 __skb_queue_tail(&temp, sctp_event2skb(event));
1349 return sctp_enqueue_event(ulpq, &temp);
1350}
1351
1320static struct sctp_stream_interleave sctp_stream_interleave_1 = { 1352static struct sctp_stream_interleave sctp_stream_interleave_1 = {
1321 .data_chunk_len = sizeof(struct sctp_idata_chunk), 1353 .data_chunk_len = sizeof(struct sctp_idata_chunk),
1322 .ftsn_chunk_len = sizeof(struct sctp_ifwdtsn_chunk), 1354 .ftsn_chunk_len = sizeof(struct sctp_ifwdtsn_chunk),
@@ -1325,7 +1357,7 @@ static struct sctp_stream_interleave sctp_stream_interleave_1 = {
1325 .assign_number = sctp_chunk_assign_mid, 1357 .assign_number = sctp_chunk_assign_mid,
1326 .validate_data = sctp_validate_idata, 1358 .validate_data = sctp_validate_idata,
1327 .ulpevent_data = sctp_ulpevent_idata, 1359 .ulpevent_data = sctp_ulpevent_idata,
1328 .enqueue_event = sctp_enqueue_event, 1360 .enqueue_event = do_sctp_enqueue_event,
1329 .renege_events = sctp_renege_events, 1361 .renege_events = sctp_renege_events,
1330 .start_pd = sctp_intl_start_pd, 1362 .start_pd = sctp_intl_start_pd,
1331 .abort_pd = sctp_intl_abort_pd, 1363 .abort_pd = sctp_intl_abort_pd,
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
index 8cb7d9858270..c2a7478587ab 100644
--- a/net/sctp/ulpevent.c
+++ b/net/sctp/ulpevent.c
@@ -634,8 +634,9 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
634 gfp_t gfp) 634 gfp_t gfp)
635{ 635{
636 struct sctp_ulpevent *event = NULL; 636 struct sctp_ulpevent *event = NULL;
637 struct sk_buff *skb; 637 struct sk_buff *skb = chunk->skb;
638 size_t padding, len; 638 struct sock *sk = asoc->base.sk;
639 size_t padding, datalen;
639 int rx_count; 640 int rx_count;
640 641
641 /* 642 /*
@@ -646,15 +647,12 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
646 if (asoc->ep->rcvbuf_policy) 647 if (asoc->ep->rcvbuf_policy)
647 rx_count = atomic_read(&asoc->rmem_alloc); 648 rx_count = atomic_read(&asoc->rmem_alloc);
648 else 649 else
649 rx_count = atomic_read(&asoc->base.sk->sk_rmem_alloc); 650 rx_count = atomic_read(&sk->sk_rmem_alloc);
650 651
651 if (rx_count >= asoc->base.sk->sk_rcvbuf) { 652 datalen = ntohs(chunk->chunk_hdr->length);
652 653
653 if ((asoc->base.sk->sk_userlocks & SOCK_RCVBUF_LOCK) || 654 if (rx_count >= sk->sk_rcvbuf || !sk_rmem_schedule(sk, skb, datalen))
654 (!sk_rmem_schedule(asoc->base.sk, chunk->skb, 655 goto fail;
655 chunk->skb->truesize)))
656 goto fail;
657 }
658 656
659 /* Clone the original skb, sharing the data. */ 657 /* Clone the original skb, sharing the data. */
660 skb = skb_clone(chunk->skb, gfp); 658 skb = skb_clone(chunk->skb, gfp);
@@ -681,8 +679,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
681 * The sender should never pad with more than 3 bytes. The receiver 679 * The sender should never pad with more than 3 bytes. The receiver
682 * MUST ignore the padding bytes. 680 * MUST ignore the padding bytes.
683 */ 681 */
684 len = ntohs(chunk->chunk_hdr->length); 682 padding = SCTP_PAD4(datalen) - datalen;
685 padding = SCTP_PAD4(len) - len;
686 683
687 /* Fixup cloned skb with just this chunks data. */ 684 /* Fixup cloned skb with just this chunks data. */
688 skb_trim(skb, chunk->chunk_end - padding - skb->data); 685 skb_trim(skb, chunk->chunk_end - padding - skb->data);
diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c
index 5dde92101743..a212fe079c07 100644
--- a/net/sctp/ulpqueue.c
+++ b/net/sctp/ulpqueue.c
@@ -116,12 +116,13 @@ int sctp_ulpq_tail_data(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
116 event = sctp_ulpq_reasm(ulpq, event); 116 event = sctp_ulpq_reasm(ulpq, event);
117 117
118 /* Do ordering if needed. */ 118 /* Do ordering if needed. */
119 if ((event) && (event->msg_flags & MSG_EOR)) { 119 if (event) {
120 /* Create a temporary list to collect chunks on. */ 120 /* Create a temporary list to collect chunks on. */
121 skb_queue_head_init(&temp); 121 skb_queue_head_init(&temp);
122 __skb_queue_tail(&temp, sctp_event2skb(event)); 122 __skb_queue_tail(&temp, sctp_event2skb(event));
123 123
124 event = sctp_ulpq_order(ulpq, event); 124 if (event->msg_flags & MSG_EOR)
125 event = sctp_ulpq_order(ulpq, event);
125 } 126 }
126 127
127 /* Send event to the ULP. 'event' is the sctp_ulpevent for 128 /* Send event to the ULP. 'event' is the sctp_ulpevent for
@@ -129,7 +130,7 @@ int sctp_ulpq_tail_data(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
129 */ 130 */
130 if (event) { 131 if (event) {
131 event_eor = (event->msg_flags & MSG_EOR) ? 1 : 0; 132 event_eor = (event->msg_flags & MSG_EOR) ? 1 : 0;
132 sctp_ulpq_tail_event(ulpq, event); 133 sctp_ulpq_tail_event(ulpq, &temp);
133 } 134 }
134 135
135 return event_eor; 136 return event_eor;
@@ -193,18 +194,17 @@ static int sctp_ulpq_clear_pd(struct sctp_ulpq *ulpq)
193 return sctp_clear_pd(ulpq->asoc->base.sk, ulpq->asoc); 194 return sctp_clear_pd(ulpq->asoc->base.sk, ulpq->asoc);
194} 195}
195 196
196/* If the SKB of 'event' is on a list, it is the first such member 197int sctp_ulpq_tail_event(struct sctp_ulpq *ulpq, struct sk_buff_head *skb_list)
197 * of that list.
198 */
199int sctp_ulpq_tail_event(struct sctp_ulpq *ulpq, struct sctp_ulpevent *event)
200{ 198{
201 struct sock *sk = ulpq->asoc->base.sk; 199 struct sock *sk = ulpq->asoc->base.sk;
202 struct sctp_sock *sp = sctp_sk(sk); 200 struct sctp_sock *sp = sctp_sk(sk);
203 struct sk_buff_head *queue, *skb_list; 201 struct sctp_ulpevent *event;
204 struct sk_buff *skb = sctp_event2skb(event); 202 struct sk_buff_head *queue;
203 struct sk_buff *skb;
205 int clear_pd = 0; 204 int clear_pd = 0;
206 205
207 skb_list = (struct sk_buff_head *) skb->prev; 206 skb = __skb_peek(skb_list);
207 event = sctp_skb2event(skb);
208 208
209 /* If the socket is just going to throw this away, do not 209 /* If the socket is just going to throw this away, do not
210 * even try to deliver it. 210 * even try to deliver it.
@@ -257,13 +257,7 @@ int sctp_ulpq_tail_event(struct sctp_ulpq *ulpq, struct sctp_ulpevent *event)
257 } 257 }
258 } 258 }
259 259
260 /* If we are harvesting multiple skbs they will be 260 skb_queue_splice_tail_init(skb_list, queue);
261 * collected on a list.
262 */
263 if (skb_list)
264 skb_queue_splice_tail_init(skb_list, queue);
265 else
266 __skb_queue_tail(queue, skb);
267 261
268 /* Did we just complete partial delivery and need to get 262 /* Did we just complete partial delivery and need to get
269 * rolling again? Move pending data to the receive 263 * rolling again? Move pending data to the receive
@@ -738,25 +732,25 @@ void sctp_ulpq_reasm_flushtsn(struct sctp_ulpq *ulpq, __u32 fwd_tsn)
738static void sctp_ulpq_reasm_drain(struct sctp_ulpq *ulpq) 732static void sctp_ulpq_reasm_drain(struct sctp_ulpq *ulpq)
739{ 733{
740 struct sctp_ulpevent *event = NULL; 734 struct sctp_ulpevent *event = NULL;
741 struct sk_buff_head temp;
742 735
743 if (skb_queue_empty(&ulpq->reasm)) 736 if (skb_queue_empty(&ulpq->reasm))
744 return; 737 return;
745 738
746 while ((event = sctp_ulpq_retrieve_reassembled(ulpq)) != NULL) { 739 while ((event = sctp_ulpq_retrieve_reassembled(ulpq)) != NULL) {
747 /* Do ordering if needed. */ 740 struct sk_buff_head temp;
748 if ((event) && (event->msg_flags & MSG_EOR)) { 741
749 skb_queue_head_init(&temp); 742 skb_queue_head_init(&temp);
750 __skb_queue_tail(&temp, sctp_event2skb(event)); 743 __skb_queue_tail(&temp, sctp_event2skb(event));
751 744
745 /* Do ordering if needed. */
746 if (event->msg_flags & MSG_EOR)
752 event = sctp_ulpq_order(ulpq, event); 747 event = sctp_ulpq_order(ulpq, event);
753 }
754 748
755 /* Send event to the ULP. 'event' is the 749 /* Send event to the ULP. 'event' is the
756 * sctp_ulpevent for very first SKB on the temp' list. 750 * sctp_ulpevent for very first SKB on the temp' list.
757 */ 751 */
758 if (event) 752 if (event)
759 sctp_ulpq_tail_event(ulpq, event); 753 sctp_ulpq_tail_event(ulpq, &temp);
760 } 754 }
761} 755}
762 756
@@ -956,7 +950,7 @@ static void sctp_ulpq_reap_ordered(struct sctp_ulpq *ulpq, __u16 sid)
956 if (event) { 950 if (event) {
957 /* see if we have more ordered that we can deliver */ 951 /* see if we have more ordered that we can deliver */
958 sctp_ulpq_retrieve_ordered(ulpq, event); 952 sctp_ulpq_retrieve_ordered(ulpq, event);
959 sctp_ulpq_tail_event(ulpq, event); 953 sctp_ulpq_tail_event(ulpq, &temp);
960 } 954 }
961} 955}
962 956
@@ -1082,7 +1076,11 @@ void sctp_ulpq_partial_delivery(struct sctp_ulpq *ulpq,
1082 event = sctp_ulpq_retrieve_first(ulpq); 1076 event = sctp_ulpq_retrieve_first(ulpq);
1083 /* Send event to the ULP. */ 1077 /* Send event to the ULP. */
1084 if (event) { 1078 if (event) {
1085 sctp_ulpq_tail_event(ulpq, event); 1079 struct sk_buff_head temp;
1080
1081 skb_queue_head_init(&temp);
1082 __skb_queue_tail(&temp, sctp_event2skb(event));
1083 sctp_ulpq_tail_event(ulpq, &temp);
1086 sctp_ulpq_set_pd(ulpq); 1084 sctp_ulpq_set_pd(ulpq);
1087 return; 1085 return;
1088 } 1086 }
@@ -1106,7 +1104,8 @@ void sctp_ulpq_renege(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
1106 freed += sctp_ulpq_renege_frags(ulpq, needed - freed); 1104 freed += sctp_ulpq_renege_frags(ulpq, needed - freed);
1107 } 1105 }
1108 /* If able to free enough room, accept this chunk. */ 1106 /* If able to free enough room, accept this chunk. */
1109 if (freed >= needed) { 1107 if (sk_rmem_schedule(asoc->base.sk, chunk->skb, needed) &&
1108 freed >= needed) {
1110 int retval = sctp_ulpq_tail_data(ulpq, chunk, gfp); 1109 int retval = sctp_ulpq_tail_data(ulpq, chunk, gfp);
1111 /* 1110 /*
1112 * Enter partial delivery if chunk has not been 1111 * Enter partial delivery if chunk has not been
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 77ef53596d18..086d9913975d 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -134,11 +134,9 @@ static int smc_release(struct socket *sock)
134 smc = smc_sk(sk); 134 smc = smc_sk(sk);
135 135
136 /* cleanup for a dangling non-blocking connect */ 136 /* cleanup for a dangling non-blocking connect */
137 if (smc->connect_info && sk->sk_state == SMC_INIT) 137 if (smc->connect_nonblock && sk->sk_state == SMC_INIT)
138 tcp_abort(smc->clcsock->sk, ECONNABORTED); 138 tcp_abort(smc->clcsock->sk, ECONNABORTED);
139 flush_work(&smc->connect_work); 139 flush_work(&smc->connect_work);
140 kfree(smc->connect_info);
141 smc->connect_info = NULL;
142 140
143 if (sk->sk_state == SMC_LISTEN) 141 if (sk->sk_state == SMC_LISTEN)
144 /* smc_close_non_accepted() is called and acquires 142 /* smc_close_non_accepted() is called and acquires
@@ -167,10 +165,9 @@ static int smc_release(struct socket *sock)
167 165
168 if (sk->sk_state == SMC_CLOSED) { 166 if (sk->sk_state == SMC_CLOSED) {
169 if (smc->clcsock) { 167 if (smc->clcsock) {
170 mutex_lock(&smc->clcsock_release_lock); 168 release_sock(sk);
171 sock_release(smc->clcsock); 169 smc_clcsock_release(smc);
172 smc->clcsock = NULL; 170 lock_sock(sk);
173 mutex_unlock(&smc->clcsock_release_lock);
174 } 171 }
175 if (!smc->use_fallback) 172 if (!smc->use_fallback)
176 smc_conn_free(&smc->conn); 173 smc_conn_free(&smc->conn);
@@ -446,12 +443,22 @@ static void smc_link_save_peer_info(struct smc_link *link,
446 link->peer_mtu = clc->qp_mtu; 443 link->peer_mtu = clc->qp_mtu;
447} 444}
448 445
446static void smc_switch_to_fallback(struct smc_sock *smc)
447{
448 smc->use_fallback = true;
449 if (smc->sk.sk_socket && smc->sk.sk_socket->file) {
450 smc->clcsock->file = smc->sk.sk_socket->file;
451 smc->clcsock->file->private_data = smc->clcsock;
452 }
453}
454
449/* fall back during connect */ 455/* fall back during connect */
450static int smc_connect_fallback(struct smc_sock *smc, int reason_code) 456static int smc_connect_fallback(struct smc_sock *smc, int reason_code)
451{ 457{
452 smc->use_fallback = true; 458 smc_switch_to_fallback(smc);
453 smc->fallback_rsn = reason_code; 459 smc->fallback_rsn = reason_code;
454 smc_copy_sock_settings_to_clc(smc); 460 smc_copy_sock_settings_to_clc(smc);
461 smc->connect_nonblock = 0;
455 if (smc->sk.sk_state == SMC_INIT) 462 if (smc->sk.sk_state == SMC_INIT)
456 smc->sk.sk_state = SMC_ACTIVE; 463 smc->sk.sk_state = SMC_ACTIVE;
457 return 0; 464 return 0;
@@ -491,46 +498,41 @@ static int smc_connect_abort(struct smc_sock *smc, int reason_code,
491 mutex_unlock(&smc_client_lgr_pending); 498 mutex_unlock(&smc_client_lgr_pending);
492 499
493 smc_conn_free(&smc->conn); 500 smc_conn_free(&smc->conn);
501 smc->connect_nonblock = 0;
494 return reason_code; 502 return reason_code;
495} 503}
496 504
497/* check if there is a rdma device available for this connection. */ 505/* check if there is a rdma device available for this connection. */
498/* called for connect and listen */ 506/* called for connect and listen */
499static int smc_check_rdma(struct smc_sock *smc, struct smc_ib_device **ibdev, 507static int smc_find_rdma_device(struct smc_sock *smc, struct smc_init_info *ini)
500 u8 *ibport, unsigned short vlan_id, u8 gid[])
501{ 508{
502 int reason_code = 0;
503
504 /* PNET table look up: search active ib_device and port 509 /* PNET table look up: search active ib_device and port
505 * within same PNETID that also contains the ethernet device 510 * within same PNETID that also contains the ethernet device
506 * used for the internal TCP socket 511 * used for the internal TCP socket
507 */ 512 */
508 smc_pnet_find_roce_resource(smc->clcsock->sk, ibdev, ibport, vlan_id, 513 smc_pnet_find_roce_resource(smc->clcsock->sk, ini);
509 gid); 514 if (!ini->ib_dev)
510 if (!(*ibdev)) 515 return SMC_CLC_DECL_NOSMCRDEV;
511 reason_code = SMC_CLC_DECL_CNFERR; /* configuration error */ 516 return 0;
512
513 return reason_code;
514} 517}
515 518
516/* check if there is an ISM device available for this connection. */ 519/* check if there is an ISM device available for this connection. */
517/* called for connect and listen */ 520/* called for connect and listen */
518static int smc_check_ism(struct smc_sock *smc, struct smcd_dev **ismdev) 521static int smc_find_ism_device(struct smc_sock *smc, struct smc_init_info *ini)
519{ 522{
520 /* Find ISM device with same PNETID as connecting interface */ 523 /* Find ISM device with same PNETID as connecting interface */
521 smc_pnet_find_ism_resource(smc->clcsock->sk, ismdev); 524 smc_pnet_find_ism_resource(smc->clcsock->sk, ini);
522 if (!(*ismdev)) 525 if (!ini->ism_dev)
523 return SMC_CLC_DECL_CNFERR; /* configuration error */ 526 return SMC_CLC_DECL_NOSMCDDEV;
524 return 0; 527 return 0;
525} 528}
526 529
527/* Check for VLAN ID and register it on ISM device just for CLC handshake */ 530/* Check for VLAN ID and register it on ISM device just for CLC handshake */
528static int smc_connect_ism_vlan_setup(struct smc_sock *smc, 531static int smc_connect_ism_vlan_setup(struct smc_sock *smc,
529 struct smcd_dev *ismdev, 532 struct smc_init_info *ini)
530 unsigned short vlan_id)
531{ 533{
532 if (vlan_id && smc_ism_get_vlan(ismdev, vlan_id)) 534 if (ini->vlan_id && smc_ism_get_vlan(ini->ism_dev, ini->vlan_id))
533 return SMC_CLC_DECL_CNFERR; 535 return SMC_CLC_DECL_ISMVLANERR;
534 return 0; 536 return 0;
535} 537}
536 538
@@ -538,12 +540,11 @@ static int smc_connect_ism_vlan_setup(struct smc_sock *smc,
538 * used, the VLAN ID will be registered again during the connection setup. 540 * used, the VLAN ID will be registered again during the connection setup.
539 */ 541 */
540static int smc_connect_ism_vlan_cleanup(struct smc_sock *smc, bool is_smcd, 542static int smc_connect_ism_vlan_cleanup(struct smc_sock *smc, bool is_smcd,
541 struct smcd_dev *ismdev, 543 struct smc_init_info *ini)
542 unsigned short vlan_id)
543{ 544{
544 if (!is_smcd) 545 if (!is_smcd)
545 return 0; 546 return 0;
546 if (vlan_id && smc_ism_put_vlan(ismdev, vlan_id)) 547 if (ini->vlan_id && smc_ism_put_vlan(ini->ism_dev, ini->vlan_id))
547 return SMC_CLC_DECL_CNFERR; 548 return SMC_CLC_DECL_CNFERR;
548 return 0; 549 return 0;
549} 550}
@@ -551,13 +552,12 @@ static int smc_connect_ism_vlan_cleanup(struct smc_sock *smc, bool is_smcd,
551/* CLC handshake during connect */ 552/* CLC handshake during connect */
552static int smc_connect_clc(struct smc_sock *smc, int smc_type, 553static int smc_connect_clc(struct smc_sock *smc, int smc_type,
553 struct smc_clc_msg_accept_confirm *aclc, 554 struct smc_clc_msg_accept_confirm *aclc,
554 struct smc_ib_device *ibdev, u8 ibport, 555 struct smc_init_info *ini)
555 u8 gid[], struct smcd_dev *ismdev)
556{ 556{
557 int rc = 0; 557 int rc = 0;
558 558
559 /* do inband token exchange */ 559 /* do inband token exchange */
560 rc = smc_clc_send_proposal(smc, smc_type, ibdev, ibport, gid, ismdev); 560 rc = smc_clc_send_proposal(smc, smc_type, ini);
561 if (rc) 561 if (rc)
562 return rc; 562 return rc;
563 /* receive SMC Accept CLC message */ 563 /* receive SMC Accept CLC message */
@@ -568,23 +568,19 @@ static int smc_connect_clc(struct smc_sock *smc, int smc_type,
568/* setup for RDMA connection of client */ 568/* setup for RDMA connection of client */
569static int smc_connect_rdma(struct smc_sock *smc, 569static int smc_connect_rdma(struct smc_sock *smc,
570 struct smc_clc_msg_accept_confirm *aclc, 570 struct smc_clc_msg_accept_confirm *aclc,
571 struct smc_ib_device *ibdev, u8 ibport) 571 struct smc_init_info *ini)
572{ 572{
573 int local_contact = SMC_FIRST_CONTACT;
574 struct smc_link *link; 573 struct smc_link *link;
575 int reason_code = 0; 574 int reason_code = 0;
576 575
576 ini->is_smcd = false;
577 ini->ib_lcl = &aclc->lcl;
578 ini->ib_clcqpn = ntoh24(aclc->qpn);
579 ini->srv_first_contact = aclc->hdr.flag;
580
577 mutex_lock(&smc_client_lgr_pending); 581 mutex_lock(&smc_client_lgr_pending);
578 local_contact = smc_conn_create(smc, false, aclc->hdr.flag, ibdev, 582 reason_code = smc_conn_create(smc, ini);
579 ibport, ntoh24(aclc->qpn), &aclc->lcl, 583 if (reason_code) {
580 NULL, 0);
581 if (local_contact < 0) {
582 if (local_contact == -ENOMEM)
583 reason_code = SMC_CLC_DECL_MEM;/* insufficient memory*/
584 else if (local_contact == -ENOLINK)
585 reason_code = SMC_CLC_DECL_SYNCERR; /* synchr. error */
586 else
587 reason_code = SMC_CLC_DECL_INTERR; /* other error */
588 mutex_unlock(&smc_client_lgr_pending); 584 mutex_unlock(&smc_client_lgr_pending);
589 return reason_code; 585 return reason_code;
590 } 586 }
@@ -594,45 +590,48 @@ static int smc_connect_rdma(struct smc_sock *smc,
594 590
595 /* create send buffer and rmb */ 591 /* create send buffer and rmb */
596 if (smc_buf_create(smc, false)) 592 if (smc_buf_create(smc, false))
597 return smc_connect_abort(smc, SMC_CLC_DECL_MEM, local_contact); 593 return smc_connect_abort(smc, SMC_CLC_DECL_MEM,
594 ini->cln_first_contact);
598 595
599 if (local_contact == SMC_FIRST_CONTACT) 596 if (ini->cln_first_contact == SMC_FIRST_CONTACT)
600 smc_link_save_peer_info(link, aclc); 597 smc_link_save_peer_info(link, aclc);
601 598
602 if (smc_rmb_rtoken_handling(&smc->conn, aclc)) 599 if (smc_rmb_rtoken_handling(&smc->conn, aclc))
603 return smc_connect_abort(smc, SMC_CLC_DECL_ERR_RTOK, 600 return smc_connect_abort(smc, SMC_CLC_DECL_ERR_RTOK,
604 local_contact); 601 ini->cln_first_contact);
605 602
606 smc_close_init(smc); 603 smc_close_init(smc);
607 smc_rx_init(smc); 604 smc_rx_init(smc);
608 605
609 if (local_contact == SMC_FIRST_CONTACT) { 606 if (ini->cln_first_contact == SMC_FIRST_CONTACT) {
610 if (smc_ib_ready_link(link)) 607 if (smc_ib_ready_link(link))
611 return smc_connect_abort(smc, SMC_CLC_DECL_ERR_RDYLNK, 608 return smc_connect_abort(smc, SMC_CLC_DECL_ERR_RDYLNK,
612 local_contact); 609 ini->cln_first_contact);
613 } else { 610 } else {
614 if (smc_reg_rmb(link, smc->conn.rmb_desc, true)) 611 if (smc_reg_rmb(link, smc->conn.rmb_desc, true))
615 return smc_connect_abort(smc, SMC_CLC_DECL_ERR_REGRMB, 612 return smc_connect_abort(smc, SMC_CLC_DECL_ERR_REGRMB,
616 local_contact); 613 ini->cln_first_contact);
617 } 614 }
618 smc_rmb_sync_sg_for_device(&smc->conn); 615 smc_rmb_sync_sg_for_device(&smc->conn);
619 616
620 reason_code = smc_clc_send_confirm(smc); 617 reason_code = smc_clc_send_confirm(smc);
621 if (reason_code) 618 if (reason_code)
622 return smc_connect_abort(smc, reason_code, local_contact); 619 return smc_connect_abort(smc, reason_code,
620 ini->cln_first_contact);
623 621
624 smc_tx_init(smc); 622 smc_tx_init(smc);
625 623
626 if (local_contact == SMC_FIRST_CONTACT) { 624 if (ini->cln_first_contact == SMC_FIRST_CONTACT) {
627 /* QP confirmation over RoCE fabric */ 625 /* QP confirmation over RoCE fabric */
628 reason_code = smc_clnt_conf_first_link(smc); 626 reason_code = smc_clnt_conf_first_link(smc);
629 if (reason_code) 627 if (reason_code)
630 return smc_connect_abort(smc, reason_code, 628 return smc_connect_abort(smc, reason_code,
631 local_contact); 629 ini->cln_first_contact);
632 } 630 }
633 mutex_unlock(&smc_client_lgr_pending); 631 mutex_unlock(&smc_client_lgr_pending);
634 632
635 smc_copy_sock_settings_to_clc(smc); 633 smc_copy_sock_settings_to_clc(smc);
634 smc->connect_nonblock = 0;
636 if (smc->sk.sk_state == SMC_INIT) 635 if (smc->sk.sk_state == SMC_INIT)
637 smc->sk.sk_state = SMC_ACTIVE; 636 smc->sk.sk_state = SMC_ACTIVE;
638 637
@@ -642,23 +641,26 @@ static int smc_connect_rdma(struct smc_sock *smc,
642/* setup for ISM connection of client */ 641/* setup for ISM connection of client */
643static int smc_connect_ism(struct smc_sock *smc, 642static int smc_connect_ism(struct smc_sock *smc,
644 struct smc_clc_msg_accept_confirm *aclc, 643 struct smc_clc_msg_accept_confirm *aclc,
645 struct smcd_dev *ismdev) 644 struct smc_init_info *ini)
646{ 645{
647 int local_contact = SMC_FIRST_CONTACT;
648 int rc = 0; 646 int rc = 0;
649 647
648 ini->is_smcd = true;
649 ini->ism_gid = aclc->gid;
650 ini->srv_first_contact = aclc->hdr.flag;
651
650 /* there is only one lgr role for SMC-D; use server lock */ 652 /* there is only one lgr role for SMC-D; use server lock */
651 mutex_lock(&smc_server_lgr_pending); 653 mutex_lock(&smc_server_lgr_pending);
652 local_contact = smc_conn_create(smc, true, aclc->hdr.flag, NULL, 0, 0, 654 rc = smc_conn_create(smc, ini);
653 NULL, ismdev, aclc->gid); 655 if (rc) {
654 if (local_contact < 0) {
655 mutex_unlock(&smc_server_lgr_pending); 656 mutex_unlock(&smc_server_lgr_pending);
656 return SMC_CLC_DECL_MEM; 657 return rc;
657 } 658 }
658 659
659 /* Create send and receive buffers */ 660 /* Create send and receive buffers */
660 if (smc_buf_create(smc, true)) 661 if (smc_buf_create(smc, true))
661 return smc_connect_abort(smc, SMC_CLC_DECL_MEM, local_contact); 662 return smc_connect_abort(smc, SMC_CLC_DECL_MEM,
663 ini->cln_first_contact);
662 664
663 smc_conn_save_peer_info(smc, aclc); 665 smc_conn_save_peer_info(smc, aclc);
664 smc_close_init(smc); 666 smc_close_init(smc);
@@ -667,10 +669,11 @@ static int smc_connect_ism(struct smc_sock *smc,
667 669
668 rc = smc_clc_send_confirm(smc); 670 rc = smc_clc_send_confirm(smc);
669 if (rc) 671 if (rc)
670 return smc_connect_abort(smc, rc, local_contact); 672 return smc_connect_abort(smc, rc, ini->cln_first_contact);
671 mutex_unlock(&smc_server_lgr_pending); 673 mutex_unlock(&smc_server_lgr_pending);
672 674
673 smc_copy_sock_settings_to_clc(smc); 675 smc_copy_sock_settings_to_clc(smc);
676 smc->connect_nonblock = 0;
674 if (smc->sk.sk_state == SMC_INIT) 677 if (smc->sk.sk_state == SMC_INIT)
675 smc->sk.sk_state = SMC_ACTIVE; 678 smc->sk.sk_state = SMC_ACTIVE;
676 679
@@ -682,13 +685,9 @@ static int __smc_connect(struct smc_sock *smc)
682{ 685{
683 bool ism_supported = false, rdma_supported = false; 686 bool ism_supported = false, rdma_supported = false;
684 struct smc_clc_msg_accept_confirm aclc; 687 struct smc_clc_msg_accept_confirm aclc;
685 struct smc_ib_device *ibdev; 688 struct smc_init_info ini = {0};
686 struct smcd_dev *ismdev;
687 u8 gid[SMC_GID_SIZE];
688 unsigned short vlan;
689 int smc_type; 689 int smc_type;
690 int rc = 0; 690 int rc = 0;
691 u8 ibport;
692 691
693 sock_hold(&smc->sk); /* sock put in passive closing */ 692 sock_hold(&smc->sk); /* sock put in passive closing */
694 693
@@ -703,20 +702,21 @@ static int __smc_connect(struct smc_sock *smc)
703 if (using_ipsec(smc)) 702 if (using_ipsec(smc))
704 return smc_connect_decline_fallback(smc, SMC_CLC_DECL_IPSEC); 703 return smc_connect_decline_fallback(smc, SMC_CLC_DECL_IPSEC);
705 704
706 /* check for VLAN ID */ 705 /* get vlan id from IP device */
707 if (smc_vlan_by_tcpsk(smc->clcsock, &vlan)) 706 if (smc_vlan_by_tcpsk(smc->clcsock, &ini))
708 return smc_connect_decline_fallback(smc, SMC_CLC_DECL_CNFERR); 707 return smc_connect_decline_fallback(smc,
708 SMC_CLC_DECL_GETVLANERR);
709 709
710 /* check if there is an ism device available */ 710 /* check if there is an ism device available */
711 if (!smc_check_ism(smc, &ismdev) && 711 if (!smc_find_ism_device(smc, &ini) &&
712 !smc_connect_ism_vlan_setup(smc, ismdev, vlan)) { 712 !smc_connect_ism_vlan_setup(smc, &ini)) {
713 /* ISM is supported for this connection */ 713 /* ISM is supported for this connection */
714 ism_supported = true; 714 ism_supported = true;
715 smc_type = SMC_TYPE_D; 715 smc_type = SMC_TYPE_D;
716 } 716 }
717 717
718 /* check if there is a rdma device available */ 718 /* check if there is a rdma device available */
719 if (!smc_check_rdma(smc, &ibdev, &ibport, vlan, gid)) { 719 if (!smc_find_rdma_device(smc, &ini)) {
720 /* RDMA is supported for this connection */ 720 /* RDMA is supported for this connection */
721 rdma_supported = true; 721 rdma_supported = true;
722 if (ism_supported) 722 if (ism_supported)
@@ -730,25 +730,25 @@ static int __smc_connect(struct smc_sock *smc)
730 return smc_connect_decline_fallback(smc, SMC_CLC_DECL_NOSMCDEV); 730 return smc_connect_decline_fallback(smc, SMC_CLC_DECL_NOSMCDEV);
731 731
732 /* perform CLC handshake */ 732 /* perform CLC handshake */
733 rc = smc_connect_clc(smc, smc_type, &aclc, ibdev, ibport, gid, ismdev); 733 rc = smc_connect_clc(smc, smc_type, &aclc, &ini);
734 if (rc) { 734 if (rc) {
735 smc_connect_ism_vlan_cleanup(smc, ism_supported, ismdev, vlan); 735 smc_connect_ism_vlan_cleanup(smc, ism_supported, &ini);
736 return smc_connect_decline_fallback(smc, rc); 736 return smc_connect_decline_fallback(smc, rc);
737 } 737 }
738 738
739 /* depending on previous steps, connect using rdma or ism */ 739 /* depending on previous steps, connect using rdma or ism */
740 if (rdma_supported && aclc.hdr.path == SMC_TYPE_R) 740 if (rdma_supported && aclc.hdr.path == SMC_TYPE_R)
741 rc = smc_connect_rdma(smc, &aclc, ibdev, ibport); 741 rc = smc_connect_rdma(smc, &aclc, &ini);
742 else if (ism_supported && aclc.hdr.path == SMC_TYPE_D) 742 else if (ism_supported && aclc.hdr.path == SMC_TYPE_D)
743 rc = smc_connect_ism(smc, &aclc, ismdev); 743 rc = smc_connect_ism(smc, &aclc, &ini);
744 else 744 else
745 rc = SMC_CLC_DECL_MODEUNSUPP; 745 rc = SMC_CLC_DECL_MODEUNSUPP;
746 if (rc) { 746 if (rc) {
747 smc_connect_ism_vlan_cleanup(smc, ism_supported, ismdev, vlan); 747 smc_connect_ism_vlan_cleanup(smc, ism_supported, &ini);
748 return smc_connect_decline_fallback(smc, rc); 748 return smc_connect_decline_fallback(smc, rc);
749 } 749 }
750 750
751 smc_connect_ism_vlan_cleanup(smc, ism_supported, ismdev, vlan); 751 smc_connect_ism_vlan_cleanup(smc, ism_supported, &ini);
752 return 0; 752 return 0;
753} 753}
754 754
@@ -756,17 +756,30 @@ static void smc_connect_work(struct work_struct *work)
756{ 756{
757 struct smc_sock *smc = container_of(work, struct smc_sock, 757 struct smc_sock *smc = container_of(work, struct smc_sock,
758 connect_work); 758 connect_work);
759 int rc; 759 long timeo = smc->sk.sk_sndtimeo;
760 int rc = 0;
760 761
761 lock_sock(&smc->sk); 762 if (!timeo)
762 rc = kernel_connect(smc->clcsock, &smc->connect_info->addr, 763 timeo = MAX_SCHEDULE_TIMEOUT;
763 smc->connect_info->alen, smc->connect_info->flags); 764 lock_sock(smc->clcsock->sk);
764 if (smc->clcsock->sk->sk_err) { 765 if (smc->clcsock->sk->sk_err) {
765 smc->sk.sk_err = smc->clcsock->sk->sk_err; 766 smc->sk.sk_err = smc->clcsock->sk->sk_err;
766 goto out; 767 } else if ((1 << smc->clcsock->sk->sk_state) &
767 } 768 (TCPF_SYN_SENT | TCP_SYN_RECV)) {
768 if (rc < 0) { 769 rc = sk_stream_wait_connect(smc->clcsock->sk, &timeo);
769 smc->sk.sk_err = -rc; 770 if ((rc == -EPIPE) &&
771 ((1 << smc->clcsock->sk->sk_state) &
772 (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)))
773 rc = 0;
774 }
775 release_sock(smc->clcsock->sk);
776 lock_sock(&smc->sk);
777 if (rc != 0 || smc->sk.sk_err) {
778 smc->sk.sk_state = SMC_CLOSED;
779 if (rc == -EPIPE || rc == -EAGAIN)
780 smc->sk.sk_err = EPIPE;
781 else if (signal_pending(current))
782 smc->sk.sk_err = -sock_intr_errno(timeo);
770 goto out; 783 goto out;
771 } 784 }
772 785
@@ -775,12 +788,14 @@ static void smc_connect_work(struct work_struct *work)
775 smc->sk.sk_err = -rc; 788 smc->sk.sk_err = -rc;
776 789
777out: 790out:
778 if (smc->sk.sk_err) 791 if (!sock_flag(&smc->sk, SOCK_DEAD)) {
779 smc->sk.sk_state_change(&smc->sk); 792 if (smc->sk.sk_err) {
780 else 793 smc->sk.sk_state_change(&smc->sk);
781 smc->sk.sk_write_space(&smc->sk); 794 } else { /* allow polling before and after fallback decision */
782 kfree(smc->connect_info); 795 smc->clcsock->sk->sk_write_space(smc->clcsock->sk);
783 smc->connect_info = NULL; 796 smc->sk.sk_write_space(&smc->sk);
797 }
798 }
784 release_sock(&smc->sk); 799 release_sock(&smc->sk);
785} 800}
786 801
@@ -813,26 +828,18 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr,
813 828
814 smc_copy_sock_settings_to_clc(smc); 829 smc_copy_sock_settings_to_clc(smc);
815 tcp_sk(smc->clcsock->sk)->syn_smc = 1; 830 tcp_sk(smc->clcsock->sk)->syn_smc = 1;
831 if (smc->connect_nonblock) {
832 rc = -EALREADY;
833 goto out;
834 }
835 rc = kernel_connect(smc->clcsock, addr, alen, flags);
836 if (rc && rc != -EINPROGRESS)
837 goto out;
816 if (flags & O_NONBLOCK) { 838 if (flags & O_NONBLOCK) {
817 if (smc->connect_info) { 839 if (schedule_work(&smc->connect_work))
818 rc = -EALREADY; 840 smc->connect_nonblock = 1;
819 goto out;
820 }
821 smc->connect_info = kzalloc(alen + 2 * sizeof(int), GFP_KERNEL);
822 if (!smc->connect_info) {
823 rc = -ENOMEM;
824 goto out;
825 }
826 smc->connect_info->alen = alen;
827 smc->connect_info->flags = flags ^ O_NONBLOCK;
828 memcpy(&smc->connect_info->addr, addr, alen);
829 schedule_work(&smc->connect_work);
830 rc = -EINPROGRESS; 841 rc = -EINPROGRESS;
831 } else { 842 } else {
832 rc = kernel_connect(smc->clcsock, addr, alen, flags);
833 if (rc)
834 goto out;
835
836 rc = __smc_connect(smc); 843 rc = __smc_connect(smc);
837 if (rc < 0) 844 if (rc < 0)
838 goto out; 845 goto out;
@@ -872,11 +879,11 @@ static int smc_clcsock_accept(struct smc_sock *lsmc, struct smc_sock **new_smc)
872 if (rc < 0) 879 if (rc < 0)
873 lsk->sk_err = -rc; 880 lsk->sk_err = -rc;
874 if (rc < 0 || lsk->sk_state == SMC_CLOSED) { 881 if (rc < 0 || lsk->sk_state == SMC_CLOSED) {
882 new_sk->sk_prot->unhash(new_sk);
875 if (new_clcsock) 883 if (new_clcsock)
876 sock_release(new_clcsock); 884 sock_release(new_clcsock);
877 new_sk->sk_state = SMC_CLOSED; 885 new_sk->sk_state = SMC_CLOSED;
878 sock_set_flag(new_sk, SOCK_DEAD); 886 sock_set_flag(new_sk, SOCK_DEAD);
879 new_sk->sk_prot->unhash(new_sk);
880 sock_put(new_sk); /* final */ 887 sock_put(new_sk); /* final */
881 *new_smc = NULL; 888 *new_smc = NULL;
882 goto out; 889 goto out;
@@ -927,16 +934,21 @@ struct sock *smc_accept_dequeue(struct sock *parent,
927 934
928 smc_accept_unlink(new_sk); 935 smc_accept_unlink(new_sk);
929 if (new_sk->sk_state == SMC_CLOSED) { 936 if (new_sk->sk_state == SMC_CLOSED) {
937 new_sk->sk_prot->unhash(new_sk);
930 if (isk->clcsock) { 938 if (isk->clcsock) {
931 sock_release(isk->clcsock); 939 sock_release(isk->clcsock);
932 isk->clcsock = NULL; 940 isk->clcsock = NULL;
933 } 941 }
934 new_sk->sk_prot->unhash(new_sk);
935 sock_put(new_sk); /* final */ 942 sock_put(new_sk); /* final */
936 continue; 943 continue;
937 } 944 }
938 if (new_sock) 945 if (new_sock) {
939 sock_graft(new_sk, new_sock); 946 sock_graft(new_sk, new_sock);
947 if (isk->use_fallback) {
948 smc_sk(new_sk)->clcsock->file = new_sock->file;
949 isk->clcsock->file->private_data = isk->clcsock;
950 }
951 }
940 return new_sk; 952 return new_sk;
941 } 953 }
942 return NULL; 954 return NULL;
@@ -956,6 +968,7 @@ void smc_close_non_accepted(struct sock *sk)
956 sock_set_flag(sk, SOCK_DEAD); 968 sock_set_flag(sk, SOCK_DEAD);
957 sk->sk_shutdown |= SHUTDOWN_MASK; 969 sk->sk_shutdown |= SHUTDOWN_MASK;
958 } 970 }
971 sk->sk_prot->unhash(sk);
959 if (smc->clcsock) { 972 if (smc->clcsock) {
960 struct socket *tcp; 973 struct socket *tcp;
961 974
@@ -971,7 +984,6 @@ void smc_close_non_accepted(struct sock *sk)
971 smc_conn_free(&smc->conn); 984 smc_conn_free(&smc->conn);
972 } 985 }
973 release_sock(sk); 986 release_sock(sk);
974 sk->sk_prot->unhash(sk);
975 sock_put(sk); /* final sock_put */ 987 sock_put(sk); /* final sock_put */
976} 988}
977 989
@@ -1037,13 +1049,13 @@ static void smc_listen_out(struct smc_sock *new_smc)
1037 struct smc_sock *lsmc = new_smc->listen_smc; 1049 struct smc_sock *lsmc = new_smc->listen_smc;
1038 struct sock *newsmcsk = &new_smc->sk; 1050 struct sock *newsmcsk = &new_smc->sk;
1039 1051
1040 lock_sock_nested(&lsmc->sk, SINGLE_DEPTH_NESTING);
1041 if (lsmc->sk.sk_state == SMC_LISTEN) { 1052 if (lsmc->sk.sk_state == SMC_LISTEN) {
1053 lock_sock_nested(&lsmc->sk, SINGLE_DEPTH_NESTING);
1042 smc_accept_enqueue(&lsmc->sk, newsmcsk); 1054 smc_accept_enqueue(&lsmc->sk, newsmcsk);
1055 release_sock(&lsmc->sk);
1043 } else { /* no longer listening */ 1056 } else { /* no longer listening */
1044 smc_close_non_accepted(newsmcsk); 1057 smc_close_non_accepted(newsmcsk);
1045 } 1058 }
1046 release_sock(&lsmc->sk);
1047 1059
1048 /* Wake up accept */ 1060 /* Wake up accept */
1049 lsmc->sk.sk_data_ready(&lsmc->sk); 1061 lsmc->sk.sk_data_ready(&lsmc->sk);
@@ -1087,7 +1099,7 @@ static void smc_listen_decline(struct smc_sock *new_smc, int reason_code,
1087 return; 1099 return;
1088 } 1100 }
1089 smc_conn_free(&new_smc->conn); 1101 smc_conn_free(&new_smc->conn);
1090 new_smc->use_fallback = true; 1102 smc_switch_to_fallback(new_smc);
1091 new_smc->fallback_rsn = reason_code; 1103 new_smc->fallback_rsn = reason_code;
1092 if (reason_code && reason_code != SMC_CLC_DECL_PEERDECL) { 1104 if (reason_code && reason_code != SMC_CLC_DECL_PEERDECL) {
1093 if (smc_clc_send_decline(new_smc, reason_code) < 0) { 1105 if (smc_clc_send_decline(new_smc, reason_code) < 0) {
@@ -1099,7 +1111,7 @@ static void smc_listen_decline(struct smc_sock *new_smc, int reason_code,
1099} 1111}
1100 1112
1101/* listen worker: check prefixes */ 1113/* listen worker: check prefixes */
1102static int smc_listen_rdma_check(struct smc_sock *new_smc, 1114static int smc_listen_prfx_check(struct smc_sock *new_smc,
1103 struct smc_clc_msg_proposal *pclc) 1115 struct smc_clc_msg_proposal *pclc)
1104{ 1116{
1105 struct smc_clc_msg_proposal_prefix *pclc_prfx; 1117 struct smc_clc_msg_proposal_prefix *pclc_prfx;
@@ -1107,25 +1119,21 @@ static int smc_listen_rdma_check(struct smc_sock *new_smc,
1107 1119
1108 pclc_prfx = smc_clc_proposal_get_prefix(pclc); 1120 pclc_prfx = smc_clc_proposal_get_prefix(pclc);
1109 if (smc_clc_prfx_match(newclcsock, pclc_prfx)) 1121 if (smc_clc_prfx_match(newclcsock, pclc_prfx))
1110 return SMC_CLC_DECL_CNFERR; 1122 return SMC_CLC_DECL_DIFFPREFIX;
1111 1123
1112 return 0; 1124 return 0;
1113} 1125}
1114 1126
1115/* listen worker: initialize connection and buffers */ 1127/* listen worker: initialize connection and buffers */
1116static int smc_listen_rdma_init(struct smc_sock *new_smc, 1128static int smc_listen_rdma_init(struct smc_sock *new_smc,
1117 struct smc_clc_msg_proposal *pclc, 1129 struct smc_init_info *ini)
1118 struct smc_ib_device *ibdev, u8 ibport,
1119 int *local_contact)
1120{ 1130{
1131 int rc;
1132
1121 /* allocate connection / link group */ 1133 /* allocate connection / link group */
1122 *local_contact = smc_conn_create(new_smc, false, 0, ibdev, ibport, 0, 1134 rc = smc_conn_create(new_smc, ini);
1123 &pclc->lcl, NULL, 0); 1135 if (rc)
1124 if (*local_contact < 0) { 1136 return rc;
1125 if (*local_contact == -ENOMEM)
1126 return SMC_CLC_DECL_MEM;/* insufficient memory*/
1127 return SMC_CLC_DECL_INTERR; /* other error */
1128 }
1129 1137
1130 /* create send buffer and rmb */ 1138 /* create send buffer and rmb */
1131 if (smc_buf_create(new_smc, false)) 1139 if (smc_buf_create(new_smc, false))
@@ -1137,33 +1145,30 @@ static int smc_listen_rdma_init(struct smc_sock *new_smc,
1137/* listen worker: initialize connection and buffers for SMC-D */ 1145/* listen worker: initialize connection and buffers for SMC-D */
1138static int smc_listen_ism_init(struct smc_sock *new_smc, 1146static int smc_listen_ism_init(struct smc_sock *new_smc,
1139 struct smc_clc_msg_proposal *pclc, 1147 struct smc_clc_msg_proposal *pclc,
1140 struct smcd_dev *ismdev, 1148 struct smc_init_info *ini)
1141 int *local_contact)
1142{ 1149{
1143 struct smc_clc_msg_smcd *pclc_smcd; 1150 struct smc_clc_msg_smcd *pclc_smcd;
1151 int rc;
1144 1152
1145 pclc_smcd = smc_get_clc_msg_smcd(pclc); 1153 pclc_smcd = smc_get_clc_msg_smcd(pclc);
1146 *local_contact = smc_conn_create(new_smc, true, 0, NULL, 0, 0, NULL, 1154 ini->ism_gid = pclc_smcd->gid;
1147 ismdev, pclc_smcd->gid); 1155 rc = smc_conn_create(new_smc, ini);
1148 if (*local_contact < 0) { 1156 if (rc)
1149 if (*local_contact == -ENOMEM) 1157 return rc;
1150 return SMC_CLC_DECL_MEM;/* insufficient memory*/
1151 return SMC_CLC_DECL_INTERR; /* other error */
1152 }
1153 1158
1154 /* Check if peer can be reached via ISM device */ 1159 /* Check if peer can be reached via ISM device */
1155 if (smc_ism_cantalk(new_smc->conn.lgr->peer_gid, 1160 if (smc_ism_cantalk(new_smc->conn.lgr->peer_gid,
1156 new_smc->conn.lgr->vlan_id, 1161 new_smc->conn.lgr->vlan_id,
1157 new_smc->conn.lgr->smcd)) { 1162 new_smc->conn.lgr->smcd)) {
1158 if (*local_contact == SMC_FIRST_CONTACT) 1163 if (ini->cln_first_contact == SMC_FIRST_CONTACT)
1159 smc_lgr_forget(new_smc->conn.lgr); 1164 smc_lgr_forget(new_smc->conn.lgr);
1160 smc_conn_free(&new_smc->conn); 1165 smc_conn_free(&new_smc->conn);
1161 return SMC_CLC_DECL_CNFERR; 1166 return SMC_CLC_DECL_SMCDNOTALK;
1162 } 1167 }
1163 1168
1164 /* Create send and receive buffers */ 1169 /* Create send and receive buffers */
1165 if (smc_buf_create(new_smc, true)) { 1170 if (smc_buf_create(new_smc, true)) {
1166 if (*local_contact == SMC_FIRST_CONTACT) 1171 if (ini->cln_first_contact == SMC_FIRST_CONTACT)
1167 smc_lgr_forget(new_smc->conn.lgr); 1172 smc_lgr_forget(new_smc->conn.lgr);
1168 smc_conn_free(&new_smc->conn); 1173 smc_conn_free(&new_smc->conn);
1169 return SMC_CLC_DECL_MEM; 1174 return SMC_CLC_DECL_MEM;
@@ -1227,15 +1232,13 @@ static void smc_listen_work(struct work_struct *work)
1227 struct socket *newclcsock = new_smc->clcsock; 1232 struct socket *newclcsock = new_smc->clcsock;
1228 struct smc_clc_msg_accept_confirm cclc; 1233 struct smc_clc_msg_accept_confirm cclc;
1229 struct smc_clc_msg_proposal *pclc; 1234 struct smc_clc_msg_proposal *pclc;
1230 struct smc_ib_device *ibdev; 1235 struct smc_init_info ini = {0};
1231 bool ism_supported = false; 1236 bool ism_supported = false;
1232 struct smcd_dev *ismdev;
1233 u8 buf[SMC_CLC_MAX_LEN]; 1237 u8 buf[SMC_CLC_MAX_LEN];
1234 int local_contact = 0;
1235 unsigned short vlan;
1236 int reason_code = 0;
1237 int rc = 0; 1238 int rc = 0;
1238 u8 ibport; 1239
1240 if (new_smc->listen_smc->sk.sk_state != SMC_LISTEN)
1241 return smc_listen_out_err(new_smc);
1239 1242
1240 if (new_smc->use_fallback) { 1243 if (new_smc->use_fallback) {
1241 smc_listen_out_connected(new_smc); 1244 smc_listen_out_connected(new_smc);
@@ -1244,7 +1247,7 @@ static void smc_listen_work(struct work_struct *work)
1244 1247
1245 /* check if peer is smc capable */ 1248 /* check if peer is smc capable */
1246 if (!tcp_sk(newclcsock->sk)->syn_smc) { 1249 if (!tcp_sk(newclcsock->sk)->syn_smc) {
1247 new_smc->use_fallback = true; 1250 smc_switch_to_fallback(new_smc);
1248 new_smc->fallback_rsn = SMC_CLC_DECL_PEERNOSMC; 1251 new_smc->fallback_rsn = SMC_CLC_DECL_PEERNOSMC;
1249 smc_listen_out_connected(new_smc); 1252 smc_listen_out_connected(new_smc);
1250 return; 1253 return;
@@ -1254,17 +1257,26 @@ static void smc_listen_work(struct work_struct *work)
1254 * wait for and receive SMC Proposal CLC message 1257 * wait for and receive SMC Proposal CLC message
1255 */ 1258 */
1256 pclc = (struct smc_clc_msg_proposal *)&buf; 1259 pclc = (struct smc_clc_msg_proposal *)&buf;
1257 reason_code = smc_clc_wait_msg(new_smc, pclc, SMC_CLC_MAX_LEN, 1260 rc = smc_clc_wait_msg(new_smc, pclc, SMC_CLC_MAX_LEN,
1258 SMC_CLC_PROPOSAL, CLC_WAIT_TIME); 1261 SMC_CLC_PROPOSAL, CLC_WAIT_TIME);
1259 if (reason_code) { 1262 if (rc)
1260 smc_listen_decline(new_smc, reason_code, 0); 1263 goto out_decl;
1261 return;
1262 }
1263 1264
1264 /* IPSec connections opt out of SMC-R optimizations */ 1265 /* IPSec connections opt out of SMC-R optimizations */
1265 if (using_ipsec(new_smc)) { 1266 if (using_ipsec(new_smc)) {
1266 smc_listen_decline(new_smc, SMC_CLC_DECL_IPSEC, 0); 1267 rc = SMC_CLC_DECL_IPSEC;
1267 return; 1268 goto out_decl;
1269 }
1270
1271 /* check for matching IP prefix and subnet length */
1272 rc = smc_listen_prfx_check(new_smc, pclc);
1273 if (rc)
1274 goto out_decl;
1275
1276 /* get vlan id from IP device */
1277 if (smc_vlan_by_tcpsk(new_smc->clcsock, &ini)) {
1278 rc = SMC_CLC_DECL_GETVLANERR;
1279 goto out_decl;
1268 } 1280 }
1269 1281
1270 mutex_lock(&smc_server_lgr_pending); 1282 mutex_lock(&smc_server_lgr_pending);
@@ -1273,59 +1285,73 @@ static void smc_listen_work(struct work_struct *work)
1273 smc_tx_init(new_smc); 1285 smc_tx_init(new_smc);
1274 1286
1275 /* check if ISM is available */ 1287 /* check if ISM is available */
1276 if ((pclc->hdr.path == SMC_TYPE_D || pclc->hdr.path == SMC_TYPE_B) && 1288 if (pclc->hdr.path == SMC_TYPE_D || pclc->hdr.path == SMC_TYPE_B) {
1277 !smc_check_ism(new_smc, &ismdev) && 1289 ini.is_smcd = true; /* prepare ISM check */
1278 !smc_listen_ism_init(new_smc, pclc, ismdev, &local_contact)) { 1290 rc = smc_find_ism_device(new_smc, &ini);
1279 ism_supported = true; 1291 if (!rc)
1292 rc = smc_listen_ism_init(new_smc, pclc, &ini);
1293 if (!rc)
1294 ism_supported = true;
1295 else if (pclc->hdr.path == SMC_TYPE_D)
1296 goto out_unlock; /* skip RDMA and decline */
1280 } 1297 }
1281 1298
1282 /* check if RDMA is available */ 1299 /* check if RDMA is available */
1283 if (!ism_supported && 1300 if (!ism_supported) { /* SMC_TYPE_R or SMC_TYPE_B */
1284 ((pclc->hdr.path != SMC_TYPE_R && pclc->hdr.path != SMC_TYPE_B) || 1301 /* prepare RDMA check */
1285 smc_vlan_by_tcpsk(new_smc->clcsock, &vlan) || 1302 memset(&ini, 0, sizeof(ini));
1286 smc_check_rdma(new_smc, &ibdev, &ibport, vlan, NULL) || 1303 ini.is_smcd = false;
1287 smc_listen_rdma_check(new_smc, pclc) || 1304 ini.ib_lcl = &pclc->lcl;
1288 smc_listen_rdma_init(new_smc, pclc, ibdev, ibport, 1305 rc = smc_find_rdma_device(new_smc, &ini);
1289 &local_contact) || 1306 if (rc) {
1290 smc_listen_rdma_reg(new_smc, local_contact))) { 1307 /* no RDMA device found */
1291 /* SMC not supported, decline */ 1308 if (pclc->hdr.path == SMC_TYPE_B)
1292 mutex_unlock(&smc_server_lgr_pending); 1309 /* neither ISM nor RDMA device found */
1293 smc_listen_decline(new_smc, SMC_CLC_DECL_MODEUNSUPP, 1310 rc = SMC_CLC_DECL_NOSMCDEV;
1294 local_contact); 1311 goto out_unlock;
1295 return; 1312 }
1313 rc = smc_listen_rdma_init(new_smc, &ini);
1314 if (rc)
1315 goto out_unlock;
1316 rc = smc_listen_rdma_reg(new_smc, ini.cln_first_contact);
1317 if (rc)
1318 goto out_unlock;
1296 } 1319 }
1297 1320
1298 /* send SMC Accept CLC message */ 1321 /* send SMC Accept CLC message */
1299 rc = smc_clc_send_accept(new_smc, local_contact); 1322 rc = smc_clc_send_accept(new_smc, ini.cln_first_contact);
1300 if (rc) { 1323 if (rc)
1301 mutex_unlock(&smc_server_lgr_pending); 1324 goto out_unlock;
1302 smc_listen_decline(new_smc, rc, local_contact);
1303 return;
1304 }
1305 1325
1306 /* SMC-D does not need this lock any more */ 1326 /* SMC-D does not need this lock any more */
1307 if (ism_supported) 1327 if (ism_supported)
1308 mutex_unlock(&smc_server_lgr_pending); 1328 mutex_unlock(&smc_server_lgr_pending);
1309 1329
1310 /* receive SMC Confirm CLC message */ 1330 /* receive SMC Confirm CLC message */
1311 reason_code = smc_clc_wait_msg(new_smc, &cclc, sizeof(cclc), 1331 rc = smc_clc_wait_msg(new_smc, &cclc, sizeof(cclc),
1312 SMC_CLC_CONFIRM, CLC_WAIT_TIME); 1332 SMC_CLC_CONFIRM, CLC_WAIT_TIME);
1313 if (reason_code) { 1333 if (rc) {
1314 if (!ism_supported) 1334 if (!ism_supported)
1315 mutex_unlock(&smc_server_lgr_pending); 1335 goto out_unlock;
1316 smc_listen_decline(new_smc, reason_code, local_contact); 1336 goto out_decl;
1317 return;
1318 } 1337 }
1319 1338
1320 /* finish worker */ 1339 /* finish worker */
1321 if (!ism_supported) { 1340 if (!ism_supported) {
1322 rc = smc_listen_rdma_finish(new_smc, &cclc, local_contact); 1341 rc = smc_listen_rdma_finish(new_smc, &cclc,
1342 ini.cln_first_contact);
1323 mutex_unlock(&smc_server_lgr_pending); 1343 mutex_unlock(&smc_server_lgr_pending);
1324 if (rc) 1344 if (rc)
1325 return; 1345 return;
1326 } 1346 }
1327 smc_conn_save_peer_info(new_smc, &cclc); 1347 smc_conn_save_peer_info(new_smc, &cclc);
1328 smc_listen_out_connected(new_smc); 1348 smc_listen_out_connected(new_smc);
1349 return;
1350
1351out_unlock:
1352 mutex_unlock(&smc_server_lgr_pending);
1353out_decl:
1354 smc_listen_decline(new_smc, rc, ini.cln_first_contact);
1329} 1355}
1330 1356
1331static void smc_tcp_listen_work(struct work_struct *work) 1357static void smc_tcp_listen_work(struct work_struct *work)
@@ -1501,7 +1527,7 @@ static int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
1501 1527
1502 if (msg->msg_flags & MSG_FASTOPEN) { 1528 if (msg->msg_flags & MSG_FASTOPEN) {
1503 if (sk->sk_state == SMC_INIT) { 1529 if (sk->sk_state == SMC_INIT) {
1504 smc->use_fallback = true; 1530 smc_switch_to_fallback(smc);
1505 smc->fallback_rsn = SMC_CLC_DECL_OPTUNSUPP; 1531 smc->fallback_rsn = SMC_CLC_DECL_OPTUNSUPP;
1506 } else { 1532 } else {
1507 rc = -EINVAL; 1533 rc = -EINVAL;
@@ -1571,8 +1597,8 @@ static __poll_t smc_poll(struct file *file, struct socket *sock,
1571 poll_table *wait) 1597 poll_table *wait)
1572{ 1598{
1573 struct sock *sk = sock->sk; 1599 struct sock *sk = sock->sk;
1574 __poll_t mask = 0;
1575 struct smc_sock *smc; 1600 struct smc_sock *smc;
1601 __poll_t mask = 0;
1576 1602
1577 if (!sk) 1603 if (!sk)
1578 return EPOLLNVAL; 1604 return EPOLLNVAL;
@@ -1582,8 +1608,6 @@ static __poll_t smc_poll(struct file *file, struct socket *sock,
1582 /* delegate to CLC child sock */ 1608 /* delegate to CLC child sock */
1583 mask = smc->clcsock->ops->poll(file, smc->clcsock, wait); 1609 mask = smc->clcsock->ops->poll(file, smc->clcsock, wait);
1584 sk->sk_err = smc->clcsock->sk->sk_err; 1610 sk->sk_err = smc->clcsock->sk->sk_err;
1585 if (sk->sk_err)
1586 mask |= EPOLLERR;
1587 } else { 1611 } else {
1588 if (sk->sk_state != SMC_CLOSED) 1612 if (sk->sk_state != SMC_CLOSED)
1589 sock_poll_wait(file, sock, wait); 1613 sock_poll_wait(file, sock, wait);
@@ -1594,9 +1618,14 @@ static __poll_t smc_poll(struct file *file, struct socket *sock,
1594 mask |= EPOLLHUP; 1618 mask |= EPOLLHUP;
1595 if (sk->sk_state == SMC_LISTEN) { 1619 if (sk->sk_state == SMC_LISTEN) {
1596 /* woken up by sk_data_ready in smc_listen_work() */ 1620 /* woken up by sk_data_ready in smc_listen_work() */
1597 mask = smc_accept_poll(sk); 1621 mask |= smc_accept_poll(sk);
1622 } else if (smc->use_fallback) { /* as result of connect_work()*/
1623 mask |= smc->clcsock->ops->poll(file, smc->clcsock,
1624 wait);
1625 sk->sk_err = smc->clcsock->sk->sk_err;
1598 } else { 1626 } else {
1599 if (atomic_read(&smc->conn.sndbuf_space) || 1627 if ((sk->sk_state != SMC_INIT &&
1628 atomic_read(&smc->conn.sndbuf_space)) ||
1600 sk->sk_shutdown & SEND_SHUTDOWN) { 1629 sk->sk_shutdown & SEND_SHUTDOWN) {
1601 mask |= EPOLLOUT | EPOLLWRNORM; 1630 mask |= EPOLLOUT | EPOLLWRNORM;
1602 } else { 1631 } else {
@@ -1703,7 +1732,7 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
1703 case TCP_FASTOPEN_NO_COOKIE: 1732 case TCP_FASTOPEN_NO_COOKIE:
1704 /* option not supported by SMC */ 1733 /* option not supported by SMC */
1705 if (sk->sk_state == SMC_INIT) { 1734 if (sk->sk_state == SMC_INIT) {
1706 smc->use_fallback = true; 1735 smc_switch_to_fallback(smc);
1707 smc->fallback_rsn = SMC_CLC_DECL_OPTUNSUPP; 1736 smc->fallback_rsn = SMC_CLC_DECL_OPTUNSUPP;
1708 } else { 1737 } else {
1709 if (!smc->use_fallback) 1738 if (!smc->use_fallback)
diff --git a/net/smc/smc.h b/net/smc/smc.h
index adbdf195eb08..878313f8d6c1 100644
--- a/net/smc/smc.h
+++ b/net/smc/smc.h
@@ -190,18 +190,11 @@ struct smc_connection {
190 u64 peer_token; /* SMC-D token of peer */ 190 u64 peer_token; /* SMC-D token of peer */
191}; 191};
192 192
193struct smc_connect_info {
194 int flags;
195 int alen;
196 struct sockaddr addr;
197};
198
199struct smc_sock { /* smc sock container */ 193struct smc_sock { /* smc sock container */
200 struct sock sk; 194 struct sock sk;
201 struct socket *clcsock; /* internal tcp socket */ 195 struct socket *clcsock; /* internal tcp socket */
202 struct smc_connection conn; /* smc connection */ 196 struct smc_connection conn; /* smc connection */
203 struct smc_sock *listen_smc; /* listen parent */ 197 struct smc_sock *listen_smc; /* listen parent */
204 struct smc_connect_info *connect_info; /* connect address & flags */
205 struct work_struct connect_work; /* handle non-blocking connect*/ 198 struct work_struct connect_work; /* handle non-blocking connect*/
206 struct work_struct tcp_listen_work;/* handle tcp socket accepts */ 199 struct work_struct tcp_listen_work;/* handle tcp socket accepts */
207 struct work_struct smc_listen_work;/* prepare new accept socket */ 200 struct work_struct smc_listen_work;/* prepare new accept socket */
@@ -219,6 +212,10 @@ struct smc_sock { /* smc sock container */
219 * started, waiting for unsent 212 * started, waiting for unsent
220 * data to be sent 213 * data to be sent
221 */ 214 */
215 u8 connect_nonblock : 1;
216 /* non-blocking connect in
217 * flight
218 */
222 struct mutex clcsock_release_lock; 219 struct mutex clcsock_release_lock;
223 /* protects clcsock of a listen 220 /* protects clcsock of a listen
224 * socket 221 * socket
diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
index d53fd588d1f5..745afd82f281 100644
--- a/net/smc/smc_clc.c
+++ b/net/smc/smc_clc.c
@@ -385,8 +385,7 @@ int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info)
385 385
386/* send CLC PROPOSAL message across internal TCP socket */ 386/* send CLC PROPOSAL message across internal TCP socket */
387int smc_clc_send_proposal(struct smc_sock *smc, int smc_type, 387int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
388 struct smc_ib_device *ibdev, u8 ibport, u8 gid[], 388 struct smc_init_info *ini)
389 struct smcd_dev *ismdev)
390{ 389{
391 struct smc_clc_ipv6_prefix ipv6_prfx[SMC_CLC_MAX_V6_PREFIX]; 390 struct smc_clc_ipv6_prefix ipv6_prfx[SMC_CLC_MAX_V6_PREFIX];
392 struct smc_clc_msg_proposal_prefix pclc_prfx; 391 struct smc_clc_msg_proposal_prefix pclc_prfx;
@@ -416,8 +415,9 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
416 /* add SMC-R specifics */ 415 /* add SMC-R specifics */
417 memcpy(pclc.lcl.id_for_peer, local_systemid, 416 memcpy(pclc.lcl.id_for_peer, local_systemid,
418 sizeof(local_systemid)); 417 sizeof(local_systemid));
419 memcpy(&pclc.lcl.gid, gid, SMC_GID_SIZE); 418 memcpy(&pclc.lcl.gid, ini->ib_gid, SMC_GID_SIZE);
420 memcpy(&pclc.lcl.mac, &ibdev->mac[ibport - 1], ETH_ALEN); 419 memcpy(&pclc.lcl.mac, &ini->ib_dev->mac[ini->ib_port - 1],
420 ETH_ALEN);
421 pclc.iparea_offset = htons(0); 421 pclc.iparea_offset = htons(0);
422 } 422 }
423 if (smc_type == SMC_TYPE_D || smc_type == SMC_TYPE_B) { 423 if (smc_type == SMC_TYPE_D || smc_type == SMC_TYPE_B) {
@@ -425,7 +425,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
425 memset(&pclc_smcd, 0, sizeof(pclc_smcd)); 425 memset(&pclc_smcd, 0, sizeof(pclc_smcd));
426 plen += sizeof(pclc_smcd); 426 plen += sizeof(pclc_smcd);
427 pclc.iparea_offset = htons(SMC_CLC_PROPOSAL_MAX_OFFSET); 427 pclc.iparea_offset = htons(SMC_CLC_PROPOSAL_MAX_OFFSET);
428 pclc_smcd.gid = ismdev->local_gid; 428 pclc_smcd.gid = ini->ism_dev->local_gid;
429 } 429 }
430 pclc.hdr.length = htons(plen); 430 pclc.hdr.length = htons(plen);
431 431
diff --git a/net/smc/smc_clc.h b/net/smc/smc_clc.h
index 24658e8c0de4..ca209272e5fa 100644
--- a/net/smc/smc_clc.h
+++ b/net/smc/smc_clc.h
@@ -34,16 +34,22 @@
34#define SMC_CLC_DECL_CNFERR 0x03000000 /* configuration error */ 34#define SMC_CLC_DECL_CNFERR 0x03000000 /* configuration error */
35#define SMC_CLC_DECL_PEERNOSMC 0x03010000 /* peer did not indicate SMC */ 35#define SMC_CLC_DECL_PEERNOSMC 0x03010000 /* peer did not indicate SMC */
36#define SMC_CLC_DECL_IPSEC 0x03020000 /* IPsec usage */ 36#define SMC_CLC_DECL_IPSEC 0x03020000 /* IPsec usage */
37#define SMC_CLC_DECL_NOSMCDEV 0x03030000 /* no SMC device found */ 37#define SMC_CLC_DECL_NOSMCDEV 0x03030000 /* no SMC device found (R or D) */
38#define SMC_CLC_DECL_NOSMCDDEV 0x03030001 /* no SMC-D device found */
39#define SMC_CLC_DECL_NOSMCRDEV 0x03030002 /* no SMC-R device found */
40#define SMC_CLC_DECL_SMCDNOTALK 0x03030003 /* SMC-D dev can't talk to peer */
38#define SMC_CLC_DECL_MODEUNSUPP 0x03040000 /* smc modes do not match (R or D)*/ 41#define SMC_CLC_DECL_MODEUNSUPP 0x03040000 /* smc modes do not match (R or D)*/
39#define SMC_CLC_DECL_RMBE_EC 0x03050000 /* peer has eyecatcher in RMBE */ 42#define SMC_CLC_DECL_RMBE_EC 0x03050000 /* peer has eyecatcher in RMBE */
40#define SMC_CLC_DECL_OPTUNSUPP 0x03060000 /* fastopen sockopt not supported */ 43#define SMC_CLC_DECL_OPTUNSUPP 0x03060000 /* fastopen sockopt not supported */
44#define SMC_CLC_DECL_DIFFPREFIX 0x03070000 /* IP prefix / subnet mismatch */
45#define SMC_CLC_DECL_GETVLANERR 0x03080000 /* err to get vlan id of ip device*/
46#define SMC_CLC_DECL_ISMVLANERR 0x03090000 /* err to reg vlan id on ism dev */
41#define SMC_CLC_DECL_SYNCERR 0x04000000 /* synchronization error */ 47#define SMC_CLC_DECL_SYNCERR 0x04000000 /* synchronization error */
42#define SMC_CLC_DECL_PEERDECL 0x05000000 /* peer declined during handshake */ 48#define SMC_CLC_DECL_PEERDECL 0x05000000 /* peer declined during handshake */
43#define SMC_CLC_DECL_INTERR 0x99990000 /* internal error */ 49#define SMC_CLC_DECL_INTERR 0x09990000 /* internal error */
44#define SMC_CLC_DECL_ERR_RTOK 0x99990001 /* rtoken handling failed */ 50#define SMC_CLC_DECL_ERR_RTOK 0x09990001 /* rtoken handling failed */
45#define SMC_CLC_DECL_ERR_RDYLNK 0x99990002 /* ib ready link failed */ 51#define SMC_CLC_DECL_ERR_RDYLNK 0x09990002 /* ib ready link failed */
46#define SMC_CLC_DECL_ERR_REGRMB 0x99990003 /* reg rmb failed */ 52#define SMC_CLC_DECL_ERR_REGRMB 0x09990003 /* reg rmb failed */
47 53
48struct smc_clc_msg_hdr { /* header1 of clc messages */ 54struct smc_clc_msg_hdr { /* header1 of clc messages */
49 u8 eyecatcher[4]; /* eye catcher */ 55 u8 eyecatcher[4]; /* eye catcher */
@@ -179,6 +185,7 @@ smc_get_clc_msg_smcd(struct smc_clc_msg_proposal *prop)
179} 185}
180 186
181struct smcd_dev; 187struct smcd_dev;
188struct smc_init_info;
182 189
183int smc_clc_prfx_match(struct socket *clcsock, 190int smc_clc_prfx_match(struct socket *clcsock,
184 struct smc_clc_msg_proposal_prefix *prop); 191 struct smc_clc_msg_proposal_prefix *prop);
@@ -186,8 +193,7 @@ int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen,
186 u8 expected_type, unsigned long timeout); 193 u8 expected_type, unsigned long timeout);
187int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info); 194int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info);
188int smc_clc_send_proposal(struct smc_sock *smc, int smc_type, 195int smc_clc_send_proposal(struct smc_sock *smc, int smc_type,
189 struct smc_ib_device *smcibdev, u8 ibport, u8 gid[], 196 struct smc_init_info *ini);
190 struct smcd_dev *ismdev);
191int smc_clc_send_confirm(struct smc_sock *smc); 197int smc_clc_send_confirm(struct smc_sock *smc);
192int smc_clc_send_accept(struct smc_sock *smc, int srv_first_contact); 198int smc_clc_send_accept(struct smc_sock *smc, int srv_first_contact);
193 199
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
index 2ad37e998509..fc06720b53c1 100644
--- a/net/smc/smc_close.c
+++ b/net/smc/smc_close.c
@@ -21,6 +21,22 @@
21 21
22#define SMC_CLOSE_WAIT_LISTEN_CLCSOCK_TIME (5 * HZ) 22#define SMC_CLOSE_WAIT_LISTEN_CLCSOCK_TIME (5 * HZ)
23 23
24/* release the clcsock that is assigned to the smc_sock */
25void smc_clcsock_release(struct smc_sock *smc)
26{
27 struct socket *tcp;
28
29 if (smc->listen_smc && current_work() != &smc->smc_listen_work)
30 cancel_work_sync(&smc->smc_listen_work);
31 mutex_lock(&smc->clcsock_release_lock);
32 if (smc->clcsock) {
33 tcp = smc->clcsock;
34 smc->clcsock = NULL;
35 sock_release(tcp);
36 }
37 mutex_unlock(&smc->clcsock_release_lock);
38}
39
24static void smc_close_cleanup_listen(struct sock *parent) 40static void smc_close_cleanup_listen(struct sock *parent)
25{ 41{
26 struct sock *sk; 42 struct sock *sk;
@@ -321,6 +337,7 @@ static void smc_close_passive_work(struct work_struct *work)
321 close_work); 337 close_work);
322 struct smc_sock *smc = container_of(conn, struct smc_sock, conn); 338 struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
323 struct smc_cdc_conn_state_flags *rxflags; 339 struct smc_cdc_conn_state_flags *rxflags;
340 bool release_clcsock = false;
324 struct sock *sk = &smc->sk; 341 struct sock *sk = &smc->sk;
325 int old_state; 342 int old_state;
326 343
@@ -400,13 +417,13 @@ wakeup:
400 if ((sk->sk_state == SMC_CLOSED) && 417 if ((sk->sk_state == SMC_CLOSED) &&
401 (sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) { 418 (sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) {
402 smc_conn_free(conn); 419 smc_conn_free(conn);
403 if (smc->clcsock) { 420 if (smc->clcsock)
404 sock_release(smc->clcsock); 421 release_clcsock = true;
405 smc->clcsock = NULL;
406 }
407 } 422 }
408 } 423 }
409 release_sock(sk); 424 release_sock(sk);
425 if (release_clcsock)
426 smc_clcsock_release(smc);
410 sock_put(sk); /* sock_hold done by schedulers of close_work */ 427 sock_put(sk); /* sock_hold done by schedulers of close_work */
411} 428}
412 429
diff --git a/net/smc/smc_close.h b/net/smc/smc_close.h
index 19eb6a211c23..e0e3b5df25d2 100644
--- a/net/smc/smc_close.h
+++ b/net/smc/smc_close.h
@@ -23,5 +23,6 @@ void smc_close_wake_tx_prepared(struct smc_sock *smc);
23int smc_close_active(struct smc_sock *smc); 23int smc_close_active(struct smc_sock *smc);
24int smc_close_shutdown_write(struct smc_sock *smc); 24int smc_close_shutdown_write(struct smc_sock *smc);
25void smc_close_init(struct smc_sock *smc); 25void smc_close_init(struct smc_sock *smc);
26void smc_clcsock_release(struct smc_sock *smc);
26 27
27#endif /* SMC_CLOSE_H */ 28#endif /* SMC_CLOSE_H */
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 53a17cfa61af..2d2850adc2a3 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -195,10 +195,7 @@ static void smc_lgr_free_work(struct work_struct *work)
195} 195}
196 196
197/* create a new SMC link group */ 197/* create a new SMC link group */
198static int smc_lgr_create(struct smc_sock *smc, bool is_smcd, 198static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
199 struct smc_ib_device *smcibdev, u8 ibport,
200 char *peer_systemid, unsigned short vlan_id,
201 struct smcd_dev *smcismdev, u64 peer_gid)
202{ 199{
203 struct smc_link_group *lgr; 200 struct smc_link_group *lgr;
204 struct smc_link *lnk; 201 struct smc_link *lnk;
@@ -206,20 +203,21 @@ static int smc_lgr_create(struct smc_sock *smc, bool is_smcd,
206 int rc = 0; 203 int rc = 0;
207 int i; 204 int i;
208 205
209 if (is_smcd && vlan_id) { 206 if (ini->is_smcd && ini->vlan_id) {
210 rc = smc_ism_get_vlan(smcismdev, vlan_id); 207 if (smc_ism_get_vlan(ini->ism_dev, ini->vlan_id)) {
211 if (rc) 208 rc = SMC_CLC_DECL_ISMVLANERR;
212 goto out; 209 goto out;
210 }
213 } 211 }
214 212
215 lgr = kzalloc(sizeof(*lgr), GFP_KERNEL); 213 lgr = kzalloc(sizeof(*lgr), GFP_KERNEL);
216 if (!lgr) { 214 if (!lgr) {
217 rc = -ENOMEM; 215 rc = SMC_CLC_DECL_MEM;
218 goto out; 216 goto out;
219 } 217 }
220 lgr->is_smcd = is_smcd; 218 lgr->is_smcd = ini->is_smcd;
221 lgr->sync_err = 0; 219 lgr->sync_err = 0;
222 lgr->vlan_id = vlan_id; 220 lgr->vlan_id = ini->vlan_id;
223 rwlock_init(&lgr->sndbufs_lock); 221 rwlock_init(&lgr->sndbufs_lock);
224 rwlock_init(&lgr->rmbs_lock); 222 rwlock_init(&lgr->rmbs_lock);
225 rwlock_init(&lgr->conns_lock); 223 rwlock_init(&lgr->conns_lock);
@@ -231,29 +229,32 @@ static int smc_lgr_create(struct smc_sock *smc, bool is_smcd,
231 memcpy(&lgr->id, (u8 *)&smc_lgr_list.num, SMC_LGR_ID_SIZE); 229 memcpy(&lgr->id, (u8 *)&smc_lgr_list.num, SMC_LGR_ID_SIZE);
232 INIT_DELAYED_WORK(&lgr->free_work, smc_lgr_free_work); 230 INIT_DELAYED_WORK(&lgr->free_work, smc_lgr_free_work);
233 lgr->conns_all = RB_ROOT; 231 lgr->conns_all = RB_ROOT;
234 if (is_smcd) { 232 if (ini->is_smcd) {
235 /* SMC-D specific settings */ 233 /* SMC-D specific settings */
236 lgr->peer_gid = peer_gid; 234 lgr->peer_gid = ini->ism_gid;
237 lgr->smcd = smcismdev; 235 lgr->smcd = ini->ism_dev;
238 } else { 236 } else {
239 /* SMC-R specific settings */ 237 /* SMC-R specific settings */
240 lgr->role = smc->listen_smc ? SMC_SERV : SMC_CLNT; 238 lgr->role = smc->listen_smc ? SMC_SERV : SMC_CLNT;
241 memcpy(lgr->peer_systemid, peer_systemid, SMC_SYSTEMID_LEN); 239 memcpy(lgr->peer_systemid, ini->ib_lcl->id_for_peer,
240 SMC_SYSTEMID_LEN);
242 241
243 lnk = &lgr->lnk[SMC_SINGLE_LINK]; 242 lnk = &lgr->lnk[SMC_SINGLE_LINK];
244 /* initialize link */ 243 /* initialize link */
245 lnk->state = SMC_LNK_ACTIVATING; 244 lnk->state = SMC_LNK_ACTIVATING;
246 lnk->link_id = SMC_SINGLE_LINK; 245 lnk->link_id = SMC_SINGLE_LINK;
247 lnk->smcibdev = smcibdev; 246 lnk->smcibdev = ini->ib_dev;
248 lnk->ibport = ibport; 247 lnk->ibport = ini->ib_port;
249 lnk->path_mtu = smcibdev->pattr[ibport - 1].active_mtu; 248 lnk->path_mtu =
250 if (!smcibdev->initialized) 249 ini->ib_dev->pattr[ini->ib_port - 1].active_mtu;
251 smc_ib_setup_per_ibdev(smcibdev); 250 if (!ini->ib_dev->initialized)
251 smc_ib_setup_per_ibdev(ini->ib_dev);
252 get_random_bytes(rndvec, sizeof(rndvec)); 252 get_random_bytes(rndvec, sizeof(rndvec));
253 lnk->psn_initial = rndvec[0] + (rndvec[1] << 8) + 253 lnk->psn_initial = rndvec[0] + (rndvec[1] << 8) +
254 (rndvec[2] << 16); 254 (rndvec[2] << 16);
255 rc = smc_ib_determine_gid(lnk->smcibdev, lnk->ibport, 255 rc = smc_ib_determine_gid(lnk->smcibdev, lnk->ibport,
256 vlan_id, lnk->gid, &lnk->sgid_index); 256 ini->vlan_id, lnk->gid,
257 &lnk->sgid_index);
257 if (rc) 258 if (rc)
258 goto free_lgr; 259 goto free_lgr;
259 rc = smc_llc_link_init(lnk); 260 rc = smc_llc_link_init(lnk);
@@ -289,6 +290,12 @@ clear_llc_lnk:
289free_lgr: 290free_lgr:
290 kfree(lgr); 291 kfree(lgr);
291out: 292out:
293 if (rc < 0) {
294 if (rc == -ENOMEM)
295 rc = SMC_CLC_DECL_MEM;
296 else
297 rc = SMC_CLC_DECL_INTERR;
298 }
292 return rc; 299 return rc;
293} 300}
294 301
@@ -528,13 +535,13 @@ void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid, unsigned short vlan)
528/* Determine vlan of internal TCP socket. 535/* Determine vlan of internal TCP socket.
529 * @vlan_id: address to store the determined vlan id into 536 * @vlan_id: address to store the determined vlan id into
530 */ 537 */
531int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id) 538int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini)
532{ 539{
533 struct dst_entry *dst = sk_dst_get(clcsock->sk); 540 struct dst_entry *dst = sk_dst_get(clcsock->sk);
534 struct net_device *ndev; 541 struct net_device *ndev;
535 int i, nest_lvl, rc = 0; 542 int i, nest_lvl, rc = 0;
536 543
537 *vlan_id = 0; 544 ini->vlan_id = 0;
538 if (!dst) { 545 if (!dst) {
539 rc = -ENOTCONN; 546 rc = -ENOTCONN;
540 goto out; 547 goto out;
@@ -546,7 +553,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id)
546 553
547 ndev = dst->dev; 554 ndev = dst->dev;
548 if (is_vlan_dev(ndev)) { 555 if (is_vlan_dev(ndev)) {
549 *vlan_id = vlan_dev_vlan_id(ndev); 556 ini->vlan_id = vlan_dev_vlan_id(ndev);
550 goto out_rel; 557 goto out_rel;
551 } 558 }
552 559
@@ -560,7 +567,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id)
560 lower = lower->next; 567 lower = lower->next;
561 ndev = (struct net_device *)netdev_lower_get_next(ndev, &lower); 568 ndev = (struct net_device *)netdev_lower_get_next(ndev, &lower);
562 if (is_vlan_dev(ndev)) { 569 if (is_vlan_dev(ndev)) {
563 *vlan_id = vlan_dev_vlan_id(ndev); 570 ini->vlan_id = vlan_dev_vlan_id(ndev);
564 break; 571 break;
565 } 572 }
566 } 573 }
@@ -594,24 +601,16 @@ static bool smcd_lgr_match(struct smc_link_group *lgr,
594} 601}
595 602
596/* create a new SMC connection (and a new link group if necessary) */ 603/* create a new SMC connection (and a new link group if necessary) */
597int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact, 604int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
598 struct smc_ib_device *smcibdev, u8 ibport, u32 clcqpn,
599 struct smc_clc_msg_local *lcl, struct smcd_dev *smcd,
600 u64 peer_gid)
601{ 605{
602 struct smc_connection *conn = &smc->conn; 606 struct smc_connection *conn = &smc->conn;
603 int local_contact = SMC_FIRST_CONTACT;
604 struct smc_link_group *lgr; 607 struct smc_link_group *lgr;
605 unsigned short vlan_id;
606 enum smc_lgr_role role; 608 enum smc_lgr_role role;
607 int rc = 0; 609 int rc = 0;
608 610
611 ini->cln_first_contact = SMC_FIRST_CONTACT;
609 role = smc->listen_smc ? SMC_SERV : SMC_CLNT; 612 role = smc->listen_smc ? SMC_SERV : SMC_CLNT;
610 rc = smc_vlan_by_tcpsk(smc->clcsock, &vlan_id); 613 if (role == SMC_CLNT && ini->srv_first_contact)
611 if (rc)
612 return rc;
613
614 if ((role == SMC_CLNT) && srv_first_contact)
615 /* create new link group as well */ 614 /* create new link group as well */
616 goto create; 615 goto create;
617 616
@@ -619,14 +618,15 @@ int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
619 spin_lock_bh(&smc_lgr_list.lock); 618 spin_lock_bh(&smc_lgr_list.lock);
620 list_for_each_entry(lgr, &smc_lgr_list.list, list) { 619 list_for_each_entry(lgr, &smc_lgr_list.list, list) {
621 write_lock_bh(&lgr->conns_lock); 620 write_lock_bh(&lgr->conns_lock);
622 if ((is_smcd ? smcd_lgr_match(lgr, smcd, peer_gid) : 621 if ((ini->is_smcd ?
623 smcr_lgr_match(lgr, lcl, role, clcqpn)) && 622 smcd_lgr_match(lgr, ini->ism_dev, ini->ism_gid) :
623 smcr_lgr_match(lgr, ini->ib_lcl, role, ini->ib_clcqpn)) &&
624 !lgr->sync_err && 624 !lgr->sync_err &&
625 lgr->vlan_id == vlan_id && 625 lgr->vlan_id == ini->vlan_id &&
626 (role == SMC_CLNT || 626 (role == SMC_CLNT ||
627 lgr->conns_num < SMC_RMBS_PER_LGR_MAX)) { 627 lgr->conns_num < SMC_RMBS_PER_LGR_MAX)) {
628 /* link group found */ 628 /* link group found */
629 local_contact = SMC_REUSE_CONTACT; 629 ini->cln_first_contact = SMC_REUSE_CONTACT;
630 conn->lgr = lgr; 630 conn->lgr = lgr;
631 smc_lgr_register_conn(conn); /* add smc conn to lgr */ 631 smc_lgr_register_conn(conn); /* add smc conn to lgr */
632 if (delayed_work_pending(&lgr->free_work)) 632 if (delayed_work_pending(&lgr->free_work))
@@ -638,19 +638,18 @@ int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
638 } 638 }
639 spin_unlock_bh(&smc_lgr_list.lock); 639 spin_unlock_bh(&smc_lgr_list.lock);
640 640
641 if (role == SMC_CLNT && !srv_first_contact && 641 if (role == SMC_CLNT && !ini->srv_first_contact &&
642 (local_contact == SMC_FIRST_CONTACT)) { 642 ini->cln_first_contact == SMC_FIRST_CONTACT) {
643 /* Server reuses a link group, but Client wants to start 643 /* Server reuses a link group, but Client wants to start
644 * a new one 644 * a new one
645 * send out_of_sync decline, reason synchr. error 645 * send out_of_sync decline, reason synchr. error
646 */ 646 */
647 return -ENOLINK; 647 return SMC_CLC_DECL_SYNCERR;
648 } 648 }
649 649
650create: 650create:
651 if (local_contact == SMC_FIRST_CONTACT) { 651 if (ini->cln_first_contact == SMC_FIRST_CONTACT) {
652 rc = smc_lgr_create(smc, is_smcd, smcibdev, ibport, 652 rc = smc_lgr_create(smc, ini);
653 lcl->id_for_peer, vlan_id, smcd, peer_gid);
654 if (rc) 653 if (rc)
655 goto out; 654 goto out;
656 smc_lgr_register_conn(conn); /* add smc conn to lgr */ 655 smc_lgr_register_conn(conn); /* add smc conn to lgr */
@@ -658,7 +657,7 @@ create:
658 conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE; 657 conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE;
659 conn->local_tx_ctrl.len = SMC_WR_TX_SIZE; 658 conn->local_tx_ctrl.len = SMC_WR_TX_SIZE;
660 conn->urg_state = SMC_URG_READ; 659 conn->urg_state = SMC_URG_READ;
661 if (is_smcd) { 660 if (ini->is_smcd) {
662 conn->rx_off = sizeof(struct smcd_cdc_msg); 661 conn->rx_off = sizeof(struct smcd_cdc_msg);
663 smcd_cdc_rx_init(conn); /* init tasklet for this conn */ 662 smcd_cdc_rx_init(conn); /* init tasklet for this conn */
664 } 663 }
@@ -667,7 +666,7 @@ create:
667#endif 666#endif
668 667
669out: 668out:
670 return rc ? rc : local_contact; 669 return rc;
671} 670}
672 671
673/* convert the RMB size into the compressed notation - minimum 16K. 672/* convert the RMB size into the compressed notation - minimum 16K.
diff --git a/net/smc/smc_core.h b/net/smc/smc_core.h
index 8806d2afa6ed..c00ac61dc129 100644
--- a/net/smc/smc_core.h
+++ b/net/smc/smc_core.h
@@ -229,6 +229,24 @@ struct smc_link_group {
229 }; 229 };
230}; 230};
231 231
232struct smc_clc_msg_local;
233
234struct smc_init_info {
235 u8 is_smcd;
236 unsigned short vlan_id;
237 int srv_first_contact;
238 int cln_first_contact;
239 /* SMC-R */
240 struct smc_clc_msg_local *ib_lcl;
241 struct smc_ib_device *ib_dev;
242 u8 ib_gid[SMC_GID_SIZE];
243 u8 ib_port;
244 u32 ib_clcqpn;
245 /* SMC-D */
246 u64 ism_gid;
247 struct smcd_dev *ism_dev;
248};
249
232/* Find the connection associated with the given alert token in the link group. 250/* Find the connection associated with the given alert token in the link group.
233 * To use rbtrees we have to implement our own search core. 251 * To use rbtrees we have to implement our own search core.
234 * Requires @conns_lock 252 * Requires @conns_lock
@@ -281,13 +299,10 @@ void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn);
281void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn); 299void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn);
282void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn); 300void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn);
283void smc_rmb_sync_sg_for_device(struct smc_connection *conn); 301void smc_rmb_sync_sg_for_device(struct smc_connection *conn);
284int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id); 302int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini);
285 303
286void smc_conn_free(struct smc_connection *conn); 304void smc_conn_free(struct smc_connection *conn);
287int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact, 305int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini);
288 struct smc_ib_device *smcibdev, u8 ibport, u32 clcqpn,
289 struct smc_clc_msg_local *lcl, struct smcd_dev *smcd,
290 u64 peer_gid);
291void smcd_conn_free(struct smc_connection *conn); 306void smcd_conn_free(struct smc_connection *conn);
292void smc_lgr_schedule_free_work_fast(struct smc_link_group *lgr); 307void smc_lgr_schedule_free_work_fast(struct smc_link_group *lgr);
293void smc_core_exit(void); 308void smc_core_exit(void);
diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c
index 2fff79db1a59..e89e918b88e0 100644
--- a/net/smc/smc_ism.c
+++ b/net/smc/smc_ism.c
@@ -289,6 +289,11 @@ struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name,
289 INIT_LIST_HEAD(&smcd->vlan); 289 INIT_LIST_HEAD(&smcd->vlan);
290 smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)", 290 smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)",
291 WQ_MEM_RECLAIM, name); 291 WQ_MEM_RECLAIM, name);
292 if (!smcd->event_wq) {
293 kfree(smcd->conn);
294 kfree(smcd);
295 return NULL;
296 }
292 return smcd; 297 return smcd;
293} 298}
294EXPORT_SYMBOL_GPL(smcd_alloc_dev); 299EXPORT_SYMBOL_GPL(smcd_alloc_dev);
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
index 8d2f6296279c..bab2da8cf17a 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -26,6 +26,7 @@
26#include "smc_pnet.h" 26#include "smc_pnet.h"
27#include "smc_ib.h" 27#include "smc_ib.h"
28#include "smc_ism.h" 28#include "smc_ism.h"
29#include "smc_core.h"
29 30
30#define SMC_ASCII_BLANK 32 31#define SMC_ASCII_BLANK 32
31 32
@@ -603,35 +604,36 @@ static int smc_pnet_flush(struct sk_buff *skb, struct genl_info *info)
603{ 604{
604 struct net *net = genl_info_net(info); 605 struct net *net = genl_info_net(info);
605 606
606 return smc_pnet_remove_by_pnetid(net, NULL); 607 smc_pnet_remove_by_pnetid(net, NULL);
608 return 0;
607} 609}
608 610
609/* SMC_PNETID generic netlink operation definition */ 611/* SMC_PNETID generic netlink operation definition */
610static const struct genl_ops smc_pnet_ops[] = { 612static const struct genl_ops smc_pnet_ops[] = {
611 { 613 {
612 .cmd = SMC_PNETID_GET, 614 .cmd = SMC_PNETID_GET,
615 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
613 .flags = GENL_ADMIN_PERM, 616 .flags = GENL_ADMIN_PERM,
614 .policy = smc_pnet_policy,
615 .doit = smc_pnet_get, 617 .doit = smc_pnet_get,
616 .dumpit = smc_pnet_dump, 618 .dumpit = smc_pnet_dump,
617 .start = smc_pnet_dump_start 619 .start = smc_pnet_dump_start
618 }, 620 },
619 { 621 {
620 .cmd = SMC_PNETID_ADD, 622 .cmd = SMC_PNETID_ADD,
623 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
621 .flags = GENL_ADMIN_PERM, 624 .flags = GENL_ADMIN_PERM,
622 .policy = smc_pnet_policy,
623 .doit = smc_pnet_add 625 .doit = smc_pnet_add
624 }, 626 },
625 { 627 {
626 .cmd = SMC_PNETID_DEL, 628 .cmd = SMC_PNETID_DEL,
629 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
627 .flags = GENL_ADMIN_PERM, 630 .flags = GENL_ADMIN_PERM,
628 .policy = smc_pnet_policy,
629 .doit = smc_pnet_del 631 .doit = smc_pnet_del
630 }, 632 },
631 { 633 {
632 .cmd = SMC_PNETID_FLUSH, 634 .cmd = SMC_PNETID_FLUSH,
635 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
633 .flags = GENL_ADMIN_PERM, 636 .flags = GENL_ADMIN_PERM,
634 .policy = smc_pnet_policy,
635 .doit = smc_pnet_flush 637 .doit = smc_pnet_flush
636 } 638 }
637}; 639};
@@ -642,6 +644,7 @@ static struct genl_family smc_pnet_nl_family __ro_after_init = {
642 .name = SMCR_GENL_FAMILY_NAME, 644 .name = SMCR_GENL_FAMILY_NAME,
643 .version = SMCR_GENL_FAMILY_VERSION, 645 .version = SMCR_GENL_FAMILY_VERSION,
644 .maxattr = SMC_PNETID_MAX, 646 .maxattr = SMC_PNETID_MAX,
647 .policy = smc_pnet_policy,
645 .netnsok = true, 648 .netnsok = true,
646 .module = THIS_MODULE, 649 .module = THIS_MODULE,
647 .ops = smc_pnet_ops, 650 .ops = smc_pnet_ops,
@@ -758,8 +761,7 @@ static int smc_pnet_find_ndev_pnetid_by_table(struct net_device *ndev,
758 * IB device and port 761 * IB device and port
759 */ 762 */
760static void smc_pnet_find_rdma_dev(struct net_device *netdev, 763static void smc_pnet_find_rdma_dev(struct net_device *netdev,
761 struct smc_ib_device **smcibdev, 764 struct smc_init_info *ini)
762 u8 *ibport, unsigned short vlan_id, u8 gid[])
763{ 765{
764 struct smc_ib_device *ibdev; 766 struct smc_ib_device *ibdev;
765 767
@@ -779,10 +781,10 @@ static void smc_pnet_find_rdma_dev(struct net_device *netdev,
779 dev_put(ndev); 781 dev_put(ndev);
780 if (netdev == ndev && 782 if (netdev == ndev &&
781 smc_ib_port_active(ibdev, i) && 783 smc_ib_port_active(ibdev, i) &&
782 !smc_ib_determine_gid(ibdev, i, vlan_id, gid, 784 !smc_ib_determine_gid(ibdev, i, ini->vlan_id,
783 NULL)) { 785 ini->ib_gid, NULL)) {
784 *smcibdev = ibdev; 786 ini->ib_dev = ibdev;
785 *ibport = i; 787 ini->ib_port = i;
786 break; 788 break;
787 } 789 }
788 } 790 }
@@ -797,9 +799,7 @@ static void smc_pnet_find_rdma_dev(struct net_device *netdev,
797 * If nothing found, try to use handshake device 799 * If nothing found, try to use handshake device
798 */ 800 */
799static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev, 801static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev,
800 struct smc_ib_device **smcibdev, 802 struct smc_init_info *ini)
801 u8 *ibport, unsigned short vlan_id,
802 u8 gid[])
803{ 803{
804 u8 ndev_pnetid[SMC_MAX_PNETID_LEN]; 804 u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
805 struct smc_ib_device *ibdev; 805 struct smc_ib_device *ibdev;
@@ -809,7 +809,7 @@ static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev,
809 if (smc_pnetid_by_dev_port(ndev->dev.parent, ndev->dev_port, 809 if (smc_pnetid_by_dev_port(ndev->dev.parent, ndev->dev_port,
810 ndev_pnetid) && 810 ndev_pnetid) &&
811 smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid)) { 811 smc_pnet_find_ndev_pnetid_by_table(ndev, ndev_pnetid)) {
812 smc_pnet_find_rdma_dev(ndev, smcibdev, ibport, vlan_id, gid); 812 smc_pnet_find_rdma_dev(ndev, ini);
813 return; /* pnetid could not be determined */ 813 return; /* pnetid could not be determined */
814 } 814 }
815 815
@@ -820,10 +820,10 @@ static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev,
820 continue; 820 continue;
821 if (smc_pnet_match(ibdev->pnetid[i - 1], ndev_pnetid) && 821 if (smc_pnet_match(ibdev->pnetid[i - 1], ndev_pnetid) &&
822 smc_ib_port_active(ibdev, i) && 822 smc_ib_port_active(ibdev, i) &&
823 !smc_ib_determine_gid(ibdev, i, vlan_id, gid, 823 !smc_ib_determine_gid(ibdev, i, ini->vlan_id,
824 NULL)) { 824 ini->ib_gid, NULL)) {
825 *smcibdev = ibdev; 825 ini->ib_dev = ibdev;
826 *ibport = i; 826 ini->ib_port = i;
827 goto out; 827 goto out;
828 } 828 }
829 } 829 }
@@ -833,7 +833,7 @@ out:
833} 833}
834 834
835static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev, 835static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev,
836 struct smcd_dev **smcismdev) 836 struct smc_init_info *ini)
837{ 837{
838 u8 ndev_pnetid[SMC_MAX_PNETID_LEN]; 838 u8 ndev_pnetid[SMC_MAX_PNETID_LEN];
839 struct smcd_dev *ismdev; 839 struct smcd_dev *ismdev;
@@ -847,7 +847,7 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev,
847 spin_lock(&smcd_dev_list.lock); 847 spin_lock(&smcd_dev_list.lock);
848 list_for_each_entry(ismdev, &smcd_dev_list.list, list) { 848 list_for_each_entry(ismdev, &smcd_dev_list.list, list) {
849 if (smc_pnet_match(ismdev->pnetid, ndev_pnetid)) { 849 if (smc_pnet_match(ismdev->pnetid, ndev_pnetid)) {
850 *smcismdev = ismdev; 850 ini->ism_dev = ismdev;
851 break; 851 break;
852 } 852 }
853 } 853 }
@@ -858,21 +858,18 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev,
858 * determine ib_device and port belonging to used internal TCP socket 858 * determine ib_device and port belonging to used internal TCP socket
859 * ethernet interface. 859 * ethernet interface.
860 */ 860 */
861void smc_pnet_find_roce_resource(struct sock *sk, 861void smc_pnet_find_roce_resource(struct sock *sk, struct smc_init_info *ini)
862 struct smc_ib_device **smcibdev, u8 *ibport,
863 unsigned short vlan_id, u8 gid[])
864{ 862{
865 struct dst_entry *dst = sk_dst_get(sk); 863 struct dst_entry *dst = sk_dst_get(sk);
866 864
867 *smcibdev = NULL; 865 ini->ib_dev = NULL;
868 *ibport = 0; 866 ini->ib_port = 0;
869
870 if (!dst) 867 if (!dst)
871 goto out; 868 goto out;
872 if (!dst->dev) 869 if (!dst->dev)
873 goto out_rel; 870 goto out_rel;
874 871
875 smc_pnet_find_roce_by_pnetid(dst->dev, smcibdev, ibport, vlan_id, gid); 872 smc_pnet_find_roce_by_pnetid(dst->dev, ini);
876 873
877out_rel: 874out_rel:
878 dst_release(dst); 875 dst_release(dst);
@@ -880,17 +877,17 @@ out:
880 return; 877 return;
881} 878}
882 879
883void smc_pnet_find_ism_resource(struct sock *sk, struct smcd_dev **smcismdev) 880void smc_pnet_find_ism_resource(struct sock *sk, struct smc_init_info *ini)
884{ 881{
885 struct dst_entry *dst = sk_dst_get(sk); 882 struct dst_entry *dst = sk_dst_get(sk);
886 883
887 *smcismdev = NULL; 884 ini->ism_dev = NULL;
888 if (!dst) 885 if (!dst)
889 goto out; 886 goto out;
890 if (!dst->dev) 887 if (!dst->dev)
891 goto out_rel; 888 goto out_rel;
892 889
893 smc_pnet_find_ism_by_pnetid(dst->dev, smcismdev); 890 smc_pnet_find_ism_by_pnetid(dst->dev, ini);
894 891
895out_rel: 892out_rel:
896 dst_release(dst); 893 dst_release(dst);
diff --git a/net/smc/smc_pnet.h b/net/smc/smc_pnet.h
index 5eac42fb45d0..4564e4d69c2e 100644
--- a/net/smc/smc_pnet.h
+++ b/net/smc/smc_pnet.h
@@ -18,6 +18,7 @@
18 18
19struct smc_ib_device; 19struct smc_ib_device;
20struct smcd_dev; 20struct smcd_dev;
21struct smc_init_info;
21 22
22/** 23/**
23 * struct smc_pnettable - SMC PNET table anchor 24 * struct smc_pnettable - SMC PNET table anchor
@@ -43,9 +44,7 @@ int smc_pnet_init(void) __init;
43int smc_pnet_net_init(struct net *net); 44int smc_pnet_net_init(struct net *net);
44void smc_pnet_exit(void); 45void smc_pnet_exit(void);
45void smc_pnet_net_exit(struct net *net); 46void smc_pnet_net_exit(struct net *net);
46void smc_pnet_find_roce_resource(struct sock *sk, 47void smc_pnet_find_roce_resource(struct sock *sk, struct smc_init_info *ini);
47 struct smc_ib_device **smcibdev, u8 *ibport, 48void smc_pnet_find_ism_resource(struct sock *sk, struct smc_init_info *ini);
48 unsigned short vlan_id, u8 gid[]);
49void smc_pnet_find_ism_resource(struct sock *sk, struct smcd_dev **smcismdev);
50 49
51#endif 50#endif
diff --git a/net/socket.c b/net/socket.c
index 8255f5bda0aa..472fbefa5d9b 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -90,6 +90,7 @@
90#include <linux/slab.h> 90#include <linux/slab.h>
91#include <linux/xattr.h> 91#include <linux/xattr.h>
92#include <linux/nospec.h> 92#include <linux/nospec.h>
93#include <linux/indirect_call_wrapper.h>
93 94
94#include <linux/uaccess.h> 95#include <linux/uaccess.h>
95#include <asm/unistd.h> 96#include <asm/unistd.h>
@@ -108,6 +109,13 @@
108#include <net/busy_poll.h> 109#include <net/busy_poll.h>
109#include <linux/errqueue.h> 110#include <linux/errqueue.h>
110 111
112/* proto_ops for ipv4 and ipv6 use the same {recv,send}msg function */
113#if IS_ENABLED(CONFIG_INET)
114#define INDIRECT_CALL_INET4(f, f1, ...) INDIRECT_CALL_1(f, f1, __VA_ARGS__)
115#else
116#define INDIRECT_CALL_INET4(f, f1, ...) f(__VA_ARGS__)
117#endif
118
111#ifdef CONFIG_NET_RX_BUSY_POLL 119#ifdef CONFIG_NET_RX_BUSY_POLL
112unsigned int sysctl_net_busy_read __read_mostly; 120unsigned int sysctl_net_busy_read __read_mostly;
113unsigned int sysctl_net_busy_poll __read_mostly; 121unsigned int sysctl_net_busy_poll __read_mostly;
@@ -645,10 +653,12 @@ EXPORT_SYMBOL(__sock_tx_timestamp);
645 * Sends @msg through @sock, passing through LSM. 653 * Sends @msg through @sock, passing through LSM.
646 * Returns the number of bytes sent, or an error code. 654 * Returns the number of bytes sent, or an error code.
647 */ 655 */
648 656INDIRECT_CALLABLE_DECLARE(int inet_sendmsg(struct socket *, struct msghdr *,
657 size_t));
649static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg) 658static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg)
650{ 659{
651 int ret = sock->ops->sendmsg(sock, msg, msg_data_left(msg)); 660 int ret = INDIRECT_CALL_INET4(sock->ops->sendmsg, inet_sendmsg, sock,
661 msg, msg_data_left(msg));
652 BUG_ON(ret == -EIOCBQUEUED); 662 BUG_ON(ret == -EIOCBQUEUED);
653 return ret; 663 return ret;
654} 664}
@@ -874,11 +884,13 @@ EXPORT_SYMBOL_GPL(__sock_recv_ts_and_drops);
874 * Receives @msg from @sock, passing through LSM. Returns the total number 884 * Receives @msg from @sock, passing through LSM. Returns the total number
875 * of bytes received, or an error. 885 * of bytes received, or an error.
876 */ 886 */
877 887INDIRECT_CALLABLE_DECLARE(int inet_recvmsg(struct socket *, struct msghdr *,
888 size_t , int ));
878static inline int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg, 889static inline int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg,
879 int flags) 890 int flags)
880{ 891{
881 return sock->ops->recvmsg(sock, msg, msg_data_left(msg), flags); 892 return INDIRECT_CALL_INET4(sock->ops->recvmsg, inet_recvmsg, sock, msg,
893 msg_data_left(msg), flags);
882} 894}
883 895
884int sock_recvmsg(struct socket *sock, struct msghdr *msg, int flags) 896int sock_recvmsg(struct socket *sock, struct msghdr *msg, int flags)
@@ -1164,6 +1176,26 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
1164 1176
1165 err = open_related_ns(&net->ns, get_net_ns); 1177 err = open_related_ns(&net->ns, get_net_ns);
1166 break; 1178 break;
1179 case SIOCGSTAMP_OLD:
1180 case SIOCGSTAMPNS_OLD:
1181 if (!sock->ops->gettstamp) {
1182 err = -ENOIOCTLCMD;
1183 break;
1184 }
1185 err = sock->ops->gettstamp(sock, argp,
1186 cmd == SIOCGSTAMP_OLD,
1187 !IS_ENABLED(CONFIG_64BIT));
1188 break;
1189 case SIOCGSTAMP_NEW:
1190 case SIOCGSTAMPNS_NEW:
1191 if (!sock->ops->gettstamp) {
1192 err = -ENOIOCTLCMD;
1193 break;
1194 }
1195 err = sock->ops->gettstamp(sock, argp,
1196 cmd == SIOCGSTAMP_NEW,
1197 false);
1198 break;
1167 default: 1199 default:
1168 err = sock_do_ioctl(net, sock, cmd, arg); 1200 err = sock_do_ioctl(net, sock, cmd, arg);
1169 break; 1201 break;
@@ -2916,38 +2948,6 @@ void socket_seq_show(struct seq_file *seq)
2916#endif /* CONFIG_PROC_FS */ 2948#endif /* CONFIG_PROC_FS */
2917 2949
2918#ifdef CONFIG_COMPAT 2950#ifdef CONFIG_COMPAT
2919static int do_siocgstamp(struct net *net, struct socket *sock,
2920 unsigned int cmd, void __user *up)
2921{
2922 mm_segment_t old_fs = get_fs();
2923 struct timeval ktv;
2924 int err;
2925
2926 set_fs(KERNEL_DS);
2927 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv);
2928 set_fs(old_fs);
2929 if (!err)
2930 err = compat_put_timeval(&ktv, up);
2931
2932 return err;
2933}
2934
2935static int do_siocgstampns(struct net *net, struct socket *sock,
2936 unsigned int cmd, void __user *up)
2937{
2938 mm_segment_t old_fs = get_fs();
2939 struct timespec kts;
2940 int err;
2941
2942 set_fs(KERNEL_DS);
2943 err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts);
2944 set_fs(old_fs);
2945 if (!err)
2946 err = compat_put_timespec(&kts, up);
2947
2948 return err;
2949}
2950
2951static int compat_dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) 2951static int compat_dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32)
2952{ 2952{
2953 struct compat_ifconf ifc32; 2953 struct compat_ifconf ifc32;
@@ -3347,10 +3347,13 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
3347 case SIOCADDRT: 3347 case SIOCADDRT:
3348 case SIOCDELRT: 3348 case SIOCDELRT:
3349 return routing_ioctl(net, sock, cmd, argp); 3349 return routing_ioctl(net, sock, cmd, argp);
3350 case SIOCGSTAMP: 3350 case SIOCGSTAMP_OLD:
3351 return do_siocgstamp(net, sock, cmd, argp); 3351 case SIOCGSTAMPNS_OLD:
3352 case SIOCGSTAMPNS: 3352 if (!sock->ops->gettstamp)
3353 return do_siocgstampns(net, sock, cmd, argp); 3353 return -ENOIOCTLCMD;
3354 return sock->ops->gettstamp(sock, argp, cmd == SIOCGSTAMP_OLD,
3355 !COMPAT_USE_64BIT_TIME);
3356
3354 case SIOCBONDSLAVEINFOQUERY: 3357 case SIOCBONDSLAVEINFOQUERY:
3355 case SIOCBONDINFOQUERY: 3358 case SIOCBONDINFOQUERY:
3356 case SIOCSHWTSTAMP: 3359 case SIOCSHWTSTAMP:
@@ -3368,6 +3371,8 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
3368 case SIOCADDDLCI: 3371 case SIOCADDDLCI:
3369 case SIOCDELDLCI: 3372 case SIOCDELDLCI:
3370 case SIOCGSKNS: 3373 case SIOCGSKNS:
3374 case SIOCGSTAMP_NEW:
3375 case SIOCGSTAMPNS_NEW:
3371 return sock_ioctl(file, cmd, arg); 3376 return sock_ioctl(file, cmd, arg);
3372 3377
3373 case SIOCGIFFLAGS: 3378 case SIOCGIFFLAGS:
diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c
index 860dcfb95ee4..e137698e8aef 100644
--- a/net/strparser/strparser.c
+++ b/net/strparser/strparser.c
@@ -14,7 +14,8 @@
14#include <linux/file.h> 14#include <linux/file.h>
15#include <linux/in.h> 15#include <linux/in.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/export.h>
18#include <linux/init.h>
18#include <linux/net.h> 19#include <linux/net.h>
19#include <linux/netdevice.h> 20#include <linux/netdevice.h>
20#include <linux/poll.h> 21#include <linux/poll.h>
@@ -140,13 +141,11 @@ static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
140 /* We are going to append to the frags_list of head. 141 /* We are going to append to the frags_list of head.
141 * Need to unshare the frag_list. 142 * Need to unshare the frag_list.
142 */ 143 */
143 if (skb_has_frag_list(head)) { 144 err = skb_unclone(head, GFP_ATOMIC);
144 err = skb_unclone(head, GFP_ATOMIC); 145 if (err) {
145 if (err) { 146 STRP_STATS_INCR(strp->stats.mem_fail);
146 STRP_STATS_INCR(strp->stats.mem_fail); 147 desc->error = err;
147 desc->error = err; 148 return 0;
148 return 0;
149 }
150 } 149 }
151 150
152 if (unlikely(skb_shinfo(head)->frag_list)) { 151 if (unlikely(skb_shinfo(head)->frag_list)) {
@@ -299,7 +298,7 @@ static int __strp_recv(read_descriptor_t *desc, struct sk_buff *orig_skb,
299 break; 298 break;
300 } 299 }
301 300
302 /* Positive extra indicates ore bytes than needed for the 301 /* Positive extra indicates more bytes than needed for the
303 * message 302 * message
304 */ 303 */
305 304
@@ -547,7 +546,7 @@ void strp_check_rcv(struct strparser *strp)
547} 546}
548EXPORT_SYMBOL_GPL(strp_check_rcv); 547EXPORT_SYMBOL_GPL(strp_check_rcv);
549 548
550static int __init strp_mod_init(void) 549static int __init strp_dev_init(void)
551{ 550{
552 strp_wq = create_singlethread_workqueue("kstrp"); 551 strp_wq = create_singlethread_workqueue("kstrp");
553 if (unlikely(!strp_wq)) 552 if (unlikely(!strp_wq))
@@ -555,11 +554,4 @@ static int __init strp_mod_init(void)
555 554
556 return 0; 555 return 0;
557} 556}
558 557device_initcall(strp_dev_init);
559static void __exit strp_mod_exit(void)
560{
561 destroy_workqueue(strp_wq);
562}
563module_init(strp_mod_init);
564module_exit(strp_mod_exit);
565MODULE_LICENSE("GPL");
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 3fd56c0c90ae..4ce42c62458e 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -269,6 +269,7 @@ err:
269struct gss_upcall_msg { 269struct gss_upcall_msg {
270 refcount_t count; 270 refcount_t count;
271 kuid_t uid; 271 kuid_t uid;
272 const char *service_name;
272 struct rpc_pipe_msg msg; 273 struct rpc_pipe_msg msg;
273 struct list_head list; 274 struct list_head list;
274 struct gss_auth *auth; 275 struct gss_auth *auth;
@@ -316,6 +317,7 @@ gss_release_msg(struct gss_upcall_msg *gss_msg)
316 gss_put_ctx(gss_msg->ctx); 317 gss_put_ctx(gss_msg->ctx);
317 rpc_destroy_wait_queue(&gss_msg->rpc_waitqueue); 318 rpc_destroy_wait_queue(&gss_msg->rpc_waitqueue);
318 gss_put_auth(gss_msg->auth); 319 gss_put_auth(gss_msg->auth);
320 kfree_const(gss_msg->service_name);
319 kfree(gss_msg); 321 kfree(gss_msg);
320} 322}
321 323
@@ -410,9 +412,12 @@ gss_upcall_callback(struct rpc_task *task)
410 gss_release_msg(gss_msg); 412 gss_release_msg(gss_msg);
411} 413}
412 414
413static void gss_encode_v0_msg(struct gss_upcall_msg *gss_msg) 415static void gss_encode_v0_msg(struct gss_upcall_msg *gss_msg,
416 const struct cred *cred)
414{ 417{
415 uid_t uid = from_kuid(&init_user_ns, gss_msg->uid); 418 struct user_namespace *userns = cred->user_ns;
419
420 uid_t uid = from_kuid_munged(userns, gss_msg->uid);
416 memcpy(gss_msg->databuf, &uid, sizeof(uid)); 421 memcpy(gss_msg->databuf, &uid, sizeof(uid));
417 gss_msg->msg.data = gss_msg->databuf; 422 gss_msg->msg.data = gss_msg->databuf;
418 gss_msg->msg.len = sizeof(uid); 423 gss_msg->msg.len = sizeof(uid);
@@ -420,17 +425,31 @@ static void gss_encode_v0_msg(struct gss_upcall_msg *gss_msg)
420 BUILD_BUG_ON(sizeof(uid) > sizeof(gss_msg->databuf)); 425 BUILD_BUG_ON(sizeof(uid) > sizeof(gss_msg->databuf));
421} 426}
422 427
428static ssize_t
429gss_v0_upcall(struct file *file, struct rpc_pipe_msg *msg,
430 char __user *buf, size_t buflen)
431{
432 struct gss_upcall_msg *gss_msg = container_of(msg,
433 struct gss_upcall_msg,
434 msg);
435 if (msg->copied == 0)
436 gss_encode_v0_msg(gss_msg, file->f_cred);
437 return rpc_pipe_generic_upcall(file, msg, buf, buflen);
438}
439
423static int gss_encode_v1_msg(struct gss_upcall_msg *gss_msg, 440static int gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,
424 const char *service_name, 441 const char *service_name,
425 const char *target_name) 442 const char *target_name,
443 const struct cred *cred)
426{ 444{
445 struct user_namespace *userns = cred->user_ns;
427 struct gss_api_mech *mech = gss_msg->auth->mech; 446 struct gss_api_mech *mech = gss_msg->auth->mech;
428 char *p = gss_msg->databuf; 447 char *p = gss_msg->databuf;
429 size_t buflen = sizeof(gss_msg->databuf); 448 size_t buflen = sizeof(gss_msg->databuf);
430 int len; 449 int len;
431 450
432 len = scnprintf(p, buflen, "mech=%s uid=%d", mech->gm_name, 451 len = scnprintf(p, buflen, "mech=%s uid=%d", mech->gm_name,
433 from_kuid(&init_user_ns, gss_msg->uid)); 452 from_kuid_munged(userns, gss_msg->uid));
434 buflen -= len; 453 buflen -= len;
435 p += len; 454 p += len;
436 gss_msg->msg.len = len; 455 gss_msg->msg.len = len;
@@ -491,6 +510,25 @@ out_overflow:
491 return -ENOMEM; 510 return -ENOMEM;
492} 511}
493 512
513static ssize_t
514gss_v1_upcall(struct file *file, struct rpc_pipe_msg *msg,
515 char __user *buf, size_t buflen)
516{
517 struct gss_upcall_msg *gss_msg = container_of(msg,
518 struct gss_upcall_msg,
519 msg);
520 int err;
521 if (msg->copied == 0) {
522 err = gss_encode_v1_msg(gss_msg,
523 gss_msg->service_name,
524 gss_msg->auth->target_name,
525 file->f_cred);
526 if (err)
527 return err;
528 }
529 return rpc_pipe_generic_upcall(file, msg, buf, buflen);
530}
531
494static struct gss_upcall_msg * 532static struct gss_upcall_msg *
495gss_alloc_msg(struct gss_auth *gss_auth, 533gss_alloc_msg(struct gss_auth *gss_auth,
496 kuid_t uid, const char *service_name) 534 kuid_t uid, const char *service_name)
@@ -513,16 +551,14 @@ gss_alloc_msg(struct gss_auth *gss_auth,
513 refcount_set(&gss_msg->count, 1); 551 refcount_set(&gss_msg->count, 1);
514 gss_msg->uid = uid; 552 gss_msg->uid = uid;
515 gss_msg->auth = gss_auth; 553 gss_msg->auth = gss_auth;
516 switch (vers) { 554 kref_get(&gss_auth->kref);
517 case 0: 555 if (service_name) {
518 gss_encode_v0_msg(gss_msg); 556 gss_msg->service_name = kstrdup_const(service_name, GFP_NOFS);
519 break; 557 if (!gss_msg->service_name) {
520 default: 558 err = -ENOMEM;
521 err = gss_encode_v1_msg(gss_msg, service_name, gss_auth->target_name);
522 if (err)
523 goto err_put_pipe_version; 559 goto err_put_pipe_version;
560 }
524 } 561 }
525 kref_get(&gss_auth->kref);
526 return gss_msg; 562 return gss_msg;
527err_put_pipe_version: 563err_put_pipe_version:
528 put_pipe_version(gss_auth->net); 564 put_pipe_version(gss_auth->net);
@@ -581,8 +617,8 @@ gss_refresh_upcall(struct rpc_task *task)
581 /* XXX: warning on the first, under the assumption we 617 /* XXX: warning on the first, under the assumption we
582 * shouldn't normally hit this case on a refresh. */ 618 * shouldn't normally hit this case on a refresh. */
583 warn_gssd(); 619 warn_gssd();
584 task->tk_timeout = 15*HZ; 620 rpc_sleep_on_timeout(&pipe_version_rpc_waitqueue,
585 rpc_sleep_on(&pipe_version_rpc_waitqueue, task, NULL); 621 task, NULL, jiffies + (15 * HZ));
586 err = -EAGAIN; 622 err = -EAGAIN;
587 goto out; 623 goto out;
588 } 624 }
@@ -595,7 +631,6 @@ gss_refresh_upcall(struct rpc_task *task)
595 if (gss_cred->gc_upcall != NULL) 631 if (gss_cred->gc_upcall != NULL)
596 rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL); 632 rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL);
597 else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) { 633 else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) {
598 task->tk_timeout = 0;
599 gss_cred->gc_upcall = gss_msg; 634 gss_cred->gc_upcall = gss_msg;
600 /* gss_upcall_callback will release the reference to gss_upcall_msg */ 635 /* gss_upcall_callback will release the reference to gss_upcall_msg */
601 refcount_inc(&gss_msg->count); 636 refcount_inc(&gss_msg->count);
@@ -707,7 +742,7 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
707 goto err; 742 goto err;
708 } 743 }
709 744
710 uid = make_kuid(&init_user_ns, id); 745 uid = make_kuid(current_user_ns(), id);
711 if (!uid_valid(uid)) { 746 if (!uid_valid(uid)) {
712 err = -EINVAL; 747 err = -EINVAL;
713 goto err; 748 goto err;
@@ -2116,7 +2151,7 @@ static const struct rpc_credops gss_nullops = {
2116}; 2151};
2117 2152
2118static const struct rpc_pipe_ops gss_upcall_ops_v0 = { 2153static const struct rpc_pipe_ops gss_upcall_ops_v0 = {
2119 .upcall = rpc_pipe_generic_upcall, 2154 .upcall = gss_v0_upcall,
2120 .downcall = gss_pipe_downcall, 2155 .downcall = gss_pipe_downcall,
2121 .destroy_msg = gss_pipe_destroy_msg, 2156 .destroy_msg = gss_pipe_destroy_msg,
2122 .open_pipe = gss_pipe_open_v0, 2157 .open_pipe = gss_pipe_open_v0,
@@ -2124,7 +2159,7 @@ static const struct rpc_pipe_ops gss_upcall_ops_v0 = {
2124}; 2159};
2125 2160
2126static const struct rpc_pipe_ops gss_upcall_ops_v1 = { 2161static const struct rpc_pipe_ops gss_upcall_ops_v1 = {
2127 .upcall = rpc_pipe_generic_upcall, 2162 .upcall = gss_v1_upcall,
2128 .downcall = gss_pipe_downcall, 2163 .downcall = gss_pipe_downcall,
2129 .destroy_msg = gss_pipe_destroy_msg, 2164 .destroy_msg = gss_pipe_destroy_msg,
2130 .open_pipe = gss_pipe_open_v1, 2165 .open_pipe = gss_pipe_open_v1,
diff --git a/net/sunrpc/auth_gss/gss_krb5_crypto.c b/net/sunrpc/auth_gss/gss_krb5_crypto.c
index 4f43383971ba..6f2d30d7b766 100644
--- a/net/sunrpc/auth_gss/gss_krb5_crypto.c
+++ b/net/sunrpc/auth_gss/gss_krb5_crypto.c
@@ -977,7 +977,6 @@ krb5_rc4_setup_seq_key(struct krb5_ctx *kctx,
977 } 977 }
978 978
979 desc->tfm = hmac; 979 desc->tfm = hmac;
980 desc->flags = 0;
981 980
982 /* Compute intermediate Kseq from session key */ 981 /* Compute intermediate Kseq from session key */
983 err = crypto_shash_setkey(hmac, kctx->Ksess, kctx->gk5e->keylength); 982 err = crypto_shash_setkey(hmac, kctx->Ksess, kctx->gk5e->keylength);
@@ -1045,7 +1044,6 @@ krb5_rc4_setup_enc_key(struct krb5_ctx *kctx,
1045 } 1044 }
1046 1045
1047 desc->tfm = hmac; 1046 desc->tfm = hmac;
1048 desc->flags = 0;
1049 1047
1050 /* Compute intermediate Kcrypt from session key */ 1048 /* Compute intermediate Kcrypt from session key */
1051 for (i = 0; i < kctx->gk5e->keylength; i++) 1049 for (i = 0; i < kctx->gk5e->keylength; i++)
diff --git a/net/sunrpc/auth_gss/gss_krb5_mech.c b/net/sunrpc/auth_gss/gss_krb5_mech.c
index 56cc85c5bc06..6e5d6d240215 100644
--- a/net/sunrpc/auth_gss/gss_krb5_mech.c
+++ b/net/sunrpc/auth_gss/gss_krb5_mech.c
@@ -438,7 +438,6 @@ context_derive_keys_rc4(struct krb5_ctx *ctx)
438 } 438 }
439 439
440 desc->tfm = hmac; 440 desc->tfm = hmac;
441 desc->flags = 0;
442 441
443 err = crypto_shash_digest(desc, sigkeyconstant, slen, ctx->cksum); 442 err = crypto_shash_digest(desc, sigkeyconstant, slen, ctx->cksum);
444 kzfree(desc); 443 kzfree(desc);
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index d4018e5a24c5..e7df1f782b2e 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -107,6 +107,8 @@ unx_marshal(struct rpc_task *task, struct xdr_stream *xdr)
107 __be32 *p, *cred_len, *gidarr_len; 107 __be32 *p, *cred_len, *gidarr_len;
108 int i; 108 int i;
109 struct group_info *gi = cred->cr_cred->group_info; 109 struct group_info *gi = cred->cr_cred->group_info;
110 struct user_namespace *userns = clnt->cl_cred ?
111 clnt->cl_cred->user_ns : &init_user_ns;
110 112
111 /* Credential */ 113 /* Credential */
112 114
@@ -122,14 +124,13 @@ unx_marshal(struct rpc_task *task, struct xdr_stream *xdr)
122 p = xdr_reserve_space(xdr, 3 * sizeof(*p)); 124 p = xdr_reserve_space(xdr, 3 * sizeof(*p));
123 if (!p) 125 if (!p)
124 goto marshal_failed; 126 goto marshal_failed;
125 *p++ = cpu_to_be32(from_kuid(&init_user_ns, cred->cr_cred->fsuid)); 127 *p++ = cpu_to_be32(from_kuid_munged(userns, cred->cr_cred->fsuid));
126 *p++ = cpu_to_be32(from_kgid(&init_user_ns, cred->cr_cred->fsgid)); 128 *p++ = cpu_to_be32(from_kgid_munged(userns, cred->cr_cred->fsgid));
127 129
128 gidarr_len = p++; 130 gidarr_len = p++;
129 if (gi) 131 if (gi)
130 for (i = 0; i < UNX_NGROUPS && i < gi->ngroups; i++) 132 for (i = 0; i < UNX_NGROUPS && i < gi->ngroups; i++)
131 *p++ = cpu_to_be32(from_kgid(&init_user_ns, 133 *p++ = cpu_to_be32(from_kgid_munged(userns, gi->gid[i]));
132 gi->gid[i]));
133 *gidarr_len = cpu_to_be32(p - gidarr_len - 1); 134 *gidarr_len = cpu_to_be32(p - gidarr_len - 1);
134 *cred_len = cpu_to_be32((p - cred_len - 1) << 2); 135 *cred_len = cpu_to_be32((p - cred_len - 1) << 2);
135 p = xdr_reserve_space(xdr, (p - gidarr_len - 1) << 2); 136 p = xdr_reserve_space(xdr, (p - gidarr_len - 1) << 2);
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 12bb23b8e0c5..261131dfa1f1 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -54,6 +54,7 @@ static void cache_init(struct cache_head *h, struct cache_detail *detail)
54 h->last_refresh = now; 54 h->last_refresh = now;
55} 55}
56 56
57static inline int cache_is_valid(struct cache_head *h);
57static void cache_fresh_locked(struct cache_head *head, time_t expiry, 58static void cache_fresh_locked(struct cache_head *head, time_t expiry,
58 struct cache_detail *detail); 59 struct cache_detail *detail);
59static void cache_fresh_unlocked(struct cache_head *head, 60static void cache_fresh_unlocked(struct cache_head *head,
@@ -105,6 +106,8 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
105 if (cache_is_expired(detail, tmp)) { 106 if (cache_is_expired(detail, tmp)) {
106 hlist_del_init_rcu(&tmp->cache_list); 107 hlist_del_init_rcu(&tmp->cache_list);
107 detail->entries --; 108 detail->entries --;
109 if (cache_is_valid(tmp) == -EAGAIN)
110 set_bit(CACHE_NEGATIVE, &tmp->flags);
108 cache_fresh_locked(tmp, 0, detail); 111 cache_fresh_locked(tmp, 0, detail);
109 freeme = tmp; 112 freeme = tmp;
110 break; 113 break;
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 1d0395ef62c9..c1f1afabd024 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -394,6 +394,7 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args,
394 if (err) 394 if (err)
395 goto out_no_clid; 395 goto out_no_clid;
396 396
397 clnt->cl_cred = get_cred(args->cred);
397 clnt->cl_procinfo = version->procs; 398 clnt->cl_procinfo = version->procs;
398 clnt->cl_maxproc = version->nrprocs; 399 clnt->cl_maxproc = version->nrprocs;
399 clnt->cl_prog = args->prognumber ? : program->number; 400 clnt->cl_prog = args->prognumber ? : program->number;
@@ -439,6 +440,7 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args,
439out_no_path: 440out_no_path:
440 rpc_free_iostats(clnt->cl_metrics); 441 rpc_free_iostats(clnt->cl_metrics);
441out_no_stats: 442out_no_stats:
443 put_cred(clnt->cl_cred);
442 rpc_free_clid(clnt); 444 rpc_free_clid(clnt);
443out_no_clid: 445out_no_clid:
444 kfree(clnt); 446 kfree(clnt);
@@ -484,8 +486,11 @@ static struct rpc_clnt *rpc_create_xprt(struct rpc_create_args *args,
484 } 486 }
485 487
486 clnt->cl_softrtry = 1; 488 clnt->cl_softrtry = 1;
487 if (args->flags & RPC_CLNT_CREATE_HARDRTRY) 489 if (args->flags & (RPC_CLNT_CREATE_HARDRTRY|RPC_CLNT_CREATE_SOFTERR)) {
488 clnt->cl_softrtry = 0; 490 clnt->cl_softrtry = 0;
491 if (args->flags & RPC_CLNT_CREATE_SOFTERR)
492 clnt->cl_softerr = 1;
493 }
489 494
490 if (args->flags & RPC_CLNT_CREATE_AUTOBIND) 495 if (args->flags & RPC_CLNT_CREATE_AUTOBIND)
491 clnt->cl_autobind = 1; 496 clnt->cl_autobind = 1;
@@ -623,10 +628,12 @@ static struct rpc_clnt *__rpc_clone_client(struct rpc_create_args *args,
623 /* Turn off autobind on clones */ 628 /* Turn off autobind on clones */
624 new->cl_autobind = 0; 629 new->cl_autobind = 0;
625 new->cl_softrtry = clnt->cl_softrtry; 630 new->cl_softrtry = clnt->cl_softrtry;
631 new->cl_softerr = clnt->cl_softerr;
626 new->cl_noretranstimeo = clnt->cl_noretranstimeo; 632 new->cl_noretranstimeo = clnt->cl_noretranstimeo;
627 new->cl_discrtry = clnt->cl_discrtry; 633 new->cl_discrtry = clnt->cl_discrtry;
628 new->cl_chatty = clnt->cl_chatty; 634 new->cl_chatty = clnt->cl_chatty;
629 new->cl_principal = clnt->cl_principal; 635 new->cl_principal = clnt->cl_principal;
636 new->cl_cred = get_cred(clnt->cl_cred);
630 return new; 637 return new;
631 638
632out_err: 639out_err:
@@ -648,6 +655,7 @@ struct rpc_clnt *rpc_clone_client(struct rpc_clnt *clnt)
648 .prognumber = clnt->cl_prog, 655 .prognumber = clnt->cl_prog,
649 .version = clnt->cl_vers, 656 .version = clnt->cl_vers,
650 .authflavor = clnt->cl_auth->au_flavor, 657 .authflavor = clnt->cl_auth->au_flavor,
658 .cred = clnt->cl_cred,
651 }; 659 };
652 return __rpc_clone_client(&args, clnt); 660 return __rpc_clone_client(&args, clnt);
653} 661}
@@ -669,6 +677,7 @@ rpc_clone_client_set_auth(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
669 .prognumber = clnt->cl_prog, 677 .prognumber = clnt->cl_prog,
670 .version = clnt->cl_vers, 678 .version = clnt->cl_vers,
671 .authflavor = flavor, 679 .authflavor = flavor,
680 .cred = clnt->cl_cred,
672 }; 681 };
673 return __rpc_clone_client(&args, clnt); 682 return __rpc_clone_client(&args, clnt);
674} 683}
@@ -827,14 +836,8 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
827 * Spin lock all_tasks to prevent changes... 836 * Spin lock all_tasks to prevent changes...
828 */ 837 */
829 spin_lock(&clnt->cl_lock); 838 spin_lock(&clnt->cl_lock);
830 list_for_each_entry(rovr, &clnt->cl_tasks, tk_task) { 839 list_for_each_entry(rovr, &clnt->cl_tasks, tk_task)
831 if (!RPC_IS_ACTIVATED(rovr)) 840 rpc_signal_task(rovr);
832 continue;
833 if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
834 rovr->tk_flags |= RPC_TASK_KILLED;
835 rpc_exit(rovr, -EIO);
836 }
837 }
838 spin_unlock(&clnt->cl_lock); 841 spin_unlock(&clnt->cl_lock);
839} 842}
840EXPORT_SYMBOL_GPL(rpc_killall_tasks); 843EXPORT_SYMBOL_GPL(rpc_killall_tasks);
@@ -882,6 +885,7 @@ rpc_free_client(struct rpc_clnt *clnt)
882 xprt_put(rcu_dereference_raw(clnt->cl_xprt)); 885 xprt_put(rcu_dereference_raw(clnt->cl_xprt));
883 xprt_iter_destroy(&clnt->cl_xpi); 886 xprt_iter_destroy(&clnt->cl_xpi);
884 rpciod_down(); 887 rpciod_down();
888 put_cred(clnt->cl_cred);
885 rpc_free_clid(clnt); 889 rpc_free_clid(clnt);
886 kfree(clnt); 890 kfree(clnt);
887 return parent; 891 return parent;
@@ -946,6 +950,7 @@ struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *old,
946 .prognumber = program->number, 950 .prognumber = program->number,
947 .version = vers, 951 .version = vers,
948 .authflavor = old->cl_auth->au_flavor, 952 .authflavor = old->cl_auth->au_flavor,
953 .cred = old->cl_cred,
949 }; 954 };
950 struct rpc_clnt *clnt; 955 struct rpc_clnt *clnt;
951 int err; 956 int err;
@@ -1007,6 +1012,8 @@ void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt)
1007 atomic_inc(&clnt->cl_count); 1012 atomic_inc(&clnt->cl_count);
1008 if (clnt->cl_softrtry) 1013 if (clnt->cl_softrtry)
1009 task->tk_flags |= RPC_TASK_SOFT; 1014 task->tk_flags |= RPC_TASK_SOFT;
1015 if (clnt->cl_softerr)
1016 task->tk_flags |= RPC_TASK_TIMEOUT;
1010 if (clnt->cl_noretranstimeo) 1017 if (clnt->cl_noretranstimeo)
1011 task->tk_flags |= RPC_TASK_NO_RETRANS_TIMEOUT; 1018 task->tk_flags |= RPC_TASK_NO_RETRANS_TIMEOUT;
1012 if (atomic_read(&clnt->cl_swapper)) 1019 if (atomic_read(&clnt->cl_swapper))
@@ -1470,22 +1477,14 @@ void rpc_force_rebind(struct rpc_clnt *clnt)
1470} 1477}
1471EXPORT_SYMBOL_GPL(rpc_force_rebind); 1478EXPORT_SYMBOL_GPL(rpc_force_rebind);
1472 1479
1473/* 1480static int
1474 * Restart an (async) RPC call from the call_prepare state. 1481__rpc_restart_call(struct rpc_task *task, void (*action)(struct rpc_task *))
1475 * Usually called from within the exit handler.
1476 */
1477int
1478rpc_restart_call_prepare(struct rpc_task *task)
1479{ 1482{
1480 if (RPC_ASSASSINATED(task))
1481 return 0;
1482 task->tk_action = call_start;
1483 task->tk_status = 0; 1483 task->tk_status = 0;
1484 if (task->tk_ops->rpc_call_prepare != NULL) 1484 task->tk_rpc_status = 0;
1485 task->tk_action = rpc_prepare_task; 1485 task->tk_action = action;
1486 return 1; 1486 return 1;
1487} 1487}
1488EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
1489 1488
1490/* 1489/*
1491 * Restart an (async) RPC call. Usually called from within the 1490 * Restart an (async) RPC call. Usually called from within the
@@ -1494,14 +1493,23 @@ EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
1494int 1493int
1495rpc_restart_call(struct rpc_task *task) 1494rpc_restart_call(struct rpc_task *task)
1496{ 1495{
1497 if (RPC_ASSASSINATED(task)) 1496 return __rpc_restart_call(task, call_start);
1498 return 0;
1499 task->tk_action = call_start;
1500 task->tk_status = 0;
1501 return 1;
1502} 1497}
1503EXPORT_SYMBOL_GPL(rpc_restart_call); 1498EXPORT_SYMBOL_GPL(rpc_restart_call);
1504 1499
1500/*
1501 * Restart an (async) RPC call from the call_prepare state.
1502 * Usually called from within the exit handler.
1503 */
1504int
1505rpc_restart_call_prepare(struct rpc_task *task)
1506{
1507 if (task->tk_ops->rpc_call_prepare != NULL)
1508 return __rpc_restart_call(task, rpc_prepare_task);
1509 return rpc_restart_call(task);
1510}
1511EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
1512
1505const char 1513const char
1506*rpc_proc_name(const struct rpc_task *task) 1514*rpc_proc_name(const struct rpc_task *task)
1507{ 1515{
@@ -1516,6 +1524,19 @@ const char
1516 return "no proc"; 1524 return "no proc";
1517} 1525}
1518 1526
1527static void
1528__rpc_call_rpcerror(struct rpc_task *task, int tk_status, int rpc_status)
1529{
1530 task->tk_rpc_status = rpc_status;
1531 rpc_exit(task, tk_status);
1532}
1533
1534static void
1535rpc_call_rpcerror(struct rpc_task *task, int status)
1536{
1537 __rpc_call_rpcerror(task, status, status);
1538}
1539
1519/* 1540/*
1520 * 0. Initial state 1541 * 0. Initial state
1521 * 1542 *
@@ -1580,7 +1601,7 @@ call_reserveresult(struct rpc_task *task)
1580 1601
1581 printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n", 1602 printk(KERN_ERR "%s: status=%d, but no request slot, exiting\n",
1582 __func__, status); 1603 __func__, status);
1583 rpc_exit(task, -EIO); 1604 rpc_call_rpcerror(task, -EIO);
1584 return; 1605 return;
1585 } 1606 }
1586 1607
@@ -1608,7 +1629,7 @@ call_reserveresult(struct rpc_task *task)
1608 __func__, status); 1629 __func__, status);
1609 break; 1630 break;
1610 } 1631 }
1611 rpc_exit(task, status); 1632 rpc_call_rpcerror(task, status);
1612} 1633}
1613 1634
1614/* 1635/*
@@ -1676,7 +1697,7 @@ call_refreshresult(struct rpc_task *task)
1676 } 1697 }
1677 dprintk("RPC: %5u %s: refresh creds failed with error %d\n", 1698 dprintk("RPC: %5u %s: refresh creds failed with error %d\n",
1678 task->tk_pid, __func__, status); 1699 task->tk_pid, __func__, status);
1679 rpc_exit(task, status); 1700 rpc_call_rpcerror(task, status);
1680} 1701}
1681 1702
1682/* 1703/*
@@ -1727,7 +1748,7 @@ call_allocate(struct rpc_task *task)
1727 if (status == 0) 1748 if (status == 0)
1728 return; 1749 return;
1729 if (status != -ENOMEM) { 1750 if (status != -ENOMEM) {
1730 rpc_exit(task, status); 1751 rpc_call_rpcerror(task, status);
1731 return; 1752 return;
1732 } 1753 }
1733 1754
@@ -1793,10 +1814,17 @@ call_encode(struct rpc_task *task)
1793 rpc_delay(task, HZ >> 4); 1814 rpc_delay(task, HZ >> 4);
1794 break; 1815 break;
1795 case -EKEYEXPIRED: 1816 case -EKEYEXPIRED:
1796 task->tk_action = call_refresh; 1817 if (!task->tk_cred_retry) {
1818 rpc_exit(task, task->tk_status);
1819 } else {
1820 task->tk_action = call_refresh;
1821 task->tk_cred_retry--;
1822 dprintk("RPC: %5u %s: retry refresh creds\n",
1823 task->tk_pid, __func__);
1824 }
1797 break; 1825 break;
1798 default: 1826 default:
1799 rpc_exit(task, task->tk_status); 1827 rpc_call_rpcerror(task, task->tk_status);
1800 } 1828 }
1801 return; 1829 return;
1802 } else { 1830 } else {
@@ -1857,7 +1885,6 @@ call_bind(struct rpc_task *task)
1857 if (!xprt_prepare_transmit(task)) 1885 if (!xprt_prepare_transmit(task))
1858 return; 1886 return;
1859 1887
1860 task->tk_timeout = xprt->bind_timeout;
1861 xprt->ops->rpcbind(task); 1888 xprt->ops->rpcbind(task);
1862} 1889}
1863 1890
@@ -1938,7 +1965,7 @@ call_bind_status(struct rpc_task *task)
1938 task->tk_pid, -task->tk_status); 1965 task->tk_pid, -task->tk_status);
1939 } 1966 }
1940 1967
1941 rpc_exit(task, status); 1968 rpc_call_rpcerror(task, status);
1942 return; 1969 return;
1943 1970
1944retry_timeout: 1971retry_timeout:
@@ -1973,7 +2000,7 @@ call_connect(struct rpc_task *task)
1973 if (task->tk_status < 0) 2000 if (task->tk_status < 0)
1974 return; 2001 return;
1975 if (task->tk_flags & RPC_TASK_NOCONNECT) { 2002 if (task->tk_flags & RPC_TASK_NOCONNECT) {
1976 rpc_exit(task, -ENOTCONN); 2003 rpc_call_rpcerror(task, -ENOTCONN);
1977 return; 2004 return;
1978 } 2005 }
1979 if (!xprt_prepare_transmit(task)) 2006 if (!xprt_prepare_transmit(task))
@@ -2033,7 +2060,7 @@ call_connect_status(struct rpc_task *task)
2033 task->tk_action = call_transmit; 2060 task->tk_action = call_transmit;
2034 return; 2061 return;
2035 } 2062 }
2036 rpc_exit(task, status); 2063 rpc_call_rpcerror(task, status);
2037 return; 2064 return;
2038out_retry: 2065out_retry:
2039 /* Check for timeouts before looping back to call_bind */ 2066 /* Check for timeouts before looping back to call_bind */
@@ -2081,8 +2108,8 @@ call_transmit_status(struct rpc_task *task)
2081 * test first. 2108 * test first.
2082 */ 2109 */
2083 if (rpc_task_transmitted(task)) { 2110 if (rpc_task_transmitted(task)) {
2084 if (task->tk_status == 0) 2111 task->tk_status = 0;
2085 xprt_request_wait_receive(task); 2112 xprt_request_wait_receive(task);
2086 return; 2113 return;
2087 } 2114 }
2088 2115
@@ -2118,7 +2145,7 @@ call_transmit_status(struct rpc_task *task)
2118 if (!task->tk_msg.rpc_proc->p_proc) 2145 if (!task->tk_msg.rpc_proc->p_proc)
2119 trace_xprt_ping(task->tk_xprt, 2146 trace_xprt_ping(task->tk_xprt,
2120 task->tk_status); 2147 task->tk_status);
2121 rpc_exit(task, task->tk_status); 2148 rpc_call_rpcerror(task, task->tk_status);
2122 return; 2149 return;
2123 } 2150 }
2124 /* fall through */ 2151 /* fall through */
@@ -2167,6 +2194,9 @@ call_bc_transmit_status(struct rpc_task *task)
2167{ 2194{
2168 struct rpc_rqst *req = task->tk_rqstp; 2195 struct rpc_rqst *req = task->tk_rqstp;
2169 2196
2197 if (rpc_task_transmitted(task))
2198 task->tk_status = 0;
2199
2170 dprint_status(task); 2200 dprint_status(task);
2171 2201
2172 switch (task->tk_status) { 2202 switch (task->tk_status) {
@@ -2279,7 +2309,7 @@ call_status(struct rpc_task *task)
2279 rpc_check_timeout(task); 2309 rpc_check_timeout(task);
2280 return; 2310 return;
2281out_exit: 2311out_exit:
2282 rpc_exit(task, status); 2312 rpc_call_rpcerror(task, status);
2283} 2313}
2284 2314
2285static bool 2315static bool
@@ -2303,29 +2333,40 @@ rpc_check_timeout(struct rpc_task *task)
2303 task->tk_timeouts++; 2333 task->tk_timeouts++;
2304 2334
2305 if (RPC_IS_SOFTCONN(task) && !rpc_check_connected(task->tk_rqstp)) { 2335 if (RPC_IS_SOFTCONN(task) && !rpc_check_connected(task->tk_rqstp)) {
2306 rpc_exit(task, -ETIMEDOUT); 2336 rpc_call_rpcerror(task, -ETIMEDOUT);
2307 return; 2337 return;
2308 } 2338 }
2309 2339
2310 if (RPC_IS_SOFT(task)) { 2340 if (RPC_IS_SOFT(task)) {
2341 /*
2342 * Once a "no retrans timeout" soft tasks (a.k.a NFSv4) has
2343 * been sent, it should time out only if the transport
2344 * connection gets terminally broken.
2345 */
2346 if ((task->tk_flags & RPC_TASK_NO_RETRANS_TIMEOUT) &&
2347 rpc_check_connected(task->tk_rqstp))
2348 return;
2349
2311 if (clnt->cl_chatty) { 2350 if (clnt->cl_chatty) {
2312 printk(KERN_NOTICE "%s: server %s not responding, timed out\n", 2351 pr_notice_ratelimited(
2352 "%s: server %s not responding, timed out\n",
2313 clnt->cl_program->name, 2353 clnt->cl_program->name,
2314 task->tk_xprt->servername); 2354 task->tk_xprt->servername);
2315 } 2355 }
2316 if (task->tk_flags & RPC_TASK_TIMEOUT) 2356 if (task->tk_flags & RPC_TASK_TIMEOUT)
2317 rpc_exit(task, -ETIMEDOUT); 2357 rpc_call_rpcerror(task, -ETIMEDOUT);
2318 else 2358 else
2319 rpc_exit(task, -EIO); 2359 __rpc_call_rpcerror(task, -EIO, -ETIMEDOUT);
2320 return; 2360 return;
2321 } 2361 }
2322 2362
2323 if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) { 2363 if (!(task->tk_flags & RPC_CALL_MAJORSEEN)) {
2324 task->tk_flags |= RPC_CALL_MAJORSEEN; 2364 task->tk_flags |= RPC_CALL_MAJORSEEN;
2325 if (clnt->cl_chatty) { 2365 if (clnt->cl_chatty) {
2326 printk(KERN_NOTICE "%s: server %s not responding, still trying\n", 2366 pr_notice_ratelimited(
2327 clnt->cl_program->name, 2367 "%s: server %s not responding, still trying\n",
2328 task->tk_xprt->servername); 2368 clnt->cl_program->name,
2369 task->tk_xprt->servername);
2329 } 2370 }
2330 } 2371 }
2331 rpc_force_rebind(clnt); 2372 rpc_force_rebind(clnt);
@@ -2355,7 +2396,7 @@ call_decode(struct rpc_task *task)
2355 2396
2356 if (task->tk_flags & RPC_CALL_MAJORSEEN) { 2397 if (task->tk_flags & RPC_CALL_MAJORSEEN) {
2357 if (clnt->cl_chatty) { 2398 if (clnt->cl_chatty) {
2358 printk(KERN_NOTICE "%s: server %s OK\n", 2399 pr_notice_ratelimited("%s: server %s OK\n",
2359 clnt->cl_program->name, 2400 clnt->cl_program->name,
2360 task->tk_xprt->servername); 2401 task->tk_xprt->servername);
2361 } 2402 }
@@ -2878,7 +2919,7 @@ static void rpc_show_task(const struct rpc_clnt *clnt,
2878 2919
2879 printk(KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n", 2920 printk(KERN_INFO "%5u %04x %6d %8p %8p %8ld %8p %sv%u %s a:%ps q:%s\n",
2880 task->tk_pid, task->tk_flags, task->tk_status, 2921 task->tk_pid, task->tk_flags, task->tk_status,
2881 clnt, task->tk_rqstp, task->tk_timeout, task->tk_ops, 2922 clnt, task->tk_rqstp, rpc_task_timeout(task), task->tk_ops,
2882 clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task), 2923 clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task),
2883 task->tk_action, rpc_waitq); 2924 task->tk_action, rpc_waitq);
2884} 2925}
diff --git a/net/sunrpc/debugfs.c b/net/sunrpc/debugfs.c
index 19bb356230ed..95ebd76b132d 100644
--- a/net/sunrpc/debugfs.c
+++ b/net/sunrpc/debugfs.c
@@ -33,7 +33,7 @@ tasks_show(struct seq_file *f, void *v)
33 33
34 seq_printf(f, "%5u %04x %6d 0x%x 0x%x %8ld %ps %sv%u %s a:%ps q:%s\n", 34 seq_printf(f, "%5u %04x %6d 0x%x 0x%x %8ld %ps %sv%u %s a:%ps q:%s\n",
35 task->tk_pid, task->tk_flags, task->tk_status, 35 task->tk_pid, task->tk_flags, task->tk_status,
36 clnt->cl_clid, xid, task->tk_timeout, task->tk_ops, 36 clnt->cl_clid, xid, rpc_task_timeout(task), task->tk_ops,
37 clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task), 37 clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task),
38 task->tk_action, rpc_waitq); 38 task->tk_action, rpc_waitq);
39 return 0; 39 return 0;
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 69663681bf9d..979d23646e33 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -202,18 +202,11 @@ rpc_alloc_inode(struct super_block *sb)
202} 202}
203 203
204static void 204static void
205rpc_i_callback(struct rcu_head *head) 205rpc_free_inode(struct inode *inode)
206{ 206{
207 struct inode *inode = container_of(head, struct inode, i_rcu);
208 kmem_cache_free(rpc_inode_cachep, RPC_I(inode)); 207 kmem_cache_free(rpc_inode_cachep, RPC_I(inode));
209} 208}
210 209
211static void
212rpc_destroy_inode(struct inode *inode)
213{
214 call_rcu(&inode->i_rcu, rpc_i_callback);
215}
216
217static int 210static int
218rpc_pipe_open(struct inode *inode, struct file *filp) 211rpc_pipe_open(struct inode *inode, struct file *filp)
219{ 212{
@@ -1123,7 +1116,7 @@ void rpc_remove_cache_dir(struct dentry *dentry)
1123 */ 1116 */
1124static const struct super_operations s_ops = { 1117static const struct super_operations s_ops = {
1125 .alloc_inode = rpc_alloc_inode, 1118 .alloc_inode = rpc_alloc_inode,
1126 .destroy_inode = rpc_destroy_inode, 1119 .free_inode = rpc_free_inode,
1127 .statfs = simple_statfs, 1120 .statfs = simple_statfs,
1128}; 1121};
1129 1122
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index 41a971ac1c63..2277b7cdad27 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -240,6 +240,7 @@ static int rpcb_create_local_unix(struct net *net)
240 .program = &rpcb_program, 240 .program = &rpcb_program,
241 .version = RPCBVERS_2, 241 .version = RPCBVERS_2,
242 .authflavor = RPC_AUTH_NULL, 242 .authflavor = RPC_AUTH_NULL,
243 .cred = current_cred(),
243 /* 244 /*
244 * We turn off the idle timeout to prevent the kernel 245 * We turn off the idle timeout to prevent the kernel
245 * from automatically disconnecting the socket. 246 * from automatically disconnecting the socket.
@@ -299,6 +300,7 @@ static int rpcb_create_local_net(struct net *net)
299 .program = &rpcb_program, 300 .program = &rpcb_program,
300 .version = RPCBVERS_2, 301 .version = RPCBVERS_2,
301 .authflavor = RPC_AUTH_UNIX, 302 .authflavor = RPC_AUTH_UNIX,
303 .cred = current_cred(),
302 .flags = RPC_CLNT_CREATE_NOPING, 304 .flags = RPC_CLNT_CREATE_NOPING,
303 }; 305 };
304 struct rpc_clnt *clnt, *clnt4; 306 struct rpc_clnt *clnt, *clnt4;
@@ -358,7 +360,8 @@ out:
358static struct rpc_clnt *rpcb_create(struct net *net, const char *nodename, 360static struct rpc_clnt *rpcb_create(struct net *net, const char *nodename,
359 const char *hostname, 361 const char *hostname,
360 struct sockaddr *srvaddr, size_t salen, 362 struct sockaddr *srvaddr, size_t salen,
361 int proto, u32 version) 363 int proto, u32 version,
364 const struct cred *cred)
362{ 365{
363 struct rpc_create_args args = { 366 struct rpc_create_args args = {
364 .net = net, 367 .net = net,
@@ -370,6 +373,7 @@ static struct rpc_clnt *rpcb_create(struct net *net, const char *nodename,
370 .program = &rpcb_program, 373 .program = &rpcb_program,
371 .version = version, 374 .version = version,
372 .authflavor = RPC_AUTH_UNIX, 375 .authflavor = RPC_AUTH_UNIX,
376 .cred = cred,
373 .flags = (RPC_CLNT_CREATE_NOPING | 377 .flags = (RPC_CLNT_CREATE_NOPING |
374 RPC_CLNT_CREATE_NONPRIVPORT), 378 RPC_CLNT_CREATE_NONPRIVPORT),
375 }; 379 };
@@ -694,7 +698,8 @@ void rpcb_getport_async(struct rpc_task *task)
694 698
695 /* Put self on the wait queue to ensure we get notified if 699 /* Put self on the wait queue to ensure we get notified if
696 * some other task is already attempting to bind the port */ 700 * some other task is already attempting to bind the port */
697 rpc_sleep_on(&xprt->binding, task, NULL); 701 rpc_sleep_on_timeout(&xprt->binding, task,
702 NULL, jiffies + xprt->bind_timeout);
698 703
699 if (xprt_test_and_set_binding(xprt)) { 704 if (xprt_test_and_set_binding(xprt)) {
700 dprintk("RPC: %5u %s: waiting for another binder\n", 705 dprintk("RPC: %5u %s: waiting for another binder\n",
@@ -744,7 +749,8 @@ void rpcb_getport_async(struct rpc_task *task)
744 rpcb_clnt = rpcb_create(xprt->xprt_net, 749 rpcb_clnt = rpcb_create(xprt->xprt_net,
745 clnt->cl_nodename, 750 clnt->cl_nodename,
746 xprt->servername, sap, salen, 751 xprt->servername, sap, salen,
747 xprt->prot, bind_version); 752 xprt->prot, bind_version,
753 clnt->cl_cred);
748 if (IS_ERR(rpcb_clnt)) { 754 if (IS_ERR(rpcb_clnt)) {
749 status = PTR_ERR(rpcb_clnt); 755 status = PTR_ERR(rpcb_clnt);
750 dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n", 756 dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n",
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index 28956c70100a..1a12fb03e611 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -58,6 +58,20 @@ static struct rpc_wait_queue delay_queue;
58struct workqueue_struct *rpciod_workqueue __read_mostly; 58struct workqueue_struct *rpciod_workqueue __read_mostly;
59struct workqueue_struct *xprtiod_workqueue __read_mostly; 59struct workqueue_struct *xprtiod_workqueue __read_mostly;
60 60
61unsigned long
62rpc_task_timeout(const struct rpc_task *task)
63{
64 unsigned long timeout = READ_ONCE(task->tk_timeout);
65
66 if (timeout != 0) {
67 unsigned long now = jiffies;
68 if (time_before(now, timeout))
69 return timeout - now;
70 }
71 return 0;
72}
73EXPORT_SYMBOL_GPL(rpc_task_timeout);
74
61/* 75/*
62 * Disable the timer for a given RPC task. Should be called with 76 * Disable the timer for a given RPC task. Should be called with
63 * queue->lock and bh_disabled in order to avoid races within 77 * queue->lock and bh_disabled in order to avoid races within
@@ -66,7 +80,7 @@ struct workqueue_struct *xprtiod_workqueue __read_mostly;
66static void 80static void
67__rpc_disable_timer(struct rpc_wait_queue *queue, struct rpc_task *task) 81__rpc_disable_timer(struct rpc_wait_queue *queue, struct rpc_task *task)
68{ 82{
69 if (task->tk_timeout == 0) 83 if (list_empty(&task->u.tk_wait.timer_list))
70 return; 84 return;
71 dprintk("RPC: %5u disabling timer\n", task->tk_pid); 85 dprintk("RPC: %5u disabling timer\n", task->tk_pid);
72 task->tk_timeout = 0; 86 task->tk_timeout = 0;
@@ -78,25 +92,21 @@ __rpc_disable_timer(struct rpc_wait_queue *queue, struct rpc_task *task)
78static void 92static void
79rpc_set_queue_timer(struct rpc_wait_queue *queue, unsigned long expires) 93rpc_set_queue_timer(struct rpc_wait_queue *queue, unsigned long expires)
80{ 94{
81 queue->timer_list.expires = expires; 95 timer_reduce(&queue->timer_list.timer, expires);
82 mod_timer(&queue->timer_list.timer, expires);
83} 96}
84 97
85/* 98/*
86 * Set up a timer for the current task. 99 * Set up a timer for the current task.
87 */ 100 */
88static void 101static void
89__rpc_add_timer(struct rpc_wait_queue *queue, struct rpc_task *task) 102__rpc_add_timer(struct rpc_wait_queue *queue, struct rpc_task *task,
103 unsigned long timeout)
90{ 104{
91 if (!task->tk_timeout)
92 return;
93
94 dprintk("RPC: %5u setting alarm for %u ms\n", 105 dprintk("RPC: %5u setting alarm for %u ms\n",
95 task->tk_pid, jiffies_to_msecs(task->tk_timeout)); 106 task->tk_pid, jiffies_to_msecs(timeout - jiffies));
96 107
97 task->u.tk_wait.expires = jiffies + task->tk_timeout; 108 task->tk_timeout = timeout;
98 if (list_empty(&queue->timer_list.list) || time_before(task->u.tk_wait.expires, queue->timer_list.expires)) 109 rpc_set_queue_timer(queue, timeout);
99 rpc_set_queue_timer(queue, task->u.tk_wait.expires);
100 list_add(&task->u.tk_wait.timer_list, &queue->timer_list.list); 110 list_add(&task->u.tk_wait.timer_list, &queue->timer_list.list);
101} 111}
102 112
@@ -188,6 +198,7 @@ static void __rpc_add_wait_queue(struct rpc_wait_queue *queue,
188 if (RPC_IS_QUEUED(task)) 198 if (RPC_IS_QUEUED(task))
189 return; 199 return;
190 200
201 INIT_LIST_HEAD(&task->u.tk_wait.timer_list);
191 if (RPC_IS_PRIORITY(queue)) 202 if (RPC_IS_PRIORITY(queue))
192 __rpc_add_wait_queue_priority(queue, task, queue_priority); 203 __rpc_add_wait_queue_priority(queue, task, queue_priority);
193 else if (RPC_IS_SWAPPER(task)) 204 else if (RPC_IS_SWAPPER(task))
@@ -238,7 +249,9 @@ static void __rpc_init_priority_wait_queue(struct rpc_wait_queue *queue, const c
238 queue->maxpriority = nr_queues - 1; 249 queue->maxpriority = nr_queues - 1;
239 rpc_reset_waitqueue_priority(queue); 250 rpc_reset_waitqueue_priority(queue);
240 queue->qlen = 0; 251 queue->qlen = 0;
241 timer_setup(&queue->timer_list.timer, __rpc_queue_timer_fn, 0); 252 timer_setup(&queue->timer_list.timer,
253 __rpc_queue_timer_fn,
254 TIMER_DEFERRABLE);
242 INIT_LIST_HEAD(&queue->timer_list.list); 255 INIT_LIST_HEAD(&queue->timer_list.list);
243 rpc_assign_waitqueue_name(queue, qname); 256 rpc_assign_waitqueue_name(queue, qname);
244} 257}
@@ -362,7 +375,6 @@ static void rpc_make_runnable(struct workqueue_struct *wq,
362 */ 375 */
363static void __rpc_sleep_on_priority(struct rpc_wait_queue *q, 376static void __rpc_sleep_on_priority(struct rpc_wait_queue *q,
364 struct rpc_task *task, 377 struct rpc_task *task,
365 rpc_action action,
366 unsigned char queue_priority) 378 unsigned char queue_priority)
367{ 379{
368 dprintk("RPC: %5u sleep_on(queue \"%s\" time %lu)\n", 380 dprintk("RPC: %5u sleep_on(queue \"%s\" time %lu)\n",
@@ -372,47 +384,100 @@ static void __rpc_sleep_on_priority(struct rpc_wait_queue *q,
372 384
373 __rpc_add_wait_queue(q, task, queue_priority); 385 __rpc_add_wait_queue(q, task, queue_priority);
374 386
375 WARN_ON_ONCE(task->tk_callback != NULL);
376 task->tk_callback = action;
377 __rpc_add_timer(q, task);
378} 387}
379 388
380void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task, 389static void __rpc_sleep_on_priority_timeout(struct rpc_wait_queue *q,
381 rpc_action action) 390 struct rpc_task *task, unsigned long timeout,
391 unsigned char queue_priority)
392{
393 if (time_is_after_jiffies(timeout)) {
394 __rpc_sleep_on_priority(q, task, queue_priority);
395 __rpc_add_timer(q, task, timeout);
396 } else
397 task->tk_status = -ETIMEDOUT;
398}
399
400static void rpc_set_tk_callback(struct rpc_task *task, rpc_action action)
401{
402 if (action && !WARN_ON_ONCE(task->tk_callback != NULL))
403 task->tk_callback = action;
404}
405
406static bool rpc_sleep_check_activated(struct rpc_task *task)
382{ 407{
383 /* We shouldn't ever put an inactive task to sleep */ 408 /* We shouldn't ever put an inactive task to sleep */
384 WARN_ON_ONCE(!RPC_IS_ACTIVATED(task)); 409 if (WARN_ON_ONCE(!RPC_IS_ACTIVATED(task))) {
385 if (!RPC_IS_ACTIVATED(task)) {
386 task->tk_status = -EIO; 410 task->tk_status = -EIO;
387 rpc_put_task_async(task); 411 rpc_put_task_async(task);
388 return; 412 return false;
389 } 413 }
414 return true;
415}
416
417void rpc_sleep_on_timeout(struct rpc_wait_queue *q, struct rpc_task *task,
418 rpc_action action, unsigned long timeout)
419{
420 if (!rpc_sleep_check_activated(task))
421 return;
422
423 rpc_set_tk_callback(task, action);
424
425 /*
426 * Protect the queue operations.
427 */
428 spin_lock_bh(&q->lock);
429 __rpc_sleep_on_priority_timeout(q, task, timeout, task->tk_priority);
430 spin_unlock_bh(&q->lock);
431}
432EXPORT_SYMBOL_GPL(rpc_sleep_on_timeout);
390 433
434void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
435 rpc_action action)
436{
437 if (!rpc_sleep_check_activated(task))
438 return;
439
440 rpc_set_tk_callback(task, action);
441
442 WARN_ON_ONCE(task->tk_timeout != 0);
391 /* 443 /*
392 * Protect the queue operations. 444 * Protect the queue operations.
393 */ 445 */
394 spin_lock_bh(&q->lock); 446 spin_lock_bh(&q->lock);
395 __rpc_sleep_on_priority(q, task, action, task->tk_priority); 447 __rpc_sleep_on_priority(q, task, task->tk_priority);
396 spin_unlock_bh(&q->lock); 448 spin_unlock_bh(&q->lock);
397} 449}
398EXPORT_SYMBOL_GPL(rpc_sleep_on); 450EXPORT_SYMBOL_GPL(rpc_sleep_on);
399 451
452void rpc_sleep_on_priority_timeout(struct rpc_wait_queue *q,
453 struct rpc_task *task, unsigned long timeout, int priority)
454{
455 if (!rpc_sleep_check_activated(task))
456 return;
457
458 priority -= RPC_PRIORITY_LOW;
459 /*
460 * Protect the queue operations.
461 */
462 spin_lock_bh(&q->lock);
463 __rpc_sleep_on_priority_timeout(q, task, timeout, priority);
464 spin_unlock_bh(&q->lock);
465}
466EXPORT_SYMBOL_GPL(rpc_sleep_on_priority_timeout);
467
400void rpc_sleep_on_priority(struct rpc_wait_queue *q, struct rpc_task *task, 468void rpc_sleep_on_priority(struct rpc_wait_queue *q, struct rpc_task *task,
401 rpc_action action, int priority) 469 int priority)
402{ 470{
403 /* We shouldn't ever put an inactive task to sleep */ 471 if (!rpc_sleep_check_activated(task))
404 WARN_ON_ONCE(!RPC_IS_ACTIVATED(task));
405 if (!RPC_IS_ACTIVATED(task)) {
406 task->tk_status = -EIO;
407 rpc_put_task_async(task);
408 return; 472 return;
409 }
410 473
474 WARN_ON_ONCE(task->tk_timeout != 0);
475 priority -= RPC_PRIORITY_LOW;
411 /* 476 /*
412 * Protect the queue operations. 477 * Protect the queue operations.
413 */ 478 */
414 spin_lock_bh(&q->lock); 479 spin_lock_bh(&q->lock);
415 __rpc_sleep_on_priority(q, task, action, priority - RPC_PRIORITY_LOW); 480 __rpc_sleep_on_priority(q, task, priority);
416 spin_unlock_bh(&q->lock); 481 spin_unlock_bh(&q->lock);
417} 482}
418EXPORT_SYMBOL_GPL(rpc_sleep_on_priority); 483EXPORT_SYMBOL_GPL(rpc_sleep_on_priority);
@@ -704,7 +769,7 @@ static void __rpc_queue_timer_fn(struct timer_list *t)
704 spin_lock(&queue->lock); 769 spin_lock(&queue->lock);
705 expires = now = jiffies; 770 expires = now = jiffies;
706 list_for_each_entry_safe(task, n, &queue->timer_list.list, u.tk_wait.timer_list) { 771 list_for_each_entry_safe(task, n, &queue->timer_list.list, u.tk_wait.timer_list) {
707 timeo = task->u.tk_wait.expires; 772 timeo = task->tk_timeout;
708 if (time_after_eq(now, timeo)) { 773 if (time_after_eq(now, timeo)) {
709 dprintk("RPC: %5u timeout\n", task->tk_pid); 774 dprintk("RPC: %5u timeout\n", task->tk_pid);
710 task->tk_status = -ETIMEDOUT; 775 task->tk_status = -ETIMEDOUT;
@@ -730,8 +795,7 @@ static void __rpc_atrun(struct rpc_task *task)
730 */ 795 */
731void rpc_delay(struct rpc_task *task, unsigned long delay) 796void rpc_delay(struct rpc_task *task, unsigned long delay)
732{ 797{
733 task->tk_timeout = delay; 798 rpc_sleep_on_timeout(&delay_queue, task, __rpc_atrun, jiffies + delay);
734 rpc_sleep_on(&delay_queue, task, __rpc_atrun);
735} 799}
736EXPORT_SYMBOL_GPL(rpc_delay); 800EXPORT_SYMBOL_GPL(rpc_delay);
737 801
@@ -759,8 +823,7 @@ static void
759rpc_reset_task_statistics(struct rpc_task *task) 823rpc_reset_task_statistics(struct rpc_task *task)
760{ 824{
761 task->tk_timeouts = 0; 825 task->tk_timeouts = 0;
762 task->tk_flags &= ~(RPC_CALL_MAJORSEEN|RPC_TASK_KILLED|RPC_TASK_SENT); 826 task->tk_flags &= ~(RPC_CALL_MAJORSEEN|RPC_TASK_SENT);
763
764 rpc_init_task_statistics(task); 827 rpc_init_task_statistics(task);
765} 828}
766 829
@@ -773,7 +836,6 @@ void rpc_exit_task(struct rpc_task *task)
773 if (task->tk_ops->rpc_call_done != NULL) { 836 if (task->tk_ops->rpc_call_done != NULL) {
774 task->tk_ops->rpc_call_done(task, task->tk_calldata); 837 task->tk_ops->rpc_call_done(task, task->tk_calldata);
775 if (task->tk_action != NULL) { 838 if (task->tk_action != NULL) {
776 WARN_ON(RPC_ASSASSINATED(task));
777 /* Always release the RPC slot and buffer memory */ 839 /* Always release the RPC slot and buffer memory */
778 xprt_release(task); 840 xprt_release(task);
779 rpc_reset_task_statistics(task); 841 rpc_reset_task_statistics(task);
@@ -781,6 +843,19 @@ void rpc_exit_task(struct rpc_task *task)
781 } 843 }
782} 844}
783 845
846void rpc_signal_task(struct rpc_task *task)
847{
848 struct rpc_wait_queue *queue;
849
850 if (!RPC_IS_ACTIVATED(task))
851 return;
852 set_bit(RPC_TASK_SIGNALLED, &task->tk_runstate);
853 smp_mb__after_atomic();
854 queue = READ_ONCE(task->tk_waitqueue);
855 if (queue)
856 rpc_wake_up_queued_task_set_status(queue, task, -ERESTARTSYS);
857}
858
784void rpc_exit(struct rpc_task *task, int status) 859void rpc_exit(struct rpc_task *task, int status)
785{ 860{
786 task->tk_status = status; 861 task->tk_status = status;
@@ -836,6 +911,13 @@ static void __rpc_execute(struct rpc_task *task)
836 */ 911 */
837 if (!RPC_IS_QUEUED(task)) 912 if (!RPC_IS_QUEUED(task))
838 continue; 913 continue;
914
915 /*
916 * Signalled tasks should exit rather than sleep.
917 */
918 if (RPC_SIGNALLED(task))
919 rpc_exit(task, -ERESTARTSYS);
920
839 /* 921 /*
840 * The queue->lock protects against races with 922 * The queue->lock protects against races with
841 * rpc_make_runnable(). 923 * rpc_make_runnable().
@@ -861,7 +943,7 @@ static void __rpc_execute(struct rpc_task *task)
861 status = out_of_line_wait_on_bit(&task->tk_runstate, 943 status = out_of_line_wait_on_bit(&task->tk_runstate,
862 RPC_TASK_QUEUED, rpc_wait_bit_killable, 944 RPC_TASK_QUEUED, rpc_wait_bit_killable,
863 TASK_KILLABLE); 945 TASK_KILLABLE);
864 if (status == -ERESTARTSYS) { 946 if (status < 0) {
865 /* 947 /*
866 * When a sync task receives a signal, it exits with 948 * When a sync task receives a signal, it exits with
867 * -ERESTARTSYS. In order to catch any callbacks that 949 * -ERESTARTSYS. In order to catch any callbacks that
@@ -869,7 +951,7 @@ static void __rpc_execute(struct rpc_task *task)
869 * break the loop here, but go around once more. 951 * break the loop here, but go around once more.
870 */ 952 */
871 dprintk("RPC: %5u got signal\n", task->tk_pid); 953 dprintk("RPC: %5u got signal\n", task->tk_pid);
872 task->tk_flags |= RPC_TASK_KILLED; 954 set_bit(RPC_TASK_SIGNALLED, &task->tk_runstate);
873 rpc_exit(task, -ERESTARTSYS); 955 rpc_exit(task, -ERESTARTSYS);
874 } 956 }
875 dprintk("RPC: %5u sync task resuming\n", task->tk_pid); 957 dprintk("RPC: %5u sync task resuming\n", task->tk_pid);
diff --git a/net/sunrpc/socklib.c b/net/sunrpc/socklib.c
index 7e55cfc69697..9faea12624a6 100644
--- a/net/sunrpc/socklib.c
+++ b/net/sunrpc/socklib.c
@@ -106,7 +106,7 @@ xdr_partial_copy_from_skb(struct xdr_buf *xdr, unsigned int base, struct xdr_skb
106 /* ACL likes to be lazy in allocating pages - ACLs 106 /* ACL likes to be lazy in allocating pages - ACLs
107 * are small by default but can get huge. */ 107 * are small by default but can get huge. */
108 if ((xdr->flags & XDRBUF_SPARSE_PAGES) && *ppage == NULL) { 108 if ((xdr->flags & XDRBUF_SPARSE_PAGES) && *ppage == NULL) {
109 *ppage = alloc_page(GFP_ATOMIC); 109 *ppage = alloc_page(GFP_NOWAIT | __GFP_NOWARN);
110 if (unlikely(*ppage == NULL)) { 110 if (unlikely(*ppage == NULL)) {
111 if (copied == 0) 111 if (copied == 0)
112 copied = -ENOMEM; 112 copied = -ENOMEM;
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index d7117d241460..a9d40bc7ebed 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -73,6 +73,15 @@ static void xprt_destroy(struct rpc_xprt *xprt);
73static DEFINE_SPINLOCK(xprt_list_lock); 73static DEFINE_SPINLOCK(xprt_list_lock);
74static LIST_HEAD(xprt_list); 74static LIST_HEAD(xprt_list);
75 75
76static unsigned long xprt_request_timeout(const struct rpc_rqst *req)
77{
78 unsigned long timeout = jiffies + req->rq_timeout;
79
80 if (time_before(timeout, req->rq_majortimeo))
81 return timeout;
82 return req->rq_majortimeo;
83}
84
76/** 85/**
77 * xprt_register_transport - register a transport implementation 86 * xprt_register_transport - register a transport implementation
78 * @transport: transport to register 87 * @transport: transport to register
@@ -209,9 +218,12 @@ out_unlock:
209out_sleep: 218out_sleep:
210 dprintk("RPC: %5u failed to lock transport %p\n", 219 dprintk("RPC: %5u failed to lock transport %p\n",
211 task->tk_pid, xprt); 220 task->tk_pid, xprt);
212 task->tk_timeout = RPC_IS_SOFT(task) ? req->rq_timeout : 0;
213 task->tk_status = -EAGAIN; 221 task->tk_status = -EAGAIN;
214 rpc_sleep_on(&xprt->sending, task, NULL); 222 if (RPC_IS_SOFT(task))
223 rpc_sleep_on_timeout(&xprt->sending, task, NULL,
224 xprt_request_timeout(req));
225 else
226 rpc_sleep_on(&xprt->sending, task, NULL);
215 return 0; 227 return 0;
216} 228}
217EXPORT_SYMBOL_GPL(xprt_reserve_xprt); 229EXPORT_SYMBOL_GPL(xprt_reserve_xprt);
@@ -273,9 +285,12 @@ out_unlock:
273 xprt_clear_locked(xprt); 285 xprt_clear_locked(xprt);
274out_sleep: 286out_sleep:
275 dprintk("RPC: %5u failed to lock transport %p\n", task->tk_pid, xprt); 287 dprintk("RPC: %5u failed to lock transport %p\n", task->tk_pid, xprt);
276 task->tk_timeout = RPC_IS_SOFT(task) ? req->rq_timeout : 0;
277 task->tk_status = -EAGAIN; 288 task->tk_status = -EAGAIN;
278 rpc_sleep_on(&xprt->sending, task, NULL); 289 if (RPC_IS_SOFT(task))
290 rpc_sleep_on_timeout(&xprt->sending, task, NULL,
291 xprt_request_timeout(req));
292 else
293 rpc_sleep_on(&xprt->sending, task, NULL);
279 return 0; 294 return 0;
280} 295}
281EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong); 296EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong);
@@ -554,53 +569,44 @@ bool xprt_write_space(struct rpc_xprt *xprt)
554} 569}
555EXPORT_SYMBOL_GPL(xprt_write_space); 570EXPORT_SYMBOL_GPL(xprt_write_space);
556 571
557/** 572static unsigned long xprt_abs_ktime_to_jiffies(ktime_t abstime)
558 * xprt_set_retrans_timeout_def - set a request's retransmit timeout
559 * @task: task whose timeout is to be set
560 *
561 * Set a request's retransmit timeout based on the transport's
562 * default timeout parameters. Used by transports that don't adjust
563 * the retransmit timeout based on round-trip time estimation.
564 */
565void xprt_set_retrans_timeout_def(struct rpc_task *task)
566{ 573{
567 task->tk_timeout = task->tk_rqstp->rq_timeout; 574 s64 delta = ktime_to_ns(ktime_get() - abstime);
575 return likely(delta >= 0) ?
576 jiffies - nsecs_to_jiffies(delta) :
577 jiffies + nsecs_to_jiffies(-delta);
568} 578}
569EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_def);
570 579
571/** 580static unsigned long xprt_calc_majortimeo(struct rpc_rqst *req)
572 * xprt_set_retrans_timeout_rtt - set a request's retransmit timeout
573 * @task: task whose timeout is to be set
574 *
575 * Set a request's retransmit timeout using the RTT estimator.
576 */
577void xprt_set_retrans_timeout_rtt(struct rpc_task *task)
578{ 581{
579 int timer = task->tk_msg.rpc_proc->p_timer; 582 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout;
580 struct rpc_clnt *clnt = task->tk_client; 583 unsigned long majortimeo = req->rq_timeout;
581 struct rpc_rtt *rtt = clnt->cl_rtt;
582 struct rpc_rqst *req = task->tk_rqstp;
583 unsigned long max_timeout = clnt->cl_timeout->to_maxval;
584 584
585 task->tk_timeout = rpc_calc_rto(rtt, timer); 585 if (to->to_exponential)
586 task->tk_timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries; 586 majortimeo <<= to->to_retries;
587 if (task->tk_timeout > max_timeout || task->tk_timeout == 0) 587 else
588 task->tk_timeout = max_timeout; 588 majortimeo += to->to_increment * to->to_retries;
589 if (majortimeo > to->to_maxval || majortimeo == 0)
590 majortimeo = to->to_maxval;
591 return majortimeo;
589} 592}
590EXPORT_SYMBOL_GPL(xprt_set_retrans_timeout_rtt);
591 593
592static void xprt_reset_majortimeo(struct rpc_rqst *req) 594static void xprt_reset_majortimeo(struct rpc_rqst *req)
593{ 595{
594 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout; 596 req->rq_majortimeo += xprt_calc_majortimeo(req);
597}
595 598
596 req->rq_majortimeo = req->rq_timeout; 599static void xprt_init_majortimeo(struct rpc_task *task, struct rpc_rqst *req)
597 if (to->to_exponential) 600{
598 req->rq_majortimeo <<= to->to_retries; 601 unsigned long time_init;
602 struct rpc_xprt *xprt = req->rq_xprt;
603
604 if (likely(xprt && xprt_connected(xprt)))
605 time_init = jiffies;
599 else 606 else
600 req->rq_majortimeo += to->to_increment * to->to_retries; 607 time_init = xprt_abs_ktime_to_jiffies(task->tk_start);
601 if (req->rq_majortimeo > to->to_maxval || req->rq_majortimeo == 0) 608 req->rq_timeout = task->tk_client->cl_timeout->to_initval;
602 req->rq_majortimeo = to->to_maxval; 609 req->rq_majortimeo = time_init + xprt_calc_majortimeo(req);
603 req->rq_majortimeo += jiffies;
604} 610}
605 611
606/** 612/**
@@ -822,9 +828,9 @@ void xprt_connect(struct rpc_task *task)
822 xprt->ops->close(xprt); 828 xprt->ops->close(xprt);
823 829
824 if (!xprt_connected(xprt)) { 830 if (!xprt_connected(xprt)) {
825 task->tk_timeout = task->tk_rqstp->rq_timeout;
826 task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie; 831 task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie;
827 rpc_sleep_on(&xprt->pending, task, NULL); 832 rpc_sleep_on_timeout(&xprt->pending, task, NULL,
833 xprt_request_timeout(task->tk_rqstp));
828 834
829 if (test_bit(XPRT_CLOSING, &xprt->state)) 835 if (test_bit(XPRT_CLOSING, &xprt->state))
830 return; 836 return;
@@ -949,7 +955,7 @@ xprt_is_pinned_rqst(struct rpc_rqst *req)
949 * @req: Request to pin 955 * @req: Request to pin
950 * 956 *
951 * Caller must ensure this is atomic with the call to xprt_lookup_rqst() 957 * Caller must ensure this is atomic with the call to xprt_lookup_rqst()
952 * so should be holding the xprt receive lock. 958 * so should be holding xprt->queue_lock.
953 */ 959 */
954void xprt_pin_rqst(struct rpc_rqst *req) 960void xprt_pin_rqst(struct rpc_rqst *req)
955{ 961{
@@ -961,7 +967,7 @@ EXPORT_SYMBOL_GPL(xprt_pin_rqst);
961 * xprt_unpin_rqst - Unpin a request on the transport receive list 967 * xprt_unpin_rqst - Unpin a request on the transport receive list
962 * @req: Request to pin 968 * @req: Request to pin
963 * 969 *
964 * Caller should be holding the xprt receive lock. 970 * Caller should be holding xprt->queue_lock.
965 */ 971 */
966void xprt_unpin_rqst(struct rpc_rqst *req) 972void xprt_unpin_rqst(struct rpc_rqst *req)
967{ 973{
@@ -1017,7 +1023,6 @@ xprt_request_enqueue_receive(struct rpc_task *task)
1017 set_bit(RPC_TASK_NEED_RECV, &task->tk_runstate); 1023 set_bit(RPC_TASK_NEED_RECV, &task->tk_runstate);
1018 spin_unlock(&xprt->queue_lock); 1024 spin_unlock(&xprt->queue_lock);
1019 1025
1020 xprt_reset_majortimeo(req);
1021 /* Turn off autodisconnect */ 1026 /* Turn off autodisconnect */
1022 del_singleshot_timer_sync(&xprt->timer); 1027 del_singleshot_timer_sync(&xprt->timer);
1023} 1028}
@@ -1103,6 +1108,49 @@ static void xprt_timer(struct rpc_task *task)
1103} 1108}
1104 1109
1105/** 1110/**
1111 * xprt_wait_for_reply_request_def - wait for reply
1112 * @task: pointer to rpc_task
1113 *
1114 * Set a request's retransmit timeout based on the transport's
1115 * default timeout parameters. Used by transports that don't adjust
1116 * the retransmit timeout based on round-trip time estimation,
1117 * and put the task to sleep on the pending queue.
1118 */
1119void xprt_wait_for_reply_request_def(struct rpc_task *task)
1120{
1121 struct rpc_rqst *req = task->tk_rqstp;
1122
1123 rpc_sleep_on_timeout(&req->rq_xprt->pending, task, xprt_timer,
1124 xprt_request_timeout(req));
1125}
1126EXPORT_SYMBOL_GPL(xprt_wait_for_reply_request_def);
1127
1128/**
1129 * xprt_wait_for_reply_request_rtt - wait for reply using RTT estimator
1130 * @task: pointer to rpc_task
1131 *
1132 * Set a request's retransmit timeout using the RTT estimator,
1133 * and put the task to sleep on the pending queue.
1134 */
1135void xprt_wait_for_reply_request_rtt(struct rpc_task *task)
1136{
1137 int timer = task->tk_msg.rpc_proc->p_timer;
1138 struct rpc_clnt *clnt = task->tk_client;
1139 struct rpc_rtt *rtt = clnt->cl_rtt;
1140 struct rpc_rqst *req = task->tk_rqstp;
1141 unsigned long max_timeout = clnt->cl_timeout->to_maxval;
1142 unsigned long timeout;
1143
1144 timeout = rpc_calc_rto(rtt, timer);
1145 timeout <<= rpc_ntimeo(rtt, timer) + req->rq_retries;
1146 if (timeout > max_timeout || timeout == 0)
1147 timeout = max_timeout;
1148 rpc_sleep_on_timeout(&req->rq_xprt->pending, task, xprt_timer,
1149 jiffies + timeout);
1150}
1151EXPORT_SYMBOL_GPL(xprt_wait_for_reply_request_rtt);
1152
1153/**
1106 * xprt_request_wait_receive - wait for the reply to an RPC request 1154 * xprt_request_wait_receive - wait for the reply to an RPC request
1107 * @task: RPC task about to send a request 1155 * @task: RPC task about to send a request
1108 * 1156 *
@@ -1121,8 +1169,7 @@ void xprt_request_wait_receive(struct rpc_task *task)
1121 */ 1169 */
1122 spin_lock(&xprt->queue_lock); 1170 spin_lock(&xprt->queue_lock);
1123 if (test_bit(RPC_TASK_NEED_RECV, &task->tk_runstate)) { 1171 if (test_bit(RPC_TASK_NEED_RECV, &task->tk_runstate)) {
1124 xprt->ops->set_retrans_timeout(task); 1172 xprt->ops->wait_for_reply_request(task);
1125 rpc_sleep_on(&xprt->pending, task, xprt_timer);
1126 /* 1173 /*
1127 * Send an extra queue wakeup call if the 1174 * Send an extra queue wakeup call if the
1128 * connection was dropped in case the call to 1175 * connection was dropped in case the call to
@@ -1337,6 +1384,10 @@ xprt_request_transmit(struct rpc_rqst *req, struct rpc_task *snd_task)
1337 if (status < 0) 1384 if (status < 0)
1338 goto out_dequeue; 1385 goto out_dequeue;
1339 } 1386 }
1387 if (RPC_SIGNALLED(task)) {
1388 status = -ERESTARTSYS;
1389 goto out_dequeue;
1390 }
1340 } 1391 }
1341 1392
1342 /* 1393 /*
@@ -1605,7 +1656,6 @@ xprt_request_init(struct rpc_task *task)
1605 struct rpc_xprt *xprt = task->tk_xprt; 1656 struct rpc_xprt *xprt = task->tk_xprt;
1606 struct rpc_rqst *req = task->tk_rqstp; 1657 struct rpc_rqst *req = task->tk_rqstp;
1607 1658
1608 req->rq_timeout = task->tk_client->cl_timeout->to_initval;
1609 req->rq_task = task; 1659 req->rq_task = task;
1610 req->rq_xprt = xprt; 1660 req->rq_xprt = xprt;
1611 req->rq_buffer = NULL; 1661 req->rq_buffer = NULL;
@@ -1618,7 +1668,7 @@ xprt_request_init(struct rpc_task *task)
1618 req->rq_snd_buf.bvec = NULL; 1668 req->rq_snd_buf.bvec = NULL;
1619 req->rq_rcv_buf.bvec = NULL; 1669 req->rq_rcv_buf.bvec = NULL;
1620 req->rq_release_snd_buf = NULL; 1670 req->rq_release_snd_buf = NULL;
1621 xprt_reset_majortimeo(req); 1671 xprt_init_majortimeo(task, req);
1622 dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid, 1672 dprintk("RPC: %5u reserved req %p xid %08x\n", task->tk_pid,
1623 req, ntohl(req->rq_xid)); 1673 req, ntohl(req->rq_xid));
1624} 1674}
@@ -1647,7 +1697,6 @@ void xprt_reserve(struct rpc_task *task)
1647 if (task->tk_rqstp != NULL) 1697 if (task->tk_rqstp != NULL)
1648 return; 1698 return;
1649 1699
1650 task->tk_timeout = 0;
1651 task->tk_status = -EAGAIN; 1700 task->tk_status = -EAGAIN;
1652 if (!xprt_throttle_congested(xprt, task)) 1701 if (!xprt_throttle_congested(xprt, task))
1653 xprt_do_reserve(xprt, task); 1702 xprt_do_reserve(xprt, task);
@@ -1670,7 +1719,6 @@ void xprt_retry_reserve(struct rpc_task *task)
1670 if (task->tk_rqstp != NULL) 1719 if (task->tk_rqstp != NULL)
1671 return; 1720 return;
1672 1721
1673 task->tk_timeout = 0;
1674 task->tk_status = -EAGAIN; 1722 task->tk_status = -EAGAIN;
1675 xprt_do_reserve(xprt, task); 1723 xprt_do_reserve(xprt, task);
1676} 1724}
@@ -1827,7 +1875,9 @@ found:
1827 xprt->idle_timeout = 0; 1875 xprt->idle_timeout = 0;
1828 INIT_WORK(&xprt->task_cleanup, xprt_autoclose); 1876 INIT_WORK(&xprt->task_cleanup, xprt_autoclose);
1829 if (xprt_has_timer(xprt)) 1877 if (xprt_has_timer(xprt))
1830 timer_setup(&xprt->timer, xprt_init_autodisconnect, 0); 1878 timer_setup(&xprt->timer,
1879 xprt_init_autodisconnect,
1880 TIMER_DEFERRABLE);
1831 else 1881 else
1832 timer_setup(&xprt->timer, NULL, 0); 1882 timer_setup(&xprt->timer, NULL, 0);
1833 1883
diff --git a/net/sunrpc/xprtrdma/backchannel.c b/net/sunrpc/xprtrdma/backchannel.c
index d79b18c1f4cd..ce986591f213 100644
--- a/net/sunrpc/xprtrdma/backchannel.c
+++ b/net/sunrpc/xprtrdma/backchannel.c
@@ -19,45 +19,6 @@
19 19
20#undef RPCRDMA_BACKCHANNEL_DEBUG 20#undef RPCRDMA_BACKCHANNEL_DEBUG
21 21
22static int rpcrdma_bc_setup_reqs(struct rpcrdma_xprt *r_xprt,
23 unsigned int count)
24{
25 struct rpc_xprt *xprt = &r_xprt->rx_xprt;
26 struct rpcrdma_req *req;
27 struct rpc_rqst *rqst;
28 unsigned int i;
29
30 for (i = 0; i < (count << 1); i++) {
31 struct rpcrdma_regbuf *rb;
32 size_t size;
33
34 req = rpcrdma_create_req(r_xprt);
35 if (IS_ERR(req))
36 return PTR_ERR(req);
37 rqst = &req->rl_slot;
38
39 rqst->rq_xprt = xprt;
40 INIT_LIST_HEAD(&rqst->rq_bc_list);
41 __set_bit(RPC_BC_PA_IN_USE, &rqst->rq_bc_pa_state);
42 spin_lock(&xprt->bc_pa_lock);
43 list_add(&rqst->rq_bc_pa_list, &xprt->bc_pa_list);
44 spin_unlock(&xprt->bc_pa_lock);
45
46 size = r_xprt->rx_data.inline_rsize;
47 rb = rpcrdma_alloc_regbuf(size, DMA_TO_DEVICE, GFP_KERNEL);
48 if (IS_ERR(rb))
49 goto out_fail;
50 req->rl_sendbuf = rb;
51 xdr_buf_init(&rqst->rq_snd_buf, rb->rg_base,
52 min_t(size_t, size, PAGE_SIZE));
53 }
54 return 0;
55
56out_fail:
57 rpcrdma_req_destroy(req);
58 return -ENOMEM;
59}
60
61/** 22/**
62 * xprt_rdma_bc_setup - Pre-allocate resources for handling backchannel requests 23 * xprt_rdma_bc_setup - Pre-allocate resources for handling backchannel requests
63 * @xprt: transport associated with these backchannel resources 24 * @xprt: transport associated with these backchannel resources
@@ -68,34 +29,10 @@ out_fail:
68int xprt_rdma_bc_setup(struct rpc_xprt *xprt, unsigned int reqs) 29int xprt_rdma_bc_setup(struct rpc_xprt *xprt, unsigned int reqs)
69{ 30{
70 struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt); 31 struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
71 int rc;
72 32
73 /* The backchannel reply path returns each rpc_rqst to the 33 r_xprt->rx_buf.rb_bc_srv_max_requests = RPCRDMA_BACKWARD_WRS >> 1;
74 * bc_pa_list _after_ the reply is sent. If the server is
75 * faster than the client, it can send another backward
76 * direction request before the rpc_rqst is returned to the
77 * list. The client rejects the request in this case.
78 *
79 * Twice as many rpc_rqsts are prepared to ensure there is
80 * always an rpc_rqst available as soon as a reply is sent.
81 */
82 if (reqs > RPCRDMA_BACKWARD_WRS >> 1)
83 goto out_err;
84
85 rc = rpcrdma_bc_setup_reqs(r_xprt, reqs);
86 if (rc)
87 goto out_free;
88
89 r_xprt->rx_buf.rb_bc_srv_max_requests = reqs;
90 trace_xprtrdma_cb_setup(r_xprt, reqs); 34 trace_xprtrdma_cb_setup(r_xprt, reqs);
91 return 0; 35 return 0;
92
93out_free:
94 xprt_rdma_bc_destroy(xprt, reqs);
95
96out_err:
97 pr_err("RPC: %s: setup backchannel transport failed\n", __func__);
98 return -ENOMEM;
99} 36}
100 37
101/** 38/**
@@ -107,10 +44,10 @@ out_err:
107size_t xprt_rdma_bc_maxpayload(struct rpc_xprt *xprt) 44size_t xprt_rdma_bc_maxpayload(struct rpc_xprt *xprt)
108{ 45{
109 struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt); 46 struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
110 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data; 47 struct rpcrdma_ep *ep = &r_xprt->rx_ep;
111 size_t maxmsg; 48 size_t maxmsg;
112 49
113 maxmsg = min_t(unsigned int, cdata->inline_rsize, cdata->inline_wsize); 50 maxmsg = min_t(unsigned int, ep->rep_inline_send, ep->rep_inline_recv);
114 maxmsg = min_t(unsigned int, maxmsg, PAGE_SIZE); 51 maxmsg = min_t(unsigned int, maxmsg, PAGE_SIZE);
115 return maxmsg - RPCRDMA_HDRLEN_MIN; 52 return maxmsg - RPCRDMA_HDRLEN_MIN;
116} 53}
@@ -123,7 +60,7 @@ static int rpcrdma_bc_marshal_reply(struct rpc_rqst *rqst)
123 60
124 rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0); 61 rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0);
125 xdr_init_encode(&req->rl_stream, &req->rl_hdrbuf, 62 xdr_init_encode(&req->rl_stream, &req->rl_hdrbuf,
126 req->rl_rdmabuf->rg_base, rqst); 63 rdmab_data(req->rl_rdmabuf), rqst);
127 64
128 p = xdr_reserve_space(&req->rl_stream, 28); 65 p = xdr_reserve_space(&req->rl_stream, 28);
129 if (unlikely(!p)) 66 if (unlikely(!p))
@@ -223,6 +160,43 @@ void xprt_rdma_bc_free_rqst(struct rpc_rqst *rqst)
223 spin_unlock(&xprt->bc_pa_lock); 160 spin_unlock(&xprt->bc_pa_lock);
224} 161}
225 162
163static struct rpc_rqst *rpcrdma_bc_rqst_get(struct rpcrdma_xprt *r_xprt)
164{
165 struct rpc_xprt *xprt = &r_xprt->rx_xprt;
166 struct rpcrdma_req *req;
167 struct rpc_rqst *rqst;
168 size_t size;
169
170 spin_lock(&xprt->bc_pa_lock);
171 rqst = list_first_entry_or_null(&xprt->bc_pa_list, struct rpc_rqst,
172 rq_bc_pa_list);
173 if (!rqst)
174 goto create_req;
175 list_del(&rqst->rq_bc_pa_list);
176 spin_unlock(&xprt->bc_pa_lock);
177 return rqst;
178
179create_req:
180 spin_unlock(&xprt->bc_pa_lock);
181
182 /* Set a limit to prevent a remote from overrunning our resources.
183 */
184 if (xprt->bc_alloc_count >= RPCRDMA_BACKWARD_WRS)
185 return NULL;
186
187 size = min_t(size_t, r_xprt->rx_ep.rep_inline_recv, PAGE_SIZE);
188 req = rpcrdma_req_create(r_xprt, size, GFP_KERNEL);
189 if (!req)
190 return NULL;
191
192 xprt->bc_alloc_count++;
193 rqst = &req->rl_slot;
194 rqst->rq_xprt = xprt;
195 __set_bit(RPC_BC_PA_IN_USE, &rqst->rq_bc_pa_state);
196 xdr_buf_init(&rqst->rq_snd_buf, rdmab_data(req->rl_sendbuf), size);
197 return rqst;
198}
199
226/** 200/**
227 * rpcrdma_bc_receive_call - Handle a backward direction call 201 * rpcrdma_bc_receive_call - Handle a backward direction call
228 * @r_xprt: transport receiving the call 202 * @r_xprt: transport receiving the call
@@ -254,18 +228,10 @@ void rpcrdma_bc_receive_call(struct rpcrdma_xprt *r_xprt,
254 pr_info("RPC: %s: %*ph\n", __func__, size, p); 228 pr_info("RPC: %s: %*ph\n", __func__, size, p);
255#endif 229#endif
256 230
257 /* Grab a free bc rqst */ 231 rqst = rpcrdma_bc_rqst_get(r_xprt);
258 spin_lock(&xprt->bc_pa_lock); 232 if (!rqst)
259 if (list_empty(&xprt->bc_pa_list)) {
260 spin_unlock(&xprt->bc_pa_lock);
261 goto out_overflow; 233 goto out_overflow;
262 }
263 rqst = list_first_entry(&xprt->bc_pa_list,
264 struct rpc_rqst, rq_bc_pa_list);
265 list_del(&rqst->rq_bc_pa_list);
266 spin_unlock(&xprt->bc_pa_lock);
267 234
268 /* Prepare rqst */
269 rqst->rq_reply_bytes_recvd = 0; 235 rqst->rq_reply_bytes_recvd = 0;
270 rqst->rq_xid = *p; 236 rqst->rq_xid = *p;
271 237
diff --git a/net/sunrpc/xprtrdma/frwr_ops.c b/net/sunrpc/xprtrdma/frwr_ops.c
index 52cb6c1b0c2b..794ba4ca0994 100644
--- a/net/sunrpc/xprtrdma/frwr_ops.c
+++ b/net/sunrpc/xprtrdma/frwr_ops.c
@@ -82,13 +82,13 @@
82 82
83/** 83/**
84 * frwr_is_supported - Check if device supports FRWR 84 * frwr_is_supported - Check if device supports FRWR
85 * @ia: interface adapter to check 85 * @device: interface adapter to check
86 * 86 *
87 * Returns true if device supports FRWR, otherwise false 87 * Returns true if device supports FRWR, otherwise false
88 */ 88 */
89bool frwr_is_supported(struct rpcrdma_ia *ia) 89bool frwr_is_supported(struct ib_device *device)
90{ 90{
91 struct ib_device_attr *attrs = &ia->ri_device->attrs; 91 struct ib_device_attr *attrs = &device->attrs;
92 92
93 if (!(attrs->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS)) 93 if (!(attrs->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS))
94 goto out_not_supported; 94 goto out_not_supported;
@@ -98,7 +98,7 @@ bool frwr_is_supported(struct rpcrdma_ia *ia)
98 98
99out_not_supported: 99out_not_supported:
100 pr_info("rpcrdma: 'frwr' mode is not supported by device %s\n", 100 pr_info("rpcrdma: 'frwr' mode is not supported by device %s\n",
101 ia->ri_device->name); 101 device->name);
102 return false; 102 return false;
103} 103}
104 104
@@ -131,7 +131,7 @@ frwr_mr_recycle_worker(struct work_struct *work)
131 131
132 if (mr->mr_dir != DMA_NONE) { 132 if (mr->mr_dir != DMA_NONE) {
133 trace_xprtrdma_mr_unmap(mr); 133 trace_xprtrdma_mr_unmap(mr);
134 ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, 134 ib_dma_unmap_sg(r_xprt->rx_ia.ri_id->device,
135 mr->mr_sg, mr->mr_nents, mr->mr_dir); 135 mr->mr_sg, mr->mr_nents, mr->mr_dir);
136 mr->mr_dir = DMA_NONE; 136 mr->mr_dir = DMA_NONE;
137 } 137 }
@@ -194,12 +194,11 @@ out_list_err:
194 * frwr_open - Prepare an endpoint for use with FRWR 194 * frwr_open - Prepare an endpoint for use with FRWR
195 * @ia: interface adapter this endpoint will use 195 * @ia: interface adapter this endpoint will use
196 * @ep: endpoint to prepare 196 * @ep: endpoint to prepare
197 * @cdata: transport parameters
198 * 197 *
199 * On success, sets: 198 * On success, sets:
200 * ep->rep_attr.cap.max_send_wr 199 * ep->rep_attr.cap.max_send_wr
201 * ep->rep_attr.cap.max_recv_wr 200 * ep->rep_attr.cap.max_recv_wr
202 * cdata->max_requests 201 * ep->rep_max_requests
203 * ia->ri_max_segs 202 * ia->ri_max_segs
204 * 203 *
205 * And these FRWR-related fields: 204 * And these FRWR-related fields:
@@ -208,10 +207,9 @@ out_list_err:
208 * 207 *
209 * On failure, a negative errno is returned. 208 * On failure, a negative errno is returned.
210 */ 209 */
211int frwr_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep, 210int frwr_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep)
212 struct rpcrdma_create_data_internal *cdata)
213{ 211{
214 struct ib_device_attr *attrs = &ia->ri_device->attrs; 212 struct ib_device_attr *attrs = &ia->ri_id->device->attrs;
215 int max_qp_wr, depth, delta; 213 int max_qp_wr, depth, delta;
216 214
217 ia->ri_mrtype = IB_MR_TYPE_MEM_REG; 215 ia->ri_mrtype = IB_MR_TYPE_MEM_REG;
@@ -253,24 +251,23 @@ int frwr_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep,
253 } while (delta > 0); 251 } while (delta > 0);
254 } 252 }
255 253
256 max_qp_wr = ia->ri_device->attrs.max_qp_wr; 254 max_qp_wr = ia->ri_id->device->attrs.max_qp_wr;
257 max_qp_wr -= RPCRDMA_BACKWARD_WRS; 255 max_qp_wr -= RPCRDMA_BACKWARD_WRS;
258 max_qp_wr -= 1; 256 max_qp_wr -= 1;
259 if (max_qp_wr < RPCRDMA_MIN_SLOT_TABLE) 257 if (max_qp_wr < RPCRDMA_MIN_SLOT_TABLE)
260 return -ENOMEM; 258 return -ENOMEM;
261 if (cdata->max_requests > max_qp_wr) 259 if (ep->rep_max_requests > max_qp_wr)
262 cdata->max_requests = max_qp_wr; 260 ep->rep_max_requests = max_qp_wr;
263 ep->rep_attr.cap.max_send_wr = cdata->max_requests * depth; 261 ep->rep_attr.cap.max_send_wr = ep->rep_max_requests * depth;
264 if (ep->rep_attr.cap.max_send_wr > max_qp_wr) { 262 if (ep->rep_attr.cap.max_send_wr > max_qp_wr) {
265 cdata->max_requests = max_qp_wr / depth; 263 ep->rep_max_requests = max_qp_wr / depth;
266 if (!cdata->max_requests) 264 if (!ep->rep_max_requests)
267 return -EINVAL; 265 return -EINVAL;
268 ep->rep_attr.cap.max_send_wr = cdata->max_requests * 266 ep->rep_attr.cap.max_send_wr = ep->rep_max_requests * depth;
269 depth;
270 } 267 }
271 ep->rep_attr.cap.max_send_wr += RPCRDMA_BACKWARD_WRS; 268 ep->rep_attr.cap.max_send_wr += RPCRDMA_BACKWARD_WRS;
272 ep->rep_attr.cap.max_send_wr += 1; /* for ib_drain_sq */ 269 ep->rep_attr.cap.max_send_wr += 1; /* for ib_drain_sq */
273 ep->rep_attr.cap.max_recv_wr = cdata->max_requests; 270 ep->rep_attr.cap.max_recv_wr = ep->rep_max_requests;
274 ep->rep_attr.cap.max_recv_wr += RPCRDMA_BACKWARD_WRS; 271 ep->rep_attr.cap.max_recv_wr += RPCRDMA_BACKWARD_WRS;
275 ep->rep_attr.cap.max_recv_wr += 1; /* for ib_drain_rq */ 272 ep->rep_attr.cap.max_recv_wr += 1; /* for ib_drain_rq */
276 273
@@ -300,15 +297,6 @@ size_t frwr_maxpages(struct rpcrdma_xprt *r_xprt)
300 (ia->ri_max_segs - 2) * ia->ri_max_frwr_depth); 297 (ia->ri_max_segs - 2) * ia->ri_max_frwr_depth);
301} 298}
302 299
303static void
304__frwr_sendcompletion_flush(struct ib_wc *wc, const char *wr)
305{
306 if (wc->status != IB_WC_WR_FLUSH_ERR)
307 pr_err("rpcrdma: %s: %s (%u/0x%x)\n",
308 wr, ib_wc_status_msg(wc->status),
309 wc->status, wc->vendor_err);
310}
311
312/** 300/**
313 * frwr_wc_fastreg - Invoked by RDMA provider for a flushed FastReg WC 301 * frwr_wc_fastreg - Invoked by RDMA provider for a flushed FastReg WC
314 * @cq: completion queue (ignored) 302 * @cq: completion queue (ignored)
@@ -323,10 +311,8 @@ frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc)
323 container_of(cqe, struct rpcrdma_frwr, fr_cqe); 311 container_of(cqe, struct rpcrdma_frwr, fr_cqe);
324 312
325 /* WARNING: Only wr_cqe and status are reliable at this point */ 313 /* WARNING: Only wr_cqe and status are reliable at this point */
326 if (wc->status != IB_WC_SUCCESS) { 314 if (wc->status != IB_WC_SUCCESS)
327 frwr->fr_state = FRWR_FLUSHED_FR; 315 frwr->fr_state = FRWR_FLUSHED_FR;
328 __frwr_sendcompletion_flush(wc, "fastreg");
329 }
330 trace_xprtrdma_wc_fastreg(wc, frwr); 316 trace_xprtrdma_wc_fastreg(wc, frwr);
331} 317}
332 318
@@ -344,10 +330,8 @@ frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc)
344 fr_cqe); 330 fr_cqe);
345 331
346 /* WARNING: Only wr_cqe and status are reliable at this point */ 332 /* WARNING: Only wr_cqe and status are reliable at this point */
347 if (wc->status != IB_WC_SUCCESS) { 333 if (wc->status != IB_WC_SUCCESS)
348 frwr->fr_state = FRWR_FLUSHED_LI; 334 frwr->fr_state = FRWR_FLUSHED_LI;
349 __frwr_sendcompletion_flush(wc, "localinv");
350 }
351 trace_xprtrdma_wc_li(wc, frwr); 335 trace_xprtrdma_wc_li(wc, frwr);
352} 336}
353 337
@@ -366,12 +350,10 @@ frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc)
366 fr_cqe); 350 fr_cqe);
367 351
368 /* WARNING: Only wr_cqe and status are reliable at this point */ 352 /* WARNING: Only wr_cqe and status are reliable at this point */
369 if (wc->status != IB_WC_SUCCESS) { 353 if (wc->status != IB_WC_SUCCESS)
370 frwr->fr_state = FRWR_FLUSHED_LI; 354 frwr->fr_state = FRWR_FLUSHED_LI;
371 __frwr_sendcompletion_flush(wc, "localinv");
372 }
373 complete(&frwr->fr_linv_done);
374 trace_xprtrdma_wc_li_wake(wc, frwr); 355 trace_xprtrdma_wc_li_wake(wc, frwr);
356 complete(&frwr->fr_linv_done);
375} 357}
376 358
377/** 359/**
@@ -436,7 +418,8 @@ struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
436 } 418 }
437 mr->mr_dir = rpcrdma_data_dir(writing); 419 mr->mr_dir = rpcrdma_data_dir(writing);
438 420
439 mr->mr_nents = ib_dma_map_sg(ia->ri_device, mr->mr_sg, i, mr->mr_dir); 421 mr->mr_nents =
422 ib_dma_map_sg(ia->ri_id->device, mr->mr_sg, i, mr->mr_dir);
440 if (!mr->mr_nents) 423 if (!mr->mr_nents)
441 goto out_dmamap_err; 424 goto out_dmamap_err;
442 425
@@ -466,7 +449,7 @@ struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt,
466 return seg; 449 return seg;
467 450
468out_dmamap_err: 451out_dmamap_err:
469 frwr->fr_state = FRWR_IS_INVALID; 452 mr->mr_dir = DMA_NONE;
470 trace_xprtrdma_frwr_sgerr(mr, i); 453 trace_xprtrdma_frwr_sgerr(mr, i);
471 rpcrdma_mr_put(mr); 454 rpcrdma_mr_put(mr);
472 return ERR_PTR(-EIO); 455 return ERR_PTR(-EIO);
diff --git a/net/sunrpc/xprtrdma/rpc_rdma.c b/net/sunrpc/xprtrdma/rpc_rdma.c
index 6c1fb270f127..85115a2e2639 100644
--- a/net/sunrpc/xprtrdma/rpc_rdma.c
+++ b/net/sunrpc/xprtrdma/rpc_rdma.c
@@ -105,16 +105,23 @@ static unsigned int rpcrdma_max_reply_header_size(unsigned int maxsegs)
105 return size; 105 return size;
106} 106}
107 107
108/**
109 * rpcrdma_set_max_header_sizes - Initialize inline payload sizes
110 * @r_xprt: transport instance to initialize
111 *
112 * The max_inline fields contain the maximum size of an RPC message
113 * so the marshaling code doesn't have to repeat this calculation
114 * for every RPC.
115 */
108void rpcrdma_set_max_header_sizes(struct rpcrdma_xprt *r_xprt) 116void rpcrdma_set_max_header_sizes(struct rpcrdma_xprt *r_xprt)
109{ 117{
110 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data; 118 unsigned int maxsegs = r_xprt->rx_ia.ri_max_segs;
111 struct rpcrdma_ia *ia = &r_xprt->rx_ia; 119 struct rpcrdma_ep *ep = &r_xprt->rx_ep;
112 unsigned int maxsegs = ia->ri_max_segs; 120
113 121 ep->rep_max_inline_send =
114 ia->ri_max_inline_write = cdata->inline_wsize - 122 ep->rep_inline_send - rpcrdma_max_call_header_size(maxsegs);
115 rpcrdma_max_call_header_size(maxsegs); 123 ep->rep_max_inline_recv =
116 ia->ri_max_inline_read = cdata->inline_rsize - 124 ep->rep_inline_recv - rpcrdma_max_reply_header_size(maxsegs);
117 rpcrdma_max_reply_header_size(maxsegs);
118} 125}
119 126
120/* The client can send a request inline as long as the RPCRDMA header 127/* The client can send a request inline as long as the RPCRDMA header
@@ -131,7 +138,7 @@ static bool rpcrdma_args_inline(struct rpcrdma_xprt *r_xprt,
131 struct xdr_buf *xdr = &rqst->rq_snd_buf; 138 struct xdr_buf *xdr = &rqst->rq_snd_buf;
132 unsigned int count, remaining, offset; 139 unsigned int count, remaining, offset;
133 140
134 if (xdr->len > r_xprt->rx_ia.ri_max_inline_write) 141 if (xdr->len > r_xprt->rx_ep.rep_max_inline_send)
135 return false; 142 return false;
136 143
137 if (xdr->page_len) { 144 if (xdr->page_len) {
@@ -159,9 +166,7 @@ static bool rpcrdma_args_inline(struct rpcrdma_xprt *r_xprt,
159static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt, 166static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,
160 struct rpc_rqst *rqst) 167 struct rpc_rqst *rqst)
161{ 168{
162 struct rpcrdma_ia *ia = &r_xprt->rx_ia; 169 return rqst->rq_rcv_buf.buflen <= r_xprt->rx_ep.rep_max_inline_recv;
163
164 return rqst->rq_rcv_buf.buflen <= ia->ri_max_inline_read;
165} 170}
166 171
167/* The client is required to provide a Reply chunk if the maximum 172/* The client is required to provide a Reply chunk if the maximum
@@ -173,10 +178,9 @@ rpcrdma_nonpayload_inline(const struct rpcrdma_xprt *r_xprt,
173 const struct rpc_rqst *rqst) 178 const struct rpc_rqst *rqst)
174{ 179{
175 const struct xdr_buf *buf = &rqst->rq_rcv_buf; 180 const struct xdr_buf *buf = &rqst->rq_rcv_buf;
176 const struct rpcrdma_ia *ia = &r_xprt->rx_ia;
177 181
178 return buf->head[0].iov_len + buf->tail[0].iov_len < 182 return (buf->head[0].iov_len + buf->tail[0].iov_len) <
179 ia->ri_max_inline_read; 183 r_xprt->rx_ep.rep_max_inline_recv;
180} 184}
181 185
182/* Split @vec on page boundaries into SGEs. FMR registers pages, not 186/* Split @vec on page boundaries into SGEs. FMR registers pages, not
@@ -238,7 +242,7 @@ rpcrdma_convert_iovs(struct rpcrdma_xprt *r_xprt, struct xdr_buf *xdrbuf,
238 */ 242 */
239 if (unlikely(xdrbuf->flags & XDRBUF_SPARSE_PAGES)) { 243 if (unlikely(xdrbuf->flags & XDRBUF_SPARSE_PAGES)) {
240 if (!*ppages) 244 if (!*ppages)
241 *ppages = alloc_page(GFP_ATOMIC); 245 *ppages = alloc_page(GFP_NOWAIT | __GFP_NOWARN);
242 if (!*ppages) 246 if (!*ppages)
243 return -ENOBUFS; 247 return -ENOBUFS;
244 } 248 }
@@ -508,50 +512,45 @@ rpcrdma_encode_reply_chunk(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
508} 512}
509 513
510/** 514/**
511 * rpcrdma_unmap_sendctx - DMA-unmap Send buffers 515 * rpcrdma_sendctx_unmap - DMA-unmap Send buffer
512 * @sc: sendctx containing SGEs to unmap 516 * @sc: sendctx containing SGEs to unmap
513 * 517 *
514 */ 518 */
515void 519void rpcrdma_sendctx_unmap(struct rpcrdma_sendctx *sc)
516rpcrdma_unmap_sendctx(struct rpcrdma_sendctx *sc)
517{ 520{
518 struct rpcrdma_ia *ia = &sc->sc_xprt->rx_ia;
519 struct ib_sge *sge; 521 struct ib_sge *sge;
520 unsigned int count;
521 522
522 /* The first two SGEs contain the transport header and 523 /* The first two SGEs contain the transport header and
523 * the inline buffer. These are always left mapped so 524 * the inline buffer. These are always left mapped so
524 * they can be cheaply re-used. 525 * they can be cheaply re-used.
525 */ 526 */
526 sge = &sc->sc_sges[2]; 527 for (sge = &sc->sc_sges[2]; sc->sc_unmap_count;
527 for (count = sc->sc_unmap_count; count; ++sge, --count) 528 ++sge, --sc->sc_unmap_count)
528 ib_dma_unmap_page(ia->ri_device, 529 ib_dma_unmap_page(sc->sc_device, sge->addr, sge->length,
529 sge->addr, sge->length, DMA_TO_DEVICE); 530 DMA_TO_DEVICE);
530 531
531 if (test_and_clear_bit(RPCRDMA_REQ_F_TX_RESOURCES, &sc->sc_req->rl_flags)) { 532 if (test_and_clear_bit(RPCRDMA_REQ_F_TX_RESOURCES,
532 smp_mb__after_atomic(); 533 &sc->sc_req->rl_flags))
533 wake_up_bit(&sc->sc_req->rl_flags, RPCRDMA_REQ_F_TX_RESOURCES); 534 wake_up_bit(&sc->sc_req->rl_flags, RPCRDMA_REQ_F_TX_RESOURCES);
534 }
535} 535}
536 536
537/* Prepare an SGE for the RPC-over-RDMA transport header. 537/* Prepare an SGE for the RPC-over-RDMA transport header.
538 */ 538 */
539static bool 539static bool rpcrdma_prepare_hdr_sge(struct rpcrdma_xprt *r_xprt,
540rpcrdma_prepare_hdr_sge(struct rpcrdma_ia *ia, struct rpcrdma_req *req, 540 struct rpcrdma_req *req, u32 len)
541 u32 len)
542{ 541{
543 struct rpcrdma_sendctx *sc = req->rl_sendctx; 542 struct rpcrdma_sendctx *sc = req->rl_sendctx;
544 struct rpcrdma_regbuf *rb = req->rl_rdmabuf; 543 struct rpcrdma_regbuf *rb = req->rl_rdmabuf;
545 struct ib_sge *sge = sc->sc_sges; 544 struct ib_sge *sge = sc->sc_sges;
546 545
547 if (!rpcrdma_dma_map_regbuf(ia, rb)) 546 if (!rpcrdma_regbuf_dma_map(r_xprt, rb))
548 goto out_regbuf; 547 goto out_regbuf;
549 sge->addr = rdmab_addr(rb); 548 sge->addr = rdmab_addr(rb);
550 sge->length = len; 549 sge->length = len;
551 sge->lkey = rdmab_lkey(rb); 550 sge->lkey = rdmab_lkey(rb);
552 551
553 ib_dma_sync_single_for_device(rdmab_device(rb), sge->addr, 552 ib_dma_sync_single_for_device(rdmab_device(rb), sge->addr, sge->length,
554 sge->length, DMA_TO_DEVICE); 553 DMA_TO_DEVICE);
555 sc->sc_wr.num_sge++; 554 sc->sc_wr.num_sge++;
556 return true; 555 return true;
557 556
@@ -563,23 +562,23 @@ out_regbuf:
563/* Prepare the Send SGEs. The head and tail iovec, and each entry 562/* Prepare the Send SGEs. The head and tail iovec, and each entry
564 * in the page list, gets its own SGE. 563 * in the page list, gets its own SGE.
565 */ 564 */
566static bool 565static bool rpcrdma_prepare_msg_sges(struct rpcrdma_xprt *r_xprt,
567rpcrdma_prepare_msg_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req, 566 struct rpcrdma_req *req,
568 struct xdr_buf *xdr, enum rpcrdma_chunktype rtype) 567 struct xdr_buf *xdr,
568 enum rpcrdma_chunktype rtype)
569{ 569{
570 struct rpcrdma_sendctx *sc = req->rl_sendctx; 570 struct rpcrdma_sendctx *sc = req->rl_sendctx;
571 unsigned int sge_no, page_base, len, remaining; 571 unsigned int sge_no, page_base, len, remaining;
572 struct rpcrdma_regbuf *rb = req->rl_sendbuf; 572 struct rpcrdma_regbuf *rb = req->rl_sendbuf;
573 struct ib_device *device = ia->ri_device;
574 struct ib_sge *sge = sc->sc_sges; 573 struct ib_sge *sge = sc->sc_sges;
575 u32 lkey = ia->ri_pd->local_dma_lkey;
576 struct page *page, **ppages; 574 struct page *page, **ppages;
577 575
578 /* The head iovec is straightforward, as it is already 576 /* The head iovec is straightforward, as it is already
579 * DMA-mapped. Sync the content that has changed. 577 * DMA-mapped. Sync the content that has changed.
580 */ 578 */
581 if (!rpcrdma_dma_map_regbuf(ia, rb)) 579 if (!rpcrdma_regbuf_dma_map(r_xprt, rb))
582 goto out_regbuf; 580 goto out_regbuf;
581 sc->sc_device = rdmab_device(rb);
583 sge_no = 1; 582 sge_no = 1;
584 sge[sge_no].addr = rdmab_addr(rb); 583 sge[sge_no].addr = rdmab_addr(rb);
585 sge[sge_no].length = xdr->head[0].iov_len; 584 sge[sge_no].length = xdr->head[0].iov_len;
@@ -626,13 +625,14 @@ rpcrdma_prepare_msg_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
626 goto out_mapping_overflow; 625 goto out_mapping_overflow;
627 626
628 len = min_t(u32, PAGE_SIZE - page_base, remaining); 627 len = min_t(u32, PAGE_SIZE - page_base, remaining);
629 sge[sge_no].addr = ib_dma_map_page(device, *ppages, 628 sge[sge_no].addr =
630 page_base, len, 629 ib_dma_map_page(rdmab_device(rb), *ppages,
631 DMA_TO_DEVICE); 630 page_base, len, DMA_TO_DEVICE);
632 if (ib_dma_mapping_error(device, sge[sge_no].addr)) 631 if (ib_dma_mapping_error(rdmab_device(rb),
632 sge[sge_no].addr))
633 goto out_mapping_err; 633 goto out_mapping_err;
634 sge[sge_no].length = len; 634 sge[sge_no].length = len;
635 sge[sge_no].lkey = lkey; 635 sge[sge_no].lkey = rdmab_lkey(rb);
636 636
637 sc->sc_unmap_count++; 637 sc->sc_unmap_count++;
638 ppages++; 638 ppages++;
@@ -653,13 +653,13 @@ rpcrdma_prepare_msg_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
653 653
654map_tail: 654map_tail:
655 sge_no++; 655 sge_no++;
656 sge[sge_no].addr = ib_dma_map_page(device, page, 656 sge[sge_no].addr =
657 page_base, len, 657 ib_dma_map_page(rdmab_device(rb), page, page_base, len,
658 DMA_TO_DEVICE); 658 DMA_TO_DEVICE);
659 if (ib_dma_mapping_error(device, sge[sge_no].addr)) 659 if (ib_dma_mapping_error(rdmab_device(rb), sge[sge_no].addr))
660 goto out_mapping_err; 660 goto out_mapping_err;
661 sge[sge_no].length = len; 661 sge[sge_no].length = len;
662 sge[sge_no].lkey = lkey; 662 sge[sge_no].lkey = rdmab_lkey(rb);
663 sc->sc_unmap_count++; 663 sc->sc_unmap_count++;
664 } 664 }
665 665
@@ -674,12 +674,12 @@ out_regbuf:
674 return false; 674 return false;
675 675
676out_mapping_overflow: 676out_mapping_overflow:
677 rpcrdma_unmap_sendctx(sc); 677 rpcrdma_sendctx_unmap(sc);
678 pr_err("rpcrdma: too many Send SGEs (%u)\n", sge_no); 678 pr_err("rpcrdma: too many Send SGEs (%u)\n", sge_no);
679 return false; 679 return false;
680 680
681out_mapping_err: 681out_mapping_err:
682 rpcrdma_unmap_sendctx(sc); 682 rpcrdma_sendctx_unmap(sc);
683 trace_xprtrdma_dma_maperr(sge[sge_no].addr); 683 trace_xprtrdma_dma_maperr(sge[sge_no].addr);
684 return false; 684 return false;
685} 685}
@@ -699,7 +699,7 @@ rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,
699 struct rpcrdma_req *req, u32 hdrlen, 699 struct rpcrdma_req *req, u32 hdrlen,
700 struct xdr_buf *xdr, enum rpcrdma_chunktype rtype) 700 struct xdr_buf *xdr, enum rpcrdma_chunktype rtype)
701{ 701{
702 req->rl_sendctx = rpcrdma_sendctx_get_locked(&r_xprt->rx_buf); 702 req->rl_sendctx = rpcrdma_sendctx_get_locked(r_xprt);
703 if (!req->rl_sendctx) 703 if (!req->rl_sendctx)
704 return -EAGAIN; 704 return -EAGAIN;
705 req->rl_sendctx->sc_wr.num_sge = 0; 705 req->rl_sendctx->sc_wr.num_sge = 0;
@@ -707,11 +707,11 @@ rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,
707 req->rl_sendctx->sc_req = req; 707 req->rl_sendctx->sc_req = req;
708 __clear_bit(RPCRDMA_REQ_F_TX_RESOURCES, &req->rl_flags); 708 __clear_bit(RPCRDMA_REQ_F_TX_RESOURCES, &req->rl_flags);
709 709
710 if (!rpcrdma_prepare_hdr_sge(&r_xprt->rx_ia, req, hdrlen)) 710 if (!rpcrdma_prepare_hdr_sge(r_xprt, req, hdrlen))
711 return -EIO; 711 return -EIO;
712 712
713 if (rtype != rpcrdma_areadch) 713 if (rtype != rpcrdma_areadch)
714 if (!rpcrdma_prepare_msg_sges(&r_xprt->rx_ia, req, xdr, rtype)) 714 if (!rpcrdma_prepare_msg_sges(r_xprt, req, xdr, rtype))
715 return -EIO; 715 return -EIO;
716 716
717 return 0; 717 return 0;
@@ -747,8 +747,8 @@ rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst)
747 int ret; 747 int ret;
748 748
749 rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0); 749 rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0);
750 xdr_init_encode(xdr, &req->rl_hdrbuf, 750 xdr_init_encode(xdr, &req->rl_hdrbuf, rdmab_data(req->rl_rdmabuf),
751 req->rl_rdmabuf->rg_base, rqst); 751 rqst);
752 752
753 /* Fixed header fields */ 753 /* Fixed header fields */
754 ret = -EMSGSIZE; 754 ret = -EMSGSIZE;
@@ -876,6 +876,7 @@ rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst)
876 return 0; 876 return 0;
877 877
878out_err: 878out_err:
879 trace_xprtrdma_marshal_failed(rqst, ret);
879 switch (ret) { 880 switch (ret) {
880 case -EAGAIN: 881 case -EAGAIN:
881 xprt_wait_for_buffer_space(rqst->rq_xprt); 882 xprt_wait_for_buffer_space(rqst->rq_xprt);
diff --git a/net/sunrpc/xprtrdma/svc_rdma_backchannel.c b/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
index 907464c2a9f0..bed57d8b5c19 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
@@ -261,7 +261,7 @@ static const struct rpc_xprt_ops xprt_rdma_bc_procs = {
261 .buf_alloc = xprt_rdma_bc_allocate, 261 .buf_alloc = xprt_rdma_bc_allocate,
262 .buf_free = xprt_rdma_bc_free, 262 .buf_free = xprt_rdma_bc_free,
263 .send_request = xprt_rdma_bc_send_request, 263 .send_request = xprt_rdma_bc_send_request,
264 .set_retrans_timeout = xprt_set_retrans_timeout_def, 264 .wait_for_reply_request = xprt_wait_for_reply_request_def,
265 .close = xprt_rdma_bc_close, 265 .close = xprt_rdma_bc_close,
266 .destroy = xprt_rdma_bc_put, 266 .destroy = xprt_rdma_bc_put,
267 .print_stats = xprt_rdma_print_stats 267 .print_stats = xprt_rdma_print_stats
diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 5d261353bd90..1f73a6a7e43c 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -68,9 +68,9 @@
68 * tunables 68 * tunables
69 */ 69 */
70 70
71static unsigned int xprt_rdma_slot_table_entries = RPCRDMA_DEF_SLOT_TABLE; 71unsigned int xprt_rdma_slot_table_entries = RPCRDMA_DEF_SLOT_TABLE;
72unsigned int xprt_rdma_max_inline_read = RPCRDMA_DEF_INLINE; 72unsigned int xprt_rdma_max_inline_read = RPCRDMA_DEF_INLINE;
73static unsigned int xprt_rdma_max_inline_write = RPCRDMA_DEF_INLINE; 73unsigned int xprt_rdma_max_inline_write = RPCRDMA_DEF_INLINE;
74unsigned int xprt_rdma_memreg_strategy = RPCRDMA_FRWR; 74unsigned int xprt_rdma_memreg_strategy = RPCRDMA_FRWR;
75int xprt_rdma_pad_optimize; 75int xprt_rdma_pad_optimize;
76 76
@@ -288,7 +288,7 @@ xprt_rdma_destroy(struct rpc_xprt *xprt)
288 288
289 cancel_delayed_work_sync(&r_xprt->rx_connect_worker); 289 cancel_delayed_work_sync(&r_xprt->rx_connect_worker);
290 290
291 rpcrdma_ep_destroy(&r_xprt->rx_ep, &r_xprt->rx_ia); 291 rpcrdma_ep_destroy(r_xprt);
292 rpcrdma_buffer_destroy(&r_xprt->rx_buf); 292 rpcrdma_buffer_destroy(&r_xprt->rx_buf);
293 rpcrdma_ia_close(&r_xprt->rx_ia); 293 rpcrdma_ia_close(&r_xprt->rx_ia);
294 294
@@ -311,10 +311,8 @@ static const struct rpc_timeout xprt_rdma_default_timeout = {
311static struct rpc_xprt * 311static struct rpc_xprt *
312xprt_setup_rdma(struct xprt_create *args) 312xprt_setup_rdma(struct xprt_create *args)
313{ 313{
314 struct rpcrdma_create_data_internal cdata;
315 struct rpc_xprt *xprt; 314 struct rpc_xprt *xprt;
316 struct rpcrdma_xprt *new_xprt; 315 struct rpcrdma_xprt *new_xprt;
317 struct rpcrdma_ep *new_ep;
318 struct sockaddr *sap; 316 struct sockaddr *sap;
319 int rc; 317 int rc;
320 318
@@ -349,40 +347,12 @@ xprt_setup_rdma(struct xprt_create *args)
349 xprt_set_bound(xprt); 347 xprt_set_bound(xprt);
350 xprt_rdma_format_addresses(xprt, sap); 348 xprt_rdma_format_addresses(xprt, sap);
351 349
352 cdata.max_requests = xprt_rdma_slot_table_entries;
353
354 cdata.rsize = RPCRDMA_MAX_SEGS * PAGE_SIZE; /* RDMA write max */
355 cdata.wsize = RPCRDMA_MAX_SEGS * PAGE_SIZE; /* RDMA read max */
356
357 cdata.inline_wsize = xprt_rdma_max_inline_write;
358 if (cdata.inline_wsize > cdata.wsize)
359 cdata.inline_wsize = cdata.wsize;
360
361 cdata.inline_rsize = xprt_rdma_max_inline_read;
362 if (cdata.inline_rsize > cdata.rsize)
363 cdata.inline_rsize = cdata.rsize;
364
365 /*
366 * Create new transport instance, which includes initialized
367 * o ia
368 * o endpoint
369 * o buffers
370 */
371
372 new_xprt = rpcx_to_rdmax(xprt); 350 new_xprt = rpcx_to_rdmax(xprt);
373
374 rc = rpcrdma_ia_open(new_xprt); 351 rc = rpcrdma_ia_open(new_xprt);
375 if (rc) 352 if (rc)
376 goto out1; 353 goto out1;
377 354
378 /* 355 rc = rpcrdma_ep_create(new_xprt);
379 * initialize and create ep
380 */
381 new_xprt->rx_data = cdata;
382 new_ep = &new_xprt->rx_ep;
383
384 rc = rpcrdma_ep_create(&new_xprt->rx_ep,
385 &new_xprt->rx_ia, &new_xprt->rx_data);
386 if (rc) 356 if (rc)
387 goto out2; 357 goto out2;
388 358
@@ -413,7 +383,7 @@ out4:
413 rpcrdma_buffer_destroy(&new_xprt->rx_buf); 383 rpcrdma_buffer_destroy(&new_xprt->rx_buf);
414 rc = -ENODEV; 384 rc = -ENODEV;
415out3: 385out3:
416 rpcrdma_ep_destroy(new_ep, &new_xprt->rx_ia); 386 rpcrdma_ep_destroy(new_xprt);
417out2: 387out2:
418 rpcrdma_ia_close(&new_xprt->rx_ia); 388 rpcrdma_ia_close(&new_xprt->rx_ia);
419out1: 389out1:
@@ -585,52 +555,15 @@ xprt_rdma_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *rqst)
585 rpc_wake_up_next(&xprt->backlog); 555 rpc_wake_up_next(&xprt->backlog);
586} 556}
587 557
588static bool 558static bool rpcrdma_check_regbuf(struct rpcrdma_xprt *r_xprt,
589rpcrdma_get_sendbuf(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req, 559 struct rpcrdma_regbuf *rb, size_t size,
590 size_t size, gfp_t flags) 560 gfp_t flags)
591{ 561{
592 struct rpcrdma_regbuf *rb; 562 if (unlikely(rdmab_length(rb) < size)) {
593 563 if (!rpcrdma_regbuf_realloc(rb, size, flags))
594 if (req->rl_sendbuf && rdmab_length(req->rl_sendbuf) >= size) 564 return false;
595 return true; 565 r_xprt->rx_stats.hardway_register_count += size;
596 566 }
597 rb = rpcrdma_alloc_regbuf(size, DMA_TO_DEVICE, flags);
598 if (IS_ERR(rb))
599 return false;
600
601 rpcrdma_free_regbuf(req->rl_sendbuf);
602 r_xprt->rx_stats.hardway_register_count += size;
603 req->rl_sendbuf = rb;
604 return true;
605}
606
607/* The rq_rcv_buf is used only if a Reply chunk is necessary.
608 * The decision to use a Reply chunk is made later in
609 * rpcrdma_marshal_req. This buffer is registered at that time.
610 *
611 * Otherwise, the associated RPC Reply arrives in a separate
612 * Receive buffer, arbitrarily chosen by the HCA. The buffer
613 * allocated here for the RPC Reply is not utilized in that
614 * case. See rpcrdma_inline_fixup.
615 *
616 * A regbuf is used here to remember the buffer size.
617 */
618static bool
619rpcrdma_get_recvbuf(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
620 size_t size, gfp_t flags)
621{
622 struct rpcrdma_regbuf *rb;
623
624 if (req->rl_recvbuf && rdmab_length(req->rl_recvbuf) >= size)
625 return true;
626
627 rb = rpcrdma_alloc_regbuf(size, DMA_NONE, flags);
628 if (IS_ERR(rb))
629 return false;
630
631 rpcrdma_free_regbuf(req->rl_recvbuf);
632 r_xprt->rx_stats.hardway_register_count += size;
633 req->rl_recvbuf = rb;
634 return true; 567 return true;
635} 568}
636 569
@@ -655,13 +588,15 @@ xprt_rdma_allocate(struct rpc_task *task)
655 if (RPC_IS_SWAPPER(task)) 588 if (RPC_IS_SWAPPER(task))
656 flags = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN; 589 flags = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN;
657 590
658 if (!rpcrdma_get_sendbuf(r_xprt, req, rqst->rq_callsize, flags)) 591 if (!rpcrdma_check_regbuf(r_xprt, req->rl_sendbuf, rqst->rq_callsize,
592 flags))
659 goto out_fail; 593 goto out_fail;
660 if (!rpcrdma_get_recvbuf(r_xprt, req, rqst->rq_rcvsize, flags)) 594 if (!rpcrdma_check_regbuf(r_xprt, req->rl_recvbuf, rqst->rq_rcvsize,
595 flags))
661 goto out_fail; 596 goto out_fail;
662 597
663 rqst->rq_buffer = req->rl_sendbuf->rg_base; 598 rqst->rq_buffer = rdmab_data(req->rl_sendbuf);
664 rqst->rq_rbuffer = req->rl_recvbuf->rg_base; 599 rqst->rq_rbuffer = rdmab_data(req->rl_recvbuf);
665 trace_xprtrdma_op_allocate(task, req); 600 trace_xprtrdma_op_allocate(task, req);
666 return 0; 601 return 0;
667 602
@@ -815,7 +750,7 @@ static const struct rpc_xprt_ops xprt_rdma_procs = {
815 .alloc_slot = xprt_rdma_alloc_slot, 750 .alloc_slot = xprt_rdma_alloc_slot,
816 .free_slot = xprt_rdma_free_slot, 751 .free_slot = xprt_rdma_free_slot,
817 .release_request = xprt_release_rqst_cong, /* ditto */ 752 .release_request = xprt_release_rqst_cong, /* ditto */
818 .set_retrans_timeout = xprt_set_retrans_timeout_def, /* ditto */ 753 .wait_for_reply_request = xprt_wait_for_reply_request_def, /* ditto */
819 .timer = xprt_rdma_timer, 754 .timer = xprt_rdma_timer,
820 .rpcbind = rpcb_getport_async, /* sunrpc/rpcb_clnt.c */ 755 .rpcbind = rpcb_getport_async, /* sunrpc/rpcb_clnt.c */
821 .set_port = xprt_rdma_set_port, 756 .set_port = xprt_rdma_set_port,
diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
index 30cfc0efe699..bef5eac8ab38 100644
--- a/net/sunrpc/xprtrdma/verbs.c
+++ b/net/sunrpc/xprtrdma/verbs.c
@@ -76,11 +76,16 @@
76static void rpcrdma_sendctx_put_locked(struct rpcrdma_sendctx *sc); 76static void rpcrdma_sendctx_put_locked(struct rpcrdma_sendctx *sc);
77static void rpcrdma_mrs_create(struct rpcrdma_xprt *r_xprt); 77static void rpcrdma_mrs_create(struct rpcrdma_xprt *r_xprt);
78static void rpcrdma_mrs_destroy(struct rpcrdma_buffer *buf); 78static void rpcrdma_mrs_destroy(struct rpcrdma_buffer *buf);
79static int rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt, bool temp); 79static struct rpcrdma_regbuf *
80static void rpcrdma_dma_unmap_regbuf(struct rpcrdma_regbuf *rb); 80rpcrdma_regbuf_alloc(size_t size, enum dma_data_direction direction,
81 gfp_t flags);
82static void rpcrdma_regbuf_dma_unmap(struct rpcrdma_regbuf *rb);
83static void rpcrdma_regbuf_free(struct rpcrdma_regbuf *rb);
81static void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp); 84static void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp);
82 85
83/* Wait for outstanding transport work to finish. 86/* Wait for outstanding transport work to finish. ib_drain_qp
87 * handles the drains in the wrong order for us, so open code
88 * them here.
84 */ 89 */
85static void rpcrdma_xprt_drain(struct rpcrdma_xprt *r_xprt) 90static void rpcrdma_xprt_drain(struct rpcrdma_xprt *r_xprt)
86{ 91{
@@ -132,11 +137,6 @@ rpcrdma_wc_send(struct ib_cq *cq, struct ib_wc *wc)
132 137
133 /* WARNING: Only wr_cqe and status are reliable at this point */ 138 /* WARNING: Only wr_cqe and status are reliable at this point */
134 trace_xprtrdma_wc_send(sc, wc); 139 trace_xprtrdma_wc_send(sc, wc);
135 if (wc->status != IB_WC_SUCCESS && wc->status != IB_WC_WR_FLUSH_ERR)
136 pr_err("rpcrdma: Send: %s (%u/0x%x)\n",
137 ib_wc_status_msg(wc->status),
138 wc->status, wc->vendor_err);
139
140 rpcrdma_sendctx_put_locked(sc); 140 rpcrdma_sendctx_put_locked(sc);
141} 141}
142 142
@@ -174,10 +174,6 @@ rpcrdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc)
174 return; 174 return;
175 175
176out_flushed: 176out_flushed:
177 if (wc->status != IB_WC_WR_FLUSH_ERR)
178 pr_err("rpcrdma: Recv: %s (%u/0x%x)\n",
179 ib_wc_status_msg(wc->status),
180 wc->status, wc->vendor_err);
181 rpcrdma_recv_buffer_put(rep); 177 rpcrdma_recv_buffer_put(rep);
182} 178}
183 179
@@ -185,7 +181,6 @@ static void
185rpcrdma_update_connect_private(struct rpcrdma_xprt *r_xprt, 181rpcrdma_update_connect_private(struct rpcrdma_xprt *r_xprt,
186 struct rdma_conn_param *param) 182 struct rdma_conn_param *param)
187{ 183{
188 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
189 const struct rpcrdma_connect_private *pmsg = param->private_data; 184 const struct rpcrdma_connect_private *pmsg = param->private_data;
190 unsigned int rsize, wsize; 185 unsigned int rsize, wsize;
191 186
@@ -202,12 +197,13 @@ rpcrdma_update_connect_private(struct rpcrdma_xprt *r_xprt,
202 wsize = rpcrdma_decode_buffer_size(pmsg->cp_recv_size); 197 wsize = rpcrdma_decode_buffer_size(pmsg->cp_recv_size);
203 } 198 }
204 199
205 if (rsize < cdata->inline_rsize) 200 if (rsize < r_xprt->rx_ep.rep_inline_recv)
206 cdata->inline_rsize = rsize; 201 r_xprt->rx_ep.rep_inline_recv = rsize;
207 if (wsize < cdata->inline_wsize) 202 if (wsize < r_xprt->rx_ep.rep_inline_send)
208 cdata->inline_wsize = wsize; 203 r_xprt->rx_ep.rep_inline_send = wsize;
209 dprintk("RPC: %s: max send %u, max recv %u\n", 204 dprintk("RPC: %s: max send %u, max recv %u\n", __func__,
210 __func__, cdata->inline_wsize, cdata->inline_rsize); 205 r_xprt->rx_ep.rep_inline_send,
206 r_xprt->rx_ep.rep_inline_recv);
211 rpcrdma_set_max_header_sizes(r_xprt); 207 rpcrdma_set_max_header_sizes(r_xprt);
212} 208}
213 209
@@ -247,7 +243,7 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
247 case RDMA_CM_EVENT_DEVICE_REMOVAL: 243 case RDMA_CM_EVENT_DEVICE_REMOVAL:
248#if IS_ENABLED(CONFIG_SUNRPC_DEBUG) 244#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
249 pr_info("rpcrdma: removing device %s for %s:%s\n", 245 pr_info("rpcrdma: removing device %s for %s:%s\n",
250 ia->ri_device->name, 246 ia->ri_id->device->name,
251 rpcrdma_addrstr(r_xprt), rpcrdma_portstr(r_xprt)); 247 rpcrdma_addrstr(r_xprt), rpcrdma_portstr(r_xprt));
252#endif 248#endif
253 set_bit(RPCRDMA_IAF_REMOVING, &ia->ri_flags); 249 set_bit(RPCRDMA_IAF_REMOVING, &ia->ri_flags);
@@ -256,7 +252,6 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
256 wait_for_completion(&ia->ri_remove_done); 252 wait_for_completion(&ia->ri_remove_done);
257 253
258 ia->ri_id = NULL; 254 ia->ri_id = NULL;
259 ia->ri_device = NULL;
260 /* Return 1 to ensure the core destroys the id. */ 255 /* Return 1 to ensure the core destroys the id. */
261 return 1; 256 return 1;
262 case RDMA_CM_EVENT_ESTABLISHED: 257 case RDMA_CM_EVENT_ESTABLISHED:
@@ -291,7 +286,7 @@ disconnected:
291 286
292 dprintk("RPC: %s: %s:%s on %s/frwr: %s\n", __func__, 287 dprintk("RPC: %s: %s:%s on %s/frwr: %s\n", __func__,
293 rpcrdma_addrstr(r_xprt), rpcrdma_portstr(r_xprt), 288 rpcrdma_addrstr(r_xprt), rpcrdma_portstr(r_xprt),
294 ia->ri_device->name, rdma_event_msg(event->event)); 289 ia->ri_id->device->name, rdma_event_msg(event->event));
295 return 0; 290 return 0;
296} 291}
297 292
@@ -370,9 +365,8 @@ rpcrdma_ia_open(struct rpcrdma_xprt *xprt)
370 rc = PTR_ERR(ia->ri_id); 365 rc = PTR_ERR(ia->ri_id);
371 goto out_err; 366 goto out_err;
372 } 367 }
373 ia->ri_device = ia->ri_id->device;
374 368
375 ia->ri_pd = ib_alloc_pd(ia->ri_device, 0); 369 ia->ri_pd = ib_alloc_pd(ia->ri_id->device, 0);
376 if (IS_ERR(ia->ri_pd)) { 370 if (IS_ERR(ia->ri_pd)) {
377 rc = PTR_ERR(ia->ri_pd); 371 rc = PTR_ERR(ia->ri_pd);
378 pr_err("rpcrdma: ib_alloc_pd() returned %d\n", rc); 372 pr_err("rpcrdma: ib_alloc_pd() returned %d\n", rc);
@@ -381,12 +375,12 @@ rpcrdma_ia_open(struct rpcrdma_xprt *xprt)
381 375
382 switch (xprt_rdma_memreg_strategy) { 376 switch (xprt_rdma_memreg_strategy) {
383 case RPCRDMA_FRWR: 377 case RPCRDMA_FRWR:
384 if (frwr_is_supported(ia)) 378 if (frwr_is_supported(ia->ri_id->device))
385 break; 379 break;
386 /*FALLTHROUGH*/ 380 /*FALLTHROUGH*/
387 default: 381 default:
388 pr_err("rpcrdma: Device %s does not support memreg mode %d\n", 382 pr_err("rpcrdma: Device %s does not support memreg mode %d\n",
389 ia->ri_device->name, xprt_rdma_memreg_strategy); 383 ia->ri_id->device->name, xprt_rdma_memreg_strategy);
390 rc = -EINVAL; 384 rc = -EINVAL;
391 goto out_err; 385 goto out_err;
392 } 386 }
@@ -438,11 +432,11 @@ rpcrdma_ia_remove(struct rpcrdma_ia *ia)
438 * mappings and MRs are gone. 432 * mappings and MRs are gone.
439 */ 433 */
440 list_for_each_entry(rep, &buf->rb_recv_bufs, rr_list) 434 list_for_each_entry(rep, &buf->rb_recv_bufs, rr_list)
441 rpcrdma_dma_unmap_regbuf(rep->rr_rdmabuf); 435 rpcrdma_regbuf_dma_unmap(rep->rr_rdmabuf);
442 list_for_each_entry(req, &buf->rb_allreqs, rl_all) { 436 list_for_each_entry(req, &buf->rb_allreqs, rl_all) {
443 rpcrdma_dma_unmap_regbuf(req->rl_rdmabuf); 437 rpcrdma_regbuf_dma_unmap(req->rl_rdmabuf);
444 rpcrdma_dma_unmap_regbuf(req->rl_sendbuf); 438 rpcrdma_regbuf_dma_unmap(req->rl_sendbuf);
445 rpcrdma_dma_unmap_regbuf(req->rl_recvbuf); 439 rpcrdma_regbuf_dma_unmap(req->rl_recvbuf);
446 } 440 }
447 rpcrdma_mrs_destroy(buf); 441 rpcrdma_mrs_destroy(buf);
448 ib_dealloc_pd(ia->ri_pd); 442 ib_dealloc_pd(ia->ri_pd);
@@ -468,7 +462,6 @@ rpcrdma_ia_close(struct rpcrdma_ia *ia)
468 rdma_destroy_id(ia->ri_id); 462 rdma_destroy_id(ia->ri_id);
469 } 463 }
470 ia->ri_id = NULL; 464 ia->ri_id = NULL;
471 ia->ri_device = NULL;
472 465
473 /* If the pd is still busy, xprtrdma missed freeing a resource */ 466 /* If the pd is still busy, xprtrdma missed freeing a resource */
474 if (ia->ri_pd && !IS_ERR(ia->ri_pd)) 467 if (ia->ri_pd && !IS_ERR(ia->ri_pd))
@@ -476,19 +469,26 @@ rpcrdma_ia_close(struct rpcrdma_ia *ia)
476 ia->ri_pd = NULL; 469 ia->ri_pd = NULL;
477} 470}
478 471
479/* 472/**
480 * Create unconnected endpoint. 473 * rpcrdma_ep_create - Create unconnected endpoint
474 * @r_xprt: transport to instantiate
475 *
476 * Returns zero on success, or a negative errno.
481 */ 477 */
482int 478int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt)
483rpcrdma_ep_create(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia,
484 struct rpcrdma_create_data_internal *cdata)
485{ 479{
480 struct rpcrdma_ep *ep = &r_xprt->rx_ep;
481 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
486 struct rpcrdma_connect_private *pmsg = &ep->rep_cm_private; 482 struct rpcrdma_connect_private *pmsg = &ep->rep_cm_private;
487 struct ib_cq *sendcq, *recvcq; 483 struct ib_cq *sendcq, *recvcq;
488 unsigned int max_sge; 484 unsigned int max_sge;
489 int rc; 485 int rc;
490 486
491 max_sge = min_t(unsigned int, ia->ri_device->attrs.max_send_sge, 487 ep->rep_max_requests = xprt_rdma_slot_table_entries;
488 ep->rep_inline_send = xprt_rdma_max_inline_write;
489 ep->rep_inline_recv = xprt_rdma_max_inline_read;
490
491 max_sge = min_t(unsigned int, ia->ri_id->device->attrs.max_send_sge,
492 RPCRDMA_MAX_SEND_SGES); 492 RPCRDMA_MAX_SEND_SGES);
493 if (max_sge < RPCRDMA_MIN_SEND_SGES) { 493 if (max_sge < RPCRDMA_MIN_SEND_SGES) {
494 pr_warn("rpcrdma: HCA provides only %d send SGEs\n", max_sge); 494 pr_warn("rpcrdma: HCA provides only %d send SGEs\n", max_sge);
@@ -496,7 +496,7 @@ rpcrdma_ep_create(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia,
496 } 496 }
497 ia->ri_max_send_sges = max_sge; 497 ia->ri_max_send_sges = max_sge;
498 498
499 rc = frwr_open(ia, ep, cdata); 499 rc = frwr_open(ia, ep);
500 if (rc) 500 if (rc)
501 return rc; 501 return rc;
502 502
@@ -518,23 +518,21 @@ rpcrdma_ep_create(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia,
518 ep->rep_attr.cap.max_send_sge, 518 ep->rep_attr.cap.max_send_sge,
519 ep->rep_attr.cap.max_recv_sge); 519 ep->rep_attr.cap.max_recv_sge);
520 520
521 /* set trigger for requesting send completion */ 521 ep->rep_send_batch = ep->rep_max_requests >> 3;
522 ep->rep_send_batch = min_t(unsigned int, RPCRDMA_MAX_SEND_BATCH,
523 cdata->max_requests >> 2);
524 ep->rep_send_count = ep->rep_send_batch; 522 ep->rep_send_count = ep->rep_send_batch;
525 init_waitqueue_head(&ep->rep_connect_wait); 523 init_waitqueue_head(&ep->rep_connect_wait);
526 ep->rep_receive_count = 0; 524 ep->rep_receive_count = 0;
527 525
528 sendcq = ib_alloc_cq(ia->ri_device, NULL, 526 sendcq = ib_alloc_cq(ia->ri_id->device, NULL,
529 ep->rep_attr.cap.max_send_wr + 1, 527 ep->rep_attr.cap.max_send_wr + 1,
530 ia->ri_device->num_comp_vectors > 1 ? 1 : 0, 528 ia->ri_id->device->num_comp_vectors > 1 ? 1 : 0,
531 IB_POLL_WORKQUEUE); 529 IB_POLL_WORKQUEUE);
532 if (IS_ERR(sendcq)) { 530 if (IS_ERR(sendcq)) {
533 rc = PTR_ERR(sendcq); 531 rc = PTR_ERR(sendcq);
534 goto out1; 532 goto out1;
535 } 533 }
536 534
537 recvcq = ib_alloc_cq(ia->ri_device, NULL, 535 recvcq = ib_alloc_cq(ia->ri_id->device, NULL,
538 ep->rep_attr.cap.max_recv_wr + 1, 536 ep->rep_attr.cap.max_recv_wr + 1,
539 0, IB_POLL_WORKQUEUE); 537 0, IB_POLL_WORKQUEUE);
540 if (IS_ERR(recvcq)) { 538 if (IS_ERR(recvcq)) {
@@ -552,15 +550,15 @@ rpcrdma_ep_create(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia,
552 pmsg->cp_magic = rpcrdma_cmp_magic; 550 pmsg->cp_magic = rpcrdma_cmp_magic;
553 pmsg->cp_version = RPCRDMA_CMP_VERSION; 551 pmsg->cp_version = RPCRDMA_CMP_VERSION;
554 pmsg->cp_flags |= RPCRDMA_CMP_F_SND_W_INV_OK; 552 pmsg->cp_flags |= RPCRDMA_CMP_F_SND_W_INV_OK;
555 pmsg->cp_send_size = rpcrdma_encode_buffer_size(cdata->inline_wsize); 553 pmsg->cp_send_size = rpcrdma_encode_buffer_size(ep->rep_inline_send);
556 pmsg->cp_recv_size = rpcrdma_encode_buffer_size(cdata->inline_rsize); 554 pmsg->cp_recv_size = rpcrdma_encode_buffer_size(ep->rep_inline_recv);
557 ep->rep_remote_cma.private_data = pmsg; 555 ep->rep_remote_cma.private_data = pmsg;
558 ep->rep_remote_cma.private_data_len = sizeof(*pmsg); 556 ep->rep_remote_cma.private_data_len = sizeof(*pmsg);
559 557
560 /* Client offers RDMA Read but does not initiate */ 558 /* Client offers RDMA Read but does not initiate */
561 ep->rep_remote_cma.initiator_depth = 0; 559 ep->rep_remote_cma.initiator_depth = 0;
562 ep->rep_remote_cma.responder_resources = 560 ep->rep_remote_cma.responder_resources =
563 min_t(int, U8_MAX, ia->ri_device->attrs.max_qp_rd_atom); 561 min_t(int, U8_MAX, ia->ri_id->device->attrs.max_qp_rd_atom);
564 562
565 /* Limit transport retries so client can detect server 563 /* Limit transport retries so client can detect server
566 * GID changes quickly. RPC layer handles re-establishing 564 * GID changes quickly. RPC layer handles re-establishing
@@ -583,16 +581,16 @@ out1:
583 return rc; 581 return rc;
584} 582}
585 583
586/* 584/**
587 * rpcrdma_ep_destroy 585 * rpcrdma_ep_destroy - Disconnect and destroy endpoint.
586 * @r_xprt: transport instance to shut down
588 * 587 *
589 * Disconnect and destroy endpoint. After this, the only
590 * valid operations on the ep are to free it (if dynamically
591 * allocated) or re-create it.
592 */ 588 */
593void 589void rpcrdma_ep_destroy(struct rpcrdma_xprt *r_xprt)
594rpcrdma_ep_destroy(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
595{ 590{
591 struct rpcrdma_ep *ep = &r_xprt->rx_ep;
592 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
593
596 if (ia->ri_id && ia->ri_id->qp) { 594 if (ia->ri_id && ia->ri_id->qp) {
597 rpcrdma_ep_disconnect(ep, ia); 595 rpcrdma_ep_disconnect(ep, ia);
598 rdma_destroy_qp(ia->ri_id); 596 rdma_destroy_qp(ia->ri_id);
@@ -622,7 +620,7 @@ rpcrdma_ep_recreate_xprt(struct rpcrdma_xprt *r_xprt,
622 goto out1; 620 goto out1;
623 621
624 rc = -ENOMEM; 622 rc = -ENOMEM;
625 err = rpcrdma_ep_create(ep, ia, &r_xprt->rx_data); 623 err = rpcrdma_ep_create(r_xprt);
626 if (err) { 624 if (err) {
627 pr_err("rpcrdma: rpcrdma_ep_create returned %d\n", err); 625 pr_err("rpcrdma: rpcrdma_ep_create returned %d\n", err);
628 goto out2; 626 goto out2;
@@ -639,7 +637,7 @@ rpcrdma_ep_recreate_xprt(struct rpcrdma_xprt *r_xprt,
639 return 0; 637 return 0;
640 638
641out3: 639out3:
642 rpcrdma_ep_destroy(ep, ia); 640 rpcrdma_ep_destroy(r_xprt);
643out2: 641out2:
644 rpcrdma_ia_close(ia); 642 rpcrdma_ia_close(ia);
645out1: 643out1:
@@ -672,7 +670,7 @@ rpcrdma_ep_reconnect(struct rpcrdma_xprt *r_xprt, struct rpcrdma_ep *ep,
672 */ 670 */
673 old = id; 671 old = id;
674 rc = -ENETUNREACH; 672 rc = -ENETUNREACH;
675 if (ia->ri_device != id->device) { 673 if (ia->ri_id->device != id->device) {
676 pr_err("rpcrdma: can't reconnect on different device!\n"); 674 pr_err("rpcrdma: can't reconnect on different device!\n");
677 goto out_destroy; 675 goto out_destroy;
678 } 676 }
@@ -796,8 +794,8 @@ rpcrdma_ep_disconnect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
796 */ 794 */
797 795
798/* rpcrdma_sendctxs_destroy() assumes caller has already quiesced 796/* rpcrdma_sendctxs_destroy() assumes caller has already quiesced
799 * queue activity, and ib_drain_qp has flushed all remaining Send 797 * queue activity, and rpcrdma_xprt_drain has flushed all remaining
800 * requests. 798 * Send requests.
801 */ 799 */
802static void rpcrdma_sendctxs_destroy(struct rpcrdma_buffer *buf) 800static void rpcrdma_sendctxs_destroy(struct rpcrdma_buffer *buf)
803{ 801{
@@ -867,20 +865,20 @@ static unsigned long rpcrdma_sendctx_next(struct rpcrdma_buffer *buf,
867 865
868/** 866/**
869 * rpcrdma_sendctx_get_locked - Acquire a send context 867 * rpcrdma_sendctx_get_locked - Acquire a send context
870 * @buf: transport buffers from which to acquire an unused context 868 * @r_xprt: controlling transport instance
871 * 869 *
872 * Returns pointer to a free send completion context; or NULL if 870 * Returns pointer to a free send completion context; or NULL if
873 * the queue is empty. 871 * the queue is empty.
874 * 872 *
875 * Usage: Called to acquire an SGE array before preparing a Send WR. 873 * Usage: Called to acquire an SGE array before preparing a Send WR.
876 * 874 *
877 * The caller serializes calls to this function (per rpcrdma_buffer), 875 * The caller serializes calls to this function (per transport), and
878 * and provides an effective memory barrier that flushes the new value 876 * provides an effective memory barrier that flushes the new value
879 * of rb_sc_head. 877 * of rb_sc_head.
880 */ 878 */
881struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked(struct rpcrdma_buffer *buf) 879struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked(struct rpcrdma_xprt *r_xprt)
882{ 880{
883 struct rpcrdma_xprt *r_xprt; 881 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
884 struct rpcrdma_sendctx *sc; 882 struct rpcrdma_sendctx *sc;
885 unsigned long next_head; 883 unsigned long next_head;
886 884
@@ -905,7 +903,6 @@ out_emptyq:
905 * backing up. Cause the caller to pause and try again. 903 * backing up. Cause the caller to pause and try again.
906 */ 904 */
907 set_bit(RPCRDMA_BUF_F_EMPTY_SCQ, &buf->rb_flags); 905 set_bit(RPCRDMA_BUF_F_EMPTY_SCQ, &buf->rb_flags);
908 r_xprt = container_of(buf, struct rpcrdma_xprt, rx_buf);
909 r_xprt->rx_stats.empty_sendctx_q++; 906 r_xprt->rx_stats.empty_sendctx_q++;
910 return NULL; 907 return NULL;
911} 908}
@@ -917,7 +914,7 @@ out_emptyq:
917 * Usage: Called from Send completion to return a sendctxt 914 * Usage: Called from Send completion to return a sendctxt
918 * to the queue. 915 * to the queue.
919 * 916 *
920 * The caller serializes calls to this function (per rpcrdma_buffer). 917 * The caller serializes calls to this function (per transport).
921 */ 918 */
922static void 919static void
923rpcrdma_sendctx_put_locked(struct rpcrdma_sendctx *sc) 920rpcrdma_sendctx_put_locked(struct rpcrdma_sendctx *sc)
@@ -925,7 +922,7 @@ rpcrdma_sendctx_put_locked(struct rpcrdma_sendctx *sc)
925 struct rpcrdma_buffer *buf = &sc->sc_xprt->rx_buf; 922 struct rpcrdma_buffer *buf = &sc->sc_xprt->rx_buf;
926 unsigned long next_tail; 923 unsigned long next_tail;
927 924
928 /* Unmap SGEs of previously completed by unsignaled 925 /* Unmap SGEs of previously completed but unsignaled
929 * Sends by walking up the queue until @sc is found. 926 * Sends by walking up the queue until @sc is found.
930 */ 927 */
931 next_tail = buf->rb_sc_tail; 928 next_tail = buf->rb_sc_tail;
@@ -933,7 +930,7 @@ rpcrdma_sendctx_put_locked(struct rpcrdma_sendctx *sc)
933 next_tail = rpcrdma_sendctx_next(buf, next_tail); 930 next_tail = rpcrdma_sendctx_next(buf, next_tail);
934 931
935 /* ORDER: item must be accessed _before_ tail is updated */ 932 /* ORDER: item must be accessed _before_ tail is updated */
936 rpcrdma_unmap_sendctx(buf->rb_sc_ctxs[next_tail]); 933 rpcrdma_sendctx_unmap(buf->rb_sc_ctxs[next_tail]);
937 934
938 } while (buf->rb_sc_ctxs[next_tail] != sc); 935 } while (buf->rb_sc_ctxs[next_tail] != sc);
939 936
@@ -996,54 +993,70 @@ rpcrdma_mr_refresh_worker(struct work_struct *work)
996 rpcrdma_mrs_create(r_xprt); 993 rpcrdma_mrs_create(r_xprt);
997} 994}
998 995
999struct rpcrdma_req * 996/**
1000rpcrdma_create_req(struct rpcrdma_xprt *r_xprt) 997 * rpcrdma_req_create - Allocate an rpcrdma_req object
998 * @r_xprt: controlling r_xprt
999 * @size: initial size, in bytes, of send and receive buffers
1000 * @flags: GFP flags passed to memory allocators
1001 *
1002 * Returns an allocated and fully initialized rpcrdma_req or NULL.
1003 */
1004struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size,
1005 gfp_t flags)
1001{ 1006{
1002 struct rpcrdma_buffer *buffer = &r_xprt->rx_buf; 1007 struct rpcrdma_buffer *buffer = &r_xprt->rx_buf;
1003 struct rpcrdma_regbuf *rb; 1008 struct rpcrdma_regbuf *rb;
1004 struct rpcrdma_req *req; 1009 struct rpcrdma_req *req;
1005 1010
1006 req = kzalloc(sizeof(*req), GFP_KERNEL); 1011 req = kzalloc(sizeof(*req), flags);
1007 if (req == NULL) 1012 if (req == NULL)
1008 return ERR_PTR(-ENOMEM); 1013 goto out1;
1009 1014
1010 rb = rpcrdma_alloc_regbuf(RPCRDMA_HDRBUF_SIZE, 1015 rb = rpcrdma_regbuf_alloc(RPCRDMA_HDRBUF_SIZE, DMA_TO_DEVICE, flags);
1011 DMA_TO_DEVICE, GFP_KERNEL); 1016 if (!rb)
1012 if (IS_ERR(rb)) { 1017 goto out2;
1013 kfree(req);
1014 return ERR_PTR(-ENOMEM);
1015 }
1016 req->rl_rdmabuf = rb; 1018 req->rl_rdmabuf = rb;
1017 xdr_buf_init(&req->rl_hdrbuf, rb->rg_base, rdmab_length(rb)); 1019 xdr_buf_init(&req->rl_hdrbuf, rdmab_data(rb), rdmab_length(rb));
1020
1021 req->rl_sendbuf = rpcrdma_regbuf_alloc(size, DMA_TO_DEVICE, flags);
1022 if (!req->rl_sendbuf)
1023 goto out3;
1024
1025 req->rl_recvbuf = rpcrdma_regbuf_alloc(size, DMA_NONE, flags);
1026 if (!req->rl_recvbuf)
1027 goto out4;
1028
1018 req->rl_buffer = buffer; 1029 req->rl_buffer = buffer;
1019 INIT_LIST_HEAD(&req->rl_registered); 1030 INIT_LIST_HEAD(&req->rl_registered);
1020
1021 spin_lock(&buffer->rb_lock); 1031 spin_lock(&buffer->rb_lock);
1022 list_add(&req->rl_all, &buffer->rb_allreqs); 1032 list_add(&req->rl_all, &buffer->rb_allreqs);
1023 spin_unlock(&buffer->rb_lock); 1033 spin_unlock(&buffer->rb_lock);
1024 return req; 1034 return req;
1035
1036out4:
1037 kfree(req->rl_sendbuf);
1038out3:
1039 kfree(req->rl_rdmabuf);
1040out2:
1041 kfree(req);
1042out1:
1043 return NULL;
1025} 1044}
1026 1045
1027static int 1046static bool rpcrdma_rep_create(struct rpcrdma_xprt *r_xprt, bool temp)
1028rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt, bool temp)
1029{ 1047{
1030 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
1031 struct rpcrdma_buffer *buf = &r_xprt->rx_buf; 1048 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
1032 struct rpcrdma_rep *rep; 1049 struct rpcrdma_rep *rep;
1033 int rc;
1034 1050
1035 rc = -ENOMEM;
1036 rep = kzalloc(sizeof(*rep), GFP_KERNEL); 1051 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
1037 if (rep == NULL) 1052 if (rep == NULL)
1038 goto out; 1053 goto out;
1039 1054
1040 rep->rr_rdmabuf = rpcrdma_alloc_regbuf(cdata->inline_rsize, 1055 rep->rr_rdmabuf = rpcrdma_regbuf_alloc(r_xprt->rx_ep.rep_inline_recv,
1041 DMA_FROM_DEVICE, GFP_KERNEL); 1056 DMA_FROM_DEVICE, GFP_KERNEL);
1042 if (IS_ERR(rep->rr_rdmabuf)) { 1057 if (!rep->rr_rdmabuf)
1043 rc = PTR_ERR(rep->rr_rdmabuf);
1044 goto out_free; 1058 goto out_free;
1045 } 1059 xdr_buf_init(&rep->rr_hdrbuf, rdmab_data(rep->rr_rdmabuf),
1046 xdr_buf_init(&rep->rr_hdrbuf, rep->rr_rdmabuf->rg_base,
1047 rdmab_length(rep->rr_rdmabuf)); 1060 rdmab_length(rep->rr_rdmabuf));
1048 1061
1049 rep->rr_cqe.done = rpcrdma_wc_receive; 1062 rep->rr_cqe.done = rpcrdma_wc_receive;
@@ -1058,22 +1071,27 @@ rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt, bool temp)
1058 spin_lock(&buf->rb_lock); 1071 spin_lock(&buf->rb_lock);
1059 list_add(&rep->rr_list, &buf->rb_recv_bufs); 1072 list_add(&rep->rr_list, &buf->rb_recv_bufs);
1060 spin_unlock(&buf->rb_lock); 1073 spin_unlock(&buf->rb_lock);
1061 return 0; 1074 return true;
1062 1075
1063out_free: 1076out_free:
1064 kfree(rep); 1077 kfree(rep);
1065out: 1078out:
1066 return rc; 1079 return false;
1067} 1080}
1068 1081
1069int 1082/**
1070rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt) 1083 * rpcrdma_buffer_create - Create initial set of req/rep objects
1084 * @r_xprt: transport instance to (re)initialize
1085 *
1086 * Returns zero on success, otherwise a negative errno.
1087 */
1088int rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
1071{ 1089{
1072 struct rpcrdma_buffer *buf = &r_xprt->rx_buf; 1090 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
1073 int i, rc; 1091 int i, rc;
1074 1092
1075 buf->rb_flags = 0; 1093 buf->rb_flags = 0;
1076 buf->rb_max_requests = r_xprt->rx_data.max_requests; 1094 buf->rb_max_requests = r_xprt->rx_ep.rep_max_requests;
1077 buf->rb_bc_srv_max_requests = 0; 1095 buf->rb_bc_srv_max_requests = 0;
1078 spin_lock_init(&buf->rb_mrlock); 1096 spin_lock_init(&buf->rb_mrlock);
1079 spin_lock_init(&buf->rb_lock); 1097 spin_lock_init(&buf->rb_lock);
@@ -1086,16 +1104,15 @@ rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
1086 1104
1087 INIT_LIST_HEAD(&buf->rb_send_bufs); 1105 INIT_LIST_HEAD(&buf->rb_send_bufs);
1088 INIT_LIST_HEAD(&buf->rb_allreqs); 1106 INIT_LIST_HEAD(&buf->rb_allreqs);
1107
1108 rc = -ENOMEM;
1089 for (i = 0; i < buf->rb_max_requests; i++) { 1109 for (i = 0; i < buf->rb_max_requests; i++) {
1090 struct rpcrdma_req *req; 1110 struct rpcrdma_req *req;
1091 1111
1092 req = rpcrdma_create_req(r_xprt); 1112 req = rpcrdma_req_create(r_xprt, RPCRDMA_V1_DEF_INLINE_SIZE,
1093 if (IS_ERR(req)) { 1113 GFP_KERNEL);
1094 dprintk("RPC: %s: request buffer %d alloc" 1114 if (!req)
1095 " failed\n", __func__, i);
1096 rc = PTR_ERR(req);
1097 goto out; 1115 goto out;
1098 }
1099 list_add(&req->rl_list, &buf->rb_send_bufs); 1116 list_add(&req->rl_list, &buf->rb_send_bufs);
1100 } 1117 }
1101 1118
@@ -1121,10 +1138,9 @@ out:
1121 return rc; 1138 return rc;
1122} 1139}
1123 1140
1124static void 1141static void rpcrdma_rep_destroy(struct rpcrdma_rep *rep)
1125rpcrdma_destroy_rep(struct rpcrdma_rep *rep)
1126{ 1142{
1127 rpcrdma_free_regbuf(rep->rr_rdmabuf); 1143 rpcrdma_regbuf_free(rep->rr_rdmabuf);
1128 kfree(rep); 1144 kfree(rep);
1129} 1145}
1130 1146
@@ -1140,9 +1156,9 @@ rpcrdma_req_destroy(struct rpcrdma_req *req)
1140{ 1156{
1141 list_del(&req->rl_all); 1157 list_del(&req->rl_all);
1142 1158
1143 rpcrdma_free_regbuf(req->rl_recvbuf); 1159 rpcrdma_regbuf_free(req->rl_recvbuf);
1144 rpcrdma_free_regbuf(req->rl_sendbuf); 1160 rpcrdma_regbuf_free(req->rl_sendbuf);
1145 rpcrdma_free_regbuf(req->rl_rdmabuf); 1161 rpcrdma_regbuf_free(req->rl_rdmabuf);
1146 kfree(req); 1162 kfree(req);
1147} 1163}
1148 1164
@@ -1180,7 +1196,7 @@ rpcrdma_mrs_destroy(struct rpcrdma_buffer *buf)
1180 * rpcrdma_buffer_destroy - Release all hw resources 1196 * rpcrdma_buffer_destroy - Release all hw resources
1181 * @buf: root control block for resources 1197 * @buf: root control block for resources
1182 * 1198 *
1183 * ORDERING: relies on a prior ib_drain_qp : 1199 * ORDERING: relies on a prior rpcrdma_xprt_drain :
1184 * - No more Send or Receive completions can occur 1200 * - No more Send or Receive completions can occur
1185 * - All MRs, reps, and reqs are returned to their free lists 1201 * - All MRs, reps, and reqs are returned to their free lists
1186 */ 1202 */
@@ -1202,7 +1218,7 @@ rpcrdma_buffer_destroy(struct rpcrdma_buffer *buf)
1202 rep = list_first_entry(&buf->rb_recv_bufs, 1218 rep = list_first_entry(&buf->rb_recv_bufs,
1203 struct rpcrdma_rep, rr_list); 1219 struct rpcrdma_rep, rr_list);
1204 list_del(&rep->rr_list); 1220 list_del(&rep->rr_list);
1205 rpcrdma_destroy_rep(rep); 1221 rpcrdma_rep_destroy(rep);
1206 } 1222 }
1207 1223
1208 while (!list_empty(&buf->rb_send_bufs)) { 1224 while (!list_empty(&buf->rb_send_bufs)) {
@@ -1281,7 +1297,7 @@ rpcrdma_mr_unmap_and_put(struct rpcrdma_mr *mr)
1281 1297
1282 if (mr->mr_dir != DMA_NONE) { 1298 if (mr->mr_dir != DMA_NONE) {
1283 trace_xprtrdma_mr_unmap(mr); 1299 trace_xprtrdma_mr_unmap(mr);
1284 ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, 1300 ib_dma_unmap_sg(r_xprt->rx_ia.ri_id->device,
1285 mr->mr_sg, mr->mr_nents, mr->mr_dir); 1301 mr->mr_sg, mr->mr_nents, mr->mr_dir);
1286 mr->mr_dir = DMA_NONE; 1302 mr->mr_dir = DMA_NONE;
1287 } 1303 }
@@ -1331,7 +1347,7 @@ rpcrdma_buffer_put(struct rpcrdma_req *req)
1331 } 1347 }
1332 spin_unlock(&buffers->rb_lock); 1348 spin_unlock(&buffers->rb_lock);
1333 if (rep) 1349 if (rep)
1334 rpcrdma_destroy_rep(rep); 1350 rpcrdma_rep_destroy(rep);
1335} 1351}
1336 1352
1337/* 1353/*
@@ -1348,69 +1364,90 @@ rpcrdma_recv_buffer_put(struct rpcrdma_rep *rep)
1348 list_add(&rep->rr_list, &buffers->rb_recv_bufs); 1364 list_add(&rep->rr_list, &buffers->rb_recv_bufs);
1349 spin_unlock(&buffers->rb_lock); 1365 spin_unlock(&buffers->rb_lock);
1350 } else { 1366 } else {
1351 rpcrdma_destroy_rep(rep); 1367 rpcrdma_rep_destroy(rep);
1352 } 1368 }
1353} 1369}
1354 1370
1355/** 1371/* Returns a pointer to a rpcrdma_regbuf object, or NULL.
1356 * rpcrdma_alloc_regbuf - allocate and DMA-map memory for SEND/RECV buffers
1357 * @size: size of buffer to be allocated, in bytes
1358 * @direction: direction of data movement
1359 * @flags: GFP flags
1360 *
1361 * Returns an ERR_PTR, or a pointer to a regbuf, a buffer that
1362 * can be persistently DMA-mapped for I/O.
1363 * 1372 *
1364 * xprtrdma uses a regbuf for posting an outgoing RDMA SEND, or for 1373 * xprtrdma uses a regbuf for posting an outgoing RDMA SEND, or for
1365 * receiving the payload of RDMA RECV operations. During Long Calls 1374 * receiving the payload of RDMA RECV operations. During Long Calls
1366 * or Replies they may be registered externally via frwr_map. 1375 * or Replies they may be registered externally via frwr_map.
1367 */ 1376 */
1368struct rpcrdma_regbuf * 1377static struct rpcrdma_regbuf *
1369rpcrdma_alloc_regbuf(size_t size, enum dma_data_direction direction, 1378rpcrdma_regbuf_alloc(size_t size, enum dma_data_direction direction,
1370 gfp_t flags) 1379 gfp_t flags)
1371{ 1380{
1372 struct rpcrdma_regbuf *rb; 1381 struct rpcrdma_regbuf *rb;
1373 1382
1374 rb = kmalloc(sizeof(*rb) + size, flags); 1383 rb = kmalloc(sizeof(*rb), flags);
1375 if (rb == NULL) 1384 if (!rb)
1376 return ERR_PTR(-ENOMEM); 1385 return NULL;
1386 rb->rg_data = kmalloc(size, flags);
1387 if (!rb->rg_data) {
1388 kfree(rb);
1389 return NULL;
1390 }
1377 1391
1378 rb->rg_device = NULL; 1392 rb->rg_device = NULL;
1379 rb->rg_direction = direction; 1393 rb->rg_direction = direction;
1380 rb->rg_iov.length = size; 1394 rb->rg_iov.length = size;
1381
1382 return rb; 1395 return rb;
1383} 1396}
1384 1397
1385/** 1398/**
1386 * __rpcrdma_map_regbuf - DMA-map a regbuf 1399 * rpcrdma_regbuf_realloc - re-allocate a SEND/RECV buffer
1387 * @ia: controlling rpcrdma_ia 1400 * @rb: regbuf to reallocate
1401 * @size: size of buffer to be allocated, in bytes
1402 * @flags: GFP flags
1403 *
1404 * Returns true if reallocation was successful. If false is
1405 * returned, @rb is left untouched.
1406 */
1407bool rpcrdma_regbuf_realloc(struct rpcrdma_regbuf *rb, size_t size, gfp_t flags)
1408{
1409 void *buf;
1410
1411 buf = kmalloc(size, flags);
1412 if (!buf)
1413 return false;
1414
1415 rpcrdma_regbuf_dma_unmap(rb);
1416 kfree(rb->rg_data);
1417
1418 rb->rg_data = buf;
1419 rb->rg_iov.length = size;
1420 return true;
1421}
1422
1423/**
1424 * __rpcrdma_regbuf_dma_map - DMA-map a regbuf
1425 * @r_xprt: controlling transport instance
1388 * @rb: regbuf to be mapped 1426 * @rb: regbuf to be mapped
1427 *
1428 * Returns true if the buffer is now DMA mapped to @r_xprt's device
1389 */ 1429 */
1390bool 1430bool __rpcrdma_regbuf_dma_map(struct rpcrdma_xprt *r_xprt,
1391__rpcrdma_dma_map_regbuf(struct rpcrdma_ia *ia, struct rpcrdma_regbuf *rb) 1431 struct rpcrdma_regbuf *rb)
1392{ 1432{
1393 struct ib_device *device = ia->ri_device; 1433 struct ib_device *device = r_xprt->rx_ia.ri_id->device;
1394 1434
1395 if (rb->rg_direction == DMA_NONE) 1435 if (rb->rg_direction == DMA_NONE)
1396 return false; 1436 return false;
1397 1437
1398 rb->rg_iov.addr = ib_dma_map_single(device, 1438 rb->rg_iov.addr = ib_dma_map_single(device, rdmab_data(rb),
1399 (void *)rb->rg_base, 1439 rdmab_length(rb), rb->rg_direction);
1400 rdmab_length(rb),
1401 rb->rg_direction);
1402 if (ib_dma_mapping_error(device, rdmab_addr(rb))) { 1440 if (ib_dma_mapping_error(device, rdmab_addr(rb))) {
1403 trace_xprtrdma_dma_maperr(rdmab_addr(rb)); 1441 trace_xprtrdma_dma_maperr(rdmab_addr(rb));
1404 return false; 1442 return false;
1405 } 1443 }
1406 1444
1407 rb->rg_device = device; 1445 rb->rg_device = device;
1408 rb->rg_iov.lkey = ia->ri_pd->local_dma_lkey; 1446 rb->rg_iov.lkey = r_xprt->rx_ia.ri_pd->local_dma_lkey;
1409 return true; 1447 return true;
1410} 1448}
1411 1449
1412static void 1450static void rpcrdma_regbuf_dma_unmap(struct rpcrdma_regbuf *rb)
1413rpcrdma_dma_unmap_regbuf(struct rpcrdma_regbuf *rb)
1414{ 1451{
1415 if (!rb) 1452 if (!rb)
1416 return; 1453 return;
@@ -1418,19 +1455,16 @@ rpcrdma_dma_unmap_regbuf(struct rpcrdma_regbuf *rb)
1418 if (!rpcrdma_regbuf_is_mapped(rb)) 1455 if (!rpcrdma_regbuf_is_mapped(rb))
1419 return; 1456 return;
1420 1457
1421 ib_dma_unmap_single(rb->rg_device, rdmab_addr(rb), 1458 ib_dma_unmap_single(rb->rg_device, rdmab_addr(rb), rdmab_length(rb),
1422 rdmab_length(rb), rb->rg_direction); 1459 rb->rg_direction);
1423 rb->rg_device = NULL; 1460 rb->rg_device = NULL;
1424} 1461}
1425 1462
1426/** 1463static void rpcrdma_regbuf_free(struct rpcrdma_regbuf *rb)
1427 * rpcrdma_free_regbuf - deregister and free registered buffer
1428 * @rb: regbuf to be deregistered and freed
1429 */
1430void
1431rpcrdma_free_regbuf(struct rpcrdma_regbuf *rb)
1432{ 1464{
1433 rpcrdma_dma_unmap_regbuf(rb); 1465 rpcrdma_regbuf_dma_unmap(rb);
1466 if (rb)
1467 kfree(rb->rg_data);
1434 kfree(rb); 1468 kfree(rb);
1435} 1469}
1436 1470
@@ -1497,17 +1531,15 @@ rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp)
1497 list_del(&rep->rr_list); 1531 list_del(&rep->rr_list);
1498 spin_unlock(&buf->rb_lock); 1532 spin_unlock(&buf->rb_lock);
1499 if (!rep) { 1533 if (!rep) {
1500 if (rpcrdma_create_rep(r_xprt, temp)) 1534 if (!rpcrdma_rep_create(r_xprt, temp))
1501 break; 1535 break;
1502 continue; 1536 continue;
1503 } 1537 }
1504 1538
1505 rb = rep->rr_rdmabuf; 1539 rb = rep->rr_rdmabuf;
1506 if (!rpcrdma_regbuf_is_mapped(rb)) { 1540 if (!rpcrdma_regbuf_dma_map(r_xprt, rb)) {
1507 if (!__rpcrdma_dma_map_regbuf(&r_xprt->rx_ia, rb)) { 1541 rpcrdma_recv_buffer_put(rep);
1508 rpcrdma_recv_buffer_put(rep); 1542 break;
1509 break;
1510 }
1511 } 1543 }
1512 1544
1513 trace_xprtrdma_post_recv(rep->rr_recv_wr.wr_cqe); 1545 trace_xprtrdma_post_recv(rep->rr_recv_wr.wr_cqe);
diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h
index 10f6593e1a6a..d1e0749bcbc4 100644
--- a/net/sunrpc/xprtrdma/xprt_rdma.h
+++ b/net/sunrpc/xprtrdma/xprt_rdma.h
@@ -66,20 +66,17 @@
66 * Interface Adapter -- one per transport instance 66 * Interface Adapter -- one per transport instance
67 */ 67 */
68struct rpcrdma_ia { 68struct rpcrdma_ia {
69 struct ib_device *ri_device;
70 struct rdma_cm_id *ri_id; 69 struct rdma_cm_id *ri_id;
71 struct ib_pd *ri_pd; 70 struct ib_pd *ri_pd;
72 struct completion ri_done;
73 struct completion ri_remove_done;
74 int ri_async_rc; 71 int ri_async_rc;
75 unsigned int ri_max_segs; 72 unsigned int ri_max_segs;
76 unsigned int ri_max_frwr_depth; 73 unsigned int ri_max_frwr_depth;
77 unsigned int ri_max_inline_write;
78 unsigned int ri_max_inline_read;
79 unsigned int ri_max_send_sges; 74 unsigned int ri_max_send_sges;
80 bool ri_implicit_roundup; 75 bool ri_implicit_roundup;
81 enum ib_mr_type ri_mrtype; 76 enum ib_mr_type ri_mrtype;
82 unsigned long ri_flags; 77 unsigned long ri_flags;
78 struct completion ri_done;
79 struct completion ri_remove_done;
83}; 80};
84 81
85enum { 82enum {
@@ -93,22 +90,29 @@ enum {
93struct rpcrdma_ep { 90struct rpcrdma_ep {
94 unsigned int rep_send_count; 91 unsigned int rep_send_count;
95 unsigned int rep_send_batch; 92 unsigned int rep_send_batch;
93 unsigned int rep_max_inline_send;
94 unsigned int rep_max_inline_recv;
96 int rep_connected; 95 int rep_connected;
97 struct ib_qp_init_attr rep_attr; 96 struct ib_qp_init_attr rep_attr;
98 wait_queue_head_t rep_connect_wait; 97 wait_queue_head_t rep_connect_wait;
99 struct rpcrdma_connect_private rep_cm_private; 98 struct rpcrdma_connect_private rep_cm_private;
100 struct rdma_conn_param rep_remote_cma; 99 struct rdma_conn_param rep_remote_cma;
100 unsigned int rep_max_requests; /* set by /proc */
101 unsigned int rep_inline_send; /* negotiated */
102 unsigned int rep_inline_recv; /* negotiated */
101 int rep_receive_count; 103 int rep_receive_count;
102}; 104};
103 105
104/* Pre-allocate extra Work Requests for handling backward receives 106/* Pre-allocate extra Work Requests for handling backward receives
105 * and sends. This is a fixed value because the Work Queues are 107 * and sends. This is a fixed value because the Work Queues are
106 * allocated when the forward channel is set up. 108 * allocated when the forward channel is set up, long before the
109 * backchannel is provisioned. This value is two times
110 * NFS4_DEF_CB_SLOT_TABLE_SIZE.
107 */ 111 */
108#if defined(CONFIG_SUNRPC_BACKCHANNEL) 112#if defined(CONFIG_SUNRPC_BACKCHANNEL)
109#define RPCRDMA_BACKWARD_WRS (8) 113#define RPCRDMA_BACKWARD_WRS (32)
110#else 114#else
111#define RPCRDMA_BACKWARD_WRS (0) 115#define RPCRDMA_BACKWARD_WRS (0)
112#endif 116#endif
113 117
114/* Registered buffer -- registered kmalloc'd memory for RDMA SEND/RECV 118/* Registered buffer -- registered kmalloc'd memory for RDMA SEND/RECV
@@ -121,33 +125,34 @@ struct rpcrdma_regbuf {
121 struct ib_sge rg_iov; 125 struct ib_sge rg_iov;
122 struct ib_device *rg_device; 126 struct ib_device *rg_device;
123 enum dma_data_direction rg_direction; 127 enum dma_data_direction rg_direction;
124 __be32 rg_base[0] __attribute__ ((aligned(256))); 128 void *rg_data;
125}; 129};
126 130
127static inline u64 131static inline u64 rdmab_addr(struct rpcrdma_regbuf *rb)
128rdmab_addr(struct rpcrdma_regbuf *rb)
129{ 132{
130 return rb->rg_iov.addr; 133 return rb->rg_iov.addr;
131} 134}
132 135
133static inline u32 136static inline u32 rdmab_length(struct rpcrdma_regbuf *rb)
134rdmab_length(struct rpcrdma_regbuf *rb)
135{ 137{
136 return rb->rg_iov.length; 138 return rb->rg_iov.length;
137} 139}
138 140
139static inline u32 141static inline u32 rdmab_lkey(struct rpcrdma_regbuf *rb)
140rdmab_lkey(struct rpcrdma_regbuf *rb)
141{ 142{
142 return rb->rg_iov.lkey; 143 return rb->rg_iov.lkey;
143} 144}
144 145
145static inline struct ib_device * 146static inline struct ib_device *rdmab_device(struct rpcrdma_regbuf *rb)
146rdmab_device(struct rpcrdma_regbuf *rb)
147{ 147{
148 return rb->rg_device; 148 return rb->rg_device;
149} 149}
150 150
151static inline void *rdmab_data(const struct rpcrdma_regbuf *rb)
152{
153 return rb->rg_data;
154}
155
151#define RPCRDMA_DEF_GFP (GFP_NOIO | __GFP_NOWARN) 156#define RPCRDMA_DEF_GFP (GFP_NOIO | __GFP_NOWARN)
152 157
153/* To ensure a transport can always make forward progress, 158/* To ensure a transport can always make forward progress,
@@ -222,34 +227,18 @@ struct rpcrdma_xprt;
222struct rpcrdma_sendctx { 227struct rpcrdma_sendctx {
223 struct ib_send_wr sc_wr; 228 struct ib_send_wr sc_wr;
224 struct ib_cqe sc_cqe; 229 struct ib_cqe sc_cqe;
230 struct ib_device *sc_device;
225 struct rpcrdma_xprt *sc_xprt; 231 struct rpcrdma_xprt *sc_xprt;
226 struct rpcrdma_req *sc_req; 232 struct rpcrdma_req *sc_req;
227 unsigned int sc_unmap_count; 233 unsigned int sc_unmap_count;
228 struct ib_sge sc_sges[]; 234 struct ib_sge sc_sges[];
229}; 235};
230 236
231/* Limit the number of SGEs that can be unmapped during one
232 * Send completion. This caps the amount of work a single
233 * completion can do before returning to the provider.
234 *
235 * Setting this to zero disables Send completion batching.
236 */
237enum {
238 RPCRDMA_MAX_SEND_BATCH = 7,
239};
240
241/* 237/*
242 * struct rpcrdma_mr - external memory region metadata 238 * struct rpcrdma_mr - external memory region metadata
243 * 239 *
244 * An external memory region is any buffer or page that is registered 240 * An external memory region is any buffer or page that is registered
245 * on the fly (ie, not pre-registered). 241 * on the fly (ie, not pre-registered).
246 *
247 * Each rpcrdma_buffer has a list of free MWs anchored in rb_mrs. During
248 * call_allocate, rpcrdma_buffer_get() assigns one to each segment in
249 * an rpcrdma_req. Then rpcrdma_register_external() grabs these to keep
250 * track of registration metadata while each RPC is pending.
251 * rpcrdma_deregister_external() uses this metadata to unmap and
252 * release these resources when an RPC is complete.
253 */ 242 */
254enum rpcrdma_frwr_state { 243enum rpcrdma_frwr_state {
255 FRWR_IS_INVALID, /* ready to be used */ 244 FRWR_IS_INVALID, /* ready to be used */
@@ -419,20 +408,6 @@ enum {
419}; 408};
420 409
421/* 410/*
422 * Internal structure for transport instance creation. This
423 * exists primarily for modularity.
424 *
425 * This data should be set with mount options
426 */
427struct rpcrdma_create_data_internal {
428 unsigned int max_requests; /* max requests (slots) in flight */
429 unsigned int rsize; /* mount rsize - max read hdr+data */
430 unsigned int wsize; /* mount wsize - max write hdr+data */
431 unsigned int inline_rsize; /* max non-rdma read data payload */
432 unsigned int inline_wsize; /* max non-rdma write data payload */
433};
434
435/*
436 * Statistics for RPCRDMA 411 * Statistics for RPCRDMA
437 */ 412 */
438struct rpcrdma_stats { 413struct rpcrdma_stats {
@@ -476,13 +451,11 @@ struct rpcrdma_xprt {
476 struct rpcrdma_ia rx_ia; 451 struct rpcrdma_ia rx_ia;
477 struct rpcrdma_ep rx_ep; 452 struct rpcrdma_ep rx_ep;
478 struct rpcrdma_buffer rx_buf; 453 struct rpcrdma_buffer rx_buf;
479 struct rpcrdma_create_data_internal rx_data;
480 struct delayed_work rx_connect_worker; 454 struct delayed_work rx_connect_worker;
481 struct rpcrdma_stats rx_stats; 455 struct rpcrdma_stats rx_stats;
482}; 456};
483 457
484#define rpcx_to_rdmax(x) container_of(x, struct rpcrdma_xprt, rx_xprt) 458#define rpcx_to_rdmax(x) container_of(x, struct rpcrdma_xprt, rx_xprt)
485#define rpcx_to_rdmad(x) (rpcx_to_rdmax(x)->rx_data)
486 459
487static inline const char * 460static inline const char *
488rpcrdma_addrstr(const struct rpcrdma_xprt *r_xprt) 461rpcrdma_addrstr(const struct rpcrdma_xprt *r_xprt)
@@ -516,9 +489,8 @@ void rpcrdma_ia_close(struct rpcrdma_ia *);
516/* 489/*
517 * Endpoint calls - xprtrdma/verbs.c 490 * Endpoint calls - xprtrdma/verbs.c
518 */ 491 */
519int rpcrdma_ep_create(struct rpcrdma_ep *, struct rpcrdma_ia *, 492int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt);
520 struct rpcrdma_create_data_internal *); 493void rpcrdma_ep_destroy(struct rpcrdma_xprt *r_xprt);
521void rpcrdma_ep_destroy(struct rpcrdma_ep *, struct rpcrdma_ia *);
522int rpcrdma_ep_connect(struct rpcrdma_ep *, struct rpcrdma_ia *); 494int rpcrdma_ep_connect(struct rpcrdma_ep *, struct rpcrdma_ia *);
523void rpcrdma_ep_disconnect(struct rpcrdma_ep *, struct rpcrdma_ia *); 495void rpcrdma_ep_disconnect(struct rpcrdma_ep *, struct rpcrdma_ia *);
524 496
@@ -528,11 +500,12 @@ int rpcrdma_ep_post(struct rpcrdma_ia *, struct rpcrdma_ep *,
528/* 500/*
529 * Buffer calls - xprtrdma/verbs.c 501 * Buffer calls - xprtrdma/verbs.c
530 */ 502 */
531struct rpcrdma_req *rpcrdma_create_req(struct rpcrdma_xprt *); 503struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size,
504 gfp_t flags);
532void rpcrdma_req_destroy(struct rpcrdma_req *req); 505void rpcrdma_req_destroy(struct rpcrdma_req *req);
533int rpcrdma_buffer_create(struct rpcrdma_xprt *); 506int rpcrdma_buffer_create(struct rpcrdma_xprt *);
534void rpcrdma_buffer_destroy(struct rpcrdma_buffer *); 507void rpcrdma_buffer_destroy(struct rpcrdma_buffer *);
535struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked(struct rpcrdma_buffer *buf); 508struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked(struct rpcrdma_xprt *r_xprt);
536 509
537struct rpcrdma_mr *rpcrdma_mr_get(struct rpcrdma_xprt *r_xprt); 510struct rpcrdma_mr *rpcrdma_mr_get(struct rpcrdma_xprt *r_xprt);
538void rpcrdma_mr_put(struct rpcrdma_mr *mr); 511void rpcrdma_mr_put(struct rpcrdma_mr *mr);
@@ -548,23 +521,34 @@ struct rpcrdma_req *rpcrdma_buffer_get(struct rpcrdma_buffer *);
548void rpcrdma_buffer_put(struct rpcrdma_req *); 521void rpcrdma_buffer_put(struct rpcrdma_req *);
549void rpcrdma_recv_buffer_put(struct rpcrdma_rep *); 522void rpcrdma_recv_buffer_put(struct rpcrdma_rep *);
550 523
551struct rpcrdma_regbuf *rpcrdma_alloc_regbuf(size_t, enum dma_data_direction, 524bool rpcrdma_regbuf_realloc(struct rpcrdma_regbuf *rb, size_t size,
552 gfp_t); 525 gfp_t flags);
553bool __rpcrdma_dma_map_regbuf(struct rpcrdma_ia *, struct rpcrdma_regbuf *); 526bool __rpcrdma_regbuf_dma_map(struct rpcrdma_xprt *r_xprt,
554void rpcrdma_free_regbuf(struct rpcrdma_regbuf *); 527 struct rpcrdma_regbuf *rb);
555 528
556static inline bool 529/**
557rpcrdma_regbuf_is_mapped(struct rpcrdma_regbuf *rb) 530 * rpcrdma_regbuf_is_mapped - check if buffer is DMA mapped
531 *
532 * Returns true if the buffer is now mapped to rb->rg_device.
533 */
534static inline bool rpcrdma_regbuf_is_mapped(struct rpcrdma_regbuf *rb)
558{ 535{
559 return rb->rg_device != NULL; 536 return rb->rg_device != NULL;
560} 537}
561 538
562static inline bool 539/**
563rpcrdma_dma_map_regbuf(struct rpcrdma_ia *ia, struct rpcrdma_regbuf *rb) 540 * rpcrdma_regbuf_dma_map - DMA-map a regbuf
541 * @r_xprt: controlling transport instance
542 * @rb: regbuf to be mapped
543 *
544 * Returns true if the buffer is currently DMA mapped.
545 */
546static inline bool rpcrdma_regbuf_dma_map(struct rpcrdma_xprt *r_xprt,
547 struct rpcrdma_regbuf *rb)
564{ 548{
565 if (likely(rpcrdma_regbuf_is_mapped(rb))) 549 if (likely(rpcrdma_regbuf_is_mapped(rb)))
566 return true; 550 return true;
567 return __rpcrdma_dma_map_regbuf(ia, rb); 551 return __rpcrdma_regbuf_dma_map(r_xprt, rb);
568} 552}
569 553
570/* 554/*
@@ -579,9 +563,8 @@ rpcrdma_data_dir(bool writing)
579 563
580/* Memory registration calls xprtrdma/frwr_ops.c 564/* Memory registration calls xprtrdma/frwr_ops.c
581 */ 565 */
582bool frwr_is_supported(struct rpcrdma_ia *); 566bool frwr_is_supported(struct ib_device *device);
583int frwr_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep, 567int frwr_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep);
584 struct rpcrdma_create_data_internal *cdata);
585int frwr_init_mr(struct rpcrdma_ia *ia, struct rpcrdma_mr *mr); 568int frwr_init_mr(struct rpcrdma_ia *ia, struct rpcrdma_mr *mr);
586void frwr_release_mr(struct rpcrdma_mr *mr); 569void frwr_release_mr(struct rpcrdma_mr *mr);
587size_t frwr_maxpages(struct rpcrdma_xprt *r_xprt); 570size_t frwr_maxpages(struct rpcrdma_xprt *r_xprt);
@@ -610,7 +593,7 @@ int rpcrdma_prepare_send_sges(struct rpcrdma_xprt *r_xprt,
610 struct rpcrdma_req *req, u32 hdrlen, 593 struct rpcrdma_req *req, u32 hdrlen,
611 struct xdr_buf *xdr, 594 struct xdr_buf *xdr,
612 enum rpcrdma_chunktype rtype); 595 enum rpcrdma_chunktype rtype);
613void rpcrdma_unmap_sendctx(struct rpcrdma_sendctx *sc); 596void rpcrdma_sendctx_unmap(struct rpcrdma_sendctx *sc);
614int rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst); 597int rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst);
615void rpcrdma_set_max_header_sizes(struct rpcrdma_xprt *); 598void rpcrdma_set_max_header_sizes(struct rpcrdma_xprt *);
616void rpcrdma_complete_rqst(struct rpcrdma_rep *rep); 599void rpcrdma_complete_rqst(struct rpcrdma_rep *rep);
@@ -627,7 +610,9 @@ static inline void rpcrdma_set_xdrlen(struct xdr_buf *xdr, size_t len)
627 610
628/* RPC/RDMA module init - xprtrdma/transport.c 611/* RPC/RDMA module init - xprtrdma/transport.c
629 */ 612 */
613extern unsigned int xprt_rdma_slot_table_entries;
630extern unsigned int xprt_rdma_max_inline_read; 614extern unsigned int xprt_rdma_max_inline_read;
615extern unsigned int xprt_rdma_max_inline_write;
631void xprt_rdma_format_addresses(struct rpc_xprt *xprt, struct sockaddr *sap); 616void xprt_rdma_format_addresses(struct rpc_xprt *xprt, struct sockaddr *sap);
632void xprt_rdma_free_addresses(struct rpc_xprt *xprt); 617void xprt_rdma_free_addresses(struct rpc_xprt *xprt);
633void xprt_rdma_close(struct rpc_xprt *xprt); 618void xprt_rdma_close(struct rpc_xprt *xprt);
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 732d4b57411a..c69951ed2ebc 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -2017,6 +2017,7 @@ static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task)
2017 * we'll need to figure out how to pass a namespace to 2017 * we'll need to figure out how to pass a namespace to
2018 * connect. 2018 * connect.
2019 */ 2019 */
2020 task->tk_rpc_status = -ENOTCONN;
2020 rpc_exit(task, -ENOTCONN); 2021 rpc_exit(task, -ENOTCONN);
2021 return; 2022 return;
2022 } 2023 }
@@ -2690,7 +2691,7 @@ static const struct rpc_xprt_ops xs_local_ops = {
2690 .buf_free = rpc_free, 2691 .buf_free = rpc_free,
2691 .prepare_request = xs_stream_prepare_request, 2692 .prepare_request = xs_stream_prepare_request,
2692 .send_request = xs_local_send_request, 2693 .send_request = xs_local_send_request,
2693 .set_retrans_timeout = xprt_set_retrans_timeout_def, 2694 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2694 .close = xs_close, 2695 .close = xs_close,
2695 .destroy = xs_destroy, 2696 .destroy = xs_destroy,
2696 .print_stats = xs_local_print_stats, 2697 .print_stats = xs_local_print_stats,
@@ -2710,7 +2711,7 @@ static const struct rpc_xprt_ops xs_udp_ops = {
2710 .buf_alloc = rpc_malloc, 2711 .buf_alloc = rpc_malloc,
2711 .buf_free = rpc_free, 2712 .buf_free = rpc_free,
2712 .send_request = xs_udp_send_request, 2713 .send_request = xs_udp_send_request,
2713 .set_retrans_timeout = xprt_set_retrans_timeout_rtt, 2714 .wait_for_reply_request = xprt_wait_for_reply_request_rtt,
2714 .timer = xs_udp_timer, 2715 .timer = xs_udp_timer,
2715 .release_request = xprt_release_rqst_cong, 2716 .release_request = xprt_release_rqst_cong,
2716 .close = xs_close, 2717 .close = xs_close,
@@ -2733,7 +2734,7 @@ static const struct rpc_xprt_ops xs_tcp_ops = {
2733 .buf_free = rpc_free, 2734 .buf_free = rpc_free,
2734 .prepare_request = xs_stream_prepare_request, 2735 .prepare_request = xs_stream_prepare_request,
2735 .send_request = xs_tcp_send_request, 2736 .send_request = xs_tcp_send_request,
2736 .set_retrans_timeout = xprt_set_retrans_timeout_def, 2737 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2737 .close = xs_tcp_shutdown, 2738 .close = xs_tcp_shutdown,
2738 .destroy = xs_destroy, 2739 .destroy = xs_destroy,
2739 .set_connect_timeout = xs_tcp_set_connect_timeout, 2740 .set_connect_timeout = xs_tcp_set_connect_timeout,
@@ -2761,7 +2762,7 @@ static const struct rpc_xprt_ops bc_tcp_ops = {
2761 .buf_alloc = bc_malloc, 2762 .buf_alloc = bc_malloc,
2762 .buf_free = bc_free, 2763 .buf_free = bc_free,
2763 .send_request = bc_send_request, 2764 .send_request = bc_send_request,
2764 .set_retrans_timeout = xprt_set_retrans_timeout_def, 2765 .wait_for_reply_request = xprt_wait_for_reply_request_def,
2765 .close = bc_close, 2766 .close = bc_close,
2766 .destroy = bc_destroy, 2767 .destroy = bc_destroy,
2767 .print_stats = xs_tcp_print_stats, 2768 .print_stats = xs_tcp_print_stats,
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index d8026543bf4c..6c997d4a6218 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -54,7 +54,9 @@ const char tipc_bclink_name[] = "broadcast-link";
54 * @dests: array keeping number of reachable destinations per bearer 54 * @dests: array keeping number of reachable destinations per bearer
55 * @primary_bearer: a bearer having links to all broadcast destinations, if any 55 * @primary_bearer: a bearer having links to all broadcast destinations, if any
56 * @bcast_support: indicates if primary bearer, if any, supports broadcast 56 * @bcast_support: indicates if primary bearer, if any, supports broadcast
57 * @force_bcast: forces broadcast for multicast traffic
57 * @rcast_support: indicates if all peer nodes support replicast 58 * @rcast_support: indicates if all peer nodes support replicast
59 * @force_rcast: forces replicast for multicast traffic
58 * @rc_ratio: dest count as percentage of cluster size where send method changes 60 * @rc_ratio: dest count as percentage of cluster size where send method changes
59 * @bc_threshold: calculated from rc_ratio; if dests > threshold use broadcast 61 * @bc_threshold: calculated from rc_ratio; if dests > threshold use broadcast
60 */ 62 */
@@ -64,7 +66,9 @@ struct tipc_bc_base {
64 int dests[MAX_BEARERS]; 66 int dests[MAX_BEARERS];
65 int primary_bearer; 67 int primary_bearer;
66 bool bcast_support; 68 bool bcast_support;
69 bool force_bcast;
67 bool rcast_support; 70 bool rcast_support;
71 bool force_rcast;
68 int rc_ratio; 72 int rc_ratio;
69 int bc_threshold; 73 int bc_threshold;
70}; 74};
@@ -216,9 +220,24 @@ static void tipc_bcast_select_xmit_method(struct net *net, int dests,
216 } 220 }
217 /* Can current method be changed ? */ 221 /* Can current method be changed ? */
218 method->expires = jiffies + TIPC_METHOD_EXPIRE; 222 method->expires = jiffies + TIPC_METHOD_EXPIRE;
219 if (method->mandatory || time_before(jiffies, exp)) 223 if (method->mandatory)
220 return; 224 return;
221 225
226 if (!(tipc_net(net)->capabilities & TIPC_MCAST_RBCTL) &&
227 time_before(jiffies, exp))
228 return;
229
230 /* Configuration as force 'broadcast' method */
231 if (bb->force_bcast) {
232 method->rcast = false;
233 return;
234 }
235 /* Configuration as force 'replicast' method */
236 if (bb->force_rcast) {
237 method->rcast = true;
238 return;
239 }
240 /* Configuration as 'autoselect' or default method */
222 /* Determine method to use now */ 241 /* Determine method to use now */
223 method->rcast = dests <= bb->bc_threshold; 242 method->rcast = dests <= bb->bc_threshold;
224} 243}
@@ -281,6 +300,63 @@ static int tipc_rcast_xmit(struct net *net, struct sk_buff_head *pkts,
281 return 0; 300 return 0;
282} 301}
283 302
303/* tipc_mcast_send_sync - deliver a dummy message with SYN bit
304 * @net: the applicable net namespace
305 * @skb: socket buffer to copy
306 * @method: send method to be used
307 * @dests: destination nodes for message.
308 * @cong_link_cnt: returns number of encountered congested destination links
309 * Returns 0 if success, otherwise errno
310 */
311static int tipc_mcast_send_sync(struct net *net, struct sk_buff *skb,
312 struct tipc_mc_method *method,
313 struct tipc_nlist *dests,
314 u16 *cong_link_cnt)
315{
316 struct tipc_msg *hdr, *_hdr;
317 struct sk_buff_head tmpq;
318 struct sk_buff *_skb;
319
320 /* Is a cluster supporting with new capabilities ? */
321 if (!(tipc_net(net)->capabilities & TIPC_MCAST_RBCTL))
322 return 0;
323
324 hdr = buf_msg(skb);
325 if (msg_user(hdr) == MSG_FRAGMENTER)
326 hdr = msg_get_wrapped(hdr);
327 if (msg_type(hdr) != TIPC_MCAST_MSG)
328 return 0;
329
330 /* Allocate dummy message */
331 _skb = tipc_buf_acquire(MCAST_H_SIZE, GFP_KERNEL);
332 if (!_skb)
333 return -ENOMEM;
334
335 /* Preparing for 'synching' header */
336 msg_set_syn(hdr, 1);
337
338 /* Copy skb's header into a dummy header */
339 skb_copy_to_linear_data(_skb, hdr, MCAST_H_SIZE);
340 skb_orphan(_skb);
341
342 /* Reverse method for dummy message */
343 _hdr = buf_msg(_skb);
344 msg_set_size(_hdr, MCAST_H_SIZE);
345 msg_set_is_rcast(_hdr, !msg_is_rcast(hdr));
346
347 skb_queue_head_init(&tmpq);
348 __skb_queue_tail(&tmpq, _skb);
349 if (method->rcast)
350 tipc_bcast_xmit(net, &tmpq, cong_link_cnt);
351 else
352 tipc_rcast_xmit(net, &tmpq, dests, cong_link_cnt);
353
354 /* This queue should normally be empty by now */
355 __skb_queue_purge(&tmpq);
356
357 return 0;
358}
359
284/* tipc_mcast_xmit - deliver message to indicated destination nodes 360/* tipc_mcast_xmit - deliver message to indicated destination nodes
285 * and to identified node local sockets 361 * and to identified node local sockets
286 * @net: the applicable net namespace 362 * @net: the applicable net namespace
@@ -296,6 +372,9 @@ int tipc_mcast_xmit(struct net *net, struct sk_buff_head *pkts,
296 u16 *cong_link_cnt) 372 u16 *cong_link_cnt)
297{ 373{
298 struct sk_buff_head inputq, localq; 374 struct sk_buff_head inputq, localq;
375 bool rcast = method->rcast;
376 struct tipc_msg *hdr;
377 struct sk_buff *skb;
299 int rc = 0; 378 int rc = 0;
300 379
301 skb_queue_head_init(&inputq); 380 skb_queue_head_init(&inputq);
@@ -309,6 +388,18 @@ int tipc_mcast_xmit(struct net *net, struct sk_buff_head *pkts,
309 /* Send according to determined transmit method */ 388 /* Send according to determined transmit method */
310 if (dests->remote) { 389 if (dests->remote) {
311 tipc_bcast_select_xmit_method(net, dests->remote, method); 390 tipc_bcast_select_xmit_method(net, dests->remote, method);
391
392 skb = skb_peek(pkts);
393 hdr = buf_msg(skb);
394 if (msg_user(hdr) == MSG_FRAGMENTER)
395 hdr = msg_get_wrapped(hdr);
396 msg_set_is_rcast(hdr, method->rcast);
397
398 /* Switch method ? */
399 if (rcast != method->rcast)
400 tipc_mcast_send_sync(net, skb, method,
401 dests, cong_link_cnt);
402
312 if (method->rcast) 403 if (method->rcast)
313 rc = tipc_rcast_xmit(net, pkts, dests, cong_link_cnt); 404 rc = tipc_rcast_xmit(net, pkts, dests, cong_link_cnt);
314 else 405 else
@@ -485,10 +576,63 @@ static int tipc_bc_link_set_queue_limits(struct net *net, u32 limit)
485 return 0; 576 return 0;
486} 577}
487 578
579static int tipc_bc_link_set_broadcast_mode(struct net *net, u32 bc_mode)
580{
581 struct tipc_bc_base *bb = tipc_bc_base(net);
582
583 switch (bc_mode) {
584 case BCLINK_MODE_BCAST:
585 if (!bb->bcast_support)
586 return -ENOPROTOOPT;
587
588 bb->force_bcast = true;
589 bb->force_rcast = false;
590 break;
591 case BCLINK_MODE_RCAST:
592 if (!bb->rcast_support)
593 return -ENOPROTOOPT;
594
595 bb->force_bcast = false;
596 bb->force_rcast = true;
597 break;
598 case BCLINK_MODE_SEL:
599 if (!bb->bcast_support || !bb->rcast_support)
600 return -ENOPROTOOPT;
601
602 bb->force_bcast = false;
603 bb->force_rcast = false;
604 break;
605 default:
606 return -EINVAL;
607 }
608
609 return 0;
610}
611
612static int tipc_bc_link_set_broadcast_ratio(struct net *net, u32 bc_ratio)
613{
614 struct tipc_bc_base *bb = tipc_bc_base(net);
615
616 if (!bb->bcast_support || !bb->rcast_support)
617 return -ENOPROTOOPT;
618
619 if (bc_ratio > 100 || bc_ratio <= 0)
620 return -EINVAL;
621
622 bb->rc_ratio = bc_ratio;
623 tipc_bcast_lock(net);
624 tipc_bcbase_calc_bc_threshold(net);
625 tipc_bcast_unlock(net);
626
627 return 0;
628}
629
488int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[]) 630int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[])
489{ 631{
490 int err; 632 int err;
491 u32 win; 633 u32 win;
634 u32 bc_mode;
635 u32 bc_ratio;
492 struct nlattr *props[TIPC_NLA_PROP_MAX + 1]; 636 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
493 637
494 if (!attrs[TIPC_NLA_LINK_PROP]) 638 if (!attrs[TIPC_NLA_LINK_PROP])
@@ -498,12 +642,28 @@ int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[])
498 if (err) 642 if (err)
499 return err; 643 return err;
500 644
501 if (!props[TIPC_NLA_PROP_WIN]) 645 if (!props[TIPC_NLA_PROP_WIN] &&
646 !props[TIPC_NLA_PROP_BROADCAST] &&
647 !props[TIPC_NLA_PROP_BROADCAST_RATIO]) {
502 return -EOPNOTSUPP; 648 return -EOPNOTSUPP;
649 }
650
651 if (props[TIPC_NLA_PROP_BROADCAST]) {
652 bc_mode = nla_get_u32(props[TIPC_NLA_PROP_BROADCAST]);
653 err = tipc_bc_link_set_broadcast_mode(net, bc_mode);
654 }
655
656 if (!err && props[TIPC_NLA_PROP_BROADCAST_RATIO]) {
657 bc_ratio = nla_get_u32(props[TIPC_NLA_PROP_BROADCAST_RATIO]);
658 err = tipc_bc_link_set_broadcast_ratio(net, bc_ratio);
659 }
503 660
504 win = nla_get_u32(props[TIPC_NLA_PROP_WIN]); 661 if (!err && props[TIPC_NLA_PROP_WIN]) {
662 win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
663 err = tipc_bc_link_set_queue_limits(net, win);
664 }
505 665
506 return tipc_bc_link_set_queue_limits(net, win); 666 return err;
507} 667}
508 668
509int tipc_bcast_init(struct net *net) 669int tipc_bcast_init(struct net *net)
@@ -529,7 +689,7 @@ int tipc_bcast_init(struct net *net)
529 goto enomem; 689 goto enomem;
530 bb->link = l; 690 bb->link = l;
531 tn->bcl = l; 691 tn->bcl = l;
532 bb->rc_ratio = 25; 692 bb->rc_ratio = 10;
533 bb->rcast_support = true; 693 bb->rcast_support = true;
534 return 0; 694 return 0;
535enomem: 695enomem:
@@ -576,3 +736,108 @@ void tipc_nlist_purge(struct tipc_nlist *nl)
576 nl->remote = 0; 736 nl->remote = 0;
577 nl->local = false; 737 nl->local = false;
578} 738}
739
740u32 tipc_bcast_get_broadcast_mode(struct net *net)
741{
742 struct tipc_bc_base *bb = tipc_bc_base(net);
743
744 if (bb->force_bcast)
745 return BCLINK_MODE_BCAST;
746
747 if (bb->force_rcast)
748 return BCLINK_MODE_RCAST;
749
750 if (bb->bcast_support && bb->rcast_support)
751 return BCLINK_MODE_SEL;
752
753 return 0;
754}
755
756u32 tipc_bcast_get_broadcast_ratio(struct net *net)
757{
758 struct tipc_bc_base *bb = tipc_bc_base(net);
759
760 return bb->rc_ratio;
761}
762
763void tipc_mcast_filter_msg(struct net *net, struct sk_buff_head *defq,
764 struct sk_buff_head *inputq)
765{
766 struct sk_buff *skb, *_skb, *tmp;
767 struct tipc_msg *hdr, *_hdr;
768 bool match = false;
769 u32 node, port;
770
771 skb = skb_peek(inputq);
772 if (!skb)
773 return;
774
775 hdr = buf_msg(skb);
776
777 if (likely(!msg_is_syn(hdr) && skb_queue_empty(defq)))
778 return;
779
780 node = msg_orignode(hdr);
781 if (node == tipc_own_addr(net))
782 return;
783
784 port = msg_origport(hdr);
785
786 /* Has the twin SYN message already arrived ? */
787 skb_queue_walk(defq, _skb) {
788 _hdr = buf_msg(_skb);
789 if (msg_orignode(_hdr) != node)
790 continue;
791 if (msg_origport(_hdr) != port)
792 continue;
793 match = true;
794 break;
795 }
796
797 if (!match) {
798 if (!msg_is_syn(hdr))
799 return;
800 __skb_dequeue(inputq);
801 __skb_queue_tail(defq, skb);
802 return;
803 }
804
805 /* Deliver non-SYN message from other link, otherwise queue it */
806 if (!msg_is_syn(hdr)) {
807 if (msg_is_rcast(hdr) != msg_is_rcast(_hdr))
808 return;
809 __skb_dequeue(inputq);
810 __skb_queue_tail(defq, skb);
811 return;
812 }
813
814 /* Queue non-SYN/SYN message from same link */
815 if (msg_is_rcast(hdr) == msg_is_rcast(_hdr)) {
816 __skb_dequeue(inputq);
817 __skb_queue_tail(defq, skb);
818 return;
819 }
820
821 /* Matching SYN messages => return the one with data, if any */
822 __skb_unlink(_skb, defq);
823 if (msg_data_sz(hdr)) {
824 kfree_skb(_skb);
825 } else {
826 __skb_dequeue(inputq);
827 kfree_skb(skb);
828 __skb_queue_tail(inputq, _skb);
829 }
830
831 /* Deliver subsequent non-SYN messages from same peer */
832 skb_queue_walk_safe(defq, _skb, tmp) {
833 _hdr = buf_msg(_skb);
834 if (msg_orignode(_hdr) != node)
835 continue;
836 if (msg_origport(_hdr) != port)
837 continue;
838 if (msg_is_syn(_hdr))
839 break;
840 __skb_unlink(_skb, defq);
841 __skb_queue_tail(inputq, _skb);
842 }
843}
diff --git a/net/tipc/bcast.h b/net/tipc/bcast.h
index 751530ab0c49..dadad953e2be 100644
--- a/net/tipc/bcast.h
+++ b/net/tipc/bcast.h
@@ -48,6 +48,10 @@ extern const char tipc_bclink_name[];
48 48
49#define TIPC_METHOD_EXPIRE msecs_to_jiffies(5000) 49#define TIPC_METHOD_EXPIRE msecs_to_jiffies(5000)
50 50
51#define BCLINK_MODE_BCAST 0x1
52#define BCLINK_MODE_RCAST 0x2
53#define BCLINK_MODE_SEL 0x4
54
51struct tipc_nlist { 55struct tipc_nlist {
52 struct list_head list; 56 struct list_head list;
53 u32 self; 57 u32 self;
@@ -63,11 +67,13 @@ void tipc_nlist_del(struct tipc_nlist *nl, u32 node);
63/* Cookie to be used between socket and broadcast layer 67/* Cookie to be used between socket and broadcast layer
64 * @rcast: replicast (instead of broadcast) was used at previous xmit 68 * @rcast: replicast (instead of broadcast) was used at previous xmit
65 * @mandatory: broadcast/replicast indication was set by user 69 * @mandatory: broadcast/replicast indication was set by user
70 * @deferredq: defer queue to make message in order
66 * @expires: re-evaluate non-mandatory transmit method if we are past this 71 * @expires: re-evaluate non-mandatory transmit method if we are past this
67 */ 72 */
68struct tipc_mc_method { 73struct tipc_mc_method {
69 bool rcast; 74 bool rcast;
70 bool mandatory; 75 bool mandatory;
76 struct sk_buff_head deferredq;
71 unsigned long expires; 77 unsigned long expires;
72}; 78};
73 79
@@ -92,6 +98,12 @@ int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg);
92int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[]); 98int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[]);
93int tipc_bclink_reset_stats(struct net *net); 99int tipc_bclink_reset_stats(struct net *net);
94 100
101u32 tipc_bcast_get_broadcast_mode(struct net *net);
102u32 tipc_bcast_get_broadcast_ratio(struct net *net);
103
104void tipc_mcast_filter_msg(struct net *net, struct sk_buff_head *defq,
105 struct sk_buff_head *inputq);
106
95static inline void tipc_bcast_lock(struct net *net) 107static inline void tipc_bcast_lock(struct net *net)
96{ 108{
97 spin_lock_bh(&tipc_net(net)->bclock); 109 spin_lock_bh(&tipc_net(net)->bclock);
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index d27f30a9a01d..2bed6589f41e 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -687,14 +687,14 @@ static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg,
687 if (!hdr) 687 if (!hdr)
688 return -EMSGSIZE; 688 return -EMSGSIZE;
689 689
690 attrs = nla_nest_start(msg->skb, TIPC_NLA_BEARER); 690 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_BEARER);
691 if (!attrs) 691 if (!attrs)
692 goto msg_full; 692 goto msg_full;
693 693
694 if (nla_put_string(msg->skb, TIPC_NLA_BEARER_NAME, bearer->name)) 694 if (nla_put_string(msg->skb, TIPC_NLA_BEARER_NAME, bearer->name))
695 goto attr_msg_full; 695 goto attr_msg_full;
696 696
697 prop = nla_nest_start(msg->skb, TIPC_NLA_BEARER_PROP); 697 prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_BEARER_PROP);
698 if (!prop) 698 if (!prop)
699 goto prop_msg_full; 699 goto prop_msg_full;
700 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, bearer->priority)) 700 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, bearer->priority))
@@ -776,9 +776,9 @@ int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
776 if (!info->attrs[TIPC_NLA_BEARER]) 776 if (!info->attrs[TIPC_NLA_BEARER])
777 return -EINVAL; 777 return -EINVAL;
778 778
779 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX, 779 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
780 info->attrs[TIPC_NLA_BEARER], 780 info->attrs[TIPC_NLA_BEARER],
781 tipc_nl_bearer_policy, info->extack); 781 tipc_nl_bearer_policy, info->extack);
782 if (err) 782 if (err)
783 return err; 783 return err;
784 784
@@ -825,9 +825,9 @@ int __tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
825 if (!info->attrs[TIPC_NLA_BEARER]) 825 if (!info->attrs[TIPC_NLA_BEARER])
826 return -EINVAL; 826 return -EINVAL;
827 827
828 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX, 828 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
829 info->attrs[TIPC_NLA_BEARER], 829 info->attrs[TIPC_NLA_BEARER],
830 tipc_nl_bearer_policy, info->extack); 830 tipc_nl_bearer_policy, info->extack);
831 if (err) 831 if (err)
832 return err; 832 return err;
833 833
@@ -870,9 +870,9 @@ int __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
870 if (!info->attrs[TIPC_NLA_BEARER]) 870 if (!info->attrs[TIPC_NLA_BEARER])
871 return -EINVAL; 871 return -EINVAL;
872 872
873 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX, 873 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
874 info->attrs[TIPC_NLA_BEARER], 874 info->attrs[TIPC_NLA_BEARER],
875 tipc_nl_bearer_policy, info->extack); 875 tipc_nl_bearer_policy, info->extack);
876 if (err) 876 if (err)
877 return err; 877 return err;
878 878
@@ -921,9 +921,9 @@ int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info)
921 if (!info->attrs[TIPC_NLA_BEARER]) 921 if (!info->attrs[TIPC_NLA_BEARER])
922 return -EINVAL; 922 return -EINVAL;
923 923
924 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX, 924 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
925 info->attrs[TIPC_NLA_BEARER], 925 info->attrs[TIPC_NLA_BEARER],
926 tipc_nl_bearer_policy, info->extack); 926 tipc_nl_bearer_policy, info->extack);
927 if (err) 927 if (err)
928 return err; 928 return err;
929 929
@@ -964,9 +964,9 @@ int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
964 if (!info->attrs[TIPC_NLA_BEARER]) 964 if (!info->attrs[TIPC_NLA_BEARER])
965 return -EINVAL; 965 return -EINVAL;
966 966
967 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX, 967 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
968 info->attrs[TIPC_NLA_BEARER], 968 info->attrs[TIPC_NLA_BEARER],
969 tipc_nl_bearer_policy, info->extack); 969 tipc_nl_bearer_policy, info->extack);
970 if (err) 970 if (err)
971 return err; 971 return err;
972 972
@@ -1033,14 +1033,14 @@ static int __tipc_nl_add_media(struct tipc_nl_msg *msg,
1033 if (!hdr) 1033 if (!hdr)
1034 return -EMSGSIZE; 1034 return -EMSGSIZE;
1035 1035
1036 attrs = nla_nest_start(msg->skb, TIPC_NLA_MEDIA); 1036 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_MEDIA);
1037 if (!attrs) 1037 if (!attrs)
1038 goto msg_full; 1038 goto msg_full;
1039 1039
1040 if (nla_put_string(msg->skb, TIPC_NLA_MEDIA_NAME, media->name)) 1040 if (nla_put_string(msg->skb, TIPC_NLA_MEDIA_NAME, media->name))
1041 goto attr_msg_full; 1041 goto attr_msg_full;
1042 1042
1043 prop = nla_nest_start(msg->skb, TIPC_NLA_MEDIA_PROP); 1043 prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_MEDIA_PROP);
1044 if (!prop) 1044 if (!prop)
1045 goto prop_msg_full; 1045 goto prop_msg_full;
1046 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, media->priority)) 1046 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, media->priority))
@@ -1107,9 +1107,9 @@ int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info)
1107 if (!info->attrs[TIPC_NLA_MEDIA]) 1107 if (!info->attrs[TIPC_NLA_MEDIA])
1108 return -EINVAL; 1108 return -EINVAL;
1109 1109
1110 err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX, 1110 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_MEDIA_MAX,
1111 info->attrs[TIPC_NLA_MEDIA], 1111 info->attrs[TIPC_NLA_MEDIA],
1112 tipc_nl_media_policy, info->extack); 1112 tipc_nl_media_policy, info->extack);
1113 if (err) 1113 if (err)
1114 return err; 1114 return err;
1115 1115
@@ -1155,9 +1155,9 @@ int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
1155 if (!info->attrs[TIPC_NLA_MEDIA]) 1155 if (!info->attrs[TIPC_NLA_MEDIA])
1156 return -EINVAL; 1156 return -EINVAL;
1157 1157
1158 err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX, 1158 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_MEDIA_MAX,
1159 info->attrs[TIPC_NLA_MEDIA], 1159 info->attrs[TIPC_NLA_MEDIA],
1160 tipc_nl_media_policy, info->extack); 1160 tipc_nl_media_policy, info->extack);
1161 1161
1162 if (!attrs[TIPC_NLA_MEDIA_NAME]) 1162 if (!attrs[TIPC_NLA_MEDIA_NAME])
1163 return -EINVAL; 1163 return -EINVAL;
diff --git a/net/tipc/core.c b/net/tipc/core.c
index 5b38f5164281..27cccd101ef6 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -43,6 +43,7 @@
43#include "net.h" 43#include "net.h"
44#include "socket.h" 44#include "socket.h"
45#include "bcast.h" 45#include "bcast.h"
46#include "node.h"
46 47
47#include <linux/module.h> 48#include <linux/module.h>
48 49
@@ -59,6 +60,7 @@ static int __net_init tipc_init_net(struct net *net)
59 tn->node_addr = 0; 60 tn->node_addr = 0;
60 tn->trial_addr = 0; 61 tn->trial_addr = 0;
61 tn->addr_trial_end = 0; 62 tn->addr_trial_end = 0;
63 tn->capabilities = TIPC_NODE_CAPABILITIES;
62 memset(tn->node_id, 0, sizeof(tn->node_id)); 64 memset(tn->node_id, 0, sizeof(tn->node_id));
63 memset(tn->node_id_string, 0, sizeof(tn->node_id_string)); 65 memset(tn->node_id_string, 0, sizeof(tn->node_id_string));
64 tn->mon_threshold = TIPC_DEF_MON_THRESHOLD; 66 tn->mon_threshold = TIPC_DEF_MON_THRESHOLD;
diff --git a/net/tipc/core.h b/net/tipc/core.h
index 8020a6c360ff..7a68e1b6a066 100644
--- a/net/tipc/core.h
+++ b/net/tipc/core.h
@@ -122,6 +122,9 @@ struct tipc_net {
122 /* Topology subscription server */ 122 /* Topology subscription server */
123 struct tipc_topsrv *topsrv; 123 struct tipc_topsrv *topsrv;
124 atomic_t subscription_count; 124 atomic_t subscription_count;
125
126 /* Cluster capabilities */
127 u16 capabilities;
125}; 128};
126 129
127static inline struct tipc_net *tipc_net(struct net *net) 130static inline struct tipc_net *tipc_net(struct net *net)
diff --git a/net/tipc/group.c b/net/tipc/group.c
index 63f39201e41e..992be6113676 100644
--- a/net/tipc/group.c
+++ b/net/tipc/group.c
@@ -917,7 +917,7 @@ void tipc_group_member_evt(struct tipc_group *grp,
917 917
918int tipc_group_fill_sock_diag(struct tipc_group *grp, struct sk_buff *skb) 918int tipc_group_fill_sock_diag(struct tipc_group *grp, struct sk_buff *skb)
919{ 919{
920 struct nlattr *group = nla_nest_start(skb, TIPC_NLA_SOCK_GROUP); 920 struct nlattr *group = nla_nest_start_noflag(skb, TIPC_NLA_SOCK_GROUP);
921 921
922 if (!group) 922 if (!group)
923 return -EMSGSIZE; 923 return -EMSGSIZE;
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 341ecd796aa4..f5cd986e1e50 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -151,6 +151,7 @@ struct tipc_link {
151 /* Failover/synch */ 151 /* Failover/synch */
152 u16 drop_point; 152 u16 drop_point;
153 struct sk_buff *failover_reasm_skb; 153 struct sk_buff *failover_reasm_skb;
154 struct sk_buff_head failover_deferdq;
154 155
155 /* Max packet negotiation */ 156 /* Max packet negotiation */
156 u16 mtu; 157 u16 mtu;
@@ -209,6 +210,7 @@ enum {
209}; 210};
210 211
211#define TIPC_BC_RETR_LIM msecs_to_jiffies(10) /* [ms] */ 212#define TIPC_BC_RETR_LIM msecs_to_jiffies(10) /* [ms] */
213#define TIPC_UC_RETR_TIME (jiffies + msecs_to_jiffies(1))
212 214
213/* 215/*
214 * Interval between NACKs when packets arrive out of order 216 * Interval between NACKs when packets arrive out of order
@@ -246,6 +248,10 @@ static int tipc_link_build_nack_msg(struct tipc_link *l,
246static void tipc_link_build_bc_init_msg(struct tipc_link *l, 248static void tipc_link_build_bc_init_msg(struct tipc_link *l,
247 struct sk_buff_head *xmitq); 249 struct sk_buff_head *xmitq);
248static bool tipc_link_release_pkts(struct tipc_link *l, u16 to); 250static bool tipc_link_release_pkts(struct tipc_link *l, u16 to);
251static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data);
252static void tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap,
253 struct tipc_gap_ack_blks *ga,
254 struct sk_buff_head *xmitq);
249 255
250/* 256/*
251 * Simple non-static link routines (i.e. referenced outside this file) 257 * Simple non-static link routines (i.e. referenced outside this file)
@@ -493,6 +499,7 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
493 __skb_queue_head_init(&l->transmq); 499 __skb_queue_head_init(&l->transmq);
494 __skb_queue_head_init(&l->backlogq); 500 __skb_queue_head_init(&l->backlogq);
495 __skb_queue_head_init(&l->deferdq); 501 __skb_queue_head_init(&l->deferdq);
502 __skb_queue_head_init(&l->failover_deferdq);
496 skb_queue_head_init(&l->wakeupq); 503 skb_queue_head_init(&l->wakeupq);
497 skb_queue_head_init(l->inputq); 504 skb_queue_head_init(l->inputq);
498 return true; 505 return true;
@@ -869,6 +876,8 @@ void tipc_link_reset(struct tipc_link *l)
869 __skb_queue_head_init(&list); 876 __skb_queue_head_init(&list);
870 877
871 l->in_session = false; 878 l->in_session = false;
879 /* Force re-synch of peer session number before establishing */
880 l->peer_session--;
872 l->session++; 881 l->session++;
873 l->mtu = l->advertised_mtu; 882 l->mtu = l->advertised_mtu;
874 883
@@ -883,6 +892,7 @@ void tipc_link_reset(struct tipc_link *l)
883 __skb_queue_purge(&l->transmq); 892 __skb_queue_purge(&l->transmq);
884 __skb_queue_purge(&l->deferdq); 893 __skb_queue_purge(&l->deferdq);
885 __skb_queue_purge(&l->backlogq); 894 __skb_queue_purge(&l->backlogq);
895 __skb_queue_purge(&l->failover_deferdq);
886 l->backlog[TIPC_LOW_IMPORTANCE].len = 0; 896 l->backlog[TIPC_LOW_IMPORTANCE].len = 0;
887 l->backlog[TIPC_MEDIUM_IMPORTANCE].len = 0; 897 l->backlog[TIPC_MEDIUM_IMPORTANCE].len = 0;
888 l->backlog[TIPC_HIGH_IMPORTANCE].len = 0; 898 l->backlog[TIPC_HIGH_IMPORTANCE].len = 0;
@@ -1154,34 +1164,14 @@ static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb,
1154 * Consumes buffer 1164 * Consumes buffer
1155 */ 1165 */
1156static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb, 1166static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb,
1157 struct sk_buff_head *inputq) 1167 struct sk_buff_head *inputq,
1168 struct sk_buff **reasm_skb)
1158{ 1169{
1159 struct tipc_msg *hdr = buf_msg(skb); 1170 struct tipc_msg *hdr = buf_msg(skb);
1160 struct sk_buff **reasm_skb = &l->reasm_buf;
1161 struct sk_buff *iskb; 1171 struct sk_buff *iskb;
1162 struct sk_buff_head tmpq; 1172 struct sk_buff_head tmpq;
1163 int usr = msg_user(hdr); 1173 int usr = msg_user(hdr);
1164 int rc = 0;
1165 int pos = 0; 1174 int pos = 0;
1166 int ipos = 0;
1167
1168 if (unlikely(usr == TUNNEL_PROTOCOL)) {
1169 if (msg_type(hdr) == SYNCH_MSG) {
1170 __skb_queue_purge(&l->deferdq);
1171 goto drop;
1172 }
1173 if (!tipc_msg_extract(skb, &iskb, &ipos))
1174 return rc;
1175 kfree_skb(skb);
1176 skb = iskb;
1177 hdr = buf_msg(skb);
1178 if (less(msg_seqno(hdr), l->drop_point))
1179 goto drop;
1180 if (tipc_data_input(l, skb, inputq))
1181 return rc;
1182 usr = msg_user(hdr);
1183 reasm_skb = &l->failover_reasm_skb;
1184 }
1185 1175
1186 if (usr == MSG_BUNDLER) { 1176 if (usr == MSG_BUNDLER) {
1187 skb_queue_head_init(&tmpq); 1177 skb_queue_head_init(&tmpq);
@@ -1206,11 +1196,66 @@ static int tipc_link_input(struct tipc_link *l, struct sk_buff *skb,
1206 tipc_link_bc_init_rcv(l->bc_rcvlink, hdr); 1196 tipc_link_bc_init_rcv(l->bc_rcvlink, hdr);
1207 tipc_bcast_unlock(l->net); 1197 tipc_bcast_unlock(l->net);
1208 } 1198 }
1209drop: 1199
1210 kfree_skb(skb); 1200 kfree_skb(skb);
1211 return 0; 1201 return 0;
1212} 1202}
1213 1203
1204/* tipc_link_tnl_rcv() - receive TUNNEL_PROTOCOL message, drop or process the
1205 * inner message along with the ones in the old link's
1206 * deferdq
1207 * @l: tunnel link
1208 * @skb: TUNNEL_PROTOCOL message
1209 * @inputq: queue to put messages ready for delivery
1210 */
1211static int tipc_link_tnl_rcv(struct tipc_link *l, struct sk_buff *skb,
1212 struct sk_buff_head *inputq)
1213{
1214 struct sk_buff **reasm_skb = &l->failover_reasm_skb;
1215 struct sk_buff_head *fdefq = &l->failover_deferdq;
1216 struct tipc_msg *hdr = buf_msg(skb);
1217 struct sk_buff *iskb;
1218 int ipos = 0;
1219 int rc = 0;
1220 u16 seqno;
1221
1222 /* SYNCH_MSG */
1223 if (msg_type(hdr) == SYNCH_MSG)
1224 goto drop;
1225
1226 /* FAILOVER_MSG */
1227 if (!tipc_msg_extract(skb, &iskb, &ipos)) {
1228 pr_warn_ratelimited("Cannot extract FAILOVER_MSG, defq: %d\n",
1229 skb_queue_len(fdefq));
1230 return rc;
1231 }
1232
1233 do {
1234 seqno = buf_seqno(iskb);
1235
1236 if (unlikely(less(seqno, l->drop_point))) {
1237 kfree_skb(iskb);
1238 continue;
1239 }
1240
1241 if (unlikely(seqno != l->drop_point)) {
1242 __tipc_skb_queue_sorted(fdefq, seqno, iskb);
1243 continue;
1244 }
1245
1246 l->drop_point++;
1247
1248 if (!tipc_data_input(l, iskb, inputq))
1249 rc |= tipc_link_input(l, iskb, inputq, reasm_skb);
1250 if (unlikely(rc))
1251 break;
1252 } while ((iskb = __tipc_skb_dequeue(fdefq, l->drop_point)));
1253
1254drop:
1255 kfree_skb(skb);
1256 return rc;
1257}
1258
1214static bool tipc_link_release_pkts(struct tipc_link *l, u16 acked) 1259static bool tipc_link_release_pkts(struct tipc_link *l, u16 acked)
1215{ 1260{
1216 bool released = false; 1261 bool released = false;
@@ -1226,6 +1271,106 @@ static bool tipc_link_release_pkts(struct tipc_link *l, u16 acked)
1226 return released; 1271 return released;
1227} 1272}
1228 1273
1274/* tipc_build_gap_ack_blks - build Gap ACK blocks
1275 * @l: tipc link that data have come with gaps in sequence if any
1276 * @data: data buffer to store the Gap ACK blocks after built
1277 *
1278 * returns the actual allocated memory size
1279 */
1280static u16 tipc_build_gap_ack_blks(struct tipc_link *l, void *data)
1281{
1282 struct sk_buff *skb = skb_peek(&l->deferdq);
1283 struct tipc_gap_ack_blks *ga = data;
1284 u16 len, expect, seqno = 0;
1285 u8 n = 0;
1286
1287 if (!skb)
1288 goto exit;
1289
1290 expect = buf_seqno(skb);
1291 skb_queue_walk(&l->deferdq, skb) {
1292 seqno = buf_seqno(skb);
1293 if (unlikely(more(seqno, expect))) {
1294 ga->gacks[n].ack = htons(expect - 1);
1295 ga->gacks[n].gap = htons(seqno - expect);
1296 if (++n >= MAX_GAP_ACK_BLKS) {
1297 pr_info_ratelimited("Too few Gap ACK blocks!\n");
1298 goto exit;
1299 }
1300 } else if (unlikely(less(seqno, expect))) {
1301 pr_warn("Unexpected skb in deferdq!\n");
1302 continue;
1303 }
1304 expect = seqno + 1;
1305 }
1306
1307 /* last block */
1308 ga->gacks[n].ack = htons(seqno);
1309 ga->gacks[n].gap = 0;
1310 n++;
1311
1312exit:
1313 len = tipc_gap_ack_blks_sz(n);
1314 ga->len = htons(len);
1315 ga->gack_cnt = n;
1316 return len;
1317}
1318
1319/* tipc_link_advance_transmq - advance TIPC link transmq queue by releasing
1320 * acked packets, also doing retransmissions if
1321 * gaps found
1322 * @l: tipc link with transmq queue to be advanced
1323 * @acked: seqno of last packet acked by peer without any gaps before
1324 * @gap: # of gap packets
1325 * @ga: buffer pointer to Gap ACK blocks from peer
1326 * @xmitq: queue for accumulating the retransmitted packets if any
1327 */
1328static void tipc_link_advance_transmq(struct tipc_link *l, u16 acked, u16 gap,
1329 struct tipc_gap_ack_blks *ga,
1330 struct sk_buff_head *xmitq)
1331{
1332 struct sk_buff *skb, *_skb, *tmp;
1333 struct tipc_msg *hdr;
1334 u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
1335 u16 ack = l->rcv_nxt - 1;
1336 u16 seqno;
1337 u16 n = 0;
1338
1339 skb_queue_walk_safe(&l->transmq, skb, tmp) {
1340 seqno = buf_seqno(skb);
1341
1342next_gap_ack:
1343 if (less_eq(seqno, acked)) {
1344 /* release skb */
1345 __skb_unlink(skb, &l->transmq);
1346 kfree_skb(skb);
1347 } else if (less_eq(seqno, acked + gap)) {
1348 /* retransmit skb */
1349 if (time_before(jiffies, TIPC_SKB_CB(skb)->nxt_retr))
1350 continue;
1351 TIPC_SKB_CB(skb)->nxt_retr = TIPC_UC_RETR_TIME;
1352
1353 _skb = __pskb_copy(skb, MIN_H_SIZE, GFP_ATOMIC);
1354 if (!_skb)
1355 continue;
1356 hdr = buf_msg(_skb);
1357 msg_set_ack(hdr, ack);
1358 msg_set_bcast_ack(hdr, bc_ack);
1359 _skb->priority = TC_PRIO_CONTROL;
1360 __skb_queue_tail(xmitq, _skb);
1361 l->stats.retransmitted++;
1362 } else {
1363 /* retry with Gap ACK blocks if any */
1364 if (!ga || n >= ga->gack_cnt)
1365 break;
1366 acked = ntohs(ga->gacks[n].ack);
1367 gap = ntohs(ga->gacks[n].gap);
1368 n++;
1369 goto next_gap_ack;
1370 }
1371 }
1372}
1373
1229/* tipc_link_build_state_msg: prepare link state message for transmission 1374/* tipc_link_build_state_msg: prepare link state message for transmission
1230 * 1375 *
1231 * Note that sending of broadcast ack is coordinated among nodes, to reduce 1376 * Note that sending of broadcast ack is coordinated among nodes, to reduce
@@ -1280,6 +1425,7 @@ static int tipc_link_build_nack_msg(struct tipc_link *l,
1280 struct sk_buff_head *xmitq) 1425 struct sk_buff_head *xmitq)
1281{ 1426{
1282 u32 def_cnt = ++l->stats.deferred_recv; 1427 u32 def_cnt = ++l->stats.deferred_recv;
1428 u32 defq_len = skb_queue_len(&l->deferdq);
1283 int match1, match2; 1429 int match1, match2;
1284 1430
1285 if (link_is_bc_rcvlink(l)) { 1431 if (link_is_bc_rcvlink(l)) {
@@ -1290,7 +1436,7 @@ static int tipc_link_build_nack_msg(struct tipc_link *l,
1290 return 0; 1436 return 0;
1291 } 1437 }
1292 1438
1293 if ((skb_queue_len(&l->deferdq) == 1) || !(def_cnt % TIPC_NACK_INTV)) 1439 if (defq_len >= 3 && !((defq_len - 3) % 16))
1294 tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq); 1440 tipc_link_build_proto_msg(l, STATE_MSG, 0, 0, 0, 0, 0, xmitq);
1295 return 0; 1441 return 0;
1296} 1442}
@@ -1304,29 +1450,29 @@ int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb,
1304 struct sk_buff_head *xmitq) 1450 struct sk_buff_head *xmitq)
1305{ 1451{
1306 struct sk_buff_head *defq = &l->deferdq; 1452 struct sk_buff_head *defq = &l->deferdq;
1307 struct tipc_msg *hdr; 1453 struct tipc_msg *hdr = buf_msg(skb);
1308 u16 seqno, rcv_nxt, win_lim; 1454 u16 seqno, rcv_nxt, win_lim;
1309 int rc = 0; 1455 int rc = 0;
1310 1456
1457 /* Verify and update link state */
1458 if (unlikely(msg_user(hdr) == LINK_PROTOCOL))
1459 return tipc_link_proto_rcv(l, skb, xmitq);
1460
1461 /* Don't send probe at next timeout expiration */
1462 l->silent_intv_cnt = 0;
1463
1311 do { 1464 do {
1312 hdr = buf_msg(skb); 1465 hdr = buf_msg(skb);
1313 seqno = msg_seqno(hdr); 1466 seqno = msg_seqno(hdr);
1314 rcv_nxt = l->rcv_nxt; 1467 rcv_nxt = l->rcv_nxt;
1315 win_lim = rcv_nxt + TIPC_MAX_LINK_WIN; 1468 win_lim = rcv_nxt + TIPC_MAX_LINK_WIN;
1316 1469
1317 /* Verify and update link state */
1318 if (unlikely(msg_user(hdr) == LINK_PROTOCOL))
1319 return tipc_link_proto_rcv(l, skb, xmitq);
1320
1321 if (unlikely(!link_is_up(l))) { 1470 if (unlikely(!link_is_up(l))) {
1322 if (l->state == LINK_ESTABLISHING) 1471 if (l->state == LINK_ESTABLISHING)
1323 rc = TIPC_LINK_UP_EVT; 1472 rc = TIPC_LINK_UP_EVT;
1324 goto drop; 1473 goto drop;
1325 } 1474 }
1326 1475
1327 /* Don't send probe at next timeout expiration */
1328 l->silent_intv_cnt = 0;
1329
1330 /* Drop if outside receive window */ 1476 /* Drop if outside receive window */
1331 if (unlikely(less(seqno, rcv_nxt) || more(seqno, win_lim))) { 1477 if (unlikely(less(seqno, rcv_nxt) || more(seqno, win_lim))) {
1332 l->stats.duplicates++; 1478 l->stats.duplicates++;
@@ -1351,13 +1497,16 @@ int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb,
1351 /* Deliver packet */ 1497 /* Deliver packet */
1352 l->rcv_nxt++; 1498 l->rcv_nxt++;
1353 l->stats.recv_pkts++; 1499 l->stats.recv_pkts++;
1354 if (!tipc_data_input(l, skb, l->inputq)) 1500
1355 rc |= tipc_link_input(l, skb, l->inputq); 1501 if (unlikely(msg_user(hdr) == TUNNEL_PROTOCOL))
1502 rc |= tipc_link_tnl_rcv(l, skb, l->inputq);
1503 else if (!tipc_data_input(l, skb, l->inputq))
1504 rc |= tipc_link_input(l, skb, l->inputq, &l->reasm_buf);
1356 if (unlikely(++l->rcv_unacked >= TIPC_MIN_LINK_WIN)) 1505 if (unlikely(++l->rcv_unacked >= TIPC_MIN_LINK_WIN))
1357 rc |= tipc_link_build_state_msg(l, xmitq); 1506 rc |= tipc_link_build_state_msg(l, xmitq);
1358 if (unlikely(rc & ~TIPC_LINK_SND_STATE)) 1507 if (unlikely(rc & ~TIPC_LINK_SND_STATE))
1359 break; 1508 break;
1360 } while ((skb = __skb_dequeue(defq))); 1509 } while ((skb = __tipc_skb_dequeue(defq, l->rcv_nxt)));
1361 1510
1362 return rc; 1511 return rc;
1363drop: 1512drop:
@@ -1378,6 +1527,7 @@ static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
1378 struct tipc_mon_state *mstate = &l->mon_state; 1527 struct tipc_mon_state *mstate = &l->mon_state;
1379 int dlen = 0; 1528 int dlen = 0;
1380 void *data; 1529 void *data;
1530 u16 glen = 0;
1381 1531
1382 /* Don't send protocol message during reset or link failover */ 1532 /* Don't send protocol message during reset or link failover */
1383 if (tipc_link_is_blocked(l)) 1533 if (tipc_link_is_blocked(l))
@@ -1390,8 +1540,8 @@ static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
1390 rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt; 1540 rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
1391 1541
1392 skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE, 1542 skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE,
1393 tipc_max_domain_size, l->addr, 1543 tipc_max_domain_size + MAX_GAP_ACK_BLKS_SZ,
1394 tipc_own_addr(l->net), 0, 0, 0); 1544 l->addr, tipc_own_addr(l->net), 0, 0, 0);
1395 if (!skb) 1545 if (!skb)
1396 return; 1546 return;
1397 1547
@@ -1418,9 +1568,11 @@ static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
1418 msg_set_bc_gap(hdr, link_bc_rcv_gap(bcl)); 1568 msg_set_bc_gap(hdr, link_bc_rcv_gap(bcl));
1419 msg_set_probe(hdr, probe); 1569 msg_set_probe(hdr, probe);
1420 msg_set_is_keepalive(hdr, probe || probe_reply); 1570 msg_set_is_keepalive(hdr, probe || probe_reply);
1421 tipc_mon_prep(l->net, data, &dlen, mstate, l->bearer_id); 1571 if (l->peer_caps & TIPC_GAP_ACK_BLOCK)
1422 msg_set_size(hdr, INT_H_SIZE + dlen); 1572 glen = tipc_build_gap_ack_blks(l, data);
1423 skb_trim(skb, INT_H_SIZE + dlen); 1573 tipc_mon_prep(l->net, data + glen, &dlen, mstate, l->bearer_id);
1574 msg_set_size(hdr, INT_H_SIZE + glen + dlen);
1575 skb_trim(skb, INT_H_SIZE + glen + dlen);
1424 l->stats.sent_states++; 1576 l->stats.sent_states++;
1425 l->rcv_unacked = 0; 1577 l->rcv_unacked = 0;
1426 } else { 1578 } else {
@@ -1479,6 +1631,7 @@ void tipc_link_create_dummy_tnl_msg(struct tipc_link *l,
1479void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl, 1631void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
1480 int mtyp, struct sk_buff_head *xmitq) 1632 int mtyp, struct sk_buff_head *xmitq)
1481{ 1633{
1634 struct sk_buff_head *fdefq = &tnl->failover_deferdq;
1482 struct sk_buff *skb, *tnlskb; 1635 struct sk_buff *skb, *tnlskb;
1483 struct tipc_msg *hdr, tnlhdr; 1636 struct tipc_msg *hdr, tnlhdr;
1484 struct sk_buff_head *queue = &l->transmq; 1637 struct sk_buff_head *queue = &l->transmq;
@@ -1506,7 +1659,11 @@ void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
1506 /* Initialize reusable tunnel packet header */ 1659 /* Initialize reusable tunnel packet header */
1507 tipc_msg_init(tipc_own_addr(l->net), &tnlhdr, TUNNEL_PROTOCOL, 1660 tipc_msg_init(tipc_own_addr(l->net), &tnlhdr, TUNNEL_PROTOCOL,
1508 mtyp, INT_H_SIZE, l->addr); 1661 mtyp, INT_H_SIZE, l->addr);
1509 pktcnt = skb_queue_len(&l->transmq) + skb_queue_len(&l->backlogq); 1662 if (mtyp == SYNCH_MSG)
1663 pktcnt = l->snd_nxt - buf_seqno(skb_peek(&l->transmq));
1664 else
1665 pktcnt = skb_queue_len(&l->transmq);
1666 pktcnt += skb_queue_len(&l->backlogq);
1510 msg_set_msgcnt(&tnlhdr, pktcnt); 1667 msg_set_msgcnt(&tnlhdr, pktcnt);
1511 msg_set_bearer_id(&tnlhdr, l->peer_bearer_id); 1668 msg_set_bearer_id(&tnlhdr, l->peer_bearer_id);
1512tnl: 1669tnl:
@@ -1537,6 +1694,49 @@ tnl:
1537 tnl->drop_point = l->rcv_nxt; 1694 tnl->drop_point = l->rcv_nxt;
1538 tnl->failover_reasm_skb = l->reasm_buf; 1695 tnl->failover_reasm_skb = l->reasm_buf;
1539 l->reasm_buf = NULL; 1696 l->reasm_buf = NULL;
1697
1698 /* Failover the link's deferdq */
1699 if (unlikely(!skb_queue_empty(fdefq))) {
1700 pr_warn("Link failover deferdq not empty: %d!\n",
1701 skb_queue_len(fdefq));
1702 __skb_queue_purge(fdefq);
1703 }
1704 skb_queue_splice_init(&l->deferdq, fdefq);
1705 }
1706}
1707
1708/**
1709 * tipc_link_failover_prepare() - prepare tnl for link failover
1710 *
1711 * This is a special version of the precursor - tipc_link_tnl_prepare(),
1712 * see the tipc_node_link_failover() for details
1713 *
1714 * @l: failover link
1715 * @tnl: tunnel link
1716 * @xmitq: queue for messages to be xmited
1717 */
1718void tipc_link_failover_prepare(struct tipc_link *l, struct tipc_link *tnl,
1719 struct sk_buff_head *xmitq)
1720{
1721 struct sk_buff_head *fdefq = &tnl->failover_deferdq;
1722
1723 tipc_link_create_dummy_tnl_msg(tnl, xmitq);
1724
1725 /* This failover link enpoint was never established before,
1726 * so it has not received anything from peer.
1727 * Otherwise, it must be a normal failover situation or the
1728 * node has entered SELF_DOWN_PEER_LEAVING and both peer nodes
1729 * would have to start over from scratch instead.
1730 */
1731 WARN_ON(l && tipc_link_is_up(l));
1732 tnl->drop_point = 1;
1733 tnl->failover_reasm_skb = NULL;
1734
1735 /* Initiate the link's failover deferdq */
1736 if (unlikely(!skb_queue_empty(fdefq))) {
1737 pr_warn("Link failover deferdq not empty: %d!\n",
1738 skb_queue_len(fdefq));
1739 __skb_queue_purge(fdefq);
1540 } 1740 }
1541} 1741}
1542 1742
@@ -1590,6 +1790,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
1590 struct sk_buff_head *xmitq) 1790 struct sk_buff_head *xmitq)
1591{ 1791{
1592 struct tipc_msg *hdr = buf_msg(skb); 1792 struct tipc_msg *hdr = buf_msg(skb);
1793 struct tipc_gap_ack_blks *ga = NULL;
1593 u16 rcvgap = 0; 1794 u16 rcvgap = 0;
1594 u16 ack = msg_ack(hdr); 1795 u16 ack = msg_ack(hdr);
1595 u16 gap = msg_seq_gap(hdr); 1796 u16 gap = msg_seq_gap(hdr);
@@ -1600,6 +1801,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
1600 u16 dlen = msg_data_sz(hdr); 1801 u16 dlen = msg_data_sz(hdr);
1601 int mtyp = msg_type(hdr); 1802 int mtyp = msg_type(hdr);
1602 bool reply = msg_probe(hdr); 1803 bool reply = msg_probe(hdr);
1804 u16 glen = 0;
1603 void *data; 1805 void *data;
1604 char *if_name; 1806 char *if_name;
1605 int rc = 0; 1807 int rc = 0;
@@ -1697,7 +1899,17 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
1697 rc = TIPC_LINK_UP_EVT; 1899 rc = TIPC_LINK_UP_EVT;
1698 break; 1900 break;
1699 } 1901 }
1700 tipc_mon_rcv(l->net, data, dlen, l->addr, 1902
1903 /* Receive Gap ACK blocks from peer if any */
1904 if (l->peer_caps & TIPC_GAP_ACK_BLOCK) {
1905 ga = (struct tipc_gap_ack_blks *)data;
1906 glen = ntohs(ga->len);
1907 /* sanity check: if failed, ignore Gap ACK blocks */
1908 if (glen != tipc_gap_ack_blks_sz(ga->gack_cnt))
1909 ga = NULL;
1910 }
1911
1912 tipc_mon_rcv(l->net, data + glen, dlen - glen, l->addr,
1701 &l->mon_state, l->bearer_id); 1913 &l->mon_state, l->bearer_id);
1702 1914
1703 /* Send NACK if peer has sent pkts we haven't received yet */ 1915 /* Send NACK if peer has sent pkts we haven't received yet */
@@ -1706,13 +1918,12 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
1706 if (rcvgap || reply) 1918 if (rcvgap || reply)
1707 tipc_link_build_proto_msg(l, STATE_MSG, 0, reply, 1919 tipc_link_build_proto_msg(l, STATE_MSG, 0, reply,
1708 rcvgap, 0, 0, xmitq); 1920 rcvgap, 0, 0, xmitq);
1709 tipc_link_release_pkts(l, ack); 1921
1922 tipc_link_advance_transmq(l, ack, gap, ga, xmitq);
1710 1923
1711 /* If NACK, retransmit will now start at right position */ 1924 /* If NACK, retransmit will now start at right position */
1712 if (gap) { 1925 if (gap)
1713 rc = tipc_link_retrans(l, l, ack + 1, ack + gap, xmitq);
1714 l->stats.recv_nacks++; 1926 l->stats.recv_nacks++;
1715 }
1716 1927
1717 tipc_link_advance_backlog(l, xmitq); 1928 tipc_link_advance_backlog(l, xmitq);
1718 if (unlikely(!skb_queue_empty(&l->wakeupq))) 1929 if (unlikely(!skb_queue_empty(&l->wakeupq)))
@@ -1972,8 +2183,8 @@ int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[])
1972{ 2183{
1973 int err; 2184 int err;
1974 2185
1975 err = nla_parse_nested(props, TIPC_NLA_PROP_MAX, prop, 2186 err = nla_parse_nested_deprecated(props, TIPC_NLA_PROP_MAX, prop,
1976 tipc_nl_prop_policy, NULL); 2187 tipc_nl_prop_policy, NULL);
1977 if (err) 2188 if (err)
1978 return err; 2189 return err;
1979 2190
@@ -2052,7 +2263,7 @@ static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
2052 (s->accu_queue_sz / s->queue_sz_counts) : 0} 2263 (s->accu_queue_sz / s->queue_sz_counts) : 0}
2053 }; 2264 };
2054 2265
2055 stats = nla_nest_start(skb, TIPC_NLA_LINK_STATS); 2266 stats = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS);
2056 if (!stats) 2267 if (!stats)
2057 return -EMSGSIZE; 2268 return -EMSGSIZE;
2058 2269
@@ -2084,7 +2295,7 @@ int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
2084 if (!hdr) 2295 if (!hdr)
2085 return -EMSGSIZE; 2296 return -EMSGSIZE;
2086 2297
2087 attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK); 2298 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK);
2088 if (!attrs) 2299 if (!attrs)
2089 goto msg_full; 2300 goto msg_full;
2090 2301
@@ -2106,7 +2317,7 @@ int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
2106 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE)) 2317 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_ACTIVE))
2107 goto attr_msg_full; 2318 goto attr_msg_full;
2108 2319
2109 prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP); 2320 prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP);
2110 if (!prop) 2321 if (!prop)
2111 goto attr_msg_full; 2322 goto attr_msg_full;
2112 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority)) 2323 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, link->priority))
@@ -2173,7 +2384,7 @@ static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb,
2173 (stats->accu_queue_sz / stats->queue_sz_counts) : 0} 2384 (stats->accu_queue_sz / stats->queue_sz_counts) : 0}
2174 }; 2385 };
2175 2386
2176 nest = nla_nest_start(skb, TIPC_NLA_LINK_STATS); 2387 nest = nla_nest_start_noflag(skb, TIPC_NLA_LINK_STATS);
2177 if (!nest) 2388 if (!nest)
2178 return -EMSGSIZE; 2389 return -EMSGSIZE;
2179 2390
@@ -2197,6 +2408,8 @@ int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
2197 struct nlattr *attrs; 2408 struct nlattr *attrs;
2198 struct nlattr *prop; 2409 struct nlattr *prop;
2199 struct tipc_net *tn = net_generic(net, tipc_net_id); 2410 struct tipc_net *tn = net_generic(net, tipc_net_id);
2411 u32 bc_mode = tipc_bcast_get_broadcast_mode(net);
2412 u32 bc_ratio = tipc_bcast_get_broadcast_ratio(net);
2200 struct tipc_link *bcl = tn->bcl; 2413 struct tipc_link *bcl = tn->bcl;
2201 2414
2202 if (!bcl) 2415 if (!bcl)
@@ -2211,7 +2424,7 @@ int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
2211 return -EMSGSIZE; 2424 return -EMSGSIZE;
2212 } 2425 }
2213 2426
2214 attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK); 2427 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK);
2215 if (!attrs) 2428 if (!attrs)
2216 goto msg_full; 2429 goto msg_full;
2217 2430
@@ -2228,11 +2441,17 @@ int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
2228 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, 0)) 2441 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, 0))
2229 goto attr_msg_full; 2442 goto attr_msg_full;
2230 2443
2231 prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP); 2444 prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_LINK_PROP);
2232 if (!prop) 2445 if (!prop)
2233 goto attr_msg_full; 2446 goto attr_msg_full;
2234 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->window)) 2447 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->window))
2235 goto prop_msg_full; 2448 goto prop_msg_full;
2449 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST, bc_mode))
2450 goto prop_msg_full;
2451 if (bc_mode & BCLINK_MODE_SEL)
2452 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_BROADCAST_RATIO,
2453 bc_ratio))
2454 goto prop_msg_full;
2236 nla_nest_end(msg->skb, prop); 2455 nla_nest_end(msg->skb, prop);
2237 2456
2238 err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats); 2457 err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats);
diff --git a/net/tipc/link.h b/net/tipc/link.h
index 8439e0ee53a8..adcad65e761c 100644
--- a/net/tipc/link.h
+++ b/net/tipc/link.h
@@ -90,6 +90,8 @@ void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
90 int mtyp, struct sk_buff_head *xmitq); 90 int mtyp, struct sk_buff_head *xmitq);
91void tipc_link_create_dummy_tnl_msg(struct tipc_link *tnl, 91void tipc_link_create_dummy_tnl_msg(struct tipc_link *tnl,
92 struct sk_buff_head *xmitq); 92 struct sk_buff_head *xmitq);
93void tipc_link_failover_prepare(struct tipc_link *l, struct tipc_link *tnl,
94 struct sk_buff_head *xmitq);
93void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq); 95void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq);
94int tipc_link_fsm_evt(struct tipc_link *l, int evt); 96int tipc_link_fsm_evt(struct tipc_link *l, int evt);
95bool tipc_link_is_up(struct tipc_link *l); 97bool tipc_link_is_up(struct tipc_link *l);
diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c
index 67f69389ec17..6a6eae88442f 100644
--- a/net/tipc/monitor.c
+++ b/net/tipc/monitor.c
@@ -696,7 +696,7 @@ static int __tipc_nl_add_monitor_peer(struct tipc_peer *peer,
696 if (!hdr) 696 if (!hdr)
697 return -EMSGSIZE; 697 return -EMSGSIZE;
698 698
699 attrs = nla_nest_start(msg->skb, TIPC_NLA_MON_PEER); 699 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_MON_PEER);
700 if (!attrs) 700 if (!attrs)
701 goto msg_full; 701 goto msg_full;
702 702
@@ -785,7 +785,7 @@ int __tipc_nl_add_monitor(struct net *net, struct tipc_nl_msg *msg,
785 if (!hdr) 785 if (!hdr)
786 return -EMSGSIZE; 786 return -EMSGSIZE;
787 787
788 attrs = nla_nest_start(msg->skb, TIPC_NLA_MON); 788 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_MON);
789 if (!attrs) 789 if (!attrs)
790 goto msg_full; 790 goto msg_full;
791 791
diff --git a/net/tipc/msg.h b/net/tipc/msg.h
index d7e4b8b93f9d..8de02ad6e352 100644
--- a/net/tipc/msg.h
+++ b/net/tipc/msg.h
@@ -117,6 +117,37 @@ struct tipc_msg {
117 __be32 hdr[15]; 117 __be32 hdr[15];
118}; 118};
119 119
120/* struct tipc_gap_ack - TIPC Gap ACK block
121 * @ack: seqno of the last consecutive packet in link deferdq
122 * @gap: number of gap packets since the last ack
123 *
124 * E.g:
125 * link deferdq: 1 2 3 4 10 11 13 14 15 20
126 * --> Gap ACK blocks: <4, 5>, <11, 1>, <15, 4>, <20, 0>
127 */
128struct tipc_gap_ack {
129 __be16 ack;
130 __be16 gap;
131};
132
133/* struct tipc_gap_ack_blks
134 * @len: actual length of the record
135 * @gack_cnt: number of Gap ACK blocks in the record
136 * @gacks: array of Gap ACK blocks
137 */
138struct tipc_gap_ack_blks {
139 __be16 len;
140 u8 gack_cnt;
141 u8 reserved;
142 struct tipc_gap_ack gacks[];
143};
144
145#define tipc_gap_ack_blks_sz(n) (sizeof(struct tipc_gap_ack_blks) + \
146 sizeof(struct tipc_gap_ack) * (n))
147
148#define MAX_GAP_ACK_BLKS 32
149#define MAX_GAP_ACK_BLKS_SZ tipc_gap_ack_blks_sz(MAX_GAP_ACK_BLKS)
150
120static inline struct tipc_msg *buf_msg(struct sk_buff *skb) 151static inline struct tipc_msg *buf_msg(struct sk_buff *skb)
121{ 152{
122 return (struct tipc_msg *)skb->data; 153 return (struct tipc_msg *)skb->data;
@@ -257,6 +288,16 @@ static inline void msg_set_src_droppable(struct tipc_msg *m, u32 d)
257 msg_set_bits(m, 0, 18, 1, d); 288 msg_set_bits(m, 0, 18, 1, d);
258} 289}
259 290
291static inline bool msg_is_rcast(struct tipc_msg *m)
292{
293 return msg_bits(m, 0, 18, 0x1);
294}
295
296static inline void msg_set_is_rcast(struct tipc_msg *m, bool d)
297{
298 msg_set_bits(m, 0, 18, 0x1, d);
299}
300
260static inline void msg_set_size(struct tipc_msg *m, u32 sz) 301static inline void msg_set_size(struct tipc_msg *m, u32 sz)
261{ 302{
262 m->hdr[0] = htonl((msg_word(m, 0) & ~0x1ffff) | sz); 303 m->hdr[0] = htonl((msg_word(m, 0) & ~0x1ffff) | sz);
@@ -1110,4 +1151,25 @@ static inline void tipc_skb_queue_splice_tail_init(struct sk_buff_head *list,
1110 tipc_skb_queue_splice_tail(&tmp, head); 1151 tipc_skb_queue_splice_tail(&tmp, head);
1111} 1152}
1112 1153
1154/* __tipc_skb_dequeue() - dequeue the head skb according to expected seqno
1155 * @list: list to be dequeued from
1156 * @seqno: seqno of the expected msg
1157 *
1158 * returns skb dequeued from the list if its seqno is less than or equal to
1159 * the expected one, otherwise the skb is still hold
1160 *
1161 * Note: must be used with appropriate locks held only
1162 */
1163static inline struct sk_buff *__tipc_skb_dequeue(struct sk_buff_head *list,
1164 u16 seqno)
1165{
1166 struct sk_buff *skb = skb_peek(list);
1167
1168 if (skb && less_eq(buf_seqno(skb), seqno)) {
1169 __skb_unlink(skb, list);
1170 return skb;
1171 }
1172 return NULL;
1173}
1174
1113#endif 1175#endif
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index bff241f03525..66a65c2cdb23 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -829,11 +829,11 @@ static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg,
829 if (!hdr) 829 if (!hdr)
830 return -EMSGSIZE; 830 return -EMSGSIZE;
831 831
832 attrs = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE); 832 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_NAME_TABLE);
833 if (!attrs) 833 if (!attrs)
834 goto msg_full; 834 goto msg_full;
835 835
836 b = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE_PUBL); 836 b = nla_nest_start_noflag(msg->skb, TIPC_NLA_NAME_TABLE_PUBL);
837 if (!b) 837 if (!b)
838 goto attr_msg_full; 838 goto attr_msg_full;
839 839
@@ -909,7 +909,8 @@ static int tipc_nl_service_list(struct net *net, struct tipc_nl_msg *msg,
909 for (; i < TIPC_NAMETBL_SIZE; i++) { 909 for (; i < TIPC_NAMETBL_SIZE; i++) {
910 head = &tn->nametbl->services[i]; 910 head = &tn->nametbl->services[i];
911 911
912 if (*last_type) { 912 if (*last_type ||
913 (!i && *last_key && (*last_lower == *last_key))) {
913 service = tipc_service_find(net, *last_type); 914 service = tipc_service_find(net, *last_type);
914 if (!service) 915 if (!service)
915 return -EPIPE; 916 return -EPIPE;
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 7ce1e86b024f..85707c185360 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -187,7 +187,7 @@ static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
187 if (!hdr) 187 if (!hdr)
188 return -EMSGSIZE; 188 return -EMSGSIZE;
189 189
190 attrs = nla_nest_start(msg->skb, TIPC_NLA_NET); 190 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_NET);
191 if (!attrs) 191 if (!attrs)
192 goto msg_full; 192 goto msg_full;
193 193
@@ -245,9 +245,9 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
245 if (!info->attrs[TIPC_NLA_NET]) 245 if (!info->attrs[TIPC_NLA_NET])
246 return -EINVAL; 246 return -EINVAL;
247 247
248 err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX, 248 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_NET_MAX,
249 info->attrs[TIPC_NLA_NET], tipc_nl_net_policy, 249 info->attrs[TIPC_NLA_NET],
250 info->extack); 250 tipc_nl_net_policy, info->extack);
251 251
252 if (err) 252 if (err)
253 return err; 253 return err;
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index 99ee419210ba..99bd166bccec 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -110,7 +110,9 @@ const struct nla_policy tipc_nl_prop_policy[TIPC_NLA_PROP_MAX + 1] = {
110 [TIPC_NLA_PROP_UNSPEC] = { .type = NLA_UNSPEC }, 110 [TIPC_NLA_PROP_UNSPEC] = { .type = NLA_UNSPEC },
111 [TIPC_NLA_PROP_PRIO] = { .type = NLA_U32 }, 111 [TIPC_NLA_PROP_PRIO] = { .type = NLA_U32 },
112 [TIPC_NLA_PROP_TOL] = { .type = NLA_U32 }, 112 [TIPC_NLA_PROP_TOL] = { .type = NLA_U32 },
113 [TIPC_NLA_PROP_WIN] = { .type = NLA_U32 } 113 [TIPC_NLA_PROP_WIN] = { .type = NLA_U32 },
114 [TIPC_NLA_PROP_BROADCAST] = { .type = NLA_U32 },
115 [TIPC_NLA_PROP_BROADCAST_RATIO] = { .type = NLA_U32 }
114}; 116};
115 117
116const struct nla_policy tipc_nl_bearer_policy[TIPC_NLA_BEARER_MAX + 1] = { 118const struct nla_policy tipc_nl_bearer_policy[TIPC_NLA_BEARER_MAX + 1] = {
@@ -141,115 +143,115 @@ const struct nla_policy tipc_nl_udp_policy[TIPC_NLA_UDP_MAX + 1] = {
141static const struct genl_ops tipc_genl_v2_ops[] = { 143static const struct genl_ops tipc_genl_v2_ops[] = {
142 { 144 {
143 .cmd = TIPC_NL_BEARER_DISABLE, 145 .cmd = TIPC_NL_BEARER_DISABLE,
146 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
144 .doit = tipc_nl_bearer_disable, 147 .doit = tipc_nl_bearer_disable,
145 .policy = tipc_nl_policy,
146 }, 148 },
147 { 149 {
148 .cmd = TIPC_NL_BEARER_ENABLE, 150 .cmd = TIPC_NL_BEARER_ENABLE,
151 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
149 .doit = tipc_nl_bearer_enable, 152 .doit = tipc_nl_bearer_enable,
150 .policy = tipc_nl_policy,
151 }, 153 },
152 { 154 {
153 .cmd = TIPC_NL_BEARER_GET, 155 .cmd = TIPC_NL_BEARER_GET,
156 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
154 .doit = tipc_nl_bearer_get, 157 .doit = tipc_nl_bearer_get,
155 .dumpit = tipc_nl_bearer_dump, 158 .dumpit = tipc_nl_bearer_dump,
156 .policy = tipc_nl_policy,
157 }, 159 },
158 { 160 {
159 .cmd = TIPC_NL_BEARER_ADD, 161 .cmd = TIPC_NL_BEARER_ADD,
162 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
160 .doit = tipc_nl_bearer_add, 163 .doit = tipc_nl_bearer_add,
161 .policy = tipc_nl_policy,
162 }, 164 },
163 { 165 {
164 .cmd = TIPC_NL_BEARER_SET, 166 .cmd = TIPC_NL_BEARER_SET,
167 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
165 .doit = tipc_nl_bearer_set, 168 .doit = tipc_nl_bearer_set,
166 .policy = tipc_nl_policy,
167 }, 169 },
168 { 170 {
169 .cmd = TIPC_NL_SOCK_GET, 171 .cmd = TIPC_NL_SOCK_GET,
172 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
170 .start = tipc_dump_start, 173 .start = tipc_dump_start,
171 .dumpit = tipc_nl_sk_dump, 174 .dumpit = tipc_nl_sk_dump,
172 .done = tipc_dump_done, 175 .done = tipc_dump_done,
173 .policy = tipc_nl_policy,
174 }, 176 },
175 { 177 {
176 .cmd = TIPC_NL_PUBL_GET, 178 .cmd = TIPC_NL_PUBL_GET,
179 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
177 .dumpit = tipc_nl_publ_dump, 180 .dumpit = tipc_nl_publ_dump,
178 .policy = tipc_nl_policy,
179 }, 181 },
180 { 182 {
181 .cmd = TIPC_NL_LINK_GET, 183 .cmd = TIPC_NL_LINK_GET,
184 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
182 .doit = tipc_nl_node_get_link, 185 .doit = tipc_nl_node_get_link,
183 .dumpit = tipc_nl_node_dump_link, 186 .dumpit = tipc_nl_node_dump_link,
184 .policy = tipc_nl_policy,
185 }, 187 },
186 { 188 {
187 .cmd = TIPC_NL_LINK_SET, 189 .cmd = TIPC_NL_LINK_SET,
190 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
188 .doit = tipc_nl_node_set_link, 191 .doit = tipc_nl_node_set_link,
189 .policy = tipc_nl_policy,
190 }, 192 },
191 { 193 {
192 .cmd = TIPC_NL_LINK_RESET_STATS, 194 .cmd = TIPC_NL_LINK_RESET_STATS,
195 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
193 .doit = tipc_nl_node_reset_link_stats, 196 .doit = tipc_nl_node_reset_link_stats,
194 .policy = tipc_nl_policy,
195 }, 197 },
196 { 198 {
197 .cmd = TIPC_NL_MEDIA_GET, 199 .cmd = TIPC_NL_MEDIA_GET,
200 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
198 .doit = tipc_nl_media_get, 201 .doit = tipc_nl_media_get,
199 .dumpit = tipc_nl_media_dump, 202 .dumpit = tipc_nl_media_dump,
200 .policy = tipc_nl_policy,
201 }, 203 },
202 { 204 {
203 .cmd = TIPC_NL_MEDIA_SET, 205 .cmd = TIPC_NL_MEDIA_SET,
206 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
204 .doit = tipc_nl_media_set, 207 .doit = tipc_nl_media_set,
205 .policy = tipc_nl_policy,
206 }, 208 },
207 { 209 {
208 .cmd = TIPC_NL_NODE_GET, 210 .cmd = TIPC_NL_NODE_GET,
211 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
209 .dumpit = tipc_nl_node_dump, 212 .dumpit = tipc_nl_node_dump,
210 .policy = tipc_nl_policy,
211 }, 213 },
212 { 214 {
213 .cmd = TIPC_NL_NET_GET, 215 .cmd = TIPC_NL_NET_GET,
216 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
214 .dumpit = tipc_nl_net_dump, 217 .dumpit = tipc_nl_net_dump,
215 .policy = tipc_nl_policy,
216 }, 218 },
217 { 219 {
218 .cmd = TIPC_NL_NET_SET, 220 .cmd = TIPC_NL_NET_SET,
221 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
219 .doit = tipc_nl_net_set, 222 .doit = tipc_nl_net_set,
220 .policy = tipc_nl_policy,
221 }, 223 },
222 { 224 {
223 .cmd = TIPC_NL_NAME_TABLE_GET, 225 .cmd = TIPC_NL_NAME_TABLE_GET,
226 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
224 .dumpit = tipc_nl_name_table_dump, 227 .dumpit = tipc_nl_name_table_dump,
225 .policy = tipc_nl_policy,
226 }, 228 },
227 { 229 {
228 .cmd = TIPC_NL_MON_SET, 230 .cmd = TIPC_NL_MON_SET,
231 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
229 .doit = tipc_nl_node_set_monitor, 232 .doit = tipc_nl_node_set_monitor,
230 .policy = tipc_nl_policy,
231 }, 233 },
232 { 234 {
233 .cmd = TIPC_NL_MON_GET, 235 .cmd = TIPC_NL_MON_GET,
236 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
234 .doit = tipc_nl_node_get_monitor, 237 .doit = tipc_nl_node_get_monitor,
235 .dumpit = tipc_nl_node_dump_monitor, 238 .dumpit = tipc_nl_node_dump_monitor,
236 .policy = tipc_nl_policy,
237 }, 239 },
238 { 240 {
239 .cmd = TIPC_NL_MON_PEER_GET, 241 .cmd = TIPC_NL_MON_PEER_GET,
242 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
240 .dumpit = tipc_nl_node_dump_monitor_peer, 243 .dumpit = tipc_nl_node_dump_monitor_peer,
241 .policy = tipc_nl_policy,
242 }, 244 },
243 { 245 {
244 .cmd = TIPC_NL_PEER_REMOVE, 246 .cmd = TIPC_NL_PEER_REMOVE,
247 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
245 .doit = tipc_nl_peer_rm, 248 .doit = tipc_nl_peer_rm,
246 .policy = tipc_nl_policy,
247 }, 249 },
248#ifdef CONFIG_TIPC_MEDIA_UDP 250#ifdef CONFIG_TIPC_MEDIA_UDP
249 { 251 {
250 .cmd = TIPC_NL_UDP_GET_REMOTEIP, 252 .cmd = TIPC_NL_UDP_GET_REMOTEIP,
253 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
251 .dumpit = tipc_udp_nl_dump_remoteip, 254 .dumpit = tipc_udp_nl_dump_remoteip,
252 .policy = tipc_nl_policy,
253 }, 255 },
254#endif 256#endif
255}; 257};
@@ -259,6 +261,7 @@ struct genl_family tipc_genl_family __ro_after_init = {
259 .version = TIPC_GENL_V2_VERSION, 261 .version = TIPC_GENL_V2_VERSION,
260 .hdrsize = 0, 262 .hdrsize = 0,
261 .maxattr = TIPC_NLA_MAX, 263 .maxattr = TIPC_NLA_MAX,
264 .policy = tipc_nl_policy,
262 .netnsok = true, 265 .netnsok = true,
263 .module = THIS_MODULE, 266 .module = THIS_MODULE,
264 .ops = tipc_genl_v2_ops, 267 .ops = tipc_genl_v2_ops,
@@ -273,8 +276,8 @@ int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***attr)
273 if (!*attr) 276 if (!*attr)
274 return -EOPNOTSUPP; 277 return -EOPNOTSUPP;
275 278
276 return nlmsg_parse(nlh, GENL_HDRLEN, *attr, maxattr, tipc_nl_policy, 279 return nlmsg_parse_deprecated(nlh, GENL_HDRLEN, *attr, maxattr,
277 NULL); 280 tipc_nl_policy, NULL);
278} 281}
279 282
280int __init tipc_netlink_start(void) 283int __init tipc_netlink_start(void)
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index 340a6e7c43a7..c6a04c09d075 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -328,9 +328,9 @@ static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd,
328 if (err) 328 if (err)
329 goto doit_out; 329 goto doit_out;
330 330
331 err = nla_parse(attrbuf, tipc_genl_family.maxattr, 331 err = nla_parse_deprecated(attrbuf, tipc_genl_family.maxattr,
332 (const struct nlattr *)trans_buf->data, 332 (const struct nlattr *)trans_buf->data,
333 trans_buf->len, NULL, NULL); 333 trans_buf->len, NULL, NULL);
334 if (err) 334 if (err)
335 goto doit_out; 335 goto doit_out;
336 336
@@ -378,8 +378,8 @@ static int tipc_nl_compat_bearer_dump(struct tipc_nl_compat_msg *msg,
378 if (!attrs[TIPC_NLA_BEARER]) 378 if (!attrs[TIPC_NLA_BEARER])
379 return -EINVAL; 379 return -EINVAL;
380 380
381 err = nla_parse_nested(bearer, TIPC_NLA_BEARER_MAX, 381 err = nla_parse_nested_deprecated(bearer, TIPC_NLA_BEARER_MAX,
382 attrs[TIPC_NLA_BEARER], NULL, NULL); 382 attrs[TIPC_NLA_BEARER], NULL, NULL);
383 if (err) 383 if (err)
384 return err; 384 return err;
385 385
@@ -399,7 +399,7 @@ static int tipc_nl_compat_bearer_enable(struct tipc_nl_compat_cmd_doit *cmd,
399 399
400 b = (struct tipc_bearer_config *)TLV_DATA(msg->req); 400 b = (struct tipc_bearer_config *)TLV_DATA(msg->req);
401 401
402 bearer = nla_nest_start(skb, TIPC_NLA_BEARER); 402 bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER);
403 if (!bearer) 403 if (!bearer)
404 return -EMSGSIZE; 404 return -EMSGSIZE;
405 405
@@ -419,7 +419,7 @@ static int tipc_nl_compat_bearer_enable(struct tipc_nl_compat_cmd_doit *cmd,
419 return -EMSGSIZE; 419 return -EMSGSIZE;
420 420
421 if (ntohl(b->priority) <= TIPC_MAX_LINK_PRI) { 421 if (ntohl(b->priority) <= TIPC_MAX_LINK_PRI) {
422 prop = nla_nest_start(skb, TIPC_NLA_BEARER_PROP); 422 prop = nla_nest_start_noflag(skb, TIPC_NLA_BEARER_PROP);
423 if (!prop) 423 if (!prop)
424 return -EMSGSIZE; 424 return -EMSGSIZE;
425 if (nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(b->priority))) 425 if (nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(b->priority)))
@@ -441,7 +441,7 @@ static int tipc_nl_compat_bearer_disable(struct tipc_nl_compat_cmd_doit *cmd,
441 441
442 name = (char *)TLV_DATA(msg->req); 442 name = (char *)TLV_DATA(msg->req);
443 443
444 bearer = nla_nest_start(skb, TIPC_NLA_BEARER); 444 bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER);
445 if (!bearer) 445 if (!bearer)
446 return -EMSGSIZE; 446 return -EMSGSIZE;
447 447
@@ -514,24 +514,26 @@ static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg,
514 if (!attrs[TIPC_NLA_LINK]) 514 if (!attrs[TIPC_NLA_LINK])
515 return -EINVAL; 515 return -EINVAL;
516 516
517 err = nla_parse_nested(link, TIPC_NLA_LINK_MAX, attrs[TIPC_NLA_LINK], 517 err = nla_parse_nested_deprecated(link, TIPC_NLA_LINK_MAX,
518 NULL, NULL); 518 attrs[TIPC_NLA_LINK], NULL, NULL);
519 if (err) 519 if (err)
520 return err; 520 return err;
521 521
522 if (!link[TIPC_NLA_LINK_PROP]) 522 if (!link[TIPC_NLA_LINK_PROP])
523 return -EINVAL; 523 return -EINVAL;
524 524
525 err = nla_parse_nested(prop, TIPC_NLA_PROP_MAX, 525 err = nla_parse_nested_deprecated(prop, TIPC_NLA_PROP_MAX,
526 link[TIPC_NLA_LINK_PROP], NULL, NULL); 526 link[TIPC_NLA_LINK_PROP], NULL,
527 NULL);
527 if (err) 528 if (err)
528 return err; 529 return err;
529 530
530 if (!link[TIPC_NLA_LINK_STATS]) 531 if (!link[TIPC_NLA_LINK_STATS])
531 return -EINVAL; 532 return -EINVAL;
532 533
533 err = nla_parse_nested(stats, TIPC_NLA_STATS_MAX, 534 err = nla_parse_nested_deprecated(stats, TIPC_NLA_STATS_MAX,
534 link[TIPC_NLA_LINK_STATS], NULL, NULL); 535 link[TIPC_NLA_LINK_STATS], NULL,
536 NULL);
535 if (err) 537 if (err)
536 return err; 538 return err;
537 539
@@ -645,8 +647,8 @@ static int tipc_nl_compat_link_dump(struct tipc_nl_compat_msg *msg,
645 if (!attrs[TIPC_NLA_LINK]) 647 if (!attrs[TIPC_NLA_LINK])
646 return -EINVAL; 648 return -EINVAL;
647 649
648 err = nla_parse_nested(link, TIPC_NLA_LINK_MAX, attrs[TIPC_NLA_LINK], 650 err = nla_parse_nested_deprecated(link, TIPC_NLA_LINK_MAX,
649 NULL, NULL); 651 attrs[TIPC_NLA_LINK], NULL, NULL);
650 if (err) 652 if (err)
651 return err; 653 return err;
652 654
@@ -685,7 +687,7 @@ static int tipc_nl_compat_media_set(struct sk_buff *skb,
685 687
686 lc = (struct tipc_link_config *)TLV_DATA(msg->req); 688 lc = (struct tipc_link_config *)TLV_DATA(msg->req);
687 689
688 media = nla_nest_start(skb, TIPC_NLA_MEDIA); 690 media = nla_nest_start_noflag(skb, TIPC_NLA_MEDIA);
689 if (!media) 691 if (!media)
690 return -EMSGSIZE; 692 return -EMSGSIZE;
691 693
@@ -696,7 +698,7 @@ static int tipc_nl_compat_media_set(struct sk_buff *skb,
696 if (nla_put_string(skb, TIPC_NLA_MEDIA_NAME, lc->name)) 698 if (nla_put_string(skb, TIPC_NLA_MEDIA_NAME, lc->name))
697 return -EMSGSIZE; 699 return -EMSGSIZE;
698 700
699 prop = nla_nest_start(skb, TIPC_NLA_MEDIA_PROP); 701 prop = nla_nest_start_noflag(skb, TIPC_NLA_MEDIA_PROP);
700 if (!prop) 702 if (!prop)
701 return -EMSGSIZE; 703 return -EMSGSIZE;
702 704
@@ -717,7 +719,7 @@ static int tipc_nl_compat_bearer_set(struct sk_buff *skb,
717 719
718 lc = (struct tipc_link_config *)TLV_DATA(msg->req); 720 lc = (struct tipc_link_config *)TLV_DATA(msg->req);
719 721
720 bearer = nla_nest_start(skb, TIPC_NLA_BEARER); 722 bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER);
721 if (!bearer) 723 if (!bearer)
722 return -EMSGSIZE; 724 return -EMSGSIZE;
723 725
@@ -728,7 +730,7 @@ static int tipc_nl_compat_bearer_set(struct sk_buff *skb,
728 if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, lc->name)) 730 if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, lc->name))
729 return -EMSGSIZE; 731 return -EMSGSIZE;
730 732
731 prop = nla_nest_start(skb, TIPC_NLA_BEARER_PROP); 733 prop = nla_nest_start_noflag(skb, TIPC_NLA_BEARER_PROP);
732 if (!prop) 734 if (!prop)
733 return -EMSGSIZE; 735 return -EMSGSIZE;
734 736
@@ -748,14 +750,14 @@ static int __tipc_nl_compat_link_set(struct sk_buff *skb,
748 750
749 lc = (struct tipc_link_config *)TLV_DATA(msg->req); 751 lc = (struct tipc_link_config *)TLV_DATA(msg->req);
750 752
751 link = nla_nest_start(skb, TIPC_NLA_LINK); 753 link = nla_nest_start_noflag(skb, TIPC_NLA_LINK);
752 if (!link) 754 if (!link)
753 return -EMSGSIZE; 755 return -EMSGSIZE;
754 756
755 if (nla_put_string(skb, TIPC_NLA_LINK_NAME, lc->name)) 757 if (nla_put_string(skb, TIPC_NLA_LINK_NAME, lc->name))
756 return -EMSGSIZE; 758 return -EMSGSIZE;
757 759
758 prop = nla_nest_start(skb, TIPC_NLA_LINK_PROP); 760 prop = nla_nest_start_noflag(skb, TIPC_NLA_LINK_PROP);
759 if (!prop) 761 if (!prop)
760 return -EMSGSIZE; 762 return -EMSGSIZE;
761 763
@@ -811,7 +813,7 @@ static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd,
811 813
812 name = (char *)TLV_DATA(msg->req); 814 name = (char *)TLV_DATA(msg->req);
813 815
814 link = nla_nest_start(skb, TIPC_NLA_LINK); 816 link = nla_nest_start_noflag(skb, TIPC_NLA_LINK);
815 if (!link) 817 if (!link)
816 return -EMSGSIZE; 818 return -EMSGSIZE;
817 819
@@ -869,16 +871,18 @@ static int tipc_nl_compat_name_table_dump(struct tipc_nl_compat_msg *msg,
869 if (!attrs[TIPC_NLA_NAME_TABLE]) 871 if (!attrs[TIPC_NLA_NAME_TABLE])
870 return -EINVAL; 872 return -EINVAL;
871 873
872 err = nla_parse_nested(nt, TIPC_NLA_NAME_TABLE_MAX, 874 err = nla_parse_nested_deprecated(nt, TIPC_NLA_NAME_TABLE_MAX,
873 attrs[TIPC_NLA_NAME_TABLE], NULL, NULL); 875 attrs[TIPC_NLA_NAME_TABLE], NULL,
876 NULL);
874 if (err) 877 if (err)
875 return err; 878 return err;
876 879
877 if (!nt[TIPC_NLA_NAME_TABLE_PUBL]) 880 if (!nt[TIPC_NLA_NAME_TABLE_PUBL])
878 return -EINVAL; 881 return -EINVAL;
879 882
880 err = nla_parse_nested(publ, TIPC_NLA_PUBL_MAX, 883 err = nla_parse_nested_deprecated(publ, TIPC_NLA_PUBL_MAX,
881 nt[TIPC_NLA_NAME_TABLE_PUBL], NULL, NULL); 884 nt[TIPC_NLA_NAME_TABLE_PUBL], NULL,
885 NULL);
882 if (err) 886 if (err)
883 return err; 887 return err;
884 888
@@ -937,8 +941,8 @@ static int __tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg,
937 if (!attrs[TIPC_NLA_PUBL]) 941 if (!attrs[TIPC_NLA_PUBL])
938 return -EINVAL; 942 return -EINVAL;
939 943
940 err = nla_parse_nested(publ, TIPC_NLA_PUBL_MAX, attrs[TIPC_NLA_PUBL], 944 err = nla_parse_nested_deprecated(publ, TIPC_NLA_PUBL_MAX,
941 NULL, NULL); 945 attrs[TIPC_NLA_PUBL], NULL, NULL);
942 if (err) 946 if (err)
943 return err; 947 return err;
944 948
@@ -973,7 +977,7 @@ static int tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg, u32 sock)
973 return -EMSGSIZE; 977 return -EMSGSIZE;
974 } 978 }
975 979
976 nest = nla_nest_start(args, TIPC_NLA_SOCK); 980 nest = nla_nest_start_noflag(args, TIPC_NLA_SOCK);
977 if (!nest) { 981 if (!nest) {
978 kfree_skb(args); 982 kfree_skb(args);
979 return -EMSGSIZE; 983 return -EMSGSIZE;
@@ -1007,8 +1011,8 @@ static int tipc_nl_compat_sk_dump(struct tipc_nl_compat_msg *msg,
1007 if (!attrs[TIPC_NLA_SOCK]) 1011 if (!attrs[TIPC_NLA_SOCK])
1008 return -EINVAL; 1012 return -EINVAL;
1009 1013
1010 err = nla_parse_nested(sock, TIPC_NLA_SOCK_MAX, attrs[TIPC_NLA_SOCK], 1014 err = nla_parse_nested_deprecated(sock, TIPC_NLA_SOCK_MAX,
1011 NULL, NULL); 1015 attrs[TIPC_NLA_SOCK], NULL, NULL);
1012 if (err) 1016 if (err)
1013 return err; 1017 return err;
1014 1018
@@ -1019,8 +1023,9 @@ static int tipc_nl_compat_sk_dump(struct tipc_nl_compat_msg *msg,
1019 u32 node; 1023 u32 node;
1020 struct nlattr *con[TIPC_NLA_CON_MAX + 1]; 1024 struct nlattr *con[TIPC_NLA_CON_MAX + 1];
1021 1025
1022 err = nla_parse_nested(con, TIPC_NLA_CON_MAX, 1026 err = nla_parse_nested_deprecated(con, TIPC_NLA_CON_MAX,
1023 sock[TIPC_NLA_SOCK_CON], NULL, NULL); 1027 sock[TIPC_NLA_SOCK_CON],
1028 NULL, NULL);
1024 1029
1025 if (err) 1030 if (err)
1026 return err; 1031 return err;
@@ -1059,8 +1064,8 @@ static int tipc_nl_compat_media_dump(struct tipc_nl_compat_msg *msg,
1059 if (!attrs[TIPC_NLA_MEDIA]) 1064 if (!attrs[TIPC_NLA_MEDIA])
1060 return -EINVAL; 1065 return -EINVAL;
1061 1066
1062 err = nla_parse_nested(media, TIPC_NLA_MEDIA_MAX, 1067 err = nla_parse_nested_deprecated(media, TIPC_NLA_MEDIA_MAX,
1063 attrs[TIPC_NLA_MEDIA], NULL, NULL); 1068 attrs[TIPC_NLA_MEDIA], NULL, NULL);
1064 if (err) 1069 if (err)
1065 return err; 1070 return err;
1066 1071
@@ -1079,8 +1084,8 @@ static int tipc_nl_compat_node_dump(struct tipc_nl_compat_msg *msg,
1079 if (!attrs[TIPC_NLA_NODE]) 1084 if (!attrs[TIPC_NLA_NODE])
1080 return -EINVAL; 1085 return -EINVAL;
1081 1086
1082 err = nla_parse_nested(node, TIPC_NLA_NODE_MAX, attrs[TIPC_NLA_NODE], 1087 err = nla_parse_nested_deprecated(node, TIPC_NLA_NODE_MAX,
1083 NULL, NULL); 1088 attrs[TIPC_NLA_NODE], NULL, NULL);
1084 if (err) 1089 if (err)
1085 return err; 1090 return err;
1086 1091
@@ -1100,7 +1105,7 @@ static int tipc_nl_compat_net_set(struct tipc_nl_compat_cmd_doit *cmd,
1100 1105
1101 val = ntohl(*(__be32 *)TLV_DATA(msg->req)); 1106 val = ntohl(*(__be32 *)TLV_DATA(msg->req));
1102 1107
1103 net = nla_nest_start(skb, TIPC_NLA_NET); 1108 net = nla_nest_start_noflag(skb, TIPC_NLA_NET);
1104 if (!net) 1109 if (!net)
1105 return -EMSGSIZE; 1110 return -EMSGSIZE;
1106 1111
@@ -1126,8 +1131,8 @@ static int tipc_nl_compat_net_dump(struct tipc_nl_compat_msg *msg,
1126 if (!attrs[TIPC_NLA_NET]) 1131 if (!attrs[TIPC_NLA_NET])
1127 return -EINVAL; 1132 return -EINVAL;
1128 1133
1129 err = nla_parse_nested(net, TIPC_NLA_NET_MAX, attrs[TIPC_NLA_NET], 1134 err = nla_parse_nested_deprecated(net, TIPC_NLA_NET_MAX,
1130 NULL, NULL); 1135 attrs[TIPC_NLA_NET], NULL, NULL);
1131 if (err) 1136 if (err)
1132 return err; 1137 return err;
1133 1138
@@ -1300,6 +1305,7 @@ send:
1300static const struct genl_ops tipc_genl_compat_ops[] = { 1305static const struct genl_ops tipc_genl_compat_ops[] = {
1301 { 1306 {
1302 .cmd = TIPC_GENL_CMD, 1307 .cmd = TIPC_GENL_CMD,
1308 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1303 .doit = tipc_nl_compat_recv, 1309 .doit = tipc_nl_compat_recv,
1304 }, 1310 },
1305}; 1311};
diff --git a/net/tipc/node.c b/net/tipc/node.c
index dd3b6dc17662..9e106d3ed187 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -375,14 +375,20 @@ static struct tipc_node *tipc_node_create(struct net *net, u32 addr,
375 if (n->capabilities == capabilities) 375 if (n->capabilities == capabilities)
376 goto exit; 376 goto exit;
377 /* Same node may come back with new capabilities */ 377 /* Same node may come back with new capabilities */
378 write_lock_bh(&n->lock); 378 tipc_node_write_lock(n);
379 n->capabilities = capabilities; 379 n->capabilities = capabilities;
380 for (bearer_id = 0; bearer_id < MAX_BEARERS; bearer_id++) { 380 for (bearer_id = 0; bearer_id < MAX_BEARERS; bearer_id++) {
381 l = n->links[bearer_id].link; 381 l = n->links[bearer_id].link;
382 if (l) 382 if (l)
383 tipc_link_update_caps(l, capabilities); 383 tipc_link_update_caps(l, capabilities);
384 } 384 }
385 write_unlock_bh(&n->lock); 385 tipc_node_write_unlock_fast(n);
386
387 /* Calculate cluster capabilities */
388 tn->capabilities = TIPC_NODE_CAPABILITIES;
389 list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
390 tn->capabilities &= temp_node->capabilities;
391 }
386 goto exit; 392 goto exit;
387 } 393 }
388 n = kzalloc(sizeof(*n), GFP_ATOMIC); 394 n = kzalloc(sizeof(*n), GFP_ATOMIC);
@@ -433,6 +439,11 @@ static struct tipc_node *tipc_node_create(struct net *net, u32 addr,
433 break; 439 break;
434 } 440 }
435 list_add_tail_rcu(&n->list, &temp_node->list); 441 list_add_tail_rcu(&n->list, &temp_node->list);
442 /* Calculate cluster capabilities */
443 tn->capabilities = TIPC_NODE_CAPABILITIES;
444 list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
445 tn->capabilities &= temp_node->capabilities;
446 }
436 trace_tipc_node_create(n, true, " "); 447 trace_tipc_node_create(n, true, " ");
437exit: 448exit:
438 spin_unlock_bh(&tn->node_list_lock); 449 spin_unlock_bh(&tn->node_list_lock);
@@ -589,6 +600,7 @@ static void tipc_node_clear_links(struct tipc_node *node)
589 */ 600 */
590static bool tipc_node_cleanup(struct tipc_node *peer) 601static bool tipc_node_cleanup(struct tipc_node *peer)
591{ 602{
603 struct tipc_node *temp_node;
592 struct tipc_net *tn = tipc_net(peer->net); 604 struct tipc_net *tn = tipc_net(peer->net);
593 bool deleted = false; 605 bool deleted = false;
594 606
@@ -604,6 +616,13 @@ static bool tipc_node_cleanup(struct tipc_node *peer)
604 deleted = true; 616 deleted = true;
605 } 617 }
606 tipc_node_write_unlock(peer); 618 tipc_node_write_unlock(peer);
619
620 /* Calculate cluster capabilities */
621 tn->capabilities = TIPC_NODE_CAPABILITIES;
622 list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
623 tn->capabilities &= temp_node->capabilities;
624 }
625
607 spin_unlock_bh(&tn->node_list_lock); 626 spin_unlock_bh(&tn->node_list_lock);
608 return deleted; 627 return deleted;
609} 628}
@@ -695,7 +714,6 @@ static void __tipc_node_link_up(struct tipc_node *n, int bearer_id,
695 *slot0 = bearer_id; 714 *slot0 = bearer_id;
696 *slot1 = bearer_id; 715 *slot1 = bearer_id;
697 tipc_node_fsm_evt(n, SELF_ESTABL_CONTACT_EVT); 716 tipc_node_fsm_evt(n, SELF_ESTABL_CONTACT_EVT);
698 n->failover_sent = false;
699 n->action_flags |= TIPC_NOTIFY_NODE_UP; 717 n->action_flags |= TIPC_NOTIFY_NODE_UP;
700 tipc_link_set_active(nl, true); 718 tipc_link_set_active(nl, true);
701 tipc_bcast_add_peer(n->net, nl, xmitq); 719 tipc_bcast_add_peer(n->net, nl, xmitq);
@@ -738,6 +756,45 @@ static void tipc_node_link_up(struct tipc_node *n, int bearer_id,
738} 756}
739 757
740/** 758/**
759 * tipc_node_link_failover() - start failover in case "half-failover"
760 *
761 * This function is only called in a very special situation where link
762 * failover can be already started on peer node but not on this node.
763 * This can happen when e.g.
764 * 1. Both links <1A-2A>, <1B-2B> down
765 * 2. Link endpoint 2A up, but 1A still down (e.g. due to network
766 * disturbance, wrong session, etc.)
767 * 3. Link <1B-2B> up
768 * 4. Link endpoint 2A down (e.g. due to link tolerance timeout)
769 * 5. Node B starts failover onto link <1B-2B>
770 *
771 * ==> Node A does never start link/node failover!
772 *
773 * @n: tipc node structure
774 * @l: link peer endpoint failingover (- can be NULL)
775 * @tnl: tunnel link
776 * @xmitq: queue for messages to be xmited on tnl link later
777 */
778static void tipc_node_link_failover(struct tipc_node *n, struct tipc_link *l,
779 struct tipc_link *tnl,
780 struct sk_buff_head *xmitq)
781{
782 /* Avoid to be "self-failover" that can never end */
783 if (!tipc_link_is_up(tnl))
784 return;
785
786 tipc_link_fsm_evt(tnl, LINK_SYNCH_END_EVT);
787 tipc_node_fsm_evt(n, NODE_SYNCH_END_EVT);
788
789 n->sync_point = tipc_link_rcv_nxt(tnl) + (U16_MAX / 2 - 1);
790 tipc_link_failover_prepare(l, tnl, xmitq);
791
792 if (l)
793 tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
794 tipc_node_fsm_evt(n, NODE_FAILOVER_BEGIN_EVT);
795}
796
797/**
741 * __tipc_node_link_down - handle loss of link 798 * __tipc_node_link_down - handle loss of link
742 */ 799 */
743static void __tipc_node_link_down(struct tipc_node *n, int *bearer_id, 800static void __tipc_node_link_down(struct tipc_node *n, int *bearer_id,
@@ -1340,7 +1397,7 @@ static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node)
1340 if (!hdr) 1397 if (!hdr)
1341 return -EMSGSIZE; 1398 return -EMSGSIZE;
1342 1399
1343 attrs = nla_nest_start(msg->skb, TIPC_NLA_NODE); 1400 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_NODE);
1344 if (!attrs) 1401 if (!attrs)
1345 goto msg_full; 1402 goto msg_full;
1346 1403
@@ -1656,14 +1713,16 @@ static bool tipc_node_check_state(struct tipc_node *n, struct sk_buff *skb,
1656 tipc_skb_queue_splice_tail_init(tipc_link_inputq(pl), 1713 tipc_skb_queue_splice_tail_init(tipc_link_inputq(pl),
1657 tipc_link_inputq(l)); 1714 tipc_link_inputq(l));
1658 } 1715 }
1716
1659 /* If parallel link was already down, and this happened before 1717 /* If parallel link was already down, and this happened before
1660 * the tunnel link came up, FAILOVER was never sent. Ensure that 1718 * the tunnel link came up, node failover was never started.
1661 * FAILOVER is sent to get peer out of NODE_FAILINGOVER state. 1719 * Ensure that a FAILOVER_MSG is sent to get peer out of
1720 * NODE_FAILINGOVER state, also this node must accept
1721 * TUNNEL_MSGs from peer.
1662 */ 1722 */
1663 if (n->state != NODE_FAILINGOVER && !n->failover_sent) { 1723 if (n->state != NODE_FAILINGOVER)
1664 tipc_link_create_dummy_tnl_msg(l, xmitq); 1724 tipc_node_link_failover(n, pl, l, xmitq);
1665 n->failover_sent = true; 1725
1666 }
1667 /* If pkts arrive out of order, use lowest calculated syncpt */ 1726 /* If pkts arrive out of order, use lowest calculated syncpt */
1668 if (less(syncpt, n->sync_point)) 1727 if (less(syncpt, n->sync_point))
1669 n->sync_point = syncpt; 1728 n->sync_point = syncpt;
@@ -1866,9 +1925,9 @@ int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info)
1866 if (!info->attrs[TIPC_NLA_NET]) 1925 if (!info->attrs[TIPC_NLA_NET])
1867 return -EINVAL; 1926 return -EINVAL;
1868 1927
1869 err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX, 1928 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_NET_MAX,
1870 info->attrs[TIPC_NLA_NET], tipc_nl_net_policy, 1929 info->attrs[TIPC_NLA_NET],
1871 info->extack); 1930 tipc_nl_net_policy, info->extack);
1872 if (err) 1931 if (err)
1873 return err; 1932 return err;
1874 1933
@@ -2024,9 +2083,9 @@ int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info)
2024 if (!info->attrs[TIPC_NLA_LINK]) 2083 if (!info->attrs[TIPC_NLA_LINK])
2025 return -EINVAL; 2084 return -EINVAL;
2026 2085
2027 err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX, 2086 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2028 info->attrs[TIPC_NLA_LINK], 2087 info->attrs[TIPC_NLA_LINK],
2029 tipc_nl_link_policy, info->extack); 2088 tipc_nl_link_policy, info->extack);
2030 if (err) 2089 if (err)
2031 return err; 2090 return err;
2032 2091
@@ -2100,9 +2159,9 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
2100 if (!info->attrs[TIPC_NLA_LINK]) 2159 if (!info->attrs[TIPC_NLA_LINK])
2101 return -EINVAL; 2160 return -EINVAL;
2102 2161
2103 err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX, 2162 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2104 info->attrs[TIPC_NLA_LINK], 2163 info->attrs[TIPC_NLA_LINK],
2105 tipc_nl_link_policy, info->extack); 2164 tipc_nl_link_policy, info->extack);
2106 if (err) 2165 if (err)
2107 return err; 2166 return err;
2108 2167
@@ -2165,9 +2224,9 @@ int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)
2165 if (!info->attrs[TIPC_NLA_LINK]) 2224 if (!info->attrs[TIPC_NLA_LINK])
2166 return -EINVAL; 2225 return -EINVAL;
2167 2226
2168 err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX, 2227 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2169 info->attrs[TIPC_NLA_LINK], 2228 info->attrs[TIPC_NLA_LINK],
2170 tipc_nl_link_policy, info->extack); 2229 tipc_nl_link_policy, info->extack);
2171 if (err) 2230 if (err)
2172 return err; 2231 return err;
2173 2232
@@ -2305,9 +2364,10 @@ int tipc_nl_node_set_monitor(struct sk_buff *skb, struct genl_info *info)
2305 if (!info->attrs[TIPC_NLA_MON]) 2364 if (!info->attrs[TIPC_NLA_MON])
2306 return -EINVAL; 2365 return -EINVAL;
2307 2366
2308 err = nla_parse_nested(attrs, TIPC_NLA_MON_MAX, 2367 err = nla_parse_nested_deprecated(attrs, TIPC_NLA_MON_MAX,
2309 info->attrs[TIPC_NLA_MON], 2368 info->attrs[TIPC_NLA_MON],
2310 tipc_nl_monitor_policy, info->extack); 2369 tipc_nl_monitor_policy,
2370 info->extack);
2311 if (err) 2371 if (err)
2312 return err; 2372 return err;
2313 2373
@@ -2334,7 +2394,7 @@ static int __tipc_nl_add_monitor_prop(struct net *net, struct tipc_nl_msg *msg)
2334 if (!hdr) 2394 if (!hdr)
2335 return -EMSGSIZE; 2395 return -EMSGSIZE;
2336 2396
2337 attrs = nla_nest_start(msg->skb, TIPC_NLA_MON); 2397 attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_MON);
2338 if (!attrs) 2398 if (!attrs)
2339 goto msg_full; 2399 goto msg_full;
2340 2400
@@ -2425,9 +2485,10 @@ int tipc_nl_node_dump_monitor_peer(struct sk_buff *skb,
2425 if (!attrs[TIPC_NLA_MON]) 2485 if (!attrs[TIPC_NLA_MON])
2426 return -EINVAL; 2486 return -EINVAL;
2427 2487
2428 err = nla_parse_nested(mon, TIPC_NLA_MON_MAX, 2488 err = nla_parse_nested_deprecated(mon, TIPC_NLA_MON_MAX,
2429 attrs[TIPC_NLA_MON], 2489 attrs[TIPC_NLA_MON],
2430 tipc_nl_monitor_policy, NULL); 2490 tipc_nl_monitor_policy,
2491 NULL);
2431 if (err) 2492 if (err)
2432 return err; 2493 return err;
2433 2494
diff --git a/net/tipc/node.h b/net/tipc/node.h
index 4f59a30e989a..c0bf49ea3de4 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -51,7 +51,9 @@ enum {
51 TIPC_BLOCK_FLOWCTL = (1 << 3), 51 TIPC_BLOCK_FLOWCTL = (1 << 3),
52 TIPC_BCAST_RCAST = (1 << 4), 52 TIPC_BCAST_RCAST = (1 << 4),
53 TIPC_NODE_ID128 = (1 << 5), 53 TIPC_NODE_ID128 = (1 << 5),
54 TIPC_LINK_PROTO_SEQNO = (1 << 6) 54 TIPC_LINK_PROTO_SEQNO = (1 << 6),
55 TIPC_MCAST_RBCTL = (1 << 7),
56 TIPC_GAP_ACK_BLOCK = (1 << 8)
55}; 57};
56 58
57#define TIPC_NODE_CAPABILITIES (TIPC_SYN_BIT | \ 59#define TIPC_NODE_CAPABILITIES (TIPC_SYN_BIT | \
@@ -60,7 +62,9 @@ enum {
60 TIPC_BCAST_RCAST | \ 62 TIPC_BCAST_RCAST | \
61 TIPC_BLOCK_FLOWCTL | \ 63 TIPC_BLOCK_FLOWCTL | \
62 TIPC_NODE_ID128 | \ 64 TIPC_NODE_ID128 | \
63 TIPC_LINK_PROTO_SEQNO) 65 TIPC_LINK_PROTO_SEQNO | \
66 TIPC_MCAST_RBCTL | \
67 TIPC_GAP_ACK_BLOCK)
64#define INVALID_BEARER_ID -1 68#define INVALID_BEARER_ID -1
65 69
66void tipc_node_stop(struct net *net); 70void tipc_node_stop(struct net *net);
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index b542f14ed444..dd8537f988c4 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -485,6 +485,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
485 tsk_set_unreturnable(tsk, true); 485 tsk_set_unreturnable(tsk, true);
486 if (sock->type == SOCK_DGRAM) 486 if (sock->type == SOCK_DGRAM)
487 tsk_set_unreliable(tsk, true); 487 tsk_set_unreliable(tsk, true);
488 __skb_queue_head_init(&tsk->mc_method.deferredq);
488 } 489 }
489 490
490 trace_tipc_sk_create(sk, NULL, TIPC_DUMP_NONE, " "); 491 trace_tipc_sk_create(sk, NULL, TIPC_DUMP_NONE, " ");
@@ -582,6 +583,7 @@ static int tipc_release(struct socket *sock)
582 sk->sk_shutdown = SHUTDOWN_MASK; 583 sk->sk_shutdown = SHUTDOWN_MASK;
583 tipc_sk_leave(tsk); 584 tipc_sk_leave(tsk);
584 tipc_sk_withdraw(tsk, 0, NULL); 585 tipc_sk_withdraw(tsk, 0, NULL);
586 __skb_queue_purge(&tsk->mc_method.deferredq);
585 sk_stop_timer(sk, &sk->sk_timer); 587 sk_stop_timer(sk, &sk->sk_timer);
586 tipc_sk_remove(tsk); 588 tipc_sk_remove(tsk);
587 589
@@ -734,11 +736,11 @@ static __poll_t tipc_poll(struct file *file, struct socket *sock,
734 736
735 switch (sk->sk_state) { 737 switch (sk->sk_state) {
736 case TIPC_ESTABLISHED: 738 case TIPC_ESTABLISHED:
737 case TIPC_CONNECTING:
738 if (!tsk->cong_link_cnt && !tsk_conn_cong(tsk)) 739 if (!tsk->cong_link_cnt && !tsk_conn_cong(tsk))
739 revents |= EPOLLOUT; 740 revents |= EPOLLOUT;
740 /* fall through */ 741 /* fall through */
741 case TIPC_LISTEN: 742 case TIPC_LISTEN:
743 case TIPC_CONNECTING:
742 if (!skb_queue_empty(&sk->sk_receive_queue)) 744 if (!skb_queue_empty(&sk->sk_receive_queue))
743 revents |= EPOLLIN | EPOLLRDNORM; 745 revents |= EPOLLIN | EPOLLRDNORM;
744 break; 746 break;
@@ -2041,7 +2043,7 @@ static bool tipc_sk_filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
2041 if (msg_data_sz(hdr)) 2043 if (msg_data_sz(hdr))
2042 return true; 2044 return true;
2043 /* Empty ACK-, - wake up sleeping connect() and drop */ 2045 /* Empty ACK-, - wake up sleeping connect() and drop */
2044 sk->sk_data_ready(sk); 2046 sk->sk_state_change(sk);
2045 msg_set_dest_droppable(hdr, 1); 2047 msg_set_dest_droppable(hdr, 1);
2046 return false; 2048 return false;
2047 } 2049 }
@@ -2149,6 +2151,7 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb,
2149 struct tipc_msg *hdr = buf_msg(skb); 2151 struct tipc_msg *hdr = buf_msg(skb);
2150 struct net *net = sock_net(sk); 2152 struct net *net = sock_net(sk);
2151 struct sk_buff_head inputq; 2153 struct sk_buff_head inputq;
2154 int mtyp = msg_type(hdr);
2152 int limit, err = TIPC_OK; 2155 int limit, err = TIPC_OK;
2153 2156
2154 trace_tipc_sk_filter_rcv(sk, skb, TIPC_DUMP_ALL, " "); 2157 trace_tipc_sk_filter_rcv(sk, skb, TIPC_DUMP_ALL, " ");
@@ -2162,6 +2165,9 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb,
2162 if (unlikely(grp)) 2165 if (unlikely(grp))
2163 tipc_group_filter_msg(grp, &inputq, xmitq); 2166 tipc_group_filter_msg(grp, &inputq, xmitq);
2164 2167
2168 if (unlikely(!grp) && mtyp == TIPC_MCAST_MSG)
2169 tipc_mcast_filter_msg(net, &tsk->mc_method.deferredq, &inputq);
2170
2165 /* Validate and add to receive buffer if there is space */ 2171 /* Validate and add to receive buffer if there is space */
2166 while ((skb = __skb_dequeue(&inputq))) { 2172 while ((skb = __skb_dequeue(&inputq))) {
2167 hdr = buf_msg(skb); 2173 hdr = buf_msg(skb);
@@ -3064,6 +3070,9 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
3064 case TIPC_SOCK_RECVQ_DEPTH: 3070 case TIPC_SOCK_RECVQ_DEPTH:
3065 value = skb_queue_len(&sk->sk_receive_queue); 3071 value = skb_queue_len(&sk->sk_receive_queue);
3066 break; 3072 break;
3073 case TIPC_SOCK_RECVQ_USED:
3074 value = sk_rmem_alloc_get(sk);
3075 break;
3067 case TIPC_GROUP_JOIN: 3076 case TIPC_GROUP_JOIN:
3068 seq.type = 0; 3077 seq.type = 0;
3069 if (tsk->group) 3078 if (tsk->group)
@@ -3264,7 +3273,7 @@ static int __tipc_nl_add_sk_con(struct sk_buff *skb, struct tipc_sock *tsk)
3264 peer_node = tsk_peer_node(tsk); 3273 peer_node = tsk_peer_node(tsk);
3265 peer_port = tsk_peer_port(tsk); 3274 peer_port = tsk_peer_port(tsk);
3266 3275
3267 nest = nla_nest_start(skb, TIPC_NLA_SOCK_CON); 3276 nest = nla_nest_start_noflag(skb, TIPC_NLA_SOCK_CON);
3268 if (!nest) 3277 if (!nest)
3269 return -EMSGSIZE; 3278 return -EMSGSIZE;
3270 3279
@@ -3323,7 +3332,7 @@ static int __tipc_nl_add_sk(struct sk_buff *skb, struct netlink_callback *cb,
3323 if (!hdr) 3332 if (!hdr)
3324 goto msg_cancel; 3333 goto msg_cancel;
3325 3334
3326 attrs = nla_nest_start(skb, TIPC_NLA_SOCK); 3335 attrs = nla_nest_start_noflag(skb, TIPC_NLA_SOCK);
3327 if (!attrs) 3336 if (!attrs)
3328 goto genlmsg_cancel; 3337 goto genlmsg_cancel;
3329 3338
@@ -3428,7 +3437,7 @@ int tipc_sk_fill_sock_diag(struct sk_buff *skb, struct netlink_callback *cb,
3428 if (!(sk_filter_state & (1 << sk->sk_state))) 3437 if (!(sk_filter_state & (1 << sk->sk_state)))
3429 return 0; 3438 return 0;
3430 3439
3431 attrs = nla_nest_start(skb, TIPC_NLA_SOCK); 3440 attrs = nla_nest_start_noflag(skb, TIPC_NLA_SOCK);
3432 if (!attrs) 3441 if (!attrs)
3433 goto msg_cancel; 3442 goto msg_cancel;
3434 3443
@@ -3446,7 +3455,7 @@ int tipc_sk_fill_sock_diag(struct sk_buff *skb, struct netlink_callback *cb,
3446 TIPC_NLA_SOCK_PAD)) 3455 TIPC_NLA_SOCK_PAD))
3447 goto attr_msg_cancel; 3456 goto attr_msg_cancel;
3448 3457
3449 stat = nla_nest_start(skb, TIPC_NLA_SOCK_STAT); 3458 stat = nla_nest_start_noflag(skb, TIPC_NLA_SOCK_STAT);
3450 if (!stat) 3459 if (!stat)
3451 goto attr_msg_cancel; 3460 goto attr_msg_cancel;
3452 3461
@@ -3503,7 +3512,7 @@ static int __tipc_nl_add_sk_publ(struct sk_buff *skb,
3503 if (!hdr) 3512 if (!hdr)
3504 goto msg_cancel; 3513 goto msg_cancel;
3505 3514
3506 attrs = nla_nest_start(skb, TIPC_NLA_PUBL); 3515 attrs = nla_nest_start_noflag(skb, TIPC_NLA_PUBL);
3507 if (!attrs) 3516 if (!attrs)
3508 goto genlmsg_cancel; 3517 goto genlmsg_cancel;
3509 3518
@@ -3590,9 +3599,9 @@ int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb)
3590 if (!attrs[TIPC_NLA_SOCK]) 3599 if (!attrs[TIPC_NLA_SOCK])
3591 return -EINVAL; 3600 return -EINVAL;
3592 3601
3593 err = nla_parse_nested(sock, TIPC_NLA_SOCK_MAX, 3602 err = nla_parse_nested_deprecated(sock, TIPC_NLA_SOCK_MAX,
3594 attrs[TIPC_NLA_SOCK], 3603 attrs[TIPC_NLA_SOCK],
3595 tipc_nl_sock_policy, NULL); 3604 tipc_nl_sock_policy, NULL);
3596 if (err) 3605 if (err)
3597 return err; 3606 return err;
3598 3607
diff --git a/net/tipc/sysctl.c b/net/tipc/sysctl.c
index 3481e4906bd6..9df82a573aa7 100644
--- a/net/tipc/sysctl.c
+++ b/net/tipc/sysctl.c
@@ -38,6 +38,8 @@
38 38
39#include <linux/sysctl.h> 39#include <linux/sysctl.h>
40 40
41static int zero;
42static int one = 1;
41static struct ctl_table_header *tipc_ctl_hdr; 43static struct ctl_table_header *tipc_ctl_hdr;
42 44
43static struct ctl_table tipc_table[] = { 45static struct ctl_table tipc_table[] = {
@@ -46,14 +48,16 @@ static struct ctl_table tipc_table[] = {
46 .data = &sysctl_tipc_rmem, 48 .data = &sysctl_tipc_rmem,
47 .maxlen = sizeof(sysctl_tipc_rmem), 49 .maxlen = sizeof(sysctl_tipc_rmem),
48 .mode = 0644, 50 .mode = 0644,
49 .proc_handler = proc_dointvec, 51 .proc_handler = proc_dointvec_minmax,
52 .extra1 = &one,
50 }, 53 },
51 { 54 {
52 .procname = "named_timeout", 55 .procname = "named_timeout",
53 .data = &sysctl_tipc_named_timeout, 56 .data = &sysctl_tipc_named_timeout,
54 .maxlen = sizeof(sysctl_tipc_named_timeout), 57 .maxlen = sizeof(sysctl_tipc_named_timeout),
55 .mode = 0644, 58 .mode = 0644,
56 .proc_handler = proc_dointvec, 59 .proc_handler = proc_dointvec_minmax,
60 .extra1 = &zero,
57 }, 61 },
58 { 62 {
59 .procname = "sk_filter", 63 .procname = "sk_filter",
diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c
index 4d85d71f16e2..7fc02d84c4f1 100644
--- a/net/tipc/udp_media.c
+++ b/net/tipc/udp_media.c
@@ -44,7 +44,7 @@
44#include <net/sock.h> 44#include <net/sock.h>
45#include <net/ip.h> 45#include <net/ip.h>
46#include <net/udp_tunnel.h> 46#include <net/udp_tunnel.h>
47#include <net/addrconf.h> 47#include <net/ipv6_stubs.h>
48#include <linux/tipc_netlink.h> 48#include <linux/tipc_netlink.h>
49#include "core.h" 49#include "core.h"
50#include "addr.h" 50#include "addr.h"
@@ -354,25 +354,21 @@ static int tipc_udp_recv(struct sock *sk, struct sk_buff *skb)
354 skb_pull(skb, sizeof(struct udphdr)); 354 skb_pull(skb, sizeof(struct udphdr));
355 hdr = buf_msg(skb); 355 hdr = buf_msg(skb);
356 356
357 rcu_read_lock(); 357 b = rcu_dereference(ub->bearer);
358 b = rcu_dereference_rtnl(ub->bearer);
359 if (!b) 358 if (!b)
360 goto rcu_out; 359 goto out;
361 360
362 if (b && test_bit(0, &b->up)) { 361 if (b && test_bit(0, &b->up)) {
363 tipc_rcv(sock_net(sk), skb, b); 362 tipc_rcv(sock_net(sk), skb, b);
364 rcu_read_unlock();
365 return 0; 363 return 0;
366 } 364 }
367 365
368 if (unlikely(msg_user(hdr) == LINK_CONFIG)) { 366 if (unlikely(msg_user(hdr) == LINK_CONFIG)) {
369 err = tipc_udp_rcast_disc(b, skb); 367 err = tipc_udp_rcast_disc(b, skb);
370 if (err) 368 if (err)
371 goto rcu_out; 369 goto out;
372 } 370 }
373 371
374rcu_out:
375 rcu_read_unlock();
376out: 372out:
377 kfree_skb(skb); 373 kfree_skb(skb);
378 return 0; 374 return 0;
@@ -451,9 +447,9 @@ int tipc_udp_nl_dump_remoteip(struct sk_buff *skb, struct netlink_callback *cb)
451 if (!attrs[TIPC_NLA_BEARER]) 447 if (!attrs[TIPC_NLA_BEARER])
452 return -EINVAL; 448 return -EINVAL;
453 449
454 err = nla_parse_nested(battrs, TIPC_NLA_BEARER_MAX, 450 err = nla_parse_nested_deprecated(battrs, TIPC_NLA_BEARER_MAX,
455 attrs[TIPC_NLA_BEARER], 451 attrs[TIPC_NLA_BEARER],
456 tipc_nl_bearer_policy, NULL); 452 tipc_nl_bearer_policy, NULL);
457 if (err) 453 if (err)
458 return err; 454 return err;
459 455
@@ -527,7 +523,7 @@ int tipc_udp_nl_add_bearer_data(struct tipc_nl_msg *msg, struct tipc_bearer *b)
527 if (!ub) 523 if (!ub)
528 return -ENODEV; 524 return -ENODEV;
529 525
530 nest = nla_nest_start(msg->skb, TIPC_NLA_BEARER_UDP_OPTS); 526 nest = nla_nest_start_noflag(msg->skb, TIPC_NLA_BEARER_UDP_OPTS);
531 if (!nest) 527 if (!nest)
532 goto msg_full; 528 goto msg_full;
533 529
@@ -605,8 +601,7 @@ int tipc_udp_nl_bearer_add(struct tipc_bearer *b, struct nlattr *attr)
605 struct nlattr *opts[TIPC_NLA_UDP_MAX + 1]; 601 struct nlattr *opts[TIPC_NLA_UDP_MAX + 1];
606 struct udp_media_addr *dst; 602 struct udp_media_addr *dst;
607 603
608 if (nla_parse_nested(opts, TIPC_NLA_UDP_MAX, attr, 604 if (nla_parse_nested_deprecated(opts, TIPC_NLA_UDP_MAX, attr, tipc_nl_udp_policy, NULL))
609 tipc_nl_udp_policy, NULL))
610 return -EINVAL; 605 return -EINVAL;
611 606
612 if (!opts[TIPC_NLA_UDP_REMOTE]) 607 if (!opts[TIPC_NLA_UDP_REMOTE])
@@ -659,9 +654,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
659 if (!attrs[TIPC_NLA_BEARER_UDP_OPTS]) 654 if (!attrs[TIPC_NLA_BEARER_UDP_OPTS])
660 goto err; 655 goto err;
661 656
662 if (nla_parse_nested(opts, TIPC_NLA_UDP_MAX, 657 if (nla_parse_nested_deprecated(opts, TIPC_NLA_UDP_MAX, attrs[TIPC_NLA_BEARER_UDP_OPTS], tipc_nl_udp_policy, NULL))
663 attrs[TIPC_NLA_BEARER_UDP_OPTS],
664 tipc_nl_udp_policy, NULL))
665 goto err; 658 goto err;
666 659
667 if (!opts[TIPC_NLA_UDP_LOCAL] || !opts[TIPC_NLA_UDP_REMOTE]) { 660 if (!opts[TIPC_NLA_UDP_LOCAL] || !opts[TIPC_NLA_UDP_REMOTE]) {
diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index 135a7ee9db03..ca54a7c7ec81 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -52,8 +52,11 @@ static DEFINE_SPINLOCK(tls_device_lock);
52 52
53static void tls_device_free_ctx(struct tls_context *ctx) 53static void tls_device_free_ctx(struct tls_context *ctx)
54{ 54{
55 if (ctx->tx_conf == TLS_HW) 55 if (ctx->tx_conf == TLS_HW) {
56 kfree(tls_offload_ctx_tx(ctx)); 56 kfree(tls_offload_ctx_tx(ctx));
57 kfree(ctx->tx.rec_seq);
58 kfree(ctx->tx.iv);
59 }
57 60
58 if (ctx->rx_conf == TLS_HW) 61 if (ctx->rx_conf == TLS_HW)
59 kfree(tls_offload_ctx_rx(ctx)); 62 kfree(tls_offload_ctx_rx(ctx));
@@ -86,22 +89,6 @@ static void tls_device_gc_task(struct work_struct *work)
86 } 89 }
87} 90}
88 91
89static void tls_device_attach(struct tls_context *ctx, struct sock *sk,
90 struct net_device *netdev)
91{
92 if (sk->sk_destruct != tls_device_sk_destruct) {
93 refcount_set(&ctx->refcount, 1);
94 dev_hold(netdev);
95 ctx->netdev = netdev;
96 spin_lock_irq(&tls_device_lock);
97 list_add_tail(&ctx->list, &tls_device_list);
98 spin_unlock_irq(&tls_device_lock);
99
100 ctx->sk_destruct = sk->sk_destruct;
101 sk->sk_destruct = tls_device_sk_destruct;
102 }
103}
104
105static void tls_device_queue_ctx_destruction(struct tls_context *ctx) 92static void tls_device_queue_ctx_destruction(struct tls_context *ctx)
106{ 93{
107 unsigned long flags; 94 unsigned long flags;
@@ -196,7 +183,7 @@ static void tls_icsk_clean_acked(struct sock *sk, u32 acked_seq)
196 * socket and no in-flight SKBs associated with this 183 * socket and no in-flight SKBs associated with this
197 * socket, so it is safe to free all the resources. 184 * socket, so it is safe to free all the resources.
198 */ 185 */
199void tls_device_sk_destruct(struct sock *sk) 186static void tls_device_sk_destruct(struct sock *sk)
200{ 187{
201 struct tls_context *tls_ctx = tls_get_ctx(sk); 188 struct tls_context *tls_ctx = tls_get_ctx(sk);
202 struct tls_offload_context_tx *ctx = tls_offload_ctx_tx(tls_ctx); 189 struct tls_offload_context_tx *ctx = tls_offload_ctx_tx(tls_ctx);
@@ -214,7 +201,13 @@ void tls_device_sk_destruct(struct sock *sk)
214 if (refcount_dec_and_test(&tls_ctx->refcount)) 201 if (refcount_dec_and_test(&tls_ctx->refcount))
215 tls_device_queue_ctx_destruction(tls_ctx); 202 tls_device_queue_ctx_destruction(tls_ctx);
216} 203}
217EXPORT_SYMBOL(tls_device_sk_destruct); 204
205void tls_device_free_resources_tx(struct sock *sk)
206{
207 struct tls_context *tls_ctx = tls_get_ctx(sk);
208
209 tls_free_partial_record(sk, tls_ctx);
210}
218 211
219static void tls_append_frag(struct tls_record_info *record, 212static void tls_append_frag(struct tls_record_info *record,
220 struct page_frag *pfrag, 213 struct page_frag *pfrag,
@@ -548,14 +541,11 @@ static int tls_device_push_pending_record(struct sock *sk, int flags)
548 541
549void tls_device_write_space(struct sock *sk, struct tls_context *ctx) 542void tls_device_write_space(struct sock *sk, struct tls_context *ctx)
550{ 543{
551 int rc = 0;
552
553 if (!sk->sk_write_pending && tls_is_partially_sent_record(ctx)) { 544 if (!sk->sk_write_pending && tls_is_partially_sent_record(ctx)) {
554 gfp_t sk_allocation = sk->sk_allocation; 545 gfp_t sk_allocation = sk->sk_allocation;
555 546
556 sk->sk_allocation = GFP_ATOMIC; 547 sk->sk_allocation = GFP_ATOMIC;
557 rc = tls_push_partial_record(sk, ctx, 548 tls_push_partial_record(sk, ctx, MSG_DONTWAIT | MSG_NOSIGNAL);
558 MSG_DONTWAIT | MSG_NOSIGNAL);
559 sk->sk_allocation = sk_allocation; 549 sk->sk_allocation = sk_allocation;
560 } 550 }
561} 551}
@@ -574,7 +564,7 @@ void handle_device_resync(struct sock *sk, u32 seq, u64 rcd_sn)
574 564
575 rx_ctx = tls_offload_ctx_rx(tls_ctx); 565 rx_ctx = tls_offload_ctx_rx(tls_ctx);
576 resync_req = atomic64_read(&rx_ctx->resync_req); 566 resync_req = atomic64_read(&rx_ctx->resync_req);
577 req_seq = ntohl(resync_req >> 32) - ((u32)TLS_HEADER_SIZE - 1); 567 req_seq = (resync_req >> 32) - ((u32)TLS_HEADER_SIZE - 1);
578 is_req_pending = resync_req; 568 is_req_pending = resync_req;
579 569
580 if (unlikely(is_req_pending) && req_seq == seq && 570 if (unlikely(is_req_pending) && req_seq == seq &&
@@ -587,7 +577,7 @@ void handle_device_resync(struct sock *sk, u32 seq, u64 rcd_sn)
587static int tls_device_reencrypt(struct sock *sk, struct sk_buff *skb) 577static int tls_device_reencrypt(struct sock *sk, struct sk_buff *skb)
588{ 578{
589 struct strp_msg *rxm = strp_msg(skb); 579 struct strp_msg *rxm = strp_msg(skb);
590 int err = 0, offset = rxm->offset, copy, nsg; 580 int err = 0, offset = rxm->offset, copy, nsg, data_len, pos;
591 struct sk_buff *skb_iter, *unused; 581 struct sk_buff *skb_iter, *unused;
592 struct scatterlist sg[1]; 582 struct scatterlist sg[1];
593 char *orig_buf, *buf; 583 char *orig_buf, *buf;
@@ -618,25 +608,42 @@ static int tls_device_reencrypt(struct sock *sk, struct sk_buff *skb)
618 else 608 else
619 err = 0; 609 err = 0;
620 610
621 copy = min_t(int, skb_pagelen(skb) - offset, 611 data_len = rxm->full_len - TLS_CIPHER_AES_GCM_128_TAG_SIZE;
622 rxm->full_len - TLS_CIPHER_AES_GCM_128_TAG_SIZE);
623 612
624 if (skb->decrypted) 613 if (skb_pagelen(skb) > offset) {
625 skb_store_bits(skb, offset, buf, copy); 614 copy = min_t(int, skb_pagelen(skb) - offset, data_len);
626 615
627 offset += copy; 616 if (skb->decrypted)
628 buf += copy; 617 skb_store_bits(skb, offset, buf, copy);
629 618
619 offset += copy;
620 buf += copy;
621 }
622
623 pos = skb_pagelen(skb);
630 skb_walk_frags(skb, skb_iter) { 624 skb_walk_frags(skb, skb_iter) {
631 copy = min_t(int, skb_iter->len, 625 int frag_pos;
632 rxm->full_len - offset + rxm->offset - 626
633 TLS_CIPHER_AES_GCM_128_TAG_SIZE); 627 /* Practically all frags must belong to msg if reencrypt
628 * is needed with current strparser and coalescing logic,
629 * but strparser may "get optimized", so let's be safe.
630 */
631 if (pos + skb_iter->len <= offset)
632 goto done_with_frag;
633 if (pos >= data_len + rxm->offset)
634 break;
635
636 frag_pos = offset - pos;
637 copy = min_t(int, skb_iter->len - frag_pos,
638 data_len + rxm->offset - offset);
634 639
635 if (skb_iter->decrypted) 640 if (skb_iter->decrypted)
636 skb_store_bits(skb_iter, offset, buf, copy); 641 skb_store_bits(skb_iter, frag_pos, buf, copy);
637 642
638 offset += copy; 643 offset += copy;
639 buf += copy; 644 buf += copy;
645done_with_frag:
646 pos += skb_iter->len;
640 } 647 }
641 648
642free_buf: 649free_buf:
@@ -672,6 +679,22 @@ int tls_device_decrypted(struct sock *sk, struct sk_buff *skb)
672 tls_device_reencrypt(sk, skb); 679 tls_device_reencrypt(sk, skb);
673} 680}
674 681
682static void tls_device_attach(struct tls_context *ctx, struct sock *sk,
683 struct net_device *netdev)
684{
685 if (sk->sk_destruct != tls_device_sk_destruct) {
686 refcount_set(&ctx->refcount, 1);
687 dev_hold(netdev);
688 ctx->netdev = netdev;
689 spin_lock_irq(&tls_device_lock);
690 list_add_tail(&ctx->list, &tls_device_list);
691 spin_unlock_irq(&tls_device_lock);
692
693 ctx->sk_destruct = sk->sk_destruct;
694 sk->sk_destruct = tls_device_sk_destruct;
695 }
696}
697
675int tls_set_device_offload(struct sock *sk, struct tls_context *ctx) 698int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
676{ 699{
677 u16 nonce_size, tag_size, iv_size, rec_seq_size; 700 u16 nonce_size, tag_size, iv_size, rec_seq_size;
@@ -855,8 +878,6 @@ int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx)
855 } 878 }
856 879
857 if (!(netdev->features & NETIF_F_HW_TLS_RX)) { 880 if (!(netdev->features & NETIF_F_HW_TLS_RX)) {
858 pr_err_ratelimited("%s: netdev %s with no TLS offload\n",
859 __func__, netdev->name);
860 rc = -ENOTSUPP; 881 rc = -ENOTSUPP;
861 goto release_netdev; 882 goto release_netdev;
862 } 883 }
@@ -884,17 +905,16 @@ int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx)
884 rc = netdev->tlsdev_ops->tls_dev_add(netdev, sk, TLS_OFFLOAD_CTX_DIR_RX, 905 rc = netdev->tlsdev_ops->tls_dev_add(netdev, sk, TLS_OFFLOAD_CTX_DIR_RX,
885 &ctx->crypto_recv.info, 906 &ctx->crypto_recv.info,
886 tcp_sk(sk)->copied_seq); 907 tcp_sk(sk)->copied_seq);
887 if (rc) { 908 if (rc)
888 pr_err_ratelimited("%s: The netdev has refused to offload this socket\n",
889 __func__);
890 goto free_sw_resources; 909 goto free_sw_resources;
891 }
892 910
893 tls_device_attach(ctx, sk, netdev); 911 tls_device_attach(ctx, sk, netdev);
894 goto release_netdev; 912 goto release_netdev;
895 913
896free_sw_resources: 914free_sw_resources:
915 up_read(&device_offload_lock);
897 tls_sw_free_resources_rx(sk); 916 tls_sw_free_resources_rx(sk);
917 down_read(&device_offload_lock);
898release_ctx: 918release_ctx:
899 ctx->priv_ctx_rx = NULL; 919 ctx->priv_ctx_rx = NULL;
900release_netdev: 920release_netdev:
@@ -929,8 +949,6 @@ void tls_device_offload_cleanup_rx(struct sock *sk)
929 } 949 }
930out: 950out:
931 up_read(&device_offload_lock); 951 up_read(&device_offload_lock);
932 kfree(tls_ctx->rx.rec_seq);
933 kfree(tls_ctx->rx.iv);
934 tls_sw_release_resources_rx(sk); 952 tls_sw_release_resources_rx(sk);
935} 953}
936 954
@@ -1015,4 +1033,5 @@ void __exit tls_device_cleanup(void)
1015{ 1033{
1016 unregister_netdevice_notifier(&tls_dev_notifier); 1034 unregister_netdevice_notifier(&tls_dev_notifier);
1017 flush_work(&tls_device_gc_work); 1035 flush_work(&tls_device_gc_work);
1036 clean_acked_data_flush();
1018} 1037}
diff --git a/net/tls/tls_device_fallback.c b/net/tls/tls_device_fallback.c
index 54c3a758f2a7..c3a5fe624b4e 100644
--- a/net/tls/tls_device_fallback.c
+++ b/net/tls/tls_device_fallback.c
@@ -194,18 +194,26 @@ static void update_chksum(struct sk_buff *skb, int headln)
194 194
195static void complete_skb(struct sk_buff *nskb, struct sk_buff *skb, int headln) 195static void complete_skb(struct sk_buff *nskb, struct sk_buff *skb, int headln)
196{ 196{
197 struct sock *sk = skb->sk;
198 int delta;
199
197 skb_copy_header(nskb, skb); 200 skb_copy_header(nskb, skb);
198 201
199 skb_put(nskb, skb->len); 202 skb_put(nskb, skb->len);
200 memcpy(nskb->data, skb->data, headln); 203 memcpy(nskb->data, skb->data, headln);
201 update_chksum(nskb, headln);
202 204
203 nskb->destructor = skb->destructor; 205 nskb->destructor = skb->destructor;
204 nskb->sk = skb->sk; 206 nskb->sk = sk;
205 skb->destructor = NULL; 207 skb->destructor = NULL;
206 skb->sk = NULL; 208 skb->sk = NULL;
207 refcount_add(nskb->truesize - skb->truesize, 209
208 &nskb->sk->sk_wmem_alloc); 210 update_chksum(nskb, headln);
211
212 delta = nskb->truesize - skb->truesize;
213 if (likely(delta < 0))
214 WARN_ON_ONCE(refcount_sub_and_test(-delta, &sk->sk_wmem_alloc));
215 else if (delta)
216 refcount_add(delta, &sk->sk_wmem_alloc);
209} 217}
210 218
211/* This function may be called after the user socket is already 219/* This function may be called after the user socket is already
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index df921a2904b9..fc81ae18cc44 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -208,6 +208,26 @@ int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
208 return tls_push_sg(sk, ctx, sg, offset, flags); 208 return tls_push_sg(sk, ctx, sg, offset, flags);
209} 209}
210 210
211bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx)
212{
213 struct scatterlist *sg;
214
215 sg = ctx->partially_sent_record;
216 if (!sg)
217 return false;
218
219 while (1) {
220 put_page(sg_page(sg));
221 sk_mem_uncharge(sk, sg->length);
222
223 if (sg_is_last(sg))
224 break;
225 sg++;
226 }
227 ctx->partially_sent_record = NULL;
228 return true;
229}
230
211static void tls_write_space(struct sock *sk) 231static void tls_write_space(struct sock *sk)
212{ 232{
213 struct tls_context *ctx = tls_get_ctx(sk); 233 struct tls_context *ctx = tls_get_ctx(sk);
@@ -267,13 +287,14 @@ static void tls_sk_proto_close(struct sock *sk, long timeout)
267 kfree(ctx->tx.rec_seq); 287 kfree(ctx->tx.rec_seq);
268 kfree(ctx->tx.iv); 288 kfree(ctx->tx.iv);
269 tls_sw_free_resources_tx(sk); 289 tls_sw_free_resources_tx(sk);
290#ifdef CONFIG_TLS_DEVICE
291 } else if (ctx->tx_conf == TLS_HW) {
292 tls_device_free_resources_tx(sk);
293#endif
270 } 294 }
271 295
272 if (ctx->rx_conf == TLS_SW) { 296 if (ctx->rx_conf == TLS_SW)
273 kfree(ctx->rx.rec_seq);
274 kfree(ctx->rx.iv);
275 tls_sw_free_resources_rx(sk); 297 tls_sw_free_resources_rx(sk);
276 }
277 298
278#ifdef CONFIG_TLS_DEVICE 299#ifdef CONFIG_TLS_DEVICE
279 if (ctx->rx_conf == TLS_HW) 300 if (ctx->rx_conf == TLS_HW)
@@ -469,27 +490,32 @@ static int do_tls_setsockopt_conf(struct sock *sk, char __user *optval,
469 490
470 switch (crypto_info->cipher_type) { 491 switch (crypto_info->cipher_type) {
471 case TLS_CIPHER_AES_GCM_128: 492 case TLS_CIPHER_AES_GCM_128:
493 optsize = sizeof(struct tls12_crypto_info_aes_gcm_128);
494 break;
472 case TLS_CIPHER_AES_GCM_256: { 495 case TLS_CIPHER_AES_GCM_256: {
473 optsize = crypto_info->cipher_type == TLS_CIPHER_AES_GCM_128 ? 496 optsize = sizeof(struct tls12_crypto_info_aes_gcm_256);
474 sizeof(struct tls12_crypto_info_aes_gcm_128) :
475 sizeof(struct tls12_crypto_info_aes_gcm_256);
476 if (optlen != optsize) {
477 rc = -EINVAL;
478 goto err_crypto_info;
479 }
480 rc = copy_from_user(crypto_info + 1, optval + sizeof(*crypto_info),
481 optlen - sizeof(*crypto_info));
482 if (rc) {
483 rc = -EFAULT;
484 goto err_crypto_info;
485 }
486 break; 497 break;
487 } 498 }
499 case TLS_CIPHER_AES_CCM_128:
500 optsize = sizeof(struct tls12_crypto_info_aes_ccm_128);
501 break;
488 default: 502 default:
489 rc = -EINVAL; 503 rc = -EINVAL;
490 goto err_crypto_info; 504 goto err_crypto_info;
491 } 505 }
492 506
507 if (optlen != optsize) {
508 rc = -EINVAL;
509 goto err_crypto_info;
510 }
511
512 rc = copy_from_user(crypto_info + 1, optval + sizeof(*crypto_info),
513 optlen - sizeof(*crypto_info));
514 if (rc) {
515 rc = -EFAULT;
516 goto err_crypto_info;
517 }
518
493 if (tx) { 519 if (tx) {
494#ifdef CONFIG_TLS_DEVICE 520#ifdef CONFIG_TLS_DEVICE
495 rc = tls_set_device_offload(sk, ctx); 521 rc = tls_set_device_offload(sk, ctx);
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 20b191227969..d93f83f77864 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -42,8 +42,6 @@
42#include <net/strparser.h> 42#include <net/strparser.h>
43#include <net/tls.h> 43#include <net/tls.h>
44 44
45#define MAX_IV_SIZE TLS_CIPHER_AES_GCM_128_IV_SIZE
46
47static int __skb_nsg(struct sk_buff *skb, int offset, int len, 45static int __skb_nsg(struct sk_buff *skb, int offset, int len,
48 unsigned int recursion_level) 46 unsigned int recursion_level)
49{ 47{
@@ -121,23 +119,25 @@ static int skb_nsg(struct sk_buff *skb, int offset, int len)
121} 119}
122 120
123static int padding_length(struct tls_sw_context_rx *ctx, 121static int padding_length(struct tls_sw_context_rx *ctx,
124 struct tls_context *tls_ctx, struct sk_buff *skb) 122 struct tls_prot_info *prot, struct sk_buff *skb)
125{ 123{
126 struct strp_msg *rxm = strp_msg(skb); 124 struct strp_msg *rxm = strp_msg(skb);
127 int sub = 0; 125 int sub = 0;
128 126
129 /* Determine zero-padding length */ 127 /* Determine zero-padding length */
130 if (tls_ctx->prot_info.version == TLS_1_3_VERSION) { 128 if (prot->version == TLS_1_3_VERSION) {
131 char content_type = 0; 129 char content_type = 0;
132 int err; 130 int err;
133 int back = 17; 131 int back = 17;
134 132
135 while (content_type == 0) { 133 while (content_type == 0) {
136 if (back > rxm->full_len) 134 if (back > rxm->full_len - prot->prepend_size)
137 return -EBADMSG; 135 return -EBADMSG;
138 err = skb_copy_bits(skb, 136 err = skb_copy_bits(skb,
139 rxm->offset + rxm->full_len - back, 137 rxm->offset + rxm->full_len - back,
140 &content_type, 1); 138 &content_type, 1);
139 if (err)
140 return err;
141 if (content_type) 141 if (content_type)
142 break; 142 break;
143 sub++; 143 sub++;
@@ -172,9 +172,17 @@ static void tls_decrypt_done(struct crypto_async_request *req, int err)
172 tls_err_abort(skb->sk, err); 172 tls_err_abort(skb->sk, err);
173 } else { 173 } else {
174 struct strp_msg *rxm = strp_msg(skb); 174 struct strp_msg *rxm = strp_msg(skb);
175 rxm->full_len -= padding_length(ctx, tls_ctx, skb); 175 int pad;
176 rxm->offset += prot->prepend_size; 176
177 rxm->full_len -= prot->overhead_size; 177 pad = padding_length(ctx, prot, skb);
178 if (pad < 0) {
179 ctx->async_wait.err = pad;
180 tls_err_abort(skb->sk, pad);
181 } else {
182 rxm->full_len -= pad;
183 rxm->offset += prot->prepend_size;
184 rxm->full_len -= prot->overhead_size;
185 }
178 } 186 }
179 187
180 /* After using skb->sk to propagate sk through crypto async callback 188 /* After using skb->sk to propagate sk through crypto async callback
@@ -225,7 +233,7 @@ static int tls_do_decryption(struct sock *sk,
225 /* Using skb->sk to push sk through to crypto async callback 233 /* Using skb->sk to push sk through to crypto async callback
226 * handler. This allows propagating errors up to the socket 234 * handler. This allows propagating errors up to the socket
227 * if needed. It _must_ be cleared in the async handler 235 * if needed. It _must_ be cleared in the async handler
228 * before kfree_skb is called. We _know_ skb->sk is NULL 236 * before consume_skb is called. We _know_ skb->sk is NULL
229 * because it is a clone from strparser. 237 * because it is a clone from strparser.
230 */ 238 */
231 skb->sk = sk; 239 skb->sk = sk;
@@ -479,11 +487,18 @@ static int tls_do_encryption(struct sock *sk,
479 struct tls_rec *rec = ctx->open_rec; 487 struct tls_rec *rec = ctx->open_rec;
480 struct sk_msg *msg_en = &rec->msg_encrypted; 488 struct sk_msg *msg_en = &rec->msg_encrypted;
481 struct scatterlist *sge = sk_msg_elem(msg_en, start); 489 struct scatterlist *sge = sk_msg_elem(msg_en, start);
482 int rc; 490 int rc, iv_offset = 0;
491
492 /* For CCM based ciphers, first byte of IV is a constant */
493 if (prot->cipher_type == TLS_CIPHER_AES_CCM_128) {
494 rec->iv_data[0] = TLS_AES_CCM_IV_B0_BYTE;
495 iv_offset = 1;
496 }
483 497
484 memcpy(rec->iv_data, tls_ctx->tx.iv, sizeof(rec->iv_data)); 498 memcpy(&rec->iv_data[iv_offset], tls_ctx->tx.iv,
485 xor_iv_with_seq(prot->version, rec->iv_data, 499 prot->iv_size + prot->salt_size);
486 tls_ctx->tx.rec_seq); 500
501 xor_iv_with_seq(prot->version, rec->iv_data, tls_ctx->tx.rec_seq);
487 502
488 sge->offset += prot->prepend_size; 503 sge->offset += prot->prepend_size;
489 sge->length -= prot->prepend_size; 504 sge->length -= prot->prepend_size;
@@ -1344,6 +1359,7 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
1344 struct scatterlist *sgout = NULL; 1359 struct scatterlist *sgout = NULL;
1345 const int data_len = rxm->full_len - prot->overhead_size + 1360 const int data_len = rxm->full_len - prot->overhead_size +
1346 prot->tail_size; 1361 prot->tail_size;
1362 int iv_offset = 0;
1347 1363
1348 if (*zc && (out_iov || out_sg)) { 1364 if (*zc && (out_iov || out_sg)) {
1349 if (out_iov) 1365 if (out_iov)
@@ -1386,18 +1402,25 @@ static int decrypt_internal(struct sock *sk, struct sk_buff *skb,
1386 aad = (u8 *)(sgout + n_sgout); 1402 aad = (u8 *)(sgout + n_sgout);
1387 iv = aad + prot->aad_size; 1403 iv = aad + prot->aad_size;
1388 1404
1405 /* For CCM based ciphers, first byte of nonce+iv is always '2' */
1406 if (prot->cipher_type == TLS_CIPHER_AES_CCM_128) {
1407 iv[0] = 2;
1408 iv_offset = 1;
1409 }
1410
1389 /* Prepare IV */ 1411 /* Prepare IV */
1390 err = skb_copy_bits(skb, rxm->offset + TLS_HEADER_SIZE, 1412 err = skb_copy_bits(skb, rxm->offset + TLS_HEADER_SIZE,
1391 iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, 1413 iv + iv_offset + prot->salt_size,
1392 prot->iv_size); 1414 prot->iv_size);
1393 if (err < 0) { 1415 if (err < 0) {
1394 kfree(mem); 1416 kfree(mem);
1395 return err; 1417 return err;
1396 } 1418 }
1397 if (prot->version == TLS_1_3_VERSION) 1419 if (prot->version == TLS_1_3_VERSION)
1398 memcpy(iv, tls_ctx->rx.iv, crypto_aead_ivsize(ctx->aead_recv)); 1420 memcpy(iv + iv_offset, tls_ctx->rx.iv,
1421 crypto_aead_ivsize(ctx->aead_recv));
1399 else 1422 else
1400 memcpy(iv, tls_ctx->rx.iv, TLS_CIPHER_AES_GCM_128_SALT_SIZE); 1423 memcpy(iv + iv_offset, tls_ctx->rx.iv, prot->salt_size);
1401 1424
1402 xor_iv_with_seq(prot->version, iv, tls_ctx->rx.rec_seq); 1425 xor_iv_with_seq(prot->version, iv, tls_ctx->rx.rec_seq);
1403 1426
@@ -1465,7 +1488,7 @@ static int decrypt_skb_update(struct sock *sk, struct sk_buff *skb,
1465 struct tls_prot_info *prot = &tls_ctx->prot_info; 1488 struct tls_prot_info *prot = &tls_ctx->prot_info;
1466 int version = prot->version; 1489 int version = prot->version;
1467 struct strp_msg *rxm = strp_msg(skb); 1490 struct strp_msg *rxm = strp_msg(skb);
1468 int err = 0; 1491 int pad, err = 0;
1469 1492
1470 if (!ctx->decrypted) { 1493 if (!ctx->decrypted) {
1471#ifdef CONFIG_TLS_DEVICE 1494#ifdef CONFIG_TLS_DEVICE
@@ -1488,7 +1511,11 @@ static int decrypt_skb_update(struct sock *sk, struct sk_buff *skb,
1488 *zc = false; 1511 *zc = false;
1489 } 1512 }
1490 1513
1491 rxm->full_len -= padding_length(ctx, tls_ctx, skb); 1514 pad = padding_length(ctx, prot, skb);
1515 if (pad < 0)
1516 return pad;
1517
1518 rxm->full_len -= pad;
1492 rxm->offset += prot->prepend_size; 1519 rxm->offset += prot->prepend_size;
1493 rxm->full_len -= prot->overhead_size; 1520 rxm->full_len -= prot->overhead_size;
1494 tls_advance_record_sn(sk, &tls_ctx->rx, version); 1521 tls_advance_record_sn(sk, &tls_ctx->rx, version);
@@ -1524,7 +1551,7 @@ static bool tls_sw_advance_skb(struct sock *sk, struct sk_buff *skb,
1524 rxm->full_len -= len; 1551 rxm->full_len -= len;
1525 return false; 1552 return false;
1526 } 1553 }
1527 kfree_skb(skb); 1554 consume_skb(skb);
1528 } 1555 }
1529 1556
1530 /* Finished with message */ 1557 /* Finished with message */
@@ -1633,7 +1660,7 @@ static int process_rx_list(struct tls_sw_context_rx *ctx,
1633 1660
1634 if (!is_peek) { 1661 if (!is_peek) {
1635 skb_unlink(skb, &ctx->rx_list); 1662 skb_unlink(skb, &ctx->rx_list);
1636 kfree_skb(skb); 1663 consume_skb(skb);
1637 } 1664 }
1638 1665
1639 skb = next_skb; 1666 skb = next_skb;
@@ -2052,20 +2079,7 @@ void tls_sw_free_resources_tx(struct sock *sk)
2052 /* Free up un-sent records in tx_list. First, free 2079 /* Free up un-sent records in tx_list. First, free
2053 * the partially sent record if any at head of tx_list. 2080 * the partially sent record if any at head of tx_list.
2054 */ 2081 */
2055 if (tls_ctx->partially_sent_record) { 2082 if (tls_free_partial_record(sk, tls_ctx)) {
2056 struct scatterlist *sg = tls_ctx->partially_sent_record;
2057
2058 while (1) {
2059 put_page(sg_page(sg));
2060 sk_mem_uncharge(sk, sg->length);
2061
2062 if (sg_is_last(sg))
2063 break;
2064 sg++;
2065 }
2066
2067 tls_ctx->partially_sent_record = NULL;
2068
2069 rec = list_first_entry(&ctx->tx_list, 2083 rec = list_first_entry(&ctx->tx_list,
2070 struct tls_rec, list); 2084 struct tls_rec, list);
2071 list_del(&rec->list); 2085 list_del(&rec->list);
@@ -2091,6 +2105,9 @@ void tls_sw_release_resources_rx(struct sock *sk)
2091 struct tls_context *tls_ctx = tls_get_ctx(sk); 2105 struct tls_context *tls_ctx = tls_get_ctx(sk);
2092 struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx); 2106 struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);
2093 2107
2108 kfree(tls_ctx->rx.rec_seq);
2109 kfree(tls_ctx->rx.iv);
2110
2094 if (ctx->aead_recv) { 2111 if (ctx->aead_recv) {
2095 kfree_skb(ctx->recv_pkt); 2112 kfree_skb(ctx->recv_pkt);
2096 ctx->recv_pkt = NULL; 2113 ctx->recv_pkt = NULL;
@@ -2154,14 +2171,15 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
2154 struct tls_crypto_info *crypto_info; 2171 struct tls_crypto_info *crypto_info;
2155 struct tls12_crypto_info_aes_gcm_128 *gcm_128_info; 2172 struct tls12_crypto_info_aes_gcm_128 *gcm_128_info;
2156 struct tls12_crypto_info_aes_gcm_256 *gcm_256_info; 2173 struct tls12_crypto_info_aes_gcm_256 *gcm_256_info;
2174 struct tls12_crypto_info_aes_ccm_128 *ccm_128_info;
2157 struct tls_sw_context_tx *sw_ctx_tx = NULL; 2175 struct tls_sw_context_tx *sw_ctx_tx = NULL;
2158 struct tls_sw_context_rx *sw_ctx_rx = NULL; 2176 struct tls_sw_context_rx *sw_ctx_rx = NULL;
2159 struct cipher_context *cctx; 2177 struct cipher_context *cctx;
2160 struct crypto_aead **aead; 2178 struct crypto_aead **aead;
2161 struct strp_callbacks cb; 2179 struct strp_callbacks cb;
2162 u16 nonce_size, tag_size, iv_size, rec_seq_size; 2180 u16 nonce_size, tag_size, iv_size, rec_seq_size, salt_size;
2163 struct crypto_tfm *tfm; 2181 struct crypto_tfm *tfm;
2164 char *iv, *rec_seq, *key, *salt; 2182 char *iv, *rec_seq, *key, *salt, *cipher_name;
2165 size_t keysize; 2183 size_t keysize;
2166 int rc = 0; 2184 int rc = 0;
2167 2185
@@ -2226,6 +2244,8 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
2226 keysize = TLS_CIPHER_AES_GCM_128_KEY_SIZE; 2244 keysize = TLS_CIPHER_AES_GCM_128_KEY_SIZE;
2227 key = gcm_128_info->key; 2245 key = gcm_128_info->key;
2228 salt = gcm_128_info->salt; 2246 salt = gcm_128_info->salt;
2247 salt_size = TLS_CIPHER_AES_GCM_128_SALT_SIZE;
2248 cipher_name = "gcm(aes)";
2229 break; 2249 break;
2230 } 2250 }
2231 case TLS_CIPHER_AES_GCM_256: { 2251 case TLS_CIPHER_AES_GCM_256: {
@@ -2241,6 +2261,25 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
2241 keysize = TLS_CIPHER_AES_GCM_256_KEY_SIZE; 2261 keysize = TLS_CIPHER_AES_GCM_256_KEY_SIZE;
2242 key = gcm_256_info->key; 2262 key = gcm_256_info->key;
2243 salt = gcm_256_info->salt; 2263 salt = gcm_256_info->salt;
2264 salt_size = TLS_CIPHER_AES_GCM_256_SALT_SIZE;
2265 cipher_name = "gcm(aes)";
2266 break;
2267 }
2268 case TLS_CIPHER_AES_CCM_128: {
2269 nonce_size = TLS_CIPHER_AES_CCM_128_IV_SIZE;
2270 tag_size = TLS_CIPHER_AES_CCM_128_TAG_SIZE;
2271 iv_size = TLS_CIPHER_AES_CCM_128_IV_SIZE;
2272 iv = ((struct tls12_crypto_info_aes_ccm_128 *)crypto_info)->iv;
2273 rec_seq_size = TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE;
2274 rec_seq =
2275 ((struct tls12_crypto_info_aes_ccm_128 *)crypto_info)->rec_seq;
2276 ccm_128_info =
2277 (struct tls12_crypto_info_aes_ccm_128 *)crypto_info;
2278 keysize = TLS_CIPHER_AES_CCM_128_KEY_SIZE;
2279 key = ccm_128_info->key;
2280 salt = ccm_128_info->salt;
2281 salt_size = TLS_CIPHER_AES_CCM_128_SALT_SIZE;
2282 cipher_name = "ccm(aes)";
2244 break; 2283 break;
2245 } 2284 }
2246 default: 2285 default:
@@ -2270,16 +2309,16 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
2270 prot->overhead_size = prot->prepend_size + 2309 prot->overhead_size = prot->prepend_size +
2271 prot->tag_size + prot->tail_size; 2310 prot->tag_size + prot->tail_size;
2272 prot->iv_size = iv_size; 2311 prot->iv_size = iv_size;
2273 cctx->iv = kmalloc(iv_size + TLS_CIPHER_AES_GCM_128_SALT_SIZE, 2312 prot->salt_size = salt_size;
2274 GFP_KERNEL); 2313 cctx->iv = kmalloc(iv_size + salt_size, GFP_KERNEL);
2275 if (!cctx->iv) { 2314 if (!cctx->iv) {
2276 rc = -ENOMEM; 2315 rc = -ENOMEM;
2277 goto free_priv; 2316 goto free_priv;
2278 } 2317 }
2279 /* Note: 128 & 256 bit salt are the same size */ 2318 /* Note: 128 & 256 bit salt are the same size */
2280 memcpy(cctx->iv, salt, TLS_CIPHER_AES_GCM_128_SALT_SIZE);
2281 memcpy(cctx->iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, iv, iv_size);
2282 prot->rec_seq_size = rec_seq_size; 2319 prot->rec_seq_size = rec_seq_size;
2320 memcpy(cctx->iv, salt, salt_size);
2321 memcpy(cctx->iv + salt_size, iv, iv_size);
2283 cctx->rec_seq = kmemdup(rec_seq, rec_seq_size, GFP_KERNEL); 2322 cctx->rec_seq = kmemdup(rec_seq, rec_seq_size, GFP_KERNEL);
2284 if (!cctx->rec_seq) { 2323 if (!cctx->rec_seq) {
2285 rc = -ENOMEM; 2324 rc = -ENOMEM;
@@ -2287,7 +2326,7 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
2287 } 2326 }
2288 2327
2289 if (!*aead) { 2328 if (!*aead) {
2290 *aead = crypto_alloc_aead("gcm(aes)", 0, 0); 2329 *aead = crypto_alloc_aead(cipher_name, 0, 0);
2291 if (IS_ERR(*aead)) { 2330 if (IS_ERR(*aead)) {
2292 rc = PTR_ERR(*aead); 2331 rc = PTR_ERR(*aead);
2293 *aead = NULL; 2332 *aead = NULL;
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index ddb838a1b74c..e68d7454f2e3 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2040,8 +2040,8 @@ static int unix_dgram_recvmsg(struct socket *sock, struct msghdr *msg,
2040 struct unix_sock *u = unix_sk(sk); 2040 struct unix_sock *u = unix_sk(sk);
2041 struct sk_buff *skb, *last; 2041 struct sk_buff *skb, *last;
2042 long timeo; 2042 long timeo;
2043 int skip;
2043 int err; 2044 int err;
2044 int peeked, skip;
2045 2045
2046 err = -EOPNOTSUPP; 2046 err = -EOPNOTSUPP;
2047 if (flags&MSG_OOB) 2047 if (flags&MSG_OOB)
@@ -2053,8 +2053,8 @@ static int unix_dgram_recvmsg(struct socket *sock, struct msghdr *msg,
2053 mutex_lock(&u->iolock); 2053 mutex_lock(&u->iolock);
2054 2054
2055 skip = sk_peek_offset(sk, flags); 2055 skip = sk_peek_offset(sk, flags);
2056 skb = __skb_try_recv_datagram(sk, flags, NULL, &peeked, &skip, 2056 skb = __skb_try_recv_datagram(sk, flags, NULL, &skip, &err,
2057 &err, &last); 2057 &last);
2058 if (skb) 2058 if (skb)
2059 break; 2059 break;
2060 2060
diff --git a/net/wimax/stack.c b/net/wimax/stack.c
index a6307813b6d5..4969de672886 100644
--- a/net/wimax/stack.c
+++ b/net/wimax/stack.c
@@ -419,26 +419,26 @@ static const struct nla_policy wimax_gnl_policy[WIMAX_GNL_ATTR_MAX + 1] = {
419static const struct genl_ops wimax_gnl_ops[] = { 419static const struct genl_ops wimax_gnl_ops[] = {
420 { 420 {
421 .cmd = WIMAX_GNL_OP_MSG_FROM_USER, 421 .cmd = WIMAX_GNL_OP_MSG_FROM_USER,
422 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
422 .flags = GENL_ADMIN_PERM, 423 .flags = GENL_ADMIN_PERM,
423 .policy = wimax_gnl_policy,
424 .doit = wimax_gnl_doit_msg_from_user, 424 .doit = wimax_gnl_doit_msg_from_user,
425 }, 425 },
426 { 426 {
427 .cmd = WIMAX_GNL_OP_RESET, 427 .cmd = WIMAX_GNL_OP_RESET,
428 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
428 .flags = GENL_ADMIN_PERM, 429 .flags = GENL_ADMIN_PERM,
429 .policy = wimax_gnl_policy,
430 .doit = wimax_gnl_doit_reset, 430 .doit = wimax_gnl_doit_reset,
431 }, 431 },
432 { 432 {
433 .cmd = WIMAX_GNL_OP_RFKILL, 433 .cmd = WIMAX_GNL_OP_RFKILL,
434 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
434 .flags = GENL_ADMIN_PERM, 435 .flags = GENL_ADMIN_PERM,
435 .policy = wimax_gnl_policy,
436 .doit = wimax_gnl_doit_rfkill, 436 .doit = wimax_gnl_doit_rfkill,
437 }, 437 },
438 { 438 {
439 .cmd = WIMAX_GNL_OP_STATE_GET, 439 .cmd = WIMAX_GNL_OP_STATE_GET,
440 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
440 .flags = GENL_ADMIN_PERM, 441 .flags = GENL_ADMIN_PERM,
441 .policy = wimax_gnl_policy,
442 .doit = wimax_gnl_doit_state_get, 442 .doit = wimax_gnl_doit_state_get,
443 }, 443 },
444}; 444};
@@ -582,6 +582,7 @@ struct genl_family wimax_gnl_family __ro_after_init = {
582 .version = WIMAX_GNL_VERSION, 582 .version = WIMAX_GNL_VERSION,
583 .hdrsize = 0, 583 .hdrsize = 0,
584 .maxattr = WIMAX_GNL_ATTR_MAX, 584 .maxattr = WIMAX_GNL_ATTR_MAX,
585 .policy = wimax_gnl_policy,
585 .module = THIS_MODULE, 586 .module = THIS_MODULE,
586 .ops = wimax_gnl_ops, 587 .ops = wimax_gnl_ops,
587 .n_ops = ARRAY_SIZE(wimax_gnl_ops), 588 .n_ops = ARRAY_SIZE(wimax_gnl_ops),
diff --git a/net/wireless/lib80211_crypt_tkip.c b/net/wireless/lib80211_crypt_tkip.c
index 35f06563207d..11eaa5956f00 100644
--- a/net/wireless/lib80211_crypt_tkip.c
+++ b/net/wireless/lib80211_crypt_tkip.c
@@ -501,7 +501,6 @@ static int michael_mic(struct crypto_shash *tfm_michael, u8 *key, u8 *hdr,
501 } 501 }
502 502
503 desc->tfm = tfm_michael; 503 desc->tfm = tfm_michael;
504 desc->flags = 0;
505 504
506 if (crypto_shash_setkey(tfm_michael, key, 8)) 505 if (crypto_shash_setkey(tfm_michael, key, 8))
507 return -1; 506 return -1;
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 25a9e3b5c154..fffe4b371e23 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -331,6 +331,11 @@ const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
331 .len = NL80211_MAX_SUPP_RATES }, 331 .len = NL80211_MAX_SUPP_RATES },
332 [NL80211_ATTR_STA_PLINK_ACTION] = 332 [NL80211_ATTR_STA_PLINK_ACTION] =
333 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), 333 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
334 [NL80211_ATTR_STA_TX_POWER_SETTING] =
335 NLA_POLICY_RANGE(NLA_U8,
336 NL80211_TX_POWER_AUTOMATIC,
337 NL80211_TX_POWER_FIXED),
338 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
334 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, 339 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
335 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, 340 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
336 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, 341 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
@@ -553,6 +558,7 @@ static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
553 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, 558 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
554 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), 559 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
555 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 560 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
561 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
556}; 562};
557 563
558/* policy for the key default flags */ 564/* policy for the key default flags */
@@ -618,11 +624,20 @@ nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
618}; 624};
619 625
620static const struct nla_policy 626static const struct nla_policy
627nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
628 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
629 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
630 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
631};
632
633static const struct nla_policy
621nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { 634nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
622 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, 635 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
623 .len = IEEE80211_MAX_SSID_LEN }, 636 .len = IEEE80211_MAX_SSID_LEN },
624 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN }, 637 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN },
625 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, 638 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
639 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
640 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
626}; 641};
627 642
628static const struct nla_policy 643static const struct nla_policy
@@ -688,9 +703,11 @@ int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
688 int err; 703 int err;
689 704
690 if (!cb->args[0]) { 705 if (!cb->args[0]) {
691 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, 706 err = nlmsg_parse_deprecated(cb->nlh,
692 genl_family_attrbuf(&nl80211_fam), 707 GENL_HDRLEN + nl80211_fam.hdrsize,
693 nl80211_fam.maxattr, nl80211_policy, NULL); 708 genl_family_attrbuf(&nl80211_fam),
709 nl80211_fam.maxattr,
710 nl80211_policy, NULL);
694 if (err) 711 if (err)
695 return err; 712 return err;
696 713
@@ -740,13 +757,13 @@ static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
740{ 757{
741 int j; 758 int j;
742 struct nlattr *nl_wmm_rules = 759 struct nlattr *nl_wmm_rules =
743 nla_nest_start(msg, NL80211_FREQUENCY_ATTR_WMM); 760 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
744 761
745 if (!nl_wmm_rules) 762 if (!nl_wmm_rules)
746 goto nla_put_failure; 763 goto nla_put_failure;
747 764
748 for (j = 0; j < IEEE80211_NUM_ACS; j++) { 765 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
749 struct nlattr *nl_wmm_rule = nla_nest_start(msg, j); 766 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
750 767
751 if (!nl_wmm_rule) 768 if (!nl_wmm_rule)
752 goto nla_put_failure; 769 goto nla_put_failure;
@@ -875,7 +892,7 @@ static bool nl80211_put_txq_stats(struct sk_buff *msg,
875 return false; \ 892 return false; \
876 } while (0) 893 } while (0)
877 894
878 txqattr = nla_nest_start(msg, attrtype); 895 txqattr = nla_nest_start_noflag(msg, attrtype);
879 if (!txqattr) 896 if (!txqattr)
880 return false; 897 return false;
881 898
@@ -910,8 +927,9 @@ static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
910 struct key_parse *k) 927 struct key_parse *k)
911{ 928{
912 struct nlattr *tb[NL80211_KEY_MAX + 1]; 929 struct nlattr *tb[NL80211_KEY_MAX + 1];
913 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, 930 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
914 nl80211_key_policy, info->extack); 931 nl80211_key_policy,
932 info->extack);
915 if (err) 933 if (err)
916 return err; 934 return err;
917 935
@@ -947,10 +965,11 @@ static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
947 if (tb[NL80211_KEY_DEFAULT_TYPES]) { 965 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
948 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 966 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
949 967
950 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, 968 err = nla_parse_nested_deprecated(kdt,
951 tb[NL80211_KEY_DEFAULT_TYPES], 969 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
952 nl80211_key_default_policy, 970 tb[NL80211_KEY_DEFAULT_TYPES],
953 info->extack); 971 nl80211_key_default_policy,
972 info->extack);
954 if (err) 973 if (err)
955 return err; 974 return err;
956 975
@@ -958,6 +977,9 @@ static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
958 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 977 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
959 } 978 }
960 979
980 if (tb[NL80211_KEY_MODE])
981 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
982
961 return 0; 983 return 0;
962} 984}
963 985
@@ -994,11 +1016,11 @@ static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
994 1016
995 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { 1017 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
996 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1018 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
997 int err = nla_parse_nested(kdt, 1019 int err = nla_parse_nested_deprecated(kdt,
998 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1020 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
999 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], 1021 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1000 nl80211_key_default_policy, 1022 nl80211_key_default_policy,
1001 info->extack); 1023 info->extack);
1002 if (err) 1024 if (err)
1003 return err; 1025 return err;
1004 1026
@@ -1187,7 +1209,7 @@ static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1187 1209
1188static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) 1210static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1189{ 1211{
1190 struct nlattr *nl_modes = nla_nest_start(msg, attr); 1212 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
1191 int i; 1213 int i;
1192 1214
1193 if (!nl_modes) 1215 if (!nl_modes)
@@ -1215,8 +1237,8 @@ static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1215 struct nlattr *nl_combis; 1237 struct nlattr *nl_combis;
1216 int i, j; 1238 int i, j;
1217 1239
1218 nl_combis = nla_nest_start(msg, 1240 nl_combis = nla_nest_start_noflag(msg,
1219 NL80211_ATTR_INTERFACE_COMBINATIONS); 1241 NL80211_ATTR_INTERFACE_COMBINATIONS);
1220 if (!nl_combis) 1242 if (!nl_combis)
1221 goto nla_put_failure; 1243 goto nla_put_failure;
1222 1244
@@ -1226,18 +1248,19 @@ static int nl80211_put_iface_combinations(struct wiphy *wiphy,
1226 1248
1227 c = &wiphy->iface_combinations[i]; 1249 c = &wiphy->iface_combinations[i];
1228 1250
1229 nl_combi = nla_nest_start(msg, i + 1); 1251 nl_combi = nla_nest_start_noflag(msg, i + 1);
1230 if (!nl_combi) 1252 if (!nl_combi)
1231 goto nla_put_failure; 1253 goto nla_put_failure;
1232 1254
1233 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); 1255 nl_limits = nla_nest_start_noflag(msg,
1256 NL80211_IFACE_COMB_LIMITS);
1234 if (!nl_limits) 1257 if (!nl_limits)
1235 goto nla_put_failure; 1258 goto nla_put_failure;
1236 1259
1237 for (j = 0; j < c->n_limits; j++) { 1260 for (j = 0; j < c->n_limits; j++) {
1238 struct nlattr *nl_limit; 1261 struct nlattr *nl_limit;
1239 1262
1240 nl_limit = nla_nest_start(msg, j + 1); 1263 nl_limit = nla_nest_start_noflag(msg, j + 1);
1241 if (!nl_limit) 1264 if (!nl_limit)
1242 goto nla_put_failure; 1265 goto nla_put_failure;
1243 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, 1266 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
@@ -1290,7 +1313,8 @@ static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1290 if (!tcp) 1313 if (!tcp)
1291 return 0; 1314 return 0;
1292 1315
1293 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); 1316 nl_tcp = nla_nest_start_noflag(msg,
1317 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1294 if (!nl_tcp) 1318 if (!nl_tcp)
1295 return -ENOBUFS; 1319 return -ENOBUFS;
1296 1320
@@ -1330,7 +1354,8 @@ static int nl80211_send_wowlan(struct sk_buff *msg,
1330 if (!rdev->wiphy.wowlan) 1354 if (!rdev->wiphy.wowlan)
1331 return 0; 1355 return 0;
1332 1356
1333 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); 1357 nl_wowlan = nla_nest_start_noflag(msg,
1358 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1334 if (!nl_wowlan) 1359 if (!nl_wowlan)
1335 return -ENOBUFS; 1360 return -ENOBUFS;
1336 1361
@@ -1459,7 +1484,8 @@ static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1459 1484
1460 if (sband->n_iftype_data) { 1485 if (sband->n_iftype_data) {
1461 struct nlattr *nl_iftype_data = 1486 struct nlattr *nl_iftype_data =
1462 nla_nest_start(msg, NL80211_BAND_ATTR_IFTYPE_DATA); 1487 nla_nest_start_noflag(msg,
1488 NL80211_BAND_ATTR_IFTYPE_DATA);
1463 int err; 1489 int err;
1464 1490
1465 if (!nl_iftype_data) 1491 if (!nl_iftype_data)
@@ -1468,7 +1494,7 @@ static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1468 for (i = 0; i < sband->n_iftype_data; i++) { 1494 for (i = 0; i < sband->n_iftype_data; i++) {
1469 struct nlattr *iftdata; 1495 struct nlattr *iftdata;
1470 1496
1471 iftdata = nla_nest_start(msg, i + 1); 1497 iftdata = nla_nest_start_noflag(msg, i + 1);
1472 if (!iftdata) 1498 if (!iftdata)
1473 return -ENOBUFS; 1499 return -ENOBUFS;
1474 1500
@@ -1484,12 +1510,12 @@ static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1484 } 1510 }
1485 1511
1486 /* add bitrates */ 1512 /* add bitrates */
1487 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); 1513 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
1488 if (!nl_rates) 1514 if (!nl_rates)
1489 return -ENOBUFS; 1515 return -ENOBUFS;
1490 1516
1491 for (i = 0; i < sband->n_bitrates; i++) { 1517 for (i = 0; i < sband->n_bitrates; i++) {
1492 nl_rate = nla_nest_start(msg, i); 1518 nl_rate = nla_nest_start_noflag(msg, i);
1493 if (!nl_rate) 1519 if (!nl_rate)
1494 return -ENOBUFS; 1520 return -ENOBUFS;
1495 1521
@@ -1522,12 +1548,12 @@ nl80211_send_mgmt_stypes(struct sk_buff *msg,
1522 if (!mgmt_stypes) 1548 if (!mgmt_stypes)
1523 return 0; 1549 return 0;
1524 1550
1525 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); 1551 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
1526 if (!nl_ifs) 1552 if (!nl_ifs)
1527 return -ENOBUFS; 1553 return -ENOBUFS;
1528 1554
1529 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1555 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1530 nl_ftypes = nla_nest_start(msg, ift); 1556 nl_ftypes = nla_nest_start_noflag(msg, ift);
1531 if (!nl_ftypes) 1557 if (!nl_ftypes)
1532 return -ENOBUFS; 1558 return -ENOBUFS;
1533 i = 0; 1559 i = 0;
@@ -1545,12 +1571,12 @@ nl80211_send_mgmt_stypes(struct sk_buff *msg,
1545 1571
1546 nla_nest_end(msg, nl_ifs); 1572 nla_nest_end(msg, nl_ifs);
1547 1573
1548 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); 1574 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
1549 if (!nl_ifs) 1575 if (!nl_ifs)
1550 return -ENOBUFS; 1576 return -ENOBUFS;
1551 1577
1552 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 1578 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1553 nl_ftypes = nla_nest_start(msg, ift); 1579 nl_ftypes = nla_nest_start_noflag(msg, ift);
1554 if (!nl_ftypes) 1580 if (!nl_ftypes)
1555 return -ENOBUFS; 1581 return -ENOBUFS;
1556 i = 0; 1582 i = 0;
@@ -1668,7 +1694,7 @@ nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1668 if (!cap->ftm.supported) 1694 if (!cap->ftm.supported)
1669 return 0; 1695 return 0;
1670 1696
1671 ftm = nla_nest_start(msg, NL80211_PMSR_TYPE_FTM); 1697 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
1672 if (!ftm) 1698 if (!ftm)
1673 return -ENOBUFS; 1699 return -ENOBUFS;
1674 1700
@@ -1716,7 +1742,7 @@ static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1716 * will genlmsg_cancel() if we fail 1742 * will genlmsg_cancel() if we fail
1717 */ 1743 */
1718 1744
1719 pmsr = nla_nest_start(msg, NL80211_ATTR_PEER_MEASUREMENTS); 1745 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
1720 if (!pmsr) 1746 if (!pmsr)
1721 return -ENOBUFS; 1747 return -ENOBUFS;
1722 1748
@@ -1731,7 +1757,7 @@ static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1731 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) 1757 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1732 return -ENOBUFS; 1758 return -ENOBUFS;
1733 1759
1734 caps = nla_nest_start(msg, NL80211_PMSR_ATTR_TYPE_CAPA); 1760 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
1735 if (!caps) 1761 if (!caps)
1736 return -ENOBUFS; 1762 return -ENOBUFS;
1737 1763
@@ -1892,7 +1918,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1892 break; 1918 break;
1893 /* fall through */ 1919 /* fall through */
1894 case 3: 1920 case 3:
1895 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); 1921 nl_bands = nla_nest_start_noflag(msg,
1922 NL80211_ATTR_WIPHY_BANDS);
1896 if (!nl_bands) 1923 if (!nl_bands)
1897 goto nla_put_failure; 1924 goto nla_put_failure;
1898 1925
@@ -1905,7 +1932,7 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1905 if (!sband) 1932 if (!sband)
1906 continue; 1933 continue;
1907 1934
1908 nl_band = nla_nest_start(msg, band); 1935 nl_band = nla_nest_start_noflag(msg, band);
1909 if (!nl_band) 1936 if (!nl_band)
1910 goto nla_put_failure; 1937 goto nla_put_failure;
1911 1938
@@ -1919,15 +1946,16 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1919 /* fall through */ 1946 /* fall through */
1920 default: 1947 default:
1921 /* add frequencies */ 1948 /* add frequencies */
1922 nl_freqs = nla_nest_start( 1949 nl_freqs = nla_nest_start_noflag(msg,
1923 msg, NL80211_BAND_ATTR_FREQS); 1950 NL80211_BAND_ATTR_FREQS);
1924 if (!nl_freqs) 1951 if (!nl_freqs)
1925 goto nla_put_failure; 1952 goto nla_put_failure;
1926 1953
1927 for (i = state->chan_start - 1; 1954 for (i = state->chan_start - 1;
1928 i < sband->n_channels; 1955 i < sband->n_channels;
1929 i++) { 1956 i++) {
1930 nl_freq = nla_nest_start(msg, i); 1957 nl_freq = nla_nest_start_noflag(msg,
1958 i);
1931 if (!nl_freq) 1959 if (!nl_freq)
1932 goto nla_put_failure; 1960 goto nla_put_failure;
1933 1961
@@ -1972,7 +2000,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1972 break; 2000 break;
1973 /* fall through */ 2001 /* fall through */
1974 case 4: 2002 case 4:
1975 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); 2003 nl_cmds = nla_nest_start_noflag(msg,
2004 NL80211_ATTR_SUPPORTED_COMMANDS);
1976 if (!nl_cmds) 2005 if (!nl_cmds)
1977 goto nla_put_failure; 2006 goto nla_put_failure;
1978 2007
@@ -2120,7 +2149,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2120 const struct nl80211_vendor_cmd_info *info; 2149 const struct nl80211_vendor_cmd_info *info;
2121 struct nlattr *nested; 2150 struct nlattr *nested;
2122 2151
2123 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); 2152 nested = nla_nest_start_noflag(msg,
2153 NL80211_ATTR_VENDOR_DATA);
2124 if (!nested) 2154 if (!nested)
2125 goto nla_put_failure; 2155 goto nla_put_failure;
2126 2156
@@ -2136,8 +2166,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2136 const struct nl80211_vendor_cmd_info *info; 2166 const struct nl80211_vendor_cmd_info *info;
2137 struct nlattr *nested; 2167 struct nlattr *nested;
2138 2168
2139 nested = nla_nest_start(msg, 2169 nested = nla_nest_start_noflag(msg,
2140 NL80211_ATTR_VENDOR_EVENTS); 2170 NL80211_ATTR_VENDOR_EVENTS);
2141 if (!nested) 2171 if (!nested)
2142 goto nla_put_failure; 2172 goto nla_put_failure;
2143 2173
@@ -2174,7 +2204,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2174 struct nlattr *nested; 2204 struct nlattr *nested;
2175 u32 bss_select_support = rdev->wiphy.bss_select_support; 2205 u32 bss_select_support = rdev->wiphy.bss_select_support;
2176 2206
2177 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); 2207 nested = nla_nest_start_noflag(msg,
2208 NL80211_ATTR_BSS_SELECT);
2178 if (!nested) 2209 if (!nested)
2179 goto nla_put_failure; 2210 goto nla_put_failure;
2180 2211
@@ -2196,8 +2227,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2196 rdev->wiphy.iftype_ext_capab) { 2227 rdev->wiphy.iftype_ext_capab) {
2197 struct nlattr *nested_ext_capab, *nested; 2228 struct nlattr *nested_ext_capab, *nested;
2198 2229
2199 nested = nla_nest_start(msg, 2230 nested = nla_nest_start_noflag(msg,
2200 NL80211_ATTR_IFTYPE_EXT_CAPA); 2231 NL80211_ATTR_IFTYPE_EXT_CAPA);
2201 if (!nested) 2232 if (!nested)
2202 goto nla_put_failure; 2233 goto nla_put_failure;
2203 2234
@@ -2207,7 +2238,8 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
2207 2238
2208 capab = &rdev->wiphy.iftype_ext_capab[i]; 2239 capab = &rdev->wiphy.iftype_ext_capab[i];
2209 2240
2210 nested_ext_capab = nla_nest_start(msg, i); 2241 nested_ext_capab = nla_nest_start_noflag(msg,
2242 i);
2211 if (!nested_ext_capab || 2243 if (!nested_ext_capab ||
2212 nla_put_u32(msg, NL80211_ATTR_IFTYPE, 2244 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2213 capab->iftype) || 2245 capab->iftype) ||
@@ -2289,8 +2321,10 @@ static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2289 struct nl80211_dump_wiphy_state *state) 2321 struct nl80211_dump_wiphy_state *state)
2290{ 2322{
2291 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); 2323 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
2292 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb, 2324 int ret = nlmsg_parse_deprecated(cb->nlh,
2293 nl80211_fam.maxattr, nl80211_policy, NULL); 2325 GENL_HDRLEN + nl80211_fam.hdrsize,
2326 tb, nl80211_fam.maxattr,
2327 nl80211_policy, NULL);
2294 /* ignore parse errors for backward compatibility */ 2328 /* ignore parse errors for backward compatibility */
2295 if (ret) 2329 if (ret)
2296 return 0; 2330 return 0;
@@ -2733,10 +2767,11 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2733 nla_for_each_nested(nl_txq_params, 2767 nla_for_each_nested(nl_txq_params,
2734 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], 2768 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2735 rem_txq_params) { 2769 rem_txq_params) {
2736 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, 2770 result = nla_parse_nested_deprecated(tb,
2737 nl_txq_params, 2771 NL80211_TXQ_ATTR_MAX,
2738 txq_params_policy, 2772 nl_txq_params,
2739 info->extack); 2773 txq_params_policy,
2774 info->extack);
2740 if (result) 2775 if (result)
2741 return result; 2776 return result;
2742 result = parse_txq_params(tb, &txq_params); 2777 result = parse_txq_params(tb, &txq_params);
@@ -3193,8 +3228,7 @@ static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3193 if (!nla) 3228 if (!nla)
3194 return -EINVAL; 3229 return -EINVAL;
3195 3230
3196 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla, 3231 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
3197 mntr_flags_policy, NULL))
3198 return -EINVAL; 3232 return -EINVAL;
3199 3233
3200 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) 3234 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
@@ -3521,7 +3555,7 @@ static void get_key_callback(void *c, struct key_params *params)
3521 params->cipher))) 3555 params->cipher)))
3522 goto nla_put_failure; 3556 goto nla_put_failure;
3523 3557
3524 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); 3558 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
3525 if (!key) 3559 if (!key)
3526 goto nla_put_failure; 3560 goto nla_put_failure;
3527 3561
@@ -3634,8 +3668,11 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3634 if (key.idx < 0) 3668 if (key.idx < 0)
3635 return -EINVAL; 3669 return -EINVAL;
3636 3670
3637 /* only support setting default key */ 3671 /* Only support setting default key and
3638 if (!key.def && !key.defmgmt) 3672 * Extended Key ID action NL80211_KEY_SET_TX.
3673 */
3674 if (!key.def && !key.defmgmt &&
3675 !(key.p.mode == NL80211_KEY_SET_TX))
3639 return -EINVAL; 3676 return -EINVAL;
3640 3677
3641 wdev_lock(dev->ieee80211_ptr); 3678 wdev_lock(dev->ieee80211_ptr);
@@ -3659,7 +3696,7 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3659#ifdef CONFIG_CFG80211_WEXT 3696#ifdef CONFIG_CFG80211_WEXT
3660 dev->ieee80211_ptr->wext.default_key = key.idx; 3697 dev->ieee80211_ptr->wext.default_key = key.idx;
3661#endif 3698#endif
3662 } else { 3699 } else if (key.defmgmt) {
3663 if (key.def_uni || !key.def_multi) { 3700 if (key.def_uni || !key.def_multi) {
3664 err = -EINVAL; 3701 err = -EINVAL;
3665 goto out; 3702 goto out;
@@ -3681,8 +3718,25 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3681#ifdef CONFIG_CFG80211_WEXT 3718#ifdef CONFIG_CFG80211_WEXT
3682 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; 3719 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3683#endif 3720#endif
3684 } 3721 } else if (key.p.mode == NL80211_KEY_SET_TX &&
3722 wiphy_ext_feature_isset(&rdev->wiphy,
3723 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
3724 u8 *mac_addr = NULL;
3725
3726 if (info->attrs[NL80211_ATTR_MAC])
3727 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3728
3729 if (!mac_addr || key.idx < 0 || key.idx > 1) {
3730 err = -EINVAL;
3731 goto out;
3732 }
3685 3733
3734 err = rdev_add_key(rdev, dev, key.idx,
3735 NL80211_KEYTYPE_PAIRWISE,
3736 mac_addr, &key.p);
3737 } else {
3738 err = -EINVAL;
3739 }
3686 out: 3740 out:
3687 wdev_unlock(dev->ieee80211_ptr); 3741 wdev_unlock(dev->ieee80211_ptr);
3688 3742
@@ -3843,8 +3897,7 @@ static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3843 if (n_entries > wiphy->max_acl_mac_addrs) 3897 if (n_entries > wiphy->max_acl_mac_addrs)
3844 return ERR_PTR(-ENOTSUPP); 3898 return ERR_PTR(-ENOTSUPP);
3845 3899
3846 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), 3900 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
3847 GFP_KERNEL);
3848 if (!acl) 3901 if (!acl)
3849 return ERR_PTR(-ENOMEM); 3902 return ERR_PTR(-ENOMEM);
3850 3903
@@ -4054,8 +4107,10 @@ static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4054 sband = rdev->wiphy.bands[band]; 4107 sband = rdev->wiphy.bands[band];
4055 if (sband == NULL) 4108 if (sband == NULL)
4056 return -EINVAL; 4109 return -EINVAL;
4057 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, 4110 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4058 nl80211_txattr_policy, info->extack); 4111 tx_rates,
4112 nl80211_txattr_policy,
4113 info->extack);
4059 if (err) 4114 if (err)
4060 return err; 4115 return err;
4061 if (tb[NL80211_TXRATE_LEGACY]) { 4116 if (tb[NL80211_TXRATE_LEGACY]) {
@@ -4223,9 +4278,10 @@ static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4223 if (attrs[NL80211_ATTR_FTM_RESPONDER]) { 4278 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4224 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; 4279 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4225 4280
4226 err = nla_parse_nested(tb, NL80211_FTM_RESP_ATTR_MAX, 4281 err = nla_parse_nested_deprecated(tb,
4227 attrs[NL80211_ATTR_FTM_RESPONDER], 4282 NL80211_FTM_RESP_ATTR_MAX,
4228 NULL, NULL); 4283 attrs[NL80211_ATTR_FTM_RESPONDER],
4284 NULL, NULL);
4229 if (err) 4285 if (err)
4230 return err; 4286 return err;
4231 4287
@@ -4633,8 +4689,7 @@ static int parse_station_flags(struct genl_info *info,
4633 if (!nla) 4689 if (!nla)
4634 return 0; 4690 return 0;
4635 4691
4636 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla, 4692 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
4637 sta_flags_policy, info->extack))
4638 return -EINVAL; 4693 return -EINVAL;
4639 4694
4640 /* 4695 /*
@@ -4686,7 +4741,7 @@ bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
4686 u16 bitrate_compat; 4741 u16 bitrate_compat;
4687 enum nl80211_rate_info rate_flg; 4742 enum nl80211_rate_info rate_flg;
4688 4743
4689 rate = nla_nest_start(msg, attr); 4744 rate = nla_nest_start_noflag(msg, attr);
4690 if (!rate) 4745 if (!rate)
4691 return false; 4746 return false;
4692 4747
@@ -4773,7 +4828,7 @@ static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4773 if (!mask) 4828 if (!mask)
4774 return true; 4829 return true;
4775 4830
4776 attr = nla_nest_start(msg, id); 4831 attr = nla_nest_start_noflag(msg, id);
4777 if (!attr) 4832 if (!attr)
4778 return false; 4833 return false;
4779 4834
@@ -4808,7 +4863,7 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4808 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) 4863 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4809 goto nla_put_failure; 4864 goto nla_put_failure;
4810 4865
4811 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); 4866 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
4812 if (!sinfoattr) 4867 if (!sinfoattr)
4813 goto nla_put_failure; 4868 goto nla_put_failure;
4814 4869
@@ -4889,6 +4944,7 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4889 PUT_SINFO(TX_RETRIES, tx_retries, u32); 4944 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4890 PUT_SINFO(TX_FAILED, tx_failed, u32); 4945 PUT_SINFO(TX_FAILED, tx_failed, u32);
4891 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); 4946 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4947 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
4892 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); 4948 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4893 PUT_SINFO(LOCAL_PM, local_pm, u32); 4949 PUT_SINFO(LOCAL_PM, local_pm, u32);
4894 PUT_SINFO(PEER_PM, peer_pm, u32); 4950 PUT_SINFO(PEER_PM, peer_pm, u32);
@@ -4896,7 +4952,8 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4896 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); 4952 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
4897 4953
4898 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { 4954 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
4899 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); 4955 bss_param = nla_nest_start_noflag(msg,
4956 NL80211_STA_INFO_BSS_PARAM);
4900 if (!bss_param) 4957 if (!bss_param)
4901 goto nla_put_failure; 4958 goto nla_put_failure;
4902 4959
@@ -4939,7 +4996,8 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4939 struct nlattr *tidsattr; 4996 struct nlattr *tidsattr;
4940 int tid; 4997 int tid;
4941 4998
4942 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); 4999 tidsattr = nla_nest_start_noflag(msg,
5000 NL80211_STA_INFO_TID_STATS);
4943 if (!tidsattr) 5001 if (!tidsattr)
4944 goto nla_put_failure; 5002 goto nla_put_failure;
4945 5003
@@ -4952,7 +5010,7 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4952 if (!tidstats->filled) 5010 if (!tidstats->filled)
4953 continue; 5011 continue;
4954 5012
4955 tidattr = nla_nest_start(msg, tid + 1); 5013 tidattr = nla_nest_start_noflag(msg, tid + 1);
4956 if (!tidattr) 5014 if (!tidattr)
4957 goto nla_put_failure; 5015 goto nla_put_failure;
4958 5016
@@ -5300,8 +5358,9 @@ static int nl80211_parse_sta_wme(struct genl_info *info,
5300 return 0; 5358 return 0;
5301 5359
5302 nla = info->attrs[NL80211_ATTR_STA_WME]; 5360 nla = info->attrs[NL80211_ATTR_STA_WME];
5303 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, 5361 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
5304 nl80211_sta_wme_policy, info->extack); 5362 nl80211_sta_wme_policy,
5363 info->extack);
5305 if (err) 5364 if (err)
5306 return err; 5365 return err;
5307 5366
@@ -5387,6 +5446,36 @@ static int nl80211_set_station_tdls(struct genl_info *info,
5387 return nl80211_parse_sta_wme(info, params); 5446 return nl80211_parse_sta_wme(info, params);
5388} 5447}
5389 5448
5449static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
5450 struct station_parameters *params)
5451{
5452 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5453 int idx;
5454
5455 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
5456 if (!rdev->ops->set_tx_power ||
5457 !wiphy_ext_feature_isset(&rdev->wiphy,
5458 NL80211_EXT_FEATURE_STA_TX_PWR))
5459 return -EOPNOTSUPP;
5460
5461 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
5462 params->txpwr.type = nla_get_u8(info->attrs[idx]);
5463
5464 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
5465 idx = NL80211_ATTR_STA_TX_POWER;
5466
5467 if (info->attrs[idx])
5468 params->txpwr.power =
5469 nla_get_s16(info->attrs[idx]);
5470 else
5471 return -EINVAL;
5472 }
5473 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
5474 }
5475
5476 return 0;
5477}
5478
5390static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 5479static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5391{ 5480{
5392 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
@@ -5480,6 +5569,10 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5480 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 5569 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5481 return -EOPNOTSUPP; 5570 return -EOPNOTSUPP;
5482 5571
5572 err = nl80211_parse_sta_txpower_setting(info, &params);
5573 if (err)
5574 return err;
5575
5483 /* Include parameters for TDLS peer (will check later) */ 5576 /* Include parameters for TDLS peer (will check later) */
5484 err = nl80211_set_station_tdls(info, &params); 5577 err = nl80211_set_station_tdls(info, &params);
5485 if (err) 5578 if (err)
@@ -5617,6 +5710,10 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
5617 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 5710 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5618 return -EOPNOTSUPP; 5711 return -EOPNOTSUPP;
5619 5712
5713 err = nl80211_parse_sta_txpower_setting(info, &params);
5714 if (err)
5715 return err;
5716
5620 err = nl80211_parse_sta_channel_info(info, &params); 5717 err = nl80211_parse_sta_channel_info(info, &params);
5621 if (err) 5718 if (err)
5622 return err; 5719 return err;
@@ -5799,7 +5896,7 @@ static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
5799 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) 5896 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5800 goto nla_put_failure; 5897 goto nla_put_failure;
5801 5898
5802 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); 5899 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
5803 if (!pinfoattr) 5900 if (!pinfoattr)
5804 goto nla_put_failure; 5901 goto nla_put_failure;
5805 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && 5902 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
@@ -6250,7 +6347,7 @@ static int nl80211_get_mesh_config(struct sk_buff *skb,
6250 NL80211_CMD_GET_MESH_CONFIG); 6347 NL80211_CMD_GET_MESH_CONFIG);
6251 if (!hdr) 6348 if (!hdr)
6252 goto out; 6349 goto out;
6253 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); 6350 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
6254 if (!pinfoattr) 6351 if (!pinfoattr)
6255 goto nla_put_failure; 6352 goto nla_put_failure;
6256 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 6353 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
@@ -6403,9 +6500,7 @@ do { \
6403 6500
6404 if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) 6501 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
6405 return -EINVAL; 6502 return -EINVAL;
6406 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, 6503 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack))
6407 info->attrs[NL80211_ATTR_MESH_CONFIG],
6408 nl80211_meshconf_params_policy, info->extack))
6409 return -EINVAL; 6504 return -EINVAL;
6410 6505
6411 /* This makes sure that there aren't more than 32 mesh config 6506 /* This makes sure that there aren't more than 32 mesh config
@@ -6538,9 +6633,7 @@ static int nl80211_parse_mesh_setup(struct genl_info *info,
6538 6633
6539 if (!info->attrs[NL80211_ATTR_MESH_SETUP]) 6634 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
6540 return -EINVAL; 6635 return -EINVAL;
6541 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, 6636 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack))
6542 info->attrs[NL80211_ATTR_MESH_SETUP],
6543 nl80211_mesh_setup_params_policy, info->extack))
6544 return -EINVAL; 6637 return -EINVAL;
6545 6638
6546 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) 6639 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
@@ -6629,7 +6722,7 @@ static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6629 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) 6722 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
6630 goto nla_put_failure; 6723 goto nla_put_failure;
6631 6724
6632 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); 6725 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
6633 if (!nl_reg_rules) 6726 if (!nl_reg_rules)
6634 goto nla_put_failure; 6727 goto nla_put_failure;
6635 6728
@@ -6644,7 +6737,7 @@ static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6644 freq_range = &reg_rule->freq_range; 6737 freq_range = &reg_rule->freq_range;
6645 power_rule = &reg_rule->power_rule; 6738 power_rule = &reg_rule->power_rule;
6646 6739
6647 nl_reg_rule = nla_nest_start(msg, i); 6740 nl_reg_rule = nla_nest_start_noflag(msg, i);
6648 if (!nl_reg_rule) 6741 if (!nl_reg_rule)
6649 goto nla_put_failure; 6742 goto nla_put_failure;
6650 6743
@@ -6882,7 +6975,7 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6882 struct nlattr *nl_reg_rule; 6975 struct nlattr *nl_reg_rule;
6883 char *alpha2; 6976 char *alpha2;
6884 int rem_reg_rules, r; 6977 int rem_reg_rules, r;
6885 u32 num_rules = 0, rule_idx = 0, size_of_regd; 6978 u32 num_rules = 0, rule_idx = 0;
6886 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; 6979 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
6887 struct ieee80211_regdomain *rd; 6980 struct ieee80211_regdomain *rd;
6888 6981
@@ -6907,10 +7000,7 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6907 if (!reg_is_valid_request(alpha2)) 7000 if (!reg_is_valid_request(alpha2))
6908 return -EINVAL; 7001 return -EINVAL;
6909 7002
6910 size_of_regd = sizeof(struct ieee80211_regdomain) + 7003 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
6911 num_rules * sizeof(struct ieee80211_reg_rule);
6912
6913 rd = kzalloc(size_of_regd, GFP_KERNEL);
6914 if (!rd) 7004 if (!rd)
6915 return -ENOMEM; 7005 return -ENOMEM;
6916 7006
@@ -6927,9 +7017,9 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6927 7017
6928 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 7018 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
6929 rem_reg_rules) { 7019 rem_reg_rules) {
6930 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, 7020 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
6931 nl_reg_rule, reg_rule_policy, 7021 nl_reg_rule, reg_rule_policy,
6932 info->extack); 7022 info->extack);
6933 if (r) 7023 if (r)
6934 goto bad_reg; 7024 goto bad_reg;
6935 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); 7025 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
@@ -7000,8 +7090,9 @@ static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7000 if (!nla_ok(nest, nla_len(nest))) 7090 if (!nla_ok(nest, nla_len(nest)))
7001 return -EINVAL; 7091 return -EINVAL;
7002 7092
7003 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, 7093 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7004 nl80211_bss_select_policy, NULL); 7094 nest, nl80211_bss_select_policy,
7095 NULL);
7005 if (err) 7096 if (err)
7006 return err; 7097 return err;
7007 7098
@@ -7494,8 +7585,10 @@ nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7494 if (WARN_ON(i >= n_plans)) 7585 if (WARN_ON(i >= n_plans))
7495 return -EINVAL; 7586 return -EINVAL;
7496 7587
7497 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, 7588 err = nla_parse_nested_deprecated(plan,
7498 attr, nl80211_plan_policy, NULL); 7589 NL80211_SCHED_SCAN_PLAN_MAX,
7590 attr, nl80211_plan_policy,
7591 NULL);
7499 if (err) 7592 if (err)
7500 return err; 7593 return err;
7501 7594
@@ -7537,6 +7630,41 @@ nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7537 return 0; 7630 return 0;
7538} 7631}
7539 7632
7633static int
7634nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
7635 struct cfg80211_match_set *match_sets,
7636 struct nlattr *tb_band_rssi,
7637 s32 rssi_thold)
7638{
7639 struct nlattr *attr;
7640 int i, tmp, ret = 0;
7641
7642 if (!wiphy_ext_feature_isset(wiphy,
7643 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
7644 if (tb_band_rssi)
7645 ret = -EOPNOTSUPP;
7646 else
7647 for (i = 0; i < NUM_NL80211_BANDS; i++)
7648 match_sets->per_band_rssi_thold[i] =
7649 NL80211_SCAN_RSSI_THOLD_OFF;
7650 return ret;
7651 }
7652
7653 for (i = 0; i < NUM_NL80211_BANDS; i++)
7654 match_sets->per_band_rssi_thold[i] = rssi_thold;
7655
7656 nla_for_each_nested(attr, tb_band_rssi, tmp) {
7657 enum nl80211_band band = nla_type(attr);
7658
7659 if (band < 0 || band >= NUM_NL80211_BANDS)
7660 return -EINVAL;
7661
7662 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
7663 }
7664
7665 return 0;
7666}
7667
7540static struct cfg80211_sched_scan_request * 7668static struct cfg80211_sched_scan_request *
7541nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, 7669nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
7542 struct nlattr **attrs, int max_match_sets) 7670 struct nlattr **attrs, int max_match_sets)
@@ -7581,10 +7709,11 @@ nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
7581 tmp) { 7709 tmp) {
7582 struct nlattr *rssi; 7710 struct nlattr *rssi;
7583 7711
7584 err = nla_parse_nested(tb, 7712 err = nla_parse_nested_deprecated(tb,
7585 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 7713 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7586 attr, nl80211_match_policy, 7714 attr,
7587 NULL); 7715 nl80211_match_policy,
7716 NULL);
7588 if (err) 7717 if (err)
7589 return ERR_PTR(err); 7718 return ERR_PTR(err);
7590 7719
@@ -7768,51 +7897,64 @@ nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
7768 tmp) { 7897 tmp) {
7769 struct nlattr *ssid, *bssid, *rssi; 7898 struct nlattr *ssid, *bssid, *rssi;
7770 7899
7771 err = nla_parse_nested(tb, 7900 err = nla_parse_nested_deprecated(tb,
7772 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 7901 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7773 attr, nl80211_match_policy, 7902 attr,
7774 NULL); 7903 nl80211_match_policy,
7904 NULL);
7775 if (err) 7905 if (err)
7776 goto out_free; 7906 goto out_free;
7777 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; 7907 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
7778 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; 7908 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
7779 if (ssid || bssid) { 7909
7780 if (WARN_ON(i >= n_match_sets)) { 7910 if (!ssid && !bssid) {
7781 /* this indicates a programming error, 7911 i++;
7782 * the loop above should have verified 7912 continue;
7783 * things properly 7913 }
7784 */ 7914
7915 if (WARN_ON(i >= n_match_sets)) {
7916 /* this indicates a programming error,
7917 * the loop above should have verified
7918 * things properly
7919 */
7920 err = -EINVAL;
7921 goto out_free;
7922 }
7923
7924 if (ssid) {
7925 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7785 err = -EINVAL; 7926 err = -EINVAL;
7786 goto out_free; 7927 goto out_free;
7787 } 7928 }
7788 7929 memcpy(request->match_sets[i].ssid.ssid,
7789 if (ssid) { 7930 nla_data(ssid), nla_len(ssid));
7790 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { 7931 request->match_sets[i].ssid.ssid_len =
7791 err = -EINVAL; 7932 nla_len(ssid);
7792 goto out_free; 7933 }
7793 } 7934 if (bssid) {
7794 memcpy(request->match_sets[i].ssid.ssid, 7935 if (nla_len(bssid) != ETH_ALEN) {
7795 nla_data(ssid), nla_len(ssid)); 7936 err = -EINVAL;
7796 request->match_sets[i].ssid.ssid_len = 7937 goto out_free;
7797 nla_len(ssid);
7798 }
7799 if (bssid) {
7800 if (nla_len(bssid) != ETH_ALEN) {
7801 err = -EINVAL;
7802 goto out_free;
7803 }
7804 memcpy(request->match_sets[i].bssid,
7805 nla_data(bssid), ETH_ALEN);
7806 } 7938 }
7939 memcpy(request->match_sets[i].bssid,
7940 nla_data(bssid), ETH_ALEN);
7941 }
7807 7942
7808 /* special attribute - old implementation w/a */ 7943 /* special attribute - old implementation w/a */
7944 request->match_sets[i].rssi_thold = default_match_rssi;
7945 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7946 if (rssi)
7809 request->match_sets[i].rssi_thold = 7947 request->match_sets[i].rssi_thold =
7810 default_match_rssi; 7948 nla_get_s32(rssi);
7811 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 7949
7812 if (rssi) 7950 /* Parse per band RSSI attribute */
7813 request->match_sets[i].rssi_thold = 7951 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
7814 nla_get_s32(rssi); 7952 &request->match_sets[i],
7815 } 7953 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
7954 request->match_sets[i].rssi_thold);
7955 if (err)
7956 goto out_free;
7957
7816 i++; 7958 i++;
7817 } 7959 }
7818 7960
@@ -8061,7 +8203,7 @@ static int nl80211_notify_radar_detection(struct sk_buff *skb,
8061 8203
8062 cfg80211_sched_dfs_chan_update(rdev); 8204 cfg80211_sched_dfs_chan_update(rdev);
8063 8205
8064 memcpy(&rdev->radar_chandef, &chandef, sizeof(chandef)); 8206 rdev->radar_chandef = chandef;
8065 8207
8066 /* Propagate this notification to other radios as well */ 8208 /* Propagate this notification to other radios as well */
8067 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); 8209 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
@@ -8143,9 +8285,9 @@ static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8143 if (err) 8285 if (err)
8144 return err; 8286 return err;
8145 8287
8146 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, 8288 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8147 info->attrs[NL80211_ATTR_CSA_IES], 8289 info->attrs[NL80211_ATTR_CSA_IES],
8148 nl80211_policy, info->extack); 8290 nl80211_policy, info->extack);
8149 if (err) 8291 if (err)
8150 return err; 8292 return err;
8151 8293
@@ -8269,7 +8411,7 @@ static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8269 NL80211_ATTR_PAD)) 8411 NL80211_ATTR_PAD))
8270 goto nla_put_failure; 8412 goto nla_put_failure;
8271 8413
8272 bss = nla_nest_start(msg, NL80211_ATTR_BSS); 8414 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
8273 if (!bss) 8415 if (!bss)
8274 goto nla_put_failure; 8416 goto nla_put_failure;
8275 if ((!is_zero_ether_addr(res->bssid) && 8417 if ((!is_zero_ether_addr(res->bssid) &&
@@ -8446,7 +8588,7 @@ static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
8446 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 8588 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8447 goto nla_put_failure; 8589 goto nla_put_failure;
8448 8590
8449 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); 8591 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
8450 if (!infoattr) 8592 if (!infoattr)
8451 goto nla_put_failure; 8593 goto nla_put_failure;
8452 8594
@@ -9287,7 +9429,7 @@ __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
9287 goto nla_put_failure; 9429 goto nla_put_failure;
9288 } 9430 }
9289 9431
9290 data = nla_nest_start(skb, attr); 9432 data = nla_nest_start_noflag(skb, attr);
9291 if (!data) 9433 if (!data)
9292 goto nla_put_failure; 9434 goto nla_put_failure;
9293 9435
@@ -9420,9 +9562,10 @@ static int nl80211_testmode_dump(struct sk_buff *skb,
9420 } else { 9562 } else {
9421 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); 9563 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
9422 9564
9423 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, 9565 err = nlmsg_parse_deprecated(cb->nlh,
9424 attrbuf, nl80211_fam.maxattr, 9566 GENL_HDRLEN + nl80211_fam.hdrsize,
9425 nl80211_policy, NULL); 9567 attrbuf, nl80211_fam.maxattr,
9568 nl80211_policy, NULL);
9426 if (err) 9569 if (err)
9427 goto out_err; 9570 goto out_err;
9428 9571
@@ -9461,7 +9604,7 @@ static int nl80211_testmode_dump(struct sk_buff *skb,
9461 break; 9604 break;
9462 } 9605 }
9463 9606
9464 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); 9607 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
9465 if (!tmdata) { 9608 if (!tmdata) {
9466 genlmsg_cancel(skb, hdr); 9609 genlmsg_cancel(skb, hdr);
9467 break; 9610 break;
@@ -10546,8 +10689,9 @@ static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
10546 if (!cqm) 10689 if (!cqm)
10547 return -EINVAL; 10690 return -EINVAL;
10548 10691
10549 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, 10692 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
10550 nl80211_attr_cqm_policy, info->extack); 10693 nl80211_attr_cqm_policy,
10694 info->extack);
10551 if (err) 10695 if (err)
10552 return err; 10696 return err;
10553 10697
@@ -10739,12 +10883,12 @@ static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
10739 if (!wowlan->n_patterns) 10883 if (!wowlan->n_patterns)
10740 return 0; 10884 return 0;
10741 10885
10742 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); 10886 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
10743 if (!nl_pats) 10887 if (!nl_pats)
10744 return -ENOBUFS; 10888 return -ENOBUFS;
10745 10889
10746 for (i = 0; i < wowlan->n_patterns; i++) { 10890 for (i = 0; i < wowlan->n_patterns; i++) {
10747 nl_pat = nla_nest_start(msg, i + 1); 10891 nl_pat = nla_nest_start_noflag(msg, i + 1);
10748 if (!nl_pat) 10892 if (!nl_pat)
10749 return -ENOBUFS; 10893 return -ENOBUFS;
10750 pat_len = wowlan->patterns[i].pattern_len; 10894 pat_len = wowlan->patterns[i].pattern_len;
@@ -10770,7 +10914,8 @@ static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
10770 if (!tcp) 10914 if (!tcp)
10771 return 0; 10915 return 0;
10772 10916
10773 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); 10917 nl_tcp = nla_nest_start_noflag(msg,
10918 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
10774 if (!nl_tcp) 10919 if (!nl_tcp)
10775 return -ENOBUFS; 10920 return -ENOBUFS;
10776 10921
@@ -10814,7 +10959,7 @@ static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10814 if (!req) 10959 if (!req)
10815 return 0; 10960 return 0;
10816 10961
10817 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); 10962 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
10818 if (!nd) 10963 if (!nd)
10819 return -ENOBUFS; 10964 return -ENOBUFS;
10820 10965
@@ -10840,7 +10985,7 @@ static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10840 return -ENOBUFS; 10985 return -ENOBUFS;
10841 } 10986 }
10842 10987
10843 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); 10988 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10844 if (!freqs) 10989 if (!freqs)
10845 return -ENOBUFS; 10990 return -ENOBUFS;
10846 10991
@@ -10852,12 +10997,13 @@ static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10852 nla_nest_end(msg, freqs); 10997 nla_nest_end(msg, freqs);
10853 10998
10854 if (req->n_match_sets) { 10999 if (req->n_match_sets) {
10855 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); 11000 matches = nla_nest_start_noflag(msg,
11001 NL80211_ATTR_SCHED_SCAN_MATCH);
10856 if (!matches) 11002 if (!matches)
10857 return -ENOBUFS; 11003 return -ENOBUFS;
10858 11004
10859 for (i = 0; i < req->n_match_sets; i++) { 11005 for (i = 0; i < req->n_match_sets; i++) {
10860 match = nla_nest_start(msg, i); 11006 match = nla_nest_start_noflag(msg, i);
10861 if (!match) 11007 if (!match)
10862 return -ENOBUFS; 11008 return -ENOBUFS;
10863 11009
@@ -10870,12 +11016,12 @@ static int nl80211_send_wowlan_nd(struct sk_buff *msg,
10870 nla_nest_end(msg, matches); 11016 nla_nest_end(msg, matches);
10871 } 11017 }
10872 11018
10873 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); 11019 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
10874 if (!scan_plans) 11020 if (!scan_plans)
10875 return -ENOBUFS; 11021 return -ENOBUFS;
10876 11022
10877 for (i = 0; i < req->n_scan_plans; i++) { 11023 for (i = 0; i < req->n_scan_plans; i++) {
10878 scan_plan = nla_nest_start(msg, i + 1); 11024 scan_plan = nla_nest_start_noflag(msg, i + 1);
10879 if (!scan_plan) 11025 if (!scan_plan)
10880 return -ENOBUFS; 11026 return -ENOBUFS;
10881 11027
@@ -10924,7 +11070,8 @@ static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
10924 if (rdev->wiphy.wowlan_config) { 11070 if (rdev->wiphy.wowlan_config) {
10925 struct nlattr *nl_wowlan; 11071 struct nlattr *nl_wowlan;
10926 11072
10927 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); 11073 nl_wowlan = nla_nest_start_noflag(msg,
11074 NL80211_ATTR_WOWLAN_TRIGGERS);
10928 if (!nl_wowlan) 11075 if (!nl_wowlan)
10929 goto nla_put_failure; 11076 goto nla_put_failure;
10930 11077
@@ -10982,8 +11129,8 @@ static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10982 if (!rdev->wiphy.wowlan->tcp) 11129 if (!rdev->wiphy.wowlan->tcp)
10983 return -EINVAL; 11130 return -EINVAL;
10984 11131
10985 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, 11132 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
10986 nl80211_wowlan_tcp_policy, NULL); 11133 nl80211_wowlan_tcp_policy, NULL);
10987 if (err) 11134 if (err)
10988 return err; 11135 return err;
10989 11136
@@ -11128,8 +11275,8 @@ static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11128 goto out; 11275 goto out;
11129 } 11276 }
11130 11277
11131 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy, 11278 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
11132 NULL); 11279 nl80211_policy, NULL);
11133 if (err) 11280 if (err)
11134 goto out; 11281 goto out;
11135 11282
@@ -11164,9 +11311,9 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11164 goto set_wakeup; 11311 goto set_wakeup;
11165 } 11312 }
11166 11313
11167 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, 11314 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
11168 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], 11315 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
11169 nl80211_wowlan_policy, info->extack); 11316 nl80211_wowlan_policy, info->extack);
11170 if (err) 11317 if (err)
11171 return err; 11318 return err;
11172 11319
@@ -11248,9 +11395,11 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11248 rem) { 11395 rem) {
11249 u8 *mask_pat; 11396 u8 *mask_pat;
11250 11397
11251 err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, 11398 err = nla_parse_nested_deprecated(pat_tb,
11252 nl80211_packet_pattern_policy, 11399 MAX_NL80211_PKTPAT,
11253 info->extack); 11400 pat,
11401 nl80211_packet_pattern_policy,
11402 info->extack);
11254 if (err) 11403 if (err)
11255 goto error; 11404 goto error;
11256 11405
@@ -11358,12 +11507,12 @@ static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11358 if (!rdev->coalesce->n_rules) 11507 if (!rdev->coalesce->n_rules)
11359 return 0; 11508 return 0;
11360 11509
11361 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); 11510 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
11362 if (!nl_rules) 11511 if (!nl_rules)
11363 return -ENOBUFS; 11512 return -ENOBUFS;
11364 11513
11365 for (i = 0; i < rdev->coalesce->n_rules; i++) { 11514 for (i = 0; i < rdev->coalesce->n_rules; i++) {
11366 nl_rule = nla_nest_start(msg, i + 1); 11515 nl_rule = nla_nest_start_noflag(msg, i + 1);
11367 if (!nl_rule) 11516 if (!nl_rule)
11368 return -ENOBUFS; 11517 return -ENOBUFS;
11369 11518
@@ -11376,13 +11525,13 @@ static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11376 rule->condition)) 11525 rule->condition))
11377 return -ENOBUFS; 11526 return -ENOBUFS;
11378 11527
11379 nl_pats = nla_nest_start(msg, 11528 nl_pats = nla_nest_start_noflag(msg,
11380 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); 11529 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
11381 if (!nl_pats) 11530 if (!nl_pats)
11382 return -ENOBUFS; 11531 return -ENOBUFS;
11383 11532
11384 for (j = 0; j < rule->n_patterns; j++) { 11533 for (j = 0; j < rule->n_patterns; j++) {
11385 nl_pat = nla_nest_start(msg, j + 1); 11534 nl_pat = nla_nest_start_noflag(msg, j + 1);
11386 if (!nl_pat) 11535 if (!nl_pat)
11387 return -ENOBUFS; 11536 return -ENOBUFS;
11388 pat_len = rule->patterns[j].pattern_len; 11537 pat_len = rule->patterns[j].pattern_len;
@@ -11463,8 +11612,8 @@ static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11463 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; 11612 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
11464 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 11613 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
11465 11614
11466 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, 11615 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
11467 nl80211_coalesce_policy, NULL); 11616 rule, nl80211_coalesce_policy, NULL);
11468 if (err) 11617 if (err)
11469 return err; 11618 return err;
11470 11619
@@ -11499,8 +11648,10 @@ static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
11499 rem) { 11648 rem) {
11500 u8 *mask_pat; 11649 u8 *mask_pat;
11501 11650
11502 err = nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, 11651 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
11503 nl80211_packet_pattern_policy, NULL); 11652 pat,
11653 nl80211_packet_pattern_policy,
11654 NULL);
11504 if (err) 11655 if (err)
11505 return err; 11656 return err;
11506 11657
@@ -11622,9 +11773,9 @@ static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
11622 if (!info->attrs[NL80211_ATTR_REKEY_DATA]) 11773 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
11623 return -EINVAL; 11774 return -EINVAL;
11624 11775
11625 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, 11776 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
11626 info->attrs[NL80211_ATTR_REKEY_DATA], 11777 info->attrs[NL80211_ATTR_REKEY_DATA],
11627 nl80211_rekey_policy, info->extack); 11778 nl80211_rekey_policy, info->extack);
11628 if (err) 11779 if (err)
11629 return err; 11780 return err;
11630 11781
@@ -11936,9 +12087,10 @@ static int nl80211_nan_add_func(struct sk_buff *skb,
11936 if (!info->attrs[NL80211_ATTR_NAN_FUNC]) 12087 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
11937 return -EINVAL; 12088 return -EINVAL;
11938 12089
11939 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, 12090 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
11940 info->attrs[NL80211_ATTR_NAN_FUNC], 12091 info->attrs[NL80211_ATTR_NAN_FUNC],
11941 nl80211_nan_func_policy, info->extack); 12092 nl80211_nan_func_policy,
12093 info->extack);
11942 if (err) 12094 if (err)
11943 return err; 12095 return err;
11944 12096
@@ -12034,9 +12186,11 @@ static int nl80211_nan_add_func(struct sk_buff *skb,
12034 if (tb[NL80211_NAN_FUNC_SRF]) { 12186 if (tb[NL80211_NAN_FUNC_SRF]) {
12035 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; 12187 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12036 12188
12037 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, 12189 err = nla_parse_nested_deprecated(srf_tb,
12038 tb[NL80211_NAN_FUNC_SRF], 12190 NL80211_NAN_SRF_ATTR_MAX,
12039 nl80211_nan_srf_policy, info->extack); 12191 tb[NL80211_NAN_FUNC_SRF],
12192 nl80211_nan_srf_policy,
12193 info->extack);
12040 if (err) 12194 if (err)
12041 goto out; 12195 goto out;
12042 12196
@@ -12134,7 +12288,7 @@ out:
12134 NL80211_ATTR_PAD)) 12288 NL80211_ATTR_PAD))
12135 goto nla_put_failure; 12289 goto nla_put_failure;
12136 12290
12137 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); 12291 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
12138 if (!func_attr) 12292 if (!func_attr)
12139 goto nla_put_failure; 12293 goto nla_put_failure;
12140 12294
@@ -12251,11 +12405,12 @@ void cfg80211_nan_match(struct wireless_dev *wdev,
12251 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) 12405 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12252 goto nla_put_failure; 12406 goto nla_put_failure;
12253 12407
12254 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); 12408 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
12255 if (!match_attr) 12409 if (!match_attr)
12256 goto nla_put_failure; 12410 goto nla_put_failure;
12257 12411
12258 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); 12412 local_func_attr = nla_nest_start_noflag(msg,
12413 NL80211_NAN_MATCH_FUNC_LOCAL);
12259 if (!local_func_attr) 12414 if (!local_func_attr)
12260 goto nla_put_failure; 12415 goto nla_put_failure;
12261 12416
@@ -12264,7 +12419,8 @@ void cfg80211_nan_match(struct wireless_dev *wdev,
12264 12419
12265 nla_nest_end(msg, local_func_attr); 12420 nla_nest_end(msg, local_func_attr);
12266 12421
12267 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); 12422 peer_func_attr = nla_nest_start_noflag(msg,
12423 NL80211_NAN_MATCH_FUNC_PEER);
12268 if (!peer_func_attr) 12424 if (!peer_func_attr)
12269 goto nla_put_failure; 12425 goto nla_put_failure;
12270 12426
@@ -12330,7 +12486,7 @@ void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12330 NL80211_ATTR_PAD)) 12486 NL80211_ATTR_PAD))
12331 goto nla_put_failure; 12487 goto nla_put_failure;
12332 12488
12333 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); 12489 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
12334 if (!func_attr) 12490 if (!func_attr)
12335 goto nla_put_failure; 12491 goto nla_put_failure;
12336 12492
@@ -12567,8 +12723,10 @@ static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
12567 return 0; 12723 return 0;
12568 } 12724 }
12569 12725
12570 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf, 12726 err = nlmsg_parse_deprecated(cb->nlh,
12571 nl80211_fam.maxattr, nl80211_policy, NULL); 12727 GENL_HDRLEN + nl80211_fam.hdrsize,
12728 attrbuf, nl80211_fam.maxattr,
12729 nl80211_policy, NULL);
12572 if (err) 12730 if (err)
12573 return err; 12731 return err;
12574 12732
@@ -12679,7 +12837,8 @@ static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
12679 break; 12837 break;
12680 } 12838 }
12681 12839
12682 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); 12840 vendor_data = nla_nest_start_noflag(skb,
12841 NL80211_ATTR_VENDOR_DATA);
12683 if (!vendor_data) { 12842 if (!vendor_data) {
12684 genlmsg_cancel(skb, hdr); 12843 genlmsg_cancel(skb, hdr);
12685 break; 12844 break;
@@ -13223,7 +13382,8 @@ static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13223 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 13382 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13224 goto nla_put_failure; 13383 goto nla_put_failure;
13225 13384
13226 ftm_stats_attr = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER_STATS); 13385 ftm_stats_attr = nla_nest_start_noflag(msg,
13386 NL80211_ATTR_FTM_RESPONDER_STATS);
13227 if (!ftm_stats_attr) 13387 if (!ftm_stats_attr)
13228 goto nla_put_failure; 13388 goto nla_put_failure;
13229 13389
@@ -13259,6 +13419,72 @@ nla_put_failure:
13259 return -ENOBUFS; 13419 return -ENOBUFS;
13260} 13420}
13261 13421
13422static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
13423{
13424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13425 struct cfg80211_update_owe_info owe_info;
13426 struct net_device *dev = info->user_ptr[1];
13427
13428 if (!rdev->ops->update_owe_info)
13429 return -EOPNOTSUPP;
13430
13431 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
13432 !info->attrs[NL80211_ATTR_MAC])
13433 return -EINVAL;
13434
13435 memset(&owe_info, 0, sizeof(owe_info));
13436 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13437 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
13438
13439 if (info->attrs[NL80211_ATTR_IE]) {
13440 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13441 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13442 }
13443
13444 return rdev_update_owe_info(rdev, dev, &owe_info);
13445}
13446
13447static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
13448{
13449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13450 struct net_device *dev = info->user_ptr[1];
13451 struct wireless_dev *wdev = dev->ieee80211_ptr;
13452 struct station_info sinfo = {};
13453 const u8 *buf;
13454 size_t len;
13455 u8 *dest;
13456 int err;
13457
13458 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
13459 return -EOPNOTSUPP;
13460
13461 if (!info->attrs[NL80211_ATTR_MAC] ||
13462 !info->attrs[NL80211_ATTR_FRAME]) {
13463 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
13464 return -EINVAL;
13465 }
13466
13467 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
13468 return -EOPNOTSUPP;
13469
13470 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13471 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13472 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13473
13474 if (len < sizeof(struct ethhdr))
13475 return -EINVAL;
13476
13477 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
13478 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
13479 return -EINVAL;
13480
13481 err = rdev_get_station(rdev, dev, dest, &sinfo);
13482 if (err)
13483 return err;
13484
13485 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
13486}
13487
13262#define NL80211_FLAG_NEED_WIPHY 0x01 13488#define NL80211_FLAG_NEED_WIPHY 0x01
13263#define NL80211_FLAG_NEED_NETDEV 0x02 13489#define NL80211_FLAG_NEED_NETDEV 0x02
13264#define NL80211_FLAG_NEED_RTNL 0x04 13490#define NL80211_FLAG_NEED_RTNL 0x04
@@ -13365,66 +13591,66 @@ static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
13365static const struct genl_ops nl80211_ops[] = { 13591static const struct genl_ops nl80211_ops[] = {
13366 { 13592 {
13367 .cmd = NL80211_CMD_GET_WIPHY, 13593 .cmd = NL80211_CMD_GET_WIPHY,
13594 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13368 .doit = nl80211_get_wiphy, 13595 .doit = nl80211_get_wiphy,
13369 .dumpit = nl80211_dump_wiphy, 13596 .dumpit = nl80211_dump_wiphy,
13370 .done = nl80211_dump_wiphy_done, 13597 .done = nl80211_dump_wiphy_done,
13371 .policy = nl80211_policy,
13372 /* can be retrieved by unprivileged users */ 13598 /* can be retrieved by unprivileged users */
13373 .internal_flags = NL80211_FLAG_NEED_WIPHY | 13599 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13374 NL80211_FLAG_NEED_RTNL, 13600 NL80211_FLAG_NEED_RTNL,
13375 }, 13601 },
13376 { 13602 {
13377 .cmd = NL80211_CMD_SET_WIPHY, 13603 .cmd = NL80211_CMD_SET_WIPHY,
13604 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13378 .doit = nl80211_set_wiphy, 13605 .doit = nl80211_set_wiphy,
13379 .policy = nl80211_policy,
13380 .flags = GENL_UNS_ADMIN_PERM, 13606 .flags = GENL_UNS_ADMIN_PERM,
13381 .internal_flags = NL80211_FLAG_NEED_RTNL, 13607 .internal_flags = NL80211_FLAG_NEED_RTNL,
13382 }, 13608 },
13383 { 13609 {
13384 .cmd = NL80211_CMD_GET_INTERFACE, 13610 .cmd = NL80211_CMD_GET_INTERFACE,
13611 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13385 .doit = nl80211_get_interface, 13612 .doit = nl80211_get_interface,
13386 .dumpit = nl80211_dump_interface, 13613 .dumpit = nl80211_dump_interface,
13387 .policy = nl80211_policy,
13388 /* can be retrieved by unprivileged users */ 13614 /* can be retrieved by unprivileged users */
13389 .internal_flags = NL80211_FLAG_NEED_WDEV | 13615 .internal_flags = NL80211_FLAG_NEED_WDEV |
13390 NL80211_FLAG_NEED_RTNL, 13616 NL80211_FLAG_NEED_RTNL,
13391 }, 13617 },
13392 { 13618 {
13393 .cmd = NL80211_CMD_SET_INTERFACE, 13619 .cmd = NL80211_CMD_SET_INTERFACE,
13620 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13394 .doit = nl80211_set_interface, 13621 .doit = nl80211_set_interface,
13395 .policy = nl80211_policy,
13396 .flags = GENL_UNS_ADMIN_PERM, 13622 .flags = GENL_UNS_ADMIN_PERM,
13397 .internal_flags = NL80211_FLAG_NEED_NETDEV | 13623 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13398 NL80211_FLAG_NEED_RTNL, 13624 NL80211_FLAG_NEED_RTNL,
13399 }, 13625 },
13400 { 13626 {
13401 .cmd = NL80211_CMD_NEW_INTERFACE, 13627 .cmd = NL80211_CMD_NEW_INTERFACE,
13628 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13402 .doit = nl80211_new_interface, 13629 .doit = nl80211_new_interface,
13403 .policy = nl80211_policy,
13404 .flags = GENL_UNS_ADMIN_PERM, 13630 .flags = GENL_UNS_ADMIN_PERM,
13405 .internal_flags = NL80211_FLAG_NEED_WIPHY | 13631 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13406 NL80211_FLAG_NEED_RTNL, 13632 NL80211_FLAG_NEED_RTNL,
13407 }, 13633 },
13408 { 13634 {
13409 .cmd = NL80211_CMD_DEL_INTERFACE, 13635 .cmd = NL80211_CMD_DEL_INTERFACE,
13636 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13410 .doit = nl80211_del_interface, 13637 .doit = nl80211_del_interface,
13411 .policy = nl80211_policy,
13412 .flags = GENL_UNS_ADMIN_PERM, 13638 .flags = GENL_UNS_ADMIN_PERM,
13413 .internal_flags = NL80211_FLAG_NEED_WDEV | 13639 .internal_flags = NL80211_FLAG_NEED_WDEV |
13414 NL80211_FLAG_NEED_RTNL, 13640 NL80211_FLAG_NEED_RTNL,
13415 }, 13641 },
13416 { 13642 {
13417 .cmd = NL80211_CMD_GET_KEY, 13643 .cmd = NL80211_CMD_GET_KEY,
13644 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13418 .doit = nl80211_get_key, 13645 .doit = nl80211_get_key,
13419 .policy = nl80211_policy,
13420 .flags = GENL_UNS_ADMIN_PERM, 13646 .flags = GENL_UNS_ADMIN_PERM,
13421 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13422 NL80211_FLAG_NEED_RTNL, 13648 NL80211_FLAG_NEED_RTNL,
13423 }, 13649 },
13424 { 13650 {
13425 .cmd = NL80211_CMD_SET_KEY, 13651 .cmd = NL80211_CMD_SET_KEY,
13652 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13426 .doit = nl80211_set_key, 13653 .doit = nl80211_set_key,
13427 .policy = nl80211_policy,
13428 .flags = GENL_UNS_ADMIN_PERM, 13654 .flags = GENL_UNS_ADMIN_PERM,
13429 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13430 NL80211_FLAG_NEED_RTNL | 13656 NL80211_FLAG_NEED_RTNL |
@@ -13432,8 +13658,8 @@ static const struct genl_ops nl80211_ops[] = {
13432 }, 13658 },
13433 { 13659 {
13434 .cmd = NL80211_CMD_NEW_KEY, 13660 .cmd = NL80211_CMD_NEW_KEY,
13661 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13435 .doit = nl80211_new_key, 13662 .doit = nl80211_new_key,
13436 .policy = nl80211_policy,
13437 .flags = GENL_UNS_ADMIN_PERM, 13663 .flags = GENL_UNS_ADMIN_PERM,
13438 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13664 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13439 NL80211_FLAG_NEED_RTNL | 13665 NL80211_FLAG_NEED_RTNL |
@@ -13441,15 +13667,15 @@ static const struct genl_ops nl80211_ops[] = {
13441 }, 13667 },
13442 { 13668 {
13443 .cmd = NL80211_CMD_DEL_KEY, 13669 .cmd = NL80211_CMD_DEL_KEY,
13670 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13444 .doit = nl80211_del_key, 13671 .doit = nl80211_del_key,
13445 .policy = nl80211_policy,
13446 .flags = GENL_UNS_ADMIN_PERM, 13672 .flags = GENL_UNS_ADMIN_PERM,
13447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13673 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13448 NL80211_FLAG_NEED_RTNL, 13674 NL80211_FLAG_NEED_RTNL,
13449 }, 13675 },
13450 { 13676 {
13451 .cmd = NL80211_CMD_SET_BEACON, 13677 .cmd = NL80211_CMD_SET_BEACON,
13452 .policy = nl80211_policy, 13678 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13453 .flags = GENL_UNS_ADMIN_PERM, 13679 .flags = GENL_UNS_ADMIN_PERM,
13454 .doit = nl80211_set_beacon, 13680 .doit = nl80211_set_beacon,
13455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13681 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
@@ -13457,7 +13683,7 @@ static const struct genl_ops nl80211_ops[] = {
13457 }, 13683 },
13458 { 13684 {
13459 .cmd = NL80211_CMD_START_AP, 13685 .cmd = NL80211_CMD_START_AP,
13460 .policy = nl80211_policy, 13686 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13461 .flags = GENL_UNS_ADMIN_PERM, 13687 .flags = GENL_UNS_ADMIN_PERM,
13462 .doit = nl80211_start_ap, 13688 .doit = nl80211_start_ap,
13463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13689 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
@@ -13465,7 +13691,7 @@ static const struct genl_ops nl80211_ops[] = {
13465 }, 13691 },
13466 { 13692 {
13467 .cmd = NL80211_CMD_STOP_AP, 13693 .cmd = NL80211_CMD_STOP_AP,
13468 .policy = nl80211_policy, 13694 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13469 .flags = GENL_UNS_ADMIN_PERM, 13695 .flags = GENL_UNS_ADMIN_PERM,
13470 .doit = nl80211_stop_ap, 13696 .doit = nl80211_stop_ap,
13471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13697 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
@@ -13473,172 +13699,172 @@ static const struct genl_ops nl80211_ops[] = {
13473 }, 13699 },
13474 { 13700 {
13475 .cmd = NL80211_CMD_GET_STATION, 13701 .cmd = NL80211_CMD_GET_STATION,
13702 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13476 .doit = nl80211_get_station, 13703 .doit = nl80211_get_station,
13477 .dumpit = nl80211_dump_station, 13704 .dumpit = nl80211_dump_station,
13478 .policy = nl80211_policy,
13479 .internal_flags = NL80211_FLAG_NEED_NETDEV | 13705 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13480 NL80211_FLAG_NEED_RTNL, 13706 NL80211_FLAG_NEED_RTNL,
13481 }, 13707 },
13482 { 13708 {
13483 .cmd = NL80211_CMD_SET_STATION, 13709 .cmd = NL80211_CMD_SET_STATION,
13710 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13484 .doit = nl80211_set_station, 13711 .doit = nl80211_set_station,
13485 .policy = nl80211_policy,
13486 .flags = GENL_UNS_ADMIN_PERM, 13712 .flags = GENL_UNS_ADMIN_PERM,
13487 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13713 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13488 NL80211_FLAG_NEED_RTNL, 13714 NL80211_FLAG_NEED_RTNL,
13489 }, 13715 },
13490 { 13716 {
13491 .cmd = NL80211_CMD_NEW_STATION, 13717 .cmd = NL80211_CMD_NEW_STATION,
13718 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13492 .doit = nl80211_new_station, 13719 .doit = nl80211_new_station,
13493 .policy = nl80211_policy,
13494 .flags = GENL_UNS_ADMIN_PERM, 13720 .flags = GENL_UNS_ADMIN_PERM,
13495 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13721 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13496 NL80211_FLAG_NEED_RTNL, 13722 NL80211_FLAG_NEED_RTNL,
13497 }, 13723 },
13498 { 13724 {
13499 .cmd = NL80211_CMD_DEL_STATION, 13725 .cmd = NL80211_CMD_DEL_STATION,
13726 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13500 .doit = nl80211_del_station, 13727 .doit = nl80211_del_station,
13501 .policy = nl80211_policy,
13502 .flags = GENL_UNS_ADMIN_PERM, 13728 .flags = GENL_UNS_ADMIN_PERM,
13503 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13729 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13504 NL80211_FLAG_NEED_RTNL, 13730 NL80211_FLAG_NEED_RTNL,
13505 }, 13731 },
13506 { 13732 {
13507 .cmd = NL80211_CMD_GET_MPATH, 13733 .cmd = NL80211_CMD_GET_MPATH,
13734 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13508 .doit = nl80211_get_mpath, 13735 .doit = nl80211_get_mpath,
13509 .dumpit = nl80211_dump_mpath, 13736 .dumpit = nl80211_dump_mpath,
13510 .policy = nl80211_policy,
13511 .flags = GENL_UNS_ADMIN_PERM, 13737 .flags = GENL_UNS_ADMIN_PERM,
13512 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13738 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13513 NL80211_FLAG_NEED_RTNL, 13739 NL80211_FLAG_NEED_RTNL,
13514 }, 13740 },
13515 { 13741 {
13516 .cmd = NL80211_CMD_GET_MPP, 13742 .cmd = NL80211_CMD_GET_MPP,
13743 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13517 .doit = nl80211_get_mpp, 13744 .doit = nl80211_get_mpp,
13518 .dumpit = nl80211_dump_mpp, 13745 .dumpit = nl80211_dump_mpp,
13519 .policy = nl80211_policy,
13520 .flags = GENL_UNS_ADMIN_PERM, 13746 .flags = GENL_UNS_ADMIN_PERM,
13521 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13747 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13522 NL80211_FLAG_NEED_RTNL, 13748 NL80211_FLAG_NEED_RTNL,
13523 }, 13749 },
13524 { 13750 {
13525 .cmd = NL80211_CMD_SET_MPATH, 13751 .cmd = NL80211_CMD_SET_MPATH,
13752 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13526 .doit = nl80211_set_mpath, 13753 .doit = nl80211_set_mpath,
13527 .policy = nl80211_policy,
13528 .flags = GENL_UNS_ADMIN_PERM, 13754 .flags = GENL_UNS_ADMIN_PERM,
13529 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13530 NL80211_FLAG_NEED_RTNL, 13756 NL80211_FLAG_NEED_RTNL,
13531 }, 13757 },
13532 { 13758 {
13533 .cmd = NL80211_CMD_NEW_MPATH, 13759 .cmd = NL80211_CMD_NEW_MPATH,
13760 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13534 .doit = nl80211_new_mpath, 13761 .doit = nl80211_new_mpath,
13535 .policy = nl80211_policy,
13536 .flags = GENL_UNS_ADMIN_PERM, 13762 .flags = GENL_UNS_ADMIN_PERM,
13537 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13763 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13538 NL80211_FLAG_NEED_RTNL, 13764 NL80211_FLAG_NEED_RTNL,
13539 }, 13765 },
13540 { 13766 {
13541 .cmd = NL80211_CMD_DEL_MPATH, 13767 .cmd = NL80211_CMD_DEL_MPATH,
13768 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13542 .doit = nl80211_del_mpath, 13769 .doit = nl80211_del_mpath,
13543 .policy = nl80211_policy,
13544 .flags = GENL_UNS_ADMIN_PERM, 13770 .flags = GENL_UNS_ADMIN_PERM,
13545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13771 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13546 NL80211_FLAG_NEED_RTNL, 13772 NL80211_FLAG_NEED_RTNL,
13547 }, 13773 },
13548 { 13774 {
13549 .cmd = NL80211_CMD_SET_BSS, 13775 .cmd = NL80211_CMD_SET_BSS,
13776 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13550 .doit = nl80211_set_bss, 13777 .doit = nl80211_set_bss,
13551 .policy = nl80211_policy,
13552 .flags = GENL_UNS_ADMIN_PERM, 13778 .flags = GENL_UNS_ADMIN_PERM,
13553 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13779 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13554 NL80211_FLAG_NEED_RTNL, 13780 NL80211_FLAG_NEED_RTNL,
13555 }, 13781 },
13556 { 13782 {
13557 .cmd = NL80211_CMD_GET_REG, 13783 .cmd = NL80211_CMD_GET_REG,
13784 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13558 .doit = nl80211_get_reg_do, 13785 .doit = nl80211_get_reg_do,
13559 .dumpit = nl80211_get_reg_dump, 13786 .dumpit = nl80211_get_reg_dump,
13560 .policy = nl80211_policy,
13561 .internal_flags = NL80211_FLAG_NEED_RTNL, 13787 .internal_flags = NL80211_FLAG_NEED_RTNL,
13562 /* can be retrieved by unprivileged users */ 13788 /* can be retrieved by unprivileged users */
13563 }, 13789 },
13564#ifdef CONFIG_CFG80211_CRDA_SUPPORT 13790#ifdef CONFIG_CFG80211_CRDA_SUPPORT
13565 { 13791 {
13566 .cmd = NL80211_CMD_SET_REG, 13792 .cmd = NL80211_CMD_SET_REG,
13793 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13567 .doit = nl80211_set_reg, 13794 .doit = nl80211_set_reg,
13568 .policy = nl80211_policy,
13569 .flags = GENL_ADMIN_PERM, 13795 .flags = GENL_ADMIN_PERM,
13570 .internal_flags = NL80211_FLAG_NEED_RTNL, 13796 .internal_flags = NL80211_FLAG_NEED_RTNL,
13571 }, 13797 },
13572#endif 13798#endif
13573 { 13799 {
13574 .cmd = NL80211_CMD_REQ_SET_REG, 13800 .cmd = NL80211_CMD_REQ_SET_REG,
13801 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13575 .doit = nl80211_req_set_reg, 13802 .doit = nl80211_req_set_reg,
13576 .policy = nl80211_policy,
13577 .flags = GENL_ADMIN_PERM, 13803 .flags = GENL_ADMIN_PERM,
13578 }, 13804 },
13579 { 13805 {
13580 .cmd = NL80211_CMD_RELOAD_REGDB, 13806 .cmd = NL80211_CMD_RELOAD_REGDB,
13807 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13581 .doit = nl80211_reload_regdb, 13808 .doit = nl80211_reload_regdb,
13582 .policy = nl80211_policy,
13583 .flags = GENL_ADMIN_PERM, 13809 .flags = GENL_ADMIN_PERM,
13584 }, 13810 },
13585 { 13811 {
13586 .cmd = NL80211_CMD_GET_MESH_CONFIG, 13812 .cmd = NL80211_CMD_GET_MESH_CONFIG,
13813 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13587 .doit = nl80211_get_mesh_config, 13814 .doit = nl80211_get_mesh_config,
13588 .policy = nl80211_policy,
13589 /* can be retrieved by unprivileged users */ 13815 /* can be retrieved by unprivileged users */
13590 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13816 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13591 NL80211_FLAG_NEED_RTNL, 13817 NL80211_FLAG_NEED_RTNL,
13592 }, 13818 },
13593 { 13819 {
13594 .cmd = NL80211_CMD_SET_MESH_CONFIG, 13820 .cmd = NL80211_CMD_SET_MESH_CONFIG,
13821 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13595 .doit = nl80211_update_mesh_config, 13822 .doit = nl80211_update_mesh_config,
13596 .policy = nl80211_policy,
13597 .flags = GENL_UNS_ADMIN_PERM, 13823 .flags = GENL_UNS_ADMIN_PERM,
13598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13824 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13599 NL80211_FLAG_NEED_RTNL, 13825 NL80211_FLAG_NEED_RTNL,
13600 }, 13826 },
13601 { 13827 {
13602 .cmd = NL80211_CMD_TRIGGER_SCAN, 13828 .cmd = NL80211_CMD_TRIGGER_SCAN,
13829 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13603 .doit = nl80211_trigger_scan, 13830 .doit = nl80211_trigger_scan,
13604 .policy = nl80211_policy,
13605 .flags = GENL_UNS_ADMIN_PERM, 13831 .flags = GENL_UNS_ADMIN_PERM,
13606 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 13832 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13607 NL80211_FLAG_NEED_RTNL, 13833 NL80211_FLAG_NEED_RTNL,
13608 }, 13834 },
13609 { 13835 {
13610 .cmd = NL80211_CMD_ABORT_SCAN, 13836 .cmd = NL80211_CMD_ABORT_SCAN,
13837 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13611 .doit = nl80211_abort_scan, 13838 .doit = nl80211_abort_scan,
13612 .policy = nl80211_policy,
13613 .flags = GENL_UNS_ADMIN_PERM, 13839 .flags = GENL_UNS_ADMIN_PERM,
13614 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 13840 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13615 NL80211_FLAG_NEED_RTNL, 13841 NL80211_FLAG_NEED_RTNL,
13616 }, 13842 },
13617 { 13843 {
13618 .cmd = NL80211_CMD_GET_SCAN, 13844 .cmd = NL80211_CMD_GET_SCAN,
13619 .policy = nl80211_policy, 13845 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13620 .dumpit = nl80211_dump_scan, 13846 .dumpit = nl80211_dump_scan,
13621 }, 13847 },
13622 { 13848 {
13623 .cmd = NL80211_CMD_START_SCHED_SCAN, 13849 .cmd = NL80211_CMD_START_SCHED_SCAN,
13850 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13624 .doit = nl80211_start_sched_scan, 13851 .doit = nl80211_start_sched_scan,
13625 .policy = nl80211_policy,
13626 .flags = GENL_UNS_ADMIN_PERM, 13852 .flags = GENL_UNS_ADMIN_PERM,
13627 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13628 NL80211_FLAG_NEED_RTNL, 13854 NL80211_FLAG_NEED_RTNL,
13629 }, 13855 },
13630 { 13856 {
13631 .cmd = NL80211_CMD_STOP_SCHED_SCAN, 13857 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
13858 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13632 .doit = nl80211_stop_sched_scan, 13859 .doit = nl80211_stop_sched_scan,
13633 .policy = nl80211_policy,
13634 .flags = GENL_UNS_ADMIN_PERM, 13860 .flags = GENL_UNS_ADMIN_PERM,
13635 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13861 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13636 NL80211_FLAG_NEED_RTNL, 13862 NL80211_FLAG_NEED_RTNL,
13637 }, 13863 },
13638 { 13864 {
13639 .cmd = NL80211_CMD_AUTHENTICATE, 13865 .cmd = NL80211_CMD_AUTHENTICATE,
13866 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13640 .doit = nl80211_authenticate, 13867 .doit = nl80211_authenticate,
13641 .policy = nl80211_policy,
13642 .flags = GENL_UNS_ADMIN_PERM, 13868 .flags = GENL_UNS_ADMIN_PERM,
13643 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13869 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13644 NL80211_FLAG_NEED_RTNL | 13870 NL80211_FLAG_NEED_RTNL |
@@ -13646,40 +13872,41 @@ static const struct genl_ops nl80211_ops[] = {
13646 }, 13872 },
13647 { 13873 {
13648 .cmd = NL80211_CMD_ASSOCIATE, 13874 .cmd = NL80211_CMD_ASSOCIATE,
13875 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13649 .doit = nl80211_associate, 13876 .doit = nl80211_associate,
13650 .policy = nl80211_policy,
13651 .flags = GENL_UNS_ADMIN_PERM, 13877 .flags = GENL_UNS_ADMIN_PERM,
13652 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13878 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13653 NL80211_FLAG_NEED_RTNL, 13879 NL80211_FLAG_NEED_RTNL |
13880 NL80211_FLAG_CLEAR_SKB,
13654 }, 13881 },
13655 { 13882 {
13656 .cmd = NL80211_CMD_DEAUTHENTICATE, 13883 .cmd = NL80211_CMD_DEAUTHENTICATE,
13884 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13657 .doit = nl80211_deauthenticate, 13885 .doit = nl80211_deauthenticate,
13658 .policy = nl80211_policy,
13659 .flags = GENL_UNS_ADMIN_PERM, 13886 .flags = GENL_UNS_ADMIN_PERM,
13660 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13887 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13661 NL80211_FLAG_NEED_RTNL, 13888 NL80211_FLAG_NEED_RTNL,
13662 }, 13889 },
13663 { 13890 {
13664 .cmd = NL80211_CMD_DISASSOCIATE, 13891 .cmd = NL80211_CMD_DISASSOCIATE,
13892 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13665 .doit = nl80211_disassociate, 13893 .doit = nl80211_disassociate,
13666 .policy = nl80211_policy,
13667 .flags = GENL_UNS_ADMIN_PERM, 13894 .flags = GENL_UNS_ADMIN_PERM,
13668 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13895 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13669 NL80211_FLAG_NEED_RTNL, 13896 NL80211_FLAG_NEED_RTNL,
13670 }, 13897 },
13671 { 13898 {
13672 .cmd = NL80211_CMD_JOIN_IBSS, 13899 .cmd = NL80211_CMD_JOIN_IBSS,
13900 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13673 .doit = nl80211_join_ibss, 13901 .doit = nl80211_join_ibss,
13674 .policy = nl80211_policy,
13675 .flags = GENL_UNS_ADMIN_PERM, 13902 .flags = GENL_UNS_ADMIN_PERM,
13676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13903 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13677 NL80211_FLAG_NEED_RTNL, 13904 NL80211_FLAG_NEED_RTNL,
13678 }, 13905 },
13679 { 13906 {
13680 .cmd = NL80211_CMD_LEAVE_IBSS, 13907 .cmd = NL80211_CMD_LEAVE_IBSS,
13908 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13681 .doit = nl80211_leave_ibss, 13909 .doit = nl80211_leave_ibss,
13682 .policy = nl80211_policy,
13683 .flags = GENL_UNS_ADMIN_PERM, 13910 .flags = GENL_UNS_ADMIN_PERM,
13684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13911 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13685 NL80211_FLAG_NEED_RTNL, 13912 NL80211_FLAG_NEED_RTNL,
@@ -13687,9 +13914,9 @@ static const struct genl_ops nl80211_ops[] = {
13687#ifdef CONFIG_NL80211_TESTMODE 13914#ifdef CONFIG_NL80211_TESTMODE
13688 { 13915 {
13689 .cmd = NL80211_CMD_TESTMODE, 13916 .cmd = NL80211_CMD_TESTMODE,
13917 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13690 .doit = nl80211_testmode_do, 13918 .doit = nl80211_testmode_do,
13691 .dumpit = nl80211_testmode_dump, 13919 .dumpit = nl80211_testmode_dump,
13692 .policy = nl80211_policy,
13693 .flags = GENL_UNS_ADMIN_PERM, 13920 .flags = GENL_UNS_ADMIN_PERM,
13694 .internal_flags = NL80211_FLAG_NEED_WIPHY | 13921 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13695 NL80211_FLAG_NEED_RTNL, 13922 NL80211_FLAG_NEED_RTNL,
@@ -13697,181 +13924,184 @@ static const struct genl_ops nl80211_ops[] = {
13697#endif 13924#endif
13698 { 13925 {
13699 .cmd = NL80211_CMD_CONNECT, 13926 .cmd = NL80211_CMD_CONNECT,
13927 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13700 .doit = nl80211_connect, 13928 .doit = nl80211_connect,
13701 .policy = nl80211_policy,
13702 .flags = GENL_UNS_ADMIN_PERM, 13929 .flags = GENL_UNS_ADMIN_PERM,
13703 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13930 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13704 NL80211_FLAG_NEED_RTNL, 13931 NL80211_FLAG_NEED_RTNL |
13932 NL80211_FLAG_CLEAR_SKB,
13705 }, 13933 },
13706 { 13934 {
13707 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, 13935 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
13936 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13708 .doit = nl80211_update_connect_params, 13937 .doit = nl80211_update_connect_params,
13709 .policy = nl80211_policy,
13710 .flags = GENL_ADMIN_PERM, 13938 .flags = GENL_ADMIN_PERM,
13711 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13939 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13712 NL80211_FLAG_NEED_RTNL, 13940 NL80211_FLAG_NEED_RTNL |
13941 NL80211_FLAG_CLEAR_SKB,
13713 }, 13942 },
13714 { 13943 {
13715 .cmd = NL80211_CMD_DISCONNECT, 13944 .cmd = NL80211_CMD_DISCONNECT,
13945 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13716 .doit = nl80211_disconnect, 13946 .doit = nl80211_disconnect,
13717 .policy = nl80211_policy,
13718 .flags = GENL_UNS_ADMIN_PERM, 13947 .flags = GENL_UNS_ADMIN_PERM,
13719 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13948 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13720 NL80211_FLAG_NEED_RTNL, 13949 NL80211_FLAG_NEED_RTNL,
13721 }, 13950 },
13722 { 13951 {
13723 .cmd = NL80211_CMD_SET_WIPHY_NETNS, 13952 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
13953 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13724 .doit = nl80211_wiphy_netns, 13954 .doit = nl80211_wiphy_netns,
13725 .policy = nl80211_policy,
13726 .flags = GENL_UNS_ADMIN_PERM, 13955 .flags = GENL_UNS_ADMIN_PERM,
13727 .internal_flags = NL80211_FLAG_NEED_WIPHY | 13956 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13728 NL80211_FLAG_NEED_RTNL, 13957 NL80211_FLAG_NEED_RTNL,
13729 }, 13958 },
13730 { 13959 {
13731 .cmd = NL80211_CMD_GET_SURVEY, 13960 .cmd = NL80211_CMD_GET_SURVEY,
13732 .policy = nl80211_policy, 13961 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13733 .dumpit = nl80211_dump_survey, 13962 .dumpit = nl80211_dump_survey,
13734 }, 13963 },
13735 { 13964 {
13736 .cmd = NL80211_CMD_SET_PMKSA, 13965 .cmd = NL80211_CMD_SET_PMKSA,
13966 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13737 .doit = nl80211_setdel_pmksa, 13967 .doit = nl80211_setdel_pmksa,
13738 .policy = nl80211_policy,
13739 .flags = GENL_UNS_ADMIN_PERM, 13968 .flags = GENL_UNS_ADMIN_PERM,
13740 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13969 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13741 NL80211_FLAG_NEED_RTNL, 13970 NL80211_FLAG_NEED_RTNL |
13971 NL80211_FLAG_CLEAR_SKB,
13742 }, 13972 },
13743 { 13973 {
13744 .cmd = NL80211_CMD_DEL_PMKSA, 13974 .cmd = NL80211_CMD_DEL_PMKSA,
13975 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13745 .doit = nl80211_setdel_pmksa, 13976 .doit = nl80211_setdel_pmksa,
13746 .policy = nl80211_policy,
13747 .flags = GENL_UNS_ADMIN_PERM, 13977 .flags = GENL_UNS_ADMIN_PERM,
13748 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13749 NL80211_FLAG_NEED_RTNL, 13979 NL80211_FLAG_NEED_RTNL,
13750 }, 13980 },
13751 { 13981 {
13752 .cmd = NL80211_CMD_FLUSH_PMKSA, 13982 .cmd = NL80211_CMD_FLUSH_PMKSA,
13983 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13753 .doit = nl80211_flush_pmksa, 13984 .doit = nl80211_flush_pmksa,
13754 .policy = nl80211_policy,
13755 .flags = GENL_UNS_ADMIN_PERM, 13985 .flags = GENL_UNS_ADMIN_PERM,
13756 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 13986 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13757 NL80211_FLAG_NEED_RTNL, 13987 NL80211_FLAG_NEED_RTNL,
13758 }, 13988 },
13759 { 13989 {
13760 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, 13990 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
13991 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13761 .doit = nl80211_remain_on_channel, 13992 .doit = nl80211_remain_on_channel,
13762 .policy = nl80211_policy,
13763 .flags = GENL_UNS_ADMIN_PERM, 13993 .flags = GENL_UNS_ADMIN_PERM,
13764 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 13994 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13765 NL80211_FLAG_NEED_RTNL, 13995 NL80211_FLAG_NEED_RTNL,
13766 }, 13996 },
13767 { 13997 {
13768 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 13998 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
13999 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13769 .doit = nl80211_cancel_remain_on_channel, 14000 .doit = nl80211_cancel_remain_on_channel,
13770 .policy = nl80211_policy,
13771 .flags = GENL_UNS_ADMIN_PERM, 14001 .flags = GENL_UNS_ADMIN_PERM,
13772 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14002 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13773 NL80211_FLAG_NEED_RTNL, 14003 NL80211_FLAG_NEED_RTNL,
13774 }, 14004 },
13775 { 14005 {
13776 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, 14006 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
14007 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13777 .doit = nl80211_set_tx_bitrate_mask, 14008 .doit = nl80211_set_tx_bitrate_mask,
13778 .policy = nl80211_policy,
13779 .flags = GENL_UNS_ADMIN_PERM, 14009 .flags = GENL_UNS_ADMIN_PERM,
13780 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14010 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13781 NL80211_FLAG_NEED_RTNL, 14011 NL80211_FLAG_NEED_RTNL,
13782 }, 14012 },
13783 { 14013 {
13784 .cmd = NL80211_CMD_REGISTER_FRAME, 14014 .cmd = NL80211_CMD_REGISTER_FRAME,
14015 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13785 .doit = nl80211_register_mgmt, 14016 .doit = nl80211_register_mgmt,
13786 .policy = nl80211_policy,
13787 .flags = GENL_UNS_ADMIN_PERM, 14017 .flags = GENL_UNS_ADMIN_PERM,
13788 .internal_flags = NL80211_FLAG_NEED_WDEV | 14018 .internal_flags = NL80211_FLAG_NEED_WDEV |
13789 NL80211_FLAG_NEED_RTNL, 14019 NL80211_FLAG_NEED_RTNL,
13790 }, 14020 },
13791 { 14021 {
13792 .cmd = NL80211_CMD_FRAME, 14022 .cmd = NL80211_CMD_FRAME,
14023 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13793 .doit = nl80211_tx_mgmt, 14024 .doit = nl80211_tx_mgmt,
13794 .policy = nl80211_policy,
13795 .flags = GENL_UNS_ADMIN_PERM, 14025 .flags = GENL_UNS_ADMIN_PERM,
13796 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14026 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13797 NL80211_FLAG_NEED_RTNL, 14027 NL80211_FLAG_NEED_RTNL,
13798 }, 14028 },
13799 { 14029 {
13800 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, 14030 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
14031 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13801 .doit = nl80211_tx_mgmt_cancel_wait, 14032 .doit = nl80211_tx_mgmt_cancel_wait,
13802 .policy = nl80211_policy,
13803 .flags = GENL_UNS_ADMIN_PERM, 14033 .flags = GENL_UNS_ADMIN_PERM,
13804 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14034 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13805 NL80211_FLAG_NEED_RTNL, 14035 NL80211_FLAG_NEED_RTNL,
13806 }, 14036 },
13807 { 14037 {
13808 .cmd = NL80211_CMD_SET_POWER_SAVE, 14038 .cmd = NL80211_CMD_SET_POWER_SAVE,
14039 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13809 .doit = nl80211_set_power_save, 14040 .doit = nl80211_set_power_save,
13810 .policy = nl80211_policy,
13811 .flags = GENL_UNS_ADMIN_PERM, 14041 .flags = GENL_UNS_ADMIN_PERM,
13812 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14042 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13813 NL80211_FLAG_NEED_RTNL, 14043 NL80211_FLAG_NEED_RTNL,
13814 }, 14044 },
13815 { 14045 {
13816 .cmd = NL80211_CMD_GET_POWER_SAVE, 14046 .cmd = NL80211_CMD_GET_POWER_SAVE,
14047 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13817 .doit = nl80211_get_power_save, 14048 .doit = nl80211_get_power_save,
13818 .policy = nl80211_policy,
13819 /* can be retrieved by unprivileged users */ 14049 /* can be retrieved by unprivileged users */
13820 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14050 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13821 NL80211_FLAG_NEED_RTNL, 14051 NL80211_FLAG_NEED_RTNL,
13822 }, 14052 },
13823 { 14053 {
13824 .cmd = NL80211_CMD_SET_CQM, 14054 .cmd = NL80211_CMD_SET_CQM,
14055 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13825 .doit = nl80211_set_cqm, 14056 .doit = nl80211_set_cqm,
13826 .policy = nl80211_policy,
13827 .flags = GENL_UNS_ADMIN_PERM, 14057 .flags = GENL_UNS_ADMIN_PERM,
13828 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14058 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13829 NL80211_FLAG_NEED_RTNL, 14059 NL80211_FLAG_NEED_RTNL,
13830 }, 14060 },
13831 { 14061 {
13832 .cmd = NL80211_CMD_SET_CHANNEL, 14062 .cmd = NL80211_CMD_SET_CHANNEL,
14063 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13833 .doit = nl80211_set_channel, 14064 .doit = nl80211_set_channel,
13834 .policy = nl80211_policy,
13835 .flags = GENL_UNS_ADMIN_PERM, 14065 .flags = GENL_UNS_ADMIN_PERM,
13836 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14066 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13837 NL80211_FLAG_NEED_RTNL, 14067 NL80211_FLAG_NEED_RTNL,
13838 }, 14068 },
13839 { 14069 {
13840 .cmd = NL80211_CMD_SET_WDS_PEER, 14070 .cmd = NL80211_CMD_SET_WDS_PEER,
14071 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13841 .doit = nl80211_set_wds_peer, 14072 .doit = nl80211_set_wds_peer,
13842 .policy = nl80211_policy,
13843 .flags = GENL_UNS_ADMIN_PERM, 14073 .flags = GENL_UNS_ADMIN_PERM,
13844 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14074 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13845 NL80211_FLAG_NEED_RTNL, 14075 NL80211_FLAG_NEED_RTNL,
13846 }, 14076 },
13847 { 14077 {
13848 .cmd = NL80211_CMD_JOIN_MESH, 14078 .cmd = NL80211_CMD_JOIN_MESH,
14079 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13849 .doit = nl80211_join_mesh, 14080 .doit = nl80211_join_mesh,
13850 .policy = nl80211_policy,
13851 .flags = GENL_UNS_ADMIN_PERM, 14081 .flags = GENL_UNS_ADMIN_PERM,
13852 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14082 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13853 NL80211_FLAG_NEED_RTNL, 14083 NL80211_FLAG_NEED_RTNL,
13854 }, 14084 },
13855 { 14085 {
13856 .cmd = NL80211_CMD_LEAVE_MESH, 14086 .cmd = NL80211_CMD_LEAVE_MESH,
14087 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13857 .doit = nl80211_leave_mesh, 14088 .doit = nl80211_leave_mesh,
13858 .policy = nl80211_policy,
13859 .flags = GENL_UNS_ADMIN_PERM, 14089 .flags = GENL_UNS_ADMIN_PERM,
13860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13861 NL80211_FLAG_NEED_RTNL, 14091 NL80211_FLAG_NEED_RTNL,
13862 }, 14092 },
13863 { 14093 {
13864 .cmd = NL80211_CMD_JOIN_OCB, 14094 .cmd = NL80211_CMD_JOIN_OCB,
14095 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13865 .doit = nl80211_join_ocb, 14096 .doit = nl80211_join_ocb,
13866 .policy = nl80211_policy,
13867 .flags = GENL_UNS_ADMIN_PERM, 14097 .flags = GENL_UNS_ADMIN_PERM,
13868 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14098 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13869 NL80211_FLAG_NEED_RTNL, 14099 NL80211_FLAG_NEED_RTNL,
13870 }, 14100 },
13871 { 14101 {
13872 .cmd = NL80211_CMD_LEAVE_OCB, 14102 .cmd = NL80211_CMD_LEAVE_OCB,
14103 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13873 .doit = nl80211_leave_ocb, 14104 .doit = nl80211_leave_ocb,
13874 .policy = nl80211_policy,
13875 .flags = GENL_UNS_ADMIN_PERM, 14105 .flags = GENL_UNS_ADMIN_PERM,
13876 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14106 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13877 NL80211_FLAG_NEED_RTNL, 14107 NL80211_FLAG_NEED_RTNL,
@@ -13879,16 +14109,16 @@ static const struct genl_ops nl80211_ops[] = {
13879#ifdef CONFIG_PM 14109#ifdef CONFIG_PM
13880 { 14110 {
13881 .cmd = NL80211_CMD_GET_WOWLAN, 14111 .cmd = NL80211_CMD_GET_WOWLAN,
14112 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13882 .doit = nl80211_get_wowlan, 14113 .doit = nl80211_get_wowlan,
13883 .policy = nl80211_policy,
13884 /* can be retrieved by unprivileged users */ 14114 /* can be retrieved by unprivileged users */
13885 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14115 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13886 NL80211_FLAG_NEED_RTNL, 14116 NL80211_FLAG_NEED_RTNL,
13887 }, 14117 },
13888 { 14118 {
13889 .cmd = NL80211_CMD_SET_WOWLAN, 14119 .cmd = NL80211_CMD_SET_WOWLAN,
14120 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13890 .doit = nl80211_set_wowlan, 14121 .doit = nl80211_set_wowlan,
13891 .policy = nl80211_policy,
13892 .flags = GENL_UNS_ADMIN_PERM, 14122 .flags = GENL_UNS_ADMIN_PERM,
13893 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14123 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13894 NL80211_FLAG_NEED_RTNL, 14124 NL80211_FLAG_NEED_RTNL,
@@ -13896,8 +14126,8 @@ static const struct genl_ops nl80211_ops[] = {
13896#endif 14126#endif
13897 { 14127 {
13898 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, 14128 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
14129 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13899 .doit = nl80211_set_rekey_data, 14130 .doit = nl80211_set_rekey_data,
13900 .policy = nl80211_policy,
13901 .flags = GENL_UNS_ADMIN_PERM, 14131 .flags = GENL_UNS_ADMIN_PERM,
13902 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13903 NL80211_FLAG_NEED_RTNL | 14133 NL80211_FLAG_NEED_RTNL |
@@ -13905,290 +14135,306 @@ static const struct genl_ops nl80211_ops[] = {
13905 }, 14135 },
13906 { 14136 {
13907 .cmd = NL80211_CMD_TDLS_MGMT, 14137 .cmd = NL80211_CMD_TDLS_MGMT,
14138 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13908 .doit = nl80211_tdls_mgmt, 14139 .doit = nl80211_tdls_mgmt,
13909 .policy = nl80211_policy,
13910 .flags = GENL_UNS_ADMIN_PERM, 14140 .flags = GENL_UNS_ADMIN_PERM,
13911 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14141 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13912 NL80211_FLAG_NEED_RTNL, 14142 NL80211_FLAG_NEED_RTNL,
13913 }, 14143 },
13914 { 14144 {
13915 .cmd = NL80211_CMD_TDLS_OPER, 14145 .cmd = NL80211_CMD_TDLS_OPER,
14146 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13916 .doit = nl80211_tdls_oper, 14147 .doit = nl80211_tdls_oper,
13917 .policy = nl80211_policy,
13918 .flags = GENL_UNS_ADMIN_PERM, 14148 .flags = GENL_UNS_ADMIN_PERM,
13919 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14149 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13920 NL80211_FLAG_NEED_RTNL, 14150 NL80211_FLAG_NEED_RTNL,
13921 }, 14151 },
13922 { 14152 {
13923 .cmd = NL80211_CMD_UNEXPECTED_FRAME, 14153 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
14154 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13924 .doit = nl80211_register_unexpected_frame, 14155 .doit = nl80211_register_unexpected_frame,
13925 .policy = nl80211_policy,
13926 .flags = GENL_UNS_ADMIN_PERM, 14156 .flags = GENL_UNS_ADMIN_PERM,
13927 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14157 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13928 NL80211_FLAG_NEED_RTNL, 14158 NL80211_FLAG_NEED_RTNL,
13929 }, 14159 },
13930 { 14160 {
13931 .cmd = NL80211_CMD_PROBE_CLIENT, 14161 .cmd = NL80211_CMD_PROBE_CLIENT,
14162 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13932 .doit = nl80211_probe_client, 14163 .doit = nl80211_probe_client,
13933 .policy = nl80211_policy,
13934 .flags = GENL_UNS_ADMIN_PERM, 14164 .flags = GENL_UNS_ADMIN_PERM,
13935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14165 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
13936 NL80211_FLAG_NEED_RTNL, 14166 NL80211_FLAG_NEED_RTNL,
13937 }, 14167 },
13938 { 14168 {
13939 .cmd = NL80211_CMD_REGISTER_BEACONS, 14169 .cmd = NL80211_CMD_REGISTER_BEACONS,
14170 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13940 .doit = nl80211_register_beacons, 14171 .doit = nl80211_register_beacons,
13941 .policy = nl80211_policy,
13942 .flags = GENL_UNS_ADMIN_PERM, 14172 .flags = GENL_UNS_ADMIN_PERM,
13943 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14173 .internal_flags = NL80211_FLAG_NEED_WIPHY |
13944 NL80211_FLAG_NEED_RTNL, 14174 NL80211_FLAG_NEED_RTNL,
13945 }, 14175 },
13946 { 14176 {
13947 .cmd = NL80211_CMD_SET_NOACK_MAP, 14177 .cmd = NL80211_CMD_SET_NOACK_MAP,
14178 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13948 .doit = nl80211_set_noack_map, 14179 .doit = nl80211_set_noack_map,
13949 .policy = nl80211_policy,
13950 .flags = GENL_UNS_ADMIN_PERM, 14180 .flags = GENL_UNS_ADMIN_PERM,
13951 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14181 .internal_flags = NL80211_FLAG_NEED_NETDEV |
13952 NL80211_FLAG_NEED_RTNL, 14182 NL80211_FLAG_NEED_RTNL,
13953 }, 14183 },
13954 { 14184 {
13955 .cmd = NL80211_CMD_START_P2P_DEVICE, 14185 .cmd = NL80211_CMD_START_P2P_DEVICE,
14186 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13956 .doit = nl80211_start_p2p_device, 14187 .doit = nl80211_start_p2p_device,
13957 .policy = nl80211_policy,
13958 .flags = GENL_UNS_ADMIN_PERM, 14188 .flags = GENL_UNS_ADMIN_PERM,
13959 .internal_flags = NL80211_FLAG_NEED_WDEV | 14189 .internal_flags = NL80211_FLAG_NEED_WDEV |
13960 NL80211_FLAG_NEED_RTNL, 14190 NL80211_FLAG_NEED_RTNL,
13961 }, 14191 },
13962 { 14192 {
13963 .cmd = NL80211_CMD_STOP_P2P_DEVICE, 14193 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
14194 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13964 .doit = nl80211_stop_p2p_device, 14195 .doit = nl80211_stop_p2p_device,
13965 .policy = nl80211_policy,
13966 .flags = GENL_UNS_ADMIN_PERM, 14196 .flags = GENL_UNS_ADMIN_PERM,
13967 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14197 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13968 NL80211_FLAG_NEED_RTNL, 14198 NL80211_FLAG_NEED_RTNL,
13969 }, 14199 },
13970 { 14200 {
13971 .cmd = NL80211_CMD_START_NAN, 14201 .cmd = NL80211_CMD_START_NAN,
14202 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13972 .doit = nl80211_start_nan, 14203 .doit = nl80211_start_nan,
13973 .policy = nl80211_policy,
13974 .flags = GENL_ADMIN_PERM, 14204 .flags = GENL_ADMIN_PERM,
13975 .internal_flags = NL80211_FLAG_NEED_WDEV | 14205 .internal_flags = NL80211_FLAG_NEED_WDEV |
13976 NL80211_FLAG_NEED_RTNL, 14206 NL80211_FLAG_NEED_RTNL,
13977 }, 14207 },
13978 { 14208 {
13979 .cmd = NL80211_CMD_STOP_NAN, 14209 .cmd = NL80211_CMD_STOP_NAN,
14210 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13980 .doit = nl80211_stop_nan, 14211 .doit = nl80211_stop_nan,
13981 .policy = nl80211_policy,
13982 .flags = GENL_ADMIN_PERM, 14212 .flags = GENL_ADMIN_PERM,
13983 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14213 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13984 NL80211_FLAG_NEED_RTNL, 14214 NL80211_FLAG_NEED_RTNL,
13985 }, 14215 },
13986 { 14216 {
13987 .cmd = NL80211_CMD_ADD_NAN_FUNCTION, 14217 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
14218 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13988 .doit = nl80211_nan_add_func, 14219 .doit = nl80211_nan_add_func,
13989 .policy = nl80211_policy,
13990 .flags = GENL_ADMIN_PERM, 14220 .flags = GENL_ADMIN_PERM,
13991 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14221 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
13992 NL80211_FLAG_NEED_RTNL, 14222 NL80211_FLAG_NEED_RTNL,
13993 }, 14223 },
13994 { 14224 {
13995 .cmd = NL80211_CMD_DEL_NAN_FUNCTION, 14225 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
14226 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
13996 .doit = nl80211_nan_del_func, 14227 .doit = nl80211_nan_del_func,
13997 .policy = nl80211_policy,
13998 .flags = GENL_ADMIN_PERM, 14228 .flags = GENL_ADMIN_PERM,
13999 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14229 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14000 NL80211_FLAG_NEED_RTNL, 14230 NL80211_FLAG_NEED_RTNL,
14001 }, 14231 },
14002 { 14232 {
14003 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, 14233 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
14234 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14004 .doit = nl80211_nan_change_config, 14235 .doit = nl80211_nan_change_config,
14005 .policy = nl80211_policy,
14006 .flags = GENL_ADMIN_PERM, 14236 .flags = GENL_ADMIN_PERM,
14007 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14237 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14008 NL80211_FLAG_NEED_RTNL, 14238 NL80211_FLAG_NEED_RTNL,
14009 }, 14239 },
14010 { 14240 {
14011 .cmd = NL80211_CMD_SET_MCAST_RATE, 14241 .cmd = NL80211_CMD_SET_MCAST_RATE,
14242 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14012 .doit = nl80211_set_mcast_rate, 14243 .doit = nl80211_set_mcast_rate,
14013 .policy = nl80211_policy,
14014 .flags = GENL_UNS_ADMIN_PERM, 14244 .flags = GENL_UNS_ADMIN_PERM,
14015 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14245 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14016 NL80211_FLAG_NEED_RTNL, 14246 NL80211_FLAG_NEED_RTNL,
14017 }, 14247 },
14018 { 14248 {
14019 .cmd = NL80211_CMD_SET_MAC_ACL, 14249 .cmd = NL80211_CMD_SET_MAC_ACL,
14250 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14020 .doit = nl80211_set_mac_acl, 14251 .doit = nl80211_set_mac_acl,
14021 .policy = nl80211_policy,
14022 .flags = GENL_UNS_ADMIN_PERM, 14252 .flags = GENL_UNS_ADMIN_PERM,
14023 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14253 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14024 NL80211_FLAG_NEED_RTNL, 14254 NL80211_FLAG_NEED_RTNL,
14025 }, 14255 },
14026 { 14256 {
14027 .cmd = NL80211_CMD_RADAR_DETECT, 14257 .cmd = NL80211_CMD_RADAR_DETECT,
14258 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14028 .doit = nl80211_start_radar_detection, 14259 .doit = nl80211_start_radar_detection,
14029 .policy = nl80211_policy,
14030 .flags = GENL_UNS_ADMIN_PERM, 14260 .flags = GENL_UNS_ADMIN_PERM,
14031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14261 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14032 NL80211_FLAG_NEED_RTNL, 14262 NL80211_FLAG_NEED_RTNL,
14033 }, 14263 },
14034 { 14264 {
14035 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, 14265 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
14266 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14036 .doit = nl80211_get_protocol_features, 14267 .doit = nl80211_get_protocol_features,
14037 .policy = nl80211_policy,
14038 }, 14268 },
14039 { 14269 {
14040 .cmd = NL80211_CMD_UPDATE_FT_IES, 14270 .cmd = NL80211_CMD_UPDATE_FT_IES,
14271 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14041 .doit = nl80211_update_ft_ies, 14272 .doit = nl80211_update_ft_ies,
14042 .policy = nl80211_policy,
14043 .flags = GENL_UNS_ADMIN_PERM, 14273 .flags = GENL_UNS_ADMIN_PERM,
14044 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14045 NL80211_FLAG_NEED_RTNL, 14275 NL80211_FLAG_NEED_RTNL,
14046 }, 14276 },
14047 { 14277 {
14048 .cmd = NL80211_CMD_CRIT_PROTOCOL_START, 14278 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
14279 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14049 .doit = nl80211_crit_protocol_start, 14280 .doit = nl80211_crit_protocol_start,
14050 .policy = nl80211_policy,
14051 .flags = GENL_UNS_ADMIN_PERM, 14281 .flags = GENL_UNS_ADMIN_PERM,
14052 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14282 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14053 NL80211_FLAG_NEED_RTNL, 14283 NL80211_FLAG_NEED_RTNL,
14054 }, 14284 },
14055 { 14285 {
14056 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, 14286 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
14287 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14057 .doit = nl80211_crit_protocol_stop, 14288 .doit = nl80211_crit_protocol_stop,
14058 .policy = nl80211_policy,
14059 .flags = GENL_UNS_ADMIN_PERM, 14289 .flags = GENL_UNS_ADMIN_PERM,
14060 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14290 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14061 NL80211_FLAG_NEED_RTNL, 14291 NL80211_FLAG_NEED_RTNL,
14062 }, 14292 },
14063 { 14293 {
14064 .cmd = NL80211_CMD_GET_COALESCE, 14294 .cmd = NL80211_CMD_GET_COALESCE,
14295 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14065 .doit = nl80211_get_coalesce, 14296 .doit = nl80211_get_coalesce,
14066 .policy = nl80211_policy,
14067 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14297 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14068 NL80211_FLAG_NEED_RTNL, 14298 NL80211_FLAG_NEED_RTNL,
14069 }, 14299 },
14070 { 14300 {
14071 .cmd = NL80211_CMD_SET_COALESCE, 14301 .cmd = NL80211_CMD_SET_COALESCE,
14302 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14072 .doit = nl80211_set_coalesce, 14303 .doit = nl80211_set_coalesce,
14073 .policy = nl80211_policy,
14074 .flags = GENL_UNS_ADMIN_PERM, 14304 .flags = GENL_UNS_ADMIN_PERM,
14075 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14305 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14076 NL80211_FLAG_NEED_RTNL, 14306 NL80211_FLAG_NEED_RTNL,
14077 }, 14307 },
14078 { 14308 {
14079 .cmd = NL80211_CMD_CHANNEL_SWITCH, 14309 .cmd = NL80211_CMD_CHANNEL_SWITCH,
14310 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14080 .doit = nl80211_channel_switch, 14311 .doit = nl80211_channel_switch,
14081 .policy = nl80211_policy,
14082 .flags = GENL_UNS_ADMIN_PERM, 14312 .flags = GENL_UNS_ADMIN_PERM,
14083 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14313 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14084 NL80211_FLAG_NEED_RTNL, 14314 NL80211_FLAG_NEED_RTNL,
14085 }, 14315 },
14086 { 14316 {
14087 .cmd = NL80211_CMD_VENDOR, 14317 .cmd = NL80211_CMD_VENDOR,
14318 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14088 .doit = nl80211_vendor_cmd, 14319 .doit = nl80211_vendor_cmd,
14089 .dumpit = nl80211_vendor_cmd_dump, 14320 .dumpit = nl80211_vendor_cmd_dump,
14090 .policy = nl80211_policy,
14091 .flags = GENL_UNS_ADMIN_PERM, 14321 .flags = GENL_UNS_ADMIN_PERM,
14092 .internal_flags = NL80211_FLAG_NEED_WIPHY | 14322 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14093 NL80211_FLAG_NEED_RTNL, 14323 NL80211_FLAG_NEED_RTNL |
14324 NL80211_FLAG_CLEAR_SKB,
14094 }, 14325 },
14095 { 14326 {
14096 .cmd = NL80211_CMD_SET_QOS_MAP, 14327 .cmd = NL80211_CMD_SET_QOS_MAP,
14328 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14097 .doit = nl80211_set_qos_map, 14329 .doit = nl80211_set_qos_map,
14098 .policy = nl80211_policy,
14099 .flags = GENL_UNS_ADMIN_PERM, 14330 .flags = GENL_UNS_ADMIN_PERM,
14100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14101 NL80211_FLAG_NEED_RTNL, 14332 NL80211_FLAG_NEED_RTNL,
14102 }, 14333 },
14103 { 14334 {
14104 .cmd = NL80211_CMD_ADD_TX_TS, 14335 .cmd = NL80211_CMD_ADD_TX_TS,
14336 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14105 .doit = nl80211_add_tx_ts, 14337 .doit = nl80211_add_tx_ts,
14106 .policy = nl80211_policy,
14107 .flags = GENL_UNS_ADMIN_PERM, 14338 .flags = GENL_UNS_ADMIN_PERM,
14108 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14339 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14109 NL80211_FLAG_NEED_RTNL, 14340 NL80211_FLAG_NEED_RTNL,
14110 }, 14341 },
14111 { 14342 {
14112 .cmd = NL80211_CMD_DEL_TX_TS, 14343 .cmd = NL80211_CMD_DEL_TX_TS,
14344 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14113 .doit = nl80211_del_tx_ts, 14345 .doit = nl80211_del_tx_ts,
14114 .policy = nl80211_policy,
14115 .flags = GENL_UNS_ADMIN_PERM, 14346 .flags = GENL_UNS_ADMIN_PERM,
14116 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14347 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14117 NL80211_FLAG_NEED_RTNL, 14348 NL80211_FLAG_NEED_RTNL,
14118 }, 14349 },
14119 { 14350 {
14120 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, 14351 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
14352 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14121 .doit = nl80211_tdls_channel_switch, 14353 .doit = nl80211_tdls_channel_switch,
14122 .policy = nl80211_policy,
14123 .flags = GENL_UNS_ADMIN_PERM, 14354 .flags = GENL_UNS_ADMIN_PERM,
14124 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14125 NL80211_FLAG_NEED_RTNL, 14356 NL80211_FLAG_NEED_RTNL,
14126 }, 14357 },
14127 { 14358 {
14128 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, 14359 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
14360 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14129 .doit = nl80211_tdls_cancel_channel_switch, 14361 .doit = nl80211_tdls_cancel_channel_switch,
14130 .policy = nl80211_policy,
14131 .flags = GENL_UNS_ADMIN_PERM, 14362 .flags = GENL_UNS_ADMIN_PERM,
14132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14133 NL80211_FLAG_NEED_RTNL, 14364 NL80211_FLAG_NEED_RTNL,
14134 }, 14365 },
14135 { 14366 {
14136 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, 14367 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
14368 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14137 .doit = nl80211_set_multicast_to_unicast, 14369 .doit = nl80211_set_multicast_to_unicast,
14138 .policy = nl80211_policy,
14139 .flags = GENL_UNS_ADMIN_PERM, 14370 .flags = GENL_UNS_ADMIN_PERM,
14140 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14371 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14141 NL80211_FLAG_NEED_RTNL, 14372 NL80211_FLAG_NEED_RTNL,
14142 }, 14373 },
14143 { 14374 {
14144 .cmd = NL80211_CMD_SET_PMK, 14375 .cmd = NL80211_CMD_SET_PMK,
14376 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14145 .doit = nl80211_set_pmk, 14377 .doit = nl80211_set_pmk,
14146 .policy = nl80211_policy,
14147 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14148 NL80211_FLAG_NEED_RTNL, 14379 NL80211_FLAG_NEED_RTNL |
14380 NL80211_FLAG_CLEAR_SKB,
14149 }, 14381 },
14150 { 14382 {
14151 .cmd = NL80211_CMD_DEL_PMK, 14383 .cmd = NL80211_CMD_DEL_PMK,
14384 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14152 .doit = nl80211_del_pmk, 14385 .doit = nl80211_del_pmk,
14153 .policy = nl80211_policy,
14154 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14155 NL80211_FLAG_NEED_RTNL, 14387 NL80211_FLAG_NEED_RTNL,
14156 }, 14388 },
14157 { 14389 {
14158 .cmd = NL80211_CMD_EXTERNAL_AUTH, 14390 .cmd = NL80211_CMD_EXTERNAL_AUTH,
14391 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14159 .doit = nl80211_external_auth, 14392 .doit = nl80211_external_auth,
14160 .policy = nl80211_policy,
14161 .flags = GENL_ADMIN_PERM, 14393 .flags = GENL_ADMIN_PERM,
14162 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14163 NL80211_FLAG_NEED_RTNL, 14395 NL80211_FLAG_NEED_RTNL,
14164 }, 14396 },
14165 { 14397 {
14166 .cmd = NL80211_CMD_CONTROL_PORT_FRAME, 14398 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
14399 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14167 .doit = nl80211_tx_control_port, 14400 .doit = nl80211_tx_control_port,
14168 .policy = nl80211_policy,
14169 .flags = GENL_UNS_ADMIN_PERM, 14401 .flags = GENL_UNS_ADMIN_PERM,
14170 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14171 NL80211_FLAG_NEED_RTNL, 14403 NL80211_FLAG_NEED_RTNL,
14172 }, 14404 },
14173 { 14405 {
14174 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, 14406 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
14407 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14175 .doit = nl80211_get_ftm_responder_stats, 14408 .doit = nl80211_get_ftm_responder_stats,
14176 .policy = nl80211_policy,
14177 .internal_flags = NL80211_FLAG_NEED_NETDEV | 14409 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14178 NL80211_FLAG_NEED_RTNL, 14410 NL80211_FLAG_NEED_RTNL,
14179 }, 14411 },
14180 { 14412 {
14181 .cmd = NL80211_CMD_PEER_MEASUREMENT_START, 14413 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
14414 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14182 .doit = nl80211_pmsr_start, 14415 .doit = nl80211_pmsr_start,
14183 .policy = nl80211_policy,
14184 .flags = GENL_UNS_ADMIN_PERM, 14416 .flags = GENL_UNS_ADMIN_PERM,
14185 .internal_flags = NL80211_FLAG_NEED_WDEV_UP | 14417 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14186 NL80211_FLAG_NEED_RTNL, 14418 NL80211_FLAG_NEED_RTNL,
14187 }, 14419 },
14188 { 14420 {
14189 .cmd = NL80211_CMD_NOTIFY_RADAR, 14421 .cmd = NL80211_CMD_NOTIFY_RADAR,
14422 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
14190 .doit = nl80211_notify_radar_detection, 14423 .doit = nl80211_notify_radar_detection,
14191 .policy = nl80211_policy, 14424 .flags = GENL_UNS_ADMIN_PERM,
14425 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14426 NL80211_FLAG_NEED_RTNL,
14427 },
14428 {
14429 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
14430 .doit = nl80211_update_owe_info,
14431 .flags = GENL_ADMIN_PERM,
14432 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14433 NL80211_FLAG_NEED_RTNL,
14434 },
14435 {
14436 .cmd = NL80211_CMD_PROBE_MESH_LINK,
14437 .doit = nl80211_probe_mesh_link,
14192 .flags = GENL_UNS_ADMIN_PERM, 14438 .flags = GENL_UNS_ADMIN_PERM,
14193 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | 14439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14194 NL80211_FLAG_NEED_RTNL, 14440 NL80211_FLAG_NEED_RTNL,
@@ -14200,6 +14446,7 @@ static struct genl_family nl80211_fam __ro_after_init = {
14200 .hdrsize = 0, /* no private header */ 14446 .hdrsize = 0, /* no private header */
14201 .version = 1, /* no particular meaning now */ 14447 .version = 1, /* no particular meaning now */
14202 .maxattr = NL80211_ATTR_MAX, 14448 .maxattr = NL80211_ATTR_MAX,
14449 .policy = nl80211_policy,
14203 .netnsok = true, 14450 .netnsok = true,
14204 .pre_doit = nl80211_pre_doit, 14451 .pre_doit = nl80211_pre_doit,
14205 .post_doit = nl80211_post_doit, 14452 .post_doit = nl80211_post_doit,
@@ -14263,7 +14510,7 @@ static int nl80211_add_scan_req(struct sk_buff *msg,
14263 if (WARN_ON(!req)) 14510 if (WARN_ON(!req))
14264 return 0; 14511 return 0;
14265 14512
14266 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); 14513 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
14267 if (!nest) 14514 if (!nest)
14268 goto nla_put_failure; 14515 goto nla_put_failure;
14269 for (i = 0; i < req->n_ssids; i++) { 14516 for (i = 0; i < req->n_ssids; i++) {
@@ -14272,7 +14519,7 @@ static int nl80211_add_scan_req(struct sk_buff *msg,
14272 } 14519 }
14273 nla_nest_end(msg, nest); 14520 nla_nest_end(msg, nest);
14274 14521
14275 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); 14522 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
14276 if (!nest) 14523 if (!nest)
14277 goto nla_put_failure; 14524 goto nla_put_failure;
14278 for (i = 0; i < req->n_channels; i++) { 14525 for (i = 0; i < req->n_channels; i++) {
@@ -14534,7 +14781,7 @@ static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
14534 14781
14535 if (uapsd_queues >= 0) { 14782 if (uapsd_queues >= 0) {
14536 struct nlattr *nla_wmm = 14783 struct nlattr *nla_wmm =
14537 nla_nest_start(msg, NL80211_ATTR_STA_WME); 14784 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
14538 if (!nla_wmm) 14785 if (!nla_wmm)
14539 goto nla_put_failure; 14786 goto nla_put_failure;
14540 14787
@@ -14975,7 +15222,7 @@ void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14975 goto nla_put_failure; 15222 goto nla_put_failure;
14976 15223
14977 /* Before */ 15224 /* Before */
14978 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); 15225 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
14979 if (!nl_freq) 15226 if (!nl_freq)
14980 goto nla_put_failure; 15227 goto nla_put_failure;
14981 15228
@@ -14984,7 +15231,7 @@ void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
14984 nla_nest_end(msg, nl_freq); 15231 nla_nest_end(msg, nl_freq);
14985 15232
14986 /* After */ 15233 /* After */
14987 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); 15234 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
14988 if (!nl_freq) 15235 if (!nl_freq)
14989 goto nla_put_failure; 15236 goto nla_put_failure;
14990 15237
@@ -15418,7 +15665,7 @@ static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
15418 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 15665 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
15419 goto nla_put_failure; 15666 goto nla_put_failure;
15420 15667
15421 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); 15668 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
15422 if (!cb[1]) 15669 if (!cb[1])
15423 goto nla_put_failure; 15670 goto nla_put_failure;
15424 15671
@@ -15579,7 +15826,7 @@ static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
15579 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 15826 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15580 goto nla_put_failure; 15827 goto nla_put_failure;
15581 15828
15582 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); 15829 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
15583 if (!rekey_attr) 15830 if (!rekey_attr)
15584 goto nla_put_failure; 15831 goto nla_put_failure;
15585 15832
@@ -15634,7 +15881,7 @@ nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
15634 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 15881 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
15635 goto nla_put_failure; 15882 goto nla_put_failure;
15636 15883
15637 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); 15884 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
15638 if (!attr) 15885 if (!attr)
15639 goto nla_put_failure; 15886 goto nla_put_failure;
15640 15887
@@ -15721,6 +15968,11 @@ void cfg80211_ch_switch_notify(struct net_device *dev,
15721 15968
15722 wdev->chandef = *chandef; 15969 wdev->chandef = *chandef;
15723 wdev->preset_chandef = *chandef; 15970 wdev->preset_chandef = *chandef;
15971
15972 if (wdev->iftype == NL80211_IFTYPE_STATION &&
15973 !WARN_ON(!wdev->current_bss))
15974 wdev->current_bss->pub.channel = chandef->chan;
15975
15724 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, 15976 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
15725 NL80211_CMD_CH_SWITCH_NOTIFY, 0); 15977 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
15726} 15978}
@@ -15939,15 +16191,15 @@ static int cfg80211_net_detect_results(struct sk_buff *msg,
15939 struct nlattr *nl_results, *nl_match, *nl_freqs; 16191 struct nlattr *nl_results, *nl_match, *nl_freqs;
15940 int i, j; 16192 int i, j;
15941 16193
15942 nl_results = nla_nest_start( 16194 nl_results = nla_nest_start_noflag(msg,
15943 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); 16195 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
15944 if (!nl_results) 16196 if (!nl_results)
15945 return -EMSGSIZE; 16197 return -EMSGSIZE;
15946 16198
15947 for (i = 0; i < nd->n_matches; i++) { 16199 for (i = 0; i < nd->n_matches; i++) {
15948 struct cfg80211_wowlan_nd_match *match = nd->matches[i]; 16200 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
15949 16201
15950 nl_match = nla_nest_start(msg, i); 16202 nl_match = nla_nest_start_noflag(msg, i);
15951 if (!nl_match) 16203 if (!nl_match)
15952 break; 16204 break;
15953 16205
@@ -15965,8 +16217,8 @@ static int cfg80211_net_detect_results(struct sk_buff *msg,
15965 } 16217 }
15966 16218
15967 if (match->n_channels) { 16219 if (match->n_channels) {
15968 nl_freqs = nla_nest_start( 16220 nl_freqs = nla_nest_start_noflag(msg,
15969 msg, NL80211_ATTR_SCAN_FREQUENCIES); 16221 NL80211_ATTR_SCAN_FREQUENCIES);
15970 if (!nl_freqs) { 16222 if (!nl_freqs) {
15971 nla_nest_cancel(msg, nl_match); 16223 nla_nest_cancel(msg, nl_match);
15972 goto out; 16224 goto out;
@@ -16025,7 +16277,8 @@ void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
16025 if (wakeup) { 16277 if (wakeup) {
16026 struct nlattr *reasons; 16278 struct nlattr *reasons;
16027 16279
16028 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); 16280 reasons = nla_nest_start_noflag(msg,
16281 NL80211_ATTR_WOWLAN_TRIGGERS);
16029 if (!reasons) 16282 if (!reasons)
16030 goto free_msg; 16283 goto free_msg;
16031 16284
@@ -16364,6 +16617,46 @@ int cfg80211_external_auth_request(struct net_device *dev,
16364} 16617}
16365EXPORT_SYMBOL(cfg80211_external_auth_request); 16618EXPORT_SYMBOL(cfg80211_external_auth_request);
16366 16619
16620void cfg80211_update_owe_info_event(struct net_device *netdev,
16621 struct cfg80211_update_owe_info *owe_info,
16622 gfp_t gfp)
16623{
16624 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
16625 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16626 struct sk_buff *msg;
16627 void *hdr;
16628
16629 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
16630
16631 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16632 if (!msg)
16633 return;
16634
16635 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
16636 if (!hdr)
16637 goto nla_put_failure;
16638
16639 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16640 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16641 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
16642 goto nla_put_failure;
16643
16644 if (!owe_info->ie_len ||
16645 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
16646 goto nla_put_failure;
16647
16648 genlmsg_end(msg, hdr);
16649
16650 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16651 NL80211_MCGRP_MLME, gfp);
16652 return;
16653
16654nla_put_failure:
16655 genlmsg_cancel(msg, hdr);
16656 nlmsg_free(msg);
16657}
16658EXPORT_SYMBOL(cfg80211_update_owe_info_event);
16659
16367/* initialisation/exit functions */ 16660/* initialisation/exit functions */
16368 16661
16369int __init nl80211_init(void) 16662int __init nl80211_init(void)
diff --git a/net/wireless/pmsr.c b/net/wireless/pmsr.c
index 5e2ab01d325c..1b190475359a 100644
--- a/net/wireless/pmsr.c
+++ b/net/wireless/pmsr.c
@@ -25,7 +25,8 @@ static int pmsr_parse_ftm(struct cfg80211_registered_device *rdev,
25 } 25 }
26 26
27 /* no validation needed - was already done via nested policy */ 27 /* no validation needed - was already done via nested policy */
28 nla_parse_nested(tb, NL80211_PMSR_FTM_REQ_ATTR_MAX, ftmreq, NULL, NULL); 28 nla_parse_nested_deprecated(tb, NL80211_PMSR_FTM_REQ_ATTR_MAX, ftmreq,
29 NULL, NULL);
29 30
30 if (tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE]) 31 if (tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE])
31 preamble = nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE]); 32 preamble = nla_get_u32(tb[NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE]);
@@ -139,7 +140,8 @@ static int pmsr_parse_peer(struct cfg80211_registered_device *rdev,
139 int err, rem; 140 int err, rem;
140 141
141 /* no validation needed - was already done via nested policy */ 142 /* no validation needed - was already done via nested policy */
142 nla_parse_nested(tb, NL80211_PMSR_PEER_ATTR_MAX, peer, NULL, NULL); 143 nla_parse_nested_deprecated(tb, NL80211_PMSR_PEER_ATTR_MAX, peer,
144 NULL, NULL);
143 145
144 if (!tb[NL80211_PMSR_PEER_ATTR_ADDR] || 146 if (!tb[NL80211_PMSR_PEER_ATTR_ADDR] ||
145 !tb[NL80211_PMSR_PEER_ATTR_CHAN] || 147 !tb[NL80211_PMSR_PEER_ATTR_CHAN] ||
@@ -154,9 +156,9 @@ static int pmsr_parse_peer(struct cfg80211_registered_device *rdev,
154 /* reuse info->attrs */ 156 /* reuse info->attrs */
155 memset(info->attrs, 0, sizeof(*info->attrs) * (NL80211_ATTR_MAX + 1)); 157 memset(info->attrs, 0, sizeof(*info->attrs) * (NL80211_ATTR_MAX + 1));
156 /* need to validate here, we don't want to have validation recursion */ 158 /* need to validate here, we don't want to have validation recursion */
157 err = nla_parse_nested(info->attrs, NL80211_ATTR_MAX, 159 err = nla_parse_nested_deprecated(info->attrs, NL80211_ATTR_MAX,
158 tb[NL80211_PMSR_PEER_ATTR_CHAN], 160 tb[NL80211_PMSR_PEER_ATTR_CHAN],
159 nl80211_policy, info->extack); 161 nl80211_policy, info->extack);
160 if (err) 162 if (err)
161 return err; 163 return err;
162 164
@@ -165,9 +167,9 @@ static int pmsr_parse_peer(struct cfg80211_registered_device *rdev,
165 return err; 167 return err;
166 168
167 /* no validation needed - was already done via nested policy */ 169 /* no validation needed - was already done via nested policy */
168 nla_parse_nested(req, NL80211_PMSR_REQ_ATTR_MAX, 170 nla_parse_nested_deprecated(req, NL80211_PMSR_REQ_ATTR_MAX,
169 tb[NL80211_PMSR_PEER_ATTR_REQ], 171 tb[NL80211_PMSR_PEER_ATTR_REQ], NULL,
170 NULL, NULL); 172 NULL);
171 173
172 if (!req[NL80211_PMSR_REQ_ATTR_DATA]) { 174 if (!req[NL80211_PMSR_REQ_ATTR_DATA]) {
173 NL_SET_ERR_MSG_ATTR(info->extack, 175 NL_SET_ERR_MSG_ATTR(info->extack,
@@ -420,22 +422,22 @@ static int nl80211_pmsr_send_result(struct sk_buff *msg,
420{ 422{
421 struct nlattr *pmsr, *peers, *peer, *resp, *data, *typedata; 423 struct nlattr *pmsr, *peers, *peer, *resp, *data, *typedata;
422 424
423 pmsr = nla_nest_start(msg, NL80211_ATTR_PEER_MEASUREMENTS); 425 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
424 if (!pmsr) 426 if (!pmsr)
425 goto error; 427 goto error;
426 428
427 peers = nla_nest_start(msg, NL80211_PMSR_ATTR_PEERS); 429 peers = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_PEERS);
428 if (!peers) 430 if (!peers)
429 goto error; 431 goto error;
430 432
431 peer = nla_nest_start(msg, 1); 433 peer = nla_nest_start_noflag(msg, 1);
432 if (!peer) 434 if (!peer)
433 goto error; 435 goto error;
434 436
435 if (nla_put(msg, NL80211_PMSR_PEER_ATTR_ADDR, ETH_ALEN, res->addr)) 437 if (nla_put(msg, NL80211_PMSR_PEER_ATTR_ADDR, ETH_ALEN, res->addr))
436 goto error; 438 goto error;
437 439
438 resp = nla_nest_start(msg, NL80211_PMSR_PEER_ATTR_RESP); 440 resp = nla_nest_start_noflag(msg, NL80211_PMSR_PEER_ATTR_RESP);
439 if (!resp) 441 if (!resp)
440 goto error; 442 goto error;
441 443
@@ -452,11 +454,11 @@ static int nl80211_pmsr_send_result(struct sk_buff *msg,
452 if (res->final && nla_put_flag(msg, NL80211_PMSR_RESP_ATTR_FINAL)) 454 if (res->final && nla_put_flag(msg, NL80211_PMSR_RESP_ATTR_FINAL))
453 goto error; 455 goto error;
454 456
455 data = nla_nest_start(msg, NL80211_PMSR_RESP_ATTR_DATA); 457 data = nla_nest_start_noflag(msg, NL80211_PMSR_RESP_ATTR_DATA);
456 if (!data) 458 if (!data)
457 goto error; 459 goto error;
458 460
459 typedata = nla_nest_start(msg, res->type); 461 typedata = nla_nest_start_noflag(msg, res->type);
460 if (!typedata) 462 if (!typedata)
461 goto error; 463 goto error;
462 464
diff --git a/net/wireless/rdev-ops.h b/net/wireless/rdev-ops.h
index 5cb48d135fab..e853a4fe6f97 100644
--- a/net/wireless/rdev-ops.h
+++ b/net/wireless/rdev-ops.h
@@ -77,7 +77,8 @@ static inline int rdev_add_key(struct cfg80211_registered_device *rdev,
77 struct key_params *params) 77 struct key_params *params)
78{ 78{
79 int ret; 79 int ret;
80 trace_rdev_add_key(&rdev->wiphy, netdev, key_index, pairwise, mac_addr); 80 trace_rdev_add_key(&rdev->wiphy, netdev, key_index, pairwise,
81 mac_addr, params->mode);
81 ret = rdev->ops->add_key(&rdev->wiphy, netdev, key_index, pairwise, 82 ret = rdev->ops->add_key(&rdev->wiphy, netdev, key_index, pairwise,
82 mac_addr, params); 83 mac_addr, params);
83 trace_rdev_return_int(&rdev->wiphy, ret); 84 trace_rdev_return_int(&rdev->wiphy, ret);
@@ -1272,4 +1273,30 @@ rdev_abort_pmsr(struct cfg80211_registered_device *rdev,
1272 trace_rdev_return_void(&rdev->wiphy); 1273 trace_rdev_return_void(&rdev->wiphy);
1273} 1274}
1274 1275
1276static inline int rdev_update_owe_info(struct cfg80211_registered_device *rdev,
1277 struct net_device *dev,
1278 struct cfg80211_update_owe_info *oweinfo)
1279{
1280 int ret = -EOPNOTSUPP;
1281
1282 trace_rdev_update_owe_info(&rdev->wiphy, dev, oweinfo);
1283 if (rdev->ops->update_owe_info)
1284 ret = rdev->ops->update_owe_info(&rdev->wiphy, dev, oweinfo);
1285 trace_rdev_return_int(&rdev->wiphy, ret);
1286 return ret;
1287}
1288
1289static inline int
1290rdev_probe_mesh_link(struct cfg80211_registered_device *rdev,
1291 struct net_device *dev, const u8 *dest,
1292 const void *buf, size_t len)
1293{
1294 int ret;
1295
1296 trace_rdev_probe_mesh_link(&rdev->wiphy, dev, dest, buf, len);
1297 ret = rdev->ops->probe_mesh_link(&rdev->wiphy, dev, buf, len);
1298 trace_rdev_return_int(&rdev->wiphy, ret);
1299 return ret;
1300}
1301
1275#endif /* __CFG80211_RDEV_OPS */ 1302#endif /* __CFG80211_RDEV_OPS */
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 2f1bf91eb226..4831ad745f91 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -427,14 +427,10 @@ static const struct ieee80211_regdomain *
427reg_copy_regd(const struct ieee80211_regdomain *src_regd) 427reg_copy_regd(const struct ieee80211_regdomain *src_regd)
428{ 428{
429 struct ieee80211_regdomain *regd; 429 struct ieee80211_regdomain *regd;
430 int size_of_regd;
431 unsigned int i; 430 unsigned int i;
432 431
433 size_of_regd = 432 regd = kzalloc(struct_size(regd, reg_rules, src_regd->n_reg_rules),
434 sizeof(struct ieee80211_regdomain) + 433 GFP_KERNEL);
435 src_regd->n_reg_rules * sizeof(struct ieee80211_reg_rule);
436
437 regd = kzalloc(size_of_regd, GFP_KERNEL);
438 if (!regd) 434 if (!regd)
439 return ERR_PTR(-ENOMEM); 435 return ERR_PTR(-ENOMEM);
440 436
@@ -948,12 +944,10 @@ static int regdb_query_country(const struct fwdb_header *db,
948 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; 944 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2;
949 struct fwdb_collection *coll = (void *)((u8 *)db + ptr); 945 struct fwdb_collection *coll = (void *)((u8 *)db + ptr);
950 struct ieee80211_regdomain *regdom; 946 struct ieee80211_regdomain *regdom;
951 unsigned int size_of_regd, i; 947 unsigned int i;
952
953 size_of_regd = sizeof(struct ieee80211_regdomain) +
954 coll->n_rules * sizeof(struct ieee80211_reg_rule);
955 948
956 regdom = kzalloc(size_of_regd, GFP_KERNEL); 949 regdom = kzalloc(struct_size(regdom, reg_rules, coll->n_rules),
950 GFP_KERNEL);
957 if (!regdom) 951 if (!regdom)
958 return -ENOMEM; 952 return -ENOMEM;
959 953
@@ -1309,6 +1303,16 @@ reg_intersect_dfs_region(const enum nl80211_dfs_regions dfs_region1,
1309 return dfs_region1; 1303 return dfs_region1;
1310} 1304}
1311 1305
1306static void reg_wmm_rules_intersect(const struct ieee80211_wmm_ac *wmm_ac1,
1307 const struct ieee80211_wmm_ac *wmm_ac2,
1308 struct ieee80211_wmm_ac *intersect)
1309{
1310 intersect->cw_min = max_t(u16, wmm_ac1->cw_min, wmm_ac2->cw_min);
1311 intersect->cw_max = max_t(u16, wmm_ac1->cw_max, wmm_ac2->cw_max);
1312 intersect->cot = min_t(u16, wmm_ac1->cot, wmm_ac2->cot);
1313 intersect->aifsn = max_t(u8, wmm_ac1->aifsn, wmm_ac2->aifsn);
1314}
1315
1312/* 1316/*
1313 * Helper for regdom_intersect(), this does the real 1317 * Helper for regdom_intersect(), this does the real
1314 * mathematical intersection fun 1318 * mathematical intersection fun
@@ -1323,6 +1327,8 @@ static int reg_rules_intersect(const struct ieee80211_regdomain *rd1,
1323 struct ieee80211_freq_range *freq_range; 1327 struct ieee80211_freq_range *freq_range;
1324 const struct ieee80211_power_rule *power_rule1, *power_rule2; 1328 const struct ieee80211_power_rule *power_rule1, *power_rule2;
1325 struct ieee80211_power_rule *power_rule; 1329 struct ieee80211_power_rule *power_rule;
1330 const struct ieee80211_wmm_rule *wmm_rule1, *wmm_rule2;
1331 struct ieee80211_wmm_rule *wmm_rule;
1326 u32 freq_diff, max_bandwidth1, max_bandwidth2; 1332 u32 freq_diff, max_bandwidth1, max_bandwidth2;
1327 1333
1328 freq_range1 = &rule1->freq_range; 1334 freq_range1 = &rule1->freq_range;
@@ -1333,6 +1339,10 @@ static int reg_rules_intersect(const struct ieee80211_regdomain *rd1,
1333 power_rule2 = &rule2->power_rule; 1339 power_rule2 = &rule2->power_rule;
1334 power_rule = &intersected_rule->power_rule; 1340 power_rule = &intersected_rule->power_rule;
1335 1341
1342 wmm_rule1 = &rule1->wmm_rule;
1343 wmm_rule2 = &rule2->wmm_rule;
1344 wmm_rule = &intersected_rule->wmm_rule;
1345
1336 freq_range->start_freq_khz = max(freq_range1->start_freq_khz, 1346 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
1337 freq_range2->start_freq_khz); 1347 freq_range2->start_freq_khz);
1338 freq_range->end_freq_khz = min(freq_range1->end_freq_khz, 1348 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
@@ -1376,6 +1386,29 @@ static int reg_rules_intersect(const struct ieee80211_regdomain *rd1,
1376 intersected_rule->dfs_cac_ms = max(rule1->dfs_cac_ms, 1386 intersected_rule->dfs_cac_ms = max(rule1->dfs_cac_ms,
1377 rule2->dfs_cac_ms); 1387 rule2->dfs_cac_ms);
1378 1388
1389 if (rule1->has_wmm && rule2->has_wmm) {
1390 u8 ac;
1391
1392 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1393 reg_wmm_rules_intersect(&wmm_rule1->client[ac],
1394 &wmm_rule2->client[ac],
1395 &wmm_rule->client[ac]);
1396 reg_wmm_rules_intersect(&wmm_rule1->ap[ac],
1397 &wmm_rule2->ap[ac],
1398 &wmm_rule->ap[ac]);
1399 }
1400
1401 intersected_rule->has_wmm = true;
1402 } else if (rule1->has_wmm) {
1403 *wmm_rule = *wmm_rule1;
1404 intersected_rule->has_wmm = true;
1405 } else if (rule2->has_wmm) {
1406 *wmm_rule = *wmm_rule2;
1407 intersected_rule->has_wmm = true;
1408 } else {
1409 intersected_rule->has_wmm = false;
1410 }
1411
1379 if (!is_valid_reg_rule(intersected_rule)) 1412 if (!is_valid_reg_rule(intersected_rule))
1380 return -EINVAL; 1413 return -EINVAL;
1381 1414
@@ -1450,7 +1483,7 @@ static struct ieee80211_regdomain *
1450regdom_intersect(const struct ieee80211_regdomain *rd1, 1483regdom_intersect(const struct ieee80211_regdomain *rd1,
1451 const struct ieee80211_regdomain *rd2) 1484 const struct ieee80211_regdomain *rd2)
1452{ 1485{
1453 int r, size_of_regd; 1486 int r;
1454 unsigned int x, y; 1487 unsigned int x, y;
1455 unsigned int num_rules = 0; 1488 unsigned int num_rules = 0;
1456 const struct ieee80211_reg_rule *rule1, *rule2; 1489 const struct ieee80211_reg_rule *rule1, *rule2;
@@ -1481,10 +1514,7 @@ regdom_intersect(const struct ieee80211_regdomain *rd1,
1481 if (!num_rules) 1514 if (!num_rules)
1482 return NULL; 1515 return NULL;
1483 1516
1484 size_of_regd = sizeof(struct ieee80211_regdomain) + 1517 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
1485 num_rules * sizeof(struct ieee80211_reg_rule);
1486
1487 rd = kzalloc(size_of_regd, GFP_KERNEL);
1488 if (!rd) 1518 if (!rd)
1489 return NULL; 1519 return NULL;
1490 1520
@@ -3739,10 +3769,9 @@ void wiphy_regulatory_register(struct wiphy *wiphy)
3739 /* 3769 /*
3740 * The last request may have been received before this 3770 * The last request may have been received before this
3741 * registration call. Call the driver notifier if 3771 * registration call. Call the driver notifier if
3742 * initiator is USER and user type is CELL_BASE. 3772 * initiator is USER.
3743 */ 3773 */
3744 if (lr->initiator == NL80211_REGDOM_SET_BY_USER && 3774 if (lr->initiator == NL80211_REGDOM_SET_BY_USER)
3745 lr->user_reg_hint_type == NL80211_USER_REG_HINT_CELL_BASE)
3746 reg_call_notifier(wiphy, lr); 3775 reg_call_notifier(wiphy, lr);
3747 } 3776 }
3748 3777
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index 287518c6caa4..c04f5451f89b 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -179,21 +179,71 @@ static bool __cfg80211_unlink_bss(struct cfg80211_registered_device *rdev,
179 return true; 179 return true;
180} 180}
181 181
182bool cfg80211_is_element_inherited(const struct element *elem,
183 const struct element *non_inherit_elem)
184{
185 u8 id_len, ext_id_len, i, loop_len, id;
186 const u8 *list;
187
188 if (elem->id == WLAN_EID_MULTIPLE_BSSID)
189 return false;
190
191 if (!non_inherit_elem || non_inherit_elem->datalen < 2)
192 return true;
193
194 /*
195 * non inheritance element format is:
196 * ext ID (56) | IDs list len | list | extension IDs list len | list
197 * Both lists are optional. Both lengths are mandatory.
198 * This means valid length is:
199 * elem_len = 1 (extension ID) + 2 (list len fields) + list lengths
200 */
201 id_len = non_inherit_elem->data[1];
202 if (non_inherit_elem->datalen < 3 + id_len)
203 return true;
204
205 ext_id_len = non_inherit_elem->data[2 + id_len];
206 if (non_inherit_elem->datalen < 3 + id_len + ext_id_len)
207 return true;
208
209 if (elem->id == WLAN_EID_EXTENSION) {
210 if (!ext_id_len)
211 return true;
212 loop_len = ext_id_len;
213 list = &non_inherit_elem->data[3 + id_len];
214 id = elem->data[0];
215 } else {
216 if (!id_len)
217 return true;
218 loop_len = id_len;
219 list = &non_inherit_elem->data[2];
220 id = elem->id;
221 }
222
223 for (i = 0; i < loop_len; i++) {
224 if (list[i] == id)
225 return false;
226 }
227
228 return true;
229}
230EXPORT_SYMBOL(cfg80211_is_element_inherited);
231
182static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen, 232static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
183 const u8 *subelement, size_t subie_len, 233 const u8 *subelement, size_t subie_len,
184 u8 *new_ie, gfp_t gfp) 234 u8 *new_ie, gfp_t gfp)
185{ 235{
186 u8 *pos, *tmp; 236 u8 *pos, *tmp;
187 const u8 *tmp_old, *tmp_new; 237 const u8 *tmp_old, *tmp_new;
238 const struct element *non_inherit_elem;
188 u8 *sub_copy; 239 u8 *sub_copy;
189 240
190 /* copy subelement as we need to change its content to 241 /* copy subelement as we need to change its content to
191 * mark an ie after it is processed. 242 * mark an ie after it is processed.
192 */ 243 */
193 sub_copy = kmalloc(subie_len, gfp); 244 sub_copy = kmemdup(subelement, subie_len, gfp);
194 if (!sub_copy) 245 if (!sub_copy)
195 return 0; 246 return 0;
196 memcpy(sub_copy, subelement, subie_len);
197 247
198 pos = &new_ie[0]; 248 pos = &new_ie[0];
199 249
@@ -204,6 +254,11 @@ static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
204 pos += (tmp_new[1] + 2); 254 pos += (tmp_new[1] + 2);
205 } 255 }
206 256
257 /* get non inheritance list if exists */
258 non_inherit_elem =
259 cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE,
260 sub_copy, subie_len);
261
207 /* go through IEs in ie (skip SSID) and subelement, 262 /* go through IEs in ie (skip SSID) and subelement,
208 * merge them into new_ie 263 * merge them into new_ie
209 */ 264 */
@@ -224,8 +279,11 @@ static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
224 subie_len); 279 subie_len);
225 280
226 if (!tmp) { 281 if (!tmp) {
282 const struct element *old_elem = (void *)tmp_old;
283
227 /* ie in old ie but not in subelement */ 284 /* ie in old ie but not in subelement */
228 if (tmp_old[0] != WLAN_EID_MULTIPLE_BSSID) { 285 if (cfg80211_is_element_inherited(old_elem,
286 non_inherit_elem)) {
229 memcpy(pos, tmp_old, tmp_old[1] + 2); 287 memcpy(pos, tmp_old, tmp_old[1] + 2);
230 pos += tmp_old[1] + 2; 288 pos += tmp_old[1] + 2;
231 } 289 }
@@ -269,8 +327,7 @@ static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
269 tmp_new = sub_copy; 327 tmp_new = sub_copy;
270 while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) { 328 while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
271 if (!(tmp_new[0] == WLAN_EID_NON_TX_BSSID_CAP || 329 if (!(tmp_new[0] == WLAN_EID_NON_TX_BSSID_CAP ||
272 tmp_new[0] == WLAN_EID_SSID || 330 tmp_new[0] == WLAN_EID_SSID)) {
273 tmp_new[0] == WLAN_EID_MULTI_BSSID_IDX)) {
274 memcpy(pos, tmp_new, tmp_new[1] + 2); 331 memcpy(pos, tmp_new, tmp_new[1] + 2);
275 pos += tmp_new[1] + 2; 332 pos += tmp_new[1] + 2;
276 } 333 }
@@ -1398,6 +1455,78 @@ cfg80211_inform_single_bss_data(struct wiphy *wiphy,
1398 return &res->pub; 1455 return &res->pub;
1399} 1456}
1400 1457
1458static const struct element
1459*cfg80211_get_profile_continuation(const u8 *ie, size_t ielen,
1460 const struct element *mbssid_elem,
1461 const struct element *sub_elem)
1462{
1463 const u8 *mbssid_end = mbssid_elem->data + mbssid_elem->datalen;
1464 const struct element *next_mbssid;
1465 const struct element *next_sub;
1466
1467 next_mbssid = cfg80211_find_elem(WLAN_EID_MULTIPLE_BSSID,
1468 mbssid_end,
1469 ielen - (mbssid_end - ie));
1470
1471 /*
1472 * If is is not the last subelement in current MBSSID IE or there isn't
1473 * a next MBSSID IE - profile is complete.
1474 */
1475 if ((sub_elem->data + sub_elem->datalen < mbssid_end - 1) ||
1476 !next_mbssid)
1477 return NULL;
1478
1479 /* For any length error, just return NULL */
1480
1481 if (next_mbssid->datalen < 4)
1482 return NULL;
1483
1484 next_sub = (void *)&next_mbssid->data[1];
1485
1486 if (next_mbssid->data + next_mbssid->datalen <
1487 next_sub->data + next_sub->datalen)
1488 return NULL;
1489
1490 if (next_sub->id != 0 || next_sub->datalen < 2)
1491 return NULL;
1492
1493 /*
1494 * Check if the first element in the next sub element is a start
1495 * of a new profile
1496 */
1497 return next_sub->data[0] == WLAN_EID_NON_TX_BSSID_CAP ?
1498 NULL : next_mbssid;
1499}
1500
1501size_t cfg80211_merge_profile(const u8 *ie, size_t ielen,
1502 const struct element *mbssid_elem,
1503 const struct element *sub_elem,
1504 u8 *merged_ie, size_t max_copy_len)
1505{
1506 size_t copied_len = sub_elem->datalen;
1507 const struct element *next_mbssid;
1508
1509 if (sub_elem->datalen > max_copy_len)
1510 return 0;
1511
1512 memcpy(merged_ie, sub_elem->data, sub_elem->datalen);
1513
1514 while ((next_mbssid = cfg80211_get_profile_continuation(ie, ielen,
1515 mbssid_elem,
1516 sub_elem))) {
1517 const struct element *next_sub = (void *)&next_mbssid->data[1];
1518
1519 if (copied_len + next_sub->datalen > max_copy_len)
1520 break;
1521 memcpy(merged_ie + copied_len, next_sub->data,
1522 next_sub->datalen);
1523 copied_len += next_sub->datalen;
1524 }
1525
1526 return copied_len;
1527}
1528EXPORT_SYMBOL(cfg80211_merge_profile);
1529
1401static void cfg80211_parse_mbssid_data(struct wiphy *wiphy, 1530static void cfg80211_parse_mbssid_data(struct wiphy *wiphy,
1402 struct cfg80211_inform_bss *data, 1531 struct cfg80211_inform_bss *data,
1403 enum cfg80211_bss_frame_type ftype, 1532 enum cfg80211_bss_frame_type ftype,
@@ -1411,7 +1540,8 @@ static void cfg80211_parse_mbssid_data(struct wiphy *wiphy,
1411 const struct element *elem, *sub; 1540 const struct element *elem, *sub;
1412 size_t new_ie_len; 1541 size_t new_ie_len;
1413 u8 new_bssid[ETH_ALEN]; 1542 u8 new_bssid[ETH_ALEN];
1414 u8 *new_ie; 1543 u8 *new_ie, *profile;
1544 u64 seen_indices = 0;
1415 u16 capability; 1545 u16 capability;
1416 struct cfg80211_bss *bss; 1546 struct cfg80211_bss *bss;
1417 1547
@@ -1429,10 +1559,16 @@ static void cfg80211_parse_mbssid_data(struct wiphy *wiphy,
1429 if (!new_ie) 1559 if (!new_ie)
1430 return; 1560 return;
1431 1561
1562 profile = kmalloc(ielen, gfp);
1563 if (!profile)
1564 goto out;
1565
1432 for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, ie, ielen) { 1566 for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, ie, ielen) {
1433 if (elem->datalen < 4) 1567 if (elem->datalen < 4)
1434 continue; 1568 continue;
1435 for_each_element(sub, elem->data + 1, elem->datalen - 1) { 1569 for_each_element(sub, elem->data + 1, elem->datalen - 1) {
1570 u8 profile_len;
1571
1436 if (sub->id != 0 || sub->datalen < 4) { 1572 if (sub->id != 0 || sub->datalen < 4) {
1437 /* not a valid BSS profile */ 1573 /* not a valid BSS profile */
1438 continue; 1574 continue;
@@ -1447,16 +1583,31 @@ static void cfg80211_parse_mbssid_data(struct wiphy *wiphy,
1447 continue; 1583 continue;
1448 } 1584 }
1449 1585
1586 memset(profile, 0, ielen);
1587 profile_len = cfg80211_merge_profile(ie, ielen,
1588 elem,
1589 sub,
1590 profile,
1591 ielen);
1592
1450 /* found a Nontransmitted BSSID Profile */ 1593 /* found a Nontransmitted BSSID Profile */
1451 mbssid_index_ie = cfg80211_find_ie 1594 mbssid_index_ie = cfg80211_find_ie
1452 (WLAN_EID_MULTI_BSSID_IDX, 1595 (WLAN_EID_MULTI_BSSID_IDX,
1453 sub->data, sub->datalen); 1596 profile, profile_len);
1454 if (!mbssid_index_ie || mbssid_index_ie[1] < 1 || 1597 if (!mbssid_index_ie || mbssid_index_ie[1] < 1 ||
1455 mbssid_index_ie[2] == 0) { 1598 mbssid_index_ie[2] == 0 ||
1599 mbssid_index_ie[2] > 46) {
1456 /* No valid Multiple BSSID-Index element */ 1600 /* No valid Multiple BSSID-Index element */
1457 continue; 1601 continue;
1458 } 1602 }
1459 1603
1604 if (seen_indices & BIT(mbssid_index_ie[2]))
1605 /* We don't support legacy split of a profile */
1606 net_dbg_ratelimited("Partial info for BSSID index %d\n",
1607 mbssid_index_ie[2]);
1608
1609 seen_indices |= BIT(mbssid_index_ie[2]);
1610
1460 non_tx_data->bssid_index = mbssid_index_ie[2]; 1611 non_tx_data->bssid_index = mbssid_index_ie[2];
1461 non_tx_data->max_bssid_indicator = elem->data[0]; 1612 non_tx_data->max_bssid_indicator = elem->data[0];
1462 1613
@@ -1465,13 +1616,14 @@ static void cfg80211_parse_mbssid_data(struct wiphy *wiphy,
1465 non_tx_data->bssid_index, 1616 non_tx_data->bssid_index,
1466 new_bssid); 1617 new_bssid);
1467 memset(new_ie, 0, IEEE80211_MAX_DATA_LEN); 1618 memset(new_ie, 0, IEEE80211_MAX_DATA_LEN);
1468 new_ie_len = cfg80211_gen_new_ie(ie, ielen, sub->data, 1619 new_ie_len = cfg80211_gen_new_ie(ie, ielen,
1469 sub->datalen, new_ie, 1620 profile,
1621 profile_len, new_ie,
1470 gfp); 1622 gfp);
1471 if (!new_ie_len) 1623 if (!new_ie_len)
1472 continue; 1624 continue;
1473 1625
1474 capability = get_unaligned_le16(sub->data + 2); 1626 capability = get_unaligned_le16(profile + 2);
1475 bss = cfg80211_inform_single_bss_data(wiphy, data, 1627 bss = cfg80211_inform_single_bss_data(wiphy, data,
1476 ftype, 1628 ftype,
1477 new_bssid, tsf, 1629 new_bssid, tsf,
@@ -1487,7 +1639,9 @@ static void cfg80211_parse_mbssid_data(struct wiphy *wiphy,
1487 } 1639 }
1488 } 1640 }
1489 1641
1642out:
1490 kfree(new_ie); 1643 kfree(new_ie);
1644 kfree(profile);
1491} 1645}
1492 1646
1493struct cfg80211_bss * 1647struct cfg80211_bss *
diff --git a/net/wireless/trace.h b/net/wireless/trace.h
index 44b2ce1bb13a..2abfff925aac 100644
--- a/net/wireless/trace.h
+++ b/net/wireless/trace.h
@@ -430,22 +430,43 @@ DECLARE_EVENT_CLASS(key_handle,
430 BOOL_TO_STR(__entry->pairwise), MAC_PR_ARG(mac_addr)) 430 BOOL_TO_STR(__entry->pairwise), MAC_PR_ARG(mac_addr))
431); 431);
432 432
433DEFINE_EVENT(key_handle, rdev_add_key, 433DEFINE_EVENT(key_handle, rdev_get_key,
434 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, 434 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
435 bool pairwise, const u8 *mac_addr), 435 bool pairwise, const u8 *mac_addr),
436 TP_ARGS(wiphy, netdev, key_index, pairwise, mac_addr) 436 TP_ARGS(wiphy, netdev, key_index, pairwise, mac_addr)
437); 437);
438 438
439DEFINE_EVENT(key_handle, rdev_get_key, 439DEFINE_EVENT(key_handle, rdev_del_key,
440 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, 440 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
441 bool pairwise, const u8 *mac_addr), 441 bool pairwise, const u8 *mac_addr),
442 TP_ARGS(wiphy, netdev, key_index, pairwise, mac_addr) 442 TP_ARGS(wiphy, netdev, key_index, pairwise, mac_addr)
443); 443);
444 444
445DEFINE_EVENT(key_handle, rdev_del_key, 445TRACE_EVENT(rdev_add_key,
446 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, 446 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
447 bool pairwise, const u8 *mac_addr), 447 bool pairwise, const u8 *mac_addr, u8 mode),
448 TP_ARGS(wiphy, netdev, key_index, pairwise, mac_addr) 448 TP_ARGS(wiphy, netdev, key_index, pairwise, mac_addr, mode),
449 TP_STRUCT__entry(
450 WIPHY_ENTRY
451 NETDEV_ENTRY
452 MAC_ENTRY(mac_addr)
453 __field(u8, key_index)
454 __field(bool, pairwise)
455 __field(u8, mode)
456 ),
457 TP_fast_assign(
458 WIPHY_ASSIGN;
459 NETDEV_ASSIGN;
460 MAC_ASSIGN(mac_addr, mac_addr);
461 __entry->key_index = key_index;
462 __entry->pairwise = pairwise;
463 __entry->mode = mode;
464 ),
465 TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", key_index: %u, "
466 "mode: %u, pairwise: %s, mac addr: " MAC_PR_FMT,
467 WIPHY_PR_ARG, NETDEV_PR_ARG, __entry->key_index,
468 __entry->mode, BOOL_TO_STR(__entry->pairwise),
469 MAC_PR_ARG(mac_addr))
449); 470);
450 471
451TRACE_EVENT(rdev_set_default_key, 472TRACE_EVENT(rdev_set_default_key,
@@ -3362,6 +3383,62 @@ TRACE_EVENT(cfg80211_pmsr_complete,
3362 WIPHY_PR_ARG, WDEV_PR_ARG, 3383 WIPHY_PR_ARG, WDEV_PR_ARG,
3363 (unsigned long long)__entry->cookie) 3384 (unsigned long long)__entry->cookie)
3364); 3385);
3386
3387TRACE_EVENT(rdev_update_owe_info,
3388 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
3389 struct cfg80211_update_owe_info *owe_info),
3390 TP_ARGS(wiphy, netdev, owe_info),
3391 TP_STRUCT__entry(WIPHY_ENTRY
3392 NETDEV_ENTRY
3393 MAC_ENTRY(peer)
3394 __field(u16, status)
3395 __dynamic_array(u8, ie, owe_info->ie_len)),
3396 TP_fast_assign(WIPHY_ASSIGN;
3397 NETDEV_ASSIGN;
3398 MAC_ASSIGN(peer, owe_info->peer);
3399 __entry->status = owe_info->status;
3400 memcpy(__get_dynamic_array(ie),
3401 owe_info->ie, owe_info->ie_len);),
3402 TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", peer: " MAC_PR_FMT
3403 " status %d", WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(peer),
3404 __entry->status)
3405);
3406
3407TRACE_EVENT(cfg80211_update_owe_info_event,
3408 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
3409 struct cfg80211_update_owe_info *owe_info),
3410 TP_ARGS(wiphy, netdev, owe_info),
3411 TP_STRUCT__entry(WIPHY_ENTRY
3412 NETDEV_ENTRY
3413 MAC_ENTRY(peer)
3414 __dynamic_array(u8, ie, owe_info->ie_len)),
3415 TP_fast_assign(WIPHY_ASSIGN;
3416 NETDEV_ASSIGN;
3417 MAC_ASSIGN(peer, owe_info->peer);
3418 memcpy(__get_dynamic_array(ie), owe_info->ie,
3419 owe_info->ie_len);),
3420 TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", peer: " MAC_PR_FMT,
3421 WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(peer))
3422);
3423
3424TRACE_EVENT(rdev_probe_mesh_link,
3425 TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
3426 const u8 *dest, const u8 *buf, size_t len),
3427 TP_ARGS(wiphy, netdev, dest, buf, len),
3428 TP_STRUCT__entry(
3429 WIPHY_ENTRY
3430 NETDEV_ENTRY
3431 MAC_ENTRY(dest)
3432 ),
3433 TP_fast_assign(
3434 WIPHY_ASSIGN;
3435 NETDEV_ASSIGN;
3436 MAC_ASSIGN(dest, dest);
3437 ),
3438 TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", " MAC_PR_FMT,
3439 WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(dest))
3440);
3441
3365#endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */ 3442#endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */
3366 3443
3367#undef TRACE_INCLUDE_PATH 3444#undef TRACE_INCLUDE_PATH
diff --git a/net/wireless/util.c b/net/wireless/util.c
index e4b8db5e81ec..cf63b635afc0 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -237,14 +237,23 @@ int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
237 case WLAN_CIPHER_SUITE_CCMP_256: 237 case WLAN_CIPHER_SUITE_CCMP_256:
238 case WLAN_CIPHER_SUITE_GCMP: 238 case WLAN_CIPHER_SUITE_GCMP:
239 case WLAN_CIPHER_SUITE_GCMP_256: 239 case WLAN_CIPHER_SUITE_GCMP_256:
240 /* Disallow pairwise keys with non-zero index unless it's WEP 240 /* IEEE802.11-2016 allows only 0 and - when using Extended Key
241 * or a vendor specific cipher (because current deployments use 241 * ID - 1 as index for pairwise keys.
242 * pairwise WEP keys with non-zero indices and for vendor 242 * @NL80211_KEY_NO_TX is only allowed for pairwise keys when
243 * specific ciphers this should be validated in the driver or 243 * the driver supports Extended Key ID.
244 * hardware level - but 802.11i clearly specifies to use zero) 244 * @NL80211_KEY_SET_TX can't be set when installing and
245 * validating a key.
245 */ 246 */
246 if (pairwise && key_idx) 247 if (params->mode == NL80211_KEY_NO_TX) {
248 if (!wiphy_ext_feature_isset(&rdev->wiphy,
249 NL80211_EXT_FEATURE_EXT_KEY_ID))
250 return -EINVAL;
251 else if (!pairwise || key_idx < 0 || key_idx > 1)
252 return -EINVAL;
253 } else if ((pairwise && key_idx) ||
254 params->mode == NL80211_KEY_SET_TX) {
247 return -EINVAL; 255 return -EINVAL;
256 }
248 break; 257 break;
249 case WLAN_CIPHER_SUITE_AES_CMAC: 258 case WLAN_CIPHER_SUITE_AES_CMAC:
250 case WLAN_CIPHER_SUITE_BIP_CMAC_256: 259 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
@@ -1220,9 +1229,11 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
1220 else if (rate->bw == RATE_INFO_BW_HE_RU && 1229 else if (rate->bw == RATE_INFO_BW_HE_RU &&
1221 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26) 1230 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26)
1222 result = rates_26[rate->he_gi]; 1231 result = rates_26[rate->he_gi];
1223 else if (WARN(1, "invalid HE MCS: bw:%d, ru:%d\n", 1232 else {
1224 rate->bw, rate->he_ru_alloc)) 1233 WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
1234 rate->bw, rate->he_ru_alloc);
1225 return 0; 1235 return 0;
1236 }
1226 1237
1227 /* now scale to the appropriate MCS */ 1238 /* now scale to the appropriate MCS */
1228 tmp = result; 1239 tmp = result;
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index d522787c7354..46e4d69db845 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -353,9 +353,6 @@ static int cfg80211_wext_siwretry(struct net_device *dev,
353 changed |= WIPHY_PARAM_RETRY_SHORT; 353 changed |= WIPHY_PARAM_RETRY_SHORT;
354 } 354 }
355 355
356 if (!changed)
357 return 0;
358
359 err = rdev_set_wiphy_params(rdev, changed); 356 err = rdev_set_wiphy_params(rdev, changed);
360 if (err) { 357 if (err) {
361 wdev->wiphy->retry_short = oshort; 358 wdev->wiphy->retry_short = oshort;
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 20a511398389..0ea48a52ce79 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -1398,18 +1398,6 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1398 break; 1398 break;
1399 } 1399 }
1400 1400
1401 case SIOCGSTAMP:
1402 rc = -EINVAL;
1403 if (sk)
1404 rc = sock_get_timestamp(sk,
1405 (struct timeval __user *)argp);
1406 break;
1407 case SIOCGSTAMPNS:
1408 rc = -EINVAL;
1409 if (sk)
1410 rc = sock_get_timestampns(sk,
1411 (struct timespec __user *)argp);
1412 break;
1413 case SIOCGIFADDR: 1401 case SIOCGIFADDR:
1414 case SIOCSIFADDR: 1402 case SIOCSIFADDR:
1415 case SIOCGIFDSTADDR: 1403 case SIOCGIFDSTADDR:
@@ -1681,8 +1669,6 @@ static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
1681 unsigned long arg) 1669 unsigned long arg)
1682{ 1670{
1683 void __user *argp = compat_ptr(arg); 1671 void __user *argp = compat_ptr(arg);
1684 struct sock *sk = sock->sk;
1685
1686 int rc = -ENOIOCTLCMD; 1672 int rc = -ENOIOCTLCMD;
1687 1673
1688 switch(cmd) { 1674 switch(cmd) {
@@ -1690,18 +1676,6 @@ static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
1690 case TIOCINQ: 1676 case TIOCINQ:
1691 rc = x25_ioctl(sock, cmd, (unsigned long)argp); 1677 rc = x25_ioctl(sock, cmd, (unsigned long)argp);
1692 break; 1678 break;
1693 case SIOCGSTAMP:
1694 rc = -EINVAL;
1695 if (sk)
1696 rc = compat_sock_get_timestamp(sk,
1697 (struct timeval __user*)argp);
1698 break;
1699 case SIOCGSTAMPNS:
1700 rc = -EINVAL;
1701 if (sk)
1702 rc = compat_sock_get_timestampns(sk,
1703 (struct timespec __user*)argp);
1704 break;
1705 case SIOCGIFADDR: 1679 case SIOCGIFADDR:
1706 case SIOCSIFADDR: 1680 case SIOCSIFADDR:
1707 case SIOCGIFDSTADDR: 1681 case SIOCGIFDSTADDR:
@@ -1765,6 +1739,7 @@ static const struct proto_ops x25_proto_ops = {
1765#ifdef CONFIG_COMPAT 1739#ifdef CONFIG_COMPAT
1766 .compat_ioctl = compat_x25_ioctl, 1740 .compat_ioctl = compat_x25_ioctl,
1767#endif 1741#endif
1742 .gettstamp = sock_gettstamp,
1768 .listen = x25_listen, 1743 .listen = x25_listen,
1769 .shutdown = sock_no_shutdown, 1744 .shutdown = sock_no_shutdown,
1770 .setsockopt = x25_setsockopt, 1745 .setsockopt = x25_setsockopt,
diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index 989e52386c35..2b18223e7eb8 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -253,8 +253,8 @@ static int xdp_umem_pin_pages(struct xdp_umem *umem)
253 return -ENOMEM; 253 return -ENOMEM;
254 254
255 down_read(&current->mm->mmap_sem); 255 down_read(&current->mm->mmap_sem);
256 npgs = get_user_pages_longterm(umem->address, umem->npgs, 256 npgs = get_user_pages(umem->address, umem->npgs,
257 gup_flags, &umem->pgs[0], NULL); 257 gup_flags | FOLL_LONGTERM, &umem->pgs[0], NULL);
258 up_read(&current->mm->mmap_sem); 258 up_read(&current->mm->mmap_sem);
259 259
260 if (npgs != umem->npgs) { 260 if (npgs != umem->npgs) {
diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
index 610c0bdc0c2b..88b9ae24658d 100644
--- a/net/xdp/xsk_queue.h
+++ b/net/xdp/xsk_queue.h
@@ -43,6 +43,48 @@ struct xsk_queue {
43 u64 invalid_descs; 43 u64 invalid_descs;
44}; 44};
45 45
46/* The structure of the shared state of the rings are the same as the
47 * ring buffer in kernel/events/ring_buffer.c. For the Rx and completion
48 * ring, the kernel is the producer and user space is the consumer. For
49 * the Tx and fill rings, the kernel is the consumer and user space is
50 * the producer.
51 *
52 * producer consumer
53 *
54 * if (LOAD ->consumer) { LOAD ->producer
55 * (A) smp_rmb() (C)
56 * STORE $data LOAD $data
57 * smp_wmb() (B) smp_mb() (D)
58 * STORE ->producer STORE ->consumer
59 * }
60 *
61 * (A) pairs with (D), and (B) pairs with (C).
62 *
63 * Starting with (B), it protects the data from being written after
64 * the producer pointer. If this barrier was missing, the consumer
65 * could observe the producer pointer being set and thus load the data
66 * before the producer has written the new data. The consumer would in
67 * this case load the old data.
68 *
69 * (C) protects the consumer from speculatively loading the data before
70 * the producer pointer actually has been read. If we do not have this
71 * barrier, some architectures could load old data as speculative loads
72 * are not discarded as the CPU does not know there is a dependency
73 * between ->producer and data.
74 *
75 * (A) is a control dependency that separates the load of ->consumer
76 * from the stores of $data. In case ->consumer indicates there is no
77 * room in the buffer to store $data we do not. So no barrier is needed.
78 *
79 * (D) protects the load of the data to be observed to happen after the
80 * store of the consumer pointer. If we did not have this memory
81 * barrier, the producer could observe the consumer pointer being set
82 * and overwrite the data with a new value before the consumer got the
83 * chance to read the old value. The consumer would thus miss reading
84 * the old entry and very likely read the new entry twice, once right
85 * now and again after circling through the ring.
86 */
87
46/* Common functions operating for both RXTX and umem queues */ 88/* Common functions operating for both RXTX and umem queues */
47 89
48static inline u64 xskq_nb_invalid_descs(struct xsk_queue *q) 90static inline u64 xskq_nb_invalid_descs(struct xsk_queue *q)
@@ -106,6 +148,7 @@ static inline u64 *xskq_validate_addr(struct xsk_queue *q, u64 *addr)
106static inline u64 *xskq_peek_addr(struct xsk_queue *q, u64 *addr) 148static inline u64 *xskq_peek_addr(struct xsk_queue *q, u64 *addr)
107{ 149{
108 if (q->cons_tail == q->cons_head) { 150 if (q->cons_tail == q->cons_head) {
151 smp_mb(); /* D, matches A */
109 WRITE_ONCE(q->ring->consumer, q->cons_tail); 152 WRITE_ONCE(q->ring->consumer, q->cons_tail);
110 q->cons_head = q->cons_tail + xskq_nb_avail(q, RX_BATCH_SIZE); 153 q->cons_head = q->cons_tail + xskq_nb_avail(q, RX_BATCH_SIZE);
111 154
@@ -128,10 +171,11 @@ static inline int xskq_produce_addr(struct xsk_queue *q, u64 addr)
128 if (xskq_nb_free(q, q->prod_tail, 1) == 0) 171 if (xskq_nb_free(q, q->prod_tail, 1) == 0)
129 return -ENOSPC; 172 return -ENOSPC;
130 173
174 /* A, matches D */
131 ring->desc[q->prod_tail++ & q->ring_mask] = addr; 175 ring->desc[q->prod_tail++ & q->ring_mask] = addr;
132 176
133 /* Order producer and data */ 177 /* Order producer and data */
134 smp_wmb(); 178 smp_wmb(); /* B, matches C */
135 179
136 WRITE_ONCE(q->ring->producer, q->prod_tail); 180 WRITE_ONCE(q->ring->producer, q->prod_tail);
137 return 0; 181 return 0;
@@ -144,6 +188,7 @@ static inline int xskq_produce_addr_lazy(struct xsk_queue *q, u64 addr)
144 if (xskq_nb_free(q, q->prod_head, LAZY_UPDATE_THRESHOLD) == 0) 188 if (xskq_nb_free(q, q->prod_head, LAZY_UPDATE_THRESHOLD) == 0)
145 return -ENOSPC; 189 return -ENOSPC;
146 190
191 /* A, matches D */
147 ring->desc[q->prod_head++ & q->ring_mask] = addr; 192 ring->desc[q->prod_head++ & q->ring_mask] = addr;
148 return 0; 193 return 0;
149} 194}
@@ -152,7 +197,7 @@ static inline void xskq_produce_flush_addr_n(struct xsk_queue *q,
152 u32 nb_entries) 197 u32 nb_entries)
153{ 198{
154 /* Order producer and data */ 199 /* Order producer and data */
155 smp_wmb(); 200 smp_wmb(); /* B, matches C */
156 201
157 q->prod_tail += nb_entries; 202 q->prod_tail += nb_entries;
158 WRITE_ONCE(q->ring->producer, q->prod_tail); 203 WRITE_ONCE(q->ring->producer, q->prod_tail);
@@ -163,6 +208,7 @@ static inline int xskq_reserve_addr(struct xsk_queue *q)
163 if (xskq_nb_free(q, q->prod_head, 1) == 0) 208 if (xskq_nb_free(q, q->prod_head, 1) == 0)
164 return -ENOSPC; 209 return -ENOSPC;
165 210
211 /* A, matches D */
166 q->prod_head++; 212 q->prod_head++;
167 return 0; 213 return 0;
168} 214}
@@ -204,11 +250,12 @@ static inline struct xdp_desc *xskq_peek_desc(struct xsk_queue *q,
204 struct xdp_desc *desc) 250 struct xdp_desc *desc)
205{ 251{
206 if (q->cons_tail == q->cons_head) { 252 if (q->cons_tail == q->cons_head) {
253 smp_mb(); /* D, matches A */
207 WRITE_ONCE(q->ring->consumer, q->cons_tail); 254 WRITE_ONCE(q->ring->consumer, q->cons_tail);
208 q->cons_head = q->cons_tail + xskq_nb_avail(q, RX_BATCH_SIZE); 255 q->cons_head = q->cons_tail + xskq_nb_avail(q, RX_BATCH_SIZE);
209 256
210 /* Order consumer and data */ 257 /* Order consumer and data */
211 smp_rmb(); 258 smp_rmb(); /* C, matches B */
212 } 259 }
213 260
214 return xskq_validate_desc(q, desc); 261 return xskq_validate_desc(q, desc);
@@ -228,6 +275,7 @@ static inline int xskq_produce_batch_desc(struct xsk_queue *q,
228 if (xskq_nb_free(q, q->prod_head, 1) == 0) 275 if (xskq_nb_free(q, q->prod_head, 1) == 0)
229 return -ENOSPC; 276 return -ENOSPC;
230 277
278 /* A, matches D */
231 idx = (q->prod_head++) & q->ring_mask; 279 idx = (q->prod_head++) & q->ring_mask;
232 ring->desc[idx].addr = addr; 280 ring->desc[idx].addr = addr;
233 ring->desc[idx].len = len; 281 ring->desc[idx].len = len;
@@ -238,7 +286,7 @@ static inline int xskq_produce_batch_desc(struct xsk_queue *q,
238static inline void xskq_produce_flush_desc(struct xsk_queue *q) 286static inline void xskq_produce_flush_desc(struct xsk_queue *q)
239{ 287{
240 /* Order producer and data */ 288 /* Order producer and data */
241 smp_wmb(); 289 smp_wmb(); /* B, matches C */
242 290
243 q->prod_tail = q->prod_head, 291 q->prod_tail = q->prod_head,
244 WRITE_ONCE(q->ring->producer, q->prod_tail); 292 WRITE_ONCE(q->ring->producer, q->prod_tail);
diff --git a/net/xfrm/Kconfig b/net/xfrm/Kconfig
index 5d43aaa17027..1ec8071226b2 100644
--- a/net/xfrm/Kconfig
+++ b/net/xfrm/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4config XFRM 4config XFRM
5 bool 5 bool
6 depends on NET 6 depends on INET
7 select GRO_CELLS 7 select GRO_CELLS
8 select SKB_EXTENSIONS 8 select SKB_EXTENSIONS
9 9
@@ -15,9 +15,9 @@ config XFRM_ALGO
15 select XFRM 15 select XFRM
16 select CRYPTO 16 select CRYPTO
17 17
18if INET
18config XFRM_USER 19config XFRM_USER
19 tristate "Transformation user configuration interface" 20 tristate "Transformation user configuration interface"
20 depends on INET
21 select XFRM_ALGO 21 select XFRM_ALGO
22 ---help--- 22 ---help---
23 Support for Transformation(XFRM) user configuration interface 23 Support for Transformation(XFRM) user configuration interface
@@ -56,7 +56,7 @@ config XFRM_MIGRATE
56 56
57config XFRM_STATISTICS 57config XFRM_STATISTICS
58 bool "Transformation statistics" 58 bool "Transformation statistics"
59 depends on INET && XFRM && PROC_FS 59 depends on XFRM && PROC_FS
60 ---help--- 60 ---help---
61 This statistics is not a SNMP/MIB specification but shows 61 This statistics is not a SNMP/MIB specification but shows
62 statistics about transformation error (or almost error) factor 62 statistics about transformation error (or almost error) factor
@@ -95,3 +95,5 @@ config NET_KEY_MIGRATE
95 <draft-sugimoto-mip6-pfkey-migrate>. 95 <draft-sugimoto-mip6-pfkey-migrate>.
96 96
97 If unsure, say N. 97 If unsure, say N.
98
99endif # INET
diff --git a/net/xfrm/xfrm_device.c b/net/xfrm/xfrm_device.c
index b8736f56e7f7..b24cd86a02c3 100644
--- a/net/xfrm/xfrm_device.c
+++ b/net/xfrm/xfrm_device.c
@@ -23,6 +23,60 @@
23#include <linux/notifier.h> 23#include <linux/notifier.h>
24 24
25#ifdef CONFIG_XFRM_OFFLOAD 25#ifdef CONFIG_XFRM_OFFLOAD
26static void __xfrm_transport_prep(struct xfrm_state *x, struct sk_buff *skb,
27 unsigned int hsize)
28{
29 struct xfrm_offload *xo = xfrm_offload(skb);
30
31 skb_reset_mac_len(skb);
32 pskb_pull(skb, skb->mac_len + hsize + x->props.header_len);
33
34 if (xo->flags & XFRM_GSO_SEGMENT) {
35 skb_reset_transport_header(skb);
36 skb->transport_header -= x->props.header_len;
37 }
38}
39
40static void __xfrm_mode_tunnel_prep(struct xfrm_state *x, struct sk_buff *skb,
41 unsigned int hsize)
42
43{
44 struct xfrm_offload *xo = xfrm_offload(skb);
45
46 if (xo->flags & XFRM_GSO_SEGMENT)
47 skb->transport_header = skb->network_header + hsize;
48
49 skb_reset_mac_len(skb);
50 pskb_pull(skb, skb->mac_len + x->props.header_len);
51}
52
53/* Adjust pointers into the packet when IPsec is done at layer2 */
54static void xfrm_outer_mode_prep(struct xfrm_state *x, struct sk_buff *skb)
55{
56 switch (x->outer_mode.encap) {
57 case XFRM_MODE_TUNNEL:
58 if (x->outer_mode.family == AF_INET)
59 return __xfrm_mode_tunnel_prep(x, skb,
60 sizeof(struct iphdr));
61 if (x->outer_mode.family == AF_INET6)
62 return __xfrm_mode_tunnel_prep(x, skb,
63 sizeof(struct ipv6hdr));
64 break;
65 case XFRM_MODE_TRANSPORT:
66 if (x->outer_mode.family == AF_INET)
67 return __xfrm_transport_prep(x, skb,
68 sizeof(struct iphdr));
69 if (x->outer_mode.family == AF_INET6)
70 return __xfrm_transport_prep(x, skb,
71 sizeof(struct ipv6hdr));
72 break;
73 case XFRM_MODE_ROUTEOPTIMIZATION:
74 case XFRM_MODE_IN_TRIGGER:
75 case XFRM_MODE_BEET:
76 break;
77 }
78}
79
26struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t features, bool *again) 80struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t features, bool *again)
27{ 81{
28 int err; 82 int err;
@@ -78,7 +132,8 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featur
78 } 132 }
79 133
80 if (!skb->next) { 134 if (!skb->next) {
81 x->outer_mode->xmit(x, skb); 135 esp_features |= skb->dev->gso_partial_features;
136 xfrm_outer_mode_prep(x, skb);
82 137
83 xo->flags |= XFRM_DEV_RESUME; 138 xo->flags |= XFRM_DEV_RESUME;
84 139
@@ -101,12 +156,14 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featur
101 156
102 do { 157 do {
103 struct sk_buff *nskb = skb2->next; 158 struct sk_buff *nskb = skb2->next;
159
160 esp_features |= skb->dev->gso_partial_features;
104 skb_mark_not_on_list(skb2); 161 skb_mark_not_on_list(skb2);
105 162
106 xo = xfrm_offload(skb2); 163 xo = xfrm_offload(skb2);
107 xo->flags |= XFRM_DEV_RESUME; 164 xo->flags |= XFRM_DEV_RESUME;
108 165
109 x->outer_mode->xmit(x, skb2); 166 xfrm_outer_mode_prep(x, skb2);
110 167
111 err = x->type_offload->xmit(x, skb2, esp_features); 168 err = x->type_offload->xmit(x, skb2, esp_features);
112 if (!err) { 169 if (!err) {
@@ -247,7 +304,7 @@ void xfrm_dev_resume(struct sk_buff *skb)
247 unsigned long flags; 304 unsigned long flags;
248 305
249 rcu_read_lock(); 306 rcu_read_lock();
250 txq = netdev_pick_tx(dev, skb, NULL); 307 txq = netdev_core_pick_tx(dev, skb, NULL);
251 308
252 HARD_TX_LOCK(dev, txq, smp_processor_id()); 309 HARD_TX_LOCK(dev, txq, smp_processor_id());
253 if (!netif_xmit_frozen_or_stopped(txq)) 310 if (!netif_xmit_frozen_or_stopped(txq))
diff --git a/net/xfrm/xfrm_inout.h b/net/xfrm/xfrm_inout.h
new file mode 100644
index 000000000000..c7b0318938e2
--- /dev/null
+++ b/net/xfrm/xfrm_inout.h
@@ -0,0 +1,38 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/ipv6.h>
3#include <net/dsfield.h>
4#include <net/xfrm.h>
5
6#ifndef XFRM_INOUT_H
7#define XFRM_INOUT_H 1
8
9static inline void xfrm6_beet_make_header(struct sk_buff *skb)
10{
11 struct ipv6hdr *iph = ipv6_hdr(skb);
12
13 iph->version = 6;
14
15 memcpy(iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
16 sizeof(iph->flow_lbl));
17 iph->nexthdr = XFRM_MODE_SKB_CB(skb)->protocol;
18
19 ipv6_change_dsfield(iph, 0, XFRM_MODE_SKB_CB(skb)->tos);
20 iph->hop_limit = XFRM_MODE_SKB_CB(skb)->ttl;
21}
22
23static inline void xfrm4_beet_make_header(struct sk_buff *skb)
24{
25 struct iphdr *iph = ip_hdr(skb);
26
27 iph->ihl = 5;
28 iph->version = 4;
29
30 iph->protocol = XFRM_MODE_SKB_CB(skb)->protocol;
31 iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
32
33 iph->id = XFRM_MODE_SKB_CB(skb)->id;
34 iph->frag_off = XFRM_MODE_SKB_CB(skb)->frag_off;
35 iph->ttl = XFRM_MODE_SKB_CB(skb)->ttl;
36}
37
38#endif
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index b3b613660d44..314973aaa414 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -21,6 +21,8 @@
21#include <net/ip_tunnels.h> 21#include <net/ip_tunnels.h>
22#include <net/ip6_tunnel.h> 22#include <net/ip6_tunnel.h>
23 23
24#include "xfrm_inout.h"
25
24struct xfrm_trans_tasklet { 26struct xfrm_trans_tasklet {
25 struct tasklet_struct tasklet; 27 struct tasklet_struct tasklet;
26 struct sk_buff_head queue; 28 struct sk_buff_head queue;
@@ -166,35 +168,299 @@ int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, __be32 *spi, __be32 *seq)
166} 168}
167EXPORT_SYMBOL(xfrm_parse_spi); 169EXPORT_SYMBOL(xfrm_parse_spi);
168 170
169int xfrm_prepare_input(struct xfrm_state *x, struct sk_buff *skb) 171static int xfrm4_remove_beet_encap(struct xfrm_state *x, struct sk_buff *skb)
172{
173 struct iphdr *iph;
174 int optlen = 0;
175 int err = -EINVAL;
176
177 if (unlikely(XFRM_MODE_SKB_CB(skb)->protocol == IPPROTO_BEETPH)) {
178 struct ip_beet_phdr *ph;
179 int phlen;
180
181 if (!pskb_may_pull(skb, sizeof(*ph)))
182 goto out;
183
184 ph = (struct ip_beet_phdr *)skb->data;
185
186 phlen = sizeof(*ph) + ph->padlen;
187 optlen = ph->hdrlen * 8 + (IPV4_BEET_PHMAXLEN - phlen);
188 if (optlen < 0 || optlen & 3 || optlen > 250)
189 goto out;
190
191 XFRM_MODE_SKB_CB(skb)->protocol = ph->nexthdr;
192
193 if (!pskb_may_pull(skb, phlen))
194 goto out;
195 __skb_pull(skb, phlen);
196 }
197
198 skb_push(skb, sizeof(*iph));
199 skb_reset_network_header(skb);
200 skb_mac_header_rebuild(skb);
201
202 xfrm4_beet_make_header(skb);
203
204 iph = ip_hdr(skb);
205
206 iph->ihl += optlen / 4;
207 iph->tot_len = htons(skb->len);
208 iph->daddr = x->sel.daddr.a4;
209 iph->saddr = x->sel.saddr.a4;
210 iph->check = 0;
211 iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
212 err = 0;
213out:
214 return err;
215}
216
217static void ipip_ecn_decapsulate(struct sk_buff *skb)
218{
219 struct iphdr *inner_iph = ipip_hdr(skb);
220
221 if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
222 IP_ECN_set_ce(inner_iph);
223}
224
225static int xfrm4_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
170{ 226{
171 struct xfrm_mode *inner_mode = x->inner_mode; 227 int err = -EINVAL;
228
229 if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPIP)
230 goto out;
231
232 if (!pskb_may_pull(skb, sizeof(struct iphdr)))
233 goto out;
234
235 err = skb_unclone(skb, GFP_ATOMIC);
236 if (err)
237 goto out;
238
239 if (x->props.flags & XFRM_STATE_DECAP_DSCP)
240 ipv4_copy_dscp(XFRM_MODE_SKB_CB(skb)->tos, ipip_hdr(skb));
241 if (!(x->props.flags & XFRM_STATE_NOECN))
242 ipip_ecn_decapsulate(skb);
243
244 skb_reset_network_header(skb);
245 skb_mac_header_rebuild(skb);
246 if (skb->mac_len)
247 eth_hdr(skb)->h_proto = skb->protocol;
248
249 err = 0;
250
251out:
252 return err;
253}
254
255static void ipip6_ecn_decapsulate(struct sk_buff *skb)
256{
257 struct ipv6hdr *inner_iph = ipipv6_hdr(skb);
258
259 if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
260 IP6_ECN_set_ce(skb, inner_iph);
261}
262
263static int xfrm6_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
264{
265 int err = -EINVAL;
266
267 if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPV6)
268 goto out;
269 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
270 goto out;
271
272 err = skb_unclone(skb, GFP_ATOMIC);
273 if (err)
274 goto out;
275
276 if (x->props.flags & XFRM_STATE_DECAP_DSCP)
277 ipv6_copy_dscp(ipv6_get_dsfield(ipv6_hdr(skb)),
278 ipipv6_hdr(skb));
279 if (!(x->props.flags & XFRM_STATE_NOECN))
280 ipip6_ecn_decapsulate(skb);
281
282 skb_reset_network_header(skb);
283 skb_mac_header_rebuild(skb);
284 if (skb->mac_len)
285 eth_hdr(skb)->h_proto = skb->protocol;
286
287 err = 0;
288
289out:
290 return err;
291}
292
293static int xfrm6_remove_beet_encap(struct xfrm_state *x, struct sk_buff *skb)
294{
295 struct ipv6hdr *ip6h;
296 int size = sizeof(struct ipv6hdr);
172 int err; 297 int err;
173 298
174 err = x->outer_mode->afinfo->extract_input(x, skb); 299 err = skb_cow_head(skb, size + skb->mac_len);
175 if (err) 300 if (err)
301 goto out;
302
303 __skb_push(skb, size);
304 skb_reset_network_header(skb);
305 skb_mac_header_rebuild(skb);
306
307 xfrm6_beet_make_header(skb);
308
309 ip6h = ipv6_hdr(skb);
310 ip6h->payload_len = htons(skb->len - size);
311 ip6h->daddr = x->sel.daddr.in6;
312 ip6h->saddr = x->sel.saddr.in6;
313 err = 0;
314out:
315 return err;
316}
317
318/* Remove encapsulation header.
319 *
320 * The IP header will be moved over the top of the encapsulation
321 * header.
322 *
323 * On entry, the transport header shall point to where the IP header
324 * should be and the network header shall be set to where the IP
325 * header currently is. skb->data shall point to the start of the
326 * payload.
327 */
328static int
329xfrm_inner_mode_encap_remove(struct xfrm_state *x,
330 const struct xfrm_mode *inner_mode,
331 struct sk_buff *skb)
332{
333 switch (inner_mode->encap) {
334 case XFRM_MODE_BEET:
335 if (inner_mode->family == AF_INET)
336 return xfrm4_remove_beet_encap(x, skb);
337 if (inner_mode->family == AF_INET6)
338 return xfrm6_remove_beet_encap(x, skb);
339 break;
340 case XFRM_MODE_TUNNEL:
341 if (inner_mode->family == AF_INET)
342 return xfrm4_remove_tunnel_encap(x, skb);
343 if (inner_mode->family == AF_INET6)
344 return xfrm6_remove_tunnel_encap(x, skb);
345 break;
346 }
347
348 WARN_ON_ONCE(1);
349 return -EOPNOTSUPP;
350}
351
352static int xfrm_prepare_input(struct xfrm_state *x, struct sk_buff *skb)
353{
354 const struct xfrm_mode *inner_mode = &x->inner_mode;
355 const struct xfrm_state_afinfo *afinfo;
356 int err = -EAFNOSUPPORT;
357
358 rcu_read_lock();
359 afinfo = xfrm_state_afinfo_get_rcu(x->outer_mode.family);
360 if (likely(afinfo))
361 err = afinfo->extract_input(x, skb);
362
363 if (err) {
364 rcu_read_unlock();
176 return err; 365 return err;
366 }
177 367
178 if (x->sel.family == AF_UNSPEC) { 368 if (x->sel.family == AF_UNSPEC) {
179 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol); 369 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
180 if (inner_mode == NULL) 370 if (!inner_mode) {
371 rcu_read_unlock();
181 return -EAFNOSUPPORT; 372 return -EAFNOSUPPORT;
373 }
182 } 374 }
183 375
184 skb->protocol = inner_mode->afinfo->eth_proto; 376 afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
185 return inner_mode->input2(x, skb); 377 if (unlikely(!afinfo)) {
378 rcu_read_unlock();
379 return -EAFNOSUPPORT;
380 }
381
382 skb->protocol = afinfo->eth_proto;
383 rcu_read_unlock();
384 return xfrm_inner_mode_encap_remove(x, inner_mode, skb);
385}
386
387/* Remove encapsulation header.
388 *
389 * The IP header will be moved over the top of the encapsulation header.
390 *
391 * On entry, skb_transport_header() shall point to where the IP header
392 * should be and skb_network_header() shall be set to where the IP header
393 * currently is. skb->data shall point to the start of the payload.
394 */
395static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
396{
397 int ihl = skb->data - skb_transport_header(skb);
398
399 if (skb->transport_header != skb->network_header) {
400 memmove(skb_transport_header(skb),
401 skb_network_header(skb), ihl);
402 skb->network_header = skb->transport_header;
403 }
404 ip_hdr(skb)->tot_len = htons(skb->len + ihl);
405 skb_reset_transport_header(skb);
406 return 0;
407}
408
409static int xfrm6_transport_input(struct xfrm_state *x, struct sk_buff *skb)
410{
411#if IS_ENABLED(CONFIG_IPV6)
412 int ihl = skb->data - skb_transport_header(skb);
413
414 if (skb->transport_header != skb->network_header) {
415 memmove(skb_transport_header(skb),
416 skb_network_header(skb), ihl);
417 skb->network_header = skb->transport_header;
418 }
419 ipv6_hdr(skb)->payload_len = htons(skb->len + ihl -
420 sizeof(struct ipv6hdr));
421 skb_reset_transport_header(skb);
422 return 0;
423#else
424 WARN_ON_ONCE(1);
425 return -EAFNOSUPPORT;
426#endif
427}
428
429static int xfrm_inner_mode_input(struct xfrm_state *x,
430 const struct xfrm_mode *inner_mode,
431 struct sk_buff *skb)
432{
433 switch (inner_mode->encap) {
434 case XFRM_MODE_BEET:
435 case XFRM_MODE_TUNNEL:
436 return xfrm_prepare_input(x, skb);
437 case XFRM_MODE_TRANSPORT:
438 if (inner_mode->family == AF_INET)
439 return xfrm4_transport_input(x, skb);
440 if (inner_mode->family == AF_INET6)
441 return xfrm6_transport_input(x, skb);
442 break;
443 case XFRM_MODE_ROUTEOPTIMIZATION:
444 WARN_ON_ONCE(1);
445 break;
446 default:
447 WARN_ON_ONCE(1);
448 break;
449 }
450
451 return -EOPNOTSUPP;
186} 452}
187EXPORT_SYMBOL(xfrm_prepare_input);
188 453
189int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) 454int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
190{ 455{
456 const struct xfrm_state_afinfo *afinfo;
191 struct net *net = dev_net(skb->dev); 457 struct net *net = dev_net(skb->dev);
458 const struct xfrm_mode *inner_mode;
192 int err; 459 int err;
193 __be32 seq; 460 __be32 seq;
194 __be32 seq_hi; 461 __be32 seq_hi;
195 struct xfrm_state *x = NULL; 462 struct xfrm_state *x = NULL;
196 xfrm_address_t *daddr; 463 xfrm_address_t *daddr;
197 struct xfrm_mode *inner_mode;
198 u32 mark = skb->mark; 464 u32 mark = skb->mark;
199 unsigned int family = AF_UNSPEC; 465 unsigned int family = AF_UNSPEC;
200 int decaps = 0; 466 int decaps = 0;
@@ -216,7 +482,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
216 goto drop; 482 goto drop;
217 } 483 }
218 484
219 family = x->outer_mode->afinfo->family; 485 family = x->outer_mode.family;
220 486
221 /* An encap_type of -1 indicates async resumption. */ 487 /* An encap_type of -1 indicates async resumption. */
222 if (encap_type == -1) { 488 if (encap_type == -1) {
@@ -400,7 +666,7 @@ resume:
400 666
401 XFRM_MODE_SKB_CB(skb)->protocol = nexthdr; 667 XFRM_MODE_SKB_CB(skb)->protocol = nexthdr;
402 668
403 inner_mode = x->inner_mode; 669 inner_mode = &x->inner_mode;
404 670
405 if (x->sel.family == AF_UNSPEC) { 671 if (x->sel.family == AF_UNSPEC) {
406 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol); 672 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
@@ -410,12 +676,12 @@ resume:
410 } 676 }
411 } 677 }
412 678
413 if (inner_mode->input(x, skb)) { 679 if (xfrm_inner_mode_input(x, inner_mode, skb)) {
414 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR); 680 XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
415 goto drop; 681 goto drop;
416 } 682 }
417 683
418 if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) { 684 if (x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL) {
419 decaps = 1; 685 decaps = 1;
420 break; 686 break;
421 } 687 }
@@ -425,7 +691,7 @@ resume:
425 * transport mode so the outer address is identical. 691 * transport mode so the outer address is identical.
426 */ 692 */
427 daddr = &x->id.daddr; 693 daddr = &x->id.daddr;
428 family = x->outer_mode->afinfo->family; 694 family = x->outer_mode.family;
429 695
430 err = xfrm_parse_spi(skb, nexthdr, &spi, &seq); 696 err = xfrm_parse_spi(skb, nexthdr, &spi, &seq);
431 if (err < 0) { 697 if (err < 0) {
@@ -453,7 +719,12 @@ resume:
453 if (xo) 719 if (xo)
454 xfrm_gro = xo->flags & XFRM_GRO; 720 xfrm_gro = xo->flags & XFRM_GRO;
455 721
456 err = x->inner_mode->afinfo->transport_finish(skb, xfrm_gro || async); 722 err = -EAFNOSUPPORT;
723 rcu_read_lock();
724 afinfo = xfrm_state_afinfo_get_rcu(x->inner_mode.family);
725 if (likely(afinfo))
726 err = afinfo->transport_finish(skb, xfrm_gro || async);
727 rcu_read_unlock();
457 if (xfrm_gro) { 728 if (xfrm_gro) {
458 sp = skb_sec_path(skb); 729 sp = skb_sec_path(skb);
459 if (sp) 730 if (sp)
diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c
index dbb3c1945b5c..ad3a2555c517 100644
--- a/net/xfrm/xfrm_interface.c
+++ b/net/xfrm/xfrm_interface.c
@@ -70,17 +70,28 @@ static struct xfrm_if *xfrmi_lookup(struct net *net, struct xfrm_state *x)
70 return NULL; 70 return NULL;
71} 71}
72 72
73static struct xfrm_if *xfrmi_decode_session(struct sk_buff *skb) 73static struct xfrm_if *xfrmi_decode_session(struct sk_buff *skb,
74 unsigned short family)
74{ 75{
75 struct xfrmi_net *xfrmn; 76 struct xfrmi_net *xfrmn;
76 int ifindex;
77 struct xfrm_if *xi; 77 struct xfrm_if *xi;
78 int ifindex = 0;
78 79
79 if (!secpath_exists(skb) || !skb->dev) 80 if (!secpath_exists(skb) || !skb->dev)
80 return NULL; 81 return NULL;
81 82
83 switch (family) {
84 case AF_INET6:
85 ifindex = inet6_sdif(skb);
86 break;
87 case AF_INET:
88 ifindex = inet_sdif(skb);
89 break;
90 }
91 if (!ifindex)
92 ifindex = skb->dev->ifindex;
93
82 xfrmn = net_generic(xs_net(xfrm_input_state(skb)), xfrmi_net_id); 94 xfrmn = net_generic(xs_net(xfrm_input_state(skb)), xfrmi_net_id);
83 ifindex = skb->dev->ifindex;
84 95
85 for_each_xfrmi_rcu(xfrmn->xfrmi[0], xi) { 96 for_each_xfrmi_rcu(xfrmn->xfrmi[0], xi) {
86 if (ifindex == xi->dev->ifindex && 97 if (ifindex == xi->dev->ifindex &&
@@ -244,8 +255,8 @@ static void xfrmi_scrub_packet(struct sk_buff *skb, bool xnet)
244 255
245static int xfrmi_rcv_cb(struct sk_buff *skb, int err) 256static int xfrmi_rcv_cb(struct sk_buff *skb, int err)
246{ 257{
258 const struct xfrm_mode *inner_mode;
247 struct pcpu_sw_netstats *tstats; 259 struct pcpu_sw_netstats *tstats;
248 struct xfrm_mode *inner_mode;
249 struct net_device *dev; 260 struct net_device *dev;
250 struct xfrm_state *x; 261 struct xfrm_state *x;
251 struct xfrm_if *xi; 262 struct xfrm_if *xi;
@@ -273,7 +284,7 @@ static int xfrmi_rcv_cb(struct sk_buff *skb, int err)
273 xnet = !net_eq(xi->net, dev_net(skb->dev)); 284 xnet = !net_eq(xi->net, dev_net(skb->dev));
274 285
275 if (xnet) { 286 if (xnet) {
276 inner_mode = x->inner_mode; 287 inner_mode = &x->inner_mode;
277 288
278 if (x->sel.family == AF_UNSPEC) { 289 if (x->sel.family == AF_UNSPEC) {
279 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol); 290 inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
@@ -285,7 +296,7 @@ static int xfrmi_rcv_cb(struct sk_buff *skb, int err)
285 } 296 }
286 297
287 if (!xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, 298 if (!xfrm_policy_check(NULL, XFRM_POLICY_IN, skb,
288 inner_mode->afinfo->family)) 299 inner_mode->family))
289 return -EPERM; 300 return -EPERM;
290 } 301 }
291 302
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index 9333153bafda..a55510f9ff35 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -17,9 +17,13 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19#include <net/dst.h> 19#include <net/dst.h>
20#include <net/inet_ecn.h>
20#include <net/xfrm.h> 21#include <net/xfrm.h>
21 22
23#include "xfrm_inout.h"
24
22static int xfrm_output2(struct net *net, struct sock *sk, struct sk_buff *skb); 25static int xfrm_output2(struct net *net, struct sock *sk, struct sk_buff *skb);
26static int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb);
23 27
24static int xfrm_skb_check_space(struct sk_buff *skb) 28static int xfrm_skb_check_space(struct sk_buff *skb)
25{ 29{
@@ -50,6 +54,360 @@ static struct dst_entry *skb_dst_pop(struct sk_buff *skb)
50 return child; 54 return child;
51} 55}
52 56
57/* Add encapsulation header.
58 *
59 * The IP header will be moved forward to make space for the encapsulation
60 * header.
61 */
62static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb)
63{
64 struct iphdr *iph = ip_hdr(skb);
65 int ihl = iph->ihl * 4;
66
67 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
68
69 skb_set_network_header(skb, -x->props.header_len);
70 skb->mac_header = skb->network_header +
71 offsetof(struct iphdr, protocol);
72 skb->transport_header = skb->network_header + ihl;
73 __skb_pull(skb, ihl);
74 memmove(skb_network_header(skb), iph, ihl);
75 return 0;
76}
77
78/* Add encapsulation header.
79 *
80 * The IP header and mutable extension headers will be moved forward to make
81 * space for the encapsulation header.
82 */
83static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
84{
85#if IS_ENABLED(CONFIG_IPV6)
86 struct ipv6hdr *iph;
87 u8 *prevhdr;
88 int hdr_len;
89
90 iph = ipv6_hdr(skb);
91 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
92
93 hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
94 if (hdr_len < 0)
95 return hdr_len;
96 skb_set_mac_header(skb,
97 (prevhdr - x->props.header_len) - skb->data);
98 skb_set_network_header(skb, -x->props.header_len);
99 skb->transport_header = skb->network_header + hdr_len;
100 __skb_pull(skb, hdr_len);
101 memmove(ipv6_hdr(skb), iph, hdr_len);
102 return 0;
103#else
104 WARN_ON_ONCE(1);
105 return -EAFNOSUPPORT;
106#endif
107}
108
109/* Add route optimization header space.
110 *
111 * The IP header and mutable extension headers will be moved forward to make
112 * space for the route optimization header.
113 */
114static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
115{
116#if IS_ENABLED(CONFIG_IPV6)
117 struct ipv6hdr *iph;
118 u8 *prevhdr;
119 int hdr_len;
120
121 iph = ipv6_hdr(skb);
122
123 hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
124 if (hdr_len < 0)
125 return hdr_len;
126 skb_set_mac_header(skb,
127 (prevhdr - x->props.header_len) - skb->data);
128 skb_set_network_header(skb, -x->props.header_len);
129 skb->transport_header = skb->network_header + hdr_len;
130 __skb_pull(skb, hdr_len);
131 memmove(ipv6_hdr(skb), iph, hdr_len);
132
133 x->lastused = ktime_get_real_seconds();
134
135 return 0;
136#else
137 WARN_ON_ONCE(1);
138 return -EAFNOSUPPORT;
139#endif
140}
141
142/* Add encapsulation header.
143 *
144 * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
145 */
146static int xfrm4_beet_encap_add(struct xfrm_state *x, struct sk_buff *skb)
147{
148 struct ip_beet_phdr *ph;
149 struct iphdr *top_iph;
150 int hdrlen, optlen;
151
152 hdrlen = 0;
153 optlen = XFRM_MODE_SKB_CB(skb)->optlen;
154 if (unlikely(optlen))
155 hdrlen += IPV4_BEET_PHMAXLEN - (optlen & 4);
156
157 skb_set_network_header(skb, -x->props.header_len - hdrlen +
158 (XFRM_MODE_SKB_CB(skb)->ihl - sizeof(*top_iph)));
159 if (x->sel.family != AF_INET6)
160 skb->network_header += IPV4_BEET_PHMAXLEN;
161 skb->mac_header = skb->network_header +
162 offsetof(struct iphdr, protocol);
163 skb->transport_header = skb->network_header + sizeof(*top_iph);
164
165 xfrm4_beet_make_header(skb);
166
167 ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdrlen);
168
169 top_iph = ip_hdr(skb);
170
171 if (unlikely(optlen)) {
172 if (WARN_ON(optlen < 0))
173 return -EINVAL;
174
175 ph->padlen = 4 - (optlen & 4);
176 ph->hdrlen = optlen / 8;
177 ph->nexthdr = top_iph->protocol;
178 if (ph->padlen)
179 memset(ph + 1, IPOPT_NOP, ph->padlen);
180
181 top_iph->protocol = IPPROTO_BEETPH;
182 top_iph->ihl = sizeof(struct iphdr) / 4;
183 }
184
185 top_iph->saddr = x->props.saddr.a4;
186 top_iph->daddr = x->id.daddr.a4;
187
188 return 0;
189}
190
191/* Add encapsulation header.
192 *
193 * The top IP header will be constructed per RFC 2401.
194 */
195static int xfrm4_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
196{
197 struct dst_entry *dst = skb_dst(skb);
198 struct iphdr *top_iph;
199 int flags;
200
201 skb_set_inner_network_header(skb, skb_network_offset(skb));
202 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
203
204 skb_set_network_header(skb, -x->props.header_len);
205 skb->mac_header = skb->network_header +
206 offsetof(struct iphdr, protocol);
207 skb->transport_header = skb->network_header + sizeof(*top_iph);
208 top_iph = ip_hdr(skb);
209
210 top_iph->ihl = 5;
211 top_iph->version = 4;
212
213 top_iph->protocol = xfrm_af2proto(skb_dst(skb)->ops->family);
214
215 /* DS disclosing depends on XFRM_SA_XFLAG_DONT_ENCAP_DSCP */
216 if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
217 top_iph->tos = 0;
218 else
219 top_iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
220 top_iph->tos = INET_ECN_encapsulate(top_iph->tos,
221 XFRM_MODE_SKB_CB(skb)->tos);
222
223 flags = x->props.flags;
224 if (flags & XFRM_STATE_NOECN)
225 IP_ECN_clear(top_iph);
226
227 top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
228 0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));
229
230 top_iph->ttl = ip4_dst_hoplimit(xfrm_dst_child(dst));
231
232 top_iph->saddr = x->props.saddr.a4;
233 top_iph->daddr = x->id.daddr.a4;
234 ip_select_ident(dev_net(dst->dev), skb, NULL);
235
236 return 0;
237}
238
239#if IS_ENABLED(CONFIG_IPV6)
240static int xfrm6_tunnel_encap_add(struct xfrm_state *x, struct sk_buff *skb)
241{
242 struct dst_entry *dst = skb_dst(skb);
243 struct ipv6hdr *top_iph;
244 int dsfield;
245
246 skb_set_inner_network_header(skb, skb_network_offset(skb));
247 skb_set_inner_transport_header(skb, skb_transport_offset(skb));
248
249 skb_set_network_header(skb, -x->props.header_len);
250 skb->mac_header = skb->network_header +
251 offsetof(struct ipv6hdr, nexthdr);
252 skb->transport_header = skb->network_header + sizeof(*top_iph);
253 top_iph = ipv6_hdr(skb);
254
255 top_iph->version = 6;
256
257 memcpy(top_iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
258 sizeof(top_iph->flow_lbl));
259 top_iph->nexthdr = xfrm_af2proto(skb_dst(skb)->ops->family);
260
261 if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
262 dsfield = 0;
263 else
264 dsfield = XFRM_MODE_SKB_CB(skb)->tos;
265 dsfield = INET_ECN_encapsulate(dsfield, XFRM_MODE_SKB_CB(skb)->tos);
266 if (x->props.flags & XFRM_STATE_NOECN)
267 dsfield &= ~INET_ECN_MASK;
268 ipv6_change_dsfield(top_iph, 0, dsfield);
269 top_iph->hop_limit = ip6_dst_hoplimit(xfrm_dst_child(dst));
270 top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
271 top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
272 return 0;
273}
274
275static int xfrm6_beet_encap_add(struct xfrm_state *x, struct sk_buff *skb)
276{
277 struct ipv6hdr *top_iph;
278 struct ip_beet_phdr *ph;
279 int optlen, hdr_len;
280
281 hdr_len = 0;
282 optlen = XFRM_MODE_SKB_CB(skb)->optlen;
283 if (unlikely(optlen))
284 hdr_len += IPV4_BEET_PHMAXLEN - (optlen & 4);
285
286 skb_set_network_header(skb, -x->props.header_len - hdr_len);
287 if (x->sel.family != AF_INET6)
288 skb->network_header += IPV4_BEET_PHMAXLEN;
289 skb->mac_header = skb->network_header +
290 offsetof(struct ipv6hdr, nexthdr);
291 skb->transport_header = skb->network_header + sizeof(*top_iph);
292 ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdr_len);
293
294 xfrm6_beet_make_header(skb);
295
296 top_iph = ipv6_hdr(skb);
297 if (unlikely(optlen)) {
298 if (WARN_ON(optlen < 0))
299 return -EINVAL;
300
301 ph->padlen = 4 - (optlen & 4);
302 ph->hdrlen = optlen / 8;
303 ph->nexthdr = top_iph->nexthdr;
304 if (ph->padlen)
305 memset(ph + 1, IPOPT_NOP, ph->padlen);
306
307 top_iph->nexthdr = IPPROTO_BEETPH;
308 }
309
310 top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
311 top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
312 return 0;
313}
314#endif
315
316/* Add encapsulation header.
317 *
318 * On exit, the transport header will be set to the start of the
319 * encapsulation header to be filled in by x->type->output and the mac
320 * header will be set to the nextheader (protocol for IPv4) field of the
321 * extension header directly preceding the encapsulation header, or in
322 * its absence, that of the top IP header.
323 * The value of the network header will always point to the top IP header
324 * while skb->data will point to the payload.
325 */
326static int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
327{
328 int err;
329
330 err = xfrm_inner_extract_output(x, skb);
331 if (err)
332 return err;
333
334 IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
335 skb->protocol = htons(ETH_P_IP);
336
337 switch (x->outer_mode.encap) {
338 case XFRM_MODE_BEET:
339 return xfrm4_beet_encap_add(x, skb);
340 case XFRM_MODE_TUNNEL:
341 return xfrm4_tunnel_encap_add(x, skb);
342 }
343
344 WARN_ON_ONCE(1);
345 return -EOPNOTSUPP;
346}
347
348static int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
349{
350#if IS_ENABLED(CONFIG_IPV6)
351 int err;
352
353 err = xfrm_inner_extract_output(x, skb);
354 if (err)
355 return err;
356
357 skb->ignore_df = 1;
358 skb->protocol = htons(ETH_P_IPV6);
359
360 switch (x->outer_mode.encap) {
361 case XFRM_MODE_BEET:
362 return xfrm6_beet_encap_add(x, skb);
363 case XFRM_MODE_TUNNEL:
364 return xfrm6_tunnel_encap_add(x, skb);
365 default:
366 WARN_ON_ONCE(1);
367 return -EOPNOTSUPP;
368 }
369#endif
370 WARN_ON_ONCE(1);
371 return -EAFNOSUPPORT;
372}
373
374static int xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
375{
376 switch (x->outer_mode.encap) {
377 case XFRM_MODE_BEET:
378 case XFRM_MODE_TUNNEL:
379 if (x->outer_mode.family == AF_INET)
380 return xfrm4_prepare_output(x, skb);
381 if (x->outer_mode.family == AF_INET6)
382 return xfrm6_prepare_output(x, skb);
383 break;
384 case XFRM_MODE_TRANSPORT:
385 if (x->outer_mode.family == AF_INET)
386 return xfrm4_transport_output(x, skb);
387 if (x->outer_mode.family == AF_INET6)
388 return xfrm6_transport_output(x, skb);
389 break;
390 case XFRM_MODE_ROUTEOPTIMIZATION:
391 if (x->outer_mode.family == AF_INET6)
392 return xfrm6_ro_output(x, skb);
393 WARN_ON_ONCE(1);
394 break;
395 default:
396 WARN_ON_ONCE(1);
397 break;
398 }
399
400 return -EOPNOTSUPP;
401}
402
403#if IS_ENABLED(CONFIG_NET_PKTGEN)
404int pktgen_xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb)
405{
406 return xfrm_outer_mode_output(x, skb);
407}
408EXPORT_SYMBOL_GPL(pktgen_xfrm_outer_mode_output);
409#endif
410
53static int xfrm_output_one(struct sk_buff *skb, int err) 411static int xfrm_output_one(struct sk_buff *skb, int err)
54{ 412{
55 struct dst_entry *dst = skb_dst(skb); 413 struct dst_entry *dst = skb_dst(skb);
@@ -68,7 +426,7 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
68 426
69 skb->mark = xfrm_smark_get(skb->mark, x); 427 skb->mark = xfrm_smark_get(skb->mark, x);
70 428
71 err = x->outer_mode->output(x, skb); 429 err = xfrm_outer_mode_output(x, skb);
72 if (err) { 430 if (err) {
73 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR); 431 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR);
74 goto error_nolock; 432 goto error_nolock;
@@ -131,7 +489,7 @@ resume:
131 } 489 }
132 skb_dst_set(skb, dst); 490 skb_dst_set(skb, dst);
133 x = dst->xfrm; 491 x = dst->xfrm;
134 } while (x && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL)); 492 } while (x && !(x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL));
135 493
136 return 0; 494 return 0;
137 495
@@ -258,20 +616,29 @@ out:
258} 616}
259EXPORT_SYMBOL_GPL(xfrm_output); 617EXPORT_SYMBOL_GPL(xfrm_output);
260 618
261int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb) 619static int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb)
262{ 620{
263 struct xfrm_mode *inner_mode; 621 const struct xfrm_state_afinfo *afinfo;
622 const struct xfrm_mode *inner_mode;
623 int err = -EAFNOSUPPORT;
624
264 if (x->sel.family == AF_UNSPEC) 625 if (x->sel.family == AF_UNSPEC)
265 inner_mode = xfrm_ip2inner_mode(x, 626 inner_mode = xfrm_ip2inner_mode(x,
266 xfrm_af2proto(skb_dst(skb)->ops->family)); 627 xfrm_af2proto(skb_dst(skb)->ops->family));
267 else 628 else
268 inner_mode = x->inner_mode; 629 inner_mode = &x->inner_mode;
269 630
270 if (inner_mode == NULL) 631 if (inner_mode == NULL)
271 return -EAFNOSUPPORT; 632 return -EAFNOSUPPORT;
272 return inner_mode->afinfo->extract_output(x, skb); 633
634 rcu_read_lock();
635 afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
636 if (likely(afinfo))
637 err = afinfo->extract_output(x, skb);
638 rcu_read_unlock();
639
640 return err;
273} 641}
274EXPORT_SYMBOL_GPL(xfrm_inner_extract_output);
275 642
276void xfrm_local_error(struct sk_buff *skb, int mtu) 643void xfrm_local_error(struct sk_buff *skb, int mtu)
277{ 644{
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 8d1a898d0ba5..410233c5681e 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -27,10 +27,14 @@
27#include <linux/cpu.h> 27#include <linux/cpu.h>
28#include <linux/audit.h> 28#include <linux/audit.h>
29#include <linux/rhashtable.h> 29#include <linux/rhashtable.h>
30#include <linux/if_tunnel.h>
30#include <net/dst.h> 31#include <net/dst.h>
31#include <net/flow.h> 32#include <net/flow.h>
32#include <net/xfrm.h> 33#include <net/xfrm.h>
33#include <net/ip.h> 34#include <net/ip.h>
35#if IS_ENABLED(CONFIG_IPV6_MIP6)
36#include <net/mip6.h>
37#endif
34#ifdef CONFIG_XFRM_STATISTICS 38#ifdef CONFIG_XFRM_STATISTICS
35#include <net/snmp.h> 39#include <net/snmp.h>
36#endif 40#endif
@@ -2450,18 +2454,10 @@ xfrm_tmpl_resolve(struct xfrm_policy **pols, int npols, const struct flowi *fl,
2450 2454
2451static int xfrm_get_tos(const struct flowi *fl, int family) 2455static int xfrm_get_tos(const struct flowi *fl, int family)
2452{ 2456{
2453 const struct xfrm_policy_afinfo *afinfo; 2457 if (family == AF_INET)
2454 int tos; 2458 return IPTOS_RT_MASK & fl->u.ip4.flowi4_tos;
2455 2459
2456 afinfo = xfrm_policy_get_afinfo(family); 2460 return 0;
2457 if (!afinfo)
2458 return 0;
2459
2460 tos = afinfo->get_tos(fl);
2461
2462 rcu_read_unlock();
2463
2464 return tos;
2465} 2461}
2466 2462
2467static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family) 2463static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
@@ -2499,21 +2495,14 @@ static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)
2499 return xdst; 2495 return xdst;
2500} 2496}
2501 2497
2502static inline int xfrm_init_path(struct xfrm_dst *path, struct dst_entry *dst, 2498static void xfrm_init_path(struct xfrm_dst *path, struct dst_entry *dst,
2503 int nfheader_len) 2499 int nfheader_len)
2504{ 2500{
2505 const struct xfrm_policy_afinfo *afinfo = 2501 if (dst->ops->family == AF_INET6) {
2506 xfrm_policy_get_afinfo(dst->ops->family); 2502 struct rt6_info *rt = (struct rt6_info *)dst;
2507 int err; 2503 path->path_cookie = rt6_get_cookie(rt);
2508 2504 path->u.rt6.rt6i_nfheader_len = nfheader_len;
2509 if (!afinfo) 2505 }
2510 return -EINVAL;
2511
2512 err = afinfo->init_path(path, dst, nfheader_len);
2513
2514 rcu_read_unlock();
2515
2516 return err;
2517} 2506}
2518 2507
2519static inline int xfrm_fill_dst(struct xfrm_dst *xdst, struct net_device *dev, 2508static inline int xfrm_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
@@ -2545,10 +2534,11 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
2545 const struct flowi *fl, 2534 const struct flowi *fl,
2546 struct dst_entry *dst) 2535 struct dst_entry *dst)
2547{ 2536{
2537 const struct xfrm_state_afinfo *afinfo;
2538 const struct xfrm_mode *inner_mode;
2548 struct net *net = xp_net(policy); 2539 struct net *net = xp_net(policy);
2549 unsigned long now = jiffies; 2540 unsigned long now = jiffies;
2550 struct net_device *dev; 2541 struct net_device *dev;
2551 struct xfrm_mode *inner_mode;
2552 struct xfrm_dst *xdst_prev = NULL; 2542 struct xfrm_dst *xdst_prev = NULL;
2553 struct xfrm_dst *xdst0 = NULL; 2543 struct xfrm_dst *xdst0 = NULL;
2554 int i = 0; 2544 int i = 0;
@@ -2594,7 +2584,7 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
2594 goto put_states; 2584 goto put_states;
2595 } 2585 }
2596 } else 2586 } else
2597 inner_mode = xfrm[i]->inner_mode; 2587 inner_mode = &xfrm[i]->inner_mode;
2598 2588
2599 xdst->route = dst; 2589 xdst->route = dst;
2600 dst_copy_metrics(dst1, dst); 2590 dst_copy_metrics(dst1, dst);
@@ -2622,7 +2612,14 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
2622 dst1->lastuse = now; 2612 dst1->lastuse = now;
2623 2613
2624 dst1->input = dst_discard; 2614 dst1->input = dst_discard;
2625 dst1->output = inner_mode->afinfo->output; 2615
2616 rcu_read_lock();
2617 afinfo = xfrm_state_afinfo_get_rcu(inner_mode->family);
2618 if (likely(afinfo))
2619 dst1->output = afinfo->output;
2620 else
2621 dst1->output = dst_discard_out;
2622 rcu_read_unlock();
2626 2623
2627 xdst_prev = xdst; 2624 xdst_prev = xdst;
2628 2625
@@ -3263,20 +3260,229 @@ xfrm_policy_ok(const struct xfrm_tmpl *tmpl, const struct sec_path *sp, int star
3263 return start; 3260 return start;
3264} 3261}
3265 3262
3263static void
3264decode_session4(struct sk_buff *skb, struct flowi *fl, bool reverse)
3265{
3266 const struct iphdr *iph = ip_hdr(skb);
3267 u8 *xprth = skb_network_header(skb) + iph->ihl * 4;
3268 struct flowi4 *fl4 = &fl->u.ip4;
3269 int oif = 0;
3270
3271 if (skb_dst(skb))
3272 oif = skb_dst(skb)->dev->ifindex;
3273
3274 memset(fl4, 0, sizeof(struct flowi4));
3275 fl4->flowi4_mark = skb->mark;
3276 fl4->flowi4_oif = reverse ? skb->skb_iif : oif;
3277
3278 if (!ip_is_fragment(iph)) {
3279 switch (iph->protocol) {
3280 case IPPROTO_UDP:
3281 case IPPROTO_UDPLITE:
3282 case IPPROTO_TCP:
3283 case IPPROTO_SCTP:
3284 case IPPROTO_DCCP:
3285 if (xprth + 4 < skb->data ||
3286 pskb_may_pull(skb, xprth + 4 - skb->data)) {
3287 __be16 *ports;
3288
3289 xprth = skb_network_header(skb) + iph->ihl * 4;
3290 ports = (__be16 *)xprth;
3291
3292 fl4->fl4_sport = ports[!!reverse];
3293 fl4->fl4_dport = ports[!reverse];
3294 }
3295 break;
3296 case IPPROTO_ICMP:
3297 if (xprth + 2 < skb->data ||
3298 pskb_may_pull(skb, xprth + 2 - skb->data)) {
3299 u8 *icmp;
3300
3301 xprth = skb_network_header(skb) + iph->ihl * 4;
3302 icmp = xprth;
3303
3304 fl4->fl4_icmp_type = icmp[0];
3305 fl4->fl4_icmp_code = icmp[1];
3306 }
3307 break;
3308 case IPPROTO_ESP:
3309 if (xprth + 4 < skb->data ||
3310 pskb_may_pull(skb, xprth + 4 - skb->data)) {
3311 __be32 *ehdr;
3312
3313 xprth = skb_network_header(skb) + iph->ihl * 4;
3314 ehdr = (__be32 *)xprth;
3315
3316 fl4->fl4_ipsec_spi = ehdr[0];
3317 }
3318 break;
3319 case IPPROTO_AH:
3320 if (xprth + 8 < skb->data ||
3321 pskb_may_pull(skb, xprth + 8 - skb->data)) {
3322 __be32 *ah_hdr;
3323
3324 xprth = skb_network_header(skb) + iph->ihl * 4;
3325 ah_hdr = (__be32 *)xprth;
3326
3327 fl4->fl4_ipsec_spi = ah_hdr[1];
3328 }
3329 break;
3330 case IPPROTO_COMP:
3331 if (xprth + 4 < skb->data ||
3332 pskb_may_pull(skb, xprth + 4 - skb->data)) {
3333 __be16 *ipcomp_hdr;
3334
3335 xprth = skb_network_header(skb) + iph->ihl * 4;
3336 ipcomp_hdr = (__be16 *)xprth;
3337
3338 fl4->fl4_ipsec_spi = htonl(ntohs(ipcomp_hdr[1]));
3339 }
3340 break;
3341 case IPPROTO_GRE:
3342 if (xprth + 12 < skb->data ||
3343 pskb_may_pull(skb, xprth + 12 - skb->data)) {
3344 __be16 *greflags;
3345 __be32 *gre_hdr;
3346
3347 xprth = skb_network_header(skb) + iph->ihl * 4;
3348 greflags = (__be16 *)xprth;
3349 gre_hdr = (__be32 *)xprth;
3350
3351 if (greflags[0] & GRE_KEY) {
3352 if (greflags[0] & GRE_CSUM)
3353 gre_hdr++;
3354 fl4->fl4_gre_key = gre_hdr[1];
3355 }
3356 }
3357 break;
3358 default:
3359 fl4->fl4_ipsec_spi = 0;
3360 break;
3361 }
3362 }
3363 fl4->flowi4_proto = iph->protocol;
3364 fl4->daddr = reverse ? iph->saddr : iph->daddr;
3365 fl4->saddr = reverse ? iph->daddr : iph->saddr;
3366 fl4->flowi4_tos = iph->tos;
3367}
3368
3369#if IS_ENABLED(CONFIG_IPV6)
3370static void
3371decode_session6(struct sk_buff *skb, struct flowi *fl, bool reverse)
3372{
3373 struct flowi6 *fl6 = &fl->u.ip6;
3374 int onlyproto = 0;
3375 const struct ipv6hdr *hdr = ipv6_hdr(skb);
3376 u32 offset = sizeof(*hdr);
3377 struct ipv6_opt_hdr *exthdr;
3378 const unsigned char *nh = skb_network_header(skb);
3379 u16 nhoff = IP6CB(skb)->nhoff;
3380 int oif = 0;
3381 u8 nexthdr;
3382
3383 if (!nhoff)
3384 nhoff = offsetof(struct ipv6hdr, nexthdr);
3385
3386 nexthdr = nh[nhoff];
3387
3388 if (skb_dst(skb))
3389 oif = skb_dst(skb)->dev->ifindex;
3390
3391 memset(fl6, 0, sizeof(struct flowi6));
3392 fl6->flowi6_mark = skb->mark;
3393 fl6->flowi6_oif = reverse ? skb->skb_iif : oif;
3394
3395 fl6->daddr = reverse ? hdr->saddr : hdr->daddr;
3396 fl6->saddr = reverse ? hdr->daddr : hdr->saddr;
3397
3398 while (nh + offset + sizeof(*exthdr) < skb->data ||
3399 pskb_may_pull(skb, nh + offset + sizeof(*exthdr) - skb->data)) {
3400 nh = skb_network_header(skb);
3401 exthdr = (struct ipv6_opt_hdr *)(nh + offset);
3402
3403 switch (nexthdr) {
3404 case NEXTHDR_FRAGMENT:
3405 onlyproto = 1;
3406 /* fall through */
3407 case NEXTHDR_ROUTING:
3408 case NEXTHDR_HOP:
3409 case NEXTHDR_DEST:
3410 offset += ipv6_optlen(exthdr);
3411 nexthdr = exthdr->nexthdr;
3412 exthdr = (struct ipv6_opt_hdr *)(nh + offset);
3413 break;
3414 case IPPROTO_UDP:
3415 case IPPROTO_UDPLITE:
3416 case IPPROTO_TCP:
3417 case IPPROTO_SCTP:
3418 case IPPROTO_DCCP:
3419 if (!onlyproto && (nh + offset + 4 < skb->data ||
3420 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
3421 __be16 *ports;
3422
3423 nh = skb_network_header(skb);
3424 ports = (__be16 *)(nh + offset);
3425 fl6->fl6_sport = ports[!!reverse];
3426 fl6->fl6_dport = ports[!reverse];
3427 }
3428 fl6->flowi6_proto = nexthdr;
3429 return;
3430 case IPPROTO_ICMPV6:
3431 if (!onlyproto && (nh + offset + 2 < skb->data ||
3432 pskb_may_pull(skb, nh + offset + 2 - skb->data))) {
3433 u8 *icmp;
3434
3435 nh = skb_network_header(skb);
3436 icmp = (u8 *)(nh + offset);
3437 fl6->fl6_icmp_type = icmp[0];
3438 fl6->fl6_icmp_code = icmp[1];
3439 }
3440 fl6->flowi6_proto = nexthdr;
3441 return;
3442#if IS_ENABLED(CONFIG_IPV6_MIP6)
3443 case IPPROTO_MH:
3444 offset += ipv6_optlen(exthdr);
3445 if (!onlyproto && (nh + offset + 3 < skb->data ||
3446 pskb_may_pull(skb, nh + offset + 3 - skb->data))) {
3447 struct ip6_mh *mh;
3448
3449 nh = skb_network_header(skb);
3450 mh = (struct ip6_mh *)(nh + offset);
3451 fl6->fl6_mh_type = mh->ip6mh_type;
3452 }
3453 fl6->flowi6_proto = nexthdr;
3454 return;
3455#endif
3456 /* XXX Why are there these headers? */
3457 case IPPROTO_AH:
3458 case IPPROTO_ESP:
3459 case IPPROTO_COMP:
3460 default:
3461 fl6->fl6_ipsec_spi = 0;
3462 fl6->flowi6_proto = nexthdr;
3463 return;
3464 }
3465 }
3466}
3467#endif
3468
3266int __xfrm_decode_session(struct sk_buff *skb, struct flowi *fl, 3469int __xfrm_decode_session(struct sk_buff *skb, struct flowi *fl,
3267 unsigned int family, int reverse) 3470 unsigned int family, int reverse)
3268{ 3471{
3269 const struct xfrm_policy_afinfo *afinfo = xfrm_policy_get_afinfo(family); 3472 switch (family) {
3270 int err; 3473 case AF_INET:
3271 3474 decode_session4(skb, fl, reverse);
3272 if (unlikely(afinfo == NULL)) 3475 break;
3476#if IS_ENABLED(CONFIG_IPV6)
3477 case AF_INET6:
3478 decode_session6(skb, fl, reverse);
3479 break;
3480#endif
3481 default:
3273 return -EAFNOSUPPORT; 3482 return -EAFNOSUPPORT;
3483 }
3274 3484
3275 afinfo->decode_session(skb, fl, reverse); 3485 return security_xfrm_decode_session(skb, &fl->flowi_secid);
3276
3277 err = security_xfrm_decode_session(skb, &fl->flowi_secid);
3278 rcu_read_unlock();
3279 return err;
3280} 3486}
3281EXPORT_SYMBOL(__xfrm_decode_session); 3487EXPORT_SYMBOL(__xfrm_decode_session);
3282 3488
@@ -3313,7 +3519,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
3313 ifcb = xfrm_if_get_cb(); 3519 ifcb = xfrm_if_get_cb();
3314 3520
3315 if (ifcb) { 3521 if (ifcb) {
3316 xi = ifcb->decode_session(skb); 3522 xi = ifcb->decode_session(skb, family);
3317 if (xi) { 3523 if (xi) {
3318 if_id = xi->p.if_id; 3524 if_id = xi->p.if_id;
3319 net = xi->net; 3525 net = xi->net;
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 1bb971f46fc6..c5d81316330b 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -173,7 +173,7 @@ static DEFINE_SPINLOCK(xfrm_state_gc_lock);
173int __xfrm_state_delete(struct xfrm_state *x); 173int __xfrm_state_delete(struct xfrm_state *x);
174 174
175int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol); 175int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
176bool km_is_alive(const struct km_event *c); 176static bool km_is_alive(const struct km_event *c);
177void km_state_expired(struct xfrm_state *x, int hard, u32 portid); 177void km_state_expired(struct xfrm_state *x, int hard, u32 portid);
178 178
179static DEFINE_SPINLOCK(xfrm_type_lock); 179static DEFINE_SPINLOCK(xfrm_type_lock);
@@ -330,100 +330,67 @@ static void xfrm_put_type_offload(const struct xfrm_type_offload *type)
330 module_put(type->owner); 330 module_put(type->owner);
331} 331}
332 332
333static DEFINE_SPINLOCK(xfrm_mode_lock); 333static const struct xfrm_mode xfrm4_mode_map[XFRM_MODE_MAX] = {
334int xfrm_register_mode(struct xfrm_mode *mode, int family) 334 [XFRM_MODE_BEET] = {
335{ 335 .encap = XFRM_MODE_BEET,
336 struct xfrm_state_afinfo *afinfo; 336 .flags = XFRM_MODE_FLAG_TUNNEL,
337 struct xfrm_mode **modemap; 337 .family = AF_INET,
338 int err; 338 },
339 339 [XFRM_MODE_TRANSPORT] = {
340 if (unlikely(mode->encap >= XFRM_MODE_MAX)) 340 .encap = XFRM_MODE_TRANSPORT,
341 return -EINVAL; 341 .family = AF_INET,
342 342 },
343 afinfo = xfrm_state_get_afinfo(family); 343 [XFRM_MODE_TUNNEL] = {
344 if (unlikely(afinfo == NULL)) 344 .encap = XFRM_MODE_TUNNEL,
345 return -EAFNOSUPPORT; 345 .flags = XFRM_MODE_FLAG_TUNNEL,
346 346 .family = AF_INET,
347 err = -EEXIST; 347 },
348 modemap = afinfo->mode_map; 348};
349 spin_lock_bh(&xfrm_mode_lock); 349
350 if (modemap[mode->encap]) 350static const struct xfrm_mode xfrm6_mode_map[XFRM_MODE_MAX] = {
351 goto out; 351 [XFRM_MODE_BEET] = {
352 352 .encap = XFRM_MODE_BEET,
353 err = -ENOENT; 353 .flags = XFRM_MODE_FLAG_TUNNEL,
354 if (!try_module_get(afinfo->owner)) 354 .family = AF_INET6,
355 goto out; 355 },
356 356 [XFRM_MODE_ROUTEOPTIMIZATION] = {
357 mode->afinfo = afinfo; 357 .encap = XFRM_MODE_ROUTEOPTIMIZATION,
358 modemap[mode->encap] = mode; 358 .family = AF_INET6,
359 err = 0; 359 },
360 360 [XFRM_MODE_TRANSPORT] = {
361out: 361 .encap = XFRM_MODE_TRANSPORT,
362 spin_unlock_bh(&xfrm_mode_lock); 362 .family = AF_INET6,
363 rcu_read_unlock(); 363 },
364 return err; 364 [XFRM_MODE_TUNNEL] = {
365} 365 .encap = XFRM_MODE_TUNNEL,
366EXPORT_SYMBOL(xfrm_register_mode); 366 .flags = XFRM_MODE_FLAG_TUNNEL,
367 367 .family = AF_INET6,
368int xfrm_unregister_mode(struct xfrm_mode *mode, int family) 368 },
369{ 369};
370 struct xfrm_state_afinfo *afinfo; 370
371 struct xfrm_mode **modemap; 371static const struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family)
372 int err; 372{
373 373 const struct xfrm_mode *mode;
374 if (unlikely(mode->encap >= XFRM_MODE_MAX))
375 return -EINVAL;
376
377 afinfo = xfrm_state_get_afinfo(family);
378 if (unlikely(afinfo == NULL))
379 return -EAFNOSUPPORT;
380
381 err = -ENOENT;
382 modemap = afinfo->mode_map;
383 spin_lock_bh(&xfrm_mode_lock);
384 if (likely(modemap[mode->encap] == mode)) {
385 modemap[mode->encap] = NULL;
386 module_put(mode->afinfo->owner);
387 err = 0;
388 }
389
390 spin_unlock_bh(&xfrm_mode_lock);
391 rcu_read_unlock();
392 return err;
393}
394EXPORT_SYMBOL(xfrm_unregister_mode);
395
396static struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family)
397{
398 struct xfrm_state_afinfo *afinfo;
399 struct xfrm_mode *mode;
400 int modload_attempted = 0;
401 374
402 if (unlikely(encap >= XFRM_MODE_MAX)) 375 if (unlikely(encap >= XFRM_MODE_MAX))
403 return NULL; 376 return NULL;
404 377
405retry: 378 switch (family) {
406 afinfo = xfrm_state_get_afinfo(family); 379 case AF_INET:
407 if (unlikely(afinfo == NULL)) 380 mode = &xfrm4_mode_map[encap];
408 return NULL; 381 if (mode->family == family)
409 382 return mode;
410 mode = READ_ONCE(afinfo->mode_map[encap]); 383 break;
411 if (unlikely(mode && !try_module_get(mode->owner))) 384 case AF_INET6:
412 mode = NULL; 385 mode = &xfrm6_mode_map[encap];
413 386 if (mode->family == family)
414 rcu_read_unlock(); 387 return mode;
415 if (!mode && !modload_attempted) { 388 break;
416 request_module("xfrm-mode-%d-%d", family, encap); 389 default:
417 modload_attempted = 1; 390 break;
418 goto retry;
419 } 391 }
420 392
421 return mode; 393 return NULL;
422}
423
424static void xfrm_put_mode(struct xfrm_mode *mode)
425{
426 module_put(mode->owner);
427} 394}
428 395
429void xfrm_state_free(struct xfrm_state *x) 396void xfrm_state_free(struct xfrm_state *x)
@@ -434,7 +401,7 @@ EXPORT_SYMBOL(xfrm_state_free);
434 401
435static void ___xfrm_state_destroy(struct xfrm_state *x) 402static void ___xfrm_state_destroy(struct xfrm_state *x)
436{ 403{
437 tasklet_hrtimer_cancel(&x->mtimer); 404 hrtimer_cancel(&x->mtimer);
438 del_timer_sync(&x->rtimer); 405 del_timer_sync(&x->rtimer);
439 kfree(x->aead); 406 kfree(x->aead);
440 kfree(x->aalg); 407 kfree(x->aalg);
@@ -444,12 +411,6 @@ static void ___xfrm_state_destroy(struct xfrm_state *x)
444 kfree(x->coaddr); 411 kfree(x->coaddr);
445 kfree(x->replay_esn); 412 kfree(x->replay_esn);
446 kfree(x->preplay_esn); 413 kfree(x->preplay_esn);
447 if (x->inner_mode)
448 xfrm_put_mode(x->inner_mode);
449 if (x->inner_mode_iaf)
450 xfrm_put_mode(x->inner_mode_iaf);
451 if (x->outer_mode)
452 xfrm_put_mode(x->outer_mode);
453 if (x->type_offload) 414 if (x->type_offload)
454 xfrm_put_type_offload(x->type_offload); 415 xfrm_put_type_offload(x->type_offload);
455 if (x->type) { 416 if (x->type) {
@@ -479,8 +440,8 @@ static void xfrm_state_gc_task(struct work_struct *work)
479 440
480static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me) 441static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me)
481{ 442{
482 struct tasklet_hrtimer *thr = container_of(me, struct tasklet_hrtimer, timer); 443 struct xfrm_state *x = container_of(me, struct xfrm_state, mtimer);
483 struct xfrm_state *x = container_of(thr, struct xfrm_state, mtimer); 444 enum hrtimer_restart ret = HRTIMER_NORESTART;
484 time64_t now = ktime_get_real_seconds(); 445 time64_t now = ktime_get_real_seconds();
485 time64_t next = TIME64_MAX; 446 time64_t next = TIME64_MAX;
486 int warn = 0; 447 int warn = 0;
@@ -544,7 +505,8 @@ static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me)
544 km_state_expired(x, 0, 0); 505 km_state_expired(x, 0, 0);
545resched: 506resched:
546 if (next != TIME64_MAX) { 507 if (next != TIME64_MAX) {
547 tasklet_hrtimer_start(&x->mtimer, ktime_set(next, 0), HRTIMER_MODE_REL); 508 hrtimer_forward_now(&x->mtimer, ktime_set(next, 0));
509 ret = HRTIMER_RESTART;
548 } 510 }
549 511
550 goto out; 512 goto out;
@@ -561,7 +523,7 @@ expired:
561 523
562out: 524out:
563 spin_unlock(&x->lock); 525 spin_unlock(&x->lock);
564 return HRTIMER_NORESTART; 526 return ret;
565} 527}
566 528
567static void xfrm_replay_timer_handler(struct timer_list *t); 529static void xfrm_replay_timer_handler(struct timer_list *t);
@@ -580,8 +542,8 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
580 INIT_HLIST_NODE(&x->bydst); 542 INIT_HLIST_NODE(&x->bydst);
581 INIT_HLIST_NODE(&x->bysrc); 543 INIT_HLIST_NODE(&x->bysrc);
582 INIT_HLIST_NODE(&x->byspi); 544 INIT_HLIST_NODE(&x->byspi);
583 tasklet_hrtimer_init(&x->mtimer, xfrm_timer_handler, 545 hrtimer_init(&x->mtimer, CLOCK_BOOTTIME, HRTIMER_MODE_ABS_SOFT);
584 CLOCK_BOOTTIME, HRTIMER_MODE_ABS); 546 x->mtimer.function = xfrm_timer_handler;
585 timer_setup(&x->rtimer, xfrm_replay_timer_handler, 0); 547 timer_setup(&x->rtimer, xfrm_replay_timer_handler, 0);
586 x->curlft.add_time = ktime_get_real_seconds(); 548 x->curlft.add_time = ktime_get_real_seconds();
587 x->lft.soft_byte_limit = XFRM_INF; 549 x->lft.soft_byte_limit = XFRM_INF;
@@ -590,8 +552,6 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
590 x->lft.hard_packet_limit = XFRM_INF; 552 x->lft.hard_packet_limit = XFRM_INF;
591 x->replay_maxage = 0; 553 x->replay_maxage = 0;
592 x->replay_maxdiff = 0; 554 x->replay_maxdiff = 0;
593 x->inner_mode = NULL;
594 x->inner_mode_iaf = NULL;
595 spin_lock_init(&x->lock); 555 spin_lock_init(&x->lock);
596 } 556 }
597 return x; 557 return x;
@@ -1047,7 +1007,9 @@ found:
1047 hlist_add_head_rcu(&x->byspi, net->xfrm.state_byspi + h); 1007 hlist_add_head_rcu(&x->byspi, net->xfrm.state_byspi + h);
1048 } 1008 }
1049 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires; 1009 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
1050 tasklet_hrtimer_start(&x->mtimer, ktime_set(net->xfrm.sysctl_acq_expires, 0), HRTIMER_MODE_REL); 1010 hrtimer_start(&x->mtimer,
1011 ktime_set(net->xfrm.sysctl_acq_expires, 0),
1012 HRTIMER_MODE_REL_SOFT);
1051 net->xfrm.state_num++; 1013 net->xfrm.state_num++;
1052 xfrm_hash_grow_check(net, x->bydst.next != NULL); 1014 xfrm_hash_grow_check(net, x->bydst.next != NULL);
1053 spin_unlock_bh(&net->xfrm.xfrm_state_lock); 1015 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
@@ -1159,7 +1121,7 @@ static void __xfrm_state_insert(struct xfrm_state *x)
1159 hlist_add_head_rcu(&x->byspi, net->xfrm.state_byspi + h); 1121 hlist_add_head_rcu(&x->byspi, net->xfrm.state_byspi + h);
1160 } 1122 }
1161 1123
1162 tasklet_hrtimer_start(&x->mtimer, ktime_set(1, 0), HRTIMER_MODE_REL); 1124 hrtimer_start(&x->mtimer, ktime_set(1, 0), HRTIMER_MODE_REL_SOFT);
1163 if (x->replay_maxage) 1125 if (x->replay_maxage)
1164 mod_timer(&x->rtimer, jiffies + x->replay_maxage); 1126 mod_timer(&x->rtimer, jiffies + x->replay_maxage);
1165 1127
@@ -1266,7 +1228,9 @@ static struct xfrm_state *__find_acq_core(struct net *net,
1266 x->mark.m = m->m; 1228 x->mark.m = m->m;
1267 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires; 1229 x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
1268 xfrm_state_hold(x); 1230 xfrm_state_hold(x);
1269 tasklet_hrtimer_start(&x->mtimer, ktime_set(net->xfrm.sysctl_acq_expires, 0), HRTIMER_MODE_REL); 1231 hrtimer_start(&x->mtimer,
1232 ktime_set(net->xfrm.sysctl_acq_expires, 0),
1233 HRTIMER_MODE_REL_SOFT);
1270 list_add(&x->km.all, &net->xfrm.state_all); 1234 list_add(&x->km.all, &net->xfrm.state_all);
1271 hlist_add_head_rcu(&x->bydst, net->xfrm.state_bydst + h); 1235 hlist_add_head_rcu(&x->bydst, net->xfrm.state_bydst + h);
1272 h = xfrm_src_hash(net, daddr, saddr, family); 1236 h = xfrm_src_hash(net, daddr, saddr, family);
@@ -1571,7 +1535,8 @@ out:
1571 memcpy(&x1->lft, &x->lft, sizeof(x1->lft)); 1535 memcpy(&x1->lft, &x->lft, sizeof(x1->lft));
1572 x1->km.dying = 0; 1536 x1->km.dying = 0;
1573 1537
1574 tasklet_hrtimer_start(&x1->mtimer, ktime_set(1, 0), HRTIMER_MODE_REL); 1538 hrtimer_start(&x1->mtimer, ktime_set(1, 0),
1539 HRTIMER_MODE_REL_SOFT);
1575 if (x1->curlft.use_time) 1540 if (x1->curlft.use_time)
1576 xfrm_state_check_expire(x1); 1541 xfrm_state_check_expire(x1);
1577 1542
@@ -1610,7 +1575,7 @@ int xfrm_state_check_expire(struct xfrm_state *x)
1610 if (x->curlft.bytes >= x->lft.hard_byte_limit || 1575 if (x->curlft.bytes >= x->lft.hard_byte_limit ||
1611 x->curlft.packets >= x->lft.hard_packet_limit) { 1576 x->curlft.packets >= x->lft.hard_packet_limit) {
1612 x->km.state = XFRM_STATE_EXPIRED; 1577 x->km.state = XFRM_STATE_EXPIRED;
1613 tasklet_hrtimer_start(&x->mtimer, 0, HRTIMER_MODE_REL); 1578 hrtimer_start(&x->mtimer, 0, HRTIMER_MODE_REL_SOFT);
1614 return -EINVAL; 1579 return -EINVAL;
1615 } 1580 }
1616 1581
@@ -2066,7 +2031,7 @@ int km_report(struct net *net, u8 proto, struct xfrm_selector *sel, xfrm_address
2066} 2031}
2067EXPORT_SYMBOL(km_report); 2032EXPORT_SYMBOL(km_report);
2068 2033
2069bool km_is_alive(const struct km_event *c) 2034static bool km_is_alive(const struct km_event *c)
2070{ 2035{
2071 struct xfrm_mgr *km; 2036 struct xfrm_mgr *km;
2072 bool is_alive = false; 2037 bool is_alive = false;
@@ -2082,7 +2047,6 @@ bool km_is_alive(const struct km_event *c)
2082 2047
2083 return is_alive; 2048 return is_alive;
2084} 2049}
2085EXPORT_SYMBOL(km_is_alive);
2086 2050
2087int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen) 2051int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
2088{ 2052{
@@ -2195,6 +2159,7 @@ struct xfrm_state_afinfo *xfrm_state_afinfo_get_rcu(unsigned int family)
2195 2159
2196 return rcu_dereference(xfrm_state_afinfo[family]); 2160 return rcu_dereference(xfrm_state_afinfo[family]);
2197} 2161}
2162EXPORT_SYMBOL_GPL(xfrm_state_afinfo_get_rcu);
2198 2163
2199struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family) 2164struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family)
2200{ 2165{
@@ -2242,8 +2207,9 @@ int xfrm_state_mtu(struct xfrm_state *x, int mtu)
2242 2207
2243int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload) 2208int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload)
2244{ 2209{
2245 struct xfrm_state_afinfo *afinfo; 2210 const struct xfrm_state_afinfo *afinfo;
2246 struct xfrm_mode *inner_mode; 2211 const struct xfrm_mode *inner_mode;
2212 const struct xfrm_mode *outer_mode;
2247 int family = x->props.family; 2213 int family = x->props.family;
2248 int err; 2214 int err;
2249 2215
@@ -2269,25 +2235,22 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload)
2269 goto error; 2235 goto error;
2270 2236
2271 if (!(inner_mode->flags & XFRM_MODE_FLAG_TUNNEL) && 2237 if (!(inner_mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
2272 family != x->sel.family) { 2238 family != x->sel.family)
2273 xfrm_put_mode(inner_mode);
2274 goto error; 2239 goto error;
2275 }
2276 2240
2277 x->inner_mode = inner_mode; 2241 x->inner_mode = *inner_mode;
2278 } else { 2242 } else {
2279 struct xfrm_mode *inner_mode_iaf; 2243 const struct xfrm_mode *inner_mode_iaf;
2280 int iafamily = AF_INET; 2244 int iafamily = AF_INET;
2281 2245
2282 inner_mode = xfrm_get_mode(x->props.mode, x->props.family); 2246 inner_mode = xfrm_get_mode(x->props.mode, x->props.family);
2283 if (inner_mode == NULL) 2247 if (inner_mode == NULL)
2284 goto error; 2248 goto error;
2285 2249
2286 if (!(inner_mode->flags & XFRM_MODE_FLAG_TUNNEL)) { 2250 if (!(inner_mode->flags & XFRM_MODE_FLAG_TUNNEL))
2287 xfrm_put_mode(inner_mode);
2288 goto error; 2251 goto error;
2289 } 2252
2290 x->inner_mode = inner_mode; 2253 x->inner_mode = *inner_mode;
2291 2254
2292 if (x->props.family == AF_INET) 2255 if (x->props.family == AF_INET)
2293 iafamily = AF_INET6; 2256 iafamily = AF_INET6;
@@ -2295,9 +2258,7 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload)
2295 inner_mode_iaf = xfrm_get_mode(x->props.mode, iafamily); 2258 inner_mode_iaf = xfrm_get_mode(x->props.mode, iafamily);
2296 if (inner_mode_iaf) { 2259 if (inner_mode_iaf) {
2297 if (inner_mode_iaf->flags & XFRM_MODE_FLAG_TUNNEL) 2260 if (inner_mode_iaf->flags & XFRM_MODE_FLAG_TUNNEL)
2298 x->inner_mode_iaf = inner_mode_iaf; 2261 x->inner_mode_iaf = *inner_mode_iaf;
2299 else
2300 xfrm_put_mode(inner_mode_iaf);
2301 } 2262 }
2302 } 2263 }
2303 2264
@@ -2311,12 +2272,13 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload)
2311 if (err) 2272 if (err)
2312 goto error; 2273 goto error;
2313 2274
2314 x->outer_mode = xfrm_get_mode(x->props.mode, family); 2275 outer_mode = xfrm_get_mode(x->props.mode, family);
2315 if (x->outer_mode == NULL) { 2276 if (!outer_mode) {
2316 err = -EPROTONOSUPPORT; 2277 err = -EPROTONOSUPPORT;
2317 goto error; 2278 goto error;
2318 } 2279 }
2319 2280
2281 x->outer_mode = *outer_mode;
2320 if (init_replay) { 2282 if (init_replay) {
2321 err = xfrm_init_replay(x); 2283 err = xfrm_init_replay(x);
2322 if (err) 2284 if (err)
@@ -2384,7 +2346,7 @@ void xfrm_state_fini(struct net *net)
2384 2346
2385 flush_work(&net->xfrm.state_hash_work); 2347 flush_work(&net->xfrm.state_hash_work);
2386 flush_work(&xfrm_state_gc_work); 2348 flush_work(&xfrm_state_gc_work);
2387 xfrm_state_flush(net, IPSEC_PROTO_ANY, false, true); 2349 xfrm_state_flush(net, 0, false, true);
2388 2350
2389 WARN_ON(!list_empty(&net->xfrm.state_all)); 2351 WARN_ON(!list_empty(&net->xfrm.state_all));
2390 2352
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index a131f9ff979e..eb8d14389601 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1006,8 +1006,8 @@ static int xfrm_dump_sa(struct sk_buff *skb, struct netlink_callback *cb)
1006 u8 proto = 0; 1006 u8 proto = 0;
1007 int err; 1007 int err;
1008 1008
1009 err = nlmsg_parse(cb->nlh, 0, attrs, XFRMA_MAX, xfrma_policy, 1009 err = nlmsg_parse_deprecated(cb->nlh, 0, attrs, XFRMA_MAX,
1010 cb->extack); 1010 xfrma_policy, cb->extack);
1011 if (err < 0) 1011 if (err < 0)
1012 return err; 1012 return err;
1013 1013
@@ -1424,7 +1424,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
1424 ret = verify_policy_dir(p->dir); 1424 ret = verify_policy_dir(p->dir);
1425 if (ret) 1425 if (ret)
1426 return ret; 1426 return ret;
1427 if (p->index && ((p->index & XFRM_POLICY_MAX) != p->dir)) 1427 if (p->index && (xfrm_policy_id2dir(p->index) != p->dir))
1428 return -EINVAL; 1428 return -EINVAL;
1429 1429
1430 return 0; 1430 return 0;
@@ -1513,20 +1513,8 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
1513 return -EINVAL; 1513 return -EINVAL;
1514 } 1514 }
1515 1515
1516 switch (ut[i].id.proto) { 1516 if (!xfrm_id_proto_valid(ut[i].id.proto))
1517 case IPPROTO_AH:
1518 case IPPROTO_ESP:
1519 case IPPROTO_COMP:
1520#if IS_ENABLED(CONFIG_IPV6)
1521 case IPPROTO_ROUTING:
1522 case IPPROTO_DSTOPTS:
1523#endif
1524 case IPSEC_PROTO_ANY:
1525 break;
1526 default:
1527 return -EINVAL; 1517 return -EINVAL;
1528 }
1529
1530 } 1518 }
1531 1519
1532 return 0; 1520 return 0;
@@ -2656,9 +2644,9 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
2656 } 2644 }
2657 } 2645 }
2658 2646
2659 err = nlmsg_parse(nlh, xfrm_msg_min[type], attrs, 2647 err = nlmsg_parse_deprecated(nlh, xfrm_msg_min[type], attrs,
2660 link->nla_max ? : XFRMA_MAX, 2648 link->nla_max ? : XFRMA_MAX,
2661 link->nla_pol ? : xfrma_policy, extack); 2649 link->nla_pol ? : xfrma_policy, extack);
2662 if (err < 0) 2650 if (err < 0)
2663 return err; 2651 return err;
2664 2652