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 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#ifndef _LIBILB_H
2N/A#define _LIBILB_H
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A#include <sys/types.h>
2N/A#include <netinet/in.h>
2N/A#include <net/if.h>
2N/A
2N/A/* make sure these values stay in sync with definitions in ilb.h! */
2N/A#define ILB_FLAGS_RULE_ENABLED 0x01
2N/A#define ILB_FLAGS_RULE_STICKY 0x02
2N/A#define ILB_FLAGS_RULE_ALLRULES 0x04
2N/A#define ILB_FLAGS_RESERVED 0x08 /* in use by kernel, don't overlay */
2N/A
2N/A/*
2N/A * information whether we're interested in names or numerical information
2N/A */
2N/A#define ILB_FLAGS_SRV_HOSTNAME 0x01 /* a servers hostname was given */
2N/A#define ILB_FLAGS_SRV_PORTNAME 0x02 /* a port was spec'd by name */
2N/A
2N/A/*
2N/A * server status information
2N/A */
2N/A#define ILB_FLAGS_SRV_ENABLED 0x10
2N/A
2N/A/*
2N/A * macros to determine, and for some cases, set status of server
2N/A */
2N/A#define ILB_IS_SRV_ENABLED(f) \
2N/A ((f & ILB_FLAGS_SRV_ENABLED) == ILB_FLAGS_SRV_ENABLED)
2N/A#define ILB_IS_SRV_DISABLED(f) ((f & ILB_FLAGS_SRV_ENABLED) == 0)
2N/A
2N/A#define ILB_SET_ENABLED(f) (f |= ILB_FLAGS_SRV_ENABLED)
2N/A#define ILB_SET_DISABLED(f) (f &= ~ILB_FLAGS_SRV_ENABLED)
2N/A
2N/A#define MAX_IP_SPREAD 0xff /* largest ip addr. range */
2N/A
2N/A#define ILB_HC_STR_UDP "udp"
2N/A#define ILB_HC_STR_TCP "tcp"
2N/A#define ILB_HC_STR_PING "ping"
2N/A
2N/A#define ILB_NAMESZ 20 /* keep in sync with kernel definition */
2N/A#define ILB_SGNAME_SZ (ILB_NAMESZ - 5) /* 3 numeric digits, "." and "_" */
2N/A
2N/A#define ILB_SRVID_PREFIX '_' /* a valid serverID starts with this */
2N/A
2N/A/* producers of these statuses are libilb and ilbd functions */
2N/Atypedef enum {
2N/A ILB_STATUS_OK = 0,
2N/A ILB_STATUS_INTERNAL, /* an error internal to the library */
2N/A ILB_STATUS_EINVAL, /* invalid argument(s) */
2N/A ILB_STATUS_ENOMEM, /* not enough memory for operation */
2N/A ILB_STATUS_ENOENT, /* no such/no more element(s) */
2N/A ILB_STATUS_SOCKET, /* socket related failure */
2N/A ILB_STATUS_READ, /* read related failure */
2N/A ILB_STATUS_WRITE, /* write related failure */
2N/A ILB_STATUS_TIMER, /* healthcheck timer error */
2N/A ILB_STATUS_INUSE, /* item in use, cannot delete */
2N/A ILB_STATUS_EEXIST, /* scf item exist */
2N/A ILB_STATUS_PERMIT, /* no scf permit */
2N/A ILB_STATUS_CALLBACK, /* scf callback error */
2N/A ILB_STATUS_EWOULDBLOCK, /* operation is blocked - no error string */
2N/A ILB_STATUS_INPROGRESS, /* operation already in progress */
2N/A ILB_STATUS_SEND, /* send related failure */
2N/A ILB_STATUS_GENERIC, /* generic failure - no error string */
2N/A ILB_STATUS_ENOHCINFO, /* missing healthcheck info */
2N/A ILB_STATUS_INVAL_HCTESTTYPE, /* invalid health check */
2N/A ILB_STATUS_INVAL_CMD, /* unknown command */
2N/A ILB_STATUS_DUP_RULE, /* rule name exists */
2N/A ILB_STATUS_ENORULE, /* rule does not exist */
2N/A ILB_STATUS_MISMATCHSG, /* addr family mismatch with sgroup */
2N/A ILB_STATUS_MISMATCHH, /* addr family mismatch with hosts/rule */
2N/A ILB_STATUS_SGUNAVAIL, /* cannot find sgroup in sggroup list */
2N/A ILB_STATUS_SGINUSE, /* server is un use, cannot remove */
2N/A ILB_STATUS_SGEXISTS, /* server exists */
2N/A ILB_STATUS_SGFULL, /* cannot add any more servers */
2N/A ILB_STATUS_SGEMPTY, /* sgroup is empty */
2N/A ILB_STATUS_NAMETOOLONG, /* a name is longer than allowed */
2N/A ILB_STATUS_CFGAUTH, /* config authoriz denied -no error string */
2N/A ILB_STATUS_CFGUPDATE, /* failed to update config! */
2N/A ILB_STATUS_BADSG, /* rules port range size does not match */
2N/A /* that of the servers */
2N/A ILB_STATUS_INVAL_SRVR, /* server port is incompatible with */
2N/A /* rule port */
2N/A ILB_STATUS_INVAL_ENBSRVR, /* server cannot be enabled since it's */
2N/A /* not being used by a rule */
2N/A ILB_STATUS_BADPORT, /* rules port value does not match */
2N/A /* server's */
2N/A ILB_STATUS_SRVUNAVAIL, /* cannot find specified server */
2N/A ILB_STATUS_RULE_NO_HC, /* rule does not have hc info */
2N/A ILB_STATUS_RULE_HC_MISMATCH, /* rule and hc object mismatch */
2N/A ILB_STATUS_HANDLE_CLOSING /* library handle is being closed */
2N/A} ilb_status_t;
2N/A
2N/Atypedef struct {
2N/A int32_t ia_af; /* AF_INET or AF_INET6 */
2N/A union {
2N/A struct in_addr v4; /* network byte order */
2N/A struct in6_addr v6; /* network byte order */
2N/A } _au;
2N/A#define ia_v4 _au.v4
2N/A#define ia_v6 _au.v6
2N/A} ilb_ip_addr_t;
2N/A
2N/A/* Supported load balancing algorithm type */
2N/Atypedef enum {
2N/A ILB_ALG_ROUNDROBIN = 1,
2N/A ILB_ALG_HASH_IP,
2N/A ILB_ALG_HASH_IP_SPORT,
2N/A ILB_ALG_HASH_IP_VIP
2N/A} ilb_algo_t;
2N/A
2N/A/* Supported load balancing method */
2N/Atypedef enum {
2N/A ILB_TOPO_DSR = 1,
2N/A ILB_TOPO_NAT,
2N/A ILB_TOPO_HALF_NAT
2N/A} ilb_topo_t;
2N/A
2N/A#define ILB_INVALID_HANDLE ((void *) NULL)
2N/A
2N/A/*
2N/A * note: pointer to a non-existant struct
2N/A */
2N/Atypedef struct ilb_handle *ilb_handle_t;
2N/A
2N/A/*
2N/A * Health check related information
2N/A */
2N/A
2N/A/* HC state of a server */
2N/Atypedef enum {
2N/A ILB_HCS_UNINIT = -1, /* Uninitialized */
2N/A ILB_HCS_UNREACH = 0, /* Unreachable, ping fails */
2N/A ILB_HCS_ALIVE, /* Probe succeeds */
2N/A ILB_HCS_DEAD, /* Probe fails */
2N/A ILB_HCS_DISABLED /* Server is disabled */
2N/A} ilb_hc_srv_status_t;
2N/A
2N/A/*
2N/A * Struct representing a server in a hc object
2N/A *
2N/A * hcs_rule_name: rule using this server
2N/A * hcs_ID: server ID
2N/A * hcs_hc_name: hc object this server is associated with
2N/A * hcs_IP: IP address of the server
2N/A * hcs_fail_cnt: number of fail hc probe
2N/A * hcs_status: hc status of the server
2N/A * hcs_rtt: (in microsec) smoothed average RTT to the server
2N/A * hcs_lasttime: last time hc test was done (as returned by time(2))
2N/A * hcs_nexttime: next time hc test will be done (as returned by (time(2))
2N/A */
2N/Atypedef struct {
2N/A char hcs_rule_name[ILB_NAMESZ];
2N/A char hcs_ID[ILB_NAMESZ];
2N/A char hcs_hc_name[ILB_NAMESZ];
2N/A struct in6_addr hcs_IP;
2N/A uint32_t hcs_fail_cnt;
2N/A ilb_hc_srv_status_t hcs_status;
2N/A uint32_t hcs_rtt;
2N/A time_t hcs_lasttime;
2N/A time_t hcs_nexttime;
2N/A} ilb_hc_srv_t;
2N/A
2N/A/* Probe flags to be used in r_hcpflag in struct rule data. */
2N/Atypedef enum {
2N/A ILB_HCI_PROBE_ANY = 0, /* Probe any port in the server port range */
2N/A ILB_HCI_PROBE_FIX /* Probe a fixed port */
2N/A} ilb_hcp_flags_t;
2N/A
2N/A/*
2N/A * Struct representing a hc object
2N/A *
2N/A * hci_name: name of the hc object
2N/A * hci_test: hc test to be done, TCP, UDP, or user supplied path name
2N/A * hci_timeout: (in sec) test time out
2N/A * hci_interval: (in sec) test execution interval
2N/A * hci_def_ping: true if default ping is done; false otherwise
2N/A */
2N/Atypedef struct {
2N/A char hci_name[ILB_NAMESZ];
2N/A char hci_test[MAXPATHLEN];
2N/A int32_t hci_timeout;
2N/A int32_t hci_count;
2N/A int32_t hci_interval;
2N/A boolean_t hci_def_ping;
2N/A} ilb_hc_info_t;
2N/A
2N/Atypedef struct rule_data {
2N/A char r_name[ILB_NAMESZ]; /* name of this rule */
2N/A int32_t r_flags; /* opt: ILB_FLAGS_RULE_ENABLED etc. */
2N/A ilb_ip_addr_t r_vip; /* vip, required for rule creation */
2N/A uint16_t r_proto; /* protocol (tcp, udp) */
2N/A in_port_t r_minport; /* port this rule refers to */
2N/A in_port_t r_maxport; /* if != 0, defines port range */
2N/A ilb_algo_t r_algo; /* round-robin, hash-ip, etc. */
2N/A ilb_topo_t r_topo; /* dsr, NAT, etc */
2N/A ilb_ip_addr_t r_nat_src_start; /* required for NAT */
2N/A ilb_ip_addr_t r_nat_src_end; /* required for NAT */
2N/A ilb_ip_addr_t r_stickymask; /* netmask for persistence */
2N/A uint32_t r_conndrain; /* opt: time for conn. draining (s) */
2N/A uint32_t r_nat_timeout; /* opt: timeout for nat connections */
2N/A uint32_t r_sticky_timeout; /* opt: timeout for persistence */
2N/A ilb_hcp_flags_t r_hcpflag; /* HC port flag */
2N/A in_port_t r_hcport; /* opt with HC */
2N/A char r_sgname[ILB_SGNAME_SZ]; /* this rule's server grp. */
2N/A char r_hcname[ILB_NAMESZ]; /* HC name: optional */
2N/A} ilb_rule_data_t;
2N/A
2N/A/* not all fields are valid in all calls where this is used */
2N/Atypedef struct server_data {
2N/A ilb_ip_addr_t sd_addr; /* a server's ip address */
2N/A in_port_t sd_minport; /* port information */
2N/A in_port_t sd_maxport; /* ... if != 0, defines a port range */
2N/A uint32_t sd_flags; /* enabled, dis- */
2N/A char sd_srvID[ILB_NAMESZ]; /* "name" for server */
2N/A /* assigned by system, not user */
2N/A} ilb_server_data_t;
2N/A
2N/A/*
2N/A * Struct to represent a server group.
2N/A *
2N/A * sgd_name: server group name
2N/A * sgd_flags: flags
2N/A * sgd_srvcount: number of servers in the group (not used in sever group
2N/A * creation); filled in when used by call back function for
2N/A * ilb_walk_servergroups().
2N/A */
2N/Atypedef struct sg_data {
2N/A char sgd_name[ILB_SGNAME_SZ];
2N/A int32_t sgd_flags;
2N/A int32_t sgd_srvcount;
2N/A} ilb_sg_data_t;
2N/A
2N/A/*
2N/A * Struct to represent a NAT entry in kernel.
2N/A *
2N/A * nat_proto: transport protocol used in this NAT entry
2N/A *
2N/A * nat_out_global: IP address of client's request
2N/A * nat_out_global_port: port number of client's request
2N/A * nat_in_global: VIP of a rule for the NAT entry
2N/A * nat_in_global_port: port of a rule for the NAT entry
2N/A *
2N/A * nat_out_local: half NAT: IP address of client's request
2N/A * full NAT: NAT'ed IP addres of client' request
2N/A * nat_out_local_port: half NAT: port number of client's request
2N/A * full NAT: NAT'ed port number of client's request
2N/A * nat_in_local: IP address of back end server handling this request
2N/A * nat_in_local_port: port number in back end server handling thi request
2N/A *
2N/A * (*) IPv4 address is represented as IPv4 mapped IPv6 address.
2N/A */
2N/Atypedef struct {
2N/A uint32_t nat_proto;
2N/A
2N/A in6_addr_t nat_in_local;
2N/A in6_addr_t nat_in_global;
2N/A in6_addr_t nat_out_local;
2N/A in6_addr_t nat_out_global;
2N/A
2N/A in_port_t nat_in_local_port;
2N/A in_port_t nat_in_global_port;
2N/A in_port_t nat_out_local_port;
2N/A in_port_t nat_out_global_port;
2N/A} ilb_nat_info_t;
2N/A
2N/A/*
2N/A * Struct to represet a persistent entry in kernel.
2N/A *
2N/A * rule_name: the name of rule for a persistent entry
2N/A * req_addr: the client's IP address (*)
2N/A * srv_addr: the server's IP address (*) handling the client's request
2N/A *
2N/A * (*) IPv4 address is represented as IPv4 mapped IPv6 address.
2N/A */
2N/Atypedef struct {
2N/A char persist_rule_name[ILB_NAMESZ];
2N/A in6_addr_t persist_req_addr;
2N/A in6_addr_t persist_srv_addr;
2N/A} ilb_persist_info_t;
2N/A
2N/A/*
2N/A * Function prototype of the call back function of those walker functions.
2N/A *
2N/A * Note: the storage of the data item parameter (ilb_sg_data_t/
2N/A * ilb_server_data_/ilb_rule_data_t/ilb_hc_info_t/ilb_hc_srv_t) will be
2N/A * freed after calling the call back function. If the call back function
2N/A * needs to keep a copy of the data, it must copy the data content.
2N/A */
2N/Atypedef ilb_status_t (* sg_walkerfunc_t)(ilb_handle_t, ilb_sg_data_t *,
2N/A void *);
2N/Atypedef ilb_status_t (* srv_walkerfunc_t)(ilb_handle_t, ilb_server_data_t *,
2N/A const char *, void *);
2N/Atypedef ilb_status_t (* rule_walkerfunc_t)(ilb_handle_t, ilb_rule_data_t *,
2N/A void *);
2N/Atypedef ilb_status_t (* hc_walkerfunc_t)(ilb_handle_t, ilb_hc_info_t *,
2N/A void *);
2N/Atypedef ilb_status_t (* hc_srvwalkerfunc_t)(ilb_handle_t, ilb_hc_srv_t *,
2N/A void *);
2N/A
2N/A/*
2N/A * ilb_open creates a session handle that every caller into
2N/A * libilb needs to use
2N/A */
2N/Ailb_status_t ilb_open(ilb_handle_t *);
2N/A
2N/A/*
2N/A * relinquish the session handle
2N/A */
2N/Ailb_status_t ilb_close(ilb_handle_t);
2N/A
2N/A/* support and general functions */
2N/Ailb_status_t ilb_reset_config(ilb_handle_t);
2N/Aconst char *ilb_errstr(ilb_status_t);
2N/A
2N/A/* rule-related functions */
2N/Ailb_status_t ilb_create_rule(ilb_handle_t, const ilb_rule_data_t *);
2N/Ailb_status_t ilb_destroy_rule(ilb_handle_t, const char *);
2N/Ailb_status_t ilb_disable_rule(ilb_handle_t, const char *);
2N/Ailb_status_t ilb_enable_rule(ilb_handle_t, const char *);
2N/Ailb_status_t ilb_walk_rules(ilb_handle_t, rule_walkerfunc_t, const char *,
2N/A void *);
2N/A
2N/A/* servergroup functionality */
2N/Ailb_status_t ilb_create_servergroup(ilb_handle_t, const char *);
2N/Ailb_status_t ilb_destroy_servergroup(ilb_handle_t, const char *);
2N/Ailb_status_t ilb_add_server_to_group(ilb_handle_t, const char *,
2N/A ilb_server_data_t *);
2N/Ailb_status_t ilb_rem_server_from_group(ilb_handle_t, const char *,
2N/A ilb_server_data_t *);
2N/Ailb_status_t ilb_walk_servergroups(ilb_handle_t, sg_walkerfunc_t,
2N/A const char *, void *);
2N/Ailb_status_t ilb_walk_servers(ilb_handle_t, srv_walkerfunc_t,
2N/A const char *, void *);
2N/A
2N/A/* functions for individual servers */
2N/Ailb_status_t ilb_enable_server(ilb_handle_t, ilb_server_data_t *, void *);
2N/Ailb_status_t ilb_disable_server(ilb_handle_t, ilb_server_data_t *, void *);
2N/Ailb_status_t ilb_srvID_to_address(ilb_handle_t, ilb_server_data_t *,
2N/A const char *);
2N/Ailb_status_t ilb_address_to_srvID(ilb_handle_t, ilb_server_data_t *,
2N/A const char *);
2N/A
2N/A/* health check-related functions */
2N/Ailb_status_t ilb_create_hc(ilb_handle_t, const ilb_hc_info_t *);
2N/Ailb_status_t ilb_destroy_hc(ilb_handle_t, const char *);
2N/Ailb_status_t ilb_get_hc_info(ilb_handle_t, const char *, ilb_hc_info_t *);
2N/Ailb_status_t ilb_walk_hc(ilb_handle_t, hc_walkerfunc_t, void *);
2N/Ailb_status_t ilb_walk_hc_srvs(ilb_handle_t, hc_srvwalkerfunc_t,
2N/A const char *, void *);
2N/A
2N/A/* To show NAT table entries of ILB */
2N/Ailb_status_t ilb_show_nat(ilb_handle_t, ilb_nat_info_t[], size_t *,
2N/A boolean_t *);
2N/A
2N/A/* To show persistent table entries of ILB */
2N/Ailb_status_t ilb_show_persist(ilb_handle_t, ilb_persist_info_t[], size_t *,
2N/A boolean_t *);
2N/A
2N/A/* PRIVATE */
2N/Aint ilb_cmp_ipaddr(ilb_ip_addr_t *, ilb_ip_addr_t *, int64_t *);
2N/Aint ilb_cmp_in6_addr(struct in6_addr *, struct in6_addr *, int64_t *);
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _LIBILB_H */