1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _LIBINETUTIL_H
28*0Sstevel@tonic-gate #define	_LIBINETUTIL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * Contains SMI-private API for general internet functionality
34*0Sstevel@tonic-gate  */
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #ifdef	__cplusplus
37*0Sstevel@tonic-gate extern "C" {
38*0Sstevel@tonic-gate #endif
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #include <netinet/inetutil.h>
41*0Sstevel@tonic-gate #include <sys/types.h>
42*0Sstevel@tonic-gate #include <sys/socket.h>
43*0Sstevel@tonic-gate #include <netinet/in.h>
44*0Sstevel@tonic-gate #include <net/if.h>
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(_BOOT)
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #define	IFSP_MAXMODS	9	/* Max modules that can be pushed on if */
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate typedef struct {
51*0Sstevel@tonic-gate 	uint_t		ifsp_ppa;	/* Physical Point of Attachment */
52*0Sstevel@tonic-gate 	uint_t		ifsp_lun;	/* Logical Unit number */
53*0Sstevel@tonic-gate 	boolean_t	ifsp_lunvalid;	/* TRUE if lun is valid */
54*0Sstevel@tonic-gate 	int		ifsp_modcnt;	/* Number of modules to be pushed */
55*0Sstevel@tonic-gate 	char		ifsp_devnm[LIFNAMSIZ];	/* only the device name */
56*0Sstevel@tonic-gate 	char		ifsp_mods[IFSP_MAXMODS][LIFNAMSIZ]; /* table of mods */
57*0Sstevel@tonic-gate } ifspec_t;
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate extern boolean_t ifparse_ifspec(const char *, ifspec_t *);
60*0Sstevel@tonic-gate extern void get_netmask4(const struct in_addr *, struct in_addr *);
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate /*
63*0Sstevel@tonic-gate  * Timer queues
64*0Sstevel@tonic-gate  *
65*0Sstevel@tonic-gate  * timer queues are a facility for managing timeouts in unix.  in the
66*0Sstevel@tonic-gate  * event driven model, unix provides us with poll(2)/select(3C), which
67*0Sstevel@tonic-gate  * allow us to coordinate waiting on multiple descriptors with an
68*0Sstevel@tonic-gate  * optional timeout.  however, often (as is the case with the DHCP
69*0Sstevel@tonic-gate  * agent), we want to manage multiple independent timeouts (say, one
70*0Sstevel@tonic-gate  * for waiting for an OFFER to come back from a server in response to
71*0Sstevel@tonic-gate  * a DISCOVER sent out on one interface, and another for waiting for
72*0Sstevel@tonic-gate  * the T1 time on another interface).  timer queues allow us to do
73*0Sstevel@tonic-gate  * this in the event-driven model.
74*0Sstevel@tonic-gate  *
75*0Sstevel@tonic-gate  * note that timer queues do not in and of themselves provide the
76*0Sstevel@tonic-gate  * event driven model (for instance, there is no handle_events()
77*0Sstevel@tonic-gate  * routine).  they merely provide the hooks to support multiple
78*0Sstevel@tonic-gate  * independent timeouts.  this is done for both simplicity and
79*0Sstevel@tonic-gate  * applicability (for instance, while one approach would be to use
80*0Sstevel@tonic-gate  * this timer queue with poll(2), another one would be to use SIGALRM
81*0Sstevel@tonic-gate  * to wake up periodically, and then process all the expired timers.)
82*0Sstevel@tonic-gate  */
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate typedef struct iu_timer_queue iu_tq_t;
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate  * a iu_timer_id_t refers to a given timer.  its value should not be
88*0Sstevel@tonic-gate  * interpreted by the interface consumer.  it is a signed arithmetic
89*0Sstevel@tonic-gate  * type, and no valid iu_timer_id_t has the value `-1'.
90*0Sstevel@tonic-gate  */
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate typedef int iu_timer_id_t;
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate #define	IU_TIMER_ID_MAX	1024	/* max number of concurrent timers */
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate /*
97*0Sstevel@tonic-gate  * a iu_tq_callback_t is a function that is called back in response to a
98*0Sstevel@tonic-gate  * timer expiring.  it may then carry out any necessary work,
99*0Sstevel@tonic-gate  * including rescheduling itself for callback or scheduling /
100*0Sstevel@tonic-gate  * cancelling other timers.  the `void *' argument is the same value
101*0Sstevel@tonic-gate  * that was passed into iu_schedule_timer(), and if it is dynamically
102*0Sstevel@tonic-gate  * allocated, it is the callback's responsibility to know that, and to
103*0Sstevel@tonic-gate  * free it.
104*0Sstevel@tonic-gate  */
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate typedef void	iu_tq_callback_t(iu_tq_t *, void *);
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate iu_tq_t		*iu_tq_create(void);
109*0Sstevel@tonic-gate void		iu_tq_destroy(iu_tq_t *);
110*0Sstevel@tonic-gate iu_timer_id_t	iu_schedule_timer(iu_tq_t *, uint32_t, iu_tq_callback_t *,
111*0Sstevel@tonic-gate 		    void *);
112*0Sstevel@tonic-gate iu_timer_id_t	iu_schedule_timer_ms(iu_tq_t *, uint64_t, iu_tq_callback_t *,
113*0Sstevel@tonic-gate 		    void *);
114*0Sstevel@tonic-gate int		iu_adjust_timer(iu_tq_t *, iu_timer_id_t, uint32_t);
115*0Sstevel@tonic-gate int		iu_cancel_timer(iu_tq_t *, iu_timer_id_t, void **);
116*0Sstevel@tonic-gate int		iu_expire_timers(iu_tq_t *);
117*0Sstevel@tonic-gate int		iu_earliest_timer(iu_tq_t *);
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate /*
120*0Sstevel@tonic-gate  * Event Handler
121*0Sstevel@tonic-gate  *
122*0Sstevel@tonic-gate  * an event handler is an object-oriented "wrapper" for select(3C) /
123*0Sstevel@tonic-gate  * poll(2), aimed to make the event demultiplexing system calls easier
124*0Sstevel@tonic-gate  * to use and provide a generic reusable component.  instead of
125*0Sstevel@tonic-gate  * applications directly using select(3C) / poll(2), they register
126*0Sstevel@tonic-gate  * events that should be received with the event handler, providing a
127*0Sstevel@tonic-gate  * callback function to call when the event occurs.  they then call
128*0Sstevel@tonic-gate  * iu_handle_events() to wait and callback the registered functions
129*0Sstevel@tonic-gate  * when events occur.  also called a `reactor'.
130*0Sstevel@tonic-gate  */
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate typedef struct iu_event_handler iu_eh_t;
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate /*
135*0Sstevel@tonic-gate  * an iu_event_id_t refers to a given event.  its value should not be
136*0Sstevel@tonic-gate  * interpreted by the interface consumer.  it is a signed arithmetic
137*0Sstevel@tonic-gate  * type, and no valid iu_event_id_t has the value `-1'.
138*0Sstevel@tonic-gate  */
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate typedef int iu_event_id_t;
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate /*
143*0Sstevel@tonic-gate  * an iu_eh_callback_t is a function that is called back in response to
144*0Sstevel@tonic-gate  * an event occurring.  it may then carry out any work necessary in
145*0Sstevel@tonic-gate  * response to the event.  it receives the file descriptor upon which
146*0Sstevel@tonic-gate  * the event occurred, a bit array of events that occurred (the same
147*0Sstevel@tonic-gate  * array used as the revents by poll(2)), and its context through the
148*0Sstevel@tonic-gate  * `void *' that was originally passed into iu_register_event().
149*0Sstevel@tonic-gate  *
150*0Sstevel@tonic-gate  * NOTE: the same descriptor may not be registered multiple times for
151*0Sstevel@tonic-gate  * different callbacks.  if this behavior is desired, either use dup(2)
152*0Sstevel@tonic-gate  * to get a unique descriptor, or demultiplex in the callback function
153*0Sstevel@tonic-gate  * based on the events.
154*0Sstevel@tonic-gate  */
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate typedef void	iu_eh_callback_t(iu_eh_t *, int, short, iu_event_id_t, void *);
157*0Sstevel@tonic-gate typedef void	iu_eh_sighandler_t(iu_eh_t *, int, void *);
158*0Sstevel@tonic-gate typedef boolean_t iu_eh_shutdown_t(iu_eh_t *, void *);
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate iu_eh_t		*iu_eh_create(void);
161*0Sstevel@tonic-gate void		iu_eh_destroy(iu_eh_t *);
162*0Sstevel@tonic-gate iu_event_id_t	iu_register_event(iu_eh_t *, int, short, iu_eh_callback_t *,
163*0Sstevel@tonic-gate 		    void *);
164*0Sstevel@tonic-gate int		iu_unregister_event(iu_eh_t *, iu_event_id_t, void **);
165*0Sstevel@tonic-gate int		iu_handle_events(iu_eh_t *, iu_tq_t *);
166*0Sstevel@tonic-gate void		iu_stop_handling_events(iu_eh_t *, unsigned int,
167*0Sstevel@tonic-gate 		    iu_eh_shutdown_t *, void *);
168*0Sstevel@tonic-gate int		iu_eh_register_signal(iu_eh_t *, int, iu_eh_sighandler_t *,
169*0Sstevel@tonic-gate 		    void *);
170*0Sstevel@tonic-gate int		iu_eh_unregister_signal(iu_eh_t *, int, void **);
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate #endif	/* !defined(_KERNEL) && !defined(_BOOT) */
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate #ifdef	__cplusplus
175*0Sstevel@tonic-gate }
176*0Sstevel@tonic-gate #endif
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate #endif	/* !_LIBINETUTIL_H */
179