xref: /openbsd-src/usr.sbin/npppd/npppd/radius_req.h (revision 006a08d99c7bf984e1680019458bb87e35aee5df)
1 /*	$OpenBSD: radius_req.h,v 1.8 2024/02/26 08:47:28 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	RADIUS_REQ_H
29 #define	RADIUS_REQ_H 1
30 
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <stdbool.h>
34 #include <radius.h>
35 
36 /** maximum number of length for RADIUS shared secret */
37 #define MAX_RADIUS_SECRET				128
38 
39 /** maximum number of RADIUS server */
40 #define MAX_RADIUS_SERVERS				16
41 
42 /** RADIUS request failed */
43 #define	RADIUS_REQUEST_ERROR				0x0001
44 
45 /** RADIUS request timed out */
46 #define	RADIUS_REQUEST_TIMEOUT				0x0002
47 
48 /** response has valid authenticator */
49 #define	RADIUS_REQUEST_CHECK_AUTHENTICATOR_OK		0x0010
50 
51 /** authenticator is not checked */
52 #define	RADIUS_REQUEST_CHECK_AUTHENTICATOR_NO_CHECK	0x0020
53 
54 /** no message authenticator */
55 #define	RADIUS_REQUEST_CHECK_NO_MSG_AUTHENTICATOR	0x0040
56 
57 /** has valid message authenticator */
58 #define	RADIUS_REQUEST_CHECK_MSG_AUTHENTICATOR_OK	0x0080
59 
60 /** message authenticator is not checked*/
61 #define	RADIUS_REQUEST_CHECK_MSG_AUTHENTICATOR_NO_CHECK	0x0100
62 
63 /** type for context to handle RADIUS request / response */
64 typedef void * RADIUS_REQUEST_CTX;
65 
66 /** type for callback function to receive the RADIUS response */
67 typedef void (radius_response)(void *context, RADIUS_PACKET *pkt, int flags, RADIUS_REQUEST_CTX reqctx);
68 
69 /** type for setting of RADIUS request */
70 typedef struct _radius_req_setting
71 {
72 	/** RADIUS Servers */
73 	struct {
74 		/** Server's address */
75 		union {
76 			struct sockaddr_in6	sin6;
77 			struct sockaddr_in	sin4;
78 		} peer;
79 		/** Our address */
80 		union {
81 			struct sockaddr_in6	sin6;
82 			struct sockaddr_in	sin4;
83 		} sock;
84 		char	secret[MAX_RADIUS_SECRET];
85 		int	enabled;
86 	} server[MAX_RADIUS_SERVERS];
87 	/** Index of current server */
88 	int curr_server;
89 	/** request timeout(in second) */
90 	int timeout;
91 	/** The maximum number of RADIUS request transmission */
92 	int max_tries;
93 	/** The maximum number of RADIUS request failover */
94 	int max_failovers;
95 
96 	/** references by radius request */
97 	int refcnt;
98 	/** destroy is requested */
99 	int destroyed;
100 
101 } radius_req_setting;
102 
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106 
107 void                radius_request (RADIUS_REQUEST_CTX, RADIUS_PACKET *);
108 int                 radius_prepare_nas_address (radius_req_setting *, RADIUS_PACKET *);
109 int                 radius_request_can_failover (RADIUS_REQUEST_CTX);
110 int                 radius_request_failover (RADIUS_REQUEST_CTX);
111 int                 radius_prepare (radius_req_setting *, void *, RADIUS_REQUEST_CTX *, radius_response);
112 void                radius_cancel_request (RADIUS_REQUEST_CTX);
113 const char          *radius_get_server_secret (RADIUS_REQUEST_CTX);
114 struct sockaddr     *radius_get_server_address (RADIUS_REQUEST_CTX);
115 radius_req_setting  *radius_req_setting_create (void);
116 int                 radius_req_setting_has_server(radius_req_setting *);
117 void                radius_req_setting_destroy (radius_req_setting *);
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
123 #endif
124