Mercurial > hg > freeDiameter
annotate libfdcore/routing_dispatch.c @ 1554:566bb46cc73f
Updated copyright information
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Tue, 06 Oct 2020 21:34:53 +0800 |
parents | 239ba25870d8 |
children |
rev | line source |
---|---|
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
738
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
1554
566bb46cc73f
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1397
diff
changeset
|
5 * Copyright (c) 2019, WIDE Project and NICT * |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
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 * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
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 * |
c5c99c73c2bf
Added some extensions and functions in the daemon
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 * |
c5c99c73c2bf
Added some extensions and functions in the daemon
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 * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
c5c99c73c2bf
Added some extensions and functions in the daemon
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 * |
c5c99c73c2bf
Added some extensions and functions in the daemon
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 * |
c5c99c73c2bf
Added some extensions and functions in the daemon
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 * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
649
diff
changeset
|
36 #include "fdcore-internal.h" |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
38 #ifdef linux |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
39 /* This needs -D_USE_GNU, and since I have no idea what else that does, let's simply copy the declaration. */ |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
40 |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
41 /* Set thread name visible in the kernel and its interfaces. */ |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
42 extern int pthread_setname_np (pthread_t __target_thread, const char *__name); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
43 #endif |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
44 |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
45 /********************************************************************************/ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
46 /* First part : handling the extensions callbacks */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
47 /********************************************************************************/ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
48 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
49 /* Lists of the callbacks, and locks to protect them */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
50 static pthread_rwlock_t rt_fwd_lock = PTHREAD_RWLOCK_INITIALIZER; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
51 static struct fd_list rt_fwd_list = FD_LIST_INITIALIZER_O(rt_fwd_list, &rt_fwd_lock); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
52 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
53 static pthread_rwlock_t rt_out_lock = PTHREAD_RWLOCK_INITIALIZER; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
54 static struct fd_list rt_out_list = FD_LIST_INITIALIZER_O(rt_out_list, &rt_out_lock); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
55 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
56 /* Items in the lists are the same */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
57 struct rt_hdl { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
58 struct fd_list chain; /* link in the rt_fwd_list or rt_out_list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
59 void * cbdata; /* the registered data */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
60 union { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
61 int order; /* This value is used to sort the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
62 int dir; /* It is the direction for FWD handlers */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
63 int prio; /* and the priority for OUT handlers */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
64 }; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
65 union { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
66 int (*rt_fwd_cb)(void * cbdata, struct msg ** msg); |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
67 int (*rt_out_cb)(void * cbdata, struct msg ** msg, struct fd_list * candidates); |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
68 }; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
69 }; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
70 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
71 /* Add a new entry in the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
72 static int add_ordered(struct rt_hdl * new, struct fd_list * list) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
73 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
74 /* The list is ordered by prio parameter */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
75 struct fd_list * li; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
76 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
77 CHECK_POSIX( pthread_rwlock_wrlock(list->o) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
78 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
79 for (li = list->next; li != list; li = li->next) { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
80 struct rt_hdl * h = (struct rt_hdl *) li; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
81 if (new->order <= h->order) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
82 break; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
83 } |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
84 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
85 fd_list_insert_before(li, &new->chain); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
86 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
87 CHECK_POSIX( pthread_rwlock_unlock(list->o) ); |
92
892219aef3bc
Add missing return value
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
90
diff
changeset
|
88 |
892219aef3bc
Add missing return value
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
90
diff
changeset
|
89 return 0; |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
90 } |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
91 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
92 /* Register a new FWD callback */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
93 int fd_rt_fwd_register ( int (*rt_fwd_cb)(void * cbdata, struct msg ** msg), void * cbdata, enum fd_rt_fwd_dir dir, struct fd_rt_fwd_hdl ** handler ) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
94 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
95 struct rt_hdl * new; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
96 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
97 TRACE_ENTRY("%p %p %d %p", rt_fwd_cb, cbdata, dir, handler); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
98 CHECK_PARAMS( rt_fwd_cb ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
99 CHECK_PARAMS( (dir >= RT_FWD_REQ) && ( dir <= RT_FWD_ANS) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
100 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
101 /* Create a new container */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
102 CHECK_MALLOC(new = malloc(sizeof(struct rt_hdl))); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
103 memset(new, 0, sizeof(struct rt_hdl)); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
104 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
105 /* Write the content */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
106 fd_list_init(&new->chain, NULL); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
107 new->cbdata = cbdata; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
108 new->dir = dir; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
109 new->rt_fwd_cb = rt_fwd_cb; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
110 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
111 /* Save this in the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
112 CHECK_FCT( add_ordered(new, &rt_fwd_list) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
113 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
114 /* Give it back to the extension if needed */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
115 if (handler) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
116 *handler = (void *)new; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
117 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
118 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
119 } |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
120 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
121 /* Remove it */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
122 int fd_rt_fwd_unregister ( struct fd_rt_fwd_hdl * handler, void ** cbdata ) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
123 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
124 struct rt_hdl * del; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
125 TRACE_ENTRY( "%p %p", handler, cbdata); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
126 CHECK_PARAMS( handler ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
127 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
128 del = (struct rt_hdl *)handler; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
129 CHECK_PARAMS( del->chain.head == &rt_fwd_list ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
130 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
131 /* Unlink */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
132 CHECK_POSIX( pthread_rwlock_wrlock(&rt_fwd_lock) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
133 fd_list_unlink(&del->chain); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
134 CHECK_POSIX( pthread_rwlock_unlock(&rt_fwd_lock) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
135 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
136 if (cbdata) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
137 *cbdata = del->cbdata; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
138 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
139 free(del); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
140 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
141 } |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
142 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
143 /* Register a new OUT callback */ |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
144 int fd_rt_out_register ( int (*rt_out_cb)(void * cbdata, struct msg ** pmsg, struct fd_list * candidates), void * cbdata, int priority, struct fd_rt_out_hdl ** handler ) |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
145 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
146 struct rt_hdl * new; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
147 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
148 TRACE_ENTRY("%p %p %d %p", rt_out_cb, cbdata, priority, handler); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
149 CHECK_PARAMS( rt_out_cb ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
150 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
151 /* Create a new container */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
152 CHECK_MALLOC(new = malloc(sizeof(struct rt_hdl))); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
153 memset(new, 0, sizeof(struct rt_hdl)); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
154 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
155 /* Write the content */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
156 fd_list_init(&new->chain, NULL); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
157 new->cbdata = cbdata; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
158 new->prio = priority; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
159 new->rt_out_cb = rt_out_cb; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
160 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
161 /* Save this in the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
162 CHECK_FCT( add_ordered(new, &rt_out_list) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
163 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
164 /* Give it back to the extension if needed */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
165 if (handler) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
166 *handler = (void *)new; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
167 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
168 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
169 } |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
170 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
171 /* Remove it */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
172 int fd_rt_out_unregister ( struct fd_rt_out_hdl * handler, void ** cbdata ) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
173 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
174 struct rt_hdl * del; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
175 TRACE_ENTRY( "%p %p", handler, cbdata); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
176 CHECK_PARAMS( handler ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
177 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
178 del = (struct rt_hdl *)handler; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
179 CHECK_PARAMS( del->chain.head == &rt_out_list ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
180 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
181 /* Unlink */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
182 CHECK_POSIX( pthread_rwlock_wrlock(&rt_out_lock) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
183 fd_list_unlink(&del->chain); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
184 CHECK_POSIX( pthread_rwlock_unlock(&rt_out_lock) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
185 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
186 if (cbdata) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
187 *cbdata = del->cbdata; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
188 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
189 free(del); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
190 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
191 } |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
192 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
193 /********************************************************************************/ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
194 /* Some default OUT routing callbacks */ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
195 /********************************************************************************/ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
196 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
197 /* Prevent sending to peers that do not support the message application */ |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
198 static int dont_send_if_no_common_app(void * cbdata, struct msg ** pmsg, struct fd_list * candidates) |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
199 { |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
200 struct msg * msg = *pmsg; |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
201 struct fd_list * li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
202 struct msg_hdr * hdr; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
203 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
204 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
205 CHECK_PARAMS(msg && candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
206 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
207 CHECK_FCT( fd_msg_hdr(msg, &hdr) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
208 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
209 /* For Base Diameter Protocol, every peer is supposed to support it, so skip */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
210 if (hdr->msg_appl == 0) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
211 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
212 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
213 /* Otherwise, check that the peers support the application */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
214 for (li = candidates->next; li != candidates; li = li->next) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
215 struct rtd_candidate *c = (struct rtd_candidate *) li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
216 struct fd_peer * peer; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
217 struct fd_app *found; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
218 CHECK_FCT( fd_peer_getbyid( c->diamid, c->diamidlen, 0, (void *)&peer ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
219 if (peer && !peer->p_hdr.info.runtime.pir_relay) { |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
220 /* Check if the remote peer advertised the message's appli */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
221 CHECK_FCT( fd_app_check(&peer->p_hdr.info.runtime.pir_apps, hdr->msg_appl, &found) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
222 if (!found) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
223 c->score += FD_SCORE_NO_DELIVERY; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
224 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
225 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
226 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
227 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
228 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
229 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
230 /* Detect if the Destination-Host and Destination-Realm match the peer */ |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
231 static int score_destination_avp(void * cbdata, struct msg ** pmsg, struct fd_list * candidates) |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
232 { |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
233 struct msg * msg = *pmsg; |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
234 struct fd_list * li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
235 struct avp * avp; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
236 union avp_value *dh = NULL, *dr = NULL; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
237 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
238 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
239 CHECK_PARAMS(msg && candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
240 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
241 /* Search the Destination-Host and Destination-Realm AVPs -- we could also use fd_msg_search_avp here, but this one is slightly more efficient */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
242 CHECK_FCT( fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
243 while (avp) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
244 struct avp_hdr * ahdr; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
245 CHECK_FCT( fd_msg_avp_hdr( avp, &ahdr ) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
246 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
247 if (! (ahdr->avp_flags & AVP_FLAG_VENDOR)) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
248 switch (ahdr->avp_code) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
249 case AC_DESTINATION_HOST: |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
250 /* Parse this AVP */ |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
104
diff
changeset
|
251 CHECK_FCT( fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, NULL ) ); |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
252 ASSERT( ahdr->avp_value ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
253 dh = ahdr->avp_value; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
254 break; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
255 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
256 case AC_DESTINATION_REALM: |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
257 /* Parse this AVP */ |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
104
diff
changeset
|
258 CHECK_FCT( fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, NULL ) ); |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
259 ASSERT( ahdr->avp_value ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
260 dr = ahdr->avp_value; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
261 break; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
262 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
263 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
264 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
265 if (dh && dr) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
266 break; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
267 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
268 /* Go to next AVP */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
269 CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
270 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
271 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
272 /* Now, check each candidate against these AVP values */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
273 for (li = candidates->next; li != candidates; li = li->next) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
274 struct rtd_candidate *c = (struct rtd_candidate *) li; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
275 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
276 #if 0 /* this is actually useless since the sending process will also ensure that the peer is still available */ |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
277 struct fd_peer * peer; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
278 /* Since the candidates list comes from the peers list, we do not have any issue with upper/lower case to find the peer object */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
279 CHECK_FCT( fd_peer_getbyid( c->diamid, c->diamidlen, 0, (void *)&peer ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
280 if (!peer) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
281 continue; /* it has been deleted since the candidate list was generated; avoid sending to this one in that case. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
282 #endif /* 0 */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
283 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
284 /* In the AVPs, the value comes from the network, so let's be case permissive */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
285 if (dh && !fd_os_almostcasesrch(dh->os.data, dh->os.len, c->diamid, c->diamidlen, NULL) ) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
286 /* The candidate is the Destination-Host */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
287 c->score += FD_SCORE_FINALDEST; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
288 } else { |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
289 if (dr && !fd_os_almostcasesrch(dr->os.data, dr->os.len, c->realm, c->realmlen, NULL) ) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
290 /* The candidate's realm matchs the Destination-Realm */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
291 c->score += FD_SCORE_REALM; |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
292 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
293 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
294 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
295 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
296 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
297 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
298 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
299 /********************************************************************************/ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
300 /* Helper functions */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
301 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
302 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
303 /* Find (first) '!' and '@' positions in a UTF-8 encoded string (User-Name AVP value) */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
304 static void nai_get_indexes(union avp_value * un, int * excl_idx, int * at_idx) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
305 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
306 int i; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
307 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
308 TRACE_ENTRY("%p %p %p", un, excl_idx, at_idx); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
309 CHECK_PARAMS_DO( un && excl_idx && at_idx, return ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
310 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
311 *excl_idx = 0; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
312 *at_idx = 0; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
313 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
314 /* Search if there is a '!' before any '@' -- do we need to check it contains a '.' ? */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
315 for (i = 0; i < un->os.len; i++) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
316 /* The '!' marks the decorated NAI */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
317 if ( un->os.data[i] == (unsigned char) '!' ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
318 if (!*excl_idx) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
319 *excl_idx = i; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
320 continue; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
321 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
322 /* If we reach the realm part, we can stop */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
323 if ( un->os.data[i] == (unsigned char) '@' ) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
324 *at_idx = i; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
325 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
326 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
327 /* Stop if we find a \0 in the middle */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
328 if ( un->os.data[i] == 0 ) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
329 return; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
330 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
331 /* Skip escaped characters */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
332 if ( un->os.data[i] == (unsigned char) '\\' ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
333 i++; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
334 continue; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
335 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
336 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
337 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
338 return; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
339 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
340 |
241
84460aa8d77b
NAI routing became RFC, update the reference...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
229
diff
changeset
|
341 /* Test if a User-Name AVP contains a Decorated NAI -- RFC4282, RFC5729 */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
342 /* Create new User-Name and Destination-Realm values */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
343 static int process_decorated_NAI(int * was_nai, union avp_value * un, union avp_value * dr) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
344 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
345 int at_idx, sep_idx; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
346 unsigned char * old_un; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
347 TRACE_ENTRY("%p %p %p", was_nai, un, dr); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
348 CHECK_PARAMS(was_nai && un && dr); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
349 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
350 /* Save the decorated User-Name, for example 'homerealm.example.net!user@otherrealm.example.net' */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
351 old_un = un->os.data; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
352 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
353 /* Search the positions of the first '!' and the '@' in the string */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
354 nai_get_indexes(un, &sep_idx, &at_idx); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
355 if ((!sep_idx) || (sep_idx > at_idx) || !fd_os_is_valid_DiameterIdentity(old_un, sep_idx /* this is the new realm part */)) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
356 *was_nai = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
357 return 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
358 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
359 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
360 *was_nai = 1; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
361 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
362 /* Create the new User-Name value */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
363 CHECK_MALLOC( un->os.data = malloc( at_idx ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
364 memcpy( un->os.data, old_un + sep_idx + 1, at_idx - sep_idx ); /* user@ */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
365 memcpy( un->os.data + at_idx - sep_idx, old_un, sep_idx ); /* homerealm.example.net */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
366 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
367 /* Create the new Destination-Realm value */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
368 CHECK_MALLOC( dr->os.data = realloc(dr->os.data, sep_idx) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
369 memcpy( dr->os.data, old_un, sep_idx ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
370 dr->os.len = sep_idx; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
371 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
372 TRACE_DEBUG(FULL, "Processed Decorated NAI : '%.*s' became '%.*s' (%.*s)", |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1014
diff
changeset
|
373 (int)un->os.len, old_un, |
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1014
diff
changeset
|
374 (int)at_idx, un->os.data, |
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1014
diff
changeset
|
375 (int)dr->os.len, dr->os.data); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
376 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
377 un->os.len = at_idx; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
378 free(old_un); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
379 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
380 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
381 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
382 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
383 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
384 /* Function to return an error to an incoming request */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
385 static int return_error(struct msg ** pmsg, char * error_code, char * error_message, struct avp * failedavp) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
386 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
387 struct fd_peer * peer; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
388 int is_loc = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
389 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
390 /* Get the source of the message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
391 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
392 DiamId_t id; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
393 size_t idlen; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
394 CHECK_FCT( fd_msg_source_get( *pmsg, &id, &idlen ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
395 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
396 if (id == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
397 is_loc = 1; /* The message was issued locally */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
398 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
399 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
400 /* Search the peer with this id */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
401 CHECK_FCT( fd_peer_getbyid( id, idlen, 0, (void *)&peer ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
402 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
403 if (!peer) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
404 char buf[256]; |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
405 snprintf(buf, sizeof(buf), "Unable to send error '%s' to deleted peer '%s' in reply to this message.", error_code, id); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
406 fd_hook_call(HOOK_MESSAGE_DROPPED, *pmsg, NULL, buf, fd_msg_pmdl_get(*pmsg)); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
407 fd_msg_free(*pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
408 *pmsg = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
409 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
410 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
411 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
412 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
413 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
414 /* Create the error message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
415 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, pmsg, MSGFL_ANSW_ERROR ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
416 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
417 /* Set the error code */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
418 CHECK_FCT( fd_msg_rescode_set(*pmsg, error_code, error_message, failedavp, 1 ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
419 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
420 /* Send the answer */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
421 if (is_loc) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
422 CHECK_FCT( fd_fifo_post(fd_g_incoming, pmsg) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
423 } else { |
1238
8f9684264fe0
Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1230
diff
changeset
|
424 CHECK_FCT( fd_out_send(pmsg, NULL, peer, 1) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
425 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
426 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
427 /* Done */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
428 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
429 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
430 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
431 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
432 /****************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
433 /* Second part : threads moving messages in the daemon */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
434 /****************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
435 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
436 /* The DISPATCH message processing */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
437 static int msg_dispatch(struct msg * msg) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
438 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
439 struct msg_hdr * hdr; |
1119
79dd22145f52
Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1113
diff
changeset
|
440 int is_req = 0; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
441 struct session * sess; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
442 enum disp_action action; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
443 char * ec = NULL; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
444 char * em = NULL; |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
445 struct msg *msgptr = msg, *error = NULL; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
446 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
447 /* Read the message header */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
448 CHECK_FCT( fd_msg_hdr(msg, &hdr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
449 is_req = hdr->msg_flags & CMD_FLAG_REQUEST; |
226
406f74f0789b
Few cosmetics changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
168
diff
changeset
|
450 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
451 /* Note: if the message is for local delivery, we should test for duplicate |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
452 (draft-asveren-dime-dupcons-00). This may conflict with path validation decisions, no clear answer yet */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
453 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
454 /* At this point, we need to understand the message content, so parse it */ |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
455 CHECK_FCT_DO( fd_msg_parse_or_error( &msgptr, &error ), |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
456 { |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
457 int rescue = 0; |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
458 if (__ret__ != EBADMSG) { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
459 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, "Error while parsing received answer", fd_msg_pmdl_get(msgptr)); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
460 fd_msg_free(msgptr); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
461 } else { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
462 if (!msgptr) { |
1301
50fb308e84f7
Added a new hook to allow extensions act on the error messages being returned in case of parsing error (e.g. if some mandatory AVP are expected in error messages)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1283
diff
changeset
|
463 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR2, error, NULL, NULL, fd_msg_pmdl_get(error)); |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
464 /* error now contains the answer message to send back */ |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
465 CHECK_FCT( fd_fifo_post(fd_g_outgoing, &error) ); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
466 } else if (!error) { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
467 /* We have received an invalid answer to our query */ |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
468 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, "Received answer failed the dictionary / rules parsing", fd_msg_pmdl_get(msgptr)); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
469 fd_msg_free(msgptr); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
470 } else { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
471 /* We will pass the invalid received error to the application */ |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
472 rescue = 1; |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
473 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
474 } |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
475 if (!rescue) |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
476 return 0; /* We are done with this message, go to the next */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
477 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
478 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
479 /* First, if the original request was registered with a callback and we receive the answer, call it. */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
480 if ( ! is_req ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
481 struct msg * qry; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
482 void (*anscb)(void *, struct msg **) = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
483 void * data = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
484 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
485 /* Retrieve the corresponding query */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
486 CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
487 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
488 /* Retrieve any registered handler */ |
1014
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
489 CHECK_FCT( fd_msg_anscb_get( qry, &anscb, NULL, &data ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
490 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
491 /* If a callback was registered, pass the message to it */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
492 if (anscb != NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
493 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
494 TRACE_DEBUG(FULL, "Calling callback registered when query was sent (%p, %p)", anscb, data); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
495 (*anscb)(data, &msgptr); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
496 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
497 /* If the message is processed, we're done */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
498 if (msgptr == NULL) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
499 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
500 } |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
501 |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
502 /* otherwise continue the dispatching --hoping that the anscb callback did not mess with our message :) */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
503 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
504 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
505 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
506 /* Retrieve the session of the message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
507 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, msgptr, &sess, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
508 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
509 /* Now, call any callback registered for the message */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
510 CHECK_FCT( fd_msg_dispatch ( &msgptr, sess, &action, &ec, &em, &error) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
511 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
512 /* Now, act depending on msg and action and ec */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
513 if (msgptr) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
514 switch ( action ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
515 case DISP_ACT_CONT: |
754
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
516 /* No callback has handled the message, let's reply with a generic error or relay it */ |
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
517 if (!fd_g_config->cnf_flags.no_fwd) { |
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
518 /* requeue to fd_g_outgoing */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
519 fd_hook_call(HOOK_MESSAGE_ROUTING_FORWARD, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
520 CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) ); |
754
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
521 break; |
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
522 } |
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
523 /* We don't relay => reply error */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
524 em = "The message was not handled by any extension callback"; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
525 ec = "DIAMETER_COMMAND_UNSUPPORTED"; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
526 /* and continue as if an error occurred... */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
527 case DISP_ACT_ERROR: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
528 /* We have a problem with delivering the message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
529 if (ec == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
530 ec = "DIAMETER_UNABLE_TO_COMPLY"; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
531 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
532 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
533 if (!is_req) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
534 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, "Internal error: Answer received to locally issued request, but not handled by any handler.", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
535 fd_msg_free(msgptr); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
536 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
537 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
538 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
539 /* Create an answer with the error code and message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
540 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msgptr, 0 ) ); |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
541 CHECK_FCT( fd_msg_rescode_set(msgptr, ec, em, NULL, 1 ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
542 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
543 case DISP_ACT_SEND: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
544 /* Now, send the message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
545 CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
546 } |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
547 } else if (em) { |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
548 fd_hook_call(HOOK_MESSAGE_DROPPED, error, NULL, em, fd_msg_pmdl_get(error)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
549 fd_msg_free(error); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
550 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
551 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
552 /* We're done with dispatching this message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
553 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
554 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
555 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
556 /* The ROUTING-IN message processing */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
557 static int msg_rt_in(struct msg * msg) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
558 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
559 struct msg_hdr * hdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
560 int is_req = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
561 int is_err = 0; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
562 DiamId_t qry_src = NULL; |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
563 struct msg *msgptr = msg; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
564 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
565 /* Read the message header */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
566 CHECK_FCT( fd_msg_hdr(msg, &hdr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
567 is_req = hdr->msg_flags & CMD_FLAG_REQUEST; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
568 is_err = hdr->msg_flags & CMD_FLAG_ERROR; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
569 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
570 /* Handle incorrect bits */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
571 if (is_req && is_err) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
572 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "R & E bits were set", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
573 CHECK_FCT( return_error( &msgptr, "DIAMETER_INVALID_HDR_BITS", "R & E bits were set", NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
574 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
575 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
576 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
577 /* If it is a request, we must analyze its content to decide what we do with it */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
578 if (is_req) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
579 struct avp * avp, *un = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
580 union avp_value * un_val = NULL, *dr_val = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
581 enum status { UNKNOWN, YES, NO }; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
582 /* Are we Destination-Host? */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
583 enum status is_dest_host = UNKNOWN; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
584 /* Are we Destination-Realm? */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
585 enum status is_dest_realm = UNKNOWN; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
586 /* Do we support the application of the message? */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
587 enum status is_local_app = UNKNOWN; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
588 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
589 /* Check if we have local support for the message application */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
590 if ( (hdr->msg_appl == 0) || (hdr->msg_appl == AI_RELAY) ) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
591 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Received a routable message with application id 0 or " _stringize(AI_RELAY) " (relay)", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
592 CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", "Routable message with application id 0 or relay", NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
593 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
594 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
595 struct fd_app * app; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
596 CHECK_FCT( fd_app_check(&fd_g_config->cnf_apps, hdr->msg_appl, &app) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
597 is_local_app = (app ? YES : NO); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
598 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
599 |
1154
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
600 /* Parse the message for Dest-Host, Dest-Realm, and Route-Record */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
601 CHECK_FCT( fd_msg_browse(msgptr, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
602 while (avp) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
603 struct avp_hdr * ahdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
604 struct fd_pei error_info; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
605 int ret; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
606 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
607 memset(&error_info, 0, sizeof(struct fd_pei)); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
608 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
609 CHECK_FCT( fd_msg_avp_hdr( avp, &ahdr ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
610 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
611 if (! (ahdr->avp_flags & AVP_FLAG_VENDOR)) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
612 switch (ahdr->avp_code) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
613 case AC_DESTINATION_HOST: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
614 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
615 CHECK_FCT_DO( ret = fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, &error_info ), |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
616 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
617 if (error_info.pei_errcode) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
618 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
619 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
620 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
621 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
622 } else { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
623 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing Destination-Host AVP", fd_msg_pmdl_get(msgptr)); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
624 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
625 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
626 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
627 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
628 /* Compare the Destination-Host AVP of the message with our identity */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
629 if (!fd_os_almostcasesrch(ahdr->avp_value->os.data, ahdr->avp_value->os.len, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, NULL)) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
630 is_dest_host = YES; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
631 } else { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
632 is_dest_host = NO; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
633 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
634 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
635 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
636 case AC_DESTINATION_REALM: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
637 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
638 CHECK_FCT_DO( ret = fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, &error_info ), |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
639 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
640 if (error_info.pei_errcode) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
641 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
642 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
643 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
644 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
645 } else { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
646 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing Destination-Realm AVP", fd_msg_pmdl_get(msgptr)); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
647 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
648 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
649 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
650 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
651 dr_val = ahdr->avp_value; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
652 /* Compare the Destination-Realm AVP of the message with our identity */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
653 if (!fd_os_almostcasesrch(dr_val->os.data, dr_val->os.len, fd_g_config->cnf_diamrlm, fd_g_config->cnf_diamrlm_len, NULL)) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
654 is_dest_realm = YES; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
655 } else { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
656 is_dest_realm = NO; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
657 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
658 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
659 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
660 /* we also use User-Name for decorated NAI */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
661 case AC_USER_NAME: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
662 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
663 CHECK_FCT_DO( ret = fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, &error_info ), |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
664 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
665 if (error_info.pei_errcode) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
666 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
667 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
668 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
669 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
670 } else { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
671 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing User-Name AVP", fd_msg_pmdl_get(msgptr)); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
672 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
673 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
674 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
675 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
676 un = avp; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
677 un_val = ahdr->avp_value; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
678 break; |
1154
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
679 |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
680 case AC_ROUTE_RECORD: |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
681 /* Parse this AVP */ |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
682 CHECK_FCT_DO( ret = fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, &error_info ), |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
683 { |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
684 if (error_info.pei_errcode) { |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
685 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr)); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
686 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
687 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
1154
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
688 return 0; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
689 } else { |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
690 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing Route-Record AVP", fd_msg_pmdl_get(msgptr)); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
691 return ret; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
692 } |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
693 } ); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
694 ASSERT( ahdr->avp_value ); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
695 /* Is this our own name ? */ |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
696 if (!fd_os_almostcasesrch(ahdr->avp_value->os.data, ahdr->avp_value->os.len, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, NULL)) { |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
697 /* Yes: then we must return DIAMETER_LOOP_DETECTED according to Diameter RFC */ |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
698 char * error = "DIAMETER_LOOP_DETECTED"; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
699 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error, fd_msg_pmdl_get(msgptr)); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
700 CHECK_FCT( return_error( &msgptr, error, NULL, NULL) ); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
701 return 0; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
702 } |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
703 break; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
704 |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
705 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
706 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
707 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
708 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
709 /* Stop when we found all 3 AVPs -- they are supposed to be at the beginning of the message, so this should be fast */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
710 if ((is_dest_host != UNKNOWN) && (is_dest_realm != UNKNOWN) && un) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
711 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
712 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
713 /* Go to next AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
714 CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
715 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
716 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
717 /* OK, now decide what we do with the request */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
718 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
719 /* Handle the missing routing AVPs first */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
720 if ( is_dest_realm == UNKNOWN ) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
721 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
722 CHECK_FCT( return_error( &msgptr, "DIAMETER_COMMAND_UNSUPPORTED", "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
723 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
724 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
725 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
726 /* If we are listed as Destination-Host */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
727 if (is_dest_host == YES) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
728 if (is_local_app == YES) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
729 /* Ok, give the message to the dispatch thread */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
730 fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
731 CHECK_FCT( fd_fifo_post(fd_g_local, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
732 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
733 /* We don't support the application, reply an error */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
734 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Application unsupported", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
735 CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
736 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
737 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
738 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
739 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
740 /* If the message is explicitely for someone else */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
741 if ((is_dest_host == NO) || (is_dest_realm == NO)) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
742 if (fd_g_config->cnf_flags.no_fwd) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
743 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "Message for another realm/host", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
744 CHECK_FCT( return_error( &msgptr, "DIAMETER_UNABLE_TO_DELIVER", "I am not a Diameter agent", NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
745 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
746 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
747 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
748 /* Destination-Host was not set, and Destination-Realm is matching : we may handle or pass to a fellow peer */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
749 int is_nai = 0; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
750 |
241
84460aa8d77b
NAI routing became RFC, update the reference...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
229
diff
changeset
|
751 /* test for decorated NAI (RFC5729 section 4.4) */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
752 /* Handle the decorated NAI */ |
712
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
753 if (un_val) { |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
754 CHECK_FCT_DO( process_decorated_NAI(&is_nai, un_val, dr_val), |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
755 { |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
756 /* If the process failed, we assume it is because of the AVP format */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
757 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Failed to process decorated NAI", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
758 CHECK_FCT( return_error( &msgptr, "DIAMETER_INVALID_AVP_VALUE", "Failed to process decorated NAI", un) ); |
712
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
759 return 0; |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
760 } ); |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
761 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
762 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
763 if (is_nai) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
764 /* We have transformed the AVP, now submit it again in the queue */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
765 CHECK_FCT(fd_fifo_post(fd_g_incoming, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
766 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
767 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
768 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
769 if (is_local_app == YES) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
770 /* Handle localy since we are able to */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
771 fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
772 CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
773 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
774 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
775 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
776 if (fd_g_config->cnf_flags.no_fwd) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
777 /* We return an error */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
778 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "Application unsupported", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
779 CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
780 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
781 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
782 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
783 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
784 /* From that point, for requests, we will call the registered callbacks, then forward to another peer */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
785 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
786 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
787 /* The message is an answer */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
788 struct msg * qry; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
789 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
790 /* Retrieve the corresponding query and its origin */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
791 CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) ); |
1120
c473581adff2
Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1119
diff
changeset
|
792 CHECK_FCT( fd_msg_source_get( qry, &qry_src, NULL ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
793 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
794 if ((!qry_src) && (!is_err)) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
795 /* The message is a normal answer to a request issued localy, we do not call the callbacks chain on it. */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
796 fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
797 CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
798 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
799 } |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
715
diff
changeset
|
800 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
801 /* From that point, for answers, we will call the registered callbacks, then pass it to the dispatch module or forward it */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
802 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
803 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
804 /* Call all registered callbacks for this message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
805 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
806 struct fd_list * li; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
807 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
808 CHECK_FCT( pthread_rwlock_rdlock( &rt_fwd_lock ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
809 pthread_cleanup_push( fd_cleanup_rwlock, &rt_fwd_lock ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
810 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
811 /* requests: dir = 1 & 2 => in order; answers = 3 & 2 => in reverse order */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
812 for ( li = (is_req ? rt_fwd_list.next : rt_fwd_list.prev) ; msgptr && (li != &rt_fwd_list) ; li = (is_req ? li->next : li->prev) ) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
813 struct rt_hdl * rh = (struct rt_hdl *)li; |
688
8c3dc8584dab
Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
814 int ret; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
815 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
816 if (is_req && (rh->dir > RT_FWD_ALL)) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
817 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
818 if ((!is_req) && (rh->dir < RT_FWD_ALL)) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
819 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
820 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
821 /* Ok, call this cb */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
822 TRACE_DEBUG(ANNOYING, "Calling next FWD callback on %p : %p", msgptr, rh->rt_fwd_cb); |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
823 CHECK_FCT_DO( ret = (*rh->rt_fwd_cb)(rh->cbdata, &msgptr), |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
824 { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
825 char buf[256]; |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
826 snprintf(buf, sizeof(buf), "A FWD routing callback returned an error: %s", strerror(ret)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
827 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
828 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
829 fd_msg_free(msgptr); |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
830 msgptr = NULL; |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
831 break; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
832 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
833 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
834 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
835 pthread_cleanup_pop(0); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
836 CHECK_FCT( pthread_rwlock_unlock( &rt_fwd_lock ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
837 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
838 /* If a callback has handled the message, we stop now */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
839 if (!msgptr) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
840 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
841 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
842 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
843 /* Now pass the message to the next step: either forward to another peer, or dispatch to local extensions */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
844 if (is_req || qry_src) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
845 fd_hook_call(HOOK_MESSAGE_ROUTING_FORWARD, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
846 CHECK_FCT(fd_fifo_post(fd_g_outgoing, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
847 } else { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
848 fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
849 CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
850 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
851 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
852 /* We're done with this message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
853 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
854 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
855 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
856 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
857 /* The ROUTING-OUT message processing */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
858 static int msg_rt_out(struct msg * msg) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
859 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
860 struct rt_data * rtd = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
861 struct msg_hdr * hdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
862 int is_req = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
863 int ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
864 struct fd_list * li, *candidates; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
865 struct avp * avp; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
866 struct rtd_candidate * c; |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
867 struct msg *msgptr = msg; |
1014
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
868 DiamId_t qry_src = NULL; |
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
869 size_t qry_src_len = 0; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
870 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
871 /* Read the message header */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
872 CHECK_FCT( fd_msg_hdr(msgptr, &hdr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
873 is_req = hdr->msg_flags & CMD_FLAG_REQUEST; |
649
5e5d8152c229
Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
563
diff
changeset
|
874 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
875 /* For answers, the routing is very easy */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
876 if ( ! is_req ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
877 struct msg * qry; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
878 struct msg_hdr * qry_hdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
879 struct fd_peer * peer = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
880 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
881 /* Retrieve the corresponding query and its origin */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
882 CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
883 CHECK_FCT( fd_msg_source_get( qry, &qry_src, &qry_src_len ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
884 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
885 ASSERT( qry_src ); /* if it is NULL, the message should have been in the LOCAL queue! */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
886 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
887 /* Find the peer corresponding to this name */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
888 CHECK_FCT( fd_peer_getbyid( qry_src, qry_src_len, 0, (void *) &peer ) ); |
1274
681e8e55af27
Allow routing messages in state CLOSING_GRACE.
Thomas Klausner <tk@giga.or.at>
parents:
1238
diff
changeset
|
889 if (fd_peer_getstate(peer) != STATE_OPEN && fd_peer_getstate(peer) != STATE_CLOSING_GRACE) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
890 char buf[128]; |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
891 snprintf(buf, sizeof(buf), "Unable to forward answer to deleted / closed peer '%s'.", qry_src); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
892 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
893 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
894 fd_msg_free(msgptr); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
895 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
896 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
897 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
898 /* We must restore the hop-by-hop id */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
899 CHECK_FCT( fd_msg_hdr(qry, &qry_hdr) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
900 hdr->msg_hbhid = qry_hdr->msg_hbhid; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
901 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
902 /* Push the message into this peer */ |
1238
8f9684264fe0
Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1230
diff
changeset
|
903 CHECK_FCT( fd_out_send(&msgptr, NULL, peer, 1) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
904 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
905 /* We're done with this answer */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
906 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
907 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
908 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
909 /* From that point, the message is a request */ |
1014
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
910 CHECK_FCT( fd_msg_source_get( msgptr, &qry_src, &qry_src_len ) ); |
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
911 /* if qry_src != NULL, this message is relayed, otherwise it is locally issued */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
912 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
913 /* Get the routing data out of the message if any (in case of re-transmit) */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
914 CHECK_FCT( fd_msg_rt_get ( msgptr, &rtd ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
915 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
916 /* If there is no routing data already, let's create it */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
917 if (rtd == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
918 CHECK_FCT( fd_rtd_init(&rtd) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
919 |
563
dc9764591567
Automatic load-balancing between peers that have the same routing score. Use rt_ereg to obtain stable routes.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
920 /* Add all peers currently in OPEN state */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
921 CHECK_FCT( pthread_rwlock_rdlock(&fd_g_activ_peers_rw) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
922 for (li = fd_g_activ_peers.next; li != &fd_g_activ_peers; li = li->next) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
923 struct fd_peer * p = (struct fd_peer *)li->o; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
924 CHECK_FCT_DO( ret = fd_rtd_candidate_add(rtd, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
925 p->p_hdr.info.pi_diamid, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
926 p->p_hdr.info.pi_diamidlen, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
927 p->p_hdr.info.runtime.pir_realm, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
928 p->p_hdr.info.runtime.pir_realmlen), |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
929 { CHECK_FCT_DO( pthread_rwlock_unlock(&fd_g_activ_peers_rw), ); return ret; } ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
930 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
931 CHECK_FCT( pthread_rwlock_unlock(&fd_g_activ_peers_rw) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
932 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
933 /* Now let's remove all peers from the Route-Records */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
934 CHECK_FCT( fd_msg_browse(msgptr, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
935 while (avp) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
936 struct avp_hdr * ahdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
937 struct fd_pei error_info; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
938 CHECK_FCT( fd_msg_avp_hdr( avp, &ahdr ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
939 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
940 if ((ahdr->avp_code == AC_ROUTE_RECORD) && (! (ahdr->avp_flags & AVP_FLAG_VENDOR)) ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
941 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
942 CHECK_FCT_DO( ret = fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, &error_info ), |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
943 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
944 if (error_info.pei_errcode) { |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
945 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
946 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
947 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
948 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
949 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
950 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
951 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
952 ASSERT( ahdr->avp_value ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
953 /* Remove this value from the list. We don't need to pay special attention to the contents here. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
954 fd_rtd_candidate_del(rtd, ahdr->avp_value->os.data, ahdr->avp_value->os.len); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
955 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
956 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
957 /* Go to next AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
958 CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
959 } |
1212
c38bb8b69c43
Fix message rtd handling for extensions based on this data
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
960 |
c38bb8b69c43
Fix message rtd handling for extensions based on this data
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
961 /* Save the routing information in the message */ |
c38bb8b69c43
Fix message rtd handling for extensions based on this data
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
962 CHECK_FCT( fd_msg_rt_associate ( msgptr, rtd ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
963 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
964 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
965 /* Note: we reset the scores and pass the message to the callbacks, maybe we could re-use the saved scores when we have received an error ? -- TODO */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
966 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
967 /* Ok, we have our list in rtd now, let's (re)initialize the scores */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
968 fd_rtd_candidate_extract(rtd, &candidates, FD_SCORE_INI); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
969 |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
970 /* Pass the list to registered callbacks (even if it is empty list) */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
971 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
972 CHECK_FCT( pthread_rwlock_rdlock( &rt_out_lock ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
973 pthread_cleanup_push( fd_cleanup_rwlock, &rt_out_lock ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
974 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
975 /* We call the cb by reverse priority order */ |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
976 for ( li = rt_out_list.prev ; (msgptr != NULL) && (li != &rt_out_list) ; li = li->prev ) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
977 struct rt_hdl * rh = (struct rt_hdl *)li; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
978 |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
979 TRACE_DEBUG(ANNOYING, "Calling next OUT callback on %p : %p (prio %d)", msgptr, rh->rt_out_cb, rh->prio); |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
980 CHECK_FCT_DO( ret = (*rh->rt_out_cb)(rh->cbdata, &msgptr, candidates), |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
981 { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
982 char buf[256]; |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
983 snprintf(buf, sizeof(buf), "An OUT routing callback returned an error: %s", strerror(ret)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
984 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
985 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
986 fd_msg_free(msgptr); |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
987 msgptr = NULL; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
988 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
989 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
990 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
991 pthread_cleanup_pop(0); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
992 CHECK_FCT( pthread_rwlock_unlock( &rt_out_lock ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
993 |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
994 /* If an error occurred or the callback disposed of the message, go to next message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
995 if (! msgptr) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
996 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
997 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
998 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
999 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1000 /* Order the candidate peers by score attributed by the callbacks */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1001 CHECK_FCT( fd_rtd_candidate_reorder(candidates) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1002 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1003 /* Now try sending the message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1004 for (li = candidates->prev; li != candidates; li = li->prev) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1005 struct fd_peer * peer; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1006 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1007 c = (struct rtd_candidate *) li; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1008 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1009 /* Stop when we have reached the end of valid candidates */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1010 if (c->score < 0) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1011 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1012 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1013 /* Search for the peer */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1014 CHECK_FCT( fd_peer_getbyid( c->diamid, c->diamidlen, 0, (void *)&peer ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1015 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1016 if (fd_peer_getstate(peer) == STATE_OPEN) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1017 /* Send to this one */ |
1238
8f9684264fe0
Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1230
diff
changeset
|
1018 CHECK_FCT_DO( fd_out_send(&msgptr, NULL, peer, 1), continue ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1019 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1020 /* If the sending was successful */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1021 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1022 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1023 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1024 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1025 /* If the message has not been sent, return an error */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
1026 if (msgptr) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
1027 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "No remaining suitable candidate to route the message to", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
1028 return_error( &msgptr, "DIAMETER_UNABLE_TO_DELIVER", "No suitable candidate to route the message to", NULL); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1029 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1030 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1031 /* We're done with this message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1032 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1033 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1034 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1035 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1036 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1037 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1038 /* Management of the threads */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1039 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1040 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1041 /* Note: in the first version, we only create one thread of each kind. |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1042 We could improve the scalability by using the threshold feature of the queues |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1043 to create additional threads if a queue is filling up, or at least giving a configurable |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1044 number of threads of each kind. |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1045 */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1046 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1047 /* Control of the threads */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1048 static enum { RUN = 0, STOP = 1 } order_val = RUN; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1049 static pthread_mutex_t order_state_lock = PTHREAD_MUTEX_INITIALIZER; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1050 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1051 /* Threads report their status */ |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1052 enum thread_state { NOTRUNNING = 0, RUNNING = 1 }; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1053 static void cleanup_state(void * state_loc) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1054 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1055 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1056 *(enum thread_state *)state_loc = NOTRUNNING; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1057 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1058 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1059 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1060 /* This is the common thread code (same for routing and dispatching) */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
1061 static void * process_thr(void * arg, int (*action_cb)(struct msg * msg), struct fifo * queue, char * action_name) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1062 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1063 TRACE_ENTRY("%p %p %p %p", arg, action_cb, queue, action_name); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1064 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1065 /* Set the thread name */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1066 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1067 char buf[48]; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1068 snprintf(buf, sizeof(buf), "%s (%p)", action_name, arg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1069 fd_log_threadname ( buf ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1070 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1071 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1072 /* The thread reports its status when canceled */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1073 CHECK_PARAMS_DO(arg, return NULL); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1074 pthread_cleanup_push( cleanup_state, arg ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1075 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1076 /* Mark the thread running */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1077 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1078 *(enum thread_state *)arg = RUNNING; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1079 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1080 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1081 do { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1082 struct msg * msg; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1083 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1084 /* Get the next message from the queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1085 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1086 int ret; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1087 struct timespec ts; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1088 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1089 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), goto fatal_error ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1090 ts.tv_sec += 1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1091 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1092 ret = fd_fifo_timedget ( queue, &msg, &ts ); |
1328 | 1093 if (ret == ETIMEDOUT) { |
1094 /* Test the current order */ | |
1095 { | |
1096 int must_stop; | |
1097 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), { ASSERT(0); } ); /* we lock to flush the caches */ | |
1098 must_stop = (order_val == STOP); | |
1099 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), { ASSERT(0); } ); | |
1100 if (must_stop) | |
1101 goto end; | |
1102 | |
1103 pthread_testcancel(); | |
1104 } | |
1105 /* Ok, we are allowed to continue */ | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1106 continue; |
1328 | 1107 } |
125
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1108 if (ret == EPIPE) |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1109 /* The queue was destroyed, we are probably exiting */ |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1110 goto end; |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1111 |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1112 /* check if another error occurred */ |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1113 CHECK_FCT_DO( ret, goto fatal_error ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1114 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1115 |
1119
79dd22145f52
Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1113
diff
changeset
|
1116 LOG_A("%s: Picked next message", action_name); |
1037
4f5eb63aef96
In TRACE_DEBUG, mention which thread we're in (Routing-IN/Routing-OUT/Dispatch).
Thomas Klausner <tk@giga.or.at>
parents:
1027
diff
changeset
|
1117 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1118 /* Now process the message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
1119 CHECK_FCT_DO( (*action_cb)(msg), goto fatal_error); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1120 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1121 /* We're done with this message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1122 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1123 } while (1); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1124 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1125 fatal_error: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1126 TRACE_DEBUG(INFO, "An unrecoverable error occurred, %s thread is terminating...", action_name); |
1190
6a1042d8075b
Replace FDEV_TERMINATE events with calls to fd_core_shutdown to handle the core state properly
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
1127 CHECK_FCT_DO(fd_core_shutdown(), ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1128 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1129 end: |
164 | 1130 ; /* noop so that we get rid of "label at end of compund statement" warning */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1131 /* Mark the thread as terminated */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1132 pthread_cleanup_pop(1); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1133 return NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1134 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1135 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1136 /* The dispatch thread */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1137 static void * dispatch_thr(void * arg) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1138 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1139 return process_thr(arg, msg_dispatch, fd_g_local, "Dispatch"); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1140 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1141 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1142 /* The (routing-in) thread -- see description in freeDiameter.h */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1143 static void * routing_in_thr(void * arg) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1144 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1145 return process_thr(arg, msg_rt_in, fd_g_incoming, "Routing-IN"); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1146 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1147 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1148 /* The (routing-out) thread -- see description in freeDiameter.h */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1149 static void * routing_out_thr(void * arg) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1150 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1151 return process_thr(arg, msg_rt_out, fd_g_outgoing, "Routing-OUT"); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1152 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1153 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1154 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1155 /********************************************************************************/ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1156 /* The functions for the other files */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1157 /********************************************************************************/ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1158 |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1159 static pthread_t * dispatch = NULL; |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1160 static enum thread_state * disp_state = NULL; |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1161 |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1162 static pthread_t * rt_out = NULL; |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1163 static enum thread_state * out_state = NULL; |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
1164 |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1165 static pthread_t * rt_in = NULL; |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1166 static enum thread_state * in_state = NULL; |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1167 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1168 /* Initialize the routing and dispatch threads */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1169 int fd_rtdisp_init(void) |
82 | 1170 { |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1171 int i; |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1172 |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1173 /* Prepare the array for threads */ |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1174 CHECK_MALLOC( disp_state = calloc(fd_g_config->cnf_dispthr, sizeof(enum thread_state)) ); |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1175 CHECK_MALLOC( dispatch = calloc(fd_g_config->cnf_dispthr, sizeof(pthread_t)) ); |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1176 CHECK_MALLOC( out_state = calloc(fd_g_config->cnf_rtoutthr, sizeof(enum thread_state)) ); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1177 CHECK_MALLOC( rt_out = calloc(fd_g_config->cnf_rtoutthr, sizeof(pthread_t)) ); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1178 CHECK_MALLOC( in_state = calloc(fd_g_config->cnf_rtinthr, sizeof(enum thread_state)) ); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1179 CHECK_MALLOC( rt_in = calloc(fd_g_config->cnf_rtinthr, sizeof(pthread_t)) ); |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1180 |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1181 /* Create the threads */ |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1182 for (i=0; i < fd_g_config->cnf_dispthr; i++) { |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1183 CHECK_POSIX( pthread_create( &dispatch[i], NULL, dispatch_thr, &disp_state[i] ) ); |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1184 #ifdef linux |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1185 pthread_setname_np(dispatch[i], "fd-dispatch"); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1186 #endif |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1187 } |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1188 for (i=0; i < fd_g_config->cnf_rtoutthr; i++) { |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1189 CHECK_POSIX( pthread_create( &rt_out[i], NULL, routing_out_thr, &out_state[i] ) ); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1190 #ifdef linux |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1191 pthread_setname_np(rt_out[i], "fd-routing-out"); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1192 #endif |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1193 } |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1194 for (i=0; i < fd_g_config->cnf_rtinthr; i++) { |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1195 CHECK_POSIX( pthread_create( &rt_in[i], NULL, routing_in_thr, &in_state[i] ) ); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1196 #ifdef linux |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1197 pthread_setname_np(rt_in[i], "fd-routing-in"); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1198 #endif |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1199 } |
87 | 1200 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1201 /* Later: TODO("Set the thresholds for the queues to create more threads as needed"); */ |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
1202 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
1203 /* Register the built-in callbacks */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
1204 CHECK_FCT( fd_rt_out_register( dont_send_if_no_common_app, NULL, 10, NULL ) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
1205 CHECK_FCT( fd_rt_out_register( score_destination_avp, NULL, 10, NULL ) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1206 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1207 return 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1208 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1209 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1210 /* Ask the thread to terminate after next iteration */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1211 int fd_rtdisp_cleanstop(void) |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1212 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1213 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1214 order_val = STOP; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1215 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1216 |
88
9e2db1647d6f
Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
87
diff
changeset
|
1217 return 0; |
82 | 1218 } |
1219 | |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1220 static void stop_thread_delayed(enum thread_state *st, pthread_t * thr, char * th_name) |
82 | 1221 { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1222 TRACE_ENTRY("%p %p", st, thr); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1223 CHECK_PARAMS_DO(st && thr, return); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1224 int terminated; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1225 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1226 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1227 terminated = (*st == NOTRUNNING); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1228 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1229 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1230 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1231 /* Wait for a second for the thread to complete, by monitoring my_state */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1232 if (!terminated) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1233 TRACE_DEBUG(INFO, "Waiting for the %s thread to have a chance to terminate", th_name); |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1234 do { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1235 struct timespec ts, ts_final; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1236 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1237 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), break ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1238 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1239 ts_final.tv_sec = ts.tv_sec + 1; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1240 ts_final.tv_nsec = ts.tv_nsec; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1241 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1242 while (TS_IS_INFERIOR( &ts, &ts_final )) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1243 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1244 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1245 terminated = (*st == NOTRUNNING); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1246 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1247 if (terminated) |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1248 break; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1249 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1250 usleep(100000); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1251 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), break ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1252 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1253 } while (0); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1254 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1255 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1256 /* Now stop the thread and reclaim its resources */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1257 CHECK_FCT_DO( fd_thr_term(thr ), /* continue */); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1258 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1259 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1260 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1261 /* Stop the thread after up to one second of wait */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1262 int fd_rtdisp_fini(void) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1263 { |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1264 int i; |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1265 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1266 /* Destroy the incoming queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1267 CHECK_FCT_DO( fd_queues_fini(&fd_g_incoming), /* ignore */); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1268 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1269 /* Stop the routing IN thread */ |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1270 if (rt_in != NULL) { |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1271 for (i=0; i < fd_g_config->cnf_rtinthr; i++) { |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1272 stop_thread_delayed(&in_state[i], &rt_in[i], "IN routing"); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1273 } |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1274 free(rt_in); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1275 rt_in = NULL; |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1276 } |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1277 if (in_state != NULL) { |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1278 free(in_state); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1279 in_state = NULL; |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1280 } |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1281 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1282 /* Destroy the outgoing queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1283 CHECK_FCT_DO( fd_queues_fini(&fd_g_outgoing), /* ignore */); |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1284 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1285 /* Stop the routing OUT thread */ |
1397
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1286 if (rt_out != NULL) { |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1287 for (i=0; i < fd_g_config->cnf_rtinthr; i++) { |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1288 stop_thread_delayed(&out_state[i], &rt_out[i], "OUT routing"); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1289 } |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1290 free(rt_out); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1291 rt_out = NULL; |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1292 } |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1293 if (out_state != NULL) { |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1294 free(out_state); |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1295 out_state = NULL; |
239ba25870d8
Allow parametrizing the number of threads for routing in/out.
Thomas Klausner <tk@giga.or.at>
parents:
1328
diff
changeset
|
1296 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1297 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1298 /* Destroy the local queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1299 CHECK_FCT_DO( fd_queues_fini(&fd_g_local), /* ignore */); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1300 |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1301 /* Stop the Dispatch threads */ |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1302 if (dispatch != NULL) { |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1303 for (i=0; i < fd_g_config->cnf_dispthr; i++) { |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1304 stop_thread_delayed(&disp_state[i], &dispatch[i], "Dispatching"); |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1305 } |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1306 free(dispatch); |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1307 dispatch = NULL; |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1308 } |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1309 if (disp_state != NULL) { |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1310 free(disp_state); |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1311 disp_state = NULL; |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1312 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1313 |
122
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1314 return 0; |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1315 } |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1316 |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1317 /* Cleanup handlers */ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1318 int fd_rtdisp_cleanup(void) |
122
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1319 { |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1320 /* Cleanup all remaining handlers */ |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1321 while (!FD_IS_LIST_EMPTY(&rt_fwd_list)) { |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1322 CHECK_FCT_DO( fd_rt_fwd_unregister ( (void *)rt_fwd_list.next, NULL ), /* continue */ ); |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1323 } |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1324 while (!FD_IS_LIST_EMPTY(&rt_out_list)) { |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1325 CHECK_FCT_DO( fd_rt_out_unregister ( (void *)rt_out_list.next, NULL ), /* continue */ ); |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1326 } |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1327 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1328 fd_disp_unregister_all(); /* destroy remaining handlers */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1329 |
88
9e2db1647d6f
Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
87
diff
changeset
|
1330 return 0; |
82 | 1331 } |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
82
diff
changeset
|
1332 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
82
diff
changeset
|
1333 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1334 /********************************************************************************/ |
1055 | 1335 /* For extensions to register a new appl */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1336 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1337 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1338 /* Add an application into the peer's supported apps */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1339 int fd_disp_app_support ( struct dict_object * app, struct dict_object * vendor, int auth, int acct ) |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1340 { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1341 application_id_t aid = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1342 vendor_id_t vid = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1343 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1344 TRACE_ENTRY("%p %p %d %d", app, vendor, auth, acct); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1345 CHECK_PARAMS( app && (auth || acct) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1346 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1347 { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1348 enum dict_object_type type = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1349 struct dict_application_data data; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1350 CHECK_FCT( fd_dict_gettype(app, &type) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1351 CHECK_PARAMS( type == DICT_APPLICATION ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1352 CHECK_FCT( fd_dict_getval(app, &data) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1353 aid = data.application_id; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1354 } |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
1355 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1356 if (vendor) { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1357 enum dict_object_type type = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1358 struct dict_vendor_data data; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1359 CHECK_FCT( fd_dict_gettype(vendor, &type) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1360 CHECK_PARAMS( type == DICT_VENDOR ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1361 CHECK_FCT( fd_dict_getval(vendor, &data) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1362 vid = data.vendor_id; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1363 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1364 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1365 return fd_app_merge(&fd_g_config->cnf_apps, aid, vid, auth, acct); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1366 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1367 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1368 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1369 |