protocol.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /* SCTP kernel reference 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. * Copyright (c) 2001 Nokia, Inc.
  7. * Copyright (c) 2001 La Monte H.P. Yarroll
  8. *
  9. * This file is part of the SCTP kernel reference Implementation
  10. *
  11. * Initialization/cleanup for SCTP protocol support.
  12. *
  13. * The SCTP reference implementation is free software;
  14. * you can redistribute it and/or modify it under the terms of
  15. * the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2, or (at your option)
  17. * any later version.
  18. *
  19. * The SCTP reference implementation is distributed in the hope that it
  20. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  21. * ************************
  22. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  23. * See the GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with GNU CC; see the file COPYING. If not, write to
  27. * the Free Software Foundation, 59 Temple Place - Suite 330,
  28. * Boston, MA 02111-1307, USA.
  29. *
  30. * Please send any bug reports or fixes you make to the
  31. * email address(es):
  32. * lksctp developers <lksctp-developers@lists.sourceforge.net>
  33. *
  34. * Or submit a bug report through the following website:
  35. * http://www.sf.net/projects/lksctp
  36. *
  37. * Written or modified by:
  38. * La Monte H.P. Yarroll <piggy@acm.org>
  39. * Karl Knutson <karl@athena.chicago.il.us>
  40. * Jon Grimm <jgrimm@us.ibm.com>
  41. * Sridhar Samudrala <sri@us.ibm.com>
  42. * Daisy Chang <daisyc@us.ibm.com>
  43. * Ardelle Fan <ardelle.fan@intel.com>
  44. *
  45. * Any bugs reported given to us we will try to fix... any fixes shared will
  46. * be incorporated into the next SCTP release.
  47. */
  48. #include <linux/module.h>
  49. #include <linux/init.h>
  50. #include <linux/netdevice.h>
  51. #include <linux/inetdevice.h>
  52. #include <linux/seq_file.h>
  53. #include <net/protocol.h>
  54. #include <net/ip.h>
  55. #include <net/ipv6.h>
  56. #include <net/sctp/sctp.h>
  57. #include <net/addrconf.h>
  58. #include <net/inet_common.h>
  59. #include <net/inet_ecn.h>
  60. /* Global data structures. */
  61. struct sctp_globals sctp_globals;
  62. struct proc_dir_entry *proc_net_sctp;
  63. DEFINE_SNMP_STAT(struct sctp_mib, sctp_statistics) __read_mostly;
  64. struct idr sctp_assocs_id;
  65. DEFINE_SPINLOCK(sctp_assocs_id_lock);
  66. /* This is the global socket data structure used for responding to
  67. * the Out-of-the-blue (OOTB) packets. A control sock will be created
  68. * for this socket at the initialization time.
  69. */
  70. static struct socket *sctp_ctl_socket;
  71. static struct sctp_pf *sctp_pf_inet6_specific;
  72. static struct sctp_pf *sctp_pf_inet_specific;
  73. static struct sctp_af *sctp_af_v4_specific;
  74. static struct sctp_af *sctp_af_v6_specific;
  75. kmem_cache_t *sctp_chunk_cachep __read_mostly;
  76. kmem_cache_t *sctp_bucket_cachep __read_mostly;
  77. extern int sctp_snmp_proc_init(void);
  78. extern int sctp_snmp_proc_exit(void);
  79. extern int sctp_eps_proc_init(void);
  80. extern int sctp_eps_proc_exit(void);
  81. extern int sctp_assocs_proc_init(void);
  82. extern int sctp_assocs_proc_exit(void);
  83. /* Return the address of the control sock. */
  84. struct sock *sctp_get_ctl_sock(void)
  85. {
  86. return sctp_ctl_socket->sk;
  87. }
  88. /* Set up the proc fs entry for the SCTP protocol. */
  89. static __init int sctp_proc_init(void)
  90. {
  91. if (!proc_net_sctp) {
  92. struct proc_dir_entry *ent;
  93. ent = proc_mkdir("net/sctp", NULL);
  94. if (ent) {
  95. ent->owner = THIS_MODULE;
  96. proc_net_sctp = ent;
  97. } else
  98. goto out_nomem;
  99. }
  100. if (sctp_snmp_proc_init())
  101. goto out_nomem;
  102. if (sctp_eps_proc_init())
  103. goto out_nomem;
  104. if (sctp_assocs_proc_init())
  105. goto out_nomem;
  106. return 0;
  107. out_nomem:
  108. return -ENOMEM;
  109. }
  110. /* Clean up the proc fs entry for the SCTP protocol.
  111. * Note: Do not make this __exit as it is used in the init error
  112. * path.
  113. */
  114. static void sctp_proc_exit(void)
  115. {
  116. sctp_snmp_proc_exit();
  117. sctp_eps_proc_exit();
  118. sctp_assocs_proc_exit();
  119. if (proc_net_sctp) {
  120. proc_net_sctp = NULL;
  121. remove_proc_entry("net/sctp", NULL);
  122. }
  123. }
  124. /* Private helper to extract ipv4 address and stash them in
  125. * the protocol structure.
  126. */
  127. static void sctp_v4_copy_addrlist(struct list_head *addrlist,
  128. struct net_device *dev)
  129. {
  130. struct in_device *in_dev;
  131. struct in_ifaddr *ifa;
  132. struct sctp_sockaddr_entry *addr;
  133. rcu_read_lock();
  134. if ((in_dev = __in_dev_get_rcu(dev)) == NULL) {
  135. rcu_read_unlock();
  136. return;
  137. }
  138. for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
  139. /* Add the address to the local list. */
  140. addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC);
  141. if (addr) {
  142. addr->a.v4.sin_family = AF_INET;
  143. addr->a.v4.sin_port = 0;
  144. addr->a.v4.sin_addr.s_addr = ifa->ifa_local;
  145. list_add_tail(&addr->list, addrlist);
  146. }
  147. }
  148. rcu_read_unlock();
  149. }
  150. /* Extract our IP addresses from the system and stash them in the
  151. * protocol structure.
  152. */
  153. static void __sctp_get_local_addr_list(void)
  154. {
  155. struct net_device *dev;
  156. struct list_head *pos;
  157. struct sctp_af *af;
  158. read_lock(&dev_base_lock);
  159. for (dev = dev_base; dev; dev = dev->next) {
  160. __list_for_each(pos, &sctp_address_families) {
  161. af = list_entry(pos, struct sctp_af, list);
  162. af->copy_addrlist(&sctp_local_addr_list, dev);
  163. }
  164. }
  165. read_unlock(&dev_base_lock);
  166. }
  167. static void sctp_get_local_addr_list(void)
  168. {
  169. unsigned long flags;
  170. sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);
  171. __sctp_get_local_addr_list();
  172. sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);
  173. }
  174. /* Free the existing local addresses. */
  175. static void __sctp_free_local_addr_list(void)
  176. {
  177. struct sctp_sockaddr_entry *addr;
  178. struct list_head *pos, *temp;
  179. list_for_each_safe(pos, temp, &sctp_local_addr_list) {
  180. addr = list_entry(pos, struct sctp_sockaddr_entry, list);
  181. list_del(pos);
  182. kfree(addr);
  183. }
  184. }
  185. /* Free the existing local addresses. */
  186. static void sctp_free_local_addr_list(void)
  187. {
  188. unsigned long flags;
  189. sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);
  190. __sctp_free_local_addr_list();
  191. sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);
  192. }
  193. /* Copy the local addresses which are valid for 'scope' into 'bp'. */
  194. int sctp_copy_local_addr_list(struct sctp_bind_addr *bp, sctp_scope_t scope,
  195. gfp_t gfp, int copy_flags)
  196. {
  197. struct sctp_sockaddr_entry *addr;
  198. int error = 0;
  199. struct list_head *pos;
  200. unsigned long flags;
  201. sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);
  202. list_for_each(pos, &sctp_local_addr_list) {
  203. addr = list_entry(pos, struct sctp_sockaddr_entry, list);
  204. if (sctp_in_scope(&addr->a, scope)) {
  205. /* Now that the address is in scope, check to see if
  206. * the address type is really supported by the local
  207. * sock as well as the remote peer.
  208. */
  209. if ((((AF_INET == addr->a.sa.sa_family) &&
  210. (copy_flags & SCTP_ADDR4_PEERSUPP))) ||
  211. (((AF_INET6 == addr->a.sa.sa_family) &&
  212. (copy_flags & SCTP_ADDR6_ALLOWED) &&
  213. (copy_flags & SCTP_ADDR6_PEERSUPP)))) {
  214. error = sctp_add_bind_addr(bp, &addr->a,
  215. GFP_ATOMIC);
  216. if (error)
  217. goto end_copy;
  218. }
  219. }
  220. }
  221. end_copy:
  222. sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);
  223. return error;
  224. }
  225. /* Initialize a sctp_addr from in incoming skb. */
  226. static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb,
  227. int is_saddr)
  228. {
  229. void *from;
  230. __u16 *port;
  231. struct sctphdr *sh;
  232. port = &addr->v4.sin_port;
  233. addr->v4.sin_family = AF_INET;
  234. sh = (struct sctphdr *) skb->h.raw;
  235. if (is_saddr) {
  236. *port = ntohs(sh->source);
  237. from = &skb->nh.iph->saddr;
  238. } else {
  239. *port = ntohs(sh->dest);
  240. from = &skb->nh.iph->daddr;
  241. }
  242. memcpy(&addr->v4.sin_addr.s_addr, from, sizeof(struct in_addr));
  243. }
  244. /* Initialize an sctp_addr from a socket. */
  245. static void sctp_v4_from_sk(union sctp_addr *addr, struct sock *sk)
  246. {
  247. addr->v4.sin_family = AF_INET;
  248. addr->v4.sin_port = inet_sk(sk)->num;
  249. addr->v4.sin_addr.s_addr = inet_sk(sk)->rcv_saddr;
  250. }
  251. /* Initialize sk->sk_rcv_saddr from sctp_addr. */
  252. static void sctp_v4_to_sk_saddr(union sctp_addr *addr, struct sock *sk)
  253. {
  254. inet_sk(sk)->rcv_saddr = addr->v4.sin_addr.s_addr;
  255. }
  256. /* Initialize sk->sk_daddr from sctp_addr. */
  257. static void sctp_v4_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
  258. {
  259. inet_sk(sk)->daddr = addr->v4.sin_addr.s_addr;
  260. }
  261. /* Initialize a sctp_addr from an address parameter. */
  262. static void sctp_v4_from_addr_param(union sctp_addr *addr,
  263. union sctp_addr_param *param,
  264. __u16 port, int iif)
  265. {
  266. addr->v4.sin_family = AF_INET;
  267. addr->v4.sin_port = port;
  268. addr->v4.sin_addr.s_addr = param->v4.addr.s_addr;
  269. }
  270. /* Initialize an address parameter from a sctp_addr and return the length
  271. * of the address parameter.
  272. */
  273. static int sctp_v4_to_addr_param(const union sctp_addr *addr,
  274. union sctp_addr_param *param)
  275. {
  276. int length = sizeof(sctp_ipv4addr_param_t);
  277. param->v4.param_hdr.type = SCTP_PARAM_IPV4_ADDRESS;
  278. param->v4.param_hdr.length = ntohs(length);
  279. param->v4.addr.s_addr = addr->v4.sin_addr.s_addr;
  280. return length;
  281. }
  282. /* Initialize a sctp_addr from a dst_entry. */
  283. static void sctp_v4_dst_saddr(union sctp_addr *saddr, struct dst_entry *dst,
  284. unsigned short port)
  285. {
  286. struct rtable *rt = (struct rtable *)dst;
  287. saddr->v4.sin_family = AF_INET;
  288. saddr->v4.sin_port = port;
  289. saddr->v4.sin_addr.s_addr = rt->rt_src;
  290. }
  291. /* Compare two addresses exactly. */
  292. static int sctp_v4_cmp_addr(const union sctp_addr *addr1,
  293. const union sctp_addr *addr2)
  294. {
  295. if (addr1->sa.sa_family != addr2->sa.sa_family)
  296. return 0;
  297. if (addr1->v4.sin_port != addr2->v4.sin_port)
  298. return 0;
  299. if (addr1->v4.sin_addr.s_addr != addr2->v4.sin_addr.s_addr)
  300. return 0;
  301. return 1;
  302. }
  303. /* Initialize addr struct to INADDR_ANY. */
  304. static void sctp_v4_inaddr_any(union sctp_addr *addr, unsigned short port)
  305. {
  306. addr->v4.sin_family = AF_INET;
  307. addr->v4.sin_addr.s_addr = INADDR_ANY;
  308. addr->v4.sin_port = port;
  309. }
  310. /* Is this a wildcard address? */
  311. static int sctp_v4_is_any(const union sctp_addr *addr)
  312. {
  313. return INADDR_ANY == addr->v4.sin_addr.s_addr;
  314. }
  315. /* This function checks if the address is a valid address to be used for
  316. * SCTP binding.
  317. *
  318. * Output:
  319. * Return 0 - If the address is a non-unicast or an illegal address.
  320. * Return 1 - If the address is a unicast.
  321. */
  322. static int sctp_v4_addr_valid(union sctp_addr *addr, struct sctp_sock *sp)
  323. {
  324. /* Is this a non-unicast address or a unusable SCTP address? */
  325. if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr))
  326. return 0;
  327. return 1;
  328. }
  329. /* Should this be available for binding? */
  330. static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp)
  331. {
  332. int ret = inet_addr_type(addr->v4.sin_addr.s_addr);
  333. if (addr->v4.sin_addr.s_addr != INADDR_ANY &&
  334. ret != RTN_LOCAL &&
  335. !sp->inet.freebind &&
  336. !sysctl_ip_nonlocal_bind)
  337. return 0;
  338. return 1;
  339. }
  340. /* Checking the loopback, private and other address scopes as defined in
  341. * RFC 1918. The IPv4 scoping is based on the draft for SCTP IPv4
  342. * scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
  343. *
  344. * Level 0 - unusable SCTP addresses
  345. * Level 1 - loopback address
  346. * Level 2 - link-local addresses
  347. * Level 3 - private addresses.
  348. * Level 4 - global addresses
  349. * For INIT and INIT-ACK address list, let L be the level of
  350. * of requested destination address, sender and receiver
  351. * SHOULD include all of its addresses with level greater
  352. * than or equal to L.
  353. */
  354. static sctp_scope_t sctp_v4_scope(union sctp_addr *addr)
  355. {
  356. sctp_scope_t retval;
  357. /* Should IPv4 scoping be a sysctl configurable option
  358. * so users can turn it off (default on) for certain
  359. * unconventional networking environments?
  360. */
  361. /* Check for unusable SCTP addresses. */
  362. if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  363. retval = SCTP_SCOPE_UNUSABLE;
  364. } else if (LOOPBACK(addr->v4.sin_addr.s_addr)) {
  365. retval = SCTP_SCOPE_LOOPBACK;
  366. } else if (IS_IPV4_LINK_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  367. retval = SCTP_SCOPE_LINK;
  368. } else if (IS_IPV4_PRIVATE_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  369. retval = SCTP_SCOPE_PRIVATE;
  370. } else {
  371. retval = SCTP_SCOPE_GLOBAL;
  372. }
  373. return retval;
  374. }
  375. /* Returns a valid dst cache entry for the given source and destination ip
  376. * addresses. If an association is passed, trys to get a dst entry with a
  377. * source address that matches an address in the bind address list.
  378. */
  379. static struct dst_entry *sctp_v4_get_dst(struct sctp_association *asoc,
  380. union sctp_addr *daddr,
  381. union sctp_addr *saddr)
  382. {
  383. struct rtable *rt;
  384. struct flowi fl;
  385. struct sctp_bind_addr *bp;
  386. rwlock_t *addr_lock;
  387. struct sctp_sockaddr_entry *laddr;
  388. struct list_head *pos;
  389. struct dst_entry *dst = NULL;
  390. union sctp_addr dst_saddr;
  391. memset(&fl, 0x0, sizeof(struct flowi));
  392. fl.fl4_dst = daddr->v4.sin_addr.s_addr;
  393. fl.proto = IPPROTO_SCTP;
  394. if (asoc) {
  395. fl.fl4_tos = RT_CONN_FLAGS(asoc->base.sk);
  396. fl.oif = asoc->base.sk->sk_bound_dev_if;
  397. }
  398. if (saddr)
  399. fl.fl4_src = saddr->v4.sin_addr.s_addr;
  400. SCTP_DEBUG_PRINTK("%s: DST:%u.%u.%u.%u, SRC:%u.%u.%u.%u - ",
  401. __FUNCTION__, NIPQUAD(fl.fl4_dst),
  402. NIPQUAD(fl.fl4_src));
  403. if (!ip_route_output_key(&rt, &fl)) {
  404. dst = &rt->u.dst;
  405. }
  406. /* If there is no association or if a source address is passed, no
  407. * more validation is required.
  408. */
  409. if (!asoc || saddr)
  410. goto out;
  411. bp = &asoc->base.bind_addr;
  412. addr_lock = &asoc->base.addr_lock;
  413. if (dst) {
  414. /* Walk through the bind address list and look for a bind
  415. * address that matches the source address of the returned dst.
  416. */
  417. sctp_read_lock(addr_lock);
  418. list_for_each(pos, &bp->address_list) {
  419. laddr = list_entry(pos, struct sctp_sockaddr_entry,
  420. list);
  421. sctp_v4_dst_saddr(&dst_saddr, dst, bp->port);
  422. if (sctp_v4_cmp_addr(&dst_saddr, &laddr->a))
  423. goto out_unlock;
  424. }
  425. sctp_read_unlock(addr_lock);
  426. /* None of the bound addresses match the source address of the
  427. * dst. So release it.
  428. */
  429. dst_release(dst);
  430. dst = NULL;
  431. }
  432. /* Walk through the bind address list and try to get a dst that
  433. * matches a bind address as the source address.
  434. */
  435. sctp_read_lock(addr_lock);
  436. list_for_each(pos, &bp->address_list) {
  437. laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
  438. if (AF_INET == laddr->a.sa.sa_family) {
  439. fl.fl4_src = laddr->a.v4.sin_addr.s_addr;
  440. if (!ip_route_output_key(&rt, &fl)) {
  441. dst = &rt->u.dst;
  442. goto out_unlock;
  443. }
  444. }
  445. }
  446. out_unlock:
  447. sctp_read_unlock(addr_lock);
  448. out:
  449. if (dst)
  450. SCTP_DEBUG_PRINTK("rt_dst:%u.%u.%u.%u, rt_src:%u.%u.%u.%u\n",
  451. NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_src));
  452. else
  453. SCTP_DEBUG_PRINTK("NO ROUTE\n");
  454. return dst;
  455. }
  456. /* For v4, the source address is cached in the route entry(dst). So no need
  457. * to cache it separately and hence this is an empty routine.
  458. */
  459. static void sctp_v4_get_saddr(struct sctp_association *asoc,
  460. struct dst_entry *dst,
  461. union sctp_addr *daddr,
  462. union sctp_addr *saddr)
  463. {
  464. struct rtable *rt = (struct rtable *)dst;
  465. if (!asoc)
  466. return;
  467. if (rt) {
  468. saddr->v4.sin_family = AF_INET;
  469. saddr->v4.sin_port = asoc->base.bind_addr.port;
  470. saddr->v4.sin_addr.s_addr = rt->rt_src;
  471. }
  472. }
  473. /* What interface did this skb arrive on? */
  474. static int sctp_v4_skb_iif(const struct sk_buff *skb)
  475. {
  476. return ((struct rtable *)skb->dst)->rt_iif;
  477. }
  478. /* Was this packet marked by Explicit Congestion Notification? */
  479. static int sctp_v4_is_ce(const struct sk_buff *skb)
  480. {
  481. return INET_ECN_is_ce(skb->nh.iph->tos);
  482. }
  483. /* Create and initialize a new sk for the socket returned by accept(). */
  484. static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
  485. struct sctp_association *asoc)
  486. {
  487. struct inet_sock *inet = inet_sk(sk);
  488. struct inet_sock *newinet;
  489. struct sock *newsk = sk_alloc(PF_INET, GFP_KERNEL, sk->sk_prot, 1);
  490. if (!newsk)
  491. goto out;
  492. sock_init_data(NULL, newsk);
  493. newsk->sk_type = SOCK_STREAM;
  494. newsk->sk_no_check = sk->sk_no_check;
  495. newsk->sk_reuse = sk->sk_reuse;
  496. newsk->sk_shutdown = sk->sk_shutdown;
  497. newsk->sk_destruct = inet_sock_destruct;
  498. newsk->sk_family = PF_INET;
  499. newsk->sk_protocol = IPPROTO_SCTP;
  500. newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
  501. sock_reset_flag(newsk, SOCK_ZAPPED);
  502. newinet = inet_sk(newsk);
  503. /* Initialize sk's sport, dport, rcv_saddr and daddr for
  504. * getsockname() and getpeername()
  505. */
  506. newinet->sport = inet->sport;
  507. newinet->saddr = inet->saddr;
  508. newinet->rcv_saddr = inet->rcv_saddr;
  509. newinet->dport = htons(asoc->peer.port);
  510. newinet->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr;
  511. newinet->pmtudisc = inet->pmtudisc;
  512. newinet->id = 0;
  513. newinet->uc_ttl = -1;
  514. newinet->mc_loop = 1;
  515. newinet->mc_ttl = 1;
  516. newinet->mc_index = 0;
  517. newinet->mc_list = NULL;
  518. sk_refcnt_debug_inc(newsk);
  519. if (newsk->sk_prot->init(newsk)) {
  520. sk_common_release(newsk);
  521. newsk = NULL;
  522. }
  523. out:
  524. return newsk;
  525. }
  526. /* Map address, empty for v4 family */
  527. static void sctp_v4_addr_v4map(struct sctp_sock *sp, union sctp_addr *addr)
  528. {
  529. /* Empty */
  530. }
  531. /* Dump the v4 addr to the seq file. */
  532. static void sctp_v4_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
  533. {
  534. seq_printf(seq, "%d.%d.%d.%d ", NIPQUAD(addr->v4.sin_addr));
  535. }
  536. /* Event handler for inet address addition/deletion events.
  537. * Basically, whenever there is an event, we re-build our local address list.
  538. */
  539. int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,
  540. void *ptr)
  541. {
  542. unsigned long flags;
  543. sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);
  544. __sctp_free_local_addr_list();
  545. __sctp_get_local_addr_list();
  546. sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);
  547. return NOTIFY_DONE;
  548. }
  549. /*
  550. * Initialize the control inode/socket with a control endpoint data
  551. * structure. This endpoint is reserved exclusively for the OOTB processing.
  552. */
  553. static int sctp_ctl_sock_init(void)
  554. {
  555. int err;
  556. sa_family_t family;
  557. if (sctp_get_pf_specific(PF_INET6))
  558. family = PF_INET6;
  559. else
  560. family = PF_INET;
  561. err = sock_create_kern(family, SOCK_SEQPACKET, IPPROTO_SCTP,
  562. &sctp_ctl_socket);
  563. if (err < 0) {
  564. printk(KERN_ERR
  565. "SCTP: Failed to create the SCTP control socket.\n");
  566. return err;
  567. }
  568. sctp_ctl_socket->sk->sk_allocation = GFP_ATOMIC;
  569. inet_sk(sctp_ctl_socket->sk)->uc_ttl = -1;
  570. return 0;
  571. }
  572. /* Register address family specific functions. */
  573. int sctp_register_af(struct sctp_af *af)
  574. {
  575. switch (af->sa_family) {
  576. case AF_INET:
  577. if (sctp_af_v4_specific)
  578. return 0;
  579. sctp_af_v4_specific = af;
  580. break;
  581. case AF_INET6:
  582. if (sctp_af_v6_specific)
  583. return 0;
  584. sctp_af_v6_specific = af;
  585. break;
  586. default:
  587. return 0;
  588. }
  589. INIT_LIST_HEAD(&af->list);
  590. list_add_tail(&af->list, &sctp_address_families);
  591. return 1;
  592. }
  593. /* Get the table of functions for manipulating a particular address
  594. * family.
  595. */
  596. struct sctp_af *sctp_get_af_specific(sa_family_t family)
  597. {
  598. switch (family) {
  599. case AF_INET:
  600. return sctp_af_v4_specific;
  601. case AF_INET6:
  602. return sctp_af_v6_specific;
  603. default:
  604. return NULL;
  605. }
  606. }
  607. /* Common code to initialize a AF_INET msg_name. */
  608. static void sctp_inet_msgname(char *msgname, int *addr_len)
  609. {
  610. struct sockaddr_in *sin;
  611. sin = (struct sockaddr_in *)msgname;
  612. *addr_len = sizeof(struct sockaddr_in);
  613. sin->sin_family = AF_INET;
  614. memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
  615. }
  616. /* Copy the primary address of the peer primary address as the msg_name. */
  617. static void sctp_inet_event_msgname(struct sctp_ulpevent *event, char *msgname,
  618. int *addr_len)
  619. {
  620. struct sockaddr_in *sin, *sinfrom;
  621. if (msgname) {
  622. struct sctp_association *asoc;
  623. asoc = event->asoc;
  624. sctp_inet_msgname(msgname, addr_len);
  625. sin = (struct sockaddr_in *)msgname;
  626. sinfrom = &asoc->peer.primary_addr.v4;
  627. sin->sin_port = htons(asoc->peer.port);
  628. sin->sin_addr.s_addr = sinfrom->sin_addr.s_addr;
  629. }
  630. }
  631. /* Initialize and copy out a msgname from an inbound skb. */
  632. static void sctp_inet_skb_msgname(struct sk_buff *skb, char *msgname, int *len)
  633. {
  634. struct sctphdr *sh;
  635. struct sockaddr_in *sin;
  636. if (msgname) {
  637. sctp_inet_msgname(msgname, len);
  638. sin = (struct sockaddr_in *)msgname;
  639. sh = (struct sctphdr *)skb->h.raw;
  640. sin->sin_port = sh->source;
  641. sin->sin_addr.s_addr = skb->nh.iph->saddr;
  642. }
  643. }
  644. /* Do we support this AF? */
  645. static int sctp_inet_af_supported(sa_family_t family, struct sctp_sock *sp)
  646. {
  647. /* PF_INET only supports AF_INET addresses. */
  648. return (AF_INET == family);
  649. }
  650. /* Address matching with wildcards allowed. */
  651. static int sctp_inet_cmp_addr(const union sctp_addr *addr1,
  652. const union sctp_addr *addr2,
  653. struct sctp_sock *opt)
  654. {
  655. /* PF_INET only supports AF_INET addresses. */
  656. if (addr1->sa.sa_family != addr2->sa.sa_family)
  657. return 0;
  658. if (INADDR_ANY == addr1->v4.sin_addr.s_addr ||
  659. INADDR_ANY == addr2->v4.sin_addr.s_addr)
  660. return 1;
  661. if (addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr)
  662. return 1;
  663. return 0;
  664. }
  665. /* Verify that provided sockaddr looks bindable. Common verification has
  666. * already been taken care of.
  667. */
  668. static int sctp_inet_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
  669. {
  670. return sctp_v4_available(addr, opt);
  671. }
  672. /* Verify that sockaddr looks sendable. Common verification has already
  673. * been taken care of.
  674. */
  675. static int sctp_inet_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
  676. {
  677. return 1;
  678. }
  679. /* Fill in Supported Address Type information for INIT and INIT-ACK
  680. * chunks. Returns number of addresses supported.
  681. */
  682. static int sctp_inet_supported_addrs(const struct sctp_sock *opt,
  683. __u16 *types)
  684. {
  685. types[0] = SCTP_PARAM_IPV4_ADDRESS;
  686. return 1;
  687. }
  688. /* Wrapper routine that calls the ip transmit routine. */
  689. static inline int sctp_v4_xmit(struct sk_buff *skb,
  690. struct sctp_transport *transport, int ipfragok)
  691. {
  692. SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, "
  693. "src:%u.%u.%u.%u, dst:%u.%u.%u.%u\n",
  694. __FUNCTION__, skb, skb->len,
  695. NIPQUAD(((struct rtable *)skb->dst)->rt_src),
  696. NIPQUAD(((struct rtable *)skb->dst)->rt_dst));
  697. SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS);
  698. return ip_queue_xmit(skb, ipfragok);
  699. }
  700. static struct sctp_af sctp_ipv4_specific;
  701. static struct sctp_pf sctp_pf_inet = {
  702. .event_msgname = sctp_inet_event_msgname,
  703. .skb_msgname = sctp_inet_skb_msgname,
  704. .af_supported = sctp_inet_af_supported,
  705. .cmp_addr = sctp_inet_cmp_addr,
  706. .bind_verify = sctp_inet_bind_verify,
  707. .send_verify = sctp_inet_send_verify,
  708. .supported_addrs = sctp_inet_supported_addrs,
  709. .create_accept_sk = sctp_v4_create_accept_sk,
  710. .addr_v4map = sctp_v4_addr_v4map,
  711. .af = &sctp_ipv4_specific,
  712. };
  713. /* Notifier for inetaddr addition/deletion events. */
  714. static struct notifier_block sctp_inetaddr_notifier = {
  715. .notifier_call = sctp_inetaddr_event,
  716. };
  717. /* Socket operations. */
  718. static struct proto_ops inet_seqpacket_ops = {
  719. .family = PF_INET,
  720. .owner = THIS_MODULE,
  721. .release = inet_release, /* Needs to be wrapped... */
  722. .bind = inet_bind,
  723. .connect = inet_dgram_connect,
  724. .socketpair = sock_no_socketpair,
  725. .accept = inet_accept,
  726. .getname = inet_getname, /* Semantics are different. */
  727. .poll = sctp_poll,
  728. .ioctl = inet_ioctl,
  729. .listen = sctp_inet_listen,
  730. .shutdown = inet_shutdown, /* Looks harmless. */
  731. .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem. */
  732. .getsockopt = sock_common_getsockopt,
  733. .sendmsg = inet_sendmsg,
  734. .recvmsg = sock_common_recvmsg,
  735. .mmap = sock_no_mmap,
  736. .sendpage = sock_no_sendpage,
  737. };
  738. /* Registration with AF_INET family. */
  739. static struct inet_protosw sctp_seqpacket_protosw = {
  740. .type = SOCK_SEQPACKET,
  741. .protocol = IPPROTO_SCTP,
  742. .prot = &sctp_prot,
  743. .ops = &inet_seqpacket_ops,
  744. .capability = -1,
  745. .no_check = 0,
  746. .flags = SCTP_PROTOSW_FLAG
  747. };
  748. static struct inet_protosw sctp_stream_protosw = {
  749. .type = SOCK_STREAM,
  750. .protocol = IPPROTO_SCTP,
  751. .prot = &sctp_prot,
  752. .ops = &inet_seqpacket_ops,
  753. .capability = -1,
  754. .no_check = 0,
  755. .flags = SCTP_PROTOSW_FLAG
  756. };
  757. /* Register with IP layer. */
  758. static struct net_protocol sctp_protocol = {
  759. .handler = sctp_rcv,
  760. .err_handler = sctp_v4_err,
  761. .no_policy = 1,
  762. };
  763. /* IPv4 address related functions. */
  764. static struct sctp_af sctp_ipv4_specific = {
  765. .sctp_xmit = sctp_v4_xmit,
  766. .setsockopt = ip_setsockopt,
  767. .getsockopt = ip_getsockopt,
  768. .get_dst = sctp_v4_get_dst,
  769. .get_saddr = sctp_v4_get_saddr,
  770. .copy_addrlist = sctp_v4_copy_addrlist,
  771. .from_skb = sctp_v4_from_skb,
  772. .from_sk = sctp_v4_from_sk,
  773. .to_sk_saddr = sctp_v4_to_sk_saddr,
  774. .to_sk_daddr = sctp_v4_to_sk_daddr,
  775. .from_addr_param= sctp_v4_from_addr_param,
  776. .to_addr_param = sctp_v4_to_addr_param,
  777. .dst_saddr = sctp_v4_dst_saddr,
  778. .cmp_addr = sctp_v4_cmp_addr,
  779. .addr_valid = sctp_v4_addr_valid,
  780. .inaddr_any = sctp_v4_inaddr_any,
  781. .is_any = sctp_v4_is_any,
  782. .available = sctp_v4_available,
  783. .scope = sctp_v4_scope,
  784. .skb_iif = sctp_v4_skb_iif,
  785. .is_ce = sctp_v4_is_ce,
  786. .seq_dump_addr = sctp_v4_seq_dump_addr,
  787. .net_header_len = sizeof(struct iphdr),
  788. .sockaddr_len = sizeof(struct sockaddr_in),
  789. .sa_family = AF_INET,
  790. };
  791. struct sctp_pf *sctp_get_pf_specific(sa_family_t family) {
  792. switch (family) {
  793. case PF_INET:
  794. return sctp_pf_inet_specific;
  795. case PF_INET6:
  796. return sctp_pf_inet6_specific;
  797. default:
  798. return NULL;
  799. }
  800. }
  801. /* Register the PF specific function table. */
  802. int sctp_register_pf(struct sctp_pf *pf, sa_family_t family)
  803. {
  804. switch (family) {
  805. case PF_INET:
  806. if (sctp_pf_inet_specific)
  807. return 0;
  808. sctp_pf_inet_specific = pf;
  809. break;
  810. case PF_INET6:
  811. if (sctp_pf_inet6_specific)
  812. return 0;
  813. sctp_pf_inet6_specific = pf;
  814. break;
  815. default:
  816. return 0;
  817. }
  818. return 1;
  819. }
  820. static int __init init_sctp_mibs(void)
  821. {
  822. sctp_statistics[0] = alloc_percpu(struct sctp_mib);
  823. if (!sctp_statistics[0])
  824. return -ENOMEM;
  825. sctp_statistics[1] = alloc_percpu(struct sctp_mib);
  826. if (!sctp_statistics[1]) {
  827. free_percpu(sctp_statistics[0]);
  828. return -ENOMEM;
  829. }
  830. return 0;
  831. }
  832. static void cleanup_sctp_mibs(void)
  833. {
  834. free_percpu(sctp_statistics[0]);
  835. free_percpu(sctp_statistics[1]);
  836. }
  837. /* Initialize the universe into something sensible. */
  838. SCTP_STATIC __init int sctp_init(void)
  839. {
  840. int i;
  841. int status = -EINVAL;
  842. unsigned long goal;
  843. int order;
  844. /* SCTP_DEBUG sanity check. */
  845. if (!sctp_sanity_check())
  846. goto out;
  847. status = proto_register(&sctp_prot, 1);
  848. if (status)
  849. goto out;
  850. /* Add SCTP to inet_protos hash table. */
  851. status = -EAGAIN;
  852. if (inet_add_protocol(&sctp_protocol, IPPROTO_SCTP) < 0)
  853. goto err_add_protocol;
  854. /* Add SCTP(TCP and UDP style) to inetsw linked list. */
  855. inet_register_protosw(&sctp_seqpacket_protosw);
  856. inet_register_protosw(&sctp_stream_protosw);
  857. /* Allocate a cache pools. */
  858. status = -ENOBUFS;
  859. sctp_bucket_cachep = kmem_cache_create("sctp_bind_bucket",
  860. sizeof(struct sctp_bind_bucket),
  861. 0, SLAB_HWCACHE_ALIGN,
  862. NULL, NULL);
  863. if (!sctp_bucket_cachep)
  864. goto err_bucket_cachep;
  865. sctp_chunk_cachep = kmem_cache_create("sctp_chunk",
  866. sizeof(struct sctp_chunk),
  867. 0, SLAB_HWCACHE_ALIGN,
  868. NULL, NULL);
  869. if (!sctp_chunk_cachep)
  870. goto err_chunk_cachep;
  871. /* Allocate and initialise sctp mibs. */
  872. status = init_sctp_mibs();
  873. if (status)
  874. goto err_init_mibs;
  875. /* Initialize proc fs directory. */
  876. status = sctp_proc_init();
  877. if (status)
  878. goto err_init_proc;
  879. /* Initialize object count debugging. */
  880. sctp_dbg_objcnt_init();
  881. /* Initialize the SCTP specific PF functions. */
  882. sctp_register_pf(&sctp_pf_inet, PF_INET);
  883. /*
  884. * 14. Suggested SCTP Protocol Parameter Values
  885. */
  886. /* The following protocol parameters are RECOMMENDED: */
  887. /* RTO.Initial - 3 seconds */
  888. sctp_rto_initial = SCTP_RTO_INITIAL;
  889. /* RTO.Min - 1 second */
  890. sctp_rto_min = SCTP_RTO_MIN;
  891. /* RTO.Max - 60 seconds */
  892. sctp_rto_max = SCTP_RTO_MAX;
  893. /* RTO.Alpha - 1/8 */
  894. sctp_rto_alpha = SCTP_RTO_ALPHA;
  895. /* RTO.Beta - 1/4 */
  896. sctp_rto_beta = SCTP_RTO_BETA;
  897. /* Valid.Cookie.Life - 60 seconds */
  898. sctp_valid_cookie_life = 60 * HZ;
  899. /* Whether Cookie Preservative is enabled(1) or not(0) */
  900. sctp_cookie_preserve_enable = 1;
  901. /* Max.Burst - 4 */
  902. sctp_max_burst = SCTP_MAX_BURST;
  903. /* Association.Max.Retrans - 10 attempts
  904. * Path.Max.Retrans - 5 attempts (per destination address)
  905. * Max.Init.Retransmits - 8 attempts
  906. */
  907. sctp_max_retrans_association = 10;
  908. sctp_max_retrans_path = 5;
  909. sctp_max_retrans_init = 8;
  910. /* Sendbuffer growth - do per-socket accounting */
  911. sctp_sndbuf_policy = 0;
  912. /* Rcvbuffer growth - do per-socket accounting */
  913. sctp_rcvbuf_policy = 0;
  914. /* HB.interval - 30 seconds */
  915. sctp_hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT;
  916. /* delayed SACK timeout */
  917. sctp_sack_timeout = SCTP_DEFAULT_TIMEOUT_SACK;
  918. /* Implementation specific variables. */
  919. /* Initialize default stream count setup information. */
  920. sctp_max_instreams = SCTP_DEFAULT_INSTREAMS;
  921. sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS;
  922. /* Initialize handle used for association ids. */
  923. idr_init(&sctp_assocs_id);
  924. /* Size and allocate the association hash table.
  925. * The methodology is similar to that of the tcp hash tables.
  926. */
  927. if (num_physpages >= (128 * 1024))
  928. goal = num_physpages >> (22 - PAGE_SHIFT);
  929. else
  930. goal = num_physpages >> (24 - PAGE_SHIFT);
  931. for (order = 0; (1UL << order) < goal; order++)
  932. ;
  933. do {
  934. sctp_assoc_hashsize = (1UL << order) * PAGE_SIZE /
  935. sizeof(struct sctp_hashbucket);
  936. if ((sctp_assoc_hashsize > (64 * 1024)) && order > 0)
  937. continue;
  938. sctp_assoc_hashtable = (struct sctp_hashbucket *)
  939. __get_free_pages(GFP_ATOMIC, order);
  940. } while (!sctp_assoc_hashtable && --order > 0);
  941. if (!sctp_assoc_hashtable) {
  942. printk(KERN_ERR "SCTP: Failed association hash alloc.\n");
  943. status = -ENOMEM;
  944. goto err_ahash_alloc;
  945. }
  946. for (i = 0; i < sctp_assoc_hashsize; i++) {
  947. rwlock_init(&sctp_assoc_hashtable[i].lock);
  948. sctp_assoc_hashtable[i].chain = NULL;
  949. }
  950. /* Allocate and initialize the endpoint hash table. */
  951. sctp_ep_hashsize = 64;
  952. sctp_ep_hashtable = (struct sctp_hashbucket *)
  953. kmalloc(64 * sizeof(struct sctp_hashbucket), GFP_KERNEL);
  954. if (!sctp_ep_hashtable) {
  955. printk(KERN_ERR "SCTP: Failed endpoint_hash alloc.\n");
  956. status = -ENOMEM;
  957. goto err_ehash_alloc;
  958. }
  959. for (i = 0; i < sctp_ep_hashsize; i++) {
  960. rwlock_init(&sctp_ep_hashtable[i].lock);
  961. sctp_ep_hashtable[i].chain = NULL;
  962. }
  963. /* Allocate and initialize the SCTP port hash table. */
  964. do {
  965. sctp_port_hashsize = (1UL << order) * PAGE_SIZE /
  966. sizeof(struct sctp_bind_hashbucket);
  967. if ((sctp_port_hashsize > (64 * 1024)) && order > 0)
  968. continue;
  969. sctp_port_hashtable = (struct sctp_bind_hashbucket *)
  970. __get_free_pages(GFP_ATOMIC, order);
  971. } while (!sctp_port_hashtable && --order > 0);
  972. if (!sctp_port_hashtable) {
  973. printk(KERN_ERR "SCTP: Failed bind hash alloc.");
  974. status = -ENOMEM;
  975. goto err_bhash_alloc;
  976. }
  977. for (i = 0; i < sctp_port_hashsize; i++) {
  978. spin_lock_init(&sctp_port_hashtable[i].lock);
  979. sctp_port_hashtable[i].chain = NULL;
  980. }
  981. spin_lock_init(&sctp_port_alloc_lock);
  982. sctp_port_rover = sysctl_local_port_range[0] - 1;
  983. printk(KERN_INFO "SCTP: Hash tables configured "
  984. "(established %d bind %d)\n",
  985. sctp_assoc_hashsize, sctp_port_hashsize);
  986. /* Disable ADDIP by default. */
  987. sctp_addip_enable = 0;
  988. /* Enable PR-SCTP by default. */
  989. sctp_prsctp_enable = 1;
  990. sctp_sysctl_register();
  991. INIT_LIST_HEAD(&sctp_address_families);
  992. sctp_register_af(&sctp_ipv4_specific);
  993. status = sctp_v6_init();
  994. if (status)
  995. goto err_v6_init;
  996. /* Initialize the control inode/socket for handling OOTB packets. */
  997. if ((status = sctp_ctl_sock_init())) {
  998. printk (KERN_ERR
  999. "SCTP: Failed to initialize the SCTP control sock.\n");
  1000. goto err_ctl_sock_init;
  1001. }
  1002. /* Initialize the local address list. */
  1003. INIT_LIST_HEAD(&sctp_local_addr_list);
  1004. spin_lock_init(&sctp_local_addr_lock);
  1005. /* Register notifier for inet address additions/deletions. */
  1006. register_inetaddr_notifier(&sctp_inetaddr_notifier);
  1007. sctp_get_local_addr_list();
  1008. __unsafe(THIS_MODULE);
  1009. status = 0;
  1010. out:
  1011. return status;
  1012. err_ctl_sock_init:
  1013. sctp_v6_exit();
  1014. err_v6_init:
  1015. sctp_sysctl_unregister();
  1016. list_del(&sctp_ipv4_specific.list);
  1017. free_pages((unsigned long)sctp_port_hashtable,
  1018. get_order(sctp_port_hashsize *
  1019. sizeof(struct sctp_bind_hashbucket)));
  1020. err_bhash_alloc:
  1021. kfree(sctp_ep_hashtable);
  1022. err_ehash_alloc:
  1023. free_pages((unsigned long)sctp_assoc_hashtable,
  1024. get_order(sctp_assoc_hashsize *
  1025. sizeof(struct sctp_hashbucket)));
  1026. err_ahash_alloc:
  1027. sctp_dbg_objcnt_exit();
  1028. err_init_proc:
  1029. sctp_proc_exit();
  1030. cleanup_sctp_mibs();
  1031. err_init_mibs:
  1032. kmem_cache_destroy(sctp_chunk_cachep);
  1033. err_chunk_cachep:
  1034. kmem_cache_destroy(sctp_bucket_cachep);
  1035. err_bucket_cachep:
  1036. inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
  1037. inet_unregister_protosw(&sctp_seqpacket_protosw);
  1038. inet_unregister_protosw(&sctp_stream_protosw);
  1039. err_add_protocol:
  1040. proto_unregister(&sctp_prot);
  1041. goto out;
  1042. }
  1043. /* Exit handler for the SCTP protocol. */
  1044. SCTP_STATIC __exit void sctp_exit(void)
  1045. {
  1046. /* BUG. This should probably do something useful like clean
  1047. * up all the remaining associations and all that memory.
  1048. */
  1049. /* Unregister notifier for inet address additions/deletions. */
  1050. unregister_inetaddr_notifier(&sctp_inetaddr_notifier);
  1051. /* Free the local address list. */
  1052. sctp_free_local_addr_list();
  1053. /* Free the control endpoint. */
  1054. sock_release(sctp_ctl_socket);
  1055. sctp_v6_exit();
  1056. sctp_sysctl_unregister();
  1057. list_del(&sctp_ipv4_specific.list);
  1058. free_pages((unsigned long)sctp_assoc_hashtable,
  1059. get_order(sctp_assoc_hashsize *
  1060. sizeof(struct sctp_hashbucket)));
  1061. kfree(sctp_ep_hashtable);
  1062. free_pages((unsigned long)sctp_port_hashtable,
  1063. get_order(sctp_port_hashsize *
  1064. sizeof(struct sctp_bind_hashbucket)));
  1065. kmem_cache_destroy(sctp_chunk_cachep);
  1066. kmem_cache_destroy(sctp_bucket_cachep);
  1067. sctp_dbg_objcnt_exit();
  1068. sctp_proc_exit();
  1069. cleanup_sctp_mibs();
  1070. inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
  1071. inet_unregister_protosw(&sctp_seqpacket_protosw);
  1072. inet_unregister_protosw(&sctp_stream_protosw);
  1073. proto_unregister(&sctp_prot);
  1074. }
  1075. module_init(sctp_init);
  1076. module_exit(sctp_exit);
  1077. /*
  1078. * __stringify doesn't likes enums, so use IPPROTO_SCTP value (132) directly.
  1079. */
  1080. MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132");
  1081. MODULE_AUTHOR("Linux Kernel SCTP developers <lksctp-developers@lists.sourceforge.net>");
  1082. MODULE_DESCRIPTION("Support for the SCTP protocol (RFC2960)");
  1083. MODULE_LICENSE("GPL");