PadicoTM

Documentation

« back to PM2 home.

Grid topology directory. More...

#include <Padico/Puk.h>
#include <Padico/Module.h>
#include <Padico/PM2.h>
#include <Padico/PadicoTM.h>
#include "Topology-internals.h"
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <resolv.h>
#include <dirent.h>
#include <poll.h>
#include <ifaddrs.h>
#include <netpacket/packet.h>
#include <sys/ioctl.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/sockios.h>
#include <linux/ethtool.h>
#include <linux/if.h>
Include dependency graph for topology.c:

Go to the source code of this file.

Macros

#define BUFSIZE   512
 

Functions

static int padico_topology_init (void)
 
static void padico_topology_finalize (void)
 
static void padico_module_create_initializer__Topology (void)
 
static void padico_module_attr_initializer__disable_dns (void)
 
static void padico_module_attr_finalizer__disable_dns (void)
 
static void padico_module_attr_disable_dns_setvalue (puk_opt_type_bool_t v) __attribute__((unused))
 
static puk_opt_type_bool_t padico_module_attr_disable_dns_getvalue (void)
 
static void padico_module_attr_initializer__disable_ipv6 (void)
 
static void padico_module_attr_finalizer__disable_ipv6 (void)
 
static void padico_module_attr_disable_ipv6_setvalue (puk_opt_type_bool_t v) __attribute__((unused))
 
static puk_opt_type_bool_t padico_module_attr_disable_ipv6_getvalue (void)
 
static void padico_module_attr_initializer__autodetect (void)
 
static void padico_module_attr_finalizer__autodetect (void)
 
static void padico_module_attr_autodetect_setvalue (puk_opt_type_bool_t v) __attribute__((unused))
 
static puk_opt_type_bool_t padico_module_attr_autodetect_getvalue (void)
 
struct padico_topology_s * topology_get (void)
 
static void topology_populate (void)
 
static void topo_inet_addr_detect (padico_topo_host_t localhost)
 
static void topo_inet_route_detect (padico_topo_host_t localhost)
 
static void topo_inet_service_detect (padico_topo_host_t localhost)
 
static void topo_device_detect (void)
 
static const char * topo_addr_visibility_name (padico_topo_addr_visibility_t v)
 inet address visibility pretty print
 
static const char * topo_hwaddr_type_name (int type)
 MAC address type pretty print.
 
static void topo_host_destroy (padico_topo_host_t host)
 
static void topo_network_destroy (padico_topo_network_t network)
 
 __attribute__ ((visibility("internal")))
 Init the parser.
 
padico_topo_hwaddr_t padico_topo_hwaddr_create (const char *name, int index, int type, size_t len, const void *addr)
 
void padico_topo_hwaddr_get (padico_topo_hwaddr_t hwaddr, const char **name, int *index, int *type, size_t *len, const void **addr)
 
void padico_topo_hwaddr_add (padico_topo_host_t host, padico_topo_hwaddr_t *_hwaddr)
 
void padico_topo_hwaddr_destroy (padico_topo_hwaddr_t hwaddr)
 
void padico_topo_binding_add_addr (padico_topo_binding_t binding, const void *addr)
 
void padico_topo_binding_add_hwaddr (padico_topo_binding_t binding, padico_topo_hwaddr_t hwaddr)
 
void padico_topo_binding_add_index (padico_topo_binding_t binding, int64_t index)
 
void padico_topo_binding_add_gw_addr (padico_topo_binding_t binding, struct in_addr *inaddr)
 
void padico_topo_binding_add_gw_hwaddr (padico_topo_binding_t binding, padico_topo_hwaddr_t hwaddr)
 
void padico_topo_binding_add_hostname (padico_topo_binding_t binding, const char *name)
 
void padico_topo_binding_add_route (padico_topo_binding_t binding, padico_topo_network_t dest, const void *gwaddr)
 
void padico_topo_binding_add_filter (padico_topo_binding_t binding, padico_topo_filter_policy_t policy, uint16_t port, int protocol)
 
void padico_topo_binding_add_perf (padico_topo_binding_t binding, int latency, int bandwidth)
 
