structs.h 67.0 KB
Newer Older
1
/* SCTP kernel implementation
L
Linus Torvalds 已提交
2 3 4 5 6
 * (C) Copyright IBM Corp. 2001, 2004
 * Copyright (c) 1999-2000 Cisco, Inc.
 * Copyright (c) 1999-2001 Motorola, Inc.
 * Copyright (c) 2001 Intel Corp.
 *
7
 * This file is part of the SCTP kernel implementation
L
Linus Torvalds 已提交
8
 *
9
 * This SCTP implementation is free software;
L
Linus Torvalds 已提交
10 11 12 13 14
 * 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.
 *
15
 * This SCTP implementation is distributed in the hope that it
L
Linus Torvalds 已提交
16 17 18 19 20 21
 * 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
22 23
 * along with GNU CC; see the file COPYING.  If not, see
 * <http://www.gnu.org/licenses/>.
L
Linus Torvalds 已提交
24 25 26
 *
 * Please send any bug reports or fixes you make to the
 * email addresses:
27
 *    lksctp developers <linux-sctp@vger.kernel.org>
L
Linus Torvalds 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 *
 * 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__

50
#include <linux/ktime.h>
K
Kent Overstreet 已提交
51
#include <linux/generic-radix-tree.h>
N
NeilBrown 已提交
52
#include <linux/rhashtable-types.h>
L
Linus Torvalds 已提交
53 54 55 56 57
#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.     */
A
Arun Sharma 已提交
58
#include <linux/atomic.h>		/* This gets us atomic counters.  */
L
Linus Torvalds 已提交
59 60 61
#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.  */
62
#include <net/sctp/auth.h>	/* We need auth specific structs */
63
#include <net/ip.h>		/* For inet_skb_parm */
L
Linus Torvalds 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

/* 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;
H
Herbert Xu 已提交
86
struct crypto_shash;
87
struct sctp_stream;
L
Linus Torvalds 已提交
88 89 90 91 92


#include <net/sctp/tsnmap.h>
#include <net/sctp/ulpevent.h>
#include <net/sctp/ulpqueue.h>
93
#include <net/sctp/stream_interleave.h>
L
Linus Torvalds 已提交
94 95 96 97 98

/* Structures useful for managing bind/connect. */

struct sctp_bind_bucket {
	unsigned short	port;
99 100 101
	signed char	fastreuse;
	signed char	fastreuseport;
	kuid_t		fastuid;
102
	struct hlist_node	node;
L
Linus Torvalds 已提交
103
	struct hlist_head	owner;
104
	struct net	*net;
L
Linus Torvalds 已提交
105 106 107 108
};

struct sctp_bind_hashbucket {
	spinlock_t	lock;
109
	struct hlist_head	chain;
L
Linus Torvalds 已提交
110 111 112 113 114
};

/* Used for hashing all associations.  */
struct sctp_hashbucket {
	rwlock_t	lock;
115
	struct hlist_head	chain;
L
Linus Torvalds 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129
} __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;
130
	/* This is the hash of all transports. */
131
	struct rhltable transport_hashtable;
132

133 134 135 136 137 138 139 140
	/* 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;

141 142 143
	/* Flag to indicate whether computing and verifying checksum
	 * is disabled. */
        bool checksum_disable;
L
Linus Torvalds 已提交
144 145 146 147 148 149 150 151 152
} 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)
153
#define sctp_transport_hashtable	(sctp_globals.transport_hashtable)
154
#define sctp_checksum_disable		(sctp_globals.checksum_disable)
L
Linus Torvalds 已提交
155 156

/* SCTP Socket type: UDP or TCP style. */
157
enum sctp_socket_type {
L
Linus Torvalds 已提交
158 159 160
	SCTP_SOCKET_UDP = 0,
	SCTP_SOCKET_UDP_HIGH_BANDWIDTH,
	SCTP_SOCKET_TCP
161
};
L
Linus Torvalds 已提交
162 163 164 165 166 167

/* 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? */
168
	enum sctp_socket_type type;
L
Linus Torvalds 已提交
169 170 171 172 173

	/* PF_ family specific functions.  */
	struct sctp_pf *pf;

	/* Access to HMAC transform. */
H
Herbert Xu 已提交
174
	struct crypto_shash *hmac;
175
	char *sctp_hmac_alg;
L
Linus Torvalds 已提交
176 177 178 179 180 181 182 183 184 185 186

	/* 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;
187
	__u32 default_rcv_context;
188
	int max_burst;
L
Linus Torvalds 已提交
189

190 191 192 193 194 195 196 197 198
	/* 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;

199 200 201
	__u32 flowlabel;
	__u8  dscp;

202 203
	int pf_retrans;

204 205 206 207 208
	/* The initial Path MTU to use for new associations. */
	__u32 pathmtu;

	/* The default SACK delay timeout for new associations. */
	__u32 sackdelay;
209
	__u32 sackfreq;
210

J
Joe Perches 已提交
211
	/* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
212 213
	__u32 param_flags;

214 215
	__u32 default_ss;

L
Linus Torvalds 已提交
216 217 218
	struct sctp_rtoinfo rtoinfo;
	struct sctp_paddrparams paddrparam;
	struct sctp_assocparams assocparams;
219

220 221 222 223
	/*
	 * These two structures must be grouped together for the usercopy
	 * whitelist region.
	 */
224
	__u16 subscribe;
225 226
	struct sctp_initmsg initmsg;

L
Linus Torvalds 已提交
227
	int user_frag;
228

L
Linus Torvalds 已提交
229
	__u32 autoclose;
230
	__u32 adaptation_ind;
231
	__u32 pd_point;
232
	__u16	nodelay:1,
233
		reuse:1,
234 235 236
		disable_fragments:1,
		v4mapped:1,
		frag_interleave:1,
237
		strm_interleave:1,
238
		recvrcvinfo:1,
239
		recvnxtinfo:1,
240
		data_ready_signalled:1;
L
Linus Torvalds 已提交
241

242
	atomic_t pd_mode;
L
Linus Torvalds 已提交
243 244
	/* Receive to here while partial delivery is in effect. */
	struct sk_buff_head pd_lobby;
245 246 247 248

	/* These must be the last fields, as they will skipped on copies,
	 * like on accept and peeloff operations
	 */
249 250
	struct list_head auto_asconf_list;
	int do_auto_asconf;
L
Linus Torvalds 已提交
251 252 253 254 255 256 257 258 259 260 261 262
};

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;
}

E
Eric Dumazet 已提交
263
#if IS_ENABLED(CONFIG_IPV6)
L
Linus Torvalds 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
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? */
305
	ktime_t expiration;
L
Linus Torvalds 已提交
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

	/* 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;  		

329
	__u32 adaptation_ind;
L
Linus Torvalds 已提交
330

331 332
	__u8 auth_random[sizeof(struct sctp_paramhdr) +
			 SCTP_AUTH_RANDOM_LENGTH];
333
	__u8 auth_hmacs[SCTP_AUTH_NUM_HMACS * sizeof(__u16) + 2];
334
	__u8 auth_chunks[sizeof(struct sctp_paramhdr) + SCTP_AUTH_MAX_CHUNKS];
L
Linus Torvalds 已提交
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349

	/* 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];
350
	__u32 __pad;		/* force sctp_cookie alignment to 64 bits */
L
Linus Torvalds 已提交
351
	struct sctp_cookie c;
E
Eric Dumazet 已提交
352
} __packed;
L
Linus Torvalds 已提交
353 354 355 356 357 358

/* 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 {
359
	struct sctp_paramhdr p;
L
Linus Torvalds 已提交
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
	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;
377
	struct sctp_adaptation_ind_param *aind;
378
	struct sctp_supported_ext_param *ext;
379 380 381
	struct sctp_random_param *random;
	struct sctp_chunks_param *chunks;
	struct sctp_hmac_algo_param *hmac_algo;
382
	struct sctp_addip_param *addip;
L
Linus Torvalds 已提交
383 384 385 386 387 388 389 390 391
};

/* 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).
 */
392
struct sctp_sender_hb_info {
L
Linus Torvalds 已提交
393 394 395
	struct sctp_paramhdr param_hdr;
	union sctp_addr daddr;
	unsigned long sent_at;
396
	__u64 hb_nonce;
397
};
L
Linus Torvalds 已提交
398

399 400
int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
		     gfp_t gfp);
401
int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid);
402 403
void sctp_stream_free(struct sctp_stream *stream);
void sctp_stream_clear(struct sctp_stream *stream);
404
void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new);
L
Linus Torvalds 已提交
405 406

