77#include <sys/kernel.h>
78#include <sys/module.h>
101#define FTP_CONTROL_PORT_NUMBER 21
112 if (ah->
dport == NULL || ah->
sport == NULL || ah->
lnk == NULL ||
124 if (ah->
dport == NULL || ah->
sport == NULL || ah->
lnk == NULL)
197#define FTP_CONTROL_PORT_NUMBER 21
198#define MAX_MESSAGE_SIZE 128
201#define WAIT_CRLF 0x01
225 int hlen, tlen, dlen, pflags;
231 tc = (
struct tcphdr *)ip_next(pip);
232 hlen = (pip->
ip_hl + tc->th_off) << 2;
233 tlen = ntohs(pip->
ip_len);
271 tlen = ntohs(pip->
ip_len);
272 if (sptr[tlen - 2] ==
'\r' && sptr[tlen - 1] ==
'\n')
273 pflags &= ~WAIT_CRLF;
285 int hlen, tlen, dlen, pflags;
290 tc = (
struct tcphdr *)ip_next(pip);
291 hlen = (pip->
ip_hl + tc->th_off) << 2;
292 tlen = ntohs(pip->
ip_len);
320 tlen = ntohs(pip->
ip_len);
322 if (sptr[tlen - 2] ==
'\r' && sptr[tlen - 1] ==
'\n')
323 pflags &= ~WAIT_CRLF;
345 if (strncasecmp(
"PORT ", sptr, 5))
348 addr = port = octet = 0;
350 for (i = 5; i < dlen; i++) {
375 octet = 10 * octet + ch -
'0';
376 else if (ch ==
',') {
377 addr = (addr << 8) + octet;
385 octet = 10 * octet + ch -
'0';
386 else if (ch ==
',' ||
state == 12) {
387 port = (port << 8) + octet;
418 if (strncasecmp(
"EPRT ", sptr, 5))
421 addr = port = octet = 0;
424 for (i = 5; i < dlen; i++) {
460 octet = 10 * octet + ch -
'0';
461 else if (ch ==
'.' ||
state == 10) {
462 addr = (addr << 8) + octet;
476 port = 10 * port + ch -
'0';
477 else if (ch == delim)
508 if (strncmp(
"227 ", sptr, 4))
511 addr = port = octet = 0;
514 for (i = 4; i < dlen; i++) {
538 octet = 10 * octet + ch -
'0';
539 else if (ch ==
',') {
540 addr = (addr << 8) + octet;
548 octet = 10 * octet + ch -
'0';
549 else if (ch ==
',' || (
state == 12 && ch ==
')')) {
550 port = (port << 8) + octet;
579 if (strncmp(
"229 ", sptr, 4))
586 for (i = 4; i < dlen; i++) {
613 port = 10 * port + ch -
'0';
614 else if (ch == delim)
655 if (ftp_lnk != NULL) {
656 int slen, hlen, tlen, dlen;
665 tc = (
struct tcphdr *)ip_next(pip);
666 hlen = (pip->
ip_hl + tc->th_off) << 2;
667 tlen = ntohs(pip->
ip_len);
676 int a1, a2, a3, a4, p1, p2;
681 ptr = (u_char *)&alias_address.
s_addr;
694 ptr = (
char *)&alias_port;
700 sprintf(stemp,
"PORT %d,%d,%d,%d,%d,%d\r\n",
701 a1, a2, a3, a4, p1, p2);
705 "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n",
706 a1, a2, a3, a4, p1, p2);
711 sprintf(stemp,
"EPRT |1|%d.%d.%d.%d|%d|\r\n",
712 a1, a2, a3, a4, ntohs(alias_port));
716 sprintf(stemp,
"229 Entering Extended Passive Mode (|||%d|)\r\n",
722 slen = strlen(stemp);
727 strncpy(sptr, stemp, maxpacketsize - hlen);
735 tc = (
struct tcphdr *)ip_next(pip);
738 pip->
ip_len, tc->th_seq, tc->th_off);
745 new_len = htons(hlen +
746 MIN(slen, maxpacketsize - hlen));
759 tc->th_sum = TcpChecksum(pip);
764 "PacketAlias/HandleFtpOut: Cannot allocate FTP data port\n");
u_short GetAliasPort(struct alias_link *lnk)
void PunchFWHole(struct alias_link *lnk)
struct in_addr GetAliasAddress(struct alias_link *lnk)
struct in_addr GetDestAddress(struct alias_link *lnk)
int GetProtocolFlags(struct alias_link *lnk)
struct in_addr GetOriginalAddress(struct alias_link *lnk)
void SetAckModified(struct alias_link *lnk)
struct alias_link * AddLink(struct libalias *la, struct in_addr src_addr, struct in_addr dst_addr, struct in_addr alias_addr, u_short src_port, u_short dst_port, int alias_port_param, int link_type)
void SetProtocolFlags(struct alias_link *lnk, int pflags)
void AddSeq(struct alias_link *lnk, int delta, u_int ip_hl, u_short ip_len, u_long th_seq, u_int th_off)
int GetDeltaSeqOut(u_long seq, struct alias_link *lnk)
static int mod_handler(module_t mod, int type, void *data)
static int ParseFtp227Reply(struct libalias *la, char *, int)
static int protohandler_in(struct libalias *la, struct ip *pip, struct alias_data *ah)
MODULE_VERSION(alias_ftp, 1)
static void NewFtpMessage(struct libalias *la, struct ip *, struct alias_link *, int, int)
static moduledata_t alias_mod
static int fingerprint_out(struct libalias *la, struct alias_data *ah)
#define FTP_CONTROL_PORT_NUMBER
static int ParseFtpEprtCommand(struct libalias *la, char *, int)
static int ParseFtp229Reply(struct libalias *la, char *, int)
MODULE_DEPEND(alias_ftp, libalias, 1, 1, 1)
DECLARE_MODULE(alias_ftp, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND)
static void AliasHandleFtpIn(struct libalias *, struct ip *, struct alias_link *)
static int protohandler_out(struct libalias *la, struct ip *pip, struct alias_data *ah)
static void AliasHandleFtpOut(struct libalias *, struct ip *, struct alias_link *, int maxpacketsize)
struct proto_handler handlers[]
static int fingerprint_in(struct libalias *la, struct alias_data *ah)
static int ParseFtpPortCommand(struct libalias *la, char *, int)
void DifferentialChecksum(u_short *_cksum, void *_new, void *_old, int _n)
int LibAliasAttachHandlers(struct proto_handler *p)
int LibAliasDetachHandlers(struct proto_handler *p)