4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Minor number allocation for various protocol modules.
32 #include <sys/types.h>
34 #include <sys/mutex.h>
36 #include <sys/types.h>
37 #include <sys/mkdev.h>
38 #include <sys/param.h>
39 #include <inet/common.h>
41 typedef struct inet_arena
{
42 vmem_t
*ineta_arena
; /* Minor number arena */
43 minor_t ineta_maxminor
; /* max minor number in the arena */
47 inet_minor_create(char *name
, dev_t min_dev
, dev_t max_dev
, int kmflags
)
49 inet_arena_t
*arena
= kmem_alloc(sizeof (inet_arena_t
), kmflags
);
52 arena
->ineta_maxminor
= max_dev
;
53 arena
->ineta_arena
= vmem_create(name
,
54 (void *)min_dev
, arena
->ineta_maxminor
- min_dev
+ 1,
55 1, NULL
, NULL
, NULL
, 1, kmflags
| VMC_IDENTIFIER
);
57 if (arena
->ineta_arena
== NULL
) {
58 kmem_free(arena
, sizeof (inet_arena_t
));
67 inet_minor_destroy(void *a
)
69 inet_arena_t
*arena
= (inet_arena_t
*)a
;
72 vmem_destroy(arena
->ineta_arena
);
73 kmem_free(arena
, sizeof (inet_arena_t
));
78 inet_minor_alloc(void *arena
)
80 return ((dev_t
)vmem_alloc(((inet_arena_t
*)arena
)->ineta_arena
,
85 inet_minor_free(void *arena
, dev_t dev
)
87 ASSERT((dev
!= OPENFAIL
) && (dev
!= 0) && (dev
<= MAXMIN
));
88 vmem_free(((inet_arena_t
*)arena
)->ineta_arena
, (void *)dev
, 1);
92 * This function is used to free a message that has gone through
93 * mi_copyin processing which modifies the M_IOCTL mblk's b_next
94 * and b_prev pointers. We use this function to set b_next/b_prev
95 * to NULL and free them.
98 inet_freemsg(mblk_t
*mp
)
102 for (; bp
!= NULL
; bp
= bp
->b_cont
) {