Message ID | 508123AC.5080208@parallels.com |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
On Fri, 2012-10-19 at 13:55 +0400, Pavel Emelyanov wrote: > The SO_BINDTODEVICE option is the only SOL_SOCKET one that can be set, but > cannot be get via sockopt API. The only way we can find the device id a > socket is bound to is via sock-diag interface. But the diag works only on > hashed sockets, while the opt in question can be set for yet unhashed one. > > That said, in order to know what device a socket is bound to (we do want > to know this in checkpoint-restore project) I propose to make this option > getsockopt-able and report the respective device index. > > Another solution to the problem might be to teach the sock-diag reporting > info on unhashed sockets. Should I go this way instead? > > Signed-off-by: Pavel Emelyanov <xemul@parallels.com> > > --- > > diff --git a/net/core/sock.c b/net/core/sock.c > index 8a146cf..c49412c 100644 > --- a/net/core/sock.c > +++ b/net/core/sock.c > @@ -1074,6 +1074,9 @@ int sock_getsockopt(struct socket *sock, int level, int optname, > case SO_NOFCS: > v.val = sock_flag(sk, SOCK_NOFCS); > break; > + case SO_BINDTODEVICE: > + v.val = sk->sk_bound_dev_if; > + break; > default: > return -ENOPROTOOPT; > } This looks quite reasonable to me. Acked-by: Eric Dumazet <edumazet@google.com> -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Pavel Emelyanov <xemul@parallels.com> Date: Fri, 19 Oct 2012 13:55:56 +0400 > The SO_BINDTODEVICE option is the only SOL_SOCKET one that can be set, but > cannot be get via sockopt API. The only way we can find the device id a > socket is bound to is via sock-diag interface. But the diag works only on > hashed sockets, while the opt in question can be set for yet unhashed one. > > That said, in order to know what device a socket is bound to (we do want > to know this in checkpoint-restore project) I propose to make this option > getsockopt-able and report the respective device index. > > Another solution to the problem might be to teach the sock-diag reporting > info on unhashed sockets. Should I go this way instead? > > Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Applied. I can't believe we didn't support this when the feature was added. I guess we figured that if the application made this setting, then it knows and doesn't need to query it. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 10/22/2012 04:43 AM, David Miller wrote: > From: Pavel Emelyanov <xemul@parallels.com> > Date: Fri, 19 Oct 2012 13:55:56 +0400 > >> The SO_BINDTODEVICE option is the only SOL_SOCKET one that can be set, but >> cannot be get via sockopt API. The only way we can find the device id a >> socket is bound to is via sock-diag interface. But the diag works only on >> hashed sockets, while the opt in question can be set for yet unhashed one. >> >> That said, in order to know what device a socket is bound to (we do want >> to know this in checkpoint-restore project) I propose to make this option >> getsockopt-able and report the respective device index. >> >> Another solution to the problem might be to teach the sock-diag reporting >> info on unhashed sockets. Should I go this way instead? >> >> Signed-off-by: Pavel Emelyanov <xemul@parallels.com> > > Applied. I can't believe we didn't support this when the feature > was added. > > I guess we figured that if the application made this setting, then > it knows and doesn't need to query it. > . AFAIS such decision (application that configures something knows what it is) was made for many things. The same is true at least for the SO_ATTACH_FILTER option and for the shutdown syscall. Both add something to a socket that cannot be queried back. And I'm now thinking which way for getting one would be better. Thanks, Pavel -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/net/core/sock.c b/net/core/sock.c index 8a146cf..c49412c 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1074,6 +1074,9 @@ int sock_getsockopt(struct socket *sock, int level, int optname, case SO_NOFCS: v.val = sock_flag(sk, SOCK_NOFCS); break; + case SO_BINDTODEVICE: + v.val = sk->sk_bound_dev_if; + break; default: return -ENOPROTOOPT; }
The SO_BINDTODEVICE option is the only SOL_SOCKET one that can be set, but cannot be get via sockopt API. The only way we can find the device id a socket is bound to is via sock-diag interface. But the diag works only on hashed sockets, while the opt in question can be set for yet unhashed one. That said, in order to know what device a socket is bound to (we do want to know this in checkpoint-restore project) I propose to make this option getsockopt-able and report the respective device index. Another solution to the problem might be to teach the sock-diag reporting info on unhashed sockets. Should I go this way instead? Signed-off-by: Pavel Emelyanov <xemul@parallels.com> --- -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html