void padico_topo_binding_get_perf (padico_topo_binding_t binding, int *latency_nsec, int *bandwidth_kbps)
 
padico_topo_hwaddr_t padico_topo_binding_gethwaddr (padico_topo_binding_t binding)
 
int padico_topo_binding_get_index (padico_topo_binding_t binding, int64_t *index)
 
void padico_sockaddr_init (struct sockaddr_pa *addr, socklen_t *addrlen, int magic)
 
int padico_sockaddr_check (const struct sockaddr_pa *addr, int magic)
 
static const struct hostent * topo_gethostbyaddr (const void *addr, socklen_t len, int family)
 frontend to gethostbyaddr
 
static const struct hostent * topo_gethostbyname2 (const char *name, int family)
 frontend to gethostbyname2 to manage TRY_AGAIN error
 
static void topo_detect_link_perf (padico_topo_binding_t b, const padico_topo_hwaddr_t hwaddr)
 
static int topo_inet_addr_detect_getifaddrs (padico_topo_host_t localhost)
 detect network interfaces using Linux getifaddrs, if available
 
static void topo_inet_addr_detect_siocgifconf (padico_topo_host_t localhost)
 detect network interfaces using netdevice ioctl
 
static int topo_inet_addr_detect_netlink (padico_topo_host_t localhost)
 detect network interfaces using netlink socket
 
padico_topo_addr_visibility_t padico_topo_inet_visibility (in_addr_t _inaddr)
 
padico_topo_addr_visibility_t padico_topo_inet6_visibility (const struct in6_addr *in6addr)
 
padico_topo_host_t padico_topo_host_create (const char *hostname)
 Create a new 'host' record from a given canonical name.
 
padico_topo_host_t topo_host_lookup (const char *hostname)
 
void padico_topo_host_add_name (padico_topo_host_t host, const char *_name, int resolvable)
 Add a name to a host;.
 
void padico_topo_host_add_service (padico_topo_host_t host, const char *service_name, uint16_t service_port)
 Add a service to a host.
 
void padico_topo_host_add_property (padico_topo_host_t host, const char *label, const char *value)
 Add a property to a host.
 
padico_topo_binding_t padico_topo_host_bind (padico_topo_host_t host, padico_topo_network_t network, const void *address)
 Declare a new binding for a host.
 
padico_topo_binding_t padico_topo_node_bind (padico_topo_node_t node, padico_topo_network_t network, const void *address)
 Declare a new binding for a node.
 
void topo_binding_destroy (struct topo_binding_s *binding)
 
void topo_property_destroy (struct topo_property_s *prop)
 
void topo_binding_merge (padico_topo_binding_t binding, padico_topo_binding_t b2)
 merge properties from b2 into 'binding', then destroy b2
 
void topo_binding_bind_host (padico_topo_binding_t *_binding, padico_topo_host_t host)
 
void topo_binding_bind_node (padico_topo_binding_t *_binding, padico_topo_node_t node)
 
padico_topo_node_t topo_node_create (const char *name, padico_topo_host_t host, const char *uuid, const char *boot_id)
 Create a new node, either locally or received as XML description.
 
void topo_node_destroy (padico_topo_node_t node)
 
padico_topo_network_t padico_topo_network_create (const char *id, padico_topo_binding_scope_t scope, size_t addr_size, int family)
 
padico_topo_node_t padico_topo_getlocalnode (void)
 
padico_topo_address_t padico_topo_node_getaddress (padico_topo_node_t node, padico_topo_network_t network)
 Get the address of the node in the given network.
 
padico_topo_uuid_t padico_topo_node_getuuid (padico_topo_node_t node)
 Get the UUID of a node.
 
const char * padico_topo_node_getname (padico_topo_node_t node)
 Get the canonical name of a node.
 
const char * padico_topo_node_getsession (padico_topo_node_t node)
 Get the boot session ID.
 
padico_topo_host_t padico_topo_node_gethost (padico_topo_node_t node)
 Get the host hosting a node.
 
void padico_topo_node_getnetworks (padico_topo_node_t node, padico_topo_network_vect_t networks)
 Get the networks a node is connected to.
 
