network - Completely revamp the netisr / dispatch code
[dragonfly.git] / sys / netproto / atm / ipatm / ipatm_input.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/sys/netatm/ipatm/ipatm_input.c,v 1.4 2000/01/17 20:49:43 mks Exp $
27  *      @(#) $DragonFly: src/sys/netproto/atm/ipatm/ipatm_input.c,v 1.7 2006/01/14 13:36:39 swildner Exp $
28  */
29
30 /*
31  * IP Over ATM Support
32  * -------------------
33  *
34  * Process stack and data input
35  *
36  */
37
38 #include <netproto/atm/kern_include.h>
39
40 #include "ipatm_var.h"
41
42 /*
43  * Process VCC Input Data
44  * 
45  * Arguments:
46  *      tok     ipatm connection token (pointer to ipvcc)
47  *      m       pointer to input packet buffer chain
48  *
49  * Returns:
50  *      none
51  *
52  */
53 void
54 ipatm_cpcs_data(void *tok, KBuffer *m)
55 {
56         struct ipvcc    *ivp = tok;
57
58 #ifdef DIAGNOSTIC
59         if (ipatm_print) {
60                 atm_pdu_print(m, "ipatm_input");
61         }
62 #endif
63
64         /*
65          * Handle input packet
66          */
67         if (ivp->iv_state != IPVCC_ACTIVE) {
68                 KB_FREEALL(m);
69                 ipatm_stat.ias_rcvstate++;
70                 return;
71         }
72
73         /*
74          * IP packet - reset idle timer
75          */
76         ivp->iv_idle = 0;
77
78         /*
79          * Pass packet to IP
80          */
81         ipatm_ipinput(ivp->iv_ipnif, m);
82 }
83
84
85 /*
86  * IP Input Packet Handler
87  * 
88  * All IP packets received from various ATM sources will be sent here
89  * for final queuing to the IP layer.
90  *
91  * Arguments:
92  *      inp     pointer to packet's receiving IP network interface
93  *      m       pointer to packet buffer chain
94  *
95  * Returns:
96  *      0       packet successfully queued to IP layer
97  *      else    error queuing packet, buffer chain freed
98  *
99  */
100 int
101 ipatm_ipinput(struct ip_nif *inp, KBuffer *m)
102 {
103 #ifdef DIAGNOSTIC
104         if (ipatm_print) {
105                 atm_pdu_print(m, "ipatm_ipinput");
106         }
107 #endif
108
109 #ifdef DIAGNOSTIC
110         if (!KB_ISPKT(m)) {
111                 panic("ipatm_ipinput: no packet header");
112         }
113         {
114                 int     cnt = 0;
115                 KBuffer *m0 = m;
116
117                 while (m0) {
118                         cnt += KB_LEN(m0);
119                         m0 = KB_NEXT(m0);
120                 }
121                 if (m->m_pkthdr.len != cnt) {
122                         panic("ipatm_ipinput: packet length incorrect");
123                 }
124         }
125 #endif
126         /*
127          * Save the input ifnet pointer in the packet header
128          */
129         m->m_pkthdr.rcvif = (struct ifnet *)inp->inf_nif;
130
131         /*
132          * Finally, hand packet off to IP.
133          *
134          * NB: Since we're already in the softint kernel state, we
135          * just call IP directly to avoid the extra unnecessary 
136          * kernel scheduling.
137          */
138         netisr_queue(NETISR_IP, m);
139         return (0);
140 }