2182 lines · 66.2 KB · C
RawDownload
/* SPDX-License-Identifier: GPL-2.0-or-later *//* SCTP kernel implementation * (C) Copyright IBM Corp. 2001, 2004 * Copyright (c) 1999-2000 Cisco, Inc. * Copyright (c) 1999-2001 Motorola, Inc. * Copyright (c) 2001 Intel Corp. * * This file is part of the SCTP kernel implementation * * Please send any bug reports or fixes you make to the * email addresses: *    lksctp developers <linux-sctp@vger.kernel.org> * * Written or modified by: *    Randall Stewart	    <randall@sctp.chicago.il.us> *    Ken Morneau	    <kmorneau@cisco.com> *    Qiaobing Xie	    <qxie1@email.mot.com> *    La Monte H.P. Yarroll <piggy@acm.org> *    Karl Knutson	    <karl@athena.chicago.il.us> *    Jon Grimm		    <jgrimm@us.ibm.com> *    Xingang Guo	    <xingang.guo@intel.com> *    Hui Huang		    <hui.huang@nokia.com> *    Sridhar Samudrala	    <sri@us.ibm.com> *    Daisy Chang	    <daisyc@us.ibm.com> *    Dajiang Zhang	    <dajiang.zhang@nokia.com> *    Ardelle Fan	    <ardelle.fan@intel.com> *    Ryan Layer	    <rmlayer@us.ibm.com> *    Anup Pemmaiah	    <pemmaiah@cc.usu.edu> *    Kevin Gao             <kevin.gao@intel.com> */ #ifndef __sctp_structs_h__#define __sctp_structs_h__ #include <crypto/sha2.h>#include <linux/ktime.h>#include <linux/generic-radix-tree.h>#include <linux/rhashtable-types.h>#include <linux/socket.h>	/* linux/in.h needs this!!    */#include <linux/in.h>		/* We get struct sockaddr_in. */#include <linux/in6.h>		/* We get struct in6_addr     */#include <linux/ipv6.h>#include <asm/param.h>		/* We get MAXHOSTNAMELEN.     */#include <linux/atomic.h>		/* This gets us atomic counters.  */#include <linux/skbuff.h>	/* We need sk_buff_head. */#include <linux/workqueue.h>	/* We need tq_struct.	 */#include <linux/sctp.h>		/* We need sctp* header structs.  */#include <net/sctp/auth.h>	/* We need auth specific structs */#include <net/ip.h>		/* For inet_skb_parm */ /* A convenience structure for handling sockaddr structures. * We should wean ourselves off this. */union sctp_addr {	struct sockaddr_inet sa;	/* Large enough for both address families */	struct sockaddr_in v4;	struct sockaddr_in6 v6;}; /* Forward declarations for data structures. */struct sctp_globals;struct sctp_endpoint;struct sctp_association;struct sctp_transport;struct sctp_packet;struct sctp_chunk;struct sctp_inq;struct sctp_outq;struct sctp_bind_addr;struct sctp_ulpq;struct sctp_ep_common;struct sctp_stream;  #include <net/sctp/tsnmap.h>#include <net/sctp/ulpevent.h>#include <net/sctp/ulpqueue.h>#include <net/sctp/stream_interleave.h> /* Structures useful for managing bind/connect. */ struct sctp_bind_bucket {	unsigned short	port;	signed char	fastreuse;	signed char	fastreuseport;	kuid_t		fastuid;	struct hlist_node	node;	struct hlist_head	owner;	struct net	*net;}; struct sctp_bind_hashbucket {	spinlock_t	lock;	struct hlist_head	chain;}; /* Used for hashing all associations.  */struct sctp_hashbucket {	rwlock_t	lock;	struct hlist_head	chain;} __attribute__((__aligned__(8)));  /* The SCTP globals structure. */extern struct sctp_globals {	/* This is a list of groups of functions for each address	 * family that we support.	 */	struct list_head address_families; 	/* This is the hash of all endpoints. */	struct sctp_hashbucket *ep_hashtable;	/* This is the sctp port control hash.	*/	struct sctp_bind_hashbucket *port_hashtable;	/* This is the hash of all transports. */	struct rhltable transport_hashtable; 	/* Sizes of above hashtables. */	int ep_hashsize;	int port_hashsize; 	/* Default initialization values to be applied to new associations. */	__u16 max_instreams;	__u16 max_outstreams; 	/* Flag to indicate whether computing and verifying checksum	 * is disabled. */        bool checksum_disable;} sctp_globals; #define sctp_max_instreams		(sctp_globals.max_instreams)#define sctp_max_outstreams		(sctp_globals.max_outstreams)#define sctp_address_families		(sctp_globals.address_families)#define sctp_ep_hashsize		(sctp_globals.ep_hashsize)#define sctp_ep_hashtable		(sctp_globals.ep_hashtable)#define sctp_port_hashsize		(sctp_globals.port_hashsize)#define sctp_port_hashtable		(sctp_globals.port_hashtable)#define sctp_transport_hashtable	(sctp_globals.transport_hashtable)#define sctp_checksum_disable		(sctp_globals.checksum_disable) /* SCTP Socket type: UDP or TCP style. */enum sctp_socket_type {	SCTP_SOCKET_UDP = 0,	SCTP_SOCKET_UDP_HIGH_BANDWIDTH,	SCTP_SOCKET_TCP}; /* Per socket SCTP information. */struct sctp_sock {	/* inet_sock has to be the first member of sctp_sock */	struct inet_sock inet;	/* What kind of a socket is this? */	enum sctp_socket_type type; 	/* PF_ family specific functions.  */	struct sctp_pf *pf; 	/* What is our base endpointer? */	struct sctp_endpoint *ep; 	struct sctp_bind_bucket *bind_hash;	/* Various Socket Options.  */	__u16 default_stream;	__u32 default_ppid;	__u16 default_flags;	__u32 default_context;	__u32 default_timetolive;	__u32 default_rcv_context;	int max_burst; 	/* Heartbeat interval: The endpoint sends out a Heartbeat chunk to	 * the destination address every heartbeat interval. This value	 * will be inherited by all new associations.	 */	__u32 hbinterval;	__u32 probe_interval; 	__be16 udp_port;	__be16 encap_port; 	/* This is the max_retrans value for new associations. */	__u16 pathmaxrxt; 	__u32 flowlabel;	__u8  dscp; 	__u16 pf_retrans;	__u16 ps_retrans; 	/* The initial Path MTU to use for new associations. */	__u32 pathmtu; 	/* The default SACK delay timeout for new associations. */	__u32 sackdelay;	__u32 sackfreq; 	/* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */	__u32 param_flags; 	__u32 default_ss; 	struct sctp_rtoinfo rtoinfo;	struct sctp_paddrparams paddrparam;	struct sctp_assocparams assocparams; 	/*	 * These two structures must be grouped together for the usercopy	 * whitelist region.	 */	__u16 subscribe;	struct sctp_initmsg initmsg; 	int user_frag; 	__u32 autoclose;	__u32 adaptation_ind;	__u32 pd_point;	__u16	nodelay:1,		pf_expose:2,		reuse:1,		disable_fragments:1,		v4mapped:1,		frag_interleave:1,		recvrcvinfo:1,		recvnxtinfo:1,		data_ready_signalled:1,		cookie_auth_enable:1; 	atomic_t pd_mode; 	/* Receive to here while partial delivery is in effect. */	struct sk_buff_head pd_lobby; 	struct list_head auto_asconf_list;	int do_auto_asconf;}; #define sctp_sk(ptr) container_of_const(ptr, struct sctp_sock, inet.sk) static inline struct sock *sctp_opt2sk(const struct sctp_sock *sp){       return (struct sock *)sp;} #if IS_ENABLED(CONFIG_IPV6)struct sctp6_sock {       struct sctp_sock  sctp;       struct ipv6_pinfo inet6;};#endif /* CONFIG_IPV6 */  /* This is our APPLICATION-SPECIFIC state cookie. * THIS IS NOT DICTATED BY THE SPECIFICATION. *//* These are the parts of an association which we send in the cookie. * Most of these are straight out of: * RFC2960 12.2 Parameters necessary per association (i.e. the TCB) * */ struct sctp_cookie { 	/* My	       : Tag expected in every inbound packet and sent	 * Verification: in the INIT or INIT ACK chunk.	 * Tag	       :	 */	__u32 my_vtag; 	/* Peer's      : Tag expected in every outbound packet except	 * Verification: in the INIT chunk.	 * Tag	       :	 */	__u32 peer_vtag; 	/* The rest of these are not from the spec, but really need to	 * be in the cookie.	 */ 	/* My Tie Tag  : Assist in discovering a restarting association. */	__u32 my_ttag; 	/* Peer's Tie Tag: Assist in discovering a restarting association. */	__u32 peer_ttag; 	/* When does this cookie expire? */	ktime_t expiration; 	/* Number of inbound/outbound streams which are set	 * and negotiated during the INIT process.	 */	__u16 sinit_num_ostreams;	__u16 sinit_max_instreams; 	/* This is the first sequence number I used.  */	__u32 initial_tsn; 	/* This holds the originating address of the INIT packet.  */	union sctp_addr peer_addr; 	/* IG Section 2.35.3 	 * Include the source port of the INIT-ACK	 */	__u16		my_port; 	__u8 prsctp_capable; 	/* Padding for future use */	__u8 padding;  		 	__u32 adaptation_ind; 	__u8 auth_random[sizeof(struct sctp_paramhdr) +			 SCTP_AUTH_RANDOM_LENGTH];	__u8 auth_hmacs[sizeof(struct sctp_paramhdr) +			SCTP_AUTH_NUM_HMACS * sizeof(__u16)];	__u8 auth_chunks[sizeof(struct sctp_paramhdr) + SCTP_AUTH_MAX_CHUNKS]; 	/* This is a shim for my peer's INIT packet, followed by	 * a copy of the raw address list of the association.	 * The length of the raw address list is saved in the	 * raw_addr_list_len field, which will be used at the time when	 * the association TCB is re-constructed from the cookie.	 */	__u32 raw_addr_list_len;	/* struct sctp_init_chunk peer_init[]; */};  /* The format of our cookie that we send to our peer. */struct sctp_signed_cookie {	__u8 mac[SCTP_COOKIE_MAC_SIZE];	__u32 __pad;		/* force sctp_cookie alignment to 64 bits */	struct sctp_cookie c;} __packed; /* This is another convenience type to allocate memory for address * params for the maximum size and pass such structures around * internally. */union sctp_addr_param {	struct sctp_paramhdr p;	struct sctp_ipv4addr_param v4;	struct sctp_ipv6addr_param v6;}; /* A convenience type to allow walking through the various * parameters and avoid casting all over the place. */union sctp_params {	void *v;	struct sctp_paramhdr *p;	struct sctp_cookie_preserve_param *life;	struct sctp_hostname_param *dns;	struct sctp_cookie_param *cookie;	struct sctp_supported_addrs_param *sat;	struct sctp_ipv4addr_param *v4;	struct sctp_ipv6addr_param *v6;	union sctp_addr_param *addr;	struct sctp_adaptation_ind_param *aind;	struct sctp_supported_ext_param *ext;	struct sctp_random_param *random;	struct sctp_chunks_param *chunks;	struct sctp_hmac_algo_param *hmac_algo;	struct sctp_addip_param *addip;}; /* RFC 2960.  Section 3.3.5 Heartbeat. *    Heartbeat Information: variable length *    The Sender-specific Heartbeat Info field should normally include *    information about the sender's current time when this HEARTBEAT *    chunk is sent and the destination transport address to which this *    HEARTBEAT is sent (see Section 8.3). */struct sctp_sender_hb_info {	struct sctp_paramhdr param_hdr;	union sctp_addr daddr;	unsigned long sent_at;	__u64 hb_nonce;	__u32 probe_size;}; int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,		     gfp_t gfp);int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid);void sctp_stream_free(struct sctp_stream *stream);void sctp_stream_clear(struct sctp_stream *stream);void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new); /* What is the current SSN number for this stream? */#define sctp_ssn_peek(stream, type, sid) \	(sctp_stream_##type((stream), (sid))->ssn) /* Return the next SSN number for this stream.	*/#define sctp_ssn_next(stream, type, sid) \	(sctp_stream_##type((stream), (sid))->ssn++) /* Skip over this ssn and all below. */#define sctp_ssn_skip(stream, type, sid, ssn) \	(sctp_stream_##type((stream), (sid))->ssn = ssn + 1) /* What is the current MID number for this stream? */#define sctp_mid_peek(stream, type, sid) \	(sctp_stream_##type((stream), (sid))->mid) /* Return the next MID number for this stream.  */#define sctp_mid_next(stream, type, sid) \	(sctp_stream_##type((stream), (sid))->mid++) /* Skip over this mid and all below. */#define sctp_mid_skip(stream, type, sid, mid) \	(sctp_stream_##type((stream), (sid))->mid = mid + 1) /* What is the current MID_uo number for this stream? */#define sctp_mid_uo_peek(stream, type, sid) \	(sctp_stream_##type((stream), (sid))->mid_uo) /* Return the next MID_uo number for this stream.  */#define sctp_mid_uo_next(stream, type, sid) \	(sctp_stream_##type((stream), (sid))->mid_uo++) /* * Pointers to address related SCTP functions. * (i.e. things that depend on the address family.) */struct sctp_af {	int		(*sctp_xmit)	(struct sk_buff *skb,					 struct sctp_transport *);	int		(*setsockopt)	(struct sock *sk,					 int level,					 int optname,					 sockptr_t optval,					 unsigned int optlen);	int		(*getsockopt)	(struct sock *sk,					 int level,					 int optname,					 char __user *optval,					 int __user *optlen);	void		(*get_dst)	(struct sctp_transport *t,					 union sctp_addr *saddr,					 struct flowi *fl,					 struct sock *sk);	void		(*get_saddr)	(struct sctp_sock *sk,					 struct sctp_transport *t,					 struct flowi *fl);	void		(*copy_addrlist) (struct list_head *,					  struct net_device *);	int		(*cmp_addr)	(const union sctp_addr *addr1,					 const union sctp_addr *addr2);	void		(*addr_copy)	(union sctp_addr *dst,					 union sctp_addr *src);	void		(*from_skb)	(union sctp_addr *,					 struct sk_buff *skb,					 int saddr);	void		(*from_sk)	(union sctp_addr *,					 struct sock *sk);	bool		(*from_addr_param) (union sctp_addr *,					    union sctp_addr_param *,					    __be16 port, int iif);	int		(*to_addr_param) (const union sctp_addr *,					  union sctp_addr_param *); 	int		(*addr_valid)	(union sctp_addr *,					 struct sctp_sock *,					 const struct sk_buff *);	enum sctp_scope	(*scope)(union sctp_addr *);	void		(*inaddr_any)	(union sctp_addr *, __be16);	int		(*is_any)	(const union sctp_addr *);	int		(*available)	(union sctp_addr *,					 struct sctp_sock *);	int		(*skb_iif)	(const struct sk_buff *sk);	int		(*skb_sdif)(const struct sk_buff *sk);	int		(*is_ce)	(const struct sk_buff *sk);	void		(*seq_dump_addr)(struct seq_file *seq,					 union sctp_addr *addr);	void		(*ecn_capable)(struct sock *sk);	__u16		net_header_len;	int		sockaddr_len;	int		(*ip_options_len)(struct sock *sk);	sa_family_t	sa_family;	struct list_head list;}; struct sctp_af *sctp_get_af_specific(sa_family_t);int sctp_register_af(struct sctp_af *); /* Protocol family functions. */struct sctp_pf {	void (*event_msgname)(struct sctp_ulpevent *, char *, int *);	void (*skb_msgname)  (struct sk_buff *, char *, int *);	int  (*af_supported) (sa_family_t, struct sctp_sock *);	int  (*cmp_addr) (const union sctp_addr *,			  const union sctp_addr *,			  struct sctp_sock *);	int  (*bind_verify) (struct sctp_sock *, union sctp_addr *);	int  (*send_verify) (struct sctp_sock *, union sctp_addr *);	int  (*supported_addrs)(const struct sctp_sock *, __be16 *);	int (*addr_to_user)(struct sctp_sock *sk, union sctp_addr *addr);	void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);	void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);	void (*copy_ip_options)(struct sock *sk, struct sock *newsk);

Lines 1–500 of 2182.