xref: /freebsd/sys/netinet/libalias/alias.h (revision 807a5caa14df5ff04b331e24b45893f6a2f6bc1b)
1 /*lint -save -library Flexelint comment for external headers */
2 
3 /*
4     Alias.h defines the outside world interfaces for the packet
5     aliasing software.
6 
7     This software is placed into the public domain with no restrictions
8     on its distribution.
9 
10  $FreeBSD$
11 */
12 
13 
14 #ifndef _ALIAS_H_
15 #define _ALIAS_H_
16 
17 /* Alias link representative (incomplete struct) */
18 struct alias_link;
19 
20 /* External interfaces (API) to packet aliasing engine */
21 
22 /* Initialization and Control */
23     extern void
24     PacketAliasInit(void);
25 
26     extern void
27     PacketAliasUninit(void);
28 
29     extern void
30     PacketAliasSetAddress(struct in_addr);
31 
32     extern unsigned int
33     PacketAliasSetMode(unsigned int, unsigned int);
34 
35 #ifndef NO_FW_PUNCH
36     extern void
37     PacketAliasSetFWBase(unsigned int, unsigned int);
38 #endif
39 
40 /* Packet Handling */
41     extern int
42     PacketAliasIn(char *, int maxpacketsize);
43 
44     extern int
45     PacketAliasOut(char *, int maxpacketsize);
46 
47 /* Port and Address Redirection */
48     extern struct alias_link *
49     PacketAliasRedirectPort(struct in_addr, u_short,
50                             struct in_addr, u_short,
51                             struct in_addr, u_short,
52                             u_char);
53 
54     extern int
55     PacketAliasPptp(struct in_addr);
56 
57 
58     extern struct alias_link *
59     PacketAliasRedirectAddr(struct in_addr,
60                             struct in_addr);
61 
62     extern void
63     PacketAliasRedirectDelete(struct alias_link *);
64 
65 /* Fragment Handling */
66     extern int
67     PacketAliasSaveFragment(char *);
68 
69     extern char *
70     PacketAliasGetFragment(char *);
71 
72     extern void
73     PacketAliasFragmentIn(char *, char *);
74 
75 /* Miscellaneous Functions */
76     extern void
77     PacketAliasSetTarget(struct in_addr addr);
78 
79     extern int
80     PacketAliasCheckNewLink(void);
81 
82     extern u_short
83     PacketAliasInternetChecksum(u_short *, int);
84 
85 /* Transparent Proxying */
86     extern int
87     PacketAliasProxyRule(const char *);
88 
89 
90 /********************** Mode flags ********************/
91 /* Set these flags using PacketAliasSetMode() */
92 
93 /* If PKT_ALIAS_LOG is set, a message will be printed to
94 	/var/log/alias.log every time a link is created or deleted.  This
95 	is useful for debugging */
96 #define PKT_ALIAS_LOG 0x01
97 
98 /* If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g.
99 	to ftp, telnet or web servers will be prevented by the aliasing
100 	mechanism.  */
101 #define PKT_ALIAS_DENY_INCOMING 0x02
102 
103 /* If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from
104 	the same port as they originated on.  This allows e.g. rsh to work
105 	*99% of the time*, but _not_ 100%.  (It will be slightly flakey
106 	instead of not working at all.)  This mode bit is set by
107         PacketAliasInit(), so it is a default mode of operation. */
108 #define PKT_ALIAS_SAME_PORTS 0x04
109 
110 /* If PKT_ALIAS_USE_SOCKETS is set, then when partially specified
111 	links (e.g. destination port and/or address is zero), the packet
112 	aliasing engine will attempt to allocate a socket for the aliasing
113 	port it chooses.  This will avoid interference with the host
114 	machine.  Fully specified links do not require this.  This bit
115         is set after a call to PacketAliasInit(), so it is a default
116         mode of operation.*/
117 #define PKT_ALIAS_USE_SOCKETS 0x08
118 
119 /* If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
120 	unregistered source addresses will be aliased (along with those
121 	of the ppp host maching itself.  Private addresses are those
122         in the following ranges:
123 		10.0.0.0     ->   10.255.255.255
124 		172.16.0.0   ->   172.31.255.255
125 		192.168.0.0  ->   192.168.255.255  */
126 #define PKT_ALIAS_UNREGISTERED_ONLY 0x10
127 
128 /* If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
129 	aliasing links will be reset whenever PacketAliasSetAddress()
130         changes the default aliasing address.  If the default aliasing
131         address is left unchanged by this functions call, then the
132         table of dynamic aliasing links will be left intact.  This
133         bit is set after a call to PacketAliasInit(). */
134 #define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
135 
136 #ifndef NO_FW_PUNCH
137 /* If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections
138    will create a 'hole' in the firewall to allow the transfers to
139    work.  Where (IPFW "line-numbers") the hole is created is
140    controlled by PacketAliasSetFWBase(base, size). The hole will be
141    attached to that particular alias_link, so when the link goes away
142    so do the hole.  */
143 #define PKT_ALIAS_PUNCH_FW 0x100
144 #endif
145 
146 /* If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
147       transparent proxying performed */
148 #define PKT_ALIAS_PROXY_ONLY 0x40
149 
150 /* If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn()
151       and PacketAliasOut() are reversed */
152 #define PKT_ALIAS_REVERSE 0x80
153 
154 /* Return Codes */
155 #define PKT_ALIAS_ERROR -1
156 #define PKT_ALIAS_OK 1
157 #define PKT_ALIAS_IGNORED 2
158 #define PKT_ALIAS_UNRESOLVED_FRAGMENT 3
159 #define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4
160 
161 #endif
162 /*lint -restore */
163