const char * padico_topo_host_getname (padico_topo_host_t host)
 Get the canonical name of a host.
 
const char * padico_topo_host_getname2 (padico_topo_host_t host, padico_topo_network_t network)
 Get the canonical name of a host on a network.
 
const struct in_addr * padico_topo_host_getaddr (padico_topo_host_t host)
 Get the canonical IP address of a host.
 
padico_topo_binding_vect_t padico_topo_host_getbindings (padico_topo_host_t host, padico_topo_network_t network)
 Get the bindings of a host on a network.
 
const struct in_addr * padico_topo_host_getaddr2 (padico_topo_host_t host, padico_topo_network_t network)
 Get the canonical IP address of a host on a network.
 
padico_topo_node_vect_t padico_topo_host_getnodes (padico_topo_host_t host)
 Get the nodes on a host.
 
void padico_topo_host_getnetworks (padico_topo_host_t host, padico_topo_network_vect_t networks)
 Get the networks a host is connected to.
 
static padico_topo_filter_policy_t padico_topo_host_policy (topo_net_entity_t entity, padico_topo_network_t network, uint16_t port, int protocol)
 
int padico_topo_host_can_input (padico_topo_host_t host, padico_topo_network_t network, uint16_t port, int protocol)
 Verify if the port is filtered input between host and network.
 
int padico_topo_host_can_output (padico_topo_host_t host, padico_topo_network_t network, uint16_t port, int protocol)
 Verify if the port is filtered output between host and network.
 
int padico_topo_network_can_input (padico_topo_network_t subnet, padico_topo_network_t network, uint16_t port, int protocol)
 
int padico_topo_network_can_output (padico_topo_network_t subnet, padico_topo_network_t network, uint16_t port, int protocol)
 
int padico_topo_host_getservice (padico_topo_host_t host, char *service_name)
 Get the service port of the service on a host.
 
const char * padico_topo_host_getproperty (padico_topo_host_t host, const char *label)
 Get property on a host.
 
padico_topo_host_vect_t padico_topo_gethosts (void)
 Get known hosts.
 
const char * padico_topo_network_getname (padico_topo_network_t network)
 
int padico_topo_network_size (padico_topo_network_t network)
 
static int padico_topo_network_inet_info (const padico_topo_network_t network, struct in_addr *addr, int *cidr)
 
static int na_bindings_vect_contains_network (struct padico_topo_binding_vect_s *bindings, padico_topo_network_t network)
 
int padico_topo_network_contains_node (padico_topo_network_t network, padico_topo_node_t node)
 tests whether the given node belong to the network
 
int padico_topo_network_contains_host (padico_topo_network_t network, padico_topo_host_t host)
 
static topo_net_entity_t na_network_getentity_byaddr (padico_topo_network_t network, const void *_addr)
 
void padico_topo_network_gethosts (padico_topo_network_t n, padico_topo_host_vect_t hosts)
 
void padico_topo_network_get_common_host (padico_topo_network_t n1, padico_topo_network_t n2, padico_topo_host_vect_t hosts)
 
void padico_topo_network_set_perf (padico_topo_network_t n, int latency_nsec, int bandwidth_kbps)
 
void padico_topo_network_get_perf (padico_topo_network_t n, int *latency_nsec, int *bandwidth_kbps)
 
const void * padico_topo_address_getbytes (padico_topo_address_t address)
 
padico_topo_network_t padico_topo_network_getbyid (const char *network_id)
 
padico_topo_network_vect_t padico_topo_networks_getbyfamily (int family)
 Get networks of a given address family (e.g.
 
padico_topo_node_t padico_topo_network_getnodebyaddr (padico_topo_network_t network, const void *_addr)
 Get a node descriptor from an address.
 
padico_topo_node_t padico_topo_getnodebyname (const char *nodename)
 node lookup, by node name
 
padico_topo_node_t padico_topo_getnodebyuuid (padico_topo_uuid_t uuid)
 node lookup, by UUID
 
padico_topo_host_t padico_topo_network_gethostbyaddr (padico_topo_network_t network, const void *_addr)
 Get a host description record from an address.
 
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).
 
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).
 
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)
 
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)
 
