]> git.proxmox.com Git - mirror_frr.git/blobdiff - vrrpd/vrrp.h
Merge pull request #5793 from ton31337/fix/formatting_show_bgp_summary_failed
[mirror_frr.git] / vrrpd / vrrp.h
index eabb23fe75a32ee5336a3bcc9156b7205bb4dff2..502d7b82b6137f8dead0a4f7606635a7e9d9dd44 100644 (file)
 #include <zebra.h>
 #include <netinet/ip.h>
 
+#include "lib/memory.h"
 #include "lib/hash.h"
 #include "lib/hook.h"
 #include "lib/if.h"
 #include "lib/linklist.h"
+#include "lib/northbound.h"
 #include "lib/privs.h"
 #include "lib/stream.h"
 #include "lib/thread.h"
 #include "lib/vty.h"
 
 /* Global definitions */
-#define VRRP_DEFAULT_ADVINT 100
-#define VRRP_DEFAULT_PRIORITY 100
 #define VRRP_RADV_INT 16
 #define VRRP_PRIO_MASTER 255
 #define VRRP_MCASTV4_GROUP_STR "224.0.0.18"
 #define VRRP_MCASTV6_GROUP 0xff020000000000000000000000000012
 #define IPPROTO_VRRP 112
 
-#define VRRP_LOGPFX_VRID "[VRID: %u] "
+#define VRRP_LOGPFX_VRID "[VRID %u] "
+#define VRRP_LOGPFX_FAM "[%s] "
+
+/* Default defaults */
+#define VRRP_XPATH_FULL "/frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group"
+#define VRRP_XPATH "./frr-vrrpd:vrrp/vrrp-group"
+#define VRRP_DEFAULT_PRIORITY 100
+#define VRRP_DEFAULT_ADVINT 100
+#define VRRP_DEFAULT_PREEMPT true
+#define VRRP_DEFAULT_ACCEPT true
+#define VRRP_DEFAULT_SHUTDOWN false
+
+/* User compatibility constant */
+#define CS2MS 10
+
+DECLARE_MGROUP(VRRPD)
+
+/* Northbound */
+extern const struct frr_yang_module_info frr_vrrpd_info;
+
+/* Configured defaults */
+struct vrrp_defaults {
+       uint8_t version;
+       uint8_t priority;
+       uint16_t advertisement_interval;
+       bool preempt_mode;
+       bool accept_mode;
+       bool shutdown;
+};
+
+extern struct vrrp_defaults vd;
 
 /* threadmaster */
 extern struct thread_master *master;
@@ -104,6 +134,27 @@ struct vrrp_router {
         */
        struct list *addrs;
 
+       /*
+        * This flag says whether we are waiting on an interface up
+        * notification from Zebra before we send an ADVERTISEMENT.
+        */
+       bool advert_pending;
+
+       /*
+        * If this is an IPv4 VRRP router, this flag says whether we are
+        * waiting on an interface up notification from Zebra before we send
+        * gratuitous ARP packets for all our addresses. Should never be true
+        * if family == AF_INET6.
+        */
+       bool garp_pending;
+       /*
+        * If this is an IPv6 VRRP router, this flag says whether we are
+        * waiting on an interface up notification from Zebra before we send
+        * Unsolicited Neighbor Advertisement packets for all our addresses.
+        * Should never be true if family == AF_INET.
+        */
+       bool ndisc_pending;
+
        /*
         * Effective priority
         *    => vr->priority if we are Backup
@@ -141,6 +192,18 @@ struct vrrp_router {
                int state;
        } fsm;
 
+       struct {
+               /* Total number of advertisements sent and received */
+               uint32_t adver_tx_cnt;
+               uint32_t adver_rx_cnt;
+               /* Total number of gratuitous ARPs sent */
+               uint32_t garp_tx_cnt;
+               /* Total number of unsolicited Neighbor Advertisements sent */
+               uint32_t una_tx_cnt;
+               /* Total number of state transitions */
+               uint32_t trans_cnt;
+       } stats;
+
        struct thread *t_master_down_timer;
        struct thread *t_adver_timer;
        struct thread *t_read;
