diff mbox

[v4,4/4] net/filter: Add a default filter to each netdev

Message ID 1454640424-12612-5-git-send-email-zhang.zhanghailiang@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zhanghailiang Feb. 5, 2016, 2:47 a.m. UTC
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(+)
diff mbox

Patch

diff --git a/include/net/filter.h b/include/net/filter.h
index b42f473..f7ca794 100644
--- a/include/net/filter.h
+++ b/include/net/filter.h
@@ -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);
 /*
diff --git a/net/net.c b/net/net.c
index c5e414f..b882d98 100644
--- a/net/net.c
+++ b/net/net.c
@@ -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;
 }