2015-10-07 06:52:14 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 FUJITSU LIMITED
|
|
|
|
* Author: Yang Hongyang <yanghy@cn.fujitsu.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or
|
|
|
|
* later. See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-01-29 20:50:00 +03:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2015-10-07 06:52:14 +03:00
|
|
|
#include "qapi/qmp/qerror.h"
|
|
|
|
#include "qemu/error-report.h"
|
|
|
|
|
|
|
|
#include "net/filter.h"
|
|
|
|
#include "net/net.h"
|
|
|
|
#include "net/vhost_net.h"
|
|
|
|
#include "qom/object_interfaces.h"
|
2015-10-07 06:52:18 +03:00
|
|
|
#include "qemu/iov.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2018-09-03 07:38:56 +03:00
|
|
|
#include "net/colo.h"
|
|
|
|
#include "migration/colo.h"
|
2015-10-07 06:52:14 +03:00
|
|
|
|
2016-03-01 08:37:02 +03:00
|
|
|
static inline bool qemu_can_skip_netfilter(NetFilterState *nf)
|
|
|
|
{
|
|
|
|
return !nf->on;
|
|
|
|
}
|
|
|
|
|
2015-10-07 06:52:15 +03:00
|
|
|
ssize_t qemu_netfilter_receive(NetFilterState *nf,
|
|
|
|
NetFilterDirection direction,
|
|
|
|
NetClientState *sender,
|
|
|
|
unsigned flags,
|
|
|
|
const struct iovec *iov,
|
|
|
|
int iovcnt,
|
|
|
|
NetPacketSent *sent_cb)
|
|
|
|
{
|
2016-03-01 08:37:02 +03:00
|
|
|
if (qemu_can_skip_netfilter(nf)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-07 06:52:15 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-01-26 08:00:22 +03:00
|
|
|
static NetFilterState *netfilter_next(NetFilterState *nf,
|
|
|
|
NetFilterDirection dir)
|
|
|
|
{
|
|
|
|
NetFilterState *next;
|
|
|
|
|
|
|
|
if (dir == NET_FILTER_DIRECTION_TX) {
|
|
|
|
/* forward walk through filters */
|
|
|
|
next = QTAILQ_NEXT(nf, next);
|
|
|
|
} else {
|
|
|
|
/* reverse order */
|
2018-12-06 15:10:34 +03:00
|
|
|
next = QTAILQ_PREV(nf, next);
|
2016-01-26 08:00:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2015-10-07 06:52:18 +03:00
|
|
|
ssize_t qemu_netfilter_pass_to_next(NetClientState *sender,
|
|
|
|
unsigned flags,
|
|
|
|
const struct iovec *iov,
|
|
|
|
int iovcnt,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int direction;
|
|
|
|
NetFilterState *nf = opaque;
|
2016-01-26 08:00:22 +03:00
|
|
|
NetFilterState *next = NULL;
|
2015-10-07 06:52:18 +03:00
|
|
|
|
|
|
|
if (!sender || !sender->peer) {
|
|
|
|
/* no receiver, or sender been deleted, no need to pass it further */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nf->direction == NET_FILTER_DIRECTION_ALL) {
|
|
|
|
if (sender == nf->netdev) {
|
|
|
|
/* This packet is sent by netdev itself */
|
|
|
|
direction = NET_FILTER_DIRECTION_TX;
|
|
|
|
} else {
|
|
|
|
direction = NET_FILTER_DIRECTION_RX;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
direction = nf->direction;
|
|
|
|
}
|
|
|
|
|
2016-01-26 08:00:22 +03:00
|
|
|
next = netfilter_next(nf, direction);
|
2015-10-07 06:52:18 +03:00
|
|
|
while (next) {
|
|
|
|
/*
|
|
|
|
* if qemu_netfilter_pass_to_next been called, means that
|
|
|
|
* the packet has been hold by filter and has already retured size
|
|
|
|
* to the sender, so sent_cb shouldn't be called later, just
|
|
|
|
* pass NULL to next.
|
|
|
|
*/
|
|
|
|
ret = qemu_netfilter_receive(next, direction, sender, flags, iov,
|
|
|
|
iovcnt, NULL);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
2016-01-26 08:00:22 +03:00
|
|
|
next = netfilter_next(next, direction);
|
2015-10-07 06:52:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have gone through all filters, pass it to receiver.
|
|
|
|
* Do the valid check again incase sender or receiver been
|
|
|
|
* deleted while we go through filters.
|
|
|
|
*/
|
|
|
|
if (sender && sender->peer) {
|
|
|
|
qemu_net_queue_send_iov(sender->peer->incoming_queue,
|
|
|
|
sender, flags, iov, iovcnt, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* no receiver, or sender been deleted */
|
|
|
|
return iov_size(iov, iovcnt);
|
|
|
|
}
|
|
|
|
|
2015-10-07 06:52:14 +03:00
|
|
|
static char *netfilter_get_netdev_id(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
|
|
|
|
return g_strdup(nf->netdev_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netfilter_set_netdev_id(Object *obj, const char *str, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
|
|
|
|
nf->netdev_id = g_strdup(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netfilter_get_direction(Object *obj, Error **errp G_GNUC_UNUSED)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
return nf->direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netfilter_set_direction(Object *obj, int direction, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
nf->direction = direction;
|
|
|
|
}
|
|
|
|
|
2016-03-01 08:37:02 +03:00
|
|
|
static char *netfilter_get_status(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
|
|
|
|
return nf->on ? g_strdup("on") : g_strdup("off");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netfilter_set_status(Object *obj, const char *str, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
NetFilterClass *nfc = NETFILTER_GET_CLASS(obj);
|
|
|
|
|
|
|
|
if (strcmp(str, "on") && strcmp(str, "off")) {
|
|
|
|
error_setg(errp, "Invalid value for netfilter status, "
|
|
|
|
"should be 'on' or 'off'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (nf->on == !strcmp(str, "on")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nf->on = !nf->on;
|
2016-04-05 06:43:55 +03:00
|
|
|
if (nf->netdev && nfc->status_changed) {
|
2016-03-01 08:37:02 +03:00
|
|
|
nfc->status_changed(nf, errp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 17:25:48 +03:00
|
|
|
static char *netfilter_get_position(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
|
|
|
|
return g_strdup(nf->position);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netfilter_set_position(Object *obj, const char *str, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
|
|
|
|
nf->position = g_strdup(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *netfilter_get_insert(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
|
|
|
|
return nf->insert_before_flag ? g_strdup("before") : g_strdup("behind");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netfilter_set_insert(Object *obj, const char *str, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
|
|
|
|
if (strcmp(str, "before") && strcmp(str, "behind")) {
|
|
|
|
error_setg(errp, "Invalid value for netfilter insert, "
|
|
|
|
"should be 'before' or 'behind'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nf->insert_before_flag = !strcmp(str, "before");
|
|
|
|
}
|
|
|
|
|
2015-10-07 06:52:14 +03:00
|
|
|
static void netfilter_init(Object *obj)
|
|
|
|
{
|
2016-03-01 08:37:02 +03:00
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
|
|
|
|
nf->on = true;
|
2019-10-24 17:25:48 +03:00
|
|
|
nf->insert_before_flag = false;
|
|
|
|
nf->position = g_strdup("tail");
|
2016-03-01 08:37:02 +03:00
|
|
|
|
2015-10-07 06:52:14 +03:00
|
|
|
object_property_add_str(obj, "netdev",
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
netfilter_get_netdev_id, netfilter_set_netdev_id);
|
2015-10-07 06:52:14 +03:00
|
|
|
object_property_add_enum(obj, "queue", "NetFilterDirection",
|
2017-08-24 11:46:10 +03:00
|
|
|
&NetFilterDirection_lookup,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
netfilter_get_direction, netfilter_set_direction);
|
2016-03-01 08:37:02 +03:00
|
|
|
object_property_add_str(obj, "status",
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
netfilter_get_status, netfilter_set_status);
|
2019-10-24 17:25:48 +03:00
|
|
|
object_property_add_str(obj, "position",
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
netfilter_get_position, netfilter_set_position);
|
2019-10-24 17:25:48 +03:00
|
|
|
object_property_add_str(obj, "insert",
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
netfilter_get_insert, netfilter_set_insert);
|
2015-10-07 06:52:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void netfilter_complete(UserCreatable *uc, Error **errp)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(uc);
|
2019-10-24 17:25:48 +03:00
|
|
|
NetFilterState *position = NULL;
|
2015-10-07 06:52:14 +03:00
|
|
|
NetClientState *ncs[MAX_QUEUE_NUM];
|
|
|
|
NetFilterClass *nfc = NETFILTER_GET_CLASS(uc);
|
|
|
|
int queues;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
|
|
|
if (!nf->netdev_id) {
|
|
|
|
error_setg(errp, "Parameter 'netdev' is required");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
queues = qemu_find_net_clients_except(nf->netdev_id, ncs,
|
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat
union 'Netdev' QAPI type that covers all the branches of the
former 'NetClientOptions' simple union, where the branches are
now listed in a new 'NetClientDriver' enum rather than generated
from the simple union. The existence of a flat union has no
change to the command line syntax accepted for new code, and
will make it possible for a future patch to switch the QMP
command to parse a boxed union for no change to valid QMP; but
it does have some ripple effect on the C code when dealing with
the new types.
While making the conversion, note that the 'NetLegacy' type
remains unchanged: it applies only to legacy command line options,
and will not be ported to QMP, so it should remain a wrapper
around a simple union; to avoid confusion, the type named
'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
in its place. Then, in the C code, we convert from NetLegacy to
Netdev as soon as possible, so that the bulk of the net stack
only has to deal with one QAPI type, not two. Note that since
the old legacy code always rejected 'hubport', we can just omit
that branch from the new 'NetLegacyOptions' simple union.
Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
although the sed script in that patch no longer applies due to
other changes in the tree since then, and I also did some manual
cleanups (such as fixing whitespace to keep checkpatch happy).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Fixup from Eric squashed in]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-14 06:50:23 +03:00
|
|
|
NET_CLIENT_DRIVER_NIC,
|
2015-10-07 06:52:14 +03:00
|
|
|
MAX_QUEUE_NUM);
|
|
|
|
if (queues < 1) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "netdev",
|
|
|
|
"a network backend id");
|
|
|
|
return;
|
|
|
|
} else if (queues > 1) {
|
|
|
|
error_setg(errp, "multiqueue is not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_vhost_net(ncs[0])) {
|
|
|
|
error_setg(errp, "Vhost is not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-24 17:25:48 +03:00
|
|
|
if (strcmp(nf->position, "head") && strcmp(nf->position, "tail")) {
|
|
|
|
Object *container;
|
|
|
|
Object *obj;
|
|
|
|
char *position_id;
|
|
|
|
|
|
|
|
if (!g_str_has_prefix(nf->position, "id=")) {
|
|
|
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "position",
|
|
|
|
"'head', 'tail' or 'id=<id>'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the id from the string */
|
|
|
|
position_id = g_strndup(nf->position + 3, strlen(nf->position) - 3);
|
|
|
|
|
|
|
|
/* Search for the position to insert before/behind */
|
|
|
|
container = object_get_objects_root();
|
|
|
|
obj = object_resolve_path_component(container, position_id);
|
|
|
|
if (!obj) {
|
|
|
|
error_setg(errp, "filter '%s' not found", position_id);
|
|
|
|
g_free(position_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
position = NETFILTER(obj);
|
|
|
|
|
|
|
|
if (position->netdev != ncs[0]) {
|
|
|
|
error_setg(errp, "filter '%s' belongs to a different netdev",
|
|
|
|
position_id);
|
|
|
|
g_free(position_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(position_id);
|
|
|
|
}
|
|
|
|
|
2015-10-07 06:52:14 +03:00
|
|
|
nf->netdev = ncs[0];
|
|
|
|
|
|
|
|
if (nfc->setup) {
|
|
|
|
nfc->setup(nf, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-10-24 17:25:48 +03:00
|
|
|
|
|
|
|
if (position) {
|
|
|
|
if (nf->insert_before_flag) {
|
|
|
|
QTAILQ_INSERT_BEFORE(position, nf, next);
|
|
|
|
} else {
|
|
|
|
QTAILQ_INSERT_AFTER(&nf->netdev->filters, position, nf, next);
|
|
|
|
}
|
|
|
|
} else if (!strcmp(nf->position, "head")) {
|
|
|
|
QTAILQ_INSERT_HEAD(&nf->netdev->filters, nf, next);
|
|
|
|
} else if (!strcmp(nf->position, "tail")) {
|
|
|
|
QTAILQ_INSERT_TAIL(&nf->netdev->filters, nf, next);
|
|
|
|
}
|
2015-10-07 06:52:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void netfilter_finalize(Object *obj)
|
|
|
|
{
|
|
|
|
NetFilterState *nf = NETFILTER(obj);
|
|
|
|
NetFilterClass *nfc = NETFILTER_GET_CLASS(obj);
|
|
|
|
|
|
|
|
if (nfc->cleanup) {
|
|
|
|
nfc->cleanup(nf);
|
|
|
|
}
|
|
|
|
|
2016-02-15 07:52:34 +03:00
|
|
|
if (nf->netdev && !QTAILQ_EMPTY(&nf->netdev->filters) &&
|
2016-07-25 15:47:12 +03:00
|
|
|
QTAILQ_IN_USE(nf, next)) {
|
2015-10-07 06:52:14 +03:00
|
|
|
QTAILQ_REMOVE(&nf->netdev->filters, nf, next);
|
|
|
|
}
|
2015-12-23 10:43:18 +03:00
|
|
|
g_free(nf->netdev_id);
|
2019-10-24 17:25:48 +03:00
|
|
|
g_free(nf->position);
|
2015-10-07 06:52:14 +03:00
|
|
|
}
|
|
|
|
|
2018-09-03 07:38:56 +03:00
|
|
|
static void default_handle_event(NetFilterState *nf, int event, Error **errp)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case COLO_EVENT_CHECKPOINT:
|
|
|
|
break;
|
|
|
|
case COLO_EVENT_FAILOVER:
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 19:05:54 +03:00
|
|
|
object_property_set_str(OBJECT(nf), "status", "off", errp);
|
2018-09-03 07:38:56 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 06:52:14 +03:00
|
|
|
static void netfilter_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
|
2018-09-03 07:38:56 +03:00
|
|
|
NetFilterClass *nfc = NETFILTER_CLASS(oc);
|
2015-10-07 06:52:14 +03:00
|
|
|
|
|
|
|
ucc->complete = netfilter_complete;
|
2018-09-03 07:38:56 +03:00
|
|
|
nfc->handle_event = default_handle_event;
|
2015-10-07 06:52:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo netfilter_info = {
|
|
|
|
.name = TYPE_NETFILTER,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(NetFilterClass),
|
|
|
|
.class_init = netfilter_class_init,
|
|
|
|
.instance_size = sizeof(NetFilterState),
|
|
|
|
.instance_init = netfilter_init,
|
|
|
|
.instance_finalize = netfilter_finalize,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_USER_CREATABLE },
|
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&netfilter_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types);
|