22 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_NET 31 #include <arpa/inet.h> 47 #define MAX_PREFIX_STRLEN 10 70 he = gethostbyaddr(&
addr,
sizeof(
addr), AF_INET);
87 static int parse_prefix(
const char *ep_name,
const char **prefixes,
88 int nr_prefixes,
int *
index,
int *shift)
92 for (
i = 0;
i < nr_prefixes; ++
i) {
93 if (prefixes[
i] !=
NULL) {
95 if (strncmp(ep_name, prefixes[
i], *shift) == 0) {
102 if (
i >= nr_prefixes)
129 const char *ep_name =
name;
134 if (
rc != 0 || ep_name[shift] !=
':')
136 ep_name += shift + 1;
140 if (
rc != 0 || ep_name[shift] !=
':')
142 ep_name += shift + 1;
144 at = strchr(ep_name,
'@');
152 portnum = strtol(
port, &end, 10);
155 addr->nia_n.nip_port = (uint16_t)portnum;
159 &
addr->nia_n.nip_format);
162 ip, &
addr->nia_n.nip_ip_n.sn[0]);
171 addr->nia_n.nip_fmt_pvt.ia.nia_family = family;
172 addr->nia_n.nip_fmt_pvt.ia.nia_type =
type;
198 const char *ep_name =
name;
203 bool is_localhost =
false;
206 at = strchr(ep_name,
'@');
207 if (strncmp(ep_name,
"0@lo", 4) == 0) {
208 nia_n = htonl(INADDR_LOOPBACK);
216 memcpy(
node, ep_name,
at - ep_name);
227 nr = sscanf(
at + 1,
"%d:%d:%d", &pid, &portal, &tmid);
229 nr = sscanf(
at + 1,
"%d:%d:*", &pid, &portal);
237 addr->nia_n.nip_fmt_pvt.la.nla_autotm =
true;
244 return M0_ERR(-EADDRNOTAVAIL);
246 addr->nia_n.nip_fmt_pvt.la.nla_autotm =
false;
264 addr->nia_n.nip_fmt_pvt.la.nla_portal = (uint16_t)portal;
266 portal = 30 + portal;
268 portnum = tmid | (1 << 10) | ((portal - 30) << 11);
273 inet_pton(AF_INET,
node, &
addr->nia_n.nip_ip_n.sn[0]);
274 addr->nia_n.nip_fmt_pvt.la.nla_tmid = (uint16_t)tmid;
275 addr->nia_n.nip_port = (uint16_t)portnum;
276 addr->nia_n.nip_fmt_pvt.la.nla_type = is_localhost ? 0xFF :
type;
293 return (a1[0] == a2[0]);
301 return (a1[0] == a2[0] && a1[1] == a2[1]);
351 char ip_p[INET6_ADDRSTRLEN] = {};
359 (
int)na->nip_format, na->nip_ip_n.ln[0], na->nip_ip_n.ln[1],
364 (
int)na->nip_fmt_pvt.la.nla_type,
365 (
int)na->nip_fmt_pvt.la.nla_portal,
366 (
int)na->nip_fmt_pvt.la.nla_tmid,
367 na->nip_fmt_pvt.la.nla_autotm ?
"true" :
"false");
370 (
int)na->nip_fmt_pvt.ia.nia_family,
371 (
int)na->nip_fmt_pvt.ia.nia_type);
374 rc = na->nip_fmt_pvt.la.nla_autotm ?
377 na->nip_fmt_pvt.la.nla_tmid);
379 inet_ntop(AF_INET, &na->nip_ip_n.sn[0], ip_p,
ARRAY_SIZE(ip_p));
382 na->nip_fmt_pvt.la.nla_type == 0xFF ?
"0" : ip_p,
383 na->nip_fmt_pvt.la.nla_type == 0xFF ?
"lo" :
384 ((na->nip_fmt_pvt.la.nla_type ==
386 na->nip_fmt_pvt.la.nla_portal, tmid);
389 inet_ntop(na->nip_fmt_pvt.ia.nia_family ==
393 na->nip_fmt_pvt.ia.nia_family ==
400 inet_ntop(AF_INET, &na->nip_ip_n.sn[0], ip_p,
ARRAY_SIZE(ip_p));
406 hostname, na->nip_port);
418 struct hostent *hname;
419 struct in_addr **
addr;
426 M0_ENTRY(
"Hostname=%s", (
char*)hostname);
427 cp = strchr(hostname,
'@');
433 strncat(
name, hostname,
n);
435 if (inet_pton(AF_INET,
name, &ip_n[0]) == 1 ||
436 inet_pton(AF_INET6,
name, &ip_n[0]) == 1) {
442 hname = gethostbyname(
name);
445 h_errno, (
char*)
name);
449 addr = (
struct in_addr **)hname->h_addr_list;
452 strcpy(ip, inet_ntoa(*
addr[
i]));
470 return (strcmp(addr1->
nia_p, addr2->
nia_p) == 0);
496 #undef M0_TRACE_SUBSYSTEM union m0_net_ip_params::@377 nip_fmt_pvt
static bool m0_net_ip_v4_eq(const uint32_t *a1, const uint32_t *a2)
struct m0_net_ip_lnet_addr la
static const char * ip_protocol[M0_NET_IP_PROTO_NR]
M0_INTERNAL void m0_mutex_unlock(struct m0_mutex *mutex)
static int m0_net_ip_to_hostname(const char *ip, char *hostname)
enum m0_net_ip_format nip_format
M0_INTERNAL int m0_net_hostname_to_ip(const char *hostname, char *ip, enum m0_net_ip_format *fmt)
static bool m0_net_ip_ia_eq(const struct m0_net_ip_addr *a1, const struct m0_net_ip_addr *a2)
#define M0_LOG(level,...)
static struct net_test_cmd_node * node
#define M0_NET_IP_PORTLEN_MAX
static int m0_net_ip_lnet_parse(const char *name, struct m0_net_ip_addr *addr)
M0_INTERNAL void m0_mutex_lock(struct m0_mutex *mutex)
M0_INTERNAL void m0_net_ip_fini(void)
struct m0_net_ip_params nia_n
char nia_p[M0_NET_IP_STRLEN_MAX]
M0_INTERNAL int m0_net_ip_print(const struct m0_net_ip_addr *nia)
return M0_ERR(-EOPNOTSUPP)
static uint8_t ip_autotm[1024]
static bool m0_net_ip_v6_eq(const uint64_t *a1, const uint64_t *a2)
#define MAX_PREFIX_STRLEN
struct m0_net_ip_inet_addr ia
union m0_net_ip_params::@376 nip_ip_n
char * fmt(const char *format,...) __attribute__((format(printf
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
M0_INTERNAL int m0_net_ip_init(void)
static int parse_prefix(const char *ep_name, const char **prefixes, int nr_prefixes, int *index, int *shift)
static bool at(struct ff2c_context *ctx, char c)
static int m0_net_ip_inet_parse(const char *name, struct m0_net_ip_addr *addr)
M0_INTERNAL int m0_net_ip_parse(const char *name, struct m0_net_ip_addr *addr)
M0_INTERNAL void m0_mutex_fini(struct m0_mutex *mutex)
static bool m0_net_ip_la_eq(const struct m0_net_ip_addr *a1, const struct m0_net_ip_addr *a2)
#define M0_NET_IP_STRLEN_MAX
static struct m0_mutex autotm_lock
#define M0_NET_IP_PORT_MAX
static const char * ip_family[M0_NET_IP_AF_NR]
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)