On 2016/2/29 15:27, Jason Wang wrote:
On 02/29/2016 09:46 AM, zhanghailiang wrote:
While the status of filter-buffer changing from 'on' to 'off',
it need to release all the buffered packets, and delete the related
timer, while switch from 'off' to 'on', it need to resume the release
packets timer.
Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com>
Cc: Jason Wang <jasow...@redhat.com>
Cc: Yang Hongyang <hongyang.y...@easystack.cn>
---
v2:
- New patch
---
net/filter-buffer.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/net/filter-buffer.c b/net/filter-buffer.c
index 12ad2e3..ed3f19e 100644
--- a/net/filter-buffer.c
+++ b/net/filter-buffer.c
@@ -124,6 +124,24 @@ static void filter_buffer_setup(NetFilterState *nf, Error
**errp)
}
}
+static void filter_buffer_status_changed(NetFilterState *nf, Error **errp)
+{
+ FilterBufferState *s = FILTER_BUFFER(nf);
+
+ if (!strcmp(nf->status, "off")) {
+ if (s->interval) {
+ timer_del(&s->release_timer);
+ }
+ filter_buffer_flush(nf);
+ } else {
+ if (s->interval) {
+ timer_init_us(&s->release_timer, QEMU_CLOCK_VIRTUAL,
+ filter_buffer_release_timer, nf);
+ timer_mod(&s->release_timer,
+ qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + s->interval);
+ }
The code looks duplicated with filter_buffer_setup().
Yea, extract them into a new helper ? filter_buffer_setup_timer() ?
+ }
+}
static void filter_buffer_class_init(ObjectClass *oc, void *data)
{
NetFilterClass *nfc = NETFILTER_CLASS(oc);
@@ -131,6 +149,7 @@ static void filter_buffer_class_init(ObjectClass *oc, void
*data)
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_get_interval(Object *obj, Visitor *v,
.