History

ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH()

INET6_MATCH() runs without holding a lock on the socket. We probably need to annotate most reads. This patch makes INET6_MATCH() an inline function to ease our changes. v2: inline function only defined if IS_ENABLED(CONFIG_IPV6) Change the name to inet6_match(), this is no longer a macro.

Eric Dumazet committed 4 years ago

Commit 5d368f01 parent ff009404 files · +24 −14Browse files

Showing the changes to include (1 of 4 files). Show all

Unified · Split

include/net/inet6_hashtables.h+19−9
@@ -103,15 +103,25 @@ struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo, · 102 unmodified lines
103103 const int dif);
104104
105105 int inet6_hash(struct sock *sk);
106−#endif /* IS_ENABLED(CONFIG_IPV6) */
107106
108−#define INET6_MATCH(__sk, __net, __saddr, __daddr, __ports, __dif, __sdif) \
109− (((__sk)->sk_portpair == (__ports)) && \
110− ((__sk)->sk_family == AF_INET6) && \
111− ipv6_addr_equal(&(__sk)->sk_v6_daddr, (__saddr)) && \
112− ipv6_addr_equal(&(__sk)->sk_v6_rcv_saddr, (__daddr)) && \
113− (((__sk)->sk_bound_dev_if == (__dif)) || \
114− ((__sk)->sk_bound_dev_if == (__sdif))) && \
115− net_eq(sock_net(__sk), (__net)))
107+static inline bool inet6_match(struct net *net, const struct sock *sk,
108+ const struct in6_addr *saddr,
109+ const struct in6_addr *daddr,
110+ const __portpair ports,
111+ const int dif, const int sdif)
112+{
113+ int bound_dev_if;
114+
115+ if (!net_eq(sock_net(sk), net) ||
116+ sk->sk_family != AF_INET6 ||
117+ sk->sk_portpair != ports ||
118+ !ipv6_addr_equal(&sk->sk_v6_daddr, saddr) ||
119+ !ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
120+ return false;
121+
122+ bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
123+ return bound_dev_if == dif || bound_dev_if == sdif;
124+}
125+#endif /* IS_ENABLED(CONFIG_IPV6) */
116126
117127 #endif /* _INET6_HASHTABLES_H */