GNUnet 0.21.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 43 of file gnunet_nt_lib.h.

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

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

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

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

Referenced by GNUNET_NT_scanner_get_type().

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

310{
311 struct NT_Network *cur = is->net_head;
313
314 switch (addr->sa_family)
315 {
316 case AF_UNIX:
318 break;
319
320 case AF_INET:
321 {
322 const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
323
324 if ((a4->sin_addr.s_addr & htonl (0xff000000)) == htonl (0x7f000000))
326 break;
327 }
328
329 case AF_INET6:
330 {
331 const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
332
333 if (IN6_IS_ADDR_LOOPBACK (&a6->sin6_addr))
335 break;
336 }
337
338 default:
339 GNUNET_break (0);
340 break;
341 }
342
343 /* Check local networks */
344 while ((NULL != cur) && (GNUNET_NT_UNSPECIFIED == type))
345 {
346 if (addrlen != cur->length)
347 {
348 cur = cur->next;
349 continue;
350 }
351 if (addr->sa_family == AF_INET)
352 {
353 const struct sockaddr_in *a4 = (const struct sockaddr_in *) addr;
354 const struct sockaddr_in *net4 = (const struct
355 sockaddr_in *) cur->network;
356 const struct sockaddr_in *mask4 = (const struct
357 sockaddr_in *) cur->netmask;
358
359 if (((a4->sin_addr.s_addr & mask4->sin_addr.s_addr)) ==
360 net4->sin_addr.s_addr)
362 }
363 if (addr->sa_family == AF_INET6)
364 {
365 const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *) addr;
366 const struct sockaddr_in6 *net6 = (const struct
367 sockaddr_in6 *) cur->network;
368 const struct sockaddr_in6 *mask6 = (const struct
369 sockaddr_in6 *) cur->netmask;
370
371 int res = GNUNET_YES;
372 int c = 0;
373 uint32_t *addr_elem = (uint32_t *) &a6->sin6_addr;
374 uint32_t *mask_elem = (uint32_t *) &mask6->sin6_addr;
375 uint32_t *net_elem = (uint32_t *) &net6->sin6_addr;
376 for (c = 0; c < 4; c++)
377 if ((addr_elem[c] & mask_elem[c]) != net_elem[c])
378 res = GNUNET_NO;
379
380 if (res == GNUNET_YES)
382 }
383 cur = cur->next;
384 }
385
386 /* no local network found for this address, default: WAN */
390 "nt-scanner-api",
391 "`%s' is in network `%s'\n",
392 GNUNET_a2s (addr,
393 addrlen),
395 return type;
396}
struct GNUNET_TESTING_Interpreter * is
static char * res
Currently read line or NULL on EOF.
static uint32_t type
Type string converted to DNS type value.
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_YES
@ GNUNET_NO
#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:44
const char * GNUNET_NT_to_string(enum GNUNET_NetworkType net)
Convert a enum GNUNET_NetworkType to a string.
Definition: nt.c:37
We keep a list of our local networks so we can answer LAN vs.
Definition: nt.c:72
struct NT_Network * next
Kept in a DLL.
Definition: nt.c:76
socklen_t length
How long are network and netmask?
Definition: nt.c:96
struct sockaddr * network
Network address.
Definition: nt.c:86
struct sockaddr * netmask
Netmask to determine what is in the LAN.
Definition: nt.c:91

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, is, NT_Network::length, NT_Network::netmask, NT_Network::network, NT_Network::next, res, and type.

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

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

406{
408
411 is);
412 is->interface_task = GNUNET_SCHEDULER_add_delayed (
415 is);
416 return is;
417}
#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:397
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:1278
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:157
#define INTERFACE_PROCESSING_INTERVAL
How frequently do we scan the interfaces for changes to the addresses?
Definition: nt.c:32
static void get_addresses(void *cls)
Periodically get list of network addresses from our interfaces.
Definition: nt.c:283
Handle to the interface scanner.
Definition: nt.c:104

References get_addresses(), GNUNET_new, GNUNET_OS_network_interfaces_list(), GNUNET_SCHEDULER_add_delayed(), interface_proc(), INTERFACE_PROCESSING_INTERVAL, 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 426 of file nt.c.

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

References delete_networks(), GNUNET_free, GNUNET_SCHEDULER_cancel(), and is.

Referenced by do_shutdown().

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