static int topo_host_ping (const struct in_addr *inaddr)
 try to ping a host to detect whether it is reachable.
 
static padico_topo_host_t topo_host_from_hostent (const struct hostent *he)
 Create a new host from host entry.
 
padico_topo_host_t padico_topo_host_resolvebyname (const char *hostname)
 resolve a host from name
 
void padico_topo_node_disconnect (padico_topo_node_t node)
 Handle node disconnection.
 

Variables

struct puk_mod_binary_s padico_mod_binary__Topology = { .name = "Topology", .funcs = &padico_mod_funcs__Topology , .mod = NULL, .profile = { .total_mem = 0, .max_mem = 0, .num_malloc = 0, .num_free = 0 } , .auto_deps = & puk_mod_dep_0 , .n_deps = sizeof((char*[]){ 0, }) / sizeof(char*), .deps = { NULL, } }
 
static const struct puk_mod_funcs_s padico_mod_funcs__Topology = { .init = ( padico_topology_init ), .run = ( NULL ), .finalize = ( padico_topology_finalize ) }
 
static struct puk_opt_s padico_module_opt_disable_dns = { .label = "disable_dns", .env_var = ( "PADICO_DISABLE_DNS" ), .desc = ( "do not try to resolve hostnames" ), .type = puk_opt_type_bool , .value = (union puk_opt_value_u){ .as_bool = ( 0 ) }, .flags = ( 0 ) }
 
static struct puk_opt_s padico_module_opt_disable_ipv6 = { .label = "disable_ipv6", .env_var = ( "PADICO_DISABLE_IPV6" ), .desc = ( "do not use IPv6 addresses" ), .type = puk_opt_type_bool , .value = (union puk_opt_value_u){ .as_bool = ( 0 ) }, .flags = ( 0 ) }
 
static struct puk_opt_s padico_module_opt_autodetect = { .label = "autodetect", .env_var = ( "PADICO_AUTODETECT" ), .desc = ( "auto-detect networks on startup and load drivers" ), .type = puk_opt_type_bool , .value = (union puk_opt_value_u){ .as_bool = ( 1 ) }, .flags = ( 0 ) }
 
static struct padico_topology_s na_topology
 

Detailed Description

Grid topology directory.

Definition in file topology.c.

Macro Definition Documentation

◆ BUFSIZE

#define BUFSIZE   512

Function Documentation

◆ __attribute__()

__attribute__ ( (visibility("internal"))  )

Init the parser.

Init the parser.

Definition at line 100 of file topology.c.

◆ na_bindings_vect_contains_network()

static int na_bindings_vect_contains_network ( struct padico_topo_binding_vect_s *  bindings,
padico_topo_network_t  network 
)
inlinestatic

Definition at line 2249 of file topology.c.

References b, done, and network.

Referenced by padico_topo_network_contains_host(), and padico_topo_network_contains_node().

◆ na_network_getentity_byaddr()

◆ padico_module_attr_autodetect_getvalue()

static puk_opt_type_bool_t padico_module_attr_autodetect_getvalue ( void  )
inlinestatic

Definition at line 82 of file topology.c.

Referenced by topo_device_detect().

◆ padico_module_attr_autodetect_setvalue()

static void padico_module_attr_autodetect_setvalue ( puk_opt_type_bool_t  v)
inlinestatic

Definition at line 82 of file topology.c.

◆ padico_module_attr_disable_dns_getvalue()

static puk_opt_type_bool_t padico_module_attr_disable_dns_getvalue ( void  )
inlinestatic

Definition at line 80 of file topology.c.

Referenced by padico_topo_host_add_name(), and topo_gethostbyaddr().

◆ padico_module_attr_disable_dns_setvalue()

static void padico_module_attr_disable_dns_setvalue ( puk_opt_type_bool_t  v)
inlinestatic

Definition at line 80 of file topology.c.

◆ padico_module_attr_disable_ipv6_getvalue()

