1 /* $OpenBSD: ripe.h,v 1.14 2021/01/19 10:02:22 claudio 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/ip.h> 27 28 /* neighbor events */ 29 enum nbr_event { 30 NBR_EVT_RESPONSE_RCVD, 31 NBR_EVT_REQUEST_RCVD, 32 NBR_EVT_RESPONSE_SENT, 33 NBR_EVT_TIMEOUT, 34 NBR_EVT_KILL_NBR, 35 NBR_EVT_NOTHING 36 }; 37 38 /* neighbor actions */ 39 enum nbr_action { 40 NBR_ACT_STRT_TIMER, 41 NBR_ACT_RST_TIMER, 42 NBR_ACT_DEL, 43 NBR_ACT_NOTHING 44 }; 45 46 struct nbr_failed { 47 struct event timeout_timer; 48 LIST_ENTRY(nbr_failed) entry; 49 struct in_addr addr; 50 u_int32_t auth_seq_num; 51 }; 52 53 struct nbr { 54 LIST_ENTRY(nbr) entry, hash; 55 struct event timeout_timer; 56 struct in_addr addr; 57 struct in_addr id; 58 59 struct packet_head rq_list; 60 struct packet_head rp_list; 61 62 struct iface *iface; 63 64 u_int32_t peerid; /* unique ID in DB */ 65 u_int32_t auth_seq_num; 66 u_int16_t port; 67 time_t uptime; 68 int state; 69 int flags; 70 }; 71 72 struct ctl_conn; 73 74 /* packet.c */ 75 int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); 76 void recv_packet(int, short, void *); 77 int gen_rip_hdr(struct ibuf *, u_int8_t); 78 79 /* interface.c */ 80 void if_init(struct ripd_conf *, struct iface *); 81 int if_fsm(struct iface *, enum iface_event); 82 int if_set_mcast(struct iface *); 83 int if_set_mcast_ttl(int, u_int8_t); 84 int if_set_mcast_loop(int); 85 int if_set_opt(int); 86 int if_set_tos(int, int); 87 void if_set_recvbuf(int); 88 struct iface *if_new(struct kif *); 89 void if_del(struct iface *); 90 const char *if_event_name(int); 91 const char *if_action_name(int); 92 int if_join_group(struct iface *, struct in_addr *); 93 int if_leave_group(struct iface *, struct in_addr *); 94 struct ctl_iface *if_to_ctl(struct iface *); 95 96 /* message.c */ 97 void recv_request(struct iface *, struct nbr *, u_int8_t *, u_int16_t); 98 void recv_response(struct iface *, struct nbr *, u_int8_t *, u_int16_t); 99 void add_entry(struct packet_head *, struct rip_route *); 100 void clear_list(struct packet_head *); 101 int send_triggered_update(struct iface *, struct rip_route *); 102 int send_request(struct packet_head *, struct iface *, struct nbr *); 103 int send_response(struct packet_head *, struct iface *, struct nbr *); 104 int start_report_timer(void); 105 void report_timer(int, short, void *); 106 107 /* ripe.c */ 108 pid_t ripe(struct ripd_conf *, int [2], int [2], int [2]); 109 int ripe_imsg_compose_parent(int, pid_t, void *, u_int16_t); 110 int ripe_imsg_compose_rde(int, u_int32_t, pid_t, void *, 111 u_int16_t); 112 void ripe_dispatch_main(int, short, void *); 113 void ripe_dispatch_rde(int, short, void *); 114 void ripe_iface_ctl(struct ctl_conn *, unsigned int); 115 void ripe_nbr_ctl(struct ctl_conn *); 116 void ripe_demote_iface(struct iface *, int); 117 118 /* auth.c */ 119 int auth_validate(u_int8_t **, u_int16_t *, struct iface *, struct nbr *, 120 struct nbr_failed *, u_int32_t *); 121 int auth_gen(struct ibuf *, struct iface *); 122 int auth_add_trailer(struct ibuf *, struct iface *); 123 int md_list_add(struct auth_md_head *, u_int8_t, char *); 124 void md_list_copy(struct auth_md_head *, struct auth_md_head *); 125 void md_list_clr(struct auth_md_head *); 126 127 /* neighbor.c */ 128 void nbr_init(u_int32_t); 129 struct nbr *nbr_new(u_int32_t, struct iface *); 130 void nbr_del(struct nbr *); 131 132 struct nbr *nbr_find_ip(struct iface *, u_int32_t); 133 struct nbr *nbr_find_peerid(u_int32_t); 134 struct nbr_failed *nbr_failed_find(struct iface *, u_int32_t); 135 void nbr_failed_delete(struct nbr_failed *); 136 137 int nbr_fsm(struct nbr *, enum nbr_event); 138 void nbr_timeout_timer(int, short, void *); 139 void nbr_act_del(struct nbr *); 140 141 const char *nbr_event_name(int); 142 const char *nbr_action_name(int); 143 144 struct ctl_nbr *nbr_to_ctl(struct nbr *); 145 146 #endif /* _RIPE_H_ */ 147