wccp2.cc
Go to the documentation of this file.
184 char buckets[32]; /* Draft indicates 8x 32-bit buckets but it's just a mask so doesn't matter how we define. */
511 wccp2_service_list_ptr = (wccp2_service_list_t *) xcalloc(1, sizeof(struct wccp2_service_list_t));
588 static_assert(sizeof(pwd) - 1 == 8, "WCCP2 password has exactly 8 (padded) octets, excluding storage-terminating NUL");
618 debugs(80, DBG_IMPORTANT, "wccp2_check_security: received packet has the wrong security option");
644 static_assert(sizeof(pwd) - 1 == 8, "WCCP2 password has exactly 8 (padded) octets, excluding storage-terminating NUL");
756 memset(&wccp2_identity_info.cache_identity.hash_revision, '\0', sizeof(wccp2_identity_info.cache_identity.hash_revision));
757 memset(&wccp2_identity_info.cache_identity.bits, '\0', sizeof(wccp2_identity_info.cache_identity.bits));
758 memset(&wccp2_identity_info.cache_identity.buckets, '\0', sizeof(wccp2_identity_info.cache_identity.buckets));
760 memset(&wccp2_identity_info.cache_identity.status, '\0', sizeof(wccp2_identity_info.cache_identity.status));
773 wccp2_mask_identity_info.cache_identity_length = htons(sizeof(wccp2_mask_identity_info.cache_identity));
781 if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
783 } else if ((service_list_ptr->info.service == WCCP2_SERVICE_STANDARD) || (service_flags & WCCP2_SERVICE_DST_IP_HASH) || (service_flags & WCCP2_SERVICE_DST_IP_ALT_HASH)) {
785 } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
787 } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
833 /* Add each router. Keep this functionality here to make sure the received_id can be updated in the packet */
880 wccp2_capability_info_header.capability_info_length = htons(3 * sizeof(wccp2_capability_element));
893 wccp2_capability_element.capability_length = htons(sizeof(wccp2_capability_element.capability_value));
908 wccp2_capability_element.capability_length = htons(sizeof(wccp2_capability_element.capability_value));
923 wccp2_capability_element.capability_length = htons(sizeof(wccp2_capability_element.capability_value));
934 memcpy(&service_list_ptr->wccp_packet, &wccp2_here_i_am_header, sizeof(wccp2_here_i_am_header));
936 service_list_ptr->wccp_packet_size = ntohs(wccp2_here_i_am_header.length) + sizeof(wccp2_here_i_am_header);
969 debugs(80, DBG_CRITICAL, "WCCPv2 Disabled. Local address " << Config.Wccp2.address << " is not an IPv4 address.");
988 debugs(80, 2, "WARNING: Path MTU discovery could not be disabled on FD " << theWccp2Connection << ": " << xstrerr(xerrno));
995 debugs(80, DBG_IMPORTANT, "Accepting WCCPv2 messages on port " << WCCP_PORT << ", FD " << theWccp2Connection << ".");
1006 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1074 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr != nullptr; router_list_ptr = router_list_next) {
1075 for (cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr; cache_list_ptr = cache_list_ptr_next) {
1115CheckSectionLength(const void *sectionStart, const size_t sectionLength, const void *wholeStart, const size_t wholeSize, const char *error)
1122 assert(sectionStart <= wholeEnd && "we never go beyond our whole (but zero-sized fields are OK)");
1123 static_assert(sizeof(wccp2_i_see_you_t) <= PTRDIFF_MAX, "paranoid: no UB when subtracting in-whole pointers");
1142CheckFieldDataLength(const FieldHeader *header, const size_t dataLength, const void *areaStart, const size_t areaSize, const char *error)
1159SetField(Field *&field, const void *fieldStart, const void *areaStart, const size_t areaSize, const char *error)
1215 const auto lenOrError = comm_udp_recvfrom(sock, &wccp2_i_see_you, WCCP_RESPONSE_SIZE, 0, from_tmp);
1282 CheckFieldDataLength(router_capability_header, ntohs(router_capability_header->capability_info_length),
1296 debugs(80, DBG_IMPORTANT, "ERROR: Unknown record type in WCCPv2 Packet (" << ntohs(itemHeader->type) << ").");
1322 debugs(80, DBG_IMPORTANT, "ERROR: WCCPv2 Unknown service received from router (" << service_info->service_id << ")");
1326 if (ntohl(security_info->security_option) != ntohl(service_list_ptr->security_info->security_option)) {
1327 debugs(80, DBG_IMPORTANT, "ERROR: Invalid security option in WCCPv2 Packet (" << ntohl(security_info->security_option) << " vs " << ntohl(service_list_ptr->security_info->security_option) << ").");
1331 if (!wccp2_check_security(service_list_ptr, (char *) security_info, (char *) &wccp2_i_see_you, len)) {
1337 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1345 router_list_ptr->info->router_address = router_identity_info->router_id_element.router_address;
1348 if (ntohl(router_list_ptr->info->received_id) != ntohl(router_identity_info->router_id_element.received_id)) {
1349 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) << ".");
1355 if ((Config.Wccp2.return_method != WCCP2_PACKET_RETURN_METHOD_GRE) || (Config.Wccp2.forwarding_method != WCCP2_FORWARDING_METHOD_GRE)) {
1356 debugs(80, DBG_IMPORTANT, "ERROR: wccp2HandleUdp: fatal error - A WCCP router does not support the forwarding method specified, only GRE supported");
1362 const auto router_capability_data_length = ntohs(router_capability_header->capability_info_length);
1382 debugs(80, DBG_IMPORTANT, "ERROR: wccp2HandleUdp: fatal error - A WCCP router has specified a different forwarding method " << ntohl(router_capability_element->capability_value) << ", expected " << Config.Wccp2.forwarding_method);
1392 debugs(80, DBG_IMPORTANT, "ERROR: wccp2HandleUdp: fatal error - A WCCP router has specified a different assignment method " << ntohl(router_capability_element->capability_value) << ", expected "<< Config.Wccp2.assignment_method);
1402 debugs(80, DBG_IMPORTANT, "ERROR: wccp2HandleUdp: fatal error - A WCCP router has specified a different return method " << ntohl(router_capability_element->capability_value) << ", expected " << Config.Wccp2.return_method);
1414 debugs(80, DBG_IMPORTANT, "ERROR: Unknown capability type in WCCPv2 Packet (" << ntohs(router_capability_element->capability_type) << ").");
1424 for (cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr; cache_list_ptr = cache_list_ptr_next) {
1456 CheckSectionLength(ptr, ipsSize, router_view_header, router_view_size, "invalid IP address count");
1525 debugs (80, 5, "checking cache list: (" << std::hex << cache_address.s_addr << ":" << router_list_ptr->local_ip.s_addr << ")");
1560 debugs(80, 5, "Change not detected (" << ntohl(router_view_header->change_number) << " = " << router_list_ptr->member_change << ")");
1606 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1615 wccp2_identity_info_ptr = (struct wccp2_identity_info_t *) service_list_ptr->wccp2_identity_info_ptr;
1621 wccp2_mask_identity_info_ptr = (struct wccp2_mask_identity_info_t *) service_list_ptr->wccp2_identity_info_ptr;
1632 wccp2_update_md5_security(service_list_ptr->wccp_password, (char *) service_list_ptr->security_info, service_list_ptr->wccp_packet, service_list_ptr->wccp_packet_size);
1644 if (send(theWccp2Connection, &service_list_ptr->wccp_packet, service_list_ptr->wccp_packet_size, 0) < static_cast<int>(service_list_ptr->wccp_packet_size)) {
1646 debugs(80, 2, "ERROR: failed to send WCCPv2 HERE_I_AM packet to " << router << " : " << xstrerr(xerrno));
1757 memcpy(&wccp_packet[offset], service_list_ptr->service_info, sizeof(struct wccp2_service_info_t));
1804 memcpy(&wccp_packet[offset], &service_list_ptr->num_routers, sizeof(service_list_ptr->num_routers));
1808 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1822 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1823 unsigned long *weight = (unsigned long *)xcalloc(sizeof(*weight), ntohl(router_list_ptr->num_caches));
1833 memcpy(&wccp_packet[offset], &router_list_ptr->num_caches, sizeof(router_list_ptr->num_caches));
1839 for (cache = 0, cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr->next; cache_list_ptr = cache_list_ptr->next, ++cache) {
1909 if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
1914 } else if ((service_list_ptr->info.service == WCCP2_SERVICE_STANDARD) || (service_flags & WCCP2_SERVICE_DST_IP_HASH) || (service_flags & WCCP2_SERVICE_DST_IP_ALT_HASH)) {
1919 } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
1924 } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
1950 if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
1955 } else if ((service_list_ptr->info.service == WCCP2_SERVICE_STANDARD) || (service_flags & WCCP2_SERVICE_DST_IP_HASH) || (service_flags & WCCP2_SERVICE_DST_IP_ALT_HASH)) {
1960 } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
1965 } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
2013 wccp2_update_md5_security(service_list_ptr->wccp_password, (char *) security, wccp_packet, offset);
2030 debugs(80, 2, "ERROR: failed to send WCCPv2 HERE_I_AM packet to " << tmp_rtr << " : " << xstrerr(xerrno));
2132 debugs(80, DBG_CRITICAL, "FATAL: WCCPv2 configured " << label << " (" << v << ") is not valid.");
2156 debugs(80, DBG_IMPORTANT, "WCCPv2: Somehow reparsing the configuration without having shut down WCCP! Try reloading squid again.");
2162 debugs(80, DBG_CRITICAL, "ERROR: wccp2ParseServiceInfo: missing service info type (standard|dynamic)");
2172 debugs(80, DBG_CRITICAL, "ERROR: wccp2ParseServiceInfo: bad service info type (expected standard|dynamic, got " << t << ")");
2181 debugs(80, DBG_CRITICAL, "ERROR: invalid WCCP service id " << service_id << " (must be between 0 .. 255)");
2197 wccp2_add_service_list(service, service_id, 0, 0, 0, empty_portlist, security_type, wccp_password);
2207 debugs(80, 3, "dump_wccp2_service: id " << srv->info.service_id << ", type " << srv->info.service);
2339 debugs(80, DBG_IMPORTANT, "WCCPv2: Somehow reparsing the configuration without having shut down WCCP! Try reloading squid again.");
2349 debugs(80, DBG_CRITICAL, "ERROR: invalid WCCP service id " << service_id << " (must be between 0 .. 255)");
2358 fatalf("parse_wccp2_service_info: unknown dynamic service id %d: you need to define it using wccp2_service (and make sure you wish to configure it as a dynamic service.)\n", service_id);
2374 fatalf("parse_wccp2_service_info: id %d: unknown protocol (%s) - must be tcp or udp!\n", service_id, t);
2388 fatalf("parse_wccp2_service_info: service %d: no priority defined (valid: 0..255)!\n", service_id);
2392 fatalf("parse_wccp2_service_info: service %d: no protocol defined (valid: tcp or udp)!\n", service_id);
2414 debugs(80, 3, "dump_wccp2_service_info: id " << srv->info.service_id << " (type " << srv->info.service << ")");
2419 debugs(80, 3, "dump_wccp2_service_info: id " << srv->info.service_id << ": standard service, not dumping info");
2533 storeAppendPrintf(e, " protocol=%s", (srv->info.service_protocol == IPPROTO_TCP) ? "tcp" : "udp");
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
Definition: TextException.cc:88
void error(char *format,...)
Definition: Address.h:364
Definition: Address.h:41
void getSockAddr(struct sockaddr_storage &addr, const int family) const
Definition: Address.cc:924
struct SquidConfig::@97 Wccp2
Definition: Store.h:42
static int store_dirs_rebuilding
the number of cache_dirs being rebuilt; TODO: move to Disks::Rebuilding
Definition: Controller.h:134
int comm_udp_sendto(int fd, const Ip::Address &to_addr, const void *buf, int len)
Definition: comm.cc:918
void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note)
Definition: comm.cc:256
int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags, Ip::Address &from)
Definition: comm.cc:125
void eventAdd(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata)
Definition: event.cc:107
SQUIDCEXTERN void SquidMD5Update(struct SquidMD5Context *context, const void *buf, unsigned len)
Definition: md5.c:89
SQUIDCEXTERN void SquidMD5Final(uint8_t digest[16], struct SquidMD5Context *context)
void SetSelect(int, unsigned int, PF *, void *, time_t)
Mark an FD to be watched for its IO status.
Definition: ModDevPoll.cc:223
Definition: md5.h:55
Definition: wccp2.cc:391
Definition: wccp2.cc:381
Definition: wccp2.cc:364
struct wccp2_router_id_element_t router_id_element
Definition: wccp2.cc:368
Definition: wccp2.cc:399
Definition: wccp2.cc:177
Definition: wccp2.cc:409
Definition: wccp2.cc:215
uint32_t mask_element_count
Definition: wccp2.cc:226
Definition: wccp2.cc:255
Definition: wccp2.cc:265
Definition: wccp2.cc:297
Definition: wccp2.cc:286
uint16_t capability_info_length
Definition: wccp2.cc:288
uint16_t capability_info_type
Definition: wccp2.cc:287
Definition: wccp2.cc:341
Definition: wccp2.cc:192
struct wccp2_cache_identity_info_t cache_identity
Definition: wccp2.cc:196
Definition: wccp2.cc:61
Definition: wccp2.cc:204
Definition: wccp2.cc:240
struct wccp2_cache_mask_identity_info_t cache_identity
Definition: wccp2.cc:244
uint16_t cache_identity_length
Definition: wccp2.cc:242
Definition: wccp2.cc:83
Definition: wccp2.cc:353
Definition: wccp2.cc:275
Definition: wccp2.cc:419
struct wccp2_cache_list_t cache_list_head
Definition: wccp2.cc:429
struct in_addr router_sendto_address
Definition: wccp2.cc:425
Definition: wccp2.cc:119
uint8_t security_implementation[WCCP2_MD5_SECURITY_LEN]
Definition: wccp2.cc:123
Definition: wccp2.cc:103
Definition: wccp2.cc:131
Definition: wccp2.cc:437
struct wccp2_router_list_t router_list_head
Definition: wccp2.cc:442
struct wccp2_service_info_t * service_info
Definition: wccp2.cc:450
struct wccp2_security_md5_t * security_info
Definition: wccp2.cc:448
Definition: wccp2.cc:327
static struct wccp2_cache_view_header_t wccp2_cache_view_header
Definition: wccp2.cc:261
static char wccp2_update_md5_security(char *password, char *ptr, char *packet, int len)
Definition: wccp2.cc:554
static struct wccp2_message_header_t wccp2_here_i_am_header
Definition: wccp2.cc:90
static struct wccp2_capability_element_t wccp2_capability_element
Definition: wccp2.cc:302
static void wccp2SortCacheList(struct wccp2_cache_list_t *head)
Definition: wccp2.cc:2543
static struct wccp2_capability_info_header_t wccp2_capability_info_header
Definition: wccp2.cc:292
void dump_wccp2_amethod(StoreEntry *e, const char *label, int v)
Definition: wccp2.cc:2122
#define WCCP2_CAPABILITY_FORWARDING_METHOD
Definition: wccp2.cc:305
void dump_wccp2_method(StoreEntry *e, const char *label, int v)
Definition: wccp2.cc:2074
static void parse_wccp2_service_ports(char *options, int portlist[])
Definition: wccp2.cc:2292
#define WCCP2_CAPABILITY_ASSIGNMENT_METHOD
Definition: wccp2.cc:306
static size_t CheckFieldDataLength(const FieldHeader *header, const size_t dataLength, const void *areaStart, const size_t areaSize, const char *error)
Definition: wccp2.cc:1142
static void wccp2_update_service(struct wccp2_service_list_t *srv, int service, int service_id, int service_priority, int service_proto, int service_flags, int ports[])
Definition: wccp2.cc:483
void dump_wccp2_service_info(StoreEntry *e, const char *label, void *)
Definition: wccp2.cc:2407
static struct wccp2_service_list_t * wccp2_get_service_by_id(int service, int service_id)
Definition: wccp2.cc:531
static struct wccp2_service_list_t * wccp2_service_list_head
Definition: wccp2.cc:459
static struct wccp2_mask_identity_info_t wccp2_mask_identity_info
Definition: wccp2.cc:247
static void wccp2_add_service_list(int service, int service_id, int service_priority, int service_proto, int service_flags, int ports[], int security_type, char *password)
Definition: wccp2.cc:504
static void CheckSectionLength(const void *sectionStart, const size_t sectionLength, const void *wholeStart, const size_t wholeSize, const char *error)
Definition: wccp2.cc:1115
static struct wccp2_cache_view_info_t wccp2_cache_view_info
Definition: wccp2.cc:270
static char wccp2_check_security(struct wccp2_service_list_t *srv, char *security, char *packet, int len)
Definition: wccp2.cc:607
void dump_wccp2_service(StoreEntry *e, const char *label, void *)
Definition: wccp2.cc:2201
static void SetField(Field *&field, const void *fieldStart, const void *areaStart, const size_t areaSize, const char *error)
Definition: wccp2.cc:1159