Plan 9 from Bell Labs’s /usr/web/sources/contrib/dho/nfil/src/9/ip/nfiltest.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"

#include "ip.h"

int hook_in(Ipifc *, Block *, void *);
int hook_out(Ipifc *, Block *, void *);

void
nfiltestinit(Fs *f)
{
	USED(f);

	nfil_register_hook(hook_in, 0, Direction_In);
	nfil_register_hook(hook_out, 0, Direction_Out);
}

int
hook_in(Ipifc *ifc, Block *bp, void *xtra)
{
	Ip4hdr *h = nil;
	Fs *f = nil;
	Proto *p = nil;

	USED(xtra); USED(bp); USED(ifc); USED(h); USED(p);

	h = (Ip4hdr *)(bp->rp);
	f = (Fs *)xtra;
	p = Fsrcvpcol(f, h->proto);

	print("nfil filtered a packet of type %s\n", p->name);

	return Nfil_Success;
}

int
hook_out(Ipifc *ifc, Block *bp, void *xtra)
{
	Ip4hdr *h = (Ip4hdr *)(bp->rp);
	Nfil_output_args *args = (Nfil_output_args *)xtra;
	Fs *f = args->f;
	Proto *p = Fsrcvpcol(f, h->proto);

	USED(xtra); USED(bp); USED(ifc); USED(h); USED(p);

	print("nfil filtered a packet of type %s outgoing\n", p->name);

	return Nfil_Success;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.