/* What is the current SSN number for this stream? */
407
#define sctp_ssn_peek(stream, type, sid) \
408
	(sctp_stream_##type((stream), (sid))->ssn)
L
Linus Torvalds 已提交
409 410

/* Return the next SSN number for this stream.	*/
411
#define sctp_ssn_next(stream, type, sid) \
412
	(sctp_stream_##type((stream), (sid))->ssn++)
L
Linus Torvalds 已提交
413 414

/* Skip over this ssn and all below. */
415
#define sctp_ssn_skip(stream, type, sid, ssn) \
416
	(sctp_stream_##type((stream), (sid))->ssn = ssn + 1)
417

418 419
/* What is the current MID number for this stream? */
#define sctp_mid_peek(stream, type, sid) \
420
	(sctp_stream_##type((stream), (sid))->mid)
421 422 423

/* Return the next MID number for this stream.  */
#define sctp_mid_next(stream, type, sid) \
424
	(sctp_stream_##type((stream), (sid))->mid++)
425 426 427

/* Skip over this mid and all below. */
#define sctp_mid_skip(stream, type, sid, mid) \
428
	(sctp_stream_##type((stream), (sid))->mid = mid + 1)
429

430 431
/* What is the current MID_uo number for this stream? */
#define sctp_mid_uo_peek(stream, type, sid) \
432
	(sctp_stream_##type((stream), (sid))->mid_uo)
433 434 435

/* Return the next MID_uo number for this stream.  */
#define sctp_mid_uo_next(stream, type, sid) \
436
	(sctp_stream_##type((stream), (sid))->mid_uo++)
437

L
Linus Torvalds 已提交
438 439 440 441 442 443
/*
 * 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,
444
					 struct sctp_transport *);
L
Linus Torvalds 已提交
445 446 447 448
	int		(*setsockopt)	(struct sock *sk,
					 int level,
					 int optname,
					 char __user *optval,
449
					 unsigned int optlen);
L
Linus Torvalds 已提交
450 451 452 453 454
	int		(*getsockopt)	(struct sock *sk,
					 int level,
					 int optname,
					 char __user *optval,
					 int __user *optlen);
455 456 457 458
	int		(*compat_setsockopt)	(struct sock *sk,
					 int level,
					 int optname,
					 char __user *optval,
459
					 unsigned int optlen);
460 461 462 463 464
	int		(*compat_getsockopt)	(struct sock *sk,
					 int level,
					 int optname,
					 char __user *optval,
					 int __user *optlen);
465
	void		(*get_dst)	(struct sctp_transport *t,
466 467 468
					 union sctp_addr *saddr,
					 struct flowi *fl,
					 struct sock *sk);
469
	void		(*get_saddr)	(struct sctp_sock *sk,
470 471
					 struct sctp_transport *t,
					 struct flowi *fl);
L
Linus Torvalds 已提交
472 473 474 475 476 477 478 479 480 481 482 483 484
	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 *,
485
					    __be16 port, int iif);
L
Linus Torvalds 已提交
486 487 488
	int		(*to_addr_param) (const union sctp_addr *,
					  union sctp_addr_param *); 
	int		(*addr_valid)	(union sctp_addr *,
489 490
					 struct sctp_sock *,
					 const struct sk_buff *);
X
Xin Long 已提交
491
	enum sctp_scope	(*scope)(union sctp_addr *);
A
Al Viro 已提交
492
	void		(*inaddr_any)	(union sctp_addr *, __be16);
L
Linus Torvalds 已提交
493 494 495 496 497 498 499
	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);
V
Vlad Yasevich 已提交
500
	void		(*ecn_capable)(struct sock *sk);
L
Linus Torvalds 已提交
501 502
	__u16		net_header_len;
	int		sockaddr_len;
R
Richard Haines 已提交
503
	int		(*ip_options_len)(struct sock *sk);
L
Linus Torvalds 已提交
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
	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 *);
A
Al Viro 已提交
521
	int  (*supported_addrs)(const struct sctp_sock *, __be16 *);
L
Linus Torvalds 已提交
522
	struct sock *(*create_accept_sk) (struct sock *sk,
523 524
					  struct sctp_association *asoc,
					  bool kern);
525 526 527
	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);
R
Richard Haines 已提交
528
	void (*copy_ip_options)(struct sock *sk, struct sock *newsk);
L
Linus Torvalds 已提交
529 530 531 532 533 534 535 536 537 538 539
	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. */
540
	refcount_t refcnt;
L
Linus Torvalds 已提交
541 542 543 544
	/* When is this message no longer interesting to the peer? */
	unsigned long expires_at;
	/* Did the messenge fail to send? */
	int send_error;
545
	u8 send_failed:1,
546 547
	   can_delay:1,	/* should this message be Nagle delayed */
	   abandoned:1;	/* should this message be abandoned */
L
Linus Torvalds 已提交
548 549 550 551
};

struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *,
					    struct sctp_sndrcvinfo *,
552
					    struct iov_iter *);
553
void sctp_datamsg_free(struct sctp_datamsg *);
L
Linus Torvalds 已提交
554 555 556 557 558 559 560 561 562 563 564 565 566
void sctp_datamsg_put(struct sctp_datamsg *);
void sctp_chunk_fail(struct sctp_chunk *, int error);
int sctp_chunk_abandoned(struct sctp_chunk *);

/* RFC2960 1.4 Key Terms
 *
 * o Chunk: A unit of information within an SCTP packet, consisting of
 * a chunk header and chunk-specific content.
 *
 * As a matter of convenience, we remember the SCTP common header for
 * each chunk as well as a few other header pointers...
 */
struct sctp_chunk {
567 568
	struct list_head list;

569
	refcount_t refcnt;
L
Linus Torvalds 已提交
570

571 572 573
	/* How many times this chunk have been sent, for prsctp RTX policy */
	int sent_count;

574 575 576 577 578 579
	union {
		/* This is our link to the per-transport transmitted list.  */
		struct list_head transmitted_list;
		/* List in specific stream outq */
		struct list_head stream_list;
	};
L
Linus Torvalds 已提交
580 581 582 583 584 585 586 587 588 589 590

	/* This field is used by chunks that hold fragmented data.
	 * For the first fragment this is the list that holds the rest of
	 * fragments. For the remaining fragments, this is the link to the
	 * frag_list maintained in the first fragment.
	 */
	struct list_head frag_list;

	/* This points to the sk_buff containing the actual data.  */
	struct sk_buff *skb;

X
Xin Long 已提交
591 592 593 594 595 596
	union {
		/* In case of GSO packets, this will store the head one */
		struct sk_buff *head_skb;
		/* In case of auth enabled, this will point to the shkey */
		struct sctp_shared_key *shkey;
	};
M
Marcelo Ricardo Leitner 已提交
597

L
Linus Torvalds 已提交
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
	/* These are the SCTP headers by reverse order in a packet.
	 * Note that some of these may happen more than once.  In that
	 * case, we point at the "current" one, whatever that means
	 * for that level of header.
	 */

	/* We point this at the FIRST TLV parameter to chunk_hdr.  */
	union sctp_params param_hdr;
	union {
		__u8 *v;
		struct sctp_datahdr *data_hdr;
		struct sctp_inithdr *init_hdr;
		struct sctp_sackhdr *sack_hdr;
		struct sctp_heartbeathdr *hb_hdr;
		struct sctp_sender_hb_info *hbs_hdr;
		struct sctp_shutdownhdr *shutdown_hdr;
		struct sctp_signed_cookie *cookie_hdr;
		struct sctp_ecnehdr *ecne_hdr;
		struct sctp_cwrhdr *ecn_cwr_hdr;
		struct sctp_errhdr *err_hdr;
		struct sctp_addiphdr *addip_hdr;
		struct sctp_fwdtsn_hdr *fwdtsn_hdr;
620
		struct sctp_authhdr *auth_hdr;
621
		struct sctp_idatahdr *idata_hdr;
622
		struct sctp_ifwdtsn_hdr *ifwdtsn_hdr;
L
Linus Torvalds 已提交
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
	} subh;

	__u8 *chunk_end;

	struct sctp_chunkhdr *chunk_hdr;
	struct sctphdr *sctp_hdr;

	/* This needs to be recoverable for SCTP_SEND_FAILED events. */
	struct sctp_sndrcvinfo sinfo;

	/* Which association does this belong to?  */
	struct sctp_association *asoc;

	/* What endpoint received this chunk? */
	struct sctp_ep_common *rcvr;

	/* We fill this in if we are calculating RTT. */
	unsigned long sent_at;

	/* What is the origin IP address for this chunk?  */
	union sctp_addr source;
	/* Destination address for this chunk. */
	union sctp_addr dest;

	/* For outbound message, track all fragments for SEND_FAILED. */
	struct sctp_datamsg *msg;

	/* For an inbound chunk, this tells us where it came from.
	 * For an outbound chunk, it tells us where we'd like it to
	 * go.	It is NULL if we have no preference.
	 */
	struct sctp_transport *transport;

656 657 658 659 660 661 662
	/* SCTP-AUTH:  For the special case inbound processing of COOKIE-ECHO
	 * we need save a pointer to the AUTH chunk, since the SCTP-AUTH
	 * spec violates the principle premis that all chunks are processed
	 * in order.
	 */
	struct sk_buff *auth_chunk;

663 664 665 666 667 668
#define SCTP_CAN_FRTX 0x0
#define SCTP_NEED_FRTX 0x1
#define SCTP_DONT_FRTX 0x2
	__u16	rtt_in_progress:1,	/* This chunk used for RTT calc? */
		has_tsn:1,		/* Does this chunk have a TSN yet? */
		has_ssn:1,		/* Does this chunk have a SSN yet? */
669
#define has_mid has_ssn
670 671 672 673 674 675 676 677 678 679
		singleton:1,		/* Only chunk in the packet? */
		end_of_packet:1,	/* Last chunk in the packet? */
		ecn_ce_done:1,		/* Have we processed the ECN CE bit? */
		pdiscard:1,		/* Discard the whole packet now? */
		tsn_gap_acked:1,	/* Is this chunk acked by a GAP ACK? */
		data_accepted:1,	/* At least 1 chunk accepted */
		auth:1,			/* IN: was auth'ed | OUT: needs auth */
		has_asconf:1,		/* IN: have seen an asconf before */
		tsn_missing_report:2,	/* Data chunk missing counter. */
		fast_retransmit:2;	/* Is this chunk fast retransmitted? */
L
Linus Torvalds 已提交
680 681
};

682
#define sctp_chunk_retransmitted(chunk)	(chunk->sent_count > 1)
L
Linus Torvalds 已提交
683 684
void sctp_chunk_hold(struct sctp_chunk *);
void sctp_chunk_put(struct sctp_chunk *);
685 686
int sctp_user_addto_chunk(struct sctp_chunk *chunk, int len,
			  struct iov_iter *from);
L
Linus Torvalds 已提交
687 688 689 690
void sctp_chunk_free(struct sctp_chunk *);
void  *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data);
struct sctp_chunk *sctp_chunkify(struct sk_buff *,
				 const struct sctp_association *,
691
				 struct sock *, gfp_t gfp);
L
Linus Torvalds 已提交
692 693 694 695
void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
		     union sctp_addr *);
const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);

696 697 698 699 700
static inline __u16 sctp_chunk_stream_no(struct sctp_chunk *ch)
{
	return ntohs(ch->subh.data_hdr->stream);
}

701 702 703 704 705 706
enum {
	SCTP_ADDR_NEW,		/* new address added to assoc/ep */
	SCTP_ADDR_SRC,		/* address can be used as source */
	SCTP_ADDR_DEL,		/* address about to be deleted */
};

L
Linus Torvalds 已提交
707 708 709
/* This is a structure for holding either an IPv6 or an IPv4 address.  */
struct sctp_sockaddr_entry {
	struct list_head list;
710
	struct rcu_head	rcu;
L
Linus Torvalds 已提交
711
	union sctp_addr a;
712
	__u8 state;
713
	__u8 valid;
L
Linus Torvalds 已提交
714 715
};

716 717
#define SCTP_ADDRESS_TICK_DELAY	500

L
Linus Torvalds 已提交
718 719 720 721 722 723 724 725 726 727
/* This structure holds lists of chunks as we are assembling for
 * transmission.
 */
struct sctp_packet {
	/* These are the SCTP header values (host order) for the packet. */
	__u16 source_port;
	__u16 destination_port;
	__u32 vtag;

	/* This contains the payload chunks.  */
728
	struct list_head chunk_list;
L
Linus Torvalds 已提交
729 730 731 732 733

	/* This is the overhead of the sctp and ip headers. */
	size_t overhead;
	/* This is the total size of all chunks INCLUDING padding.  */
	size_t size;
M
Marcelo Ricardo Leitner 已提交
734 735
	/* This is the maximum size this packet may have */
	size_t max_size;
L
Linus Torvalds 已提交
736 737 738 739 740 741 742

	/* The packet is destined for this transport address.
	 * The function we finally use to pass down to the next lower
	 * layer lives in the transport structure.
	 */
	struct sctp_transport *transport;

743 744 745
	/* pointer to the auth chunk for this packet */
	struct sctp_chunk *auth;

746 747 748 749
	u8  has_cookie_echo:1,	/* This packet contains a COOKIE-ECHO chunk. */
	    has_sack:1,		/* This packet contains a SACK chunk. */
	    has_auth:1,		/* This packet contains an AUTH chunk */
	    has_data:1,		/* This packet contains at least 1 DATA chunk */
750
	    ipfragok:1;		/* So let ip fragment this packet */
L
Linus Torvalds 已提交
751 752
};

753 754 755
void sctp_packet_init(struct sctp_packet *, struct sctp_transport *,
		      __u16 sport, __u16 dport);
void sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
X
Xin Long 已提交
756 757 758 759 760
enum sctp_xmit sctp_packet_transmit_chunk(struct sctp_packet *packet,
					  struct sctp_chunk *chunk,
					  int one_packet, gfp_t gfp);
enum sctp_xmit sctp_packet_append_chunk(struct sctp_packet *packet,
					struct sctp_chunk *chunk);
761
int sctp_packet_transmit(struct sctp_packet *, gfp_t);
L
Linus Torvalds 已提交
762 763 764 765
void sctp_packet_free(struct sctp_packet *);

static inline int sctp_packet_empty(struct sctp_packet *packet)
{
E
Eric Dumazet 已提交
766
	return packet->size == packet->overhead;
L
Linus Torvalds 已提交
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
}

/* This represents a remote transport address.
 * For local transport addresses, we just use union sctp_addr.
 *
 * RFC2960 Section 1.4 Key Terms
 *
 *   o	Transport address:  A Transport Address is traditionally defined
 *	by Network Layer address, Transport Layer protocol and Transport
 *	Layer port number.  In the case of SCTP running over IP, a
 *	transport address is defined by the combination of an IP address
 *	and an SCTP port number (where SCTP is the Transport protocol).
 *
 * RFC2960 Section 7.1 SCTP Differences from TCP Congestion control
 *
 *   o	The sender keeps a separate congestion control parameter set for
 *	each of the destination addresses it can send to (not each
 *	source-destination pair but for each destination).  The parameters
 *	should decay if the address is not used for a long enough time
 *	period.
 *
 */
struct sctp_transport {
	/* A list of transports. */
	struct list_head transports;
792
	struct rhlist_head node;
L
Linus Torvalds 已提交
793 794

	/* Reference counting. */
795
	refcount_t refcnt;
796 797 798 799 800 801 802 803 804
		/* RTO-Pending : A flag used to track if one of the DATA
		 *		chunks sent to this address is currently being
		 *		used to compute a RTT. If this flag is 0,
		 *		the next DATA chunk sent to this destination
		 *		should be used to compute a RTT and this flag
		 *		should be set. Every time the RTT
		 *		calculation completes (i.e. the DATA chunk
		 *		is SACK'd) clear this flag.
		 */
805
	__u32	rto_pending:1,
806 807 808 809 810 811 812 813

		/*
		 * hb_sent : a flag that signals that we have a pending
		 * heartbeat.
		 */
		hb_sent:1,

		/* Is the Path MTU update pending on this tranport */
814
		pmtu_pending:1,
815

816 817
		dst_pending_confirm:1,	/* need to confirm neighbour */

818 819
		/* Has this transport moved the ctsn since we last sacked */
		sack_generation:1;
820
	u32 dst_cookie;
821

822
	struct flowi fl;
L
Linus Torvalds 已提交
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841

	/* This is the peer's IP address and port. */
	union sctp_addr ipaddr;

	/* These are the functions we call to handle LLP stuff.	 */
	struct sctp_af *af_specific;

	/* Which association do we belong to?  */
	struct sctp_association *asoc;

	/* RFC2960
	 *
	 * 12.3 Per Transport Address Data
	 *
	 * For each destination transport address in the peer's
	 * address list derived from the INIT or INIT ACK chunk, a
	 * number of data elements needs to be maintained including:
	 */
	/* RTO	       : The current retransmission timeout value.  */
842
	unsigned long rto;
843 844

	__u32 rtt;		/* This is the most recent RTT.	 */
L
Linus Torvalds 已提交
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868

	/* RTTVAR      : The current RTT variation.  */
	__u32 rttvar;

	/* SRTT	       : The current smoothed round trip time.	*/
	__u32 srtt;

	/*
	 * These are the congestion stats.
	 */
	/* cwnd	       : The current congestion window.	 */
	__u32 cwnd;		  /* This is the actual cwnd.  */

	/* ssthresh    : The current slow start threshold value.  */
	__u32 ssthresh;

	/* partial     : The tracking method for increase of cwnd when in
	 * bytes acked : congestion avoidance mode (see Section 6.2.2)
	 */
	__u32 partial_bytes_acked;

	/* Data that has been sent, but not acknowledged. */
	__u32 flight_size;

869 870
	__u32 burst_limited;	/* Holds old cwnd when max.burst is applied */

L
Linus Torvalds 已提交
871 872 873 874 875 876 877 878
	/* Destination */
	struct dst_entry *dst;
	/* Source address. */
	union sctp_addr saddr;

	/* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
	 * the destination address every heartbeat interval.
	 */
879
	unsigned long hbinterval;
880 881

	/* SACK delay timeout */
882
	unsigned long sackdelay;
883
	__u32 sackfreq;
L
Linus Torvalds 已提交
884

885 886
	atomic_t mtu_info;

887 888
	/* When was the last time that we heard from this transport? We use
	 * this to pick new active and retran paths.
L
Linus Torvalds 已提交
889
	 */
890
	ktime_t last_time_heard;
L
Linus Torvalds 已提交
891

892 893 894 895 896
	/* When was the last time that we sent a chunk using this
	 * transport? We use this to check for idle transports
	 */
	unsigned long last_time_sent;

L
Linus Torvalds 已提交
897 898 899 900 901
	/* Last time(in jiffies) when cwnd is reduced due to the congestion
	 * indication based on ECNE chunk.
	 */
	unsigned long last_time_ecne_reduced;

902 903
	/* This is the max_retrans value for the transport and will
	 * be initialized from the assocs value.  This can be changed
904
	 * using the SCTP_SET_PEER_ADDR_PARAMS socket option.
905 906 907
	 */
	__u16 pathmaxrxt;

908 909 910
	__u32 flowlabel;
	__u8  dscp;

911 912 913 914 915
	/* This is the partially failed retrans value for the transport
	 * and will be initialized from the assocs value.  This can be changed
	 * using the SCTP_PEER_ADDR_THLDS socket option
	 */
	int pf_retrans;
916 917 918
	/* PMTU	      : The current known path MTU.  */
	__u32 pathmtu;

J
Joe Perches 已提交
919
	/* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
920 921
	__u32 param_flags;

F
Frank Filz 已提交
922 923 924 925
	/* The number of times INIT has been sent on this transport. */
	int init_sent_count;

	/* state       : The current state of this destination,
926
	 *             : i.e. SCTP_ACTIVE, SCTP_INACTIVE, SCTP_UNKNOWN.
L
Linus Torvalds 已提交
927
	 */
F
Frank Filz 已提交
928
	int state;
L
Linus Torvalds 已提交
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945

	/* These are the error stats for this destination.  */

	/* Error count : The current error count for this destination.	*/
	unsigned short error_count;

	/* Per	       : A timer used by each destination.
	 * Destination :
	 * Timer       :
	 *
	 * [Everywhere else in the text this is called T3-rtx. -ed]
	 */
	struct timer_list T3_rtx_timer;

	/* Heartbeat timer is per destination. */
	struct timer_list hb_timer;

946 947 948
	/* Timer to handle ICMP proto unreachable envets */
	struct timer_list proto_unreach_timer;

X
Xin Long 已提交
949 950 951
	/* Timer to handler reconf chunk rtx */
	struct timer_list reconf_timer;

L
Linus Torvalds 已提交
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
	/* Since we're using per-destination retransmission timers
	 * (see above), we're also using per-destination "transmitted"
	 * queues.  This probably ought to be a private struct
	 * accessible only within the outqueue, but it's not, yet.
	 */
	struct list_head transmitted;

	/* We build bundle-able packets for this transport here.  */
	struct sctp_packet packet;

	/* This is the list of transports that have chunks to send.  */
	struct list_head send_ready;

	/* State information saved for SFR_CACC algorithm. The key
	 * idea in SFR_CACC is to maintain state at the sender on a
	 * per-destination basis when a changeover happens.
	 *	char changeover_active;
	 *	char cycling_changeover;
	 *	__u32 next_tsn_at_change;
	 *	char cacc_saw_newack;
	 */
	struct {
		/* An unsigned integer, which stores the next TSN to be
		 * used by the sender, at the moment of changeover.
		 */
		__u32 next_tsn_at_change;

		/* A flag which indicates the occurrence of a changeover */
		char changeover_active;

		/* A flag which indicates whether the change of primary is
		 * the first switch to this destination address during an
		 * active switch.
		 */
		char cycling_changeover;

		/* A temporary flag, which is used during the processing of
		 * a SACK to estimate the causative TSN(s)'s group.
		 */
		char cacc_saw_newack;
	} cacc;
993 994 995

	/* 64-bit random number sent with heartbeat. */
	__u64 hb_nonce;
996 997

	struct rcu_head rcu;
L
Linus Torvalds 已提交
998 999
};

1000
struct sctp_transport *sctp_transport_new(struct net *, const union sctp_addr *,
A
Al Viro 已提交
1001
					  gfp_t);
L
Linus Torvalds 已提交
1002 1003 1004 1005
void sctp_transport_set_owner(struct sctp_transport *,
			      struct sctp_association *);
void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
			  struct sctp_sock *);
1006
void sctp_transport_pmtu(struct sctp_transport *, struct sock *sk);
L
Linus Torvalds 已提交
1007
void sctp_transport_free(struct sctp_transport *);
1008 1009
void sctp_transport_reset_t3_rtx(struct sctp_transport *);
void sctp_transport_reset_hb_timer(struct sctp_transport *);
X
Xin Long 已提交
1010
void sctp_transport_reset_reconf_timer(struct sctp_transport *transport);
1011
int sctp_transport_hold(struct sctp_transport *);
L
Linus Torvalds 已提交
1012 1013 1014
void sctp_transport_put(struct sctp_transport *);
void sctp_transport_update_rto(struct sctp_transport *, __u32);
void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32);
1015 1016
void sctp_transport_lower_cwnd(struct sctp_transport *t,
			       enum sctp_lower_cwnd reason);
1017 1018
void sctp_transport_burst_limited(struct sctp_transport *);
void sctp_transport_burst_reset(struct sctp_transport *);
L
Linus Torvalds 已提交
1019
unsigned long sctp_transport_timeout(struct sctp_transport *);
1020
void sctp_transport_reset(struct sctp_transport *t);
1021
bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu);
1022
void sctp_transport_immediate_rtx(struct sctp_transport *);
1023 1024
void sctp_transport_dst_release(struct sctp_transport *t);
void sctp_transport_dst_confirm(struct sctp_transport *t);
L
Linus Torvalds 已提交
1025 1026 1027 1028 1029 1030 1031 1032 1033


