dn_nsp_out.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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/timer.h>
  42. #include <linux/string.h>
  43. #include <linux/sockios.h>
  44. #include <linux/net.h>
  45. #include <linux/netdevice.h>
  46. #include <linux/inet.h>
  47. #include <linux/route.h>
  48. #include <linux/slab.h>
  49. #include <net/sock.h>
  50. #include <linux/fcntl.h>
  51. #include <linux/mm.h>
  52. #include <linux/termios.h>
  53. #include <linux/interrupt.h>
  54. #include <linux/proc_fs.h>
  55. #include <linux/stat.h>
  56. #include <linux/init.h>
  57. #include <linux/poll.h>
  58. #include <linux/if_packet.h>
  59. #include <net/neighbour.h>
  60. #include <net/dst.h>
  61. #include <net/flow.h>
  62. #include <net/dn.h>
  63. #include <net/dn_nsp.h>
  64. #include <net/dn_dev.h>
  65. #include <net/dn_route.h>
  66. static int nsp_backoff[NSP_MAXRXTSHIFT + 1] = { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
  67. static void dn_nsp_send(struct sk_buff *skb)
  68. {
  69. struct sock *sk = skb->sk;
  70. struct dn_scp *scp = DN_SK(sk);
  71. struct dst_entry *dst;
  72. struct flowidn fld;
  73. skb_reset_transport_header(skb);
  74. scp->stamp = jiffies;
  75. dst = sk_dst_check(sk, 0);
  76. if (dst) {
  77. try_again:
  78. skb_dst_set(skb, dst);
  79. dst_output(skb);
  80. return;
  81. }
  82. memset(&fld, 0, sizeof(fld));
  83. fld.flowidn_oif = sk->sk_bound_dev_if;
  84. fld.saddr = dn_saddr2dn(&scp->addr);
  85. fld.daddr = dn_saddr2dn(&scp->peer);
  86. dn_sk_ports_copy(&fld, scp);
  87. fld.flowidn_proto = DNPROTO_NSP;
  88. if (dn_route_output_sock(&sk->sk_dst_cache, &fld, sk, 0) == 0) {
  89. dst = sk_dst_get(sk);
  90. sk->sk_route_caps = dst->dev->features;
  91. goto try_again;
  92. }
  93. sk->sk_err = EHOSTUNREACH;
  94. if (!sock_flag(sk, SOCK_DEAD))
  95. sk->sk_state_change(sk);
  96. }
  97. /*
  98. * If sk == NULL, then we assume that we are supposed to be making
  99. * a routing layer skb. If sk != NULL, then we are supposed to be
  100. * creating an skb for the NSP layer.
  101. *
  102. * The eventual aim is for each socket to have a cached header size
  103. * for its outgoing packets, and to set hdr from this when sk != NULL.
  104. */
  105. struct sk_buff *dn_alloc_skb(struct sock *sk, int size, gfp_t pri)
  106. {
  107. struct sk_buff *skb;
  108. int hdr = 64;
  109. if ((skb = alloc_skb(size + hdr, pri)) == NULL)
  110. return NULL;
  111. skb->protocol = htons(ETH_P_DNA_RT);
  112. skb->pkt_type = PACKET_OUTGOING;
  113. if (sk)
  114. skb_set_owner_w(skb, sk);
  115. skb_reserve(skb, hdr);
  116. return skb;
  117. }
  118. /*
  119. * Calculate persist timer based upon the smoothed round
  120. * trip time and the variance. Backoff according to the
  121. * nsp_backoff[] array.
  122. */
  123. unsigned long dn_nsp_persist(struct sock *sk)
  124. {
  125. struct dn_scp *scp = DN_SK(sk);
  126. unsigned long t = ((scp->nsp_srtt >> 2) + scp->nsp_rttvar) >> 1;
  127. t *= nsp_backoff[scp->nsp_rxtshift];
  128. if (t < HZ) t = HZ;
  129. if (t > (600*HZ)) t = (600*HZ);
  130. if (scp->nsp_rxtshift < NSP_MAXRXTSHIFT)
  131. scp->nsp_rxtshift++;
  132. /* printk(KERN_DEBUG "rxtshift %lu, t=%lu\n", scp->nsp_rxtshift, t); */
  133. return t;
  134. }
  135. /*
  136. * This is called each time we get an estimate for the rtt
  137. * on the link.
  138. */
  139. static void dn_nsp_rtt(struct sock *sk, long rtt)
  140. {
  141. struct dn_scp *scp = DN_SK(sk);
  142. long srtt = (long)scp->nsp_srtt;
  143. long rttvar = (long)scp->nsp_rttvar;
  144. long delta;
  145. /*
  146. * If the jiffies clock flips over in the middle of timestamp
  147. * gathering this value might turn out negative, so we make sure
  148. * that is it always positive here.
  149. */
  150. if (rtt < 0)
  151. rtt = -rtt;
  152. /*
  153. * Add new rtt to smoothed average
  154. */
  155. delta = ((rtt << 3) - srtt);
  156. srtt += (delta >> 3);
  157. if (srtt >= 1)
  158. scp->nsp_srtt = (unsigned long)srtt;
  159. else
  160. scp->nsp_srtt = 1;
  161. /*
  162. * Add new rtt varience to smoothed varience
  163. */
  164. delta >>= 1;
  165. rttvar += ((((delta>0)?(delta):(-delta)) - rttvar) >> 2);
  166. if (rttvar >= 1)
  167. scp->nsp_rttvar = (unsigned long)rttvar;
  168. else
  169. scp->nsp_rttvar = 1;
  170. /* printk(KERN_DEBUG "srtt=%lu rttvar=%lu\n", scp->nsp_srtt, scp->nsp_rttvar); */
  171. }
  172. /**
  173. * dn_nsp_clone_and_send - Send a data packet by cloning it
  174. * @skb: The packet to clone and transmit
  175. * @gfp: memory allocation flag
  176. *
  177. * Clone a queued data or other data packet and transmit it.
  178. *
  179. * Returns: The number of times the packet has been sent previously
  180. */
  181. static inline unsigned int dn_nsp_clone_and_send(struct sk_buff *skb,
  182. gfp_t gfp)
  183. {
  184. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  185. struct sk_buff *skb2;
  186. int ret = 0;
  187. if ((skb2 = skb_clone(skb, gfp)) != NULL) {
  188. ret = cb->xmit_count;
  189. cb->xmit_count++;
  190. cb->stamp = jiffies;
  191. skb2->sk = skb->sk;
  192. dn_nsp_send(skb2);
  193. }
  194. return ret;
  195. }
  196. /**
  197. * dn_nsp_output - Try and send something from socket queues
  198. * @sk: The socket whose queues are to be investigated
  199. *
  200. * Try and send the packet on the end of the data and other data queues.
  201. * Other data gets priority over data, and if we retransmit a packet we
  202. * reduce the window by dividing it in two.
  203. *
  204. */
  205. void dn_nsp_output(struct sock *sk)
  206. {
  207. struct dn_scp *scp = DN_SK(sk);
  208. struct sk_buff *skb;
  209. unsigned int reduce_win = 0;
  210. /*
  211. * First we check for otherdata/linkservice messages
  212. */
  213. if ((skb = skb_peek(&scp->other_xmit_queue)) != NULL)
  214. reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC);
  215. /*
  216. * If we may not send any data, we don't.
  217. * If we are still trying to get some other data down the
  218. * channel, we don't try and send any data.
  219. */
  220. if (reduce_win || (scp->flowrem_sw != DN_SEND))
  221. goto recalc_window;
  222. if ((skb = skb_peek(&scp->data_xmit_queue)) != NULL)
  223. reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC);
  224. /*
  225. * If we've sent any frame more than once, we cut the
  226. * send window size in half. There is always a minimum
  227. * window size of one available.
  228. */
  229. recalc_window:
  230. if (reduce_win) {
  231. scp->snd_window >>= 1;
  232. if (scp->snd_window < NSP_MIN_WINDOW)
  233. scp->snd_window = NSP_MIN_WINDOW;
  234. }
  235. }
  236. int dn_nsp_xmit_timeout(struct sock *sk)
  237. {
  238. struct dn_scp *scp = DN_SK(sk);
  239. dn_nsp_output(sk);
  240. if (!skb_queue_empty(&scp->data_xmit_queue) ||
  241. !skb_queue_empty(&scp->other_xmit_queue))
  242. scp->persist = dn_nsp_persist(sk);
  243. return 0;
  244. }
  245. static inline __le16 *dn_mk_common_header(struct dn_scp *scp, struct sk_buff *skb, unsigned char msgflag, int len)
  246. {
  247. unsigned char *ptr = skb_push(skb, len);
  248. BUG_ON(len < 5);
  249. *ptr++ = msgflag;
  250. *((__le16 *)ptr) = scp->addrrem;
  251. ptr += 2;
  252. *((__le16 *)ptr) = scp->addrloc;
  253. ptr += 2;
  254. return (__le16 __force *)ptr;
  255. }
  256. static __le16 *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned char msgflag, int hlen, int other)
  257. {
  258. struct dn_scp *scp = DN_SK(sk);
  259. unsigned short acknum = scp->numdat_rcv & 0x0FFF;
  260. unsigned short ackcrs = scp->numoth_rcv & 0x0FFF;
  261. __le16 *ptr;
  262. BUG_ON(hlen < 9);
  263. scp->ackxmt_dat = acknum;
  264. scp->ackxmt_oth = ackcrs;
  265. acknum |= 0x8000;
  266. ackcrs |= 0x8000;
  267. /* If this is an "other data/ack" message, swap acknum and ackcrs */
  268. if (other) {
  269. unsigned short tmp = acknum;
  270. acknum = ackcrs;
  271. ackcrs = tmp;
  272. }
  273. /* Set "cross subchannel" bit in ackcrs */
  274. ackcrs |= 0x2000;
  275. ptr = dn_mk_common_header(scp, skb, msgflag, hlen);
  276. *ptr++ = cpu_to_le16(acknum);
  277. *ptr++ = cpu_to_le16(ackcrs);
  278. return ptr;
  279. }
  280. static __le16 *dn_nsp_mk_data_header(struct sock *sk, struct sk_buff *skb, int oth)
  281. {
  282. struct dn_scp *scp = DN_SK(sk);
  283. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  284. __le16 *ptr = dn_mk_ack_header(sk, skb, cb->nsp_flags, 11, oth);
  285. if (unlikely(oth)) {
  286. cb->segnum = scp->numoth;
  287. seq_add(&scp->numoth, 1);
  288. } else {
  289. cb->segnum = scp->numdat;
  290. seq_add(&scp->numdat, 1);
  291. }
  292. *(ptr++) = cpu_to_le16(cb->segnum);
  293. return ptr;
  294. }
  295. void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb,
  296. gfp_t gfp, int oth)
  297. {
  298. struct dn_scp *scp = DN_SK(sk);
  299. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  300. unsigned long t = ((scp->nsp_srtt >> 2) + scp->nsp_rttvar) >> 1;
  301. cb->xmit_count = 0;
  302. dn_nsp_mk_data_header(sk, skb, oth);
  303. /*
  304. * Slow start: If we have been idle for more than
  305. * one RTT, then reset window to min size.
  306. */
  307. if ((jiffies - scp->stamp) > t)
  308. scp->snd_window = NSP_MIN_WINDOW;
  309. if (oth)
  310. skb_queue_tail(&scp->other_xmit_queue, skb);
  311. else
  312. skb_queue_tail(&scp->data_xmit_queue, skb);
  313. if (scp->flowrem_sw != DN_SEND)
  314. return;
  315. dn_nsp_clone_and_send(skb, gfp);
  316. }
  317. int dn_nsp_check_xmit_queue(struct sock *sk, struct sk_buff *skb, struct sk_buff_head *q, unsigned short acknum)
  318. {
  319. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  320. struct dn_scp *scp = DN_SK(sk);
  321. struct sk_buff *skb2, *n, *ack = NULL;
  322. int wakeup = 0;
  323. int try_retrans = 0;
  324. unsigned long reftime = cb->stamp;
  325. unsigned long pkttime;
  326. unsigned short xmit_count;
  327. unsigned short segnum;
  328. skb_queue_walk_safe(q, skb2, n) {
  329. struct dn_skb_cb *cb2 = DN_SKB_CB(skb2);
  330. if (dn_before_or_equal(cb2->segnum, acknum))
  331. ack = skb2;
  332. /* printk(KERN_DEBUG "ack: %s %04x %04x\n", ack ? "ACK" : "SKIP", (int)cb2->segnum, (int)acknum); */
  333. if (ack == NULL)
  334. continue;
  335. /* printk(KERN_DEBUG "check_xmit_queue: %04x, %d\n", acknum, cb2->xmit_count); */
  336. /* Does _last_ packet acked have xmit_count > 1 */
  337. try_retrans = 0;
  338. /* Remember to wake up the sending process */
  339. wakeup = 1;
  340. /* Keep various statistics */
  341. pkttime = cb2->stamp;
  342. xmit_count = cb2->xmit_count;
  343. segnum = cb2->segnum;
  344. /* Remove and drop ack'ed packet */
  345. skb_unlink(ack, q);
  346. kfree_skb(ack);
  347. ack = NULL;
  348. /*
  349. * We don't expect to see acknowledgements for packets we
  350. * haven't sent yet.
  351. */
  352. WARN_ON(xmit_count == 0);
  353. /*
  354. * If the packet has only been sent once, we can use it
  355. * to calculate the RTT and also open the window a little
  356. * further.
  357. */
  358. if (xmit_count == 1) {
  359. if (dn_equal(segnum, acknum))
  360. dn_nsp_rtt(sk, (long)(pkttime - reftime));
  361. if (scp->snd_window < scp->max_window)
  362. scp->snd_window++;
  363. }
  364. /*
  365. * Packet has been sent more than once. If this is the last
  366. * packet to be acknowledged then we want to send the next
  367. * packet in the send queue again (assumes the remote host does
  368. * go-back-N error control).
  369. */
  370. if (xmit_count > 1)
  371. try_retrans = 1;
  372. }
  373. if (try_retrans)
  374. dn_nsp_output(sk);
  375. return wakeup;
  376. }
  377. void dn_nsp_send_data_ack(struct sock *sk)
  378. {
  379. struct sk_buff *skb = NULL;
  380. if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL)
  381. return;
  382. skb_reserve(skb, 9);
  383. dn_mk_ack_header(sk, skb, 0x04, 9, 0);
  384. dn_nsp_send(skb);
  385. }
  386. void dn_nsp_send_oth_ack(struct sock *sk)
  387. {
  388. struct sk_buff *skb = NULL;
  389. if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL)
  390. return;
  391. skb_reserve(skb, 9);
  392. dn_mk_ack_header(sk, skb, 0x14, 9, 1);
  393. dn_nsp_send(skb);
  394. }
  395. void dn_send_conn_ack (struct sock *sk)
  396. {
  397. struct dn_scp *scp = DN_SK(sk);
  398. struct sk_buff *skb = NULL;
  399. struct nsp_conn_ack_msg *msg;
  400. if ((skb = dn_alloc_skb(sk, 3, sk->sk_allocation)) == NULL)
  401. return;
  402. msg = (struct nsp_conn_ack_msg *)skb_put(skb, 3);
  403. msg->msgflg = 0x24;
  404. msg->dstaddr = scp->addrrem;
  405. dn_nsp_send(skb);
  406. }
  407. void dn_nsp_delayed_ack(struct sock *sk)
  408. {
  409. struct dn_scp *scp = DN_SK(sk);
  410. if (scp->ackxmt_oth != scp->numoth_rcv)
  411. dn_nsp_send_oth_ack(sk);
  412. if (scp->ackxmt_dat != scp->numdat_rcv)
  413. dn_nsp_send_data_ack(sk);
  414. }
  415. static int dn_nsp_retrans_conn_conf(struct sock *sk)
  416. {
  417. struct dn_scp *scp = DN_SK(sk);
  418. if (scp->state == DN_CC)
  419. dn_send_conn_conf(sk, GFP_ATOMIC);
  420. return 0;
  421. }
  422. void dn_send_conn_conf(struct sock *sk, gfp_t gfp)
  423. {
  424. struct dn_scp *scp = DN_SK(sk);
  425. struct sk_buff *skb = NULL;
  426. struct nsp_conn_init_msg *msg;
  427. __u8 len = (__u8)le16_to_cpu(scp->conndata_out.opt_optl);
  428. if ((skb = dn_alloc_skb(sk, 50 + len, gfp)) == NULL)
  429. return;
  430. msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg));
  431. msg->msgflg = 0x28;
  432. msg->dstaddr = scp->addrrem;
  433. msg->srcaddr = scp->addrloc;
  434. msg->services = scp->services_loc;
  435. msg->info = scp->info_loc;
  436. msg->segsize = cpu_to_le16(scp->segsize_loc);
  437. *skb_put(skb,1) = len;
  438. if (len > 0)
  439. memcpy(skb_put(skb, len), scp->conndata_out.opt_data, len);
  440. dn_nsp_send(skb);
  441. scp->persist = dn_nsp_persist(sk);
  442. scp->persist_fxn = dn_nsp_retrans_conn_conf;
  443. }
  444. static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
  445. unsigned short reason, gfp_t gfp,
  446. struct dst_entry *dst,
  447. int ddl, unsigned char *dd, __le16 rem, __le16 loc)
  448. {
  449. struct sk_buff *skb = NULL;
  450. int size = 7 + ddl + ((msgflg == NSP_DISCINIT) ? 1 : 0);
  451. unsigned char *msg;
  452. if ((dst == NULL) || (rem == 0)) {
  453. net_dbg_ratelimited("DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p\n",
  454. le16_to_cpu(rem), dst);
  455. return;
  456. }
  457. if ((skb = dn_alloc_skb(sk, size, gfp)) == NULL)
  458. return;
  459. msg = skb_put(skb, size);
  460. *msg++ = msgflg;
  461. *(__le16 *)msg = rem;
  462. msg += 2;
  463. *(__le16 *)msg = loc;
  464. msg += 2;
  465. *(__le16 *)msg = cpu_to_le16(reason);
  466. msg += 2;
  467. if (msgflg == NSP_DISCINIT)
  468. *msg++ = ddl;
  469. if (ddl) {
  470. memcpy(msg, dd, ddl);
  471. }
  472. /*
  473. * This doesn't go via the dn_nsp_send() function since we need
  474. * to be able to send disc packets out which have no socket
  475. * associations.
  476. */
  477. skb_dst_set(skb, dst_clone(dst));
  478. dst_output(skb);
  479. }
  480. void dn_nsp_send_disc(struct sock *sk, unsigned char msgflg,
  481. unsigned short reason, gfp_t gfp)
  482. {
  483. struct dn_scp *scp = DN_SK(sk);
  484. int ddl = 0;
  485. if (msgflg == NSP_DISCINIT)
  486. ddl = le16_to_cpu(scp->discdata_out.opt_optl);
  487. if (reason == 0)
  488. reason = le16_to_cpu(scp->discdata_out.opt_status);
  489. dn_nsp_do_disc(sk, msgflg, reason, gfp, __sk_dst_get(sk), ddl,
  490. scp->discdata_out.opt_data, scp->addrrem, scp->addrloc);
  491. }
  492. void dn_nsp_return_disc(struct sk_buff *skb, unsigned char msgflg,
  493. unsigned short reason)
  494. {
  495. struct dn_skb_cb *cb = DN_SKB_CB(skb);
  496. int ddl = 0;
  497. gfp_t gfp = GFP_ATOMIC;
  498. dn_nsp_do_disc(NULL, msgflg, reason, gfp, skb_dst(skb), ddl,
  499. NULL, cb->src_port, cb->dst_port);
  500. }
  501. void dn_nsp_send_link(struct sock *sk, unsigned char lsflags, char fcval)
  502. {
  503. struct dn_scp *scp = DN_SK(sk);
  504. struct sk_buff *skb;
  505. unsigned char *ptr;
  506. gfp_t gfp = GFP_ATOMIC;
  507. if ((skb = dn_alloc_skb(sk, DN_MAX_NSP_DATA_HEADER + 2, gfp)) == NULL)
  508. return;
  509. skb_reserve(skb, DN_MAX_NSP_DATA_HEADER);
  510. ptr = skb_put(skb, 2);
  511. DN_SKB_CB(skb)->nsp_flags = 0x10;
  512. *ptr++ = lsflags;
  513. *ptr = fcval;
  514. dn_nsp_queue_xmit(sk, skb, gfp, 1);
  515. scp->persist = dn_nsp_persist(sk);
  516. scp->persist_fxn = dn_nsp_xmit_timeout;
  517. }
  518. static int dn_nsp_retrans_conninit(struct sock *sk)
  519. {
  520. struct dn_scp *scp = DN_SK(sk);
  521. if (scp->state == DN_CI)
  522. dn_nsp_send_conninit(sk, NSP_RCI);
  523. return 0;
  524. }
  525. void dn_nsp_send_conninit(struct sock *sk, unsigned char msgflg)
  526. {
  527. struct dn_scp *scp = DN_SK(sk);
  528. struct nsp_conn_init_msg *msg;
  529. unsigned char aux;
  530. unsigned char menuver;
  531. struct dn_skb_cb *cb;
  532. unsigned char type = 1;
  533. gfp_t allocation = (msgflg == NSP_CI) ? sk->sk_allocation : GFP_ATOMIC;
  534. struct sk_buff *skb = dn_alloc_skb(sk, 200, allocation);
  535. if (!skb)
  536. return;
  537. cb = DN_SKB_CB(skb);
  538. msg = (struct nsp_conn_init_msg *)skb_put(skb,sizeof(*msg));
  539. msg->msgflg = msgflg;
  540. msg->dstaddr = 0x0000; /* Remote Node will assign it*/
  541. msg->srcaddr = scp->addrloc;
  542. msg->services = scp->services_loc; /* Requested flow control */
  543. msg->info = scp->info_loc; /* Version Number */
  544. msg->segsize = cpu_to_le16(scp->segsize_loc); /* Max segment size */
  545. if (scp->peer.sdn_objnum)
  546. type = 0;
  547. skb_put(skb, dn_sockaddr2username(&scp->peer,
  548. skb_tail_pointer(skb), type));
  549. skb_put(skb, dn_sockaddr2username(&scp->addr,
  550. skb_tail_pointer(skb), 2));
  551. menuver = DN_MENUVER_ACC | DN_MENUVER_USR;
  552. if (scp->peer.sdn_flags & SDF_PROXY)
  553. menuver |= DN_MENUVER_PRX;
  554. if (scp->peer.sdn_flags & SDF_UICPROXY)
  555. menuver |= DN_MENUVER_UIC;
  556. *skb_put(skb, 1) = menuver; /* Menu Version */
  557. aux = scp->accessdata.acc_userl;
  558. *skb_put(skb, 1) = aux;
  559. if (aux > 0)
  560. memcpy(skb_put(skb, aux), scp->accessdata.acc_user, aux);
  561. aux = scp->accessdata.acc_passl;
  562. *skb_put(skb, 1) = aux;
  563. if (aux > 0)
  564. memcpy(skb_put(skb, aux), scp->accessdata.acc_pass, aux);
  565. aux = scp->accessdata.acc_accl;
  566. *skb_put(skb, 1) = aux;
  567. if (aux > 0)
  568. memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux);
  569. aux = (__u8)le16_to_cpu(scp->conndata_out.opt_optl);
  570. *skb_put(skb, 1) = aux;
  571. if (aux > 0)
  572. memcpy(skb_put(skb, aux), scp->conndata_out.opt_data, aux);
  573. scp->persist = dn_nsp_persist(sk);
  574. scp->persist_fxn = dn_nsp_retrans_conninit;
  575. cb->rt_flags = DN_RT_F_RQR;
  576. dn_nsp_send(skb);
  577. }