1 /* $OpenBSD: dvmrpe.h,v 1.5 2014/10/25 03:23:49 lteo 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 TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; 28 29 /* neighbor events */ 30 enum nbr_event { 31 NBR_EVT_NOTHING, 32 NBR_EVT_PROBE_RCVD, 33 NBR_EVT_1_WAY_RCVD, 34 NBR_EVT_2_WAY_RCVD, 35 NBR_EVT_KILL_NBR, 36 NBR_EVT_ITIMER, 37 NBR_EVT_LL_DOWN 38 }; 39 40 /* neighbor actions */ 41 enum nbr_action { 42 NBR_ACT_NOTHING, 43 NBR_ACT_RST_ITIMER, 44 NBR_ACT_STRT_ITIMER, 45 NBR_ACT_RESET, 46 NBR_ACT_DEL, 47 NBR_ACT_CLR_LST 48 }; 49 50 struct nbr { 51 LIST_ENTRY(nbr) entry, hash; 52 struct event inactivity_timer; 53 54 struct rr_head rr_list; 55 56 struct in_addr addr; 57 struct in_addr id; 58 59 struct iface *iface; 60 61 u_int32_t peerid; /* unique ID in DB */ 62 u_int32_t gen_id; 63 64 time_t uptime; 65 66 int state; 67 u_int8_t link_state; 68 u_int8_t capabilities; 69 u_int8_t compat; /* mrouted compat */ 70 }; 71 72 struct route_report { 73 struct in_addr net; 74 struct in_addr mask; 75 struct in_addr nexthop; 76 struct in_addr adv_rtr; 77 int refcount; 78 u_short ifindex; 79 u_int8_t metric; 80 81 }; 82 83 struct rr_entry { 84 TAILQ_ENTRY(rr_entry) entry; 85 struct route_report *re; 86 }; 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 char *pkt_ptr; /* packet buffer */ 190 191 /* probe.c */ 192 int send_probe(struct iface *); 193 void recv_probe(struct iface *, struct in_addr, u_int32_t, u_int8_t, 194 char *, u_int16_t); 195 196 /* prune.c */ 197 int send_prune(struct nbr *, struct prune *); 198 void recv_prune(struct nbr *, char *, u_int16_t); 199 200 /* report.c */ 201 int send_report(struct iface *, struct in_addr, void *, int); 202 void recv_report(struct nbr *, char *, u_int16_t); 203 204 void report_timer(int, short, void *); 205 int start_report_timer(void); 206 int stop_report_timer(void); 207 208 void rr_list_add(struct rr_head *, struct route_report *); 209 void rr_list_clr(struct rr_head *); 210 void rr_list_send(struct rr_head *, struct iface *, struct nbr *); 211 212 #endif /* _DVMRPE_H_ */ 213