wccp2.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
280 
287  /* dynamic length capabilities list */
288 };
289 
291 
296  uint16_t capability_type;
299 };
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 
326  uint32_t source_ip_value;
327  uint32_t dest_ip_value;
329  uint16_t dest_port_value;
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 
352  struct in_addr router_address;
353  uint32_t received_id;
354  uint32_t change_number;
355 };
356 
357 /* Router identity struct */
358 
363 
365 
367 
368  struct in_addr router_address;
369  uint32_t number_caches;
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;
391  uint32_t master_number;
392 };
393 
399  uint32_t change_number;
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 
411  int weight;
412 
414 };
415 
418 
420 
421  struct in_addr local_ip;
422 
423  struct in_addr router_sendto_address;
424  uint32_t member_change;
425  uint32_t num_caches;
426 
428 
430 };
431 
432 static int wccp2_numrouters;
433 
436 
438  uint32_t num_routers;
439 
442  uint32_t change_num;
443 
445 
447 
451 
453  char wccp_password[WCCP2_PASSWORD_LEN + 1]; /* hold the trailing C-string NUL */
455 };
456 
457 static struct wccp2_service_list_t *wccp2_service_list_head = NULL;
458 
459 int empty_portlist[WCCP2_NUMPORTS] = {0, 0, 0, 0, 0, 0, 0, 0};
460 
461 /* END WCCP V2 PROTOCL TYPES DEFINITION */
462 
463 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);
465 static void wccp2SortCacheList(struct wccp2_cache_list_t *head);
466 
467 /*
468  * The functions used during startup:
469  * wccp2Init
470  * wccp2ConnectionOpen
471  * wccp2ConnectionClose
472  */
473 
474 static void
476 {
477  debugs(80, 5, "wccp2InitServices: called");
478 }
479 
480 static 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 
501 void
502 wccp2_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 + 1);
522  strncpy(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 
528 static struct wccp2_service_list_t *
529 wccp2_get_service_by_id(int service, int service_id) {
530 
531  struct wccp2_service_list_t *p;
532 
534 
535  while (p != NULL) {
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 NULL;
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  */
551 static char
552 wccp2_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  strncpy(pwd, password, sizeof(pwd));
565  pwd[sizeof(pwd) - 1] = '\0';
566 
567  ws = (struct wccp2_security_md5_t *) ptr;
568  assert(ntohs(ws->security_type) == WCCP2_SECURITY_INFO);
569  /* Its the security part */
570 
571  if (ntohl(ws->security_option) != WCCP2_MD5_SECURITY) {
572  debugs(80, 5, "wccp2_update_md5_security: this service ain't md5'ing, abort");
573  return 0;
574  }
575 
576  /* And now its the MD5 section! */
577  /* According to the draft, the MD5 security hash is the combination of
578  * the 8-octet password (padded w/ NUL bytes) and the entire WCCP packet,
579  * including the WCCP message header. The WCCP security implementation
580  * area should be zero'ed before calculating the MD5 hash.
581  */
582  /* XXX eventually we should be able to kill md5Digest and blit it directly in */
583  memset(ws->security_implementation, 0, sizeof(ws->security_implementation));
584 
585  SquidMD5Init(&M);
586 
587  SquidMD5Update(&M, pwd, sizeof(pwd));
588 
589  SquidMD5Update(&M, packet, len);
590 
591  SquidMD5Final(md5Digest, &M);
592 
593  memcpy(ws->security_implementation, md5Digest, sizeof(md5Digest));
594 
595  /* Finished! */
596  return 1;
597 }
598 
599 /*
600  * Check the given WCCP2 packet against the given password.
601  */
602 static char
603 
604 wccp2_check_security(struct wccp2_service_list_t *srv, char *security, char *packet, int len)
605 {
606 
607  struct wccp2_security_md5_t *ws = (struct wccp2_security_md5_t *) security;
608  uint8_t md5Digest[SQUID_MD5_DIGEST_LENGTH], md5_challenge[SQUID_MD5_DIGEST_LENGTH];
609  char pwd[WCCP2_PASSWORD_LEN];
610  SquidMD5_CTX M;
611 
612  /* Make sure the security type matches what we expect */
613 
614  if (ntohl(ws->security_option) != srv->wccp2_security_type) {
615  debugs(80, DBG_IMPORTANT, "wccp2_check_security: received packet has the wrong security option");
616  return 0;
617  }
618 
620  return 1;
621  }
622 
624  debugs(80, DBG_IMPORTANT, "wccp2_check_security: invalid security option");
625  return 0;
626  }
627 
628  /* If execution makes it here then we have an MD5 security */
629 
630  /* The password field, for the MD5 hash, needs to be 8 bytes and NUL padded. */
631  memset(pwd, 0, sizeof(pwd));
632  strncpy(pwd, srv->wccp_password, sizeof(pwd));
633  pwd[sizeof(pwd) - 1] = '\0';
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  SquidMD5Update(&M, pwd, sizeof(pwd));
643 
644  SquidMD5Update(&M, packet, len);
645 
646  SquidMD5Final(md5Digest, &M);
647 
648  return (memcmp(md5Digest, md5_challenge, SQUID_MD5_DIGEST_LENGTH) == 0);
649 }
650 
651 void
653 {
654  Ip::Address_list *s;
655  char *ptr;
656  uint32_t service_flags;
657 
658  struct wccp2_service_list_t *service_list_ptr;
659 
660  struct wccp2_router_list_t *router_list_ptr;
661 
662  debugs(80, 5, "wccp2Init: Called");
663 
664  if (wccp2_connected == 1)
665  return;
666 
667  wccp2_numrouters = 0;
668 
669  /* Calculate the number of routers configured in the config file */
670  for (s = Config.Wccp2.router; s; s = s->next) {
671  if (!s->s.isAnyAddr()) {
672  /* Increment the counter */
674  }
675  }
676 
677  if (wccp2_numrouters == 0) {
678  return;
679  }
680 
681  struct wccp2_security_md5_t wccp2_security_md5;
682  memset(&wccp2_security_md5, 0, sizeof(wccp2_security_md5));
683 
684  /* Initialise the list of services */
686 
687  service_list_ptr = wccp2_service_list_head;
688 
689  while (service_list_ptr != NULL) {
690  /* Set up our list pointers */
691  router_list_ptr = &service_list_ptr->router_list_head;
692 
693  /* start the wccp header */
697  ptr = service_list_ptr->wccp_packet + sizeof(wccp2_here_i_am_header);
698 
699  /* add the security section */
700  /* XXX this is ugly */
701 
702  if (service_list_ptr->wccp2_security_type == WCCP2_MD5_SECURITY) {
703  wccp2_security_md5.security_option = htonl(WCCP2_MD5_SECURITY);
704 
705  wccp2_security_md5.security_length = htons(sizeof(struct wccp2_security_md5_t) - 4);
706  } else if (service_list_ptr->wccp2_security_type == WCCP2_NO_SECURITY) {
707  wccp2_security_md5.security_option = htonl(WCCP2_NO_SECURITY);
708  /* XXX I hate magic length numbers! */
709  wccp2_security_md5.security_length = htons(4);
710  } else {
711  fatalf("Bad WCCP2 security type\n");
712  }
713 
714  wccp2_here_i_am_header.length += ntohs(wccp2_security_md5.security_length) + 4;
716  wccp2_security_md5.security_type = htons(WCCP2_SECURITY_INFO);
717 
718  service_list_ptr->security_info = (struct wccp2_security_md5_t *) ptr;
719 
720  if (service_list_ptr->wccp2_security_type == WCCP2_MD5_SECURITY) {
721  memcpy(ptr, &wccp2_security_md5, sizeof(struct wccp2_security_md5_t));
722  ptr += sizeof(struct wccp2_security_md5_t);
723  } else {
724  /* assume NONE, and XXX I hate magic length numbers */
725  memcpy(ptr, &wccp2_security_md5, 8);
726  ptr += 8;
727  }
728 
729  /* Add the service info section */
730 
732 
734 
735  memcpy(ptr, &service_list_ptr->info, sizeof(struct wccp2_service_info_t));
736 
737  service_list_ptr->service_info = (struct wccp2_service_info_t *) ptr;
738 
739  ptr += sizeof(struct wccp2_service_info_t);
740 
741  /* Add the cache identity section */
742 
743  switch (Config.Wccp2.assignment_method) {
744 
746 
751  memset(&wccp2_identity_info.cache_identity.addr, '\0', sizeof(struct in_addr));
757 
758  memcpy(ptr, &wccp2_identity_info, sizeof(struct wccp2_identity_info_t));
759  service_list_ptr->wccp2_identity_info_ptr = ptr;
760 
761  ptr += sizeof(struct wccp2_identity_info_t);
762  break;
763 
765 
770  memset(&wccp2_mask_identity_info.cache_identity.addr, '\0', sizeof(struct in_addr));
773  service_flags = ntohl(service_list_ptr->service_info->service_flags);
774 
776 
777  if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
779  } 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)) {
781  } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
783  } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
785  } else {
786  fatalf("Unknown service hash method\n");
787  }
788 
791 
792  memcpy(ptr, &wccp2_mask_identity_info, sizeof(struct wccp2_mask_identity_info_t));
793  service_list_ptr->wccp2_identity_info_ptr = ptr;
794 
795  ptr += sizeof(struct wccp2_mask_identity_info_t);
796  break;
797 
798  default:
799  fatalf("Unknown Wccp2 assignment method\n");
800  }
801 
802  /* Add the cache view section */
804 
806 
808 
811 
813 
814  memcpy(ptr, &wccp2_cache_view_header, sizeof(wccp2_cache_view_header));
815 
816  ptr += sizeof(wccp2_cache_view_header);
817 
818  /* Add the number of routers to the packet */
819  wccp2_here_i_am_header.length += sizeof(service_list_ptr->num_routers);
820 
822 
823  service_list_ptr->num_routers = htonl(wccp2_numrouters);
824 
825  memcpy(ptr, &service_list_ptr->num_routers, sizeof(service_list_ptr->num_routers));
826 
827  ptr += sizeof(service_list_ptr->num_routers);
828 
829  /* Add each router. Keep this functionality here to make sure the received_id can be updated in the packet */
830  for (s = Config.Wccp2.router; s; s = s->next) {
831  if (!s->s.isAnyAddr()) {
832 
835 
836  /* Add a pointer to the router list for this router */
837 
838  router_list_ptr->info = (struct wccp2_router_id_element_t *) ptr;
839  s->s.getInAddr(router_list_ptr->info->router_address);
840  router_list_ptr->info->received_id = htonl(0);
841  s->s.getInAddr(router_list_ptr->router_sendto_address);
842  router_list_ptr->member_change = htonl(0);
843 
844  /* Build the next struct */
845 
846  router_list_ptr->next = (wccp2_router_list_t*) xcalloc(1, sizeof(struct wccp2_router_list_t));
847 
848  /* update the pointer */
849  router_list_ptr = router_list_ptr->next;
850  router_list_ptr->next = NULL;
851 
852  /* no need to copy memory - we've just set the values directly in the packet above */
853 
854  ptr += sizeof(struct wccp2_router_id_element_t);
855  }
856  }
857 
858  /* Add the number of caches (0) */
860 
862 
864 
866 
867  ptr += sizeof(wccp2_cache_view_info.num_caches);
868 
869  /* Add the extra capability header */
871 
873 
875 
877 
879 
880  ptr += sizeof(wccp2_capability_info_header);
881 
882  /* Add the forwarding method */
884 
886 
888 
890 
892 
893  memcpy(ptr, &wccp2_capability_element, sizeof(wccp2_capability_element));
894 
895  ptr += sizeof(wccp2_capability_element);
896 
897  /* Add the assignment method */
899 
901 
903 
905 
907 
908  memcpy(ptr, &wccp2_capability_element, sizeof(wccp2_capability_element));
909 
910  ptr += sizeof(wccp2_capability_element);
911 
912  /* Add the return method */
914 
916 
918 
920 
922 
923  memcpy(ptr, &wccp2_capability_element, sizeof(wccp2_capability_element));
924 
925  ptr += sizeof(wccp2_capability_element);
926 
927  /* Finally, fix the total length to network order, and copy to the appropriate memory blob */
929 
930  memcpy(&service_list_ptr->wccp_packet, &wccp2_here_i_am_header, sizeof(wccp2_here_i_am_header));
931 
932  service_list_ptr->wccp_packet_size = ntohs(wccp2_here_i_am_header.length) + sizeof(wccp2_here_i_am_header);
933 
934  /* Add the event if everything initialised correctly */
935  debugs(80,3,"wccp2Init: scheduled 'HERE_I_AM' message to " << wccp2_numrouters << "routers.");
936  if (wccp2_numrouters) {
937  if (!eventFind(wccp2HereIam, NULL)) {
938  eventAdd("wccp2HereIam", wccp2HereIam, NULL, 1, 1);
939  } else
940  debugs(80,3,"wccp2Init: skip duplicate 'HERE_I_AM'.");
941  }
942 
943  service_list_ptr = service_list_ptr->next;
944  }
945 }
946 
947 void
949 {
950  struct sockaddr_in router, local, null;
951  socklen_t local_len, router_len;
952 
953  struct wccp2_service_list_t *service_list_ptr;
954 
955  struct wccp2_router_list_t *router_list_ptr;
956 
957  debugs(80, 5, "wccp2ConnectionOpen: Called");
958 
959  if (wccp2_numrouters == 0 || !wccp2_service_list_head) {
960  debugs(80, 2, "WCCPv2 Disabled. No IPv4 Router(s) configured.");
961  return;
962  }
963 
964  if ( !Config.Wccp2.address.setIPv4() ) {
965  debugs(80, DBG_CRITICAL, "WCCPv2 Disabled. Local address " << Config.Wccp2.address << " is not an IPv4 address.");
966  return;
967  }
968 
971  0,
974  "WCCPv2 Socket");
975 
976  if (theWccp2Connection < 0)
977  fatal("Cannot open WCCP Port");
978 
979 #if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
980  {
981  int i = IP_PMTUDISC_DONT;
982  if (setsockopt(theWccp2Connection, SOL_IP, IP_MTU_DISCOVER, &i, sizeof i) < 0) {
983  int xerrno = errno;
984  debugs(80, 2, "WARNING: Path MTU discovery could not be disabled on FD " << theWccp2Connection << ": " << xstrerr(xerrno));
985  }
986  }
987 
988 #endif
990 
991  debugs(80, DBG_IMPORTANT, "Accepting WCCPv2 messages on port " << WCCP_PORT << ", FD " << theWccp2Connection << ".");
992  debugs(80, DBG_IMPORTANT, "Initialising all WCCPv2 lists");
993 
994  /* Initialise all routers on all services */
995  memset(&null, 0, sizeof(null));
996 
997  null.sin_family = AF_UNSPEC;
998 
999  service_list_ptr = wccp2_service_list_head;
1000 
1001  while (service_list_ptr != NULL) {
1002  for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != NULL; router_list_ptr = router_list_ptr->next) {
1003  router_len = sizeof(router);
1004  memset(&router, '\0', router_len);
1005  router.sin_family = AF_INET;
1006  router.sin_port = htons(WCCP_PORT);
1007  router.sin_addr = router_list_ptr->router_sendto_address;
1008 
1009  if (connect(theWccp2Connection, (struct sockaddr *) &router, router_len))
1010  fatal("Unable to connect WCCP out socket");
1011 
1012  local_len = sizeof(local);
1013 
1014  memset(&local, '\0', local_len);
1015 
1016  if (getsockname(theWccp2Connection, (struct sockaddr *) &local, &local_len))
1017  fatal("Unable to getsockname on WCCP out socket");
1018 
1019  router_list_ptr->local_ip = local.sin_addr;
1020 
1021  /* Disconnect the sending socket. Note: FreeBSD returns error
1022  * but disconnects anyway so we have to just assume it worked
1023  */
1024  if (wccp2_numrouters > 1) {
1025  (void)connect(theWccp2Connection, (struct sockaddr *) &null, router_len);
1026  }
1027  }
1028 
1029  service_list_ptr = service_list_ptr->next;
1030  }
1031 
1032  wccp2_connected = 1;
1033 }
1034 
1035 void
1037 {
1038 
1039  struct wccp2_service_list_t *service_list_ptr;
1040 
1041  struct wccp2_service_list_t *service_list_ptr_next;
1042 
1043  struct wccp2_router_list_t *router_list_ptr;
1044 
1045  struct wccp2_router_list_t *router_list_next;
1046 
1047  struct wccp2_cache_list_t *cache_list_ptr;
1048 
1049  struct wccp2_cache_list_t *cache_list_ptr_next;
1050 
1051  if (wccp2_connected == 0) {
1052  return;
1053  }
1054 
1055  /* TODO A shutting-down cache should generate a removal query, informing the router
1056  * (and therefore the caches in the group) that this cache is going
1057  * away and no new traffic should be forwarded to it.
1058  */
1059 
1060  if (theWccp2Connection > -1) {
1061  debugs(80, DBG_IMPORTANT, "FD " << theWccp2Connection << " Closing WCCPv2 socket");
1063  theWccp2Connection = -1;
1064  }
1065 
1066  /* free all stored router state */
1067  service_list_ptr = wccp2_service_list_head;
1068 
1069  while (service_list_ptr != NULL) {
1070  for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr != NULL; router_list_ptr = router_list_next) {
1071  for (cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr; cache_list_ptr = cache_list_ptr_next) {
1072  cache_list_ptr_next = cache_list_ptr->next;
1073 
1074  if (cache_list_ptr != &router_list_ptr->cache_list_head) {
1075  xfree(cache_list_ptr);
1076  } else {
1077 
1078  memset(cache_list_ptr, '\0', sizeof(struct wccp2_cache_list_t));
1079  }
1080  }
1081 
1082  router_list_next = router_list_ptr->next;
1083 
1084  if (router_list_ptr != &service_list_ptr->router_list_head) {
1085  xfree(router_list_ptr);
1086  } else {
1087 
1088  memset(router_list_ptr, '\0', sizeof(struct wccp2_router_list_t));
1089  }
1090  }
1091 
1092  service_list_ptr_next = service_list_ptr->next;
1093  xfree(service_list_ptr);
1094  service_list_ptr = service_list_ptr_next;
1095  }
1096 
1097  wccp2_service_list_head = NULL;
1101  wccp2_connected = 0;
1102 }
1103 
1104 /*
1105  * Functions for handling the requests.
1106  */
1107 
1108 /*
1109  * Accept the UDP packet
1110  */
1111 static void
1112 wccp2HandleUdp(int sock, void *)
1113 {
1114  struct wccp2_service_list_t *service_list_ptr;
1115 
1116  struct wccp2_router_list_t *router_list_ptr;
1117 
1118  struct wccp2_cache_list_t *cache_list_ptr;
1119 
1120  struct wccp2_cache_list_t *cache_list_ptr_next;
1121 
1122  /* These structs form the parts of the packet */
1123 
1124  struct wccp2_item_header_t *header = NULL;
1125 
1126  struct wccp2_security_none_t *security_info = NULL;
1127 
1128  struct wccp2_service_info_t *service_info = NULL;
1129 
1130  struct router_identity_info_t *router_identity_info = NULL;
1131 
1132  struct router_view_t *router_view_header = NULL;
1133 
1134  struct wccp2_cache_mask_identity_info_t *cache_mask_identity = NULL;
1135 
1136  struct cache_mask_info_t *cache_mask_info = NULL;
1137 
1138  struct wccp2_cache_identity_info_t *cache_identity = NULL;
1139 
1140  struct wccp2_capability_info_header_t *router_capability_header = NULL;
1141 
1142  struct wccp2_capability_element_t *router_capability_element;
1143 
1144  struct sockaddr_in from;
1145 
1146  struct in_addr cache_address;
1147  int len, found;
1148  short int data_length, offset;
1149  uint32_t tmp;
1150  char *ptr;
1151  int num_caches;
1152 
1153  debugs(80, 6, "wccp2HandleUdp: Called.");
1154 
1156 
1157  /* FIXME INET6 : drop conversion boundary */
1158  Ip::Address from_tmp;
1159  from_tmp.setIPv4();
1160 
1161  len = comm_udp_recvfrom(sock,
1162  &wccp2_i_see_you,
1164  0,
1165  from_tmp);
1166 
1167  if (len < 0)
1168  return;
1169 
1170  if (ntohs(wccp2_i_see_you.version) != WCCP2_VERSION)
1171  return;
1172 
1173  if (ntohl(wccp2_i_see_you.type) != WCCP2_I_SEE_YOU)
1174  return;
1175 
1176  /* FIXME INET6 : drop conversion boundary */
1177  from_tmp.getSockAddr(from);
1178 
1179  debugs(80, 3, "Incoming WCCPv2 I_SEE_YOU length " << ntohs(wccp2_i_see_you.length) << ".");
1180 
1181  /* Record the total data length */
1182  data_length = ntohs(wccp2_i_see_you.length);
1183 
1184  offset = 0;
1185 
1186  if (data_length > len) {
1187  debugs(80, DBG_IMPORTANT, "ERROR: Malformed WCCPv2 packet claiming it's bigger than received data");
1188  return;
1189  }
1190 
1191  /* Go through the data structure */
1192  while (data_length > offset) {
1193 
1194  char *data = wccp2_i_see_you.data;
1195 
1196  header = (struct wccp2_item_header_t *) &data[offset];
1197 
1198  switch (ntohs(header->type)) {
1199 
1200  case WCCP2_SECURITY_INFO:
1201 
1202  if (security_info != NULL) {
1203  debugs(80, DBG_IMPORTANT, "Duplicate security definition");
1204  return;
1205  }
1206 
1207  security_info = (struct wccp2_security_none_t *) &wccp2_i_see_you.data[offset];
1208  break;
1209 
1210  case WCCP2_SERVICE_INFO:
1211 
1212  if (service_info != NULL) {
1213  debugs(80, DBG_IMPORTANT, "Duplicate service_info definition");
1214  return;
1215  }
1216 
1217  service_info = (struct wccp2_service_info_t *) &wccp2_i_see_you.data[offset];
1218  break;
1219 
1220  case WCCP2_ROUTER_ID_INFO:
1221 
1222  if (router_identity_info != NULL) {
1223  debugs(80, DBG_IMPORTANT, "Duplicate router_identity_info definition");
1224  return;
1225  }
1226 
1227  router_identity_info = (struct router_identity_info_t *) &wccp2_i_see_you.data[offset];
1228  break;
1229 
1230  case WCCP2_RTR_VIEW_INFO:
1231 
1232  if (router_view_header != NULL) {
1233  debugs(80, DBG_IMPORTANT, "Duplicate router_view definition");
1234  return;
1235  }
1236 
1237  router_view_header = (struct router_view_t *) &wccp2_i_see_you.data[offset];
1238  break;
1239 
1240  case WCCP2_CAPABILITY_INFO:
1241 
1242  if (router_capability_header != NULL) {
1243  debugs(80, DBG_IMPORTANT, "Duplicate router_capability definition");
1244  return;
1245  }
1246 
1247  router_capability_header = (struct wccp2_capability_info_header_t *) &wccp2_i_see_you.data[offset];
1248  break;
1249 
1250  /* Nothing to do for the types below */
1251 
1252  case WCCP2_ASSIGN_MAP:
1254  break;
1255 
1256  default:
1257  debugs(80, DBG_IMPORTANT, "Unknown record type in WCCPv2 Packet (" << ntohs(header->type) << ").");
1258  }
1259 
1260  offset += sizeof(struct wccp2_item_header_t);
1261  offset += ntohs(header->length);
1262 
1263  if (offset > data_length) {
1264  debugs(80, DBG_IMPORTANT, "Error: WCCPv2 packet tried to tell us there is data beyond the end of the packet");
1265  return;
1266  }
1267  }
1268 
1269  if ((security_info == NULL) || (service_info == NULL) || (router_identity_info == NULL) || (router_view_header == NULL)) {
1270  debugs(80, DBG_IMPORTANT, "Incomplete WCCPv2 Packet");
1271  return;
1272  }
1273 
1274  debugs(80, 5, "Complete packet received");
1275 
1276  /* Check that the service in the packet is configured on this router */
1277  service_list_ptr = wccp2_service_list_head;
1278 
1279  while (service_list_ptr != NULL) {
1280  if (service_info->service_id == service_list_ptr->service_info->service_id) {
1281  break;
1282  }
1283 
1284  service_list_ptr = service_list_ptr->next;
1285  }
1286 
1287  if (service_list_ptr == NULL) {
1288  debugs(80, DBG_IMPORTANT, "WCCPv2 Unknown service received from router (" << service_info->service_id << ")");
1289  return;
1290  }
1291 
1292  if (ntohl(security_info->security_option) != ntohl(service_list_ptr->security_info->security_option)) {
1293  debugs(80, DBG_IMPORTANT, "Invalid security option in WCCPv2 Packet (" << ntohl(security_info->security_option) << " vs " << ntohl(service_list_ptr->security_info->security_option) << ").");
1294  return;
1295  }
1296 
1297  if (!wccp2_check_security(service_list_ptr, (char *) security_info, (char *) &wccp2_i_see_you, len)) {
1298  debugs(80, DBG_IMPORTANT, "Received WCCPv2 Packet failed authentication");
1299  return;
1300  }
1301 
1302  /* Check that the router address is configured on this router */
1303  for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != NULL; router_list_ptr = router_list_ptr->next) {
1304  if (router_list_ptr->router_sendto_address.s_addr == from.sin_addr.s_addr)
1305  break;
1306  }
1307 
1308  if (router_list_ptr->next == NULL) {
1309  debugs(80, DBG_IMPORTANT, "WCCPv2 Packet received from unknown router");
1310  return;
1311  }
1312 
1313  /* Set the router id */
1314  router_list_ptr->info->router_address = router_identity_info->router_id_element.router_address;
1315 
1316  /* Increment the received id in the packet */
1317  if (ntohl(router_list_ptr->info->received_id) != ntohl(router_identity_info->router_id_element.received_id)) {
1318  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) << ".");
1319  router_list_ptr->info->received_id = router_identity_info->router_id_element.received_id;
1320  }
1321 
1322  /* TODO: check return/forwarding methods */
1323  if (router_capability_header == NULL) {
1325  debugs(80, DBG_IMPORTANT, "wccp2HandleUdp: fatal error - A WCCP router does not support the forwarding method specified, only GRE supported");
1327  return;
1328  }
1329  } else {
1330 
1331  char *end = ((char *) router_capability_header) + sizeof(*router_capability_header) + ntohs(router_capability_header->capability_info_length) - sizeof(struct wccp2_capability_info_header_t);
1332 
1333  router_capability_element = (struct wccp2_capability_element_t *) (((char *) router_capability_header) + sizeof(*router_capability_header));
1334 
1335  while ((char *) router_capability_element <= end) {
1336 
1337  switch (ntohs(router_capability_element->capability_type)) {
1338 
1340 
1341  if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.forwarding_method)) {
1342  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);
1344  return;
1345  }
1346 
1347  break;
1348 
1350 
1351  if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.assignment_method)) {
1352  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);
1354  return;
1355  }
1356 
1357  break;
1358 
1360 
1361  if (!(ntohl(router_capability_element->capability_value) & Config.Wccp2.return_method)) {
1362  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);
1364  return;
1365  }
1366 
1367  break;
1368 
1369  case 4:
1370  case 5:
1371  break; // ignore silently for now
1372 
1373  default:
1374  debugs(80, DBG_IMPORTANT, "Unknown capability type in WCCPv2 Packet (" << ntohs(router_capability_element->capability_type) << ").");
1375  }
1376 
1377  router_capability_element = (struct wccp2_capability_element_t *) (((char *) router_capability_element) + sizeof(struct wccp2_item_header_t) + ntohs(router_capability_element->capability_length));
1378  }
1379  }
1380 
1381  debugs(80, 5, "Cleaning out cache list");
1382  /* clean out the old cache list */
1383 
1384  for (cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr; cache_list_ptr = cache_list_ptr_next) {
1385  cache_list_ptr_next = cache_list_ptr->next;
1386 
1387  if (cache_list_ptr != &router_list_ptr->cache_list_head) {
1388  xfree(cache_list_ptr);
1389  }
1390  }
1391 
1392  router_list_ptr->num_caches = htonl(0);
1393  num_caches = 0;
1394 
1395  /* Check to see if we're the master cache and update the cache list */
1396  found = 0;
1397  service_list_ptr->lowest_ip = 1;
1398  cache_list_ptr = &router_list_ptr->cache_list_head;
1399 
1400  /* to find the list of caches, we start at the end of the router view header */
1401 
1402  ptr = (char *) (router_view_header) + sizeof(struct router_view_t);
1403 
1404  /* Then we read the number of routers */
1405  memcpy(&tmp, ptr, sizeof(tmp));
1406 
1407  /* skip the number plus all the ip's */
1408 
1409  ptr += sizeof(tmp) + (ntohl(tmp) * sizeof(struct in_addr));
1410 
1411  /* Then read the number of caches */
1412  memcpy(&tmp, ptr, sizeof(tmp));
1413  ptr += sizeof(tmp);
1414 
1415  if (ntohl(tmp) != 0) {
1416  /* search through the list of received-from ip addresses */
1417 
1418  for (num_caches = 0; num_caches < (int) ntohl(tmp); ++num_caches) {
1419  /* Get a copy of the ip */
1420  memset(&cache_address, 0, sizeof(cache_address)); // Make GCC happy
1421 
1422  switch (Config.Wccp2.assignment_method) {
1423 
1425 
1426  cache_identity = (struct wccp2_cache_identity_info_t *) ptr;
1427 
1428  ptr += sizeof(struct wccp2_cache_identity_info_t);
1429 
1430  memcpy(&cache_address, &cache_identity->addr, sizeof(struct in_addr));
1431 
1432  cache_list_ptr->weight = ntohs(cache_identity->weight);
1433  break;
1434 
1436 
1437  cache_mask_info = (struct cache_mask_info_t *) ptr;
1438 
1439  /* The mask assignment has an undocumented variable length entry here */
1440 
1441  if (ntohl(cache_mask_info->num1) == 3) {
1442 
1443  cache_mask_identity = (struct wccp2_cache_mask_identity_info_t *) ptr;
1444 
1445  ptr += sizeof(struct wccp2_cache_mask_identity_info_t);
1446 
1447  memcpy(&cache_address, &cache_mask_identity->addr, sizeof(struct in_addr));
1448  } else {
1449 
1450  ptr += sizeof(struct cache_mask_info_t);
1451 
1452  memcpy(&cache_address, &cache_mask_info->addr, sizeof(struct in_addr));
1453  }
1454 
1455  cache_list_ptr->weight = 0;
1456  break;
1457 
1458  default:
1459  fatalf("Unknown Wccp2 assignment method\n");
1460  }
1461 
1462  /* Update the cache list */
1463  cache_list_ptr->cache_ip = cache_address;
1464 
1465  cache_list_ptr->next = (wccp2_cache_list_t*) xcalloc(1, sizeof(struct wccp2_cache_list_t));
1466 
1467  cache_list_ptr = cache_list_ptr->next;
1468 
1469  cache_list_ptr->next = NULL;
1470 
1471  debugs (80, 5, "checking cache list: (" << std::hex << cache_address.s_addr << ":" << router_list_ptr->local_ip.s_addr << ")");
1472 
1473  /* Check to see if it's the master, or us */
1474 
1475  if (cache_address.s_addr == router_list_ptr->local_ip.s_addr) {
1476  found = 1;
1477  }
1478 
1479  if (cache_address.s_addr < router_list_ptr->local_ip.s_addr) {
1480  service_list_ptr->lowest_ip = 0;
1481  }
1482  }
1483  } else {
1484  debugs(80, 5, "Adding ourselves as the only cache");
1485 
1486  /* Update the cache list */
1487  cache_list_ptr->cache_ip = router_list_ptr->local_ip;
1488 
1489  cache_list_ptr->next = (wccp2_cache_list_t*) xcalloc(1, sizeof(struct wccp2_cache_list_t));
1490  cache_list_ptr = cache_list_ptr->next;
1491  cache_list_ptr->next = NULL;
1492 
1493  service_list_ptr->lowest_ip = 1;
1494  found = 1;
1495  num_caches = 1;
1496  }
1497 
1498  wccp2SortCacheList(&router_list_ptr->cache_list_head);
1499 
1500  router_list_ptr->num_caches = htonl(num_caches);
1501 
1502  if ((found == 1) && (service_list_ptr->lowest_ip == 1)) {
1503  if (ntohl(router_view_header->change_number) != router_list_ptr->member_change) {
1504  debugs(80, 4, "Change detected - queueing up new assignment");
1505  router_list_ptr->member_change = ntohl(router_view_header->change_number);
1507  eventAdd("wccp2AssignBuckets", wccp2AssignBuckets, NULL, 15.0, 1);
1508  } else {
1509  debugs(80, 5, "Change not detected (" << ntohl(router_view_header->change_number) << " = " << router_list_ptr->member_change << ")");
1510  }
1511  } else {
1513  debugs(80, 5, "I am not the lowest ip cache - not assigning buckets");
1514  }
1515 }
1516 
1517 static void
1519 {
1520  struct wccp2_service_list_t *service_list_ptr;
1521 
1522  struct wccp2_router_list_t *router_list_ptr;
1523 
1524  struct wccp2_identity_info_t *wccp2_identity_info_ptr;
1525 
1526  struct wccp2_mask_identity_info_t *wccp2_mask_identity_info_ptr;
1527 
1528  Ip::Address router;
1529 
1530  debugs(80, 6, "wccp2HereIam: Called");
1531 
1532  if (wccp2_connected == 0) {
1533  debugs(80, DBG_IMPORTANT, "wccp2HereIam: wccp2 socket closed. Shutting down WCCP2");
1534  return;
1535  }
1536 
1537  /* Wait if store dirs are rebuilding */
1539  eventAdd("wccp2HereIam", wccp2HereIam, NULL, 1.0, 1);
1540  return;
1541  }
1542 
1543  router.port(WCCP_PORT);
1544 
1545  /* for each router on each service send a packet */
1546  service_list_ptr = wccp2_service_list_head;
1547 
1548  while (service_list_ptr != NULL) {
1549  debugs(80, 5, "wccp2HereIam: sending to service id " << service_list_ptr->info.service_id);
1550 
1551  for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != NULL; router_list_ptr = router_list_ptr->next) {
1552  router = router_list_ptr->router_sendto_address;
1553 
1554  /* Set the cache id (ip) */
1555 
1556  switch (Config.Wccp2.assignment_method) {
1557 
1559 
1560  wccp2_identity_info_ptr = (struct wccp2_identity_info_t *) service_list_ptr->wccp2_identity_info_ptr;
1561  wccp2_identity_info_ptr->cache_identity.addr = router_list_ptr->local_ip;
1562  break;
1563 
1565 
1566  wccp2_mask_identity_info_ptr = (struct wccp2_mask_identity_info_t *) service_list_ptr->wccp2_identity_info_ptr;
1567  wccp2_mask_identity_info_ptr->cache_identity.addr = router_list_ptr->local_ip;
1568  break;
1569 
1570  default:
1571  fatalf("Unknown Wccp2 assignment method\n");
1572  }
1573 
1574  /* Security update, if needed */
1575 
1576  if (service_list_ptr->wccp2_security_type == WCCP2_MD5_SECURITY) {
1577  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);
1578  }
1579 
1580  debugs(80, 3, "Sending HereIam packet size " << service_list_ptr->wccp_packet_size);
1581  /* Send the packet */
1582 
1583  if (wccp2_numrouters > 1) {
1585  router,
1586  &service_list_ptr->wccp_packet,
1587  service_list_ptr->wccp_packet_size);
1588  } else {
1589  if (send(theWccp2Connection, &service_list_ptr->wccp_packet, service_list_ptr->wccp_packet_size, 0) < static_cast<int>(service_list_ptr->wccp_packet_size)) {
1590  int xerrno = errno;
1591  debugs(80, 2, "ERROR: failed to send WCCPv2 HERE_I_AM packet to " << router << " : " << xstrerr(xerrno));
1592  }
1593  }
1594  }
1595 
1596  service_list_ptr = service_list_ptr->next;
1597  }
1598 
1599  eventAdd("wccp2HereIam", wccp2HereIam, NULL, 10.0, 1);
1600 }
1601 
1602 static void
1604 {
1605  struct wccp2_service_list_t *service_list_ptr;
1606 
1607  struct wccp2_router_list_t *router_list_ptr;
1608 
1609  struct wccp2_cache_list_t *cache_list_ptr;
1610  char wccp_packet[WCCP_RESPONSE_SIZE];
1611  short int offset, saved_offset, assignment_offset, alt_assignment_offset;
1612 
1613  struct sockaddr_in router;
1614  int router_len;
1615  int bucket_counter;
1616  uint32_t service_flags;
1617  unsigned short port = WCCP_PORT;
1618 
1619  /* Packet segments */
1620 
1621  struct wccp2_message_header_t *main_header;
1622 
1623  struct wccp2_security_md5_t *security = NULL;
1624  /* service from service struct */
1625 
1626  struct wccp2_item_header_t *assignment_header;
1627 
1628  struct wccp2_item_header_t *alt_assignment_type_header = NULL;
1629 
1630  struct assignment_key_t *assignment_key;
1631  /* number of routers */
1632 
1633  struct wccp2_router_assign_element_t *router_assign;
1634  /* number of caches */
1635 
1636  struct in_addr *cache_address;
1637  /* Alternative assignement mask/values */
1638  int num_maskval;
1639 
1640  struct wccp2_mask_element_t *mask_element;
1641 
1642  struct wccp2_value_element_t *value_element;
1643  int valuecounter, value;
1644  char *buckets;
1645 
1646  assignment_offset = alt_assignment_offset = 0;
1647 
1648  router_len = sizeof(router);
1649  memset(&router, '\0', router_len);
1650  router.sin_family = AF_INET;
1651  router.sin_port = htons(port);
1652 
1653  /* Start main header - fill in length later */
1654  offset = 0;
1655 
1656  main_header = (struct wccp2_message_header_t *) &wccp_packet[offset];
1657  main_header->type = htonl(WCCP2_REDIRECT_ASSIGN);
1658  main_header->version = htons(WCCP2_VERSION);
1659 
1660  debugs(80, 2, "Running wccp2AssignBuckets");
1661  service_list_ptr = wccp2_service_list_head;
1662 
1663  while (service_list_ptr != NULL) {
1664  /* If we're not the lowest, we don't need to worry */
1665 
1666  if (service_list_ptr->lowest_ip == 0) {
1667  /* XXX eww */
1668  service_list_ptr = service_list_ptr->next;
1669  continue;
1670  }
1671 
1672  /* reset the offset */
1673 
1674  offset = sizeof(struct wccp2_message_header_t);
1675 
1676  /* build packet header from hereIam packet */
1677  /* Security info */
1678  /* XXX this should be made more generic! */
1679  /* XXX and I hate magic numbers! */
1680  switch (service_list_ptr->wccp2_security_type) {
1681 
1682  case WCCP2_NO_SECURITY:
1683 
1684  security = (struct wccp2_security_md5_t *) &wccp_packet[offset];
1685  memcpy(security, service_list_ptr->security_info, 8);
1686  offset += 8;
1687  break;
1688 
1689  case WCCP2_MD5_SECURITY:
1690 
1691  security = (struct wccp2_security_md5_t *) &wccp_packet[offset];
1692 
1693  memcpy(security, service_list_ptr->security_info, sizeof(struct wccp2_security_md5_t));
1694 
1695  offset += sizeof(struct wccp2_security_md5_t);
1696  break;
1697 
1698  default:
1699  fatalf("Unknown Wccp2 security type\n");
1700  }
1701 
1702  /* Service info */
1703 
1704  memcpy(&wccp_packet[offset], service_list_ptr->service_info, sizeof(struct wccp2_service_info_t));
1705 
1706  offset += sizeof(struct wccp2_service_info_t);
1707 
1708  /* assignment header - fill in length later */
1709 
1710  assignment_header = (struct wccp2_item_header_t *) &wccp_packet[offset];
1711 
1712  switch (Config.Wccp2.assignment_method) {
1713 
1715  assignment_header->type = htons(WCCP2_REDIRECT_ASSIGNMENT);
1716 
1717  offset += sizeof(struct wccp2_item_header_t);
1718  assignment_offset = offset;
1719  break;
1720 
1722  assignment_header->type = htons(WCCP2_ALT_ASSIGNMENT);
1723 
1724  offset += sizeof(struct wccp2_item_header_t);
1725  assignment_offset = offset;
1726 
1727  /* The alternative assignment has an extra header, fill in length later */
1728 
1729  alt_assignment_type_header = (struct wccp2_item_header_t *) &wccp_packet[offset];
1730  alt_assignment_type_header->type = htons(WCCP2_MASK_ASSIGNMENT);
1731 
1732  offset += sizeof(struct wccp2_item_header_t);
1733  alt_assignment_offset = offset;
1734 
1735  break;
1736 
1737  default:
1738  fatalf("Unknown Wccp2 assignment method\n");
1739  }
1740 
1741  /* Assignment key - fill in master ip later */
1742 
1743  assignment_key = (struct assignment_key_t *) &wccp_packet[offset];
1744 
1745  assignment_key->master_number = htonl(++service_list_ptr->change_num);
1746 
1747  offset += sizeof(struct assignment_key_t);
1748 
1749  /* Number of routers */
1750  memcpy(&wccp_packet[offset], &service_list_ptr->num_routers, sizeof(service_list_ptr->num_routers));
1751 
1752  offset += sizeof(service_list_ptr->num_routers);
1753 
1754  for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != NULL; router_list_ptr = router_list_ptr->next) {
1755 
1756  /* Add routers */
1757 
1758  router_assign = (struct wccp2_router_assign_element_t *) &wccp_packet[offset];
1759  router_assign->router_address = router_list_ptr->info->router_address;
1760  router_assign->received_id = router_list_ptr->info->received_id;
1761  router_assign->change_number = htonl(router_list_ptr->member_change);
1762 
1763  offset += sizeof(struct wccp2_router_assign_element_t);
1764  }
1765 
1766  saved_offset = offset;
1767 
1768  for (router_list_ptr = &service_list_ptr->router_list_head; router_list_ptr->next != NULL; router_list_ptr = router_list_ptr->next) {
1769  unsigned long *weight = (unsigned long *)xcalloc(sizeof(*weight), ntohl(router_list_ptr->num_caches));
1770  unsigned long total_weight = 0;
1771  int num_caches = ntohl(router_list_ptr->num_caches);
1772 
1773  offset = saved_offset;
1774 
1775  switch (Config.Wccp2.assignment_method) {
1776 
1778  /* Number of caches */
1779  memcpy(&wccp_packet[offset], &router_list_ptr->num_caches, sizeof(router_list_ptr->num_caches));
1780  offset += sizeof(router_list_ptr->num_caches);
1781 
1782  if (num_caches) {
1783  int cache;
1784 
1785  for (cache = 0, cache_list_ptr = &router_list_ptr->cache_list_head; cache_list_ptr->next; cache_list_ptr = cache_list_ptr->next, ++cache) {
1786  /* add caches */
1787 
1788  cache_address = (struct in_addr *) &wccp_packet[offset];
1789 
1790  memcpy(cache_address, &cache_list_ptr->cache_ip, sizeof(struct in_addr));
1791  total_weight += cache_list_ptr->weight << 12;
1792  weight[cache] = cache_list_ptr->weight << 12;
1793 
1794  offset += sizeof(struct in_addr);
1795  }
1796  }
1797 
1798  /* Add buckets */
1799  buckets = (char *) &wccp_packet[offset];
1800 
1801  memset(buckets, '\0', WCCP_BUCKETS);
1802 
1803  if (num_caches != 0) {
1804  if (total_weight == 0) {
1805  for (bucket_counter = 0; bucket_counter < WCCP_BUCKETS; ++bucket_counter) {
1806  buckets[bucket_counter] = (char) (bucket_counter % num_caches);
1807  }
1808  } else {
1809  unsigned long *assigned = (unsigned long *)xcalloc(sizeof(*assigned), num_caches);
1810  unsigned long done = 0;
1811  int cache = -1;
1812  unsigned long per_bucket = total_weight / WCCP_BUCKETS;
1813 
1814  for (bucket_counter = 0; bucket_counter < WCCP_BUCKETS; ++bucket_counter) {
1815  int n;
1816  unsigned long step;
1817 
1818  for (n = num_caches; n; --n) {
1819  ++cache;
1820 
1821  if (cache >= num_caches)
1822  cache = 0;
1823 
1824  if (!weight[cache]) {
1825  ++n;
1826  continue;
1827  }
1828 
1829  if (assigned[cache] <= done)
1830  break;
1831  }
1832 
1833  buckets[bucket_counter] = (char) cache;
1834  step = per_bucket * total_weight / weight[cache];
1835  assigned[cache] += step;
1836  done += per_bucket;
1837  }
1838 
1839  safe_free(assigned);
1840  }
1841  }
1842 
1843  offset += (WCCP_BUCKETS * sizeof(char));
1844  safe_free(weight);
1845  break;
1846 
1848  num_maskval = htonl(1);
1849  memcpy(&wccp_packet[offset], &num_maskval, sizeof(int));
1850  offset += sizeof(int);
1851 
1852  mask_element = (struct wccp2_mask_element_t *) &wccp_packet[offset];
1853  service_flags = ntohl(service_list_ptr->service_info->service_flags);
1854 
1855  if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
1856  mask_element->source_ip_mask = htonl(0x00001741);
1857  mask_element->dest_ip_mask = 0;
1858  mask_element->source_port_mask = 0;
1859  mask_element->dest_port_mask = 0;
1860  } 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)) {
1861  mask_element->source_ip_mask = 0;
1862  mask_element->dest_ip_mask = htonl(0x00001741);
1863  mask_element->source_port_mask = 0;
1864  mask_element->dest_port_mask = 0;
1865  } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
1866  mask_element->source_ip_mask = 0;
1867  mask_element->dest_ip_mask = 0;
1868  mask_element->source_port_mask = htons(0x1741);
1869  mask_element->dest_port_mask = 0;
1870  } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
1871  mask_element->source_ip_mask = 0;
1872  mask_element->dest_ip_mask = 0;
1873  mask_element->source_port_mask = 0;
1874  mask_element->dest_port_mask = htons(0x1741);
1875  } else {
1876  fatalf("Unknown service hash method\n");
1877  }
1878 
1879  mask_element->number_values = htonl(64);
1880 
1881  offset += sizeof(struct wccp2_mask_element_t);
1882 
1883  cache_list_ptr = &router_list_ptr->cache_list_head;
1884  value = 0;
1885 
1886  for (valuecounter = 0; valuecounter < 64; ++valuecounter) {
1887 
1888  value_element = (struct wccp2_value_element_t *) &wccp_packet[offset];
1889 
1890  /* Update the value according the the "correct" formula */
1891 
1892  for (; (value & 0x1741) != value; ++value) {
1893  assert(value <= 0x1741);
1894  }
1895 
1896  if ((service_flags & WCCP2_SERVICE_SRC_IP_HASH) || (service_flags & WCCP2_SERVICE_SRC_IP_ALT_HASH)) {
1897  value_element->source_ip_value = htonl(value);
1898  value_element->dest_ip_value = 0;
1899  value_element->source_port_value = 0;
1900  value_element->dest_port_value = 0;
1901  } 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)) {
1902  value_element->source_ip_value = 0;
1903  value_element->dest_ip_value = htonl(value);
1904  value_element->source_port_value = 0;
1905  value_element->dest_port_value = 0;
1906  } else if ((service_flags & WCCP2_SERVICE_SRC_PORT_HASH) || (service_flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH)) {
1907  value_element->source_ip_value = 0;
1908  value_element->dest_ip_value = 0;
1909  value_element->source_port_value = htons(value);
1910  value_element->dest_port_value = 0;
1911  } else if ((service_flags & WCCP2_SERVICE_DST_PORT_HASH) || (service_flags & WCCP2_SERVICE_DST_PORT_ALT_HASH)) {
1912  value_element->source_ip_value = 0;
1913  value_element->dest_ip_value = 0;
1914  value_element->source_port_value = 0;
1915  value_element->dest_port_value = htons(value);
1916  } else {
1917  fatalf("Unknown service hash method\n");
1918  }
1919 
1920  value_element->cache_ip = cache_list_ptr->cache_ip;
1921 
1922  offset += sizeof(struct wccp2_value_element_t);
1923  ++value;
1924 
1925  /* Assign the next value to the next cache */
1926 
1927  if ((cache_list_ptr->next) && (cache_list_ptr->next->next))
1928  cache_list_ptr = cache_list_ptr->next;
1929  else
1930  cache_list_ptr = &router_list_ptr->cache_list_head;
1931  }
1932 
1933  /* Fill in length */
1934  alt_assignment_type_header->length = htons(offset - alt_assignment_offset);
1935 
1936  break;
1937 
1938  default:
1939  fatalf("Unknown Wccp2 assignment method\n");
1940  }
1941 
1942  /* Fill in length */
1943 
1944  assignment_header->length = htons(offset - assignment_offset);
1945 
1946  /* Fill in assignment key */
1947  assignment_key->master_ip = router_list_ptr->local_ip;
1948 
1949  /* finish length */
1950 
1951  main_header->length = htons(offset - sizeof(struct wccp2_message_header_t));
1952 
1953  /* set the destination address */
1954  router.sin_addr = router_list_ptr->router_sendto_address;
1955 
1956  /* Security update, if needed */
1957 
1958  if (service_list_ptr->wccp2_security_type == WCCP2_MD5_SECURITY) {
1959  wccp2_update_md5_security(service_list_ptr->wccp_password, (char *) security, wccp_packet, offset);
1960  }
1961 
1962  if (ntohl(router_list_ptr->num_caches)) {
1963  /* send packet */
1964 
1965  /* FIXME INET6 : drop temp conversion */
1966  Ip::Address tmp_rtr(router);
1967 
1968  if (wccp2_numrouters > 1) {
1970  tmp_rtr,
1971  &wccp_packet,
1972  offset);
1973  } else {
1974  if (send(theWccp2Connection, &wccp_packet, offset, 0) < static_cast<int>(offset)) {
1975  int xerrno = errno;
1976  debugs(80, 2, "ERROR: failed to send WCCPv2 HERE_I_AM packet to " << tmp_rtr << " : " << xstrerr(xerrno));
1977  }
1978  }
1979  }
1980  safe_free(weight);
1981  }
1982 
1983  service_list_ptr = service_list_ptr->next;
1984  }
1985 }
1986 
1987 /*
1988  * Configuration option parsing code
1989  */
1990 
1996 void
1998 {
1999  char *t;
2000 
2001  /* Snarf the method */
2002  if ((t = ConfigParser::NextToken()) == NULL) {
2003  debugs(80, DBG_CRITICAL, "wccp2_*_method: missing setting.");
2004  self_destruct();
2005  return;
2006  }
2007 
2008  /* update configuration if its valid */
2009  if (strcmp(t, "gre") == 0 || strcmp(t, "1") == 0) {
2010  *method = WCCP2_METHOD_GRE;
2011  } else if (strcmp(t, "l2") == 0 || strcmp(t, "2") == 0) {
2012  *method = WCCP2_METHOD_L2;
2013  } else {
2014  debugs(80, DBG_CRITICAL, "wccp2_*_method: unknown setting, got " << t );
2015  self_destruct();
2016  }
2017 }
2018 
2019 void
2020 dump_wccp2_method(StoreEntry * e, const char *label, int v)
2021 {
2022  switch (v) {
2023  case WCCP2_METHOD_GRE:
2024  storeAppendPrintf(e, "%s gre\n", label);
2025  break;
2026  case WCCP2_METHOD_L2:
2027  storeAppendPrintf(e, "%s l2\n", label);
2028  break;
2029  default:
2030  debugs(80, DBG_CRITICAL, "FATAL: WCCPv2 configured method (" << v << ") is not valid.");
2031  self_destruct();
2032  }
2033 }
2034 
2035 void
2037 { }
2038 
2044 void
2046 {
2047  char *t;
2048 
2049  /* Snarf the method */
2050  if ((t = ConfigParser::NextToken()) == NULL) {
2051  debugs(80, DBG_CRITICAL, "wccp2_assignment_method: missing setting.");
2052  self_destruct();
2053  return;
2054  }
2055 
2056  /* update configuration if its valid */
2057  if (strcmp(t, "hash") == 0 || strcmp(t, "1") == 0) {
2058  *method = WCCP2_ASSIGNMENT_METHOD_HASH;
2059  } else if (strcmp(t, "mask") == 0 || strcmp(t, "2") == 0) {
2060  *method = WCCP2_ASSIGNMENT_METHOD_MASK;
2061  } else {
2062  debugs(80, DBG_CRITICAL, "wccp2_assignment_method: unknown setting, got " << t );
2063  self_destruct();
2064  }
2065 }
2066 
2067 void
2068 dump_wccp2_amethod(StoreEntry * e, const char *label, int v)
2069 {
2070  switch (v) {
2072  storeAppendPrintf(e, "%s hash\n", label);
2073  break;
2075  storeAppendPrintf(e, "%s mask\n", label);
2076  break;
2077  default:
2078  debugs(80, DBG_CRITICAL, "FATAL: WCCPv2 configured " << label << " (" << v << ") is not valid.");
2079  self_destruct();
2080  }
2081 }
2082 
2083 void
2085 {}
2086 
2087 /*
2088  * Format:
2089  *
2090  * wccp2_service {standard|dynamic} {id} (password=password)
2091  */
2092 void
2094 {
2095  char *t;
2096  int service = 0;
2097  int service_id = 0;
2098  int security_type = WCCP2_NO_SECURITY;
2099  char wccp_password[WCCP2_PASSWORD_LEN + 1];
2100 
2101  if (wccp2_connected == 1) {
2102  debugs(80, DBG_IMPORTANT, "WCCPv2: Somehow reparsing the configuration without having shut down WCCP! Try reloading squid again.");
2103  return;
2104  }
2105 
2106  /* Snarf the type */
2107  if ((t = ConfigParser::NextToken()) == NULL) {
2108  debugs(80, DBG_CRITICAL, "wccp2ParseServiceInfo: missing service info type (standard|dynamic)");
2109  self_destruct();
2110  return;
2111  }
2112 
2113  if (strcmp(t, "standard") == 0) {
2114  service = WCCP2_SERVICE_STANDARD;
2115  } else if (strcmp(t, "dynamic") == 0) {
2116  service = WCCP2_SERVICE_DYNAMIC;
2117  } else {
2118  debugs(80, DBG_CRITICAL, "wccp2ParseServiceInfo: bad service info type (expected standard|dynamic, got " << t << ")");
2119  self_destruct();
2120  return;
2121  }
2122 
2123  /* Snarf the ID */
2124  service_id = GetInteger();
2125 
2126  if (service_id < 0 || service_id > 255) {
2127  debugs(80, DBG_CRITICAL, "ERROR: invalid WCCP service id " << service_id << " (must be between 0 .. 255)");
2128  self_destruct();
2129  return;
2130  }
2131 
2132  memset(wccp_password, 0, sizeof(wccp_password));
2133  /* Handle password, if any */
2134 
2135  if ((t = ConfigParser::NextToken()) != NULL) {
2136  if (strncmp(t, "password=", 9) == 0) {
2137  security_type = WCCP2_MD5_SECURITY;
2138  strncpy(wccp_password, t + 9, WCCP2_PASSWORD_LEN);
2139  }
2140  }
2141 
2142  /* Create a placeholder service record */
2143  wccp2_add_service_list(service, service_id, 0, 0, 0, empty_portlist, security_type, wccp_password);
2144 }
2145 
2146 void
2147 dump_wccp2_service(StoreEntry * e, const char *label, void *)
2148 {
2149  struct wccp2_service_list_t *srv;
2151 
2152  while (srv != NULL) {
2153  debugs(80, 3, "dump_wccp2_service: id " << srv->info.service_id << ", type " << srv->info.service);
2154  storeAppendPrintf(e, "%s %s %d", label,
2155  (srv->info.service == WCCP2_SERVICE_DYNAMIC) ? "dynamic" : "standard",
2156  srv->info.service_id);
2157 
2159  storeAppendPrintf(e, " %s", srv->wccp_password);
2160  }
2161 
2162  storeAppendPrintf(e, "\n");
2163 
2164  srv = srv->next;
2165  }
2166 }
2167 
2168 void
2170 {}
2171 
2172 int
2174 {
2175  return !wccp2_service_list_head;
2176 }
2177 
2178 /*
2179  * Format:
2180  *
2181  * wccp2_service_info {id} stuff..
2182  *
2183  * Where stuff is:
2184  *
2185  * + flags=flag,flag,flag..
2186  * + proto=protocol (tcp|udp)
2187  * + ports=port,port,port (up to a max of 8)
2188  * + priority=priority (0->255)
2189  *
2190  * The flags here are:
2191  * src_ip_hash, dst_ip_hash, source_port_hash, dst_port_hash, ports_defined,
2192  * ports_source, src_ip_alt_hash, dst_ip_alt_hash, src_port_alt_hash, dst_port_alt_hash
2193  */
2194 static int
2196 {
2197  if (!flags)
2198  return 0;
2199 
2200  char *flag = flags;
2201  int retflag = 0;
2202 
2203  while (size_t len = strcspn(flag, ",")) {
2204 
2205  if (strncmp(flag, "src_ip_hash", len) == 0) {
2206  retflag |= WCCP2_SERVICE_SRC_IP_HASH;
2207  } else if (strncmp(flag, "dst_ip_hash", len) == 0) {
2208  retflag |= WCCP2_SERVICE_DST_IP_HASH;
2209  } else if (strncmp(flag, "source_port_hash", len) == 0) {
2210  retflag |= WCCP2_SERVICE_SRC_PORT_HASH;
2211  } else if (strncmp(flag, "dst_port_hash", len) == 0) {
2212  retflag |= WCCP2_SERVICE_DST_PORT_HASH;
2213  } else if (strncmp(flag, "ports_source", len) == 0) {
2214  retflag |= WCCP2_SERVICE_PORTS_SOURCE;
2215  } else if (strncmp(flag, "src_ip_alt_hash", len) == 0) {
2216  retflag |= WCCP2_SERVICE_SRC_IP_ALT_HASH;
2217  } else if (strncmp(flag, "dst_ip_alt_hash", len) == 0) {
2218  retflag |= WCCP2_SERVICE_DST_IP_ALT_HASH;
2219  } else if (strncmp(flag, "src_port_alt_hash", len) == 0) {
2221  } else if (strncmp(flag, "dst_port_alt_hash", len) == 0) {
2223  } else {
2224  flag[len] = '\0';
2225  fatalf("Unknown wccp2 service flag: %s\n", flag);
2226  }
2227 
2228  if (flag[len] == '\0')
2229  break;
2230 
2231  flag += len+1;
2232  }
2233 
2234  return retflag;
2235 }
2236 
2237 static void
2238 parse_wccp2_service_ports(char *options, int portlist[])
2239 {
2240  if (!options) {
2241  return;
2242  }
2243 
2244  int i = 0;
2245  char *tmp = options;
2246  static char copy[10];
2247 
2248  while (size_t len = strcspn(tmp, ",")) {
2249  if (i >= WCCP2_NUMPORTS) {
2250  fatalf("parse_wccp2_service_ports: too many ports (maximum: 8) in list '%s'\n", options);
2251  }
2252  if (len > 6) { // 6 because "65535,"
2253  fatalf("parse_wccp2_service_ports: port value '%s' isn't valid (1..65535)\n", tmp);
2254  }
2255 
2256  memcpy(copy, tmp, len);
2257  copy[len] = '\0';
2258  int p = xatoi(copy);
2259 
2260  if (p < 1 || p > 65535) {
2261  fatalf("parse_wccp2_service_ports: port value '%s' isn't valid (1..65535)\n", tmp);
2262  }
2263 
2264  portlist[i] = p;
2265  ++i;
2266  if (tmp[len] == '\0')
2267  return;
2268  tmp += len+1;
2269  }
2270 }
2271 
2272 void
2274 {
2275  char *t, *end;
2276  int service_id = 0;
2277  int flags = 0;
2278  int portlist[WCCP2_NUMPORTS];
2279  int protocol = -1; /* IPPROTO_TCP | IPPROTO_UDP */
2280 
2281  struct wccp2_service_list_t *srv;
2282  int priority = -1;
2283 
2284  if (wccp2_connected == 1) {
2285  debugs(80, DBG_IMPORTANT, "WCCPv2: Somehow reparsing the configuration without having shut down WCCP! Try reloading squid again.");
2286  return;
2287  }
2288 
2289  debugs(80, 5, "parse_wccp2_service_info: called");
2290  memset(portlist, 0, sizeof(portlist));
2291  /* First argument: id */
2292  service_id = GetInteger();
2293 
2294  if (service_id < 0 || service_id > 255) {
2295  debugs(80, DBG_CRITICAL, "ERROR: invalid WCCP service id " << service_id << " (must be between 0 .. 255)");
2296  self_destruct();
2297  return;
2298  }
2299 
2300  /* Next: find the (hopefully!) existing service */
2302 
2303  if (srv == NULL) {
2304  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);
2305  }
2306 
2307  /* Next: loop until we don't have any more tokens */
2308  while ((t = ConfigParser::NextToken()) != NULL) {
2309  if (strncmp(t, "flags=", 6) == 0) {
2310  /* XXX eww, string pointer math */
2311  flags = parse_wccp2_service_flags(t + 6);
2312  } else if (strncmp(t, "ports=", 6) == 0) {
2313  parse_wccp2_service_ports(t + 6, portlist);
2314  flags |= WCCP2_SERVICE_PORTS_DEFINED;
2315  } else if (strncmp(t, "protocol=tcp", 12) == 0) {
2316  protocol = IPPROTO_TCP;
2317  } else if (strncmp(t, "protocol=udp", 12) == 0) {
2318  protocol = IPPROTO_UDP;
2319  } else if (strncmp(t, "protocol=", 9) == 0) {
2320  fatalf("parse_wccp2_service_info: id %d: unknown protocol (%s) - must be tcp or udp!\n", service_id, t);
2321  } else if (strncmp(t, "priority=", 9) == 0) {
2322  priority = strtol(t + 9, &end, 0);
2323 
2324  if (priority < 0 || priority > 255) {
2325  fatalf("parse_wccp2_service_info: id %d: %s out of range (0..255)!\n", service_id, t);
2326  }
2327  } else {
2328  fatalf("parse_wccp2_service_info: id %d: unknown option '%s'\n", service_id, t);
2329  }
2330  }
2331 
2332  /* Check everything is set */
2333  if (priority == -1) {
2334  fatalf("parse_wccp2_service_info: service %d: no priority defined (valid: 0..255)!\n", service_id);
2335  }
2336 
2337  if (protocol == -1) {
2338  fatalf("parse_wccp2_service_info: service %d: no protocol defined (valid: tcp or udp)!\n", service_id);
2339  }
2340 
2341  if (!(flags & WCCP2_SERVICE_PORTS_DEFINED)) {
2342  fatalf("parse_wccp2_service_info: service %d: no ports defined!\n", service_id);
2343  }
2344 
2345  /* rightio! now we can update */
2346  wccp2_update_service(srv, WCCP2_SERVICE_DYNAMIC, service_id, priority,
2347  protocol, flags, portlist);
2348 
2349  /* Done! */
2350 }
2351 
2352 void
2353 dump_wccp2_service_info(StoreEntry * e, const char *label, void *)
2354 {
2355  struct wccp2_service_list_t *srv;
2356  int flags;
2358 
2359  while (srv != NULL) {
2360  debugs(80, 3, "dump_wccp2_service_info: id " << srv->info.service_id << " (type " << srv->info.service << ")");
2361 
2362  /* We don't need to spit out information for standard services */
2363 
2364  if (srv->info.service == WCCP2_SERVICE_STANDARD) {
2365  debugs(80, 3, "dump_wccp2_service_info: id " << srv->info.service_id << ": standard service, not dumping info");
2366 
2367  /* XXX eww */
2368  srv = srv->next;
2369  continue;
2370  }
2371 
2372  storeAppendPrintf(e, "%s %d", label, srv->info.service_id);
2373 
2374  /* priority */
2375  storeAppendPrintf(e, " priority=%d", srv->info.service_priority);
2376 
2377  /* flags */
2378  flags = ntohl(srv->info.service_flags);
2379 
2380  bool comma = false;
2381  if (flags != 0) {
2382  storeAppendPrintf(e, " flags=");
2383 
2384  if (flags & WCCP2_SERVICE_SRC_IP_HASH) {
2385  storeAppendPrintf(e, "src_ip_hash");
2386  comma = true;
2387  }
2388 
2389  if (flags & WCCP2_SERVICE_DST_IP_HASH) {
2390  storeAppendPrintf(e, "%sdst_ip_hash", comma ? "," : "");
2391  comma = true;
2392  }
2393 
2394  if (flags & WCCP2_SERVICE_SRC_PORT_HASH) {
2395  storeAppendPrintf(e, "%ssource_port_hash", comma ? "," : "");
2396  comma = true;
2397  }
2398 
2399  if (flags & WCCP2_SERVICE_DST_PORT_HASH) {
2400  storeAppendPrintf(e, "%sdst_port_hash", comma ? "," : "");
2401  comma = true;
2402  }
2403 
2404  if (flags & WCCP2_SERVICE_PORTS_DEFINED) {
2405  storeAppendPrintf(e, "%sports_defined", comma ? "," : "");
2406  comma = true;
2407  }
2408 
2409  if (flags & WCCP2_SERVICE_PORTS_SOURCE) {
2410  storeAppendPrintf(e, "%sports_source", comma ? "," : "");
2411  comma = true;
2412  }
2413 
2414  if (flags & WCCP2_SERVICE_SRC_IP_ALT_HASH) {
2415  storeAppendPrintf(e, "%ssrc_ip_alt_hash", comma ? "," : "");
2416  comma = true;
2417  }
2418 
2419  if (flags & WCCP2_SERVICE_DST_IP_ALT_HASH) {
2420  storeAppendPrintf(e, "%ssrc_ip_alt_hash", comma ? "," : "");
2421  comma = true;
2422  }
2423 
2424  if (flags & WCCP2_SERVICE_SRC_PORT_ALT_HASH) {
2425  storeAppendPrintf(e, "%ssrc_port_alt_hash", comma ? "," : "");
2426  comma = true;
2427  }
2428 
2429  if (flags & WCCP2_SERVICE_DST_PORT_ALT_HASH) {
2430  storeAppendPrintf(e, "%sdst_port_alt_hash", comma ? "," : "");
2431  //comma = true; // uncomment if more options added
2432  }
2433  }
2434 
2435  /* ports */
2436  comma = false;
2437 
2438  if (srv->info.port0 != 0) {
2439  storeAppendPrintf(e, " ports=%d", ntohs(srv->info.port0));
2440  comma = true;
2441  }
2442 
2443  if (srv->info.port1 != 0) {
2444  storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port1));
2445  comma = true;
2446  }
2447 
2448  if (srv->info.port2 != 0) {
2449  storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port2));
2450  comma = true;
2451  }
2452 
2453  if (srv->info.port3 != 0) {
2454  storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port3));
2455  comma = true;
2456  }
2457 
2458  if (srv->info.port4 != 0) {
2459  storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port4));
2460  comma = true;
2461  }
2462 
2463  if (srv->info.port5 != 0) {
2464  storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port5));
2465  comma = true;
2466  }
2467 
2468  if (srv->info.port6 != 0) {
2469  storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port6));
2470  comma = true;
2471  }
2472 
2473  if (srv->info.port7 != 0) {
2474  storeAppendPrintf(e, "%s%d", comma ? "," : "ports=", ntohs(srv->info.port7));
2475  // comma = true; // uncomment if more options are added
2476  }
2477 
2478  /* protocol */
2479  storeAppendPrintf(e, " protocol=%s", (srv->info.service_protocol == IPPROTO_TCP) ? "tcp" : "udp");
2480 
2481  storeAppendPrintf(e, "\n");
2482 
2483  srv = srv->next;
2484  }
2485 }
2486 
2487 /* Sort the cache list by doing a "selection sort" by IP address */
2488 static void
2490 {
2491  struct wccp2_cache_list_t tmp;
2492  struct wccp2_cache_list_t *this_item;
2493  struct wccp2_cache_list_t *find_item;
2494  struct wccp2_cache_list_t *next_lowest;
2495 
2496  /* Go through each position in the list one at a time */
2497  for (this_item = head; this_item->next; this_item = this_item->next) {
2498  /* Find the item with the lowest IP */
2499  next_lowest = this_item;
2500 
2501  for (find_item = this_item; find_item->next; find_item = find_item->next) {
2502  if (find_item->cache_ip.s_addr < next_lowest->cache_ip.s_addr) {
2503  next_lowest = find_item;
2504  }
2505  }
2506  /* Swap if we need to */
2507  if (next_lowest != this_item) {
2508  /* First make a copy of the current item */
2509  memcpy(&tmp, this_item, sizeof(struct wccp2_cache_list_t));
2510 
2511  /* Next update the pointers to maintain the linked list */
2512  tmp.next = next_lowest->next;
2513  next_lowest->next = this_item->next;
2514 
2515  /* Finally copy the updated items to their correct location */
2516  memcpy(this_item, next_lowest, sizeof(struct wccp2_cache_list_t));
2517  memcpy(next_lowest, &tmp, sizeof(struct wccp2_cache_list_t));
2518  }
2519  }
2520 }
2521 
2522 void
2524 {}
2525 
2526 #endif /* USE_WCCPv2 */
2527 
struct wccp2_item_header_t header
Definition: wccp2.cc:364
bool setIPv4()
Definition: Address.cc:217
struct in_addr local_ip
Definition: wccp2.cc:421
void dump_wccp2_service_info(StoreEntry *e, const char *label, void *)
Definition: wccp2.cc:2353
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:90
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_MASK_ASSIGNMENT
Definition: wccp2.cc:45
struct wccp2_cache_list_t * next
Definition: wccp2.cc:413
#define WCCP2_CAPABILITY_RETURN_METHOD
Definition: wccp2.cc:305
#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:448
void free_wccp2_service_info(void *)
Definition: wccp2.cc:2523
#define WCCP2_SERVICE_SRC_PORT_ALT_HASH
Definition: wccp2.cc:163
int empty_portlist[WCCP2_NUMPORTS]
Definition: wccp2.cc:459
static void wccp2SortCacheList(struct wccp2_cache_list_t *head)
Definition: wccp2.cc:2489
int forwarding_method
Definition: SquidConfig.h:162
Ip::Address router
Definition: SquidConfig.h:152
void parse_wccp2_service_info(void *)
Definition: wccp2.cc:2273
struct wccp2_cache_list_t cache_list_head
Definition: wccp2.cc:427
uint16_t source_port_mask
Definition: wccp2.cc:206
struct assignment_key_t assignment_key
Definition: wccp2.cc:400
uint16_t dest_port_mask
Definition: wccp2.cc:207
#define WCCP2_NO_SECURITY
Definition: wccp2.cc:109
static struct wccp2_router_id_element_t wccp2_router_id_element
Definition: wccp2.cc:279
static struct wccp2_capability_element_t wccp2_capability_element
Definition: wccp2.cc:300
struct in_addr addr
Definition: wccp2.cc:177
struct wccp2_router_id_element_t * info
Definition: wccp2.cc:419
#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:255
struct in_addr cache_ip
Definition: wccp2.cc:331
int i
Definition: membanger.c:49
uint32_t num1
Definition: wccp2.cc:381
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:604
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:304
#define WCCP2_METHOD_L2
Definition: wccp2.cc:311
#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:364
uint32_t source_ip_value
Definition: wccp2.cc:326
static int parse_wccp2_service_flags(char *flags)
Definition: wccp2.cc:2195
static struct wccp2_i_see_you_t wccp2_i_see_you
Definition: wccp2.cc:346
char data[WCCP_RESPONSE_SIZE]
Definition: wccp2.cc:343
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:44
uint16_t source_port_value
Definition: wccp2.cc:328
char * p
Definition: membanger.c:43
uint16_t version
Definition: wccp2.cc:84
void wccp2Init(void)
Definition: wccp2.cc:652
#define WCCP2_ASSIGNMENT_METHOD_HASH
Definition: wccp2.cc:316
#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:440
char wccp_password[WCCP2_PASSWORD_LEN+1]
Definition: wccp2.cc:453
uint16_t version
Definition: wccp2.cc:341
uint16_t dest_port_value
Definition: wccp2.cc:329
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:79
#define WCCP_RESPONSE_SIZE
Definition: wccp2.cc:32
void free_wccp2_service(void *)
Definition: wccp2.cc:2169
#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:369
void EVH(void *)
Definition: event.h:19
struct wccp2_router_list_t * next
Definition: wccp2.cc:429
struct wccp2_service_list_t * next
Definition: wccp2.cc:452
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
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:450
#define DBG_IMPORTANT
Definition: Debug.h:45
void dump_wccp2_amethod(StoreEntry *e, const char *label, int v)
Definition: wccp2.cc:2068
#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:437
#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:529
struct in_addr cache_ip
Definition: wccp2.cc:409
#define WCCP2_ASSIGNMENT_METHOD_MASK
Definition: wccp2.cc:317
uint16_t port0
Definition: wccp2.cc:138
static void wccp2InitServices(void)
Definition: wccp2.cc:475
#define WCCP2_WC_ID_INFO
Definition: wccp2.cc:69
char wccp_packet[WCCP_RESPONSE_SIZE]
Definition: wccp2.cc:449
uint16_t cache_identity_type
Definition: wccp2.cc:240
struct in_addr addr
Definition: wccp2.cc:380
uint16_t cache_identity_length
Definition: wccp2.cc:193
uint32_t num2
Definition: wccp2.cc:382
static PF wccp2HandleUdp
Definition: wccp2.cc:38
static char * NextToken()
#define WCCP2_PACKET_RETURN_METHOD_GRE
Definition: wccp2.cc:319
void free_wccp2_method(int *)
Definition: wccp2.cc:2036
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:39
void parse_wccp2_amethod(int *method)
Definition: wccp2.cc:2045
uint16_t port5
Definition: wccp2.cc:143
static void parse_wccp2_service_ports(char *options, int portlist[])
Definition: wccp2.cc:2238
void PF(int, void *)
Definition: forward.h:18
static struct wccp2_service_list_t * wccp2_service_list_head
Definition: wccp2.cc:457
uint16_t service_type
Definition: wccp2.cc:131
char * wccp2_identity_info_ptr
Definition: wccp2.cc:444
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:1997
#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:425
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:502
void wccp2ConnectionOpen(void)
Definition: wccp2.cc:948
uint32_t master_number
Definition: wccp2.cc:391
void getSockAddr(struct sockaddr_storage &addr, const int family) const
Definition: Address.cc:942
struct wccp2_item_header_t header
Definition: wccp2.cc:398
#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:786
#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:340
#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:446
struct in_addr router_address
Definition: wccp2.cc:352
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:2147
static struct wccp2_mask_identity_info_t wccp2_mask_identity_info
Definition: wccp2.cc:246
#define WCCP2_METHOD_GRE
Definition: wccp2.cc:310
uint32_t cache_view_version
Definition: wccp2.cc:257
uint32_t number_values
Definition: wccp2.cc:208
uint32_t member_change
Definition: wccp2.cc:424
void free_wccp2_amethod(int *)
Definition: wccp2.cc:2084
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:126
#define WCCP2_FORWARDING_METHOD_GRE
Definition: wccp2.cc:313
struct in_addr router_address
Definition: wccp2.cc:368
#define WCCP2_RTR_VIEW_INFO
Definition: wccp2.cc:70
void parse_wccp2_service(void *)
Definition: wccp2.cc:2093
static int wccp2_connected
Definition: wccp2.cc:36
#define WCCP2_CAPABILITY_FORWARDING_METHOD
Definition: wccp2.cc:303
int check_null_wccp2_service(void *)
Definition: wccp2.cc:2173
#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:432
SQUIDCEXTERN void SquidMD5Final(uint8_t digest[16], struct SquidMD5Context *context)
struct wccp2_router_id_element_t router_id_element
Definition: wccp2.cc:366
uint32_t change_number
Definition: wccp2.cc:399
#define COMM_NONBLOCKING
Definition: Connection.h:44
uint16_t type
Definition: wccp2.cc:61
uint32_t num3
Definition: wccp2.cc:383
uint16_t security_length
Definition: wccp2.cc:120
struct in_addr master_ip
Definition: wccp2.cc:390
int assignment_method
Definition: SquidConfig.h:164
#define WCCP2_WC_VIEW_INFO
Definition: wccp2.cc:71
uint32_t change_num
Definition: wccp2.cc:442
struct SquidConfig::@102 Wccp2
uint16_t capability_length
Definition: wccp2.cc:297
struct in_addr router_sendto_address
Definition: wccp2.cc:423
#define WCCP2_MD5_SECURITY_LEN
Definition: wccp2.cc:48
bool getInAddr(struct in_addr &) const
Definition: Address.cc:1038
#define WCCP2_ASSIGN_MAP
Definition: wccp2.cc:76
static struct wccp2_capability_info_header_t wccp2_capability_info_header
Definition: wccp2.cc:290
static char wccp2_update_md5_security(char *password, char *ptr, char *packet, int len)
Definition: wccp2.cc:552
#define xfree
uint16_t length
Definition: wccp2.cc:342
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:904
void dump_wccp2_method(StoreEntry *e, const char *label, int v)
Definition: wccp2.cc:2020
#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:1036
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:454
#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:327
uint32_t num_routers
Definition: wccp2.cc:438
int return_method
Definition: SquidConfig.h:163
#define WCCP2_NUMPORTS
Definition: wccp2.cc:51

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors