xref: /freebsd/sys/netinet/libalias/alias_local.h (revision 77a0943ded95b9e6438f7db70c4a28e4d93946d4)
1 /* -*- mode: c; tab-width: 3; c-basic-offset: 3; -*-
2     Alias_local.h contains the function prototypes for alias.c,
3     alias_db.c, alias_util.c and alias_ftp.c, alias_irc.c (as well
4     as any future add-ons).  It also includes macros, globals and
5     struct definitions shared by more than one alias*.c file.
6 
7     This include file is intended to be used only within the aliasing
8     software.  Outside world interfaces are defined in alias.h
9 
10     This software is placed into the public domain with no restrictions
11     on its distribution.
12 
13     Initial version:  August, 1996  (cjm)
14 
15      <updated several times by original author and Eivind Eklund>
16 
17     $FreeBSD$
18 */
19 #ifndef ALIAS_LOCAL_H
20 #define ALIAS_LOCAL_H
21 
22 #ifndef NULL
23 #define NULL 0
24 #endif
25 
26 /*
27     Macros
28  */
29 
30 /*
31    The following macro is used to update an
32    internet checksum.  "delta" is a 32-bit
33    accumulation of all the changes to the
34    checksum (adding in new 16-bit words and
35    subtracting out old words), and "cksum"
36    is the checksum value to be updated.
37 */
38 #define ADJUST_CHECKSUM(acc, cksum) { \
39     acc += cksum; \
40     if (acc < 0) \
41     { \
42         acc = -acc; \
43         acc = (acc >> 16) + (acc & 0xffff); \
44         acc += acc >> 16; \
45         cksum = (u_short) ~acc; \
46     } \
47     else \
48     { \
49         acc = (acc >> 16) + (acc & 0xffff); \
50         acc += acc >> 16; \
51         cksum = (u_short) acc; \
52     } \
53 }
54 
55 
56 /*
57     Globals
58 */
59 
60 extern int packetAliasMode;
61 
62 
63 /*
64     Structs
65 */
66 
67 struct alias_link;    /* Incomplete structure */
68 
69 
70 /*
71     Prototypes
72 */
73 
74 /* General utilities */
75 u_short IpChecksum(struct ip *);
76 u_short TcpChecksum(struct ip *);
77 void DifferentialChecksum(u_short *, u_short *, u_short *, int);
78 
79 /* Internal data access */
80 struct alias_link *
81 FindIcmpIn(struct in_addr, struct in_addr, u_short, int);
82 
83 struct alias_link *
84 FindIcmpOut(struct in_addr, struct in_addr, u_short, int);
85 
86 struct alias_link *
87 FindFragmentIn1(struct in_addr, struct in_addr, u_short);
88 
89 struct alias_link *
90 FindFragmentIn2(struct in_addr, struct in_addr, u_short);
91 
92 struct alias_link *
93 AddFragmentPtrLink(struct in_addr, u_short);
94 
95 struct alias_link *
96 FindFragmentPtr(struct in_addr, u_short);
97 
98 struct alias_link *
99 FindProtoIn(struct in_addr, struct in_addr, u_char);
100 
101 struct alias_link *
102 FindProtoOut(struct in_addr, struct in_addr, u_char);
103 
104 struct alias_link *
105 FindUdpTcpIn (struct in_addr, struct in_addr, u_short, u_short, u_char, int);
106 
107 struct alias_link *
108 FindUdpTcpOut(struct in_addr, struct in_addr, u_short, u_short, u_char, int);
109 
110 struct alias_link *
111 AddPptp(struct in_addr, struct in_addr, struct in_addr, u_int16_t);
112 
113 struct alias_link *
114 FindPptpOutByCallId(struct in_addr, struct in_addr, u_int16_t);
115 
116 struct alias_link *
117 FindPptpInByCallId(struct in_addr, struct in_addr, u_int16_t);
118 
119 struct alias_link *
120 FindPptpOutByPeerCallId(struct in_addr, struct in_addr, u_int16_t);
121 
122 struct alias_link *
123 FindPptpInByPeerCallId(struct in_addr, struct in_addr, u_int16_t);
124 
125 struct alias_link *
126 FindRtspOut(struct in_addr, struct in_addr, u_short, u_short, u_char);
127 
128 struct in_addr
129 FindOriginalAddress(struct in_addr);
130 
131 struct in_addr
132 FindAliasAddress(struct in_addr);
133 
134 /* External data access/modification */
135 int FindNewPortGroup(struct in_addr, struct in_addr,
136                      u_short, u_short, u_short, u_char, u_char);
137 void GetFragmentAddr(struct alias_link *, struct in_addr *);
138 void SetFragmentAddr(struct alias_link *, struct in_addr);
139 void GetFragmentPtr(struct alias_link *, char **);
140 void SetFragmentPtr(struct alias_link *, char *);
141 void SetStateIn(struct alias_link *, int);
142 void SetStateOut(struct alias_link *, int);
143 int GetStateIn(struct alias_link *);
144 int GetStateOut(struct alias_link *);
145 struct in_addr GetOriginalAddress(struct alias_link *);
146 struct in_addr GetDestAddress(struct alias_link *);
147 struct in_addr GetAliasAddress(struct alias_link *);
148 struct in_addr GetDefaultAliasAddress(void);
149 void SetDefaultAliasAddress(struct in_addr);
150 u_short GetOriginalPort(struct alias_link *);
151 u_short GetAliasPort(struct alias_link *);
152 struct in_addr GetProxyAddress(struct alias_link *);
153 void SetProxyAddress(struct alias_link *, struct in_addr);
154 u_short GetProxyPort(struct alias_link *);
155 void SetProxyPort(struct alias_link *, u_short);
156 void SetAckModified(struct alias_link *);
157 int GetAckModified(struct alias_link *);
158 int GetDeltaAckIn(struct ip *, struct alias_link *);
159 int GetDeltaSeqOut(struct ip *, struct alias_link *);
160 void AddSeq(struct ip *, struct alias_link *, int);
161 void SetExpire(struct alias_link *, int);
162 void ClearCheckNewLink(void);
163 void SetLastLineCrlfTermed(struct alias_link *, int);
164 int GetLastLineCrlfTermed(struct alias_link *);
165 void SetDestCallId(struct alias_link *, u_int16_t);
166 #ifndef NO_FW_PUNCH
167 void PunchFWHole(struct alias_link *);
168 #endif
169 
170 
171 /* Housekeeping function */
172 void HouseKeeping(void);
173 
174 /* Tcp specfic routines */
175 /*lint -save -library Suppress flexelint warnings */
176 
177 /* FTP routines */
178 void AliasHandleFtpOut(struct ip *, struct alias_link *, int);
179 
180 /* IRC routines */
181 void AliasHandleIrcOut(struct ip *, struct alias_link *, int);
182 
183 /* RTSP routines */
184 void AliasHandleRtspOut(struct ip *, struct alias_link *, int);
185 
186 /* PPTP routines */
187 void AliasHandlePptpOut(struct ip *, struct alias_link *);
188 void AliasHandlePptpIn(struct ip *, struct alias_link *);
189 int AliasHandlePptpGreOut(struct ip *);
190 int AliasHandlePptpGreIn(struct ip *);
191 
192 /* NetBIOS routines */
193 int AliasHandleUdpNbt(struct ip *, struct alias_link *, struct in_addr *, u_short);
194 int AliasHandleUdpNbtNS(struct ip *, struct alias_link *, struct in_addr *, u_short *, struct in_addr *, u_short *);
195 
196 /* CUSeeMe routines */
197 void AliasHandleCUSeeMeOut(struct ip *, struct alias_link *);
198 void AliasHandleCUSeeMeIn(struct ip *, struct in_addr);
199 
200 /* Transparent proxy routines */
201 int ProxyCheck(struct ip *, struct in_addr *, u_short *);
202 void ProxyModify(struct alias_link *, struct ip *, int, int);
203 
204 
205 enum alias_tcp_state {
206     ALIAS_TCP_STATE_NOT_CONNECTED,
207     ALIAS_TCP_STATE_CONNECTED,
208     ALIAS_TCP_STATE_DISCONNECTED
209 };
210 /*lint -restore */
211 #endif /* defined(ALIAS_LOCAL_H) */
212