1 /* $OpenBSD: rde.h,v 1.38 2011/05/09 12:24:41 claudio 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 TAILQ_HEAD(, rde_req_entry) req_list; 70 struct area *area; 71 struct iface *iface; 72 u_int32_t peerid; /* unique ID in DB */ 73 int state; 74 unsigned int ifindex; 75 u_int8_t self; 76 u_int8_t capa_options; 77 }; 78 79 struct rt_nexthop { 80 TAILQ_ENTRY(rt_nexthop) entry; 81 struct in_addr nexthop; 82 struct in_addr adv_rtr; 83 time_t uptime; 84 u_int8_t connected; 85 u_int8_t invalid; 86 }; 87 88 struct rt_node { 89 RB_ENTRY(rt_node) entry; 90 TAILQ_HEAD(,rt_nexthop) nexthop; 91 struct in_addr prefix; 92 struct in_addr area; 93 u_int32_t cost; 94 u_int32_t cost2; 95 u_int32_t ext_tag; 96 enum path_type p_type; 97 enum dst_type d_type; 98 u_int8_t flags; 99 u_int8_t prefixlen; 100 u_int8_t invalid; 101 }; 102 103 struct abr_rtr { 104 struct in_addr addr; 105 struct in_addr abr_id; 106 struct in_addr dst_ip; 107 struct in_addr area; 108 u_int16_t metric; 109 }; 110 111 extern struct lsa_tree asext_tree; 112 113 /* rde.c */ 114 pid_t rde(struct ospfd_conf *, int [2], int [2], int [2]); 115 int rde_imsg_compose_ospfe(int, u_int32_t, pid_t, void *, 116 u_int16_t); 117 u_int32_t rde_router_id(void); 118 struct area *rde_backbone_area(void); 119 void rde_send_change_kroute(struct rt_node *); 120 void rde_send_delete_kroute(struct rt_node *); 121 void rde_nbr_del(struct rde_nbr *); 122 int rde_nbr_loading(struct area *); 123 struct rde_nbr *rde_nbr_self(struct area *); 124 void rde_summary_update(struct rt_node *, struct area *); 125 struct lsa *orig_sum_lsa(struct rt_node *, struct area *, u_int8_t, int); 126 127 /* rde_lsdb.c */ 128 void lsa_init(struct lsa_tree *); 129 int lsa_compare(struct vertex *, struct vertex *); 130 void vertex_free(struct vertex *); 131 void vertex_nexthop_clear(struct vertex *); 132 void vertex_nexthop_add(struct vertex *, struct vertex *, 133 u_int32_t); 134 int lsa_newer(struct lsa_hdr *, struct lsa_hdr *); 135 int lsa_check(struct rde_nbr *, struct lsa *, u_int16_t); 136 int lsa_self(struct rde_nbr *, struct lsa *, struct vertex *); 137 int lsa_add(struct rde_nbr *, struct lsa *); 138 void lsa_del(struct rde_nbr *, struct lsa_hdr *); 139 void lsa_age(struct vertex *); 140 struct vertex *lsa_find(struct iface *, u_int8_t, u_int32_t, u_int32_t); 141 struct vertex *lsa_find_area(struct area *, u_int8_t, u_int32_t, u_int32_t); 142 struct vertex *lsa_find_net(struct area *area, u_int32_t); 143 u_int16_t lsa_num_links(struct vertex *); 144 void lsa_snap(struct rde_nbr *); 145 void lsa_dump(struct lsa_tree *, int, pid_t); 146 void lsa_merge(struct rde_nbr *, struct lsa *, struct vertex *); 147 void lsa_remove_invalid_sums(struct area *); 148 void lsa_generate_stub_sums(struct area *); 149 150 /* rde_spf.c */ 151 void spf_calc(struct area *); 152 void rt_calc(struct vertex *, struct area *, struct ospfd_conf *); 153 void asext_calc(struct vertex *); 154 void spf_tree_clr(struct area *); 155 156 void cand_list_init(void); 157 void cand_list_add(struct vertex *); 158 struct vertex *cand_list_pop(void); 159 int cand_list_present(struct vertex *); 160 void cand_list_clr(void); 161 162 void spf_timer(int, short, void *); 163 void start_spf_timer(void); 164 void stop_spf_timer(struct ospfd_conf *); 165 void start_spf_holdtimer(struct ospfd_conf *); 166 167 void rt_init(void); 168 int rt_compare(struct rt_node *, struct rt_node *); 169 struct rt_node *rt_find(in_addr_t, u_int8_t, enum dst_type); 170 int rt_insert(struct rt_node *); 171 int rt_remove(struct rt_node *); 172 void rt_clear(void); 173 void rt_dump(struct in_addr, pid_t, u_int8_t); 174 struct rt_node *rt_lookup(enum dst_type, in_addr_t); 175 176 RB_PROTOTYPE(lsa_tree, vertex, entry, lsa_compare) 177 178 #endif /* _RDE_H_ */ 179