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