Squid Web Cache master
Loading...
Searching...
No Matches
wccp2.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 80 WCCP Support */
10
11#include "squid.h"
12
13#if USE_WCCPv2
15#include "cache_cf.h"
16#include "comm.h"
17#include "comm/Connection.h"
18#include "comm/Loops.h"
19#include "compat/socket.h"
20#include "ConfigParser.h"
21#include "event.h"
22#include "ip/Address.h"
23#include "md5.h"
24#include "Parsing.h"
25#include "SquidConfig.h"
26#include "Store.h"
27#include "tools.h"
28#include "wccp2.h"
29
30#define WCCP_PORT 2048
31#define WCCP_RESPONSE_SIZE 12448
32#define WCCP_BUCKETS 256
33
34static int theWccp2Connection = -1;
35static int wccp2_connected = 0;
36
40
41/* KDW WCCP V2 */
42
43#define WCCP2_HASH_ASSIGNMENT 0x00
44#define WCCP2_MASK_ASSIGNMENT 0x01
45
46#define WCCP2_NONE_SECURITY_LEN 0
47#define WCCP2_MD5_SECURITY_LEN SQUID_MD5_DIGEST_LENGTH // 16
48
49/* Useful defines */
50#define WCCP2_NUMPORTS 8
51#define WCCP2_PASSWORD_LEN 8 + 1 /* + 1 for C-string NUL terminator */
52
53/* WCCPv2 Packet format structures */
54/* Defined in draft-wilson-wccp-v2-12-oct-2001.txt */
55
60 uint16_t type;
61 uint16_t length;
62};
63
64/* item type values */
65#define WCCP2_SECURITY_INFO 0
66#define WCCP2_SERVICE_INFO 1
67#define WCCP2_ROUTER_ID_INFO 2
68#define WCCP2_WC_ID_INFO 3
69#define WCCP2_RTR_VIEW_INFO 4
70#define WCCP2_WC_VIEW_INFO 5
71#define WCCP2_REDIRECT_ASSIGNMENT 6
72#define WCCP2_QUERY_INFO 7
73#define WCCP2_CAPABILITY_INFO 8
74#define WCCP2_ALT_ASSIGNMENT 13
75#define WCCP2_ASSIGN_MAP 14
76#define WCCP2_COMMAND_EXTENSION 15
77
82 uint32_t type;
83 uint16_t version;
84#define WCCP2_VERSION 0x200
85
86 uint16_t length;
87};
89
90/* message types */
91#define WCCP2_HERE_I_AM 10
92#define WCCP2_I_SEE_YOU 11
93#define WCCP2_REDIRECT_ASSIGN 12
94#define WCCP2_REMOVAL_QUERY 13
95
106
107/* security options */
108#define WCCP2_NO_SECURITY 0
109#define WCCP2_MD5_SECURITY 1
110
123
124/* Service info struct */
125
130 uint16_t service_type;
132 uint8_t service;
133 uint8_t service_id;
137 uint16_t port0;
138 uint16_t port1;
139 uint16_t port2;
140 uint16_t port3;
141 uint16_t port4;
142 uint16_t port5;
143 uint16_t port6;
144 uint16_t port7;
145};
146/* services */
147#define WCCP2_SERVICE_STANDARD 0
148#define WCCP2_SERVICE_DYNAMIC 1
149
150/* service IDs */
151#define WCCP2_SERVICE_ID_HTTP 0x00
152
153/* service flags */
154#define WCCP2_SERVICE_SRC_IP_HASH 0x1
155#define WCCP2_SERVICE_DST_IP_HASH 0x2
156#define WCCP2_SERVICE_SRC_PORT_HASH 0x4
157#define WCCP2_SERVICE_DST_PORT_HASH 0x8
158#define WCCP2_SERVICE_PORTS_DEFINED 0x10
159#define WCCP2_SERVICE_PORTS_SOURCE 0x20
160#define WCCP2_SERVICE_SRC_IP_ALT_HASH 0x100
161#define WCCP2_SERVICE_DST_IP_ALT_HASH 0x200
162#define WCCP2_SERVICE_SRC_PORT_ALT_HASH 0x400
163#define WCCP2_SERVICE_DST_PORT_ALT_HASH 0x800
164
165/* TODO the following structures need to be re-defined for correct full operation.
166 wccp2_cache_identity_element needs to be merged as a sub-struct of
167 wccp2_identity_info_t (identity_type); which frees up the identifty info
168 structures so mask_assigment_data_element can become variable length
169 and cope with multiple fail-over caches hanging off one router.
170 */
171
176 struct in_addr addr;
178 uint16_t bits;
179//#define WCCP2_HASH_ASSIGNMENT_DATA 0x0
180
181 /* 5.7.2 Hash Assignment Data Element */
182 char buckets[32]; /* Draft indicates 8x 32-bit buckets but it's just a mask so doesn't matter how we define. */
183 uint16_t weight;
184 uint16_t status;
185};
186
196
198
209
214 struct in_addr addr;
216 uint16_t bits;
217#define WCCP2_MASK_ASSIGNMENT_DATA (0x2)
218
219 /* Sect 5.7.2 Mask Assignment Data Element
220 *
221 * NP: draft specifies a variable-length set of keys here.
222 * the following fields only matche the special case Squid sends outbound (single-cache).
223 */
225
226 /* Sect 5.7.6 Mask/Value Set Element */
227 /* special case: single mask element. no values. */
229
230 /* Sect 5.7.2 Mask Assignment Data Element */
231 uint16_t weight;
232 uint16_t status;
233};
234
244
246
258
260
262/* NP: special-case 5.6.5 or 5.6.6 * View Info when no routers or caches are advertised? */
264 uint32_t num_routers;
265 uint32_t num_caches;
266};
267
269
274 struct in_addr router_address;
275 uint32_t received_id;
276};
277
278// unused (for now)
279// static struct wccp2_router_id_element_t wccp2_router_id_element;
280
287 /* dynamic length capabilities list */
288};
289
291
301
302/* capability types */
303#define WCCP2_CAPABILITY_FORWARDING_METHOD 0x01
304#define WCCP2_CAPABILITY_ASSIGNMENT_METHOD 0x02
305#define WCCP2_CAPABILITY_RETURN_METHOD 0x03
306// 0x04 ?? - advertised by a 4507 (ios v15.1) Cisco switch
307// 0x05 ?? - advertised by a 4507 (ios v15.1) Cisco switch
308
309/* capability values */
310#define WCCP2_METHOD_GRE 0x00000001
311#define WCCP2_METHOD_L2 0x00000002
312/* when type=WCCP2_CAPABILITY_FORWARDING_METHOD */
313#define WCCP2_FORWARDING_METHOD_GRE WCCP2_METHOD_GRE
314#define WCCP2_FORWARDING_METHOD_L2 WCCP2_METHOD_L2
315/* when type=WCCP2_CAPABILITY_ASSIGNMENT_METHOD */
316#define WCCP2_ASSIGNMENT_METHOD_HASH 0x00000001
317#define WCCP2_ASSIGNMENT_METHOD_MASK 0x00000002
318/* when type=WCCP2_CAPABILITY_RETURN_METHOD */
319#define WCCP2_PACKET_RETURN_METHOD_GRE WCCP2_METHOD_GRE
320#define WCCP2_PACKET_RETURN_METHOD_L2 WCCP2_METHOD_L2
321
330
331 struct in_addr cache_ip;
332};
333
334/* RECEIVED PACKET STRUCTURE */
335
340 uint32_t type;
341 uint16_t version;
342 uint16_t length;
344};
345
347
356
357/* Router identity struct */
358
363
365
367
368 struct in_addr router_address;
370 /* dynamic list of cache IP addresses */
371};
372
373/* The received packet for a mask assignment is unusual */
374
380 struct in_addr addr;
381 uint32_t num1;
382 uint32_t num2;
383 uint32_t num3;
384};
385
390 struct in_addr master_ip;
392};
393
401 /* dynamic lists of routers and caches elided */
402};
403
404/* Lists used to keep track of caches, routers and services */
405
408
409 struct in_addr cache_ip;
410
412
414};
415
431
433
456
458
459int empty_portlist[WCCP2_NUMPORTS] = {0, 0, 0, 0, 0, 0, 0, 0};
460
461/* END WCCP V2 PROTOCOL TYPES DEFINITION */
462
463static void wccp2_add_service_list(int service, int service_id, int service_priority,
464 int service_proto, int service_flags, int ports[], int security_type, char *password);
465static void wccp2SortCacheList(struct wccp2_cache_list_t *head);
466
467/*
468 * The functions used during startup:
469 * wccp2Init
470 * wccp2ConnectionOpen
471 * wccp2ConnectionClose
472 */
473
474static void
476{
477 debugs(80, 5, "wccp2InitServices: called");
478}
479
480static void
482 int service_id, int service_priority, int service_proto, int service_flags,
483 int ports[])
484{
485 /* XXX check what needs to be wrapped in htons()! */
486 srv->info.service = service;
487 srv->info.service_id = service_id;
488 srv->info.service_priority = service_priority;
489 srv->info.service_protocol = service_proto;
490 srv->info.service_flags = htonl(service_flags);
491 srv->info.port0 = htons(ports[0]);
492 srv->info.port1 = htons(ports[1]);
493 srv->info.port2 = htons(ports[2]);
494 srv->info.port3 = htons(ports[3]);
495 srv->info.port4 = htons(ports[4]);
496 srv->info.port5 = htons(ports[5]);
497 srv->info.port6 = htons(ports[6]);
498 srv->info.port7 = htons(ports[7]);
499}
500
501void
502wccp2_add_service_list(int service, int service_id, int service_priority,
503 int service_proto, int service_flags, int ports[], int security_type,
504 char *password)
505{
506
507 struct wccp2_service_list_t *wccp2_service_list_ptr;
508
509 wccp2_service_list_ptr = (wccp2_service_list_t *) xcalloc(1, sizeof(struct wccp2_service_list_t));
510
511 debugs(80, 5, "wccp2_add_service_list: added service id " << service_id);
512
513 /* XXX check what needs to be wrapped in htons()! */
514 wccp2_service_list_ptr->info.service_type = htons(WCCP2_SERVICE_INFO);
515
516 wccp2_service_list_ptr->info.service_length = htons(sizeof(struct wccp2_service_info_t) - 4);
517 wccp2_service_list_ptr->change_num = 0;
518 wccp2_update_service(wccp2_service_list_ptr, service, service_id,
519 service_priority, service_proto, service_flags, ports);
520 wccp2_service_list_ptr->wccp2_security_type = security_type;
521 memset(wccp2_service_list_ptr->wccp_password, 0, WCCP2_PASSWORD_LEN);
522 xstrncpy(wccp2_service_list_ptr->wccp_password, password, WCCP2_PASSWORD_LEN);
523 /* add to linked list - XXX this should use the Squid dlink* routines! */
524 wccp2_service_list_ptr->next = wccp2_service_list_head;
525 wccp2_service_list_head = wccp2_service_list_ptr;
526}
527
528static struct wccp2_service_list_t *
529wccp2_get_service_by_id(int service, int service_id) {
530
531 struct wccp2_service_list_t *p;
532
534
535 while (p != nullptr) {
536 if (p->info.service == service && p->info.service_id == service_id) {
537 return p;
538 }
539
540 p = p->next;
541 }
542
543 return nullptr;
544}
545
546/*
547 * Update the md5 security header, if possible
548 *
549 * Returns: 1 if we set it, 0 if not (eg, no security section, or non-md5)
550 */
551static char
552wccp2_update_md5_security(char *password, char *ptr, char *packet, int len)
553{
554 uint8_t md5Digest[SQUID_MD5_DIGEST_LENGTH];
555 char pwd[WCCP2_PASSWORD_LEN];
556 SquidMD5_CTX M;
557
558 struct wccp2_security_md5_t *ws;
559
560 debugs(80, 5, "wccp2_update_md5_security: called");
561
562 /* The password field, for the MD5 hash, needs to be 8 bytes and NUL padded. */
563 memset(pwd, 0, sizeof(pwd));
564 xstrncpy(pwd, password, sizeof(pwd));
565
566 ws = (struct wccp2_security_md5_t *) ptr;
568 /* Its the security part */
569
570 if (ntohl(ws->security_option) != WCCP2_MD5_SECURITY) {
571 debugs(80, 5, "wccp2_update_md5_security: this service ain't md5'ing, abort");
572 return 0;
573 }
574
575 /* And now its the MD5 section! */
576 /* According to the draft, the MD5 security hash is the combination of
577 * the 8-octet password (padded w/ NUL bytes) and the entire WCCP packet,
578 * including the WCCP message header. The WCCP security implementation
579 * area should be zero'ed before calculating the MD5 hash.
580 */
581 /* XXX eventually we should be able to kill md5Digest and blit it directly in */
582 memset(ws->security_implementation, 0, sizeof(ws->security_implementation));
583
584 SquidMD5Init(&M);
585
586 static_assert(sizeof(pwd) - 1 == 8, "WCCP2 password has exactly 8 (padded) octets, excluding storage-terminating NUL");
587
588 SquidMD5Update(&M, pwd, sizeof(pwd) - 1);
589
590 SquidMD5Update(&M, packet, len);
591
592 SquidMD5Final(md5Digest, &M);
593
594 memcpy(ws->security_implementation, md5Digest, sizeof(md5Digest));
595
596 /* Finished! */
597 return 1;
598}
599
600/*
601 * Check the given WCCP2 packet against the given password.
602 */
603static char
604
605wccp2_check_security(struct wccp2_service_list_t *srv, char *security, char *packet, int len)
606{
607
608 struct wccp2_security_md5_t *ws = (struct wccp2_security_md5_t *) security;
609 uint8_t md5Digest[SQUID_MD5_DIGEST_LENGTH], md5_challenge[SQUID_MD5_DIGEST_LENGTH];
610 char pwd[WCCP2_PASSWORD_LEN];
611 SquidMD5_CTX M;
612
613 /* Make sure the security type matches what we expect */
614
615 if (ntohl(ws->security_option) != srv->wccp2_security_type) {
616 debugs(80, DBG_IMPORTANT, "wccp2_check_security: received packet has the wrong security option");
617 return 0;
618 }
619
621 return 1;
622 }
623
625 debugs(80, DBG_IMPORTANT, "ERROR: wccp2_check_security: invalid security option");
626 return 0;
627 }
628
629 /* If execution makes it here then we have an MD5 security */
630
631 /* The password field, for the MD5 hash, needs to be 8 bytes and NUL padded. */
632 memset(pwd, 0, sizeof(pwd));
633 xstrncpy(pwd, srv->wccp_password, sizeof(pwd));
634
635 /* Take a copy of the challenge: we need to NUL it before comparing */
636 memcpy(md5_challenge, ws->security_implementation, sizeof(md5_challenge));
637
638 memset(ws->security_implementation, 0, sizeof(ws->security_implementation));
639
640 SquidMD5Init(&M);
641
642 static_assert(sizeof(pwd) - 1 == 8, "WCCP2 password has exactly 8 (padded) octets, excluding storage-terminating NUL");
643
644 SquidMD5Update(&M, pwd, sizeof(pwd) - 1);
645
646 SquidMD5Update(&M, packet, len);
647
648 SquidMD5Final(md5Digest, &M);
649
650 return (memcmp(md5Digest, md5_challenge, SQUID_MD5_DIGEST_LENGTH) == 0);
651}
652
653static void
655{
656 if (!IamPrimaryProcess())
657 return;
658
660 char *ptr;
661 uint32_t service_flags;
662
663 struct wccp2_service_list_t *service_list_ptr;
664
665 struct wccp2_router_list_t *router_list_ptr;
666
667 debugs(80, 5, "wccp2Init: Called");
668
669 if (wccp2_connected == 1)
670 return;
671
673
674 /* Calculate the number of routers configured in the config file */
675 for (s = Config.Wccp2.router; s; s = s->next) {
676 if (!s->s.isAnyAddr()) {
677 /* Increment the counter */
679 }
680 }
681
682 if (wccp2_numrouters == 0) {
683 return;
684 }
685
686 struct wccp2_security_md5_t wccp2_security_md5;
687 memset(&wccp2_security_md5, 0, sizeof(wccp2_security_md5));
688
689 /* Initialise the list of services */
691
692 service_list_ptr = wccp2_service_list_head;
693
694 while (service_list_ptr != nullptr) {
695 /* Set up our list pointers */
696 router_list_ptr = &service_list_ptr->router_list_head;
697
698 /* start the wccp header */
702 ptr = service_list_ptr->wccp_packet + sizeof(wccp2_here_i_am_header);
703
704 /* add the security section */
705 /* XXX this is ugly */
706
707 if (service_list_ptr->wccp2_security_type == WCCP2_MD5_SECURITY) {
708 wccp2_security_md5.security_option = htonl(WCCP2_MD5_SECURITY);
709
710 wccp2_security_md5.security_length = htons(sizeof(struct wccp2_security_md5_t) - 4);
711 } else if (service_list_ptr->wccp2_security_type == WCCP2_NO_SECURITY) {
712 wccp2_security_md5.security_option = htonl(WCCP2_NO_SECURITY);
713 /* XXX I hate magic length numbers! */
714 wccp2_security_md5.security_length = htons(4);
715 } else {
716 fatalf("Bad WCCP2 security type\n");
717 }
718
719 wccp2_here_i_am_header.length += ntohs(wccp2_security_md5.security_length) + 4;
721 wccp2_security_md5.security_type = htons(WCCP2_SECURITY_INFO);
722
723 service_list_ptr->security_info = (struct wccp2_security_md5_t *) ptr;
724
725 if (service_list_ptr->wccp2_security_type == WCCP2_MD5_SECURITY) {
726 memcpy(ptr, &wccp2_security_md5, sizeof(struct wccp2_security_md5_t));
727 ptr += sizeof(struct wccp2_security_md5_t);
728 } else {
729 /* assume NONE, and XXX I hate magic length numbers */
730 memcpy(ptr, &wccp2_security_md5, 8);
731 ptr += 8;
732 }
733
734 /* Add the service info section */
735
737
739
740 memcpy(ptr, &service_list_ptr->info, sizeof(struct wccp2_service_info_t));
741
742 service_list_ptr->service_info = (struct wccp2_service_info_t *) ptr;
743
744 ptr += sizeof(struct wccp2_service_info_t);
745
746 /* Add the cache identity section */
747
749
751
756 memset(&wccp2_identity_info.cache_identity.addr, '\0', sizeof(struct in_addr));
762
763 memcpy(ptr, &wccp2_identity_info, sizeof(struct wccp2_identity_info_t));
764 service_list_ptr->wccp2_identity_info_ptr = ptr;
765
766 ptr += sizeof(struct wccp2_identity_info_t);
767 break;
768
770
775 memset(&wccp2_mask_identity_info.cache_identity.addr, '\0', sizeof(struct in_addr));
778 service_flags = ntohl(service_list_ptr->service_info->service_flags);
779
781
782 if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
784 } 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)) {
786 } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
788 } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
790 } else {
791 fatalf("Unknown service hash method\n");
792 }
793
796
797 memcpy(ptr, &wccp2_mask_identity_info, sizeof(struct wccp2_mask_identity_info_t));
798 service_list_ptr->wccp2_identity_info_ptr = ptr;
799
800 ptr += sizeof(struct wccp2_mask_identity_info_t);
801 break;
802
803 default:
804 fatalf("Unknown Wccp2 assignment method\n");
805 }
806
807 /* Add the cache view section */
809
811
813
816
818
820
821 ptr += sizeof(wccp2_cache_view_header);
822
823 /* Add the number of routers to the packet */
824 wccp2_here_i_am_header.length += sizeof(service_list_ptr->num_routers);
825
827
828 service_list_ptr->num_routers = htonl(wccp2_numrouters);
829
830 memcpy(ptr, &service_list_ptr->num_routers, sizeof(service_list_ptr->num_routers));
831
832 ptr += sizeof(service_list_ptr->num_routers);
833
834 /* Add each router. Keep this functionality here to make sure the received_id can be updated in the packet */
835 for (s = Config.Wccp2.router; s; s = s->next) {
836 if (!s->s.isAnyAddr()) {
837
840
841 /* Add a pointer to the router list for this router */
842
843 router_list_ptr->info = (struct wccp2_router_id_element_t *) ptr;
844 s->s.getInAddr(router_list_ptr->info->router_address);
845 router_list_ptr->info->received_id = htonl(0);
846 s->s.getInAddr(router_list_ptr->router_sendto_address);
847 router_list_ptr->member_change = htonl(0);
848
849 /* Build the next struct */
850
851 router_list_ptr->next = (wccp2_router_list_t*) xcalloc(1, sizeof(struct wccp2_router_list_t));
852
853 /* update the pointer */
854 router_list_ptr = router_list_ptr->next;
855 router_list_ptr->next = nullptr;
856
857 /* no need to copy memory - we've just set the values directly in the packet above */
858
859 ptr += sizeof(struct wccp2_router_id_element_t);
860 }
861 }
862
863 /* Add the number of caches (0) */
865
867
869
871
872 ptr += sizeof(wccp2_cache_view_info.num_caches);
873
874 /* Add the extra capability header */
876
878
880
882
884
885 ptr += sizeof(wccp2_capability_info_header);
886
887 /* Add the forwarding method */
889
891
893
895
897
899
900 ptr += sizeof(wccp2_capability_element);
901
902 /* Add the assignment method */
904
906
908
910
912
914
915 ptr += sizeof(wccp2_capability_element);
916
917 /* Add the return method */
919
921
923
925
927
929
930 ptr += sizeof(wccp2_capability_element);
931
932 /* Finally, fix the total length to network order, and copy to the appropriate memory blob */
934
935 memcpy(&service_list_ptr->wccp_packet, &wccp2_here_i_am_header, sizeof(wccp2_here_i_am_header));
936
937 service_list_ptr->wccp_packet_size = ntohs(wccp2_here_i_am_header.length) + sizeof(wccp2_here_i_am_header);
938
939 /* Add the event if everything initialised correctly */
940 debugs(80,3,"wccp2Init: scheduled 'HERE_I_AM' message to " << wccp2_numrouters << "routers.");
941 if (wccp2_numrouters) {
942 if (!eventFind(wccp2HereIam, nullptr)) {
943 eventAdd("wccp2HereIam", wccp2HereIam, nullptr, 1, 1);
944 } else
945 debugs(80,3,"wccp2Init: skip duplicate 'HERE_I_AM'.");
946 }
947
948 service_list_ptr = service_list_ptr->next;
949 }
950}
951
952static void
954{
955 if (!IamPrimaryProcess())
956 return;
957
958 struct sockaddr_in router, local, null;
959 socklen_t local_len, router_len;
960
961 struct wccp2_service_list_t *service_list_ptr;
962
963 struct wccp2_router_list_t *router_list_ptr;
964
965 debugs(80, 5, "wccp2ConnectionOpen: Called");
966
968 debugs(80, 2, "WCCPv2 Disabled. No IPv4 Router(s) configured.");
969 return;
970 }
971
972 if ( !Config.Wccp2.address.setIPv4() ) {
973 debugs(80, DBG_CRITICAL, "WCCPv2 Disabled. Local address " << Config.Wccp2.address << " is not an IPv4 address.");
974 return;
975 }
976
979 0,
982 "WCCPv2 Socket");
983
984 if (theWccp2Connection < 0)
985 fatal("Cannot open WCCP Port");
986
987#if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
988 {
989 int i = IP_PMTUDISC_DONT;
990 if (xsetsockopt(theWccp2Connection, SOL_IP, IP_MTU_DISCOVER, &i, sizeof i) < 0) {
991 int xerrno = errno;
992 debugs(80, 2, "WARNING: Path MTU discovery could not be disabled on FD " << theWccp2Connection << ": " << xstrerr(xerrno));
993 }
994 }
995
996#endif
998
999 debugs(80, DBG_IMPORTANT, "Accepting WCCPv2 messages on port " << WCCP_PORT << ", FD " << theWccp2Connection << ".");
1000 debugs(80, DBG_IMPORTANT, "Initialising all WCCPv2 lists");
1001
1002 /* Initialise all routers on all services */
1003 memset(&null, 0, sizeof(null));
1004
1005 null.sin_family = AF_UNSPEC;
1006
1007 service_list_ptr = wccp2_service_list_head;
1008
1009 while (service_list_ptr != nullptr) {
1010 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1011 router_len = sizeof(router);
1012 memset(&router, '\0', router_len);
1013 router.sin_family = AF_INET;
1014 router.sin_port = htons(WCCP_PORT);
1015 router.sin_addr = router_list_ptr->router_sendto_address;
1016
1017 if (xconnect(theWccp2Connection, (struct sockaddr *) &router, router_len))
1018 fatal("Unable to connect WCCP out socket");
1019
1020 local_len = sizeof(local);
1021
1022 memset(&local, '\0', local_len);
1023
1024 if (xgetsockname(theWccp2Connection, (struct sockaddr *) &local, &local_len))
1025 fatal("Unable to getsockname on WCCP out socket");
1026
1027 router_list_ptr->local_ip = local.sin_addr;
1028
1029 /* Disconnect the sending socket. Note: FreeBSD returns error
1030 * but disconnects anyway so we have to just assume it worked
1031 */
1032 if (wccp2_numrouters > 1) {
1033 (void)xconnect(theWccp2Connection, (struct sockaddr *) &null, router_len);
1034 }
1035 }
1036
1037 service_list_ptr = service_list_ptr->next;
1038 }
1039
1040 wccp2_connected = 1;
1041}
1042
1043static void
1045{
1046 if (!IamPrimaryProcess())
1047 return;
1048
1049 struct wccp2_service_list_t *service_list_ptr;
1050
1051 struct wccp2_service_list_t *service_list_ptr_next;
1052
1053 struct wccp2_router_list_t *router_list_ptr;
1054
1055 struct wccp2_router_list_t *router_list_next;
1056
1057 struct wccp2_cache_list_t *cache_list_ptr;
1058
1059 struct wccp2_cache_list_t *cache_list_ptr_next;
1060
1061 if (wccp2_connected == 0) {
1062 return;
1063 }
1064
1065 /* TODO A shutting-down cache should generate a removal query, informing the router
1066 * (and therefore the caches in the group) that this cache is going
1067 * away and no new traffic should be forwarded to it.
1068 */
1069
1070 if (theWccp2Connection > -1) {
1071 debugs(80, DBG_IMPORTANT, "FD " << theWccp2Connection << " Closing WCCPv2 socket");
1073 theWccp2Connection = -1;
1074 }
1075
1076 /* free all stored router state */
1077 service_list_ptr = wccp2_service_list_head;
1078
1079 while (service_list_ptr != nullptr) {
1080 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr != nullptr; router_list_ptr = router_list_next) {
1081 for (cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr; cache_list_ptr = cache_list_ptr_next) {
1082 cache_list_ptr_next = cache_list_ptr->next;
1083
1084 if (cache_list_ptr != &router_list_ptr->cache_list_head) {
1085 xfree(cache_list_ptr);
1086 } else {
1087
1088 memset(cache_list_ptr, '\0', sizeof(struct wccp2_cache_list_t));
1089 }
1090 }
1091
1092 router_list_next = router_list_ptr->next;
1093
1094 if (router_list_ptr != &service_list_ptr->router_list_head) {
1095 xfree(router_list_ptr);
1096 } else {
1097
1098 memset(router_list_ptr, '\0', sizeof(struct wccp2_router_list_t));
1099 }
1100 }
1101
1102 service_list_ptr_next = service_list_ptr->next;
1103 xfree(service_list_ptr);
1104 service_list_ptr = service_list_ptr_next;
1105 }
1106
1107 wccp2_service_list_head = nullptr;
1108 eventDelete(wccp2HereIam, nullptr);
1110 eventDelete(wccp2HereIam, nullptr);
1111 wccp2_connected = 0;
1112}
1113
1115{
1116public:
1117 void useConfig() override { wccp2Init(); wccp2ConnectionOpen(); }
1119 void syncConfig() override { wccp2ConnectionOpen(); }
1121};
1123
1124/*
1125 * Functions for handling the requests.
1126 */
1127
1130static void
1131CheckSectionLength(const void *sectionStart, const size_t sectionLength, const void *wholeStart, const size_t wholeSize, const char *error)
1132{
1133 assert(sectionStart);
1134 assert(wholeStart);
1135
1136 const auto wholeEnd = static_cast<const char*>(wholeStart) + wholeSize;
1137 assert(sectionStart >= wholeStart && "we never go backwards");
1138 assert(sectionStart <= wholeEnd && "we never go beyond our whole (but zero-sized fields are OK)");
1139 static_assert(sizeof(wccp2_i_see_you_t) <= PTRDIFF_MAX, "paranoid: no UB when subtracting in-whole pointers");
1140 // subtraction safe due to the three assertions above
1141 const auto remainderDiff = wholeEnd - static_cast<const char*>(sectionStart);
1142
1143 // casting safe due to the assertions above (and size_t definition)
1144 assert(remainderDiff >= 0);
1145 const auto remainderSize = static_cast<size_t>(remainderDiff);
1146
1147 if (sectionLength <= remainderSize)
1148 return;
1149
1150 throw TextException(error, Here());
1151}
1152
1156template<class FieldHeader>
1157static size_t
1158CheckFieldDataLength(const FieldHeader *header, const size_t dataLength, const void *areaStart, const size_t areaSize, const char *error)
1159{
1160 assert(header);
1161 const auto dataStart = reinterpret_cast<const char*>(header) + sizeof(header);
1162 CheckSectionLength(dataStart, dataLength, areaStart, areaSize, error);
1163 return sizeof(header) + dataLength; // no overflow after CheckSectionLength()
1164}
1165
1173template<class Field>
1174static void
1175SetField(Field *&field, const void *fieldStart, const void *areaStart, const size_t areaSize, const char *error)
1176{
1177 CheckSectionLength(fieldStart, sizeof(Field), areaStart, areaSize, error);
1178 field = static_cast<Field*>(const_cast<void*>(fieldStart));
1179}
1180
1181/*
1182 * Accept the UDP packet
1183 */
1184static void
1185wccp2HandleUdp(int sock, void *)
1186{
1187 struct wccp2_service_list_t *service_list_ptr;
1188
1189 struct wccp2_router_list_t *router_list_ptr;
1190
1191 struct wccp2_cache_list_t *cache_list_ptr;
1192
1193 struct wccp2_cache_list_t *cache_list_ptr_next;
1194
1195 /* These structs form the parts of the packet */
1196
1197 struct wccp2_security_none_t *security_info = nullptr;
1198
1199 struct wccp2_service_info_t *service_info = nullptr;
1200
1201 struct router_identity_info_t *router_identity_info = nullptr;
1202
1203 struct router_view_t *router_view_header = nullptr;
1204
1205 struct wccp2_cache_mask_identity_info_t *cache_mask_identity = nullptr;
1206
1207 struct cache_mask_info_t *cache_mask_info = nullptr;
1208
1209 struct wccp2_cache_identity_info_t *cache_identity = nullptr;
1210
1211 struct wccp2_capability_info_header_t *router_capability_header = nullptr;
1212 char *router_capability_data_start = nullptr;
1213
1214 struct wccp2_capability_element_t *router_capability_element;
1215
1216 struct sockaddr_in from;
1217
1218 struct in_addr cache_address;
1219 uint32_t tmp;
1220 char *ptr;
1221 int num_caches;
1222
1223 debugs(80, 6, "wccp2HandleUdp: Called.");
1224
1226
1227 // TODO: drop conversion boundary
1228 Ip::Address from_tmp;
1229 from_tmp.setIPv4();
1230
1231 const auto lenOrError = comm_udp_recvfrom(sock, &wccp2_i_see_you, WCCP_RESPONSE_SIZE, 0, from_tmp);
1232
1233 if (lenOrError < 0)
1234 return;
1235 const auto len = static_cast<size_t>(lenOrError);
1236
1237 try {
1238 // TODO: Remove wccp2_i_see_you.data and use a buffer to read messages.
1239 const auto message_header_size = sizeof(wccp2_i_see_you) - sizeof(wccp2_i_see_you.data);
1240 Must3(len >= message_header_size, "incomplete WCCP message header", Here());
1241 Must3(ntohs(wccp2_i_see_you.version) == WCCP2_VERSION, "WCCP version unsupported", Here());
1242 Must3(ntohl(wccp2_i_see_you.type) == WCCP2_I_SEE_YOU, "WCCP packet type unsupported", Here());
1243
1244 // XXX: drop conversion boundary
1245 from_tmp.getSockAddr(from);
1246
1247 debugs(80, 3, "Incoming WCCPv2 I_SEE_YOU length " << ntohs(wccp2_i_see_you.length) << ".");
1248
1249 /* Record the total data length */
1250 const auto data_length = ntohs(wccp2_i_see_you.length);
1251 Must3(data_length <= len - message_header_size,
1252 "malformed packet claiming it's bigger than received data", Here());
1253
1254 size_t offset = 0;
1255
1256 /* Go through the data structure */
1257 while (offset + sizeof(struct wccp2_item_header_t) <= data_length) {
1258
1259 char *data = wccp2_i_see_you.data;
1260
1261 const auto itemHeader = reinterpret_cast<const wccp2_item_header_t*>(&data[offset]);
1262 const auto itemSize = CheckFieldDataLength(itemHeader, ntohs(itemHeader->length),
1263 data, data_length, "truncated record");
1264 // XXX: Check "The specified length must be a multiple of 4 octets"
1265 // requirement to avoid unaligned memory reads after the first item.
1266
1267 switch (ntohs(itemHeader->type)) {
1268
1270 Must3(!security_info, "duplicate security definition", Here());
1271 SetField(security_info, itemHeader, itemHeader, itemSize,
1272 "security definition truncated");
1273 break;
1274
1275 case WCCP2_SERVICE_INFO:
1276 Must3(!service_info, "duplicate service_info definition", Here());
1277 SetField(service_info, itemHeader, itemHeader, itemSize,
1278 "service_info definition truncated");
1279 break;
1280
1282 Must3(!router_identity_info, "duplicate router_identity_info definition", Here());
1283 SetField(router_identity_info, itemHeader, itemHeader, itemSize,
1284 "router_identity_info definition truncated");
1285 break;
1286
1288 Must3(!router_view_header, "duplicate router_view definition", Here());
1289 SetField(router_view_header, itemHeader, itemHeader, itemSize,
1290 "router_view definition truncated");
1291 break;
1292
1293 case WCCP2_CAPABILITY_INFO: {
1294 Must3(!router_capability_header, "duplicate router_capability definition", Here());
1295 SetField(router_capability_header, itemHeader, itemHeader, itemSize,
1296 "router_capability definition truncated");
1297
1298 CheckFieldDataLength(router_capability_header, ntohs(router_capability_header->capability_info_length),
1299 itemHeader, itemSize, "capability info truncated");
1300 router_capability_data_start = reinterpret_cast<char*>(router_capability_header) +
1301 sizeof(*router_capability_header);
1302 break;
1303 }
1304
1305 /* Nothing to do for the types below */
1306
1307 case WCCP2_ASSIGN_MAP:
1309 break;
1310
1311 default:
1312 debugs(80, DBG_IMPORTANT, "ERROR: Unknown record type in WCCPv2 Packet (" << ntohs(itemHeader->type) << ").");
1313 }
1314
1315 offset += itemSize;
1316 assert(offset <= data_length && "CheckFieldDataLength(itemHeader...) established that");
1317 }
1318
1319 Must3(security_info, "packet missing security definition", Here());
1320 Must3(service_info, "packet missing service_info definition", Here());
1321 Must3(router_identity_info, "packet missing router_identity_info definition", Here());
1322 Must3(router_view_header, "packet missing router_view definition", Here());
1323
1324 debugs(80, 5, "Complete packet received");
1325
1326 /* Check that the service in the packet is configured on this router */
1327 service_list_ptr = wccp2_service_list_head;
1328
1329 while (service_list_ptr != nullptr) {
1330 if (service_info->service_id == service_list_ptr->service_info->service_id) {
1331 break;
1332 }
1333
1334 service_list_ptr = service_list_ptr->next;
1335 }
1336
1337 if (service_list_ptr == nullptr) {
1338 debugs(80, DBG_IMPORTANT, "ERROR: WCCPv2 Unknown service received from router (" << service_info->service_id << ")");
1339 return;
1340 }
1341
1342 if (ntohl(security_info->security_option) != ntohl(service_list_ptr->security_info->security_option)) {
1343 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) << ").");
1344 return;
1345 }
1346
1347 if (!wccp2_check_security(service_list_ptr, (char *) security_info, (char *) &wccp2_i_see_you, len)) {
1348 debugs(80, DBG_IMPORTANT, "ERROR: Received WCCPv2 Packet failed authentication");
1349 return;
1350 }
1351
1352 /* Check that the router address is configured on this router */
1353 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1354 if (router_list_ptr->router_sendto_address.s_addr == from.sin_addr.s_addr)
1355 break;
1356 }
1357
1358 Must3(router_list_ptr->next, "packet received from unknown router", Here());
1359
1360 /* Set the router id */
1361 router_list_ptr->info->router_address = router_identity_info->router_id_element.router_address;
1362
1363 /* Increment the received id in the packet */
1364 if (ntohl(router_list_ptr->info->received_id) != ntohl(router_identity_info->router_id_element.received_id)) {
1365 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) << ".");
1366 router_list_ptr->info->received_id = router_identity_info->router_id_element.received_id;
1367 }
1368
1369 /* TODO: check return/forwarding methods */
1370 if (router_capability_header == nullptr) {
1372 debugs(80, DBG_IMPORTANT, "ERROR: wccp2HandleUdp: fatal error - A WCCP router does not support the forwarding method specified, only GRE supported");
1374 return;
1375 }
1376 } else {
1377
1378 const auto router_capability_data_length = ntohs(router_capability_header->capability_info_length);
1379 assert(router_capability_data_start);
1380 const auto router_capability_data_end = router_capability_data_start +
1381 router_capability_data_length;
1382 for (auto router_capability_data_current = router_capability_data_start;
1383 router_capability_data_current < router_capability_data_end;) {
1384
1385 SetField(router_capability_element, router_capability_data_current,
1386 router_capability_data_start, router_capability_data_length,
1387 "capability element header truncated");
1388 const auto elementSize = CheckFieldDataLength(
1389 router_capability_element, ntohs(router_capability_element->capability_length),
1390 router_capability_data_start, router_capability_data_length,
1391 "capability element truncated");
1392
1393 switch (ntohs(router_capability_element->capability_type)) {
1394
1396
1397 if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.forwarding_method)) {
1398 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);
1400 return;
1401 }
1402
1403 break;
1404
1406
1407 if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.assignment_method)) {
1408 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);
1410 return;
1411 }
1412
1413 break;
1414
1416
1417 if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.return_method)) {
1418 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);
1420 return;
1421 }
1422
1423 break;
1424
1425 case 4:
1426 case 5:
1427 break; // ignore silently for now
1428
1429 default:
1430 debugs(80, DBG_IMPORTANT, "ERROR: Unknown capability type in WCCPv2 Packet (" << ntohs(router_capability_element->capability_type) << ").");
1431 }
1432
1433 router_capability_data_current += elementSize;
1434 }
1435 }
1436
1437 debugs(80, 5, "Cleaning out cache list");
1438 /* clean out the old cache list */
1439
1440 for (cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr; cache_list_ptr = cache_list_ptr_next) {
1441 cache_list_ptr_next = cache_list_ptr->next;
1442
1443 if (cache_list_ptr != &router_list_ptr->cache_list_head) {
1444 xfree(cache_list_ptr);
1445 }
1446 }
1447
1448 router_list_ptr->num_caches = htonl(0);
1449 num_caches = 0;
1450
1451 /* Check to see if we're the master cache and update the cache list */
1452 bool found = false;
1453 service_list_ptr->lowest_ip = 1;
1454 cache_list_ptr = &router_list_ptr->cache_list_head;
1455
1456 /* to find the list of caches, we start at the end of the router view header */
1457
1458 ptr = (char *) (router_view_header) + sizeof(struct router_view_t);
1459 const auto router_view_size = sizeof(struct router_view_t) +
1460 ntohs(router_view_header->header.length);
1461
1462 /* Then we read the number of routers */
1463 const uint32_t *routerCountRaw = nullptr;
1464 SetField(routerCountRaw, ptr, router_view_header, router_view_size,
1465 "malformed packet (truncated router view info w/o number of routers)");
1466
1467 /* skip the number plus all the ip's */
1468 ptr += sizeof(*routerCountRaw);
1469 const auto ipCount = ntohl(*routerCountRaw);
1470 const auto ipsSize = ipCount * sizeof(struct in_addr); // we check for unsigned overflow below
1471 Must3(ipsSize / sizeof(struct in_addr) == ipCount, "huge IP address count", Here());
1472 CheckSectionLength(ptr, ipsSize, router_view_header, router_view_size, "invalid IP address count");
1473 ptr += ipsSize;
1474
1475 /* Then read the number of caches */
1476 const uint32_t *cacheCountRaw = nullptr;
1477 SetField(cacheCountRaw, ptr, router_view_header, router_view_size,
1478 "malformed packet (truncated router view info w/o cache count)");
1479 memcpy(&tmp, cacheCountRaw, sizeof(tmp)); // TODO: Replace tmp with cacheCount
1480 ptr += sizeof(tmp);
1481
1482 if (ntohl(tmp) != 0) {
1483 /* search through the list of received-from ip addresses */
1484
1485 for (num_caches = 0; num_caches < (int) ntohl(tmp); ++num_caches) {
1486 /* Get a copy of the ip */
1487 memset(&cache_address, 0, sizeof(cache_address)); // Make GCC happy
1488
1489 switch (Config.Wccp2.assignment_method) {
1490
1492
1493 SetField(cache_identity, ptr, router_view_header, router_view_size,
1494 "malformed packet (truncated router view info cache w/o assignment hash)");
1495
1496 ptr += sizeof(struct wccp2_cache_identity_info_t);
1497
1498 memcpy(&cache_address, &cache_identity->addr, sizeof(struct in_addr));
1499
1500 cache_list_ptr->weight = ntohs(cache_identity->weight);
1501 break;
1502
1504
1505 SetField(cache_mask_info, ptr, router_view_header, router_view_size,
1506 "malformed packet (truncated router view info cache w/o assignment mask)");
1507
1508 /* The mask assignment has an undocumented variable length entry here */
1509
1510 if (ntohl(cache_mask_info->num1) == 3) {
1511
1512 SetField(cache_mask_identity, ptr, router_view_header, router_view_size,
1513 "malformed packet (truncated router view info cache w/o assignment mask identity)");
1514
1515 ptr += sizeof(struct wccp2_cache_mask_identity_info_t);
1516
1517 memcpy(&cache_address, &cache_mask_identity->addr, sizeof(struct in_addr));
1518 } else {
1519
1520 ptr += sizeof(struct cache_mask_info_t);
1521
1522 memcpy(&cache_address, &cache_mask_info->addr, sizeof(struct in_addr));
1523 }
1524
1525 cache_list_ptr->weight = 0;
1526 break;
1527
1528 default:
1529 fatalf("Unknown Wccp2 assignment method\n");
1530 }
1531
1532 /* Update the cache list */
1533 cache_list_ptr->cache_ip = cache_address;
1534
1535 cache_list_ptr->next = (wccp2_cache_list_t*) xcalloc(1, sizeof(struct wccp2_cache_list_t));
1536
1537 cache_list_ptr = cache_list_ptr->next;
1538
1539 cache_list_ptr->next = nullptr;
1540
1541 debugs (80, 5, "checking cache list: (" << std::hex << cache_address.s_addr << ":" << router_list_ptr->local_ip.s_addr << ")");
1542
1543 /* Check to see if it's the master, or us */
1544 found = found || (cache_address.s_addr == router_list_ptr->local_ip.s_addr);
1545
1546 if (cache_address.s_addr < router_list_ptr->local_ip.s_addr) {
1547 service_list_ptr->lowest_ip = 0;
1548 }
1549 }
1550 } else {
1551 debugs(80, 5, "Adding ourselves as the only cache");
1552
1553 /* Update the cache list */
1554 cache_list_ptr->cache_ip = router_list_ptr->local_ip;
1555
1556 cache_list_ptr->next = (wccp2_cache_list_t*) xcalloc(1, sizeof(struct wccp2_cache_list_t));
1557 cache_list_ptr = cache_list_ptr->next;
1558 cache_list_ptr->next = nullptr;
1559
1560 service_list_ptr->lowest_ip = 1;
1561 found = true;
1562 num_caches = 1;
1563 }
1564
1565 wccp2SortCacheList(&router_list_ptr->cache_list_head);
1566
1567 router_list_ptr->num_caches = htonl(num_caches);
1568
1569 if (found && (service_list_ptr->lowest_ip == 1)) {
1570 if (ntohl(router_view_header->change_number) != router_list_ptr->member_change) {
1571 debugs(80, 4, "Change detected - queueing up new assignment");
1572 router_list_ptr->member_change = ntohl(router_view_header->change_number);
1574 eventAdd("wccp2AssignBuckets", wccp2AssignBuckets, nullptr, 15.0, 1);
1575 } else {
1576 debugs(80, 5, "Change not detected (" << ntohl(router_view_header->change_number) << " = " << router_list_ptr->member_change << ")");
1577 }
1578 } else {
1580 debugs(80, 5, "I am not the lowest ip cache - not assigning buckets");
1581 }
1582
1583 } catch (...) {
1584 debugs(80, DBG_IMPORTANT, "ERROR: Ignoring WCCPv2 message: " << CurrentException);
1585 }
1586}
1587
1588static void
1590{
1591 struct wccp2_service_list_t *service_list_ptr;
1592
1593 struct wccp2_router_list_t *router_list_ptr;
1594
1595 struct wccp2_identity_info_t *wccp2_identity_info_ptr;
1596
1597 struct wccp2_mask_identity_info_t *wccp2_mask_identity_info_ptr;
1598
1599 Ip::Address router;
1600
1601 debugs(80, 6, "wccp2HereIam: Called");
1602
1603 if (wccp2_connected == 0) {
1604 debugs(80, DBG_IMPORTANT, "wccp2HereIam: wccp2 socket closed. Shutting down WCCP2");
1605 return;
1606 }
1607
1608 /* Wait if store dirs are rebuilding */
1610 eventAdd("wccp2HereIam", wccp2HereIam, nullptr, 1.0, 1);
1611 return;
1612 }
1613
1614 router.port(WCCP_PORT);
1615
1616 /* for each router on each service send a packet */
1617 service_list_ptr = wccp2_service_list_head;
1618
1619 while (service_list_ptr != nullptr) {
1620 debugs(80, 5, "wccp2HereIam: sending to service id " << service_list_ptr->info.service_id);
1621
1622 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1623 router = router_list_ptr->router_sendto_address;
1624
1625 /* Set the cache id (ip) */
1626
1627 switch (Config.Wccp2.assignment_method) {
1628
1630
1631 wccp2_identity_info_ptr = (struct wccp2_identity_info_t *) service_list_ptr->wccp2_identity_info_ptr;
1632 wccp2_identity_info_ptr->cache_identity.addr = router_list_ptr->local_ip;
1633 break;
1634
1636
1637 wccp2_mask_identity_info_ptr = (struct wccp2_mask_identity_info_t *) service_list_ptr->wccp2_identity_info_ptr;
1638 wccp2_mask_identity_info_ptr->cache_identity.addr = router_list_ptr->local_ip;
1639 break;
1640
1641 default:
1642 fatalf("Unknown Wccp2 assignment method\n");
1643 }
1644
1645 /* Security update, if needed */
1646
1647 if (service_list_ptr->wccp2_security_type == WCCP2_MD5_SECURITY) {
1648 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);
1649 }
1650
1651 debugs(80, 3, "Sending HereIam packet size " << service_list_ptr->wccp_packet_size);
1652 /* Send the packet */
1653
1654 if (wccp2_numrouters > 1) {
1656 router,
1657 &service_list_ptr->wccp_packet,
1658 service_list_ptr->wccp_packet_size);
1659 } else {
1660 if (xsend(theWccp2Connection, &service_list_ptr->wccp_packet, service_list_ptr->wccp_packet_size, 0) < static_cast<int>(service_list_ptr->wccp_packet_size)) {
1661 int xerrno = errno;
1662 debugs(80, 2, "ERROR: failed to send WCCPv2 HERE_I_AM packet to " << router << " : " << xstrerr(xerrno));
1663 }
1664 }
1665 }
1666
1667 service_list_ptr = service_list_ptr->next;
1668 }
1669
1670 eventAdd("wccp2HereIam", wccp2HereIam, nullptr, 10.0, 1);
1671}
1672
1673static void
1675{
1676 struct wccp2_service_list_t *service_list_ptr;
1677
1678 struct wccp2_router_list_t *router_list_ptr;
1679
1680 struct wccp2_cache_list_t *cache_list_ptr;
1681 char wccp_packet[WCCP_RESPONSE_SIZE];
1682 short int offset, saved_offset, assignment_offset, alt_assignment_offset;
1683
1684 struct sockaddr_in router;
1685 int router_len;
1686 int bucket_counter;
1687 uint32_t service_flags;
1688 /* Packet segments */
1689
1690 struct wccp2_message_header_t *main_header;
1691
1692 struct wccp2_security_md5_t *security = nullptr;
1693 /* service from service struct */
1694
1695 struct wccp2_item_header_t *assignment_header;
1696
1697 struct wccp2_item_header_t *alt_assignment_type_header = nullptr;
1698
1699 struct assignment_key_t *assignment_key;
1700 /* number of routers */
1701
1702 struct wccp2_router_assign_element_t *router_assign;
1703 /* number of caches */
1704
1705 struct in_addr *cache_address;
1706 /* Alternative assignment mask/values */
1707 int num_maskval;
1708
1709 struct wccp2_mask_element_t *mask_element;
1710
1711 struct wccp2_value_element_t *value_element;
1712 int valuecounter, value;
1713 char *buckets;
1714
1715 assignment_offset = alt_assignment_offset = 0;
1716
1717 router_len = sizeof(router);
1718 memset(&router, '\0', router_len);
1719 router.sin_family = AF_INET;
1720 router.sin_port = htons(WCCP_PORT);
1721
1722 /* Start main header - fill in length later */
1723 offset = 0;
1724
1725 main_header = (struct wccp2_message_header_t *) &wccp_packet[offset];
1726 main_header->type = htonl(WCCP2_REDIRECT_ASSIGN);
1727 main_header->version = htons(WCCP2_VERSION);
1728
1729 debugs(80, 2, "Running wccp2AssignBuckets");
1730 service_list_ptr = wccp2_service_list_head;
1731
1732 while (service_list_ptr != nullptr) {
1733 /* If we're not the lowest, we don't need to worry */
1734
1735 if (service_list_ptr->lowest_ip == 0) {
1736 /* XXX eww */
1737 service_list_ptr = service_list_ptr->next;
1738 continue;
1739 }
1740
1741 /* reset the offset */
1742
1743 offset = sizeof(struct wccp2_message_header_t);
1744
1745 /* build packet header from hereIam packet */
1746 /* Security info */
1747 /* XXX this should be made more generic! */
1748 /* XXX and I hate magic numbers! */
1749 switch (service_list_ptr->wccp2_security_type) {
1750
1751 case WCCP2_NO_SECURITY:
1752
1753 security = (struct wccp2_security_md5_t *) &wccp_packet[offset];
1754 memcpy(security, service_list_ptr->security_info, 8);
1755 offset += 8;
1756 break;
1757
1758 case WCCP2_MD5_SECURITY:
1759
1760 security = (struct wccp2_security_md5_t *) &wccp_packet[offset];
1761
1762 memcpy(security, service_list_ptr->security_info, sizeof(struct wccp2_security_md5_t));
1763
1764 offset += sizeof(struct wccp2_security_md5_t);
1765 break;
1766
1767 default:
1768 fatalf("Unknown Wccp2 security type\n");
1769 }
1770
1771 /* Service info */
1772
1773 memcpy(&wccp_packet[offset], service_list_ptr->service_info, sizeof(struct wccp2_service_info_t));
1774
1775 offset += sizeof(struct wccp2_service_info_t);
1776
1777 /* assignment header - fill in length later */
1778
1779 assignment_header = (struct wccp2_item_header_t *) &wccp_packet[offset];
1780
1781 switch (Config.Wccp2.assignment_method) {
1782
1784 assignment_header->type = htons(WCCP2_REDIRECT_ASSIGNMENT);
1785
1786 offset += sizeof(struct wccp2_item_header_t);
1787 assignment_offset = offset;
1788 break;
1789
1791 assignment_header->type = htons(WCCP2_ALT_ASSIGNMENT);
1792
1793 offset += sizeof(struct wccp2_item_header_t);
1794 assignment_offset = offset;
1795
1796 /* The alternative assignment has an extra header, fill in length later */
1797
1798 alt_assignment_type_header = (struct wccp2_item_header_t *) &wccp_packet[offset];
1799 alt_assignment_type_header->type = htons(WCCP2_MASK_ASSIGNMENT);
1800
1801 offset += sizeof(struct wccp2_item_header_t);
1802 alt_assignment_offset = offset;
1803
1804 break;
1805
1806 default:
1807 fatalf("Unknown Wccp2 assignment method\n");
1808 }
1809
1810 /* Assignment key - fill in master ip later */
1811
1812 assignment_key = (struct assignment_key_t *) &wccp_packet[offset];
1813
1814 ++service_list_ptr->change_num;
1815 assignment_key->master_number = htonl(service_list_ptr->change_num);
1816
1817 offset += sizeof(struct assignment_key_t);
1818
1819 /* Number of routers */
1820 memcpy(&wccp_packet[offset], &service_list_ptr->num_routers, sizeof(service_list_ptr->num_routers));
1821
1822 offset += sizeof(service_list_ptr->num_routers);
1823
1824 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1825
1826 /* Add routers */
1827
1828 router_assign = (struct wccp2_router_assign_element_t *) &wccp_packet[offset];
1829 router_assign->router_address = router_list_ptr->info->router_address;
1830 router_assign->received_id = router_list_ptr->info->received_id;
1831 router_assign->change_number = htonl(router_list_ptr->member_change);
1832
1833 offset += sizeof(struct wccp2_router_assign_element_t);
1834 }
1835
1836 saved_offset = offset;
1837
1838 for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != nullptr; router_list_ptr = router_list_ptr->next) {
1839 unsigned long *weight = (unsigned long *)xcalloc(sizeof(*weight), ntohl(router_list_ptr->num_caches));
1840 unsigned long total_weight = 0;
1841 int num_caches = ntohl(router_list_ptr->num_caches);
1842
1843 offset = saved_offset;
1844
1845 switch (Config.Wccp2.assignment_method) {
1846
1848 /* Number of caches */
1849 memcpy(&wccp_packet[offset], &router_list_ptr->num_caches, sizeof(router_list_ptr->num_caches));
1850 offset += sizeof(router_list_ptr->num_caches);
1851
1852 if (num_caches) {
1853 int cache;
1854
1855 for (cache = 0, cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr->next; cache_list_ptr = cache_list_ptr->next, ++cache) {
1856 /* add caches */
1857
1858 cache_address = (struct in_addr *) &wccp_packet[offset];
1859
1860 memcpy(cache_address, &cache_list_ptr->cache_ip, sizeof(struct in_addr));
1861 total_weight += cache_list_ptr->weight << 12;
1862 weight[cache] = cache_list_ptr->weight << 12;
1863
1864 offset += sizeof(struct in_addr);
1865 }
1866 }
1867
1868 /* Add buckets */
1869 buckets = (char *) &wccp_packet[offset];
1870
1871 memset(buckets, '\0', WCCP_BUCKETS);
1872
1873 if (num_caches != 0) {
1874 if (total_weight == 0) {
1875 for (bucket_counter = 0; bucket_counter < WCCP_BUCKETS; ++bucket_counter) {
1876 buckets[bucket_counter] = (char) (bucket_counter % num_caches);
1877 }
1878 } else {
1879 unsigned long *assigned = (unsigned long *)xcalloc(sizeof(*assigned), num_caches);
1880 unsigned long done = 0;
1881 int cache = -1;
1882 unsigned long per_bucket = total_weight / WCCP_BUCKETS;
1883
1884 for (bucket_counter = 0; bucket_counter < WCCP_BUCKETS; ++bucket_counter) {
1885 int n;
1886 unsigned long step;
1887
1888 for (n = num_caches; n; --n) {
1889 ++cache;
1890
1891 if (cache >= num_caches)
1892 cache = 0;
1893
1894 if (!weight[cache]) {
1895 ++n;
1896 continue;
1897 }
1898
1899 if (assigned[cache] <= done)
1900 break;
1901 }
1902
1903 buckets[bucket_counter] = (char) cache;
1904 step = per_bucket * total_weight / weight[cache];
1905 assigned[cache] += step;
1906 done += per_bucket;
1907 }
1908
1909 safe_free(assigned);
1910 }
1911 }
1912
1913 offset += (WCCP_BUCKETS * sizeof(char));
1914 safe_free(weight);
1915 break;
1916
1918 num_maskval = htonl(1);
1919 memcpy(&wccp_packet[offset], &num_maskval, sizeof(int));
1920 offset += sizeof(int);
1921
1922 mask_element = (struct wccp2_mask_element_t *) &wccp_packet[offset];
1923 service_flags = ntohl(service_list_ptr->service_info->service_flags);
1924
1925 if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
1926 mask_element->source_ip_mask = htonl(0x00001741);
1927 mask_element->dest_ip_mask = 0;
1928 mask_element->source_port_mask = 0;
1929 mask_element->dest_port_mask = 0;
1930 } 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)) {
1931 mask_element->source_ip_mask = 0;
1932 mask_element->dest_ip_mask = htonl(0x00001741);
1933 mask_element->source_port_mask = 0;
1934 mask_element->dest_port_mask = 0;
1935 } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
1936 mask_element->source_ip_mask = 0;
1937 mask_element->dest_ip_mask = 0;
1938 mask_element->source_port_mask = htons(0x1741);
1939 mask_element->dest_port_mask = 0;
1940 } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
1941 mask_element->source_ip_mask = 0;
1942 mask_element->dest_ip_mask = 0;
1943 mask_element->source_port_mask = 0;
1944 mask_element->dest_port_mask = htons(0x1741);
1945 } else {
1946 fatalf("Unknown service hash method\n");
1947 }
1948
1949 mask_element->number_values = htonl(64);
1950
1951 offset += sizeof(struct wccp2_mask_element_t);
1952
1953 cache_list_ptr = &router_list_ptr->cache_list_head;
1954 value = 0;
1955
1956 for (valuecounter = 0; valuecounter < 64; ++valuecounter) {
1957
1958 value_element = (struct wccp2_value_element_t *) &wccp_packet[offset];
1959
1960 /* Update the value according the the "correct" formula */
1961
1962 for (; (value & 0x1741) != value; ++value) {
1963 assert(value <= 0x1741);
1964 }
1965
1966 if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
1967 value_element->source_ip_value = htonl(value);
1968 value_element->dest_ip_value = 0;
1969 value_element->source_port_value = 0;
1970 value_element->dest_port_value = 0;
1971 } 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)) {
1972 value_element->source_ip_value = 0;
1973 value_element->dest_ip_value = htonl(value);
1974 value_element->source_port_value = 0;
1975 value_element->dest_port_value = 0;
1976 } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
1977 value_element->source_ip_value = 0;
1978 value_element->dest_ip_value = 0;
1979 value_element->source_port_value = htons(value);
1980 value_element->dest_port_value = 0;
1981 } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
1982 value_element->source_ip_value = 0;
1983 value_element->dest_ip_value = 0;
1984 value_element->source_port_value = 0;
1985 value_element->dest_port_value = htons(value);
1986 } else {
1987 fatalf("Unknown service hash method\n");
1988 }
1989
1990 value_element->cache_ip = cache_list_ptr->cache_ip;
1991
1992 offset += sizeof(struct wccp2_value_element_t);
1993 ++value;
1994
1995 /* Assign the next value to the next cache */
1996
1997 if ((cache_list_ptr->next) && (cache_list_ptr->next->next))
1998 cache_list_ptr = cache_list_ptr->next;
1999 else
2000 cache_list_ptr = &router_list_ptr->cache_list_head;
2001 }
2002
2003 /* Fill in length */
2004 alt_assignment_type_header->length = htons(offset - alt_assignment_offset);
2005
2006 break;
2007
2008 default:
2009 fatalf("Unknown Wccp2 assignment method\n");
2010 }
2011
2012 /* Fill in length */
2013
2014 assignment_header->length = htons(offset - assignment_offset);
2015
2016 /* Fill in assignment key */
2017 assignment_key->master_ip = router_list_ptr->local_ip;
2018
2019 /* finish length */
2020
2021 main_header->length = htons(offset - sizeof(struct wccp2_message_header_t));
2022
2023 /* set the destination address */
2024 router.sin_addr = router_list_ptr->router_sendto_address;
2025
2026 /* Security update, if needed */
2027
2028 if (service_list_ptr->wccp2_security_type == WCCP2_MD5_SECURITY) {
2029 wccp2_update_md5_security(service_list_ptr->wccp_password, (char *) security, wccp_packet, offset);
2030 }
2031
2032 if (ntohl(router_list_ptr->num_caches)) {
2033 /* send packet */
2034
2035 // XXX: drop temp conversion
2036 Ip::Address tmp_rtr(router);
2037
2038 if (wccp2_numrouters > 1) {
2040 tmp_rtr,
2041 &wccp_packet,
2042 offset);
2043 } else {
2044 if (xsend(theWccp2Connection, &wccp_packet, offset, 0) < offset) {
2045 int xerrno = errno;
2046 debugs(80, 2, "ERROR: failed to send WCCPv2 HERE_I_AM packet to " << tmp_rtr << " : " << xstrerr(xerrno));
2047 }
2048 }
2049 }
2050 safe_free(weight);
2051 }
2052
2053 service_list_ptr = service_list_ptr->next;
2054 }
2055}
2056
2057/*
2058 * Configuration option parsing code
2059 */
2060
2066void
2068{
2069 char *t;
2070
2071 /* Snarf the method */
2072 if ((t = ConfigParser::NextToken()) == nullptr) {
2073 debugs(80, DBG_CRITICAL, "ERROR: wccp2_*_method: missing setting.");
2074 self_destruct();
2075 return;
2076 }
2077
2078 /* update configuration if its valid */
2079 if (strcmp(t, "gre") == 0 || strcmp(t, "1") == 0) {
2080 *method = WCCP2_METHOD_GRE;
2081 } else if (strcmp(t, "l2") == 0 || strcmp(t, "2") == 0) {
2082 *method = WCCP2_METHOD_L2;
2083 } else {
2084 debugs(80, DBG_CRITICAL, "ERROR: wccp2_*_method: unknown setting, got " << t );
2085 self_destruct();
2086 }
2087}
2088
2089void
2090dump_wccp2_method(StoreEntry * e, const char *label, int v)
2091{
2092 switch (v) {
2093 case WCCP2_METHOD_GRE:
2094 storeAppendPrintf(e, "%s gre\n", label);
2095 break;
2096 case WCCP2_METHOD_L2:
2097 storeAppendPrintf(e, "%s l2\n", label);
2098 break;
2099 default:
2100 debugs(80, DBG_CRITICAL, "FATAL: WCCPv2 configured method (" << v << ") is not valid.");
2101 self_destruct();
2102 }
2103}
2104
2105void
2107{ }
2108
2114void
2116{
2117 char *t;
2118
2119 /* Snarf the method */
2120 if ((t = ConfigParser::NextToken()) == nullptr) {
2121 debugs(80, DBG_CRITICAL, "ERROR: wccp2_assignment_method: missing setting.");
2122 self_destruct();
2123 return;
2124 }
2125
2126 /* update configuration if its valid */
2127 if (strcmp(t, "hash") == 0 || strcmp(t, "1") == 0) {
2129 } else if (strcmp(t, "mask") == 0 || strcmp(t, "2") == 0) {
2131 } else {
2132 debugs(80, DBG_CRITICAL, "ERROR: wccp2_assignment_method: unknown setting, got " << t );
2133 self_destruct();
2134 }
2135}
2136
2137void
2138dump_wccp2_amethod(StoreEntry * e, const char *label, int v)
2139{
2140 switch (v) {
2142 storeAppendPrintf(e, "%s hash\n", label);
2143 break;
2145 storeAppendPrintf(e, "%s mask\n", label);
2146 break;
2147 default:
2148 debugs(80, DBG_CRITICAL, "FATAL: WCCPv2 configured " << label << " (" << v << ") is not valid.");
2149 self_destruct();
2150 }
2151}
2152
2153void
2156
2157/*
2158 * Format:
2159 *
2160 * wccp2_service {standard|dynamic} {id} (password=password)
2161 */
2162void
2164{
2165 char *t;
2166 int service = 0;
2167 int service_id = 0;
2168 int security_type = WCCP2_NO_SECURITY;
2169 char wccp_password[WCCP2_PASSWORD_LEN];
2170
2171 if (wccp2_connected == 1) {
2172 debugs(80, DBG_IMPORTANT, "WCCPv2: Somehow reparsing the configuration without having shut down WCCP! Try reloading squid again.");
2173 return;
2174 }
2175
2176 /* Snarf the type */
2177 if ((t = ConfigParser::NextToken()) == nullptr) {
2178 debugs(80, DBG_CRITICAL, "ERROR: wccp2ParseServiceInfo: missing service info type (standard|dynamic)");
2179 self_destruct();
2180 return;
2181 }
2182
2183 if (strcmp(t, "standard") == 0) {
2184 service = WCCP2_SERVICE_STANDARD;
2185 } else if (strcmp(t, "dynamic") == 0) {
2186 service = WCCP2_SERVICE_DYNAMIC;
2187 } else {
2188 debugs(80, DBG_CRITICAL, "ERROR: wccp2ParseServiceInfo: bad service info type (expected standard|dynamic, got " << t << ")");
2189 self_destruct();
2190 return;
2191 }
2192
2193 /* Snarf the ID */
2194 service_id = GetInteger();
2195
2196 if (service_id < 0 || service_id > 255) {
2197 debugs(80, DBG_CRITICAL, "ERROR: invalid WCCP service id " << service_id << " (must be between 0 .. 255)");
2198 self_destruct();
2199 return;
2200 }
2201
2202 memset(wccp_password, 0, sizeof(wccp_password));
2203 /* Handle password, if any */
2204
2205 if ((t = ConfigParser::NextToken()) != nullptr) {
2206 if (strncmp(t, "password=", 9) == 0) {
2207 security_type = WCCP2_MD5_SECURITY;
2208 xstrncpy(wccp_password, t + 9, sizeof(wccp_password));
2209 }
2210 }
2211
2212 /* Create a placeholder service record */
2213 wccp2_add_service_list(service, service_id, 0, 0, 0, empty_portlist, security_type, wccp_password);
2214}
2215
2216void
2217dump_wccp2_service(StoreEntry * e, const char *label, void *)
2218{
2219 struct wccp2_service_list_t *srv;
2221
2222 while (srv != nullptr) {
2223 debugs(80, 3, "dump_wccp2_service: id " << srv->info.service_id << ", type " << srv->info.service);
2224 storeAppendPrintf(e, "%s %s %d", label,
2225 (srv->info.service == WCCP2_SERVICE_DYNAMIC) ? "dynamic" : "standard",
2226 srv->info.service_id);
2227
2229 storeAppendPrintf(e, " %s", srv->wccp_password);
2230 }
2231
2232 storeAppendPrintf(e, "\n");
2233
2234 srv = srv->next;
2235 }
2236}
2237
2238void
2240{}
2241
2242int
2244{
2246}
2247
2248/*
2249 * Format:
2250 *
2251 * wccp2_service_info {id} stuff..
2252 *
2253 * Where stuff is:
2254 *
2255 * + flags=flag,flag,flag..
2256 * + proto=protocol (tcp|udp)
2257 * + ports=port,port,port (up to a max of 8)
2258 * + priority=priority (0->255)
2259 *
2260 * The flags here are:
2261 * src_ip_hash, dst_ip_hash, source_port_hash, dst_port_hash, ports_defined,
2262 * ports_source, src_ip_alt_hash, dst_ip_alt_hash, src_port_alt_hash, dst_port_alt_hash
2263 */
2264static int
2266{
2267 if (!flags)
2268 return 0;
2269
2270 char *flag = flags;
2271 int retflag = 0;
2272
2273 while (size_t len = strcspn(flag, ",")) {
2274
2275 if (strncmp(flag, "src_ip_hash", len) == 0) {
2276 retflag |= WCCP2_SERVICE_SRC_IP_HASH;
2277 } else if (strncmp(flag, "dst_ip_hash", len) == 0) {
2278 retflag |= WCCP2_SERVICE_DST_IP_HASH;
2279 } else if (strncmp(flag, "source_port_hash", len) == 0) {
2280 retflag |= WCCP2_SERVICE_SRC_PORT_HASH;
2281 } else if (strncmp(flag, "dst_port_hash", len) == 0) {
2282 retflag |= WCCP2_SERVICE_DST_PORT_HASH;
2283 } else if (strncmp(flag, "ports_source", len) == 0) {
2284 retflag |= WCCP2_SERVICE_PORTS_SOURCE;
2285 } else if (strncmp(flag, "src_ip_alt_hash", len) == 0) {
2287 } else if (strncmp(flag, "dst_ip_alt_hash", len) == 0) {
2289 } else if (strncmp(flag, "src_port_alt_hash", len) == 0) {
2291 } else if (strncmp(flag, "dst_port_alt_hash", len) == 0) {
2293 } else {
2294 flag[len] = '\0';
2295 fatalf("Unknown wccp2 service flag: %s\n", flag);
2296 }
2297
2298 if (flag[len] == '\0')
2299 break;
2300
2301 flag += len+1;
2302 }
2303
2304 return retflag;
2305}
2306
2307static void
2308parse_wccp2_service_ports(char *options, int portlist[])
2309{
2310 if (!options) {
2311 return;
2312 }
2313
2314 int i = 0;
2315 char *tmp = options;
2316 static char copy[10];
2317
2318 while (size_t len = strcspn(tmp, ",")) {
2319 if (i >= WCCP2_NUMPORTS) {
2320 fatalf("parse_wccp2_service_ports: too many ports (maximum: 8) in list '%s'\n", options);
2321 }
2322 if (len > 6) { // 6 because "65535,"
2323 fatalf("parse_wccp2_service_ports: port value '%s' isn't valid (1..65535)\n", tmp);
2324 }
2325
2326 memcpy(copy, tmp, len);
2327 copy[len] = '\0';
2328 int p = xatoi(copy);
2329
2330 if (p < 1 || p > 65535) {
2331 fatalf("parse_wccp2_service_ports: port value '%s' isn't valid (1..65535)\n", tmp);
2332 }
2333
2334 portlist[i] = p;
2335 ++i;
2336 if (tmp[len] == '\0')
2337 return;
2338 tmp += len+1;
2339 }
2340}
2341
2342void
2344{
2345 char *t, *end;
2346 int service_id = 0;
2347 int flags = 0;
2348 int portlist[WCCP2_NUMPORTS];
2349 int protocol = -1; /* IPPROTO_TCP | IPPROTO_UDP */
2350
2351 struct wccp2_service_list_t *srv;
2352 int priority = -1;
2353
2354 if (wccp2_connected == 1) {
2355 debugs(80, DBG_IMPORTANT, "WCCPv2: Somehow reparsing the configuration without having shut down WCCP! Try reloading squid again.");
2356 return;
2357 }
2358
2359 debugs(80, 5, "parse_wccp2_service_info: called");
2360 memset(portlist, 0, sizeof(portlist));
2361 /* First argument: id */
2362 service_id = GetInteger();
2363
2364 if (service_id < 0 || service_id > 255) {
2365 debugs(80, DBG_CRITICAL, "ERROR: invalid WCCP service id " << service_id << " (must be between 0 .. 255)");
2366 self_destruct();
2367 return;
2368 }
2369
2370 /* Next: find the (hopefully!) existing service */
2372
2373 if (srv == nullptr) {
2374 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);
2375 }
2376
2377 /* Next: loop until we don't have any more tokens */
2378 while ((t = ConfigParser::NextToken()) != nullptr) {
2379 if (strncmp(t, "flags=", 6) == 0) {
2380 /* XXX eww, string pointer math */
2381 flags = parse_wccp2_service_flags(t + 6);
2382 } else if (strncmp(t, "ports=", 6) == 0) {
2383 parse_wccp2_service_ports(t + 6, portlist);
2385 } else if (strncmp(t, "protocol=tcp", 12) == 0) {
2386 protocol = IPPROTO_TCP;
2387 } else if (strncmp(t, "protocol=udp", 12) == 0) {
2388 protocol = IPPROTO_UDP;
2389 } else if (strncmp(t, "protocol=", 9) == 0) {
2390 fatalf("parse_wccp2_service_info: id %d: unknown protocol (%s) - must be tcp or udp!\n", service_id, t);
2391 } else if (strncmp(t, "priority=", 9) == 0) {
2392 priority = strtol(t + 9, &end, 0);
2393
2394 if (priority < 0 || priority > 255) {
2395 fatalf("parse_wccp2_service_info: id %d: %s out of range (0..255)!\n", service_id, t);
2396 }
2397 } else {
2398 fatalf("parse_wccp2_service_info: id %d: unknown option '%s'\n", service_id, t);
2399 }
2400 }
2401
2402 /* Check everything is set */
2403 if (priority == -1) {
2404 fatalf("parse_wccp2_service_info: service %d: no priority defined (valid: 0..255)!\n", service_id);
2405 }
2406
2407 if (protocol == -1) {
2408 fatalf("parse_wccp2_service_info: service %d: no protocol defined (valid: tcp or udp)!\n", service_id);
2409 }
2410
2411 if (!(flags & WCCP2_SERVICE_PORTS_DEFINED)) {
2412 fatalf("parse_wccp2_service_info: service %d: no ports defined!\n", service_id);
2413 }
2414
2415 /* rightio! now we can update */
2416 wccp2_update_service(srv, WCCP2_SERVICE_DYNAMIC, service_id, priority,
2417 protocol, flags, portlist);
2418
2419 /* Done! */
2420}
2421
2422void
2423dump_wccp2_service_info(StoreEntry * e, const char *label, void *)
2424{
2425 struct wccp2_service_list_t *srv;
2426 int flags;
2428
2429 while (srv != nullptr) {
2430 debugs(80, 3, "dump_wccp2_service_info: id " << srv->info.service_id << " (type " << srv->info.service << ")");
2431
2432 /* We don't need to spit out information for standard services */
2433
2434 if (srv->info.service == WCCP2_SERVICE_STANDARD) {
2435 debugs(80, 3, "dump_wccp2_service_info: id " << srv->info.service_id << ": standard service, not dumping info");
2436
2437 /* XXX eww */
2438 srv = srv->next;
2439 continue;
2440 }
2441
2442 storeAppendPrintf(e, "%s %d", label, srv->info.service_id);
2443
2444 /* priority */
2445 storeAppendPrintf(e, " priority=%d", srv->info.service_priority);
2446
2447 /* flags */
2448 flags = ntohl(srv->info.service_flags);
2449
2450 bool comma = false;
2451 if (flags != 0) {
2452 storeAppendPrintf(e, " flags=");
2453
2454 if (flags & WCCP2_SERVICE_SRC_IP_HASH) {
2455 storeAppendPrintf(e, "src_ip_hash");
2456 comma = true;
2457 }
2458
2459 if (flags & WCCP2_SERVICE_DST_IP_HASH) {
2460 storeAppendPrintf(e, "%sdst_ip_hash", comma ? "," : "");
2461 comma = true;
2462 }
2463
2464 if (flags & WCCP2_SERVICE_SRC_PORT_HASH) {
2465 storeAppendPrintf(e, "%ssource_port_hash", comma ? "," : "");
2466 comma = true;
2467 }
2468
2469 if (flags & WCCP2_SERVICE_DST_PORT_HASH) {
2470 storeAppendPrintf(e, "%sdst_port_hash", comma ? "," : "");
2471 comma = true;
2472 }
2473
2474 if (flags & WCCP2_SERVICE_PORTS_DEFINED) {
2475 storeAppendPrintf(e, "%sports_defined", comma ? "," : "");
2476 comma = true;
2477 }
2478
2479 if (flags & WCCP2_SERVICE_PORTS_SOURCE) {
2480 storeAppendPrintf(e, "%sports_source", comma ? "," : "");
2481 comma = true;
2482 }
2483
2484 if (flags & WCCP2_SERVICE_SRC_IP_ALT_HASH) {
2485 storeAppendPrintf(e, "%ssrc_ip_alt_hash", comma ? "," : "");
2486 comma = true;
2487 }
2488
2489 if (flags & WCCP2_SERVICE_DST_IP_ALT_HASH) {
2490 storeAppendPrintf(e, "%ssrc_ip_alt_hash", comma ? "," : "");
2491 comma = true;
2492 }
2493
2494 if (flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH) {
2495 storeAppendPrintf(e, "%ssrc_port_alt_hash", comma ? "," : "");
2496 comma = true;
2497 }
2498
2499 if (flags & WCCP2_SERVICE_DST_PORT_ALT_HASH) {
2500 storeAppendPrintf(e, "%sdst_port_alt_hash", comma ? "," : "");
2501 //comma = true; // uncomment if more options added
2502 }
2503 }
2504
2505 /* ports */
2506 comma = false;
2507
2508 if (srv->info.port0 != 0) {
2509 storeAppendPrintf(e, " ports=%d", ntohs(srv->info.port0));
2510 comma = true;
2511 }
2512
2513 if (srv->info.port1 != 0) {
2514 storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port1));
2515 comma = true;
2516 }
2517
2518 if (srv->info.port2 != 0) {
2519 storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port2));
2520 comma = true;
2521 }
2522
2523 if (srv->info.port3 != 0) {
2524 storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port3));
2525 comma = true;
2526 }
2527
2528 if (srv->info.port4 != 0) {
2529 storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port4));
2530 comma = true;
2531 }
2532
2533 if (srv->info.port5 != 0) {
2534 storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port5));
2535 comma = true;
2536 }
2537
2538 if (srv->info.port6 != 0) {
2539 storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port6));
2540 comma = true;
2541 }
2542
2543 if (srv->info.port7 != 0) {
2544 storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port7));
2545 // comma = true; // uncomment if more options are added
2546 }
2547
2548 /* protocol */
2549 storeAppendPrintf(e, " protocol=%s", (srv->info.service_protocol == IPPROTO_TCP) ? "tcp" : "udp");
2550
2551 storeAppendPrintf(e, "\n");
2552
2553 srv = srv->next;
2554 }
2555}
2556
2557/* Sort the cache list by doing a "selection sort" by IP address */
2558static void
2560{
2561 struct wccp2_cache_list_t tmp;
2562 struct wccp2_cache_list_t *this_item;
2563 struct wccp2_cache_list_t *find_item;
2564 struct wccp2_cache_list_t *next_lowest;
2565
2566 /* Go through each position in the list one at a time */
2567 for (this_item = head; this_item->next; this_item = this_item->next) {
2568 /* Find the item with the lowest IP */
2569 next_lowest = this_item;
2570
2571 for (find_item = this_item; find_item->next; find_item = find_item->next) {
2572 if (find_item->cache_ip.s_addr < next_lowest->cache_ip.s_addr) {
2573 next_lowest = find_item;
2574 }
2575 }
2576 /* Swap if we need to */
2577 if (next_lowest != this_item) {
2578 /* First make a copy of the current item */
2579 memcpy(&tmp, this_item, sizeof(struct wccp2_cache_list_t));
2580
2581 /* Next update the pointers to maintain the linked list */
2582 tmp.next = next_lowest->next;
2583 next_lowest->next = this_item->next;
2584
2585 /* Finally copy the updated items to their correct location */
2586 memcpy(this_item, next_lowest, sizeof(struct wccp2_cache_list_t));
2587 memcpy(next_lowest, &tmp, sizeof(struct wccp2_cache_list_t));
2588 }
2589 }
2590}
2591
2592void
2595
2596#endif /* USE_WCCPv2 */
2597
#define COMM_NONBLOCKING
Definition Connection.h:46
#define Here()
source code location of the caller
Definition Here.h:15
int GetInteger(void)
Definition Parsing.cc:148
int xatoi(const char *token)
Definition Parsing.cc:44
#define DefineRunnerRegistrator(ClassName)
class SquidConfig Config
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
#define Must3(condition, description, location)
void error(char *format,...)
squidaio_request_t * head
Definition aiops.cc:129
#define assert(EX)
Definition assert.h:17
void self_destruct(void)
Definition cache_cf.cc:275
static char * NextToken()
Address_list * next
Definition Address.h:389
bool setIPv4()
Definition Address.cc:244
void getSockAddr(struct sockaddr_storage &addr, const int family) const
Definition Address.cc:936
bool isAnyAddr() const
Definition Address.cc:190
bool getInAddr(struct in_addr &) const
Definition Address.cc:1032
unsigned short port() const
Definition Address.cc:790
Ip::Address address
struct SquidConfig::@81 Wccp2
int forwarding_method
int assignment_method
Ip::Address router
static int store_dirs_rebuilding
the number of cache_dirs being rebuilt; TODO: move to Disks::Rebuilding
Definition Controller.h:133
an std::runtime_error with thrower location info
void startShutdown() override
Definition wccp2.cc:1120
void startReconfigure() override
Definition wccp2.cc:1118
void useConfig() override
Definition wccp2.cc:1117
void syncConfig() override
Definition wccp2.cc:1119
void PF(int, void *)
Definition forward.h:18
int comm_udp_sendto(int fd, const Ip::Address &to_addr, const void *buf, int len)
Definition comm.cc:911
void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note)
Definition comm.cc:259
int comm_udp_recvfrom(int fd, void *buf, size_t len, int flags, Ip::Address &from)
Definition comm.cc:128
#define comm_close(x)
Definition comm.h:36
#define DBG_IMPORTANT
Definition Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define DBG_CRITICAL
Definition Stream.h:37
#define COMM_SELECT_READ
Definition defines.h:24
int eventFind(EVH *func, void *arg)
Definition event.cc:145
void eventDelete(EVH *func, void *arg)
Definition event.cc:127
void eventAdd(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata)
Definition event.cc:107
void EVH(void *)
Definition event.h:18
void fatal(const char *message)
Definition fatal.cc:28
void fatalf(const char *fmt,...)
Definition fatal.cc:68
SQUIDCEXTERN void SquidMD5Init(struct SquidMD5Context *context)
Definition md5.c:73
#define SQUID_MD5_DIGEST_LENGTH
Definition md5.h:66
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.
#define xfree
static struct tok * buckets[HASHSIZE]
Definition parse.c:219
ssize_t xsend(int socketFd, const void *buf, size_t bufLength, int flags)
POSIX send(2) equivalent.
Definition socket.h:110
int xgetsockname(int socketFd, struct sockaddr *sa, socklen_t *saLength)
POSIX getsockname(2) equivalent.
Definition socket.h:80
int xsetsockopt(int socketFd, int level, int option, const void *value, socklen_t valueLength)
POSIX setsockopt(2) equivalent.
Definition socket.h:122
int xconnect(int socketFd, const struct sockaddr *sa, socklen_t saLength)
POSIX connect(2) equivalent.
Definition socket.h:74
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition store.cc:855
struct in_addr master_ip
Definition wccp2.cc:390
uint32_t master_number
Definition wccp2.cc:391
uint32_t num3
Definition wccp2.cc:383
uint32_t num1
Definition wccp2.cc:381
struct in_addr addr
Definition wccp2.cc:380
uint32_t num2
Definition wccp2.cc:382
struct wccp2_router_id_element_t router_id_element
Definition wccp2.cc:366
uint32_t number_caches
Definition wccp2.cc:369
struct in_addr router_address
Definition wccp2.cc:368
struct wccp2_item_header_t header
Definition wccp2.cc:364
uint32_t change_number
Definition wccp2.cc:399
struct wccp2_item_header_t header
Definition wccp2.cc:398
struct assignment_key_t assignment_key
Definition wccp2.cc:400
struct in_addr addr
Definition wccp2.cc:176
struct in_addr cache_ip
Definition wccp2.cc:409
struct wccp2_cache_list_t * next
Definition wccp2.cc:413
struct wccp2_mask_element_t mask
Definition wccp2.cc:228
uint32_t cache_view_version
Definition wccp2.cc:256
uint16_t length
Definition wccp2.cc:342
uint32_t type
Definition wccp2.cc:340
uint16_t version
Definition wccp2.cc:341
char data[WCCP_RESPONSE_SIZE]
Definition wccp2.cc:343
uint16_t cache_identity_length
Definition wccp2.cc:192
struct wccp2_cache_identity_info_t cache_identity
Definition wccp2.cc:194
uint16_t cache_identity_type
Definition wccp2.cc:191
uint16_t length
Definition wccp2.cc:61
uint16_t type
Definition wccp2.cc:60
uint16_t dest_port_mask
Definition wccp2.cc:206
uint16_t source_port_mask
Definition wccp2.cc:205
uint32_t number_values
Definition wccp2.cc:207
uint32_t dest_ip_mask
Definition wccp2.cc:204
uint32_t source_ip_mask
Definition wccp2.cc:203
struct wccp2_cache_mask_identity_info_t cache_identity
Definition wccp2.cc:242
uint16_t cache_identity_length
Definition wccp2.cc:240
struct in_addr router_address
Definition wccp2.cc:352
struct in_addr router_address
Definition wccp2.cc:274
struct wccp2_router_id_element_t * info
Definition wccp2.cc:419
uint32_t member_change
Definition wccp2.cc:424
struct in_addr local_ip
Definition wccp2.cc:421
struct wccp2_router_list_t * next
Definition wccp2.cc:429
uint32_t num_caches
Definition wccp2.cc:425
struct wccp2_cache_list_t cache_list_head
Definition wccp2.cc:427
struct in_addr router_sendto_address
Definition wccp2.cc:423
uint8_t security_implementation[WCCP2_MD5_SECURITY_LEN]
Definition wccp2.cc:121
uint16_t security_length
Definition wccp2.cc:119
uint16_t security_type
Definition wccp2.cc:118
uint32_t security_option
Definition wccp2.cc:120
uint32_t security_option
Definition wccp2.cc:104
uint16_t security_type
Definition wccp2.cc:102
uint16_t security_length
Definition wccp2.cc:103
uint8_t service_priority
Definition wccp2.cc:134
uint16_t service_type
Definition wccp2.cc:130
uint16_t service_length
Definition wccp2.cc:131
uint32_t service_flags
Definition wccp2.cc:136
uint8_t service_protocol
Definition wccp2.cc:135
size_t wccp_packet_size
Definition wccp2.cc:450
struct wccp2_service_info_t info
Definition wccp2.cc:437
struct wccp2_router_list_t router_list_head
Definition wccp2.cc:440
uint32_t change_num
Definition wccp2.cc:442
char wccp_password[WCCP2_PASSWORD_LEN]
Definition wccp2.cc:453
uint32_t num_routers
Definition wccp2.cc:438
uint32_t wccp2_security_type
Definition wccp2.cc:454
struct wccp2_service_list_t * next
Definition wccp2.cc:452
struct wccp2_service_info_t * service_info
Definition wccp2.cc:448
struct wccp2_security_md5_t * security_info
Definition wccp2.cc:446
char * wccp2_identity_info_ptr
Definition wccp2.cc:444
char wccp_packet[WCCP_RESPONSE_SIZE]
Definition wccp2.cc:449
uint16_t dest_port_value
Definition wccp2.cc:329
uint32_t dest_ip_value
Definition wccp2.cc:327
uint32_t source_ip_value
Definition wccp2.cc:326
uint16_t source_port_value
Definition wccp2.cc:328
struct in_addr cache_ip
Definition wccp2.cc:331
int unsigned int
Definition stub_fd.cc:19
bool IamPrimaryProcess()
Definition tools.cc:709
int socklen_t
Definition types.h:137
#define WCCP2_ASSIGNMENT_METHOD_MASK
Definition wccp2.cc:317
static struct wccp2_cache_view_header_t wccp2_cache_view_header
Definition wccp2.cc:259
void parse_wccp2_service(void *)
Definition wccp2.cc:2163
#define WCCP2_SERVICE_SRC_IP_ALT_HASH
Definition wccp2.cc:160
static char wccp2_update_md5_security(char *password, char *ptr, char *packet, int len)
Definition wccp2.cc:552
#define WCCP2_SERVICE_DST_PORT_ALT_HASH
Definition wccp2.cc:163
void parse_wccp2_method(int *method)
Definition wccp2.cc:2067
static EVH wccp2AssignBuckets
Definition wccp2.cc:39
static void wccp2InitServices(void)
Definition wccp2.cc:475
static struct wccp2_message_header_t wccp2_here_i_am_header
Definition wccp2.cc:88
#define WCCP2_REDIRECT_ASSIGNMENT
Definition wccp2.cc:71
void free_wccp2_amethod(int *)
Definition wccp2.cc:2154
#define WCCP2_PASSWORD_LEN
Definition wccp2.cc:51
static PF wccp2HandleUdp
Definition wccp2.cc:37
void free_wccp2_service_info(void *)
Definition wccp2.cc:2593
#define WCCP2_ROUTER_ID_INFO
Definition wccp2.cc:67
#define WCCP2_SERVICE_PORTS_DEFINED
Definition wccp2.cc:158
#define WCCP2_SERVICE_DST_IP_HASH
Definition wccp2.cc:155
static struct wccp2_capability_element_t wccp2_capability_element
Definition wccp2.cc:300
#define WCCP2_I_SEE_YOU
Definition wccp2.cc:92
#define WCCP2_METHOD_L2
Definition wccp2.cc:311
static void wccp2SortCacheList(struct wccp2_cache_list_t *head)
Definition wccp2.cc:2559
#define WCCP2_NO_SECURITY
Definition wccp2.cc:108
#define WCCP2_MD5_SECURITY
Definition wccp2.cc:109
#define WCCP2_MASK_ASSIGNMENT_DATA
Definition wccp2.cc:217
#define WCCP2_SERVICE_DYNAMIC
Definition wccp2.cc:148
int check_null_wccp2_service(void *)
Definition wccp2.cc:2243
static struct wccp2_capability_info_header_t wccp2_capability_info_header
Definition wccp2.cc:290
#define WCCP2_PACKET_RETURN_METHOD_GRE
Definition wccp2.cc:319
void dump_wccp2_amethod(StoreEntry *e, const char *label, int v)
Definition wccp2.cc:2138
#define WCCP2_CAPABILITY_FORWARDING_METHOD
Definition wccp2.cc:303
static void wccp2ConnectionClose(void)
Definition wccp2.cc:1044
static int theWccp2Connection
Definition wccp2.cc:34
#define WCCP2_CAPABILITY_RETURN_METHOD
Definition wccp2.cc:305
void dump_wccp2_method(StoreEntry *e, const char *label, int v)
Definition wccp2.cc:2090
static int wccp2_connected
Definition wccp2.cc:35
#define WCCP2_SERVICE_STANDARD
Definition wccp2.cc:147
#define WCCP2_FORWARDING_METHOD_GRE
Definition wccp2.cc:313
static EVH wccp2HereIam
Definition wccp2.cc:38
#define WCCP2_REDIRECT_ASSIGN
Definition wccp2.cc:93
static int wccp2_numrouters
Definition wccp2.cc:432
static void parse_wccp2_service_ports(char *options, int portlist[])
Definition wccp2.cc:2308
void parse_wccp2_service_info(void *)
Definition wccp2.cc:2343
#define WCCP2_METHOD_GRE
Definition wccp2.cc:310
#define WCCP2_CAPABILITY_INFO
Definition wccp2.cc:73
#define WCCP2_SERVICE_INFO
Definition wccp2.cc:66
#define WCCP2_CAPABILITY_ASSIGNMENT_METHOD
Definition wccp2.cc:304
#define WCCP_BUCKETS
Definition wccp2.cc:32
#define WCCP_PORT
Definition wccp2.cc:30
#define WCCP2_SERVICE_PORTS_SOURCE
Definition wccp2.cc:159
static void wccp2Init(void)
Definition wccp2.cc:654
#define WCCP2_RTR_VIEW_INFO
Definition wccp2.cc:69
int empty_portlist[WCCP2_NUMPORTS]
Definition wccp2.cc:459
static size_t CheckFieldDataLength(const FieldHeader *header, const size_t dataLength, const void *areaStart, const size_t areaSize, const char *error)
Definition wccp2.cc:1158
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:481
#define WCCP2_WC_ID_INFO
Definition wccp2.cc:68
void dump_wccp2_service_info(StoreEntry *e, const char *label, void *)
Definition wccp2.cc:2423
static int parse_wccp2_service_flags(char *flags)
Definition wccp2.cc:2265
#define WCCP2_SERVICE_SRC_IP_HASH
Definition wccp2.cc:154
#define WCCP2_VERSION
Definition wccp2.cc:84
static struct wccp2_service_list_t * wccp2_get_service_by_id(int service, int service_id)
Definition wccp2.cc:529
#define WCCP_RESPONSE_SIZE
Definition wccp2.cc:31
static struct wccp2_identity_info_t wccp2_identity_info
Definition wccp2.cc:197
static void wccp2ConnectionOpen(void)
Definition wccp2.cc:953
static struct wccp2_service_list_t * wccp2_service_list_head
Definition wccp2.cc:457
#define WCCP2_SERVICE_DST_PORT_HASH
Definition wccp2.cc:157
static struct wccp2_i_see_you_t wccp2_i_see_you
Definition wccp2.cc:346
#define WCCP2_ASSIGN_MAP
Definition wccp2.cc:75
#define WCCP2_HERE_I_AM
Definition wccp2.cc:91
#define WCCP2_SERVICE_SRC_PORT_HASH
Definition wccp2.cc:156
#define WCCP2_NUMPORTS
Definition wccp2.cc:50
#define WCCP2_MD5_SECURITY_LEN
Definition wccp2.cc:47
static struct wccp2_mask_identity_info_t wccp2_mask_identity_info
Definition wccp2.cc:245
#define WCCP2_ASSIGNMENT_METHOD_HASH
Definition wccp2.cc:316
#define WCCP2_MASK_ASSIGNMENT
Definition wccp2.cc:44
#define WCCP2_ALT_ASSIGNMENT
Definition wccp2.cc:74
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:502
void free_wccp2_service(void *)
Definition wccp2.cc:2239
static void CheckSectionLength(const void *sectionStart, const size_t sectionLength, const void *wholeStart, const size_t wholeSize, const char *error)
Definition wccp2.cc:1131
#define WCCP2_SERVICE_DST_IP_ALT_HASH
Definition wccp2.cc:161
void free_wccp2_method(int *)
Definition wccp2.cc:2106
static struct wccp2_cache_view_info_t wccp2_cache_view_info
Definition wccp2.cc:268
static char wccp2_check_security(struct wccp2_service_list_t *srv, char *security, char *packet, int len)
Definition wccp2.cc:605
#define WCCP2_WC_VIEW_INFO
Definition wccp2.cc:70
#define WCCP2_SERVICE_SRC_PORT_ALT_HASH
Definition wccp2.cc:162
#define WCCP2_SECURITY_INFO
Definition wccp2.cc:65
void dump_wccp2_service(StoreEntry *e, const char *label, void *)
Definition wccp2.cc:2217
static void SetField(Field *&field, const void *fieldStart, const void *areaStart, const size_t areaSize, const char *error)
Definition wccp2.cc:1175
void parse_wccp2_amethod(int *method)
Definition wccp2.cc:2115
void * xcalloc(size_t n, size_t sz)
Definition xalloc.cc:71
#define safe_free(x)
Definition xalloc.h:73
const char * xstrerr(int error)
Definition xstrerror.cc:83
char * xstrncpy(char *dst, const char *src, size_t n)
Definition xstring.cc:37