18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _INET_COMMON_H
38c2ecf20Sopenharmony_ci#define _INET_COMMON_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/indirect_call_wrapper.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciextern const struct proto_ops inet_stream_ops;
88c2ecf20Sopenharmony_ciextern const struct proto_ops inet_dgram_ops;
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci *	INET4 prototypes used by INET6
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct msghdr;
158c2ecf20Sopenharmony_cistruct sock;
168c2ecf20Sopenharmony_cistruct sockaddr;
178c2ecf20Sopenharmony_cistruct socket;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciint inet_release(struct socket *sock);
208c2ecf20Sopenharmony_ciint inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
218c2ecf20Sopenharmony_ci			int addr_len, int flags);
228c2ecf20Sopenharmony_ciint __inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
238c2ecf20Sopenharmony_ci			  int addr_len, int flags, int is_sendmsg);
248c2ecf20Sopenharmony_ciint inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
258c2ecf20Sopenharmony_ci		       int addr_len, int flags);
268c2ecf20Sopenharmony_ciint inet_accept(struct socket *sock, struct socket *newsock, int flags,
278c2ecf20Sopenharmony_ci		bool kern);
288c2ecf20Sopenharmony_ciint inet_send_prepare(struct sock *sk);
298c2ecf20Sopenharmony_ciint inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size);
308c2ecf20Sopenharmony_cissize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
318c2ecf20Sopenharmony_ci		      size_t size, int flags);
328c2ecf20Sopenharmony_ciint inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
338c2ecf20Sopenharmony_ci		 int flags);
348c2ecf20Sopenharmony_ciint inet_shutdown(struct socket *sock, int how);
358c2ecf20Sopenharmony_ciint inet_listen(struct socket *sock, int backlog);
368c2ecf20Sopenharmony_civoid inet_sock_destruct(struct sock *sk);
378c2ecf20Sopenharmony_ciint inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len);
388c2ecf20Sopenharmony_ci/* Don't allocate port at this moment, defer to connect. */
398c2ecf20Sopenharmony_ci#define BIND_FORCE_ADDRESS_NO_PORT	(1 << 0)
408c2ecf20Sopenharmony_ci/* Grab and release socket lock. */
418c2ecf20Sopenharmony_ci#define BIND_WITH_LOCK			(1 << 1)
428c2ecf20Sopenharmony_ci/* Called from BPF program. */
438c2ecf20Sopenharmony_ci#define BIND_FROM_BPF			(1 << 2)
448c2ecf20Sopenharmony_ciint __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
458c2ecf20Sopenharmony_ci		u32 flags);
468c2ecf20Sopenharmony_ciint inet_getname(struct socket *sock, struct sockaddr *uaddr,
478c2ecf20Sopenharmony_ci		 int peer);
488c2ecf20Sopenharmony_ciint inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
498c2ecf20Sopenharmony_ciint inet_ctl_sock_create(struct sock **sk, unsigned short family,
508c2ecf20Sopenharmony_ci			 unsigned short type, unsigned char protocol,
518c2ecf20Sopenharmony_ci			 struct net *net);
528c2ecf20Sopenharmony_ciint inet_recv_error(struct sock *sk, struct msghdr *msg, int len,
538c2ecf20Sopenharmony_ci		    int *addr_len);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistruct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb);
568c2ecf20Sopenharmony_ciint inet_gro_complete(struct sk_buff *skb, int nhoff);
578c2ecf20Sopenharmony_cistruct sk_buff *inet_gso_segment(struct sk_buff *skb,
588c2ecf20Sopenharmony_ci				 netdev_features_t features);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline void inet_ctl_sock_destroy(struct sock *sk)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	if (sk)
638c2ecf20Sopenharmony_ci		sock_release(sk->sk_socket);
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define indirect_call_gro_receive(f2, f1, cb, head, skb)	\
678c2ecf20Sopenharmony_ci({								\
688c2ecf20Sopenharmony_ci	unlikely(gro_recursion_inc_test(skb)) ?			\
698c2ecf20Sopenharmony_ci		NAPI_GRO_CB(skb)->flush |= 1, NULL :		\
708c2ecf20Sopenharmony_ci		INDIRECT_CALL_2(cb, f2, f1, head, skb);		\
718c2ecf20Sopenharmony_ci})
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#endif
74