aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/filter.c92
1 files changed, 91 insertions, 1 deletions
diff --git a/net/filter.c b/net/filter.c
index 4b932e79f9..8221666263 100644
--- a/net/filter.c
+++ b/net/filter.c
@@ -171,11 +171,47 @@ static void netfilter_set_status(Object *obj, const char *str, Error **errp)
}
}
+static char *netfilter_get_position(Object *obj, Error **errp)
+{
+ NetFilterState *nf = NETFILTER(obj);
+
+ return g_strdup(nf->position);
+}
+
+static void netfilter_set_position(Object *obj, const char *str, Error **errp)
+{
+ NetFilterState *nf = NETFILTER(obj);
+
+ nf->position = g_strdup(str);
+}
+
+static char *netfilter_get_insert(Object *obj, Error **errp)
+{
+ NetFilterState *nf = NETFILTER(obj);
+
+ return nf->insert_before_flag ? g_strdup("before") : g_strdup("behind");
+}
+
+static void netfilter_set_insert(Object *obj, const char *str, Error **errp)
+{
+ NetFilterState *nf = NETFILTER(obj);
+
+ if (strcmp(str, "before") && strcmp(str, "behind")) {
+ error_setg(errp, "Invalid value for netfilter insert, "
+ "should be 'before' or 'behind'");
+ return;
+ }
+
+ nf->insert_before_flag = !strcmp(str, "before");
+}
+
static void netfilter_init(Object *obj)
{
NetFilterState *nf = NETFILTER(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,
@@ -187,11 +223,18 @@ static void netfilter_init(Object *obj)
object_property_add_str(obj, "status",
netfilter_get_status, netfilter_set_status,
NULL);
+ object_property_add_str(obj, "position",
+ netfilter_get_position, netfilter_set_position,
+ NULL);
+ object_property_add_str(obj, "insert",
+ netfilter_get_insert, netfilter_set_insert,
+ NULL);
}
static void netfilter_complete(UserCreatable *uc, Error **errp)
{
NetFilterState *nf = NETFILTER(uc);
+ NetFilterState *position = NULL;
NetClientState *ncs[MAX_QUEUE_NUM];
NetFilterClass *nfc = NETFILTER_GET_CLASS(uc);
int queues;
@@ -219,6 +262,41 @@ static void netfilter_complete(UserCreatable *uc, Error **errp)
return;
}
+ if (strcmp(nf->position, "head") && strcmp(nf->position, "tail")) {
+ Object *container;
+ Object *obj;
+ char *position_id;
+
+ if (!g_str_has_prefix(nf->position, "id=")) {
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "position",
+ "'head', 'tail' or 'id=<id>'");
+ return;
+ }
+
+ /* get the id from the string */
+ position_id = g_strndup(nf->position + 3, strlen(nf->position) - 3);
+
+ /* Search for the position to insert before/behind */
+ container = object_get_objects_root();
+ obj = object_resolve_path_component(container, position_id);
+ if (!obj) {
+ error_setg(errp, "filter '%s' not found", position_id);
+ g_free(position_id);
+ return;
+ }
+
+ position = NETFILTER(obj);
+
+ if (position->netdev != ncs[0]) {
+ error_setg(errp, "filter '%s' belongs to a different netdev",
+ position_id);
+ g_free(position_id);
+ return;
+ }
+
+ g_free(position_id);
+ }
+
nf->netdev = ncs[0];
if (nfc->setup) {
@@ -228,7 +306,18 @@ static void netfilter_complete(UserCreatable *uc, Error **errp)
return;
}
}
- QTAILQ_INSERT_TAIL(&nf->netdev->filters, nf, next);
+
+ if (position) {
+ if (nf->insert_before_flag) {
+ QTAILQ_INSERT_BEFORE(position, nf, next);
+ } else {
+ QTAILQ_INSERT_AFTER(&nf->netdev->filters, position, nf, next);
+ }
+ } else if (!strcmp(nf->position, "head")) {
+ QTAILQ_INSERT_HEAD(&nf->netdev->filters, nf, next);
+ } else if (!strcmp(nf->position, "tail")) {
+ QTAILQ_INSERT_TAIL(&nf->netdev->filters, nf, next);
+ }
}
static void netfilter_finalize(Object *obj)
@@ -245,6 +334,7 @@ static void netfilter_finalize(Object *obj)
QTAILQ_REMOVE(&nf->netdev->filters, nf, next);
}
g_free(nf->netdev_id);
+ g_free(nf->position);
}
static void default_handle_event(NetFilterState *nf, int event, Error **errp)