annotate extensions/app_radgw/rgw_clients.c @ 519:3f43713be92d

Added flag information in list dump
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 27 Aug 2010 15:28:31 +0900
parents 1c2f5ee38039
children 9b5422e5385c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
258
5df55136361b Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 254
diff changeset
5 * Copyright (c) 2010, WIDE Project and NICT *
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
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 *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
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 *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
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 *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
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 *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
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 *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
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 *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
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 *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /* Manage the list of RADIUS clients, along with their shared secrets. */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 /* Probably some changes are needed to support RADIUS Proxies */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 #include "rgw.h"
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
42 #define REVERSE_DNS_SIZE_MAX 512 /* length of our buffer for reverse DNS */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
43
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44 /* Ordered lists of clients. The order relationship is a memcmp on the address zone.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 For same addresses, the port is compared.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 The same address cannot be added twice, once with a 0-port and once with another port value.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47 */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 static struct fd_list cli_ip = FD_LIST_INITIALIZER(cli_ip);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49 static struct fd_list cli_ip6 = FD_LIST_INITIALIZER(cli_ip6);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 /* Mutex to protect the previous lists */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 static pthread_mutex_t cli_mtx = PTHREAD_MUTEX_INITIALIZER;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 /* Structure describing one client */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 struct rgw_client {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 /* Link information in global list */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 struct fd_list chain;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59 /* Reference count */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 int refcount;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 /* The address and optional port (alloc'd during configuration file parsing). */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 union {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 struct sockaddr *sa; /* generic pointer */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65 struct sockaddr_in *sin;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 struct sockaddr_in6 *sin6;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 };
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 /* The FQDN, realm, and optional aliases */
500
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
70 int is_local; /* true if the RADIUS client runs on the same host -- we use Diameter Identity in that case */
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
71 enum rgw_cli_type type; /* is it a proxy ? */
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 char *fqdn;
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
73 size_t fqdn_len;
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 char *realm;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 char **aliases;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 size_t aliases_nb;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 /* The secret key data. */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 struct {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 unsigned char * data;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81 size_t len;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 } key;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84 /* information of previous msg received, for duplicate checks. */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 struct {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 uint16_t port;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 uint8_t id;
395
8e26b203e3cb Fix issue for buggy RADIUS routeurs that use the same identifier again and again
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 278
diff changeset
88 uint8_t auth[16]; /* we also compare the request authenticator to avoid buggy NASes */
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 struct radius_msg * ans; /* to be able to resend a lost answer */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90 } last[2]; /*[0] for auth, [1] for acct. */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91 };
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95 /* create a new rgw_client. the arguments are moved into the structure (to limit malloc & free calls). */
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
96 static int client_create(struct rgw_client ** res, struct sockaddr ** ip_port, unsigned char ** key, size_t keylen, enum rgw_cli_type type )
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98 struct rgw_client *tmp = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 char buf[255];
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100 int ret;
500
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
101 int loc = 0;
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102
500
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
103 /* Check if the IP address is local */
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
104 if ( ( ((*ip_port)->sa_family == AF_INET ) && ( IN_IS_ADDR_LOOPBACK( &((struct sockaddr_in *)(*ip_port))->sin_addr ) ) )
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
105 ||( ((*ip_port)->sa_family == AF_INET6) && ( IN6_IS_ADDR_LOOPBACK( &((struct sockaddr_in6 *)(*ip_port))->sin6_addr) ) )) {
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
106 /* The client is local */
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
107 loc = 1;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
108 } else {
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
109
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
110 /* Search FQDN for the client */
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
111 ret = getnameinfo( *ip_port, sizeof(struct sockaddr_storage), &buf[0], sizeof(buf), NULL, 0, 0 );
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
112 if (ret) {
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
113 TRACE_DEBUG(INFO, "Unable to resolve peer name: %s", gai_strerror(ret));
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
114 return EINVAL;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
115 }
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 /* Create the new object */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119 CHECK_MALLOC( tmp = malloc(sizeof (struct rgw_client)) );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 memset(tmp, 0, sizeof(struct rgw_client));
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121 fd_list_init(&tmp->chain, NULL);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
122
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
123 tmp->type = type;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
124
500
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
125 if (loc) {
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
126 tmp->is_local = 1;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
127 } else {
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
128 /* Copy the fqdn */
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
129 CHECK_MALLOC( tmp->fqdn = strdup(buf) );
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
130 tmp->fqdn_len = strlen(tmp->fqdn);
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
131 /* Find an appropriate realm */
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
132 tmp->realm = strchr(tmp->fqdn, '.');
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
133 if (tmp->realm)
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
134 tmp->realm += 1;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
135 if ((!tmp->realm) || (*tmp->realm == '\0')) /* in case the fqdn was "localhost." for example, if it is possible... */
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
136 tmp->realm = fd_g_config->cnf_diamrlm;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
137 }
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
138
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
139 /* move the sa info reference */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140 tmp->sa = *ip_port;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141 *ip_port = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 /* move the key material */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144 tmp->key.data = *key;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 tmp->key.len = keylen;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146 *key = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148 /* Done! */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149 *res = tmp;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150 return 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
151 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
152
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154 /* Decrease refcount on a client; the lock must be held when this function is called. */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 static void client_unlink(struct rgw_client * client)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 client->refcount -= 1;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 if (client->refcount <= 0) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160 int idx;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 /* to be sure: the refcount should be 0 only when client_fini is called */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 ASSERT( FD_IS_LIST_EMPTY(&client->chain) );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 /* Free the data */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 for (idx = 0; idx < client->aliases_nb; idx++)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 free(client->aliases[idx]);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 free(client->aliases);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 free(client->fqdn);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 free(client->sa);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170 free(client->key.data);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 free(client);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
173 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
174
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175
500
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
176 /* Macro to avoid duplicating the code in the next function */
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 #define client_search_family( _family_ ) \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178 case AF_INET##_family_: { \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 struct sockaddr_in##_family_ * sin##_family_ = (struct sockaddr_in##_family_ *)ip_port; \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 for (ref = cli_ip##_family_.next; ref != &cli_ip##_family_; ref = ref->next) { \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 cmp = memcmp(&sin##_family_->sin##_family_##_addr, \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 &((struct rgw_client *)ref)->sin##_family_->sin##_family_##_addr, \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 sizeof(struct in##_family_##_addr)); \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 if (cmp > 0) continue; /* search further in the list */ \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 if (cmp < 0) break; /* this IP is not in the list */ \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186 /* Now compare the ports as follow: */ \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 /* If the ip_port we are searching does not contain a port, just return the first match result */ \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188 if ( (sin##_family_->sin##_family_##_port == 0) \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 /* If the entry in the list does not contain a port, return it as a match */ \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190 || (((struct rgw_client *)ref)->sin##_family_->sin##_family_##_port == 0) \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191 /* If both ports are equal, it is a match */ \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192 || (sin##_family_->sin##_family_##_port == \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 ((struct rgw_client *)ref)->sin##_family_->sin##_family_##_port)) { \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 *res = (struct rgw_client *)ref; \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 return EEXIST; \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196 } \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 /* Otherwise, the list is ordered by port value (byte order does not matter */ \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198 if (sin##_family_->sin##_family_##_port \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 > ((struct rgw_client *)ref)->sin##_family_->sin##_family_##_port) continue; \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 else break; \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201 } \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202 *res = (struct rgw_client *)(ref->prev); \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
203 return ENOENT; \
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
204 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
205 /* Function to look for an existing rgw_client, or the previous element.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
206 The cli_mtx must be held when calling this function.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 Returns ENOENT if the matching client does not exist, and res points to the previous element in the list.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208 Returns EEXIST if the matching client is found, and res points to this element.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 Returns other error code on other error. */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 static int client_search(struct rgw_client ** res, struct sockaddr * ip_port )
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
211 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 int cmp;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 struct fd_list *ref = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 CHECK_PARAMS(res && ip_port);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217 switch (ip_port->sa_family) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
218 client_search_family()
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219 break;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
220
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221 client_search_family( 6 )
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 break;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 /* We're never supposed to reach this point */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226 ASSERT(0);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227 return EINVAL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230 int rgw_clients_getkey(struct rgw_client * cli, unsigned char **key, size_t *key_len)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
231 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232 CHECK_PARAMS( cli && key && key_len );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233 *key = cli->key.data;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
234 *key_len = cli->key.len;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235 return 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
236 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
237
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
238 int rgw_clients_gettype(struct rgw_client * cli, enum rgw_cli_type *type)
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
239 {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
240 CHECK_PARAMS( cli && type );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
241 *type = cli->type;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
242 return 0;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
243 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
244
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
245
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
246 int rgw_clients_search(struct sockaddr * ip_port, struct rgw_client ** ref)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
247 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
248 int ret = 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
249
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
250 TRACE_ENTRY("%p %p", ip_port, ref);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
251
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
252 CHECK_PARAMS(ip_port && ref);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
253
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
254 CHECK_POSIX( pthread_mutex_lock(&cli_mtx) );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
255
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
256 ret = client_search(ref, ip_port);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
257 if (ret == EEXIST) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
258 (*ref)->refcount ++;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
259 ret = 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
260 } else {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
261 *ref = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
262 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
263
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
264 CHECK_POSIX( pthread_mutex_unlock(&cli_mtx) );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
265
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
266 return ret;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
267 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
268
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
269 int rgw_clients_check_dup(struct rgw_radius_msg_meta **msg, struct rgw_client *cli)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
270 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
271 int idx;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
272
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
273 TRACE_ENTRY("%p %p", msg, cli);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
274
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
275 CHECK_PARAMS( msg && cli );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
276
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
277 if ((*msg)->serv_type == RGW_PLG_TYPE_AUTH)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
278 idx = 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
279 else
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
280 idx = 1;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
281
395
8e26b203e3cb Fix issue for buggy RADIUS routeurs that use the same identifier again and again
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 278
diff changeset
282 if ((cli->last[idx].id == (*msg)->radius.hdr->identifier)
8e26b203e3cb Fix issue for buggy RADIUS routeurs that use the same identifier again and again
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 278
diff changeset
283 && (cli->last[idx].port == (*msg)->port)
8e26b203e3cb Fix issue for buggy RADIUS routeurs that use the same identifier again and again
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 278
diff changeset
284 && !memcmp(&cli->last[idx].auth[0], &(*msg)->radius.hdr->authenticator[0], 16)) {
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
285 /* Duplicate! */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
286 TRACE_DEBUG(INFO, "Received duplicated RADIUS message (id: %02hhx, port: %hu).", (*msg)->radius.hdr->identifier, ntohs((*msg)->port));
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
287 if (cli->last[idx].ans) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
288 /* Resend the answer */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
289 CHECK_FCT_DO( rgw_servers_send((*msg)->serv_type, cli->last[idx].ans->buf, cli->last[idx].ans->buf_used, cli->sa, (*msg)->port), );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
290 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
291 rgw_msg_free(msg);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
292 } else {
278
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
293 /* We have not just received this message already */
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
294 if (cli->last[idx].port == 0) { /* first message from this client */
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
295 /* Just add the new information */
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
296 ASSERT(cli->last[idx].ans == NULL);
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
297 cli->last[idx].id = (*msg)->radius.hdr->identifier;
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
298 cli->last[idx].port = (*msg)->port;
395
8e26b203e3cb Fix issue for buggy RADIUS routeurs that use the same identifier again and again
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 278
diff changeset
299 memcpy(&cli->last[idx].auth[0], &(*msg)->radius.hdr->authenticator[0], 16);
278
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
300 } else {
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
301 /* We have got previous message(s), update the info only if answered already */
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
302 if (cli->last[idx].ans) {
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
303 cli->last[idx].id = (*msg)->radius.hdr->identifier;
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
304 cli->last[idx].port = (*msg)->port;
395
8e26b203e3cb Fix issue for buggy RADIUS routeurs that use the same identifier again and again
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 278
diff changeset
305 memcpy(&cli->last[idx].auth[0], &(*msg)->radius.hdr->authenticator[0], 16);
278
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
306 /* Free the previous answer */
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
307 radius_msg_free(cli->last[idx].ans);
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
308 free(cli->last[idx].ans);
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
309 cli->last[idx].ans = NULL;
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
310 }
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
311 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
312 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
313
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
314 return 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
315 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
316
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
317 /* Check that the NAS-IP-Adress or NAS-Identifier is coherent with the IP the packet was received from */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
318 /* Also update the client list of aliases if needed */
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
319 /* NOTE: This function does nothing if the client is a RADIUS Proxy... */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
320 /* Check if the message has a valid authenticator, and update the meta-data accordingly */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
321 int rgw_clients_auth_check(struct rgw_radius_msg_meta * msg, struct rgw_client * cli, uint8_t * req_auth)
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
322 {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
323 unsigned char * key;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
324 size_t keylen;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
325 int count;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
326
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
327 TRACE_ENTRY("%p %p %p", msg, cli, req_auth);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
328
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
329 CHECK_PARAMS(msg && cli);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
330
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
331 CHECK_FCT(rgw_clients_getkey(cli, &key, &keylen));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
332
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
333 count = radius_msg_count_attr(&msg->radius, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, 0);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
334 if (count > 1) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
335 TRACE_DEBUG(INFO, "Too many Message-Authenticator attributes (%d), discarding message.", count);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
336 return EINVAL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
337 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
338 if (count == 0) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
339 TRACE_DEBUG(FULL, "Message does not contain a Message-Authenticator attributes.");
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
340 msg->valid_mac = 0;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
341 } else {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
342 if (radius_msg_verify_msg_auth( &msg->radius, key, keylen, req_auth )) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
343 TRACE_DEBUG(INFO, "Invalid Message-Authenticator received, discarding message.");
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
344 return EINVAL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
345 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
346 msg->valid_mac = 1;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
347 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
348
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
349 return 0;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
350 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
351
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
352 static struct dict_object * cache_orig_host = NULL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
353 static struct dict_object * cache_orig_realm = NULL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
354 static struct dict_object * cache_route_record = NULL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
355
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
356 int rgw_clients_init(void)
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
357 {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
358 TRACE_ENTRY();
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
359 CHECK_FCT( fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &cache_orig_host, ENOENT) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
360 CHECK_FCT( fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Realm", &cache_orig_realm, ENOENT) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
361 CHECK_FCT( fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Route-Record", &cache_route_record, ENOENT) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
362 return 0;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
363 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
364
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
365
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
366 /* The following function checks if a RADIUS message contains a valid NAS identifier, and initializes an empty Diameter
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
367 message with the appropriate routing information */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
368 int rgw_clients_create_origin(struct rgw_radius_msg_meta *msg, struct rgw_client * cli, struct msg ** diam)
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
369 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
370 int idx;
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
371 int valid_nas_info = 0;
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
372 struct radius_attr_hdr *nas_ip = NULL, *nas_ip6 = NULL, *nas_id = NULL;
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
373 char * oh_str = NULL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
374 char * or_str = NULL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
375 char * rr_str = NULL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
376 char buf[REVERSE_DNS_SIZE_MAX]; /* to store DNS lookups results */
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
377
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
378 struct avp *avp = NULL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
379 union avp_value avp_val;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
380
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
381 TRACE_ENTRY("%p %p %p", msg, cli, diam);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
382 CHECK_PARAMS(msg && cli && diam && (*diam == NULL));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
383
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
384 /* Find the relevant attributes, if any */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
385 for (idx = 0; idx < msg->radius.attr_used; idx++) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
386 struct radius_attr_hdr * attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[idx]);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
387 size_t attr_len = attr->length - sizeof(struct radius_attr_hdr);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
388
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
389 if ((attr->type == RADIUS_ATTR_NAS_IP_ADDRESS) && (attr_len = 4)) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
390 nas_ip = attr;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
391 continue;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
392 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
393
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
394 if ((attr->type == RADIUS_ATTR_NAS_IDENTIFIER) && (attr_len > 0)) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
395 nas_id = attr;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
396 continue;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
397 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
398
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
399 if ((attr->type == RADIUS_ATTR_NAS_IPV6_ADDRESS) && (attr_len = 16)) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
400 nas_ip6 = attr;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
401 continue;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
402 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
403 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
404
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
405 if (!nas_ip && !nas_ip6 && !nas_id) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
406 TRACE_DEBUG(FULL, "The message does not contain any NAS identification attribute.");
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
407
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
408 /* Get information on this peer */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
409 CHECK_FCT( rgw_clients_get_origin(cli, &oh_str, &or_str) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
410
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
411 goto diameter;
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
412 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
413
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
414 /* Check if the message was received from the IP in NAS-IP-Address attribute */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
415 if (nas_ip && (cli->sa->sa_family == AF_INET) && !memcmp(nas_ip+1, &cli->sin->sin_addr, sizeof(struct in_addr))) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
416 TRACE_DEBUG(FULL, "NAS-IP-Address contains the same address as the message was received from.");
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
417 valid_nas_info |= 1;
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
418 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
419 if (nas_ip6 && (cli->sa->sa_family == AF_INET6) && !memcmp(nas_ip6+1, &cli->sin6->sin6_addr, sizeof(struct in6_addr))) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
420 TRACE_DEBUG(FULL, "NAS-IPv6-Address contains the same address as the message was received from.");
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
421 valid_nas_info |= 2;
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
422 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
423
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
424
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
425 /*
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
426 In RADIUS it would be possible for a rogue NAS to forge the NAS-IP-
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
427 Address attribute value. Diameter/RADIUS translation agents MUST
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
428 check a received NAS-IP-Address or NAS-IPv6-Address attribute against
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
429 the source address of the RADIUS packet. If they do not match and
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
430 the Diameter/RADIUS translation agent does not know whether the
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
431 packet was sent by a RADIUS proxy or NAS (e.g., no Proxy-State
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
432 attribute), then by default it is assumed that the source address
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
433 corresponds to a RADIUS proxy, and that the NAS Address is behind
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
434 that proxy, potentially with some additional RADIUS proxies in
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
435 between. The Diameter/RADIUS translation agent MUST insert entries
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
436 in the Route-Record AVP corresponding to the apparent route. This
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
437 implies doing a reverse lookup on the source address and NAS-IP-
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
438 Address or NAS-IPv6-Address attributes to determine the corresponding
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
439 FQDNs.
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
440
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
441 If the source address and the NAS-IP-Address or NAS-IPv6-Address do
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
442 not match, and the Diameter/RADIUS translation agent knows that it is
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
443 talking directly to the NAS (e.g., there are no RADIUS proxies
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
444 between it and the NAS), then the error should be logged, and the
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
445 packet MUST be discarded.
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
446
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
447 Diameter agents and servers MUST check whether the NAS-IP-Address AVP
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
448 corresponds to an entry in the Route-Record AVP. This is done by
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
449 doing a reverse lookup (PTR RR) for the NAS-IP-Address to retrieve
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
450 the corresponding FQDN, and by checking for a match with the Route-
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
451 Record AVP. If no match is found, then an error is logged, but no
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
452 other action is taken.
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
453 */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
454 if (nas_ip || nas_ip6) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
455 if (!valid_nas_info) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
456 if (cli->type == RGW_CLI_NAS) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
457 TRACE_DEBUG(INFO, "Message received with a NAS-IP-Address or NAS-IPv6-Address different \nfrom the sender's. Please configure as Proxy if this is expected.\n Message discarded.");
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
458 return EINVAL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
459 } else {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
460 /* the peer is configured as a proxy, so accept the message */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
461 sSS ss;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
462
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
463 /* In that case, the cli will be stored as Route-Record and the NAS-IP-Address as origin */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
464 if (!cli->is_local) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
465 rr_str = cli->fqdn;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
466 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
467
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
468 /* We must DNS-reverse the NAS-IP*-Address */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
469 memset(&ss, 0 , sizeof(sSS));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
470 if (nas_ip) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
471 sSA4 * sin = (sSA4 *)&ss;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
472 sin->sin_family = AF_INET;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
473 memcpy(&sin->sin_addr, nas_ip + 1, sizeof(struct in_addr));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
474 } else {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
475 sSA6 * sin6 = (sSA6 *)&ss;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
476 sin6->sin6_family = AF_INET6;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
477 memcpy(&sin6->sin6_addr, nas_ip6 + 1, sizeof(struct in6_addr));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
478 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
479 CHECK_SYS_DO( getnameinfo( (sSA *)&ss, sSAlen(&ss), &buf[0], sizeof(buf), NULL, 0, NI_NAMEREQD),
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
480 {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
481 TRACE_DEBUG(INFO, "The NAS-IP*-Address cannot be DNS reversed in order to create the Origin-Host AVP; rejecting the message (translation is impossible).");
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
482 return EINVAL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
483 } );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
484
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
485 oh_str = &buf[0];
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
486 or_str = strchr(oh_str, '.');
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
487 if (or_str) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
488 or_str ++; /* move after the first dot */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
489 if (*or_str == '\0')
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
490 or_str = NULL; /* Discard this realm, we will use the local realm later */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
491 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
492 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
493 } else {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
494 /* The attribute matches the source address, just use this in origin-host */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
495 CHECK_FCT( rgw_clients_get_origin(cli, &oh_str, &or_str) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
496 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
497
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
498 goto diameter; /* we ignore the nas_id in that case */
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
499 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
500
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
501 /* We don't have a NAS-IP*-Address attribute if we are here */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
502 if (cli->is_local) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
503 /* Simple: we use our own configuration */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
504 CHECK_FCT( rgw_clients_get_origin(cli, &oh_str, &or_str) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
505 goto diameter;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
506 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
507
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
508 /* At this point, we only have nas_id, and the client is not local */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
509 ASSERT(nas_id);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
510
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
511 {
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
512 int found, ret;
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
513 struct addrinfo hint, *res, *ptr;
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
514
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
515 /*
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
516 In RADIUS it would be possible for a rogue NAS to forge the NAS-
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
517 Identifier attribute. Diameter/RADIUS translation agents SHOULD
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
518 attempt to check a received NAS-Identifier attribute against the
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
519 source address of the RADIUS packet, by doing an A/AAAA RR query. If
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
520 the NAS-Identifier attribute contains an FQDN, then such a query
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
521 would resolve to an IP address matching the source address. However,
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
522 the NAS-Identifier attribute is not required to contain an FQDN, so
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
523 such a query could fail. If it fails, an error should be logged, but
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
524 no action should be taken, other than a reverse lookup on the source
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
525 address and insert the resulting FQDN into the Route-Record AVP.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
526
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
527 Diameter agents and servers SHOULD check whether a NAS-Identifier AVP
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
528 corresponds to an entry in the Route-Record AVP. If no match is
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
529 found, then an error is logged, but no other action is taken.
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
530 */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
531
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
532 /* first, check if the nas_id is the fqdn of the peer or a known alias */
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
533 if ((cli->fqdn_len == (nas_id->length - sizeof(struct radius_attr_hdr)))
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
534 && (!strncasecmp((char *)(nas_id + 1), cli->fqdn, nas_id->length - sizeof(struct radius_attr_hdr)))) {
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
535 TRACE_DEBUG(FULL, "NAS-Identifier contains the fqdn of the client");
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
536 found = 1;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
537 } else {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
538 for (idx = 0; idx < cli->aliases_nb; idx++) {
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
539 if (((nas_id->length - sizeof(struct radius_attr_hdr)) == strlen(cli->aliases[idx]))
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
540 && (!strncasecmp((char *)(nas_id + 1), cli->aliases[idx], nas_id->length - sizeof(struct radius_attr_hdr)))) {
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
541 TRACE_DEBUG(FULL, "NAS-Identifier valid value found in the cache");
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
542 found = 1;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
543 break;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
544 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
545 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
546 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
547
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
548 if (found) {
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
549 /* The NAS-Identifier matches the source IP */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
550 CHECK_FCT( rgw_clients_get_origin(cli, &oh_str, &or_str) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
551
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
552 goto diameter;
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
553 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
554
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
555 /* Attempt DNS resolution of the identifier */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
556 ASSERT( nas_id->length - sizeof(struct radius_attr_hdr) < sizeof(buf) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
557 memcpy(buf, nas_id + 1, nas_id->length - sizeof(struct radius_attr_hdr));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
558 buf[nas_id->length - sizeof(struct radius_attr_hdr)] = '\0';
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
559
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
560 /* Now check if this alias is valid for this peer */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
561 memset(&hint, 0, sizeof(hint));
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
562 hint.ai_flags = AI_CANONNAME;
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
563 ret = getaddrinfo(buf, NULL, &hint, &res);
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
564 if (ret == 0) {
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
565 strncpy(buf, res->ai_canonname, sizeof(buf));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
566 /* The name was resolved correctly, does it match the IP of the client? */
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
567 for (ptr = res; ptr != NULL; ptr = ptr->ai_next) {
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
568 if (cli->sa->sa_family != ptr->ai_family)
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
569 continue;
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
570 if (memcmp(cli->sa, ptr->ai_addr, sSAlen(cli->sa)))
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
571 continue;
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
572
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
573 found = 1;
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
574 break;
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
575 }
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
576 freeaddrinfo(res);
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
577
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
578 if (!found) {
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
579 if (cli->type == RGW_CLI_NAS) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
580 TRACE_DEBUG(INFO, "The NAS-Identifier value '%.*s' resolves to a different IP than the client's, discarding the message. \nConfigure this client as a Proxy if this message should be valid.",
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
581 nas_id->length - sizeof(struct radius_attr_hdr), nas_id + 1);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
582 return EINVAL;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
583 } else {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
584 /* This identifier matches a different IP, assume it is a proxied message */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
585 if (!cli->is_local) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
586 rr_str = cli->fqdn;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
587 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
588 oh_str = &buf[0]; /* The canonname resolved */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
589 or_str = strchr(oh_str, '.');
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
590 if (or_str) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
591 or_str ++; /* move after the first dot */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
592 if (*or_str == '\0')
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
593 or_str = NULL; /* Discard this realm, we will use the local realm later */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
594 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
595 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
596 } else {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
597 /* It is a valid alias, save it */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
598 CHECK_MALLOC( cli->aliases = realloc(cli->aliases, (cli->aliases_nb + 1) * sizeof(char *)) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
599 CHECK_MALLOC( cli->aliases[cli->aliases_nb + 1] = malloc( 1 + nas_id->length - sizeof(struct radius_attr_hdr) ));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
600 memcpy( cli->aliases[cli->aliases_nb + 1], nas_id + 1, nas_id->length - sizeof(struct radius_attr_hdr));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
601 *(cli->aliases[cli->aliases_nb + 1] + nas_id->length - sizeof(struct radius_attr_hdr)) = '\0';
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
602 cli->aliases_nb ++;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
603 TRACE_DEBUG(FULL, "Saved valid alias for client: '%s' -> '%s'", cli->aliases[cli->aliases_nb + 1], cli->fqdn);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
604 CHECK_FCT( rgw_clients_get_origin(cli, &oh_str, &or_str) );
442
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
605 }
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
606 } else {
02e3976b9163 Attempt at fixing a problem with NAS-Identifier RADIUS attribute handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
607 /* Error resolving the name */
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
608 TRACE_DEBUG(INFO, "NAS-Identifier '%s' cannot be resolved: %s. Ignoring...", buf, gai_strerror(ret));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
609 /* Assume this is a valid identifier for the client */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
610 CHECK_FCT( rgw_clients_get_origin(cli, &oh_str, &or_str) );
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
611 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
612 }
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
613
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
614 /* Now, let's create the empty Diameter message with Origin-Host, -Realm, and Route-Record if needed. */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
615 diameter:
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
616 ASSERT(oh_str); /* If it is not defined here, there is a bug... */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
617 if (!or_str)
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
618 or_str = fd_g_config->cnf_diamrlm; /* Use local realm in that case */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
619
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
620 /* Create an empty Diameter message so that extensions can store their AVPs */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
621 CHECK_FCT( fd_msg_new ( NULL, MSGFL_ALLOC_ETEID, diam ) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
622
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
623 /* Add the Origin-Host as next AVP */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
624 CHECK_FCT( fd_msg_avp_new ( cache_orig_host, 0, &avp ) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
625 memset(&avp_val, 0, sizeof(avp_val));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
626 avp_val.os.data = (unsigned char *)oh_str;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
627 avp_val.os.len = strlen(oh_str);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
628 CHECK_FCT( fd_msg_avp_setvalue ( avp, &avp_val ) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
629 CHECK_FCT( fd_msg_avp_add ( *diam, MSG_BRW_LAST_CHILD, avp) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
630
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
631 /* Add the Origin-Realm as next AVP */
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
632 CHECK_FCT( fd_msg_avp_new ( cache_orig_realm, 0, &avp ) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
633 memset(&avp_val, 0, sizeof(avp_val));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
634 avp_val.os.data = (unsigned char *)or_str;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
635 avp_val.os.len = strlen(or_str);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
636 CHECK_FCT( fd_msg_avp_setvalue ( avp, &avp_val ) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
637 CHECK_FCT( fd_msg_avp_add ( *diam, MSG_BRW_LAST_CHILD, avp) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
638
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
639 if (rr_str) {
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
640 CHECK_FCT( fd_msg_avp_new ( cache_route_record, 0, &avp ) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
641 memset(&avp_val, 0, sizeof(avp_val));
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
642 avp_val.os.data = (unsigned char *)rr_str;
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
643 avp_val.os.len = strlen(rr_str);
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
644 CHECK_FCT( fd_msg_avp_setvalue ( avp, &avp_val ) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
645 CHECK_FCT( fd_msg_avp_add ( *diam, MSG_BRW_LAST_CHILD, avp) );
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
646 }
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
647
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
648 /* Done! */
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
649 return 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
650 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
651
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
652 int rgw_clients_get_origin(struct rgw_client *cli, char **fqdn, char **realm)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
653 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
654 TRACE_ENTRY("%p %p %p", cli, fqdn, realm);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
655 CHECK_PARAMS(cli && fqdn);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
656
500
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
657 if (cli->is_local) {
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
658 *fqdn = fd_g_config->cnf_diamid;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
659 if (realm)
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
660 *realm= fd_g_config->cnf_diamrlm;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
661 } else {
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
662 *fqdn = cli->fqdn;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
663 if (realm)
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
664 *realm= cli->realm;
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
665 }
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
666
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
667 return 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
668 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
669
271
411314907b43 Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 261
diff changeset
670 char * rgw_clients_id(struct rgw_client *cli)
411314907b43 Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 261
diff changeset
671 {
500
d4fc98a3b79c Handle more nicely the local RADIUS clients in the gateway
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 442
diff changeset
672 return cli->is_local ? "(local)" : cli->fqdn;
271
411314907b43 Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 261
diff changeset
673 }
411314907b43 Added translation of Accounting messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 261
diff changeset
674
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
675
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
676 void rgw_clients_dispose(struct rgw_client ** ref)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
677 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
678 TRACE_ENTRY("%p", ref);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
679 CHECK_PARAMS_DO(ref, return);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
680
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
681 CHECK_POSIX_DO( pthread_mutex_lock(&cli_mtx), );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
682 client_unlink(*ref);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
683 *ref = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
684 CHECK_POSIX_DO( pthread_mutex_unlock(&cli_mtx), );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
685 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
686
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
687 int rgw_clients_add( struct sockaddr * ip_port, unsigned char ** key, size_t keylen, enum rgw_cli_type type )
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
688 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
689 struct rgw_client * prev = NULL, *new = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
690 int ret;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
691
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
692 TRACE_ENTRY("%p %p %lu", ip_port, key, keylen);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
693
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
694 CHECK_PARAMS( ip_port && key && *key && keylen );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
695 CHECK_PARAMS( (ip_port->sa_family == AF_INET) || (ip_port->sa_family == AF_INET6) );
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
696 CHECK_PARAMS( (type == RGW_CLI_NAS) || (type == RGW_CLI_PXY) );
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
697
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
698 /* Dump the entry in debug mode */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
699 if (TRACE_BOOL(FULL + 1 )) {
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
700 TRACE_DEBUG(FULL, "Adding %s:", (type == RGW_CLI_NAS) ? "NAS" : "PROXY" );
260
4c2656ff3400 Cleanup newlines
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
701 TRACE_DEBUG_sSA(FULL, "\tIP : ", ip_port, NI_NUMERICHOST | NI_NUMERICSERV, "" );
4c2656ff3400 Cleanup newlines
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
702 TRACE_DEBUG_BUFFER(FULL, "\tKey: [", *key, keylen, "]" );
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
703 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
704
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
705 /* Lock the lists */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
706 CHECK_POSIX( pthread_mutex_lock(&cli_mtx) );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
707
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
708 /* Check if the same entry does not already exist */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
709 ret = client_search(&prev, ip_port );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
710 if (ret == ENOENT) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
711 /* No duplicate found, Ok to add */
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
712 CHECK_FCT_DO( ret = client_create( &new, &ip_port, key, keylen, type ), goto end );
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
713 fd_list_insert_after(&prev->chain, &new->chain);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
714 new->refcount++;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
715 ret = 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
716 goto end;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
717 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
718
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
719 if (ret == EEXIST) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
720 /* Check if the key is the same, then skip or return an error */
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
721 if ((keylen == prev->key.len ) && ( ! memcmp(*key, prev->key.data, keylen) ) && (type == prev->type)) {
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
722 TRACE_DEBUG(INFO, "Skipping duplicate client description");
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
723 ret = 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
724 goto end;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
725 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
726
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
727 fd_log_debug("ERROR: Conflicting RADIUS clients descriptions!\n");
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
728 TRACE_DEBUG(NONE, "Previous entry: %s", (prev->type == RGW_CLI_NAS) ? "NAS" : "PROXY");
260
4c2656ff3400 Cleanup newlines
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
729 TRACE_DEBUG_sSA(NONE, "\tIP : ", prev->sa, NI_NUMERICHOST | NI_NUMERICSERV, "" );
4c2656ff3400 Cleanup newlines
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
730 TRACE_DEBUG_BUFFER(NONE, "\tKey: [", prev->key.data, prev->key.len, "]" );
516
1c2f5ee38039 Allow RADIUS Proxies with the app_radgw extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 500
diff changeset
731 TRACE_DEBUG(NONE, "Conflicting entry: %s", (type == RGW_CLI_NAS) ? "NAS" : "PROXY");
260
4c2656ff3400 Cleanup newlines
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
732 TRACE_DEBUG_sSA(NONE, "\tIP : ", ip_port, NI_NUMERICHOST | NI_NUMERICSERV, "" );
4c2656ff3400 Cleanup newlines
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
733 TRACE_DEBUG_BUFFER(NONE, "\tKey: [", *key, keylen, "]" );
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
734 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
735 end:
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
736 /* release the lists */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
737 CHECK_POSIX( pthread_mutex_unlock(&cli_mtx) );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
738
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
739 return ret;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
740 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
741
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
742 static void dump_cli_list(struct fd_list *senti)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
743 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
744 struct rgw_client * client = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
745 struct fd_list *ref = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
746
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
747 for (ref = senti->next; ref != senti; ref = ref->next) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
748 client = (struct rgw_client *)ref;
519
3f43713be92d Added flag information in list dump
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 516
diff changeset
749 TRACE_DEBUG_sSA(NONE, " - ", client->sa, NI_NUMERICHOST | NI_NUMERICSERV, (type == RGW_CLI_NAS) ? "" : " [PROXY]" );
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
750 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
751 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
752
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
753 void rgw_clients_dump(void)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
754 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
755 if ( ! TRACE_BOOL(FULL) )
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
756 return;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
757
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
758 CHECK_POSIX_DO( pthread_mutex_lock(&cli_mtx), /* ignore error */ );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
759
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
760 if (!FD_IS_LIST_EMPTY(&cli_ip))
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
761 fd_log_debug(" RADIUS IP clients list:\n");
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
762 dump_cli_list(&cli_ip);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
763
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
764 if (!FD_IS_LIST_EMPTY(&cli_ip6))
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
765 fd_log_debug(" RADIUS IPv6 clients list:\n");
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
766 dump_cli_list(&cli_ip6);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
767
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
768 CHECK_POSIX_DO( pthread_mutex_unlock(&cli_mtx), /* ignore error */ );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
769 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
770
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
771 void rgw_clients_fini(void)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
772 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
773 struct fd_list * client;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
774
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
775 TRACE_ENTRY();
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
776
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
777 CHECK_POSIX_DO( pthread_mutex_lock(&cli_mtx), /* ignore error */ );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
778
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
779 /* empty the lists */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
780 while ( ! FD_IS_LIST_EMPTY(&cli_ip) ) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
781 client = cli_ip.next;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
782 fd_list_unlink(client);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
783 client_unlink((struct rgw_client *)client);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
784 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
785 while (! FD_IS_LIST_EMPTY(&cli_ip6)) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
786 client = cli_ip6.next;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
787 fd_list_unlink(client);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
788 client_unlink((struct rgw_client *)client);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
789 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
790
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
791 CHECK_POSIX_DO( pthread_mutex_unlock(&cli_mtx), /* ignore error */ );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
792
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
793 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
794
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
795 int rgw_client_finish_send(struct radius_msg ** msg, struct rgw_radius_msg_meta * req, struct rgw_client * cli)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
796 {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
797 int idx;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
798
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
799 TRACE_ENTRY("%p %p %p", msg, req, cli);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
800 CHECK_PARAMS( msg && *msg && cli );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
801
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
802 if (!req) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
803 /* We don't support this case yet */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
804 ASSERT(0);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
805 return ENOTSUP;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
806 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
807
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
808 if (radius_msg_finish_srv(*msg, cli->key.data, cli->key.len, req->radius.hdr->authenticator)) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
809 TRACE_DEBUG(INFO, "An error occurred while preparing the RADIUS answer");
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
810 radius_msg_free(*msg);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
811 free(*msg);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
812 *msg = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
813 return EINVAL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
814 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
815
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
816 /* Debug */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
817 TRACE_DEBUG(FULL, "RADIUS message ready for sending:");
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
818 rgw_msg_dump((struct rgw_radius_msg_meta *)*msg);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
819
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
820 /* Send the message */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
821 CHECK_FCT( rgw_servers_send(req->serv_type, (*msg)->buf, (*msg)->buf_used, cli->sa, req->port) );
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
822
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
823 /* update the duplicate cache in rgw_clients */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
824 if (req->serv_type == RGW_PLG_TYPE_AUTH)
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
825 idx = 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
826 else
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
827 idx = 1;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
828 if (cli->last[idx].ans) {
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
829 /* Free it */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
830 radius_msg_free(cli->last[idx].ans);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
831 free(cli->last[idx].ans);
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
832 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
833 cli->last[idx].ans = *msg;
278
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
834 cli->last[idx].id = req->radius.hdr->identifier;
50bfb29bf036 Try better handling several pending requests for the same session (not very clean yet)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 271
diff changeset
835 cli->last[idx].port = req->port;
254
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
836 *msg = NULL;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
837
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
838 /* Finished */
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
839 return 0;
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
840 }
a857024cb48b Ported the RADIUS/Diameter translation code from waaad project. Not tested yet. Gateway plugins to come later.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
841
"Welcome to our mercurial repository"