Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
  • Loading branch information
bmk committed Oct 17, 2024
2 parents 25908ae + 33f3604 commit ff7556b
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 134 deletions.
53 changes: 50 additions & 3 deletions erts/emulator/drivers/common/inet_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,25 @@
#define D2S(__D__) (((__D__) == INET_DELIVER_PORT) ? "port" : \
(((__D__) == INET_DELIVER_TERM) ? "term" : \
"undefined"))
#define DOM2S(__D__) (((__D__) == INET_AF_INET) ? "inet" : \
(((__D__) == INET_AF_INET6) ? "inet6" : \
(((__D__) == INET_AF_LOCAL) ? "local" : \
#define DOM2S(__D__) (((__D__) == INET_AF_INET) ? "inet" : \
(((__D__) == INET_AF_INET6) ? "inet6" : \
(((__D__) == INET_AF_LOCAL) ? "local" : \
"undefined")))
#if defined(AF_LINK)
#define FAM2S(__F__) (((__F__) == AF_INET) ? "inet" : \
(((__F__) == AF_INET6) ? "inet6" : \
(((__F__) == AF_LINK) ? "link" : \
"undefined")))
#elif defined(AF_PACKET)
#define FAM2S(__F__) (((__F__) == AF_INET) ? "inet" : \
(((__F__) == AF_INET6) ? "inet6" : \
(((__F__) == AF_PACKET) ? "packet" : \
"undefined")))
#else
#define FAM2S(__F__) (((__F__) == AF_INET) ? "inet" : \
(((__F__) == AF_INET6) ? "inet6" : \
"undefined"))
#endif

#if defined(__WIN32__) && defined(ARCH_64)
#define SOCKET_FSTR "%lld"
Expand Down Expand Up @@ -6571,20 +6586,44 @@ static ErlDrvSSizeT inet_ctl_getifaddrs(inet_descriptor* desc_p,
} \
} while (0)

DDBG(desc_p,
("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
"%s -> get if addrs"
"\r\n",
__LINE__, desc_p->s, driver_caller(desc_p->port), __FUNCTION__) );

if ((save_errno = call_getifaddrs(desc_p, &ifa_p)) != 0)
return ctl_error(save_errno, rbuf_pp, rsize);

