xref: /openbsd/usr.sbin/npppd/npppd/npppd_local.h (revision 9791a9c5)
1 /*	$OpenBSD: npppd_local.h,v 1.19 2024/07/11 14:05:59 yasuoka Exp $ */
2 
3 /*-
4  * Copyright (c) 2009 Internet Initiative Japan Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 #ifndef	_NPPPD_LOCAL_H
29 #define	_NPPPD_LOCAL_H	1
30 
31 #ifndef	NPPPD_BUFSZ
32 /** buffer size */
33 #define	NPPPD_BUFSZ			BUFSZ
34 #endif
35 
36 #include <net/if.h>
37 
38 #include "npppd_defs.h"
39 
40 #include "slist.h"
41 #include "hash.h"
42 #include "debugutil.h"
43 
44 #ifdef	USE_NPPPD_RADIUS
45 #include "radius_req.h"
46 #endif
47 
48 #ifdef	USE_NPPPD_L2TP
49 #include "bytebuf.h"
50 #include "l2tp.h"
51 #endif
52 
53 #ifdef	USE_NPPPD_PPTP
54 #include "bytebuf.h"
55 #include "pptp.h"
56 #endif
57 #ifdef	USE_NPPPD_PPPOE
58 #if defined(__NetBSD__)
59 #include <net/if_ether.h>
60 #else
61 #include <netinet/if_ether.h>
62 #endif
63 #include "bytebuf.h"
64 #include "pppoe.h"
65 #endif
66 #include "npppd_auth.h"
67 #include "npppd.h"
68 #include "npppd_iface.h"
69 
70 #include "privsep.h"
71 
72 #include "addr_range.h"
73 #include "npppd_pool.h"
74 #include "npppd_ctl.h"
75 
76 #ifdef	USE_NPPPD_RADIUS
77 #include "npppd_radius.h"
78 #endif
79 
80 /** structure of pool */
81 struct _npppd_pool {
82 	/** base of npppd structure */
83 	npppd		*npppd;
84 	/** ipcp name */
85 	char		ipcp_name[NPPPD_GENERIC_NAME_LEN];
86 	/** size of sockaddr_npppd array */
87 	int		addrs_size;
88 	/** pointer indicated to sockaddr_npppd array */
89 	struct sockaddr_npppd *addrs;
90 	/** list of addresses dynamically allocated */
91 	slist 		dyna_addrs;
92 	unsigned int	/** whether initialized or not */
93 			initialized:1,
94 			/** whether in use or not */
95 			running:1;
96 };
97 
98 /** structure for control socket. (control.c) */
99 struct control_sock {
100 	const char      *cs_name;
101 	struct event     cs_ev;
102 	struct event     cs_evt;
103 	int              cs_fd;
104 	int              cs_restricted;
105 	void            *cs_ctx;
106 };
107 
108 /**
109  * npppd
110  */
111 struct _npppd {
112 	/** event handler */
113 	struct event ev_sigterm, ev_sigint, ev_sighup, ev_sigchld, ev_timer;
114 
115 	/** interface which concentrates PPP  */
116 	npppd_iface		iface[NPPPD_MAX_IFACE];
117 
118 	npppd_pool		*iface_pool[NPPPD_MAX_IFACE];
119 
120 	/** address pool */
121 	npppd_pool		pool[NPPPD_MAX_POOL];
122 
123 	/** radish pool which uses to manage allocated address */
124 	struct radish_head *rd;
125 
126 	/** map of username to slist of npppd_ppp */
127 	hash_table *map_user_ppp;
128 
129 	/** authentication realms */
130 	slist realms;
131 
132 	/** interval time(in seconds) which finalizes authentication realms */
133 	int auth_finalizer_itvl;
134 
135 	/** name of configuration file */
136 	char 	config_file[PATH_MAX];
137 
138 	/** name of pid file */
139 	char 	pidpath[PATH_MAX];
140 
141 	/** process id */
142 	pid_t	pid;
143 
144 	/** boot identifier */
145 	uint32_t boot_id;
146 
147 #ifdef	USE_NPPPD_L2TP
148 	/** structure of L2TP daemon */
149 	l2tpd l2tpd;
150 #endif
151 #ifdef	USE_NPPPD_PPTP
152 	/** structure of PPTP daemon */
153 	pptpd pptpd;
154 #endif
155 #ifdef	USE_NPPPD_PPPOE
156 	/** structure of PPPOE daemon */
157 	pppoed pppoed;
158 #endif
159 	/** configuration file  */
160 	struct npppd_conf conf;
161 
162 	/** the time in seconds which process was started.*/
163 	uint32_t	secs;
164 
165 	/** delay time in seconds reload configuration */
166 	int16_t		delayed_reload;
167 	/** counter of reload configuration */
168 	int16_t		reloading_count;
169 
170 	int		nsession;
171 
172 	struct ipcpstat_head ipcpstats;
173 
174 	struct control_sock  ctl_sock;
175 
176 #ifdef	USE_NPPPD_RADIUS
177 	struct npppd_radius_dae_listens	raddae_listens;
178 #endif
179 
180 	u_int /** whether finalizing or not */
181 	    finalizing:1,
182 	    /** whether finalize completed or not */
183 	    finalized:1,
184 	    /** npppd stopped itself because of an error. */
185 	    stop_by_error:1;
186 };
187 
188 #define	ppp_iface(ppp)	(&(ppp)->pppd->iface[(ppp)->ifidx])
189 #define	ppp_ipcp(ppp)	((ppp)->pppd->iface[(ppp)->ifidx].ipcpconf)
190 #define	ppp_pool(ppp)	((ppp)->pppd->iface_pool[(ppp)->ifidx])
191 
192 #define	SIN(sa)		((struct sockaddr_in *)(sa))
193 
194 #define	TIMER_TICK_RUP(interval)			\
195 	((((interval) % NPPPD_TIMER_TICK_IVAL) == 0)	\
196 	    ? (interval)				\
197 	    : (interval) + NPPPD_TIMER_TICK_IVAL	\
198 		- ((interval) % NPPPD_TIMER_TICK_IVAL))
199 
200 #endif
201