GNUnet  0.11.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.

36 {
41 
46 
50  GNUNET_NT_LAN = 2,
51 
55  GNUNET_NT_WAN = 3,
56 
60  GNUNET_NT_WLAN = 4,
61 
65  GNUNET_NT_BT = 5
66 
70 #define GNUNET_NT_COUNT 6
71 };
Local area network.
Definition: gnunet_nt_lib.h:50
Wide area network (i.e.
Definition: gnunet_nt_lib.h:55
Wireless LAN (i.e.
Definition: gnunet_nt_lib.h:60
Bluetooth LAN.
Definition: gnunet_nt_lib.h:65
Loopback (same host).
Definition: gnunet_nt_lib.h:45
Category of last resort.
Definition: gnunet_nt_lib.h:40

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 44 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_ats_proportional_init(), load_quota(), load_quotas(), parse_quota(), print_quotas(), and transport_addr_to_str_cb().

45 {
46  switch (net)
47  {
49  return "UNSPECIFIED";
50 
51  case GNUNET_NT_LOOPBACK:
52  return "LOOPBACK";
53 
54  case GNUNET_NT_LAN:
55  return "LAN";
56 
57  case GNUNET_NT_WAN:
58  return "WAN";
59 
60  case GNUNET_NT_WLAN:
61  return "WLAN";
62 
63  case GNUNET_NT_BT:
64  return "BLUETOOTH";
65 
66  default:
67  return NULL;
68  }
69 }
Local area network.
Definition: gnunet_nt_lib.h:50
Wide area network (i.e.
Definition: gnunet_nt_lib.h:55
Wireless LAN (i.e.
Definition: gnunet_nt_lib.h:60
Bluetooth LAN.
Definition: gnunet_nt_lib.h:65
Loopback (same host).
Definition: gnunet_nt_lib.h:45
Category of last resort.
Definition: gnunet_nt_lib.h:40
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 314 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().

317 {
318  struct NT_Network *cur = is->net_head;
320 
321  switch (addr->sa_family)
322  {
323  case AF_UNIX:
324  type = GNUNET_NT_LOOPBACK;
325  break;
326 
327  case AF_INET:
328  {
329  const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
330 
331  if ((a4->sin_addr.s_addr & htonl (0xff000000)) == htonl (0x7f000000))
332  type = GNUNET_NT_LOOPBACK;
333  break;
334  }
335 
336  case AF_INET6:
337  {
338  const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
339 
340  if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
341  type = GNUNET_NT_LOOPBACK;
342  break;
343  }
344 
345  default:
346  GNUNET_break (0);
347  break;
348  }
349 
350  /* Check local networks */
351  while ((NULL != cur) && (GNUNET_NT_UNSPECIFIED == type))
352  {
353  if (addrlen != cur->length)
354  {
355  cur = cur->next;
356  continue;
357  }
358  if (addr->sa_family == AF_INET)
359  {
360  const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
361  const struct sockaddr_in *net4 = (const struct
362  sockaddr_in *) cur->network;
363  const struct sockaddr_in *mask4 = (const struct
364  sockaddr_in *) cur->netmask;
365 
366  if (((a4->sin_addr.s_addr & mask4->sin_addr.s_addr)) ==
367  net4->sin_addr.s_addr)
368  type = GNUNET_NT_LAN;
369  }
370  if (addr->sa_family == AF_INET6)
371  {
372  const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
373  const struct sockaddr_in6 *net6 = (const struct
374  sockaddr_in6 *) cur->network;
375  const struct sockaddr_in6 *mask6 = (const struct
376  sockaddr_in6 *) cur->netmask;
377 
378  int res = GNUNET_YES;
379  int c = 0;
380  uint32_t *addr_elem = (uint32_t *) &a6->sin6_addr;
381  uint32_t *mask_elem = (uint32_t *) &mask6->sin6_addr;
382  uint32_t *net_elem = (uint32_t *) &net6->sin6_addr;
383  for (c = 0; c < 4; c++)
384  if ((addr_elem[c] & mask_elem[c]) != net_elem[c])
385  res = GNUNET_NO;
386 
387  if (res == GNUNET_YES)
388  type = GNUNET_NT_LAN;
389  }
390  cur = cur->next;
391  }
392 
393  /* no local network found for this address, default: WAN */
394  if (type == GNUNET_NT_UNSPECIFIED)
395  type = GNUNET_NT_WAN;
397  "nt-scanner-api",
398  "`%s' is in network `%s'\n",
399  GNUNET_a2s (addr,
400  addrlen),
401  GNUNET_NT_to_string (type));
402  return type;
403 }
Local area network.
Definition: gnunet_nt_lib.h:50
We keep a list of our local networks so we can answer LAN vs.
Definition: nt.c:78
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:44
struct sockaddr * network
Network address.
Definition: nt.c:93
Wide area network (i.e.
Definition: gnunet_nt_lib.h:55
#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:115
socklen_t length
How long are network and netmask?
Definition: nt.c:103
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:83
static int res
Loopback (same host).
Definition: gnunet_nt_lib.h:45
struct sockaddr * netmask
Netmask to determine what is in the LAN.
Definition: nt.c:98
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:40
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 412 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().

413 {
415 
418  is);
421  &get_addresses,
422  is);
423  return is;
424 }
Handle to the interface scanner.
Definition: nt.c:110
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:396
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:164
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:1253
#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:125
static void get_addresses(void *cls)
Periodically get list of network addresses from our interfaces.
Definition: nt.c:290
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 433 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().

434 {
435  if (NULL != is->interface_task)
436  {
438  is->interface_task = NULL;
439  }
440  delete_networks (is);
441  GNUNET_free (is);
442 }
static void delete_networks(struct GNUNET_NT_InterfaceScanner *is)
Delete all entries from the current network list.
Definition: nt.c:135
struct GNUNET_SCHEDULER_Task * interface_task
Task for periodically refreshing our LAN network list.
Definition: nt.c:125
#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:966
Here is the call graph for this function:
Here is the caller graph for this function: