ipv6: remove use of HAVE_INET_PTON_IPV6
PATCH 1/1 ipv6: remove use of HAVE_INET_PTON_IPV6
The goal of this patch is to fix the ipv6 support when conntrackd is cross-compiled. The AC_RUN_IFELSE macro must be avoided as much as possible. See section 6.6 of the gnu autoconf:
"If you really need to test for a runtime behavior while configuring, you can
write a test program to determine the result, and compile and run it using AC_RUN_IFELSE. Avoid running test programs if possible, because this prevents people from configuring your package for cross-compiling."
Let's remove this check and test the returned error to handle the case where ipv6 is not supported (inet_pton() returns -1 when the family is not supported).
--- configure.ac | 28 ----------------- src/conntrack.c | 2 -- src/read_config_yy.y | 87 +++++++++++++++++++++++++++------------------------- 3 files changed, 46 insertions(+), 71 deletions(-)
configure.ac +0 -28
@@ -81,34 +81,6 @@ dnl AC_CHECK_LIB([c], [main]) AC_CHECK_HEADERS(arpa/inet.h) dnl check for inet_pton AC_CHECK_FUNCS(inet_pton) -dnl Some systems have it, but not IPv6 -if test "$ac_cv_func_inet_pton" = "yes" ; then -AC_MSG_CHECKING(if inet_pton supports IPv6) -AC_RUN_IFELSE([AC_LANG_SOURCE([[ -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif -#ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -int main() - { - struct in6_addr addr6; - if (inet_pton(AF_INET6, "::1", &addr6) < 1) - exit(1); - else - exit(0); - } - ]])],[ AC_MSG_RESULT(yes) - AC_DEFINE_UNQUOTED(HAVE_INET_PTON_IPV6, 1, [Define to 1 if inet_pton supports IPv6.]) - ],[AC_MSG_RESULT(no)],[AC_MSG_RESULT(no)]) -fi # Checks for header files. dnl AC_HEADER_STDC
src/conntrack.c +0 -2
@@ -1057,10 +1057,8 @@ parse_inetaddr(const char *cp, struct addr_parse *parse) {if (inet_aton (cp, &parse->addr))return AF_INET ; -#ifdef HAVE_INET_PTON_IPV6 else if (inet_pton (AF_INET6 , cp, &parse->addr6) >0 )return AF_INET6 ; -#endif return AF_UNSPEC ; }
src/read_config_yy.y +46 -41
152 lines not on this page · raw message
Signature · 1 line
2.8.1
Pablo Neira Ayuso
maintainerQuoted 10 lines · Nicolas Dichtel
The goal of this patch is to fix the ipv6 support when conntrackd is cross-compiled. The
AC_RUN_IFELSEmacro must be avoided as much as possible. See section 6.6 of the gnu autoconf:
"If you really need to test for a runtime behavior while configuring, you can
write a test program to determine the result, and compile and run it usingAC_RUN_IFELSE. Avoid running test programs if possible, because this prevents people from configuring your package for cross-compiling."Let's remove this check and test the returned error to handle the case where ipv6 is not supported (
inet_pton()returns -1 when the family is not supported).
Much less ifdef pollution, much better indeed.
One comment below:
Quoted 11 lines
src/read_config_yy.y +1
-1@@ -240,17 +240,17 @@ multicast_option : T_IPV4_ADDR T_IP multicast_option : T_IPV6_ADDR T_IP { __max_dedicated_links_reached(); + int err; -#ifdef HAVE_INET_PTON_IPV6
src/read_config_yy.y multicast_option : T_IPV4_ADDR T_IP · line 252
Quoted 10 lines
src/read_config_yy.y +6
-2- if (inet_pton(AF_INET6, $2, - &conf.channel[conf.channel_num].u.mcast.in) <= 0) { + err = inet_pton(AF_INET6, $2, + &conf.channel[conf.channel_num].u.mcast.in); + if (err == 0) { dlog(LOG_WARNING, "%s is not a valid IPv6 address", $2); break; + } else if (err < 0) { + dlog(LOG_WARNING, "inet_pton(): IPv6 unsupported!"); + break;
Probably better to exit() here and to use LOG_ERR instead?
If we cannot interpret this IPv6 address, we shouldn't go much further.
Le 29/05/2017 à 18:25, Pablo Neira Ayuso a écrit :
[snip]
Quoted 5 lines
Quoted 5 lines
src/read_config_yy.y +2
-3-#ifdef HAVE_INET_PTON_IPV6 - if (inet_pton(AF_INET6, $2, - &conf.channel[conf.channel_num].u.mcast.in) <= 0) { + err = inet_pton(AF_INET6, $2, + &conf.channel[conf.channel_num].u.mcast.in);
Quoted 8 lines
src/read_config_yy.y multicast_option : T_IPV4_ADDR T_IP · line 252
Quoted 6 lines
src/read_config_yy.y +4
-0+ if (err == 0) { dlog(LOG_WARNING, "%s is not a valid IPv6 address", $2); break; + } else if (err < 0) { + dlog(LOG_WARNING, "inet_pton(): IPv6 unsupported!"); + break;Probably better to
exit()here and to useLOG_ERRinstead?
Sure, I kept the previous behavior, but indeed, it's better to exit. I will send a new version.
PATCH v2 1/1 ipv6: remove use of HAVE_INET_PTON_IPV6
In reply to Pablo Neira AyusoThe goal of this patch is to fix the ipv6 support when conntrackd is cross-compiled. The AC_RUN_IFELSE macro must be avoided as much as possible. See section 6.6 of the gnu autoconf:
"If you really need to test for a runtime behavior while configuring, you can
write a test program to determine the result, and compile and run it using AC_RUN_IFELSE. Avoid running test programs if possible, because this prevents people from configuring your package for cross-compiling."
Let's remove this check and test the returned error to handle the case where ipv6 is not supported (inet_pton() returns -1 when the family is not supported).
---
v2: user LOG_ERR and exit() when IPv6 is not supported
configure.ac | 28 ----------------- src/conntrack.c | 2 -- src/read_config_yy.y | 87 +++++++++++++++++++++++++++------------------------- 3 files changed, 46 insertions(+), 71 deletions(-)
configure.ac +0 -28
@@ -81,34 +81,6 @@ dnl AC_CHECK_LIB([c], [main]) AC_CHECK_HEADERS(arpa/inet.h) dnl check for inet_pton AC_CHECK_FUNCS(inet_pton) -dnl Some systems have it, but not IPv6 -if test "$ac_cv_func_inet_pton" = "yes" ; then -AC_MSG_CHECKING(if inet_pton supports IPv6) -AC_RUN_IFELSE([AC_LANG_SOURCE([[ -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif -#ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif -#ifdef HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -int main() - { - struct in6_addr addr6; - if (inet_pton(AF_INET6, "::1", &addr6) < 1) - exit(1); - else - exit(0); - } - ]])],[ AC_MSG_RESULT(yes) - AC_DEFINE_UNQUOTED(HAVE_INET_PTON_IPV6, 1, [Define to 1 if inet_pton supports IPv6.]) - ],[AC_MSG_RESULT(no)],[AC_MSG_RESULT(no)]) -fi # Checks for header files. dnl AC_HEADER_STDC
src/conntrack.c +0 -2
@@ -1057,10 +1057,8 @@ parse_inetaddr(const char *cp, struct addr_parse *parse) {if (inet_aton (cp, &parse->addr))return AF_INET ; -#ifdef HAVE_INET_PTON_IPV6 else if (inet_pton (AF_INET6 , cp, &parse->addr6) >0 )return AF_INET6 ; -#endif return AF_UNSPEC ; }
src/read_config_yy.y +46 -41
152 lines not on this page · raw message
Signature · 1 line
2.8.1
Quoted 10 lines · Nicolas Dichtel
The goal of this patch is to fix the ipv6 support when conntrackd is cross-compiled. The
AC_RUN_IFELSEmacro must be avoided as much as possible. See section 6.6 of the gnu autoconf:
"If you really need to test for a runtime behavior while configuring, you can
write a test program to determine the result, and compile and run it usingAC_RUN_IFELSE. Avoid running test programs if possible, because this prevents people from configuring your package for cross-compiling."Let's remove this check and test the returned error to handle the case where ipv6 is not supported (
inet_pton()returns -1 when the family is not supported).
Applied, thanks Nicolas.