annotate extensions/app_radgw/rgwx_sample.c @ 377:7c0ddec9ab42

Added comment about sessions
author Sebastien Decugis <sdecugis@nict.go.jp>
date Mon, 05 Jul 2010 14:36:50 +0900
parents e203fc0c95e3
children 4a9f08d6b6ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
258
5df55136361b Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 256
diff changeset
5 * Copyright (c) 2010, WIDE Project and NICT *
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
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 *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
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 *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
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 *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
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 *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
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 *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
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 *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
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 *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /* Sample radius/diameter gateway plugin, for developers to see the structure of a plugin. */
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 #include "rgw_common.h"
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 /* The state of this extension */
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 struct rgwp_config {
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 /* In a real extension, we would store the parsed configuration file, and the states of the extension */
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
43 int init;
377
7c0ddec9ab42 Added comment about sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 356
diff changeset
44
7c0ddec9ab42 Added comment about sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 356
diff changeset
45 /* If needed to store information between sent Diameter request and received answer, the session is probably the best place.
7c0ddec9ab42 Added comment about sessions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 356
diff changeset
46 See rgwx_echodrop for an example. */
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47 };
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49 /* The function called at plugin initialization */
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
50 static int sample_conf_parse ( char * conf_file, struct rgwp_config ** state )
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 {
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
52 TRACE_ENTRY("%p %p", conf_file, state);
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
53 CHECK_PARAMS(state);
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
55 CHECK_MALLOC( *state = malloc(sizeof(struct rgwp_config)) );
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
57 (*state)->init = 1;
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
59 return 0;
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 }
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 /* This function is called when the plugin is unloaded, to cleanup all the states */
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
63 static void sample_conf_free(struct rgwp_config * state)
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 {
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
65 TRACE_ENTRY("%p", state);
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
66 CHECK_PARAMS_DO( state, );
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
67 free(state);
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 return;
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 }
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 /* This function is called on incoming RADIUS messages. It should handle (some) RADIUS data and store into the Diameter message. */
356
e203fc0c95e3 Updated the app_radgw extension to allow more souple management of sessions, and stateful gateway features.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
72 static int sample_rad_req( struct rgwp_config * cs, struct session ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 {
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 CHECK_PARAMS(cs);
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 TRACE_DEBUG(INFO, "RADIUS/Diameter Sample plugin received a new RADIUS message.");
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77 return 0;
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 }
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 /* This function is called when a Diameter answer is coming back. It should remove the AVPs and add the attributes in the RADIUS message. */
356
e203fc0c95e3 Updated the app_radgw extension to allow more souple management of sessions, and stateful gateway features.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
81 static int sample_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful )
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 {
356
e203fc0c95e3 Updated the app_radgw extension to allow more souple management of sessions, and stateful gateway features.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
83 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, diam_ans, rad_fw, cli, stateful);
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84 CHECK_PARAMS(cs);
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 TRACE_DEBUG(INFO, "RADIUS/Diameter Sample plugin received a new Diameter answer.");
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 return 0;
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 }
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90 /* Finally, we declare the structure that will be loaded by main RADIUS/Diameter gateway extension */
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91 struct rgw_api rgwp_descriptor = {
256
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
92 .rgwp_name = "sample",
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
93 .rgwp_conf_parse = sample_conf_parse,
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
94 .rgwp_conf_free = sample_conf_free,
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
95 .rgwp_rad_req = sample_rad_req,
042af0000c0a Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 255
diff changeset
96 .rgwp_diam_ans = sample_diam_ans
255
cb4307a1cd29 Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 };
"Welcome to our mercurial repository"