dn_nsp_out.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * DECnet An implementation of the DECnet protocol suite for the LINUX
  3. * operating system. DECnet is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * DECnet Network Services Protocol (Output)
  7. *
  8. * Author: Eduardo Marcelo Serrat <emserrat@geocities.com>
  9. *
  10. * Changes:
  11. *
  12. * Steve Whitehouse: Split into dn_nsp_in.c and dn_nsp_out.c from
  13. * original dn_nsp.c.
  14. * Steve Whitehouse: Updated to work with my new routing architecture.
  15. * Steve Whitehouse: Added changes from Eduardo Serrat's patches.
  16. * Steve Whitehouse: Now conninits have the "return" bit set.
  17. * Steve Whitehouse: Fixes to check alloc'd skbs are non NULL!
  18. * Moved output state machine into one function
  19. * Steve Whitehouse: New output state machine
  20. * Paul Koning: Connect Confirm message fix.
  21. * Eduardo Serrat: Fix to stop dn_nsp_do_disc() sending malformed packets.
  22. * Steve Whitehouse: dn_nsp_output() and friends needed a spring clean
  23. * Steve Whitehouse: Moved dn_nsp_send() in here from route.h
  24. */
  25. /******************************************************************************
  26. (c) 1995-1998 E.M. Serrat emserrat@geocities.com
  27. This program is free software; you can redistribute it and/or modify
  28. it under the terms of the GNU General Public License as published by
  29. the Free Software Foundation; either version 2 of the License, or
  30. any later version.
  31. This program is distributed in the hope that it will be useful,
  32. but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. GNU General Public License for more details.
  35. *******************************************************************************/
  36. #include <linux/errno.h>
  37. #include <linux/types.h>
  38. #include <linux/socket.h>
  39. #include <linux/in.h>
  40. #include <linux/kernel.h>
  41. #include <linux/sched.h>
  42. #include <linux/timer.h>
  43. #include <linux/string.h>
  44. #include <linux/sockios.h>
  45. #include <linux/net.h>
  46. #include <linux/netdevice.h>
  47. #include <linux/inet.h>
  48. #include <linux/route.h>
  49. #include <net/sock.h>
  50. #include <asm/system.h>
  51. #include <linux/fcntl.h>
  52. #include <linux/mm.h>
  53. #include <linux/termios.h>
  54. #include <linux/interrupt.h>
  55. #include <linux/proc_fs.h>
  56. #include <linux/stat.h>
  57. #include <linux/init.h>
  58. #include <linux/poll.h>
  59. #include <linux/if_packet.h>
  60. #include <net/neighbour.h>
  61. #include <net/dst.h>
  62. #include <net/flow.h>
  63. #include <net/dn.h>
  64. #include <net/dn_nsp.h>
  65. #include <net/dn_dev.h>
  66. #include <net/dn_route.h>
  67. static int nsp_backoff[NSP_MAXRXTSHIFT + 1] = { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
  68. static void dn_nsp_send(struct sk_buff *skb)
  69. {
  70. struct sock *sk = skb->sk;
  71. struct dn_scp *scp = DN_SK(sk);
  72. struct dst_entry *dst;
  73. struct flowi fl;
  74. skb->h.raw = skb->data;
  75. scp->stamp = jiffies;
  76. dst = sk_dst_check(sk, 0);
  77. if (dst) {
  78. try_again:
  79. skb->dst = dst;
  80. dst_output(skb);
  81. return;
  82. }
  83. memset(&fl, 0, sizeof(fl));
  84. fl.oif = sk->sk_bound_dev_if;
  85. fl.fld_src = dn_saddr2dn(&scp->addr);
  86. fl.fld_dst = dn_saddr2dn(&scp->peer);
  87. dn_sk_ports_copy(&fl, scp);
  88. fl.proto = DNPROTO_NSP;
  89. if (dn_route_output_sock(&sk->sk_dst_cache, &fl, sk, 0) == 0) {
  90. dst = sk_dst_get(sk);
  91. sk->sk_route_caps = dst->dev->features;
  92. goto try_again;
  93. }
  94. sk->sk_err = EHOSTUNREACH;
  95. if (!sock_flag(sk, SOCK_DEAD))
  96. sk->sk_state_change(sk);
  97. }
  98. /*
  99. * If sk == NULL, then we assume that we are supposed to be making
  100. * a routing layer skb. If sk != NULL, then we are supposed to be
  101. * creating an skb for the NSP layer.
  102. *
  103. * The eventual aim is for each socket to have a cached header size
  104. * for its outgoing packets, and to set hdr from this when sk != NULL.
  105. */
  106. struct sk_buff *dn_alloc_skb(struct sock *sk, int size, int pri)
  107. {
  108. struct sk_buff *skb;
  109. int hdr = 64;
  110. if ((skb = alloc_skb(size + hdr, pri)) == NULL)
  111. return NULL;
  112. skb->protocol = __constant_htons(ETH_P_DNA_RT);
  113. skb->pkt_type = PACKET_OUTGOING;
  114. if (sk)
  115. skb_set_owner_w(skb, sk);
  116. skb_reserve(skb, hdr);
  117. return skb;
  118. }
  119. /*
  120. * Wrapper for the above, for allocs of data skbs. We try and get the
  121. * whole size thats been asked for (plus 11 bytes of header). If this
  122. * fails, then we try for any size over 16 bytes for SOCK_STREAMS.
  123. */
  124. struct sk_buff *dn_alloc_send_skb(struct sock *sk, size_t *size, int noblock, long timeo, int *err)
  125. {
  126. int space;
  127. int len;
  128. struct sk_buff *skb = NULL;
  129. *err = 0;
  130. while(skb == NULL) {
  131. if (signal_pending(current)) {
  132. *err = sock_intr_errno(timeo);
  133. break;
  134. }
  135. if (sk->sk_shutdown & SEND_SHUTDOWN) {
  136. *err = EINVAL;
  137. break;
  138. }
  139. if (sk->sk_err)
  140. break;
  141. len = *size + 11;
  142. space = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
  143. if (space < len) {
  144. if ((sk->sk_socket->type == SOCK_STREAM) &&
  145. (space >= (16 + 11)))
  146. len = space;
  147. }
  148. if (space < len) {
  149. set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
  150. if (noblock) {
  151. *err = EWOULDBLOCK;
  152. break;
  153. }
  154. clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
  155. SOCK_SLEEP_PRE(sk)
  156. if ((sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc)) <
  157. len)
  158. schedule();
  159. SOCK_SLEEP_POST(sk)
  160. continue;
  161. }
  162. if ((skb = dn_alloc_skb(sk, len, sk->sk_allocation)) == NULL)
  163. continue;
  164. *size = len - 11;
  165. }
  166. return skb;
  167. }
  168. /*
  169. * Calculate persist timer based upon the smoothed round
  170. * trip time and the variance. Backoff according to the
  171. * nsp_backoff[] array.
  172. */
  173. unsigned long dn_nsp_persist(struct sock *sk)
  174. {
  175. struct dn_scp *scp = DN_SK(sk);
  176. unsigned long t = ((scp->nsp_srtt >> 2) + scp->nsp_rttvar) >> 1;
  177. t *= nsp_backoff[scp->nsp_rxtshift];
  178. if (t < HZ) t = HZ;
  179. if (t > (600*HZ)) t = (600*HZ);
  180. if (scp->nsp_rxtshift < NSP_MAXRXTSHIFT)
  181. scp->nsp_rxtshift++;
  182. /* printk(KERN_DEBUG "rxtshift %lu, t=%lu\n", scp->nsp_rxtshift, t); */
  183. return t;
  184. }
  185. /*
  186. * This is called each time we get an estimate for the rtt
  187. * on the link.
  188. */
  189. static void dn_nsp_rtt(struct sock *sk, long rtt)
  190. {
  191. struct dn_scp *scp = DN_SK(sk);
  192. long srtt = (long)scp->nsp_srtt;
  193. long rttvar = (long)scp->nsp_rttvar;
  194. long delta;
  195. /*
  196. * If the jiffies clock flips over in the middle of timestamp
  197. * gathering this value might turn out negative, so we make sure
  198. * that is it always positive here.
  199. */
  200. if (rtt < 0)
  201. rtt = -rtt;
  202. /*
  203. * Add new rtt to smoothed average
  204. */
  205. delta = ((rtt << 3) - srtt);
  206. srtt += (delta >> 3);
  207. if (srtt >= 1)
  208. scp->nsp_srtt = (unsigned long)srtt;
  209. else
  210. scp->nsp_srtt = 1;
  211. /*
  212. * Add new rtt varience to smoothed varience
  213. */
  214. delta >>= 1;
  215. rttvar += ((((delta>0)?(delta):(-delta)) - rttvar) >> 2);
  216. if (rttvar >= 1)
  217. scp->nsp_rttvar = (unsigned long)rttvar;
  218. else
  219. scp->nsp_rttvar = 1;
  220. /* printk(KERN_DEBUG "srtt=%lu rttvar=%lu\n", scp->nsp_srtt, scp->nsp_rttvar); */
  221. }
  222. /**
  223. * dn_nsp_clone_and_send - Send a data packet by cloning it
  224. * @skb: The packet to clone and transmit
  225. * @gfp: memory allocation flag
  226. *
  227. * Clone a queued data or other data packet and transmit it.
  228. *
  229. * Returns: The number of times the packet has been sent previously
  230. */
  231. static inline unsigned dn_nsp_clone_and_send(struct sk_buff *skb, int gfp)
  232. {
  233. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  234. struct sk_buff *skb2;
  235. int ret = 0;
  236. if ((skb2 = skb_clone(skb, gfp)) != NULL) {
  237. ret = cb->xmit_count;
  238. cb->xmit_count++;
  239. cb->stamp = jiffies;
  240. skb2->sk = skb->sk;
  241. dn_nsp_send(skb2);
  242. }
  243. return ret;
  244. }
  245. /**
  246. * dn_nsp_output - Try and send something from socket queues
  247. * @sk: The socket whose queues are to be investigated
  248. * @gfp: The memory allocation flags
  249. *
  250. * Try and send the packet on the end of the data and other data queues.
  251. * Other data gets priority over data, and if we retransmit a packet we
  252. * reduce the window by dividing it in two.
  253. *
  254. */
  255. void dn_nsp_output(struct sock *sk)
  256. {
  257. struct dn_scp *scp = DN_SK(sk);
  258. struct sk_buff *skb;
  259. unsigned reduce_win = 0;
  260. /*
  261. * First we check for otherdata/linkservice messages
  262. */
  263. if ((skb = skb_peek(&scp->other_xmit_queue)) != NULL)
  264. reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC);
  265. /*
  266. * If we may not send any data, we don't.
  267. * If we are still trying to get some other data down the
  268. * channel, we don't try and send any data.
  269. */
  270. if (reduce_win || (scp->flowrem_sw != DN_SEND))
  271. goto recalc_window;
  272. if ((skb = skb_peek(&scp->data_xmit_queue)) != NULL)
  273. reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC);
  274. /*
  275. * If we've sent any frame more than once, we cut the
  276. * send window size in half. There is always a minimum
  277. * window size of one available.
  278. */
  279. recalc_window:
  280. if (reduce_win) {
  281. scp->snd_window >>= 1;
  282. if (scp->snd_window < NSP_MIN_WINDOW)
  283. scp->snd_window = NSP_MIN_WINDOW;
  284. }
  285. }
  286. int dn_nsp_xmit_timeout(struct sock *sk)
  287. {
  288. struct dn_scp *scp = DN_SK(sk);
  289. dn_nsp_output(sk);
  290. if (skb_queue_len(&scp->data_xmit_queue) || skb_queue_len(&scp->other_xmit_queue))
  291. scp->persist = dn_nsp_persist(sk);
  292. return 0;
  293. }
  294. static inline unsigned char *dn_mk_common_header(struct dn_scp *scp, struct sk_buff *skb, unsigned char msgflag, int len)
  295. {
  296. unsigned char *ptr = skb_push(skb, len);
  297. BUG_ON(len < 5);
  298. *ptr++ = msgflag;
  299. *((unsigned short *)ptr) = scp->addrrem;
  300. ptr += 2;
  301. *((unsigned short *)ptr) = scp->addrloc;
  302. ptr += 2;
  303. return ptr;
  304. }
  305. static unsigned short *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned char msgflag, int hlen, int other)
  306. {
  307. struct dn_scp *scp = DN_SK(sk);
  308. unsigned short acknum = scp->numdat_rcv & 0x0FFF;
  309. unsigned short ackcrs = scp->numoth_rcv & 0x0FFF;
  310. unsigned short *ptr;
  311. BUG_ON(hlen < 9);
  312. scp->ackxmt_dat = acknum;
  313. scp->ackxmt_oth = ackcrs;
  314. acknum |= 0x8000;
  315. ackcrs |= 0x8000;
  316. /* If this is an "other data/ack" message, swap acknum and ackcrs */
  317. if (other) {
  318. unsigned short tmp = acknum;
  319. acknum = ackcrs;
  320. ackcrs = tmp;
  321. }
  322. /* Set "cross subchannel" bit in ackcrs */
  323. ackcrs |= 0x2000;
  324. ptr = (unsigned short *)dn_mk_common_header(scp, skb, msgflag, hlen);
  325. *ptr++ = dn_htons(acknum);
  326. *ptr++ = dn_htons(ackcrs);
  327. return ptr;
  328. }
  329. static unsigned short *dn_nsp_mk_data_header(struct sock *sk, struct sk_buff *skb, int oth)
  330. {
  331. struct dn_scp *scp = DN_SK(sk);
  332. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  333. unsigned short *ptr = dn_mk_ack_header(sk, skb, cb->nsp_flags, 11, oth);
  334. if (unlikely(oth)) {
  335. cb->segnum = scp->numoth;
  336. seq_add(&scp->numoth, 1);
  337. } else {
  338. cb->segnum = scp->numdat;
  339. seq_add(&scp->numdat, 1);
  340. }
  341. *(ptr++) = dn_htons(cb->segnum);
  342. return ptr;
  343. }
  344. void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb, int gfp, int oth)
  345. {
  346. struct dn_scp *scp = DN_SK(sk);
  347. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  348. unsigned long t = ((scp->nsp_srtt >> 2) + scp->nsp_rttvar) >> 1;
  349. cb->xmit_count = 0;
  350. dn_nsp_mk_data_header(sk, skb, oth);
  351. /*
  352. * Slow start: If we have been idle for more than
  353. * one RTT, then reset window to min size.
  354. */
  355. if ((jiffies - scp->stamp) > t)
  356. scp->snd_window = NSP_MIN_WINDOW;
  357. if (oth)
  358. skb_queue_tail(&scp->other_xmit_queue, skb);
  359. else
  360. skb_queue_tail(&scp->data_xmit_queue, skb);
  361. if (scp->flowrem_sw != DN_SEND)
  362. return;
  363. dn_nsp_clone_and_send(skb, gfp);
  364. }
  365. int dn_nsp_check_xmit_queue(struct sock *sk, struct sk_buff *skb, struct sk_buff_head *q, unsigned short acknum)
  366. {
  367. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  368. struct dn_scp *scp = DN_SK(sk);
  369. struct sk_buff *skb2, *list, *ack = NULL;
  370. int wakeup = 0;
  371. int try_retrans = 0;
  372. unsigned long reftime = cb->stamp;
  373. unsigned long pkttime;
  374. unsigned short xmit_count;
  375. unsigned short segnum;
  376. skb2 = q->next;
  377. list = (struct sk_buff *)q;
  378. while(list != skb2) {
  379. struct dn_skb_cb *cb2 = DN_SKB_CB(skb2);
  380. if (dn_before_or_equal(cb2->segnum, acknum))
  381. ack = skb2;
  382. /* printk(KERN_DEBUG "ack: %s %04x %04x\n", ack ? "ACK" : "SKIP", (int)cb2->segnum, (int)acknum); */
  383. skb2 = skb2->next;
  384. if (ack == NULL)
  385. continue;
  386. /* printk(KERN_DEBUG "check_xmit_queue: %04x, %d\n", acknum, cb2->xmit_count); */
  387. /* Does _last_ packet acked have xmit_count > 1 */
  388. try_retrans = 0;
  389. /* Remember to wake up the sending process */
  390. wakeup = 1;
  391. /* Keep various statistics */
  392. pkttime = cb2->stamp;
  393. xmit_count = cb2->xmit_count;
  394. segnum = cb2->segnum;
  395. /* Remove and drop ack'ed packet */
  396. skb_unlink(ack);
  397. kfree_skb(ack);
  398. ack = NULL;
  399. /*
  400. * We don't expect to see acknowledgements for packets we
  401. * haven't sent yet.
  402. */
  403. WARN_ON(xmit_count == 0);
  404. /*
  405. * If the packet has only been sent once, we can use it
  406. * to calculate the RTT and also open the window a little
  407. * further.
  408. */
  409. if (xmit_count == 1) {
  410. if (dn_equal(segnum, acknum))
  411. dn_nsp_rtt(sk, (long)(pkttime - reftime));
  412. if (scp->snd_window < scp->max_window)
  413. scp->snd_window++;
  414. }
  415. /*
  416. * Packet has been sent more than once. If this is the last
  417. * packet to be acknowledged then we want to send the next
  418. * packet in the send queue again (assumes the remote host does
  419. * go-back-N error control).
  420. */
  421. if (xmit_count > 1)
  422. try_retrans = 1;
  423. }
  424. if (try_retrans)
  425. dn_nsp_output(sk);
  426. return wakeup;
  427. }
  428. void dn_nsp_send_data_ack(struct sock *sk)
  429. {
  430. struct sk_buff *skb = NULL;
  431. if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL)
  432. return;
  433. skb_reserve(skb, 9);
  434. dn_mk_ack_header(sk, skb, 0x04, 9, 0);
  435. dn_nsp_send(skb);
  436. }
  437. void dn_nsp_send_oth_ack(struct sock *sk)
  438. {
  439. struct sk_buff *skb = NULL;
  440. if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL)
  441. return;
  442. skb_reserve(skb, 9);
  443. dn_mk_ack_header(sk, skb, 0x14, 9, 1);
  444. dn_nsp_send(skb);
  445. }
  446. void dn_send_conn_ack (struct sock *sk)
  447. {
  448. struct dn_scp *scp = DN_SK(sk);
  449. struct sk_buff *skb = NULL;
  450. struct nsp_conn_ack_msg *msg;
  451. if ((skb = dn_alloc_skb(sk, 3, sk->sk_allocation)) == NULL)
  452. return;
  453. msg = (struct nsp_conn_ack_msg *)skb_put(skb, 3);
  454. msg->msgflg = 0x24;
  455. msg->dstaddr = scp->addrrem;
  456. dn_nsp_send(skb);
  457. }
  458. void dn_nsp_delayed_ack(struct sock *sk)
  459. {
  460. struct dn_scp *scp = DN_SK(sk);
  461. if (scp->ackxmt_oth != scp->numoth_rcv)
  462. dn_nsp_send_oth_ack(sk);
  463. if (scp->ackxmt_dat != scp->numdat_rcv)
  464. dn_nsp_send_data_ack(sk);
  465. }
  466. static int dn_nsp_retrans_conn_conf(struct sock *sk)
  467. {
  468. struct dn_scp *scp = DN_SK(sk);
  469. if (scp->state == DN_CC)
  470. dn_send_conn_conf(sk, GFP_ATOMIC);
  471. return 0;
  472. }
  473. void dn_send_conn_conf(struct sock *sk, int gfp)
  474. {
  475. struct dn_scp *scp = DN_SK(sk);
  476. struct sk_buff *skb = NULL;
  477. struct nsp_conn_init_msg *msg;
  478. unsigned char len = scp->conndata_out.opt_optl;
  479. if ((skb = dn_alloc_skb(sk, 50 + scp->conndata_out.opt_optl, gfp)) == NULL)
  480. return;
  481. msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg));
  482. msg->msgflg = 0x28;
  483. msg->dstaddr = scp->addrrem;
  484. msg->srcaddr = scp->addrloc;
  485. msg->services = scp->services_loc;
  486. msg->info = scp->info_loc;
  487. msg->segsize = dn_htons(scp->segsize_loc);
  488. *skb_put(skb,1) = len;
  489. if (len > 0)
  490. memcpy(skb_put(skb, len), scp->conndata_out.opt_data, len);
  491. dn_nsp_send(skb);
  492. scp->persist = dn_nsp_persist(sk);
  493. scp->persist_fxn = dn_nsp_retrans_conn_conf;
  494. }
  495. static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
  496. unsigned short reason, int gfp, struct dst_entry *dst,
  497. int ddl, unsigned char *dd, __u16 rem, __u16 loc)
  498. {
  499. struct sk_buff *skb = NULL;
  500. int size = 7 + ddl + ((msgflg == NSP_DISCINIT) ? 1 : 0);
  501. unsigned char *msg;
  502. if ((dst == NULL) || (rem == 0)) {
  503. if (net_ratelimit())
  504. printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p\n", (unsigned)rem, dst);
  505. return;
  506. }
  507. if ((skb = dn_alloc_skb(sk, size, gfp)) == NULL)
  508. return;
  509. msg = skb_put(skb, size);
  510. *msg++ = msgflg;
  511. *(__u16 *)msg = rem;
  512. msg += 2;
  513. *(__u16 *)msg = loc;
  514. msg += 2;
  515. *(__u16 *)msg = dn_htons(reason);
  516. msg += 2;
  517. if (msgflg == NSP_DISCINIT)
  518. *msg++ = ddl;
  519. if (ddl) {
  520. memcpy(msg, dd, ddl);
  521. }
  522. /*
  523. * This doesn't go via the dn_nsp_send() function since we need
  524. * to be able to send disc packets out which have no socket
  525. * associations.
  526. */
  527. skb->dst = dst_clone(dst);
  528. dst_output(skb);
  529. }
  530. void dn_nsp_send_disc(struct sock *sk, unsigned char msgflg,
  531. unsigned short reason, int gfp)
  532. {
  533. struct dn_scp *scp = DN_SK(sk);
  534. int ddl = 0;
  535. if (msgflg == NSP_DISCINIT)
  536. ddl = scp->discdata_out.opt_optl;
  537. if (reason == 0)
  538. reason = scp->discdata_out.opt_status;
  539. dn_nsp_do_disc(sk, msgflg, reason, gfp, sk->sk_dst_cache, ddl,
  540. scp->discdata_out.opt_data, scp->addrrem, scp->addrloc);
  541. }
  542. void dn_nsp_return_disc(struct sk_buff *skb, unsigned char msgflg,
  543. unsigned short reason)
  544. {
  545. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  546. int ddl = 0;
  547. int gfp = GFP_ATOMIC;
  548. dn_nsp_do_disc(NULL, msgflg, reason, gfp, skb->dst, ddl,
  549. NULL, cb->src_port, cb->dst_port);
  550. }
  551. void dn_nsp_send_link(struct sock *sk, unsigned char lsflags, char fcval)
  552. {
  553. struct dn_scp *scp = DN_SK(sk);
  554. struct sk_buff *skb;
  555. unsigned char *ptr;
  556. int gfp = GFP_ATOMIC;
  557. if ((skb = dn_alloc_skb(sk, DN_MAX_NSP_DATA_HEADER + 2, gfp)) == NULL)
  558. return;
  559. skb_reserve(skb, DN_MAX_NSP_DATA_HEADER);
  560. ptr = skb_put(skb, 2);
  561. DN_SKB_CB(skb)->nsp_flags = 0x10;
  562. *ptr++ = lsflags;
  563. *ptr = fcval;
  564. dn_nsp_queue_xmit(sk, skb, gfp, 1);
  565. scp->persist = dn_nsp_persist(sk);
  566. scp->persist_fxn = dn_nsp_xmit_timeout;
  567. }
  568. static int dn_nsp_retrans_conninit(struct sock *sk)
  569. {
  570. struct dn_scp *scp = DN_SK(sk);
  571. if (scp->state == DN_CI)
  572. dn_nsp_send_conninit(sk, NSP_RCI);
  573. return 0;
  574. }
  575. void dn_nsp_send_conninit(struct sock *sk, unsigned char msgflg)
  576. {
  577. struct dn_scp *scp = DN_SK(sk);
  578. struct nsp_conn_init_msg *msg;
  579. unsigned char aux;
  580. unsigned char menuver;
  581. struct dn_skb_cb *cb;
  582. unsigned char type = 1;
  583. int allocation = (msgflg == NSP_CI) ? sk->sk_allocation : GFP_ATOMIC;
  584. struct sk_buff *skb = dn_alloc_skb(sk, 200, allocation);
  585. if (!skb)
  586. return;
  587. cb = DN_SKB_CB(skb);
  588. msg = (struct nsp_conn_init_msg *)skb_put(skb,sizeof(*msg));
  589. msg->msgflg = msgflg;
  590. msg->dstaddr = 0x0000; /* Remote Node will assign it*/
  591. msg->srcaddr = scp->addrloc;
  592. msg->services = scp->services_loc; /* Requested flow control */
  593. msg->info = scp->info_loc; /* Version Number */
  594. msg->segsize = dn_htons(scp->segsize_loc); /* Max segment size */
  595. if (scp->peer.sdn_objnum)
  596. type = 0;
  597. skb_put(skb, dn_sockaddr2username(&scp->peer, skb->tail, type));
  598. skb_put(skb, dn_sockaddr2username(&scp->addr, skb->tail, 2));
  599. menuver = DN_MENUVER_ACC | DN_MENUVER_USR;
  600. if (scp->peer.sdn_flags & SDF_PROXY)
  601. menuver |= DN_MENUVER_PRX;
  602. if (scp->peer.sdn_flags & SDF_UICPROXY)
  603. menuver |= DN_MENUVER_UIC;
  604. *skb_put(skb, 1) = menuver; /* Menu Version */
  605. aux = scp->accessdata.acc_userl;
  606. *skb_put(skb, 1) = aux;
  607. if (aux > 0)
  608. memcpy(skb_put(skb, aux), scp->accessdata.acc_user, aux);
  609. aux = scp->accessdata.acc_passl;
  610. *skb_put(skb, 1) = aux;
  611. if (aux > 0)
  612. memcpy(skb_put(skb, aux), scp->accessdata.acc_pass, aux);
  613. aux = scp->accessdata.acc_accl;
  614. *skb_put(skb, 1) = aux;
  615. if (aux > 0)
  616. memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux);
  617. aux = scp->conndata_out.opt_optl;
  618. *skb_put(skb, 1) = aux;
  619. if (aux > 0)
  620. memcpy(skb_put(skb,aux), scp->conndata_out.opt_data, aux);
  621. scp->persist = dn_nsp_persist(sk);
  622. scp->persist_fxn = dn_nsp_retrans_conninit;
  623. cb->rt_flags = DN_RT_F_RQR;
  624. dn_nsp_send(skb);
  625. }