protocol.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  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. int 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. /* FIXME: ip_nonlocal_bind sysctl support. */
  334. if (addr->v4.sin_addr.s_addr != INADDR_ANY && ret != RTN_LOCAL)
  335. return 0;
  336. return 1;
  337. }
  338. /* Checking the loopback, private and other address scopes as defined in
  339. * RFC 1918. The IPv4 scoping is based on the draft for SCTP IPv4
  340. * scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
  341. *
  342. * Level 0 - unusable SCTP addresses
  343. * Level 1 - loopback address
  344. * Level 2 - link-local addresses
  345. * Level 3 - private addresses.
  346. * Level 4 - global addresses
  347. * For INIT and INIT-ACK address list, let L be the level of
  348. * of requested destination address, sender and receiver
  349. * SHOULD include all of its addresses with level greater
  350. * than or equal to L.
  351. */
  352. static sctp_scope_t sctp_v4_scope(union sctp_addr *addr)
  353. {
  354. sctp_scope_t retval;
  355. /* Should IPv4 scoping be a sysctl configurable option
  356. * so users can turn it off (default on) for certain
  357. * unconventional networking environments?
  358. */
  359. /* Check for unusable SCTP addresses. */
  360. if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  361. retval = SCTP_SCOPE_UNUSABLE;
  362. } else if (LOOPBACK(addr->v4.sin_addr.s_addr)) {
  363. retval = SCTP_SCOPE_LOOPBACK;
  364. } else if (IS_IPV4_LINK_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  365. retval = SCTP_SCOPE_LINK;
  366. } else if (IS_IPV4_PRIVATE_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  367. retval = SCTP_SCOPE_PRIVATE;
  368. } else {
  369. retval = SCTP_SCOPE_GLOBAL;
  370. }
  371. return retval;
  372. }
  373. /* Returns a valid dst cache entry for the given source and destination ip
  374. * addresses. If an association is passed, trys to get a dst entry with a
  375. * source address that matches an address in the bind address list.
  376. */
  377. static struct dst_entry *sctp_v4_get_dst(struct sctp_association *asoc,
  378. union sctp_addr *daddr,
  379. union sctp_addr *saddr)
  380. {
  381. struct rtable *rt;
  382. struct flowi fl;
  383. struct sctp_bind_addr *bp;
  384. rwlock_t *addr_lock;
  385. struct sctp_sockaddr_entry *laddr;
  386. struct list_head *pos;
  387. struct dst_entry *dst = NULL;
  388. union sctp_addr dst_saddr;
  389. memset(&fl, 0x0, sizeof(struct flowi));
  390. fl.fl4_dst = daddr->v4.sin_addr.s_addr;
  391. fl.proto = IPPROTO_SCTP;
  392. if (asoc) {
  393. fl.fl4_tos = RT_CONN_FLAGS(asoc->base.sk);
  394. fl.oif = asoc->base.sk->sk_bound_dev_if;
  395. }
  396. if (saddr)
  397. fl.fl4_src = saddr->v4.sin_addr.s_addr;
  398. SCTP_DEBUG_PRINTK("%s: DST:%u.%u.%u.%u, SRC:%u.%u.%u.%u - ",
  399. __FUNCTION__, NIPQUAD(fl.fl4_dst),
  400. NIPQUAD(fl.fl4_src));
  401. if (!ip_route_output_key(&rt, &fl)) {
  402. dst = &rt->u.dst;
  403. }
  404. /* If there is no association or if a source address is passed, no
  405. * more validation is required.
  406. */
  407. if (!asoc || saddr)
  408. goto out;
  409. bp = &asoc->base.bind_addr;
  410. addr_lock = &asoc->base.addr_lock;
  411. if (dst) {
  412. /* Walk through the bind address list and look for a bind
  413. * address that matches the source address of the returned dst.
  414. */
  415. sctp_read_lock(addr_lock);
  416. list_for_each(pos, &bp->address_list) {
  417. laddr = list_entry(pos, struct sctp_sockaddr_entry,
  418. list);
  419. sctp_v4_dst_saddr(&dst_saddr, dst, bp->port);
  420. if (sctp_v4_cmp_addr(&dst_saddr, &laddr->a))
  421. goto out_unlock;
  422. }
  423. sctp_read_unlock(addr_lock);
  424. /* None of the bound addresses match the source address of the
  425. * dst. So release it.
  426. */
  427. dst_release(dst);
  428. dst = NULL;
  429. }
  430. /* Walk through the bind address list and try to get a dst that
  431. * matches a bind address as the source address.
  432. */
  433. sctp_read_lock(addr_lock);
  434. list_for_each(pos, &bp->address_list) {
  435. laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
  436. if (AF_INET == laddr->a.sa.sa_family) {
  437. fl.fl4_src = laddr->a.v4.sin_addr.s_addr;
  438. if (!ip_route_output_key(&rt, &fl)) {
  439. dst = &rt->u.dst;
  440. goto out_unlock;
  441. }
  442. }
  443. }
  444. out_unlock:
  445. sctp_read_unlock(addr_lock);
  446. out:
  447. if (dst)
  448. SCTP_DEBUG_PRINTK("rt_dst:%u.%u.%u.%u, rt_src:%u.%u.%u.%u\n",
  449. NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_src));
  450. else
  451. SCTP_DEBUG_PRINTK("NO ROUTE\n");
  452. return dst;
  453. }
  454. /* For v4, the source address is cached in the route entry(dst). So no need
  455. * to cache it separately and hence this is an empty routine.
  456. */
  457. static void sctp_v4_get_saddr(struct sctp_association *asoc,
  458. struct dst_entry *dst,
  459. union sctp_addr *daddr,
  460. union sctp_addr *saddr)
  461. {
  462. struct rtable *rt = (struct rtable *)dst;
  463. if (rt) {
  464. saddr->v4.sin_family = AF_INET;
  465. saddr->v4.sin_port = asoc->base.bind_addr.port;
  466. saddr->v4.sin_addr.s_addr = rt->rt_src;
  467. }
  468. }
  469. /* What interface did this skb arrive on? */
  470. static int sctp_v4_skb_iif(const struct sk_buff *skb)
  471. {
  472. return ((struct rtable *)skb->dst)->rt_iif;
  473. }
  474. /* Was this packet marked by Explicit Congestion Notification? */
  475. static int sctp_v4_is_ce(const struct sk_buff *skb)
  476. {
  477. return INET_ECN_is_ce(skb->nh.iph->tos);
  478. }
  479. /* Create and initialize a new sk for the socket returned by accept(). */
  480. static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
  481. struct sctp_association *asoc)
  482. {
  483. struct inet_sock *inet = inet_sk(sk);
  484. struct inet_sock *newinet;
  485. struct sock *newsk = sk_alloc(PF_INET, GFP_KERNEL, sk->sk_prot, 1);
  486. if (!newsk)
  487. goto out;
  488. sock_init_data(NULL, newsk);
  489. newsk->sk_type = SOCK_STREAM;
  490. newsk->sk_no_check = sk->sk_no_check;
  491. newsk->sk_reuse = sk->sk_reuse;
  492. newsk->sk_shutdown = sk->sk_shutdown;
  493. newsk->sk_destruct = inet_sock_destruct;
  494. newsk->sk_family = PF_INET;
  495. newsk->sk_protocol = IPPROTO_SCTP;
  496. newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
  497. sock_reset_flag(newsk, SOCK_ZAPPED);
  498. newinet = inet_sk(newsk);
  499. /* Initialize sk's sport, dport, rcv_saddr and daddr for
  500. * getsockname() and getpeername()
  501. */
  502. newinet->sport = inet->sport;
  503. newinet->saddr = inet->saddr;
  504. newinet->rcv_saddr = inet->rcv_saddr;
  505. newinet->dport = htons(asoc->peer.port);
  506. newinet->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr;
  507. newinet->pmtudisc = inet->pmtudisc;
  508. newinet->id = 0;
  509. newinet->uc_ttl = -1;
  510. newinet->mc_loop = 1;
  511. newinet->mc_ttl = 1;
  512. newinet->mc_index = 0;
  513. newinet->mc_list = NULL;
  514. #ifdef INET_REFCNT_DEBUG
  515. atomic_inc(&inet_sock_nr);
  516. #endif
  517. if (newsk->sk_prot->init(newsk)) {
  518. sk_common_release(newsk);
  519. newsk = NULL;
  520. }
  521. out:
  522. return newsk;
  523. }
  524. /* Map address, empty for v4 family */
  525. static void sctp_v4_addr_v4map(struct sctp_sock *sp, union sctp_addr *addr)
  526. {
  527. /* Empty */
  528. }
  529. /* Dump the v4 addr to the seq file. */
  530. static void sctp_v4_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
  531. {
  532. seq_printf(seq, "%d.%d.%d.%d ", NIPQUAD(addr->v4.sin_addr));
  533. }
  534. /* Event handler for inet address addition/deletion events.
  535. * Basically, whenever there is an event, we re-build our local address list.
  536. */
  537. int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,
  538. void *ptr)
  539. {
  540. unsigned long flags;
  541. sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);
  542. __sctp_free_local_addr_list();
  543. __sctp_get_local_addr_list();
  544. sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);
  545. return NOTIFY_DONE;
  546. }
  547. /*
  548. * Initialize the control inode/socket with a control endpoint data
  549. * structure. This endpoint is reserved exclusively for the OOTB processing.
  550. */
  551. static int sctp_ctl_sock_init(void)
  552. {
  553. int err;
  554. sa_family_t family;
  555. if (sctp_get_pf_specific(PF_INET6))
  556. family = PF_INET6;
  557. else
  558. family = PF_INET;
  559. err = sock_create_kern(family, SOCK_SEQPACKET, IPPROTO_SCTP,
  560. &sctp_ctl_socket);
  561. if (err < 0) {
  562. printk(KERN_ERR
  563. "SCTP: Failed to create the SCTP control socket.\n");
  564. return err;
  565. }
  566. sctp_ctl_socket->sk->sk_allocation = GFP_ATOMIC;
  567. inet_sk(sctp_ctl_socket->sk)->uc_ttl = -1;
  568. return 0;
  569. }
  570. /* Register address family specific functions. */
  571. int sctp_register_af(struct sctp_af *af)
  572. {
  573. switch (af->sa_family) {
  574. case AF_INET:
  575. if (sctp_af_v4_specific)
  576. return 0;
  577. sctp_af_v4_specific = af;
  578. break;
  579. case AF_INET6:
  580. if (sctp_af_v6_specific)
  581. return 0;
  582. sctp_af_v6_specific = af;
  583. break;
  584. default:
  585. return 0;
  586. }
  587. INIT_LIST_HEAD(&af->list);
  588. list_add_tail(&af->list, &sctp_address_families);
  589. return 1;
  590. }
  591. /* Get the table of functions for manipulating a particular address
  592. * family.
  593. */
  594. struct sctp_af *sctp_get_af_specific(sa_family_t family)
  595. {
  596. switch (family) {
  597. case AF_INET:
  598. return sctp_af_v4_specific;
  599. case AF_INET6:
  600. return sctp_af_v6_specific;
  601. default:
  602. return NULL;
  603. }
  604. }
  605. /* Common code to initialize a AF_INET msg_name. */
  606. static void sctp_inet_msgname(char *msgname, int *addr_len)
  607. {
  608. struct sockaddr_in *sin;
  609. sin = (struct sockaddr_in *)msgname;
  610. *addr_len = sizeof(struct sockaddr_in);
  611. sin->sin_family = AF_INET;
  612. memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
  613. }
  614. /* Copy the primary address of the peer primary address as the msg_name. */
  615. static void sctp_inet_event_msgname(struct sctp_ulpevent *event, char *msgname,
  616. int *addr_len)
  617. {
  618. struct sockaddr_in *sin, *sinfrom;
  619. if (msgname) {
  620. struct sctp_association *asoc;
  621. asoc = event->asoc;
  622. sctp_inet_msgname(msgname, addr_len);
  623. sin = (struct sockaddr_in *)msgname;
  624. sinfrom = &asoc->peer.primary_addr.v4;
  625. sin->sin_port = htons(asoc->peer.port);
  626. sin->sin_addr.s_addr = sinfrom->sin_addr.s_addr;
  627. }
  628. }
  629. /* Initialize and copy out a msgname from an inbound skb. */
  630. static void sctp_inet_skb_msgname(struct sk_buff *skb, char *msgname, int *len)
  631. {
  632. struct sctphdr *sh;
  633. struct sockaddr_in *sin;
  634. if (msgname) {
  635. sctp_inet_msgname(msgname, len);
  636. sin = (struct sockaddr_in *)msgname;
  637. sh = (struct sctphdr *)skb->h.raw;
  638. sin->sin_port = sh->source;
  639. sin->sin_addr.s_addr = skb->nh.iph->saddr;
  640. }
  641. }
  642. /* Do we support this AF? */
  643. static int sctp_inet_af_supported(sa_family_t family, struct sctp_sock *sp)
  644. {
  645. /* PF_INET only supports AF_INET addresses. */
  646. return (AF_INET == family);
  647. }
  648. /* Address matching with wildcards allowed. */
  649. static int sctp_inet_cmp_addr(const union sctp_addr *addr1,
  650. const union sctp_addr *addr2,
  651. struct sctp_sock *opt)
  652. {
  653. /* PF_INET only supports AF_INET addresses. */
  654. if (addr1->sa.sa_family != addr2->sa.sa_family)
  655. return 0;
  656. if (INADDR_ANY == addr1->v4.sin_addr.s_addr ||
  657. INADDR_ANY == addr2->v4.sin_addr.s_addr)
  658. return 1;
  659. if (addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr)
  660. return 1;
  661. return 0;
  662. }
  663. /* Verify that provided sockaddr looks bindable. Common verification has
  664. * already been taken care of.
  665. */
  666. static int sctp_inet_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
  667. {
  668. return sctp_v4_available(addr, opt);
  669. }
  670. /* Verify that sockaddr looks sendable. Common verification has already
  671. * been taken care of.
  672. */
  673. static int sctp_inet_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
  674. {
  675. return 1;
  676. }
  677. /* Fill in Supported Address Type information for INIT and INIT-ACK
  678. * chunks. Returns number of addresses supported.
  679. */
  680. static int sctp_inet_supported_addrs(const struct sctp_sock *opt,
  681. __u16 *types)
  682. {
  683. types[0] = SCTP_PARAM_IPV4_ADDRESS;
  684. return 1;
  685. }
  686. /* Wrapper routine that calls the ip transmit routine. */
  687. static inline int sctp_v4_xmit(struct sk_buff *skb,
  688. struct sctp_transport *transport, int ipfragok)
  689. {
  690. SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, "
  691. "src:%u.%u.%u.%u, dst:%u.%u.%u.%u\n",
  692. __FUNCTION__, skb, skb->len,
  693. NIPQUAD(((struct rtable *)skb->dst)->rt_src),
  694. NIPQUAD(((struct rtable *)skb->dst)->rt_dst));
  695. SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS);
  696. return ip_queue_xmit(skb, ipfragok);
  697. }
  698. static struct sctp_af sctp_ipv4_specific;
  699. static struct sctp_pf sctp_pf_inet = {
  700. .event_msgname = sctp_inet_event_msgname,
  701. .skb_msgname = sctp_inet_skb_msgname,
  702. .af_supported = sctp_inet_af_supported,
  703. .cmp_addr = sctp_inet_cmp_addr,
  704. .bind_verify = sctp_inet_bind_verify,
  705. .send_verify = sctp_inet_send_verify,
  706. .supported_addrs = sctp_inet_supported_addrs,
  707. .create_accept_sk = sctp_v4_create_accept_sk,
  708. .addr_v4map = sctp_v4_addr_v4map,
  709. .af = &sctp_ipv4_specific,
  710. };
  711. /* Notifier for inetaddr addition/deletion events. */
  712. static struct notifier_block sctp_inetaddr_notifier = {
  713. .notifier_call = sctp_inetaddr_event,
  714. };
  715. /* Socket operations. */
  716. static struct proto_ops inet_seqpacket_ops = {
  717. .family = PF_INET,
  718. .owner = THIS_MODULE,
  719. .release = inet_release, /* Needs to be wrapped... */
  720. .bind = inet_bind,
  721. .connect = inet_dgram_connect,
  722. .socketpair = sock_no_socketpair,
  723. .accept = inet_accept,
  724. .getname = inet_getname, /* Semantics are different. */
  725. .poll = sctp_poll,
  726. .ioctl = inet_ioctl,
  727. .listen = sctp_inet_listen,
  728. .shutdown = inet_shutdown, /* Looks harmless. */
  729. .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem. */
  730. .getsockopt = sock_common_getsockopt,
  731. .sendmsg = inet_sendmsg,
  732. .recvmsg = sock_common_recvmsg,
  733. .mmap = sock_no_mmap,
  734. .sendpage = sock_no_sendpage,
  735. };
  736. /* Registration with AF_INET family. */
  737. static struct inet_protosw sctp_seqpacket_protosw = {
  738. .type = SOCK_SEQPACKET,
  739. .protocol = IPPROTO_SCTP,
  740. .prot = &sctp_prot,
  741. .ops = &inet_seqpacket_ops,
  742. .capability = -1,
  743. .no_check = 0,
  744. .flags = SCTP_PROTOSW_FLAG
  745. };
  746. static struct inet_protosw sctp_stream_protosw = {
  747. .type = SOCK_STREAM,
  748. .protocol = IPPROTO_SCTP,
  749. .prot = &sctp_prot,
  750. .ops = &inet_seqpacket_ops,
  751. .capability = -1,
  752. .no_check = 0,
  753. .flags = SCTP_PROTOSW_FLAG
  754. };
  755. /* Register with IP layer. */
  756. static struct net_protocol sctp_protocol = {
  757. .handler = sctp_rcv,
  758. .err_handler = sctp_v4_err,
  759. .no_policy = 1,
  760. };
  761. /* IPv4 address related functions. */
  762. static struct sctp_af sctp_ipv4_specific = {
  763. .sctp_xmit = sctp_v4_xmit,
  764. .setsockopt = ip_setsockopt,
  765. .getsockopt = ip_getsockopt,
  766. .get_dst = sctp_v4_get_dst,
  767. .get_saddr = sctp_v4_get_saddr,
  768. .copy_addrlist = sctp_v4_copy_addrlist,
  769. .from_skb = sctp_v4_from_skb,
  770. .from_sk = sctp_v4_from_sk,
  771. .to_sk_saddr = sctp_v4_to_sk_saddr,
  772. .to_sk_daddr = sctp_v4_to_sk_daddr,
  773. .from_addr_param= sctp_v4_from_addr_param,
  774. .to_addr_param = sctp_v4_to_addr_param,
  775. .dst_saddr = sctp_v4_dst_saddr,
  776. .cmp_addr = sctp_v4_cmp_addr,
  777. .addr_valid = sctp_v4_addr_valid,
  778. .inaddr_any = sctp_v4_inaddr_any,
  779. .is_any = sctp_v4_is_any,
  780. .available = sctp_v4_available,
  781. .scope = sctp_v4_scope,
  782. .skb_iif = sctp_v4_skb_iif,
  783. .is_ce = sctp_v4_is_ce,
  784. .seq_dump_addr = sctp_v4_seq_dump_addr,
  785. .net_header_len = sizeof(struct iphdr),
  786. .sockaddr_len = sizeof(struct sockaddr_in),
  787. .sa_family = AF_INET,
  788. };
  789. struct sctp_pf *sctp_get_pf_specific(sa_family_t family) {
  790. switch (family) {
  791. case PF_INET:
  792. return sctp_pf_inet_specific;
  793. case PF_INET6:
  794. return sctp_pf_inet6_specific;
  795. default:
  796. return NULL;
  797. }
  798. }
  799. /* Register the PF specific function table. */
  800. int sctp_register_pf(struct sctp_pf *pf, sa_family_t family)
  801. {
  802. switch (family) {
  803. case PF_INET:
  804. if (sctp_pf_inet_specific)
  805. return 0;
  806. sctp_pf_inet_specific = pf;
  807. break;
  808. case PF_INET6:
  809. if (sctp_pf_inet6_specific)
  810. return 0;
  811. sctp_pf_inet6_specific = pf;
  812. break;
  813. default:
  814. return 0;
  815. }
  816. return 1;
  817. }
  818. static int __init init_sctp_mibs(void)
  819. {
  820. sctp_statistics[0] = alloc_percpu(struct sctp_mib);
  821. if (!sctp_statistics[0])
  822. return -ENOMEM;
  823. sctp_statistics[1] = alloc_percpu(struct sctp_mib);
  824. if (!sctp_statistics[1]) {
  825. free_percpu(sctp_statistics[0]);
  826. return -ENOMEM;
  827. }
  828. return 0;
  829. }
  830. static void cleanup_sctp_mibs(void)
  831. {
  832. free_percpu(sctp_statistics[0]);
  833. free_percpu(sctp_statistics[1]);
  834. }
  835. /* Initialize the universe into something sensible. */
  836. SCTP_STATIC __init int sctp_init(void)
  837. {
  838. int i;
  839. int status = -EINVAL;
  840. unsigned long goal;
  841. int order;
  842. /* SCTP_DEBUG sanity check. */
  843. if (!sctp_sanity_check())
  844. goto out;
  845. status = proto_register(&sctp_prot, 1);
  846. if (status)
  847. goto out;
  848. /* Add SCTP to inet_protos hash table. */
  849. status = -EAGAIN;
  850. if (inet_add_protocol(&sctp_protocol, IPPROTO_SCTP) < 0)
  851. goto err_add_protocol;
  852. /* Add SCTP(TCP and UDP style) to inetsw linked list. */
  853. inet_register_protosw(&sctp_seqpacket_protosw);
  854. inet_register_protosw(&sctp_stream_protosw);
  855. /* Allocate a cache pools. */
  856. status = -ENOBUFS;
  857. sctp_bucket_cachep = kmem_cache_create("sctp_bind_bucket",
  858. sizeof(struct sctp_bind_bucket),
  859. 0, SLAB_HWCACHE_ALIGN,
  860. NULL, NULL);
  861. if (!sctp_bucket_cachep)
  862. goto err_bucket_cachep;
  863. sctp_chunk_cachep = kmem_cache_create("sctp_chunk",
  864. sizeof(struct sctp_chunk),
  865. 0, SLAB_HWCACHE_ALIGN,
  866. NULL, NULL);
  867. if (!sctp_chunk_cachep)
  868. goto err_chunk_cachep;
  869. /* Allocate and initialise sctp mibs. */
  870. status = init_sctp_mibs();
  871. if (status)
  872. goto err_init_mibs;
  873. /* Initialize proc fs directory. */
  874. status = sctp_proc_init();
  875. if (status)
  876. goto err_init_proc;
  877. /* Initialize object count debugging. */
  878. sctp_dbg_objcnt_init();
  879. /* Initialize the SCTP specific PF functions. */
  880. sctp_register_pf(&sctp_pf_inet, PF_INET);
  881. /*
  882. * 14. Suggested SCTP Protocol Parameter Values
  883. */
  884. /* The following protocol parameters are RECOMMENDED: */
  885. /* RTO.Initial - 3 seconds */
  886. sctp_rto_initial = SCTP_RTO_INITIAL;
  887. /* RTO.Min - 1 second */
  888. sctp_rto_min = SCTP_RTO_MIN;
  889. /* RTO.Max - 60 seconds */
  890. sctp_rto_max = SCTP_RTO_MAX;
  891. /* RTO.Alpha - 1/8 */
  892. sctp_rto_alpha = SCTP_RTO_ALPHA;
  893. /* RTO.Beta - 1/4 */
  894. sctp_rto_beta = SCTP_RTO_BETA;
  895. /* Valid.Cookie.Life - 60 seconds */
  896. sctp_valid_cookie_life = 60 * HZ;
  897. /* Whether Cookie Preservative is enabled(1) or not(0) */
  898. sctp_cookie_preserve_enable = 1;
  899. /* Max.Burst - 4 */
  900. sctp_max_burst = SCTP_MAX_BURST;
  901. /* Association.Max.Retrans - 10 attempts
  902. * Path.Max.Retrans - 5 attempts (per destination address)
  903. * Max.Init.Retransmits - 8 attempts
  904. */
  905. sctp_max_retrans_association = 10;
  906. sctp_max_retrans_path = 5;
  907. sctp_max_retrans_init = 8;
  908. /* HB.interval - 30 seconds */
  909. sctp_hb_interval = 30 * HZ;
  910. /* Implementation specific variables. */
  911. /* Initialize default stream count setup information. */
  912. sctp_max_instreams = SCTP_DEFAULT_INSTREAMS;
  913. sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS;
  914. /* Initialize handle used for association ids. */
  915. idr_init(&sctp_assocs_id);
  916. /* Size and allocate the association hash table.
  917. * The methodology is similar to that of the tcp hash tables.
  918. */
  919. if (num_physpages >= (128 * 1024))
  920. goal = num_physpages >> (22 - PAGE_SHIFT);
  921. else
  922. goal = num_physpages >> (24 - PAGE_SHIFT);
  923. for (order = 0; (1UL << order) < goal; order++)
  924. ;
  925. do {
  926. sctp_assoc_hashsize = (1UL << order) * PAGE_SIZE /
  927. sizeof(struct sctp_hashbucket);
  928. if ((sctp_assoc_hashsize > (64 * 1024)) && order > 0)
  929. continue;
  930. sctp_assoc_hashtable = (struct sctp_hashbucket *)
  931. __get_free_pages(GFP_ATOMIC, order);
  932. } while (!sctp_assoc_hashtable && --order > 0);
  933. if (!sctp_assoc_hashtable) {
  934. printk(KERN_ERR "SCTP: Failed association hash alloc.\n");
  935. status = -ENOMEM;
  936. goto err_ahash_alloc;
  937. }
  938. for (i = 0; i < sctp_assoc_hashsize; i++) {
  939. rwlock_init(&sctp_assoc_hashtable[i].lock);
  940. sctp_assoc_hashtable[i].chain = NULL;
  941. }
  942. /* Allocate and initialize the endpoint hash table. */
  943. sctp_ep_hashsize = 64;
  944. sctp_ep_hashtable = (struct sctp_hashbucket *)
  945. kmalloc(64 * sizeof(struct sctp_hashbucket), GFP_KERNEL);
  946. if (!sctp_ep_hashtable) {
  947. printk(KERN_ERR "SCTP: Failed endpoint_hash alloc.\n");
  948. status = -ENOMEM;
  949. goto err_ehash_alloc;
  950. }
  951. for (i = 0; i < sctp_ep_hashsize; i++) {
  952. rwlock_init(&sctp_ep_hashtable[i].lock);
  953. sctp_ep_hashtable[i].chain = NULL;
  954. }
  955. /* Allocate and initialize the SCTP port hash table. */
  956. do {
  957. sctp_port_hashsize = (1UL << order) * PAGE_SIZE /
  958. sizeof(struct sctp_bind_hashbucket);
  959. if ((sctp_port_hashsize > (64 * 1024)) && order > 0)
  960. continue;
  961. sctp_port_hashtable = (struct sctp_bind_hashbucket *)
  962. __get_free_pages(GFP_ATOMIC, order);
  963. } while (!sctp_port_hashtable && --order > 0);
  964. if (!sctp_port_hashtable) {
  965. printk(KERN_ERR "SCTP: Failed bind hash alloc.");
  966. status = -ENOMEM;
  967. goto err_bhash_alloc;
  968. }
  969. for (i = 0; i < sctp_port_hashsize; i++) {
  970. spin_lock_init(&sctp_port_hashtable[i].lock);
  971. sctp_port_hashtable[i].chain = NULL;
  972. }
  973. spin_lock_init(&sctp_port_alloc_lock);
  974. sctp_port_rover = sysctl_local_port_range[0] - 1;
  975. printk(KERN_INFO "SCTP: Hash tables configured "
  976. "(established %d bind %d)\n",
  977. sctp_assoc_hashsize, sctp_port_hashsize);
  978. /* Disable ADDIP by default. */
  979. sctp_addip_enable = 0;
  980. /* Enable PR-SCTP by default. */
  981. sctp_prsctp_enable = 1;
  982. sctp_sysctl_register();
  983. INIT_LIST_HEAD(&sctp_address_families);
  984. sctp_register_af(&sctp_ipv4_specific);
  985. status = sctp_v6_init();
  986. if (status)
  987. goto err_v6_init;
  988. /* Initialize the control inode/socket for handling OOTB packets. */
  989. if ((status = sctp_ctl_sock_init())) {
  990. printk (KERN_ERR
  991. "SCTP: Failed to initialize the SCTP control sock.\n");
  992. goto err_ctl_sock_init;
  993. }
  994. /* Initialize the local address list. */
  995. INIT_LIST_HEAD(&sctp_local_addr_list);
  996. spin_lock_init(&sctp_local_addr_lock);
  997. /* Register notifier for inet address additions/deletions. */
  998. register_inetaddr_notifier(&sctp_inetaddr_notifier);
  999. sctp_get_local_addr_list();
  1000. __unsafe(THIS_MODULE);
  1001. status = 0;
  1002. out:
  1003. return status;
  1004. err_add_protocol:
  1005. proto_unregister(&sctp_prot);
  1006. err_ctl_sock_init:
  1007. sctp_v6_exit();
  1008. err_v6_init:
  1009. sctp_sysctl_unregister();
  1010. list_del(&sctp_ipv4_specific.list);
  1011. free_pages((unsigned long)sctp_port_hashtable,
  1012. get_order(sctp_port_hashsize *
  1013. sizeof(struct sctp_bind_hashbucket)));
  1014. err_bhash_alloc:
  1015. kfree(sctp_ep_hashtable);
  1016. err_ehash_alloc:
  1017. free_pages((unsigned long)sctp_assoc_hashtable,
  1018. get_order(sctp_assoc_hashsize *
  1019. sizeof(struct sctp_hashbucket)));
  1020. err_ahash_alloc:
  1021. sctp_dbg_objcnt_exit();
  1022. err_init_proc:
  1023. sctp_proc_exit();
  1024. cleanup_sctp_mibs();
  1025. err_init_mibs:
  1026. kmem_cache_destroy(sctp_chunk_cachep);
  1027. err_chunk_cachep:
  1028. kmem_cache_destroy(sctp_bucket_cachep);
  1029. err_bucket_cachep:
  1030. inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
  1031. inet_unregister_protosw(&sctp_seqpacket_protosw);
  1032. inet_unregister_protosw(&sctp_stream_protosw);
  1033. goto out;
  1034. }
  1035. /* Exit handler for the SCTP protocol. */
  1036. SCTP_STATIC __exit void sctp_exit(void)
  1037. {
  1038. /* BUG. This should probably do something useful like clean
  1039. * up all the remaining associations and all that memory.
  1040. */
  1041. /* Unregister notifier for inet address additions/deletions. */
  1042. unregister_inetaddr_notifier(&sctp_inetaddr_notifier);
  1043. /* Free the local address list. */
  1044. sctp_free_local_addr_list();
  1045. /* Free the control endpoint. */
  1046. sock_release(sctp_ctl_socket);
  1047. sctp_v6_exit();
  1048. sctp_sysctl_unregister();
  1049. list_del(&sctp_ipv4_specific.list);
  1050. free_pages((unsigned long)sctp_assoc_hashtable,
  1051. get_order(sctp_assoc_hashsize *
  1052. sizeof(struct sctp_hashbucket)));
  1053. kfree(sctp_ep_hashtable);
  1054. free_pages((unsigned long)sctp_port_hashtable,
  1055. get_order(sctp_port_hashsize *
  1056. sizeof(struct sctp_bind_hashbucket)));
  1057. kmem_cache_destroy(sctp_chunk_cachep);
  1058. kmem_cache_destroy(sctp_bucket_cachep);
  1059. sctp_dbg_objcnt_exit();
  1060. sctp_proc_exit();
  1061. cleanup_sctp_mibs();
  1062. inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
  1063. inet_unregister_protosw(&sctp_seqpacket_protosw);
  1064. inet_unregister_protosw(&sctp_stream_protosw);
  1065. proto_unregister(&sctp_prot);
  1066. }
  1067. module_init(sctp_init);
  1068. module_exit(sctp_exit);
  1069. MODULE_AUTHOR("Linux Kernel SCTP developers <lksctp-developers@lists.sourceforge.net>");
  1070. MODULE_DESCRIPTION("Support for the SCTP protocol (RFC2960)");
  1071. MODULE_LICENSE("GPL");