protocol.c 34 KB

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