@@ -22,6 +22,10 @@
#define NETFILTER_CLASS(klass) \
OBJECT_CLASS_CHECK(NetFilterClass, (klass), TYPE_NETFILTER)
+#define DEFAULT_FILTER_ID "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 */
@@ -1039,6 +1045,22 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
}
return -1;
}
+
+ if (is_netdev) {
+ const Netdev *netdev = object;
+ char filter_name[128];
+
+ snprintf(filter_name, sizeof(filter_name),
+ "%s%s", netdev->id, DEFAULT_FILTER_ID);
+ /*
+ * Here we add each netdev a default filter,
+ * it will disabled by default, Users can enable it when necessary.
+ */
+ netdev_add_default_filter(netdev->id,
+ default_netfilter_type,
+ filter_name,
+ 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> --- v4: - Rname DEFAULT_FILTER_TYPE to DEFAULT_FILTER_ID 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 | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+)