diff options
author | glebius <glebius@FreeBSD.org> | 2012-10-16 13:37:54 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2012-10-16 13:37:54 +0000 |
commit | 05f24a6b77a43334f14f31cd33a4f3e34a418ea2 (patch) | |
tree | 0f54a9446bfe2083d3c0a3f744318b2be8a0db05 /sys/net/if_clone.h | |
parent | 745884b065065ffc8847d3ea463bf751ffcaf863 (diff) | |
download | FreeBSD-src-05f24a6b77a43334f14f31cd33a4f3e34a418ea2.zip FreeBSD-src-05f24a6b77a43334f14f31cd33a4f3e34a418ea2.tar.gz |
Make the "struct if_clone" opaque to users of the cloning API. Users
now use function calls:
if_clone_simple()
if_clone_advanced()
to initialize a cloner, instead of macros that initialize if_clone
structure.
Discussed with: brooks, bz, 1 year ago
Diffstat (limited to 'sys/net/if_clone.h')
-rw-r--r-- | sys/net/if_clone.h | 97 |
1 files changed, 26 insertions, 71 deletions
diff --git a/sys/net/if_clone.h b/sys/net/if_clone.h index 4278814..7159421 100644 --- a/sys/net/if_clone.h +++ b/sys/net/if_clone.h @@ -35,87 +35,42 @@ #ifdef _KERNEL -#define IFC_CLONE_INITIALIZER(name, data, maxunit, \ - attach, match, create, destroy) \ - { \ - .ifc_name = name, \ - .ifc_maxunit = maxunit, \ - .ifc_data = data, \ - .ifc_attach = attach, \ - .ifc_match = match, \ - .ifc_create = create, \ - .ifc_destroy = destroy, \ - } - -/* - * Structure describing a `cloning' interface. - * - * List of locks - * (c) const until freeing - * (d) driver specific data, may need external protection. - * (e) locked by if_cloners_mtx - * (i) locked by ifc_mtx mtx - */ -struct if_clone { - LIST_ENTRY(if_clone) ifc_list; /* (e) On list of cloners */ - const char *ifc_name; /* (c) Name of device, e.g. `gif' */ - int ifc_maxunit; /* (c) Maximum unit number */ - struct unrhdr *ifc_unrhdr; /* (c) alloc_unr(9) header */ - void *ifc_data; /* (*) Data for ifc_* functions. */ - - /* (c) Driver specific cloning functions. Called with no locks held. */ - void (*ifc_attach)(struct if_clone *); - int (*ifc_match)(struct if_clone *, const char *); - int (*ifc_create)(struct if_clone *, char *, size_t, caddr_t); - int (*ifc_destroy)(struct if_clone *, struct ifnet *); - - long ifc_refcnt; /* (i) Refrence count. */ - struct mtx ifc_mtx; /* Mutex to protect members. */ - LIST_HEAD(, ifnet) ifc_iflist; /* (i) List of cloned interfaces */ -}; - -void if_clone_init(void); -int if_clone_attach(struct if_clone *); +struct if_clone; + +/* Methods. */ +typedef int ifc_match_t(struct if_clone *, const char *); +typedef int ifc_create_t(struct if_clone *, char *, size_t, caddr_t); +typedef int ifc_destroy_t(struct if_clone *, struct ifnet *); + +typedef int ifcs_create_t(struct if_clone *, int, caddr_t); +typedef void ifcs_destroy_t(struct ifnet *); + +/* Interface cloner (de)allocating functions. */ +struct if_clone * + if_clone_advanced(const char *, u_int, ifc_match_t, ifc_create_t, + ifc_destroy_t); +struct if_clone * + if_clone_simple(const char *, ifcs_create_t, ifcs_destroy_t, u_int); void if_clone_detach(struct if_clone *); -void vnet_if_clone_init(void); - -int if_clone_create(char *, size_t, caddr_t); -int if_clone_destroy(const char *); -int if_clone_destroyif(struct if_clone *, struct ifnet *); -int if_clone_list(struct if_clonereq *); +/* Unit (de)allocating fucntions. */ int ifc_name2unit(const char *name, int *unit); int ifc_alloc_unit(struct if_clone *, int *); void ifc_free_unit(struct if_clone *, int); -/* - * The ifc_simple functions, structures, and macros implement basic - * cloning as in 5.[012]. - */ - -struct ifc_simple_data { - int ifcs_minifs; /* minimum number of interfaces */ - - int (*ifcs_create)(struct if_clone *, int, caddr_t); - void (*ifcs_destroy)(struct ifnet *); -}; - -/* interface clone event */ +/* Interface clone event. */ typedef void (*if_clone_event_handler_t)(void *, struct if_clone *); EVENTHANDLER_DECLARE(if_clone_event, if_clone_event_handler_t); -#define IFC_SIMPLE_DECLARE(name, minifs) \ -struct ifc_simple_data name##_cloner_data = \ - {minifs, name##_clone_create, name##_clone_destroy}; \ -struct if_clone name##_cloner = \ - IFC_CLONE_INITIALIZER(#name, &name##_cloner_data, IF_MAXUNIT, \ - ifc_simple_attach, ifc_simple_match, ifc_simple_create, ifc_simple_destroy) +/* The below interfaces used only by net/if.c. */ +void if_clone_init(void); +void vnet_if_clone_init(void); +int if_clone_create(char *, size_t, caddr_t); +int if_clone_destroy(const char *); +int if_clone_list(struct if_clonereq *); -void ifc_simple_attach(struct if_clone *); -int ifc_simple_match(struct if_clone *, const char *); -int ifc_simple_create(struct if_clone *, char *, size_t, caddr_t); -int ifc_simple_destroy(struct if_clone *, struct ifnet *); +/* The below interface used only by epair(4). */ +int if_clone_destroyif(struct if_clone *, struct ifnet *); #endif /* _KERNEL */ - #endif /* !_NET_IF_CLONE_H_ */ |