/* This is the structure we use to queue packets as they come into
 * SCTP.  We write packets to it and read chunks from it.
 */
struct sctp_inq {
	/* This is actually a queue of sctp_chunk each
	 * containing a partially decoded packet.
	 */
1034
	struct list_head in_chunk_list;
L
Linus Torvalds 已提交
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
	/* This is the packet which is currently off the in queue and is
	 * being worked on through the inbound chunk processing.
	 */
	struct sctp_chunk *in_progress;

	/* This is the delayed task to finish delivering inbound
	 * messages.
	 */
	struct work_struct immediate;
};

void sctp_inq_init(struct sctp_inq *);
void sctp_inq_free(struct sctp_inq *);
void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet);
struct sctp_chunk *sctp_inq_pop(struct sctp_inq *);
1050
struct sctp_chunkhdr *sctp_inq_peek(struct sctp_inq *);
D
David Howells 已提交
1051
void sctp_inq_set_th_handler(struct sctp_inq *, work_func_t);
L
Linus Torvalds 已提交
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075

/* This is the structure we use to hold outbound chunks.  You push
 * chunks in and they automatically pop out the other end as bundled
 * packets (it calls (*output_handler)()).
 *
 * This structure covers sections 6.3, 6.4, 6.7, 6.8, 6.10, 7., 8.1,
 * and 8.2 of the v13 draft.
 *
 * It handles retransmissions.	The connection to the timeout portion
 * of the state machine is through sctp_..._timeout() and timeout_handler.
 *
 * If you feed it SACKs, it will eat them.
 *
 * If you give it big chunks, it will fragment them.
 *
 * It assigns TSN's to data chunks.  This happens at the last possible
 * instant before transmission.
 *
 * When free()'d, it empties itself out via output_handler().
 */
