grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / net / pfil.c
blobfe205285b3a0cb75ec985ad6ac85ac56ab13db0a
1 /* $FreeBSD: src/sys/net/pfil.c,v 1.8.4.4 2005/01/31 23:26:23 imp Exp $ */
2 /* $NetBSD: pfil.c,v 1.20 2001/11/12 23:49:46 lukem Exp $ */
4 /*-
5 * Copyright (c) 1996 Matthew R. Green
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #include <conf.h>
34 #include <aros/asmcall.h>
35 #include <exec/lists.h>
36 #include <libraries/miami.h>
37 #include <utility/hooks.h>
38 #include <proto/exec.h>
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/errno.h>
42 #include <sys/malloc.h>
43 #include <sys/socket.h>
44 #include <sys/socketvar.h>
45 #include <sys/systm.h>
46 #include <sys/queue.h>
48 #include <net/if.h>
49 #include <net/pfil.h>
51 struct SignalSemaphore pfil_list_lock;
52 struct MinList pfil_list;
54 static __inline void
55 PFIL_RLOCK(void)
57 ObtainSemaphoreShared(&pfil_list_lock);
60 static __inline void
61 PFIL_RUNLOCK(void)
63 ReleaseSemaphore(&pfil_list_lock);
66 void pfil_init(void)
68 InitSemaphore(&pfil_list_lock);
69 NewList((struct List *)&pfil_list);
73 * pfil_run_hooks() runs the specified packet filter hooks.
75 void
76 pfil_run_hooks(struct mbuf *m, struct ifnet *ifp, unsigned char pr)
78 struct packet_filter_hook *pfh;
79 struct MiamiPFBuffer pfb;
80 unsigned char ifname[IFNAMSIZ+3];
81 void (*pfil_func)(struct Hook *, APTR, struct MiamiPFBuffer *);
83 DPF(kprintf("pfil_run_hooks(0x%08lx, %s%u, %u) called\n", ifp, ifp->if_name, ifp->if_unit, pr);)
84 pfb.data = mtod(m, unsigned char *);
85 pfb.length = m->m_len;
86 sprintf(ifname, "%s%u", ifp->if_name, ifp->if_unit);
87 pfb.name = ifname;
88 if (ifp->if_flags & IFF_LOOPBACK)
89 pfb.itype = MIAMIPFBIT_LOOP;
90 else
91 pfb.itype = MIAMIPFBIT_BUILTIN;
92 pfb.ptype = pr;
93 PFIL_RLOCK();
94 for (pfh = (struct packet_filter_hook *)pfil_list.mlh_Head;
95 pfh->pfil_link.mln_Succ;
96 pfh = (struct packet_filter_hook *)pfh->pfil_link.mln_Succ) {
97 /* TODO: NicJA - Where is CHECK_POINTER() !!!! */
98 #if !defined(__AROS__)
99 CHECK_POINTER(pfh);
100 #endif
101 DPF(kprintf("Checking handle 0x%08lx\n", pfh);)
102 DPF(kprintf("Interface: 0x%08lx\n", pfh->pfil_if);)
103 DPF(kprintf("Hook: 0x%08lx\n", pfh->pfil_hook);)
104 DPF(kprintf("Function: 0x%08lx\n", pfh->pfil_hook->h_Entry);)
105 DPF(kprintf("CPU type: %ld\n", pfh->pfil_hooktype);)
106 if (pfh->pfil_if == ifp) {
107 pfil_func = (APTR)pfh->pfil_hook->h_Entry;
108 DPF(kprintf("Executing packet filter routine: 0x%08lx\n", pfil_func);)
109 switch (pfh->pfil_hooktype) {
110 case MIAMICPU_M68KREG:
111 AROS_UFC3NR(void, pfil_func,
112 AROS_UFCA(struct Hook *, pfh->pfil_hook, A0),
113 AROS_UFCA(APTR, pfh, A2),
114 AROS_UFCA(struct MiamiPFBuffer *, &pfb, A1));
115 break;
116 case MIAMICPU_PPCV4:
117 pfil_func(pfh->pfil_hook, pfh, &pfb);
118 break;
122 PFIL_RUNLOCK();