Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Ethan Ferguson
Mon, 16 Nov 2026 17:55
[PATCH net-next v2] net: remove CONFIG_NETDEVICES requirement for SO_BINDTODEVICE and SO_BINDTOIFINDEX
Author: Ethan Ferguson
Date: Mon, 16 Nov 2026 17:55
Date: Mon, 16 Nov 2026 17:55
166 lines
14554 bytes
14554 bytes
The SO_BINDTODEVICE and SO_BINDTOIFINDEX sockopts return -ENOPROTOOPT
if CONFIG_NETDEVICES is disabled, but the lo interface still exists.
I believe that these sockopts should not fail on the lo device just
because there are no other net devices.
Signed-off-by: Ethan Ferguson <ethanf108@gmail.com>
---
v2:
- Reverse xmas tree
- Use net-next tree
v1: https://lore.kernel.org/netdev/20261110204524.82341-1-ethanf108@gmail.com/
net/core/sock.c | 61 ++++++++++++++-----------------------------------
1 file changed, 17 insertions(+), 44 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index e529ffeaedb9..4225e0569125 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -635,18 +635,14 @@ EXPORT_SYMBOL(sk_dst_check);
static int sock_bindtoindex_locked(struct sock *sk, int ifindex)
{
- int ret = -ENOPROTOOPT;
-#ifdef CONFIG_NETDEVICES
struct net *net = sock_net(sk);
/* Sorry... */
- ret = -EPERM;
if (sk->sk_bound_dev_if && !ns_capable(net->user_ns, CAP_NET_RAW))
- goto out;
+ return -EPERM;
- ret = -EINVAL;
if (ifindex < 0)
- goto out;
+ return -EINVAL;
/* Paired with all READ_ONCE() done locklessly. */
WRITE_ONCE(sk->sk_bound_dev_if, ifindex);
@@ -655,12 +651,7 @@ static int sock_bindtoindex_locked(struct sock *sk, int ifindex)
sk->sk_prot->rehash(sk);
sk_dst_reset(sk);
- ret = 0;
-
-out:
-#endif
-
- return ret;
+ return 0;
}
int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk)
@@ -679,48 +670,40 @@ EXPORT_SYMBOL(sock_bindtoindex);
static int sock_setbindtodevice(struct sock *sk, sockptr_t optval, int optlen)
{
- int ret = -ENOPROTOOPT;
-#ifdef CONFIG_NETDEVICES
struct net *net = sock_net(sk);
+ struct net_device *dev;
char devname[IFNAMSIZ];
- int index;
+ int ret, index;
- ret = -EINVAL;
if (optlen < 0)
- goto out;
+ return -EINVAL;
/* Bind this socket to a particular device like "eth0",
* as specified in the passed interface name. If the
* name is "" or the option length is zero the socket
- * is not bound.
+ * is unbound.
*/
if (optlen > IFNAMSIZ - 1)
optlen = IFNAMSIZ - 1;
memset(devname, 0, sizeof(devname));
- ret = -EFAULT;
if (copy_from_sockptr(devname, optval, optlen))
- goto out;
+ return -EFAULT;
index = 0;
if (devname[0] != '\0') {
- struct net_device *dev;
-
rcu_read_lock();
dev = dev_get_by_name_rcu(net, devname);
if (dev)
index = dev->ifindex;
rcu_read_unlock();
- ret = -ENODEV;
if (!dev)
- goto out;
+ return -ENODEV;
}
sockopt_lock_sock(sk);
ret = sock_bindtoindex_locked(sk, index);
sockopt_release_sock(sk);
-out:
-#endif
return ret;
}
@@ -728,42 +711,32 @@ static int sock_setbindtodevice(struct sock *sk, sockptr_t optval, int optlen)
static int sock_getbindtodevice(struct sock *sk, sockptr_t optval,
sockptr_t optlen, int len)
{
- int ret = -ENOPROTOOPT;
-#ifdef CONFIG_NETDEVICES
- int bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
+ int ret, bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
struct net *net = sock_net(sk);
char devname[IFNAMSIZ];
if (bound_dev_if == 0) {
len = 0;
- goto zero;
+ goto copy_len;
}
- ret = -EINVAL;
if (len < IFNAMSIZ)
- goto out;
+ return -EINVAL;
ret = netdev_get_name(net, devname, bound_dev_if);
if (ret)
- goto out;
+ return ret;
len = strlen(devname) + 1;
- ret = -EFAULT;
if (copy_to_sockptr(optval, devname, len))
- goto out;
+ return -EFAULT;
-zero:
- ret = -EFAULT;
+copy_len:
if (copy_to_sockptr(optlen, &len, sizeof(int)))
- goto out;
-
- ret = 0;
-
-out:
-#endif
+ return -EFAULT;
- return ret;
+ return 0;
}
bool sk_mc_loop(const struct sock *sk)
base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
--
2.56.1
Re: [PATCH net-next v2] net: remove CONFIG_NETDEVICES requirement for SO_BINDTODEVICE and SO_BINDTOIFINDEX
Author: patchwork-bot+netdevbpf
Date: Fri, 20 Nov 2026 02:30
Date: Fri, 20 Nov 2026 02:30
24 lines
8697 bytes
8697 bytes
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 16 Nov 2026 12:55:04 -0500 you wrote:
> The SO_BINDTODEVICE and SO_BINDTOIFINDEX sockopts return -ENOPROTOOPT
> if CONFIG_NETDEVICES is disabled, but the lo interface still exists.
> I believe that these sockopts should not fail on the lo device just
> because there are no other net devices.
>
> Signed-off-by: Ethan Ferguson <ethanf108@gmail.com>
>
> [...]
Here is the summary with links:
- [net-next,v2] net: remove CONFIG_NETDEVICES requirement for SO_BINDTODEVICE and SO_BINDTOIFINDEX
https://git.kernel.org/netdev/net-next/c/f69dfe594053
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads