@@ -22,6 +22,10 @@
#define NETFILTER_CLASS(klass) \
OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER)
+#define DEFAULT_FILTER_TYPE "nop"
+
+#define TYPE_FILTER_BUFFER "filter-buffer"
+
typedef void (FilterSetup) (NetFilterState *nf, Error **errp);
typedef void (FilterCleanup) (NetFilterState *nf);
/*
@@ -77,6 +77,12 @@ const char *host_net_devices[] = {
int default_net = 1;
+/*
+ * TODO: Export this with an option for users to control
+ * this with comand line ?
+ */
+char default_netfilter_type[16] = TYPE_FILTER_BUFFER;
+
/***********************************************************/
/* network device redirectors */
@@ -1029,6 +1035,23 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
}
return -1;
}
+
+ if (is_netdev) {
+ const Netdev *netdev = object;
+ char default_name[128];
+
+ snprintf(default_name, sizeof(default_name),
+ "%s%s0", netdev->id, DEFAULT_FILTER_TYPE);
+ /*
+ * Here we add each netdev a default filter,
+ * it will disabled by default, Users can enable it when necessary.
+ */
+ netdev_add_filter(netdev->id,
+ default_netfilter_type,
+ default_name,
+ true,
+ errp);
+ }
return 0;
}
We add each netdev a default buffer filter, and the default buffer filter is disabled, so it has no side effect for packets delivering in qemu net layer. The default buffer filter can be used by COLO or Micro-checkpoint, The reason we add the default filter is we hope to support hot add network during COLO state in future. Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> --- v2: - Add codes that generate id automatically for default filter (Jason's suggestion) - Some other minor fixes. --- include/net/filter.h | 4 ++++ net/net.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)