diff mbox series

[09/12] netfilter: Use class properties

Message ID 20201009160122.1662082-10-ehabkost@redhat.com
State Accepted
Commit f0e34a06f6580e666a1f49d1b8315adf1d587c43
Headers show
Series qom: Make all -object types use only class properties | expand

Commit Message

Eduardo Habkost Oct. 9, 2020, 4:01 p.m. UTC
Instance properties make introspection hard and are not shown by
"-object ...,help".  Convert them to class properties.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Jason Wang <jasowang@redhat.com>
Cc: Zhang Chen <chen.zhang@intel.com>
Cc: Li Zhijian <lizhijian@cn.fujitsu.com>
Cc: qemu-devel@nongnu.org
---
 net/dump.c            | 10 +++++-----
 net/filter-buffer.c   | 12 ++++--------
 net/filter-mirror.c   | 28 ++++++++++++++--------------
 net/filter-rewriter.c |  7 ++++---
 net/filter.c          | 24 ++++++++++++------------
 5 files changed, 39 insertions(+), 42 deletions(-)
diff mbox series

Patch

diff --git a/net/dump.c b/net/dump.c
index 7fd448d2e1..4d538d82a6 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -224,11 +224,6 @@  static void filter_dump_instance_init(Object *obj)
     NetFilterDumpState *nfds = FILTER_DUMP(obj);
 
     nfds->maxlen = 65536;
-
-    object_property_add(obj, "maxlen", "uint32", filter_dump_get_maxlen,
-                        filter_dump_set_maxlen, NULL, NULL);
-    object_property_add_str(obj, "file", file_dump_get_filename,
-                            file_dump_set_filename);
 }
 
 static void filter_dump_instance_finalize(Object *obj)