struct sctp_outq {
	struct sctp_association *asoc;

	/* Data pending that has never been transmitted.  */
1076
	struct list_head out_chunk_list;
L
Linus Torvalds 已提交
1077

1078 1079 1080
	/* Stream scheduler being used */
	struct sctp_sched_ops *sched;

1081
	unsigned int out_qlen;	/* Total length of queued data chunks. */
L
Linus Torvalds 已提交
1082 1083

	/* Error of send failed, may used in SCTP_SEND_FAILED event. */
1084
	unsigned int error;
L
Linus Torvalds 已提交
1085 1086

	/* These are control chunks we want to send.  */
1087
	struct list_head control_chunk_list;
L
Linus Torvalds 已提交
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106

	/* These are chunks that have been sacked but are above the
	 * CTSN, or cumulative tsn ack point.
	 */
	struct list_head sacked;

	/* Put chunks on this list to schedule them for
	 * retransmission.
	 */
	struct list_head retransmit;

	/* Put chunks on this list to save them for FWD TSN processing as
	 * they were abandoned.
	 */
	struct list_head abandoned;

	/* How many unackd bytes do we have in-flight?	*/
	__u32 outstanding_bytes;

1107 1108 1109
	/* Are we doing fast-rtx on this queue */
	char fast_rtx;

L
Linus Torvalds 已提交
1110 1111 1112 1113 1114 1115 1116
	/* Corked? */
	char cork;
};

void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
void sctp_outq_teardown(struct sctp_outq *);
void sctp_outq_free(struct sctp_outq*);
1117
void sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk, gfp_t);
1118
int sctp_outq_sack(struct sctp_outq *, struct sctp_chunk *);
L
Linus Torvalds 已提交
1119 1120 1121
int sctp_outq_is_empty(const struct sctp_outq *);
void sctp_outq_restart(struct sctp_outq *);

1122 1123
void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
		     enum sctp_retransmit_reason reason);
L
Linus Torvalds 已提交
1124
void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
1125
void sctp_outq_uncork(struct sctp_outq *, gfp_t gfp);
X
Xin Long 已提交
1126 1127
void sctp_prsctp_prune(struct sctp_association *asoc,
		       struct sctp_sndrcvinfo *sinfo, int msg_len);
1128
void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
L
Linus Torvalds 已提交
1129 1130 1131 1132 1133 1134
/* Uncork and flush an outqueue.  */
static inline void sctp_outq_cork(struct sctp_outq *q)
{
	q->cork = 1;
}

1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
/* SCTP skb control block.
 * sctp_input_cb is currently used on rx and sock rx queue
 */
struct sctp_input_cb {
	union {
		struct inet_skb_parm	h4;
#if IS_ENABLED(CONFIG_IPV6)
		struct inet6_skb_parm	h6;
#endif
	} header;
	struct sctp_chunk *chunk;
1146
	struct sctp_af *af;
1147 1148 1149
};
#define SCTP_INPUT_CB(__skb)	((struct sctp_input_cb *)&((__skb)->cb[0]))

1150 1151 1152 1153 1154
struct sctp_output_cb {
	struct sk_buff *last;
};
#define SCTP_OUTPUT_CB(__skb)	((struct sctp_output_cb *)&((__skb)->cb[0]))

1155 1156 1157 1158 1159 1160 1161
static inline const struct sk_buff *sctp_gso_headskb(const struct sk_buff *skb)
{
	const struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;

	return chunk->head_skb ? : skb;
}

L
Linus Torvalds 已提交
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
/* These bind address data fields common between endpoints and associations */
struct sctp_bind_addr {

	/* RFC 2960 12.1 Parameters necessary for the SCTP instance
	 *
	 * SCTP Port:	The local SCTP port number the endpoint is
	 *		bound to.
	 */
	__u16 port;

	/* RFC 2960 12.1 Parameters necessary for the SCTP instance
	 *
	 * Address List: The list of IP addresses that this instance
	 *	has bound.  This information is passed to one's
	 *	peer(s) in INIT and INIT ACK chunks.
	 */
	struct list_head address_list;
};

void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
void sctp_bind_addr_free(struct sctp_bind_addr *);
1183
int sctp_bind_addr_copy(struct net *net, struct sctp_bind_addr *dest,
L
Linus Torvalds 已提交
1184
			const struct sctp_bind_addr *src,
X
Xin Long 已提交
1185
			enum sctp_scope scope, gfp_t gfp,
A
Alexey Dobriyan 已提交
1186
			int flags);
1187 1188 1189
int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
			const struct sctp_bind_addr *src,
			gfp_t gfp);
L
Linus Torvalds 已提交
1190
int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
1191
		       int new_size, __u8 addr_state, gfp_t gfp);
1192
int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
L
Linus Torvalds 已提交
1193 1194
int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *,
			 struct sctp_sock *);
1195 1196
int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
			 struct sctp_sock *, struct sctp_sock *);
1197 1198
int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
			 const union sctp_addr *addr);
1199 1200
int sctp_bind_addrs_check(struct sctp_sock *sp,
			  struct sctp_sock *sp2, int cnt2);
L
Linus Torvalds 已提交
1201 1202 1203 1204 1205
union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr	*bp,
					const union sctp_addr	*addrs,
					int			addrcnt,
					struct sctp_sock	*opt);
