PadicoTM

Documentation

« back to PM2 home.
vlink-resolver.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2026 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
32#include <Padico/VLink-debug.h>
33#include <Padico/Topology.h>
34#include <Padico/Module.h>
35#include <Padico/PadicoControl.h>
36
37#include <netinet/in.h>
38#include <arpa/inet.h>
39#include <netdb.h>
40#include <sys/types.h>
41#include <sys/socket.h>
42#include <sys/un.h>
43#include <sys/time.h>
44
45PADICO_MODULE_HOOK(VLink_selector);
46
52 );
53
60
61static int padico_vaddr_matches(const struct padico_vaddr_s*server,
62 const struct padico_vaddr_s*client);
63
66
67/* *** resolver ******************************************** */
68
72{
74
75 switch(vaddr->addr->sa_family)
76 {
77 case AF_INET:
78 {
79 struct sockaddr_in*inaddr = (struct sockaddr_in*)vaddr->addr;
81
82 if(host != NULL)
83 {
86 {
88 }
89 }
90 }
91 break;
92
93 case AF_INET6:
94 {
95 padico_warning("resolving node as IPv6 address.\n");
96 struct sockaddr_in6*in6addr = (struct sockaddr_in6*)vaddr->addr;
98 if(host != NULL)
99 {
103 }
104 }
105 break;
106
107 case AF_UNIX:
108 {
110 padico_out(6, "VLink-resolver: family=AF_UNIX; path=**%s**\n", addr_un->sun_path);
111 node = NULL;
112 }
113 break;
114
115 default:
116 padico_warning("trying to use address family %d -- not available\n",
117 vaddr->addr->sa_family);
118 node = NULL;
119 }
120 return node;
121}
122
128{
130
131 switch(vaddr->addr->sa_family)
132 {
133 case AF_INET:
134 {
135 const struct in_addr*inaddr = &((struct sockaddr_in*)vaddr->addr)->sin_addr;
137 }
138 break;
139 case AF_INET6:
140 {
141 padico_warning("resolving host as IPv6 address.\n");
142 const struct in6_addr*in6addr = &((struct sockaddr_in6*)vaddr->addr)->sin6_addr;
144 }
145 break;
146 case AF_UNIX:
147 {
149 }
150 break;
151 default:
152 host = NULL;
153 }
154 return host;
155}
156
157/* *** sockaddr toolbox ************************************ */
158
160 const struct padico_vaddr_s*client)
161{
162 int matches = 0;
163 if( /* (i->proto == proto) && */ /* XXX */
164 (server->addrlen == client->addrlen) &&
165 (server->addr->sa_family == client->addr->sa_family))
166 {
167 switch(server->addr->sa_family)
168 {
169 case AF_INET:
170 {
171 const struct sockaddr_in*const inaddr_c = (struct sockaddr_in*)client->addr;
172 const struct sockaddr_in*const inaddr_s = (struct sockaddr_in*)server->addr;
173 if( (inaddr_s->sin_port == inaddr_c->sin_port) &&
174 ( (inaddr_s->sin_addr.s_addr == inaddr_c->sin_addr.s_addr) ||
175 (inaddr_s->sin_addr.s_addr == INADDR_ANY)) )
176 {
177 return 1;
178 }
179 }
180 break;
181
182 case AF_INET6:
183 {
184 const struct sockaddr_in6*const in6addr_c = (struct sockaddr_in6*)client->addr;
185 const struct sockaddr_in6*const in6addr_s = (struct sockaddr_in6*)server->addr;
186 return( (in6addr_s->sin6_port == in6addr_c->sin6_port) &&
187 ( (memcmp(&in6addr_s->sin6_addr, &in6addr_c->sin6_addr, sizeof(struct in6_addr)) == 0) ||
188 (memcmp(&in6addr_s->sin6_addr, &in6addr_any, sizeof(struct in6_addr)) == 0)) );
189 }
190 break;
191
192 case AF_UNIX:
193 {
194 if(memcmp(server->addr, client->addr, server->addrlen) == 0)
195 return 1;
196 }
197 break;
198
199 default:
200 padico_fatal("Looking for an unknown family of socket.\n");
201 }
202 }
203 return matches;
204}
205
206
207/* *** VLink registry ************************************** */
208
209static void vlink_registry_bind(padico_vnode_t vnode, struct sockaddr*addr, socklen_t addrlen, int proto)
210{
212 b->vnode = vnode;
213 b->vaddr.proto = proto;
214 b->vaddr.addr = addr;
215 b->vaddr.addrlen = addrlen;
219}
220
222 socklen_t addrlen, int proto)
223{
224 padico_out(40, "vnode=%p registering\n", vnode);
225 switch(addr->sa_family)
226 {
227 case AF_INET:
228 {
229 /* normalize IPv4 address */
230 struct sockaddr_in*inaddr = padico_malloc(addrlen);
231 memcpy(inaddr, addr, addrlen);
232 memset(inaddr->sin_zero, 0, sizeof(inaddr->sin_zero));
233 vlink_registry_bind(vnode, (struct sockaddr*)inaddr, addrlen, proto);
234 padico_out(40, " register IPv4 addr = %s\n", inet_ntoa(inaddr->sin_addr));
235 }
236 break;
237
238 case AF_INET6:
239 {
240 /* normalize IPv6 address */
241 struct sockaddr_in6*in6addr = padico_malloc(addrlen);
242 memcpy(in6addr, addr, addrlen);
243 in6addr->sin6_flowinfo = 0;
244 in6addr->sin6_scope_id = 0;
245 vlink_registry_bind(vnode, (struct sockaddr*)in6addr, addrlen, proto);
246 if(IN6_IS_ADDR_UNSPECIFIED(&in6addr->sin6_addr))
247 {
248 /* create wildcard IPv4 binding in dual stack mode */
249 struct sockaddr_in*in4addr = padico_malloc(sizeof(struct sockaddr_in));
250 in4addr->sin_family = AF_INET;
251 in4addr->sin_port = in6addr->sin6_port;
252 in4addr->sin_addr.s_addr = htonl(INADDR_ANY);
253 memset(in4addr->sin_zero, 0, sizeof(in4addr->sin_zero));
254 vlink_registry_bind(vnode, (struct sockaddr*)in4addr, sizeof(struct sockaddr_in), proto);
255 }
256 }
257 break;
258 }
259}
260
282
283padico_vnode_t vlink_registry_lookup(const struct sockaddr*addr, socklen_t addrlen, int proto)
284{
286 const struct padico_vaddr_s vaddr =
287 {
288 .addr = (struct sockaddr*)addr, /* discard 'const', but it is not changed anyway */
289 .addrlen = addrlen,
290 .proto = proto
291 };
293 padico_out(40, "looking up: addrlen=%d; addr family=%d; proto=%d\n",
294 addrlen, addr->sa_family, proto);
299 {
300 padico_out(60, "trying: vnode=%p; addrlen=%d; addr family=%d; proto=%d\n",
301 i->vnode, i->vaddr.addrlen,
302 i->vaddr.addr->sa_family,
303 i->vaddr.proto);
304 vlink_address_trace(i->vaddr.addr, i->vaddr.addrlen);
305 if(padico_vaddr_matches(&i->vaddr, &vaddr))
306 {
307 vnode = i->vnode;
308 padico_out(40, "vnode=%p matches\n", vnode);
309 break;
310 }
311 }
313 return vnode;
314}
315
316
319{
323 padico_out(40, "resolving vaddr...\n");
324 /* send requests to candidates */
326 {
327 const padico_topo_node_t node = *n;
329 {
330 padico_reqs_vect_push_back(reqs, NULL); /* place-holder for self */
331 }
332 else
333 {
336 padico_string_catf(request, "<VLink-resolver-request>%s</VLink-resolver-request>\n",
338 padico_out(40, "sending request *%s* to node %s\n",
342 req->notify_key = node;
344 }
345 }
346 /* wait for reply */
349 {
350 padico_req_t req = *r;
351 if(req != NULL)
352 {
353 /* padico_rc_t reply = padico_tm_req_wait(req); */
355 struct timeval starttime;
357 while(!req->completed)
358 {
359 struct timeval nowtime;
361 if( ((nowtime.tv_sec - starttime.tv_sec) * 1000000)
362 + (nowtime.tv_usec - starttime.tv_usec) > 1000000 )
363 break;
364 }
365 if(req->completed)
366 {
367 reply = req->rc;
368 padico_topo_node_t node = req->notify_key;
369 padico_out(40, "got reply rc=%d from node %s.\n",
372 {
374 }
375 if(reply)
376 {
378 }
379 }
380 }
381 }
383 if(selected_node == NULL)
384 {
385 padico_out(40, "no matching node for this address.\n");
386 }
387 else
388 {
390 }
391 return selected_node;
392}
393
394
398{
401 assert(e->text != NULL);
402 padico_out(40, "received VLink-resolver request for vaddr: *%s*\n", e->text);
405 if(vnode == NULL)
406 {
407 puk_parse_set_rc(e, padico_rc_error("address not managed by VLink"));
408 }
409 else
410 {
412 }
414}
415
416/* ********************************************************* */
417
419{
420 /* init local registry */
423
425 .xml_tag = "VLink-resolver-request",
426 .start_handler = NULL,
427 .end_handler = &resolver_request_end_handler,
428 .required_level = PUK_TRUST_CONTROL,
429 .help = "Used internally by VLink-resolver"
430 });
431}
assert(slab_size > 0)
struct ns_rulebucket_hash_entry_s * e
ssize_t n
struct ns_rulebucket_hash_entry_s * b
return NULL
Definition Shm.h:88
int r
Definition Shm.h:88
padico_topo_host_t host
struct padico_addrkey_hash_entry_block_lfstack_s __attribute__
hint whether the queue is empty.
static int done
Definition console-mod.c:49
static void client()
Definition datacheck.c:151
static int server()
Definition datacheck.c:179
static char * request(const char *url)
Definition g5k-topo.c:122
static padico_req_t padico_control_send(padico_topo_node_t node, const char *cmd)
Send a blocking request on the control channel.
typdef struct padico_reqs_vect_s * padico_reqs_vect_t
Definition PadicoTM.h:150
padico_topo_node_vect_t padico_topo_host_getnodes(padico_topo_host_t host)
Get the nodes on a host.
Definition topology.c:2049
padico_topo_host_t padico_topo_host_resolve_byinaddr(const struct in_addr *addr)
Get a host description record from an inet address (create if it didn't exist)
Definition topology.c:2452
padico_topo_node_t padico_topo_getlocalnode(void)
Definition topology.c:1891
const char * padico_topo_node_getname(padico_topo_node_t node)
Get the canonical name of a node.
Definition topology.c:1917
padico_topo_host_t padico_topo_host_getbyin6addr(const struct in6_addr *addr)
Get a host from an inet6 address (return NULL if host doesn't exist).
Definition topology.c:2438
padico_string_t padico_vaddr_marshall(const struct padico_vaddr_s *vaddr)
Definition topo-vaddr.c:46
padico_topo_host_t padico_topo_host_getbyinaddr(const struct in_addr *addr)
Get a host from an inet address (return NULL if host doesn't exist).
Definition topology.c:2424
#define padico_topo_getlocalhost()
Definition Topology.h:319
typdef struct padico_topo_node_vect_s * padico_topo_node_vect_t
Definition Topology.h:84
padico_vaddr_t padico_vaddr_unmarshall(const char *s)
Definition topo-vaddr.c:93
padico_topo_host_t padico_topo_host_resolve_byin6addr(const struct in6_addr *addr)
Get a host description record from an inet6 address (create if it didn't exist)
Definition topology.c:2466
padico_topo_node_t node
Definition na-control.c:65
mx_request_t req
Definition psp-mx.c:103
socklen_t addrlen
Definition Topology.h:463
struct sockaddr * addr
Definition Topology.h:462
virtual node descriptor, common to any file type
Definition VLink-API.h:383
struct padico_req_list_s reqs