ref: 67b0aeb219473911f4d29565085a17ecb90c0548
parent: 460b007c3540e9584835968be245344a643ddc82
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Jul 28 15:40:54 EDT 2024
ipmux: implement hangup ctl Implement a hangup ctl command that flushes the queues, but keeps the filter around. This can be usefull for low-overhead traffic blocking, as only the file-descriptor needs to be kept around and the queues can be flushed. No user-space process is needed to consume packets and no buffers are wasted. example: aux/dial -e -o hangup 'ipmux!ver=4;src=8.8.8.8' rc -c 'echo 0 > /srv/blocked' rm /srv/blocked
--- a/sys/src/9/ip/ipmux.c
+++ b/sys/src/9/ip/ipmux.c
@@ -815,6 +815,18 @@
return n;
}
+static char*
+ipmuxctl(Conv *c, char **f, int n)
+{
+ if(n == 1 && strcmp(f[0], "hangup") == 0){
+ /* hangup and flush the queues, but keep the filter around */
+ qclose(c->rq);
+ qclose(c->wq);
+ return nil;
+ }
+ return "unknown control request";
+}
+
void
ipmuxinit(Fs *f)
{
@@ -829,7 +841,7 @@
ipmux->create = ipmuxcreate;
ipmux->close = ipmuxclose;
ipmux->rcv = ipmuxiput;
- ipmux->ctl = nil;
+ ipmux->ctl = ipmuxctl;
ipmux->advise = nil;
ipmux->stats = ipmuxstats;
ipmux->ipproto = -1;
--
⑨