union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
A
Alexey Dobriyan 已提交
1206
					 int *addrs_len,
A
Al Viro 已提交
1207
					 gfp_t gfp);
L
Linus Torvalds 已提交
1208
int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
A
Al Viro 已提交
1209
			   __u16 port, gfp_t gfp);
L
Linus Torvalds 已提交
1210

X
Xin Long 已提交
1211 1212 1213
enum sctp_scope sctp_scope(const union sctp_addr *addr);
int sctp_in_scope(struct net *net, const union sctp_addr *addr,
		  const enum sctp_scope scope);
1214
int sctp_is_any(struct sock *sk, const union sctp_addr *addr);
1215
int sctp_is_ep_boundall(struct sock *sk);
L
Linus Torvalds 已提交
1216 1217 1218


/* What type of endpoint?  */
1219
enum sctp_endpoint_type {
L
Linus Torvalds 已提交
1220 1221
	SCTP_EP_TYPE_SOCKET,
	SCTP_EP_TYPE_ASSOCIATION,
1222
};
L
Linus Torvalds 已提交
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241

/*
 * A common base class to bridge the implmentation view of a
 * socket (usually listening) endpoint versus an association's
 * local endpoint.
 * This common structure is useful for several purposes:
 *   1) Common interface for lookup routines.
 *	a) Subfunctions work for either endpoint or association
 *	b) Single interface to lookup allows hiding the lookup lock rather
 *	   than acquiring it externally.
 *   2) Common interface for the inbound chunk handling/state machine.
 *   3) Common object handling routines for reference counting, etc.
 *   4) Disentangle association lookup from endpoint lookup, where we
 *	do not have to find our endpoint to find our association.
 *
 */

struct sctp_ep_common {
	/* Fields to help us manage our entries in the hash tables. */
1242
	struct hlist_node node;
L
Linus Torvalds 已提交
1243 1244 1245
	int hashent;

	/* Runtime type information.  What kind of endpoint is this? */
1246
	enum sctp_endpoint_type type;
L
Linus Torvalds 已提交
1247 1248 1249 1250 1251

	/* Some fields to help us manage this object.
	 *   refcnt   - Reference count access to this object.
	 *   dead     - Do not attempt to use this object.
	 */
1252
	refcount_t    refcnt;
1253
	bool	    dead;
L
Linus Torvalds 已提交
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310

	/* What socket does this endpoint belong to?  */
	struct sock *sk;

	/* This is where we receive inbound chunks.  */
	struct sctp_inq	  inqueue;

	/* This substructure includes the defining parameters of the
	 * endpoint:
	 * bind_addr.port is our shared port number.
	 * bind_addr.address_list is our set of local IP addresses.
	 */
	struct sctp_bind_addr bind_addr;
};


/* RFC Section 1.4 Key Terms
 *
 * o SCTP endpoint: The logical sender/receiver of SCTP packets. On a
 *   multi-homed host, an SCTP endpoint is represented to its peers as a
 *   combination of a set of eligible destination transport addresses to
 *   which SCTP packets can be sent and a set of eligible source
 *   transport addresses from which SCTP packets can be received.
 *   All transport addresses used by an SCTP endpoint must use the
 *   same port number, but can use multiple IP addresses. A transport
 *   address used by an SCTP endpoint must not be used by another
 *   SCTP endpoint. In other words, a transport address is unique
 *   to an SCTP endpoint.
 *
 * From an implementation perspective, each socket has one of these.
 * A TCP-style socket will have exactly one association on one of
 * these.  An UDP-style socket will have multiple associations hanging
 * off one of these.
 */

struct sctp_endpoint {
	/* Common substructure for endpoint and association. */
	struct sctp_ep_common base;

	/* Associations: A list of current associations and mappings
	 *	      to the data consumers for each association. This
	 *	      may be in the form of a hash table or other
	 *	      implementation dependent structure. The data
	 *	      consumers may be process identification
	 *	      information such as file descriptors, named pipe
	 *	      pointer, or table pointers dependent on how SCTP
	 *	      is implemented.
	 */
	/* This is really a list of struct sctp_association entries. */
	struct list_head asocs;

	/* Secret Key: A secret key used by this endpoint to compute
	 *	      the MAC.	This SHOULD be a cryptographic quality
	 *	      random number with a sufficient length.
	 *	      Discussion in [RFC1750] can be helpful in
	 *	      selection of the key.
	 */
1311
	__u8 secret_key[SCTP_SECRET_SIZE];
L
Linus Torvalds 已提交
1312

1313 1314 1315 1316 1317 1318
 	/* digest:  This is a digest of the sctp cookie.  This field is
 	 * 	    only used on the receive path when we try to validate
 	 * 	    that the cookie has not been tampered with.  We put
 	 * 	    this here so we pre-allocate this once and can re-use
 	 * 	    on every receive.
 	 */
V
Vlad Yasevich 已提交
1319
 	__u8 *digest;
1320
 
1321 1322
	/* sendbuf acct. policy.	*/
	__u32 sndbuf_policy;
1323 1324 1325

	/* rcvbuf acct. policy.	*/
	__u32 rcvbuf_policy;
1326 1327 1328 1329

	/* SCTP AUTH: array of the HMACs that will be allocated
	 * we need this per association so that we don't serialize
	 */
H
Herbert Xu 已提交
1330
	struct crypto_shash **auth_hmacs;
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340

	/* SCTP-AUTH: hmacs for the endpoint encoded into parameter */
	 struct sctp_hmac_algo_param *auth_hmacs_list;

	/* SCTP-AUTH: chunks to authenticate encoded into parameter */
	struct sctp_chunks_param *auth_chunk_list;

	/* SCTP-AUTH: endpoint shared keys */
	struct list_head endpoint_shared_keys;
	__u16 active_key_id;
1341
	__u8  auth_enable:1,
1342 1343
	      prsctp_enable:1,
	      reconf_enable:1;
1344 1345

	__u8  strreset_enable;
R
Richard Haines 已提交
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355

	/* Security identifiers from incoming (INIT). These are set by
	 * security_sctp_assoc_request(). These will only be used by
	 * SCTP TCP type sockets and peeled off connections as they
	 * cause a new socket to be generated. security_sctp_sk_clone()
	 * will then plug these into the new socket.
	 */

	u32 secid;
	u32 peer_secid;
L
Linus Torvalds 已提交
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
};

/* Recover the outter endpoint structure. */
static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base)
{
	struct sctp_endpoint *ep;

	ep = container_of(base, struct sctp_endpoint, base);
	return ep;
}

/* These are function signatures for manipulating endpoints.  */
A
Al Viro 已提交
1368
struct sctp_endpoint *sctp_endpoint_new(struct sock *, gfp_t);
L
Linus Torvalds 已提交
1369 1370 1371 1372 1373 1374 1375 1376
void sctp_endpoint_free(struct sctp_endpoint *);
void sctp_endpoint_put(struct sctp_endpoint *);
void sctp_endpoint_hold(struct sctp_endpoint *);
void sctp_endpoint_add_asoc(struct sctp_endpoint *, struct sctp_association *);
struct sctp_association *sctp_endpoint_lookup_assoc(
	const struct sctp_endpoint *ep,
	const union sctp_addr *paddr,
	struct sctp_transport **);
1377 1378
bool sctp_endpoint_is_peeled_off(struct sctp_endpoint *ep,
				 const union sctp_addr *paddr);
L
Linus Torvalds 已提交
1379
struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *,
1380
					struct net *, const union sctp_addr *);
1381 1382
bool sctp_has_association(struct net *net, const union sctp_addr *laddr,
			  const union sctp_addr *paddr);
L
Linus Torvalds 已提交
1383

1384 1385
int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep,
		     const struct sctp_association *asoc,
1386
		     enum sctp_cid cid, struct sctp_init_chunk *peer_init,
1387
		     struct sctp_chunk *chunk, struct sctp_chunk **err_chunk);
1388
int sctp_process_init(struct sctp_association *, struct sctp_chunk *chunk,
L
Linus Torvalds 已提交
1389
		      const union sctp_addr *peer,
1390
		      struct sctp_init_chunk *init, gfp_t gfp);
L
Linus Torvalds 已提交
1391 1392 1393
__u32 sctp_generate_tag(const struct sctp_endpoint *);
__u32 sctp_generate_tsn(const struct sctp_endpoint *);

1394 1395 1396 1397 1398 1399 1400
struct sctp_inithdr_host {
	__u32 init_tag;
	__u32 a_rwnd;
	__u16 num_outbound_streams;
	__u16 num_inbound_streams;
	__u32 initial_tsn;
};
L
Linus Torvalds 已提交
1401

1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
struct sctp_stream_priorities {
	/* List of priorities scheduled */
	struct list_head prio_sched;
	/* List of streams scheduled */
	struct list_head active;
	/* The next stream stream in line */
	struct sctp_stream_out_ext *next;
	__u16 prio;
};

1412 1413 1414
struct sctp_stream_out_ext {
	__u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
	__u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
1415
	struct list_head outq; /* chunks enqueued by this stream */
1416 1417 1418 1419 1420 1421
	union {
		struct {
			/* Scheduled streams list */
			struct list_head prio_list;
			struct sctp_stream_priorities *prio_head;
		};
1422 1423 1424 1425
		/* Fields used by RR scheduler */
		struct {
			struct list_head rr_list;
		};
1426
	};
1427 1428
};

1429
struct sctp_stream_out {
1430 1431 1432 1433
	union {
		__u32 mid;
		__u16 ssn;
	};
1434
	__u32 mid_uo;
1435
	struct sctp_stream_out_ext *ext;
1436
	__u8 state;
1437 1438 1439
};

struct sctp_stream_in {
1440 1441 1442 1443
	union {
		__u32 mid;
		__u16 ssn;
	};
1444
	__u32 mid_uo;
1445
	__u32 fsn;
1446
	__u32 fsn_uo;
1447
	char pd_mode;
1448
	char pd_mode_uo;
1449 1450 1451
};

