2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _LIBINETUTIL_H
2N/A#define _LIBINETUTIL_H
2N/A
2N/A/*
2N/A * Contains SMI-private API for general Internet functionality
2N/A */
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A#include <netinet/inetutil.h>
2N/A#include <sys/types.h>
2N/A#include <sys/socket.h>
2N/A#include <netinet/in.h>
2N/A#include <net/if.h>
2N/A
2N/A#if !defined(_KERNEL) && !defined(_BOOT)
2N/A
2N/Atypedef struct {
2N/A uint_t ifsp_ppa; /* Physical Point of Attachment */
2N/A uint_t ifsp_lun; /* Logical Unit number */
2N/A boolean_t ifsp_lunvalid; /* TRUE if lun is valid */
2N/A char ifsp_devnm[LIFNAMSIZ]; /* only the device name */
2N/A} ifspec_t;
2N/A
2N/Aextern boolean_t ifparse_ifspec(const char *, ifspec_t *);
2N/Aextern boolean_t dlparse_drvppa(const char *, char *, uint_t, uint_t *);
2N/Aextern boolean_t dlparse_zonelinkname(const char *, char *, zoneid_t *);
2N/A
2N/Aextern void get_netmask4(const struct in_addr *, struct in_addr *);
2N/Aextern boolean_t sockaddrcmp(const struct sockaddr_storage *,
2N/A const struct sockaddr_storage *);
2N/Aextern int plen2mask(uint_t, sa_family_t, struct sockaddr *);
2N/Aextern int mask2plen(const struct sockaddr *);
2N/Aextern boolean_t sockaddrunspec(const struct sockaddr *);
2N/A
2N/Aextern boolean_t valid_hostname(const char *);
2N/Aextern void num2alpha(int32_t, char **, char *);
2N/A
2N/A/*
2N/A * Extended version of the classic BSD ifaddrlist() interface:
2N/A *
2N/A * int ifaddrlist(struct ifaddrlist **addrlistp, int af, uint_t flags,
2N/A * char *errbuf);
2N/A *
2N/A * * addrlistp: Upon success, ifaddrlist() sets *addrlistp to a
2N/A * dynamically-allocated array of addresses.
2N/A *
2N/A * * af: Either AF_INET to obtain IPv4 addresses, or AF_INET6 to
2N/A * obtain IPv6 addresses.
2N/A *
2N/A * * flags: LIFC_* flags that control the classes of interfaces that
2N/A * will be visible.
2N/A *
2N/A * * errbuf: A caller-supplied buffer of ERRBUFSIZE. Upon failure,
2N/A * provides the reason for the failure.
2N/A *
2N/A * Upon success, ifaddrlist() returns the number of addresses in the array
2N/A * pointed to by `addrlistp'. If the count is 0, then `addrlistp' is NULL.
2N/A */
2N/Aunion any_in_addr {
2N/A struct in6_addr addr6;
2N/A struct in_addr addr;
2N/A};
2N/A
2N/Astruct ifaddrlist {
2N/A int index; /* interface index */
2N/A union any_in_addr addr; /* interface address */
2N/A char device[LIFNAMSIZ + 1]; /* interface name */
2N/A uint64_t flags; /* interface flags */
2N/A};
2N/A
2N/A#define ERRBUFSIZE 128 /* expected size of fourth argument */
2N/A
2N/Aextern int ifaddrlist(struct ifaddrlist **, int, uint_t, char *);
2N/A
2N/A/*
2N/A * Similar to ifaddrlist(), but returns a linked-list of addresses for a
2N/A * *specific* interface name, and allows specific address flags to be matched
2N/A * against. A linked list is used rather than an array so that information
2N/A * can grow over time without affecting binary compatibility. Also, leaves
2N/A * error-handling up to the caller. Returns the number of ifaddrlistx's
2N/A * chained through ifaddrp.
2N/A *
2N/A * int ifaddrlistx(const char *ifname, uint64_t set, uint64_t clear,
2N/A * ifaddrlistx_t **ifaddrp);
2N/A *
2N/A * * ifname: Interface name to match against.
2N/A *
2N/A * * set: One or more flags that must be set on the address for
2N/A * it to be returned.
2N/A *
2N/A * * clear: Flags that must be clear on the address for it to be
2N/A * returned.
2N/A *
2N/A * * ifaddrp: Upon success, ifaddrlistx() sets *ifaddrp to the head
2N/A * of a dynamically-allocated array of ifaddrlistx structures.
2N/A *
2N/A * Once done, the caller must free `ifaddrp' by calling ifaddrlistx_free().
2N/A */
2N/Atypedef struct ifaddrlistx {
2N/A struct ifaddrlistx *ia_next;
2N/A char ia_name[LIFNAMSIZ];
2N/A uint64_t ia_flags;
2N/A struct sockaddr_storage ia_addr;
2N/A} ifaddrlistx_t;
2N/A
2N/Aextern int ifaddrlistx(const char *, uint64_t, uint64_t, ifaddrlistx_t **);
2N/Aextern void ifaddrlistx_free(ifaddrlistx_t *);
2N/A
2N/A/*
2N/A * Timer queues
2N/A *
2N/A * timer queues are a facility for managing timeouts in unix. in the
2N/A * event driven model, unix provides us with poll(2)/select(3C), which
2N/A * allow us to coordinate waiting on multiple descriptors with an
2N/A * optional timeout. however, often (as is the case with the DHCP
2N/A * agent), we want to manage multiple independent timeouts (say, one
2N/A * for waiting for an OFFER to come back from a server in response to
2N/A * a DISCOVER sent out on one interface, and another for waiting for
2N/A * the T1 time on another interface). timer queues allow us to do
2N/A * this in the event-driven model.
2N/A *
2N/A * note that timer queues do not in and of themselves provide the
2N/A * event driven model (for instance, there is no handle_events()
2N/A * routine). they merely provide the hooks to support multiple
2N/A * independent timeouts. this is done for both simplicity and
2N/A * applicability (for instance, while one approach would be to use
2N/A * this timer queue with poll(2), another one would be to use SIGALRM
2N/A * to wake up periodically, and then process all the expired timers.)
2N/A */
2N/A
2N/Atypedef struct iu_timer_queue iu_tq_t;
2N/A
2N/A/*
2N/A * a iu_timer_id_t refers to a given timer. its value should not be
2N/A * interpreted by the interface consumer. it is a signed arithmetic
2N/A * type, and no valid iu_timer_id_t has the value `-1'.
2N/A */
2N/A
2N/Atypedef int iu_timer_id_t;
2N/A
2N/A#define IU_TIMER_ID_MAX 4096 /* max number of concurrent timers */
2N/A
2N/A/*
2N/A * a iu_tq_callback_t is a function that is called back in response to a
2N/A * timer expiring. it may then carry out any necessary work,
2N/A * including rescheduling itself for callback or scheduling /
2N/A * cancelling other timers. the `void *' argument is the same value
2N/A * that was passed into iu_schedule_timer(), and if it is dynamically
2N/A * allocated, it is the callback's responsibility to know that, and to
2N/A * free it.
2N/A */
2N/A
2N/Atypedef void iu_tq_callback_t(iu_tq_t *, void *);
2N/A
2N/Aiu_tq_t *iu_tq_create(void);
2N/Avoid iu_tq_destroy(iu_tq_t *);
2N/Aiu_timer_id_t iu_schedule_timer(iu_tq_t *, uint32_t, iu_tq_callback_t *,
2N/A void *);
2N/Aiu_timer_id_t iu_schedule_timer_ms(iu_tq_t *, uint64_t, iu_tq_callback_t *,
2N/A void *);
2N/Aint iu_adjust_timer(iu_tq_t *, iu_timer_id_t, uint32_t);
2N/Aint iu_cancel_timer(iu_tq_t *, iu_timer_id_t, void **);
2N/Aint iu_expire_timers(iu_tq_t *);
2N/Aint iu_earliest_timer(iu_tq_t *);
2N/A
2N/A/*
2N/A * Event Handler
2N/A *
2N/A * an event handler is an object-oriented "wrapper" for select(3C) /
2N/A * poll(2), aimed to make the event demultiplexing system calls easier
2N/A * to use and provide a generic reusable component. instead of
2N/A * applications directly using select(3C) / poll(2), they register
2N/A * events that should be received with the event handler, providing a
2N/A * callback function to call when the event occurs. they then call
2N/A * iu_handle_events() to wait and callback the registered functions
2N/A * when events occur. also called a `reactor'.
2N/A */
2N/A
2N/Atypedef struct iu_event_handler iu_eh_t;
2N/A
2N/A/*
2N/A * an iu_event_id_t refers to a given event. its value should not be
2N/A * interpreted by the interface consumer. it is a signed arithmetic
2N/A * type, and no valid iu_event_id_t has the value `-1'.
2N/A */
2N/A
2N/Atypedef int iu_event_id_t;
2N/A
2N/A/*
2N/A * an iu_eh_callback_t is a function that is called back in response to
2N/A * an event occurring. it may then carry out any work necessary in
2N/A * response to the event. it receives the file descriptor upon which
2N/A * the event occurred, a bit array of events that occurred (the same
2N/A * array used as the revents by poll(2)), and its context through the
2N/A * `void *' that was originally passed into iu_register_event().
2N/A *
2N/A * NOTE: the same descriptor may not be registered multiple times for
2N/A * different callbacks. if this behavior is desired, either use dup(2)
2N/A * to get a unique descriptor, or demultiplex in the callback function
2N/A * based on the events.
2N/A */
2N/A
2N/Atypedef void iu_eh_callback_t(iu_eh_t *, int, short, iu_event_id_t, void *);
2N/Atypedef void iu_eh_sighandler_t(iu_eh_t *, int, void *);
2N/Atypedef boolean_t iu_eh_shutdown_t(iu_eh_t *, void *);
2N/A
2N/Aiu_eh_t *iu_eh_create(void);
2N/Avoid iu_eh_destroy(iu_eh_t *);
2N/Aiu_event_id_t iu_register_event(iu_eh_t *, int, short, iu_eh_callback_t *,
2N/A void *);
2N/Aint iu_unregister_event(iu_eh_t *, iu_event_id_t, void **);
2N/Aint iu_handle_events(iu_eh_t *, iu_tq_t *);
2N/Avoid iu_stop_handling_events(iu_eh_t *, unsigned int,
2N/A iu_eh_shutdown_t *, void *);
2N/Aint iu_eh_register_signal(iu_eh_t *, int, iu_eh_sighandler_t *,
2N/A void *);
2N/Aint iu_eh_unregister_signal(iu_eh_t *, int, void **);
2N/A
2N/A/*
2N/A * soaf2str() provides numeric to string mapping of socket address family.
2N/A * Returns NULL if no mapping is found.
2N/A */
2N/Aextern const char *soaf2str(uint_t family);
2N/A
2N/A/*
2N/A * proto2str() provides numeric to string mapping of IP protocol.
2N/A * Returns NULL if no mapping is found.
2N/A */
2N/Aextern const char *ipproto2str(uint_t family, uint_t protocol);
2N/A
2N/A/*
2N/A * sotype2str() provides numeric to string mapping of socket type.
2N/A * Returns NULL if no mapping is found.
2N/A */
2N/Aextern const char *sotype2str(uint_t type);
2N/A
2N/A#endif /* !defined(_KERNEL) && !defined(_BOOT) */
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* !_LIBINETUTIL_H */