sctp_pcb.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /*-
  2. * SPDX-License-Identifier: BSD-3-Clause
  3. *
  4. * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
  5. * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
  6. * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * a) Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. *
  14. * b) Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the distribution.
  17. *
  18. * c) Neither the name of Cisco Systems, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  24. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #if defined(__FreeBSD__) && !defined(__Userspace__)
  35. #include <sys/cdefs.h>
  36. __FBSDID("$FreeBSD$");
  37. #endif
  38. #ifndef _NETINET_SCTP_PCB_H_
  39. #define _NETINET_SCTP_PCB_H_
  40. #include <netinet/sctp_os.h>
  41. #include <netinet/sctp.h>
  42. #include <netinet/sctp_constants.h>
  43. #include <netinet/sctp_sysctl.h>
  44. LIST_HEAD(sctppcbhead, sctp_inpcb);
  45. LIST_HEAD(sctpasochead, sctp_tcb);
  46. LIST_HEAD(sctpladdr, sctp_laddr);
  47. LIST_HEAD(sctpvtaghead, sctp_tagblock);
  48. LIST_HEAD(sctp_vrflist, sctp_vrf);
  49. LIST_HEAD(sctp_ifnlist, sctp_ifn);
  50. LIST_HEAD(sctp_ifalist, sctp_ifa);
  51. TAILQ_HEAD(sctp_readhead, sctp_queued_to_read);
  52. TAILQ_HEAD(sctp_streamhead, sctp_stream_queue_pending);
  53. #include <netinet/sctp_structs.h>
  54. #include <netinet/sctp_auth.h>
  55. #define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask)
  56. #define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask)
  57. struct sctp_vrf {
  58. LIST_ENTRY (sctp_vrf) next_vrf;
  59. struct sctp_ifalist *vrf_addr_hash;
  60. struct sctp_ifnlist ifnlist;
  61. uint32_t vrf_id;
  62. uint32_t tbl_id_v4; /* default v4 table id */
  63. uint32_t tbl_id_v6; /* default v6 table id */
  64. uint32_t total_ifa_count;
  65. u_long vrf_addr_hashmark;
  66. uint32_t refcount;
  67. };
  68. struct sctp_ifn {
  69. struct sctp_ifalist ifalist;
  70. struct sctp_vrf *vrf;
  71. LIST_ENTRY(sctp_ifn) next_ifn;
  72. LIST_ENTRY(sctp_ifn) next_bucket;
  73. void *ifn_p; /* never access without appropriate lock */
  74. uint32_t ifn_mtu;
  75. uint32_t ifn_type;
  76. uint32_t ifn_index; /* shorthand way to look at ifn for reference */
  77. uint32_t refcount; /* number of reference held should be >= ifa_count */
  78. uint32_t ifa_count; /* IFA's we hold (in our list - ifalist)*/
  79. uint32_t num_v6; /* number of v6 addresses */
  80. uint32_t num_v4; /* number of v4 addresses */
  81. uint32_t registered_af; /* registered address family for i/f events */
  82. char ifn_name[SCTP_IFNAMSIZ];
  83. };
  84. /* SCTP local IFA flags */
  85. #define SCTP_ADDR_VALID 0x00000001 /* its up and active */
  86. #define SCTP_BEING_DELETED 0x00000002 /* being deleted,
  87. * when refcount = 0. Note
  88. * that it is pulled from the ifn list
  89. * and ifa_p is nulled right away but
  90. * it cannot be freed until the last *net
  91. * pointing to it is deleted.
  92. */
  93. #define SCTP_ADDR_DEFER_USE 0x00000004 /* Hold off using this one */
  94. #define SCTP_ADDR_IFA_UNUSEABLE 0x00000008
  95. struct sctp_ifa {
  96. LIST_ENTRY(sctp_ifa) next_ifa;
  97. LIST_ENTRY(sctp_ifa) next_bucket;
  98. struct sctp_ifn *ifn_p; /* back pointer to parent ifn */
  99. void *ifa; /* pointer to ifa, needed for flag
  100. * update for that we MUST lock
  101. * appropriate locks. This is for V6.
  102. */
  103. union sctp_sockstore address;
  104. uint32_t refcount; /* number of folks referring to this */
  105. uint32_t flags;
  106. uint32_t localifa_flags;
  107. uint32_t vrf_id; /* vrf_id of this addr (for deleting) */
  108. uint8_t src_is_loop;
  109. uint8_t src_is_priv;
  110. uint8_t src_is_glob;
  111. uint8_t resv;
  112. };
  113. struct sctp_laddr {
  114. LIST_ENTRY(sctp_laddr) sctp_nxt_addr; /* next in list */
  115. struct sctp_ifa *ifa;
  116. uint32_t action; /* Used during asconf and adding
  117. * if no-zero src-addr selection will
  118. * not consider this address.
  119. */
  120. struct timeval start_time; /* time when this address was created */
  121. };
  122. struct sctp_block_entry {
  123. int error;
  124. };
  125. struct sctp_timewait {
  126. uint32_t tv_sec_at_expire; /* the seconds from boot to expire */
  127. uint32_t v_tag; /* the vtag that can not be reused */
  128. uint16_t lport; /* the local port used in vtag */
  129. uint16_t rport; /* the remote port used in vtag */
  130. };
  131. struct sctp_tagblock {
  132. LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock;
  133. struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
  134. };
  135. struct sctp_epinfo {
  136. #if defined(__FreeBSD__) && !defined(__Userspace__)
  137. #ifdef INET
  138. struct socket *udp4_tun_socket;
  139. #endif
  140. #ifdef INET6
  141. struct socket *udp6_tun_socket;
  142. #endif
  143. #endif
  144. struct sctpasochead *sctp_asochash;
  145. u_long hashasocmark;
  146. struct sctppcbhead *sctp_ephash;
  147. u_long hashmark;
  148. /*-
  149. * The TCP model represents a substantial overhead in that we get an
  150. * additional hash table to keep explicit connections in. The
  151. * listening TCP endpoint will exist in the usual ephash above and
  152. * accept only INIT's. It will be incapable of sending off an INIT.
  153. * When a dg arrives we must look in the normal ephash. If we find a
  154. * TCP endpoint that will tell us to go to the specific endpoint
  155. * hash and re-hash to find the right assoc/socket. If we find a UDP
  156. * model socket we then must complete the lookup. If this fails,
  157. * i.e. no association can be found then we must continue to see if
  158. * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket
  159. * acts like a TCP model connected socket).
  160. */
  161. struct sctppcbhead *sctp_tcpephash;
  162. u_long hashtcpmark;
  163. uint32_t hashtblsize;
  164. struct sctp_vrflist *sctp_vrfhash;
  165. u_long hashvrfmark;
  166. struct sctp_ifnlist *vrf_ifn_hash;
  167. u_long vrf_ifn_hashmark;
  168. struct sctppcbhead listhead;
  169. struct sctpladdr addr_wq;
  170. #if defined(__APPLE__) && !defined(__Userspace__)
  171. struct inpcbhead inplisthead;
  172. struct inpcbinfo sctbinfo;
  173. #endif
  174. /* ep zone info */
  175. sctp_zone_t ipi_zone_ep;
  176. sctp_zone_t ipi_zone_asoc;
  177. sctp_zone_t ipi_zone_laddr;
  178. sctp_zone_t ipi_zone_net;
  179. sctp_zone_t ipi_zone_chunk;
  180. sctp_zone_t ipi_zone_readq;
  181. sctp_zone_t ipi_zone_strmoq;
  182. sctp_zone_t ipi_zone_asconf;
  183. sctp_zone_t ipi_zone_asconf_ack;
  184. #if defined(__FreeBSD__) && !defined(__Userspace__)
  185. struct rwlock ipi_ep_mtx;
  186. struct mtx ipi_iterator_wq_mtx;
  187. struct rwlock ipi_addr_mtx;
  188. struct mtx ipi_pktlog_mtx;
  189. struct mtx wq_addr_mtx;
  190. #elif defined(SCTP_PROCESS_LEVEL_LOCKS)
  191. userland_rwlock_t ipi_ep_mtx;
  192. userland_rwlock_t ipi_addr_mtx;
  193. userland_mutex_t ipi_count_mtx;
  194. userland_mutex_t ipi_pktlog_mtx;
  195. userland_mutex_t wq_addr_mtx;
  196. #elif defined(__APPLE__) && !defined(__Userspace__)
  197. #ifdef _KERN_LOCKS_H_
  198. lck_mtx_t *ipi_addr_mtx;
  199. lck_mtx_t *ipi_count_mtx;
  200. lck_mtx_t *ipi_pktlog_mtx;
  201. lck_mtx_t *logging_mtx;
  202. lck_mtx_t *wq_addr_mtx;
  203. #else
  204. void *ipi_count_mtx;
  205. void *logging_mtx;
  206. #endif /* _KERN_LOCKS_H_ */
  207. #elif defined(_WIN32) && !defined(__Userspace__)
  208. struct rwlock ipi_ep_lock;
  209. struct rwlock ipi_addr_lock;
  210. struct spinlock ipi_pktlog_mtx;
  211. struct rwlock wq_addr_mtx;
  212. #elif defined(__Userspace__)
  213. #endif
  214. uint32_t ipi_count_ep;
  215. /* assoc/tcb zone info */
  216. uint32_t ipi_count_asoc;
  217. /* local addrlist zone info */
  218. uint32_t ipi_count_laddr;
  219. /* remote addrlist zone info */
  220. uint32_t ipi_count_raddr;
  221. /* chunk structure list for output */
  222. uint32_t ipi_count_chunk;
  223. /* socket queue zone info */
  224. uint32_t ipi_count_readq;
  225. /* socket queue zone info */
  226. uint32_t ipi_count_strmoq;
  227. /* Number of vrfs */
  228. uint32_t ipi_count_vrfs;
  229. /* Number of ifns */
  230. uint32_t ipi_count_ifns;
  231. /* Number of ifas */
  232. uint32_t ipi_count_ifas;
  233. /* system wide number of free chunks hanging around */
  234. uint32_t ipi_free_chunks;
  235. uint32_t ipi_free_strmoq;
  236. struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
  237. /* address work queue handling */
  238. struct sctp_timer addr_wq_timer;
  239. #if defined(_SCTP_NEEDS_CALLOUT_) || defined(_USER_SCTP_NEEDS_CALLOUT_)
  240. struct calloutlist callqueue;
  241. #endif
  242. };
  243. struct sctp_base_info {
  244. /* All static structures that
  245. * anchor the system must be here.
  246. */
  247. struct sctp_epinfo sctppcbinfo;
  248. #if defined(__FreeBSD__) && !defined(__Userspace__)
  249. #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
  250. struct sctpstat *sctpstat;
  251. #else
  252. struct sctpstat sctpstat;
  253. #endif
  254. #else
  255. struct sctpstat sctpstat;
  256. #endif
  257. struct sctp_sysctl sctpsysctl;
  258. uint8_t first_time;
  259. char sctp_pcb_initialized;
  260. #if defined(SCTP_PACKET_LOGGING)
  261. int packet_log_writers;
  262. int packet_log_end;
  263. uint8_t packet_log_buffer[SCTP_PACKET_LOG_SIZE];
  264. #endif
  265. #if defined(__FreeBSD__) && !defined(__Userspace__)
  266. eventhandler_tag eh_tag;
  267. #endif
  268. #if defined(__APPLE__) && !defined(__Userspace__)
  269. int sctp_main_timer_ticks;
  270. #endif
  271. #if defined(__Userspace__)
  272. userland_mutex_t timer_mtx;
  273. userland_thread_t timer_thread;
  274. int timer_thread_should_exit;
  275. int iterator_thread_started;
  276. int timer_thread_started;
  277. #if !defined(_WIN32)
  278. pthread_mutexattr_t mtx_attr;
  279. pthread_rwlockattr_t rwlock_attr;
  280. #if defined(INET) || defined(INET6)
  281. int userspace_route;
  282. userland_thread_t recvthreadroute;
  283. #endif
  284. #endif
  285. #ifdef INET
  286. #if defined(_WIN32) && !defined(__MINGW32__)
  287. SOCKET userspace_rawsctp;
  288. SOCKET userspace_udpsctp;
  289. #else
  290. int userspace_rawsctp;
  291. int userspace_udpsctp;
  292. #endif
  293. userland_thread_t recvthreadraw;
  294. userland_thread_t recvthreadudp;
  295. #endif
  296. #ifdef INET6
  297. #if defined(_WIN32) && !defined(__MINGW32__)
  298. SOCKET userspace_rawsctp6;
  299. SOCKET userspace_udpsctp6;
  300. #else
  301. int userspace_rawsctp6;
  302. int userspace_udpsctp6;
  303. #endif
  304. userland_thread_t recvthreadraw6;
  305. userland_thread_t recvthreadudp6;
  306. #endif
  307. int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df);
  308. void (*debug_printf)(const char *format, ...);
  309. int crc32c_offloaded;
  310. #endif
  311. };
  312. /*-
  313. * Here we have all the relevant information for each SCTP entity created. We
  314. * will need to modify this as approprate. We also need to figure out how to
  315. * access /dev/random.
  316. */
  317. struct sctp_pcb {
  318. unsigned int time_of_secret_change; /* number of seconds from
  319. * timeval.tv_sec */
  320. uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
  321. unsigned int size_of_a_cookie;
  322. uint32_t sctp_timeoutticks[SCTP_NUM_TMRS];
  323. uint32_t sctp_minrto;
  324. uint32_t sctp_maxrto;
  325. uint32_t initial_rto;
  326. uint32_t initial_init_rto_max;
  327. unsigned int sctp_sack_freq;
  328. uint32_t sctp_sws_sender;
  329. uint32_t sctp_sws_receiver;
  330. uint32_t sctp_default_cc_module;
  331. uint32_t sctp_default_ss_module;
  332. /* authentication related fields */
  333. struct sctp_keyhead shared_keys;
  334. sctp_auth_chklist_t *local_auth_chunks;
  335. sctp_hmaclist_t *local_hmacs;
  336. uint16_t default_keyid;
  337. uint32_t default_mtu;
  338. /* various thresholds */
  339. /* Max times I will init at a guy */
  340. uint16_t max_init_times;
  341. /* Max times I will send before we consider someone dead */
  342. uint16_t max_send_times;
  343. uint16_t def_net_failure;
  344. uint16_t def_net_pf_threshold;
  345. /* number of streams to pre-open on a association */
  346. uint16_t pre_open_stream_count;
  347. uint16_t max_open_streams_intome;
  348. /* random number generator */
  349. uint32_t random_counter;
  350. uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
  351. uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
  352. /*
  353. * This timer is kept running per endpoint. When it fires it will
  354. * change the secret key. The default is once a hour
  355. */
  356. struct sctp_timer signature_change;
  357. uint32_t def_cookie_life;
  358. /* defaults to 0 */
  359. uint32_t auto_close_time;
  360. uint32_t initial_sequence_debug;
  361. uint32_t adaptation_layer_indicator;
  362. uint8_t adaptation_layer_indicator_provided;
  363. uint32_t store_at;
  364. uint32_t max_burst;
  365. uint32_t fr_max_burst;
  366. #ifdef INET6
  367. uint32_t default_flowlabel;
  368. #endif
  369. uint8_t default_dscp;
  370. char current_secret_number;
  371. char last_secret_number;
  372. uint16_t port; /* remote UDP encapsulation port */
  373. };
  374. #ifndef SCTP_ALIGNMENT
  375. #define SCTP_ALIGNMENT 32
  376. #endif
  377. #ifndef SCTP_ALIGNM1
  378. #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
  379. #endif
  380. #define sctp_lport ip_inp.inp.inp_lport
  381. struct sctp_pcbtsn_rlog {
  382. uint32_t vtag;
  383. uint16_t strm;
  384. uint16_t seq;
  385. uint16_t sz;
  386. uint16_t flgs;
  387. };
  388. #define SCTP_READ_LOG_SIZE 135 /* we choose the number to make a pcb a page */
  389. struct sctp_inpcb {
  390. /*-
  391. * put an inpcb in front of it all, kind of a waste but we need to
  392. * for compatibility with all the other stuff.
  393. */
  394. union {
  395. struct inpcb inp;
  396. char align[(sizeof(struct inpcb) + SCTP_ALIGNM1) &
  397. ~SCTP_ALIGNM1];
  398. } ip_inp;
  399. #if defined(__APPLE__) && !defined(__Userspace__)
  400. /* leave some space in case i386 inpcb is bigger than ppc */
  401. uint8_t padding[128];
  402. #endif
  403. /* Socket buffer lock protects read_queue and of course sb_cc */
  404. struct sctp_readhead read_queue;
  405. LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */
  406. /* hash of all endpoints for model */
  407. LIST_ENTRY(sctp_inpcb) sctp_hash;
  408. /* count of local addresses bound, 0 if bound all */
  409. int laddr_count;
  410. /* list of addrs in use by the EP, NULL if bound-all */
  411. struct sctpladdr sctp_addr_list;
  412. /* used for source address selection rotation when we are subset bound */
  413. struct sctp_laddr *next_addr_touse;
  414. /* back pointer to our socket */
  415. struct socket *sctp_socket;
  416. uint64_t sctp_features; /* Feature flags */
  417. uint32_t sctp_flags; /* INP state flag set */
  418. uint32_t sctp_mobility_features; /* Mobility Feature flags */
  419. struct sctp_pcb sctp_ep;/* SCTP ep data */
  420. /* head of the hash of all associations */
  421. struct sctpasochead *sctp_tcbhash;
  422. u_long sctp_hashmark;
  423. /* head of the list of all associations */
  424. struct sctpasochead sctp_asoc_list;
  425. #ifdef SCTP_TRACK_FREED_ASOCS
  426. struct sctpasochead sctp_asoc_free_list;
  427. #endif
  428. uint32_t sctp_frag_point;
  429. uint32_t partial_delivery_point;
  430. uint32_t sctp_context;
  431. uint32_t max_cwnd;
  432. uint8_t local_strreset_support;
  433. uint32_t sctp_cmt_on_off;
  434. uint8_t ecn_supported;
  435. uint8_t prsctp_supported;
  436. uint8_t auth_supported;
  437. uint8_t idata_supported;
  438. uint8_t asconf_supported;
  439. uint8_t reconfig_supported;
  440. uint8_t nrsack_supported;
  441. uint8_t pktdrop_supported;
  442. struct sctp_nonpad_sndrcvinfo def_send;
  443. /*-
  444. * These three are here for the sosend_dgram
  445. * (pkt, pkt_last and control).
  446. * routine. However, I don't think anyone in
  447. * the current FreeBSD kernel calls this. So
  448. * they are candidates with sctp_sendm for
  449. * de-supporting.
  450. */
  451. struct mbuf *pkt, *pkt_last;
  452. struct mbuf *control;
  453. #if defined(__FreeBSD__) && !defined(__Userspace__)
  454. struct mtx inp_mtx;
  455. struct mtx inp_create_mtx;
  456. struct mtx inp_rdata_mtx;
  457. int32_t refcount;
  458. #elif defined(SCTP_PROCESS_LEVEL_LOCKS)
  459. userland_mutex_t inp_mtx;
  460. userland_mutex_t inp_create_mtx;
  461. userland_mutex_t inp_rdata_mtx;
  462. int32_t refcount;
  463. #elif defined(__APPLE__) && !defined(__Userspace__)
  464. #if defined(SCTP_APPLE_RWLOCK)
  465. lck_rw_t *inp_mtx;
  466. #else
  467. lck_mtx_t *inp_mtx;
  468. #endif
  469. lck_mtx_t *inp_create_mtx;
  470. lck_mtx_t *inp_rdata_mtx;
  471. #elif defined(_WIN32) && !defined(__Userspace__)
  472. struct rwlock inp_lock;
  473. struct spinlock inp_create_lock;
  474. struct spinlock inp_rdata_lock;
  475. int32_t refcount;
  476. #elif defined(__Userspace__)
  477. int32_t refcount;
  478. #endif
  479. #if defined(__APPLE__) && !defined(__Userspace__)
  480. int32_t refcount;
  481. uint32_t lock_caller1;
  482. uint32_t lock_caller2;
  483. uint32_t lock_caller3;
  484. uint32_t unlock_caller1;
  485. uint32_t unlock_caller2;
  486. uint32_t unlock_caller3;
  487. uint32_t getlock_caller1;
  488. uint32_t getlock_caller2;
  489. uint32_t getlock_caller3;
  490. uint32_t gen_count;
  491. uint32_t lock_gen_count;
  492. uint32_t unlock_gen_count;
  493. uint32_t getlock_gen_count;
  494. uint32_t i_am_here_file;
  495. uint32_t i_am_here_line;
  496. #endif
  497. uint32_t def_vrf_id;
  498. uint16_t fibnum;
  499. #ifdef SCTP_MVRF
  500. uint32_t *m_vrf_ids;
  501. uint32_t num_vrfs;
  502. uint32_t vrf_size;
  503. #endif
  504. uint32_t total_sends;
  505. uint32_t total_recvs;
  506. uint32_t last_abort_code;
  507. uint32_t total_nospaces;
  508. struct sctpasochead *sctp_asocidhash;
  509. u_long hashasocidmark;
  510. uint32_t sctp_associd_counter;
  511. #ifdef SCTP_ASOCLOG_OF_TSNS
  512. struct sctp_pcbtsn_rlog readlog[SCTP_READ_LOG_SIZE];
  513. uint32_t readlog_index;
  514. #endif
  515. #if defined(__Userspace__)
  516. void *ulp_info;
  517. int (*recv_callback)(struct socket *, union sctp_sockstore, void *, size_t,
  518. struct sctp_rcvinfo, int, void *);
  519. uint32_t send_sb_threshold;
  520. int (*send_callback)(struct socket *, uint32_t, void *);
  521. #endif
  522. };
  523. #if defined(__Userspace__)
  524. int register_recv_cb (struct socket *,
  525. int (*)(struct socket *, union sctp_sockstore, void *, size_t,
  526. struct sctp_rcvinfo, int, void *));
  527. int register_send_cb (struct socket *, uint32_t, int (*)(struct socket *, uint32_t, void *));
  528. int register_ulp_info (struct socket *, void *);
  529. int retrieve_ulp_info (struct socket *, void **);
  530. #endif
  531. struct sctp_tcb {
  532. struct socket *sctp_socket; /* back pointer to socket */
  533. struct sctp_inpcb *sctp_ep; /* back pointer to ep */
  534. LIST_ENTRY(sctp_tcb) sctp_tcbhash; /* next link in hash
  535. * table */
  536. LIST_ENTRY(sctp_tcb) sctp_tcblist; /* list of all of the
  537. * TCB's */
  538. LIST_ENTRY(sctp_tcb) sctp_tcbasocidhash; /* next link in asocid
  539. * hash table
  540. */
  541. LIST_ENTRY(sctp_tcb) sctp_asocs; /* vtag hash list */
  542. struct sctp_block_entry *block_entry; /* pointer locked by socket
  543. * send buffer */
  544. struct sctp_association asoc;
  545. /*-
  546. * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the
  547. * tcb_lock. Its special in this way to help avoid extra mutex calls
  548. * in the reading of data.
  549. */
  550. uint32_t freed_by_sorcv_sincelast;
  551. uint32_t total_sends;
  552. uint32_t total_recvs;
  553. int freed_from_where;
  554. uint16_t rport; /* remote port in network format */
  555. uint16_t resv;
  556. #if defined(__FreeBSD__) && !defined(__Userspace__)
  557. struct mtx tcb_mtx;
  558. #elif defined(SCTP_PROCESS_LEVEL_LOCKS)
  559. userland_mutex_t tcb_mtx;
  560. #elif defined(__APPLE__) && !defined(__Userspace__)
  561. lck_mtx_t* tcb_mtx;
  562. #elif defined(_WIN32) && !defined(__Userspace__)
  563. struct spinlock tcb_lock;
  564. #elif defined(__Userspace__)
  565. #endif
  566. #if defined(__APPLE__) && !defined(__Userspace__)
  567. uint32_t caller1;
  568. uint32_t caller2;
  569. uint32_t caller3;
  570. #endif
  571. };
  572. #if defined(__FreeBSD__) && !defined(__Userspace__)
  573. #include <netinet/sctp_lock_bsd.h>
  574. #elif defined(__APPLE__) && !defined(__Userspace__)
  575. /*
  576. * Apple MacOS X 10.4 "Tiger"
  577. */
  578. #include <netinet/sctp_lock_apple_fg.h>
  579. #elif defined(SCTP_PROCESS_LEVEL_LOCKS)
  580. #include <netinet/sctp_process_lock.h>
  581. #elif defined(_WIN32) && !defined(__Userspace__)
  582. #include <netinet/sctp_lock_windows.h>
  583. #elif defined(__Userspace__)
  584. #include <netinet/sctp_lock_userspace.h>
  585. #else
  586. /*
  587. * Pre-5.x FreeBSD, and others.
  588. */
  589. #include <netinet/sctp_lock_empty.h>
  590. #endif
  591. #if defined(_KERNEL) || defined(__Userspace__)
  592. /* Attention Julian, this is the extern that
  593. * goes with the base info. sctp_pcb.c has
  594. * the real definition.
  595. */
  596. #if defined(__FreeBSD__) && !defined(__Userspace__)
  597. VNET_DECLARE(struct sctp_base_info, system_base_info);
  598. #else
  599. extern struct sctp_base_info system_base_info;
  600. #endif
  601. #ifdef INET6
  602. int SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b);
  603. #endif
  604. void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
  605. struct sctp_ifn *
  606. sctp_find_ifn(void *ifn, uint32_t ifn_index);
  607. struct sctp_vrf *sctp_allocate_vrf(int vrfid);
  608. struct sctp_vrf *sctp_find_vrf(uint32_t vrfid);
  609. void sctp_free_vrf(struct sctp_vrf *vrf);
  610. /*-
  611. * Change address state, can be used if
  612. * O/S supports telling transports about
  613. * changes to IFA/IFN's (link layer triggers).
  614. * If a ifn goes down, we will do src-addr-selection
  615. * and NOT use that, as a source address. This does
  616. * not stop the routing system from routing out
  617. * that interface, but we won't put it as a source.
  618. */
  619. void sctp_mark_ifa_addr_down(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index);
  620. void sctp_mark_ifa_addr_up(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index);
  621. struct sctp_ifa *
  622. sctp_add_addr_to_vrf(uint32_t vrfid,
  623. void *ifn, uint32_t ifn_index, uint32_t ifn_type,
  624. const char *if_name,
  625. void *ifa, struct sockaddr *addr, uint32_t ifa_flags,
  626. int dynamic_add);
  627. void sctp_update_ifn_mtu(uint32_t ifn_index, uint32_t mtu);
  628. void sctp_free_ifn(struct sctp_ifn *sctp_ifnp);
  629. void sctp_free_ifa(struct sctp_ifa *sctp_ifap);
  630. void sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr,
  631. uint32_t ifn_index, const char *if_name);
  632. struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
  633. struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t);
  634. #if defined(__FreeBSD__) && !defined(__Userspace__)
  635. int
  636. sctp_inpcb_bind(struct socket *, struct sockaddr *,
  637. struct sctp_ifa *, struct thread *);
  638. int
  639. sctp_inpcb_bind_locked(struct sctp_inpcb *, struct sockaddr *,
  640. struct sctp_ifa *, struct thread *);
  641. #elif defined(_WIN32) && !defined(__Userspace__)
  642. int
  643. sctp_inpcb_bind(struct socket *, struct sockaddr *,
  644. struct sctp_ifa *, PKTHREAD);
  645. int
  646. sctp_inpcb_bind_locked(struct sctp_inpcb *, struct sockaddr *,
  647. struct sctp_ifa *, PKTHREAD);
  648. #else
  649. /* struct proc is a dummy for __Userspace__ */
  650. int
  651. sctp_inpcb_bind(struct socket *, struct sockaddr *,
  652. struct sctp_ifa *, struct proc *);
  653. int
  654. sctp_inpcb_bind_locked(struct sctp_inpcb *, struct sockaddr *,
  655. struct sctp_ifa *, struct proc *);
  656. #endif
  657. struct sctp_tcb *
  658. sctp_findassociation_addr(struct mbuf *, int,
  659. struct sockaddr *, struct sockaddr *,
  660. struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
  661. struct sctp_nets **, uint32_t vrf_id);
  662. struct sctp_tcb *
  663. sctp_findassociation_addr_sa(struct sockaddr *,
  664. struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int, uint32_t);
  665. void
  666. sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
  667. struct sctp_tcb *);
  668. /*-
  669. * For this call ep_addr, the to is the destination endpoint address of the
  670. * peer (relative to outbound). The from field is only used if the TCP model
  671. * is enabled and helps distingush amongst the subset bound (non-boundall).
  672. * The TCP model MAY change the actual ep field, this is why it is passed.
  673. */
  674. struct sctp_tcb *
  675. sctp_findassociation_ep_addr(struct sctp_inpcb **,
  676. struct sockaddr *, struct sctp_nets **, struct sockaddr *,
  677. struct sctp_tcb *);
  678. struct sctp_tcb *
  679. sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock);
  680. struct sctp_tcb *
  681. sctp_findassociation_ep_asocid(struct sctp_inpcb *,
  682. sctp_assoc_t, int);
  683. struct sctp_tcb *
  684. sctp_findassociation_ep_asconf(struct mbuf *, int, struct sockaddr *,
  685. struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **, uint32_t vrf_id);
  686. int sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id);
  687. int sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id);
  688. void sctp_inpcb_free(struct sctp_inpcb *, int, int);
  689. #define SCTP_DONT_INITIALIZE_AUTH_PARAMS 0
  690. #define SCTP_INITIALIZE_AUTH_PARAMS 1
  691. #if defined(__FreeBSD__) && !defined(__Userspace__)
  692. struct sctp_tcb *
  693. sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
  694. int *, uint32_t, uint32_t, uint32_t, uint16_t, uint16_t,
  695. struct thread *, int);
  696. struct sctp_tcb *
  697. sctp_aloc_assoc_connected(struct sctp_inpcb *, struct sockaddr *,
  698. int *, uint32_t, uint32_t, uint32_t, uint16_t, uint16_t,
  699. struct thread *, int);
  700. #elif defined(_WIN32) && !defined(__Userspace__)
  701. struct sctp_tcb *
  702. sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, int *, uint32_t,
  703. uint32_t, uint32_t, uint16_t, uint16_t, PKTHREAD, int);
  704. struct sctp_tcb *
  705. sctp_aloc_assoc_connected(struct sctp_inpcb *, struct sockaddr *, int *, uint32_t,
  706. uint32_t, uint32_t, uint16_t, uint16_t, PKTHREAD, int);
  707. #else
  708. /* proc will be NULL for __Userspace__ */
  709. struct sctp_tcb *
  710. sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, int *, uint32_t,
  711. uint32_t, uint32_t, uint16_t, uint16_t, struct proc *, int);
  712. struct sctp_tcb *
  713. sctp_aloc_assoc_connected(struct sctp_inpcb *, struct sockaddr *, int *, uint32_t,
  714. uint32_t, uint32_t, uint16_t, uint16_t, struct proc *, int);
  715. #endif
  716. int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
  717. void sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t);
  718. void sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *);
  719. int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, struct sctp_nets **, uint16_t, int, int);
  720. void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
  721. int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
  722. #if defined(__Userspace__)
  723. void sctp_pcb_init(int);
  724. #else
  725. void sctp_pcb_init(void);
  726. #endif
  727. void sctp_pcb_finish(void);
  728. void sctp_add_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
  729. void sctp_del_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
  730. int
  731. sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
  732. struct sockaddr *, struct sockaddr *, struct sockaddr *, uint16_t);
  733. int
  734. sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
  735. struct sctp_nets *);
  736. bool
  737. sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *);
  738. /* void sctp_drain(void); */
  739. int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *);
  740. int sctp_swap_inpcb_for_listen(struct sctp_inpcb *inp);
  741. void sctp_clean_up_stream(struct sctp_tcb *stcb, struct sctp_readhead *rh);
  742. void
  743. sctp_pcb_add_flags(struct sctp_inpcb *, uint32_t);
  744. /*-
  745. * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg
  746. * indicates run on ONLY assoc's of the specified endpoint.
  747. */
  748. int
  749. sctp_initiate_iterator(inp_func inpf,
  750. asoc_func af,
  751. inp_func inpe,
  752. uint32_t, uint32_t,
  753. uint32_t, void *,
  754. uint32_t,
  755. end_func ef,
  756. struct sctp_inpcb *,
  757. uint8_t co_off);
  758. #if defined(__FreeBSD__) && !defined(__Userspace__)
  759. #if defined(SCTP_MCORE_INPUT) && defined(SMP)
  760. void
  761. sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use);
  762. #endif
  763. #endif
  764. #endif /* _KERNEL */
  765. #endif /* !__sctp_pcb_h__ */