ref: c34c2d7fded04797f262132acac23c1a894d5c8f
parent: 4c05b3825aeb98bf5b49a0323fea3a345306014b
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;
--
⑨