Fix source option prefix.
[fwd] / acl.h
CommitLineData
e82f7154 1/* -*-c-*-
2 *
0ac54f22 3 * $Id: acl.h,v 1.4 2003/11/25 14:08:23 mdw Exp $
e82f7154 4 *
5 * Access control list handling
6 *
e5398e09 7 * (c) 1999 Straylight/Edgeware
e82f7154 8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the `fw' port forwarder.
13 *
14 * `fw' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * `fw' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with `fw'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29/*----- Revision history --------------------------------------------------*
30 *
31 * $Log: acl.h,v $
0ac54f22 32 * Revision 1.4 2003/11/25 14:08:23 mdw
33 * Debianization. Socket target options. Internet binding.
34 *
e0ce9d38 35 * Revision 1.3 1999/07/27 18:30:53 mdw
36 * Various minor portability fixes.
37 *
e5398e09 38 * Revision 1.2 1999/07/26 23:28:16 mdw
39 * Minor modifications for new design.
40 *
41 * Revision 1.1.1.1 1999/07/01 08:56:23 mdw
42 * Initial revision.
e82f7154 43 *
44 */
45
46#ifndef ACL_H
47#define ACL_H
48
49#ifdef __cplusplus
50 extern "C" {
51#endif
52
53/*----- Header files ------------------------------------------------------*/
54
55#include <stdio.h>
56
e0ce9d38 57#include <sys/types.h>
e82f7154 58#include <sys/socket.h>
59#include <netinet/in.h>
60
61/*----- Data structures ---------------------------------------------------*/
62
63/* --- An access control entry --- */
64
65typedef struct acl_entry {
66 struct acl_entry *next; /* Next entry in the list */
0ac54f22 67 const struct acl_ops *ops; /* Operations for the ACL entry */
e82f7154 68 unsigned act; /* What to do with matching hosts */
e82f7154 69} acl_entry;
70
0ac54f22 71#define ACL_DENY 0 /* Deny access to matching conns */
72#define ACL_ALLOW 1 /* Allow access to matching conns */
e82f7154 73#define ACL_PERM 1u /* Bit mask for permission bit */
74
0ac54f22 75/* --- Host-based access control --- */
76
77typedef struct acl_host {
78 acl_entry a; /* Base structure */
79 struct in_addr addr, mask; /* Address and netmask */
80} acl_host;
81
82/* --- ACL methods --- */
83
84typedef struct acl_ops {
85 int (*check)(void */*a*/, struct in_addr /*addr*/, unsigned /*port*/);
86 void (*dump)(void */*a*/, FILE */*fp*/);
87 void (*free)(void */*a*/);
88} acl_ops;
89
e82f7154 90/*----- Functions provided ------------------------------------------------*/
91
92/* --- @acl_check@ --- *
93 *
94 * Arguments: @acl_entry *a@ = pointer to ACL to check against
95 * @struct in_addr addr@ = address to check
0ac54f22 96 * @unsigned port@ = port number to check
97 * @int *act@ = verdict (should initially be @ACT_ALLOW@)
e82f7154 98 *
0ac54f22 99 * Returns: Zero if undecided, nonzero if a rule matched.
e82f7154 100 *
101 * Use: Checks an address against an ACL.
102 */
103
0ac54f22 104extern int acl_check(acl_entry */*a*/,
105 struct in_addr /*addr*/, unsigned /*port*/,
106 int */*act*/);
e82f7154 107
108/* --- @acl_dump@ --- *
109 *
110 * Arguments: @acl_entry *a@ = pointer to ACL to dump
111 * @FILE *fp@ = pointer to stream to dump on
112 *
113 * Returns: ---
114 *
115 * Use: Dumps an access control list to an output stream.
116 */
117
118extern void acl_dump(acl_entry */*a*/, FILE */*fp*/);
119
e5398e09 120/* --- @acl_free@ --- *
121 *
122 * Arguments: @acl_entry *a@ = pointer to a list of ACLs
123 *
124 * Returns: ---
125 *
126 * Use: Frees all of the memory used by an ACL.
127 */
128
129extern void acl_free(acl_entry */*a*/);
130
0ac54f22 131/* --- @acl_addhost@ --- *
e82f7154 132 *
133 * Arguments: @acl_entry ***a@ = address of pointer to list tail
134 * @unsigned act@ = what to do with matching addresses
135 * @struct in_addr addr, mask@ = address and mask to match
136 *
137 * Returns: ---
138 *
0ac54f22 139 * Use: Adds a host-authentication entry to the end of an access
140 * control list.
141 */
142
143extern void acl_addhost(acl_entry ***/*a*/, unsigned /*act*/,
144 struct in_addr /*addr*/, struct in_addr /*mask*/);
145
146/* --- @acl_addpriv@ --- *
147 *
148 * Arguments: @acl_entry ***a@ = address of pointer to list tail
149 * @unsigned act@ = what to do with matching addresses
150 *
151 * Returns: ---
152 *
153 * Use: Adds a privileged-port check to the end of an access control
154 * list.
e82f7154 155 */
156
0ac54f22 157extern void acl_addpriv(acl_entry ***/*a*/, unsigned /*act*/);
e82f7154 158
159/*----- That's all, folks -------------------------------------------------*/
160
161#ifdef __cplusplus
162 }
163#endif
164
165#endif