Mercurial > hg > freeDiameter
annotate freeDiameter/routing_dispatch.c @ 241:84460aa8d77b
NAI routing became RFC, update the reference...
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 18 Mar 2010 17:24:16 +0900 |
parents | 965f5971dc23 |
children | ad6c0118fb50 |
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) * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
5 * Copyright (c) 2009, WIDE Project and NICT * |
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 |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 #include "fD.h" |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
38 /********************************************************************************/ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
39 /* First part : handling the extensions callbacks */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
40 /********************************************************************************/ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
41 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
42 /* Lists of the callbacks, and locks to protect them */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
43 static pthread_rwlock_t rt_fwd_lock = PTHREAD_RWLOCK_INITIALIZER; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
44 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
|
45 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
46 static pthread_rwlock_t rt_out_lock = PTHREAD_RWLOCK_INITIALIZER; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
47 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
|
48 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
49 /* Items in the lists are the same */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
50 struct rt_hdl { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
51 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
|
52 void * cbdata; /* the registered data */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
53 union { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
54 int order; /* This value is used to sort the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
55 int dir; /* It is the direction for FWD handlers */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
56 int prio; /* and the priority for OUT handlers */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
57 }; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
58 union { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
59 int (*rt_fwd_cb)(void * cbdata, struct msg ** msg); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
60 int (*rt_out_cb)(void * cbdata, struct msg * msg, struct fd_list * candidates); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
61 }; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
62 }; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
63 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
64 /* Add a new entry in the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
65 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
|
66 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
67 /* The list is ordered by prio parameter */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
68 struct fd_list * li; |
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 CHECK_POSIX( pthread_rwlock_wrlock(list->o) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
71 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
72 for (li = list->next; li != list; li = li->next) { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
73 struct rt_hdl * h = (struct rt_hdl *) li; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
74 if (new->order <= h->order) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
75 break; |
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 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
78 fd_list_insert_before(li, &new->chain); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
79 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
80 CHECK_POSIX( pthread_rwlock_unlock(list->o) ); |
92
892219aef3bc
Add missing return value
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
90
diff
changeset
|
81 |
892219aef3bc
Add missing return value
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
90
diff
changeset
|
82 return 0; |
86
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 /* Register a new FWD callback */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
86 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
|
87 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
88 struct rt_hdl * new; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
89 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
90 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
|
91 CHECK_PARAMS( rt_fwd_cb ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
92 CHECK_PARAMS( (dir >= RT_FWD_REQ) && ( dir <= RT_FWD_ANS) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
93 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
94 /* Create a new container */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
95 CHECK_MALLOC(new = malloc(sizeof(struct rt_hdl))); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
96 memset(new, 0, sizeof(struct rt_hdl)); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
97 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
98 /* Write the content */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
99 fd_list_init(&new->chain, NULL); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
100 new->cbdata = cbdata; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
101 new->dir = dir; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
102 new->rt_fwd_cb = rt_fwd_cb; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
103 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
104 /* Save this in the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
105 CHECK_FCT( add_ordered(new, &rt_fwd_list) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
106 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
107 /* Give it back to the extension if needed */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
108 if (handler) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
109 *handler = (void *)new; |
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 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
112 } |
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 /* Remove it */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
115 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
|
116 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
117 struct rt_hdl * del; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
118 TRACE_ENTRY( "%p %p", handler, cbdata); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
119 CHECK_PARAMS( handler ); |
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 del = (struct rt_hdl *)handler; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
122 CHECK_PARAMS( del->chain.head == &rt_fwd_list ); |
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 /* Unlink */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
125 CHECK_POSIX( pthread_rwlock_wrlock(&rt_fwd_lock) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
126 fd_list_unlink(&del->chain); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
127 CHECK_POSIX( pthread_rwlock_unlock(&rt_fwd_lock) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
128 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
129 if (cbdata) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
130 *cbdata = del->cbdata; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
131 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
132 free(del); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
133 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
134 } |
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 /* Register a new OUT callback */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
137 int fd_rt_out_register ( int (*rt_out_cb)(void * cbdata, struct msg * msg, struct fd_list * candidates), void * cbdata, int priority, struct fd_rt_out_hdl ** handler ) |
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 struct rt_hdl * new; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
140 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
141 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
|
142 CHECK_PARAMS( rt_out_cb ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
143 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
144 /* Create a new container */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
145 CHECK_MALLOC(new = malloc(sizeof(struct rt_hdl))); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
146 memset(new, 0, sizeof(struct rt_hdl)); |
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 /* Write the content */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
149 fd_list_init(&new->chain, NULL); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
150 new->cbdata = cbdata; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
151 new->prio = priority; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
152 new->rt_out_cb = rt_out_cb; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
153 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
154 /* Save this in the list */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
155 CHECK_FCT( add_ordered(new, &rt_out_list) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
156 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
157 /* Give it back to the extension if needed */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
158 if (handler) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
159 *handler = (void *)new; |
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 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
162 } |
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 /* Remove it */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
165 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
|
166 { |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
167 struct rt_hdl * del; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
168 TRACE_ENTRY( "%p %p", handler, cbdata); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
169 CHECK_PARAMS( handler ); |
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 del = (struct rt_hdl *)handler; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
172 CHECK_PARAMS( del->chain.head == &rt_out_list ); |
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 /* Unlink */ |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
175 CHECK_POSIX( pthread_rwlock_wrlock(&rt_out_lock) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
176 fd_list_unlink(&del->chain); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
177 CHECK_POSIX( pthread_rwlock_unlock(&rt_out_lock) ); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
178 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
179 if (cbdata) |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
180 *cbdata = del->cbdata; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
181 |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
182 free(del); |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
183 return 0; |
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
184 } |
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 /********************************************************************************/ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
187 /* Some default OUT routing callbacks */ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
188 /********************************************************************************/ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
189 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
190 /* Prevent sending to peers that do not support the message application */ |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
191 static int dont_send_if_no_common_app(void * cbdata, struct msg * msg, struct fd_list * candidates) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
192 { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
193 struct fd_list * li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
194 struct msg_hdr * hdr; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
195 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
196 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
197 CHECK_PARAMS(msg && candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
198 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
199 CHECK_FCT( fd_msg_hdr(msg, &hdr) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
200 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
201 /* 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
|
202 if (hdr->msg_appl == 0) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
203 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
204 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
205 /* Otherwise, check that the peers support the application */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
206 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
|
207 struct rtd_candidate *c = (struct rtd_candidate *) li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
208 struct fd_peer * peer; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
209 struct fd_app *found; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
210 CHECK_FCT( fd_peer_getbyid( c->diamid, (void *)&peer ) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
211 if (peer && (peer->p_hdr.info.runtime.pir_relay == 0)) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
212 /* 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
|
213 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
|
214 if (!found) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
215 c->score += FD_SCORE_NO_DELIVERY; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
216 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
217 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
218 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
219 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
220 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
221 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
222 /* Detect if the Destination-Host and Destination-Realm match the peer */ |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
223 static int score_destination_avp(void * cbdata, struct msg * msg, struct fd_list * candidates) |
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 struct fd_list * li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
226 struct avp * avp; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
227 union avp_value *dh = NULL, *dr = NULL; |
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 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
230 CHECK_PARAMS(msg && candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
231 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
232 /* 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
|
233 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
|
234 while (avp) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
235 struct avp_hdr * ahdr; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
236 CHECK_FCT( fd_msg_avp_hdr( avp, &ahdr ) ); |
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 if (! (ahdr->avp_flags & AVP_FLAG_VENDOR)) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
239 switch (ahdr->avp_code) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
240 case AC_DESTINATION_HOST: |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
241 /* Parse this AVP */ |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
104
diff
changeset
|
242 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
|
243 ASSERT( ahdr->avp_value ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
244 dh = ahdr->avp_value; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
245 break; |
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 case AC_DESTINATION_REALM: |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
248 /* Parse this AVP */ |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
104
diff
changeset
|
249 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
|
250 ASSERT( ahdr->avp_value ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
251 dr = ahdr->avp_value; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
252 break; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
253 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
254 } |
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 if (dh && dr) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
257 break; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
258 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
259 /* Go to next AVP */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
260 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
|
261 } |
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 /* Now, check each candidate against these AVP values */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
264 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
|
265 struct rtd_candidate *c = (struct rtd_candidate *) li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
266 struct fd_peer * peer; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
267 CHECK_FCT( fd_peer_getbyid( c->diamid, (void *)&peer ) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
268 if (peer) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
269 if (dh |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
270 && (dh->os.len == strlen(peer->p_hdr.info.pi_diamid)) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
271 && (strncasecmp(peer->p_hdr.info.pi_diamid, dh->os.data, dh->os.len) == 0)) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
272 /* The candidate is the Destination-Host */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
273 c->score += FD_SCORE_FINALDEST; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
274 } else { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
275 if (dr && peer->p_hdr.info.runtime.pir_realm |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
276 && (dr->os.len == strlen(peer->p_hdr.info.runtime.pir_realm)) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
277 && (strncasecmp(peer->p_hdr.info.runtime.pir_realm, dr->os.data, dr->os.len) == 0)) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
278 /* The candidate's realm matchs the Destination-Realm */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
279 c->score += FD_SCORE_REALM; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
280 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
281 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
282 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
283 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
284 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
285 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
286 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
287 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
288 /********************************************************************************/ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
289 /* Helper functions */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
290 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
291 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
292 /* 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
|
293 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
|
294 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
295 int i; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
296 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
297 TRACE_ENTRY("%p %p %p", un, excl_idx, at_idx); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
298 CHECK_PARAMS_DO( un && excl_idx, return ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
299 *excl_idx = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
300 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
301 /* 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
|
302 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
|
303 /* 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
|
304 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
|
305 if (!*excl_idx) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
306 *excl_idx = i; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
307 if (!at_idx) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
308 return; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
309 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
310 /* 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
|
311 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
|
312 if (at_idx) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
313 *at_idx = i; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
314 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
315 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
316 /* Skip escaped characters */ |
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 i++; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
319 continue; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
320 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
321 /* Skip UTF-8 characters spanning on several bytes */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
322 if ( (un->os.data[i] & 0xF8) == 0xF0 ) { /* 11110zzz */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
323 i += 3; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
324 continue; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
325 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
326 if ( (un->os.data[i] & 0xF0) == 0xE0 ) { /* 1110yyyy */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
327 i += 2; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
328 continue; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
329 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
330 if ( (un->os.data[i] & 0xE0) == 0xC0 ) { /* 110yyyxx */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
331 i += 1; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
332 continue; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
333 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
334 } |
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 return; |
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 |
241
84460aa8d77b
NAI routing became RFC, update the reference...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
229
diff
changeset
|
339 /* Test if a User-Name AVP contains a Decorated NAI -- RFC4282, RFC5729 */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
340 static int is_decorated_NAI(union avp_value * un) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
341 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
342 int i; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
343 TRACE_ENTRY("%p", un); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
344 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
345 /* If there was no User-Name, we return false */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
346 if (un == NULL) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
347 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
348 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
349 nai_get_indexes(un, &i, NULL); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
350 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
351 return i; |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
354 /* Create new User-Name and Destination-Realm values */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
355 static int process_decorated_NAI(union avp_value * un, union avp_value * dr) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
356 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
357 int i, at_idx = 0, sep_idx = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
358 unsigned char * old_un; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
359 TRACE_ENTRY("%p %p", un, dr); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
360 CHECK_PARAMS(un && dr); |
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 /* 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
|
363 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
|
364 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
365 /* 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
|
366 nai_get_indexes(un, &sep_idx, &at_idx); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
367 CHECK_PARAMS( 0 < sep_idx < at_idx < un->os.len); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
368 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
369 /* 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
|
370 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
|
371 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
|
372 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
|
373 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
374 /* 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
|
375 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
|
376 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
|
377 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
|
378 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
379 TRACE_DEBUG(FULL, "Processed Decorated NAI : '%.*s' became '%.*s' (%.*s)", |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
380 un->os.len, old_un, |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
381 at_idx, un->os.data, |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
382 dr->os.len, dr->os.data); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
383 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
384 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
|
385 free(old_un); |
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 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
388 } |
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 /* 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
|
391 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
|
392 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
393 struct fd_peer * peer; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
394 int is_loc = 0; |
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 /* 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
|
397 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
398 char * id; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
399 CHECK_FCT( fd_msg_source_get( *pmsg, &id ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
400 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
401 if (id == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
402 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
|
403 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
404 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
405 /* Search the peer with this id */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
406 CHECK_FCT( fd_peer_getbyid( id, (void *)&peer ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
407 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
408 if (!peer) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
409 TRACE_DEBUG(INFO, "Unable to send error '%s' to deleted peer '%s' in reply to:", error_code, id); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
410 fd_msg_dump_walk(INFO, *pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
411 fd_msg_free(*pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
412 *pmsg = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
413 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
414 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
415 } |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
418 /* Create the error message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
419 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
|
420 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
421 /* Set the error code */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
422 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
|
423 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
424 /* Send the answer */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
425 if (is_loc) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
426 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
|
427 } else { |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
226
diff
changeset
|
428 CHECK_FCT( fd_out_send(pmsg, NULL, peer, 0) ); |
124
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 /* Done */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
432 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
433 } |
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 /****************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
437 /* 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
|
438 /****************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
439 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
440 /* These are the functions of each threads: dispatch & routing */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
441 /* The DISPATCH message processing */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
442 static int msg_dispatch(struct msg ** pmsg) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
443 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
444 struct msg_hdr * hdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
445 int is_req = 0, ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
446 struct session * sess; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
447 enum disp_action action; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
448 const char * ec = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
449 const char * em = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
450 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
451 /* Read the message header */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
452 CHECK_FCT( fd_msg_hdr(*pmsg, &hdr) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
453 is_req = hdr->msg_flags & CMD_FLAG_REQUEST; |
226
406f74f0789b
Few cosmetics changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
168
diff
changeset
|
454 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
455 /* 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
|
456 (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
|
457 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
458 /* At this point, we need to understand the message content, so parse it */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
459 CHECK_FCT_DO( ret = fd_msg_parse_or_error( pmsg ), |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
460 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
461 /* in case of error, the message is already dump'd */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
462 if ((ret == EBADMSG) && (*pmsg != NULL)) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
463 /* msg now contains the answer message to send back */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
464 CHECK_FCT( fd_fifo_post(fd_g_outgoing, pmsg) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
465 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
466 if (*pmsg) { /* another error happen'd */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
467 TRACE_DEBUG(INFO, "An unexpected error occurred (%s), discarding a message:", strerror(ret)); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
468 fd_msg_dump_walk(INFO, *pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
469 CHECK_FCT_DO( fd_msg_free(*pmsg), /* continue */); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
470 *pmsg = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
471 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
472 /* We're done with this one */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
473 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
474 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
475 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
476 /* 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
|
477 if ( ! is_req ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
478 struct msg * qry; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
479 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
|
480 void * data = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
481 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
482 /* Retrieve the corresponding query */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
483 CHECK_FCT( fd_msg_answ_getq( *pmsg, &qry ) ); |
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 any registered handler */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
486 CHECK_FCT( fd_msg_anscb_get( qry, &anscb, &data ) ); |
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 /* 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
|
489 if (anscb != NULL) { |
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 TRACE_DEBUG(FULL, "Calling callback registered when query was sent (%p, %p)", anscb, data); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
492 (*anscb)(data, pmsg); |
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 /* If the message is processed, we're done */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
495 if (*pmsg == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
496 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
497 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
498 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
499 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
500 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
501 /* Retrieve the session of the message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
502 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *pmsg, &sess, NULL) ); |
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 /* Now, call any callback registered for the message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
505 CHECK_FCT( fd_msg_dispatch ( pmsg, sess, &action, &ec) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
506 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
507 /* Now, act depending on msg and action and ec */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
508 if (*pmsg) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
509 switch ( action ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
510 case DISP_ACT_CONT: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
511 /* No callback has handled the message, let's reply with a generic error */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
512 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
|
513 ec = "DIAMETER_COMMAND_UNSUPPORTED"; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
514 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
515 case DISP_ACT_ERROR: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
516 /* 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
|
517 if (ec == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
518 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
|
519 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
520 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
521 if (!is_req) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
522 TRACE_DEBUG(INFO, "Received an answer to a localy issued query, but no handler processed this answer!"); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
523 fd_msg_dump_walk(INFO, *pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
524 fd_msg_free(*pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
525 *pmsg = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
526 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
527 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
528 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
529 /* Create an answer with the error code and message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
530 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, pmsg, 0 ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
531 CHECK_FCT( fd_msg_rescode_set(*pmsg, (char *)ec, (char *)em, NULL, 1 ) ); |
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 case DISP_ACT_SEND: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
534 /* Now, send the message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
535 CHECK_FCT( fd_fifo_post(fd_g_outgoing, pmsg) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
536 } |
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 /* 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
|
539 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
540 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
541 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
542 /* The ROUTING-IN message processing */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
543 static int msg_rt_in(struct msg ** pmsg) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
544 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
545 struct msg_hdr * hdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
546 int is_req = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
547 int is_err = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
548 char * qry_src = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
549 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
550 /* Read the message header */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
551 CHECK_FCT( fd_msg_hdr(*pmsg, &hdr) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
552 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
|
553 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
|
554 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
555 /* Handle incorrect bits */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
556 if (is_req && is_err) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
557 CHECK_FCT( return_error( pmsg, "DIAMETER_INVALID_HDR_BITS", "R & E bits were set", NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
558 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
559 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
560 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
561 /* 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
|
562 if (is_req) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 /* Are we Destination-Host? */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
567 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
|
568 /* Are we Destination-Realm? */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
569 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
|
570 /* 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
|
571 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
|
572 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
573 /* 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
|
574 if ( (hdr->msg_appl == 0) || (hdr->msg_appl == AI_RELAY) ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
575 TRACE_DEBUG(INFO, "Received a routable message with application id 0, returning DIAMETER_APPLICATION_UNSUPPORTED"); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
576 CHECK_FCT( return_error( pmsg, "DIAMETER_APPLICATION_UNSUPPORTED", "Routable message with application id 0 or relay", NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
577 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
578 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
579 struct fd_app * app; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
580 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
|
581 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
|
582 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
583 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
584 /* Parse the message for Dest-Host and Dest-Realm */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
585 CHECK_FCT( fd_msg_browse(*pmsg, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
586 while (avp) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
587 struct avp_hdr * ahdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
588 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
|
589 int ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
590 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
|
591 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
592 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
|
593 switch (ahdr->avp_code) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
594 case AC_DESTINATION_HOST: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
595 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
596 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
|
597 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
598 if (error_info.pei_errcode) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
599 CHECK_FCT( return_error( pmsg, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
600 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
601 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
602 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
603 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
604 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
605 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
606 /* Compare the Destination-Host AVP of the message with our identity */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
607 if (ahdr->avp_value->os.len != fd_g_config->cnf_diamid_len) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
608 is_dest_host = NO; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
609 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
610 is_dest_host = (strncasecmp(fd_g_config->cnf_diamid, (char *)ahdr->avp_value->os.data, fd_g_config->cnf_diamid_len) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
611 ? NO : YES); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
612 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
613 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
614 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
615 case AC_DESTINATION_REALM: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
616 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
617 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
|
618 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
619 if (error_info.pei_errcode) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
620 CHECK_FCT( return_error( pmsg, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
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 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
623 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
624 } |
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 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
627 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
|
628 /* Compare the Destination-Realm AVP of the message with our identity */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
629 if (ahdr->avp_value->os.len != fd_g_config->cnf_diamrlm_len) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
630 is_dest_realm = NO; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
631 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
632 is_dest_realm = (strncasecmp(fd_g_config->cnf_diamrlm, (char *)ahdr->avp_value->os.data, fd_g_config->cnf_diamrlm_len) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
633 ? NO : YES); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
634 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
635 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
636 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
637 case AC_USER_NAME: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
638 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
639 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
|
640 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
641 if (error_info.pei_errcode) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
642 CHECK_FCT( return_error( pmsg, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
643 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
644 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
645 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
646 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
647 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
648 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
649 un = avp; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
650 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
|
651 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
652 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
653 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
654 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
655 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
|
656 break; |
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 /* Go to next AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
659 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
|
660 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
661 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
662 /* 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
|
663 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
664 /* 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
|
665 if ( is_dest_realm == UNKNOWN ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
666 CHECK_FCT( return_error( pmsg, "DIAMETER_COMMAND_UNSUPPORTED", "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
667 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
668 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
669 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
670 /* 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
|
671 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
|
672 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
|
673 /* Ok, give the message to the dispatch thread */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
674 CHECK_FCT( fd_fifo_post(fd_g_local, pmsg) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
675 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
676 /* We don't support the application, reply an error */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
677 CHECK_FCT( return_error( pmsg, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
678 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
679 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
680 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
681 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
682 /* 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
|
683 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
|
684 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
|
685 CHECK_FCT( return_error( pmsg, "DIAMETER_UNABLE_TO_DELIVER", "This peer is not an agent", NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
686 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
687 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
688 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
689 /* Destination-Host was not set, and Destination-Realm is matching : we may handle or pass to a fellow peer */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
690 |
241
84460aa8d77b
NAI routing became RFC, update the reference...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
229
diff
changeset
|
691 /* test for decorated NAI (RFC5729 section 4.4) */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
692 if (is_decorated_NAI(un_val)) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
693 /* Handle the decorated NAI */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
694 CHECK_FCT_DO( process_decorated_NAI(un_val, dr_val), |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
695 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
696 /* If the process failed, we assume it is because of the AVP format */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
697 CHECK_FCT( return_error( pmsg, "DIAMETER_INVALID_AVP_VALUE", "Failed to process decorated NAI", un) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
698 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
699 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
700 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
701 /* We have transformed the AVP, now submit it again in the queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
702 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
|
703 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
704 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
705 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
706 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
|
707 /* Handle localy since we are able to */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
708 CHECK_FCT(fd_fifo_post(fd_g_local, pmsg) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
709 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
710 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
711 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
712 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
|
713 /* We return an error */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
714 CHECK_FCT( return_error( pmsg, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
715 return 0; |
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 } |
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 /* 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
|
720 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
721 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
722 /* 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
|
723 struct msg * qry; |
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 /* Retrieve the corresponding query and its origin */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
726 CHECK_FCT( fd_msg_answ_getq( *pmsg, &qry ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
727 CHECK_FCT( fd_msg_source_get( qry, &qry_src ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
728 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
729 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
|
730 /* The message is a normal answer to a request issued localy, we do not call the callbacks chain on it. */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
731 CHECK_FCT(fd_fifo_post(fd_g_local, pmsg) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
732 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
733 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
734 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
735 /* 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
|
736 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
737 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
738 /* 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
|
739 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
740 struct fd_list * li; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
741 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
742 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
|
743 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
|
744 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
745 /* requests: dir = 1 & 2 => in order; answers = 3 & 2 => in reverse order */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
746 for ( li = (is_req ? rt_fwd_list.next : rt_fwd_list.prev) ; *pmsg && (li != &rt_fwd_list) ; li = (is_req ? li->next : li->prev) ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
747 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
|
748 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
749 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
|
750 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
751 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
|
752 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
753 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
754 /* Ok, call this cb */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
755 TRACE_DEBUG(ANNOYING, "Calling next FWD callback on %p : %p", *pmsg, rh->rt_fwd_cb); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
756 CHECK_FCT_DO( (*rh->rt_fwd_cb)(rh->cbdata, pmsg), |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
757 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
758 TRACE_DEBUG(INFO, "A FWD routing callback returned an error, message discarded."); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
759 fd_msg_dump_walk(INFO, *pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
760 fd_msg_free(*pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
761 *pmsg = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
762 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
763 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
764 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
765 pthread_cleanup_pop(0); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
766 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
|
767 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
768 /* If a callback has handled the message, we stop now */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
769 if (!*pmsg) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
770 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
771 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
772 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
773 /* 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
|
774 if (is_req || qry_src) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
775 CHECK_FCT(fd_fifo_post(fd_g_outgoing, pmsg) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
776 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
777 CHECK_FCT(fd_fifo_post(fd_g_local, pmsg) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
778 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
779 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
780 /* 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
|
781 return 0; |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
785 /* The ROUTING-OUT message processing */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
786 static int msg_rt_out(struct msg ** pmsg) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
787 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
788 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
|
789 struct msg_hdr * hdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
790 int is_req = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
791 int ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
792 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
|
793 struct avp * avp; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
794 struct rtd_candidate * c; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
795 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
796 /* Read the message header */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
797 CHECK_FCT( fd_msg_hdr(*pmsg, &hdr) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
798 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
|
799 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
800 /* 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
|
801 if ( ! is_req ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
802 struct msg * qry; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
803 char * qry_src = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
804 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
|
805 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
|
806 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
807 /* Retrieve the corresponding query and its origin */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
808 CHECK_FCT( fd_msg_answ_getq( *pmsg, &qry ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
809 CHECK_FCT( fd_msg_source_get( qry, &qry_src ) ); |
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 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
|
812 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
813 /* Find the peer corresponding to this name */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
814 CHECK_FCT( fd_peer_getbyid( qry_src, (void *) &peer ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
815 if ((!peer) || (peer->p_hdr.info.runtime.pir_state != STATE_OPEN)) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
816 TRACE_DEBUG(INFO, "Unable to forward answer message to peer '%s', deleted or not in OPEN state.", qry_src); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
817 fd_msg_dump_walk(INFO, *pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
818 fd_msg_free(*pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
819 *pmsg = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
820 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
821 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
822 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
823 /* 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
|
824 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
|
825 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
|
826 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
827 /* Push the message into this peer */ |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
226
diff
changeset
|
828 CHECK_FCT( fd_out_send(pmsg, NULL, peer, 0) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
829 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
830 /* 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
|
831 return 0; |
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 /* From that point, the message is a request */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
835 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
836 /* Get the routing data out of the message if any (in case of re-transmit) */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
837 CHECK_FCT( fd_msg_rt_get ( *pmsg, &rtd ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
838 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
839 /* 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
|
840 if (rtd == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
841 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
|
842 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
843 /* Add all peers in OPEN state */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
844 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
|
845 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
|
846 struct fd_peer * p = (struct fd_peer *)li->o; |
168
6db078b955e3
Completed rt_default extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
164
diff
changeset
|
847 CHECK_FCT_DO( ret = fd_rtd_candidate_add(rtd, p->p_hdr.info.pi_diamid, p->p_hdr.info.runtime.pir_realm), { 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
|
848 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
849 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
|
850 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
851 /* Now let's remove all peers from the Route-Records */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
852 CHECK_FCT( fd_msg_browse(*pmsg, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
853 while (avp) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
854 struct avp_hdr * ahdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
855 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
|
856 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
|
857 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
858 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
|
859 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
860 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
|
861 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
862 if (error_info.pei_errcode) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
863 CHECK_FCT( return_error( pmsg, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
864 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
865 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
866 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
867 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
868 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
869 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
870 /* Remove this value from the list */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
871 fd_rtd_candidate_del(rtd, (char *)ahdr->avp_value->os.data, ahdr->avp_value->os.len); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
872 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
873 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
874 /* Go to next AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
875 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
|
876 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
877 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
878 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
879 /* 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 ? */ |
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 /* 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
|
882 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
|
883 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
884 /* Pass the list to registered callbacks (even if it is empty) */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
885 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
886 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
|
887 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
|
888 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
889 /* We call the cb by reverse priority order */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
890 for ( li = rt_out_list.prev ; li != &rt_out_list ; li = li->prev ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
891 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
|
892 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
893 TRACE_DEBUG(ANNOYING, "Calling next OUT callback on %p : %p (prio %d)", *pmsg, rh->rt_out_cb, rh->prio); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
894 CHECK_FCT_DO( ret = (*rh->rt_out_cb)(rh->cbdata, *pmsg, candidates), |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
895 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
896 TRACE_DEBUG(INFO, "An OUT routing callback returned an error (%s) ! Message discarded.", strerror(ret)); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
897 fd_msg_dump_walk(INFO, *pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
898 fd_msg_free(*pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
899 *pmsg = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
900 break; |
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 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
903 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
904 pthread_cleanup_pop(0); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
905 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
|
906 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
907 /* If an error occurred, skip to the next message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
908 if (! *pmsg) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
909 if (rtd) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
910 fd_rtd_free(&rtd); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
911 return 0; |
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 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
914 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
915 /* 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
|
916 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
|
917 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
918 /* Save the routing information in the message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
919 CHECK_FCT( fd_msg_rt_associate ( *pmsg, &rtd ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
920 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
921 /* 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
|
922 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
|
923 struct fd_peer * peer; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
924 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
925 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
|
926 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
927 /* 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
|
928 if (c->score < 0) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
929 break; |
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 /* Search for the peer */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
932 CHECK_FCT( fd_peer_getbyid( c->diamid, (void *)&peer ) ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
933 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
934 if (peer && (peer->p_hdr.info.runtime.pir_state == STATE_OPEN)) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
935 /* Send to this one */ |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
226
diff
changeset
|
936 CHECK_FCT_DO( fd_out_send(pmsg, NULL, peer, 0), continue ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
937 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
938 /* 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
|
939 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
940 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
941 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
942 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
943 /* If the message has not been sent, return an error */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
944 if (*pmsg) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
945 TRACE_DEBUG(INFO, "Could not send the following message, replying with UNABLE_TO_DELIVER"); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
946 fd_msg_dump_walk(INFO, *pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
947 return_error( pmsg, "DIAMETER_UNABLE_TO_DELIVER", "No suitable candidate to route the message to", NULL); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
948 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
949 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
950 /* 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
|
951 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
952 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
953 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
954 |
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 /* Management of the threads */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
958 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
959 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
960 /* 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
|
961 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
|
962 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
|
963 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
|
964 */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
965 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
966 /* Control of the threads */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
967 static enum { RUN = 0, STOP = 1 } order_val = RUN; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
968 static pthread_mutex_t order_lock = PTHREAD_MUTEX_INITIALIZER; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
969 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
970 /* Threads report their status */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
971 enum thread_state { INITIAL = 0, RUNNING = 1, TERMINATED = 2 }; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
972 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
|
973 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
974 if (state_loc) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
975 *(enum thread_state *)state_loc = TERMINATED; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
976 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
977 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
978 /* This is the common thread code (same for routing and dispatching) */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
979 static void * process_thr(void * arg, int (*action_cb)(struct msg ** pmsg), struct fifo * queue, char * action_name) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
980 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
981 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
|
982 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
983 /* Set the thread name */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
984 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
985 char buf[48]; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
986 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
|
987 fd_log_threadname ( buf ); |
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 /* 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
|
991 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
|
992 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
|
993 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
994 /* Mark the thread running */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
995 *(enum thread_state *)arg = RUNNING; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
996 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
997 do { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
998 struct msg * msg; |
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 /* Test the current order */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1001 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1002 int must_stop; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1003 CHECK_POSIX_DO( pthread_mutex_lock(&order_lock), goto end ); /* we lock to flush the caches */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1004 must_stop = (order_val == STOP); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1005 CHECK_POSIX_DO( pthread_mutex_unlock(&order_lock), goto end ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1006 if (must_stop) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1007 goto end; |
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 pthread_testcancel(); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1010 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1011 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1012 /* Ok, we are allowed to run */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1013 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1014 /* 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
|
1015 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1016 int ret; |
125
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1017 ret = fd_fifo_get ( queue, &msg ); |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1018 if (ret == EPIPE) |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1019 /* 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
|
1020 goto end; |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1021 |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1022 /* check if another error occurred */ |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1023 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
|
1024 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1025 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1026 if (TRACE_BOOL(FULL)) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1027 TRACE_DEBUG(FULL, "Picked next message"); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1028 fd_msg_dump_one(ANNOYING, msg); |
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 /* Now process the message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1032 CHECK_FCT_DO( (*action_cb)(&msg), goto fatal_error); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1033 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1034 /* 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
|
1035 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1036 } while (1); |
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 fatal_error: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1039 TRACE_DEBUG(INFO, "An unrecoverable error occurred, %s thread is terminating...", action_name); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1040 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1041 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1042 end: |
164 | 1043 ; /* 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
|
1044 /* 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
|
1045 pthread_cleanup_pop(1); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1046 return NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1047 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1048 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1049 /* The dispatch thread */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1050 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
|
1051 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1052 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
|
1053 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1054 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1055 /* 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
|
1056 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
|
1057 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1058 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
|
1059 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1060 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1061 /* 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
|
1062 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
|
1063 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1064 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
|
1065 } |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1068 /********************************************************************************/ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1069 /* The functions for the other files */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1070 /********************************************************************************/ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1071 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1072 /* Later: make this more dynamic */ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1073 static pthread_t dispatch = (pthread_t)NULL; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1074 static enum thread_state disp_state = INITIAL; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1075 |
88
9e2db1647d6f
Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
87
diff
changeset
|
1076 static pthread_t rt_out = (pthread_t)NULL; |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1077 static enum thread_state out_state = INITIAL; |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
1078 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1079 static pthread_t rt_in = (pthread_t)NULL; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1080 static enum thread_state in_state = INITIAL; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1081 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1082 /* Initialize the routing and dispatch threads */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1083 int fd_rtdisp_init(void) |
82 | 1084 { |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1085 CHECK_POSIX( pthread_create( &dispatch, NULL, dispatch_thr, &disp_state ) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1086 CHECK_POSIX( pthread_create( &rt_out, NULL, routing_out_thr, &out_state) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1087 CHECK_POSIX( pthread_create( &rt_in, NULL, routing_in_thr, &in_state) ); |
87 | 1088 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1089 /* 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
|
1090 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
1091 /* Register the built-in callbacks */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
1092 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
|
1093 CHECK_FCT( fd_rt_out_register( score_destination_avp, NULL, 10, NULL ) ); |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1094 return 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1095 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1096 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1097 /* 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
|
1098 int fd_rtdisp_cleanstop(void) |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1099 { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1100 CHECK_POSIX( pthread_mutex_lock(&order_lock) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1101 order_val = STOP; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1102 CHECK_POSIX( pthread_mutex_unlock(&order_lock) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1103 |
88
9e2db1647d6f
Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
87
diff
changeset
|
1104 return 0; |
82 | 1105 } |
1106 | |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1107 static void stop_thread_delayed(enum thread_state *st, pthread_t * thr, char * th_name) |
82 | 1108 { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1109 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
|
1110 CHECK_PARAMS_DO(st && thr, return); |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1111 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1112 /* Wait for a second for the thread to complete, by monitoring my_state */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1113 if (*st != TERMINATED) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1114 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
|
1115 do { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1116 struct timespec ts, ts_final; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1117 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1118 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
|
1119 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1120 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
|
1121 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
|
1122 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1123 while (TS_IS_INFERIOR( &ts, &ts_final )) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1124 if (*st == TERMINATED) |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1125 break; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1126 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1127 usleep(100000); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1128 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
|
1129 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1130 } while (0); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1131 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1132 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1133 /* 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
|
1134 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
|
1135 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1136 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1137 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1138 /* 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
|
1139 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
|
1140 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1141 /* Destroy the incoming queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1142 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
|
1143 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1144 /* Stop the routing IN thread */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1145 stop_thread_delayed(&in_state, &rt_in, "IN routing"); |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1146 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1147 /* Destroy the outgoing queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1148 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
|
1149 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1150 /* Stop the routing OUT thread */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1151 stop_thread_delayed(&out_state, &rt_out, "OUT routing"); |
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 /* Destroy the local queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1154 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
|
1155 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1156 /* Stop the Dispatch thread */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1157 stop_thread_delayed(&disp_state, &dispatch, "Dispatching"); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1158 |
122
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1159 return 0; |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1160 } |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1161 |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1162 /* Cleanup handlers */ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1163 int fd_rtdisp_cleanup(void) |
122
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1164 { |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1165 /* Cleanup all remaining handlers */ |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1166 while (!FD_IS_LIST_EMPTY(&rt_fwd_list)) { |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1167 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
|
1168 } |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1169 while (!FD_IS_LIST_EMPTY(&rt_out_list)) { |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1170 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
|
1171 } |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1172 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1173 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
|
1174 |
88
9e2db1647d6f
Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
87
diff
changeset
|
1175 return 0; |
82 | 1176 } |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
82
diff
changeset
|
1177 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
82
diff
changeset
|
1178 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1179 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1180 /* For extensiosn to register a new appl */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1181 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1182 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1183 /* 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
|
1184 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
|
1185 { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1186 application_id_t aid = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1187 vendor_id_t vid = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1188 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1189 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
|
1190 CHECK_PARAMS( app && (auth || acct) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1191 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1192 { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1193 enum dict_object_type type = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1194 struct dict_application_data data; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1195 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
|
1196 CHECK_PARAMS( type == DICT_APPLICATION ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1197 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
|
1198 aid = data.application_id; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1199 } |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
1200 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1201 if (vendor) { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1202 enum dict_object_type type = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1203 struct dict_vendor_data data; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1204 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
|
1205 CHECK_PARAMS( type == DICT_VENDOR ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1206 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
|
1207 vid = data.vendor_id; |
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 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
|
1211 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1212 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1213 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1214 |