1 /* $OpenBSD: rde.h,v 1.12 2016/09/02 16:46:29 renato Exp $ */ 2 3 /* 4 * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _RDE_H_ 20 #define _RDE_H_ 21 22 #include <sys/queue.h> 23 #include <sys/tree.h> 24 25 #include <event.h> 26 27 /* just the info RDE needs */ 28 struct rde_nbr { 29 RB_ENTRY(rde_nbr) entry; 30 uint32_t peerid; 31 uint32_t ifaceid; 32 union eigrpd_addr addr; 33 struct eigrp_iface *ei; 34 struct eigrp *eigrp; 35 TAILQ_HEAD(,reply_node) rijk; /* outstanding replies */ 36 37 /* 38 * We have one "self" neighbor for each interface on which EIGRP is 39 * configured. This way we can inject local routes into the DUAL FSM 40 * just like any other route received from a remote neighbor. For each 41 * instance, we also have two additional special neighbors used to 42 * inject redistributed and summarized routes. 43 */ 44 uint8_t flags; 45 #define F_RDE_NBR_SELF 0x01 46 #define F_RDE_NBR_LOCAL 0x02 47 #define F_RDE_NBR_REDIST 0x04 48 #define F_RDE_NBR_SUMMARY 0x08 49 }; 50 RB_PROTOTYPE(rde_nbr_head, rde_nbr, entry, rde_nbr_compare) 51 52 struct reply_node { 53 TAILQ_ENTRY(reply_node) rn_entry; 54 TAILQ_ENTRY(reply_node) nbr_entry; 55 struct event ev_active_timeout; 56 struct event ev_sia_timeout; 57 int siaquery_sent; 58 int siareply_recv; 59 struct rt_node *rn; 60 struct rde_nbr *nbr; 61 }; 62 63 struct eigrp_route { 64 TAILQ_ENTRY(eigrp_route) entry; 65 struct rde_nbr *nbr; /* advertising nbr */ 66 enum route_type type; 67 union eigrpd_addr nexthop; 68 uint32_t distance; /* local distance */ 69 uint32_t rdistance; /* reported distance */ 70 struct classic_metric metric; /* metric */ 71 struct classic_emetric emetric; /* external metric */ 72 uint8_t flags; 73 }; 74 #define F_EIGRP_ROUTE_INSTALLED 0x01 75 #define F_EIGRP_ROUTE_M_CHANGED 0x02 76 77 struct rt_node { 78 RB_ENTRY(rt_node) entry; 79 struct eigrp *eigrp; 80 union eigrpd_addr prefix; 81 uint8_t prefixlen; 82 int state; 83 TAILQ_HEAD(,eigrp_route) routes; 84 TAILQ_HEAD(,reply_node) rijk; /* outstanding replies */ 85 86 struct { 87 struct rde_nbr *nbr; 88 enum route_type type; 89 uint32_t fdistance; 90 uint32_t rdistance; 91 struct classic_metric metric; 92 struct classic_emetric emetric; 93 } successor; 94 }; 95 RB_PROTOTYPE(rt_tree, rt_node, entry, rt_compare) 96 97 /* DUAL states */ 98 #define DUAL_STA_PASSIVE 0x0001 99 #define DUAL_STA_ACTIVE0 0x0002 100 #define DUAL_STA_ACTIVE1 0x0004 101 #define DUAL_STA_ACTIVE2 0x0008 102 #define DUAL_STA_ACTIVE3 0x0010 103 #define DUAL_STA_ACTIVE_ALL (DUAL_STA_ACTIVE0 | DUAL_STA_ACTIVE1 | \ 104 DUAL_STA_ACTIVE2 | DUAL_STA_ACTIVE3) 105 106 enum dual_event { 107 DUAL_EVT_1, 108 DUAL_EVT_2, 109 DUAL_EVT_3, 110 DUAL_EVT_4, 111 DUAL_EVT_5, 112 DUAL_EVT_6, 113 DUAL_EVT_7, 114 DUAL_EVT_8, 115 DUAL_EVT_9, 116 DUAL_EVT_10, 117 DUAL_EVT_11, 118 DUAL_EVT_12, 119 DUAL_EVT_13, 120 DUAL_EVT_14, 121 DUAL_EVT_15, 122 DUAL_EVT_16 123 }; 124 125 extern struct eigrpd_conf *rdeconf; 126 extern struct rde_nbr_head rde_nbrs; 127 128 /* rde.c */ 129 void rde(int, int); 130 int rde_imsg_compose_parent(int, pid_t, void *, uint16_t); 131 int rde_imsg_compose_eigrpe(int, uint32_t, pid_t, void *, 132 uint16_t); 133 void rde_instance_init(struct eigrp *); 134 void rde_instance_del(struct eigrp *); 135 void rde_send_change_kroute(struct rt_node *, struct eigrp_route *); 136 void rde_send_delete_kroute(struct rt_node *, struct eigrp_route *); 137 void rt_summary_set(struct eigrp *, struct summary_addr *, 138 struct classic_metric *); 139 140 /* rde_dual.c */ 141 void rt_del(struct rt_node *); 142 uint32_t eigrp_composite_delay(uint32_t); 143 uint32_t eigrp_real_delay(uint32_t); 144 uint32_t eigrp_composite_bandwidth(uint32_t); 145 uint32_t eigrp_real_bandwidth(uint32_t); 146 void rinfo_fill_successor(struct rt_node *, struct rinfo *); 147 struct summary_addr *rde_summary_check(struct eigrp_iface *, 148 union eigrpd_addr *, uint8_t); 149 void rde_flush_queries(void); 150 void rde_check_update(struct rde_nbr *, struct rinfo *); 151 void rde_check_query(struct rde_nbr *, struct rinfo *, int); 152 void rde_check_reply(struct rde_nbr *, struct rinfo *, int); 153 void rde_check_link_down_rn(struct rde_nbr *, 154 struct rt_node *, struct eigrp_route *); 155 void rde_check_link_down_nbr(struct rde_nbr *); 156 void rde_check_link_down(unsigned int); 157 void rde_check_link_cost_change(struct rde_nbr *, 158 struct eigrp_iface *); 159 struct rde_nbr *rde_nbr_find(uint32_t); 160 struct rde_nbr *rde_nbr_new(uint32_t, struct rde_nbr *); 161 void rde_nbr_del(struct rde_nbr *, int); 162 163 #endif /* _RDE_H_ */ 164