Skip to content

Commit c3aa1bd

Browse files
Julian Anastasovhorms
authored andcommitted
ipvs: support more FTP PASV responses
Change the parsing of FTP commands and responses to support skip character. It allows to detect variations in the 227 PASV response. Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au>
1 parent 8f0ea0f commit c3aa1bd

1 file changed

Lines changed: 38 additions & 14 deletions

File tree

‎net/netfilter/ipvs/ip_vs_ftp.c‎

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
#include <net/ip_vs.h>
4545

4646

47-
#define SERVER_STRING "227 Entering Passive Mode ("
48-
#define CLIENT_STRING "PORT "
47+
#define SERVER_STRING "227 "
48+
#define CLIENT_STRING "PORT"
4949

5050

5151
/*
@@ -79,14 +79,17 @@ ip_vs_ftp_done_conn(struct ip_vs_app *app, struct ip_vs_conn *cp)
7979

8080
/*
8181
* Get <addr,port> from the string "xxx.xxx.xxx.xxx,ppp,ppp", started
82-
* with the "pattern" and terminated with the "term" character.
82+
* with the "pattern", ignoring before "skip" and terminated with
83+
* the "term" character.
8384
* <addr,port> is in network order.
8485
*/
8586
static int ip_vs_ftp_get_addrport(char *data, char *data_limit,
86-
const char *pattern, size_t plen, char term,
87+
const char *pattern, size_t plen,
88+
char skip, char term,
8789
__be32 *addr, __be16 *port,
8890
char **start, char **end)
8991
{
92+
char *s, c;
9093
unsigned char p[6];
9194
int i = 0;
9295

@@ -101,19 +104,38 @@ static int ip_vs_ftp_get_addrport(char *data, char *data_limit,
101104
if (strnicmp(data, pattern, plen) != 0) {
102105
return 0;
103106
}
104-
*start = data + plen;
107+
s = data + plen;
108+
if (skip) {
109+
int found = 0;
110+
111+
for (;; s++) {
112+
if (s == data_limit)
113+
return -1;
114+
if (!found) {
115+
if (*s == skip)
116+
found = 1;
117+
} else if (*s != skip) {
118+
break;
119+
}
120+
}
121+
}
105122

106-
for (data = *start; *data != term; data++) {
123+
for (data = s; ; data++) {
107124
if (data == data_limit)
108125
return -1;
126+
if (*data == term)
127+
break;
109128
}
110129
*end = data;
111130

112131
memset(p, 0, sizeof(p));
113-
for (data = *start; data != *end; data++) {
114-
if (*data >= '0' && *data <= '9') {
115-
p[i] = p[i]*10 + *data - '0';
116-
} else if (*data == ',' && i < 5) {
132+
for (data = s; ; data++) {
133+
c = *data;
134+
if (c == term)
135+
break;
136+
if (c >= '0' && c <= '9') {
137+
p[i] = p[i]*10 + c - '0';
138+
} else if (c == ',' && i < 5) {
117139
i++;
118140
} else {
119141
/* unexpected character */
@@ -124,8 +146,9 @@ static int ip_vs_ftp_get_addrport(char *data, char *data_limit,
124146
if (i != 5)
125147
return -1;
126148

127-
*addr = get_unaligned((__be32 *)p);
128-
*port = get_unaligned((__be16 *)(p + 4));
149+
*start = s;
150+
*addr = get_unaligned((__be32 *) p);
151+
*port = get_unaligned((__be16 *) (p + 4));
129152
return 1;
130153
}
131154

@@ -185,7 +208,8 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
185208

186209
if (ip_vs_ftp_get_addrport(data, data_limit,
187210
SERVER_STRING,
188-
sizeof(SERVER_STRING)-1, ')',
211+
sizeof(SERVER_STRING)-1,
212+
'(', ')',
189213
&from.ip, &port,
190214
&start, &end) != 1)
191215
return 1;
@@ -345,7 +369,7 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
345369
*/
346370
if (ip_vs_ftp_get_addrport(data_start, data_limit,
347371
CLIENT_STRING, sizeof(CLIENT_STRING)-1,
348-
'\r', &to.ip, &port,
372+
' ', '\r', &to.ip, &port,
349373
&start, &end) != 1)
350374
return 1;
351375

0 commit comments

Comments
 (0)