static puk_opt_type_bool_t padico_module_attr_disable_ipv6_getvalue ( void  )
inlinestatic

Definition at line 81 of file topology.c.

Referenced by topo_gethostbyaddr(), and topo_gethostbyname2().

◆ padico_module_attr_disable_ipv6_setvalue()

static void padico_module_attr_disable_ipv6_setvalue ( puk_opt_type_bool_t  v)
inlinestatic

Definition at line 81 of file topology.c.

◆ padico_module_attr_finalizer__autodetect()

static void padico_module_attr_finalizer__autodetect ( void  )
static

Definition at line 82 of file topology.c.

◆ padico_module_attr_finalizer__disable_dns()

static void padico_module_attr_finalizer__disable_dns ( void  )
static

Definition at line 80 of file topology.c.

◆ padico_module_attr_finalizer__disable_ipv6()

static void padico_module_attr_finalizer__disable_ipv6 ( void  )
static

Definition at line 81 of file topology.c.

◆ padico_module_attr_initializer__autodetect()

static void padico_module_attr_initializer__autodetect ( void  )
static

Definition at line 82 of file topology.c.

◆ padico_module_attr_initializer__disable_dns()

static void padico_module_attr_initializer__disable_dns ( void  )
static

Definition at line 80 of file topology.c.

◆ padico_module_attr_initializer__disable_ipv6()

static void padico_module_attr_initializer__disable_ipv6 ( void  )
static

Definition at line 81 of file topology.c.

◆ padico_module_create_initializer__Topology()

static void padico_module_create_initializer__Topology ( void  )
static

Definition at line 78 of file topology.c.

◆ padico_topo_binding_add_gw_hwaddr()

void padico_topo_binding_add_gw_hwaddr ( padico_topo_binding_t  binding,
padico_topo_hwaddr_t  hwaddr 
)

◆ padico_topo_host_policy()

◆ padico_topo_network_contains_host()

int padico_topo_network_contains_host ( padico_topo_network_t  network,
padico_topo_host_t  host 
)

Definition at line 2263 of file topology.c.

References topo_host_s::bindings, host, na_bindings_vect_contains_network(), and network.

◆ padico_topo_network_inet_info()

static int padico_topo_network_inet_info ( const padico_topo_network_t  network,
struct in_addr *  addr,
int *  cidr 
)
inlinestatic

Definition at line 2241 of file topology.c.

References done, network, and topo_network_s::network_id.

Referenced by topo_host_from_hostent().

◆ padico_topology_finalize()

◆ padico_topology_init()

◆ topo_addr_visibility_name()

◆ topo_binding_bind_host()

◆ topo_binding_bind_node()

◆ topo_binding_destroy()

void topo_binding_destroy ( struct topo_binding_s *  binding)

◆ topo_binding_merge()

◆ topo_detect_link_perf()

static void topo_detect_link_perf ( padico_topo_binding_t  b,
const padico_topo_hwaddr_t  hwaddr 
)
static

Definition at line 480 of file topology.c.

References b, done, topo_hwaddr_s::name, padico_topo_binding_add_perf(), and rc.

Referenced by topo_inet_addr_detect_getifaddrs().

◆ topo_device_detect()

static void topo_device_detect ( void  )
static

Definition at line 1068 of file topology.c.

References done, NULL, padico_module_attr_autodetect_getvalue(), rc, and s.

Referenced by topology_populate().

◆ topo_gethostbyaddr()

static const struct hostent * topo_gethostbyaddr ( const void *  addr,
socklen_t  len,
int  family 
)
static

◆ topo_gethostbyname2()

static const struct hostent * topo_gethostbyname2 ( const char *  name,
int  family 
)
static

frontend to gethostbyname2 to manage TRY_AGAIN error

Definition at line 438 of file topology.c.

References done, name, NULL, and padico_module_attr_disable_ipv6_getvalue().

Referenced by padico_topo_host_resolvebyname(), topo_host_from_hostent(), and topology_populate().

◆ topo_host_destroy()

◆ topo_host_from_hostent()

◆ topo_host_lookup()

◆ topo_host_ping()

static int topo_host_ping ( const struct in_addr *  inaddr)
static

