virtio-net: add vlan receive state to RxFilterInfo
Stefan Fritsch just fixed a virtio-net driver bug [1], virtio-net won't filter out VLAN-tagged packets if VIRTIO_NET_F_CTRL_VLAN isn't negotiated. This patch added a new field to @RxFilterInfo to indicate vlan receive state ('normal', 'none', 'all'). If VIRTIO_NET_F_CTRL_VLAN isn't negotiated, vlan receive state will be 'all', then all VLAN-tagged packets will be received by guest. This patch also fixed a boundary issue in visiting vlan table. [1] http://lists.nongnu.org/archive/html/qemu-devel/2014-02/msg02604.html Signed-off-by: Amos Kong <akong@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
0b1eaa8803
commit
f7bc8ef809
@ -222,13 +222,33 @@ static char *mac_strdup_printf(const uint8_t *mac)
|
|||||||
mac[1], mac[2], mac[3], mac[4], mac[5]);
|
mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static intList *get_vlan_table(VirtIONet *n)
|
||||||
|
{
|
||||||
|
intList *list, *entry;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
list = NULL;
|
||||||
|
for (i = 0; i < MAX_VLAN >> 5; i++) {
|
||||||
|
for (j = 0; n->vlans[i] && j <= 0x1f; j++) {
|
||||||
|
if (n->vlans[i] & (1U << j)) {
|
||||||
|
entry = g_malloc0(sizeof(*entry));
|
||||||
|
entry->value = (i << 5) + j;
|
||||||
|
entry->next = list;
|
||||||
|
list = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
|
static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
|
||||||
{
|
{
|
||||||
VirtIONet *n = qemu_get_nic_opaque(nc);
|
VirtIONet *n = qemu_get_nic_opaque(nc);
|
||||||
|
VirtIODevice *vdev = VIRTIO_DEVICE(n);
|
||||||
RxFilterInfo *info;
|
RxFilterInfo *info;
|
||||||
strList *str_list, *entry;
|
strList *str_list, *entry;
|
||||||
intList *int_list, *int_entry;
|
int i;
|
||||||
int i, j;
|
|
||||||
|
|
||||||
info = g_malloc0(sizeof(*info));
|
info = g_malloc0(sizeof(*info));
|
||||||
info->name = g_strdup(nc->name);
|
info->name = g_strdup(nc->name);
|
||||||
@ -273,19 +293,15 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
|
|||||||
str_list = entry;
|
str_list = entry;
|
||||||
}
|
}
|
||||||
info->multicast_table = str_list;
|
info->multicast_table = str_list;
|
||||||
|
info->vlan_table = get_vlan_table(n);
|
||||||
|
|
||||||
int_list = NULL;
|
if (!((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features)) {
|
||||||
for (i = 0; i < MAX_VLAN >> 5; i++) {
|
info->vlan = RX_STATE_ALL;
|
||||||
for (j = 0; n->vlans[i] && j < 0x1f; j++) {
|
} else if (!info->vlan_table) {
|
||||||
if (n->vlans[i] & (1U << j)) {
|
info->vlan = RX_STATE_NONE;
|
||||||
int_entry = g_malloc0(sizeof(*int_entry));
|
} else {
|
||||||
int_entry->value = (i << 5) + j;
|
info->vlan = RX_STATE_NORMAL;
|
||||||
int_entry->next = int_list;
|
|
||||||
int_list = int_entry;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
info->vlan_table = int_list;
|
|
||||||
|
|
||||||
/* enable event notification after query */
|
/* enable event notification after query */
|
||||||
nc->rxfilter_notify_enabled = 1;
|
nc->rxfilter_notify_enabled = 1;
|
||||||
|
@ -4184,6 +4184,8 @@
|
|||||||
#
|
#
|
||||||
# @unicast: unicast receive state
|
# @unicast: unicast receive state
|
||||||
#
|
#
|
||||||
|
# @vlan: vlan receive state (Since 2.0)
|
||||||
|
#
|
||||||
# @broadcast-allowed: whether to receive broadcast
|
# @broadcast-allowed: whether to receive broadcast
|
||||||
#
|
#
|
||||||
# @multicast-overflow: multicast table is overflowed or not
|
# @multicast-overflow: multicast table is overflowed or not
|
||||||
@ -4207,6 +4209,7 @@
|
|||||||
'promiscuous': 'bool',
|
'promiscuous': 'bool',
|
||||||
'multicast': 'RxState',
|
'multicast': 'RxState',
|
||||||
'unicast': 'RxState',
|
'unicast': 'RxState',
|
||||||
|
'vlan': 'RxState',
|
||||||
'broadcast-allowed': 'bool',
|
'broadcast-allowed': 'bool',
|
||||||
'multicast-overflow': 'bool',
|
'multicast-overflow': 'bool',
|
||||||
'unicast-overflow': 'bool',
|
'unicast-overflow': 'bool',
|
||||||
|
@ -3407,6 +3407,7 @@ Each array entry contains the following:
|
|||||||
- "promiscuous": promiscuous mode is enabled (json-bool)
|
- "promiscuous": promiscuous mode is enabled (json-bool)
|
||||||
- "multicast": multicast receive state (one of 'normal', 'none', 'all')
|
- "multicast": multicast receive state (one of 'normal', 'none', 'all')
|
||||||
- "unicast": unicast receive state (one of 'normal', 'none', 'all')
|
- "unicast": unicast receive state (one of 'normal', 'none', 'all')
|
||||||
|
- "vlan": vlan receive state (one of 'normal', 'none', 'all') (Since 2.0)
|
||||||
- "broadcast-allowed": allow to receive broadcast (json-bool)
|
- "broadcast-allowed": allow to receive broadcast (json-bool)
|
||||||
- "multicast-overflow": multicast table is overflowed (json-bool)
|
- "multicast-overflow": multicast table is overflowed (json-bool)
|
||||||
- "unicast-overflow": unicast table is overflowed (json-bool)
|
- "unicast-overflow": unicast table is overflowed (json-bool)
|
||||||
@ -3424,6 +3425,7 @@ Example:
|
|||||||
"name": "vnet0",
|
"name": "vnet0",
|
||||||
"main-mac": "52:54:00:12:34:56",
|
"main-mac": "52:54:00:12:34:56",
|
||||||
"unicast": "normal",
|
"unicast": "normal",
|
||||||
|
"vlan": "normal",
|
||||||
"vlan-table": [
|
"vlan-table": [
|
||||||
4,
|
4,
|
||||||
0
|
0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user