1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * CDDL HEADER START
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou *
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * The contents of this file are subject to the terms of the
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Common Development and Distribution License (the "License").
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * You may not use this file except in compliance with the License.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou *
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * or http://www.opensolaris.org/os/licensing.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * See the License for the specific language governing permissions
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * and limitations under the License.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou *
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * When distributing Covered Code, include this CDDL HEADER in each
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * If applicable, add the following below this CDDL HEADER, with the
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * fields enclosed by brackets "[]" replaced with your own identifying
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * information: Portions Copyright [yyyy] [name of copyright owner]
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou *
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * CDDL HEADER END
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Use is subject to license terms.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#ifndef _VRRPD_IMPL_H
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define _VRRPD_IMPL_H
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#include <sys/queue.h>
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#include <libinetutil.h>
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#include <libvrrpadm.h>
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#ifdef __cplusplus
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhouextern "C" {
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#endif
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Internal data structs to store VRRP instance configuration information
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * and run-time state information.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhoutypedef useconds_t vrrp_timeout_t;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhoutypedef struct vrrp_vr_s {
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_vr_conf_t vvr_conf;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou uint32_t vvr_master_adver_int;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou char vvr_vnic[MAXLINKNAMELEN];
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou struct vrrp_intf_s *vvr_pif;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou struct vrrp_intf_s *vvr_vif;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou /*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Timer reused in master/backup state:
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Master: The Advertisement_Interval (Adver_Timer)
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Backup: The Master_Down_Intervel (Master_Down_timer)
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_timeout_t vvr_timeout;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou iu_timer_id_t vvr_timer_id;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou /*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Peer information, got from the last adv message received
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_peer_t vvr_peer;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvr_peer_addr vvr_peer.vp_addr
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvr_peer_time vvr_peer.vp_time
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvr_peer_prio vvr_peer.vp_prio
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvr_peer_adver_int vvr_peer.vp_adver_int
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_stateinfo_t vvr_sinfo;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvr_state vvr_sinfo.vs_state
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvr_prev_state vvr_sinfo.vs_prev_state
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvr_st_time vvr_sinfo.vs_st_time
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou /*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Record the reason why the virtual router stays at the INIT
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * state, for the diagnose purpose.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_err_t vvr_err;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou TAILQ_ENTRY(vrrp_vr_s) vvr_next;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou} vrrp_vr_t;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/* IP address/interface cache state flags */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhoutypedef enum {
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou NODE_STATE_NONE = 0,
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou NODE_STATE_STALE = 1,
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou NODE_STATE_NEW = 2
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou} node_state_t;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * The ifindex is get by the SIOCGLIFINDEX ioctl, easy to make it part of
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * vrrp_ip_t instead of vrrp_intf_t
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhoutypedef struct vrrp_ip_s {
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou char vip_lifname[LIFNAMSIZ];
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_addr_t vip_addr;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou uint64_t vip_flags;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou node_state_t vip_state;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou TAILQ_ENTRY(vrrp_ip_s) vip_next;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou} vrrp_ip_t;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Used for primary interfaces
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhoutypedef struct vrrp_primary_ifinfo {
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou uint32_t vpii_nvr; /* numbers of virtual routers */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_ip_t *vpii_pip; /* primary IP address */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou iu_event_id_t vpii_eid; /* event id of RX socket */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou /* non-zero on the primary if */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou} vrrp_primary_ifinfo_t;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Used for virtual interfaces
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhoutypedef struct vrrp_virtual_ifinfo {
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou /*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * the state of the VRRP router, used to determine the up/down
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * state of the virtual IP addresses
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_state_t vvii_state;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou} vrrp_virtual_ifinfo_t;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * VRRP interface structure
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou *
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * An interface is either the primary interface which owns the primary IP
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * address or a VNIC interface which owns the virtual IP addresses.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * As the primary interface, it can be shared by several VRRP routers.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhoutypedef struct vrrp_intf_s {
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou char vvi_ifname[LIFNAMSIZ];
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou int vvi_af; /* address family */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou node_state_t vvi_state;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou uint32_t vvi_ifindex; /* interface index */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou TAILQ_HEAD(, vrrp_ip_s) vvi_iplist; /* IP adddress list */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou TAILQ_ENTRY(vrrp_intf_s) vvi_next;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou /*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * Socket fd.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * - physical interfaces: used to receive the VRRP packet, and shared
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * by all virtual routers on this physical interface.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * - vnic interfaces: used to send the VRRP packet.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou int vvi_sockfd;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_primary_ifinfo_t pifinfo; /* Primary interface info */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou vrrp_virtual_ifinfo_t vifinfo; /* VNIC interface info */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvi_nvr pifinfo.vpii_nvr
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvi_pip pifinfo.vpii_pip
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvi_eid pifinfo.vpii_eid
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define vvi_vr_state vifinfo.vvii_state
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou} vrrp_intf_t;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define IS_PRIMARY_INTF(intf) \
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou (((intf)->vvi_sockfd >= 0) && ((intf)->vvi_eid != -1))
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define IS_VIRTUAL_INTF(intf) \
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou (((intf)->vvi_sockfd >= 0) && ((intf)->vvi_eid == -1))
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define VRRP_ERR 0 /* error message */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define VRRP_WARNING 1
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define VRRP_NOTICE 2
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define VRRP_INFO 3
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define VRRP_DBG0 4 /* debug message, only function calls */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define VRRP_DBG1 5 /* detailed debug message */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou/*
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * The primary IP address must be brought up; further, in the case of IPv6,
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou * the link-local IP address is used as the primary IP address.
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#define QUALIFY_PRIMARY_ADDR(intf, ip) \
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou (((ip)->vip_flags & IFF_UP) && ((intf)->vvi_af != AF_INET6 || \
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou IN6_IS_ADDR_LINKLOCAL(&(ip)->vip_addr.in6.sin6_addr)))
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#ifdef __cplusplus
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou}
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#endif
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou#endif /* _VRRPD_IMPL_H */