Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Jul 2006 10:45:53 GMT
From:      Paolo Pisati <piso@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 100716 for review
Message-ID:  <200607061045.k66AjrQv063123@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=100716

Change 100716 by piso@piso_newluxor on 2006/07/06 10:45:40

	Queue(3)-ify handler_chain: now it's just a matter of
	style(9)-ify the rest and cleanup.

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#12 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#12 edit

Differences ...

==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#12 (text+ko) ====

@@ -60,11 +60,10 @@
 #include <sys/types.h>
 
 /* protocol and userland module handlers chains */
-struct chain    handler_chain;
+LIST_HEAD(handler_chain, proto_handler) handler_chain = LIST_HEAD_INITIALIZER(foo);
 #ifdef _KERNEL
 struct rwlock   handler_rw;
 #endif
-
 SLIST_HEAD(dll_chain, dll) dll_chain = SLIST_HEAD_INITIALIZER(foo); 
 
 #ifdef _KERNEL
@@ -166,37 +165,36 @@
 }
 
 static int
-_attach_handler(struct chain *c, struct proto_handler *p) {
-	struct proto_handler **b;
-	int i = 0;
+_attach_handler(struct proto_handler *p) {
+	struct proto_handler *b;
 
 	LIBALIAS_WLOCK_ASSERT();	
-	b = (struct proto_handler **)&c->chain;
-	p->next = NULL; /* i'm paranoid... */
-	for(; *b != NULL; b = &((*b)->next), i++) {
-		if (((*b)->pri == p->pri) && ((*b)->dir == p->dir) &&
-			((*b)->proto == p->proto))
+	LIST_FOREACH(b, &handler_chain, entries) {
+		if ((b->pri == p->pri) && (b->dir == p->dir) &&
+			(b->proto == p->proto))
 			return (EHDCON); /* priority conflict */
-		if ((*b)->pri > p->pri) {
-			p->next = *b; break;
+		if (b->pri > p->pri) {
+			LIST_INSERT_BEFORE(b, p, entries);
+			return (OK);
 		}
 	}
 	/* end of list or got right position, insert here */
-	*b = p;
+	LIST_INSERT_AFTER(b, p, entries);
 	return (OK);
 }
 
 static int
-_detach_handler(struct chain *c, struct proto_handler *p) {
-	struct proto_handler **b;
+_detach_handler(struct proto_handler *p) {
+	struct proto_handler *b, *b_tmp;;
 
 	LIBALIAS_WLOCK_ASSERT();	
-	b = (struct proto_handler **)&c->chain;
-	for(; (*b != NULL) && (*b != p); b = &((*b)->next))
-		;
-	if (*b == p) *b = p->next;		
-	else return (EHDNOF); /* handler not found */
-	return (OK);
+	LIST_FOREACH_SAFE(b, &handler_chain, entries, b_tmp) {
+		if (b == p) {
+			LIST_REMOVE(b, entries);
+			return (OK);
+		}
+	}
+	return (EHDNOF); /* handler not found */
 }
 
 int
@@ -206,7 +204,7 @@
 	LIBALIAS_WLOCK();
 	for (i=0; 1; i++) {
 		if (*((int *)&_p[i]) == EOH) break;
-		res = _attach_handler(&handler_chain, &_p[i]);
+		res = _attach_handler(&_p[i]);
 		if (res != OK) break;
 	}
 	LIBALIAS_WUNLOCK();
@@ -220,7 +218,7 @@
 	LIBALIAS_WLOCK();
 	for (i=0; 1; i++) {
 		if (*((int *)&_p[i]) == EOH) break;
-		res = _detach_handler(&handler_chain, &_p[i]);
+		res = _detach_handler(&_p[i]);
 		if (res != OK) break;
 	}
 	LIBALIAS_WUNLOCK();
@@ -232,7 +230,7 @@
 	int res = NOK;
 
 	LIBALIAS_WLOCK();
-	res = _detach_handler(&handler_chain, _p);
+	res = _detach_handler(_p);
 	LIBALIAS_WUNLOCK();
 	return (res);
 }
@@ -240,15 +238,17 @@
 int
 find_handler(int8_t dir, int8_t proto, struct libalias *la, struct ip *pip, struct alias_data *ad) {
 	struct proto_handler *p;
-	int err;
+	int err = EHDNOF;
 
 	LIBALIAS_RLOCK();
-	for (p = handler_chain.chain, err = EHDNOF; p != NULL; p = p->next)
+	
+	LIST_FOREACH(p, &handler_chain, entries) {
 		if ((p->dir & dir) && (p->proto & proto))
 			if (p->fingerprint(la, pip, ad) == OK) {
 				err = p->protohandler(la, pip, ad);
 				break;
 			}
+	}
 	LIBALIAS_RUNLOCK();
 	return (err);	
 }
@@ -256,7 +256,7 @@
 struct proto_handler *
 first_handler(void) {
 	
-	return (handler_chain.chain);	
+	return (LIST_FIRST(&handler_chain));	
 }
 
 /* dll manipulation code - this code is not thread safe... */

==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#12 (text+ko) ====

@@ -72,15 +72,10 @@
 		 struct ip *pip, struct alias_data *ah);
 	int (*protohandler)(struct libalias *la,                /* Aliasing * function. */
 		 struct ip *pip, struct alias_data *ah);                 
-	struct proto_handler *next;
+	LIST_ENTRY(proto_handler) entries;
 };
 
 
-// XXX - convert it to use queue(3)
-struct chain {
-	void            *chain;	
-};
-
 /* 
  * Used only in userland when libalias needs to keep track of all
  * module loaded. In kernel land (kld mode) we don't need to care



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607061045.k66AjrQv063123>