aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/802/hippi.c4
-rw-r--r--net/Kconfig4
-rw-r--r--net/batman-adv/main.h2
-rw-r--r--net/batman-adv/originator.c2
-rw-r--r--net/batman-adv/translation-table.c2
-rw-r--r--net/bluetooth/bnep/bnep.h3
-rw-r--r--net/bridge/br_fdb.c3
-rw-r--r--net/bridge/br_forward.c6
-rw-r--r--net/bridge/br_if.c2
-rw-r--r--net/bridge/br_ioctl.c2
-rw-r--r--net/bridge/br_netfilter.c2
-rw-r--r--net/bridge/br_netlink.c7
-rw-r--r--net/bridge/br_private.h12
-rw-r--r--net/bridge/br_stp_bpdu.c2
-rw-r--r--net/bridge/br_stp_timer.c2
-rw-r--r--net/bridge/br_sysfs_if.c20
-rw-r--r--net/bridge/br_vlan.c2
-rw-r--r--net/bridge/netfilter/ebt_log.c2
-rw-r--r--net/bridge/netfilter/ebt_snat.c2
-rw-r--r--net/bridge/netfilter/ebt_vlan.c3
-rw-r--r--net/bridge/netfilter/ebtable_broute.c6
-rw-r--r--net/bridge/netfilter/ebtable_filter.c9
-rw-r--r--net/bridge/netfilter/ebtable_nat.c9
-rw-r--r--net/bridge/netfilter/ebtables.c17
-rw-r--r--net/can/gw.c6
-rw-r--r--net/compat.c2
-rw-r--r--net/core/dev.c184
-rw-r--r--net/core/dev_addr_lists.c97
-rw-r--r--net/core/dev_ioctl.c2
-rw-r--r--net/core/drop_monitor.c1
-rw-r--r--net/core/flow_dissector.c6
-rw-r--r--net/core/neighbour.c467
-rw-r--r--net/core/net-sysfs.c4
-rw-r--r--net/core/netprio_cgroup.c2
-rw-r--r--net/core/pktgen.c7
-rw-r--r--net/core/skbuff.c9
-rw-r--r--net/core/sock.c2
-rw-r--r--net/core/sysctl_net_core.c3
-rw-r--r--net/dcb/dcbevent.c3
-rw-r--r--net/dcb/dcbnl.c3
-rw-r--r--net/dccp/ipv4.c2
-rw-r--r--net/dccp/ipv6.c12
-rw-r--r--net/decnet/dn_dev.c13
-rw-r--r--net/decnet/dn_neigh.c28
-rw-r--r--net/decnet/dn_route.c2
-rw-r--r--net/dns_resolver/dns_key.c3
-rw-r--r--net/dns_resolver/dns_query.c3
-rw-r--r--net/dns_resolver/internal.h3
-rw-r--r--net/hsr/hsr_framereg.c16
-rw-r--r--net/hsr/hsr_netlink.c28
-rw-r--r--net/ieee802154/wpan-class.c2
-rw-r--r--net/ipv4/af_inet.c32
-rw-r--r--net/ipv4/arp.c42
-rw-r--r--net/ipv4/cipso_ipv4.c12
-rw-r--r--net/ipv4/datagram.c2
-rw-r--r--net/ipv4/devinet.c62
-rw-r--r--net/ipv4/fib_lookup.h2
-rw-r--r--net/ipv4/fib_rules.c5
-rw-r--r--net/ipv4/fib_semantics.c5
-rw-r--r--net/ipv4/icmp.c4
-rw-r--r--net/ipv4/igmp.c70
-rw-r--r--net/ipv4/inet_lro.c173
-rw-r--r--net/ipv4/inetpeer.c11
-rw-r--r--net/ipv4/ip_fragment.c2
-rw-r--r--net/ipv4/ip_options.c12
-rw-r--r--net/ipv4/ip_sockglue.c5
-rw-r--r--net/ipv4/ip_tunnel_core.c5
-rw-r--r--net/ipv4/ipmr.c2
-rw-r--r--net/ipv4/netfilter/ipt_SYNPROXY.c1
-rw-r--r--net/ipv4/netfilter/nf_nat_snmp_basic.c15
-rw-r--r--net/ipv4/netfilter/nft_reject_ipv4.c2
-rw-r--r--net/ipv4/ping.c17
-rw-r--r--net/ipv4/proc.c1
-rw-r--r--net/ipv4/protocol.c8
-rw-r--r--net/ipv4/raw.c4
-rw-r--r--net/ipv4/syncookies.c2
-rw-r--r--net/ipv4/sysctl_net_ipv4.c25
-rw-r--r--net/ipv4/tcp.c73
-rw-r--r--net/ipv4/tcp_input.c6
-rw-r--r--net/ipv4/tcp_ipv4.c6
-rw-r--r--net/ipv4/tcp_memcontrol.c9
-rw-r--r--net/ipv4/tcp_offload.c40
-rw-r--r--net/ipv4/tcp_output.c141
-rw-r--r--net/ipv4/tcp_probe.c4
-rw-r--r--net/ipv4/tcp_yeah.c20
-rw-r--r--net/ipv4/udp.c49
-rw-r--r--net/ipv4/xfrm4_mode_beet.c2
-rw-r--r--net/ipv4/xfrm4_state.c2
-rw-r--r--net/ipv6/addrconf.c273
-rw-r--r--net/ipv6/af_inet6.c7
-rw-r--r--net/ipv6/ah6.c3
-rw-r--r--net/ipv6/datagram.c11
-rw-r--r--net/ipv6/esp6.c3
-rw-r--r--net/ipv6/fib6_rules.c6
-rw-r--r--net/ipv6/inet6_connection_sock.c4
-rw-r--r--net/ipv6/ip6_gre.c3
-rw-r--r--net/ipv6/ip6_offload.c51
-rw-r--r--net/ipv6/ip6_output.c47
-rw-r--r--net/ipv6/ip6_tunnel.c3
-rw-r--r--net/ipv6/ipcomp6.c3
-rw-r--r--net/ipv6/ipv6_sockglue.c9
-rw-r--r--net/ipv6/mip6.c3
-rw-r--r--net/ipv6/ndisc.c58
-rw-r--r--net/ipv6/netfilter/ip6t_SYNPROXY.c1
-rw-r--r--net/ipv6/ping.c5
-rw-r--r--net/ipv6/protocol.c4
-rw-r--r--net/ipv6/raw.c7
-rw-r--r--net/ipv6/route.c46
-rw-r--r--net/ipv6/sit.c50
-rw-r--r--net/ipv6/syncookies.c2
-rw-r--r--net/ipv6/tcp_ipv6.c38
-rw-r--r--net/ipv6/tcpv6_offload.c38
-rw-r--r--net/ipv6/tunnel6.c3
-rw-r--r--net/ipv6/udp.c12
-rw-r--r--net/ipv6/xfrm6_mode_ro.c3
-rw-r--r--net/ipv6/xfrm6_tunnel.c3
-rw-r--r--net/irda/af_irda.c4
-rw-r--r--net/irda/discovery.c4
-rw-r--r--net/irda/ircomm/ircomm_core.c4
-rw-r--r--net/irda/ircomm/ircomm_event.c4
-rw-r--r--net/irda/ircomm/ircomm_lmp.c4
-rw-r--r--net/irda/ircomm/ircomm_param.c4
-rw-r--r--net/irda/ircomm/ircomm_ttp.c4
-rw-r--r--net/irda/ircomm/ircomm_tty.c4
-rw-r--r--net/irda/ircomm/ircomm_tty_attach.c4
-rw-r--r--net/irda/ircomm/ircomm_tty_ioctl.c4
-rw-r--r--net/irda/irda_device.c4
-rw-r--r--net/irda/irlap.c4
-rw-r--r--net/irda/parameters.c4
-rw-r--r--net/irda/qos.c4
-rw-r--r--net/key/af_key.c29
-rw-r--r--net/l2tp/l2tp_ip6.c5
-rw-r--r--net/llc/llc_conn.c4
-rw-r--r--net/llc/llc_core.c2
-rw-r--r--net/llc/llc_sap.c4
-rw-r--r--net/mac80211/iface.c7
-rw-r--r--net/mac802154/wpan.c4
-rw-r--r--net/netfilter/ipset/ip_set_hash_netnet.c2
-rw-r--r--net/netfilter/ipvs/ip_vs_nfct.c3
-rw-r--r--net/netfilter/nf_tables_api.c46
-rw-r--r--net/netfilter/xt_connmark.c3
-rw-r--r--net/netfilter/xt_hashlimit.c25
-rw-r--r--net/netfilter/xt_osf.c3
-rw-r--r--net/netlabel/netlabel_addrlist.c3
-rw-r--r--net/netlabel/netlabel_addrlist.h3
-rw-r--r--net/netlabel/netlabel_cipso_v4.c3
-rw-r--r--net/netlabel/netlabel_cipso_v4.h3
-rw-r--r--net/netlabel/netlabel_domainhash.c3
-rw-r--r--net/netlabel/netlabel_domainhash.h3
-rw-r--r--net/netlabel/netlabel_kapi.c3
-rw-r--r--net/netlabel/netlabel_mgmt.c3
-rw-r--r--net/netlabel/netlabel_mgmt.h3
-rw-r--r--net/netlabel/netlabel_unlabeled.c3
-rw-r--r--net/netlabel/netlabel_unlabeled.h3
-rw-r--r--net/netlabel/netlabel_user.c3
-rw-r--r--net/netlabel/netlabel_user.h3
-rw-r--r--net/netlink/af_netlink.c15
-rw-r--r--net/netlink/genetlink.c13
-rw-r--r--net/openvswitch/actions.c10
-rw-r--r--net/openvswitch/flow_table.c4
-rw-r--r--net/packet/af_packet.c202
-rw-r--r--net/packet/internal.h1
-rw-r--r--net/rds/ib_send.c5
-rw-r--r--net/rose/af_rose.c2
-rw-r--r--net/rose/rose_dev.c2
-rw-r--r--net/sched/Kconfig9
-rw-r--r--net/sched/Makefile1
-rw-r--r--net/sched/act_api.c276
-rw-r--r--net/sched/act_csum.c15
-rw-r--r--net/sched/act_gact.c15
-rw-r--r--net/sched/act_ipt.c25
-rw-r--r--net/sched/act_mirred.c20
-rw-r--r--net/sched/act_nat.c14
-rw-r--r--net/sched/act_pedit.c14
-rw-r--r--net/sched/act_police.c70
-rw-r--r--net/sched/act_simple.c21
-rw-r--r--net/sched/act_skbedit.c17
-rw-r--r--net/sched/cls_api.c117
-rw-r--r--net/sched/cls_basic.c13
-rw-r--r--net/sched/cls_bpf.c15
-rw-r--r--net/sched/cls_cgroup.c14
-rw-r--r--net/sched/cls_flow.c15
-rw-r--r--net/sched/cls_fw.c13
-rw-r--r--net/sched/cls_route.c13
-rw-r--r--net/sched/cls_rsvp.h13
-rw-r--r--net/sched/cls_tcindex.c17
-rw-r--r--net/sched/cls_u32.c15
-rw-r--r--net/sched/em_meta.c159
-rw-r--r--net/sched/sch_api.c10
-rw-r--r--net/sched/sch_cbq.c10
-rw-r--r--net/sched/sch_dsmark.c39
-rw-r--r--net/sched/sch_fq.c36
-rw-r--r--net/sched/sch_generic.c6
-rw-r--r--net/sched/sch_gred.c4
-rw-r--r--net/sched/sch_hhf.c745
-rw-r--r--net/sched/sch_htb.c55
-rw-r--r--net/sched/sch_mq.c13
-rw-r--r--net/sched/sch_mqprio.c10
-rw-r--r--net/sched/sch_multiq.c3
-rw-r--r--net/sched/sch_netem.c26
-rw-r--r--net/sched/sch_sfq.c10
-rw-r--r--net/sched/sch_tbf.c162
-rw-r--r--net/sctp/associola.c75
-rw-r--r--net/sctp/auth.c32
-rw-r--r--net/sctp/bind_addr.c5
-rw-r--r--net/sctp/chunk.c9
-rw-r--r--net/sctp/command.c5
-rw-r--r--net/sctp/debug.c5
-rw-r--r--net/sctp/endpointola.c5
-rw-r--r--net/sctp/input.c82
-rw-r--r--net/sctp/inqueue.c5
-rw-r--r--net/sctp/ipv6.c14
-rw-r--r--net/sctp/objcnt.c7
-rw-r--r--net/sctp/output.c30
-rw-r--r--net/sctp/outqueue.c19
-rw-r--r--net/sctp/primitive.c5
-rw-r--r--net/sctp/probe.c17
-rw-r--r--net/sctp/proc.c13
-rw-r--r--net/sctp/protocol.c9
-rw-r--r--net/sctp/sm_make_chunk.c76
-rw-r--r--net/sctp/sm_sideeffect.c11
-rw-r--r--net/sctp/sm_statefuns.c44
-rw-r--r--net/sctp/sm_statetable.c7
-rw-r--r--net/sctp/socket.c124
-rw-r--r--net/sctp/ssnmap.c5
-rw-r--r--net/sctp/sysctl.c83
-rw-r--r--net/sctp/transport.c7
-rw-r--r--net/sctp/tsnmap.c5
-rw-r--r--net/sctp/ulpevent.c5
-rw-r--r--net/sctp/ulpqueue.c16
-rw-r--r--net/socket.c108
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c2
-rw-r--r--net/sunrpc/rpc_pipe.c11
-rw-r--r--net/tipc/bcast.c6
-rw-r--r--net/tipc/bearer.c323
-rw-r--r--net/tipc/bearer.h52
-rw-r--r--net/tipc/core.c15
-rw-r--r--net/tipc/core.h2
-rw-r--r--net/tipc/discover.c17
-rw-r--r--net/tipc/eth_media.c326
-rw-r--r--net/tipc/handler.c11
-rw-r--r--net/tipc/ib_media.c319
-rw-r--r--net/tipc/link.c124
-rw-r--r--net/tipc/link.h7
-rw-r--r--net/tipc/name_table.c3
-rw-r--r--net/tipc/node.c6
-rw-r--r--net/tipc/port.c9
-rw-r--r--net/tipc/socket.c33
-rw-r--r--net/unix/af_unix.c25
-rw-r--r--net/x25/af_x25.c4
-rw-r--r--net/x25/x25_dev.c10
-rw-r--r--net/x25/x25_facilities.c14
-rw-r--r--net/x25/x25_forward.c5
-rw-r--r--net/x25/x25_in.c4
-rw-r--r--net/x25/x25_link.c6
-rw-r--r--net/x25/x25_subr.c6
-rw-r--r--net/xfrm/xfrm_policy.c151
-rw-r--r--net/xfrm/xfrm_state.c149
-rw-r--r--net/xfrm/xfrm_user.c56
259 files changed, 4042 insertions, 3602 deletions
diff --git a/net/802/hippi.c b/net/802/hippi.c
index 51a1f530417d..a97a3bde77bb 100644
--- a/net/802/hippi.c
+++ b/net/802/hippi.c
@@ -172,14 +172,14 @@ EXPORT_SYMBOL(hippi_mac_addr);
172int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p) 172int hippi_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
173{ 173{
174 /* Never send broadcast/multicast ARP messages */ 174 /* Never send broadcast/multicast ARP messages */
175 p->mcast_probes = 0; 175 NEIGH_VAR_SET(p, MCAST_PROBES, 0);
176 176
177 /* In IPv6 unicast probes are valid even on NBMA, 177 /* In IPv6 unicast probes are valid even on NBMA,
178 * because they are encapsulated in normal IPv6 protocol. 178 * because they are encapsulated in normal IPv6 protocol.
179 * Should be a generic flag. 179 * Should be a generic flag.
180 */ 180 */
181 if (p->tbl->family != AF_INET6) 181 if (p->tbl->family != AF_INET6)
182 p->ucast_probes = 0; 182 NEIGH_VAR_SET(p, UCAST_PROBES, 0);
183 return 0; 183 return 0;
184} 184}
185EXPORT_SYMBOL(hippi_neigh_setup_dev); 185EXPORT_SYMBOL(hippi_neigh_setup_dev);
diff --git a/net/Kconfig b/net/Kconfig
index 0715db64a5c3..d334678c0bd8 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -224,7 +224,7 @@ source "net/hsr/Kconfig"
224 224
225config RPS 225config RPS
226 boolean 226 boolean
227 depends on SMP && SYSFS && USE_GENERIC_SMP_HELPERS 227 depends on SMP && SYSFS
228 default y 228 default y
229 229
230config RFS_ACCEL 230config RFS_ACCEL
@@ -235,7 +235,7 @@ config RFS_ACCEL
235 235
236config XPS 236config XPS
237 boolean 237 boolean
238 depends on SMP && USE_GENERIC_SMP_HELPERS 238 depends on SMP
239 default y 239 default y
240 240
241config NETPRIO_CGROUP 241config NETPRIO_CGROUP
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index f94f287b8670..322dd7323732 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -266,7 +266,7 @@ static inline void batadv_dbg(int type __always_unused,
266 */ 266 */
267static inline int batadv_compare_eth(const void *data1, const void *data2) 267static inline int batadv_compare_eth(const void *data1, const void *data2)
268{ 268{
269 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); 269 return ether_addr_equal_unaligned(data1, data2);
270} 270}
271 271
272/** 272/**
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 8ab14340d10f..803ab4be40c2 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -41,7 +41,7 @@ int batadv_compare_orig(const struct hlist_node *node, const void *data2)
41 const void *data1 = container_of(node, struct batadv_orig_node, 41 const void *data1 = container_of(node, struct batadv_orig_node,
42 hash_entry); 42 hash_entry);
43 43
44 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); 44 return batadv_compare_eth(data1, data2);
45} 45}
46 46
47/** 47/**
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 4add57d4857f..06506e6f9006 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -51,7 +51,7 @@ static int batadv_compare_tt(const struct hlist_node *node, const void *data2)
51 const void *data1 = container_of(node, struct batadv_tt_common_entry, 51 const void *data1 = container_of(node, struct batadv_tt_common_entry,
52 hash_entry); 52 hash_entry);
53 53
54 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); 54 return batadv_compare_eth(data1, data2);
55} 55}
56 56
57/** 57/**
diff --git a/net/bluetooth/bnep/bnep.h b/net/bluetooth/bnep/bnep.h
index e7ee5314f39a..5a5b16f365e9 100644
--- a/net/bluetooth/bnep/bnep.h
+++ b/net/bluetooth/bnep/bnep.h
@@ -12,8 +12,7 @@
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software 15 along with this program; if not, see <http://www.gnu.org/licenses/>.
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 16*/
18 17
19#ifndef _BNEP_H 18#ifndef _BNEP_H
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 33e8f23acddd..c5f5a4a933f4 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -570,8 +570,7 @@ static void fdb_notify(struct net_bridge *br,
570 rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC); 570 rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
571 return; 571 return;
572errout: 572errout:
573 if (err < 0) 573 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
574 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
575} 574}
576 575
577/* Dump information about entries, in response to GETNEIGH */ 576/* Dump information about entries, in response to GETNEIGH */
diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index 4b81b1471789..d3409e6b5453 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -26,13 +26,13 @@ static int deliver_clone(const struct net_bridge_port *prev,
26 void (*__packet_hook)(const struct net_bridge_port *p, 26 void (*__packet_hook)(const struct net_bridge_port *p,
27 struct sk_buff *skb)); 27 struct sk_buff *skb));
28 28
29/* Don't forward packets to originating port or forwarding diasabled */ 29/* Don't forward packets to originating port or forwarding disabled */
30static inline int should_deliver(const struct net_bridge_port *p, 30static inline int should_deliver(const struct net_bridge_port *p,
31 const struct sk_buff *skb) 31 const struct sk_buff *skb)
32{ 32{
33 return (((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) && 33 return ((p->flags & BR_HAIRPIN_MODE) || skb->dev != p->dev) &&
34 br_allowed_egress(p->br, nbp_get_vlan_info(p), skb) && 34 br_allowed_egress(p->br, nbp_get_vlan_info(p), skb) &&
35 p->state == BR_STATE_FORWARDING); 35 p->state == BR_STATE_FORWARDING;
36} 36}
37 37
38static inline unsigned int packet_length(const struct sk_buff *skb) 38static inline unsigned int packet_length(const struct sk_buff *skb)
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 4bf02adb5dc2..1f6bd1e2e8a4 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -61,7 +61,7 @@ static int port_cost(struct net_device *dev)
61} 61}
62 62
63 63
64/* Check for port carrier transistions. */ 64/* Check for port carrier transitions. */
65void br_port_carrier_check(struct net_bridge_port *p) 65void br_port_carrier_check(struct net_bridge_port *p)
66{ 66{
67 struct net_device *dev = p->dev; 67 struct net_device *dev = p->dev;
diff --git a/net/bridge/br_ioctl.c b/net/bridge/br_ioctl.c
index cd8c3a44ab7d..a9a4a1b7863d 100644
--- a/net/bridge/br_ioctl.c
+++ b/net/bridge/br_ioctl.c
@@ -381,7 +381,7 @@ int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
381{ 381{
382 struct net_bridge *br = netdev_priv(dev); 382 struct net_bridge *br = netdev_priv(dev);
383 383
384 switch(cmd) { 384 switch (cmd) {
385 case SIOCDEVPRIVATE: 385 case SIOCDEVPRIVATE:
386 return old_dev_ioctl(dev, rq, cmd); 386 return old_dev_ioctl(dev, rq, cmd);
387 387
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index 80cad2cf02a7..b008c59a92c4 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -1001,7 +1001,7 @@ static struct nf_hook_ops br_nf_ops[] __read_mostly = {
1001#ifdef CONFIG_SYSCTL 1001#ifdef CONFIG_SYSCTL
1002static 1002static
1003int brnf_sysctl_call_tables(struct ctl_table *ctl, int write, 1003int brnf_sysctl_call_tables(struct ctl_table *ctl, int write,
1004 void __user * buffer, size_t * lenp, loff_t * ppos) 1004 void __user *buffer, size_t *lenp, loff_t *ppos)
1005{ 1005{
1006 int ret; 1006 int ret;
1007 1007
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index f75d92e4f96b..6526ac89bbfa 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -195,8 +195,7 @@ void br_ifinfo_notify(int event, struct net_bridge_port *port)
195 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC); 195 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
196 return; 196 return;
197errout: 197errout:
198 if (err < 0) 198 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
199 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
200} 199}
201 200
202 201
@@ -373,7 +372,7 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)
373 372
374 p = br_port_get_rtnl(dev); 373 p = br_port_get_rtnl(dev);
375 /* We want to accept dev as bridge itself if the AF_SPEC 374 /* We want to accept dev as bridge itself if the AF_SPEC
376 * is set to see if someone is setting vlan info on the brigde 375 * is set to see if someone is setting vlan info on the bridge
377 */ 376 */
378 if (!p && !afspec) 377 if (!p && !afspec)
379 return -EINVAL; 378 return -EINVAL;
@@ -389,7 +388,7 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)
389 err = br_setport(p, tb); 388 err = br_setport(p, tb);
390 spin_unlock_bh(&p->br->lock); 389 spin_unlock_bh(&p->br->lock);
391 } else { 390 } else {
392 /* Binary compatability with old RSTP */ 391 /* Binary compatibility with old RSTP */
393 if (nla_len(protinfo) < sizeof(u8)) 392 if (nla_len(protinfo) < sizeof(u8))
394 return -EINVAL; 393 return -EINVAL;
395 394
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 229d820bdf0b..2e77d923c8ee 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -426,6 +426,16 @@ netdev_features_t br_features_recompute(struct net_bridge *br,
426int br_handle_frame_finish(struct sk_buff *skb); 426int br_handle_frame_finish(struct sk_buff *skb);
427rx_handler_result_t br_handle_frame(struct sk_buff **pskb); 427rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
428 428
429static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
430{
431 return rcu_dereference(dev->rx_handler) == br_handle_frame;
432}
433
434static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
435{
436 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL;
437}
438
429/* br_ioctl.c */ 439/* br_ioctl.c */
430int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 440int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
431int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, 441int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
@@ -711,7 +721,7 @@ void br_netfilter_fini(void);
711void br_netfilter_rtable_init(struct net_bridge *); 721void br_netfilter_rtable_init(struct net_bridge *);
712#else 722#else
713#define br_netfilter_init() (0) 723#define br_netfilter_init() (0)
714#define br_netfilter_fini() do { } while(0) 724#define br_netfilter_fini() do { } while (0)
715#define br_netfilter_rtable_init(x) 725#define br_netfilter_rtable_init(x)
716#endif 726#endif
717 727
diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c
index 8660ea3be705..bdb459d21ad8 100644
--- a/net/bridge/br_stp_bpdu.c
+++ b/net/bridge/br_stp_bpdu.c
@@ -153,7 +153,7 @@ void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
153 if (buf[0] != 0 || buf[1] != 0 || buf[2] != 0) 153 if (buf[0] != 0 || buf[1] != 0 || buf[2] != 0)
154 goto err; 154 goto err;
155 155
156 p = br_port_get_rcu(dev); 156 p = br_port_get_check_rcu(dev);
157 if (!p) 157 if (!p)
158 goto err; 158 goto err;
159 159
diff --git a/net/bridge/br_stp_timer.c b/net/bridge/br_stp_timer.c
index 950663d4d330..558c46d19e05 100644
--- a/net/bridge/br_stp_timer.c
+++ b/net/bridge/br_stp_timer.c
@@ -110,7 +110,7 @@ static void br_tcn_timer_expired(unsigned long arg)
110 if (!br_is_root_bridge(br) && (br->dev->flags & IFF_UP)) { 110 if (!br_is_root_bridge(br) && (br->dev->flags & IFF_UP)) {
111 br_transmit_tcn(br); 111 br_transmit_tcn(br);
112 112
113 mod_timer(&br->tcn_timer,jiffies + br->bridge_hello_time); 113 mod_timer(&br->tcn_timer, jiffies + br->bridge_hello_time);
114 } 114 }
115 spin_unlock(&br->lock); 115 spin_unlock(&br->lock);
116} 116}
diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
index 2a2cdb756d51..dd595bd7fa82 100644
--- a/net/bridge/br_sysfs_if.c
+++ b/net/bridge/br_sysfs_if.c
@@ -26,7 +26,7 @@ struct brport_attribute {
26 int (*store)(struct net_bridge_port *, unsigned long); 26 int (*store)(struct net_bridge_port *, unsigned long);
27}; 27};
28 28
29#define BRPORT_ATTR(_name,_mode,_show,_store) \ 29#define BRPORT_ATTR(_name, _mode, _show, _store) \
30const struct brport_attribute brport_attr_##_name = { \ 30const struct brport_attribute brport_attr_##_name = { \
31 .attr = {.name = __stringify(_name), \ 31 .attr = {.name = __stringify(_name), \
32 .mode = _mode }, \ 32 .mode = _mode }, \
@@ -209,21 +209,21 @@ static const struct brport_attribute *brport_attrs[] = {
209#define to_brport_attr(_at) container_of(_at, struct brport_attribute, attr) 209#define to_brport_attr(_at) container_of(_at, struct brport_attribute, attr)
210#define to_brport(obj) container_of(obj, struct net_bridge_port, kobj) 210#define to_brport(obj) container_of(obj, struct net_bridge_port, kobj)
211 211
212static ssize_t brport_show(struct kobject * kobj, 212static ssize_t brport_show(struct kobject *kobj,
213 struct attribute * attr, char * buf) 213 struct attribute *attr, char *buf)
214{ 214{
215 struct brport_attribute * brport_attr = to_brport_attr(attr); 215 struct brport_attribute *brport_attr = to_brport_attr(attr);
216 struct net_bridge_port * p = to_brport(kobj); 216 struct net_bridge_port *p = to_brport(kobj);
217 217
218 return brport_attr->show(p, buf); 218 return brport_attr->show(p, buf);
219} 219}
220 220
221static ssize_t brport_store(struct kobject * kobj, 221static ssize_t brport_store(struct kobject *kobj,
222 struct attribute * attr, 222 struct attribute *attr,
223 const char * buf, size_t count) 223 const char *buf, size_t count)
224{ 224{
225 struct brport_attribute * brport_attr = to_brport_attr(attr); 225 struct brport_attribute *brport_attr = to_brport_attr(attr);
226 struct net_bridge_port * p = to_brport(kobj); 226 struct net_bridge_port *p = to_brport(kobj);
227 ssize_t ret = -EINVAL; 227 ssize_t ret = -EINVAL;
228 char *endp; 228 char *endp;
229 unsigned long val; 229 unsigned long val;
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index af5ebd18d705..7ffc801467ec 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -146,7 +146,7 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
146 146
147 /* At this point, we know that the frame was filtered and contains 147 /* At this point, we know that the frame was filtered and contains
148 * a valid vlan id. If the vlan id is set in the untagged bitmap, 148 * a valid vlan id. If the vlan id is set in the untagged bitmap,
149 * send untagged; otherwise, send taged. 149 * send untagged; otherwise, send tagged.
150 */ 150 */
151 br_vlan_get_tag(skb, &vid); 151 br_vlan_get_tag(skb, &vid);
152 if (test_bit(vid, pv->untagged_bitmap)) 152 if (test_bit(vid, pv->untagged_bitmap))
diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index 19c37a4929bc..5322a36867a3 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -96,7 +96,7 @@ ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
96 bitmask = NF_LOG_MASK; 96 bitmask = NF_LOG_MASK;
97 97
98 if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto == 98 if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto ==
99 htons(ETH_P_IP)){ 99 htons(ETH_P_IP)) {
100 const struct iphdr *ih; 100 const struct iphdr *ih;
101 struct iphdr _iph; 101 struct iphdr _iph;
102 102
diff --git a/net/bridge/netfilter/ebt_snat.c b/net/bridge/netfilter/ebt_snat.c
index f8f0bd1a1d51..0f6b118d6cb2 100644
--- a/net/bridge/netfilter/ebt_snat.c
+++ b/net/bridge/netfilter/ebt_snat.c
@@ -35,7 +35,7 @@ ebt_snat_tg(struct sk_buff *skb, const struct xt_action_param *par)
35 return EBT_DROP; 35 return EBT_DROP;
36 if (ap->ar_hln != ETH_ALEN) 36 if (ap->ar_hln != ETH_ALEN)
37 goto out; 37 goto out;
38 if (skb_store_bits(skb, sizeof(_ah), info->mac,ETH_ALEN)) 38 if (skb_store_bits(skb, sizeof(_ah), info->mac, ETH_ALEN))
39 return EBT_DROP; 39 return EBT_DROP;
40 } 40 }
41out: 41out:
diff --git a/net/bridge/netfilter/ebt_vlan.c b/net/bridge/netfilter/ebt_vlan.c
index eae67bf0446c..8d3f8c7651f0 100644
--- a/net/bridge/netfilter/ebt_vlan.c
+++ b/net/bridge/netfilter/ebt_vlan.c
@@ -14,8 +14,7 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 18 */
20 19
21#include <linux/if_ether.h> 20#include <linux/if_ether.h>
diff --git a/net/bridge/netfilter/ebtable_broute.c b/net/bridge/netfilter/ebtable_broute.c
index dbd1c783431b..d2cdf5d6e98c 100644
--- a/net/bridge/netfilter/ebtable_broute.c
+++ b/net/bridge/netfilter/ebtable_broute.c
@@ -23,8 +23,7 @@ static struct ebt_entries initial_chain = {
23 .policy = EBT_ACCEPT, 23 .policy = EBT_ACCEPT,
24}; 24};
25 25
26static struct ebt_replace_kernel initial_table = 26static struct ebt_replace_kernel initial_table = {
27{
28 .name = "broute", 27 .name = "broute",
29 .valid_hooks = 1 << NF_BR_BROUTING, 28 .valid_hooks = 1 << NF_BR_BROUTING,
30 .entries_size = sizeof(struct ebt_entries), 29 .entries_size = sizeof(struct ebt_entries),
@@ -41,8 +40,7 @@ static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
41 return 0; 40 return 0;
42} 41}
43 42
44static const struct ebt_table broute_table = 43static const struct ebt_table broute_table = {
45{
46 .name = "broute", 44 .name = "broute",
47 .table = &initial_table, 45 .table = &initial_table,
48 .valid_hooks = 1 << NF_BR_BROUTING, 46 .valid_hooks = 1 << NF_BR_BROUTING,
diff --git a/net/bridge/netfilter/ebtable_filter.c b/net/bridge/netfilter/ebtable_filter.c
index bb2da7b706e7..ce205aabf9c5 100644
--- a/net/bridge/netfilter/ebtable_filter.c
+++ b/net/bridge/netfilter/ebtable_filter.c
@@ -14,8 +14,7 @@
14#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \ 14#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
15 (1 << NF_BR_LOCAL_OUT)) 15 (1 << NF_BR_LOCAL_OUT))
16 16
17static struct ebt_entries initial_chains[] = 17static struct ebt_entries initial_chains[] = {
18{
19 { 18 {
20 .name = "INPUT", 19 .name = "INPUT",
21 .policy = EBT_ACCEPT, 20 .policy = EBT_ACCEPT,
@@ -30,8 +29,7 @@ static struct ebt_entries initial_chains[] =
30 }, 29 },
31}; 30};
32 31
33static struct ebt_replace_kernel initial_table = 32static struct ebt_replace_kernel initial_table = {
34{
35 .name = "filter", 33 .name = "filter",
36 .valid_hooks = FILTER_VALID_HOOKS, 34 .valid_hooks = FILTER_VALID_HOOKS,
37 .entries_size = 3 * sizeof(struct ebt_entries), 35 .entries_size = 3 * sizeof(struct ebt_entries),
@@ -50,8 +48,7 @@ static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
50 return 0; 48 return 0;
51} 49}
52 50
53static const struct ebt_table frame_filter = 51static const struct ebt_table frame_filter = {
54{
55 .name = "filter", 52 .name = "filter",
56 .table = &initial_table, 53 .table = &initial_table,
57 .valid_hooks = FILTER_VALID_HOOKS, 54 .valid_hooks = FILTER_VALID_HOOKS,
diff --git a/net/bridge/netfilter/ebtable_nat.c b/net/bridge/netfilter/ebtable_nat.c
index bd238f1f105b..a0ac2984fb6c 100644
--- a/net/bridge/netfilter/ebtable_nat.c
+++ b/net/bridge/netfilter/ebtable_nat.c
@@ -14,8 +14,7 @@
14#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \ 14#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
15 (1 << NF_BR_POST_ROUTING)) 15 (1 << NF_BR_POST_ROUTING))
16 16
17static struct ebt_entries initial_chains[] = 17static struct ebt_entries initial_chains[] = {
18{
19 { 18 {
20 .name = "PREROUTING", 19 .name = "PREROUTING",
21 .policy = EBT_ACCEPT, 20 .policy = EBT_ACCEPT,
@@ -30,8 +29,7 @@ static struct ebt_entries initial_chains[] =
30 } 29 }
31}; 30};
32 31
33static struct ebt_replace_kernel initial_table = 32static struct ebt_replace_kernel initial_table = {
34{
35 .name = "nat", 33 .name = "nat",
36 .valid_hooks = NAT_VALID_HOOKS, 34 .valid_hooks = NAT_VALID_HOOKS,
37 .entries_size = 3 * sizeof(struct ebt_entries), 35 .entries_size = 3 * sizeof(struct ebt_entries),
@@ -50,8 +48,7 @@ static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
50 return 0; 48 return 0;
51} 49}
52 50
53static struct ebt_table frame_nat = 51static struct ebt_table frame_nat = {
54{
55 .name = "nat", 52 .name = "nat",
56 .table = &initial_table, 53 .table = &initial_table,
57 .valid_hooks = NAT_VALID_HOOKS, 54 .valid_hooks = NAT_VALID_HOOKS,
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index ac7802428384..0e474b13463b 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -118,10 +118,10 @@ ebt_dev_check(const char *entry, const struct net_device *device)
118 /* 1 is the wildcard token */ 118 /* 1 is the wildcard token */
119 while (entry[i] != '\0' && entry[i] != 1 && entry[i] == devname[i]) 119 while (entry[i] != '\0' && entry[i] != 1 && entry[i] == devname[i])
120 i++; 120 i++;
121 return (devname[i] != entry[i] && entry[i] != 1); 121 return devname[i] != entry[i] && entry[i] != 1;
122} 122}
123 123
124#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg)) 124#define FWINV2(bool, invflg) ((bool) ^ !!(e->invflags & invflg))
125/* process standard matches */ 125/* process standard matches */
126static inline int 126static inline int
127ebt_basic_match(const struct ebt_entry *e, const struct sk_buff *skb, 127ebt_basic_match(const struct ebt_entry *e, const struct sk_buff *skb,
@@ -1441,7 +1441,7 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
1441 return -EFAULT; 1441 return -EFAULT;
1442 1442
1443 if (*len != sizeof(struct ebt_replace) + entries_size + 1443 if (*len != sizeof(struct ebt_replace) + entries_size +
1444 (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) 1444 (tmp.num_counters ? nentries * sizeof(struct ebt_counter) : 0))
1445 return -EINVAL; 1445 return -EINVAL;
1446 1446
1447 if (tmp.nentries != nentries) { 1447 if (tmp.nentries != nentries) {
@@ -1477,7 +1477,7 @@ static int do_ebt_set_ctl(struct sock *sk,
1477 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) 1477 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1478 return -EPERM; 1478 return -EPERM;
1479 1479
1480 switch(cmd) { 1480 switch (cmd) {
1481 case EBT_SO_SET_ENTRIES: 1481 case EBT_SO_SET_ENTRIES:
1482 ret = do_replace(net, user, len); 1482 ret = do_replace(net, user, len);
1483 break; 1483 break;
@@ -1507,10 +1507,10 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1507 if (!t) 1507 if (!t)
1508 return ret; 1508 return ret;
1509 1509
1510 switch(cmd) { 1510 switch (cmd) {
1511 case EBT_SO_GET_INFO: 1511 case EBT_SO_GET_INFO:
1512 case EBT_SO_GET_INIT_INFO: 1512 case EBT_SO_GET_INIT_INFO:
1513 if (*len != sizeof(struct ebt_replace)){ 1513 if (*len != sizeof(struct ebt_replace)) {
1514 ret = -EINVAL; 1514 ret = -EINVAL;
1515 mutex_unlock(&ebt_mutex); 1515 mutex_unlock(&ebt_mutex);
1516 break; 1516 break;
@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
1525 tmp.valid_hooks = t->table->valid_hooks; 1525 tmp.valid_hooks = t->table->valid_hooks;
1526 } 1526 }
1527 mutex_unlock(&ebt_mutex); 1527 mutex_unlock(&ebt_mutex);
1528 if (copy_to_user(user, &tmp, *len) != 0){ 1528 if (copy_to_user(user, &tmp, *len) != 0) {
1529 BUGPRINT("c2u Didn't work\n"); 1529 BUGPRINT("c2u Didn't work\n");
1530 ret = -EFAULT; 1530 ret = -EFAULT;
1531 break; 1531 break;
@@ -2375,8 +2375,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
2375} 2375}
2376#endif 2376#endif
2377 2377
2378static struct nf_sockopt_ops ebt_sockopts = 2378static struct nf_sockopt_ops ebt_sockopts = {
2379{
2380 .pf = PF_INET, 2379 .pf = PF_INET,
2381 .set_optmin = EBT_BASE_CTL, 2380 .set_optmin = EBT_BASE_CTL,
2382 .set_optmax = EBT_SO_SET_MAX + 1, 2381 .set_optmax = EBT_SO_SET_MAX + 1,
diff --git a/net/can/gw.c b/net/can/gw.c
index 3f9b0f3a2818..88c8a39c173d 100644
--- a/net/can/gw.c
+++ b/net/can/gw.c
@@ -844,8 +844,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
844 if (!gwj->src.dev) 844 if (!gwj->src.dev)
845 goto out; 845 goto out;
846 846
847 /* check for CAN netdev not using header_ops - see gw_rcv() */ 847 if (gwj->src.dev->type != ARPHRD_CAN)
848 if (gwj->src.dev->type != ARPHRD_CAN || gwj->src.dev->header_ops)
849 goto put_src_out; 848 goto put_src_out;
850 849
851 gwj->dst.dev = dev_get_by_index(&init_net, gwj->ccgw.dst_idx); 850 gwj->dst.dev = dev_get_by_index(&init_net, gwj->ccgw.dst_idx);
@@ -853,8 +852,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
853 if (!gwj->dst.dev) 852 if (!gwj->dst.dev)
854 goto put_src_out; 853 goto put_src_out;
855 854
856 /* check for CAN netdev not using header_ops - see gw_rcv() */ 855 if (gwj->dst.dev->type != ARPHRD_CAN)
857 if (gwj->dst.dev->type != ARPHRD_CAN || gwj->dst.dev->header_ops)
858 goto put_src_dst_out; 856 goto put_src_dst_out;
859 857
860 gwj->limit_hops = limhops; 858 gwj->limit_hops = limhops;
diff --git a/net/compat.c b/net/compat.c
index 618c6a8a911b..dd32e34c1e2c 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -72,7 +72,7 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
72 __get_user(kmsg->msg_flags, &umsg->msg_flags)) 72 __get_user(kmsg->msg_flags, &umsg->msg_flags))
73 return -EFAULT; 73 return -EFAULT;
74 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage)) 74 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
75 return -EINVAL; 75 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
76 kmsg->msg_name = compat_ptr(tmp1); 76 kmsg->msg_name = compat_ptr(tmp1);
77 kmsg->msg_iov = compat_ptr(tmp2); 77 kmsg->msg_iov = compat_ptr(tmp2);
78 kmsg->msg_control = compat_ptr(tmp3); 78 kmsg->msg_control = compat_ptr(tmp3);
diff --git a/net/core/dev.c b/net/core/dev.c
index ba3b7ea5ebb3..cc9ab80581d7 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2145,30 +2145,42 @@ void __netif_schedule(struct Qdisc *q)
2145} 2145}
2146EXPORT_SYMBOL(__netif_schedule); 2146EXPORT_SYMBOL(__netif_schedule);
2147 2147
2148void dev_kfree_skb_irq(struct sk_buff *skb) 2148struct dev_kfree_skb_cb {
2149 enum skb_free_reason reason;
2150};
2151
2152static struct dev_kfree_skb_cb *get_kfree_skb_cb(const struct sk_buff *skb)
2153{
2154 return (struct dev_kfree_skb_cb *)skb->cb;
2155}
2156
2157void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason)
2149{ 2158{
2150 if (atomic_dec_and_test(&skb->users)) { 2159 unsigned long flags;
2151 struct softnet_data *sd;
2152 unsigned long flags;
2153 2160
2154 local_irq_save(flags); 2161 if (likely(atomic_read(&skb->users) == 1)) {
2155 sd = &__get_cpu_var(softnet_data); 2162 smp_rmb();
2156 skb->next = sd->completion_queue; 2163 atomic_set(&skb->users, 0);
2157 sd->completion_queue = skb; 2164 } else if (likely(!atomic_dec_and_test(&skb->users))) {
2158 raise_softirq_irqoff(NET_TX_SOFTIRQ); 2165 return;
2159 local_irq_restore(flags);
2160 } 2166 }
2167 get_kfree_skb_cb(skb)->reason = reason;
2168 local_irq_save(flags);
2169 skb->next = __this_cpu_read(softnet_data.completion_queue);
2170 __this_cpu_write(softnet_data.completion_queue, skb);
2171 raise_softirq_irqoff(NET_TX_SOFTIRQ);
2172 local_irq_restore(flags);
2161} 2173}
2162EXPORT_SYMBOL(dev_kfree_skb_irq); 2174EXPORT_SYMBOL(__dev_kfree_skb_irq);
2163 2175
2164void dev_kfree_skb_any(struct sk_buff *skb) 2176void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason)
2165{ 2177{
2166 if (in_irq() || irqs_disabled()) 2178 if (in_irq() || irqs_disabled())
2167 dev_kfree_skb_irq(skb); 2179 __dev_kfree_skb_irq(skb, reason);
2168 else 2180 else
2169 dev_kfree_skb(skb); 2181 dev_kfree_skb(skb);
2170} 2182}
2171EXPORT_SYMBOL(dev_kfree_skb_any); 2183EXPORT_SYMBOL(__dev_kfree_skb_any);
2172 2184
2173 2185
2174/** 2186/**
@@ -2442,13 +2454,8 @@ static void dev_gso_skb_destructor(struct sk_buff *skb)
2442{ 2454{
2443 struct dev_gso_cb *cb; 2455 struct dev_gso_cb *cb;
2444 2456
2445 do { 2457 kfree_skb_list(skb->next);
2446 struct sk_buff *nskb = skb->next; 2458 skb->next = NULL;
2447
2448 skb->next = nskb->next;
2449 nskb->next = NULL;
2450 kfree_skb(nskb);
2451 } while (skb->next);
2452 2459
2453 cb = DEV_GSO_CB(skb); 2460 cb = DEV_GSO_CB(skb);
2454 if (cb->destructor) 2461 if (cb->destructor)
@@ -2523,21 +2530,6 @@ netdev_features_t netif_skb_features(struct sk_buff *skb)
2523} 2530}
2524EXPORT_SYMBOL(netif_skb_features); 2531EXPORT_SYMBOL(netif_skb_features);
2525 2532
2526/*
2527 * Returns true if either:
2528 * 1. skb has frag_list and the device doesn't support FRAGLIST, or
2529 * 2. skb is fragmented and the device does not support SG.
2530 */
2531static inline int skb_needs_linearize(struct sk_buff *skb,
2532 netdev_features_t features)
2533{
2534 return skb_is_nonlinear(skb) &&
2535 ((skb_has_frag_list(skb) &&
2536 !(features & NETIF_F_FRAGLIST)) ||
2537 (skb_shinfo(skb)->nr_frags &&
2538 !(features & NETIF_F_SG)));
2539}
2540
2541int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, 2533int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
2542 struct netdev_queue *txq, void *accel_priv) 2534 struct netdev_queue *txq, void *accel_priv)
2543{ 2535{
@@ -3009,7 +3001,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
3009 } 3001 }
3010 3002
3011 skb_reset_network_header(skb); 3003 skb_reset_network_header(skb);
3012 if (!skb_get_rxhash(skb)) 3004 if (!skb_get_hash(skb))
3013 goto done; 3005 goto done;
3014 3006
3015 flow_table = rcu_dereference(rxqueue->rps_flow_table); 3007 flow_table = rcu_dereference(rxqueue->rps_flow_table);
@@ -3154,7 +3146,7 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen)
3154 rcu_read_lock(); 3146 rcu_read_lock();
3155 fl = rcu_dereference(sd->flow_limit); 3147 fl = rcu_dereference(sd->flow_limit);
3156 if (fl) { 3148 if (fl) {
3157 new_flow = skb_get_rxhash(skb) & (fl->num_buckets - 1); 3149 new_flow = skb_get_hash(skb) & (fl->num_buckets - 1);
3158 old_flow = fl->history[fl->history_head]; 3150 old_flow = fl->history[fl->history_head];
3159 fl->history[fl->history_head] = new_flow; 3151 fl->history[fl->history_head] = new_flow;
3160 3152
@@ -3306,7 +3298,10 @@ static void net_tx_action(struct softirq_action *h)
3306 clist = clist->next; 3298 clist = clist->next;
3307 3299
3308 WARN_ON(atomic_read(&skb->users)); 3300 WARN_ON(atomic_read(&skb->users));
3309 trace_kfree_skb(skb, net_tx_action); 3301 if (likely(get_kfree_skb_cb(skb)->reason == SKB_REASON_CONSUMED))
3302 trace_consume_skb(skb);
3303 else
3304 trace_kfree_skb(skb, net_tx_action);
3310 __kfree_skb(skb); 3305 __kfree_skb(skb);
3311 } 3306 }
3312 } 3307 }
@@ -3752,7 +3747,7 @@ static int napi_gro_complete(struct sk_buff *skb)
3752 if (ptype->type != type || !ptype->callbacks.gro_complete) 3747 if (ptype->type != type || !ptype->callbacks.gro_complete)
3753 continue; 3748 continue;
3754 3749
3755 err = ptype->callbacks.gro_complete(skb); 3750 err = ptype->callbacks.gro_complete(skb, 0);
3756 break; 3751 break;
3757 } 3752 }
3758 rcu_read_unlock(); 3753 rcu_read_unlock();
@@ -3818,6 +3813,23 @@ static void gro_list_prepare(struct napi_struct *napi, struct sk_buff *skb)
3818 } 3813 }
3819} 3814}
3820 3815
3816static void skb_gro_reset_offset(struct sk_buff *skb)
3817{
3818 const struct skb_shared_info *pinfo = skb_shinfo(skb);
3819 const skb_frag_t *frag0 = &pinfo->frags[0];
3820
3821 NAPI_GRO_CB(skb)->data_offset = 0;
3822 NAPI_GRO_CB(skb)->frag0 = NULL;
3823 NAPI_GRO_CB(skb)->frag0_len = 0;
3824
3825 if (skb_mac_header(skb) == skb_tail_pointer(skb) &&
3826 pinfo->nr_frags &&
3827 !PageHighMem(skb_frag_page(frag0))) {
3828 NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0);
3829 NAPI_GRO_CB(skb)->frag0_len = skb_frag_size(frag0);
3830 }
3831}
3832
3821static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 3833static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
3822{ 3834{
3823 struct sk_buff **pp = NULL; 3835 struct sk_buff **pp = NULL;
@@ -3833,6 +3845,7 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff
3833 if (skb_is_gso(skb) || skb_has_frag_list(skb)) 3845 if (skb_is_gso(skb) || skb_has_frag_list(skb))
3834 goto normal; 3846 goto normal;
3835 3847
3848 skb_gro_reset_offset(skb);
3836 gro_list_prepare(napi, skb); 3849 gro_list_prepare(napi, skb);
3837 3850
3838 rcu_read_lock(); 3851 rcu_read_lock();
@@ -3938,27 +3951,8 @@ static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
3938 return ret; 3951 return ret;
3939} 3952}
3940 3953
3941static void skb_gro_reset_offset(struct sk_buff *skb)
3942{
3943 const struct skb_shared_info *pinfo = skb_shinfo(skb);
3944 const skb_frag_t *frag0 = &pinfo->frags[0];
3945
3946 NAPI_GRO_CB(skb)->data_offset = 0;
3947 NAPI_GRO_CB(skb)->frag0 = NULL;
3948 NAPI_GRO_CB(skb)->frag0_len = 0;
3949
3950 if (skb_mac_header(skb) == skb_tail_pointer(skb) &&
3951 pinfo->nr_frags &&
3952 !PageHighMem(skb_frag_page(frag0))) {
3953 NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0);
3954 NAPI_GRO_CB(skb)->frag0_len = skb_frag_size(frag0);
3955 }
3956}
3957
3958gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 3954gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
3959{ 3955{
3960 skb_gro_reset_offset(skb);
3961
3962 return napi_skb_finish(dev_gro_receive(napi, skb), skb); 3956 return napi_skb_finish(dev_gro_receive(napi, skb), skb);
3963} 3957}
3964EXPORT_SYMBOL(napi_gro_receive); 3958EXPORT_SYMBOL(napi_gro_receive);
@@ -3981,8 +3975,7 @@ struct sk_buff *napi_get_frags(struct napi_struct *napi)
3981 3975
3982 if (!skb) { 3976 if (!skb) {
3983 skb = netdev_alloc_skb_ip_align(napi->dev, GRO_MAX_HEAD); 3977 skb = netdev_alloc_skb_ip_align(napi->dev, GRO_MAX_HEAD);
3984 if (skb) 3978 napi->skb = skb;
3985 napi->skb = skb;
3986 } 3979 }
3987 return skb; 3980 return skb;
3988} 3981}
@@ -3993,12 +3986,7 @@ static gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *
3993{ 3986{
3994 switch (ret) { 3987 switch (ret) {
3995 case GRO_NORMAL: 3988 case GRO_NORMAL:
3996 case GRO_HELD: 3989 if (netif_receive_skb(skb))
3997 skb->protocol = eth_type_trans(skb, skb->dev);
3998
3999 if (ret == GRO_HELD)
4000 skb_gro_pull(skb, -ETH_HLEN);
4001 else if (netif_receive_skb(skb))
4002 ret = GRO_DROP; 3990 ret = GRO_DROP;
4003 break; 3991 break;
4004 3992
@@ -4007,6 +3995,7 @@ static gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *
4007 napi_reuse_skb(napi, skb); 3995 napi_reuse_skb(napi, skb);
4008 break; 3996 break;
4009 3997
3998 case GRO_HELD:
4010 case GRO_MERGED: 3999 case GRO_MERGED:
4011 break; 4000 break;
4012 } 4001 }
@@ -4017,36 +4006,15 @@ static gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *
4017static struct sk_buff *napi_frags_skb(struct napi_struct *napi) 4006static struct sk_buff *napi_frags_skb(struct napi_struct *napi)
4018{ 4007{
4019 struct sk_buff *skb = napi->skb; 4008 struct sk_buff *skb = napi->skb;
4020 struct ethhdr *eth;
4021 unsigned int hlen;
4022 unsigned int off;
4023 4009
4024 napi->skb = NULL; 4010 napi->skb = NULL;
4025 4011
4026 skb_reset_mac_header(skb); 4012 if (unlikely(!pskb_may_pull(skb, sizeof(struct ethhdr)))) {
4027 skb_gro_reset_offset(skb); 4013 napi_reuse_skb(napi, skb);
4028 4014 return NULL;
4029 off = skb_gro_offset(skb);
4030 hlen = off + sizeof(*eth);
4031 eth = skb_gro_header_fast(skb, off);
4032 if (skb_gro_header_hard(skb, hlen)) {
4033 eth = skb_gro_header_slow(skb, hlen, off);
4034 if (unlikely(!eth)) {
4035 napi_reuse_skb(napi, skb);
4036 skb = NULL;
4037 goto out;
4038 }
4039 } 4015 }
4016 skb->protocol = eth_type_trans(skb, skb->dev);
4040 4017
4041 skb_gro_pull(skb, sizeof(*eth));
4042
4043 /*
4044 * This works because the only protocols we care about don't require
4045 * special handling. We'll fix it up properly at the end.
4046 */
4047 skb->protocol = eth->h_proto;
4048
4049out:
4050 return skb; 4018 return skb;
4051} 4019}
4052 4020
@@ -4062,7 +4030,7 @@ gro_result_t napi_gro_frags(struct napi_struct *napi)
4062EXPORT_SYMBOL(napi_gro_frags); 4030EXPORT_SYMBOL(napi_gro_frags);
4063 4031
4064/* 4032/*
4065 * net_rps_action sends any pending IPI's for rps. 4033 * net_rps_action_and_irq_enable sends any pending IPI's for rps.
4066 * Note: called with local irq disabled, but exits with local irq enabled. 4034 * Note: called with local irq disabled, but exits with local irq enabled.
4067 */ 4035 */
4068static void net_rps_action_and_irq_enable(struct softnet_data *sd) 4036static void net_rps_action_and_irq_enable(struct softnet_data *sd)
@@ -4267,17 +4235,10 @@ EXPORT_SYMBOL(netif_napi_add);
4267 4235
4268void netif_napi_del(struct napi_struct *napi) 4236void netif_napi_del(struct napi_struct *napi)
4269{ 4237{
4270 struct sk_buff *skb, *next;
4271
4272 list_del_init(&napi->dev_list); 4238 list_del_init(&napi->dev_list);
4273 napi_free_frags(napi); 4239 napi_free_frags(napi);
4274 4240
4275 for (skb = napi->gro_list; skb; skb = next) { 4241 kfree_skb_list(napi->gro_list);
4276 next = skb->next;
4277 skb->next = NULL;
4278 kfree_skb(skb);
4279 }
4280
4281 napi->gro_list = NULL; 4242 napi->gro_list = NULL;
4282 napi->gro_count = 0; 4243 napi->gro_count = 0;
4283} 4244}
@@ -4571,6 +4532,27 @@ void *netdev_lower_get_next_private_rcu(struct net_device *dev,
4571EXPORT_SYMBOL(netdev_lower_get_next_private_rcu); 4532EXPORT_SYMBOL(netdev_lower_get_next_private_rcu);
4572 4533
4573/** 4534/**
4535 * netdev_lower_get_first_private_rcu - Get the first ->private from the
4536 * lower neighbour list, RCU
4537 * variant
4538 * @dev: device
4539 *
4540 * Gets the first netdev_adjacent->private from the dev's lower neighbour
4541 * list. The caller must hold RCU read lock.
4542 */
4543void *netdev_lower_get_first_private_rcu(struct net_device *dev)
4544{
4545 struct netdev_adjacent *lower;
4546
4547 lower = list_first_or_null_rcu(&dev->adj_list.lower,
4548 struct netdev_adjacent, list);
4549 if (lower)
4550 return lower->private;
4551 return NULL;
4552}
4553EXPORT_SYMBOL(netdev_lower_get_first_private_rcu);
4554
4555/**
4574 * netdev_master_upper_dev_get_rcu - Get master upper device 4556 * netdev_master_upper_dev_get_rcu - Get master upper device
4575 * @dev: device 4557 * @dev: device
4576 * 4558 *
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index ec40a849fc42..bb504a919e33 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -186,47 +186,6 @@ static int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
186 return err; 186 return err;
187} 187}
188 188
189int __hw_addr_add_multiple(struct netdev_hw_addr_list *to_list,
190 struct netdev_hw_addr_list *from_list,
191 int addr_len, unsigned char addr_type)
192{
193 int err;
194 struct netdev_hw_addr *ha, *ha2;
195 unsigned char type;
196
197 list_for_each_entry(ha, &from_list->list, list) {
198 type = addr_type ? addr_type : ha->type;
199 err = __hw_addr_add(to_list, ha->addr, addr_len, type);
200 if (err)
201 goto unroll;
202 }
203 return 0;
204
205unroll:
206 list_for_each_entry(ha2, &from_list->list, list) {
207 if (ha2 == ha)
208 break;
209 type = addr_type ? addr_type : ha2->type;
210 __hw_addr_del(to_list, ha2->addr, addr_len, type);
211 }
212 return err;
213}
214EXPORT_SYMBOL(__hw_addr_add_multiple);
215
216void __hw_addr_del_multiple(struct netdev_hw_addr_list *to_list,
217 struct netdev_hw_addr_list *from_list,
218 int addr_len, unsigned char addr_type)
219{
220 struct netdev_hw_addr *ha;
221 unsigned char type;
222
223 list_for_each_entry(ha, &from_list->list, list) {
224 type = addr_type ? addr_type : ha->type;
225 __hw_addr_del(to_list, ha->addr, addr_len, type);
226 }
227}
228EXPORT_SYMBOL(__hw_addr_del_multiple);
229
230/* This function only works where there is a strict 1-1 relationship 189/* This function only works where there is a strict 1-1 relationship
231 * between source and destionation of they synch. If you ever need to 190 * between source and destionation of they synch. If you ever need to
232 * sync addresses to more then 1 destination, you need to use 191 * sync addresses to more then 1 destination, you need to use
@@ -264,7 +223,7 @@ void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
264} 223}
265EXPORT_SYMBOL(__hw_addr_unsync); 224EXPORT_SYMBOL(__hw_addr_unsync);
266 225
267void __hw_addr_flush(struct netdev_hw_addr_list *list) 226static void __hw_addr_flush(struct netdev_hw_addr_list *list)
268{ 227{
269 struct netdev_hw_addr *ha, *tmp; 228 struct netdev_hw_addr *ha, *tmp;
270 229
@@ -274,7 +233,6 @@ void __hw_addr_flush(struct netdev_hw_addr_list *list)
274 } 233 }
275 list->count = 0; 234 list->count = 0;
276} 235}
277EXPORT_SYMBOL(__hw_addr_flush);
278 236
279void __hw_addr_init(struct netdev_hw_addr_list *list) 237void __hw_addr_init(struct netdev_hw_addr_list *list)
280{ 238{
@@ -400,59 +358,6 @@ int dev_addr_del(struct net_device *dev, const unsigned char *addr,
400} 358}
401EXPORT_SYMBOL(dev_addr_del); 359EXPORT_SYMBOL(dev_addr_del);
402 360
403/**
404 * dev_addr_add_multiple - Add device addresses from another device
405 * @to_dev: device to which addresses will be added
406 * @from_dev: device from which addresses will be added
407 * @addr_type: address type - 0 means type will be used from from_dev
408 *
409 * Add device addresses of the one device to another.
410 **
411 * The caller must hold the rtnl_mutex.
412 */
413int dev_addr_add_multiple(struct net_device *to_dev,
414 struct net_device *from_dev,
415 unsigned char addr_type)
416{
417 int err;
418
419 ASSERT_RTNL();
420
421 if (from_dev->addr_len != to_dev->addr_len)
422 return -EINVAL;
423 err = __hw_addr_add_multiple(&to_dev->dev_addrs, &from_dev->dev_addrs,
424 to_dev->addr_len, addr_type);
425 if (!err)
426 call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev);
427 return err;
428}
429EXPORT_SYMBOL(dev_addr_add_multiple);
430
431/**
432 * dev_addr_del_multiple - Delete device addresses by another device
433 * @to_dev: device where the addresses will be deleted
434 * @from_dev: device supplying the addresses to be deleted
435 * @addr_type: address type - 0 means type will be used from from_dev
436 *
437 * Deletes addresses in to device by the list of addresses in from device.
438 *
439 * The caller must hold the rtnl_mutex.
440 */
441int dev_addr_del_multiple(struct net_device *to_dev,
442 struct net_device *from_dev,
443 unsigned char addr_type)
444{
445 ASSERT_RTNL();
446
447 if (from_dev->addr_len != to_dev->addr_len)
448 return -EINVAL;
449 __hw_addr_del_multiple(&to_dev->dev_addrs, &from_dev->dev_addrs,
450 to_dev->addr_len, addr_type);
451 call_netdevice_notifiers(NETDEV_CHANGEADDR, to_dev);
452 return 0;
453}
454EXPORT_SYMBOL(dev_addr_del_multiple);
455
456/* 361/*
457 * Unicast list handling functions 362 * Unicast list handling functions
458 */ 363 */
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 5b7d0e1d0664..cf999e09bcd2 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -327,6 +327,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
327 cmd == SIOCBRADDIF || 327 cmd == SIOCBRADDIF ||
328 cmd == SIOCBRDELIF || 328 cmd == SIOCBRDELIF ||
329 cmd == SIOCSHWTSTAMP || 329 cmd == SIOCSHWTSTAMP ||
330 cmd == SIOCGHWTSTAMP ||
330 cmd == SIOCWANDEV) { 331 cmd == SIOCWANDEV) {
331 err = -EOPNOTSUPP; 332 err = -EOPNOTSUPP;
332 if (ops->ndo_do_ioctl) { 333 if (ops->ndo_do_ioctl) {
@@ -546,6 +547,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
546 */ 547 */
547 default: 548 default:
548 if (cmd == SIOCWANDEV || 549 if (cmd == SIOCWANDEV ||
550 cmd == SIOCGHWTSTAMP ||
549 (cmd >= SIOCDEVPRIVATE && 551 (cmd >= SIOCDEVPRIVATE &&
550 cmd <= SIOCDEVPRIVATE + 15)) { 552 cmd <= SIOCDEVPRIVATE + 15)) {
551 dev_load(net, ifr.ifr_name); 553 dev_load(net, ifr.ifr_name);
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index 95897183226e..e70301eb7a4a 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -64,7 +64,6 @@ static struct genl_family net_drop_monitor_family = {
64 .hdrsize = 0, 64 .hdrsize = 0,
65 .name = "NET_DM", 65 .name = "NET_DM",
66 .version = 2, 66 .version = 2,
67 .maxattr = NET_DM_CMD_MAX,
68}; 67};
69 68
70static DEFINE_PER_CPU(struct per_cpu_dm_data, dm_cpu_data); 69static DEFINE_PER_CPU(struct per_cpu_dm_data, dm_cpu_data);
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index d6ef17322500..b324bfa3485c 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -202,12 +202,12 @@ static __always_inline u32 __flow_hash_1word(u32 a)
202} 202}
203 203
204/* 204/*
205 * __skb_get_rxhash: calculate a flow hash based on src/dst addresses 205 * __skb_get_hash: calculate a flow hash based on src/dst addresses
206 * and src/dst port numbers. Sets rxhash in skb to non-zero hash value 206 * and src/dst port numbers. Sets rxhash in skb to non-zero hash value
207 * on success, zero indicates no valid hash. Also, sets l4_rxhash in skb 207 * on success, zero indicates no valid hash. Also, sets l4_rxhash in skb
208 * if hash is a canonical 4-tuple hash over transport ports. 208 * if hash is a canonical 4-tuple hash over transport ports.
209 */ 209 */
210void __skb_get_rxhash(struct sk_buff *skb) 210void __skb_get_hash(struct sk_buff *skb)
211{ 211{
212 struct flow_keys keys; 212 struct flow_keys keys;
213 u32 hash; 213 u32 hash;
@@ -234,7 +234,7 @@ void __skb_get_rxhash(struct sk_buff *skb)
234 234
235 skb->rxhash = hash; 235 skb->rxhash = hash;
236} 236}
237EXPORT_SYMBOL(__skb_get_rxhash); 237EXPORT_SYMBOL(__skb_get_hash);
238 238
239/* 239/*
240 * Returns a Tx hash based on the given packet descriptor a Tx queues' number 240 * Returns a Tx hash based on the given packet descriptor a Tx queues' number
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index ca15f32821fb..a666740051dc 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -38,6 +38,8 @@
38#include <linux/random.h> 38#include <linux/random.h>
39#include <linux/string.h> 39#include <linux/string.h>
40#include <linux/log2.h> 40#include <linux/log2.h>
41#include <linux/inetdevice.h>
42#include <net/addrconf.h>
41 43
42#define DEBUG 44#define DEBUG
43#define NEIGH_DEBUG 1 45#define NEIGH_DEBUG 1
@@ -497,7 +499,7 @@ struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
497 goto out_neigh_release; 499 goto out_neigh_release;
498 } 500 }
499 501
500 n->confirmed = jiffies - (n->parms->base_reachable_time << 1); 502 n->confirmed = jiffies - (NEIGH_VAR(n->parms, BASE_REACHABLE_TIME) << 1);
501 503
502 write_lock_bh(&tbl->lock); 504 write_lock_bh(&tbl->lock);
503 nht = rcu_dereference_protected(tbl->nht, 505 nht = rcu_dereference_protected(tbl->nht,
@@ -776,7 +778,7 @@ static void neigh_periodic_work(struct work_struct *work)
776 tbl->last_rand = jiffies; 778 tbl->last_rand = jiffies;
777 for (p = &tbl->parms; p; p = p->next) 779 for (p = &tbl->parms; p; p = p->next)
778 p->reachable_time = 780 p->reachable_time =
779 neigh_rand_reach_time(p->base_reachable_time); 781 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
780 } 782 }
781 783
782 for (i = 0 ; i < (1 << nht->hash_shift); i++) { 784 for (i = 0 ; i < (1 << nht->hash_shift); i++) {
@@ -799,7 +801,7 @@ static void neigh_periodic_work(struct work_struct *work)
799 801
800 if (atomic_read(&n->refcnt) == 1 && 802 if (atomic_read(&n->refcnt) == 1 &&
801 (state == NUD_FAILED || 803 (state == NUD_FAILED ||
802 time_after(jiffies, n->used + n->parms->gc_staletime))) { 804 time_after(jiffies, n->used + NEIGH_VAR(n->parms, GC_STALETIME)))) {
803 *np = n->next; 805 *np = n->next;
804 n->dead = 1; 806 n->dead = 1;
805 write_unlock(&n->lock); 807 write_unlock(&n->lock);
@@ -822,12 +824,12 @@ next_elt:
822 lockdep_is_held(&tbl->lock)); 824 lockdep_is_held(&tbl->lock));
823 } 825 }
824out: 826out:
825 /* Cycle through all hash buckets every base_reachable_time/2 ticks. 827 /* Cycle through all hash buckets every BASE_REACHABLE_TIME/2 ticks.
826 * ARP entry timeouts range from 1/2 base_reachable_time to 3/2 828 * ARP entry timeouts range from 1/2 BASE_REACHABLE_TIME to 3/2
827 * base_reachable_time. 829 * BASE_REACHABLE_TIME.
828 */ 830 */
829 schedule_delayed_work(&tbl->gc_work, 831 schedule_delayed_work(&tbl->gc_work,
830 tbl->parms.base_reachable_time >> 1); 832 NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME) >> 1);
831 write_unlock_bh(&tbl->lock); 833 write_unlock_bh(&tbl->lock);
832} 834}
833 835
@@ -835,8 +837,9 @@ static __inline__ int neigh_max_probes(struct neighbour *n)
835{ 837{
836 struct neigh_parms *p = n->parms; 838 struct neigh_parms *p = n->parms;
837 return (n->nud_state & NUD_PROBE) ? 839 return (n->nud_state & NUD_PROBE) ?
838 p->ucast_probes : 840 NEIGH_VAR(p, UCAST_PROBES) :
839 p->ucast_probes + p->app_probes + p->mcast_probes; 841 NEIGH_VAR(p, UCAST_PROBES) + NEIGH_VAR(p, APP_PROBES) +
842 NEIGH_VAR(p, MCAST_PROBES);
840} 843}
841 844
842static void neigh_invalidate(struct neighbour *neigh) 845static void neigh_invalidate(struct neighbour *neigh)
@@ -901,12 +904,13 @@ static void neigh_timer_handler(unsigned long arg)
901 neigh_dbg(2, "neigh %p is still alive\n", neigh); 904 neigh_dbg(2, "neigh %p is still alive\n", neigh);
902 next = neigh->confirmed + neigh->parms->reachable_time; 905 next = neigh->confirmed + neigh->parms->reachable_time;
903 } else if (time_before_eq(now, 906 } else if (time_before_eq(now,
904 neigh->used + neigh->parms->delay_probe_time)) { 907 neigh->used +
908 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {
905 neigh_dbg(2, "neigh %p is delayed\n", neigh); 909 neigh_dbg(2, "neigh %p is delayed\n", neigh);
906 neigh->nud_state = NUD_DELAY; 910 neigh->nud_state = NUD_DELAY;
907 neigh->updated = jiffies; 911 neigh->updated = jiffies;
908 neigh_suspect(neigh); 912 neigh_suspect(neigh);
909 next = now + neigh->parms->delay_probe_time; 913 next = now + NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME);
910 } else { 914 } else {
911 neigh_dbg(2, "neigh %p is suspected\n", neigh); 915 neigh_dbg(2, "neigh %p is suspected\n", neigh);
912 neigh->nud_state = NUD_STALE; 916 neigh->nud_state = NUD_STALE;
@@ -916,7 +920,8 @@ static void neigh_timer_handler(unsigned long arg)
916 } 920 }
917 } else if (state & NUD_DELAY) { 921 } else if (state & NUD_DELAY) {
918 if (time_before_eq(now, 922 if (time_before_eq(now,
919 neigh->confirmed + neigh->parms->delay_probe_time)) { 923 neigh->confirmed +
924 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME))) {
920 neigh_dbg(2, "neigh %p is now reachable\n", neigh); 925 neigh_dbg(2, "neigh %p is now reachable\n", neigh);
921 neigh->nud_state = NUD_REACHABLE; 926 neigh->nud_state = NUD_REACHABLE;
922 neigh->updated = jiffies; 927 neigh->updated = jiffies;
@@ -928,11 +933,11 @@ static void neigh_timer_handler(unsigned long arg)
928 neigh->nud_state = NUD_PROBE; 933 neigh->nud_state = NUD_PROBE;
929 neigh->updated = jiffies; 934 neigh->updated = jiffies;
930 atomic_set(&neigh->probes, 0); 935 atomic_set(&neigh->probes, 0);
931 next = now + neigh->parms->retrans_time; 936 next = now + NEIGH_VAR(neigh->parms, RETRANS_TIME);
932 } 937 }
933 } else { 938 } else {
934 /* NUD_PROBE|NUD_INCOMPLETE */ 939 /* NUD_PROBE|NUD_INCOMPLETE */
935 next = now + neigh->parms->retrans_time; 940 next = now + NEIGH_VAR(neigh->parms, RETRANS_TIME);
936 } 941 }
937 942
938 if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) && 943 if ((neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) &&
@@ -973,13 +978,16 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
973 goto out_unlock_bh; 978 goto out_unlock_bh;
974 979
975 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) { 980 if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {
976 if (neigh->parms->mcast_probes + neigh->parms->app_probes) { 981 if (NEIGH_VAR(neigh->parms, MCAST_PROBES) +
982 NEIGH_VAR(neigh->parms, APP_PROBES)) {
977 unsigned long next, now = jiffies; 983 unsigned long next, now = jiffies;
978 984
979 atomic_set(&neigh->probes, neigh->parms->ucast_probes); 985 atomic_set(&neigh->probes,
986 NEIGH_VAR(neigh->parms, UCAST_PROBES));
980 neigh->nud_state = NUD_INCOMPLETE; 987 neigh->nud_state = NUD_INCOMPLETE;
981 neigh->updated = now; 988 neigh->updated = now;
982 next = now + max(neigh->parms->retrans_time, HZ/2); 989 next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME),
990 HZ/2);
983 neigh_add_timer(neigh, next); 991 neigh_add_timer(neigh, next);
984 immediate_probe = true; 992 immediate_probe = true;
985 } else { 993 } else {
@@ -994,14 +1002,14 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
994 neigh_dbg(2, "neigh %p is delayed\n", neigh); 1002 neigh_dbg(2, "neigh %p is delayed\n", neigh);
995 neigh->nud_state = NUD_DELAY; 1003 neigh->nud_state = NUD_DELAY;
996 neigh->updated = jiffies; 1004 neigh->updated = jiffies;
997 neigh_add_timer(neigh, 1005 neigh_add_timer(neigh, jiffies +
998 jiffies + neigh->parms->delay_probe_time); 1006 NEIGH_VAR(neigh->parms, DELAY_PROBE_TIME));
999 } 1007 }
1000 1008
1001 if (neigh->nud_state == NUD_INCOMPLETE) { 1009 if (neigh->nud_state == NUD_INCOMPLETE) {
1002 if (skb) { 1010 if (skb) {
1003 while (neigh->arp_queue_len_bytes + skb->truesize > 1011 while (neigh->arp_queue_len_bytes + skb->truesize >
1004 neigh->parms->queue_len_bytes) { 1012 NEIGH_VAR(neigh->parms, QUEUE_LEN_BYTES)) {
1005 struct sk_buff *buff; 1013 struct sk_buff *buff;
1006 1014
1007 buff = __skb_dequeue(&neigh->arp_queue); 1015 buff = __skb_dequeue(&neigh->arp_queue);
@@ -1161,6 +1169,7 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
1161 neigh->parms->reachable_time : 1169 neigh->parms->reachable_time :
1162 0))); 1170 0)));
1163 neigh->nud_state = new; 1171 neigh->nud_state = new;
1172 notify = 1;
1164 } 1173 }
1165 1174
1166 if (lladdr != neigh->ha) { 1175 if (lladdr != neigh->ha) {
@@ -1170,7 +1179,7 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
1170 neigh_update_hhs(neigh); 1179 neigh_update_hhs(neigh);
1171 if (!(new & NUD_CONNECTED)) 1180 if (!(new & NUD_CONNECTED))
1172 neigh->confirmed = jiffies - 1181 neigh->confirmed = jiffies -
1173 (neigh->parms->base_reachable_time << 1); 1182 (NEIGH_VAR(neigh->parms, BASE_REACHABLE_TIME) << 1);
1174 notify = 1; 1183 notify = 1;
1175 } 1184 }
1176 if (new == old) 1185 if (new == old)
@@ -1230,6 +1239,21 @@ out:
1230} 1239}
1231EXPORT_SYMBOL(neigh_update); 1240EXPORT_SYMBOL(neigh_update);
1232 1241
1242/* Update the neigh to listen temporarily for probe responses, even if it is
1243 * in a NUD_FAILED state. The caller has to hold neigh->lock for writing.
1244 */
1245void __neigh_set_probe_once(struct neighbour *neigh)
1246{
1247 neigh->updated = jiffies;
1248 if (!(neigh->nud_state & NUD_FAILED))
1249 return;
1250 neigh->nud_state = NUD_PROBE;
1251 atomic_set(&neigh->probes, NEIGH_VAR(neigh->parms, UCAST_PROBES));
1252 neigh_add_timer(neigh,
1253 jiffies + NEIGH_VAR(neigh->parms, RETRANS_TIME));
1254}
1255EXPORT_SYMBOL(__neigh_set_probe_once);
1256
1233struct neighbour *neigh_event_ns(struct neigh_table *tbl, 1257struct neighbour *neigh_event_ns(struct neigh_table *tbl,
1234 u8 *lladdr, void *saddr, 1258 u8 *lladdr, void *saddr,
1235 struct net_device *dev) 1259 struct net_device *dev)
@@ -1391,9 +1415,10 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
1391 struct sk_buff *skb) 1415 struct sk_buff *skb)
1392{ 1416{
1393 unsigned long now = jiffies; 1417 unsigned long now = jiffies;
1394 unsigned long sched_next = now + (net_random() % p->proxy_delay); 1418 unsigned long sched_next = now + (net_random() %
1419 NEIGH_VAR(p, PROXY_DELAY));
1395 1420
1396 if (tbl->proxy_queue.qlen > p->proxy_qlen) { 1421 if (tbl->proxy_queue.qlen > NEIGH_VAR(p, PROXY_QLEN)) {
1397 kfree_skb(skb); 1422 kfree_skb(skb);
1398 return; 1423 return;
1399 } 1424 }
@@ -1440,7 +1465,7 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
1440 p->tbl = tbl; 1465 p->tbl = tbl;
1441 atomic_set(&p->refcnt, 1); 1466 atomic_set(&p->refcnt, 1);
1442 p->reachable_time = 1467 p->reachable_time =
1443 neigh_rand_reach_time(p->base_reachable_time); 1468 neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME));
1444 dev_hold(dev); 1469 dev_hold(dev);
1445 p->dev = dev; 1470 p->dev = dev;
1446 write_pnet(&p->net, hold_net(net)); 1471 write_pnet(&p->net, hold_net(net));
@@ -1457,6 +1482,8 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev,
1457 p->next = tbl->parms.next; 1482 p->next = tbl->parms.next;
1458 tbl->parms.next = p; 1483 tbl->parms.next = p;
1459 write_unlock_bh(&tbl->lock); 1484 write_unlock_bh(&tbl->lock);
1485
1486 neigh_parms_data_state_cleanall(p);
1460 } 1487 }
1461 return p; 1488 return p;
1462} 1489}
@@ -1509,7 +1536,7 @@ static void neigh_table_init_no_netlink(struct neigh_table *tbl)
1509 write_pnet(&tbl->parms.net, &init_net); 1536 write_pnet(&tbl->parms.net, &init_net);
1510 atomic_set(&tbl->parms.refcnt, 1); 1537 atomic_set(&tbl->parms.refcnt, 1);
1511 tbl->parms.reachable_time = 1538 tbl->parms.reachable_time =
1512 neigh_rand_reach_time(tbl->parms.base_reachable_time); 1539 neigh_rand_reach_time(NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME));
1513 1540
1514 tbl->stats = alloc_percpu(struct neigh_statistics); 1541 tbl->stats = alloc_percpu(struct neigh_statistics);
1515 if (!tbl->stats) 1542 if (!tbl->stats)
@@ -1777,24 +1804,32 @@ static int neightbl_fill_parms(struct sk_buff *skb, struct neigh_parms *parms)
1777 if ((parms->dev && 1804 if ((parms->dev &&
1778 nla_put_u32(skb, NDTPA_IFINDEX, parms->dev->ifindex)) || 1805 nla_put_u32(skb, NDTPA_IFINDEX, parms->dev->ifindex)) ||
1779 nla_put_u32(skb, NDTPA_REFCNT, atomic_read(&parms->refcnt)) || 1806 nla_put_u32(skb, NDTPA_REFCNT, atomic_read(&parms->refcnt)) ||
1780 nla_put_u32(skb, NDTPA_QUEUE_LENBYTES, parms->queue_len_bytes) || 1807 nla_put_u32(skb, NDTPA_QUEUE_LENBYTES,
1808 NEIGH_VAR(parms, QUEUE_LEN_BYTES)) ||
1781 /* approximative value for deprecated QUEUE_LEN (in packets) */ 1809 /* approximative value for deprecated QUEUE_LEN (in packets) */
1782 nla_put_u32(skb, NDTPA_QUEUE_LEN, 1810 nla_put_u32(skb, NDTPA_QUEUE_LEN,
1783 parms->queue_len_bytes / SKB_TRUESIZE(ETH_FRAME_LEN)) || 1811 NEIGH_VAR(parms, QUEUE_LEN_BYTES) / SKB_TRUESIZE(ETH_FRAME_LEN)) ||
1784 nla_put_u32(skb, NDTPA_PROXY_QLEN, parms->proxy_qlen) || 1812 nla_put_u32(skb, NDTPA_PROXY_QLEN, NEIGH_VAR(parms, PROXY_QLEN)) ||
1785 nla_put_u32(skb, NDTPA_APP_PROBES, parms->app_probes) || 1813 nla_put_u32(skb, NDTPA_APP_PROBES, NEIGH_VAR(parms, APP_PROBES)) ||
1786 nla_put_u32(skb, NDTPA_UCAST_PROBES, parms->ucast_probes) || 1814 nla_put_u32(skb, NDTPA_UCAST_PROBES,
1787 nla_put_u32(skb, NDTPA_MCAST_PROBES, parms->mcast_probes) || 1815 NEIGH_VAR(parms, UCAST_PROBES)) ||
1816 nla_put_u32(skb, NDTPA_MCAST_PROBES,
1817 NEIGH_VAR(parms, MCAST_PROBES)) ||
1788 nla_put_msecs(skb, NDTPA_REACHABLE_TIME, parms->reachable_time) || 1818 nla_put_msecs(skb, NDTPA_REACHABLE_TIME, parms->reachable_time) ||
1789 nla_put_msecs(skb, NDTPA_BASE_REACHABLE_TIME, 1819 nla_put_msecs(skb, NDTPA_BASE_REACHABLE_TIME,
1790 parms->base_reachable_time) || 1820 NEIGH_VAR(parms, BASE_REACHABLE_TIME)) ||
1791 nla_put_msecs(skb, NDTPA_GC_STALETIME, parms->gc_staletime) || 1821 nla_put_msecs(skb, NDTPA_GC_STALETIME,
1822 NEIGH_VAR(parms, GC_STALETIME)) ||
1792 nla_put_msecs(skb, NDTPA_DELAY_PROBE_TIME, 1823 nla_put_msecs(skb, NDTPA_DELAY_PROBE_TIME,
1793 parms->delay_probe_time) || 1824 NEIGH_VAR(parms, DELAY_PROBE_TIME)) ||
1794 nla_put_msecs(skb, NDTPA_RETRANS_TIME, parms->retrans_time) || 1825 nla_put_msecs(skb, NDTPA_RETRANS_TIME,
1795 nla_put_msecs(skb, NDTPA_ANYCAST_DELAY, parms->anycast_delay) || 1826 NEIGH_VAR(parms, RETRANS_TIME)) ||
1796 nla_put_msecs(skb, NDTPA_PROXY_DELAY, parms->proxy_delay) || 1827 nla_put_msecs(skb, NDTPA_ANYCAST_DELAY,
1797 nla_put_msecs(skb, NDTPA_LOCKTIME, parms->locktime)) 1828 NEIGH_VAR(parms, ANYCAST_DELAY)) ||
1829 nla_put_msecs(skb, NDTPA_PROXY_DELAY,
1830 NEIGH_VAR(parms, PROXY_DELAY)) ||
1831 nla_put_msecs(skb, NDTPA_LOCKTIME,
1832 NEIGH_VAR(parms, LOCKTIME)))
1798 goto nla_put_failure; 1833 goto nla_put_failure;
1799 return nla_nest_end(skb, nest); 1834 return nla_nest_end(skb, nest);
1800 1835
@@ -2010,44 +2045,54 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh)
2010 2045
2011 switch (i) { 2046 switch (i) {
2012 case NDTPA_QUEUE_LEN: 2047 case NDTPA_QUEUE_LEN:
2013 p->queue_len_bytes = nla_get_u32(tbp[i]) * 2048 NEIGH_VAR_SET(p, QUEUE_LEN_BYTES,
2014 SKB_TRUESIZE(ETH_FRAME_LEN); 2049 nla_get_u32(tbp[i]) *
2050 SKB_TRUESIZE(ETH_FRAME_LEN));
2015 break; 2051 break;
2016 case NDTPA_QUEUE_LENBYTES: 2052 case NDTPA_QUEUE_LENBYTES:
2017 p->queue_len_bytes = nla_get_u32(tbp[i]); 2053 NEIGH_VAR_SET(p, QUEUE_LEN_BYTES,
2054 nla_get_u32(tbp[i]));
2018 break; 2055 break;
2019 case NDTPA_PROXY_QLEN: 2056 case NDTPA_PROXY_QLEN:
2020 p->proxy_qlen = nla_get_u32(tbp[i]); 2057 NEIGH_VAR_SET(p, PROXY_QLEN,
2058 nla_get_u32(tbp[i]));
2021 break; 2059 break;
2022 case NDTPA_APP_PROBES: 2060 case NDTPA_APP_PROBES:
2023 p->app_probes = nla_get_u32(tbp[i]); 2061 NEIGH_VAR_SET(p, APP_PROBES,
2062 nla_get_u32(tbp[i]));
2024 break; 2063 break;
2025 case NDTPA_UCAST_PROBES: 2064 case NDTPA_UCAST_PROBES:
2026 p->ucast_probes = nla_get_u32(tbp[i]); 2065 NEIGH_VAR_SET(p, UCAST_PROBES,
2066 nla_get_u32(tbp[i]));
2027 break; 2067 break;
2028 case NDTPA_MCAST_PROBES: 2068 case NDTPA_MCAST_PROBES:
2029 p->mcast_probes = nla_get_u32(tbp[i]); 2069 NEIGH_VAR_SET(p, MCAST_PROBES,
2070 nla_get_u32(tbp[i]));
2030 break; 2071 break;
2031 case NDTPA_BASE_REACHABLE_TIME: 2072 case NDTPA_BASE_REACHABLE_TIME:
2032 p->base_reachable_time = nla_get_msecs(tbp[i]); 2073 NEIGH_VAR_SET(p, BASE_REACHABLE_TIME,
2074 nla_get_msecs(tbp[i]));
2033 break; 2075 break;
2034 case NDTPA_GC_STALETIME: 2076 case NDTPA_GC_STALETIME:
2035 p->gc_staletime = nla_get_msecs(tbp[i]); 2077 NEIGH_VAR_SET(p, GC_STALETIME,
2078 nla_get_msecs(tbp[i]));
2036 break; 2079 break;
2037 case NDTPA_DELAY_PROBE_TIME: 2080 case NDTPA_DELAY_PROBE_TIME:
2038 p->delay_probe_time = nla_get_msecs(tbp[i]); 2081 NEIGH_VAR_SET(p, DELAY_PROBE_TIME,
2082 nla_get_msecs(tbp[i]));
2039 break; 2083 break;
2040 case NDTPA_RETRANS_TIME: 2084 case NDTPA_RETRANS_TIME:
2041 p->retrans_time = nla_get_msecs(tbp[i]); 2085 NEIGH_VAR_SET(p, RETRANS_TIME,
2086 nla_get_msecs(tbp[i]));
2042 break; 2087 break;
2043 case NDTPA_ANYCAST_DELAY: 2088 case NDTPA_ANYCAST_DELAY:
2044 p->anycast_delay = nla_get_msecs(tbp[i]); 2089 NEIGH_VAR_SET(p, ANYCAST_DELAY, nla_get_msecs(tbp[i]));
2045 break; 2090 break;
2046 case NDTPA_PROXY_DELAY: 2091 case NDTPA_PROXY_DELAY:
2047 p->proxy_delay = nla_get_msecs(tbp[i]); 2092 NEIGH_VAR_SET(p, PROXY_DELAY, nla_get_msecs(tbp[i]));
2048 break; 2093 break;
2049 case NDTPA_LOCKTIME: 2094 case NDTPA_LOCKTIME:
2050 p->locktime = nla_get_msecs(tbp[i]); 2095 NEIGH_VAR_SET(p, LOCKTIME, nla_get_msecs(tbp[i]));
2051 break; 2096 break;
2052 } 2097 }
2053 } 2098 }
@@ -2788,133 +2833,167 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
2788 return ret; 2833 return ret;
2789} 2834}
2790 2835
2791enum { 2836static struct neigh_parms *neigh_get_dev_parms_rcu(struct net_device *dev,
2792 NEIGH_VAR_MCAST_PROBE, 2837 int family)
2793 NEIGH_VAR_UCAST_PROBE, 2838{
2794 NEIGH_VAR_APP_PROBE, 2839 switch (family) {
2795 NEIGH_VAR_RETRANS_TIME, 2840 case AF_INET:
2796 NEIGH_VAR_BASE_REACHABLE_TIME, 2841 return __in_dev_arp_parms_get_rcu(dev);
2797 NEIGH_VAR_DELAY_PROBE_TIME, 2842 case AF_INET6:
2798 NEIGH_VAR_GC_STALETIME, 2843 return __in6_dev_nd_parms_get_rcu(dev);
2799 NEIGH_VAR_QUEUE_LEN, 2844 }
2800 NEIGH_VAR_QUEUE_LEN_BYTES, 2845 return NULL;
2801 NEIGH_VAR_PROXY_QLEN, 2846}
2802 NEIGH_VAR_ANYCAST_DELAY, 2847
2803 NEIGH_VAR_PROXY_DELAY, 2848static void neigh_copy_dflt_parms(struct net *net, struct neigh_parms *p,
2804 NEIGH_VAR_LOCKTIME, 2849 int index)
2805 NEIGH_VAR_RETRANS_TIME_MS, 2850{
2806 NEIGH_VAR_BASE_REACHABLE_TIME_MS, 2851 struct net_device *dev;
2807 NEIGH_VAR_GC_INTERVAL, 2852 int family = neigh_parms_family(p);
2808 NEIGH_VAR_GC_THRESH1, 2853
2809 NEIGH_VAR_GC_THRESH2, 2854 rcu_read_lock();
2810 NEIGH_VAR_GC_THRESH3, 2855 for_each_netdev_rcu(net, dev) {
2811 NEIGH_VAR_MAX 2856 struct neigh_parms *dst_p =
2812}; 2857 neigh_get_dev_parms_rcu(dev, family);
2858
2859 if (dst_p && !test_bit(index, dst_p->data_state))
2860 dst_p->data[index] = p->data[index];
2861 }
2862 rcu_read_unlock();
2863}
2864
2865static void neigh_proc_update(struct ctl_table *ctl, int write)
2866{
2867 struct net_device *dev = ctl->extra1;
2868 struct neigh_parms *p = ctl->extra2;
2869 struct net *net = neigh_parms_net(p);
2870 int index = (int *) ctl->data - p->data;
2871
2872 if (!write)
2873 return;
2874
2875 set_bit(index, p->data_state);
2876 if (!dev) /* NULL dev means this is default value */
2877 neigh_copy_dflt_parms(net, p, index);
2878}
2879
2880static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
2881 void __user *buffer,
2882 size_t *lenp, loff_t *ppos)
2883{
2884 struct ctl_table tmp = *ctl;
2885 int ret;
2886
2887 tmp.extra1 = &zero;
2888 tmp.extra2 = &int_max;
2889
2890 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
2891 neigh_proc_update(ctl, write);
2892 return ret;
2893}
2894
2895int neigh_proc_dointvec(struct ctl_table *ctl, int write,
2896 void __user *buffer, size_t *lenp, loff_t *ppos)
2897{
2898 int ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
2899
2900 neigh_proc_update(ctl, write);
2901 return ret;
2902}
2903EXPORT_SYMBOL(neigh_proc_dointvec);
2904
2905int neigh_proc_dointvec_jiffies(struct ctl_table *ctl, int write,
2906 void __user *buffer,
2907 size_t *lenp, loff_t *ppos)
2908{
2909 int ret = proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos);
2910
2911 neigh_proc_update(ctl, write);
2912 return ret;
2913}
2914EXPORT_SYMBOL(neigh_proc_dointvec_jiffies);
2915
2916static int neigh_proc_dointvec_userhz_jiffies(struct ctl_table *ctl, int write,
2917 void __user *buffer,
2918 size_t *lenp, loff_t *ppos)
2919{
2920 int ret = proc_dointvec_userhz_jiffies(ctl, write, buffer, lenp, ppos);
2921
2922 neigh_proc_update(ctl, write);
2923 return ret;
2924}
2925
2926int neigh_proc_dointvec_ms_jiffies(struct ctl_table *ctl, int write,
2927 void __user *buffer,
2928 size_t *lenp, loff_t *ppos)
2929{
2930 int ret = proc_dointvec_ms_jiffies(ctl, write, buffer, lenp, ppos);
2931
2932 neigh_proc_update(ctl, write);
2933 return ret;
2934}
2935EXPORT_SYMBOL(neigh_proc_dointvec_ms_jiffies);
2936
2937static int neigh_proc_dointvec_unres_qlen(struct ctl_table *ctl, int write,
2938 void __user *buffer,
2939 size_t *lenp, loff_t *ppos)
2940{
2941 int ret = proc_unres_qlen(ctl, write, buffer, lenp, ppos);
2942
2943 neigh_proc_update(ctl, write);
2944 return ret;
2945}
2946
2947#define NEIGH_PARMS_DATA_OFFSET(index) \
2948 (&((struct neigh_parms *) 0)->data[index])
2949
2950#define NEIGH_SYSCTL_ENTRY(attr, data_attr, name, mval, proc) \
2951 [NEIGH_VAR_ ## attr] = { \
2952 .procname = name, \
2953 .data = NEIGH_PARMS_DATA_OFFSET(NEIGH_VAR_ ## data_attr), \
2954 .maxlen = sizeof(int), \
2955 .mode = mval, \
2956 .proc_handler = proc, \
2957 }
2958
2959#define NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(attr, name) \
2960 NEIGH_SYSCTL_ENTRY(attr, attr, name, 0644, neigh_proc_dointvec_zero_intmax)
2961
2962#define NEIGH_SYSCTL_JIFFIES_ENTRY(attr, name) \
2963 NEIGH_SYSCTL_ENTRY(attr, attr, name, 0644, neigh_proc_dointvec_jiffies)
2964
2965#define NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(attr, name) \
2966 NEIGH_SYSCTL_ENTRY(attr, attr, name, 0644, neigh_proc_dointvec_userhz_jiffies)
2967
2968#define NEIGH_SYSCTL_MS_JIFFIES_ENTRY(attr, name) \
2969 NEIGH_SYSCTL_ENTRY(attr, attr, name, 0644, neigh_proc_dointvec_ms_jiffies)
2970
2971#define NEIGH_SYSCTL_MS_JIFFIES_REUSED_ENTRY(attr, data_attr, name) \
2972 NEIGH_SYSCTL_ENTRY(attr, data_attr, name, 0644, neigh_proc_dointvec_ms_jiffies)
2973
2974#define NEIGH_SYSCTL_UNRES_QLEN_REUSED_ENTRY(attr, data_attr, name) \
2975 NEIGH_SYSCTL_ENTRY(attr, data_attr, name, 0644, neigh_proc_dointvec_unres_qlen)
2813 2976
2814static struct neigh_sysctl_table { 2977static struct neigh_sysctl_table {
2815 struct ctl_table_header *sysctl_header; 2978 struct ctl_table_header *sysctl_header;
2816 struct ctl_table neigh_vars[NEIGH_VAR_MAX + 1]; 2979 struct ctl_table neigh_vars[NEIGH_VAR_MAX + 1];
2817} neigh_sysctl_template __read_mostly = { 2980} neigh_sysctl_template __read_mostly = {
2818 .neigh_vars = { 2981 .neigh_vars = {
2819 [NEIGH_VAR_MCAST_PROBE] = { 2982 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(MCAST_PROBES, "mcast_solicit"),
2820 .procname = "mcast_solicit", 2983 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(UCAST_PROBES, "ucast_solicit"),
2821 .maxlen = sizeof(int), 2984 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(APP_PROBES, "app_solicit"),
2822 .mode = 0644, 2985 NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(RETRANS_TIME, "retrans_time"),
2823 .extra1 = &zero, 2986 NEIGH_SYSCTL_JIFFIES_ENTRY(BASE_REACHABLE_TIME, "base_reachable_time"),
2824 .extra2 = &int_max, 2987 NEIGH_SYSCTL_JIFFIES_ENTRY(DELAY_PROBE_TIME, "delay_first_probe_time"),
2825 .proc_handler = proc_dointvec_minmax, 2988 NEIGH_SYSCTL_JIFFIES_ENTRY(GC_STALETIME, "gc_stale_time"),
2826 }, 2989 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(QUEUE_LEN_BYTES, "unres_qlen_bytes"),
2827 [NEIGH_VAR_UCAST_PROBE] = { 2990 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(PROXY_QLEN, "proxy_qlen"),
2828 .procname = "ucast_solicit", 2991 NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(ANYCAST_DELAY, "anycast_delay"),
2829 .maxlen = sizeof(int), 2992 NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(PROXY_DELAY, "proxy_delay"),
2830 .mode = 0644, 2993 NEIGH_SYSCTL_USERHZ_JIFFIES_ENTRY(LOCKTIME, "locktime"),
2831 .extra1 = &zero, 2994 NEIGH_SYSCTL_UNRES_QLEN_REUSED_ENTRY(QUEUE_LEN, QUEUE_LEN_BYTES, "unres_qlen"),
2832 .extra2 = &int_max, 2995 NEIGH_SYSCTL_MS_JIFFIES_REUSED_ENTRY(RETRANS_TIME_MS, RETRANS_TIME, "retrans_time_ms"),
2833 .proc_handler = proc_dointvec_minmax, 2996 NEIGH_SYSCTL_MS_JIFFIES_REUSED_ENTRY(BASE_REACHABLE_TIME_MS, BASE_REACHABLE_TIME, "base_reachable_time_ms"),
2834 },
2835 [NEIGH_VAR_APP_PROBE] = {
2836 .procname = "app_solicit",
2837 .maxlen = sizeof(int),
2838 .mode = 0644,
2839 .extra1 = &zero,
2840 .extra2 = &int_max,
2841 .proc_handler = proc_dointvec_minmax,
2842 },
2843 [NEIGH_VAR_RETRANS_TIME] = {
2844 .procname = "retrans_time",
2845 .maxlen = sizeof(int),
2846 .mode = 0644,
2847 .proc_handler = proc_dointvec_userhz_jiffies,
2848 },
2849 [NEIGH_VAR_BASE_REACHABLE_TIME] = {
2850 .procname = "base_reachable_time",
2851 .maxlen = sizeof(int),
2852 .mode = 0644,
2853 .proc_handler = proc_dointvec_jiffies,
2854 },
2855 [NEIGH_VAR_DELAY_PROBE_TIME] = {
2856 .procname = "delay_first_probe_time",
2857 .maxlen = sizeof(int),
2858 .mode = 0644,
2859 .proc_handler = proc_dointvec_jiffies,
2860 },
2861 [NEIGH_VAR_GC_STALETIME] = {
2862 .procname = "gc_stale_time",
2863 .maxlen = sizeof(int),
2864 .mode = 0644,
2865 .proc_handler = proc_dointvec_jiffies,
2866 },
2867 [NEIGH_VAR_QUEUE_LEN] = {
2868 .procname = "unres_qlen",
2869 .maxlen = sizeof(int),
2870 .mode = 0644,
2871 .proc_handler = proc_unres_qlen,
2872 },
2873 [NEIGH_VAR_QUEUE_LEN_BYTES] = {
2874 .procname = "unres_qlen_bytes",
2875 .maxlen = sizeof(int),
2876 .mode = 0644,
2877 .extra1 = &zero,
2878 .proc_handler = proc_dointvec_minmax,
2879 },
2880 [NEIGH_VAR_PROXY_QLEN] = {
2881 .procname = "proxy_qlen",
2882 .maxlen = sizeof(int),
2883 .mode = 0644,
2884 .extra1 = &zero,
2885 .extra2 = &int_max,
2886 .proc_handler = proc_dointvec_minmax,
2887 },
2888 [NEIGH_VAR_ANYCAST_DELAY] = {
2889 .procname = "anycast_delay",
2890 .maxlen = sizeof(int),
2891 .mode = 0644,
2892 .proc_handler = proc_dointvec_userhz_jiffies,
2893 },
2894 [NEIGH_VAR_PROXY_DELAY] = {
2895 .procname = "proxy_delay",
2896 .maxlen = sizeof(int),
2897 .mode = 0644,
2898 .proc_handler = proc_dointvec_userhz_jiffies,
2899 },
2900 [NEIGH_VAR_LOCKTIME] = {
2901 .procname = "locktime",
2902 .maxlen = sizeof(int),
2903 .mode = 0644,
2904 .proc_handler = proc_dointvec_userhz_jiffies,
2905 },
2906 [NEIGH_VAR_RETRANS_TIME_MS] = {
2907 .procname = "retrans_time_ms",
2908 .maxlen = sizeof(int),
2909 .mode = 0644,
2910 .proc_handler = proc_dointvec_ms_jiffies,
2911 },
2912 [NEIGH_VAR_BASE_REACHABLE_TIME_MS] = {
2913 .procname = "base_reachable_time_ms",
2914 .maxlen = sizeof(int),
2915 .mode = 0644,
2916 .proc_handler = proc_dointvec_ms_jiffies,
2917 },
2918 [NEIGH_VAR_GC_INTERVAL] = { 2997 [NEIGH_VAR_GC_INTERVAL] = {
2919 .procname = "gc_interval", 2998 .procname = "gc_interval",
2920 .maxlen = sizeof(int), 2999 .maxlen = sizeof(int),
@@ -2950,31 +3029,23 @@ static struct neigh_sysctl_table {
2950}; 3029};
2951 3030
2952int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p, 3031int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
2953 char *p_name, proc_handler *handler) 3032 proc_handler *handler)
2954{ 3033{
3034 int i;
2955 struct neigh_sysctl_table *t; 3035 struct neigh_sysctl_table *t;
2956 const char *dev_name_source = NULL; 3036 const char *dev_name_source;
2957 char neigh_path[ sizeof("net//neigh/") + IFNAMSIZ + IFNAMSIZ ]; 3037 char neigh_path[ sizeof("net//neigh/") + IFNAMSIZ + IFNAMSIZ ];
3038 char *p_name;
2958 3039
2959 t = kmemdup(&neigh_sysctl_template, sizeof(*t), GFP_KERNEL); 3040 t = kmemdup(&neigh_sysctl_template, sizeof(*t), GFP_KERNEL);
2960 if (!t) 3041 if (!t)
2961 goto err; 3042 goto err;
2962 3043
2963 t->neigh_vars[NEIGH_VAR_MCAST_PROBE].data = &p->mcast_probes; 3044 for (i = 0; i < ARRAY_SIZE(t->neigh_vars); i++) {
2964 t->neigh_vars[NEIGH_VAR_UCAST_PROBE].data = &p->ucast_probes; 3045 t->neigh_vars[i].data += (long) p;
2965 t->neigh_vars[NEIGH_VAR_APP_PROBE].data = &p->app_probes; 3046 t->neigh_vars[i].extra1 = dev;
2966 t->neigh_vars[NEIGH_VAR_RETRANS_TIME].data = &p->retrans_time; 3047 t->neigh_vars[i].extra2 = p;
2967 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME].data = &p->base_reachable_time; 3048 }
2968 t->neigh_vars[NEIGH_VAR_DELAY_PROBE_TIME].data = &p->delay_probe_time;
2969 t->neigh_vars[NEIGH_VAR_GC_STALETIME].data = &p->gc_staletime;
2970 t->neigh_vars[NEIGH_VAR_QUEUE_LEN].data = &p->queue_len_bytes;
2971 t->neigh_vars[NEIGH_VAR_QUEUE_LEN_BYTES].data = &p->queue_len_bytes;
2972 t->neigh_vars[NEIGH_VAR_PROXY_QLEN].data = &p->proxy_qlen;
2973 t->neigh_vars[NEIGH_VAR_ANYCAST_DELAY].data = &p->anycast_delay;
2974 t->neigh_vars[NEIGH_VAR_PROXY_DELAY].data = &p->proxy_delay;
2975 t->neigh_vars[NEIGH_VAR_LOCKTIME].data = &p->locktime;
2976 t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].data = &p->retrans_time;
2977 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].data = &p->base_reachable_time;
2978 3049
2979 if (dev) { 3050 if (dev) {
2980 dev_name_source = dev->name; 3051 dev_name_source = dev->name;
@@ -2989,26 +3060,32 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
2989 t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3; 3060 t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
2990 } 3061 }
2991 3062
2992
2993 if (handler) { 3063 if (handler) {
2994 /* RetransTime */ 3064 /* RetransTime */
2995 t->neigh_vars[NEIGH_VAR_RETRANS_TIME].proc_handler = handler; 3065 t->neigh_vars[NEIGH_VAR_RETRANS_TIME].proc_handler = handler;
2996 t->neigh_vars[NEIGH_VAR_RETRANS_TIME].extra1 = dev;
2997 /* ReachableTime */ 3066 /* ReachableTime */
2998 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME].proc_handler = handler; 3067 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME].proc_handler = handler;
2999 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME].extra1 = dev;
3000 /* RetransTime (in milliseconds)*/ 3068 /* RetransTime (in milliseconds)*/
3001 t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].proc_handler = handler; 3069 t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].proc_handler = handler;
3002 t->neigh_vars[NEIGH_VAR_RETRANS_TIME_MS].extra1 = dev;
3003 /* ReachableTime (in milliseconds) */ 3070 /* ReachableTime (in milliseconds) */
3004 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler = handler; 3071 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].proc_handler = handler;
3005 t->neigh_vars[NEIGH_VAR_BASE_REACHABLE_TIME_MS].extra1 = dev;
3006 } 3072 }
3007 3073
3008 /* Don't export sysctls to unprivileged users */ 3074 /* Don't export sysctls to unprivileged users */
3009 if (neigh_parms_net(p)->user_ns != &init_user_ns) 3075 if (neigh_parms_net(p)->user_ns != &init_user_ns)
3010 t->neigh_vars[0].procname = NULL; 3076 t->neigh_vars[0].procname = NULL;
3011 3077
3078 switch (neigh_parms_family(p)) {
3079 case AF_INET:
3080 p_name = "ipv4";
3081 break;
3082 case AF_INET6:
3083 p_name = "ipv6";
3084 break;
3085 default:
3086 BUG();
3087 }
3088
3012 snprintf(neigh_path, sizeof(neigh_path), "net/%s/neigh/%s", 3089 snprintf(neigh_path, sizeof(neigh_path), "net/%s/neigh/%s",
3013 p_name, dev_name_source); 3090 p_name, dev_name_source);
3014 t->sysctl_header = 3091 t->sysctl_header =
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index f3edf9635e02..1a7b7b1df0d1 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -676,8 +676,8 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
676 while ((mask | (mask >> 1)) != mask) 676 while ((mask | (mask >> 1)) != mask)
677 mask |= (mask >> 1); 677 mask |= (mask >> 1);
678 /* On 64 bit arches, must check mask fits in table->mask (u32), 678 /* On 64 bit arches, must check mask fits in table->mask (u32),
679 * and on 32bit arches, must check RPS_DEV_FLOW_TABLE_SIZE(mask + 1) 679 * and on 32bit arches, must check
680 * doesnt overflow. 680 * RPS_DEV_FLOW_TABLE_SIZE(mask + 1) doesn't overflow.
681 */ 681 */
682#if BITS_PER_LONG > 32 682#if BITS_PER_LONG > 32
683 if (mask > (unsigned long)(u32)mask) 683 if (mask > (unsigned long)(u32)mask)
diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c
index 9b7cf6c85f82..1dda50c2e705 100644
--- a/net/core/netprio_cgroup.c
+++ b/net/core/netprio_cgroup.c
@@ -30,7 +30,7 @@
30#define PRIOMAP_MIN_SZ 128 30#define PRIOMAP_MIN_SZ 128
31 31
32/* 32/*
33 * Extend @dev->priomap so that it's large enough to accomodate 33 * Extend @dev->priomap so that it's large enough to accommodate
34 * @target_idx. @dev->priomap.priomap_len > @target_idx after successful 34 * @target_idx. @dev->priomap.priomap_len > @target_idx after successful
35 * return. Must be called under rtnl lock. 35 * return. Must be called under rtnl lock.
36 */ 36 */
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 261357a66300..a797fff7f222 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -2527,6 +2527,8 @@ static int process_ipsec(struct pktgen_dev *pkt_dev,
2527 if (x) { 2527 if (x) {
2528 int ret; 2528 int ret;
2529 __u8 *eth; 2529 __u8 *eth;
2530 struct iphdr *iph;
2531
2530 nhead = x->props.header_len - skb_headroom(skb); 2532 nhead = x->props.header_len - skb_headroom(skb);
2531 if (nhead > 0) { 2533 if (nhead > 0) {
2532 ret = pskb_expand_head(skb, nhead, 0, GFP_ATOMIC); 2534 ret = pskb_expand_head(skb, nhead, 0, GFP_ATOMIC);
@@ -2548,6 +2550,11 @@ static int process_ipsec(struct pktgen_dev *pkt_dev,
2548 eth = (__u8 *) skb_push(skb, ETH_HLEN); 2550 eth = (__u8 *) skb_push(skb, ETH_HLEN);
2549 memcpy(eth, pkt_dev->hh, 12); 2551 memcpy(eth, pkt_dev->hh, 12);
2550 *(u16 *) &eth[12] = protocol; 2552 *(u16 *) &eth[12] = protocol;
2553
2554 /* Update IPv4 header len as well as checksum value */
2555 iph = ip_hdr(skb);
2556 iph->tot_len = htons(skb->len - ETH_HLEN);
2557 ip_send_check(iph);
2551 } 2558 }
2552 } 2559 }
2553 return 1; 2560 return 1;
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 2718fed53d8c..eb96c2c22400 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -712,9 +712,8 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
712 new->inner_network_header = old->inner_network_header; 712 new->inner_network_header = old->inner_network_header;
713 new->inner_mac_header = old->inner_mac_header; 713 new->inner_mac_header = old->inner_mac_header;
714 skb_dst_copy(new, old); 714 skb_dst_copy(new, old);
715 new->rxhash = old->rxhash; 715 skb_copy_hash(new, old);
716 new->ooo_okay = old->ooo_okay; 716 new->ooo_okay = old->ooo_okay;
717 new->l4_rxhash = old->l4_rxhash;
718 new->no_fcs = old->no_fcs; 717 new->no_fcs = old->no_fcs;
719 new->encapsulation = old->encapsulation; 718 new->encapsulation = old->encapsulation;
720#ifdef CONFIG_XFRM 719#ifdef CONFIG_XFRM
@@ -2982,10 +2981,7 @@ perform_csum_check:
2982 return segs; 2981 return segs;
2983 2982
2984err: 2983err:
2985 while ((skb = segs)) { 2984 kfree_skb_list(segs);
2986 segs = skb->next;
2987 kfree_skb(skb);
2988 }
2989 return ERR_PTR(err); 2985 return ERR_PTR(err);
2990} 2986}
2991EXPORT_SYMBOL_GPL(skb_segment); 2987EXPORT_SYMBOL_GPL(skb_segment);
@@ -3584,6 +3580,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
3584 skb->tstamp.tv64 = 0; 3580 skb->tstamp.tv64 = 0;
3585 skb->pkt_type = PACKET_HOST; 3581 skb->pkt_type = PACKET_HOST;
3586 skb->skb_iif = 0; 3582 skb->skb_iif = 0;
3583 skb->local_df = 0;
3587 skb_dst_drop(skb); 3584 skb_dst_drop(skb);
3588 skb->mark = 0; 3585 skb->mark = 0;
3589 secpath_reset(skb); 3586 secpath_reset(skb);
diff --git a/net/core/sock.c b/net/core/sock.c
index ab20ed9b0f31..5393b4b719d7 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -882,7 +882,7 @@ set_rcvbuf:
882 882
883 case SO_PEEK_OFF: 883 case SO_PEEK_OFF:
884 if (sock->ops->set_peek_off) 884 if (sock->ops->set_peek_off)
885 sock->ops->set_peek_off(sk, val); 885 ret = sock->ops->set_peek_off(sk, val);
886 else 886 else
887 ret = -EOPNOTSUPP; 887 ret = -EOPNOTSUPP;
888 break; 888 break;
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index cca444190907..cf9cd13509a7 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -122,7 +122,8 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
122 synchronize_rcu(); 122 synchronize_rcu();
123 kfree(cur); 123 kfree(cur);
124 } else if (!cur && cpumask_test_cpu(i, mask)) { 124 } else if (!cur && cpumask_test_cpu(i, mask)) {
125 cur = kzalloc(len, GFP_KERNEL); 125 cur = kzalloc_node(len, GFP_KERNEL,
126 cpu_to_node(i));
126 if (!cur) { 127 if (!cur) {
127 /* not unwinding previous changes */ 128 /* not unwinding previous changes */
128 ret = -ENOMEM; 129 ret = -ENOMEM;
diff --git a/net/dcb/dcbevent.c b/net/dcb/dcbevent.c
index 4f72fc40bf02..a520d8004d89 100644
--- a/net/dcb/dcbevent.c
+++ b/net/dcb/dcbevent.c
@@ -11,8 +11,7 @@
11 * more details. 11 * more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along with 13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 14 * this program; if not, see <http://www.gnu.org/licenses/>.
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 * 15 *
17 * Author: John Fastabend <john.r.fastabend@intel.com> 16 * Author: John Fastabend <john.r.fastabend@intel.com>
18 */ 17 */
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index 40d5829ed36a..66fbe1948fb5 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -11,8 +11,7 @@
11 * more details. 11 * more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along with 13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 14 * this program; if not, see <http://www.gnu.org/licenses/>.
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 * 15 *
17 * Author: Lucy Liu <lucy.liu@intel.com> 16 * Author: Lucy Liu <lucy.liu@intel.com>
18 */ 17 */
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index d9f65fc66db5..88299c29101d 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -75,7 +75,7 @@ int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
75 rt = ip_route_connect(fl4, nexthop, inet->inet_saddr, 75 rt = ip_route_connect(fl4, nexthop, inet->inet_saddr,
76 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if, 76 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
77 IPPROTO_DCCP, 77 IPPROTO_DCCP,
78 orig_sport, orig_dport, sk, true); 78 orig_sport, orig_dport, sk);
79 if (IS_ERR(rt)) 79 if (IS_ERR(rt))
80 return PTR_ERR(rt); 80 return PTR_ERR(rt);
81 81
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 4ac71ff7c2e4..4db3c2a1679c 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -141,6 +141,9 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
141 if (type == ICMPV6_PKT_TOOBIG) { 141 if (type == ICMPV6_PKT_TOOBIG) {
142 struct dst_entry *dst = NULL; 142 struct dst_entry *dst = NULL;
143 143
144 if (!ip6_sk_accept_pmtu(sk))
145 goto out;
146
144 if (sock_owned_by_user(sk)) 147 if (sock_owned_by_user(sk))
145 goto out; 148 goto out;
146 if ((1 << sk->sk_state) & (DCCPF_LISTEN | DCCPF_CLOSED)) 149 if ((1 << sk->sk_state) & (DCCPF_LISTEN | DCCPF_CLOSED))
@@ -237,7 +240,7 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req)
237 240
238 final_p = fl6_update_dst(&fl6, np->opt, &final); 241 final_p = fl6_update_dst(&fl6, np->opt, &final);
239 242
240 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, false); 243 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
241 if (IS_ERR(dst)) { 244 if (IS_ERR(dst)) {
242 err = PTR_ERR(dst); 245 err = PTR_ERR(dst);
243 dst = NULL; 246 dst = NULL;
@@ -301,7 +304,7 @@ static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
301 security_skb_classify_flow(rxskb, flowi6_to_flowi(&fl6)); 304 security_skb_classify_flow(rxskb, flowi6_to_flowi(&fl6));
302 305
303 /* sk = NULL, but it is safe for now. RST socket required. */ 306 /* sk = NULL, but it is safe for now. RST socket required. */
304 dst = ip6_dst_lookup_flow(ctl_sk, &fl6, NULL, false); 307 dst = ip6_dst_lookup_flow(ctl_sk, &fl6, NULL);
305 if (!IS_ERR(dst)) { 308 if (!IS_ERR(dst)) {
306 skb_dst_set(skb, dst); 309 skb_dst_set(skb, dst);
307 ip6_xmit(ctl_sk, skb, &fl6, NULL, 0); 310 ip6_xmit(ctl_sk, skb, &fl6, NULL, 0);
@@ -512,7 +515,7 @@ static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
512 fl6.fl6_sport = htons(ireq->ir_num); 515 fl6.fl6_sport = htons(ireq->ir_num);
513 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 516 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
514 517
515 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, false); 518 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
516 if (IS_ERR(dst)) 519 if (IS_ERR(dst))
517 goto out; 520 goto out;
518 } 521 }
@@ -851,7 +854,6 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
851 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); 854 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
852 if (flowlabel == NULL) 855 if (flowlabel == NULL)
853 return -EINVAL; 856 return -EINVAL;
854 usin->sin6_addr = flowlabel->dst;
855 fl6_sock_release(flowlabel); 857 fl6_sock_release(flowlabel);
856 } 858 }
857 } 859 }
@@ -932,7 +934,7 @@ static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
932 934
933 final_p = fl6_update_dst(&fl6, np->opt, &final); 935 final_p = fl6_update_dst(&fl6, np->opt, &final);
934 936
935 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, true); 937 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
936 if (IS_ERR(dst)) { 938 if (IS_ERR(dst)) {
937 err = PTR_ERR(dst); 939 err = PTR_ERR(dst);
938 goto failure; 940 goto failure;
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index dd0dfb25f4b1..a603823a3e27 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -561,6 +561,7 @@ static const struct nla_policy dn_ifa_policy[IFA_MAX+1] = {
561 [IFA_LOCAL] = { .type = NLA_U16 }, 561 [IFA_LOCAL] = { .type = NLA_U16 },
562 [IFA_LABEL] = { .type = NLA_STRING, 562 [IFA_LABEL] = { .type = NLA_STRING,
563 .len = IFNAMSIZ - 1 }, 563 .len = IFNAMSIZ - 1 },
564 [IFA_FLAGS] = { .type = NLA_U32 },
564}; 565};
565 566
566static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh) 567static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh)
@@ -648,7 +649,8 @@ static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)
648 649
649 ifa->ifa_local = nla_get_le16(tb[IFA_LOCAL]); 650 ifa->ifa_local = nla_get_le16(tb[IFA_LOCAL]);
650 ifa->ifa_address = nla_get_le16(tb[IFA_ADDRESS]); 651 ifa->ifa_address = nla_get_le16(tb[IFA_ADDRESS]);
651 ifa->ifa_flags = ifm->ifa_flags; 652 ifa->ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) :
653 ifm->ifa_flags;
652 ifa->ifa_scope = ifm->ifa_scope; 654 ifa->ifa_scope = ifm->ifa_scope;
653 ifa->ifa_dev = dn_db; 655 ifa->ifa_dev = dn_db;
654 656
@@ -669,7 +671,8 @@ static inline size_t dn_ifaddr_nlmsg_size(void)
669 return NLMSG_ALIGN(sizeof(struct ifaddrmsg)) 671 return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
670 + nla_total_size(IFNAMSIZ) /* IFA_LABEL */ 672 + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
671 + nla_total_size(2) /* IFA_ADDRESS */ 673 + nla_total_size(2) /* IFA_ADDRESS */
672 + nla_total_size(2); /* IFA_LOCAL */ 674 + nla_total_size(2) /* IFA_LOCAL */
675 + nla_total_size(4); /* IFA_FLAGS */
673} 676}
674 677
675static int dn_nl_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa, 678static int dn_nl_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
@@ -677,6 +680,7 @@ static int dn_nl_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
677{ 680{
678 struct ifaddrmsg *ifm; 681 struct ifaddrmsg *ifm;
679 struct nlmsghdr *nlh; 682 struct nlmsghdr *nlh;
683 u32 ifa_flags = ifa->ifa_flags | IFA_F_PERMANENT;
680 684
681 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*ifm), flags); 685 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*ifm), flags);
682 if (nlh == NULL) 686 if (nlh == NULL)
@@ -685,7 +689,7 @@ static int dn_nl_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
685 ifm = nlmsg_data(nlh); 689 ifm = nlmsg_data(nlh);
686 ifm->ifa_family = AF_DECnet; 690 ifm->ifa_family = AF_DECnet;
687 ifm->ifa_prefixlen = 16; 691 ifm->ifa_prefixlen = 16;
688 ifm->ifa_flags = ifa->ifa_flags | IFA_F_PERMANENT; 692 ifm->ifa_flags = ifa_flags;
689 ifm->ifa_scope = ifa->ifa_scope; 693 ifm->ifa_scope = ifa->ifa_scope;
690 ifm->ifa_index = ifa->ifa_dev->dev->ifindex; 694 ifm->ifa_index = ifa->ifa_dev->dev->ifindex;
691 695
@@ -694,7 +698,8 @@ static int dn_nl_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
694 (ifa->ifa_local && 698 (ifa->ifa_local &&
695 nla_put_le16(skb, IFA_LOCAL, ifa->ifa_local)) || 699 nla_put_le16(skb, IFA_LOCAL, ifa->ifa_local)) ||
696 (ifa->ifa_label[0] && 700 (ifa->ifa_label[0] &&
697 nla_put_string(skb, IFA_LABEL, ifa->ifa_label))) 701 nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) ||
702 nla_put_u32(skb, IFA_FLAGS, ifa_flags))
698 goto nla_put_failure; 703 goto nla_put_failure;
699 return nlmsg_end(skb, nlh); 704 return nlmsg_end(skb, nlh);
700 705
diff --git a/net/decnet/dn_neigh.c b/net/decnet/dn_neigh.c
index f8637f93d318..c8121ceddb9e 100644
--- a/net/decnet/dn_neigh.c
+++ b/net/decnet/dn_neigh.c
@@ -102,19 +102,21 @@ struct neigh_table dn_neigh_table = {
102 .id = "dn_neigh_cache", 102 .id = "dn_neigh_cache",
103 .parms ={ 103 .parms ={
104 .tbl = &dn_neigh_table, 104 .tbl = &dn_neigh_table,
105 .base_reachable_time = 30 * HZ, 105 .reachable_time = 30 * HZ,
106 .retrans_time = 1 * HZ, 106 .data = {
107 .gc_staletime = 60 * HZ, 107 [NEIGH_VAR_MCAST_PROBES] = 0,
108 .reachable_time = 30 * HZ, 108 [NEIGH_VAR_UCAST_PROBES] = 0,
109 .delay_probe_time = 5 * HZ, 109 [NEIGH_VAR_APP_PROBES] = 0,
110 .queue_len_bytes = 64*1024, 110 [NEIGH_VAR_RETRANS_TIME] = 1 * HZ,
111 .ucast_probes = 0, 111 [NEIGH_VAR_BASE_REACHABLE_TIME] = 30 * HZ,
112 .app_probes = 0, 112 [NEIGH_VAR_DELAY_PROBE_TIME] = 5 * HZ,
113 .mcast_probes = 0, 113 [NEIGH_VAR_GC_STALETIME] = 60 * HZ,
114 .anycast_delay = 0, 114 [NEIGH_VAR_QUEUE_LEN_BYTES] = 64*1024,
115 .proxy_delay = 0, 115 [NEIGH_VAR_PROXY_QLEN] = 0,
116 .proxy_qlen = 0, 116 [NEIGH_VAR_ANYCAST_DELAY] = 0,
117 .locktime = 1 * HZ, 117 [NEIGH_VAR_PROXY_DELAY] = 0,
118 [NEIGH_VAR_LOCKTIME] = 1 * HZ,
119 },
118 }, 120 },
119 .gc_interval = 30 * HZ, 121 .gc_interval = 30 * HZ,
120 .gc_thresh1 = 128, 122 .gc_thresh1 = 128,
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index fe32388ea24f..ad2efa5b861b 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -1288,8 +1288,6 @@ int dn_route_output_sock(struct dst_entry __rcu **pprt, struct flowidn *fl, stru
1288 1288
1289 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD); 1289 err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
1290 if (err == 0 && fl->flowidn_proto) { 1290 if (err == 0 && fl->flowidn_proto) {
1291 if (!(flags & MSG_DONTWAIT))
1292 fl->flowidn_flags |= FLOWI_FLAG_CAN_SLEEP;
1293 *pprt = xfrm_lookup(&init_net, *pprt, 1291 *pprt = xfrm_lookup(&init_net, *pprt,
1294 flowidn_to_flowi(fl), sk, 0); 1292 flowidn_to_flowi(fl), sk, 0);
1295 if (IS_ERR(*pprt)) { 1293 if (IS_ERR(*pprt)) {
diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
index f347a2ca7d7e..bf8584339048 100644
--- a/net/dns_resolver/dns_key.c
+++ b/net/dns_resolver/dns_key.c
@@ -19,8 +19,7 @@
19 * the GNU Lesser General Public License for more details. 19 * the GNU Lesser General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU Lesser General Public License 21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library; if not, write to the Free Software 22 * along with this library; if not, see <http://www.gnu.org/licenses/>.
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 23 */
25#include <linux/module.h> 24#include <linux/module.h>
26#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
diff --git a/net/dns_resolver/dns_query.c b/net/dns_resolver/dns_query.c
index c32be292c7e3..e7b6d53eef88 100644
--- a/net/dns_resolver/dns_query.c
+++ b/net/dns_resolver/dns_query.c
@@ -32,8 +32,7 @@
32 * the GNU Lesser General Public License for more details. 32 * the GNU Lesser General Public License for more details.
33 * 33 *
34 * You should have received a copy of the GNU Lesser General Public License 34 * You should have received a copy of the GNU Lesser General Public License
35 * along with this library; if not, write to the Free Software 35 * along with this library; if not, see <http://www.gnu.org/licenses/>.
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 */ 36 */
38 37
39#include <linux/module.h> 38#include <linux/module.h>
diff --git a/net/dns_resolver/internal.h b/net/dns_resolver/internal.h
index 17c7886b5b3a..7af1ed39c009 100644
--- a/net/dns_resolver/internal.h
+++ b/net/dns_resolver/internal.h
@@ -15,8 +15,7 @@
15 * the GNU Lesser General Public License for more details. 15 * the GNU Lesser General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Lesser General Public License 17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software 18 * along with this library; if not, see <http://www.gnu.org/licenses/>.
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 19 */
21 20
22#include <linux/compiler.h> 21#include <linux/compiler.h>
diff --git a/net/hsr/hsr_framereg.c b/net/hsr/hsr_framereg.c
index 003f5bb3acd2..327060c6c874 100644
--- a/net/hsr/hsr_framereg.c
+++ b/net/hsr/hsr_framereg.c
@@ -127,11 +127,6 @@ int hsr_create_self_node(struct list_head *self_node_db,
127 return 0; 127 return 0;
128} 128}
129 129
130static void node_entry_reclaim(struct rcu_head *rh)
131{
132 kfree(container_of(rh, struct node_entry, rcu_head));
133}
134
135 130
136/* Add/merge node to the database of nodes. 'skb' must contain an HSR 131/* Add/merge node to the database of nodes. 'skb' must contain an HSR
137 * supervision frame. 132 * supervision frame.
@@ -175,7 +170,7 @@ struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv,
175 if (node && !ether_addr_equal(node->MacAddressA, hsr_sp->MacAddressA)) { 170 if (node && !ether_addr_equal(node->MacAddressA, hsr_sp->MacAddressA)) {
176 /* Node has changed its AddrA, frame was received from SlaveB */ 171 /* Node has changed its AddrA, frame was received from SlaveB */
177 list_del_rcu(&node->mac_list); 172 list_del_rcu(&node->mac_list);
178 call_rcu(&node->rcu_head, node_entry_reclaim); 173 kfree_rcu(node, rcu_head);
179 node = NULL; 174 node = NULL;
180 } 175 }
181 176
@@ -183,7 +178,7 @@ struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv,
183 !ether_addr_equal(node->MacAddressB, hsr_ethsup->ethhdr.h_source)) { 178 !ether_addr_equal(node->MacAddressB, hsr_ethsup->ethhdr.h_source)) {
184 /* Cables have been swapped */ 179 /* Cables have been swapped */
185 list_del_rcu(&node->mac_list); 180 list_del_rcu(&node->mac_list);
186 call_rcu(&node->rcu_head, node_entry_reclaim); 181 kfree_rcu(node, rcu_head);
187 node = NULL; 182 node = NULL;
188 } 183 }
189 184
@@ -192,7 +187,7 @@ struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv,
192 !ether_addr_equal(node->MacAddressA, hsr_ethsup->ethhdr.h_source)) { 187 !ether_addr_equal(node->MacAddressA, hsr_ethsup->ethhdr.h_source)) {
193 /* Cables have been swapped */ 188 /* Cables have been swapped */
194 list_del_rcu(&node->mac_list); 189 list_del_rcu(&node->mac_list);
195 call_rcu(&node->rcu_head, node_entry_reclaim); 190 kfree_rcu(node, rcu_head);
196 node = NULL; 191 node = NULL;
197 } 192 }
198 193
@@ -288,7 +283,8 @@ void hsr_addr_subst_dest(struct hsr_priv *hsr_priv, struct ethhdr *ethhdr,
288static bool seq_nr_after(u16 a, u16 b) 283static bool seq_nr_after(u16 a, u16 b)
289{ 284{
290 /* Remove inconsistency where 285 /* Remove inconsistency where
291 * seq_nr_after(a, b) == seq_nr_before(a, b) */ 286 * seq_nr_after(a, b) == seq_nr_before(a, b)
287 */
292 if ((int) b - a == 32768) 288 if ((int) b - a == 32768)
293 return false; 289 return false;
294 290
@@ -416,7 +412,7 @@ void hsr_prune_nodes(struct hsr_priv *hsr_priv)
416 hsr_nl_nodedown(hsr_priv, node->MacAddressA); 412 hsr_nl_nodedown(hsr_priv, node->MacAddressA);
417 list_del_rcu(&node->mac_list); 413 list_del_rcu(&node->mac_list);
418 /* Note that we need to free this entry later: */ 414 /* Note that we need to free this entry later: */
419 call_rcu(&node->rcu_head, node_entry_reclaim); 415 kfree_rcu(node, rcu_head);
420 } 416 }
421 } 417 }
422 rcu_read_unlock(); 418 rcu_read_unlock();
diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
index 5325af85eea6..01a5261ac7a5 100644
--- a/net/hsr/hsr_netlink.c
+++ b/net/hsr/hsr_netlink.c
@@ -23,6 +23,8 @@ static const struct nla_policy hsr_policy[IFLA_HSR_MAX + 1] = {
23 [IFLA_HSR_SLAVE1] = { .type = NLA_U32 }, 23 [IFLA_HSR_SLAVE1] = { .type = NLA_U32 },
24 [IFLA_HSR_SLAVE2] = { .type = NLA_U32 }, 24 [IFLA_HSR_SLAVE2] = { .type = NLA_U32 },
25 [IFLA_HSR_MULTICAST_SPEC] = { .type = NLA_U8 }, 25 [IFLA_HSR_MULTICAST_SPEC] = { .type = NLA_U8 },
26 [IFLA_HSR_SUPERVISION_ADDR] = { .type = NLA_BINARY, .len = ETH_ALEN },
27 [IFLA_HSR_SEQ_NR] = { .type = NLA_U16 },
26}; 28};
27 29
28 30
@@ -59,6 +61,31 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
59 return hsr_dev_finalize(dev, link, multicast_spec); 61 return hsr_dev_finalize(dev, link, multicast_spec);
60} 62}
61 63
64static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
65{
66 struct hsr_priv *hsr_priv;
67
68 hsr_priv = netdev_priv(dev);
69
70 if (hsr_priv->slave[0])
71 if (nla_put_u32(skb, IFLA_HSR_SLAVE1, hsr_priv->slave[0]->ifindex))
72 goto nla_put_failure;
73
74 if (hsr_priv->slave[1])
75 if (nla_put_u32(skb, IFLA_HSR_SLAVE2, hsr_priv->slave[1]->ifindex))
76 goto nla_put_failure;
77
78 if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN,
79 hsr_priv->sup_multicast_addr) ||
80 nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr_priv->sequence_nr))
81 goto nla_put_failure;
82
83 return 0;
84
85nla_put_failure:
86 return -EMSGSIZE;
87}
88
62static struct rtnl_link_ops hsr_link_ops __read_mostly = { 89static struct rtnl_link_ops hsr_link_ops __read_mostly = {
63 .kind = "hsr", 90 .kind = "hsr",
64 .maxtype = IFLA_HSR_MAX, 91 .maxtype = IFLA_HSR_MAX,
@@ -66,6 +93,7 @@ static struct rtnl_link_ops hsr_link_ops __read_mostly = {
66 .priv_size = sizeof(struct hsr_priv), 93 .priv_size = sizeof(struct hsr_priv),
67 .setup = hsr_dev_setup, 94 .setup = hsr_dev_setup,
68 .newlink = hsr_newlink, 95 .newlink = hsr_newlink,
96 .fill_info = hsr_fill_info,
69}; 97};
70 98
71 99
diff --git a/net/ieee802154/wpan-class.c b/net/ieee802154/wpan-class.c
index ef56ab5b35fe..4dd37615a749 100644
--- a/net/ieee802154/wpan-class.c
+++ b/net/ieee802154/wpan-class.c
@@ -46,7 +46,7 @@ MASTER_SHOW(current_channel, "%d");
46MASTER_SHOW(current_page, "%d"); 46MASTER_SHOW(current_page, "%d");
47MASTER_SHOW_COMPLEX(transmit_power, "%d +- %d dB", 47MASTER_SHOW_COMPLEX(transmit_power, "%d +- %d dB",
48 ((signed char) (phy->transmit_power << 2)) >> 2, 48 ((signed char) (phy->transmit_power << 2)) >> 2,
49 (phy->transmit_power >> 6) ? (phy->transmit_power >> 6) * 3 : 1 ); 49 (phy->transmit_power >> 6) ? (phy->transmit_power >> 6) * 3 : 1);
50MASTER_SHOW(cca_mode, "%d"); 50MASTER_SHOW(cca_mode, "%d");
51 51
52static ssize_t channels_supported_show(struct device *dev, 52static ssize_t channels_supported_show(struct device *dev,
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 70011e029ac1..b8bc1a3d5cf1 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -126,9 +126,6 @@
126static struct list_head inetsw[SOCK_MAX]; 126static struct list_head inetsw[SOCK_MAX];
127static DEFINE_SPINLOCK(inetsw_lock); 127static DEFINE_SPINLOCK(inetsw_lock);
128 128
129struct ipv4_config ipv4_config;
130EXPORT_SYMBOL(ipv4_config);
131
132/* New destruction routine */ 129/* New destruction routine */
133 130
134void inet_sock_destruct(struct sock *sk) 131void inet_sock_destruct(struct sock *sk)
@@ -342,7 +339,7 @@ lookup_protocol:
342 inet->hdrincl = 1; 339 inet->hdrincl = 1;
343 } 340 }
344 341
345 if (ipv4_config.no_pmtu_disc) 342 if (net->ipv4.sysctl_ip_no_pmtu_disc)
346 inet->pmtudisc = IP_PMTUDISC_DONT; 343 inet->pmtudisc = IP_PMTUDISC_DONT;
347 else 344 else
348 inet->pmtudisc = IP_PMTUDISC_WANT; 345 inet->pmtudisc = IP_PMTUDISC_WANT;
@@ -1133,7 +1130,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
1133 fl4 = &inet->cork.fl.u.ip4; 1130 fl4 = &inet->cork.fl.u.ip4;
1134 rt = ip_route_connect(fl4, daddr, 0, RT_CONN_FLAGS(sk), 1131 rt = ip_route_connect(fl4, daddr, 0, RT_CONN_FLAGS(sk),
1135 sk->sk_bound_dev_if, sk->sk_protocol, 1132 sk->sk_bound_dev_if, sk->sk_protocol,
1136 inet->inet_sport, inet->inet_dport, sk, false); 1133 inet->inet_sport, inet->inet_dport, sk);
1137 if (IS_ERR(rt)) 1134 if (IS_ERR(rt))
1138 return PTR_ERR(rt); 1135 return PTR_ERR(rt);
1139 1136
@@ -1377,8 +1374,12 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
1377 if (!NAPI_GRO_CB(p)->same_flow) 1374 if (!NAPI_GRO_CB(p)->same_flow)
1378 continue; 1375 continue;
1379 1376
1380 iph2 = ip_hdr(p); 1377 iph2 = (struct iphdr *)(p->data + off);
1381 1378 /* The above works because, with the exception of the top
1379 * (inner most) layer, we only aggregate pkts with the same
1380 * hdr length so all the hdrs we'll need to verify will start
1381 * at the same offset.
1382 */
1382 if ((iph->protocol ^ iph2->protocol) | 1383 if ((iph->protocol ^ iph2->protocol) |
1383 ((__force u32)iph->saddr ^ (__force u32)iph2->saddr) | 1384 ((__force u32)iph->saddr ^ (__force u32)iph2->saddr) |
1384 ((__force u32)iph->daddr ^ (__force u32)iph2->daddr)) { 1385 ((__force u32)iph->daddr ^ (__force u32)iph2->daddr)) {
@@ -1397,6 +1398,11 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
1397 } 1398 }
1398 1399
1399 NAPI_GRO_CB(skb)->flush |= flush; 1400 NAPI_GRO_CB(skb)->flush |= flush;
1401 skb_set_network_header(skb, off);
1402 /* The above will be needed by the transport layer if there is one
1403 * immediately following this IP hdr.
1404 */
1405
1400 skb_gro_pull(skb, sizeof(*iph)); 1406 skb_gro_pull(skb, sizeof(*iph));
1401 skb_set_transport_header(skb, skb_gro_offset(skb)); 1407 skb_set_transport_header(skb, skb_gro_offset(skb));
1402 1408
@@ -1411,10 +1417,10 @@ out:
1411 return pp; 1417 return pp;
1412} 1418}
1413 1419
1414static int inet_gro_complete(struct sk_buff *skb) 1420static int inet_gro_complete(struct sk_buff *skb, int nhoff)
1415{ 1421{
1416 __be16 newlen = htons(skb->len - skb_network_offset(skb)); 1422 __be16 newlen = htons(skb->len - nhoff);
1417 struct iphdr *iph = ip_hdr(skb); 1423 struct iphdr *iph = (struct iphdr *)(skb->data + nhoff);
1418 const struct net_offload *ops; 1424 const struct net_offload *ops;
1419 int proto = iph->protocol; 1425 int proto = iph->protocol;
1420 int err = -ENOSYS; 1426 int err = -ENOSYS;
@@ -1427,7 +1433,11 @@ static int inet_gro_complete(struct sk_buff *skb)
1427 if (WARN_ON(!ops || !ops->callbacks.gro_complete)) 1433 if (WARN_ON(!ops || !ops->callbacks.gro_complete))
1428 goto out_unlock; 1434 goto out_unlock;
1429 1435
1430 err = ops->callbacks.gro_complete(skb); 1436 /* Only need to add sizeof(*iph) to get to the next hdr below
1437 * because any hdr with option will have been flushed in
1438 * inet_gro_receive().
1439 */
1440 err = ops->callbacks.gro_complete(skb, nhoff + sizeof(*iph));
1431 1441
1432out_unlock: 1442out_unlock:
1433 rcu_read_unlock(); 1443 rcu_read_unlock();
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 7808093cede6..5bf408b466b1 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -166,18 +166,20 @@ struct neigh_table arp_tbl = {
166 .id = "arp_cache", 166 .id = "arp_cache",
167 .parms = { 167 .parms = {
168 .tbl = &arp_tbl, 168 .tbl = &arp_tbl,
169 .base_reachable_time = 30 * HZ,
170 .retrans_time = 1 * HZ,
171 .gc_staletime = 60 * HZ,
172 .reachable_time = 30 * HZ, 169 .reachable_time = 30 * HZ,
173 .delay_probe_time = 5 * HZ, 170 .data = {
174 .queue_len_bytes = 64*1024, 171 [NEIGH_VAR_MCAST_PROBES] = 3,
175 .ucast_probes = 3, 172 [NEIGH_VAR_UCAST_PROBES] = 3,
176 .mcast_probes = 3, 173 [NEIGH_VAR_RETRANS_TIME] = 1 * HZ,
177 .anycast_delay = 1 * HZ, 174 [NEIGH_VAR_BASE_REACHABLE_TIME] = 30 * HZ,
178 .proxy_delay = (8 * HZ) / 10, 175 [NEIGH_VAR_DELAY_PROBE_TIME] = 5 * HZ,
179 .proxy_qlen = 64, 176 [NEIGH_VAR_GC_STALETIME] = 60 * HZ,
180 .locktime = 1 * HZ, 177 [NEIGH_VAR_QUEUE_LEN_BYTES] = 64 * 1024,
178 [NEIGH_VAR_PROXY_QLEN] = 64,
179 [NEIGH_VAR_ANYCAST_DELAY] = 1 * HZ,
180 [NEIGH_VAR_PROXY_DELAY] = (8 * HZ) / 10,
181 [NEIGH_VAR_LOCKTIME] = 1 * HZ,
182 },
181 }, 183 },
182 .gc_interval = 30 * HZ, 184 .gc_interval = 30 * HZ,
183 .gc_thresh1 = 128, 185 .gc_thresh1 = 128,
@@ -359,14 +361,14 @@ static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb)
359 if (!saddr) 361 if (!saddr)
360 saddr = inet_select_addr(dev, target, RT_SCOPE_LINK); 362 saddr = inet_select_addr(dev, target, RT_SCOPE_LINK);
361 363
362 probes -= neigh->parms->ucast_probes; 364 probes -= NEIGH_VAR(neigh->parms, UCAST_PROBES);
363 if (probes < 0) { 365 if (probes < 0) {
364 if (!(neigh->nud_state & NUD_VALID)) 366 if (!(neigh->nud_state & NUD_VALID))
365 pr_debug("trying to ucast probe in NUD_INVALID\n"); 367 pr_debug("trying to ucast probe in NUD_INVALID\n");
366 neigh_ha_snapshot(dst_ha, neigh, dev); 368 neigh_ha_snapshot(dst_ha, neigh, dev);
367 dst_hw = dst_ha; 369 dst_hw = dst_ha;
368 } else { 370 } else {
369 probes -= neigh->parms->app_probes; 371 probes -= NEIGH_VAR(neigh->parms, APP_PROBES);
370 if (probes < 0) { 372 if (probes < 0) {
371 neigh_app_ns(neigh); 373 neigh_app_ns(neigh);
372 return; 374 return;
@@ -379,6 +381,7 @@ static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb)
379 381
380static int arp_ignore(struct in_device *in_dev, __be32 sip, __be32 tip) 382static int arp_ignore(struct in_device *in_dev, __be32 sip, __be32 tip)
381{ 383{
384 struct net *net = dev_net(in_dev->dev);
382 int scope; 385 int scope;
383 386
384 switch (IN_DEV_ARP_IGNORE(in_dev)) { 387 switch (IN_DEV_ARP_IGNORE(in_dev)) {
@@ -397,6 +400,7 @@ static int arp_ignore(struct in_device *in_dev, __be32 sip, __be32 tip)
397 case 3: /* Do not reply for scope host addresses */ 400 case 3: /* Do not reply for scope host addresses */
398 sip = 0; 401 sip = 0;
399 scope = RT_SCOPE_LINK; 402 scope = RT_SCOPE_LINK;
403 in_dev = NULL;
400 break; 404 break;
401 case 4: /* Reserved */ 405 case 4: /* Reserved */
402 case 5: 406 case 5:
@@ -408,7 +412,7 @@ static int arp_ignore(struct in_device *in_dev, __be32 sip, __be32 tip)
408 default: 412 default:
409 return 0; 413 return 0;
410 } 414 }
411 return !inet_confirm_addr(in_dev, sip, tip, scope); 415 return !inet_confirm_addr(net, in_dev, sip, tip, scope);
412} 416}
413 417
414static int arp_filter(__be32 sip, __be32 tip, struct net_device *dev) 418static int arp_filter(__be32 sip, __be32 tip, struct net_device *dev)
@@ -871,7 +875,7 @@ static int arp_process(struct sk_buff *skb)
871 875
872 if (NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED || 876 if (NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED ||
873 skb->pkt_type == PACKET_HOST || 877 skb->pkt_type == PACKET_HOST ||
874 in_dev->arp_parms->proxy_delay == 0) { 878 NEIGH_VAR(in_dev->arp_parms, PROXY_DELAY) == 0) {
875 arp_send(ARPOP_REPLY, ETH_P_ARP, sip, 879 arp_send(ARPOP_REPLY, ETH_P_ARP, sip,
876 dev, tip, sha, dev->dev_addr, 880 dev, tip, sha, dev->dev_addr,
877 sha); 881 sha);
@@ -910,7 +914,8 @@ static int arp_process(struct sk_buff *skb)
910 agents are active. Taking the first reply prevents 914 agents are active. Taking the first reply prevents
911 arp trashing and chooses the fastest router. 915 arp trashing and chooses the fastest router.
912 */ 916 */
913 override = time_after(jiffies, n->updated + n->parms->locktime); 917 override = time_after(jiffies, n->updated +
918 NEIGH_VAR(n->parms, LOCKTIME));
914 919
915 /* Broadcast replies and request packets 920 /* Broadcast replies and request packets
916 do not assert neighbour reachability. 921 do not assert neighbour reachability.
@@ -1107,7 +1112,7 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
1107 return err; 1112 return err;
1108} 1113}
1109 1114
1110int arp_invalidate(struct net_device *dev, __be32 ip) 1115static int arp_invalidate(struct net_device *dev, __be32 ip)
1111{ 1116{
1112 struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev); 1117 struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
1113 int err = -ENXIO; 1118 int err = -ENXIO;
@@ -1122,7 +1127,6 @@ int arp_invalidate(struct net_device *dev, __be32 ip)
1122 1127
1123 return err; 1128 return err;
1124} 1129}
1125EXPORT_SYMBOL(arp_invalidate);
1126 1130
1127static int arp_req_delete_public(struct net *net, struct arpreq *r, 1131static int arp_req_delete_public(struct net *net, struct arpreq *r,
1128 struct net_device *dev) 1132 struct net_device *dev)
@@ -1284,7 +1288,7 @@ void __init arp_init(void)
1284 dev_add_pack(&arp_packet_type); 1288 dev_add_pack(&arp_packet_type);
1285 arp_proc_init(); 1289 arp_proc_init();
1286#ifdef CONFIG_SYSCTL 1290#ifdef CONFIG_SYSCTL
1287 neigh_sysctl_register(NULL, &arp_tbl.parms, "ipv4", NULL); 1291 neigh_sysctl_register(NULL, &arp_tbl.parms, NULL);
1288#endif 1292#endif
1289 register_netdevice_notifier(&arp_netdev_notifier); 1293 register_netdevice_notifier(&arp_netdev_notifier);
1290} 1294}
diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index 667c1d4ca984..69e77c8ff285 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -31,8 +31,7 @@
31 * the GNU General Public License for more details. 31 * the GNU General Public License for more details.
32 * 32 *
33 * You should have received a copy of the GNU General Public License 33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software 34 * along with this program; if not, see <http://www.gnu.org/licenses/>.
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 * 35 *
37 */ 36 */
38 37
@@ -1336,8 +1335,7 @@ static int cipso_v4_parsetag_rbm(const struct cipso_v4_doi *doi_def,
1336 secattr->flags |= NETLBL_SECATTR_MLS_LVL; 1335 secattr->flags |= NETLBL_SECATTR_MLS_LVL;
1337 1336
1338 if (tag_len > 4) { 1337 if (tag_len > 4) {
1339 secattr->attr.mls.cat = 1338 secattr->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1340 netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1341 if (secattr->attr.mls.cat == NULL) 1339 if (secattr->attr.mls.cat == NULL)
1342 return -ENOMEM; 1340 return -ENOMEM;
1343 1341
@@ -1432,8 +1430,7 @@ static int cipso_v4_parsetag_enum(const struct cipso_v4_doi *doi_def,
1432 secattr->flags |= NETLBL_SECATTR_MLS_LVL; 1430 secattr->flags |= NETLBL_SECATTR_MLS_LVL;
1433 1431
1434 if (tag_len > 4) { 1432 if (tag_len > 4) {
1435 secattr->attr.mls.cat = 1433 secattr->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1436 netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1437 if (secattr->attr.mls.cat == NULL) 1434 if (secattr->attr.mls.cat == NULL)
1438 return -ENOMEM; 1435 return -ENOMEM;
1439 1436
@@ -1527,8 +1524,7 @@ static int cipso_v4_parsetag_rng(const struct cipso_v4_doi *doi_def,
1527 secattr->flags |= NETLBL_SECATTR_MLS_LVL; 1524 secattr->flags |= NETLBL_SECATTR_MLS_LVL;
1528 1525
1529 if (tag_len > 4) { 1526 if (tag_len > 4) {
1530 secattr->attr.mls.cat = 1527 secattr->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1531 netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1532 if (secattr->attr.mls.cat == NULL) 1528 if (secattr->attr.mls.cat == NULL)
1533 return -ENOMEM; 1529 return -ENOMEM;
1534 1530
diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c
index 19e36376d2a0..8b5134c582f1 100644
--- a/net/ipv4/datagram.c
+++ b/net/ipv4/datagram.c
@@ -53,7 +53,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
53 rt = ip_route_connect(fl4, usin->sin_addr.s_addr, saddr, 53 rt = ip_route_connect(fl4, usin->sin_addr.s_addr, saddr,
54 RT_CONN_FLAGS(sk), oif, 54 RT_CONN_FLAGS(sk), oif,
55 sk->sk_protocol, 55 sk->sk_protocol,
56 inet->inet_sport, usin->sin_port, sk, true); 56 inet->inet_sport, usin->sin_port, sk);
57 if (IS_ERR(rt)) { 57 if (IS_ERR(rt)) {
58 err = PTR_ERR(rt); 58 err = PTR_ERR(rt);
59 if (err == -ENETUNREACH) 59 if (err == -ENETUNREACH)
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index a1b5bcbd04ae..0feebd5de295 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -99,6 +99,7 @@ static const struct nla_policy ifa_ipv4_policy[IFA_MAX+1] = {
99 [IFA_BROADCAST] = { .type = NLA_U32 }, 99 [IFA_BROADCAST] = { .type = NLA_U32 },
100 [IFA_LABEL] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, 100 [IFA_LABEL] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
101 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) }, 101 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) },
102 [IFA_FLAGS] = { .type = NLA_U32 },
102}; 103};
103 104
104#define IN4_ADDR_HSIZE_SHIFT 8 105#define IN4_ADDR_HSIZE_SHIFT 8
@@ -500,6 +501,7 @@ static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
500 return -ENOBUFS; 501 return -ENOBUFS;
501 } 502 }
502 ipv4_devconf_setall(in_dev); 503 ipv4_devconf_setall(in_dev);
504 neigh_parms_data_state_setall(in_dev->arp_parms);
503 if (ifa->ifa_dev != in_dev) { 505 if (ifa->ifa_dev != in_dev) {
504 WARN_ON(ifa->ifa_dev); 506 WARN_ON(ifa->ifa_dev);
505 in_dev_hold(in_dev); 507 in_dev_hold(in_dev);
@@ -747,6 +749,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
747 goto errout; 749 goto errout;
748 750
749 ipv4_devconf_setall(in_dev); 751 ipv4_devconf_setall(in_dev);
752 neigh_parms_data_state_setall(in_dev->arp_parms);
750 in_dev_hold(in_dev); 753 in_dev_hold(in_dev);
751 754
752 if (tb[IFA_ADDRESS] == NULL) 755 if (tb[IFA_ADDRESS] == NULL)
@@ -755,7 +758,8 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
755 INIT_HLIST_NODE(&ifa->hash); 758 INIT_HLIST_NODE(&ifa->hash);
756 ifa->ifa_prefixlen = ifm->ifa_prefixlen; 759 ifa->ifa_prefixlen = ifm->ifa_prefixlen;
757 ifa->ifa_mask = inet_make_mask(ifm->ifa_prefixlen); 760 ifa->ifa_mask = inet_make_mask(ifm->ifa_prefixlen);
758 ifa->ifa_flags = ifm->ifa_flags; 761 ifa->ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) :
762 ifm->ifa_flags;
759 ifa->ifa_scope = ifm->ifa_scope; 763 ifa->ifa_scope = ifm->ifa_scope;
760 ifa->ifa_dev = in_dev; 764 ifa->ifa_dev = in_dev;
761 765
@@ -1236,22 +1240,21 @@ static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst,
1236 1240
1237/* 1241/*
1238 * Confirm that local IP address exists using wildcards: 1242 * Confirm that local IP address exists using wildcards:
1239 * - in_dev: only on this interface, 0=any interface 1243 * - net: netns to check, cannot be NULL
1244 * - in_dev: only on this interface, NULL=any interface
1240 * - dst: only in the same subnet as dst, 0=any dst 1245 * - dst: only in the same subnet as dst, 0=any dst
1241 * - local: address, 0=autoselect the local address 1246 * - local: address, 0=autoselect the local address
1242 * - scope: maximum allowed scope value for the local address 1247 * - scope: maximum allowed scope value for the local address
1243 */ 1248 */
1244__be32 inet_confirm_addr(struct in_device *in_dev, 1249__be32 inet_confirm_addr(struct net *net, struct in_device *in_dev,
1245 __be32 dst, __be32 local, int scope) 1250 __be32 dst, __be32 local, int scope)
1246{ 1251{
1247 __be32 addr = 0; 1252 __be32 addr = 0;
1248 struct net_device *dev; 1253 struct net_device *dev;
1249 struct net *net;
1250 1254
1251 if (scope != RT_SCOPE_LINK) 1255 if (in_dev != NULL)
1252 return confirm_addr_indev(in_dev, dst, local, scope); 1256 return confirm_addr_indev(in_dev, dst, local, scope);
1253 1257
1254 net = dev_net(in_dev->dev);
1255 rcu_read_lock(); 1258 rcu_read_lock();
1256 for_each_netdev_rcu(net, dev) { 1259 for_each_netdev_rcu(net, dev) {
1257 in_dev = __in_dev_get_rcu(dev); 1260 in_dev = __in_dev_get_rcu(dev);
@@ -1435,7 +1438,8 @@ static size_t inet_nlmsg_size(void)
1435 + nla_total_size(4) /* IFA_ADDRESS */ 1438 + nla_total_size(4) /* IFA_ADDRESS */
1436 + nla_total_size(4) /* IFA_LOCAL */ 1439 + nla_total_size(4) /* IFA_LOCAL */
1437 + nla_total_size(4) /* IFA_BROADCAST */ 1440 + nla_total_size(4) /* IFA_BROADCAST */
1438 + nla_total_size(IFNAMSIZ); /* IFA_LABEL */ 1441 + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
1442 + nla_total_size(4); /* IFA_FLAGS */
1439} 1443}
1440 1444
1441static inline u32 cstamp_delta(unsigned long cstamp) 1445static inline u32 cstamp_delta(unsigned long cstamp)
@@ -1503,6 +1507,7 @@ static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa,
1503 nla_put_be32(skb, IFA_BROADCAST, ifa->ifa_broadcast)) || 1507 nla_put_be32(skb, IFA_BROADCAST, ifa->ifa_broadcast)) ||
1504 (ifa->ifa_label[0] && 1508 (ifa->ifa_label[0] &&
1505 nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) || 1509 nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) ||
1510 nla_put_u32(skb, IFA_FLAGS, ifa->ifa_flags) ||
1506 put_cacheinfo(skb, ifa->ifa_cstamp, ifa->ifa_tstamp, 1511 put_cacheinfo(skb, ifa->ifa_cstamp, ifa->ifa_tstamp,
1507 preferred, valid)) 1512 preferred, valid))
1508 goto nla_put_failure; 1513 goto nla_put_failure;
@@ -1691,6 +1696,8 @@ static int inet_netconf_msgsize_devconf(int type)
1691 size += nla_total_size(4); 1696 size += nla_total_size(4);
1692 if (type == -1 || type == NETCONFA_MC_FORWARDING) 1697 if (type == -1 || type == NETCONFA_MC_FORWARDING)
1693 size += nla_total_size(4); 1698 size += nla_total_size(4);
1699 if (type == -1 || type == NETCONFA_PROXY_NEIGH)
1700 size += nla_total_size(4);
1694 1701
1695 return size; 1702 return size;
1696} 1703}
@@ -1727,6 +1734,10 @@ static int inet_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
1727 nla_put_s32(skb, NETCONFA_MC_FORWARDING, 1734 nla_put_s32(skb, NETCONFA_MC_FORWARDING,
1728 IPV4_DEVCONF(*devconf, MC_FORWARDING)) < 0) 1735 IPV4_DEVCONF(*devconf, MC_FORWARDING)) < 0)
1729 goto nla_put_failure; 1736 goto nla_put_failure;
1737 if ((type == -1 || type == NETCONFA_PROXY_NEIGH) &&
1738 nla_put_s32(skb, NETCONFA_PROXY_NEIGH,
1739 IPV4_DEVCONF(*devconf, PROXY_ARP)) < 0)
1740 goto nla_put_failure;
1730 1741
1731 return nlmsg_end(skb, nlh); 1742 return nlmsg_end(skb, nlh);
1732 1743
@@ -1764,6 +1775,7 @@ static const struct nla_policy devconf_ipv4_policy[NETCONFA_MAX+1] = {
1764 [NETCONFA_IFINDEX] = { .len = sizeof(int) }, 1775 [NETCONFA_IFINDEX] = { .len = sizeof(int) },
1765 [NETCONFA_FORWARDING] = { .len = sizeof(int) }, 1776 [NETCONFA_FORWARDING] = { .len = sizeof(int) },
1766 [NETCONFA_RP_FILTER] = { .len = sizeof(int) }, 1777 [NETCONFA_RP_FILTER] = { .len = sizeof(int) },
1778 [NETCONFA_PROXY_NEIGH] = { .len = sizeof(int) },
1767}; 1779};
1768 1780
1769static int inet_netconf_get_devconf(struct sk_buff *in_skb, 1781static int inet_netconf_get_devconf(struct sk_buff *in_skb,
@@ -1945,6 +1957,19 @@ static void inet_forward_change(struct net *net)
1945 } 1957 }
1946} 1958}
1947 1959
1960static int devinet_conf_ifindex(struct net *net, struct ipv4_devconf *cnf)
1961{
1962 if (cnf == net->ipv4.devconf_dflt)
1963 return NETCONFA_IFINDEX_DEFAULT;
1964 else if (cnf == net->ipv4.devconf_all)
1965 return NETCONFA_IFINDEX_ALL;
1966 else {
1967 struct in_device *idev
1968 = container_of(cnf, struct in_device, cnf);
1969 return idev->dev->ifindex;
1970 }
1971}
1972
1948static int devinet_conf_proc(struct ctl_table *ctl, int write, 1973static int devinet_conf_proc(struct ctl_table *ctl, int write,
1949 void __user *buffer, 1974 void __user *buffer,
1950 size_t *lenp, loff_t *ppos) 1975 size_t *lenp, loff_t *ppos)
@@ -1957,6 +1982,7 @@ static int devinet_conf_proc(struct ctl_table *ctl, int write,
1957 struct ipv4_devconf *cnf = ctl->extra1; 1982 struct ipv4_devconf *cnf = ctl->extra1;
1958 struct net *net = ctl->extra2; 1983 struct net *net = ctl->extra2;
1959 int i = (int *)ctl->data - cnf->data; 1984 int i = (int *)ctl->data - cnf->data;
1985 int ifindex;
1960 1986
1961 set_bit(i, cnf->state); 1987 set_bit(i, cnf->state);
1962 1988
@@ -1966,23 +1992,19 @@ static int devinet_conf_proc(struct ctl_table *ctl, int write,
1966 i == IPV4_DEVCONF_ROUTE_LOCALNET - 1) 1992 i == IPV4_DEVCONF_ROUTE_LOCALNET - 1)
1967 if ((new_value == 0) && (old_value != 0)) 1993 if ((new_value == 0) && (old_value != 0))
1968 rt_cache_flush(net); 1994 rt_cache_flush(net);
1995
1969 if (i == IPV4_DEVCONF_RP_FILTER - 1 && 1996 if (i == IPV4_DEVCONF_RP_FILTER - 1 &&
1970 new_value != old_value) { 1997 new_value != old_value) {
1971 int ifindex; 1998 ifindex = devinet_conf_ifindex(net, cnf);
1972
1973 if (cnf == net->ipv4.devconf_dflt)
1974 ifindex = NETCONFA_IFINDEX_DEFAULT;
1975 else if (cnf == net->ipv4.devconf_all)
1976 ifindex = NETCONFA_IFINDEX_ALL;
1977 else {
1978 struct in_device *idev =
1979 container_of(cnf, struct in_device,
1980 cnf);
1981 ifindex = idev->dev->ifindex;
1982 }
1983 inet_netconf_notify_devconf(net, NETCONFA_RP_FILTER, 1999 inet_netconf_notify_devconf(net, NETCONFA_RP_FILTER,
1984 ifindex, cnf); 2000 ifindex, cnf);
1985 } 2001 }
2002 if (i == IPV4_DEVCONF_PROXY_ARP - 1 &&
2003 new_value != old_value) {
2004 ifindex = devinet_conf_ifindex(net, cnf);
2005 inet_netconf_notify_devconf(net, NETCONFA_PROXY_NEIGH,
2006 ifindex, cnf);
2007 }
1986 } 2008 }
1987 2009
1988 return ret; 2010 return ret;
@@ -2160,7 +2182,7 @@ static void __devinet_sysctl_unregister(struct ipv4_devconf *cnf)
2160 2182
2161static void devinet_sysctl_register(struct in_device *idev) 2183static void devinet_sysctl_register(struct in_device *idev)
2162{ 2184{
2163 neigh_sysctl_register(idev->dev, idev->arp_parms, "ipv4", NULL); 2185 neigh_sysctl_register(idev->dev, idev->arp_parms, NULL);
2164 __devinet_sysctl_register(dev_net(idev->dev), idev->dev->name, 2186 __devinet_sysctl_register(dev_net(idev->dev), idev->dev->name,
2165 &idev->cnf); 2187 &idev->cnf);
2166} 2188}
diff --git a/net/ipv4/fib_lookup.h b/net/ipv4/fib_lookup.h
index 388d113fd289..1e4f6600b31d 100644
--- a/net/ipv4/fib_lookup.h
+++ b/net/ipv4/fib_lookup.h
@@ -33,8 +33,6 @@ int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event, u32 tb_id,
33void rtmsg_fib(int event, __be32 key, struct fib_alias *fa, int dst_len, 33void rtmsg_fib(int event, __be32 key, struct fib_alias *fa, int dst_len,
34 u32 tb_id, const struct nl_info *info, unsigned int nlm_flags); 34 u32 tb_id, const struct nl_info *info, unsigned int nlm_flags);
35struct fib_alias *fib_find_alias(struct list_head *fah, u8 tos, u32 prio); 35struct fib_alias *fib_find_alias(struct list_head *fah, u8 tos, u32 prio);
36int fib_detect_death(struct fib_info *fi, int order,
37 struct fib_info **last_resort, int *last_idx, int dflt);
38 36
39static inline void fib_result_assign(struct fib_result *res, 37static inline void fib_result_assign(struct fib_result *res,
40 struct fib_info *fi) 38 struct fib_info *fi)
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index 523be38e37de..f2e15738534d 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -104,7 +104,10 @@ errout:
104static bool fib4_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg) 104static bool fib4_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg)
105{ 105{
106 struct fib_result *result = (struct fib_result *) arg->result; 106 struct fib_result *result = (struct fib_result *) arg->result;
107 struct net_device *dev = result->fi->fib_dev; 107 struct net_device *dev = NULL;
108
109 if (result->fi)
110 dev = result->fi->fib_dev;
108 111
109 /* do not accept result if the route does 112 /* do not accept result if the route does
110 * not meet the required prefix length 113 * not meet the required prefix length
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index e63f47a4e651..b53f0bf84dca 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -426,8 +426,9 @@ struct fib_alias *fib_find_alias(struct list_head *fah, u8 tos, u32 prio)
426 return NULL; 426 return NULL;
427} 427}
428 428
429int fib_detect_death(struct fib_info *fi, int order, 429static int fib_detect_death(struct fib_info *fi, int order,
430 struct fib_info **last_resort, int *last_idx, int dflt) 430 struct fib_info **last_resort, int *last_idx,
431 int dflt)
431{ 432{
432 struct neighbour *n; 433 struct neighbour *n;
433 int state = NUD_NONE; 434 int state = NUD_NONE;
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 5c0e8bc6e5ba..fb3c5637199d 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -705,7 +705,9 @@ static void icmp_unreach(struct sk_buff *skb)
705 case ICMP_PORT_UNREACH: 705 case ICMP_PORT_UNREACH:
706 break; 706 break;
707 case ICMP_FRAG_NEEDED: 707 case ICMP_FRAG_NEEDED:
708 if (ipv4_config.no_pmtu_disc) { 708 if (net->ipv4.sysctl_ip_no_pmtu_disc == 2) {
709 goto out;
710 } else if (net->ipv4.sysctl_ip_no_pmtu_disc) {
709 LIMIT_NETDEBUG(KERN_INFO pr_fmt("%pI4: fragmentation needed and DF set\n"), 711 LIMIT_NETDEBUG(KERN_INFO pr_fmt("%pI4: fragmentation needed and DF set\n"),
710 &iph->daddr); 712 &iph->daddr);
711 } else { 713 } else {
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 7defdc9ba167..84c4329cbd30 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -310,7 +310,7 @@ igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted)
310 struct ip_sf_list *psf; 310 struct ip_sf_list *psf;
311 int scount = 0; 311 int scount = 0;
312 312
313 for (psf=pmc->sources; psf; psf=psf->sf_next) { 313 for (psf = pmc->sources; psf; psf = psf->sf_next) {
314 if (!is_in(pmc, psf, type, gdeleted, sdeleted)) 314 if (!is_in(pmc, psf, type, gdeleted, sdeleted))
315 continue; 315 continue;
316 scount++; 316 scount++;
@@ -463,7 +463,7 @@ static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc,
463 } 463 }
464 first = 1; 464 first = 1;
465 psf_prev = NULL; 465 psf_prev = NULL;
466 for (psf=*psf_list; psf; psf=psf_next) { 466 for (psf = *psf_list; psf; psf = psf_next) {
467 __be32 *psrc; 467 __be32 *psrc;
468 468
469 psf_next = psf->sf_next; 469 psf_next = psf->sf_next;
@@ -520,7 +520,7 @@ empty_source:
520 return skb; 520 return skb;
521 if (pmc->crcount || isquery) { 521 if (pmc->crcount || isquery) {
522 /* make sure we have room for group header */ 522 /* make sure we have room for group header */
523 if (skb && AVAILABLE(skb)<sizeof(struct igmpv3_grec)) { 523 if (skb && AVAILABLE(skb) < sizeof(struct igmpv3_grec)) {
524 igmpv3_sendpack(skb); 524 igmpv3_sendpack(skb);
525 skb = NULL; /* add_grhead will get a new one */ 525 skb = NULL; /* add_grhead will get a new one */
526 } 526 }
@@ -576,7 +576,7 @@ static void igmpv3_clear_zeros(struct ip_sf_list **ppsf)
576 struct ip_sf_list *psf_prev, *psf_next, *psf; 576 struct ip_sf_list *psf_prev, *psf_next, *psf;
577 577
578 psf_prev = NULL; 578 psf_prev = NULL;
579 for (psf=*ppsf; psf; psf = psf_next) { 579 for (psf = *ppsf; psf; psf = psf_next) {
580 psf_next = psf->sf_next; 580 psf_next = psf->sf_next;
581 if (psf->sf_crcount == 0) { 581 if (psf->sf_crcount == 0) {
582 if (psf_prev) 582 if (psf_prev)
@@ -600,7 +600,7 @@ static void igmpv3_send_cr(struct in_device *in_dev)
600 600
601 /* deleted MCA's */ 601 /* deleted MCA's */
602 pmc_prev = NULL; 602 pmc_prev = NULL;
603 for (pmc=in_dev->mc_tomb; pmc; pmc=pmc_next) { 603 for (pmc = in_dev->mc_tomb; pmc; pmc = pmc_next) {
604 pmc_next = pmc->next; 604 pmc_next = pmc->next;
605 if (pmc->sfmode == MCAST_INCLUDE) { 605 if (pmc->sfmode == MCAST_INCLUDE) {
606 type = IGMPV3_BLOCK_OLD_SOURCES; 606 type = IGMPV3_BLOCK_OLD_SOURCES;
@@ -764,7 +764,7 @@ static void igmp_ifc_event(struct in_device *in_dev)
764 764
765static void igmp_timer_expire(unsigned long data) 765static void igmp_timer_expire(unsigned long data)
766{ 766{
767 struct ip_mc_list *im=(struct ip_mc_list *)data; 767 struct ip_mc_list *im = (struct ip_mc_list *)data;
768 struct in_device *in_dev = im->interface; 768 struct in_device *in_dev = im->interface;
769 769
770 spin_lock(&im->lock); 770 spin_lock(&im->lock);
@@ -794,10 +794,10 @@ static int igmp_xmarksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs)
794 int i, scount; 794 int i, scount;
795 795
796 scount = 0; 796 scount = 0;
797 for (psf=pmc->sources; psf; psf=psf->sf_next) { 797 for (psf = pmc->sources; psf; psf = psf->sf_next) {
798 if (scount == nsrcs) 798 if (scount == nsrcs)
799 break; 799 break;
800 for (i=0; i<nsrcs; i++) { 800 for (i = 0; i < nsrcs; i++) {
801 /* skip inactive filters */ 801 /* skip inactive filters */
802 if (psf->sf_count[MCAST_INCLUDE] || 802 if (psf->sf_count[MCAST_INCLUDE] ||
803 pmc->sfcount[MCAST_EXCLUDE] != 803 pmc->sfcount[MCAST_EXCLUDE] !=
@@ -825,10 +825,10 @@ static int igmp_marksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs)
825 825
826 /* mark INCLUDE-mode sources */ 826 /* mark INCLUDE-mode sources */
827 scount = 0; 827 scount = 0;
828 for (psf=pmc->sources; psf; psf=psf->sf_next) { 828 for (psf = pmc->sources; psf; psf = psf->sf_next) {
829 if (scount == nsrcs) 829 if (scount == nsrcs)
830 break; 830 break;
831 for (i=0; i<nsrcs; i++) 831 for (i = 0; i < nsrcs; i++)
832 if (srcs[i] == psf->sf_inaddr) { 832 if (srcs[i] == psf->sf_inaddr) {
833 psf->sf_gsresp = 1; 833 psf->sf_gsresp = 1;
834 scount++; 834 scount++;
@@ -1103,7 +1103,7 @@ static void igmpv3_add_delrec(struct in_device *in_dev, struct ip_mc_list *im)
1103 pmc->tomb = im->tomb; 1103 pmc->tomb = im->tomb;
1104 pmc->sources = im->sources; 1104 pmc->sources = im->sources;
1105 im->tomb = im->sources = NULL; 1105 im->tomb = im->sources = NULL;
1106 for (psf=pmc->sources; psf; psf=psf->sf_next) 1106 for (psf = pmc->sources; psf; psf = psf->sf_next)
1107 psf->sf_crcount = pmc->crcount; 1107 psf->sf_crcount = pmc->crcount;
1108 } 1108 }
1109 spin_unlock_bh(&im->lock); 1109 spin_unlock_bh(&im->lock);
@@ -1121,7 +1121,7 @@ static void igmpv3_del_delrec(struct in_device *in_dev, __be32 multiaddr)
1121 1121
1122 spin_lock_bh(&in_dev->mc_tomb_lock); 1122 spin_lock_bh(&in_dev->mc_tomb_lock);
1123 pmc_prev = NULL; 1123 pmc_prev = NULL;
1124 for (pmc=in_dev->mc_tomb; pmc; pmc=pmc->next) { 1124 for (pmc = in_dev->mc_tomb; pmc; pmc = pmc->next) {
1125 if (pmc->multiaddr == multiaddr) 1125 if (pmc->multiaddr == multiaddr)
1126 break; 1126 break;
1127 pmc_prev = pmc; 1127 pmc_prev = pmc;
@@ -1134,7 +1134,7 @@ static void igmpv3_del_delrec(struct in_device *in_dev, __be32 multiaddr)
1134 } 1134 }
1135 spin_unlock_bh(&in_dev->mc_tomb_lock); 1135 spin_unlock_bh(&in_dev->mc_tomb_lock);
1136 if (pmc) { 1136 if (pmc) {
1137 for (psf=pmc->tomb; psf; psf=psf_next) { 1137 for (psf = pmc->tomb; psf; psf = psf_next) {
1138 psf_next = psf->sf_next; 1138 psf_next = psf->sf_next;
1139 kfree(psf); 1139 kfree(psf);
1140 } 1140 }
@@ -1167,7 +1167,7 @@ static void igmpv3_clear_delrec(struct in_device *in_dev)
1167 psf = pmc->tomb; 1167 psf = pmc->tomb;
1168 pmc->tomb = NULL; 1168 pmc->tomb = NULL;
1169 spin_unlock_bh(&pmc->lock); 1169 spin_unlock_bh(&pmc->lock);
1170 for (; psf; psf=psf_next) { 1170 for (; psf; psf = psf_next) {
1171 psf_next = psf->sf_next; 1171 psf_next = psf->sf_next;
1172 kfree(psf); 1172 kfree(psf);
1173 } 1173 }
@@ -1557,7 +1557,7 @@ static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode,
1557 int rv = 0; 1557 int rv = 0;
1558 1558
1559 psf_prev = NULL; 1559 psf_prev = NULL;
1560 for (psf=pmc->sources; psf; psf=psf->sf_next) { 1560 for (psf = pmc->sources; psf; psf = psf->sf_next) {
1561 if (psf->sf_inaddr == *psfsrc) 1561 if (psf->sf_inaddr == *psfsrc)
1562 break; 1562 break;
1563 psf_prev = psf; 1563 psf_prev = psf;
@@ -1630,7 +1630,7 @@ static int ip_mc_del_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
1630 pmc->sfcount[sfmode]--; 1630 pmc->sfcount[sfmode]--;
1631 } 1631 }
1632 err = 0; 1632 err = 0;
1633 for (i=0; i<sfcount; i++) { 1633 for (i = 0; i < sfcount; i++) {
1634 int rv = ip_mc_del1_src(pmc, sfmode, &psfsrc[i]); 1634 int rv = ip_mc_del1_src(pmc, sfmode, &psfsrc[i]);
1635 1635
1636 changerec |= rv > 0; 1636 changerec |= rv > 0;
@@ -1650,7 +1650,7 @@ static int ip_mc_del_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
1650 pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv : 1650 pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv :
1651 IGMP_Unsolicited_Report_Count; 1651 IGMP_Unsolicited_Report_Count;
1652 in_dev->mr_ifc_count = pmc->crcount; 1652 in_dev->mr_ifc_count = pmc->crcount;
1653 for (psf=pmc->sources; psf; psf = psf->sf_next) 1653 for (psf = pmc->sources; psf; psf = psf->sf_next)
1654 psf->sf_crcount = 0; 1654 psf->sf_crcount = 0;
1655 igmp_ifc_event(pmc->interface); 1655 igmp_ifc_event(pmc->interface);
1656 } else if (sf_setstate(pmc) || changerec) { 1656 } else if (sf_setstate(pmc) || changerec) {
@@ -1671,7 +1671,7 @@ static int ip_mc_add1_src(struct ip_mc_list *pmc, int sfmode,
1671 struct ip_sf_list *psf, *psf_prev; 1671 struct ip_sf_list *psf, *psf_prev;
1672 1672
1673 psf_prev = NULL; 1673 psf_prev = NULL;
1674 for (psf=pmc->sources; psf; psf=psf->sf_next) { 1674 for (psf = pmc->sources; psf; psf = psf->sf_next) {
1675 if (psf->sf_inaddr == *psfsrc) 1675 if (psf->sf_inaddr == *psfsrc)
1676 break; 1676 break;
1677 psf_prev = psf; 1677 psf_prev = psf;
@@ -1699,7 +1699,7 @@ static void sf_markstate(struct ip_mc_list *pmc)
1699 struct ip_sf_list *psf; 1699 struct ip_sf_list *psf;
1700 int mca_xcount = pmc->sfcount[MCAST_EXCLUDE]; 1700 int mca_xcount = pmc->sfcount[MCAST_EXCLUDE];
1701 1701
1702 for (psf=pmc->sources; psf; psf=psf->sf_next) 1702 for (psf = pmc->sources; psf; psf = psf->sf_next)
1703 if (pmc->sfcount[MCAST_EXCLUDE]) { 1703 if (pmc->sfcount[MCAST_EXCLUDE]) {
1704 psf->sf_oldin = mca_xcount == 1704 psf->sf_oldin = mca_xcount ==
1705 psf->sf_count[MCAST_EXCLUDE] && 1705 psf->sf_count[MCAST_EXCLUDE] &&
@@ -1716,7 +1716,7 @@ static int sf_setstate(struct ip_mc_list *pmc)
1716 int new_in, rv; 1716 int new_in, rv;
1717 1717
1718 rv = 0; 1718 rv = 0;
1719 for (psf=pmc->sources; psf; psf=psf->sf_next) { 1719 for (psf = pmc->sources; psf; psf = psf->sf_next) {
1720 if (pmc->sfcount[MCAST_EXCLUDE]) { 1720 if (pmc->sfcount[MCAST_EXCLUDE]) {
1721 new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] && 1721 new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] &&
1722 !psf->sf_count[MCAST_INCLUDE]; 1722 !psf->sf_count[MCAST_INCLUDE];
@@ -1726,7 +1726,7 @@ static int sf_setstate(struct ip_mc_list *pmc)
1726 if (!psf->sf_oldin) { 1726 if (!psf->sf_oldin) {
1727 struct ip_sf_list *prev = NULL; 1727 struct ip_sf_list *prev = NULL;
1728 1728
1729 for (dpsf=pmc->tomb; dpsf; dpsf=dpsf->sf_next) { 1729 for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next) {
1730 if (dpsf->sf_inaddr == psf->sf_inaddr) 1730 if (dpsf->sf_inaddr == psf->sf_inaddr)
1731 break; 1731 break;
1732 prev = dpsf; 1732 prev = dpsf;
@@ -1748,7 +1748,7 @@ static int sf_setstate(struct ip_mc_list *pmc)
1748 * add or update "delete" records if an active filter 1748 * add or update "delete" records if an active filter
1749 * is now inactive 1749 * is now inactive
1750 */ 1750 */
1751 for (dpsf=pmc->tomb; dpsf; dpsf=dpsf->sf_next) 1751 for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next)
1752 if (dpsf->sf_inaddr == psf->sf_inaddr) 1752 if (dpsf->sf_inaddr == psf->sf_inaddr)
1753 break; 1753 break;
1754 if (!dpsf) { 1754 if (!dpsf) {
@@ -1800,7 +1800,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
1800 if (!delta) 1800 if (!delta)
1801 pmc->sfcount[sfmode]++; 1801 pmc->sfcount[sfmode]++;
1802 err = 0; 1802 err = 0;
1803 for (i=0; i<sfcount; i++) { 1803 for (i = 0; i < sfcount; i++) {
1804 err = ip_mc_add1_src(pmc, sfmode, &psfsrc[i]); 1804 err = ip_mc_add1_src(pmc, sfmode, &psfsrc[i]);
1805 if (err) 1805 if (err)
1806 break; 1806 break;
@@ -1810,7 +1810,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
1810 1810
1811 if (!delta) 1811 if (!delta)
1812 pmc->sfcount[sfmode]--; 1812 pmc->sfcount[sfmode]--;
1813 for (j=0; j<i; j++) 1813 for (j = 0; j < i; j++)
1814 (void) ip_mc_del1_src(pmc, sfmode, &psfsrc[j]); 1814 (void) ip_mc_del1_src(pmc, sfmode, &psfsrc[j]);
1815 } else if (isexclude != (pmc->sfcount[MCAST_EXCLUDE] != 0)) { 1815 } else if (isexclude != (pmc->sfcount[MCAST_EXCLUDE] != 0)) {
1816#ifdef CONFIG_IP_MULTICAST 1816#ifdef CONFIG_IP_MULTICAST
@@ -1829,7 +1829,7 @@ static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode,
1829 pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv : 1829 pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv :
1830 IGMP_Unsolicited_Report_Count; 1830 IGMP_Unsolicited_Report_Count;
1831 in_dev->mr_ifc_count = pmc->crcount; 1831 in_dev->mr_ifc_count = pmc->crcount;
1832 for (psf=pmc->sources; psf; psf = psf->sf_next) 1832 for (psf = pmc->sources; psf; psf = psf->sf_next)
1833 psf->sf_crcount = 0; 1833 psf->sf_crcount = 0;
1834 igmp_ifc_event(in_dev); 1834 igmp_ifc_event(in_dev);
1835 } else if (sf_setstate(pmc)) { 1835 } else if (sf_setstate(pmc)) {
@@ -1844,12 +1844,12 @@ static void ip_mc_clear_src(struct ip_mc_list *pmc)
1844{ 1844{
1845 struct ip_sf_list *psf, *nextpsf; 1845 struct ip_sf_list *psf, *nextpsf;
1846 1846
1847 for (psf=pmc->tomb; psf; psf=nextpsf) { 1847 for (psf = pmc->tomb; psf; psf = nextpsf) {
1848 nextpsf = psf->sf_next; 1848 nextpsf = psf->sf_next;
1849 kfree(psf); 1849 kfree(psf);
1850 } 1850 }
1851 pmc->tomb = NULL; 1851 pmc->tomb = NULL;
1852 for (psf=pmc->sources; psf; psf=nextpsf) { 1852 for (psf = pmc->sources; psf; psf = nextpsf) {
1853 nextpsf = psf->sf_next; 1853 nextpsf = psf->sf_next;
1854 kfree(psf); 1854 kfree(psf);
1855 } 1855 }
@@ -2043,7 +2043,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
2043 if (!psl) 2043 if (!psl)
2044 goto done; /* err = -EADDRNOTAVAIL */ 2044 goto done; /* err = -EADDRNOTAVAIL */
2045 rv = !0; 2045 rv = !0;
2046 for (i=0; i<psl->sl_count; i++) { 2046 for (i = 0; i < psl->sl_count; i++) {
2047 rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr, 2047 rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr,
2048 sizeof(__be32)); 2048 sizeof(__be32));
2049 if (rv == 0) 2049 if (rv == 0)
@@ -2062,7 +2062,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
2062 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, omode, 1, 2062 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, omode, 1,
2063 &mreqs->imr_sourceaddr, 1); 2063 &mreqs->imr_sourceaddr, 1);
2064 2064
2065 for (j=i+1; j<psl->sl_count; j++) 2065 for (j = i+1; j < psl->sl_count; j++)
2066 psl->sl_addr[j-1] = psl->sl_addr[j]; 2066 psl->sl_addr[j-1] = psl->sl_addr[j];
2067 psl->sl_count--; 2067 psl->sl_count--;
2068 err = 0; 2068 err = 0;
@@ -2088,7 +2088,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
2088 newpsl->sl_max = count; 2088 newpsl->sl_max = count;
2089 newpsl->sl_count = count - IP_SFBLOCK; 2089 newpsl->sl_count = count - IP_SFBLOCK;
2090 if (psl) { 2090 if (psl) {
2091 for (i=0; i<psl->sl_count; i++) 2091 for (i = 0; i < psl->sl_count; i++)
2092 newpsl->sl_addr[i] = psl->sl_addr[i]; 2092 newpsl->sl_addr[i] = psl->sl_addr[i];
2093 /* decrease mem now to avoid the memleak warning */ 2093 /* decrease mem now to avoid the memleak warning */
2094 atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc); 2094 atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc);
@@ -2098,7 +2098,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
2098 psl = newpsl; 2098 psl = newpsl;
2099 } 2099 }
2100 rv = 1; /* > 0 for insert logic below if sl_count is 0 */ 2100 rv = 1; /* > 0 for insert logic below if sl_count is 0 */
2101 for (i=0; i<psl->sl_count; i++) { 2101 for (i = 0; i < psl->sl_count; i++) {
2102 rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr, 2102 rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr,
2103 sizeof(__be32)); 2103 sizeof(__be32));
2104 if (rv == 0) 2104 if (rv == 0)
@@ -2106,7 +2106,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
2106 } 2106 }
2107 if (rv == 0) /* address already there is an error */ 2107 if (rv == 0) /* address already there is an error */
2108 goto done; 2108 goto done;
2109 for (j=psl->sl_count-1; j>=i; j--) 2109 for (j = psl->sl_count-1; j >= i; j--)
2110 psl->sl_addr[j+1] = psl->sl_addr[j]; 2110 psl->sl_addr[j+1] = psl->sl_addr[j];
2111 psl->sl_addr[i] = mreqs->imr_sourceaddr; 2111 psl->sl_addr[i] = mreqs->imr_sourceaddr;
2112 psl->sl_count++; 2112 psl->sl_count++;
@@ -2305,7 +2305,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
2305 copy_to_user(optval, gsf, GROUP_FILTER_SIZE(0))) { 2305 copy_to_user(optval, gsf, GROUP_FILTER_SIZE(0))) {
2306 return -EFAULT; 2306 return -EFAULT;
2307 } 2307 }
2308 for (i=0; i<copycount; i++) { 2308 for (i = 0; i < copycount; i++) {
2309 struct sockaddr_storage ss; 2309 struct sockaddr_storage ss;
2310 2310
2311 psin = (struct sockaddr_in *)&ss; 2311 psin = (struct sockaddr_in *)&ss;
@@ -2350,7 +2350,7 @@ int ip_mc_sf_allow(struct sock *sk, __be32 loc_addr, __be32 rmt_addr, int dif)
2350 if (!psl) 2350 if (!psl)
2351 goto unlock; 2351 goto unlock;
2352 2352
2353 for (i=0; i<psl->sl_count; i++) { 2353 for (i = 0; i < psl->sl_count; i++) {
2354 if (psl->sl_addr[i] == rmt_addr) 2354 if (psl->sl_addr[i] == rmt_addr)
2355 break; 2355 break;
2356 } 2356 }
@@ -2423,7 +2423,7 @@ int ip_check_mc_rcu(struct in_device *in_dev, __be32 mc_addr, __be32 src_addr, u
2423 rv = 1; 2423 rv = 1;
2424 } else if (im) { 2424 } else if (im) {
2425 if (src_addr) { 2425 if (src_addr) {
2426 for (psf=im->sources; psf; psf=psf->sf_next) { 2426 for (psf = im->sources; psf; psf = psf->sf_next) {
2427 if (psf->sf_inaddr == src_addr) 2427 if (psf->sf_inaddr == src_addr)
2428 break; 2428 break;
2429 } 2429 }
diff --git a/net/ipv4/inet_lro.c b/net/ipv4/inet_lro.c
index 1975f52933c5..f17ea49b28fb 100644
--- a/net/ipv4/inet_lro.c
+++ b/net/ipv4/inet_lro.c
@@ -230,29 +230,6 @@ static void lro_add_packet(struct net_lro_desc *lro_desc, struct sk_buff *skb,
230 lro_desc->last_skb = skb; 230 lro_desc->last_skb = skb;
231} 231}
232 232
233static void lro_add_frags(struct net_lro_desc *lro_desc,
234 int len, int hlen, int truesize,
235 struct skb_frag_struct *skb_frags,
236 struct iphdr *iph, struct tcphdr *tcph)
237{
238 struct sk_buff *skb = lro_desc->parent;
239 int tcp_data_len = TCP_PAYLOAD_LENGTH(iph, tcph);
240
241 lro_add_common(lro_desc, iph, tcph, tcp_data_len);
242
243 skb->truesize += truesize;
244
245 skb_frags[0].page_offset += hlen;
246 skb_frag_size_sub(&skb_frags[0], hlen);
247
248 while (tcp_data_len > 0) {
249 *(lro_desc->next_frag) = *skb_frags;
250 tcp_data_len -= skb_frag_size(skb_frags);
251 lro_desc->next_frag++;
252 skb_frags++;
253 skb_shinfo(skb)->nr_frags++;
254 }
255}
256 233
257static int lro_check_tcp_conn(struct net_lro_desc *lro_desc, 234static int lro_check_tcp_conn(struct net_lro_desc *lro_desc,
258 struct iphdr *iph, 235 struct iphdr *iph,
@@ -371,128 +348,6 @@ out:
371 return 1; 348 return 1;
372} 349}
373 350
374
375static struct sk_buff *lro_gen_skb(struct net_lro_mgr *lro_mgr,
376 struct skb_frag_struct *frags,
377 int len, int true_size,
378 void *mac_hdr,
379 int hlen, __wsum sum,
380 u32 ip_summed)
381{
382 struct sk_buff *skb;
383 struct skb_frag_struct *skb_frags;
384 int data_len = len;
385 int hdr_len = min(len, hlen);
386
387 skb = netdev_alloc_skb(lro_mgr->dev, hlen + lro_mgr->frag_align_pad);
388 if (!skb)
389 return NULL;
390
391 skb_reserve(skb, lro_mgr->frag_align_pad);
392 skb->len = len;
393 skb->data_len = len - hdr_len;
394 skb->truesize += true_size;
395 skb->tail += hdr_len;
396
397 memcpy(skb->data, mac_hdr, hdr_len);
398
399 skb_frags = skb_shinfo(skb)->frags;
400 while (data_len > 0) {
401 *skb_frags = *frags;
402 data_len -= skb_frag_size(frags);
403 skb_frags++;
404 frags++;
405 skb_shinfo(skb)->nr_frags++;
406 }
407
408 skb_shinfo(skb)->frags[0].page_offset += hdr_len;
409 skb_frag_size_sub(&skb_shinfo(skb)->frags[0], hdr_len);
410
411 skb->ip_summed = ip_summed;
412 skb->csum = sum;
413 skb->protocol = eth_type_trans(skb, lro_mgr->dev);
414 return skb;
415}
416
417static struct sk_buff *__lro_proc_segment(struct net_lro_mgr *lro_mgr,
418 struct skb_frag_struct *frags,
419 int len, int true_size,
420 void *priv, __wsum sum)
421{
422 struct net_lro_desc *lro_desc;
423 struct iphdr *iph;
424 struct tcphdr *tcph;
425 struct sk_buff *skb;
426 u64 flags;
427 void *mac_hdr;
428 int mac_hdr_len;
429 int hdr_len = LRO_MAX_PG_HLEN;
430 int vlan_hdr_len = 0;
431
432 if (!lro_mgr->get_frag_header ||
433 lro_mgr->get_frag_header(frags, (void *)&mac_hdr, (void *)&iph,
434 (void *)&tcph, &flags, priv)) {
435 mac_hdr = skb_frag_address(frags);
436 goto out1;
437 }
438
439 if (!(flags & LRO_IPV4) || !(flags & LRO_TCP))
440 goto out1;
441
442 hdr_len = (int)((void *)(tcph) + TCP_HDR_LEN(tcph) - mac_hdr);
443 mac_hdr_len = (int)((void *)(iph) - mac_hdr);
444
445 lro_desc = lro_get_desc(lro_mgr, lro_mgr->lro_arr, iph, tcph);
446 if (!lro_desc)
447 goto out1;
448
449 if (!lro_desc->active) { /* start new lro session */
450 if (lro_tcp_ip_check(iph, tcph, len - mac_hdr_len, NULL))
451 goto out1;
452
453 skb = lro_gen_skb(lro_mgr, frags, len, true_size, mac_hdr,
454 hdr_len, 0, lro_mgr->ip_summed_aggr);
455 if (!skb)
456 goto out;
457
458 if ((skb->protocol == htons(ETH_P_8021Q)) &&
459 !(lro_mgr->features & LRO_F_EXTRACT_VLAN_ID))
460 vlan_hdr_len = VLAN_HLEN;
461
462 iph = (void *)(skb->data + vlan_hdr_len);
463 tcph = (void *)((u8 *)skb->data + vlan_hdr_len
464 + IP_HDR_LEN(iph));
465
466 lro_init_desc(lro_desc, skb, iph, tcph);
467 LRO_INC_STATS(lro_mgr, aggregated);
468 return NULL;
469 }
470
471 if (lro_desc->tcp_next_seq != ntohl(tcph->seq))
472 goto out2;
473
474 if (lro_tcp_ip_check(iph, tcph, len - mac_hdr_len, lro_desc))
475 goto out2;
476
477 lro_add_frags(lro_desc, len, hdr_len, true_size, frags, iph, tcph);
478 LRO_INC_STATS(lro_mgr, aggregated);
479
480 if ((skb_shinfo(lro_desc->parent)->nr_frags >= lro_mgr->max_aggr) ||
481 lro_desc->parent->len > (0xFFFF - lro_mgr->dev->mtu))
482 lro_flush(lro_mgr, lro_desc);
483
484 return NULL;
485
486out2: /* send aggregated packets to the stack */
487 lro_flush(lro_mgr, lro_desc);
488
489out1: /* Original packet has to be posted to the stack */
490 skb = lro_gen_skb(lro_mgr, frags, len, true_size, mac_hdr,
491 hdr_len, sum, lro_mgr->ip_summed);
492out:
493 return skb;
494}
495
496void lro_receive_skb(struct net_lro_mgr *lro_mgr, 351void lro_receive_skb(struct net_lro_mgr *lro_mgr,
497 struct sk_buff *skb, 352 struct sk_buff *skb,
498 void *priv) 353 void *priv)
@@ -506,23 +361,6 @@ void lro_receive_skb(struct net_lro_mgr *lro_mgr,
506} 361}
507EXPORT_SYMBOL(lro_receive_skb); 362EXPORT_SYMBOL(lro_receive_skb);
508 363
509void lro_receive_frags(struct net_lro_mgr *lro_mgr,
510 struct skb_frag_struct *frags,
511 int len, int true_size, void *priv, __wsum sum)
512{
513 struct sk_buff *skb;
514
515 skb = __lro_proc_segment(lro_mgr, frags, len, true_size, priv, sum);
516 if (!skb)
517 return;
518
519 if (lro_mgr->features & LRO_F_NAPI)
520 netif_receive_skb(skb);
521 else
522 netif_rx(skb);
523}
524EXPORT_SYMBOL(lro_receive_frags);
525
526void lro_flush_all(struct net_lro_mgr *lro_mgr) 364void lro_flush_all(struct net_lro_mgr *lro_mgr)
527{ 365{
528 int i; 366 int i;
@@ -534,14 +372,3 @@ void lro_flush_all(struct net_lro_mgr *lro_mgr)
534 } 372 }
535} 373}
536EXPORT_SYMBOL(lro_flush_all); 374EXPORT_SYMBOL(lro_flush_all);
537
538void lro_flush_pkt(struct net_lro_mgr *lro_mgr,
539 struct iphdr *iph, struct tcphdr *tcph)
540{
541 struct net_lro_desc *lro_desc;
542
543 lro_desc = lro_get_desc(lro_mgr, lro_mgr->lro_arr, iph, tcph);
544 if (lro_desc->active)
545 lro_flush(lro_mgr, lro_desc);
546}
547EXPORT_SYMBOL(lro_flush_pkt);
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index 33d5537881ed..48f424465112 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -109,13 +109,6 @@ static inline void flush_check(struct inet_peer_base *base, int family)
109 } 109 }
110} 110}
111 111
112void inetpeer_invalidate_family(int family)
113{
114 atomic_t *fp = inetpeer_seq_ptr(family);
115
116 atomic_inc(fp);
117}
118
119#define PEER_MAXDEPTH 40 /* sufficient for about 2^27 nodes */ 112#define PEER_MAXDEPTH 40 /* sufficient for about 2^27 nodes */
120 113
121/* Exported for sysctl_net_ipv4. */ 114/* Exported for sysctl_net_ipv4. */
@@ -227,7 +220,7 @@ static int addr_compare(const struct inetpeer_addr *a,
227 stackptr = _stack; \ 220 stackptr = _stack; \
228 *stackptr++ = &_base->root; \ 221 *stackptr++ = &_base->root; \
229 for (u = rcu_deref_locked(_base->root, _base); \ 222 for (u = rcu_deref_locked(_base->root, _base); \
230 u != peer_avl_empty; ) { \ 223 u != peer_avl_empty;) { \
231 int cmp = addr_compare(_daddr, &u->daddr); \ 224 int cmp = addr_compare(_daddr, &u->daddr); \
232 if (cmp == 0) \ 225 if (cmp == 0) \
233 break; \ 226 break; \
@@ -282,7 +275,7 @@ static struct inet_peer *lookup_rcu(const struct inetpeer_addr *daddr,
282 *stackptr++ = &start->avl_left; \ 275 *stackptr++ = &start->avl_left; \
283 v = &start->avl_left; \ 276 v = &start->avl_left; \
284 for (u = rcu_deref_locked(*v, base); \ 277 for (u = rcu_deref_locked(*v, base); \
285 u->avl_right != peer_avl_empty_rcu; ) { \ 278 u->avl_right != peer_avl_empty_rcu;) { \
286 v = &u->avl_right; \ 279 v = &u->avl_right; \
287 *stackptr++ = v; \ 280 *stackptr++ = v; \
288 u = rcu_deref_locked(*v, base); \ 281 u = rcu_deref_locked(*v, base); \
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 2481993a4970..c10a3ce5cbff 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -704,7 +704,7 @@ struct sk_buff *ip_check_defrag(struct sk_buff *skb, u32 user)
704 memset(IPCB(skb), 0, sizeof(struct inet_skb_parm)); 704 memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
705 if (ip_defrag(skb, user)) 705 if (ip_defrag(skb, user))
706 return NULL; 706 return NULL;
707 skb->rxhash = 0; 707 skb_clear_hash(skb);
708 } 708 }
709 } 709 }
710 return skb; 710 return skb;
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c
index ec7264514a82..dd9d90b44f97 100644
--- a/net/ipv4/ip_options.c
+++ b/net/ipv4/ip_options.c
@@ -167,7 +167,7 @@ int ip_options_echo(struct ip_options *dopt, struct sk_buff *skb)
167 soffset -= 4; 167 soffset -= 4;
168 if (soffset > 3) { 168 if (soffset > 3) {
169 memcpy(&faddr, &start[soffset-1], 4); 169 memcpy(&faddr, &start[soffset-1], 4);
170 for (soffset-=4, doffset=4; soffset > 3; soffset-=4, doffset+=4) 170 for (soffset -= 4, doffset = 4; soffset > 3; soffset -= 4, doffset += 4)
171 memcpy(&dptr[doffset-1], &start[soffset-1], 4); 171 memcpy(&dptr[doffset-1], &start[soffset-1], 4);
172 /* 172 /*
173 * RFC1812 requires to fix illegal source routes. 173 * RFC1812 requires to fix illegal source routes.
@@ -227,7 +227,7 @@ void ip_options_fragment(struct sk_buff *skb)
227 continue; 227 continue;
228 } 228 }
229 optlen = optptr[1]; 229 optlen = optptr[1];
230 if (optlen<2 || optlen>l) 230 if (optlen < 2 || optlen > l)
231 return; 231 return;
232 if (!IPOPT_COPIED(*optptr)) 232 if (!IPOPT_COPIED(*optptr))
233 memset(optptr, IPOPT_NOOP, optlen); 233 memset(optptr, IPOPT_NOOP, optlen);
@@ -276,7 +276,7 @@ int ip_options_compile(struct net *net,
276 for (l = opt->optlen; l > 0; ) { 276 for (l = opt->optlen; l > 0; ) {
277 switch (*optptr) { 277 switch (*optptr) {
278 case IPOPT_END: 278 case IPOPT_END:
279 for (optptr++, l--; l>0; optptr++, l--) { 279 for (optptr++, l--; l > 0; optptr++, l--) {
280 if (*optptr != IPOPT_END) { 280 if (*optptr != IPOPT_END) {
281 *optptr = IPOPT_END; 281 *optptr = IPOPT_END;
282 opt->is_changed = 1; 282 opt->is_changed = 1;
@@ -289,7 +289,7 @@ int ip_options_compile(struct net *net,
289 continue; 289 continue;
290 } 290 }
291 optlen = optptr[1]; 291 optlen = optptr[1];
292 if (optlen<2 || optlen>l) { 292 if (optlen < 2 || optlen > l) {
293 pp_ptr = optptr; 293 pp_ptr = optptr;
294 goto error; 294 goto error;
295 } 295 }
@@ -572,7 +572,7 @@ void ip_forward_options(struct sk_buff *skb)
572 572
573 optptr = raw + opt->srr; 573 optptr = raw + opt->srr;
574 574
575 for ( srrptr=optptr[2], srrspace = optptr[1]; 575 for ( srrptr = optptr[2], srrspace = optptr[1];
576 srrptr <= srrspace; 576 srrptr <= srrspace;
577 srrptr += 4 577 srrptr += 4
578 ) { 578 ) {
@@ -628,7 +628,7 @@ int ip_options_rcv_srr(struct sk_buff *skb)
628 if (rt->rt_type != RTN_LOCAL) 628 if (rt->rt_type != RTN_LOCAL)
629 return -EINVAL; 629 return -EINVAL;
630 630
631 for (srrptr=optptr[2], srrspace = optptr[1]; srrptr <= srrspace; srrptr += 4) { 631 for (srrptr = optptr[2], srrspace = optptr[1]; srrptr <= srrspace; srrptr += 4) {
632 if (srrptr + 3 > srrspace) { 632 if (srrptr + 3 > srrspace) {
633 icmp_send(skb, ICMP_PARAMETERPROB, 0, htonl((opt->srr+2)<<24)); 633 icmp_send(skb, ICMP_PARAMETERPROB, 0, htonl((opt->srr+2)<<24));
634 return -EINVAL; 634 return -EINVAL;
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 3f858266fa7e..a9fc435dc89f 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -386,7 +386,7 @@ void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 port, u32 inf
386/* 386/*
387 * Handle MSG_ERRQUEUE 387 * Handle MSG_ERRQUEUE
388 */ 388 */
389int ip_recv_error(struct sock *sk, struct msghdr *msg, int len) 389int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
390{ 390{
391 struct sock_exterr_skb *serr; 391 struct sock_exterr_skb *serr;
392 struct sk_buff *skb, *skb2; 392 struct sk_buff *skb, *skb2;
@@ -423,6 +423,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len)
423 serr->addr_offset); 423 serr->addr_offset);
424 sin->sin_port = serr->port; 424 sin->sin_port = serr->port;
425 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero)); 425 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
426 *addr_len = sizeof(*sin);
426 } 427 }
427 428
428 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err)); 429 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
@@ -1050,7 +1051,7 @@ e_inval:
1050 * 1051 *
1051 * To support IP_CMSG_PKTINFO option, we store rt_iif and specific 1052 * To support IP_CMSG_PKTINFO option, we store rt_iif and specific
1052 * destination in skb->cb[] before dst drop. 1053 * destination in skb->cb[] before dst drop.
1053 * This way, receiver doesnt make cache line misses to read rtable. 1054 * This way, receiver doesn't make cache line misses to read rtable.
1054 */ 1055 */
1055void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb) 1056void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb)
1056{ 1057{
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 42ffbc8d65c6..6156f4ef5e91 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -56,7 +56,7 @@ int iptunnel_xmit(struct rtable *rt, struct sk_buff *skb,
56 56
57 skb_scrub_packet(skb, xnet); 57 skb_scrub_packet(skb, xnet);
58 58
59 skb->rxhash = 0; 59 skb_clear_hash(skb);
60 skb_dst_set(skb, &rt->dst); 60 skb_dst_set(skb, &rt->dst);
61 memset(IPCB(skb), 0, sizeof(*IPCB(skb))); 61 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
62 62
@@ -107,8 +107,7 @@ int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto)
107 107
108 nf_reset(skb); 108 nf_reset(skb);
109 secpath_reset(skb); 109 secpath_reset(skb);
110 if (!skb->l4_rxhash) 110 skb_clear_hash_if_not_l4(skb);
111 skb->rxhash = 0;
112 skb_dst_drop(skb); 111 skb_dst_drop(skb);
113 skb->vlan_tci = 0; 112 skb->vlan_tci = 0;
114 skb_set_queue_mapping(skb, 0); 113 skb_set_queue_mapping(skb, 0);
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 62212c772a4b..421a24934ffd 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -425,6 +425,7 @@ struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v)
425 goto failure; 425 goto failure;
426 426
427 ipv4_devconf_setall(in_dev); 427 ipv4_devconf_setall(in_dev);
428 neigh_parms_data_state_setall(in_dev->arp_parms);
428 IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0; 429 IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0;
429 430
430 if (dev_open(dev)) 431 if (dev_open(dev))
@@ -517,6 +518,7 @@ static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt)
517 } 518 }
518 519
519 ipv4_devconf_setall(in_dev); 520 ipv4_devconf_setall(in_dev);
521 neigh_parms_data_state_setall(in_dev->arp_parms);
520 IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0; 522 IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0;
521 rcu_read_unlock(); 523 rcu_read_unlock();
522 524
diff --git a/net/ipv4/netfilter/ipt_SYNPROXY.c b/net/ipv4/netfilter/ipt_SYNPROXY.c
index f13bd91d9a56..a313c3fbeb46 100644
--- a/net/ipv4/netfilter/ipt_SYNPROXY.c
+++ b/net/ipv4/netfilter/ipt_SYNPROXY.c
@@ -423,6 +423,7 @@ static void synproxy_tg4_destroy(const struct xt_tgdtor_param *par)
423static struct xt_target synproxy_tg4_reg __read_mostly = { 423static struct xt_target synproxy_tg4_reg __read_mostly = {
424 .name = "SYNPROXY", 424 .name = "SYNPROXY",
425 .family = NFPROTO_IPV4, 425 .family = NFPROTO_IPV4,
426 .hooks = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD),
426 .target = synproxy_tg4, 427 .target = synproxy_tg4,
427 .targetsize = sizeof(struct xt_synproxy_info), 428 .targetsize = sizeof(struct xt_synproxy_info),
428 .checkentry = synproxy_tg4_check, 429 .checkentry = synproxy_tg4_check,
diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
index 5f011cc89cd9..d551e31b416e 100644
--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
@@ -34,8 +34,7 @@
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details. 35 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License 36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software 37 * along with this program; if not, see <http://www.gnu.org/licenses/>.
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 * 38 *
40 * Author: James Morris <jmorris@intercode.com.au> 39 * Author: James Morris <jmorris@intercode.com.au>
41 * 40 *
@@ -462,14 +461,14 @@ static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
462 } 461 }
463 462
464 if (subid < 40) { 463 if (subid < 40) {
465 optr [0] = 0; 464 optr[0] = 0;
466 optr [1] = subid; 465 optr[1] = subid;
467 } else if (subid < 80) { 466 } else if (subid < 80) {
468 optr [0] = 1; 467 optr[0] = 1;
469 optr [1] = subid - 40; 468 optr[1] = subid - 40;
470 } else { 469 } else {
471 optr [0] = 2; 470 optr[0] = 2;
472 optr [1] = subid - 80; 471 optr[1] = subid - 80;
473 } 472 }
474 473
475 *len = 2; 474 *len = 2;
diff --git a/net/ipv4/netfilter/nft_reject_ipv4.c b/net/ipv4/netfilter/nft_reject_ipv4.c
index fff5ba1a33b7..4a5e94ac314a 100644
--- a/net/ipv4/netfilter/nft_reject_ipv4.c
+++ b/net/ipv4/netfilter/nft_reject_ipv4.c
@@ -72,7 +72,7 @@ static int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
72{ 72{
73 const struct nft_reject *priv = nft_expr_priv(expr); 73 const struct nft_reject *priv = nft_expr_priv(expr);
74 74
75 if (nla_put_be32(skb, NFTA_REJECT_TYPE, priv->type)) 75 if (nla_put_be32(skb, NFTA_REJECT_TYPE, htonl(priv->type)))
76 goto nla_put_failure; 76 goto nla_put_failure;
77 77
78 switch (priv->type) { 78 switch (priv->type) {
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 876c6ca2d8f9..cae5262a337c 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -53,8 +53,12 @@
53#include <net/transp_v6.h> 53#include <net/transp_v6.h>
54#endif 54#endif
55 55
56struct ping_table {
57 struct hlist_nulls_head hash[PING_HTABLE_SIZE];
58 rwlock_t lock;
59};
56 60
57struct ping_table ping_table; 61static struct ping_table ping_table;
58struct pingv6_ops pingv6_ops; 62struct pingv6_ops pingv6_ops;
59EXPORT_SYMBOL_GPL(pingv6_ops); 63EXPORT_SYMBOL_GPL(pingv6_ops);
60 64
@@ -668,8 +672,8 @@ int ping_common_sendmsg(int family, struct msghdr *msg, size_t len,
668} 672}
669EXPORT_SYMBOL_GPL(ping_common_sendmsg); 673EXPORT_SYMBOL_GPL(ping_common_sendmsg);
670 674
671int ping_v4_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 675static int ping_v4_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
672 size_t len) 676 size_t len)
673{ 677{
674 struct net *net = sock_net(sk); 678 struct net *net = sock_net(sk);
675 struct flowi4 fl4; 679 struct flowi4 fl4;
@@ -772,7 +776,7 @@ int ping_v4_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
772 err = PTR_ERR(rt); 776 err = PTR_ERR(rt);
773 rt = NULL; 777 rt = NULL;
774 if (err == -ENETUNREACH) 778 if (err == -ENETUNREACH)
775 IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES); 779 IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
776 goto out; 780 goto out;
777 } 781 }
778 782
@@ -841,10 +845,11 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
841 845
842 if (flags & MSG_ERRQUEUE) { 846 if (flags & MSG_ERRQUEUE) {
843 if (family == AF_INET) { 847 if (family == AF_INET) {
844 return ip_recv_error(sk, msg, len); 848 return ip_recv_error(sk, msg, len, addr_len);
845#if IS_ENABLED(CONFIG_IPV6) 849#if IS_ENABLED(CONFIG_IPV6)
846 } else if (family == AF_INET6) { 850 } else if (family == AF_INET6) {
847 return pingv6_ops.ipv6_recv_error(sk, msg, len); 851 return pingv6_ops.ipv6_recv_error(sk, msg, len,
852 addr_len);
848#endif 853#endif
849 } 854 }
850 } 855 }
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index 4a0335854b89..8ecd7ad959b4 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -279,6 +279,7 @@ static const struct snmp_mib snmp4_net_list[] = {
279 SNMP_MIB_ITEM("TCPFastOpenCookieReqd", LINUX_MIB_TCPFASTOPENCOOKIEREQD), 279 SNMP_MIB_ITEM("TCPFastOpenCookieReqd", LINUX_MIB_TCPFASTOPENCOOKIEREQD),
280 SNMP_MIB_ITEM("TCPSpuriousRtxHostQueues", LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES), 280 SNMP_MIB_ITEM("TCPSpuriousRtxHostQueues", LINUX_MIB_TCPSPURIOUS_RTX_HOSTQUEUES),
281 SNMP_MIB_ITEM("BusyPollRxPackets", LINUX_MIB_BUSYPOLLRXPACKETS), 281 SNMP_MIB_ITEM("BusyPollRxPackets", LINUX_MIB_BUSYPOLLRXPACKETS),
282 SNMP_MIB_ITEM("TCPAutoCorking", LINUX_MIB_TCPAUTOCORKING),
282 SNMP_MIB_SENTINEL 283 SNMP_MIB_SENTINEL
283}; 284};
284 285
diff --git a/net/ipv4/protocol.c b/net/ipv4/protocol.c
index ce848461acbb..46d6a1c923a8 100644
--- a/net/ipv4/protocol.c
+++ b/net/ipv4/protocol.c
@@ -31,10 +31,6 @@
31const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS] __read_mostly; 31const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS] __read_mostly;
32const struct net_offload __rcu *inet_offloads[MAX_INET_PROTOS] __read_mostly; 32const struct net_offload __rcu *inet_offloads[MAX_INET_PROTOS] __read_mostly;
33 33
34/*
35 * Add a protocol handler to the hash tables
36 */
37
38int inet_add_protocol(const struct net_protocol *prot, unsigned char protocol) 34int inet_add_protocol(const struct net_protocol *prot, unsigned char protocol)
39{ 35{
40 if (!prot->netns_ok) { 36 if (!prot->netns_ok) {
@@ -55,10 +51,6 @@ int inet_add_offload(const struct net_offload *prot, unsigned char protocol)
55} 51}
56EXPORT_SYMBOL(inet_add_offload); 52EXPORT_SYMBOL(inet_add_offload);
57 53
58/*
59 * Remove a protocol from the hash tables.
60 */
61
62int inet_del_protocol(const struct net_protocol *prot, unsigned char protocol) 54int inet_del_protocol(const struct net_protocol *prot, unsigned char protocol)
63{ 55{
64 int ret; 56 int ret;
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 5cb8ddb505ee..81e6cfd5a365 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -575,7 +575,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
575 flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos, 575 flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos,
576 RT_SCOPE_UNIVERSE, 576 RT_SCOPE_UNIVERSE,
577 inet->hdrincl ? IPPROTO_RAW : sk->sk_protocol, 577 inet->hdrincl ? IPPROTO_RAW : sk->sk_protocol,
578 inet_sk_flowi_flags(sk) | FLOWI_FLAG_CAN_SLEEP | 578 inet_sk_flowi_flags(sk) |
579 (inet->hdrincl ? FLOWI_FLAG_KNOWN_NH : 0), 579 (inet->hdrincl ? FLOWI_FLAG_KNOWN_NH : 0),
580 daddr, saddr, 0, 0); 580 daddr, saddr, 0, 0);
581 581
@@ -697,7 +697,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
697 goto out; 697 goto out;
698 698
699 if (flags & MSG_ERRQUEUE) { 699 if (flags & MSG_ERRQUEUE) {
700 err = ip_recv_error(sk, msg, len); 700 err = ip_recv_error(sk, msg, len, addr_len);
701 goto out; 701 goto out;
702 } 702 }
703 703
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index b95331e6c077..f2ed13c2125f 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -121,7 +121,7 @@ static __u32 check_tcp_syn_cookie(__u32 cookie, __be32 saddr, __be32 daddr,
121 cookie -= cookie_hash(saddr, daddr, sport, dport, 0, 0) + sseq; 121 cookie -= cookie_hash(saddr, daddr, sport, dport, 0, 0) + sseq;
122 122
123 /* Cookie is now reduced to (count * 2^24) ^ (hash % 2^24) */ 123 /* Cookie is now reduced to (count * 2^24) ^ (hash % 2^24) */
124 diff = (count - (cookie >> COOKIEBITS)) & ((__u32) - 1 >> COOKIEBITS); 124 diff = (count - (cookie >> COOKIEBITS)) & ((__u32) -1 >> COOKIEBITS);
125 if (diff >= MAX_SYNCOOKIE_AGE) 125 if (diff >= MAX_SYNCOOKIE_AGE)
126 return (__u32)-1; 126 return (__u32)-1;
127 127
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 3d69ec8dac57..1d2480ac2bb6 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -286,13 +286,6 @@ static struct ctl_table ipv4_table[] = {
286 .extra2 = &ip_ttl_max, 286 .extra2 = &ip_ttl_max,
287 }, 287 },
288 { 288 {
289 .procname = "ip_no_pmtu_disc",
290 .data = &ipv4_config.no_pmtu_disc,
291 .maxlen = sizeof(int),
292 .mode = 0644,
293 .proc_handler = proc_dointvec
294 },
295 {
296 .procname = "ip_nonlocal_bind", 289 .procname = "ip_nonlocal_bind",
297 .data = &sysctl_ip_nonlocal_bind, 290 .data = &sysctl_ip_nonlocal_bind,
298 .maxlen = sizeof(int), 291 .maxlen = sizeof(int),
@@ -707,7 +700,7 @@ static struct ctl_table ipv4_table[] = {
707 .mode = 0644, 700 .mode = 0644,
708 .proc_handler = proc_dointvec 701 .proc_handler = proc_dointvec
709 }, 702 },
710 { 703 {
711 .procname = "tcp_thin_dupack", 704 .procname = "tcp_thin_dupack",
712 .data = &sysctl_tcp_thin_dupack, 705 .data = &sysctl_tcp_thin_dupack,
713 .maxlen = sizeof(int), 706 .maxlen = sizeof(int),
@@ -733,6 +726,15 @@ static struct ctl_table ipv4_table[] = {
733 .extra2 = &gso_max_segs, 726 .extra2 = &gso_max_segs,
734 }, 727 },
735 { 728 {
729 .procname = "tcp_autocorking",
730 .data = &sysctl_tcp_autocorking,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = proc_dointvec_minmax,
734 .extra1 = &zero,
735 .extra2 = &one,
736 },
737 {
736 .procname = "udp_mem", 738 .procname = "udp_mem",
737 .data = &sysctl_udp_mem, 739 .data = &sysctl_udp_mem,
738 .maxlen = sizeof(sysctl_udp_mem), 740 .maxlen = sizeof(sysctl_udp_mem),
@@ -822,6 +824,13 @@ static struct ctl_table ipv4_net_table[] = {
822 .mode = 0644, 824 .mode = 0644,
823 .proc_handler = ipv4_local_port_range, 825 .proc_handler = ipv4_local_port_range,
824 }, 826 },
827 {
828 .procname = "ip_no_pmtu_disc",
829 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
830 .maxlen = sizeof(int),
831 .mode = 0644,
832 .proc_handler = proc_dointvec
833 },
825 { } 834 { }
826}; 835};
827 836
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 3dc0c6cf02a8..d099f9a055c6 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -285,6 +285,8 @@ int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT;
285 285
286int sysctl_tcp_min_tso_segs __read_mostly = 2; 286int sysctl_tcp_min_tso_segs __read_mostly = 2;
287 287
288int sysctl_tcp_autocorking __read_mostly = 1;
289
288struct percpu_counter tcp_orphan_count; 290struct percpu_counter tcp_orphan_count;
289EXPORT_SYMBOL_GPL(tcp_orphan_count); 291EXPORT_SYMBOL_GPL(tcp_orphan_count);
290 292
@@ -619,19 +621,58 @@ static inline void tcp_mark_urg(struct tcp_sock *tp, int flags)
619 tp->snd_up = tp->write_seq; 621 tp->snd_up = tp->write_seq;
620} 622}
621 623
622static inline void tcp_push(struct sock *sk, int flags, int mss_now, 624/* If a not yet filled skb is pushed, do not send it if
623 int nonagle) 625 * we have data packets in Qdisc or NIC queues :
626 * Because TX completion will happen shortly, it gives a chance
627 * to coalesce future sendmsg() payload into this skb, without
628 * need for a timer, and with no latency trade off.
629 * As packets containing data payload have a bigger truesize
630 * than pure acks (dataless) packets, the last checks prevent
631 * autocorking if we only have an ACK in Qdisc/NIC queues,
632 * or if TX completion was delayed after we processed ACK packet.
633 */
634static bool tcp_should_autocork(struct sock *sk, struct sk_buff *skb,
635 int size_goal)
624{ 636{
625 if (tcp_send_head(sk)) { 637 return skb->len < size_goal &&
626 struct tcp_sock *tp = tcp_sk(sk); 638 sysctl_tcp_autocorking &&
639 skb != tcp_write_queue_head(sk) &&
640 atomic_read(&sk->sk_wmem_alloc) > skb->truesize;
641}
642
643static void tcp_push(struct sock *sk, int flags, int mss_now,
644 int nonagle, int size_goal)
645{
646 struct tcp_sock *tp = tcp_sk(sk);
647 struct sk_buff *skb;
627 648
628 if (!(flags & MSG_MORE) || forced_push(tp)) 649 if (!tcp_send_head(sk))
629 tcp_mark_push(tp, tcp_write_queue_tail(sk)); 650 return;
651
652 skb = tcp_write_queue_tail(sk);
653 if (!(flags & MSG_MORE) || forced_push(tp))
654 tcp_mark_push(tp, skb);
655
656 tcp_mark_urg(tp, flags);
657
658 if (tcp_should_autocork(sk, skb, size_goal)) {
630 659
631 tcp_mark_urg(tp, flags); 660 /* avoid atomic op if TSQ_THROTTLED bit is already set */
632 __tcp_push_pending_frames(sk, mss_now, 661 if (!test_bit(TSQ_THROTTLED, &tp->tsq_flags)) {
633 (flags & MSG_MORE) ? TCP_NAGLE_CORK : nonagle); 662 NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAUTOCORKING);
663 set_bit(TSQ_THROTTLED, &tp->tsq_flags);
664 }
665 /* It is possible TX completion already happened
666 * before we set TSQ_THROTTLED.
667 */
668 if (atomic_read(&sk->sk_wmem_alloc) > skb->truesize)
669 return;
634 } 670 }
671
672 if (flags & MSG_MORE)
673 nonagle = TCP_NAGLE_CORK;
674
675 __tcp_push_pending_frames(sk, mss_now, nonagle);
635} 676}
636 677
637static int tcp_splice_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb, 678static int tcp_splice_data_recv(read_descriptor_t *rd_desc, struct sk_buff *skb,
@@ -934,7 +975,8 @@ new_segment:
934wait_for_sndbuf: 975wait_for_sndbuf:
935 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); 976 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
936wait_for_memory: 977wait_for_memory:
937 tcp_push(sk, flags & ~MSG_MORE, mss_now, TCP_NAGLE_PUSH); 978 tcp_push(sk, flags & ~MSG_MORE, mss_now,
979 TCP_NAGLE_PUSH, size_goal);
938 980
939 if ((err = sk_stream_wait_memory(sk, &timeo)) != 0) 981 if ((err = sk_stream_wait_memory(sk, &timeo)) != 0)
940 goto do_error; 982 goto do_error;
@@ -944,7 +986,7 @@ wait_for_memory:
944 986
945out: 987out:
946 if (copied && !(flags & MSG_SENDPAGE_NOTLAST)) 988 if (copied && !(flags & MSG_SENDPAGE_NOTLAST))
947 tcp_push(sk, flags, mss_now, tp->nonagle); 989 tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
948 return copied; 990 return copied;
949 991
950do_error: 992do_error:
@@ -1225,7 +1267,8 @@ wait_for_sndbuf:
1225 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); 1267 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
1226wait_for_memory: 1268wait_for_memory:
1227 if (copied) 1269 if (copied)
1228 tcp_push(sk, flags & ~MSG_MORE, mss_now, TCP_NAGLE_PUSH); 1270 tcp_push(sk, flags & ~MSG_MORE, mss_now,
1271 TCP_NAGLE_PUSH, size_goal);
1229 1272
1230 if ((err = sk_stream_wait_memory(sk, &timeo)) != 0) 1273 if ((err = sk_stream_wait_memory(sk, &timeo)) != 0)
1231 goto do_error; 1274 goto do_error;
@@ -1236,7 +1279,7 @@ wait_for_memory:
1236 1279
1237out: 1280out:
1238 if (copied) 1281 if (copied)
1239 tcp_push(sk, flags, mss_now, tp->nonagle); 1282 tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
1240 release_sock(sk); 1283 release_sock(sk);
1241 return copied + copied_syn; 1284 return copied + copied_syn;
1242 1285
@@ -1425,7 +1468,7 @@ static void tcp_service_net_dma(struct sock *sk, bool wait)
1425 do { 1468 do {
1426 if (dma_async_is_tx_complete(tp->ucopy.dma_chan, 1469 if (dma_async_is_tx_complete(tp->ucopy.dma_chan,
1427 last_issued, &done, 1470 last_issued, &done,
1428 &used) == DMA_SUCCESS) { 1471 &used) == DMA_COMPLETE) {
1429 /* Safe to free early-copied skbs now */ 1472 /* Safe to free early-copied skbs now */
1430 __skb_queue_purge(&sk->sk_async_wait_queue); 1473 __skb_queue_purge(&sk->sk_async_wait_queue);
1431 break; 1474 break;
@@ -1433,7 +1476,7 @@ static void tcp_service_net_dma(struct sock *sk, bool wait)
1433 struct sk_buff *skb; 1476 struct sk_buff *skb;
1434 while ((skb = skb_peek(&sk->sk_async_wait_queue)) && 1477 while ((skb = skb_peek(&sk->sk_async_wait_queue)) &&
1435 (dma_async_is_complete(skb->dma_cookie, done, 1478 (dma_async_is_complete(skb->dma_cookie, done,
1436 used) == DMA_SUCCESS)) { 1479 used) == DMA_COMPLETE)) {
1437 __skb_dequeue(&sk->sk_async_wait_queue); 1480 __skb_dequeue(&sk->sk_async_wait_queue);
1438 kfree_skb(skb); 1481 kfree_skb(skb);
1439 } 1482 }
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index c53b7f35c51d..65cf90e063d5 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -766,7 +766,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
766/* Calculate rto without backoff. This is the second half of Van Jacobson's 766/* Calculate rto without backoff. This is the second half of Van Jacobson's
767 * routine referred to above. 767 * routine referred to above.
768 */ 768 */
769void tcp_set_rto(struct sock *sk) 769static void tcp_set_rto(struct sock *sk)
770{ 770{
771 const struct tcp_sock *tp = tcp_sk(sk); 771 const struct tcp_sock *tp = tcp_sk(sk);
772 /* Old crap is replaced with new one. 8) 772 /* Old crap is replaced with new one. 8)
@@ -3686,7 +3686,7 @@ const u8 *tcp_parse_md5sig_option(const struct tcphdr *th)
3686 int opcode = *ptr++; 3686 int opcode = *ptr++;
3687 int opsize; 3687 int opsize;
3688 3688
3689 switch(opcode) { 3689 switch (opcode) {
3690 case TCPOPT_EOL: 3690 case TCPOPT_EOL:
3691 return NULL; 3691 return NULL;
3692 case TCPOPT_NOP: 3692 case TCPOPT_NOP:
@@ -4046,7 +4046,7 @@ static void tcp_sack_remove(struct tcp_sock *tp)
4046 WARN_ON(before(tp->rcv_nxt, sp->end_seq)); 4046 WARN_ON(before(tp->rcv_nxt, sp->end_seq));
4047 4047
4048 /* Zap this SACK, by moving forward any other SACKS. */ 4048 /* Zap this SACK, by moving forward any other SACKS. */
4049 for (i=this_sack+1; i < num_sacks; i++) 4049 for (i = this_sack+1; i < num_sacks; i++)
4050 tp->selective_acks[i-1] = tp->selective_acks[i]; 4050 tp->selective_acks[i-1] = tp->selective_acks[i];
4051 num_sacks--; 4051 num_sacks--;
4052 continue; 4052 continue;
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 59a6f8b90cd9..7297b56c28c7 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -173,11 +173,11 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
173 rt = ip_route_connect(fl4, nexthop, inet->inet_saddr, 173 rt = ip_route_connect(fl4, nexthop, inet->inet_saddr,
174 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if, 174 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
175 IPPROTO_TCP, 175 IPPROTO_TCP,
176 orig_sport, orig_dport, sk, true); 176 orig_sport, orig_dport, sk);
177 if (IS_ERR(rt)) { 177 if (IS_ERR(rt)) {
178 err = PTR_ERR(rt); 178 err = PTR_ERR(rt);
179 if (err == -ENETUNREACH) 179 if (err == -ENETUNREACH)
180 IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES); 180 IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
181 return err; 181 return err;
182 } 182 }
183 183
@@ -827,7 +827,7 @@ static int tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst,
827 const struct inet_request_sock *ireq = inet_rsk(req); 827 const struct inet_request_sock *ireq = inet_rsk(req);
828 struct flowi4 fl4; 828 struct flowi4 fl4;
829 int err = -1; 829 int err = -1;
830 struct sk_buff * skb; 830 struct sk_buff *skb;
831 831
832 /* First, grab a route. */ 832 /* First, grab a route. */
833 if (!dst && (dst = inet_csk_route_req(sk, &fl4, req)) == NULL) 833 if (!dst && (dst = inet_csk_route_req(sk, &fl4, req)) == NULL)
diff --git a/net/ipv4/tcp_memcontrol.c b/net/ipv4/tcp_memcontrol.c
index 03e9154f7e68..f7e522c558ba 100644
--- a/net/ipv4/tcp_memcontrol.c
+++ b/net/ipv4/tcp_memcontrol.c
@@ -6,13 +6,6 @@
6#include <linux/memcontrol.h> 6#include <linux/memcontrol.h>
7#include <linux/module.h> 7#include <linux/module.h>
8 8
9static void memcg_tcp_enter_memory_pressure(struct sock *sk)
10{
11 if (sk->sk_cgrp->memory_pressure)
12 sk->sk_cgrp->memory_pressure = 1;
13}
14EXPORT_SYMBOL(memcg_tcp_enter_memory_pressure);
15
16int tcp_init_cgroup(struct mem_cgroup *memcg, struct cgroup_subsys *ss) 9int tcp_init_cgroup(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
17{ 10{
18 /* 11 /*
@@ -60,7 +53,6 @@ EXPORT_SYMBOL(tcp_destroy_cgroup);
60static int tcp_update_limit(struct mem_cgroup *memcg, u64 val) 53static int tcp_update_limit(struct mem_cgroup *memcg, u64 val)
61{ 54{
62 struct cg_proto *cg_proto; 55 struct cg_proto *cg_proto;
63 u64 old_lim;
64 int i; 56 int i;
65 int ret; 57 int ret;
66 58
@@ -71,7 +63,6 @@ static int tcp_update_limit(struct mem_cgroup *memcg, u64 val)
71 if (val > RES_COUNTER_MAX) 63 if (val > RES_COUNTER_MAX)
72 val = RES_COUNTER_MAX; 64 val = RES_COUNTER_MAX;
73 65
74 old_lim = res_counter_read_u64(&cg_proto->memory_allocated, RES_LIMIT);
75 ret = res_counter_set_limit(&cg_proto->memory_allocated, val); 66 ret = res_counter_set_limit(&cg_proto->memory_allocated, val);
76 if (ret) 67 if (ret)
77 return ret; 68 return ret;
diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c
index a2b68a108eae..2658a27f540d 100644
--- a/net/ipv4/tcp_offload.c
+++ b/net/ipv4/tcp_offload.c
@@ -240,7 +240,7 @@ int tcp_gro_complete(struct sk_buff *skb)
240{ 240{
241 struct tcphdr *th = tcp_hdr(skb); 241 struct tcphdr *th = tcp_hdr(skb);
242 242
243 skb->csum_start = skb_transport_header(skb) - skb->head; 243 skb->csum_start = (unsigned char *)th - skb->head;
244 skb->csum_offset = offsetof(struct tcphdr, check); 244 skb->csum_offset = offsetof(struct tcphdr, check);
245 skb->ip_summed = CHECKSUM_PARTIAL; 245 skb->ip_summed = CHECKSUM_PARTIAL;
246 246
@@ -272,45 +272,45 @@ static int tcp_v4_gso_send_check(struct sk_buff *skb)
272 272
273static struct sk_buff **tcp4_gro_receive(struct sk_buff **head, struct sk_buff *skb) 273static struct sk_buff **tcp4_gro_receive(struct sk_buff **head, struct sk_buff *skb)
274{ 274{
275 /* Use the IP hdr immediately proceeding for this transport */
275 const struct iphdr *iph = skb_gro_network_header(skb); 276 const struct iphdr *iph = skb_gro_network_header(skb);
276 __wsum wsum; 277 __wsum wsum;
277 __sum16 sum; 278
279 /* Don't bother verifying checksum if we're going to flush anyway. */
280 if (NAPI_GRO_CB(skb)->flush)
281 goto skip_csum;
282
283 wsum = skb->csum;
278 284
279 switch (skb->ip_summed) { 285 switch (skb->ip_summed) {
286 case CHECKSUM_NONE:
287 wsum = skb_checksum(skb, skb_gro_offset(skb), skb_gro_len(skb),
288 0);
289
290 /* fall through */
291
280 case CHECKSUM_COMPLETE: 292 case CHECKSUM_COMPLETE:
281 if (!tcp_v4_check(skb_gro_len(skb), iph->saddr, iph->daddr, 293 if (!tcp_v4_check(skb_gro_len(skb), iph->saddr, iph->daddr,
282 skb->csum)) { 294 wsum)) {
283 skb->ip_summed = CHECKSUM_UNNECESSARY; 295 skb->ip_summed = CHECKSUM_UNNECESSARY;
284 break; 296 break;
285 } 297 }
286flush: 298
287 NAPI_GRO_CB(skb)->flush = 1; 299 NAPI_GRO_CB(skb)->flush = 1;
288 return NULL; 300 return NULL;
289
290 case CHECKSUM_NONE:
291 wsum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
292 skb_gro_len(skb), IPPROTO_TCP, 0);
293 sum = csum_fold(skb_checksum(skb,
294 skb_gro_offset(skb),
295 skb_gro_len(skb),
296 wsum));
297 if (sum)
298 goto flush;
299
300 skb->ip_summed = CHECKSUM_UNNECESSARY;
301 break;
302 } 301 }
303 302
303skip_csum:
304 return tcp_gro_receive(head, skb); 304 return tcp_gro_receive(head, skb);
305} 305}
306 306
307static int tcp4_gro_complete(struct sk_buff *skb) 307static int tcp4_gro_complete(struct sk_buff *skb, int thoff)
308{ 308{
309 const struct iphdr *iph = ip_hdr(skb); 309 const struct iphdr *iph = ip_hdr(skb);
310 struct tcphdr *th = tcp_hdr(skb); 310 struct tcphdr *th = tcp_hdr(skb);
311 311
312 th->check = ~tcp_v4_check(skb->len - skb_transport_offset(skb), 312 th->check = ~tcp_v4_check(skb->len - thoff, iph->saddr,
313 iph->saddr, iph->daddr, 0); 313 iph->daddr, 0);
314 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; 314 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
315 315
316 return tcp_gro_complete(skb); 316 return tcp_gro_complete(skb);
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 7820f3a7dd70..03d26b85eab8 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -363,15 +363,17 @@ static inline void TCP_ECN_send(struct sock *sk, struct sk_buff *skb,
363 */ 363 */
364static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u8 flags) 364static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u8 flags)
365{ 365{
366 struct skb_shared_info *shinfo = skb_shinfo(skb);
367
366 skb->ip_summed = CHECKSUM_PARTIAL; 368 skb->ip_summed = CHECKSUM_PARTIAL;
367 skb->csum = 0; 369 skb->csum = 0;
368 370
369 TCP_SKB_CB(skb)->tcp_flags = flags; 371 TCP_SKB_CB(skb)->tcp_flags = flags;
370 TCP_SKB_CB(skb)->sacked = 0; 372 TCP_SKB_CB(skb)->sacked = 0;
371 373
372 skb_shinfo(skb)->gso_segs = 1; 374 shinfo->gso_segs = 1;
373 skb_shinfo(skb)->gso_size = 0; 375 shinfo->gso_size = 0;
374 skb_shinfo(skb)->gso_type = 0; 376 shinfo->gso_type = 0;
375 377
376 TCP_SKB_CB(skb)->seq = seq; 378 TCP_SKB_CB(skb)->seq = seq;
377 if (flags & (TCPHDR_SYN | TCPHDR_FIN)) 379 if (flags & (TCPHDR_SYN | TCPHDR_FIN))
@@ -406,7 +408,7 @@ struct tcp_out_options {
406 * Beware: Something in the Internet is very sensitive to the ordering of 408 * Beware: Something in the Internet is very sensitive to the ordering of
407 * TCP options, we learned this through the hard way, so be careful here. 409 * TCP options, we learned this through the hard way, so be careful here.
408 * Luckily we can at least blame others for their non-compliance but from 410 * Luckily we can at least blame others for their non-compliance but from
409 * inter-operatibility perspective it seems that we're somewhat stuck with 411 * inter-operability perspective it seems that we're somewhat stuck with
410 * the ordering which we have been using if we want to keep working with 412 * the ordering which we have been using if we want to keep working with
411 * those broken things (not that it currently hurts anybody as there isn't 413 * those broken things (not that it currently hurts anybody as there isn't
412 * particular reason why the ordering would need to be changed). 414 * particular reason why the ordering would need to be changed).
@@ -679,7 +681,7 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
679 * 681 *
680 * Its important tcp_wfree() can be replaced by sock_wfree() in the event skb 682 * Its important tcp_wfree() can be replaced by sock_wfree() in the event skb
681 * needs to be reallocated in a driver. 683 * needs to be reallocated in a driver.
682 * The invariant being skb->truesize substracted from sk->sk_wmem_alloc 684 * The invariant being skb->truesize subtracted from sk->sk_wmem_alloc
683 * 685 *
684 * Since transmit from skb destructor is forbidden, we use a tasklet 686 * Since transmit from skb destructor is forbidden, we use a tasklet
685 * to process all sockets that eventually need to send more skbs. 687 * to process all sockets that eventually need to send more skbs.
@@ -699,9 +701,9 @@ static void tcp_tsq_handler(struct sock *sk)
699 tcp_write_xmit(sk, tcp_current_mss(sk), 0, 0, GFP_ATOMIC); 701 tcp_write_xmit(sk, tcp_current_mss(sk), 0, 0, GFP_ATOMIC);
700} 702}
701/* 703/*
702 * One tasklest per cpu tries to send more skbs. 704 * One tasklet per cpu tries to send more skbs.
703 * We run in tasklet context but need to disable irqs when 705 * We run in tasklet context but need to disable irqs when
704 * transfering tsq->head because tcp_wfree() might 706 * transferring tsq->head because tcp_wfree() might
705 * interrupt us (non NAPI drivers) 707 * interrupt us (non NAPI drivers)
706 */ 708 */
707static void tcp_tasklet_func(unsigned long data) 709static void tcp_tasklet_func(unsigned long data)
@@ -795,7 +797,7 @@ void __init tcp_tasklet_init(void)
795 797
796/* 798/*
797 * Write buffer destructor automatically called from kfree_skb. 799 * Write buffer destructor automatically called from kfree_skb.
798 * We cant xmit new skbs from this context, as we might already 800 * We can't xmit new skbs from this context, as we might already
799 * hold qdisc lock. 801 * hold qdisc lock.
800 */ 802 */
801void tcp_wfree(struct sk_buff *skb) 803void tcp_wfree(struct sk_buff *skb)
@@ -986,6 +988,8 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb)
986static void tcp_set_skb_tso_segs(const struct sock *sk, struct sk_buff *skb, 988static void tcp_set_skb_tso_segs(const struct sock *sk, struct sk_buff *skb,
987 unsigned int mss_now) 989 unsigned int mss_now)
988{ 990{
991 struct skb_shared_info *shinfo = skb_shinfo(skb);
992
989 /* Make sure we own this skb before messing gso_size/gso_segs */ 993 /* Make sure we own this skb before messing gso_size/gso_segs */
990 WARN_ON_ONCE(skb_cloned(skb)); 994 WARN_ON_ONCE(skb_cloned(skb));
991 995
@@ -993,13 +997,13 @@ static void tcp_set_skb_tso_segs(const struct sock *sk, struct sk_buff *skb,
993 /* Avoid the costly divide in the normal 997 /* Avoid the costly divide in the normal
994 * non-TSO case. 998 * non-TSO case.
995 */ 999 */
996 skb_shinfo(skb)->gso_segs = 1; 1000 shinfo->gso_segs = 1;
997 skb_shinfo(skb)->gso_size = 0; 1001 shinfo->gso_size = 0;
998 skb_shinfo(skb)->gso_type = 0; 1002 shinfo->gso_type = 0;
999 } else { 1003 } else {
1000 skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss_now); 1004 shinfo->gso_segs = DIV_ROUND_UP(skb->len, mss_now);
1001 skb_shinfo(skb)->gso_size = mss_now; 1005 shinfo->gso_size = mss_now;
1002 skb_shinfo(skb)->gso_type = sk->sk_gso_type; 1006 shinfo->gso_type = sk->sk_gso_type;
1003 } 1007 }
1004} 1008}
1005 1009
@@ -1146,6 +1150,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len,
1146 */ 1150 */
1147static void __pskb_trim_head(struct sk_buff *skb, int len) 1151static void __pskb_trim_head(struct sk_buff *skb, int len)
1148{ 1152{
1153 struct skb_shared_info *shinfo;
1149 int i, k, eat; 1154 int i, k, eat;
1150 1155
1151 eat = min_t(int, len, skb_headlen(skb)); 1156 eat = min_t(int, len, skb_headlen(skb));
@@ -1157,23 +1162,24 @@ static void __pskb_trim_head(struct sk_buff *skb, int len)
1157 } 1162 }
1158 eat = len; 1163 eat = len;
1159 k = 0; 1164 k = 0;
1160 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 1165 shinfo = skb_shinfo(skb);
1161 int size = skb_frag_size(&skb_shinfo(skb)->frags[i]); 1166 for (i = 0; i < shinfo->nr_frags; i++) {
1167 int size = skb_frag_size(&shinfo->frags[i]);
1162 1168
1163 if (size <= eat) { 1169 if (size <= eat) {
1164 skb_frag_unref(skb, i); 1170 skb_frag_unref(skb, i);
1165 eat -= size; 1171 eat -= size;
1166 } else { 1172 } else {
1167 skb_shinfo(skb)->frags[k] = skb_shinfo(skb)->frags[i]; 1173 shinfo->frags[k] = shinfo->frags[i];
1168 if (eat) { 1174 if (eat) {
1169 skb_shinfo(skb)->frags[k].page_offset += eat; 1175 shinfo->frags[k].page_offset += eat;
1170 skb_frag_size_sub(&skb_shinfo(skb)->frags[k], eat); 1176 skb_frag_size_sub(&shinfo->frags[k], eat);
1171 eat = 0; 1177 eat = 0;
1172 } 1178 }
1173 k++; 1179 k++;
1174 } 1180 }
1175 } 1181 }
1176 skb_shinfo(skb)->nr_frags = k; 1182 shinfo->nr_frags = k;
1177 1183
1178 skb_reset_tail_pointer(skb); 1184 skb_reset_tail_pointer(skb);
1179 skb->data_len -= len; 1185 skb->data_len -= len;
@@ -1378,23 +1384,51 @@ static void tcp_cwnd_validate(struct sock *sk)
1378 } 1384 }
1379} 1385}
1380 1386
1381/* Returns the portion of skb which can be sent right away without 1387/* Minshall's variant of the Nagle send check. */
1382 * introducing MSS oddities to segment boundaries. In rare cases where 1388static bool tcp_minshall_check(const struct tcp_sock *tp)
1383 * mss_now != mss_cache, we will request caller to create a small skb 1389{
1384 * per input skb which could be mostly avoided here (if desired). 1390 return after(tp->snd_sml, tp->snd_una) &&
1385 * 1391 !after(tp->snd_sml, tp->snd_nxt);
1386 * We explicitly want to create a request for splitting write queue tail 1392}
1387 * to a small skb for Nagle purposes while avoiding unnecessary modulos, 1393
1388 * thus all the complexity (cwnd_len is always MSS multiple which we 1394/* Update snd_sml if this skb is under mss
1389 * return whenever allowed by the other factors). Basically we need the 1395 * Note that a TSO packet might end with a sub-mss segment
1390 * modulo only when the receiver window alone is the limiting factor or 1396 * The test is really :
1391 * when we would be allowed to send the split-due-to-Nagle skb fully. 1397 * if ((skb->len % mss) != 0)
1398 * tp->snd_sml = TCP_SKB_CB(skb)->end_seq;
1399 * But we can avoid doing the divide again given we already have
1400 * skb_pcount = skb->len / mss_now
1401 */
1402static void tcp_minshall_update(struct tcp_sock *tp, unsigned int mss_now,
1403 const struct sk_buff *skb)
1404{
1405 if (skb->len < tcp_skb_pcount(skb) * mss_now)
1406 tp->snd_sml = TCP_SKB_CB(skb)->end_seq;
1407}
1408
1409/* Return false, if packet can be sent now without violation Nagle's rules:
1410 * 1. It is full sized. (provided by caller in %partial bool)
1411 * 2. Or it contains FIN. (already checked by caller)
1412 * 3. Or TCP_CORK is not set, and TCP_NODELAY is set.
1413 * 4. Or TCP_CORK is not set, and all sent packets are ACKed.
1414 * With Minshall's modification: all sent small packets are ACKed.
1392 */ 1415 */
1393static unsigned int tcp_mss_split_point(const struct sock *sk, const struct sk_buff *skb, 1416static bool tcp_nagle_check(bool partial, const struct tcp_sock *tp,
1394 unsigned int mss_now, unsigned int max_segs) 1417 unsigned int mss_now, int nonagle)
1418{
1419 return partial &&
1420 ((nonagle & TCP_NAGLE_CORK) ||
1421 (!nonagle && tp->packets_out && tcp_minshall_check(tp)));
1422}
1423/* Returns the portion of skb which can be sent right away */
1424static unsigned int tcp_mss_split_point(const struct sock *sk,
1425 const struct sk_buff *skb,
1426 unsigned int mss_now,
1427 unsigned int max_segs,
1428 int nonagle)
1395{ 1429{
1396 const struct tcp_sock *tp = tcp_sk(sk); 1430 const struct tcp_sock *tp = tcp_sk(sk);
1397 u32 needed, window, max_len; 1431 u32 partial, needed, window, max_len;
1398 1432
1399 window = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq; 1433 window = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq;
1400 max_len = mss_now * max_segs; 1434 max_len = mss_now * max_segs;
@@ -1407,7 +1441,15 @@ static unsigned int tcp_mss_split_point(const struct sock *sk, const struct sk_b
1407 if (max_len <= needed) 1441 if (max_len <= needed)
1408 return max_len; 1442 return max_len;
1409 1443
1410 return needed - needed % mss_now; 1444 partial = needed % mss_now;
1445 /* If last segment is not a full MSS, check if Nagle rules allow us
1446 * to include this last segment in this skb.
1447 * Otherwise, we'll split the skb at last MSS boundary
1448 */
1449 if (tcp_nagle_check(partial != 0, tp, mss_now, nonagle))
1450 return needed - partial;
1451
1452 return needed;
1411} 1453}
1412 1454
1413/* Can at least one segment of SKB be sent right now, according to the 1455/* Can at least one segment of SKB be sent right now, according to the
@@ -1447,28 +1489,6 @@ static int tcp_init_tso_segs(const struct sock *sk, struct sk_buff *skb,
1447 return tso_segs; 1489 return tso_segs;
1448} 1490}
1449 1491
1450/* Minshall's variant of the Nagle send check. */
1451static inline bool tcp_minshall_check(const struct tcp_sock *tp)
1452{
1453 return after(tp->snd_sml, tp->snd_una) &&
1454 !after(tp->snd_sml, tp->snd_nxt);
1455}
1456
1457/* Return false, if packet can be sent now without violation Nagle's rules:
1458 * 1. It is full sized.
1459 * 2. Or it contains FIN. (already checked by caller)
1460 * 3. Or TCP_CORK is not set, and TCP_NODELAY is set.
1461 * 4. Or TCP_CORK is not set, and all sent packets are ACKed.
1462 * With Minshall's modification: all sent small packets are ACKed.
1463 */
1464static inline bool tcp_nagle_check(const struct tcp_sock *tp,
1465 const struct sk_buff *skb,
1466 unsigned int mss_now, int nonagle)
1467{
1468 return skb->len < mss_now &&
1469 ((nonagle & TCP_NAGLE_CORK) ||
1470 (!nonagle && tp->packets_out && tcp_minshall_check(tp)));
1471}
1472 1492
1473/* Return true if the Nagle test allows this packet to be 1493/* Return true if the Nagle test allows this packet to be
1474 * sent now. 1494 * sent now.
@@ -1489,7 +1509,7 @@ static inline bool tcp_nagle_test(const struct tcp_sock *tp, const struct sk_buf
1489 if (tcp_urg_mode(tp) || (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)) 1509 if (tcp_urg_mode(tp) || (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN))
1490 return true; 1510 return true;
1491 1511
1492 if (!tcp_nagle_check(tp, skb, cur_mss, nonagle)) 1512 if (!tcp_nagle_check(skb->len < cur_mss, tp, cur_mss, nonagle))
1493 return true; 1513 return true;
1494 1514
1495 return false; 1515 return false;
@@ -1892,7 +1912,8 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
1892 limit = tcp_mss_split_point(sk, skb, mss_now, 1912 limit = tcp_mss_split_point(sk, skb, mss_now,
1893 min_t(unsigned int, 1913 min_t(unsigned int,
1894 cwnd_quota, 1914 cwnd_quota,
1895 sk->sk_gso_max_segs)); 1915 sk->sk_gso_max_segs),
1916 nonagle);
1896 1917
1897 if (skb->len > limit && 1918 if (skb->len > limit &&
1898 unlikely(tso_fragment(sk, skb, limit, mss_now, gfp))) 1919 unlikely(tso_fragment(sk, skb, limit, mss_now, gfp)))
@@ -2756,7 +2777,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2756EXPORT_SYMBOL(tcp_make_synack); 2777EXPORT_SYMBOL(tcp_make_synack);
2757 2778
2758/* Do all connect socket setups that can be done AF independent. */ 2779/* Do all connect socket setups that can be done AF independent. */
2759void tcp_connect_init(struct sock *sk) 2780static void tcp_connect_init(struct sock *sk)
2760{ 2781{
2761 const struct dst_entry *dst = __sk_dst_get(sk); 2782 const struct dst_entry *dst = __sk_dst_get(sk);
2762 struct tcp_sock *tp = tcp_sk(sk); 2783 struct tcp_sock *tp = tcp_sk(sk);
diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
index 8b97d71e193b..1f2d37613c9e 100644
--- a/net/ipv4/tcp_probe.c
+++ b/net/ipv4/tcp_probe.c
@@ -38,7 +38,7 @@ MODULE_DESCRIPTION("TCP cwnd snooper");
38MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
39MODULE_VERSION("1.1"); 39MODULE_VERSION("1.1");
40 40
41static int port __read_mostly = 0; 41static int port __read_mostly;
42MODULE_PARM_DESC(port, "Port to match (0=all)"); 42MODULE_PARM_DESC(port, "Port to match (0=all)");
43module_param(port, int, 0); 43module_param(port, int, 0);
44 44
@@ -46,7 +46,7 @@ static unsigned int bufsize __read_mostly = 4096;
46MODULE_PARM_DESC(bufsize, "Log buffer size in packets (4096)"); 46MODULE_PARM_DESC(bufsize, "Log buffer size in packets (4096)");
47module_param(bufsize, uint, 0); 47module_param(bufsize, uint, 0);
48 48
49static unsigned int fwmark __read_mostly = 0; 49static unsigned int fwmark __read_mostly;
50MODULE_PARM_DESC(fwmark, "skb mark to match (0=no mark)"); 50MODULE_PARM_DESC(fwmark, "skb mark to match (0=no mark)");
51module_param(fwmark, uint, 0); 51module_param(fwmark, uint, 0);
52 52
diff --git a/net/ipv4/tcp_yeah.c b/net/ipv4/tcp_yeah.c
index a347a078ee07..1a8d271f994d 100644
--- a/net/ipv4/tcp_yeah.c
+++ b/net/ipv4/tcp_yeah.c
@@ -3,7 +3,7 @@
3 * YeAH TCP 3 * YeAH TCP
4 * 4 *
5 * For further details look at: 5 * For further details look at:
6 * http://wil.cs.caltech.edu/pfldnet2007/paper/YeAH_TCP.pdf 6 * https://web.archive.org/web/20080316215752/http://wil.cs.caltech.edu/pfldnet2007/paper/YeAH_TCP.pdf
7 * 7 *
8 */ 8 */
9#include <linux/mm.h> 9#include <linux/mm.h>
@@ -15,13 +15,13 @@
15 15
16#include "tcp_vegas.h" 16#include "tcp_vegas.h"
17 17
18#define TCP_YEAH_ALPHA 80 //lin number of packets queued at the bottleneck 18#define TCP_YEAH_ALPHA 80 /* number of packets queued at the bottleneck */
19#define TCP_YEAH_GAMMA 1 //lin fraction of queue to be removed per rtt 19#define TCP_YEAH_GAMMA 1 /* fraction of queue to be removed per rtt */
20#define TCP_YEAH_DELTA 3 //log minimum fraction of cwnd to be removed on loss 20#define TCP_YEAH_DELTA 3 /* log minimum fraction of cwnd to be removed on loss */
21#define TCP_YEAH_EPSILON 1 //log maximum fraction to be removed on early decongestion 21#define TCP_YEAH_EPSILON 1 /* log maximum fraction to be removed on early decongestion */
22#define TCP_YEAH_PHY 8 //lin maximum delta from base 22#define TCP_YEAH_PHY 8 /* maximum delta from base */
23#define TCP_YEAH_RHO 16 //lin minimum number of consecutive rtt to consider competition on loss 23#define TCP_YEAH_RHO 16 /* minimum number of consecutive rtt to consider competition on loss */
24#define TCP_YEAH_ZETA 50 //lin minimum number of state switchs to reset reno_count 24#define TCP_YEAH_ZETA 50 /* minimum number of state switches to reset reno_count */
25 25
26#define TCP_SCALABLE_AI_CNT 100U 26#define TCP_SCALABLE_AI_CNT 100U
27 27
@@ -214,9 +214,9 @@ static u32 tcp_yeah_ssthresh(struct sock *sk) {
214 if (yeah->doing_reno_now < TCP_YEAH_RHO) { 214 if (yeah->doing_reno_now < TCP_YEAH_RHO) {
215 reduction = yeah->lastQ; 215 reduction = yeah->lastQ;
216 216
217 reduction = min( reduction, max(tp->snd_cwnd>>1, 2U) ); 217 reduction = min(reduction, max(tp->snd_cwnd>>1, 2U));
218 218
219 reduction = max( reduction, tp->snd_cwnd >> TCP_YEAH_DELTA); 219 reduction = max(reduction, tp->snd_cwnd >> TCP_YEAH_DELTA);
220 } else 220 } else
221 reduction = max(tp->snd_cwnd>>1, 2U); 221 reduction = max(tp->snd_cwnd>>1, 2U);
222 222
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 5944d7d668dd..d5d24ecde6a5 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -560,15 +560,11 @@ static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb,
560 __be16 sport, __be16 dport, 560 __be16 sport, __be16 dport,
561 struct udp_table *udptable) 561 struct udp_table *udptable)
562{ 562{
563 struct sock *sk;
564 const struct iphdr *iph = ip_hdr(skb); 563 const struct iphdr *iph = ip_hdr(skb);
565 564
566 if (unlikely(sk = skb_steal_sock(skb))) 565 return __udp4_lib_lookup(dev_net(skb_dst(skb)->dev), iph->saddr, sport,
567 return sk; 566 iph->daddr, dport, inet_iif(skb),
568 else 567 udptable);
569 return __udp4_lib_lookup(dev_net(skb_dst(skb)->dev), iph->saddr, sport,
570 iph->daddr, dport, inet_iif(skb),
571 udptable);
572} 568}
573 569
574struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport, 570struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
@@ -990,7 +986,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
990 fl4 = &fl4_stack; 986 fl4 = &fl4_stack;
991 flowi4_init_output(fl4, ipc.oif, sk->sk_mark, tos, 987 flowi4_init_output(fl4, ipc.oif, sk->sk_mark, tos,
992 RT_SCOPE_UNIVERSE, sk->sk_protocol, 988 RT_SCOPE_UNIVERSE, sk->sk_protocol,
993 inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP, 989 inet_sk_flowi_flags(sk),
994 faddr, saddr, dport, inet->inet_sport); 990 faddr, saddr, dport, inet->inet_sport);
995 991
996 security_sk_classify_flow(sk, flowi4_to_flowi(fl4)); 992 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
@@ -999,7 +995,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
999 err = PTR_ERR(rt); 995 err = PTR_ERR(rt);
1000 rt = NULL; 996 rt = NULL;
1001 if (err == -ENETUNREACH) 997 if (err == -ENETUNREACH)
1002 IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES); 998 IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
1003 goto out; 999 goto out;
1004 } 1000 }
1005 1001
@@ -1098,6 +1094,9 @@ int udp_sendpage(struct sock *sk, struct page *page, int offset,
1098 struct udp_sock *up = udp_sk(sk); 1094 struct udp_sock *up = udp_sk(sk);
1099 int ret; 1095 int ret;
1100 1096
1097 if (flags & MSG_SENDPAGE_NOTLAST)
1098 flags |= MSG_MORE;
1099
1101 if (!up->pending) { 1100 if (!up->pending) {
1102 struct msghdr msg = { .msg_flags = flags|MSG_MORE }; 1101 struct msghdr msg = { .msg_flags = flags|MSG_MORE };
1103 1102
@@ -1236,7 +1235,7 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
1236 bool slow; 1235 bool slow;
1237 1236
1238 if (flags & MSG_ERRQUEUE) 1237 if (flags & MSG_ERRQUEUE)
1239 return ip_recv_error(sk, msg, len); 1238 return ip_recv_error(sk, msg, len, addr_len);
1240 1239
1241try_again: 1240try_again:
1242 skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0), 1241 skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
@@ -1600,12 +1599,16 @@ static void flush_stack(struct sock **stack, unsigned int count,
1600 kfree_skb(skb1); 1599 kfree_skb(skb1);
1601} 1600}
1602 1601
1603static void udp_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) 1602/* For TCP sockets, sk_rx_dst is protected by socket lock
1603 * For UDP, we use xchg() to guard against concurrent changes.
1604 */
1605static void udp_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst)
1604{ 1606{
1605 struct dst_entry *dst = skb_dst(skb); 1607 struct dst_entry *old;
1606 1608
1607 dst_hold(dst); 1609 dst_hold(dst);
1608 sk->sk_rx_dst = dst; 1610 old = xchg(&sk->sk_rx_dst, dst);
1611 dst_release(old);
1609} 1612}
1610 1613
1611/* 1614/*
@@ -1736,15 +1739,16 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
1736 if (udp4_csum_init(skb, uh, proto)) 1739 if (udp4_csum_init(skb, uh, proto))
1737 goto csum_error; 1740 goto csum_error;
1738 1741
1739 if (skb->sk) { 1742 sk = skb_steal_sock(skb);
1743 if (sk) {
1744 struct dst_entry *dst = skb_dst(skb);
1740 int ret; 1745 int ret;
1741 sk = skb->sk;
1742 1746
1743 if (unlikely(sk->sk_rx_dst == NULL)) 1747 if (unlikely(sk->sk_rx_dst != dst))
1744 udp_sk_rx_dst_set(sk, skb); 1748 udp_sk_rx_dst_set(sk, dst);
1745 1749
1746 ret = udp_queue_rcv_skb(sk, skb); 1750 ret = udp_queue_rcv_skb(sk, skb);
1747 1751 sock_put(sk);
1748 /* a return value > 0 means to resubmit the input, but 1752 /* a return value > 0 means to resubmit the input, but
1749 * it wants the return to be -protocol, or 0 1753 * it wants the return to be -protocol, or 0
1750 */ 1754 */
@@ -1910,17 +1914,20 @@ static struct sock *__udp4_lib_demux_lookup(struct net *net,
1910 1914
1911void udp_v4_early_demux(struct sk_buff *skb) 1915void udp_v4_early_demux(struct sk_buff *skb)
1912{ 1916{
1913 const struct iphdr *iph = ip_hdr(skb); 1917 struct net *net = dev_net(skb->dev);
1914 const struct udphdr *uh = udp_hdr(skb); 1918 const struct iphdr *iph;
1919 const struct udphdr *uh;
1915 struct sock *sk; 1920 struct sock *sk;
1916 struct dst_entry *dst; 1921 struct dst_entry *dst;
1917 struct net *net = dev_net(skb->dev);
1918 int dif = skb->dev->ifindex; 1922 int dif = skb->dev->ifindex;
1919 1923
1920 /* validate the packet */ 1924 /* validate the packet */
1921 if (!pskb_may_pull(skb, skb_transport_offset(skb) + sizeof(struct udphdr))) 1925 if (!pskb_may_pull(skb, skb_transport_offset(skb) + sizeof(struct udphdr)))
1922 return; 1926 return;
1923 1927
1928 iph = ip_hdr(skb);
1929 uh = udp_hdr(skb);
1930
1924 if (skb->pkt_type == PACKET_BROADCAST || 1931 if (skb->pkt_type == PACKET_BROADCAST ||
1925 skb->pkt_type == PACKET_MULTICAST) 1932 skb->pkt_type == PACKET_MULTICAST)
1926 sk = __udp4_lib_mcast_demux_lookup(net, uh->dest, iph->daddr, 1933 sk = __udp4_lib_mcast_demux_lookup(net, uh->dest, iph->daddr,
diff --git a/net/ipv4/xfrm4_mode_beet.c b/net/ipv4/xfrm4_mode_beet.c
index e3db3f915114..71acd0014f2d 100644
--- a/net/ipv4/xfrm4_mode_beet.c
+++ b/net/ipv4/xfrm4_mode_beet.c
@@ -48,7 +48,7 @@ static int xfrm4_beet_output(struct xfrm_state *x, struct sk_buff *skb)
48 hdrlen += IPV4_BEET_PHMAXLEN - (optlen & 4); 48 hdrlen += IPV4_BEET_PHMAXLEN - (optlen & 4);
49 49
50 skb_set_network_header(skb, -x->props.header_len - 50 skb_set_network_header(skb, -x->props.header_len -
51 hdrlen + (XFRM_MODE_SKB_CB(skb)->ihl - sizeof(*top_iph))); 51 hdrlen + (XFRM_MODE_SKB_CB(skb)->ihl - sizeof(*top_iph)));
52 if (x->sel.family != AF_INET6) 52 if (x->sel.family != AF_INET6)
53 skb->network_header += IPV4_BEET_PHMAXLEN; 53 skb->network_header += IPV4_BEET_PHMAXLEN;
54 skb->mac_header = skb->network_header + 54 skb->mac_header = skb->network_header +
diff --git a/net/ipv4/xfrm4_state.c b/net/ipv4/xfrm4_state.c
index 0b2a0641526a..542074c00c78 100644
--- a/net/ipv4/xfrm4_state.c
+++ b/net/ipv4/xfrm4_state.c
@@ -16,7 +16,7 @@
16 16
17static int xfrm4_init_flags(struct xfrm_state *x) 17static int xfrm4_init_flags(struct xfrm_state *x)
18{ 18{
19 if (ipv4_config.no_pmtu_disc) 19 if (xs_net(x)->ipv4.sysctl_ip_no_pmtu_disc)
20 x->props.flags |= XFRM_STATE_NOPMTUDISC; 20 x->props.flags |= XFRM_STATE_NOPMTUDISC;
21 return 0; 21 return 0;
22} 22}
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 12c97d8aa6bb..9418ca375132 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -442,6 +442,8 @@ static int inet6_netconf_msgsize_devconf(int type)
442 if (type == -1 || type == NETCONFA_MC_FORWARDING) 442 if (type == -1 || type == NETCONFA_MC_FORWARDING)
443 size += nla_total_size(4); 443 size += nla_total_size(4);
444#endif 444#endif
445 if (type == -1 || type == NETCONFA_PROXY_NEIGH)
446 size += nla_total_size(4);
445 447
446 return size; 448 return size;
447} 449}
@@ -475,6 +477,10 @@ static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
475 devconf->mc_forwarding) < 0) 477 devconf->mc_forwarding) < 0)
476 goto nla_put_failure; 478 goto nla_put_failure;
477#endif 479#endif
480 if ((type == -1 || type == NETCONFA_PROXY_NEIGH) &&
481 nla_put_s32(skb, NETCONFA_PROXY_NEIGH, devconf->proxy_ndp) < 0)
482 goto nla_put_failure;
483
478 return nlmsg_end(skb, nlh); 484 return nlmsg_end(skb, nlh);
479 485
480nla_put_failure: 486nla_put_failure:
@@ -509,6 +515,7 @@ errout:
509static const struct nla_policy devconf_ipv6_policy[NETCONFA_MAX+1] = { 515static const struct nla_policy devconf_ipv6_policy[NETCONFA_MAX+1] = {
510 [NETCONFA_IFINDEX] = { .len = sizeof(int) }, 516 [NETCONFA_IFINDEX] = { .len = sizeof(int) },
511 [NETCONFA_FORWARDING] = { .len = sizeof(int) }, 517 [NETCONFA_FORWARDING] = { .len = sizeof(int) },
518 [NETCONFA_PROXY_NEIGH] = { .len = sizeof(int) },
512}; 519};
513 520
514static int inet6_netconf_get_devconf(struct sk_buff *in_skb, 521static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
@@ -834,6 +841,8 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
834 goto out; 841 goto out;
835 } 842 }
836 843
844 neigh_parms_data_state_setall(idev->nd_parms);
845
837 ifa->addr = *addr; 846 ifa->addr = *addr;
838 if (peer_addr) 847 if (peer_addr)
839 ifa->peer_addr = *peer_addr; 848 ifa->peer_addr = *peer_addr;
@@ -986,12 +995,9 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
986 * --yoshfuji 995 * --yoshfuji
987 */ 996 */
988 if ((ifp->flags & IFA_F_PERMANENT) && onlink < 1) { 997 if ((ifp->flags & IFA_F_PERMANENT) && onlink < 1) {
989 struct in6_addr prefix;
990 struct rt6_info *rt; 998 struct rt6_info *rt;
991 999
992 ipv6_addr_prefix(&prefix, &ifp->addr, ifp->prefix_len); 1000 rt = addrconf_get_prefix_route(&ifp->addr,
993
994 rt = addrconf_get_prefix_route(&prefix,
995 ifp->prefix_len, 1001 ifp->prefix_len,
996 ifp->idev->dev, 1002 ifp->idev->dev,
997 0, RTF_GATEWAY | RTF_DEFAULT); 1003 0, RTF_GATEWAY | RTF_DEFAULT);
@@ -1024,7 +1030,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *i
1024 u32 addr_flags; 1030 u32 addr_flags;
1025 unsigned long now = jiffies; 1031 unsigned long now = jiffies;
1026 1032
1027 write_lock(&idev->lock); 1033 write_lock_bh(&idev->lock);
1028 if (ift) { 1034 if (ift) {
1029 spin_lock_bh(&ift->lock); 1035 spin_lock_bh(&ift->lock);
1030 memcpy(&addr.s6_addr[8], &ift->addr.s6_addr[8], 8); 1036 memcpy(&addr.s6_addr[8], &ift->addr.s6_addr[8], 8);
@@ -1036,7 +1042,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *i
1036retry: 1042retry:
1037 in6_dev_hold(idev); 1043 in6_dev_hold(idev);
1038 if (idev->cnf.use_tempaddr <= 0) { 1044 if (idev->cnf.use_tempaddr <= 0) {
1039 write_unlock(&idev->lock); 1045 write_unlock_bh(&idev->lock);
1040 pr_info("%s: use_tempaddr is disabled\n", __func__); 1046 pr_info("%s: use_tempaddr is disabled\n", __func__);
1041 in6_dev_put(idev); 1047 in6_dev_put(idev);
1042 ret = -1; 1048 ret = -1;
@@ -1046,7 +1052,7 @@ retry:
1046 if (ifp->regen_count++ >= idev->cnf.regen_max_retry) { 1052 if (ifp->regen_count++ >= idev->cnf.regen_max_retry) {
1047 idev->cnf.use_tempaddr = -1; /*XXX*/ 1053 idev->cnf.use_tempaddr = -1; /*XXX*/
1048 spin_unlock_bh(&ifp->lock); 1054 spin_unlock_bh(&ifp->lock);
1049 write_unlock(&idev->lock); 1055 write_unlock_bh(&idev->lock);
1050 pr_warn("%s: regeneration time exceeded - disabled temporary address support\n", 1056 pr_warn("%s: regeneration time exceeded - disabled temporary address support\n",
1051 __func__); 1057 __func__);
1052 in6_dev_put(idev); 1058 in6_dev_put(idev);
@@ -1071,8 +1077,8 @@ retry:
1071 1077
1072 regen_advance = idev->cnf.regen_max_retry * 1078 regen_advance = idev->cnf.regen_max_retry *
1073 idev->cnf.dad_transmits * 1079 idev->cnf.dad_transmits *
1074 idev->nd_parms->retrans_time / HZ; 1080 NEIGH_VAR(idev->nd_parms, RETRANS_TIME) / HZ;
1075 write_unlock(&idev->lock); 1081 write_unlock_bh(&idev->lock);
1076 1082
1077 /* A temporary address is created only if this calculated Preferred 1083 /* A temporary address is created only if this calculated Preferred
1078 * Lifetime is greater than REGEN_ADVANCE time units. In particular, 1084 * Lifetime is greater than REGEN_ADVANCE time units. In particular,
@@ -1099,7 +1105,7 @@ retry:
1099 in6_dev_put(idev); 1105 in6_dev_put(idev);
1100 pr_info("%s: retry temporary address regeneration\n", __func__); 1106 pr_info("%s: retry temporary address regeneration\n", __func__);
1101 tmpaddr = &addr; 1107 tmpaddr = &addr;
1102 write_lock(&idev->lock); 1108 write_lock_bh(&idev->lock);
1103 goto retry; 1109 goto retry;
1104 } 1110 }
1105 1111
@@ -1407,7 +1413,7 @@ try_nextdev:
1407EXPORT_SYMBOL(ipv6_dev_get_saddr); 1413EXPORT_SYMBOL(ipv6_dev_get_saddr);
1408 1414
1409int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr, 1415int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
1410 unsigned char banned_flags) 1416 u32 banned_flags)
1411{ 1417{
1412 struct inet6_ifaddr *ifp; 1418 struct inet6_ifaddr *ifp;
1413 int err = -EADDRNOTAVAIL; 1419 int err = -EADDRNOTAVAIL;
@@ -1424,7 +1430,7 @@ int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
1424} 1430}
1425 1431
1426int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, 1432int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
1427 unsigned char banned_flags) 1433 u32 banned_flags)
1428{ 1434{
1429 struct inet6_dev *idev; 1435 struct inet6_dev *idev;
1430 int err = -EADDRNOTAVAIL; 1436 int err = -EADDRNOTAVAIL;
@@ -1888,7 +1894,8 @@ static void ipv6_regen_rndid(unsigned long data)
1888 1894
1889 expires = jiffies + 1895 expires = jiffies +
1890 idev->cnf.temp_prefered_lft * HZ - 1896 idev->cnf.temp_prefered_lft * HZ -
1891 idev->cnf.regen_max_retry * idev->cnf.dad_transmits * idev->nd_parms->retrans_time - 1897 idev->cnf.regen_max_retry * idev->cnf.dad_transmits *
1898 NEIGH_VAR(idev->nd_parms, RETRANS_TIME) -
1892 idev->cnf.max_desync_factor * HZ; 1899 idev->cnf.max_desync_factor * HZ;
1893 if (time_before(expires, jiffies)) { 1900 if (time_before(expires, jiffies)) {
1894 pr_warn("%s: too short regeneration interval; timer disabled for %s\n", 1901 pr_warn("%s: too short regeneration interval; timer disabled for %s\n",
@@ -2016,6 +2023,73 @@ static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
2016 return idev; 2023 return idev;
2017} 2024}
2018 2025
2026static void manage_tempaddrs(struct inet6_dev *idev,
2027 struct inet6_ifaddr *ifp,
2028 __u32 valid_lft, __u32 prefered_lft,
2029 bool create, unsigned long now)
2030{
2031 u32 flags;
2032 struct inet6_ifaddr *ift;
2033
2034 read_lock_bh(&idev->lock);
2035 /* update all temporary addresses in the list */
2036 list_for_each_entry(ift, &idev->tempaddr_list, tmp_list) {
2037 int age, max_valid, max_prefered;
2038
2039 if (ifp != ift->ifpub)
2040 continue;
2041
2042 /* RFC 4941 section 3.3:
2043 * If a received option will extend the lifetime of a public
2044 * address, the lifetimes of temporary addresses should
2045 * be extended, subject to the overall constraint that no
2046 * temporary addresses should ever remain "valid" or "preferred"
2047 * for a time longer than (TEMP_VALID_LIFETIME) or
2048 * (TEMP_PREFERRED_LIFETIME - DESYNC_FACTOR), respectively.
2049 */
2050 age = (now - ift->cstamp) / HZ;
2051 max_valid = idev->cnf.temp_valid_lft - age;
2052 if (max_valid < 0)
2053 max_valid = 0;
2054
2055 max_prefered = idev->cnf.temp_prefered_lft -
2056 idev->cnf.max_desync_factor - age;
2057 if (max_prefered < 0)
2058 max_prefered = 0;
2059
2060 if (valid_lft > max_valid)
2061 valid_lft = max_valid;
2062
2063 if (prefered_lft > max_prefered)
2064 prefered_lft = max_prefered;
2065
2066 spin_lock(&ift->lock);
2067 flags = ift->flags;
2068 ift->valid_lft = valid_lft;
2069 ift->prefered_lft = prefered_lft;
2070 ift->tstamp = now;
2071 if (prefered_lft > 0)
2072 ift->flags &= ~IFA_F_DEPRECATED;
2073
2074 spin_unlock(&ift->lock);
2075 if (!(flags&IFA_F_TENTATIVE))
2076 ipv6_ifa_notify(0, ift);
2077 }
2078
2079 if ((create || list_empty(&idev->tempaddr_list)) &&
2080 idev->cnf.use_tempaddr > 0) {
2081 /* When a new public address is created as described
2082 * in [ADDRCONF], also create a new temporary address.
2083 * Also create a temporary address if it's enabled but
2084 * no temporary address currently exists.
2085 */
2086 read_unlock_bh(&idev->lock);
2087 ipv6_create_tempaddr(ifp, NULL);
2088 } else {
2089 read_unlock_bh(&idev->lock);
2090 }
2091}
2092
2019void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) 2093void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
2020{ 2094{
2021 struct prefix_info *pinfo; 2095 struct prefix_info *pinfo;
@@ -2170,6 +2244,7 @@ ok:
2170 return; 2244 return;
2171 } 2245 }
2172 2246
2247 ifp->flags |= IFA_F_MANAGETEMPADDR;
2173 update_lft = 0; 2248 update_lft = 0;
2174 create = 1; 2249 create = 1;
2175 ifp->cstamp = jiffies; 2250 ifp->cstamp = jiffies;
@@ -2178,9 +2253,8 @@ ok:
2178 } 2253 }
2179 2254
2180 if (ifp) { 2255 if (ifp) {
2181 int flags; 2256 u32 flags;
2182 unsigned long now; 2257 unsigned long now;
2183 struct inet6_ifaddr *ift;
2184 u32 stored_lft; 2258 u32 stored_lft;
2185 2259
2186 /* update lifetime (RFC2462 5.5.3 e) */ 2260 /* update lifetime (RFC2462 5.5.3 e) */
@@ -2221,70 +2295,8 @@ ok:
2221 } else 2295 } else
2222 spin_unlock(&ifp->lock); 2296 spin_unlock(&ifp->lock);
2223 2297
2224 read_lock_bh(&in6_dev->lock); 2298 manage_tempaddrs(in6_dev, ifp, valid_lft, prefered_lft,
2225 /* update all temporary addresses in the list */ 2299 create, now);
2226 list_for_each_entry(ift, &in6_dev->tempaddr_list,
2227 tmp_list) {
2228 int age, max_valid, max_prefered;
2229
2230 if (ifp != ift->ifpub)
2231 continue;
2232
2233 /*
2234 * RFC 4941 section 3.3:
2235 * If a received option will extend the lifetime
2236 * of a public address, the lifetimes of
2237 * temporary addresses should be extended,
2238 * subject to the overall constraint that no
2239 * temporary addresses should ever remain
2240 * "valid" or "preferred" for a time longer than
2241 * (TEMP_VALID_LIFETIME) or
2242 * (TEMP_PREFERRED_LIFETIME - DESYNC_FACTOR),
2243 * respectively.
2244 */
2245 age = (now - ift->cstamp) / HZ;
2246 max_valid = in6_dev->cnf.temp_valid_lft - age;
2247 if (max_valid < 0)
2248 max_valid = 0;
2249
2250 max_prefered = in6_dev->cnf.temp_prefered_lft -
2251 in6_dev->cnf.max_desync_factor -
2252 age;
2253 if (max_prefered < 0)
2254 max_prefered = 0;
2255
2256 if (valid_lft > max_valid)
2257 valid_lft = max_valid;
2258
2259 if (prefered_lft > max_prefered)
2260 prefered_lft = max_prefered;
2261
2262 spin_lock(&ift->lock);
2263 flags = ift->flags;
2264 ift->valid_lft = valid_lft;
2265 ift->prefered_lft = prefered_lft;
2266 ift->tstamp = now;
2267 if (prefered_lft > 0)
2268 ift->flags &= ~IFA_F_DEPRECATED;
2269
2270 spin_unlock(&ift->lock);
2271 if (!(flags&IFA_F_TENTATIVE))
2272 ipv6_ifa_notify(0, ift);
2273 }
2274
2275 if ((create || list_empty(&in6_dev->tempaddr_list)) && in6_dev->cnf.use_tempaddr > 0) {
2276 /*
2277 * When a new public address is created as
2278 * described in [ADDRCONF], also create a new
2279 * temporary address. Also create a temporary
2280 * address if it's enabled but no temporary
2281 * address currently exists.
2282 */
2283 read_unlock_bh(&in6_dev->lock);
2284 ipv6_create_tempaddr(ifp, NULL);
2285 } else {
2286 read_unlock_bh(&in6_dev->lock);
2287 }
2288 2300
2289 in6_ifa_put(ifp); 2301 in6_ifa_put(ifp);
2290 addrconf_verify(0); 2302 addrconf_verify(0);
@@ -2363,10 +2375,11 @@ err_exit:
2363/* 2375/*
2364 * Manual configuration of address on an interface 2376 * Manual configuration of address on an interface
2365 */ 2377 */
2366static int inet6_addr_add(struct net *net, int ifindex, const struct in6_addr *pfx, 2378static int inet6_addr_add(struct net *net, int ifindex,
2379 const struct in6_addr *pfx,
2367 const struct in6_addr *peer_pfx, 2380 const struct in6_addr *peer_pfx,
2368 unsigned int plen, __u8 ifa_flags, __u32 prefered_lft, 2381 unsigned int plen, __u32 ifa_flags,
2369 __u32 valid_lft) 2382 __u32 prefered_lft, __u32 valid_lft)
2370{ 2383{
2371 struct inet6_ifaddr *ifp; 2384 struct inet6_ifaddr *ifp;
2372 struct inet6_dev *idev; 2385 struct inet6_dev *idev;
@@ -2385,6 +2398,9 @@ static int inet6_addr_add(struct net *net, int ifindex, const struct in6_addr *p
2385 if (!valid_lft || prefered_lft > valid_lft) 2398 if (!valid_lft || prefered_lft > valid_lft)
2386 return -EINVAL; 2399 return -EINVAL;
2387 2400
2401 if (ifa_flags & IFA_F_MANAGETEMPADDR && plen != 64)
2402 return -EINVAL;
2403
2388 dev = __dev_get_by_index(net, ifindex); 2404 dev = __dev_get_by_index(net, ifindex);
2389 if (!dev) 2405 if (!dev)
2390 return -ENODEV; 2406 return -ENODEV;
@@ -2425,6 +2441,9 @@ static int inet6_addr_add(struct net *net, int ifindex, const struct in6_addr *p
2425 * manually configured addresses 2441 * manually configured addresses
2426 */ 2442 */
2427 addrconf_dad_start(ifp); 2443 addrconf_dad_start(ifp);
2444 if (ifa_flags & IFA_F_MANAGETEMPADDR)
2445 manage_tempaddrs(idev, ifp, valid_lft, prefered_lft,
2446 true, jiffies);
2428 in6_ifa_put(ifp); 2447 in6_ifa_put(ifp);
2429 addrconf_verify(0); 2448 addrconf_verify(0);
2430 return 0; 2449 return 0;
@@ -2613,7 +2632,7 @@ static void init_loopback(struct net_device *dev)
2613 if (sp_ifa->rt) 2632 if (sp_ifa->rt)
2614 continue; 2633 continue;
2615 2634
2616 sp_rt = addrconf_dst_alloc(idev, &sp_ifa->addr, 0); 2635 sp_rt = addrconf_dst_alloc(idev, &sp_ifa->addr, false);
2617 2636
2618 /* Failure cases are ignored */ 2637 /* Failure cases are ignored */
2619 if (!IS_ERR(sp_rt)) { 2638 if (!IS_ERR(sp_rt)) {
@@ -3176,7 +3195,8 @@ static void addrconf_dad_timer(unsigned long data)
3176 } 3195 }
3177 3196
3178 ifp->dad_probes--; 3197 ifp->dad_probes--;
3179 addrconf_mod_dad_timer(ifp, ifp->idev->nd_parms->retrans_time); 3198 addrconf_mod_dad_timer(ifp,
3199 NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME));
3180 spin_unlock(&ifp->lock); 3200 spin_unlock(&ifp->lock);
3181 write_unlock(&idev->lock); 3201 write_unlock(&idev->lock);
3182 3202
@@ -3356,7 +3376,7 @@ static int if6_seq_show(struct seq_file *seq, void *v)
3356 ifp->idev->dev->ifindex, 3376 ifp->idev->dev->ifindex,
3357 ifp->prefix_len, 3377 ifp->prefix_len,
3358 ifp->scope, 3378 ifp->scope,
3359 ifp->flags, 3379 (u8) ifp->flags,
3360 ifp->idev->dev->name); 3380 ifp->idev->dev->name);
3361 return 0; 3381 return 0;
3362} 3382}
@@ -3497,7 +3517,7 @@ restart:
3497 !(ifp->flags&IFA_F_TENTATIVE)) { 3517 !(ifp->flags&IFA_F_TENTATIVE)) {
3498 unsigned long regen_advance = ifp->idev->cnf.regen_max_retry * 3518 unsigned long regen_advance = ifp->idev->cnf.regen_max_retry *
3499 ifp->idev->cnf.dad_transmits * 3519 ifp->idev->cnf.dad_transmits *
3500 ifp->idev->nd_parms->retrans_time / HZ; 3520 NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME) / HZ;
3501 3521
3502 if (age >= ifp->prefered_lft - regen_advance) { 3522 if (age >= ifp->prefered_lft - regen_advance) {
3503 struct inet6_ifaddr *ifpub = ifp->ifpub; 3523 struct inet6_ifaddr *ifpub = ifp->ifpub;
@@ -3572,6 +3592,7 @@ static const struct nla_policy ifa_ipv6_policy[IFA_MAX+1] = {
3572 [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) }, 3592 [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) },
3573 [IFA_LOCAL] = { .len = sizeof(struct in6_addr) }, 3593 [IFA_LOCAL] = { .len = sizeof(struct in6_addr) },
3574 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) }, 3594 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) },
3595 [IFA_FLAGS] = { .len = sizeof(u32) },
3575}; 3596};
3576 3597
3577static int 3598static int
@@ -3595,16 +3616,21 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh)
3595 return inet6_addr_del(net, ifm->ifa_index, pfx, ifm->ifa_prefixlen); 3616 return inet6_addr_del(net, ifm->ifa_index, pfx, ifm->ifa_prefixlen);
3596} 3617}
3597 3618
3598static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags, 3619static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags,
3599 u32 prefered_lft, u32 valid_lft) 3620 u32 prefered_lft, u32 valid_lft)
3600{ 3621{
3601 u32 flags; 3622 u32 flags;
3602 clock_t expires; 3623 clock_t expires;
3603 unsigned long timeout; 3624 unsigned long timeout;
3625 bool was_managetempaddr;
3604 3626
3605 if (!valid_lft || (prefered_lft > valid_lft)) 3627 if (!valid_lft || (prefered_lft > valid_lft))
3606 return -EINVAL; 3628 return -EINVAL;
3607 3629
3630 if (ifa_flags & IFA_F_MANAGETEMPADDR &&
3631 (ifp->flags & IFA_F_TEMPORARY || ifp->prefix_len != 64))
3632 return -EINVAL;
3633
3608 timeout = addrconf_timeout_fixup(valid_lft, HZ); 3634 timeout = addrconf_timeout_fixup(valid_lft, HZ);
3609 if (addrconf_finite_timeout(timeout)) { 3635 if (addrconf_finite_timeout(timeout)) {
3610 expires = jiffies_to_clock_t(timeout * HZ); 3636 expires = jiffies_to_clock_t(timeout * HZ);
@@ -3624,7 +3650,10 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
3624 } 3650 }
3625 3651
3626 spin_lock_bh(&ifp->lock); 3652 spin_lock_bh(&ifp->lock);
3627 ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | IFA_F_HOMEADDRESS)) | ifa_flags; 3653 was_managetempaddr = ifp->flags & IFA_F_MANAGETEMPADDR;
3654 ifp->flags &= ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD |
3655 IFA_F_HOMEADDRESS | IFA_F_MANAGETEMPADDR);
3656 ifp->flags |= ifa_flags;
3628 ifp->tstamp = jiffies; 3657 ifp->tstamp = jiffies;
3629 ifp->valid_lft = valid_lft; 3658 ifp->valid_lft = valid_lft;
3630 ifp->prefered_lft = prefered_lft; 3659 ifp->prefered_lft = prefered_lft;
@@ -3635,6 +3664,14 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
3635 3664
3636 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev, 3665 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev,
3637 expires, flags); 3666 expires, flags);
3667
3668 if (was_managetempaddr || ifp->flags & IFA_F_MANAGETEMPADDR) {
3669 if (was_managetempaddr && !(ifp->flags & IFA_F_MANAGETEMPADDR))
3670 valid_lft = prefered_lft = 0;
3671 manage_tempaddrs(ifp->idev, ifp, valid_lft, prefered_lft,
3672 !was_managetempaddr, jiffies);
3673 }
3674
3638 addrconf_verify(0); 3675 addrconf_verify(0);
3639 3676
3640 return 0; 3677 return 0;
@@ -3650,7 +3687,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)
3650 struct inet6_ifaddr *ifa; 3687 struct inet6_ifaddr *ifa;
3651 struct net_device *dev; 3688 struct net_device *dev;
3652 u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME; 3689 u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME;
3653 u8 ifa_flags; 3690 u32 ifa_flags;
3654 int err; 3691 int err;
3655 3692
3656 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); 3693 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
@@ -3677,8 +3714,10 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)
3677 if (dev == NULL) 3714 if (dev == NULL)
3678 return -ENODEV; 3715 return -ENODEV;
3679 3716
3717 ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags;
3718
3680 /* We ignore other flags so far. */ 3719 /* We ignore other flags so far. */
3681 ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS); 3720 ifa_flags &= IFA_F_NODAD | IFA_F_HOMEADDRESS | IFA_F_MANAGETEMPADDR;
3682 3721
3683 ifa = ipv6_get_ifaddr(net, pfx, dev, 1); 3722 ifa = ipv6_get_ifaddr(net, pfx, dev, 1);
3684 if (ifa == NULL) { 3723 if (ifa == NULL) {
@@ -3702,7 +3741,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)
3702 return err; 3741 return err;
3703} 3742}
3704 3743
3705static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags, 3744static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u32 flags,
3706 u8 scope, int ifindex) 3745 u8 scope, int ifindex)
3707{ 3746{
3708 struct ifaddrmsg *ifm; 3747 struct ifaddrmsg *ifm;
@@ -3745,7 +3784,8 @@ static inline int inet6_ifaddr_msgsize(void)
3745 return NLMSG_ALIGN(sizeof(struct ifaddrmsg)) 3784 return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
3746 + nla_total_size(16) /* IFA_LOCAL */ 3785 + nla_total_size(16) /* IFA_LOCAL */
3747 + nla_total_size(16) /* IFA_ADDRESS */ 3786 + nla_total_size(16) /* IFA_ADDRESS */
3748 + nla_total_size(sizeof(struct ifa_cacheinfo)); 3787 + nla_total_size(sizeof(struct ifa_cacheinfo))
3788 + nla_total_size(4) /* IFA_FLAGS */;
3749} 3789}
3750 3790
3751static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, 3791static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
@@ -3793,6 +3833,9 @@ static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
3793 if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) 3833 if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0)
3794 goto error; 3834 goto error;
3795 3835
3836 if (nla_put_u32(skb, IFA_FLAGS, ifa->flags) < 0)
3837 goto error;
3838
3796 return nlmsg_end(skb, nlh); 3839 return nlmsg_end(skb, nlh);
3797 3840
3798error: 3841error:
@@ -4196,7 +4239,7 @@ static int inet6_fill_ifla6_attrs(struct sk_buff *skb, struct inet6_dev *idev)
4196 ci.max_reasm_len = IPV6_MAXPLEN; 4239 ci.max_reasm_len = IPV6_MAXPLEN;
4197 ci.tstamp = cstamp_delta(idev->tstamp); 4240 ci.tstamp = cstamp_delta(idev->tstamp);
4198 ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time); 4241 ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time);
4199 ci.retrans_time = jiffies_to_msecs(idev->nd_parms->retrans_time); 4242 ci.retrans_time = jiffies_to_msecs(NEIGH_VAR(idev->nd_parms, RETRANS_TIME));
4200 if (nla_put(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci)) 4243 if (nla_put(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci))
4201 goto nla_put_failure; 4244 goto nla_put_failure;
4202 nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32)); 4245 nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32));
@@ -4689,6 +4732,46 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
4689 return ret; 4732 return ret;
4690} 4733}
4691 4734
4735static
4736int addrconf_sysctl_proxy_ndp(struct ctl_table *ctl, int write,
4737 void __user *buffer, size_t *lenp, loff_t *ppos)
4738{
4739 int *valp = ctl->data;
4740 int ret;
4741 int old, new;
4742
4743 old = *valp;
4744 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
4745 new = *valp;
4746
4747 if (write && old != new) {
4748 struct net *net = ctl->extra2;
4749
4750 if (!rtnl_trylock())
4751 return restart_syscall();
4752
4753 if (valp == &net->ipv6.devconf_dflt->proxy_ndp)
4754 inet6_netconf_notify_devconf(net, NETCONFA_PROXY_NEIGH,
4755 NETCONFA_IFINDEX_DEFAULT,
4756 net->ipv6.devconf_dflt);
4757 else if (valp == &net->ipv6.devconf_all->proxy_ndp)
4758 inet6_netconf_notify_devconf(net, NETCONFA_PROXY_NEIGH,
4759 NETCONFA_IFINDEX_ALL,
4760 net->ipv6.devconf_all);
4761 else {
4762 struct inet6_dev *idev = ctl->extra1;
4763
4764 inet6_netconf_notify_devconf(net, NETCONFA_PROXY_NEIGH,
4765 idev->dev->ifindex,
4766 &idev->cnf);
4767 }
4768 rtnl_unlock();
4769 }
4770
4771 return ret;
4772}
4773
4774
4692static struct addrconf_sysctl_table 4775static struct addrconf_sysctl_table
4693{ 4776{
4694 struct ctl_table_header *sysctl_header; 4777 struct ctl_table_header *sysctl_header;
@@ -4875,7 +4958,7 @@ static struct addrconf_sysctl_table
4875 .data = &ipv6_devconf.proxy_ndp, 4958 .data = &ipv6_devconf.proxy_ndp,
4876 .maxlen = sizeof(int), 4959 .maxlen = sizeof(int),
4877 .mode = 0644, 4960 .mode = 0644,
4878 .proc_handler = proc_dointvec, 4961 .proc_handler = addrconf_sysctl_proxy_ndp,
4879 }, 4962 },
4880 { 4963 {
4881 .procname = "accept_source_route", 4964 .procname = "accept_source_route",
@@ -4991,7 +5074,7 @@ static void __addrconf_sysctl_unregister(struct ipv6_devconf *p)
4991 5074
4992static void addrconf_sysctl_register(struct inet6_dev *idev) 5075static void addrconf_sysctl_register(struct inet6_dev *idev)
4993{ 5076{
4994 neigh_sysctl_register(idev->dev, idev->nd_parms, "ipv6", 5077 neigh_sysctl_register(idev->dev, idev->nd_parms,
4995 &ndisc_ifinfo_sysctl_change); 5078 &ndisc_ifinfo_sysctl_change);
4996 __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name, 5079 __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name,
4997 idev, &idev->cnf); 5080 idev, &idev->cnf);
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 4fbdb7046d28..c921d5d38831 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -213,7 +213,7 @@ lookup_protocol:
213 inet->mc_list = NULL; 213 inet->mc_list = NULL;
214 inet->rcv_tos = 0; 214 inet->rcv_tos = 0;
215 215
216 if (ipv4_config.no_pmtu_disc) 216 if (net->ipv4.sysctl_ip_no_pmtu_disc)
217 inet->pmtudisc = IP_PMTUDISC_DONT; 217 inet->pmtudisc = IP_PMTUDISC_DONT;
218 else 218 else
219 inet->pmtudisc = IP_PMTUDISC_WANT; 219 inet->pmtudisc = IP_PMTUDISC_WANT;
@@ -661,7 +661,7 @@ int inet6_sk_rebuild_header(struct sock *sk)
661 661
662 final_p = fl6_update_dst(&fl6, np->opt, &final); 662 final_p = fl6_update_dst(&fl6, np->opt, &final);
663 663
664 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, false); 664 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
665 if (IS_ERR(dst)) { 665 if (IS_ERR(dst)) {
666 sk->sk_route_caps = 0; 666 sk->sk_route_caps = 0;
667 sk->sk_err_soft = -PTR_ERR(dst); 667 sk->sk_err_soft = -PTR_ERR(dst);
@@ -683,8 +683,7 @@ bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb)
683 if (np->rxopt.all) { 683 if (np->rxopt.all) {
684 if ((opt->hop && (np->rxopt.bits.hopopts || 684 if ((opt->hop && (np->rxopt.bits.hopopts ||
685 np->rxopt.bits.ohopopts)) || 685 np->rxopt.bits.ohopopts)) ||
686 ((IPV6_FLOWINFO_MASK & 686 (ip6_flowinfo((struct ipv6hdr *) skb_network_header(skb)) &&
687 *(__be32 *)skb_network_header(skb)) &&
688 np->rxopt.bits.rxflow) || 687 np->rxopt.bits.rxflow) ||
689 (opt->srcrt && (np->rxopt.bits.srcrt || 688 (opt->srcrt && (np->rxopt.bits.srcrt ||
690 np->rxopt.bits.osrcrt)) || 689 np->rxopt.bits.osrcrt)) ||
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
index 82e1da3a40b9..81e496a2e008 100644
--- a/net/ipv6/ah6.c
+++ b/net/ipv6/ah6.c
@@ -12,8 +12,7 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * 16 *
18 * Authors 17 * Authors
19 * 18 *
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index a454b0ff57c7..6983058942ea 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -73,7 +73,6 @@ int ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
73 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); 73 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
74 if (flowlabel == NULL) 74 if (flowlabel == NULL)
75 return -EINVAL; 75 return -EINVAL;
76 usin->sin6_addr = flowlabel->dst;
77 } 76 }
78 } 77 }
79 78
@@ -171,7 +170,7 @@ ipv4_connected:
171 opt = flowlabel ? flowlabel->opt : np->opt; 170 opt = flowlabel ? flowlabel->opt : np->opt;
172 final_p = fl6_update_dst(&fl6, opt, &final); 171 final_p = fl6_update_dst(&fl6, opt, &final);
173 172
174 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, true); 173 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
175 err = 0; 174 err = 0;
176 if (IS_ERR(dst)) { 175 if (IS_ERR(dst)) {
177 err = PTR_ERR(dst); 176 err = PTR_ERR(dst);
@@ -318,7 +317,7 @@ void ipv6_local_rxpmtu(struct sock *sk, struct flowi6 *fl6, u32 mtu)
318/* 317/*
319 * Handle MSG_ERRQUEUE 318 * Handle MSG_ERRQUEUE
320 */ 319 */
321int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len) 320int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
322{ 321{
323 struct ipv6_pinfo *np = inet6_sk(sk); 322 struct ipv6_pinfo *np = inet6_sk(sk);
324 struct sock_exterr_skb *serr; 323 struct sock_exterr_skb *serr;
@@ -369,6 +368,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
369 &sin->sin6_addr); 368 &sin->sin6_addr);
370 sin->sin6_scope_id = 0; 369 sin->sin6_scope_id = 0;
371 } 370 }
371 *addr_len = sizeof(*sin);
372 } 372 }
373 373
374 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err)); 374 memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
@@ -377,6 +377,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
377 if (serr->ee.ee_origin != SO_EE_ORIGIN_LOCAL) { 377 if (serr->ee.ee_origin != SO_EE_ORIGIN_LOCAL) {
378 sin->sin6_family = AF_INET6; 378 sin->sin6_family = AF_INET6;
379 sin->sin6_flowinfo = 0; 379 sin->sin6_flowinfo = 0;
380 sin->sin6_port = 0;
380 if (skb->protocol == htons(ETH_P_IPV6)) { 381 if (skb->protocol == htons(ETH_P_IPV6)) {
381 sin->sin6_addr = ipv6_hdr(skb)->saddr; 382 sin->sin6_addr = ipv6_hdr(skb)->saddr;
382 if (np->rxopt.all) 383 if (np->rxopt.all)
@@ -423,7 +424,8 @@ EXPORT_SYMBOL_GPL(ipv6_recv_error);
423/* 424/*
424 * Handle IPV6_RECVPATHMTU 425 * Handle IPV6_RECVPATHMTU
425 */ 426 */
426int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len) 427int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len,
428 int *addr_len)
427{ 429{
428 struct ipv6_pinfo *np = inet6_sk(sk); 430 struct ipv6_pinfo *np = inet6_sk(sk);
429 struct sk_buff *skb; 431 struct sk_buff *skb;
@@ -457,6 +459,7 @@ int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len)
457 sin->sin6_port = 0; 459 sin->sin6_port = 0;
458 sin->sin6_scope_id = mtu_info.ip6m_addr.sin6_scope_id; 460 sin->sin6_scope_id = mtu_info.ip6m_addr.sin6_scope_id;
459 sin->sin6_addr = mtu_info.ip6m_addr.sin6_addr; 461 sin->sin6_addr = mtu_info.ip6m_addr.sin6_addr;
462 *addr_len = sizeof(*sin);
460 } 463 }
461 464
462 put_cmsg(msg, SOL_IPV6, IPV6_PATHMTU, sizeof(mtu_info), &mtu_info); 465 put_cmsg(msg, SOL_IPV6, IPV6_PATHMTU, sizeof(mtu_info), &mtu_info);
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index b8719df0366e..6eef8a7e35f2 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -12,8 +12,7 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * 16 *
18 * Authors 17 * Authors
19 * 18 *
diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index e27591635f92..3fd0a578329e 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -122,7 +122,11 @@ out:
122static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg) 122static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg)
123{ 123{
124 struct rt6_info *rt = (struct rt6_info *) arg->result; 124 struct rt6_info *rt = (struct rt6_info *) arg->result;
125 struct net_device *dev = rt->rt6i_idev->dev; 125 struct net_device *dev = NULL;
126
127 if (rt->rt6i_idev)
128 dev = rt->rt6i_idev->dev;
129
126 /* do not accept result if the route does 130 /* do not accept result if the route does
127 * not meet the required prefix length 131 * not meet the required prefix length
128 */ 132 */
diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
index 77bb8afb141d..c9138189415a 100644
--- a/net/ipv6/inet6_connection_sock.c
+++ b/net/ipv6/inet6_connection_sock.c
@@ -86,7 +86,7 @@ struct dst_entry *inet6_csk_route_req(struct sock *sk,
86 fl6->fl6_sport = htons(ireq->ir_num); 86 fl6->fl6_sport = htons(ireq->ir_num);
87 security_req_classify_flow(req, flowi6_to_flowi(fl6)); 87 security_req_classify_flow(req, flowi6_to_flowi(fl6));
88 88
89 dst = ip6_dst_lookup_flow(sk, fl6, final_p, false); 89 dst = ip6_dst_lookup_flow(sk, fl6, final_p);
90 if (IS_ERR(dst)) 90 if (IS_ERR(dst))
91 return NULL; 91 return NULL;
92 92
@@ -216,7 +216,7 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk,
216 216
217 dst = __inet6_csk_dst_check(sk, np->dst_cookie); 217 dst = __inet6_csk_dst_check(sk, np->dst_cookie);
218 if (!dst) { 218 if (!dst) {
219 dst = ip6_dst_lookup_flow(sk, fl6, final_p, false); 219 dst = ip6_dst_lookup_flow(sk, fl6, final_p);
220 220
221 if (!IS_ERR(dst)) 221 if (!IS_ERR(dst))
222 __inet6_csk_dst_store(sk, dst, NULL, NULL); 222 __inet6_csk_dst_store(sk, dst, NULL, NULL);
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 8acb28621f9c..e27fb78c61f2 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -61,7 +61,6 @@ static bool log_ecn_error = true;
61module_param(log_ecn_error, bool, 0644); 61module_param(log_ecn_error, bool, 0644);
62MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); 62MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
63 63
64#define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
65#define IPV6_TCLASS_SHIFT 20 64#define IPV6_TCLASS_SHIFT 20
66 65
67#define HASH_SIZE_SHIFT 5 66#define HASH_SIZE_SHIFT 5
@@ -846,7 +845,7 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
846 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS) 845 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
847 fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK); 846 fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
848 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) 847 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
849 fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK); 848 fl6.flowlabel |= ip6_flowlabel(ipv6h);
850 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK) 849 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
851 fl6.flowi6_mark = skb->mark; 850 fl6.flowi6_mark = skb->mark;
852 851
diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
index 4b851692b1f6..6fb4162fa785 100644
--- a/net/ipv6/ip6_offload.c
+++ b/net/ipv6/ip6_offload.c
@@ -154,6 +154,32 @@ out:
154 return segs; 154 return segs;
155} 155}
156 156
157/* Return the total length of all the extension hdrs, following the same
158 * logic in ipv6_gso_pull_exthdrs() when parsing ext-hdrs.
159 */
160static int ipv6_exthdrs_len(struct ipv6hdr *iph,
161 const struct net_offload **opps)
162{
163 struct ipv6_opt_hdr *opth = (void *)iph;
164 int len = 0, proto, optlen = sizeof(*iph);
165
166 proto = iph->nexthdr;
167 for (;;) {
168 if (proto != NEXTHDR_HOP) {
169 *opps = rcu_dereference(inet6_offloads[proto]);
170 if (unlikely(!(*opps)))
171 break;
172 if (!((*opps)->flags & INET6_PROTO_GSO_EXTHDR))
173 break;
174 }
175 opth = (void *)opth + optlen;
176 optlen = ipv6_optlen(opth);
177 len += optlen;
178 proto = opth->nexthdr;
179 }
180 return len;
181}
182
157static struct sk_buff **ipv6_gro_receive(struct sk_buff **head, 183static struct sk_buff **ipv6_gro_receive(struct sk_buff **head,
158 struct sk_buff *skb) 184 struct sk_buff *skb)
159{ 185{
@@ -177,6 +203,7 @@ static struct sk_buff **ipv6_gro_receive(struct sk_buff **head,
177 goto out; 203 goto out;
178 } 204 }
179 205
206 skb_set_network_header(skb, off);
180 skb_gro_pull(skb, sizeof(*iph)); 207 skb_gro_pull(skb, sizeof(*iph));
181 skb_set_transport_header(skb, skb_gro_offset(skb)); 208 skb_set_transport_header(skb, skb_gro_offset(skb));
182 209
@@ -211,12 +238,16 @@ static struct sk_buff **ipv6_gro_receive(struct sk_buff **head,
211 if (!NAPI_GRO_CB(p)->same_flow) 238 if (!NAPI_GRO_CB(p)->same_flow)
212 continue; 239 continue;
213 240
214 iph2 = ipv6_hdr(p); 241 iph2 = (struct ipv6hdr *)(p->data + off);
215 first_word = *(__be32 *)iph ^ *(__be32 *)iph2 ; 242 first_word = *(__be32 *)iph ^ *(__be32 *)iph2 ;
216 243
217 /* All fields must match except length and Traffic Class. */ 244 /* All fields must match except length and Traffic Class.
218 if (nlen != skb_network_header_len(p) || 245 * XXX skbs on the gro_list have all been parsed and pulled
219 (first_word & htonl(0xF00FFFFF)) || 246 * already so we don't need to compare nlen
247 * (nlen != (sizeof(*iph2) + ipv6_exthdrs_len(iph2, &ops)))
248 * memcmp() alone below is suffcient, right?
249 */
250 if ((first_word & htonl(0xF00FFFFF)) ||
220 memcmp(&iph->nexthdr, &iph2->nexthdr, 251 memcmp(&iph->nexthdr, &iph2->nexthdr,
221 nlen - offsetof(struct ipv6hdr, nexthdr))) { 252 nlen - offsetof(struct ipv6hdr, nexthdr))) {
222 NAPI_GRO_CB(p)->same_flow = 0; 253 NAPI_GRO_CB(p)->same_flow = 0;
@@ -245,21 +276,21 @@ out:
245 return pp; 276 return pp;
246} 277}
247 278
248static int ipv6_gro_complete(struct sk_buff *skb) 279static int ipv6_gro_complete(struct sk_buff *skb, int nhoff)
249{ 280{
250 const struct net_offload *ops; 281 const struct net_offload *ops;
251 struct ipv6hdr *iph = ipv6_hdr(skb); 282 struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + nhoff);
252 int err = -ENOSYS; 283 int err = -ENOSYS;
253 284
254 iph->payload_len = htons(skb->len - skb_network_offset(skb) - 285 iph->payload_len = htons(skb->len - nhoff - sizeof(*iph));
255 sizeof(*iph));
256 286
257 rcu_read_lock(); 287 rcu_read_lock();
258 ops = rcu_dereference(inet6_offloads[NAPI_GRO_CB(skb)->proto]); 288
289 nhoff += sizeof(*iph) + ipv6_exthdrs_len(iph, &ops);
259 if (WARN_ON(!ops || !ops->callbacks.gro_complete)) 290 if (WARN_ON(!ops || !ops->callbacks.gro_complete))
260 goto out_unlock; 291 goto out_unlock;
261 292
262 err = ops->callbacks.gro_complete(skb); 293 err = ops->callbacks.gro_complete(skb, nhoff);
263 294
264out_unlock: 295out_unlock:
265 rcu_read_unlock(); 296 rcu_read_unlock();
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 59df872e2f4d..788c01a53593 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -116,8 +116,8 @@ static int ip6_finish_output2(struct sk_buff *skb)
116 } 116 }
117 rcu_read_unlock_bh(); 117 rcu_read_unlock_bh();
118 118
119 IP6_INC_STATS_BH(dev_net(dst->dev), 119 IP6_INC_STATS(dev_net(dst->dev),
120 ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES); 120 ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
121 kfree_skb(skb); 121 kfree_skb(skb);
122 return -EINVAL; 122 return -EINVAL;
123} 123}
@@ -336,7 +336,8 @@ int ip6_forward(struct sk_buff *skb)
336 goto drop; 336 goto drop;
337 337
338 if (!xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) { 338 if (!xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) {
339 IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS); 339 IP6_INC_STATS_BH(net, ip6_dst_idev(dst),
340 IPSTATS_MIB_INDISCARDS);
340 goto drop; 341 goto drop;
341 } 342 }
342 343
@@ -370,8 +371,8 @@ int ip6_forward(struct sk_buff *skb)
370 /* Force OUTPUT device used as source address */ 371 /* Force OUTPUT device used as source address */
371 skb->dev = dst->dev; 372 skb->dev = dst->dev;
372 icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); 373 icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0);
373 IP6_INC_STATS_BH(net, 374 IP6_INC_STATS_BH(net, ip6_dst_idev(dst),
374 ip6_dst_idev(dst), IPSTATS_MIB_INHDRERRORS); 375 IPSTATS_MIB_INHDRERRORS);
375 376
376 kfree_skb(skb); 377 kfree_skb(skb);
377 return -ETIMEDOUT; 378 return -ETIMEDOUT;
@@ -384,14 +385,15 @@ int ip6_forward(struct sk_buff *skb)
384 if (proxied > 0) 385 if (proxied > 0)
385 return ip6_input(skb); 386 return ip6_input(skb);
386 else if (proxied < 0) { 387 else if (proxied < 0) {
387 IP6_INC_STATS(net, ip6_dst_idev(dst), 388 IP6_INC_STATS_BH(net, ip6_dst_idev(dst),
388 IPSTATS_MIB_INDISCARDS); 389 IPSTATS_MIB_INDISCARDS);
389 goto drop; 390 goto drop;
390 } 391 }
391 } 392 }
392 393
393 if (!xfrm6_route_forward(skb)) { 394 if (!xfrm6_route_forward(skb)) {
394 IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS); 395 IP6_INC_STATS_BH(net, ip6_dst_idev(dst),
396 IPSTATS_MIB_INDISCARDS);
395 goto drop; 397 goto drop;
396 } 398 }
397 dst = skb_dst(skb); 399 dst = skb_dst(skb);
@@ -448,16 +450,17 @@ int ip6_forward(struct sk_buff *skb)
448 /* Again, force OUTPUT device used as source address */ 450 /* Again, force OUTPUT device used as source address */
449 skb->dev = dst->dev; 451 skb->dev = dst->dev;
450 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu); 452 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
451 IP6_INC_STATS_BH(net, 453 IP6_INC_STATS_BH(net, ip6_dst_idev(dst),
452 ip6_dst_idev(dst), IPSTATS_MIB_INTOOBIGERRORS); 454 IPSTATS_MIB_INTOOBIGERRORS);
453 IP6_INC_STATS_BH(net, 455 IP6_INC_STATS_BH(net, ip6_dst_idev(dst),
454 ip6_dst_idev(dst), IPSTATS_MIB_FRAGFAILS); 456 IPSTATS_MIB_FRAGFAILS);
455 kfree_skb(skb); 457 kfree_skb(skb);
456 return -EMSGSIZE; 458 return -EMSGSIZE;
457 } 459 }
458 460
459 if (skb_cow(skb, dst->dev->hard_header_len)) { 461 if (skb_cow(skb, dst->dev->hard_header_len)) {
460 IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTDISCARDS); 462 IP6_INC_STATS_BH(net, ip6_dst_idev(dst),
463 IPSTATS_MIB_OUTDISCARDS);
461 goto drop; 464 goto drop;
462 } 465 }
463 466
@@ -938,7 +941,6 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup);
938 * @sk: socket which provides route info 941 * @sk: socket which provides route info
939 * @fl6: flow to lookup 942 * @fl6: flow to lookup
940 * @final_dst: final destination address for ipsec lookup 943 * @final_dst: final destination address for ipsec lookup
941 * @can_sleep: we are in a sleepable context
942 * 944 *
943 * This function performs a route lookup on the given flow. 945 * This function performs a route lookup on the given flow.
944 * 946 *
@@ -946,8 +948,7 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup);
946 * error code. 948 * error code.
947 */ 949 */
948struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6, 950struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
949 const struct in6_addr *final_dst, 951 const struct in6_addr *final_dst)
950 bool can_sleep)
951{ 952{
952 struct dst_entry *dst = NULL; 953 struct dst_entry *dst = NULL;
953 int err; 954 int err;
@@ -957,8 +958,6 @@ struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
957 return ERR_PTR(err); 958 return ERR_PTR(err);
958 if (final_dst) 959 if (final_dst)
959 fl6->daddr = *final_dst; 960 fl6->daddr = *final_dst;
960 if (can_sleep)
961 fl6->flowi6_flags |= FLOWI_FLAG_CAN_SLEEP;
962 961
963 return xfrm_lookup(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0); 962 return xfrm_lookup(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
964} 963}
@@ -969,7 +968,6 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
969 * @sk: socket which provides the dst cache and route info 968 * @sk: socket which provides the dst cache and route info
970 * @fl6: flow to lookup 969 * @fl6: flow to lookup
971 * @final_dst: final destination address for ipsec lookup 970 * @final_dst: final destination address for ipsec lookup
972 * @can_sleep: we are in a sleepable context
973 * 971 *
974 * This function performs a route lookup on the given flow with the 972 * This function performs a route lookup on the given flow with the
975 * possibility of using the cached route in the socket if it is valid. 973 * possibility of using the cached route in the socket if it is valid.
@@ -980,8 +978,7 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
980 * error code. 978 * error code.
981 */ 979 */
982struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6, 980struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
983 const struct in6_addr *final_dst, 981 const struct in6_addr *final_dst)
984 bool can_sleep)
985{ 982{
986 struct dst_entry *dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie); 983 struct dst_entry *dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie);
987 int err; 984 int err;
@@ -993,8 +990,6 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
993 return ERR_PTR(err); 990 return ERR_PTR(err);
994 if (final_dst) 991 if (final_dst)
995 fl6->daddr = *final_dst; 992 fl6->daddr = *final_dst;
996 if (can_sleep)
997 fl6->flowi6_flags |= FLOWI_FLAG_CAN_SLEEP;
998 993
999 return xfrm_lookup(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0); 994 return xfrm_lookup(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
1000} 995}
@@ -1162,10 +1157,10 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
1162 np->cork.hop_limit = hlimit; 1157 np->cork.hop_limit = hlimit;
1163 np->cork.tclass = tclass; 1158 np->cork.tclass = tclass;
1164 if (rt->dst.flags & DST_XFRM_TUNNEL) 1159 if (rt->dst.flags & DST_XFRM_TUNNEL)
1165 mtu = np->pmtudisc == IPV6_PMTUDISC_PROBE ? 1160 mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ?
1166 rt->dst.dev->mtu : dst_mtu(&rt->dst); 1161 rt->dst.dev->mtu : dst_mtu(&rt->dst);
1167 else 1162 else
1168 mtu = np->pmtudisc == IPV6_PMTUDISC_PROBE ? 1163 mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ?
1169 rt->dst.dev->mtu : dst_mtu(rt->dst.path); 1164 rt->dst.dev->mtu : dst_mtu(rt->dst.path);
1170 if (np->frag_size < mtu) { 1165 if (np->frag_size < mtu) {
1171 if (np->frag_size) 1166 if (np->frag_size)
@@ -1267,7 +1262,7 @@ alloc_new_skb:
1267 if (skb == NULL || skb_prev == NULL) 1262 if (skb == NULL || skb_prev == NULL)
1268 ip6_append_data_mtu(&mtu, &maxfraglen, 1263 ip6_append_data_mtu(&mtu, &maxfraglen,
1269 fragheaderlen, skb, rt, 1264 fragheaderlen, skb, rt,
1270 np->pmtudisc == 1265 np->pmtudisc >=
1271 IPV6_PMTUDISC_PROBE); 1266 IPV6_PMTUDISC_PROBE);
1272 1267
1273 skb_prev = skb; 1268 skb_prev = skb;
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index d6062325db08..8d7c9867a445 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -70,7 +70,6 @@ MODULE_ALIAS_NETDEV("ip6tnl0");
70#define IP6_TNL_TRACE(x...) do {;} while(0) 70#define IP6_TNL_TRACE(x...) do {;} while(0)
71#endif 71#endif
72 72
73#define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
74#define IPV6_TCLASS_SHIFT 20 73#define IPV6_TCLASS_SHIFT 20
75 74
76#define HASH_SIZE_SHIFT 5 75#define HASH_SIZE_SHIFT 5
@@ -1131,7 +1130,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1131 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS) 1130 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1132 fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK); 1131 fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
1133 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) 1132 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
1134 fl6.flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK); 1133 fl6.flowlabel |= ip6_flowlabel(ipv6h);
1135 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK) 1134 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
1136 fl6.flowi6_mark = skb->mark; 1135 fl6.flowi6_mark = skb->mark;
1137 1136
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c
index ce507d9e1c90..da9becb42e81 100644
--- a/net/ipv6/ipcomp6.c
+++ b/net/ipv6/ipcomp6.c
@@ -16,8 +16,7 @@
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 20 */
22/* 21/*
23 * [Memo] 22 * [Memo]
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 1c6ce3119ff8..af0ecb94b3b4 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -722,7 +722,7 @@ done:
722 case IPV6_MTU_DISCOVER: 722 case IPV6_MTU_DISCOVER:
723 if (optlen < sizeof(int)) 723 if (optlen < sizeof(int))
724 goto e_inval; 724 goto e_inval;
725 if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_PROBE) 725 if (val < IPV6_PMTUDISC_DONT || val > IPV6_PMTUDISC_INTERFACE)
726 goto e_inval; 726 goto e_inval;
727 np->pmtudisc = val; 727 np->pmtudisc = val;
728 retv = 0; 728 retv = 0;
@@ -1019,7 +1019,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
1019 put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim); 1019 put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim);
1020 } 1020 }
1021 if (np->rxopt.bits.rxtclass) { 1021 if (np->rxopt.bits.rxtclass) {
1022 int tclass = np->rcv_tclass; 1022 int tclass = ntohl(np->rcv_flowinfo & IPV6_TCLASS_MASK) >> 20;
1023 put_cmsg(&msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass); 1023 put_cmsg(&msg, SOL_IPV6, IPV6_TCLASS, sizeof(tclass), &tclass);
1024 } 1024 }
1025 if (np->rxopt.bits.rxoinfo) { 1025 if (np->rxopt.bits.rxoinfo) {
@@ -1034,6 +1034,11 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
1034 int hlim = np->mcast_hops; 1034 int hlim = np->mcast_hops;
1035 put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim); 1035 put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim);
1036 } 1036 }
1037 if (np->rxopt.bits.rxflow) {
1038 __be32 flowinfo = np->rcv_flowinfo;
1039
1040 put_cmsg(&msg, SOL_IPV6, IPV6_FLOWINFO, sizeof(flowinfo), &flowinfo);
1041 }
1037 } 1042 }
1038 len -= msg.msg_controllen; 1043 len -= msg.msg_controllen;
1039 return put_user(len, optlen); 1044 return put_user(len, optlen);
diff --git a/net/ipv6/mip6.c b/net/ipv6/mip6.c
index 9ac01dc9402e..db9b6cbc9db3 100644
--- a/net/ipv6/mip6.c
+++ b/net/ipv6/mip6.c
@@ -13,8 +13,7 @@
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 17 */
19/* 18/*
20 * Authors: 19 * Authors:
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 3512177deb4d..09a22f4f36c9 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -125,17 +125,19 @@ struct neigh_table nd_tbl = {
125 .id = "ndisc_cache", 125 .id = "ndisc_cache",
126 .parms = { 126 .parms = {
127 .tbl = &nd_tbl, 127 .tbl = &nd_tbl,
128 .base_reachable_time = ND_REACHABLE_TIME,
129 .retrans_time = ND_RETRANS_TIMER,
130 .gc_staletime = 60 * HZ,
131 .reachable_time = ND_REACHABLE_TIME, 128 .reachable_time = ND_REACHABLE_TIME,
132 .delay_probe_time = 5 * HZ, 129 .data = {
133 .queue_len_bytes = 64*1024, 130 [NEIGH_VAR_MCAST_PROBES] = 3,
134 .ucast_probes = 3, 131 [NEIGH_VAR_UCAST_PROBES] = 3,
135 .mcast_probes = 3, 132 [NEIGH_VAR_RETRANS_TIME] = ND_RETRANS_TIMER,
136 .anycast_delay = 1 * HZ, 133 [NEIGH_VAR_BASE_REACHABLE_TIME] = ND_REACHABLE_TIME,
137 .proxy_delay = (8 * HZ) / 10, 134 [NEIGH_VAR_DELAY_PROBE_TIME] = 5 * HZ,
138 .proxy_qlen = 64, 135 [NEIGH_VAR_GC_STALETIME] = 60 * HZ,
136 [NEIGH_VAR_QUEUE_LEN_BYTES] = 64 * 1024,
137 [NEIGH_VAR_PROXY_QLEN] = 64,
138 [NEIGH_VAR_ANYCAST_DELAY] = 1 * HZ,
139 [NEIGH_VAR_PROXY_DELAY] = (8 * HZ) / 10,
140 },
139 }, 141 },
140 .gc_interval = 30 * HZ, 142 .gc_interval = 30 * HZ,
141 .gc_thresh1 = 128, 143 .gc_thresh1 = 128,
@@ -656,14 +658,14 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb)
656 if (skb && ipv6_chk_addr(dev_net(dev), &ipv6_hdr(skb)->saddr, dev, 1)) 658 if (skb && ipv6_chk_addr(dev_net(dev), &ipv6_hdr(skb)->saddr, dev, 1))
657 saddr = &ipv6_hdr(skb)->saddr; 659 saddr = &ipv6_hdr(skb)->saddr;
658 660
659 if ((probes -= neigh->parms->ucast_probes) < 0) { 661 if ((probes -= NEIGH_VAR(neigh->parms, UCAST_PROBES)) < 0) {
660 if (!(neigh->nud_state & NUD_VALID)) { 662 if (!(neigh->nud_state & NUD_VALID)) {
661 ND_PRINTK(1, dbg, 663 ND_PRINTK(1, dbg,
662 "%s: trying to ucast probe in NUD_INVALID: %pI6\n", 664 "%s: trying to ucast probe in NUD_INVALID: %pI6\n",
663 __func__, target); 665 __func__, target);
664 } 666 }
665 ndisc_send_ns(dev, neigh, target, target, saddr); 667 ndisc_send_ns(dev, neigh, target, target, saddr);
666 } else if ((probes -= neigh->parms->app_probes) < 0) { 668 } else if ((probes -= NEIGH_VAR(neigh->parms, APP_PROBES)) < 0) {
667 neigh_app_ns(neigh); 669 neigh_app_ns(neigh);
668 } else { 670 } else {
669 addrconf_addr_solict_mult(target, &mcaddr); 671 addrconf_addr_solict_mult(target, &mcaddr);
@@ -790,7 +792,7 @@ static void ndisc_recv_ns(struct sk_buff *skb)
790 if (!(NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED) && 792 if (!(NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED) &&
791 skb->pkt_type != PACKET_HOST && 793 skb->pkt_type != PACKET_HOST &&
792 inc && 794 inc &&
793 idev->nd_parms->proxy_delay != 0) { 795 NEIGH_VAR(idev->nd_parms, PROXY_DELAY) != 0) {
794 /* 796 /*
795 * for anycast or proxy, 797 * for anycast or proxy,
796 * sender should delay its response 798 * sender should delay its response
@@ -1210,7 +1212,7 @@ skip_defrtr:
1210 rtime = (rtime*HZ)/1000; 1212 rtime = (rtime*HZ)/1000;
1211 if (rtime < HZ/10) 1213 if (rtime < HZ/10)
1212 rtime = HZ/10; 1214 rtime = HZ/10;
1213 in6_dev->nd_parms->retrans_time = rtime; 1215 NEIGH_VAR_SET(in6_dev->nd_parms, RETRANS_TIME, rtime);
1214 in6_dev->tstamp = jiffies; 1216 in6_dev->tstamp = jiffies;
1215 inet6_ifinfo_notify(RTM_NEWLINK, in6_dev); 1217 inet6_ifinfo_notify(RTM_NEWLINK, in6_dev);
1216 } 1218 }
@@ -1222,9 +1224,11 @@ skip_defrtr:
1222 if (rtime < HZ/10) 1224 if (rtime < HZ/10)
1223 rtime = HZ/10; 1225 rtime = HZ/10;
1224 1226
1225 if (rtime != in6_dev->nd_parms->base_reachable_time) { 1227 if (rtime != NEIGH_VAR(in6_dev->nd_parms, BASE_REACHABLE_TIME)) {
1226 in6_dev->nd_parms->base_reachable_time = rtime; 1228 NEIGH_VAR_SET(in6_dev->nd_parms,
1227 in6_dev->nd_parms->gc_staletime = 3 * rtime; 1229 BASE_REACHABLE_TIME, rtime);
1230 NEIGH_VAR_SET(in6_dev->nd_parms,
1231 GC_STALETIME, 3 * rtime);
1228 in6_dev->nd_parms->reachable_time = neigh_rand_reach_time(rtime); 1232 in6_dev->nd_parms->reachable_time = neigh_rand_reach_time(rtime);
1229 in6_dev->tstamp = jiffies; 1233 in6_dev->tstamp = jiffies;
1230 inet6_ifinfo_notify(RTM_NEWLINK, in6_dev); 1234 inet6_ifinfo_notify(RTM_NEWLINK, in6_dev);
@@ -1277,6 +1281,9 @@ skip_linkparms:
1277 ri->prefix_len == 0) 1281 ri->prefix_len == 0)
1278 continue; 1282 continue;
1279#endif 1283#endif
1284 if (ri->prefix_len == 0 &&
1285 !in6_dev->cnf.accept_ra_defrtr)
1286 continue;
1280 if (ri->prefix_len > in6_dev->cnf.accept_ra_rt_info_max_plen) 1287 if (ri->prefix_len > in6_dev->cnf.accept_ra_rt_info_max_plen)
1281 continue; 1288 continue;
1282 rt6_route_rcv(skb->dev, (u8*)p, (p->nd_opt_len) << 3, 1289 rt6_route_rcv(skb->dev, (u8*)p, (p->nd_opt_len) << 3,
@@ -1648,22 +1655,23 @@ int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, void __user *bu
1648 ndisc_warn_deprecated_sysctl(ctl, "syscall", dev ? dev->name : "default"); 1655 ndisc_warn_deprecated_sysctl(ctl, "syscall", dev ? dev->name : "default");
1649 1656
1650 if (strcmp(ctl->procname, "retrans_time") == 0) 1657 if (strcmp(ctl->procname, "retrans_time") == 0)
1651 ret = proc_dointvec(ctl, write, buffer, lenp, ppos); 1658 ret = neigh_proc_dointvec(ctl, write, buffer, lenp, ppos);
1652 1659
1653 else if (strcmp(ctl->procname, "base_reachable_time") == 0) 1660 else if (strcmp(ctl->procname, "base_reachable_time") == 0)
1654 ret = proc_dointvec_jiffies(ctl, write, 1661 ret = neigh_proc_dointvec_jiffies(ctl, write,
1655 buffer, lenp, ppos); 1662 buffer, lenp, ppos);
1656 1663
1657 else if ((strcmp(ctl->procname, "retrans_time_ms") == 0) || 1664 else if ((strcmp(ctl->procname, "retrans_time_ms") == 0) ||
1658 (strcmp(ctl->procname, "base_reachable_time_ms") == 0)) 1665 (strcmp(ctl->procname, "base_reachable_time_ms") == 0))
1659 ret = proc_dointvec_ms_jiffies(ctl, write, 1666 ret = neigh_proc_dointvec_ms_jiffies(ctl, write,
1660 buffer, lenp, ppos); 1667 buffer, lenp, ppos);
1661 else 1668 else
1662 ret = -1; 1669 ret = -1;
1663 1670
1664 if (write && ret == 0 && dev && (idev = in6_dev_get(dev)) != NULL) { 1671 if (write && ret == 0 && dev && (idev = in6_dev_get(dev)) != NULL) {
1665 if (ctl->data == &idev->nd_parms->base_reachable_time) 1672 if (ctl->data == &NEIGH_VAR(idev->nd_parms, BASE_REACHABLE_TIME))
1666 idev->nd_parms->reachable_time = neigh_rand_reach_time(idev->nd_parms->base_reachable_time); 1673 idev->nd_parms->reachable_time =
1674 neigh_rand_reach_time(NEIGH_VAR(idev->nd_parms, BASE_REACHABLE_TIME));
1667 idev->tstamp = jiffies; 1675 idev->tstamp = jiffies;
1668 inet6_ifinfo_notify(RTM_NEWLINK, idev); 1676 inet6_ifinfo_notify(RTM_NEWLINK, idev);
1669 in6_dev_put(idev); 1677 in6_dev_put(idev);
@@ -1722,7 +1730,7 @@ int __init ndisc_init(void)
1722 neigh_table_init(&nd_tbl); 1730 neigh_table_init(&nd_tbl);
1723 1731
1724#ifdef CONFIG_SYSCTL 1732#ifdef CONFIG_SYSCTL
1725 err = neigh_sysctl_register(NULL, &nd_tbl.parms, "ipv6", 1733 err = neigh_sysctl_register(NULL, &nd_tbl.parms,
1726 &ndisc_ifinfo_sysctl_change); 1734 &ndisc_ifinfo_sysctl_change);
1727 if (err) 1735 if (err)
1728 goto out_unregister_pernet; 1736 goto out_unregister_pernet;
diff --git a/net/ipv6/netfilter/ip6t_SYNPROXY.c b/net/ipv6/netfilter/ip6t_SYNPROXY.c
index f78f41aca8e9..a0d17270117c 100644
--- a/net/ipv6/netfilter/ip6t_SYNPROXY.c
+++ b/net/ipv6/netfilter/ip6t_SYNPROXY.c
@@ -446,6 +446,7 @@ static void synproxy_tg6_destroy(const struct xt_tgdtor_param *par)
446static struct xt_target synproxy_tg6_reg __read_mostly = { 446static struct xt_target synproxy_tg6_reg __read_mostly = {
447 .name = "SYNPROXY", 447 .name = "SYNPROXY",
448 .family = NFPROTO_IPV6, 448 .family = NFPROTO_IPV6,
449 .hooks = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD),
449 .target = synproxy_tg6, 450 .target = synproxy_tg6,
450 .targetsize = sizeof(struct xt_synproxy_info), 451 .targetsize = sizeof(struct xt_synproxy_info),
451 .checkentry = synproxy_tg6_check, 452 .checkentry = synproxy_tg6_check,
diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
index 8815e31a87fe..15d23b8c2129 100644
--- a/net/ipv6/ping.c
+++ b/net/ipv6/ping.c
@@ -57,7 +57,8 @@ static struct inet_protosw pingv6_protosw = {
57 57
58 58
59/* Compatibility glue so we can support IPv6 when it's compiled as a module */ 59/* Compatibility glue so we can support IPv6 when it's compiled as a module */
60static int dummy_ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len) 60static int dummy_ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len,
61 int *addr_len)
61{ 62{
62 return -EAFNOSUPPORT; 63 return -EAFNOSUPPORT;
63} 64}
@@ -144,7 +145,7 @@ int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
144 else if (!fl6.flowi6_oif) 145 else if (!fl6.flowi6_oif)
145 fl6.flowi6_oif = np->ucast_oif; 146 fl6.flowi6_oif = np->ucast_oif;
146 147
147 dst = ip6_sk_dst_lookup_flow(sk, &fl6, daddr, 1); 148 dst = ip6_sk_dst_lookup_flow(sk, &fl6, daddr);
148 if (IS_ERR(dst)) 149 if (IS_ERR(dst))
149 return PTR_ERR(dst); 150 return PTR_ERR(dst);
150 rt = (struct rt6_info *) dst; 151 rt = (struct rt6_info *) dst;
diff --git a/net/ipv6/protocol.c b/net/ipv6/protocol.c
index 22d1bd4670da..e048cf1bb6a2 100644
--- a/net/ipv6/protocol.c
+++ b/net/ipv6/protocol.c
@@ -36,10 +36,6 @@ int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char protocol
36} 36}
37EXPORT_SYMBOL(inet6_add_protocol); 37EXPORT_SYMBOL(inet6_add_protocol);
38 38
39/*
40 * Remove a protocol from the hash tables.
41 */
42
43int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol) 39int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char protocol)
44{ 40{
45 int ret; 41 int ret;
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index e24ff1df0401..5f10b7ea7ccc 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -466,10 +466,10 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
466 return -EOPNOTSUPP; 466 return -EOPNOTSUPP;
467 467
468 if (flags & MSG_ERRQUEUE) 468 if (flags & MSG_ERRQUEUE)
469 return ipv6_recv_error(sk, msg, len); 469 return ipv6_recv_error(sk, msg, len, addr_len);
470 470
471 if (np->rxpmtu && np->rxopt.bits.rxpmtu) 471 if (np->rxpmtu && np->rxopt.bits.rxpmtu)
472 return ipv6_recv_rxpmtu(sk, msg, len); 472 return ipv6_recv_rxpmtu(sk, msg, len, addr_len);
473 473
474 skb = skb_recv_datagram(sk, flags, noblock, &err); 474 skb = skb_recv_datagram(sk, flags, noblock, &err);
475 if (!skb) 475 if (!skb)
@@ -792,7 +792,6 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
792 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); 792 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
793 if (flowlabel == NULL) 793 if (flowlabel == NULL)
794 return -EINVAL; 794 return -EINVAL;
795 daddr = &flowlabel->dst;
796 } 795 }
797 } 796 }
798 797
@@ -865,7 +864,7 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
865 fl6.flowi6_oif = np->ucast_oif; 864 fl6.flowi6_oif = np->ucast_oif;
866 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 865 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
867 866
868 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, true); 867 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
869 if (IS_ERR(dst)) { 868 if (IS_ERR(dst)) {
870 err = PTR_ERR(dst); 869 err = PTR_ERR(dst);
871 goto out; 870 goto out;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 7faa9d5e1503..89b2735cecf5 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -66,8 +66,9 @@
66#endif 66#endif
67 67
68enum rt6_nud_state { 68enum rt6_nud_state {
69 RT6_NUD_FAIL_HARD = -2, 69 RT6_NUD_FAIL_HARD = -3,
70 RT6_NUD_FAIL_SOFT = -1, 70 RT6_NUD_FAIL_PROBE = -2,
71 RT6_NUD_FAIL_DO_RR = -1,
71 RT6_NUD_SUCCEED = 1 72 RT6_NUD_SUCCEED = 1
72}; 73};
73 74
@@ -84,6 +85,8 @@ static int ip6_dst_gc(struct dst_ops *ops);
84 85
85static int ip6_pkt_discard(struct sk_buff *skb); 86static int ip6_pkt_discard(struct sk_buff *skb);
86static int ip6_pkt_discard_out(struct sk_buff *skb); 87static int ip6_pkt_discard_out(struct sk_buff *skb);
88static int ip6_pkt_prohibit(struct sk_buff *skb);
89static int ip6_pkt_prohibit_out(struct sk_buff *skb);
87static void ip6_link_failure(struct sk_buff *skb); 90static void ip6_link_failure(struct sk_buff *skb);
88static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk, 91static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
89 struct sk_buff *skb, u32 mtu); 92 struct sk_buff *skb, u32 mtu);
@@ -234,9 +237,6 @@ static const struct rt6_info ip6_null_entry_template = {
234 237
235#ifdef CONFIG_IPV6_MULTIPLE_TABLES 238#ifdef CONFIG_IPV6_MULTIPLE_TABLES
236 239
237static int ip6_pkt_prohibit(struct sk_buff *skb);
238static int ip6_pkt_prohibit_out(struct sk_buff *skb);
239
240static const struct rt6_info ip6_prohibit_entry_template = { 240static const struct rt6_info ip6_prohibit_entry_template = {
241 .dst = { 241 .dst = {
242 .__refcnt = ATOMIC_INIT(1), 242 .__refcnt = ATOMIC_INIT(1),
@@ -522,7 +522,7 @@ static void rt6_probe(struct rt6_info *rt)
522 work = kmalloc(sizeof(*work), GFP_ATOMIC); 522 work = kmalloc(sizeof(*work), GFP_ATOMIC);
523 523
524 if (neigh && work) 524 if (neigh && work)
525 neigh->updated = jiffies; 525 __neigh_set_probe_once(neigh);
526 526
527 if (neigh) 527 if (neigh)
528 write_unlock(&neigh->lock); 528 write_unlock(&neigh->lock);
@@ -578,11 +578,13 @@ static inline enum rt6_nud_state rt6_check_neigh(struct rt6_info *rt)
578#ifdef CONFIG_IPV6_ROUTER_PREF 578#ifdef CONFIG_IPV6_ROUTER_PREF
579 else if (!(neigh->nud_state & NUD_FAILED)) 579 else if (!(neigh->nud_state & NUD_FAILED))
580 ret = RT6_NUD_SUCCEED; 580 ret = RT6_NUD_SUCCEED;
581 else
582 ret = RT6_NUD_FAIL_PROBE;
581#endif 583#endif
582 read_unlock(&neigh->lock); 584 read_unlock(&neigh->lock);
583 } else { 585 } else {
584 ret = IS_ENABLED(CONFIG_IPV6_ROUTER_PREF) ? 586 ret = IS_ENABLED(CONFIG_IPV6_ROUTER_PREF) ?
585 RT6_NUD_SUCCEED : RT6_NUD_FAIL_SOFT; 587 RT6_NUD_SUCCEED : RT6_NUD_FAIL_DO_RR;
586 } 588 }
587 rcu_read_unlock_bh(); 589 rcu_read_unlock_bh();
588 590
@@ -619,16 +621,17 @@ static struct rt6_info *find_match(struct rt6_info *rt, int oif, int strict,
619 goto out; 621 goto out;
620 622
621 m = rt6_score_route(rt, oif, strict); 623 m = rt6_score_route(rt, oif, strict);
622 if (m == RT6_NUD_FAIL_SOFT) { 624 if (m == RT6_NUD_FAIL_DO_RR) {
623 match_do_rr = true; 625 match_do_rr = true;
624 m = 0; /* lowest valid score */ 626 m = 0; /* lowest valid score */
625 } else if (m < 0) { 627 } else if (m == RT6_NUD_FAIL_HARD) {
626 goto out; 628 goto out;
627 } 629 }
628 630
629 if (strict & RT6_LOOKUP_F_REACHABLE) 631 if (strict & RT6_LOOKUP_F_REACHABLE)
630 rt6_probe(rt); 632 rt6_probe(rt);
631 633
634 /* note that m can be RT6_NUD_FAIL_PROBE at this point */
632 if (m > *mpri) { 635 if (m > *mpri) {
633 *do_rr = match_do_rr; 636 *do_rr = match_do_rr;
634 *mpri = m; 637 *mpri = m;
@@ -1565,21 +1568,24 @@ int ip6_route_add(struct fib6_config *cfg)
1565 goto out; 1568 goto out;
1566 } 1569 }
1567 } 1570 }
1568 rt->dst.output = ip6_pkt_discard_out;
1569 rt->dst.input = ip6_pkt_discard;
1570 rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP; 1571 rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP;
1571 switch (cfg->fc_type) { 1572 switch (cfg->fc_type) {
1572 case RTN_BLACKHOLE: 1573 case RTN_BLACKHOLE:
1573 rt->dst.error = -EINVAL; 1574 rt->dst.error = -EINVAL;
1575 rt->dst.output = dst_discard;
1576 rt->dst.input = dst_discard;
1574 break; 1577 break;
1575 case RTN_PROHIBIT: 1578 case RTN_PROHIBIT:
1576 rt->dst.error = -EACCES; 1579 rt->dst.error = -EACCES;
1580 rt->dst.output = ip6_pkt_prohibit_out;
1581 rt->dst.input = ip6_pkt_prohibit;
1577 break; 1582 break;
1578 case RTN_THROW: 1583 case RTN_THROW:
1579 rt->dst.error = -EAGAIN;
1580 break;
1581 default: 1584 default:
1582 rt->dst.error = -ENETUNREACH; 1585 rt->dst.error = (cfg->fc_type == RTN_THROW) ? -EAGAIN
1586 : -ENETUNREACH;
1587 rt->dst.output = ip6_pkt_discard_out;
1588 rt->dst.input = ip6_pkt_discard;
1583 break; 1589 break;
1584 } 1590 }
1585 goto install_route; 1591 goto install_route;
@@ -2144,8 +2150,6 @@ static int ip6_pkt_discard_out(struct sk_buff *skb)
2144 return ip6_pkt_drop(skb, ICMPV6_NOROUTE, IPSTATS_MIB_OUTNOROUTES); 2150 return ip6_pkt_drop(skb, ICMPV6_NOROUTE, IPSTATS_MIB_OUTNOROUTES);
2145} 2151}
2146 2152
2147#ifdef CONFIG_IPV6_MULTIPLE_TABLES
2148
2149static int ip6_pkt_prohibit(struct sk_buff *skb) 2153static int ip6_pkt_prohibit(struct sk_buff *skb)
2150{ 2154{
2151 return ip6_pkt_drop(skb, ICMPV6_ADM_PROHIBITED, IPSTATS_MIB_INNOROUTES); 2155 return ip6_pkt_drop(skb, ICMPV6_ADM_PROHIBITED, IPSTATS_MIB_INNOROUTES);
@@ -2157,8 +2161,6 @@ static int ip6_pkt_prohibit_out(struct sk_buff *skb)
2157 return ip6_pkt_drop(skb, ICMPV6_ADM_PROHIBITED, IPSTATS_MIB_OUTNOROUTES); 2161 return ip6_pkt_drop(skb, ICMPV6_ADM_PROHIBITED, IPSTATS_MIB_OUTNOROUTES);
2158} 2162}
2159 2163
2160#endif
2161
2162/* 2164/*
2163 * Allocate a dst for local (unicast / anycast) address. 2165 * Allocate a dst for local (unicast / anycast) address.
2164 */ 2166 */
@@ -2168,12 +2170,10 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
2168 bool anycast) 2170 bool anycast)
2169{ 2171{
2170 struct net *net = dev_net(idev->dev); 2172 struct net *net = dev_net(idev->dev);
2171 struct rt6_info *rt = ip6_dst_alloc(net, net->loopback_dev, 0, NULL); 2173 struct rt6_info *rt = ip6_dst_alloc(net, net->loopback_dev,
2172 2174 DST_NOCOUNT, NULL);
2173 if (!rt) { 2175 if (!rt)
2174 net_warn_ratelimited("Maximum number of routes reached, consider increasing route/max_size\n");
2175 return ERR_PTR(-ENOMEM); 2176 return ERR_PTR(-ENOMEM);
2176 }
2177 2177
2178 in6_dev_hold(idev); 2178 in6_dev_hold(idev);
2179 2179
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 1b4a4a953675..366fbba3359a 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -478,14 +478,44 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
478 dev_put(dev); 478 dev_put(dev);
479} 479}
480 480
481/* Generate icmpv6 with type/code ICMPV6_DEST_UNREACH/ICMPV6_ADDR_UNREACH
482 * if sufficient data bytes are available
483 */
484static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
485{
486 const struct iphdr *iph = (const struct iphdr *) skb->data;
487 struct rt6_info *rt;
488 struct sk_buff *skb2;
489
490 if (!pskb_may_pull(skb, iph->ihl * 4 + sizeof(struct ipv6hdr) + 8))
491 return 1;
492
493 skb2 = skb_clone(skb, GFP_ATOMIC);
494
495 if (!skb2)
496 return 1;
497
498 skb_dst_drop(skb2);
499 skb_pull(skb2, iph->ihl * 4);
500 skb_reset_network_header(skb2);
501
502 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
503
504 if (rt && rt->dst.dev)
505 skb2->dev = rt->dst.dev;
506
507 icmpv6_send(skb2, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0);
508
509 if (rt)
510 ip6_rt_put(rt);
511
512 kfree_skb(skb2);
513
514 return 0;
515}
481 516
482static int ipip6_err(struct sk_buff *skb, u32 info) 517static int ipip6_err(struct sk_buff *skb, u32 info)
483{ 518{
484
485/* All the routers (except for Linux) return only
486 8 bytes of packet payload. It means, that precise relaying of
487 ICMP in the real Internet is absolutely infeasible.
488 */
489 const struct iphdr *iph = (const struct iphdr *)skb->data; 519 const struct iphdr *iph = (const struct iphdr *)skb->data;
490 const int type = icmp_hdr(skb)->type; 520 const int type = icmp_hdr(skb)->type;
491 const int code = icmp_hdr(skb)->code; 521 const int code = icmp_hdr(skb)->code;
@@ -500,7 +530,6 @@ static int ipip6_err(struct sk_buff *skb, u32 info)
500 case ICMP_DEST_UNREACH: 530 case ICMP_DEST_UNREACH:
501 switch (code) { 531 switch (code) {
502 case ICMP_SR_FAILED: 532 case ICMP_SR_FAILED:
503 case ICMP_PORT_UNREACH:
504 /* Impossible event. */ 533 /* Impossible event. */
505 return 0; 534 return 0;
506 default: 535 default:
@@ -545,6 +574,9 @@ static int ipip6_err(struct sk_buff *skb, u32 info)
545 goto out; 574 goto out;
546 575
547 err = 0; 576 err = 0;
577 if (!ipip6_err_gen_icmpv6_unreach(skb))
578 goto out;
579
548 if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED) 580 if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
549 goto out; 581 goto out;
550 582
@@ -919,7 +951,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
919 if (!new_skb) { 951 if (!new_skb) {
920 ip_rt_put(rt); 952 ip_rt_put(rt);
921 dev->stats.tx_dropped++; 953 dev->stats.tx_dropped++;
922 dev_kfree_skb(skb); 954 kfree_skb(skb);
923 return NETDEV_TX_OK; 955 return NETDEV_TX_OK;
924 } 956 }
925 if (skb->sk) 957 if (skb->sk)
@@ -945,7 +977,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
945tx_error_icmp: 977tx_error_icmp:
946 dst_link_failure(skb); 978 dst_link_failure(skb);
947tx_error: 979tx_error:
948 dev_kfree_skb(skb); 980 kfree_skb(skb);
949out: 981out:
950 dev->stats.tx_errors++; 982 dev->stats.tx_errors++;
951 return NETDEV_TX_OK; 983 return NETDEV_TX_OK;
@@ -985,7 +1017,7 @@ static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb,
985 1017
986tx_err: 1018tx_err:
987 dev->stats.tx_errors++; 1019 dev->stats.tx_errors++;
988 dev_kfree_skb(skb); 1020 kfree_skb(skb);
989 return NETDEV_TX_OK; 1021 return NETDEV_TX_OK;
990 1022
991} 1023}
diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c
index 535a3ad262f1..bb53a5e73c1a 100644
--- a/net/ipv6/syncookies.c
+++ b/net/ipv6/syncookies.c
@@ -247,7 +247,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
247 fl6.fl6_sport = inet_sk(sk)->inet_sport; 247 fl6.fl6_sport = inet_sk(sk)->inet_sport;
248 security_req_classify_flow(req, flowi6_to_flowi(&fl6)); 248 security_req_classify_flow(req, flowi6_to_flowi(&fl6));
249 249
250 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, false); 250 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
251 if (IS_ERR(dst)) 251 if (IS_ERR(dst))
252 goto out_free; 252 goto out_free;
253 } 253 }
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 0740f93a114a..ffd5fa8bdb15 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -156,7 +156,6 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
156 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); 156 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
157 if (flowlabel == NULL) 157 if (flowlabel == NULL)
158 return -EINVAL; 158 return -EINVAL;
159 usin->sin6_addr = flowlabel->dst;
160 fl6_sock_release(flowlabel); 159 fl6_sock_release(flowlabel);
161 } 160 }
162 } 161 }
@@ -165,12 +164,12 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
165 * connect() to INADDR_ANY means loopback (BSD'ism). 164 * connect() to INADDR_ANY means loopback (BSD'ism).
166 */ 165 */
167 166
168 if(ipv6_addr_any(&usin->sin6_addr)) 167 if (ipv6_addr_any(&usin->sin6_addr))
169 usin->sin6_addr.s6_addr[15] = 0x1; 168 usin->sin6_addr.s6_addr[15] = 0x1;
170 169
171 addr_type = ipv6_addr_type(&usin->sin6_addr); 170 addr_type = ipv6_addr_type(&usin->sin6_addr);
172 171
173 if(addr_type & IPV6_ADDR_MULTICAST) 172 if (addr_type & IPV6_ADDR_MULTICAST)
174 return -ENETUNREACH; 173 return -ENETUNREACH;
175 174
176 if (addr_type&IPV6_ADDR_LINKLOCAL) { 175 if (addr_type&IPV6_ADDR_LINKLOCAL) {
@@ -258,7 +257,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
258 257
259 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 258 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
260 259
261 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, true); 260 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
262 if (IS_ERR(dst)) { 261 if (IS_ERR(dst)) {
263 err = PTR_ERR(dst); 262 err = PTR_ERR(dst);
264 goto failure; 263 goto failure;
@@ -337,7 +336,7 @@ static void tcp_v6_mtu_reduced(struct sock *sk)
337static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 336static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
338 u8 type, u8 code, int offset, __be32 info) 337 u8 type, u8 code, int offset, __be32 info)
339{ 338{
340 const struct ipv6hdr *hdr = (const struct ipv6hdr*)skb->data; 339 const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data;
341 const struct tcphdr *th = (struct tcphdr *)(skb->data+offset); 340 const struct tcphdr *th = (struct tcphdr *)(skb->data+offset);
342 struct ipv6_pinfo *np; 341 struct ipv6_pinfo *np;
343 struct sock *sk; 342 struct sock *sk;
@@ -398,6 +397,9 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
398 if (sk->sk_state == TCP_LISTEN) 397 if (sk->sk_state == TCP_LISTEN)
399 goto out; 398 goto out;
400 399
400 if (!ip6_sk_accept_pmtu(sk))
401 goto out;
402
401 tp->mtu_info = ntohl(info); 403 tp->mtu_info = ntohl(info);
402 if (!sock_owned_by_user(sk)) 404 if (!sock_owned_by_user(sk))
403 tcp_v6_mtu_reduced(sk); 405 tcp_v6_mtu_reduced(sk);
@@ -467,7 +469,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct dst_entry *dst,
467{ 469{
468 struct inet_request_sock *ireq = inet_rsk(req); 470 struct inet_request_sock *ireq = inet_rsk(req);
469 struct ipv6_pinfo *np = inet6_sk(sk); 471 struct ipv6_pinfo *np = inet6_sk(sk);
470 struct sk_buff * skb; 472 struct sk_buff *skb;
471 int err = -ENOMEM; 473 int err = -ENOMEM;
472 474
473 /* First, grab a route. */ 475 /* First, grab a route. */
@@ -801,7 +803,7 @@ static void tcp_v6_send_response(struct sk_buff *skb, u32 seq, u32 ack, u32 win,
801 * Underlying function will use this to retrieve the network 803 * Underlying function will use this to retrieve the network
802 * namespace 804 * namespace
803 */ 805 */
804 dst = ip6_dst_lookup_flow(ctl_sk, &fl6, NULL, false); 806 dst = ip6_dst_lookup_flow(ctl_sk, &fl6, NULL);
805 if (!IS_ERR(dst)) { 807 if (!IS_ERR(dst)) {
806 skb_dst_set(buff, dst); 808 skb_dst_set(buff, dst);
807 ip6_xmit(ctl_sk, buff, &fl6, NULL, tclass); 809 ip6_xmit(ctl_sk, buff, &fl6, NULL, tclass);
@@ -910,7 +912,7 @@ static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
910} 912}
911 913
912 914
913static struct sock *tcp_v6_hnd_req(struct sock *sk,struct sk_buff *skb) 915static struct sock *tcp_v6_hnd_req(struct sock *sk, struct sk_buff *skb)
914{ 916{
915 struct request_sock *req, **prev; 917 struct request_sock *req, **prev;
916 const struct tcphdr *th = tcp_hdr(skb); 918 const struct tcphdr *th = tcp_hdr(skb);
@@ -1083,9 +1085,9 @@ drop:
1083 return 0; /* don't send reset */ 1085 return 0; /* don't send reset */
1084} 1086}
1085 1087
1086static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, 1088static struct sock *tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1087 struct request_sock *req, 1089 struct request_sock *req,
1088 struct dst_entry *dst) 1090 struct dst_entry *dst)
1089{ 1091{
1090 struct inet_request_sock *ireq; 1092 struct inet_request_sock *ireq;
1091 struct ipv6_pinfo *newnp, *np = inet6_sk(sk); 1093 struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
@@ -1135,7 +1137,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1135 newnp->opt = NULL; 1137 newnp->opt = NULL;
1136 newnp->mcast_oif = inet6_iif(skb); 1138 newnp->mcast_oif = inet6_iif(skb);
1137 newnp->mcast_hops = ipv6_hdr(skb)->hop_limit; 1139 newnp->mcast_hops = ipv6_hdr(skb)->hop_limit;
1138 newnp->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb)); 1140 newnp->rcv_flowinfo = ip6_flowinfo(ipv6_hdr(skb));
1139 1141
1140 /* 1142 /*
1141 * No need to charge this sock to the relevant IPv6 refcnt debug socks count 1143 * No need to charge this sock to the relevant IPv6 refcnt debug socks count
@@ -1215,7 +1217,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1215 newnp->opt = NULL; 1217 newnp->opt = NULL;
1216 newnp->mcast_oif = inet6_iif(skb); 1218 newnp->mcast_oif = inet6_iif(skb);
1217 newnp->mcast_hops = ipv6_hdr(skb)->hop_limit; 1219 newnp->mcast_hops = ipv6_hdr(skb)->hop_limit;
1218 newnp->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb)); 1220 newnp->rcv_flowinfo = ip6_flowinfo(ipv6_hdr(skb));
1219 1221
1220 /* Clone native IPv6 options from listening socket (if any) 1222 /* Clone native IPv6 options from listening socket (if any)
1221 1223
@@ -1380,7 +1382,7 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
1380 * otherwise we just shortcircuit this and continue with 1382 * otherwise we just shortcircuit this and continue with
1381 * the new socket.. 1383 * the new socket..
1382 */ 1384 */
1383 if(nsk != sk) { 1385 if (nsk != sk) {
1384 sock_rps_save_rxhash(nsk, skb); 1386 sock_rps_save_rxhash(nsk, skb);
1385 if (tcp_child_process(sk, nsk, skb)) 1387 if (tcp_child_process(sk, nsk, skb))
1386 goto reset; 1388 goto reset;
@@ -1425,8 +1427,8 @@ ipv6_pktoptions:
1425 np->mcast_oif = inet6_iif(opt_skb); 1427 np->mcast_oif = inet6_iif(opt_skb);
1426 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim) 1428 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
1427 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit; 1429 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
1428 if (np->rxopt.bits.rxtclass) 1430 if (np->rxopt.bits.rxflow || np->rxopt.bits.rxtclass)
1429 np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb)); 1431 np->rcv_flowinfo = ip6_flowinfo(ipv6_hdr(opt_skb));
1430 if (ipv6_opt_accepted(sk, opt_skb)) { 1432 if (ipv6_opt_accepted(sk, opt_skb)) {
1431 skb_set_owner_r(opt_skb, sk); 1433 skb_set_owner_r(opt_skb, sk);
1432 opt_skb = xchg(&np->pktoptions, opt_skb); 1434 opt_skb = xchg(&np->pktoptions, opt_skb);
@@ -1740,7 +1742,7 @@ static void get_openreq6(struct seq_file *seq,
1740 dest->s6_addr32[2], dest->s6_addr32[3], 1742 dest->s6_addr32[2], dest->s6_addr32[3],
1741 ntohs(inet_rsk(req)->ir_rmt_port), 1743 ntohs(inet_rsk(req)->ir_rmt_port),
1742 TCP_SYN_RECV, 1744 TCP_SYN_RECV,
1743 0,0, /* could print option size, but that is af dependent. */ 1745 0, 0, /* could print option size, but that is af dependent. */
1744 1, /* timers active (only the expire timer) */ 1746 1, /* timers active (only the expire timer) */
1745 jiffies_to_clock_t(ttd), 1747 jiffies_to_clock_t(ttd),
1746 req->num_timeout, 1748 req->num_timeout,
@@ -1799,7 +1801,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
1799 atomic_read(&sp->sk_refcnt), sp, 1801 atomic_read(&sp->sk_refcnt), sp,
1800 jiffies_to_clock_t(icsk->icsk_rto), 1802 jiffies_to_clock_t(icsk->icsk_rto),
1801 jiffies_to_clock_t(icsk->icsk_ack.ato), 1803 jiffies_to_clock_t(icsk->icsk_ack.ato),
1802 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong, 1804 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
1803 tp->snd_cwnd, 1805 tp->snd_cwnd,
1804 tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh 1806 tcp_in_initial_slowstart(tp) ? -1 : tp->snd_ssthresh
1805 ); 1807 );
diff --git a/net/ipv6/tcpv6_offload.c b/net/ipv6/tcpv6_offload.c
index c1097c798900..0d78132ff18a 100644
--- a/net/ipv6/tcpv6_offload.c
+++ b/net/ipv6/tcpv6_offload.c
@@ -37,44 +37,42 @@ static struct sk_buff **tcp6_gro_receive(struct sk_buff **head,
37{ 37{
38 const struct ipv6hdr *iph = skb_gro_network_header(skb); 38 const struct ipv6hdr *iph = skb_gro_network_header(skb);
39 __wsum wsum; 39 __wsum wsum;
40 __sum16 sum; 40
41 /* Don't bother verifying checksum if we're going to flush anyway. */
42 if (NAPI_GRO_CB(skb)->flush)
43 goto skip_csum;
44
45 wsum = skb->csum;
41 46
42 switch (skb->ip_summed) { 47 switch (skb->ip_summed) {
48 case CHECKSUM_NONE:
49 wsum = skb_checksum(skb, skb_gro_offset(skb), skb_gro_len(skb),
50 wsum);
51
52 /* fall through */
53
43 case CHECKSUM_COMPLETE: 54 case CHECKSUM_COMPLETE:
44 if (!tcp_v6_check(skb_gro_len(skb), &iph->saddr, &iph->daddr, 55 if (!tcp_v6_check(skb_gro_len(skb), &iph->saddr, &iph->daddr,
45 skb->csum)) { 56 wsum)) {
46 skb->ip_summed = CHECKSUM_UNNECESSARY; 57 skb->ip_summed = CHECKSUM_UNNECESSARY;
47 break; 58 break;
48 } 59 }
49flush: 60
50 NAPI_GRO_CB(skb)->flush = 1; 61 NAPI_GRO_CB(skb)->flush = 1;
51 return NULL; 62 return NULL;
52
53 case CHECKSUM_NONE:
54 wsum = ~csum_unfold(csum_ipv6_magic(&iph->saddr, &iph->daddr,
55 skb_gro_len(skb),
56 IPPROTO_TCP, 0));
57 sum = csum_fold(skb_checksum(skb,
58 skb_gro_offset(skb),
59 skb_gro_len(skb),
60 wsum));
61 if (sum)
62 goto flush;
63
64 skb->ip_summed = CHECKSUM_UNNECESSARY;
65 break;
66 } 63 }
67 64
65skip_csum:
68 return tcp_gro_receive(head, skb); 66 return tcp_gro_receive(head, skb);
69} 67}
70 68
71static int tcp6_gro_complete(struct sk_buff *skb) 69static int tcp6_gro_complete(struct sk_buff *skb, int thoff)
72{ 70{
73 const struct ipv6hdr *iph = ipv6_hdr(skb); 71 const struct ipv6hdr *iph = ipv6_hdr(skb);
74 struct tcphdr *th = tcp_hdr(skb); 72 struct tcphdr *th = tcp_hdr(skb);
75 73
76 th->check = ~tcp_v6_check(skb->len - skb_transport_offset(skb), 74 th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
77 &iph->saddr, &iph->daddr, 0); 75 &iph->daddr, 0);
78 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; 76 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
79 77
80 return tcp_gro_complete(skb); 78 return tcp_gro_complete(skb);
diff --git a/net/ipv6/tunnel6.c b/net/ipv6/tunnel6.c
index 4b0f50d9a962..2c4e4c5c7614 100644
--- a/net/ipv6/tunnel6.c
+++ b/net/ipv6/tunnel6.c
@@ -12,8 +12,7 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * 16 *
18 * Authors Mitsuru KANDA <mk@linux-ipv6.org> 17 * Authors Mitsuru KANDA <mk@linux-ipv6.org>
19 * YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> 18 * YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 81eb8cf8389b..fa9d988f4012 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -393,10 +393,10 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
393 bool slow; 393 bool slow;
394 394
395 if (flags & MSG_ERRQUEUE) 395 if (flags & MSG_ERRQUEUE)
396 return ipv6_recv_error(sk, msg, len); 396 return ipv6_recv_error(sk, msg, len, addr_len);
397 397
398 if (np->rxpmtu && np->rxopt.bits.rxpmtu) 398 if (np->rxpmtu && np->rxopt.bits.rxpmtu)
399 return ipv6_recv_rxpmtu(sk, msg, len); 399 return ipv6_recv_rxpmtu(sk, msg, len, addr_len);
400 400
401try_again: 401try_again:
402 skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0), 402 skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
@@ -538,8 +538,11 @@ void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
538 if (sk == NULL) 538 if (sk == NULL)
539 return; 539 return;
540 540
541 if (type == ICMPV6_PKT_TOOBIG) 541 if (type == ICMPV6_PKT_TOOBIG) {
542 if (!ip6_sk_accept_pmtu(sk))
543 goto out;
542 ip6_sk_update_pmtu(skb, sk, info); 544 ip6_sk_update_pmtu(skb, sk, info);
545 }
543 if (type == NDISC_REDIRECT) { 546 if (type == NDISC_REDIRECT) {
544 ip6_sk_redirect(skb, sk); 547 ip6_sk_redirect(skb, sk);
545 goto out; 548 goto out;
@@ -1140,7 +1143,6 @@ do_udp_sendmsg:
1140 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); 1143 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
1141 if (flowlabel == NULL) 1144 if (flowlabel == NULL)
1142 return -EINVAL; 1145 return -EINVAL;
1143 daddr = &flowlabel->dst;
1144 } 1146 }
1145 } 1147 }
1146 1148
@@ -1221,7 +1223,7 @@ do_udp_sendmsg:
1221 1223
1222 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 1224 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
1223 1225
1224 dst = ip6_sk_dst_lookup_flow(sk, &fl6, final_p, true); 1226 dst = ip6_sk_dst_lookup_flow(sk, &fl6, final_p);
1225 if (IS_ERR(dst)) { 1227 if (IS_ERR(dst)) {
1226 err = PTR_ERR(dst); 1228 err = PTR_ERR(dst);
1227 dst = NULL; 1229 dst = NULL;
diff --git a/net/ipv6/xfrm6_mode_ro.c b/net/ipv6/xfrm6_mode_ro.c
index 63d5d493098a..0e015906f9ca 100644
--- a/net/ipv6/xfrm6_mode_ro.c
+++ b/net/ipv6/xfrm6_mode_ro.c
@@ -15,8 +15,7 @@
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 19 */
21/* 20/*
22 * Authors: 21 * Authors:
diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
index de2bcfaaf759..1c66465a42dd 100644
--- a/net/ipv6/xfrm6_tunnel.c
+++ b/net/ipv6/xfrm6_tunnel.c
@@ -12,8 +12,7 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * 16 *
18 * Authors Mitsuru KANDA <mk@linux-ipv6.org> 17 * Authors Mitsuru KANDA <mk@linux-ipv6.org>
19 * YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> 18 * YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index de7db23049f1..73baf9b346b6 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -25,9 +25,7 @@
25 * GNU General Public License for more details. 25 * GNU General Public License for more details.
26 * 26 *
27 * You should have received a copy of the GNU General Public License 27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software 28 * along with this program; if not, see <http://www.gnu.org/licenses/>.
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * MA 02111-1307 USA
31 * 29 *
32 * Linux-IrDA now supports four different types of IrDA sockets: 30 * Linux-IrDA now supports four different types of IrDA sockets:
33 * 31 *
diff --git a/net/irda/discovery.c b/net/irda/discovery.c
index b0b56a339a83..6786e7f193d2 100644
--- a/net/irda/discovery.c
+++ b/net/irda/discovery.c
@@ -24,9 +24,7 @@
24 * GNU General Public License for more details. 24 * GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 * 28 *
31 ********************************************************************/ 29 ********************************************************************/
32 30
diff --git a/net/irda/ircomm/ircomm_core.c b/net/irda/ircomm/ircomm_core.c
index b797daac063c..4490a675b1bb 100644
--- a/net/irda/ircomm/ircomm_core.c
+++ b/net/irda/ircomm/ircomm_core.c
@@ -23,9 +23,7 @@
23 * GNU General Public License for more details. 23 * GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 * 27 *
30 ********************************************************************/ 28 ********************************************************************/
31 29
diff --git a/net/irda/ircomm/ircomm_event.c b/net/irda/ircomm/ircomm_event.c
index d78554fedbac..b172c6522328 100644
--- a/net/irda/ircomm/ircomm_event.c
+++ b/net/irda/ircomm/ircomm_event.c
@@ -22,9 +22,7 @@
22 * GNU General Public License for more details. 22 * GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software 25 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 * 26 *
29 ********************************************************************/ 27 ********************************************************************/
30 28
diff --git a/net/irda/ircomm/ircomm_lmp.c b/net/irda/ircomm/ircomm_lmp.c
index 3b8095c771d4..6536114adf37 100644
--- a/net/irda/ircomm/ircomm_lmp.c
+++ b/net/irda/ircomm/ircomm_lmp.c
@@ -24,9 +24,7 @@
24 * GNU General Public License for more details. 24 * GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 * 28 *
31 ********************************************************************/ 29 ********************************************************************/
32 30
diff --git a/net/irda/ircomm/ircomm_param.c b/net/irda/ircomm/ircomm_param.c
index 308939128359..f80b1a6a244b 100644
--- a/net/irda/ircomm/ircomm_param.c
+++ b/net/irda/ircomm/ircomm_param.c
@@ -22,9 +22,7 @@
22 * GNU General Public License for more details. 22 * GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software 25 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 * 26 *
29 ********************************************************************/ 27 ********************************************************************/
30 28
diff --git a/net/irda/ircomm/ircomm_ttp.c b/net/irda/ircomm/ircomm_ttp.c
index 6e6509f22f60..d362d711b79c 100644
--- a/net/irda/ircomm/ircomm_ttp.c
+++ b/net/irda/ircomm/ircomm_ttp.c
@@ -23,9 +23,7 @@
23 * GNU General Public License for more details. 23 * GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 * 27 *
30 ********************************************************************/ 28 ********************************************************************/
31 29
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index 41ac7938268b..2ba8b9705bb7 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -24,9 +24,7 @@
24 * GNU General Public License for more details. 24 * GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 * 28 *
31 ********************************************************************/ 29 ********************************************************************/
32 30
diff --git a/net/irda/ircomm/ircomm_tty_attach.c b/net/irda/ircomm/ircomm_tty_attach.c
index a2a508f5f268..2ee87bf387cc 100644
--- a/net/irda/ircomm/ircomm_tty_attach.c
+++ b/net/irda/ircomm/ircomm_tty_attach.c
@@ -23,9 +23,7 @@
23 * GNU General Public License for more details. 23 * GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 * 27 *
30 ********************************************************************/ 28 ********************************************************************/
31 29
diff --git a/net/irda/ircomm/ircomm_tty_ioctl.c b/net/irda/ircomm/ircomm_tty_ioctl.c
index b343f50dc8d7..ce943853c38d 100644
--- a/net/irda/ircomm/ircomm_tty_ioctl.c
+++ b/net/irda/ircomm/ircomm_tty_ioctl.c
@@ -22,9 +22,7 @@
22 * GNU General Public License for more details. 22 * GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software 25 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 * 26 *
29 ********************************************************************/ 27 ********************************************************************/
30 28
diff --git a/net/irda/irda_device.c b/net/irda/irda_device.c
index 14653b8d664d..365b895da84b 100644
--- a/net/irda/irda_device.c
+++ b/net/irda/irda_device.c
@@ -23,9 +23,7 @@
23 * GNU General Public License for more details. 23 * GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 * 27 *
30 ********************************************************************/ 28 ********************************************************************/
31 29
diff --git a/net/irda/irlap.c b/net/irda/irlap.c
index 005b424494a0..a778df55f5d6 100644
--- a/net/irda/irlap.c
+++ b/net/irda/irlap.c
@@ -23,9 +23,7 @@
23 * GNU General Public License for more details. 23 * GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 * 27 *
30 ********************************************************************/ 28 ********************************************************************/
31 29
diff --git a/net/irda/parameters.c b/net/irda/parameters.c
index 71cd38c1a67f..6d0869716bf6 100644
--- a/net/irda/parameters.c
+++ b/net/irda/parameters.c
@@ -22,9 +22,7 @@
22 * GNU General Public License for more details. 22 * GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software 25 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 * 26 *
29 ********************************************************************/ 27 ********************************************************************/
30 28
diff --git a/net/irda/qos.c b/net/irda/qos.c
index 798ffd9a705e..11a7cc0cbc28 100644
--- a/net/irda/qos.c
+++ b/net/irda/qos.c
@@ -24,9 +24,7 @@
24 * GNU General Public License for more details. 24 * GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 * 28 *
31 ********************************************************************/ 29 ********************************************************************/
32 30
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 545f047868ad..1a04c1329362 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -1340,6 +1340,12 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, const struct sadb_
1340 max_spi = range->sadb_spirange_max; 1340 max_spi = range->sadb_spirange_max;
1341 } 1341 }
1342 1342
1343 err = verify_spi_info(x->id.proto, min_spi, max_spi);
1344 if (err) {
1345 xfrm_state_put(x);
1346 return err;
1347 }
1348
1343 err = xfrm_alloc_spi(x, min_spi, max_spi); 1349 err = xfrm_alloc_spi(x, min_spi, max_spi);
1344 resp_skb = err ? ERR_PTR(err) : pfkey_xfrm_state2msg(x); 1350 resp_skb = err ? ERR_PTR(err) : pfkey_xfrm_state2msg(x);
1345 1351
@@ -1380,10 +1386,9 @@ static int pfkey_acquire(struct sock *sk, struct sk_buff *skb, const struct sadb
1380 return 0; 1386 return 0;
1381 1387
1382 spin_lock_bh(&x->lock); 1388 spin_lock_bh(&x->lock);
1383 if (x->km.state == XFRM_STATE_ACQ) { 1389 if (x->km.state == XFRM_STATE_ACQ)
1384 x->km.state = XFRM_STATE_ERROR; 1390 x->km.state = XFRM_STATE_ERROR;
1385 wake_up(&net->xfrm.km_waitq); 1391
1386 }
1387 spin_unlock_bh(&x->lock); 1392 spin_unlock_bh(&x->lock);
1388 xfrm_state_put(x); 1393 xfrm_state_put(x);
1389 return 0; 1394 return 0;
@@ -1785,7 +1790,9 @@ static int pfkey_dump_sa(struct pfkey_sock *pfk)
1785 1790
1786static void pfkey_dump_sa_done(struct pfkey_sock *pfk) 1791static void pfkey_dump_sa_done(struct pfkey_sock *pfk)
1787{ 1792{
1788 xfrm_state_walk_done(&pfk->dump.u.state); 1793 struct net *net = sock_net(&pfk->sk);
1794
1795 xfrm_state_walk_done(&pfk->dump.u.state, net);
1789} 1796}
1790 1797
1791static int pfkey_dump(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs) 1798static int pfkey_dump(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
@@ -1861,7 +1868,7 @@ static u32 gen_reqid(struct net *net)
1861 reqid = IPSEC_MANUAL_REQID_MAX+1; 1868 reqid = IPSEC_MANUAL_REQID_MAX+1;
1862 xfrm_policy_walk_init(&walk, XFRM_POLICY_TYPE_MAIN); 1869 xfrm_policy_walk_init(&walk, XFRM_POLICY_TYPE_MAIN);
1863 rc = xfrm_policy_walk(net, &walk, check_reqid, (void*)&reqid); 1870 rc = xfrm_policy_walk(net, &walk, check_reqid, (void*)&reqid);
1864 xfrm_policy_walk_done(&walk); 1871 xfrm_policy_walk_done(&walk, net);
1865 if (rc != -EEXIST) 1872 if (rc != -EEXIST)
1866 return reqid; 1873 return reqid;
1867 } while (reqid != start); 1874 } while (reqid != start);
@@ -2485,6 +2492,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
2485 struct xfrm_selector sel; 2492 struct xfrm_selector sel;
2486 struct xfrm_migrate m[XFRM_MAX_DEPTH]; 2493 struct xfrm_migrate m[XFRM_MAX_DEPTH];
2487 struct xfrm_kmaddress k; 2494 struct xfrm_kmaddress k;
2495 struct net *net = sock_net(sk);
2488 2496
2489 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1], 2497 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
2490 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) || 2498 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
@@ -2558,7 +2566,7 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
2558 } 2566 }
2559 2567
2560 return xfrm_migrate(&sel, dir, XFRM_POLICY_TYPE_MAIN, m, i, 2568 return xfrm_migrate(&sel, dir, XFRM_POLICY_TYPE_MAIN, m, i,
2561 kma ? &k : NULL); 2569 kma ? &k : NULL, net);
2562 2570
2563 out: 2571 out:
2564 return err; 2572 return err;
@@ -2659,7 +2667,9 @@ static int pfkey_dump_sp(struct pfkey_sock *pfk)
2659 2667
2660static void pfkey_dump_sp_done(struct pfkey_sock *pfk) 2668static void pfkey_dump_sp_done(struct pfkey_sock *pfk)
2661{ 2669{
2662 xfrm_policy_walk_done(&pfk->dump.u.policy); 2670 struct net *net = sock_net((struct sock *)pfk);
2671
2672 xfrm_policy_walk_done(&pfk->dump.u.policy, net);
2663} 2673}
2664 2674
2665static int pfkey_spddump(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs) 2675static int pfkey_spddump(struct sock *sk, struct sk_buff *skb, const struct sadb_msg *hdr, void * const *ext_hdrs)
@@ -3569,6 +3579,7 @@ static int pfkey_sendmsg(struct kiocb *kiocb,
3569 struct sk_buff *skb = NULL; 3579 struct sk_buff *skb = NULL;
3570 struct sadb_msg *hdr = NULL; 3580 struct sadb_msg *hdr = NULL;
3571 int err; 3581 int err;
3582 struct net *net = sock_net(sk);
3572 3583
3573 err = -EOPNOTSUPP; 3584 err = -EOPNOTSUPP;
3574 if (msg->msg_flags & MSG_OOB) 3585 if (msg->msg_flags & MSG_OOB)
@@ -3591,9 +3602,9 @@ static int pfkey_sendmsg(struct kiocb *kiocb,
3591 if (!hdr) 3602 if (!hdr)
3592 goto out; 3603 goto out;
3593 3604
3594 mutex_lock(&xfrm_cfg_mutex); 3605 mutex_lock(&net->xfrm.xfrm_cfg_mutex);
3595 err = pfkey_process(sk, skb, hdr); 3606 err = pfkey_process(sk, skb, hdr);
3596 mutex_unlock(&xfrm_cfg_mutex); 3607 mutex_unlock(&net->xfrm.xfrm_cfg_mutex);
3597 3608
3598out: 3609out:
3599 if (err && hdr && pfkey_error(hdr, err, sk) == 0) 3610 if (err && hdr && pfkey_error(hdr, err, sk) == 0)
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index cfd65304be60..29487a8f7fa0 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -528,7 +528,6 @@ static int l2tp_ip6_sendmsg(struct kiocb *iocb, struct sock *sk,
528 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); 528 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
529 if (flowlabel == NULL) 529 if (flowlabel == NULL)
530 return -EINVAL; 530 return -EINVAL;
531 daddr = &flowlabel->dst;
532 } 531 }
533 } 532 }
534 533
@@ -598,7 +597,7 @@ static int l2tp_ip6_sendmsg(struct kiocb *iocb, struct sock *sk,
598 597
599 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 598 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
600 599
601 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, true); 600 dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
602 if (IS_ERR(dst)) { 601 if (IS_ERR(dst)) {
603 err = PTR_ERR(dst); 602 err = PTR_ERR(dst);
604 goto out; 603 goto out;
@@ -665,7 +664,7 @@ static int l2tp_ip6_recvmsg(struct kiocb *iocb, struct sock *sk,
665 *addr_len = sizeof(*lsa); 664 *addr_len = sizeof(*lsa);
666 665
667 if (flags & MSG_ERRQUEUE) 666 if (flags & MSG_ERRQUEUE)
668 return ipv6_recv_error(sk, msg, len); 667 return ipv6_recv_error(sk, msg, len, addr_len);
669 668
670 skb = skb_recv_datagram(sk, flags, noblock, &err); 669 skb = skb_recv_datagram(sk, flags, noblock, &err);
671 if (!skb) 670 if (!skb)
diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
index cd8724177965..42dc2e45c921 100644
--- a/net/llc/llc_conn.c
+++ b/net/llc/llc_conn.c
@@ -753,7 +753,7 @@ void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk)
753 * 753 *
754 * Sends received pdus to the connection state machine. 754 * Sends received pdus to the connection state machine.
755 */ 755 */
756static int llc_conn_rcv(struct sock* sk, struct sk_buff *skb) 756static int llc_conn_rcv(struct sock *sk, struct sk_buff *skb)
757{ 757{
758 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 758 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
759 759
@@ -891,7 +891,7 @@ out_kfree_skb:
891 * 891 *
892 * Initializes a socket with default llc values. 892 * Initializes a socket with default llc values.
893 */ 893 */
894static void llc_sk_init(struct sock* sk) 894static void llc_sk_init(struct sock *sk)
895{ 895{
896 struct llc_sock *llc = llc_sk(sk); 896 struct llc_sock *llc = llc_sk(sk);
897 897
diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c
index 2bb0ddff8c0f..e251c0493ac0 100644
--- a/net/llc/llc_core.c
+++ b/net/llc/llc_core.c
@@ -48,7 +48,7 @@ static struct llc_sap *llc_sap_alloc(void)
48 48
49static struct llc_sap *__llc_sap_find(unsigned char sap_value) 49static struct llc_sap *__llc_sap_find(unsigned char sap_value)
50{ 50{
51 struct llc_sap* sap; 51 struct llc_sap *sap;
52 52
53 list_for_each_entry(sap, &llc_sap_list, node) 53 list_for_each_entry(sap, &llc_sap_list, node)
54 if (sap->laddr.lsap == sap_value) 54 if (sap->laddr.lsap == sap_value)
diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c
index e5850699098e..06033f6c845f 100644
--- a/net/llc/llc_sap.c
+++ b/net/llc/llc_sap.c
@@ -66,7 +66,7 @@ struct sk_buff *llc_alloc_frame(struct sock *sk, struct net_device *dev,
66 return skb; 66 return skb;
67} 67}
68 68
69void llc_save_primitive(struct sock *sk, struct sk_buff* skb, u8 prim) 69void llc_save_primitive(struct sock *sk, struct sk_buff *skb, u8 prim)
70{ 70{
71 struct sockaddr_llc *addr; 71 struct sockaddr_llc *addr;
72 72
@@ -114,7 +114,7 @@ void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb)
114 * failure. 114 * failure.
115 */ 115 */
116static struct llc_sap_state_trans *llc_find_sap_trans(struct llc_sap *sap, 116static struct llc_sap_state_trans *llc_find_sap_trans(struct llc_sap *sap,
117 struct sk_buff* skb) 117 struct sk_buff *skb)
118{ 118{
119 int i = 0; 119 int i = 0;
120 struct llc_sap_state_trans *rc = NULL; 120 struct llc_sap_state_trans *rc = NULL;
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 3d2168c3269e..d624ed49a7d9 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1476,8 +1476,8 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
1476 bool used = false; 1476 bool used = false;
1477 1477
1478 list_for_each_entry(sdata, &local->interfaces, list) { 1478 list_for_each_entry(sdata, &local->interfaces, list) {
1479 if (memcmp(local->hw.wiphy->addresses[i].addr, 1479 if (ether_addr_equal(local->hw.wiphy->addresses[i].addr,
1480 sdata->vif.addr, ETH_ALEN) == 0) { 1480 sdata->vif.addr)) {
1481 used = true; 1481 used = true;
1482 break; 1482 break;
1483 } 1483 }
@@ -1537,8 +1537,7 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
1537 val += inc; 1537 val += inc;
1538 1538
1539 list_for_each_entry(sdata, &local->interfaces, list) { 1539 list_for_each_entry(sdata, &local->interfaces, list) {
1540 if (memcmp(tmp_addr, sdata->vif.addr, 1540 if (ether_addr_equal(tmp_addr, sdata->vif.addr)) {
1541 ETH_ALEN) == 0) {
1542 used = true; 1541 used = true;
1543 break; 1542 break;
1544 } 1543 }
diff --git a/net/mac802154/wpan.c b/net/mac802154/wpan.c
index e24bcf977296..372d8a222b91 100644
--- a/net/mac802154/wpan.c
+++ b/net/mac802154/wpan.c
@@ -444,8 +444,8 @@ mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb)
444 case IEEE802154_FC_TYPE_DATA: 444 case IEEE802154_FC_TYPE_DATA:
445 return mac802154_process_data(sdata->dev, skb); 445 return mac802154_process_data(sdata->dev, skb);
446 default: 446 default:
447 pr_warning("ieee802154: bad frame received (type = %d)\n", 447 pr_warn("ieee802154: bad frame received (type = %d)\n",
448 mac_cb_type(skb)); 448 mac_cb_type(skb));
449 kfree_skb(skb); 449 kfree_skb(skb);
450 return NET_RX_DROP; 450 return NET_RX_DROP;
451 } 451 }
diff --git a/net/netfilter/ipset/ip_set_hash_netnet.c b/net/netfilter/ipset/ip_set_hash_netnet.c
index 2bc2dec20b00..6226803fc490 100644
--- a/net/netfilter/ipset/ip_set_hash_netnet.c
+++ b/net/netfilter/ipset/ip_set_hash_netnet.c
@@ -59,7 +59,7 @@ hash_netnet4_data_equal(const struct hash_netnet4_elem *ip1,
59 u32 *multi) 59 u32 *multi)
60{ 60{
61 return ip1->ipcmp == ip2->ipcmp && 61 return ip1->ipcmp == ip2->ipcmp &&
62 ip2->ccmp == ip2->ccmp; 62 ip1->ccmp == ip2->ccmp;
63} 63}
64 64
65static inline int 65static inline int
diff --git a/net/netfilter/ipvs/ip_vs_nfct.c b/net/netfilter/ipvs/ip_vs_nfct.c
index c8beafd401aa..d5f41514f577 100644
--- a/net/netfilter/ipvs/ip_vs_nfct.c
+++ b/net/netfilter/ipvs/ip_vs_nfct.c
@@ -19,8 +19,7 @@
19 * GNU General Public License for more details. 19 * GNU General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * 23 *
25 * 24 *
26 * Authors: 25 * Authors:
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index dcddc49c0e08..f93b7d06f4be 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -1717,6 +1717,19 @@ nf_tables_delrule_one(struct nft_ctx *ctx, struct nft_rule *rule)
1717 return -ENOENT; 1717 return -ENOENT;
1718} 1718}
1719 1719
1720static int nf_table_delrule_by_chain(struct nft_ctx *ctx)
1721{
1722 struct nft_rule *rule;
1723 int err;
1724
1725 list_for_each_entry(rule, &ctx->chain->rules, list) {
1726 err = nf_tables_delrule_one(ctx, rule);
1727 if (err < 0)
1728 return err;
1729 }
1730 return 0;
1731}
1732
1720static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb, 1733static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,
1721 const struct nlmsghdr *nlh, 1734 const struct nlmsghdr *nlh,
1722 const struct nlattr * const nla[]) 1735 const struct nlattr * const nla[])
@@ -1725,8 +1738,8 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,
1725 const struct nft_af_info *afi; 1738 const struct nft_af_info *afi;
1726 struct net *net = sock_net(skb->sk); 1739 struct net *net = sock_net(skb->sk);
1727 const struct nft_table *table; 1740 const struct nft_table *table;
1728 struct nft_chain *chain; 1741 struct nft_chain *chain = NULL;
1729 struct nft_rule *rule, *tmp; 1742 struct nft_rule *rule;
1730 int family = nfmsg->nfgen_family, err = 0; 1743 int family = nfmsg->nfgen_family, err = 0;
1731 struct nft_ctx ctx; 1744 struct nft_ctx ctx;
1732 1745
@@ -1738,22 +1751,29 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb,
1738 if (IS_ERR(table)) 1751 if (IS_ERR(table))
1739 return PTR_ERR(table); 1752 return PTR_ERR(table);
1740 1753
1741 chain = nf_tables_chain_lookup(table, nla[NFTA_RULE_CHAIN]); 1754 if (nla[NFTA_RULE_CHAIN]) {
1742 if (IS_ERR(chain)) 1755 chain = nf_tables_chain_lookup(table, nla[NFTA_RULE_CHAIN]);
1743 return PTR_ERR(chain); 1756 if (IS_ERR(chain))
1757 return PTR_ERR(chain);
1758 }
1744 1759
1745 nft_ctx_init(&ctx, skb, nlh, afi, table, chain, nla); 1760 nft_ctx_init(&ctx, skb, nlh, afi, table, chain, nla);
1746 1761
1747 if (nla[NFTA_RULE_HANDLE]) { 1762 if (chain) {
1748 rule = nf_tables_rule_lookup(chain, nla[NFTA_RULE_HANDLE]); 1763 if (nla[NFTA_RULE_HANDLE]) {
1749 if (IS_ERR(rule)) 1764 rule = nf_tables_rule_lookup(chain,
1750 return PTR_ERR(rule); 1765 nla[NFTA_RULE_HANDLE]);
1766 if (IS_ERR(rule))
1767 return PTR_ERR(rule);
1751 1768
1752 err = nf_tables_delrule_one(&ctx, rule);
1753 } else {
1754 /* Remove all rules in this chain */
1755 list_for_each_entry_safe(rule, tmp, &chain->rules, list) {
1756 err = nf_tables_delrule_one(&ctx, rule); 1769 err = nf_tables_delrule_one(&ctx, rule);
1770 } else {
1771 err = nf_table_delrule_by_chain(&ctx);
1772 }
1773 } else {
1774 list_for_each_entry(chain, &table->chains, list) {
1775 ctx.chain = chain;
1776 err = nf_table_delrule_by_chain(&ctx);
1757 if (err < 0) 1777 if (err < 0)
1758 break; 1778 break;
1759 } 1779 }
diff --git a/net/netfilter/xt_connmark.c b/net/netfilter/xt_connmark.c
index 7278145e6a68..69f78e96fdb4 100644
--- a/net/netfilter/xt_connmark.c
+++ b/net/netfilter/xt_connmark.c
@@ -17,8 +17,7 @@
17 * GNU General Public License for more details. 17 * GNU General Public License for more details.
18 * 18 *
19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software 20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 21 */
23 22
24#include <linux/module.h> 23#include <linux/module.h>
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 9ff035c71403..a3910fc2122b 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -325,21 +325,24 @@ static void htable_gc(unsigned long htlong)
325 add_timer(&ht->timer); 325 add_timer(&ht->timer);
326} 326}
327 327
328static void htable_destroy(struct xt_hashlimit_htable *hinfo) 328static void htable_remove_proc_entry(struct xt_hashlimit_htable *hinfo)
329{ 329{
330 struct hashlimit_net *hashlimit_net = hashlimit_pernet(hinfo->net); 330 struct hashlimit_net *hashlimit_net = hashlimit_pernet(hinfo->net);
331 struct proc_dir_entry *parent; 331 struct proc_dir_entry *parent;
332 332
333 del_timer_sync(&hinfo->timer);
334
335 if (hinfo->family == NFPROTO_IPV4) 333 if (hinfo->family == NFPROTO_IPV4)
336 parent = hashlimit_net->ipt_hashlimit; 334 parent = hashlimit_net->ipt_hashlimit;
337 else 335 else
338 parent = hashlimit_net->ip6t_hashlimit; 336 parent = hashlimit_net->ip6t_hashlimit;
339 337
340 if(parent != NULL) 338 if (parent != NULL)
341 remove_proc_entry(hinfo->name, parent); 339 remove_proc_entry(hinfo->name, parent);
340}
342 341
342static void htable_destroy(struct xt_hashlimit_htable *hinfo)
343{
344 del_timer_sync(&hinfo->timer);
345 htable_remove_proc_entry(hinfo);
343 htable_selective_cleanup(hinfo, select_all); 346 htable_selective_cleanup(hinfo, select_all);
344 kfree(hinfo->name); 347 kfree(hinfo->name);
345 vfree(hinfo); 348 vfree(hinfo);
@@ -883,21 +886,15 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
883static void __net_exit hashlimit_proc_net_exit(struct net *net) 886static void __net_exit hashlimit_proc_net_exit(struct net *net)
884{ 887{
885 struct xt_hashlimit_htable *hinfo; 888 struct xt_hashlimit_htable *hinfo;
886 struct proc_dir_entry *pde;
887 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net); 889 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
888 890
889 /* recent_net_exit() is called before recent_mt_destroy(). Make sure 891 /* hashlimit_net_exit() is called before hashlimit_mt_destroy().
890 * that the parent xt_recent proc entry is is empty before trying to 892 * Make sure that the parent ipt_hashlimit and ip6t_hashlimit proc
891 * remove it. 893 * entries is empty before trying to remove it.
892 */ 894 */
893 mutex_lock(&hashlimit_mutex); 895 mutex_lock(&hashlimit_mutex);
894 pde = hashlimit_net->ipt_hashlimit;
895 if (pde == NULL)
896 pde = hashlimit_net->ip6t_hashlimit;
897
898 hlist_for_each_entry(hinfo, &hashlimit_net->htables, node) 896 hlist_for_each_entry(hinfo, &hashlimit_net->htables, node)
899 remove_proc_entry(hinfo->name, pde); 897 htable_remove_proc_entry(hinfo);
900
901 hashlimit_net->ipt_hashlimit = NULL; 898 hashlimit_net->ipt_hashlimit = NULL;
902 hashlimit_net->ip6t_hashlimit = NULL; 899 hashlimit_net->ip6t_hashlimit = NULL;
903 mutex_unlock(&hashlimit_mutex); 900 mutex_unlock(&hashlimit_mutex);
diff --git a/net/netfilter/xt_osf.c b/net/netfilter/xt_osf.c
index 647d989a01e6..7174611bd672 100644
--- a/net/netfilter/xt_osf.c
+++ b/net/netfilter/xt_osf.c
@@ -13,8 +13,7 @@
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 17 */
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20#include <linux/module.h> 19#include <linux/module.h>
diff --git a/net/netlabel/netlabel_addrlist.c b/net/netlabel/netlabel_addrlist.c
index 6f1701322fb6..d0a3acfa5742 100644
--- a/net/netlabel/netlabel_addrlist.c
+++ b/net/netlabel/netlabel_addrlist.c
@@ -24,8 +24,7 @@
24 * the GNU General Public License for more details. 24 * the GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * 28 *
30 */ 29 */
31 30
diff --git a/net/netlabel/netlabel_addrlist.h b/net/netlabel/netlabel_addrlist.h
index a1287ce18130..d0f38bc9af6d 100644
--- a/net/netlabel/netlabel_addrlist.h
+++ b/net/netlabel/netlabel_addrlist.h
@@ -24,8 +24,7 @@
24 * the GNU General Public License for more details. 24 * the GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * 28 *
30 */ 29 */
31 30
diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c
index 69345cebe3a3..c2f2a53a4879 100644
--- a/net/netlabel/netlabel_cipso_v4.c
+++ b/net/netlabel/netlabel_cipso_v4.c
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlabel/netlabel_cipso_v4.h b/net/netlabel/netlabel_cipso_v4.h
index d24d774bfd62..875826808b00 100644
--- a/net/netlabel/netlabel_cipso_v4.h
+++ b/net/netlabel/netlabel_cipso_v4.h
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlabel/netlabel_domainhash.c b/net/netlabel/netlabel_domainhash.c
index 85d842e6e431..f0cb92f3ddaf 100644
--- a/net/netlabel/netlabel_domainhash.c
+++ b/net/netlabel/netlabel_domainhash.c
@@ -24,8 +24,7 @@
24 * the GNU General Public License for more details. 24 * the GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * 28 *
30 */ 29 */
31 30
diff --git a/net/netlabel/netlabel_domainhash.h b/net/netlabel/netlabel_domainhash.h
index b9be0eed8980..680caf4dff56 100644
--- a/net/netlabel/netlabel_domainhash.h
+++ b/net/netlabel/netlabel_domainhash.h
@@ -24,8 +24,7 @@
24 * the GNU General Public License for more details. 24 * the GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software 27 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * 28 *
30 */ 29 */
31 30
diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
index dce1bebf7aec..3045a964f39c 100644
--- a/net/netlabel/netlabel_kapi.c
+++ b/net/netlabel/netlabel_kapi.c
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c
index 8ef83ee97c6a..e66e977ef2fa 100644
--- a/net/netlabel/netlabel_mgmt.c
+++ b/net/netlabel/netlabel_mgmt.c
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlabel/netlabel_mgmt.h b/net/netlabel/netlabel_mgmt.h
index 5a9f31ce5799..8b6e1ab62b48 100644
--- a/net/netlabel/netlabel_mgmt.h
+++ b/net/netlabel/netlabel_mgmt.h
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c
index 43817d73ccf9..78a63c18779e 100644
--- a/net/netlabel/netlabel_unlabeled.c
+++ b/net/netlabel/netlabel_unlabeled.c
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlabel/netlabel_unlabeled.h b/net/netlabel/netlabel_unlabeled.h
index 700af49022a0..3a9e5dc9511b 100644
--- a/net/netlabel/netlabel_unlabeled.h
+++ b/net/netlabel/netlabel_unlabeled.h
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c
index 9650c4ad5f88..1e779bb7fa43 100644
--- a/net/netlabel/netlabel_user.c
+++ b/net/netlabel/netlabel_user.c
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlabel/netlabel_user.h b/net/netlabel/netlabel_user.h
index 81969785e279..4a397cde1a48 100644
--- a/net/netlabel/netlabel_user.h
+++ b/net/netlabel/netlabel_user.h
@@ -23,8 +23,7 @@
23 * the GNU General Public License for more details. 23 * the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software 26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 27 *
29 */ 28 */
30 29
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index bca50b95c182..3f75f1cd9eb3 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -204,6 +204,8 @@ static int __netlink_deliver_tap_skb(struct sk_buff *skb,
204 if (nskb) { 204 if (nskb) {
205 nskb->dev = dev; 205 nskb->dev = dev;
206 nskb->protocol = htons((u16) sk->sk_protocol); 206 nskb->protocol = htons((u16) sk->sk_protocol);
207 nskb->pkt_type = netlink_is_kernel(sk) ?
208 PACKET_KERNEL : PACKET_USER;
207 209
208 ret = dev_queue_xmit(nskb); 210 ret = dev_queue_xmit(nskb);
209 if (unlikely(ret > 0)) 211 if (unlikely(ret > 0))
@@ -239,6 +241,13 @@ static void netlink_deliver_tap(struct sk_buff *skb)
239 rcu_read_unlock(); 241 rcu_read_unlock();
240} 242}
241 243
244static void netlink_deliver_tap_kernel(struct sock *dst, struct sock *src,
245 struct sk_buff *skb)
246{
247 if (!(netlink_is_kernel(dst) && netlink_is_kernel(src)))
248 netlink_deliver_tap(skb);
249}
250
242static void netlink_overrun(struct sock *sk) 251static void netlink_overrun(struct sock *sk)
243{ 252{
244 struct netlink_sock *nlk = nlk_sk(sk); 253 struct netlink_sock *nlk = nlk_sk(sk);
@@ -1697,14 +1706,10 @@ static int netlink_unicast_kernel(struct sock *sk, struct sk_buff *skb,
1697 1706
1698 ret = -ECONNREFUSED; 1707 ret = -ECONNREFUSED;
1699 if (nlk->netlink_rcv != NULL) { 1708 if (nlk->netlink_rcv != NULL) {
1700 /* We could do a netlink_deliver_tap(skb) here as well
1701 * but since this is intended for the kernel only, we
1702 * should rather let it stay under the hood.
1703 */
1704
1705 ret = skb->len; 1709 ret = skb->len;
1706 netlink_skb_set_owner_r(skb, sk); 1710 netlink_skb_set_owner_r(skb, sk);
1707 NETLINK_CB(skb).sk = ssk; 1711 NETLINK_CB(skb).sk = ssk;
1712 netlink_deliver_tap_kernel(sk, ssk, skb);
1708 nlk->netlink_rcv(skb); 1713 nlk->netlink_rcv(skb);
1709 consume_skb(skb); 1714 consume_skb(skb);
1710 } else { 1715 } else {
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 4518a57aa5fe..713671ae45af 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -74,9 +74,12 @@ static struct list_head family_ht[GENL_FAM_TAB_SIZE];
74 * Bit 17 is marked as already used since the VFS quota code 74 * Bit 17 is marked as already used since the VFS quota code
75 * also abused this API and relied on family == group ID, we 75 * also abused this API and relied on family == group ID, we
76 * cater to that by giving it a static family and group ID. 76 * cater to that by giving it a static family and group ID.
77 * Bit 18 is marked as already used since the PMCRAID driver
78 * did the same thing as the VFS quota code (maybe copied?)
77 */ 79 */
78static unsigned long mc_group_start = 0x3 | BIT(GENL_ID_CTRL) | 80static unsigned long mc_group_start = 0x3 | BIT(GENL_ID_CTRL) |
79 BIT(GENL_ID_VFS_DQUOT); 81 BIT(GENL_ID_VFS_DQUOT) |
82 BIT(GENL_ID_PMCRAID);
80static unsigned long *mc_groups = &mc_group_start; 83static unsigned long *mc_groups = &mc_group_start;
81static unsigned long mc_groups_longs = 1; 84static unsigned long mc_groups_longs = 1;
82 85
@@ -139,6 +142,7 @@ static u16 genl_generate_id(void)
139 142
140 for (i = 0; i <= GENL_MAX_ID - GENL_MIN_ID; i++) { 143 for (i = 0; i <= GENL_MAX_ID - GENL_MIN_ID; i++) {
141 if (id_gen_idx != GENL_ID_VFS_DQUOT && 144 if (id_gen_idx != GENL_ID_VFS_DQUOT &&
145 id_gen_idx != GENL_ID_PMCRAID &&
142 !genl_family_find_byid(id_gen_idx)) 146 !genl_family_find_byid(id_gen_idx))
143 return id_gen_idx; 147 return id_gen_idx;
144 if (++id_gen_idx > GENL_MAX_ID) 148 if (++id_gen_idx > GENL_MAX_ID)
@@ -214,7 +218,7 @@ static int genl_validate_assign_mc_groups(struct genl_family *family)
214{ 218{
215 int first_id; 219 int first_id;
216 int n_groups = family->n_mcgrps; 220 int n_groups = family->n_mcgrps;
217 int err, i; 221 int err = 0, i;
218 bool groups_allocated = false; 222 bool groups_allocated = false;
219 223
220 if (!n_groups) 224 if (!n_groups)
@@ -236,9 +240,12 @@ static int genl_validate_assign_mc_groups(struct genl_family *family)
236 } else if (strcmp(family->name, "NET_DM") == 0) { 240 } else if (strcmp(family->name, "NET_DM") == 0) {
237 first_id = 1; 241 first_id = 1;
238 BUG_ON(n_groups != 1); 242 BUG_ON(n_groups != 1);
239 } else if (strcmp(family->name, "VFS_DQUOT") == 0) { 243 } else if (family->id == GENL_ID_VFS_DQUOT) {
240 first_id = GENL_ID_VFS_DQUOT; 244 first_id = GENL_ID_VFS_DQUOT;
241 BUG_ON(n_groups != 1); 245 BUG_ON(n_groups != 1);
246 } else if (family->id == GENL_ID_PMCRAID) {
247 first_id = GENL_ID_PMCRAID;
248 BUG_ON(n_groups != 1);
242 } else { 249 } else {
243 groups_allocated = true; 250 groups_allocated = true;
244 err = genl_allocate_reserve_groups(n_groups, &first_id); 251 err = genl_allocate_reserve_groups(n_groups, &first_id);
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 65cfaa816075..716b7eebfe70 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -165,7 +165,7 @@ static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,
165 } 165 }
166 166
167 csum_replace4(&nh->check, *addr, new_addr); 167 csum_replace4(&nh->check, *addr, new_addr);
168 skb->rxhash = 0; 168 skb_clear_hash(skb);
169 *addr = new_addr; 169 *addr = new_addr;
170} 170}
171 171
@@ -199,7 +199,7 @@ static void set_ipv6_addr(struct sk_buff *skb, u8 l4_proto,
199 if (recalculate_csum) 199 if (recalculate_csum)
200 update_ipv6_checksum(skb, l4_proto, addr, new_addr); 200 update_ipv6_checksum(skb, l4_proto, addr, new_addr);
201 201
202 skb->rxhash = 0; 202 skb_clear_hash(skb);
203 memcpy(addr, new_addr, sizeof(__be32[4])); 203 memcpy(addr, new_addr, sizeof(__be32[4]));
204} 204}
205 205
@@ -296,7 +296,7 @@ static void set_tp_port(struct sk_buff *skb, __be16 *port,
296{ 296{
297 inet_proto_csum_replace2(check, skb, *port, new_port, 0); 297 inet_proto_csum_replace2(check, skb, *port, new_port, 0);
298 *port = new_port; 298 *port = new_port;
299 skb->rxhash = 0; 299 skb_clear_hash(skb);
300} 300}
301 301
302static void set_udp_port(struct sk_buff *skb, __be16 *port, __be16 new_port) 302static void set_udp_port(struct sk_buff *skb, __be16 *port, __be16 new_port)
@@ -310,7 +310,7 @@ static void set_udp_port(struct sk_buff *skb, __be16 *port, __be16 new_port)
310 uh->check = CSUM_MANGLED_0; 310 uh->check = CSUM_MANGLED_0;
311 } else { 311 } else {
312 *port = new_port; 312 *port = new_port;
313 skb->rxhash = 0; 313 skb_clear_hash(skb);
314 } 314 }
315} 315}
316 316
@@ -381,7 +381,7 @@ static int set_sctp(struct sk_buff *skb,
381 /* Carry any checksum errors through. */ 381 /* Carry any checksum errors through. */
382 sh->checksum = old_csum ^ old_correct_csum ^ new_csum; 382 sh->checksum = old_csum ^ old_correct_csum ^ new_csum;
383 383
384 skb->rxhash = 0; 384 skb_clear_hash(skb);
385 } 385 }
386 386
387 return 0; 387 return 0;
diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
index e42542706087..0e720c316070 100644
--- a/net/openvswitch/flow_table.c
+++ b/net/openvswitch/flow_table.c
@@ -25,7 +25,7 @@
25#include <linux/if_vlan.h> 25#include <linux/if_vlan.h>
26#include <net/llc_pdu.h> 26#include <net/llc_pdu.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/jhash.h> 28#include <linux/hash.h>
29#include <linux/jiffies.h> 29#include <linux/jiffies.h>
30#include <linux/llc.h> 30#include <linux/llc.h>
31#include <linux/module.h> 31#include <linux/module.h>
@@ -362,7 +362,7 @@ static u32 flow_hash(const struct sw_flow_key *key, int key_start,
362 /* Make sure number of hash bytes are multiple of u32. */ 362 /* Make sure number of hash bytes are multiple of u32. */
363 BUILD_BUG_ON(sizeof(long) % sizeof(u32)); 363 BUILD_BUG_ON(sizeof(long) % sizeof(u32));
364 364
365 return jhash2(hash_key, hash_u32s, 0); 365 return arch_fast_hash2(hash_key, hash_u32s, 0);
366} 366}
367 367
368static int flow_key_start(const struct sw_flow_key *key) 368static int flow_key_start(const struct sw_flow_key *key)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index ac27c86ef6d1..279467b74eb7 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -237,6 +237,82 @@ struct packet_skb_cb {
237static void __fanout_unlink(struct sock *sk, struct packet_sock *po); 237static void __fanout_unlink(struct sock *sk, struct packet_sock *po);
238static void __fanout_link(struct sock *sk, struct packet_sock *po); 238static void __fanout_link(struct sock *sk, struct packet_sock *po);
239 239
240static int packet_direct_xmit(struct sk_buff *skb)
241{
242 struct net_device *dev = skb->dev;
243 const struct net_device_ops *ops = dev->netdev_ops;
244 netdev_features_t features;
245 struct netdev_queue *txq;
246 u16 queue_map;
247 int ret;
248
249 if (unlikely(!netif_running(dev) ||
250 !netif_carrier_ok(dev))) {
251 kfree_skb(skb);
252 return NET_XMIT_DROP;
253 }
254
255 features = netif_skb_features(skb);
256 if (skb_needs_linearize(skb, features) &&
257 __skb_linearize(skb)) {
258 kfree_skb(skb);
259 return NET_XMIT_DROP;
260 }
261
262 queue_map = skb_get_queue_mapping(skb);
263 txq = netdev_get_tx_queue(dev, queue_map);
264
265 __netif_tx_lock_bh(txq);
266 if (unlikely(netif_xmit_frozen_or_stopped(txq))) {
267 ret = NETDEV_TX_BUSY;
268 kfree_skb(skb);
269 goto out;
270 }
271
272 ret = ops->ndo_start_xmit(skb, dev);
273 if (likely(dev_xmit_complete(ret)))
274 txq_trans_update(txq);
275 else
276 kfree_skb(skb);
277out:
278 __netif_tx_unlock_bh(txq);
279 return ret;
280}
281
282static struct net_device *packet_cached_dev_get(struct packet_sock *po)
283{
284 struct net_device *dev;
285
286 rcu_read_lock();
287 dev = rcu_dereference(po->cached_dev);
288 if (likely(dev))
289 dev_hold(dev);
290 rcu_read_unlock();
291
292 return dev;
293}
294
295static void packet_cached_dev_assign(struct packet_sock *po,
296 struct net_device *dev)
297{
298 rcu_assign_pointer(po->cached_dev, dev);
299}
300
301static void packet_cached_dev_reset(struct packet_sock *po)
302{
303 RCU_INIT_POINTER(po->cached_dev, NULL);
304}
305
306static bool packet_use_direct_xmit(const struct packet_sock *po)
307{
308 return po->xmit == packet_direct_xmit;
309}
310
311static u16 packet_pick_tx_queue(struct net_device *dev)
312{
313 return (u16) raw_smp_processor_id() % dev->real_num_tx_queues;
314}
315
240/* register_prot_hook must be invoked with the po->bind_lock held, 316/* register_prot_hook must be invoked with the po->bind_lock held,
241 * or from a context in which asynchronous accesses to the packet 317 * or from a context in which asynchronous accesses to the packet
242 * socket is not possible (packet_create()). 318 * socket is not possible (packet_create()).
@@ -246,12 +322,10 @@ static void register_prot_hook(struct sock *sk)
246 struct packet_sock *po = pkt_sk(sk); 322 struct packet_sock *po = pkt_sk(sk);
247 323
248 if (!po->running) { 324 if (!po->running) {
249 if (po->fanout) { 325 if (po->fanout)
250 __fanout_link(sk, po); 326 __fanout_link(sk, po);
251 } else { 327 else
252 dev_add_pack(&po->prot_hook); 328 dev_add_pack(&po->prot_hook);
253 rcu_assign_pointer(po->cached_dev, po->prot_hook.dev);
254 }
255 329
256 sock_hold(sk); 330 sock_hold(sk);
257 po->running = 1; 331 po->running = 1;
@@ -270,12 +344,11 @@ static void __unregister_prot_hook(struct sock *sk, bool sync)
270 struct packet_sock *po = pkt_sk(sk); 344 struct packet_sock *po = pkt_sk(sk);
271 345
272 po->running = 0; 346 po->running = 0;
273 if (po->fanout) { 347
348 if (po->fanout)
274 __fanout_unlink(sk, po); 349 __fanout_unlink(sk, po);
275 } else { 350 else
276 __dev_remove_pack(&po->prot_hook); 351 __dev_remove_pack(&po->prot_hook);
277 RCU_INIT_POINTER(po->cached_dev, NULL);
278 }
279 352
280 __sock_put(sk); 353 __sock_put(sk);
281 354
@@ -437,11 +510,12 @@ static void prb_shutdown_retire_blk_timer(struct packet_sock *po,
437{ 510{
438 struct tpacket_kbdq_core *pkc; 511 struct tpacket_kbdq_core *pkc;
439 512
440 pkc = tx_ring ? &po->tx_ring.prb_bdqc : &po->rx_ring.prb_bdqc; 513 pkc = tx_ring ? GET_PBDQC_FROM_RB(&po->tx_ring) :
514 GET_PBDQC_FROM_RB(&po->rx_ring);
441 515
442 spin_lock(&rb_queue->lock); 516 spin_lock_bh(&rb_queue->lock);
443 pkc->delete_blk_timer = 1; 517 pkc->delete_blk_timer = 1;
444 spin_unlock(&rb_queue->lock); 518 spin_unlock_bh(&rb_queue->lock);
445 519
446 prb_del_retire_blk_timer(pkc); 520 prb_del_retire_blk_timer(pkc);
447} 521}
@@ -463,7 +537,8 @@ static void prb_setup_retire_blk_timer(struct packet_sock *po, int tx_ring)
463 if (tx_ring) 537 if (tx_ring)
464 BUG(); 538 BUG();
465 539
466 pkc = tx_ring ? &po->tx_ring.prb_bdqc : &po->rx_ring.prb_bdqc; 540 pkc = tx_ring ? GET_PBDQC_FROM_RB(&po->tx_ring) :
541 GET_PBDQC_FROM_RB(&po->rx_ring);
467 prb_init_blk_timer(po, pkc, prb_retire_rx_blk_timer_expired); 542 prb_init_blk_timer(po, pkc, prb_retire_rx_blk_timer_expired);
468} 543}
469 544
@@ -521,7 +596,7 @@ static void init_prb_bdqc(struct packet_sock *po,
521 struct pgv *pg_vec, 596 struct pgv *pg_vec,
522 union tpacket_req_u *req_u, int tx_ring) 597 union tpacket_req_u *req_u, int tx_ring)
523{ 598{
524 struct tpacket_kbdq_core *p1 = &rb->prb_bdqc; 599 struct tpacket_kbdq_core *p1 = GET_PBDQC_FROM_RB(rb);
525 struct tpacket_block_desc *pbd; 600 struct tpacket_block_desc *pbd;
526 601
527 memset(p1, 0x0, sizeof(*p1)); 602 memset(p1, 0x0, sizeof(*p1));
@@ -585,7 +660,7 @@ static void _prb_refresh_rx_retire_blk_timer(struct tpacket_kbdq_core *pkc)
585static void prb_retire_rx_blk_timer_expired(unsigned long data) 660static void prb_retire_rx_blk_timer_expired(unsigned long data)
586{ 661{
587 struct packet_sock *po = (struct packet_sock *)data; 662 struct packet_sock *po = (struct packet_sock *)data;
588 struct tpacket_kbdq_core *pkc = &po->rx_ring.prb_bdqc; 663 struct tpacket_kbdq_core *pkc = GET_PBDQC_FROM_RB(&po->rx_ring);
589 unsigned int frozen; 664 unsigned int frozen;
590 struct tpacket_block_desc *pbd; 665 struct tpacket_block_desc *pbd;
591 666
@@ -888,7 +963,7 @@ static void prb_clear_blk_fill_status(struct packet_ring_buffer *rb)
888static void prb_fill_rxhash(struct tpacket_kbdq_core *pkc, 963static void prb_fill_rxhash(struct tpacket_kbdq_core *pkc,
889 struct tpacket3_hdr *ppd) 964 struct tpacket3_hdr *ppd)
890{ 965{
891 ppd->hv1.tp_rxhash = skb_get_rxhash(pkc->skb); 966 ppd->hv1.tp_rxhash = skb_get_hash(pkc->skb);
892} 967}
893 968
894static void prb_clear_rxhash(struct tpacket_kbdq_core *pkc, 969static void prb_clear_rxhash(struct tpacket_kbdq_core *pkc,
@@ -902,9 +977,11 @@ static void prb_fill_vlan_info(struct tpacket_kbdq_core *pkc,
902{ 977{
903 if (vlan_tx_tag_present(pkc->skb)) { 978 if (vlan_tx_tag_present(pkc->skb)) {
904 ppd->hv1.tp_vlan_tci = vlan_tx_tag_get(pkc->skb); 979 ppd->hv1.tp_vlan_tci = vlan_tx_tag_get(pkc->skb);
905 ppd->tp_status = TP_STATUS_VLAN_VALID; 980 ppd->hv1.tp_vlan_tpid = ntohs(pkc->skb->vlan_proto);
981 ppd->tp_status = TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
906 } else { 982 } else {
907 ppd->hv1.tp_vlan_tci = 0; 983 ppd->hv1.tp_vlan_tci = 0;
984 ppd->hv1.tp_vlan_tpid = 0;
908 ppd->tp_status = TP_STATUS_AVAILABLE; 985 ppd->tp_status = TP_STATUS_AVAILABLE;
909 } 986 }
910} 987}
@@ -912,6 +989,7 @@ static void prb_fill_vlan_info(struct tpacket_kbdq_core *pkc,
912static void prb_run_all_ft_ops(struct tpacket_kbdq_core *pkc, 989static void prb_run_all_ft_ops(struct tpacket_kbdq_core *pkc,
913 struct tpacket3_hdr *ppd) 990 struct tpacket3_hdr *ppd)
914{ 991{
992 ppd->hv1.tp_padding = 0;
915 prb_fill_vlan_info(pkc, ppd); 993 prb_fill_vlan_info(pkc, ppd);
916 994
917 if (pkc->feature_req_word & TP_FT_REQ_FILL_RXHASH) 995 if (pkc->feature_req_word & TP_FT_REQ_FILL_RXHASH)
@@ -1220,7 +1298,7 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,
1220 if (!skb) 1298 if (!skb)
1221 return 0; 1299 return 0;
1222 } 1300 }
1223 skb_get_rxhash(skb); 1301 skb_get_hash(skb);
1224 idx = fanout_demux_hash(f, skb, num); 1302 idx = fanout_demux_hash(f, skb, num);
1225 break; 1303 break;
1226 case PACKET_FANOUT_LB: 1304 case PACKET_FANOUT_LB:
@@ -1278,9 +1356,9 @@ static void __fanout_unlink(struct sock *sk, struct packet_sock *po)
1278 spin_unlock(&f->lock); 1356 spin_unlock(&f->lock);
1279} 1357}
1280 1358
1281static bool match_fanout_group(struct packet_type *ptype, struct sock * sk) 1359static bool match_fanout_group(struct packet_type *ptype, struct sock *sk)
1282{ 1360{
1283 if (ptype->af_packet_priv == (void*)((struct packet_sock *)sk)->fanout) 1361 if (ptype->af_packet_priv == (void *)((struct packet_sock *)sk)->fanout)
1284 return true; 1362 return true;
1285 1363
1286 return false; 1364 return false;
@@ -1737,6 +1815,13 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
1737 struct timespec ts; 1815 struct timespec ts;
1738 __u32 ts_status; 1816 __u32 ts_status;
1739 1817
1818 /* struct tpacket{2,3}_hdr is aligned to a multiple of TPACKET_ALIGNMENT.
1819 * We may add members to them until current aligned size without forcing
1820 * userspace to call getsockopt(..., PACKET_HDRLEN, ...).
1821 */
1822 BUILD_BUG_ON(TPACKET_ALIGN(sizeof(*h.h2)) != 32);
1823 BUILD_BUG_ON(TPACKET_ALIGN(sizeof(*h.h3)) != 48);
1824
1740 if (skb->pkt_type == PACKET_LOOPBACK) 1825 if (skb->pkt_type == PACKET_LOOPBACK)
1741 goto drop; 1826 goto drop;
1742 1827
@@ -1843,11 +1928,13 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
1843 h.h2->tp_nsec = ts.tv_nsec; 1928 h.h2->tp_nsec = ts.tv_nsec;
1844 if (vlan_tx_tag_present(skb)) { 1929 if (vlan_tx_tag_present(skb)) {
1845 h.h2->tp_vlan_tci = vlan_tx_tag_get(skb); 1930 h.h2->tp_vlan_tci = vlan_tx_tag_get(skb);
1846 status |= TP_STATUS_VLAN_VALID; 1931 h.h2->tp_vlan_tpid = ntohs(skb->vlan_proto);
1932 status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
1847 } else { 1933 } else {
1848 h.h2->tp_vlan_tci = 0; 1934 h.h2->tp_vlan_tci = 0;
1935 h.h2->tp_vlan_tpid = 0;
1849 } 1936 }
1850 h.h2->tp_padding = 0; 1937 memset(h.h2->tp_padding, 0, sizeof(h.h2->tp_padding));
1851 hdrlen = sizeof(*h.h2); 1938 hdrlen = sizeof(*h.h2);
1852 break; 1939 break;
1853 case TPACKET_V3: 1940 case TPACKET_V3:
@@ -1861,6 +1948,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
1861 h.h3->tp_net = netoff; 1948 h.h3->tp_net = netoff;
1862 h.h3->tp_sec = ts.tv_sec; 1949 h.h3->tp_sec = ts.tv_sec;
1863 h.h3->tp_nsec = ts.tv_nsec; 1950 h.h3->tp_nsec = ts.tv_nsec;
1951 memset(h.h3->tp_padding, 0, sizeof(h.h3->tp_padding));
1864 hdrlen = sizeof(*h.h3); 1952 hdrlen = sizeof(*h.h3);
1865 break; 1953 break;
1866 default: 1954 default:
@@ -1971,9 +2059,10 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
1971 2059
1972 skb_reserve(skb, hlen); 2060 skb_reserve(skb, hlen);
1973 skb_reset_network_header(skb); 2061 skb_reset_network_header(skb);
1974 skb_probe_transport_header(skb, 0);
1975 2062
1976 if (po->tp_tx_has_off) { 2063 if (!packet_use_direct_xmit(po))
2064 skb_probe_transport_header(skb, 0);
2065 if (unlikely(po->tp_tx_has_off)) {
1977 int off_min, off_max, off; 2066 int off_min, off_max, off;
1978 off_min = po->tp_hdrlen - sizeof(struct sockaddr_ll); 2067 off_min = po->tp_hdrlen - sizeof(struct sockaddr_ll);
1979 off_max = po->tx_ring.frame_size - tp_len; 2068 off_max = po->tx_ring.frame_size - tp_len;
@@ -2059,19 +2148,6 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
2059 return tp_len; 2148 return tp_len;
2060} 2149}
2061 2150
2062static struct net_device *packet_cached_dev_get(struct packet_sock *po)
2063{
2064 struct net_device *dev;
2065
2066 rcu_read_lock();
2067 dev = rcu_dereference(po->cached_dev);
2068 if (dev)
2069 dev_hold(dev);
2070 rcu_read_unlock();
2071
2072 return dev;
2073}
2074
2075static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) 2151static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2076{ 2152{
2077 struct sk_buff *skb; 2153 struct sk_buff *skb;
@@ -2088,7 +2164,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2088 2164
2089 mutex_lock(&po->pg_vec_lock); 2165 mutex_lock(&po->pg_vec_lock);
2090 2166
2091 if (saddr == NULL) { 2167 if (likely(saddr == NULL)) {
2092 dev = packet_cached_dev_get(po); 2168 dev = packet_cached_dev_get(po);
2093 proto = po->num; 2169 proto = po->num;
2094 addr = NULL; 2170 addr = NULL;
@@ -2156,12 +2232,13 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2156 } 2232 }
2157 } 2233 }
2158 2234
2235 skb_set_queue_mapping(skb, packet_pick_tx_queue(dev));
2159 skb->destructor = tpacket_destruct_skb; 2236 skb->destructor = tpacket_destruct_skb;
2160 __packet_set_status(po, ph, TP_STATUS_SENDING); 2237 __packet_set_status(po, ph, TP_STATUS_SENDING);
2161 atomic_inc(&po->tx_ring.pending); 2238 atomic_inc(&po->tx_ring.pending);
2162 2239
2163 status = TP_STATUS_SEND_REQUEST; 2240 status = TP_STATUS_SEND_REQUEST;
2164 err = dev_queue_xmit(skb); 2241 err = po->xmit(skb);
2165 if (unlikely(err > 0)) { 2242 if (unlikely(err > 0)) {
2166 err = net_xmit_errno(err); 2243 err = net_xmit_errno(err);
2167 if (err && __packet_get_status(po, ph) == 2244 if (err && __packet_get_status(po, ph) ==
@@ -2220,8 +2297,7 @@ static struct sk_buff *packet_alloc_skb(struct sock *sk, size_t prepad,
2220 return skb; 2297 return skb;
2221} 2298}
2222 2299
2223static int packet_snd(struct socket *sock, 2300static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2224 struct msghdr *msg, size_t len)
2225{ 2301{
2226 struct sock *sk = sock->sk; 2302 struct sock *sk = sock->sk;
2227 struct sockaddr_ll *saddr = (struct sockaddr_ll *)msg->msg_name; 2303 struct sockaddr_ll *saddr = (struct sockaddr_ll *)msg->msg_name;
@@ -2242,7 +2318,7 @@ static int packet_snd(struct socket *sock,
2242 * Get and verify the address. 2318 * Get and verify the address.
2243 */ 2319 */
2244 2320
2245 if (saddr == NULL) { 2321 if (likely(saddr == NULL)) {
2246 dev = packet_cached_dev_get(po); 2322 dev = packet_cached_dev_get(po);
2247 proto = po->num; 2323 proto = po->num;
2248 addr = NULL; 2324 addr = NULL;
@@ -2366,6 +2442,7 @@ static int packet_snd(struct socket *sock,
2366 skb->dev = dev; 2442 skb->dev = dev;
2367 skb->priority = sk->sk_priority; 2443 skb->priority = sk->sk_priority;
2368 skb->mark = sk->sk_mark; 2444 skb->mark = sk->sk_mark;
2445 skb_set_queue_mapping(skb, packet_pick_tx_queue(dev));
2369 2446
2370 if (po->has_vnet_hdr) { 2447 if (po->has_vnet_hdr) {
2371 if (vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { 2448 if (vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
@@ -2386,16 +2463,12 @@ static int packet_snd(struct socket *sock,
2386 len += vnet_hdr_len; 2463 len += vnet_hdr_len;
2387 } 2464 }
2388 2465
2389 skb_probe_transport_header(skb, reserve); 2466 if (!packet_use_direct_xmit(po))
2390 2467 skb_probe_transport_header(skb, reserve);
2391 if (unlikely(extra_len == 4)) 2468 if (unlikely(extra_len == 4))
2392 skb->no_fcs = 1; 2469 skb->no_fcs = 1;
2393 2470
2394 /* 2471 err = po->xmit(skb);
2395 * Now send it
2396 */
2397
2398 err = dev_queue_xmit(skb);
2399 if (err > 0 && (err = net_xmit_errno(err)) != 0) 2472 if (err > 0 && (err = net_xmit_errno(err)) != 0)
2400 goto out_unlock; 2473 goto out_unlock;
2401 2474
@@ -2417,6 +2490,7 @@ static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
2417{ 2490{
2418 struct sock *sk = sock->sk; 2491 struct sock *sk = sock->sk;
2419 struct packet_sock *po = pkt_sk(sk); 2492 struct packet_sock *po = pkt_sk(sk);
2493
2420 if (po->tx_ring.pg_vec) 2494 if (po->tx_ring.pg_vec)
2421 return tpacket_snd(po, msg); 2495 return tpacket_snd(po, msg);
2422 else 2496 else
@@ -2451,6 +2525,8 @@ static int packet_release(struct socket *sock)
2451 2525
2452 spin_lock(&po->bind_lock); 2526 spin_lock(&po->bind_lock);
2453 unregister_prot_hook(sk, false); 2527 unregister_prot_hook(sk, false);
2528 packet_cached_dev_reset(po);
2529
2454 if (po->prot_hook.dev) { 2530 if (po->prot_hook.dev) {
2455 dev_put(po->prot_hook.dev); 2531 dev_put(po->prot_hook.dev);
2456 po->prot_hook.dev = NULL; 2532 po->prot_hook.dev = NULL;
@@ -2506,14 +2582,17 @@ static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protoc
2506 2582
2507 spin_lock(&po->bind_lock); 2583 spin_lock(&po->bind_lock);
2508 unregister_prot_hook(sk, true); 2584 unregister_prot_hook(sk, true);
2585
2509 po->num = protocol; 2586 po->num = protocol;
2510 po->prot_hook.type = protocol; 2587 po->prot_hook.type = protocol;
2511 if (po->prot_hook.dev) 2588 if (po->prot_hook.dev)
2512 dev_put(po->prot_hook.dev); 2589 dev_put(po->prot_hook.dev);
2513 po->prot_hook.dev = dev;
2514 2590
2591 po->prot_hook.dev = dev;
2515 po->ifindex = dev ? dev->ifindex : 0; 2592 po->ifindex = dev ? dev->ifindex : 0;
2516 2593
2594 packet_cached_dev_assign(po, dev);
2595
2517 if (protocol == 0) 2596 if (protocol == 0)
2518 goto out_unlock; 2597 goto out_unlock;
2519 2598
@@ -2626,7 +2705,9 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
2626 po = pkt_sk(sk); 2705 po = pkt_sk(sk);
2627 sk->sk_family = PF_PACKET; 2706 sk->sk_family = PF_PACKET;
2628 po->num = proto; 2707 po->num = proto;
2629 RCU_INIT_POINTER(po->cached_dev, NULL); 2708 po->xmit = dev_queue_xmit;
2709
2710 packet_cached_dev_reset(po);
2630 2711
2631 sk->sk_destruct = packet_sock_destruct; 2712 sk->sk_destruct = packet_sock_destruct;
2632 sk_refcnt_debug_inc(sk); 2713 sk_refcnt_debug_inc(sk);
@@ -2799,11 +2880,12 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
2799 aux.tp_net = skb_network_offset(skb); 2880 aux.tp_net = skb_network_offset(skb);
2800 if (vlan_tx_tag_present(skb)) { 2881 if (vlan_tx_tag_present(skb)) {
2801 aux.tp_vlan_tci = vlan_tx_tag_get(skb); 2882 aux.tp_vlan_tci = vlan_tx_tag_get(skb);
2802 aux.tp_status |= TP_STATUS_VLAN_VALID; 2883 aux.tp_vlan_tpid = ntohs(skb->vlan_proto);
2884 aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
2803 } else { 2885 } else {
2804 aux.tp_vlan_tci = 0; 2886 aux.tp_vlan_tci = 0;
2887 aux.tp_vlan_tpid = 0;
2805 } 2888 }
2806 aux.tp_padding = 0;
2807 put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux); 2889 put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
2808 } 2890 }
2809 2891
@@ -3204,6 +3286,18 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
3204 po->tp_tx_has_off = !!val; 3286 po->tp_tx_has_off = !!val;
3205 return 0; 3287 return 0;
3206 } 3288 }
3289 case PACKET_QDISC_BYPASS:
3290 {
3291 int val;
3292
3293 if (optlen != sizeof(val))
3294 return -EINVAL;
3295 if (copy_from_user(&val, optval, sizeof(val)))
3296 return -EFAULT;
3297
3298 po->xmit = val ? packet_direct_xmit : dev_queue_xmit;
3299 return 0;
3300 }
3207 default: 3301 default:
3208 return -ENOPROTOOPT; 3302 return -ENOPROTOOPT;
3209 } 3303 }
@@ -3296,6 +3390,9 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
3296 case PACKET_TX_HAS_OFF: 3390 case PACKET_TX_HAS_OFF:
3297 val = po->tp_tx_has_off; 3391 val = po->tp_tx_has_off;
3298 break; 3392 break;
3393 case PACKET_QDISC_BYPASS:
3394 val = packet_use_direct_xmit(po);
3395 break;
3299 default: 3396 default:
3300 return -ENOPROTOOPT; 3397 return -ENOPROTOOPT;
3301 } 3398 }
@@ -3337,6 +3434,7 @@ static int packet_notifier(struct notifier_block *this,
3337 sk->sk_error_report(sk); 3434 sk->sk_error_report(sk);
3338 } 3435 }
3339 if (msg == NETDEV_UNREGISTER) { 3436 if (msg == NETDEV_UNREGISTER) {
3437 packet_cached_dev_reset(po);
3340 po->ifindex = -1; 3438 po->ifindex = -1;
3341 if (po->prot_hook.dev) 3439 if (po->prot_hook.dev)
3342 dev_put(po->prot_hook.dev); 3440 dev_put(po->prot_hook.dev);
diff --git a/net/packet/internal.h b/net/packet/internal.h
index 1035fa2d909c..0a87d7b36c9e 100644
--- a/net/packet/internal.h
+++ b/net/packet/internal.h
@@ -114,6 +114,7 @@ struct packet_sock {
114 unsigned int tp_tx_has_off:1; 114 unsigned int tp_tx_has_off:1;
115 unsigned int tp_tstamp; 115 unsigned int tp_tstamp;
116 struct net_device __rcu *cached_dev; 116 struct net_device __rcu *cached_dev;
117 int (*xmit)(struct sk_buff *skb);
117 struct packet_type prot_hook ____cacheline_aligned_in_smp; 118 struct packet_type prot_hook ____cacheline_aligned_in_smp;
118}; 119};
119 120
diff --git a/net/rds/ib_send.c b/net/rds/ib_send.c
index e59094981175..37be6e226d1b 100644
--- a/net/rds/ib_send.c
+++ b/net/rds/ib_send.c
@@ -552,9 +552,8 @@ int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm,
552 && rm->m_inc.i_hdr.h_flags & RDS_FLAG_CONG_BITMAP) { 552 && rm->m_inc.i_hdr.h_flags & RDS_FLAG_CONG_BITMAP) {
553 rds_cong_map_updated(conn->c_fcong, ~(u64) 0); 553 rds_cong_map_updated(conn->c_fcong, ~(u64) 0);
554 scat = &rm->data.op_sg[sg]; 554 scat = &rm->data.op_sg[sg];
555 ret = sizeof(struct rds_header) + RDS_CONG_MAP_BYTES; 555 ret = max_t(int, RDS_CONG_MAP_BYTES, scat->length);
556 ret = min_t(int, ret, scat->length - conn->c_xmit_data_off); 556 return sizeof(struct rds_header) + ret;
557 return ret;
558 } 557 }
559 558
560 /* FIXME we may overallocate here */ 559 /* FIXME we may overallocate here */
diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index 33af77246bfe..81f94b1ae1c7 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -1012,7 +1012,7 @@ int rose_rx_call_request(struct sk_buff *skb, struct net_device *dev, struct ros
1012 make_rose->source_call = facilities.source_call; 1012 make_rose->source_call = facilities.source_call;
1013 make_rose->source_ndigis = facilities.source_ndigis; 1013 make_rose->source_ndigis = facilities.source_ndigis;
1014 for (n = 0 ; n < facilities.source_ndigis ; n++) 1014 for (n = 0 ; n < facilities.source_ndigis ; n++)
1015 make_rose->source_digis[n]= facilities.source_digis[n]; 1015 make_rose->source_digis[n] = facilities.source_digis[n];
1016 make_rose->neighbour = neigh; 1016 make_rose->neighbour = neigh;
1017 make_rose->device = dev; 1017 make_rose->device = dev;
1018 make_rose->facilities = facilities; 1018 make_rose->facilities = facilities;
diff --git a/net/rose/rose_dev.c b/net/rose/rose_dev.c
index 28dbdb911b85..50005888be57 100644
--- a/net/rose/rose_dev.c
+++ b/net/rose/rose_dev.c
@@ -146,7 +146,7 @@ static netdev_tx_t rose_xmit(struct sk_buff *skb, struct net_device *dev)
146 146
147static const struct header_ops rose_header_ops = { 147static const struct header_ops rose_header_ops = {
148 .create = rose_header, 148 .create = rose_header,
149 .rebuild= rose_rebuild_header, 149 .rebuild = rose_rebuild_header,
150}; 150};
151 151
152static const struct net_device_ops rose_netdev_ops = { 152static const struct net_device_ops rose_netdev_ops = {
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index ad1f1d819203..919847beec39 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -286,6 +286,15 @@ config NET_SCH_FQ
286 286
287 If unsure, say N. 287 If unsure, say N.
288 288
289config NET_SCH_HHF
290 tristate "Heavy-Hitter Filter (HHF)"
291 help
292 Say Y here if you want to use the Heavy-Hitter Filter (HHF)
293 packet scheduling algorithm.
294
295 To compile this driver as a module, choose M here: the module
296 will be called sch_hhf.
297
289config NET_SCH_INGRESS 298config NET_SCH_INGRESS
290 tristate "Ingress Qdisc" 299 tristate "Ingress Qdisc"
291 depends on NET_CLS_ACT 300 depends on NET_CLS_ACT
diff --git a/net/sched/Makefile b/net/sched/Makefile
index 35fa47a494ab..3442e5fbc4d7 100644
--- a/net/sched/Makefile
+++ b/net/sched/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_NET_SCH_QFQ) += sch_qfq.o
40obj-$(CONFIG_NET_SCH_CODEL) += sch_codel.o 40obj-$(CONFIG_NET_SCH_CODEL) += sch_codel.o
41obj-$(CONFIG_NET_SCH_FQ_CODEL) += sch_fq_codel.o 41obj-$(CONFIG_NET_SCH_FQ_CODEL) += sch_fq_codel.o
42obj-$(CONFIG_NET_SCH_FQ) += sch_fq.o 42obj-$(CONFIG_NET_SCH_FQ) += sch_fq.o
43obj-$(CONFIG_NET_SCH_HHF) += sch_hhf.o
43 44
44obj-$(CONFIG_NET_CLS_U32) += cls_u32.o 45obj-$(CONFIG_NET_CLS_U32) += cls_u32.o
45obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o 46obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index fd7072827a40..dce2b6ecdbd8 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -29,25 +29,16 @@
29 29
30void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo) 30void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo)
31{ 31{
32 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask); 32 spin_lock_bh(&hinfo->lock);
33 struct tcf_common **p1p; 33 hlist_del(&p->tcfc_head);
34 34 spin_unlock_bh(&hinfo->lock);
35 for (p1p = &hinfo->htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) { 35 gen_kill_estimator(&p->tcfc_bstats,
36 if (*p1p == p) { 36 &p->tcfc_rate_est);
37 write_lock_bh(hinfo->lock); 37 /*
38 *p1p = p->tcfc_next; 38 * gen_estimator est_timer() might access p->tcfc_lock
39 write_unlock_bh(hinfo->lock); 39 * or bstats, wait a RCU grace period before freeing p
40 gen_kill_estimator(&p->tcfc_bstats, 40 */
41 &p->tcfc_rate_est); 41 kfree_rcu(p, tcfc_rcu);
42 /*
43 * gen_estimator est_timer() might access p->tcfc_lock
44 * or bstats, wait a RCU grace period before freeing p
45 */
46 kfree_rcu(p, tcfc_rcu);
47 return;
48 }
49 }
50 WARN_ON(1);
51} 42}
52EXPORT_SYMBOL(tcf_hash_destroy); 43EXPORT_SYMBOL(tcf_hash_destroy);
53 44
@@ -73,18 +64,19 @@ EXPORT_SYMBOL(tcf_hash_release);
73static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb, 64static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
74 struct tc_action *a, struct tcf_hashinfo *hinfo) 65 struct tc_action *a, struct tcf_hashinfo *hinfo)
75{ 66{
67 struct hlist_head *head;
76 struct tcf_common *p; 68 struct tcf_common *p;
77 int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; 69 int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
78 struct nlattr *nest; 70 struct nlattr *nest;
79 71
80 read_lock_bh(hinfo->lock); 72 spin_lock_bh(&hinfo->lock);
81 73
82 s_i = cb->args[0]; 74 s_i = cb->args[0];
83 75
84 for (i = 0; i < (hinfo->hmask + 1); i++) { 76 for (i = 0; i < (hinfo->hmask + 1); i++) {
85 p = hinfo->htab[tcf_hash(i, hinfo->hmask)]; 77 head = &hinfo->htab[tcf_hash(i, hinfo->hmask)];
86 78
87 for (; p; p = p->tcfc_next) { 79 hlist_for_each_entry_rcu(p, head, tcfc_head) {
88 index++; 80 index++;
89 if (index < s_i) 81 if (index < s_i)
90 continue; 82 continue;
@@ -107,7 +99,7 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
107 } 99 }
108 } 100 }
109done: 101done:
110 read_unlock_bh(hinfo->lock); 102 spin_unlock_bh(&hinfo->lock);
111 if (n_i) 103 if (n_i)
112 cb->args[0] += n_i; 104 cb->args[0] += n_i;
113 return n_i; 105 return n_i;
@@ -120,7 +112,9 @@ nla_put_failure:
120static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a, 112static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a,
121 struct tcf_hashinfo *hinfo) 113 struct tcf_hashinfo *hinfo)
122{ 114{
123 struct tcf_common *p, *s_p; 115 struct hlist_head *head;
116 struct hlist_node *n;
117 struct tcf_common *p;
124 struct nlattr *nest; 118 struct nlattr *nest;
125 int i = 0, n_i = 0; 119 int i = 0, n_i = 0;
126 120
@@ -130,14 +124,11 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a,
130 if (nla_put_string(skb, TCA_KIND, a->ops->kind)) 124 if (nla_put_string(skb, TCA_KIND, a->ops->kind))
131 goto nla_put_failure; 125 goto nla_put_failure;
132 for (i = 0; i < (hinfo->hmask + 1); i++) { 126 for (i = 0; i < (hinfo->hmask + 1); i++) {
133 p = hinfo->htab[tcf_hash(i, hinfo->hmask)]; 127 head = &hinfo->htab[tcf_hash(i, hinfo->hmask)];
134 128 hlist_for_each_entry_safe(p, n, head, tcfc_head) {
135 while (p != NULL) {
136 s_p = p->tcfc_next;
137 if (ACT_P_DELETED == tcf_hash_release(p, 0, hinfo)) 129 if (ACT_P_DELETED == tcf_hash_release(p, 0, hinfo))
138 module_put(a->ops->owner); 130 module_put(a->ops->owner);
139 n_i++; 131 n_i++;
140 p = s_p;
141 } 132 }
142 } 133 }
143 if (nla_put_u32(skb, TCA_FCNT, n_i)) 134 if (nla_put_u32(skb, TCA_FCNT, n_i))
@@ -168,15 +159,15 @@ EXPORT_SYMBOL(tcf_generic_walker);
168 159
169struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo) 160struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo)
170{ 161{
171 struct tcf_common *p; 162 struct tcf_common *p = NULL;
163 struct hlist_head *head;
172 164
173 read_lock_bh(hinfo->lock); 165 spin_lock_bh(&hinfo->lock);
174 for (p = hinfo->htab[tcf_hash(index, hinfo->hmask)]; p; 166 head = &hinfo->htab[tcf_hash(index, hinfo->hmask)];
175 p = p->tcfc_next) { 167 hlist_for_each_entry_rcu(p, head, tcfc_head)
176 if (p->tcfc_index == index) 168 if (p->tcfc_index == index)
177 break; 169 break;
178 } 170 spin_unlock_bh(&hinfo->lock);
179 read_unlock_bh(hinfo->lock);
180 171
181 return p; 172 return p;
182} 173}
@@ -191,7 +182,8 @@ u32 tcf_hash_new_index(u32 *idx_gen, struct tcf_hashinfo *hinfo)
191 val = 1; 182 val = 1;
192 } while (tcf_hash_lookup(val, hinfo)); 183 } while (tcf_hash_lookup(val, hinfo));
193 184
194 return (*idx_gen = val); 185 *idx_gen = val;
186 return val;
195} 187}
196EXPORT_SYMBOL(tcf_hash_new_index); 188EXPORT_SYMBOL(tcf_hash_new_index);
197 189
@@ -235,6 +227,7 @@ struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
235 p->tcfc_bindcnt = 1; 227 p->tcfc_bindcnt = 1;
236 228
237 spin_lock_init(&p->tcfc_lock); 229 spin_lock_init(&p->tcfc_lock);
230 INIT_HLIST_NODE(&p->tcfc_head);
238 p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo); 231 p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo);
239 p->tcfc_tm.install = jiffies; 232 p->tcfc_tm.install = jiffies;
240 p->tcfc_tm.lastuse = jiffies; 233 p->tcfc_tm.lastuse = jiffies;
@@ -256,29 +249,37 @@ void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo)
256{ 249{
257 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask); 250 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);
258 251
259 write_lock_bh(hinfo->lock); 252 spin_lock_bh(&hinfo->lock);
260 p->tcfc_next = hinfo->htab[h]; 253 hlist_add_head(&p->tcfc_head, &hinfo->htab[h]);
261 hinfo->htab[h] = p; 254 spin_unlock_bh(&hinfo->lock);
262 write_unlock_bh(hinfo->lock);
263} 255}
264EXPORT_SYMBOL(tcf_hash_insert); 256EXPORT_SYMBOL(tcf_hash_insert);
265 257
266static struct tc_action_ops *act_base = NULL; 258static LIST_HEAD(act_base);
267static DEFINE_RWLOCK(act_mod_lock); 259static DEFINE_RWLOCK(act_mod_lock);
268 260
269int tcf_register_action(struct tc_action_ops *act) 261int tcf_register_action(struct tc_action_ops *act)
270{ 262{
271 struct tc_action_ops *a, **ap; 263 struct tc_action_ops *a;
264
265 /* Must supply act, dump, cleanup and init */
266 if (!act->act || !act->dump || !act->cleanup || !act->init)
267 return -EINVAL;
268
269 /* Supply defaults */
270 if (!act->lookup)
271 act->lookup = tcf_hash_search;
272 if (!act->walk)
273 act->walk = tcf_generic_walker;
272 274
273 write_lock(&act_mod_lock); 275 write_lock(&act_mod_lock);
274 for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) { 276 list_for_each_entry(a, &act_base, head) {
275 if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) { 277 if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
276 write_unlock(&act_mod_lock); 278 write_unlock(&act_mod_lock);
277 return -EEXIST; 279 return -EEXIST;
278 } 280 }
279 } 281 }
280 act->next = NULL; 282 list_add_tail(&act->head, &act_base);
281 *ap = act;
282 write_unlock(&act_mod_lock); 283 write_unlock(&act_mod_lock);
283 return 0; 284 return 0;
284} 285}
@@ -286,17 +287,16 @@ EXPORT_SYMBOL(tcf_register_action);
286 287
287int tcf_unregister_action(struct tc_action_ops *act) 288int tcf_unregister_action(struct tc_action_ops *act)
288{ 289{
289 struct tc_action_ops *a, **ap; 290 struct tc_action_ops *a;
290 int err = -ENOENT; 291 int err = -ENOENT;
291 292
292 write_lock(&act_mod_lock); 293 write_lock(&act_mod_lock);
293 for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) 294 list_for_each_entry(a, &act_base, head) {
294 if (a == act) 295 if (a == act) {
296 list_del(&act->head);
297 err = 0;
295 break; 298 break;
296 if (a) { 299 }
297 *ap = a->next;
298 a->next = NULL;
299 err = 0;
300 } 300 }
301 write_unlock(&act_mod_lock); 301 write_unlock(&act_mod_lock);
302 return err; 302 return err;
@@ -306,69 +306,42 @@ EXPORT_SYMBOL(tcf_unregister_action);
306/* lookup by name */ 306/* lookup by name */
307static struct tc_action_ops *tc_lookup_action_n(char *kind) 307static struct tc_action_ops *tc_lookup_action_n(char *kind)
308{ 308{
309 struct tc_action_ops *a = NULL; 309 struct tc_action_ops *a, *res = NULL;
310 310
311 if (kind) { 311 if (kind) {
312 read_lock(&act_mod_lock); 312 read_lock(&act_mod_lock);
313 for (a = act_base; a; a = a->next) { 313 list_for_each_entry(a, &act_base, head) {
314 if (strcmp(kind, a->kind) == 0) { 314 if (strcmp(kind, a->kind) == 0) {
315 if (!try_module_get(a->owner)) { 315 if (try_module_get(a->owner))
316 read_unlock(&act_mod_lock); 316 res = a;
317 return NULL;
318 }
319 break; 317 break;
320 } 318 }
321 } 319 }
322 read_unlock(&act_mod_lock); 320 read_unlock(&act_mod_lock);
323 } 321 }
324 return a; 322 return res;
325} 323}
326 324
327/* lookup by nlattr */ 325/* lookup by nlattr */
328static struct tc_action_ops *tc_lookup_action(struct nlattr *kind) 326static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
329{ 327{
330 struct tc_action_ops *a = NULL; 328 struct tc_action_ops *a, *res = NULL;
331 329
332 if (kind) { 330 if (kind) {
333 read_lock(&act_mod_lock); 331 read_lock(&act_mod_lock);
334 for (a = act_base; a; a = a->next) { 332 list_for_each_entry(a, &act_base, head) {
335 if (nla_strcmp(kind, a->kind) == 0) { 333 if (nla_strcmp(kind, a->kind) == 0) {
336 if (!try_module_get(a->owner)) { 334 if (try_module_get(a->owner))
337 read_unlock(&act_mod_lock); 335 res = a;
338 return NULL;
339 }
340 break;
341 }
342 }
343 read_unlock(&act_mod_lock);
344 }
345 return a;
346}
347
348#if 0
349/* lookup by id */
350static struct tc_action_ops *tc_lookup_action_id(u32 type)
351{
352 struct tc_action_ops *a = NULL;
353
354 if (type) {
355 read_lock(&act_mod_lock);
356 for (a = act_base; a; a = a->next) {
357 if (a->type == type) {
358 if (!try_module_get(a->owner)) {
359 read_unlock(&act_mod_lock);
360 return NULL;
361 }
362 break; 336 break;
363 } 337 }
364 } 338 }
365 read_unlock(&act_mod_lock); 339 read_unlock(&act_mod_lock);
366 } 340 }
367 return a; 341 return res;
368} 342}
369#endif
370 343
371int tcf_action_exec(struct sk_buff *skb, const struct tc_action *act, 344int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
372 struct tcf_result *res) 345 struct tcf_result *res)
373{ 346{
374 const struct tc_action *a; 347 const struct tc_action *a;
@@ -379,9 +352,9 @@ int tcf_action_exec(struct sk_buff *skb, const struct tc_action *act,
379 ret = TC_ACT_OK; 352 ret = TC_ACT_OK;
380 goto exec_done; 353 goto exec_done;
381 } 354 }
382 while ((a = act) != NULL) { 355 list_for_each_entry(a, actions, list) {
383repeat: 356repeat:
384 if (a->ops && a->ops->act) { 357 if (a->ops) {
385 ret = a->ops->act(skb, a, res); 358 ret = a->ops->act(skb, a, res);
386 if (TC_MUNGED & skb->tc_verd) { 359 if (TC_MUNGED & skb->tc_verd) {
387 /* copied already, allow trampling */ 360 /* copied already, allow trampling */
@@ -393,27 +366,26 @@ repeat:
393 if (ret != TC_ACT_PIPE) 366 if (ret != TC_ACT_PIPE)
394 goto exec_done; 367 goto exec_done;
395 } 368 }
396 act = a->next;
397 } 369 }
398exec_done: 370exec_done:
399 return ret; 371 return ret;
400} 372}
401EXPORT_SYMBOL(tcf_action_exec); 373EXPORT_SYMBOL(tcf_action_exec);
402 374
403void tcf_action_destroy(struct tc_action *act, int bind) 375void tcf_action_destroy(struct list_head *actions, int bind)
404{ 376{
405 struct tc_action *a; 377 struct tc_action *a, *tmp;
406 378
407 for (a = act; a; a = act) { 379 list_for_each_entry_safe(a, tmp, actions, list) {
408 if (a->ops && a->ops->cleanup) { 380 if (a->ops) {
409 if (a->ops->cleanup(a, bind) == ACT_P_DELETED) 381 if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
410 module_put(a->ops->owner); 382 module_put(a->ops->owner);
411 act = act->next; 383 list_del(&a->list);
412 kfree(a); 384 kfree(a);
413 } else { 385 } else {
414 /*FIXME: Remove later - catch insertion bugs*/ 386 /*FIXME: Remove later - catch insertion bugs*/
415 WARN(1, "tcf_action_destroy: BUG? destroying NULL ops\n"); 387 WARN(1, "tcf_action_destroy: BUG? destroying NULL ops\n");
416 act = act->next; 388 list_del(&a->list);
417 kfree(a); 389 kfree(a);
418 } 390 }
419 } 391 }
@@ -424,7 +396,7 @@ tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
424{ 396{
425 int err = -EINVAL; 397 int err = -EINVAL;
426 398
427 if (a->ops == NULL || a->ops->dump == NULL) 399 if (a->ops == NULL)
428 return err; 400 return err;
429 return a->ops->dump(skb, a, bind, ref); 401 return a->ops->dump(skb, a, bind, ref);
430} 402}
@@ -436,7 +408,7 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
436 unsigned char *b = skb_tail_pointer(skb); 408 unsigned char *b = skb_tail_pointer(skb);
437 struct nlattr *nest; 409 struct nlattr *nest;
438 410
439 if (a->ops == NULL || a->ops->dump == NULL) 411 if (a->ops == NULL)
440 return err; 412 return err;
441 413
442 if (nla_put_string(skb, TCA_KIND, a->ops->kind)) 414 if (nla_put_string(skb, TCA_KIND, a->ops->kind))
@@ -459,14 +431,13 @@ nla_put_failure:
459EXPORT_SYMBOL(tcf_action_dump_1); 431EXPORT_SYMBOL(tcf_action_dump_1);
460 432
461int 433int
462tcf_action_dump(struct sk_buff *skb, struct tc_action *act, int bind, int ref) 434tcf_action_dump(struct sk_buff *skb, struct list_head *actions, int bind, int ref)
463{ 435{
464 struct tc_action *a; 436 struct tc_action *a;
465 int err = -EINVAL; 437 int err = -EINVAL;
466 struct nlattr *nest; 438 struct nlattr *nest;
467 439
468 while ((a = act) != NULL) { 440 list_for_each_entry(a, actions, list) {
469 act = a->next;
470 nest = nla_nest_start(skb, a->order); 441 nest = nla_nest_start(skb, a->order);
471 if (nest == NULL) 442 if (nest == NULL)
472 goto nla_put_failure; 443 goto nla_put_failure;
@@ -541,6 +512,7 @@ struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
541 if (a == NULL) 512 if (a == NULL)
542 goto err_mod; 513 goto err_mod;
543 514
515 INIT_LIST_HEAD(&a->list);
544 /* backward compatibility for policer */ 516 /* backward compatibility for policer */
545 if (name == NULL) 517 if (name == NULL)
546 err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, a, ovr, bind); 518 err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, a, ovr, bind);
@@ -567,37 +539,33 @@ err_out:
567 return ERR_PTR(err); 539 return ERR_PTR(err);
568} 540}
569 541
570struct tc_action *tcf_action_init(struct net *net, struct nlattr *nla, 542int tcf_action_init(struct net *net, struct nlattr *nla,
571 struct nlattr *est, char *name, int ovr, 543 struct nlattr *est, char *name, int ovr,
572 int bind) 544 int bind, struct list_head *actions)
573{ 545{
574 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1]; 546 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
575 struct tc_action *head = NULL, *act, *act_prev = NULL; 547 struct tc_action *act;
576 int err; 548 int err;
577 int i; 549 int i;
578 550
579 err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL); 551 err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
580 if (err < 0) 552 if (err < 0)
581 return ERR_PTR(err); 553 return err;
582 554
583 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) { 555 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
584 act = tcf_action_init_1(net, tb[i], est, name, ovr, bind); 556 act = tcf_action_init_1(net, tb[i], est, name, ovr, bind);
585 if (IS_ERR(act)) 557 if (IS_ERR(act)) {
558 err = PTR_ERR(act);
586 goto err; 559 goto err;
560 }
587 act->order = i; 561 act->order = i;
588 562 list_add_tail(&act->list, actions);
589 if (head == NULL)
590 head = act;
591 else
592 act_prev->next = act;
593 act_prev = act;
594 } 563 }
595 return head; 564 return 0;
596 565
597err: 566err:
598 if (head != NULL) 567 tcf_action_destroy(actions, bind);
599 tcf_action_destroy(head, bind); 568 return err;
600 return act;
601} 569}
602 570
603int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a, 571int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
@@ -626,10 +594,6 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
626 if (err < 0) 594 if (err < 0)
627 goto errout; 595 goto errout;
628 596
629 if (a->ops != NULL && a->ops->get_stats != NULL)
630 if (a->ops->get_stats(skb, a) < 0)
631 goto errout;
632
633 if (gnet_stats_copy_basic(&d, &h->tcf_bstats) < 0 || 597 if (gnet_stats_copy_basic(&d, &h->tcf_bstats) < 0 ||
634 gnet_stats_copy_rate_est(&d, &h->tcf_bstats, 598 gnet_stats_copy_rate_est(&d, &h->tcf_bstats,
635 &h->tcf_rate_est) < 0 || 599 &h->tcf_rate_est) < 0 ||
@@ -646,7 +610,7 @@ errout:
646} 610}
647 611
648static int 612static int
649tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 portid, u32 seq, 613tca_get_fill(struct sk_buff *skb, struct list_head *actions, u32 portid, u32 seq,
650 u16 flags, int event, int bind, int ref) 614 u16 flags, int event, int bind, int ref)
651{ 615{
652 struct tcamsg *t; 616 struct tcamsg *t;
@@ -666,7 +630,7 @@ tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 portid, u32 seq,
666 if (nest == NULL) 630 if (nest == NULL)
667 goto out_nlmsg_trim; 631 goto out_nlmsg_trim;
668 632
669 if (tcf_action_dump(skb, a, bind, ref) < 0) 633 if (tcf_action_dump(skb, actions, bind, ref) < 0)
670 goto out_nlmsg_trim; 634 goto out_nlmsg_trim;
671 635
672 nla_nest_end(skb, nest); 636 nla_nest_end(skb, nest);
@@ -681,14 +645,14 @@ out_nlmsg_trim:
681 645
682static int 646static int
683act_get_notify(struct net *net, u32 portid, struct nlmsghdr *n, 647act_get_notify(struct net *net, u32 portid, struct nlmsghdr *n,
684 struct tc_action *a, int event) 648 struct list_head *actions, int event)
685{ 649{
686 struct sk_buff *skb; 650 struct sk_buff *skb;
687 651
688 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); 652 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
689 if (!skb) 653 if (!skb)
690 return -ENOBUFS; 654 return -ENOBUFS;
691 if (tca_get_fill(skb, a, portid, n->nlmsg_seq, 0, event, 0, 0) <= 0) { 655 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, event, 0, 0) <= 0) {
692 kfree_skb(skb); 656 kfree_skb(skb);
693 return -EINVAL; 657 return -EINVAL;
694 } 658 }
@@ -719,12 +683,11 @@ tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 portid)
719 if (a == NULL) 683 if (a == NULL)
720 goto err_out; 684 goto err_out;
721 685
686 INIT_LIST_HEAD(&a->list);
722 err = -EINVAL; 687 err = -EINVAL;
723 a->ops = tc_lookup_action(tb[TCA_ACT_KIND]); 688 a->ops = tc_lookup_action(tb[TCA_ACT_KIND]);
724 if (a->ops == NULL) 689 if (a->ops == NULL)
725 goto err_free; 690 goto err_free;
726 if (a->ops->lookup == NULL)
727 goto err_mod;
728 err = -ENOENT; 691 err = -ENOENT;
729 if (a->ops->lookup(a, index) == 0) 692 if (a->ops->lookup(a, index) == 0)
730 goto err_mod; 693 goto err_mod;
@@ -740,12 +703,12 @@ err_out:
740 return ERR_PTR(err); 703 return ERR_PTR(err);
741} 704}
742 705
743static void cleanup_a(struct tc_action *act) 706static void cleanup_a(struct list_head *actions)
744{ 707{
745 struct tc_action *a; 708 struct tc_action *a, *tmp;
746 709
747 for (a = act; a; a = act) { 710 list_for_each_entry_safe(a, tmp, actions, list) {
748 act = a->next; 711 list_del(&a->list);
749 kfree(a); 712 kfree(a);
750 } 713 }
751} 714}
@@ -760,6 +723,7 @@ static struct tc_action *create_a(int i)
760 return NULL; 723 return NULL;
761 } 724 }
762 act->order = i; 725 act->order = i;
726 INIT_LIST_HEAD(&act->list);
763 return act; 727 return act;
764} 728}
765 729
@@ -847,7 +811,8 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
847{ 811{
848 int i, ret; 812 int i, ret;
849 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1]; 813 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
850 struct tc_action *head = NULL, *act, *act_prev = NULL; 814 struct tc_action *act;
815 LIST_HEAD(actions);
851 816
852 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL); 817 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
853 if (ret < 0) 818 if (ret < 0)
@@ -867,16 +832,11 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
867 goto err; 832 goto err;
868 } 833 }
869 act->order = i; 834 act->order = i;
870 835 list_add_tail(&act->list, &actions);
871 if (head == NULL)
872 head = act;
873 else
874 act_prev->next = act;
875 act_prev = act;
876 } 836 }
877 837
878 if (event == RTM_GETACTION) 838 if (event == RTM_GETACTION)
879 ret = act_get_notify(net, portid, n, head, event); 839 ret = act_get_notify(net, portid, n, &actions, event);
880 else { /* delete */ 840 else { /* delete */
881 struct sk_buff *skb; 841 struct sk_buff *skb;
882 842
@@ -886,7 +846,7 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
886 goto err; 846 goto err;
887 } 847 }
888 848
889 if (tca_get_fill(skb, head, portid, n->nlmsg_seq, 0, event, 849 if (tca_get_fill(skb, &actions, portid, n->nlmsg_seq, 0, event,
890 0, 1) <= 0) { 850 0, 1) <= 0) {
891 kfree_skb(skb); 851 kfree_skb(skb);
892 ret = -EINVAL; 852 ret = -EINVAL;
@@ -894,7 +854,7 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
894 } 854 }
895 855
896 /* now do the delete */ 856 /* now do the delete */
897 tcf_action_destroy(head, 0); 857 tcf_action_destroy(&actions, 0);
898 ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC, 858 ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
899 n->nlmsg_flags & NLM_F_ECHO); 859 n->nlmsg_flags & NLM_F_ECHO);
900 if (ret > 0) 860 if (ret > 0)
@@ -902,11 +862,11 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
902 return ret; 862 return ret;
903 } 863 }
904err: 864err:
905 cleanup_a(head); 865 cleanup_a(&actions);
906 return ret; 866 return ret;
907} 867}
908 868
909static int tcf_add_notify(struct net *net, struct tc_action *a, 869static int tcf_add_notify(struct net *net, struct list_head *actions,
910 u32 portid, u32 seq, int event, u16 flags) 870 u32 portid, u32 seq, int event, u16 flags)
911{ 871{
912 struct tcamsg *t; 872 struct tcamsg *t;
@@ -934,7 +894,7 @@ static int tcf_add_notify(struct net *net, struct tc_action *a,
934 if (nest == NULL) 894 if (nest == NULL)
935 goto out_kfree_skb; 895 goto out_kfree_skb;
936 896
937 if (tcf_action_dump(skb, a, 0, 0) < 0) 897 if (tcf_action_dump(skb, actions, 0, 0) < 0)
938 goto out_kfree_skb; 898 goto out_kfree_skb;
939 899
940 nla_nest_end(skb, nest); 900 nla_nest_end(skb, nest);
@@ -958,26 +918,18 @@ tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
958 u32 portid, int ovr) 918 u32 portid, int ovr)
959{ 919{
960 int ret = 0; 920 int ret = 0;
961 struct tc_action *act; 921 LIST_HEAD(actions);
962 struct tc_action *a;
963 u32 seq = n->nlmsg_seq; 922 u32 seq = n->nlmsg_seq;
964 923
965 act = tcf_action_init(net, nla, NULL, NULL, ovr, 0); 924 ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions);
966 if (act == NULL) 925 if (ret)
967 goto done; 926 goto done;
968 if (IS_ERR(act)) {
969 ret = PTR_ERR(act);
970 goto done;
971 }
972 927
973 /* dump then free all the actions after update; inserted policy 928 /* dump then free all the actions after update; inserted policy
974 * stays intact 929 * stays intact
975 */ 930 */
976 ret = tcf_add_notify(net, act, portid, seq, RTM_NEWACTION, n->nlmsg_flags); 931 ret = tcf_add_notify(net, &actions, portid, seq, RTM_NEWACTION, n->nlmsg_flags);
977 for (a = act; a; a = act) { 932 cleanup_a(&actions);
978 act = a->next;
979 kfree(a);
980 }
981done: 933done:
982 return ret; 934 return ret;
983} 935}
@@ -1084,12 +1036,6 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1084 memset(&a, 0, sizeof(struct tc_action)); 1036 memset(&a, 0, sizeof(struct tc_action));
1085 a.ops = a_o; 1037 a.ops = a_o;
1086 1038
1087 if (a_o->walk == NULL) {
1088 WARN(1, "tc_dump_action: %s !capable of dumping table\n",
1089 a_o->kind);
1090 goto out_module_put;
1091 }
1092
1093 nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, 1039 nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
1094 cb->nlh->nlmsg_type, sizeof(*t), 0); 1040 cb->nlh->nlmsg_type, sizeof(*t), 0);
1095 if (!nlh) 1041 if (!nlh)
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index 3a4c0caa1f7d..9cc6717c5f19 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -37,15 +37,8 @@
37#include <net/tc_act/tc_csum.h> 37#include <net/tc_act/tc_csum.h>
38 38
39#define CSUM_TAB_MASK 15 39#define CSUM_TAB_MASK 15
40static struct tcf_common *tcf_csum_ht[CSUM_TAB_MASK + 1];
41static u32 csum_idx_gen; 40static u32 csum_idx_gen;
42static DEFINE_RWLOCK(csum_lock); 41static struct tcf_hashinfo csum_hash_info;
43
44static struct tcf_hashinfo csum_hash_info = {
45 .htab = tcf_csum_ht,
46 .hmask = CSUM_TAB_MASK,
47 .lock = &csum_lock,
48};
49 42
50static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = { 43static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
51 [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), }, 44 [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), },
@@ -585,9 +578,7 @@ static struct tc_action_ops act_csum_ops = {
585 .act = tcf_csum, 578 .act = tcf_csum,
586 .dump = tcf_csum_dump, 579 .dump = tcf_csum_dump,
587 .cleanup = tcf_csum_cleanup, 580 .cleanup = tcf_csum_cleanup,
588 .lookup = tcf_hash_search,
589 .init = tcf_csum_init, 581 .init = tcf_csum_init,
590 .walk = tcf_generic_walker
591}; 582};
592 583
593MODULE_DESCRIPTION("Checksum updating actions"); 584MODULE_DESCRIPTION("Checksum updating actions");
@@ -595,6 +586,10 @@ MODULE_LICENSE("GPL");
595 586
596static int __init csum_init_module(void) 587static int __init csum_init_module(void)
597{ 588{
589 int err = tcf_hashinfo_init(&csum_hash_info, CSUM_TAB_MASK);
590 if (err)
591 return err;
592
598 return tcf_register_action(&act_csum_ops); 593 return tcf_register_action(&act_csum_ops);
599} 594}
600 595
diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
index fd2b3cff5fa2..dea927343bf4 100644
--- a/net/sched/act_gact.c
+++ b/net/sched/act_gact.c
@@ -24,15 +24,8 @@
24#include <net/tc_act/tc_gact.h> 24#include <net/tc_act/tc_gact.h>
25 25
26#define GACT_TAB_MASK 15 26#define GACT_TAB_MASK 15
27static struct tcf_common *tcf_gact_ht[GACT_TAB_MASK + 1];
28static u32 gact_idx_gen; 27static u32 gact_idx_gen;
29static DEFINE_RWLOCK(gact_lock); 28static struct tcf_hashinfo gact_hash_info;
30
31static struct tcf_hashinfo gact_hash_info = {
32 .htab = tcf_gact_ht,
33 .hmask = GACT_TAB_MASK,
34 .lock = &gact_lock,
35};
36 29
37#ifdef CONFIG_GACT_PROB 30#ifdef CONFIG_GACT_PROB
38static int gact_net_rand(struct tcf_gact *gact) 31static int gact_net_rand(struct tcf_gact *gact)
@@ -206,9 +199,7 @@ static struct tc_action_ops act_gact_ops = {
206 .act = tcf_gact, 199 .act = tcf_gact,
207 .dump = tcf_gact_dump, 200 .dump = tcf_gact_dump,
208 .cleanup = tcf_gact_cleanup, 201 .cleanup = tcf_gact_cleanup,
209 .lookup = tcf_hash_search,
210 .init = tcf_gact_init, 202 .init = tcf_gact_init,
211 .walk = tcf_generic_walker
212}; 203};
213 204
214MODULE_AUTHOR("Jamal Hadi Salim(2002-4)"); 205MODULE_AUTHOR("Jamal Hadi Salim(2002-4)");
@@ -217,6 +208,9 @@ MODULE_LICENSE("GPL");
217 208
218static int __init gact_init_module(void) 209static int __init gact_init_module(void)
219{ 210{
211 int err = tcf_hashinfo_init(&gact_hash_info, GACT_TAB_MASK);
212 if (err)
213 return err;
220#ifdef CONFIG_GACT_PROB 214#ifdef CONFIG_GACT_PROB
221 pr_info("GACT probability on\n"); 215 pr_info("GACT probability on\n");
222#else 216#else
@@ -228,6 +222,7 @@ static int __init gact_init_module(void)
228static void __exit gact_cleanup_module(void) 222static void __exit gact_cleanup_module(void)
229{ 223{
230 tcf_unregister_action(&act_gact_ops); 224 tcf_unregister_action(&act_gact_ops);
225 tcf_hashinfo_destroy(&gact_hash_info);
231} 226}
232 227
233module_init(gact_init_module); 228module_init(gact_init_module);
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 60d88b6b9560..e13ecbbfe8c4 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -29,15 +29,8 @@
29 29
30 30
31#define IPT_TAB_MASK 15 31#define IPT_TAB_MASK 15
32static struct tcf_common *tcf_ipt_ht[IPT_TAB_MASK + 1];
33static u32 ipt_idx_gen; 32static u32 ipt_idx_gen;
34static DEFINE_RWLOCK(ipt_lock); 33static struct tcf_hashinfo ipt_hash_info;
35
36static struct tcf_hashinfo ipt_hash_info = {
37 .htab = tcf_ipt_ht,
38 .hmask = IPT_TAB_MASK,
39 .lock = &ipt_lock,
40};
41 34
42static int ipt_init_target(struct xt_entry_target *t, char *table, unsigned int hook) 35static int ipt_init_target(struct xt_entry_target *t, char *table, unsigned int hook)
43{ 36{
@@ -298,9 +291,7 @@ static struct tc_action_ops act_ipt_ops = {
298 .act = tcf_ipt, 291 .act = tcf_ipt,
299 .dump = tcf_ipt_dump, 292 .dump = tcf_ipt_dump,
300 .cleanup = tcf_ipt_cleanup, 293 .cleanup = tcf_ipt_cleanup,
301 .lookup = tcf_hash_search,
302 .init = tcf_ipt_init, 294 .init = tcf_ipt_init,
303 .walk = tcf_generic_walker
304}; 295};
305 296
306static struct tc_action_ops act_xt_ops = { 297static struct tc_action_ops act_xt_ops = {
@@ -312,9 +303,7 @@ static struct tc_action_ops act_xt_ops = {
312 .act = tcf_ipt, 303 .act = tcf_ipt,
313 .dump = tcf_ipt_dump, 304 .dump = tcf_ipt_dump,
314 .cleanup = tcf_ipt_cleanup, 305 .cleanup = tcf_ipt_cleanup,
315 .lookup = tcf_hash_search,
316 .init = tcf_ipt_init, 306 .init = tcf_ipt_init,
317 .walk = tcf_generic_walker
318}; 307};
319 308
320MODULE_AUTHOR("Jamal Hadi Salim(2002-13)"); 309MODULE_AUTHOR("Jamal Hadi Salim(2002-13)");
@@ -324,7 +313,11 @@ MODULE_ALIAS("act_xt");
324 313
325static int __init ipt_init_module(void) 314static int __init ipt_init_module(void)
326{ 315{
327 int ret1, ret2; 316 int ret1, ret2, err;
317 err = tcf_hashinfo_init(&ipt_hash_info, IPT_TAB_MASK);
318 if (err)
319 return err;
320
328 ret1 = tcf_register_action(&act_xt_ops); 321 ret1 = tcf_register_action(&act_xt_ops);
329 if (ret1 < 0) 322 if (ret1 < 0)
330 printk("Failed to load xt action\n"); 323 printk("Failed to load xt action\n");
@@ -332,9 +325,10 @@ static int __init ipt_init_module(void)
332 if (ret2 < 0) 325 if (ret2 < 0)
333 printk("Failed to load ipt action\n"); 326 printk("Failed to load ipt action\n");
334 327
335 if (ret1 < 0 && ret2 < 0) 328 if (ret1 < 0 && ret2 < 0) {
329 tcf_hashinfo_destroy(&ipt_hash_info);
336 return ret1; 330 return ret1;
337 else 331 } else
338 return 0; 332 return 0;
339} 333}
340 334
@@ -342,6 +336,7 @@ static void __exit ipt_cleanup_module(void)
342{ 336{
343 tcf_unregister_action(&act_xt_ops); 337 tcf_unregister_action(&act_xt_ops);
344 tcf_unregister_action(&act_ipt_ops); 338 tcf_unregister_action(&act_ipt_ops);
339 tcf_hashinfo_destroy(&ipt_hash_info);
345} 340}
346 341
347module_init(ipt_init_module); 342module_init(ipt_init_module);
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 977c10e0631b..9dbb8cd64cb0 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -30,16 +30,9 @@
30#include <linux/if_arp.h> 30#include <linux/if_arp.h>
31 31
32#define MIRRED_TAB_MASK 7 32#define MIRRED_TAB_MASK 7
33static struct tcf_common *tcf_mirred_ht[MIRRED_TAB_MASK + 1];
34static u32 mirred_idx_gen; 33static u32 mirred_idx_gen;
35static DEFINE_RWLOCK(mirred_lock);
36static LIST_HEAD(mirred_list); 34static LIST_HEAD(mirred_list);
37 35static struct tcf_hashinfo mirred_hash_info;
38static struct tcf_hashinfo mirred_hash_info = {
39 .htab = tcf_mirred_ht,
40 .hmask = MIRRED_TAB_MASK,
41 .lock = &mirred_lock,
42};
43 36
44static int tcf_mirred_release(struct tcf_mirred *m, int bind) 37static int tcf_mirred_release(struct tcf_mirred *m, int bind)
45{ 38{
@@ -261,7 +254,6 @@ static struct notifier_block mirred_device_notifier = {
261 .notifier_call = mirred_device_event, 254 .notifier_call = mirred_device_event,
262}; 255};
263 256
264
265static struct tc_action_ops act_mirred_ops = { 257static struct tc_action_ops act_mirred_ops = {
266 .kind = "mirred", 258 .kind = "mirred",
267 .hinfo = &mirred_hash_info, 259 .hinfo = &mirred_hash_info,
@@ -271,9 +263,7 @@ static struct tc_action_ops act_mirred_ops = {
271 .act = tcf_mirred, 263 .act = tcf_mirred,
272 .dump = tcf_mirred_dump, 264 .dump = tcf_mirred_dump,
273 .cleanup = tcf_mirred_cleanup, 265 .cleanup = tcf_mirred_cleanup,
274 .lookup = tcf_hash_search,
275 .init = tcf_mirred_init, 266 .init = tcf_mirred_init,
276 .walk = tcf_generic_walker
277}; 267};
278 268
279MODULE_AUTHOR("Jamal Hadi Salim(2002)"); 269MODULE_AUTHOR("Jamal Hadi Salim(2002)");
@@ -286,14 +276,20 @@ static int __init mirred_init_module(void)
286 if (err) 276 if (err)
287 return err; 277 return err;
288 278
279 err = tcf_hashinfo_init(&mirred_hash_info, MIRRED_TAB_MASK);
280 if (err) {
281 unregister_netdevice_notifier(&mirred_device_notifier);
282 return err;
283 }
289 pr_info("Mirror/redirect action on\n"); 284 pr_info("Mirror/redirect action on\n");
290 return tcf_register_action(&act_mirred_ops); 285 return tcf_register_action(&act_mirred_ops);
291} 286}
292 287
293static void __exit mirred_cleanup_module(void) 288static void __exit mirred_cleanup_module(void)
294{ 289{
295 unregister_netdevice_notifier(&mirred_device_notifier);
296 tcf_unregister_action(&act_mirred_ops); 290 tcf_unregister_action(&act_mirred_ops);
291 tcf_hashinfo_destroy(&mirred_hash_info);
292 unregister_netdevice_notifier(&mirred_device_notifier);
297} 293}
298 294
299module_init(mirred_init_module); 295module_init(mirred_init_module);
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index 876f0ef29694..921fea43fca2 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -30,15 +30,9 @@
30 30
31 31
32#define NAT_TAB_MASK 15 32#define NAT_TAB_MASK 15
33static struct tcf_common *tcf_nat_ht[NAT_TAB_MASK + 1];
34static u32 nat_idx_gen; 33static u32 nat_idx_gen;
35static DEFINE_RWLOCK(nat_lock);
36 34
37static struct tcf_hashinfo nat_hash_info = { 35static struct tcf_hashinfo nat_hash_info;
38 .htab = tcf_nat_ht,
39 .hmask = NAT_TAB_MASK,
40 .lock = &nat_lock,
41};
42 36
43static const struct nla_policy nat_policy[TCA_NAT_MAX + 1] = { 37static const struct nla_policy nat_policy[TCA_NAT_MAX + 1] = {
44 [TCA_NAT_PARMS] = { .len = sizeof(struct tc_nat) }, 38 [TCA_NAT_PARMS] = { .len = sizeof(struct tc_nat) },
@@ -308,9 +302,7 @@ static struct tc_action_ops act_nat_ops = {
308 .act = tcf_nat, 302 .act = tcf_nat,
309 .dump = tcf_nat_dump, 303 .dump = tcf_nat_dump,
310 .cleanup = tcf_nat_cleanup, 304 .cleanup = tcf_nat_cleanup,
311 .lookup = tcf_hash_search,
312 .init = tcf_nat_init, 305 .init = tcf_nat_init,
313 .walk = tcf_generic_walker
314}; 306};
315 307
316MODULE_DESCRIPTION("Stateless NAT actions"); 308MODULE_DESCRIPTION("Stateless NAT actions");
@@ -318,12 +310,16 @@ MODULE_LICENSE("GPL");
318 310
319static int __init nat_init_module(void) 311static int __init nat_init_module(void)
320{ 312{
313 int err = tcf_hashinfo_init(&nat_hash_info, NAT_TAB_MASK);
314 if (err)
315 return err;
321 return tcf_register_action(&act_nat_ops); 316 return tcf_register_action(&act_nat_ops);
322} 317}
323 318
324static void __exit nat_cleanup_module(void) 319static void __exit nat_cleanup_module(void)
325{ 320{
326 tcf_unregister_action(&act_nat_ops); 321 tcf_unregister_action(&act_nat_ops);
322 tcf_hashinfo_destroy(&nat_hash_info);
327} 323}
328 324
329module_init(nat_init_module); 325module_init(nat_init_module);
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 7ed78c9e505c..e2520e90a10d 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -24,15 +24,9 @@
24#include <net/tc_act/tc_pedit.h> 24#include <net/tc_act/tc_pedit.h>
25 25
26#define PEDIT_TAB_MASK 15 26#define PEDIT_TAB_MASK 15
27static struct tcf_common *tcf_pedit_ht[PEDIT_TAB_MASK + 1];
28static u32 pedit_idx_gen; 27static u32 pedit_idx_gen;
29static DEFINE_RWLOCK(pedit_lock);
30 28
31static struct tcf_hashinfo pedit_hash_info = { 29static struct tcf_hashinfo pedit_hash_info;
32 .htab = tcf_pedit_ht,
33 .hmask = PEDIT_TAB_MASK,
34 .lock = &pedit_lock,
35};
36 30
37static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = { 31static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
38 [TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) }, 32 [TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) },
@@ -243,9 +237,7 @@ static struct tc_action_ops act_pedit_ops = {
243 .act = tcf_pedit, 237 .act = tcf_pedit,
244 .dump = tcf_pedit_dump, 238 .dump = tcf_pedit_dump,
245 .cleanup = tcf_pedit_cleanup, 239 .cleanup = tcf_pedit_cleanup,
246 .lookup = tcf_hash_search,
247 .init = tcf_pedit_init, 240 .init = tcf_pedit_init,
248 .walk = tcf_generic_walker
249}; 241};
250 242
251MODULE_AUTHOR("Jamal Hadi Salim(2002-4)"); 243MODULE_AUTHOR("Jamal Hadi Salim(2002-4)");
@@ -254,11 +246,15 @@ MODULE_LICENSE("GPL");
254 246
255static int __init pedit_init_module(void) 247static int __init pedit_init_module(void)
256{ 248{
249 int err = tcf_hashinfo_init(&pedit_hash_info, PEDIT_TAB_MASK);
250 if (err)
251 return err;
257 return tcf_register_action(&act_pedit_ops); 252 return tcf_register_action(&act_pedit_ops);
258} 253}
259 254
260static void __exit pedit_cleanup_module(void) 255static void __exit pedit_cleanup_module(void)
261{ 256{
257 tcf_hashinfo_destroy(&pedit_hash_info);
262 tcf_unregister_action(&act_pedit_ops); 258 tcf_unregister_action(&act_pedit_ops);
263} 259}
264 260
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 272d8e924cf6..819a9a4d1987 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -41,15 +41,8 @@ struct tcf_police {
41 container_of(pc, struct tcf_police, common) 41 container_of(pc, struct tcf_police, common)
42 42
43#define POL_TAB_MASK 15 43#define POL_TAB_MASK 15
44static struct tcf_common *tcf_police_ht[POL_TAB_MASK + 1];
45static u32 police_idx_gen; 44static u32 police_idx_gen;
46static DEFINE_RWLOCK(police_lock); 45static struct tcf_hashinfo police_hash_info;
47
48static struct tcf_hashinfo police_hash_info = {
49 .htab = tcf_police_ht,
50 .hmask = POL_TAB_MASK,
51 .lock = &police_lock,
52};
53 46
54/* old policer structure from before tc actions */ 47/* old policer structure from before tc actions */
55struct tc_police_compat { 48struct tc_police_compat {
@@ -67,18 +60,19 @@ struct tc_police_compat {
67static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *cb, 60static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *cb,
68 int type, struct tc_action *a) 61 int type, struct tc_action *a)
69{ 62{
63 struct hlist_head *head;
70 struct tcf_common *p; 64 struct tcf_common *p;
71 int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; 65 int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
72 struct nlattr *nest; 66 struct nlattr *nest;
73 67
74 read_lock_bh(&police_lock); 68 spin_lock_bh(&police_hash_info.lock);
75 69
76 s_i = cb->args[0]; 70 s_i = cb->args[0];
77 71
78 for (i = 0; i < (POL_TAB_MASK + 1); i++) { 72 for (i = 0; i < (POL_TAB_MASK + 1); i++) {
79 p = tcf_police_ht[tcf_hash(i, POL_TAB_MASK)]; 73 head = &police_hash_info.htab[tcf_hash(i, POL_TAB_MASK)];
80 74
81 for (; p; p = p->tcfc_next) { 75 hlist_for_each_entry_rcu(p, head, tcfc_head) {
82 index++; 76 index++;
83 if (index < s_i) 77 if (index < s_i)
84 continue; 78 continue;
@@ -101,7 +95,7 @@ static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *c
101 } 95 }
102 } 96 }
103done: 97done:
104 read_unlock_bh(&police_lock); 98 spin_unlock_bh(&police_hash_info.lock);
105 if (n_i) 99 if (n_i)
106 cb->args[0] += n_i; 100 cb->args[0] += n_i;
107 return n_i; 101 return n_i;
@@ -113,25 +107,16 @@ nla_put_failure:
113 107
114static void tcf_police_destroy(struct tcf_police *p) 108static void tcf_police_destroy(struct tcf_police *p)
115{ 109{
116 unsigned int h = tcf_hash(p->tcf_index, POL_TAB_MASK); 110 spin_lock_bh(&police_hash_info.lock);
117 struct tcf_common **p1p; 111 hlist_del(&p->tcf_head);
118 112 spin_unlock_bh(&police_hash_info.lock);
119 for (p1p = &tcf_police_ht[h]; *p1p; p1p = &(*p1p)->tcfc_next) { 113 gen_kill_estimator(&p->tcf_bstats,
120 if (*p1p == &p->common) { 114 &p->tcf_rate_est);
121 write_lock_bh(&police_lock); 115 /*
122 *p1p = p->tcf_next; 116 * gen_estimator est_timer() might access p->tcf_lock
123 write_unlock_bh(&police_lock); 117 * or bstats, wait a RCU grace period before freeing p
124 gen_kill_estimator(&p->tcf_bstats, 118 */
125 &p->tcf_rate_est); 119 kfree_rcu(p, tcf_rcu);
126 /*
127 * gen_estimator est_timer() might access p->tcf_lock
128 * or bstats, wait a RCU grace period before freeing p
129 */
130 kfree_rcu(p, tcf_rcu);
131 return;
132 }
133 }
134 WARN_ON(1);
135} 120}
136 121
137static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = { 122static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = {
@@ -266,10 +251,9 @@ override:
266 police->tcf_index = parm->index ? parm->index : 251 police->tcf_index = parm->index ? parm->index :
267 tcf_hash_new_index(&police_idx_gen, &police_hash_info); 252 tcf_hash_new_index(&police_idx_gen, &police_hash_info);
268 h = tcf_hash(police->tcf_index, POL_TAB_MASK); 253 h = tcf_hash(police->tcf_index, POL_TAB_MASK);
269 write_lock_bh(&police_lock); 254 spin_lock_bh(&police_hash_info.lock);
270 police->tcf_next = tcf_police_ht[h]; 255 hlist_add_head(&police->tcf_head, &police_hash_info.htab[h]);
271 tcf_police_ht[h] = &police->common; 256 spin_unlock_bh(&police_hash_info.lock);
272 write_unlock_bh(&police_lock);
273 257
274 a->priv = police; 258 a->priv = police;
275 return ret; 259 return ret;
@@ -277,10 +261,8 @@ override:
277failure_unlock: 261failure_unlock:
278 spin_unlock_bh(&police->tcf_lock); 262 spin_unlock_bh(&police->tcf_lock);
279failure: 263failure:
280 if (P_tab) 264 qdisc_put_rtab(P_tab);
281 qdisc_put_rtab(P_tab); 265 qdisc_put_rtab(R_tab);
282 if (R_tab)
283 qdisc_put_rtab(R_tab);
284 if (ret == ACT_P_CREATED) 266 if (ret == ACT_P_CREATED)
285 kfree(police); 267 kfree(police);
286 return err; 268 return err;
@@ -407,7 +389,6 @@ static struct tc_action_ops act_police_ops = {
407 .act = tcf_act_police, 389 .act = tcf_act_police,
408 .dump = tcf_act_police_dump, 390 .dump = tcf_act_police_dump,
409 .cleanup = tcf_act_police_cleanup, 391 .cleanup = tcf_act_police_cleanup,
410 .lookup = tcf_hash_search,
411 .init = tcf_act_police_locate, 392 .init = tcf_act_police_locate,
412 .walk = tcf_act_police_walker 393 .walk = tcf_act_police_walker
413}; 394};
@@ -415,12 +396,19 @@ static struct tc_action_ops act_police_ops = {
415static int __init 396static int __init
416police_init_module(void) 397police_init_module(void)
417{ 398{
418 return tcf_register_action(&act_police_ops); 399 int err = tcf_hashinfo_init(&police_hash_info, POL_TAB_MASK);
400 if (err)
401 return err;
402 err = tcf_register_action(&act_police_ops);
403 if (err)
404 tcf_hashinfo_destroy(&police_hash_info);
405 return err;
419} 406}
420 407
421static void __exit 408static void __exit
422police_cleanup_module(void) 409police_cleanup_module(void)
423{ 410{
411 tcf_hashinfo_destroy(&police_hash_info);
424 tcf_unregister_action(&act_police_ops); 412 tcf_unregister_action(&act_police_ops);
425} 413}
426 414
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index 7725eb4ab756..81aebc162e5c 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -25,15 +25,8 @@
25#include <net/tc_act/tc_defact.h> 25#include <net/tc_act/tc_defact.h>
26 26
27#define SIMP_TAB_MASK 7 27#define SIMP_TAB_MASK 7
28static struct tcf_common *tcf_simp_ht[SIMP_TAB_MASK + 1];
29static u32 simp_idx_gen; 28static u32 simp_idx_gen;
30static DEFINE_RWLOCK(simp_lock); 29static struct tcf_hashinfo simp_hash_info;
31
32static struct tcf_hashinfo simp_hash_info = {
33 .htab = tcf_simp_ht,
34 .hmask = SIMP_TAB_MASK,
35 .lock = &simp_lock,
36};
37 30
38#define SIMP_MAX_DATA 32 31#define SIMP_MAX_DATA 32
39static int tcf_simp(struct sk_buff *skb, const struct tc_action *a, 32static int tcf_simp(struct sk_buff *skb, const struct tc_action *a,
@@ -201,7 +194,6 @@ static struct tc_action_ops act_simp_ops = {
201 .dump = tcf_simp_dump, 194 .dump = tcf_simp_dump,
202 .cleanup = tcf_simp_cleanup, 195 .cleanup = tcf_simp_cleanup,
203 .init = tcf_simp_init, 196 .init = tcf_simp_init,
204 .walk = tcf_generic_walker,
205}; 197};
206 198
207MODULE_AUTHOR("Jamal Hadi Salim(2005)"); 199MODULE_AUTHOR("Jamal Hadi Salim(2005)");
@@ -210,14 +202,23 @@ MODULE_LICENSE("GPL");
210 202
211static int __init simp_init_module(void) 203static int __init simp_init_module(void)
212{ 204{
213 int ret = tcf_register_action(&act_simp_ops); 205 int err, ret;
206 err = tcf_hashinfo_init(&simp_hash_info, SIMP_TAB_MASK);
207 if (err)
208 return err;
209
210 ret = tcf_register_action(&act_simp_ops);
214 if (!ret) 211 if (!ret)
215 pr_info("Simple TC action Loaded\n"); 212 pr_info("Simple TC action Loaded\n");
213 else
214 tcf_hashinfo_destroy(&simp_hash_info);
215
216 return ret; 216 return ret;
217} 217}
218 218
219static void __exit simp_cleanup_module(void) 219static void __exit simp_cleanup_module(void)
220{ 220{
221 tcf_hashinfo_destroy(&simp_hash_info);
221 tcf_unregister_action(&act_simp_ops); 222 tcf_unregister_action(&act_simp_ops);
222} 223}
223 224
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index cb4221171f93..aa0a4c056f31 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -11,8 +11,7 @@
11 * more details. 11 * more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along with 13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 14 * this program; if not, see <http://www.gnu.org/licenses/>.
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 * 15 *
17 * Author: Alexander Duyck <alexander.h.duyck@intel.com> 16 * Author: Alexander Duyck <alexander.h.duyck@intel.com>
18 */ 17 */
@@ -29,15 +28,8 @@
29#include <net/tc_act/tc_skbedit.h> 28#include <net/tc_act/tc_skbedit.h>
30 29
31#define SKBEDIT_TAB_MASK 15 30#define SKBEDIT_TAB_MASK 15
32static struct tcf_common *tcf_skbedit_ht[SKBEDIT_TAB_MASK + 1];
33static u32 skbedit_idx_gen; 31static u32 skbedit_idx_gen;
34static DEFINE_RWLOCK(skbedit_lock); 32static struct tcf_hashinfo skbedit_hash_info;
35
36static struct tcf_hashinfo skbedit_hash_info = {
37 .htab = tcf_skbedit_ht,
38 .hmask = SKBEDIT_TAB_MASK,
39 .lock = &skbedit_lock,
40};
41 33
42static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a, 34static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a,
43 struct tcf_result *res) 35 struct tcf_result *res)
@@ -203,7 +195,6 @@ static struct tc_action_ops act_skbedit_ops = {
203 .dump = tcf_skbedit_dump, 195 .dump = tcf_skbedit_dump,
204 .cleanup = tcf_skbedit_cleanup, 196 .cleanup = tcf_skbedit_cleanup,
205 .init = tcf_skbedit_init, 197 .init = tcf_skbedit_init,
206 .walk = tcf_generic_walker,
207}; 198};
208 199
209MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>"); 200MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>");
@@ -212,11 +203,15 @@ MODULE_LICENSE("GPL");
212 203
213static int __init skbedit_init_module(void) 204static int __init skbedit_init_module(void)
214{ 205{
206 int err = tcf_hashinfo_init(&skbedit_hash_info, SKBEDIT_TAB_MASK);
207 if (err)
208 return err;
215 return tcf_register_action(&act_skbedit_ops); 209 return tcf_register_action(&act_skbedit_ops);
216} 210}
217 211
218static void __exit skbedit_cleanup_module(void) 212static void __exit skbedit_cleanup_module(void)
219{ 213{
214 tcf_hashinfo_destroy(&skbedit_hash_info);
220 tcf_unregister_action(&act_skbedit_ops); 215 tcf_unregister_action(&act_skbedit_ops);
221} 216}
222 217
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 8e118af90973..12e882ef596b 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -31,8 +31,7 @@
31#include <net/pkt_cls.h> 31#include <net/pkt_cls.h>
32 32
33/* The list of all installed classifier types */ 33/* The list of all installed classifier types */
34 34static LIST_HEAD(tcf_proto_base);
35static struct tcf_proto_ops *tcf_proto_base __read_mostly;
36 35
37/* Protects list of registered TC modules. It is pure SMP lock. */ 36/* Protects list of registered TC modules. It is pure SMP lock. */
38static DEFINE_RWLOCK(cls_mod_lock); 37static DEFINE_RWLOCK(cls_mod_lock);
@@ -41,36 +40,35 @@ static DEFINE_RWLOCK(cls_mod_lock);
41 40
42static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind) 41static const struct tcf_proto_ops *tcf_proto_lookup_ops(struct nlattr *kind)
43{ 42{
44 const struct tcf_proto_ops *t = NULL; 43 const struct tcf_proto_ops *t, *res = NULL;
45 44
46 if (kind) { 45 if (kind) {
47 read_lock(&cls_mod_lock); 46 read_lock(&cls_mod_lock);
48 for (t = tcf_proto_base; t; t = t->next) { 47 list_for_each_entry(t, &tcf_proto_base, head) {
49 if (nla_strcmp(kind, t->kind) == 0) { 48 if (nla_strcmp(kind, t->kind) == 0) {
50 if (!try_module_get(t->owner)) 49 if (try_module_get(t->owner))
51 t = NULL; 50 res = t;
52 break; 51 break;
53 } 52 }
54 } 53 }
55 read_unlock(&cls_mod_lock); 54 read_unlock(&cls_mod_lock);
56 } 55 }
57 return t; 56 return res;
58} 57}
59 58
60/* Register(unregister) new classifier type */ 59/* Register(unregister) new classifier type */
61 60
62int register_tcf_proto_ops(struct tcf_proto_ops *ops) 61int register_tcf_proto_ops(struct tcf_proto_ops *ops)
63{ 62{
64 struct tcf_proto_ops *t, **tp; 63 struct tcf_proto_ops *t;
65 int rc = -EEXIST; 64 int rc = -EEXIST;
66 65
67 write_lock(&cls_mod_lock); 66 write_lock(&cls_mod_lock);
68 for (tp = &tcf_proto_base; (t = *tp) != NULL; tp = &t->next) 67 list_for_each_entry(t, &tcf_proto_base, head)
69 if (!strcmp(ops->kind, t->kind)) 68 if (!strcmp(ops->kind, t->kind))
70 goto out; 69 goto out;
71 70
72 ops->next = NULL; 71 list_add_tail(&ops->head, &tcf_proto_base);
73 *tp = ops;
74 rc = 0; 72 rc = 0;
75out: 73out:
76 write_unlock(&cls_mod_lock); 74 write_unlock(&cls_mod_lock);
@@ -80,19 +78,17 @@ EXPORT_SYMBOL(register_tcf_proto_ops);
80 78
81int unregister_tcf_proto_ops(struct tcf_proto_ops *ops) 79int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
82{ 80{
83 struct tcf_proto_ops *t, **tp; 81 struct tcf_proto_ops *t;
84 int rc = -ENOENT; 82 int rc = -ENOENT;
85 83
86 write_lock(&cls_mod_lock); 84 write_lock(&cls_mod_lock);
87 for (tp = &tcf_proto_base; (t = *tp) != NULL; tp = &t->next) 85 list_for_each_entry(t, &tcf_proto_base, head) {
88 if (t == ops) 86 if (t == ops) {
87 list_del(&t->head);
88 rc = 0;
89 break; 89 break;
90 90 }
91 if (!t) 91 }
92 goto out;
93 *tp = t->next;
94 rc = 0;
95out:
96 write_unlock(&cls_mod_lock); 92 write_unlock(&cls_mod_lock);
97 return rc; 93 return rc;
98} 94}
@@ -500,46 +496,41 @@ out:
500void tcf_exts_destroy(struct tcf_proto *tp, struct tcf_exts *exts) 496void tcf_exts_destroy(struct tcf_proto *tp, struct tcf_exts *exts)
501{ 497{
502#ifdef CONFIG_NET_CLS_ACT 498#ifdef CONFIG_NET_CLS_ACT
503 if (exts->action) { 499 tcf_action_destroy(&exts->actions, TCA_ACT_UNBIND);
504 tcf_action_destroy(exts->action, TCA_ACT_UNBIND); 500 INIT_LIST_HEAD(&exts->actions);
505 exts->action = NULL;
506 }
507#endif 501#endif
508} 502}
509EXPORT_SYMBOL(tcf_exts_destroy); 503EXPORT_SYMBOL(tcf_exts_destroy);
510 504
511int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, 505int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
512 struct nlattr *rate_tlv, struct tcf_exts *exts, 506 struct nlattr *rate_tlv, struct tcf_exts *exts)
513 const struct tcf_ext_map *map)
514{ 507{
515 memset(exts, 0, sizeof(*exts));
516
517#ifdef CONFIG_NET_CLS_ACT 508#ifdef CONFIG_NET_CLS_ACT
518 { 509 {
519 struct tc_action *act; 510 struct tc_action *act;
520 511
521 if (map->police && tb[map->police]) { 512 INIT_LIST_HEAD(&exts->actions);
522 act = tcf_action_init_1(net, tb[map->police], rate_tlv, 513 if (exts->police && tb[exts->police]) {
514 act = tcf_action_init_1(net, tb[exts->police], rate_tlv,
523 "police", TCA_ACT_NOREPLACE, 515 "police", TCA_ACT_NOREPLACE,
524 TCA_ACT_BIND); 516 TCA_ACT_BIND);
525 if (IS_ERR(act)) 517 if (IS_ERR(act))
526 return PTR_ERR(act); 518 return PTR_ERR(act);
527 519
528 act->type = TCA_OLD_COMPAT; 520 act->type = exts->type = TCA_OLD_COMPAT;
529 exts->action = act; 521 list_add(&act->list, &exts->actions);
530 } else if (map->action && tb[map->action]) { 522 } else if (exts->action && tb[exts->action]) {
531 act = tcf_action_init(net, tb[map->action], rate_tlv, 523 int err;
524 err = tcf_action_init(net, tb[exts->action], rate_tlv,
532 NULL, TCA_ACT_NOREPLACE, 525 NULL, TCA_ACT_NOREPLACE,
533 TCA_ACT_BIND); 526 TCA_ACT_BIND, &exts->actions);
534 if (IS_ERR(act)) 527 if (err)
535 return PTR_ERR(act); 528 return err;
536
537 exts->action = act;
538 } 529 }
539 } 530 }
540#else 531#else
541 if ((map->action && tb[map->action]) || 532 if ((exts->action && tb[exts->action]) ||
542 (map->police && tb[map->police])) 533 (exts->police && tb[exts->police]))
543 return -EOPNOTSUPP; 534 return -EOPNOTSUPP;
544#endif 535#endif
545 536
@@ -551,43 +542,44 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
551 struct tcf_exts *src) 542 struct tcf_exts *src)
552{ 543{
553#ifdef CONFIG_NET_CLS_ACT 544#ifdef CONFIG_NET_CLS_ACT
554 if (src->action) { 545 if (!list_empty(&src->actions)) {
555 struct tc_action *act; 546 LIST_HEAD(tmp);
556 tcf_tree_lock(tp); 547 tcf_tree_lock(tp);
557 act = dst->action; 548 list_splice_init(&dst->actions, &tmp);
558 dst->action = src->action; 549 list_splice(&src->actions, &dst->actions);
559 tcf_tree_unlock(tp); 550 tcf_tree_unlock(tp);
560 if (act) 551 tcf_action_destroy(&tmp, TCA_ACT_UNBIND);
561 tcf_action_destroy(act, TCA_ACT_UNBIND);
562 } 552 }
563#endif 553#endif
564} 554}
565EXPORT_SYMBOL(tcf_exts_change); 555EXPORT_SYMBOL(tcf_exts_change);
566 556
567int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts, 557#define tcf_exts_first_act(ext) \
568 const struct tcf_ext_map *map) 558 list_first_entry(&(exts)->actions, struct tc_action, list)
559
560int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
569{ 561{
570#ifdef CONFIG_NET_CLS_ACT 562#ifdef CONFIG_NET_CLS_ACT
571 if (map->action && exts->action) { 563 if (exts->action && !list_empty(&exts->actions)) {
572 /* 564 /*
573 * again for backward compatible mode - we want 565 * again for backward compatible mode - we want
574 * to work with both old and new modes of entering 566 * to work with both old and new modes of entering
575 * tc data even if iproute2 was newer - jhs 567 * tc data even if iproute2 was newer - jhs
576 */ 568 */
577 struct nlattr *nest; 569 struct nlattr *nest;
578 570 if (exts->type != TCA_OLD_COMPAT) {
579 if (exts->action->type != TCA_OLD_COMPAT) { 571 nest = nla_nest_start(skb, exts->action);
580 nest = nla_nest_start(skb, map->action);
581 if (nest == NULL) 572 if (nest == NULL)
582 goto nla_put_failure; 573 goto nla_put_failure;
583 if (tcf_action_dump(skb, exts->action, 0, 0) < 0) 574 if (tcf_action_dump(skb, &exts->actions, 0, 0) < 0)
584 goto nla_put_failure; 575 goto nla_put_failure;
585 nla_nest_end(skb, nest); 576 nla_nest_end(skb, nest);
586 } else if (map->police) { 577 } else if (exts->police) {
587 nest = nla_nest_start(skb, map->police); 578 struct tc_action *act = tcf_exts_first_act(exts);
579 nest = nla_nest_start(skb, exts->police);
588 if (nest == NULL) 580 if (nest == NULL)
589 goto nla_put_failure; 581 goto nla_put_failure;
590 if (tcf_action_dump_old(skb, exts->action, 0, 0) < 0) 582 if (tcf_action_dump_old(skb, act, 0, 0) < 0)
591 goto nla_put_failure; 583 goto nla_put_failure;
592 nla_nest_end(skb, nest); 584 nla_nest_end(skb, nest);
593 } 585 }
@@ -600,17 +592,14 @@ nla_put_failure: __attribute__ ((unused))
600EXPORT_SYMBOL(tcf_exts_dump); 592EXPORT_SYMBOL(tcf_exts_dump);
601 593
602 594
603int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts, 595int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
604 const struct tcf_ext_map *map)
605{ 596{
606#ifdef CONFIG_NET_CLS_ACT 597#ifdef CONFIG_NET_CLS_ACT
607 if (exts->action) 598 struct tc_action *a = tcf_exts_first_act(exts);
608 if (tcf_action_copy_stats(skb, exts->action, 1) < 0) 599 if (tcf_action_copy_stats(skb, a, 1) < 0)
609 goto nla_put_failure; 600 return -1;
610#endif 601#endif
611 return 0; 602 return 0;
612nla_put_failure: __attribute__ ((unused))
613 return -1;
614} 603}
615EXPORT_SYMBOL(tcf_exts_dump_stats); 604EXPORT_SYMBOL(tcf_exts_dump_stats);
616 605
diff --git a/net/sched/cls_basic.c b/net/sched/cls_basic.c
index 636d9131d870..b6552035d1f4 100644
--- a/net/sched/cls_basic.c
+++ b/net/sched/cls_basic.c
@@ -34,11 +34,6 @@ struct basic_filter {
34 struct list_head link; 34 struct list_head link;
35}; 35};
36 36
37static const struct tcf_ext_map basic_ext_map = {
38 .action = TCA_BASIC_ACT,
39 .police = TCA_BASIC_POLICE
40};
41
42static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp, 37static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp,
43 struct tcf_result *res) 38 struct tcf_result *res)
44{ 39{
@@ -141,7 +136,8 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,
141 struct tcf_exts e; 136 struct tcf_exts e;
142 struct tcf_ematch_tree t; 137 struct tcf_ematch_tree t;
143 138
144 err = tcf_exts_validate(net, tp, tb, est, &e, &basic_ext_map); 139 tcf_exts_init(&e, TCA_BASIC_ACT, TCA_BASIC_POLICE);
140 err = tcf_exts_validate(net, tp, tb, est, &e);
145 if (err < 0) 141 if (err < 0)
146 return err; 142 return err;
147 143
@@ -191,6 +187,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
191 if (f == NULL) 187 if (f == NULL)
192 goto errout; 188 goto errout;
193 189
190 tcf_exts_init(&f->exts, TCA_BASIC_ACT, TCA_BASIC_POLICE);
194 err = -EINVAL; 191 err = -EINVAL;
195 if (handle) 192 if (handle)
196 f->handle = handle; 193 f->handle = handle;
@@ -263,13 +260,13 @@ static int basic_dump(struct tcf_proto *tp, unsigned long fh,
263 nla_put_u32(skb, TCA_BASIC_CLASSID, f->res.classid)) 260 nla_put_u32(skb, TCA_BASIC_CLASSID, f->res.classid))
264 goto nla_put_failure; 261 goto nla_put_failure;
265 262
266 if (tcf_exts_dump(skb, &f->exts, &basic_ext_map) < 0 || 263 if (tcf_exts_dump(skb, &f->exts) < 0 ||
267 tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0) 264 tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0)
268 goto nla_put_failure; 265 goto nla_put_failure;
269 266
270 nla_nest_end(skb, nest); 267 nla_nest_end(skb, nest);
271 268
272 if (tcf_exts_dump_stats(skb, &f->exts, &basic_ext_map) < 0) 269 if (tcf_exts_dump_stats(skb, &f->exts) < 0)
273 goto nla_put_failure; 270 goto nla_put_failure;
274 271
275 return skb->len; 272 return skb->len;
diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
index 1002a8226281..00a5a585e5f1 100644
--- a/net/sched/cls_bpf.c
+++ b/net/sched/cls_bpf.c
@@ -46,11 +46,6 @@ static const struct nla_policy bpf_policy[TCA_BPF_MAX + 1] = {
46 .len = sizeof(struct sock_filter) * BPF_MAXINSNS }, 46 .len = sizeof(struct sock_filter) * BPF_MAXINSNS },
47}; 47};
48 48
49static const struct tcf_ext_map bpf_ext_map = {
50 .action = TCA_BPF_ACT,
51 .police = TCA_BPF_POLICE,
52};
53
54static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp, 49static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
55 struct tcf_result *res) 50 struct tcf_result *res)
56{ 51{
@@ -174,7 +169,8 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
174 if (!tb[TCA_BPF_OPS_LEN] || !tb[TCA_BPF_OPS] || !tb[TCA_BPF_CLASSID]) 169 if (!tb[TCA_BPF_OPS_LEN] || !tb[TCA_BPF_OPS] || !tb[TCA_BPF_CLASSID])
175 return -EINVAL; 170 return -EINVAL;
176 171
177 ret = tcf_exts_validate(net, tp, tb, est, &exts, &bpf_ext_map); 172 tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE);
173 ret = tcf_exts_validate(net, tp, tb, est, &exts);
178 if (ret < 0) 174 if (ret < 0)
179 return ret; 175 return ret;
180 176
@@ -271,6 +267,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
271 if (prog == NULL) 267 if (prog == NULL)
272 return -ENOBUFS; 268 return -ENOBUFS;
273 269
270 tcf_exts_init(&prog->exts, TCA_BPF_ACT, TCA_BPF_POLICE);
274 if (handle == 0) 271 if (handle == 0)
275 prog->handle = cls_bpf_grab_new_handle(tp, head); 272 prog->handle = cls_bpf_grab_new_handle(tp, head);
276 else 273 else
@@ -323,14 +320,14 @@ static int cls_bpf_dump(struct tcf_proto *tp, unsigned long fh,
323 if (nla == NULL) 320 if (nla == NULL)
324 goto nla_put_failure; 321 goto nla_put_failure;
325 322
326 memcpy(nla_data(nla), prog->bpf_ops, nla_len(nla)); 323 memcpy(nla_data(nla), prog->bpf_ops, nla_len(nla));
327 324
328 if (tcf_exts_dump(skb, &prog->exts, &bpf_ext_map) < 0) 325 if (tcf_exts_dump(skb, &prog->exts) < 0)
329 goto nla_put_failure; 326 goto nla_put_failure;
330 327
331 nla_nest_end(skb, nest); 328 nla_nest_end(skb, nest);
332 329
333 if (tcf_exts_dump_stats(skb, &prog->exts, &bpf_ext_map) < 0) 330 if (tcf_exts_dump_stats(skb, &prog->exts) < 0)
334 goto nla_put_failure; 331 goto nla_put_failure;
335 332
336 return skb->len; 333 return skb->len;
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 16006c92c3fd..f9d212583ea2 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -172,11 +172,6 @@ static int cls_cgroup_init(struct tcf_proto *tp)
172 return 0; 172 return 0;
173} 173}
174 174
175static const struct tcf_ext_map cgroup_ext_map = {
176 .action = TCA_CGROUP_ACT,
177 .police = TCA_CGROUP_POLICE,
178};
179
180static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = { 175static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = {
181 [TCA_CGROUP_EMATCHES] = { .type = NLA_NESTED }, 176 [TCA_CGROUP_EMATCHES] = { .type = NLA_NESTED },
182}; 177};
@@ -203,6 +198,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
203 if (head == NULL) 198 if (head == NULL)
204 return -ENOBUFS; 199 return -ENOBUFS;
205 200
201 tcf_exts_init(&head->exts, TCA_CGROUP_ACT, TCA_CGROUP_POLICE);
206 head->handle = handle; 202 head->handle = handle;
207 203
208 tcf_tree_lock(tp); 204 tcf_tree_lock(tp);
@@ -218,8 +214,8 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
218 if (err < 0) 214 if (err < 0)
219 return err; 215 return err;
220 216
221 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, 217 tcf_exts_init(&e, TCA_CGROUP_ACT, TCA_CGROUP_POLICE);
222 &cgroup_ext_map); 218 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e);
223 if (err < 0) 219 if (err < 0)
224 return err; 220 return err;
225 221
@@ -277,13 +273,13 @@ static int cls_cgroup_dump(struct tcf_proto *tp, unsigned long fh,
277 if (nest == NULL) 273 if (nest == NULL)
278 goto nla_put_failure; 274 goto nla_put_failure;
279 275
280 if (tcf_exts_dump(skb, &head->exts, &cgroup_ext_map) < 0 || 276 if (tcf_exts_dump(skb, &head->exts) < 0 ||
281 tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0) 277 tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0)
282 goto nla_put_failure; 278 goto nla_put_failure;
283 279
284 nla_nest_end(skb, nest); 280 nla_nest_end(skb, nest);
285 281
286 if (tcf_exts_dump_stats(skb, &head->exts, &cgroup_ext_map) < 0) 282 if (tcf_exts_dump_stats(skb, &head->exts) < 0)
287 goto nla_put_failure; 283 goto nla_put_failure;
288 284
289 return skb->len; 285 return skb->len;
diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c
index 7881e2fccbc2..dfd18a5c3e81 100644
--- a/net/sched/cls_flow.c
+++ b/net/sched/cls_flow.c
@@ -56,11 +56,6 @@ struct flow_filter {
56 u32 hashrnd; 56 u32 hashrnd;
57}; 57};
58 58
59static const struct tcf_ext_map flow_ext_map = {
60 .action = TCA_FLOW_ACT,
61 .police = TCA_FLOW_POLICE,
62};
63
64static inline u32 addr_fold(void *addr) 59static inline u32 addr_fold(void *addr)
65{ 60{
66 unsigned long a = (unsigned long)addr; 61 unsigned long a = (unsigned long)addr;
@@ -220,7 +215,7 @@ static u32 flow_get_vlan_tag(const struct sk_buff *skb)
220 215
221static u32 flow_get_rxhash(struct sk_buff *skb) 216static u32 flow_get_rxhash(struct sk_buff *skb)
222{ 217{
223 return skb_get_rxhash(skb); 218 return skb_get_hash(skb);
224} 219}
225 220
226static u32 flow_key_get(struct sk_buff *skb, int key, struct flow_keys *flow) 221static u32 flow_key_get(struct sk_buff *skb, int key, struct flow_keys *flow)
@@ -397,7 +392,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
397 return -EOPNOTSUPP; 392 return -EOPNOTSUPP;
398 } 393 }
399 394
400 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, &flow_ext_map); 395 tcf_exts_init(&e, TCA_FLOW_ACT, TCA_FLOW_POLICE);
396 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e);
401 if (err < 0) 397 if (err < 0)
402 return err; 398 return err;
403 399
@@ -455,6 +451,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
455 451
456 f->handle = handle; 452 f->handle = handle;
457 f->mask = ~0U; 453 f->mask = ~0U;
454 tcf_exts_init(&f->exts, TCA_FLOW_ACT, TCA_FLOW_POLICE);
458 455
459 get_random_bytes(&f->hashrnd, 4); 456 get_random_bytes(&f->hashrnd, 4);
460 f->perturb_timer.function = flow_perturbation; 457 f->perturb_timer.function = flow_perturbation;
@@ -608,7 +605,7 @@ static int flow_dump(struct tcf_proto *tp, unsigned long fh,
608 nla_put_u32(skb, TCA_FLOW_PERTURB, f->perturb_period / HZ)) 605 nla_put_u32(skb, TCA_FLOW_PERTURB, f->perturb_period / HZ))
609 goto nla_put_failure; 606 goto nla_put_failure;
610 607
611 if (tcf_exts_dump(skb, &f->exts, &flow_ext_map) < 0) 608 if (tcf_exts_dump(skb, &f->exts) < 0)
612 goto nla_put_failure; 609 goto nla_put_failure;
613#ifdef CONFIG_NET_EMATCH 610#ifdef CONFIG_NET_EMATCH
614 if (f->ematches.hdr.nmatches && 611 if (f->ematches.hdr.nmatches &&
@@ -617,7 +614,7 @@ static int flow_dump(struct tcf_proto *tp, unsigned long fh,
617#endif 614#endif
618 nla_nest_end(skb, nest); 615 nla_nest_end(skb, nest);
619 616
620 if (tcf_exts_dump_stats(skb, &f->exts, &flow_ext_map) < 0) 617 if (tcf_exts_dump_stats(skb, &f->exts) < 0)
621 goto nla_put_failure; 618 goto nla_put_failure;
622 619
623 return skb->len; 620 return skb->len;
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index 9b97172db84a..3f9cece13807 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -46,11 +46,6 @@ struct fw_filter {
46 struct tcf_exts exts; 46 struct tcf_exts exts;
47}; 47};
48 48
49static const struct tcf_ext_map fw_ext_map = {
50 .action = TCA_FW_ACT,
51 .police = TCA_FW_POLICE
52};
53
54static inline int fw_hash(u32 handle) 49static inline int fw_hash(u32 handle)
55{ 50{
56 if (HTSIZE == 4096) 51 if (HTSIZE == 4096)
@@ -200,7 +195,8 @@ fw_change_attrs(struct net *net, struct tcf_proto *tp, struct fw_filter *f,
200 u32 mask; 195 u32 mask;
201 int err; 196 int err;
202 197
203 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, &fw_ext_map); 198 tcf_exts_init(&e, TCA_FW_ACT, TCA_FW_POLICE);
199 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e);
204 if (err < 0) 200 if (err < 0)
205 return err; 201 return err;
206 202
@@ -280,6 +276,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
280 if (f == NULL) 276 if (f == NULL)
281 return -ENOBUFS; 277 return -ENOBUFS;
282 278
279 tcf_exts_init(&f->exts, TCA_FW_ACT, TCA_FW_POLICE);
283 f->id = handle; 280 f->id = handle;
284 281
285 err = fw_change_attrs(net, tp, f, tb, tca, base); 282 err = fw_change_attrs(net, tp, f, tb, tca, base);
@@ -359,12 +356,12 @@ static int fw_dump(struct tcf_proto *tp, unsigned long fh,
359 nla_put_u32(skb, TCA_FW_MASK, head->mask)) 356 nla_put_u32(skb, TCA_FW_MASK, head->mask))
360 goto nla_put_failure; 357 goto nla_put_failure;
361 358
362 if (tcf_exts_dump(skb, &f->exts, &fw_ext_map) < 0) 359 if (tcf_exts_dump(skb, &f->exts) < 0)
363 goto nla_put_failure; 360 goto nla_put_failure;
364 361
365 nla_nest_end(skb, nest); 362 nla_nest_end(skb, nest);
366 363
367 if (tcf_exts_dump_stats(skb, &f->exts, &fw_ext_map) < 0) 364 if (tcf_exts_dump_stats(skb, &f->exts) < 0)
368 goto nla_put_failure; 365 goto nla_put_failure;
369 366
370 return skb->len; 367 return skb->len;
diff --git a/net/sched/cls_route.c b/net/sched/cls_route.c
index 37da567d833e..2473953a5948 100644
--- a/net/sched/cls_route.c
+++ b/net/sched/cls_route.c
@@ -59,11 +59,6 @@ struct route4_filter {
59 59
60#define ROUTE4_FAILURE ((struct route4_filter *)(-1L)) 60#define ROUTE4_FAILURE ((struct route4_filter *)(-1L))
61 61
62static const struct tcf_ext_map route_ext_map = {
63 .police = TCA_ROUTE4_POLICE,
64 .action = TCA_ROUTE4_ACT
65};
66
67static inline int route4_fastmap_hash(u32 id, int iif) 62static inline int route4_fastmap_hash(u32 id, int iif)
68{ 63{
69 return id & 0xF; 64 return id & 0xF;
@@ -347,7 +342,8 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
347 struct route4_bucket *b; 342 struct route4_bucket *b;
348 struct tcf_exts e; 343 struct tcf_exts e;
349 344
350 err = tcf_exts_validate(net, tp, tb, est, &e, &route_ext_map); 345 tcf_exts_init(&e, TCA_ROUTE4_ACT, TCA_ROUTE4_POLICE);
346 err = tcf_exts_validate(net, tp, tb, est, &e);
351 if (err < 0) 347 if (err < 0)
352 return err; 348 return err;
353 349
@@ -481,6 +477,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
481 if (f == NULL) 477 if (f == NULL)
482 goto errout; 478 goto errout;
483 479
480 tcf_exts_init(&f->exts, TCA_ROUTE4_ACT, TCA_ROUTE4_POLICE);
484 err = route4_set_parms(net, tp, base, f, handle, head, tb, 481 err = route4_set_parms(net, tp, base, f, handle, head, tb,
485 tca[TCA_RATE], 1); 482 tca[TCA_RATE], 1);
486 if (err < 0) 483 if (err < 0)
@@ -589,12 +586,12 @@ static int route4_dump(struct tcf_proto *tp, unsigned long fh,
589 nla_put_u32(skb, TCA_ROUTE4_CLASSID, f->res.classid)) 586 nla_put_u32(skb, TCA_ROUTE4_CLASSID, f->res.classid))
590 goto nla_put_failure; 587 goto nla_put_failure;
591 588
592 if (tcf_exts_dump(skb, &f->exts, &route_ext_map) < 0) 589 if (tcf_exts_dump(skb, &f->exts) < 0)
593 goto nla_put_failure; 590 goto nla_put_failure;
594 591
595 nla_nest_end(skb, nest); 592 nla_nest_end(skb, nest);
596 593
597 if (tcf_exts_dump_stats(skb, &f->exts, &route_ext_map) < 0) 594 if (tcf_exts_dump_stats(skb, &f->exts) < 0)
598 goto nla_put_failure; 595 goto nla_put_failure;
599 596
600 return skb->len; 597 return skb->len;
diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h
index 252d8b05872e..4f25c2ac825b 100644
--- a/net/sched/cls_rsvp.h
+++ b/net/sched/cls_rsvp.h
@@ -116,11 +116,6 @@ static inline unsigned int hash_src(__be32 *src)
116 return h & 0xF; 116 return h & 0xF;
117} 117}
118 118
119static struct tcf_ext_map rsvp_ext_map = {
120 .police = TCA_RSVP_POLICE,
121 .action = TCA_RSVP_ACT
122};
123
124#define RSVP_APPLY_RESULT() \ 119#define RSVP_APPLY_RESULT() \
125{ \ 120{ \
126 int r = tcf_exts_exec(skb, &f->exts, res); \ 121 int r = tcf_exts_exec(skb, &f->exts, res); \
@@ -440,7 +435,8 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
440 if (err < 0) 435 if (err < 0)
441 return err; 436 return err;
442 437
443 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, &rsvp_ext_map); 438 tcf_exts_init(&e, TCA_RSVP_ACT, TCA_RSVP_POLICE);
439 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e);
444 if (err < 0) 440 if (err < 0)
445 return err; 441 return err;
446 442
@@ -471,6 +467,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
471 if (f == NULL) 467 if (f == NULL)
472 goto errout2; 468 goto errout2;
473 469
470 tcf_exts_init(&f->exts, TCA_RSVP_ACT, TCA_RSVP_POLICE);
474 h2 = 16; 471 h2 = 16;
475 if (tb[TCA_RSVP_SRC]) { 472 if (tb[TCA_RSVP_SRC]) {
476 memcpy(f->src, nla_data(tb[TCA_RSVP_SRC]), sizeof(f->src)); 473 memcpy(f->src, nla_data(tb[TCA_RSVP_SRC]), sizeof(f->src));
@@ -633,12 +630,12 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh,
633 nla_put(skb, TCA_RSVP_SRC, sizeof(f->src), f->src)) 630 nla_put(skb, TCA_RSVP_SRC, sizeof(f->src), f->src))
634 goto nla_put_failure; 631 goto nla_put_failure;
635 632
636 if (tcf_exts_dump(skb, &f->exts, &rsvp_ext_map) < 0) 633 if (tcf_exts_dump(skb, &f->exts) < 0)
637 goto nla_put_failure; 634 goto nla_put_failure;
638 635
639 nla_nest_end(skb, nest); 636 nla_nest_end(skb, nest);
640 637
641 if (tcf_exts_dump_stats(skb, &f->exts, &rsvp_ext_map) < 0) 638 if (tcf_exts_dump_stats(skb, &f->exts) < 0)
642 goto nla_put_failure; 639 goto nla_put_failure;
643 return skb->len; 640 return skb->len;
644 641
diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c
index b86535a40169..ffad18791c93 100644
--- a/net/sched/cls_tcindex.c
+++ b/net/sched/cls_tcindex.c
@@ -50,11 +50,6 @@ struct tcindex_data {
50 int fall_through; /* 0: only classify if explicit match */ 50 int fall_through; /* 0: only classify if explicit match */
51}; 51};
52 52
53static const struct tcf_ext_map tcindex_ext_map = {
54 .police = TCA_TCINDEX_POLICE,
55 .action = TCA_TCINDEX_ACT
56};
57
58static inline int 53static inline int
59tcindex_filter_is_set(struct tcindex_filter_result *r) 54tcindex_filter_is_set(struct tcindex_filter_result *r)
60{ 55{
@@ -209,17 +204,21 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
209 struct tcindex_filter *f = NULL; /* make gcc behave */ 204 struct tcindex_filter *f = NULL; /* make gcc behave */
210 struct tcf_exts e; 205 struct tcf_exts e;
211 206
212 err = tcf_exts_validate(net, tp, tb, est, &e, &tcindex_ext_map); 207 tcf_exts_init(&e, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
208 err = tcf_exts_validate(net, tp, tb, est, &e);
213 if (err < 0) 209 if (err < 0)
214 return err; 210 return err;
215 211
216 memcpy(&cp, p, sizeof(cp)); 212 memcpy(&cp, p, sizeof(cp));
217 memset(&new_filter_result, 0, sizeof(new_filter_result)); 213 memset(&new_filter_result, 0, sizeof(new_filter_result));
214 tcf_exts_init(&new_filter_result.exts, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
218 215
219 if (old_r) 216 if (old_r)
220 memcpy(&cr, r, sizeof(cr)); 217 memcpy(&cr, r, sizeof(cr));
221 else 218 else {
222 memset(&cr, 0, sizeof(cr)); 219 memset(&cr, 0, sizeof(cr));
220 tcf_exts_init(&cr.exts, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
221 }
223 222
224 if (tb[TCA_TCINDEX_HASH]) 223 if (tb[TCA_TCINDEX_HASH])
225 cp.hash = nla_get_u32(tb[TCA_TCINDEX_HASH]); 224 cp.hash = nla_get_u32(tb[TCA_TCINDEX_HASH]);
@@ -468,11 +467,11 @@ static int tcindex_dump(struct tcf_proto *tp, unsigned long fh,
468 nla_put_u32(skb, TCA_TCINDEX_CLASSID, r->res.classid)) 467 nla_put_u32(skb, TCA_TCINDEX_CLASSID, r->res.classid))
469 goto nla_put_failure; 468 goto nla_put_failure;
470 469
471 if (tcf_exts_dump(skb, &r->exts, &tcindex_ext_map) < 0) 470 if (tcf_exts_dump(skb, &r->exts) < 0)
472 goto nla_put_failure; 471 goto nla_put_failure;
473 nla_nest_end(skb, nest); 472 nla_nest_end(skb, nest);
474 473
475 if (tcf_exts_dump_stats(skb, &r->exts, &tcindex_ext_map) < 0) 474 if (tcf_exts_dump_stats(skb, &r->exts) < 0)
476 goto nla_put_failure; 475 goto nla_put_failure;
477 } 476 }
478 477
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index eb07a1e536e6..20f2fb79c747 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -79,11 +79,6 @@ struct tc_u_common {
79 u32 hgenerator; 79 u32 hgenerator;
80}; 80};
81 81
82static const struct tcf_ext_map u32_ext_map = {
83 .action = TCA_U32_ACT,
84 .police = TCA_U32_POLICE
85};
86
87static inline unsigned int u32_hash_fold(__be32 key, 82static inline unsigned int u32_hash_fold(__be32 key,
88 const struct tc_u32_sel *sel, 83 const struct tc_u32_sel *sel,
89 u8 fshift) 84 u8 fshift)
@@ -352,7 +347,7 @@ static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n)
352 return 0; 347 return 0;
353} 348}
354 349
355static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode* key) 350static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode *key)
356{ 351{
357 struct tc_u_knode **kp; 352 struct tc_u_knode **kp;
358 struct tc_u_hnode *ht = key->ht_up; 353 struct tc_u_hnode *ht = key->ht_up;
@@ -496,7 +491,8 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
496 int err; 491 int err;
497 struct tcf_exts e; 492 struct tcf_exts e;
498 493
499 err = tcf_exts_validate(net, tp, tb, est, &e, &u32_ext_map); 494 tcf_exts_init(&e, TCA_U32_ACT, TCA_U32_POLICE);
495 err = tcf_exts_validate(net, tp, tb, est, &e);
500 if (err < 0) 496 if (err < 0)
501 return err; 497 return err;
502 498
@@ -646,6 +642,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
646 n->ht_up = ht; 642 n->ht_up = ht;
647 n->handle = handle; 643 n->handle = handle;
648 n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0; 644 n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0;
645 tcf_exts_init(&n->exts, TCA_U32_ACT, TCA_U32_POLICE);
649 646
650#ifdef CONFIG_CLS_U32_MARK 647#ifdef CONFIG_CLS_U32_MARK
651 if (tb[TCA_U32_MARK]) { 648 if (tb[TCA_U32_MARK]) {
@@ -759,7 +756,7 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,
759 goto nla_put_failure; 756 goto nla_put_failure;
760#endif 757#endif
761 758
762 if (tcf_exts_dump(skb, &n->exts, &u32_ext_map) < 0) 759 if (tcf_exts_dump(skb, &n->exts) < 0)
763 goto nla_put_failure; 760 goto nla_put_failure;
764 761
765#ifdef CONFIG_NET_CLS_IND 762#ifdef CONFIG_NET_CLS_IND
@@ -778,7 +775,7 @@ static int u32_dump(struct tcf_proto *tp, unsigned long fh,
778 nla_nest_end(skb, nest); 775 nla_nest_end(skb, nest);
779 776
780 if (TC_U32_KEY(n->handle)) 777 if (TC_U32_KEY(n->handle))
781 if (tcf_exts_dump_stats(skb, &n->exts, &u32_ext_map) < 0) 778 if (tcf_exts_dump_stats(skb, &n->exts) < 0)
782 goto nla_put_failure; 779 goto nla_put_failure;
783 return skb->len; 780 return skb->len;
784 781
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
index e5cef9567225..9b8c0b0e60d7 100644
--- a/net/sched/em_meta.c
+++ b/net/sched/em_meta.c
@@ -222,7 +222,7 @@ META_COLLECTOR(int_maclen)
222 222
223META_COLLECTOR(int_rxhash) 223META_COLLECTOR(int_rxhash)
224{ 224{
225 dst->value = skb_get_rxhash(skb); 225 dst->value = skb_get_hash(skb);
226} 226}
227 227
228/************************************************************************** 228/**************************************************************************
@@ -271,40 +271,52 @@ META_COLLECTOR(int_rtiif)
271 * Socket Attributes 271 * Socket Attributes
272 **************************************************************************/ 272 **************************************************************************/
273 273
274#define SKIP_NONLOCAL(skb) \ 274#define skip_nonlocal(skb) \
275 if (unlikely(skb->sk == NULL)) { \ 275 (unlikely(skb->sk == NULL))
276 *err = -1; \
277 return; \
278 }
279 276
280META_COLLECTOR(int_sk_family) 277META_COLLECTOR(int_sk_family)
281{ 278{
282 SKIP_NONLOCAL(skb); 279 if (skip_nonlocal(skb)) {
280 *err = -1;
281 return;
282 }
283 dst->value = skb->sk->sk_family; 283 dst->value = skb->sk->sk_family;
284} 284}
285 285
286META_COLLECTOR(int_sk_state) 286META_COLLECTOR(int_sk_state)
287{ 287{
288 SKIP_NONLOCAL(skb); 288 if (skip_nonlocal(skb)) {
289 *err = -1;
290 return;
291 }
289 dst->value = skb->sk->sk_state; 292 dst->value = skb->sk->sk_state;
290} 293}
291 294
292META_COLLECTOR(int_sk_reuse) 295META_COLLECTOR(int_sk_reuse)
293{ 296{
294 SKIP_NONLOCAL(skb); 297 if (skip_nonlocal(skb)) {
298 *err = -1;
299 return;
300 }
295 dst->value = skb->sk->sk_reuse; 301 dst->value = skb->sk->sk_reuse;
296} 302}
297 303
298META_COLLECTOR(int_sk_bound_if) 304META_COLLECTOR(int_sk_bound_if)
299{ 305{
300 SKIP_NONLOCAL(skb); 306 if (skip_nonlocal(skb)) {
307 *err = -1;
308 return;
309 }
301 /* No error if bound_dev_if is 0, legal userspace check */ 310 /* No error if bound_dev_if is 0, legal userspace check */
302 dst->value = skb->sk->sk_bound_dev_if; 311 dst->value = skb->sk->sk_bound_dev_if;
303} 312}
304 313
305META_COLLECTOR(var_sk_bound_if) 314META_COLLECTOR(var_sk_bound_if)
306{ 315{
307 SKIP_NONLOCAL(skb); 316 if (skip_nonlocal(skb)) {
317 *err = -1;
318 return;
319 }
308 320
309 if (skb->sk->sk_bound_dev_if == 0) { 321 if (skb->sk->sk_bound_dev_if == 0) {
310 dst->value = (unsigned long) "any"; 322 dst->value = (unsigned long) "any";
@@ -322,151 +334,226 @@ META_COLLECTOR(var_sk_bound_if)
322 334
323META_COLLECTOR(int_sk_refcnt) 335META_COLLECTOR(int_sk_refcnt)
324{ 336{
325 SKIP_NONLOCAL(skb); 337 if (skip_nonlocal(skb)) {
338 *err = -1;
339 return;
340 }
326 dst->value = atomic_read(&skb->sk->sk_refcnt); 341 dst->value = atomic_read(&skb->sk->sk_refcnt);
327} 342}
328 343
329META_COLLECTOR(int_sk_rcvbuf) 344META_COLLECTOR(int_sk_rcvbuf)
330{ 345{
331 SKIP_NONLOCAL(skb); 346 if (skip_nonlocal(skb)) {
347 *err = -1;
348 return;
349 }
332 dst->value = skb->sk->sk_rcvbuf; 350 dst->value = skb->sk->sk_rcvbuf;
333} 351}
334 352
335META_COLLECTOR(int_sk_shutdown) 353META_COLLECTOR(int_sk_shutdown)
336{ 354{
337 SKIP_NONLOCAL(skb); 355 if (skip_nonlocal(skb)) {
356 *err = -1;
357 return;
358 }
338 dst->value = skb->sk->sk_shutdown; 359 dst->value = skb->sk->sk_shutdown;
339} 360}
340 361
341META_COLLECTOR(int_sk_proto) 362META_COLLECTOR(int_sk_proto)
342{ 363{
343 SKIP_NONLOCAL(skb); 364 if (skip_nonlocal(skb)) {
365 *err = -1;
366 return;
367 }
344 dst->value = skb->sk->sk_protocol; 368 dst->value = skb->sk->sk_protocol;
345} 369}
346 370
347META_COLLECTOR(int_sk_type) 371META_COLLECTOR(int_sk_type)
348{ 372{
349 SKIP_NONLOCAL(skb); 373 if (skip_nonlocal(skb)) {
374 *err = -1;
375 return;
376 }
350 dst->value = skb->sk->sk_type; 377 dst->value = skb->sk->sk_type;
351} 378}
352 379
353META_COLLECTOR(int_sk_rmem_alloc) 380META_COLLECTOR(int_sk_rmem_alloc)
354{ 381{
355 SKIP_NONLOCAL(skb); 382 if (skip_nonlocal(skb)) {
383 *err = -1;
384 return;
385 }
356 dst->value = sk_rmem_alloc_get(skb->sk); 386 dst->value = sk_rmem_alloc_get(skb->sk);
357} 387}
358 388
359META_COLLECTOR(int_sk_wmem_alloc) 389META_COLLECTOR(int_sk_wmem_alloc)
360{ 390{
361 SKIP_NONLOCAL(skb); 391 if (skip_nonlocal(skb)) {
392 *err = -1;
393 return;
394 }
362 dst->value = sk_wmem_alloc_get(skb->sk); 395 dst->value = sk_wmem_alloc_get(skb->sk);
363} 396}
364 397
365META_COLLECTOR(int_sk_omem_alloc) 398META_COLLECTOR(int_sk_omem_alloc)
366{ 399{
367 SKIP_NONLOCAL(skb); 400 if (skip_nonlocal(skb)) {
401 *err = -1;
402 return;
403 }
368 dst->value = atomic_read(&skb->sk->sk_omem_alloc); 404 dst->value = atomic_read(&skb->sk->sk_omem_alloc);
369} 405}
370 406
371META_COLLECTOR(int_sk_rcv_qlen) 407META_COLLECTOR(int_sk_rcv_qlen)
372{ 408{
373 SKIP_NONLOCAL(skb); 409 if (skip_nonlocal(skb)) {
410 *err = -1;
411 return;
412 }
374 dst->value = skb->sk->sk_receive_queue.qlen; 413 dst->value = skb->sk->sk_receive_queue.qlen;
375} 414}
376 415
377META_COLLECTOR(int_sk_snd_qlen) 416META_COLLECTOR(int_sk_snd_qlen)
378{ 417{
379 SKIP_NONLOCAL(skb); 418 if (skip_nonlocal(skb)) {
419 *err = -1;
420 return;
421 }
380 dst->value = skb->sk->sk_write_queue.qlen; 422 dst->value = skb->sk->sk_write_queue.qlen;
381} 423}
382 424
383META_COLLECTOR(int_sk_wmem_queued) 425META_COLLECTOR(int_sk_wmem_queued)
384{ 426{
385 SKIP_NONLOCAL(skb); 427 if (skip_nonlocal(skb)) {
428 *err = -1;
429 return;
430 }
386 dst->value = skb->sk->sk_wmem_queued; 431 dst->value = skb->sk->sk_wmem_queued;
387} 432}
388 433
389META_COLLECTOR(int_sk_fwd_alloc) 434META_COLLECTOR(int_sk_fwd_alloc)
390{ 435{
391 SKIP_NONLOCAL(skb); 436 if (skip_nonlocal(skb)) {
437 *err = -1;
438 return;
439 }
392 dst->value = skb->sk->sk_forward_alloc; 440 dst->value = skb->sk->sk_forward_alloc;
393} 441}
394 442
395META_COLLECTOR(int_sk_sndbuf) 443META_COLLECTOR(int_sk_sndbuf)
396{ 444{
397 SKIP_NONLOCAL(skb); 445 if (skip_nonlocal(skb)) {
446 *err = -1;
447 return;
448 }
398 dst->value = skb->sk->sk_sndbuf; 449 dst->value = skb->sk->sk_sndbuf;
399} 450}
400 451
401META_COLLECTOR(int_sk_alloc) 452META_COLLECTOR(int_sk_alloc)
402{ 453{
403 SKIP_NONLOCAL(skb); 454 if (skip_nonlocal(skb)) {
455 *err = -1;
456 return;
457 }
404 dst->value = (__force int) skb->sk->sk_allocation; 458 dst->value = (__force int) skb->sk->sk_allocation;
405} 459}
406 460
407META_COLLECTOR(int_sk_hash) 461META_COLLECTOR(int_sk_hash)
408{ 462{
409 SKIP_NONLOCAL(skb); 463 if (skip_nonlocal(skb)) {
464 *err = -1;
465 return;
466 }
410 dst->value = skb->sk->sk_hash; 467 dst->value = skb->sk->sk_hash;
411} 468}
412 469
413META_COLLECTOR(int_sk_lingertime) 470META_COLLECTOR(int_sk_lingertime)
414{ 471{
415 SKIP_NONLOCAL(skb); 472 if (skip_nonlocal(skb)) {
473 *err = -1;
474 return;
475 }
416 dst->value = skb->sk->sk_lingertime / HZ; 476 dst->value = skb->sk->sk_lingertime / HZ;
417} 477}
418 478
419META_COLLECTOR(int_sk_err_qlen) 479META_COLLECTOR(int_sk_err_qlen)
420{ 480{
421 SKIP_NONLOCAL(skb); 481 if (skip_nonlocal(skb)) {
482 *err = -1;
483 return;
484 }
422 dst->value = skb->sk->sk_error_queue.qlen; 485 dst->value = skb->sk->sk_error_queue.qlen;
423} 486}
424 487
425META_COLLECTOR(int_sk_ack_bl) 488META_COLLECTOR(int_sk_ack_bl)
426{ 489{
427 SKIP_NONLOCAL(skb); 490 if (skip_nonlocal(skb)) {
491 *err = -1;
492 return;
493 }
428 dst->value = skb->sk->sk_ack_backlog; 494 dst->value = skb->sk->sk_ack_backlog;
429} 495}
430 496
431META_COLLECTOR(int_sk_max_ack_bl) 497META_COLLECTOR(int_sk_max_ack_bl)
432{ 498{
433 SKIP_NONLOCAL(skb); 499 if (skip_nonlocal(skb)) {
500 *err = -1;
501 return;
502 }
434 dst->value = skb->sk->sk_max_ack_backlog; 503 dst->value = skb->sk->sk_max_ack_backlog;
435} 504}
436 505
437META_COLLECTOR(int_sk_prio) 506META_COLLECTOR(int_sk_prio)
438{ 507{
439 SKIP_NONLOCAL(skb); 508 if (skip_nonlocal(skb)) {
509 *err = -1;
510 return;
511 }
440 dst->value = skb->sk->sk_priority; 512 dst->value = skb->sk->sk_priority;
441} 513}
442 514
443META_COLLECTOR(int_sk_rcvlowat) 515META_COLLECTOR(int_sk_rcvlowat)
444{ 516{
445 SKIP_NONLOCAL(skb); 517 if (skip_nonlocal(skb)) {
518 *err = -1;
519 return;
520 }
446 dst->value = skb->sk->sk_rcvlowat; 521 dst->value = skb->sk->sk_rcvlowat;
447} 522}
448 523
449META_COLLECTOR(int_sk_rcvtimeo) 524META_COLLECTOR(int_sk_rcvtimeo)
450{ 525{
451 SKIP_NONLOCAL(skb); 526 if (skip_nonlocal(skb)) {
527 *err = -1;
528 return;
529 }
452 dst->value = skb->sk->sk_rcvtimeo / HZ; 530 dst->value = skb->sk->sk_rcvtimeo / HZ;
453} 531}
454 532
455META_COLLECTOR(int_sk_sndtimeo) 533META_COLLECTOR(int_sk_sndtimeo)
456{ 534{
457 SKIP_NONLOCAL(skb); 535 if (skip_nonlocal(skb)) {
536 *err = -1;
537 return;
538 }
458 dst->value = skb->sk->sk_sndtimeo / HZ; 539 dst->value = skb->sk->sk_sndtimeo / HZ;
459} 540}
460 541
461META_COLLECTOR(int_sk_sendmsg_off) 542META_COLLECTOR(int_sk_sendmsg_off)
462{ 543{
463 SKIP_NONLOCAL(skb); 544 if (skip_nonlocal(skb)) {
545 *err = -1;
546 return;
547 }
464 dst->value = skb->sk->sk_frag.offset; 548 dst->value = skb->sk->sk_frag.offset;
465} 549}
466 550
467META_COLLECTOR(int_sk_write_pend) 551META_COLLECTOR(int_sk_write_pend)
468{ 552{
469 SKIP_NONLOCAL(skb); 553 if (skip_nonlocal(skb)) {
554 *err = -1;
555 return;
556 }
470 dst->value = skb->sk->sk_write_pending; 557 dst->value = skb->sk->sk_write_pending;
471} 558}
472 559
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index cd81505662b8..1313145e3b86 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -135,7 +135,7 @@ static DEFINE_RWLOCK(qdisc_mod_lock);
135 135
136static struct Qdisc_ops *qdisc_base; 136static struct Qdisc_ops *qdisc_base;
137 137
138/* Register/uregister queueing discipline */ 138/* Register/unregister queueing discipline */
139 139
140int register_qdisc(struct Qdisc_ops *qops) 140int register_qdisc(struct Qdisc_ops *qops)
141{ 141{
@@ -271,11 +271,15 @@ static struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle)
271 return NULL; 271 return NULL;
272} 272}
273 273
274static void qdisc_list_add(struct Qdisc *q) 274void qdisc_list_add(struct Qdisc *q)
275{ 275{
276 struct Qdisc *root = qdisc_dev(q)->qdisc;
277
278 WARN_ON_ONCE(root == &noop_qdisc);
276 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS)) 279 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS))
277 list_add_tail(&q->list, &qdisc_dev(q)->qdisc->list); 280 list_add_tail(&q->list, &root->list);
278} 281}
282EXPORT_SYMBOL(qdisc_list_add);
279 283
280void qdisc_list_del(struct Qdisc *q) 284void qdisc_list_del(struct Qdisc *q)
281{ 285{
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 7a42c81a19eb..2f80d01d42a6 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -1058,9 +1058,10 @@ static void cbq_normalize_quanta(struct cbq_sched_data *q, int prio)
1058 cl->quantum = (cl->weight*cl->allot*q->nclasses[prio])/ 1058 cl->quantum = (cl->weight*cl->allot*q->nclasses[prio])/
1059 q->quanta[prio]; 1059 q->quanta[prio];
1060 } 1060 }
1061 if (cl->quantum <= 0 || cl->quantum>32*qdisc_dev(cl->qdisc)->mtu) { 1061 if (cl->quantum <= 0 ||
1062 pr_warning("CBQ: class %08x has bad quantum==%ld, repaired.\n", 1062 cl->quantum > 32*qdisc_dev(cl->qdisc)->mtu) {
1063 cl->common.classid, cl->quantum); 1063 pr_warn("CBQ: class %08x has bad quantum==%ld, repaired.\n",
1064 cl->common.classid, cl->quantum);
1064 cl->quantum = qdisc_dev(cl->qdisc)->mtu/2 + 1; 1065 cl->quantum = qdisc_dev(cl->qdisc)->mtu/2 + 1;
1065 } 1066 }
1066 } 1067 }
@@ -1782,8 +1783,7 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
1782 qdisc_root_sleeping_lock(sch), 1783 qdisc_root_sleeping_lock(sch),
1783 tca[TCA_RATE]); 1784 tca[TCA_RATE]);
1784 if (err) { 1785 if (err) {
1785 if (rtab) 1786 qdisc_put_rtab(rtab);
1786 qdisc_put_rtab(rtab);
1787 return err; 1787 return err;
1788 } 1788 }
1789 } 1789 }
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c
index 3886365cc207..49d6ef338b55 100644
--- a/net/sched/sch_dsmark.c
+++ b/net/sched/sch_dsmark.c
@@ -47,7 +47,7 @@ struct dsmark_qdisc_data {
47 47
48static inline int dsmark_valid_index(struct dsmark_qdisc_data *p, u16 index) 48static inline int dsmark_valid_index(struct dsmark_qdisc_data *p, u16 index)
49{ 49{
50 return (index <= p->indices && index > 0); 50 return index <= p->indices && index > 0;
51} 51}
52 52
53/* ------------------------- Class/flow operations ------------------------- */ 53/* ------------------------- Class/flow operations ------------------------- */
@@ -57,8 +57,8 @@ static int dsmark_graft(struct Qdisc *sch, unsigned long arg,
57{ 57{
58 struct dsmark_qdisc_data *p = qdisc_priv(sch); 58 struct dsmark_qdisc_data *p = qdisc_priv(sch);
59 59
60 pr_debug("dsmark_graft(sch %p,[qdisc %p],new %p,old %p)\n", 60 pr_debug("%s(sch %p,[qdisc %p],new %p,old %p)\n",
61 sch, p, new, old); 61 __func__, sch, p, new, old);
62 62
63 if (new == NULL) { 63 if (new == NULL) {
64 new = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, 64 new = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops,
@@ -85,8 +85,8 @@ static struct Qdisc *dsmark_leaf(struct Qdisc *sch, unsigned long arg)
85 85
86static unsigned long dsmark_get(struct Qdisc *sch, u32 classid) 86static unsigned long dsmark_get(struct Qdisc *sch, u32 classid)
87{ 87{
88 pr_debug("dsmark_get(sch %p,[qdisc %p],classid %x)\n", 88 pr_debug("%s(sch %p,[qdisc %p],classid %x)\n",
89 sch, qdisc_priv(sch), classid); 89 __func__, sch, qdisc_priv(sch), classid);
90 90
91 return TC_H_MIN(classid) + 1; 91 return TC_H_MIN(classid) + 1;
92} 92}
@@ -118,8 +118,8 @@ static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent,
118 int err = -EINVAL; 118 int err = -EINVAL;
119 u8 mask = 0; 119 u8 mask = 0;
120 120
121 pr_debug("dsmark_change(sch %p,[qdisc %p],classid %x,parent %x)," 121 pr_debug("%s(sch %p,[qdisc %p],classid %x,parent %x), arg 0x%lx\n",
122 "arg 0x%lx\n", sch, p, classid, parent, *arg); 122 __func__, sch, p, classid, parent, *arg);
123 123
124 if (!dsmark_valid_index(p, *arg)) { 124 if (!dsmark_valid_index(p, *arg)) {
125 err = -ENOENT; 125 err = -ENOENT;
@@ -166,7 +166,8 @@ static void dsmark_walk(struct Qdisc *sch, struct qdisc_walker *walker)
166 struct dsmark_qdisc_data *p = qdisc_priv(sch); 166 struct dsmark_qdisc_data *p = qdisc_priv(sch);
167 int i; 167 int i;
168 168
169 pr_debug("dsmark_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker); 169 pr_debug("%s(sch %p,[qdisc %p],walker %p)\n",
170 __func__, sch, p, walker);
170 171
171 if (walker->stop) 172 if (walker->stop)
172 return; 173 return;
@@ -199,7 +200,7 @@ static int dsmark_enqueue(struct sk_buff *skb, struct Qdisc *sch)
199 struct dsmark_qdisc_data *p = qdisc_priv(sch); 200 struct dsmark_qdisc_data *p = qdisc_priv(sch);
200 int err; 201 int err;
201 202
202 pr_debug("dsmark_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p); 203 pr_debug("%s(skb %p,sch %p,[qdisc %p])\n", __func__, skb, sch, p);
203 204
204 if (p->set_tc_index) { 205 if (p->set_tc_index) {
205 switch (skb->protocol) { 206 switch (skb->protocol) {
@@ -275,7 +276,7 @@ static struct sk_buff *dsmark_dequeue(struct Qdisc *sch)
275 struct sk_buff *skb; 276 struct sk_buff *skb;
276 u32 index; 277 u32 index;
277 278
278 pr_debug("dsmark_dequeue(sch %p,[qdisc %p])\n", sch, p); 279 pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
279 280
280 skb = p->q->ops->dequeue(p->q); 281 skb = p->q->ops->dequeue(p->q);
281 if (skb == NULL) 282 if (skb == NULL)
@@ -303,8 +304,8 @@ static struct sk_buff *dsmark_dequeue(struct Qdisc *sch)
303 * and don't need yet another qdisc as a bypass. 304 * and don't need yet another qdisc as a bypass.
304 */ 305 */
305 if (p->mask[index] != 0xff || p->value[index]) 306 if (p->mask[index] != 0xff || p->value[index])
306 pr_warning("dsmark_dequeue: unsupported protocol %d\n", 307 pr_warn("%s: unsupported protocol %d\n",
307 ntohs(skb->protocol)); 308 __func__, ntohs(skb->protocol));
308 break; 309 break;
309 } 310 }
310 311
@@ -315,7 +316,7 @@ static struct sk_buff *dsmark_peek(struct Qdisc *sch)
315{ 316{
316 struct dsmark_qdisc_data *p = qdisc_priv(sch); 317 struct dsmark_qdisc_data *p = qdisc_priv(sch);
317 318
318 pr_debug("dsmark_peek(sch %p,[qdisc %p])\n", sch, p); 319 pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
319 320
320 return p->q->ops->peek(p->q); 321 return p->q->ops->peek(p->q);
321} 322}
@@ -325,7 +326,7 @@ static unsigned int dsmark_drop(struct Qdisc *sch)
325 struct dsmark_qdisc_data *p = qdisc_priv(sch); 326 struct dsmark_qdisc_data *p = qdisc_priv(sch);
326 unsigned int len; 327 unsigned int len;
327 328
328 pr_debug("dsmark_reset(sch %p,[qdisc %p])\n", sch, p); 329 pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
329 330
330 if (p->q->ops->drop == NULL) 331 if (p->q->ops->drop == NULL)
331 return 0; 332 return 0;
@@ -346,7 +347,7 @@ static int dsmark_init(struct Qdisc *sch, struct nlattr *opt)
346 u16 indices; 347 u16 indices;
347 u8 *mask; 348 u8 *mask;
348 349
349 pr_debug("dsmark_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt); 350 pr_debug("%s(sch %p,[qdisc %p],opt %p)\n", __func__, sch, p, opt);
350 351
351 if (!opt) 352 if (!opt)
352 goto errout; 353 goto errout;
@@ -384,7 +385,7 @@ static int dsmark_init(struct Qdisc *sch, struct nlattr *opt)
384 if (p->q == NULL) 385 if (p->q == NULL)
385 p->q = &noop_qdisc; 386 p->q = &noop_qdisc;
386 387
387 pr_debug("dsmark_init: qdisc %p\n", p->q); 388 pr_debug("%s: qdisc %p\n", __func__, p->q);
388 389
389 err = 0; 390 err = 0;
390errout: 391errout:
@@ -395,7 +396,7 @@ static void dsmark_reset(struct Qdisc *sch)
395{ 396{
396 struct dsmark_qdisc_data *p = qdisc_priv(sch); 397 struct dsmark_qdisc_data *p = qdisc_priv(sch);
397 398
398 pr_debug("dsmark_reset(sch %p,[qdisc %p])\n", sch, p); 399 pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
399 qdisc_reset(p->q); 400 qdisc_reset(p->q);
400 sch->q.qlen = 0; 401 sch->q.qlen = 0;
401} 402}
@@ -404,7 +405,7 @@ static void dsmark_destroy(struct Qdisc *sch)
404{ 405{
405 struct dsmark_qdisc_data *p = qdisc_priv(sch); 406 struct dsmark_qdisc_data *p = qdisc_priv(sch);
406 407
407 pr_debug("dsmark_destroy(sch %p,[qdisc %p])\n", sch, p); 408 pr_debug("%s(sch %p,[qdisc %p])\n", __func__, sch, p);
408 409
409 tcf_destroy_chain(&p->filter_list); 410 tcf_destroy_chain(&p->filter_list);
410 qdisc_destroy(p->q); 411 qdisc_destroy(p->q);
@@ -417,7 +418,7 @@ static int dsmark_dump_class(struct Qdisc *sch, unsigned long cl,
417 struct dsmark_qdisc_data *p = qdisc_priv(sch); 418 struct dsmark_qdisc_data *p = qdisc_priv(sch);
418 struct nlattr *opts = NULL; 419 struct nlattr *opts = NULL;
419 420
420 pr_debug("dsmark_dump_class(sch %p,[qdisc %p],class %ld\n", sch, p, cl); 421 pr_debug("%s(sch %p,[qdisc %p],class %ld\n", __func__, sch, p, cl);
421 422
422 if (!dsmark_valid_index(p, cl)) 423 if (!dsmark_valid_index(p, cl))
423 return -EINVAL; 424 return -EINVAL;
diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c
index 95d843961907..08ef7a42c0e4 100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -47,6 +47,7 @@
47#include <linux/rbtree.h> 47#include <linux/rbtree.h>
48#include <linux/hash.h> 48#include <linux/hash.h>
49#include <linux/prefetch.h> 49#include <linux/prefetch.h>
50#include <linux/vmalloc.h>
50#include <net/netlink.h> 51#include <net/netlink.h>
51#include <net/pkt_sched.h> 52#include <net/pkt_sched.h>
52#include <net/sock.h> 53#include <net/sock.h>
@@ -225,7 +226,7 @@ static struct fq_flow *fq_classify(struct sk_buff *skb, struct fq_sched_data *q)
225 /* By forcing low order bit to 1, we make sure to not 226 /* By forcing low order bit to 1, we make sure to not
226 * collide with a local flow (socket pointers are word aligned) 227 * collide with a local flow (socket pointers are word aligned)
227 */ 228 */
228 sk = (struct sock *)(skb_get_rxhash(skb) | 1L); 229 sk = (struct sock *)(skb_get_hash(skb) | 1L);
229 } 230 }
230 231
231 root = &q->fq_root[hash_32((u32)(long)sk, q->fq_trees_log)]; 232 root = &q->fq_root[hash_32((u32)(long)sk, q->fq_trees_log)];
@@ -578,15 +579,36 @@ static void fq_rehash(struct fq_sched_data *q,
578 q->stat_gc_flows += fcnt; 579 q->stat_gc_flows += fcnt;
579} 580}
580 581
581static int fq_resize(struct fq_sched_data *q, u32 log) 582static void *fq_alloc_node(size_t sz, int node)
582{ 583{
584 void *ptr;
585
586 ptr = kmalloc_node(sz, GFP_KERNEL | __GFP_REPEAT | __GFP_NOWARN, node);
587 if (!ptr)
588 ptr = vmalloc_node(sz, node);
589 return ptr;
590}
591
592static void fq_free(void *addr)
593{
594 if (addr && is_vmalloc_addr(addr))
595 vfree(addr);
596 else
597 kfree(addr);
598}
599
600static int fq_resize(struct Qdisc *sch, u32 log)
601{
602 struct fq_sched_data *q = qdisc_priv(sch);
583 struct rb_root *array; 603 struct rb_root *array;
584 u32 idx; 604 u32 idx;
585 605
586 if (q->fq_root && log == q->fq_trees_log) 606 if (q->fq_root && log == q->fq_trees_log)
587 return 0; 607 return 0;
588 608
589 array = kmalloc(sizeof(struct rb_root) << log, GFP_KERNEL); 609 /* If XPS was setup, we can allocate memory on right NUMA node */
610 array = fq_alloc_node(sizeof(struct rb_root) << log,
611 netdev_queue_numa_node_read(sch->dev_queue));
590 if (!array) 612 if (!array)
591 return -ENOMEM; 613 return -ENOMEM;
592 614
@@ -595,7 +617,7 @@ static int fq_resize(struct fq_sched_data *q, u32 log)
595 617
596 if (q->fq_root) { 618 if (q->fq_root) {
597 fq_rehash(q, q->fq_root, q->fq_trees_log, array, log); 619 fq_rehash(q, q->fq_root, q->fq_trees_log, array, log);
598 kfree(q->fq_root); 620 fq_free(q->fq_root);
599 } 621 }
600 q->fq_root = array; 622 q->fq_root = array;
601 q->fq_trees_log = log; 623 q->fq_trees_log = log;
@@ -676,7 +698,7 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
676 } 698 }
677 699
678 if (!err) 700 if (!err)
679 err = fq_resize(q, fq_log); 701 err = fq_resize(sch, fq_log);
680 702
681 while (sch->q.qlen > sch->limit) { 703 while (sch->q.qlen > sch->limit) {
682 struct sk_buff *skb = fq_dequeue(sch); 704 struct sk_buff *skb = fq_dequeue(sch);
@@ -697,7 +719,7 @@ static void fq_destroy(struct Qdisc *sch)
697 struct fq_sched_data *q = qdisc_priv(sch); 719 struct fq_sched_data *q = qdisc_priv(sch);
698 720
699 fq_reset(sch); 721 fq_reset(sch);
700 kfree(q->fq_root); 722 fq_free(q->fq_root);
701 qdisc_watchdog_cancel(&q->watchdog); 723 qdisc_watchdog_cancel(&q->watchdog);
702} 724}
703 725
@@ -723,7 +745,7 @@ static int fq_init(struct Qdisc *sch, struct nlattr *opt)
723 if (opt) 745 if (opt)
724 err = fq_change(sch, opt); 746 err = fq_change(sch, opt);
725 else 747 else
726 err = fq_resize(q, q->fq_trees_log); 748 err = fq_resize(sch, q->fq_trees_log);
727 749
728 return err; 750 return err;
729} 751}
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 922a09406ba7..32bb942d2faa 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -338,13 +338,13 @@ EXPORT_SYMBOL(netif_carrier_off);
338 cheaper. 338 cheaper.
339 */ 339 */
340 340
341static int noop_enqueue(struct sk_buff *skb, struct Qdisc * qdisc) 341static int noop_enqueue(struct sk_buff *skb, struct Qdisc *qdisc)
342{ 342{
343 kfree_skb(skb); 343 kfree_skb(skb);
344 return NET_XMIT_CN; 344 return NET_XMIT_CN;
345} 345}
346 346
347static struct sk_buff *noop_dequeue(struct Qdisc * qdisc) 347static struct sk_buff *noop_dequeue(struct Qdisc *qdisc)
348{ 348{
349 return NULL; 349 return NULL;
350} 350}
@@ -718,8 +718,8 @@ static void attach_default_qdiscs(struct net_device *dev)
718 } else { 718 } else {
719 qdisc = qdisc_create_dflt(txq, &mq_qdisc_ops, TC_H_ROOT); 719 qdisc = qdisc_create_dflt(txq, &mq_qdisc_ops, TC_H_ROOT);
720 if (qdisc) { 720 if (qdisc) {
721 qdisc->ops->attach(qdisc);
722 dev->qdisc = qdisc; 721 dev->qdisc = qdisc;
722 qdisc->ops->attach(qdisc);
723 } 723 }
724 } 724 }
725} 725}
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index d42234c0f13b..12cbc09157fc 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -370,8 +370,8 @@ static inline int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps)
370 370
371 for (i = table->DPs; i < MAX_DPs; i++) { 371 for (i = table->DPs; i < MAX_DPs; i++) {
372 if (table->tab[i]) { 372 if (table->tab[i]) {
373 pr_warning("GRED: Warning: Destroying " 373 pr_warn("GRED: Warning: Destroying shadowed VQ 0x%x\n",
374 "shadowed VQ 0x%x\n", i); 374 i);
375 gred_destroy_vq(table->tab[i]); 375 gred_destroy_vq(table->tab[i]);
376 table->tab[i] = NULL; 376 table->tab[i] = NULL;
377 } 377 }
diff --git a/net/sched/sch_hhf.c b/net/sched/sch_hhf.c
new file mode 100644
index 000000000000..cf7f614e841b
--- /dev/null
+++ b/net/sched/sch_hhf.c
@@ -0,0 +1,745 @@
1/* net/sched/sch_hhf.c Heavy-Hitter Filter (HHF)
2 *
3 * Copyright (C) 2013 Terry Lam <vtlam@google.com>
4 * Copyright (C) 2013 Nandita Dukkipati <nanditad@google.com>
5 */
6
7#include <linux/jhash.h>
8#include <linux/jiffies.h>
9#include <linux/module.h>
10#include <linux/skbuff.h>
11#include <linux/vmalloc.h>
12#include <net/flow_keys.h>
13#include <net/pkt_sched.h>
14#include <net/sock.h>
15
16/* Heavy-Hitter Filter (HHF)
17 *
18 * Principles :
19 * Flows are classified into two buckets: non-heavy-hitter and heavy-hitter
20 * buckets. Initially, a new flow starts as non-heavy-hitter. Once classified
21 * as heavy-hitter, it is immediately switched to the heavy-hitter bucket.
22 * The buckets are dequeued by a Weighted Deficit Round Robin (WDRR) scheduler,
23 * in which the heavy-hitter bucket is served with less weight.
24 * In other words, non-heavy-hitters (e.g., short bursts of critical traffic)
25 * are isolated from heavy-hitters (e.g., persistent bulk traffic) and also have
26 * higher share of bandwidth.
27 *
28 * To capture heavy-hitters, we use the "multi-stage filter" algorithm in the
29 * following paper:
30 * [EV02] C. Estan and G. Varghese, "New Directions in Traffic Measurement and
31 * Accounting", in ACM SIGCOMM, 2002.
32 *
33 * Conceptually, a multi-stage filter comprises k independent hash functions
34 * and k counter arrays. Packets are indexed into k counter arrays by k hash
35 * functions, respectively. The counters are then increased by the packet sizes.
36 * Therefore,
37 * - For a heavy-hitter flow: *all* of its k array counters must be large.
38 * - For a non-heavy-hitter flow: some of its k array counters can be large
39 * due to hash collision with other small flows; however, with high
40 * probability, not *all* k counters are large.
41 *
42 * By the design of the multi-stage filter algorithm, the false negative rate
43 * (heavy-hitters getting away uncaptured) is zero. However, the algorithm is
44 * susceptible to false positives (non-heavy-hitters mistakenly classified as
45 * heavy-hitters).
46 * Therefore, we also implement the following optimizations to reduce false
47 * positives by avoiding unnecessary increment of the counter values:
48 * - Optimization O1: once a heavy-hitter is identified, its bytes are not
49 * accounted in the array counters. This technique is called "shielding"
50 * in Section 3.3.1 of [EV02].
51 * - Optimization O2: conservative update of counters
52 * (Section 3.3.2 of [EV02]),
53 * New counter value = max {old counter value,
54 * smallest counter value + packet bytes}
55 *
56 * Finally, we refresh the counters periodically since otherwise the counter
57 * values will keep accumulating.
58 *
59 * Once a flow is classified as heavy-hitter, we also save its per-flow state
60 * in an exact-matching flow table so that its subsequent packets can be
61 * dispatched to the heavy-hitter bucket accordingly.
62 *
63 *
64 * At a high level, this qdisc works as follows:
65 * Given a packet p:
66 * - If the flow-id of p (e.g., TCP 5-tuple) is already in the exact-matching
67 * heavy-hitter flow table, denoted table T, then send p to the heavy-hitter
68 * bucket.
69 * - Otherwise, forward p to the multi-stage filter, denoted filter F
70 * + If F decides that p belongs to a non-heavy-hitter flow, then send p
71 * to the non-heavy-hitter bucket.
72 * + Otherwise, if F decides that p belongs to a new heavy-hitter flow,
73 * then set up a new flow entry for the flow-id of p in the table T and
74 * send p to the heavy-hitter bucket.
75 *
76 * In this implementation:
77 * - T is a fixed-size hash-table with 1024 entries. Hash collision is
78 * resolved by linked-list chaining.
79 * - F has four counter arrays, each array containing 1024 32-bit counters.
80 * That means 4 * 1024 * 32 bits = 16KB of memory.
81 * - Since each array in F contains 1024 counters, 10 bits are sufficient to
82 * index into each array.
83 * Hence, instead of having four hash functions, we chop the 32-bit
84 * skb-hash into three 10-bit chunks, and the remaining 10-bit chunk is
85 * computed as XOR sum of those three chunks.
86 * - We need to clear the counter arrays periodically; however, directly
87 * memsetting 16KB of memory can lead to cache eviction and unwanted delay.
88 * So by representing each counter by a valid bit, we only need to reset
89 * 4K of 1 bit (i.e. 512 bytes) instead of 16KB of memory.
90 * - The Deficit Round Robin engine is taken from fq_codel implementation
91 * (net/sched/sch_fq_codel.c). Note that wdrr_bucket corresponds to
92 * fq_codel_flow in fq_codel implementation.
93 *
94 */
95
96/* Non-configurable parameters */
97#define HH_FLOWS_CNT 1024 /* number of entries in exact-matching table T */
98#define HHF_ARRAYS_CNT 4 /* number of arrays in multi-stage filter F */
99#define HHF_ARRAYS_LEN 1024 /* number of counters in each array of F */
100#define HHF_BIT_MASK_LEN 10 /* masking 10 bits */
101#define HHF_BIT_MASK 0x3FF /* bitmask of 10 bits */
102
103#define WDRR_BUCKET_CNT 2 /* two buckets for Weighted DRR */
104enum wdrr_bucket_idx {
105 WDRR_BUCKET_FOR_HH = 0, /* bucket id for heavy-hitters */
106 WDRR_BUCKET_FOR_NON_HH = 1 /* bucket id for non-heavy-hitters */
107};
108
109#define hhf_time_before(a, b) \
110 (typecheck(u32, a) && typecheck(u32, b) && ((s32)((a) - (b)) < 0))
111
112/* Heavy-hitter per-flow state */
113struct hh_flow_state {
114 u32 hash_id; /* hash of flow-id (e.g. TCP 5-tuple) */
115 u32 hit_timestamp; /* last time heavy-hitter was seen */
116 struct list_head flowchain; /* chaining under hash collision */
117};
118
119/* Weighted Deficit Round Robin (WDRR) scheduler */
120struct wdrr_bucket {
121 struct sk_buff *head;
122 struct sk_buff *tail;
123 struct list_head bucketchain;
124 int deficit;
125};
126
127struct hhf_sched_data {
128 struct wdrr_bucket buckets[WDRR_BUCKET_CNT];
129 u32 perturbation; /* hash perturbation */
130 u32 quantum; /* psched_mtu(qdisc_dev(sch)); */
131 u32 drop_overlimit; /* number of times max qdisc packet
132 * limit was hit
133 */
134 struct list_head *hh_flows; /* table T (currently active HHs) */
135 u32 hh_flows_limit; /* max active HH allocs */
136 u32 hh_flows_overlimit; /* num of disallowed HH allocs */
137 u32 hh_flows_total_cnt; /* total admitted HHs */
138 u32 hh_flows_current_cnt; /* total current HHs */
139 u32 *hhf_arrays[HHF_ARRAYS_CNT]; /* HH filter F */
140 u32 hhf_arrays_reset_timestamp; /* last time hhf_arrays
141 * was reset
142 */
143 unsigned long *hhf_valid_bits[HHF_ARRAYS_CNT]; /* shadow valid bits
144 * of hhf_arrays
145 */
146 /* Similar to the "new_flows" vs. "old_flows" concept in fq_codel DRR */
147 struct list_head new_buckets; /* list of new buckets */
148 struct list_head old_buckets; /* list of old buckets */
149
150 /* Configurable HHF parameters */
151 u32 hhf_reset_timeout; /* interval to reset counter
152 * arrays in filter F
153 * (default 40ms)
154 */
155 u32 hhf_admit_bytes; /* counter thresh to classify as
156 * HH (default 128KB).
157 * With these default values,
158 * 128KB / 40ms = 25 Mbps
159 * i.e., we expect to capture HHs
160 * sending > 25 Mbps.
161 */
162 u32 hhf_evict_timeout; /* aging threshold to evict idle
163 * HHs out of table T. This should
164 * be large enough to avoid
165 * reordering during HH eviction.
166 * (default 1s)
167 */
168 u32 hhf_non_hh_weight; /* WDRR weight for non-HHs
169 * (default 2,
170 * i.e., non-HH : HH = 2 : 1)
171 */
172};
173
174static u32 hhf_time_stamp(void)
175{
176 return jiffies;
177}
178
179static unsigned int skb_hash(const struct hhf_sched_data *q,
180 const struct sk_buff *skb)
181{
182 struct flow_keys keys;
183 unsigned int hash;
184
185 if (skb->sk && skb->sk->sk_hash)
186 return skb->sk->sk_hash;
187
188 skb_flow_dissect(skb, &keys);
189 hash = jhash_3words((__force u32)keys.dst,
190 (__force u32)keys.src ^ keys.ip_proto,
191 (__force u32)keys.ports, q->perturbation);
192 return hash;
193}
194
195/* Looks up a heavy-hitter flow in a chaining list of table T. */
196static struct hh_flow_state *seek_list(const u32 hash,
197 struct list_head *head,
198 struct hhf_sched_data *q)
199{
200 struct hh_flow_state *flow, *next;
201 u32 now = hhf_time_stamp();
202
203 if (list_empty(head))
204 return NULL;
205
206 list_for_each_entry_safe(flow, next, head, flowchain) {
207 u32 prev = flow->hit_timestamp + q->hhf_evict_timeout;
208
209 if (hhf_time_before(prev, now)) {
210 /* Delete expired heavy-hitters, but preserve one entry
211 * to avoid kzalloc() when next time this slot is hit.
212 */
213 if (list_is_last(&flow->flowchain, head))
214 return NULL;
215 list_del(&flow->flowchain);
216 kfree(flow);
217 q->hh_flows_current_cnt--;
218 } else if (flow->hash_id == hash) {
219 return flow;
220 }
221 }
222 return NULL;
223}
224
225/* Returns a flow state entry for a new heavy-hitter. Either reuses an expired
226 * entry or dynamically alloc a new entry.
227 */
228static struct hh_flow_state *alloc_new_hh(struct list_head *head,
229 struct hhf_sched_data *q)
230{
231 struct hh_flow_state *flow;
232 u32 now = hhf_time_stamp();
233
234 if (!list_empty(head)) {
235 /* Find an expired heavy-hitter flow entry. */
236 list_for_each_entry(flow, head, flowchain) {
237 u32 prev = flow->hit_timestamp + q->hhf_evict_timeout;
238
239 if (hhf_time_before(prev, now))
240 return flow;
241 }
242 }
243
244 if (q->hh_flows_current_cnt >= q->hh_flows_limit) {
245 q->hh_flows_overlimit++;
246 return NULL;
247 }
248 /* Create new entry. */
249 flow = kzalloc(sizeof(struct hh_flow_state), GFP_ATOMIC);
250 if (!flow)
251 return NULL;
252
253 q->hh_flows_current_cnt++;
254 INIT_LIST_HEAD(&flow->flowchain);
255 list_add_tail(&flow->flowchain, head);
256
257 return flow;
258}
259
260/* Assigns packets to WDRR buckets. Implements a multi-stage filter to
261 * classify heavy-hitters.
262 */
263static enum wdrr_bucket_idx hhf_classify(struct sk_buff *skb, struct Qdisc *sch)
264{
265 struct hhf_sched_data *q = qdisc_priv(sch);
266 u32 tmp_hash, hash;
267 u32 xorsum, filter_pos[HHF_ARRAYS_CNT], flow_pos;
268 struct hh_flow_state *flow;
269 u32 pkt_len, min_hhf_val;
270 int i;
271 u32 prev;
272 u32 now = hhf_time_stamp();
273
274 /* Reset the HHF counter arrays if this is the right time. */
275 prev = q->hhf_arrays_reset_timestamp + q->hhf_reset_timeout;
276 if (hhf_time_before(prev, now)) {
277 for (i = 0; i < HHF_ARRAYS_CNT; i++)
278 bitmap_zero(q->hhf_valid_bits[i], HHF_ARRAYS_LEN);
279 q->hhf_arrays_reset_timestamp = now;
280 }
281
282 /* Get hashed flow-id of the skb. */
283 hash = skb_hash(q, skb);
284
285 /* Check if this packet belongs to an already established HH flow. */
286 flow_pos = hash & HHF_BIT_MASK;
287 flow = seek_list(hash, &q->hh_flows[flow_pos], q);
288 if (flow) { /* found its HH flow */
289 flow->hit_timestamp = now;
290 return WDRR_BUCKET_FOR_HH;
291 }
292
293 /* Now pass the packet through the multi-stage filter. */
294 tmp_hash = hash;
295 xorsum = 0;
296 for (i = 0; i < HHF_ARRAYS_CNT - 1; i++) {
297 /* Split the skb_hash into three 10-bit chunks. */
298 filter_pos[i] = tmp_hash & HHF_BIT_MASK;
299 xorsum ^= filter_pos[i];
300 tmp_hash >>= HHF_BIT_MASK_LEN;
301 }
302 /* The last chunk is computed as XOR sum of other chunks. */
303 filter_pos[HHF_ARRAYS_CNT - 1] = xorsum ^ tmp_hash;
304
305 pkt_len = qdisc_pkt_len(skb);
306 min_hhf_val = ~0U;
307 for (i = 0; i < HHF_ARRAYS_CNT; i++) {
308 u32 val;
309
310 if (!test_bit(filter_pos[i], q->hhf_valid_bits[i])) {
311 q->hhf_arrays[i][filter_pos[i]] = 0;
312 __set_bit(filter_pos[i], q->hhf_valid_bits[i]);
313 }
314
315 val = q->hhf_arrays[i][filter_pos[i]] + pkt_len;
316 if (min_hhf_val > val)
317 min_hhf_val = val;
318 }
319
320 /* Found a new HH iff all counter values > HH admit threshold. */
321 if (min_hhf_val > q->hhf_admit_bytes) {
322 /* Just captured a new heavy-hitter. */
323 flow = alloc_new_hh(&q->hh_flows[flow_pos], q);
324 if (!flow) /* memory alloc problem */
325 return WDRR_BUCKET_FOR_NON_HH;
326 flow->hash_id = hash;
327 flow->hit_timestamp = now;
328 q->hh_flows_total_cnt++;
329
330 /* By returning without updating counters in q->hhf_arrays,
331 * we implicitly implement "shielding" (see Optimization O1).
332 */
333 return WDRR_BUCKET_FOR_HH;
334 }
335
336 /* Conservative update of HHF arrays (see Optimization O2). */
337 for (i = 0; i < HHF_ARRAYS_CNT; i++) {
338 if (q->hhf_arrays[i][filter_pos[i]] < min_hhf_val)
339 q->hhf_arrays[i][filter_pos[i]] = min_hhf_val;
340 }
341 return WDRR_BUCKET_FOR_NON_HH;
342}
343
344/* Removes one skb from head of bucket. */
345static struct sk_buff *dequeue_head(struct wdrr_bucket *bucket)
346{
347 struct sk_buff *skb = bucket->head;
348
349 bucket->head = skb->next;
350 skb->next = NULL;
351 return skb;
352}
353
354/* Tail-adds skb to bucket. */
355static void bucket_add(struct wdrr_bucket *bucket, struct sk_buff *skb)
356{
357 if (bucket->head == NULL)
358 bucket->head = skb;
359 else
360 bucket->tail->next = skb;
361 bucket->tail = skb;
362 skb->next = NULL;
363}
364
365static unsigned int hhf_drop(struct Qdisc *sch)
366{
367 struct hhf_sched_data *q = qdisc_priv(sch);
368 struct wdrr_bucket *bucket;
369
370 /* Always try to drop from heavy-hitters first. */
371 bucket = &q->buckets[WDRR_BUCKET_FOR_HH];
372 if (!bucket->head)
373 bucket = &q->buckets[WDRR_BUCKET_FOR_NON_HH];
374
375 if (bucket->head) {
376 struct sk_buff *skb = dequeue_head(bucket);
377
378 sch->q.qlen--;
379 sch->qstats.drops++;
380 sch->qstats.backlog -= qdisc_pkt_len(skb);
381 kfree_skb(skb);
382 }
383
384 /* Return id of the bucket from which the packet was dropped. */
385 return bucket - q->buckets;
386}
387
388static int hhf_enqueue(struct sk_buff *skb, struct Qdisc *sch)
389{
390 struct hhf_sched_data *q = qdisc_priv(sch);
391 enum wdrr_bucket_idx idx;
392 struct wdrr_bucket *bucket;
393
394 idx = hhf_classify(skb, sch);
395
396 bucket = &q->buckets[idx];
397 bucket_add(bucket, skb);
398 sch->qstats.backlog += qdisc_pkt_len(skb);
399
400 if (list_empty(&bucket->bucketchain)) {
401 unsigned int weight;
402
403 /* The logic of new_buckets vs. old_buckets is the same as
404 * new_flows vs. old_flows in the implementation of fq_codel,
405 * i.e., short bursts of non-HHs should have strict priority.
406 */
407 if (idx == WDRR_BUCKET_FOR_HH) {
408 /* Always move heavy-hitters to old bucket. */
409 weight = 1;
410 list_add_tail(&bucket->bucketchain, &q->old_buckets);
411 } else {
412 weight = q->hhf_non_hh_weight;
413 list_add_tail(&bucket->bucketchain, &q->new_buckets);
414 }
415 bucket->deficit = weight * q->quantum;
416 }
417 if (++sch->q.qlen < sch->limit)
418 return NET_XMIT_SUCCESS;
419
420 q->drop_overlimit++;
421 /* Return Congestion Notification only if we dropped a packet from this
422 * bucket.
423 */
424 if (hhf_drop(sch) == idx)
425 return NET_XMIT_CN;
426
427 /* As we dropped a packet, better let upper stack know this. */
428 qdisc_tree_decrease_qlen(sch, 1);
429 return NET_XMIT_SUCCESS;
430}
431
432static struct sk_buff *hhf_dequeue(struct Qdisc *sch)
433{
434 struct hhf_sched_data *q = qdisc_priv(sch);
435 struct sk_buff *skb = NULL;
436 struct wdrr_bucket *bucket;
437 struct list_head *head;
438
439begin:
440 head = &q->new_buckets;
441 if (list_empty(head)) {
442 head = &q->old_buckets;
443 if (list_empty(head))
444 return NULL;
445 }
446 bucket = list_first_entry(head, struct wdrr_bucket, bucketchain);
447
448 if (bucket->deficit <= 0) {
449 int weight = (bucket - q->buckets == WDRR_BUCKET_FOR_HH) ?
450 1 : q->hhf_non_hh_weight;
451
452 bucket->deficit += weight * q->quantum;
453 list_move_tail(&bucket->bucketchain, &q->old_buckets);
454 goto begin;
455 }
456
457 if (bucket->head) {
458 skb = dequeue_head(bucket);
459 sch->q.qlen--;
460 sch->qstats.backlog -= qdisc_pkt_len(skb);
461 }
462
463 if (!skb) {
464 /* Force a pass through old_buckets to prevent starvation. */
465 if ((head == &q->new_buckets) && !list_empty(&q->old_buckets))
466 list_move_tail(&bucket->bucketchain, &q->old_buckets);
467 else
468 list_del_init(&bucket->bucketchain);
469 goto begin;
470 }
471 qdisc_bstats_update(sch, skb);
472 bucket->deficit -= qdisc_pkt_len(skb);
473
474 return skb;
475}
476
477static void hhf_reset(struct Qdisc *sch)
478{
479 struct sk_buff *skb;
480
481 while ((skb = hhf_dequeue(sch)) != NULL)
482 kfree_skb(skb);
483}
484
485static void *hhf_zalloc(size_t sz)
486{
487 void *ptr = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN);
488
489 if (!ptr)
490 ptr = vzalloc(sz);
491
492 return ptr;
493}
494
495static void hhf_free(void *addr)
496{
497 if (addr) {
498 if (is_vmalloc_addr(addr))
499 vfree(addr);
500 else
501 kfree(addr);
502 }
503}
504
505static void hhf_destroy(struct Qdisc *sch)
506{
507 int i;
508 struct hhf_sched_data *q = qdisc_priv(sch);
509
510 for (i = 0; i < HHF_ARRAYS_CNT; i++) {
511 hhf_free(q->hhf_arrays[i]);
512 hhf_free(q->hhf_valid_bits[i]);
513 }
514
515 for (i = 0; i < HH_FLOWS_CNT; i++) {
516 struct hh_flow_state *flow, *next;
517 struct list_head *head = &q->hh_flows[i];
518
519 if (list_empty(head))
520 continue;
521 list_for_each_entry_safe(flow, next, head, flowchain) {
522 list_del(&flow->flowchain);
523 kfree(flow);
524 }
525 }
526 hhf_free(q->hh_flows);
527}
528
529static const struct nla_policy hhf_policy[TCA_HHF_MAX + 1] = {
530 [TCA_HHF_BACKLOG_LIMIT] = { .type = NLA_U32 },
531 [TCA_HHF_QUANTUM] = { .type = NLA_U32 },
532 [TCA_HHF_HH_FLOWS_LIMIT] = { .type = NLA_U32 },
533 [TCA_HHF_RESET_TIMEOUT] = { .type = NLA_U32 },
534 [TCA_HHF_ADMIT_BYTES] = { .type = NLA_U32 },
535 [TCA_HHF_EVICT_TIMEOUT] = { .type = NLA_U32 },
536 [TCA_HHF_NON_HH_WEIGHT] = { .type = NLA_U32 },
537};
538
539static int hhf_change(struct Qdisc *sch, struct nlattr *opt)
540{
541 struct hhf_sched_data *q = qdisc_priv(sch);
542 struct nlattr *tb[TCA_HHF_MAX + 1];
543 unsigned int qlen;
544 int err;
545 u64 non_hh_quantum;
546 u32 new_quantum = q->quantum;
547 u32 new_hhf_non_hh_weight = q->hhf_non_hh_weight;
548
549 if (!opt)
550 return -EINVAL;
551
552 err = nla_parse_nested(tb, TCA_HHF_MAX, opt, hhf_policy);
553 if (err < 0)
554 return err;
555
556 sch_tree_lock(sch);
557
558 if (tb[TCA_HHF_BACKLOG_LIMIT])
559 sch->limit = nla_get_u32(tb[TCA_HHF_BACKLOG_LIMIT]);
560
561 if (tb[TCA_HHF_QUANTUM])
562 new_quantum = nla_get_u32(tb[TCA_HHF_QUANTUM]);
563
564 if (tb[TCA_HHF_NON_HH_WEIGHT])
565 new_hhf_non_hh_weight = nla_get_u32(tb[TCA_HHF_NON_HH_WEIGHT]);
566
567 non_hh_quantum = (u64)new_quantum * new_hhf_non_hh_weight;
568 if (non_hh_quantum > INT_MAX)
569 return -EINVAL;
570 q->quantum = new_quantum;
571 q->hhf_non_hh_weight = new_hhf_non_hh_weight;
572
573 if (tb[TCA_HHF_HH_FLOWS_LIMIT])
574 q->hh_flows_limit = nla_get_u32(tb[TCA_HHF_HH_FLOWS_LIMIT]);
575
576 if (tb[TCA_HHF_RESET_TIMEOUT]) {
577 u32 ms = nla_get_u32(tb[TCA_HHF_RESET_TIMEOUT]);
578
579 q->hhf_reset_timeout = msecs_to_jiffies(ms);
580 }
581
582 if (tb[TCA_HHF_ADMIT_BYTES])
583 q->hhf_admit_bytes = nla_get_u32(tb[TCA_HHF_ADMIT_BYTES]);
584
585 if (tb[TCA_HHF_EVICT_TIMEOUT]) {
586 u32 ms = nla_get_u32(tb[TCA_HHF_EVICT_TIMEOUT]);
587
588 q->hhf_evict_timeout = msecs_to_jiffies(ms);
589 }
590
591 qlen = sch->q.qlen;
592 while (sch->q.qlen > sch->limit) {
593 struct sk_buff *skb = hhf_dequeue(sch);
594
595 kfree_skb(skb);
596 }
597 qdisc_tree_decrease_qlen(sch, qlen - sch->q.qlen);
598
599 sch_tree_unlock(sch);
600 return 0;
601}
602
603static int hhf_init(struct Qdisc *sch, struct nlattr *opt)
604{
605 struct hhf_sched_data *q = qdisc_priv(sch);
606 int i;
607
608 sch->limit = 1000;
609 q->quantum = psched_mtu(qdisc_dev(sch));
610 q->perturbation = net_random();
611 INIT_LIST_HEAD(&q->new_buckets);
612 INIT_LIST_HEAD(&q->old_buckets);
613
614 /* Configurable HHF parameters */
615 q->hhf_reset_timeout = HZ / 25; /* 40 ms */
616 q->hhf_admit_bytes = 131072; /* 128 KB */
617 q->hhf_evict_timeout = HZ; /* 1 sec */
618 q->hhf_non_hh_weight = 2;
619
620 if (opt) {
621 int err = hhf_change(sch, opt);
622
623 if (err)
624 return err;
625 }
626
627 if (!q->hh_flows) {
628 /* Initialize heavy-hitter flow table. */
629 q->hh_flows = hhf_zalloc(HH_FLOWS_CNT *
630 sizeof(struct list_head));
631 if (!q->hh_flows)
632 return -ENOMEM;
633 for (i = 0; i < HH_FLOWS_CNT; i++)
634 INIT_LIST_HEAD(&q->hh_flows[i]);
635
636 /* Cap max active HHs at twice len of hh_flows table. */
637 q->hh_flows_limit = 2 * HH_FLOWS_CNT;
638 q->hh_flows_overlimit = 0;
639 q->hh_flows_total_cnt = 0;
640 q->hh_flows_current_cnt = 0;
641
642 /* Initialize heavy-hitter filter arrays. */
643 for (i = 0; i < HHF_ARRAYS_CNT; i++) {
644 q->hhf_arrays[i] = hhf_zalloc(HHF_ARRAYS_LEN *
645 sizeof(u32));
646 if (!q->hhf_arrays[i]) {
647 hhf_destroy(sch);
648 return -ENOMEM;
649 }
650 }
651 q->hhf_arrays_reset_timestamp = hhf_time_stamp();
652
653 /* Initialize valid bits of heavy-hitter filter arrays. */
654 for (i = 0; i < HHF_ARRAYS_CNT; i++) {
655 q->hhf_valid_bits[i] = hhf_zalloc(HHF_ARRAYS_LEN /
656 BITS_PER_BYTE);
657 if (!q->hhf_valid_bits[i]) {
658 hhf_destroy(sch);
659 return -ENOMEM;
660 }
661 }
662
663 /* Initialize Weighted DRR buckets. */
664 for (i = 0; i < WDRR_BUCKET_CNT; i++) {
665 struct wdrr_bucket *bucket = q->buckets + i;
666
667 INIT_LIST_HEAD(&bucket->bucketchain);
668 }
669 }
670
671 return 0;
672}
673
674static int hhf_dump(struct Qdisc *sch, struct sk_buff *skb)
675{
676 struct hhf_sched_data *q = qdisc_priv(sch);
677 struct nlattr *opts;
678
679 opts = nla_nest_start(skb, TCA_OPTIONS);
680 if (opts == NULL)
681 goto nla_put_failure;
682
683 if (nla_put_u32(skb, TCA_HHF_BACKLOG_LIMIT, sch->limit) ||
684 nla_put_u32(skb, TCA_HHF_QUANTUM, q->quantum) ||
685 nla_put_u32(skb, TCA_HHF_HH_FLOWS_LIMIT, q->hh_flows_limit) ||
686 nla_put_u32(skb, TCA_HHF_RESET_TIMEOUT,
687 jiffies_to_msecs(q->hhf_reset_timeout)) ||
688 nla_put_u32(skb, TCA_HHF_ADMIT_BYTES, q->hhf_admit_bytes) ||
689 nla_put_u32(skb, TCA_HHF_EVICT_TIMEOUT,
690 jiffies_to_msecs(q->hhf_evict_timeout)) ||
691 nla_put_u32(skb, TCA_HHF_NON_HH_WEIGHT, q->hhf_non_hh_weight))
692 goto nla_put_failure;
693
694 nla_nest_end(skb, opts);
695 return skb->len;
696
697nla_put_failure:
698 return -1;
699}
700
701static int hhf_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
702{
703 struct hhf_sched_data *q = qdisc_priv(sch);
704 struct tc_hhf_xstats st = {
705 .drop_overlimit = q->drop_overlimit,
706 .hh_overlimit = q->hh_flows_overlimit,
707 .hh_tot_count = q->hh_flows_total_cnt,
708 .hh_cur_count = q->hh_flows_current_cnt,
709 };
710
711 return gnet_stats_copy_app(d, &st, sizeof(st));
712}
713
714static struct Qdisc_ops hhf_qdisc_ops __read_mostly = {
715 .id = "hhf",
716 .priv_size = sizeof(struct hhf_sched_data),
717
718 .enqueue = hhf_enqueue,
719 .dequeue = hhf_dequeue,
720 .peek = qdisc_peek_dequeued,
721 .drop = hhf_drop,
722 .init = hhf_init,
723 .reset = hhf_reset,
724 .destroy = hhf_destroy,
725 .change = hhf_change,
726 .dump = hhf_dump,
727 .dump_stats = hhf_dump_stats,
728 .owner = THIS_MODULE,
729};
730
731static int __init hhf_module_init(void)
732{
733 return register_qdisc(&hhf_qdisc_ops);
734}
735
736static void __exit hhf_module_exit(void)
737{
738 unregister_qdisc(&hhf_qdisc_ops);
739}
740
741module_init(hhf_module_init)
742module_exit(hhf_module_exit)
743MODULE_AUTHOR("Terry Lam");
744MODULE_AUTHOR("Nandita Dukkipati");
745MODULE_LICENSE("GPL");
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 0e1e38b40025..0db5a6eae87f 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -712,7 +712,7 @@ static s64 htb_do_events(struct htb_sched *q, const int level,
712 712
713 /* too much load - let's continue after a break for scheduling */ 713 /* too much load - let's continue after a break for scheduling */
714 if (!(q->warned & HTB_WARN_TOOMANYEVENTS)) { 714 if (!(q->warned & HTB_WARN_TOOMANYEVENTS)) {
715 pr_warning("htb: too many events!\n"); 715 pr_warn("htb: too many events!\n");
716 q->warned |= HTB_WARN_TOOMANYEVENTS; 716 q->warned |= HTB_WARN_TOOMANYEVENTS;
717 } 717 }
718 718
@@ -1276,9 +1276,10 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg)
1276 struct Qdisc *new_q = NULL; 1276 struct Qdisc *new_q = NULL;
1277 int last_child = 0; 1277 int last_child = 0;
1278 1278
1279 // TODO: why don't allow to delete subtree ? references ? does 1279 /* TODO: why don't allow to delete subtree ? references ? does
1280 // tc subsys quarantee us that in htb_destroy it holds no class 1280 * tc subsys guarantee us that in htb_destroy it holds no class
1281 // refs so that we can remove children safely there ? 1281 * refs so that we can remove children safely there ?
1282 */
1282 if (cl->children || cl->filter_cnt) 1283 if (cl->children || cl->filter_cnt)
1283 return -EBUSY; 1284 return -EBUSY;
1284 1285
@@ -1337,7 +1338,6 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1337 struct htb_sched *q = qdisc_priv(sch); 1338 struct htb_sched *q = qdisc_priv(sch);
1338 struct htb_class *cl = (struct htb_class *)*arg, *parent; 1339 struct htb_class *cl = (struct htb_class *)*arg, *parent;
1339 struct nlattr *opt = tca[TCA_OPTIONS]; 1340 struct nlattr *opt = tca[TCA_OPTIONS];
1340 struct qdisc_rate_table *rtab = NULL, *ctab = NULL;
1341 struct nlattr *tb[TCA_HTB_MAX + 1]; 1341 struct nlattr *tb[TCA_HTB_MAX + 1];
1342 struct tc_htb_opt *hopt; 1342 struct tc_htb_opt *hopt;
1343 u64 rate64, ceil64; 1343 u64 rate64, ceil64;
@@ -1361,16 +1361,11 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1361 goto failure; 1361 goto failure;
1362 1362
1363 /* Keeping backward compatible with rate_table based iproute2 tc */ 1363 /* Keeping backward compatible with rate_table based iproute2 tc */
1364 if (hopt->rate.linklayer == TC_LINKLAYER_UNAWARE) { 1364 if (hopt->rate.linklayer == TC_LINKLAYER_UNAWARE)
1365 rtab = qdisc_get_rtab(&hopt->rate, tb[TCA_HTB_RTAB]); 1365 qdisc_put_rtab(qdisc_get_rtab(&hopt->rate, tb[TCA_HTB_RTAB]));
1366 if (rtab) 1366
1367 qdisc_put_rtab(rtab); 1367 if (hopt->ceil.linklayer == TC_LINKLAYER_UNAWARE)
1368 } 1368 qdisc_put_rtab(qdisc_get_rtab(&hopt->ceil, tb[TCA_HTB_CTAB]));
1369 if (hopt->ceil.linklayer == TC_LINKLAYER_UNAWARE) {
1370 ctab = qdisc_get_rtab(&hopt->ceil, tb[TCA_HTB_CTAB]);
1371 if (ctab)
1372 qdisc_put_rtab(ctab);
1373 }
1374 1369
1375 if (!cl) { /* new class */ 1370 if (!cl) { /* new class */
1376 struct Qdisc *new_q; 1371 struct Qdisc *new_q;
@@ -1477,21 +1472,30 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1477 sch_tree_lock(sch); 1472 sch_tree_lock(sch);
1478 } 1473 }
1479 1474
1475 rate64 = tb[TCA_HTB_RATE64] ? nla_get_u64(tb[TCA_HTB_RATE64]) : 0;
1476
1477 ceil64 = tb[TCA_HTB_CEIL64] ? nla_get_u64(tb[TCA_HTB_CEIL64]) : 0;
1478
1479 psched_ratecfg_precompute(&cl->rate, &hopt->rate, rate64);
1480 psched_ratecfg_precompute(&cl->ceil, &hopt->ceil, ceil64);
1481
1480 /* it used to be a nasty bug here, we have to check that node 1482 /* it used to be a nasty bug here, we have to check that node
1481 * is really leaf before changing cl->un.leaf ! 1483 * is really leaf before changing cl->un.leaf !
1482 */ 1484 */
1483 if (!cl->level) { 1485 if (!cl->level) {
1484 cl->quantum = hopt->rate.rate / q->rate2quantum; 1486 u64 quantum = cl->rate.rate_bytes_ps;
1487
1488 do_div(quantum, q->rate2quantum);
1489 cl->quantum = min_t(u64, quantum, INT_MAX);
1490
1485 if (!hopt->quantum && cl->quantum < 1000) { 1491 if (!hopt->quantum && cl->quantum < 1000) {
1486 pr_warning( 1492 pr_warn("HTB: quantum of class %X is small. Consider r2q change.\n",
1487 "HTB: quantum of class %X is small. Consider r2q change.\n", 1493 cl->common.classid);
1488 cl->common.classid);
1489 cl->quantum = 1000; 1494 cl->quantum = 1000;
1490 } 1495 }
1491 if (!hopt->quantum && cl->quantum > 200000) { 1496 if (!hopt->quantum && cl->quantum > 200000) {
1492 pr_warning( 1497 pr_warn("HTB: quantum of class %X is big. Consider r2q change.\n",
1493 "HTB: quantum of class %X is big. Consider r2q change.\n", 1498 cl->common.classid);
1494 cl->common.classid);
1495 cl->quantum = 200000; 1499 cl->quantum = 200000;
1496 } 1500 }
1497 if (hopt->quantum) 1501 if (hopt->quantum)
@@ -1500,13 +1504,6 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1500 cl->prio = TC_HTB_NUMPRIO - 1; 1504 cl->prio = TC_HTB_NUMPRIO - 1;
1501 } 1505 }
1502 1506
1503 rate64 = tb[TCA_HTB_RATE64] ? nla_get_u64(tb[TCA_HTB_RATE64]) : 0;
1504
1505 ceil64 = tb[TCA_HTB_CEIL64] ? nla_get_u64(tb[TCA_HTB_CEIL64]) : 0;
1506
1507 psched_ratecfg_precompute(&cl->rate, &hopt->rate, rate64);
1508 psched_ratecfg_precompute(&cl->ceil, &hopt->ceil, ceil64);
1509
1510 cl->buffer = PSCHED_TICKS2NS(hopt->buffer); 1507 cl->buffer = PSCHED_TICKS2NS(hopt->buffer);
1511 cl->cbuffer = PSCHED_TICKS2NS(hopt->cbuffer); 1508 cl->cbuffer = PSCHED_TICKS2NS(hopt->cbuffer);
1512 1509
diff --git a/net/sched/sch_mq.c b/net/sched/sch_mq.c
index 2e56185736d6..a8b2864a696b 100644
--- a/net/sched/sch_mq.c
+++ b/net/sched/sch_mq.c
@@ -78,14 +78,19 @@ static void mq_attach(struct Qdisc *sch)
78{ 78{
79 struct net_device *dev = qdisc_dev(sch); 79 struct net_device *dev = qdisc_dev(sch);
80 struct mq_sched *priv = qdisc_priv(sch); 80 struct mq_sched *priv = qdisc_priv(sch);
81 struct Qdisc *qdisc; 81 struct Qdisc *qdisc, *old;
82 unsigned int ntx; 82 unsigned int ntx;
83 83
84 for (ntx = 0; ntx < dev->num_tx_queues; ntx++) { 84 for (ntx = 0; ntx < dev->num_tx_queues; ntx++) {
85 qdisc = priv->qdiscs[ntx]; 85 qdisc = priv->qdiscs[ntx];
86 qdisc = dev_graft_qdisc(qdisc->dev_queue, qdisc); 86 old = dev_graft_qdisc(qdisc->dev_queue, qdisc);
87 if (qdisc) 87 if (old)
88 qdisc_destroy(qdisc); 88 qdisc_destroy(old);
89#ifdef CONFIG_NET_SCHED
90 if (ntx < dev->real_num_tx_queues)
91 qdisc_list_add(qdisc);
92#endif
93
89 } 94 }
90 kfree(priv->qdiscs); 95 kfree(priv->qdiscs);
91 priv->qdiscs = NULL; 96 priv->qdiscs = NULL;
diff --git a/net/sched/sch_mqprio.c b/net/sched/sch_mqprio.c
index d44c868cb537..6749e2f540d0 100644
--- a/net/sched/sch_mqprio.c
+++ b/net/sched/sch_mqprio.c
@@ -167,15 +167,17 @@ static void mqprio_attach(struct Qdisc *sch)
167{ 167{
168 struct net_device *dev = qdisc_dev(sch); 168 struct net_device *dev = qdisc_dev(sch);
169 struct mqprio_sched *priv = qdisc_priv(sch); 169 struct mqprio_sched *priv = qdisc_priv(sch);
170 struct Qdisc *qdisc; 170 struct Qdisc *qdisc, *old;
171 unsigned int ntx; 171 unsigned int ntx;
172 172
173 /* Attach underlying qdisc */ 173 /* Attach underlying qdisc */
174 for (ntx = 0; ntx < dev->num_tx_queues; ntx++) { 174 for (ntx = 0; ntx < dev->num_tx_queues; ntx++) {
175 qdisc = priv->qdiscs[ntx]; 175 qdisc = priv->qdiscs[ntx];
176 qdisc = dev_graft_qdisc(qdisc->dev_queue, qdisc); 176 old = dev_graft_qdisc(qdisc->dev_queue, qdisc);
177 if (qdisc) 177 if (old)
178 qdisc_destroy(qdisc); 178 qdisc_destroy(old);
179 if (ntx < dev->real_num_tx_queues)
180 qdisc_list_add(qdisc);
179 } 181 }
180 kfree(priv->qdiscs); 182 kfree(priv->qdiscs);
181 priv->qdiscs = NULL; 183 priv->qdiscs = NULL;
diff --git a/net/sched/sch_multiq.c b/net/sched/sch_multiq.c
index 2a2b096d9a66..afb050a735fa 100644
--- a/net/sched/sch_multiq.c
+++ b/net/sched/sch_multiq.c
@@ -11,8 +11,7 @@
11 * more details. 11 * more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License along with 13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 14 * this program; if not, see <http://www.gnu.org/licenses/>.
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 * 15 *
17 * Author: Alexander Duyck <alexander.h.duyck@intel.com> 16 * Author: Alexander Duyck <alexander.h.duyck@intel.com>
18 */ 17 */
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 75c94e59a3bd..090a4e3ecd0d 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -88,7 +88,7 @@ struct netem_sched_data {
88 u32 duplicate; 88 u32 duplicate;
89 u32 reorder; 89 u32 reorder;
90 u32 corrupt; 90 u32 corrupt;
91 u32 rate; 91 u64 rate;
92 s32 packet_overhead; 92 s32 packet_overhead;
93 u32 cell_size; 93 u32 cell_size;
94 u32 cell_size_reciprocal; 94 u32 cell_size_reciprocal;
@@ -215,10 +215,10 @@ static bool loss_4state(struct netem_sched_data *q)
215 if (rnd < clg->a4) { 215 if (rnd < clg->a4) {
216 clg->state = 4; 216 clg->state = 4;
217 return true; 217 return true;
218 } else if (clg->a4 < rnd && rnd < clg->a1) { 218 } else if (clg->a4 < rnd && rnd < clg->a1 + clg->a4) {
219 clg->state = 3; 219 clg->state = 3;
220 return true; 220 return true;
221 } else if (clg->a1 < rnd) 221 } else if (clg->a1 + clg->a4 < rnd)
222 clg->state = 1; 222 clg->state = 1;
223 223
224 break; 224 break;
@@ -268,10 +268,11 @@ static bool loss_gilb_ell(struct netem_sched_data *q)
268 clg->state = 2; 268 clg->state = 2;
269 if (net_random() < clg->a4) 269 if (net_random() < clg->a4)
270 return true; 270 return true;
271 break;
271 case 2: 272 case 2:
272 if (net_random() < clg->a2) 273 if (net_random() < clg->a2)
273 clg->state = 1; 274 clg->state = 1;
274 if (clg->a3 > net_random()) 275 if (net_random() > clg->a3)
275 return true; 276 return true;
276 } 277 }
277 278
@@ -494,7 +495,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
494 now = netem_skb_cb(last)->time_to_send; 495 now = netem_skb_cb(last)->time_to_send;
495 } 496 }
496 497
497 delay += packet_len_2_sched_time(skb->len, q); 498 delay += packet_len_2_sched_time(qdisc_pkt_len(skb), q);
498 } 499 }
499 500
500 cb->time_to_send = now + delay; 501 cb->time_to_send = now + delay;
@@ -728,7 +729,7 @@ static int get_loss_clg(struct Qdisc *sch, const struct nlattr *attr)
728 nla_for_each_nested(la, attr, rem) { 729 nla_for_each_nested(la, attr, rem) {
729 u16 type = nla_type(la); 730 u16 type = nla_type(la);
730 731
731 switch(type) { 732 switch (type) {
732 case NETEM_LOSS_GI: { 733 case NETEM_LOSS_GI: {
733 const struct tc_netem_gimodel *gi = nla_data(la); 734 const struct tc_netem_gimodel *gi = nla_data(la);
734 735
@@ -781,6 +782,7 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
781 [TCA_NETEM_RATE] = { .len = sizeof(struct tc_netem_rate) }, 782 [TCA_NETEM_RATE] = { .len = sizeof(struct tc_netem_rate) },
782 [TCA_NETEM_LOSS] = { .type = NLA_NESTED }, 783 [TCA_NETEM_LOSS] = { .type = NLA_NESTED },
783 [TCA_NETEM_ECN] = { .type = NLA_U32 }, 784 [TCA_NETEM_ECN] = { .type = NLA_U32 },
785 [TCA_NETEM_RATE64] = { .type = NLA_U64 },
784}; 786};
785 787
786static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla, 788static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
@@ -851,6 +853,10 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
851 if (tb[TCA_NETEM_RATE]) 853 if (tb[TCA_NETEM_RATE])
852 get_rate(sch, tb[TCA_NETEM_RATE]); 854 get_rate(sch, tb[TCA_NETEM_RATE]);
853 855
856 if (tb[TCA_NETEM_RATE64])
857 q->rate = max_t(u64, q->rate,
858 nla_get_u64(tb[TCA_NETEM_RATE64]));
859
854 if (tb[TCA_NETEM_ECN]) 860 if (tb[TCA_NETEM_ECN])
855 q->ecn = nla_get_u32(tb[TCA_NETEM_ECN]); 861 q->ecn = nla_get_u32(tb[TCA_NETEM_ECN]);
856 862
@@ -973,7 +979,13 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
973 if (nla_put(skb, TCA_NETEM_CORRUPT, sizeof(corrupt), &corrupt)) 979 if (nla_put(skb, TCA_NETEM_CORRUPT, sizeof(corrupt), &corrupt))
974 goto nla_put_failure; 980 goto nla_put_failure;
975 981
976 rate.rate = q->rate; 982 if (q->rate >= (1ULL << 32)) {
983 if (nla_put_u64(skb, TCA_NETEM_RATE64, q->rate))
984 goto nla_put_failure;
985 rate.rate = ~0U;
986 } else {
987 rate.rate = q->rate;
988 }
977 rate.packet_overhead = q->packet_overhead; 989 rate.packet_overhead = q->packet_overhead;
978 rate.cell_size = q->cell_size; 990 rate.cell_size = q->cell_size;
979 rate.cell_overhead = q->cell_overhead; 991 rate.cell_overhead = q->cell_overhead;
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index d3a1bc26dbfc..76f01e0258df 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -237,10 +237,12 @@ static inline void sfq_link(struct sfq_sched_data *q, sfq_index x)
237} 237}
238 238
239#define sfq_unlink(q, x, n, p) \ 239#define sfq_unlink(q, x, n, p) \
240 n = q->slots[x].dep.next; \ 240 do { \
241 p = q->slots[x].dep.prev; \ 241 n = q->slots[x].dep.next; \
242 sfq_dep_head(q, p)->next = n; \ 242 p = q->slots[x].dep.prev; \
243 sfq_dep_head(q, n)->prev = p 243 sfq_dep_head(q, p)->next = n; \
244 sfq_dep_head(q, n)->prev = p; \
245 } while (0)
244 246
245 247
246static inline void sfq_dec(struct sfq_sched_data *q, sfq_index x) 248static inline void sfq_dec(struct sfq_sched_data *q, sfq_index x)
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index 68f98595819c..fbba5b0ec121 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -21,6 +21,7 @@
21#include <net/netlink.h> 21#include <net/netlink.h>
22#include <net/sch_generic.h> 22#include <net/sch_generic.h>
23#include <net/pkt_sched.h> 23#include <net/pkt_sched.h>
24#include <net/tcp.h>
24 25
25 26
26/* Simple Token Bucket Filter. 27/* Simple Token Bucket Filter.
@@ -117,6 +118,48 @@ struct tbf_sched_data {
117}; 118};
118 119
119 120
121/* Time to Length, convert time in ns to length in bytes
122 * to determinate how many bytes can be sent in given time.
123 */
124static u64 psched_ns_t2l(const struct psched_ratecfg *r,
125 u64 time_in_ns)
126{
127 /* The formula is :
128 * len = (time_in_ns * r->rate_bytes_ps) / NSEC_PER_SEC
129 */
130 u64 len = time_in_ns * r->rate_bytes_ps;
131
132 do_div(len, NSEC_PER_SEC);
133
134 if (unlikely(r->linklayer == TC_LINKLAYER_ATM)) {
135 do_div(len, 53);
136 len = len * 48;
137 }
138
139 if (len > r->overhead)
140 len -= r->overhead;
141 else
142 len = 0;
143
144 return len;
145}
146
147/*
148 * Return length of individual segments of a gso packet,
149 * including all headers (MAC, IP, TCP/UDP)
150 */
151static unsigned int skb_gso_seglen(const struct sk_buff *skb)
152{
153 unsigned int hdr_len = skb_transport_header(skb) - skb_mac_header(skb);
154 const struct skb_shared_info *shinfo = skb_shinfo(skb);
155
156 if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))
157 hdr_len += tcp_hdrlen(skb);
158 else
159 hdr_len += sizeof(struct udphdr);
160 return hdr_len + shinfo->gso_size;
161}
162
120/* GSO packet is too big, segment it so that tbf can transmit 163/* GSO packet is too big, segment it so that tbf can transmit
121 * each segment in time 164 * each segment in time
122 */ 165 */
@@ -136,12 +179,8 @@ static int tbf_segment(struct sk_buff *skb, struct Qdisc *sch)
136 while (segs) { 179 while (segs) {
137 nskb = segs->next; 180 nskb = segs->next;
138 segs->next = NULL; 181 segs->next = NULL;
139 if (likely(segs->len <= q->max_size)) { 182 qdisc_skb_cb(segs)->pkt_len = segs->len;
140 qdisc_skb_cb(segs)->pkt_len = segs->len; 183 ret = qdisc_enqueue(segs, q->qdisc);
141 ret = qdisc_enqueue(segs, q->qdisc);
142 } else {
143 ret = qdisc_reshape_fail(skb, sch);
144 }
145 if (ret != NET_XMIT_SUCCESS) { 184 if (ret != NET_XMIT_SUCCESS) {
146 if (net_xmit_drop_count(ret)) 185 if (net_xmit_drop_count(ret))
147 sch->qstats.drops++; 186 sch->qstats.drops++;
@@ -163,7 +202,7 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc *sch)
163 int ret; 202 int ret;
164 203
165 if (qdisc_pkt_len(skb) > q->max_size) { 204 if (qdisc_pkt_len(skb) > q->max_size) {
166 if (skb_is_gso(skb)) 205 if (skb_is_gso(skb) && skb_gso_seglen(skb) <= q->max_size)
167 return tbf_segment(skb, sch); 206 return tbf_segment(skb, sch);
168 return qdisc_reshape_fail(skb, sch); 207 return qdisc_reshape_fail(skb, sch);
169 } 208 }
@@ -268,6 +307,8 @@ static const struct nla_policy tbf_policy[TCA_TBF_MAX + 1] = {
268 [TCA_TBF_PTAB] = { .type = NLA_BINARY, .len = TC_RTAB_SIZE }, 307 [TCA_TBF_PTAB] = { .type = NLA_BINARY, .len = TC_RTAB_SIZE },
269 [TCA_TBF_RATE64] = { .type = NLA_U64 }, 308 [TCA_TBF_RATE64] = { .type = NLA_U64 },
270 [TCA_TBF_PRATE64] = { .type = NLA_U64 }, 309 [TCA_TBF_PRATE64] = { .type = NLA_U64 },
310 [TCA_TBF_BURST] = { .type = NLA_U32 },
311 [TCA_TBF_PBURST] = { .type = NLA_U32 },
271}; 312};
272 313
273static int tbf_change(struct Qdisc *sch, struct nlattr *opt) 314static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
@@ -276,10 +317,11 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
276 struct tbf_sched_data *q = qdisc_priv(sch); 317 struct tbf_sched_data *q = qdisc_priv(sch);
277 struct nlattr *tb[TCA_TBF_MAX + 1]; 318 struct nlattr *tb[TCA_TBF_MAX + 1];
278 struct tc_tbf_qopt *qopt; 319 struct tc_tbf_qopt *qopt;
279 struct qdisc_rate_table *rtab = NULL;
280 struct qdisc_rate_table *ptab = NULL;
281 struct Qdisc *child = NULL; 320 struct Qdisc *child = NULL;
282 int max_size, n; 321 struct psched_ratecfg rate;
322 struct psched_ratecfg peak;
323 u64 max_size;
324 s64 buffer, mtu;
283 u64 rate64 = 0, prate64 = 0; 325 u64 rate64 = 0, prate64 = 0;
284 326
285 err = nla_parse_nested(tb, TCA_TBF_MAX, opt, tbf_policy); 327 err = nla_parse_nested(tb, TCA_TBF_MAX, opt, tbf_policy);
@@ -291,33 +333,13 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
291 goto done; 333 goto done;
292 334
293 qopt = nla_data(tb[TCA_TBF_PARMS]); 335 qopt = nla_data(tb[TCA_TBF_PARMS]);
294 rtab = qdisc_get_rtab(&qopt->rate, tb[TCA_TBF_RTAB]); 336 if (qopt->rate.linklayer == TC_LINKLAYER_UNAWARE)
295 if (rtab == NULL) 337 qdisc_put_rtab(qdisc_get_rtab(&qopt->rate,
296 goto done; 338 tb[TCA_TBF_RTAB]));
297 339
298 if (qopt->peakrate.rate) { 340 if (qopt->peakrate.linklayer == TC_LINKLAYER_UNAWARE)
299 if (qopt->peakrate.rate > qopt->rate.rate) 341 qdisc_put_rtab(qdisc_get_rtab(&qopt->peakrate,
300 ptab = qdisc_get_rtab(&qopt->peakrate, tb[TCA_TBF_PTAB]); 342 tb[TCA_TBF_PTAB]));
301 if (ptab == NULL)
302 goto done;
303 }
304
305 for (n = 0; n < 256; n++)
306 if (rtab->data[n] > qopt->buffer)
307 break;
308 max_size = (n << qopt->rate.cell_log) - 1;
309 if (ptab) {
310 int size;
311
312 for (n = 0; n < 256; n++)
313 if (ptab->data[n] > qopt->mtu)
314 break;
315 size = (n << qopt->peakrate.cell_log) - 1;
316 if (size < max_size)
317 max_size = size;
318 }
319 if (max_size < 0)
320 goto done;
321 343
322 if (q->qdisc != &noop_qdisc) { 344 if (q->qdisc != &noop_qdisc) {
323 err = fifo_set_limit(q->qdisc, qopt->limit); 345 err = fifo_set_limit(q->qdisc, qopt->limit);
@@ -331,6 +353,50 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
331 } 353 }
332 } 354 }
333 355
356 buffer = min_t(u64, PSCHED_TICKS2NS(qopt->buffer), ~0U);
357 mtu = min_t(u64, PSCHED_TICKS2NS(qopt->mtu), ~0U);
358
359 if (tb[TCA_TBF_RATE64])
360 rate64 = nla_get_u64(tb[TCA_TBF_RATE64]);
361 psched_ratecfg_precompute(&rate, &qopt->rate, rate64);
362
363 if (tb[TCA_TBF_BURST]) {
364 max_size = nla_get_u32(tb[TCA_TBF_BURST]);
365 buffer = psched_l2t_ns(&rate, max_size);
366 } else {
367 max_size = min_t(u64, psched_ns_t2l(&rate, buffer), ~0U);
368 }
369
370 if (qopt->peakrate.rate) {
371 if (tb[TCA_TBF_PRATE64])
372 prate64 = nla_get_u64(tb[TCA_TBF_PRATE64]);
373 psched_ratecfg_precompute(&peak, &qopt->peakrate, prate64);
374 if (peak.rate_bytes_ps <= rate.rate_bytes_ps) {
375 pr_warn_ratelimited("sch_tbf: peakrate %llu is lower than or equals to rate %llu !\n",
376 peak.rate_bytes_ps, rate.rate_bytes_ps);
377 err = -EINVAL;
378 goto done;
379 }
380
381 if (tb[TCA_TBF_PBURST]) {
382 u32 pburst = nla_get_u32(tb[TCA_TBF_PBURST]);
383 max_size = min_t(u32, max_size, pburst);
384 mtu = psched_l2t_ns(&peak, pburst);
385 } else {
386 max_size = min_t(u64, max_size, psched_ns_t2l(&peak, mtu));
387 }
388 }
389
390 if (max_size < psched_mtu(qdisc_dev(sch)))
391 pr_warn_ratelimited("sch_tbf: burst %llu is lower than device %s mtu (%u) !\n",
392 max_size, qdisc_dev(sch)->name,
393 psched_mtu(qdisc_dev(sch)));
394
395 if (!max_size) {
396 err = -EINVAL;
397 goto done;
398 }
399
334 sch_tree_lock(sch); 400 sch_tree_lock(sch);
335 if (child) { 401 if (child) {
336 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen); 402 qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen);
@@ -338,19 +404,21 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
338 q->qdisc = child; 404 q->qdisc = child;
339 } 405 }
340 q->limit = qopt->limit; 406 q->limit = qopt->limit;
341 q->mtu = PSCHED_TICKS2NS(qopt->mtu); 407 if (tb[TCA_TBF_PBURST])
408 q->mtu = mtu;
409 else
410 q->mtu = PSCHED_TICKS2NS(qopt->mtu);
342 q->max_size = max_size; 411 q->max_size = max_size;
343 q->buffer = PSCHED_TICKS2NS(qopt->buffer); 412 if (tb[TCA_TBF_BURST])
413 q->buffer = buffer;
414 else
415 q->buffer = PSCHED_TICKS2NS(qopt->buffer);
344 q->tokens = q->buffer; 416 q->tokens = q->buffer;
345 q->ptokens = q->mtu; 417 q->ptokens = q->mtu;
346 418
347 if (tb[TCA_TBF_RATE64]) 419 memcpy(&q->rate, &rate, sizeof(struct psched_ratecfg));
348 rate64 = nla_get_u64(tb[TCA_TBF_RATE64]); 420 if (qopt->peakrate.rate) {
349 psched_ratecfg_precompute(&q->rate, &rtab->rate, rate64); 421 memcpy(&q->peak, &peak, sizeof(struct psched_ratecfg));
350 if (ptab) {
351 if (tb[TCA_TBF_PRATE64])
352 prate64 = nla_get_u64(tb[TCA_TBF_PRATE64]);
353 psched_ratecfg_precompute(&q->peak, &ptab->rate, prate64);
354 q->peak_present = true; 422 q->peak_present = true;
355 } else { 423 } else {
356 q->peak_present = false; 424 q->peak_present = false;
@@ -359,10 +427,6 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
359 sch_tree_unlock(sch); 427 sch_tree_unlock(sch);
360 err = 0; 428 err = 0;
361done: 429done:
362 if (rtab)
363 qdisc_put_rtab(rtab);
364 if (ptab)
365 qdisc_put_rtab(ptab);
366 return err; 430 return err;
367} 431}
368 432
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index 68a27f9796d2..5ae609200674 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -22,9 +22,8 @@
22 * See the GNU General Public License for more details. 22 * See the GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to 25 * along with GNU CC; see the file COPYING. If not, see
26 * the Free Software Foundation, 59 Temple Place - Suite 330, 26 * <http://www.gnu.org/licenses/>.
27 * Boston, MA 02111-1307, USA.
28 * 27 *
29 * Please send any bug reports or fixes you make to the 28 * Please send any bug reports or fixes you make to the
30 * email address(es): 29 * email address(es):
@@ -90,14 +89,12 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
90 89
91 /* Initialize the object handling fields. */ 90 /* Initialize the object handling fields. */
92 atomic_set(&asoc->base.refcnt, 1); 91 atomic_set(&asoc->base.refcnt, 1);
93 asoc->base.dead = false;
94 92
95 /* Initialize the bind addr area. */ 93 /* Initialize the bind addr area. */
96 sctp_bind_addr_init(&asoc->base.bind_addr, ep->base.bind_addr.port); 94 sctp_bind_addr_init(&asoc->base.bind_addr, ep->base.bind_addr.port);
97 95
98 asoc->state = SCTP_STATE_CLOSED; 96 asoc->state = SCTP_STATE_CLOSED;
99 asoc->cookie_life = ms_to_ktime(sp->assocparams.sasoc_cookie_life); 97 asoc->cookie_life = ms_to_ktime(sp->assocparams.sasoc_cookie_life);
100 asoc->frag_point = 0;
101 asoc->user_frag = sp->user_frag; 98 asoc->user_frag = sp->user_frag;
102 99
103 /* Set the association max_retrans and RTO values from the 100 /* Set the association max_retrans and RTO values from the
@@ -110,8 +107,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
110 asoc->rto_max = msecs_to_jiffies(sp->rtoinfo.srto_max); 107 asoc->rto_max = msecs_to_jiffies(sp->rtoinfo.srto_max);
111 asoc->rto_min = msecs_to_jiffies(sp->rtoinfo.srto_min); 108 asoc->rto_min = msecs_to_jiffies(sp->rtoinfo.srto_min);
112 109
113 asoc->overall_error_count = 0;
114
115 /* Initialize the association's heartbeat interval based on the 110 /* Initialize the association's heartbeat interval based on the
116 * sock configured value. 111 * sock configured value.
117 */ 112 */
@@ -132,18 +127,15 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
132 */ 127 */
133 asoc->param_flags = sp->param_flags; 128 asoc->param_flags = sp->param_flags;
134 129
135 /* Initialize the maximum mumber of new data packets that can be sent 130 /* Initialize the maximum number of new data packets that can be sent
136 * in a burst. 131 * in a burst.
137 */ 132 */
138 asoc->max_burst = sp->max_burst; 133 asoc->max_burst = sp->max_burst;
139 134
140 /* initialize association timers */ 135 /* initialize association timers */
141 asoc->timeouts[SCTP_EVENT_TIMEOUT_NONE] = 0;
142 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = asoc->rto_initial; 136 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = asoc->rto_initial;
143 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = asoc->rto_initial; 137 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = asoc->rto_initial;
144 asoc->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = asoc->rto_initial; 138 asoc->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = asoc->rto_initial;
145 asoc->timeouts[SCTP_EVENT_TIMEOUT_T3_RTX] = 0;
146 asoc->timeouts[SCTP_EVENT_TIMEOUT_T4_RTO] = 0;
147 139
148 /* sctpimpguide Section 2.12.2 140 /* sctpimpguide Section 2.12.2
149 * If the 'T5-shutdown-guard' timer is used, it SHOULD be set to the 141 * If the 'T5-shutdown-guard' timer is used, it SHOULD be set to the
@@ -152,10 +144,8 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
152 asoc->timeouts[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD] 144 asoc->timeouts[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]
153 = 5 * asoc->rto_max; 145 = 5 * asoc->rto_max;
154 146
155 asoc->timeouts[SCTP_EVENT_TIMEOUT_HEARTBEAT] = 0;
156 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] = asoc->sackdelay; 147 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] = asoc->sackdelay;
157 asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = 148 asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = sp->autoclose * HZ;
158 min_t(unsigned long, sp->autoclose, net->sctp.max_autoclose) * HZ;
159 149
160 /* Initializes the timers */ 150 /* Initializes the timers */
161 for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) 151 for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i)
@@ -173,11 +163,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
173 asoc->max_init_timeo = 163 asoc->max_init_timeo =
174 msecs_to_jiffies(sp->initmsg.sinit_max_init_timeo); 164 msecs_to_jiffies(sp->initmsg.sinit_max_init_timeo);
175 165
176 /* Allocate storage for the ssnmap after the inbound and outbound
177 * streams have been negotiated during Init.
178 */
179 asoc->ssnmap = NULL;
180
181 /* Set the local window size for receive. 166 /* Set the local window size for receive.
182 * This is also the rcvbuf space per association. 167 * This is also the rcvbuf space per association.
183 * RFC 6 - A SCTP receiver MUST be able to receive a minimum of 168 * RFC 6 - A SCTP receiver MUST be able to receive a minimum of
@@ -190,25 +175,15 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
190 175
191 asoc->a_rwnd = asoc->rwnd; 176 asoc->a_rwnd = asoc->rwnd;
192 177
193 asoc->rwnd_over = 0;
194 asoc->rwnd_press = 0;
195
196 /* Use my own max window until I learn something better. */ 178 /* Use my own max window until I learn something better. */
197 asoc->peer.rwnd = SCTP_DEFAULT_MAXWINDOW; 179 asoc->peer.rwnd = SCTP_DEFAULT_MAXWINDOW;
198 180
199 /* Set the sndbuf size for transmit. */
200 asoc->sndbuf_used = 0;
201
202 /* Initialize the receive memory counter */ 181 /* Initialize the receive memory counter */
203 atomic_set(&asoc->rmem_alloc, 0); 182 atomic_set(&asoc->rmem_alloc, 0);
204 183
205 init_waitqueue_head(&asoc->wait); 184 init_waitqueue_head(&asoc->wait);
206 185
207 asoc->c.my_vtag = sctp_generate_tag(ep); 186 asoc->c.my_vtag = sctp_generate_tag(ep);
208 asoc->peer.i.init_tag = 0; /* INIT needs a vtag of 0. */
209 asoc->c.peer_vtag = 0;
210 asoc->c.my_ttag = 0;
211 asoc->c.peer_ttag = 0;
212 asoc->c.my_port = ep->base.bind_addr.port; 187 asoc->c.my_port = ep->base.bind_addr.port;
213 188
214 asoc->c.initial_tsn = sctp_generate_tsn(ep); 189 asoc->c.initial_tsn = sctp_generate_tsn(ep);
@@ -219,7 +194,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
219 asoc->adv_peer_ack_point = asoc->ctsn_ack_point; 194 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
220 asoc->highest_sacked = asoc->ctsn_ack_point; 195 asoc->highest_sacked = asoc->ctsn_ack_point;
221 asoc->last_cwr_tsn = asoc->ctsn_ack_point; 196 asoc->last_cwr_tsn = asoc->ctsn_ack_point;
222 asoc->unack_data = 0;
223 197
224 /* ADDIP Section 4.1 Asconf Chunk Procedures 198 /* ADDIP Section 4.1 Asconf Chunk Procedures
225 * 199 *
@@ -238,7 +212,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
238 212
239 /* Make an empty list of remote transport addresses. */ 213 /* Make an empty list of remote transport addresses. */
240 INIT_LIST_HEAD(&asoc->peer.transport_addr_list); 214 INIT_LIST_HEAD(&asoc->peer.transport_addr_list);
241 asoc->peer.transport_count = 0;
242 215
243 /* RFC 2960 5.1 Normal Establishment of an Association 216 /* RFC 2960 5.1 Normal Establishment of an Association
244 * 217 *
@@ -252,20 +225,15 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
252 * already received one packet.] 225 * already received one packet.]
253 */ 226 */
254 asoc->peer.sack_needed = 1; 227 asoc->peer.sack_needed = 1;
255 asoc->peer.sack_cnt = 0;
256 asoc->peer.sack_generation = 1; 228 asoc->peer.sack_generation = 1;
257 229
258 /* Assume that the peer will tell us if he recognizes ASCONF 230 /* Assume that the peer will tell us if he recognizes ASCONF
259 * as part of INIT exchange. 231 * as part of INIT exchange.
260 * The sctp_addip_noauth option is there for backward compatibilty 232 * The sctp_addip_noauth option is there for backward compatibility
261 * and will revert old behavior. 233 * and will revert old behavior.
262 */ 234 */
263 asoc->peer.asconf_capable = 0;
264 if (net->sctp.addip_noauth) 235 if (net->sctp.addip_noauth)
265 asoc->peer.asconf_capable = 1; 236 asoc->peer.asconf_capable = 1;
266 asoc->asconf_addr_del_pending = NULL;
267 asoc->src_out_of_asoc_ok = 0;
268 asoc->new_transport = NULL;
269 237
270 /* Create an input queue. */ 238 /* Create an input queue. */
271 sctp_inq_init(&asoc->base.inqueue); 239 sctp_inq_init(&asoc->base.inqueue);
@@ -277,12 +245,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
277 if (!sctp_ulpq_init(&asoc->ulpq, asoc)) 245 if (!sctp_ulpq_init(&asoc->ulpq, asoc))
278 goto fail_init; 246 goto fail_init;
279 247
280 memset(&asoc->peer.tsn_map, 0, sizeof(struct sctp_tsnmap));
281
282 asoc->need_ecne = 0;
283
284 asoc->assoc_id = 0;
285
286 /* Assume that peer would support both address types unless we are 248 /* Assume that peer would support both address types unless we are
287 * told otherwise. 249 * told otherwise.
288 */ 250 */
@@ -291,8 +253,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
291 asoc->peer.ipv6_address = 1; 253 asoc->peer.ipv6_address = 1;
292 INIT_LIST_HEAD(&asoc->asocs); 254 INIT_LIST_HEAD(&asoc->asocs);
293 255
294 asoc->autoclose = sp->autoclose;
295
296 asoc->default_stream = sp->default_stream; 256 asoc->default_stream = sp->default_stream;
297 asoc->default_ppid = sp->default_ppid; 257 asoc->default_ppid = sp->default_ppid;
298 asoc->default_flags = sp->default_flags; 258 asoc->default_flags = sp->default_flags;
@@ -300,9 +260,6 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
300 asoc->default_timetolive = sp->default_timetolive; 260 asoc->default_timetolive = sp->default_timetolive;
301 asoc->default_rcv_context = sp->default_rcv_context; 261 asoc->default_rcv_context = sp->default_rcv_context;
302 262
303 /* SCTP_GET_ASSOC_STATS COUNTERS */
304 memset(&asoc->stats, 0, sizeof(struct sctp_priv_assoc_stats));
305
306 /* AUTH related initializations */ 263 /* AUTH related initializations */
307 INIT_LIST_HEAD(&asoc->endpoint_shared_keys); 264 INIT_LIST_HEAD(&asoc->endpoint_shared_keys);
308 err = sctp_auth_asoc_copy_shkeys(ep, asoc, gfp); 265 err = sctp_auth_asoc_copy_shkeys(ep, asoc, gfp);
@@ -310,9 +267,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
310 goto fail_init; 267 goto fail_init;
311 268
312 asoc->active_key_id = ep->active_key_id; 269 asoc->active_key_id = ep->active_key_id;
313 asoc->asoc_shared_key = NULL;
314 270
315 asoc->default_hmac_id = 0;
316 /* Save the hmacs and chunks list into this association */ 271 /* Save the hmacs and chunks list into this association */
317 if (ep->auth_hmacs_list) 272 if (ep->auth_hmacs_list)
318 memcpy(asoc->c.auth_hmacs, ep->auth_hmacs_list, 273 memcpy(asoc->c.auth_hmacs, ep->auth_hmacs_list,
@@ -997,17 +952,13 @@ int sctp_cmp_addr_exact(const union sctp_addr *ss1,
997 */ 952 */
998struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc) 953struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc)
999{ 954{
1000 struct sctp_chunk *chunk; 955 if (!asoc->need_ecne)
956 return NULL;
1001 957
1002 /* Send ECNE if needed. 958 /* Send ECNE if needed.
1003 * Not being able to allocate a chunk here is not deadly. 959 * Not being able to allocate a chunk here is not deadly.
1004 */ 960 */
1005 if (asoc->need_ecne) 961 return sctp_make_ecne(asoc, asoc->last_ecne_tsn);
1006 chunk = sctp_make_ecne(asoc, asoc->last_ecne_tsn);
1007 else
1008 chunk = NULL;
1009
1010 return chunk;
1011} 962}
1012 963
1013/* 964/*
@@ -1268,7 +1219,7 @@ void sctp_assoc_update(struct sctp_association *asoc,
1268 } 1219 }
1269 } 1220 }
1270 1221
1271 /* SCTP-AUTH: Save the peer parameters from the new assocaitions 1222 /* SCTP-AUTH: Save the peer parameters from the new associations
1272 * and also move the association shared keys over 1223 * and also move the association shared keys over
1273 */ 1224 */
1274 kfree(asoc->peer.peer_random); 1225 kfree(asoc->peer.peer_random);
@@ -1396,7 +1347,7 @@ void sctp_assoc_sync_pmtu(struct sock *sk, struct sctp_association *asoc)
1396} 1347}
1397 1348
1398/* Should we send a SACK to update our peer? */ 1349/* Should we send a SACK to update our peer? */
1399static inline int sctp_peer_needs_update(struct sctp_association *asoc) 1350static inline bool sctp_peer_needs_update(struct sctp_association *asoc)
1400{ 1351{
1401 struct net *net = sock_net(asoc->base.sk); 1352 struct net *net = sock_net(asoc->base.sk);
1402 switch (asoc->state) { 1353 switch (asoc->state) {
@@ -1408,12 +1359,12 @@ static inline int sctp_peer_needs_update(struct sctp_association *asoc)
1408 ((asoc->rwnd - asoc->a_rwnd) >= max_t(__u32, 1359 ((asoc->rwnd - asoc->a_rwnd) >= max_t(__u32,
1409 (asoc->base.sk->sk_rcvbuf >> net->sctp.rwnd_upd_shift), 1360 (asoc->base.sk->sk_rcvbuf >> net->sctp.rwnd_upd_shift),
1410 asoc->pathmtu))) 1361 asoc->pathmtu)))
1411 return 1; 1362 return true;
1412 break; 1363 break;
1413 default: 1364 default:
1414 break; 1365 break;
1415 } 1366 }
1416 return 0; 1367 return false;
1417} 1368}
1418 1369
1419/* Increase asoc's rwnd by len and send any window update SACK if needed. */ 1370/* Increase asoc's rwnd by len and send any window update SACK if needed. */
@@ -1493,7 +1444,7 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned int len)
1493 1444
1494 /* If we've reached or overflowed our receive buffer, announce 1445 /* If we've reached or overflowed our receive buffer, announce
1495 * a 0 rwnd if rwnd would still be positive. Store the 1446 * a 0 rwnd if rwnd would still be positive. Store the
1496 * the pottential pressure overflow so that the window can be restored 1447 * the potential pressure overflow so that the window can be restored
1497 * back to original value. 1448 * back to original value.
1498 */ 1449 */
1499 if (rx_count >= asoc->base.sk->sk_rcvbuf) 1450 if (rx_count >= asoc->base.sk->sk_rcvbuf)
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index 46b5977978a1..683c7d1b1306 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -16,9 +16,8 @@
16 * See the GNU General Public License for more details. 16 * See the GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with GNU CC; see the file COPYING. If not, write to 19 * along with GNU CC; see the file COPYING. If not, see
20 * the Free Software Foundation, 59 Temple Place - Suite 330, 20 * <http://www.gnu.org/licenses/>.
21 * Boston, MA 02111-1307, USA.
22 * 21 *
23 * Please send any bug reports or fixes you make to the 22 * Please send any bug reports or fixes you make to the
24 * email address(es): 23 * email address(es):
@@ -42,7 +41,7 @@ static struct sctp_hmac sctp_hmac_list[SCTP_AUTH_NUM_HMACS] = {
42 }, 41 },
43 { 42 {
44 .hmac_id = SCTP_AUTH_HMAC_ID_SHA1, 43 .hmac_id = SCTP_AUTH_HMAC_ID_SHA1,
45 .hmac_name="hmac(sha1)", 44 .hmac_name = "hmac(sha1)",
46 .hmac_len = SCTP_SHA1_SIG_SIZE, 45 .hmac_len = SCTP_SHA1_SIG_SIZE,
47 }, 46 },
48 { 47 {
@@ -52,7 +51,7 @@ static struct sctp_hmac sctp_hmac_list[SCTP_AUTH_NUM_HMACS] = {
52#if defined (CONFIG_CRYPTO_SHA256) || defined (CONFIG_CRYPTO_SHA256_MODULE) 51#if defined (CONFIG_CRYPTO_SHA256) || defined (CONFIG_CRYPTO_SHA256_MODULE)
53 { 52 {
54 .hmac_id = SCTP_AUTH_HMAC_ID_SHA256, 53 .hmac_id = SCTP_AUTH_HMAC_ID_SHA256,
55 .hmac_name="hmac(sha256)", 54 .hmac_name = "hmac(sha256)",
56 .hmac_len = SCTP_SHA256_SIG_SIZE, 55 .hmac_len = SCTP_SHA256_SIG_SIZE,
57 } 56 }
58#endif 57#endif
@@ -164,7 +163,7 @@ static int sctp_auth_compare_vectors(struct sctp_auth_bytes *vector1,
164 * lead-zero padded. If it is not, it 163 * lead-zero padded. If it is not, it
165 * is automatically larger numerically. 164 * is automatically larger numerically.
166 */ 165 */
167 for (i = 0; i < abs(diff); i++ ) { 166 for (i = 0; i < abs(diff); i++) {
168 if (longer[i] != 0) 167 if (longer[i] != 0)
169 return diff; 168 return diff;
170 } 169 }
@@ -227,9 +226,9 @@ static struct sctp_auth_bytes *sctp_auth_make_local_vector(
227 gfp_t gfp) 226 gfp_t gfp)
228{ 227{
229 return sctp_auth_make_key_vector( 228 return sctp_auth_make_key_vector(
230 (sctp_random_param_t*)asoc->c.auth_random, 229 (sctp_random_param_t *)asoc->c.auth_random,
231 (sctp_chunks_param_t*)asoc->c.auth_chunks, 230 (sctp_chunks_param_t *)asoc->c.auth_chunks,
232 (sctp_hmac_algo_param_t*)asoc->c.auth_hmacs, 231 (sctp_hmac_algo_param_t *)asoc->c.auth_hmacs,
233 gfp); 232 gfp);
234} 233}
235 234
@@ -500,8 +499,7 @@ void sctp_auth_destroy_hmacs(struct crypto_hash *auth_hmacs[])
500 if (!auth_hmacs) 499 if (!auth_hmacs)
501 return; 500 return;
502 501
503 for (i = 0; i < SCTP_AUTH_NUM_HMACS; i++) 502 for (i = 0; i < SCTP_AUTH_NUM_HMACS; i++) {
504 {
505 if (auth_hmacs[i]) 503 if (auth_hmacs[i])
506 crypto_free_hash(auth_hmacs[i]); 504 crypto_free_hash(auth_hmacs[i]);
507 } 505 }
@@ -648,15 +646,15 @@ static int __sctp_auth_cid(sctp_cid_t chunk, struct sctp_chunks_param *param)
648 */ 646 */
649 for (i = 0; !found && i < len; i++) { 647 for (i = 0; !found && i < len; i++) {
650 switch (param->chunks[i]) { 648 switch (param->chunks[i]) {
651 case SCTP_CID_INIT: 649 case SCTP_CID_INIT:
652 case SCTP_CID_INIT_ACK: 650 case SCTP_CID_INIT_ACK:
653 case SCTP_CID_SHUTDOWN_COMPLETE: 651 case SCTP_CID_SHUTDOWN_COMPLETE:
654 case SCTP_CID_AUTH: 652 case SCTP_CID_AUTH:
655 break; 653 break;
656 654
657 default: 655 default:
658 if (param->chunks[i] == chunk) 656 if (param->chunks[i] == chunk)
659 found = 1; 657 found = 1;
660 break; 658 break;
661 } 659 }
662 } 660 }
diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
index 077bb070052b..871cdf9567e6 100644
--- a/net/sctp/bind_addr.c
+++ b/net/sctp/bind_addr.c
@@ -21,9 +21,8 @@
21 * See the GNU General Public License for more details. 21 * See the GNU General Public License for more details.
22 * 22 *
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with GNU CC; see the file COPYING. If not, write to 24 * along with GNU CC; see the file COPYING. If not, see
25 * the Free Software Foundation, 59 Temple Place - Suite 330, 25 * <http://www.gnu.org/licenses/>.
26 * Boston, MA 02111-1307, USA.
27 * 26 *
28 * Please send any bug reports or fixes you make to the 27 * Please send any bug reports or fixes you make to the
29 * email address(es): 28 * email address(es):
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index f2044fcb9dd1..158701da2d31 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -18,9 +18,8 @@
18 * See the GNU General Public License for more details. 18 * See the GNU General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with GNU CC; see the file COPYING. If not, write to 21 * along with GNU CC; see the file COPYING. If not, see
22 * the Free Software Foundation, 59 Temple Place - Suite 330, 22 * <http://www.gnu.org/licenses/>.
23 * Boston, MA 02111-1307, USA.
24 * 23 *
25 * Please send any bug reports or fixes you make to the 24 * Please send any bug reports or fixes you make to the
26 * email address(es): 25 * email address(es):
@@ -255,7 +254,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
255 SCTP_INC_STATS_USER(sock_net(asoc->base.sk), SCTP_MIB_FRAGUSRMSGS); 254 SCTP_INC_STATS_USER(sock_net(asoc->base.sk), SCTP_MIB_FRAGUSRMSGS);
256 255
257 /* Create chunks for all the full sized DATA chunks. */ 256 /* Create chunks for all the full sized DATA chunks. */
258 for (i=0, len=first_len; i < whole; i++) { 257 for (i = 0, len = first_len; i < whole; i++) {
259 frag = SCTP_DATA_MIDDLE_FRAG; 258 frag = SCTP_DATA_MIDDLE_FRAG;
260 259
261 if (0 == i) 260 if (0 == i)
@@ -318,7 +317,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
318 goto errout; 317 goto errout;
319 } 318 }
320 319
321 err = sctp_user_addto_chunk(chunk, offset, over,msgh->msg_iov); 320 err = sctp_user_addto_chunk(chunk, offset, over, msgh->msg_iov);
322 321
323 /* Put the chunk->skb back into the form expected by send. */ 322 /* Put the chunk->skb back into the form expected by send. */
324 __skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr 323 __skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
diff --git a/net/sctp/command.c b/net/sctp/command.c
index 3d9a9ff69c03..dd7375851618 100644
--- a/net/sctp/command.c
+++ b/net/sctp/command.c
@@ -19,9 +19,8 @@
19 * See the GNU General Public License for more details. 19 * See the GNU General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with GNU CC; see the file COPYING. If not, write to 22 * along with GNU CC; see the file COPYING. If not, see
23 * the Free Software Foundation, 59 Temple Place - Suite 330, 23 * <http://www.gnu.org/licenses/>.
24 * Boston, MA 02111-1307, USA.
25 * 24 *
26 * Please send any bug reports or fixes you make to the 25 * Please send any bug reports or fixes you make to the
27 * email address(es): 26 * email address(es):
diff --git a/net/sctp/debug.c b/net/sctp/debug.c
index e89015d8935a..95d7b15dad21 100644
--- a/net/sctp/debug.c
+++ b/net/sctp/debug.c
@@ -22,9 +22,8 @@
22 * See the GNU General Public License for more details. 22 * See the GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to 25 * along with GNU CC; see the file COPYING. If not, see
26 * the Free Software Foundation, 59 Temple Place - Suite 330, 26 * <http://www.gnu.org/licenses/>.
27 * Boston, MA 02111-1307, USA.
28 * 27 *
29 * Please send any bug reports or fixes you make to the 28 * Please send any bug reports or fixes you make to the
30 * email address(es): 29 * email address(es):
diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
index 09b8daac87c8..6ffb6c1b13b7 100644
--- a/net/sctp/endpointola.c
+++ b/net/sctp/endpointola.c
@@ -23,9 +23,8 @@
23 * See the GNU General Public License for more details. 23 * See the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, write to 26 * along with GNU CC; see the file COPYING. If not, see
27 * the Free Software Foundation, 59 Temple Place - Suite 330, 27 * <http://www.gnu.org/licenses/>.
28 * Boston, MA 02111-1307, USA.
29 * 28 *
30 * Please send any bug reports or fixes you make to the 29 * Please send any bug reports or fixes you make to the
31 * email address(es): 30 * email address(es):
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 98b69bbecdd9..1f4eeb43fbd6 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -23,9 +23,8 @@
23 * See the GNU General Public License for more details. 23 * See the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, write to 26 * along with GNU CC; see the file COPYING. If not, see
27 * the Free Software Foundation, 59 Temple Place - Suite 330, 27 * <http://www.gnu.org/licenses/>.
28 * Boston, MA 02111-1307, USA.
29 * 28 *
30 * Please send any bug reports or fixes you make to the 29 * Please send any bug reports or fixes you make to the
31 * email address(es): 30 * email address(es):
@@ -120,7 +119,7 @@ int sctp_rcv(struct sk_buff *skb)
120 struct sctp_af *af; 119 struct sctp_af *af;
121 struct net *net = dev_net(skb->dev); 120 struct net *net = dev_net(skb->dev);
122 121
123 if (skb->pkt_type!=PACKET_HOST) 122 if (skb->pkt_type != PACKET_HOST)
124 goto discard_it; 123 goto discard_it;
125 124
126 SCTP_INC_STATS_BH(net, SCTP_MIB_INSCTPPACKS); 125 SCTP_INC_STATS_BH(net, SCTP_MIB_INSCTPPACKS);
@@ -181,8 +180,7 @@ int sctp_rcv(struct sk_buff *skb)
181 * If a frame arrives on an interface and the receiving socket is 180 * If a frame arrives on an interface and the receiving socket is
182 * bound to another interface, via SO_BINDTODEVICE, treat it as OOTB 181 * bound to another interface, via SO_BINDTODEVICE, treat it as OOTB
183 */ 182 */
184 if (sk->sk_bound_dev_if && (sk->sk_bound_dev_if != af->skb_iif(skb))) 183 if (sk->sk_bound_dev_if && (sk->sk_bound_dev_if != af->skb_iif(skb))) {
185 {
186 if (asoc) { 184 if (asoc) {
187 sctp_association_put(asoc); 185 sctp_association_put(asoc);
188 asoc = NULL; 186 asoc = NULL;
@@ -537,8 +535,7 @@ struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *skb,
537 return sk; 535 return sk;
538 536
539out: 537out:
540 if (asoc) 538 sctp_association_put(asoc);
541 sctp_association_put(asoc);
542 return NULL; 539 return NULL;
543} 540}
544 541
@@ -546,8 +543,7 @@ out:
546void sctp_err_finish(struct sock *sk, struct sctp_association *asoc) 543void sctp_err_finish(struct sock *sk, struct sctp_association *asoc)
547{ 544{
548 sctp_bh_unlock_sock(sk); 545 sctp_bh_unlock_sock(sk);
549 if (asoc) 546 sctp_association_put(asoc);
550 sctp_association_put(asoc);
551} 547}
552 548
553/* 549/*
@@ -613,8 +609,7 @@ void sctp_v4_err(struct sk_buff *skb, __u32 info)
613 if (ICMP_FRAG_NEEDED == code) { 609 if (ICMP_FRAG_NEEDED == code) {
614 sctp_icmp_frag_needed(sk, asoc, transport, info); 610 sctp_icmp_frag_needed(sk, asoc, transport, info);
615 goto out_unlock; 611 goto out_unlock;
616 } 612 } else {
617 else {
618 if (ICMP_PROT_UNREACH == code) { 613 if (ICMP_PROT_UNREACH == code) {
619 sctp_icmp_proto_unreachable(sk, asoc, 614 sctp_icmp_proto_unreachable(sk, asoc,
620 transport); 615 transport);
@@ -1058,31 +1053,31 @@ static struct sctp_association *__sctp_rcv_walk_lookup(struct net *net,
1058 if (ch_end > skb_tail_pointer(skb)) 1053 if (ch_end > skb_tail_pointer(skb))
1059 break; 1054 break;
1060 1055
1061 switch(ch->type) { 1056 switch (ch->type) {
1062 case SCTP_CID_AUTH: 1057 case SCTP_CID_AUTH:
1063 have_auth = chunk_num; 1058 have_auth = chunk_num;
1064 break; 1059 break;
1065 1060
1066 case SCTP_CID_COOKIE_ECHO: 1061 case SCTP_CID_COOKIE_ECHO:
1067 /* If a packet arrives containing an AUTH chunk as 1062 /* If a packet arrives containing an AUTH chunk as
1068 * a first chunk, a COOKIE-ECHO chunk as the second 1063 * a first chunk, a COOKIE-ECHO chunk as the second
1069 * chunk, and possibly more chunks after them, and 1064 * chunk, and possibly more chunks after them, and
1070 * the receiver does not have an STCB for that 1065 * the receiver does not have an STCB for that
1071 * packet, then authentication is based on 1066 * packet, then authentication is based on
1072 * the contents of the COOKIE- ECHO chunk. 1067 * the contents of the COOKIE- ECHO chunk.
1073 */ 1068 */
1074 if (have_auth == 1 && chunk_num == 2) 1069 if (have_auth == 1 && chunk_num == 2)
1075 return NULL; 1070 return NULL;
1076 break; 1071 break;
1077 1072
1078 case SCTP_CID_ASCONF: 1073 case SCTP_CID_ASCONF:
1079 if (have_auth || net->sctp.addip_noauth) 1074 if (have_auth || net->sctp.addip_noauth)
1080 asoc = __sctp_rcv_asconf_lookup( 1075 asoc = __sctp_rcv_asconf_lookup(
1081 net, ch, laddr, 1076 net, ch, laddr,
1082 sctp_hdr(skb)->source, 1077 sctp_hdr(skb)->source,
1083 transportp); 1078 transportp);
1084 default: 1079 default:
1085 break; 1080 break;
1086 } 1081 }
1087 1082
1088 if (asoc) 1083 if (asoc)
@@ -1119,19 +1114,10 @@ static struct sctp_association *__sctp_rcv_lookup_harder(struct net *net,
1119 return NULL; 1114 return NULL;
1120 1115
1121 /* If this is INIT/INIT-ACK look inside the chunk too. */ 1116 /* If this is INIT/INIT-ACK look inside the chunk too. */
1122 switch (ch->type) { 1117 if (ch->type == SCTP_CID_INIT || ch->type == SCTP_CID_INIT_ACK)
1123 case SCTP_CID_INIT:
1124 case SCTP_CID_INIT_ACK:
1125 return __sctp_rcv_init_lookup(net, skb, laddr, transportp); 1118 return __sctp_rcv_init_lookup(net, skb, laddr, transportp);
1126 break;
1127 1119
1128 default: 1120 return __sctp_rcv_walk_lookup(net, skb, laddr, transportp);
1129 return __sctp_rcv_walk_lookup(net, skb, laddr, transportp);
1130 break;
1131 }
1132
1133
1134 return NULL;
1135} 1121}
1136 1122
1137/* Lookup an association for an inbound skb. */ 1123/* Lookup an association for an inbound skb. */
diff --git a/net/sctp/inqueue.c b/net/sctp/inqueue.c
index 5856932fdc38..4de12afa13d4 100644
--- a/net/sctp/inqueue.c
+++ b/net/sctp/inqueue.c
@@ -24,9 +24,8 @@
24 * See the GNU General Public License for more details. 24 * See the GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to 27 * along with GNU CC; see the file COPYING. If not, see
28 * the Free Software Foundation, 59 Temple Place - Suite 330, 28 * <http://www.gnu.org/licenses/>.
29 * Boston, MA 02111-1307, USA.
30 * 29 *
31 * Please send any bug reports or fixes you make to the 30 * Please send any bug reports or fixes you make to the
32 * email address(es): 31 * email address(es):
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 7567e6f1a920..0f6259a6a932 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -21,9 +21,8 @@
21 * See the GNU General Public License for more details. 21 * See the GNU General Public License for more details.
22 * 22 *
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with GNU CC; see the file COPYING. If not, write to 24 * along with GNU CC; see the file COPYING. If not, see
25 * the Free Software Foundation, 59 Temple Place - Suite 330, 25 * <http://www.gnu.org/licenses/>.
26 * Boston, MA 02111-1307, USA.
27 * 26 *
28 * Please send any bug reports or fixes you make to the 27 * Please send any bug reports or fixes you make to the
29 * email address(es): 28 * email address(es):
@@ -173,7 +172,8 @@ static void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
173 172
174 switch (type) { 173 switch (type) {
175 case ICMPV6_PKT_TOOBIG: 174 case ICMPV6_PKT_TOOBIG:
176 sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info)); 175 if (ip6_sk_accept_pmtu(sk))
176 sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info));
177 goto out_unlock; 177 goto out_unlock;
178 case ICMPV6_PARAMPROB: 178 case ICMPV6_PARAMPROB:
179 if (ICMPV6_UNK_NEXTHDR == code) { 179 if (ICMPV6_UNK_NEXTHDR == code) {
@@ -263,7 +263,7 @@ static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
263 } 263 }
264 264
265 final_p = fl6_update_dst(fl6, np->opt, &final); 265 final_p = fl6_update_dst(fl6, np->opt, &final);
266 dst = ip6_dst_lookup_flow(sk, fl6, final_p, false); 266 dst = ip6_dst_lookup_flow(sk, fl6, final_p);
267 if (!asoc || saddr) 267 if (!asoc || saddr)
268 goto out; 268 goto out;
269 269
@@ -322,7 +322,7 @@ static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
322 fl6->saddr = baddr->v6.sin6_addr; 322 fl6->saddr = baddr->v6.sin6_addr;
323 fl6->fl6_sport = baddr->v6.sin6_port; 323 fl6->fl6_sport = baddr->v6.sin6_port;
324 final_p = fl6_update_dst(fl6, np->opt, &final); 324 final_p = fl6_update_dst(fl6, np->opt, &final);
325 dst = ip6_dst_lookup_flow(sk, fl6, final_p, false); 325 dst = ip6_dst_lookup_flow(sk, fl6, final_p);
326 } 326 }
327 327
328out: 328out:
@@ -402,7 +402,7 @@ static void sctp_v6_copy_addrlist(struct list_head *addrlist,
402} 402}
403 403
404/* Initialize a sockaddr_storage from in incoming skb. */ 404/* Initialize a sockaddr_storage from in incoming skb. */
405static void sctp_v6_from_skb(union sctp_addr *addr,struct sk_buff *skb, 405static void sctp_v6_from_skb(union sctp_addr *addr, struct sk_buff *skb,
406 int is_saddr) 406 int is_saddr)
407{ 407{
408 __be16 *port; 408 __be16 *port;
diff --git a/net/sctp/objcnt.c b/net/sctp/objcnt.c
index 647396baa56f..40e7fac96c41 100644
--- a/net/sctp/objcnt.c
+++ b/net/sctp/objcnt.c
@@ -20,9 +20,8 @@
20 * See the GNU General Public License for more details. 20 * See the GNU General Public License for more details.
21 * 21 *
22 * You should have received a copy of the GNU General Public License 22 * You should have received a copy of the GNU General Public License
23 * along with GNU CC; see the file COPYING. If not, write to 23 * along with GNU CC; see the file COPYING. If not, see
24 * the Free Software Foundation, 59 Temple Place - Suite 330, 24 * <http://www.gnu.org/licenses/>.
25 * Boston, MA 02111-1307, USA.
26 * 25 *
27 * Please send any bug reports or fixes you make to the 26 * Please send any bug reports or fixes you make to the
28 * email address(es): 27 * email address(es):
@@ -98,7 +97,7 @@ static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v)
98{ 97{
99} 98}
100 99
101static void * sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos) 100static void *sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
102{ 101{
103 ++*pos; 102 ++*pos;
104 return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos; 103 return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
diff --git a/net/sctp/output.c b/net/sctp/output.c
index e650978daf27..0f4d15fc2627 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -20,9 +20,8 @@
20 * See the GNU General Public License for more details. 20 * See the GNU General Public License for more details.
21 * 21 *
22 * You should have received a copy of the GNU General Public License 22 * You should have received a copy of the GNU General Public License
23 * along with GNU CC; see the file COPYING. If not, write to 23 * along with GNU CC; see the file COPYING. If not, see
24 * the Free Software Foundation, 59 Temple Place - Suite 330, 24 * <http://www.gnu.org/licenses/>.
25 * Boston, MA 02111-1307, USA.
26 * 25 *
27 * Please send any bug reports or fixes you make to the 26 * Please send any bug reports or fixes you make to the
28 * email address(es): 27 * email address(es):
@@ -281,7 +280,7 @@ static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet,
281 280
282 /* We believe that this chunk is OK to add to the packet */ 281 /* We believe that this chunk is OK to add to the packet */
283 switch (chunk->chunk_hdr->type) { 282 switch (chunk->chunk_hdr->type) {
284 case SCTP_CID_DATA: 283 case SCTP_CID_DATA:
285 /* Account for the data being in the packet */ 284 /* Account for the data being in the packet */
286 sctp_packet_append_data(packet, chunk); 285 sctp_packet_append_data(packet, chunk);
287 /* Disallow SACK bundling after DATA. */ 286 /* Disallow SACK bundling after DATA. */
@@ -293,17 +292,17 @@ static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet,
293 /* timestamp the chunk for rtx purposes */ 292 /* timestamp the chunk for rtx purposes */
294 chunk->sent_at = jiffies; 293 chunk->sent_at = jiffies;
295 break; 294 break;
296 case SCTP_CID_COOKIE_ECHO: 295 case SCTP_CID_COOKIE_ECHO:
297 packet->has_cookie_echo = 1; 296 packet->has_cookie_echo = 1;
298 break; 297 break;
299 298
300 case SCTP_CID_SACK: 299 case SCTP_CID_SACK:
301 packet->has_sack = 1; 300 packet->has_sack = 1;
302 if (chunk->asoc) 301 if (chunk->asoc)
303 chunk->asoc->stats.osacks++; 302 chunk->asoc->stats.osacks++;
304 break; 303 break;
305 304
306 case SCTP_CID_AUTH: 305 case SCTP_CID_AUTH:
307 packet->has_auth = 1; 306 packet->has_auth = 1;
308 packet->auth = chunk; 307 packet->auth = chunk;
309 break; 308 break;
@@ -388,7 +387,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
388 int err = 0; 387 int err = 0;
389 int padding; /* How much padding do we need? */ 388 int padding; /* How much padding do we need? */
390 __u8 has_data = 0; 389 __u8 has_data = 0;
391 struct dst_entry *dst = tp->dst; 390 struct dst_entry *dst;
392 unsigned char *auth = NULL; /* pointer to auth in skb data */ 391 unsigned char *auth = NULL; /* pointer to auth in skb data */
393 392
394 pr_debug("%s: packet:%p\n", __func__, packet); 393 pr_debug("%s: packet:%p\n", __func__, packet);
@@ -421,9 +420,9 @@ int sctp_packet_transmit(struct sctp_packet *packet)
421 } 420 }
422 } 421 }
423 dst = dst_clone(tp->dst); 422 dst = dst_clone(tp->dst);
424 skb_dst_set(nskb, dst);
425 if (!dst) 423 if (!dst)
426 goto no_route; 424 goto no_route;
425 skb_dst_set(nskb, dst);
427 426
428 /* Build the SCTP header. */ 427 /* Build the SCTP header. */
429 sh = (struct sctphdr *)skb_push(nskb, sizeof(struct sctphdr)); 428 sh = (struct sctphdr *)skb_push(nskb, sizeof(struct sctphdr));
@@ -474,10 +473,11 @@ int sctp_packet_transmit(struct sctp_packet *packet)
474 * for a given destination transport address. 473 * for a given destination transport address.
475 */ 474 */
476 475
477 if (!tp->rto_pending) { 476 if (!chunk->resent && !tp->rto_pending) {
478 chunk->rtt_in_progress = 1; 477 chunk->rtt_in_progress = 1;
479 tp->rto_pending = 1; 478 tp->rto_pending = 1;
480 } 479 }
480
481 has_data = 1; 481 has_data = 1;
482 } 482 }
483 483
@@ -540,8 +540,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
540 } else { 540 } else {
541 /* no need to seed pseudo checksum for SCTP */ 541 /* no need to seed pseudo checksum for SCTP */
542 nskb->ip_summed = CHECKSUM_PARTIAL; 542 nskb->ip_summed = CHECKSUM_PARTIAL;
543 nskb->csum_start = (skb_transport_header(nskb) - 543 nskb->csum_start = skb_transport_header(nskb) - nskb->head;
544 nskb->head);
545 nskb->csum_offset = offsetof(struct sctphdr, checksum); 544 nskb->csum_offset = offsetof(struct sctphdr, checksum);
546 } 545 }
547 } 546 }
@@ -558,7 +557,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
558 * Note: The works for IPv6 layer checks this bit too later 557 * Note: The works for IPv6 layer checks this bit too later
559 * in transmission. See IP6_ECN_flow_xmit(). 558 * in transmission. See IP6_ECN_flow_xmit().
560 */ 559 */
561 (*tp->af_specific->ecn_capable)(nskb->sk); 560 tp->af_specific->ecn_capable(nskb->sk);
562 561
563 /* Set up the IP options. */ 562 /* Set up the IP options. */
564 /* BUG: not implemented 563 /* BUG: not implemented
@@ -580,7 +579,8 @@ int sctp_packet_transmit(struct sctp_packet *packet)
580 unsigned long timeout; 579 unsigned long timeout;
581 580
582 /* Restart the AUTOCLOSE timer when sending data. */ 581 /* Restart the AUTOCLOSE timer when sending data. */
583 if (sctp_state(asoc, ESTABLISHED) && asoc->autoclose) { 582 if (sctp_state(asoc, ESTABLISHED) &&
583 asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
584 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE]; 584 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
585 timeout = asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]; 585 timeout = asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
586 586
@@ -592,7 +592,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
592 pr_debug("***sctp_transmit_packet*** skb->len:%d\n", nskb->len); 592 pr_debug("***sctp_transmit_packet*** skb->len:%d\n", nskb->len);
593 593
594 nskb->local_df = packet->ipfragok; 594 nskb->local_df = packet->ipfragok;
595 (*tp->af_specific->sctp_xmit)(nskb, tp); 595 tp->af_specific->sctp_xmit(nskb, tp);
596 596
597out: 597out:
598 sctp_packet_reset(packet); 598 sctp_packet_reset(packet);
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index 94df75877869..111516c3d34c 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -22,9 +22,8 @@
22 * See the GNU General Public License for more details. 22 * See the GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to 25 * along with GNU CC; see the file COPYING. If not, see
26 * the Free Software Foundation, 59 Temple Place - Suite 330, 26 * <http://www.gnu.org/licenses/>.
27 * Boston, MA 02111-1307, USA.
28 * 27 *
29 * Please send any bug reports or fixes you make to the 28 * Please send any bug reports or fixes you make to the
30 * email address(es): 29 * email address(es):
@@ -111,7 +110,7 @@ static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
111 struct sctp_transport *transport, 110 struct sctp_transport *transport,
112 int count_of_newacks) 111 int count_of_newacks)
113{ 112{
114 if (count_of_newacks >=2 && transport != primary) 113 if (count_of_newacks >= 2 && transport != primary)
115 return 1; 114 return 1;
116 return 0; 115 return 0;
117} 116}
@@ -446,6 +445,8 @@ void sctp_retransmit_mark(struct sctp_outq *q,
446 transport->rto_pending = 0; 445 transport->rto_pending = 0;
447 } 446 }
448 447
448 chunk->resent = 1;
449
449 /* Move the chunk to the retransmit queue. The chunks 450 /* Move the chunk to the retransmit queue. The chunks
450 * on the retransmit queue are always kept in order. 451 * on the retransmit queue are always kept in order.
451 */ 452 */
@@ -469,7 +470,7 @@ void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
469 struct net *net = sock_net(q->asoc->base.sk); 470 struct net *net = sock_net(q->asoc->base.sk);
470 int error = 0; 471 int error = 0;
471 472
472 switch(reason) { 473 switch (reason) {
473 case SCTP_RTXR_T3_RTX: 474 case SCTP_RTXR_T3_RTX:
474 SCTP_INC_STATS(net, SCTP_MIB_T3_RETRANSMITS); 475 SCTP_INC_STATS(net, SCTP_MIB_T3_RETRANSMITS);
475 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX); 476 sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
@@ -1087,7 +1088,7 @@ sctp_flush_out:
1087 * 1088 *
1088 * --xguo 1089 * --xguo
1089 */ 1090 */
1090 while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL ) { 1091 while ((ltransport = sctp_list_dequeue(&transport_list)) != NULL) {
1091 struct sctp_transport *t = list_entry(ltransport, 1092 struct sctp_transport *t = list_entry(ltransport,
1092 struct sctp_transport, 1093 struct sctp_transport,
1093 send_ready); 1094 send_ready);
@@ -1216,7 +1217,7 @@ int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
1216 * destinations for which cacc_saw_newack is set. 1217 * destinations for which cacc_saw_newack is set.
1217 */ 1218 */
1218 if (transport->cacc.cacc_saw_newack) 1219 if (transport->cacc.cacc_saw_newack)
1219 count_of_newacks ++; 1220 count_of_newacks++;
1220 } 1221 }
1221 1222
1222 /* Move the Cumulative TSN Ack Point if appropriate. */ 1223 /* Move the Cumulative TSN Ack Point if appropriate. */
@@ -1375,6 +1376,7 @@ static void sctp_check_transmitted(struct sctp_outq *q,
1375 * instance). 1376 * instance).
1376 */ 1377 */
1377 if (!tchunk->tsn_gap_acked && 1378 if (!tchunk->tsn_gap_acked &&
1379 !tchunk->resent &&
1378 tchunk->rtt_in_progress) { 1380 tchunk->rtt_in_progress) {
1379 tchunk->rtt_in_progress = 0; 1381 tchunk->rtt_in_progress = 0;
1380 rtt = jiffies - tchunk->sent_at; 1382 rtt = jiffies - tchunk->sent_at;
@@ -1391,7 +1393,8 @@ static void sctp_check_transmitted(struct sctp_outq *q,
1391 */ 1393 */
1392 if (!tchunk->tsn_gap_acked) { 1394 if (!tchunk->tsn_gap_acked) {
1393 tchunk->tsn_gap_acked = 1; 1395 tchunk->tsn_gap_acked = 1;
1394 *highest_new_tsn_in_sack = tsn; 1396 if (TSN_lt(*highest_new_tsn_in_sack, tsn))
1397 *highest_new_tsn_in_sack = tsn;
1395 bytes_acked += sctp_data_size(tchunk); 1398 bytes_acked += sctp_data_size(tchunk);
1396 if (!tchunk->transport) 1399 if (!tchunk->transport)
1397 migrate_bytes += sctp_data_size(tchunk); 1400 migrate_bytes += sctp_data_size(tchunk);
diff --git a/net/sctp/primitive.c b/net/sctp/primitive.c
index ce1ffd811775..ab8d9f96a177 100644
--- a/net/sctp/primitive.c
+++ b/net/sctp/primitive.c
@@ -23,9 +23,8 @@
23 * See the GNU General Public License for more details. 23 * See the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, write to 26 * along with GNU CC; see the file COPYING. If not, see
27 * the Free Software Foundation, 59 Temple Place - Suite 330, 27 * <http://www.gnu.org/licenses/>.
28 * Boston, MA 02111-1307, USA.
29 * 28 *
30 * Please send any bug reports or fixes you make to the 29 * Please send any bug reports or fixes you make to the
31 * email address(es): 30 * email address(es):
diff --git a/net/sctp/probe.c b/net/sctp/probe.c
index 53c452efb40b..5e68b94ee640 100644
--- a/net/sctp/probe.c
+++ b/net/sctp/probe.c
@@ -38,6 +38,7 @@
38#include <net/sctp/sctp.h> 38#include <net/sctp/sctp.h>
39#include <net/sctp/sm.h> 39#include <net/sctp/sm.h>
40 40
41MODULE_SOFTDEP("pre: sctp");
41MODULE_AUTHOR("Wei Yongjun <yjwei@cn.fujitsu.com>"); 42MODULE_AUTHOR("Wei Yongjun <yjwei@cn.fujitsu.com>");
42MODULE_DESCRIPTION("SCTP snooper"); 43MODULE_DESCRIPTION("SCTP snooper");
43MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
@@ -182,6 +183,20 @@ static struct jprobe sctp_recv_probe = {
182 .entry = jsctp_sf_eat_sack, 183 .entry = jsctp_sf_eat_sack,
183}; 184};
184 185
186static __init int sctp_setup_jprobe(void)
187{
188 int ret = register_jprobe(&sctp_recv_probe);
189
190 if (ret) {
191 if (request_module("sctp"))
192 goto out;
193 ret = register_jprobe(&sctp_recv_probe);
194 }
195
196out:
197 return ret;
198}
199
185static __init int sctpprobe_init(void) 200static __init int sctpprobe_init(void)
186{ 201{
187 int ret = -ENOMEM; 202 int ret = -ENOMEM;
@@ -202,7 +217,7 @@ static __init int sctpprobe_init(void)
202 &sctpprobe_fops)) 217 &sctpprobe_fops))
203 goto free_kfifo; 218 goto free_kfifo;
204 219
205 ret = register_jprobe(&sctp_recv_probe); 220 ret = sctp_setup_jprobe();
206 if (ret) 221 if (ret)
207 goto remove_proc; 222 goto remove_proc;
208 223
diff --git a/net/sctp/proc.c b/net/sctp/proc.c
index 0c0642156842..63ba0bdc867a 100644
--- a/net/sctp/proc.c
+++ b/net/sctp/proc.c
@@ -16,9 +16,8 @@
16 * See the GNU General Public License for more details. 16 * See the GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with GNU CC; see the file COPYING. If not, write to 19 * along with GNU CC; see the file COPYING. If not, see
20 * the Free Software Foundation, 59 Temple Place - Suite 330, 20 * <http://www.gnu.org/licenses/>.
21 * Boston, MA 02111-1307, USA.
22 * 21 *
23 * Please send any bug reports or fixes you make to the 22 * Please send any bug reports or fixes you make to the
24 * email address(es): 23 * email address(es):
@@ -178,7 +177,7 @@ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_associa
178 rcu_read_unlock(); 177 rcu_read_unlock();
179} 178}
180 179
181static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos) 180static void *sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
182{ 181{
183 if (*pos >= sctp_ep_hashsize) 182 if (*pos >= sctp_ep_hashsize)
184 return NULL; 183 return NULL;
@@ -197,7 +196,7 @@ static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
197} 196}
198 197
199 198
200static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos) 199static void *sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
201{ 200{
202 if (++*pos >= sctp_ep_hashsize) 201 if (++*pos >= sctp_ep_hashsize)
203 return NULL; 202 return NULL;
@@ -283,7 +282,7 @@ void sctp_eps_proc_exit(struct net *net)
283} 282}
284 283
285 284
286static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos) 285static void *sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
287{ 286{
288 if (*pos >= sctp_assoc_hashsize) 287 if (*pos >= sctp_assoc_hashsize)
289 return NULL; 288 return NULL;
@@ -306,7 +305,7 @@ static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
306} 305}
307 306
308 307
309static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos) 308static void *sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
310{ 309{
311 if (++*pos >= sctp_assoc_hashsize) 310 if (++*pos >= sctp_assoc_hashsize)
312 return NULL; 311 return NULL;
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 5e17092f4ada..34b7726bcd7f 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -23,9 +23,8 @@
23 * See the GNU General Public License for more details. 23 * See the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, write to 26 * along with GNU CC; see the file COPYING. If not, see
27 * the Free Software Foundation, 59 Temple Place - Suite 330, 27 * <http://www.gnu.org/licenses/>.
28 * Boston, MA 02111-1307, USA.
29 * 28 *
30 * Please send any bug reports or fixes you make to the 29 * Please send any bug reports or fixes you make to the
31 * email address(es): 30 * email address(es):
@@ -1066,8 +1065,8 @@ static struct sctp_af sctp_af_inet = {
1066#endif 1065#endif
1067}; 1066};
1068 1067
1069struct sctp_pf *sctp_get_pf_specific(sa_family_t family) { 1068struct sctp_pf *sctp_get_pf_specific(sa_family_t family)
1070 1069{
1071 switch (family) { 1070 switch (family) {
1072 case PF_INET: 1071 case PF_INET:
1073 return sctp_pf_inet_specific; 1072 return sctp_pf_inet_specific;
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index fe690320b1e4..e5f7cdb42a85 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -23,9 +23,8 @@
23 * See the GNU General Public License for more details. 23 * See the GNU General Public License for more details.
24 * 24 *
25 * You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, write to 26 * along with GNU CC; see the file COPYING. If not, see
27 * the Free Software Foundation, 59 Temple Place - Suite 330, 27 * <http://www.gnu.org/licenses/>.
28 * Boston, MA 02111-1307, USA.
29 * 28 *
30 * Please send any bug reports or fixes you make to the 29 * Please send any bug reports or fixes you make to the
31 * email address(es): 30 * email address(es):
@@ -1968,13 +1967,13 @@ static int sctp_verify_ext_param(struct net *net, union sctp_params param)
1968 1967
1969 for (i = 0; i < num_ext; i++) { 1968 for (i = 0; i < num_ext; i++) {
1970 switch (param.ext->chunks[i]) { 1969 switch (param.ext->chunks[i]) {
1971 case SCTP_CID_AUTH: 1970 case SCTP_CID_AUTH:
1972 have_auth = 1; 1971 have_auth = 1;
1973 break; 1972 break;
1974 case SCTP_CID_ASCONF: 1973 case SCTP_CID_ASCONF:
1975 case SCTP_CID_ASCONF_ACK: 1974 case SCTP_CID_ASCONF_ACK:
1976 have_asconf = 1; 1975 have_asconf = 1;
1977 break; 1976 break;
1978 } 1977 }
1979 } 1978 }
1980 1979
@@ -2001,25 +2000,24 @@ static void sctp_process_ext_param(struct sctp_association *asoc,
2001 2000
2002 for (i = 0; i < num_ext; i++) { 2001 for (i = 0; i < num_ext; i++) {
2003 switch (param.ext->chunks[i]) { 2002 switch (param.ext->chunks[i]) {
2004 case SCTP_CID_FWD_TSN: 2003 case SCTP_CID_FWD_TSN:
2005 if (net->sctp.prsctp_enable && 2004 if (net->sctp.prsctp_enable && !asoc->peer.prsctp_capable)
2006 !asoc->peer.prsctp_capable)
2007 asoc->peer.prsctp_capable = 1; 2005 asoc->peer.prsctp_capable = 1;
2008 break; 2006 break;
2009 case SCTP_CID_AUTH: 2007 case SCTP_CID_AUTH:
2010 /* if the peer reports AUTH, assume that he 2008 /* if the peer reports AUTH, assume that he
2011 * supports AUTH. 2009 * supports AUTH.
2012 */ 2010 */
2013 if (net->sctp.auth_enable) 2011 if (net->sctp.auth_enable)
2014 asoc->peer.auth_capable = 1; 2012 asoc->peer.auth_capable = 1;
2015 break; 2013 break;
2016 case SCTP_CID_ASCONF: 2014 case SCTP_CID_ASCONF:
2017 case SCTP_CID_ASCONF_ACK: 2015 case SCTP_CID_ASCONF_ACK:
2018 if (net->sctp.addip_enable) 2016 if (net->sctp.addip_enable)
2019 asoc->peer.asconf_capable = 1; 2017 asoc->peer.asconf_capable = 1;
2020 break; 2018 break;
2021 default: 2019 default:
2022 break; 2020 break;
2023 } 2021 }
2024 } 2022 }
2025} 2023}
@@ -2252,7 +2250,7 @@ int sctp_verify_init(struct net *net, const struct sctp_association *asoc,
2252 * VIOLATION error. We build the ERROR chunk here and let the normal 2250 * VIOLATION error. We build the ERROR chunk here and let the normal
2253 * error handling code build and send the packet. 2251 * error handling code build and send the packet.
2254 */ 2252 */
2255 if (param.v != (void*)chunk->chunk_end) 2253 if (param.v != (void *)chunk->chunk_end)
2256 return sctp_process_inv_paramlength(asoc, param.p, chunk, errp); 2254 return sctp_process_inv_paramlength(asoc, param.p, chunk, errp);
2257 2255
2258 /* The only missing mandatory param possible today is 2256 /* The only missing mandatory param possible today is
@@ -2267,14 +2265,14 @@ int sctp_verify_init(struct net *net, const struct sctp_association *asoc,
2267 2265
2268 result = sctp_verify_param(net, asoc, param, cid, chunk, errp); 2266 result = sctp_verify_param(net, asoc, param, cid, chunk, errp);
2269 switch (result) { 2267 switch (result) {
2270 case SCTP_IERROR_ABORT: 2268 case SCTP_IERROR_ABORT:
2271 case SCTP_IERROR_NOMEM: 2269 case SCTP_IERROR_NOMEM:
2272 return 0; 2270 return 0;
2273 case SCTP_IERROR_ERROR: 2271 case SCTP_IERROR_ERROR:
2274 return 1; 2272 return 1;
2275 case SCTP_IERROR_NO_ERROR: 2273 case SCTP_IERROR_NO_ERROR:
2276 default: 2274 default:
2277 break; 2275 break;
2278 } 2276 }
2279 2277
2280 } /* for (loop through all parameters) */ 2278 } /* for (loop through all parameters) */
@@ -2309,7 +2307,7 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
2309 * added as the primary transport. The source address seems to 2307 * added as the primary transport. The source address seems to
2310 * be a a better choice than any of the embedded addresses. 2308 * be a a better choice than any of the embedded addresses.
2311 */ 2309 */
2312 if(!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE)) 2310 if (!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE))
2313 goto nomem; 2311 goto nomem;
2314 2312
2315 if (sctp_cmp_addr_exact(sctp_source(chunk), peer_addr)) 2313 if (sctp_cmp_addr_exact(sctp_source(chunk), peer_addr))
@@ -3335,7 +3333,7 @@ static __be16 sctp_get_asconf_response(struct sctp_chunk *asconf_ack,
3335 3333
3336 while (asconf_ack_len > 0) { 3334 while (asconf_ack_len > 0) {
3337 if (asconf_ack_param->crr_id == asconf_param->crr_id) { 3335 if (asconf_ack_param->crr_id == asconf_param->crr_id) {
3338 switch(asconf_ack_param->param_hdr.type) { 3336 switch (asconf_ack_param->param_hdr.type) {
3339 case SCTP_PARAM_SUCCESS_REPORT: 3337 case SCTP_PARAM_SUCCESS_REPORT:
3340 return SCTP_ERROR_NO_ERROR; 3338 return SCTP_ERROR_NO_ERROR;
3341 case SCTP_PARAM_ERR_CAUSE: 3339 case SCTP_PARAM_ERR_CAUSE:
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index 1a6eef39ab2f..ded6db66fb24 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -22,9 +22,8 @@
22 * See the GNU General Public License for more details. 22 * See the GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to 25 * along with GNU CC; see the file COPYING. If not, see
26 * the Free Software Foundation, 59 Temple Place - Suite 330, 26 * <http://www.gnu.org/licenses/>.
27 * Boston, MA 02111-1307, USA.
28 * 27 *
29 * Please send any bug reports or fixes you make to the 28 * Please send any bug reports or fixes you make to the
30 * email address(es): 29 * email address(es):
@@ -405,7 +404,7 @@ void sctp_generate_proto_unreach_event(unsigned long data)
405 struct sctp_transport *transport = (struct sctp_transport *) data; 404 struct sctp_transport *transport = (struct sctp_transport *) data;
406 struct sctp_association *asoc = transport->asoc; 405 struct sctp_association *asoc = transport->asoc;
407 struct net *net = sock_net(asoc->base.sk); 406 struct net *net = sock_net(asoc->base.sk);
408 407
409 sctp_bh_lock_sock(asoc->base.sk); 408 sctp_bh_lock_sock(asoc->base.sk);
410 if (sock_owned_by_user(asoc->base.sk)) { 409 if (sock_owned_by_user(asoc->base.sk)) {
411 pr_debug("%s: sock is busy\n", __func__); 410 pr_debug("%s: sock is busy\n", __func__);
@@ -544,7 +543,7 @@ static void sctp_cmd_init_failed(sctp_cmd_seq_t *commands,
544{ 543{
545 struct sctp_ulpevent *event; 544 struct sctp_ulpevent *event;
546 545
547 event = sctp_ulpevent_make_assoc_change(asoc,0, SCTP_CANT_STR_ASSOC, 546 event = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_CANT_STR_ASSOC,
548 (__u16)error, 0, 0, NULL, 547 (__u16)error, 0, 0, NULL,
549 GFP_ATOMIC); 548 GFP_ATOMIC);
550 549
@@ -1116,7 +1115,7 @@ int sctp_do_sm(struct net *net, sctp_event_t event_type, sctp_subtype_t subtype,
1116 sctp_init_cmd_seq(&commands); 1115 sctp_init_cmd_seq(&commands);
1117 1116
1118 debug_pre_sfn(); 1117 debug_pre_sfn();
1119 status = (*state_fn->fn)(net, ep, asoc, subtype, event_arg, &commands); 1118 status = state_fn->fn(net, ep, asoc, subtype, event_arg, &commands);
1120 debug_post_sfn(); 1119 debug_post_sfn();
1121 1120
1122 error = sctp_side_effects(event_type, subtype, state, 1121 error = sctp_side_effects(event_type, subtype, state,
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index dfe3f36ff2aa..483dcd71b3c5 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -22,9 +22,8 @@
22 * See the GNU General Public License for more details. 22 * See the GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to 25 * along with GNU CC; see the file COPYING. If not, see
26 * the Free Software Foundation, 59 Temple Place - Suite 330, 26 * <http://www.gnu.org/licenses/>.
27 * Boston, MA 02111-1307, USA.
28 * 27 *
29 * Please send any bug reports or fixes you make to the 28 * Please send any bug reports or fixes you make to the
30 * email address(es): 29 * email address(es):
@@ -820,7 +819,7 @@ sctp_disposition_t sctp_sf_do_5_1D_ce(struct net *net,
820 SCTP_INC_STATS(net, SCTP_MIB_PASSIVEESTABS); 819 SCTP_INC_STATS(net, SCTP_MIB_PASSIVEESTABS);
821 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); 820 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
822 821
823 if (new_asoc->autoclose) 822 if (new_asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
824 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 823 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
825 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 824 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
826 825
@@ -908,7 +907,7 @@ sctp_disposition_t sctp_sf_do_5_1E_ca(struct net *net,
908 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); 907 SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
909 SCTP_INC_STATS(net, SCTP_MIB_ACTIVEESTABS); 908 SCTP_INC_STATS(net, SCTP_MIB_ACTIVEESTABS);
910 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); 909 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
911 if (asoc->autoclose) 910 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
912 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, 911 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
913 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 912 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
914 913
@@ -2946,7 +2945,7 @@ sctp_disposition_t sctp_sf_eat_data_6_2(struct net *net,
2946 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, 2945 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
2947 commands); 2946 commands);
2948 2947
2949 error = sctp_eat_data(asoc, chunk, commands ); 2948 error = sctp_eat_data(asoc, chunk, commands);
2950 switch (error) { 2949 switch (error) {
2951 case SCTP_IERROR_NO_ERROR: 2950 case SCTP_IERROR_NO_ERROR:
2952 break; 2951 break;
@@ -2970,7 +2969,7 @@ sctp_disposition_t sctp_sf_eat_data_6_2(struct net *net,
2970 if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM) 2969 if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM)
2971 force = SCTP_FORCE(); 2970 force = SCTP_FORCE();
2972 2971
2973 if (asoc->autoclose) { 2972 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
2974 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 2973 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2975 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 2974 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2976 } 2975 }
@@ -3067,7 +3066,7 @@ sctp_disposition_t sctp_sf_eat_data_fast_4_4(struct net *net,
3067 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, 3066 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3068 commands); 3067 commands);
3069 3068
3070 error = sctp_eat_data(asoc, chunk, commands ); 3069 error = sctp_eat_data(asoc, chunk, commands);
3071 switch (error) { 3070 switch (error) {
3072 case SCTP_IERROR_NO_ERROR: 3071 case SCTP_IERROR_NO_ERROR:
3073 case SCTP_IERROR_HIGH_TSN: 3072 case SCTP_IERROR_HIGH_TSN:
@@ -3682,8 +3681,7 @@ sctp_disposition_t sctp_sf_do_asconf(struct net *net,
3682 asconf_ack->dest = chunk->source; 3681 asconf_ack->dest = chunk->source;
3683 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack)); 3682 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3684 if (asoc->new_transport) { 3683 if (asoc->new_transport) {
3685 sctp_sf_heartbeat(ep, asoc, type, asoc->new_transport, 3684 sctp_sf_heartbeat(ep, asoc, type, asoc->new_transport, commands);
3686 commands);
3687 ((struct sctp_association *)asoc)->new_transport = NULL; 3685 ((struct sctp_association *)asoc)->new_transport = NULL;
3688 } 3686 }
3689 3687
@@ -3766,7 +3764,7 @@ sctp_disposition_t sctp_sf_do_asconf_ack(struct net *net,
3766 */ 3764 */
3767 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 3765 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3768 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); 3766 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3769 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); 3767 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3770 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, 3768 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3771 SCTP_ERROR(ECONNABORTED)); 3769 SCTP_ERROR(ECONNABORTED));
3772 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 3770 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
@@ -3800,7 +3798,7 @@ sctp_disposition_t sctp_sf_do_asconf_ack(struct net *net,
3800 /* We are going to ABORT, so we might as well stop 3798 /* We are going to ABORT, so we might as well stop
3801 * processing the rest of the chunks in the packet. 3799 * processing the rest of the chunks in the packet.
3802 */ 3800 */
3803 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); 3801 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3804 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, 3802 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3805 SCTP_ERROR(ECONNABORTED)); 3803 SCTP_ERROR(ECONNABORTED));
3806 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 3804 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
@@ -3878,7 +3876,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(struct net *net,
3878 SCTP_CHUNK(chunk)); 3876 SCTP_CHUNK(chunk));
3879 3877
3880 /* Count this as receiving DATA. */ 3878 /* Count this as receiving DATA. */
3881 if (asoc->autoclose) { 3879 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
3882 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 3880 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3883 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 3881 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3884 } 3882 }
@@ -4452,7 +4450,7 @@ static sctp_disposition_t sctp_sf_violation_chunklen(
4452 void *arg, 4450 void *arg,
4453 sctp_cmd_seq_t *commands) 4451 sctp_cmd_seq_t *commands)
4454{ 4452{
4455 static const char err_str[]="The following chunk had invalid length:"; 4453 static const char err_str[] = "The following chunk had invalid length:";
4456 4454
4457 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str, 4455 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4458 sizeof(err_str)); 4456 sizeof(err_str));
@@ -4515,7 +4513,7 @@ static sctp_disposition_t sctp_sf_violation_ctsn(
4515 void *arg, 4513 void *arg,
4516 sctp_cmd_seq_t *commands) 4514 sctp_cmd_seq_t *commands)
4517{ 4515{
4518 static const char err_str[]="The cumulative tsn ack beyond the max tsn currently sent:"; 4516 static const char err_str[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4519 4517
4520 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str, 4518 return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
4521 sizeof(err_str)); 4519 sizeof(err_str));
@@ -4535,7 +4533,7 @@ static sctp_disposition_t sctp_sf_violation_chunk(
4535 void *arg, 4533 void *arg,
4536 sctp_cmd_seq_t *commands) 4534 sctp_cmd_seq_t *commands)
4537{ 4535{
4538 static const char err_str[]="The following chunk violates protocol:"; 4536 static const char err_str[] = "The following chunk violates protocol:";
4539 4537
4540 if (!asoc) 4538 if (!asoc)
4541 return sctp_sf_violation(net, ep, asoc, type, arg, commands); 4539 return sctp_sf_violation(net, ep, asoc, type, arg, commands);
@@ -4611,7 +4609,7 @@ sctp_disposition_t sctp_sf_do_prm_asoc(struct net *net,
4611 sctp_cmd_seq_t *commands) 4609 sctp_cmd_seq_t *commands)
4612{ 4610{
4613 struct sctp_chunk *repl; 4611 struct sctp_chunk *repl;
4614 struct sctp_association* my_asoc; 4612 struct sctp_association *my_asoc;
4615 4613
4616 /* The comment below says that we enter COOKIE-WAIT AFTER 4614 /* The comment below says that we enter COOKIE-WAIT AFTER
4617 * sending the INIT, but that doesn't actually work in our 4615 * sending the INIT, but that doesn't actually work in our
@@ -5267,7 +5265,7 @@ sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
5267 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 5265 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5268 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); 5266 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5269 5267
5270 if (asoc->autoclose) 5268 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
5271 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 5269 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5272 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 5270 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
5273 5271
@@ -5346,7 +5344,7 @@ sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
5346 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, 5344 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5347 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); 5345 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5348 5346
5349 if (asoc->autoclose) 5347 if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
5350 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, 5348 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5351 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); 5349 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
5352 5350
@@ -6001,7 +5999,7 @@ static struct sctp_packet *sctp_ootb_pkt_new(struct net *net,
6001 /* Special case the INIT-ACK as there is no peer's vtag 5999 /* Special case the INIT-ACK as there is no peer's vtag
6002 * yet. 6000 * yet.
6003 */ 6001 */
6004 switch(chunk->chunk_hdr->type) { 6002 switch (chunk->chunk_hdr->type) {
6005 case SCTP_CID_INIT_ACK: 6003 case SCTP_CID_INIT_ACK:
6006 { 6004 {
6007 sctp_initack_chunk_t *initack; 6005 sctp_initack_chunk_t *initack;
@@ -6018,7 +6016,7 @@ static struct sctp_packet *sctp_ootb_pkt_new(struct net *net,
6018 /* Special case the INIT and stale COOKIE_ECHO as there is no 6016 /* Special case the INIT and stale COOKIE_ECHO as there is no
6019 * vtag yet. 6017 * vtag yet.
6020 */ 6018 */
6021 switch(chunk->chunk_hdr->type) { 6019 switch (chunk->chunk_hdr->type) {
6022 case SCTP_CID_INIT: 6020 case SCTP_CID_INIT:
6023 { 6021 {
6024 sctp_init_chunk_t *init; 6022 sctp_init_chunk_t *init;
@@ -6208,7 +6206,7 @@ static int sctp_eat_data(const struct sctp_association *asoc,
6208 */ 6206 */
6209 if (*sk->sk_prot_creator->memory_pressure) { 6207 if (*sk->sk_prot_creator->memory_pressure) {
6210 if (sctp_tsnmap_has_gap(map) && 6208 if (sctp_tsnmap_has_gap(map) &&
6211 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { 6209 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
6212 pr_debug("%s: under pressure, reneging for tsn:%u\n", 6210 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6213 __func__, tsn); 6211 __func__, tsn);
6214 deliver = SCTP_CMD_RENEGE; 6212 deliver = SCTP_CMD_RENEGE;
@@ -6232,7 +6230,7 @@ static int sctp_eat_data(const struct sctp_association *asoc,
6232 /* We are going to ABORT, so we might as well stop 6230 /* We are going to ABORT, so we might as well stop
6233 * processing the rest of the chunks in the packet. 6231 * processing the rest of the chunks in the packet.
6234 */ 6232 */
6235 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); 6233 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
6236 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, 6234 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
6237 SCTP_ERROR(ECONNABORTED)); 6235 SCTP_ERROR(ECONNABORTED));
6238 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, 6236 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
diff --git a/net/sctp/sm_statetable.c b/net/sctp/sm_statetable.c
index c5999b2dde7d..a987d54b379c 100644
--- a/net/sctp/sm_statetable.c
+++ b/net/sctp/sm_statetable.c
@@ -22,9 +22,8 @@
22 * See the GNU General Public License for more details. 22 * See the GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to 25 * along with GNU CC; see the file COPYING. If not, see
26 * the Free Software Foundation, 59 Temple Place - Suite 330, 26 * <http://www.gnu.org/licenses/>.
27 * Boston, MA 02111-1307, USA.
28 * 27 *
29 * Please send any bug reports or fixes you make to the 28 * Please send any bug reports or fixes you make to the
30 * email address(es): 29 * email address(es):
@@ -70,7 +69,7 @@ static const sctp_sm_table_entry_t bug = {
70 if ((event_subtype._type > (_max))) { \ 69 if ((event_subtype._type > (_max))) { \
71 pr_warn("table %p possible attack: event %d exceeds max %d\n", \ 70 pr_warn("table %p possible attack: event %d exceeds max %d\n", \
72 _table, event_subtype._type, _max); \ 71 _table, event_subtype._type, _max); \
73 rtn = &bug; \ 72 rtn = &bug; \
74 } else \ 73 } else \
75 rtn = &_table[event_subtype._type][(int)state]; \ 74 rtn = &_table[event_subtype._type][(int)state]; \
76 \ 75 \
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 72046b9729a8..e9c5121e0fbf 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -28,9 +28,8 @@
28 * See the GNU General Public License for more details. 28 * See the GNU General Public License for more details.
29 * 29 *
30 * You should have received a copy of the GNU General Public License 30 * You should have received a copy of the GNU General Public License
31 * along with GNU CC; see the file COPYING. If not, write to 31 * along with GNU CC; see the file COPYING. If not, see
32 * the Free Software Foundation, 59 Temple Place - Suite 330, 32 * <http://www.gnu.org/licenses/>.
33 * Boston, MA 02111-1307, USA.
34 * 33 *
35 * Please send any bug reports or fixes you make to the 34 * Please send any bug reports or fixes you make to the
36 * email address(es): 35 * email address(es):
@@ -83,7 +82,7 @@ static int sctp_writeable(struct sock *sk);
83static void sctp_wfree(struct sk_buff *skb); 82static void sctp_wfree(struct sk_buff *skb);
84static int sctp_wait_for_sndbuf(struct sctp_association *, long *timeo_p, 83static int sctp_wait_for_sndbuf(struct sctp_association *, long *timeo_p,
85 size_t msg_len); 84 size_t msg_len);
86static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p); 85static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p);
87static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p); 86static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p);
88static int sctp_wait_for_accept(struct sock *sk, long timeo); 87static int sctp_wait_for_accept(struct sock *sk, long timeo);
89static void sctp_wait_for_close(struct sock *sk, long timeo); 88static void sctp_wait_for_close(struct sock *sk, long timeo);
@@ -953,7 +952,7 @@ int sctp_asconf_mgmt(struct sctp_sock *sp, struct sctp_sockaddr_entry *addrw)
953 * 952 *
954 * Returns 0 if ok, <0 errno code on error. 953 * Returns 0 if ok, <0 errno code on error.
955 */ 954 */
956static int sctp_setsockopt_bindx(struct sock* sk, 955static int sctp_setsockopt_bindx(struct sock *sk,
957 struct sockaddr __user *addrs, 956 struct sockaddr __user *addrs,
958 int addrs_size, int op) 957 int addrs_size, int op)
959{ 958{
@@ -1040,7 +1039,7 @@ out:
1040 * Common routine for handling connect() and sctp_connectx(). 1039 * Common routine for handling connect() and sctp_connectx().
1041 * Connect will come in with just a single address. 1040 * Connect will come in with just a single address.
1042 */ 1041 */
1043static int __sctp_connect(struct sock* sk, 1042static int __sctp_connect(struct sock *sk,
1044 struct sockaddr *kaddrs, 1043 struct sockaddr *kaddrs,
1045 int addrs_size, 1044 int addrs_size,
1046 sctp_assoc_t *assoc_id) 1045 sctp_assoc_t *assoc_id)
@@ -1300,7 +1299,7 @@ out_free:
1300 * 1299 *
1301 * Returns >=0 if ok, <0 errno code on error. 1300 * Returns >=0 if ok, <0 errno code on error.
1302 */ 1301 */
1303static int __sctp_setsockopt_connectx(struct sock* sk, 1302static int __sctp_setsockopt_connectx(struct sock *sk,
1304 struct sockaddr __user *addrs, 1303 struct sockaddr __user *addrs,
1305 int addrs_size, 1304 int addrs_size,
1306 sctp_assoc_t *assoc_id) 1305 sctp_assoc_t *assoc_id)
@@ -1338,7 +1337,7 @@ static int __sctp_setsockopt_connectx(struct sock* sk,
1338 * This is an older interface. It's kept for backward compatibility 1337 * This is an older interface. It's kept for backward compatibility
1339 * to the option that doesn't provide association id. 1338 * to the option that doesn't provide association id.
1340 */ 1339 */
1341static int sctp_setsockopt_connectx_old(struct sock* sk, 1340static int sctp_setsockopt_connectx_old(struct sock *sk,
1342 struct sockaddr __user *addrs, 1341 struct sockaddr __user *addrs,
1343 int addrs_size) 1342 int addrs_size)
1344{ 1343{
@@ -1351,7 +1350,7 @@ static int sctp_setsockopt_connectx_old(struct sock* sk,
1351 * indication to the call. Error is always negative and association id is 1350 * indication to the call. Error is always negative and association id is
1352 * always positive. 1351 * always positive.
1353 */ 1352 */
1354static int sctp_setsockopt_connectx(struct sock* sk, 1353static int sctp_setsockopt_connectx(struct sock *sk,
1355 struct sockaddr __user *addrs, 1354 struct sockaddr __user *addrs,
1356 int addrs_size) 1355 int addrs_size)
1357{ 1356{
@@ -1374,7 +1373,7 @@ static int sctp_setsockopt_connectx(struct sock* sk,
1374 * addrs_num structure member. That way we can re-use the existing 1373 * addrs_num structure member. That way we can re-use the existing
1375 * code. 1374 * code.
1376 */ 1375 */
1377static int sctp_getsockopt_connectx3(struct sock* sk, int len, 1376static int sctp_getsockopt_connectx3(struct sock *sk, int len,
1378 char __user *optval, 1377 char __user *optval,
1379 int __user *optlen) 1378 int __user *optlen)
1380{ 1379{
@@ -1569,7 +1568,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
1569 struct net *net = sock_net(sk); 1568 struct net *net = sock_net(sk);
1570 struct sctp_sock *sp; 1569 struct sctp_sock *sp;
1571 struct sctp_endpoint *ep; 1570 struct sctp_endpoint *ep;
1572 struct sctp_association *new_asoc=NULL, *asoc=NULL; 1571 struct sctp_association *new_asoc = NULL, *asoc = NULL;
1573 struct sctp_transport *transport, *chunk_tp; 1572 struct sctp_transport *transport, *chunk_tp;
1574 struct sctp_chunk *chunk; 1573 struct sctp_chunk *chunk;
1575 union sctp_addr to; 1574 union sctp_addr to;
@@ -2196,6 +2195,7 @@ static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval,
2196 unsigned int optlen) 2195 unsigned int optlen)
2197{ 2196{
2198 struct sctp_sock *sp = sctp_sk(sk); 2197 struct sctp_sock *sp = sctp_sk(sk);
2198 struct net *net = sock_net(sk);
2199 2199
2200 /* Applicable to UDP-style socket only */ 2200 /* Applicable to UDP-style socket only */
2201 if (sctp_style(sk, TCP)) 2201 if (sctp_style(sk, TCP))
@@ -2205,6 +2205,9 @@ static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval,
2205 if (copy_from_user(&sp->autoclose, optval, optlen)) 2205 if (copy_from_user(&sp->autoclose, optval, optlen))
2206 return -EFAULT; 2206 return -EFAULT;
2207 2207
2208 if (sp->autoclose > net->sctp.max_autoclose)
2209 sp->autoclose = net->sctp.max_autoclose;
2210
2208 return 0; 2211 return 0;
2209} 2212}
2210 2213
@@ -2459,7 +2462,7 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2459 int hb_change, pmtud_change, sackdelay_change; 2462 int hb_change, pmtud_change, sackdelay_change;
2460 2463
2461 if (optlen != sizeof(struct sctp_paddrparams)) 2464 if (optlen != sizeof(struct sctp_paddrparams))
2462 return - EINVAL; 2465 return -EINVAL;
2463 2466
2464 if (copy_from_user(&params, optval, optlen)) 2467 if (copy_from_user(&params, optval, optlen))
2465 return -EFAULT; 2468 return -EFAULT;
@@ -2480,7 +2483,7 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2480 /* If an address other than INADDR_ANY is specified, and 2483 /* If an address other than INADDR_ANY is specified, and
2481 * no transport is found, then the request is invalid. 2484 * no transport is found, then the request is invalid.
2482 */ 2485 */
2483 if (!sctp_is_any(sk, ( union sctp_addr *)&params.spp_address)) { 2486 if (!sctp_is_any(sk, (union sctp_addr *)&params.spp_address)) {
2484 trans = sctp_addr_id2transport(sk, &params.spp_address, 2487 trans = sctp_addr_id2transport(sk, &params.spp_address,
2485 params.spp_assoc_id); 2488 params.spp_assoc_id);
2486 if (!trans) 2489 if (!trans)
@@ -2575,8 +2578,9 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk,
2575 if (params.sack_delay == 0 && params.sack_freq == 0) 2578 if (params.sack_delay == 0 && params.sack_freq == 0)
2576 return 0; 2579 return 0;
2577 } else if (optlen == sizeof(struct sctp_assoc_value)) { 2580 } else if (optlen == sizeof(struct sctp_assoc_value)) {
2578 pr_warn("Use of struct sctp_assoc_value in delayed_ack socket option deprecated\n"); 2581 pr_warn_ratelimited(DEPRECATED
2579 pr_warn("Use struct sctp_sack_info instead\n"); 2582 "Use of struct sctp_assoc_value in delayed_ack socket option.\n"
2583 "Use struct sctp_sack_info instead\n");
2580 if (copy_from_user(&params, optval, optlen)) 2584 if (copy_from_user(&params, optval, optlen))
2581 return -EFAULT; 2585 return -EFAULT;
2582 2586
@@ -2585,7 +2589,7 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk,
2585 else 2589 else
2586 params.sack_freq = 0; 2590 params.sack_freq = 0;
2587 } else 2591 } else
2588 return - EINVAL; 2592 return -EINVAL;
2589 2593
2590 /* Validate value parameter. */ 2594 /* Validate value parameter. */
2591 if (params.sack_delay > 500) 2595 if (params.sack_delay > 500)
@@ -2811,6 +2815,8 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigne
2811{ 2815{
2812 struct sctp_rtoinfo rtoinfo; 2816 struct sctp_rtoinfo rtoinfo;
2813 struct sctp_association *asoc; 2817 struct sctp_association *asoc;
2818 unsigned long rto_min, rto_max;
2819 struct sctp_sock *sp = sctp_sk(sk);
2814 2820
2815 if (optlen != sizeof (struct sctp_rtoinfo)) 2821 if (optlen != sizeof (struct sctp_rtoinfo))
2816 return -EINVAL; 2822 return -EINVAL;
@@ -2824,26 +2830,36 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigne
2824 if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP)) 2830 if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP))
2825 return -EINVAL; 2831 return -EINVAL;
2826 2832
2833 rto_max = rtoinfo.srto_max;
2834 rto_min = rtoinfo.srto_min;
2835
2836 if (rto_max)
2837 rto_max = asoc ? msecs_to_jiffies(rto_max) : rto_max;
2838 else
2839 rto_max = asoc ? asoc->rto_max : sp->rtoinfo.srto_max;
2840
2841 if (rto_min)
2842 rto_min = asoc ? msecs_to_jiffies(rto_min) : rto_min;
2843 else
2844 rto_min = asoc ? asoc->rto_min : sp->rtoinfo.srto_min;
2845
2846 if (rto_min > rto_max)
2847 return -EINVAL;
2848
2827 if (asoc) { 2849 if (asoc) {
2828 if (rtoinfo.srto_initial != 0) 2850 if (rtoinfo.srto_initial != 0)
2829 asoc->rto_initial = 2851 asoc->rto_initial =
2830 msecs_to_jiffies(rtoinfo.srto_initial); 2852 msecs_to_jiffies(rtoinfo.srto_initial);
2831 if (rtoinfo.srto_max != 0) 2853 asoc->rto_max = rto_max;
2832 asoc->rto_max = msecs_to_jiffies(rtoinfo.srto_max); 2854 asoc->rto_min = rto_min;
2833 if (rtoinfo.srto_min != 0)
2834 asoc->rto_min = msecs_to_jiffies(rtoinfo.srto_min);
2835 } else { 2855 } else {
2836 /* If there is no association or the association-id = 0 2856 /* If there is no association or the association-id = 0
2837 * set the values to the endpoint. 2857 * set the values to the endpoint.
2838 */ 2858 */
2839 struct sctp_sock *sp = sctp_sk(sk);
2840
2841 if (rtoinfo.srto_initial != 0) 2859 if (rtoinfo.srto_initial != 0)
2842 sp->rtoinfo.srto_initial = rtoinfo.srto_initial; 2860 sp->rtoinfo.srto_initial = rtoinfo.srto_initial;
2843 if (rtoinfo.srto_max != 0) 2861 sp->rtoinfo.srto_max = rto_max;
2844 sp->rtoinfo.srto_max = rtoinfo.srto_max; 2862 sp->rtoinfo.srto_min = rto_min;
2845 if (rtoinfo.srto_min != 0)
2846 sp->rtoinfo.srto_min = rtoinfo.srto_min;
2847 } 2863 }
2848 2864
2849 return 0; 2865 return 0;
@@ -2979,8 +2995,9 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
2979 int val; 2995 int val;
2980 2996
2981 if (optlen == sizeof(int)) { 2997 if (optlen == sizeof(int)) {
2982 pr_warn("Use of int in maxseg socket option deprecated\n"); 2998 pr_warn_ratelimited(DEPRECATED
2983 pr_warn("Use struct sctp_assoc_value instead\n"); 2999 "Use of int in maxseg socket option.\n"
3000 "Use struct sctp_assoc_value instead\n");
2984 if (copy_from_user(&val, optval, optlen)) 3001 if (copy_from_user(&val, optval, optlen))
2985 return -EFAULT; 3002 return -EFAULT;
2986 params.assoc_id = 0; 3003 params.assoc_id = 0;
@@ -3237,8 +3254,9 @@ static int sctp_setsockopt_maxburst(struct sock *sk,
3237 int assoc_id = 0; 3254 int assoc_id = 0;
3238 3255
3239 if (optlen == sizeof(int)) { 3256 if (optlen == sizeof(int)) {
3240 pr_warn("Use of int in max_burst socket option deprecated\n"); 3257 pr_warn_ratelimited(DEPRECATED
3241 pr_warn("Use struct sctp_assoc_value instead\n"); 3258 "Use of int in max_burst socket option deprecated.\n"
3259 "Use struct sctp_assoc_value instead\n");
3242 if (copy_from_user(&val, optval, optlen)) 3260 if (copy_from_user(&val, optval, optlen))
3243 return -EFAULT; 3261 return -EFAULT;
3244 } else if (optlen == sizeof(struct sctp_assoc_value)) { 3262 } else if (optlen == sizeof(struct sctp_assoc_value)) {
@@ -3317,7 +3335,7 @@ static int sctp_setsockopt_hmac_ident(struct sock *sk,
3317 if (optlen < sizeof(struct sctp_hmacalgo)) 3335 if (optlen < sizeof(struct sctp_hmacalgo))
3318 return -EINVAL; 3336 return -EINVAL;
3319 3337
3320 hmacs= memdup_user(optval, optlen); 3338 hmacs = memdup_user(optval, optlen);
3321 if (IS_ERR(hmacs)) 3339 if (IS_ERR(hmacs))
3322 return PTR_ERR(hmacs); 3340 return PTR_ERR(hmacs);
3323 3341
@@ -3355,7 +3373,7 @@ static int sctp_setsockopt_auth_key(struct sock *sk,
3355 if (optlen <= sizeof(struct sctp_authkey)) 3373 if (optlen <= sizeof(struct sctp_authkey))
3356 return -EINVAL; 3374 return -EINVAL;
3357 3375
3358 authkey= memdup_user(optval, optlen); 3376 authkey = memdup_user(optval, optlen);
3359 if (IS_ERR(authkey)) 3377 if (IS_ERR(authkey))
3360 return PTR_ERR(authkey); 3378 return PTR_ERR(authkey);
3361 3379
@@ -3909,7 +3927,7 @@ static int sctp_init_sock(struct sock *sk)
3909 */ 3927 */
3910 sp->hbinterval = net->sctp.hb_interval; 3928 sp->hbinterval = net->sctp.hb_interval;
3911 sp->pathmaxrxt = net->sctp.max_retrans_path; 3929 sp->pathmaxrxt = net->sctp.max_retrans_path;
3912 sp->pathmtu = 0; // allow default discovery 3930 sp->pathmtu = 0; /* allow default discovery */
3913 sp->sackdelay = net->sctp.sack_timeout; 3931 sp->sackdelay = net->sctp.sack_timeout;
3914 sp->sackfreq = 2; 3932 sp->sackfreq = 2;
3915 sp->param_flags = SPP_HB_ENABLE | 3933 sp->param_flags = SPP_HB_ENABLE |
@@ -4452,7 +4470,7 @@ static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len,
4452 /* If an address other than INADDR_ANY is specified, and 4470 /* If an address other than INADDR_ANY is specified, and
4453 * no transport is found, then the request is invalid. 4471 * no transport is found, then the request is invalid.
4454 */ 4472 */
4455 if (!sctp_is_any(sk, ( union sctp_addr *)&params.spp_address)) { 4473 if (!sctp_is_any(sk, (union sctp_addr *)&params.spp_address)) {
4456 trans = sctp_addr_id2transport(sk, &params.spp_address, 4474 trans = sctp_addr_id2transport(sk, &params.spp_address,
4457 params.spp_assoc_id); 4475 params.spp_assoc_id);
4458 if (!trans) { 4476 if (!trans) {
@@ -4558,12 +4576,13 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
4558 if (copy_from_user(&params, optval, len)) 4576 if (copy_from_user(&params, optval, len))
4559 return -EFAULT; 4577 return -EFAULT;
4560 } else if (len == sizeof(struct sctp_assoc_value)) { 4578 } else if (len == sizeof(struct sctp_assoc_value)) {
4561 pr_warn("Use of struct sctp_assoc_value in delayed_ack socket option deprecated\n"); 4579 pr_warn_ratelimited(DEPRECATED
4562 pr_warn("Use struct sctp_sack_info instead\n"); 4580 "Use of struct sctp_assoc_value in delayed_ack socket option.\n"
4581 "Use struct sctp_sack_info instead\n");
4563 if (copy_from_user(&params, optval, len)) 4582 if (copy_from_user(&params, optval, len))
4564 return -EFAULT; 4583 return -EFAULT;
4565 } else 4584 } else
4566 return - EINVAL; 4585 return -EINVAL;
4567 4586
4568 /* Get association, if sack_assoc_id != 0 and the socket is a one 4587 /* Get association, if sack_assoc_id != 0 and the socket is a one
4569 * to many style socket, and an association was not found, then 4588 * to many style socket, and an association was not found, then
@@ -4653,8 +4672,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
4653 if (!asoc) 4672 if (!asoc)
4654 return -EINVAL; 4673 return -EINVAL;
4655 4674
4656 to = optval + offsetof(struct sctp_getaddrs,addrs); 4675 to = optval + offsetof(struct sctp_getaddrs, addrs);
4657 space_left = len - offsetof(struct sctp_getaddrs,addrs); 4676 space_left = len - offsetof(struct sctp_getaddrs, addrs);
4658 4677
4659 list_for_each_entry(from, &asoc->peer.transport_addr_list, 4678 list_for_each_entry(from, &asoc->peer.transport_addr_list,
4660 transports) { 4679 transports) {
@@ -4714,7 +4733,7 @@ static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to,
4714 memcpy(to, &temp, addrlen); 4733 memcpy(to, &temp, addrlen);
4715 4734
4716 to += addrlen; 4735 to += addrlen;
4717 cnt ++; 4736 cnt++;
4718 space_left -= addrlen; 4737 space_left -= addrlen;
4719 *bytes_copied += addrlen; 4738 *bytes_copied += addrlen;
4720 } 4739 }
@@ -4763,8 +4782,8 @@ static int sctp_getsockopt_local_addrs(struct sock *sk, int len,
4763 bp = &asoc->base.bind_addr; 4782 bp = &asoc->base.bind_addr;
4764 } 4783 }
4765 4784
4766 to = optval + offsetof(struct sctp_getaddrs,addrs); 4785 to = optval + offsetof(struct sctp_getaddrs, addrs);
4767 space_left = len - offsetof(struct sctp_getaddrs,addrs); 4786 space_left = len - offsetof(struct sctp_getaddrs, addrs);
4768 4787
4769 addrs = kmalloc(space_left, GFP_KERNEL); 4788 addrs = kmalloc(space_left, GFP_KERNEL);
4770 if (!addrs) 4789 if (!addrs)
@@ -4803,7 +4822,7 @@ static int sctp_getsockopt_local_addrs(struct sock *sk, int len,
4803 memcpy(buf, &temp, addrlen); 4822 memcpy(buf, &temp, addrlen);
4804 buf += addrlen; 4823 buf += addrlen;
4805 bytes_copied += addrlen; 4824 bytes_copied += addrlen;
4806 cnt ++; 4825 cnt++;
4807 space_left -= addrlen; 4826 space_left -= addrlen;
4808 } 4827 }
4809 4828
@@ -5075,7 +5094,7 @@ static int sctp_getsockopt_associnfo(struct sock *sk, int len,
5075 assocparams.sasoc_cookie_life = ktime_to_ms(asoc->cookie_life); 5094 assocparams.sasoc_cookie_life = ktime_to_ms(asoc->cookie_life);
5076 5095
5077 list_for_each(pos, &asoc->peer.transport_addr_list) { 5096 list_for_each(pos, &asoc->peer.transport_addr_list) {
5078 cnt ++; 5097 cnt++;
5079 } 5098 }
5080 5099
5081 assocparams.sasoc_number_peer_destinations = cnt; 5100 assocparams.sasoc_number_peer_destinations = cnt;
@@ -5203,8 +5222,9 @@ static int sctp_getsockopt_maxseg(struct sock *sk, int len,
5203 struct sctp_association *asoc; 5222 struct sctp_association *asoc;
5204 5223
5205 if (len == sizeof(int)) { 5224 if (len == sizeof(int)) {
5206 pr_warn("Use of int in maxseg socket option deprecated\n"); 5225 pr_warn_ratelimited(DEPRECATED
5207 pr_warn("Use struct sctp_assoc_value instead\n"); 5226 "Use of int in maxseg socket option.\n"
5227 "Use struct sctp_assoc_value instead\n");
5208 params.assoc_id = 0; 5228 params.assoc_id = 0;
5209 } else if (len >= sizeof(struct sctp_assoc_value)) { 5229 } else if (len >= sizeof(struct sctp_assoc_value)) {
5210 len = sizeof(struct sctp_assoc_value); 5230 len = sizeof(struct sctp_assoc_value);
@@ -5295,8 +5315,9 @@ static int sctp_getsockopt_maxburst(struct sock *sk, int len,
5295 struct sctp_association *asoc; 5315 struct sctp_association *asoc;
5296 5316
5297 if (len == sizeof(int)) { 5317 if (len == sizeof(int)) {
5298 pr_warn("Use of int in max_burst socket option deprecated\n"); 5318 pr_warn_ratelimited(DEPRECATED
5299 pr_warn("Use struct sctp_assoc_value instead\n"); 5319 "Use of int in max_burst socket option.\n"
5320 "Use struct sctp_assoc_value instead\n");
5300 params.assoc_id = 0; 5321 params.assoc_id = 0;
5301 } else if (len >= sizeof(struct sctp_assoc_value)) { 5322 } else if (len >= sizeof(struct sctp_assoc_value)) {
5302 len = sizeof(struct sctp_assoc_value); 5323 len = sizeof(struct sctp_assoc_value);
@@ -5428,7 +5449,8 @@ static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len,
5428 return -EFAULT; 5449 return -EFAULT;
5429num: 5450num:
5430 len = sizeof(struct sctp_authchunks) + num_chunks; 5451 len = sizeof(struct sctp_authchunks) + num_chunks;
5431 if (put_user(len, optlen)) return -EFAULT; 5452 if (put_user(len, optlen))
5453 return -EFAULT;
5432 if (put_user(num_chunks, &p->gauth_number_of_chunks)) 5454 if (put_user(num_chunks, &p->gauth_number_of_chunks))
5433 return -EFAULT; 5455 return -EFAULT;
5434 return 0; 5456 return 0;
@@ -5460,7 +5482,7 @@ static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len,
5460 return -EINVAL; 5482 return -EINVAL;
5461 5483
5462 if (asoc) 5484 if (asoc)
5463 ch = (struct sctp_chunks_param*)asoc->c.auth_chunks; 5485 ch = (struct sctp_chunks_param *)asoc->c.auth_chunks;
5464 else 5486 else
5465 ch = sctp_sk(sk)->ep->auth_chunk_list; 5487 ch = sctp_sk(sk)->ep->auth_chunk_list;
5466 5488
@@ -6402,7 +6424,7 @@ static int sctp_msghdr_parse(const struct msghdr *msg, sctp_cmsgs_t *cmsgs)
6402 * Note: This function is the same function as in core/datagram.c 6424 * Note: This function is the same function as in core/datagram.c
6403 * with a few modifications to make lksctp work. 6425 * with a few modifications to make lksctp work.
6404 */ 6426 */
6405static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p) 6427static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p)
6406{ 6428{
6407 int error; 6429 int error;
6408 DEFINE_WAIT(wait); 6430 DEFINE_WAIT(wait);
diff --git a/net/sctp/ssnmap.c b/net/sctp/ssnmap.c
index 6007124aefa0..b9c8521c1a98 100644
--- a/net/sctp/ssnmap.c
+++ b/net/sctp/ssnmap.c
@@ -18,9 +18,8 @@
18 * See the GNU General Public License for more details. 18 * See the GNU General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with GNU CC; see the file COPYING. If not, write to 21 * along with GNU CC; see the file COPYING. If not, see
22 * the Free Software Foundation, 59 Temple Place - Suite 330, 22 * <http://www.gnu.org/licenses/>.
23 * Boston, MA 02111-1307, USA.
24 * 23 *
25 * Please send any bug reports or fixes you make to the 24 * Please send any bug reports or fixes you make to the
26 * email address(es): 25 * email address(es):
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 6b36561a1b3b..7135e617ab0f 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -19,9 +19,8 @@
19 * See the GNU General Public License for more details. 19 * See the GNU General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with GNU CC; see the file COPYING. If not, write to 22 * along with GNU CC; see the file COPYING. If not, see
23 * the Free Software Foundation, 59 Temple Place - Suite 330, 23 * <http://www.gnu.org/licenses/>.
24 * Boston, MA 02111-1307, USA.
25 * 24 *
26 * Please send any bug reports or fixes you make to the 25 * Please send any bug reports or fixes you make to the
27 * email address(es): 26 * email address(es):
@@ -56,11 +55,16 @@ extern long sysctl_sctp_mem[3];
56extern int sysctl_sctp_rmem[3]; 55extern int sysctl_sctp_rmem[3];
57extern int sysctl_sctp_wmem[3]; 56extern int sysctl_sctp_wmem[3];
58 57
59static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, 58static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
60 int write, 59 void __user *buffer, size_t *lenp,
60 loff_t *ppos);
61static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
62 void __user *buffer, size_t *lenp,
63 loff_t *ppos);
64static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
61 void __user *buffer, size_t *lenp, 65 void __user *buffer, size_t *lenp,
62
63 loff_t *ppos); 66 loff_t *ppos);
67
64static struct ctl_table sctp_table[] = { 68static struct ctl_table sctp_table[] = {
65 { 69 {
66 .procname = "sctp_mem", 70 .procname = "sctp_mem",
@@ -102,17 +106,17 @@ static struct ctl_table sctp_net_table[] = {
102 .data = &init_net.sctp.rto_min, 106 .data = &init_net.sctp.rto_min,
103 .maxlen = sizeof(unsigned int), 107 .maxlen = sizeof(unsigned int),
104 .mode = 0644, 108 .mode = 0644,
105 .proc_handler = proc_dointvec_minmax, 109 .proc_handler = proc_sctp_do_rto_min,
106 .extra1 = &one, 110 .extra1 = &one,
107 .extra2 = &timer_max 111 .extra2 = &init_net.sctp.rto_max
108 }, 112 },
109 { 113 {
110 .procname = "rto_max", 114 .procname = "rto_max",
111 .data = &init_net.sctp.rto_max, 115 .data = &init_net.sctp.rto_max,
112 .maxlen = sizeof(unsigned int), 116 .maxlen = sizeof(unsigned int),
113 .mode = 0644, 117 .mode = 0644,
114 .proc_handler = proc_dointvec_minmax, 118 .proc_handler = proc_sctp_do_rto_max,
115 .extra1 = &one, 119 .extra1 = &init_net.sctp.rto_min,
116 .extra2 = &timer_max 120 .extra2 = &timer_max
117 }, 121 },
118 { 122 {
@@ -294,8 +298,7 @@ static struct ctl_table sctp_net_table[] = {
294 { /* sentinel */ } 298 { /* sentinel */ }
295}; 299};
296 300
297static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, 301static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
298 int write,
299 void __user *buffer, size_t *lenp, 302 void __user *buffer, size_t *lenp,
300 loff_t *ppos) 303 loff_t *ppos)
301{ 304{
@@ -342,6 +345,60 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl,
342 return ret; 345 return ret;
343} 346}
344 347
348static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
349 void __user *buffer, size_t *lenp,
350 loff_t *ppos)
351{
352 struct net *net = current->nsproxy->net_ns;
353 int new_value;
354 struct ctl_table tbl;
355 unsigned int min = *(unsigned int *) ctl->extra1;
356 unsigned int max = *(unsigned int *) ctl->extra2;
357 int ret;
358
359 memset(&tbl, 0, sizeof(struct ctl_table));
360 tbl.maxlen = sizeof(unsigned int);
361
362 if (write)
363 tbl.data = &new_value;
364 else
365 tbl.data = &net->sctp.rto_min;
366 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
367 if (write) {
368 if (ret || new_value > max || new_value < min)
369 return -EINVAL;
370 net->sctp.rto_min = new_value;
371 }
372 return ret;
373}
374
375static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
376 void __user *buffer, size_t *lenp,
377 loff_t *ppos)
378{
379 struct net *net = current->nsproxy->net_ns;
380 int new_value;
381 struct ctl_table tbl;
382 unsigned int min = *(unsigned int *) ctl->extra1;
383 unsigned int max = *(unsigned int *) ctl->extra2;
384 int ret;
385
386 memset(&tbl, 0, sizeof(struct ctl_table));
387 tbl.maxlen = sizeof(unsigned int);
388
389 if (write)
390 tbl.data = &new_value;
391 else
392 tbl.data = &net->sctp.rto_max;
393 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
394 if (write) {
395 if (ret || new_value > max || new_value < min)
396 return -EINVAL;
397 net->sctp.rto_max = new_value;
398 }
399 return ret;
400}
401
345int sctp_sysctl_net_register(struct net *net) 402int sctp_sysctl_net_register(struct net *net)
346{ 403{
347 struct ctl_table *table; 404 struct ctl_table *table;
@@ -367,7 +424,7 @@ void sctp_sysctl_net_unregister(struct net *net)
367 kfree(table); 424 kfree(table);
368} 425}
369 426
370static struct ctl_table_header * sctp_sysctl_header; 427static struct ctl_table_header *sctp_sysctl_header;
371 428
372/* Sysctl registration. */ 429/* Sysctl registration. */
373void sctp_sysctl_register(void) 430void sctp_sysctl_register(void)
diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index e332efb124cc..d0810dc5f079 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -24,9 +24,8 @@
24 * See the GNU General Public License for more details. 24 * See the GNU General Public License for more details.
25 * 25 *
26 * You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to 27 * along with GNU CC; see the file COPYING. If not, see
28 * the Free Software Foundation, 59 Temple Place - Suite 330, 28 * <http://www.gnu.org/licenses/>.
29 * Boston, MA 02111-1307, USA.
30 * 29 *
31 * Please send any bug reports or fixes you make to the 30 * Please send any bug reports or fixes you make to the
32 * email address(es): 31 * email address(es):
@@ -573,7 +572,7 @@ void sctp_transport_burst_limited(struct sctp_transport *t)
573 u32 old_cwnd = t->cwnd; 572 u32 old_cwnd = t->cwnd;
574 u32 max_burst_bytes; 573 u32 max_burst_bytes;
575 574
576 if (t->burst_limited) 575 if (t->burst_limited || asoc->max_burst == 0)
577 return; 576 return;
578 577
579 max_burst_bytes = t->flight_size + (asoc->max_burst * asoc->pathmtu); 578 max_burst_bytes = t->flight_size + (asoc->max_burst * asoc->pathmtu);
diff --git a/net/sctp/tsnmap.c b/net/sctp/tsnmap.c
index fbda20028285..7635f9f2311d 100644
--- a/net/sctp/tsnmap.c
+++ b/net/sctp/tsnmap.c
@@ -21,9 +21,8 @@
21 * See the GNU General Public License for more details. 21 * See the GNU General Public License for more details.
22 * 22 *
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with GNU CC; see the file COPYING. If not, write to 24 * along with GNU CC; see the file COPYING. If not, see
25 * the Free Software Foundation, 59 Temple Place - Suite 330, 25 * <http://www.gnu.org/licenses/>.
26 * Boston, MA 02111-1307, USA.
27 * 26 *
28 * Please send any bug reports or fixes you make to the 27 * Please send any bug reports or fixes you make to the
29 * email address(es): 28 * email address(es):
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
index 81089ed65456..85c64658bd0b 100644
--- a/net/sctp/ulpevent.c
+++ b/net/sctp/ulpevent.c
@@ -22,9 +22,8 @@
22 * See the GNU General Public License for more details. 22 * See the GNU General Public License for more details.
23 * 23 *
24 * You should have received a copy of the GNU General Public License 24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to 25 * along with GNU CC; see the file COPYING. If not, see
26 * the Free Software Foundation, 59 Temple Place - Suite 330, 26 * <http://www.gnu.org/licenses/>.
27 * Boston, MA 02111-1307, USA.
28 * 27 *
29 * Please send any bug reports or fixes you make to the 28 * Please send any bug reports or fixes you make to the
30 * email address(es): 29 * email address(es):
diff --git a/net/sctp/ulpqueue.c b/net/sctp/ulpqueue.c
index 1c1484ed605d..5dc94117e9d4 100644
--- a/net/sctp/ulpqueue.c
+++ b/net/sctp/ulpqueue.c
@@ -21,9 +21,8 @@
21 * See the GNU General Public License for more details. 21 * See the GNU General Public License for more details.
22 * 22 *
23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with GNU CC; see the file COPYING. If not, write to 24 * along with GNU CC; see the file COPYING. If not, see
25 * the Free Software Foundation, 59 Temple Place - Suite 330, 25 * <http://www.gnu.org/licenses/>.
26 * Boston, MA 02111-1307, USA.
27 * 26 *
28 * Please send any bug reports or fixes you make to the 27 * Please send any bug reports or fixes you make to the
29 * email address(es): 28 * email address(es):
@@ -44,9 +43,9 @@
44#include <net/sctp/sm.h> 43#include <net/sctp/sm.h>
45 44
46/* Forward declarations for internal helpers. */ 45/* Forward declarations for internal helpers. */
47static struct sctp_ulpevent * sctp_ulpq_reasm(struct sctp_ulpq *ulpq, 46static struct sctp_ulpevent *sctp_ulpq_reasm(struct sctp_ulpq *ulpq,
48 struct sctp_ulpevent *); 47 struct sctp_ulpevent *);
49static struct sctp_ulpevent * sctp_ulpq_order(struct sctp_ulpq *, 48static struct sctp_ulpevent *sctp_ulpq_order(struct sctp_ulpq *,
50 struct sctp_ulpevent *); 49 struct sctp_ulpevent *);
51static void sctp_ulpq_reasm_drain(struct sctp_ulpq *ulpq); 50static void sctp_ulpq_reasm_drain(struct sctp_ulpq *ulpq);
52 51
@@ -108,7 +107,7 @@ int sctp_ulpq_tail_data(struct sctp_ulpq *ulpq, struct sctp_chunk *chunk,
108 event = sctp_ulpq_reasm(ulpq, event); 107 event = sctp_ulpq_reasm(ulpq, event);
109 108
110 /* Do ordering if needed. */ 109 /* Do ordering if needed. */
111 if ((event) && (event->msg_flags & MSG_EOR)){ 110 if ((event) && (event->msg_flags & MSG_EOR)) {
112 /* Create a temporary list to collect chunks on. */ 111 /* Create a temporary list to collect chunks on. */
113 skb_queue_head_init(&temp); 112 skb_queue_head_init(&temp);
114 __skb_queue_tail(&temp, sctp_event2skb(event)); 113 __skb_queue_tail(&temp, sctp_event2skb(event));
@@ -337,7 +336,8 @@ static struct sctp_ulpevent *sctp_make_reassembled_event(struct net *net,
337 pos = f_frag->next; 336 pos = f_frag->next;
338 337
339 /* Get the last skb in the f_frag's frag_list if present. */ 338 /* Get the last skb in the f_frag's frag_list if present. */
340 for (last = list; list; last = list, list = list->next); 339 for (last = list; list; last = list, list = list->next)
340 ;
341 341
342 /* Add the list of remaining fragments to the first fragments 342 /* Add the list of remaining fragments to the first fragments
343 * frag_list. 343 * frag_list.
@@ -727,7 +727,7 @@ static void sctp_ulpq_reasm_drain(struct sctp_ulpq *ulpq)
727 727
728 while ((event = sctp_ulpq_retrieve_reassembled(ulpq)) != NULL) { 728 while ((event = sctp_ulpq_retrieve_reassembled(ulpq)) != NULL) {
729 /* Do ordering if needed. */ 729 /* Do ordering if needed. */
730 if ((event) && (event->msg_flags & MSG_EOR)){ 730 if ((event) && (event->msg_flags & MSG_EOR)) {
731 skb_queue_head_init(&temp); 731 skb_queue_head_init(&temp);
732 __skb_queue_tail(&temp, sctp_event2skb(event)); 732 __skb_queue_tail(&temp, sctp_event2skb(event));
733 733
diff --git a/net/socket.c b/net/socket.c
index 0b18693f2be6..879933aaed4c 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1445,48 +1445,61 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
1445 err = fd1; 1445 err = fd1;
1446 goto out_release_both; 1446 goto out_release_both;
1447 } 1447 }
1448
1448 fd2 = get_unused_fd_flags(flags); 1449 fd2 = get_unused_fd_flags(flags);
1449 if (unlikely(fd2 < 0)) { 1450 if (unlikely(fd2 < 0)) {
1450 err = fd2; 1451 err = fd2;
1451 put_unused_fd(fd1); 1452 goto out_put_unused_1;
1452 goto out_release_both;
1453 } 1453 }
1454 1454
1455 newfile1 = sock_alloc_file(sock1, flags, NULL); 1455 newfile1 = sock_alloc_file(sock1, flags, NULL);
1456 if (unlikely(IS_ERR(newfile1))) { 1456 if (unlikely(IS_ERR(newfile1))) {
1457 err = PTR_ERR(newfile1); 1457 err = PTR_ERR(newfile1);
1458 put_unused_fd(fd1); 1458 goto out_put_unused_both;
1459 put_unused_fd(fd2);
1460 goto out_release_both;
1461 } 1459 }
1462 1460
1463 newfile2 = sock_alloc_file(sock2, flags, NULL); 1461 newfile2 = sock_alloc_file(sock2, flags, NULL);
1464 if (IS_ERR(newfile2)) { 1462 if (IS_ERR(newfile2)) {
1465 err = PTR_ERR(newfile2); 1463 err = PTR_ERR(newfile2);
1466 fput(newfile1); 1464 goto out_fput_1;
1467 put_unused_fd(fd1);
1468 put_unused_fd(fd2);
1469 sock_release(sock2);
1470 goto out;
1471 } 1465 }
1472 1466
1467 err = put_user(fd1, &usockvec[0]);
1468 if (err)
1469 goto out_fput_both;
1470
1471 err = put_user(fd2, &usockvec[1]);
1472 if (err)
1473 goto out_fput_both;
1474
1473 audit_fd_pair(fd1, fd2); 1475 audit_fd_pair(fd1, fd2);
1476
1474 fd_install(fd1, newfile1); 1477 fd_install(fd1, newfile1);
1475 fd_install(fd2, newfile2); 1478 fd_install(fd2, newfile2);
1476 /* fd1 and fd2 may be already another descriptors. 1479 /* fd1 and fd2 may be already another descriptors.
1477 * Not kernel problem. 1480 * Not kernel problem.
1478 */ 1481 */
1479 1482
1480 err = put_user(fd1, &usockvec[0]); 1483 return 0;
1481 if (!err)
1482 err = put_user(fd2, &usockvec[1]);
1483 if (!err)
1484 return 0;
1485 1484
1486 sys_close(fd2); 1485out_fput_both:
1487 sys_close(fd1); 1486 fput(newfile2);
1488 return err; 1487 fput(newfile1);
1488 put_unused_fd(fd2);
1489 put_unused_fd(fd1);
1490 goto out;
1489 1491
1492out_fput_1:
1493 fput(newfile1);
1494 put_unused_fd(fd2);
1495 put_unused_fd(fd1);
1496 sock_release(sock2);
1497 goto out;
1498
1499out_put_unused_both:
1500 put_unused_fd(fd2);
1501out_put_unused_1:
1502 put_unused_fd(fd1);
1490out_release_both: 1503out_release_both:
1491 sock_release(sock2); 1504 sock_release(sock2);
1492out_release_1: 1505out_release_1:
@@ -1973,7 +1986,7 @@ static int copy_msghdr_from_user(struct msghdr *kmsg,
1973 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr))) 1986 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
1974 return -EFAULT; 1987 return -EFAULT;
1975 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage)) 1988 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
1976 return -EINVAL; 1989 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
1977 return 0; 1990 return 0;
1978} 1991}
1979 1992
@@ -2968,11 +2981,8 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
2968 struct compat_ifreq __user *ifr32) 2981 struct compat_ifreq __user *ifr32)
2969{ 2982{
2970 struct ifreq kifr; 2983 struct ifreq kifr;
2971 struct ifreq __user *uifr;
2972 mm_segment_t old_fs; 2984 mm_segment_t old_fs;
2973 int err; 2985 int err;
2974 u32 data;
2975 void __user *datap;
2976 2986
2977 switch (cmd) { 2987 switch (cmd) {
2978 case SIOCBONDENSLAVE: 2988 case SIOCBONDENSLAVE:
@@ -2989,26 +2999,13 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
2989 set_fs(old_fs); 2999 set_fs(old_fs);
2990 3000
2991 return err; 3001 return err;
2992 case SIOCBONDSLAVEINFOQUERY:
2993 case SIOCBONDINFOQUERY:
2994 uifr = compat_alloc_user_space(sizeof(*uifr));
2995 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
2996 return -EFAULT;
2997
2998 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
2999 return -EFAULT;
3000
3001 datap = compat_ptr(data);
3002 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
3003 return -EFAULT;
3004
3005 return dev_ioctl(net, cmd, uifr);
3006 default: 3002 default:
3007 return -ENOIOCTLCMD; 3003 return -ENOIOCTLCMD;
3008 } 3004 }
3009} 3005}
3010 3006
3011static int siocdevprivate_ioctl(struct net *net, unsigned int cmd, 3007/* Handle ioctls that use ifreq::ifr_data and just need struct ifreq converted */
3008static int compat_ifr_data_ioctl(struct net *net, unsigned int cmd,
3012 struct compat_ifreq __user *u_ifreq32) 3009 struct compat_ifreq __user *u_ifreq32)
3013{ 3010{
3014 struct ifreq __user *u_ifreq64; 3011 struct ifreq __user *u_ifreq64;
@@ -3019,19 +3016,16 @@ static int siocdevprivate_ioctl(struct net *net, unsigned int cmd,
3019 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]), 3016 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
3020 IFNAMSIZ)) 3017 IFNAMSIZ))
3021 return -EFAULT; 3018 return -EFAULT;
3022 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data)) 3019 if (get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
3023 return -EFAULT; 3020 return -EFAULT;
3024 data64 = compat_ptr(data32); 3021 data64 = compat_ptr(data32);
3025 3022
3026 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64)); 3023 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
3027 3024
3028 /* Don't check these user accesses, just let that get trapped
3029 * in the ioctl handler instead.
3030 */
3031 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], 3025 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
3032 IFNAMSIZ)) 3026 IFNAMSIZ))
3033 return -EFAULT; 3027 return -EFAULT;
3034 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data)) 3028 if (put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
3035 return -EFAULT; 3029 return -EFAULT;
3036 3030
3037 return dev_ioctl(net, cmd, u_ifreq64); 3031 return dev_ioctl(net, cmd, u_ifreq64);
@@ -3111,27 +3105,6 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
3111 return err; 3105 return err;
3112} 3106}
3113 3107
3114static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uifr32)
3115{
3116 void __user *uptr;
3117 compat_uptr_t uptr32;
3118 struct ifreq __user *uifr;
3119
3120 uifr = compat_alloc_user_space(sizeof(*uifr));
3121 if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq)))
3122 return -EFAULT;
3123
3124 if (get_user(uptr32, &uifr32->ifr_data))
3125 return -EFAULT;
3126
3127 uptr = compat_ptr(uptr32);
3128
3129 if (put_user(uptr, &uifr->ifr_data))
3130 return -EFAULT;
3131
3132 return dev_ioctl(net, SIOCSHWTSTAMP, uifr);
3133}
3134
3135struct rtentry32 { 3108struct rtentry32 {
3136 u32 rt_pad1; 3109 u32 rt_pad1;
3137 struct sockaddr rt_dst; /* target address */ 3110 struct sockaddr rt_dst; /* target address */
@@ -3243,7 +3216,7 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
3243 struct net *net = sock_net(sk); 3216 struct net *net = sock_net(sk);
3244 3217
3245 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) 3218 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15))
3246 return siocdevprivate_ioctl(net, cmd, argp); 3219 return compat_ifr_data_ioctl(net, cmd, argp);
3247 3220
3248 switch (cmd) { 3221 switch (cmd) {
3249 case SIOCSIFBR: 3222 case SIOCSIFBR:
@@ -3263,8 +3236,6 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
3263 case SIOCBONDENSLAVE: 3236 case SIOCBONDENSLAVE:
3264 case SIOCBONDRELEASE: 3237 case SIOCBONDRELEASE:
3265 case SIOCBONDSETHWADDR: 3238 case SIOCBONDSETHWADDR:
3266 case SIOCBONDSLAVEINFOQUERY:
3267 case SIOCBONDINFOQUERY:
3268 case SIOCBONDCHANGEACTIVE: 3239 case SIOCBONDCHANGEACTIVE:
3269 return bond_ioctl(net, cmd, argp); 3240 return bond_ioctl(net, cmd, argp);
3270 case SIOCADDRT: 3241 case SIOCADDRT:
@@ -3274,8 +3245,11 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
3274 return do_siocgstamp(net, sock, cmd, argp); 3245 return do_siocgstamp(net, sock, cmd, argp);
3275 case SIOCGSTAMPNS: 3246 case SIOCGSTAMPNS:
3276 return do_siocgstampns(net, sock, cmd, argp); 3247 return do_siocgstampns(net, sock, cmd, argp);
3248 case SIOCBONDSLAVEINFOQUERY:
3249 case SIOCBONDINFOQUERY:
3277 case SIOCSHWTSTAMP: 3250 case SIOCSHWTSTAMP:
3278 return compat_siocshwtstamp(net, argp); 3251 case SIOCGHWTSTAMP:
3252 return compat_ifr_data_ioctl(net, cmd, argp);
3279 3253
3280 case FIOSETOWN: 3254 case FIOSETOWN:
3281 case SIOCSPGRP: 3255 case SIOCSPGRP:
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 97912b40c254..42fdfc634e56 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -1517,7 +1517,7 @@ out:
1517static int 1517static int
1518gss_refresh_null(struct rpc_task *task) 1518gss_refresh_null(struct rpc_task *task)
1519{ 1519{
1520 return -EACCES; 1520 return 0;
1521} 1521}
1522 1522
1523static __be32 * 1523static __be32 *
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index d0d14a04dce1..bf04b30a788a 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -471,15 +471,6 @@ struct rpc_filelist {
471 umode_t mode; 471 umode_t mode;
472}; 472};
473 473
474static int rpc_delete_dentry(const struct dentry *dentry)
475{
476 return 1;
477}
478
479static const struct dentry_operations rpc_dentry_operations = {
480 .d_delete = rpc_delete_dentry,
481};
482
483static struct inode * 474static struct inode *
484rpc_get_inode(struct super_block *sb, umode_t mode) 475rpc_get_inode(struct super_block *sb, umode_t mode)
485{ 476{
@@ -1266,7 +1257,7 @@ rpc_fill_super(struct super_block *sb, void *data, int silent)
1266 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 1257 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1267 sb->s_magic = RPCAUTH_GSSMAGIC; 1258 sb->s_magic = RPCAUTH_GSSMAGIC;
1268 sb->s_op = &s_ops; 1259 sb->s_op = &s_ops;
1269 sb->s_d_op = &rpc_dentry_operations; 1260 sb->s_d_op = &simple_dentry_operations;
1270 sb->s_time_gran = 1; 1261 sb->s_time_gran = 1;
1271 1262
1272 inode = rpc_get_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO); 1263 inode = rpc_get_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 0d4402587fdf..4c2a80b3c01e 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -621,12 +621,6 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
621 if (!p) 621 if (!p)
622 break; /* No more bearers to try */ 622 break; /* No more bearers to try */
623 623
624 if (tipc_bearer_blocked(p)) {
625 if (!s || tipc_bearer_blocked(s))
626 continue; /* Can't use either bearer */
627 b = s;
628 }
629
630 tipc_nmap_diff(&bcbearer->remains, &b->nodes, 624 tipc_nmap_diff(&bcbearer->remains, &b->nodes,
631 &bcbearer->remains_new); 625 &bcbearer->remains_new);
632 if (bcbearer->remains_new.count == bcbearer->remains.count) 626 if (bcbearer->remains_new.count == bcbearer->remains.count)
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 3f9707a16d06..3bb5f266b0eb 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * net/tipc/bearer.c: TIPC bearer code 2 * net/tipc/bearer.c: TIPC bearer code
3 * 3 *
4 * Copyright (c) 1996-2006, Ericsson AB 4 * Copyright (c) 1996-2006, 2013, Ericsson AB
5 * Copyright (c) 2004-2006, 2010-2011, Wind River Systems 5 * Copyright (c) 2004-2006, 2010-2013, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
@@ -41,8 +41,13 @@
41 41
42#define MAX_ADDR_STR 60 42#define MAX_ADDR_STR 60
43 43
44static struct tipc_media *media_list[MAX_MEDIA]; 44static struct tipc_media * const media_info_array[] = {
45static u32 media_count; 45 &eth_media_info,
46#ifdef CONFIG_TIPC_MEDIA_IB
47 &ib_media_info,
48#endif
49 NULL
50};
46 51
47struct tipc_bearer tipc_bearers[MAX_BEARERS]; 52struct tipc_bearer tipc_bearers[MAX_BEARERS];
48 53
@@ -55,11 +60,11 @@ struct tipc_media *tipc_media_find(const char *name)
55{ 60{
56 u32 i; 61 u32 i;
57 62
58 for (i = 0; i < media_count; i++) { 63 for (i = 0; media_info_array[i] != NULL; i++) {
59 if (!strcmp(media_list[i]->name, name)) 64 if (!strcmp(media_info_array[i]->name, name))
60 return media_list[i]; 65 break;
61 } 66 }
62 return NULL; 67 return media_info_array[i];
63} 68}
64 69
65/** 70/**
@@ -69,44 +74,11 @@ static struct tipc_media *media_find_id(u8 type)
69{ 74{
70 u32 i; 75 u32 i;
71 76
72 for (i = 0; i < media_count; i++) { 77 for (i = 0; media_info_array[i] != NULL; i++) {
73 if (media_list[i]->type_id == type) 78 if (media_info_array[i]->type_id == type)
74 return media_list[i]; 79 break;
75 } 80 }
76 return NULL; 81 return media_info_array[i];
77}
78
79/**
80 * tipc_register_media - register a media type
81 *
82 * Bearers for this media type must be activated separately at a later stage.
83 */
84int tipc_register_media(struct tipc_media *m_ptr)
85{
86 int res = -EINVAL;
87
88 write_lock_bh(&tipc_net_lock);
89
90 if ((strlen(m_ptr->name) + 1) > TIPC_MAX_MEDIA_NAME)
91 goto exit;
92 if (m_ptr->priority > TIPC_MAX_LINK_PRI)
93 goto exit;
94 if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) ||
95 (m_ptr->tolerance > TIPC_MAX_LINK_TOL))
96 goto exit;
97 if (media_count >= MAX_MEDIA)
98 goto exit;
99 if (tipc_media_find(m_ptr->name) || media_find_id(m_ptr->type_id))
100 goto exit;
101
102 media_list[media_count] = m_ptr;
103 media_count++;
104 res = 0;
105exit:
106 write_unlock_bh(&tipc_net_lock);
107 if (res)
108 pr_warn("Media <%s> registration error\n", m_ptr->name);
109 return res;
110} 82}
111 83
112/** 84/**
@@ -144,13 +116,11 @@ struct sk_buff *tipc_media_get_names(void)
144 if (!buf) 116 if (!buf)
145 return NULL; 117 return NULL;
146 118
147 read_lock_bh(&tipc_net_lock); 119 for (i = 0; media_info_array[i] != NULL; i++) {
148 for (i = 0; i < media_count; i++) {
149 tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, 120 tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
150 media_list[i]->name, 121 media_info_array[i]->name,
151 strlen(media_list[i]->name) + 1); 122 strlen(media_info_array[i]->name) + 1);
152 } 123 }
153 read_unlock_bh(&tipc_net_lock);
154 return buf; 124 return buf;
155} 125}
156 126
@@ -239,7 +209,7 @@ struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
239struct sk_buff *tipc_bearer_get_names(void) 209struct sk_buff *tipc_bearer_get_names(void)
240{ 210{
241 struct sk_buff *buf; 211 struct sk_buff *buf;
242 struct tipc_bearer *b_ptr; 212 struct tipc_bearer *b;
243 int i, j; 213 int i, j;
244 214
245 buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME)); 215 buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
@@ -247,13 +217,13 @@ struct sk_buff *tipc_bearer_get_names(void)
247 return NULL; 217 return NULL;
248 218
249 read_lock_bh(&tipc_net_lock); 219 read_lock_bh(&tipc_net_lock);
250 for (i = 0; i < media_count; i++) { 220 for (i = 0; media_info_array[i] != NULL; i++) {
251 for (j = 0; j < MAX_BEARERS; j++) { 221 for (j = 0; j < MAX_BEARERS; j++) {
252 b_ptr = &tipc_bearers[j]; 222 b = &tipc_bearers[j];
253 if (b_ptr->active && (b_ptr->media == media_list[i])) { 223 if (b->active && (b->media == media_info_array[i])) {
254 tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, 224 tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
255 b_ptr->name, 225 b->name,
256 strlen(b_ptr->name) + 1); 226 strlen(b->name) + 1);
257 } 227 }
258 } 228 }
259 } 229 }
@@ -275,31 +245,6 @@ void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
275 tipc_disc_remove_dest(b_ptr->link_req); 245 tipc_disc_remove_dest(b_ptr->link_req);
276} 246}
277 247
278/*
279 * Interrupt enabling new requests after bearer blocking:
280 * See bearer_send().
281 */
282void tipc_continue(struct tipc_bearer *b)
283{
284 spin_lock_bh(&b->lock);
285 b->blocked = 0;
286 spin_unlock_bh(&b->lock);
287}
288
289/*
290 * tipc_bearer_blocked - determines if bearer is currently blocked
291 */
292int tipc_bearer_blocked(struct tipc_bearer *b)
293{
294 int res;
295
296 spin_lock_bh(&b->lock);
297 res = b->blocked;
298 spin_unlock_bh(&b->lock);
299
300 return res;
301}
302
303/** 248/**
304 * tipc_enable_bearer - enable bearer with the given name 249 * tipc_enable_bearer - enable bearer with the given name
305 */ 250 */
@@ -387,6 +332,7 @@ restart:
387 332
388 b_ptr = &tipc_bearers[bearer_id]; 333 b_ptr = &tipc_bearers[bearer_id];
389 strcpy(b_ptr->name, name); 334 strcpy(b_ptr->name, name);
335 b_ptr->media = m_ptr;
390 res = m_ptr->enable_media(b_ptr); 336 res = m_ptr->enable_media(b_ptr);
391 if (res) { 337 if (res) {
392 pr_warn("Bearer <%s> rejected, enable failure (%d)\n", 338 pr_warn("Bearer <%s> rejected, enable failure (%d)\n",
@@ -395,7 +341,6 @@ restart:
395 } 341 }
396 342
397 b_ptr->identity = bearer_id; 343 b_ptr->identity = bearer_id;
398 b_ptr->media = m_ptr;
399 b_ptr->tolerance = m_ptr->tolerance; 344 b_ptr->tolerance = m_ptr->tolerance;
400 b_ptr->window = m_ptr->window; 345 b_ptr->window = m_ptr->window;
401 b_ptr->net_plane = bearer_id + 'A'; 346 b_ptr->net_plane = bearer_id + 'A';
@@ -420,17 +365,16 @@ exit:
420} 365}
421 366
422/** 367/**
423 * tipc_block_bearer - Block the bearer, and reset all its links 368 * tipc_reset_bearer - Reset all links established over this bearer
424 */ 369 */
425int tipc_block_bearer(struct tipc_bearer *b_ptr) 370static int tipc_reset_bearer(struct tipc_bearer *b_ptr)
426{ 371{
427 struct tipc_link *l_ptr; 372 struct tipc_link *l_ptr;
428 struct tipc_link *temp_l_ptr; 373 struct tipc_link *temp_l_ptr;
429 374
430 read_lock_bh(&tipc_net_lock); 375 read_lock_bh(&tipc_net_lock);
431 pr_info("Blocking bearer <%s>\n", b_ptr->name); 376 pr_info("Resetting bearer <%s>\n", b_ptr->name);
432 spin_lock_bh(&b_ptr->lock); 377 spin_lock_bh(&b_ptr->lock);
433 b_ptr->blocked = 1;
434 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { 378 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
435 struct tipc_node *n_ptr = l_ptr->owner; 379 struct tipc_node *n_ptr = l_ptr->owner;
436 380
@@ -456,7 +400,6 @@ static void bearer_disable(struct tipc_bearer *b_ptr)
456 400
457 pr_info("Disabling bearer <%s>\n", b_ptr->name); 401 pr_info("Disabling bearer <%s>\n", b_ptr->name);
458 spin_lock_bh(&b_ptr->lock); 402 spin_lock_bh(&b_ptr->lock);
459 b_ptr->blocked = 1;
460 b_ptr->media->disable_media(b_ptr); 403 b_ptr->media->disable_media(b_ptr);
461 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { 404 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
462 tipc_link_delete(l_ptr); 405 tipc_link_delete(l_ptr);
@@ -490,6 +433,211 @@ int tipc_disable_bearer(const char *name)
490} 433}
491 434
492 435
436/* tipc_l2_media_addr_set - initialize Ethernet media address structure
437 *
438 * Media-dependent "value" field stores MAC address in first 6 bytes
439 * and zeroes out the remaining bytes.
440 */
441void tipc_l2_media_addr_set(const struct tipc_bearer *b,
442 struct tipc_media_addr *a, char *mac)
443{
444 int len = b->media->hwaddr_len;
445
446 if (unlikely(sizeof(a->value) < len)) {
447 WARN_ONCE(1, "Media length invalid\n");
448 return;
449 }
450
451 memcpy(a->value, mac, len);
452 memset(a->value + len, 0, sizeof(a->value) - len);
453 a->media_id = b->media->type_id;
454 a->broadcast = !memcmp(mac, b->bcast_addr.value, len);
455}
456
457int tipc_enable_l2_media(struct tipc_bearer *b)
458{
459 struct net_device *dev;
460 char *driver_name = strchr((const char *)b->name, ':') + 1;
461
462 /* Find device with specified name */
463 dev = dev_get_by_name(&init_net, driver_name);
464 if (!dev)
465 return -ENODEV;
466
467 /* Associate TIPC bearer with Ethernet bearer */
468 b->media_ptr = dev;
469 memset(b->bcast_addr.value, 0, sizeof(b->bcast_addr.value));
470 memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len);
471 b->bcast_addr.media_id = b->media->type_id;
472 b->bcast_addr.broadcast = 1;
473 b->mtu = dev->mtu;
474 tipc_l2_media_addr_set(b, &b->addr, (char *)dev->dev_addr);
475 rcu_assign_pointer(dev->tipc_ptr, b);
476 return 0;
477}
478
479/* tipc_disable_l2_media - detach TIPC bearer from an Ethernet interface
480 *
481 * Mark Ethernet bearer as inactive so that incoming buffers are thrown away,
482 * then get worker thread to complete bearer cleanup. (Can't do cleanup
483 * here because cleanup code needs to sleep and caller holds spinlocks.)
484 */
485void tipc_disable_l2_media(struct tipc_bearer *b)
486{
487 struct net_device *dev = (struct net_device *)b->media_ptr;
488 RCU_INIT_POINTER(dev->tipc_ptr, NULL);
489 dev_put(dev);
490}
491
492/**
493 * tipc_l2_send_msg - send a TIPC packet out over an Ethernet interface
494 * @buf: the packet to be sent
495 * @b_ptr: the bearer throught which the packet is to be sent
496 * @dest: peer destination address
497 */
498int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b,
499 struct tipc_media_addr *dest)
500{
501 struct sk_buff *clone;
502 int delta;
503 struct net_device *dev = (struct net_device *)b->media_ptr;
504
505 clone = skb_clone(buf, GFP_ATOMIC);
506 if (!clone)
507 return 0;
508
509 delta = dev->hard_header_len - skb_headroom(buf);
510 if ((delta > 0) &&
511 pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) {
512 kfree_skb(clone);
513 return 0;
514 }
515
516 skb_reset_network_header(clone);
517 clone->dev = dev;
518 clone->protocol = htons(ETH_P_TIPC);
519 dev_hard_header(clone, dev, ETH_P_TIPC, dest->value,
520 dev->dev_addr, clone->len);
521 dev_queue_xmit(clone);
522 return 0;
523}
524
525/* tipc_bearer_send- sends buffer to destination over bearer
526 *
527 * IMPORTANT:
528 * The media send routine must not alter the buffer being passed in
529 * as it may be needed for later retransmission!
530 */
531void tipc_bearer_send(struct tipc_bearer *b, struct sk_buff *buf,
532 struct tipc_media_addr *dest)
533{
534 b->media->send_msg(buf, b, dest);
535}
536
537/**
538 * tipc_l2_rcv_msg - handle incoming TIPC message from an interface
539 * @buf: the received packet
540 * @dev: the net device that the packet was received on
541 * @pt: the packet_type structure which was used to register this handler
542 * @orig_dev: the original receive net device in case the device is a bond
543 *
544 * Accept only packets explicitly sent to this node, or broadcast packets;
545 * ignores packets sent using interface multicast, and traffic sent to other
546 * nodes (which can happen if interface is running in promiscuous mode).
547 */
548static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
549 struct packet_type *pt, struct net_device *orig_dev)
550{
551 struct tipc_bearer *b_ptr;
552
553 if (!net_eq(dev_net(dev), &init_net)) {
554 kfree_skb(buf);
555 return NET_RX_DROP;
556 }
557
558 rcu_read_lock();
559 b_ptr = rcu_dereference(dev->tipc_ptr);
560 if (likely(b_ptr)) {
561 if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
562 buf->next = NULL;
563 tipc_recv_msg(buf, b_ptr);
564 rcu_read_unlock();
565 return NET_RX_SUCCESS;
566 }
567 }
568 rcu_read_unlock();
569
570 kfree_skb(buf);
571 return NET_RX_DROP;
572}
573
574/**
575 * tipc_l2_device_event - handle device events from network device
576 * @nb: the context of the notification
577 * @evt: the type of event
578 * @ptr: the net device that the event was on
579 *
580 * This function is called by the Ethernet driver in case of link
581 * change event.
582 */
583static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
584 void *ptr)
585{
586 struct tipc_bearer *b_ptr;
587 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
588
589 if (!net_eq(dev_net(dev), &init_net))
590 return NOTIFY_DONE;
591
592 rcu_read_lock();
593 b_ptr = rcu_dereference(dev->tipc_ptr);
594 if (!b_ptr) {
595 rcu_read_unlock();
596 return NOTIFY_DONE;
597 }
598
599 b_ptr->mtu = dev->mtu;
600
601 switch (evt) {
602 case NETDEV_CHANGE:
603 if (netif_carrier_ok(dev))
604 break;
605 case NETDEV_DOWN:
606 case NETDEV_CHANGEMTU:
607 case NETDEV_CHANGEADDR:
608 tipc_reset_bearer(b_ptr);
609 break;
610 case NETDEV_UNREGISTER:
611 case NETDEV_CHANGENAME:
612 tipc_disable_bearer(b_ptr->name);
613 break;
614 }
615 rcu_read_unlock();
616
617 return NOTIFY_OK;
618}
619
620static struct packet_type tipc_packet_type __read_mostly = {
621 .type = __constant_htons(ETH_P_TIPC),
622 .func = tipc_l2_rcv_msg,
623};
624
625static struct notifier_block notifier = {
626 .notifier_call = tipc_l2_device_event,
627 .priority = 0,
628};
629
630int tipc_bearer_setup(void)
631{
632 dev_add_pack(&tipc_packet_type);
633 return register_netdevice_notifier(&notifier);
634}
635
636void tipc_bearer_cleanup(void)
637{
638 unregister_netdevice_notifier(&notifier);
639 dev_remove_pack(&tipc_packet_type);
640}
493 641
494void tipc_bearer_stop(void) 642void tipc_bearer_stop(void)
495{ 643{
@@ -499,5 +647,4 @@ void tipc_bearer_stop(void)
499 if (tipc_bearers[i].active) 647 if (tipc_bearers[i].active)
500 bearer_disable(&tipc_bearers[i]); 648 bearer_disable(&tipc_bearers[i]);
501 } 649 }
502 media_count = 0;
503} 650}
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index e5e04be6fffa..fa95c34ca926 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/bearer.h: Include file for TIPC bearer code 2 * net/tipc/bearer.h: Include file for TIPC bearer code
3 * 3 *
4 * Copyright (c) 1996-2006, Ericsson AB 4 * Copyright (c) 1996-2006, 2013, Ericsson AB
5 * Copyright (c) 2005, 2010-2011, Wind River Systems 5 * Copyright (c) 2005, 2010-2011, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -73,18 +73,18 @@ struct tipc_media_addr {
73struct tipc_bearer; 73struct tipc_bearer;
74 74
75/** 75/**
76 * struct tipc_media - TIPC media information available to internal users 76 * struct tipc_media - Media specific info exposed to generic bearer layer
77 * @send_msg: routine which handles buffer transmission 77 * @send_msg: routine which handles buffer transmission
78 * @enable_media: routine which enables a media 78 * @enable_media: routine which enables a media
79 * @disable_media: routine which disables a media 79 * @disable_media: routine which disables a media
80 * @addr2str: routine which converts media address to string 80 * @addr2str: routine which converts media address to string
81 * @addr2msg: routine which converts media address to protocol message area 81 * @addr2msg: routine which converts media address to protocol message area
82 * @msg2addr: routine which converts media address from protocol message area 82 * @msg2addr: routine which converts media address from protocol message area
83 * @bcast_addr: media address used in broadcasting
84 * @priority: default link (and bearer) priority 83 * @priority: default link (and bearer) priority
85 * @tolerance: default time (in ms) before declaring link failure 84 * @tolerance: default time (in ms) before declaring link failure
86 * @window: default window (in packets) before declaring link congestion 85 * @window: default window (in packets) before declaring link congestion
87 * @type_id: TIPC media identifier 86 * @type_id: TIPC media identifier
87 * @hwaddr_len: TIPC media address len
88 * @name: media name 88 * @name: media name
89 */ 89 */
90struct tipc_media { 90struct tipc_media {
@@ -101,18 +101,20 @@ struct tipc_media {
101 u32 tolerance; 101 u32 tolerance;
102 u32 window; 102 u32 window;
103 u32 type_id; 103 u32 type_id;
104 u32 hwaddr_len;
104 char name[TIPC_MAX_MEDIA_NAME]; 105 char name[TIPC_MAX_MEDIA_NAME];
105}; 106};
106 107
107/** 108/**
108 * struct tipc_bearer - TIPC bearer structure 109 * struct tipc_bearer - Generic TIPC bearer structure
110 * @dev: ptr to associated network device
109 * @usr_handle: pointer to additional media-specific information about bearer 111 * @usr_handle: pointer to additional media-specific information about bearer
110 * @mtu: max packet size bearer can support 112 * @mtu: max packet size bearer can support
111 * @blocked: non-zero if bearer is blocked
112 * @lock: spinlock for controlling access to bearer 113 * @lock: spinlock for controlling access to bearer
113 * @addr: media-specific address associated with bearer 114 * @addr: media-specific address associated with bearer
114 * @name: bearer name (format = media:interface) 115 * @name: bearer name (format = media:interface)
115 * @media: ptr to media structure associated with bearer 116 * @media: ptr to media structure associated with bearer
117 * @bcast_addr: media address used in broadcasting
116 * @priority: default link priority for bearer 118 * @priority: default link priority for bearer
117 * @window: default window size for bearer 119 * @window: default window size for bearer
118 * @tolerance: default link tolerance for bearer 120 * @tolerance: default link tolerance for bearer
@@ -128,9 +130,8 @@ struct tipc_media {
128 * care of initializing all other fields. 130 * care of initializing all other fields.
129 */ 131 */
130struct tipc_bearer { 132struct tipc_bearer {
131 void *usr_handle; /* initalized by media */ 133 void *media_ptr; /* initalized by media */
132 u32 mtu; /* initalized by media */ 134 u32 mtu; /* initalized by media */
133 int blocked; /* initalized by media */
134 struct tipc_media_addr addr; /* initalized by media */ 135 struct tipc_media_addr addr; /* initalized by media */
135 char name[TIPC_MAX_BEARER_NAME]; 136 char name[TIPC_MAX_BEARER_NAME];
136 spinlock_t lock; 137 spinlock_t lock;
@@ -159,34 +160,31 @@ extern struct tipc_bearer tipc_bearers[];
159/* 160/*
160 * TIPC routines available to supported media types 161 * TIPC routines available to supported media types
161 */ 162 */
162int tipc_register_media(struct tipc_media *m_ptr);
163 163
164void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr); 164void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr);
165 165
166int tipc_block_bearer(struct tipc_bearer *b_ptr);
167void tipc_continue(struct tipc_bearer *tb_ptr);
168
169int tipc_enable_bearer(const char *bearer_name, u32 disc_domain, u32 priority); 166int tipc_enable_bearer(const char *bearer_name, u32 disc_domain, u32 priority);
170int tipc_disable_bearer(const char *name); 167int tipc_disable_bearer(const char *name);
171 168
172/* 169/*
173 * Routines made available to TIPC by supported media types 170 * Routines made available to TIPC by supported media types
174 */ 171 */
175int tipc_eth_media_start(void); 172extern struct tipc_media eth_media_info;
176void tipc_eth_media_stop(void);
177 173
178#ifdef CONFIG_TIPC_MEDIA_IB 174#ifdef CONFIG_TIPC_MEDIA_IB
179int tipc_ib_media_start(void); 175extern struct tipc_media ib_media_info;
180void tipc_ib_media_stop(void);
181#else
182static inline int tipc_ib_media_start(void) { return 0; }
183static inline void tipc_ib_media_stop(void) { return; }
184#endif 176#endif
185 177
186int tipc_media_set_priority(const char *name, u32 new_value); 178int tipc_media_set_priority(const char *name, u32 new_value);
187int tipc_media_set_window(const char *name, u32 new_value); 179int tipc_media_set_window(const char *name, u32 new_value);
188void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); 180void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a);
189struct sk_buff *tipc_media_get_names(void); 181struct sk_buff *tipc_media_get_names(void);
182void tipc_l2_media_addr_set(const struct tipc_bearer *b,
183 struct tipc_media_addr *a, char *mac);
184int tipc_enable_l2_media(struct tipc_bearer *b);
185void tipc_disable_l2_media(struct tipc_bearer *b);
186int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b,
187 struct tipc_media_addr *dest);
190 188
191struct sk_buff *tipc_bearer_get_names(void); 189struct sk_buff *tipc_bearer_get_names(void);
192void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest); 190void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest);
@@ -194,20 +192,10 @@ void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest);
194struct tipc_bearer *tipc_bearer_find(const char *name); 192struct tipc_bearer *tipc_bearer_find(const char *name);
195struct tipc_bearer *tipc_bearer_find_interface(const char *if_name); 193struct tipc_bearer *tipc_bearer_find_interface(const char *if_name);
196struct tipc_media *tipc_media_find(const char *name); 194struct tipc_media *tipc_media_find(const char *name);
197int tipc_bearer_blocked(struct tipc_bearer *b_ptr); 195int tipc_bearer_setup(void);
196void tipc_bearer_cleanup(void);
198void tipc_bearer_stop(void); 197void tipc_bearer_stop(void);
199 198void tipc_bearer_send(struct tipc_bearer *b, struct sk_buff *buf,
200/** 199 struct tipc_media_addr *dest);
201 * tipc_bearer_send- sends buffer to destination over bearer
202 *
203 * IMPORTANT:
204 * The media send routine must not alter the buffer being passed in
205 * as it may be needed for later retransmission!
206 */
207static inline void tipc_bearer_send(struct tipc_bearer *b, struct sk_buff *buf,
208 struct tipc_media_addr *dest)
209{
210 b->media->send_msg(buf, b, dest);
211}
212 200
213#endif /* _TIPC_BEARER_H */ 201#endif /* _TIPC_BEARER_H */
diff --git a/net/tipc/core.c b/net/tipc/core.c
index fd4eeeaa972a..f9e88d8b04ca 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -82,8 +82,7 @@ struct sk_buff *tipc_buf_acquire(u32 size)
82static void tipc_core_stop_net(void) 82static void tipc_core_stop_net(void)
83{ 83{
84 tipc_net_stop(); 84 tipc_net_stop();
85 tipc_eth_media_stop(); 85 tipc_bearer_cleanup();
86 tipc_ib_media_stop();
87} 86}
88 87
89/** 88/**
@@ -94,10 +93,7 @@ int tipc_core_start_net(unsigned long addr)
94 int res; 93 int res;
95 94
96 tipc_net_start(addr); 95 tipc_net_start(addr);
97 res = tipc_eth_media_start(); 96 res = tipc_bearer_setup();
98 if (res < 0)
99 goto err;
100 res = tipc_ib_media_start();
101 if (res < 0) 97 if (res < 0)
102 goto err; 98 goto err;
103 return res; 99 return res;
@@ -113,7 +109,6 @@ err:
113static void tipc_core_stop(void) 109static void tipc_core_stop(void)
114{ 110{
115 tipc_netlink_stop(); 111 tipc_netlink_stop();
116 tipc_handler_stop();
117 tipc_cfg_stop(); 112 tipc_cfg_stop();
118 tipc_subscr_stop(); 113 tipc_subscr_stop();
119 tipc_nametbl_stop(); 114 tipc_nametbl_stop();
@@ -146,9 +141,10 @@ static int tipc_core_start(void)
146 res = tipc_subscr_start(); 141 res = tipc_subscr_start();
147 if (!res) 142 if (!res)
148 res = tipc_cfg_init(); 143 res = tipc_cfg_init();
149 if (res) 144 if (res) {
145 tipc_handler_stop();
150 tipc_core_stop(); 146 tipc_core_stop();
151 147 }
152 return res; 148 return res;
153} 149}
154 150
@@ -178,6 +174,7 @@ static int __init tipc_init(void)
178 174
179static void __exit tipc_exit(void) 175static void __exit tipc_exit(void)
180{ 176{
177 tipc_handler_stop();
181 tipc_core_stop_net(); 178 tipc_core_stop_net();
182 tipc_core_stop(); 179 tipc_core_stop();
183 pr_info("Deactivated\n"); 180 pr_info("Deactivated\n");
diff --git a/net/tipc/core.h b/net/tipc/core.h
index 94895d4e86ab..1ff477b0450d 100644
--- a/net/tipc/core.h
+++ b/net/tipc/core.h
@@ -47,7 +47,7 @@
47#include <linux/mm.h> 47#include <linux/mm.h>
48#include <linux/timer.h> 48#include <linux/timer.h>
49#include <linux/string.h> 49#include <linux/string.h>
50#include <asm/uaccess.h> 50#include <linux/uaccess.h>
51#include <linux/interrupt.h> 51#include <linux/interrupt.h>
52#include <linux/atomic.h> 52#include <linux/atomic.h>
53#include <asm/hardirq.h> 53#include <asm/hardirq.h>
diff --git a/net/tipc/discover.c b/net/tipc/discover.c
index ecc758c6eacf..bc849f1efa16 100644
--- a/net/tipc/discover.c
+++ b/net/tipc/discover.c
@@ -239,7 +239,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr)
239 /* Accept discovery message & send response, if necessary */ 239 /* Accept discovery message & send response, if necessary */
240 link_fully_up = link_working_working(link); 240 link_fully_up = link_working_working(link);
241 241
242 if ((type == DSC_REQ_MSG) && !link_fully_up && !b_ptr->blocked) { 242 if ((type == DSC_REQ_MSG) && !link_fully_up) {
243 rbuf = tipc_disc_init_msg(DSC_RESP_MSG, orig, b_ptr); 243 rbuf = tipc_disc_init_msg(DSC_RESP_MSG, orig, b_ptr);
244 if (rbuf) { 244 if (rbuf) {
245 tipc_bearer_send(b_ptr, rbuf, &media_addr); 245 tipc_bearer_send(b_ptr, rbuf, &media_addr);
@@ -288,16 +288,6 @@ void tipc_disc_remove_dest(struct tipc_link_req *req)
288} 288}
289 289
290/** 290/**
291 * disc_send_msg - send link setup request message
292 * @req: ptr to link request structure
293 */
294static void disc_send_msg(struct tipc_link_req *req)
295{
296 if (!req->bearer->blocked)
297 tipc_bearer_send(req->bearer, req->buf, &req->dest);
298}
299
300/**
301 * disc_timeout - send a periodic link setup request 291 * disc_timeout - send a periodic link setup request
302 * @req: ptr to link request structure 292 * @req: ptr to link request structure
303 * 293 *
@@ -322,7 +312,8 @@ static void disc_timeout(struct tipc_link_req *req)
322 * hold at fast polling rate if don't have any associated nodes, 312 * hold at fast polling rate if don't have any associated nodes,
323 * otherwise hold at slow polling rate 313 * otherwise hold at slow polling rate
324 */ 314 */
325 disc_send_msg(req); 315 tipc_bearer_send(req->bearer, req->buf, &req->dest);
316
326 317
327 req->timer_intv *= 2; 318 req->timer_intv *= 2;
328 if (req->num_nodes) 319 if (req->num_nodes)
@@ -368,7 +359,7 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest,
368 k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req); 359 k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req);
369 k_start_timer(&req->timer, req->timer_intv); 360 k_start_timer(&req->timer, req->timer_intv);
370 b_ptr->link_req = req; 361 b_ptr->link_req = req;
371 disc_send_msg(req); 362 tipc_bearer_send(req->bearer, req->buf, &req->dest);
372 return 0; 363 return 0;
373} 364}
374 365
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index f80d59f5a161..67cf3f935dba 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/eth_media.c: Ethernet bearer support for TIPC 2 * net/tipc/eth_media.c: Ethernet bearer support for TIPC
3 * 3 *
4 * Copyright (c) 2001-2007, Ericsson AB 4 * Copyright (c) 2001-2007, 2013, Ericsson AB
5 * Copyright (c) 2005-2008, 2011-2013, Wind River Systems 5 * Copyright (c) 2005-2008, 2011-2013, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -37,259 +37,11 @@
37#include "core.h" 37#include "core.h"
38#include "bearer.h" 38#include "bearer.h"
39 39
40#define MAX_ETH_MEDIA MAX_BEARERS
41
42#define ETH_ADDR_OFFSET 4 /* message header offset of MAC address */ 40#define ETH_ADDR_OFFSET 4 /* message header offset of MAC address */
43 41
44/** 42/* convert Ethernet address to string */
45 * struct eth_media - Ethernet bearer data structure 43static int tipc_eth_addr2str(struct tipc_media_addr *a, char *str_buf,
46 * @bearer: ptr to associated "generic" bearer structure 44 int str_size)
47 * @dev: ptr to associated Ethernet network device
48 * @tipc_packet_type: used in binding TIPC to Ethernet driver
49 * @setup: work item used when enabling bearer
50 * @cleanup: work item used when disabling bearer
51 */
52struct eth_media {
53 struct tipc_bearer *bearer;
54 struct net_device *dev;
55 struct packet_type tipc_packet_type;
56 struct work_struct setup;
57 struct work_struct cleanup;
58};
59
60static struct tipc_media eth_media_info;
61static struct eth_media eth_media_array[MAX_ETH_MEDIA];
62static int eth_started;
63
64static int recv_notification(struct notifier_block *nb, unsigned long evt,
65 void *dv);
66/*
67 * Network device notifier info
68 */
69static struct notifier_block notifier = {
70 .notifier_call = recv_notification,
71 .priority = 0
72};
73
74/**
75 * eth_media_addr_set - initialize Ethernet media address structure
76 *
77 * Media-dependent "value" field stores MAC address in first 6 bytes
78 * and zeroes out the remaining bytes.
79 */
80static void eth_media_addr_set(const struct tipc_bearer *tb_ptr,
81 struct tipc_media_addr *a, char *mac)
82{
83 memcpy(a->value, mac, ETH_ALEN);
84 memset(a->value + ETH_ALEN, 0, sizeof(a->value) - ETH_ALEN);
85 a->media_id = TIPC_MEDIA_TYPE_ETH;
86 a->broadcast = !memcmp(mac, tb_ptr->bcast_addr.value, ETH_ALEN);
87}
88
89/**
90 * send_msg - send a TIPC message out over an Ethernet interface
91 */
92static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr,
93 struct tipc_media_addr *dest)
94{
95 struct sk_buff *clone;
96 struct net_device *dev;
97 int delta;
98
99 clone = skb_clone(buf, GFP_ATOMIC);
100 if (!clone)
101 return 0;
102
103 dev = ((struct eth_media *)(tb_ptr->usr_handle))->dev;
104 delta = dev->hard_header_len - skb_headroom(buf);
105
106 if ((delta > 0) &&
107 pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) {
108 kfree_skb(clone);
109 return 0;
110 }
111
112 skb_reset_network_header(clone);
113 clone->dev = dev;
114 clone->protocol = htons(ETH_P_TIPC);
115 dev_hard_header(clone, dev, ETH_P_TIPC, dest->value,
116 dev->dev_addr, clone->len);
117 dev_queue_xmit(clone);
118 return 0;
119}
120
121/**
122 * recv_msg - handle incoming TIPC message from an Ethernet interface
123 *
124 * Accept only packets explicitly sent to this node, or broadcast packets;
125 * ignores packets sent using Ethernet multicast, and traffic sent to other
126 * nodes (which can happen if interface is running in promiscuous mode).
127 */
128static int recv_msg(struct sk_buff *buf, struct net_device *dev,
129 struct packet_type *pt, struct net_device *orig_dev)
130{
131 struct eth_media *eb_ptr = (struct eth_media *)pt->af_packet_priv;
132
133 if (!net_eq(dev_net(dev), &init_net)) {
134 kfree_skb(buf);
135 return NET_RX_DROP;
136 }
137
138 if (likely(eb_ptr->bearer)) {
139 if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
140 buf->next = NULL;
141 tipc_recv_msg(buf, eb_ptr->bearer);
142 return NET_RX_SUCCESS;
143 }
144 }
145 kfree_skb(buf);
146 return NET_RX_DROP;
147}
148
149/**
150 * setup_media - setup association between Ethernet bearer and interface
151 */
152static void setup_media(struct work_struct *work)
153{
154 struct eth_media *eb_ptr =
155 container_of(work, struct eth_media, setup);
156
157 dev_add_pack(&eb_ptr->tipc_packet_type);
158}
159
160/**
161 * enable_media - attach TIPC bearer to an Ethernet interface
162 */
163static int enable_media(struct tipc_bearer *tb_ptr)
164{
165 struct net_device *dev;
166 struct eth_media *eb_ptr = &eth_media_array[0];
167 struct eth_media *stop = &eth_media_array[MAX_ETH_MEDIA];
168 char *driver_name = strchr((const char *)tb_ptr->name, ':') + 1;
169 int pending_dev = 0;
170
171 /* Find unused Ethernet bearer structure */
172 while (eb_ptr->dev) {
173 if (!eb_ptr->bearer)
174 pending_dev++;
175 if (++eb_ptr == stop)
176 return pending_dev ? -EAGAIN : -EDQUOT;
177 }
178
179 /* Find device with specified name */
180 dev = dev_get_by_name(&init_net, driver_name);
181 if (!dev)
182 return -ENODEV;
183
184 /* Create Ethernet bearer for device */
185 eb_ptr->dev = dev;
186 eb_ptr->tipc_packet_type.type = htons(ETH_P_TIPC);
187 eb_ptr->tipc_packet_type.dev = dev;
188 eb_ptr->tipc_packet_type.func = recv_msg;
189 eb_ptr->tipc_packet_type.af_packet_priv = eb_ptr;
190 INIT_LIST_HEAD(&(eb_ptr->tipc_packet_type.list));
191 INIT_WORK(&eb_ptr->setup, setup_media);
192 schedule_work(&eb_ptr->setup);
193
194 /* Associate TIPC bearer with Ethernet bearer */
195 eb_ptr->bearer = tb_ptr;
196 tb_ptr->usr_handle = (void *)eb_ptr;
197 memset(tb_ptr->bcast_addr.value, 0, sizeof(tb_ptr->bcast_addr.value));
198 memcpy(tb_ptr->bcast_addr.value, dev->broadcast, ETH_ALEN);
199 tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_ETH;
200 tb_ptr->bcast_addr.broadcast = 1;
201 tb_ptr->mtu = dev->mtu;
202 tb_ptr->blocked = 0;
203 eth_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr);
204 return 0;
205}
206
207/**
208 * cleanup_media - break association between Ethernet bearer and interface
209 *
210 * This routine must be invoked from a work queue because it can sleep.
211 */
212static void cleanup_media(struct work_struct *work)
213{
214 struct eth_media *eb_ptr =
215 container_of(work, struct eth_media, cleanup);
216
217 dev_remove_pack(&eb_ptr->tipc_packet_type);
218 dev_put(eb_ptr->dev);
219 eb_ptr->dev = NULL;
220}
221
222/**
223 * disable_media - detach TIPC bearer from an Ethernet interface
224 *
225 * Mark Ethernet bearer as inactive so that incoming buffers are thrown away,
226 * then get worker thread to complete bearer cleanup. (Can't do cleanup
227 * here because cleanup code needs to sleep and caller holds spinlocks.)
228 */
229static void disable_media(struct tipc_bearer *tb_ptr)
230{
231 struct eth_media *eb_ptr = (struct eth_media *)tb_ptr->usr_handle;
232
233 eb_ptr->bearer = NULL;
234 INIT_WORK(&eb_ptr->cleanup, cleanup_media);
235 schedule_work(&eb_ptr->cleanup);
236}
237
238/**
239 * recv_notification - handle device updates from OS
240 *
241 * Change the state of the Ethernet bearer (if any) associated with the
242 * specified device.
243 */
244static int recv_notification(struct notifier_block *nb, unsigned long evt,
245 void *ptr)
246{
247 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
248 struct eth_media *eb_ptr = &eth_media_array[0];
249 struct eth_media *stop = &eth_media_array[MAX_ETH_MEDIA];
250
251 if (!net_eq(dev_net(dev), &init_net))
252 return NOTIFY_DONE;
253
254 while ((eb_ptr->dev != dev)) {
255 if (++eb_ptr == stop)
256 return NOTIFY_DONE; /* couldn't find device */
257 }
258 if (!eb_ptr->bearer)
259 return NOTIFY_DONE; /* bearer had been disabled */
260
261 eb_ptr->bearer->mtu = dev->mtu;
262
263 switch (evt) {
264 case NETDEV_CHANGE:
265 if (netif_carrier_ok(dev))
266 tipc_continue(eb_ptr->bearer);
267 else
268 tipc_block_bearer(eb_ptr->bearer);
269 break;
270 case NETDEV_UP:
271 tipc_continue(eb_ptr->bearer);
272 break;
273 case NETDEV_DOWN:
274 tipc_block_bearer(eb_ptr->bearer);
275 break;
276 case NETDEV_CHANGEMTU:
277 case NETDEV_CHANGEADDR:
278 tipc_block_bearer(eb_ptr->bearer);
279 tipc_continue(eb_ptr->bearer);
280 break;
281 case NETDEV_UNREGISTER:
282 case NETDEV_CHANGENAME:
283 tipc_disable_bearer(eb_ptr->bearer->name);
284 break;
285 }
286 return NOTIFY_OK;
287}
288
289/**
290 * eth_addr2str - convert Ethernet address to string
291 */
292static int eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size)
293{ 45{
294 if (str_size < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */ 46 if (str_size < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */
295 return 1; 47 return 1;
@@ -298,10 +50,8 @@ static int eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size)
298 return 0; 50 return 0;
299} 51}
300 52
301/** 53/* convert Ethernet address format to message header format */
302 * eth_str2addr - convert Ethernet address format to message header format 54static int tipc_eth_addr2msg(struct tipc_media_addr *a, char *msg_area)
303 */
304static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area)
305{ 55{
306 memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); 56 memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE);
307 msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH; 57 msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH;
@@ -309,68 +59,30 @@ static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area)
309 return 0; 59 return 0;
310} 60}
311 61
312/** 62/* convert message header address format to Ethernet format */
313 * eth_str2addr - convert message header address format to Ethernet format 63static int tipc_eth_msg2addr(const struct tipc_bearer *tb_ptr,
314 */ 64 struct tipc_media_addr *a, char *msg_area)
315static int eth_msg2addr(const struct tipc_bearer *tb_ptr,
316 struct tipc_media_addr *a, char *msg_area)
317{ 65{
318 if (msg_area[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_ETH) 66 if (msg_area[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_ETH)
319 return 1; 67 return 1;
320 68
321 eth_media_addr_set(tb_ptr, a, msg_area + ETH_ADDR_OFFSET); 69 tipc_l2_media_addr_set(tb_ptr, a, msg_area + ETH_ADDR_OFFSET);
322 return 0; 70 return 0;
323} 71}
324 72
325/* 73/* Ethernet media registration info */
326 * Ethernet media registration info 74struct tipc_media eth_media_info = {
327 */ 75 .send_msg = tipc_l2_send_msg,
328static struct tipc_media eth_media_info = { 76 .enable_media = tipc_enable_l2_media,
329 .send_msg = send_msg, 77 .disable_media = tipc_disable_l2_media,
330 .enable_media = enable_media, 78 .addr2str = tipc_eth_addr2str,
331 .disable_media = disable_media, 79 .addr2msg = tipc_eth_addr2msg,
332 .addr2str = eth_addr2str, 80 .msg2addr = tipc_eth_msg2addr,
333 .addr2msg = eth_addr2msg,
334 .msg2addr = eth_msg2addr,
335 .priority = TIPC_DEF_LINK_PRI, 81 .priority = TIPC_DEF_LINK_PRI,
336 .tolerance = TIPC_DEF_LINK_TOL, 82 .tolerance = TIPC_DEF_LINK_TOL,
337 .window = TIPC_DEF_LINK_WIN, 83 .window = TIPC_DEF_LINK_WIN,
338 .type_id = TIPC_MEDIA_TYPE_ETH, 84 .type_id = TIPC_MEDIA_TYPE_ETH,
85 .hwaddr_len = ETH_ALEN,
339 .name = "eth" 86 .name = "eth"
340}; 87};
341 88
342/**
343 * tipc_eth_media_start - activate Ethernet bearer support
344 *
345 * Register Ethernet media type with TIPC bearer code. Also register
346 * with OS for notifications about device state changes.
347 */
348int tipc_eth_media_start(void)
349{
350 int res;
351
352 if (eth_started)
353 return -EINVAL;
354
355 res = tipc_register_media(&eth_media_info);
356 if (res)
357 return res;
358
359 res = register_netdevice_notifier(&notifier);
360 if (!res)
361 eth_started = 1;
362 return res;
363}
364
365/**
366 * tipc_eth_media_stop - deactivate Ethernet bearer support
367 */
368void tipc_eth_media_stop(void)
369{
370 if (!eth_started)
371 return;
372
373 flush_scheduled_work();
374 unregister_netdevice_notifier(&notifier);
375 eth_started = 0;
376}
diff --git a/net/tipc/handler.c b/net/tipc/handler.c
index b36f0fcd9bdf..e4bc8a296744 100644
--- a/net/tipc/handler.c
+++ b/net/tipc/handler.c
@@ -56,12 +56,13 @@ unsigned int tipc_k_signal(Handler routine, unsigned long argument)
56{ 56{
57 struct queue_item *item; 57 struct queue_item *item;
58 58
59 spin_lock_bh(&qitem_lock);
59 if (!handler_enabled) { 60 if (!handler_enabled) {
60 pr_err("Signal request ignored by handler\n"); 61 pr_err("Signal request ignored by handler\n");
62 spin_unlock_bh(&qitem_lock);
61 return -ENOPROTOOPT; 63 return -ENOPROTOOPT;
62 } 64 }
63 65
64 spin_lock_bh(&qitem_lock);
65 item = kmem_cache_alloc(tipc_queue_item_cache, GFP_ATOMIC); 66 item = kmem_cache_alloc(tipc_queue_item_cache, GFP_ATOMIC);
66 if (!item) { 67 if (!item) {
67 pr_err("Signal queue out of memory\n"); 68 pr_err("Signal queue out of memory\n");
@@ -112,10 +113,14 @@ void tipc_handler_stop(void)
112 struct list_head *l, *n; 113 struct list_head *l, *n;
113 struct queue_item *item; 114 struct queue_item *item;
114 115
115 if (!handler_enabled) 116 spin_lock_bh(&qitem_lock);
117 if (!handler_enabled) {
118 spin_unlock_bh(&qitem_lock);
116 return; 119 return;
117 120 }
118 handler_enabled = 0; 121 handler_enabled = 0;
122 spin_unlock_bh(&qitem_lock);
123
119 tasklet_kill(&tipc_tasklet); 124 tasklet_kill(&tipc_tasklet);
120 125
121 spin_lock_bh(&qitem_lock); 126 spin_lock_bh(&qitem_lock);
diff --git a/net/tipc/ib_media.c b/net/tipc/ib_media.c
index c13989297464..844a77e25828 100644
--- a/net/tipc/ib_media.c
+++ b/net/tipc/ib_media.c
@@ -42,252 +42,9 @@
42#include "core.h" 42#include "core.h"
43#include "bearer.h" 43#include "bearer.h"
44 44
45#define MAX_IB_MEDIA MAX_BEARERS 45/* convert InfiniBand address to string */
46 46static int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf,
47/** 47 int str_size)
48 * struct ib_media - Infiniband media data structure
49 * @bearer: ptr to associated "generic" bearer structure
50 * @dev: ptr to associated Infiniband network device
51 * @tipc_packet_type: used in binding TIPC to Infiniband driver
52 * @cleanup: work item used when disabling bearer
53 */
54
55struct ib_media {
56 struct tipc_bearer *bearer;
57 struct net_device *dev;
58 struct packet_type tipc_packet_type;
59 struct work_struct setup;
60 struct work_struct cleanup;
61};
62
63static struct tipc_media ib_media_info;
64static struct ib_media ib_media_array[MAX_IB_MEDIA];
65static int ib_started;
66
67/**
68 * ib_media_addr_set - initialize Infiniband media address structure
69 *
70 * Media-dependent "value" field stores MAC address in first 6 bytes
71 * and zeroes out the remaining bytes.
72 */
73static void ib_media_addr_set(const struct tipc_bearer *tb_ptr,
74 struct tipc_media_addr *a, char *mac)
75{
76 BUILD_BUG_ON(sizeof(a->value) < INFINIBAND_ALEN);
77 memcpy(a->value, mac, INFINIBAND_ALEN);
78 a->media_id = TIPC_MEDIA_TYPE_IB;
79 a->broadcast = !memcmp(mac, tb_ptr->bcast_addr.value, INFINIBAND_ALEN);
80}
81
82/**
83 * send_msg - send a TIPC message out over an InfiniBand interface
84 */
85static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr,
86 struct tipc_media_addr *dest)
87{
88 struct sk_buff *clone;
89 struct net_device *dev;
90 int delta;
91
92 clone = skb_clone(buf, GFP_ATOMIC);
93 if (!clone)
94 return 0;
95
96 dev = ((struct ib_media *)(tb_ptr->usr_handle))->dev;
97 delta = dev->hard_header_len - skb_headroom(buf);
98
99 if ((delta > 0) &&
100 pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) {
101 kfree_skb(clone);
102 return 0;
103 }
104
105 skb_reset_network_header(clone);
106 clone->dev = dev;
107 clone->protocol = htons(ETH_P_TIPC);
108 dev_hard_header(clone, dev, ETH_P_TIPC, dest->value,
109 dev->dev_addr, clone->len);
110 dev_queue_xmit(clone);
111 return 0;
112}
113
114/**
115 * recv_msg - handle incoming TIPC message from an InfiniBand interface
116 *
117 * Accept only packets explicitly sent to this node, or broadcast packets;
118 * ignores packets sent using InfiniBand multicast, and traffic sent to other
119 * nodes (which can happen if interface is running in promiscuous mode).
120 */
121static int recv_msg(struct sk_buff *buf, struct net_device *dev,
122 struct packet_type *pt, struct net_device *orig_dev)
123{
124 struct ib_media *ib_ptr = (struct ib_media *)pt->af_packet_priv;
125
126 if (!net_eq(dev_net(dev), &init_net)) {
127 kfree_skb(buf);
128 return NET_RX_DROP;
129 }
130
131 if (likely(ib_ptr->bearer)) {
132 if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
133 buf->next = NULL;
134 tipc_recv_msg(buf, ib_ptr->bearer);
135 return NET_RX_SUCCESS;
136 }
137 }
138 kfree_skb(buf);
139 return NET_RX_DROP;
140}
141
142/**
143 * setup_bearer - setup association between InfiniBand bearer and interface
144 */
145static void setup_media(struct work_struct *work)
146{
147 struct ib_media *ib_ptr =
148 container_of(work, struct ib_media, setup);
149
150 dev_add_pack(&ib_ptr->tipc_packet_type);
151}
152
153/**
154 * enable_media - attach TIPC bearer to an InfiniBand interface
155 */
156static int enable_media(struct tipc_bearer *tb_ptr)
157{
158 struct net_device *dev;
159 struct ib_media *ib_ptr = &ib_media_array[0];
160 struct ib_media *stop = &ib_media_array[MAX_IB_MEDIA];
161 char *driver_name = strchr((const char *)tb_ptr->name, ':') + 1;
162 int pending_dev = 0;
163
164 /* Find unused InfiniBand bearer structure */
165 while (ib_ptr->dev) {
166 if (!ib_ptr->bearer)
167 pending_dev++;
168 if (++ib_ptr == stop)
169 return pending_dev ? -EAGAIN : -EDQUOT;
170 }
171
172 /* Find device with specified name */
173 dev = dev_get_by_name(&init_net, driver_name);
174 if (!dev)
175 return -ENODEV;
176
177 /* Create InfiniBand bearer for device */
178 ib_ptr->dev = dev;
179 ib_ptr->tipc_packet_type.type = htons(ETH_P_TIPC);
180 ib_ptr->tipc_packet_type.dev = dev;
181 ib_ptr->tipc_packet_type.func = recv_msg;
182 ib_ptr->tipc_packet_type.af_packet_priv = ib_ptr;
183 INIT_LIST_HEAD(&(ib_ptr->tipc_packet_type.list));
184 INIT_WORK(&ib_ptr->setup, setup_media);
185 schedule_work(&ib_ptr->setup);
186
187 /* Associate TIPC bearer with InfiniBand bearer */
188 ib_ptr->bearer = tb_ptr;
189 tb_ptr->usr_handle = (void *)ib_ptr;
190 memset(tb_ptr->bcast_addr.value, 0, sizeof(tb_ptr->bcast_addr.value));
191 memcpy(tb_ptr->bcast_addr.value, dev->broadcast, INFINIBAND_ALEN);
192 tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_IB;
193 tb_ptr->bcast_addr.broadcast = 1;
194 tb_ptr->mtu = dev->mtu;
195 tb_ptr->blocked = 0;
196 ib_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr);
197 return 0;
198}
199
200/**
201 * cleanup_bearer - break association between InfiniBand bearer and interface
202 *
203 * This routine must be invoked from a work queue because it can sleep.
204 */
205static void cleanup_bearer(struct work_struct *work)
206{
207 struct ib_media *ib_ptr =
208 container_of(work, struct ib_media, cleanup);
209
210 dev_remove_pack(&ib_ptr->tipc_packet_type);
211 dev_put(ib_ptr->dev);
212 ib_ptr->dev = NULL;
213}
214
215/**
216 * disable_media - detach TIPC bearer from an InfiniBand interface
217 *
218 * Mark InfiniBand bearer as inactive so that incoming buffers are thrown away,
219 * then get worker thread to complete bearer cleanup. (Can't do cleanup
220 * here because cleanup code needs to sleep and caller holds spinlocks.)
221 */
222static void disable_media(struct tipc_bearer *tb_ptr)
223{
224 struct ib_media *ib_ptr = (struct ib_media *)tb_ptr->usr_handle;
225
226 ib_ptr->bearer = NULL;
227 INIT_WORK(&ib_ptr->cleanup, cleanup_bearer);
228 schedule_work(&ib_ptr->cleanup);
229}
230
231/**
232 * recv_notification - handle device updates from OS
233 *
234 * Change the state of the InfiniBand bearer (if any) associated with the
235 * specified device.
236 */
237static int recv_notification(struct notifier_block *nb, unsigned long evt,
238 void *ptr)
239{
240 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
241 struct ib_media *ib_ptr = &ib_media_array[0];
242 struct ib_media *stop = &ib_media_array[MAX_IB_MEDIA];
243
244 if (!net_eq(dev_net(dev), &init_net))
245 return NOTIFY_DONE;
246
247 while ((ib_ptr->dev != dev)) {
248 if (++ib_ptr == stop)
249 return NOTIFY_DONE; /* couldn't find device */
250 }
251 if (!ib_ptr->bearer)
252 return NOTIFY_DONE; /* bearer had been disabled */
253
254 ib_ptr->bearer->mtu = dev->mtu;
255
256 switch (evt) {
257 case NETDEV_CHANGE:
258 if (netif_carrier_ok(dev))
259 tipc_continue(ib_ptr->bearer);
260 else
261 tipc_block_bearer(ib_ptr->bearer);
262 break;
263 case NETDEV_UP:
264 tipc_continue(ib_ptr->bearer);
265 break;
266 case NETDEV_DOWN:
267 tipc_block_bearer(ib_ptr->bearer);
268 break;
269 case NETDEV_CHANGEMTU:
270 case NETDEV_CHANGEADDR:
271 tipc_block_bearer(ib_ptr->bearer);
272 tipc_continue(ib_ptr->bearer);
273 break;
274 case NETDEV_UNREGISTER:
275 case NETDEV_CHANGENAME:
276 tipc_disable_bearer(ib_ptr->bearer->name);
277 break;
278 }
279 return NOTIFY_OK;
280}
281
282static struct notifier_block notifier = {
283 .notifier_call = recv_notification,
284 .priority = 0,
285};
286
287/**
288 * ib_addr2str - convert InfiniBand address to string
289 */
290static int ib_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size)
291{ 48{
292 if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */ 49 if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */
293 return 1; 50 return 1;
@@ -297,10 +54,8 @@ static int ib_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size)
297 return 0; 54 return 0;
298} 55}
299 56
300/** 57/* convert InfiniBand address format to message header format */
301 * ib_addr2msg - convert InfiniBand address format to message header format 58static int tipc_ib_addr2msg(struct tipc_media_addr *a, char *msg_area)
302 */
303static int ib_addr2msg(struct tipc_media_addr *a, char *msg_area)
304{ 59{
305 memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); 60 memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE);
306 msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_IB; 61 msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_IB;
@@ -308,65 +63,27 @@ static int ib_addr2msg(struct tipc_media_addr *a, char *msg_area)
308 return 0; 63 return 0;
309} 64}
310 65
311/** 66/* convert message header address format to InfiniBand format */
312 * ib_msg2addr - convert message header address format to InfiniBand format 67static int tipc_ib_msg2addr(const struct tipc_bearer *tb_ptr,
313 */ 68 struct tipc_media_addr *a, char *msg_area)
314static int ib_msg2addr(const struct tipc_bearer *tb_ptr,
315 struct tipc_media_addr *a, char *msg_area)
316{ 69{
317 ib_media_addr_set(tb_ptr, a, msg_area); 70 tipc_l2_media_addr_set(tb_ptr, a, msg_area);
318 return 0; 71 return 0;
319} 72}
320 73
321/* 74/* InfiniBand media registration info */
322 * InfiniBand media registration info 75struct tipc_media ib_media_info = {
323 */ 76 .send_msg = tipc_l2_send_msg,
324static struct tipc_media ib_media_info = { 77 .enable_media = tipc_enable_l2_media,
325 .send_msg = send_msg, 78 .disable_media = tipc_disable_l2_media,
326 .enable_media = enable_media, 79 .addr2str = tipc_ib_addr2str,
327 .disable_media = disable_media, 80 .addr2msg = tipc_ib_addr2msg,
328 .addr2str = ib_addr2str, 81 .msg2addr = tipc_ib_msg2addr,
329 .addr2msg = ib_addr2msg,
330 .msg2addr = ib_msg2addr,
331 .priority = TIPC_DEF_LINK_PRI, 82 .priority = TIPC_DEF_LINK_PRI,
332 .tolerance = TIPC_DEF_LINK_TOL, 83 .tolerance = TIPC_DEF_LINK_TOL,
333 .window = TIPC_DEF_LINK_WIN, 84 .window = TIPC_DEF_LINK_WIN,
334 .type_id = TIPC_MEDIA_TYPE_IB, 85 .type_id = TIPC_MEDIA_TYPE_IB,
86 .hwaddr_len = INFINIBAND_ALEN,
335 .name = "ib" 87 .name = "ib"
336}; 88};
337 89
338/**
339 * tipc_ib_media_start - activate InfiniBand bearer support
340 *
341 * Register InfiniBand media type with TIPC bearer code. Also register
342 * with OS for notifications about device state changes.
343 */
344int tipc_ib_media_start(void)
345{
346 int res;
347
348 if (ib_started)
349 return -EINVAL;
350
351 res = tipc_register_media(&ib_media_info);
352 if (res)
353 return res;
354
355 res = register_netdevice_notifier(&notifier);
356 if (!res)
357 ib_started = 1;
358 return res;
359}
360
361/**
362 * tipc_ib_media_stop - deactivate InfiniBand bearer support
363 */
364void tipc_ib_media_stop(void)
365{
366 if (!ib_started)
367 return;
368
369 flush_scheduled_work();
370 unregister_netdevice_notifier(&notifier);
371 ib_started = 0;
372}
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 69cd9bf3f561..3d73144a1ccc 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -386,14 +386,7 @@ exit:
386 */ 386 */
387static void link_release_outqueue(struct tipc_link *l_ptr) 387static void link_release_outqueue(struct tipc_link *l_ptr)
388{ 388{
389 struct sk_buff *buf = l_ptr->first_out; 389 kfree_skb_list(l_ptr->first_out);
390 struct sk_buff *next;
391
392 while (buf) {
393 next = buf->next;
394 kfree_skb(buf);
395 buf = next;
396 }
397 l_ptr->first_out = NULL; 390 l_ptr->first_out = NULL;
398 l_ptr->out_queue_size = 0; 391 l_ptr->out_queue_size = 0;
399} 392}
@@ -415,32 +408,15 @@ void tipc_link_reset_fragments(struct tipc_link *l_ptr)
415 */ 408 */
416void tipc_link_stop(struct tipc_link *l_ptr) 409void tipc_link_stop(struct tipc_link *l_ptr)
417{ 410{
418 struct sk_buff *buf; 411 kfree_skb_list(l_ptr->oldest_deferred_in);
419 struct sk_buff *next; 412 kfree_skb_list(l_ptr->first_out);
420
421 buf = l_ptr->oldest_deferred_in;
422 while (buf) {
423 next = buf->next;
424 kfree_skb(buf);
425 buf = next;
426 }
427
428 buf = l_ptr->first_out;
429 while (buf) {
430 next = buf->next;
431 kfree_skb(buf);
432 buf = next;
433 }
434
435 tipc_link_reset_fragments(l_ptr); 413 tipc_link_reset_fragments(l_ptr);
436
437 kfree_skb(l_ptr->proto_msg_queue); 414 kfree_skb(l_ptr->proto_msg_queue);
438 l_ptr->proto_msg_queue = NULL; 415 l_ptr->proto_msg_queue = NULL;
439} 416}
440 417
441void tipc_link_reset(struct tipc_link *l_ptr) 418void tipc_link_reset(struct tipc_link *l_ptr)
442{ 419{
443 struct sk_buff *buf;
444 u32 prev_state = l_ptr->state; 420 u32 prev_state = l_ptr->state;
445 u32 checkpoint = l_ptr->next_in_no; 421 u32 checkpoint = l_ptr->next_in_no;
446 int was_active_link = tipc_link_is_active(l_ptr); 422 int was_active_link = tipc_link_is_active(l_ptr);
@@ -471,12 +447,7 @@ void tipc_link_reset(struct tipc_link *l_ptr)
471 link_release_outqueue(l_ptr); 447 link_release_outqueue(l_ptr);
472 kfree_skb(l_ptr->proto_msg_queue); 448 kfree_skb(l_ptr->proto_msg_queue);
473 l_ptr->proto_msg_queue = NULL; 449 l_ptr->proto_msg_queue = NULL;
474 buf = l_ptr->oldest_deferred_in; 450 kfree_skb_list(l_ptr->oldest_deferred_in);
475 while (buf) {
476 struct sk_buff *next = buf->next;
477 kfree_skb(buf);
478 buf = next;
479 }
480 if (!list_empty(&l_ptr->waiting_ports)) 451 if (!list_empty(&l_ptr->waiting_ports))
481 tipc_link_wakeup_ports(l_ptr, 1); 452 tipc_link_wakeup_ports(l_ptr, 1);
482 453
@@ -517,10 +488,11 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
517 if (!l_ptr->started && (event != STARTING_EVT)) 488 if (!l_ptr->started && (event != STARTING_EVT))
518 return; /* Not yet. */ 489 return; /* Not yet. */
519 490
520 if (link_blocked(l_ptr)) { 491 /* Check whether changeover is going on */
492 if (l_ptr->exp_msg_count) {
521 if (event == TIMEOUT_EVT) 493 if (event == TIMEOUT_EVT)
522 link_set_timer(l_ptr, cont_intv); 494 link_set_timer(l_ptr, cont_intv);
523 return; /* Changeover going on */ 495 return;
524 } 496 }
525 497
526 switch (l_ptr->state) { 498 switch (l_ptr->state) {
@@ -790,8 +762,7 @@ int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf)
790 return link_send_long_buf(l_ptr, buf); 762 return link_send_long_buf(l_ptr, buf);
791 763
792 /* Packet can be queued or sent. */ 764 /* Packet can be queued or sent. */
793 if (likely(!tipc_bearer_blocked(l_ptr->b_ptr) && 765 if (likely(!link_congested(l_ptr))) {
794 !link_congested(l_ptr))) {
795 link_add_to_outqueue(l_ptr, buf, msg); 766 link_add_to_outqueue(l_ptr, buf, msg);
796 767
797 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); 768 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
@@ -957,14 +928,13 @@ static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf,
957 928
958 if (likely(!link_congested(l_ptr))) { 929 if (likely(!link_congested(l_ptr))) {
959 if (likely(msg_size(msg) <= l_ptr->max_pkt)) { 930 if (likely(msg_size(msg) <= l_ptr->max_pkt)) {
960 if (likely(!tipc_bearer_blocked(l_ptr->b_ptr))) { 931 link_add_to_outqueue(l_ptr, buf, msg);
961 link_add_to_outqueue(l_ptr, buf, msg); 932 tipc_bearer_send(l_ptr->b_ptr, buf,
962 tipc_bearer_send(l_ptr->b_ptr, buf, 933 &l_ptr->media_addr);
963 &l_ptr->media_addr); 934 l_ptr->unacked_window = 0;
964 l_ptr->unacked_window = 0; 935 return res;
965 return res; 936 }
966 } 937 else
967 } else
968 *used_max_pkt = l_ptr->max_pkt; 938 *used_max_pkt = l_ptr->max_pkt;
969 } 939 }
970 return tipc_link_send_buf(l_ptr, buf); /* All other cases */ 940 return tipc_link_send_buf(l_ptr, buf); /* All other cases */
@@ -1013,8 +983,7 @@ exit:
1013 } 983 }
1014 984
1015 /* Exit if link (or bearer) is congested */ 985 /* Exit if link (or bearer) is congested */
1016 if (link_congested(l_ptr) || 986 if (link_congested(l_ptr)) {
1017 tipc_bearer_blocked(l_ptr->b_ptr)) {
1018 res = link_schedule_port(l_ptr, 987 res = link_schedule_port(l_ptr,
1019 sender->ref, res); 988 sender->ref, res);
1020 goto exit; 989 goto exit;
@@ -1127,10 +1096,7 @@ again:
1127 if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) { 1096 if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) {
1128 res = -EFAULT; 1097 res = -EFAULT;
1129error: 1098error:
1130 for (; buf_chain; buf_chain = buf) { 1099 kfree_skb_list(buf_chain);
1131 buf = buf_chain->next;
1132 kfree_skb(buf_chain);
1133 }
1134 return res; 1100 return res;
1135 } 1101 }
1136 sect_crs += sz; 1102 sect_crs += sz;
@@ -1180,18 +1146,12 @@ error:
1180 if (l_ptr->max_pkt < max_pkt) { 1146 if (l_ptr->max_pkt < max_pkt) {
1181 sender->max_pkt = l_ptr->max_pkt; 1147 sender->max_pkt = l_ptr->max_pkt;
1182 tipc_node_unlock(node); 1148 tipc_node_unlock(node);
1183 for (; buf_chain; buf_chain = buf) { 1149 kfree_skb_list(buf_chain);
1184 buf = buf_chain->next;
1185 kfree_skb(buf_chain);
1186 }
1187 goto again; 1150 goto again;
1188 } 1151 }
1189 } else { 1152 } else {
1190reject: 1153reject:
1191 for (; buf_chain; buf_chain = buf) { 1154 kfree_skb_list(buf_chain);
1192 buf = buf_chain->next;
1193 kfree_skb(buf_chain);
1194 }
1195 return tipc_port_reject_sections(sender, hdr, msg_sect, 1155 return tipc_port_reject_sections(sender, hdr, msg_sect,
1196 len, TIPC_ERR_NO_NODE); 1156 len, TIPC_ERR_NO_NODE);
1197 } 1157 }
@@ -1281,9 +1241,6 @@ void tipc_link_push_queue(struct tipc_link *l_ptr)
1281{ 1241{
1282 u32 res; 1242 u32 res;
1283 1243
1284 if (tipc_bearer_blocked(l_ptr->b_ptr))
1285 return;
1286
1287 do { 1244 do {
1288 res = tipc_link_push_packet(l_ptr); 1245 res = tipc_link_push_packet(l_ptr);
1289 } while (!res); 1246 } while (!res);
@@ -1370,26 +1327,15 @@ void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf,
1370 1327
1371 msg = buf_msg(buf); 1328 msg = buf_msg(buf);
1372 1329
1373 if (tipc_bearer_blocked(l_ptr->b_ptr)) { 1330 /* Detect repeated retransmit failures */
1374 if (l_ptr->retransm_queue_size == 0) { 1331 if (l_ptr->last_retransmitted == msg_seqno(msg)) {
1375 l_ptr->retransm_queue_head = msg_seqno(msg); 1332 if (++l_ptr->stale_count > 100) {
1376 l_ptr->retransm_queue_size = retransmits; 1333 link_retransmit_failure(l_ptr, buf);
1377 } else { 1334 return;
1378 pr_err("Unexpected retransmit on link %s (qsize=%d)\n",
1379 l_ptr->name, l_ptr->retransm_queue_size);
1380 } 1335 }
1381 return;
1382 } else { 1336 } else {
1383 /* Detect repeated retransmit failures on unblocked bearer */ 1337 l_ptr->last_retransmitted = msg_seqno(msg);
1384 if (l_ptr->last_retransmitted == msg_seqno(msg)) { 1338 l_ptr->stale_count = 1;
1385 if (++l_ptr->stale_count > 100) {
1386 link_retransmit_failure(l_ptr, buf);
1387 return;
1388 }
1389 } else {
1390 l_ptr->last_retransmitted = msg_seqno(msg);
1391 l_ptr->stale_count = 1;
1392 }
1393 } 1339 }
1394 1340
1395 while (retransmits && (buf != l_ptr->next_out) && buf) { 1341 while (retransmits && (buf != l_ptr->next_out) && buf) {
@@ -1786,7 +1732,8 @@ void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ,
1786 l_ptr->proto_msg_queue = NULL; 1732 l_ptr->proto_msg_queue = NULL;
1787 } 1733 }
1788 1734
1789 if (link_blocked(l_ptr)) 1735 /* Don't send protocol message during link changeover */
1736 if (l_ptr->exp_msg_count)
1790 return; 1737 return;
1791 1738
1792 /* Abort non-RESET send if communication with node is prohibited */ 1739 /* Abort non-RESET send if communication with node is prohibited */
@@ -1861,12 +1808,6 @@ void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ,
1861 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg)); 1808 skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
1862 buf->priority = TC_PRIO_CONTROL; 1809 buf->priority = TC_PRIO_CONTROL;
1863 1810
1864 /* Defer message if bearer is already blocked */
1865 if (tipc_bearer_blocked(l_ptr->b_ptr)) {
1866 l_ptr->proto_msg_queue = buf;
1867 return;
1868 }
1869
1870 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); 1811 tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
1871 l_ptr->unacked_window = 0; 1812 l_ptr->unacked_window = 0;
1872 kfree_skb(buf); 1813 kfree_skb(buf);
@@ -1885,7 +1826,8 @@ static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf)
1885 u32 msg_tol; 1826 u32 msg_tol;
1886 struct tipc_msg *msg = buf_msg(buf); 1827 struct tipc_msg *msg = buf_msg(buf);
1887 1828
1888 if (link_blocked(l_ptr)) 1829 /* Discard protocol message during link changeover */
1830 if (l_ptr->exp_msg_count)
1889 goto exit; 1831 goto exit;
1890 1832
1891 /* record unnumbered packet arrival (force mismatch on next timeout) */ 1833 /* record unnumbered packet arrival (force mismatch on next timeout) */
@@ -2306,11 +2248,7 @@ static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf)
2306 fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE); 2248 fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE);
2307 if (fragm == NULL) { 2249 if (fragm == NULL) {
2308 kfree_skb(buf); 2250 kfree_skb(buf);
2309 while (buf_chain) { 2251 kfree_skb_list(buf_chain);
2310 buf = buf_chain;
2311 buf_chain = buf_chain->next;
2312 kfree_skb(buf);
2313 }
2314 return -ENOMEM; 2252 return -ENOMEM;
2315 } 2253 }
2316 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); 2254 msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE);
diff --git a/net/tipc/link.h b/net/tipc/link.h
index 8a6c1026644d..424b1dfe436b 100644
--- a/net/tipc/link.h
+++ b/net/tipc/link.h
@@ -112,7 +112,6 @@ struct tipc_stats {
112 * @continuity_interval: link continuity testing interval [in ms] 112 * @continuity_interval: link continuity testing interval [in ms]
113 * @abort_limit: # of unacknowledged continuity probes needed to reset link 113 * @abort_limit: # of unacknowledged continuity probes needed to reset link
114 * @state: current state of link FSM 114 * @state: current state of link FSM
115 * @blocked: indicates if link has been administratively blocked
116 * @fsm_msg_cnt: # of protocol messages link FSM has sent in current state 115 * @fsm_msg_cnt: # of protocol messages link FSM has sent in current state
117 * @proto_msg: template for control messages generated by link 116 * @proto_msg: template for control messages generated by link
118 * @pmsg: convenience pointer to "proto_msg" field 117 * @pmsg: convenience pointer to "proto_msg" field
@@ -162,7 +161,6 @@ struct tipc_link {
162 u32 continuity_interval; 161 u32 continuity_interval;
163 u32 abort_limit; 162 u32 abort_limit;
164 int state; 163 int state;
165 int blocked;
166 u32 fsm_msg_cnt; 164 u32 fsm_msg_cnt;
167 struct { 165 struct {
168 unchar hdr[INT_H_SIZE]; 166 unchar hdr[INT_H_SIZE];
@@ -312,11 +310,6 @@ static inline int link_reset_reset(struct tipc_link *l_ptr)
312 return l_ptr->state == RESET_RESET; 310 return l_ptr->state == RESET_RESET;
313} 311}
314 312
315static inline int link_blocked(struct tipc_link *l_ptr)
316{
317 return l_ptr->exp_msg_count || l_ptr->blocked;
318}
319
320static inline int link_congested(struct tipc_link *l_ptr) 313static inline int link_congested(struct tipc_link *l_ptr)
321{ 314{
322 return l_ptr->out_queue_size >= l_ptr->queue_limit[0]; 315 return l_ptr->out_queue_size >= l_ptr->queue_limit[0];
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 09dcd54b04e1..92a1533af4e0 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -148,8 +148,7 @@ static struct publication *publ_create(u32 type, u32 lower, u32 upper,
148 */ 148 */
149static struct sub_seq *tipc_subseq_alloc(u32 cnt) 149static struct sub_seq *tipc_subseq_alloc(u32 cnt)
150{ 150{
151 struct sub_seq *sseq = kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC); 151 return kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC);
152 return sseq;
153} 152}
154 153
155/** 154/**
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 25100c0a6fe8..bf1ac89b4806 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -291,11 +291,7 @@ static void node_lost_contact(struct tipc_node *n_ptr)
291 291
292 /* Flush broadcast link info associated with lost node */ 292 /* Flush broadcast link info associated with lost node */
293 if (n_ptr->bclink.recv_permitted) { 293 if (n_ptr->bclink.recv_permitted) {
294 while (n_ptr->bclink.deferred_head) { 294 kfree_skb_list(n_ptr->bclink.deferred_head);
295 struct sk_buff *buf = n_ptr->bclink.deferred_head;
296 n_ptr->bclink.deferred_head = buf->next;
297 kfree_skb(buf);
298 }
299 n_ptr->bclink.deferred_size = 0; 295 n_ptr->bclink.deferred_size = 0;
300 296
301 if (n_ptr->bclink.reasm_head) { 297 if (n_ptr->bclink.reasm_head) {
diff --git a/net/tipc/port.c b/net/tipc/port.c
index c081a7632302..5fd4c8cec08e 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -832,17 +832,14 @@ exit:
832 */ 832 */
833int __tipc_disconnect(struct tipc_port *tp_ptr) 833int __tipc_disconnect(struct tipc_port *tp_ptr)
834{ 834{
835 int res;
836
837 if (tp_ptr->connected) { 835 if (tp_ptr->connected) {
838 tp_ptr->connected = 0; 836 tp_ptr->connected = 0;
839 /* let timer expire on it's own to avoid deadlock! */ 837 /* let timer expire on it's own to avoid deadlock! */
840 tipc_nodesub_unsubscribe(&tp_ptr->subscription); 838 tipc_nodesub_unsubscribe(&tp_ptr->subscription);
841 res = 0; 839 return 0;
842 } else {
843 res = -ENOTCONN;
844 } 840 }
845 return res; 841
842 return -ENOTCONN;
846} 843}
847 844
848/* 845/*
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 3b61851bb927..83f466e57fea 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -239,7 +239,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
239int tipc_sock_create_local(int type, struct socket **res) 239int tipc_sock_create_local(int type, struct socket **res)
240{ 240{
241 int rc; 241 int rc;
242 struct sock *sk;
243 242
244 rc = sock_create_lite(AF_TIPC, type, 0, res); 243 rc = sock_create_lite(AF_TIPC, type, 0, res);
245 if (rc < 0) { 244 if (rc < 0) {
@@ -248,8 +247,6 @@ int tipc_sock_create_local(int type, struct socket **res)
248 } 247 }
249 tipc_sk_create(&init_net, *res, 0, 1); 248 tipc_sk_create(&init_net, *res, 0, 1);
250 249
251 sk = (*res)->sk;
252
253 return 0; 250 return 0;
254} 251}
255 252
@@ -754,16 +751,14 @@ static int send_stream(struct kiocb *iocb, struct socket *sock,
754 751
755 /* Handle special cases where there is no connection */ 752 /* Handle special cases where there is no connection */
756 if (unlikely(sock->state != SS_CONNECTED)) { 753 if (unlikely(sock->state != SS_CONNECTED)) {
757 if (sock->state == SS_UNCONNECTED) { 754 res = -ENOTCONN;
755
756 if (sock->state == SS_UNCONNECTED)
758 res = send_packet(NULL, sock, m, total_len); 757 res = send_packet(NULL, sock, m, total_len);
759 goto exit; 758 else if (sock->state == SS_DISCONNECTING)
760 } else if (sock->state == SS_DISCONNECTING) {
761 res = -EPIPE; 759 res = -EPIPE;
762 goto exit; 760
763 } else { 761 goto exit;
764 res = -ENOTCONN;
765 goto exit;
766 }
767 } 762 }
768 763
769 if (unlikely(m->msg_name)) { 764 if (unlikely(m->msg_name)) {
@@ -1311,14 +1306,12 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf)
1311static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf) 1306static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf)
1312{ 1307{
1313 struct tipc_msg *msg = buf_msg(buf); 1308 struct tipc_msg *msg = buf_msg(buf);
1314 unsigned int limit;
1315 1309
1316 if (msg_connected(msg)) 1310 if (msg_connected(msg))
1317 limit = sysctl_tipc_rmem[2]; 1311 return sysctl_tipc_rmem[2];
1318 else 1312
1319 limit = sk->sk_rcvbuf >> TIPC_CRITICAL_IMPORTANCE << 1313 return sk->sk_rcvbuf >> TIPC_CRITICAL_IMPORTANCE <<
1320 msg_importance(msg); 1314 msg_importance(msg);
1321 return limit;
1322} 1315}
1323 1316
1324/** 1317/**
@@ -1514,14 +1507,12 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
1514 sock->state != SS_CONNECTING, 1507 sock->state != SS_CONNECTING,
1515 timeout ? (long)msecs_to_jiffies(timeout) 1508 timeout ? (long)msecs_to_jiffies(timeout)
1516 : MAX_SCHEDULE_TIMEOUT); 1509 : MAX_SCHEDULE_TIMEOUT);
1517 lock_sock(sk);
1518 if (res <= 0) { 1510 if (res <= 0) {
1519 if (res == 0) 1511 if (res == 0)
1520 res = -ETIMEDOUT; 1512 res = -ETIMEDOUT;
1521 else 1513 return res;
1522 ; /* leave "res" unchanged */
1523 goto exit;
1524 } 1514 }
1515 lock_sock(sk);
1525 } 1516 }
1526 1517
1527 if (unlikely(sock->state == SS_DISCONNECTING)) 1518 if (unlikely(sock->state == SS_DISCONNECTING))
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 01625ccc3ae6..800ca61758ff 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -80,6 +80,8 @@
80 * with BSD names. 80 * with BSD names.
81 */ 81 */
82 82
83#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
84
83#include <linux/module.h> 85#include <linux/module.h>
84#include <linux/kernel.h> 86#include <linux/kernel.h>
85#include <linux/signal.h> 87#include <linux/signal.h>
@@ -366,7 +368,7 @@ static void unix_sock_destructor(struct sock *sk)
366 WARN_ON(!sk_unhashed(sk)); 368 WARN_ON(!sk_unhashed(sk));
367 WARN_ON(sk->sk_socket); 369 WARN_ON(sk->sk_socket);
368 if (!sock_flag(sk, SOCK_DEAD)) { 370 if (!sock_flag(sk, SOCK_DEAD)) {
369 printk(KERN_INFO "Attempt to release alive unix socket: %p\n", sk); 371 pr_info("Attempt to release alive unix socket: %p\n", sk);
370 return; 372 return;
371 } 373 }
372 374
@@ -378,7 +380,7 @@ static void unix_sock_destructor(struct sock *sk)
378 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 380 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
379 local_bh_enable(); 381 local_bh_enable();
380#ifdef UNIX_REFCNT_DEBUG 382#ifdef UNIX_REFCNT_DEBUG
381 printk(KERN_DEBUG "UNIX %p is destroyed, %ld are still alive.\n", sk, 383 pr_debug("UNIX %p is destroyed, %ld are still alive.\n", sk,
382 atomic_long_read(&unix_nr_socks)); 384 atomic_long_read(&unix_nr_socks));
383#endif 385#endif
384} 386}
@@ -530,13 +532,17 @@ static int unix_seqpacket_sendmsg(struct kiocb *, struct socket *,
530static int unix_seqpacket_recvmsg(struct kiocb *, struct socket *, 532static int unix_seqpacket_recvmsg(struct kiocb *, struct socket *,
531 struct msghdr *, size_t, int); 533 struct msghdr *, size_t, int);
532 534
533static void unix_set_peek_off(struct sock *sk, int val) 535static int unix_set_peek_off(struct sock *sk, int val)
534{ 536{
535 struct unix_sock *u = unix_sk(sk); 537 struct unix_sock *u = unix_sk(sk);
536 538
537 mutex_lock(&u->readlock); 539 if (mutex_lock_interruptible(&u->readlock))
540 return -EINTR;
541
538 sk->sk_peek_off = val; 542 sk->sk_peek_off = val;
539 mutex_unlock(&u->readlock); 543 mutex_unlock(&u->readlock);
544
545 return 0;
540} 546}
541 547
542 548
@@ -714,7 +720,9 @@ static int unix_autobind(struct socket *sock)
714 int err; 720 int err;
715 unsigned int retries = 0; 721 unsigned int retries = 0;
716 722
717 mutex_lock(&u->readlock); 723 err = mutex_lock_interruptible(&u->readlock);
724 if (err)
725 return err;
718 726
719 err = 0; 727 err = 0;
720 if (u->addr) 728 if (u->addr)
@@ -873,7 +881,9 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
873 goto out; 881 goto out;
874 addr_len = err; 882 addr_len = err;
875 883
876 mutex_lock(&u->readlock); 884 err = mutex_lock_interruptible(&u->readlock);
885 if (err)
886 goto out;
877 887
878 err = -EINVAL; 888 err = -EINVAL;
879 if (u->addr) 889 if (u->addr)
@@ -2433,8 +2443,7 @@ static int __init af_unix_init(void)
2433 2443
2434 rc = proto_register(&unix_proto, 1); 2444 rc = proto_register(&unix_proto, 1);
2435 if (rc != 0) { 2445 if (rc != 0) {
2436 printk(KERN_CRIT "%s: Cannot create unix_sock SLAB cache!\n", 2446 pr_crit("%s: Cannot create unix_sock SLAB cache!\n", __func__);
2437 __func__);
2438 goto out; 2447 goto out;
2439 } 2448 }
2440 2449
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 7622789d3750..c8a8297cd4b8 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -35,6 +35,8 @@
35 * response 35 * response
36 */ 36 */
37 37
38#define pr_fmt(fmt) "X25: " fmt
39
38#include <linux/module.h> 40#include <linux/module.h>
39#include <linux/capability.h> 41#include <linux/capability.h>
40#include <linux/errno.h> 42#include <linux/errno.h>
@@ -1809,7 +1811,7 @@ static int __init x25_init(void)
1809 if (rc != 0) 1811 if (rc != 0)
1810 goto out_sock; 1812 goto out_sock;
1811 1813
1812 printk(KERN_INFO "X.25 for Linux Version 0.2\n"); 1814 pr_info("Linux Version 0.2\n");
1813 1815
1814 x25_register_sysctl(); 1816 x25_register_sysctl();
1815 rc = x25_proc_init(); 1817 rc = x25_proc_init();
diff --git a/net/x25/x25_dev.c b/net/x25/x25_dev.c
index a8a236338e61..39231237e1c3 100644
--- a/net/x25/x25_dev.c
+++ b/net/x25/x25_dev.c
@@ -17,6 +17,8 @@
17 * 2000-09-04 Henner Eisen Prevent freeing a dangling skb. 17 * 2000-09-04 Henner Eisen Prevent freeing a dangling skb.
18 */ 18 */
19 19
20#define pr_fmt(fmt) "X25: " fmt
21
20#include <linux/kernel.h> 22#include <linux/kernel.h>
21#include <linux/netdevice.h> 23#include <linux/netdevice.h>
22#include <linux/skbuff.h> 24#include <linux/skbuff.h>
@@ -89,7 +91,7 @@ static int x25_receive_data(struct sk_buff *skb, struct x25_neigh *nb)
89*/ 91*/
90 92
91 if (frametype != X25_CLEAR_CONFIRMATION) 93 if (frametype != X25_CLEAR_CONFIRMATION)
92 printk(KERN_DEBUG "x25_receive_data(): unknown frame type %2x\n",frametype); 94 pr_debug("x25_receive_data(): unknown frame type %2x\n",frametype);
93 95
94 return 0; 96 return 0;
95} 97}
@@ -114,7 +116,7 @@ int x25_lapb_receive_frame(struct sk_buff *skb, struct net_device *dev,
114 */ 116 */
115 nb = x25_get_neigh(dev); 117 nb = x25_get_neigh(dev);
116 if (!nb) { 118 if (!nb) {
117 printk(KERN_DEBUG "X.25: unknown neighbour - %s\n", dev->name); 119 pr_debug("unknown neighbour - %s\n", dev->name);
118 goto drop; 120 goto drop;
119 } 121 }
120 122
@@ -154,7 +156,7 @@ void x25_establish_link(struct x25_neigh *nb)
154 switch (nb->dev->type) { 156 switch (nb->dev->type) {
155 case ARPHRD_X25: 157 case ARPHRD_X25:
156 if ((skb = alloc_skb(1, GFP_ATOMIC)) == NULL) { 158 if ((skb = alloc_skb(1, GFP_ATOMIC)) == NULL) {
157 printk(KERN_ERR "x25_dev: out of memory\n"); 159 pr_err("x25_dev: out of memory\n");
158 return; 160 return;
159 } 161 }
160 ptr = skb_put(skb, 1); 162 ptr = skb_put(skb, 1);
@@ -189,7 +191,7 @@ void x25_terminate_link(struct x25_neigh *nb)
189 191
190 skb = alloc_skb(1, GFP_ATOMIC); 192 skb = alloc_skb(1, GFP_ATOMIC);
191 if (!skb) { 193 if (!skb) {
192 printk(KERN_ERR "x25_dev: out of memory\n"); 194 pr_err("x25_dev: out of memory\n");
193 return; 195 return;
194 } 196 }
195 197
diff --git a/net/x25/x25_facilities.c b/net/x25/x25_facilities.c
index b8253250d723..7ecd04c21360 100644
--- a/net/x25/x25_facilities.c
+++ b/net/x25/x25_facilities.c
@@ -21,6 +21,8 @@
21 * on response. 21 * on response.
22 */ 22 */
23 23
24#define pr_fmt(fmt) "X25: " fmt
25
24#include <linux/kernel.h> 26#include <linux/kernel.h>
25#include <linux/string.h> 27#include <linux/string.h>
26#include <linux/skbuff.h> 28#include <linux/skbuff.h>
@@ -109,7 +111,7 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
109 case X25_MARKER: 111 case X25_MARKER:
110 break; 112 break;
111 default: 113 default:
112 printk(KERN_DEBUG "X.25: unknown facility " 114 pr_debug("unknown facility "
113 "%02X, value %02X\n", 115 "%02X, value %02X\n",
114 p[0], p[1]); 116 p[0], p[1]);
115 break; 117 break;
@@ -132,7 +134,7 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
132 *vc_fac_mask |= X25_MASK_WINDOW_SIZE; 134 *vc_fac_mask |= X25_MASK_WINDOW_SIZE;
133 break; 135 break;
134 default: 136 default:
135 printk(KERN_DEBUG "X.25: unknown facility " 137 pr_debug("unknown facility "
136 "%02X, values %02X, %02X\n", 138 "%02X, values %02X, %02X\n",
137 p[0], p[1], p[2]); 139 p[0], p[1], p[2]);
138 break; 140 break;
@@ -143,7 +145,7 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
143 case X25_FAC_CLASS_C: 145 case X25_FAC_CLASS_C:
144 if (len < 4) 146 if (len < 4)
145 return -1; 147 return -1;
146 printk(KERN_DEBUG "X.25: unknown facility %02X, " 148 pr_debug("unknown facility %02X, "
147 "values %02X, %02X, %02X\n", 149 "values %02X, %02X, %02X\n",
148 p[0], p[1], p[2], p[3]); 150 p[0], p[1], p[2], p[3]);
149 p += 4; 151 p += 4;
@@ -172,7 +174,7 @@ int x25_parse_facilities(struct sk_buff *skb, struct x25_facilities *facilities,
172 *vc_fac_mask |= X25_MASK_CALLED_AE; 174 *vc_fac_mask |= X25_MASK_CALLED_AE;
173 break; 175 break;
174 default: 176 default:
175 printk(KERN_DEBUG "X.25: unknown facility %02X," 177 pr_debug("unknown facility %02X,"
176 "length %d\n", p[0], p[1]); 178 "length %d\n", p[0], p[1]);
177 break; 179 break;
178 } 180 }
@@ -341,12 +343,12 @@ void x25_limit_facilities(struct x25_facilities *facilities,
341 343
342 if (!nb->extended) { 344 if (!nb->extended) {
343 if (facilities->winsize_in > 7) { 345 if (facilities->winsize_in > 7) {
344 printk(KERN_DEBUG "X.25: incoming winsize limited to 7\n"); 346 pr_debug("incoming winsize limited to 7\n");
345 facilities->winsize_in = 7; 347 facilities->winsize_in = 7;
346 } 348 }
347 if (facilities->winsize_out > 7) { 349 if (facilities->winsize_out > 7) {
348 facilities->winsize_out = 7; 350 facilities->winsize_out = 7;
349 printk( KERN_DEBUG "X.25: outgoing winsize limited to 7\n"); 351 pr_debug("outgoing winsize limited to 7\n");
350 } 352 }
351 } 353 }
352} 354}
diff --git a/net/x25/x25_forward.c b/net/x25/x25_forward.c
index c541b622ae16..cf561f1613e1 100644
--- a/net/x25/x25_forward.c
+++ b/net/x25/x25_forward.c
@@ -8,6 +8,9 @@
8 * History 8 * History
9 * 03-01-2007 Added forwarding for x.25 Andrew Hendry 9 * 03-01-2007 Added forwarding for x.25 Andrew Hendry
10 */ 10 */
11
12#define pr_fmt(fmt) "X25: " fmt
13
11#include <linux/if_arp.h> 14#include <linux/if_arp.h>
12#include <linux/init.h> 15#include <linux/init.h>
13#include <linux/slab.h> 16#include <linux/slab.h>
@@ -51,7 +54,7 @@ int x25_forward_call(struct x25_address *dest_addr, struct x25_neigh *from,
51 list_for_each(entry, &x25_forward_list) { 54 list_for_each(entry, &x25_forward_list) {
52 x25_frwd = list_entry(entry, struct x25_forward, node); 55 x25_frwd = list_entry(entry, struct x25_forward, node);
53 if (x25_frwd->lci == lci) { 56 if (x25_frwd->lci == lci) {
54 printk(KERN_WARNING "X.25: call request for lci which is already registered!, transmitting but not registering new pair\n"); 57 pr_warn("call request for lci which is already registered!, transmitting but not registering new pair\n");
55 same_lci = 1; 58 same_lci = 1;
56 } 59 }
57 } 60 }
diff --git a/net/x25/x25_in.c b/net/x25/x25_in.c
index a49cd4ec551a..d1b0dc79bb6f 100644
--- a/net/x25/x25_in.c
+++ b/net/x25/x25_in.c
@@ -23,6 +23,8 @@
23 * i-frames. 23 * i-frames.
24 */ 24 */
25 25
26#define pr_fmt(fmt) "X25: " fmt
27
26#include <linux/slab.h> 28#include <linux/slab.h>
27#include <linux/errno.h> 29#include <linux/errno.h>
28#include <linux/kernel.h> 30#include <linux/kernel.h>
@@ -317,7 +319,7 @@ static int x25_state3_machine(struct sock *sk, struct sk_buff *skb, int frametyp
317 break; 319 break;
318 320
319 default: 321 default:
320 printk(KERN_WARNING "x25: unknown %02X in state 3\n", frametype); 322 pr_warn("unknown %02X in state 3\n", frametype);
321 break; 323 break;
322 } 324 }
323 325
diff --git a/net/x25/x25_link.c b/net/x25/x25_link.c
index 4acacf3c6617..fd5ffb25873f 100644
--- a/net/x25/x25_link.c
+++ b/net/x25/x25_link.c
@@ -21,6 +21,8 @@
21 * 2000-09-04 Henner Eisen dev_hold() / dev_put() for x25_neigh. 21 * 2000-09-04 Henner Eisen dev_hold() / dev_put() for x25_neigh.
22 */ 22 */
23 23
24#define pr_fmt(fmt) "X25: " fmt
25
24#include <linux/kernel.h> 26#include <linux/kernel.h>
25#include <linux/jiffies.h> 27#include <linux/jiffies.h>
26#include <linux/timer.h> 28#include <linux/timer.h>
@@ -93,13 +95,13 @@ void x25_link_control(struct sk_buff *skb, struct x25_neigh *nb,
93 if (!pskb_may_pull(skb, X25_STD_MIN_LEN + 4)) 95 if (!pskb_may_pull(skb, X25_STD_MIN_LEN + 4))
94 break; 96 break;
95 97
96 printk(KERN_WARNING "x25: diagnostic #%d - %02X %02X %02X\n", 98 pr_warn("diagnostic #%d - %02X %02X %02X\n",
97 skb->data[3], skb->data[4], 99 skb->data[3], skb->data[4],
98 skb->data[5], skb->data[6]); 100 skb->data[5], skb->data[6]);
99 break; 101 break;
100 102
101 default: 103 default:
102 printk(KERN_WARNING "x25: received unknown %02X with LCI 000\n", 104 pr_warn("received unknown %02X with LCI 000\n",
103 frametype); 105 frametype);
104 break; 106 break;
105 } 107 }
diff --git a/net/x25/x25_subr.c b/net/x25/x25_subr.c
index 5170d52bfd96..6b5af65f491f 100644
--- a/net/x25/x25_subr.c
+++ b/net/x25/x25_subr.c
@@ -23,6 +23,8 @@
23 * restriction on response. 23 * restriction on response.
24 */ 24 */
25 25
26#define pr_fmt(fmt) "X25: " fmt
27
26#include <linux/slab.h> 28#include <linux/slab.h>
27#include <linux/kernel.h> 29#include <linux/kernel.h>
28#include <linux/string.h> 30#include <linux/string.h>
@@ -148,7 +150,7 @@ void x25_write_internal(struct sock *sk, int frametype)
148 case X25_RESET_CONFIRMATION: 150 case X25_RESET_CONFIRMATION:
149 break; 151 break;
150 default: 152 default:
151 printk(KERN_ERR "X.25: invalid frame type %02X\n", frametype); 153 pr_err("invalid frame type %02X\n", frametype);
152 return; 154 return;
153 } 155 }
154 156
@@ -338,7 +340,7 @@ int x25_decode(struct sock *sk, struct sk_buff *skb, int *ns, int *nr, int *q,
338 } 340 }
339 } 341 }
340 342
341 printk(KERN_DEBUG "X.25: invalid PLP frame %02X %02X %02X\n", 343 pr_debug("invalid PLP frame %02X %02X %02X\n",
342 frame[0], frame[1], frame[2]); 344 frame[0], frame[1], frame[2]);
343 345
344 return X25_ILLEGAL; 346 return X25_ILLEGAL;
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 9a91f7431c41..a7487f34e813 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -39,12 +39,7 @@
39#define XFRM_QUEUE_TMO_MAX ((unsigned)(60*HZ)) 39#define XFRM_QUEUE_TMO_MAX ((unsigned)(60*HZ))
40#define XFRM_MAX_QUEUE_LEN 100 40#define XFRM_MAX_QUEUE_LEN 100
41 41
42DEFINE_MUTEX(xfrm_cfg_mutex);
43EXPORT_SYMBOL(xfrm_cfg_mutex);
44
45static DEFINE_SPINLOCK(xfrm_policy_sk_bundle_lock);
46static struct dst_entry *xfrm_policy_sk_bundles; 42static struct dst_entry *xfrm_policy_sk_bundles;
47static DEFINE_RWLOCK(xfrm_policy_lock);
48 43
49static DEFINE_SPINLOCK(xfrm_policy_afinfo_lock); 44static DEFINE_SPINLOCK(xfrm_policy_afinfo_lock);
50static struct xfrm_policy_afinfo __rcu *xfrm_policy_afinfo[NPROTO] 45static struct xfrm_policy_afinfo __rcu *xfrm_policy_afinfo[NPROTO]
@@ -438,7 +433,7 @@ static void xfrm_bydst_resize(struct net *net, int dir)
438 if (!ndst) 433 if (!ndst)
439 return; 434 return;
440 435
441 write_lock_bh(&xfrm_policy_lock); 436 write_lock_bh(&net->xfrm.xfrm_policy_lock);
442 437
443 for (i = hmask; i >= 0; i--) 438 for (i = hmask; i >= 0; i--)
444 xfrm_dst_hash_transfer(odst + i, ndst, nhashmask); 439 xfrm_dst_hash_transfer(odst + i, ndst, nhashmask);
@@ -446,7 +441,7 @@ static void xfrm_bydst_resize(struct net *net, int dir)
446 net->xfrm.policy_bydst[dir].table = ndst; 441 net->xfrm.policy_bydst[dir].table = ndst;
447 net->xfrm.policy_bydst[dir].hmask = nhashmask; 442 net->xfrm.policy_bydst[dir].hmask = nhashmask;
448 443
449 write_unlock_bh(&xfrm_policy_lock); 444 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
450 445
451 xfrm_hash_free(odst, (hmask + 1) * sizeof(struct hlist_head)); 446 xfrm_hash_free(odst, (hmask + 1) * sizeof(struct hlist_head));
452} 447}
@@ -463,7 +458,7 @@ static void xfrm_byidx_resize(struct net *net, int total)
463 if (!nidx) 458 if (!nidx)
464 return; 459 return;
465 460
466 write_lock_bh(&xfrm_policy_lock); 461 write_lock_bh(&net->xfrm.xfrm_policy_lock);
467 462
468 for (i = hmask; i >= 0; i--) 463 for (i = hmask; i >= 0; i--)
469 xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask); 464 xfrm_idx_hash_transfer(oidx + i, nidx, nhashmask);
@@ -471,7 +466,7 @@ static void xfrm_byidx_resize(struct net *net, int total)
471 net->xfrm.policy_byidx = nidx; 466 net->xfrm.policy_byidx = nidx;
472 net->xfrm.policy_idx_hmask = nhashmask; 467 net->xfrm.policy_idx_hmask = nhashmask;
473 468
474 write_unlock_bh(&xfrm_policy_lock); 469 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
475 470
476 xfrm_hash_free(oidx, (hmask + 1) * sizeof(struct hlist_head)); 471 xfrm_hash_free(oidx, (hmask + 1) * sizeof(struct hlist_head));
477} 472}
@@ -504,7 +499,7 @@ static inline int xfrm_byidx_should_resize(struct net *net, int total)
504 499
505void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si) 500void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si)
506{ 501{
507 read_lock_bh(&xfrm_policy_lock); 502 read_lock_bh(&net->xfrm.xfrm_policy_lock);
508 si->incnt = net->xfrm.policy_count[XFRM_POLICY_IN]; 503 si->incnt = net->xfrm.policy_count[XFRM_POLICY_IN];
509 si->outcnt = net->xfrm.policy_count[XFRM_POLICY_OUT]; 504 si->outcnt = net->xfrm.policy_count[XFRM_POLICY_OUT];
510 si->fwdcnt = net->xfrm.policy_count[XFRM_POLICY_FWD]; 505 si->fwdcnt = net->xfrm.policy_count[XFRM_POLICY_FWD];
@@ -513,7 +508,7 @@ void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si)
513 si->fwdscnt = net->xfrm.policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX]; 508 si->fwdscnt = net->xfrm.policy_count[XFRM_POLICY_FWD+XFRM_POLICY_MAX];
514 si->spdhcnt = net->xfrm.policy_idx_hmask; 509 si->spdhcnt = net->xfrm.policy_idx_hmask;
515 si->spdhmcnt = xfrm_policy_hashmax; 510 si->spdhmcnt = xfrm_policy_hashmax;
516 read_unlock_bh(&xfrm_policy_lock); 511 read_unlock_bh(&net->xfrm.xfrm_policy_lock);
517} 512}
518EXPORT_SYMBOL(xfrm_spd_getinfo); 513EXPORT_SYMBOL(xfrm_spd_getinfo);
519 514
@@ -538,7 +533,7 @@ static void xfrm_hash_resize(struct work_struct *work)
538 533
539/* Generate new index... KAME seems to generate them ordered by cost 534/* Generate new index... KAME seems to generate them ordered by cost
540 * of an absolute inpredictability of ordering of rules. This will not pass. */ 535 * of an absolute inpredictability of ordering of rules. This will not pass. */
541static u32 xfrm_gen_index(struct net *net, int dir) 536static u32 xfrm_gen_index(struct net *net, int dir, u32 index)
542{ 537{
543 static u32 idx_generator; 538 static u32 idx_generator;
544 539
@@ -548,8 +543,14 @@ static u32 xfrm_gen_index(struct net *net, int dir)
548 u32 idx; 543 u32 idx;
549 int found; 544 int found;
550 545
551 idx = (idx_generator | dir); 546 if (!index) {
552 idx_generator += 8; 547 idx = (idx_generator | dir);
548 idx_generator += 8;
549 } else {
550 idx = index;
551 index = 0;
552 }
553
553 if (idx == 0) 554 if (idx == 0)
554 idx = 8; 555 idx = 8;
555 list = net->xfrm.policy_byidx + idx_hash(net, idx); 556 list = net->xfrm.policy_byidx + idx_hash(net, idx);
@@ -630,7 +631,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
630 struct hlist_head *chain; 631 struct hlist_head *chain;
631 struct hlist_node *newpos; 632 struct hlist_node *newpos;
632 633
633 write_lock_bh(&xfrm_policy_lock); 634 write_lock_bh(&net->xfrm.xfrm_policy_lock);
634 chain = policy_hash_bysel(net, &policy->selector, policy->family, dir); 635 chain = policy_hash_bysel(net, &policy->selector, policy->family, dir);
635 delpol = NULL; 636 delpol = NULL;
636 newpos = NULL; 637 newpos = NULL;
@@ -641,7 +642,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
641 xfrm_sec_ctx_match(pol->security, policy->security) && 642 xfrm_sec_ctx_match(pol->security, policy->security) &&
642 !WARN_ON(delpol)) { 643 !WARN_ON(delpol)) {
643 if (excl) { 644 if (excl) {
644 write_unlock_bh(&xfrm_policy_lock); 645 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
645 return -EEXIST; 646 return -EEXIST;
646 } 647 }
647 delpol = pol; 648 delpol = pol;
@@ -672,14 +673,14 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
672 xfrm_policy_requeue(delpol, policy); 673 xfrm_policy_requeue(delpol, policy);
673 __xfrm_policy_unlink(delpol, dir); 674 __xfrm_policy_unlink(delpol, dir);
674 } 675 }
675 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir); 676 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir, policy->index);
676 hlist_add_head(&policy->byidx, net->xfrm.policy_byidx+idx_hash(net, policy->index)); 677 hlist_add_head(&policy->byidx, net->xfrm.policy_byidx+idx_hash(net, policy->index));
677 policy->curlft.add_time = get_seconds(); 678 policy->curlft.add_time = get_seconds();
678 policy->curlft.use_time = 0; 679 policy->curlft.use_time = 0;
679 if (!mod_timer(&policy->timer, jiffies + HZ)) 680 if (!mod_timer(&policy->timer, jiffies + HZ))
680 xfrm_pol_hold(policy); 681 xfrm_pol_hold(policy);
681 list_add(&policy->walk.all, &net->xfrm.policy_all); 682 list_add(&policy->walk.all, &net->xfrm.policy_all);
682 write_unlock_bh(&xfrm_policy_lock); 683 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
683 684
684 if (delpol) 685 if (delpol)
685 xfrm_policy_kill(delpol); 686 xfrm_policy_kill(delpol);
@@ -699,7 +700,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type,
699 struct hlist_head *chain; 700 struct hlist_head *chain;
700 701
701 *err = 0; 702 *err = 0;
702 write_lock_bh(&xfrm_policy_lock); 703 write_lock_bh(&net->xfrm.xfrm_policy_lock);
703 chain = policy_hash_bysel(net, sel, sel->family, dir); 704 chain = policy_hash_bysel(net, sel, sel->family, dir);
704 ret = NULL; 705 ret = NULL;
705 hlist_for_each_entry(pol, chain, bydst) { 706 hlist_for_each_entry(pol, chain, bydst) {
@@ -712,7 +713,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type,
712 *err = security_xfrm_policy_delete( 713 *err = security_xfrm_policy_delete(
713 pol->security); 714 pol->security);
714 if (*err) { 715 if (*err) {
715 write_unlock_bh(&xfrm_policy_lock); 716 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
716 return pol; 717 return pol;
717 } 718 }
718 __xfrm_policy_unlink(pol, dir); 719 __xfrm_policy_unlink(pol, dir);
@@ -721,7 +722,7 @@ struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark, u8 type,
721 break; 722 break;
722 } 723 }
723 } 724 }
724 write_unlock_bh(&xfrm_policy_lock); 725 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
725 726
726 if (ret && delete) 727 if (ret && delete)
727 xfrm_policy_kill(ret); 728 xfrm_policy_kill(ret);
@@ -740,7 +741,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type,
740 return NULL; 741 return NULL;
741 742
742 *err = 0; 743 *err = 0;
743 write_lock_bh(&xfrm_policy_lock); 744 write_lock_bh(&net->xfrm.xfrm_policy_lock);
744 chain = net->xfrm.policy_byidx + idx_hash(net, id); 745 chain = net->xfrm.policy_byidx + idx_hash(net, id);
745 ret = NULL; 746 ret = NULL;
746 hlist_for_each_entry(pol, chain, byidx) { 747 hlist_for_each_entry(pol, chain, byidx) {
@@ -751,7 +752,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type,
751 *err = security_xfrm_policy_delete( 752 *err = security_xfrm_policy_delete(
752 pol->security); 753 pol->security);
753 if (*err) { 754 if (*err) {
754 write_unlock_bh(&xfrm_policy_lock); 755 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
755 return pol; 756 return pol;
756 } 757 }
757 __xfrm_policy_unlink(pol, dir); 758 __xfrm_policy_unlink(pol, dir);
@@ -760,7 +761,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8 type,
760 break; 761 break;
761 } 762 }
762 } 763 }
763 write_unlock_bh(&xfrm_policy_lock); 764 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
764 765
765 if (ret && delete) 766 if (ret && delete)
766 xfrm_policy_kill(ret); 767 xfrm_policy_kill(ret);
@@ -823,7 +824,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
823{ 824{
824 int dir, err = 0, cnt = 0; 825 int dir, err = 0, cnt = 0;
825 826
826 write_lock_bh(&xfrm_policy_lock); 827 write_lock_bh(&net->xfrm.xfrm_policy_lock);
827 828
828 err = xfrm_policy_flush_secctx_check(net, type, audit_info); 829 err = xfrm_policy_flush_secctx_check(net, type, audit_info);
829 if (err) 830 if (err)
@@ -839,7 +840,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
839 if (pol->type != type) 840 if (pol->type != type)
840 continue; 841 continue;
841 __xfrm_policy_unlink(pol, dir); 842 __xfrm_policy_unlink(pol, dir);
842 write_unlock_bh(&xfrm_policy_lock); 843 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
843 cnt++; 844 cnt++;
844 845
845 xfrm_audit_policy_delete(pol, 1, audit_info->loginuid, 846 xfrm_audit_policy_delete(pol, 1, audit_info->loginuid,
@@ -848,7 +849,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
848 849
849 xfrm_policy_kill(pol); 850 xfrm_policy_kill(pol);
850 851
851 write_lock_bh(&xfrm_policy_lock); 852 write_lock_bh(&net->xfrm.xfrm_policy_lock);
852 goto again1; 853 goto again1;
853 } 854 }
854 855
@@ -860,7 +861,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
860 if (pol->type != type) 861 if (pol->type != type)
861 continue; 862 continue;
862 __xfrm_policy_unlink(pol, dir); 863 __xfrm_policy_unlink(pol, dir);
863 write_unlock_bh(&xfrm_policy_lock); 864 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
864 cnt++; 865 cnt++;
865 866
866 xfrm_audit_policy_delete(pol, 1, 867 xfrm_audit_policy_delete(pol, 1,
@@ -869,7 +870,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
869 audit_info->secid); 870 audit_info->secid);
870 xfrm_policy_kill(pol); 871 xfrm_policy_kill(pol);
871 872
872 write_lock_bh(&xfrm_policy_lock); 873 write_lock_bh(&net->xfrm.xfrm_policy_lock);
873 goto again2; 874 goto again2;
874 } 875 }
875 } 876 }
@@ -878,7 +879,7 @@ int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info)
878 if (!cnt) 879 if (!cnt)
879 err = -ESRCH; 880 err = -ESRCH;
880out: 881out:
881 write_unlock_bh(&xfrm_policy_lock); 882 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
882 return err; 883 return err;
883} 884}
884EXPORT_SYMBOL(xfrm_policy_flush); 885EXPORT_SYMBOL(xfrm_policy_flush);
@@ -898,7 +899,7 @@ int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
898 if (list_empty(&walk->walk.all) && walk->seq != 0) 899 if (list_empty(&walk->walk.all) && walk->seq != 0)
899 return 0; 900 return 0;
900 901
901 write_lock_bh(&xfrm_policy_lock); 902 write_lock_bh(&net->xfrm.xfrm_policy_lock);
902 if (list_empty(&walk->walk.all)) 903 if (list_empty(&walk->walk.all))
903 x = list_first_entry(&net->xfrm.policy_all, struct xfrm_policy_walk_entry, all); 904 x = list_first_entry(&net->xfrm.policy_all, struct xfrm_policy_walk_entry, all);
904 else 905 else
@@ -924,7 +925,7 @@ int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
924 } 925 }
925 list_del_init(&walk->walk.all); 926 list_del_init(&walk->walk.all);
926out: 927out:
927 write_unlock_bh(&xfrm_policy_lock); 928 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
928 return error; 929 return error;
929} 930}
930EXPORT_SYMBOL(xfrm_policy_walk); 931EXPORT_SYMBOL(xfrm_policy_walk);
@@ -938,14 +939,14 @@ void xfrm_policy_walk_init(struct xfrm_policy_walk *walk, u8 type)
938} 939}
939EXPORT_SYMBOL(xfrm_policy_walk_init); 940EXPORT_SYMBOL(xfrm_policy_walk_init);
940 941
941void xfrm_policy_walk_done(struct xfrm_policy_walk *walk) 942void xfrm_policy_walk_done(struct xfrm_policy_walk *walk, struct net *net)
942{ 943{
943 if (list_empty(&walk->walk.all)) 944 if (list_empty(&walk->walk.all))
944 return; 945 return;
945 946
946 write_lock_bh(&xfrm_policy_lock); 947 write_lock_bh(&net->xfrm.xfrm_policy_lock); /*FIXME where is net? */
947 list_del(&walk->walk.all); 948 list_del(&walk->walk.all);
948 write_unlock_bh(&xfrm_policy_lock); 949 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
949} 950}
950EXPORT_SYMBOL(xfrm_policy_walk_done); 951EXPORT_SYMBOL(xfrm_policy_walk_done);
951 952
@@ -990,7 +991,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
990 if (unlikely(!daddr || !saddr)) 991 if (unlikely(!daddr || !saddr))
991 return NULL; 992 return NULL;
992 993
993 read_lock_bh(&xfrm_policy_lock); 994 read_lock_bh(&net->xfrm.xfrm_policy_lock);
994 chain = policy_hash_direct(net, daddr, saddr, family, dir); 995 chain = policy_hash_direct(net, daddr, saddr, family, dir);
995 ret = NULL; 996 ret = NULL;
996 hlist_for_each_entry(pol, chain, bydst) { 997 hlist_for_each_entry(pol, chain, bydst) {
@@ -1026,7 +1027,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
1026 if (ret) 1027 if (ret)
1027 xfrm_pol_hold(ret); 1028 xfrm_pol_hold(ret);
1028fail: 1029fail:
1029 read_unlock_bh(&xfrm_policy_lock); 1030 read_unlock_bh(&net->xfrm.xfrm_policy_lock);
1030 1031
1031 return ret; 1032 return ret;
1032} 1033}
@@ -1103,8 +1104,9 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir,
1103 const struct flowi *fl) 1104 const struct flowi *fl)
1104{ 1105{
1105 struct xfrm_policy *pol; 1106 struct xfrm_policy *pol;
1107 struct net *net = sock_net(sk);
1106 1108
1107 read_lock_bh(&xfrm_policy_lock); 1109 read_lock_bh(&net->xfrm.xfrm_policy_lock);
1108 if ((pol = sk->sk_policy[dir]) != NULL) { 1110 if ((pol = sk->sk_policy[dir]) != NULL) {
1109 bool match = xfrm_selector_match(&pol->selector, fl, 1111 bool match = xfrm_selector_match(&pol->selector, fl,
1110 sk->sk_family); 1112 sk->sk_family);
@@ -1128,7 +1130,7 @@ static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir,
1128 pol = NULL; 1130 pol = NULL;
1129 } 1131 }
1130out: 1132out:
1131 read_unlock_bh(&xfrm_policy_lock); 1133 read_unlock_bh(&net->xfrm.xfrm_policy_lock);
1132 return pol; 1134 return pol;
1133} 1135}
1134 1136
@@ -1166,9 +1168,11 @@ static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol,
1166 1168
1167int xfrm_policy_delete(struct xfrm_policy *pol, int dir) 1169int xfrm_policy_delete(struct xfrm_policy *pol, int dir)
1168{ 1170{
1169 write_lock_bh(&xfrm_policy_lock); 1171 struct net *net = xp_net(pol);
1172
1173 write_lock_bh(&net->xfrm.xfrm_policy_lock);
1170 pol = __xfrm_policy_unlink(pol, dir); 1174 pol = __xfrm_policy_unlink(pol, dir);
1171 write_unlock_bh(&xfrm_policy_lock); 1175 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
1172 if (pol) { 1176 if (pol) {
1173 xfrm_policy_kill(pol); 1177 xfrm_policy_kill(pol);
1174 return 0; 1178 return 0;
@@ -1187,12 +1191,12 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
1187 return -EINVAL; 1191 return -EINVAL;
1188#endif 1192#endif
1189 1193
1190 write_lock_bh(&xfrm_policy_lock); 1194 write_lock_bh(&net->xfrm.xfrm_policy_lock);
1191 old_pol = sk->sk_policy[dir]; 1195 old_pol = sk->sk_policy[dir];
1192 sk->sk_policy[dir] = pol; 1196 sk->sk_policy[dir] = pol;
1193 if (pol) { 1197 if (pol) {
1194 pol->curlft.add_time = get_seconds(); 1198 pol->curlft.add_time = get_seconds();
1195 pol->index = xfrm_gen_index(net, XFRM_POLICY_MAX+dir); 1199 pol->index = xfrm_gen_index(net, XFRM_POLICY_MAX+dir, 0);
1196 __xfrm_policy_link(pol, XFRM_POLICY_MAX+dir); 1200 __xfrm_policy_link(pol, XFRM_POLICY_MAX+dir);
1197 } 1201 }
1198 if (old_pol) { 1202 if (old_pol) {
@@ -1204,7 +1208,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
1204 */ 1208 */
1205 __xfrm_policy_unlink(old_pol, XFRM_POLICY_MAX+dir); 1209 __xfrm_policy_unlink(old_pol, XFRM_POLICY_MAX+dir);
1206 } 1210 }
1207 write_unlock_bh(&xfrm_policy_lock); 1211 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
1208 1212
1209 if (old_pol) { 1213 if (old_pol) {
1210 xfrm_policy_kill(old_pol); 1214 xfrm_policy_kill(old_pol);
@@ -1215,6 +1219,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
1215static struct xfrm_policy *clone_policy(const struct xfrm_policy *old, int dir) 1219static struct xfrm_policy *clone_policy(const struct xfrm_policy *old, int dir)
1216{ 1220{
1217 struct xfrm_policy *newp = xfrm_policy_alloc(xp_net(old), GFP_ATOMIC); 1221 struct xfrm_policy *newp = xfrm_policy_alloc(xp_net(old), GFP_ATOMIC);
1222 struct net *net = xp_net(old);
1218 1223
1219 if (newp) { 1224 if (newp) {
1220 newp->selector = old->selector; 1225 newp->selector = old->selector;
@@ -1233,9 +1238,9 @@ static struct xfrm_policy *clone_policy(const struct xfrm_policy *old, int dir)
1233 newp->type = old->type; 1238 newp->type = old->type;
1234 memcpy(newp->xfrm_vec, old->xfrm_vec, 1239 memcpy(newp->xfrm_vec, old->xfrm_vec,
1235 newp->xfrm_nr*sizeof(struct xfrm_tmpl)); 1240 newp->xfrm_nr*sizeof(struct xfrm_tmpl));
1236 write_lock_bh(&xfrm_policy_lock); 1241 write_lock_bh(&net->xfrm.xfrm_policy_lock);
1237 __xfrm_policy_link(newp, XFRM_POLICY_MAX+dir); 1242 __xfrm_policy_link(newp, XFRM_POLICY_MAX+dir);
1238 write_unlock_bh(&xfrm_policy_lock); 1243 write_unlock_bh(&net->xfrm.xfrm_policy_lock);
1239 xfrm_pol_put(newp); 1244 xfrm_pol_put(newp);
1240 } 1245 }
1241 return newp; 1246 return newp;
@@ -1896,8 +1901,7 @@ static struct xfrm_dst *xfrm_create_dummy_bundle(struct net *net,
1896 if (IS_ERR(xdst)) 1901 if (IS_ERR(xdst))
1897 return xdst; 1902 return xdst;
1898 1903
1899 if (net->xfrm.sysctl_larval_drop || num_xfrms <= 0 || 1904 if (net->xfrm.sysctl_larval_drop || num_xfrms <= 0)
1900 (fl->flowi_flags & FLOWI_FLAG_CAN_SLEEP))
1901 return xdst; 1905 return xdst;
1902 1906
1903 dst1 = &xdst->u.dst; 1907 dst1 = &xdst->u.dst;
@@ -2072,7 +2076,6 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
2072 u8 dir = policy_to_flow_dir(XFRM_POLICY_OUT); 2076 u8 dir = policy_to_flow_dir(XFRM_POLICY_OUT);
2073 int i, err, num_pols, num_xfrms = 0, drop_pols = 0; 2077 int i, err, num_pols, num_xfrms = 0, drop_pols = 0;
2074 2078
2075restart:
2076 dst = NULL; 2079 dst = NULL;
2077 xdst = NULL; 2080 xdst = NULL;
2078 route = NULL; 2081 route = NULL;
@@ -2106,10 +2109,10 @@ restart:
2106 2109
2107 dst_hold(&xdst->u.dst); 2110 dst_hold(&xdst->u.dst);
2108 2111
2109 spin_lock_bh(&xfrm_policy_sk_bundle_lock); 2112 spin_lock_bh(&net->xfrm.xfrm_policy_sk_bundle_lock);
2110 xdst->u.dst.next = xfrm_policy_sk_bundles; 2113 xdst->u.dst.next = xfrm_policy_sk_bundles;
2111 xfrm_policy_sk_bundles = &xdst->u.dst; 2114 xfrm_policy_sk_bundles = &xdst->u.dst;
2112 spin_unlock_bh(&xfrm_policy_sk_bundle_lock); 2115 spin_unlock_bh(&net->xfrm.xfrm_policy_sk_bundle_lock);
2113 2116
2114 route = xdst->route; 2117 route = xdst->route;
2115 } 2118 }
@@ -2152,23 +2155,8 @@ restart:
2152 2155
2153 return make_blackhole(net, family, dst_orig); 2156 return make_blackhole(net, family, dst_orig);
2154 } 2157 }
2155 if (fl->flowi_flags & FLOWI_FLAG_CAN_SLEEP) {
2156 DECLARE_WAITQUEUE(wait, current);
2157
2158 add_wait_queue(&net->xfrm.km_waitq, &wait);
2159 set_current_state(TASK_INTERRUPTIBLE);
2160 schedule();
2161 set_current_state(TASK_RUNNING);
2162 remove_wait_queue(&net->xfrm.km_waitq, &wait);
2163 2158
2164 if (!signal_pending(current)) { 2159 err = -EAGAIN;
2165 dst_release(dst);
2166 goto restart;
2167 }
2168
2169 err = -ERESTART;
2170 } else
2171 err = -EAGAIN;
2172 2160
2173 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES); 2161 XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES);
2174 goto error; 2162 goto error;
@@ -2434,7 +2422,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
2434 } 2422 }
2435 xfrm_nr = ti; 2423 xfrm_nr = ti;
2436 if (npols > 1) { 2424 if (npols > 1) {
2437 xfrm_tmpl_sort(stp, tpp, xfrm_nr, family); 2425 xfrm_tmpl_sort(stp, tpp, xfrm_nr, family, net);
2438 tpp = stp; 2426 tpp = stp;
2439 } 2427 }
2440 2428
@@ -2563,10 +2551,10 @@ static void __xfrm_garbage_collect(struct net *net)
2563{ 2551{
2564 struct dst_entry *head, *next; 2552 struct dst_entry *head, *next;
2565 2553
2566 spin_lock_bh(&xfrm_policy_sk_bundle_lock); 2554 spin_lock_bh(&net->xfrm.xfrm_policy_sk_bundle_lock);
2567 head = xfrm_policy_sk_bundles; 2555 head = xfrm_policy_sk_bundles;
2568 xfrm_policy_sk_bundles = NULL; 2556 xfrm_policy_sk_bundles = NULL;
2569 spin_unlock_bh(&xfrm_policy_sk_bundle_lock); 2557 spin_unlock_bh(&net->xfrm.xfrm_policy_sk_bundle_lock);
2570 2558
2571 while (head) { 2559 while (head) {
2572 next = head->next; 2560 next = head->next;
@@ -2950,6 +2938,13 @@ static int __net_init xfrm_net_init(struct net *net)
2950 rv = xfrm_sysctl_init(net); 2938 rv = xfrm_sysctl_init(net);
2951 if (rv < 0) 2939 if (rv < 0)
2952 goto out_sysctl; 2940 goto out_sysctl;
2941
2942 /* Initialize the per-net locks here */
2943 spin_lock_init(&net->xfrm.xfrm_state_lock);
2944 rwlock_init(&net->xfrm.xfrm_policy_lock);
2945 spin_lock_init(&net->xfrm.xfrm_policy_sk_bundle_lock);
2946 mutex_init(&net->xfrm.xfrm_cfg_mutex);
2947
2953 return 0; 2948 return 0;
2954 2949
2955out_sysctl: 2950out_sysctl:
@@ -3070,14 +3065,14 @@ static bool xfrm_migrate_selector_match(const struct xfrm_selector *sel_cmp,
3070} 3065}
3071 3066
3072static struct xfrm_policy * xfrm_migrate_policy_find(const struct xfrm_selector *sel, 3067static struct xfrm_policy * xfrm_migrate_policy_find(const struct xfrm_selector *sel,
3073 u8 dir, u8 type) 3068 u8 dir, u8 type, struct net *net)
3074{ 3069{
3075 struct xfrm_policy *pol, *ret = NULL; 3070 struct xfrm_policy *pol, *ret = NULL;
3076 struct hlist_head *chain; 3071 struct hlist_head *chain;
3077 u32 priority = ~0U; 3072 u32 priority = ~0U;
3078 3073
3079 read_lock_bh(&xfrm_policy_lock); 3074 read_lock_bh(&net->xfrm.xfrm_policy_lock); /*FIXME*/
3080 chain = policy_hash_direct(&init_net, &sel->daddr, &sel->saddr, sel->family, dir); 3075 chain = policy_hash_direct(net, &sel->daddr, &sel->saddr, sel->family, dir);
3081 hlist_for_each_entry(pol, chain, bydst) { 3076 hlist_for_each_entry(pol, chain, bydst) {
3082 if (xfrm_migrate_selector_match(sel, &pol->selector) && 3077 if (xfrm_migrate_selector_match(sel, &pol->selector) &&
3083 pol->type == type) { 3078 pol->type == type) {
@@ -3086,7 +3081,7 @@ static struct xfrm_policy * xfrm_migrate_policy_find(const struct xfrm_selector
3086 break; 3081 break;
3087 } 3082 }
3088 } 3083 }
3089 chain = &init_net.xfrm.policy_inexact[dir]; 3084 chain = &net->xfrm.policy_inexact[dir];
3090 hlist_for_each_entry(pol, chain, bydst) { 3085 hlist_for_each_entry(pol, chain, bydst) {
3091 if (xfrm_migrate_selector_match(sel, &pol->selector) && 3086 if (xfrm_migrate_selector_match(sel, &pol->selector) &&
3092 pol->type == type && 3087 pol->type == type &&
@@ -3099,7 +3094,7 @@ static struct xfrm_policy * xfrm_migrate_policy_find(const struct xfrm_selector
3099 if (ret) 3094 if (ret)
3100 xfrm_pol_hold(ret); 3095 xfrm_pol_hold(ret);
3101 3096
3102 read_unlock_bh(&xfrm_policy_lock); 3097 read_unlock_bh(&net->xfrm.xfrm_policy_lock);
3103 3098
3104 return ret; 3099 return ret;
3105} 3100}
@@ -3210,7 +3205,7 @@ static int xfrm_migrate_check(const struct xfrm_migrate *m, int num_migrate)
3210 3205
3211int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type, 3206int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
3212 struct xfrm_migrate *m, int num_migrate, 3207 struct xfrm_migrate *m, int num_migrate,
3213 struct xfrm_kmaddress *k) 3208 struct xfrm_kmaddress *k, struct net *net)
3214{ 3209{
3215 int i, err, nx_cur = 0, nx_new = 0; 3210 int i, err, nx_cur = 0, nx_new = 0;
3216 struct xfrm_policy *pol = NULL; 3211 struct xfrm_policy *pol = NULL;
@@ -3223,14 +3218,14 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
3223 goto out; 3218 goto out;
3224 3219
3225 /* Stage 1 - find policy */ 3220 /* Stage 1 - find policy */
3226 if ((pol = xfrm_migrate_policy_find(sel, dir, type)) == NULL) { 3221 if ((pol = xfrm_migrate_policy_find(sel, dir, type, net)) == NULL) {
3227 err = -ENOENT; 3222 err = -ENOENT;
3228 goto out; 3223 goto out;
3229 } 3224 }
3230 3225
3231 /* Stage 2 - find and update state(s) */ 3226 /* Stage 2 - find and update state(s) */
3232 for (i = 0, mp = m; i < num_migrate; i++, mp++) { 3227 for (i = 0, mp = m; i < num_migrate; i++, mp++) {
3233 if ((x = xfrm_migrate_state_find(mp))) { 3228 if ((x = xfrm_migrate_state_find(mp, net))) {
3234 x_cur[nx_cur] = x; 3229 x_cur[nx_cur] = x;
3235 nx_cur++; 3230 nx_cur++;
3236 if ((xc = xfrm_state_migrate(x, mp))) { 3231 if ((xc = xfrm_state_migrate(x, mp))) {
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 68c2f357a183..a62c25ea3631 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -35,8 +35,6 @@
35 destination/tunnel endpoint. (output) 35 destination/tunnel endpoint. (output)
36 */ 36 */
37 37
38static DEFINE_SPINLOCK(xfrm_state_lock);
39
40static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024; 38static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024;
41 39
42static inline unsigned int xfrm_dst_hash(struct net *net, 40static inline unsigned int xfrm_dst_hash(struct net *net,
@@ -127,7 +125,7 @@ static void xfrm_hash_resize(struct work_struct *work)
127 goto out_unlock; 125 goto out_unlock;
128 } 126 }
129 127
130 spin_lock_bh(&xfrm_state_lock); 128 spin_lock_bh(&net->xfrm.xfrm_state_lock);
131 129
132 nhashmask = (nsize / sizeof(struct hlist_head)) - 1U; 130 nhashmask = (nsize / sizeof(struct hlist_head)) - 1U;
133 for (i = net->xfrm.state_hmask; i >= 0; i--) 131 for (i = net->xfrm.state_hmask; i >= 0; i--)
@@ -144,7 +142,7 @@ static void xfrm_hash_resize(struct work_struct *work)
144 net->xfrm.state_byspi = nspi; 142 net->xfrm.state_byspi = nspi;
145 net->xfrm.state_hmask = nhashmask; 143 net->xfrm.state_hmask = nhashmask;
146 144
147 spin_unlock_bh(&xfrm_state_lock); 145 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
148 146
149 osize = (ohashmask + 1) * sizeof(struct hlist_head); 147 osize = (ohashmask + 1) * sizeof(struct hlist_head);
150 xfrm_hash_free(odst, osize); 148 xfrm_hash_free(odst, osize);
@@ -374,8 +372,6 @@ static void xfrm_state_gc_task(struct work_struct *work)
374 372
375 hlist_for_each_entry_safe(x, tmp, &gc_list, gclist) 373 hlist_for_each_entry_safe(x, tmp, &gc_list, gclist)
376 xfrm_state_gc_destroy(x); 374 xfrm_state_gc_destroy(x);
377
378 wake_up(&net->xfrm.km_waitq);
379} 375}
380 376
381static inline unsigned long make_jiffies(long secs) 377static inline unsigned long make_jiffies(long secs)
@@ -390,7 +386,6 @@ static enum hrtimer_restart xfrm_timer_handler(struct hrtimer * me)
390{ 386{
391 struct tasklet_hrtimer *thr = container_of(me, struct tasklet_hrtimer, timer); 387 struct tasklet_hrtimer *thr = container_of(me, struct tasklet_hrtimer, timer);
392 struct xfrm_state *x = container_of(thr, struct xfrm_state, mtimer); 388 struct xfrm_state *x = container_of(thr, struct xfrm_state, mtimer);
393 struct net *net = xs_net(x);
394 unsigned long now = get_seconds(); 389 unsigned long now = get_seconds();
395 long next = LONG_MAX; 390 long next = LONG_MAX;
396 int warn = 0; 391 int warn = 0;
@@ -460,12 +455,8 @@ resched:
460 goto out; 455 goto out;
461 456
462expired: 457expired:
463 if (x->km.state == XFRM_STATE_ACQ && x->id.spi == 0) { 458 if (x->km.state == XFRM_STATE_ACQ && x->id.spi == 0)
464 x->km.state = XFRM_STATE_EXPIRED; 459 x->km.state = XFRM_STATE_EXPIRED;
465 wake_up(&net->xfrm.km_waitq);
466 next = 2;
467 goto resched;
468 }
469 460
470 err = __xfrm_state_delete(x); 461 err = __xfrm_state_delete(x);
471 if (!err) 462 if (!err)
@@ -535,14 +526,14 @@ int __xfrm_state_delete(struct xfrm_state *x)
535 526
536 if (x->km.state != XFRM_STATE_DEAD) { 527 if (x->km.state != XFRM_STATE_DEAD) {
537 x->km.state = XFRM_STATE_DEAD; 528 x->km.state = XFRM_STATE_DEAD;
538 spin_lock(&xfrm_state_lock); 529 spin_lock(&net->xfrm.xfrm_state_lock);
539 list_del(&x->km.all); 530 list_del(&x->km.all);
540 hlist_del(&x->bydst); 531 hlist_del(&x->bydst);
541 hlist_del(&x->bysrc); 532 hlist_del(&x->bysrc);
542 if (x->id.spi) 533 if (x->id.spi)
543 hlist_del(&x->byspi); 534 hlist_del(&x->byspi);
544 net->xfrm.state_num--; 535 net->xfrm.state_num--;
545 spin_unlock(&xfrm_state_lock); 536 spin_unlock(&net->xfrm.xfrm_state_lock);
546 537
547 /* All xfrm_state objects are created by xfrm_state_alloc. 538 /* All xfrm_state objects are created by xfrm_state_alloc.
548 * The xfrm_state_alloc call gives a reference, and that 539 * The xfrm_state_alloc call gives a reference, and that
@@ -603,7 +594,7 @@ int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info)
603{ 594{
604 int i, err = 0, cnt = 0; 595 int i, err = 0, cnt = 0;
605 596
606 spin_lock_bh(&xfrm_state_lock); 597 spin_lock_bh(&net->xfrm.xfrm_state_lock);
607 err = xfrm_state_flush_secctx_check(net, proto, audit_info); 598 err = xfrm_state_flush_secctx_check(net, proto, audit_info);
608 if (err) 599 if (err)
609 goto out; 600 goto out;
@@ -616,7 +607,7 @@ restart:
616 if (!xfrm_state_kern(x) && 607 if (!xfrm_state_kern(x) &&
617 xfrm_id_proto_match(x->id.proto, proto)) { 608 xfrm_id_proto_match(x->id.proto, proto)) {
618 xfrm_state_hold(x); 609 xfrm_state_hold(x);
619 spin_unlock_bh(&xfrm_state_lock); 610 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
620 611
621 err = xfrm_state_delete(x); 612 err = xfrm_state_delete(x);
622 xfrm_audit_state_delete(x, err ? 0 : 1, 613 xfrm_audit_state_delete(x, err ? 0 : 1,
@@ -627,7 +618,7 @@ restart:
627 if (!err) 618 if (!err)
628 cnt++; 619 cnt++;
629 620
630 spin_lock_bh(&xfrm_state_lock); 621 spin_lock_bh(&net->xfrm.xfrm_state_lock);
631 goto restart; 622 goto restart;
632 } 623 }
633 } 624 }
@@ -636,19 +627,18 @@ restart:
636 err = 0; 627 err = 0;
637 628
638out: 629out:
639 spin_unlock_bh(&xfrm_state_lock); 630 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
640 wake_up(&net->xfrm.km_waitq);
641 return err; 631 return err;
642} 632}
643EXPORT_SYMBOL(xfrm_state_flush); 633EXPORT_SYMBOL(xfrm_state_flush);
644 634
645void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si) 635void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si)
646{ 636{
647 spin_lock_bh(&xfrm_state_lock); 637 spin_lock_bh(&net->xfrm.xfrm_state_lock);
648 si->sadcnt = net->xfrm.state_num; 638 si->sadcnt = net->xfrm.state_num;
649 si->sadhcnt = net->xfrm.state_hmask; 639 si->sadhcnt = net->xfrm.state_hmask;
650 si->sadhmcnt = xfrm_state_hashmax; 640 si->sadhmcnt = xfrm_state_hashmax;
651 spin_unlock_bh(&xfrm_state_lock); 641 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
652} 642}
653EXPORT_SYMBOL(xfrm_sad_getinfo); 643EXPORT_SYMBOL(xfrm_sad_getinfo);
654 644
@@ -801,7 +791,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
801 791
802 to_put = NULL; 792 to_put = NULL;
803 793
804 spin_lock_bh(&xfrm_state_lock); 794 spin_lock_bh(&net->xfrm.xfrm_state_lock);
805 h = xfrm_dst_hash(net, daddr, saddr, tmpl->reqid, encap_family); 795 h = xfrm_dst_hash(net, daddr, saddr, tmpl->reqid, encap_family);
806 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) { 796 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) {
807 if (x->props.family == encap_family && 797 if (x->props.family == encap_family &&
@@ -886,7 +876,7 @@ out:
886 xfrm_state_hold(x); 876 xfrm_state_hold(x);
887 else 877 else
888 *err = acquire_in_progress ? -EAGAIN : error; 878 *err = acquire_in_progress ? -EAGAIN : error;
889 spin_unlock_bh(&xfrm_state_lock); 879 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
890 if (to_put) 880 if (to_put)
891 xfrm_state_put(to_put); 881 xfrm_state_put(to_put);
892 return x; 882 return x;
@@ -900,7 +890,7 @@ xfrm_stateonly_find(struct net *net, u32 mark,
900 unsigned int h; 890 unsigned int h;
901 struct xfrm_state *rx = NULL, *x = NULL; 891 struct xfrm_state *rx = NULL, *x = NULL;
902 892
903 spin_lock(&xfrm_state_lock); 893 spin_lock(&net->xfrm.xfrm_state_lock);
904 h = xfrm_dst_hash(net, daddr, saddr, reqid, family); 894 h = xfrm_dst_hash(net, daddr, saddr, reqid, family);
905 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) { 895 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) {
906 if (x->props.family == family && 896 if (x->props.family == family &&
@@ -918,7 +908,7 @@ xfrm_stateonly_find(struct net *net, u32 mark,
918 908
919 if (rx) 909 if (rx)
920 xfrm_state_hold(rx); 910 xfrm_state_hold(rx);
921 spin_unlock(&xfrm_state_lock); 911 spin_unlock(&net->xfrm.xfrm_state_lock);
922 912
923 913
924 return rx; 914 return rx;
@@ -950,14 +940,12 @@ static void __xfrm_state_insert(struct xfrm_state *x)
950 if (x->replay_maxage) 940 if (x->replay_maxage)
951 mod_timer(&x->rtimer, jiffies + x->replay_maxage); 941 mod_timer(&x->rtimer, jiffies + x->replay_maxage);
952 942
953 wake_up(&net->xfrm.km_waitq);
954
955 net->xfrm.state_num++; 943 net->xfrm.state_num++;
956 944
957 xfrm_hash_grow_check(net, x->bydst.next != NULL); 945 xfrm_hash_grow_check(net, x->bydst.next != NULL);
958} 946}
959 947
960/* xfrm_state_lock is held */ 948/* net->xfrm.xfrm_state_lock is held */
961static void __xfrm_state_bump_genids(struct xfrm_state *xnew) 949static void __xfrm_state_bump_genids(struct xfrm_state *xnew)
962{ 950{
963 struct net *net = xs_net(xnew); 951 struct net *net = xs_net(xnew);
@@ -980,14 +968,16 @@ static void __xfrm_state_bump_genids(struct xfrm_state *xnew)
980 968
981void xfrm_state_insert(struct xfrm_state *x) 969void xfrm_state_insert(struct xfrm_state *x)
982{ 970{
983 spin_lock_bh(&xfrm_state_lock); 971 struct net *net = xs_net(x);
972
973 spin_lock_bh(&net->xfrm.xfrm_state_lock);
984 __xfrm_state_bump_genids(x); 974 __xfrm_state_bump_genids(x);
985 __xfrm_state_insert(x); 975 __xfrm_state_insert(x);
986 spin_unlock_bh(&xfrm_state_lock); 976 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
987} 977}
988EXPORT_SYMBOL(xfrm_state_insert); 978EXPORT_SYMBOL(xfrm_state_insert);
989 979
990/* xfrm_state_lock is held */ 980/* net->xfrm.xfrm_state_lock is held */
991static struct xfrm_state *__find_acq_core(struct net *net, 981static struct xfrm_state *__find_acq_core(struct net *net,
992 const struct xfrm_mark *m, 982 const struct xfrm_mark *m,
993 unsigned short family, u8 mode, 983 unsigned short family, u8 mode,
@@ -1079,7 +1069,7 @@ int xfrm_state_add(struct xfrm_state *x)
1079 1069
1080 to_put = NULL; 1070 to_put = NULL;
1081 1071
1082 spin_lock_bh(&xfrm_state_lock); 1072 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1083 1073
1084 x1 = __xfrm_state_locate(x, use_spi, family); 1074 x1 = __xfrm_state_locate(x, use_spi, family);
1085 if (x1) { 1075 if (x1) {
@@ -1108,7 +1098,7 @@ int xfrm_state_add(struct xfrm_state *x)
1108 err = 0; 1098 err = 0;
1109 1099
1110out: 1100out:
1111 spin_unlock_bh(&xfrm_state_lock); 1101 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1112 1102
1113 if (x1) { 1103 if (x1) {
1114 xfrm_state_delete(x1); 1104 xfrm_state_delete(x1);
@@ -1203,16 +1193,16 @@ out:
1203 return NULL; 1193 return NULL;
1204} 1194}
1205 1195
1206/* xfrm_state_lock is held */ 1196/* net->xfrm.xfrm_state_lock is held */
1207struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m) 1197struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *net)
1208{ 1198{
1209 unsigned int h; 1199 unsigned int h;
1210 struct xfrm_state *x; 1200 struct xfrm_state *x;
1211 1201
1212 if (m->reqid) { 1202 if (m->reqid) {
1213 h = xfrm_dst_hash(&init_net, &m->old_daddr, &m->old_saddr, 1203 h = xfrm_dst_hash(net, &m->old_daddr, &m->old_saddr,
1214 m->reqid, m->old_family); 1204 m->reqid, m->old_family);
1215 hlist_for_each_entry(x, init_net.xfrm.state_bydst+h, bydst) { 1205 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) {
1216 if (x->props.mode != m->mode || 1206 if (x->props.mode != m->mode ||
1217 x->id.proto != m->proto) 1207 x->id.proto != m->proto)
1218 continue; 1208 continue;
@@ -1227,9 +1217,9 @@ struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m)
1227 return x; 1217 return x;
1228 } 1218 }
1229 } else { 1219 } else {
1230 h = xfrm_src_hash(&init_net, &m->old_daddr, &m->old_saddr, 1220 h = xfrm_src_hash(net, &m->old_daddr, &m->old_saddr,
1231 m->old_family); 1221 m->old_family);
1232 hlist_for_each_entry(x, init_net.xfrm.state_bysrc+h, bysrc) { 1222 hlist_for_each_entry(x, net->xfrm.state_bysrc+h, bysrc) {
1233 if (x->props.mode != m->mode || 1223 if (x->props.mode != m->mode ||
1234 x->id.proto != m->proto) 1224 x->id.proto != m->proto)
1235 continue; 1225 continue;
@@ -1283,10 +1273,11 @@ int xfrm_state_update(struct xfrm_state *x)
1283 struct xfrm_state *x1, *to_put; 1273 struct xfrm_state *x1, *to_put;
1284 int err; 1274 int err;
1285 int use_spi = xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY); 1275 int use_spi = xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY);
1276 struct net *net = xs_net(x);
1286 1277
1287 to_put = NULL; 1278 to_put = NULL;
1288 1279
1289 spin_lock_bh(&xfrm_state_lock); 1280 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1290 x1 = __xfrm_state_locate(x, use_spi, x->props.family); 1281 x1 = __xfrm_state_locate(x, use_spi, x->props.family);
1291 1282
1292 err = -ESRCH; 1283 err = -ESRCH;
@@ -1306,7 +1297,7 @@ int xfrm_state_update(struct xfrm_state *x)
1306 err = 0; 1297 err = 0;
1307 1298
1308out: 1299out:
1309 spin_unlock_bh(&xfrm_state_lock); 1300 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1310 1301
1311 if (to_put) 1302 if (to_put)
1312 xfrm_state_put(to_put); 1303 xfrm_state_put(to_put);
@@ -1377,9 +1368,9 @@ xfrm_state_lookup(struct net *net, u32 mark, const xfrm_address_t *daddr, __be32
1377{ 1368{
1378 struct xfrm_state *x; 1369 struct xfrm_state *x;
1379 1370
1380 spin_lock_bh(&xfrm_state_lock); 1371 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1381 x = __xfrm_state_lookup(net, mark, daddr, spi, proto, family); 1372 x = __xfrm_state_lookup(net, mark, daddr, spi, proto, family);
1382 spin_unlock_bh(&xfrm_state_lock); 1373 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1383 return x; 1374 return x;
1384} 1375}
1385EXPORT_SYMBOL(xfrm_state_lookup); 1376EXPORT_SYMBOL(xfrm_state_lookup);
@@ -1391,9 +1382,9 @@ xfrm_state_lookup_byaddr(struct net *net, u32 mark,
1391{ 1382{
1392 struct xfrm_state *x; 1383 struct xfrm_state *x;
1393 1384
1394 spin_lock_bh(&xfrm_state_lock); 1385 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1395 x = __xfrm_state_lookup_byaddr(net, mark, daddr, saddr, proto, family); 1386 x = __xfrm_state_lookup_byaddr(net, mark, daddr, saddr, proto, family);
1396 spin_unlock_bh(&xfrm_state_lock); 1387 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1397 return x; 1388 return x;
1398} 1389}
1399EXPORT_SYMBOL(xfrm_state_lookup_byaddr); 1390EXPORT_SYMBOL(xfrm_state_lookup_byaddr);
@@ -1405,9 +1396,9 @@ xfrm_find_acq(struct net *net, const struct xfrm_mark *mark, u8 mode, u32 reqid,
1405{ 1396{
1406 struct xfrm_state *x; 1397 struct xfrm_state *x;
1407 1398
1408 spin_lock_bh(&xfrm_state_lock); 1399 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1409 x = __find_acq_core(net, mark, family, mode, reqid, proto, daddr, saddr, create); 1400 x = __find_acq_core(net, mark, family, mode, reqid, proto, daddr, saddr, create);
1410 spin_unlock_bh(&xfrm_state_lock); 1401 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1411 1402
1412 return x; 1403 return x;
1413} 1404}
@@ -1416,17 +1407,17 @@ EXPORT_SYMBOL(xfrm_find_acq);
1416#ifdef CONFIG_XFRM_SUB_POLICY 1407#ifdef CONFIG_XFRM_SUB_POLICY
1417int 1408int
1418xfrm_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n, 1409xfrm_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n,
1419 unsigned short family) 1410 unsigned short family, struct net *net)
1420{ 1411{
1421 int err = 0; 1412 int err = 0;
1422 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family); 1413 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family);
1423 if (!afinfo) 1414 if (!afinfo)
1424 return -EAFNOSUPPORT; 1415 return -EAFNOSUPPORT;
1425 1416
1426 spin_lock_bh(&xfrm_state_lock); 1417 spin_lock_bh(&net->xfrm.xfrm_state_lock); /*FIXME*/
1427 if (afinfo->tmpl_sort) 1418 if (afinfo->tmpl_sort)
1428 err = afinfo->tmpl_sort(dst, src, n); 1419 err = afinfo->tmpl_sort(dst, src, n);
1429 spin_unlock_bh(&xfrm_state_lock); 1420 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1430 xfrm_state_put_afinfo(afinfo); 1421 xfrm_state_put_afinfo(afinfo);
1431 return err; 1422 return err;
1432} 1423}
@@ -1438,13 +1429,15 @@ xfrm_state_sort(struct xfrm_state **dst, struct xfrm_state **src, int n,
1438{ 1429{
1439 int err = 0; 1430 int err = 0;
1440 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family); 1431 struct xfrm_state_afinfo *afinfo = xfrm_state_get_afinfo(family);
1432 struct net *net = xs_net(*dst);
1433
1441 if (!afinfo) 1434 if (!afinfo)
1442 return -EAFNOSUPPORT; 1435 return -EAFNOSUPPORT;
1443 1436
1444 spin_lock_bh(&xfrm_state_lock); 1437 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1445 if (afinfo->state_sort) 1438 if (afinfo->state_sort)
1446 err = afinfo->state_sort(dst, src, n); 1439 err = afinfo->state_sort(dst, src, n);
1447 spin_unlock_bh(&xfrm_state_lock); 1440 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1448 xfrm_state_put_afinfo(afinfo); 1441 xfrm_state_put_afinfo(afinfo);
1449 return err; 1442 return err;
1450} 1443}
@@ -1476,9 +1469,9 @@ struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 mark, u32 seq)
1476{ 1469{
1477 struct xfrm_state *x; 1470 struct xfrm_state *x;
1478 1471
1479 spin_lock_bh(&xfrm_state_lock); 1472 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1480 x = __xfrm_find_acq_byseq(net, mark, seq); 1473 x = __xfrm_find_acq_byseq(net, mark, seq);
1481 spin_unlock_bh(&xfrm_state_lock); 1474 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1482 return x; 1475 return x;
1483} 1476}
1484EXPORT_SYMBOL(xfrm_find_acq_byseq); 1477EXPORT_SYMBOL(xfrm_find_acq_byseq);
@@ -1496,6 +1489,30 @@ u32 xfrm_get_acqseq(void)
1496} 1489}
1497EXPORT_SYMBOL(xfrm_get_acqseq); 1490EXPORT_SYMBOL(xfrm_get_acqseq);
1498 1491
1492int verify_spi_info(u8 proto, u32 min, u32 max)
1493{
1494 switch (proto) {
1495 case IPPROTO_AH:
1496 case IPPROTO_ESP:
1497 break;
1498
1499 case IPPROTO_COMP:
1500 /* IPCOMP spi is 16-bits. */
1501 if (max >= 0x10000)
1502 return -EINVAL;
1503 break;
1504
1505 default:
1506 return -EINVAL;
1507 }
1508
1509 if (min > max)
1510 return -EINVAL;
1511
1512 return 0;
1513}
1514EXPORT_SYMBOL(verify_spi_info);
1515
1499int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high) 1516int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1500{ 1517{
1501 struct net *net = xs_net(x); 1518 struct net *net = xs_net(x);
@@ -1536,10 +1553,10 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high)
1536 } 1553 }
1537 } 1554 }
1538 if (x->id.spi) { 1555 if (x->id.spi) {
1539 spin_lock_bh(&xfrm_state_lock); 1556 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1540 h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto, x->props.family); 1557 h = xfrm_spi_hash(net, &x->id.daddr, x->id.spi, x->id.proto, x->props.family);
1541 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h); 1558 hlist_add_head(&x->byspi, net->xfrm.state_byspi+h);
1542 spin_unlock_bh(&xfrm_state_lock); 1559 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1543 1560
1544 err = 0; 1561 err = 0;
1545 } 1562 }
@@ -1562,7 +1579,7 @@ int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk,
1562 if (walk->seq != 0 && list_empty(&walk->all)) 1579 if (walk->seq != 0 && list_empty(&walk->all))
1563 return 0; 1580 return 0;
1564 1581
1565 spin_lock_bh(&xfrm_state_lock); 1582 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1566 if (list_empty(&walk->all)) 1583 if (list_empty(&walk->all))
1567 x = list_first_entry(&net->xfrm.state_all, struct xfrm_state_walk, all); 1584 x = list_first_entry(&net->xfrm.state_all, struct xfrm_state_walk, all);
1568 else 1585 else
@@ -1586,7 +1603,7 @@ int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk,
1586 } 1603 }
1587 list_del_init(&walk->all); 1604 list_del_init(&walk->all);
1588out: 1605out:
1589 spin_unlock_bh(&xfrm_state_lock); 1606 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1590 return err; 1607 return err;
1591} 1608}
1592EXPORT_SYMBOL(xfrm_state_walk); 1609EXPORT_SYMBOL(xfrm_state_walk);
@@ -1600,14 +1617,14 @@ void xfrm_state_walk_init(struct xfrm_state_walk *walk, u8 proto)
1600} 1617}
1601EXPORT_SYMBOL(xfrm_state_walk_init); 1618EXPORT_SYMBOL(xfrm_state_walk_init);
1602 1619
1603void xfrm_state_walk_done(struct xfrm_state_walk *walk) 1620void xfrm_state_walk_done(struct xfrm_state_walk *walk, struct net *net)
1604{ 1621{
1605 if (list_empty(&walk->all)) 1622 if (list_empty(&walk->all))
1606 return; 1623 return;
1607 1624
1608 spin_lock_bh(&xfrm_state_lock); 1625 spin_lock_bh(&net->xfrm.xfrm_state_lock);
1609 list_del(&walk->all); 1626 list_del(&walk->all);
1610 spin_unlock_bh(&xfrm_state_lock); 1627 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
1611} 1628}
1612EXPORT_SYMBOL(xfrm_state_walk_done); 1629EXPORT_SYMBOL(xfrm_state_walk_done);
1613 1630
@@ -1655,16 +1672,12 @@ EXPORT_SYMBOL(km_state_notify);
1655 1672
1656void km_state_expired(struct xfrm_state *x, int hard, u32 portid) 1673void km_state_expired(struct xfrm_state *x, int hard, u32 portid)
1657{ 1674{
1658 struct net *net = xs_net(x);
1659 struct km_event c; 1675 struct km_event c;
1660 1676
1661 c.data.hard = hard; 1677 c.data.hard = hard;
1662 c.portid = portid; 1678 c.portid = portid;
1663 c.event = XFRM_MSG_EXPIRE; 1679 c.event = XFRM_MSG_EXPIRE;
1664 km_state_notify(x, &c); 1680 km_state_notify(x, &c);
1665
1666 if (hard)
1667 wake_up(&net->xfrm.km_waitq);
1668} 1681}
1669 1682
1670EXPORT_SYMBOL(km_state_expired); 1683EXPORT_SYMBOL(km_state_expired);
@@ -1707,16 +1720,12 @@ EXPORT_SYMBOL(km_new_mapping);
1707 1720
1708void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 portid) 1721void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 portid)
1709{ 1722{
1710 struct net *net = xp_net(pol);
1711 struct km_event c; 1723 struct km_event c;
1712 1724
1713 c.data.hard = hard; 1725 c.data.hard = hard;
1714 c.portid = portid; 1726 c.portid = portid;
1715 c.event = XFRM_MSG_POLEXPIRE; 1727 c.event = XFRM_MSG_POLEXPIRE;
1716 km_policy_notify(pol, dir, &c); 1728 km_policy_notify(pol, dir, &c);
1717
1718 if (hard)
1719 wake_up(&net->xfrm.km_waitq);
1720} 1729}
1721EXPORT_SYMBOL(km_policy_expired); 1730EXPORT_SYMBOL(km_policy_expired);
1722 1731
@@ -2025,7 +2034,7 @@ int __net_init xfrm_state_init(struct net *net)
2025 INIT_WORK(&net->xfrm.state_hash_work, xfrm_hash_resize); 2034 INIT_WORK(&net->xfrm.state_hash_work, xfrm_hash_resize);
2026 INIT_HLIST_HEAD(&net->xfrm.state_gc_list); 2035 INIT_HLIST_HEAD(&net->xfrm.state_gc_list);
2027 INIT_WORK(&net->xfrm.state_gc_work, xfrm_state_gc_task); 2036 INIT_WORK(&net->xfrm.state_gc_work, xfrm_state_gc_task);
2028 init_waitqueue_head(&net->xfrm.km_waitq); 2037 spin_lock_init(&net->xfrm.xfrm_state_lock);
2029 return 0; 2038 return 0;
2030 2039
2031out_byspi: 2040out_byspi:
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index f964d4c00ffb..97681a390402 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -181,7 +181,9 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
181 attrs[XFRMA_ALG_AEAD] || 181 attrs[XFRMA_ALG_AEAD] ||
182 attrs[XFRMA_ALG_CRYPT] || 182 attrs[XFRMA_ALG_CRYPT] ||
183 attrs[XFRMA_ALG_COMP] || 183 attrs[XFRMA_ALG_COMP] ||
184 attrs[XFRMA_TFCPAD]) 184 attrs[XFRMA_TFCPAD] ||
185 (ntohl(p->id.spi) >= 0x10000))
186
185 goto out; 187 goto out;
186 break; 188 break;
187 189
@@ -877,7 +879,10 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
877static int xfrm_dump_sa_done(struct netlink_callback *cb) 879static int xfrm_dump_sa_done(struct netlink_callback *cb)
878{ 880{
879 struct xfrm_state_walk *walk = (struct xfrm_state_walk *) &cb->args[1]; 881 struct xfrm_state_walk *walk = (struct xfrm_state_walk *) &cb->args[1];
880 xfrm_state_walk_done(walk); 882 struct sock *sk = cb->skb->sk;
883 struct net *net = sock_net(sk);
884
885 xfrm_state_walk_done(walk, net);
881 return 0; 886 return 0;
882} 887}
883 888
@@ -1074,29 +1079,6 @@ out_noput:
1074 return err; 1079 return err;
1075} 1080}
1076 1081
1077static int verify_userspi_info(struct xfrm_userspi_info *p)
1078{
1079 switch (p->info.id.proto) {
1080 case IPPROTO_AH:
1081 case IPPROTO_ESP:
1082 break;
1083
1084 case IPPROTO_COMP:
1085 /* IPCOMP spi is 16-bits. */
1086 if (p->max >= 0x10000)
1087 return -EINVAL;
1088 break;
1089
1090 default:
1091 return -EINVAL;
1092 }
1093
1094 if (p->min > p->max)
1095 return -EINVAL;
1096
1097 return 0;
1098}
1099
1100static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, 1082static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
1101 struct nlattr **attrs) 1083 struct nlattr **attrs)
1102{ 1084{
@@ -1111,7 +1093,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
1111 struct xfrm_mark m; 1093 struct xfrm_mark m;
1112 1094
1113 p = nlmsg_data(nlh); 1095 p = nlmsg_data(nlh);
1114 err = verify_userspi_info(p); 1096 err = verify_spi_info(p->info.id.proto, p->min, p->max);
1115 if (err) 1097 if (err)
1116 goto out_noput; 1098 goto out_noput;
1117 1099
@@ -1189,6 +1171,8 @@ static int verify_policy_type(u8 type)
1189 1171
1190static int verify_newpolicy_info(struct xfrm_userpolicy_info *p) 1172static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
1191{ 1173{
1174 int ret;
1175
1192 switch (p->share) { 1176 switch (p->share) {
1193 case XFRM_SHARE_ANY: 1177 case XFRM_SHARE_ANY:
1194 case XFRM_SHARE_SESSION: 1178 case XFRM_SHARE_SESSION:
@@ -1224,7 +1208,13 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
1224 return -EINVAL; 1208 return -EINVAL;
1225 } 1209 }
1226 1210
1227 return verify_policy_dir(p->dir); 1211 ret = verify_policy_dir(p->dir);
1212 if (ret)
1213 return ret;
1214 if (p->index && ((p->index & XFRM_POLICY_MAX) != p->dir))
1215 return -EINVAL;
1216
1217 return 0;
1228} 1218}
1229 1219
1230static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct nlattr **attrs) 1220static int copy_from_user_sec_ctx(struct xfrm_policy *pol, struct nlattr **attrs)
@@ -1547,8 +1537,9 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
1547static int xfrm_dump_policy_done(struct netlink_callback *cb) 1537static int xfrm_dump_policy_done(struct netlink_callback *cb)
1548{ 1538{
1549 struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *) &cb->args[1]; 1539 struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *) &cb->args[1];
1540 struct net *net = sock_net(cb->skb->sk);
1550 1541
1551 xfrm_policy_walk_done(walk); 1542 xfrm_policy_walk_done(walk, net);
1552 return 0; 1543 return 0;
1553} 1544}
1554 1545
@@ -2129,6 +2120,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
2129 u8 type; 2120 u8 type;
2130 int err; 2121 int err;
2131 int n = 0; 2122 int n = 0;
2123 struct net *net = sock_net(skb->sk);
2132 2124
2133 if (attrs[XFRMA_MIGRATE] == NULL) 2125 if (attrs[XFRMA_MIGRATE] == NULL)
2134 return -EINVAL; 2126 return -EINVAL;
@@ -2146,7 +2138,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh,
2146 if (!n) 2138 if (!n)
2147 return 0; 2139 return 0;
2148 2140
2149 xfrm_migrate(&pi->sel, pi->dir, type, m, n, kmp); 2141 xfrm_migrate(&pi->sel, pi->dir, type, m, n, kmp, net);
2150 2142
2151 return 0; 2143 return 0;
2152} 2144}
@@ -2394,9 +2386,11 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
2394 2386
2395static void xfrm_netlink_rcv(struct sk_buff *skb) 2387static void xfrm_netlink_rcv(struct sk_buff *skb)
2396{ 2388{
2397 mutex_lock(&xfrm_cfg_mutex); 2389 struct net *net = sock_net(skb->sk);
2390
2391 mutex_lock(&net->xfrm.xfrm_cfg_mutex);
2398 netlink_rcv_skb(skb, &xfrm_user_rcv_msg); 2392 netlink_rcv_skb(skb, &xfrm_user_rcv_msg);
2399 mutex_unlock(&xfrm_cfg_mutex); 2393 mutex_unlock(&net->xfrm.xfrm_cfg_mutex);
2400} 2394}
2401 2395
2402static inline size_t xfrm_expire_msgsize(void) 2396static inline size_t xfrm_expire_msgsize(void)