forked from luck/tmp_suning_uos_patched
3679d585bb
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>
58 lines
2.0 KiB
C
58 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _INET_COMMON_H
|
|
#define _INET_COMMON_H
|
|
|
|
extern const struct proto_ops inet_stream_ops;
|
|
extern const struct proto_ops inet_dgram_ops;
|
|
|
|
/*
|
|
* INET4 prototypes used by INET6
|
|
*/
|
|
|
|
struct msghdr;
|
|
struct sock;
|
|
struct sockaddr;
|
|
struct socket;
|
|
|
|
int inet_release(struct socket *sock);
|
|
int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
|
|
int addr_len, int flags);
|
|
int __inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
|
|
int addr_len, int flags, int is_sendmsg);
|
|
int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
|
|
int addr_len, int flags);
|
|
int inet_accept(struct socket *sock, struct socket *newsock, int flags,
|
|
bool kern);
|
|
int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size);
|
|
ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
|
|
size_t size, int flags);
|
|
int inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
|
|
int flags);
|
|
int inet_shutdown(struct socket *sock, int how);
|
|
int inet_listen(struct socket *sock, int backlog);
|
|
void inet_sock_destruct(struct sock *sk);
|
|
int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);
|
|
int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
|
|
bool force_bind_address_no_port, bool with_lock);
|
|
int inet_getname(struct socket *sock, struct sockaddr *uaddr,
|
|
int peer);
|
|
int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
|
|
int inet_ctl_sock_create(struct sock **sk, unsigned short family,
|
|
unsigned short type, unsigned char protocol,
|
|
struct net *net);
|
|
int inet_recv_error(struct sock *sk, struct msghdr *msg, int len,
|
|
int *addr_len);
|
|
|
|
struct sk_buff **inet_gro_receive(struct sk_buff **head, struct sk_buff *skb);
|
|
int inet_gro_complete(struct sk_buff *skb, int nhoff);
|
|
struct sk_buff *inet_gso_segment(struct sk_buff *skb,
|
|
netdev_features_t features);
|
|
|
|
static inline void inet_ctl_sock_destroy(struct sock *sk)
|
|
{
|
|
if (sk)
|
|
sock_release(sk->sk_socket);
|
|
}
|
|
|
|
#endif
|