The unified diff between revisions [57f483ac..] and [4e036a30..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'src/wccp2.c'

#
#
# patch "src/wccp2.c"
#  from [5796dfc2979401a6e06ddb4a2a7bb0aa99a4c277]
#    to [dab9798d3c9a8ad88b8ad75f47f83198d9a5d0ca]
#
============================================================
--- src/wccp2.c	5796dfc2979401a6e06ddb4a2a7bb0aa99a4c277
+++ src/wccp2.c	dab9798d3c9a8ad88b8ad75f47f83198d9a5d0ca
@@ -281,9 +281,11 @@ struct wccp2_service_list_t {
 	struct wccp2_service_list_t *next;
 };

-static struct wccp2_service_list_t wccp2_service_list_head;
+static struct wccp2_service_list_t *wccp2_service_list_head = NULL;

 /* END WCCP V2 */
+void wccp2_add_service_list(int type, int service, int service_id,
+    int service_priority, int service_proto, int service_flags, int ports[]);

 /*
  * The functions used during startup:
@@ -296,9 +298,10 @@ wccp2InitServices(void)
 static void
 wccp2InitServices(void)
 {
-    struct wccp2_service_list_t *wccp2_service_list_ptr;
-    wccp2_service_list_ptr=&wccp2_service_list_head;
+    int portlist[8];

+    bzero(portlist, sizeof(portlist));
+
     // TODO: Need to do something like this here:
     // for each wccp_service configured {
     //     if(wccp2_service_list_ptr != &wccp2_service_list_head) {
@@ -348,50 +351,51 @@ wccp2InitServices(void)
     //
     // [ports] would be up to 8 ports used to determine which packets to redirect

+
     /* This defines WCCP service number 80 (redirect traffic going to tcp port
        80, using the client ip as the hash) */
-    wccp2_service_list_ptr->info.service_type = htons(WCCP2_SERVICE_INFO);
-    wccp2_service_list_ptr->info.service_length = htons(sizeof(struct wccp2_service_info_t)-4);
-    wccp2_service_list_ptr->info.service = WCCP2_SERVICE_DYNAMIC;
-    wccp2_service_list_ptr->info.service_id = 80;
-    wccp2_service_list_ptr->info.service_priority = 240;
-    wccp2_service_list_ptr->info.service_protocol = IPPROTO_TCP;
-    wccp2_service_list_ptr->info.service_flags = htonl(WCCP2_SERVICE_SRC_IP_HASH + WCCP2_SERVICE_PORTS_DEFINED);
-    wccp2_service_list_ptr->info.port0 = htons(80);
-    wccp2_service_list_ptr->info.port1 = htons(0);
-    wccp2_service_list_ptr->info.port2 = htons(0);
-    wccp2_service_list_ptr->info.port3 = htons(0);
-    wccp2_service_list_ptr->info.port4 = htons(0);
-    wccp2_service_list_ptr->info.port5 = htons(0);
-    wccp2_service_list_ptr->info.port6 = htons(0);
-    wccp2_service_list_ptr->info.port7 = htons(0);
-    wccp2_service_list_ptr->change_num=0;
+    portlist[0] = 80;
+    wccp2_add_service_list(WCCP2_SERVICE_INFO, WCCP2_SERVICE_DYNAMIC, 80, 240, IPPROTO_TCP,
+		    WCCP2_SERVICE_SRC_IP_HASH | WCCP2_SERVICE_PORTS_DEFINED, portlist);
+    /* This defines WCCP service number 90 (redirect traffic coming from tcp
+       port 80, using the client ip as the hash) */
+    portlist[0] = 80;
+    wccp2_add_service_list(WCCP2_SERVICE_INFO, WCCP2_SERVICE_DYNAMIC, 90, 240, IPPROTO_TCP,
+		    WCCP2_SERVICE_DST_IP_HASH | WCCP2_SERVICE_PORTS_DEFINED | WCCP2_SERVICE_PORTS_SOURCE,
+		    portlist);
+}

