protocol.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  1. /* SCTP kernel reference Implementation
  2. * (C) Copyright IBM Corp. 2001, 2004
  3. * Copyright (c) 1999-2000 Cisco, Inc.
  4. * Copyright (c) 1999-2001 Motorola, Inc.
  5. * Copyright (c) 2001 Intel Corp.
  6. * Copyright (c) 2001 Nokia, Inc.
  7. * Copyright (c) 2001 La Monte H.P. Yarroll
  8. *
  9. * This file is part of the SCTP kernel reference Implementation
  10. *
  11. * Initialization/cleanup for SCTP protocol support.
  12. *
  13. * The SCTP reference implementation is free software;
  14. * you can redistribute it and/or modify it under the terms of
  15. * the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2, or (at your option)
  17. * any later version.
  18. *
  19. * The SCTP reference implementation is distributed in the hope that it
  20. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  21. * ************************
  22. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  23. * See the GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with GNU CC; see the file COPYING. If not, write to
  27. * the Free Software Foundation, 59 Temple Place - Suite 330,
  28. * Boston, MA 02111-1307, USA.
  29. *
  30. * Please send any bug reports or fixes you make to the
  31. * email address(es):
  32. * lksctp developers <lksctp-developers@lists.sourceforge.net>
  33. *
  34. * Or submit a bug report through the following website:
  35. * http://www.sf.net/projects/lksctp
  36. *
  37. * Written or modified by:
  38. * La Monte H.P. Yarroll <piggy@acm.org>
  39. * Karl Knutson <karl@athena.chicago.il.us>
  40. * Jon Grimm <jgrimm@us.ibm.com>
  41. * Sridhar Samudrala <sri@us.ibm.com>
  42. * Daisy Chang <daisyc@us.ibm.com>
  43. * Ardelle Fan <ardelle.fan@intel.com>
  44. *
  45. * Any bugs reported given to us we will try to fix... any fixes shared will
  46. * be incorporated into the next SCTP release.
  47. */
  48. #include <linux/module.h>
  49. #include <linux/init.h>
  50. #include <linux/netdevice.h>
  51. #include <linux/inetdevice.h>
  52. #include <linux/seq_file.h>
  53. #include <net/protocol.h>
  54. #include <net/ip.h>
  55. #include <net/ipv6.h>
  56. #include <net/sctp/sctp.h>
  57. #include <net/addrconf.h>
  58. #include <net/inet_common.h>
  59. #include <net/inet_ecn.h>
  60. /* Global data structures. */
  61. struct sctp_globals sctp_globals;
  62. struct proc_dir_entry *proc_net_sctp;
  63. DEFINE_SNMP_STAT(struct sctp_mib, sctp_statistics) __read_mostly;
  64. struct idr sctp_assocs_id;
  65. DEFINE_SPINLOCK(sctp_assocs_id_lock);
  66. /* This is the global socket data structure used for responding to
  67. * the Out-of-the-blue (OOTB) packets. A control sock will be created
  68. * for this socket at the initialization time.
  69. */
  70. static struct socket *sctp_ctl_socket;
  71. static struct sctp_pf *sctp_pf_inet6_specific;
  72. static struct sctp_pf *sctp_pf_inet_specific;
  73. static struct sctp_af *sctp_af_v4_specific;
  74. static struct sctp_af *sctp_af_v6_specific;
  75. kmem_cache_t *sctp_chunk_cachep __read_mostly;
  76. kmem_cache_t *sctp_bucket_cachep __read_mostly;
  77. extern int sctp_snmp_proc_init(void);
  78. extern int sctp_snmp_proc_exit(void);
  79. extern int sctp_eps_proc_init(void);
  80. extern int sctp_eps_proc_exit(void);
  81. extern int sctp_assocs_proc_init(void);
  82. extern int sctp_assocs_proc_exit(void);
  83. /* Return the address of the control sock. */
  84. struct sock *sctp_get_ctl_sock(void)
  85. {
  86. return sctp_ctl_socket->sk;
  87. }
  88. /* Set up the proc fs entry for the SCTP protocol. */
  89. static __init int sctp_proc_init(void)
  90. {
  91. if (!proc_net_sctp) {
  92. struct proc_dir_entry *ent;
  93. ent = proc_mkdir("net/sctp", NULL);
  94. if (ent) {
  95. ent->owner = THIS_MODULE;
  96. proc_net_sctp = ent;
  97. } else
  98. goto out_nomem;
  99. }
  100. if (sctp_snmp_proc_init())
  101. goto out_nomem;
  102. if (sctp_eps_proc_init())
  103. goto out_nomem;
  104. if (sctp_assocs_proc_init())
  105. goto out_nomem;
  106. return 0;
  107. out_nomem:
  108. return -ENOMEM;
  109. }
  110. /* Clean up the proc fs entry for the SCTP protocol.
  111. * Note: Do not make this __exit as it is used in the init error
  112. * path.
  113. */
  114. static void sctp_proc_exit(void)
  115. {
  116. sctp_snmp_proc_exit();
  117. sctp_eps_proc_exit();
  118. sctp_assocs_proc_exit();
  119. if (proc_net_sctp) {
  120. proc_net_sctp = NULL;
  121. remove_proc_entry("net/sctp", NULL);
  122. }
  123. }
  124. /* Private helper to extract ipv4 address and stash them in
  125. * the protocol structure.
  126. */
  127. static void sctp_v4_copy_addrlist(struct list_head *addrlist,
  128. struct net_device *dev)
  129. {
  130. struct in_device *in_dev;
  131. struct in_ifaddr *ifa;
  132. struct sctp_sockaddr_entry *addr;
  133. rcu_read_lock();
  134. if ((in_dev = __in_dev_get(dev)) == NULL) {
  135. rcu_read_unlock();
  136. return;
  137. }
  138. for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
  139. /* Add the address to the local list. */
  140. addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC);
  141. if (addr) {
  142. addr->a.v4.sin_family = AF_INET;
  143. addr->a.v4.sin_port = 0;
  144. addr->a.v4.sin_addr.s_addr = ifa->ifa_local;
  145. list_add_tail(&addr->list, addrlist);
  146. }
  147. }
  148. rcu_read_unlock();
  149. }
  150. /* Extract our IP addresses from the system and stash them in the
  151. * protocol structure.
  152. */
  153. static void __sctp_get_local_addr_list(void)
  154. {
  155. struct net_device *dev;
  156. struct list_head *pos;
  157. struct sctp_af *af;
  158. read_lock(&dev_base_lock);
  159. for (dev = dev_base; dev; dev = dev->next) {
  160. __list_for_each(pos, &sctp_address_families) {
  161. af = list_entry(pos, struct sctp_af, list);
  162. af->copy_addrlist(&sctp_local_addr_list, dev);
  163. }
  164. }
  165. read_unlock(&dev_base_lock);
  166. }
  167. static void sctp_get_local_addr_list(void)
  168. {
  169. unsigned long flags;
  170. sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);
  171. __sctp_get_local_addr_list();
  172. sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);
  173. }
  174. /* Free the existing local addresses. */
  175. static void __sctp_free_local_addr_list(void)
  176. {
  177. struct sctp_sockaddr_entry *addr;
  178. struct list_head *pos, *temp;
  179. list_for_each_safe(pos, temp, &sctp_local_addr_list) {
  180. addr = list_entry(pos, struct sctp_sockaddr_entry, list);
  181. list_del(pos);
  182. kfree(addr);
  183. }
  184. }
  185. /* Free the existing local addresses. */
  186. static void sctp_free_local_addr_list(void)
  187. {
  188. unsigned long flags;
  189. sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);
  190. __sctp_free_local_addr_list();
  191. sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);
  192. }
  193. /* Copy the local addresses which are valid for 'scope' into 'bp'. */
  194. int sctp_copy_local_addr_list(struct sctp_bind_addr *bp, sctp_scope_t scope,
  195. unsigned int __nocast gfp, int copy_flags)
  196. {
  197. struct sctp_sockaddr_entry *addr;
  198. int error = 0;
  199. struct list_head *pos;
  200. unsigned long flags;
  201. sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags);
  202. list_for_each(pos, &sctp_local_addr_list) {
  203. addr = list_entry(pos, struct sctp_sockaddr_entry, list);
  204. if (sctp_in_scope(&addr->a, scope)) {
  205. /* Now that the address is in scope, check to see if
  206. * the address type is really supported by the local
  207. * sock as well as the remote peer.
  208. */
  209. if ((((AF_INET == addr->a.sa.sa_family) &&
  210. (copy_flags & SCTP_ADDR4_PEERSUPP))) ||
  211. (((AF_INET6 == addr->a.sa.sa_family) &&
  212. (copy_flags & SCTP_ADDR6_ALLOWED) &&
  213. (copy_flags & SCTP_ADDR6_PEERSUPP)))) {
  214. error = sctp_add_bind_addr(bp, &addr->a,
  215. GFP_ATOMIC);
  216. if (error)
  217. goto end_copy;
  218. }
  219. }
  220. }
  221. end_copy:
  222. sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags);
  223. return error;
  224. }
  225. /* Initialize a sctp_addr from in incoming skb. */
  226. static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb,
  227. int is_saddr)
  228. {
  229. void *from;
  230. __u16 *port;
  231. struct sctphdr *sh;
  232. port = &addr->v4.sin_port;
  233. addr->v4.sin_family = AF_INET;
  234. sh = (struct sctphdr *) skb->h.raw;
  235. if (is_saddr) {
  236. *port = ntohs(sh->source);
  237. from = &skb->nh.iph->saddr;
  238. } else {
  239. *port = ntohs(sh->dest);
  240. from = &skb->nh.iph->daddr;
  241. }
  242. memcpy(&addr->v4.sin_addr.s_addr, from, sizeof(struct in_addr));
  243. }
  244. /* Initialize an sctp_addr from a socket. */
  245. static void sctp_v4_from_sk(union sctp_addr *addr, struct sock *sk)
  246. {
  247. addr->v4.sin_family = AF_INET;
  248. addr->v4.sin_port = inet_sk(sk)->num;
  249. addr->v4.sin_addr.s_addr = inet_sk(sk)->rcv_saddr;
  250. }
  251. /* Initialize sk->sk_rcv_saddr from sctp_addr. */
  252. static void sctp_v4_to_sk_saddr(union sctp_addr *addr, struct sock *sk)
  253. {
  254. inet_sk(sk)->rcv_saddr = addr->v4.sin_addr.s_addr;
  255. }
  256. /* Initialize sk->sk_daddr from sctp_addr. */
  257. static void sctp_v4_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
  258. {
  259. inet_sk(sk)->daddr = addr->v4.sin_addr.s_addr;
  260. }
  261. /* Initialize a sctp_addr from an address parameter. */
  262. static void sctp_v4_from_addr_param(union sctp_addr *addr,
  263. union sctp_addr_param *param,
  264. __u16 port, int iif)
  265. {
  266. addr->v4.sin_family = AF_INET;
  267. addr->v4.sin_port = port;
  268. addr->v4.sin_addr.s_addr = param->v4.addr.s_addr;
  269. }
  270. /* Initialize an address parameter from a sctp_addr and return the length
  271. * of the address parameter.
  272. */
  273. static int sctp_v4_to_addr_param(const union sctp_addr *addr,
  274. union sctp_addr_param *param)
  275. {
  276. int length = sizeof(sctp_ipv4addr_param_t);
  277. param->v4.param_hdr.type = SCTP_PARAM_IPV4_ADDRESS;
  278. param->v4.param_hdr.length = ntohs(length);
  279. param->v4.addr.s_addr = addr->v4.sin_addr.s_addr;
  280. return length;
  281. }
  282. /* Initialize a sctp_addr from a dst_entry. */
  283. static void sctp_v4_dst_saddr(union sctp_addr *saddr, struct dst_entry *dst,
  284. unsigned short port)
  285. {
  286. struct rtable *rt = (struct rtable *)dst;
  287. saddr->v4.sin_family = AF_INET;
  288. saddr->v4.sin_port = port;
  289. saddr->v4.sin_addr.s_addr = rt->rt_src;
  290. }
  291. /* Compare two addresses exactly. */
  292. static int sctp_v4_cmp_addr(const union sctp_addr *addr1,
  293. const union sctp_addr *addr2)
  294. {
  295. if (addr1->sa.sa_family != addr2->sa.sa_family)
  296. return 0;
  297. if (addr1->v4.sin_port != addr2->v4.sin_port)
  298. return 0;
  299. if (addr1->v4.sin_addr.s_addr != addr2->v4.sin_addr.s_addr)
  300. return 0;
  301. return 1;
  302. }
  303. /* Initialize addr struct to INADDR_ANY. */
  304. static void sctp_v4_inaddr_any(union sctp_addr *addr, unsigned short port)
  305. {
  306. addr->v4.sin_family = AF_INET;
  307. addr->v4.sin_addr.s_addr = INADDR_ANY;
  308. addr->v4.sin_port = port;
  309. }
  310. /* Is this a wildcard address? */
  311. static int sctp_v4_is_any(const union sctp_addr *addr)
  312. {
  313. return INADDR_ANY == addr->v4.sin_addr.s_addr;
  314. }
  315. /* This function checks if the address is a valid address to be used for
  316. * SCTP binding.
  317. *
  318. * Output:
  319. * Return 0 - If the address is a non-unicast or an illegal address.
  320. * Return 1 - If the address is a unicast.
  321. */
  322. static int sctp_v4_addr_valid(union sctp_addr *addr, struct sctp_sock *sp)
  323. {
  324. /* Is this a non-unicast address or a unusable SCTP address? */
  325. if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr))
  326. return 0;
  327. return 1;
  328. }
  329. /* Should this be available for binding? */
  330. static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp)
  331. {
  332. int ret = inet_addr_type(addr->v4.sin_addr.s_addr);
  333. if (addr->v4.sin_addr.s_addr != INADDR_ANY &&
  334. ret != RTN_LOCAL &&
  335. !sp->inet.freebind &&
  336. !sysctl_ip_nonlocal_bind)
  337. return 0;
  338. return 1;
  339. }
  340. /* Checking the loopback, private and other address scopes as defined in
  341. * RFC 1918. The IPv4 scoping is based on the draft for SCTP IPv4
  342. * scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
  343. *
  344. * Level 0 - unusable SCTP addresses
  345. * Level 1 - loopback address
  346. * Level 2 - link-local addresses
  347. * Level 3 - private addresses.
  348. * Level 4 - global addresses
  349. * For INIT and INIT-ACK address list, let L be the level of
  350. * of requested destination address, sender and receiver
  351. * SHOULD include all of its addresses with level greater
  352. * than or equal to L.
  353. */
  354. static sctp_scope_t sctp_v4_scope(union sctp_addr *addr)
  355. {
  356. sctp_scope_t retval;
  357. /* Should IPv4 scoping be a sysctl configurable option
  358. * so users can turn it off (default on) for certain
  359. * unconventional networking environments?
  360. */
  361. /* Check for unusable SCTP addresses. */
  362. if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  363. retval = SCTP_SCOPE_UNUSABLE;
  364. } else if (LOOPBACK(addr->v4.sin_addr.s_addr)) {
  365. retval = SCTP_SCOPE_LOOPBACK;
  366. } else if (IS_IPV4_LINK_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  367. retval = SCTP_SCOPE_LINK;
  368. } else if (IS_IPV4_PRIVATE_ADDRESS(&addr->v4.sin_addr.s_addr)) {
  369. retval = SCTP_SCOPE_PRIVATE;
  370. } else {
  371. retval = SCTP_SCOPE_GLOBAL;
  372. }
  373. return retval;
  374. }
  375. /* Returns a valid dst cache entry for the given source and destination ip
  376. * addresses. If an association is passed, trys to get a dst entry with a
  377. * source address that matches an address in the bind address list.
  378. */
  379. static struct dst_entry *sctp_v4_get_dst(struct sctp_association *asoc,
  380. union sctp_addr *daddr,
  381. union sctp_addr *saddr)
  382. {
  383. struct rtable *rt;
  384. struct flowi fl;
  385. struct sctp_bind_addr *bp;
  386. rwlock_t *addr_lock;
  387. struct sctp_sockaddr_entry *laddr;
  388. struct list_head *pos;
  389. struct dst_entry *dst = NULL;
  390. union sctp_addr dst_saddr;
  391. memset(&fl, 0x0, sizeof(struct flowi));
  392. fl.fl4_dst = daddr->v4.sin_addr.s_addr;
  393. fl.proto = IPPROTO_SCTP;
  394. if (asoc) {
  395. fl.fl4_tos = RT_CONN_FLAGS(asoc->base.sk);
  396. fl.oif = asoc->base.sk->sk_bound_dev_if;
  397. }
  398. if (saddr)
  399. fl.fl4_src = saddr->v4.sin_addr.s_addr;
  400. SCTP_DEBUG_PRINTK("%s: DST:%u.%u.%u.%u, SRC:%u.%u.%u.%u - ",
  401. __FUNCTION__, NIPQUAD(fl.fl4_dst),
  402. NIPQUAD(fl.fl4_src));
  403. if (!ip_route_output_key(&rt, &fl)) {
  404. dst = &rt->u.dst;
  405. }
  406. /* If there is no association or if a source address is passed, no
  407. * more validation is required.
  408. */
  409. if (!asoc || saddr)
  410. goto out;
  411. bp = &asoc->base.bind_addr;
  412. addr_lock = &asoc->base.addr_lock;
  413. if (dst) {
  414. /* Walk through the bind address list and look for a bind
  415. * address that matches the source address of the returned dst.
  416. */
  417. sctp_read_lock(addr_lock);
  418. list_for_each(pos, &bp->address_list) {
  419. laddr = list_entry(pos, struct sctp_sockaddr_entry,
  420. list);
  421. sctp_v4_dst_saddr(&dst_saddr, dst, bp->port);
  422. if (sctp_v4_cmp_addr(&dst_saddr, &laddr->a))
  423. goto out_unlock;
  424. }
  425. sctp_read_unlock(addr_lock);
  426. /* None of the bound addresses match the source address of the
  427. * dst. So release it.
  428. */
  429. dst_release(dst);
  430. dst = NULL;
  431. }
  432. /* Walk through the bind address list and try to get a dst that
  433. * matches a bind address as the source address.
  434. */
  435. sctp_read_lock(addr_lock);
  436. list_for_each(pos, &bp->address_list) {
  437. laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
  438. if (AF_INET == laddr->a.sa.sa_family) {
  439. fl.fl4_src = laddr->a.v4.sin_addr.s_addr;
  440. if (!ip_route_output_key(&rt, &fl)) {
  441. dst = &rt->u.dst;
  442. goto out_unlock;
  443. }
  444. }
  445. }
  446. out_unlock:
  447. sctp_read_unlock(addr_lock);
  448. out:
  449. if (dst)
  450. SCTP_DEBUG_PRINTK("rt_dst:%u.%u.%u.%u, rt_src:%u.%u.%u.%u\n",
  451. NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_src));
  452. else
  453. SCTP_DEBUG_PRINTK("NO ROUTE\n");
  454. return dst;
  455. }
  456. /* For v4, the source address is cached in the route entry(dst). So no need
  457. * to cache it separately and hence this is an empty routine.
  458. */
  459. static void sctp_v4_get_saddr(struct sctp_association *asoc,
  460. struct dst_entry *dst,
  461. union sctp_addr *daddr,
  462. union sctp_addr *saddr)
  463. {
  464. struct rtable *rt = (struct rtable *)dst;
  465. if (rt) {
  466. saddr->v4.sin_family = AF_INET;
  467. saddr->v4.sin_port = asoc->base.bind_addr.port;
  468. saddr->v4.sin_addr.s_addr = rt->rt_src;
  469. }
  470. }
  471. /* What interface did this skb arrive on? */
  472. static int sctp_v4_skb_iif(const struct sk_buff *skb)
  473. {
  474. return ((struct rtable *)skb->dst)->rt_iif;
  475. }
  476. /* Was this packet marked by Explicit Congestion Notification? */
  477. static int sctp_v4_is_ce(const struct sk_buff *skb)
  478. {
  479. return INET_ECN_is_ce(skb->nh.iph->tos);
  480. }
  481. /* Create and initialize a new sk for the socket returned by accept(). */
  482. static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
  483. struct sctp_association *asoc)
  484. {
  485. struct inet_sock *inet = inet_sk(sk);
  486. struct inet_sock *newinet;
  487. struct sock *newsk = sk_alloc(PF_INET, GFP_KERNEL, sk->sk_prot, 1);
  488. if (!newsk)
  489. goto out;
  490. sock_init_data(NULL, newsk);
  491. newsk->sk_type = SOCK_STREAM;
  492. newsk->sk_no_check = sk->sk_no_check;
  493. newsk->sk_reuse = sk->sk_reuse;
  494. newsk->sk_shutdown = sk->sk_shutdown;
  495. newsk->sk_destruct = inet_sock_destruct;
  496. newsk->sk_family = PF_INET;
  497. newsk->sk_protocol = IPPROTO_SCTP;
  498. newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
  499. sock_reset_flag(newsk, SOCK_ZAPPED);
  500. newinet = inet_sk(newsk);
  501. /* Initialize sk's sport, dport, rcv_saddr and daddr for
  502. * getsockname() and getpeername()
  503. */
  504. newinet->sport = inet->sport;
  505. newinet->saddr = inet->saddr;
  506. newinet->rcv_saddr = inet->rcv_saddr;
  507. newinet->dport = htons(asoc->peer.port);
  508. newinet->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr;
  509. newinet->pmtudisc = inet->pmtudisc;
  510. newinet->id = 0;
  511. newinet->uc_ttl = -1;
  512. newinet->mc_loop = 1;
  513. newinet->mc_ttl = 1;
  514. newinet->mc_index = 0;
  515. newinet->mc_list = NULL;
  516. sk_refcnt_debug_inc(newsk);
  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. /* Sendbuffer growth - do per-socket accounting */
  909. sctp_sndbuf_policy = 0;
  910. /* HB.interval - 30 seconds */
  911. sctp_hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT;
  912. /* delayed SACK timeout */
  913. sctp_sack_timeout = SCTP_DEFAULT_TIMEOUT_SACK;
  914. /* Implementation specific variables. */
  915. /* Initialize default stream count setup information. */
  916. sctp_max_instreams = SCTP_DEFAULT_INSTREAMS;
  917. sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS;
  918. /* Initialize handle used for association ids. */
  919. idr_init(&sctp_assocs_id);
  920. /* Size and allocate the association hash table.
  921. * The methodology is similar to that of the tcp hash tables.
  922. */
  923. if (num_physpages >= (128 * 1024))
  924. goal = num_physpages >> (22 - PAGE_SHIFT);
  925. else
  926. goal = num_physpages >> (24 - PAGE_SHIFT);
  927. for (order = 0; (1UL << order) < goal; order++)
  928. ;
  929. do {
  930. sctp_assoc_hashsize = (1UL << order) * PAGE_SIZE /
  931. sizeof(struct sctp_hashbucket);
  932. if ((sctp_assoc_hashsize > (64 * 1024)) && order > 0)
  933. continue;
  934. sctp_assoc_hashtable = (struct sctp_hashbucket *)
  935. __get_free_pages(GFP_ATOMIC, order);
  936. } while (!sctp_assoc_hashtable && --order > 0);
  937. if (!sctp_assoc_hashtable) {
  938. printk(KERN_ERR "SCTP: Failed association hash alloc.\n");
  939. status = -ENOMEM;
  940. goto err_ahash_alloc;
  941. }
  942. for (i = 0; i < sctp_assoc_hashsize; i++) {
  943. rwlock_init(&sctp_assoc_hashtable[i].lock);
  944. sctp_assoc_hashtable[i].chain = NULL;
  945. }
  946. /* Allocate and initialize the endpoint hash table. */
  947. sctp_ep_hashsize = 64;
  948. sctp_ep_hashtable = (struct sctp_hashbucket *)
  949. kmalloc(64 * sizeof(struct sctp_hashbucket), GFP_KERNEL);
  950. if (!sctp_ep_hashtable) {
  951. printk(KERN_ERR "SCTP: Failed endpoint_hash alloc.\n");
  952. status = -ENOMEM;
  953. goto err_ehash_alloc;
  954. }
  955. for (i = 0; i < sctp_ep_hashsize; i++) {
  956. rwlock_init(&sctp_ep_hashtable[i].lock);
  957. sctp_ep_hashtable[i].chain = NULL;
  958. }
  959. /* Allocate and initialize the SCTP port hash table. */
  960. do {
  961. sctp_port_hashsize = (1UL << order) * PAGE_SIZE /
  962. sizeof(struct sctp_bind_hashbucket);
  963. if ((sctp_port_hashsize > (64 * 1024)) && order > 0)
  964. continue;
  965. sctp_port_hashtable = (struct sctp_bind_hashbucket *)
  966. __get_free_pages(GFP_ATOMIC, order);
  967. } while (!sctp_port_hashtable && --order > 0);
  968. if (!sctp_port_hashtable) {
  969. printk(KERN_ERR "SCTP: Failed bind hash alloc.");
  970. status = -ENOMEM;
  971. goto err_bhash_alloc;
  972. }
  973. for (i = 0; i < sctp_port_hashsize; i++) {
  974. spin_lock_init(&sctp_port_hashtable[i].lock);
  975. sctp_port_hashtable[i].chain = NULL;
  976. }
  977. spin_lock_init(&sctp_port_alloc_lock);
  978. sctp_port_rover = sysctl_local_port_range[0] - 1;
  979. printk(KERN_INFO "SCTP: Hash tables configured "
  980. "(established %d bind %d)\n",
  981. sctp_assoc_hashsize, sctp_port_hashsize);
  982. /* Disable ADDIP by default. */
  983. sctp_addip_enable = 0;
  984. /* Enable PR-SCTP by default. */
  985. sctp_prsctp_enable = 1;
  986. sctp_sysctl_register();
  987. INIT_LIST_HEAD(&sctp_address_families);
  988. sctp_register_af(&sctp_ipv4_specific);
  989. status = sctp_v6_init();
  990. if (status)
  991. goto err_v6_init;
  992. /* Initialize the control inode/socket for handling OOTB packets. */
  993. if ((status = sctp_ctl_sock_init())) {
  994. printk (KERN_ERR
  995. "SCTP: Failed to initialize the SCTP control sock.\n");
  996. goto err_ctl_sock_init;
  997. }
  998. /* Initialize the local address list. */
  999. INIT_LIST_HEAD(&sctp_local_addr_list);
  1000. spin_lock_init(&sctp_local_addr_lock);
  1001. /* Register notifier for inet address additions/deletions. */
  1002. register_inetaddr_notifier(&sctp_inetaddr_notifier);
  1003. sctp_get_local_addr_list();
  1004. __unsafe(THIS_MODULE);
  1005. status = 0;
  1006. out:
  1007. return status;
  1008. err_ctl_sock_init:
  1009. sctp_v6_exit();
  1010. err_v6_init:
  1011. sctp_sysctl_unregister();
  1012. list_del(&sctp_ipv4_specific.list);
  1013. free_pages((unsigned long)sctp_port_hashtable,
  1014. get_order(sctp_port_hashsize *
  1015. sizeof(struct sctp_bind_hashbucket)));
  1016. err_bhash_alloc:
  1017. kfree(sctp_ep_hashtable);
  1018. err_ehash_alloc:
  1019. free_pages((unsigned long)sctp_assoc_hashtable,
  1020. get_order(sctp_assoc_hashsize *
  1021. sizeof(struct sctp_hashbucket)));
  1022. err_ahash_alloc:
  1023. sctp_dbg_objcnt_exit();
  1024. err_init_proc:
  1025. sctp_proc_exit();
  1026. cleanup_sctp_mibs();
  1027. err_init_mibs:
  1028. kmem_cache_destroy(sctp_chunk_cachep);
  1029. err_chunk_cachep:
  1030. kmem_cache_destroy(sctp_bucket_cachep);
  1031. err_bucket_cachep:
  1032. inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
  1033. inet_unregister_protosw(&sctp_seqpacket_protosw);
  1034. inet_unregister_protosw(&sctp_stream_protosw);
  1035. err_add_protocol:
  1036. proto_unregister(&sctp_prot);
  1037. goto out;
  1038. }
  1039. /* Exit handler for the SCTP protocol. */
  1040. SCTP_STATIC __exit void sctp_exit(void)
  1041. {
  1042. /* BUG. This should probably do something useful like clean
  1043. * up all the remaining associations and all that memory.
  1044. */
  1045. /* Unregister notifier for inet address additions/deletions. */
  1046. unregister_inetaddr_notifier(&sctp_inetaddr_notifier);
  1047. /* Free the local address list. */
  1048. sctp_free_local_addr_list();
  1049. /* Free the control endpoint. */
  1050. sock_release(sctp_ctl_socket);
  1051. sctp_v6_exit();
  1052. sctp_sysctl_unregister();
  1053. list_del(&sctp_ipv4_specific.list);
  1054. free_pages((unsigned long)sctp_assoc_hashtable,
  1055. get_order(sctp_assoc_hashsize *
  1056. sizeof(struct sctp_hashbucket)));
  1057. kfree(sctp_ep_hashtable);
  1058. free_pages((unsigned long)sctp_port_hashtable,
  1059. get_order(sctp_port_hashsize *
  1060. sizeof(struct sctp_bind_hashbucket)));
  1061. kmem_cache_destroy(sctp_chunk_cachep);
  1062. kmem_cache_destroy(sctp_bucket_cachep);
  1063. sctp_dbg_objcnt_exit();
  1064. sctp_proc_exit();
  1065. cleanup_sctp_mibs();
  1066. inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
  1067. inet_unregister_protosw(&sctp_seqpacket_protosw);
  1068. inet_unregister_protosw(&sctp_stream_protosw);
  1069. proto_unregister(&sctp_prot);
  1070. }
  1071. module_init(sctp_init);
  1072. module_exit(sctp_exit);
  1073. /*
  1074. * __stringify doesn't likes enums, so use IPPROTO_SCTP value (132) directly.
  1075. */
  1076. MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132");
  1077. MODULE_AUTHOR("Linux Kernel SCTP developers <lksctp-developers@lists.sourceforge.net>");
  1078. MODULE_DESCRIPTION("Support for the SCTP protocol (RFC2960)");
  1079. MODULE_LICENSE("GPL");