162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * INET An implementation of the TCP/IP protocol suite for the LINUX 462306a36Sopenharmony_ci * operating system. INET is implemented using the BSD Socket 562306a36Sopenharmony_ci * interface as the means of communication with the user level. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Definitions for the protocol dispatcher. 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Version: @(#)protocol.h 1.0.2 05/07/93 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * Changes: 1462306a36Sopenharmony_ci * Alan Cox : Added a name field and a frag handler 1562306a36Sopenharmony_ci * field for later. 1662306a36Sopenharmony_ci * Alan Cox : Cleaned up, and sorted types. 1762306a36Sopenharmony_ci * Pedro Roque : inet6 protocols 1862306a36Sopenharmony_ci */ 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#ifndef _PROTOCOL_H 2162306a36Sopenharmony_ci#define _PROTOCOL_H 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#include <linux/in6.h> 2462306a36Sopenharmony_ci#include <linux/skbuff.h> 2562306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 2662306a36Sopenharmony_ci#include <linux/ipv6.h> 2762306a36Sopenharmony_ci#endif 2862306a36Sopenharmony_ci#include <linux/netdevice.h> 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/* This is one larger than the largest protocol value that can be 3162306a36Sopenharmony_ci * found in an ipv4 or ipv6 header. Since in both cases the protocol 3262306a36Sopenharmony_ci * value is presented in a __u8, this is defined to be 256. 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ci#define MAX_INET_PROTOS 256 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/* This is used to register protocols. */ 3762306a36Sopenharmony_cistruct net_protocol { 3862306a36Sopenharmony_ci int (*handler)(struct sk_buff *skb); 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci /* This returns an error if we weren't able to handle the error. */ 4162306a36Sopenharmony_ci int (*err_handler)(struct sk_buff *skb, u32 info); 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci unsigned int no_policy:1, 4462306a36Sopenharmony_ci /* does the protocol do more stringent 4562306a36Sopenharmony_ci * icmp tag validation than simple 4662306a36Sopenharmony_ci * socket lookup? 4762306a36Sopenharmony_ci */ 4862306a36Sopenharmony_ci icmp_strict_tag_validation:1; 4962306a36Sopenharmony_ci}; 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 5262306a36Sopenharmony_cistruct inet6_protocol { 5362306a36Sopenharmony_ci int (*handler)(struct sk_buff *skb); 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci /* This returns an error if we weren't able to handle the error. */ 5662306a36Sopenharmony_ci int (*err_handler)(struct sk_buff *skb, 5762306a36Sopenharmony_ci struct inet6_skb_parm *opt, 5862306a36Sopenharmony_ci u8 type, u8 code, int offset, 5962306a36Sopenharmony_ci __be32 info); 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci unsigned int flags; /* INET6_PROTO_xxx */ 6262306a36Sopenharmony_ci}; 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci#define INET6_PROTO_NOPOLICY 0x1 6562306a36Sopenharmony_ci#define INET6_PROTO_FINAL 0x2 6662306a36Sopenharmony_ci#endif 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_cistruct net_offload { 6962306a36Sopenharmony_ci struct offload_callbacks callbacks; 7062306a36Sopenharmony_ci unsigned int flags; /* Flags used by IPv6 for now */ 7162306a36Sopenharmony_ci}; 7262306a36Sopenharmony_ci/* This should be set for any extension header which is compatible with GSO. */ 7362306a36Sopenharmony_ci#define INET6_PROTO_GSO_EXTHDR 0x1 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* This is used to register socket interfaces for IP protocols. */ 7662306a36Sopenharmony_cistruct inet_protosw { 7762306a36Sopenharmony_ci struct list_head list; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci /* These two fields form the lookup key. */ 8062306a36Sopenharmony_ci unsigned short type; /* This is the 2nd argument to socket(2). */ 8162306a36Sopenharmony_ci unsigned short protocol; /* This is the L4 protocol number. */ 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci struct proto *prot; 8462306a36Sopenharmony_ci const struct proto_ops *ops; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci unsigned char flags; /* See INET_PROTOSW_* below. */ 8762306a36Sopenharmony_ci}; 8862306a36Sopenharmony_ci#define INET_PROTOSW_REUSE 0x01 /* Are ports automatically reusable? */ 8962306a36Sopenharmony_ci#define INET_PROTOSW_PERMANENT 0x02 /* Permanent protocols are unremovable. */ 9062306a36Sopenharmony_ci#define INET_PROTOSW_ICSK 0x04 /* Is this an inet_connection_sock? */ 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ciextern struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS]; 9362306a36Sopenharmony_ciextern const struct net_offload __rcu *inet_offloads[MAX_INET_PROTOS]; 9462306a36Sopenharmony_ciextern const struct net_offload __rcu *inet6_offloads[MAX_INET_PROTOS]; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 9762306a36Sopenharmony_ciextern struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS]; 9862306a36Sopenharmony_ci#endif 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ciint inet_add_protocol(const struct net_protocol *prot, unsigned char num); 10162306a36Sopenharmony_ciint inet_del_protocol(const struct net_protocol *prot, unsigned char num); 10262306a36Sopenharmony_ciint inet_add_offload(const struct net_offload *prot, unsigned char num); 10362306a36Sopenharmony_ciint inet_del_offload(const struct net_offload *prot, unsigned char num); 10462306a36Sopenharmony_civoid inet_register_protosw(struct inet_protosw *p); 10562306a36Sopenharmony_civoid inet_unregister_protosw(struct inet_protosw *p); 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 10862306a36Sopenharmony_ciint inet6_add_protocol(const struct inet6_protocol *prot, unsigned char num); 10962306a36Sopenharmony_ciint inet6_del_protocol(const struct inet6_protocol *prot, unsigned char num); 11062306a36Sopenharmony_ciint inet6_register_protosw(struct inet_protosw *p); 11162306a36Sopenharmony_civoid inet6_unregister_protosw(struct inet_protosw *p); 11262306a36Sopenharmony_ci#endif 11362306a36Sopenharmony_ciint inet6_add_offload(const struct net_offload *prot, unsigned char num); 11462306a36Sopenharmony_ciint inet6_del_offload(const struct net_offload *prot, unsigned char num); 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci#endif /* _PROTOCOL_H */ 117