svn commit: r281652 - projects/ifnet/sys/net
Gleb Smirnoff
glebius at FreeBSD.org
Fri Apr 17 12:27:36 UTC 2015
Author: glebius
Date: Fri Apr 17 12:27:34 2015
New Revision: 281652
URL: https://svnweb.freebsd.org/changeset/base/281652
Log:
- Instead of eventhandler for vlan child events, provide new ifop method.
- Instead of macros to obtain ID of vlan, vlan of ID or trunk of vlan
provide shim functions in if.c, and make the function pointers private
between if.c and if_vlan.c.
Modified:
projects/ifnet/sys/net/if.c
projects/ifnet/sys/net/if.h
projects/ifnet/sys/net/if_var.h
projects/ifnet/sys/net/if_vlan.c
projects/ifnet/sys/net/if_vlan_var.h
Modified: projects/ifnet/sys/net/if.c
==============================================================================
--- projects/ifnet/sys/net/if.c Fri Apr 17 12:22:44 2015 (r281651)
+++ projects/ifnet/sys/net/if.c Fri Apr 17 12:27:34 2015 (r281652)
@@ -2232,11 +2232,15 @@ link_init_sdl(struct ifnet *ifp, struct
return (sdl);
}
-void (*vlan_link_state_p)(struct ifnet *); /* XXX: private from if_vlan */
-void (*vlan_trunk_cap_p)(struct ifnet *); /* XXX: private from if_vlan */
+/*
+ * Function pointers to vlan(4) module.
+ * XXXGL: shouldn't we just make vlan(4) always in kernel?
+ */
+void (*vlan_link_state_p)(struct ifnet *);
+void (*vlan_trunk_cap_p)(struct ifnet *);
struct ifnet *(*vlan_trunkdev_p)(struct ifnet *);
-struct ifnet *(*vlan_devat_p)(struct ifnet *, uint16_t);
-int (*vlan_tag_p)(struct ifnet *, uint16_t *);
+struct ifnet *(*vlan_dev_p)(struct ifnet *, uint16_t);
+uint16_t (*vlan_vid_p)(struct ifnet *);
/*
* Handle a change in the interface link state. To avoid LORs
@@ -3775,6 +3779,34 @@ if_snd_prepend(if_t ifp, struct mbuf *m)
mtx_unlock(&ifq->ifq_mtx);
}
+int
+if_vlanid(if_t vifp, uint16_t *vid)
+{
+
+ if (if_type(vifp) != IFT_L2VLAN)
+ return (EINVAL);
+ *vid = (*vlan_vid_p)(vifp);
+ return (0);
+}
+
+if_t
+if_vlandev(if_t parent, uint16_t vid)
+{
+
+ if (parent->if_vlantrunk == NULL)
+ return (NULL);
+ return ((*vlan_dev_p)(parent, vid));
+}
+
+if_t
+if_vlantrunk(if_t vifp)
+{
+
+ if (if_type(vifp) != IFT_L2VLAN)
+ return (NULL);
+ return ((*vlan_trunkdev_p)(vifp));
+}
+
/*
* Implementation of if ops, that can be called from drivers.
*/
Modified: projects/ifnet/sys/net/if.h
==============================================================================
--- projects/ifnet/sys/net/if.h Fri Apr 17 12:22:44 2015 (r281651)
+++ projects/ifnet/sys/net/if.h Fri Apr 17 12:27:34 2015 (r281652)
@@ -599,6 +599,7 @@ typedef void (*if_qflush_t)(if_t);
typedef int (*if_resolvemulti_t)(if_t, struct sockaddr **,
struct sockaddr *);
typedef void (*if_reassign_t)(if_t, struct vnet *);
+typedef void (*if_vlan_event_t)(if_t, uint16_t, if_t);
enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS };
typedef int (*if_poll_t)(if_t, enum poll_cmd, int);
@@ -617,6 +618,7 @@ struct ifops {
if_qflush_t ifop_qflush; /* flush any queue */
if_resolvemulti_t ifop_resolvemulti; /* validate/resolve multicast */
if_reassign_t ifop_reassign; /* reassign to vnet routine */
+ if_vlan_event_t ifop_vlan_event;/* VLAN config/unconfig */
struct ifops *ifop_next;
uint8_t ifop_origin;
};
@@ -748,6 +750,13 @@ struct mbuf * if_snd_dequeue(if_t);
void if_snd_prepend(if_t, struct mbuf *);
/*
+ * vlan(4) interfaces extra API.
+ */
+int if_vlanid(if_t, uint16_t *);
+if_t if_vlandev(if_t, uint16_t);
+if_t if_vlantrunk(if_t);
+
+/*
* Type-enforcing inliners over if_getsoftc().
*/
static inline char *
Modified: projects/ifnet/sys/net/if_var.h
==============================================================================
--- projects/ifnet/sys/net/if_var.h Fri Apr 17 12:22:44 2015 (r281651)
+++ projects/ifnet/sys/net/if_var.h Fri Apr 17 12:27:34 2015 (r281652)
@@ -523,6 +523,14 @@ if_reassign(if_t ifp, struct vnet *new)
return (ifp->if_ops->ifop_reassign(ifp, new));
}
+static inline void
+if_vlan_event(if_t ifp, uint16_t vid, if_t vifp)
+{
+
+ if (ifp->if_ops->ifop_vlan_event != NULL)
+ ifp->if_ops->ifop_vlan_event(ifp, vid, vifp);
+}
+
#ifdef DEVICE_POLLING
static inline int
if_poll(if_t ifp, enum poll_cmd cmd, int count)
Modified: projects/ifnet/sys/net/if_vlan.c
==============================================================================
--- projects/ifnet/sys/net/if_vlan.c Fri Apr 17 12:22:44 2015 (r281651)
+++ projects/ifnet/sys/net/if_vlan.c Fri Apr 17 12:27:34 2015 (r281652)
@@ -73,6 +73,11 @@ __FBSDID("$FreeBSD$");
#include <netinet/if_ether.h>
#endif
+extern struct ifnet *(*vlan_dev_p)(struct ifnet *, uint16_t);
+extern uint16_t (*vlan_vid_p)(struct ifnet *);
+extern void (*vlan_trunk_cap_p)(struct ifnet *);
+extern struct ifnet *(*vlan_trunkdev_p)(struct ifnet *);
+
#define VLAN_DEF_HWIDTH 4
#define VLAN_IFFLAGS (IFF_BROADCAST | IFF_MULTICAST)
@@ -662,18 +667,17 @@ vlan_ifdetach(void *arg __unused, struct
/*
* Return the trunk device for a virtual interface.
*/
-static struct ifnet *
+static struct ifnet *
vlan_trunkdev(struct ifnet *ifp)
{
struct ifvlan *ifv;
- if (if_type(ifp) != IFT_L2VLAN)
- return (NULL);
ifv = ifp->if_softc;
- ifp = NULL;
VLAN_LOCK();
if (ifv->ifv_trunk)
ifp = PARENT(ifv);
+ else
+ ifp = NULL;
VLAN_UNLOCK();
return (ifp);
}
@@ -681,40 +685,35 @@ vlan_trunkdev(struct ifnet *ifp)
/*
* Return the 12-bit VLAN VID for this interface, for use by external
* components such as Infiniband.
- *
- * XXXRW: Note that the function name here is historical; it should be named
- * vlan_vid().
*/
-static int
-vlan_tag(struct ifnet *ifp, uint16_t *vidp)
+static uint16_t
+vlan_vid(struct ifnet *ifp)
{
struct ifvlan *ifv;
- if (if_type(ifp) != IFT_L2VLAN)
- return (EINVAL);
+ KASSERT(if_type(ifp) == IFT_L2VLAN, ("%s: %p is not a VLAN",
+ __func__, ifp));
ifv = ifp->if_softc;
- *vidp = ifv->ifv_vid;
- return (0);
+ return (ifv->ifv_vid);
}
/*
* Return the vlan device present at the specific VID.
*/
static struct ifnet *
-vlan_devat(struct ifnet *ifp, uint16_t vid)
+vlan_dev(struct ifnet *ifp, uint16_t vid)
{
struct ifvlantrunk *trunk;
struct ifvlan *ifv;
TRUNK_LOCK_READER;
trunk = ifp->if_vlantrunk;
- if (trunk == NULL)
- return (NULL);
- ifp = NULL;
TRUNK_RLOCK(trunk);
ifv = vlan_gethash(trunk, vid);
if (ifv)
ifp = ifv->ifv_ifp;
+ else
+ ifp = NULL;
TRUNK_RUNLOCK(trunk);
return (ifp);
}
@@ -750,8 +749,8 @@ vlan_modevent(module_t mod, int type, vo
vlan_link_state_p = vlan_link_state;
vlan_trunk_cap_p = vlan_trunk_capabilities;
vlan_trunkdev_p = vlan_trunkdev;
- vlan_tag_p = vlan_tag;
- vlan_devat_p = vlan_devat;
+ vlan_vid_p = vlan_vid;
+ vlan_dev_p = vlan_dev;
#ifndef VIMAGE
vlan_cloner = if_clone_advanced(vlanname, 0, vlan_clone_match,
vlan_clone_create, vlan_clone_destroy);
@@ -776,8 +775,8 @@ vlan_modevent(module_t mod, int type, vo
vlan_link_state_p = NULL;
vlan_trunk_cap_p = NULL;
vlan_trunkdev_p = NULL;
- vlan_tag_p = NULL;
- vlan_devat_p = NULL;
+ vlan_vid_p = NULL;
+ vlan_dev_p = NULL;
VLAN_LOCK_DESTROY();
if (bootverbose)
printf("vlan: unloaded\n");
@@ -1257,7 +1256,7 @@ vlan_config(struct ifvlan *ifv, struct i
(void)vlan_setmulti(ifp); /* XXX: VLAN lock held */
TRUNK_UNLOCK(trunk);
- EVENTHANDLER_INVOKE(vlan_config, p, ifv->ifv_vid);
+ if_vlan_event(p, vid, ifp);
return (error);
}
@@ -1342,7 +1341,7 @@ vlan_unconfig(struct ifnet *ifp, int dep
* to cleanup anyway.
*/
if (parent != NULL)
- EVENTHANDLER_INVOKE(vlan_unconfig, parent, ifv->ifv_vid);
+ if_vlan_event(parent, ifv->ifv_vid, NULL);
}
/* Handle a reference counted flag that should be set on the parent as well */
Modified: projects/ifnet/sys/net/if_vlan_var.h
==============================================================================
--- projects/ifnet/sys/net/if_vlan_var.h Fri Apr 17 12:22:44 2015 (r281651)
+++ projects/ifnet/sys/net/if_vlan_var.h Fri Apr 17 12:27:34 2015 (r281652)
@@ -73,7 +73,6 @@ struct vlanreq {
#define SIOCSETVLAN SIOCSIFGENERIC
#define SIOCGETVLAN SIOCGIFGENERIC
-#ifdef _KERNEL
/*
* Drivers that are capable of adding and removing the VLAN header
* in hardware indicate they support this by marking IFCAP_VLAN_HWTAGGING
@@ -109,27 +108,4 @@ struct vlanreq {
* stripping/insertion by marking IFCAP_VLAN_HWTAGGING in
* if_capabilities.
*/
-
-#define VLAN_TRUNKDEV(_ifp) \
- (_ifp)->if_type == IFT_L2VLAN ? (*vlan_trunkdev_p)((_ifp)) : NULL
-#define VLAN_TAG(_ifp, _vid) \
- (_ifp)->if_type == IFT_L2VLAN ? (*vlan_tag_p)((_ifp), (_vid)) : EINVAL
-#define VLAN_DEVAT(_ifp, _vid) \
- (_ifp)->if_vlantrunk != NULL ? (*vlan_devat_p)((_ifp), (_vid)) : NULL
-
-extern void (*vlan_trunk_cap_p)(struct ifnet *);
-extern struct ifnet *(*vlan_trunkdev_p)(struct ifnet *);
-extern struct ifnet *(*vlan_devat_p)(struct ifnet *, uint16_t);
-extern int (*vlan_tag_p)(struct ifnet *, uint16_t *);
-
-#ifdef _SYS_EVENTHANDLER_H_
-/* VLAN state change events */
-typedef void (*vlan_config_fn)(void *, struct ifnet *, uint16_t);
-typedef void (*vlan_unconfig_fn)(void *, struct ifnet *, uint16_t);
-EVENTHANDLER_DECLARE(vlan_config, vlan_config_fn);
-EVENTHANDLER_DECLARE(vlan_unconfig, vlan_unconfig_fn);
-#endif /* _SYS_EVENTHANDLER_H_ */
-
-#endif /* _KERNEL */
-
#endif /* _NET_IF_VLAN_VAR_H_ */
More information about the svn-src-projects
mailing list