annotate libfdcore/routing_dispatch.c @ 1119:79dd22145f52

Fix a number of compilation warnings
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 14 May 2013 11:04:20 +0800
parents eb4ce68b6e5c
children c473581adff2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 * *
662
2e94ef0515d7 Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 658
diff changeset
5 * Copyright (c) 2011, 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);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
60 int (*rt_out_cb)(void * cbdata, struct msg * msg, struct fd_list * candidates);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
61 };
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
62 };
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
63
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
64 /* Add a new entry in the list */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
65 static int add_ordered(struct rt_hdl * new, struct fd_list * list)
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
66 {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
67 /* The list is ordered by prio parameter */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
68 struct fd_list * li;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
69
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
70 CHECK_POSIX( pthread_rwlock_wrlock(list->o) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
71
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
72 for (li = list->next; li != list; li = li->next) {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
73 struct rt_hdl * h = (struct rt_hdl *) li;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
74 if (new->order <= h->order)
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
75 break;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
76 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
77
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
78 fd_list_insert_before(li, &new->chain);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
79
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
80 CHECK_POSIX( pthread_rwlock_unlock(list->o) );
92
892219aef3bc Add missing return value
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 90
diff changeset
81
892219aef3bc Add missing return value
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 90
diff changeset
82 return 0;
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
83 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
84
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
85 /* Register a new FWD callback */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
86 int fd_rt_fwd_register ( int (*rt_fwd_cb)(void * cbdata, struct msg ** msg), void * cbdata, enum fd_rt_fwd_dir dir, struct fd_rt_fwd_hdl ** handler )
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
87 {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
88 struct rt_hdl * new;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
89
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
90 TRACE_ENTRY("%p %p %d %p", rt_fwd_cb, cbdata, dir, handler);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
91 CHECK_PARAMS( rt_fwd_cb );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
92 CHECK_PARAMS( (dir >= RT_FWD_REQ) && ( dir <= RT_FWD_ANS) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
93
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
94 /* Create a new container */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
95 CHECK_MALLOC(new = malloc(sizeof(struct rt_hdl)));
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
96 memset(new, 0, sizeof(struct rt_hdl));
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
97
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
98 /* Write the content */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
99 fd_list_init(&new->chain, NULL);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
100 new->cbdata = cbdata;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
101 new->dir = dir;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
102 new->rt_fwd_cb = rt_fwd_cb;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
103
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
104 /* Save this in the list */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
105 CHECK_FCT( add_ordered(new, &rt_fwd_list) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
106
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
107 /* Give it back to the extension if needed */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
108 if (handler)
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
109 *handler = (void *)new;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
110
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
111 return 0;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
112 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
113
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
114 /* Remove it */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
115 int fd_rt_fwd_unregister ( struct fd_rt_fwd_hdl * handler, void ** cbdata )
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
116 {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
117 struct rt_hdl * del;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
118 TRACE_ENTRY( "%p %p", handler, cbdata);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
119 CHECK_PARAMS( handler );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
120
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
121 del = (struct rt_hdl *)handler;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
122 CHECK_PARAMS( del->chain.head == &rt_fwd_list );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
123
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
124 /* Unlink */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
125 CHECK_POSIX( pthread_rwlock_wrlock(&rt_fwd_lock) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
126 fd_list_unlink(&del->chain);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
127 CHECK_POSIX( pthread_rwlock_unlock(&rt_fwd_lock) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
128
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
129 if (cbdata)
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
130 *cbdata = del->cbdata;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
131
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
132 free(del);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
133 return 0;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
134 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
135
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
136 /* Register a new OUT callback */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
137 int fd_rt_out_register ( int (*rt_out_cb)(void * cbdata, struct msg * msg, struct fd_list * candidates), void * cbdata, int priority, struct fd_rt_out_hdl ** handler )
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
138 {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
139 struct rt_hdl * new;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
140
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
141 TRACE_ENTRY("%p %p %d %p", rt_out_cb, cbdata, priority, handler);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
142 CHECK_PARAMS( rt_out_cb );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
143
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
144 /* Create a new container */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
145 CHECK_MALLOC(new = malloc(sizeof(struct rt_hdl)));
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
146 memset(new, 0, sizeof(struct rt_hdl));
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
147
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
148 /* Write the content */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
149 fd_list_init(&new->chain, NULL);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
150 new->cbdata = cbdata;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
151 new->prio = priority;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
152 new->rt_out_cb = rt_out_cb;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
153
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
154 /* Save this in the list */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
155 CHECK_FCT( add_ordered(new, &rt_out_list) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
156
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
157 /* Give it back to the extension if needed */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
158 if (handler)
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
159 *handler = (void *)new;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
160
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
161 return 0;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
162 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
163
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
164 /* Remove it */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
165 int fd_rt_out_unregister ( struct fd_rt_out_hdl * handler, void ** cbdata )
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
166 {
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
167 struct rt_hdl * del;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
168 TRACE_ENTRY( "%p %p", handler, cbdata);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
169 CHECK_PARAMS( handler );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
170
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
171 del = (struct rt_hdl *)handler;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
172 CHECK_PARAMS( del->chain.head == &rt_out_list );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
173
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
174 /* Unlink */
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
175 CHECK_POSIX( pthread_rwlock_wrlock(&rt_out_lock) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
176 fd_list_unlink(&del->chain);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
177 CHECK_POSIX( pthread_rwlock_unlock(&rt_out_lock) );
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
178
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
179 if (cbdata)
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
180 *cbdata = del->cbdata;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
181
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
182 free(del);
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
183 return 0;
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
184 }
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
185
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
186 /********************************************************************************/
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
187 /* Some default OUT routing callbacks */
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
188 /********************************************************************************/
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
189
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
190 /* Prevent sending to peers that do not support the message application */
89
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
191 static int dont_send_if_no_common_app(void * cbdata, struct msg * msg, struct fd_list * candidates)
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
192 {
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
193 struct fd_list * li;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
194 struct msg_hdr * hdr;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
195
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
196 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
197 CHECK_PARAMS(msg && candidates);
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
198
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
199 CHECK_FCT( fd_msg_hdr(msg, &hdr) );
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
200
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
201 /* For Base Diameter Protocol, every peer is supposed to support it, so skip */
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
202 if (hdr->msg_appl == 0)
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
203 return 0;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
204
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
205 /* Otherwise, check that the peers support the application */
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
206 for (li = candidates->next; li != candidates; li = li->next) {
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
207 struct rtd_candidate *c = (struct rtd_candidate *) li;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
208 struct fd_peer * peer;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
209 struct fd_app *found;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
210 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
211 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
212 /* Check if the remote peer advertised the message's appli */
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
213 CHECK_FCT( fd_app_check(&peer->p_hdr.info.runtime.pir_apps, hdr->msg_appl, &found) );
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
214 if (!found)
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
215 c->score += FD_SCORE_NO_DELIVERY;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
216 }
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
217 }
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
218
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
219 return 0;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
220 }
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
221
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
222 /* Detect if the Destination-Host and Destination-Realm match the peer */
89
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
223 static int score_destination_avp(void * cbdata, struct msg * msg, struct fd_list * candidates)
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
224 {
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
225 struct fd_list * li;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
226 struct avp * avp;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
227 union avp_value *dh = NULL, *dr = NULL;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
228
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
229 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
230 CHECK_PARAMS(msg && candidates);
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
231
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
232 /* Search the Destination-Host and Destination-Realm AVPs -- we could also use fd_msg_search_avp here, but this one is slightly more efficient */
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
233 CHECK_FCT( fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &avp, NULL) );
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
234 while (avp) {
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
235 struct avp_hdr * ahdr;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
236 CHECK_FCT( fd_msg_avp_hdr( avp, &ahdr ) );
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
237
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
238 if (! (ahdr->avp_flags & AVP_FLAG_VENDOR)) {
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
239 switch (ahdr->avp_code) {
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
240 case AC_DESTINATION_HOST:
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
241 /* Parse this AVP */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 104
diff changeset
242 CHECK_FCT( fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, NULL ) );
89
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
243 ASSERT( ahdr->avp_value );
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
244 dh = ahdr->avp_value;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
245 break;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
246
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
247 case AC_DESTINATION_REALM:
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
248 /* Parse this AVP */
114
5b3868944e2b Reporting errors in parse_dict function
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 104
diff changeset
249 CHECK_FCT( fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, NULL ) );
89
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
250 ASSERT( ahdr->avp_value );
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
251 dr = ahdr->avp_value;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
252 break;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
253 }
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
254 }
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
255
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
256 if (dh && dr)
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
257 break;
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
258
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
259 /* Go to next AVP */
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
260 CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) );
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
261 }
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
262
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
263 /* Now, check each candidate against these AVP values */
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
264 for (li = candidates->next; li != candidates; li = li->next) {
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
265 struct rtd_candidate *c = (struct rtd_candidate *) li;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
266
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
267 #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
268 struct fd_peer * peer;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
269 /* 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
270 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
271 if (!peer)
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
272 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
273 #endif /* 0 */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
274
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
275 /* 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
276 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
277 /* The candidate is the Destination-Host */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
278 c->score += FD_SCORE_FINALDEST;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
279 } else {
738
d666051658bd Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 717
diff changeset
280 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
281 /* 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
282 c->score += FD_SCORE_REALM;
89
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
283 }
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
284 }
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
285 }
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 return 0;
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
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
290 /********************************************************************************/
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
291 /* Helper functions */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
292 /********************************************************************************/
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
293
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
294 /* 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
295 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
296 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
297 int i;
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 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
300 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
301
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
302 *excl_idx = 0;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
303 *at_idx = 0;
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
304
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
305 /* 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
306 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
307 /* 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
308 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
309 if (!*excl_idx)
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
310 *excl_idx = i;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
311 continue;
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
312 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
313 /* 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
314 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
315 *at_idx = i;
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
316 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
317 }
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
318 /* 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
319 if ( un->os.data[i] == 0 ) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
320 return;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
321 }
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
322 /* Skip escaped characters */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
323 if ( un->os.data[i] == (unsigned char) '\\' ) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
324 i++;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
325 continue;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
326 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
327 }
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 return;
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
241
84460aa8d77b NAI routing became RFC, update the reference...
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 229
diff changeset
332 /* 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
333 /* 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
334 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
335 {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
336 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
337 unsigned char * old_un;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
338 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
339 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
340
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
341 /* 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
342 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
343
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
344 /* 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
345 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
346 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
347 *was_nai = 0;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
348 return 0;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
349 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
350
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
351 *was_nai = 1;
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
352
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
353 /* 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
354 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
355 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
356 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
357
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
358 /* 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
359 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
360 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
361 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
362
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
363 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
364 (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
365 (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
366 (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
367
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
368 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
369 free(old_un);
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
370
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
371 return 0;
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
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
374
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
375 /* 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
376 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
377 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
378 struct fd_peer * peer;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
379 int is_loc = 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
380
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
381 /* 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
382 {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
383 DiamId_t id;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
384 size_t idlen;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
385 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
386
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
387 if (id == NULL) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
388 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
389 } else {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
390
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
391 /* 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
392 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
393
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
394 if (!peer) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
395 char buf[256];
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
396 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
397 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
398 fd_msg_free(*pmsg);
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
399 *pmsg = NULL;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
400 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
401 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
402 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
403 }
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 /* Create the error message */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
406 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
407
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
408 /* Set the error code */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
409 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
410
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
411 /* Send the answer */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
412 if (is_loc) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
413 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
414 } else {
229
965f5971dc23 Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 226
diff changeset
415 CHECK_FCT( fd_out_send(pmsg, NULL, peer, 0) );
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
416 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
417
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
418 /* Done */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
419 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
420 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
421
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 /* 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
425 /****************************************************************************/
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
426
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
427 /* The DISPATCH message processing */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
428 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
429 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
430 struct msg_hdr * hdr;
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
431 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
432 struct session * sess;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
433 enum disp_action action;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
434 char * ec = NULL;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
435 char * em = NULL;
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
436 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
437
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
438 /* Read the message header */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
439 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
440 is_req = hdr->msg_flags & CMD_FLAG_REQUEST;
226
406f74f0789b Few cosmetics changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 168
diff changeset
441
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
442 /* 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
443 (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
444
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
445 /* 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
446 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
447 {
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
448 int rescue = 0;
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
449 if (__ret__ != EBADMSG) {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
450 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
451 fd_msg_free(msgptr);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
452 } else {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
453 if (!msgptr) {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
454 /* error now contains the answer message to send back */
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
455 CHECK_FCT( fd_fifo_post(fd_g_outgoing, &error) );
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
456 } else if (!error) {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
457 /* We have received an invalid answer to our query */
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
458 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
459 fd_msg_free(msgptr);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
460 } else {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
461 /* We will pass the invalid received error to the application */
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
462 rescue = 1;
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
463 }
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
464 }
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
465 if (!rescue)
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1078
diff changeset
466 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
467 } );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
468
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
469 /* 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
470 if ( ! is_req ) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
471 struct msg * qry;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
472 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
473 void * data = NULL;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
474
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
475 /* Retrieve the corresponding query */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
476 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
477
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
478 /* 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
479 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
480
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
481 /* 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
482 if (anscb != NULL) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
483
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
484 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
485 (*anscb)(data, &msgptr);
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
486
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
487 /* If the message is processed, we're done */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
488 if (msgptr == NULL) {
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
489 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
490 }
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
491
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
492 /* 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
493 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
494 }
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 /* Retrieve the session of the message */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
497 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
498
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
499 /* Now, call any callback registered for the message */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
500 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
501
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
502 /* 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
503 if (msgptr) {
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
504 switch ( action ) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
505 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
506 /* 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
507 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
508 /* requeue to fd_g_outgoing */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
509 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
510 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
511 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
512 }
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 /* 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
514 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
515 ec = "DIAMETER_COMMAND_UNSUPPORTED";
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
516 /* 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
517 case DISP_ACT_ERROR:
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
518 /* 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
519 if (ec == NULL) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
520 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
521 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
522
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
523 if (!is_req) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
524 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
525 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
526 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
527 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
528
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
529 /* Create an answer with the error code and message */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
530 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
531 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
532
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
533 case DISP_ACT_SEND:
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
534 /* Now, send the message */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
535 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
536 }
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
537 } else if (em) {
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
538 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
539 fd_msg_free(error);
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
540 }
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
541
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
542 /* 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
543 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
544 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
545
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
546 /* The ROUTING-IN message processing */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
547 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
548 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
549 struct msg_hdr * hdr;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
550 int is_req = 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
551 int is_err = 0;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
552 DiamId_t qry_src = NULL;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
553 size_t qry_src_len = 0;
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
554 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
555
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
556 /* Read the message header */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
557 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
558 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
559 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
560
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
561 /* Handle incorrect bits */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
562 if (is_req && is_err) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
563 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
564 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
565 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
566 }
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 /* 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
569 if (is_req) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
570 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
571 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
572 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
573 /* Are we Destination-Host? */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
574 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
575 /* Are we Destination-Realm? */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
576 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
577 /* 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
578 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
579
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
580 /* 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
581 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
582 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
583 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
584 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
585 } else {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
586 struct fd_app * app;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
587 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
588 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
589 }
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 /* Parse the message for Dest-Host and Dest-Realm */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
592 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
593 while (avp) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
594 struct avp_hdr * ahdr;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
595 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
596 int ret;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
597
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
598 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
599
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
600 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
601
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
602 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
603 switch (ahdr->avp_code) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
604 case AC_DESTINATION_HOST:
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
605 /* Parse this AVP */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
606 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
607 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
608 if (error_info.pei_errcode) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
609 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
610 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, 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
611 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
612 } else {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
613 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
614 return ret;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
615 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
616 } );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
617 ASSERT( ahdr->avp_value );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
618 /* 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
619 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
620 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
621 } else {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
622 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
623 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
624 break;
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 case AC_DESTINATION_REALM:
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
627 /* Parse this AVP */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
628 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
629 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
630 if (error_info.pei_errcode) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
631 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
632 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, 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
633 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
634 } else {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
635 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
636 return ret;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
637 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
638 } );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
639 ASSERT( ahdr->avp_value );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
640 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
641 /* 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
642 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
643 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
644 } else {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
645 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
646 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
647 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
648
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
649 /* 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
650 case AC_USER_NAME:
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
651 /* Parse this AVP */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
652 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
653 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
654 if (error_info.pei_errcode) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
655 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
656 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, 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
657 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
658 } else {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
659 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
660 return ret;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
661 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
662 } );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
663 ASSERT( ahdr->avp_value );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
664 un = avp;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
665 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
666 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
667 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
668 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
669
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
670 /* 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
671 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
672 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
673
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
674 /* Go to next AVP */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
675 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
676 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
677
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
678 /* 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
679
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
680 /* 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
681 if ( is_dest_realm == UNKNOWN ) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
682 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
683 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
684 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
685 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
686
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
687 /* 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
688 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
689 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
690 /* Ok, give the message to the dispatch thread */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
691 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
692 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
693 } else {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
694 /* 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
695 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
696 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
697 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
698 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
699 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
700
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
701 /* 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
702 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
703 if (fd_g_config->cnf_flags.no_fwd) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
704 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
705 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
706 return 0;
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 } else {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
709 /* 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
710 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
711
241
84460aa8d77b NAI routing became RFC, update the reference...
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 229
diff changeset
712 /* 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
713 /* 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
714 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
715 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
716 {
886e935f7513 Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
717 /* 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
718 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
719 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
720 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
721 } );
886e935f7513 Fixed decorated NAI handing in case of messages without User-Name AVP
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
722 }
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
723
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
724 if (is_nai) {
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
725 /* 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
726 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
727 return 0;
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
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
730 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
731 /* Handle localy since we are able to */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
732 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
733 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
734 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
735 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
736
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
737 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
738 /* We return an error */
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
739 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
740 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
741 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
742 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
743 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
744
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
745 /* 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
746
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
747 } else {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
748 /* 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
749 struct msg * qry;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
750
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
751 /* Retrieve the corresponding query and its origin */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
752 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
753 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
754
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
755 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
756 /* 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
757 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
758 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
759 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
760 }
717
571b3abaa5df Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 715
diff changeset
761
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
762 /* 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
763 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
764
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
765 /* 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
766 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
767 struct fd_list * li;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
768
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
769 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
770 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
771
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
772 /* 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
773 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
774 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
775 int ret;
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
776
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
777 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
778 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
779 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
780 break;
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 /* Ok, call this cb */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
783 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
784 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
785 {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
786 char buf[256];
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
787 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
788 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
789 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
790 fd_msg_free(msgptr);
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
791 msgptr = NULL;
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
792 break;
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
793 } );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
794 }
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 pthread_cleanup_pop(0);
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
797 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
798
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
799 /* 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
800 if (!msgptr)
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
801 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
802 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
803
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
804 /* 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
805 if (is_req || qry_src) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
806 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
807 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
808 } else {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
809 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
810 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
811 }
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 /* 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
814 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
815 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
816
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
817
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
818 /* The ROUTING-OUT message processing */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
819 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
820 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
821 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
822 struct msg_hdr * hdr;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
823 int is_req = 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
824 int ret;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
825 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
826 struct avp * avp;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
827 struct rtd_candidate * c;
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
828 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
829 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
830 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
831
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
832 /* Read the message header */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
833 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
834 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
835
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
836 /* 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
837 if ( ! is_req ) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
838 struct msg * qry;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
839 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
840 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
841
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
842 /* Retrieve the corresponding query and its origin */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
843 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
844 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
845
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
846 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
847
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
848 /* 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
849 CHECK_FCT( fd_peer_getbyid( qry_src, qry_src_len, 0, (void *) &peer ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
850 if (fd_peer_getstate(peer) != STATE_OPEN) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
851 char buf[128];
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
852 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
853 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
854 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
855 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
856 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
857 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
858
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
859 /* 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
860 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
861 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
862
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
863 /* Push the message into this peer */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
864 CHECK_FCT( fd_out_send(&msgptr, NULL, peer, 0) );
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
865
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
866 /* 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
867 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
868 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
869
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
870 /* 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
871 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
872 /* 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
873
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
874 /* 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
875 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
876
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
877 /* 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
878 if (rtd == NULL) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
879 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
880
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
881 /* 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
882 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
883 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
884 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
885 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
886 p->p_hdr.info.pi_diamid,
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
887 p->p_hdr.info.pi_diamidlen,
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
888 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
889 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
890 { 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
891 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
892 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
893
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
894 /* 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
895 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
896 while (avp) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
897 struct avp_hdr * ahdr;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
898 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
899 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
900
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
901 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
902 /* Parse this AVP */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
903 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
904 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
905 if (error_info.pei_errcode) {
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
906 CHECK_FCT( return_error( &msgptr, error_info.pei_errcode, error_info.pei_message, 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
907 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
908 } else {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
909 return ret;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
910 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
911 } );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
912 ASSERT( ahdr->avp_value );
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
913 /* 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
914 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
915 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
916
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
917 /* Go to next AVP */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
918 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
919 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
920 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
921
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
922 /* 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
923
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
924 /* 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
925 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
926
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
927 /* 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
928 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
929 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
930 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
931
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
932 /* We call the cb by reverse priority order */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
933 for ( li = rt_out_list.prev ; li != &rt_out_list ; li = li->prev ) {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
934 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
935
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
936 TRACE_DEBUG(ANNOYING, "Calling next OUT callback on %p : %p (prio %d)", msgptr, rh->rt_out_cb, rh->prio);
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
937 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
938 {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
939 char buf[256];
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
940 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
941 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
942 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
943 fd_msg_free(msgptr);
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
944 msgptr = NULL;
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
945 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
946 } );
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 pthread_cleanup_pop(0);
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
950 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
951
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
952 /* If an error occurred, skip to the next message */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
953 if (! msgptr) {
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
954 if (rtd)
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
955 fd_rtd_free(&rtd);
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
956 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
957 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
958 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
959
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
960 /* 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
961 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
962
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
963 /* Save the routing information in the message */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
964 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
965
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
966 /* 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
967 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
968 struct fd_peer * peer;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
969
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
970 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
971
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
972 /* 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
973 if (c->score < 0)
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
974 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
975
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
976 /* Search for the peer */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
977 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
978
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
979 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
980 /* Send to this one */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
981 CHECK_FCT_DO( fd_out_send(&msgptr, NULL, peer, 0), continue );
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
982
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
983 /* 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
984 break;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
985 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
986 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
987
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
988 /* 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
989 if (msgptr) {
1113
eb4ce68b6e5c Added calls to remaining hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1103
diff changeset
990 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
991 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
992 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
993
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
994 /* 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
995
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
996 return 0;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
997 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
998
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
999
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1000 /********************************************************************************/
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1001 /* Management of the threads */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1002 /********************************************************************************/
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1003
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1004 /* 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
1005 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
1006 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
1007 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
1008 */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1009
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1010 /* Control of the threads */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1011 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
1012 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
1013
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1014 /* 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
1015 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
1016 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
1017 {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1018 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
1019 *(enum thread_state *)state_loc = NOTRUNNING;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1020 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
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 /* 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
1024 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
1025 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1026 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
1027
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1028 /* Set the thread name */
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 char buf[48];
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1031 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
1032 fd_log_threadname ( buf );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1033 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1034
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1035 /* 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
1036 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
1037 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
1038
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1039 /* Mark the thread running */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1040 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
1041 *(enum thread_state *)arg = RUNNING;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1042 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
1043
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1044 do {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1045 struct msg * msg;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1046
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1047 /* Test the current order */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1048 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1049 int must_stop;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1050 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
1051 must_stop = (order_val == STOP);
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1052 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
1053 if (must_stop)
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1054 goto end;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1055
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1056 pthread_testcancel();
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1057 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1058
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1059 /* 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
1060
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1061 /* 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
1062 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1063 int ret;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1064 struct timespec ts;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1065
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1066 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
1067 ts.tv_sec += 1;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1068
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1069 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
1070 if (ret == ETIMEDOUT)
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1071 /* 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
1072 continue;
125
b424df830a82 Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 124
diff changeset
1073 if (ret == EPIPE)
b424df830a82 Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 124
diff changeset
1074 /* 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
1075 goto end;
b424df830a82 Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 124
diff changeset
1076
b424df830a82 Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 124
diff changeset
1077 /* check if another error occurred */
b424df830a82 Suppress error message for normal exit situation
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 124
diff changeset
1078 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
1079 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1080
1119
79dd22145f52 Fix a number of compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1113
diff changeset
1081 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
1082
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1083 /* Now process the message */
934
977a5375543c Remove one stupid indirection level
Sebastien Decugis <sdecugis@freediameter.net>
parents: 754
diff changeset
1084 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
1085
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1086 /* 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
1087
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1088 } while (1);
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 fatal_error:
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1091 TRACE_DEBUG(INFO, "An unrecoverable error occurred, %s thread is terminating...", action_name);
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1092 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1093
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1094 end:
164
6f6fd233b923 Fix Debian warning
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 125
diff changeset
1095 ; /* 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
1096 /* 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
1097 pthread_cleanup_pop(1);
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1098 return NULL;
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1099 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1100
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1101 /* The dispatch thread */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1102 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
1103 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1104 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
1105 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1106
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1107 /* 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
1108 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
1109 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1110 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
1111 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1112
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1113 /* 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
1114 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
1115 {
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1116 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
1117 }
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
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1120 /********************************************************************************/
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1121 /* The functions for the other files */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1122 /********************************************************************************/
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1123
253
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1124 static pthread_t * dispatch = NULL;
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1125 static enum thread_state * disp_state = NULL;
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1126
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1127 /* Later: make this more dynamic */
88
9e2db1647d6f Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 87
diff changeset
1128 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
1129 static enum thread_state out_state = NOTRUNNING;
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
1130
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1131 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
1132 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
1133
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1134 /* Initialize the routing and dispatch threads */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1135 int fd_rtdisp_init(void)
82
b6344f1d521a Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 41
diff changeset
1136 {
253
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1137 int i;
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1138
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1139 /* 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
1140 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
1141 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
1142
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1143 /* Create the threads */
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1144 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
1145 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
1146 }
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1147 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
1148 CHECK_POSIX( pthread_create( &rt_in, NULL, routing_in_thr, &in_state) );
87
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 86
diff changeset
1149
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1150 /* 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
1151
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
1152 /* Register the built-in callbacks */
3f8b437bcb66 Added some default routing handlers
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 88
diff changeset
1153 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
1154 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
1155
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1156 return 0;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1157 }
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1158
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1159 /* 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
1160 int fd_rtdisp_cleanstop(void)
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1161 {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1162 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
1163 order_val = STOP;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1164 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
1165
88
9e2db1647d6f Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 87
diff changeset
1166 return 0;
82
b6344f1d521a Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 41
diff changeset
1167 }
b6344f1d521a Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 41
diff changeset
1168
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1169 static void stop_thread_delayed(enum thread_state *st, pthread_t * thr, char * th_name)
82
b6344f1d521a Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 41
diff changeset
1170 {
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1171 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
1172 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
1173 int terminated;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1174
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1175 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
1176 terminated = (*st == NOTRUNNING);
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1177 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
1178
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1179
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1180 /* 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
1181 if (!terminated) {
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1182 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
1183 do {
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1184 struct timespec ts, ts_final;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1185
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1186 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
1187
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1188 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
1189 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
1190
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1191 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
1192
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1193 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
1194 terminated = (*st == NOTRUNNING);
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
1195 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
1196 if (terminated)
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1197 break;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1198
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1199 usleep(100000);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1200 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
1201 }
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1202 } while (0);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1203 }
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1204
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1205 /* 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
1206 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
1207
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1208 }
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1209
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1210 /* 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
1211 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
1212 {
253
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1213 int i;
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1214
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1215 /* Destroy the incoming queue */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1216 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
1217
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1218 /* 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
1219 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
1220
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1221 /* Destroy the outgoing queue */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1222 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
1223
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1224 /* 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
1225 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
1226
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1227 /* Destroy the local queue */
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1228 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
1229
686
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
1230 /* 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
1231 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
1232 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
1233 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
1234 }
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
1235 free(dispatch);
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
1236 dispatch = NULL;
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
1237 }
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
1238 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
1239 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
1240 disp_state = NULL;
253
ad6c0118fb50 Configurable number of server threads
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 241
diff changeset
1241 }
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1242
122
e66a82a739fa Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 114
diff changeset
1243 return 0;
e66a82a739fa Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 114
diff changeset
1244 }
e66a82a739fa Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 114
diff changeset
1245
e66a82a739fa Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 114
diff changeset
1246 /* Cleanup handlers */
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1247 int fd_rtdisp_cleanup(void)
122
e66a82a739fa Fix termination steps
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 114
diff changeset
1248 {
90
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 89
diff changeset
1249 /* Cleanup all remaining handlers */
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 89
diff changeset
1250 while (!FD_IS_LIST_EMPTY(&rt_fwd_list)) {
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 89
diff changeset
1251 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
1252 }
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 89
diff changeset
1253 while (!FD_IS_LIST_EMPTY(&rt_out_list)) {
2c9444152e4b Added the dispatch thread code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 89
diff changeset
1254 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
1255 }
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1256
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1257 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
1258
88
9e2db1647d6f Completed routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 87
diff changeset
1259 return 0;
82
b6344f1d521a Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 41
diff changeset
1260 }
85
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 82
diff changeset
1261
e5fcd672caff Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 82
diff changeset
1262
124
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1263 /********************************************************************************/
1055
4387d1beff80 Fix typo.
Thomas Klausner <tk@giga.or.at>
parents: 1037
diff changeset
1264 /* 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
1265 /********************************************************************************/
cc42d8607114 Completed cleanups of queues when the daemon is stopping
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 123
diff changeset
1266
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1267 /* 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
1268 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
1269 {
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1270 application_id_t aid = 0;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1271 vendor_id_t vid = 0;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1272
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1273 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
1274 CHECK_PARAMS( app && (auth || acct) );
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1275
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1276 {
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1277 enum dict_object_type type = 0;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1278 struct dict_application_data data;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1279 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
1280 CHECK_PARAMS( type == DICT_APPLICATION );
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1281 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
1282 aid = data.application_id;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1283 }
86
e3e22d89e023 Started routing module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 85
diff changeset
1284
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1285 if (vendor) {
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1286 enum dict_object_type type = 0;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1287 struct dict_vendor_data data;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1288 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
1289 CHECK_PARAMS( type == DICT_VENDOR );
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1290 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
1291 vid = data.vendor_id;
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1292 }
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1293
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1294 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
1295 }
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1296
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1297
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 122
diff changeset
1298
"Welcome to our mercurial repository"