GNUnet  0.10.x
Enumerations | Functions
network type characterization

Enumerations

enum  GNUNET_NetworkType {
  GNUNET_NT_UNSPECIFIED = 0, GNUNET_NT_LOOPBACK = 1, GNUNET_NT_LAN = 2, GNUNET_NT_WAN = 3,
  GNUNET_NT_WLAN = 4, GNUNET_NT_BT
}
 Types of networks (with separate quotas) we support. More...
 

Functions

const char * GNUNET_NT_to_string (enum GNUNET_NetworkType net)
 Convert a enum GNUNET_NetworkType to a string. More...
 
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type (struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
 Returns where the address is located: loopback, LAN or WAN. More...
 
struct GNUNET_NT_InterfaceScannerGNUNET_NT_scanner_init (void)
 Initialize the address characterization client handle. More...
 
void GNUNET_NT_scanner_done (struct GNUNET_NT_InterfaceScanner *is)
 Terminate interface scanner. More...
 

Detailed Description

Enumeration Type Documentation

◆ GNUNET_NetworkType

Types of networks (with separate quotas) we support.

Enumerator
GNUNET_NT_UNSPECIFIED 

Category of last resort.

GNUNET_NT_LOOPBACK 

Loopback (same host).

GNUNET_NT_LAN 

Local area network.

GNUNET_NT_WAN 

Wide area network (i.e.

Internet)

GNUNET_NT_WLAN 

Wireless LAN (i.e.

802.11abgn)

GNUNET_NT_BT 

Bluetooth LAN.

Definition at line 35 of file gnunet_nt_lib.h.

35  {
40 
45 
49  GNUNET_NT_LAN = 2,
50 
54  GNUNET_NT_WAN = 3,
55 
59  GNUNET_NT_WLAN = 4,
60 
64  GNUNET_NT_BT = 5
65 
69 #define GNUNET_NT_COUNT 6
70 };
Local area network.
Definition: gnunet_nt_lib.h:49
Wide area network (i.e.
Definition: gnunet_nt_lib.h:54
Wireless LAN (i.e.
Definition: gnunet_nt_lib.h:59
Bluetooth LAN.
Definition: gnunet_nt_lib.h:64
Loopback (same host).
Definition: gnunet_nt_lib.h:44
Category of last resort.
Definition: gnunet_nt_lib.h:39

Function Documentation

◆ GNUNET_NT_to_string()

const char* GNUNET_NT_to_string ( enum GNUNET_NetworkType  net)

Convert a enum GNUNET_NetworkType to a string.

Parameters
netthe network type
Returns
a string or NULL if invalid

Definition at line 43 of file nt.c.

References GNUNET_NT_BT, GNUNET_NT_LAN, GNUNET_NT_LOOPBACK, GNUNET_NT_UNSPECIFIED, GNUNET_NT_WAN, and GNUNET_NT_WLAN.

Referenced by distribute_bandwidth_in_network(), enforce_add_address(), GNUNET_ATS_solvers_load_quotas(), GNUNET_NT_scanner_get_type(), GST_ats_add_inbound_address(), libgnunet_plugin_ats2_simple_init(), libgnunet_plugin_ats_mlp_init(), libgnunet_plugin_ats_proportional_init(), libgnunet_plugin_ats_ril_init(), load_quota(), load_quotas(), mlp_create_problem_add_invariant_rows(), parse_quota(), print_quotas(), and transport_addr_to_str_cb().

44 {
45  switch (net)
46  {
48  return "UNSPECIFIED";
49 
50  case GNUNET_NT_LOOPBACK:
51  return "LOOPBACK";
52 
53  case GNUNET_NT_LAN:
54  return "LAN";
55 
56  case GNUNET_NT_WAN:
57  return "WAN";
58 
59  case GNUNET_NT_WLAN:
60  return "WLAN";
61 
62  case GNUNET_NT_BT:
63  return "BLUETOOTH";
64 
65  default:
66  return NULL;
67  }
68 }
Local area network.
Definition: gnunet_nt_lib.h:49
Wide area network (i.e.
Definition: gnunet_nt_lib.h:54
Wireless LAN (i.e.
Definition: gnunet_nt_lib.h:59
Bluetooth LAN.
Definition: gnunet_nt_lib.h:64
Loopback (same host).
Definition: gnunet_nt_lib.h:44
Category of last resort.
Definition: gnunet_nt_lib.h:39
Here is the caller graph for this function:

◆ GNUNET_NT_scanner_get_type()

enum GNUNET_NetworkType GNUNET_NT_scanner_get_type ( struct GNUNET_NT_InterfaceScanner is,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Returns where the address is located: loopback, LAN or WAN.

Parameters
ishandle from #GNUNET_ATS_interface_scanner_init()
addraddress
addrlenaddress length
Returns
type of the network the address belongs to

Returns where the address is located: loopback, LAN or WAN.

Parameters
isthe interface scanner handle
addraddress
addrlenaddress length
Returns
type of the network the address belongs to

Definition at line 306 of file nt.c.

References GNUNET_a2s(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log_from, GNUNET_NO, GNUNET_NT_LAN, GNUNET_NT_LOOPBACK, GNUNET_NT_to_string(), GNUNET_NT_UNSPECIFIED, GNUNET_NT_WAN, GNUNET_YES, NT_Network::length, GNUNET_NT_InterfaceScanner::net_head, NT_Network::netmask, NT_Network::network, NT_Network::next, res, and type.

Referenced by boot_queue(), iface_proc(), mq_init(), nat_address_cb(), plugin_env_address_to_type(), setup_sender(), and sock_read().

309 {
310  struct NT_Network *cur = is->net_head;
312 
313  switch (addr->sa_family)
314  {
315  case AF_UNIX:
316  type = GNUNET_NT_LOOPBACK;
317  break;
318 
319  case AF_INET:
320  {
321  const struct sockaddr_in *a4 = (const struct sockaddr_in *)addr;
322 
323  if ((a4->sin_addr.s_addr & htonl(0xff000000)) == htonl(0x7f000000))
324  type = GNUNET_NT_LOOPBACK;
325  break;
326  }
327 
328  case AF_INET6:
329  {
330  const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *)addr;
331 
332  if (IN6_IS_ADDR_LOOPBACK(&a6->sin6_addr))
333  type = GNUNET_NT_LOOPBACK;
334  break;
335  }
336 
337  default:
338  GNUNET_break(0);
339  break;
340  }
341 
342  /* Check local networks */
343  while ((NULL != cur) && (GNUNET_NT_UNSPECIFIED == type))
344  {
345  if (addrlen != cur->length)
346  {
347  cur = cur->next;
348  continue;
349  }
350  if (addr->sa_family == AF_INET)
351  {
352  const struct sockaddr_in *a4 = (const struct sockaddr_in *)addr;
353  const struct sockaddr_in *net4 = (const struct sockaddr_in *)cur->network;
354  const struct sockaddr_in *mask4 = (const struct sockaddr_in *)cur->netmask;
355 
356  if (((a4->sin_addr.s_addr & mask4->sin_addr.s_addr)) == net4->sin_addr.s_addr)
357  type = GNUNET_NT_LAN;
358  }
359  if (addr->sa_family == AF_INET6)
360  {
361  const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *)addr;
362  const struct sockaddr_in6 *net6 = (const struct sockaddr_in6 *)cur->network;
363  const struct sockaddr_in6 *mask6 = (const struct sockaddr_in6 *)cur->netmask;
364 
365  int res = GNUNET_YES;
366  int c = 0;
367  uint32_t *addr_elem = (uint32_t *)&a6->sin6_addr;
368  uint32_t *mask_elem = (uint32_t *)&mask6->sin6_addr;
369  uint32_t *net_elem = (uint32_t *)&net6->sin6_addr;
370  for (c = 0; c < 4; c++)
371  if ((addr_elem[c] & mask_elem[c]) != net_elem[c])
372  res = GNUNET_NO;
373 
374  if (res == GNUNET_YES)
375  type = GNUNET_NT_LAN;
376  }
377  cur = cur->next;
378  }
379 
380  /* no local network found for this address, default: WAN */
381  if (type == GNUNET_NT_UNSPECIFIED)
382  type = GNUNET_NT_WAN;
384  "nt-scanner-api",
385  "`%s' is in network `%s'\n",
386  GNUNET_a2s(addr,
387  addrlen),
388  GNUNET_NT_to_string(type));
389  return type;
390 }
Local area network.
Definition: gnunet_nt_lib.h:49
We keep a list of our local networks so we can answer LAN vs.
Definition: nt.c:77
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:43
struct sockaddr * network
Network address.
Definition: nt.c:91
Wide area network (i.e.
Definition: gnunet_nt_lib.h:54
#define GNUNET_NO
Definition: gnunet_common.h:78
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct NT_Network * net_head
Head of LAN networks list.
Definition: nt.c:112
socklen_t length
How long are network and netmask?
Definition: nt.c:101
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
struct NT_Network * next
Kept in a DLL.
Definition: nt.c:81
static int res
Loopback (same host).
Definition: gnunet_nt_lib.h:44
struct sockaddr * netmask
Netmask to determine what is in the LAN.
Definition: nt.c:96
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_log_from(kind, comp,...)
Category of last resort.
Definition: gnunet_nt_lib.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NT_scanner_init()

struct GNUNET_NT_InterfaceScanner* GNUNET_NT_scanner_init ( void  )

Initialize the address characterization client handle.

Returns
scanner handle, NULL on error

Initialize the address characterization client handle.

Returns
interface scanner

Definition at line 399 of file nt.c.

References get_addresses(), GNUNET_new, GNUNET_OS_network_interfaces_list(), GNUNET_SCHEDULER_add_delayed(), interface_proc(), INTERFACE_PROCESSING_INTERVAL, GNUNET_NT_InterfaceScanner::interface_task, and is.

Referenced by run().

400 {
402 
405  is);
407  &get_addresses,
408  is);
409  return is;
410 }
Handle to the interface scanner.
Definition: nt.c:108
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:388
static int interface_proc(void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
Function invoked for each interface found.
Definition: nt.c:161
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1237
#define INTERFACE_PROCESSING_INTERVAL
How frequently do we scan the interfaces for changes to the addresses?
Definition: nt.c:33
struct GNUNET_SCHEDULER_Task * interface_task
Task for periodically refreshing our LAN network list.
Definition: nt.c:122
static void get_addresses(void *cls)
Periodically get list of network addresses from our interfaces.
Definition: nt.c:283
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NT_scanner_done()

void GNUNET_NT_scanner_done ( struct GNUNET_NT_InterfaceScanner is)

Terminate interface scanner.

Parameters
isscanner we are done with

Terminate interface scanner.

Parameters
ishandle to release

Definition at line 419 of file nt.c.

References delete_networks(), GNUNET_free, GNUNET_SCHEDULER_cancel(), and GNUNET_NT_InterfaceScanner::interface_task.

Referenced by do_shutdown(), and shutdown_task().

420 {
421  if (NULL != is->interface_task)
422  {
424  is->interface_task = NULL;
425  }
426  delete_networks(is);
427  GNUNET_free(is);
428 }
static void delete_networks(struct GNUNET_NT_InterfaceScanner *is)
Delete all entries from the current network list.
Definition: nt.c:132
struct GNUNET_SCHEDULER_Task * interface_task
Task for periodically refreshing our LAN network list.
Definition: nt.c:122
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function: