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