dn_nsp_out.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:18k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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