1 /* $OpenBSD: dvmrpe.h,v 1.7 2021/01/19 12:23:30 claudio Exp $ */ 2 3 /* 4 * Copyright (c) 2004, 2005, 2006 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 _DVMRPE_H_ 20 #define _DVMRPE_H_ 21 22 #include <sys/types.h> 23 #include <sys/socket.h> 24 #include <netinet/in.h> 25 #include <netinet/ip.h> 26 27 /* neighbor events */ 28 enum nbr_event { 29 NBR_EVT_NOTHING, 30 NBR_EVT_PROBE_RCVD, 31 NBR_EVT_1_WAY_RCVD, 32 NBR_EVT_2_WAY_RCVD, 33 NBR_EVT_KILL_NBR, 34 NBR_EVT_ITIMER, 35 NBR_EVT_LL_DOWN 36 }; 37 38 /* neighbor actions */ 39 enum nbr_action { 40 NBR_ACT_NOTHING, 41 NBR_ACT_RST_ITIMER, 42 NBR_ACT_STRT_ITIMER, 43 NBR_ACT_RESET, 44 NBR_ACT_DEL, 45 NBR_ACT_CLR_LST 46 }; 47 48 struct nbr { 49 LIST_ENTRY(nbr) entry, hash; 50 struct event inactivity_timer; 51 52 struct rr_head rr_list; 53 54 struct in_addr addr; 55 struct in_addr id; 56 57 struct iface *iface; 58 59 u_int32_t peerid; /* unique ID in DB */ 60 u_int32_t gen_id; 61 62 time_t uptime; 63 64 int state; 65 u_int8_t link_state; 66 u_int8_t capabilities; 67 u_int8_t compat; /* mrouted compat */ 68 }; 69 70 struct route_report { 71 struct in_addr net; 72 struct in_addr mask; 73 struct in_addr nexthop; 74 struct in_addr adv_rtr; 75 int refcount; 76 u_short ifindex; 77 u_int8_t metric; 78 79 }; 80 81 struct rr_entry { 82 TAILQ_ENTRY(rr_entry) entry; 83 struct route_report *re; 84 }; 85 86 struct ctl_conn; 87 88 /* ask_nbrs2.c */ 89 int send_ask_nbrs2(struct iface *, struct in_addr, void *, int); 90 void recv_ask_nbrs2(struct nbr *, char *, u_int16_t); 91 92 /* dvmrpe.c */ 93 pid_t dvmrpe(struct dvmrpd_conf *, int[2], int[2], int[2]); 94 void dvmrpe_dispatch_main(int, short, void *); 95 void dvmrpe_dispatch_rde(int, short, void *); 96 int dvmrpe_imsg_compose_parent(int, pid_t, void *, u_int16_t); 97 int dvmrpe_imsg_compose_rde(int, u_int32_t, pid_t, void *, u_int16_t); 98 99 void dvmrpe_iface_ctl(struct ctl_conn *, unsigned int); 100 void dvmrpe_iface_igmp_ctl(struct ctl_conn *, unsigned int); 101 void dvmrpe_nbr_ctl(struct ctl_conn *); 102 103 /* graft.c */ 104 int send_graft(struct iface *, struct in_addr, void *, int); 105 void recv_graft(struct nbr *, char *, u_int16_t); 106 107 /* graft_ack.c */ 108 int send_graft_ack(struct iface *, struct in_addr, void *, int); 109 void recv_graft_ack(struct nbr *, char *, u_int16_t); 110 111 /* group.c */ 112 struct ctl_group *group_to_ctl(struct group *); 113 114 /* igmp.c */ 115 int group_fsm(struct group *, enum group_event); 116 int send_igmp_query(struct iface *, struct group *group); 117 void recv_igmp_query(struct iface *, struct in_addr, char *, u_int16_t); 118 void recv_igmp_report(struct iface *, struct in_addr, char *, u_int16_t, 119 u_int8_t); 120 void recv_igmp_leave(struct iface *, struct in_addr, char *, u_int16_t); 121 122 struct group *group_list_add(struct iface *, u_int32_t); 123 void group_list_remove(struct iface *, struct group *); 124 struct group *group_list_find(struct iface *, u_int32_t); 125 void group_list_clr(struct iface *); 126 int group_list_empty(struct iface *); 127 void group_list_dump(struct iface *, struct ctl_conn *); 128 129 const char *group_event_name(int); 130 const char *group_action_name(int); 131 132 /* interface.c */ 133 int if_fsm(struct iface *, enum iface_event); 134 struct iface *if_new(struct kif *); 135 int if_del(struct iface *); 136 int if_nbr_list_empty(struct iface *); 137 void if_init(struct dvmrpd_conf *, struct iface *); 138 139 const char *if_event_name(int); 140 const char *if_action_name(int); 141 142 int if_set_mcast_ttl(int, u_int8_t); 143 int if_set_tos(int, int); 144 int if_set_mcast_loop(int); 145 void if_set_recvbuf(int); 146 147 int if_join_group(struct iface *, struct in_addr *); 148 int if_leave_group(struct iface *, struct in_addr *); 149 int if_set_mcast(struct iface *); 150 151 struct ctl_iface *if_to_ctl(struct iface *); 152 153 /* nbrs2.c */ 154 int send_nbrs2(struct iface *, struct in_addr, void *, int); 155 void recv_nbrs2(struct nbr *, char *, u_int16_t); 156 157 /* neighbor.c */ 158 void nbr_init(u_int32_t); 159 struct nbr *nbr_new(u_int32_t, struct iface *, int); 160 int nbr_del(struct nbr *); 161 162 struct nbr *nbr_find_ip(struct iface *, u_int32_t); 163 struct nbr *nbr_find_peerid(u_int32_t); 164 165 int nbr_fsm(struct nbr *, enum nbr_event); 166 167 int nbr_start_itimer(struct nbr *); 168 int nbr_stop_itimer(struct nbr *); 169 int nbr_reset_itimer(struct nbr *); 170 171 void nbr_itimer(int, short, void *); 172 173 int nbr_act_start(struct nbr *); 174 int nbr_act_reset_itimer(struct nbr *); 175 int nbr_act_start_itimer(struct nbr *); 176 int nbr_act_delete(struct nbr *); 177 int nbr_act_clear_lists(struct nbr *); 178 179 const char *nbr_event_name(int); 180 const char *nbr_action_name(int); 181 182 struct ctl_nbr *nbr_to_ctl(struct nbr *); 183 184 /* packet.c */ 185 int gen_dvmrp_hdr(struct ibuf *, struct iface *, u_int8_t); 186 int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); 187 void recv_packet(int, short, void *); 188 189 /* probe.c */ 190 int send_probe(struct iface *); 191 void recv_probe(struct iface *, struct in_addr, u_int32_t, u_int8_t, 192 char *, u_int16_t); 193 194 /* prune.c */ 195 int send_prune(struct nbr *, struct prune *); 196 void recv_prune(struct nbr *, char *, u_int16_t); 197 198 /* report.c */ 199 int send_report(struct iface *, struct in_addr, void *, int); 200 void recv_report(struct nbr *, char *, u_int16_t); 201 202 void report_timer(int, short, void *); 203 int start_report_timer(void); 204 int stop_report_timer(void); 205 206 void rr_list_add(struct rr_head *, struct route_report *); 207 void rr_list_clr(struct rr_head *); 208 void rr_list_send(struct rr_head *, struct iface *, struct nbr *); 209 210 #endif /* _DVMRPE_H_ */ 211