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