Motr  M0
ip.c File Reference
#include "lib/trace.h"
#include "net/net_internal.h"
#include "lib/assert.h"
#include "lib/errno.h"
#include "lib/string.h"
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
Include dependency graph for ip.c:

Go to the source code of this file.

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_NET
 
#define MAX_PREFIX_STRLEN   10
 

Functions

static int m0_net_ip_to_hostname (const char *ip, char *hostname)
 
static int parse_prefix (const char *ep_name, const char **prefixes, int nr_prefixes, int *index, int *shift)
 
static int m0_net_ip_inet_parse (const char *name, struct m0_net_ip_addr *addr)
 
static int m0_net_ip_lnet_parse (const char *name, struct m0_net_ip_addr *addr)
 
static bool m0_net_ip_v4_eq (const uint32_t *a1, const uint32_t *a2)
 
static bool m0_net_ip_v6_eq (const uint64_t *a1, const uint64_t *a2)
 
static bool m0_net_ip_la_eq (const struct m0_net_ip_addr *a1, const struct m0_net_ip_addr *a2)
 
static bool m0_net_ip_ia_eq (const struct m0_net_ip_addr *a1, const struct m0_net_ip_addr *a2)
 
M0_INTERNAL int m0_net_ip_parse (const char *name, struct m0_net_ip_addr *addr)
 
M0_INTERNAL int m0_net_ip_print (const struct m0_net_ip_addr *nia)
 
M0_INTERNAL int m0_net_hostname_to_ip (const char *hostname, char *ip, enum m0_net_ip_format *fmt)
 
M0_INTERNAL bool m0_net_ip_addr_eq (const struct m0_net_ip_addr *addr1, const struct m0_net_ip_addr *addr2, bool is_ncmp)
 
M0_INTERNAL int m0_net_ip_init (void)
 
M0_INTERNAL void m0_net_ip_fini (void)
 

Variables

static const char * ip_family [M0_NET_IP_AF_NR]
 
static const char * ip_protocol [M0_NET_IP_PROTO_NR]
 
static uint8_t ip_autotm [1024] = {}
 
static struct m0_mutex autotm_lock = {}
 

Macro Definition Documentation

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_NET

Definition at line 22 of file ip.c.

◆ MAX_PREFIX_STRLEN

#define MAX_PREFIX_STRLEN   10

Definition at line 47 of file ip.c.

Function Documentation

◆ m0_net_hostname_to_ip()

M0_INTERNAL int m0_net_hostname_to_ip ( const char *  hostname,
char *  ip,
enum m0_net_ip_format fmt 
)

This function convert the hostname/FQDN format to ip format. Here hostname can be FQDN or local machine hostname. Return value: = 0 in case of succesful fqdn to ip resolution. > 0 when gethostbyname fails (dns resolution failed). < 0 error.

Definition at line 415 of file ip.c.

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

◆ m0_net_ip_addr_eq()

M0_INTERNAL bool m0_net_ip_addr_eq ( const struct m0_net_ip_addr addr1,
const struct m0_net_ip_addr addr2,
bool  is_ncmp 
)

This function is used to compare the fields in struct m0_net_ip_addr. If is_ncmp is true then numeric address fields are compared else string addr is compared. Returns true if addr1 and addr2 are equal else false.

Definition at line 464 of file ip.c.

Here is the call graph for this function:

◆ m0_net_ip_fini()

M0_INTERNAL void m0_net_ip_fini ( void  )

Definition at line 489 of file ip.c.

Here is the call graph for this function:

◆ m0_net_ip_ia_eq()

static bool m0_net_ip_ia_eq ( const struct m0_net_ip_addr a1,
const struct m0_net_ip_addr a2 
)
static

Compare inet address format specific parameters.

Definition at line 326 of file ip.c.

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

◆ m0_net_ip_inet_parse()

static int m0_net_ip_inet_parse ( const char *  name,
struct m0_net_ip_addr addr 
)
static

