xref: /openbsd/usr.sbin/rad/rad.h (revision 8815eebd)
1 /*	$OpenBSD: rad.h,v 1.15 2018/08/03 13:14:46 florian 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 enum {
36 	PROC_MAIN,
37 	PROC_ENGINE,
38 	PROC_FRONTEND
39 } rad_process;
40 
41 static const char * const log_procnames[] = {
42 	"main",
43 	"engine",
44 	"frontend",
45 };
46 
47 struct imsgev {
48 	struct imsgbuf	 ibuf;
49 	void		(*handler)(int, short, void *);
50 	struct event	 ev;
51 	short		 events;
52 };
53 
54 enum imsg_type {
55 	IMSG_NONE,
56 	IMSG_CTL_LOG_VERBOSE,
57 	IMSG_CTL_RELOAD,
58 	IMSG_RECONF_CONF,
59 	IMSG_RECONF_RA_IFACE,
60 	IMSG_RECONF_RA_AUTOPREFIX,
61 	IMSG_RECONF_RA_PREFIX,
62 	IMSG_RECONF_RA_RDNSS,
63 	IMSG_RECONF_RA_DNSSL,
64 	IMSG_RECONF_END,
65 	IMSG_ICMP6SOCK,
66 	IMSG_ROUTESOCK,
67 	IMSG_CONTROLFD,
68 	IMSG_STARTUP,
69 	IMSG_STARTUP_DONE,
70 	IMSG_RA_RS,
71 	IMSG_SEND_RA,
72 	IMSG_UPDATE_IF,
73 	IMSG_REMOVE_IF,
74 	IMSG_SHUTDOWN,
75 	IMSG_SOCKET_IPC
76 };
77 
78 /* RFC 8106 */
79 struct ra_rdnss_conf {
80 	SIMPLEQ_ENTRY(ra_rdnss_conf)	entry;
81 	struct in6_addr			rdnss;
82 };
83 struct ra_dnssl_conf {
84 	SIMPLEQ_ENTRY(ra_dnssl_conf)	entry;
85 	char				search[MAX_SEARCH];
86 };
87 
88 /* RFC 4861 Sections 4.2 and 4.6.4 */
89 struct ra_options_conf {
90 	int		dfr;			/* is default router? */
91 	int		cur_hl;			/* current hop limit */
92 	int		m_flag;			/* managed address conf flag */
93 	int		o_flag;			/* other conf flag */
94 	int		router_lifetime;	/* default router lifetime */
95 	uint32_t	reachable_time;
96 	uint32_t	retrans_timer;
97 	uint32_t	mtu;
98 	uint32_t	rdns_lifetime;
99 	SIMPLEQ_HEAD(, ra_rdnss_conf)		 ra_rdnss_list;
100 	int		rdnss_count;
101 	SIMPLEQ_HEAD(, ra_dnssl_conf)		 ra_dnssl_list;
102 	int		dnssl_len;
103 };
104 
105 /* RFC 4861 Section 4.6.2 */
106 struct ra_prefix_conf {
107 	SIMPLEQ_ENTRY(ra_prefix_conf)	 entry;
108 	struct in6_addr			 prefix;	/* prefix */
109 	int				 prefixlen;	/* prefix length */
110 	uint32_t			 vltime;	/* valid lifetime */
111 	uint32_t			 pltime;	/* prefered lifetime */
112 	int				 lflag;		/* on-link flag*/
113 	int				 aflag;		/* autonom. addr flag */
114 };
115 
116 struct ra_iface_conf {
117 	SIMPLEQ_ENTRY(ra_iface_conf)		 entry;
118 	struct ra_options_conf			 ra_options;
119 	struct ra_prefix_conf			*autoprefix;
120 	SIMPLEQ_HEAD(ra_prefix_conf_head,
121 	    ra_prefix_conf)			 ra_prefix_list;
122 	char					 name[IF_NAMESIZE];
123 };
124 
125 struct rad_conf {
126 	struct ra_options_conf				 ra_options;
127 	SIMPLEQ_HEAD(ra_iface_conf_head, ra_iface_conf)	 ra_iface_list;
128 };
129 
130 struct imsg_ra_rs {
131 	uint32_t		if_index;
132 	struct sockaddr_in6	from;
133 	ssize_t			len;
134 	uint8_t			packet[1500];
135 };
136 
137 struct imsg_send_ra {
138 	uint32_t		if_index;
139 	struct sockaddr_in6	to;
140 };
141 
142 extern uint32_t	 cmd_opts;
143 
144 /* rad.c */
145 void	main_imsg_compose_frontend(int, pid_t, void *, uint16_t);
146 void	main_imsg_compose_frontend_fd(int, pid_t, int);
147 
148 void	main_imsg_compose_engine(int, pid_t, void *, uint16_t);
149 void	merge_config(struct rad_conf *, struct rad_conf *);
150 void	imsg_event_add(struct imsgev *);
151 int	imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
152 	    int, void *, uint16_t);
153 
154 struct rad_conf	*config_new_empty(void);
155 void		 config_clear(struct rad_conf *);
156 void		 free_ra_iface_conf(struct ra_iface_conf *);
157 void		 free_dns_options(struct ra_options_conf *);
158 void		 mask_prefix(struct in6_addr*, int len);
159 const char	*sin6_to_str(struct sockaddr_in6 *);
160 const char	*in6_to_str(struct in6_addr *);
161 
162 /* printconf.c */
163 void	print_config(struct rad_conf *);
164 
165 /* parse.y */
166 struct rad_conf	*parse_config(char *);
167 int			 cmdline_symset(char *);
168