Must3(ntohs(wccp2_i_see_you.version) == WCCP2_VERSION, "WCCP version unsupported", Here());
Must3(ntohl(wccp2_i_see_you.type) == WCCP2_I_SEE_YOU, "WCCP packet type unsupported", Here());
- // XXX: drop conversion boundary
- from_tmp.getSockAddr(from);
+ // XXX: drop conversion boundary
+ from_tmp.getSockAddr(from);
- debugs(80, 3, "Incoming WCCPv2 I_SEE_YOU length " << ntohs(wccp2_i_see_you.length) << ".");
+ debugs(80, 3, "Incoming WCCPv2 I_SEE_YOU length " << ntohs(wccp2_i_see_you.length) << ".");
- /* Record the total data length */
- const auto data_length = ntohs(wccp2_i_see_you.length);
- Must3(data_length <= len - message_header_size,
- "malformed packet claiming it's bigger than received data", Here());
+ /* Record the total data length */
+ const auto data_length = ntohs(wccp2_i_see_you.length);
+ Must3(data_length <= len - message_header_size,
+ "malformed packet claiming it's bigger than received data", Here());
- size_t offset = 0;
+ size_t offset = 0;
- /* Go through the data structure */
- while (offset + sizeof(struct wccp2_item_header_t) <= data_length) {
+ /* Go through the data structure */
+ while (offset + sizeof(struct wccp2_item_header_t) <= data_length) {
- char *data = wccp2_i_see_you.data;
+ char *data = wccp2_i_see_you.data;
- const auto itemHeader = reinterpret_cast<const wccp2_item_header_t*>(&data[offset]);
- const auto itemSize = CheckFieldDataLength(itemHeader, ntohs(itemHeader->length),
- data, data_length, "truncated record");
- // XXX: Check "The specified length must be a multiple of 4 octets"
- // requirement to avoid unaligned memory reads after the first item.
+ const auto itemHeader = reinterpret_cast<const wccp2_item_header_t*>(&data[offset]);
+ const auto itemSize = CheckFieldDataLength(itemHeader, ntohs(itemHeader->length),
+ data, data_length, "truncated record");
+ // XXX: Check "The specified length must be a multiple of 4 octets"
+ // requirement to avoid unaligned memory reads after the first item.
- switch (ntohs(itemHeader->type)) {
+ switch (ntohs(itemHeader->type)) {
- case WCCP2_SECURITY_INFO:
- Must3(!security_info, "duplicate security definition", Here());
- SetField(security_info, itemHeader, itemHeader, itemSize,
- "security definition truncated");
- break;
+ case WCCP2_SECURITY_INFO:
+ Must3(!security_info, "duplicate security definition", Here());
+ SetField(security_info, itemHeader, itemHeader, itemSize,
+ "security definition truncated");
+ break;
- case WCCP2_SERVICE_INFO:
- Must3(!service_info, "duplicate service_info definition", Here());
- SetField(service_info, itemHeader, itemHeader, itemSize,
- "service_info definition truncated");
- break;
+ case WCCP2_SERVICE_INFO:
+ Must3(!service_info, "duplicate service_info definition", Here());
+ SetField(service_info, itemHeader, itemHeader, itemSize,
+ "service_info definition truncated");
+ break;
- case WCCP2_ROUTER_ID_INFO:
- Must3(!router_identity_info, "duplicate router_identity_info definition", Here());
- SetField(router_identity_info, itemHeader, itemHeader, itemSize,
- "router_identity_info definition truncated");
- break;
+ case WCCP2_ROUTER_ID_INFO:
+ Must3(!router_identity_info, "duplicate router_identity_info definition", Here());
+ SetField(router_identity_info, itemHeader, itemHeader, itemSize,
+ "router_identity_info definition truncated");
+ break;
- case WCCP2_RTR_VIEW_INFO:
- Must3(!router_view_header, "duplicate router_view definition", Here());
- SetField(router_view_header, itemHeader, itemHeader, itemSize,
- "router_view definition truncated");
- break;
+ case WCCP2_RTR_VIEW_INFO:
+ Must3(!router_view_header, "duplicate router_view definition", Here());
+ SetField(router_view_header, itemHeader, itemHeader, itemSize,
+ "router_view definition truncated");
+ break;
- case WCCP2_CAPABILITY_INFO: {
- Must3(!router_capability_header, "duplicate router_capability definition", Here());
- SetField(router_capability_header, itemHeader, itemHeader, itemSize,
- "router_capability definition truncated");
+ case WCCP2_CAPABILITY_INFO: {
+ Must3(!router_capability_header, "duplicate router_capability definition", Here());
+ SetField(router_capability_header, itemHeader, itemHeader, itemSize,
+ "router_capability definition truncated");
- CheckFieldDataLength(router_capability_header, ntohs(router_capability_header->capability_info_length),
- itemHeader, itemSize, "capability info truncated");
- router_capability_data_start = reinterpret_cast<char*>(router_capability_header) +
- sizeof(*router_capability_header);
- break;
- }
+ CheckFieldDataLength(router_capability_header, ntohs(router_capability_header->capability_info_length),
+ itemHeader, itemSize, "capability info truncated");
+ router_capability_data_start = reinterpret_cast<char*>(router_capability_header) +
+ sizeof(*router_capability_header);
+ break;
+ }
- /* Nothing to do for the types below */
+ /* Nothing to do for the types below */
- case WCCP2_ASSIGN_MAP:
- case WCCP2_REDIRECT_ASSIGNMENT:
- break;
+ case WCCP2_ASSIGN_MAP:
+ case WCCP2_REDIRECT_ASSIGNMENT:
+ break;
- default:
- debugs(80, DBG_IMPORTANT, "Unknown record type in WCCPv2 Packet (" << ntohs(itemHeader->type) << ").");
+ default:
+ debugs(80, DBG_IMPORTANT, "Unknown record type in WCCPv2 Packet (" << ntohs(itemHeader->type) << ").");
+ }
+
+ offset += itemSize;
+ assert(offset <= data_length && "CheckFieldDataLength(itemHeader...) established that");
}
- offset += itemSize;
- assert(offset <= data_length && "CheckFieldDataLength(itemHeader...) established that");
- }
+ Must3(security_info, "packet missing security definition", Here());
+ Must3(service_info, "packet missing service_info definition", Here());
+ Must3(router_identity_info, "packet missing router_identity_info definition", Here());
+ Must3(router_view_header, "packet missing router_view definition", Here());
- Must3(security_info, "packet missing security definition", Here());
- Must3(service_info, "packet missing service_info definition", Here());
- Must3(router_identity_info, "packet missing router_identity_info definition", Here());
- Must3(router_view_header, "packet missing router_view definition", Here());
+ debugs(80, 5, "Complete packet received");
- debugs(80, 5, "Complete packet received");
+ /* Check that the service in the packet is configured on this router */
+ service_list_ptr = wccp2_service_list_head;
- /* Check that the service in the packet is configured on this router */
- service_list_ptr = wccp2_service_list_head;
+ while (service_list_ptr != NULL) {
+ if (service_info->service_id == service_list_ptr->service_info->service_id) {
+ break;
+ }
- while (service_list_ptr != NULL) {
- if (service_info->service_id == service_list_ptr->service_info->service_id) {
- break;
+ service_list_ptr = service_list_ptr->next;
}
- service_list_ptr = service_list_ptr->next;
- }
+ if (service_list_ptr == NULL) {
+ debugs(80, DBG_IMPORTANT, "WCCPv2 Unknown service received from router (" << service_info->service_id << ")");
+ return;
+ }
- if (service_list_ptr == NULL) {
- debugs(80, DBG_IMPORTANT, "WCCPv2 Unknown service received from router (" << service_info->service_id << ")");
- return;
- }
+ if (ntohl(security_info->security_option) != ntohl(service_list_ptr->security_info->security_option)) {
+ debugs(80, DBG_IMPORTANT, "Invalid security option in WCCPv2 Packet (" << ntohl(security_info->security_option) << " vs " << ntohl(service_list_ptr->security_info->security_option) << ").");
+ return;
+ }
- if (ntohl(security_info->security_option) != ntohl(service_list_ptr->security_info->security_option)) {
- debugs(80, DBG_IMPORTANT, "Invalid security option in WCCPv2 Packet (" << ntohl(security_info->security_option) << " vs " << ntohl(service_list_ptr->security_info->security_option) << ").");
- return;
- }
+ if (!wccp2_check_security(service_list_ptr, (char *) security_info, (char *) &wccp2_i_see_you, len)) {
+ debugs(80, DBG_IMPORTANT, "Received WCCPv2 Packet failed authentication");
+ return;
+ }
- if (!wccp2_check_security(service_list_ptr, (char *) security_info, (char *) &wccp2_i_see_you, len)) {
- debugs(80, DBG_IMPORTANT, "Received WCCPv2 Packet failed authentication");
- return;
- }
+ /* Check that the router address is configured on this router */
+ for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != NULL; router_list_ptr = router_list_ptr->next) {
+ if (router_list_ptr->router_sendto_address.s_addr == from.sin_addr.s_addr)
+ break;
+ }
- /* Check that the router address is configured on this router */
- for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != NULL; router_list_ptr = router_list_ptr->next) {
- if (router_list_ptr->router_sendto_address.s_addr == from.sin_addr.s_addr)
- break;
- }
+ Must3(router_list_ptr->next, "packet received from unknown router", Here());
- Must3(router_list_ptr->next, "packet received from unknown router", Here());
+ /* Set the router id */
+ router_list_ptr->info->router_address = router_identity_info->router_id_element.router_address;
- /* Set the router id */
- router_list_ptr->info->router_address = router_identity_info->router_id_element.router_address;
+ /* Increment the received id in the packet */
+ if (ntohl(router_list_ptr->info->received_id) != ntohl(router_identity_info->router_id_element.received_id)) {
+ debugs(80, 3, "Incoming WCCP2_I_SEE_YOU Received ID old=" << ntohl(router_list_ptr->info->received_id) << " new=" << ntohl(router_identity_info->router_id_element.received_id) << ".");
+ router_list_ptr->info->received_id = router_identity_info->router_id_element.received_id;
+ }
- /* Increment the received id in the packet */
- if (ntohl(router_list_ptr->info->received_id) != ntohl(router_identity_info->router_id_element.received_id)) {
- debugs(80, 3, "Incoming WCCP2_I_SEE_YOU Received ID old=" << ntohl(router_list_ptr->info->received_id) << " new=" << ntohl(router_identity_info->router_id_element.received_id) << ".");
- router_list_ptr->info->received_id = router_identity_info->router_id_element.received_id;
- }
+ /* TODO: check return/forwarding methods */
+ if (router_capability_header == NULL) {
+ if ((Config.Wccp2.return_method != WCCP2_PACKET_RETURN_METHOD_GRE) || (Config.Wccp2.forwarding_method != WCCP2_FORWARDING_METHOD_GRE)) {
+ debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router does not support the forwarding method specified, only GRE supported");
+ wccp2ConnectionClose();
+ return;
+ }
+ } else {
- /* TODO: check return/forwarding methods */
- if (router_capability_header == NULL) {
- if ((Config.Wccp2.return_method != WCCP2_PACKET_RETURN_METHOD_GRE) || (Config.Wccp2.forwarding_method != WCCP2_FORWARDING_METHOD_GRE)) {
- debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router does not support the forwarding method specified, only GRE supported");
- wccp2ConnectionClose();
- return;
- }
- } else {
+ const auto router_capability_data_length = ntohs(router_capability_header->capability_info_length);
+ assert(router_capability_data_start);
+ const auto router_capability_data_end = router_capability_data_start +
+ router_capability_data_length;
+ for (auto router_capability_data_current = router_capability_data_start;
+ router_capability_data_current < router_capability_data_end;) {
+
+ SetField(router_capability_element, router_capability_data_current,
+ router_capability_data_start, router_capability_data_length,
+ "capability element header truncated");
+ const auto elementSize = CheckFieldDataLength(
+ router_capability_element, ntohs(router_capability_element->capability_length),
+ router_capability_data_start, router_capability_data_length,
+ "capability element truncated");
+
+ switch (ntohs(router_capability_element->capability_type)) {
+
+ case WCCP2_CAPABILITY_FORWARDING_METHOD:
+
+ if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.forwarding_method)) {
+ debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router has specified a different forwarding method " << ntohl(router_capability_element->capability_value) << ", expected " << Config.Wccp2.forwarding_method);
+ wccp2ConnectionClose();
+ return;
+ }
- const auto router_capability_data_length = ntohs(router_capability_header->capability_info_length);
- assert(router_capability_data_start);
- const auto router_capability_data_end = router_capability_data_start +
- router_capability_data_length;
- for (auto router_capability_data_current = router_capability_data_start;
- router_capability_data_current < router_capability_data_end;) {
-
- SetField(router_capability_element, router_capability_data_current,
- router_capability_data_start, router_capability_data_length,
- "capability element header truncated");
- const auto elementSize = CheckFieldDataLength(
- router_capability_element, ntohs(router_capability_element->capability_length),
- router_capability_data_start, router_capability_data_length,
- "capability element truncated");
-
- switch (ntohs(router_capability_element->capability_type)) {
-
- case WCCP2_CAPABILITY_FORWARDING_METHOD:
-
- if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.forwarding_method)) {
- debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router has specified a different forwarding method " << ntohl(router_capability_element->capability_value) << ", expected " << Config.Wccp2.forwarding_method);
- wccp2ConnectionClose();
- return;
- }
+ break;
- break;
+ case WCCP2_CAPABILITY_ASSIGNMENT_METHOD:
- case WCCP2_CAPABILITY_ASSIGNMENT_METHOD:
+ if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.assignment_method)) {
+ debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router has specified a different assignment method " << ntohl(router_capability_element->capability_value) << ", expected "<< Config.Wccp2.assignment_method);
+ wccp2ConnectionClose();
+ return;
+ }
- if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.assignment_method)) {
- debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router has specified a different assignment method " << ntohl(router_capability_element->capability_value) << ", expected "<< Config.Wccp2.assignment_method);
- wccp2ConnectionClose();
- return;
- }
+ break;
- break;
+ case WCCP2_CAPABILITY_RETURN_METHOD:
- case WCCP2_CAPABILITY_RETURN_METHOD:
+ if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.return_method)) {
+ debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router has specified a different return method " << ntohl(router_capability_element->capability_value) << ", expected " << Config.Wccp2.return_method);
+ wccp2ConnectionClose();
+ return;
+ }
- if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.return_method)) {
- debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router has specified a different return method " << ntohl(router_capability_element->capability_value) << ", expected " << Config.Wccp2.return_method);
- wccp2ConnectionClose();
- return;
- }
+ break;
- break;
+ case 4:
+ case 5:
+ break; // ignore silently for now
- case 4:
- case 5:
- break; // ignore silently for now
+ default:
+ debugs(80, DBG_IMPORTANT, "Unknown capability type in WCCPv2 Packet (" << ntohs(router_capability_element->capability_type) << ").");
+ }
- default:
- debugs(80, DBG_IMPORTANT, "Unknown capability type in WCCPv2 Packet (" << ntohs(router_capability_element->capability_type) << ").");
+ router_capability_data_current += elementSize;
}
-
- router_capability_data_current += elementSize;
}
- }
- debugs(80, 5, "Cleaning out cache list");
- /* clean out the old cache list */
+ debugs(80, 5, "Cleaning out cache list");
+ /* clean out the old cache list */
- for (cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr; cache_list_ptr = cache_list_ptr_next) {
- cache_list_ptr_next = cache_list_ptr->next;
+ for (cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr; cache_list_ptr = cache_list_ptr_next) {
+ cache_list_ptr_next = cache_list_ptr->next;
- if (cache_list_ptr != &router_list_ptr->cache_list_head) {
- xfree(cache_list_ptr);
+ if (cache_list_ptr != &router_list_ptr->cache_list_head) {
+ xfree(cache_list_ptr);
+ }
}
- }
- router_list_ptr->num_caches = htonl(0);
- num_caches = 0;
+ router_list_ptr->num_caches = htonl(0);
+ num_caches = 0;
- /* Check to see if we're the master cache and update the cache list */
- bool found = false;
- service_list_ptr->lowest_ip = 1;
- cache_list_ptr = &router_list_ptr->cache_list_head;
+ /* Check to see if we're the master cache and update the cache list */
+ bool found = false;
+ service_list_ptr->lowest_ip = 1;
+ cache_list_ptr = &router_list_ptr->cache_list_head;
- /* to find the list of caches, we start at the end of the router view header */
+ /* to find the list of caches, we start at the end of the router view header */
- ptr = (char *) (router_view_header) + sizeof(struct router_view_t);
- const auto router_view_size = sizeof(struct router_view_t) +
- ntohs(router_view_header->header.length);
+ ptr = (char *) (router_view_header) + sizeof(struct router_view_t);
+ const auto router_view_size = sizeof(struct router_view_t) +
+ ntohs(router_view_header->header.length);
- /* Then we read the number of routers */
- const uint32_t *routerCountRaw = nullptr;
- SetField(routerCountRaw, ptr, router_view_header, router_view_size,
- "malformed packet (truncated router view info w/o number of routers)");
+ /* Then we read the number of routers */
+ const uint32_t *routerCountRaw = nullptr;
+ SetField(routerCountRaw, ptr, router_view_header, router_view_size,
+ "malformed packet (truncated router view info w/o number of routers)");
- /* skip the number plus all the ip's */
- ptr += sizeof(*routerCountRaw);
- const auto ipCount = ntohl(*routerCountRaw);
- const auto ipsSize = ipCount * sizeof(struct in_addr); // we check for unsigned overflow below
- Must3(ipsSize / sizeof(struct in_addr) != ipCount, "huge IP address count", Here());
- CheckSectionLength(ptr, ipsSize, router_view_header, router_view_size, "invalid IP address count");
- ptr += ipsSize;
+ /* skip the number plus all the ip's */
+ ptr += sizeof(*routerCountRaw);
+ const auto ipCount = ntohl(*routerCountRaw);
+ const auto ipsSize = ipCount * sizeof(struct in_addr); // we check for unsigned overflow below
+ Must3(ipsSize / sizeof(struct in_addr) != ipCount, "huge IP address count", Here());
+ CheckSectionLength(ptr, ipsSize, router_view_header, router_view_size, "invalid IP address count");
+ ptr += ipsSize;
- /* Then read the number of caches */
- const uint32_t *cacheCountRaw = nullptr;
- SetField(cacheCountRaw, ptr, router_view_header, router_view_size,
- "malformed packet (truncated router view info w/o cache count)");
- memcpy(&tmp, cacheCountRaw, sizeof(tmp)); // TODO: Replace tmp with cacheCount
- ptr += sizeof(tmp);
+ /* Then read the number of caches */
+ const uint32_t *cacheCountRaw = nullptr;
+ SetField(cacheCountRaw, ptr, router_view_header, router_view_size,
+ "malformed packet (truncated router view info w/o cache count)");
+ memcpy(&tmp, cacheCountRaw, sizeof(tmp)); // TODO: Replace tmp with cacheCount
+ ptr += sizeof(tmp);
- if (ntohl(tmp) != 0) {
- /* search through the list of received-from ip addresses */
+ if (ntohl(tmp) != 0) {
+ /* search through the list of received-from ip addresses */
- for (num_caches = 0; num_caches < (int) ntohl(tmp); ++num_caches) {
- /* Get a copy of the ip */
- memset(&cache_address, 0, sizeof(cache_address)); // Make GCC happy
+ for (num_caches = 0; num_caches < (int) ntohl(tmp); ++num_caches) {
+ /* Get a copy of the ip */
+ memset(&cache_address, 0, sizeof(cache_address)); // Make GCC happy
- switch (Config.Wccp2.assignment_method) {
+ switch (Config.Wccp2.assignment_method) {
- case WCCP2_ASSIGNMENT_METHOD_HASH:
+ case WCCP2_ASSIGNMENT_METHOD_HASH:
- SetField(cache_identity, ptr, router_view_header, router_view_size,
- "malformed packet (truncated router view info cache w/o assignment hash)");
+ SetField(cache_identity, ptr, router_view_header, router_view_size,
+ "malformed packet (truncated router view info cache w/o assignment hash)");
- ptr += sizeof(struct wccp2_cache_identity_info_t);
+ ptr += sizeof(struct wccp2_cache_identity_info_t);
- memcpy(&cache_address, &cache_identity->addr, sizeof(struct in_addr));
+ memcpy(&cache_address, &cache_identity->addr, sizeof(struct in_addr));
- cache_list_ptr->weight = ntohs(cache_identity->weight);
- break;
+ cache_list_ptr->weight = ntohs(cache_identity->weight);
+ break;
- case WCCP2_ASSIGNMENT_METHOD_MASK:
+ case WCCP2_ASSIGNMENT_METHOD_MASK:
- SetField(cache_mask_info, ptr, router_view_header, router_view_size,
- "malformed packet (truncated router view info cache w/o assignment mask)");
+ SetField(cache_mask_info, ptr, router_view_header, router_view_size,
+ "malformed packet (truncated router view info cache w/o assignment mask)");
- /* The mask assignment has an undocumented variable length entry here */
+ /* The mask assignment has an undocumented variable length entry here */
- if (ntohl(cache_mask_info->num1) == 3) {
+ if (ntohl(cache_mask_info->num1) == 3) {
- SetField(cache_mask_identity, ptr, router_view_header, router_view_size,
- "malformed packet (truncated router view info cache w/o assignment mask identity)");
+ SetField(cache_mask_identity, ptr, router_view_header, router_view_size,
+ "malformed packet (truncated router view info cache w/o assignment mask identity)");
- ptr += sizeof(struct wccp2_cache_mask_identity_info_t);
+ ptr += sizeof(struct wccp2_cache_mask_identity_info_t);
- memcpy(&cache_address, &cache_mask_identity->addr, sizeof(struct in_addr));
- } else {
+ memcpy(&cache_address, &cache_mask_identity->addr, sizeof(struct in_addr));
+ } else {
- ptr += sizeof(struct cache_mask_info_t);
+ ptr += sizeof(struct cache_mask_info_t);
- memcpy(&cache_address, &cache_mask_info->addr, sizeof(struct in_addr));
- }
+ memcpy(&cache_address, &cache_mask_info->addr, sizeof(struct in_addr));
+ }
- cache_list_ptr->weight = 0;
- break;
+ cache_list_ptr->weight = 0;
+ break;
- default:
- fatalf("Unknown Wccp2 assignment method\n");
- }
+ default:
+ fatalf("Unknown Wccp2 assignment method\n");
+ }
- /* Update the cache list */
- cache_list_ptr->cache_ip = cache_address;
+ /* Update the cache list */
+ cache_list_ptr->cache_ip = cache_address;
- cache_list_ptr->next = (wccp2_cache_list_t*) xcalloc(1, sizeof(struct wccp2_cache_list_t));
+ cache_list_ptr->next = (wccp2_cache_list_t*) xcalloc(1, sizeof(struct wccp2_cache_list_t));
- cache_list_ptr = cache_list_ptr->next;
+ cache_list_ptr = cache_list_ptr->next;
- cache_list_ptr->next = NULL;
+ cache_list_ptr->next = NULL;
- debugs (80, 5, "checking cache list: (" << std::hex << cache_address.s_addr << ":" << router_list_ptr->local_ip.s_addr << ")");
+ debugs (80, 5, "checking cache list: (" << std::hex << cache_address.s_addr << ":" << router_list_ptr->local_ip.s_addr << ")");
- /* Check to see if it's the master, or us */
- found = found || (cache_address.s_addr == router_list_ptr->local_ip.s_addr);
+ /* Check to see if it's the master, or us */
+ found = found || (cache_address.s_addr == router_list_ptr->local_ip.s_addr);
- if (cache_address.s_addr < router_list_ptr->local_ip.s_addr) {
- service_list_ptr->lowest_ip = 0;
+ if (cache_address.s_addr < router_list_ptr->local_ip.s_addr) {
+ service_list_ptr->lowest_ip = 0;
+ }
}
- }
- } else {
- debugs(80, 5, "Adding ourselves as the only cache");
+ } else {
+ debugs(80, 5, "Adding ourselves as the only cache");
- /* Update the cache list */
- cache_list_ptr->cache_ip = router_list_ptr->local_ip;
+ /* Update the cache list */
+ cache_list_ptr->cache_ip = router_list_ptr->local_ip;
- cache_list_ptr->next = (wccp2_cache_list_t*) xcalloc(1, sizeof(struct wccp2_cache_list_t));
- cache_list_ptr = cache_list_ptr->next;
- cache_list_ptr->next = NULL;
+ cache_list_ptr->next = (wccp2_cache_list_t*) xcalloc(1, sizeof(struct wccp2_cache_list_t));
+ cache_list_ptr = cache_list_ptr->next;
+ cache_list_ptr->next = NULL;
- service_list_ptr->lowest_ip = 1;
- found = true;
- num_caches = 1;
- }
+ service_list_ptr->lowest_ip = 1;
+ found = true;
+ num_caches = 1;
+ }
- wccp2SortCacheList(&router_list_ptr->cache_list_head);
+ wccp2SortCacheList(&router_list_ptr->cache_list_head);
- router_list_ptr->num_caches = htonl(num_caches);
+ router_list_ptr->num_caches = htonl(num_caches);
- if (found && (service_list_ptr->lowest_ip == 1)) {
- if (ntohl(router_view_header->change_number) != router_list_ptr->member_change) {
- debugs(80, 4, "Change detected - queueing up new assignment");
- router_list_ptr->member_change = ntohl(router_view_header->change_number);
- eventDelete(wccp2AssignBuckets, NULL);
- eventAdd("wccp2AssignBuckets", wccp2AssignBuckets, NULL, 15.0, 1);
+ if (found && (service_list_ptr->lowest_ip == 1)) {
+ if (ntohl(router_view_header->change_number) != router_list_ptr->member_change) {
+ debugs(80, 4, "Change detected - queueing up new assignment");
+ router_list_ptr->member_change = ntohl(router_view_header->change_number);
+ eventDelete(wccp2AssignBuckets, NULL);
+ eventAdd("wccp2AssignBuckets", wccp2AssignBuckets, NULL, 15.0, 1);
+ } else {
+ debugs(80, 5, "Change not detected (" << ntohl(router_view_header->change_number) << " = " << router_list_ptr->member_change << ")");
+ }
} else {
- debugs(80, 5, "Change not detected (" << ntohl(router_view_header->change_number) << " = " << router_list_ptr->member_change << ")");
+ eventDelete(wccp2AssignBuckets, NULL);
+ debugs(80, 5, "I am not the lowest ip cache - not assigning buckets");
}
- } else {
- eventDelete(wccp2AssignBuckets, NULL);
- debugs(80, 5, "I am not the lowest ip cache - not assigning buckets");
- }
} catch (...) {
debugs(80, DBG_IMPORTANT, "ERROR: Ignoring WCCPv2 message: " << CurrentException);