Mercurial > hg > waaad
annotate extensions/radius_gw/rgw_work.c @ 419:fc0d723c1f8b
Added conversion of Diameter answers to RADIUS
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 23 Jun 2009 11:32:45 +0900 |
parents | 8155408c6dc5 |
children | 89e0afe61a52 |
rev | line source |
---|---|
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
371
e86dba02630a
Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
365
diff
changeset
|
5 * Copyright (c) 2009, WIDE Project and NICT * |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 /* Manage incoming RADIUS message. */ |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
38 #include "radius_gw.h" |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
39 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
40 /* How many threads to work on messages ? */ |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
41 #define NB_WORKERS 2 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
42 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
43 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
44 static pthread_mutex_t work_mtx = PTHREAD_MUTEX_INITIALIZER; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
45 static pthread_cond_t work_cond = PTHREAD_COND_INITIALIZER; |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
46 static sess_reg_t * sess_hdl = NULL; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
47 static pthread_t workers[NB_WORKERS]; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
48 static struct rg_list work_data; |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
49 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
50 /* List of pending messages to be handled */ |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 struct work_item { |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
52 struct rg_list chain; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
53 struct rgw_radius_msg_meta * msg; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
54 struct rgw_client * cli; |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
55 }; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
56 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
57 /* Structure stored in waaad when waiting for a Diameter answer */ |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
58 struct pending_answer { |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
59 struct rgw_radius_msg_meta * rad; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
60 struct rgw_client * cli; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
61 sess_id_t * sess; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
62 }; |
360
2206c7f2945a
Added md5 code to check authenticator
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
357
diff
changeset
|
63 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
64 /* Callback when a Diameter answer is received */ |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
65 static void work_receive_diam_answer(void * paback, msg_t **ans) |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
66 { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
67 struct pending_answer * pa = (struct pending_answer *)paback; |
418
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
68 struct radius_msg * rad_ans; |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
69 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
70 TRACE_ENTRY("%p %p", pa, ans); |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
71 CHECK_PARAMS_DO( pa && ans, return ); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
72 |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
73 /* Create an empty RADIUS answer message */ |
419
fc0d723c1f8b
Added conversion of Diameter answers to RADIUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
418
diff
changeset
|
74 CHECK_MALLOC_DO( rad_ans = radius_msg_new(0, pa->rad->radius.hdr->identifier), goto out ); |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
75 |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
76 /* Pass the Diameter answer to the same extensions as the request */ |
418
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
77 CHECK_FCT_DO( rgw_extensions_loop_ans(pa->rad, pa->sess, ans, &rad_ans, pa->cli), goto out ); |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
78 |
419
fc0d723c1f8b
Added conversion of Diameter answers to RADIUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
418
diff
changeset
|
79 /* Now check what AVPs remain in the diameter answer. If AVPs with the 'M' flag are here, we have a problem... */ |
fc0d723c1f8b
Added conversion of Diameter answers to RADIUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
418
diff
changeset
|
80 ASSERT(0); |
fc0d723c1f8b
Added conversion of Diameter answers to RADIUS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
418
diff
changeset
|
81 |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
82 /* Now try and send the RADIUS answer */ |
418
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
83 if (rad_ans) { |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
84 CHECK_FCT_DO( rgw_client_finish_send(&rad_ans, pa->rad, pa->cli), goto out); |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
85 } |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
86 |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
87 out: |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
88 /* Destroy remaining session data (stateless gateway) */ |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
89 CHECK_FCT_DO( sess_destroy(&pa->sess), ); |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
90 |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
91 /* Clear the Diameter message */ |
418
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
92 if (*ans) { |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
93 CHECK_FCT_DO( msg_free(*ans, 1), ); |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
94 *ans = NULL; |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
95 } |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
96 |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
97 /* Release reference on the client */ |
8155408c6dc5
Added early handling of Diameter answers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
417
diff
changeset
|
98 rgw_clients_dispose(&pa->cli); |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
99 |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
100 /* Clear the answer data */ |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
101 free(pa); |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
102 |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
103 /* Finished */ |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
104 return; |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
105 } |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
106 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
107 /* Worker thread, processing incoming RADIUS messages (after parsing) */ |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
108 static void * work_th(void * arg) |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
109 { |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
110 char thname[10]; |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
111 |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
112 TRACE_ENTRY("%p", arg); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
113 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
114 snprintf(thname, sizeof(thname), "worker #%d", (int)arg); |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
115 THREAD_NAME(thname); |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
116 |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
117 while (1) { /* The thread will be cancelled */ |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
118 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
119 struct rgw_radius_msg_meta * msg; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
120 struct rgw_client * cli; |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
121 struct work_item * wi; |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
122 sess_id_t * session; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
123 msg_t * diam_msg; |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
124 int pb, a; |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
125 struct pending_answer * pa; |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
126 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
127 /* Wait for the next incoming RADIUS message */ |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
128 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
129 CHECK_POSIX_DO( pthread_mutex_lock(&work_mtx), break ); |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
130 pthread_cleanup_push(rg_cleanup_mutex, &work_mtx); |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
131 while (rg_list_is_empty(&work_data)) { |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
132 CHECK_POSIX_DO( pthread_cond_wait( &work_cond, &work_mtx ), |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
133 { |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
134 pthread_mutex_unlock(&work_mtx); |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
135 return NULL; |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
136 } ); |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
137 } |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
138 wi = (struct work_item *)(work_data.next); |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
139 rg_list_unlink(&wi->chain); |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
140 msg = wi->msg; |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
141 cli = wi->cli; |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
142 free(wi); |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
143 pthread_cleanup_pop(0); |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
144 CHECK_POSIX_DO( pthread_mutex_unlock(&work_mtx), break ); |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
145 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
146 TRACE_DEBUG(ANNOYING, "Processing next RADIUS message: %p received on client: %p", msg, cli); |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
147 |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
148 /* process the data */ |
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
149 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
150 /* Check authenticator, if any */ |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
151 CHECK_FCT_DO( rgw_msg_auth_check(msg, cli, NULL), |
360
2206c7f2945a
Added md5 code to check authenticator
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
357
diff
changeset
|
152 { |
361
fbe54f8d535e
Added some metadata in the radius messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
360
diff
changeset
|
153 /* An error occurred, discard message */ |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
154 rgw_msg_free(&msg); |
360
2206c7f2945a
Added md5 code to check authenticator
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
357
diff
changeset
|
155 rgw_clients_dispose(&cli); |
2206c7f2945a
Added md5 code to check authenticator
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
357
diff
changeset
|
156 continue; |
2206c7f2945a
Added md5 code to check authenticator
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
357
diff
changeset
|
157 } ); |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
158 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
159 /* Check duplicate */ |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
160 CHECK_FCT_DO( rgw_clients_check_dup(&msg, cli), |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
161 { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
162 /* An error occurred, discard message */ |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
163 rgw_msg_free(&msg); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
164 rgw_clients_dispose(&cli); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
165 continue; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
166 } ); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
167 if (msg == NULL) { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
168 rgw_clients_dispose(&cli); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
169 continue; /* the message was a duplicate */ |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
170 } |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
171 |
385
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
172 /* Check that IP is coherent with the identity in the message */ |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
173 CHECK_FCT_DO( rgw_clients_check_origin(msg, cli), |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
174 { |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
175 /* An error occurred, discard message */ |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
176 rgw_msg_free(&msg); |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
177 rgw_clients_dispose(&cli); |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
178 continue; |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
179 } ); |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
180 |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
181 /* Note: after this point, the radius message buffer may not be consistent with the array of attributes anymore! */ |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
182 |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
183 session = NULL; |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
184 diam_msg = NULL; |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
185 |
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
186 /* Create the session and an empty message with some common AVPs */ |
385
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
187 CHECK_FCT_DO( rgw_msg_create_base(msg, cli, &session, &diam_msg), |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
188 { |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
189 /* An error occurred, discard message */ |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
190 rgw_msg_free(&msg); |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
191 rgw_clients_dispose(&cli); |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
192 continue; |
03b512313cc1
Added code to handle sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
374
diff
changeset
|
193 } ); |
374
883330e610e1
Progress on the echo_drop sub extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
371
diff
changeset
|
194 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
195 /* Pass the message to the list of registered extensions */ |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
196 CHECK_FCT_DO( rgw_extensions_loop_req(&msg, &session, &diam_msg, cli), |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
197 { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
198 /* An error occurred, discard message */ |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
199 rgw_msg_free(&msg); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
200 rgw_clients_dispose(&cli); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
201 continue; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
202 } ); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
203 if (msg == NULL) { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
204 rgw_clients_dispose(&cli); |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
205 continue; /* the message was handled already */ |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
206 } |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
207 |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
208 pb = 0; |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
209 |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
210 /* Check the created Diameter message */ |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
211 if ((diam_msg == NULL) || ( msg_parse_rules(diam_msg, NULL) ) ) { |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
212 log_error("No or invalid Diameter generated after processing of RADIUS command %hhd (%s).\n" |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
213 " Turn on advanced log for detail.\n", |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
214 msg->radius.hdr->code, rgw_msg_code_str(msg->radius.hdr->code)); |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
215 /* We might also dump the conflicting rule here if useful */ |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
216 pb++; |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
217 } |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
218 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
219 /* Check if the full content of the RADIUS message was handled */ |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
220 for (a = 0; a < msg->radius.attr_used; a++) { |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
221 struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[a]); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
222 pb++; |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
223 log_error("No extension available to handle attribute %hhd (%s) in command %hhd (%s)!\n", |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
224 attr->type, rgw_msg_attrtype_str(attr->type), |
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
225 msg->radius.hdr->code, rgw_msg_code_str(msg->radius.hdr->code)); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
226 } |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
227 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
228 /* Check the session is correct */ |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
229 if (session == NULL) { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
230 log_error("No session has been created to store RADIUS state (command %hhd (%s)).\n" |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
231 " Please check your configuration and documentation.\n", |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
232 msg->radius.hdr->code, rgw_msg_code_str(msg->radius.hdr->code)); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
233 pb++; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
234 } |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
235 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
236 if (pb) { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
237 /* Something went wrong during the conversion */ |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
238 if (session) { |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
239 CHECK_FCT_DO( sess_destroy(&session), ); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
240 } |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
241 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
242 if (diam_msg) { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
243 CHECK_FCT_DO( msg_free(diam_msg, 1), ); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
244 diam_msg = NULL; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
245 } |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
246 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
247 rgw_msg_free(&msg); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
248 rgw_clients_dispose(&cli); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
249 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
250 TRACE_DEBUG(INFO, "%d problem(s) occurred while translating a RADIUS message, data discarded.\n", pb); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
251 continue; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
252 } |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
253 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
254 /* Send the radius message and register for answer */ |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
255 CHECK_MALLOC_DO( pa = malloc(sizeof(struct pending_answer)), break ); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
256 memset(pa, 0, sizeof(*pa)); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
257 pa->rad = msg; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
258 pa->cli = cli; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
259 pa->sess= session; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
260 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
261 CHECK_FCT_DO( msg_send( &diam_msg, work_receive_diam_answer, pa), |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
262 { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
263 /* If an error occurs, log and destroy the data */ |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
264 log_error("An error occurred while sending Diameter message, please turn Debug on for detail.\n"); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
265 if (session) { |
415
540ed390c04f
Added sess_destroy function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
389
diff
changeset
|
266 CHECK_FCT_DO( sess_destroy(&session), ); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
267 } |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
268 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
269 if (diam_msg) { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
270 CHECK_FCT_DO( msg_free(diam_msg, 1), ); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
271 diam_msg = NULL; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
272 } |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
273 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
274 rgw_msg_free(&msg); |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
275 rgw_clients_dispose(&cli); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
276 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
277 free(pa); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
278 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
279 continue; |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
280 } ); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
281 |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
282 /* Done! */ |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
283 } |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
284 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
285 TRACE_DEBUG(INFO, "Error: thread terminated!"); |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
286 return NULL; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
287 } |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
288 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
289 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
290 int rgw_work_start(void) |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
291 { |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
292 int i; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
293 TRACE_ENTRY(); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
294 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
295 CHECK_FCT( sess_regext(&sess_hdl) ); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
296 |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
297 memset(workers, 0, sizeof(workers)); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
298 rg_list_init(&work_data); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
299 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
300 /* Create the worker thread(s) */ |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
301 for (i = 0; i < NB_WORKERS; i++) { |
357
6c2198aa037c
Worker thread pick messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
356
diff
changeset
|
302 CHECK_POSIX( pthread_create(&workers[i], NULL, work_th, (void *)i) ); |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
303 } |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
304 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
305 return 0; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
306 } |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
307 |
365
0146c60af026
Moved to the hostap implementation of RADIUS processing (copied radius.* and md5.* files)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
363
diff
changeset
|
308 int rgw_work_add(struct rgw_radius_msg_meta * msg, struct rgw_client * client) |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
309 { |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
310 struct work_item * new; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
311 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
312 CHECK_MALLOC( new = malloc(sizeof(struct work_item)) ); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
313 memset(new, 0, sizeof(struct work_item)); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
314 rg_list_init(&new->chain); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
315 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
316 new->msg = msg; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
317 new->cli = client; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
318 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
319 CHECK_POSIX( pthread_mutex_lock(&work_mtx) ); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
320 rg_list_insert_before(&work_data, &new->chain); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
321 CHECK_POSIX( pthread_cond_signal(&work_cond) ); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
322 CHECK_POSIX( pthread_mutex_unlock(&work_mtx) ); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
323 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
324 return 0; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
325 } |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
326 |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
327 void rgw_work_fini(void) |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
328 { |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
329 int i; |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
330 TRACE_ENTRY(); |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
331 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
332 for (i = 0; i < NB_WORKERS; i++) { |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
333 rg_thread_term(&workers[i]); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
334 } |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
335 |
363
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
336 CHECK_FCT_DO( sess_deregext(sess_hdl), ); |
9d330bd07134
Progress on the radius_gw gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
362
diff
changeset
|
337 |
356
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
338 return; |
555dc5a58aef
Added server code for radius extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
339 } |