- David Miller: sparc and net updates. Fix merge_segments.
[davej-history.git] / net / decnet / dn_nsp_in.c
blob361729458ada07c5da6a9d00fedb48690c9c932f
1 /*
2 * DECnet An implementation of the DECnet protocol suite for the LINUX
3 * operating system. DECnet is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * DECnet Network Services Protocol (Input)
8 * Author: Eduardo Marcelo Serrat <emserrat@geocities.com>
10 * Changes:
12 * Steve Whitehouse: Split into dn_nsp_in.c and dn_nsp_out.c from
13 * original dn_nsp.c.
14 * Steve Whitehouse: Updated to work with my new routing architecture.
15 * Steve Whitehouse: Add changes from Eduardo Serrat's patches.
16 * Steve Whitehouse: Put all ack handling code in a common routine.
17 * Steve Whitehouse: Put other common bits into dn_nsp_rx()
18 * Steve Whitehouse: More checks on skb->len to catch bogus packets
19 * Fixed various race conditions and possible nasties.
20 * Steve Whitehouse: Now handles returned conninit frames.
21 * David S. Miller: New socket locking
22 * Steve Whitehouse: Fixed lockup when socket filtering was enabled.
23 * Paul Koning: Fix to push CC sockets into RUN when acks are
24 * received.
25 * Steve Whitehouse:
26 * Patrick Caulfield: Checking conninits for correctness & sending of error
27 * responses.
30 /******************************************************************************
31 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
33 This program is free software; you can redistribute it and/or modify
34 it under the terms of the GNU General Public License as published by
35 the Free Software Foundation; either version 2 of the License, or
36 any later version.
38 This program is distributed in the hope that it will be useful,
39 but WITHOUT ANY WARRANTY; without even the implied warranty of
40 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 GNU General Public License for more details.
42 *******************************************************************************/
44 #include <linux/config.h>
45 #include <linux/errno.h>
46 #include <linux/types.h>
47 #include <linux/socket.h>
48 #include <linux/in.h>
49 #include <linux/kernel.h>
50 #include <linux/sched.h>
51 #include <linux/timer.h>
52 #include <linux/string.h>
53 #include <linux/sockios.h>
54 #include <linux/net.h>
55 #include <linux/netdevice.h>
56 #include <linux/inet.h>
57 #include <linux/route.h>
58 #include <net/sock.h>
59 #include <asm/segment.h>
60 #include <asm/system.h>
61 #include <linux/fcntl.h>
62 #include <linux/mm.h>
63 #include <linux/termios.h>
64 #include <linux/interrupt.h>
65 #include <linux/proc_fs.h>
66 #include <linux/stat.h>
67 #include <linux/init.h>
68 #include <linux/poll.h>
69 #include <linux/netfilter_decnet.h>
70 #include <net/neighbour.h>
71 #include <net/dst.h>
72 #include <net/dn_nsp.h>
73 #include <net/dn_dev.h>
74 #include <net/dn_route.h>
76 extern int decnet_log_martians;
78 static void dn_log_martian(struct sk_buff *skb, const char *msg)
80 if (decnet_log_martians && net_ratelimit()) {
81 char *devname = skb->dev ? skb->dev->name : "???";
82 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
83 printk(KERN_INFO "DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n", msg, devname, cb->src, cb->dst, cb->src_port, cb->dst_port);
88 * For this function we've flipped the cross-subchannel bit
89 * if the message is an otherdata or linkservice message. Thus
90 * we can use it to work out what to update.
92 static void dn_ack(struct sock *sk, struct sk_buff *skb, unsigned short ack)
94 struct dn_scp *scp = &sk->protinfo.dn;
95 unsigned short type = ((ack >> 12) & 0x0003);
96 int wakeup = 0;
98 switch(type) {
99 case 0: /* ACK - Data */
100 if (after(ack, scp->ackrcv_dat)) {
101 scp->ackrcv_dat = ack & 0x0fff;
102 wakeup |= dn_nsp_check_xmit_queue(sk, skb, &scp->data_xmit_queue, ack);
104 break;
105 case 1: /* NAK - Data */
106 break;
107 case 2: /* ACK - OtherData */
108 if (after(ack, scp->ackrcv_oth)) {
109 scp->ackrcv_oth = ack & 0x0fff;
110 wakeup |= dn_nsp_check_xmit_queue(sk, skb, &scp->other_xmit_queue, ack);
112 break;
113 case 3: /* NAK - OtherData */
114 break;
117 if (wakeup && !sk->dead)
118 sk->state_change(sk);
122 * This function is a universal ack processor.
124 static int dn_process_ack(struct sock *sk, struct sk_buff *skb, int oth)
126 unsigned short *ptr = (unsigned short *)skb->data;
127 int len = 0;
128 unsigned short ack;
130 if (skb->len < 2)
131 return len;
133 if ((ack = dn_ntohs(*ptr)) & 0x8000) {
134 skb_pull(skb, 2);
135 ptr++;
136 len += 2;
137 if ((ack & 0x4000) == 0) {
138 if (oth)
139 ack ^= 0x2000;
140 dn_ack(sk, skb, ack);
144 if (skb->len < 2)
145 return len;
147 if ((ack = dn_ntohs(*ptr)) & 0x8000) {
148 skb_pull(skb, 2);
149 len += 2;
150 if ((ack & 0x4000) == 0) {
151 if (oth)
152 ack ^= 0x2000;
153 dn_ack(sk, skb, ack);
157 return len;
162 * dn_check_idf - Check an image data field format is correct.
163 * @pptr: Pointer to pointer to image data
164 * @len: Pointer to length of image data
165 * @max: The maximum allowed length of the data in the image data field
166 * @follow_on: Check that this many bytes exist beyond the end of the image data
168 * Returns: 0 if ok, -1 on error
170 static inline int dn_check_idf(unsigned char **pptr, int *len, unsigned char max, unsigned char follow_on)
172 unsigned char *ptr = *pptr;
173 unsigned char flen = *ptr++;
175 (*len)--;
176 if (flen > max)
177 return -1;
178 if ((flen + follow_on) > *len)
179 return -1;
181 *len -= flen;
182 *pptr = ptr + flen;
183 return 0;
187 * Table of reason codes to pass back to node which sent us a badly
188 * formed message, plus text messages for the log. A zero entry in
189 * the reason field means "don't reply" otherwise a disc init is sent with
190 * the specified reason code.
192 static struct {
193 unsigned short reason;
194 const char *text;
195 } ci_err_table[] = {
196 { 0, "CI: Truncated message" },
197 { NSP_REASON_ID, "CI: Destination username error" },
198 { NSP_REASON_ID, "CI: Destination username type" },
199 { NSP_REASON_US, "CI: Source username error" },
200 { 0, "CI: Truncated at menuver" },
201 { 0, "CI: Truncated before access or user data" },
202 { NSP_REASON_IO, "CI: Access data format error" },
203 { NSP_REASON_IO, "CI: User data format error" }
207 * This function uses a slightly different lookup method
208 * to find its sockets, since it searches on object name/number
209 * rather than port numbers. Various tests are done to ensure that
210 * the incoming data is in the correct format before it is queued to
211 * a socket.
213 static struct sock *dn_find_listener(struct sk_buff *skb, unsigned short *reason)
215 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
216 struct nsp_conn_init_msg *msg = (struct nsp_conn_init_msg *)skb->data;
217 struct sockaddr_dn dstaddr;
218 struct sockaddr_dn srcaddr;
219 unsigned char type = 0;
220 int dstlen;
221 int srclen;
222 unsigned char *ptr;
223 int len;
224 int err = 0;
225 unsigned char menuver;
227 memset(&dstaddr, 0, sizeof(struct sockaddr_dn));
228 memset(&srcaddr, 0, sizeof(struct sockaddr_dn));
231 * 1. Decode & remove message header
233 cb->src_port = msg->srcaddr;
234 cb->dst_port = msg->dstaddr;
235 cb->services = msg->services;
236 cb->info = msg->info;
237 cb->segsize = dn_ntohs(msg->segsize);
239 if (skb->len < sizeof(*msg))
240 goto err_out;
242 skb_pull(skb, sizeof(*msg));
244 len = skb->len;
245 ptr = skb->data;
248 * 2. Check destination end username format
250 dstlen = dn_username2sockaddr(ptr, len, &dstaddr, &type);
251 err++;
252 if (dstlen < 0)
253 goto err_out;
255 err++;
256 if (type > 1)
257 goto err_out;
259 len -= dstlen;
260 ptr += dstlen;
263 * 3. Check source end username format
265 srclen = dn_username2sockaddr(ptr, len, &srcaddr, &type);
266 err++;
267 if (srclen < 0)
268 goto err_out;
270 len -= srclen;
271 ptr += srclen;
272 err++;
273 if (len < 1)
274 goto err_out;
276 menuver = *ptr;
277 ptr++;
278 len--;
281 * 4. Check that optional data actually exists if menuver says it does
283 err++;
284 if ((menuver & (DN_MENUVER_ACC | DN_MENUVER_USR)) && (len < 1))
285 goto err_out;
288 * 5. Check optional access data format
290 err++;
291 if (menuver & DN_MENUVER_ACC) {
292 if (dn_check_idf(&ptr, &len, 39, 1))
293 goto err_out;
294 if (dn_check_idf(&ptr, &len, 39, 1))
295 goto err_out;
296 if (dn_check_idf(&ptr, &len, 39, (menuver & DN_MENUVER_USR) ? 1 : 0))
297 goto err_out;
301 * 6. Check optional user data format
303 err++;
304 if (menuver & DN_MENUVER_USR) {
305 if (dn_check_idf(&ptr, &len, 16, 0))
306 goto err_out;
310 * 7. Look up socket based on destination end username
312 return dn_sklist_find_listener(&dstaddr);
313 err_out:
314 dn_log_martian(skb, ci_err_table[err].text);
315 *reason = ci_err_table[err].reason;
316 return NULL;
320 static void dn_nsp_conn_init(struct sock *sk, struct sk_buff *skb)
322 if (sk->ack_backlog >= sk->max_ack_backlog) {
323 kfree_skb(skb);
324 return;
327 sk->ack_backlog++;
328 skb_queue_tail(&sk->receive_queue, skb);
329 sk->state_change(sk);
332 static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
334 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
335 struct dn_scp *scp = &sk->protinfo.dn;
337 if (skb->len < 3)
338 goto out;
340 cb->services = *skb->data;
341 cb->info = *(skb->data+1);
342 skb_pull(skb, 2);
343 cb->segsize = dn_ntohs(*(__u16 *)skb->data);
344 skb_pull(skb, 2);
347 * FIXME: Check out services and info fields to check that
348 * we can talk to this kind of node.
351 if ((scp->state == DN_CI) || (scp->state == DN_CD)) {
352 scp->persist = 0;
353 scp->addrrem = cb->src_port;
354 sk->state = TCP_ESTABLISHED;
355 scp->state = DN_RUN;
357 if (scp->mss > cb->segsize)
358 scp->mss = cb->segsize;
359 if (scp->mss < 230)
360 scp->mss = 230;
362 if (skb->len > 0) {
363 unsigned char dlen = *skb->data;
364 if ((dlen <= 16) && (dlen <= skb->len)) {
365 scp->conndata_in.opt_optl = dlen;
366 memcpy(scp->conndata_in.opt_data, skb->data + 1, dlen);
369 dn_nsp_send_lnk(sk, DN_NOCHANGE);
370 if (!sk->dead)
371 sk->state_change(sk);
374 out:
375 kfree_skb(skb);
378 static void dn_nsp_conn_ack(struct sock *sk, struct sk_buff *skb)
380 struct dn_scp *scp = &sk->protinfo.dn;
382 if (scp->state == DN_CI) {
383 scp->state = DN_CD;
384 scp->persist = 0;
387 kfree_skb(skb);
390 static void dn_nsp_disc_init(struct sock *sk, struct sk_buff *skb)
392 struct dn_scp *scp = &sk->protinfo.dn;
393 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
394 unsigned short reason;
396 if (skb->len < 2)
397 goto out;
399 reason = dn_ntohs(*(__u16 *)skb->data);
400 skb_pull(skb, 2);
402 scp->discdata_in.opt_status = reason;
403 scp->discdata_in.opt_optl = 0;
404 memset(scp->discdata_in.opt_data, 0, 16);
406 if (skb->len > 0) {
407 unsigned char dlen = *skb->data;
408 if ((dlen <= 16) && (dlen <= skb->len)) {
409 scp->discdata_in.opt_optl = dlen;
410 memcpy(scp->discdata_in.opt_data, skb->data + 1, dlen);
414 scp->addrrem = cb->src_port;
415 sk->state = TCP_CLOSE;
417 switch(scp->state) {
418 case DN_CI:
419 case DN_CD:
420 scp->state = DN_RJ;
421 break;
422 case DN_RUN:
423 sk->shutdown |= SHUTDOWN_MASK;
424 scp->state = DN_DN;
425 break;
426 case DN_DI:
427 scp->state = DN_DIC;
428 break;
431 if (!sk->dead) {
432 if (sk->socket->state != SS_UNCONNECTED)
433 sk->socket->state = SS_DISCONNECTING;
434 sk->state_change(sk);
437 dn_nsp_send_disc(sk, NSP_DISCCONF, NSP_REASON_DC, GFP_ATOMIC);
438 scp->persist_fxn = dn_destroy_timer;
439 scp->persist = dn_nsp_persist(sk);
441 out:
442 kfree_skb(skb);
446 * disc_conf messages are also called no_resources or no_link
447 * messages depending upon the "reason" field.
449 static void dn_nsp_disc_conf(struct sock *sk, struct sk_buff *skb)
451 struct dn_scp *scp = &sk->protinfo.dn;
452 unsigned short reason;
454 if (skb->len != 2)
455 goto out;
457 reason = dn_ntohs(*(__u16 *)skb->data);
459 sk->state = TCP_CLOSE;
461 switch(scp->state) {
462 case DN_CI:
463 scp->state = DN_NR;
464 break;
465 case DN_DR:
466 if (reason == NSP_REASON_DC)
467 scp->state = DN_DRC;
468 if (reason == NSP_REASON_NL)
469 scp->state = DN_CN;
470 break;
471 case DN_DI:
472 scp->state = DN_DIC;
473 break;
474 case DN_RUN:
475 sk->shutdown |= SHUTDOWN_MASK;
476 case DN_CC:
477 scp->state = DN_CN;
480 if (!sk->dead) {
481 if (sk->socket->state != SS_UNCONNECTED)
482 sk->socket->state = SS_DISCONNECTING;
483 sk->state_change(sk);
486 scp->persist_fxn = dn_destroy_timer;
487 scp->persist = dn_nsp_persist(sk);
489 out:
490 kfree_skb(skb);
493 static void dn_nsp_linkservice(struct sock *sk, struct sk_buff *skb)
495 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
496 unsigned short segnum;
497 unsigned char lsflags;
498 char fcval;
500 if (skb->len != 4)
501 goto out;
503 cb->segnum = segnum = dn_ntohs(*(__u16 *)skb->data);
504 skb_pull(skb, 2);
505 lsflags = *(unsigned char *)skb->data;
506 skb_pull(skb, 1);
507 fcval = *(char *)skb->data;
509 if (lsflags & 0xf0)
510 goto out;
512 if (((sk->protinfo.dn.numoth_rcv + 1) & 0x0FFF) == (segnum & 0x0FFF)) {
513 sk->protinfo.dn.numoth_rcv += 1;
514 switch(lsflags & 0x03) {
515 case 0x00:
516 break;
517 case 0x01:
518 sk->protinfo.dn.flowrem_sw = DN_DONTSEND;
519 break;
520 case 0x02:
521 sk->protinfo.dn.flowrem_sw = DN_SEND;
522 dn_nsp_output(sk);
523 if (!sk->dead)
524 sk->state_change(sk);
529 dn_nsp_send_oth_ack(sk);
531 out:
532 kfree_skb(skb);
536 * Copy of sock_queue_rcv_skb (from sock.h) without
537 * bh_lock_sock() (its already held when this is called) which
538 * also allows data and other data to be queued to a socket.
540 static __inline__ int dn_queue_skb(struct sock *sk, struct sk_buff *skb, int sig, struct sk_buff_head *queue)
542 #ifdef CONFIG_FILTER
543 struct sk_filter *filter;
544 #endif
546 /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
547 number of warnings when compiling with -W --ANK
549 if (atomic_read(&sk->rmem_alloc) + skb->truesize >= (unsigned)sk->rcvbuf
551 return -ENOMEM;
553 #ifdef CONFIG_FILTER
554 if (sk->filter) {
555 int err = 0;
556 if ((filter = sk->filter) != NULL && sk_filter(skb, sk->filter))
557 err = -EPERM; /* Toss packet */
558 if (err)
559 return err;
561 #endif /* CONFIG_FILTER */
563 skb_set_owner_r(skb, sk);
564 skb_queue_tail(queue, skb);
566 /* This code only runs from BH or BH protected context.
567 * Therefore the plain read_lock is ok here. -DaveM
569 read_lock(&sk->callback_lock);
570 if (!sk->dead) {
571 struct socket *sock = sk->socket;
572 wake_up_interruptible(sk->sleep);
573 if (sock && sock->fasync_list &&
574 !test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
575 __kill_fasync(sock->fasync_list, sig,
576 (sig == SIGURG) ? POLL_PRI : POLL_IN);
578 read_unlock(&sk->callback_lock);
580 return 0;
583 static void dn_nsp_otherdata(struct sock *sk, struct sk_buff *skb)
585 struct dn_scp *scp = &sk->protinfo.dn;
586 unsigned short segnum;
587 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
588 int queued = 0;
590 if (skb->len < 2)
591 goto out;
593 cb->segnum = segnum = dn_ntohs(*(__u16 *)skb->data);
594 skb_pull(skb, 2);
596 if (((sk->protinfo.dn.numoth_rcv + 1) & 0x0fff) == (segnum & 0x0fff)) {
598 if (dn_queue_skb(sk, skb, SIGURG, &scp->other_receive_queue) == 0) {
599 sk->protinfo.dn.numoth_rcv++;
600 scp->other_report = 0;
601 queued = 1;
605 dn_nsp_send_oth_ack(sk);
606 out:
607 if (!queued)
608 kfree_skb(skb);
611 static void dn_nsp_data(struct sock *sk, struct sk_buff *skb)
613 int queued = 0;
614 unsigned short segnum;
615 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
616 struct dn_scp *scp = &sk->protinfo.dn;
618 if (skb->len < 2)
619 goto out;
621 cb->segnum = segnum = dn_ntohs(*(__u16 *)skb->data);
622 skb_pull(skb, 2);
624 if (((sk->protinfo.dn.numdat_rcv + 1) & 0x0FFF) ==
625 (segnum & 0x0FFF)) {
627 if (dn_queue_skb(sk, skb, SIGIO, &sk->receive_queue) == 0) {
628 sk->protinfo.dn.numdat_rcv++;
629 queued = 1;
632 if ((scp->flowloc_sw == DN_SEND) && dn_congested(sk)) {
633 scp->flowloc_sw = DN_DONTSEND;
634 dn_nsp_send_lnk(sk, DN_DONTSEND);
638 dn_nsp_send_data_ack(sk);
639 out:
640 if (!queued)
641 kfree_skb(skb);
645 * If one of our conninit messages is returned, this function
646 * deals with it. It puts the socket into the NO_COMMUNICATION
647 * state.
649 static void dn_returned_conn_init(struct sock *sk, struct sk_buff *skb)
651 struct dn_scp *scp = &sk->protinfo.dn;
653 if (scp->state == DN_CI) {
654 scp->state = DN_NC;
655 sk->state = TCP_CLOSE;
656 if (!sk->dead)
657 sk->state_change(sk);
660 kfree_skb(skb);
663 static void dn_nsp_no_socket(struct sk_buff *skb, unsigned short reason)
665 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
667 if ((reason != NSP_REASON_OK) && ((cb->nsp_flags & 0x0c) == 0x08)) {
668 switch(cb->nsp_flags & 0x70) {
669 case 0x10:
670 case 0x60: /* (Retransmitted) Connect Init */
671 dn_nsp_return_disc(skb, NSP_DISCINIT, reason);
672 break;
673 case 0x20: /* Connect Confirm */
674 dn_nsp_return_disc(skb, NSP_DISCCONF, reason);
675 break;
679 kfree_skb(skb);
682 static int dn_nsp_rx_packet(struct sk_buff *skb)
684 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
685 struct sock *sk = NULL;
686 unsigned char *ptr = (unsigned char *)skb->data;
687 unsigned short reason = NSP_REASON_NL;
689 skb->h.raw = skb->data;
690 cb->nsp_flags = *ptr++;
692 if (decnet_debug_level & 2)
693 printk(KERN_DEBUG "dn_nsp_rx: Message type 0x%02x\n", (int)cb->nsp_flags);
695 if (skb->len < 2)
696 goto free_out;
698 if (cb->nsp_flags & 0x83)
699 goto free_out;
702 * Returned packets...
703 * Swap src & dst and look up in the normal way.
705 if (cb->rt_flags & DN_RT_F_RTS) {
706 unsigned short tmp = cb->dst_port;
707 cb->dst_port = cb->src_port;
708 cb->src_port = tmp;
709 tmp = cb->dst;
710 cb->dst = cb->src;
711 cb->src = tmp;
712 sk = dn_find_by_skb(skb);
713 goto got_it;
717 * Filter out conninits and useless packet types
719 if ((cb->nsp_flags & 0x0c) == 0x08) {
720 switch(cb->nsp_flags & 0x70) {
721 case 0x00: /* NOP */
722 case 0x70: /* Reserved */
723 case 0x50: /* Reserved, Phase II node init */
724 goto free_out;
725 case 0x10:
726 case 0x60:
727 sk = dn_find_listener(skb, &reason);
728 goto got_it;
732 if (skb->len < 3)
733 goto free_out;
736 * Grab the destination address.
738 cb->dst_port = *(unsigned short *)ptr;
739 cb->src_port = 0;
740 ptr += 2;
743 * If not a connack, grab the source address too.
745 if (skb->len >= 5) {
746 cb->src_port = *(unsigned short *)ptr;
747 ptr += 2;
748 skb_pull(skb, 5);
752 * Find the socket to which this skb is destined.
754 sk = dn_find_by_skb(skb);
755 got_it:
756 if (sk != NULL) {
757 struct dn_scp *scp = &sk->protinfo.dn;
758 int ret;
760 /* Reset backoff */
761 scp->nsp_rxtshift = 0;
763 bh_lock_sock(sk);
764 ret = 0;
765 if (sk->lock.users == 0)
766 ret = dn_nsp_backlog_rcv(sk, skb);
767 else
768 sk_add_backlog(sk, skb);
769 bh_unlock_sock(sk);
770 sock_put(sk);
772 return ret;
775 dn_nsp_no_socket(skb, reason);
776 return 1;
778 free_out:
779 kfree_skb(skb);
780 return 0;
783 int dn_nsp_rx(struct sk_buff *skb)
785 return NF_HOOK(PF_DECnet, NF_DN_LOCAL_IN, skb, skb->dev, NULL, dn_nsp_rx_packet);
789 * This is the main receive routine for sockets. It is called
790 * from the above when the socket is not busy, and also from
791 * sock_release() when there is a backlog queued up.
793 int dn_nsp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
795 struct dn_scp *scp = &sk->protinfo.dn;
796 struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;
798 if (cb->rt_flags & DN_RT_F_RTS) {
799 dn_returned_conn_init(sk, skb);
800 return 0;
804 * Control packet.
806 if ((cb->nsp_flags & 0x0c) == 0x08) {
807 switch(cb->nsp_flags & 0x70) {
808 case 0x10:
809 case 0x60:
810 dn_nsp_conn_init(sk, skb);
811 break;
812 case 0x20:
813 dn_nsp_conn_conf(sk, skb);
814 break;
815 case 0x30:
816 dn_nsp_disc_init(sk, skb);
817 break;
818 case 0x40:
819 dn_nsp_disc_conf(sk, skb);
820 break;
823 } else if (cb->nsp_flags == 0x24) {
825 * Special for connacks, 'cos they don't have
826 * ack data or ack otherdata info.
828 dn_nsp_conn_ack(sk, skb);
829 } else {
830 int other = 1;
832 /* both data and ack frames can kick a CC socket into RUN */
833 if ((scp->state == DN_CC) && !sk->dead) {
834 scp->state = DN_RUN;
835 sk->state = TCP_ESTABLISHED;
836 sk->state_change(sk);
839 if ((cb->nsp_flags & 0x1c) == 0)
840 other = 0;
841 if (cb->nsp_flags == 0x04)
842 other = 0;
845 * Read out ack data here, this applies equally
846 * to data, other data, link serivce and both
847 * ack data and ack otherdata.
849 dn_process_ack(sk, skb, other);
852 * If we've some sort of data here then call a
853 * suitable routine for dealing with it, otherwise
854 * the packet is an ack and can be discarded.
856 if ((cb->nsp_flags & 0x0c) == 0) {
858 if (scp->state != DN_RUN)
859 goto free_out;
861 switch(cb->nsp_flags) {
862 case 0x10: /* LS */
863 dn_nsp_linkservice(sk, skb);
864 break;
865 case 0x30: /* OD */
866 dn_nsp_otherdata(sk, skb);
867 break;
868 default:
869 dn_nsp_data(sk, skb);
872 } else { /* Ack, chuck it out here */
873 free_out:
874 kfree_skb(skb);
878 return 0;