-    wccp2_service_list_ptr->next=xcalloc(1,sizeof(struct wccp2_service_list_t));
-    wccp2_service_list_ptr=wccp2_service_list_ptr->next;
-    wccp2_service_list_ptr->next=NULL;
+void
+wccp2_add_service_list(int type, int service, int service_id, int service_priority, int service_proto,
+		int service_flags, int ports[])
+{
+    struct wccp2_service_list_t *wccp2_service_list_ptr;

-    /* This defines WCCP service number 90 (redirect traffic coming from tcp
-       port 80, using the client ip as the hash) */
-    wccp2_service_list_ptr->info.service_type = htons(WCCP2_SERVICE_INFO);
+    wccp2_service_list_ptr = xcalloc(1,sizeof(struct wccp2_service_list_t));
+
+    debug(80, 5) ("wccp2_add_service_list: added service id %d\n", service_id);
+
+    /* XXX check what needs to be wrapped in htons()! */
+    wccp2_service_list_ptr->info.service_type = htons(type);
     wccp2_service_list_ptr->info.service_length = htons(sizeof(struct wccp2_service_info_t)-4);
-    wccp2_service_list_ptr->info.service = WCCP2_SERVICE_DYNAMIC;
-    wccp2_service_list_ptr->info.service_id = 90;
-    wccp2_service_list_ptr->info.service_priority = 240;
-    wccp2_service_list_ptr->info.service_protocol = IPPROTO_TCP;
-    wccp2_service_list_ptr->info.service_flags = htonl(WCCP2_SERVICE_DST_IP_HASH + WCCP2_SERVICE_PORTS_DEFINED + WCCP2_SERVICE_PORTS_SOURCE);
-    wccp2_service_list_ptr->info.port0 = htons(80);
-    wccp2_service_list_ptr->info.port1 = htons(0);
-    wccp2_service_list_ptr->info.port2 = htons(0);
-    wccp2_service_list_ptr->info.port3 = htons(0);
-    wccp2_service_list_ptr->info.port4 = htons(0);
-    wccp2_service_list_ptr->info.port5 = htons(0);
-    wccp2_service_list_ptr->info.port6 = htons(0);
-    wccp2_service_list_ptr->info.port7 = htons(0);
+    wccp2_service_list_ptr->info.service = service;
+    wccp2_service_list_ptr->info.service_id = service_id;
+    wccp2_service_list_ptr->info.service_priority = service_priority;
+    wccp2_service_list_ptr->info.service_protocol = service_proto;
+    wccp2_service_list_ptr->info.service_flags = htonl(service_flags);
+    wccp2_service_list_ptr->info.port0 = htons(ports[0]);
+    wccp2_service_list_ptr->info.port1 = htons(ports[1]);
+    wccp2_service_list_ptr->info.port2 = htons(ports[2]);
+    wccp2_service_list_ptr->info.port3 = htons(ports[3]);
+    wccp2_service_list_ptr->info.port4 = htons(ports[4]);
+    wccp2_service_list_ptr->info.port5 = htons(ports[5]);
+    wccp2_service_list_ptr->info.port6 = htons(ports[6]);
+    wccp2_service_list_ptr->info.port7 = htons(ports[7]);
     wccp2_service_list_ptr->change_num=0;
-    wccp2_service_list_ptr->next=xcalloc(1,sizeof(struct wccp2_service_list_t));
-    wccp2_service_list_ptr=wccp2_service_list_ptr->next;
-    wccp2_service_list_ptr->next=NULL;
+
+    /* add to linked list - XXX this should use the Squid dlink* routines! */
+    wccp2_service_list_ptr->next = wccp2_service_list_head;
+    wccp2_service_list_head = wccp2_service_list_ptr;
 }

 void
@@ -421,7 +425,8 @@ wccp2Init(void)
     /* Initialise the list of services */
     wccp2InitServices();

-    for(service_list_ptr=&wccp2_service_list_head;service_list_ptr->next;service_list_ptr=service_list_ptr->next) {
+    service_list_ptr = wccp2_service_list_head;
+    while (service_list_ptr != NULL) {
 	/* Set up our list pointers */
 	router_list_ptr=&service_list_ptr->router_list_head;

@@ -549,6 +554,7 @@ wccp2Init(void)
 		eventAdd("wccp2HereIam", wccp2HereIam, NULL, 10.0, 1);
 	    }
 	}
+	service_list_ptr = service_list_ptr->next;
     }
 }

@@ -606,7 +612,8 @@ wccp2ConnectionOpen(void)
     debug(80, 1) ("Initialising all WCCPv2 lists\n");

     /* Initialise all routers on all services */
-    for(service_list_ptr=&wccp2_service_list_head;service_list_ptr->next;service_list_ptr=service_list_ptr->next) {
+    service_list_ptr = wccp2_service_list_head;
+    while (service_list_ptr != NULL) {
         for (router_list_ptr=&service_list_ptr->router_list_head;router_list_ptr->next != NULL;router_list_ptr=router_list_ptr->next) {
 	    router_len = sizeof(router);
 	    memset(&router, '\0', router_len);
@@ -627,6 +634,7 @@ wccp2ConnectionOpen(void)
 	    if (connect(theOutWccp2Connection, (struct sockaddr *) &router, router_len))
 		fatal("Unable to disconnect WCCP out socket");
 	}
+	service_list_ptr = service_list_ptr->next;
     }
     wccp2_connected=1;
 }