@@ -242,6 +237,11 @@  static void filter_dump_class_init(ObjectClass *oc, void *data)
 {
     NetFilterClass *nfc = NETFILTER_CLASS(oc);
 
+    object_class_property_add(oc, "maxlen", "uint32", filter_dump_get_maxlen,
+                              filter_dump_set_maxlen, NULL, NULL);
+    object_class_property_add_str(oc, "file", file_dump_get_filename,
+                                  file_dump_set_filename);
+
     nfc->setup = filter_dump_setup;
     nfc->cleanup = filter_dump_cleanup;
     nfc->receive_iov = filter_dump_receive_iov;
diff --git a/net/filter-buffer.c b/net/filter-buffer.c
index 95e384865f..283dc9cbe6 100644
--- a/net/filter-buffer.c
+++ b/net/filter-buffer.c
@@ -176,24 +176,20 @@  static void filter_buffer_class_init(ObjectClass *oc, void *data)
 {
     NetFilterClass *nfc = NETFILTER_CLASS(oc);
 
+    object_class_property_add(oc, "interval", "uint32",
+                              filter_buffer_get_interval,
+                              filter_buffer_set_interval, NULL, NULL);
+
     nfc->setup = filter_buffer_setup;
     nfc->cleanup = filter_buffer_cleanup;
     nfc->receive_iov = filter_buffer_receive_iov;
     nfc->status_changed = filter_buffer_status_changed;
 }
 
-static void filter_buffer_init(Object *obj)
-{
-    object_property_add(obj, "interval", "uint32",
-                        filter_buffer_get_interval,
-                        filter_buffer_set_interval, NULL, NULL);
-}
-
 static const TypeInfo filter_buffer_info = {
     .name = TYPE_FILTER_BUFFER,
     .parent = TYPE_NETFILTER,
     .class_init = filter_buffer_class_init,
-    .instance_init = filter_buffer_init,
     .instance_size = sizeof(FilterBufferState),
 };
 
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
index 26b783011a..f8e65007c0 100644
--- a/net/filter-mirror.c
+++ b/net/filter-mirror.c
@@ -374,6 +374,12 @@  static void filter_mirror_class_init(ObjectClass *oc, void *data)
 {
     NetFilterClass *nfc = NETFILTER_CLASS(oc);
 
+    object_class_property_add_str(oc, "outdev", filter_mirror_get_outdev,
+                                  filter_mirror_set_outdev);
+    object_class_property_add_bool(oc, "vnet_hdr_support",
+                                   filter_mirror_get_vnet_hdr,
+                                   filter_mirror_set_vnet_hdr);
+
     nfc->setup = filter_mirror_setup;
     nfc->cleanup = filter_mirror_cleanup;
     nfc->receive_iov = filter_mirror_receive_iov;
@@ -383,6 +389,14 @@  static void filter_redirector_class_init(ObjectClass *oc, void *data)
 {
     NetFilterClass *nfc = NETFILTER_CLASS(oc);
 
+    object_class_property_add_str(oc, "indev", filter_redirector_get_indev,
+                                  filter_redirector_set_indev);
+    object_class_property_add_str(oc, "outdev", filter_redirector_get_outdev,
+                                  filter_redirector_set_outdev);
+    object_class_property_add_bool(oc, "vnet_hdr_support",
+                                   filter_redirector_get_vnet_hdr,
+                                   filter_redirector_set_vnet_hdr);
+
     nfc->setup = filter_redirector_setup;
     nfc->cleanup = filter_redirector_cleanup;
     nfc->receive_iov = filter_redirector_receive_iov;
@@ -392,28 +406,14 @@  static void filter_mirror_init(Object *obj)
 {
     MirrorState *s = FILTER_MIRROR(obj);
 
-    object_property_add_str(obj, "outdev", filter_mirror_get_outdev,
-                            filter_mirror_set_outdev);
-
     s->vnet_hdr = false;
-    object_property_add_bool(obj, "vnet_hdr_support",
-                             filter_mirror_get_vnet_hdr,
-                             filter_mirror_set_vnet_hdr);
 }
 
 static void filter_redirector_init(Object *obj)
 {
     MirrorState *s = FILTER_REDIRECTOR(obj);
 
-    object_property_add_str(obj, "indev", filter_redirector_get_indev,
-                            filter_redirector_set_indev);
-    object_property_add_str(obj, "outdev", filter_redirector_get_outdev,
-                            filter_redirector_set_outdev);
-
     s->vnet_hdr = false;
-    object_property_add_bool(obj, "vnet_hdr_support",
-                             filter_redirector_get_vnet_hdr,
-                             filter_redirector_set_vnet_hdr);
 }
 
 static void filter_mirror_fini(Object *obj)
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index dc3c27a489..ae358059d9 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -416,15 +416,16 @@  static void filter_rewriter_init(Object *obj)
 
     s->vnet_hdr = false;
     s->failover_mode = FAILOVER_MODE_OFF;
-    object_property_add_bool(obj, "vnet_hdr_support",
-                             filter_rewriter_get_vnet_hdr,
-                             filter_rewriter_set_vnet_hdr);
 }
 
 static void colo_rewriter_class_init(ObjectClass *oc, void *data)
 {
     NetFilterClass *nfc = NETFILTER_CLASS(oc);
 
+    object_class_property_add_bool(oc, "vnet_hdr_support",
+                                   filter_rewriter_get_vnet_hdr,
+                                   filter_rewriter_set_vnet_hdr);
+
     nfc->setup = colo_rewriter_setup;
     nfc->cleanup = colo_rewriter_cleanup;
     nfc->receive_iov = colo_rewriter_receive_iov;
diff --git a/net/filter.c b/net/filter.c
index eac8ba1e9c..3fe88fa43f 100644
--- a/net/filter.c
+++ b/net/filter.c
@@ -212,18 +212,6 @@  static void netfilter_init(Object *obj)
     nf->on = true;
     nf->insert_before_flag = false;
     nf->position = g_strdup("tail");
-
-    object_property_add_str(obj, "netdev",
-                            netfilter_get_netdev_id, netfilter_set_netdev_id);
-    object_property_add_enum(obj, "queue", "NetFilterDirection",
-                             &NetFilterDirection_lookup,
-                             netfilter_get_direction, netfilter_set_direction);
-    object_property_add_str(obj, "status",
-                            netfilter_get_status, netfilter_set_status);
-    object_property_add_str(obj, "position",
-                            netfilter_get_position, netfilter_set_position);
-    object_property_add_str(obj, "insert",
-                            netfilter_get_insert, netfilter_set_insert);
 }
 
 static void netfilter_complete(UserCreatable *uc, Error **errp)
@@ -350,6 +338,18 @@  static void netfilter_class_init(ObjectClass *oc, void *data)
     UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
     NetFilterClass *nfc = NETFILTER_CLASS(oc);
 
+    object_class_property_add_str(oc, "netdev",
+                                  netfilter_get_netdev_id, netfilter_set_netdev_id);
+    object_class_property_add_enum(oc, "queue", "NetFilterDirection",
+                                   &NetFilterDirection_lookup,
+                                   netfilter_get_direction, netfilter_set_direction);
+    object_class_property_add_str(oc, "status",
+                                  netfilter_get_status, netfilter_set_status);
+    object_class_property_add_str(oc, "position",
+                                  netfilter_get_position, netfilter_set_position);
+    object_class_property_add_str(oc, "insert",
+                                  netfilter_get_insert, netfilter_set_insert);
+
     ucc->complete = netfilter_complete;
     nfc->handle_event = default_handle_event;
 }