try to ping a host to detect whether it is reachable.

make a UDP ping, like tracepath, so as to run as non-root.

Definition at line 2482 of file topology.c.

References buffer, BUFSIZE, done, fd, p, PUK_ABI_FSYS_WRAP, rc, and socklen_t.

Referenced by topo_host_from_hostent().

◆ topo_hwaddr_type_name()

static const char * topo_hwaddr_type_name ( int  type)
static

MAC address type pretty print.

Definition at line 1248 of file topology.c.

References done, and type.

Referenced by topo_inet_addr_detect_getifaddrs().

◆ topo_inet_addr_detect()

static void topo_inet_addr_detect ( padico_topo_host_t  localhost)
static

◆ topo_inet_addr_detect_getifaddrs()

◆ topo_inet_addr_detect_netlink()

◆ topo_inet_addr_detect_siocgifconf()

static void topo_inet_addr_detect_siocgifconf ( padico_topo_host_t  localhost)
static

detect network interfaces using netdevice ioctl

Definition at line 649 of file topology.c.

References __puk_abi_wrap__errno, done, i, PUK_ABI_FSYS_WRAP, rc, and sockfd.

Referenced by topo_inet_addr_detect().

◆ topo_inet_route_detect()

◆ topo_inet_service_detect()

static void topo_inet_service_detect ( padico_topo_host_t  localhost)
static

Definition at line 1031 of file topology.c.

References done, local_addr, padico_topo_host_add_service(), rc, remote_addr, and timeout.

Referenced by topology_populate().

◆ topo_network_destroy()

static void topo_network_destroy ( padico_topo_network_t  network)
static

◆ topo_node_create()

◆ topo_node_destroy()

◆ topo_property_destroy()

◆ topology_get()

struct padico_topology_s * topology_get ( void  )

Definition at line 86 of file topology.c.

References na_topology.

Referenced by padico_na_topology_serialize().

◆ topology_populate()

Variable Documentation

◆ na_topology

◆ padico_mod_binary__Topology

struct puk_mod_binary_s padico_mod_binary__Topology = { .name = "Topology", .funcs = &padico_mod_funcs__Topology , .mod = NULL, .profile = { .total_mem = 0, .max_mem = 0, .num_malloc = 0, .num_free = 0 } , .auto_deps = & puk_mod_dep_0 , .n_deps = sizeof((char*[]){ 0, }) / sizeof(char*), .deps = { NULL, } }

Definition at line 78 of file topology.c.

◆ padico_mod_funcs__Topology

const struct puk_mod_funcs_s padico_mod_funcs__Topology = { .init = ( padico_topology_init ), .run = ( NULL ), .finalize = ( padico_topology_finalize ) }
static

Definition at line 78 of file topology.c.

◆ padico_module_opt_autodetect

struct puk_opt_s padico_module_opt_autodetect = { .label = "autodetect", .env_var = ( "PADICO_AUTODETECT" ), .desc = ( "auto-detect networks on startup and load drivers" ), .type = puk_opt_type_bool , .value = (union puk_opt_value_u){ .as_bool = ( 1 ) }, .flags = ( 0 ) }
static

Definition at line 82 of file topology.c.

◆ padico_module_opt_disable_dns

struct puk_opt_s padico_module_opt_disable_dns = { .label = "disable_dns", .env_var = ( "PADICO_DISABLE_DNS" ), .desc = ( "do not try to resolve hostnames" ), .type = puk_opt_type_bool , .value = (union puk_opt_value_u){ .as_bool = ( 0 ) }, .flags = ( 0 ) }
static

Definition at line 80 of file topology.c.

◆ padico_module_opt_disable_ipv6

struct puk_opt_s padico_module_opt_disable_ipv6 = { .label = "disable_ipv6", .env_var = ( "PADICO_DISABLE_IPV6" ), .desc = ( "do not use IPv6 addresses" ), .type = puk_opt_type_bool , .value = (union puk_opt_value_u){ .as_bool = ( 0 ) }, .flags = ( 0 ) }
static

Definition at line 81 of file topology.c.