1 /* $OpenBSD: rde.h,v 1.40 2019/11/19 09:55:55 remi Exp $ */ 2 3 /* 4 * Copyright (c) 2004, 2005 Esben Norby <norby@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/types.h> 23 #include <sys/time.h> 24 #include <sys/tree.h> 25 #include <sys/queue.h> 26 #include <event.h> 27 #include <limits.h> 28 29 struct v_nexthop { 30 TAILQ_ENTRY(v_nexthop) entry; 31 struct vertex *prev; 32 struct in_addr nexthop; 33 }; 34 35 TAILQ_HEAD(v_nexthead, v_nexthop); 36 37 struct vertex { 38 RB_ENTRY(vertex) entry; 39 TAILQ_ENTRY(vertex) cand; 40 struct v_nexthead nexthop; 41 struct event ev; 42 struct area *area; 43 struct lsa *lsa; 44 struct lsa_tree *lsa_tree; 45 time_t changed; 46 time_t stamp; 47 u_int32_t cost; 48 u_int32_t peerid; /* neighbor unique imsg ID */ 49 u_int32_t ls_id; 50 u_int32_t adv_rtr; 51 u_int8_t type; 52 u_int8_t flooded; 53 u_int8_t deleted; 54 u_int8_t self; 55 }; 56 57 struct rde_req_entry { 58 TAILQ_ENTRY(rde_req_entry) entry; 59 u_int32_t ls_id; 60 u_int32_t adv_rtr; 61 u_int8_t type; 62 }; 63 64 /* just the info RDE needs */ 65 struct rde_nbr { 66 LIST_ENTRY(rde_nbr) entry, hash; 67 struct in_addr id; 68 struct in_addr area_id; 69 struct in_addr addr; 70 TAILQ_HEAD(, rde_req_entry) req_list; 71 struct area *area; 72 struct iface *iface; 73 u_int32_t peerid; /* unique ID in DB */ 74 int state; 75 unsigned int ifindex; 76 u_int8_t self; 77 u_int8_t capa_options; 78 }; 79 80 struct rt_nexthop { 81 TAILQ_ENTRY(rt_nexthop) entry; 82 struct in_addr nexthop; 83 struct in_addr adv_rtr; 84 time_t uptime; 85 u_int8_t connected; 86 u_int8_t invalid; 87 }; 88 89 struct rt_node { 90 RB_ENTRY(rt_node) entry; 91 TAILQ_HEAD(,rt_nexthop) nexthop; 92 struct in_addr prefix; 93 struct in_addr area; 94 u_int32_t cost; 95 u_int32_t cost2; 96 u_int32_t ext_tag; 97 enum path_type p_type; 98 enum dst_type d_type; 99 u_int8_t flags; 100 u_int8_t prefixlen; 101 u_int8_t invalid; 102 }; 103 104 struct abr_rtr { 105 struct in_addr addr; 106 struct in_addr abr_id; 107 struct in_addr dst_ip; 108 struct in_addr area; 109 u_int16_t metric; 110 }; 111 112 extern struct lsa_tree asext_tree; 113 114 /* rde.c */ 115 pid_t rde(struct ospfd_conf *, int [2], int [2], int [2]); 116 int rde_imsg_compose_ospfe(int, u_int32_t, pid_t, void *, 117 u_int16_t); 118 u_int32_t rde_router_id(void); 119 struct area *rde_backbone_area(void); 120 void rde_send_change_kroute(struct rt_node *); 121 void rde_send_delete_kroute(struct rt_node *); 122 void rde_nbr_iface_del(struct iface *); 123 void rde_nbr_del(struct rde_nbr *); 124 int rde_nbr_loading(struct area *); 125 struct rde_nbr *rde_nbr_self(struct area *); 126 void rde_summary_update(struct rt_node *, struct area *); 127 struct lsa *orig_sum_lsa(struct rt_node *, struct area *, u_int8_t, int); 128 129 /* rde_lsdb.c */ 130 void lsa_init(struct lsa_tree *); 131 int lsa_compare(struct vertex *, struct vertex *); 132 void vertex_free(struct vertex *); 133 void vertex_nexthop_clear(struct vertex *); 134 void vertex_nexthop_add(struct vertex *, struct vertex *, 135 u_int32_t); 136 int lsa_newer(struct lsa_hdr *, struct lsa_hdr *); 137 int lsa_check(struct rde_nbr *, struct lsa *, u_int16_t); 138 int lsa_self(struct rde_nbr *, struct lsa *, struct vertex *); 139 int lsa_add(struct rde_nbr *, struct lsa *); 140 void lsa_del(struct rde_nbr *, struct lsa_hdr *); 141 void lsa_age(struct vertex *); 142 struct vertex *lsa_find(struct iface *, u_int8_t, u_int32_t, u_int32_t); 143 struct vertex *lsa_find_area(struct area *, u_int8_t, u_int32_t, u_int32_t); 144 struct vertex *lsa_find_net(struct area *area, u_int32_t); 145 u_int16_t lsa_num_links(struct vertex *); 146 void lsa_snap(struct rde_nbr *); 147 void lsa_dump(struct lsa_tree *, int, pid_t); 148 void lsa_merge(struct rde_nbr *, struct lsa *, struct vertex *); 149 void lsa_remove_invalid_sums(struct area *); 150 void lsa_generate_stub_sums(struct area *); 151 152 /* rde_spf.c */ 153 void spf_calc(struct area *); 154 void rt_calc(struct vertex *, struct area *, struct ospfd_conf *); 155 void asext_calc(struct vertex *); 156 void spf_tree_clr(struct area *); 157 158 void cand_list_init(void); 159 void cand_list_add(struct vertex *); 160 struct vertex *cand_list_pop(void); 161 int cand_list_present(struct vertex *); 162 void cand_list_clr(void); 163 164 void spf_timer(int, short, void *); 165 void start_spf_timer(void); 166 void stop_spf_timer(struct ospfd_conf *); 167 void start_spf_holdtimer(struct ospfd_conf *); 168 169 void rt_init(void); 170 int rt_compare(struct rt_node *, struct rt_node *); 171 struct rt_node *rt_find(in_addr_t, u_int8_t, enum dst_type); 172 int rt_insert(struct rt_node *); 173 int rt_remove(struct rt_node *); 174 void rt_clear(void); 175 void rt_dump(struct in_addr, pid_t, u_int8_t); 176 struct rt_node *rt_lookup(enum dst_type, in_addr_t); 177 178 RB_PROTOTYPE(lsa_tree, vertex, entry, lsa_compare) 179 180 #endif /* _RDE_H_ */ 181