提交 15a30510 编写于 作者: M Mark Sliva 提交者: Jacob Champion

cross-subnet: add ifaddrs utility

The interface addresses used for replication will be scanned using this new
utility we added called ifaddrs that returns all of the interface addresses
separated by newlines. As an internal utility, this will be installed into
$GPHOME/libexec. There is no Python 2 library that provides this functionality,
so we add it ourselves.

Also add a configure dependency on getifaddrs and inet_ntop, which are now
required to build a functioning GPDB system. As far as we can tell, the
other headers and functions are already handled through other configure
checks.
Co-authored-by: NJacob Champion <pchampion@pivotal.io>
Co-authored-by: NAdam Berlin <aberlin@pivotal.io>
Co-authored-by: NBhuvnesh Chaudhary <bchaudhary@pivotal.io>
Co-authored-by: NKalen Krempely <kkrempely@pivotal.io>
Co-authored-by: NDavid Krieger <dkrieger@pivotal.io>
Co-authored-by: NJamie McAtamney <jmcatamney@pivotal.io>
上级 05681977
......@@ -16648,6 +16648,27 @@ fi
done
# For upstream Postgres, the getifaddrs() symbol is optional, but the GPDB
# ifaddrs utility requires it, along with inet_ntop(). The check for getifaddrs
# is duplicated here to avoid a merge conflict in the AC_CHECK_FUNCS block
# above.
for ac_func in getifaddrs inet_ntop
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
else
as_fn_error $? "getifaddrs and inet_ntop are required for Greenplum" "$LINENO" 5
fi
done
ac_fn_c_check_func "$LINENO" "fseeko" "ac_cv_func_fseeko"
if test "x$ac_cv_func_fseeko" = xyes; then :
$as_echo "#define HAVE_FSEEKO 1" >>confdefs.h
......
......@@ -2017,6 +2017,17 @@ AC_CHECK_FUNCS(m4_normalize([
wcstombs_l
]))
# For upstream Postgres, the getifaddrs() symbol is optional, but the GPDB
# ifaddrs utility requires it, along with inet_ntop(). The check for getifaddrs
# is duplicated here to avoid a merge conflict in the AC_CHECK_FUNCS block
# above.
AC_CHECK_FUNCS(m4_normalize([
getifaddrs
inet_ntop
]), [], [
AC_MSG_ERROR([getifaddrs and inet_ntop are required for Greenplum])
])
AC_REPLACE_FUNCS(fseeko)
case $host_os in
# NetBSD uses a custom fseeko/ftello built on fsetpos/fgetpos
......
......@@ -7,7 +7,8 @@ ifneq "$(wildcard $(top_builddir)/src/Makefile.global)" ""
include $(top_builddir)/src/Makefile.global
endif
SUBDIRS= stream gpcheckcat_modules gpconfig_modules gpssh_modules gppylib lib
SUBDIRS = stream gpcheckcat_modules gpconfig_modules gpssh_modules gppylib lib
SUBDIRS += ifaddrs
$(recurse)
......
subdir = gpMgmt/bin/ifaddrs
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
OBJS := main.o
all: ifaddrs
ifaddrs: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) -o $@$(X)
install: all installdirs
$(INSTALL_PROGRAM) ifaddrs$(X) '$(DESTDIR)$(libexecdir)'/ifaddrs$(X)
installdirs:
$(MKDIR_P) '$(DESTDIR)$(libexecdir)'
uninstall:
rm -f '$(DESTDIR)$(libexecdir)/ifaddrs$(X)'
clean distclean maintainer-clean:
rm -f ifaddrs$(X) $(OBJS)
/*
* ifaddrs - prints the routable IP addresses for all interfaces on the local
* system. Link-local addresses are never printed.
*
* Options:
* --no-loopback: suppresses output for loopback interfaces
*/
#include <arpa/inet.h>
#include <getopt.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
struct ifaddrs *list;
int err;
int c;
/* Options */
int no_loopback = 0;
struct option opts[] = {
{"no-loopback", no_argument, &no_loopback, 1},
{ NULL },
};
while ((c = getopt_long(argc, argv, "", opts, NULL)) != -1)
{
switch (c)
{
case 0:
/* flag assignment already handled */
break;
default:
fprintf(stderr, "usage: %s [--no-loopback]\n", argv[0]);
return 1;
}
}
err = getifaddrs(&list);
if (err)
{
perror("getifaddrs");
return 1;
}
for (; list; list = list->ifa_next)
{
const void *netaddr; /* the address to be converted to a string */
char addrbuf[INET6_ADDRSTRLEN];
const char *addrstr;
struct sockaddr_in *addr4;
struct sockaddr_in6 *addr6;
struct sockaddr *addr = list->ifa_addr;
if (no_loopback && (list->ifa_flags & IFF_LOOPBACK))
{
/* user has requested that loopback interfaces not be printed */
continue;
}
switch (addr->sa_family)
{
case AF_INET:
addr4 = (struct sockaddr_in *) addr;
netaddr = &addr4->sin_addr;
break;
case AF_INET6:
addr6 = (struct sockaddr_in6 *) addr;
if (addr6->sin6_scope_id)
{
/* Don't print out link-local addresses. */
continue;
}
netaddr = &addr6->sin6_addr;
break;
default:
/* we only care about IPv4/6 */
continue;
}
/* Convert the address to a human-readable string */
addrstr = inet_ntop(addr->sa_family, netaddr, addrbuf, sizeof(addrbuf));
if (!addrstr)
{
perror("inet_ntop");
return 1;
}
printf("%s\n", addrstr);
}
return 0;
}
......@@ -108,6 +108,7 @@ datarootdir := @datarootdir@
bindir := @bindir@
sbindir := @sbindir@
libexecdir := @libexecdir@
datadir := @datadir@
ifeq "$(findstring pgsql, $(datadir))" ""
......
......@@ -306,6 +306,9 @@
/* Define to 1 if you have the `inet_aton' function. */
#undef HAVE_INET_ATON
/* Define to 1 if you have the `inet_ntop' function. */
#undef HAVE_INET_NTOP
/* Define to 1 if the system has the type `int64'. */
#undef HAVE_INT64
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册