kern/82908: [ PATCH ] ip_carp should use ifnet_departure_event event

Dan Lukes dan at obluda.cz
Sat Jul 2 23:20:20 GMT 2005


>Number:         82908
>Category:       kern
>Synopsis:       [ PATCH ] ip_carp should use ifnet_departure_event event
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 02 23:20:18 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Dan Lukes
>Release:        FreeBSD 5.4-STABLE i386
>Organization:
Obludarium
>Environment:
System: FreeBSD 5.4-STABLE i386
src/sys/net/if.c,v 1.199.2.15 2005/04/15 01:51:44 cperciva
src/sys/netinet/ip_carp.h,v 1.1.2.1 2005/03/21 16:05:35 glebius
src/sys/netinet/ip_carp.c,v 1.21.2.3 2005/05/19 10:55:14 glebius

>Description:
	modify ip_carp to use ifnet_departure_event event handler
	instead of exporting of carp_ifdetach() to public
>How-To-Repeat:
	N/A
>Fix:

--- sys/net/if.c.ORIG	Sat Jul  2 01:36:12 2005
+++ sys/net/if.c	Sun Jul  3 00:45:46 2005
@@ -532,11 +532,6 @@
  	int found;
 
 	EVENTHANDLER_INVOKE(ifnet_departure_event, ifp);
-#ifdef DEV_CARP
-	/* Maybe hook to the generalized departure handler above?!? */
-	if (ifp->if_carp)
-		carp_ifdetach(ifp);
-#endif
 
 	/*
 	 * Remove routes and flush queues.
--- sys/netinet/ip_carp.c.ORIG	Tue May 31 23:39:41 2005
+++ sys/netinet/ip_carp.c	Sun Jul  3 00:42:34 2005
@@ -182,6 +182,8 @@
 		log(LOG_DEBUG, __VA_ARGS__);		\
 } while (0)
 
+static eventhandler_tag if_detach_event_tag = NULL;
+
 static void	carp_hmac_prepare(struct carp_softc *);
 static void	carp_hmac_generate(struct carp_softc *, u_int32_t *,
 		    unsigned char *);
@@ -772,12 +774,14 @@
 }
 
 /* Detach an interface from the carp.  */
-void
-carp_ifdetach(struct ifnet *ifp)
+static void
+carp_ifdetach(void *arg __unused, struct ifnet *ifp)
 {
 	struct carp_softc *sc;
 	struct carp_if *cif = (struct carp_if *)ifp->if_carp;
 
+	if ( ! ifp->if_carp)
+		return;
 	CARP_LOCK(cif);
 	TAILQ_FOREACH(sc, &cif->vhif_vrs, sc_list)
 		carpdetach(sc);
@@ -2138,11 +2142,19 @@
 	switch (type) {
 	case MOD_LOAD:
 		mtx_init(&carp_mtx, "carp_mtx", NULL, MTX_DEF);
+		if_detach_event_tag = EVENTHANDLER_REGISTER(ifnet_departure_event, 
+			carp_ifdetach, NULL, EVENTHANDLER_PRI_ANY);
+		if (if_detach_event_tag == NULL) {
+			mtx_destroy(&carp_mtx);
+			error = ENOMEM;
+			break;
+		}
 		LIST_INIT(&carpif_list);
 		if_clone_attach(&carp_cloner);
 		break;
 
 	case MOD_UNLOAD:
+		EVENTHANDLER_DEREGISTER(ifnet_departure_event, if_detach_event_tag);
 		if_clone_detach(&carp_cloner);
 		while (!LIST_EMPTY(&carpif_list))
 			carp_clone_destroy(&LIST_FIRST(&carpif_list)->sc_if);
--- sys/netinet/ip_carp.h.ORIG	Mon Mar 21 17:05:35 2005
+++ sys/netinet/ip_carp.h	Sun Jul  3 00:43:47 2005
@@ -148,7 +148,6 @@
 }
 
 #ifdef _KERNEL
-void		 carp_ifdetach (struct ifnet *);
 void		 carp_carpdev_state(void *);
 void		 carp_input (struct mbuf *, int);
 int		 carp6_input (struct mbuf **, int *, int);
--- patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list