4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _LIBILB_IMPL_H
28 #define _LIBILB_IMPL_H
34 #include <sys/types.h>
35 #include <sys/socket.h>
37 #include <netinet/in.h>
46 #define max(a, b) ((a) > (b) ? (a) : (b))
49 /* The UNIX domain socket path to talk to ilbd. */
50 #define SOCKET_PATH "/var/run/daemon/ilb_sock"
52 /* The max message size for communicating with ilbd */
53 #define ILBD_MSG_SIZE 102400
56 * moral equivalent of ntohl for IPv6 addresses, MSB and LSB (64 bit each),
57 * assign to uint64_t variables
59 #define INV6_N2H_MSB64(addr) \
60 (((uint64_t)ntohl((addr)->_S6_un._S6_u32[0]) << 32) + \
61 (ntohl((addr)->_S6_un._S6_u32[1])))
63 #define INV6_N2H_LSB64(addr) \
64 (((uint64_t)ntohl((addr)->_S6_un._S6_u32[2]) << 32) + \
65 (ntohl((addr)->_S6_un._S6_u32[3])))
68 * moral equiv. of htonl of MSB and LSB 64-bit portions to an IPv6 address
70 #define INV6_H2N_MSB64(addr, msb) \
71 (addr)->_S6_un._S6_u32[0] = htonl((msb) >> 32); \
72 (addr)->_S6_un._S6_u32[1] = htonl((msb) & 0xffffffff)
74 #define INV6_H2N_LSB64(addr, lsb) \
75 (addr)->_S6_un._S6_u32[2] = htonl((lsb) >> 32); \
76 (addr)->_S6_un._S6_u32[3] = htonl((lsb) & 0xffffffff)
78 #define IP_COPY_CLI_2_IMPL(_e, _i) \
79 bzero(_i, sizeof (*(_i))); \
80 if ((_e)->ia_af == AF_INET6) \
81 (void) memcpy((_i), &(_e)->ia_v6, sizeof (*(_i))); \
83 IN6_INADDR_TO_V4MAPPED(&(_e)->ia_v4, (_i))
85 #define IP_COPY_IMPL_2_CLI(_i, _e) \
87 bzero(_e, sizeof (*(_e))); \
88 if (IN6_IS_ADDR_V4MAPPED(_i)) { \
89 (_e)->ia_af = AF_INET; \
90 IN6_V4MAPPED_TO_INADDR((_i), &(_e)->ia_v4); \
92 (_e)->ia_af = AF_INET6; \
93 (void) memcpy(&(_e)->ia_v6, (_i), \
94 sizeof ((_e)->ia_v6)); \
99 #define GET_AF(_a) IN6_IS_ADDR_V4MAPPED(_a)?AF_INET:AF_INET6
100 #define IS_AF_VALID(_af) (_af == AF_INET || _af == AF_INET6)
104 /* servergroup commands */
105 ILBD_CREATE_SERVERGROUP
,
106 ILBD_ADD_SERVER_TO_GROUP
,
107 ILBD_REM_SERVER_FROM_GROUP
,
110 ILBD_DESTROY_SERVERGROUP
,
111 ILBD_RETRIEVE_SG_NAMES
, /* names of all SGs registered */
112 ILBD_RETRIEVE_SG_HOSTS
, /* all hosts for a given SG (hndl) */
113 ILBD_SRV_ADDR2ID
, /* fill in serverID for given address */
114 ILBD_SRV_ID2ADDR
, /* fill in address from given serverID */
120 ILBD_RETRIEVE_RULE_NAMES
,
128 ILBD_RETRIEVE_HC_NAMES
,
130 ILBD_SHOW_NAT
, /* list the NAT table */
131 ILBD_SHOW_PERSIST
, /* list the sticky table */
133 ILBD_CMD_OK
, /* Requested operation succeeds. */
134 ILBD_CMD_ERROR
/* Rquested operation fails. */
137 typedef struct sg_srv
{
138 int32_t sgs_flags
; /* enabled, dis- */
139 struct in6_addr sgs_addr
;
142 int32_t sgs_id
; /* numerical part of srvID */
143 char sgs_srvID
[ILB_NAMESZ
]; /* "name" given to server */
146 typedef struct sg_info
{
148 char sg_name
[ILB_SGNAME_SZ
];
150 ilb_sg_srv_t sg_servers
[];
153 typedef char ilbd_name_t
[ILB_NAMESZ
];
155 typedef struct ilbd_namelist
{
158 ilbd_name_t ilbl_name
[];
161 #define ILBL_NAME_OFFSET (offsetof(ilbd_namelist_t, ilbl_name))
163 typedef struct rule_info
{
165 char rl_name
[ILB_NAMESZ
];
166 struct in6_addr rl_vip
;
168 uint16_t rl_ipversion
;
173 struct in6_addr rl_nat_src_start
;
174 struct in6_addr rl_nat_src_end
;
175 struct in6_addr rl_stickymask
;
176 uint32_t rl_conndrain
;
177 uint32_t rl_nat_timeout
;
178 uint32_t rl_sticky_timeout
;
180 ilb_hcp_flags_t rl_hcpflag
;
181 char rl_sgname
[ILB_SGNAME_SZ
];
182 char rl_hcname
[ILB_NAMESZ
];
186 * Struct to represent show NAT request and reply.
188 * sn_num: (request) indicates the number of entries wanted;
189 * (reply) the number of entries returned;
190 * sn_data: NAT/persist able entries (is uint32_t aligned).
198 * Struct to represent the set of servers associated with a hc object.
200 * rs_num_srvs: number of servers in this struct.
201 * rs_srvs: array of servers.
204 uint32_t rs_num_srvs
;
205 ilb_hc_srv_t rs_srvs
[];
208 typedef struct ilb_handle_impl
{
216 ilb_status_t h_error
; /* ... that caused invalidation */
220 * Communication flags used in ilb_comm_t.
222 * ILB_COMM_END: end of communication
224 #define ILB_COMM_END 0x1
227 * The message structure used to communicate with ilbd.
229 * ic_cmd: the message type.
230 * ic_flags: communication flags
231 * ic_data: message data (is uint32_t aligned).
239 ilb_status_t
i_check_ip_range(ilb_ip_addr_t
*, ilb_ip_addr_t
*);
240 ilb_status_t
i_ilb_do_comm(ilb_handle_t
, ilb_comm_t
*, size_t, ilb_comm_t
*,
242 void i_ilb_close_comm(ilb_handle_t
);
243 struct in6_addr
i_next_ip_addr(struct in6_addr
*, int);
245 ilb_status_t
i_ilb_retrieve_rule_names(ilb_handle_t
, ilb_comm_t
**,
247 ilb_comm_t
*i_ilb_alloc_req(ilbd_cmd_t
, size_t *);
253 #endif /* _LIBILB_IMPL_H */