protocol.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  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);
  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;
  76. kmem_cache_t *sctp_bucket_cachep;
  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(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. unsigned int __nocast 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 (rt) {
  466. saddr->v4.sin_family = AF_INET;
  467. saddr->v4.sin_port = asoc->base.bind_addr.port;
  468. saddr->v4.sin_addr.s_addr = rt->rt_src;
  469. }
  470. }
  471. /* What interface did this skb arrive on? */
  472. static int sctp_v4_skb_iif(const struct sk_buff *skb)
  473. {
  474. return ((struct rtable *)skb->dst)->rt_iif;
  475. }
  476. /* Was this packet marked by Explicit Congestion Notification? */
  477. static int sctp_v4_is_ce(const struct sk_buff *skb)
  478. {
  479. return INET_ECN_is_ce(skb->nh.iph->tos);
  480. }
  481. /* Create and initialize a new sk for the socket returned by accept(). */
  482. static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
  483. struct sctp_association *asoc)
  484. {
  485. struct inet_sock *inet = inet_sk(sk);
  486. struct inet_sock *newinet;
  487. struct sock *newsk = sk_alloc(PF_INET, GFP_KERNEL, sk->sk_prot, 1);
  488. if (!newsk)
  489. goto out;
  490. sock_init_data(NULL, newsk);
  491. newsk->sk_type = SOCK_STREAM;
  492. newsk->sk_no_check = sk->sk_no_check;
  493. newsk->sk_reuse = sk->sk_reuse;
  494. newsk->sk_shutdown = sk->sk_shutdown;
  495. newsk->sk_destruct = inet_sock_destruct;
  496. newsk->sk_family = PF_INET;
  497. newsk->sk_protocol = IPPROTO_SCTP;
  498. newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
  499. sock_reset_flag(newsk, SOCK_ZAPPED);
  500. newinet = inet_sk(newsk);
  501. /* Initialize sk's sport, dport, rcv_saddr and daddr for
  502. * getsockname() and getpeername()
  503. */
  504. newinet->sport = inet->sport;
  505. newinet->saddr = inet->saddr;
  506. newinet->rcv_saddr = inet->rcv_saddr;
  507. newinet->dport = htons(asoc->peer.port);
  508. newinet->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr;
  509. newinet->pmtudisc = inet->pmtudisc;
  510. newinet->id = 0;
  511. newinet->uc_ttl = -1;
  512. newinet->mc_loop = 1;
  513. newinet->mc_ttl = 1;
  514. newinet->mc_index = 0;
  515. newinet->mc_list = NULL;
  516. #ifdef INET_REFCNT_DEBUG
  517. atomic_inc(&inet_sock_nr);
  518. #endif
  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. /* HB.interval - 30 seconds */
  913. sctp_hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT;
  914. /* delayed SACK timeout */
  915. sctp_sack_timeout = SCTP_DEFAULT_TIMEOUT_SACK;
  916. /* Implementation specific variables. */
  917. /* Initialize default stream count setup information. */
  918. sctp_max_instreams = SCTP_DEFAULT_INSTREAMS;
  919. sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS;
  920. /* Initialize handle used for association ids. */
  921. idr_init(&sctp_assocs_id);
  922. /* Size and allocate the association hash table.
  923. * The methodology is similar to that of the tcp hash tables.
  924. */
  925. if (num_physpages >= (128 * 1024))
  926. goal = num_physpages >> (22 - PAGE_SHIFT);
  927. else
  928. goal = num_physpages >> (24 - PAGE_SHIFT);
  929. for (order = 0; (1UL << order) < goal; order++)
  930. ;
  931. do {
  932. sctp_assoc_hashsize = (1UL << order) * PAGE_SIZE /
  933. sizeof(struct sctp_hashbucket);
  934. if ((sctp_assoc_hashsize > (64 * 1024)) && order > 0)
  935. continue;
  936. sctp_assoc_hashtable = (struct sctp_hashbucket *)
  937. __get_free_pages(GFP_ATOMIC, order);
  938. } while (!sctp_assoc_hashtable && --order > 0);
  939. if (!sctp_assoc_hashtable) {
  940. printk(KERN_ERR "SCTP: Failed association hash alloc.\n");
  941. status = -ENOMEM;
  942. goto err_ahash_alloc;
  943. }
  944. for (i = 0; i < sctp_assoc_hashsize; i++) {
  945. rwlock_init(&sctp_assoc_hashtable[i].lock);
  946. sctp_assoc_hashtable[i].chain = NULL;
  947. }
  948. /* Allocate and initialize the endpoint hash table. */
  949. sctp_ep_hashsize = 64;
  950. sctp_ep_hashtable = (struct sctp_hashbucket *)
  951. kmalloc(64 * sizeof(struct sctp_hashbucket), GFP_KERNEL);
  952. if (!sctp_ep_hashtable) {
  953. printk(KERN_ERR "SCTP: Failed endpoint_hash alloc.\n");
  954. status = -ENOMEM;
  955. goto err_ehash_alloc;
  956. }
  957. for (i = 0; i < sctp_ep_hashsize; i++) {
  958. rwlock_init(&sctp_ep_hashtable[i].lock);
  959. sctp_ep_hashtable[i].chain = NULL;
  960. }
  961. /* Allocate and initialize the SCTP port hash table. */
  962. do {
  963. sctp_port_hashsize = (1UL << order) * PAGE_SIZE /
  964. sizeof(struct sctp_bind_hashbucket);
  965. if ((sctp_port_hashsize > (64 * 1024)) && order > 0)
  966. continue;
  967. sctp_port_hashtable = (struct sctp_bind_hashbucket *)
  968. __get_free_pages(GFP_ATOMIC, order);
  969. } while (!sctp_port_hashtable && --order > 0);
  970. if (!sctp_port_hashtable) {
  971. printk(KERN_ERR "SCTP: Failed bind hash alloc.");
  972. status = -ENOMEM;
  973. goto err_bhash_alloc;
  974. }
  975. for (i = 0; i < sctp_port_hashsize; i++) {
  976. spin_lock_init(&sctp_port_hashtable[i].lock);
  977. sctp_port_hashtable[i].chain = NULL;
  978. }
  979. spin_lock_init(&sctp_port_alloc_lock);
  980. sctp_port_rover = sysctl_local_port_range[0] - 1;
  981. printk(KERN_INFO "SCTP: Hash tables configured "
  982. "(established %d bind %d)\n",
  983. sctp_assoc_hashsize, sctp_port_hashsize);
  984. /* Disable ADDIP by default. */
  985. sctp_addip_enable = 0;
  986. /* Enable PR-SCTP by default. */
  987. sctp_prsctp_enable = 1;
  988. sctp_sysctl_register();
  989. INIT_LIST_HEAD(&sctp_address_families);
  990. sctp_register_af(&sctp_ipv4_specific);
  991. status = sctp_v6_init();
  992. if (status)
  993. goto err_v6_init;
  994. /* Initialize the control inode/socket for handling OOTB packets. */
  995. if ((status = sctp_ctl_sock_init())) {
  996. printk (KERN_ERR
  997. "SCTP: Failed to initialize the SCTP control sock.\n");
  998. goto err_ctl_sock_init;
  999. }
  1000. /* Initialize the local address list. */
  1001. INIT_LIST_HEAD(&sctp_local_addr_list);
  1002. spin_lock_init(&sctp_local_addr_lock);
  1003. /* Register notifier for inet address additions/deletions. */
  1004. register_inetaddr_notifier(&sctp_inetaddr_notifier);
  1005. sctp_get_local_addr_list();
  1006. __unsafe(THIS_MODULE);
  1007. status = 0;
  1008. out:
  1009. return status;
  1010. err_ctl_sock_init:
  1011. sctp_v6_exit();
  1012. err_v6_init:
  1013. sctp_sysctl_unregister();
  1014. list_del(&sctp_ipv4_specific.list);
  1015. free_pages((unsigned long)sctp_port_hashtable,
  1016. get_order(sctp_port_hashsize *
  1017. sizeof(struct sctp_bind_hashbucket)));
  1018. err_bhash_alloc:
  1019. kfree(sctp_ep_hashtable);
  1020. err_ehash_alloc:
  1021. free_pages((unsigned long)sctp_assoc_hashtable,
  1022. get_order(sctp_assoc_hashsize *
  1023. sizeof(struct sctp_hashbucket)));
  1024. err_ahash_alloc:
  1025. sctp_dbg_objcnt_exit();
  1026. err_init_proc:
  1027. sctp_proc_exit();
  1028. cleanup_sctp_mibs();
  1029. err_init_mibs:
  1030. kmem_cache_destroy(sctp_chunk_cachep);
  1031. err_chunk_cachep:
  1032. kmem_cache_destroy(sctp_bucket_cachep);
  1033. err_bucket_cachep:
  1034. inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
  1035. inet_unregister_protosw(&sctp_seqpacket_protosw);
  1036. inet_unregister_protosw(&sctp_stream_protosw);
  1037. err_add_protocol:
  1038. proto_unregister(&sctp_prot);
  1039. goto out;
  1040. }
  1041. /* Exit handler for the SCTP protocol. */
  1042. SCTP_STATIC __exit void sctp_exit(void)
  1043. {
  1044. /* BUG. This should probably do something useful like clean
  1045. * up all the remaining associations and all that memory.
  1046. */
  1047. /* Unregister notifier for inet address additions/deletions. */
  1048. unregister_inetaddr_notifier(&sctp_inetaddr_notifier);
  1049. /* Free the local address list. */
  1050. sctp_free_local_addr_list();
  1051. /* Free the control endpoint. */
  1052. sock_release(sctp_ctl_socket);
  1053. sctp_v6_exit();
  1054. sctp_sysctl_unregister();
  1055. list_del(&sctp_ipv4_specific.list);
  1056. free_pages((unsigned long)sctp_assoc_hashtable,
  1057. get_order(sctp_assoc_hashsize *
  1058. sizeof(struct sctp_hashbucket)));
  1059. kfree(sctp_ep_hashtable);
  1060. free_pages((unsigned long)sctp_port_hashtable,
  1061. get_order(sctp_port_hashsize *
  1062. sizeof(struct sctp_bind_hashbucket)));
  1063. kmem_cache_destroy(sctp_chunk_cachep);
  1064. kmem_cache_destroy(sctp_bucket_cachep);
  1065. sctp_dbg_objcnt_exit();
  1066. sctp_proc_exit();
  1067. cleanup_sctp_mibs();
  1068. inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
  1069. inet_unregister_protosw(&sctp_seqpacket_protosw);
  1070. inet_unregister_protosw(&sctp_stream_protosw);
  1071. proto_unregister(&sctp_prot);
  1072. }
  1073. module_init(sctp_init);
  1074. module_exit(sctp_exit);
  1075. MODULE_AUTHOR("Linux Kernel SCTP developers <lksctp-developers@lists.sourceforge.net>");
  1076. MODULE_DESCRIPTION("Support for the SCTP protocol (RFC2960)");
  1077. MODULE_LICENSE("GPL");