Deleted Added
full compact
ng_iface.c (131155) ng_iface.c (131575)
1/*
2 * ng_iface.c
3 *
4 * Copyright (c) 1996-1999 Whistle Communications, Inc.
5 * All rights reserved.
6 *
7 * Subject to the following obligations and disclaimer of warranty, use and
8 * redistribution of this software, in source or object code forms, with or

--- 21 unchanged lines hidden (view full) ---

30 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
34 * OF SUCH DAMAGE.
35 *
36 * Author: Archie Cobbs <archie@freebsd.org>
37 *
1/*
2 * ng_iface.c
3 *
4 * Copyright (c) 1996-1999 Whistle Communications, Inc.
5 * All rights reserved.
6 *
7 * Subject to the following obligations and disclaimer of warranty, use and
8 * redistribution of this software, in source or object code forms, with or

--- 21 unchanged lines hidden (view full) ---

30 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
34 * OF SUCH DAMAGE.
35 *
36 * Author: Archie Cobbs <archie@freebsd.org>
37 *
38 * $FreeBSD: head/sys/netgraph/ng_iface.c 131155 2004-06-26 22:24:16Z julian $
38 * $FreeBSD: head/sys/netgraph/ng_iface.c 131575 2004-07-04 16:11:03Z stefanf $
39 * $Whistle: ng_iface.c,v 1.33 1999/11/01 09:24:51 julian Exp $
40 */
41
42/*
43 * This node is also a system networking interface. It has
44 * a hook for each protocol (IP, AppleTalk, IPX, etc). Packets
45 * are simply relayed between the interface and the hooks.
46 *

--- 173 unchanged lines hidden (view full) ---

220
221/************************************************************************
222 HELPER STUFF
223 ************************************************************************/
224
225/*
226 * Get the family descriptor from the family ID
227 */
39 * $Whistle: ng_iface.c,v 1.33 1999/11/01 09:24:51 julian Exp $
40 */
41
42/*
43 * This node is also a system networking interface. It has
44 * a hook for each protocol (IP, AppleTalk, IPX, etc). Packets
45 * are simply relayed between the interface and the hooks.
46 *

--- 173 unchanged lines hidden (view full) ---

220
221/************************************************************************
222 HELPER STUFF
223 ************************************************************************/
224
225/*
226 * Get the family descriptor from the family ID
227 */
228static __inline__ iffam_p
228static __inline iffam_p
229get_iffam_from_af(sa_family_t family)
230{
231 iffam_p iffam;
232 int k;
233
234 for (k = 0; k < NUM_FAMILIES; k++) {
235 iffam = &gFamilies[k];
236 if (iffam->family == family)
237 return (iffam);
238 }
239 return (NULL);
240}
241
242/*
243 * Get the family descriptor from the hook
244 */
229get_iffam_from_af(sa_family_t family)
230{
231 iffam_p iffam;
232 int k;
233
234 for (k = 0; k < NUM_FAMILIES; k++) {
235 iffam = &gFamilies[k];
236 if (iffam->family == family)
237 return (iffam);
238 }
239 return (NULL);
240}
241
242/*
243 * Get the family descriptor from the hook
244 */
245static __inline__ iffam_p
245static __inline iffam_p
246get_iffam_from_hook(priv_p priv, hook_p hook)
247{
248 int k;
249
250 for (k = 0; k < NUM_FAMILIES; k++)
251 if (priv->hooks[k] == hook)
252 return (&gFamilies[k]);
253 return (NULL);
254}
255
256/*
257 * Get the hook from the iffam descriptor
258 */
259
246get_iffam_from_hook(priv_p priv, hook_p hook)
247{
248 int k;
249
250 for (k = 0; k < NUM_FAMILIES; k++)
251 if (priv->hooks[k] == hook)
252 return (&gFamilies[k]);
253 return (NULL);
254}
255
256/*
257 * Get the hook from the iffam descriptor
258 */
259
260static __inline__ hook_p *
260static __inline hook_p *
261get_hook_from_iffam(priv_p priv, iffam_p iffam)
262{
263 return (&priv->hooks[iffam - gFamilies]);
264}
265
266/*
267 * Get the iffam descriptor from the name
268 */
261get_hook_from_iffam(priv_p priv, iffam_p iffam)
262{
263 return (&priv->hooks[iffam - gFamilies]);
264}
265
266/*
267 * Get the iffam descriptor from the name
268 */
269static __inline__ iffam_p
269static __inline iffam_p
270get_iffam_from_name(const char *name)
271{
272 iffam_p iffam;
273 int k;
274
275 for (k = 0; k < NUM_FAMILIES; k++) {
276 iffam = &gFamilies[k];
277 if (!strcmp(iffam->hookname, name))
278 return (iffam);
279 }
280 return (NULL);
281}
282
283/*
284 * Find the first free unit number for a new interface.
285 * Increase the size of the unit bitmap as necessary.
286 */
270get_iffam_from_name(const char *name)
271{
272 iffam_p iffam;
273 int k;
274
275 for (k = 0; k < NUM_FAMILIES; k++) {
276 iffam = &gFamilies[k];
277 if (!strcmp(iffam->hookname, name))
278 return (iffam);
279 }
280 return (NULL);
281}
282
283/*
284 * Find the first free unit number for a new interface.
285 * Increase the size of the unit bitmap as necessary.
286 */
287static __inline__ int
287static __inline int
288ng_iface_get_unit(int *unit)
289{
290 int index, bit;
291
292 for (index = 0; index < ng_iface_units_len
293 && ng_iface_units[index] == 0; index++);
294 if (index == ng_iface_units_len) { /* extend array */
295 int i, *newarray, newlen;

--- 19 unchanged lines hidden (view full) ---

315 *unit = (index * UNITS_BITSPERWORD) + bit;
316 ng_units_in_use++;
317 return (0);
318}
319
320/*
321 * Free a no longer needed unit number.
322 */
288ng_iface_get_unit(int *unit)
289{
290 int index, bit;
291
292 for (index = 0; index < ng_iface_units_len
293 && ng_iface_units[index] == 0; index++);
294 if (index == ng_iface_units_len) { /* extend array */
295 int i, *newarray, newlen;

--- 19 unchanged lines hidden (view full) ---

315 *unit = (index * UNITS_BITSPERWORD) + bit;
316 ng_units_in_use++;
317 return (0);
318}
319
320/*
321 * Free a no longer needed unit number.
322 */
323static __inline__ void
323static __inline void
324ng_iface_free_unit(int unit)
325{
326 int index, bit;
327
328 index = unit / UNITS_BITSPERWORD;
329 bit = unit % UNITS_BITSPERWORD;
330 KASSERT(index < ng_iface_units_len,
331 ("%s: unit=%d len=%d", __func__, unit, ng_iface_units_len));

--- 499 unchanged lines hidden ---
324ng_iface_free_unit(int unit)
325{
326 int index, bit;
327
328 index = unit / UNITS_BITSPERWORD;
329 bit = unit % UNITS_BITSPERWORD;
330 KASSERT(index < ng_iface_units_len,
331 ("%s: unit=%d len=%d", __func__, unit, ng_iface_units_len));

--- 499 unchanged lines hidden ---