GNUnet  0.18.1
Network type characterization
Collaboration diagram for 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 38 of file gnunet_nt_lib.h.

39 {
44 
49 
53  GNUNET_NT_LAN = 2,
54 
58  GNUNET_NT_WAN = 3,
59 
63  GNUNET_NT_WLAN = 4,
64 
68  GNUNET_NT_BT = 5
69 
73 #define GNUNET_NT_COUNT 6
74 };
@ GNUNET_NT_WLAN
Wireless LAN (i.e.
Definition: gnunet_nt_lib.h:63
@ GNUNET_NT_WAN
Wide area network (i.e.
Definition: gnunet_nt_lib.h:58
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
Definition: gnunet_nt_lib.h:43
@ GNUNET_NT_LAN
Local area network.
Definition: gnunet_nt_lib.h:53
@ GNUNET_NT_LOOPBACK
Loopback (same host).
Definition: gnunet_nt_lib.h:48
@ GNUNET_NT_BT
Bluetooth LAN.
Definition: gnunet_nt_lib.h:68

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 38 of file nt.c.

39 {
40  switch (net)
41  {
43  return "UNSPECIFIED";
44 
45  case GNUNET_NT_LOOPBACK:
46  return "LOOPBACK";
47 
48  case GNUNET_NT_LAN:
49  return "LAN";
50 
51  case GNUNET_NT_WAN:
52  return "WAN";
53 
54  case GNUNET_NT_WLAN:
55  return "WLAN";
56 
57  case GNUNET_NT_BT:
58  return "BLUETOOTH";
59 
60  default:
61  return NULL;
62  }
63 }

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

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 284 of file nt.c.

311 {
312  struct NT_Network *cur = is->net_head;
314 
315  switch (addr->sa_family)
316  {
317  case AF_UNIX:
319  break;
320 
321  case AF_INET:
322  {
323  const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
324 
325  if ((a4->sin_addr.s_addr & htonl (0xff000000)) == htonl (0x7f000000))
327  break;
328  }
329 
330  case AF_INET6:
331  {
332  const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
333 
334  if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
336  break;
337  }
338 
339  default:
340  GNUNET_break (0);
341  break;
342  }
343 
344  /* Check local networks */
345  while ((NULL != cur) && (GNUNET_NT_UNSPECIFIED == type))
346  {
347  if (addrlen != cur->length)
348  {
349  cur = cur->next;
350  continue;
351  }
352  if (addr->sa_family == AF_INET)
353  {
354  const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
355  const struct sockaddr_in *net4 = (const struct
356  sockaddr_in *) cur->network;
357  const struct sockaddr_in *mask4 = (const struct
358  sockaddr_in *) cur->netmask;
359 
360  if (((a4->sin_addr.s_addr & mask4->sin_addr.s_addr)) ==
361  net4->sin_addr.s_addr)
363  }
364  if (addr->sa_family == AF_INET6)
365  {
366  const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
367  const struct sockaddr_in6 *net6 = (const struct
368  sockaddr_in6 *) cur->network;
369  const struct sockaddr_in6 *mask6 = (const struct
370  sockaddr_in6 *) cur->netmask;
371 
372  int res = GNUNET_YES;
373  int c = 0;
374  uint32_t *addr_elem = (uint32_t *) &a6->sin6_addr;
375  uint32_t *mask_elem = (uint32_t *) &mask6->sin6_addr;
376  uint32_t *net_elem = (uint32_t *) &net6->sin6_addr;
377  for (c = 0; c < 4; c++)
378  if ((addr_elem[c] & mask_elem[c]) != net_elem[c])
379  res = GNUNET_NO;
380 
381  if (res == GNUNET_YES)
383  }
384  cur = cur->next;
385  }
386 
387  /* no local network found for this address, default: WAN */
391  "nt-scanner-api",
392  "`%s' is in network `%s'\n",
393  GNUNET_a2s (addr,
394  addrlen),
396  return type;
397 }
static int res
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
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).
@ GNUNET_ERROR_TYPE_DEBUG
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:39
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:38
struct NT_Network * net_head
Head of LAN networks list.
Definition: nt.c:109
We keep a list of our local networks so we can answer LAN vs.
Definition: nt.c:73
struct NT_Network * next
Kept in a DLL.
Definition: nt.c:77
socklen_t length
How long are network and netmask?
Definition: nt.c:97
struct sockaddr * network
Network address.
Definition: nt.c:87
struct sockaddr * netmask
Netmask to determine what is in the LAN.
Definition: nt.c:92
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

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

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 406 of file nt.c.

407 {
409 
412  is);
415  &get_addresses,
416  is);
417  return is;
418 }
#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
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:1240
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:158
#define INTERFACE_PROCESSING_INTERVAL
How frequently do we scan the interfaces for changes to the addresses?
Definition: nt.c:33
static void get_addresses(void *cls)
Periodically get list of network addresses from our interfaces.
Definition: nt.c:284
Handle to the interface scanner.
Definition: nt.c:105
struct GNUNET_SCHEDULER_Task * interface_task
Task for periodically refreshing our LAN network list.
Definition: nt.c:119

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 init_socket(), and run().

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 427 of file nt.c.

428 {
429  if (NULL != is->interface_task)
430  {
432  is->interface_task = NULL;
433  }
435  GNUNET_free (is);
436 }
#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:943
static void delete_networks(struct GNUNET_NT_InterfaceScanner *is)
Delete all entries from the current network list.
Definition: nt.c:129

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

Referenced by do_shutdown(), and shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function: