structs.h 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  1. /* SCTP kernel implementation
  2. * (C) Copyright IBM Corp. 2001, 2004
  3. * Copyright (c) 1999-2000 Cisco, Inc.
  4. * Copyright (c) 1999-2001 Motorola, Inc.
  5. * Copyright (c) 2001 Intel Corp.
  6. *
  7. * This file is part of the SCTP kernel implementation
  8. *
  9. * This SCTP implementation is free software;
  10. * you can redistribute it and/or modify it under the terms of
  11. * the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * This SCTP implementation is distributed in the hope that it
  16. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  17. * ************************
  18. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. * See the GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with GNU CC; see the file COPYING. If not, see
  23. * <http://www.gnu.org/licenses/>.
  24. *
  25. * Please send any bug reports or fixes you make to the
  26. * email addresses:
  27. * lksctp developers <linux-sctp@vger.kernel.org>
  28. *
  29. * Written or modified by:
  30. * Randall Stewart <randall@sctp.chicago.il.us>
  31. * Ken Morneau <kmorneau@cisco.com>
  32. * Qiaobing Xie <qxie1@email.mot.com>
  33. * La Monte H.P. Yarroll <piggy@acm.org>
  34. * Karl Knutson <karl@athena.chicago.il.us>
  35. * Jon Grimm <jgrimm@us.ibm.com>
  36. * Xingang Guo <xingang.guo@intel.com>
  37. * Hui Huang <hui.huang@nokia.com>
  38. * Sridhar Samudrala <sri@us.ibm.com>
  39. * Daisy Chang <daisyc@us.ibm.com>
  40. * Dajiang Zhang <dajiang.zhang@nokia.com>
  41. * Ardelle Fan <ardelle.fan@intel.com>
  42. * Ryan Layer <rmlayer@us.ibm.com>
  43. * Anup Pemmaiah <pemmaiah@cc.usu.edu>
  44. * Kevin Gao <kevin.gao@intel.com>
  45. */
  46. #ifndef __sctp_structs_h__
  47. #define __sctp_structs_h__
  48. #include <linux/ktime.h>
  49. #include <linux/rhashtable.h>
  50. #include <linux/socket.h> /* linux/in.h needs this!! */
  51. #include <linux/in.h> /* We get struct sockaddr_in. */
  52. #include <linux/in6.h> /* We get struct in6_addr */
  53. #include <linux/ipv6.h>
  54. #include <asm/param.h> /* We get MAXHOSTNAMELEN. */
  55. #include <linux/atomic.h> /* This gets us atomic counters. */
  56. #include <linux/skbuff.h> /* We need sk_buff_head. */
  57. #include <linux/workqueue.h> /* We need tq_struct. */
  58. #include <linux/sctp.h> /* We need sctp* header structs. */
  59. #include <net/sctp/auth.h> /* We need auth specific structs */
  60. #include <net/ip.h> /* For inet_skb_parm */
  61. /* A convenience structure for handling sockaddr structures.
  62. * We should wean ourselves off this.
  63. */
  64. union sctp_addr {
  65. struct sockaddr_in v4;
  66. struct sockaddr_in6 v6;
  67. struct sockaddr sa;
  68. };
  69. /* Forward declarations for data structures. */
  70. struct sctp_globals;
  71. struct sctp_endpoint;
  72. struct sctp_association;
  73. struct sctp_transport;
  74. struct sctp_packet;
  75. struct sctp_chunk;
  76. struct sctp_inq;
  77. struct sctp_outq;
  78. struct sctp_bind_addr;
  79. struct sctp_ulpq;
  80. struct sctp_ep_common;
  81. struct crypto_shash;
  82. struct sctp_stream;
  83. #include <net/sctp/tsnmap.h>
  84. #include <net/sctp/ulpevent.h>
  85. #include <net/sctp/ulpqueue.h>
  86. #include <net/sctp/stream_interleave.h>
  87. /* Structures useful for managing bind/connect. */
  88. struct sctp_bind_bucket {
  89. unsigned short port;
  90. unsigned short fastreuse;
  91. struct hlist_node node;
  92. struct hlist_head owner;
  93. struct net *net;
  94. };
  95. struct sctp_bind_hashbucket {
  96. spinlock_t lock;
  97. struct hlist_head chain;
  98. };
  99. /* Used for hashing all associations. */
  100. struct sctp_hashbucket {
  101. rwlock_t lock;
  102. struct hlist_head chain;
  103. } __attribute__((__aligned__(8)));
  104. /* The SCTP globals structure. */
  105. extern struct sctp_globals {
  106. /* This is a list of groups of functions for each address
  107. * family that we support.
  108. */
  109. struct list_head address_families;
  110. /* This is the hash of all endpoints. */
  111. struct sctp_hashbucket *ep_hashtable;
  112. /* This is the sctp port control hash. */
  113. struct sctp_bind_hashbucket *port_hashtable;
  114. /* This is the hash of all transports. */
  115. struct rhltable transport_hashtable;
  116. /* Sizes of above hashtables. */
  117. int ep_hashsize;
  118. int port_hashsize;
  119. /* Default initialization values to be applied to new associations. */
  120. __u16 max_instreams;
  121. __u16 max_outstreams;
  122. /* Flag to indicate whether computing and verifying checksum
  123. * is disabled. */
  124. bool checksum_disable;
  125. } sctp_globals;
  126. #define sctp_max_instreams (sctp_globals.max_instreams)
  127. #define sctp_max_outstreams (sctp_globals.max_outstreams)
  128. #define sctp_address_families (sctp_globals.address_families)
  129. #define sctp_ep_hashsize (sctp_globals.ep_hashsize)
  130. #define sctp_ep_hashtable (sctp_globals.ep_hashtable)
  131. #define sctp_port_hashsize (sctp_globals.port_hashsize)
  132. #define sctp_port_hashtable (sctp_globals.port_hashtable)
  133. #define sctp_transport_hashtable (sctp_globals.transport_hashtable)
  134. #define sctp_checksum_disable (sctp_globals.checksum_disable)
  135. /* SCTP Socket type: UDP or TCP style. */
  136. enum sctp_socket_type {
  137. SCTP_SOCKET_UDP = 0,
  138. SCTP_SOCKET_UDP_HIGH_BANDWIDTH,
  139. SCTP_SOCKET_TCP
  140. };
  141. /* Per socket SCTP information. */
  142. struct sctp_sock {
  143. /* inet_sock has to be the first member of sctp_sock */
  144. struct inet_sock inet;
  145. /* What kind of a socket is this? */
  146. enum sctp_socket_type type;
  147. /* PF_ family specific functions. */
  148. struct sctp_pf *pf;
  149. /* Access to HMAC transform. */
  150. struct crypto_shash *hmac;
  151. char *sctp_hmac_alg;
  152. /* What is our base endpointer? */
  153. struct sctp_endpoint *ep;
  154. struct sctp_bind_bucket *bind_hash;
  155. /* Various Socket Options. */
  156. __u16 default_stream;
  157. __u32 default_ppid;
  158. __u16 default_flags;
  159. __u32 default_context;
  160. __u32 default_timetolive;
  161. __u32 default_rcv_context;
  162. int max_burst;
  163. /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
  164. * the destination address every heartbeat interval. This value
  165. * will be inherited by all new associations.
  166. */
  167. __u32 hbinterval;
  168. /* This is the max_retrans value for new associations. */
  169. __u16 pathmaxrxt;
  170. /* The initial Path MTU to use for new associations. */
  171. __u32 pathmtu;
  172. /* The default SACK delay timeout for new associations. */
  173. __u32 sackdelay;
  174. __u32 sackfreq;
  175. /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
  176. __u32 param_flags;
  177. struct sctp_rtoinfo rtoinfo;
  178. struct sctp_paddrparams paddrparam;
  179. struct sctp_assocparams assocparams;
  180. /*
  181. * These two structures must be grouped together for the usercopy
  182. * whitelist region.
  183. */
  184. struct sctp_event_subscribe subscribe;
  185. struct sctp_initmsg initmsg;
  186. int user_frag;
  187. __u32 autoclose;
  188. __u32 adaptation_ind;
  189. __u32 pd_point;
  190. __u16 nodelay:1,
  191. disable_fragments:1,
  192. v4mapped:1,
  193. frag_interleave:1,
  194. strm_interleave:1,
  195. recvrcvinfo:1,
  196. recvnxtinfo:1,
  197. data_ready_signalled:1;
  198. atomic_t pd_mode;
  199. /* Receive to here while partial delivery is in effect. */
  200. struct sk_buff_head pd_lobby;
  201. /* These must be the last fields, as they will skipped on copies,
  202. * like on accept and peeloff operations
  203. */
  204. struct list_head auto_asconf_list;
  205. int do_auto_asconf;
  206. };
  207. static inline struct sctp_sock *sctp_sk(const struct sock *sk)
  208. {
  209. return (struct sctp_sock *)sk;
  210. }
  211. static inline struct sock *sctp_opt2sk(const struct sctp_sock *sp)
  212. {
  213. return (struct sock *)sp;
  214. }
  215. #if IS_ENABLED(CONFIG_IPV6)
  216. struct sctp6_sock {
  217. struct sctp_sock sctp;
  218. struct ipv6_pinfo inet6;
  219. };
  220. #endif /* CONFIG_IPV6 */
  221. /* This is our APPLICATION-SPECIFIC state cookie.
  222. * THIS IS NOT DICTATED BY THE SPECIFICATION.
  223. */
  224. /* These are the parts of an association which we send in the cookie.
  225. * Most of these are straight out of:
  226. * RFC2960 12.2 Parameters necessary per association (i.e. the TCB)
  227. *
  228. */
  229. struct sctp_cookie {
  230. /* My : Tag expected in every inbound packet and sent
  231. * Verification: in the INIT or INIT ACK chunk.
  232. * Tag :
  233. */
  234. __u32 my_vtag;
  235. /* Peer's : Tag expected in every outbound packet except
  236. * Verification: in the INIT chunk.
  237. * Tag :
  238. */
  239. __u32 peer_vtag;
  240. /* The rest of these are not from the spec, but really need to
  241. * be in the cookie.
  242. */
  243. /* My Tie Tag : Assist in discovering a restarting association. */
  244. __u32 my_ttag;
  245. /* Peer's Tie Tag: Assist in discovering a restarting association. */
  246. __u32 peer_ttag;
  247. /* When does this cookie expire? */
  248. ktime_t expiration;
  249. /* Number of inbound/outbound streams which are set
  250. * and negotiated during the INIT process.
  251. */
  252. __u16 sinit_num_ostreams;
  253. __u16 sinit_max_instreams;
  254. /* This is the first sequence number I used. */
  255. __u32 initial_tsn;
  256. /* This holds the originating address of the INIT packet. */
  257. union sctp_addr peer_addr;
  258. /* IG Section 2.35.3
  259. * Include the source port of the INIT-ACK
  260. */
  261. __u16 my_port;
  262. __u8 prsctp_capable;
  263. /* Padding for future use */
  264. __u8 padding;
  265. __u32 adaptation_ind;
  266. __u8 auth_random[sizeof(struct sctp_paramhdr) +
  267. SCTP_AUTH_RANDOM_LENGTH];
  268. __u8 auth_hmacs[SCTP_AUTH_NUM_HMACS * sizeof(__u16) + 2];
  269. __u8 auth_chunks[sizeof(struct sctp_paramhdr) + SCTP_AUTH_MAX_CHUNKS];
  270. /* This is a shim for my peer's INIT packet, followed by
  271. * a copy of the raw address list of the association.
  272. * The length of the raw address list is saved in the
  273. * raw_addr_list_len field, which will be used at the time when
  274. * the association TCB is re-constructed from the cookie.
  275. */
  276. __u32 raw_addr_list_len;
  277. struct sctp_init_chunk peer_init[0];
  278. };
  279. /* The format of our cookie that we send to our peer. */
  280. struct sctp_signed_cookie {
  281. __u8 signature[SCTP_SECRET_SIZE];
  282. __u32 __pad; /* force sctp_cookie alignment to 64 bits */
  283. struct sctp_cookie c;
  284. } __packed;
  285. /* This is another convenience type to allocate memory for address
  286. * params for the maximum size and pass such structures around
  287. * internally.
  288. */
  289. union sctp_addr_param {
  290. struct sctp_paramhdr p;
  291. struct sctp_ipv4addr_param v4;
  292. struct sctp_ipv6addr_param v6;
  293. };
  294. /* A convenience type to allow walking through the various
  295. * parameters and avoid casting all over the place.
  296. */
  297. union sctp_params {
  298. void *v;
  299. struct sctp_paramhdr *p;
  300. struct sctp_cookie_preserve_param *life;
  301. struct sctp_hostname_param *dns;
  302. struct sctp_cookie_param *cookie;
  303. struct sctp_supported_addrs_param *sat;
  304. struct sctp_ipv4addr_param *v4;
  305. struct sctp_ipv6addr_param *v6;
  306. union sctp_addr_param *addr;
  307. struct sctp_adaptation_ind_param *aind;
  308. struct sctp_supported_ext_param *ext;
  309. struct sctp_random_param *random;
  310. struct sctp_chunks_param *chunks;
  311. struct sctp_hmac_algo_param *hmac_algo;
  312. struct sctp_addip_param *addip;
  313. };
  314. /* RFC 2960. Section 3.3.5 Heartbeat.
  315. * Heartbeat Information: variable length
  316. * The Sender-specific Heartbeat Info field should normally include
  317. * information about the sender's current time when this HEARTBEAT
  318. * chunk is sent and the destination transport address to which this
  319. * HEARTBEAT is sent (see Section 8.3).
  320. */
  321. struct sctp_sender_hb_info {
  322. struct sctp_paramhdr param_hdr;
  323. union sctp_addr daddr;
  324. unsigned long sent_at;
  325. __u64 hb_nonce;
  326. };
  327. int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
  328. gfp_t gfp);
  329. int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid);
  330. void sctp_stream_free(struct sctp_stream *stream);
  331. void sctp_stream_clear(struct sctp_stream *stream);
  332. void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new);
  333. /* What is the current SSN number for this stream? */
  334. #define sctp_ssn_peek(stream, type, sid) \
  335. ((stream)->type[sid].ssn)
  336. /* Return the next SSN number for this stream. */
  337. #define sctp_ssn_next(stream, type, sid) \
  338. ((stream)->type[sid].ssn++)
  339. /* Skip over this ssn and all below. */
  340. #define sctp_ssn_skip(stream, type, sid, ssn) \
  341. ((stream)->type[sid].ssn = ssn + 1)
  342. /* What is the current MID number for this stream? */
  343. #define sctp_mid_peek(stream, type, sid) \
  344. ((stream)->type[sid].mid)
  345. /* Return the next MID number for this stream. */
  346. #define sctp_mid_next(stream, type, sid) \
  347. ((stream)->type[sid].mid++)
  348. /* Skip over this mid and all below. */
  349. #define sctp_mid_skip(stream, type, sid, mid) \
  350. ((stream)->type[sid].mid = mid + 1)
  351. #define sctp_stream_in(asoc, sid) (&(asoc)->stream.in[sid])
  352. /* What is the current MID_uo number for this stream? */
  353. #define sctp_mid_uo_peek(stream, type, sid) \
  354. ((stream)->type[sid].mid_uo)
  355. /* Return the next MID_uo number for this stream. */
  356. #define sctp_mid_uo_next(stream, type, sid) \
  357. ((stream)->type[sid].mid_uo++)
  358. /*
  359. * Pointers to address related SCTP functions.
  360. * (i.e. things that depend on the address family.)
  361. */
  362. struct sctp_af {
  363. int (*sctp_xmit) (struct sk_buff *skb,
  364. struct sctp_transport *);
  365. int (*setsockopt) (struct sock *sk,
  366. int level,
  367. int optname,
  368. char __user *optval,
  369. unsigned int optlen);
  370. int (*getsockopt) (struct sock *sk,
  371. int level,
  372. int optname,
  373. char __user *optval,
  374. int __user *optlen);
  375. int (*compat_setsockopt) (struct sock *sk,
  376. int level,
  377. int optname,
  378. char __user *optval,
  379. unsigned int optlen);
  380. int (*compat_getsockopt) (struct sock *sk,
  381. int level,
  382. int optname,
  383. char __user *optval,
  384. int __user *optlen);
  385. void (*get_dst) (struct sctp_transport *t,
  386. union sctp_addr *saddr,
  387. struct flowi *fl,
  388. struct sock *sk);
  389. void (*get_saddr) (struct sctp_sock *sk,
  390. struct sctp_transport *t,
  391. struct flowi *fl);
  392. void (*copy_addrlist) (struct list_head *,
  393. struct net_device *);
  394. int (*cmp_addr) (const union sctp_addr *addr1,
  395. const union sctp_addr *addr2);
  396. void (*addr_copy) (union sctp_addr *dst,
  397. union sctp_addr *src);
  398. void (*from_skb) (union sctp_addr *,
  399. struct sk_buff *skb,
  400. int saddr);
  401. void (*from_sk) (union sctp_addr *,
  402. struct sock *sk);
  403. void (*from_addr_param) (union sctp_addr *,
  404. union sctp_addr_param *,
  405. __be16 port, int iif);
  406. int (*to_addr_param) (const union sctp_addr *,
  407. union sctp_addr_param *);
  408. int (*addr_valid) (union sctp_addr *,
  409. struct sctp_sock *,
  410. const struct sk_buff *);
  411. enum sctp_scope (*scope)(union sctp_addr *);
  412. void (*inaddr_any) (union sctp_addr *, __be16);
  413. int (*is_any) (const union sctp_addr *);
  414. int (*available) (union sctp_addr *,
  415. struct sctp_sock *);
  416. int (*skb_iif) (const struct sk_buff *sk);
  417. int (*is_ce) (const struct sk_buff *sk);
  418. void (*seq_dump_addr)(struct seq_file *seq,
  419. union sctp_addr *addr);
  420. void (*ecn_capable)(struct sock *sk);
  421. __u16 net_header_len;
  422. int sockaddr_len;
  423. int (*ip_options_len)(struct sock *sk);
  424. sa_family_t sa_family;
  425. struct list_head list;
  426. };
  427. struct sctp_af *sctp_get_af_specific(sa_family_t);
  428. int sctp_register_af(struct sctp_af *);
  429. /* Protocol family functions. */
  430. struct sctp_pf {
  431. void (*event_msgname)(struct sctp_ulpevent *, char *, int *);
  432. void (*skb_msgname) (struct sk_buff *, char *, int *);
  433. int (*af_supported) (sa_family_t, struct sctp_sock *);
  434. int (*cmp_addr) (const union sctp_addr *,
  435. const union sctp_addr *,
  436. struct sctp_sock *);
  437. int (*bind_verify) (struct sctp_sock *, union sctp_addr *);
  438. int (*send_verify) (struct sctp_sock *, union sctp_addr *);
  439. int (*supported_addrs)(const struct sctp_sock *, __be16 *);
  440. struct sock *(*create_accept_sk) (struct sock *sk,
  441. struct sctp_association *asoc,
  442. bool kern);
  443. int (*addr_to_user)(struct sctp_sock *sk, union sctp_addr *addr);
  444. void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
  445. void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
  446. void (*copy_ip_options)(struct sock *sk, struct sock *newsk);
  447. struct sctp_af *af;
  448. };
  449. /* Structure to track chunk fragments that have been acked, but peer
  450. * fragments of the same message have not.
  451. */
  452. struct sctp_datamsg {
  453. /* Chunks waiting to be submitted to lower layer. */
  454. struct list_head chunks;
  455. /* Reference counting. */
  456. refcount_t refcnt;
  457. /* When is this message no longer interesting to the peer? */
  458. unsigned long expires_at;
  459. /* Did the messenge fail to send? */
  460. int send_error;
  461. u8 send_failed:1,
  462. can_delay:1, /* should this message be Nagle delayed */
  463. abandoned:1; /* should this message be abandoned */
  464. };
  465. struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *,
  466. struct sctp_sndrcvinfo *,
  467. struct iov_iter *);
  468. void sctp_datamsg_free(struct sctp_datamsg *);
  469. void sctp_datamsg_put(struct sctp_datamsg *);
  470. void sctp_chunk_fail(struct sctp_chunk *, int error);
  471. int sctp_chunk_abandoned(struct sctp_chunk *);
  472. /* RFC2960 1.4 Key Terms
  473. *
  474. * o Chunk: A unit of information within an SCTP packet, consisting of
  475. * a chunk header and chunk-specific content.
  476. *
  477. * As a matter of convenience, we remember the SCTP common header for
  478. * each chunk as well as a few other header pointers...
  479. */
  480. struct sctp_chunk {
  481. struct list_head list;
  482. refcount_t refcnt;
  483. /* How many times this chunk have been sent, for prsctp RTX policy */
  484. int sent_count;
  485. union {
  486. /* This is our link to the per-transport transmitted list. */
  487. struct list_head transmitted_list;
  488. /* List in specific stream outq */
  489. struct list_head stream_list;
  490. };
  491. /* This field is used by chunks that hold fragmented data.
  492. * For the first fragment this is the list that holds the rest of
  493. * fragments. For the remaining fragments, this is the link to the
  494. * frag_list maintained in the first fragment.
  495. */
  496. struct list_head frag_list;
  497. /* This points to the sk_buff containing the actual data. */
  498. struct sk_buff *skb;
  499. union {
  500. /* In case of GSO packets, this will store the head one */
  501. struct sk_buff *head_skb;
  502. /* In case of auth enabled, this will point to the shkey */
  503. struct sctp_shared_key *shkey;
  504. };
  505. /* These are the SCTP headers by reverse order in a packet.
  506. * Note that some of these may happen more than once. In that
  507. * case, we point at the "current" one, whatever that means
  508. * for that level of header.
  509. */
  510. /* We point this at the FIRST TLV parameter to chunk_hdr. */
  511. union sctp_params param_hdr;
  512. union {
  513. __u8 *v;
  514. struct sctp_datahdr *data_hdr;
  515. struct sctp_inithdr *init_hdr;
  516. struct sctp_sackhdr *sack_hdr;
  517. struct sctp_heartbeathdr *hb_hdr;
  518. struct sctp_sender_hb_info *hbs_hdr;
  519. struct sctp_shutdownhdr *shutdown_hdr;
  520. struct sctp_signed_cookie *cookie_hdr;
  521. struct sctp_ecnehdr *ecne_hdr;
  522. struct sctp_cwrhdr *ecn_cwr_hdr;
  523. struct sctp_errhdr *err_hdr;
  524. struct sctp_addiphdr *addip_hdr;
  525. struct sctp_fwdtsn_hdr *fwdtsn_hdr;
  526. struct sctp_authhdr *auth_hdr;
  527. struct sctp_idatahdr *idata_hdr;
  528. struct sctp_ifwdtsn_hdr *ifwdtsn_hdr;
  529. } subh;
  530. __u8 *chunk_end;
  531. struct sctp_chunkhdr *chunk_hdr;
  532. struct sctphdr *sctp_hdr;
  533. /* This needs to be recoverable for SCTP_SEND_FAILED events. */
  534. struct sctp_sndrcvinfo sinfo;
  535. /* Which association does this belong to? */
  536. struct sctp_association *asoc;
  537. /* What endpoint received this chunk? */
  538. struct sctp_ep_common *rcvr;
  539. /* We fill this in if we are calculating RTT. */
  540. unsigned long sent_at;
  541. /* What is the origin IP address for this chunk? */
  542. union sctp_addr source;
  543. /* Destination address for this chunk. */
  544. union sctp_addr dest;
  545. /* For outbound message, track all fragments for SEND_FAILED. */
  546. struct sctp_datamsg *msg;
  547. /* For an inbound chunk, this tells us where it came from.
  548. * For an outbound chunk, it tells us where we'd like it to
  549. * go. It is NULL if we have no preference.
  550. */
  551. struct sctp_transport *transport;
  552. /* SCTP-AUTH: For the special case inbound processing of COOKIE-ECHO
  553. * we need save a pointer to the AUTH chunk, since the SCTP-AUTH
  554. * spec violates the principle premis that all chunks are processed
  555. * in order.
  556. */
  557. struct sk_buff *auth_chunk;
  558. #define SCTP_CAN_FRTX 0x0
  559. #define SCTP_NEED_FRTX 0x1
  560. #define SCTP_DONT_FRTX 0x2
  561. __u16 rtt_in_progress:1, /* This chunk used for RTT calc? */
  562. has_tsn:1, /* Does this chunk have a TSN yet? */
  563. has_ssn:1, /* Does this chunk have a SSN yet? */
  564. #define has_mid has_ssn
  565. singleton:1, /* Only chunk in the packet? */
  566. end_of_packet:1, /* Last chunk in the packet? */
  567. ecn_ce_done:1, /* Have we processed the ECN CE bit? */
  568. pdiscard:1, /* Discard the whole packet now? */
  569. tsn_gap_acked:1, /* Is this chunk acked by a GAP ACK? */
  570. data_accepted:1, /* At least 1 chunk accepted */
  571. auth:1, /* IN: was auth'ed | OUT: needs auth */
  572. has_asconf:1, /* IN: have seen an asconf before */
  573. tsn_missing_report:2, /* Data chunk missing counter. */
  574. fast_retransmit:2; /* Is this chunk fast retransmitted? */
  575. };
  576. #define sctp_chunk_retransmitted(chunk) (chunk->sent_count > 1)
  577. void sctp_chunk_hold(struct sctp_chunk *);
  578. void sctp_chunk_put(struct sctp_chunk *);
  579. int sctp_user_addto_chunk(struct sctp_chunk *chunk, int len,
  580. struct iov_iter *from);
  581. void sctp_chunk_free(struct sctp_chunk *);
  582. void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data);
  583. struct sctp_chunk *sctp_chunkify(struct sk_buff *,
  584. const struct sctp_association *,
  585. struct sock *, gfp_t gfp);
  586. void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
  587. union sctp_addr *);
  588. const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);
  589. static inline __u16 sctp_chunk_stream_no(struct sctp_chunk *ch)
  590. {
  591. return ntohs(ch->subh.data_hdr->stream);
  592. }
  593. enum {
  594. SCTP_ADDR_NEW, /* new address added to assoc/ep */
  595. SCTP_ADDR_SRC, /* address can be used as source */
  596. SCTP_ADDR_DEL, /* address about to be deleted */
  597. };
  598. /* This is a structure for holding either an IPv6 or an IPv4 address. */
  599. struct sctp_sockaddr_entry {
  600. struct list_head list;
  601. struct rcu_head rcu;
  602. union sctp_addr a;
  603. __u8 state;
  604. __u8 valid;
  605. };
  606. #define SCTP_ADDRESS_TICK_DELAY 500
  607. /* This structure holds lists of chunks as we are assembling for
  608. * transmission.
  609. */
  610. struct sctp_packet {
  611. /* These are the SCTP header values (host order) for the packet. */
  612. __u16 source_port;
  613. __u16 destination_port;
  614. __u32 vtag;
  615. /* This contains the payload chunks. */
  616. struct list_head chunk_list;
  617. /* This is the overhead of the sctp and ip headers. */
  618. size_t overhead;
  619. /* This is the total size of all chunks INCLUDING padding. */
  620. size_t size;
  621. /* This is the maximum size this packet may have */
  622. size_t max_size;
  623. /* The packet is destined for this transport address.
  624. * The function we finally use to pass down to the next lower
  625. * layer lives in the transport structure.
  626. */
  627. struct sctp_transport *transport;
  628. /* pointer to the auth chunk for this packet */
  629. struct sctp_chunk *auth;
  630. u8 has_cookie_echo:1, /* This packet contains a COOKIE-ECHO chunk. */
  631. has_sack:1, /* This packet contains a SACK chunk. */
  632. has_auth:1, /* This packet contains an AUTH chunk */
  633. has_data:1, /* This packet contains at least 1 DATA chunk */
  634. ipfragok:1; /* So let ip fragment this packet */
  635. };
  636. void sctp_packet_init(struct sctp_packet *, struct sctp_transport *,
  637. __u16 sport, __u16 dport);
  638. void sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
  639. enum sctp_xmit sctp_packet_transmit_chunk(struct sctp_packet *packet,
  640. struct sctp_chunk *chunk,
  641. int one_packet, gfp_t gfp);
  642. enum sctp_xmit sctp_packet_append_chunk(struct sctp_packet *packet,
  643. struct sctp_chunk *chunk);
  644. int sctp_packet_transmit(struct sctp_packet *, gfp_t);
  645. void sctp_packet_free(struct sctp_packet *);
  646. static inline int sctp_packet_empty(struct sctp_packet *packet)
  647. {
  648. return packet->size == packet->overhead;
  649. }
  650. /* This represents a remote transport address.
  651. * For local transport addresses, we just use union sctp_addr.
  652. *
  653. * RFC2960 Section 1.4 Key Terms
  654. *
  655. * o Transport address: A Transport Address is traditionally defined
  656. * by Network Layer address, Transport Layer protocol and Transport
  657. * Layer port number. In the case of SCTP running over IP, a
  658. * transport address is defined by the combination of an IP address
  659. * and an SCTP port number (where SCTP is the Transport protocol).
  660. *
  661. * RFC2960 Section 7.1 SCTP Differences from TCP Congestion control
  662. *
  663. * o The sender keeps a separate congestion control parameter set for
  664. * each of the destination addresses it can send to (not each
  665. * source-destination pair but for each destination). The parameters
  666. * should decay if the address is not used for a long enough time
  667. * period.
  668. *
  669. */
  670. struct sctp_transport {
  671. /* A list of transports. */
  672. struct list_head transports;
  673. struct rhlist_head node;
  674. /* Reference counting. */
  675. refcount_t refcnt;
  676. /* RTO-Pending : A flag used to track if one of the DATA
  677. * chunks sent to this address is currently being
  678. * used to compute a RTT. If this flag is 0,
  679. * the next DATA chunk sent to this destination
  680. * should be used to compute a RTT and this flag
  681. * should be set. Every time the RTT
  682. * calculation completes (i.e. the DATA chunk
  683. * is SACK'd) clear this flag.
  684. */
  685. __u32 rto_pending:1,
  686. /*
  687. * hb_sent : a flag that signals that we have a pending
  688. * heartbeat.
  689. */
  690. hb_sent:1,
  691. /* Is the Path MTU update pending on this tranport */
  692. pmtu_pending:1,
  693. dst_pending_confirm:1, /* need to confirm neighbour */
  694. /* Has this transport moved the ctsn since we last sacked */
  695. sack_generation:1;
  696. u32 dst_cookie;
  697. struct flowi fl;
  698. /* This is the peer's IP address and port. */
  699. union sctp_addr ipaddr;
  700. /* These are the functions we call to handle LLP stuff. */
  701. struct sctp_af *af_specific;
  702. /* Which association do we belong to? */
  703. struct sctp_association *asoc;
  704. /* RFC2960
  705. *
  706. * 12.3 Per Transport Address Data
  707. *
  708. * For each destination transport address in the peer's
  709. * address list derived from the INIT or INIT ACK chunk, a
  710. * number of data elements needs to be maintained including:
  711. */
  712. /* RTO : The current retransmission timeout value. */
  713. unsigned long rto;
  714. __u32 rtt; /* This is the most recent RTT. */
  715. /* RTTVAR : The current RTT variation. */
  716. __u32 rttvar;
  717. /* SRTT : The current smoothed round trip time. */
  718. __u32 srtt;
  719. /*
  720. * These are the congestion stats.
  721. */
  722. /* cwnd : The current congestion window. */
  723. __u32 cwnd; /* This is the actual cwnd. */
  724. /* ssthresh : The current slow start threshold value. */
  725. __u32 ssthresh;
  726. /* partial : The tracking method for increase of cwnd when in
  727. * bytes acked : congestion avoidance mode (see Section 6.2.2)
  728. */
  729. __u32 partial_bytes_acked;
  730. /* Data that has been sent, but not acknowledged. */
  731. __u32 flight_size;
  732. __u32 burst_limited; /* Holds old cwnd when max.burst is applied */
  733. /* Destination */
  734. struct dst_entry *dst;
  735. /* Source address. */
  736. union sctp_addr saddr;
  737. /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
  738. * the destination address every heartbeat interval.
  739. */
  740. unsigned long hbinterval;
  741. /* SACK delay timeout */
  742. unsigned long sackdelay;
  743. __u32 sackfreq;
  744. /* When was the last time that we heard from this transport? We use
  745. * this to pick new active and retran paths.
  746. */
  747. ktime_t last_time_heard;
  748. /* When was the last time that we sent a chunk using this
  749. * transport? We use this to check for idle transports
  750. */
  751. unsigned long last_time_sent;
  752. /* Last time(in jiffies) when cwnd is reduced due to the congestion
  753. * indication based on ECNE chunk.
  754. */
  755. unsigned long last_time_ecne_reduced;
  756. /* This is the max_retrans value for the transport and will
  757. * be initialized from the assocs value. This can be changed
  758. * using the SCTP_SET_PEER_ADDR_PARAMS socket option.
  759. */
  760. __u16 pathmaxrxt;
  761. /* This is the partially failed retrans value for the transport
  762. * and will be initialized from the assocs value. This can be changed
  763. * using the SCTP_PEER_ADDR_THLDS socket option
  764. */
  765. int pf_retrans;
  766. /* PMTU : The current known path MTU. */
  767. __u32 pathmtu;
  768. /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
  769. __u32 param_flags;
  770. /* The number of times INIT has been sent on this transport. */
  771. int init_sent_count;
  772. /* state : The current state of this destination,
  773. * : i.e. SCTP_ACTIVE, SCTP_INACTIVE, SCTP_UNKNOWN.
  774. */
  775. int state;
  776. /* These are the error stats for this destination. */
  777. /* Error count : The current error count for this destination. */
  778. unsigned short error_count;
  779. /* Per : A timer used by each destination.
  780. * Destination :
  781. * Timer :
  782. *
  783. * [Everywhere else in the text this is called T3-rtx. -ed]
  784. */
  785. struct timer_list T3_rtx_timer;
  786. /* Heartbeat timer is per destination. */
  787. struct timer_list hb_timer;
  788. /* Timer to handle ICMP proto unreachable envets */
  789. struct timer_list proto_unreach_timer;
  790. /* Timer to handler reconf chunk rtx */
  791. struct timer_list reconf_timer;
  792. /* Since we're using per-destination retransmission timers
  793. * (see above), we're also using per-destination "transmitted"
  794. * queues. This probably ought to be a private struct
  795. * accessible only within the outqueue, but it's not, yet.
  796. */
  797. struct list_head transmitted;
  798. /* We build bundle-able packets for this transport here. */
  799. struct sctp_packet packet;
  800. /* This is the list of transports that have chunks to send. */
  801. struct list_head send_ready;
  802. /* State information saved for SFR_CACC algorithm. The key
  803. * idea in SFR_CACC is to maintain state at the sender on a
  804. * per-destination basis when a changeover happens.
  805. * char changeover_active;
  806. * char cycling_changeover;
  807. * __u32 next_tsn_at_change;
  808. * char cacc_saw_newack;
  809. */
  810. struct {
  811. /* An unsigned integer, which stores the next TSN to be
  812. * used by the sender, at the moment of changeover.
  813. */
  814. __u32 next_tsn_at_change;
  815. /* A flag which indicates the occurrence of a changeover */
  816. char changeover_active;
  817. /* A flag which indicates whether the change of primary is
  818. * the first switch to this destination address during an
  819. * active switch.
  820. */
  821. char cycling_changeover;
  822. /* A temporary flag, which is used during the processing of
  823. * a SACK to estimate the causative TSN(s)'s group.
  824. */
  825. char cacc_saw_newack;
  826. } cacc;
  827. /* 64-bit random number sent with heartbeat. */
  828. __u64 hb_nonce;
  829. struct rcu_head rcu;
  830. };
  831. struct sctp_transport *sctp_transport_new(struct net *, const union sctp_addr *,
  832. gfp_t);
  833. void sctp_transport_set_owner(struct sctp_transport *,
  834. struct sctp_association *);
  835. void sctp_transport_route(struct sctp_transport *, union sctp_addr *,
  836. struct sctp_sock *);
  837. void sctp_transport_pmtu(struct sctp_transport *, struct sock *sk);
  838. void sctp_transport_free(struct sctp_transport *);
  839. void sctp_transport_reset_t3_rtx(struct sctp_transport *);
  840. void sctp_transport_reset_hb_timer(struct sctp_transport *);
  841. void sctp_transport_reset_reconf_timer(struct sctp_transport *transport);
  842. int sctp_transport_hold(struct sctp_transport *);
  843. void sctp_transport_put(struct sctp_transport *);
  844. void sctp_transport_update_rto(struct sctp_transport *, __u32);
  845. void sctp_transport_raise_cwnd(struct sctp_transport *, __u32, __u32);
  846. void sctp_transport_lower_cwnd(struct sctp_transport *t,
  847. enum sctp_lower_cwnd reason);
  848. void sctp_transport_burst_limited(struct sctp_transport *);
  849. void sctp_transport_burst_reset(struct sctp_transport *);
  850. unsigned long sctp_transport_timeout(struct sctp_transport *);
  851. void sctp_transport_reset(struct sctp_transport *t);
  852. bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu);
  853. void sctp_transport_immediate_rtx(struct sctp_transport *);
  854. void sctp_transport_dst_release(struct sctp_transport *t);
  855. void sctp_transport_dst_confirm(struct sctp_transport *t);
  856. /* This is the structure we use to queue packets as they come into
  857. * SCTP. We write packets to it and read chunks from it.
  858. */
  859. struct sctp_inq {
  860. /* This is actually a queue of sctp_chunk each
  861. * containing a partially decoded packet.
  862. */
  863. struct list_head in_chunk_list;
  864. /* This is the packet which is currently off the in queue and is
  865. * being worked on through the inbound chunk processing.
  866. */
  867. struct sctp_chunk *in_progress;
  868. /* This is the delayed task to finish delivering inbound
  869. * messages.
  870. */
  871. struct work_struct immediate;
  872. };
  873. void sctp_inq_init(struct sctp_inq *);
  874. void sctp_inq_free(struct sctp_inq *);
  875. void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet);
  876. struct sctp_chunk *sctp_inq_pop(struct sctp_inq *);
  877. struct sctp_chunkhdr *sctp_inq_peek(struct sctp_inq *);
  878. void sctp_inq_set_th_handler(struct sctp_inq *, work_func_t);
  879. /* This is the structure we use to hold outbound chunks. You push
  880. * chunks in and they automatically pop out the other end as bundled
  881. * packets (it calls (*output_handler)()).
  882. *
  883. * This structure covers sections 6.3, 6.4, 6.7, 6.8, 6.10, 7., 8.1,
  884. * and 8.2 of the v13 draft.
  885. *
  886. * It handles retransmissions. The connection to the timeout portion
  887. * of the state machine is through sctp_..._timeout() and timeout_handler.
  888. *
  889. * If you feed it SACKs, it will eat them.
  890. *
  891. * If you give it big chunks, it will fragment them.
  892. *
  893. * It assigns TSN's to data chunks. This happens at the last possible
  894. * instant before transmission.
  895. *
  896. * When free()'d, it empties itself out via output_handler().
  897. */
  898. struct sctp_outq {
  899. struct sctp_association *asoc;
  900. /* Data pending that has never been transmitted. */
  901. struct list_head out_chunk_list;
  902. /* Stream scheduler being used */
  903. struct sctp_sched_ops *sched;
  904. unsigned int out_qlen; /* Total length of queued data chunks. */
  905. /* Error of send failed, may used in SCTP_SEND_FAILED event. */
  906. unsigned int error;
  907. /* These are control chunks we want to send. */
  908. struct list_head control_chunk_list;
  909. /* These are chunks that have been sacked but are above the
  910. * CTSN, or cumulative tsn ack point.
  911. */
  912. struct list_head sacked;
  913. /* Put chunks on this list to schedule them for
  914. * retransmission.
  915. */
  916. struct list_head retransmit;
  917. /* Put chunks on this list to save them for FWD TSN processing as
  918. * they were abandoned.
  919. */
  920. struct list_head abandoned;
  921. /* How many unackd bytes do we have in-flight? */
  922. __u32 outstanding_bytes;
  923. /* Are we doing fast-rtx on this queue */
  924. char fast_rtx;
  925. /* Corked? */
  926. char cork;
  927. };
  928. void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
  929. void sctp_outq_teardown(struct sctp_outq *);
  930. void sctp_outq_free(struct sctp_outq*);
  931. void sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk, gfp_t);
  932. int sctp_outq_sack(struct sctp_outq *, struct sctp_chunk *);
  933. int sctp_outq_is_empty(const struct sctp_outq *);
  934. void sctp_outq_restart(struct sctp_outq *);
  935. void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
  936. enum sctp_retransmit_reason reason);
  937. void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
  938. void sctp_outq_uncork(struct sctp_outq *, gfp_t gfp);
  939. void sctp_prsctp_prune(struct sctp_association *asoc,
  940. struct sctp_sndrcvinfo *sinfo, int msg_len);
  941. void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
  942. /* Uncork and flush an outqueue. */
  943. static inline void sctp_outq_cork(struct sctp_outq *q)
  944. {
  945. q->cork = 1;
  946. }
  947. /* SCTP skb control block.
  948. * sctp_input_cb is currently used on rx and sock rx queue
  949. */
  950. struct sctp_input_cb {
  951. union {
  952. struct inet_skb_parm h4;
  953. #if IS_ENABLED(CONFIG_IPV6)
  954. struct inet6_skb_parm h6;
  955. #endif
  956. } header;
  957. struct sctp_chunk *chunk;
  958. struct sctp_af *af;
  959. };
  960. #define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0]))
  961. struct sctp_output_cb {
  962. struct sk_buff *last;
  963. };
  964. #define SCTP_OUTPUT_CB(__skb) ((struct sctp_output_cb *)&((__skb)->cb[0]))
  965. static inline const struct sk_buff *sctp_gso_headskb(const struct sk_buff *skb)
  966. {
  967. const struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
  968. return chunk->head_skb ? : skb;
  969. }
  970. /* These bind address data fields common between endpoints and associations */
  971. struct sctp_bind_addr {
  972. /* RFC 2960 12.1 Parameters necessary for the SCTP instance
  973. *
  974. * SCTP Port: The local SCTP port number the endpoint is
  975. * bound to.
  976. */
  977. __u16 port;
  978. /* RFC 2960 12.1 Parameters necessary for the SCTP instance
  979. *
  980. * Address List: The list of IP addresses that this instance
  981. * has bound. This information is passed to one's
  982. * peer(s) in INIT and INIT ACK chunks.
  983. */
  984. struct list_head address_list;
  985. };
  986. void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
  987. void sctp_bind_addr_free(struct sctp_bind_addr *);
  988. int sctp_bind_addr_copy(struct net *net, struct sctp_bind_addr *dest,
  989. const struct sctp_bind_addr *src,
  990. enum sctp_scope scope, gfp_t gfp,
  991. int flags);
  992. int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
  993. const struct sctp_bind_addr *src,
  994. gfp_t gfp);
  995. int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
  996. int new_size, __u8 addr_state, gfp_t gfp);
  997. int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
  998. int sctp_bind_addr_match(struct sctp_bind_addr *, const union sctp_addr *,
  999. struct sctp_sock *);
  1000. int sctp_bind_addr_conflict(struct sctp_bind_addr *, const union sctp_addr *,
  1001. struct sctp_sock *, struct sctp_sock *);
  1002. int sctp_bind_addr_state(const struct sctp_bind_addr *bp,
  1003. const union sctp_addr *addr);
  1004. union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
  1005. const union sctp_addr *addrs,
  1006. int addrcnt,
  1007. struct sctp_sock *opt);
  1008. union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
  1009. int *addrs_len,
  1010. gfp_t gfp);
  1011. int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
  1012. __u16 port, gfp_t gfp);
  1013. enum sctp_scope sctp_scope(const union sctp_addr *addr);
  1014. int sctp_in_scope(struct net *net, const union sctp_addr *addr,
  1015. const enum sctp_scope scope);
  1016. int sctp_is_any(struct sock *sk, const union sctp_addr *addr);
  1017. int sctp_is_ep_boundall(struct sock *sk);
  1018. /* What type of endpoint? */
  1019. enum sctp_endpoint_type {
  1020. SCTP_EP_TYPE_SOCKET,
  1021. SCTP_EP_TYPE_ASSOCIATION,
  1022. };
  1023. /*
  1024. * A common base class to bridge the implmentation view of a
  1025. * socket (usually listening) endpoint versus an association's
  1026. * local endpoint.
  1027. * This common structure is useful for several purposes:
  1028. * 1) Common interface for lookup routines.
  1029. * a) Subfunctions work for either endpoint or association
  1030. * b) Single interface to lookup allows hiding the lookup lock rather
  1031. * than acquiring it externally.
  1032. * 2) Common interface for the inbound chunk handling/state machine.
  1033. * 3) Common object handling routines for reference counting, etc.
  1034. * 4) Disentangle association lookup from endpoint lookup, where we
  1035. * do not have to find our endpoint to find our association.
  1036. *
  1037. */
  1038. struct sctp_ep_common {
  1039. /* Fields to help us manage our entries in the hash tables. */
  1040. struct hlist_node node;
  1041. int hashent;
  1042. /* Runtime type information. What kind of endpoint is this? */
  1043. enum sctp_endpoint_type type;
  1044. /* Some fields to help us manage this object.
  1045. * refcnt - Reference count access to this object.
  1046. * dead - Do not attempt to use this object.
  1047. */
  1048. refcount_t refcnt;
  1049. bool dead;
  1050. /* What socket does this endpoint belong to? */
  1051. struct sock *sk;
  1052. /* This is where we receive inbound chunks. */
  1053. struct sctp_inq inqueue;
  1054. /* This substructure includes the defining parameters of the
  1055. * endpoint:
  1056. * bind_addr.port is our shared port number.
  1057. * bind_addr.address_list is our set of local IP addresses.
  1058. */
  1059. struct sctp_bind_addr bind_addr;
  1060. };
  1061. /* RFC Section 1.4 Key Terms
  1062. *
  1063. * o SCTP endpoint: The logical sender/receiver of SCTP packets. On a
  1064. * multi-homed host, an SCTP endpoint is represented to its peers as a
  1065. * combination of a set of eligible destination transport addresses to
  1066. * which SCTP packets can be sent and a set of eligible source
  1067. * transport addresses from which SCTP packets can be received.
  1068. * All transport addresses used by an SCTP endpoint must use the
  1069. * same port number, but can use multiple IP addresses. A transport
  1070. * address used by an SCTP endpoint must not be used by another
  1071. * SCTP endpoint. In other words, a transport address is unique
  1072. * to an SCTP endpoint.
  1073. *
  1074. * From an implementation perspective, each socket has one of these.
  1075. * A TCP-style socket will have exactly one association on one of
  1076. * these. An UDP-style socket will have multiple associations hanging
  1077. * off one of these.
  1078. */
  1079. struct sctp_endpoint {
  1080. /* Common substructure for endpoint and association. */
  1081. struct sctp_ep_common base;
  1082. /* Associations: A list of current associations and mappings
  1083. * to the data consumers for each association. This
  1084. * may be in the form of a hash table or other
  1085. * implementation dependent structure. The data
  1086. * consumers may be process identification
  1087. * information such as file descriptors, named pipe
  1088. * pointer, or table pointers dependent on how SCTP
  1089. * is implemented.
  1090. */
  1091. /* This is really a list of struct sctp_association entries. */
  1092. struct list_head asocs;
  1093. /* Secret Key: A secret key used by this endpoint to compute
  1094. * the MAC. This SHOULD be a cryptographic quality
  1095. * random number with a sufficient length.
  1096. * Discussion in [RFC1750] can be helpful in
  1097. * selection of the key.
  1098. */
  1099. __u8 secret_key[SCTP_SECRET_SIZE];
  1100. /* digest: This is a digest of the sctp cookie. This field is
  1101. * only used on the receive path when we try to validate
  1102. * that the cookie has not been tampered with. We put
  1103. * this here so we pre-allocate this once and can re-use
  1104. * on every receive.
  1105. */
  1106. __u8 *digest;
  1107. /* sendbuf acct. policy. */
  1108. __u32 sndbuf_policy;
  1109. /* rcvbuf acct. policy. */
  1110. __u32 rcvbuf_policy;
  1111. /* SCTP AUTH: array of the HMACs that will be allocated
  1112. * we need this per association so that we don't serialize
  1113. */
  1114. struct crypto_shash **auth_hmacs;
  1115. /* SCTP-AUTH: hmacs for the endpoint encoded into parameter */
  1116. struct sctp_hmac_algo_param *auth_hmacs_list;
  1117. /* SCTP-AUTH: chunks to authenticate encoded into parameter */
  1118. struct sctp_chunks_param *auth_chunk_list;
  1119. /* SCTP-AUTH: endpoint shared keys */
  1120. struct list_head endpoint_shared_keys;
  1121. __u16 active_key_id;
  1122. __u8 auth_enable:1,
  1123. prsctp_enable:1,
  1124. reconf_enable:1;
  1125. __u8 strreset_enable;
  1126. /* Security identifiers from incoming (INIT). These are set by
  1127. * security_sctp_assoc_request(). These will only be used by
  1128. * SCTP TCP type sockets and peeled off connections as they
  1129. * cause a new socket to be generated. security_sctp_sk_clone()
  1130. * will then plug these into the new socket.
  1131. */
  1132. u32 secid;
  1133. u32 peer_secid;
  1134. };
  1135. /* Recover the outter endpoint structure. */
  1136. static inline struct sctp_endpoint *sctp_ep(struct sctp_ep_common *base)
  1137. {
  1138. struct sctp_endpoint *ep;
  1139. ep = container_of(base, struct sctp_endpoint, base);
  1140. return ep;
  1141. }
  1142. /* These are function signatures for manipulating endpoints. */
  1143. struct sctp_endpoint *sctp_endpoint_new(struct sock *, gfp_t);
  1144. void sctp_endpoint_free(struct sctp_endpoint *);
  1145. void sctp_endpoint_put(struct sctp_endpoint *);
  1146. void sctp_endpoint_hold(struct sctp_endpoint *);
  1147. void sctp_endpoint_add_asoc(struct sctp_endpoint *, struct sctp_association *);
  1148. struct sctp_association *sctp_endpoint_lookup_assoc(
  1149. const struct sctp_endpoint *ep,
  1150. const union sctp_addr *paddr,
  1151. struct sctp_transport **);
  1152. bool sctp_endpoint_is_peeled_off(struct sctp_endpoint *ep,
  1153. const union sctp_addr *paddr);
  1154. struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *,
  1155. struct net *, const union sctp_addr *);
  1156. bool sctp_has_association(struct net *net, const union sctp_addr *laddr,
  1157. const union sctp_addr *paddr);
  1158. int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep,
  1159. const struct sctp_association *asoc,
  1160. enum sctp_cid cid, struct sctp_init_chunk *peer_init,
  1161. struct sctp_chunk *chunk, struct sctp_chunk **err_chunk);
  1162. int sctp_process_init(struct sctp_association *, struct sctp_chunk *chunk,
  1163. const union sctp_addr *peer,
  1164. struct sctp_init_chunk *init, gfp_t gfp);
  1165. __u32 sctp_generate_tag(const struct sctp_endpoint *);
  1166. __u32 sctp_generate_tsn(const struct sctp_endpoint *);
  1167. struct sctp_inithdr_host {
  1168. __u32 init_tag;
  1169. __u32 a_rwnd;
  1170. __u16 num_outbound_streams;
  1171. __u16 num_inbound_streams;
  1172. __u32 initial_tsn;
  1173. };
  1174. struct sctp_stream_priorities {
  1175. /* List of priorities scheduled */
  1176. struct list_head prio_sched;
  1177. /* List of streams scheduled */
  1178. struct list_head active;
  1179. /* The next stream stream in line */
  1180. struct sctp_stream_out_ext *next;
  1181. __u16 prio;
  1182. };
  1183. struct sctp_stream_out_ext {
  1184. __u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
  1185. __u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
  1186. struct list_head outq; /* chunks enqueued by this stream */
  1187. union {
  1188. struct {
  1189. /* Scheduled streams list */
  1190. struct list_head prio_list;
  1191. struct sctp_stream_priorities *prio_head;
  1192. };
  1193. /* Fields used by RR scheduler */
  1194. struct {
  1195. struct list_head rr_list;
  1196. };
  1197. };
  1198. };
  1199. struct sctp_stream_out {
  1200. union {
  1201. __u32 mid;
  1202. __u16 ssn;
  1203. };
  1204. __u32 mid_uo;
  1205. struct sctp_stream_out_ext *ext;
  1206. __u8 state;
  1207. };
  1208. struct sctp_stream_in {
  1209. union {
  1210. __u32 mid;
  1211. __u16 ssn;
  1212. };
  1213. __u32 mid_uo;
  1214. __u32 fsn;
  1215. __u32 fsn_uo;
  1216. char pd_mode;
  1217. char pd_mode_uo;
  1218. };
  1219. struct sctp_stream {
  1220. struct sctp_stream_out *out;
  1221. struct sctp_stream_in *in;
  1222. __u16 outcnt;
  1223. __u16 incnt;
  1224. /* Current stream being sent, if any */
  1225. struct sctp_stream_out *out_curr;
  1226. union {
  1227. /* Fields used by priority scheduler */
  1228. struct {
  1229. /* List of priorities scheduled */
  1230. struct list_head prio_list;
  1231. };
  1232. /* Fields used by RR scheduler */
  1233. struct {
  1234. /* List of streams scheduled */
  1235. struct list_head rr_list;
  1236. /* The next stream stream in line */
  1237. struct sctp_stream_out_ext *rr_next;
  1238. };
  1239. };
  1240. struct sctp_stream_interleave *si;
  1241. };
  1242. #define SCTP_STREAM_CLOSED 0x00
  1243. #define SCTP_STREAM_OPEN 0x01
  1244. static inline __u16 sctp_datachk_len(const struct sctp_stream *stream)
  1245. {
  1246. return stream->si->data_chunk_len;
  1247. }
  1248. static inline __u16 sctp_datahdr_len(const struct sctp_stream *stream)
  1249. {
  1250. return stream->si->data_chunk_len - sizeof(struct sctp_chunkhdr);
  1251. }
  1252. static inline __u16 sctp_ftsnchk_len(const struct sctp_stream *stream)
  1253. {
  1254. return stream->si->ftsn_chunk_len;
  1255. }
  1256. static inline __u16 sctp_ftsnhdr_len(const struct sctp_stream *stream)
  1257. {
  1258. return stream->si->ftsn_chunk_len - sizeof(struct sctp_chunkhdr);
  1259. }
  1260. /* SCTP_GET_ASSOC_STATS counters */
  1261. struct sctp_priv_assoc_stats {
  1262. /* Maximum observed rto in the association during subsequent
  1263. * observations. Value is set to 0 if no RTO measurement took place
  1264. * The transport where the max_rto was observed is returned in
  1265. * obs_rto_ipaddr
  1266. */
  1267. struct sockaddr_storage obs_rto_ipaddr;
  1268. __u64 max_obs_rto;
  1269. /* Total In and Out SACKs received and sent */
  1270. __u64 isacks;
  1271. __u64 osacks;
  1272. /* Total In and Out packets received and sent */
  1273. __u64 opackets;
  1274. __u64 ipackets;
  1275. /* Total retransmitted chunks */
  1276. __u64 rtxchunks;
  1277. /* TSN received > next expected */
  1278. __u64 outofseqtsns;
  1279. /* Duplicate Chunks received */
  1280. __u64 idupchunks;
  1281. /* Gap Ack Blocks received */
  1282. __u64 gapcnt;
  1283. /* Unordered data chunks sent and received */
  1284. __u64 ouodchunks;
  1285. __u64 iuodchunks;
  1286. /* Ordered data chunks sent and received */
  1287. __u64 oodchunks;
  1288. __u64 iodchunks;
  1289. /* Control chunks sent and received */
  1290. __u64 octrlchunks;
  1291. __u64 ictrlchunks;
  1292. };
  1293. /* RFC2960
  1294. *
  1295. * 12. Recommended Transmission Control Block (TCB) Parameters
  1296. *
  1297. * This section details a recommended set of parameters that should
  1298. * be contained within the TCB for an implementation. This section is
  1299. * for illustrative purposes and should not be deemed as requirements
  1300. * on an implementation or as an exhaustive list of all parameters
  1301. * inside an SCTP TCB. Each implementation may need its own additional
  1302. * parameters for optimization.
  1303. */
  1304. /* Here we have information about each individual association. */
  1305. struct sctp_association {
  1306. /* A base structure common to endpoint and association.
  1307. * In this context, it represents the associations's view
  1308. * of the local endpoint of the association.
  1309. */
  1310. struct sctp_ep_common base;
  1311. /* Associations on the same socket. */
  1312. struct list_head asocs;
  1313. /* association id. */
  1314. sctp_assoc_t assoc_id;
  1315. /* This is our parent endpoint. */
  1316. struct sctp_endpoint *ep;
  1317. /* These are those association elements needed in the cookie. */
  1318. struct sctp_cookie c;
  1319. /* This is all information about our peer. */
  1320. struct {
  1321. /* transport_addr_list
  1322. *
  1323. * Peer : A list of SCTP transport addresses that the
  1324. * Transport : peer is bound to. This information is derived
  1325. * Address : from the INIT or INIT ACK and is used to
  1326. * List : associate an inbound packet with a given
  1327. * : association. Normally this information is
  1328. * : hashed or keyed for quick lookup and access
  1329. * : of the TCB.
  1330. * : The list is also initialized with the list
  1331. * : of addresses passed with the sctp_connectx()
  1332. * : call.
  1333. *
  1334. * It is a list of SCTP_transport's.
  1335. */
  1336. struct list_head transport_addr_list;
  1337. /* rwnd
  1338. *
  1339. * Peer Rwnd : Current calculated value of the peer's rwnd.
  1340. */
  1341. __u32 rwnd;
  1342. /* transport_count
  1343. *
  1344. * Peer : A count of the number of peer addresses
  1345. * Transport : in the Peer Transport Address List.
  1346. * Address :
  1347. * Count :
  1348. */
  1349. __u16 transport_count;
  1350. /* port
  1351. * The transport layer port number.
  1352. */
  1353. __u16 port;
  1354. /* primary_path
  1355. *
  1356. * Primary : This is the current primary destination
  1357. * Path : transport address of the peer endpoint. It
  1358. * : may also specify a source transport address
  1359. * : on this endpoint.
  1360. *
  1361. * All of these paths live on transport_addr_list.
  1362. *
  1363. * At the bakeoffs, we discovered that the intent of
  1364. * primaryPath is that it only changes when the ULP
  1365. * asks to have it changed. We add the activePath to
  1366. * designate the connection we are currently using to
  1367. * transmit new data and most control chunks.
  1368. */
  1369. struct sctp_transport *primary_path;
  1370. /* Cache the primary path address here, when we
  1371. * need a an address for msg_name.
  1372. */
  1373. union sctp_addr primary_addr;
  1374. /* active_path
  1375. * The path that we are currently using to
  1376. * transmit new data and most control chunks.
  1377. */
  1378. struct sctp_transport *active_path;
  1379. /* retran_path
  1380. *
  1381. * RFC2960 6.4 Multi-homed SCTP Endpoints
  1382. * ...
  1383. * Furthermore, when its peer is multi-homed, an
  1384. * endpoint SHOULD try to retransmit a chunk to an
  1385. * active destination transport address that is
  1386. * different from the last destination address to
  1387. * which the DATA chunk was sent.
  1388. */
  1389. struct sctp_transport *retran_path;
  1390. /* Pointer to last transport I have sent on. */
  1391. struct sctp_transport *last_sent_to;
  1392. /* This is the last transport I have received DATA on. */
  1393. struct sctp_transport *last_data_from;
  1394. /*
  1395. * Mapping An array of bits or bytes indicating which out of
  1396. * Array order TSN's have been received (relative to the
  1397. * Last Rcvd TSN). If no gaps exist, i.e. no out of
  1398. * order packets have been received, this array
  1399. * will be set to all zero. This structure may be
  1400. * in the form of a circular buffer or bit array.
  1401. *
  1402. * Last Rcvd : This is the last TSN received in
  1403. * TSN : sequence. This value is set initially by
  1404. * : taking the peer's Initial TSN, received in
  1405. * : the INIT or INIT ACK chunk, and subtracting
  1406. * : one from it.
  1407. *
  1408. * Throughout most of the specification this is called the
  1409. * "Cumulative TSN ACK Point". In this case, we
  1410. * ignore the advice in 12.2 in favour of the term
  1411. * used in the bulk of the text. This value is hidden
  1412. * in tsn_map--we get it by calling sctp_tsnmap_get_ctsn().
  1413. */
  1414. struct sctp_tsnmap tsn_map;
  1415. /* This mask is used to disable sending the ASCONF chunk
  1416. * with specified parameter to peer.
  1417. */
  1418. __be16 addip_disabled_mask;
  1419. /* These are capabilities which our peer advertised. */
  1420. __u8 ecn_capable:1, /* Can peer do ECN? */
  1421. ipv4_address:1, /* Peer understands IPv4 addresses? */
  1422. ipv6_address:1, /* Peer understands IPv6 addresses? */
  1423. hostname_address:1, /* Peer understands DNS addresses? */
  1424. asconf_capable:1, /* Does peer support ADDIP? */
  1425. prsctp_capable:1, /* Can peer do PR-SCTP? */
  1426. reconf_capable:1, /* Can peer do RE-CONFIG? */
  1427. auth_capable:1; /* Is peer doing SCTP-AUTH? */
  1428. /* sack_needed : This flag indicates if the next received
  1429. * : packet is to be responded to with a
  1430. * : SACK. This is initialized to 0. When a packet
  1431. * : is received sack_cnt is incremented. If this value
  1432. * : reaches 2 or more, a SACK is sent and the
  1433. * : value is reset to 0. Note: This is used only
  1434. * : when no DATA chunks are received out of
  1435. * : order. When DATA chunks are out of order,
  1436. * : SACK's are not delayed (see Section 6).
  1437. */
  1438. __u8 sack_needed:1, /* Do we need to sack the peer? */
  1439. sack_generation:1,
  1440. zero_window_announced:1;
  1441. __u32 sack_cnt;
  1442. __u32 adaptation_ind; /* Adaptation Code point. */
  1443. struct sctp_inithdr_host i;
  1444. void *cookie;
  1445. int cookie_len;
  1446. /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.
  1447. * C1) ... "Peer-Serial-Number'. This value MUST be initialized to the
  1448. * Initial TSN Value minus 1
  1449. */
  1450. __u32 addip_serial;
  1451. /* SCTP-AUTH: We need to know pears random number, hmac list
  1452. * and authenticated chunk list. All that is part of the
  1453. * cookie and these are just pointers to those locations
  1454. */
  1455. struct sctp_random_param *peer_random;
  1456. struct sctp_chunks_param *peer_chunks;
  1457. struct sctp_hmac_algo_param *peer_hmacs;
  1458. } peer;
  1459. /* State : A state variable indicating what state the
  1460. * : association is in, i.e. COOKIE-WAIT,
  1461. * : COOKIE-ECHOED, ESTABLISHED, SHUTDOWN-PENDING,
  1462. * : SHUTDOWN-SENT, SHUTDOWN-RECEIVED, SHUTDOWN-ACK-SENT.
  1463. *
  1464. * Note: No "CLOSED" state is illustrated since if a
  1465. * association is "CLOSED" its TCB SHOULD be removed.
  1466. *
  1467. * In this implementation we DO have a CLOSED
  1468. * state which is used during initiation and shutdown.
  1469. *
  1470. * State takes values from SCTP_STATE_*.
  1471. */
  1472. enum sctp_state state;
  1473. /* Overall : The overall association error count.
  1474. * Error Count : [Clear this any time I get something.]
  1475. */
  1476. int overall_error_count;
  1477. /* The cookie life I award for any cookie. */
  1478. ktime_t cookie_life;
  1479. /* These are the association's initial, max, and min RTO values.
  1480. * These values will be initialized by system defaults, but can
  1481. * be modified via the SCTP_RTOINFO socket option.
  1482. */
  1483. unsigned long rto_initial;
  1484. unsigned long rto_max;
  1485. unsigned long rto_min;
  1486. /* Maximum number of new data packets that can be sent in a burst. */
  1487. int max_burst;
  1488. /* This is the max_retrans value for the association. This value will
  1489. * be initialized initialized from system defaults, but can be
  1490. * modified by the SCTP_ASSOCINFO socket option.
  1491. */
  1492. int max_retrans;
  1493. /* This is the partially failed retrans value for the transport
  1494. * and will be initialized from the assocs value. This can be
  1495. * changed using the SCTP_PEER_ADDR_THLDS socket option
  1496. */
  1497. int pf_retrans;
  1498. /* Maximum number of times the endpoint will retransmit INIT */
  1499. __u16 max_init_attempts;
  1500. /* How many times have we resent an INIT? */
  1501. __u16 init_retries;
  1502. /* The largest timeout or RTO value to use in attempting an INIT */
  1503. unsigned long max_init_timeo;
  1504. /* Heartbeat interval: The endpoint sends out a Heartbeat chunk to
  1505. * the destination address every heartbeat interval. This value
  1506. * will be inherited by all new transports.
  1507. */
  1508. unsigned long hbinterval;
  1509. /* This is the max_retrans value for new transports in the
  1510. * association.
  1511. */
  1512. __u16 pathmaxrxt;
  1513. /* Flag that path mtu update is pending */
  1514. __u8 pmtu_pending;
  1515. /* Association : The smallest PMTU discovered for all of the
  1516. * PMTU : peer's transport addresses.
  1517. */
  1518. __u32 pathmtu;
  1519. /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
  1520. __u32 param_flags;
  1521. __u32 sackfreq;
  1522. /* SACK delay timeout */
  1523. unsigned long sackdelay;
  1524. unsigned long timeouts[SCTP_NUM_TIMEOUT_TYPES];
  1525. struct timer_list timers[SCTP_NUM_TIMEOUT_TYPES];
  1526. /* Transport to which SHUTDOWN chunk was last sent. */
  1527. struct sctp_transport *shutdown_last_sent_to;
  1528. /* Transport to which INIT chunk was last sent. */
  1529. struct sctp_transport *init_last_sent_to;
  1530. /* How many times have we resent a SHUTDOWN */
  1531. int shutdown_retries;
  1532. /* Next TSN : The next TSN number to be assigned to a new
  1533. * : DATA chunk. This is sent in the INIT or INIT
  1534. * : ACK chunk to the peer and incremented each
  1535. * : time a DATA chunk is assigned a TSN
  1536. * : (normally just prior to transmit or during
  1537. * : fragmentation).
  1538. */
  1539. __u32 next_tsn;
  1540. /*
  1541. * Last Rcvd : This is the last TSN received in sequence. This value
  1542. * TSN : is set initially by taking the peer's Initial TSN,
  1543. * : received in the INIT or INIT ACK chunk, and
  1544. * : subtracting one from it.
  1545. *
  1546. * Most of RFC 2960 refers to this as the Cumulative TSN Ack Point.
  1547. */
  1548. __u32 ctsn_ack_point;
  1549. /* PR-SCTP Advanced.Peer.Ack.Point */
  1550. __u32 adv_peer_ack_point;
  1551. /* Highest TSN that is acknowledged by incoming SACKs. */
  1552. __u32 highest_sacked;
  1553. /* TSN marking the fast recovery exit point */
  1554. __u32 fast_recovery_exit;
  1555. /* Flag to track the current fast recovery state */
  1556. __u8 fast_recovery;
  1557. /* The number of unacknowledged data chunks. Reported through
  1558. * the SCTP_STATUS sockopt.
  1559. */
  1560. __u16 unack_data;
  1561. /* The total number of data chunks that we've had to retransmit
  1562. * as the result of a T3 timer expiration
  1563. */
  1564. __u32 rtx_data_chunks;
  1565. /* This is the association's receive buffer space. This value is used
  1566. * to set a_rwnd field in an INIT or a SACK chunk.
  1567. */
  1568. __u32 rwnd;
  1569. /* This is the last advertised value of rwnd over a SACK chunk. */
  1570. __u32 a_rwnd;
  1571. /* Number of bytes by which the rwnd has slopped. The rwnd is allowed
  1572. * to slop over a maximum of the association's frag_point.
  1573. */
  1574. __u32 rwnd_over;
  1575. /* Keeps treack of rwnd pressure. This happens when we have
  1576. * a window, but not recevie buffer (i.e small packets). This one
  1577. * is releases slowly (1 PMTU at a time ).
  1578. */
  1579. __u32 rwnd_press;
  1580. /* This is the sndbuf size in use for the association.
  1581. * This corresponds to the sndbuf size for the association,
  1582. * as specified in the sk->sndbuf.
  1583. */
  1584. int sndbuf_used;
  1585. /* This is the amount of memory that this association has allocated
  1586. * in the receive path at any given time.
  1587. */
  1588. atomic_t rmem_alloc;
  1589. /* This is the wait queue head for send requests waiting on
  1590. * the association sndbuf space.
  1591. */
  1592. wait_queue_head_t wait;
  1593. /* The message size at which SCTP fragmentation will occur. */
  1594. __u32 frag_point;
  1595. __u32 user_frag;
  1596. /* Counter used to count INIT errors. */
  1597. int init_err_counter;
  1598. /* Count the number of INIT cycles (for doubling timeout). */
  1599. int init_cycle;
  1600. /* Default send parameters. */
  1601. __u16 default_stream;
  1602. __u16 default_flags;
  1603. __u32 default_ppid;
  1604. __u32 default_context;
  1605. __u32 default_timetolive;
  1606. /* Default receive parameters */
  1607. __u32 default_rcv_context;
  1608. /* Stream arrays */
  1609. struct sctp_stream stream;
  1610. /* All outbound chunks go through this structure. */
  1611. struct sctp_outq outqueue;
  1612. /* A smart pipe that will handle reordering and fragmentation,
  1613. * as well as handle passing events up to the ULP.
  1614. */
  1615. struct sctp_ulpq ulpq;
  1616. /* Last TSN that caused an ECNE Chunk to be sent. */
  1617. __u32 last_ecne_tsn;
  1618. /* Last TSN that caused a CWR Chunk to be sent. */
  1619. __u32 last_cwr_tsn;
  1620. /* How many duplicated TSNs have we seen? */
  1621. int numduptsns;
  1622. /* These are to support
  1623. * "SCTP Extensions for Dynamic Reconfiguration of IP Addresses
  1624. * and Enforcement of Flow and Message Limits"
  1625. * <draft-ietf-tsvwg-addip-sctp-02.txt>
  1626. * or "ADDIP" for short.
  1627. */
  1628. /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
  1629. *
  1630. * R1) One and only one ASCONF Chunk MAY be in transit and
  1631. * unacknowledged at any one time. If a sender, after sending
  1632. * an ASCONF chunk, decides it needs to transfer another
  1633. * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
  1634. * returns from the previous ASCONF Chunk before sending a
  1635. * subsequent ASCONF. Note this restriction binds each side,
  1636. * so at any time two ASCONF may be in-transit on any given
  1637. * association (one sent from each endpoint).
  1638. *
  1639. * [This is our one-and-only-one ASCONF in flight. If we do
  1640. * not have an ASCONF in flight, this is NULL.]
  1641. */
  1642. struct sctp_chunk *addip_last_asconf;
  1643. /* ADDIP Section 5.2 Upon reception of an ASCONF Chunk.
  1644. *
  1645. * This is needed to implement itmes E1 - E4 of the updated
  1646. * spec. Here is the justification:
  1647. *
  1648. * Since the peer may bundle multiple ASCONF chunks toward us,
  1649. * we now need the ability to cache multiple ACKs. The section
  1650. * describes in detail how they are cached and cleaned up.
  1651. */
  1652. struct list_head asconf_ack_list;
  1653. /* These ASCONF chunks are waiting to be sent.
  1654. *
  1655. * These chunaks can't be pushed to outqueue until receiving
  1656. * ASCONF_ACK for the previous ASCONF indicated by
  1657. * addip_last_asconf, so as to guarantee that only one ASCONF
  1658. * is in flight at any time.
  1659. *
  1660. * ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
  1661. *
  1662. * In defining the ASCONF Chunk transfer procedures, it is
  1663. * essential that these transfers MUST NOT cause congestion
  1664. * within the network. To achieve this, we place these
  1665. * restrictions on the transfer of ASCONF Chunks:
  1666. *
  1667. * R1) One and only one ASCONF Chunk MAY be in transit and
  1668. * unacknowledged at any one time. If a sender, after sending
  1669. * an ASCONF chunk, decides it needs to transfer another
  1670. * ASCONF Chunk, it MUST wait until the ASCONF-ACK Chunk
  1671. * returns from the previous ASCONF Chunk before sending a
  1672. * subsequent ASCONF. Note this restriction binds each side,
  1673. * so at any time two ASCONF may be in-transit on any given
  1674. * association (one sent from each endpoint).
  1675. *
  1676. *
  1677. * [I really think this is EXACTLY the sort of intelligence
  1678. * which already resides in sctp_outq. Please move this
  1679. * queue and its supporting logic down there. --piggy]
  1680. */
  1681. struct list_head addip_chunk_list;
  1682. /* ADDIP Section 4.1 ASCONF Chunk Procedures
  1683. *
  1684. * A2) A serial number should be assigned to the Chunk. The
  1685. * serial number SHOULD be a monotonically increasing
  1686. * number. The serial number SHOULD be initialized at
  1687. * the start of the association to the same value as the
  1688. * Initial TSN and every time a new ASCONF chunk is created
  1689. * it is incremented by one after assigning the serial number
  1690. * to the newly created chunk.
  1691. *
  1692. * ADDIP
  1693. * 3.1.1 Address/Stream Configuration Change Chunk (ASCONF)
  1694. *
  1695. * Serial Number : 32 bits (unsigned integer)
  1696. *
  1697. * This value represents a Serial Number for the ASCONF
  1698. * Chunk. The valid range of Serial Number is from 0 to
  1699. * 4294967295 (2^32 - 1). Serial Numbers wrap back to 0
  1700. * after reaching 4294967295.
  1701. */
  1702. __u32 addip_serial;
  1703. int src_out_of_asoc_ok;
  1704. union sctp_addr *asconf_addr_del_pending;
  1705. struct sctp_transport *new_transport;
  1706. /* SCTP AUTH: list of the endpoint shared keys. These
  1707. * keys are provided out of band by the user applicaton
  1708. * and can't change during the lifetime of the association
  1709. */
  1710. struct list_head endpoint_shared_keys;
  1711. /* SCTP AUTH:
  1712. * The current generated assocaition shared key (secret)
  1713. */
  1714. struct sctp_auth_bytes *asoc_shared_key;
  1715. struct sctp_shared_key *shkey;
  1716. /* SCTP AUTH: hmac id of the first peer requested algorithm
  1717. * that we support.
  1718. */
  1719. __u16 default_hmac_id;
  1720. __u16 active_key_id;
  1721. __u8 need_ecne:1, /* Need to send an ECNE Chunk? */
  1722. temp:1, /* Is it a temporary association? */
  1723. force_delay:1,
  1724. intl_enable:1,
  1725. prsctp_enable:1,
  1726. reconf_enable:1;
  1727. __u8 strreset_enable;
  1728. __u8 strreset_outstanding; /* request param count on the fly */
  1729. __u32 strreset_outseq; /* Update after receiving response */
  1730. __u32 strreset_inseq; /* Update after receiving request */
  1731. __u32 strreset_result[2]; /* save the results of last 2 responses */
  1732. struct sctp_chunk *strreset_chunk; /* save request chunk */
  1733. struct sctp_priv_assoc_stats stats;
  1734. int sent_cnt_removable;
  1735. __u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
  1736. __u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
  1737. };
  1738. /* An eyecatcher for determining if we are really looking at an
  1739. * association data structure.
  1740. */
  1741. enum {
  1742. SCTP_ASSOC_EYECATCHER = 0xa550c123,
  1743. };
  1744. /* Recover the outter association structure. */
  1745. static inline struct sctp_association *sctp_assoc(struct sctp_ep_common *base)
  1746. {
  1747. struct sctp_association *asoc;
  1748. asoc = container_of(base, struct sctp_association, base);
  1749. return asoc;
  1750. }
  1751. /* These are function signatures for manipulating associations. */
  1752. struct sctp_association *
  1753. sctp_association_new(const struct sctp_endpoint *ep, const struct sock *sk,
  1754. enum sctp_scope scope, gfp_t gfp);
  1755. void sctp_association_free(struct sctp_association *);
  1756. void sctp_association_put(struct sctp_association *);
  1757. void sctp_association_hold(struct sctp_association *);
  1758. struct sctp_transport *sctp_assoc_choose_alter_transport(
  1759. struct sctp_association *, struct sctp_transport *);
  1760. void sctp_assoc_update_retran_path(struct sctp_association *);
  1761. struct sctp_transport *sctp_assoc_lookup_paddr(const struct sctp_association *,
  1762. const union sctp_addr *);
  1763. int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
  1764. const union sctp_addr *laddr);
  1765. struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *,
  1766. const union sctp_addr *address,
  1767. const gfp_t gfp,
  1768. const int peer_state);
  1769. void sctp_assoc_del_peer(struct sctp_association *asoc,
  1770. const union sctp_addr *addr);
  1771. void sctp_assoc_rm_peer(struct sctp_association *asoc,
  1772. struct sctp_transport *peer);
  1773. void sctp_assoc_control_transport(struct sctp_association *asoc,
  1774. struct sctp_transport *transport,
  1775. enum sctp_transport_cmd command,
  1776. sctp_sn_error_t error);
  1777. struct sctp_transport *sctp_assoc_lookup_tsn(struct sctp_association *, __u32);
  1778. void sctp_assoc_migrate(struct sctp_association *, struct sock *);
  1779. int sctp_assoc_update(struct sctp_association *old,
  1780. struct sctp_association *new);
  1781. __u32 sctp_association_get_next_tsn(struct sctp_association *);
  1782. void sctp_assoc_update_frag_point(struct sctp_association *asoc);
  1783. void sctp_assoc_set_pmtu(struct sctp_association *asoc, __u32 pmtu);
  1784. void sctp_assoc_sync_pmtu(struct sctp_association *asoc);
  1785. void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned int);
  1786. void sctp_assoc_rwnd_decrease(struct sctp_association *, unsigned int);
  1787. void sctp_assoc_set_primary(struct sctp_association *,
  1788. struct sctp_transport *);
  1789. void sctp_assoc_del_nonprimary_peers(struct sctp_association *,
  1790. struct sctp_transport *);
  1791. int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
  1792. enum sctp_scope scope, gfp_t gfp);
  1793. int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *,
  1794. struct sctp_cookie*,
  1795. gfp_t gfp);
  1796. int sctp_assoc_set_id(struct sctp_association *, gfp_t);
  1797. void sctp_assoc_clean_asconf_ack_cache(const struct sctp_association *asoc);
  1798. struct sctp_chunk *sctp_assoc_lookup_asconf_ack(
  1799. const struct sctp_association *asoc,
  1800. __be32 serial);
  1801. void sctp_asconf_queue_teardown(struct sctp_association *asoc);
  1802. int sctp_cmp_addr_exact(const union sctp_addr *ss1,
  1803. const union sctp_addr *ss2);
  1804. struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc);
  1805. /* A convenience structure to parse out SCTP specific CMSGs. */
  1806. struct sctp_cmsgs {
  1807. struct sctp_initmsg *init;
  1808. struct sctp_sndrcvinfo *srinfo;
  1809. struct sctp_sndinfo *sinfo;
  1810. struct sctp_prinfo *prinfo;
  1811. struct sctp_authinfo *authinfo;
  1812. struct msghdr *addrs_msg;
  1813. };
  1814. /* Structure for tracking memory objects */
  1815. struct sctp_dbg_objcnt_entry {
  1816. char *label;
  1817. atomic_t *counter;
  1818. };
  1819. #endif /* __sctp_structs_h__ */