Linux Audio

Check our new training course

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