MCPcopy Create free account
hub / github.com/F-Stack/f-stack / AliasHandleFtpOut

Function AliasHandleFtpOut

freebsd/netinet/libalias/alias_ftp.c:221–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219static void NewFtpMessage(struct libalias *la, struct ip *, struct alias_link *, int, int);
220
221static void
222AliasHandleFtpOut(
223 struct libalias *la,
224 struct ip *pip, /* IP packet to examine/patch */
225 struct alias_link *lnk, /* The link to go through (aliased port) */
226 int maxpacketsize /* The maximum size this packet can grow to
227 (including headers) */ )
228{
229 int hlen, tlen, dlen, pflags;
230 char *sptr;
231 struct tcphdr *tc;
232 int ftp_message_type;
233
234/* Calculate data length of TCP packet */
235 tc = (struct tcphdr *)ip_next(pip);
236 hlen = (pip->ip_hl + tc->th_off) << 2;
237 tlen = ntohs(pip->ip_len);
238 dlen = tlen - hlen;
239
240/* Place string pointer and beginning of data */
241 sptr = (char *)pip;
242 sptr += hlen;
243
244/*
245 * Check that data length is not too long and previous message was
246 * properly terminated with CRLF.
247 */
248 pflags = GetProtocolFlags(lnk);
249 if (dlen <= MAX_MESSAGE_SIZE && !(pflags & WAIT_CRLF)) {
250 ftp_message_type = FTP_UNKNOWN_MESSAGE;
251
252 if (ntohs(tc->th_dport) == FTP_CONTROL_PORT_NUMBER) {
253/*
254 * When aliasing a client, check for the PORT/EPRT command.
255 */
256 if (ParseFtpPortCommand(la, sptr, dlen))
257 ftp_message_type = FTP_PORT_COMMAND;
258 else if (ParseFtpEprtCommand(la, sptr, dlen))
259 ftp_message_type = FTP_EPRT_COMMAND;
260 } else {
261/*
262 * When aliasing a server, check for the 227/229 reply.
263 */
264 if (ParseFtp227Reply(la, sptr, dlen))
265 ftp_message_type = FTP_227_REPLY;
266 else if (ParseFtp229Reply(la, sptr, dlen)) {
267 ftp_message_type = FTP_229_REPLY;
268 la->true_addr.s_addr = pip->ip_src.s_addr;
269 }
270 }
271
272 if (ftp_message_type != FTP_UNKNOWN_MESSAGE)
273 NewFtpMessage(la, pip, lnk, maxpacketsize, ftp_message_type);
274 }
275/* Track the msgs which are CRLF term'd for PORT/PASV FW breach */
276
277 if (dlen) { /* only if there's data */
278 sptr = (char *)pip; /* start over at beginning */

Callers 1

protohandler_outFunction · 0.85

Calls 8

ip_nextFunction · 0.85
GetProtocolFlagsFunction · 0.85
ParseFtpPortCommandFunction · 0.85
ParseFtpEprtCommandFunction · 0.85
ParseFtp227ReplyFunction · 0.85
ParseFtp229ReplyFunction · 0.85
NewFtpMessageFunction · 0.85
SetProtocolFlagsFunction · 0.85

Tested by

no test coverage detected