Mercurial > hg > freeDiameter
annotate libfdcore/routing_dispatch.c @ 1281:ab6457399be2 1.2.1-rc1
Updated copyright information
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sat, 03 Jan 2015 02:23:28 +0800 |
parents | 681e8e55af27 |
children | f09f16f432e6 |
rev | line source |
---|---|
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
738
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
1281
ab6457399be2
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1274
diff
changeset
|
5 * Copyright (c) 2014, WIDE Project and NICT * |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
649
diff
changeset
|
36 #include "fdcore-internal.h" |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
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); |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
60 int (*rt_out_cb)(void * cbdata, struct msg ** msg, struct fd_list * candidates); |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
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 */ |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
137 int fd_rt_out_register ( int (*rt_out_cb)(void * cbdata, struct msg ** pmsg, struct fd_list * candidates), void * cbdata, int priority, struct fd_rt_out_hdl ** handler ) |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
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 */ |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
191 static int dont_send_if_no_common_app(void * cbdata, struct msg ** pmsg, struct fd_list * candidates) |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
192 { |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
193 struct msg * msg = *pmsg; |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
194 struct fd_list * li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
195 struct msg_hdr * hdr; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
196 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
197 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
198 CHECK_PARAMS(msg && candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
199 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
200 CHECK_FCT( fd_msg_hdr(msg, &hdr) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
201 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
202 /* 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
|
203 if (hdr->msg_appl == 0) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
204 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
205 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
206 /* Otherwise, check that the peers support the application */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
207 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
|
208 struct rtd_candidate *c = (struct rtd_candidate *) li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
209 struct fd_peer * peer; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
210 struct fd_app *found; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
211 CHECK_FCT( fd_peer_getbyid( c->diamid, c->diamidlen, 0, (void *)&peer ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
212 if (peer && !peer->p_hdr.info.runtime.pir_relay) { |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
213 /* 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
|
214 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
|
215 if (!found) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
216 c->score += FD_SCORE_NO_DELIVERY; |
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 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
220 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
221 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
222 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
223 /* Detect if the Destination-Host and Destination-Realm match the peer */ |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
224 static int score_destination_avp(void * cbdata, struct msg ** pmsg, struct fd_list * candidates) |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
225 { |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
226 struct msg * msg = *pmsg; |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
227 struct fd_list * li; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
228 struct avp * avp; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
229 union avp_value *dh = NULL, *dr = NULL; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
230 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
231 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
232 CHECK_PARAMS(msg && candidates); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
233 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
234 /* 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
|
235 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
|
236 while (avp) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
237 struct avp_hdr * ahdr; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
238 CHECK_FCT( fd_msg_avp_hdr( avp, &ahdr ) ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
239 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
240 if (! (ahdr->avp_flags & AVP_FLAG_VENDOR)) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
241 switch (ahdr->avp_code) { |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
242 case AC_DESTINATION_HOST: |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
243 /* Parse this AVP */ |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
104
diff
changeset
|
244 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
|
245 ASSERT( ahdr->avp_value ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
246 dh = ahdr->avp_value; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
247 break; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
248 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
249 case AC_DESTINATION_REALM: |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
250 /* Parse this AVP */ |
114
5b3868944e2b
Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
104
diff
changeset
|
251 CHECK_FCT( fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, NULL ) ); |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
252 ASSERT( ahdr->avp_value ); |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
253 dr = ahdr->avp_value; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
254 break; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
255 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
256 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
257 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
258 if (dh && dr) |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
259 break; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
260 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
261 /* Go to next AVP */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
262 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
|
263 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
264 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
265 /* Now, check each candidate against these AVP values */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
266 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
|
267 struct rtd_candidate *c = (struct rtd_candidate *) li; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
268 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
269 #if 0 /* this is actually useless since the sending process will also ensure that the peer is still available */ |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
270 struct fd_peer * peer; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
271 /* Since the candidates list comes from the peers list, we do not have any issue with upper/lower case to find the peer object */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
272 CHECK_FCT( fd_peer_getbyid( c->diamid, c->diamidlen, 0, (void *)&peer ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
273 if (!peer) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
274 continue; /* it has been deleted since the candidate list was generated; avoid sending to this one in that case. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
275 #endif /* 0 */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
276 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
277 /* In the AVPs, the value comes from the network, so let's be case permissive */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
278 if (dh && !fd_os_almostcasesrch(dh->os.data, dh->os.len, c->diamid, c->diamidlen, NULL) ) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
279 /* The candidate is the Destination-Host */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
280 c->score += FD_SCORE_FINALDEST; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
281 } else { |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
282 if (dr && !fd_os_almostcasesrch(dr->os.data, dr->os.len, c->realm, c->realmlen, NULL) ) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
283 /* The candidate's realm matchs the Destination-Realm */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
284 c->score += FD_SCORE_REALM; |
89
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
285 } |
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 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
288 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
289 return 0; |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
290 } |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
291 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
292 /********************************************************************************/ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
293 /* Helper functions */ |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
296 /* 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
|
297 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
|
298 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
299 int i; |
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 TRACE_ENTRY("%p %p %p", un, excl_idx, at_idx); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
302 CHECK_PARAMS_DO( un && excl_idx && at_idx, return ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
303 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
304 *excl_idx = 0; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
305 *at_idx = 0; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
306 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
307 /* 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
|
308 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
|
309 /* 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
|
310 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
|
311 if (!*excl_idx) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
312 *excl_idx = i; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
313 continue; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
314 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
315 /* 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
|
316 if ( un->os.data[i] == (unsigned char) '@' ) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
317 *at_idx = i; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
318 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
319 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
320 /* Stop if we find a \0 in the middle */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
321 if ( un->os.data[i] == 0 ) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
322 return; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
323 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
324 /* Skip escaped characters */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
325 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
|
326 i++; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
327 continue; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
328 } |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
331 return; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
332 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
333 |
241
84460aa8d77b
NAI routing became RFC, update the reference...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
229
diff
changeset
|
334 /* Test if a User-Name AVP contains a Decorated NAI -- RFC4282, RFC5729 */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
335 /* Create new User-Name and Destination-Realm values */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
336 static int process_decorated_NAI(int * was_nai, union avp_value * un, union avp_value * dr) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
337 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
338 int at_idx, sep_idx; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
339 unsigned char * old_un; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
340 TRACE_ENTRY("%p %p %p", was_nai, un, dr); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
341 CHECK_PARAMS(was_nai && un && dr); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
342 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
343 /* 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
|
344 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
|
345 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
346 /* 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
|
347 nai_get_indexes(un, &sep_idx, &at_idx); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
348 if ((!sep_idx) || (sep_idx > at_idx) || !fd_os_is_valid_DiameterIdentity(old_un, sep_idx /* this is the new realm part */)) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
349 *was_nai = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
350 return 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
351 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
352 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
353 *was_nai = 1; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
354 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
355 /* 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
|
356 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
|
357 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
|
358 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
|
359 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
360 /* 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
|
361 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
|
362 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
|
363 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
|
364 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
365 TRACE_DEBUG(FULL, "Processed Decorated NAI : '%.*s' became '%.*s' (%.*s)", |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1014
diff
changeset
|
366 (int)un->os.len, old_un, |
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1014
diff
changeset
|
367 (int)at_idx, un->os.data, |
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1014
diff
changeset
|
368 (int)dr->os.len, dr->os.data); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
369 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
370 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
|
371 free(old_un); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
372 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
373 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
374 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
375 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
376 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
377 /* 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
|
378 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
|
379 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
380 struct fd_peer * peer; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
381 int is_loc = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
382 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
383 /* 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
|
384 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
385 DiamId_t id; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
386 size_t idlen; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
387 CHECK_FCT( fd_msg_source_get( *pmsg, &id, &idlen ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
388 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
389 if (id == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
390 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
|
391 } else { |
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 /* Search the peer with this id */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
394 CHECK_FCT( fd_peer_getbyid( id, idlen, 0, (void *)&peer ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
395 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
396 if (!peer) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
397 char buf[256]; |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
398 snprintf(buf, sizeof(buf), "Unable to send error '%s' to deleted peer '%s' in reply to this message.", error_code, id); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
399 fd_hook_call(HOOK_MESSAGE_DROPPED, *pmsg, NULL, buf, fd_msg_pmdl_get(*pmsg)); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
400 fd_msg_free(*pmsg); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
401 *pmsg = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
402 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
403 } |
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 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
406 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
407 /* Create the error message */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
408 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
|
409 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
410 /* Set the error code */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
411 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
|
412 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
413 /* Send the answer */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
414 if (is_loc) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
415 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
|
416 } else { |
1238
8f9684264fe0
Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1230
diff
changeset
|
417 CHECK_FCT( fd_out_send(pmsg, NULL, peer, 1) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
418 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
419 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
420 /* Done */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
421 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
422 } |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
425 /****************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
426 /* 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
|
427 /****************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
428 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
429 /* The DISPATCH message processing */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
430 static int msg_dispatch(struct msg * msg) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
431 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
432 struct msg_hdr * hdr; |
1119
79dd22145f52
Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1113
diff
changeset
|
433 int is_req = 0; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
434 struct session * sess; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
435 enum disp_action action; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
436 char * ec = NULL; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
437 char * em = NULL; |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
438 struct msg *msgptr = msg, *error = NULL; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
439 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
440 /* Read the message header */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
441 CHECK_FCT( fd_msg_hdr(msg, &hdr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
442 is_req = hdr->msg_flags & CMD_FLAG_REQUEST; |
226
406f74f0789b
Few cosmetics changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
168
diff
changeset
|
443 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
444 /* 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
|
445 (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
|
446 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
447 /* At this point, we need to understand the message content, so parse it */ |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
448 CHECK_FCT_DO( fd_msg_parse_or_error( &msgptr, &error ), |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
449 { |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
450 int rescue = 0; |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
451 if (__ret__ != EBADMSG) { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
452 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, "Error while parsing received answer", fd_msg_pmdl_get(msgptr)); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
453 fd_msg_free(msgptr); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
454 } else { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
455 if (!msgptr) { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
456 /* error now contains the answer message to send back */ |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
457 CHECK_FCT( fd_fifo_post(fd_g_outgoing, &error) ); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
458 } else if (!error) { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
459 /* We have received an invalid answer to our query */ |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
460 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, "Received answer failed the dictionary / rules parsing", fd_msg_pmdl_get(msgptr)); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
461 fd_msg_free(msgptr); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
462 } else { |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
463 /* We will pass the invalid received error to the application */ |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
464 rescue = 1; |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
465 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
466 } |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
467 if (!rescue) |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1078
diff
changeset
|
468 return 0; /* We are done with this message, go to the next */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
469 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
470 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
471 /* 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
|
472 if ( ! is_req ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
473 struct msg * qry; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
474 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
|
475 void * data = NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
476 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
477 /* Retrieve the corresponding query */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
478 CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
479 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
480 /* Retrieve any registered handler */ |
1014
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
481 CHECK_FCT( fd_msg_anscb_get( qry, &anscb, NULL, &data ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
482 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
483 /* 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
|
484 if (anscb != NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
485 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
486 TRACE_DEBUG(FULL, "Calling callback registered when query was sent (%p, %p)", anscb, data); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
487 (*anscb)(data, &msgptr); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
488 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
489 /* If the message is processed, we're done */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
490 if (msgptr == NULL) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
491 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
492 } |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
493 |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
494 /* otherwise continue the dispatching --hoping that the anscb callback did not mess with our message :) */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
495 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
496 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
497 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
498 /* Retrieve the session of the message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
499 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, msgptr, &sess, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
500 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
501 /* Now, call any callback registered for the message */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
502 CHECK_FCT( fd_msg_dispatch ( &msgptr, sess, &action, &ec, &em, &error) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
503 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
504 /* Now, act depending on msg and action and ec */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
505 if (msgptr) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
506 switch ( action ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
507 case DISP_ACT_CONT: |
754
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
508 /* No callback has handled the message, let's reply with a generic error or relay it */ |
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
509 if (!fd_g_config->cnf_flags.no_fwd) { |
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
510 /* requeue to fd_g_outgoing */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
511 fd_hook_call(HOOK_MESSAGE_ROUTING_FORWARD, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
512 CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) ); |
754
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
513 break; |
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
514 } |
e02254d7d01b
Fix handling of message when no dispatch cb handled the message, to conform to documentation (thanks Zach for report)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
515 /* We don't relay => reply error */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
516 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
|
517 ec = "DIAMETER_COMMAND_UNSUPPORTED"; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
518 /* and continue as if an error occurred... */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
519 case DISP_ACT_ERROR: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
520 /* 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
|
521 if (ec == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
522 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
|
523 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
524 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
525 if (!is_req) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
526 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, "Internal error: Answer received to locally issued request, but not handled by any handler.", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
527 fd_msg_free(msgptr); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
528 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
529 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
530 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
531 /* Create an answer with the error code and message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
532 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, &msgptr, 0 ) ); |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
533 CHECK_FCT( fd_msg_rescode_set(msgptr, ec, em, NULL, 1 ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
534 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
535 case DISP_ACT_SEND: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
536 /* Now, send the message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
537 CHECK_FCT( fd_fifo_post(fd_g_outgoing, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
538 } |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
539 } else if (em) { |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
540 fd_hook_call(HOOK_MESSAGE_DROPPED, error, NULL, em, fd_msg_pmdl_get(error)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
541 fd_msg_free(error); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
542 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
543 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
544 /* 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
|
545 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
546 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
547 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
548 /* The ROUTING-IN message processing */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
549 static int msg_rt_in(struct msg * msg) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
550 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
551 struct msg_hdr * hdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
552 int is_req = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
553 int is_err = 0; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
554 DiamId_t qry_src = NULL; |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
555 struct msg *msgptr = msg; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
556 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
557 /* Read the message header */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
558 CHECK_FCT( fd_msg_hdr(msg, &hdr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
559 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
|
560 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
|
561 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
562 /* Handle incorrect bits */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
563 if (is_req && is_err) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
564 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "R & E bits were set", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
565 CHECK_FCT( return_error( &msgptr, "DIAMETER_INVALID_HDR_BITS", "R & E bits were set", NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
566 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
567 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
568 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
569 /* 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
|
570 if (is_req) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 /* Are we Destination-Host? */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
575 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
|
576 /* Are we Destination-Realm? */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
577 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
|
578 /* 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
|
579 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
|
580 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
581 /* 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
|
582 if ( (hdr->msg_appl == 0) || (hdr->msg_appl == AI_RELAY) ) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
583 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Received a routable message with application id 0 or " _stringize(AI_RELAY) " (relay)", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
584 CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", "Routable message with application id 0 or relay", NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
585 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
586 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
587 struct fd_app * app; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
588 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
|
589 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
|
590 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
591 |
1154
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
592 /* Parse the message for Dest-Host, Dest-Realm, and Route-Record */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
593 CHECK_FCT( fd_msg_browse(msgptr, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
594 while (avp) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
595 struct avp_hdr * ahdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
596 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
|
597 int ret; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
598 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
599 memset(&error_info, 0, sizeof(struct fd_pei)); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
600 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
601 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
|
602 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
603 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
|
604 switch (ahdr->avp_code) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
605 case AC_DESTINATION_HOST: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
606 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
607 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
|
608 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
609 if (error_info.pei_errcode) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
610 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
611 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
612 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
613 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
614 } else { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
615 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing Destination-Host AVP", fd_msg_pmdl_get(msgptr)); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
616 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
617 } |
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 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
620 /* Compare the Destination-Host AVP of the message with our identity */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
621 if (!fd_os_almostcasesrch(ahdr->avp_value->os.data, ahdr->avp_value->os.len, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, NULL)) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
622 is_dest_host = YES; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
623 } else { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
624 is_dest_host = NO; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
625 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
626 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
627 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
628 case AC_DESTINATION_REALM: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
629 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
630 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
|
631 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
632 if (error_info.pei_errcode) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
633 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
634 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
635 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
636 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
637 } else { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
638 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing Destination-Realm AVP", fd_msg_pmdl_get(msgptr)); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
639 return ret; |
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 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
642 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
643 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
|
644 /* Compare the Destination-Realm AVP of the message with our identity */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
645 if (!fd_os_almostcasesrch(dr_val->os.data, dr_val->os.len, fd_g_config->cnf_diamrlm, fd_g_config->cnf_diamrlm_len, NULL)) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
646 is_dest_realm = YES; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
647 } else { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
648 is_dest_realm = NO; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
649 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
650 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
651 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
652 /* we also use User-Name for decorated NAI */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
653 case AC_USER_NAME: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
654 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
655 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
|
656 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
657 if (error_info.pei_errcode) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
658 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
659 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
660 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
661 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
662 } else { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
663 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing User-Name AVP", fd_msg_pmdl_get(msgptr)); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
664 return ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
665 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
666 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
667 ASSERT( ahdr->avp_value ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
668 un = avp; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
669 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
|
670 break; |
1154
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
671 |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
672 case AC_ROUTE_RECORD: |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
673 /* Parse this AVP */ |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
674 CHECK_FCT_DO( ret = fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, &error_info ), |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
675 { |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
676 if (error_info.pei_errcode) { |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
677 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error_info.pei_message ?: error_info.pei_errcode, fd_msg_pmdl_get(msgptr)); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
678 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
679 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
1154
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
680 return 0; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
681 } else { |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
682 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Unspecified error while parsing Route-Record AVP", fd_msg_pmdl_get(msgptr)); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
683 return ret; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
684 } |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
685 } ); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
686 ASSERT( ahdr->avp_value ); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
687 /* Is this our own name ? */ |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
688 if (!fd_os_almostcasesrch(ahdr->avp_value->os.data, ahdr->avp_value->os.len, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, NULL)) { |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
689 /* Yes: then we must return DIAMETER_LOOP_DETECTED according to Diameter RFC */ |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
690 char * error = "DIAMETER_LOOP_DETECTED"; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
691 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, error, fd_msg_pmdl_get(msgptr)); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
692 CHECK_FCT( return_error( &msgptr, error, NULL, NULL) ); |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
693 return 0; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
694 } |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
695 break; |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
696 |
0b95a3afbfc3
Return DIAMETER_LOOP_DETECTED if local peer is already in the Route-Record AVP of a new received request.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
697 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
698 } |
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 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
701 /* Stop when we found all 3 AVPs -- they are supposed to be at the beginning of the message, so this should be fast */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
702 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
|
703 break; |
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 /* Go to next AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
706 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
|
707 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
708 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
709 /* 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
|
710 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
711 /* 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
|
712 if ( is_dest_realm == UNKNOWN ) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
713 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
714 CHECK_FCT( return_error( &msgptr, "DIAMETER_COMMAND_UNSUPPORTED", "Non-routable message not supported (invalid bit ? missing Destination-Realm ?)", NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
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 /* 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
|
719 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
|
720 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
|
721 /* Ok, give the message to the dispatch thread */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
722 fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
723 CHECK_FCT( fd_fifo_post(fd_g_local, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
724 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
725 /* We don't support the application, reply an error */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
726 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Application unsupported", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
727 CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
728 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
729 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
730 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
731 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
732 /* 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
|
733 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
|
734 if (fd_g_config->cnf_flags.no_fwd) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
735 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "Message for another realm/host", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
736 CHECK_FCT( return_error( &msgptr, "DIAMETER_UNABLE_TO_DELIVER", "I am not a Diameter agent", NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
737 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
738 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
739 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
740 /* Destination-Host was not set, and Destination-Realm is matching : we may handle or pass to a fellow peer */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
741 int is_nai = 0; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
742 |
241
84460aa8d77b
NAI routing became RFC, update the reference...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
229
diff
changeset
|
743 /* test for decorated NAI (RFC5729 section 4.4) */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
744 /* Handle the decorated NAI */ |
712
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
745 if (un_val) { |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
746 CHECK_FCT_DO( process_decorated_NAI(&is_nai, un_val, dr_val), |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
747 { |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
748 /* If the process failed, we assume it is because of the AVP format */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
749 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR, msgptr, NULL, "Failed to process decorated NAI", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
750 CHECK_FCT( return_error( &msgptr, "DIAMETER_INVALID_AVP_VALUE", "Failed to process decorated NAI", un) ); |
712
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
751 return 0; |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
752 } ); |
886e935f7513
Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
753 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
754 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
755 if (is_nai) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
756 /* We have transformed the AVP, now submit it again in the queue */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
757 CHECK_FCT(fd_fifo_post(fd_g_incoming, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
758 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
759 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
760 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
761 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
|
762 /* Handle localy since we are able to */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
763 fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
764 CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
765 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
766 } |
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 (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
|
769 /* We return an error */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
770 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "Application unsupported", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
771 CHECK_FCT( return_error( &msgptr, "DIAMETER_APPLICATION_UNSUPPORTED", NULL, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
772 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
773 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
774 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
775 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
776 /* 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
|
777 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
778 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
779 /* 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
|
780 struct msg * qry; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
781 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
782 /* Retrieve the corresponding query and its origin */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
783 CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) ); |
1120
c473581adff2
Cleanup some traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1119
diff
changeset
|
784 CHECK_FCT( fd_msg_source_get( qry, &qry_src, NULL ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
785 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
786 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
|
787 /* The message is a normal answer to a request issued localy, we do not call the callbacks chain on it. */ |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
788 fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
789 CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
790 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
791 } |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
715
diff
changeset
|
792 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
793 /* 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
|
794 } |
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 /* 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
|
797 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
798 struct fd_list * li; |
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 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
|
801 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
|
802 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
803 /* requests: dir = 1 & 2 => in order; answers = 3 & 2 => in reverse order */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
804 for ( li = (is_req ? rt_fwd_list.next : rt_fwd_list.prev) ; msgptr && (li != &rt_fwd_list) ; li = (is_req ? li->next : li->prev) ) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
805 struct rt_hdl * rh = (struct rt_hdl *)li; |
688
8c3dc8584dab
Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
806 int ret; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
807 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
808 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
|
809 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
810 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
|
811 break; |
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 /* Ok, call this cb */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
814 TRACE_DEBUG(ANNOYING, "Calling next FWD callback on %p : %p", msgptr, rh->rt_fwd_cb); |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
815 CHECK_FCT_DO( ret = (*rh->rt_fwd_cb)(rh->cbdata, &msgptr), |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
816 { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
817 char buf[256]; |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
818 snprintf(buf, sizeof(buf), "A FWD routing callback returned an error: %s", strerror(ret)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
819 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
820 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
821 fd_msg_free(msgptr); |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
822 msgptr = NULL; |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
823 break; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
824 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
825 } |
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 pthread_cleanup_pop(0); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
828 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
|
829 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
830 /* If a callback has handled the message, we stop now */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
831 if (!msgptr) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
832 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
833 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
834 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
835 /* 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
|
836 if (is_req || qry_src) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
837 fd_hook_call(HOOK_MESSAGE_ROUTING_FORWARD, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
838 CHECK_FCT(fd_fifo_post(fd_g_outgoing, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
839 } else { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
840 fd_hook_call(HOOK_MESSAGE_ROUTING_LOCAL, msgptr, NULL, NULL, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
841 CHECK_FCT(fd_fifo_post(fd_g_local, &msgptr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
842 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
843 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
844 /* 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
|
845 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
846 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
847 |
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 /* The ROUTING-OUT message processing */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
850 static int msg_rt_out(struct msg * msg) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
851 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
852 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
|
853 struct msg_hdr * hdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
854 int is_req = 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
855 int ret; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
856 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
|
857 struct avp * avp; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
858 struct rtd_candidate * c; |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
859 struct msg *msgptr = msg; |
1014
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
860 DiamId_t qry_src = NULL; |
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
861 size_t qry_src_len = 0; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
862 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
863 /* Read the message header */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
864 CHECK_FCT( fd_msg_hdr(msgptr, &hdr) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
865 is_req = hdr->msg_flags & CMD_FLAG_REQUEST; |
649
5e5d8152c229
Implemented fd_msg_send_timeout to close #10. Not tested yet.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
563
diff
changeset
|
866 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
867 /* 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
|
868 if ( ! is_req ) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
869 struct msg * qry; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
870 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
|
871 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
|
872 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
873 /* Retrieve the corresponding query and its origin */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
874 CHECK_FCT( fd_msg_answ_getq( msgptr, &qry ) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
875 CHECK_FCT( fd_msg_source_get( qry, &qry_src, &qry_src_len ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
876 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
877 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
|
878 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
879 /* Find the peer corresponding to this name */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
880 CHECK_FCT( fd_peer_getbyid( qry_src, qry_src_len, 0, (void *) &peer ) ); |
1274
681e8e55af27
Allow routing messages in state CLOSING_GRACE.
Thomas Klausner <tk@giga.or.at>
parents:
1238
diff
changeset
|
881 if (fd_peer_getstate(peer) != STATE_OPEN && fd_peer_getstate(peer) != STATE_CLOSING_GRACE) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
882 char buf[128]; |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
883 snprintf(buf, sizeof(buf), "Unable to forward answer to deleted / closed peer '%s'.", qry_src); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
884 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
885 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
886 fd_msg_free(msgptr); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
887 return 0; |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
890 /* 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
|
891 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
|
892 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
|
893 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
894 /* Push the message into this peer */ |
1238
8f9684264fe0
Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1230
diff
changeset
|
895 CHECK_FCT( fd_out_send(&msgptr, NULL, peer, 1) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
896 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
897 /* 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
|
898 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
899 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
900 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
901 /* From that point, the message is a request */ |
1014
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
902 CHECK_FCT( fd_msg_source_get( msgptr, &qry_src, &qry_src_len ) ); |
908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
903 /* if qry_src != NULL, this message is relayed, otherwise it is locally issued */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
904 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
905 /* Get the routing data out of the message if any (in case of re-transmit) */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
906 CHECK_FCT( fd_msg_rt_get ( msgptr, &rtd ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
907 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
908 /* 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
|
909 if (rtd == NULL) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
910 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
|
911 |
563
dc9764591567
Automatic load-balancing between peers that have the same routing score. Use rt_ereg to obtain stable routes.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
912 /* Add all peers currently in OPEN state */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
913 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
|
914 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
|
915 struct fd_peer * p = (struct fd_peer *)li->o; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
916 CHECK_FCT_DO( ret = fd_rtd_candidate_add(rtd, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
917 p->p_hdr.info.pi_diamid, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
918 p->p_hdr.info.pi_diamidlen, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
919 p->p_hdr.info.runtime.pir_realm, |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
920 p->p_hdr.info.runtime.pir_realmlen), |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
921 { 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
|
922 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
923 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
|
924 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
925 /* Now let's remove all peers from the Route-Records */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
926 CHECK_FCT( fd_msg_browse(msgptr, MSG_BRW_FIRST_CHILD, &avp, NULL) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
927 while (avp) { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
928 struct avp_hdr * ahdr; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
929 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
|
930 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
|
931 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
932 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
|
933 /* Parse this AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
934 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
|
935 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
936 if (error_info.pei_errcode) { |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
937 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, error_info.pei_avp) ); |
1230
e72c9dad62ac
Fix issue with generating Failed-AVP when the error is DIAMETER_MISSING_AVP. Also fix a memory leak in that case
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1216
diff
changeset
|
938 if (error_info.pei_avp_free) { fd_msg_free(error_info.pei_avp); } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
939 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
940 } else { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
941 return ret; |
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 } ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
944 ASSERT( ahdr->avp_value ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
945 /* Remove this value from the list. We don't need to pay special attention to the contents here. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
946 fd_rtd_candidate_del(rtd, ahdr->avp_value->os.data, ahdr->avp_value->os.len); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
947 } |
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 /* Go to next AVP */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
950 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
|
951 } |
1212
c38bb8b69c43
Fix message rtd handling for extensions based on this data
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
952 |
c38bb8b69c43
Fix message rtd handling for extensions based on this data
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
953 /* Save the routing information in the message */ |
c38bb8b69c43
Fix message rtd handling for extensions based on this data
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
954 CHECK_FCT( fd_msg_rt_associate ( msgptr, rtd ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
955 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
956 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
957 /* Note: we reset the scores and pass the message to the callbacks, maybe we could re-use the saved scores when we have received an error ? -- TODO */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
958 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
959 /* 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
|
960 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
|
961 |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
962 /* Pass the list to registered callbacks (even if it is empty list) */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
963 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
964 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
|
965 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
|
966 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
967 /* We call the cb by reverse priority order */ |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
968 for ( li = rt_out_list.prev ; (msgptr != NULL) && (li != &rt_out_list) ; li = li->prev ) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
969 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
|
970 |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
971 TRACE_DEBUG(ANNOYING, "Calling next OUT callback on %p : %p (prio %d)", msgptr, rh->rt_out_cb, rh->prio); |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
972 CHECK_FCT_DO( ret = (*rh->rt_out_cb)(rh->cbdata, &msgptr, candidates), |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
973 { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
974 char buf[256]; |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
975 snprintf(buf, sizeof(buf), "An OUT routing callback returned an error: %s", strerror(ret)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
976 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
977 fd_hook_call(HOOK_MESSAGE_DROPPED, msgptr, NULL, buf, fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
978 fd_msg_free(msgptr); |
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
979 msgptr = NULL; |
124
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 } |
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 pthread_cleanup_pop(0); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
984 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
|
985 |
1216
581bbd48524a
Change prototype of rt_out callbacks to allow disposal of messages
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1212
diff
changeset
|
986 /* If an error occurred or the callback disposed of the message, go to next message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
987 if (! msgptr) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
988 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
989 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
990 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
991 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
992 /* 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
|
993 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
|
994 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
995 /* 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
|
996 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
|
997 struct fd_peer * peer; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
998 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
999 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
|
1000 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1001 /* 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
|
1002 if (c->score < 0) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1003 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1004 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1005 /* Search for the peer */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1006 CHECK_FCT( fd_peer_getbyid( c->diamid, c->diamidlen, 0, (void *)&peer ) ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1007 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1008 if (fd_peer_getstate(peer) == STATE_OPEN) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1009 /* Send to this one */ |
1238
8f9684264fe0
Change management of the p_reqin_count counter to be updated only on routable messages. This should limit the errors in the counter value resulting from rejected or discarded link-local messages.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1230
diff
changeset
|
1010 CHECK_FCT_DO( fd_out_send(&msgptr, NULL, peer, 1), continue ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1011 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1012 /* 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
|
1013 break; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1014 } |
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 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1017 /* If the message has not been sent, return an error */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
1018 if (msgptr) { |
1113
eb4ce68b6e5c
Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
1019 fd_hook_call(HOOK_MESSAGE_ROUTING_ERROR, msgptr, NULL, "No remaining suitable candidate to route the message to", fd_msg_pmdl_get(msgptr)); |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
1020 return_error( &msgptr, "DIAMETER_UNABLE_TO_DELIVER", "No suitable candidate to route the message to", NULL); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1021 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1022 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1023 /* 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
|
1024 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1025 return 0; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1026 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1027 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1028 |
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 /* Management of the threads */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1031 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1032 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1033 /* 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
|
1034 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
|
1035 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
|
1036 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
|
1037 */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1038 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1039 /* Control of the threads */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1040 static enum { RUN = 0, STOP = 1 } order_val = RUN; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1041 static pthread_mutex_t order_state_lock = PTHREAD_MUTEX_INITIALIZER; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1042 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1043 /* Threads report their status */ |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1044 enum thread_state { NOTRUNNING = 0, RUNNING = 1 }; |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1045 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
|
1046 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1047 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1048 *(enum thread_state *)state_loc = NOTRUNNING; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1049 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1050 } |
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 /* This is the common thread code (same for routing and dispatching) */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
1053 static void * process_thr(void * arg, int (*action_cb)(struct msg * msg), struct fifo * queue, char * action_name) |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1054 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1055 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
|
1056 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1057 /* Set the thread name */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1058 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1059 char buf[48]; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1060 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
|
1061 fd_log_threadname ( buf ); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1062 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1063 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1064 /* 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
|
1065 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
|
1066 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
|
1067 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1068 /* Mark the thread running */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1069 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1070 *(enum thread_state *)arg = RUNNING; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1071 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1072 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1073 do { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1074 struct msg * msg; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1075 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1076 /* Test the current order */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1077 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1078 int must_stop; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1079 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), { ASSERT(0); } ); /* we lock to flush the caches */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1080 must_stop = (order_val == STOP); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1081 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), { ASSERT(0); } ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1082 if (must_stop) |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1083 goto end; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1084 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1085 pthread_testcancel(); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1086 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1087 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1088 /* 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
|
1089 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1090 /* 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
|
1091 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1092 int ret; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1093 struct timespec ts; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1094 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1095 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), goto fatal_error ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1096 ts.tv_sec += 1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1097 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1098 ret = fd_fifo_timedget ( queue, &msg, &ts ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1099 if (ret == ETIMEDOUT) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1100 /* loop, check if the thread must stop now */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1101 continue; |
125
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1102 if (ret == EPIPE) |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1103 /* 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
|
1104 goto end; |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1105 |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1106 /* check if another error occurred */ |
b424df830a82
Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
124
diff
changeset
|
1107 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
|
1108 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1109 |
1119
79dd22145f52
Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1113
diff
changeset
|
1110 LOG_A("%s: Picked next message", action_name); |
1037
4f5eb63aef96
In TRACE_DEBUG, mention which thread we're in (Routing-IN/Routing-OUT/Dispatch).
Thomas Klausner <tk@giga.or.at>
parents:
1027
diff
changeset
|
1111 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1112 /* Now process the message */ |
934
977a5375543c
Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents:
754
diff
changeset
|
1113 CHECK_FCT_DO( (*action_cb)(msg), goto fatal_error); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1114 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1115 /* 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
|
1116 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1117 } while (1); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1118 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1119 fatal_error: |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1120 TRACE_DEBUG(INFO, "An unrecoverable error occurred, %s thread is terminating...", action_name); |
1190
6a1042d8075b
Replace FDEV_TERMINATE events with calls to fd_core_shutdown to handle the core state properly
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
1121 CHECK_FCT_DO(fd_core_shutdown(), ); |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1122 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1123 end: |
164 | 1124 ; /* 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
|
1125 /* 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
|
1126 pthread_cleanup_pop(1); |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1127 return NULL; |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1128 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1129 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1130 /* The dispatch thread */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1131 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
|
1132 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1133 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
|
1134 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1135 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1136 /* The (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
|
1137 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
|
1138 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1139 return process_thr(arg, msg_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
|
1140 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1141 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1142 /* The (routing-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
|
1143 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
|
1144 { |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1145 return process_thr(arg, msg_rt_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
|
1146 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1147 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1148 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1149 /********************************************************************************/ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1150 /* The functions for the other files */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1151 /********************************************************************************/ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1152 |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1153 static pthread_t * dispatch = NULL; |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1154 static enum thread_state * disp_state = NULL; |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1155 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1156 /* Later: make this more dynamic */ |
88
9e2db1647d6f
Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
87
diff
changeset
|
1157 static pthread_t rt_out = (pthread_t)NULL; |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1158 static enum thread_state out_state = NOTRUNNING; |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
1159 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1160 static pthread_t rt_in = (pthread_t)NULL; |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1161 static enum thread_state in_state = NOTRUNNING; |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1162 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1163 /* Initialize the routing and dispatch threads */ |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1164 int fd_rtdisp_init(void) |
82 | 1165 { |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1166 int i; |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1167 |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1168 /* Prepare the array for dispatch */ |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1169 CHECK_MALLOC( disp_state = calloc(fd_g_config->cnf_dispthr, sizeof(enum thread_state)) ); |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1170 CHECK_MALLOC( dispatch = calloc(fd_g_config->cnf_dispthr, sizeof(pthread_t)) ); |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1171 |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1172 /* Create the threads */ |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1173 for (i=0; i < fd_g_config->cnf_dispthr; i++) { |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1174 CHECK_POSIX( pthread_create( &dispatch[i], NULL, dispatch_thr, &disp_state[i] ) ); |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1175 } |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1176 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
|
1177 CHECK_POSIX( pthread_create( &rt_in, NULL, routing_in_thr, &in_state) ); |
87 | 1178 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1179 /* 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
|
1180 |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
1181 /* Register the built-in callbacks */ |
3f8b437bcb66
Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
88
diff
changeset
|
1182 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
|
1183 CHECK_FCT( fd_rt_out_register( score_destination_avp, NULL, 10, NULL ) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1184 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1185 return 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1186 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1187 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1188 /* 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
|
1189 int fd_rtdisp_cleanstop(void) |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1190 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1191 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1192 order_val = STOP; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1193 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1194 |
88
9e2db1647d6f
Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
87
diff
changeset
|
1195 return 0; |
82 | 1196 } |
1197 | |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1198 static void stop_thread_delayed(enum thread_state *st, pthread_t * thr, char * th_name) |
82 | 1199 { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1200 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
|
1201 CHECK_PARAMS_DO(st && thr, return); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1202 int terminated; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1203 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1204 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1205 terminated = (*st == NOTRUNNING); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1206 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1207 |
123
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 /* Wait for a second for the thread to complete, by monitoring my_state */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1210 if (!terminated) { |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1211 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
|
1212 do { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1213 struct timespec ts, ts_final; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1214 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1215 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
|
1216 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1217 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
|
1218 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
|
1219 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1220 while (TS_IS_INFERIOR( &ts, &ts_final )) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1221 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1222 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1223 terminated = (*st == NOTRUNNING); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1224 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
1225 if (terminated) |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1226 break; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1227 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1228 usleep(100000); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1229 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
|
1230 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1231 } while (0); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1232 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1233 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1234 /* 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
|
1235 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
|
1236 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1237 } |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1238 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1239 /* 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
|
1240 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
|
1241 { |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1242 int i; |
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1243 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1244 /* Destroy the incoming queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1245 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
|
1246 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1247 /* 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
|
1248 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
|
1249 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1250 /* Destroy the outgoing queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1251 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
|
1252 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1253 /* 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
|
1254 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
|
1255 |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1256 /* Destroy the local queue */ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1257 CHECK_FCT_DO( fd_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
|
1258 |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1259 /* Stop the Dispatch threads */ |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1260 if (dispatch != NULL) { |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1261 for (i=0; i < fd_g_config->cnf_dispthr; i++) { |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1262 stop_thread_delayed(&disp_state[i], &dispatch[i], "Dispatching"); |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1263 } |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1264 free(dispatch); |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1265 dispatch = NULL; |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1266 } |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1267 if (disp_state != NULL) { |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1268 free(disp_state); |
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1269 disp_state = NULL; |
253
ad6c0118fb50
Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
241
diff
changeset
|
1270 } |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1271 |
122
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1272 return 0; |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1273 } |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1274 |
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1275 /* Cleanup handlers */ |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1276 int fd_rtdisp_cleanup(void) |
122
e66a82a739fa
Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
114
diff
changeset
|
1277 { |
90
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1278 /* Cleanup all remaining handlers */ |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1279 while (!FD_IS_LIST_EMPTY(&rt_fwd_list)) { |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1280 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
|
1281 } |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1282 while (!FD_IS_LIST_EMPTY(&rt_out_list)) { |
2c9444152e4b
Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
89
diff
changeset
|
1283 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
|
1284 } |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1285 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1286 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
|
1287 |
88
9e2db1647d6f
Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
87
diff
changeset
|
1288 return 0; |
82 | 1289 } |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
82
diff
changeset
|
1290 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
82
diff
changeset
|
1291 |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1292 /********************************************************************************/ |
1055 | 1293 /* For extensions to register a new appl */ |
124
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1294 /********************************************************************************/ |
cc42d8607114
Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
123
diff
changeset
|
1295 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1296 /* 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
|
1297 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
|
1298 { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1299 application_id_t aid = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1300 vendor_id_t vid = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1301 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1302 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
|
1303 CHECK_PARAMS( app && (auth || acct) ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1304 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1305 { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1306 enum dict_object_type type = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1307 struct dict_application_data data; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1308 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
|
1309 CHECK_PARAMS( type == DICT_APPLICATION ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1310 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
|
1311 aid = data.application_id; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1312 } |
86
e3e22d89e023
Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
1313 |
123
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1314 if (vendor) { |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1315 enum dict_object_type type = 0; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1316 struct dict_vendor_data data; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1317 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
|
1318 CHECK_PARAMS( type == DICT_VENDOR ); |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1319 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
|
1320 vid = data.vendor_id; |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1321 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1322 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1323 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
|
1324 } |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1325 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1326 |
960fa8048805
Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
122
diff
changeset
|
1327 |