xref: /openbmc/linux/include/net/protocol.h (revision dfd56b8b)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * INET		An implementation of the TCP/IP protocol suite for the LINUX
31da177e4SLinus Torvalds  *		operating system.  INET is implemented using the  BSD Socket
41da177e4SLinus Torvalds  *		interface as the means of communication with the user level.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *		Definitions for the protocol dispatcher.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Version:	@(#)protocol.h	1.0.2	05/07/93
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * Author:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *		This program is free software; you can redistribute it and/or
131da177e4SLinus Torvalds  *		modify it under the terms of the GNU General Public License
141da177e4SLinus Torvalds  *		as published by the Free Software Foundation; either version
151da177e4SLinus Torvalds  *		2 of the License, or (at your option) any later version.
161da177e4SLinus Torvalds  *
171da177e4SLinus Torvalds  *	Changes:
181da177e4SLinus Torvalds  *		Alan Cox	:	Added a name field and a frag handler
191da177e4SLinus Torvalds  *					field for later.
201da177e4SLinus Torvalds  *		Alan Cox	:	Cleaned up, and sorted types.
211da177e4SLinus Torvalds  *		Pedro Roque	:	inet6 protocols
221da177e4SLinus Torvalds  */
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds #ifndef _PROTOCOL_H
251da177e4SLinus Torvalds #define _PROTOCOL_H
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #include <linux/in6.h>
28dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6)
291da177e4SLinus Torvalds #include <linux/ipv6.h>
301da177e4SLinus Torvalds #endif
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds #define MAX_INET_PROTOS	256		/* Must be a power of 2		*/
331da177e4SLinus Torvalds 
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds /* This is used to register protocols. */
361da177e4SLinus Torvalds struct net_protocol {
371da177e4SLinus Torvalds 	int			(*handler)(struct sk_buff *skb);
381da177e4SLinus Torvalds 	void			(*err_handler)(struct sk_buff *skb, u32 info);
39a430a43dSHerbert Xu 	int			(*gso_send_check)(struct sk_buff *skb);
40576a30ebSHerbert Xu 	struct sk_buff	       *(*gso_segment)(struct sk_buff *skb,
41c8f44affSMichał Mirosław 					       netdev_features_t features);
4273cc19f1SHerbert Xu 	struct sk_buff	      **(*gro_receive)(struct sk_buff **head,
4373cc19f1SHerbert Xu 					       struct sk_buff *skb);
4473cc19f1SHerbert Xu 	int			(*gro_complete)(struct sk_buff *skb);
45f145049aSDenis V. Lunev 	unsigned int		no_policy:1,
46f145049aSDenis V. Lunev 				netns_ok:1;
471da177e4SLinus Torvalds };
481da177e4SLinus Torvalds 
49dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6)
50fd2c3ef7SEric Dumazet struct inet6_protocol {
51e5bbef20SHerbert Xu 	int	(*handler)(struct sk_buff *skb);
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds 	void	(*err_handler)(struct sk_buff *skb,
541da177e4SLinus Torvalds 			       struct inet6_skb_parm *opt,
55d5fdd6baSBrian Haley 			       u8 type, u8 code, int offset,
5604ce6909SAl Viro 			       __be32 info);
57adcfc7d0SHerbert Xu 
58a430a43dSHerbert Xu 	int	(*gso_send_check)(struct sk_buff *skb);
59adcfc7d0SHerbert Xu 	struct sk_buff *(*gso_segment)(struct sk_buff *skb,
60c8f44affSMichał Mirosław 				       netdev_features_t features);
61787e9208SHerbert Xu 	struct sk_buff **(*gro_receive)(struct sk_buff **head,
62787e9208SHerbert Xu 					struct sk_buff *skb);
63787e9208SHerbert Xu 	int	(*gro_complete)(struct sk_buff *skb);
64adcfc7d0SHerbert Xu 
651da177e4SLinus Torvalds 	unsigned int	flags;	/* INET6_PROTO_xxx */
661da177e4SLinus Torvalds };
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #define INET6_PROTO_NOPOLICY	0x1
691da177e4SLinus Torvalds #define INET6_PROTO_FINAL	0x2
70adcfc7d0SHerbert Xu /* This should be set for any extension header which is compatible with GSO. */
71adcfc7d0SHerbert Xu #define INET6_PROTO_GSO_EXTHDR	0x4
721da177e4SLinus Torvalds #endif
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds /* This is used to register socket interfaces for IP protocols.  */
751da177e4SLinus Torvalds struct inet_protosw {
761da177e4SLinus Torvalds 	struct list_head list;
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds         /* These two fields form the lookup key.  */
791da177e4SLinus Torvalds 	unsigned short	 type;	   /* This is the 2nd argument to socket(2). */
80ee41e2dfSArnaldo Carvalho de Melo 	unsigned short	 protocol; /* This is the L4 protocol number.  */
811da177e4SLinus Torvalds 
821da177e4SLinus Torvalds 	struct proto	 *prot;
8390ddc4f0SEric Dumazet 	const struct proto_ops *ops;
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds 	char             no_check;   /* checksum on rcv/xmit/none? */
861da177e4SLinus Torvalds 	unsigned char	 flags;      /* See INET_PROTOSW_* below.  */
871da177e4SLinus Torvalds };
881da177e4SLinus Torvalds #define INET_PROTOSW_REUSE 0x01	     /* Are ports automatically reusable? */
891da177e4SLinus Torvalds #define INET_PROTOSW_PERMANENT 0x02  /* Permanent protocols are unremovable. */
90d83d8461SArnaldo Carvalho de Melo #define INET_PROTOSW_ICSK      0x04  /* Is this an inet_connection_sock? */
911da177e4SLinus Torvalds 
92e0ad61ecSEric Dumazet extern const struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS];
931da177e4SLinus Torvalds 
94dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6)
95e0ad61ecSEric Dumazet extern const struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS];
961da177e4SLinus Torvalds #endif
971da177e4SLinus Torvalds 
9832613090SAlexey Dobriyan extern int	inet_add_protocol(const struct net_protocol *prot, unsigned char num);
9932613090SAlexey Dobriyan extern int	inet_del_protocol(const struct net_protocol *prot, unsigned char num);
1001da177e4SLinus Torvalds extern void	inet_register_protosw(struct inet_protosw *p);
1011da177e4SLinus Torvalds extern void	inet_unregister_protosw(struct inet_protosw *p);
1021da177e4SLinus Torvalds 
103dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6)
10441135cc8SAlexey Dobriyan extern int	inet6_add_protocol(const struct inet6_protocol *prot, unsigned char num);
10541135cc8SAlexey Dobriyan extern int	inet6_del_protocol(const struct inet6_protocol *prot, unsigned char num);
10687c3efbfSDaniel Lezcano extern int	inet6_register_protosw(struct inet_protosw *p);
1071da177e4SLinus Torvalds extern void	inet6_unregister_protosw(struct inet_protosw *p);
1081da177e4SLinus Torvalds #endif
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds #endif	/* _PROTOCOL_H */
111