Merge branch 'inet-more-data-race-fixes'
Eric Dumazet says: ==================== inet: more data-race fixes This series fixes some existing data-races on inet fields: inet->mc_ttl, inet->pmtudisc, inet->tos, inet->uc_index, inet->mc_index and inet->mc_addr. While fixing them, we convert eight socket options to lockless implementation. v2: addressed David Ahern feedback on ("inet: implement lockless IP_TOS") Added David Reviewed-by: tag on other patches. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
fbff653a40
@ -258,7 +258,7 @@ static inline u8 ip_sendmsg_scope(const struct inet_sock *inet,
|
||||
|
||||
static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
|
||||
{
|
||||
return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(inet->tos);
|
||||
return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(READ_ONCE(inet->tos));
|
||||
}
|
||||
|
||||
/* datagram.c */
|
||||
@ -434,19 +434,22 @@ int ip_dont_fragment(const struct sock *sk, const struct dst_entry *dst)
|
||||
|
||||
static inline bool ip_sk_accept_pmtu(const struct sock *sk)
|
||||
{
|
||||
return inet_sk(sk)->pmtudisc != IP_PMTUDISC_INTERFACE &&
|
||||
inet_sk(sk)->pmtudisc != IP_PMTUDISC_OMIT;
|
||||
u8 pmtudisc = READ_ONCE(inet_sk(sk)->pmtudisc);
|
||||
|
||||
return pmtudisc != IP_PMTUDISC_INTERFACE &&
|
||||
pmtudisc != IP_PMTUDISC_OMIT;
|
||||
}
|
||||
|
||||
static inline bool ip_sk_use_pmtu(const struct sock *sk)
|
||||
{
|
||||
return inet_sk(sk)->pmtudisc < IP_PMTUDISC_PROBE;
|
||||
return READ_ONCE(inet_sk(sk)->pmtudisc) < IP_PMTUDISC_PROBE;
|
||||
}
|
||||
|
||||
static inline bool ip_sk_ignore_df(const struct sock *sk)
|
||||
{
|
||||
return inet_sk(sk)->pmtudisc < IP_PMTUDISC_DO ||
|
||||
inet_sk(sk)->pmtudisc == IP_PMTUDISC_OMIT;
|
||||
u8 pmtudisc = READ_ONCE(inet_sk(sk)->pmtudisc);
|
||||
|
||||
return pmtudisc < IP_PMTUDISC_DO || pmtudisc == IP_PMTUDISC_OMIT;
|
||||
}
|
||||
|
||||
static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
|
||||
@ -807,6 +810,5 @@ int ip_sock_set_mtu_discover(struct sock *sk, int val);
|
||||
void ip_sock_set_pktinfo(struct sock *sk);
|
||||
void ip_sock_set_recverr(struct sock *sk);
|
||||
void ip_sock_set_tos(struct sock *sk, int val);
|
||||
void __ip_sock_set_tos(struct sock *sk, int val);
|
||||
|
||||
#endif /* _IP_H */
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
#define RTO_ONLINK 0x01
|
||||
|
||||
#define RT_CONN_FLAGS(sk) (RT_TOS(inet_sk(sk)->tos) | sock_flag(sk, SOCK_LOCALROUTE))
|
||||
#define RT_CONN_FLAGS(sk) (RT_TOS(READ_ONCE(inet_sk(sk)->tos)) | sock_flag(sk, SOCK_LOCALROUTE))
|
||||
#define RT_CONN_FLAGS_TOS(sk,tos) (RT_TOS(tos) | sock_flag(sk, SOCK_LOCALROUTE))
|
||||
|
||||
static inline __u8 ip_sock_rt_scope(const struct sock *sk)
|
||||
@ -50,7 +50,7 @@ static inline __u8 ip_sock_rt_scope(const struct sock *sk)
|
||||
|
||||
static inline __u8 ip_sock_rt_tos(const struct sock *sk)
|
||||
{
|
||||
return RT_TOS(inet_sk(sk)->tos);
|
||||
return RT_TOS(READ_ONCE(inet_sk(sk)->tos));
|
||||
}
|
||||
|
||||
struct ip_tunnel_info;
|
||||
|
@ -511,7 +511,7 @@ static int dccp_v4_send_response(const struct sock *sk, struct request_sock *req
|
||||
err = ip_build_and_send_pkt(skb, sk, ireq->ir_loc_addr,
|
||||
ireq->ir_rmt_addr,
|
||||
rcu_dereference(ireq->ireq_opt),
|
||||
inet_sk(sk)->tos);
|
||||
READ_ONCE(inet_sk(sk)->tos));
|
||||
rcu_read_unlock();
|
||||
err = net_xmit_eval(err);
|
||||
}
|
||||
|
@ -39,11 +39,11 @@ int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len
|
||||
saddr = inet->inet_saddr;
|
||||
if (ipv4_is_multicast(usin->sin_addr.s_addr)) {
|
||||
if (!oif || netif_index_is_l3_master(sock_net(sk), oif))
|
||||
oif = inet->mc_index;
|
||||
oif = READ_ONCE(inet->mc_index);
|
||||
if (!saddr)
|
||||
saddr = inet->mc_addr;
|
||||
saddr = READ_ONCE(inet->mc_addr);
|
||||
} else if (!oif) {
|
||||
oif = inet->uc_index;
|
||||
oif = READ_ONCE(inet->uc_index);
|
||||
}
|
||||
fl4 = &inet->cork.fl.u.ip4;
|
||||
rt = ip_route_connect(fl4, usin->sin_addr.s_addr, saddr, oif,
|
||||
|
@ -134,7 +134,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
|
||||
* hence this needs to be included regardless of socket family.
|
||||
*/
|
||||
if (ext & (1 << (INET_DIAG_TOS - 1)))
|
||||
if (nla_put_u8(skb, INET_DIAG_TOS, inet->tos) < 0)
|
||||
if (nla_put_u8(skb, INET_DIAG_TOS, READ_ONCE(inet->tos)) < 0)
|
||||
goto errout;
|
||||
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
|
@ -544,7 +544,7 @@ EXPORT_SYMBOL(__ip_queue_xmit);
|
||||
|
||||
int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl)
|
||||
{
|
||||
return __ip_queue_xmit(sk, skb, fl, inet_sk(sk)->tos);
|
||||
return __ip_queue_xmit(sk, skb, fl, READ_ONCE(inet_sk(sk)->tos));
|
||||
}
|
||||
EXPORT_SYMBOL(ip_queue_xmit);
|
||||
|
||||
@ -1387,8 +1387,8 @@ struct sk_buff *__ip_make_skb(struct sock *sk,
|
||||
struct ip_options *opt = NULL;
|
||||
struct rtable *rt = (struct rtable *)cork->dst;
|
||||
struct iphdr *iph;
|
||||
u8 pmtudisc, ttl;
|
||||
__be16 df = 0;
|
||||
__u8 ttl;
|
||||
|
||||
skb = __skb_dequeue(queue);
|
||||
if (!skb)
|
||||
@ -1418,8 +1418,9 @@ struct sk_buff *__ip_make_skb(struct sock *sk,
|
||||
/* DF bit is set when we want to see DF on outgoing frames.
|
||||
* If ignore_df is set too, we still allow to fragment this frame
|
||||
* locally. */
|
||||
if (inet->pmtudisc == IP_PMTUDISC_DO ||
|
||||
inet->pmtudisc == IP_PMTUDISC_PROBE ||
|
||||
pmtudisc = READ_ONCE(inet->pmtudisc);
|
||||
if (pmtudisc == IP_PMTUDISC_DO ||
|
||||
pmtudisc == IP_PMTUDISC_PROBE ||
|
||||
(skb->len <= dst_mtu(&rt->dst) &&
|
||||
ip_dont_fragment(sk, &rt->dst)))
|
||||
df = htons(IP_DF);
|
||||
@ -1430,14 +1431,14 @@ struct sk_buff *__ip_make_skb(struct sock *sk,
|
||||
if (cork->ttl != 0)
|
||||
ttl = cork->ttl;
|
||||
else if (rt->rt_type == RTN_MULTICAST)
|
||||
ttl = inet->mc_ttl;
|
||||
ttl = READ_ONCE(inet->mc_ttl);
|
||||
else
|
||||
ttl = ip_select_ttl(inet, &rt->dst);
|
||||
|
||||
iph = ip_hdr(skb);
|
||||
iph->version = 4;
|
||||
iph->ihl = 5;
|
||||
iph->tos = (cork->tos != -1) ? cork->tos : inet->tos;
|
||||
iph->tos = (cork->tos != -1) ? cork->tos : READ_ONCE(inet->tos);
|
||||
iph->frag_off = df;
|
||||
iph->ttl = ttl;
|
||||
iph->protocol = sk->sk_protocol;
|
||||
|
@ -585,25 +585,20 @@ out:
|
||||
return err;
|
||||
}
|
||||
|
||||
void __ip_sock_set_tos(struct sock *sk, int val)
|
||||
void ip_sock_set_tos(struct sock *sk, int val)
|
||||
{
|
||||
u8 old_tos = READ_ONCE(inet_sk(sk)->tos);
|
||||
|
||||
if (sk->sk_type == SOCK_STREAM) {
|
||||
val &= ~INET_ECN_MASK;
|
||||
val |= inet_sk(sk)->tos & INET_ECN_MASK;
|
||||
val |= old_tos & INET_ECN_MASK;
|
||||
}
|
||||
if (inet_sk(sk)->tos != val) {
|
||||
inet_sk(sk)->tos = val;
|
||||
if (old_tos != val) {
|
||||
WRITE_ONCE(inet_sk(sk)->tos, val);
|
||||
WRITE_ONCE(sk->sk_priority, rt_tos2priority(val));
|
||||
sk_dst_reset(sk);
|
||||
}
|
||||
}
|
||||
|
||||
void ip_sock_set_tos(struct sock *sk, int val)
|
||||
{
|
||||
lock_sock(sk);
|
||||
__ip_sock_set_tos(sk, val);
|
||||
release_sock(sk);
|
||||
}
|
||||
EXPORT_SYMBOL(ip_sock_set_tos);
|
||||
|
||||
void ip_sock_set_freebind(struct sock *sk)
|
||||
@ -622,9 +617,7 @@ int ip_sock_set_mtu_discover(struct sock *sk, int val)
|
||||
{
|
||||
if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_OMIT)
|
||||
return -EINVAL;
|
||||
lock_sock(sk);
|
||||
inet_sk(sk)->pmtudisc = val;
|
||||
release_sock(sk);
|
||||
WRITE_ONCE(inet_sk(sk)->pmtudisc, val);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(ip_sock_set_mtu_discover);
|
||||
@ -1039,6 +1032,22 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
|
||||
|
||||
WRITE_ONCE(inet->min_ttl, val);
|
||||
return 0;
|
||||
case IP_MULTICAST_TTL:
|
||||
if (sk->sk_type == SOCK_STREAM)
|
||||
return -EINVAL;
|
||||
if (optlen < 1)
|
||||
return -EINVAL;
|
||||
if (val == -1)
|
||||
val = 1;
|
||||
if (val < 0 || val > 255)
|
||||
return -EINVAL;
|
||||
WRITE_ONCE(inet->mc_ttl, val);
|
||||
return 0;
|
||||
case IP_MTU_DISCOVER:
|
||||
return ip_sock_set_mtu_discover(sk, val);
|
||||
case IP_TOS: /* This sets both TOS and Precedence */
|
||||
ip_sock_set_tos(sk, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = 0;
|
||||
@ -1093,25 +1102,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IP_TOS: /* This sets both TOS and Precedence */
|
||||
__ip_sock_set_tos(sk, val);
|
||||
break;
|
||||
case IP_MTU_DISCOVER:
|
||||
if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_OMIT)
|
||||
goto e_inval;
|
||||
inet->pmtudisc = val;
|
||||
break;
|
||||
case IP_MULTICAST_TTL:
|
||||
if (sk->sk_type == SOCK_STREAM)
|
||||
goto e_inval;
|
||||
if (optlen < 1)
|
||||
goto e_inval;
|
||||
if (val == -1)
|
||||
val = 1;
|
||||
if (val < 0 || val > 255)
|
||||
goto e_inval;
|
||||
inet->mc_ttl = val;
|
||||
break;
|
||||
case IP_UNICAST_IF:
|
||||
{
|
||||
struct net_device *dev = NULL;
|
||||
@ -1123,7 +1113,7 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
|
||||
|
||||
ifindex = (__force int)ntohl((__force __be32)val);
|
||||
if (ifindex == 0) {
|
||||
inet->uc_index = 0;
|
||||
WRITE_ONCE(inet->uc_index, 0);
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
@ -1140,7 +1130,7 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
|
||||
if (sk->sk_bound_dev_if && midx != sk->sk_bound_dev_if)
|
||||
break;
|
||||
|
||||
inet->uc_index = ifindex;
|
||||
WRITE_ONCE(inet->uc_index, ifindex);
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
@ -1178,8 +1168,8 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
|
||||
|
||||
if (!mreq.imr_ifindex) {
|
||||
if (mreq.imr_address.s_addr == htonl(INADDR_ANY)) {
|
||||
inet->mc_index = 0;
|
||||
inet->mc_addr = 0;
|
||||
WRITE_ONCE(inet->mc_index, 0);
|
||||
WRITE_ONCE(inet->mc_addr, 0);
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
@ -1204,8 +1194,8 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
|
||||
midx != sk->sk_bound_dev_if)
|
||||
break;
|
||||
|
||||
inet->mc_index = mreq.imr_ifindex;
|
||||
inet->mc_addr = mreq.imr_address.s_addr;
|
||||
WRITE_ONCE(inet->mc_index, mreq.imr_ifindex);
|
||||
WRITE_ONCE(inet->mc_addr, mreq.imr_address.s_addr);
|
||||
err = 0;
|
||||
break;
|
||||
}
|
||||
@ -1592,27 +1582,29 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
|
||||
case IP_MINTTL:
|
||||
val = READ_ONCE(inet->min_ttl);
|
||||
goto copyval;
|
||||
}
|
||||
|
||||
if (needs_rtnl)
|
||||
rtnl_lock();
|
||||
sockopt_lock_sock(sk);
|
||||
|
||||
switch (optname) {
|
||||
case IP_MULTICAST_TTL:
|
||||
val = READ_ONCE(inet->mc_ttl);
|
||||
goto copyval;
|
||||
case IP_MTU_DISCOVER:
|
||||
val = READ_ONCE(inet->pmtudisc);
|
||||
goto copyval;
|
||||
case IP_TOS:
|
||||
val = READ_ONCE(inet->tos);
|
||||
goto copyval;
|
||||
case IP_OPTIONS:
|
||||
{
|
||||
unsigned char optbuf[sizeof(struct ip_options)+40];
|
||||
struct ip_options *opt = (struct ip_options *)optbuf;
|
||||
struct ip_options_rcu *inet_opt;
|
||||
|
||||
inet_opt = rcu_dereference_protected(inet->inet_opt,
|
||||
lockdep_sock_is_held(sk));
|
||||
rcu_read_lock();
|
||||
inet_opt = rcu_dereference(inet->inet_opt);
|
||||
opt->optlen = 0;
|
||||
if (inet_opt)
|
||||
memcpy(optbuf, &inet_opt->opt,
|
||||
sizeof(struct ip_options) +
|
||||
inet_opt->opt.optlen);
|
||||
sockopt_release_sock(sk);
|
||||
rcu_read_unlock();
|
||||
|
||||
if (opt->optlen == 0) {
|
||||
len = 0;
|
||||
@ -1628,12 +1620,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
case IP_TOS:
|
||||
val = inet->tos;
|
||||
break;
|
||||
case IP_MTU_DISCOVER:
|
||||
val = inet->pmtudisc;
|
||||
break;
|
||||
case IP_MTU:
|
||||
{
|
||||
struct dst_entry *dst;
|
||||
@ -1643,24 +1629,55 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
|
||||
val = dst_mtu(dst);
|
||||
dst_release(dst);
|
||||
}
|
||||
if (!val) {
|
||||
sockopt_release_sock(sk);
|
||||
if (!val)
|
||||
return -ENOTCONN;
|
||||
}
|
||||
break;
|
||||
goto copyval;
|
||||
}
|
||||
case IP_PKTOPTIONS:
|
||||
{
|
||||
struct msghdr msg;
|
||||
|
||||
if (sk->sk_type != SOCK_STREAM)
|
||||
return -ENOPROTOOPT;
|
||||
|
||||
if (optval.is_kernel) {
|
||||
msg.msg_control_is_user = false;
|
||||
msg.msg_control = optval.kernel;
|
||||
} else {
|
||||
msg.msg_control_is_user = true;
|
||||
msg.msg_control_user = optval.user;
|
||||
}
|
||||
msg.msg_controllen = len;
|
||||
msg.msg_flags = in_compat_syscall() ? MSG_CMSG_COMPAT : 0;
|
||||
|
||||
if (inet_test_bit(PKTINFO, sk)) {
|
||||
struct in_pktinfo info;
|
||||
|
||||
info.ipi_addr.s_addr = READ_ONCE(inet->inet_rcv_saddr);
|
||||
info.ipi_spec_dst.s_addr = READ_ONCE(inet->inet_rcv_saddr);
|
||||
info.ipi_ifindex = READ_ONCE(inet->mc_index);
|
||||
put_cmsg(&msg, SOL_IP, IP_PKTINFO, sizeof(info), &info);
|
||||
}
|
||||
if (inet_test_bit(TTL, sk)) {
|
||||
int hlim = READ_ONCE(inet->mc_ttl);
|
||||
|
||||
put_cmsg(&msg, SOL_IP, IP_TTL, sizeof(hlim), &hlim);
|
||||
}
|
||||
if (inet_test_bit(TOS, sk)) {
|
||||
int tos = READ_ONCE(inet->rcv_tos);
|
||||
put_cmsg(&msg, SOL_IP, IP_TOS, sizeof(tos), &tos);
|
||||
}
|
||||
len -= msg.msg_controllen;
|
||||
return copy_to_sockptr(optlen, &len, sizeof(int));
|
||||
}
|
||||
case IP_MULTICAST_TTL:
|
||||
val = inet->mc_ttl;
|
||||
break;
|
||||
case IP_UNICAST_IF:
|
||||
val = (__force int)htonl((__u32) inet->uc_index);
|
||||
break;
|
||||
val = (__force int)htonl((__u32) READ_ONCE(inet->uc_index));
|
||||
goto copyval;
|
||||
case IP_MULTICAST_IF:
|
||||
{
|
||||
struct in_addr addr;
|
||||
len = min_t(unsigned int, len, sizeof(struct in_addr));
|
||||
addr.s_addr = inet->mc_addr;
|
||||
sockopt_release_sock(sk);
|
||||
addr.s_addr = READ_ONCE(inet->mc_addr);
|
||||
|
||||
if (copy_to_sockptr(optlen, &len, sizeof(int)))
|
||||
return -EFAULT;
|
||||
@ -1668,6 +1685,13 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (needs_rtnl)
|
||||
rtnl_lock();
|
||||
sockopt_lock_sock(sk);
|
||||
|
||||
switch (optname) {
|
||||
case IP_MSFILTER:
|
||||
{
|
||||
struct ip_msfilter msf;
|
||||
@ -1690,44 +1714,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
|
||||
else
|
||||
err = ip_get_mcast_msfilter(sk, optval, optlen, len);
|
||||
goto out;
|
||||
case IP_PKTOPTIONS:
|
||||
{
|
||||
struct msghdr msg;
|
||||
|
||||
sockopt_release_sock(sk);
|
||||
|
||||
if (sk->sk_type != SOCK_STREAM)
|
||||
return -ENOPROTOOPT;
|
||||
|
||||
if (optval.is_kernel) {
|
||||
msg.msg_control_is_user = false;
|
||||
msg.msg_control = optval.kernel;
|
||||
} else {
|
||||
msg.msg_control_is_user = true;
|
||||
msg.msg_control_user = optval.user;
|
||||
}
|
||||
msg.msg_controllen = len;
|
||||
msg.msg_flags = in_compat_syscall() ? MSG_CMSG_COMPAT : 0;
|
||||
|
||||
if (inet_test_bit(PKTINFO, sk)) {
|
||||
struct in_pktinfo info;
|
||||
|
||||
info.ipi_addr.s_addr = inet->inet_rcv_saddr;
|
||||
info.ipi_spec_dst.s_addr = inet->inet_rcv_saddr;
|
||||
info.ipi_ifindex = inet->mc_index;
|
||||
put_cmsg(&msg, SOL_IP, IP_PKTINFO, sizeof(info), &info);
|
||||
}
|
||||
if (inet_test_bit(TTL, sk)) {
|
||||
int hlim = inet->mc_ttl;
|
||||
put_cmsg(&msg, SOL_IP, IP_TTL, sizeof(hlim), &hlim);
|
||||
}
|
||||
if (inet_test_bit(TOS, sk)) {
|
||||
int tos = inet->rcv_tos;
|
||||
put_cmsg(&msg, SOL_IP, IP_TOS, sizeof(tos), &tos);
|
||||
}
|
||||
len -= msg.msg_controllen;
|
||||
return copy_to_sockptr(optlen, &len, sizeof(int));
|
||||
}
|
||||
case IP_LOCAL_PORT_RANGE:
|
||||
val = inet->local_port_range.hi << 16 | inet->local_port_range.lo;
|
||||
break;
|
||||
|
@ -551,7 +551,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
|
||||
case ICMP_DEST_UNREACH:
|
||||
if (code == ICMP_FRAG_NEEDED) { /* Path MTU discovery */
|
||||
ipv4_sk_update_pmtu(skb, sk, info);
|
||||
if (inet_sock->pmtudisc != IP_PMTUDISC_DONT) {
|
||||
if (READ_ONCE(inet_sock->pmtudisc) != IP_PMTUDISC_DONT) {
|
||||
err = EMSGSIZE;
|
||||
harderr = 1;
|
||||
break;
|
||||
@ -773,11 +773,11 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
||||
|
||||
if (ipv4_is_multicast(daddr)) {
|
||||
if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
|
||||
ipc.oif = inet->mc_index;
|
||||
ipc.oif = READ_ONCE(inet->mc_index);
|
||||
if (!saddr)
|
||||
saddr = inet->mc_addr;
|
||||
saddr = READ_ONCE(inet->mc_addr);
|
||||
} else if (!ipc.oif)
|
||||
ipc.oif = inet->uc_index;
|
||||
ipc.oif = READ_ONCE(inet->uc_index);
|
||||
|
||||
flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope,
|
||||
sk->sk_protocol, inet_sk_flowi_flags(sk), faddr,
|
||||
|
@ -239,7 +239,7 @@ static void raw_err(struct sock *sk, struct sk_buff *skb, u32 info)
|
||||
if (code > NR_ICMP_UNREACH)
|
||||
break;
|
||||
if (code == ICMP_FRAG_NEEDED) {
|
||||
harderr = inet->pmtudisc != IP_PMTUDISC_DONT;
|
||||
harderr = READ_ONCE(inet->pmtudisc) != IP_PMTUDISC_DONT;
|
||||
err = EMSGSIZE;
|
||||
} else {
|
||||
err = icmp_err_convert[code].errno;
|
||||
@ -482,7 +482,7 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
||||
int free = 0;
|
||||
__be32 daddr;
|
||||
__be32 saddr;
|
||||
int err;
|
||||
int uc_index, err;
|
||||
struct ip_options_data opt_copy;
|
||||
struct raw_frag_vec rfv;
|
||||
int hdrincl;
|
||||
@ -576,24 +576,25 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
||||
tos = get_rttos(&ipc, inet);
|
||||
scope = ip_sendmsg_scope(inet, &ipc, msg);
|
||||
|
||||
uc_index = READ_ONCE(inet->uc_index);
|
||||
if (ipv4_is_multicast(daddr)) {
|
||||
if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
|
||||
ipc.oif = inet->mc_index;
|
||||
ipc.oif = READ_ONCE(inet->mc_index);
|
||||
if (!saddr)
|
||||
saddr = inet->mc_addr;
|
||||
saddr = READ_ONCE(inet->mc_addr);
|
||||
} else if (!ipc.oif) {
|
||||
ipc.oif = inet->uc_index;
|
||||
} else if (ipv4_is_lbcast(daddr) && inet->uc_index) {
|
||||
ipc.oif = uc_index;
|
||||
} else if (ipv4_is_lbcast(daddr) && uc_index) {
|
||||
/* oif is set, packet is to local broadcast
|
||||
* and uc_index is set. oif is most likely set
|
||||
* by sk_bound_dev_if. If uc_index != oif check if the
|
||||
* oif is an L3 master and uc_index is an L3 slave.
|
||||
* If so, we want to allow the send using the uc_index.
|
||||
*/
|
||||
if (ipc.oif != inet->uc_index &&
|
||||
if (ipc.oif != uc_index &&
|
||||
ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk),
|
||||
inet->uc_index)) {
|
||||
ipc.oif = inet->uc_index;
|
||||
uc_index)) {
|
||||
ipc.oif = uc_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1024,10 +1024,11 @@ static int tcp_v4_send_synack(const struct sock *sk, struct dst_entry *dst,
|
||||
if (skb) {
|
||||
__tcp_v4_send_check(skb, ireq->ir_loc_addr, ireq->ir_rmt_addr);
|
||||
|
||||
tos = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos) ?
|
||||
(tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
|
||||
(inet_sk(sk)->tos & INET_ECN_MASK) :
|
||||
inet_sk(sk)->tos;
|
||||
tos = READ_ONCE(inet_sk(sk)->tos);
|
||||
|
||||
if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reflect_tos))
|
||||
tos = (tcp_rsk(req)->syn_tos & ~INET_ECN_MASK) |
|
||||
(tos & INET_ECN_MASK);
|
||||
|
||||
if (!INET_ECN_is_capable(tos) &&
|
||||
tcp_bpf_ca_needs_ecn((struct sock *)req))
|
||||
|
@ -750,7 +750,7 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
|
||||
case ICMP_DEST_UNREACH:
|
||||
if (code == ICMP_FRAG_NEEDED) { /* Path MTU discovery */
|
||||
ipv4_sk_update_pmtu(skb, sk, info);
|
||||
if (inet->pmtudisc != IP_PMTUDISC_DONT) {
|
||||
if (READ_ONCE(inet->pmtudisc) != IP_PMTUDISC_DONT) {
|
||||
err = EMSGSIZE;
|
||||
harderr = 1;
|
||||
break;
|
||||
@ -1055,6 +1055,7 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
||||
int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
|
||||
struct sk_buff *skb;
|
||||
struct ip_options_data opt_copy;
|
||||
int uc_index;
|
||||
|
||||
if (len > 0xFFFF)
|
||||
return -EMSGSIZE;
|
||||
@ -1173,25 +1174,26 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
||||
if (scope == RT_SCOPE_LINK)
|
||||
connected = 0;
|
||||
|
||||
uc_index = READ_ONCE(inet->uc_index);
|
||||
if (ipv4_is_multicast(daddr)) {
|
||||
if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
|
||||
ipc.oif = inet->mc_index;
|
||||
ipc.oif = READ_ONCE(inet->mc_index);
|
||||
if (!saddr)
|
||||
saddr = inet->mc_addr;
|
||||
saddr = READ_ONCE(inet->mc_addr);
|
||||
connected = 0;
|
||||
} else if (!ipc.oif) {
|
||||
ipc.oif = inet->uc_index;
|
||||
} else if (ipv4_is_lbcast(daddr) && inet->uc_index) {
|
||||
ipc.oif = uc_index;
|
||||
} else if (ipv4_is_lbcast(daddr) && uc_index) {
|
||||
/* oif is set, packet is to local broadcast and
|
||||
* uc_index is set. oif is most likely set
|
||||
* by sk_bound_dev_if. If uc_index != oif check if the
|
||||
* oif is an L3 master and uc_index is an L3 slave.
|
||||
* If so, we want to allow the send using the uc_index.
|
||||
*/
|
||||
if (ipc.oif != inet->uc_index &&
|
||||
if (ipc.oif != uc_index &&
|
||||
ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk),
|
||||
inet->uc_index)) {
|
||||
ipc.oif = inet->uc_index;
|
||||
uc_index)) {
|
||||
ipc.oif = uc_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -734,11 +734,11 @@ static int mptcp_setsockopt_v4_set_tos(struct mptcp_sock *msk, int optname,
|
||||
|
||||
lock_sock(sk);
|
||||
sockopt_seq_inc(msk);
|
||||
val = inet_sk(sk)->tos;
|
||||
val = READ_ONCE(inet_sk(sk)->tos);
|
||||
mptcp_for_each_subflow(msk, subflow) {
|
||||
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
|
||||
|
||||
__ip_sock_set_tos(ssk, val);
|
||||
ip_sock_set_tos(ssk, val);
|
||||
}
|
||||
release_sock(sk);
|
||||
|
||||
@ -1343,7 +1343,7 @@ static int mptcp_getsockopt_v4(struct mptcp_sock *msk, int optname,
|
||||
|
||||
switch (optname) {
|
||||
case IP_TOS:
|
||||
return mptcp_put_int_option(msk, optval, optlen, inet_sk(sk)->tos);
|
||||
return mptcp_put_int_option(msk, optval, optlen, READ_ONCE(inet_sk(sk)->tos));
|
||||
}
|
||||
|
||||
return -EOPNOTSUPP;
|
||||
@ -1411,7 +1411,7 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk)
|
||||
ssk->sk_bound_dev_if = sk->sk_bound_dev_if;
|
||||
ssk->sk_incoming_cpu = sk->sk_incoming_cpu;
|
||||
ssk->sk_ipv6only = sk->sk_ipv6only;
|
||||
__ip_sock_set_tos(ssk, inet_sk(sk)->tos);
|
||||
ip_sock_set_tos(ssk, inet_sk(sk)->tos);
|
||||
|
||||
if (sk->sk_userlocks & tx_rx_locks) {
|
||||
ssk->sk_userlocks |= sk->sk_userlocks & tx_rx_locks;
|
||||
|
@ -1316,7 +1316,7 @@ static void set_mcast_ttl(struct sock *sk, u_char ttl)
|
||||
|
||||
/* setsockopt(sock, SOL_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)); */
|
||||
lock_sock(sk);
|
||||
inet->mc_ttl = ttl;
|
||||
WRITE_ONCE(inet->mc_ttl, ttl);
|
||||
#ifdef CONFIG_IP_VS_IPV6
|
||||
if (sk->sk_family == AF_INET6) {
|
||||
struct ipv6_pinfo *np = inet6_sk(sk);
|
||||
@ -1335,7 +1335,7 @@ static void set_mcast_pmtudisc(struct sock *sk, int val)
|
||||
|
||||
/* setsockopt(sock, SOL_IP, IP_MTU_DISCOVER, &val, sizeof(val)); */
|
||||
lock_sock(sk);
|
||||
inet->pmtudisc = val;
|
||||
WRITE_ONCE(inet->pmtudisc, val);
|
||||
#ifdef CONFIG_IP_VS_IPV6
|
||||
if (sk->sk_family == AF_INET6) {
|
||||
struct ipv6_pinfo *np = inet6_sk(sk);
|
||||
|
@ -426,7 +426,7 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
|
||||
struct dst_entry *dst = NULL;
|
||||
union sctp_addr *daddr = &t->ipaddr;
|
||||
union sctp_addr dst_saddr;
|
||||
__u8 tos = inet_sk(sk)->tos;
|
||||
u8 tos = READ_ONCE(inet_sk(sk)->tos);
|
||||
|
||||
if (t->dscp & SCTP_DSCP_SET_MASK)
|
||||
tos = t->dscp & SCTP_DSCP_VAL_MASK;
|
||||
@ -1057,7 +1057,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb, struct sctp_transport *t)
|
||||
struct flowi4 *fl4 = &t->fl.u.ip4;
|
||||
struct sock *sk = skb->sk;
|
||||
struct inet_sock *inet = inet_sk(sk);
|
||||
__u8 dscp = inet->tos;
|
||||
__u8 dscp = READ_ONCE(inet->tos);
|
||||
__be16 df = 0;
|
||||
|
||||
pr_debug("%s: skb:%p, len:%d, src:%pI4, dst:%pI4\n", __func__, skb,
|
||||
|
@ -716,7 +716,7 @@ run_test_transparent()
|
||||
# the required infrastructure in MPTCP sockopt code. To support TOS, the
|
||||
# following function has been exported (T). Not great but better than
|
||||
# checking for a specific kernel version.
|
||||
if ! mptcp_lib_kallsyms_has "T __ip_sock_set_tos$"; then
|
||||
if ! mptcp_lib_kallsyms_has "T ip_sock_set_tos$"; then
|
||||
echo "INFO: ${msg} not supported by the kernel: SKIP"
|
||||
mptcp_lib_result_skip "${TEST_GROUP}"
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user