ifa_free_p = ifa_p;
*buf_p++ = INET_REP_OK;
for (; ifa_p; ifa_p = ifa_p->ifa_next) {
int len = utf8_len(ifa_p->ifa_name, -1);

DDBG(desc_p,
("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
"%s -> process if-addr %s"
"\r\n flags: 0x%X"
"\r\n",
__LINE__, desc_p->s, driver_caller(desc_p->port), __FUNCTION__,
ifa_p->ifa_name, ifa_p->ifa_flags) );

BUF_ENSURE(len+1 + 1+4 + 1);
utf8_encode(ifa_p->ifa_name, -1, buf_p);
buf_p += len;
*buf_p++ = '\0';
*buf_p++ = INET_IFOPT_FLAGS;
put_int32(IFGET_FLAGS(ifa_p->ifa_flags), buf_p); buf_p += 4;
if (ifa_p->ifa_addr) {

DDBG(desc_p,
("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
"%s -> family: %d (%s)"
"\r\n",
__LINE__, desc_p->s, driver_caller(desc_p->port), __FUNCTION__,
ifa_p->ifa_addr->sa_family,
FAM2S(ifa_p->ifa_addr->sa_family)) );

if (ifa_p->ifa_addr->sa_family == AF_INET
#if defined(AF_INET6)
|| ifa_p->ifa_addr->sa_family == AF_INET6
Expand Down Expand Up @@ -6632,6 +6671,14 @@ static ErlDrvSSizeT inet_ctl_getifaddrs(inet_descriptor* desc_p,
/* buf_p is now unreliable */
freeifaddrs(ifa_free_p);
*rbuf_pp = buf_alloc_p;

DDBG(desc_p,
("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] "
"%s -> done when buffer size: %d"
"\r\n",
__LINE__, desc_p->s, driver_caller(desc_p->port), __FUNCTION__,
buf_size) );

return buf_size;
# undef BUF_ENSURE
}
Expand Down
27 changes: 27 additions & 0 deletions erts/emulator/nifs/common/prim_net_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,8 @@ void encode_ifaddrs(ErlNifEnv* env,
ERL_NIF_TERM eifAddrs;
BOOLEAN_T extraAddr; // This is just for debugging...

NDBG( ("NET", "encode_ifaddrs -> entry\r\n") );

ename = encode_ifaddrs_name(env, ifap->ifa_name);
NDBG( ("NET", "encode_ifaddrs -> name: %T\r\n", ename) );
eflags = encode_ifaddrs_flags(env, ifap->ifa_flags);
Expand All @@ -1618,13 +1620,15 @@ void encode_ifaddrs(ErlNifEnv* env,
NDBG( ("NET", "encode_ifaddrs -> addr: "
"\r\n %T"
"\r\n", eaddr) );

/* This is an ugly (OpenBSD?) hack...
* "For some reason" the netmask family is set to 'AF_UNSPEC'
* (when the addr family is AF_INET) on OpenBSD,
* which makes encoding the address "difficult"...
* So force the family to AF_INET in this case to allow encoding
* the netmask...
*/

if ((ifap->ifa_addr != NULL) &&
(((ESockAddress*)ifap->ifa_addr)->sa.sa_family == AF_INET)) {
if ((ifap->ifa_netmask != NULL) &&
Expand All @@ -1637,18 +1641,41 @@ void encode_ifaddrs(ErlNifEnv* env,
"\r\n %T"
"\r\n", enetmask) );
if (ifap->ifa_dstaddr && (ifap->ifa_flags & IFF_POINTOPOINT)) {

NDBG( ("NET", "encode_ifaddrs -> try encode dest addr\r\n") );

/* What the eff is this fakery? */
if (((ESockAddress*)ifap->ifa_dstaddr)->sa.sa_family == AF_UNSPEC)
((ESockAddress*)ifap->ifa_dstaddr)->sa.sa_family = AF_INET;

extraAddr = TRUE;
eifu_key = atom_dstaddr;
eifu_value = encode_ifaddrs_addr(env, ifap->ifa_dstaddr);

NDBG( ("NET", "encode_ifaddrs -> dest addr: "
"\r\n %T"
"\r\n", eifu_value) );

} else if (ifap->ifa_broadaddr && (ifap->ifa_flags & IFF_BROADCAST)) {

NDBG( ("NET", "encode_ifaddrs -> try encode broad addr\r\n") );

extraAddr = TRUE;
eifu_key = atom_broadaddr;
eifu_value = encode_ifaddrs_addr(env, ifap->ifa_broadaddr);

NDBG( ("NET", "encode_ifaddrs -> broad addr: "
"\r\n %T"
"\r\n", eifu_value) );

} else {

extraAddr = FALSE;
eifu_key = esock_atom_undefined;
eifu_value = esock_atom_undefined;

}

if (extraAddr) {
NDBG( ("NET", "encode_ifaddrs -> ifu: "
"\r\n key: %T"
Expand Down
14 changes: 13 additions & 1 deletion erts/emulator/nifs/common/prim_socket_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,7 @@ static const struct in6_addr in6addr_loopback =
* in the socket_int.h file!
*/
#define GLOBAL_ATOMS \
GLOBAL_ATOM_DECL(6to4); \
GLOBAL_ATOM_DECL(abort); \
GLOBAL_ATOM_DECL(accept); \
GLOBAL_ATOM_DECL(acceptconn); \
Expand Down Expand Up @@ -1984,6 +1985,7 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(base_addr); \
GLOBAL_ATOM_DECL(bindtodevice); \
GLOBAL_ATOM_DECL(block_source); \
GLOBAL_ATOM_DECL(bridge); \
GLOBAL_ATOM_DECL(broadcast); \
GLOBAL_ATOM_DECL(bsp_state); \
GLOBAL_ATOM_DECL(busy_poll); \
Expand All @@ -1995,6 +1997,7 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(cancel); \
GLOBAL_ATOM_DECL(cancelled); \
GLOBAL_ATOM_DECL(cantconfig); \
GLOBAL_ATOM_DECL(cellular); \
GLOBAL_ATOM_DECL(chaos); \
GLOBAL_ATOM_DECL(checksum); \
GLOBAL_ATOM_DECL(close); \
Expand Down Expand Up @@ -2070,7 +2073,9 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(frelay); \
GLOBAL_ATOM_DECL(get_overlapped_result); \
GLOBAL_ATOM_DECL(get_peer_addr_info); \
GLOBAL_ATOM_DECL(gif); \
GLOBAL_ATOM_DECL(hatype); \
GLOBAL_ATOM_DECL(hdh1822); \
GLOBAL_ATOM_DECL(hdrincl); \
GLOBAL_ATOM_DECL(hmac_ident); \
GLOBAL_ATOM_DECL(hoplimit); \
Expand All @@ -2097,6 +2102,7 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(ipcomp_level); \
GLOBAL_ATOM_DECL(ipip); \
GLOBAL_ATOM_DECL(iplevel); \
GLOBAL_ATOM_DECL(ipv4); \
GLOBAL_ATOM_DECL(ipv6); \
GLOBAL_ATOM_DECL(irq); \
GLOBAL_ATOM_DECL(i_want_mapped_v4_addr); \
Expand All @@ -2119,6 +2125,7 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(local); \
GLOBAL_ATOM_DECL(localtlk); \
GLOBAL_ATOM_DECL(local_auth_chunks); \
GLOBAL_ATOM_DECL(loop); \
GLOBAL_ATOM_DECL(loopback); \
GLOBAL_ATOM_DECL(lowdelay); \
GLOBAL_ATOM_DECL(lower_up); \
Expand Down Expand Up @@ -2179,6 +2186,7 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(oobinline); \
GLOBAL_ATOM_DECL(options); \
GLOBAL_ATOM_DECL(origdstaddr); \
GLOBAL_ATOM_DECL(other); \
GLOBAL_ATOM_DECL(otherhost); \
GLOBAL_ATOM_DECL(outgoing); \
GLOBAL_ATOM_DECL(packet); \
Expand All @@ -2197,7 +2205,8 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(port); \
GLOBAL_ATOM_DECL(portrange); \
GLOBAL_ATOM_DECL(portsel); \
GLOBAL_ATOM_DECL(ppromisc); \
GLOBAL_ATOM_DECL(ppromisc); \
GLOBAL_ATOM_DECL(ppp); \
GLOBAL_ATOM_DECL(primary_addr); \
GLOBAL_ATOM_DECL(prim_file); \
GLOBAL_ATOM_DECL(priority); \
Expand Down Expand Up @@ -2285,6 +2294,7 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(staticarp); \
GLOBAL_ATOM_DECL(state); \
GLOBAL_ATOM_DECL(status); \
GLOBAL_ATOM_DECL(stf); \
GLOBAL_ATOM_DECL(stream); \
GLOBAL_ATOM_DECL(syncnt); \
GLOBAL_ATOM_DECL(syn_rcvd); \
Expand Down Expand Up @@ -2330,6 +2340,8 @@ static const struct in6_addr in6addr_loopback =
GLOBAL_ATOM_DECL(write_pkg); \
GLOBAL_ATOM_DECL(write_tries); \
GLOBAL_ATOM_DECL(write_waits); \
GLOBAL_ATOM_DECL(x25ddn); \
GLOBAL_ATOM_DECL(x25); \
GLOBAL_ATOM_DECL(zero)


Expand Down
14 changes: 13 additions & 1 deletion erts/emulator/nifs/common/socket_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ typedef long ssize_t;
*/

#define GLOBAL_ATOM_DEFS \
GLOBAL_ATOM_DEF(6to4); \
GLOBAL_ATOM_DEF(abort); \
GLOBAL_ATOM_DEF(accept); \
GLOBAL_ATOM_DEF(acceptconn); \
Expand Down Expand Up @@ -240,6 +241,7 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(base_addr); \
GLOBAL_ATOM_DEF(bindtodevice); \
GLOBAL_ATOM_DEF(block_source); \
GLOBAL_ATOM_DEF(bridge); \
GLOBAL_ATOM_DEF(broadcast); \
GLOBAL_ATOM_DEF(bsp_state); \
GLOBAL_ATOM_DEF(busy_poll); \
Expand All @@ -251,6 +253,7 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(cancel); \
GLOBAL_ATOM_DEF(cancelled); \
GLOBAL_ATOM_DEF(cantconfig); \
GLOBAL_ATOM_DEF(cellular); \
GLOBAL_ATOM_DEF(chaos); \
GLOBAL_ATOM_DEF(checksum); \
GLOBAL_ATOM_DEF(close); \
Expand Down Expand Up @@ -326,7 +329,9 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(frelay); \
GLOBAL_ATOM_DEF(get_overlapped_result); \
GLOBAL_ATOM_DEF(get_peer_addr_info); \
GLOBAL_ATOM_DEF(gif); \
GLOBAL_ATOM_DEF(hatype); \
GLOBAL_ATOM_DEF(hdh1822); \
GLOBAL_ATOM_DEF(hdrincl); \
GLOBAL_ATOM_DEF(hmac_ident); \
GLOBAL_ATOM_DEF(hoplimit); \
Expand All @@ -353,6 +358,7 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(ipcomp_level); \
GLOBAL_ATOM_DEF(ipip); \
GLOBAL_ATOM_DEF(iplevel); \
GLOBAL_ATOM_DEF(ipv4); \
GLOBAL_ATOM_DEF(ipv6); \
GLOBAL_ATOM_DEF(irq); \
GLOBAL_ATOM_DEF(i_want_mapped_v4_addr); \
Expand All @@ -375,6 +381,7 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(local); \
GLOBAL_ATOM_DEF(localtlk); \
GLOBAL_ATOM_DEF(local_auth_chunks); \
GLOBAL_ATOM_DEF(loop); \
GLOBAL_ATOM_DEF(loopback); \
GLOBAL_ATOM_DEF(lowdelay); \
GLOBAL_ATOM_DEF(lower_up); \
Expand Down Expand Up @@ -435,6 +442,7 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(oobinline); \
GLOBAL_ATOM_DEF(options); \
GLOBAL_ATOM_DEF(origdstaddr); \
GLOBAL_ATOM_DEF(other); \
GLOBAL_ATOM_DEF(otherhost); \
GLOBAL_ATOM_DEF(outgoing); \
GLOBAL_ATOM_DEF(packet); \
Expand All @@ -449,11 +457,12 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(pktinfo); \
GLOBAL_ATOM_DEF(pktoptions); \
GLOBAL_ATOM_DEF(pkttype); \
GLOBAL_ATOM_DEF(ppromisc); \
GLOBAL_ATOM_DEF(pointopoint); \
GLOBAL_ATOM_DEF(port); \
GLOBAL_ATOM_DEF(portrange); \
GLOBAL_ATOM_DEF(portsel); \
GLOBAL_ATOM_DEF(ppromisc); \
GLOBAL_ATOM_DEF(ppp); \
GLOBAL_ATOM_DEF(primary_addr); \
GLOBAL_ATOM_DEF(prim_file); \
GLOBAL_ATOM_DEF(priority); \
Expand Down Expand Up @@ -542,6 +551,7 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(state); \
GLOBAL_ATOM_DEF(status); \
GLOBAL_ATOM_DEF(staticarp); \
GLOBAL_ATOM_DEF(stf); \
GLOBAL_ATOM_DEF(stream); \
GLOBAL_ATOM_DEF(syncnt); \
GLOBAL_ATOM_DEF(syn_rcvd); \
Expand Down Expand Up @@ -585,6 +595,8 @@ typedef long ssize_t;
GLOBAL_ATOM_DEF(write_pkg); \
GLOBAL_ATOM_DEF(write_tries); \
GLOBAL_ATOM_DEF(write_waits); \
GLOBAL_ATOM_DEF(x25ddn); \
GLOBAL_ATOM_DEF(x25); \
GLOBAL_ATOM_DEF(zero)


Expand Down
Loading

0 comments on commit ff7556b

Please sign in to comment.