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