summaryrefslogtreecommitdiff
path: root/datapath-windows/ovsext/Conntrack-ftp.c
diff options
context:
space:
mode:
authorldejing <ldejing@vmware.com>2022-09-16 15:52:51 +0800
committerAlin-Gabriel Serdean <aserdean@ovn.org>2022-09-20 02:27:20 +0300
commit54a618f0bd83431a18307a312e5b41e401538bbc (patch)
tree6b83b320e1b26858b8e3cadfe12f0468c3524968 /datapath-windows/ovsext/Conntrack-ftp.c
parent7a9dc1950f6a6c06f184b734a9f3a24b918088d7 (diff)
downloadopenvswitch-54a618f0bd83431a18307a312e5b41e401538bbc.tar.gz
datapath-windows: Alg support for ftp and tftp in conntrack
This patch mainly support alg field in ct action when process ftp/tftp traffic. Tftp with alg mainly parse the tftp packet (IPv4/IPv6), extract connect info from the tftp packet and create the related connection. For ftp, previous version has supported process of ftp traffic. However, previous version regard traffic from or to port 21 as ftp traffic, this is incorrect in some scenario. This version adds alg field in ct for ftp traffic, we could use ct(alg=ftp) to process any ftp traffic from/to any port. IPv4/IPv6. Test cases: 1) ftp ipv4/ipv6 use alg field in the normal and nat scenario. 2) tftp ipv4/ipv6 use alg field in the normal and nat scenario. Signed-off-by: ldejing <ldejing@vmware.com> Signed-off-by: Alin-Gabriel Serdean <aserdean@ovn.org>
Diffstat (limited to 'datapath-windows/ovsext/Conntrack-ftp.c')
-rw-r--r--datapath-windows/ovsext/Conntrack-ftp.c109
1 files changed, 56 insertions, 53 deletions
diff --git a/datapath-windows/ovsext/Conntrack-ftp.c b/datapath-windows/ovsext/Conntrack-ftp.c
index 066723685..6775496cf 100644
--- a/datapath-windows/ovsext/Conntrack-ftp.c
+++ b/datapath-windows/ovsext/Conntrack-ftp.c
@@ -122,12 +122,9 @@ OvsCtExtractNumbers(char *buf,
*----------------------------------------------------------------------------
*/
NDIS_STATUS
-OvsCtHandleFtp(PNET_BUFFER_LIST curNbl,
- OvsFlowKey *key,
- OVS_PACKET_HDR_INFO *layers,
- UINT64 currentTime,
- POVS_CT_ENTRY entry,
- BOOLEAN request)
+OvsCtHandleFtp(PNET_BUFFER_LIST curNbl, OvsFlowKey *key,
+ OVS_PACKET_HDR_INFO *layers, UINT64 currentTime,
+ POVS_CT_ENTRY entry)
{
NDIS_STATUS status = NDIS_STATUS_SUCCESS;
FTP_TYPE ftpType = 0;
@@ -157,52 +154,51 @@ OvsCtHandleFtp(PNET_BUFFER_LIST curNbl,
OvsStrlcpy((char *)ftpMsg, (char *)buf, min(len, sizeof(ftpMsg)));
char *req = NULL;
- if (request) {
- if ((len >= 5) && (OvsStrncmp("PORT", ftpMsg, 4) == 0)) {
- ftpType = FTP_TYPE_ACTIVE;
- req = ftpMsg + 4;
- } else if ((len >= 5) && (OvsStrncmp("EPRT", ftpMsg, 4) == 0)) {
- ftpType = FTP_EXTEND_TYPE_ACTIVE;
- req = ftpMsg + 4;
+ if ((len >= 5) && (OvsStrncmp("PORT", ftpMsg, 4) == 0)) {
+ ftpType = FTP_TYPE_ACTIVE;
+ req = ftpMsg + 4;
+ } else if ((len >= 5) && (OvsStrncmp("EPRT", ftpMsg, 4) == 0)) {
+ ftpType = FTP_EXTEND_TYPE_ACTIVE;
+ req = ftpMsg + 4;
+ }
+
+ if ((len >= 4) && (OvsStrncmp(FTP_PASV_RSP_PREFIX, ftpMsg, 3) == 0)) {
+ ftpType = FTP_TYPE_PASV;
+ /* There are various formats for PASV command. We try to support
+ * some of them. This has been addressed by RFC 2428 - EPSV.
+ * Eg:
+ * 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
+ * 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2
+ * 227 Entering Passive Mode. h1,h2,h3,h4,p1,p2
+ * 227 =h1,h2,h3,h4,p1,p2
+ */
+ char *paren;
+ paren = strchr(ftpMsg, '(');
+ if (paren) {
+ req = paren + 1;
+ } else {
+ /* PASV command without ( */
+ req = ftpMsg + 3;
+ }
+ } else if ((len >= 4) && (
+ OvsStrncmp(FTP_EXTEND_PASV_RSP_PREFIX, ftpMsg, 3) == 0)) {
+ ftpType = FTP_EXTEND_TYPE_PASV;
+ /* The ftp extended passive mode only contain port info, ip address
+ * is same with the network protocol used by control connection.
+ * 229 Entering Extended Passive Mode (|||port|)
+ * */
+ char *paren;
+ paren = strchr(ftpMsg, '|');
+ if (paren) {
+ req = paren + 3;
+ } else {
+ /* Not a valid EPSV packet. */
+ return NDIS_STATUS_INVALID_PACKET;
}
- } else {
- if ((len >= 4) && (OvsStrncmp(FTP_PASV_RSP_PREFIX, ftpMsg, 3) == 0)) {
- ftpType = FTP_TYPE_PASV;
- /* There are various formats for PASV command. We try to support
- * some of them. This has been addressed by RFC 2428 - EPSV.
- * Eg:
- * 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
- * 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2
- * 227 Entering Passive Mode. h1,h2,h3,h4,p1,p2
- * 227 =h1,h2,h3,h4,p1,p2
- */
- char *paren;
- paren = strchr(ftpMsg, '(');
- if (paren) {
- req = paren + 1;
- } else {
- /* PASV command without ( */
- req = ftpMsg + 3;
- }
- } else if ((len >= 4) && (OvsStrncmp(FTP_EXTEND_PASV_RSP_PREFIX, ftpMsg, 3) == 0)) {
- ftpType = FTP_EXTEND_TYPE_PASV;
- /* The ftp extended passive mode only contain port info, ip address
- * is same with the network protocol used by control connection.
- * 229 Entering Extended Passive Mode (|||port|)
- * */
- char *paren;
- paren = strchr(ftpMsg, '|');
- if (paren) {
- req = paren + 3;
- } else {
- /* Not a valid EPSV packet. */
- return NDIS_STATUS_INVALID_PACKET;
- }
- if (!(*req > '0' && * req < '9')) {
- /* Not a valid port number. */
- return NDIS_STATUS_INVALID_PACKET;
- }
+ if (!(*req > '0' && * req < '9')) {
+ /* Not a valid port number. */
+ return NDIS_STATUS_INVALID_PACKET;
}
}
@@ -226,8 +222,15 @@ OvsCtHandleFtp(PNET_BUFFER_LIST curNbl,
(arr[2] << 8) | arr[3]);
port = ntohs(((arr[4] << 8) | arr[5]));
- serverIp.ipv4 = ip;
- clientIp.ipv4 = key->ipKey.nwDst;
+ if (ftpType == FTP_TYPE_ACTIVE) {
+ serverIp.ipv4 = key->ipKey.nwDst;
+ clientIp.ipv4 = ip;
+ }
+
+ if (ftpType == FTP_TYPE_PASV) {
+ serverIp.ipv4 = ip;
+ clientIp.ipv4 = key->ipKey.nwDst;
+ }
} else {
if (ftpType == FTP_EXTEND_TYPE_ACTIVE) {
/** In ftp active mode, we need to parse string like below:
@@ -239,7 +242,7 @@ OvsCtHandleFtp(PNET_BUFFER_LIST curNbl,
char *nextHdr = NULL;
int index = 0;
int isIpv6AddressFamily = 0;
- char ftpStr[1024] = {0x00};
+ char ftpStr[512] = {0x00};
RtlCopyMemory(ftpStr, req, strlen(req));
for (curHdr = ftpStr; *curHdr != '|'; curHdr++);