xref: /openbsd-src/usr.sbin/rad/rad.h (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1 /*	$OpenBSD: rad.h,v 1.17 2019/03/02 03:40:45 pamela Exp $	*/
2 
3 /*
4  * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
5  * Copyright (c) 2004 Esben Norby <norby@openbsd.org>
6  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #define CONF_FILE		"/etc/rad.conf"
22 #define	RAD_SOCKET		"/var/run/rad.sock"
23 #define RAD_USER		"_rad"
24 
25 #define OPT_VERBOSE	0x00000001
26 #define OPT_VERBOSE2	0x00000002
27 #define OPT_NOACTION	0x00000004
28 
29 
30 #define	MAX_RTR_ADV_INTERVAL		600
31 #define	MIN_RTR_ADV_INTERVAL		200
32 #define	MAX_SEARCH 1025 /* same as MAXDNAME in arpa/nameser.h */
33 #define	DEFAULT_RDNS_LIFETIME		600 * 1.5
34 
35 #define IMSG_DATA_SIZE(imsg)	((imsg).hdr.len - IMSG_HEADER_SIZE)
36 
37 enum {
38 	PROC_MAIN,
39 	PROC_ENGINE,
40 	PROC_FRONTEND
41 } rad_process;
42 
43 static const char * const log_procnames[] = {
44 	"main",
45 	"engine",
46 	"frontend",
47 };
48 
49 struct imsgev {
50 	struct imsgbuf	 ibuf;
51 	void		(*handler)(int, short, void *);
52 	struct event	 ev;
53 	short		 events;
54 };
55 
56 enum imsg_type {
57 	IMSG_NONE,
58 	IMSG_CTL_LOG_VERBOSE,
59 	IMSG_CTL_RELOAD,
60 	IMSG_RECONF_CONF,
61 	IMSG_RECONF_RA_IFACE,
62 	IMSG_RECONF_RA_AUTOPREFIX,
63 	IMSG_RECONF_RA_PREFIX,
64 	IMSG_RECONF_RA_RDNSS,
65 	IMSG_RECONF_RA_DNSSL,
66 	IMSG_RECONF_END,
67 	IMSG_ICMP6SOCK,
68 	IMSG_ROUTESOCK,
69 	IMSG_CONTROLFD,
70 	IMSG_STARTUP,
71 	IMSG_STARTUP_DONE,
72 	IMSG_RA_RS,
73 	IMSG_SEND_RA,
74 	IMSG_UPDATE_IF,
75 	IMSG_REMOVE_IF,
76 	IMSG_SOCKET_IPC
77 };
78 
79 /* RFC 8106 */
80 struct ra_rdnss_conf {
81 	SIMPLEQ_ENTRY(ra_rdnss_conf)	entry;
82 	struct in6_addr			rdnss;
83 };
84 struct ra_dnssl_conf {
85 	SIMPLEQ_ENTRY(ra_dnssl_conf)	entry;
86 	char				search[MAX_SEARCH];
87 };
88 
89 /* RFC 4861 Sections 4.2 and 4.6.4 */
90 struct ra_options_conf {
91 	int		dfr;			/* is default router? */
92 	int		cur_hl;			/* current hop limit */
93 	int		m_flag;			/* managed address conf flag */
94 	int		o_flag;			/* other conf flag */
95 	int		router_lifetime;	/* default router lifetime */
96 	uint32_t	reachable_time;
97 	uint32_t	retrans_timer;
98 	uint32_t	mtu;
99 	uint32_t	rdns_lifetime;
100 	SIMPLEQ_HEAD(, ra_rdnss_conf)		 ra_rdnss_list;
101 	int		rdnss_count;
102 	SIMPLEQ_HEAD(, ra_dnssl_conf)		 ra_dnssl_list;
103 	int		dnssl_len;
104 };
105 
106 /* RFC 4861 Section 4.6.2 */
107 struct ra_prefix_conf {
108 	SIMPLEQ_ENTRY(ra_prefix_conf)	 entry;
109 	struct in6_addr			 prefix;	/* prefix */
110 	int				 prefixlen;	/* prefix length */
111 	uint32_t			 vltime;	/* valid lifetime */
112 	uint32_t			 pltime;	/* prefered lifetime */
113 	int				 lflag;		/* on-link flag*/
114 	int				 aflag;		/* autonom. addr flag */
115 };
116 
117 struct ra_iface_conf {
118 	SIMPLEQ_ENTRY(ra_iface_conf)		 entry;
119 	struct ra_options_conf			 ra_options;
120 	struct ra_prefix_conf			*autoprefix;
121 	SIMPLEQ_HEAD(ra_prefix_conf_head,
122 	    ra_prefix_conf)			 ra_prefix_list;
123 	char					 name[IF_NAMESIZE];
124 };
125 
126 struct rad_conf {
127 	struct ra_options_conf				 ra_options;
128 	SIMPLEQ_HEAD(ra_iface_conf_head, ra_iface_conf)	 ra_iface_list;
129 };
130 
131 struct imsg_ra_rs {
132 	uint32_t		if_index;
133 	struct sockaddr_in6	from;
134 	ssize_t			len;
135 	uint8_t			packet[1500];
136 };
137 
138 struct imsg_send_ra {
139 	uint32_t		if_index;
140 	struct sockaddr_in6	to;
141 };
142 
143 extern uint32_t	 cmd_opts;
144 
145 /* rad.c */
146 void	main_imsg_compose_frontend(int, pid_t, void *, uint16_t);
147 void	main_imsg_compose_frontend_fd(int, pid_t, int);
148 
149 void	main_imsg_compose_engine(int, pid_t, void *, uint16_t);
150 void	merge_config(struct rad_conf *, struct rad_conf *);
151 void	imsg_event_add(struct imsgev *);
152 int	imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
153 	    int, void *, uint16_t);
154 
155 struct rad_conf	*config_new_empty(void);
156 void		 config_clear(struct rad_conf *);
157 void		 free_ra_iface_conf(struct ra_iface_conf *);
158 void		 free_dns_options(struct ra_options_conf *);
159 void		 mask_prefix(struct in6_addr*, int len);
160 const char	*sin6_to_str(struct sockaddr_in6 *);
161 const char	*in6_to_str(struct in6_addr *);
162 
163 /* printconf.c */
164 void	print_config(struct rad_conf *);
165 
166 /* parse.y */
167 struct rad_conf	*parse_config(char *);
168 int			 cmdline_symset(char *);
169