@@ -168,6 +231,9 @@ struct vrrp_vrouter {
        /* Whether this instance was automatically configured */
        bool autoconf;
 
+       /* Whether this VRRP router is in administrative shutdown */
+       bool shutdown;
+
        /* Interface */
        struct interface *ifp;
 
@@ -209,6 +275,14 @@ struct vrrp_vrouter {
  */
 void vrrp_init(void);
 
+/*
+ * Destroy all VRRP instances and gracefully shutdown.
+ *
+ * For instances in Master state, VRRP advertisements with 0 priority will be
+ * sent if possible to notify Backup routers that we are going away.
+ */
+void vrrp_fini(void);
+
 
 /* Creation and destruction ------------------------------------------------ */
 
@@ -234,6 +308,14 @@ void vrrp_vrouter_destroy(struct vrrp_vrouter *vr);
 
 /* Configuration controllers ----------------------------------------------- */
 
+/*
+ * Check if a Virtual Router ought to be started, and if so, start it.
+ *
+ * vr
+ *    Virtual Router to checkstart
+ */
+void vrrp_check_start(struct vrrp_vrouter *vr);
+
 /*
  * Change the configured priority of a VRRP Virtual Router.
  *
@@ -265,7 +347,7 @@ void vrrp_set_advertisement_interval(struct vrrp_vrouter *vr,
 /*
  * Add an IPvX address to a VRRP Virtual Router.
  *
- * r
+ * vr
  *    Virtual Router to add IPvx address to
  *
  * ip
@@ -279,7 +361,7 @@ void vrrp_set_advertisement_interval(struct vrrp_vrouter *vr,
  *    -1 on error
  *     0 otherwise
  */
-int vrrp_add_ip(struct vrrp_router *r, struct ipaddr *ip, bool activate);
+int vrrp_add_ip(struct vrrp_vrouter *vr, struct ipaddr *ip);
 
 /*
  * Add an IPv4 address to a VRRP Virtual Router.
@@ -298,7 +380,7 @@ int vrrp_add_ip(struct vrrp_router *r, struct ipaddr *ip, bool activate);
  *    -1 on error
  *     0 otherwise
  */
-int vrrp_add_ipv4(struct vrrp_vrouter *vr, struct in_addr v4, bool activate);
+int vrrp_add_ipv4(struct vrrp_vrouter *vr, struct in_addr v4);
 
 /*
  * Add an IPv6 address to a VRRP Virtual Router.
@@ -317,12 +399,12 @@ int vrrp_add_ipv4(struct vrrp_vrouter *vr, struct in_addr v4, bool activate);
  *    -1 on error
  *     0 otherwise
  */
-int vrrp_add_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6, bool activate);
+int vrrp_add_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6);
 
 /*
  * Remove an IP address from a VRRP Virtual Router.
  *
- * r
+ * vr
  *    Virtual Router to remove IP address from
  *
  * ip
@@ -338,7 +420,7 @@ int vrrp_add_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6, bool activate);
  *    -1 on error
  *     0 otherwise
  */
-int vrrp_del_ip(struct vrrp_router *r, struct ipaddr *ip, bool deactivate);
+int vrrp_del_ip(struct vrrp_vrouter *vr, struct ipaddr *ip);
 
 /*
  * Remove an IPv4 address from a VRRP Virtual Router.
@@ -359,7 +441,7 @@ int vrrp_del_ip(struct vrrp_router *r, struct ipaddr *ip, bool deactivate);
  *    -1 on error
  *     0 otherwise
  */
-int vrrp_del_ipv4(struct vrrp_vrouter *vr, struct in_addr v4, bool deactivate);
+int vrrp_del_ipv4(struct vrrp_vrouter *vr, struct in_addr v4);
 
 /*
  * Remove an IPv6 address from a VRRP Virtual Router.
@@ -380,7 +462,7 @@ int vrrp_del_ipv4(struct vrrp_vrouter *vr, struct in_addr v4, bool deactivate);
  *    -1 on error
  *     0 otherwise
  */
-int vrrp_del_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6, bool deactivate);
+int vrrp_del_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6);
 
 /* State machine ----------------------------------------------------------- */
 
@@ -390,8 +472,7 @@ int vrrp_del_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6, bool deactivate);
 #define VRRP_EVENT_STARTUP 0
 #define VRRP_EVENT_SHUTDOWN 1
 
-extern const char *vrrp_state_names[3];
-extern const char *vrrp_event_names[2];
+extern const char *const vrrp_state_names[3];
 
 /*
  * This hook called whenever the state of a Virtual Router changes, after the
@@ -400,7 +481,7 @@ extern const char *vrrp_event_names[2];
  * Use this if you need to react to state changes to perform non-critical
  * tasks. Critical tasks should go in the internal state change handlers.
  */
