Skip to content

Commit

Permalink
inet: lockless getsockopt(IP_MTU)
Browse files Browse the repository at this point in the history
sk_dst_get() does not require socket lock.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Oct 1, 2023
1 parent a4725d0 commit 3523bc9
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1620,13 +1620,6 @@ 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_MTU:
{
struct dst_entry *dst;
Expand All @@ -1636,12 +1629,17 @@ 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;
}
}

if (needs_rtnl)
rtnl_lock();
sockopt_lock_sock(sk);

switch (optname) {
case IP_UNICAST_IF:
val = (__force int)htonl((__u32) inet->uc_index);
break;
Expand Down

0 comments on commit 3523bc9

Please sign in to comment.