/*
- * $Id: wccp.cc,v 1.44 2007/08/08 14:47:41 rousskov Exp $
+ * $Id: wccp.cc,v 1.45 2007/12/14 23:11:48 amosjeffries Exp $
*
* DEBUG: section 80 WCCP Support
* AUTHOR: Glenn Chisholm
struct wccp_cache_entry_t
{
-
- struct IN_ADDR ip_addr;
+ IPAddress ip_addr;
int revision;
char hash[WCCP_HASH_SIZE];
int reserved;
static int last_assign_buckets_change;
static unsigned int number_caches;
-static struct IN_ADDR local_ip;
+static IPAddress local_ip;
static PF wccpHandleUdp;
static int wccpLowestIP(void);
last_assign_buckets_change = 0;
number_caches = 0;
- if (Config.Wccp.router.s_addr != any_addr.s_addr)
+ if (!Config.Wccp.router.IsAnyAddr())
if (!eventFind(wccpHereIam, NULL))
eventAdd("wccpHereIam", wccpHereIam, NULL, 5.0, 1);
}
void
wccpConnectionOpen(void)
{
- u_short port = WCCP_PORT;
-
- struct sockaddr_in router, local;
- socklen_t local_len, router_len;
+ struct addrinfo *router = NULL, *local = NULL;
debugs(80, 5, "wccpConnectionOpen: Called");
- if (Config.Wccp.router.s_addr == any_addr.s_addr) {
+ if (Config.Wccp.router.IsAnyAddr()) {
debugs(80, 2, "WCCPv1 disabled.");
return;
}
+ if ( !Config.Wccp.router.SetIPv4() ) {
+ debugs(1, 1, "WCCPv1 Disabled. Router " << Config.Wccp.router << " is not IPv4.");
+ return;
+ }
+
+ if ( !Config.Wccp.address.SetIPv4() ) {
+ debugs(1, 1, "WCCPv1 Disabled. Local address " << Config.Wccp.address << " is not IPv4.");
+ return;
+ }
+
+ Config.Wccp.address.SetPort(WCCP_PORT);
+
theWccpConnection = comm_open(SOCK_DGRAM,
IPPROTO_UDP,
Config.Wccp.address,
- port,
COMM_NONBLOCKING,
"WCCP Socket");
NULL,
0);
- debugs(80, 1, "Accepting WCCPv1 messages on port " << port << ", FD " << theWccpConnection << ".");
-
-
- router_len = sizeof(router);
-
- memset(&router, '\0', router_len);
+ debugs(80, 1, "Accepting WCCPv1 messages on " << Config.Wccp.address << ", FD " << theWccpConnection << ".");
- router.sin_family = AF_INET;
+ Config.Wccp.router.GetAddrInfo(router,AF_INET);
- router.sin_port = htons(port);
-
- router.sin_addr = Config.Wccp.router;
-
- if (connect(theWccpConnection, (struct sockaddr *) &router, router_len))
+ if (connect(theWccpConnection, router->ai_addr, router->ai_addrlen))
fatal("Unable to connect WCCP out socket");
- local_len = sizeof(local);
+ Config.Wccp.router.FreeAddrInfo(router);
- memset(&local, '\0', local_len);
+ Config.Wccp.address.InitAddrInfo(local);
- if (getsockname(theWccpConnection, (struct sockaddr *) &local, &local_len))
+ if (getsockname(theWccpConnection, local->ai_addr, &local->ai_addrlen))
fatal("Unable to getsockname on WCCP out socket");
- local_ip.s_addr = local.sin_addr.s_addr;
+ local_ip = *local;
+
+ Config.Wccp.address.FreeAddrInfo(local);
}
wccpHandleUdp(int sock, void *not_used)
{
- struct sockaddr_in from;
- socklen_t from_len;
+ IPAddress from;
int len;
debugs(80, 6, "wccpHandleUdp: Called.");
commSetSelect(sock, COMM_SELECT_READ, wccpHandleUdp, NULL, 0);
- from_len = sizeof(struct sockaddr_in);
- memset(&from, '\0', from_len);
memset(&wccp_i_see_you, '\0', sizeof(wccp_i_see_you));
len = comm_udp_recvfrom(sock,
(void *) &wccp_i_see_you,
sizeof(wccp_i_see_you),
0,
-
- (struct sockaddr *) &from,
- &from_len);
- debugs(80, 3, "wccpHandleUdp: " << len << " bytes WCCP pkt from " <<
- inet_ntoa(from.sin_addr) << ": type=" <<
+ from);
+ debugs(80, 3, "wccpHandleUdp: " << len << " bytes WCCP pkt from " << from <<
+ ": type=" <<
(unsigned) ntohl(wccp_i_see_you.type) << ", version=" <<
(unsigned) ntohl(wccp_i_see_you.version) << ", change=" <<
(unsigned) ntohl(wccp_i_see_you.change) << ", id=" <<
if (len < 0)
return;
- if (Config.Wccp.router.s_addr != from.sin_addr.s_addr)
+ if (from != Config.Wccp.router)
return;
if ((unsigned) ntohl(wccp_i_see_you.version) != (unsigned) Config.Wccp.version)
if (ntohl(wccp_i_see_you.number) > WCCP_ACTIVE_CACHES) {
debugs(80, 1, "Ignoring WCCP_I_SEE_YOU from " <<
- inet_ntoa(from.sin_addr) << " with number of caches set to " <<
+ from << " with number of caches set to " <<
(int) ntohl(wccp_i_see_you.number));
return;
for (loop = 0; loop < (unsigned) ntohl(wccp_i_see_you.number); loop++) {
assert(loop < WCCP_ACTIVE_CACHES);
- if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr < local_ip.s_addr)
+ if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr < local_ip)
return 0;
- if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr == local_ip.s_addr)
+ if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr == local_ip)
found = 1;
}
for (loop = 0; loop < number_caches; loop++) {
int i;
xmemcpy(&caches[loop],
- &wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr,
+ &wccp_i_see_you.wccp_cache_entry[loop].ip_addr,
sizeof(*caches));
for (i = 0; i < buckets_per_cache; i++) {