-DECLARE_HOOK(vrrp_change_state_hook, (struct vrrp_router * r, int to), (r, to));
+DECLARE_HOOK(vrrp_change_state_hook, (struct vrrp_router *r, int to), (r, to));
 
 /*
  * Trigger a VRRP event on a given Virtual Router..
@@ -457,119 +538,17 @@ void vrrp_autoconfig_on(int version);
  */
 void vrrp_autoconfig_off(void);
 
-/*
- * Callback to notify autoconfig of interface add.
- *
- * If the interface is a VRRP-compatible device, and there is no existing VRRP
- * router running on it, one is created. All addresses on the interface are
- * added to the router.
- *
- * ifp
- *    Interface to operate on
- *
- * Returns:
- *    -1 on failure
- *     0 otherwise
- */
-int vrrp_autoconfig_if_add(struct interface *ifp);
+/* Interface Tracking ------------------------------------------------------ */
 
-/*
- * Callback to notify autoconfig of interface delete.
- *
- * If the interface is a VRRP-compatible device, and a VRRP router is running
- * on it, and that VRRP router was automatically configured, it will be
- * deleted. If that was the last router for the corresponding VRID (i.e., if
- * this interface was a v4 VRRP interface and no v6 router is configured for
- * the same VRID) then the entire virtual router is deleted.
- *
- * ifp
- *    Interface to operate on
- *
- * Returns:
- *    -1 on failure
- *     0 otherwise
- */
-int vrrp_autoconfig_if_del(struct interface *ifp);
-
-/*
- * Callback to notify autoconfig of interface up.
- *
- * Roughly equivalent to vrrp_autoconfig_if_add, except that addresses are
- * refreshed if an autoconfigured virtual router already exists.
- *
- * ifp
- *    Interface to operate on
- *
- * Returns:
- *    -1 on failure
- *     0 otherwise
- */
-int vrrp_autoconfig_if_up(struct interface *ifp);
-
-/*
- * Callback to notify autoconfig of interface down.
- *
- * Does nothing. An interface down event is accompanied by address deletion
- * events for all the addresses on the interface; if an autoconfigured VRRP
- * router exists on this interface, then it will have all its addresses deleted
- * and end up in Initialize.
- *
- * ifp
- *    Interface to operate on
- *
- * Returns:
- *    -1 on failure
- *     0 otherwise
- */
-int vrrp_autoconfig_if_down(struct interface *ifp);
-
-/*
- * Callback to notify autoconfig of a new interface address.
- *
- * If a VRRP router exists on this interface, its address list is updated to
- * match the new address list. If no addresses remain, a Shutdown event is
- * issued to the VRRP router.
- *
- * ifp
- *    Interface to operate on
- *
- * Returns:
- *    -1 on failure
- *     0 otherwise
- *
- */
-int vrrp_autoconfig_if_address_add(struct interface *ifp);
-
-/*
- * Callback to notify autoconfig of a removed interface address.
- *
- * If a VRRP router exists on this interface, its address list is updated to
- * match the new address list. If no addresses remain, a Shutdown event is
- * issued to the VRRP router.
- *
- * ifp
- *    Interface to operate on
- *
- * Returns:
- *    -1 on failure
- *     0 otherwise
- *
- */
-int vrrp_autoconfig_if_address_del(struct interface *ifp);
+void vrrp_if_add(struct interface *ifp);
+void vrrp_if_del(struct interface *ifp);
+void vrrp_if_up(struct interface *ifp);
+void vrrp_if_down(struct interface *ifp);
+void vrrp_if_address_add(struct interface *ifp);
+void vrrp_if_address_del(struct interface *ifp);
 
 /* Other ------------------------------------------------------------------- */
 
-/*
- * Write interface block-level configuration to vty.
- *
- * vty
- *    vty to write config to
- *
- * Returns:
- *    # of lines written
- */
-int vrrp_config_write_interface(struct vty *vty);
-
 /*
  * Write global level configuration to vty.
  *
@@ -584,6 +563,6 @@ int vrrp_config_write_global(struct vty *vty);
 /*
  * Find VRRP Virtual Router by Virtual Router ID
  */
-struct vrrp_vrouter *vrrp_lookup(struct interface *ifp, uint8_t vrid);
+struct vrrp_vrouter *vrrp_lookup(const struct interface *ifp, uint8_t vrid);
 
 #endif /* __VRRP_H__ */