Blame view

net/decnet/dn_nsp_out.c 17.6 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  
  /*
   * DECnet       An implementation of the DECnet protocol suite for the LINUX
   *              operating system.  DECnet is implemented using the  BSD Socket
   *              interface as the means of communication with the user level.
   *
   *              DECnet Network Services Protocol (Output)
   *
   * Author:      Eduardo Marcelo Serrat <emserrat@geocities.com>
   *
   * Changes:
   *
   *    Steve Whitehouse:  Split into dn_nsp_in.c and dn_nsp_out.c from
   *                       original dn_nsp.c.
   *    Steve Whitehouse:  Updated to work with my new routing architecture.
   *    Steve Whitehouse:  Added changes from Eduardo Serrat's patches.
   *    Steve Whitehouse:  Now conninits have the "return" bit set.
   *    Steve Whitehouse:  Fixes to check alloc'd skbs are non NULL!
   *                       Moved output state machine into one function
   *    Steve Whitehouse:  New output state machine
   *         Paul Koning:  Connect Confirm message fix.
   *      Eduardo Serrat:  Fix to stop dn_nsp_do_disc() sending malformed packets.
   *    Steve Whitehouse:  dn_nsp_output() and friends needed a spring clean
   *    Steve Whitehouse:  Moved dn_nsp_send() in here from route.h
   */
  
  /******************************************************************************
      (c) 1995-1998 E.M. Serrat		emserrat@geocities.com
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
29

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      any later version.
  
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.
  *******************************************************************************/
  
  #include <linux/errno.h>
  #include <linux/types.h>
  #include <linux/socket.h>
  #include <linux/in.h>
  #include <linux/kernel.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
50
51
52
  #include <linux/timer.h>
  #include <linux/string.h>
  #include <linux/sockios.h>
  #include <linux/net.h>
  #include <linux/netdevice.h>
  #include <linux/inet.h>
  #include <linux/route.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
