xref: /openbsd/usr.sbin/eigrpd/eigrpe.h (revision 9cf002a5)
1 /*	$OpenBSD: eigrpe.h,v 1.18 2021/01/19 10:37:25 claudio 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 struct pbuf {
29 	struct ibuf		*buf;
30 	int			 refcnt;
31 };
32 
33 struct packet {
34 	TAILQ_ENTRY(packet)	 entry;
35 	struct nbr		*nbr;
36 	uint32_t		 seq_num;
37 	struct pbuf		*pbuf;
38 	struct event		 ev_timeout;
39 	int			 attempts;
40 };
41 
42 struct nbr {
43 	RB_ENTRY(nbr)		 addr_tree, pid_tree;
44 	TAILQ_ENTRY(nbr)	 entry;
45 	struct event		 ev_ack;
46 	struct event		 ev_hello_timeout;
47 	struct eigrp_iface	*ei;
48 	union eigrpd_addr	 addr;
49 	uint32_t		 peerid;
50 	time_t			 uptime;
51 	uint16_t		 hello_holdtime;
52 	uint8_t			 flags;
53 #define F_EIGRP_NBR_SELF		0x01
54 #define F_EIGRP_NBR_PENDING		0x02
55 #define F_EIGRP_NBR_CR_MODE		0x04
56 
57 	struct rinfo_head	 update_list;	/* unicast updates */
58 	struct rinfo_head	 query_list;	/* unicast queries  */
59 	struct rinfo_head	 reply_list;	/* unicast replies */
60 
61 	/* RTP */
62 	uint32_t		 recv_seq;
63 	uint32_t		 next_mcast_seq;
64 	TAILQ_HEAD(, packet)	 retrans_list;
65 };
66 RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_compare)
67 RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare)
68 
69 #define PREFIX_SIZE4(x)	(((x - 1) / 8) + 1)
70 #define PREFIX_SIZE6(x)	((x == 128) ? 16 : ((x / 8) + 1))
71 
72 extern struct eigrpd_conf        *econf;
73 
74 struct ctl_conn;
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_addr_new(struct iface *, struct kaddr *);
95 void			 if_addr_del(struct iface *, struct kaddr *);
96 in_addr_t		 if_primary_addr(struct iface *);
97 uint8_t			 if_primary_addr_prefixlen(struct iface *);
98 void			 if_update(struct iface *, int);
99 struct eigrp_iface	*eigrp_if_new(struct eigrpd_conf *, struct eigrp *,
100 			    struct kif *);
101 void			 eigrp_if_del(struct eigrp_iface *);
102 struct eigrp_iface	*eigrp_if_lookup(struct iface *, int, uint16_t);
103 struct eigrp_iface	*eigrp_if_lookup_id(uint32_t);
104 struct ctl_iface	*if_to_ctl(struct eigrp_iface *);
105 void			 if_set_sockbuf(int);
106 int			 if_set_ipv4_mcast_ttl(int, uint8_t);
107 int			 if_set_ipv4_mcast(struct iface *);
108 int			 if_set_ipv4_mcast_loop(int);
109 int			 if_set_ipv4_recvif(int, int);
110 int			 if_set_ipv4_hdrincl(int);
111 int			 if_set_ipv6_mcast(struct iface *);
112 int			 if_set_ipv6_mcast_loop(int);
113 int			 if_set_ipv6_pktinfo(int, int);
114 int			 if_set_ipv6_dscp(int, int);
115 
116 /* neighbor.c */
117 struct nbr	*nbr_new(struct eigrp_iface *, union eigrpd_addr *,
118 		    uint16_t, int);
119 void		 nbr_init(struct nbr *);
120 void		 nbr_del(struct nbr *);
121 struct nbr	*nbr_find(struct eigrp_iface *, union eigrpd_addr *);
122 struct nbr	*nbr_find_peerid(uint32_t);
123 struct ctl_nbr	*nbr_to_ctl(struct nbr *);
124 void		 nbr_clear_ctl(struct ctl_nbr *);
125 void		 nbr_start_timeout(struct nbr *);
126 
127 /* rtp.c */
128 void		 rtp_packet_del(struct packet *);
129 void		 rtp_process_ack(struct nbr *, uint32_t);
130 void		 rtp_send_ucast(struct nbr *, struct ibuf *);
131 void		 rtp_send(struct eigrp_iface *, struct nbr *, struct ibuf *);
132 void		 rtp_send_ack(struct nbr *);
133 void		 rtp_ack_timer(int, short, void *);
134 void		 rtp_ack_start_timer(struct nbr *);
135 void		 rtp_ack_stop_timer(struct nbr *);
136 
137 /* packet.c */
138 int	 gen_eigrp_hdr(struct ibuf *, uint16_t, uint8_t, uint32_t,
139 	    uint16_t);
140 int	 send_packet(struct eigrp_iface *, struct nbr *, uint32_t,
141 	    struct ibuf *);
142 void	 recv_packet(int, short, void *);
143 
144 /* tlv.c */
145 int			 gen_parameter_tlv(struct ibuf *, struct eigrp_iface *,
146 			    int);
147 int			 gen_sequence_tlv(struct ibuf *,
148 			    struct seq_addr_head *);
149 int			 gen_sw_version_tlv(struct ibuf *);
150 int			 gen_mcast_seq_tlv(struct ibuf *, uint32_t);
151 uint16_t		 len_route_tlv(struct rinfo *);
152 int			 gen_route_tlv(struct ibuf *, struct rinfo *);
153 struct tlv_parameter	*tlv_decode_parameter(struct tlv *, char *);
154 int			 tlv_decode_seq(int, struct tlv *, char *,
155 			    struct seq_addr_head *);
156 struct tlv_sw_version	*tlv_decode_sw_version(struct tlv *, char *);
157 struct tlv_mcast_seq	*tlv_decode_mcast_seq(struct tlv *, char *);
158 int			 tlv_decode_route(int, struct tlv *, char *,
159 			    struct rinfo *);
160 void			 metric_encode_mtu(uint8_t *, int);
161 int			 metric_decode_mtu(uint8_t *);
162 
163 /* hello.c */
164 void	 send_hello(struct eigrp_iface *, struct seq_addr_head *, uint32_t);
165 void	 send_peerterm(struct nbr *);
166 void	 recv_hello(struct eigrp_iface *, union eigrpd_addr *, struct nbr *,
167 	    struct tlv_parameter *);
168 
169 /* update.c */
170 void	 send_update(struct eigrp_iface *, struct nbr *, uint32_t,
171 	    struct rinfo_head *);
172 void	 recv_update(struct nbr *, struct rinfo_head *, uint32_t);
173 
174 /* query.c */
175 void	 send_query(struct eigrp_iface *, struct nbr *, struct rinfo_head *,
176 	    int);
177 void	 recv_query(struct nbr *, struct rinfo_head *, int);
178 
179 /* reply.c */
180 void	 send_reply(struct nbr *, struct rinfo_head *, int);
181 void	 recv_reply(struct nbr *, struct rinfo_head *, int);
182 
183 #endif	/* _EIGRPE_H_ */
184