]>
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 | ||
1da177e4 LT |
139 | /* |
140 | * Calculate persist timer based upon the smoothed round | |
141 | * trip time and the variance. Backoff according to the | |
142 | * nsp_backoff[] array. | |
143 | */ | |
144 | unsigned 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 | */ | |
167 | static 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 | */ | |
213 | static inline unsigned dn_nsp_clone_and_send(struct sk_buff *skb, int gfp) | |
214 | { | |
215 | struct dn_skb_cb *cb = DN_SKB_CB(skb); | |
216 | struct sk_buff *skb2; | |
217 | int ret = 0; | |
218 | ||
219 | if ((skb2 = skb_clone(skb, gfp)) != NULL) { | |
220 | ret = cb->xmit_count; | |
221 | cb->xmit_count++; | |
222 | cb->stamp = jiffies; | |
223 | skb2->sk = skb->sk; | |
224 | dn_nsp_send(skb2); | |
225 | } | |
226 | ||
227 | return ret; | |
228 | } | |
229 | ||
230 | /** | |
231 | * dn_nsp_output - Try and send something from socket queues | |
232 | * @sk: The socket whose queues are to be investigated | |
233 | * @gfp: The memory allocation flags | |
234 | * | |
235 | * Try and send the packet on the end of the data and other data queues. | |
236 | * Other data gets priority over data, and if we retransmit a packet we | |
237 | * reduce the window by dividing it in two. | |
238 | * | |
239 | */ | |
240 | void dn_nsp_output(struct sock *sk) | |
241 | { | |
242 | struct dn_scp *scp = DN_SK(sk); | |
243 | struct sk_buff *skb; | |
244 | unsigned reduce_win = 0; | |
245 | ||
246 | /* | |
247 | * First we check for otherdata/linkservice messages | |
248 | */ | |
249 | if ((skb = skb_peek(&scp->other_xmit_queue)) != NULL) | |
250 | reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC); | |
251 | ||
252 | /* | |
253 | * If we may not send any data, we don't. | |
254 | * If we are still trying to get some other data down the | |
255 | * channel, we don't try and send any data. | |
256 | */ | |
257 | if (reduce_win || (scp->flowrem_sw != DN_SEND)) | |
258 | goto recalc_window; | |
259 | ||
260 | if ((skb = skb_peek(&scp->data_xmit_queue)) != NULL) | |
261 | reduce_win = dn_nsp_clone_and_send(skb, GFP_ATOMIC); | |
262 | ||
263 | /* | |
264 | * If we've sent any frame more than once, we cut the | |
265 | * send window size in half. There is always a minimum | |
266 | * window size of one available. | |
267 | */ | |
268 | recalc_window: | |
269 | if (reduce_win) { | |
270 | scp->snd_window >>= 1; | |
271 | if (scp->snd_window < NSP_MIN_WINDOW) | |
272 | scp->snd_window = NSP_MIN_WINDOW; | |
273 | } | |
274 | } | |
275 | ||
276 | int dn_nsp_xmit_timeout(struct sock *sk) | |
277 | { | |
278 | struct dn_scp *scp = DN_SK(sk); | |
279 | ||
280 | dn_nsp_output(sk); | |
281 | ||
b03efcfb DM |
282 | if (!skb_queue_empty(&scp->data_xmit_queue) || |
283 | !skb_queue_empty(&scp->other_xmit_queue)) | |
1da177e4 LT |
284 | scp->persist = dn_nsp_persist(sk); |
285 | ||
286 | return 0; | |
287 | } | |
288 | ||
289 | static inline unsigned char *dn_mk_common_header(struct dn_scp *scp, struct sk_buff *skb, unsigned char msgflag, int len) | |
290 | { | |
291 | unsigned char *ptr = skb_push(skb, len); | |
292 | ||
293 | BUG_ON(len < 5); | |
294 | ||
295 | *ptr++ = msgflag; | |
296 | *((unsigned short *)ptr) = scp->addrrem; | |
297 | ptr += 2; | |
298 | *((unsigned short *)ptr) = scp->addrloc; | |
299 | ptr += 2; | |
300 | return ptr; | |
301 | } | |
302 | ||
303 | static unsigned short *dn_mk_ack_header(struct sock *sk, struct sk_buff *skb, unsigned char msgflag, int hlen, int other) | |
304 | { | |
305 | struct dn_scp *scp = DN_SK(sk); | |
306 | unsigned short acknum = scp->numdat_rcv & 0x0FFF; | |
307 | unsigned short ackcrs = scp->numoth_rcv & 0x0FFF; | |
308 | unsigned short *ptr; | |
309 | ||
310 | BUG_ON(hlen < 9); | |
311 | ||
312 | scp->ackxmt_dat = acknum; | |
313 | scp->ackxmt_oth = ackcrs; | |
314 | acknum |= 0x8000; | |
315 | ackcrs |= 0x8000; | |
316 | ||
317 | /* If this is an "other data/ack" message, swap acknum and ackcrs */ | |
318 | if (other) { | |
319 | unsigned short tmp = acknum; | |
320 | acknum = ackcrs; | |
321 | ackcrs = tmp; | |
322 | } | |
323 | ||
324 | /* Set "cross subchannel" bit in ackcrs */ | |
325 | ackcrs |= 0x2000; | |
326 | ||
327 | ptr = (unsigned short *)dn_mk_common_header(scp, skb, msgflag, hlen); | |
328 | ||
329 | *ptr++ = dn_htons(acknum); | |
330 | *ptr++ = dn_htons(ackcrs); | |
331 | ||
332 | return ptr; | |
333 | } | |
334 | ||
335 | static unsigned short *dn_nsp_mk_data_header(struct sock *sk, struct sk_buff *skb, int oth) | |
336 | { | |
337 | struct dn_scp *scp = DN_SK(sk); | |
338 | struct dn_skb_cb *cb = DN_SKB_CB(skb); | |
339 | unsigned short *ptr = dn_mk_ack_header(sk, skb, cb->nsp_flags, 11, oth); | |
340 | ||
341 | if (unlikely(oth)) { | |
342 | cb->segnum = scp->numoth; | |
343 | seq_add(&scp->numoth, 1); | |
344 | } else { | |
345 | cb->segnum = scp->numdat; | |
346 | seq_add(&scp->numdat, 1); | |
347 | } | |
348 | *(ptr++) = dn_htons(cb->segnum); | |
349 | ||
350 | return ptr; | |
351 | } | |
352 | ||
353 | void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb, int gfp, int oth) | |
354 | { | |
355 | struct dn_scp *scp = DN_SK(sk); | |
356 | struct dn_skb_cb *cb = DN_SKB_CB(skb); | |
357 | unsigned long t = ((scp->nsp_srtt >> 2) + scp->nsp_rttvar) >> 1; | |
358 | ||
359 | cb->xmit_count = 0; | |
360 | dn_nsp_mk_data_header(sk, skb, oth); | |
361 | ||
362 | /* | |
363 | * Slow start: If we have been idle for more than | |
364 | * one RTT, then reset window to min size. | |
365 | */ | |
366 | if ((jiffies - scp->stamp) > t) | |
367 | scp->snd_window = NSP_MIN_WINDOW; | |
368 | ||
369 | if (oth) | |
370 | skb_queue_tail(&scp->other_xmit_queue, skb); | |
371 | else | |
372 | skb_queue_tail(&scp->data_xmit_queue, skb); | |
373 | ||
374 | if (scp->flowrem_sw != DN_SEND) | |
375 | return; | |
376 | ||
377 | dn_nsp_clone_and_send(skb, gfp); | |
378 | } | |
379 | ||
380 | ||
381 | int dn_nsp_check_xmit_queue(struct sock *sk, struct sk_buff *skb, struct sk_buff_head *q, unsigned short acknum) | |
382 | { | |
383 | struct dn_skb_cb *cb = DN_SKB_CB(skb); | |
384 | struct dn_scp *scp = DN_SK(sk); | |
385 | struct sk_buff *skb2, *list, *ack = NULL; | |
386 | int wakeup = 0; | |
387 | int try_retrans = 0; | |
388 | unsigned long reftime = cb->stamp; | |
389 | unsigned long pkttime; | |
390 | unsigned short xmit_count; | |
391 | unsigned short segnum; | |
392 | ||
393 | skb2 = q->next; | |
394 | list = (struct sk_buff *)q; | |
395 | while(list != skb2) { | |
396 | struct dn_skb_cb *cb2 = DN_SKB_CB(skb2); | |
397 | ||
398 | if (dn_before_or_equal(cb2->segnum, acknum)) | |
399 | ack = skb2; | |
400 | ||
401 | /* printk(KERN_DEBUG "ack: %s %04x %04x\n", ack ? "ACK" : "SKIP", (int)cb2->segnum, (int)acknum); */ | |
402 | ||
403 | skb2 = skb2->next; | |
404 | ||
405 | if (ack == NULL) | |
406 | continue; | |
407 | ||
408 | /* printk(KERN_DEBUG "check_xmit_queue: %04x, %d\n", acknum, cb2->xmit_count); */ | |
409 | ||
410 | /* Does _last_ packet acked have xmit_count > 1 */ | |
411 | try_retrans = 0; | |
412 | /* Remember to wake up the sending process */ | |
413 | wakeup = 1; | |
414 | /* Keep various statistics */ | |
415 | pkttime = cb2->stamp; | |
416 | xmit_count = cb2->xmit_count; | |
417 | segnum = cb2->segnum; | |
418 | /* Remove and drop ack'ed packet */ | |
8728b834 | 419 | skb_unlink(ack, q); |
1da177e4 LT |
420 | kfree_skb(ack); |
421 | ack = NULL; | |
422 | ||
423 | /* | |
424 | * We don't expect to see acknowledgements for packets we | |
425 | * haven't sent yet. | |
426 | */ | |
427 | WARN_ON(xmit_count == 0); | |
428 | ||
429 | /* | |
430 | * If the packet has only been sent once, we can use it | |
431 | * to calculate the RTT and also open the window a little | |
432 | * further. | |
433 | */ | |
434 | if (xmit_count == 1) { | |
435 | if (dn_equal(segnum, acknum)) | |
436 | dn_nsp_rtt(sk, (long)(pkttime - reftime)); | |
437 | ||
438 | if (scp->snd_window < scp->max_window) | |
439 | scp->snd_window++; | |
440 | } | |
441 | ||
442 | /* | |
443 | * Packet has been sent more than once. If this is the last | |
444 | * packet to be acknowledged then we want to send the next | |
445 | * packet in the send queue again (assumes the remote host does | |
446 | * go-back-N error control). | |
447 | */ | |
448 | if (xmit_count > 1) | |
449 | try_retrans = 1; | |
450 | } | |
451 | ||
452 | if (try_retrans) | |
453 | dn_nsp_output(sk); | |
454 | ||
455 | return wakeup; | |
456 | } | |
457 | ||
458 | void dn_nsp_send_data_ack(struct sock *sk) | |
459 | { | |
460 | struct sk_buff *skb = NULL; | |
461 | ||
462 | if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL) | |
463 | return; | |
464 | ||
465 | skb_reserve(skb, 9); | |
466 | dn_mk_ack_header(sk, skb, 0x04, 9, 0); | |
467 | dn_nsp_send(skb); | |
468 | } | |
469 | ||
470 | void dn_nsp_send_oth_ack(struct sock *sk) | |
471 | { | |
472 | struct sk_buff *skb = NULL; | |
473 | ||
474 | if ((skb = dn_alloc_skb(sk, 9, GFP_ATOMIC)) == NULL) | |
475 | return; | |
476 | ||
477 | skb_reserve(skb, 9); | |
478 | dn_mk_ack_header(sk, skb, 0x14, 9, 1); | |
479 | dn_nsp_send(skb); | |
480 | } | |
481 | ||
482 | ||
483 | void dn_send_conn_ack (struct sock *sk) | |
484 | { | |
485 | struct dn_scp *scp = DN_SK(sk); | |
486 | struct sk_buff *skb = NULL; | |
487 | struct nsp_conn_ack_msg *msg; | |
488 | ||
489 | if ((skb = dn_alloc_skb(sk, 3, sk->sk_allocation)) == NULL) | |
490 | return; | |
491 | ||
492 | msg = (struct nsp_conn_ack_msg *)skb_put(skb, 3); | |
493 | msg->msgflg = 0x24; | |
494 | msg->dstaddr = scp->addrrem; | |
495 | ||
496 | dn_nsp_send(skb); | |
497 | } | |
498 | ||
499 | void dn_nsp_delayed_ack(struct sock *sk) | |
500 | { | |
501 | struct dn_scp *scp = DN_SK(sk); | |
502 | ||
503 | if (scp->ackxmt_oth != scp->numoth_rcv) | |
504 | dn_nsp_send_oth_ack(sk); | |
505 | ||
506 | if (scp->ackxmt_dat != scp->numdat_rcv) | |
507 | dn_nsp_send_data_ack(sk); | |
508 | } | |
509 | ||
510 | static int dn_nsp_retrans_conn_conf(struct sock *sk) | |
511 | { | |
512 | struct dn_scp *scp = DN_SK(sk); | |
513 | ||
514 | if (scp->state == DN_CC) | |
515 | dn_send_conn_conf(sk, GFP_ATOMIC); | |
516 | ||
517 | return 0; | |
518 | } | |
519 | ||
520 | void dn_send_conn_conf(struct sock *sk, int gfp) | |
521 | { | |
522 | struct dn_scp *scp = DN_SK(sk); | |
523 | struct sk_buff *skb = NULL; | |
524 | struct nsp_conn_init_msg *msg; | |
525 | unsigned char len = scp->conndata_out.opt_optl; | |
526 | ||
527 | if ((skb = dn_alloc_skb(sk, 50 + scp->conndata_out.opt_optl, gfp)) == NULL) | |
528 | return; | |
529 | ||
530 | msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg)); | |
531 | msg->msgflg = 0x28; | |
532 | msg->dstaddr = scp->addrrem; | |
533 | msg->srcaddr = scp->addrloc; | |
534 | msg->services = scp->services_loc; | |
535 | msg->info = scp->info_loc; | |
536 | msg->segsize = dn_htons(scp->segsize_loc); | |
537 | ||
538 | *skb_put(skb,1) = len; | |
539 | ||
540 | if (len > 0) | |
541 | memcpy(skb_put(skb, len), scp->conndata_out.opt_data, len); | |
542 | ||
543 | ||
544 | dn_nsp_send(skb); | |
545 | ||
546 | scp->persist = dn_nsp_persist(sk); | |
547 | scp->persist_fxn = dn_nsp_retrans_conn_conf; | |
548 | } | |
549 | ||
550 | ||
551 | static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg, | |
552 | unsigned short reason, int gfp, struct dst_entry *dst, | |
553 | int ddl, unsigned char *dd, __u16 rem, __u16 loc) | |
554 | { | |
555 | struct sk_buff *skb = NULL; | |
556 | int size = 7 + ddl + ((msgflg == NSP_DISCINIT) ? 1 : 0); | |
557 | unsigned char *msg; | |
558 | ||
559 | if ((dst == NULL) || (rem == 0)) { | |
560 | if (net_ratelimit()) | |
561 | printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to SteveW@ACM.org rem=%u dst=%p\n", (unsigned)rem, dst); | |
562 | return; | |
563 | } | |
564 | ||
565 | if ((skb = dn_alloc_skb(sk, size, gfp)) == NULL) | |
566 | return; | |
567 | ||
568 | msg = skb_put(skb, size); | |
569 | *msg++ = msgflg; | |
570 | *(__u16 *)msg = rem; | |
571 | msg += 2; | |
572 | *(__u16 *)msg = loc; | |
573 | msg += 2; | |
574 | *(__u16 *)msg = dn_htons(reason); | |
575 | msg += 2; | |
576 | if (msgflg == NSP_DISCINIT) | |
577 | *msg++ = ddl; | |
578 | ||
579 | if (ddl) { | |
580 | memcpy(msg, dd, ddl); | |
581 | } | |
582 | ||
583 | /* | |
584 | * This doesn't go via the dn_nsp_send() function since we need | |
585 | * to be able to send disc packets out which have no socket | |
586 | * associations. | |
587 | */ | |
588 | skb->dst = dst_clone(dst); | |
589 | dst_output(skb); | |
590 | } | |
591 | ||
592 | ||
593 | void dn_nsp_send_disc(struct sock *sk, unsigned char msgflg, | |
594 | unsigned short reason, int gfp) | |
595 | { | |
596 | struct dn_scp *scp = DN_SK(sk); | |
597 | int ddl = 0; | |
598 | ||
599 | if (msgflg == NSP_DISCINIT) | |
600 | ddl = scp->discdata_out.opt_optl; | |
601 | ||
602 | if (reason == 0) | |
603 | reason = scp->discdata_out.opt_status; | |
604 | ||
605 | dn_nsp_do_disc(sk, msgflg, reason, gfp, sk->sk_dst_cache, ddl, | |
606 | scp->discdata_out.opt_data, scp->addrrem, scp->addrloc); | |
607 | } | |
608 | ||
609 | ||
610 | void dn_nsp_return_disc(struct sk_buff *skb, unsigned char msgflg, | |
611 | unsigned short reason) | |
612 | { | |
613 | struct dn_skb_cb *cb = DN_SKB_CB(skb); | |
614 | int ddl = 0; | |
615 | int gfp = GFP_ATOMIC; | |
616 | ||
617 | dn_nsp_do_disc(NULL, msgflg, reason, gfp, skb->dst, ddl, | |
618 | NULL, cb->src_port, cb->dst_port); | |
619 | } | |
620 | ||
621 | ||
622 | void dn_nsp_send_link(struct sock *sk, unsigned char lsflags, char fcval) | |
623 | { | |
624 | struct dn_scp *scp = DN_SK(sk); | |
625 | struct sk_buff *skb; | |
626 | unsigned char *ptr; | |
627 | int gfp = GFP_ATOMIC; | |
628 | ||
629 | if ((skb = dn_alloc_skb(sk, DN_MAX_NSP_DATA_HEADER + 2, gfp)) == NULL) | |
630 | return; | |
631 | ||
632 | skb_reserve(skb, DN_MAX_NSP_DATA_HEADER); | |
633 | ptr = skb_put(skb, 2); | |
634 | DN_SKB_CB(skb)->nsp_flags = 0x10; | |
635 | *ptr++ = lsflags; | |
636 | *ptr = fcval; | |
637 | ||
638 | dn_nsp_queue_xmit(sk, skb, gfp, 1); | |
639 | ||
640 | scp->persist = dn_nsp_persist(sk); | |
641 | scp->persist_fxn = dn_nsp_xmit_timeout; | |
642 | } | |
643 | ||
644 | static int dn_nsp_retrans_conninit(struct sock *sk) | |
645 | { | |
646 | struct dn_scp *scp = DN_SK(sk); | |
647 | ||
648 | if (scp->state == DN_CI) | |
649 | dn_nsp_send_conninit(sk, NSP_RCI); | |
650 | ||
651 | return 0; | |
652 | } | |
653 | ||
654 | void dn_nsp_send_conninit(struct sock *sk, unsigned char msgflg) | |
655 | { | |
656 | struct dn_scp *scp = DN_SK(sk); | |
657 | struct nsp_conn_init_msg *msg; | |
658 | unsigned char aux; | |
659 | unsigned char menuver; | |
660 | struct dn_skb_cb *cb; | |
661 | unsigned char type = 1; | |
662 | int allocation = (msgflg == NSP_CI) ? sk->sk_allocation : GFP_ATOMIC; | |
663 | struct sk_buff *skb = dn_alloc_skb(sk, 200, allocation); | |
664 | ||
665 | if (!skb) | |
666 | return; | |
667 | ||
668 | cb = DN_SKB_CB(skb); | |
669 | msg = (struct nsp_conn_init_msg *)skb_put(skb,sizeof(*msg)); | |
670 | ||
671 | msg->msgflg = msgflg; | |
672 | msg->dstaddr = 0x0000; /* Remote Node will assign it*/ | |
673 | ||
674 | msg->srcaddr = scp->addrloc; | |
675 | msg->services = scp->services_loc; /* Requested flow control */ | |
676 | msg->info = scp->info_loc; /* Version Number */ | |
677 | msg->segsize = dn_htons(scp->segsize_loc); /* Max segment size */ | |
678 | ||
679 | if (scp->peer.sdn_objnum) | |
680 | type = 0; | |
681 | ||
682 | skb_put(skb, dn_sockaddr2username(&scp->peer, skb->tail, type)); | |
683 | skb_put(skb, dn_sockaddr2username(&scp->addr, skb->tail, 2)); | |
684 | ||
685 | menuver = DN_MENUVER_ACC | DN_MENUVER_USR; | |
686 | if (scp->peer.sdn_flags & SDF_PROXY) | |
687 | menuver |= DN_MENUVER_PRX; | |
688 | if (scp->peer.sdn_flags & SDF_UICPROXY) | |
689 | menuver |= DN_MENUVER_UIC; | |
690 | ||
691 | *skb_put(skb, 1) = menuver; /* Menu Version */ | |
692 | ||
693 | aux = scp->accessdata.acc_userl; | |
694 | *skb_put(skb, 1) = aux; | |
695 | if (aux > 0) | |
696 | memcpy(skb_put(skb, aux), scp->accessdata.acc_user, aux); | |
697 | ||
698 | aux = scp->accessdata.acc_passl; | |
699 | *skb_put(skb, 1) = aux; | |
700 | if (aux > 0) | |
701 | memcpy(skb_put(skb, aux), scp->accessdata.acc_pass, aux); | |
702 | ||
703 | aux = scp->accessdata.acc_accl; | |
704 | *skb_put(skb, 1) = aux; | |
705 | if (aux > 0) | |
706 | memcpy(skb_put(skb, aux), scp->accessdata.acc_acc, aux); | |
707 | ||
708 | aux = scp->conndata_out.opt_optl; | |
709 | *skb_put(skb, 1) = aux; | |
710 | if (aux > 0) | |
711 | memcpy(skb_put(skb,aux), scp->conndata_out.opt_data, aux); | |
712 | ||
713 | scp->persist = dn_nsp_persist(sk); | |
714 | scp->persist_fxn = dn_nsp_retrans_conninit; | |
715 | ||
716 | cb->rt_flags = DN_RT_F_RQR; | |
717 | ||
718 | dn_nsp_send(skb); | |
719 | } | |
720 |