This function decodes the inet format address. The inet address format is of type <family>:<type>:<ipaddr/hostname_FQDN><port> for example: "inet:tcp:127.0.0.1@3000", "inet:verbs:lanl.gov@23", "inet6:o2ib:FE80::0202:B3FF:FE1E:8329@6663" Return value: 0 in case of success. < 0 in case of error.

Definition at line 119 of file ip.c.

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

◆ m0_net_ip_init()

M0_INTERNAL int m0_net_ip_init ( void  )

Definition at line 482 of file ip.c.

Here is the call graph for this function:

◆ m0_net_ip_la_eq()

static bool m0_net_ip_la_eq ( const struct m0_net_ip_addr a1,
const struct m0_net_ip_addr a2 
)
static

Compare lnet address format specific parameters.

Definition at line 307 of file ip.c.

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

◆ m0_net_ip_lnet_parse()

static int m0_net_ip_lnet_parse ( const char *  name,
struct m0_net_ip_addr addr 
)
static

This function decodes the lnet format address and extracts the ip address and port number from it. This is also used to allocate unique transfer machine identifiers for LNet network addresses with wildcard transfer machine identifier (like "192.168.96.128@tcp:12345:31:*"). Return value: 0 in case of success. < 0 in case of error.

Definition at line 187 of file ip.c.

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

◆ m0_net_ip_parse()

M0_INTERNAL int m0_net_ip_parse ( const char *  name,
struct m0_net_ip_addr addr 
)

This function decodes addresses based on address format type such as lnet or inet address format. Example: lnet format: <ip><type>:<pid=12345>:<portal>:<tmid> for example:"192.168.96.128@tcp:12345:34:1" inet format: <family>:<type>:<ipaddr/hostname_FQDN><port> for example: "inet:tcp:127.0.0.1@3000" Return value: 0 in case of success. < 0 in case of error.

Definition at line 343 of file ip.c.

Here is the call graph for this function:

◆ m0_net_ip_print()

M0_INTERNAL int m0_net_ip_print ( const struct m0_net_ip_addr nia)

This function generates printable address format from struct m0_net_ip_addr::nia_n into struct m0_net_ip_addr::nia_p.

Definition at line 349 of file ip.c.

Here is the call graph for this function:

◆ m0_net_ip_to_hostname()

static int m0_net_ip_to_hostname ( const char *  ip,
char *  hostname 
)
static

This function convert the ip to hostname/FQDN format. Here ip is string containing ip address with numbes-and-dot notation.

Definition at line 63 of file ip.c.

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

◆ m0_net_ip_v4_eq()

static bool m0_net_ip_v4_eq ( const uint32_t *  a1,
const uint32_t *  a2 
)
static

Compare ipv4 address in network byte order.

Definition at line 291 of file ip.c.

Here is the caller graph for this function:

◆ m0_net_ip_v6_eq()

static bool m0_net_ip_v6_eq ( const uint64_t *  a1,
const uint64_t *  a2 
)
static

Compare ipv6 address in network byte order.

Definition at line 299 of file ip.c.

Here is the caller graph for this function:

◆ parse_prefix()

static int parse_prefix ( const char *  ep_name,
const char **  prefixes,
int  nr_prefixes,
int *  index,
int *  shift 
)
static

Definition at line 87 of file ip.c.

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

Variable Documentation

◆ autotm_lock

struct m0_mutex autotm_lock = {}
static

Lock used while parsing lnet address.

Definition at line 57 of file ip.c.

◆ ip_autotm

uint8_t ip_autotm[1024] = {}
static

Bitmap of used transfer machine identifiers. 1 is for used and 0 is for free.

Definition at line 52 of file ip.c.

◆ ip_family

const char* ip_family[M0_NET_IP_AF_NR]
static
Initial value:

Definition at line 35 of file ip.c.

◆ ip_protocol

const char* ip_protocol[M0_NET_IP_PROTO_NR]
static
Initial value:

Definition at line 40 of file ip.c.