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 protocol dispatcher. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Version: @(#)protocol.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 * Changes: 148c2ecf20Sopenharmony_ci * Alan Cox : Added a name field and a frag handler 158c2ecf20Sopenharmony_ci * field for later. 168c2ecf20Sopenharmony_ci * Alan Cox : Cleaned up, and sorted types. 178c2ecf20Sopenharmony_ci * Pedro Roque : inet6 protocols 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#ifndef _PROTOCOL_H 218c2ecf20Sopenharmony_ci#define _PROTOCOL_H 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include <linux/in6.h> 248c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 258c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 268c2ecf20Sopenharmony_ci#include <linux/ipv6.h> 278c2ecf20Sopenharmony_ci#endif 288c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* This is one larger than the largest protocol value that can be 318c2ecf20Sopenharmony_ci * found in an ipv4 or ipv6 header. Since in both cases the protocol 328c2ecf20Sopenharmony_ci * value is presented in a __u8, this is defined to be 256. 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci#define MAX_INET_PROTOS 256 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* This is used to register protocols. */ 378c2ecf20Sopenharmony_cistruct net_protocol { 388c2ecf20Sopenharmony_ci int (*handler)(struct sk_buff *skb); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci /* This returns an error if we weren't able to handle the error. */ 418c2ecf20Sopenharmony_ci int (*err_handler)(struct sk_buff *skb, u32 info); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci unsigned int no_policy:1, 448c2ecf20Sopenharmony_ci netns_ok:1, 458c2ecf20Sopenharmony_ci /* does the protocol do more stringent 468c2ecf20Sopenharmony_ci * icmp tag validation than simple 478c2ecf20Sopenharmony_ci * socket lookup? 488c2ecf20Sopenharmony_ci */ 498c2ecf20Sopenharmony_ci icmp_strict_tag_validation:1; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 538c2ecf20Sopenharmony_cistruct inet6_protocol { 548c2ecf20Sopenharmony_ci int (*handler)(struct sk_buff *skb); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci /* This returns an error if we weren't able to handle the error. */ 578c2ecf20Sopenharmony_ci int (*err_handler)(struct sk_buff *skb, 588c2ecf20Sopenharmony_ci struct inet6_skb_parm *opt, 598c2ecf20Sopenharmony_ci u8 type, u8 code, int offset, 608c2ecf20Sopenharmony_ci __be32 info); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci unsigned int flags; /* INET6_PROTO_xxx */ 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define INET6_PROTO_NOPOLICY 0x1 668c2ecf20Sopenharmony_ci#define INET6_PROTO_FINAL 0x2 678c2ecf20Sopenharmony_ci#endif 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistruct net_offload { 708c2ecf20Sopenharmony_ci struct offload_callbacks callbacks; 718c2ecf20Sopenharmony_ci unsigned int flags; /* Flags used by IPv6 for now */ 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci/* This should be set for any extension header which is compatible with GSO. */ 748c2ecf20Sopenharmony_ci#define INET6_PROTO_GSO_EXTHDR 0x1 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci/* This is used to register socket interfaces for IP protocols. */ 778c2ecf20Sopenharmony_cistruct inet_protosw { 788c2ecf20Sopenharmony_ci struct list_head list; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci /* These two fields form the lookup key. */ 818c2ecf20Sopenharmony_ci unsigned short type; /* This is the 2nd argument to socket(2). */ 828c2ecf20Sopenharmony_ci unsigned short protocol; /* This is the L4 protocol number. */ 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci struct proto *prot; 858c2ecf20Sopenharmony_ci const struct proto_ops *ops; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci unsigned char flags; /* See INET_PROTOSW_* below. */ 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci#define INET_PROTOSW_REUSE 0x01 /* Are ports automatically reusable? */ 908c2ecf20Sopenharmony_ci#define INET_PROTOSW_PERMANENT 0x02 /* Permanent protocols are unremovable. */ 918c2ecf20Sopenharmony_ci#define INET_PROTOSW_ICSK 0x04 /* Is this an inet_connection_sock? */ 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ciextern struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS]; 948c2ecf20Sopenharmony_ciextern const struct net_offload __rcu *inet_offloads[MAX_INET_PROTOS]; 958c2ecf20Sopenharmony_ciextern const struct net_offload __rcu *inet6_offloads[MAX_INET_PROTOS]; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 988c2ecf20Sopenharmony_ciextern struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS]; 998c2ecf20Sopenharmony_ci#endif 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ciint inet_add_protocol(const struct net_protocol *prot, unsigned char num); 1028c2ecf20Sopenharmony_ciint inet_del_protocol(const struct net_protocol *prot, unsigned char num); 1038c2ecf20Sopenharmony_ciint inet_add_offload(const struct net_offload *prot, unsigned char num); 1048c2ecf20Sopenharmony_ciint inet_del_offload(const struct net_offload *prot, unsigned char num); 1058c2ecf20Sopenharmony_civoid inet_register_protosw(struct inet_protosw *p); 1068c2ecf20Sopenharmony_civoid inet_unregister_protosw(struct inet_protosw *p); 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 1098c2ecf20Sopenharmony_ciint inet6_add_protocol(const struct inet6_protocol *prot, unsigned char num); 1108c2ecf20Sopenharmony_ciint inet6_del_protocol(const struct inet6_protocol *prot, unsigned char num); 1118c2ecf20Sopenharmony_ciint inet6_register_protosw(struct inet_protosw *p); 1128c2ecf20Sopenharmony_civoid inet6_unregister_protosw(struct inet_protosw *p); 1138c2ecf20Sopenharmony_ci#endif 1148c2ecf20Sopenharmony_ciint inet6_add_offload(const struct net_offload *prot, unsigned char num); 1158c2ecf20Sopenharmony_ciint inet6_del_offload(const struct net_offload *prot, unsigned char num); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#endif /* _PROTOCOL_H */ 118