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