1*a7928e1eSrenato /* $OpenBSD: rde.h,v 1.12 2016/09/02 16:46:29 renato Exp $ */ 243509a12Srenato 343509a12Srenato /* 443509a12Srenato * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> 543509a12Srenato * 643509a12Srenato * Permission to use, copy, modify, and distribute this software for any 743509a12Srenato * purpose with or without fee is hereby granted, provided that the above 843509a12Srenato * copyright notice and this permission notice appear in all copies. 943509a12Srenato * 1043509a12Srenato * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1143509a12Srenato * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1243509a12Srenato * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1343509a12Srenato * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1443509a12Srenato * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1543509a12Srenato * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1643509a12Srenato * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1743509a12Srenato */ 1843509a12Srenato 1943509a12Srenato #ifndef _RDE_H_ 2043509a12Srenato #define _RDE_H_ 2143509a12Srenato 2243509a12Srenato #include <sys/queue.h> 238072de9bSrenato #include <sys/tree.h> 248072de9bSrenato 2543509a12Srenato #include <event.h> 2643509a12Srenato 2743509a12Srenato /* just the info RDE needs */ 2843509a12Srenato struct rde_nbr { 2943509a12Srenato RB_ENTRY(rde_nbr) entry; 3043509a12Srenato uint32_t peerid; 3143509a12Srenato uint32_t ifaceid; 3243509a12Srenato union eigrpd_addr addr; 3343509a12Srenato struct eigrp_iface *ei; 3443509a12Srenato struct eigrp *eigrp; 3543509a12Srenato TAILQ_HEAD(,reply_node) rijk; /* outstanding replies */ 36ab786365Srenato 3743509a12Srenato /* 38ab786365Srenato * We have one "self" neighbor for each interface on which EIGRP is 39ab786365Srenato * configured. This way we can inject local routes into the DUAL FSM 40ab786365Srenato * just like any other route received from a remote neighbor. For each 41ab786365Srenato * instance, we also have two additional special neighbors used to 42ab786365Srenato * inject redistributed and summarized routes. 4343509a12Srenato */ 44ab786365Srenato uint8_t flags; 4543509a12Srenato #define F_RDE_NBR_SELF 0x01 464b35c2f5Srenato #define F_RDE_NBR_LOCAL 0x02 474b35c2f5Srenato #define F_RDE_NBR_REDIST 0x04 484b35c2f5Srenato #define F_RDE_NBR_SUMMARY 0x08 49ab786365Srenato }; 50ab786365Srenato RB_PROTOTYPE(rde_nbr_head, rde_nbr, entry, rde_nbr_compare) 5143509a12Srenato 5243509a12Srenato struct reply_node { 5343509a12Srenato TAILQ_ENTRY(reply_node) rn_entry; 5443509a12Srenato TAILQ_ENTRY(reply_node) nbr_entry; 5543509a12Srenato struct event ev_active_timeout; 5643509a12Srenato struct event ev_sia_timeout; 5743509a12Srenato int siaquery_sent; 5843509a12Srenato int siareply_recv; 5943509a12Srenato struct rt_node *rn; 6043509a12Srenato struct rde_nbr *nbr; 6143509a12Srenato }; 6243509a12Srenato 6343509a12Srenato struct eigrp_route { 6443509a12Srenato TAILQ_ENTRY(eigrp_route) entry; 6543509a12Srenato struct rde_nbr *nbr; /* advertising nbr */ 6643509a12Srenato enum route_type type; 6743509a12Srenato union eigrpd_addr nexthop; 6843509a12Srenato uint32_t distance; /* local distance */ 6943509a12Srenato uint32_t rdistance; /* reported distance */ 7043509a12Srenato struct classic_metric metric; /* metric */ 7143509a12Srenato struct classic_emetric emetric; /* external metric */ 7243509a12Srenato uint8_t flags; 7343509a12Srenato }; 7443509a12Srenato #define F_EIGRP_ROUTE_INSTALLED 0x01 7543509a12Srenato #define F_EIGRP_ROUTE_M_CHANGED 0x02 7643509a12Srenato 7743509a12Srenato struct rt_node { 7843509a12Srenato RB_ENTRY(rt_node) entry; 7943509a12Srenato struct eigrp *eigrp; 8043509a12Srenato union eigrpd_addr prefix; 8143509a12Srenato uint8_t prefixlen; 8243509a12Srenato int state; 8343509a12Srenato TAILQ_HEAD(,eigrp_route) routes; 8443509a12Srenato TAILQ_HEAD(,reply_node) rijk; /* outstanding replies */ 8543509a12Srenato 8643509a12Srenato struct { 8743509a12Srenato struct rde_nbr *nbr; 8843509a12Srenato enum route_type type; 8943509a12Srenato uint32_t fdistance; 9043509a12Srenato uint32_t rdistance; 9143509a12Srenato struct classic_metric metric; 9243509a12Srenato struct classic_emetric emetric; 9343509a12Srenato } successor; 9443509a12Srenato }; 95ab786365Srenato RB_PROTOTYPE(rt_tree, rt_node, entry, rt_compare) 9643509a12Srenato 9743509a12Srenato /* DUAL states */ 9843509a12Srenato #define DUAL_STA_PASSIVE 0x0001 9943509a12Srenato #define DUAL_STA_ACTIVE0 0x0002 10043509a12Srenato #define DUAL_STA_ACTIVE1 0x0004 10143509a12Srenato #define DUAL_STA_ACTIVE2 0x0008 10243509a12Srenato #define DUAL_STA_ACTIVE3 0x0010 10343509a12Srenato #define DUAL_STA_ACTIVE_ALL (DUAL_STA_ACTIVE0 | DUAL_STA_ACTIVE1 | \ 10443509a12Srenato DUAL_STA_ACTIVE2 | DUAL_STA_ACTIVE3) 10543509a12Srenato 10643509a12Srenato enum dual_event { 10743509a12Srenato DUAL_EVT_1, 10843509a12Srenato DUAL_EVT_2, 10943509a12Srenato DUAL_EVT_3, 11043509a12Srenato DUAL_EVT_4, 11143509a12Srenato DUAL_EVT_5, 11243509a12Srenato DUAL_EVT_6, 11343509a12Srenato DUAL_EVT_7, 11443509a12Srenato DUAL_EVT_8, 11543509a12Srenato DUAL_EVT_9, 11643509a12Srenato DUAL_EVT_10, 11743509a12Srenato DUAL_EVT_11, 11843509a12Srenato DUAL_EVT_12, 11943509a12Srenato DUAL_EVT_13, 12043509a12Srenato DUAL_EVT_14, 12143509a12Srenato DUAL_EVT_15, 12243509a12Srenato DUAL_EVT_16 12343509a12Srenato }; 12443509a12Srenato 125ab786365Srenato extern struct eigrpd_conf *rdeconf; 126ab786365Srenato extern struct rde_nbr_head rde_nbrs; 127ab786365Srenato 12843509a12Srenato /* rde.c */ 129*a7928e1eSrenato void rde(int, int); 13043509a12Srenato int rde_imsg_compose_parent(int, pid_t, void *, uint16_t); 13143509a12Srenato int rde_imsg_compose_eigrpe(int, uint32_t, pid_t, void *, 13243509a12Srenato uint16_t); 13343509a12Srenato void rde_instance_init(struct eigrp *); 13443509a12Srenato void rde_instance_del(struct eigrp *); 13543509a12Srenato void rde_send_change_kroute(struct rt_node *, struct eigrp_route *); 13643509a12Srenato void rde_send_delete_kroute(struct rt_node *, struct eigrp_route *); 137bc6e1915Srenato void rt_summary_set(struct eigrp *, struct summary_addr *, 138bc6e1915Srenato struct classic_metric *); 13943509a12Srenato 14043509a12Srenato /* rde_dual.c */ 14143509a12Srenato void rt_del(struct rt_node *); 14243509a12Srenato uint32_t eigrp_composite_delay(uint32_t); 14343509a12Srenato uint32_t eigrp_real_delay(uint32_t); 14443509a12Srenato uint32_t eigrp_composite_bandwidth(uint32_t); 14543509a12Srenato uint32_t eigrp_real_bandwidth(uint32_t); 14643509a12Srenato void rinfo_fill_successor(struct rt_node *, struct rinfo *); 147bc6e1915Srenato struct summary_addr *rde_summary_check(struct eigrp_iface *, 148bc6e1915Srenato union eigrpd_addr *, uint8_t); 14943509a12Srenato void rde_flush_queries(void); 15043509a12Srenato void rde_check_update(struct rde_nbr *, struct rinfo *); 15143509a12Srenato void rde_check_query(struct rde_nbr *, struct rinfo *, int); 15243509a12Srenato void rde_check_reply(struct rde_nbr *, struct rinfo *, int); 15343509a12Srenato void rde_check_link_down_rn(struct rde_nbr *, 15443509a12Srenato struct rt_node *, struct eigrp_route *); 15543509a12Srenato void rde_check_link_down_nbr(struct rde_nbr *); 15643509a12Srenato void rde_check_link_down(unsigned int); 15743509a12Srenato void rde_check_link_cost_change(struct rde_nbr *, 1580cefb3adSrenato struct eigrp_iface *); 159ab786365Srenato struct rde_nbr *rde_nbr_find(uint32_t); 160ab786365Srenato struct rde_nbr *rde_nbr_new(uint32_t, struct rde_nbr *); 161ab786365Srenato void rde_nbr_del(struct rde_nbr *, int); 16243509a12Srenato 16343509a12Srenato #endif /* _RDE_H_ */ 164