kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / netproto / atm / uni / uniip.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/uni/uniip.c,v 1.4 1999/08/28 00:49:03 peter Exp $
27  *      @(#) $DragonFly: src/sys/netproto/atm/uni/uniip.c,v 1.3 2003/08/07 21:17:35 dillon Exp $
28  */
29
30 /*
31  * ATM Forum UNI Support
32  * ---------------------
33  *
34  * UNI IP interface module
35  *
36  */
37
38 #include <netatm/kern_include.h>
39
40 #include <netatm/ipatm/ipatm_var.h>
41 #include <netatm/ipatm/ipatm_serv.h>
42 #include "uniip_var.h"
43
44 /*
45  * Local functions
46  */
47 static int      uniip_ipact __P((struct ip_nif *));
48 static int      uniip_ipdact __P((struct ip_nif *));
49
50
51 /*
52  * Global variables
53  */
54 struct uniip    *uniip_head = NULL;
55
56 struct ip_serv  uniip_ipserv = {
57         uniip_ipact,
58         uniip_ipdact,
59         uniarp_ioctl,
60         uniarp_pvcopen,
61         uniarp_svcout,
62         uniarp_svcin,
63         uniarp_svcactive,
64         uniarp_vcclose,
65         NULL,
66         { { ATM_AAL5, ATM_ENC_LLC} },
67 };
68
69
70 /*
71  * Local variables
72  */
73 static struct sp_info  uniip_pool = {
74         "uni ip pool",                  /* si_name */
75         sizeof(struct uniip),           /* si_blksiz */
76         2,                              /* si_blkcnt */
77         100                             /* si_maxallow */
78 };
79
80
81 /*
82  * Process module loading notification
83  * 
84  * Called whenever the uni module is initializing.  
85  *
86  * Arguments:
87  *      none
88  *
89  * Returns:
90  *      0       initialization successful
91  *      errno   initialization failed - reason indicated
92  *
93  */
94 int
95 uniip_start()
96 {
97         int     err;
98
99         /*
100          * Tell arp to initialize stuff
101          */
102         err = uniarp_start();
103
104         return (err);
105 }
106
107
108 /*
109  * Process module unloading notification
110  * 
111  * Called whenever the uni module is about to be unloaded.  All signalling
112  * instances will have been previously detached.  All uniip resources
113  * must be freed now.
114  *
115  * Arguments:
116  *      none
117  *
118  * Returns:
119  *      0       shutdown was successful 
120  *      errno   shutdown failed - reason indicated
121  *
122  */
123 int
124 uniip_stop()
125 {
126
127         /*
128          * All IP interfaces should be gone
129          */
130         if (uniip_head)
131                 return (EBUSY);
132
133         /*
134          * Tell arp to stop
135          */
136         uniarp_stop();
137
138         /*
139          * Free our storage pools
140          */
141         atm_release_pool(&uniip_pool);
142
143         return (0);
144 }
145
146
147 /*
148  * Process IP Network Interface Activation
149  * 
150  * Called whenever an IP network interface becomes active.
151  *
152  * Called at splnet.
153  *
154  * Arguments:
155  *      inp     pointer to IP network interface
156  *
157  * Returns:
158  *      0       command successful
159  *      errno   command failed - reason indicated
160  *
161  */
162 static int
163 uniip_ipact(inp)
164         struct ip_nif   *inp;
165 {
166         struct uniip            *uip;
167
168         /*
169          * Make sure we don't already have this interface
170          */
171         for (uip = uniip_head; uip; uip = uip->uip_next) {
172                 if (uip->uip_ipnif == inp)
173                         return (EEXIST);
174         }
175
176         /*
177          * Get a new interface control block
178          */
179         uip = (struct uniip *)atm_allocate(&uniip_pool);
180         if (uip == NULL)
181                 return (ENOMEM);
182
183         /*
184          * Initialize and link up
185          */
186         uip->uip_ipnif = inp;
187         LINK2TAIL(uip, struct uniip, uniip_head, uip_next);
188
189         /*
190          * Link from IP world
191          */
192         inp->inf_isintf = (caddr_t)uip;
193
194         /*
195          * Tell arp about new interface
196          */
197         uniarp_ipact(uip);
198
199         return (0);
200 }
201
202
203 /*
204  * Process IP Network Interface Deactivation
205  * 
206  * Called whenever an IP network interface becomes inactive.
207  *
208  * Called at splnet.
209  *
210  * Arguments:
211  *      inp     pointer to IP network interface
212  *
213  * Returns:
214  *      0       command successful
215  *      errno   command failed - reason indicated
216  *
217  */
218 static int
219 uniip_ipdact(inp)
220         struct ip_nif   *inp;
221 {
222         struct uniip            *uip;
223
224         /*
225          * Get the appropriate IP interface block
226          */
227         uip = (struct uniip *)inp->inf_isintf;
228         if (uip == NULL)
229                 return (ENXIO);
230
231         /*
232          * Let arp know about this
233          */
234         uniarp_ipdact(uip);
235
236         /*
237          * Free interface info
238          */
239         UNLINK(uip, struct uniip, uniip_head, uip_next);
240         if (uip->uip_prefix != NULL)
241                 KM_FREE(uip->uip_prefix, 
242                         uip->uip_nprefix * sizeof(struct uniarp_prf), M_DEVBUF);
243         atm_free((caddr_t)uip);
244
245         return (0);
246 }
247