53
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
56
57
  #include <net/sock.h>
  #include <asm/system.h>
  #include <linux/fcntl.h>
  #include <linux/mm.h>
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
58
  #include <linux/termios.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  #include <linux/interrupt.h>
  #include <linux/proc_fs.h>
  #include <linux/stat.h>
  #include <linux/init.h>
  #include <linux/poll.h>
  #include <linux/if_packet.h>
  #include <net/neighbour.h>
  #include <net/dst.h>
  #include <net/flow.h>
  #include <net/dn.h>
  #include <net/dn_nsp.h>
  #include <net/dn_dev.h>
  #include <net/dn_route.h>
  
  
  static int nsp_backoff[NSP_MAXRXTSHIFT + 1] = { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
  
  static void dn_nsp_send(struct sk_buff *skb)
  {
  	struct sock *sk = skb->sk;
  	struct dn_scp *scp = DN_SK(sk);
  	struct dst_entry *dst;
bef55aebd   David S. Miller   decnet: Convert t...
81
  	struct flowidn fld;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82

badff6d01   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
83
  	skb_reset_transport_header(skb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
85
86
87
88
  	scp->stamp = jiffies;
  
  	dst = sk_dst_check(sk, 0);
  	if (dst) {
  try_again:
adf30907d   Eric Dumazet   net: skb->dst acc...
89
  		skb_dst_set(skb, dst);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
  		dst_output(skb);
  		return;
  	}
bef55aebd   David S. Miller   decnet: Convert t...
93
94
95
96
97
98
99
  	memset(&fld, 0, sizeof(fld));
  	fld.flowidn_oif = sk->sk_bound_dev_if;
  	fld.saddr = dn_saddr2dn(&scp->addr);
  	fld.daddr = dn_saddr2dn(&scp->peer);
  	dn_sk_ports_copy(&fld, scp);
  	fld.flowidn_proto = DNPROTO_NSP;
  	if (dn_route_output_sock(&sk->sk_dst_cache, &fld, sk, 0) == 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  		dst = sk_dst_get(sk);
  		sk->sk_route_caps = dst->dev->features;
  		goto try_again;
  	}
  
  	sk->sk_err = EHOSTUNREACH;
  	if (!sock_flag(sk, SOCK_DEAD))
  		sk->sk_state_change(sk);
  }
  
  
  /*
   * If sk == NULL, then we assume that we are supposed to be making
   * a routing layer skb. If sk != NULL, then we are supposed to be
   * creating an skb for the NSP layer.
   *
   * The eventual aim is for each socket to have a cached header size
   * for its outgoing packets, and to set hdr from this when sk != NULL.
   */
dd0fc66fb   Al Viro   [PATCH] gfp flags...
119
  struct sk_buff *dn_alloc_skb(struct sock *sk, int size, gfp_t pri)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
121
122
123
124
125
  {
  	struct sk_buff *skb;
  	int hdr = 64;
  
  	if ((skb = alloc_skb(size + hdr, pri)) == NULL)
  		return NULL;
b98999dc3   YOSHIFUJI Hideaki   [DECNET]: Use hto...
126
  	skb->protocol = htons(ETH_P_DNA_RT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
128
129
130
131
132
133
134
135
136
137
  	skb->pkt_type = PACKET_OUTGOING;
  
  	if (sk)
  		skb_set_owner_w(skb, sk);
  
  	skb_reserve(skb, hdr);
  
  	return skb;
  }
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
   * Calculate persist timer based upon the smoothed round
   * trip time and the variance. Backoff according to the
   * nsp_backoff[] array.
   */
  unsigned long dn_nsp_persist(struct sock *sk)
  {
  	struct dn_scp *scp = DN_SK(sk);
  
  	unsigned long t = ((scp->nsp_srtt >> 2) + scp->nsp_rttvar) >> 1;
  
  	t *= nsp_backoff[scp->nsp_rxtshift];
  
  	if (t < HZ) t = HZ;
  	if (t > (600*HZ)) t = (600*HZ);
  
  	if (scp->nsp_rxtshift < NSP_MAXRXTSHIFT)
  		scp->nsp_rxtshift++;
  
  	/* printk(KERN_DEBUG "rxtshift %lu, t=%lu
  ", scp->nsp_rxtshift, t); */
  
  	return t;
  }
  
  /*
   * This is called each time we get an estimate for the rtt
   * on the link.
   */
  static void dn_nsp_rtt(struct sock *sk, long rtt)
  {
  	struct dn_scp *scp = DN_SK(sk);
  	long srtt = (long)scp->nsp_srtt;
  	long rttvar = (long)scp->nsp_rttvar;
  	long delta;
  
  	/*
  	 * If the jiffies clock flips over in the middle of timestamp
  	 * gathering this value might turn out negative, so we make sure
  	 * that is it always positive here.
  	 */
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
178
  	if (rtt < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
182
183
184
  		rtt = -rtt;
  	/*
  	 * Add new rtt to smoothed average
  	 */
  	delta = ((rtt << 3) - srtt);
  	srtt += (delta >> 3);
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
185
  	if (srtt >= 1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
187
188
189
190
191
192
193
194
  		scp->nsp_srtt = (unsigned long)srtt;
  	else
  		scp->nsp_srtt = 1;
  
  	/*
  	 * Add new rtt varience to smoothed varience
  	 */
  	delta >>= 1;
  	rttvar += ((((delta>0)?(delta):(-delta)) - rttvar) >> 2);
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
195
  	if (rttvar >= 1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
  		scp->nsp_rttvar = (unsigned long)rttvar;
  	else
  		scp->nsp_rttvar = 1;
  
  	/* printk(KERN_DEBUG "srtt=%lu rttvar=%lu
  ", scp->nsp_srtt, scp->nsp_rttvar); */
  }
  
  /**
   * dn_nsp_clone_and_send - Send a data packet by cloning it
   * @skb: The packet to clone and transmit
   * @gfp: memory allocation flag
   *
   * Clone a queued data or other data packet and transmit it.
   *
   * Returns: The number of times the packet has been sent previously
   */
f4a19a56e   Randy Dunlap   [DECNET]: fix spa...
213
  static inline unsigned dn_nsp_clone_and_send(struct sk_buff *skb,
dd0fc66fb   Al Viro   [PATCH] gfp flags...
214
  					     gfp_t gfp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
  {
  	struct dn_skb_cb *cb = DN_SKB_CB(skb);
  	struct sk_buff *skb2;
  	int ret = 0;
  
  	if ((skb2 = skb_clone(skb, gfp)) != NULL) {
  		ret = cb->xmit_count;
  		cb->xmit_count++;
  		cb->stamp = jiffies;
  		skb2->sk = skb->sk;
  		dn_nsp_send(skb2);
  	}
  
  	return ret;
  }
  
  /**
   * dn_nsp_output - Try and send something from socket queues
   * @sk: The socket whose queues are to be investigated
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
   *
   * Try and send the packet on the end of the data and other data queues.
   * Other data gets priority over data, and if we retransmit a packet we
   * reduce the window by dividing it in two.
   *
   */
  void dn_nsp_output(struct sock *sk)
  {
  	struct dn_scp *scp = DN_SK(sk);
  	struct sk_buff *skb;
  	unsigned reduce_win = 0;
  
  	/*
  	 * First we check for otherdata/linkservice messages
  	 */
  	if ((skb = skb_peek(&scp->other_xmit_queue)) != NULL)
  		reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC);
  
  	/*
  	 * If we may not send any data, we don't.
  	 * If we are still trying to get some other data down the
  	 * channel, we don't try and send any data.
  	 */
  	if (reduce_win || (scp->flowrem_sw != DN_SEND))
  		goto recalc_window;
  
  	if ((skb = skb_peek(&scp->data_xmit_queue)) != NULL)
  		reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC);
  
  	/*
  	 * If we've sent any frame more than once, we cut the
  	 * send window size in half. There is always a minimum
  	 * window size of one available.
  	 */
  recalc_window:
  	if (reduce_win) {
  		scp->snd_window >>= 1;
  		if (scp->snd_window < NSP_MIN_WINDOW)
  			scp->snd_window = NSP_MIN_WINDOW;
  	}
  }
  
  int dn_nsp_xmit_timeout(struct sock *sk)
  {
  	struct dn_scp *scp = DN_SK(sk);
  
  	dn_nsp_output(sk);
b03efcfb2   David S. Miller   [NET]: Transform ...
281
282
  	if (!skb_queue_empty(&scp->data_xmit_queue) ||
  	    !skb_queue_empty(&scp->other_xmit_queue))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
283
284
285
286
  		scp->persist = dn_nsp_persist(sk);
  
  	return 0;
  }
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
287
  static inline __le16 *dn_mk_common_header(struct dn_scp *scp, struct sk_buff *skb, unsigned char msgflag, int len)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
289
290
291
292
293
  {
  	unsigned char *ptr = skb_push(skb, len);
  
  	BUG_ON(len < 5);
  
  	*ptr++ = msgflag;
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
294
  	*((__le16 *)ptr) = scp->addrrem;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
295
  	ptr += 2;
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
296
  	*((__le16 *)ptr) = scp->addrloc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
297
  	ptr += 2;
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
298
  	return (__le16 __force *)ptr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
  }
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
300
  static __le16 *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned char msgflag, int hlen, int other)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
301
302
303
304
  {
  	struct dn_scp *scp = DN_SK(sk);
  	unsigned short acknum = scp->numdat_rcv & 0x0FFF;
  	unsigned short ackcrs = scp->numoth_rcv & 0x0FFF;
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
305
  	__le16 *ptr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
  
  	BUG_ON(hlen < 9);
  
  	scp->ackxmt_dat = acknum;
  	scp->ackxmt_oth = ackcrs;
  	acknum |= 0x8000;
  	ackcrs |= 0x8000;
  
  	/* If this is an "other data/ack" message, swap acknum and ackcrs */
  	if (other) {
  		unsigned short tmp = acknum;
  		acknum = ackcrs;
  		ackcrs = tmp;
  	}
  
  	/* Set "cross subchannel" bit in ackcrs */
  	ackcrs |= 0x2000;
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
323
  	ptr = (__le16 *)dn_mk_common_header(scp, skb, msgflag, hlen);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324

c4106aa88   Harvey Harrison   decnet: remove pr...
325
326
  	*ptr++ = cpu_to_le16(acknum);
  	*ptr++ = cpu_to_le16(ackcrs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
327
328
329
  
  	return ptr;
  }
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
330
  static __le16 *dn_nsp_mk_data_header(struct sock *sk, struct sk_buff *skb, int oth)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331
332
333
  {
  	struct dn_scp *scp = DN_SK(sk);
  	struct dn_skb_cb *cb = DN_SKB_CB(skb);
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
334
  	__le16 *ptr = dn_mk_ack_header(sk, skb, cb->nsp_flags, 11, oth);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
337
338
339
340
341
342
  
  	if (unlikely(oth)) {
  		cb->segnum = scp->numoth;
  		seq_add(&scp->numoth, 1);
  	} else {
  		cb->segnum = scp->numdat;
  		seq_add(&scp->numdat, 1);
  	}
c4106aa88   Harvey Harrison   decnet: remove pr...
343
  	*(ptr++) = cpu_to_le16(cb->segnum);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
344
345
346
  
  	return ptr;
  }
f4a19a56e   Randy Dunlap   [DECNET]: fix spa...
347
  void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb,
dd0fc66fb   Al Viro   [PATCH] gfp flags...
348
  			gfp_t gfp, int oth)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
  {
  	struct dn_scp *scp = DN_SK(sk);
  	struct dn_skb_cb *cb = DN_SKB_CB(skb);
  	unsigned long t = ((scp->nsp_srtt >> 2) + scp->nsp_rttvar) >> 1;
  
  	cb->xmit_count = 0;
  	dn_nsp_mk_data_header(sk, skb, oth);
  
  	/*
  	 * Slow start: If we have been idle for more than
  	 * one RTT, then reset window to min size.
  	 */
  	if ((jiffies - scp->stamp) > t)
  		scp->snd_window = NSP_MIN_WINDOW;
  
  	if (oth)
  		skb_queue_tail(&scp->other_xmit_queue, skb);
  	else
  		skb_queue_tail(&scp->data_xmit_queue, skb);
  
  	if (scp->flowrem_sw != DN_SEND)
  		return;
  
  	dn_nsp_clone_and_send(skb, gfp);
  }
  
  
  int dn_nsp_check_xmit_queue(struct sock *sk, struct sk_buff *skb, struct sk_buff_head *q, unsigned short acknum)
  {
  	struct dn_skb_cb *cb = DN_SKB_CB(skb);
  	struct dn_scp *scp = DN_SK(sk);
bec571ec7   David S. Miller   decnet: Use SKB q...
380
  	struct sk_buff *skb2, *n, *ack = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381
382
383
384
385
386
  	int wakeup = 0;
  	int try_retrans = 0;
  	unsigned long reftime = cb->stamp;
  	unsigned long pkttime;
  	unsigned short xmit_count;
  	unsigned short segnum;
bec571ec7   David S. Miller   decnet: Use SKB q...
387
  	skb_queue_walk_safe(q, skb2, n) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
388
389
390
391
392
393
394
  		struct dn_skb_cb *cb2 = DN_SKB_CB(skb2);
  
  		if (dn_before_or_equal(cb2->segnum, acknum))
  			ack = skb2;
  
  		/* printk(KERN_DEBUG "ack: %s %04x %04x
  ", ack ? "ACK" : "SKIP", (int)cb2->segnum, (int)acknum); */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
  		if (ack == NULL)
  			continue;
  
  		/* printk(KERN_DEBUG "check_xmit_queue: %04x, %d
  ", acknum, cb2->xmit_count); */
  
  		/* Does _last_ packet acked have xmit_count > 1 */
  		try_retrans = 0;
  		/* Remember to wake up the sending process */
  		wakeup = 1;
  		/* Keep various statistics */
  		pkttime = cb2->stamp;
  		xmit_count = cb2->xmit_count;
  		segnum = cb2->segnum;
  		/* Remove and drop ack'ed packet */
8728b834b   David S. Miller   [NET]: Kill skb->...
410
  		skb_unlink(ack, q);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
  		kfree_skb(ack);
  		ack = NULL;
  
  		/*
  		 * We don't expect to see acknowledgements for packets we
  		 * haven't sent yet.
  		 */
  		WARN_ON(xmit_count == 0);
  
  		/*
  		 * If the packet has only been sent once, we can use it
  		 * to calculate the RTT and also open the window a little
  		 * further.
  		 */
  		if (xmit_count == 1) {
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
426
  			if (dn_equal(segnum, acknum))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
  				dn_nsp_rtt(sk, (long)(pkttime - reftime));
  
  			if (scp->snd_window < scp->max_window)
  				scp->snd_window++;
  		}
  
  		/*
  		 * Packet has been sent more than once. If this is the last
  		 * packet to be acknowledged then we want to send the next
  		 * packet in the send queue again (assumes the remote host does
  		 * go-back-N error control).
  		 */
  		if (xmit_count > 1)
  			try_retrans = 1;
  	}
  
  	if (try_retrans)
  		dn_nsp_output(sk);
  
  	return wakeup;
  }
  
  void dn_nsp_send_data_ack(struct sock *sk)
  {
  	struct sk_buff *skb = NULL;
  
  	if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL)
  		return;
  
  	skb_reserve(skb, 9);
  	dn_mk_ack_header(sk, skb, 0x04, 9, 0);
  	dn_nsp_send(skb);
  }
  
  void dn_nsp_send_oth_ack(struct sock *sk)
  {
  	struct sk_buff *skb = NULL;
  
  	if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL)
  		return;
  
  	skb_reserve(skb, 9);
  	dn_mk_ack_header(sk, skb, 0x14, 9, 1);
  	dn_nsp_send(skb);
  }
  
  
  void dn_send_conn_ack (struct sock *sk)
  {
  	struct dn_scp *scp = DN_SK(sk);
  	struct sk_buff *skb = NULL;
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
478
  	struct nsp_conn_ack_msg *msg;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
479
480
481
  
  	if ((skb = dn_alloc_skb(sk, 3, sk->sk_allocation)) == NULL)
  		return;
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
482
483
  	msg = (struct nsp_conn_ack_msg *)skb_put(skb, 3);
  	msg->msgflg = 0x24;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
484
  	msg->dstaddr = scp->addrrem;
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
485
  	dn_nsp_send(skb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
  }
  
  void dn_nsp_delayed_ack(struct sock *sk)
  {
  	struct dn_scp *scp = DN_SK(sk);
  
  	if (scp->ackxmt_oth != scp->numoth_rcv)
  		dn_nsp_send_oth_ack(sk);
  
  	if (scp->ackxmt_dat != scp->numdat_rcv)
  		dn_nsp_send_data_ack(sk);
  }
  
  static int dn_nsp_retrans_conn_conf(struct sock *sk)
  {
  	struct dn_scp *scp = DN_SK(sk);
  
  	if (scp->state == DN_CC)
  		dn_send_conn_conf(sk, GFP_ATOMIC);
  
  	return 0;
  }
dd0fc66fb   Al Viro   [PATCH] gfp flags...
508
  void dn_send_conn_conf(struct sock *sk, gfp_t gfp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
509
510
511
  {
  	struct dn_scp *scp = DN_SK(sk);
  	struct sk_buff *skb = NULL;
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
512
  	struct nsp_conn_init_msg *msg;
c4106aa88   Harvey Harrison   decnet: remove pr...
513
  	__u8 len = (__u8)le16_to_cpu(scp->conndata_out.opt_optl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
514

375d9d718   Steven Whitehouse   [DECNET]: Endiane...
515
  	if ((skb = dn_alloc_skb(sk, 50 + len, gfp)) == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
516
  		return;
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
517
518
  	msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg));
  	msg->msgflg = 0x28;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
519
  	msg->dstaddr = scp->addrrem;
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
520
521
522
  	msg->srcaddr = scp->addrloc;
  	msg->services = scp->services_loc;
  	msg->info = scp->info_loc;
c4106aa88   Harvey Harrison   decnet: remove pr...
523
  	msg->segsize = cpu_to_le16(scp->segsize_loc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
524
525
  
  	*skb_put(skb,1) = len;
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
526
  	if (len > 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
527
  		memcpy(skb_put(skb, len), scp->conndata_out.opt_data, len);
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
528

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
529
530
531
532
533
534
  
  	dn_nsp_send(skb);
  
  	scp->persist = dn_nsp_persist(sk);
  	scp->persist_fxn = dn_nsp_retrans_conn_conf;
  }
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
535
  static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
dd0fc66fb   Al Viro   [PATCH] gfp flags...
536
  			unsigned short reason, gfp_t gfp,
f4a19a56e   Randy Dunlap   [DECNET]: fix spa...
537
  			struct dst_entry *dst,
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
538
  			int ddl, unsigned char *dd, __le16 rem, __le16 loc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
539
540
541
542
543
544
545
  {
  	struct sk_buff *skb = NULL;
  	int size = 7 + ddl + ((msgflg == NSP_DISCINIT) ? 1 : 0);
  	unsigned char *msg;
  
  	if ((dst == NULL) || (rem == 0)) {
  		if (net_ratelimit())
c4106aa88   Harvey Harrison   decnet: remove pr...
546
547
  			printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p
  ", le16_to_cpu(rem), dst);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
548
549
550
551
552
553
554
555
  		return;
  	}
  
  	if ((skb = dn_alloc_skb(sk, size, gfp)) == NULL)
  		return;
  
  	msg = skb_put(skb, size);
  	*msg++ = msgflg;
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
556
  	*(__le16 *)msg = rem;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557
  	msg += 2;
c4ea94ab3   Steven Whitehouse   [DECnet]: Endian ...
558
  	*(__le16 *)msg = loc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
559
  	msg += 2;
c4106aa88   Harvey Harrison   decnet: remove pr...
560
  	*(__le16 *)msg = cpu_to_le16(reason);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
561
562
563
564
565
566
567
568
569
570
571
572
573
  	msg += 2;
  	if (msgflg == NSP_DISCINIT)
  		*msg++ = ddl;
  
  	if (ddl) {
  		memcpy(msg, dd, ddl);
  	}
  
  	/*
  	 * This doesn't go via the dn_nsp_send() function since we need
  	 * to be able to send disc packets out which have no socket
  	 * associations.
  	 */
adf30907d   Eric Dumazet   net: skb->dst acc...
574
  	skb_dst_set(skb, dst_clone(dst));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
575
576
  	dst_output(skb);
  }
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
577
  void dn_nsp_send_disc(struct sock *sk, unsigned char msgflg,
dd0fc66fb   Al Viro   [PATCH] gfp flags...
578
  			unsigned short reason, gfp_t gfp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
579
580
581
582
583
  {
  	struct dn_scp *scp = DN_SK(sk);
  	int ddl = 0;
  
  	if (msgflg == NSP_DISCINIT)
c4106aa88   Harvey Harrison   decnet: remove pr...
584
  		ddl = le16_to_cpu(scp->discdata_out.opt_optl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
585
586
  
  	if (reason == 0)
c4106aa88   Harvey Harrison   decnet: remove pr...
587
  		reason = le16_to_cpu(scp->discdata_out.opt_status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
588

429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
589
  	dn_nsp_do_disc(sk, msgflg, reason, gfp, sk->sk_dst_cache, ddl,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
590
591
  		scp->discdata_out.opt_data, scp->addrrem, scp->addrloc);
  }
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
592
  void dn_nsp_return_disc(struct sk_buff *skb, unsigned char msgflg,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
593
594
595
596
  			unsigned short reason)
  {
  	struct dn_skb_cb *cb = DN_SKB_CB(skb);
  	int ddl = 0;
dd0fc66fb   Al Viro   [PATCH] gfp flags...
597
  	gfp_t gfp = GFP_ATOMIC;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
598

adf30907d   Eric Dumazet   net: skb->dst acc...
599
  	dn_nsp_do_disc(NULL, msgflg, reason, gfp, skb_dst(skb), ddl,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
600
601
602
603
604
605
606
607
608
  			NULL, cb->src_port, cb->dst_port);
  }
  
  
  void dn_nsp_send_link(struct sock *sk, unsigned char lsflags, char fcval)
  {
  	struct dn_scp *scp = DN_SK(sk);
  	struct sk_buff *skb;
  	unsigned char *ptr;
dd0fc66fb   Al Viro   [PATCH] gfp flags...
609
  	gfp_t gfp = GFP_ATOMIC;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
  
  	if ((skb = dn_alloc_skb(sk, DN_MAX_NSP_DATA_HEADER + 2, gfp)) == NULL)
  		return;
  
  	skb_reserve(skb, DN_MAX_NSP_DATA_HEADER);
  	ptr = skb_put(skb, 2);
  	DN_SKB_CB(skb)->nsp_flags = 0x10;
  	*ptr++ = lsflags;
  	*ptr = fcval;
  
  	dn_nsp_queue_xmit(sk, skb, gfp, 1);
  
  	scp->persist = dn_nsp_persist(sk);
  	scp->persist_fxn = dn_nsp_xmit_timeout;
  }
  
  static int dn_nsp_retrans_conninit(struct sock *sk)
  {
  	struct dn_scp *scp = DN_SK(sk);
  
  	if (scp->state == DN_CI)
  		dn_nsp_send_conninit(sk, NSP_RCI);
  
  	return 0;
  }
  
  void dn_nsp_send_conninit(struct sock *sk, unsigned char msgflg)
  {
  	struct dn_scp *scp = DN_SK(sk);
  	struct nsp_conn_init_msg *msg;
  	unsigned char aux;
  	unsigned char menuver;
  	struct dn_skb_cb *cb;
  	unsigned char type = 1;
dd0fc66fb   Al Viro   [PATCH] gfp flags...
644
  	gfp_t allocation = (msgflg == NSP_CI) ? sk->sk_allocation : GFP_ATOMIC;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
645
646
647
648
649
650
651
652
653
654
655
656
657
  	struct sk_buff *skb = dn_alloc_skb(sk, 200, allocation);
  
  	if (!skb)
  		return;
  
  	cb  = DN_SKB_CB(skb);
  	msg = (struct nsp_conn_init_msg *)skb_put(skb,sizeof(*msg));
  
  	msg->msgflg	= msgflg;
  	msg->dstaddr	= 0x0000;		/* Remote Node will assign it*/
  
  	msg->srcaddr	= scp->addrloc;
  	msg->services	= scp->services_loc;	/* Requested flow control    */
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
658
  	msg->info	= scp->info_loc;	/* Version Number            */
c4106aa88   Harvey Harrison   decnet: remove pr...
659
  	msg->segsize	= cpu_to_le16(scp->segsize_loc);	/* Max segment size  */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
660
661
662
  
  	if (scp->peer.sdn_objnum)
  		type = 0;
27a884dc3   Arnaldo Carvalho de Melo   [SK_BUFF]: Conver...
663
664
665
666
  	skb_put(skb, dn_sockaddr2username(&scp->peer,
  					  skb_tail_pointer(skb), type));
  	skb_put(skb, dn_sockaddr2username(&scp->addr,
  					  skb_tail_pointer(skb), 2));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
667
668
669
670
671
672
673
674
  
  	menuver = DN_MENUVER_ACC | DN_MENUVER_USR;
  	if (scp->peer.sdn_flags & SDF_PROXY)
  		menuver |= DN_MENUVER_PRX;
  	if (scp->peer.sdn_flags & SDF_UICPROXY)
  		menuver |= DN_MENUVER_UIC;
  
  	*skb_put(skb, 1) = menuver;	/* Menu Version		*/
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
675

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
676
677
678
  	aux = scp->accessdata.acc_userl;
  	*skb_put(skb, 1) = aux;
  	if (aux > 0)
bb8a10bbd   Julia Lawall   net/decnet: Adjus...
679
  		memcpy(skb_put(skb, aux), scp->accessdata.acc_user, aux);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
680
681
682
683
  
  	aux = scp->accessdata.acc_passl;
  	*skb_put(skb, 1) = aux;
  	if (aux > 0)
bb8a10bbd   Julia Lawall   net/decnet: Adjus...
684
  		memcpy(skb_put(skb, aux), scp->accessdata.acc_pass, aux);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
685
686
687
688
  
  	aux = scp->accessdata.acc_accl;
  	*skb_put(skb, 1) = aux;
  	if (aux > 0)
bb8a10bbd   Julia Lawall   net/decnet: Adjus...
689
  		memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
690

c4106aa88   Harvey Harrison   decnet: remove pr...
691
  	aux = (__u8)le16_to_cpu(scp->conndata_out.opt_optl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
692
693
  	*skb_put(skb, 1) = aux;
  	if (aux > 0)
bb8a10bbd   Julia Lawall   net/decnet: Adjus...
694
  		memcpy(skb_put(skb, aux), scp->conndata_out.opt_data, aux);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
695
696
697
698
699
  
  	scp->persist = dn_nsp_persist(sk);
  	scp->persist_fxn = dn_nsp_retrans_conninit;
  
  	cb->rt_flags = DN_RT_F_RQR;
429eb0fae   YOSHIFUJI Hideaki   [NET] DECNET: Fix...
700
  	dn_nsp_send(skb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
701
  }