From f8d3448a0b0121bbc98284cf17e9d081108ee8ba Mon Sep 17 00:00:00 2001 From: ru Date: Thu, 6 Apr 2000 15:54:52 +0000 Subject: - Add support for FTP EPRT (RFC 2428) command. - Minor optimizations. - Minor spelling fixes. PR: 14305 Submitted by: ume Rewritten by: ru --- sys/netinet/libalias/alias_ftp.c | 232 ++++++++++++++++++++++++++++----------- 1 file changed, 169 insertions(+), 63 deletions(-) (limited to 'sys/netinet/libalias') diff --git a/sys/netinet/libalias/alias_ftp.c b/sys/netinet/libalias/alias_ftp.c index ca2d53b..2b4c51e 100644 --- a/sys/netinet/libalias/alias_ftp.c +++ b/sys/netinet/libalias/alias_ftp.c @@ -14,6 +14,10 @@ changes of sequence and acknowledgment numbers, since the client machine is totally unaware of the modification to the TCP stream. + This version also supports the EPRT command, which is functionally + equivalent to the PORT command, but was designed to support both + IPv4 and IPv6 addresses. See RFC 2428 for specifications. + This software is placed into the public domain with no restrictions on its distribution. @@ -25,13 +29,13 @@ error for modified IP packets. Version 1.7: January 9, 1996 (cjm) - Differental checksum computation for change + Differential checksum computation for change in IP packet length. Version 2.1: May, 1997 (cjm) Very minor changes to conform with local/global/function naming conventions - withing the packet alising module. + within the packet aliasing module. See HISTORY file for record of revisions. @@ -50,7 +54,9 @@ #include "alias_local.h" -static void NewFtpPortCommand(struct ip *, struct alias_link *, struct in_addr, u_short, int); +static int ParseFtpPortCommand(char *, int, struct ip *, struct alias_link *, int); +static void ParseFtpEprtCommand(char *, int, struct ip *, struct alias_link *, int); +static void NewFtpPortCommand(struct ip *, struct alias_link *, struct in_addr, u_short, int, int); @@ -61,8 +67,6 @@ struct alias_link *link, /* The link to go through (aliased port) */ int maxpacketsize /* The maximum size this packet can grow to (including headers) */) { int hlen, tlen, dlen; - struct in_addr true_addr; - u_short true_port; char *sptr; struct tcphdr *tc; @@ -72,7 +76,7 @@ int maxpacketsize /* The maximum size this packet can grow to (including header tlen = ntohs(pip->ip_len); dlen = tlen - hlen; -/* Return is data length is too long or too short */ +/* Return if data length is too long or too short */ if (dlen<10 || dlen>80) return; @@ -81,58 +85,152 @@ int maxpacketsize /* The maximum size this packet can grow to (including header sptr += hlen; /* Parse through string using state diagram method */ + if (!ParseFtpPortCommand(sptr, dlen, pip, link, maxpacketsize)) + ParseFtpEprtCommand(sptr, dlen, pip, link, maxpacketsize); +} + +static int +ParseFtpPortCommand( +char *sptr, +int dlen, +struct ip *pip, /* IP packet to examine/patch */ +struct alias_link *link, /* The link to go through (aliased port) */ +int maxpacketsize /* The maximum size this packet can grow to (including headers) */) +{ + struct in_addr true_addr; + u_short true_port; + char ch; + int i, state; + u_long a1, a2, a3, a4; + u_short p1, p2; + + a1=0; a2=0; a3=0; a4=0; p1=0; p2=0; + state=-4; + for (i=0; i