xref: /openbmc/linux/include/net/raw.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * INET		An implementation of the TCP/IP protocol suite for the LINUX
41da177e4SLinus Torvalds  *		operating system.  INET is implemented using the  BSD Socket
51da177e4SLinus Torvalds  *		interface as the means of communication with the user level.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *		Definitions for the RAW-IP module.
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * Version:	@(#)raw.h	1.0.2	05/07/93
101da177e4SLinus Torvalds  *
111da177e4SLinus Torvalds  * Author:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
121da177e4SLinus Torvalds  */
131da177e4SLinus Torvalds #ifndef _RAW_H
141da177e4SLinus Torvalds #define _RAW_H
151da177e4SLinus Torvalds 
167055420fSDuncan Eastoe #include <net/inet_sock.h>
1714c85021SArnaldo Carvalho de Melo #include <net/protocol.h>
186579f5baSEric Dumazet #include <net/netns/hash.h>
196579f5baSEric Dumazet #include <linux/hash.h>
20f74e49b5SPatrick McHardy #include <linux/icmp.h>
2114c85021SArnaldo Carvalho de Melo 
221da177e4SLinus Torvalds extern struct proto raw_prot;
231da177e4SLinus Torvalds 
24432490f9SCyrill Gorcunov extern struct raw_hashinfo raw_v4_hashinfo;
250a8c2568SEric Dumazet bool raw_v4_match(struct net *net, const struct sock *sk, unsigned short num,
26ba44f818SEric Dumazet 		  __be32 raddr, __be32 laddr, int dif, int sdif);
27432490f9SCyrill Gorcunov 
28432490f9SCyrill Gorcunov int raw_abort(struct sock *sk, int err);
297bc54c90SPavel Emelyanov void raw_icmp_error(struct sk_buff *, int, u32);
307bc54c90SPavel Emelyanov int raw_local_deliver(struct sk_buff *, int);
317bc54c90SPavel Emelyanov 
320ad6ad94SJoe Perches int raw_rcv(struct sock *, struct sk_buff *);
331da177e4SLinus Torvalds 
346579f5baSEric Dumazet #define RAW_HTABLE_LOG	8
356579f5baSEric Dumazet #define RAW_HTABLE_SIZE	(1U << RAW_HTABLE_LOG)
36b673e4dfSPavel Emelyanov 
37b673e4dfSPavel Emelyanov struct raw_hashinfo {
38af185d8cSEric Dumazet 	spinlock_t lock;
396579f5baSEric Dumazet 
40*0a78cf72SKuniyuki Iwashima 	struct hlist_head ht[RAW_HTABLE_SIZE] ____cacheline_aligned;
41b673e4dfSPavel Emelyanov };
42b673e4dfSPavel Emelyanov 
raw_hashfunc(const struct net * net,u32 proto)436579f5baSEric Dumazet static inline u32 raw_hashfunc(const struct net *net, u32 proto)
446579f5baSEric Dumazet {
456579f5baSEric Dumazet 	return hash_32(net_hash_mix(net) ^ proto, RAW_HTABLE_LOG);
466579f5baSEric Dumazet }
476579f5baSEric Dumazet 
raw_hashinfo_init(struct raw_hashinfo * hashinfo)480daf07e5SEric Dumazet static inline void raw_hashinfo_init(struct raw_hashinfo *hashinfo)
490daf07e5SEric Dumazet {
500daf07e5SEric Dumazet 	int i;
510daf07e5SEric Dumazet 
52af185d8cSEric Dumazet 	spin_lock_init(&hashinfo->lock);
530daf07e5SEric Dumazet 	for (i = 0; i < RAW_HTABLE_SIZE; i++)
54*0a78cf72SKuniyuki Iwashima 		INIT_HLIST_HEAD(&hashinfo->ht[i]);
550daf07e5SEric Dumazet }
560daf07e5SEric Dumazet 
5720380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS
580ad6ad94SJoe Perches int raw_proc_init(void);
590ad6ad94SJoe Perches void raw_proc_exit(void);
6042a73808SPavel Emelyanov 
6142a73808SPavel Emelyanov struct raw_iter_state {
62f51d599fSPavel Emelyanov 	struct seq_net_private p;
6342a73808SPavel Emelyanov 	int bucket;
6442a73808SPavel Emelyanov };
6542a73808SPavel Emelyanov 
raw_seq_private(struct seq_file * seq)66e3634169SJoe Perches static inline struct raw_iter_state *raw_seq_private(struct seq_file *seq)
67e3634169SJoe Perches {
68e3634169SJoe Perches 	return seq->private;
69e3634169SJoe Perches }
7042a73808SPavel Emelyanov void *raw_seq_start(struct seq_file *seq, loff_t *pos);
7142a73808SPavel Emelyanov void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos);
7242a73808SPavel Emelyanov void raw_seq_stop(struct seq_file *seq, void *v);
7320380731SArnaldo Carvalho de Melo #endif
7420380731SArnaldo Carvalho de Melo 
75086c653fSCraig Gallek int raw_hash_sk(struct sock *sk);
76fc8717baSPavel Emelyanov void raw_unhash_sk(struct sock *sk);
776897445fSMike Manning void raw_init(void);
7865b4c50bSPavel Emelyanov 
79f74e49b5SPatrick McHardy struct raw_sock {
80f74e49b5SPatrick McHardy 	/* inet_sock has to be the first member */
81f74e49b5SPatrick McHardy 	struct inet_sock   inet;
82f74e49b5SPatrick McHardy 	struct icmp_filter filter;
83f0ad0860SPatrick McHardy 	u32		   ipmr_table;
84f74e49b5SPatrick McHardy };
85f74e49b5SPatrick McHardy 
860a2db463SEric Dumazet #define raw_sk(ptr) container_of_const(ptr, struct raw_sock, inet.sk)
87f74e49b5SPatrick McHardy 
raw_sk_bound_dev_eq(struct net * net,int bound_dev_if,int dif,int sdif)887055420fSDuncan Eastoe static inline bool raw_sk_bound_dev_eq(struct net *net, int bound_dev_if,
897055420fSDuncan Eastoe 				       int dif, int sdif)
907055420fSDuncan Eastoe {
917055420fSDuncan Eastoe #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
921dace014SKuniyuki Iwashima 	return inet_bound_dev_eq(READ_ONCE(net->ipv4.sysctl_raw_l3mdev_accept),
937055420fSDuncan Eastoe 				 bound_dev_if, dif, sdif);
947055420fSDuncan Eastoe #else
957055420fSDuncan Eastoe 	return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
967055420fSDuncan Eastoe #endif
977055420fSDuncan Eastoe }
987055420fSDuncan Eastoe 
991da177e4SLinus Torvalds #endif	/* _RAW_H */
100