struct sctp_stream {
K
Kent Overstreet 已提交
1452 1453 1454
	GENRADIX(struct sctp_stream_out) out;
	GENRADIX(struct sctp_stream_in)	in;

1455 1456
	__u16 outcnt;
	__u16 incnt;
1457 1458
	/* Current stream being sent, if any */
	struct sctp_stream_out *out_curr;
1459 1460 1461 1462 1463 1464
	union {
		/* Fields used by priority scheduler */
		struct {
			/* List of priorities scheduled */
			struct list_head prio_list;
		};
1465 1466 1467 1468 1469 1470 1471
		/* Fields used by RR scheduler */
		struct {
			/* List of streams scheduled */
			struct list_head rr_list;
			/* The next stream stream in line */
			struct sctp_stream_out_ext *rr_next;
		};
1472
	};
1473
	struct sctp_stream_interleave *si;
1474 1475
};

1476
static inline struct sctp_stream_out *sctp_stream_out(
K
Kent Overstreet 已提交
1477
	struct sctp_stream *stream,
1478 1479
	__u16 sid)
{
K
Kent Overstreet 已提交
1480
	return genradix_ptr(&stream->out, sid);
1481 1482 1483
}

static inline struct sctp_stream_in *sctp_stream_in(
K
Kent Overstreet 已提交
1484
	struct sctp_stream *stream,
1485 1486
	__u16 sid)
{
K
Kent Overstreet 已提交
1487
	return genradix_ptr(&stream->in, sid);
1488 1489 1490 1491 1492
}

#define SCTP_SO(s, i) sctp_stream_out((s), (i))
#define SCTP_SI(s, i) sctp_stream_in((s), (i))

1493 1494 1495
#define SCTP_STREAM_CLOSED		0x00
#define SCTP_STREAM_OPEN		0x01

1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
static inline __u16 sctp_datachk_len(const struct sctp_stream *stream)
{
	return stream->si->data_chunk_len;
}

static inline __u16 sctp_datahdr_len(const struct sctp_stream *stream)
{
	return stream->si->data_chunk_len - sizeof(struct sctp_chunkhdr);
}

1506 1507 1508 1509 1510 1511 1512 1513 1514 1515
static inline __u16 sctp_ftsnchk_len(const struct sctp_stream *stream)
{
	return stream->si->ftsn_chunk_len;
}

static inline __u16 sctp_ftsnhdr_len(const struct sctp_stream *stream)
{
	return stream->si->ftsn_chunk_len - sizeof(struct sctp_chunkhdr);
}

1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
/* SCTP_GET_ASSOC_STATS counters */
struct sctp_priv_assoc_stats {
	/* Maximum observed rto in the association during subsequent
	 * observations. Value is set to 0 if no RTO measurement took place
	 * The transport where the max_rto was observed is returned in
	 * obs_rto_ipaddr
	 */
	struct sockaddr_storage obs_rto_ipaddr;
	__u64 max_obs_rto;
	/* Total In and Out SACKs received and sent */
	__u64 isacks;
	__u64 osacks;
	/* Total In and Out packets received and sent */
	__u64 opackets;
	__u64 ipackets;
	/* Total retransmitted chunks */
	__u64 rtxchunks;
	/* TSN received > next expected */
	__u64 outofseqtsns;
	/* Duplicate Chunks received */
	__u64 idupchunks;
	/* Gap Ack Blocks received */
	__u64 gapcnt;
	/* Unordered data chunks sent and received */
	__u64 ouodchunks;
	__u64 iuodchunks;
	/* Ordered data chunks sent and received */
	__u64 oodchunks;
	__u64 iodchunks;
	/* Control chunks sent and received */
	__u64 octrlchunks;
	__u64 ictrlchunks;
};

L
Linus Torvalds 已提交
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
/* RFC2960
 *
 * 12. Recommended Transmission Control Block (TCB) Parameters
 *
 * This section details a recommended set of parameters that should
 * be contained within the TCB for an implementation. This section is
 * for illustrative purposes and should not be deemed as requirements
 * on an implementation or as an exhaustive list of all parameters
 * inside an SCTP TCB. Each implementation may need its own additional
 * parameters for optimization.
 */


/* Here we have information about each individual association. */
struct sctp_association {

	/* A base structure common to endpoint and association.
	 * In this context, it represents the associations's view
	 * of the local endpoint of the association.
	 */
	struct sctp_ep_common base;

	/* Associations on the same socket. */
	struct list_head asocs;

	/* association id. */
	sctp_assoc_t assoc_id;

	/* This is our parent endpoint.	 */
	struct sctp_endpoint *ep;

	/* These are those association elements needed in the cookie.  */
	struct sctp_cookie c;

	/* This is all information about our peer.  */
	struct {
		/* transport_addr_list
		 *
		 * Peer	       : A list of SCTP transport addresses that the
		 * Transport   : peer is bound to. This information is derived
		 * Address     : from the INIT or INIT ACK and is used to
		 * List	       : associate an inbound packet with a given
		 *	       : association. Normally this information is
		 *	       : hashed or keyed for quick lookup and access
		 *	       : of the TCB.
F
Frank Filz 已提交
1595 1596 1597
		 *	       : The list is also initialized with the list
		 *	       : of addresses passed with the sctp_connectx()
		 *	       : call.
L
Linus Torvalds 已提交
1598 1599 1600 1601 1602
		 *
		 * It is a list of SCTP_transport's.
		 */
		struct list_head transport_addr_list;

1603 1604 1605 1606 1607 1608
		/* rwnd
		 *
		 * Peer Rwnd   : Current calculated value of the peer's rwnd.
		 */
		__u32 rwnd;

F
Frank Filz 已提交
1609 1610 1611 1612 1613 1614 1615 1616 1617
		/* transport_count
		 *
		 * Peer        : A count of the number of peer addresses
		 * Transport   : in the Peer Transport Address List.
		 * Address     :
		 * Count       :
		 */
		__u16 transport_count;

L
Linus Torvalds 已提交
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
		/* port
		 *   The transport layer port number.
		 */
		__u16 port;

		/* primary_path
		 *
		 * Primary     : This is the current primary destination
		 * Path	       : transport address of the peer endpoint.  It
		 *	       : may also specify a source transport address
		 *	       : on this endpoint.
		 *
		 * All of these paths live on transport_addr_list.
		 *
		 * At the bakeoffs, we discovered that the intent of
		 * primaryPath is that it only changes when the ULP
		 * asks to have it changed.  We add the activePath to
		 * designate the connection we are currently using to
		 * transmit new data and most control chunks.
		 */
		struct sctp_transport *primary_path;

		/* Cache the primary path address here, when we
		 * need a an address for msg_name.
		 */
		union sctp_addr primary_addr;

		/* active_path
		 *   The path that we are currently using to
		 *   transmit new data and most control chunks.
		 */
		struct sctp_transport *active_path;

		/* retran_path
		 *
		 * RFC2960 6.4 Multi-homed SCTP Endpoints
		 * ...
		 * Furthermore, when its peer is multi-homed, an
		 * endpoint SHOULD try to retransmit a chunk to an
		 * active destination transport address that is
		 * different from the last destination address to
		 * which the DATA chunk was sent.
		 */
		struct sctp_transport *retran_path;

		/* Pointer to last transport I have sent on.  */
		struct sctp_transport *last_sent_to;

		/* This is the last transport I have received DATA on.	*/
		struct sctp_transport *last_data_from;

		/*
		 * Mapping  An array of bits or bytes indicating which out of
		 * Array    order TSN's have been received (relative to the
		 *	    Last Rcvd TSN). If no gaps exist, i.e. no out of
		 *	    order packets have been received, this array
		 *	    will be set to all zero. This structure may be
		 *	    in the form of a circular buffer or bit array.
		 *
		 * Last Rcvd   : This is the last TSN received in
		 * TSN	       : sequence. This value is set initially by
		 *	       : taking the peer's Initial TSN, received in
		 *	       : the INIT or INIT ACK chunk, and subtracting
		 *	       : one from it.
		 *
		 * Throughout most of the specification this is called the
		 * "Cumulative TSN ACK Point".	In this case, we
		 * ignore the advice in 12.2 in favour of the term
		 * used in the bulk of the text.  This value is hidden
		 * in tsn_map--we get it by calling sctp_tsnmap_get_ctsn().
		 */
		struct sctp_tsnmap tsn_map;

1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702
		/* This mask is used to disable sending the ASCONF chunk
		 * with specified parameter to peer.
		 */
		__be16 addip_disabled_mask;

		/* These are capabilities which our peer advertised.  */
		__u8	ecn_capable:1,      /* Can peer do ECN? */
			ipv4_address:1,     /* Peer understands IPv4 addresses? */
			ipv6_address:1,     /* Peer understands IPv6 addresses? */
			hostname_address:1, /* Peer understands DNS addresses? */
			asconf_capable:1,   /* Does peer support ADDIP? */
			prsctp_capable:1,   /* Can peer do PR-SCTP? */
1703
			reconf_capable:1,   /* Can peer do RE-CONFIG? */
1704 1705
			auth_capable:1;     /* Is peer doing SCTP-AUTH? */

1706
		/* sack_needed : This flag indicates if the next received
L
Linus Torvalds 已提交
1707
		 *             : packet is to be responded to with a
1708 1709
		 *             : SACK. This is initialized to 0.  When a packet
		 *             : is received sack_cnt is incremented. If this value
L
Linus Torvalds 已提交
1710 1711 1712 1713 1714 1715
		 *             : reaches 2 or more, a SACK is sent and the
		 *             : value is reset to 0. Note: This is used only
		 *             : when no DATA chunks are received out of
		 *             : order.  When DATA chunks are out of order,
		 *             : SACK's are not delayed (see Section 6).
		 */
1716
		__u8    sack_needed:1,     /* Do we need to sack the peer? */
1717 1718
			sack_generation:1,
			zero_window_announced:1;
1719
		__u32	sack_cnt;
L
Linus Torvalds 已提交
1720

1721
		__u32   adaptation_ind;	 /* Adaptation Code point. */
L
Linus Torvalds 已提交
1722

1723
		struct sctp_inithdr_host i;
L
Linus Torvalds 已提交
1724
		void *cookie;
1725
		int cookie_len;
L
Linus Torvalds 已提交
1726 1727 1728 1729 1730 1731

