Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F115730836
D37289.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D37289.diff
View Options
diff --git a/usr.sbin/bhyve/net_backends.c b/usr.sbin/bhyve/net_backends.c
--- a/usr.sbin/bhyve/net_backends.c
+++ b/usr.sbin/bhyve/net_backends.c
@@ -168,10 +168,12 @@
/* Size of backend-specific private data. */
size_t priv_size;
- /* Room for backend-specific data. */
- char opaque[0];
+ /* Backend-specific private data follows. */
};
+#define NET_BE_PRIV(be) ((void *)((be) + 1))
+#define NET_BE_SIZE(be) (sizeof(*be) + (be)->priv_size)
+
SET_DECLARE(net_backend_set, struct net_backend);
#define VNET_HDR_LEN sizeof(struct virtio_net_rxhdr)
@@ -207,7 +209,7 @@
static void
tap_cleanup(struct net_backend *be)
{
- struct tap_priv *priv = (struct tap_priv *)be->opaque;
+ struct tap_priv *priv = NET_BE_PRIV(be);
if (priv->mevp) {
mevent_delete(priv->mevp);
@@ -222,7 +224,7 @@
tap_init(struct net_backend *be, const char *devname,
nvlist_t *nvl __unused, net_be_rxeof_t cb, void *param)
{
- struct tap_priv *priv = (struct tap_priv *)be->opaque;
+ struct tap_priv *priv = NET_BE_PRIV(be);
char tbuf[80];
int opt = 1;
#if defined(INET6) || defined(INET)
@@ -323,7 +325,7 @@
static ssize_t
tap_peek_recvlen(struct net_backend *be)
{
- struct tap_priv *priv = (struct tap_priv *)be->opaque;
+ struct tap_priv *priv = NET_BE_PRIV(be);
ssize_t ret;
if (priv->bbuflen > 0) {
@@ -353,7 +355,7 @@
static ssize_t
tap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
{
- struct tap_priv *priv = (struct tap_priv *)be->opaque;
+ struct tap_priv *priv = NET_BE_PRIV(be);
ssize_t ret;
if (priv->bbuflen > 0) {
@@ -381,7 +383,7 @@
static void
tap_recv_enable(struct net_backend *be)
{
- struct tap_priv *priv = (struct tap_priv *)be->opaque;
+ struct tap_priv *priv = NET_BE_PRIV(be);
mevent_enable(priv->mevp);
}
@@ -389,7 +391,7 @@
static void
tap_recv_disable(struct net_backend *be)
{
- struct tap_priv *priv = (struct tap_priv *)be->opaque;
+ struct tap_priv *priv = NET_BE_PRIV(be);
mevent_disable(priv->mevp);
}
@@ -453,7 +455,7 @@
ng_init(struct net_backend *be, const char *devname __unused,
nvlist_t *nvl, net_be_rxeof_t cb, void *param)
{
- struct tap_priv *p = (struct tap_priv *)be->opaque;
+ struct tap_priv *p = NET_BE_PRIV(be);
struct ngm_connect ngc;
const char *value, *nodename;
int sbsz;
@@ -629,7 +631,7 @@
{
int err;
struct nmreq req;
- struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
+ struct netmap_priv *priv = NET_BE_PRIV(be);
nmreq_init(&req, priv->ifname);
req.nr_cmd = NETMAP_BDG_VNET_HDR;
@@ -686,7 +688,7 @@
netmap_init(struct net_backend *be, const char *devname,
nvlist_t *nvl __unused, net_be_rxeof_t cb, void *param)
{
- struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
+ struct netmap_priv *priv = NET_BE_PRIV(be);
strlcpy(priv->ifname, devname, sizeof(priv->ifname));
priv->ifname[sizeof(priv->ifname) - 1] = '\0';
@@ -717,7 +719,7 @@
static void
netmap_cleanup(struct net_backend *be)
{
- struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
+ struct netmap_priv *priv = NET_BE_PRIV(be);
if (priv->mevp) {
mevent_delete(priv->mevp);
@@ -732,7 +734,7 @@
netmap_send(struct net_backend *be, const struct iovec *iov,
int iovcnt)
{
- struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
+ struct netmap_priv *priv = NET_BE_PRIV(be);
struct netmap_ring *ring;
ssize_t totlen = 0;
int nm_buf_size;
@@ -811,7 +813,7 @@
static ssize_t
netmap_peek_recvlen(struct net_backend *be)
{
- struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
+ struct netmap_priv *priv = NET_BE_PRIV(be);
struct netmap_ring *ring = priv->rx;
uint32_t head = ring->head;
ssize_t totlen = 0;
@@ -831,7 +833,7 @@
static ssize_t
netmap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
{
- struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
+ struct netmap_priv *priv = NET_BE_PRIV(be);
struct netmap_slot *slot = NULL;
struct netmap_ring *ring;
uint8_t *iov_frag_buf;
@@ -898,7 +900,7 @@
static void
netmap_recv_enable(struct net_backend *be)
{
- struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
+ struct netmap_priv *priv = NET_BE_PRIV(be);
mevent_enable(priv->mevp);
}
@@ -906,7 +908,7 @@
static void
netmap_recv_disable(struct net_backend *be)
{
- struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
+ struct netmap_priv *priv = NET_BE_PRIV(be);
mevent_disable(priv->mevp);
}
@@ -1021,7 +1023,7 @@
return (EINVAL);
}
- nbe = calloc(1, sizeof(*nbe) + tbe->priv_size);
+ nbe = calloc(1, NET_BE_SIZE(tbe));
*nbe = *tbe; /* copy the template */
nbe->fd = -1;
nbe->sc = param;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 28, 8:00 PM (2 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17830058
Default Alt Text
D37289.diff (4 KB)
Attached To
Mode
D37289: bhyve: Define an accessor for net backend private data
Attached
Detach File
Event Timeline
Log In to Comment