From e0f8b7097291fc129f5090eb975832a8f16ca401 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Thu, 29 Jul 2010 22:03:19 -0600 Subject: [PATCH] Bug 2994: pt 1: Open *_port directives correctly in IPv4-only mode. Was opening snmp_port, icp_port, htcp_port under the v4-mapping assumption. This forces the ports both listening and outgoing to IPv4-only unless v4-mapping is actually available in the system. --- src/htcp.cc | 10 ++++++++++ src/icp_v2.cc | 12 ++++++++++++ src/snmp_core.cc | 8 ++++++++ 3 files changed, 30 insertions(+) diff --git a/src/htcp.cc b/src/htcp.cc index fd17a3270b..71f4275269 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -37,6 +37,7 @@ #include "htcp.h" #include "acl/FilledChecklist.h" #include "acl/Acl.h" +#include "ip/tools.h" #include "SquidTime.h" #include "Store.h" #include "StoreClient.h" @@ -1503,6 +1504,11 @@ htcpInit(void) Ip::Address incomingAddr = Config.Addrs.udp_incoming; incomingAddr.SetPort(Config.Port.htcp); + if (!Ip::EnableIpv6 && !incomingAddr.SetIPv4()) { + debugs(31, DBG_CRITICAL, "ERROR: IPv6 is disabled. " << incomingAddr << " is not an IPv4 address."); + fatal("HTCP port cannot be opened."); + } + AsyncCall::Pointer call = asyncCall(31, 2, "htcpIncomingConnectionOpened", HtcpListeningStartedDialer(&htcpIncomingConnectionOpened)); @@ -1517,6 +1523,10 @@ htcpInit(void) Ip::Address outgoingAddr = Config.Addrs.udp_outgoing; outgoingAddr.SetPort(Config.Port.htcp); + if (!Ip::EnableIpv6 && !outgoingAddr.SetIPv4()) { + debugs(31, DBG_CRITICAL, "ERROR: IPv6 is disabled. " << outgoingAddr << " is not an IPv4 address."); + fatal("HTCP port cannot be opened."); + } enter_suid(); htcpOutSocket = comm_open_listener(SOCK_DGRAM, IPPROTO_UDP, diff --git a/src/icp_v2.cc b/src/icp_v2.cc index cb1e4cde5c..781831e623 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -48,6 +48,7 @@ #include "SwapDir.h" #include "icmp/net_db.h" #include "ip/Address.h" +#include "ip/tools.h" #include "ipc/StartListening.h" #include "rfc1738.h" @@ -686,6 +687,11 @@ icpConnectionsOpen(void) addr = Config.Addrs.udp_incoming; addr.SetPort(port); + if (!Ip::EnableIpv6 && !addr.SetIPv4()) { + debugs(12, DBG_CRITICAL, "ERROR: IPv6 is disabled. " << addr << " is not an IPv4 address."); + fatal("ICP port cannot be opened."); + } + AsyncCall::Pointer call = asyncCall(12, 2, "icpIncomingConnectionOpened", IcpListeningStartedDialer(&icpIncomingConnectionOpened, addr)); @@ -701,6 +707,12 @@ icpConnectionsOpen(void) if ( !addr.IsNoAddr() ) { enter_suid(); addr.SetPort(port); + + if (!Ip::EnableIpv6 && !addr.SetIPv4()) { + debugs(49, DBG_CRITICAL, "ERROR: IPv6 is disabled. " << addr << " is not an IPv4 address."); + fatal("ICP port cannot be opened."); + } + theOutIcpConnection = comm_open_listener(SOCK_DGRAM, IPPROTO_UDP, addr, diff --git a/src/snmp_core.cc b/src/snmp_core.cc index f68c7776c9..57a93a1ee5 100644 --- a/src/snmp_core.cc +++ b/src/snmp_core.cc @@ -307,6 +307,10 @@ snmpConnectionOpen(void) if (Config.Port.snmp > 0) { Config.Addrs.snmp_incoming.SetPort(Config.Port.snmp); + if (!Ip::EnableIpv6 && !Config.Addrs.snmp_incoming.SetIPv4()) { + debugs(49, DBG_CRITICAL, "ERROR: IPv6 is disabled. " << Config.Addrs.snmp_incoming << " is not an IPv4 address."); + fatal("SNMP port cannot be opened."); + } AsyncCall::Pointer call = asyncCall(49, 2, "snmpIncomingConnectionOpened", SnmpListeningStartedDialer(&snmpIncomingConnectionOpened)); @@ -320,6 +324,10 @@ snmpConnectionOpen(void) if (!Config.Addrs.snmp_outgoing.IsNoAddr()) { Config.Addrs.snmp_outgoing.SetPort(Config.Port.snmp); + if (!Ip::EnableIpv6 && !Config.Addrs.snmp_outgoing.SetIPv4()) { + debugs(49, DBG_CRITICAL, "ERROR: IPv6 is disabled. " << Config.Addrs.snmp_outgoing << " is not an IPv4 address."); + fatal("SNMP port cannot be opened."); + } AsyncCall::Pointer call = asyncCall(49, 2, "snmpOutgoingConnectionOpened", SnmpListeningStartedDialer(&snmpOutgoingConnectionOpened)); -- 2.47.2