xref: /freebsd/sys/netinet/libalias/alias.h (revision b601c69bdbe8755d26570261d7fd4c02ee4eff74)
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     PacketAliasAddServer(struct alias_link *link,
56                          struct in_addr addr,
57                          u_short port);
58 
59     extern struct alias_link *
60     PacketAliasRedirectProto(struct in_addr,
61                              struct in_addr,
62                              struct in_addr,
63                              u_char);
64 
65     extern struct alias_link *
66     PacketAliasRedirectAddr(struct in_addr,
67                             struct in_addr);
68 
69     extern void
70     PacketAliasRedirectDelete(struct alias_link *);
71 
72 /* Fragment Handling */
73     extern int
74     PacketAliasSaveFragment(char *);
75 
76     extern char *
77     PacketAliasGetFragment(char *);
78 
79     extern void
80     PacketAliasFragmentIn(char *, char *);
81 
82 /* Miscellaneous Functions */
83     extern void
84     PacketAliasSetTarget(struct in_addr addr);
85 
86     extern int
87     PacketAliasCheckNewLink(void);
88 
89     extern u_short
90     PacketAliasInternetChecksum(u_short *, int);
91 
92 /* Transparent Proxying */
93     extern int
94     PacketAliasProxyRule(const char *);
95 
96 
97 /********************** Mode flags ********************/
98 /* Set these flags using PacketAliasSetMode() */
99 
100 /* If PKT_ALIAS_LOG is set, a message will be printed to
101 	/var/log/alias.log every time a link is created or deleted.  This
102 	is useful for debugging */
103 #define PKT_ALIAS_LOG 0x01
104 
105 /* If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g.
106 	to ftp, telnet or web servers will be prevented by the aliasing
107 	mechanism.  */
108 #define PKT_ALIAS_DENY_INCOMING 0x02
109 
110 /* If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from
111 	the same port as they originated on.  This allows e.g. rsh to work
112 	*99% of the time*, but _not_ 100%.  (It will be slightly flakey
113 	instead of not working at all.)  This mode bit is set by
114         PacketAliasInit(), so it is a default mode of operation. */
115 #define PKT_ALIAS_SAME_PORTS 0x04
116 
117 /* If PKT_ALIAS_USE_SOCKETS is set, then when partially specified
118 	links (e.g. destination port and/or address is zero), the packet
119 	aliasing engine will attempt to allocate a socket for the aliasing
120 	port it chooses.  This will avoid interference with the host
121 	machine.  Fully specified links do not require this.  This bit
122         is set after a call to PacketAliasInit(), so it is a default
123         mode of operation. */
124 #define PKT_ALIAS_USE_SOCKETS 0x08
125 
126 /* If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with
127 	unregistered source addresses will be aliased.  Private
128 	addresses are those in the following ranges:
129 		10.0.0.0     ->   10.255.255.255
130 		172.16.0.0   ->   172.31.255.255
131 		192.168.0.0  ->   192.168.255.255  */
132 #define PKT_ALIAS_UNREGISTERED_ONLY 0x10
133 
134 /* If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
135 	aliasing links will be reset whenever PacketAliasSetAddress()
136         changes the default aliasing address.  If the default aliasing
137         address is left unchanged by this function call, then the
138         table of dynamic aliasing links will be left intact.  This
139         bit is set after a call to PacketAliasInit(). */
140 #define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
141 
142 #ifndef NO_FW_PUNCH
143 /* If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections
144    will create a 'hole' in the firewall to allow the transfers to
145    work.  Where (IPFW "line-numbers") the hole is created is
146    controlled by PacketAliasSetFWBase(base, size). The hole will be
147    attached to that particular alias_link, so when the link goes away
148    so do the hole.  */
149 #define PKT_ALIAS_PUNCH_FW 0x100
150 #endif
151 
152 /* If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only
153       transparent proxying performed */
154 #define PKT_ALIAS_PROXY_ONLY 0x40
155 
156 /* If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn()
157       and PacketAliasOut() are reversed */
158 #define PKT_ALIAS_REVERSE 0x80
159 
160 /* Return Codes */
161 #define PKT_ALIAS_ERROR -1
162 #define PKT_ALIAS_OK 1
163 #define PKT_ALIAS_IGNORED 2
164 #define PKT_ALIAS_UNRESOLVED_FRAGMENT 3
165 #define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4
166 
167 #endif
168 /*lint -restore */
169