Skip to content

Commit

Permalink
netfilter: Use class properties
Browse files Browse the repository at this point in the history
Instance properties make introspection hard and are not shown by
"-object ...,help".  Convert them to class properties.

Signed-off-by: Eduardo Habkost <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Eduardo Habkost <[email protected]>
  • Loading branch information
ehabkost committed Dec 15, 2020
1 parent 6d11ea6 commit f0e34a0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 42 deletions.
10 changes: 5 additions & 5 deletions net/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
12 changes: 4 additions & 8 deletions net/filter-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

Expand Down
28 changes: 14 additions & 14 deletions net/filter-mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions net/filter-rewriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,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;
Expand Down
24 changes: 12 additions & 12 deletions net/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f0e34a0

Please sign in to comment.