xref: /freebsd/sys/netinet/libalias/alias.h (revision 11afcc8f9f96d657b8e6f7547c02c1957331fc96)
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     $Id: alias.h,v 1.7 1998/01/16 12:56:07 bde Exp $
11 */
12 
13 
14 #ifndef _ALIAS_H_
15 #define _ALIAS_H_
16 
17 #ifndef NULL
18 #define NULL 0
19 #endif
20 
21 /* Alias link representative (incomplete struct) */
22 struct alias_link;
23 
24 /* External interfaces (API) to packet aliasing engine */
25 
26 /* Initialization and Control */
27     extern void
28     PacketAliasInit(void);
29 
30     extern void
31     PacketAliasUninit(void);
32 
33     extern void
34     PacketAliasSetAddress(struct in_addr);
35 
36     extern unsigned int
37     PacketAliasSetMode(unsigned int, unsigned int);
38 
39 #ifndef NO_FW_PUNCH
40     extern void
41     PacketAliasSetFWBase(unsigned int, unsigned int);
42 #endif
43 
44 /* Packet Handling */
45     extern int
46     PacketAliasIn(char *, int maxpacketsize);
47 
48     extern int
49     PacketAliasOut(char *, int maxpacketsize);
50 
51 /* Port and Address Redirection */
52     extern struct alias_link *
53     PacketAliasRedirectPort(struct in_addr, u_short,
54                             struct in_addr, u_short,
55                             struct in_addr, u_short,
56                             u_char);
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 
86 /*
87    In version 2.2, the function names were rationalized
88    to all be of the form PacketAlias...  These are the
89    old function names for backwards compatibility
90 */
91 extern int SaveFragmentPtr(char *);
92 extern char *GetNextFragmentPtr(char *);
93 extern void FragmentAliasIn(char *, char *);
94 extern void SetPacketAliasAddress(struct in_addr);
95 extern void InitPacketAlias(void);
96 extern unsigned int SetPacketAliasMode(unsigned int, unsigned int);
97 extern int PacketAliasIn2(char *, struct in_addr, int maxpacketsize);
98 extern int PacketAliasOut2(char *, struct in_addr, int maxpacketsize);
99 extern int
100 PacketAliasPermanentLink(struct in_addr, u_short,
101                          struct in_addr, u_short,
102                          u_short, u_char);
103 extern u_short InternetChecksum(u_short *, int);
104 
105 /* Obsolete constant */
106 #define PKT_ALIAS_NEW_LINK 5
107 
108 /********************** Mode flags ********************/
109 /* Set these flags using SetPacketAliasMode() */
110 
111 /* If PKT_ALIAS_LOG is set, a message will be printed to
112 	/var/log/alias.log every time a link is created or deleted.  This
113 	is useful for debugging */
114 #define PKT_ALIAS_LOG 0x01
115 
116 /* If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g.
117 	to ftp, telnet or web servers will be prevented by the aliasing
118 	mechanism.  */
119 #define PKT_ALIAS_DENY_INCOMING 0x02
120 
121 /* If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from
122 	the same port as they originated on.  This allows eg rsh to work
123 	*99% of the time*, but _not_ 100%.  (It will be slightly flakey
124 	instead of not working at all.)  This mode bit is set by
125         PacketAliasInit(), so it is a default mode of operation. */
126 #define PKT_ALIAS_SAME_PORTS 0x04
127 
128 /* If PKT_ALIAS_USE_SOCKETS is set, then when partially specified
129 	links (e.g. destination port and/or address is zero), the packet
130 	aliasing engine will attempt to allocate a socket for the aliasing
131 	port it chooses.  This will avoid interference with the host
132 	machine.  Fully specified links do not require this.  This bit
133         is set after a call to PacketAliasInit(), so it is a default
134         mode of operation.*/
135 #define PKT_ALIAS_USE_SOCKETS 0x08
136 
137 /* If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with with
138 	unregistered source addresses will be aliased (along with those
139 	of the ppp host maching itself.  Private addresses are those
140         in the following ranges:
141 
142 		10.0.0.0     ->   10.255.255.255
143 		172.16.0.0   ->   172.31.255.255
144 		192.168.0.0  ->   192.168.255.255  */
145 #define PKT_ALIAS_UNREGISTERED_ONLY 0x10
146 
147 /* If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic
148 	aliasing links will be reset whenever PacketAliasSetAddress()
149         changes the default aliasing address.  If the default aliasing
150         address is left unchanged by this functions call, then the
151         table of dynamic aliasing links will be left intact.  This
152         bit is set after a call to PacketAliasInit(). */
153 #define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20
154 
155 #ifndef NO_FW_PUNCH
156 /* If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections
157    will create a 'hole' in the firewall to allow the transfers to
158    work.  Where (IPFW "line-numbers") the hole is created is
159    controlled by PacketAliasSetFWBase(base, size). The hole will be
160    attached to that particular alias_link, so when the link goes away
161    so do the hole.  */
162 #define PKT_ALIAS_PUNCH_FW 0x40
163 #endif
164 
165 /* Return Codes */
166 #define PKT_ALIAS_ERROR -1
167 #define PKT_ALIAS_OK 1
168 #define PKT_ALIAS_IGNORED 2
169 #define PKT_ALIAS_UNRESOLVED_FRAGMENT 3
170 #define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4
171 
172 #endif
173 /*lint -restore */
174