162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _INET_COMMON_H
362306a36Sopenharmony_ci#define _INET_COMMON_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/indirect_call_wrapper.h>
662306a36Sopenharmony_ci#include <linux/net.h>
762306a36Sopenharmony_ci#include <linux/netdev_features.h>
862306a36Sopenharmony_ci#include <linux/types.h>
962306a36Sopenharmony_ci#include <net/sock.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciextern const struct proto_ops inet_stream_ops;
1262306a36Sopenharmony_ciextern const struct proto_ops inet_dgram_ops;
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/*
1562306a36Sopenharmony_ci *	INET4 prototypes used by INET6
1662306a36Sopenharmony_ci */
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct msghdr;
1962306a36Sopenharmony_cistruct net;
2062306a36Sopenharmony_cistruct page;
2162306a36Sopenharmony_cistruct sock;
2262306a36Sopenharmony_cistruct sockaddr;
2362306a36Sopenharmony_cistruct socket;
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ciint inet_release(struct socket *sock);
2662306a36Sopenharmony_ciint inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
2762306a36Sopenharmony_ci			int addr_len, int flags);
2862306a36Sopenharmony_ciint __inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
2962306a36Sopenharmony_ci			  int addr_len, int flags, int is_sendmsg);
3062306a36Sopenharmony_ciint inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
3162306a36Sopenharmony_ci		       int addr_len, int flags);
3262306a36Sopenharmony_ciint inet_accept(struct socket *sock, struct socket *newsock, int flags,
3362306a36Sopenharmony_ci		bool kern);
3462306a36Sopenharmony_civoid __inet_accept(struct socket *sock, struct socket *newsock,
3562306a36Sopenharmony_ci		   struct sock *newsk);
3662306a36Sopenharmony_ciint inet_send_prepare(struct sock *sk);
3762306a36Sopenharmony_ciint inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size);
3862306a36Sopenharmony_civoid inet_splice_eof(struct socket *sock);
3962306a36Sopenharmony_ciint inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
4062306a36Sopenharmony_ci		 int flags);
4162306a36Sopenharmony_ciint inet_shutdown(struct socket *sock, int how);
4262306a36Sopenharmony_ciint inet_listen(struct socket *sock, int backlog);
4362306a36Sopenharmony_ciint __inet_listen_sk(struct sock *sk, int backlog);
4462306a36Sopenharmony_civoid inet_sock_destruct(struct sock *sk);
4562306a36Sopenharmony_ciint inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);
4662306a36Sopenharmony_ciint inet_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len);
4762306a36Sopenharmony_ci/* Don't allocate port at this moment, defer to connect. */
4862306a36Sopenharmony_ci#define BIND_FORCE_ADDRESS_NO_PORT	(1 << 0)
4962306a36Sopenharmony_ci/* Grab and release socket lock. */
5062306a36Sopenharmony_ci#define BIND_WITH_LOCK			(1 << 1)
5162306a36Sopenharmony_ci/* Called from BPF program. */
5262306a36Sopenharmony_ci#define BIND_FROM_BPF			(1 << 2)
5362306a36Sopenharmony_ci/* Skip CAP_NET_BIND_SERVICE check. */
5462306a36Sopenharmony_ci#define BIND_NO_CAP_NET_BIND_SERVICE	(1 << 3)
5562306a36Sopenharmony_ciint __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
5662306a36Sopenharmony_ci		u32 flags);
5762306a36Sopenharmony_ciint inet_getname(struct socket *sock, struct sockaddr *uaddr,
5862306a36Sopenharmony_ci		 int peer);
5962306a36Sopenharmony_ciint inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
6062306a36Sopenharmony_ciint inet_ctl_sock_create(struct sock **sk, unsigned short family,
6162306a36Sopenharmony_ci			 unsigned short type, unsigned char protocol,
6262306a36Sopenharmony_ci			 struct net *net);
6362306a36Sopenharmony_ciint inet_recv_error(struct sock *sk, struct msghdr *msg, int len,
6462306a36Sopenharmony_ci		    int *addr_len);
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_cistruct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb);
6762306a36Sopenharmony_ciint inet_gro_complete(struct sk_buff *skb, int nhoff);
6862306a36Sopenharmony_cistruct sk_buff *inet_gso_segment(struct sk_buff *skb,
6962306a36Sopenharmony_ci				 netdev_features_t features);
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_cistatic inline void inet_ctl_sock_destroy(struct sock *sk)
7262306a36Sopenharmony_ci{
7362306a36Sopenharmony_ci	if (sk)
7462306a36Sopenharmony_ci		sock_release(sk->sk_socket);
7562306a36Sopenharmony_ci}
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#define indirect_call_gro_receive(f2, f1, cb, head, skb)	\
7862306a36Sopenharmony_ci({								\
7962306a36Sopenharmony_ci	unlikely(gro_recursion_inc_test(skb)) ?			\
8062306a36Sopenharmony_ci		NAPI_GRO_CB(skb)->flush |= 1, NULL :		\
8162306a36Sopenharmony_ci		INDIRECT_CALL_2(cb, f2, f1, head, skb);		\
8262306a36Sopenharmony_ci})
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#endif
85