1998 lines · 62.4 KB · C
RawDownload
/* 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 * * This SCTP implementation is free software; * you can redistribute it and/or modify it under the terms of * the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This SCTP implementation is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied *		   ************************ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU CC; see the file COPYING.  If not, see * <http://www.gnu.org/licenses/>. * * 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 <linux/ktime.h>#include <linux/rhashtable.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_in v4;	struct sockaddr_in6 v6;	struct sockaddr sa;}; /* 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 crypto_shash;struct sctp_stream;  #include <net/sctp/tsnmap.h>#include <net/sctp/ulpevent.h>#include <net/sctp/ulpqueue.h> /* Structures useful for managing bind/connect. */ struct sctp_bind_bucket {	unsigned short	port;	unsigned short	fastreuse;	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. */typedef enum {	SCTP_SOCKET_UDP = 0,	SCTP_SOCKET_UDP_HIGH_BANDWIDTH,	SCTP_SOCKET_TCP} sctp_socket_type_t; /* 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? */	sctp_socket_type_t type; 	/* PF_ family specific functions.  */	struct sctp_pf *pf; 	/* Access to HMAC transform. */	struct crypto_shash *hmac;	char *sctp_hmac_alg; 	/* 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; 	/* This is the max_retrans value for new associations. */	__u16 pathmaxrxt; 	/* 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; 	struct sctp_initmsg initmsg;	struct sctp_rtoinfo rtoinfo;	struct sctp_paddrparams paddrparam;	struct sctp_event_subscribe subscribe;	struct sctp_assocparams assocparams; 	int user_frag; 	__u32 autoclose;	__u32 adaptation_ind;	__u32 pd_point;	__u16	nodelay:1,		disable_fragments:1,		v4mapped:1,		frag_interleave:1,		recvrcvinfo:1,		recvnxtinfo:1,		data_ready_signalled:1; 	atomic_t pd_mode;	/* Receive to here while partial delivery is in effect. */	struct sk_buff_head pd_lobby; 	/* These must be the last fields, as they will skipped on copies,	 * like on accept and peeloff operations	 */	struct list_head auto_asconf_list;	int do_auto_asconf;}; static inline struct sctp_sock *sctp_sk(const struct sock *sk){       return (struct sctp_sock *)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[SCTP_AUTH_NUM_HMACS * sizeof(__u16) + 2];	__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[0];};  /* The format of our cookie that we send to our peer. */struct sctp_signed_cookie {	__u8 signature[SCTP_SECRET_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). */typedef struct sctp_sender_hb_info {	struct sctp_paramhdr param_hdr;	union sctp_addr daddr;	unsigned long sent_at;	__u64 hb_nonce;} sctp_sender_hb_info_t; int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,		     gfp_t gfp);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) \	((stream)->type[sid].ssn) /* Return the next SSN number for this stream.	*/#define sctp_ssn_next(stream, type, sid) \	((stream)->type[sid].ssn++) /* Skip over this ssn and all below. */#define sctp_ssn_skip(stream, type, sid, ssn) \	((stream)->type[sid].ssn = ssn + 1) /* * 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,					 char __user *optval,					 unsigned int optlen);	int		(*getsockopt)	(struct sock *sk,					 int level,					 int optname,					 char __user *optval,					 int __user *optlen);	int		(*compat_setsockopt)	(struct sock *sk,					 int level,					 int optname,					 char __user *optval,					 unsigned int optlen);	int		(*compat_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);	void		(*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 *);	sctp_scope_t	(*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		(*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;	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 *);	struct sock *(*create_accept_sk) (struct sock *sk,					  struct sctp_association *asoc,					  bool kern);	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);	struct sctp_af *af;};  /* Structure to track chunk fragments that have been acked, but peer * fragments of the same message have not. */struct sctp_datamsg {	/* Chunks waiting to be submitted to lower layer. */	struct list_head chunks;	/* Reference counting. */	refcount_t refcnt;	/* When is this message no longer interesting to the peer? */

Lines 1–500 of 1998.