2 * QTest testcase for netfilter
4 * Copyright (c) 2015 FUJITSU LIMITED
5 * Author: Yang Hongyang <yanghy@cn.fujitsu.com>
7 * This work is licensed under the terms of the GNU GPL, version 2 or
8 * later. See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
12 #include "libqtest-single.h"
13 #include "qapi/qmp/qdict.h"
15 /* add a netfilter to a netdev and then remove it */
16 static void add_one_netfilter(void)
20 response
= qmp("{'execute': 'object-add',"
22 " 'qom-type': 'filter-buffer',"
24 " 'netdev': 'qtest-bn0',"
30 g_assert(!qdict_haskey(response
, "error"));
31 qobject_unref(response
);
33 response
= qmp("{'execute': 'object-del',"
38 g_assert(!qdict_haskey(response
, "error"));
39 qobject_unref(response
);
42 /* add a netfilter to a netdev and then remove the netdev */
43 static void remove_netdev_with_one_netfilter(void)
47 response
= qmp("{'execute': 'object-add',"
49 " 'qom-type': 'filter-buffer',"
51 " 'netdev': 'qtest-bn0',"
57 g_assert(!qdict_haskey(response
, "error"));
58 qobject_unref(response
);
60 response
= qmp("{'execute': 'netdev_del',"
65 g_assert(!qdict_haskey(response
, "error"));
66 qobject_unref(response
);
68 /* add back the netdev */
69 response
= qmp("{'execute': 'netdev_add',"
75 g_assert(!qdict_haskey(response
, "error"));
76 qobject_unref(response
);
79 /* add multi(2) netfilters to a netdev and then remove them */
80 static void add_multi_netfilter(void)
84 response
= qmp("{'execute': 'object-add',"
86 " 'qom-type': 'filter-buffer',"
88 " 'netdev': 'qtest-bn0',"
94 g_assert(!qdict_haskey(response
, "error"));
95 qobject_unref(response
);
97 response
= qmp("{'execute': 'object-add',"
99 " 'qom-type': 'filter-buffer',"
101 " 'netdev': 'qtest-bn0',"
107 g_assert(!qdict_haskey(response
, "error"));
108 qobject_unref(response
);
110 response
= qmp("{'execute': 'object-del',"
115 g_assert(!qdict_haskey(response
, "error"));
116 qobject_unref(response
);
118 response
= qmp("{'execute': 'object-del',"
123 g_assert(!qdict_haskey(response
, "error"));
124 qobject_unref(response
);
127 /* add multi(2) netfilters to a netdev and then remove the netdev */
128 static void remove_netdev_with_multi_netfilter(void)
132 response
= qmp("{'execute': 'object-add',"
134 " 'qom-type': 'filter-buffer',"
136 " 'netdev': 'qtest-bn0',"
142 g_assert(!qdict_haskey(response
, "error"));
143 qobject_unref(response
);
145 response
= qmp("{'execute': 'object-add',"
147 " 'qom-type': 'filter-buffer',"
149 " 'netdev': 'qtest-bn0',"
155 g_assert(!qdict_haskey(response
, "error"));
156 qobject_unref(response
);
158 response
= qmp("{'execute': 'netdev_del',"
163 g_assert(!qdict_haskey(response
, "error"));
164 qobject_unref(response
);
166 /* add back the netdev */
167 response
= qmp("{'execute': 'netdev_add',"
173 g_assert(!qdict_haskey(response
, "error"));
174 qobject_unref(response
);
177 int main(int argc
, char **argv
)
182 g_test_init(&argc
, &argv
, NULL
);
183 qtest_add_func("/netfilter/addremove_one", add_one_netfilter
);
184 qtest_add_func("/netfilter/remove_netdev_one",
185 remove_netdev_with_one_netfilter
);
186 qtest_add_func("/netfilter/addremove_multi", add_multi_netfilter
);
187 qtest_add_func("/netfilter/remove_netdev_multi",
188 remove_netdev_with_multi_netfilter
);
190 args
= g_strdup_printf("-nic user,id=qtest-bn0");