proto.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. /*
  2. * net/dccp/proto.c
  3. *
  4. * An implementation of the DCCP protocol
  5. * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/dccp.h>
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/sched.h>
  15. #include <linux/kernel.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/in.h>
  19. #include <linux/if_arp.h>
  20. #include <linux/init.h>
  21. #include <linux/random.h>
  22. #include <linux/slab.h>
  23. #include <net/checksum.h>
  24. #include <net/inet_sock.h>
  25. #include <net/inet_common.h>
  26. #include <net/sock.h>
  27. #include <net/xfrm.h>
  28. #include <asm/ioctls.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/timer.h>
  31. #include <linux/delay.h>
  32. #include <linux/poll.h>
  33. #include "ccid.h"
  34. #include "dccp.h"
  35. #include "feat.h"
  36. DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics) __read_mostly;
  37. EXPORT_SYMBOL_GPL(dccp_statistics);
  38. struct percpu_counter dccp_orphan_count;
  39. EXPORT_SYMBOL_GPL(dccp_orphan_count);
  40. struct inet_hashinfo dccp_hashinfo;
  41. EXPORT_SYMBOL_GPL(dccp_hashinfo);
  42. /* the maximum queue length for tx in packets. 0 is no limit */
  43. int sysctl_dccp_tx_qlen __read_mostly = 5;
  44. #ifdef CONFIG_IP_DCCP_DEBUG
  45. static const char *dccp_state_name(const int state)
  46. {
  47. static const char *const dccp_state_names[] = {
  48. [DCCP_OPEN] = "OPEN",
  49. [DCCP_REQUESTING] = "REQUESTING",
  50. [DCCP_PARTOPEN] = "PARTOPEN",
  51. [DCCP_LISTEN] = "LISTEN",
  52. [DCCP_RESPOND] = "RESPOND",
  53. [DCCP_CLOSING] = "CLOSING",
  54. [DCCP_ACTIVE_CLOSEREQ] = "CLOSEREQ",
  55. [DCCP_PASSIVE_CLOSE] = "PASSIVE_CLOSE",
  56. [DCCP_PASSIVE_CLOSEREQ] = "PASSIVE_CLOSEREQ",
  57. [DCCP_TIME_WAIT] = "TIME_WAIT",
  58. [DCCP_CLOSED] = "CLOSED",
  59. };
  60. if (state >= DCCP_MAX_STATES)
  61. return "INVALID STATE!";
  62. else
  63. return dccp_state_names[state];
  64. }
  65. #endif
  66. void dccp_set_state(struct sock *sk, const int state)
  67. {
  68. const int oldstate = sk->sk_state;
  69. dccp_pr_debug("%s(%p) %s --> %s\n", dccp_role(sk), sk,
  70. dccp_state_name(oldstate), dccp_state_name(state));
  71. WARN_ON(state == oldstate);
  72. switch (state) {
  73. case DCCP_OPEN:
  74. if (oldstate != DCCP_OPEN)
  75. DCCP_INC_STATS(DCCP_MIB_CURRESTAB);
  76. /* Client retransmits all Confirm options until entering OPEN */
  77. if (oldstate == DCCP_PARTOPEN)
  78. dccp_feat_list_purge(&dccp_sk(sk)->dccps_featneg);
  79. break;
  80. case DCCP_CLOSED:
  81. if (oldstate == DCCP_OPEN || oldstate == DCCP_ACTIVE_CLOSEREQ ||
  82. oldstate == DCCP_CLOSING)
  83. DCCP_INC_STATS(DCCP_MIB_ESTABRESETS);
  84. sk->sk_prot->unhash(sk);
  85. if (inet_csk(sk)->icsk_bind_hash != NULL &&
  86. !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
  87. inet_put_port(sk);
  88. /* fall through */
  89. default:
  90. if (oldstate == DCCP_OPEN)
  91. DCCP_DEC_STATS(DCCP_MIB_CURRESTAB);
  92. }
  93. /* Change state AFTER socket is unhashed to avoid closed
  94. * socket sitting in hash tables.
  95. */
  96. sk->sk_state = state;
  97. }
  98. EXPORT_SYMBOL_GPL(dccp_set_state);
  99. static void dccp_finish_passive_close(struct sock *sk)
  100. {
  101. switch (sk->sk_state) {
  102. case DCCP_PASSIVE_CLOSE:
  103. /* Node (client or server) has received Close packet. */
  104. dccp_send_reset(sk, DCCP_RESET_CODE_CLOSED);
  105. dccp_set_state(sk, DCCP_CLOSED);
  106. break;
  107. case DCCP_PASSIVE_CLOSEREQ:
  108. /*
  109. * Client received CloseReq. We set the `active' flag so that
  110. * dccp_send_close() retransmits the Close as per RFC 4340, 8.3.
  111. */
  112. dccp_send_close(sk, 1);
  113. dccp_set_state(sk, DCCP_CLOSING);
  114. }
  115. }
  116. void dccp_done(struct sock *sk)
  117. {
  118. dccp_set_state(sk, DCCP_CLOSED);
  119. dccp_clear_xmit_timers(sk);
  120. sk->sk_shutdown = SHUTDOWN_MASK;
  121. if (!sock_flag(sk, SOCK_DEAD))
  122. sk->sk_state_change(sk);
  123. else
  124. inet_csk_destroy_sock(sk);
  125. }
  126. EXPORT_SYMBOL_GPL(dccp_done);
  127. const char *dccp_packet_name(const int type)
  128. {
  129. static const char *const dccp_packet_names[] = {
  130. [DCCP_PKT_REQUEST] = "REQUEST",
  131. [DCCP_PKT_RESPONSE] = "RESPONSE",
  132. [DCCP_PKT_DATA] = "DATA",
  133. [DCCP_PKT_ACK] = "ACK",
  134. [DCCP_PKT_DATAACK] = "DATAACK",
  135. [DCCP_PKT_CLOSEREQ] = "CLOSEREQ",
  136. [DCCP_PKT_CLOSE] = "CLOSE",
  137. [DCCP_PKT_RESET] = "RESET",
  138. [DCCP_PKT_SYNC] = "SYNC",
  139. [DCCP_PKT_SYNCACK] = "SYNCACK",
  140. };
  141. if (type >= DCCP_NR_PKT_TYPES)
  142. return "INVALID";
  143. else
  144. return dccp_packet_names[type];
  145. }
  146. EXPORT_SYMBOL_GPL(dccp_packet_name);
  147. static void dccp_sk_destruct(struct sock *sk)
  148. {
  149. struct dccp_sock *dp = dccp_sk(sk);
  150. ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
  151. dp->dccps_hc_tx_ccid = NULL;
  152. inet_sock_destruct(sk);
  153. }
  154. int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
  155. {
  156. struct dccp_sock *dp = dccp_sk(sk);
  157. struct inet_connection_sock *icsk = inet_csk(sk);
  158. icsk->icsk_rto = DCCP_TIMEOUT_INIT;
  159. icsk->icsk_syn_retries = sysctl_dccp_request_retries;
  160. sk->sk_state = DCCP_CLOSED;
  161. sk->sk_write_space = dccp_write_space;
  162. sk->sk_destruct = dccp_sk_destruct;
  163. icsk->icsk_sync_mss = dccp_sync_mss;
  164. dp->dccps_mss_cache = 536;
  165. dp->dccps_rate_last = jiffies;
  166. dp->dccps_role = DCCP_ROLE_UNDEFINED;
  167. dp->dccps_service = DCCP_SERVICE_CODE_IS_ABSENT;
  168. dp->dccps_tx_qlen = sysctl_dccp_tx_qlen;
  169. dccp_init_xmit_timers(sk);
  170. INIT_LIST_HEAD(&dp->dccps_featneg);
  171. /* control socket doesn't need feat nego */
  172. if (likely(ctl_sock_initialized))
  173. return dccp_feat_init(sk);
  174. return 0;
  175. }
  176. EXPORT_SYMBOL_GPL(dccp_init_sock);
  177. void dccp_destroy_sock(struct sock *sk)
  178. {
  179. struct dccp_sock *dp = dccp_sk(sk);
  180. __skb_queue_purge(&sk->sk_write_queue);
  181. if (sk->sk_send_head != NULL) {
  182. kfree_skb(sk->sk_send_head);
  183. sk->sk_send_head = NULL;
  184. }
  185. /* Clean up a referenced DCCP bind bucket. */
  186. if (inet_csk(sk)->icsk_bind_hash != NULL)
  187. inet_put_port(sk);
  188. kfree(dp->dccps_service_list);
  189. dp->dccps_service_list = NULL;
  190. if (dp->dccps_hc_rx_ackvec != NULL) {
  191. dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
  192. dp->dccps_hc_rx_ackvec = NULL;
  193. }
  194. ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
  195. dp->dccps_hc_rx_ccid = NULL;
  196. /* clean up feature negotiation state */
  197. dccp_feat_list_purge(&dp->dccps_featneg);
  198. }
  199. EXPORT_SYMBOL_GPL(dccp_destroy_sock);
  200. static inline int dccp_listen_start(struct sock *sk, int backlog)
  201. {
  202. struct dccp_sock *dp = dccp_sk(sk);
  203. dp->dccps_role = DCCP_ROLE_LISTEN;
  204. /* do not start to listen if feature negotiation setup fails */
  205. if (dccp_feat_finalise_settings(dp))
  206. return -EPROTO;
  207. return inet_csk_listen_start(sk, backlog);
  208. }
  209. static inline int dccp_need_reset(int state)
  210. {
  211. return state != DCCP_CLOSED && state != DCCP_LISTEN &&
  212. state != DCCP_REQUESTING;
  213. }
  214. int dccp_disconnect(struct sock *sk, int flags)
  215. {
  216. struct inet_connection_sock *icsk = inet_csk(sk);
  217. struct inet_sock *inet = inet_sk(sk);
  218. struct dccp_sock *dp = dccp_sk(sk);
  219. int err = 0;
  220. const int old_state = sk->sk_state;
  221. if (old_state != DCCP_CLOSED)
  222. dccp_set_state(sk, DCCP_CLOSED);
  223. /*
  224. * This corresponds to the ABORT function of RFC793, sec. 3.8
  225. * TCP uses a RST segment, DCCP a Reset packet with Code 2, "Aborted".
  226. */
  227. if (old_state == DCCP_LISTEN) {
  228. inet_csk_listen_stop(sk);
  229. } else if (dccp_need_reset(old_state)) {
  230. dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED);
  231. sk->sk_err = ECONNRESET;
  232. } else if (old_state == DCCP_REQUESTING)
  233. sk->sk_err = ECONNRESET;
  234. dccp_clear_xmit_timers(sk);
  235. ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
  236. dp->dccps_hc_rx_ccid = NULL;
  237. __skb_queue_purge(&sk->sk_receive_queue);
  238. __skb_queue_purge(&sk->sk_write_queue);
  239. if (sk->sk_send_head != NULL) {
  240. __kfree_skb(sk->sk_send_head);
  241. sk->sk_send_head = NULL;
  242. }
  243. inet->inet_dport = 0;
  244. if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK))
  245. inet_reset_saddr(sk);
  246. sk->sk_shutdown = 0;
  247. sock_reset_flag(sk, SOCK_DONE);
  248. icsk->icsk_backoff = 0;
  249. inet_csk_delack_init(sk);
  250. __sk_dst_reset(sk);
  251. WARN_ON(inet->inet_num && !icsk->icsk_bind_hash);
  252. sk->sk_error_report(sk);
  253. return err;
  254. }
  255. EXPORT_SYMBOL_GPL(dccp_disconnect);
  256. /*
  257. * Wait for a DCCP event.
  258. *
  259. * Note that we don't need to lock the socket, as the upper poll layers
  260. * take care of normal races (between the test and the event) and we don't
  261. * go look at any of the socket buffers directly.
  262. */
  263. unsigned int dccp_poll(struct file *file, struct socket *sock,
  264. poll_table *wait)
  265. {
  266. unsigned int mask;
  267. struct sock *sk = sock->sk;
  268. sock_poll_wait(file, sk_sleep(sk), wait);
  269. if (sk->sk_state == DCCP_LISTEN)
  270. return inet_csk_listen_poll(sk);
  271. /* Socket is not locked. We are protected from async events
  272. by poll logic and correct handling of state changes
  273. made by another threads is impossible in any case.
  274. */
  275. mask = 0;
  276. if (sk->sk_err)
  277. mask = POLLERR;
  278. if (sk->sk_shutdown == SHUTDOWN_MASK || sk->sk_state == DCCP_CLOSED)
  279. mask |= POLLHUP;
  280. if (sk->sk_shutdown & RCV_SHUTDOWN)
  281. mask |= POLLIN | POLLRDNORM | POLLRDHUP;
  282. /* Connected? */
  283. if ((1 << sk->sk_state) & ~(DCCPF_REQUESTING | DCCPF_RESPOND)) {
  284. if (atomic_read(&sk->sk_rmem_alloc) > 0)
  285. mask |= POLLIN | POLLRDNORM;
  286. if (!(sk->sk_shutdown & SEND_SHUTDOWN)) {
  287. if (sk_stream_is_writeable(sk)) {
  288. mask |= POLLOUT | POLLWRNORM;
  289. } else { /* send SIGIO later */
  290. sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
  291. set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
  292. /* Race breaker. If space is freed after
  293. * wspace test but before the flags are set,
  294. * IO signal will be lost.
  295. */
  296. if (sk_stream_is_writeable(sk))
  297. mask |= POLLOUT | POLLWRNORM;
  298. }
  299. }
  300. }
  301. return mask;
  302. }
  303. EXPORT_SYMBOL_GPL(dccp_poll);
  304. int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg)
  305. {
  306. int rc = -ENOTCONN;
  307. lock_sock(sk);
  308. if (sk->sk_state == DCCP_LISTEN)
  309. goto out;
  310. switch (cmd) {
  311. case SIOCINQ: {
  312. struct sk_buff *skb;
  313. unsigned long amount = 0;
  314. skb = skb_peek(&sk->sk_receive_queue);
  315. if (skb != NULL) {
  316. /*
  317. * We will only return the amount of this packet since
  318. * that is all that will be read.
  319. */
  320. amount = skb->len;
  321. }
  322. rc = put_user(amount, (int __user *)arg);
  323. }
  324. break;
  325. default:
  326. rc = -ENOIOCTLCMD;
  327. break;
  328. }
  329. out:
  330. release_sock(sk);
  331. return rc;
  332. }
  333. EXPORT_SYMBOL_GPL(dccp_ioctl);
  334. static int dccp_setsockopt_service(struct sock *sk, const __be32 service,
  335. char __user *optval, unsigned int optlen)
  336. {
  337. struct dccp_sock *dp = dccp_sk(sk);
  338. struct dccp_service_list *sl = NULL;
  339. if (service == DCCP_SERVICE_INVALID_VALUE ||
  340. optlen > DCCP_SERVICE_LIST_MAX_LEN * sizeof(u32))
  341. return -EINVAL;
  342. if (optlen > sizeof(service)) {
  343. sl = kmalloc(optlen, GFP_KERNEL);
  344. if (sl == NULL)
  345. return -ENOMEM;
  346. sl->dccpsl_nr = optlen / sizeof(u32) - 1;
  347. if (copy_from_user(sl->dccpsl_list,
  348. optval + sizeof(service),
  349. optlen - sizeof(service)) ||
  350. dccp_list_has_service(sl, DCCP_SERVICE_INVALID_VALUE)) {
  351. kfree(sl);
  352. return -EFAULT;
  353. }
  354. }
  355. lock_sock(sk);
  356. dp->dccps_service = service;
  357. kfree(dp->dccps_service_list);
  358. dp->dccps_service_list = sl;
  359. release_sock(sk);
  360. return 0;
  361. }
  362. static int dccp_setsockopt_cscov(struct sock *sk, int cscov, bool rx)
  363. {
  364. u8 *list, len;
  365. int i, rc;
  366. if (cscov < 0 || cscov > 15)
  367. return -EINVAL;
  368. /*
  369. * Populate a list of permissible values, in the range cscov...15. This
  370. * is necessary since feature negotiation of single values only works if
  371. * both sides incidentally choose the same value. Since the list starts
  372. * lowest-value first, negotiation will pick the smallest shared value.
  373. */
  374. if (cscov == 0)
  375. return 0;
  376. len = 16 - cscov;
  377. list = kmalloc(len, GFP_KERNEL);
  378. if (list == NULL)
  379. return -ENOBUFS;
  380. for (i = 0; i < len; i++)
  381. list[i] = cscov++;
  382. rc = dccp_feat_register_sp(sk, DCCPF_MIN_CSUM_COVER, rx, list, len);
  383. if (rc == 0) {
  384. if (rx)
  385. dccp_sk(sk)->dccps_pcrlen = cscov;
  386. else
  387. dccp_sk(sk)->dccps_pcslen = cscov;
  388. }
  389. kfree(list);
  390. return rc;
  391. }
  392. static int dccp_setsockopt_ccid(struct sock *sk, int type,
  393. char __user *optval, unsigned int optlen)
  394. {
  395. u8 *val;
  396. int rc = 0;
  397. if (optlen < 1 || optlen > DCCP_FEAT_MAX_SP_VALS)
  398. return -EINVAL;
  399. val = memdup_user(optval, optlen);
  400. if (IS_ERR(val))
  401. return PTR_ERR(val);
  402. lock_sock(sk);
  403. if (type == DCCP_SOCKOPT_TX_CCID || type == DCCP_SOCKOPT_CCID)
  404. rc = dccp_feat_register_sp(sk, DCCPF_CCID, 1, val, optlen);
  405. if (!rc && (type == DCCP_SOCKOPT_RX_CCID || type == DCCP_SOCKOPT_CCID))
  406. rc = dccp_feat_register_sp(sk, DCCPF_CCID, 0, val, optlen);
  407. release_sock(sk);
  408. kfree(val);
  409. return rc;
  410. }
  411. static int do_dccp_setsockopt(struct sock *sk, int level, int optname,
  412. char __user *optval, unsigned int optlen)
  413. {
  414. struct dccp_sock *dp = dccp_sk(sk);
  415. int val, err = 0;
  416. switch (optname) {
  417. case DCCP_SOCKOPT_PACKET_SIZE:
  418. DCCP_WARN("sockopt(PACKET_SIZE) is deprecated: fix your app\n");
  419. return 0;
  420. case DCCP_SOCKOPT_CHANGE_L:
  421. case DCCP_SOCKOPT_CHANGE_R:
  422. DCCP_WARN("sockopt(CHANGE_L/R) is deprecated: fix your app\n");
  423. return 0;
  424. case DCCP_SOCKOPT_CCID:
  425. case DCCP_SOCKOPT_RX_CCID:
  426. case DCCP_SOCKOPT_TX_CCID:
  427. return dccp_setsockopt_ccid(sk, optname, optval, optlen);
  428. }
  429. if (optlen < (int)sizeof(int))
  430. return -EINVAL;
  431. if (get_user(val, (int __user *)optval))
  432. return -EFAULT;
  433. if (optname == DCCP_SOCKOPT_SERVICE)
  434. return dccp_setsockopt_service(sk, val, optval, optlen);
  435. lock_sock(sk);
  436. switch (optname) {
  437. case DCCP_SOCKOPT_SERVER_TIMEWAIT:
  438. if (dp->dccps_role != DCCP_ROLE_SERVER)
  439. err = -EOPNOTSUPP;
  440. else
  441. dp->dccps_server_timewait = (val != 0);
  442. break;
  443. case DCCP_SOCKOPT_SEND_CSCOV:
  444. err = dccp_setsockopt_cscov(sk, val, false);
  445. break;
  446. case DCCP_SOCKOPT_RECV_CSCOV:
  447. err = dccp_setsockopt_cscov(sk, val, true);
  448. break;
  449. case DCCP_SOCKOPT_QPOLICY_ID:
  450. if (sk->sk_state != DCCP_CLOSED)
  451. err = -EISCONN;
  452. else if (val < 0 || val >= DCCPQ_POLICY_MAX)
  453. err = -EINVAL;
  454. else
  455. dp->dccps_qpolicy = val;
  456. break;
  457. case DCCP_SOCKOPT_QPOLICY_TXQLEN:
  458. if (val < 0)
  459. err = -EINVAL;
  460. else
  461. dp->dccps_tx_qlen = val;
  462. break;
  463. default:
  464. err = -ENOPROTOOPT;
  465. break;
  466. }
  467. release_sock(sk);
  468. return err;
  469. }
  470. int dccp_setsockopt(struct sock *sk, int level, int optname,
  471. char __user *optval, unsigned int optlen)
  472. {
  473. if (level != SOL_DCCP)
  474. return inet_csk(sk)->icsk_af_ops->setsockopt(sk, level,
  475. optname, optval,
  476. optlen);
  477. return do_dccp_setsockopt(sk, level, optname, optval, optlen);
  478. }
  479. EXPORT_SYMBOL_GPL(dccp_setsockopt);
  480. #ifdef CONFIG_COMPAT
  481. int compat_dccp_setsockopt(struct sock *sk, int level, int optname,
  482. char __user *optval, unsigned int optlen)
  483. {
  484. if (level != SOL_DCCP)
  485. return inet_csk_compat_setsockopt(sk, level, optname,
  486. optval, optlen);
  487. return do_dccp_setsockopt(sk, level, optname, optval, optlen);
  488. }
  489. EXPORT_SYMBOL_GPL(compat_dccp_setsockopt);
  490. #endif
  491. static int dccp_getsockopt_service(struct sock *sk, int len,
  492. __be32 __user *optval,
  493. int __user *optlen)
  494. {
  495. const struct dccp_sock *dp = dccp_sk(sk);
  496. const struct dccp_service_list *sl;
  497. int err = -ENOENT, slen = 0, total_len = sizeof(u32);
  498. lock_sock(sk);
  499. if ((sl = dp->dccps_service_list) != NULL) {
  500. slen = sl->dccpsl_nr * sizeof(u32);
  501. total_len += slen;
  502. }
  503. err = -EINVAL;
  504. if (total_len > len)
  505. goto out;
  506. err = 0;
  507. if (put_user(total_len, optlen) ||
  508. put_user(dp->dccps_service, optval) ||
  509. (sl != NULL && copy_to_user(optval + 1, sl->dccpsl_list, slen)))
  510. err = -EFAULT;
  511. out:
  512. release_sock(sk);
  513. return err;
  514. }
  515. static int do_dccp_getsockopt(struct sock *sk, int level, int optname,
  516. char __user *optval, int __user *optlen)
  517. {
  518. struct dccp_sock *dp;
  519. int val, len;
  520. if (get_user(len, optlen))
  521. return -EFAULT;
  522. if (len < (int)sizeof(int))
  523. return -EINVAL;
  524. dp = dccp_sk(sk);
  525. switch (optname) {
  526. case DCCP_SOCKOPT_PACKET_SIZE:
  527. DCCP_WARN("sockopt(PACKET_SIZE) is deprecated: fix your app\n");
  528. return 0;
  529. case DCCP_SOCKOPT_SERVICE:
  530. return dccp_getsockopt_service(sk, len,
  531. (__be32 __user *)optval, optlen);
  532. case DCCP_SOCKOPT_GET_CUR_MPS:
  533. val = dp->dccps_mss_cache;
  534. break;
  535. case DCCP_SOCKOPT_AVAILABLE_CCIDS:
  536. return ccid_getsockopt_builtin_ccids(sk, len, optval, optlen);
  537. case DCCP_SOCKOPT_TX_CCID:
  538. val = ccid_get_current_tx_ccid(dp);
  539. if (val < 0)
  540. return -ENOPROTOOPT;
  541. break;
  542. case DCCP_SOCKOPT_RX_CCID:
  543. val = ccid_get_current_rx_ccid(dp);
  544. if (val < 0)
  545. return -ENOPROTOOPT;
  546. break;
  547. case DCCP_SOCKOPT_SERVER_TIMEWAIT:
  548. val = dp->dccps_server_timewait;
  549. break;
  550. case DCCP_SOCKOPT_SEND_CSCOV:
  551. val = dp->dccps_pcslen;
  552. break;
  553. case DCCP_SOCKOPT_RECV_CSCOV:
  554. val = dp->dccps_pcrlen;
  555. break;
  556. case DCCP_SOCKOPT_QPOLICY_ID:
  557. val = dp->dccps_qpolicy;
  558. break;
  559. case DCCP_SOCKOPT_QPOLICY_TXQLEN:
  560. val = dp->dccps_tx_qlen;
  561. break;
  562. case 128 ... 191:
  563. return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname,
  564. len, (u32 __user *)optval, optlen);
  565. case 192 ... 255:
  566. return ccid_hc_tx_getsockopt(dp->dccps_hc_tx_ccid, sk, optname,
  567. len, (u32 __user *)optval, optlen);
  568. default:
  569. return -ENOPROTOOPT;
  570. }
  571. len = sizeof(val);
  572. if (put_user(len, optlen) || copy_to_user(optval, &val, len))
  573. return -EFAULT;
  574. return 0;
  575. }
  576. int dccp_getsockopt(struct sock *sk, int level, int optname,
  577. char __user *optval, int __user *optlen)
  578. {
  579. if (level != SOL_DCCP)
  580. return inet_csk(sk)->icsk_af_ops->getsockopt(sk, level,
  581. optname, optval,
  582. optlen);
  583. return do_dccp_getsockopt(sk, level, optname, optval, optlen);
  584. }
  585. EXPORT_SYMBOL_GPL(dccp_getsockopt);
  586. #ifdef CONFIG_COMPAT
  587. int compat_dccp_getsockopt(struct sock *sk, int level, int optname,
  588. char __user *optval, int __user *optlen)
  589. {
  590. if (level != SOL_DCCP)
  591. return inet_csk_compat_getsockopt(sk, level, optname,
  592. optval, optlen);
  593. return do_dccp_getsockopt(sk, level, optname, optval, optlen);
  594. }
  595. EXPORT_SYMBOL_GPL(compat_dccp_getsockopt);
  596. #endif
  597. static int dccp_msghdr_parse(struct msghdr *msg, struct sk_buff *skb)
  598. {
  599. struct cmsghdr *cmsg;
  600. /*
  601. * Assign an (opaque) qpolicy priority value to skb->priority.
  602. *
  603. * We are overloading this skb field for use with the qpolicy subystem.
  604. * The skb->priority is normally used for the SO_PRIORITY option, which
  605. * is initialised from sk_priority. Since the assignment of sk_priority
  606. * to skb->priority happens later (on layer 3), we overload this field
  607. * for use with queueing priorities as long as the skb is on layer 4.
  608. * The default priority value (if nothing is set) is 0.
  609. */
  610. skb->priority = 0;
  611. for_each_cmsghdr(cmsg, msg) {
  612. if (!CMSG_OK(msg, cmsg))
  613. return -EINVAL;
  614. if (cmsg->cmsg_level != SOL_DCCP)
  615. continue;
  616. if (cmsg->cmsg_type <= DCCP_SCM_QPOLICY_MAX &&
  617. !dccp_qpolicy_param_ok(skb->sk, cmsg->cmsg_type))
  618. return -EINVAL;
  619. switch (cmsg->cmsg_type) {
  620. case DCCP_SCM_PRIORITY:
  621. if (cmsg->cmsg_len != CMSG_LEN(sizeof(__u32)))
  622. return -EINVAL;
  623. skb->priority = *(__u32 *)CMSG_DATA(cmsg);
  624. break;
  625. default:
  626. return -EINVAL;
  627. }
  628. }
  629. return 0;
  630. }
  631. int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
  632. {
  633. const struct dccp_sock *dp = dccp_sk(sk);
  634. const int flags = msg->msg_flags;
  635. const int noblock = flags & MSG_DONTWAIT;
  636. struct sk_buff *skb;
  637. int rc, size;
  638. long timeo;
  639. if (len > dp->dccps_mss_cache)
  640. return -EMSGSIZE;
  641. lock_sock(sk);
  642. if (dccp_qpolicy_full(sk)) {
  643. rc = -EAGAIN;
  644. goto out_release;
  645. }
  646. timeo = sock_sndtimeo(sk, noblock);
  647. /*
  648. * We have to use sk_stream_wait_connect here to set sk_write_pending,
  649. * so that the trick in dccp_rcv_request_sent_state_process.
  650. */
  651. /* Wait for a connection to finish. */
  652. if ((1 << sk->sk_state) & ~(DCCPF_OPEN | DCCPF_PARTOPEN))
  653. if ((rc = sk_stream_wait_connect(sk, &timeo)) != 0)
  654. goto out_release;
  655. size = sk->sk_prot->max_header + len;
  656. release_sock(sk);
  657. skb = sock_alloc_send_skb(sk, size, noblock, &rc);
  658. lock_sock(sk);
  659. if (skb == NULL)
  660. goto out_release;
  661. if (sk->sk_state == DCCP_CLOSED) {
  662. rc = -ENOTCONN;
  663. goto out_discard;
  664. }
  665. skb_reserve(skb, sk->sk_prot->max_header);
  666. rc = memcpy_from_msg(skb_put(skb, len), msg, len);
  667. if (rc != 0)
  668. goto out_discard;
  669. rc = dccp_msghdr_parse(msg, skb);
  670. if (rc != 0)
  671. goto out_discard;
  672. dccp_qpolicy_push(sk, skb);
  673. /*
  674. * The xmit_timer is set if the TX CCID is rate-based and will expire
  675. * when congestion control permits to release further packets into the
  676. * network. Window-based CCIDs do not use this timer.
  677. */
  678. if (!timer_pending(&dp->dccps_xmit_timer))
  679. dccp_write_xmit(sk);
  680. out_release:
  681. release_sock(sk);
  682. return rc ? : len;
  683. out_discard:
  684. kfree_skb(skb);
  685. goto out_release;
  686. }
  687. EXPORT_SYMBOL_GPL(dccp_sendmsg);
  688. int dccp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,
  689. int flags, int *addr_len)
  690. {
  691. const struct dccp_hdr *dh;
  692. long timeo;
  693. lock_sock(sk);
  694. if (sk->sk_state == DCCP_LISTEN) {
  695. len = -ENOTCONN;
  696. goto out;
  697. }
  698. timeo = sock_rcvtimeo(sk, nonblock);
  699. do {
  700. struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
  701. if (skb == NULL)
  702. goto verify_sock_status;
  703. dh = dccp_hdr(skb);
  704. switch (dh->dccph_type) {
  705. case DCCP_PKT_DATA:
  706. case DCCP_PKT_DATAACK:
  707. goto found_ok_skb;
  708. case DCCP_PKT_CLOSE:
  709. case DCCP_PKT_CLOSEREQ:
  710. if (!(flags & MSG_PEEK))
  711. dccp_finish_passive_close(sk);
  712. /* fall through */
  713. case DCCP_PKT_RESET:
  714. dccp_pr_debug("found fin (%s) ok!\n",
  715. dccp_packet_name(dh->dccph_type));
  716. len = 0;
  717. goto found_fin_ok;
  718. default:
  719. dccp_pr_debug("packet_type=%s\n",
  720. dccp_packet_name(dh->dccph_type));
  721. sk_eat_skb(sk, skb);
  722. }
  723. verify_sock_status:
  724. if (sock_flag(sk, SOCK_DONE)) {
  725. len = 0;
  726. break;
  727. }
  728. if (sk->sk_err) {
  729. len = sock_error(sk);
  730. break;
  731. }
  732. if (sk->sk_shutdown & RCV_SHUTDOWN) {
  733. len = 0;
  734. break;
  735. }
  736. if (sk->sk_state == DCCP_CLOSED) {
  737. if (!sock_flag(sk, SOCK_DONE)) {
  738. /* This occurs when user tries to read
  739. * from never connected socket.
  740. */
  741. len = -ENOTCONN;
  742. break;
  743. }
  744. len = 0;
  745. break;
  746. }
  747. if (!timeo) {
  748. len = -EAGAIN;
  749. break;
  750. }
  751. if (signal_pending(current)) {
  752. len = sock_intr_errno(timeo);
  753. break;
  754. }
  755. sk_wait_data(sk, &timeo, NULL);
  756. continue;
  757. found_ok_skb:
  758. if (len > skb->len)
  759. len = skb->len;
  760. else if (len < skb->len)
  761. msg->msg_flags |= MSG_TRUNC;
  762. if (skb_copy_datagram_msg(skb, 0, msg, len)) {
  763. /* Exception. Bailout! */
  764. len = -EFAULT;
  765. break;
  766. }
  767. if (flags & MSG_TRUNC)
  768. len = skb->len;
  769. found_fin_ok:
  770. if (!(flags & MSG_PEEK))
  771. sk_eat_skb(sk, skb);
  772. break;
  773. } while (1);
  774. out:
  775. release_sock(sk);
  776. return len;
  777. }
  778. EXPORT_SYMBOL_GPL(dccp_recvmsg);
  779. int inet_dccp_listen(struct socket *sock, int backlog)
  780. {
  781. struct sock *sk = sock->sk;
  782. unsigned char old_state;
  783. int err;
  784. lock_sock(sk);
  785. err = -EINVAL;
  786. if (sock->state != SS_UNCONNECTED || sock->type != SOCK_DCCP)
  787. goto out;
  788. old_state = sk->sk_state;
  789. if (!((1 << old_state) & (DCCPF_CLOSED | DCCPF_LISTEN)))
  790. goto out;
  791. /* Really, if the socket is already in listen state
  792. * we can only allow the backlog to be adjusted.
  793. */
  794. if (old_state != DCCP_LISTEN) {
  795. /*
  796. * FIXME: here it probably should be sk->sk_prot->listen_start
  797. * see tcp_listen_start
  798. */
  799. err = dccp_listen_start(sk, backlog);
  800. if (err)
  801. goto out;
  802. }
  803. sk->sk_max_ack_backlog = backlog;
  804. err = 0;
  805. out:
  806. release_sock(sk);
  807. return err;
  808. }
  809. EXPORT_SYMBOL_GPL(inet_dccp_listen);
  810. static void dccp_terminate_connection(struct sock *sk)
  811. {
  812. u8 next_state = DCCP_CLOSED;
  813. switch (sk->sk_state) {
  814. case DCCP_PASSIVE_CLOSE:
  815. case DCCP_PASSIVE_CLOSEREQ:
  816. dccp_finish_passive_close(sk);
  817. break;
  818. case DCCP_PARTOPEN:
  819. dccp_pr_debug("Stop PARTOPEN timer (%p)\n", sk);
  820. inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
  821. /* fall through */
  822. case DCCP_OPEN:
  823. dccp_send_close(sk, 1);
  824. if (dccp_sk(sk)->dccps_role == DCCP_ROLE_SERVER &&
  825. !dccp_sk(sk)->dccps_server_timewait)
  826. next_state = DCCP_ACTIVE_CLOSEREQ;
  827. else
  828. next_state = DCCP_CLOSING;
  829. /* fall through */
  830. default:
  831. dccp_set_state(sk, next_state);
  832. }
  833. }
  834. void dccp_close(struct sock *sk, long timeout)
  835. {
  836. struct dccp_sock *dp = dccp_sk(sk);
  837. struct sk_buff *skb;
  838. u32 data_was_unread = 0;
  839. int state;
  840. lock_sock(sk);
  841. sk->sk_shutdown = SHUTDOWN_MASK;
  842. if (sk->sk_state == DCCP_LISTEN) {
  843. dccp_set_state(sk, DCCP_CLOSED);
  844. /* Special case. */
  845. inet_csk_listen_stop(sk);
  846. goto adjudge_to_death;
  847. }
  848. sk_stop_timer(sk, &dp->dccps_xmit_timer);
  849. /*
  850. * We need to flush the recv. buffs. We do this only on the
  851. * descriptor close, not protocol-sourced closes, because the
  852. *reader process may not have drained the data yet!
  853. */
  854. while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) {
  855. data_was_unread += skb->len;
  856. __kfree_skb(skb);
  857. }
  858. /* If socket has been already reset kill it. */
  859. if (sk->sk_state == DCCP_CLOSED)
  860. goto adjudge_to_death;
  861. if (data_was_unread) {
  862. /* Unread data was tossed, send an appropriate Reset Code */
  863. DCCP_WARN("ABORT with %u bytes unread\n", data_was_unread);
  864. dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED);
  865. dccp_set_state(sk, DCCP_CLOSED);
  866. } else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
  867. /* Check zero linger _after_ checking for unread data. */
  868. sk->sk_prot->disconnect(sk, 0);
  869. } else if (sk->sk_state != DCCP_CLOSED) {
  870. /*
  871. * Normal connection termination. May need to wait if there are
  872. * still packets in the TX queue that are delayed by the CCID.
  873. */
  874. dccp_flush_write_queue(sk, &timeout);
  875. dccp_terminate_connection(sk);
  876. }
  877. /*
  878. * Flush write queue. This may be necessary in several cases:
  879. * - we have been closed by the peer but still have application data;
  880. * - abortive termination (unread data or zero linger time),
  881. * - normal termination but queue could not be flushed within time limit
  882. */
  883. __skb_queue_purge(&sk->sk_write_queue);
  884. sk_stream_wait_close(sk, timeout);
  885. adjudge_to_death:
  886. state = sk->sk_state;
  887. sock_hold(sk);
  888. sock_orphan(sk);
  889. /*
  890. * It is the last release_sock in its life. It will remove backlog.
  891. */
  892. release_sock(sk);
  893. /*
  894. * Now socket is owned by kernel and we acquire BH lock
  895. * to finish close. No need to check for user refs.
  896. */
  897. local_bh_disable();
  898. bh_lock_sock(sk);
  899. WARN_ON(sock_owned_by_user(sk));
  900. percpu_counter_inc(sk->sk_prot->orphan_count);
  901. /* Have we already been destroyed by a softirq or backlog? */
  902. if (state != DCCP_CLOSED && sk->sk_state == DCCP_CLOSED)
  903. goto out;
  904. if (sk->sk_state == DCCP_CLOSED)
  905. inet_csk_destroy_sock(sk);
  906. /* Otherwise, socket is reprieved until protocol close. */
  907. out:
  908. bh_unlock_sock(sk);
  909. local_bh_enable();
  910. sock_put(sk);
  911. }
  912. EXPORT_SYMBOL_GPL(dccp_close);
  913. void dccp_shutdown(struct sock *sk, int how)
  914. {
  915. dccp_pr_debug("called shutdown(%x)\n", how);
  916. }
  917. EXPORT_SYMBOL_GPL(dccp_shutdown);
  918. static inline int __init dccp_mib_init(void)
  919. {
  920. dccp_statistics = alloc_percpu(struct dccp_mib);
  921. if (!dccp_statistics)
  922. return -ENOMEM;
  923. return 0;
  924. }
  925. static inline void dccp_mib_exit(void)
  926. {
  927. free_percpu(dccp_statistics);
  928. }
  929. static int thash_entries;
  930. module_param(thash_entries, int, 0444);
  931. MODULE_PARM_DESC(thash_entries, "Number of ehash buckets");
  932. #ifdef CONFIG_IP_DCCP_DEBUG
  933. bool dccp_debug;
  934. module_param(dccp_debug, bool, 0644);
  935. MODULE_PARM_DESC(dccp_debug, "Enable debug messages");
  936. EXPORT_SYMBOL_GPL(dccp_debug);
  937. #endif
  938. static int __init dccp_init(void)
  939. {
  940. unsigned long goal;
  941. int ehash_order, bhash_order, i;
  942. int rc;
  943. BUILD_BUG_ON(sizeof(struct dccp_skb_cb) >
  944. FIELD_SIZEOF(struct sk_buff, cb));
  945. rc = percpu_counter_init(&dccp_orphan_count, 0, GFP_KERNEL);
  946. if (rc)
  947. goto out_fail;
  948. rc = -ENOBUFS;
  949. inet_hashinfo_init(&dccp_hashinfo);
  950. dccp_hashinfo.bind_bucket_cachep =
  951. kmem_cache_create("dccp_bind_bucket",
  952. sizeof(struct inet_bind_bucket), 0,
  953. SLAB_HWCACHE_ALIGN, NULL);
  954. if (!dccp_hashinfo.bind_bucket_cachep)
  955. goto out_free_percpu;
  956. /*
  957. * Size and allocate the main established and bind bucket
  958. * hash tables.
  959. *
  960. * The methodology is similar to that of the buffer cache.
  961. */
  962. if (totalram_pages >= (128 * 1024))
  963. goal = totalram_pages >> (21 - PAGE_SHIFT);
  964. else
  965. goal = totalram_pages >> (23 - PAGE_SHIFT);
  966. if (thash_entries)
  967. goal = (thash_entries *
  968. sizeof(struct inet_ehash_bucket)) >> PAGE_SHIFT;
  969. for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++)
  970. ;
  971. do {
  972. unsigned long hash_size = (1UL << ehash_order) * PAGE_SIZE /
  973. sizeof(struct inet_ehash_bucket);
  974. while (hash_size & (hash_size - 1))
  975. hash_size--;
  976. dccp_hashinfo.ehash_mask = hash_size - 1;
  977. dccp_hashinfo.ehash = (struct inet_ehash_bucket *)
  978. __get_free_pages(GFP_ATOMIC|__GFP_NOWARN, ehash_order);
  979. } while (!dccp_hashinfo.ehash && --ehash_order > 0);
  980. if (!dccp_hashinfo.ehash) {
  981. DCCP_CRIT("Failed to allocate DCCP established hash table");
  982. goto out_free_bind_bucket_cachep;
  983. }
  984. for (i = 0; i <= dccp_hashinfo.ehash_mask; i++)
  985. INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].chain, i);
  986. if (inet_ehash_locks_alloc(&dccp_hashinfo))
  987. goto out_free_dccp_ehash;
  988. bhash_order = ehash_order;
  989. do {
  990. dccp_hashinfo.bhash_size = (1UL << bhash_order) * PAGE_SIZE /
  991. sizeof(struct inet_bind_hashbucket);
  992. if ((dccp_hashinfo.bhash_size > (64 * 1024)) &&
  993. bhash_order > 0)
  994. continue;
  995. dccp_hashinfo.bhash = (struct inet_bind_hashbucket *)
  996. __get_free_pages(GFP_ATOMIC|__GFP_NOWARN, bhash_order);
  997. } while (!dccp_hashinfo.bhash && --bhash_order >= 0);
  998. if (!dccp_hashinfo.bhash) {
  999. DCCP_CRIT("Failed to allocate DCCP bind hash table");
  1000. goto out_free_dccp_locks;
  1001. }
  1002. for (i = 0; i < dccp_hashinfo.bhash_size; i++) {
  1003. spin_lock_init(&dccp_hashinfo.bhash[i].lock);
  1004. INIT_HLIST_HEAD(&dccp_hashinfo.bhash[i].chain);
  1005. }
  1006. rc = dccp_mib_init();
  1007. if (rc)
  1008. goto out_free_dccp_bhash;
  1009. rc = dccp_ackvec_init();
  1010. if (rc)
  1011. goto out_free_dccp_mib;
  1012. rc = dccp_sysctl_init();
  1013. if (rc)
  1014. goto out_ackvec_exit;
  1015. rc = ccid_initialize_builtins();
  1016. if (rc)
  1017. goto out_sysctl_exit;
  1018. dccp_timestamping_init();
  1019. return 0;
  1020. out_sysctl_exit:
  1021. dccp_sysctl_exit();
  1022. out_ackvec_exit:
  1023. dccp_ackvec_exit();
  1024. out_free_dccp_mib:
  1025. dccp_mib_exit();
  1026. out_free_dccp_bhash:
  1027. free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order);
  1028. out_free_dccp_locks:
  1029. inet_ehash_locks_free(&dccp_hashinfo);
  1030. out_free_dccp_ehash:
  1031. free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order);
  1032. out_free_bind_bucket_cachep:
  1033. kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
  1034. out_free_percpu:
  1035. percpu_counter_destroy(&dccp_orphan_count);
  1036. out_fail:
  1037. dccp_hashinfo.bhash = NULL;
  1038. dccp_hashinfo.ehash = NULL;
  1039. dccp_hashinfo.bind_bucket_cachep = NULL;
  1040. return rc;
  1041. }
  1042. static void __exit dccp_fini(void)
  1043. {
  1044. ccid_cleanup_builtins();
  1045. dccp_mib_exit();
  1046. free_pages((unsigned long)dccp_hashinfo.bhash,
  1047. get_order(dccp_hashinfo.bhash_size *
  1048. sizeof(struct inet_bind_hashbucket)));
  1049. free_pages((unsigned long)dccp_hashinfo.ehash,
  1050. get_order((dccp_hashinfo.ehash_mask + 1) *
  1051. sizeof(struct inet_ehash_bucket)));
  1052. inet_ehash_locks_free(&dccp_hashinfo);
  1053. kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
  1054. dccp_ackvec_exit();
  1055. dccp_sysctl_exit();
  1056. percpu_counter_destroy(&dccp_orphan_count);
  1057. }
  1058. module_init(dccp_init);
  1059. module_exit(dccp_fini);
  1060. MODULE_LICENSE("GPL");
  1061. MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@conectiva.com.br>");
  1062. MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol");