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