22 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_NET 31 #include <arpa/inet.h> 47 #define MAX_PREFIX_STRLEN 10 72 he = gethostbyaddr(&
addr,
sizeof(
addr), AF_INET);
89 static int parse_prefix(
const char *ep_name,
const char **prefixes,
90 int nr_prefixes,
int *
index,
int *shift)
94 for (
i = 0;
i < nr_prefixes; ++
i) {
95 if (prefixes[
i] !=
NULL) {
97 if (strncmp(ep_name, prefixes[
i], *shift) == 0) {
104 if (
i >= nr_prefixes)
131 const char *ep_name =
name;
136 if (
rc != 0 || ep_name[shift] !=
':')
138 ep_name += shift + 1;
142 if (
rc != 0 || ep_name[shift] !=
':')
144 ep_name += shift + 1;
146 at = strchr(ep_name,
'@');
154 portnum = strtol(
port, &end, 10);
157 addr->nia_n.nip_port = (uint16_t)portnum;
161 &
addr->nia_n.nip_format);
164 ip, &
addr->nia_n.nip_ip_n.sn[0]);
173 addr->nia_n.nip_fmt_pvt.ia.nia_family = family;
174 addr->nia_n.nip_fmt_pvt.ia.nia_type =
type;
200 const char *ep_name =
name;
205 bool is_localhost =
false;
208 at = strchr(ep_name,
'@');
209 if (strncmp(ep_name,
"0@lo", 4) == 0) {
210 nia_n = htonl(INADDR_LOOPBACK);
218 memcpy(
node, ep_name,
at - ep_name);
229 nr = sscanf(
at + 1,
"%d:%d:%d", &pid, &portal, &tmid);
231 nr = sscanf(
at + 1,
"%d:%d:*", &pid, &portal);
244 addr->nia_n.nip_fmt_pvt.la.nla_autotm =
true;
251 return M0_ERR(-EADDRNOTAVAIL);
253 addr->nia_n.nip_fmt_pvt.la.nla_autotm =
false;
271 addr->nia_n.nip_fmt_pvt.la.nla_portal = (uint16_t)portal;
273 portal = 30 + portal;
275 portnum = tmid | (1 << 10) | ((portal - 30) << 11);
280 inet_pton(AF_INET,
node, &
addr->nia_n.nip_ip_n.sn[0]);
281 addr->nia_n.nip_fmt_pvt.la.nla_tmid = (uint16_t)tmid;
282 addr->nia_n.nip_port = (uint16_t)portnum;
283 addr->nia_n.nip_fmt_pvt.la.nla_type = is_localhost ? 0xFF :
type;
300 return (a1[0] == a2[0]);
308 return (a1[0] == a2[0] && a1[1] == a2[1]);
358 char ip_p[INET6_ADDRSTRLEN] = {};
366 (
int)na->nip_format, na->nip_ip_n.ln[0], na->nip_ip_n.ln[1],
371 (
int)na->nip_fmt_pvt.la.nla_type,
372 (
int)na->nip_fmt_pvt.la.nla_portal,
373 (
int)na->nip_fmt_pvt.la.nla_tmid,
374 na->nip_fmt_pvt.la.nla_autotm ?
"true" :
"false");
377 (
int)na->nip_fmt_pvt.ia.nia_family,
378 (
int)na->nip_fmt_pvt.ia.nia_type);
381 rc = na->nip_fmt_pvt.la.nla_autotm ?
384 na->nip_fmt_pvt.la.nla_tmid);
386 inet_ntop(AF_INET, &na->nip_ip_n.sn[0], ip_p,
ARRAY_SIZE(ip_p));
389 na->nip_fmt_pvt.la.nla_type == 0xFF ?
"0" : ip_p,
390 na->nip_fmt_pvt.la.nla_type == 0xFF ?
"lo" :
391 ((na->nip_fmt_pvt.la.nla_type ==
393 na->nip_fmt_pvt.la.nla_portal, tmid);
396 inet_ntop(na->nip_fmt_pvt.ia.nia_family ==
400 na->nip_fmt_pvt.ia.nia_family ==
407 inet_ntop(AF_INET, &na->nip_ip_n.sn[0], ip_p,
ARRAY_SIZE(ip_p));
413 hostname, na->nip_port);
425 struct hostent *hname;
426 struct in_addr **
addr;
433 M0_ENTRY(
"Hostname=%s", (
char*)hostname);
434 cp = strchr(hostname,
'@');
440 strncat(
name, hostname,
n);
442 if (inet_pton(AF_INET,
name, &ip_n[0]) == 1 ||
443 inet_pton(AF_INET6,
name, &ip_n[0]) == 1) {
449 hname = gethostbyname(
name);
452 h_errno, (
char*)
name);
456 addr = (
struct in_addr **)hname->h_addr_list;
459 strcpy(ip, inet_ntoa(*
addr[
i]));
477 return (strcmp(addr1->
nia_p, addr2->
nia_p) == 0);
503 #undef M0_TRACE_SUBSYSTEM union m0_net_ip_params::@378 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)
union m0_net_ip_params::@377 nip_ip_n
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
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)