svn commit: r201121 - head/sys/netinet/ipfw

Luigi Rizzo luigi at FreeBSD.org
Mon Dec 28 10:19:54 UTC 2009


Author: luigi
Date: Mon Dec 28 10:19:53 2009
New Revision: 201121
URL: http://svn.freebsd.org/changeset/base/201121

Log:
  readability fixes -- add braces on large blocks, remove unnecessary
  initializations

Modified:
  head/sys/netinet/ipfw/ip_dummynet.c

Modified: head/sys/netinet/ipfw/ip_dummynet.c
==============================================================================
--- head/sys/netinet/ipfw/ip_dummynet.c	Mon Dec 28 10:12:35 2009	(r201120)
+++ head/sys/netinet/ipfw/ip_dummynet.c	Mon Dec 28 10:19:53 2009	(r201121)
@@ -566,13 +566,6 @@ set_ticks(struct mbuf *m, struct dn_flow
 
 	ret = div64( (m->m_pkthdr.len * 8 + q->extra_bits) * hz
 		- q->numbytes + p->bandwidth - 1 , p->bandwidth);
-#if 0
-	printf("%s %d extra_bits %d numb %d ret %d\n",
-		__FUNCTION__, __LINE__,
-		(int)(q->extra_bits & 0xffffffff),
-		(int)(q->numbytes & 0xffffffff),
-		(int)(ret & 0xffffffff));
-#endif
 	if (ret < 0)
 		ret = 0;
 	return ret;
@@ -945,8 +938,8 @@ dummynet_task(void *context, int pending
 	}
 
 	/* Sweep pipes trying to expire idle flow_queues. */
-	for (i = 0; i < HASHSIZE; i++)
-		SLIST_FOREACH(pipe, &pipehash[i], next)
+	for (i = 0; i < HASHSIZE; i++) {
+		SLIST_FOREACH(pipe, &pipehash[i], next) {
 			if (pipe->idle_heap.elements > 0 &&
 			    DN_KEY_LT(pipe->idle_heap.p[0].key, pipe->V)) {
 				struct dn_flow_queue *q =
@@ -957,6 +950,8 @@ dummynet_task(void *context, int pending
 				q->S = q->F + 1;
 				pipe->sum -= q->fs->weight;
 			}
+		}
+	}
 
 	DUMMYNET_UNLOCK();
 
@@ -1055,8 +1050,8 @@ expire_queues(struct dn_flow_set *fs)
     if (fs->last_expired == time_uptime)
 	return 0 ;
     fs->last_expired = time_uptime ;
-    for (i = 0 ; i <= fs->rq_size ; i++) /* last one is overflow */
-	for (prev=NULL, q = fs->rq[i] ; q != NULL ; )
+    for (i = 0 ; i <= fs->rq_size ; i++) { /* last one is overflow */
+	for (prev=NULL, q = fs->rq[i] ; q != NULL ; ) {
 	    if (!QUEUE_IS_IDLE(q)) {
   		prev = q ;
   	        q = q->next ;
@@ -1070,6 +1065,8 @@ expire_queues(struct dn_flow_set *fs)
 		fs->rq_elements-- ;
 		free(old_q, M_DUMMYNET);
 	    }
+	}
+    }
     return initial_elements - fs->rq_elements ;
 }
 
@@ -1929,14 +1926,16 @@ config_pipe(struct dn_pipe *p)
 static void
 fs_remove_from_heap(struct dn_heap *h, struct dn_flow_set *fs)
 {
-    int i = 0, found = 0 ;
-    for (; i < h->elements ;)
+    int i, found;
+
+    for (i = found = 0 ; i < h->elements ;) {
 	if ( ((struct dn_flow_queue *)h->p[i].object)->fs == fs) {
 	    h->elements-- ;
 	    h->p[i] = h->p[h->elements] ;
 	    found++ ;
 	} else
 	    i++ ;
+    }
     if (found)
 	heapify(h);
 }
@@ -1947,17 +1946,16 @@ fs_remove_from_heap(struct dn_heap *h, s
 static void
 pipe_remove_from_heap(struct dn_heap *h, struct dn_pipe *p)
 {
-    if (h->elements > 0) {
-	int i = 0 ;
+	int i;
+
 	for (i=0; i < h->elements ; i++ ) {
-	    if (h->p[i].object == p) { /* found it */
-		h->elements-- ;
-		h->p[i] = h->p[h->elements] ;
-		heapify(h);
-		break ;
-	    }
+		if (h->p[i].object == p) { /* found it */
+			h->elements-- ;
+			h->p[i] = h->p[h->elements] ;
+			heapify(h);
+			break ;
+		}
 	}
-    }
 }
 
 /*
@@ -2017,14 +2015,16 @@ delete_pipe(struct dn_pipe *p)
 	SLIST_REMOVE(&pipehash[HASH(pipe->pipe_nr)], pipe, dn_pipe, next);
 
 	/* Remove all references to this pipe from flow_sets. */
-	for (i = 0; i < HASHSIZE; i++)
-	    SLIST_FOREACH(fs, &flowsethash[i], next)
+	for (i = 0; i < HASHSIZE; i++) {
+	    SLIST_FOREACH(fs, &flowsethash[i], next) {
 		if (fs->pipe == pipe) {
 			printf("dummynet: ++ ref to pipe %d from fs %d\n",
 			    p->pipe_nr, fs->fs_nr);
 			fs->pipe = NULL ;
 			purge_flow_set(fs, 0);
 		}
+	    }
+	}
 	fs_remove_from_heap(&ready_heap, &(pipe->fs));
 	purge_pipe(pipe); /* remove all data associated to this pipe */
 	/* remove reference to here from extract_heap and wfq_ready_heap */
@@ -2073,7 +2073,7 @@ dn_copy_set(struct dn_flow_set *set, cha
 
     DUMMYNET_LOCK_ASSERT();
 
-    for (i = 0 ; i <= set->rq_size ; i++)
+    for (i = 0 ; i <= set->rq_size ; i++) {
 	for (q = set->rq[i] ; q ; q = q->next, qp++ ) {
 	    if (q->hash_slot != i)
 		printf("dummynet: ++ at %d: wrong slot (have %d, "
@@ -2088,6 +2088,7 @@ dn_copy_set(struct dn_flow_set *set, cha
 	    qp->head = qp->tail = NULL ;
 	    qp->fs = NULL ;
 	}
+    }
     if (copied != set->rq_elements)
 	printf("dummynet: ++ wrong count, have %d should be %d\n",
 	    copied, set->rq_elements);
@@ -2137,7 +2138,7 @@ dummynet_get(struct sockopt *sopt)
 	DUMMYNET_UNLOCK();
 	buf = malloc(size, M_TEMP, M_WAITOK);
 	DUMMYNET_LOCK();
-	if (size == dn_calc_size())
+	if (size >= dn_calc_size())
 		break;
 	free(buf, M_TEMP);
 	buf = NULL;
@@ -2147,7 +2148,7 @@ dummynet_get(struct sockopt *sopt)
 	return ENOBUFS ;
     }
     bp = buf;
-    for (i = 0; i < HASHSIZE; i++)
+    for (i = 0; i < HASHSIZE; i++) {
 	SLIST_FOREACH(pipe, &pipehash[i], next) {
 		struct dn_pipe *pipe_bp = (struct dn_pipe *)bp;
 
@@ -2176,8 +2177,9 @@ dummynet_get(struct sockopt *sopt)
 		bp += sizeof(*pipe) ;
 		bp = dn_copy_set(&(pipe->fs), bp);
 	}
+    }
 
-    for (i = 0; i < HASHSIZE; i++)
+    for (i = 0; i < HASHSIZE; i++) {
 	SLIST_FOREACH(fs, &flowsethash[i], next) {
 		struct dn_flow_set *fs_bp = (struct dn_flow_set *)bp;
 
@@ -2189,6 +2191,7 @@ dummynet_get(struct sockopt *sopt)
 		bp += sizeof(*fs);
 		bp = dn_copy_set(fs, bp);
 	}
+    }
 
     DUMMYNET_UNLOCK();
 


More information about the svn-src-head mailing list