1*2874c5fdSThomas 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 protocol dispatcher. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Version: @(#)protocol.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 * Changes: 141da177e4SLinus Torvalds * Alan Cox : Added a name field and a frag handler 151da177e4SLinus Torvalds * field for later. 161da177e4SLinus Torvalds * Alan Cox : Cleaned up, and sorted types. 171da177e4SLinus Torvalds * Pedro Roque : inet6 protocols 181da177e4SLinus Torvalds */ 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds #ifndef _PROTOCOL_H 211da177e4SLinus Torvalds #define _PROTOCOL_H 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #include <linux/in6.h> 24c6b641a4SVlad Yasevich #include <linux/skbuff.h> 25dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 261da177e4SLinus Torvalds #include <linux/ipv6.h> 271da177e4SLinus Torvalds #endif 28f191a1d1SVlad Yasevich #include <linux/netdevice.h> 291da177e4SLinus Torvalds 30f9242b6bSDavid S. Miller /* This is one larger than the largest protocol value that can be 31f9242b6bSDavid S. Miller * found in an ipv4 or ipv6 header. Since in both cases the protocol 32f9242b6bSDavid S. Miller * value is presented in a __u8, this is defined to be 256. 33f9242b6bSDavid S. Miller */ 34f9242b6bSDavid S. Miller #define MAX_INET_PROTOS 256 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds /* This is used to register protocols. */ 371da177e4SLinus Torvalds struct net_protocol { 381da177e4SLinus Torvalds int (*handler)(struct sk_buff *skb); 3932bbd879SStefano Brivio 4032bbd879SStefano Brivio /* This returns an error if we weren't able to handle the error. */ 4132bbd879SStefano Brivio int (*err_handler)(struct sk_buff *skb, u32 info); 4232bbd879SStefano Brivio 43f145049aSDenis V. Lunev unsigned int no_policy:1, 448ed1dc44SHannes Frederic Sowa /* does the protocol do more stringent 458ed1dc44SHannes Frederic Sowa * icmp tag validation than simple 468ed1dc44SHannes Frederic Sowa * socket lookup? 478ed1dc44SHannes Frederic Sowa */ 488ed1dc44SHannes Frederic Sowa icmp_strict_tag_validation:1; 491da177e4SLinus Torvalds }; 501da177e4SLinus Torvalds 51dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 52fd2c3ef7SEric Dumazet struct inet6_protocol { 53e5bbef20SHerbert Xu int (*handler)(struct sk_buff *skb); 541da177e4SLinus Torvalds 5532bbd879SStefano Brivio /* This returns an error if we weren't able to handle the error. */ 5632bbd879SStefano Brivio int (*err_handler)(struct sk_buff *skb, 571da177e4SLinus Torvalds struct inet6_skb_parm *opt, 58d5fdd6baSBrian Haley u8 type, u8 code, int offset, 5904ce6909SAl Viro __be32 info); 6032bbd879SStefano Brivio 611da177e4SLinus Torvalds unsigned int flags; /* INET6_PROTO_xxx */ 621da177e4SLinus Torvalds }; 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #define INET6_PROTO_NOPOLICY 0x1 651da177e4SLinus Torvalds #define INET6_PROTO_FINAL 0x2 661da177e4SLinus Torvalds #endif 671da177e4SLinus Torvalds 68de27d001SVlad Yasevich struct net_offload { 69f191a1d1SVlad Yasevich struct offload_callbacks callbacks; 708ca896cfSVlad Yasevich unsigned int flags; /* Flags used by IPv6 for now */ 71de27d001SVlad Yasevich }; 72c6b641a4SVlad Yasevich /* This should be set for any extension header which is compatible with GSO. */ 73c6b641a4SVlad Yasevich #define INET6_PROTO_GSO_EXTHDR 0x1 74de27d001SVlad Yasevich 751da177e4SLinus Torvalds /* This is used to register socket interfaces for IP protocols. */ 761da177e4SLinus Torvalds struct inet_protosw { 771da177e4SLinus Torvalds struct list_head list; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /* These two fields form the lookup key. */ 801da177e4SLinus Torvalds unsigned short type; /* This is the 2nd argument to socket(2). */ 81ee41e2dfSArnaldo Carvalho de Melo unsigned short protocol; /* This is the L4 protocol number. */ 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds struct proto *prot; 8490ddc4f0SEric Dumazet const struct proto_ops *ops; 851da177e4SLinus Torvalds 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 92dddb64bcSsubashab@codeaurora.org extern struct net_protocol __rcu *inet_protos[MAX_INET_PROTOS]; 93de27d001SVlad Yasevich extern const struct net_offload __rcu *inet_offloads[MAX_INET_PROTOS]; 94c6b641a4SVlad Yasevich extern const struct net_offload __rcu *inet6_offloads[MAX_INET_PROTOS]; 951da177e4SLinus Torvalds 96dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 97dddb64bcSsubashab@codeaurora.org extern struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS]; 981da177e4SLinus Torvalds #endif 991da177e4SLinus Torvalds 100f307c636SJoe Perches int inet_add_protocol(const struct net_protocol *prot, unsigned char num); 101f307c636SJoe Perches int inet_del_protocol(const struct net_protocol *prot, unsigned char num); 102f307c636SJoe Perches int inet_add_offload(const struct net_offload *prot, unsigned char num); 103f307c636SJoe Perches int inet_del_offload(const struct net_offload *prot, unsigned char num); 104f307c636SJoe Perches void inet_register_protosw(struct inet_protosw *p); 105f307c636SJoe Perches void inet_unregister_protosw(struct inet_protosw *p); 1061da177e4SLinus Torvalds 107dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 108f307c636SJoe Perches int inet6_add_protocol(const struct inet6_protocol *prot, unsigned char num); 109f307c636SJoe Perches int inet6_del_protocol(const struct inet6_protocol *prot, unsigned char num); 110f307c636SJoe Perches int inet6_register_protosw(struct inet_protosw *p); 111f307c636SJoe Perches void inet6_unregister_protosw(struct inet_protosw *p); 1121da177e4SLinus Torvalds #endif 113f307c636SJoe Perches int inet6_add_offload(const struct net_offload *prot, unsigned char num); 114f307c636SJoe Perches int inet6_del_offload(const struct net_offload *prot, unsigned char num); 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds #endif /* _PROTOCOL_H */ 117