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"
14 /* add a netfilter to a netdev and then remove it */
15 static void add_one_netfilter(void)
19 response
= qmp("{'execute': 'object-add',"
21 " 'qom-type': 'filter-buffer',"
24 " 'netdev': 'qtest-bn0',"
30 g_assert(!qdict_haskey(response
, "error"));
33 response
= qmp("{'execute': 'object-del',"
38 g_assert(!qdict_haskey(response
, "error"));
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',"
52 " 'netdev': 'qtest-bn0',"
58 g_assert(!qdict_haskey(response
, "error"));
61 response
= qmp("{'execute': 'netdev_del',"
66 g_assert(!qdict_haskey(response
, "error"));
69 /* add back the netdev */
70 response
= qmp("{'execute': 'netdev_add',"
76 g_assert(!qdict_haskey(response
, "error"));
80 /* add multi(2) netfilters to a netdev and then remove them */
81 static void add_multi_netfilter(void)
85 response
= qmp("{'execute': 'object-add',"
87 " 'qom-type': 'filter-buffer',"
90 " 'netdev': 'qtest-bn0',"
96 g_assert(!qdict_haskey(response
, "error"));
99 response
= qmp("{'execute': 'object-add',"
101 " 'qom-type': 'filter-buffer',"
104 " 'netdev': 'qtest-bn0',"
110 g_assert(!qdict_haskey(response
, "error"));
113 response
= qmp("{'execute': 'object-del',"
118 g_assert(!qdict_haskey(response
, "error"));
121 response
= qmp("{'execute': 'object-del',"
126 g_assert(!qdict_haskey(response
, "error"));
130 /* add multi(2) netfilters to a netdev and then remove the netdev */
131 static void remove_netdev_with_multi_netfilter(void)
135 response
= qmp("{'execute': 'object-add',"
137 " 'qom-type': 'filter-buffer',"
140 " 'netdev': 'qtest-bn0',"
146 g_assert(!qdict_haskey(response
, "error"));
149 response
= qmp("{'execute': 'object-add',"
151 " 'qom-type': 'filter-buffer',"
154 " 'netdev': 'qtest-bn0',"
160 g_assert(!qdict_haskey(response
, "error"));
163 response
= qmp("{'execute': 'netdev_del',"
168 g_assert(!qdict_haskey(response
, "error"));
171 /* add back the netdev */
172 response
= qmp("{'execute': 'netdev_add',"
178 g_assert(!qdict_haskey(response
, "error"));
182 int main(int argc
, char **argv
)
186 const char *devstr
= "e1000";
188 if (g_str_equal(qtest_get_arch(), "s390x")) {
189 devstr
= "virtio-net-ccw";
192 g_test_init(&argc
, &argv
, NULL
);
193 qtest_add_func("/netfilter/addremove_one", add_one_netfilter
);
194 qtest_add_func("/netfilter/remove_netdev_one",
195 remove_netdev_with_one_netfilter
);
196 qtest_add_func("/netfilter/addremove_multi", add_multi_netfilter
);
197 qtest_add_func("/netfilter/remove_netdev_multi",
198 remove_netdev_with_multi_netfilter
);
200 args
= g_strdup_printf("-netdev user,id=qtest-bn0 "
201 "-device %s,netdev=qtest-bn0", devstr
);