protocol.c 34 KB

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