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
This commit is contained in:
cinap_lenrek 2024-07-28 19:40:54 +00:00
parent 460b007c35
commit 67b0aeb219

View file

@ -815,6 +815,18 @@ ipmuxstats(Proto *p, char *buf, int len)
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 @@ ipmuxinit(Fs *f)
ipmux->create = ipmuxcreate;
ipmux->close = ipmuxclose;
ipmux->rcv = ipmuxiput;
ipmux->ctl = nil;
ipmux->ctl = ipmuxctl;
ipmux->advise = nil;
ipmux->stats = ipmuxstats;
ipmux->ipproto = -1;