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 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h> /* in(6)_addr_t */
33 #include <arpa/inet.h>
34 #include <net/if.h> /* LIFNAMSIZ */
36 #include <netinet/vrrp.h>
44 #define VRRP_NAME_MAX 32
45 #define VRRPD_SOCKET "/var/run/vrrpd.socket"
48 * to store the IP addresses
50 typedef struct vrrp_addr
{
52 struct sockaddr_in a4
;
53 struct sockaddr_in6 a6
;
60 * VRRP instance (configuration information).
61 * Passed to vrrp_create(), returned by vrrp_query().
63 typedef struct vrrp_vr_conf_s
{
64 char vvc_name
[VRRP_NAME_MAX
]; /* VRRP router name */
65 char vvc_link
[MAXLINKNAMELEN
]; /* data-link name */
66 vrid_t vvc_vrid
; /* VRID */
67 int vvc_af
; /* IPv4/IPv6 */
69 uint32_t vvc_adver_int
; /* in ms */
70 boolean_t vvc_preempt
;
72 boolean_t vvc_enabled
;
86 * VRRP status structure
87 * Returned by vrrp_query() as part of vrrp_queryinfo_t.
89 typedef struct vrrp_statusinfo_s
{
90 vrrp_state_t vs_state
;
91 vrrp_state_t vs_prev_state
;
92 struct timeval vs_st_time
; /* timestamp of last state trans */
96 * The information obtained from peer's advertisements
97 * Returned by vrrp_query() as part of vrrp_queryinfo_t.
99 typedef struct vrrp_peer_s
{
100 vrrp_addr_t vp_addr
; /* source IP addr of the message */
101 int vp_prio
; /* priority in adv message */
102 struct timeval vp_time
; /* timestamp of the adv message */
103 int vp_adver_int
; /* adv interval in adv message */
107 * Useful timer information, in ms
109 typedef struct vrrp_timeinfo_s
{
110 int vt_since_last_tran
; /* time since last state transition */
111 int vt_since_last_adv
; /* time since last advertisement */
112 int vt_master_down_intv
; /* timer interval for backup to */
113 /* declare master down */
117 * Address information
119 typedef struct vrrp_addrinfo_s
{
120 char va_vnic
[MAXLINKNAMELEN
];
121 vrrp_addr_t va_primary
;
123 vrrp_addr_t va_vips
[1];
127 * VRRP instance configuration and run-time states information
128 * Returned by vrrp_query().
130 typedef struct vrrp_queryinfo
{
131 vrrp_vr_conf_t show_vi
;
132 vrrp_stateinfo_t show_vs
;
134 vrrp_timerinfo_t show_vt
;
135 vrrp_addrinfo_t show_va
;
139 * flags sent with the VRRP_CMD_MODIFY command. Used in vrrp_setprop().
141 #define VRRP_CONF_PRIORITY 0x01
142 #define VRRP_CONF_INTERVAL 0x02
143 #define VRRP_CONF_PREEMPT 0x04
144 #define VRRP_CONF_ACCEPT 0x08
151 VRRP_EINVAL
, /* invalid parameter */
152 VRRP_EINVALVRNAME
, /* invalid router name */
153 VRRP_ENOMEM
, /* no memory */
154 VRRP_ENOVIRT
, /* no virtual IP addresses */
155 VRRP_ENOPRIM
, /* no primary IP address */
156 VRRP_ENOVNIC
, /* no vnic created */
157 VRRP_ENOLINK
, /* the link does not exist */
158 VRRP_EINVALLINK
, /* invalid link */
159 VRRP_EINVALADDR
, /* invalid IP address */
160 VRRP_EINVALAF
, /* invalid IP address familty */
161 VRRP_EDB
, /* configuration error */
162 VRRP_EPERM
, /* permission denied */
163 VRRP_EBADSTATE
, /* VRRP router in bad state */
164 VRRP_EVREXIST
, /* <vrid, intf, af> three-tuple exists */
165 VRRP_EINSTEXIST
, /* router name already exists */
166 VRRP_EEXIST
, /* already exists */
167 VRRP_ENOTFOUND
, /* vrrp router not found */
168 VRRP_ETOOSMALL
, /* too small space */
169 VRRP_EAGAIN
, /* Try again */
170 VRRP_EALREADY
, /* already */
171 VRRP_EDLADM
, /* dladm failure */
172 VRRP_EIPADM
, /* ipadm failure */
173 VRRP_ESYS
, /* system error */
174 VRRP_ENOSVC
/* VRRP service not enabled */
178 * Internal commands used between vrrpadm and vrrpd.
191 #define addr_len(af) ((af) == AF_INET ? sizeof (in_addr_t): sizeof (in6_addr_t))
193 #define VRRPADDR_UNSPECIFIED(af, addr) \
194 (((af) == AF_INET6 && IN6_IS_ADDR_UNSPECIFIED( \
195 &(addr)->in6.sin6_addr)) || ((af) == AF_INET && \
196 ((addr)->in4.sin_addr.s_addr == INADDR_ANY)))
198 #define VRRPADDR2STR(af, addr, abuf, size, append) { \
199 char ap[INET6_ADDRSTRLEN]; \
201 if (VRRPADDR_UNSPECIFIED(af, addr)) { \
202 (void) strlcpy(ap, "--", INET6_ADDRSTRLEN); \
203 } else if ((af) == AF_INET) { \
204 (void) inet_ntop((af), &(addr)->in4.sin_addr, ap, \
207 (void) inet_ntop((af), &(addr)->in6.sin6_addr, ap, \
211 (void) strlcat(abuf, ap, size); \
213 (void) strlcpy(abuf, ap, size); \
216 typedef struct vrrp_cmd_create_s
{
218 vrrp_vr_conf_t vcc_conf
;
221 typedef struct vrrp_ret_create_s
{
225 typedef struct vrrp_cmd_delete_s
{
227 char vcd_name
[VRRP_NAME_MAX
];
230 typedef struct vrrp_ret_delete_s
{
234 typedef struct vrrp_cmd_enable_s
{
236 char vcs_name
[VRRP_NAME_MAX
];
239 typedef struct vrrp_ret_enable_s
{
243 typedef struct vrrp_cmd_disable_s
{
245 char vcx_name
[VRRP_NAME_MAX
];
246 } vrrp_cmd_disable_t
;
248 typedef struct vrrp_ret_disable_s
{
250 } vrrp_ret_disable_t
;
252 typedef struct vrrp_cmd_modify_s
{
255 vrrp_vr_conf_t vcm_conf
;
258 typedef struct vrrp_ret_modify_s
{
262 typedef struct vrrp_cmd_list_s
{
265 char vcl_ifname
[LIFNAMSIZ
];
269 typedef struct vrrp_ret_list_s
{
273 * When vrl_cnt is non-zero, the return structure will be followed
274 * by the list of router names, separated by '\0'. Its size will
275 * be vrl_cnt * VRRP_NAME_MAX.
279 typedef struct vrrp_cmd_query_s
{
281 char vcq_name
[VRRP_NAME_MAX
];
284 typedef struct vrrp_ret_query_s
{
286 vrrp_queryinfo_t vrq_qinfo
;
290 * Union of all VRRP commands
292 typedef union vrrp_cmd_s
{
294 vrrp_cmd_create_t vc_cmd_create
;
295 vrrp_cmd_delete_t vc_cmd_delete
;
296 vrrp_cmd_enable_t vc_cmd_enable
;
297 vrrp_cmd_disable_t vc_cmd_disable
;
298 vrrp_cmd_modify_t vc_cmd_modify
;
299 vrrp_cmd_list_t vc_cmd_list
;
303 * Union of all VRRP replies of the VRRP commands
305 typedef union vrrp_ret_s
{
307 vrrp_ret_create_t vr_ret_create
;
308 vrrp_ret_delete_t vr_ret_delete
;
309 vrrp_ret_enable_t vr_ret_enable
;
310 vrrp_ret_disable_t vr_ret_disable
;
311 vrrp_ret_modify_t vr_ret_modify
;
312 vrrp_ret_list_t vr_ret_list
;
313 vrrp_ret_query_t vr_ret_query
;
320 dladm_handle_t vh_dh
;
322 typedef struct vrrp_handle
*vrrp_handle_t
;
324 const char *vrrp_err2str(vrrp_err_t
);
325 const char *vrrp_state2str(vrrp_state_t
);
327 vrrp_err_t
vrrp_open(vrrp_handle_t
*);
328 void vrrp_close(vrrp_handle_t
);
330 boolean_t
vrrp_valid_name(const char *);
332 vrrp_err_t
vrrp_create(vrrp_handle_t
, vrrp_vr_conf_t
*);
333 vrrp_err_t
vrrp_delete(vrrp_handle_t
, const char *);
335 vrrp_err_t
vrrp_enable(vrrp_handle_t
, const char *);
336 vrrp_err_t
vrrp_disable(vrrp_handle_t
, const char *);
338 vrrp_err_t
vrrp_modify(vrrp_handle_t
, vrrp_vr_conf_t
*, uint32_t);
340 vrrp_err_t
vrrp_query(vrrp_handle_t
, const char *, vrrp_queryinfo_t
**);
342 vrrp_err_t
vrrp_list(vrrp_handle_t
, vrid_t
, const char *, int,
345 boolean_t
vrrp_is_vrrp_vnic(vrrp_handle_t
, datalink_id_t
,
346 datalink_id_t
*, uint16_t *, vrid_t
*, int *);
348 vrrp_err_t
vrrp_get_vnicname(vrrp_handle_t
, vrid_t
, int, char *,
349 datalink_id_t
*, uint16_t *, char *, size_t);
355 #endif /* _LIBVRRPADM_H */