xref: /openbsd/usr.sbin/npppd/npppd/npppd_local.h (revision 5af055cd)
1 /*	$OpenBSD: npppd_local.h,v 1.16 2016/03/08 01:38:04 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 /** structure of pool */
77 struct _npppd_pool {
78 	/** base of npppd structure */
79 	npppd		*npppd;
80 	/** ipcp name */
81 	char		ipcp_name[NPPPD_GENERIC_NAME_LEN];
82 	/** size of sockaddr_npppd array */
83 	int		addrs_size;
84 	/** pointer indicated to sockaddr_npppd array */
85 	struct sockaddr_npppd *addrs;
86 	/** list of addresses dynamically allocated */
87 	slist 		dyna_addrs;
88 	int		/** whether initialized or not */
89 			initialized:1,
90 			/** whether in use or not */
91 			running:1;
92 };
93 
94 /** structure for control socket. (control.c) */
95 struct control_sock {
96 	const char      *cs_name;
97 	struct event     cs_ev;
98 	struct event     cs_evt;
99 	int              cs_fd;
100 	int              cs_restricted;
101 	void            *cs_ctx;
102 };
103 
104 /**
105  * npppd
106  */
107 struct _npppd {
108 	/** event handler */
109 	struct event ev_sigterm, ev_sigint, ev_sighup, ev_sigchld, ev_timer;
110 
111 	/** interface which concentrates PPP  */
112 	npppd_iface		iface[NPPPD_MAX_IFACE];
113 
114 	npppd_pool		*iface_pool[NPPPD_MAX_IFACE];
115 
116 	/** address pool */
117 	npppd_pool		pool[NPPPD_MAX_POOL];
118 
119 	/** radish pool which uses to manage allocated address */
120 	struct radish_head *rd;
121 
122 	/** map of username to slist of npppd_ppp */
123 	hash_table *map_user_ppp;
124 
125 	/** authentication realms */
126 	slist realms;
127 
128 	/** interval time(in seconds) which finalizes authentication realms */
129 	int auth_finalizer_itvl;
130 
131 	/** name of configuration file */
132 	char 	config_file[PATH_MAX];
133 
134 	/** name of pid file */
135 	char 	pidpath[PATH_MAX];
136 
137 	/** process id */
138 	pid_t	pid;
139 
140 	/** boot identifier */
141 	uint32_t boot_id;
142 
143 #ifdef	USE_NPPPD_L2TP
144 	/** structure of L2TP daemon */
145 	l2tpd l2tpd;
146 #endif
147 #ifdef	USE_NPPPD_PPTP
148 	/** structure of PPTP daemon */
149 	pptpd pptpd;
150 #endif
151 #ifdef	USE_NPPPD_PPPOE
152 	/** structure of PPPOE daemon */
153 	pppoed pppoed;
154 #endif
155 	/** configuration file  */
156 	struct npppd_conf conf;
157 
158 	/** the time in seconds which process was started.*/
159 	uint32_t	secs;
160 
161 	/** delay time in seconds reload configuration */
162 	int16_t		delayed_reload;
163 	/** counter of reload configuration */
164 	int16_t		reloading_count;
165 
166 	int		nsession;
167 
168 	struct control_sock  ctl_sock;
169 
170 	u_int /** whether finalizing or not */
171 	    finalizing:1,
172 	    /** whether finalize completed or not */
173 	    finalized:1,
174 	    /** npppd stopped itself because of an error. */
175 	    stop_by_error:1;
176 };
177 
178 #define	ppp_iface(ppp)	(&(ppp)->pppd->iface[(ppp)->ifidx])
179 #define	ppp_ipcp(ppp)	((ppp)->pppd->iface[(ppp)->ifidx].ipcpconf)
180 #define	ppp_pool(ppp)	((ppp)->pppd->iface_pool[(ppp)->ifidx])
181 
182 #define	SIN(sa)		((struct sockaddr_in *)(sa))
183 
184 #define	TIMER_TICK_RUP(interval)			\
185 	((((interval) % NPPPD_TIMER_TICK_IVAL) == 0)	\
186 	    ? (interval)				\
187 	    : (interval) + NPPPD_TIMER_TICK_IVAL	\
188 		- ((interval) % NPPPD_TIMER_TICK_IVAL))
189 
190 #endif
191