xref: /openbsd-src/usr.sbin/rad/rad.h (revision 4905b492331fb63aacf78a6ba145bafb628c5088)
1*4905b492Sflorian /*	$OpenBSD: rad.h,v 1.29 2024/12/28 08:58:14 florian Exp $	*/
253293e44Sflorian 
353293e44Sflorian /*
453293e44Sflorian  * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
553293e44Sflorian  * Copyright (c) 2004 Esben Norby <norby@openbsd.org>
653293e44Sflorian  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
753293e44Sflorian  *
853293e44Sflorian  * Permission to use, copy, modify, and distribute this software for any
953293e44Sflorian  * purpose with or without fee is hereby granted, provided that the above
1053293e44Sflorian  * copyright notice and this permission notice appear in all copies.
1153293e44Sflorian  *
1253293e44Sflorian  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1353293e44Sflorian  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1453293e44Sflorian  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1553293e44Sflorian  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1653293e44Sflorian  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1753293e44Sflorian  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1853293e44Sflorian  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1953293e44Sflorian  */
2053293e44Sflorian 
21e0daf9a7Sflorian #define	_PATH_CONF_FILE		"/etc/rad.conf"
22e0daf9a7Sflorian #define	_PATH_RAD_SOCKET	"/var/run/rad.sock"
23118c7671Sflorian #define	RAD_USER		"_rad"
2453293e44Sflorian 
2553293e44Sflorian #define	OPT_VERBOSE	0x00000001
2653293e44Sflorian #define	OPT_VERBOSE2	0x00000002
2753293e44Sflorian #define	OPT_NOACTION	0x00000004
2853293e44Sflorian 
294c40b7e8Sflorian #define	MAX_RTR_ADV_INTERVAL	600
304c40b7e8Sflorian #define	MIN_RTR_ADV_INTERVAL	200
3103aa2005Sflorian #define	ADV_DEFAULT_LIFETIME	3 * MAX_RTR_ADV_INTERVAL
32462fa675Sphessler #define	ADV_PREFERRED_LIFETIME	2700	/* 45 minutes */
33462fa675Sphessler #define	ADV_VALID_LIFETIME	5400	/* 90 minutes */
34a14293eaSflorian #define	MAX_RA_DELAY_TIME	500	/* 500 milliseconds */
35a14293eaSflorian #define	MIN_DELAY_BETWEEN_RAS	3	/* 3 seconds */
3603aa2005Sflorian #define	MAX_SEARCH		1025	/* MAXDNAME in arpa/nameser.h */
37*4905b492Sflorian #define	DEFAULT_RDNS_LIFETIME	3 * MAX_RTR_ADV_INTERVAL
3820fc6e8eSflorian #define	PLTIME_DECAYING		1
3920fc6e8eSflorian #define	VLTIME_DECAYING		2
404c40b7e8Sflorian 
41b17c900dSpamela #define	IMSG_DATA_SIZE(imsg)	((imsg).hdr.len - IMSG_HEADER_SIZE)
42b17c900dSpamela 
4353293e44Sflorian struct imsgev {
4453293e44Sflorian 	struct imsgbuf	 ibuf;
4553293e44Sflorian 	void		(*handler)(int, short, void *);
4653293e44Sflorian 	struct event	 ev;
4753293e44Sflorian 	short		 events;
4853293e44Sflorian };
4953293e44Sflorian 
5053293e44Sflorian enum imsg_type {
5153293e44Sflorian 	IMSG_NONE,
5253293e44Sflorian 	IMSG_CTL_LOG_VERBOSE,
5353293e44Sflorian 	IMSG_CTL_RELOAD,
5453293e44Sflorian 	IMSG_RECONF_CONF,
5553293e44Sflorian 	IMSG_RECONF_RA_IFACE,
5653293e44Sflorian 	IMSG_RECONF_RA_AUTOPREFIX,
5753293e44Sflorian 	IMSG_RECONF_RA_PREFIX,
584c40b7e8Sflorian 	IMSG_RECONF_RA_RDNSS,
594c40b7e8Sflorian 	IMSG_RECONF_RA_DNSSL,
605207bb19Sflorian 	IMSG_RECONF_RA_PREF64,
6153293e44Sflorian 	IMSG_RECONF_END,
6253293e44Sflorian 	IMSG_ICMP6SOCK,
63e88dba76Sflorian 	IMSG_OPEN_ICMP6SOCK,
6448e174fdSflorian 	IMSG_ROUTESOCK,
65a778af8bSflorian 	IMSG_CONTROLFD,
6653293e44Sflorian 	IMSG_STARTUP,
6753293e44Sflorian 	IMSG_RA_RS,
6853293e44Sflorian 	IMSG_SEND_RA,
690c40990eSflorian 	IMSG_UPDATE_IF,
704a78c7cfSflorian 	IMSG_REMOVE_IF,
7153293e44Sflorian 	IMSG_SOCKET_IPC
7253293e44Sflorian };
7353293e44Sflorian 
748815eebdSflorian /* RFC 8106 */
758815eebdSflorian struct ra_rdnss_conf {
768815eebdSflorian 	SIMPLEQ_ENTRY(ra_rdnss_conf)	entry;
778815eebdSflorian 	struct in6_addr			rdnss;
788815eebdSflorian };
798815eebdSflorian struct ra_dnssl_conf {
808815eebdSflorian 	SIMPLEQ_ENTRY(ra_dnssl_conf)	entry;
818815eebdSflorian 	char				search[MAX_SEARCH];
828815eebdSflorian };
838815eebdSflorian 
845207bb19Sflorian /* RFC 8781 Section 4 */
855207bb19Sflorian struct ra_pref64_conf {
865207bb19Sflorian 	SIMPLEQ_ENTRY(ra_pref64_conf)	 entry;
875207bb19Sflorian 	struct in6_addr			 prefix;	/* prefix */
885207bb19Sflorian 	int				 prefixlen;	/* prefix length */
895207bb19Sflorian 	uint32_t			 ltime;		/* lifetime */
905207bb19Sflorian };
915207bb19Sflorian 
92cea17583Sbket /* RFC 4861 Sections 4.2 and 4.6.4 */
9353293e44Sflorian struct ra_options_conf {
9453293e44Sflorian 	int		dfr;			/* is default router? */
9553293e44Sflorian 	int		cur_hl;			/* current hop limit */
9653293e44Sflorian 	int		m_flag;			/* managed address conf flag */
9753293e44Sflorian 	int		o_flag;			/* other conf flag */
98639a58baSflorian 	int		rtpref;			/* router preference */
9953293e44Sflorian 	int		router_lifetime;	/* default router lifetime */
10053293e44Sflorian 	uint32_t	reachable_time;
10153293e44Sflorian 	uint32_t	retrans_timer;
10230ca3407Sflorian 	int		source_link_addr;	/* source link-layer address */
103cea17583Sbket 	uint32_t	mtu;
1048815eebdSflorian 	uint32_t	rdns_lifetime;
1058815eebdSflorian 	SIMPLEQ_HEAD(, ra_rdnss_conf)		 ra_rdnss_list;
1068815eebdSflorian 	int		rdnss_count;
1078815eebdSflorian 	SIMPLEQ_HEAD(, ra_dnssl_conf)		 ra_dnssl_list;
1088815eebdSflorian 	int		dnssl_len;
1095207bb19Sflorian 	SIMPLEQ_HEAD(, ra_pref64_conf)		 ra_pref64_list;
11053293e44Sflorian };
11153293e44Sflorian 
11253293e44Sflorian /* RFC 4861 Section 4.6.2 */
11353293e44Sflorian struct ra_prefix_conf {
11453293e44Sflorian 	SIMPLEQ_ENTRY(ra_prefix_conf)	 entry;
11553293e44Sflorian 	struct in6_addr			 prefix;	/* prefix */
11653293e44Sflorian 	int				 prefixlen;	/* prefix length */
11753293e44Sflorian 	uint32_t			 vltime;	/* valid lifetime */
1183a50f0a9Sjmc 	uint32_t			 pltime;	/* preferred lifetime */
11920fc6e8eSflorian 	int				 ltime_decaying;
12053293e44Sflorian 	int				 lflag;		/* on-link flag*/
12153293e44Sflorian 	int				 aflag;		/* autonom. addr flag */
12253293e44Sflorian };
12353293e44Sflorian 
12453293e44Sflorian struct ra_iface_conf {
12553293e44Sflorian 	SIMPLEQ_ENTRY(ra_iface_conf)		 entry;
12653293e44Sflorian 	struct ra_options_conf			 ra_options;
12753293e44Sflorian 	struct ra_prefix_conf			*autoprefix;
12853293e44Sflorian 	SIMPLEQ_HEAD(ra_prefix_conf_head,
12953293e44Sflorian 	    ra_prefix_conf)			 ra_prefix_list;
13053293e44Sflorian 	char					 name[IF_NAMESIZE];
13153293e44Sflorian };
13253293e44Sflorian 
13353293e44Sflorian struct rad_conf {
13453293e44Sflorian 	struct ra_options_conf				 ra_options;
13553293e44Sflorian 	SIMPLEQ_HEAD(ra_iface_conf_head, ra_iface_conf)	 ra_iface_list;
13653293e44Sflorian };
13753293e44Sflorian 
13853293e44Sflorian struct imsg_ra_rs {
13953293e44Sflorian 	uint32_t		if_index;
14053293e44Sflorian 	struct sockaddr_in6	from;
14153293e44Sflorian 	ssize_t			len;
14253293e44Sflorian 	uint8_t			packet[1500];
14353293e44Sflorian };
14453293e44Sflorian 
14553293e44Sflorian struct imsg_send_ra {
14653293e44Sflorian 	uint32_t		if_index;
14753293e44Sflorian 	struct sockaddr_in6	to;
14853293e44Sflorian };
14953293e44Sflorian 
15053293e44Sflorian extern uint32_t	 cmd_opts;
15153293e44Sflorian 
15253293e44Sflorian /* rad.c */
153e88dba76Sflorian int	main_imsg_compose_frontend(int, int, void *, uint16_t);
15453293e44Sflorian void	main_imsg_compose_engine(int, pid_t, void *, uint16_t);
15553293e44Sflorian void	merge_config(struct rad_conf *, struct rad_conf *);
15653293e44Sflorian void	imsg_event_add(struct imsgev *);
15753293e44Sflorian int	imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
15853293e44Sflorian 	    int, void *, uint16_t);
15953293e44Sflorian 
16053293e44Sflorian struct rad_conf	*config_new_empty(void);
16153293e44Sflorian void		 config_clear(struct rad_conf *);
1622ef977c0Sflorian void		 free_ra_iface_conf(struct ra_iface_conf *);
1638815eebdSflorian void		 free_dns_options(struct ra_options_conf *);
16453293e44Sflorian void		 mask_prefix(struct in6_addr*, int len);
16553293e44Sflorian const char	*sin6_to_str(struct sockaddr_in6 *);
16653293e44Sflorian const char	*in6_to_str(struct in6_addr *);
16753293e44Sflorian 
16853293e44Sflorian /* printconf.c */
16953293e44Sflorian void	print_config(struct rad_conf *);
17053293e44Sflorian 
17153293e44Sflorian /* parse.y */
17253293e44Sflorian struct rad_conf	*parse_config(char *);
17353293e44Sflorian int			 cmdline_symset(char *);
174