@@ -665,7 +673,8 @@ wccp2ConnectionClose(void)
 	comm_close(theOutWccp2Connection);
     }
     /* for each router on each service send a packet */
-    for(service_list_ptr=&wccp2_service_list_head;service_list_ptr;service_list_ptr=service_list_ptr_next) {
+    service_list_ptr = wccp2_service_list_head;
+    while (service_list_ptr != NULL) {
         for (router_list_ptr=&service_list_ptr->router_list_head;router_list_ptr != NULL;router_list_ptr=router_list_next) {
 	    for(cache_list_ptr=&router_list_ptr->cache_list_head;cache_list_ptr;cache_list_ptr=cache_list_ptr_next) {
 		cache_list_ptr_next=cache_list_ptr->next;
@@ -687,13 +696,14 @@ wccp2ConnectionClose(void)
 	    }
 	}
 	service_list_ptr_next=service_list_ptr->next;
-	if(service_list_ptr != &wccp2_service_list_head) {
+	if(service_list_ptr != wccp2_service_list_head) {
 		xfree(service_list_ptr);
 	}
 	else
 	{
 	    memset(service_list_ptr,'\0',sizeof(struct wccp2_service_list_t));
 	}
+	service_list_ptr = service_list_ptr->next;
     }
     wccp2_connected=0;
 }
@@ -825,13 +835,16 @@ wccp2HandleUdp(int sock, void *not_used)
     debug (80,5) ("Complete packet received\n");

     /* Check that the service in the packet is configured on this router */
-    for(service_list_ptr=&wccp2_service_list_head;service_list_ptr->next;service_list_ptr=service_list_ptr->next) {
+    service_list_ptr = wccp2_service_list_head;
+    while (service_list_ptr != NULL) {
+	//debug(80, 5) ("wccpv2: checking %d against %d\n", service_info->service_id, service_list_ptr->service_info->service_id);
 	if(service_info->service_id == service_list_ptr->service_info->service_id) {
 	    break;
 	}
+	service_list_ptr = service_list_ptr->next;
     }
-    if(!(service_list_ptr->next)) {
-	debug(80, 1) ("WCCPv2 Unknown service received from router\n");
+    if(service_list_ptr == NULL) {
+	debug(80, 1) ("WCCPv2 Unknown service received from router (%d)\n", service_info->service_id);
 	return;
     }

@@ -1006,7 +1019,9 @@ wccp2HereIam(void *voidnotused)
     router.sin_port = htons(port);

     /* for each router on each service send a packet */
-    for(service_list_ptr=&wccp2_service_list_head;service_list_ptr->next;service_list_ptr=service_list_ptr->next) {
+    service_list_ptr = wccp2_service_list_head;
+    while (service_list_ptr != NULL) {
+	debug(80, 5) ("wccp2HereIam: sending to service id %d\n", service_list_ptr->info.service_id);
         for (router_list_ptr=&service_list_ptr->router_list_head;router_list_ptr->next != NULL;router_list_ptr=router_list_ptr->next) {
 	    router.sin_addr = router_list_ptr->router_sendto_address;

@@ -1022,6 +1037,7 @@ wccp2HereIam(void *voidnotused)
 		(struct sockaddr *)&router,
 		router_len);
 	}
+	service_list_ptr = service_list_ptr->next;
     }

     if (!eventFind(wccp2HereIam, NULL))
@@ -1065,11 +1081,13 @@ wccp2AssignBuckets(void *voidnotused)
     main_header->version=htons(WCCP2_VERSION);

     debug(80,2) ("Running wccp2AssignBuckets\n");
-    for(service_list_ptr=&wccp2_service_list_head;service_list_ptr->next;service_list_ptr=service_list_ptr->next) {
-
+    service_list_ptr = wccp2_service_list_head;
+    while (service_list_ptr != NULL) {
 	/* If we're not the lowest, we don't need to worry */
 	if(service_list_ptr->lowest_ip == 0) {
-	    continue;
+		/* XXX eww */
+		service_list_ptr = service_list_ptr->next;
+		continue;
 	}

 	/* reset the offset */
@@ -1162,6 +1180,7 @@ wccp2AssignBuckets(void *voidnotused)
 		    router_len);
 	    }
 	}
+	service_list_ptr = service_list_ptr->next;
     }
 }
 #endif /* USE_WCCPv2 */