Net patches
The following changes since commit 5fdb4671b08e0d1631447e81348b2b50a6b85bf7:
Merge remote-tracking branch 'remotes/ehabkost/tags/x86-pull-request' into staging (2015-10-06 13:42:33 +0100)
are available in the git repository at:
https://github.com/jasowang/qemu.git tags/net-pull-request
for you to fetch changes up to 89b1273742f45c30927df203532fca0d9a3e1af7:
tests: add test cases for netfilter object (2015-10-12 13:34:32 +0800)
----------------------------------------------------------------
----------------------------------------------------------------
Dana Rubin (1):
net/vmxnet3: Refine l2 header validation
Jason Wang (1):
e1000: use alias for default model
Shmulik Ladkani (2):
vmxnet3: Support reading IMR registers on bar0
vmxnet3: Add support for VMXNET3_CMD_GET_ADAPTIVE_RING_INFO command
Yang Hongyang (10):
vl.c: init delayed object after net_init_clients init/cleanup of netfilter object
netfilter: hook packets before net queue send
net: merge qemu_deliver_packet and qemu_deliver_packet_iov net/queue: introduce NetQueueDeliverFunc
netfilter: add an API to pass the packet to next filter
netfilter: print filter info associate with the netdev net/queue: export qemu_net_queue_append_iov
netfilter: add a netbuffer filter
tests: add test cases for netfilter object
hw/net/e1000.c | 8 +- hw/net/vmxnet3.c | 19 +++- hw/net/vmxnet3.h | 6 +- hw/net/vmxnet_tx_pkt.c | 19 +++- include/net/filter.h | 77 ++++++++++++++++ include/net/net.h | 6 +- include/net/queue.h | 20 ++++- include/qemu/typedefs.h | 1 + net/Makefile.objs | 2 + net/filter-buffer.c | 186 ++++++++++++++++++++++++++++++++++++++ net/filter.c | 233 ++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 121 +++++++++++++++++++------ net/queue.c | 24 +++-- qapi-schema.json | 20 +++++ qdev-monitor.c | 1 + qemu-options.hx | 17 ++++ tests/.gitignore | 1 + tests/Makefile | 2 + tests/test-netfilter.c | 200 +++++++++++++++++++++++++++++++++++++++++ vl.c | 19 ++-- 20 files changed, 917 insertions(+), 65 deletions(-) create mode 100644 include/net/filter.h create mode 100644 net/filter-buffer.c create mode 100644 net/filter.c create mode 100644 tests/test-netfilter.c
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 01/14] net/vmxnet3: Refine l2 header validation
From: Dana Rubin <[email protected]>
Validation of l2 header length assumed minimal packet size as eth_header + 2 * vlan_header regardless of the actual protocol.
This caused crash for valid non-IP packets shorter than 22 bytes, as 'tx_pkt->packet_type' hasn't been assigned for such packets, and 'vmxnet3_on_tx_done_update_stats()' expects it to be properly set.
Refine header length validation in 'vmxnet_tx_pkt_parse_headers'. Check its return value during packet processing flow.
As a side effect, in case IPv4 and IPv6 header validation failure, corrupt packets will be dropped.
--- hw/net/vmxnet3.c | 4 +--- hw/net/vmxnet_tx_pkt.c | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-)
hw/net/vmxnet3.c +1 -3
@@ -729,9 +729,7 @@ static void vmxnet3_process_tx_queue(VMXNET3State *s, int qidx) }if (txd.eop) { -if (!s->skip_current_tx_pkt) { -vmxnet_tx_pkt_parse (s->tx_pkt); - +if (!s->skip_current_tx_pkt &&vmxnet_tx_pkt_parse (s->tx_pkt)) {if (s->needs_vlan) {vmxnet_tx_pkt_setup_vlan_header (s->tx_pkt, s->tci); }
hw/net/vmxnet_tx_pkt.c +16 -3
@@ -142,11 +142,24 @@ static bool vmxnet_tx_pkt_parse_headers(struct VmxnetTxPkt *pkt) bytes_read =iov_to_buf (pkt->raw, pkt->raw_frags,0 , l2_hdr->iov_base,ETH_MAX_L2_HDR_LEN ); -if (bytes_read <ETH_MAX_L2_HDR_LEN ) { +if (bytes_read <sizeof (struct eth_header )) { + l2_hdr->iov_len =0 ; +return false; + } + + l2_hdr->iov_len =sizeof (struct eth_header ); +switch (be16_to_cpu (PKT_GET_ETH_HDR (l2_hdr->iov_base)->h_proto)) { +case ETH_P_VLAN : + l2_hdr->iov_len +=sizeof (struct vlan_header ); +break ; +case ETH_P_DVLAN : + l2_hdr->iov_len +=2 *sizeof (struct vlan_header ); +break ; + } + +if (bytes_read < l2_hdr->iov_len) { l2_hdr->iov_len =0 ;return false; - }else { - l2_hdr->iov_len =eth_get_l2_hdr_length (l2_hdr->iov_base); } l3_proto =eth_get_l3_proto (l2_hdr->iov_base, l2_hdr->iov_len);
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 02/14] vmxnet3: Support reading IMR registers on bar0
In reply to Jason WangFrom: Shmulik Ladkani <[email protected]>
Instead of asserting, return the actual IMR register value. This is aligned with what's returned on ESXi.
--- hw/net/vmxnet3.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/net/vmxnet3.c +5 -1
@@ -1163,9 +1163,13 @@ vmxnet3_io_bar0_write(void *opaque, hwaddr addr,static uint64_t vmxnet3_io_bar0_read (void *opaque,hwaddr addr,unsigned size) { +VMXNET3State *s = opaque; +if (VMW_IS_MULTIREG_ADDR (addr,VMXNET3_REG_IMR ,VMXNET3_MAX_INTRS ,VMXNET3_REG_ALIGN )) { -g_assert_not_reached (); +int l =VMW_MULTIREG_IDX_BY_ADDR (addr,VMXNET3_REG_IMR , +VMXNET3_REG_ALIGN ); +return s->interrupt_states[l].is_masked; }VMW_CBPRN ("BAR0 unknown read [%" PRIx64"], size %d" , addr, size);
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 03/14] e1000: use alias for default model
In reply to Jason WangInstead of duplicating the "e1000-82540em" device model as "e1000", make the latter an alias for the former.
--- hw/net/e1000.c | 8 +------- qdev-monitor.c | 1 + 2 files changed, 2 insertions(+), 7 deletions(-)
hw/net/e1000.c +1 -7
@@ -1647,7 +1647,7 @@ static const TypeInfo e1000_base_info = {static const E1000Info e1000_devices[] = { { - .name ="e1000-82540em" , + .name ="e1000" , .device_id =E1000_DEV_ID_82540EM , .revision =0x03 , .phy_id2 = E1000_PHY_ID2_8254xx_DEFAULT,
@@ -1666,11 +1666,6 @@ static const E1000Info e1000_devices[] = { }, }; -static const TypeInfo e1000_default_info = { - .name ="e1000" , - .parent ="e1000-82540em" , -}; -static void e1000_register_types (void ) {int i;
@@ -1688,7 +1683,6 @@ static void e1000_register_types(void)type_register (&type_info); } -type_register_static (&e1000_default_info); }type_init (e1000_register_types)
qdev-monitor.c +1 -0
@@ -50,6 +50,7 @@ static const QDevAlias qdev_alias_table[] = { { "lsi53c895a", "lsi" }, { "ich9-ahci", "ahci" }, { "kvm-pci-assign", "pci-assign" }, + { "e1000", "e1000-82540em" }, { } };
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 04/14] vmxnet3: Add support for VMXNET3_CMD_GET_ADAPTIVE_RING_INFO command
In reply to Jason WangFrom: Shmulik Ladkani <[email protected]>
Some drivers (e.g. vmware-tools) issue the VMXNET3_CMD_GET_ADAPTIVE_RING_INFO command.
Currently, due to lack of support, a bogus value (-1) is returned.
Support this command, returning the "adaptive-ring disabled" flag.
--- hw/net/vmxnet3.c | 9 +++++++++ hw/net/vmxnet3.h | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-)
hw/net/vmxnet3.c +9 -0
@@ -1631,6 +1631,11 @@ static void vmxnet3_handle_command(VMXNET3State *s, uint64_t cmd)VMW_CBPRN ("Set: VMXNET3_CMD_GET_CONF_INTR - interrupt configuration" );break ; +case VMXNET3_CMD_GET_ADAPTIVE_RING_INFO : +VMW_CBPRN ("Set: VMXNET3_CMD_GET_ADAPTIVE_RING_INFO - " +"adaptive ring info flags" ); +break ; +default :VMW_CBPRN ("Received unknown command: %" PRIx64, cmd);break ;
@@ -1670,6 +1675,10 @@ static uint64_t vmxnet3_get_command_status(VMXNET3State *s) ret =vmxnet3_get_interrupt_config (s);break ; +case VMXNET3_CMD_GET_ADAPTIVE_RING_INFO : + ret =VMXNET3_DISABLE_ADAPTIVE_RING ; +break ; +default :VMW_WRPRN ("Received request for unknown command: %x" , s->last_command); ret =-1 ;
hw/net/vmxnet3.h +5 -1
@@ -198,9 +198,13 @@ enum {VMXNET3_CMD_GET_DID_LO ,/* 0xF00D0005 */ VMXNET3_CMD_GET_DID_HI ,/* 0xF00D0006 */ VMXNET3_CMD_GET_DEV_EXTRA_INFO ,/* 0xF00D0007 */ - VMXNET3_CMD_GET_CONF_INTR /* 0xF00D0008 */ +VMXNET3_CMD_GET_CONF_INTR ,/* 0xF00D0008 */ + VMXNET3_CMD_GET_ADAPTIVE_RING_INFO /* 0xF00D0009 */ }; +/* Adaptive Ring Info Flags */ +#define VMXNET3_DISABLE_ADAPTIVE_RING 1 +/* * Little Endian layout of bitfields - * Byte 0 : 7.....len.....0
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 05/14] vl.c: init delayed object after net_init_clients
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
Init delayed object after net_init_clients, because netfilters need to be initialized after net clients initialized.
--- vl.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
vl.c +8 -7
@@ -2767,13 +2767,14 @@ static bool object_create_initial(const char *type)if (g_str_equal (type,"rng-egd" )) {return false; } +/* TODO: implement netfilters */ return true; }/* * The remainder of object creation happens after the -* creation of chardev, fsdev and device data types. +* creation of chardev, fsdev, net clients and device data types. */ static bool object_create_delayed (const char *type) {
@@ -4286,12 +4287,6 @@ int main(int argc, char **argv, char **envp)exit (0 ); } -if (qemu_opts_foreach (qemu_find_opts ("object" ), - object_create, - object_create_delayed,NULL )) { -exit (1 ); - } - machine_opts =qemu_get_machine_opts ();if (qemu_opt_foreach (machine_opts, machine_set_property, current_machine,NULL )) {
@@ -4397,6 +4392,12 @@ int main(int argc, char **argv, char **envp)exit (1 ); } +if (qemu_opts_foreach (qemu_find_opts ("object" ), + object_create, + object_create_delayed,NULL )) { +exit (1 ); + } +#ifdef CONFIG_TPM if (tpm_init () <0 ) {exit (1 );
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 06/14] init/cleanup of netfilter object
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
Add a netfilter object based on QOM.
A netfilter is attached to a netdev, captures all network packets that pass through the netdev. When we delete the netdev, we also delete the netfilter object attached to it, because if the netdev is removed, the filter which attached to it is useless.
--- include/net/filter.h | 61 +++++++++++++++++++++ include/net/net.h | 1 + include/qemu/typedefs.h | 1 + net/Makefile.objs | 1 + net/filter.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 7 +++ qapi-schema.json | 20 +++++++ 7 files changed, 229 insertions(+) create mode 100644 include/net/filter.h create mode 100644 net/filter.c
include/net/filter.h new file +61 -0
@@ -0,0 +1,61 @@ +/* +* Copyright (c) 2015 FUJITSU LIMITED +* Author: Yang Hongyang <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_NET_FILTER_H +#define QEMU_NET_FILTER_H + +#include "qom/object.h" +#include "qemu-common.h" +#include "qemu/typedefs.h" +#include "net/queue.h" + +#define TYPE_NETFILTER "netfilter" +#define NETFILTER (obj) \ + OBJECT_CHECK(NetFilterState, (obj), TYPE_NETFILTER) +#define NETFILTER_GET_CLASS (obj) \ + OBJECT_GET_CLASS(NetFilterClass, (obj), TYPE_NETFILTER) +#define NETFILTER_CLASS (klass) \ + OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER) + +typedef void (FilterSetup ) (NetFilterState *nf,Error **errp); +typedef void (FilterCleanup ) (NetFilterState *nf); +/* +* Return: +* 0: finished handling the packet, we should continue +* size: filter stolen this packet, we stop pass this packet further +*/ +typedef ssize_t (FilterReceiveIOV )(NetFilterState *nc, +NetClientState *sender, +unsigned flags, +const struct iovec *iov, +int iovcnt, +NetPacketSent *sent_cb); + +typedef struct NetFilterClass { +ObjectClass parent_class; + +/* optional */ +FilterSetup *setup; +FilterCleanup *cleanup; +/* mandatory */ +FilterReceiveIOV *receive_iov; +}NetFilterClass ; + + +struct NetFilterState { +/* private */ +Object parent; + +/* protected */ +char *netdev_id; +NetClientState *netdev; +NetFilterDirection direction; +QTAILQ_ENTRY (NetFilterState) next; +}; + +#endif /* QEMU_NET_FILTER_H */
include/net/net.h +1 -0
@@ -92,6 +92,7 @@ struct NetClientState {NetClientDestructor *destructor;unsigned int queue_index; unsigned rxfilter_notify_enabled:1; + QTAILQ_HEAD(, NetFilterState) filters; }; typedef struct NICState {
include/qemu/typedefs.h +1 -0
@@ -45,6 +45,7 @@ typedef struct Monitor Monitor;typedef struct MouseTransformInfo MouseTransformInfo ;typedef struct MSIMessage MSIMessage ;typedef struct NetClientState NetClientState ; +typedef struct NetFilterState NetFilterState ;typedef struct NICInfo NICInfo ;typedef struct PcGuestInfo PcGuestInfo ;typedef struct PCIBridge PCIBridge ;
net/Makefile.objs +1 -0
@@ -13,3 +13,4 @@ common-obj-$(CONFIG_HAIKU) += tap-haiku.o common-obj-$(CONFIG_SLIRP) += slirp.o common-obj-$(CONFIG_VDE) += vde.o common-obj-$(CONFIG_NETMAP) += netmap.o +common-obj-y += filter.o
net/filter.c new file +138 -0
138 lines not on this page · raw message
net/net.c +7 -0
@@ -44,6 +44,7 @@#include "qapi/opts-visitor.h" #include "qapi/dealloc-visitor.h" #include "sysemu/sysemu.h" +#include "net/filter.h" /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32)
@@ -287,6 +288,7 @@ static void qemu_net_client_setup(NetClientState *nc, nc->incoming_queue =qemu_new_net_queue (nc); nc->destructor = destructor; +QTAILQ_INIT (&nc->filters); } NetClientState *qemu_new_net_client(NetClientInfo *info,
@@ -384,6 +386,7 @@ void qemu_del_net_client(NetClientState *nc) {NetClientState *ncs[MAX_QUEUE_NUM ];int queues, i; +NetFilterState *nf, *next;assert (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC );
@@ -395,6 +398,10 @@ void qemu_del_net_client(NetClientState *nc) MAX_QUEUE_NUM);assert (queues !=0 ); + QTAILQ_FOREACH_SAFE(nf, &nc->filters, next, next) { +object_unparent (OBJECT (nf)); + } +/* If there is a peer NIC, delete and cleanup client, but do not free. */ if (nc->peer && nc->peer->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) {NICState *nic =qemu_get_nic (nc->peer);
qapi-schema.json +20 -0
@@ -2588,6 +2588,26 @@ 'opts': 'NetClientOptions' } } ## +# @NetFilterDirection +# +# Indicates whether a netfilter is attached to a netdev's transmit queue or +# receive queue or both. +# +# @all: the filter is attached both to the receive and the transmit +# queue of the netdev (default). +# +# @rx: the filter is attached to the receive queue of the netdev, +# where it will receive packets sent to the netdev. +# +# @tx: the filter is attached to the transmit queue of the netdev, +# where it will receive packets sent by the netdev. +# +# Since 2.5 +## +{ 'enum': 'NetFilterDirection', + 'data': [ 'all', 'rx', 'tx' ] } + +## # @InetSocketAddress # # Captures a socket address or address range in the Internet namespace.
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 07/14] netfilter: hook packets before net queue send
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
Capture packets that will be sent.
--- include/net/filter.h | 8 +++++++ net/filter.c | 17 ++++++++++++++ net/net.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+)
include/net/filter.h +8 -0
@@ -58,4 +58,12 @@ struct NetFilterState { QTAILQ_ENTRY(NetFilterState) next; }; +ssize_t qemu_netfilter_receive (NetFilterState *nf, +NetFilterDirection direction, +NetClientState *sender, +unsigned flags, +const struct iovec *iov, +int iovcnt, +NetPacketSent *sent_cb); +#endif /* QEMU_NET_FILTER_H */
net/filter.c +17 -0
@@ -15,6 +15,23 @@#include "net/vhost_net.h" #include "qom/object_interfaces.h" +ssize_t qemu_netfilter_receive (NetFilterState *nf, +NetFilterDirection direction, +NetClientState *sender, +unsigned flags, +const struct iovec *iov, +int iovcnt, +NetPacketSent *sent_cb) +{ +if (nf->direction == direction || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { +return NETFILTER_GET_CLASS (OBJECT (nf))->receive_iov ( + nf, sender, flags, iov, iovcnt, sent_cb); + } + +return 0 ; +} +static char *netfilter_get_netdev_id (Object *obj,Error **errp) {NetFilterState *nf =NETFILTER (obj);
net/net.c +66 -0
95 lines not on this page · raw message
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 08/14] net: merge qemu_deliver_packet and qemu_deliver_packet_iov
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
qemu_deliver_packet_iov already have the compat delivery, we can drop qemu_deliver_packet.
--- include/net/net.h | 5 ----- net/net.c | 51 ++++++++++++++++----------------------------------- net/queue.c | 6 +++++- 3 files changed, 21 insertions(+), 41 deletions(-)
include/net/net.h +0 -5
@@ -152,11 +152,6 @@ void qemu_check_nic_model(NICInfo *nd, const char *model);int qemu_find_nic_model (NICInfo *nd,const char *const *models,const char *default_model); -ssize_t qemu_deliver_packet (NetClientState *sender, -unsigned flags, -const uint8_t *data, -size_t size, -void *opaque); ssize_t qemu_deliver_packet_iov(NetClientState *sender, unsigned flags, const struct iovec *iov,
net/net.c +16 -35
73 lines not on this page · raw message
net/queue.c +5 -1
@@ -152,9 +152,13 @@ static ssize_t qemu_net_queue_deliver(NetQueue *queue, size_t size) {ssize_t ret =-1 ; +struct iovec iov = { + .iov_base = (void *)data, + .iov_len = size + }; queue->delivering =1 ; - ret =qemu_deliver_packet (sender, flags, data, size, queue->opaque); + ret =qemu_deliver_packet_iov (sender, flags, &iov,1 , queue->opaque); queue->delivering =0 ;return ret;
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 09/14] net/queue: introduce NetQueueDeliverFunc
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
net/queue.c has logic to send/queue/flush packets but a qemu_deliver_packet_iov() call is hardcoded. Abstract this func so that we can use our own deliver function in netfilter.
--- include/net/queue.h | 13 ++++++++++++- net/net.c | 2 +- net/queue.c | 8 +++++--- 3 files changed, 18 insertions(+), 5 deletions(-)
include/net/queue.h +12 -1
@@ -34,7 +34,18 @@ typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret);#define QEMU_NET_PACKET_FLAG_NONE 0#define QEMU_NET_PACKET_FLAG_RAW (1<<0) -NetQueue *qemu_new_net_queue (void *opaque); +/* Returns: +* >0 - success +* 0 - queue packet for future redelivery +* <0 - failure (discard packet) +*/ +typedef ssize_t (NetQueueDeliverFunc )(NetClientState *sender, +unsigned flags, +const struct iovec *iov, +int iovcnt, +void *opaque); + +NetQueue *qemu_new_net_queue (NetQueueDeliverFunc *deliver,void *opaque);void qemu_del_net_queue (NetQueue *queue);
net/net.c +1 -1
@@ -286,7 +286,7 @@ static void qemu_net_client_setup(NetClientState *nc, }QTAILQ_INSERT_TAIL (&net_clients, nc, next); - nc->incoming_queue =qemu_new_net_queue (nc); + nc->incoming_queue =qemu_new_net_queue (qemu_deliver_packet_iov, nc); nc->destructor = destructor;QTAILQ_INIT (&nc->filters); }
net/queue.c +5 -3
@@ -52,13 +52,14 @@ struct NetQueue {void *opaque;uint32_t nq_maxlen;uint32_t nq_count; +NetQueueDeliverFunc *deliver; QTAILQ_HEAD(packets, NetPacket) packets; unsigned delivering : 1; }; -NetQueue *qemu_new_net_queue (void *opaque) +NetQueue *qemu_new_net_queue (NetQueueDeliverFunc *deliver,void *opaque) {NetQueue *queue;
@@ -67,6 +68,7 @@ NetQueue *qemu_new_net_queue(void *opaque) queue->opaque = opaque; queue->nq_maxlen =10000 ; queue->nq_count =0 ; + queue->deliver = deliver;QTAILQ_INIT (&queue->packets);
@@ -158,7 +160,7 @@ static ssize_t qemu_net_queue_deliver(NetQueue *queue, }; queue->delivering =1 ; - ret =qemu_deliver_packet_iov (sender, flags, &iov,1 , queue->opaque); + ret = queue->deliver (sender, flags, &iov,1 , queue->opaque); queue->delivering =0 ;return ret;
@@ -173,7 +175,7 @@ static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue,ssize_t ret =-1 ; queue->delivering =1 ; - ret =qemu_deliver_packet_iov (sender, flags, iov, iovcnt, queue->opaque); + ret = queue->deliver (sender, flags, iov, iovcnt, queue->opaque); queue->delivering =0 ;return ret;
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 10/14] netfilter: add an API to pass the packet to next filter
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
add an API qemu_netfilter_pass_to_next() to pass the packet to next filter.
--- include/net/filter.h | 7 +++++++ net/filter.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
include/net/filter.h +7 -0
@@ -66,4 +66,11 @@ ssize_t qemu_netfilter_receive(NetFilterState *nf,int iovcnt, NetPacketSent *sent_cb); +/* pass the packet to the next filter */ +ssize_t qemu_netfilter_pass_to_next (NetClientState *sender, +unsigned flags, +const struct iovec *iov, +int iovcnt, +void *opaque); +#endif /* QEMU_NET_FILTER_H */
net/filter.c +58 -0
70 lines not on this page · raw message
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 11/14] netfilter: print filter info associate with the netdev
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
When execute "info network", print filter info also. add a info_str member to NetFilterState, store specific filters info.
--- include/net/filter.h | 1 + net/filter.c | 20 ++++++++++++++++++++ net/net.c | 11 +++++++++++ 3 files changed, 32 insertions(+)
include/net/filter.h +1 -0
@@ -55,6 +55,7 @@ struct NetFilterState {char *netdev_id;NetClientState *netdev;NetFilterDirection direction; +char info_str[256 ];QTAILQ_ENTRY (NetFilterState) next; };
net/filter.c +20 -0
@@ -15,6 +15,7 @@#include "net/vhost_net.h" #include "qom/object_interfaces.h" #include "qemu/iov.h" +#include "qapi/string-output-visitor.h" ssize_t qemu_netfilter_receive(NetFilterState *nf, NetFilterDirection direction,
@@ -134,6 +135,9 @@ static void netfilter_complete(UserCreatable *uc, Error **errp)NetFilterClass *nfc =NETFILTER_GET_CLASS (uc);int queues;Error *local_err =NULL ; +char *str, *info; +ObjectProperty *prop; +StringOutputVisitor *ov;if (!nf->netdev_id) {error_setg (errp,"Parameter 'netdev' is required" );
@@ -167,6 +171,22 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) } }QTAILQ_INSERT_TAIL (&nf->netdev->filters, nf, next); + +/* generate info str */ + QTAILQ_FOREACH(prop, &OBJECT(nf)->properties, node) { +if (!strcmp (prop->name,"type" )) { +continue ; + } + ov =string_output_visitor_new (false); +object_property_get (OBJECT (nf),string_output_get_visitor (ov), + prop->name, errp); + str =string_output_get_string (ov); +string_output_visitor_cleanup (ov); + info =g_strdup_printf (",%s=%s" , prop->name, str); +g_strlcat (nf->info_str, info,sizeof (nf->info_str)); +g_free (str); +g_free (info); + } }static void netfilter_finalize (Object *obj)
net/net.c +11 -0
@@ -1179,10 +1179,21 @@ void qmp_netdev_del(const char *id, Error **errp)void print_net_client (Monitor *mon,NetClientState *nc) { +NetFilterState *nf; +monitor_printf (mon,"%s: index=%d,type=%s,%s\n" , nc->name, nc->queue_index, NetClientOptionsKind_lookup[nc->info->type], nc->info_str); +if (!QTAILQ_EMPTY (&nc->filters)) { +monitor_printf (mon,"filters:\n" ); + } + QTAILQ_FOREACH(nf, &nc->filters, next) { +monitor_printf (mon," - %s: type=%s%s\n" , +object_get_canonical_path_component (OBJECT (nf)), +object_get_typename (OBJECT (nf)), + nf->info_str); + } } RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 12/14] net/queue: export qemu_net_queue_append_iov
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
This will be used by buffer filter implementation later to queue packets.
--- include/net/queue.h | 7 +++++++ net/queue.c | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)
include/net/queue.h +7 -0
@@ -47,6 +47,13 @@ typedef ssize_t (NetQueueDeliverFunc)(NetClientState *sender,NetQueue *qemu_new_net_queue (NetQueueDeliverFunc *deliver,void *opaque); +void qemu_net_queue_append_iov (NetQueue *queue, +NetClientState *sender, +unsigned flags, +const struct iovec *iov, +int iovcnt, +NetPacketSent *sent_cb); +void qemu_del_net_queue (NetQueue *queue); ssize_t qemu_net_queue_send(NetQueue *queue,
net/queue.c +6 -6
@@ -112,12 +112,12 @@ static void qemu_net_queue_append(NetQueue *queue,QTAILQ_INSERT_TAIL (&queue->packets, packet, entry); } -static void qemu_net_queue_append_iov (NetQueue *queue, -NetClientState *sender, -unsigned flags, -const struct iovec *iov, -int iovcnt, -NetPacketSent *sent_cb) +void qemu_net_queue_append_iov (NetQueue *queue, +NetClientState *sender, +unsigned flags, +const struct iovec *iov, +int iovcnt, +NetPacketSent *sent_cb) {NetPacket *packet;size_t max_len =0 ;
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 13/14] netfilter: add a netbuffer filter
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
This filter is to buffer/release packets. Can be used when using MicroCheckpointing or other Remus like VM FT solutions.
You can also use it to crudely simulate network delay. Doesn't actually delay individual packets, but batches them together, which is a delay of sorts.
Usage:
-netdev tap,id=bn0
-object filter-buffer,id=f0,netdev=bn0,queue=rx,interval=1000
NOTE:
Interval is in microseconds, it can't be omitted currently, and can't be 0.
--- net/Makefile.objs | 1 + net/filter-buffer.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 17 +++++ vl.c | 6 +- 4 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 net/filter-buffer.c
net/Makefile.objs +1 -0
@@ -14,3 +14,4 @@ common-obj-$(CONFIG_SLIRP) += slirp.o common-obj-$(CONFIG_VDE) += vde.o common-obj-$(CONFIG_NETMAP) += netmap.o common-obj-y += filter.o +common-obj-y += filter-buffer.o
net/filter-buffer.c new file +186 -0
186 lines not on this page · raw message
qemu-options.hx +17 -0
@@ -3643,6 +3643,23 @@ in PEM format, in filenames @var{ca-cert.pem}, @var{ca-crl.pem} (optional), @var{server-cert.pem} (only servers), @var{server-key.pem} (only servers), @var{client-cert.pem} (only clients), and @var{client-key.pem} (only clients). +@item -object filter-buffer,id=@var{id},netdev=@var{netdevid},interval=@var{t}[,queue=@var{all|rx|tx}] + +Interval @var{t} can't be 0, this filter batches the packet delivery: all +packets arriving in a given interval on netdev @var{netdevid} are delayed +until the end of the interval. Interval is in microseconds. + +queue @var{all|rx|tx} is an option that can be applied to any netfilter. + +@option{all}: the filter is attached both to the receive and the transmit + queue of the netdev (default). + +@option{rx}: the filter is attached to the receive queue of the netdev, + where it will receive packets sent to the netdev. + +@option{tx}: the filter is attached to the transmit queue of the netdev, + where it will receive packets sent by the netdev. + @end table ETEXI
vl.c +5 -1
@@ -2767,7 +2767,11 @@ static bool object_create_initial(const char *type)if (g_str_equal (type,"rng-egd" )) {return false; } -/* TODO: implement netfilters */ + +if (g_str_equal (type,"filter-buffer" )) { +return false; + } +return true; }
Signature · 1 line
2.1.4
[Qemu-devel] [PULL 14/14] tests: add test cases for netfilter object
In reply to Jason WangFrom: Yang Hongyang <[email protected]>
Using qtest qmp interface to implement following cases:
1) add/remove netfilter
2) add a netfilter then delete the netdev
3) add/remove more than one netfilters
4) add more than one netfilters and then delete the netdev
--- tests/.gitignore | 1 + tests/Makefile | 2 + tests/test-netfilter.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 tests/test-netfilter.c
tests/.gitignore +1 -0
@@ -49,5 +49,6 @@ test-vmstate test-write-threshold test-x86-cpuid test-xbzrle +test-netfilter *-test qapi-schema/*.test.*
tests/Makefile +2 -0
@@ -191,6 +191,7 @@ gcov-files-i386-y += hw/pci-host/q35.c ifeq ($(CONFIG_VHOST_NET),y) check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF) endif +check-qtest-i386-y += tests/test-netfilter$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -437,6 +438,7 @@ tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y) +tests/test-netfilter$(EXESUF): tests/test-netfilter.o $(qtest-obj-y) ifeq ($(CONFIG_POSIX),y) LIBS += -lutil
tests/test-netfilter.c new file +200 -0
200 lines not on this page · raw message
Signature · 1 line
2.1.4
Peter Maydell
AppliedQuoted 25 lines · Jason Wang
The following changes since commit
5fdb4671b08e0d1631447e81348b2b50a6b85bf7:Merge remote-tracking branch 'remotes/ehabkost/tags/x86-pull-request' into staging (2015-10-06 13:42:33 +0100)
are available in the git repository at:
https://github.com/jasowang/qemu.git tags/net-pull-request
for you to fetch changes up to
89b1273742f45c30927df203532fca0d9a3e1af7:tests: add test cases for netfilter object (2015-10-12 13:34:32 +0800)
----------------------------------------------------------------
----------------------------------------------------------------
Dana Rubin (1):
net/vmxnet3: Refine l2 header validationJason Wang (1):
e1000: use alias for default modelShmulik Ladkani (2):
vmxnet3: Support reading IMR registers on bar0
vmxnet3: Add support forVMXNET3_CMD_GET_ADAPTIVE_RING_INFOcommand
Quoted 12 lines
Yang Hongyang (10):
vl.c: init delayed object afternet_init_clientsinit/cleanup of netfilter object
netfilter: hook packets before net queue send
net: mergeqemu_deliver_packetandqemu_deliver_packet_iovnet/queue: introduce NetQueueDeliverFunc
netfilter: add an API to pass the packet to next filter
netfilter: print filter info associate with the netdev net/queue: exportqemu_net_queue_append_iov
netfilter: add a netbuffer filter
tests: add test cases for netfilter object
Applied, thanks.
-- PMM
Re: [Qemu-devel] [PULL 08/14] net: merge qemu_deliver_packet and qemu_deliver_packet_iov
In reply to Jason WangQuoted 6 lines · Jason Wang
static
ssize_tnc_sendv_compat(NetClientState *nc, const struct iovec *iov,net/net.c +2
-2- int iovcnt) + int iovcnt, unsigned flags) { -uint8_t buffer[NET_BUFSIZE ]; +uint8_t buf[NET_BUFSIZE ];
net/net.c ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size) · line 703
Quoted 10 lines
net/net.c +7
-1+uint8_t *buffer;size_t offset; - offset =iov_to_buf (iov, iovcnt,0 , buffer,sizeof (buffer)); +if (iovcnt ==1 ) { + buffer = iov[0 ].iov_base; + offset = iov[0 ].iov_len; + }else { + buffer = buf; + offset =iov_to_buf (iov, iovcnt,0 , buffer,sizeof (buffer));
You want "buf, sizeof(buf)" here. sizeof(buffer) is the size of a pointer, which is wrong.
Jason, can you please fix this?
Paolo
Quoted 1 line
+ }
Re: [Qemu-devel] [PULL 11/14] netfilter: print filter info associate with the netdev
In reply to Jason Wangnet/net.c void qmp_netdev_del(const char *id, Error **errp) · line 1193
Quoted 4 lines · Jason Wang
net/net.c +4
-0+ } + QTAILQ_FOREACH(nf, &nc->filters, next) { + monitor_printf(mon, " - %s: type=%s%s\n", + object_get_canonical_path_component(OBJECT(nf)),
The value returned from object_get_canonical_path_component must be freed.
Paolo
Quoted 3 lines
net/net.c +3
-0+object_get_typename (OBJECT (nf)), + nf->info_str); + }