1 /* $OpenBSD: ripe.h,v 1.10 2010/05/26 13:56:08 nicm Exp $ */ 2 3 /* 4 * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> 5 * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef _RIPE_H_ 21 #define _RIPE_H_ 22 23 #include <sys/types.h> 24 #include <sys/socket.h> 25 #include <netinet/in.h> 26 #include <netinet/in_systm.h> 27 #include <netinet/ip.h> 28 29 TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; 30 u_int8_t *pkt_ptr; 31 32 /* neighbor events */ 33 enum nbr_event { 34 NBR_EVT_RESPONSE_RCVD, 35 NBR_EVT_REQUEST_RCVD, 36 NBR_EVT_RESPONSE_SENT, 37 NBR_EVT_TIMEOUT, 38 NBR_EVT_KILL_NBR, 39 NBR_EVT_NOTHING 40 }; 41 42 /* neighbor actions */ 43 enum nbr_action { 44 NBR_ACT_STRT_TIMER, 45 NBR_ACT_RST_TIMER, 46 NBR_ACT_DEL, 47 NBR_ACT_NOTHING 48 }; 49 50 struct nbr_failed { 51 struct event timeout_timer; 52 LIST_ENTRY(nbr_failed) entry; 53 struct in_addr addr; 54 u_int32_t auth_seq_num; 55 }; 56 57 struct nbr { 58 LIST_ENTRY(nbr) entry, hash; 59 struct event timeout_timer; 60 struct in_addr addr; 61 struct in_addr id; 62 63 struct packet_head rq_list; 64 struct packet_head rp_list; 65 66 struct iface *iface; 67 68 u_int32_t peerid; /* unique ID in DB */ 69 u_int32_t auth_seq_num; 70 u_int16_t port; 71 time_t uptime; 72 int state; 73 int flags; 74 }; 75 76 /* packet.c */ 77 int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); 78 void recv_packet(int, short, void *); 79 int gen_rip_hdr(struct ibuf *, u_int8_t); 80 81 /* interface.c */ 82 void if_init(struct ripd_conf *, struct iface *); 83 int if_fsm(struct iface *, enum iface_event); 84 int if_set_mcast(struct iface *); 85 int if_set_mcast_ttl(int, u_int8_t); 86 int if_set_mcast_loop(int); 87 int if_set_opt(int); 88 int if_set_tos(int, int); 89 void if_set_recvbuf(int); 90 struct iface *if_new(struct kif *); 91 void if_del(struct iface *); 92 const char *if_event_name(int); 93 const char *if_action_name(int); 94 int if_join_group(struct iface *, struct in_addr *); 95 int if_leave_group(struct iface *, struct in_addr *); 96 struct ctl_iface *if_to_ctl(struct iface *); 97 98 /* message.c */ 99 void recv_request(struct iface *, struct nbr *, u_int8_t *, u_int16_t); 100 void recv_response(struct iface *, struct nbr *, u_int8_t *, u_int16_t); 101 void add_entry(struct packet_head *, struct rip_route *); 102 void clear_list(struct packet_head *); 103 int send_triggered_update(struct iface *, struct rip_route *); 104 int send_request(struct packet_head *, struct iface *, struct nbr *); 105 int send_response(struct packet_head *, struct iface *, struct nbr *); 106 int start_report_timer(void); 107 void report_timer(int, short, void *); 108 109 /* ripe.c */ 110 pid_t ripe(struct ripd_conf *, int [2], int [2], int [2]); 111 int ripe_imsg_compose_parent(int, pid_t, void *, u_int16_t); 112 int ripe_imsg_compose_rde(int, u_int32_t, pid_t, void *, 113 u_int16_t); 114 void ripe_dispatch_main(int, short, void *); 115 void ripe_dispatch_rde(int, short, void *); 116 void ripe_iface_ctl(struct ctl_conn *, unsigned int); 117 void ripe_nbr_ctl(struct ctl_conn *); 118 void ripe_demote_iface(struct iface *, int); 119 120 /* auth.c */ 121 int auth_validate(u_int8_t **, u_int16_t *, struct iface *, struct nbr *, 122 struct nbr_failed *, u_int32_t *); 123 int auth_gen(struct ibuf *, struct iface *); 124 int auth_add_trailer(struct ibuf *, struct iface *); 125 int md_list_add(struct auth_md_head *, u_int8_t, char *); 126 void md_list_copy(struct auth_md_head *, struct auth_md_head *); 127 void md_list_clr(struct auth_md_head *); 128 129 /* neighbor.c */ 130 void nbr_init(u_int32_t); 131 struct nbr *nbr_new(u_int32_t, struct iface *); 132 void nbr_act_del(struct nbr *); 133 134 struct nbr *nbr_find_ip(struct iface *, u_int32_t); 135 struct nbr *nbr_find_peerid(u_int32_t); 136 struct nbr_failed *nbr_failed_find(struct iface *, u_int32_t); 137 void nbr_failed_delete(struct nbr_failed *); 138 139 int nbr_fsm(struct nbr *, enum nbr_event); 140 void nbr_timeout_timer(int, short, void *); 141 void nbr_act_delete(struct nbr *); 142 143 const char *nbr_event_name(int); 144 const char *nbr_action_name(int); 145 146 struct ctl_nbr *nbr_to_ctl(struct nbr *); 147 148 #endif /* _RIPE_H_ */ 149