ospfe.h revision 1.12
1/* $OpenBSD: ospfe.h,v 1.12 2009/01/27 21:58:28 stsp 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 _OSPFE_H_ 20#define _OSPFE_H_ 21 22#define max(x,y) ((x) > (y) ? (x) : (y)) 23 24#include <sys/types.h> 25#include <sys/socket.h> 26#include <netinet/in.h> 27#include <netinet/in_systm.h> 28#include <netinet/ip.h> 29 30TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; 31 32struct lsa_entry { 33 TAILQ_ENTRY(lsa_entry) entry; 34 union { 35 struct lsa_hdr *lu_lsa; 36 struct lsa_ref *lu_ref; 37 } le_data; 38 unsigned short le_when; 39 unsigned short le_oneshot; 40}; 41#define le_lsa le_data.lu_lsa 42#define le_ref le_data.lu_ref 43 44struct lsa_ref { 45 LIST_ENTRY(lsa_ref) entry; 46 struct lsa_hdr hdr; 47 void *data; 48 time_t stamp; 49 int refcnt; 50 u_int16_t len; 51}; 52 53struct nbr_stats { 54 u_int32_t sta_chng; 55}; 56 57struct nbr { 58 LIST_ENTRY(nbr) entry, hash; 59 struct event inactivity_timer; 60 struct event db_tx_timer; 61 struct event lsreq_tx_timer; 62 struct event ls_retrans_timer; 63 struct event adj_timer; 64 65 struct nbr_stats stats; 66 67 struct lsa_head ls_retrans_list; 68 struct lsa_head db_sum_list; 69 struct lsa_head ls_req_list; 70 71 struct in6_addr addr; /* ip6 address */ 72 struct in_addr id; /* router id */ 73 struct in_addr dr; /* designated router */ 74 struct in_addr bdr; /* backup designated router */ 75 76 struct iface *iface; 77 struct lsa_entry *ls_req; 78 struct lsa_entry *dd_end; 79 80 u_int32_t iface_id; /* id of neighbor's iface */ 81 u_int32_t dd_seq_num; 82 u_int32_t dd_pending; 83 u_int32_t peerid; /* unique ID in DB */ 84 u_int32_t ls_req_cnt; 85 u_int32_t ls_ret_cnt; 86 u_int32_t options; 87 u_int32_t last_rx_options; 88 89 time_t uptime; 90 int state; 91 u_int8_t priority; 92 u_int8_t last_rx_bits; 93 u_int8_t dd_master; 94 u_int8_t dd_more; 95}; 96 97/* database.c */ 98int send_db_description(struct nbr *); 99void recv_db_description(struct nbr *, char *, u_int16_t); 100void db_sum_list_add(struct nbr *, struct lsa_hdr *); 101int db_sum_list_del(struct nbr *, struct lsa_hdr *); 102void db_sum_list_clr(struct nbr *); 103void db_tx_timer(int, short, void *); 104void start_db_tx_timer(struct nbr *); 105void stop_db_tx_timer(struct nbr *); 106 107/* hello.c */ 108int send_hello(struct iface *); 109void recv_hello(struct iface *, struct in6_addr *, u_int32_t, 110 char *, u_int16_t); 111 112/* ospfe.c */ 113pid_t ospfe(struct ospfd_conf *, int[2], int[2], int[2]); 114void ospfe_dispatch_main(int, short, void *); 115void ospfe_dispatch_rde(int, short, void *); 116int ospfe_imsg_compose_parent(int, pid_t, void *, u_int16_t); 117int ospfe_imsg_compose_rde(int, u_int32_t, pid_t, void *, 118 u_int16_t); 119u_int32_t ospfe_router_id(void); 120void ospfe_fib_update(int); 121void ospfe_iface_ctl(struct ctl_conn *, unsigned int); 122void ospfe_nbr_ctl(struct ctl_conn *); 123void orig_rtr_lsa(struct iface *); 124void orig_net_lsa(struct iface *); 125void orig_link_lsa(struct iface *); 126void ospfe_demote_area(struct area *, int); 127void ospfe_demote_iface(struct iface *, int); 128 129/* interface.c */ 130int if_fsm(struct iface *, enum iface_event); 131 132void if_del(struct iface *); 133void if_start(struct ospfd_conf *, struct iface *); 134 135int if_act_start(struct iface *); 136int if_act_elect(struct iface *); 137int if_act_reset(struct iface *); 138 139struct ctl_iface *if_to_ctl(struct iface *); 140 141int if_join_group(struct iface *, struct in6_addr *); 142int if_leave_group(struct iface *, struct in6_addr *); 143int if_set_mcast(struct iface *); 144void if_set_recvbuf(int); 145int if_set_mcast_loop(int); 146int if_set_ipv6_pktinfo(int, int); 147int if_set_ipv6_checksum(int); 148 149/* lsack.c */ 150int delay_lsa_ack(struct iface *, struct lsa_hdr *); 151int send_ls_ack(struct iface *, struct in6_addr, void *, size_t); 152void recv_ls_ack(struct nbr *, char *, u_int16_t); 153int lsa_hdr_check(struct nbr *, struct lsa_hdr *); 154void ls_ack_list_add(struct iface *, struct lsa_hdr *); 155void ls_ack_list_free(struct iface *, struct lsa_entry *); 156void ls_ack_list_clr(struct iface *); 157int ls_ack_list_empty(struct iface *); 158void ls_ack_tx_timer(int, short, void *); 159void start_ls_ack_tx_timer(struct iface *); 160void stop_ls_ack_tx_timer(struct iface *); 161 162/* lsreq.c */ 163int send_ls_req(struct nbr *); 164void recv_ls_req(struct nbr *, char *, u_int16_t); 165void ls_req_list_add(struct nbr *, struct lsa_hdr *); 166int ls_req_list_del(struct nbr *, struct lsa_hdr *); 167struct lsa_entry *ls_req_list_get(struct nbr *, struct lsa_hdr *); 168void ls_req_list_free(struct nbr *, struct lsa_entry *); 169void ls_req_list_clr(struct nbr *); 170int ls_req_list_empty(struct nbr *); 171void ls_req_tx_timer(int, short, void *); 172void start_ls_req_tx_timer(struct nbr *); 173void stop_ls_req_tx_timer(struct nbr *); 174 175/* lsupdate.c */ 176int lsa_flood(struct iface *, struct nbr *, struct lsa_hdr *, 177 void *); 178void recv_ls_update(struct nbr *, char *, u_int16_t); 179 180void ls_retrans_list_add(struct nbr *, struct lsa_hdr *, 181 unsigned short, unsigned short); 182int ls_retrans_list_del(struct nbr *, struct lsa_hdr *); 183struct lsa_entry *ls_retrans_list_get(struct nbr *, struct lsa_hdr *); 184void ls_retrans_list_free(struct nbr *, struct lsa_entry *); 185void ls_retrans_list_clr(struct nbr *); 186void ls_retrans_timer(int, short, void *); 187 188void lsa_cache_init(u_int32_t); 189struct lsa_ref *lsa_cache_add(void *, u_int16_t); 190struct lsa_ref *lsa_cache_get(struct lsa_hdr *); 191void lsa_cache_put(struct lsa_ref *, struct nbr *); 192 193/* neighbor.c */ 194void nbr_init(u_int32_t); 195struct nbr *nbr_new(u_int32_t, struct iface *, u_int32_t, int); 196void nbr_del(struct nbr *); 197 198struct nbr *nbr_find_id(struct iface *, u_int32_t); 199struct nbr *nbr_find_peerid(u_int32_t); 200 201int nbr_fsm(struct nbr *, enum nbr_event); 202 203void nbr_itimer(int, short, void *); 204void nbr_start_itimer(struct nbr *); 205void nbr_stop_itimer(struct nbr *); 206void nbr_reset_itimer(struct nbr *); 207 208void nbr_adj_timer(int, short, void *); 209void nbr_start_adj_timer(struct nbr *); 210 211int nbr_act_reset_itimer(struct nbr *); 212int nbr_act_start_itimer(struct nbr *); 213int nbr_act_eval(struct nbr *); 214int nbr_act_snapshot(struct nbr *); 215int nbr_act_exchange_done(struct nbr *); 216int nbr_act_adj_ok(struct nbr *); 217int nbr_act_restart_dd(struct nbr *); 218int nbr_act_delete(struct nbr *); 219int nbr_act_clear_lists(struct nbr *); 220int nbr_act_hello_check(struct nbr *); 221 222struct ctl_nbr *nbr_to_ctl(struct nbr *); 223 224struct lsa_hdr *lsa_hdr_new(void); 225 226/* packet.c */ 227int gen_ospf_hdr(struct buf *, struct iface *, u_int8_t); 228int upd_ospf_hdr(struct buf *, struct iface *); 229int send_packet(struct iface *, void *, size_t, struct in6_addr *); 230void recv_packet(int, short, void *); 231 232char *pkt_ptr; /* packet buffer */ 233 234#endif /* _OSPFE_H_ */ 235