xref: /titanic_41/usr/src/uts/common/sys/iscsit/radius_packet.h (revision c9a6ea2e938727c95af7108c5e00eee4c890c7ae)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_RADIUS_PACKET_H
27 #define	_RADIUS_PACKET_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <netinet/in.h>
34 #include <sys/types.h>
35 #include <sys/ksocket.h>
36 #include <sys/iscsit/radius_protocol.h>
37 
38 /* A total of RAD_RCV_TIMEOUT * RAD_RETRY_MAX seconds timeout. */
39 #define	RAD_RCV_TIMEOUT 5	/* Timeout for receiving RADIUS packet in */
40 				/*   sec. */
41 #define	RAD_RETRY_MAX   2	/* Max. # of times to retry receiving */
42 				/*   packet. */
43 
44 /* Describes a RADIUS attribute */
45 typedef struct radius_attr {
46 	int	attr_type_code; /* RADIUS attribute type code, */
47 				/*   e.g. RAD_USER_PASSWORD, etc. */
48 	int	attr_value_len;
49 	uint8_t	attr_value[MAX_RAD_ATTR_VALUE_LEN];
50 } radius_attr_t;
51 
52 /* Describes data fields of a RADIUS packet. */
53 typedef struct radius_packet_data {
54 	uint8_t		code;	/* RADIUS code, section 3, RFC 2865. */
55 	uint8_t		identifier;
56 	uint8_t		authenticator[RAD_AUTHENTICATOR_LEN];
57 	int		num_of_attrs;
58 	radius_attr_t attrs[4]; /* For this implementation each */
59 				/*   outbound RADIUS packet will only */
60 				/*   have 3 attributes associated with */
61 				/*   it thus the chosen size should be */
62 				/*   good enough. */
63 } radius_packet_data_t;
64 
65 /*
66  * Send a request to a RADIUS server.
67  *
68  * Returns > 0 on success, <= 0 on failure .
69  *
70  */
71 int
72 iscsit_snd_radius_request(ksocket_t socket,
73     iscsi_ipaddr_t rsvr_ip_addr,
74     uint32_t rsvr_port,
75     radius_packet_data_t *packet_data);
76 
77 #define	RAD_RSP_RCVD_SUCCESS		0
78 #define	RAD_RSP_RCVD_NO_DATA		1
79 #define	RAD_RSP_RCVD_TIMEOUT		2
80 #define	RAD_RSP_RCVD_PROTOCOL_ERR	3
81 #define	RAD_RSP_RCVD_AUTH_FAILED	4
82 /*
83  * Receives a response from a RADIUS server.
84  *
85  * Return receive status.
86  */
87 int
88 iscsit_rcv_radius_response(ksocket_t socket,
89     uint8_t *shared_secret,
90     uint32_t shared_secret_len,
91     uint8_t *req_authenticator,
92     radius_packet_data_t *resp_data);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif /* _RADIUS_PACKET_H */
99