1 /* $OpenBSD: rde.h,v 1.25 2020/02/17 08:12:22 denis 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 in6_addr nexthop; 33 unsigned int ifindex; 34 }; 35 36 TAILQ_HEAD(v_nexthead, v_nexthop); 37 38 struct vertex { 39 RB_ENTRY(vertex) entry; 40 TAILQ_ENTRY(vertex) cand; 41 struct v_nexthead nexthop; 42 struct event ev; 43 struct area *area; 44 struct lsa *lsa; 45 struct lsa_tree *lsa_tree; 46 time_t changed; 47 time_t stamp; 48 u_int32_t cost; 49 u_int32_t peerid; /* neighbor unique imsg ID */ 50 u_int32_t ls_id; 51 u_int32_t adv_rtr; 52 u_int16_t type; 53 u_int8_t flooded; 54 u_int8_t deleted; 55 u_int8_t self; 56 }; 57 58 struct rde_req_entry { 59 TAILQ_ENTRY(rde_req_entry) entry; 60 u_int32_t ls_id; 61 u_int32_t adv_rtr; 62 u_int8_t type; 63 }; 64 65 /* just the info RDE needs */ 66 struct rde_nbr { 67 LIST_ENTRY(rde_nbr) entry, hash; 68 struct in6_addr addr; 69 struct in_addr id; 70 struct in_addr area_id; 71 TAILQ_HEAD(, rde_req_entry) req_list; 72 struct area *area; 73 struct iface *iface; 74 u_int32_t peerid; /* unique ID in DB */ 75 unsigned int ifindex; 76 u_int32_t iface_id; /* id of neighbor's 77 iface */ 78 int state; 79 int self; 80 }; 81 82 /* expanded and host-byte-order version of a lsa_prefix */ 83 struct rt_prefix { 84 struct in6_addr prefix; 85 u_int16_t metric; 86 u_int8_t prefixlen; 87 u_int8_t options; 88 }; 89 90 struct rt_nexthop { 91 TAILQ_ENTRY(rt_nexthop) entry; 92 struct in6_addr nexthop; 93 struct in_addr adv_rtr; 94 unsigned int ifindex; 95 time_t uptime; 96 u_int8_t connected; 97 u_int8_t invalid; 98 }; 99 100 struct rt_node { 101 RB_ENTRY(rt_node) entry; 102 TAILQ_HEAD(,rt_nexthop) nexthop; 103 struct in6_addr prefix; 104 struct in_addr area; 105 u_int32_t cost; 106 u_int32_t cost2; 107 u_int32_t ext_tag; 108 enum path_type p_type; 109 enum dst_type d_type; 110 u_int8_t flags; 111 u_int8_t prefixlen; 112 u_int8_t invalid; 113 }; 114 115 struct abr_rtr { 116 struct in6_addr addr; 117 struct in_addr abr_id; 118 struct in6_addr dst_ip; 119 struct in_addr area; 120 u_int16_t metric; 121 }; 122 123 extern struct lsa_tree asext_tree; 124 125 /* rde.c */ 126 pid_t rde(struct ospfd_conf *, int [2], int [2], int [2]); 127 int rde_imsg_compose_ospfe(int, u_int32_t, pid_t, void *, 128 u_int16_t); 129 u_int32_t rde_router_id(void); 130 void rde_send_change_kroute(struct rt_node *); 131 void rde_send_delete_kroute(struct rt_node *); 132 void rde_nbr_del(struct rde_nbr *); 133 int rde_nbr_loading(struct area *); 134 struct rde_nbr *rde_nbr_self(struct area *); 135 struct rde_nbr *rde_nbr_find(u_int32_t); 136 void rde_summary_update(struct rt_node *, struct area *); 137 void orig_intra_area_prefix_lsas(struct area *); 138 139 /* rde_lsdb.c */ 140 void lsa_init(struct lsa_tree *); 141 int lsa_compare(struct vertex *, struct vertex *); 142 void vertex_free(struct vertex *); 143 void vertex_nexthop_clear(struct vertex *); 144 void vertex_nexthop_add(struct vertex *, struct vertex *, 145 const struct in6_addr *, u_int32_t); 146 int lsa_newer(struct lsa_hdr *, struct lsa_hdr *); 147 int lsa_check(struct rde_nbr *, struct lsa *, u_int16_t); 148 int lsa_self(struct rde_nbr *, struct lsa *, struct vertex *); 149 int lsa_add(struct rde_nbr *, struct lsa *); 150 void lsa_del(struct rde_nbr *, struct lsa_hdr *); 151 void lsa_age(struct vertex *); 152 struct vertex *lsa_find(struct iface *, u_int16_t, u_int32_t, u_int32_t); 153 struct vertex *lsa_find_rtr(struct area *, u_int32_t); 154 struct vertex *lsa_find_rtr_frag(struct area *, u_int32_t, unsigned int); 155 struct vertex *lsa_find_tree(struct lsa_tree *, u_int16_t, u_int32_t, 156 u_int32_t); 157 u_int32_t lsa_find_lsid(struct lsa_tree *, 158 int (*)(struct lsa *, struct lsa *), struct lsa *); 159 u_int16_t lsa_num_links(struct vertex *); 160 void lsa_snap(struct rde_nbr *); 161 void lsa_dump(struct lsa_tree *, int, pid_t); 162 void lsa_merge(struct rde_nbr *, struct lsa *, struct vertex *); 163 void lsa_remove_invalid_sums(struct area *); 164 165 /* rde_spf.c */ 166 void spf_calc(struct area *); 167 void rt_calc(struct vertex *, struct area *, struct ospfd_conf *); 168 void asext_calc(struct vertex *); 169 void spf_tree_clr(struct area *); 170 171 void cand_list_init(void); 172 void cand_list_add(struct vertex *); 173 struct vertex *cand_list_pop(void); 174 int cand_list_present(struct vertex *); 175 void cand_list_clr(void); 176 177 void spf_timer(int, short, void *); 178 void start_spf_timer(void); 179 void stop_spf_timer(struct ospfd_conf *); 180 void start_spf_holdtimer(struct ospfd_conf *); 181 182 void rt_init(void); 183 int rt_compare(struct rt_node *, struct rt_node *); 184 struct rt_node *rt_find(struct in6_addr *, u_int8_t, enum dst_type); 185 int rt_insert(struct rt_node *); 186 int rt_remove(struct rt_node *); 187 void rt_clear(void); 188 void rt_dump(struct in_addr, pid_t, u_int8_t); 189 190 struct lsa_rtr_link *get_rtr_link(struct vertex *, unsigned int); 191 struct lsa_net_link *get_net_link(struct vertex *, unsigned int); 192 193 RB_PROTOTYPE(lsa_tree, vertex, entry, lsa_compare) 194 195 #endif /* _RDE_H_ */ 196