protocol.c 34 KB

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