18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * INET		An implementation of the TCP/IP protocol suite for the LINUX
48c2ecf20Sopenharmony_ci *		operating system.  INET is implemented using the  BSD Socket
58c2ecf20Sopenharmony_ci *		interface as the means of communication with the user level.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *		Definitions for the RAW-IP module.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Version:	@(#)raw.h	1.0.2	05/07/93
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * Author:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci#ifndef _RAW_H
148c2ecf20Sopenharmony_ci#define _RAW_H
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <net/inet_sock.h>
178c2ecf20Sopenharmony_ci#include <net/protocol.h>
188c2ecf20Sopenharmony_ci#include <linux/icmp.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciextern struct proto raw_prot;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciextern struct raw_hashinfo raw_v4_hashinfo;
238c2ecf20Sopenharmony_cistruct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
248c2ecf20Sopenharmony_ci			     unsigned short num, __be32 raddr,
258c2ecf20Sopenharmony_ci			     __be32 laddr, int dif, int sdif);
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciint raw_abort(struct sock *sk, int err);
288c2ecf20Sopenharmony_civoid raw_icmp_error(struct sk_buff *, int, u32);
298c2ecf20Sopenharmony_ciint raw_local_deliver(struct sk_buff *, int);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciint raw_rcv(struct sock *, struct sk_buff *);
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define RAW_HTABLE_SIZE	MAX_INET_PROTOS
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistruct raw_hashinfo {
368c2ecf20Sopenharmony_ci	rwlock_t lock;
378c2ecf20Sopenharmony_ci	struct hlist_head ht[RAW_HTABLE_SIZE];
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#ifdef CONFIG_PROC_FS
418c2ecf20Sopenharmony_ciint raw_proc_init(void);
428c2ecf20Sopenharmony_civoid raw_proc_exit(void);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistruct raw_iter_state {
458c2ecf20Sopenharmony_ci	struct seq_net_private p;
468c2ecf20Sopenharmony_ci	int bucket;
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic inline struct raw_iter_state *raw_seq_private(struct seq_file *seq)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	return seq->private;
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_civoid *raw_seq_start(struct seq_file *seq, loff_t *pos);
548c2ecf20Sopenharmony_civoid *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos);
558c2ecf20Sopenharmony_civoid raw_seq_stop(struct seq_file *seq, void *v);
568c2ecf20Sopenharmony_ci#endif
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciint raw_hash_sk(struct sock *sk);
598c2ecf20Sopenharmony_civoid raw_unhash_sk(struct sock *sk);
608c2ecf20Sopenharmony_civoid raw_init(void);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct raw_sock {
638c2ecf20Sopenharmony_ci	/* inet_sock has to be the first member */
648c2ecf20Sopenharmony_ci	struct inet_sock   inet;
658c2ecf20Sopenharmony_ci	struct icmp_filter filter;
668c2ecf20Sopenharmony_ci	u32		   ipmr_table;
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic inline struct raw_sock *raw_sk(const struct sock *sk)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	return (struct raw_sock *)sk;
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic inline bool raw_sk_bound_dev_eq(struct net *net, int bound_dev_if,
758c2ecf20Sopenharmony_ci				       int dif, int sdif)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
788c2ecf20Sopenharmony_ci	return inet_bound_dev_eq(READ_ONCE(net->ipv4.sysctl_raw_l3mdev_accept),
798c2ecf20Sopenharmony_ci				 bound_dev_if, dif, sdif);
808c2ecf20Sopenharmony_ci#else
818c2ecf20Sopenharmony_ci	return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
828c2ecf20Sopenharmony_ci#endif
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#endif	/* _RAW_H */
86