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