Skip to content
Snippets Groups Projects
structs.h 56.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • Linus Torvalds's avatar
    Linus Torvalds committed
    /* SCTP kernel reference 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 reference Implementation
     *
     * The SCTP reference 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.
     *
     * The SCTP reference 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, write to
     * the Free Software Foundation, 59 Temple Place - Suite 330,
     * Boston, MA 02111-1307, USA.
     *
     * Please send any bug reports or fixes you make to the
     * email addresses:
     *    lksctp developers <lksctp-developers@lists.sourceforge.net>
     *
     * Or submit a bug report through the following website:
     *    http://www.sf.net/projects/lksctp
     *
     * 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>
     *
     * Any bugs reported given to us we will try to fix... any fixes shared will
     * be incorporated into the next SCTP release.
     */
    
    #ifndef __sctp_structs_h__
    #define __sctp_structs_h__
    
    #include <linux/time.h>		/* We get struct timespec.    */
    #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 <asm/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.  */
    
    /* 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 sctp_ssnmap;
    
    
    #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 sctp_bind_bucket *next;
    	struct sctp_bind_bucket **pprev;
    	struct hlist_head	owner;
    };
    
    struct sctp_bind_hashbucket {
    	spinlock_t	lock;
    	struct sctp_bind_bucket	*chain;
    };
    
    /* Used for hashing all associations.  */
    struct sctp_hashbucket {
    	rwlock_t	lock;
    	struct sctp_ep_common  *chain;
    } __attribute__((__aligned__(8)));
    
    
    /* The SCTP globals structure. */
    extern struct sctp_globals {
    	/* RFC2960 Section 14. Suggested SCTP Protocol Parameter Values
    	 *
    	 * The following protocol parameters are RECOMMENDED:
    	 *
    	 * RTO.Initial		    - 3	 seconds
    	 * RTO.Min		    - 1	 second
    	 * RTO.Max		   -  60 seconds
    	 * RTO.Alpha		    - 1/8  (3 when converted to right shifts.)
    	 * RTO.Beta		    - 1/4  (2 when converted to right shifts.)
    	 */
    	__u32 rto_initial;
    	__u32 rto_min;
    	__u32 rto_max;
    
    	/* Note: rto_alpha and rto_beta are really defined as inverse
    	 * powers of two to facilitate integer operations.
    	 */
    	int rto_alpha;
    	int rto_beta;
    
    	/* Max.Burst		    - 4 */
    	int max_burst;
    
    	/* Valid.Cookie.Life	    - 60  seconds  */
    	int valid_cookie_life;
    
    	/* Whether Cookie Preservative is enabled(1) or not(0) */
    	int cookie_preserve_enable;
    
    	/* Association.Max.Retrans  - 10 attempts
    	 * Path.Max.Retrans	    - 5	 attempts (per destination address)
    	 * Max.Init.Retransmits	    - 8	 attempts
    	 */
    	int max_retrans_association;
    	int max_retrans_path;
    	int max_retrans_init;
    
    
    	/*
    	 * Policy for preforming sctp/socket accounting
    	 * 0   - do socket level accounting, all assocs share sk_sndbuf
    	 * 1   - do sctp accounting, each asoc may use sk_sndbuf bytes
    	 */
    	int sndbuf_policy;
    
    
    	/* Delayed SACK timeout  200ms default*/
    	int sack_timeout;
    
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	/* HB.interval		    - 30 seconds  */
    	int hb_interval;
    
    	/* The following variables are implementation specific.	 */
    
    	/* Default initialization values to be applied to new associations. */
    	__u16 max_instreams;
    	__u16 max_outstreams;
    
    	/* 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. */
    	int ep_hashsize;
    	struct sctp_hashbucket *ep_hashtable;
    
    	/* This is the hash of all associations. */
    	int assoc_hashsize;
    	struct sctp_hashbucket *assoc_hashtable;
    
    	/* This is the sctp port control hash.	*/
    	int port_hashsize;
    	int port_rover;
    	spinlock_t port_alloc_lock;  /* Protects port_rover. */
    	struct sctp_bind_hashbucket *port_hashtable;
    
    	/* This is the global local address list.
    	 * We actively maintain this complete list of interfaces on
    	 * the system by catching routing events.
    	 *
    	 * It is a list of sctp_sockaddr_entry.
    	 */
    	struct list_head local_addr_list;
    	spinlock_t local_addr_lock;
    	
    	/* Flag to indicate if addip is enabled. */
    	int addip_enable;
    
    	/* Flag to indicate if PR-SCTP is enabled. */
    	int prsctp_enable;
    } sctp_globals;
    
    #define sctp_rto_initial		(sctp_globals.rto_initial)
    #define sctp_rto_min			(sctp_globals.rto_min)
    #define sctp_rto_max			(sctp_globals.rto_max)
    #define sctp_rto_alpha			(sctp_globals.rto_alpha)
    #define sctp_rto_beta			(sctp_globals.rto_beta)
    #define sctp_max_burst			(sctp_globals.max_burst)
    #define sctp_valid_cookie_life		(sctp_globals.valid_cookie_life)
    #define sctp_cookie_preserve_enable	(sctp_globals.cookie_preserve_enable)
    #define sctp_max_retrans_association	(sctp_globals.max_retrans_association)
    
    #define sctp_sndbuf_policy	 	(sctp_globals.sndbuf_policy)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    #define sctp_max_retrans_path		(sctp_globals.max_retrans_path)
    #define sctp_max_retrans_init		(sctp_globals.max_retrans_init)
    
    #define sctp_sack_timeout		(sctp_globals.sack_timeout)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 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 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 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 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
    #define sctp_hb_interval		(sctp_globals.hb_interval)
    #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_assoc_hashsize		(sctp_globals.assoc_hashsize)
    #define sctp_assoc_hashtable		(sctp_globals.assoc_hashtable)
    #define sctp_port_hashsize		(sctp_globals.port_hashsize)
    #define sctp_port_rover			(sctp_globals.port_rover)
    #define sctp_port_alloc_lock		(sctp_globals.port_alloc_lock)
    #define sctp_port_hashtable		(sctp_globals.port_hashtable)
    #define sctp_local_addr_list		(sctp_globals.local_addr_list)
    #define sctp_local_addr_lock		(sctp_globals.local_addr_lock)
    #define sctp_addip_enable		(sctp_globals.addip_enable)
    #define sctp_prsctp_enable		(sctp_globals.prsctp_enable)
    
    /* 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_tfm *hmac;
    
    	/* 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;
    
    	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;
    	__u8 nodelay;
    	__u8 disable_fragments;
    	__u8 pd_mode;
    	__u8 v4mapped;
    	__u32 adaption_ind;
    
    	/* Receive to here while partial delivery is in effect. */
    	struct sk_buff_head pd_lobby;
    };
    
    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 defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
    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? */
    	struct timeval 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 adaption_ind;	
    
    
    	/* 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];
    	struct sctp_cookie c;
    };
    
    /* 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_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_adaption_ind_param *aind;
    };
    
    /* 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;
    } __attribute__((packed)) sctp_sender_hb_info_t;
    
    /*
     *  RFC 2960 1.3.2 Sequenced Delivery within Streams
     *
     *  The term "stream" is used in SCTP to refer to a sequence of user
     *  messages that are to be delivered to the upper-layer protocol in
     *  order with respect to other messages within the same stream.  This is
     *  in contrast to its usage in TCP, where it refers to a sequence of
     *  bytes (in this document a byte is assumed to be eight bits).
     *  ...
     *
     *  This is the structure we use to track both our outbound and inbound
     *  SSN, or Stream Sequence Numbers.
     */
    
    struct sctp_stream {
    	__u16 *ssn;
    	unsigned int len;
    };
    
    struct sctp_ssnmap {
    	struct sctp_stream in;
    	struct sctp_stream out;
    	int malloced;
    };
    
    struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out, int gfp);
    void sctp_ssnmap_free(struct sctp_ssnmap *map);
    void sctp_ssnmap_clear(struct sctp_ssnmap *map);
    
    /* What is the current SSN number for this stream? */
    static inline __u16 sctp_ssn_peek(struct sctp_stream *stream, __u16 id)
    {
    	return stream->ssn[id];
    }
    
    /* Return the next SSN number for this stream.	*/
    static inline __u16 sctp_ssn_next(struct sctp_stream *stream, __u16 id)
    {
    	return stream->ssn[id]++;
    }
    
    /* Skip over this ssn and all below. */
    static inline void sctp_ssn_skip(struct sctp_stream *stream, __u16 id, 
    				 __u16 ssn)
    {
    	stream->ssn[id] = 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 ipfragok);
    	int		(*setsockopt)	(struct sock *sk,
    					 int level,
    					 int optname,
    					 char __user *optval,
    					 int optlen);
    	int		(*getsockopt)	(struct sock *sk,
    					 int level,
    					 int optname,
    					 char __user *optval,
    					 int __user *optlen);
    	struct dst_entry *(*get_dst)	(struct sctp_association *asoc,
    					 union sctp_addr *daddr,
    					 union sctp_addr *saddr);
    	void		(*get_saddr)	(struct sctp_association *asoc,
    					 struct dst_entry *dst,
    					 union sctp_addr *daddr,
    					 union sctp_addr *saddr);
    	void		(*copy_addrlist) (struct list_head *,
    					  struct net_device *);
    	void		(*dst_saddr)	(union sctp_addr *saddr,
    					 struct dst_entry *dst,
    					 unsigned short port);
    	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		(*to_sk_saddr)	(union sctp_addr *,
    					 struct sock *sk);
    	void		(*to_sk_daddr)	(union sctp_addr *,
    					 struct sock *sk);
    	void		(*from_addr_param) (union sctp_addr *,
    					    union sctp_addr_param *,
    					    __u16 port, int iif);	
    	int		(*to_addr_param) (const union sctp_addr *,
    					  union sctp_addr_param *); 
    	int		(*addr_valid)	(union sctp_addr *,
    					 struct sctp_sock *);
    	sctp_scope_t	(*scope) (union sctp_addr *);
    	void		(*inaddr_any)	(union sctp_addr *, unsigned short);
    	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);
    	__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 *, __u16 *);
    	struct sock *(*create_accept_sk) (struct sock *sk,
    					  struct sctp_association *asoc);
    	void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
    	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;
    	/* Chunks that have been transmitted. */
    	struct list_head track;
    	/* Reference counting. */
    	atomic_t refcnt;
    	/* When is this message no longer interesting to the peer? */
    	unsigned long expires_at;
    	/* Did the messenge fail to send? */
    	int send_error;
    	char send_failed;
    	/* Control whether chunks from this message can be abandoned. */
    	char can_abandon;
    };
    
    struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *,
    					    struct sctp_sndrcvinfo *,
    					    struct msghdr *, int len);
    void sctp_datamsg_put(struct sctp_datamsg *);
    void sctp_datamsg_free(struct sctp_datamsg *);
    void sctp_datamsg_track(struct sctp_chunk *);
    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 {
    	/* These first three elements MUST PRECISELY match the first
    	 * three elements of struct sk_buff.  This allows us to reuse
    	 * all the skb_* queue management functions.
    	 */
    	struct sctp_chunk *next;
    	struct sctp_chunk *prev;
    	struct sk_buff_head *list;
    	atomic_t refcnt;
    
    	/* This is our link to the per-transport transmitted list.  */
    	struct list_head transmitted_list;
    
    	/* 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;
    
    	/* 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;
    	} 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;
    
    	__u8 rtt_in_progress;	/* Is this chunk used for RTT calculation? */
    	__u8 resent;		/* Has this chunk ever been retransmitted. */
    	__u8 has_tsn;		/* Does this chunk have a TSN yet? */
    	__u8 has_ssn;		/* Does this chunk have a SSN yet? */
    	__u8 singleton;		/* Was this the only chunk in the packet? */
    	__u8 end_of_packet;	/* Was this the last chunk in the packet? */
    	__u8 ecn_ce_done;	/* Have we processed the ECN CE bit? */
    	__u8 pdiscard;		/* Discard the whole packet now? */
    	__u8 tsn_gap_acked;	/* Is this chunk acked by a GAP ACK? */
    	__u8 fast_retransmit;	 /* Is this chunk fast retransmitted? */
    	__u8 tsn_missing_report; /* Data chunk missing counter. */
    };
    
    void sctp_chunk_hold(struct sctp_chunk *);
    void sctp_chunk_put(struct sctp_chunk *);
    int sctp_user_addto_chunk(struct sctp_chunk *chunk, int off, int len,
    			  struct iovec *data);
    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 *,
    				 struct sock *);
    void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
    		     union sctp_addr *);
    const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);
    
    /* This is a structure for holding either an IPv6 or an IPv4 address.  */
    /* sin_family -- AF_INET or AF_INET6
     * sin_port -- ordinary port number
     * sin_addr -- cast to either (struct in_addr) or (struct in6_addr)
     */
    struct sctp_sockaddr_entry {
    	struct list_head list;
    	union sctp_addr a;
    };
    
    typedef struct sctp_chunk *(sctp_packet_phandler_t)(struct sctp_association *);
    
    /* 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.  */
    	struct sk_buff_head chunks;
    
    	/* 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;
    
    	/* 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;
    
    	/* This packet contains a COOKIE-ECHO chunk. */
    	char has_cookie_echo;
    
    	/* This packet containsa SACK chunk. */
    	char has_sack;
    
    	/* SCTP cannot fragment this packet. So let ip fragment it. */
    	char ipfragok;
    
    	int malloced;
    };
    
    struct sctp_packet *sctp_packet_init(struct sctp_packet *,
    				     struct sctp_transport *,
    				     __u16 sport, __u16 dport);
    struct sctp_packet *sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
    sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *,
                                           struct sctp_chunk *);
    sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *,
                                         struct sctp_chunk *);
    int sctp_packet_transmit(struct sctp_packet *);
    void sctp_packet_free(struct sctp_packet *);
    
    static inline int sctp_packet_empty(struct sctp_packet *packet)
    {
    	return (packet->size == packet->overhead);
    }
    
    /* 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;
    
    	/* Reference counting. */
    	atomic_t refcnt;
    	int	 dead;
    
    	/* 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:
    	 */
    	__u32 rtt;		/* This is the most recent RTT.	 */
    
    	/* RTO	       : The current retransmission timeout value.  */
    	__u32 rto;
    
    	/* RTTVAR      : The current RTT variation.  */
    	__u32 rttvar;
    
    	/* SRTT	       : The current smoothed round trip time.	*/
    	__u32 srtt;
    
    	/* 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.
    	 */
    	int rto_pending;
    
    	/*
    	 * 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;
    
    	/* PMTU	      : The current known path MTU.  */
    	__u32 pmtu;
    
    	/* Destination */
    	struct dst_entry *dst;
    	/* Source address. */
    	union sctp_addr saddr;
    
    	/* When was the last time(in jiffies) that a data packet was sent on
    	 * this transport?  This is used to adjust the cwnd when the transport
    	 * becomes inactive.
    	 */
    	unsigned long last_time_used;
    
    	/* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
    	 * the destination address every heartbeat interval.
    	 */
    	int hb_interval;
    
    	/* When was the last time (in jiffies) that we heard from this
    	 * transport?  We use this to pick new active and retran paths.
    	 */
    	unsigned long last_time_heard;
    
    	/* Last time(in jiffies) when cwnd is reduced due to the congestion
    	 * indication based on ECNE chunk.
    	 */
    	unsigned long last_time_ecne_reduced;
    
    
    	/* The number of times INIT has been sent on this transport. */
    	int init_sent_count;
    
    	/* state       : The current state of this destination,
    	 *             : i.e. SCTP_ACTIVE, SCTP_INACTIVE, SCTP_UNKOWN.
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	 */
    
    	int state;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    	/* hb_allowed  : The current heartbeat state of this destination,
    	 *	       :  i.e. ALLOW-HB, NO-HEARTBEAT, etc.
    	 */
    	int hb_allowed;
    
    	/* These are the error stats for this destination.  */
    
    	/* Error count : The current error count for this destination.	*/
    	unsigned short error_count;
    
    	/* This is the max_retrans value for the transport and will
    	 * be initialized to proto.max_retrans.path.  This can be changed
    	 * using SCTP_SET_PEER_ADDR_PARAMS socket option.
    	 */
    	int max_retrans;
    
    	/* 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;
    
    	/* 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;
    
    	int malloced; /* Is this structure kfree()able? */
    
    	/* 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;
    };
    
    struct sctp_transport *sctp_transport_new(const union sctp_addr *, int);
    void sctp_transport_set_owner(struct sctp_transport *,
    			      struct sctp_association *);
    void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
    			  struct sctp_sock *);
    void sctp_transport_pmtu(struct sctp_transport *);
    void sctp_transport_free(struct sctp_transport *);
    void sctp_transport_reset_timers(struct sctp_transport *);
    void sctp_transport_hold(struct sctp_transport *);
    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);
    void sctp_transport_lower_cwnd(struct sctp_transport *, sctp_lower_cwnd_t);
    unsigned long sctp_transport_timeout(struct sctp_transport *);
    
    
    /* 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.
    	 */
    	struct sk_buff_head in;
    	/* 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;
    
    	int malloced;	     /* Is this structure kfree()able?	*/
    };
    
    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 *);
    void sctp_inq_set_th_handler(struct sctp_inq *, void (*)(void *), void *);
    
    /* 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)()).
     *