blob: c2e21cd89b3cd273600e80b955f27f1b011d0658 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
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
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 flowi fl;
82
83 skb->h.raw = skb->data;
84 scp->stamp = jiffies;
85
86 dst = sk_dst_check(sk, 0);
87 if (dst) {
88try_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 */
Al Virodd0fc662005-10-07 07:46:04 +0100120struct sk_buff *dn_alloc_skb(struct sock *sk, int size, gfp_t pri)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
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 = __constant_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/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 * 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 */
Randy Dunlapf4a19a52005-10-04 22:41:48 -0700213static inline unsigned dn_nsp_clone_and_send(struct sk_buff *skb,
Al Virodd0fc662005-10-07 07:46:04 +0100214 gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
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 * @gfp: The memory allocation flags
235 *
236 * Try and send the packet on the end of the data and other data queues.
237 * Other data gets priority over data, and if we retransmit a packet we
238 * reduce the window by dividing it in two.
239 *
240 */
241void dn_nsp_output(struct sock *sk)
242{
243 struct dn_scp *scp = DN_SK(sk);
244 struct sk_buff *skb;
245 unsigned reduce_win = 0;
246
247 /*
248 * First we check for otherdata/linkservice messages
249 */
250 if ((skb = skb_peek(&scp->other_xmit_queue)) != NULL)
251 reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC);
252
253 /*
254 * If we may not send any data, we don't.
255 * If we are still trying to get some other data down the
256 * channel, we don't try and send any data.
257 */
258 if (reduce_win || (scp->flowrem_sw != DN_SEND))
259 goto recalc_window;
260
261 if ((skb = skb_peek(&scp->data_xmit_queue)) != NULL)
262 reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC);
263
264 /*
265 * If we've sent any frame more than once, we cut the
266 * send window size in half. There is always a minimum
267 * window size of one available.
268 */
269recalc_window:
270 if (reduce_win) {
271 scp->snd_window >>= 1;
272 if (scp->snd_window < NSP_MIN_WINDOW)
273 scp->snd_window = NSP_MIN_WINDOW;
274 }
275}
276
277int dn_nsp_xmit_timeout(struct sock *sk)
278{
279 struct dn_scp *scp = DN_SK(sk);
280
281 dn_nsp_output(sk);
282
David S. Millerb03efcf2005-07-08 14:57:23 -0700283 if (!skb_queue_empty(&scp->data_xmit_queue) ||
284 !skb_queue_empty(&scp->other_xmit_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 scp->persist = dn_nsp_persist(sk);
286
287 return 0;
288}
289
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800290static inline __le16 *dn_mk_common_header(struct dn_scp *scp, struct sk_buff *skb, unsigned char msgflag, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
292 unsigned char *ptr = skb_push(skb, len);
293
294 BUG_ON(len < 5);
295
296 *ptr++ = msgflag;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800297 *((__le16 *)ptr) = scp->addrrem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 ptr += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800299 *((__le16 *)ptr) = scp->addrloc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 ptr += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800301 return (__le16 __force *)ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800304static __le16 *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned char msgflag, int hlen, int other)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
306 struct dn_scp *scp = DN_SK(sk);
307 unsigned short acknum = scp->numdat_rcv & 0x0FFF;
308 unsigned short ackcrs = scp->numoth_rcv & 0x0FFF;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800309 __le16 *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 BUG_ON(hlen < 9);
312
313 scp->ackxmt_dat = acknum;
314 scp->ackxmt_oth = ackcrs;
315 acknum |= 0x8000;
316 ackcrs |= 0x8000;
317
318 /* If this is an "other data/ack" message, swap acknum and ackcrs */
319 if (other) {
320 unsigned short tmp = acknum;
321 acknum = ackcrs;
322 ackcrs = tmp;
323 }
324
325 /* Set "cross subchannel" bit in ackcrs */
326 ackcrs |= 0x2000;
327
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800328 ptr = (__le16 *)dn_mk_common_header(scp, skb, msgflag, hlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 *ptr++ = dn_htons(acknum);
331 *ptr++ = dn_htons(ackcrs);
332
333 return ptr;
334}
335
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800336static __le16 *dn_nsp_mk_data_header(struct sock *sk, struct sk_buff *skb, int oth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 struct dn_scp *scp = DN_SK(sk);
339 struct dn_skb_cb *cb = DN_SKB_CB(skb);
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800340 __le16 *ptr = dn_mk_ack_header(sk, skb, cb->nsp_flags, 11, oth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 if (unlikely(oth)) {
343 cb->segnum = scp->numoth;
344 seq_add(&scp->numoth, 1);
345 } else {
346 cb->segnum = scp->numdat;
347 seq_add(&scp->numdat, 1);
348 }
349 *(ptr++) = dn_htons(cb->segnum);
350
351 return ptr;
352}
353
Randy Dunlapf4a19a52005-10-04 22:41:48 -0700354void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb,
Al Virodd0fc662005-10-07 07:46:04 +0100355 gfp_t gfp, int oth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 struct dn_scp *scp = DN_SK(sk);
358 struct dn_skb_cb *cb = DN_SKB_CB(skb);
359 unsigned long t = ((scp->nsp_srtt >> 2) + scp->nsp_rttvar) >> 1;
360
361 cb->xmit_count = 0;
362 dn_nsp_mk_data_header(sk, skb, oth);
363
364 /*
365 * Slow start: If we have been idle for more than
366 * one RTT, then reset window to min size.
367 */
368 if ((jiffies - scp->stamp) > t)
369 scp->snd_window = NSP_MIN_WINDOW;
370
371 if (oth)
372 skb_queue_tail(&scp->other_xmit_queue, skb);
373 else
374 skb_queue_tail(&scp->data_xmit_queue, skb);
375
376 if (scp->flowrem_sw != DN_SEND)
377 return;
378
379 dn_nsp_clone_and_send(skb, gfp);
380}
381
382
383int dn_nsp_check_xmit_queue(struct sock *sk, struct sk_buff *skb, struct sk_buff_head *q, unsigned short acknum)
384{
385 struct dn_skb_cb *cb = DN_SKB_CB(skb);
386 struct dn_scp *scp = DN_SK(sk);
387 struct sk_buff *skb2, *list, *ack = NULL;
388 int wakeup = 0;
389 int try_retrans = 0;
390 unsigned long reftime = cb->stamp;
391 unsigned long pkttime;
392 unsigned short xmit_count;
393 unsigned short segnum;
394
395 skb2 = q->next;
396 list = (struct sk_buff *)q;
397 while(list != skb2) {
398 struct dn_skb_cb *cb2 = DN_SKB_CB(skb2);
399
400 if (dn_before_or_equal(cb2->segnum, acknum))
401 ack = skb2;
402
403 /* printk(KERN_DEBUG "ack: %s %04x %04x\n", ack ? "ACK" : "SKIP", (int)cb2->segnum, (int)acknum); */
404
405 skb2 = skb2->next;
406
407 if (ack == NULL)
408 continue;
409
410 /* printk(KERN_DEBUG "check_xmit_queue: %04x, %d\n", acknum, cb2->xmit_count); */
411
412 /* Does _last_ packet acked have xmit_count > 1 */
413 try_retrans = 0;
414 /* Remember to wake up the sending process */
415 wakeup = 1;
416 /* Keep various statistics */
417 pkttime = cb2->stamp;
418 xmit_count = cb2->xmit_count;
419 segnum = cb2->segnum;
420 /* Remove and drop ack'ed packet */
David S. Miller8728b832005-08-09 19:25:21 -0700421 skb_unlink(ack, q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 kfree_skb(ack);
423 ack = NULL;
424
425 /*
426 * We don't expect to see acknowledgements for packets we
427 * haven't sent yet.
428 */
429 WARN_ON(xmit_count == 0);
430
431 /*
432 * If the packet has only been sent once, we can use it
433 * to calculate the RTT and also open the window a little
434 * further.
435 */
436 if (xmit_count == 1) {
437 if (dn_equal(segnum, acknum))
438 dn_nsp_rtt(sk, (long)(pkttime - reftime));
439
440 if (scp->snd_window < scp->max_window)
441 scp->snd_window++;
442 }
443
444 /*
445 * Packet has been sent more than once. If this is the last
446 * packet to be acknowledged then we want to send the next
447 * packet in the send queue again (assumes the remote host does
448 * go-back-N error control).
449 */
450 if (xmit_count > 1)
451 try_retrans = 1;
452 }
453
454 if (try_retrans)
455 dn_nsp_output(sk);
456
457 return wakeup;
458}
459
460void dn_nsp_send_data_ack(struct sock *sk)
461{
462 struct sk_buff *skb = NULL;
463
464 if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL)
465 return;
466
467 skb_reserve(skb, 9);
468 dn_mk_ack_header(sk, skb, 0x04, 9, 0);
469 dn_nsp_send(skb);
470}
471
472void dn_nsp_send_oth_ack(struct sock *sk)
473{
474 struct sk_buff *skb = NULL;
475
476 if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL)
477 return;
478
479 skb_reserve(skb, 9);
480 dn_mk_ack_header(sk, skb, 0x14, 9, 1);
481 dn_nsp_send(skb);
482}
483
484
485void dn_send_conn_ack (struct sock *sk)
486{
487 struct dn_scp *scp = DN_SK(sk);
488 struct sk_buff *skb = NULL;
489 struct nsp_conn_ack_msg *msg;
490
491 if ((skb = dn_alloc_skb(sk, 3, sk->sk_allocation)) == NULL)
492 return;
493
494 msg = (struct nsp_conn_ack_msg *)skb_put(skb, 3);
495 msg->msgflg = 0x24;
496 msg->dstaddr = scp->addrrem;
497
498 dn_nsp_send(skb);
499}
500
501void dn_nsp_delayed_ack(struct sock *sk)
502{
503 struct dn_scp *scp = DN_SK(sk);
504
505 if (scp->ackxmt_oth != scp->numoth_rcv)
506 dn_nsp_send_oth_ack(sk);
507
508 if (scp->ackxmt_dat != scp->numdat_rcv)
509 dn_nsp_send_data_ack(sk);
510}
511
512static int dn_nsp_retrans_conn_conf(struct sock *sk)
513{
514 struct dn_scp *scp = DN_SK(sk);
515
516 if (scp->state == DN_CC)
517 dn_send_conn_conf(sk, GFP_ATOMIC);
518
519 return 0;
520}
521
Al Virodd0fc662005-10-07 07:46:04 +0100522void dn_send_conn_conf(struct sock *sk, gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
524 struct dn_scp *scp = DN_SK(sk);
525 struct sk_buff *skb = NULL;
526 struct nsp_conn_init_msg *msg;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800527 __u8 len = (__u8)dn_ntohs(scp->conndata_out.opt_optl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800529 if ((skb = dn_alloc_skb(sk, 50 + dn_ntohs(scp->conndata_out.opt_optl), gfp)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 return;
531
532 msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg));
533 msg->msgflg = 0x28;
534 msg->dstaddr = scp->addrrem;
535 msg->srcaddr = scp->addrloc;
536 msg->services = scp->services_loc;
537 msg->info = scp->info_loc;
538 msg->segsize = dn_htons(scp->segsize_loc);
539
540 *skb_put(skb,1) = len;
541
542 if (len > 0)
543 memcpy(skb_put(skb, len), scp->conndata_out.opt_data, len);
544
545
546 dn_nsp_send(skb);
547
548 scp->persist = dn_nsp_persist(sk);
549 scp->persist_fxn = dn_nsp_retrans_conn_conf;
550}
551
552
553static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
Al Virodd0fc662005-10-07 07:46:04 +0100554 unsigned short reason, gfp_t gfp,
Randy Dunlapf4a19a52005-10-04 22:41:48 -0700555 struct dst_entry *dst,
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800556 int ddl, unsigned char *dd, __le16 rem, __le16 loc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
558 struct sk_buff *skb = NULL;
559 int size = 7 + ddl + ((msgflg == NSP_DISCINIT) ? 1 : 0);
560 unsigned char *msg;
561
562 if ((dst == NULL) || (rem == 0)) {
563 if (net_ratelimit())
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800564 printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p\n", dn_ntohs(rem), dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return;
566 }
567
568 if ((skb = dn_alloc_skb(sk, size, gfp)) == NULL)
569 return;
570
571 msg = skb_put(skb, size);
572 *msg++ = msgflg;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800573 *(__le16 *)msg = rem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 msg += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800575 *(__le16 *)msg = loc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 msg += 2;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800577 *(__le16 *)msg = dn_htons(reason);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 msg += 2;
579 if (msgflg == NSP_DISCINIT)
580 *msg++ = ddl;
581
582 if (ddl) {
583 memcpy(msg, dd, ddl);
584 }
585
586 /*
587 * This doesn't go via the dn_nsp_send() function since we need
588 * to be able to send disc packets out which have no socket
589 * associations.
590 */
591 skb->dst = dst_clone(dst);
592 dst_output(skb);
593}
594
595
596void dn_nsp_send_disc(struct sock *sk, unsigned char msgflg,
Al Virodd0fc662005-10-07 07:46:04 +0100597 unsigned short reason, gfp_t gfp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
599 struct dn_scp *scp = DN_SK(sk);
600 int ddl = 0;
601
602 if (msgflg == NSP_DISCINIT)
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800603 ddl = dn_ntohs(scp->discdata_out.opt_optl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 if (reason == 0)
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800606 reason = dn_ntohs(scp->discdata_out.opt_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608 dn_nsp_do_disc(sk, msgflg, reason, gfp, sk->sk_dst_cache, ddl,
609 scp->discdata_out.opt_data, scp->addrrem, scp->addrloc);
610}
611
612
613void dn_nsp_return_disc(struct sk_buff *skb, unsigned char msgflg,
614 unsigned short reason)
615{
616 struct dn_skb_cb *cb = DN_SKB_CB(skb);
617 int ddl = 0;
Al Virodd0fc662005-10-07 07:46:04 +0100618 gfp_t gfp = GFP_ATOMIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 dn_nsp_do_disc(NULL, msgflg, reason, gfp, skb->dst, ddl,
621 NULL, cb->src_port, cb->dst_port);
622}
623
624
625void dn_nsp_send_link(struct sock *sk, unsigned char lsflags, char fcval)
626{
627 struct dn_scp *scp = DN_SK(sk);
628 struct sk_buff *skb;
629 unsigned char *ptr;
Al Virodd0fc662005-10-07 07:46:04 +0100630 gfp_t gfp = GFP_ATOMIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 if ((skb = dn_alloc_skb(sk, DN_MAX_NSP_DATA_HEADER + 2, gfp)) == NULL)
633 return;
634
635 skb_reserve(skb, DN_MAX_NSP_DATA_HEADER);
636 ptr = skb_put(skb, 2);
637 DN_SKB_CB(skb)->nsp_flags = 0x10;
638 *ptr++ = lsflags;
639 *ptr = fcval;
640
641 dn_nsp_queue_xmit(sk, skb, gfp, 1);
642
643 scp->persist = dn_nsp_persist(sk);
644 scp->persist_fxn = dn_nsp_xmit_timeout;
645}
646
647static int dn_nsp_retrans_conninit(struct sock *sk)
648{
649 struct dn_scp *scp = DN_SK(sk);
650
651 if (scp->state == DN_CI)
652 dn_nsp_send_conninit(sk, NSP_RCI);
653
654 return 0;
655}
656
657void dn_nsp_send_conninit(struct sock *sk, unsigned char msgflg)
658{
659 struct dn_scp *scp = DN_SK(sk);
660 struct nsp_conn_init_msg *msg;
661 unsigned char aux;
662 unsigned char menuver;
663 struct dn_skb_cb *cb;
664 unsigned char type = 1;
Al Virodd0fc662005-10-07 07:46:04 +0100665 gfp_t allocation = (msgflg == NSP_CI) ? sk->sk_allocation : GFP_ATOMIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 struct sk_buff *skb = dn_alloc_skb(sk, 200, allocation);
667
668 if (!skb)
669 return;
670
671 cb = DN_SKB_CB(skb);
672 msg = (struct nsp_conn_init_msg *)skb_put(skb,sizeof(*msg));
673
674 msg->msgflg = msgflg;
675 msg->dstaddr = 0x0000; /* Remote Node will assign it*/
676
677 msg->srcaddr = scp->addrloc;
678 msg->services = scp->services_loc; /* Requested flow control */
679 msg->info = scp->info_loc; /* Version Number */
680 msg->segsize = dn_htons(scp->segsize_loc); /* Max segment size */
681
682 if (scp->peer.sdn_objnum)
683 type = 0;
684
685 skb_put(skb, dn_sockaddr2username(&scp->peer, skb->tail, type));
686 skb_put(skb, dn_sockaddr2username(&scp->addr, skb->tail, 2));
687
688 menuver = DN_MENUVER_ACC | DN_MENUVER_USR;
689 if (scp->peer.sdn_flags & SDF_PROXY)
690 menuver |= DN_MENUVER_PRX;
691 if (scp->peer.sdn_flags & SDF_UICPROXY)
692 menuver |= DN_MENUVER_UIC;
693
694 *skb_put(skb, 1) = menuver; /* Menu Version */
695
696 aux = scp->accessdata.acc_userl;
697 *skb_put(skb, 1) = aux;
698 if (aux > 0)
699 memcpy(skb_put(skb, aux), scp->accessdata.acc_user, aux);
700
701 aux = scp->accessdata.acc_passl;
702 *skb_put(skb, 1) = aux;
703 if (aux > 0)
704 memcpy(skb_put(skb, aux), scp->accessdata.acc_pass, aux);
705
706 aux = scp->accessdata.acc_accl;
707 *skb_put(skb, 1) = aux;
708 if (aux > 0)
709 memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux);
710
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800711 aux = (__u8)dn_ntohs(scp->conndata_out.opt_optl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 *skb_put(skb, 1) = aux;
713 if (aux > 0)
714 memcpy(skb_put(skb,aux), scp->conndata_out.opt_data, aux);
715
716 scp->persist = dn_nsp_persist(sk);
717 scp->persist_fxn = dn_nsp_retrans_conninit;
718
719 cb->rt_flags = DN_RT_F_RQR;
720
721 dn_nsp_send(skb);
722}
723