common: Adding common library for sample vnf
[samplevnf.git] / common / VIL / alg / lib_ftp_alg.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 #ifndef __INCLUDE_LIB_FTP_ALG_H__
17 #define __INCLUDE_LIB_FTP_ALG_H__
18 #include "rte_ether.h"
19 #include "rte_ct_tcp.h"
20 /*CT & CGNAT integration to be resolved for this definitions*/
21 #define META_DATA_OFFSET 128
22 #define ETHERNET_START (META_DATA_OFFSET + RTE_PKTMBUF_HEADROOM)
23 #define ETH_HDR_SIZE 14
24 #define IP_START (ETHERNET_START + ETH_HDR_SIZE)
25 #define PROTOCOL_START (IP_START + 9)
26 #define TCP_START (IP_START + IP_V4_HEADER_SIZE)
27 #define TCP_MIN_HDR_SIZE 20
28
29 #define RTE_TCP_PROTO_ID 6
30 #define RTE_SP_DEFAULT_TTL 64
31
32 #define RTE_SYNPROXY_MAX_SPOOFED_PKTS 64
33
34 #define RTE_TCP_SYN 0x02
35 #define RTE_TCP_ACK 0x10
36 #define RTE_TCP_SYN_ACK (RTE_TCP_SYN | RTE_TCP_ACK)
37 #define IP_VERSION_4 4
38 #define IP_VERSION_6 6
39 #define IPv4_HEADER_SIZE 20
40 #define IPv6_HEADER_SIZE 40
41
42 //#define IPV4 4
43 //#define IPV6 6
44 enum ftp_alg_bypass {
45         NO_BYPASS,
46         BYPASS
47 };
48
49 enum ftp_alg_mode {
50         FTP_ALG_PORT,
51         FTP_ALG_PASV
52 };
53 enum ftp_alg_direction {
54         SERVER_IN_PRIVATE,
55         SERVER_IN_PUBLIC
56 };
57 enum phy_port {
58         PRIVATE_PORT,
59         PUBLIC_PORT
60 };
61
62 struct ftp_alg_key {
63         uint32_t ip_address;
64         uint16_t l4port;
65         uint8_t filler1;
66         uint8_t filler2;
67 };
68 struct ftp_alg_table_entry {
69         uint32_t ip_address;
70         uint16_t l4port;
71         uint8_t ftp_alg_mode;
72         uint8_t ftp_alg_direction;
73         uint32_t session_id;    /*to be checked */
74         uint8_t alg_bypass_flag;
75         uint8_t dummy;
76         uint8_t dummy1;
77         //uint32_t napt_entry;/* to be checked*/
78 } __rte_cache_aligned;
79
80 #define FTP_SERVER_PORT                         21
81 #define FTP_PORT_STRING                         "PORT"
82 #define FTP_PORT_PARAMETER_STRING               "PORT %hu,%hu,%hu,%hu,%hu,%hu\r\n"
83 #define FTP_PORT_PARAMETER_COUNT                6
84 #define FTP_PORT_RESPONSE_STRING                "200 PORT command successful.\r\n"
85 #define FTP_PORT_STRING_END_MARKER              '\n'
86 #define FTP_MAXIMUM_PORT_STRING_LENGTH          60
87 #define FTP_PASV_STRING                         "PASV"
88 #define FTP_PASV_PARAMETER_STRING               "%d Entering Passive Mode (%hu,%hu,%hu,%hu,%hu,%hu)\r\n"
89 #define FTP_PASV_PARAMETER_COUNT                7
90 #define FTP_PASV_STRING_END_MARKER              '\n'    /* not ')' */
91 #define FTP_PASV_RETURN_CODE                    227
92
93 void ftp_alg_dpi(
94         struct pipeline_cgnapt *p_nat,
95         struct pipeline_cgnapt_entry_key *nat_entry_key,
96         struct rte_mbuf *pkt,
97         struct rte_ct_cnxn_tracker *cgnat_cnxn_tracker,
98         int32_t ct_position,
99         uint8_t direction);
100 void lib_ftp_alg_init(void);
101 extern int8_t rte_ct_ipversion(void *i_hdr);
102 #endif