		/* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
		 * C1) ... "Peer-Serial-Number'. This value MUST be initialized to the
		 * Initial TSN Value minus 1
		 */
		__u32 addip_serial;
1732 1733 1734 1735 1736

		/* SCTP-AUTH: We need to know pears random number, hmac list
		 * and authenticated chunk list.  All that is part of the
		 * cookie and these are just pointers to those locations
		 */
1737
		struct sctp_random_param *peer_random;
1738
		struct sctp_chunks_param *peer_chunks;
1739
		struct sctp_hmac_algo_param *peer_hmacs;
L
Linus Torvalds 已提交
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
	} peer;

	/* State       : A state variable indicating what state the
	 *	       : association is in, i.e. COOKIE-WAIT,
	 *	       : COOKIE-ECHOED, ESTABLISHED, SHUTDOWN-PENDING,
	 *	       : SHUTDOWN-SENT, SHUTDOWN-RECEIVED, SHUTDOWN-ACK-SENT.
	 *
	 *		Note: No "CLOSED" state is illustrated since if a
	 *		association is "CLOSED" its TCB SHOULD be removed.
	 *
	 *		In this implementation we DO have a CLOSED
	 *		state which is used during initiation and shutdown.
	 *
	 *		State takes values from SCTP_STATE_*.
	 */
X
Xin Long 已提交
1755
	enum sctp_state state;
L
Linus Torvalds 已提交
1756 1757 1758 1759 1760 1761

	/* Overall     : The overall association error count.
	 * Error Count : [Clear this any time I get something.]
	 */
	int overall_error_count;

1762 1763 1764
	/* The cookie life I award for any cookie.  */
	ktime_t cookie_life;

L
Linus Torvalds 已提交
1765 1766 1767 1768
	/* These are the association's initial, max, and min RTO values.
	 * These values will be initialized by system defaults, but can
	 * be modified via the SCTP_RTOINFO socket option.
	 */
1769 1770 1771
	unsigned long rto_initial;
	unsigned long rto_max;
	unsigned long rto_min;
L
Linus Torvalds 已提交
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781

	/* Maximum number of new data packets that can be sent in a burst.  */
	int max_burst;

	/* This is the max_retrans value for the association.  This value will
	 * be initialized initialized from system defaults, but can be
	 * modified by the SCTP_ASSOCINFO socket option.
	 */
	int max_retrans;

1782 1783 1784 1785 1786 1787
	/* This is the partially failed retrans value for the transport
	 * and will be initialized from the assocs value.  This can be
	 * changed using the SCTP_PEER_ADDR_THLDS socket option
	 */
	int pf_retrans;

L
Linus Torvalds 已提交
1788 1789 1790 1791 1792 1793 1794
	/* Maximum number of times the endpoint will retransmit INIT  */
	__u16 max_init_attempts;

	/* How many times have we resent an INIT? */
	__u16 init_retries;

	/* The largest timeout or RTO value to use in attempting an INIT */
1795
	unsigned long max_init_timeo;
L
Linus Torvalds 已提交
1796

1797 1798 1799 1800
	/* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
	 * the destination address every heartbeat interval. This value
	 * will be inherited by all new transports.
	 */
1801
	unsigned long hbinterval;
1802 1803 1804 1805 1806 1807

	/* This is the max_retrans value for new transports in the
	 * association.
	 */
	__u16 pathmaxrxt;

1808 1809 1810
	__u32 flowlabel;
	__u8  dscp;

1811 1812 1813
	/* Flag that path mtu update is pending */
	__u8   pmtu_pending;

1814 1815 1816 1817 1818
	/* Association : The smallest PMTU discovered for all of the
	 * PMTU	       : peer's transport addresses.
	 */
	__u32 pathmtu;

J
Joe Perches 已提交
1819
	/* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
1820 1821
	__u32 param_flags;

1822
	__u32 sackfreq;
1823 1824 1825 1826
	/* SACK delay timeout */
	unsigned long sackdelay;

	unsigned long timeouts[SCTP_NUM_TIMEOUT_TYPES];
L
Linus Torvalds 已提交
1827 1828 1829 1830 1831
	struct timer_list timers[SCTP_NUM_TIMEOUT_TYPES];

	/* Transport to which SHUTDOWN chunk was last sent.  */
	struct sctp_transport *shutdown_last_sent_to;

F
Frank Filz 已提交
1832 1833 1834
	/* Transport to which INIT chunk was last sent.  */
	struct sctp_transport *init_last_sent_to;

1835 1836 1837
	/* How many times have we resent a SHUTDOWN */
	int shutdown_retries;

L
Linus Torvalds 已提交
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
	/* Next TSN    : The next TSN number to be assigned to a new
	 *	       : DATA chunk.  This is sent in the INIT or INIT
	 *	       : ACK chunk to the peer and incremented each
	 *	       : time a DATA chunk is assigned a TSN
	 *	       : (normally just prior to transmit or during
	 *	       : fragmentation).
	 */
	__u32 next_tsn;

	/*
	 * Last Rcvd   : This is the last TSN received in sequence.  This value
	 * TSN	       : is set initially by taking the peer's Initial TSN,
	 *	       : received in the INIT or INIT ACK chunk, and
	 *	       : subtracting one from it.
	 *
	 * Most of RFC 2960 refers to this as the Cumulative TSN Ack Point.
	 */

	__u32 ctsn_ack_point;

	/* PR-SCTP Advanced.Peer.Ack.Point */
	__u32 adv_peer_ack_point;

	/* Highest TSN that is acknowledged by incoming SACKs. */
	__u32 highest_sacked;

1864 1865 1866 1867 1868 1869
	/* TSN marking the fast recovery exit point */
	__u32 fast_recovery_exit;

	/* Flag to track the current fast recovery state */
	__u8 fast_recovery;

L
Linus Torvalds 已提交
1870 1871 1872 1873 1874
	/* The number of unacknowledged data chunks.  Reported through
	 * the SCTP_STATUS sockopt.
	 */
	__u16 unack_data;

1875 1876 1877 1878 1879
	/* The total number of data chunks that we've had to retransmit
	 * as the result of a T3 timer expiration
	 */
	__u32 rtx_data_chunks;

L
Linus Torvalds 已提交
1880 1881 1882 1883 1884 1885 1886 1887
	/* This is the association's receive buffer space.  This value is used
	 * to set a_rwnd field in an INIT or a SACK chunk.
	 */
	__u32 rwnd;

	/* This is the last advertised value of rwnd over a SACK chunk. */
	__u32 a_rwnd;

1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
	/* Number of bytes by which the rwnd has slopped.  The rwnd is allowed
	 * to slop over a maximum of the association's frag_point.
	 */
	__u32 rwnd_over;

	/* Keeps treack of rwnd pressure.  This happens when we have
	 * a window, but not recevie buffer (i.e small packets).  This one
	 * is releases slowly (1 PMTU at a time ).
	 */
	__u32 rwnd_press;

L
Linus Torvalds 已提交
1899 1900 1901 1902 1903 1904
	/* This is the sndbuf size in use for the association.
	 * This corresponds to the sndbuf size for the association,
	 * as specified in the sk->sndbuf.
	 */
	int sndbuf_used;

1905 1906 1907 1908 1909
	/* This is the amount of memory that this association has allocated
	 * in the receive path at any given time.
	 */
	atomic_t rmem_alloc;

L
Linus Torvalds 已提交
1910 1911 1912 1913 1914 1915 1916
	/* This is the wait queue head for send requests waiting on
	 * the association sndbuf space.
	 */
	wait_queue_head_t	wait;

	/* The message size at which SCTP fragmentation will occur. */
	__u32 frag_point;
1917
	__u32 user_frag;
L
Linus Torvalds 已提交
1918

F
Frank Filz 已提交
1919 1920 1921 1922 1923
	/* Counter used to count INIT errors. */
	int init_err_counter;

	/* Count the number of INIT cycles (for doubling timeout). */
	int init_cycle;
L
Linus Torvalds 已提交
1924 1925 1926 1927 1928 1929 1930 1931

	/* Default send parameters. */
	__u16 default_stream;
	__u16 default_flags;
	__u32 default_ppid;
	__u32 default_context;
	__u32 default_timetolive;

1932 1933 1934
	/* Default receive parameters */
	__u32 default_rcv_context;

1935
	/* Stream arrays */
1936
	struct sctp_stream stream;
L
Linus Torvalds 已提交
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979

	/* All outbound chunks go through this structure.  */
	struct sctp_outq outqueue;

	/* A smart pipe that will handle reordering and fragmentation,
	 * as well as handle passing events up to the ULP.
	 */
	struct sctp_ulpq ulpq;

	/* Last TSN that caused an ECNE Chunk to be sent.  */
	__u32 last_ecne_tsn;

	/* Last TSN that caused a CWR Chunk to be sent.	 */
	__u32 last_cwr_tsn;

	/* How many duplicated TSNs have we seen?  */
	int numduptsns;

	/* These are to support
	 * "SCTP Extensions for Dynamic Reconfiguration of IP Addresses
	 *  and Enforcement of Flow and Message Limits"
	 * <draft-ietf-tsvwg-addip-sctp-02.txt>
	 * or "ADDIP" for short.
	 */



