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"
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',"
25 " 'netdev': 'qtest-bn0',"
31 g_assert(!qdict_haskey(response
, "error"));
32 qobject_unref(response
);
34 response
= qmp("{'execute': 'object-del',"
39 g_assert(!qdict_haskey(response
, "error"));
40 qobject_unref(response
);
43 /* add a netfilter to a netdev and then remove the netdev */
44 static void remove_netdev_with_one_netfilter(void)
48 response
= qmp("{'execute': 'object-add',"
50 " 'qom-type': 'filter-buffer',"
53 " 'netdev': 'qtest-bn0',"
59 g_assert(!qdict_haskey(response
, "error"));
60 qobject_unref(response
);
62 response
= qmp("{'execute': 'netdev_del',"
67 g_assert(!qdict_haskey(response
, "error"));
68 qobject_unref(response
);
70 /* add back the netdev */
71 response
= qmp("{'execute': 'netdev_add',"
77 g_assert(!qdict_haskey(response
, "error"));
78 qobject_unref(response
);
81 /* add multi(2) netfilters to a netdev and then remove them */
82 static void add_multi_netfilter(void)
86 response
= qmp("{'execute': 'object-add',"
88 " 'qom-type': 'filter-buffer',"
91 " 'netdev': 'qtest-bn0',"
97 g_assert(!qdict_haskey(response
, "error"));
98 qobject_unref(response
);
100 response
= qmp("{'execute': 'object-add',"
102 " 'qom-type': 'filter-buffer',"
105 " 'netdev': 'qtest-bn0',"
111 g_assert(!qdict_haskey(response
, "error"));
112 qobject_unref(response
);
114 response
= qmp("{'execute': 'object-del',"
119 g_assert(!qdict_haskey(response
, "error"));
120 qobject_unref(response
);
122 response
= qmp("{'execute': 'object-del',"
127 g_assert(!qdict_haskey(response
, "error"));
128 qobject_unref(response
);
131 /* add multi(2) netfilters to a netdev and then remove the netdev */
132 static void remove_netdev_with_multi_netfilter(void)
136 response
= qmp("{'execute': 'object-add',"
138 " 'qom-type': 'filter-buffer',"
141 " 'netdev': 'qtest-bn0',"
147 g_assert(!qdict_haskey(response
, "error"));
148 qobject_unref(response
);
150 response
= qmp("{'execute': 'object-add',"
152 " 'qom-type': 'filter-buffer',"
155 " 'netdev': 'qtest-bn0',"
161 g_assert(!qdict_haskey(response
, "error"));
162 qobject_unref(response
);
164 response
= qmp("{'execute': 'netdev_del',"
169 g_assert(!qdict_haskey(response
, "error"));
170 qobject_unref(response
);
172 /* add back the netdev */
173 response
= qmp("{'execute': 'netdev_add',"
179 g_assert(!qdict_haskey(response
, "error"));
180 qobject_unref(response
);
183 int main(int argc
, char **argv
)
187 const char *devstr
= "e1000";
189 if (g_str_equal(qtest_get_arch(), "s390x")) {
190 devstr
= "virtio-net-ccw";
193 g_test_init(&argc
, &argv
, NULL
);
194 qtest_add_func("/netfilter/addremove_one", add_one_netfilter
);
195 qtest_add_func("/netfilter/remove_netdev_one",
196 remove_netdev_with_one_netfilter
);
197 qtest_add_func("/netfilter/addremove_multi", add_multi_netfilter
);
198 qtest_add_func("/netfilter/remove_netdev_multi",
199 remove_netdev_with_multi_netfilter
);
201 args
= g_strdup_printf("-netdev user,id=qtest-bn0 "
202 "-device %s,netdev=qtest-bn0", devstr
);