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