output.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. * net/dccp/output.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
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/dccp.h>
  13. #include <linux/kernel.h>
  14. #include <linux/skbuff.h>
  15. #include <net/inet_sock.h>
  16. #include <net/sock.h>
  17. #include "ackvec.h"
  18. #include "ccid.h"
  19. #include "dccp.h"
  20. static inline void dccp_event_ack_sent(struct sock *sk)
  21. {
  22. inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
  23. }
  24. static void dccp_skb_entail(struct sock *sk, struct sk_buff *skb)
  25. {
  26. skb_set_owner_w(skb, sk);
  27. WARN_ON(sk->sk_send_head);
  28. sk->sk_send_head = skb;
  29. }
  30. /*
  31. * All SKB's seen here are completely headerless. It is our
  32. * job to build the DCCP header, and pass the packet down to
  33. * IP so it can do the same plus pass the packet off to the
  34. * device.
  35. */
  36. static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
  37. {
  38. if (likely(skb != NULL)) {
  39. const struct inet_sock *inet = inet_sk(sk);
  40. const struct inet_connection_sock *icsk = inet_csk(sk);
  41. struct dccp_sock *dp = dccp_sk(sk);
  42. struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
  43. struct dccp_hdr *dh;
  44. /* XXX For now we're using only 48 bits sequence numbers */
  45. const u32 dccp_header_size = sizeof(*dh) +
  46. sizeof(struct dccp_hdr_ext) +
  47. dccp_packet_hdr_len(dcb->dccpd_type);
  48. int err, set_ack = 1;
  49. u64 ackno = dp->dccps_gsr;
  50. dccp_inc_seqno(&dp->dccps_gss);
  51. switch (dcb->dccpd_type) {
  52. case DCCP_PKT_DATA:
  53. set_ack = 0;
  54. /* fall through */
  55. case DCCP_PKT_DATAACK:
  56. case DCCP_PKT_RESET:
  57. break;
  58. case DCCP_PKT_REQUEST:
  59. set_ack = 0;
  60. /* fall through */
  61. case DCCP_PKT_SYNC:
  62. case DCCP_PKT_SYNCACK:
  63. ackno = dcb->dccpd_ack_seq;
  64. /* fall through */
  65. default:
  66. /*
  67. * Set owner/destructor: some skbs are allocated via
  68. * alloc_skb (e.g. when retransmission may happen).
  69. * Only Data, DataAck, and Reset packets should come
  70. * through here with skb->sk set.
  71. */
  72. WARN_ON(skb->sk);
  73. skb_set_owner_w(skb, sk);
  74. break;
  75. }
  76. dcb->dccpd_seq = dp->dccps_gss;
  77. if (dccp_insert_options(sk, skb)) {
  78. kfree_skb(skb);
  79. return -EPROTO;
  80. }
  81. /* Build DCCP header and checksum it. */
  82. dh = dccp_zeroed_hdr(skb, dccp_header_size);
  83. dh->dccph_type = dcb->dccpd_type;
  84. dh->dccph_sport = inet->sport;
  85. dh->dccph_dport = inet->dport;
  86. dh->dccph_doff = (dccp_header_size + dcb->dccpd_opt_len) / 4;
  87. dh->dccph_ccval = dcb->dccpd_ccval;
  88. dh->dccph_cscov = dp->dccps_pcslen;
  89. /* XXX For now we're using only 48 bits sequence numbers */
  90. dh->dccph_x = 1;
  91. dp->dccps_awh = dp->dccps_gss;
  92. dccp_hdr_set_seq(dh, dp->dccps_gss);
  93. if (set_ack)
  94. dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), ackno);
  95. switch (dcb->dccpd_type) {
  96. case DCCP_PKT_REQUEST:
  97. dccp_hdr_request(skb)->dccph_req_service =
  98. dp->dccps_service;
  99. break;
  100. case DCCP_PKT_RESET:
  101. dccp_hdr_reset(skb)->dccph_reset_code =
  102. dcb->dccpd_reset_code;
  103. break;
  104. }
  105. icsk->icsk_af_ops->send_check(sk, 0, skb);
  106. if (set_ack)
  107. dccp_event_ack_sent(sk);
  108. DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
  109. memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
  110. err = icsk->icsk_af_ops->queue_xmit(skb, 0);
  111. return net_xmit_eval(err);
  112. }
  113. return -ENOBUFS;
  114. }
  115. /**
  116. * dccp_determine_ccmps - Find out about CCID-specfic packet-size limits
  117. * We only consider the HC-sender CCID for setting the CCMPS (RFC 4340, 14.),
  118. * since the RX CCID is restricted to feedback packets (Acks), which are small
  119. * in comparison with the data traffic. A value of 0 means "no current CCMPS".
  120. */
  121. static u32 dccp_determine_ccmps(const struct dccp_sock *dp)
  122. {
  123. const struct ccid *tx_ccid = dp->dccps_hc_tx_ccid;
  124. if (tx_ccid == NULL || tx_ccid->ccid_ops == NULL)
  125. return 0;
  126. return tx_ccid->ccid_ops->ccid_ccmps;
  127. }
  128. unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu)
  129. {
  130. struct inet_connection_sock *icsk = inet_csk(sk);
  131. struct dccp_sock *dp = dccp_sk(sk);
  132. u32 ccmps = dccp_determine_ccmps(dp);
  133. int cur_mps = ccmps ? min(pmtu, ccmps) : pmtu;
  134. /* Account for header lengths and IPv4/v6 option overhead */
  135. cur_mps -= (icsk->icsk_af_ops->net_header_len + icsk->icsk_ext_hdr_len +
  136. sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext));
  137. /*
  138. * FIXME: this should come from the CCID infrastructure, where, say,
  139. * TFRC will say it wants TIMESTAMPS, ELAPSED time, etc, for now lets
  140. * put a rough estimate for NDP + TIMESTAMP + TIMESTAMP_ECHO + ELAPSED
  141. * TIME + TFRC_OPT_LOSS_EVENT_RATE + TFRC_OPT_RECEIVE_RATE + padding to
  142. * make it a multiple of 4
  143. */
  144. cur_mps -= ((5 + 6 + 10 + 6 + 6 + 6 + 3) / 4) * 4;
  145. /* And store cached results */
  146. icsk->icsk_pmtu_cookie = pmtu;
  147. dp->dccps_mss_cache = cur_mps;
  148. return cur_mps;
  149. }
  150. EXPORT_SYMBOL_GPL(dccp_sync_mss);
  151. void dccp_write_space(struct sock *sk)
  152. {
  153. read_lock(&sk->sk_callback_lock);
  154. if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
  155. wake_up_interruptible(sk->sk_sleep);
  156. /* Should agree with poll, otherwise some programs break */
  157. if (sock_writeable(sk))
  158. sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
  159. read_unlock(&sk->sk_callback_lock);
  160. }
  161. /**
  162. * dccp_wait_for_ccid - Wait for ccid to tell us we can send a packet
  163. * @sk: socket to wait for
  164. * @skb: current skb to pass on for waiting
  165. * @delay: sleep timeout in milliseconds (> 0)
  166. * This function is called by default when the socket is closed, and
  167. * when a non-zero linger time is set on the socket. For consistency
  168. */
  169. static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb, int delay)
  170. {
  171. struct dccp_sock *dp = dccp_sk(sk);
  172. DEFINE_WAIT(wait);
  173. unsigned long jiffdelay;
  174. int rc;
  175. do {
  176. dccp_pr_debug("delayed send by %d msec\n", delay);
  177. jiffdelay = msecs_to_jiffies(delay);
  178. prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
  179. sk->sk_write_pending++;
  180. release_sock(sk);
  181. schedule_timeout(jiffdelay);
  182. lock_sock(sk);
  183. sk->sk_write_pending--;
  184. if (sk->sk_err)
  185. goto do_error;
  186. if (signal_pending(current))
  187. goto do_interrupted;
  188. rc = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb);
  189. } while ((delay = rc) > 0);
  190. out:
  191. finish_wait(sk->sk_sleep, &wait);
  192. return rc;
  193. do_error:
  194. rc = -EPIPE;
  195. goto out;
  196. do_interrupted:
  197. rc = -EINTR;
  198. goto out;
  199. }
  200. void dccp_write_xmit(struct sock *sk, int block)
  201. {
  202. struct dccp_sock *dp = dccp_sk(sk);
  203. struct sk_buff *skb;
  204. while ((skb = skb_peek(&sk->sk_write_queue))) {
  205. int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb);
  206. if (err > 0) {
  207. if (!block) {
  208. sk_reset_timer(sk, &dp->dccps_xmit_timer,
  209. msecs_to_jiffies(err)+jiffies);
  210. break;
  211. } else
  212. err = dccp_wait_for_ccid(sk, skb, err);
  213. if (err && err != -EINTR)
  214. DCCP_BUG("err=%d after dccp_wait_for_ccid", err);
  215. }
  216. skb_dequeue(&sk->sk_write_queue);
  217. if (err == 0) {
  218. struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
  219. const int len = skb->len;
  220. if (sk->sk_state == DCCP_PARTOPEN) {
  221. /* See 8.1.5. Handshake Completion */
  222. inet_csk_schedule_ack(sk);
  223. inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
  224. inet_csk(sk)->icsk_rto,
  225. DCCP_RTO_MAX);
  226. dcb->dccpd_type = DCCP_PKT_DATAACK;
  227. } else if (dccp_ack_pending(sk))
  228. dcb->dccpd_type = DCCP_PKT_DATAACK;
  229. else
  230. dcb->dccpd_type = DCCP_PKT_DATA;
  231. err = dccp_transmit_skb(sk, skb);
  232. ccid_hc_tx_packet_sent(dp->dccps_hc_tx_ccid, sk, 0, len);
  233. if (err)
  234. DCCP_BUG("err=%d after ccid_hc_tx_packet_sent",
  235. err);
  236. } else {
  237. dccp_pr_debug("packet discarded due to err=%d\n", err);
  238. kfree_skb(skb);
  239. }
  240. }
  241. }
  242. int dccp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
  243. {
  244. if (inet_csk(sk)->icsk_af_ops->rebuild_header(sk) != 0)
  245. return -EHOSTUNREACH; /* Routing failure or similar. */
  246. return dccp_transmit_skb(sk, (skb_cloned(skb) ?
  247. pskb_copy(skb, GFP_ATOMIC):
  248. skb_clone(skb, GFP_ATOMIC)));
  249. }
  250. struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
  251. struct request_sock *req)
  252. {
  253. struct dccp_hdr *dh;
  254. struct dccp_request_sock *dreq;
  255. const u32 dccp_header_size = sizeof(struct dccp_hdr) +
  256. sizeof(struct dccp_hdr_ext) +
  257. sizeof(struct dccp_hdr_response);
  258. struct sk_buff *skb = sock_wmalloc(sk, sk->sk_prot->max_header, 1,
  259. GFP_ATOMIC);
  260. if (skb == NULL)
  261. return NULL;
  262. /* Reserve space for headers. */
  263. skb_reserve(skb, sk->sk_prot->max_header);
  264. skb->dst = dst_clone(dst);
  265. dreq = dccp_rsk(req);
  266. if (inet_rsk(req)->acked) /* increase ISS upon retransmission */
  267. dccp_inc_seqno(&dreq->dreq_iss);
  268. DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESPONSE;
  269. DCCP_SKB_CB(skb)->dccpd_seq = dreq->dreq_iss;
  270. if (dccp_insert_options_rsk(dreq, skb)) {
  271. kfree_skb(skb);
  272. return NULL;
  273. }
  274. /* Build and checksum header */
  275. dh = dccp_zeroed_hdr(skb, dccp_header_size);
  276. dh->dccph_sport = inet_sk(sk)->sport;
  277. dh->dccph_dport = inet_rsk(req)->rmt_port;
  278. dh->dccph_doff = (dccp_header_size +
  279. DCCP_SKB_CB(skb)->dccpd_opt_len) / 4;
  280. dh->dccph_type = DCCP_PKT_RESPONSE;
  281. dh->dccph_x = 1;
  282. dccp_hdr_set_seq(dh, dreq->dreq_iss);
  283. dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dreq->dreq_isr);
  284. dccp_hdr_response(skb)->dccph_resp_service = dreq->dreq_service;
  285. dccp_csum_outgoing(skb);
  286. /* We use `acked' to remember that a Response was already sent. */
  287. inet_rsk(req)->acked = 1;
  288. DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
  289. return skb;
  290. }
  291. EXPORT_SYMBOL_GPL(dccp_make_response);
  292. /* answer offending packet in @rcv_skb with Reset from control socket @ctl */
  293. struct sk_buff *dccp_ctl_make_reset(struct socket *ctl, struct sk_buff *rcv_skb)
  294. {
  295. struct dccp_hdr *rxdh = dccp_hdr(rcv_skb), *dh;
  296. struct dccp_skb_cb *dcb = DCCP_SKB_CB(rcv_skb);
  297. const u32 dccp_hdr_reset_len = sizeof(struct dccp_hdr) +
  298. sizeof(struct dccp_hdr_ext) +
  299. sizeof(struct dccp_hdr_reset);
  300. struct dccp_hdr_reset *dhr;
  301. struct sk_buff *skb;
  302. skb = alloc_skb(ctl->sk->sk_prot->max_header, GFP_ATOMIC);
  303. if (skb == NULL)
  304. return NULL;
  305. skb_reserve(skb, ctl->sk->sk_prot->max_header);
  306. /* Swap the send and the receive. */
  307. dh = dccp_zeroed_hdr(skb, dccp_hdr_reset_len);
  308. dh->dccph_type = DCCP_PKT_RESET;
  309. dh->dccph_sport = rxdh->dccph_dport;
  310. dh->dccph_dport = rxdh->dccph_sport;
  311. dh->dccph_doff = dccp_hdr_reset_len / 4;
  312. dh->dccph_x = 1;
  313. dhr = dccp_hdr_reset(skb);
  314. dhr->dccph_reset_code = dcb->dccpd_reset_code;
  315. switch (dcb->dccpd_reset_code) {
  316. case DCCP_RESET_CODE_PACKET_ERROR:
  317. dhr->dccph_reset_data[0] = rxdh->dccph_type;
  318. break;
  319. case DCCP_RESET_CODE_OPTION_ERROR: /* fall through */
  320. case DCCP_RESET_CODE_MANDATORY_ERROR:
  321. memcpy(dhr->dccph_reset_data, dcb->dccpd_reset_data, 3);
  322. break;
  323. }
  324. /*
  325. * From RFC 4340, 8.3.1:
  326. * If P.ackno exists, set R.seqno := P.ackno + 1.
  327. * Else set R.seqno := 0.
  328. */
  329. if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
  330. dccp_hdr_set_seq(dh, ADD48(dcb->dccpd_ack_seq, 1));
  331. dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dcb->dccpd_seq);
  332. dccp_csum_outgoing(skb);
  333. return skb;
  334. }
  335. EXPORT_SYMBOL_GPL(dccp_ctl_make_reset);
  336. /* send Reset on established socket, to close or abort the connection */
  337. int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code)
  338. {
  339. struct sk_buff *skb;
  340. /*
  341. * FIXME: what if rebuild_header fails?
  342. * Should we be doing a rebuild_header here?
  343. */
  344. int err = inet_csk(sk)->icsk_af_ops->rebuild_header(sk);
  345. if (err != 0)
  346. return err;
  347. skb = sock_wmalloc(sk, sk->sk_prot->max_header, 1, GFP_ATOMIC);
  348. if (skb == NULL)
  349. return -ENOBUFS;
  350. /* Reserve space for headers and prepare control bits. */
  351. skb_reserve(skb, sk->sk_prot->max_header);
  352. DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESET;
  353. DCCP_SKB_CB(skb)->dccpd_reset_code = code;
  354. return dccp_transmit_skb(sk, skb);
  355. }
  356. /*
  357. * Do all connect socket setups that can be done AF independent.
  358. */
  359. static inline void dccp_connect_init(struct sock *sk)
  360. {
  361. struct dccp_sock *dp = dccp_sk(sk);
  362. struct dst_entry *dst = __sk_dst_get(sk);
  363. struct inet_connection_sock *icsk = inet_csk(sk);
  364. sk->sk_err = 0;
  365. sock_reset_flag(sk, SOCK_DONE);
  366. dccp_sync_mss(sk, dst_mtu(dst));
  367. /*
  368. * SWL and AWL are initially adjusted so that they are not less than
  369. * the initial Sequence Numbers received and sent, respectively:
  370. * SWL := max(GSR + 1 - floor(W/4), ISR),
  371. * AWL := max(GSS - W' + 1, ISS).
  372. * These adjustments MUST be applied only at the beginning of the
  373. * connection.
  374. */
  375. dccp_update_gss(sk, dp->dccps_iss);
  376. dccp_set_seqno(&dp->dccps_awl, max48(dp->dccps_awl, dp->dccps_iss));
  377. /* S.GAR - greatest valid acknowledgement number received on a non-Sync;
  378. * initialized to S.ISS (sec. 8.5) */
  379. dp->dccps_gar = dp->dccps_iss;
  380. icsk->icsk_retransmits = 0;
  381. }
  382. int dccp_connect(struct sock *sk)
  383. {
  384. struct sk_buff *skb;
  385. struct inet_connection_sock *icsk = inet_csk(sk);
  386. dccp_connect_init(sk);
  387. skb = alloc_skb(sk->sk_prot->max_header, sk->sk_allocation);
  388. if (unlikely(skb == NULL))
  389. return -ENOBUFS;
  390. /* Reserve space for headers. */
  391. skb_reserve(skb, sk->sk_prot->max_header);
  392. DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_REQUEST;
  393. dccp_skb_entail(sk, skb);
  394. dccp_transmit_skb(sk, skb_clone(skb, GFP_KERNEL));
  395. DCCP_INC_STATS(DCCP_MIB_ACTIVEOPENS);
  396. /* Timer for repeating the REQUEST until an answer. */
  397. inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
  398. icsk->icsk_rto, DCCP_RTO_MAX);
  399. return 0;
  400. }
  401. EXPORT_SYMBOL_GPL(dccp_connect);
  402. void dccp_send_ack(struct sock *sk)
  403. {
  404. /* If we have been reset, we may not send again. */
  405. if (sk->sk_state != DCCP_CLOSED) {
  406. struct sk_buff *skb = alloc_skb(sk->sk_prot->max_header,
  407. GFP_ATOMIC);
  408. if (skb == NULL) {
  409. inet_csk_schedule_ack(sk);
  410. inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN;
  411. inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
  412. TCP_DELACK_MAX,
  413. DCCP_RTO_MAX);
  414. return;
  415. }
  416. /* Reserve space for headers */
  417. skb_reserve(skb, sk->sk_prot->max_header);
  418. DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_ACK;
  419. dccp_transmit_skb(sk, skb);
  420. }
  421. }
  422. EXPORT_SYMBOL_GPL(dccp_send_ack);
  423. /* FIXME: Is this still necessary (11.3) - currently nowhere used by DCCP. */
  424. void dccp_send_delayed_ack(struct sock *sk)
  425. {
  426. struct inet_connection_sock *icsk = inet_csk(sk);
  427. /*
  428. * FIXME: tune this timer. elapsed time fixes the skew, so no problem
  429. * with using 2s, and active senders also piggyback the ACK into a
  430. * DATAACK packet, so this is really for quiescent senders.
  431. */
  432. unsigned long timeout = jiffies + 2 * HZ;
  433. /* Use new timeout only if there wasn't a older one earlier. */
  434. if (icsk->icsk_ack.pending & ICSK_ACK_TIMER) {
  435. /* If delack timer was blocked or is about to expire,
  436. * send ACK now.
  437. *
  438. * FIXME: check the "about to expire" part
  439. */
  440. if (icsk->icsk_ack.blocked) {
  441. dccp_send_ack(sk);
  442. return;
  443. }
  444. if (!time_before(timeout, icsk->icsk_ack.timeout))
  445. timeout = icsk->icsk_ack.timeout;
  446. }
  447. icsk->icsk_ack.pending |= ICSK_ACK_SCHED | ICSK_ACK_TIMER;
  448. icsk->icsk_ack.timeout = timeout;
  449. sk_reset_timer(sk, &icsk->icsk_delack_timer, timeout);
  450. }
  451. void dccp_send_sync(struct sock *sk, const u64 ackno,
  452. const enum dccp_pkt_type pkt_type)
  453. {
  454. /*
  455. * We are not putting this on the write queue, so
  456. * dccp_transmit_skb() will set the ownership to this
  457. * sock.
  458. */
  459. struct sk_buff *skb = alloc_skb(sk->sk_prot->max_header, GFP_ATOMIC);
  460. if (skb == NULL) {
  461. /* FIXME: how to make sure the sync is sent? */
  462. DCCP_CRIT("could not send %s", dccp_packet_name(pkt_type));
  463. return;
  464. }
  465. /* Reserve space for headers and prepare control bits. */
  466. skb_reserve(skb, sk->sk_prot->max_header);
  467. DCCP_SKB_CB(skb)->dccpd_type = pkt_type;
  468. DCCP_SKB_CB(skb)->dccpd_ack_seq = ackno;
  469. dccp_transmit_skb(sk, skb);
  470. }
  471. EXPORT_SYMBOL_GPL(dccp_send_sync);
  472. /*
  473. * Send a DCCP_PKT_CLOSE/CLOSEREQ. The caller locks the socket for us. This
  474. * cannot be allowed to fail queueing a DCCP_PKT_CLOSE/CLOSEREQ frame under
  475. * any circumstances.
  476. */
  477. void dccp_send_close(struct sock *sk, const int active)
  478. {
  479. struct dccp_sock *dp = dccp_sk(sk);
  480. struct sk_buff *skb;
  481. const gfp_t prio = active ? GFP_KERNEL : GFP_ATOMIC;
  482. skb = alloc_skb(sk->sk_prot->max_header, prio);
  483. if (skb == NULL)
  484. return;
  485. /* Reserve space for headers and prepare control bits. */
  486. skb_reserve(skb, sk->sk_prot->max_header);
  487. if (dp->dccps_role == DCCP_ROLE_SERVER && !dp->dccps_server_timewait)
  488. DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_CLOSEREQ;
  489. else
  490. DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_CLOSE;
  491. if (active) {
  492. dccp_write_xmit(sk, 1);
  493. dccp_skb_entail(sk, skb);
  494. dccp_transmit_skb(sk, skb_clone(skb, prio));
  495. /*
  496. * Retransmission timer for active-close: RFC 4340, 8.3 requires
  497. * to retransmit the Close/CloseReq until the CLOSING/CLOSEREQ
  498. * state can be left. The initial timeout is 2 RTTs.
  499. * Since RTT measurement is done by the CCIDs, there is no easy
  500. * way to get an RTT sample. The fallback RTT from RFC 4340, 3.4
  501. * is too low (200ms); we use a high value to avoid unnecessary
  502. * retransmissions when the link RTT is > 0.2 seconds.
  503. * FIXME: Let main module sample RTTs and use that instead.
  504. */
  505. inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
  506. DCCP_TIMEOUT_INIT, DCCP_RTO_MAX);
  507. } else
  508. dccp_transmit_skb(sk, skb);
  509. }