net: Introduce __inet_bind() and __inet6_bind
authorAndrey Ignatov <rdna@fb.com>
Fri, 30 Mar 2018 22:08:04 +0000 (15:08 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Sat, 31 Mar 2018 00:15:43 +0000 (02:15 +0200)
commit3679d585bbc07a1ac4448d5b478b492cad3587ce
tree15cfea104f4ee4dcb55005a2ca101631eefa3f2f
parente50b0a6f089308bec6b2d0198abed231dee4d277
net: Introduce __inet_bind() and __inet6_bind

Refactor `bind()` code to make it ready to be called from BPF helper
function `bpf_bind()` (will be added soon). Implementation of
`inet_bind()` and `inet6_bind()` is separated into `__inet_bind()` and
`__inet6_bind()` correspondingly. These function can be used from both
`sk_prot->bind` and `bpf_bind()` contexts.

New functions have two additional arguments.

`force_bind_address_no_port` forces binding to IP only w/o checking
`inet_sock.bind_address_no_port` field. It'll allow to bind local end of
a connection to desired IP in `bpf_bind()` w/o changing
`bind_address_no_port` field of a socket. It's useful since `bpf_bind()`
can return an error and we'd need to restore original value of
`bind_address_no_port` in that case if we changed this before calling to
the helper.

`with_lock` specifies whether to lock socket when working with `struct
sk` or not. The argument is set to `true` for `sk_prot->bind`, i.e. old
behavior is preserved. But it will be set to `false` for `bpf_bind()`
use-case. The reason is all call-sites, where `bpf_bind()` will be
called, already hold that socket lock.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/net/inet_common.h
include/net/ipv6.h
net/ipv4/af_inet.c
net/ipv6/af_inet6.c