1 /* $OpenBSD: radius_req.h,v 1.7 2015/07/23 09:04:06 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 /** type for context to handle RADIUS request / response */ 55 typedef void * RADIUS_REQUEST_CTX; 56 57 /** type for callback function to receive the RADIUS response */ 58 typedef void (radius_response)(void *context, RADIUS_PACKET *pkt, int flags, RADIUS_REQUEST_CTX reqctx); 59 60 /** type for setting of RADIUS request */ 61 typedef struct _radius_req_setting 62 { 63 /** RADIUS Servers */ 64 struct { 65 /** Server's address */ 66 union { 67 struct sockaddr_in6 sin6; 68 struct sockaddr_in sin4; 69 } peer; 70 /** Our address */ 71 union { 72 struct sockaddr_in6 sin6; 73 struct sockaddr_in sin4; 74 } sock; 75 char secret[MAX_RADIUS_SECRET]; 76 int enabled; 77 } server[MAX_RADIUS_SERVERS]; 78 /** Index of current server */ 79 int curr_server; 80 /** request timeout(in second) */ 81 int timeout; 82 /** The maximum number of RADIUS request transmission */ 83 int max_tries; 84 /** The maximum number of RADIUS request failover */ 85 int max_failovers; 86 87 /** references by radius request */ 88 int refcnt; 89 /** destroy is requested */ 90 int destroyed; 91 92 } radius_req_setting; 93 94 #ifdef __cplusplus 95 extern "C" { 96 #endif 97 98 void radius_request (RADIUS_REQUEST_CTX, RADIUS_PACKET *); 99 int radius_prepare_nas_address (radius_req_setting *, RADIUS_PACKET *); 100 int radius_request_can_failover (RADIUS_REQUEST_CTX); 101 int radius_request_failover (RADIUS_REQUEST_CTX); 102 int radius_prepare (radius_req_setting *, void *, RADIUS_REQUEST_CTX *, radius_response); 103 void radius_cancel_request (RADIUS_REQUEST_CTX); 104 const char *radius_get_server_secret (RADIUS_REQUEST_CTX); 105 struct sockaddr *radius_get_server_address (RADIUS_REQUEST_CTX); 106 radius_req_setting *radius_req_setting_create (void); 107 int radius_req_setting_has_server(radius_req_setting *); 108 void radius_req_setting_destroy (radius_req_setting *); 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif 115