	/* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
	 *
	 * R1) One and only one ASCONF Chunk MAY be in transit and
	 * unacknowledged at any one time.  If a sender, after sending
	 * an ASCONF chunk, decides it needs to transfer another
	 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
	 * returns from the previous ASCONF Chunk before sending a
	 * subsequent ASCONF. Note this restriction binds each side,
	 * so at any time two ASCONF may be in-transit on any given
	 * association (one sent from each endpoint).
	 *
	 * [This is our one-and-only-one ASCONF in flight.  If we do
	 * not have an ASCONF in flight, this is NULL.]
	 */
	struct sctp_chunk *addip_last_asconf;

1980
	/* ADDIP Section 5.2 Upon reception of an ASCONF Chunk.
L
Linus Torvalds 已提交
1981
	 *
1982 1983
	 * This is needed to implement itmes E1 - E4 of the updated
	 * spec.  Here is the justification:
L
Linus Torvalds 已提交
1984
	 *
1985 1986 1987
	 * Since the peer may bundle multiple ASCONF chunks toward us,
	 * we now need the ability to cache multiple ACKs.  The section
	 * describes in detail how they are cached and cleaned up.
L
Linus Torvalds 已提交
1988
	 */
1989
	struct list_head asconf_ack_list;
L
Linus Torvalds 已提交
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

	/* These ASCONF chunks are waiting to be sent.
	 *
	 * These chunaks can't be pushed to outqueue until receiving
	 * ASCONF_ACK for the previous ASCONF indicated by
	 * addip_last_asconf, so as to guarantee that only one ASCONF
	 * is in flight at any time.
	 *
	 * ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
	 *
	 * In defining the ASCONF Chunk transfer procedures, it is
	 * essential that these transfers MUST NOT cause congestion
	 * within the network.	To achieve this, we place these
	 * restrictions on the transfer of ASCONF Chunks:
	 *
	 * R1) One and only one ASCONF Chunk MAY be in transit and
	 * unacknowledged at any one time.  If a sender, after sending
	 * an ASCONF chunk, decides it needs to transfer another
	 * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
	 * returns from the previous ASCONF Chunk before sending a
	 * subsequent ASCONF. Note this restriction binds each side,
	 * so at any time two ASCONF may be in-transit on any given
	 * association (one sent from each endpoint).
	 *
	 *
	 * [I really think this is EXACTLY the sort of intelligence
	 *  which already resides in sctp_outq.	 Please move this
	 *  queue and its supporting logic down there.	--piggy]
	 */
2019
	struct list_head addip_chunk_list;
L
Linus Torvalds 已提交
2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041

	/* ADDIP Section 4.1 ASCONF Chunk Procedures
	 *
	 * A2) A serial number should be assigned to the Chunk. The
	 * serial number SHOULD be a monotonically increasing
	 * number. The serial number SHOULD be initialized at
	 * the start of the association to the same value as the
	 * Initial TSN and every time a new ASCONF chunk is created
	 * it is incremented by one after assigning the serial number
	 * to the newly created chunk.
	 *
	 * ADDIP
	 * 3.1.1  Address/Stream Configuration Change Chunk (ASCONF)
	 *
	 * Serial Number : 32 bits (unsigned integer)
	 *
	 * This value represents a Serial Number for the ASCONF
	 * Chunk. The valid range of Serial Number is from 0 to
	 * 4294967295 (2^32 - 1).  Serial Numbers wrap back to 0
	 * after reaching 4294967295.
	 */
	__u32 addip_serial;
2042
	int src_out_of_asoc_ok;
2043
	union sctp_addr *asconf_addr_del_pending;
2044
	struct sctp_transport *new_transport;
L
Linus Torvalds 已提交
2045

2046 2047 2048 2049 2050 2051 2052 2053 2054 2055
	/* SCTP AUTH: list of the endpoint shared keys.  These
	 * keys are provided out of band by the user applicaton
	 * and can't change during the lifetime of the association
	 */
	struct list_head endpoint_shared_keys;

	/* SCTP AUTH:
	 * The current generated assocaition shared key (secret)
	 */
	struct sctp_auth_bytes *asoc_shared_key;
X
Xin Long 已提交
2056
	struct sctp_shared_key *shkey;
2057 2058 2059 2060 2061 2062 2063 2064

	/* SCTP AUTH: hmac id of the first peer requested algorithm
	 * that we support.
	 */
	__u16 default_hmac_id;

	__u16 active_key_id;

2065
	__u8 need_ecne:1,	/* Need to send an ECNE Chunk? */
2066
	     temp:1,		/* Is it a temporary association? */
2067
	     force_delay:1,
2068
	     intl_enable:1,
2069 2070
	     prsctp_enable:1,
	     reconf_enable:1;
2071

2072
	__u8 strreset_enable;
2073
	__u8 strreset_outstanding; /* request param count on the fly */
2074

2075 2076
	__u32 strreset_outseq; /* Update after receiving response */
	__u32 strreset_inseq; /* Update after receiving request */
2077
	__u32 strreset_result[2]; /* save the results of last 2 responses */
2078

X
Xin Long 已提交
2079 2080
	struct sctp_chunk *strreset_chunk; /* save request chunk */

2081
	struct sctp_priv_assoc_stats stats;
2082

X
Xin Long 已提交
2083 2084
	int sent_cnt_removable;

X
Xin Long 已提交
2085 2086
	__u16 subscribe;

2087 2088
	__u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
	__u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
X
Xin Long 已提交
2089 2090

	struct rcu_head rcu;
L
Linus Torvalds 已提交
2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113
};


/* An eyecatcher for determining if we are really looking at an
 * association data structure.
 */
enum {
	SCTP_ASSOC_EYECATCHER = 0xa550c123,
};

/* Recover the outter association structure. */
static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base)
{
	struct sctp_association *asoc;

	asoc = container_of(base, struct sctp_association, base);
	return asoc;
}

/* These are function signatures for manipulating associations.	 */


struct sctp_association *
X
Xin Long 已提交
2114 2115
sctp_association_new(const struct sctp_endpoint *ep, const struct sock *sk,
		     enum sctp_scope scope, gfp_t gfp);
L
Linus Torvalds 已提交
2116 2117 2118 2119
void sctp_association_free(struct sctp_association *);
void sctp_association_put(struct sctp_association *);
void sctp_association_hold(struct sctp_association *);

2120 2121
struct sctp_transport *sctp_assoc_choose_alter_transport(
	struct sctp_association *, struct sctp_transport *);
L
Linus Torvalds 已提交
2122 2123 2124 2125 2126 2127 2128
void sctp_assoc_update_retran_path(struct sctp_association *);
struct sctp_transport *sctp_assoc_lookup_paddr(const struct sctp_association *,
					  const union sctp_addr *);
int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
			    const union sctp_addr *laddr);
struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *,
				     const union sctp_addr *address,
A
Al Viro 已提交
2129
				     const gfp_t gfp,
F
Frank Filz 已提交
2130
				     const int peer_state);
L
Linus Torvalds 已提交
2131 2132
void sctp_assoc_del_peer(struct sctp_association *asoc,
			 const union sctp_addr *addr);
F
Frank Filz 已提交
2133 2134
void sctp_assoc_rm_peer(struct sctp_association *asoc,
			 struct sctp_transport *peer);
2135 2136 2137 2138
void sctp_assoc_control_transport(struct sctp_association *asoc,
				  struct sctp_transport *transport,
				  enum sctp_transport_cmd command,
				  sctp_sn_error_t error);
L
Linus Torvalds 已提交
2139 2140
struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32);
void sctp_assoc_migrate(struct sctp_association *, struct sock *);
2141 2142
int sctp_assoc_update(struct sctp_association *old,
		      struct sctp_association *new);
L
Linus Torvalds 已提交
2143 2144 2145

__u32 sctp_association_get_next_tsn(struct sctp_association *);

2146
void sctp_assoc_update_frag_point(struct sctp_association *asoc);
2147
void sctp_assoc_set_pmtu(struct sctp_association *asoc, __u32 pmtu);
2148
void sctp_assoc_sync_pmtu(struct sctp_association *asoc);
2149 2150
void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned int);
void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned int);
L
Linus Torvalds 已提交
2151 2152
void sctp_assoc_set_primary(struct sctp_association *,
			    struct sctp_transport *);
2153 2154
void sctp_assoc_del_nonprimary_peers(struct sctp_association *,
				    struct sctp_transport *);
X
Xin Long 已提交
2155 2156
int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
				     enum sctp_scope scope, gfp_t gfp);
L
Linus Torvalds 已提交
2157
int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *,
A
Alexey Dobriyan 已提交
2158
					 struct sctp_cookie*,
A
Al Viro 已提交
2159
					 gfp_t gfp);
2160
int sctp_assoc_set_id(struct sctp_association *, gfp_t);
2161 2162 2163 2164
void sctp_assoc_clean_asconf_ack_cache(const struct sctp_association *asoc);
struct sctp_chunk *sctp_assoc_lookup_asconf_ack(
					const struct sctp_association *asoc,
					__be32 serial);
2165
void sctp_asconf_queue_teardown(struct sctp_association *asoc);
L
Linus Torvalds 已提交
2166 2167 2168 2169 2170 2171

int sctp_cmp_addr_exact(const union sctp_addr *ss1,
			const union sctp_addr *ss2);
struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc);

/* A convenience structure to parse out SCTP specific CMSGs. */
X
Xin Long 已提交
2172
struct sctp_cmsgs {
L
Linus Torvalds 已提交
2173
	struct sctp_initmsg *init;
2174 2175
	struct sctp_sndrcvinfo *srinfo;
	struct sctp_sndinfo *sinfo;
2176
	struct sctp_prinfo *prinfo;
2177
	struct sctp_authinfo *authinfo;
2178
	struct msghdr *addrs_msg;
X
Xin Long 已提交
2179
};
L
Linus Torvalds 已提交
2180 2181

/* Structure for tracking memory objects */
2182
struct sctp_dbg_objcnt_entry {
L
Linus Torvalds 已提交
2183 2184
	char *label;
	atomic_t *counter;
2185
};
L
Linus Torvalds 已提交
2186 2187

#endif /* __sctp_structs_h__ */