protocol.c 34 KB

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