1 /* $OpenBSD: npppd.h,v 1.19 2017/08/12 11:20:34 goda 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_H 29 #define NPPPD_H 1 30 31 32 #include <sys/queue.h> 33 #include <sys/socket.h> 34 #include <stdbool.h> 35 #include <net/if.h> 36 #include <net/if_dl.h> 37 #include <netinet/in.h> 38 #include <event.h> 39 #include <limits.h> 40 41 #include "addr_range.h" 42 43 #include "l2tp_conf.h" 44 #include "pptp_conf.h" 45 #include "pppoe_conf.h" 46 47 #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) 48 #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) 49 50 #define NPPPD_USER "_ppp" 51 #define NPPPD_GENERIC_NAME_LEN 32 52 53 /** Constants of tunnel type */ 54 #define NPPPD_TUNNEL_NONE 0 /** None Tunnel Type */ 55 #define NPPPD_TUNNEL_L2TP 1 /** L2TP Tunnel Type */ 56 #define NPPPD_TUNNEL_PPTP 2 /** PPTP Tunnel Type */ 57 #define NPPPD_TUNNEL_PPPOE 3 /** PPPoE Tunnel Type */ 58 #define NPPPD_TUNNEL_SSTP 4 /** SSTP Tunnel Type */ 59 60 #define npppd_pipex_proto(_tunnel) \ 61 (((_tunnel) == NPPPD_TUNNEL_L2TP)? PIPEX_PROTO_L2TP : \ 62 ((_tunnel) == NPPPD_TUNNEL_PPTP)? PIPEX_PROTO_PPTP : \ 63 ((_tunnel) == NPPPD_TUNNEL_PPPOE)? PIPEX_PROTO_PPPOE : -1) 64 65 #define NPPPD_AUTH_METHODS_PAP 0x0001 66 #define NPPPD_AUTH_METHODS_CHAP 0x0002 67 #define NPPPD_AUTH_METHODS_MSCHAPV2 0x0004 68 69 #define NPPPD_MPPE_DISABLED 0x0000 70 #define NPPPD_MPPE_ENABLED 0x0001 71 #define NPPPD_MPPE_REQUIRED 0x0002 72 73 #define NPPPD_MPPE_40BIT 0x0001 74 #define NPPPD_MPPE_56BIT 0x0002 75 #define NPPPD_MPPE_128BIT 0x0004 76 77 #define NPPPD_MPPE_STATEFUL 0x0001 78 #define NPPPD_MPPE_STATELESS 0x0002 79 80 #define NPPPD_PROTO_BIT_IP 0x0001 81 #define NPPPD_PROTO_BIT_LCP 0x0002 82 #define NPPPD_PROTO_BIT_PAP 0x0004 83 #define NPPPD_PROTO_BIT_CHAP 0x0008 84 #define NPPPD_PROTO_BIT_EAP 0x0010 85 #define NPPPD_PROTO_BIT_MPPE 0x0020 86 #define NPPPD_PROTO_BIT_CCP 0x0040 87 #define NPPPD_PROTO_BIT_IPCP 0x0080 88 89 #define NPPPD_CALLNUM_CHECK_NONE 0 90 #define NPPPD_CALLNUM_CHECK_STRICT 1 91 #define NPPPD_CALLNUM_CHECK_LOOSE 2 92 93 struct tunnconf { 94 TAILQ_ENTRY(tunnconf) entry; 95 const char *name; 96 int protocol; 97 98 union { 99 struct l2tp_conf l2tp; 100 struct pptp_conf pptp; 101 struct pppoe_conf pppoe; 102 } proto; 103 104 int lcp_timeout; 105 int lcp_max_configure; 106 int lcp_max_terminate; 107 int lcp_max_nak_loop; 108 int mru; 109 bool lcp_keepalive; 110 int lcp_keepalive_interval; 111 int lcp_keepalive_retry_interval; 112 int lcp_keepalive_max_retries; 113 114 u_int auth_methods; 115 116 int ipcp_timeout; 117 int ipcp_max_configure; 118 int ipcp_max_terminate; 119 int ipcp_max_nak_loop; 120 int ccp_timeout; 121 int ccp_max_configure; 122 int ccp_max_terminate; 123 int ccp_max_nak_loop; 124 char *chap_name; 125 126 bool mppe_yesno; 127 bool mppe_required; 128 u_int mppe_keylen; 129 u_int mppe_keystate; 130 131 int idle_timeout; 132 bool tcp_mss_adjust; 133 bool ingress_filter; 134 int callnum_check; 135 136 bool pipex; 137 138 u_int debug_dump_pktin; 139 u_int debug_dump_pktout; 140 }; 141 142 struct radserver { 143 TAILQ_ENTRY(radserver) entry; 144 struct sockaddr_storage address; 145 char *secret; 146 }; 147 148 struct radconf { 149 TAILQ_HEAD(radservers, radserver) servers; 150 int timeout; 151 int max_tries; 152 int max_failovers; 153 }; 154 155 struct authconf { 156 TAILQ_ENTRY(authconf) entry; 157 char name[NPPPD_GENERIC_NAME_LEN]; 158 int auth_type; 159 char *username_suffix; 160 bool eap_capable; 161 bool strip_nt_domain; 162 bool strip_atmark_realm; 163 char users_file_path[PATH_MAX]; 164 int user_max_session; 165 union { 166 struct { 167 struct radconf auth; 168 struct radconf acct; 169 } radius; 170 } data; 171 }; 172 173 struct ipcpconf { 174 TAILQ_ENTRY(ipcpconf) entry; 175 char name[NPPPD_GENERIC_NAME_LEN]; 176 bool dns_use_resolver; 177 struct in_addr dns_servers[2]; 178 struct in_addr nbns_servers[2]; 179 bool allow_user_select; 180 struct in_addr_range *dynamic_pool; 181 struct in_addr_range *static_pool; 182 int max_session; 183 }; 184 185 struct iface { 186 TAILQ_ENTRY(iface) entry; 187 char name[IFNAMSIZ]; 188 struct in_addr ip4addr; 189 struct ipcpconf *ipcpconf; 190 bool is_pppx; 191 }; 192 193 struct confbind { 194 TAILQ_ENTRY(confbind) entry; 195 struct tunnconf *tunnconf; 196 struct authconf *authconf; 197 struct iface *iface; 198 }; 199 200 struct npppd_conf { 201 int max_session; 202 int user_max_session; 203 TAILQ_HEAD(tunnconfs, tunnconf) tunnconfs; 204 TAILQ_HEAD(authconfs, authconf) authconfs; 205 TAILQ_HEAD(ipcpconfs, ipcpconf) ipcpconfs; 206 TAILQ_HEAD(ifaces, iface) ifaces; 207 TAILQ_HEAD(confbinds, confbind) confbinds; 208 struct l2tp_confs l2tp_confs; 209 struct pptp_confs pptp_confs; 210 struct pppoe_confs pppoe_confs; 211 }; 212 213 /** sockaddr_npppd */ 214 struct sockaddr_npppd { 215 struct sockaddr_in sin4; 216 struct sockaddr_in sin4mask; 217 #define snp_len sin4.sin_len 218 #define snp_family sin4.sin_family 219 #define snp_addr sin4.sin_addr 220 int snp_type; /* SNP_POOL or SNP_PPP */ 221 #define snp_mask sin4mask.sin_addr 222 /** next entry */ 223 struct sockaddr_npppd *snp_next; 224 /** contents of entry */ 225 void *snp_data_ptr; 226 }; 227 #define SNP_POOL 1 228 #define SNP_DYN_POOL 2 229 #define SNP_PPP 3 230 231 struct ipcpstat { 232 LIST_ENTRY(ipcpstat) entry; 233 char name[NPPPD_GENERIC_NAME_LEN]; 234 int nsession; 235 LIST_HEAD(, _npppd_ppp) ppp; 236 }; 237 LIST_HEAD(ipcpstat_head, ipcpstat); 238 239 typedef struct _npppd npppd; 240 241 #include "ppp.h" 242 243 #include <imsg.h> 244 245 struct imsgev { 246 struct imsgbuf ibuf; 247 void (*handler)(int, short, void *); 248 struct event ev; 249 void *data; 250 short events; 251 }; 252 253 struct ctl_conn { 254 TAILQ_ENTRY(ctl_conn) entry; 255 struct control_sock *parent; 256 u_int8_t flags; 257 #define CTL_CONN_NOTIFY 0x01 258 #define CTL_CONN_LOCKED 0x02 /* restricted mode */ 259 struct imsgev iev; 260 void *ctx; 261 }; 262 263 TAILQ_HEAD(ctl_conn_list, ctl_conn); 264 extern struct ctl_conn_list ctl_conns; 265 266 __BEGIN_DECLS 267 npppd *npppd_get_npppd (void); 268 int npppd_init (npppd *, const char *); 269 void npppd_start (npppd *); 270 void npppd_stop (npppd *); 271 void npppd_fini (npppd *); 272 int npppd_reset_routing_table (npppd *, int); 273 int npppd_get_user_password (npppd *, npppd_ppp *, const char *, char *, int *); 274 struct in_addr *npppd_get_user_framed_ip_address (npppd *, npppd_ppp *, const char *); 275 int npppd_check_calling_number (npppd *, npppd_ppp *); 276 npppd_ppp *npppd_get_ppp_by_ip (npppd *, struct in_addr); 277 npppd_ppp *npppd_get_ppp_by_id (npppd *, u_int); 278 int npppd_check_user_max_session (npppd *, npppd_ppp *); 279 void npppd_network_output (npppd *, npppd_ppp *, int, u_char *, int); 280 int npppd_ppp_pipex_enable (npppd *, npppd_ppp *); 281 int npppd_ppp_pipex_disable (npppd *, npppd_ppp *); 282 int npppd_prepare_ip (npppd *, npppd_ppp *); 283 void npppd_release_ip (npppd *, npppd_ppp *); 284 void npppd_set_ip_enabled (npppd *, npppd_ppp *, int); 285 int npppd_assign_ip_addr (npppd *, npppd_ppp *, uint32_t); 286 int npppd_set_radish (npppd *, void *); 287 int npppd_ppp_bind_realm (npppd *, npppd_ppp *, const char *, int); 288 int npppd_ppp_is_realm_local (npppd *, npppd_ppp *); 289 int npppd_ppp_is_realm_radius (npppd *, npppd_ppp *); 290 int npppd_ppp_is_realm_ready (npppd *, npppd_ppp *); 291 const char *npppd_ppp_get_realm_name (npppd *, npppd_ppp *); 292 const char *npppd_ppp_get_iface_name (npppd *, npppd_ppp *); 293 int npppd_ppp_iface_is_ready (npppd *, npppd_ppp *); 294 int npppd_ppp_bind_iface (npppd *, npppd_ppp *); 295 void npppd_ppp_unbind_iface (npppd *, npppd_ppp *); 296 void *npppd_get_radius_auth_setting (npppd *, npppd_ppp *); 297 int sockaddr_npppd_match (void *, void *); 298 const char *npppd_ppp_get_username_for_auth (npppd *, npppd_ppp *, const char *, char *); 299 const char *npppd_ppp_tunnel_protocol_name (npppd *, npppd_ppp *); 300 const char *npppd_tunnel_protocol_name (int); 301 struct tunnconf *npppd_get_tunnconf (npppd *, const char *); 302 int npppd_reload_config (npppd *); 303 int npppd_modules_reload (npppd *); 304 int npppd_ifaces_load_config (npppd *); 305 306 int npppd_conf_parse (struct npppd_conf *, const char *); 307 void npppd_conf_init (struct npppd_conf *); 308 void npppd_conf_fini (struct npppd_conf *); 309 int npppd_config_check (const char *); 310 void npppd_on_ppp_start (npppd *, npppd_ppp *); 311 void npppd_on_ppp_stop (npppd *, npppd_ppp *); 312 void imsg_event_add(struct imsgev *); 313 314 int control_init (struct control_sock *); 315 int control_listen (struct control_sock *); 316 void control_cleanup (struct control_sock *); 317 struct npppd_ctl *npppd_ctl_create (npppd *); 318 void npppd_ctl_destroy (struct npppd_ctl *); 319 int npppd_ctl_who (struct npppd_ctl *); 320 int npppd_ctl_monitor (struct npppd_ctl *); 321 int npppd_ctl_who_and_monitor (struct npppd_ctl *); 322 int npppd_ctl_add_started_ppp_id (struct npppd_ctl *, uint32_t); 323 int npppd_ctl_add_stopped_ppp (struct npppd_ctl *, npppd_ppp *); 324 int npppd_ctl_imsg_compose (struct npppd_ctl *, struct imsgbuf *); 325 int npppd_ctl_disconnect (struct npppd_ctl *, u_int *, int); 326 327 __END_DECLS 328 329 #endif 330