Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 97493e6a authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'sk_txhash'



Tom Herbert says:

====================
net: Initialize sk_hash to random value and reset for failing cnxs

This patch set implements a common function to simply set sk_txhash to
a random number instead of going through the trouble to call flow
dissector. From dst_negative_advice we now reset the sk_txhash in hopes
of finding a better ECMP path through the network. Changing sk_txhash
affects:
  - IPv6 flow label and UDP source port which affect ECMP in the network
  - Local ECMP route selection (pending changes to use sk_txhash)
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 7a86d96e 265f94ff
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -370,22 +370,6 @@ static inline void iph_to_flow_copy_v4addrs(struct flow_keys *flow,
	flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
}

static inline void inet_set_txhash(struct sock *sk)
{
	struct inet_sock *inet = inet_sk(sk);
	struct flow_keys keys;

	memset(&keys, 0, sizeof(keys));

	keys.addrs.v4addrs.src = inet->inet_saddr;
	keys.addrs.v4addrs.dst = inet->inet_daddr;
	keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
	keys.ports.src = inet->inet_sport;
	keys.ports.dst = inet->inet_dport;

	sk->sk_txhash = flow_hash_from_keys(&keys);
}

static inline __wsum inet_gro_compute_pseudo(struct sk_buff *skb, int proto)
{
	const struct iphdr *iph = skb_gro_network_header(skb);
+0 −19
Original line number Diff line number Diff line
@@ -707,25 +707,6 @@ static inline void iph_to_flow_copy_v6addrs(struct flow_keys *flow,
}

#if IS_ENABLED(CONFIG_IPV6)
static inline void ip6_set_txhash(struct sock *sk)
{
	struct inet_sock *inet = inet_sk(sk);
	struct ipv6_pinfo *np = inet6_sk(sk);
	struct flow_keys keys;

	memset(&keys, 0, sizeof(keys));

	memcpy(&keys.addrs.v6addrs.src, &np->saddr,
	       sizeof(keys.addrs.v6addrs.src));
	memcpy(&keys.addrs.v6addrs.dst, &sk->sk_v6_daddr,
	       sizeof(keys.addrs.v6addrs.dst));
	keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
	keys.ports.src = inet->inet_sport;
	keys.ports.dst = inet->inet_dport;

	sk->sk_txhash = flow_hash_from_keys(&keys);
}

static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
					__be32 flowlabel, bool autolabel)
{
+16 −0
Original line number Diff line number Diff line
@@ -1687,6 +1687,20 @@ static inline void sock_graft(struct sock *sk, struct socket *parent)
kuid_t sock_i_uid(struct sock *sk);
unsigned long sock_i_ino(struct sock *sk);

static inline void sk_set_txhash(struct sock *sk)
{
	sk->sk_txhash = prandom_u32();

	if (unlikely(!sk->sk_txhash))
		sk->sk_txhash = 1;
}

static inline void sk_rethink_txhash(struct sock *sk)
{
	if (sk->sk_txhash)
		sk_set_txhash(sk);
}

static inline struct dst_entry *
__sk_dst_get(struct sock *sk)
{
@@ -1711,6 +1725,8 @@ static inline void dst_negative_advice(struct sock *sk)
{
	struct dst_entry *ndst, *dst = __sk_dst_get(sk);

	sk_rethink_txhash(sk);

	if (dst && dst->ops->negative_advice) {
		ndst = dst->ops->negative_advice(dst);

+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len
	inet->inet_daddr = fl4->daddr;
	inet->inet_dport = usin->sin_port;
	sk->sk_state = TCP_ESTABLISHED;
	inet_set_txhash(sk);
	sk_set_txhash(sk);
	inet->inet_id = jiffies;

	sk_dst_set(sk, &rt->dst);
+2 −2
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
	if (err)
		goto failure;

	inet_set_txhash(sk);
	sk_set_txhash(sk);

	rt = ip_route_newports(fl4, rt, orig_sport, orig_dport,
			       inet->inet_sport, inet->inet_dport, sk);
@@ -1277,7 +1277,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
	newinet->mc_ttl	      = ip_hdr(skb)->ttl;
	newinet->rcv_tos      = ip_hdr(skb)->tos;
	inet_csk(newsk)->icsk_ext_hdr_len = 0;
	inet_set_txhash(newsk);
	sk_set_txhash(newsk);
	if (inet_opt)
		inet_csk(newsk)->icsk_ext_hdr_len = inet_opt->opt.optlen;
	newinet->inet_id = newtp->write_seq ^ jiffies;
Loading