protocol.c 34 KB

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