1 /* $OpenBSD: eigrpe.h,v 1.15 2016/09/02 16:46:29 renato Exp $ */ 2 3 /* 4 * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> 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 _EIGRPE_H_ 21 #define _EIGRPE_H_ 22 23 #include <sys/queue.h> 24 #include <sys/tree.h> 25 26 #include <event.h> 27 28 TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; 29 30 struct pbuf { 31 struct ibuf *buf; 32 int refcnt; 33 }; 34 35 struct packet { 36 TAILQ_ENTRY(packet) entry; 37 struct nbr *nbr; 38 uint32_t seq_num; 39 struct pbuf *pbuf; 40 struct event ev_timeout; 41 int attempts; 42 }; 43 44 struct nbr { 45 RB_ENTRY(nbr) addr_tree, pid_tree; 46 TAILQ_ENTRY(nbr) entry; 47 struct event ev_ack; 48 struct event ev_hello_timeout; 49 struct eigrp_iface *ei; 50 union eigrpd_addr addr; 51 uint32_t peerid; 52 time_t uptime; 53 uint16_t hello_holdtime; 54 uint8_t flags; 55 #define F_EIGRP_NBR_SELF 0x01 56 #define F_EIGRP_NBR_PENDING 0x02 57 #define F_EIGRP_NBR_CR_MODE 0x04 58 59 struct rinfo_head update_list; /* unicast updates */ 60 struct rinfo_head query_list; /* unicast queries */ 61 struct rinfo_head reply_list; /* unicast replies */ 62 63 /* RTP */ 64 uint32_t recv_seq; 65 uint32_t next_mcast_seq; 66 TAILQ_HEAD(, packet) retrans_list; 67 }; 68 RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_compare) 69 RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare) 70 71 #define PREFIX_SIZE4(x) (((x - 1) / 8) + 1) 72 #define PREFIX_SIZE6(x) ((x == 128) ? 16 : ((x / 8) + 1)) 73 74 extern struct eigrpd_conf *econf; 75 76 /* eigrpe.c */ 77 void eigrpe(int, int, char *); 78 int eigrpe_imsg_compose_parent(int, pid_t, void *, uint16_t); 79 int eigrpe_imsg_compose_rde(int, uint32_t, pid_t, void *, 80 uint16_t); 81 void eigrpe_instance_init(struct eigrp *); 82 void eigrpe_instance_del(struct eigrp *); 83 void message_add(struct rinfo_head *, struct rinfo *); 84 void message_list_clr(struct rinfo_head *); 85 void seq_addr_list_clr(struct seq_addr_head *); 86 void eigrpe_orig_local_route(struct eigrp_iface *, 87 struct if_addr *, int); 88 void eigrpe_iface_ctl(struct ctl_conn *, unsigned int); 89 void eigrpe_nbr_ctl(struct ctl_conn *); 90 void eigrpe_stats_ctl(struct ctl_conn *); 91 92 /* interface.c */ 93 struct iface *if_lookup(struct eigrpd_conf *, unsigned int); 94 void if_init(struct eigrpd_conf *, struct iface *); 95 void if_addr_new(struct iface *, struct kaddr *); 96 void if_addr_del(struct iface *, struct kaddr *); 97 in_addr_t if_primary_addr(struct iface *); 98 uint8_t if_primary_addr_prefixlen(struct iface *); 99 void if_update(struct iface *, int); 100 struct eigrp_iface *eigrp_if_new(struct eigrpd_conf *, struct eigrp *, 101 struct kif *); 102 void eigrp_if_del(struct eigrp_iface *); 103 struct eigrp_iface *eigrp_if_lookup(struct iface *, int, uint16_t); 104 struct eigrp_iface *eigrp_if_lookup_id(uint32_t); 105 struct ctl_iface *if_to_ctl(struct eigrp_iface *); 106 void if_set_sockbuf(int); 107 int if_set_ipv4_mcast_ttl(int, uint8_t); 108 int if_set_ipv4_mcast(struct iface *); 109 int if_set_ipv4_mcast_loop(int); 110 int if_set_ipv4_recvif(int, int); 111 int if_set_ipv4_hdrincl(int); 112 int if_set_ipv6_mcast(struct iface *); 113 int if_set_ipv6_mcast_loop(int); 114 int if_set_ipv6_pktinfo(int, int); 115 int if_set_ipv6_dscp(int, int); 116 117 /* neighbor.c */ 118 struct nbr *nbr_new(struct eigrp_iface *, union eigrpd_addr *, 119 uint16_t, int); 120 void nbr_init(struct nbr *); 121 void nbr_del(struct nbr *); 122 struct nbr *nbr_find(struct eigrp_iface *, union eigrpd_addr *); 123 struct nbr *nbr_find_peerid(uint32_t); 124 struct ctl_nbr *nbr_to_ctl(struct nbr *); 125 void nbr_clear_ctl(struct ctl_nbr *); 126 void nbr_start_timeout(struct nbr *); 127 128 /* rtp.c */ 129 void rtp_packet_del(struct packet *); 130 void rtp_process_ack(struct nbr *, uint32_t); 131 void rtp_send_ucast(struct nbr *, struct ibuf *); 132 void rtp_send(struct eigrp_iface *, struct nbr *, struct ibuf *); 133 void rtp_send_ack(struct nbr *); 134 void rtp_ack_timer(int, short, void *); 135 void rtp_ack_start_timer(struct nbr *); 136 void rtp_ack_stop_timer(struct nbr *); 137 138 /* packet.c */ 139 int gen_eigrp_hdr(struct ibuf *, uint16_t, uint8_t, uint32_t, 140 uint16_t); 141 int send_packet(struct eigrp_iface *, struct nbr *, uint32_t, 142 struct ibuf *); 143 void recv_packet(int, short, void *); 144 145 /* tlv.c */ 146 int gen_parameter_tlv(struct ibuf *, struct eigrp_iface *, 147 int); 148 int gen_sequence_tlv(struct ibuf *, 149 struct seq_addr_head *); 150 int gen_sw_version_tlv(struct ibuf *); 151 int gen_mcast_seq_tlv(struct ibuf *, uint32_t); 152 uint16_t len_route_tlv(struct rinfo *); 153 int gen_route_tlv(struct ibuf *, struct rinfo *); 154 struct tlv_parameter *tlv_decode_parameter(struct tlv *, char *); 155 int tlv_decode_seq(int, struct tlv *, char *, 156 struct seq_addr_head *); 157 struct tlv_sw_version *tlv_decode_sw_version(struct tlv *, char *); 158 struct tlv_mcast_seq *tlv_decode_mcast_seq(struct tlv *, char *); 159 int tlv_decode_route(int, struct tlv *, char *, 160 struct rinfo *); 161 void metric_encode_mtu(uint8_t *, int); 162 int metric_decode_mtu(uint8_t *); 163 164 /* hello.c */ 165 void send_hello(struct eigrp_iface *, struct seq_addr_head *, uint32_t); 166 void send_peerterm(struct nbr *); 167 void recv_hello(struct eigrp_iface *, union eigrpd_addr *, struct nbr *, 168 struct tlv_parameter *); 169 170 /* update.c */ 171 void send_update(struct eigrp_iface *, struct nbr *, uint32_t, 172 struct rinfo_head *); 173 void recv_update(struct nbr *, struct rinfo_head *, uint32_t); 174 175 /* query.c */ 176 void send_query(struct eigrp_iface *, struct nbr *, struct rinfo_head *, 177 int); 178 void recv_query(struct nbr *, struct rinfo_head *, int); 179 180 /* reply.c */ 181 void send_reply(struct nbr *, struct rinfo_head *, int); 182 void recv_reply(struct nbr *, struct rinfo_head *, int); 183 184 char *pkt_ptr; /* packet buffer */ 185 186 #endif /* _EIGRPE_H_ */ 187