Add an integer field to keep protocol-specific flags with links.
For FTP control connection, keep the CRLF end-of-line termination status in there. Fixed the bug when the first FTP command in a session was ignored. PR: 24048 MFC after: 1 week
This commit is contained in:
parent
39f6498da2
commit
79ec1c507a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=77485
@ -279,6 +279,7 @@ struct alias_link /* Main data structure */
|
||||
#define LINK_PPTP (IPPROTO_MAX + 4)
|
||||
|
||||
int flags; /* indicates special characteristics */
|
||||
int pflags; /* protocol-specific flags */
|
||||
|
||||
/* flag bits */
|
||||
#define LINK_UNKNOWN_DEST_PORT 0x01
|
||||
@ -286,7 +287,6 @@ struct alias_link /* Main data structure */
|
||||
#define LINK_PERMANENT 0x04
|
||||
#define LINK_PARTIALLY_SPECIFIED 0x03 /* logical-or of first two bits */
|
||||
#define LINK_UNFIREWALLED 0x08
|
||||
#define LINK_LAST_LINE_CRLF_TERMED 0x10
|
||||
|
||||
int timestamp; /* Time link was last accessed */
|
||||
int expire_time; /* Expire time for link */
|
||||
@ -991,6 +991,7 @@ AddLink(struct in_addr src_addr,
|
||||
link->link_type = link_type;
|
||||
link->sockfd = -1;
|
||||
link->flags = 0;
|
||||
link->pflags = 0;
|
||||
link->timestamp = timeStamp;
|
||||
|
||||
/* Expiration time */
|
||||
@ -1829,7 +1830,7 @@ FindAliasAddress(struct in_addr original_addr)
|
||||
GetOriginalPort(), GetAliasPort()
|
||||
SetAckModified(), GetAckModified()
|
||||
GetDeltaAckIn(), GetDeltaSeqOut(), AddSeq()
|
||||
SetLastLineCrlfTermed(), GetLastLineCrlfTermed()
|
||||
SetProtocolFlags(), GetProtocolFlags()
|
||||
SetDestCallId()
|
||||
*/
|
||||
|
||||
@ -2197,20 +2198,17 @@ ClearCheckNewLink(void)
|
||||
}
|
||||
|
||||
void
|
||||
SetLastLineCrlfTermed(struct alias_link *link, int yes)
|
||||
SetProtocolFlags(struct alias_link *link, int pflags)
|
||||
{
|
||||
|
||||
if (yes)
|
||||
link->flags |= LINK_LAST_LINE_CRLF_TERMED;
|
||||
else
|
||||
link->flags &= ~LINK_LAST_LINE_CRLF_TERMED;
|
||||
link->pflags = pflags;;
|
||||
}
|
||||
|
||||
int
|
||||
GetLastLineCrlfTermed(struct alias_link *link)
|
||||
GetProtocolFlags(struct alias_link *link)
|
||||
{
|
||||
|
||||
return (link->flags & LINK_LAST_LINE_CRLF_TERMED);
|
||||
return (link->pflags);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -59,6 +59,9 @@
|
||||
#define FTP_CONTROL_PORT_NUMBER 21
|
||||
#define MAX_MESSAGE_SIZE 128
|
||||
|
||||
/* FTP protocol flags. */
|
||||
#define WAIT_CRLF 0x01
|
||||
|
||||
enum ftp_message_type {
|
||||
FTP_PORT_COMMAND,
|
||||
FTP_EPRT_COMMAND,
|
||||
@ -82,7 +85,7 @@ 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) */)
|
||||
{
|
||||
int hlen, tlen, dlen;
|
||||
int hlen, tlen, dlen, pflags;
|
||||
char *sptr;
|
||||
struct tcphdr *tc;
|
||||
int ftp_message_type;
|
||||
@ -101,7 +104,8 @@ int maxpacketsize /* The maximum size this packet can grow to (including header
|
||||
* Check that data length is not too long and previous message was
|
||||
* properly terminated with CRLF.
|
||||
*/
|
||||
if (dlen <= MAX_MESSAGE_SIZE && GetLastLineCrlfTermed(link)) {
|
||||
pflags = GetProtocolFlags(link);
|
||||
if (dlen <= MAX_MESSAGE_SIZE && (pflags & WAIT_CRLF)) {
|
||||
ftp_message_type = FTP_UNKNOWN_MESSAGE;
|
||||
|
||||
if (ntohs(tc->th_dport) == FTP_CONTROL_PORT_NUMBER) {
|
||||
@ -131,8 +135,11 @@ int maxpacketsize /* The maximum size this packet can grow to (including header
|
||||
if (dlen) { /* only if there's data */
|
||||
sptr = (char *) pip; /* start over at beginning */
|
||||
tlen = ntohs(pip->ip_len); /* recalc tlen, pkt may have grown */
|
||||
SetLastLineCrlfTermed(link,
|
||||
(sptr[tlen-2] == '\r') && (sptr[tlen-1] == '\n'));
|
||||
if (sptr[tlen-2] == '\r' && sptr[tlen-1] == '\n')
|
||||
pflags &= ~WAIT_CRLF;
|
||||
else
|
||||
pflags |= WAIT_CRLF;
|
||||
SetProtocolFlags(link, pflags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,8 +144,8 @@ int GetDeltaSeqOut(struct ip *_pip, struct alias_link *_link);
|
||||
void AddSeq(struct ip *_pip, struct alias_link *_link, int _delta);
|
||||
void SetExpire(struct alias_link *_link, int _expire);
|
||||
void ClearCheckNewLink(void);
|
||||
void SetLastLineCrlfTermed(struct alias_link *_link, int _yes);
|
||||
int GetLastLineCrlfTermed(struct alias_link *_link);
|
||||
void SetProtocolFlags(struct alias_link *_link, int _pflags);
|
||||
int GetProtocolFlags(struct alias_link *_link);
|
||||
void SetDestCallId(struct alias_link *_link, u_int16_t _cid);
|
||||
#ifndef NO_FW_PUNCH
|
||||
void PunchFWHole(struct alias_link *_link);
|
||||
|
@ -279,6 +279,7 @@ struct alias_link /* Main data structure */
|
||||
#define LINK_PPTP (IPPROTO_MAX + 4)
|
||||
|
||||
int flags; /* indicates special characteristics */
|
||||
int pflags; /* protocol-specific flags */
|
||||
|
||||
/* flag bits */
|
||||
#define LINK_UNKNOWN_DEST_PORT 0x01
|
||||
@ -286,7 +287,6 @@ struct alias_link /* Main data structure */
|
||||
#define LINK_PERMANENT 0x04
|
||||
#define LINK_PARTIALLY_SPECIFIED 0x03 /* logical-or of first two bits */
|
||||
#define LINK_UNFIREWALLED 0x08
|
||||
#define LINK_LAST_LINE_CRLF_TERMED 0x10
|
||||
|
||||
int timestamp; /* Time link was last accessed */
|
||||
int expire_time; /* Expire time for link */
|
||||
@ -991,6 +991,7 @@ AddLink(struct in_addr src_addr,
|
||||
link->link_type = link_type;
|
||||
link->sockfd = -1;
|
||||
link->flags = 0;
|
||||
link->pflags = 0;
|
||||
link->timestamp = timeStamp;
|
||||
|
||||
/* Expiration time */
|
||||
@ -1829,7 +1830,7 @@ FindAliasAddress(struct in_addr original_addr)
|
||||
GetOriginalPort(), GetAliasPort()
|
||||
SetAckModified(), GetAckModified()
|
||||
GetDeltaAckIn(), GetDeltaSeqOut(), AddSeq()
|
||||
SetLastLineCrlfTermed(), GetLastLineCrlfTermed()
|
||||
SetProtocolFlags(), GetProtocolFlags()
|
||||
SetDestCallId()
|
||||
*/
|
||||
|
||||
@ -2197,20 +2198,17 @@ ClearCheckNewLink(void)
|
||||
}
|
||||
|
||||
void
|
||||
SetLastLineCrlfTermed(struct alias_link *link, int yes)
|
||||
SetProtocolFlags(struct alias_link *link, int pflags)
|
||||
{
|
||||
|
||||
if (yes)
|
||||
link->flags |= LINK_LAST_LINE_CRLF_TERMED;
|
||||
else
|
||||
link->flags &= ~LINK_LAST_LINE_CRLF_TERMED;
|
||||
link->pflags = pflags;;
|
||||
}
|
||||
|
||||
int
|
||||
GetLastLineCrlfTermed(struct alias_link *link)
|
||||
GetProtocolFlags(struct alias_link *link)
|
||||
{
|
||||
|
||||
return (link->flags & LINK_LAST_LINE_CRLF_TERMED);
|
||||
return (link->pflags);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -59,6 +59,9 @@
|
||||
#define FTP_CONTROL_PORT_NUMBER 21
|
||||
#define MAX_MESSAGE_SIZE 128
|
||||
|
||||
/* FTP protocol flags. */
|
||||
#define WAIT_CRLF 0x01
|
||||
|
||||
enum ftp_message_type {
|
||||
FTP_PORT_COMMAND,
|
||||
FTP_EPRT_COMMAND,
|
||||
@ -82,7 +85,7 @@ 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) */)
|
||||
{
|
||||
int hlen, tlen, dlen;
|
||||
int hlen, tlen, dlen, pflags;
|
||||
char *sptr;
|
||||
struct tcphdr *tc;
|
||||
int ftp_message_type;
|
||||
@ -101,7 +104,8 @@ int maxpacketsize /* The maximum size this packet can grow to (including header
|
||||
* Check that data length is not too long and previous message was
|
||||
* properly terminated with CRLF.
|
||||
*/
|
||||
if (dlen <= MAX_MESSAGE_SIZE && GetLastLineCrlfTermed(link)) {
|
||||
pflags = GetProtocolFlags(link);
|
||||
if (dlen <= MAX_MESSAGE_SIZE && (pflags & WAIT_CRLF)) {
|
||||
ftp_message_type = FTP_UNKNOWN_MESSAGE;
|
||||
|
||||
if (ntohs(tc->th_dport) == FTP_CONTROL_PORT_NUMBER) {
|
||||
@ -131,8 +135,11 @@ int maxpacketsize /* The maximum size this packet can grow to (including header
|
||||
if (dlen) { /* only if there's data */
|
||||
sptr = (char *) pip; /* start over at beginning */
|
||||
tlen = ntohs(pip->ip_len); /* recalc tlen, pkt may have grown */
|
||||
SetLastLineCrlfTermed(link,
|
||||
(sptr[tlen-2] == '\r') && (sptr[tlen-1] == '\n'));
|
||||
if (sptr[tlen-2] == '\r' && sptr[tlen-1] == '\n')
|
||||
pflags &= ~WAIT_CRLF;
|
||||
else
|
||||
pflags |= WAIT_CRLF;
|
||||
SetProtocolFlags(link, pflags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,8 +144,8 @@ int GetDeltaSeqOut(struct ip *_pip, struct alias_link *_link);
|
||||
void AddSeq(struct ip *_pip, struct alias_link *_link, int _delta);
|
||||
void SetExpire(struct alias_link *_link, int _expire);
|
||||
void ClearCheckNewLink(void);
|
||||
void SetLastLineCrlfTermed(struct alias_link *_link, int _yes);
|
||||
int GetLastLineCrlfTermed(struct alias_link *_link);
|
||||
void SetProtocolFlags(struct alias_link *_link, int _pflags);
|
||||
int GetProtocolFlags(struct alias_link *_link);
|
||||
void SetDestCallId(struct alias_link *_link, u_int16_t _cid);
|
||||
#ifndef NO_FW_PUNCH
|
||||
void PunchFWHole(struct alias_link *_link);
|
||||
|
Loading…
Reference in New Issue
Block a user