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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors