summaryrefslogtreecommitdiffstats
path: root/target/linux/realtek/files/include/net/rtl/rtl865x_nat.h
blob: 4cdbc60e998b0ccdc588698bee9aebcbe0992fa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef	RTL865X_NAT_H
#define	RTL865X_NAT_H

#define FLAG_QOS_ENABLE 1

/* NAT timeout value */
#define TCP_TIMEOUT					120	 	/* 120 secs */
#define UDP_TIMEOUT					90		/* 90 secs */
#define TCP_OVERRIDE_ELASPED_THRESHOLD	60	 	/* 60 secs */
#define UDP_OVERRIDE_ELASPED_THRESHOLD	30		/* 30 secs */

#define TCP_CLOSED_FLOW				8

#define RTL865X_PROTOCOL_UDP		0
#define RTL865X_PROTOCOL_TCP		1

#define NAT_INBOUND					0x00000001
#define NAT_OUTBOUND				0x00000002
#define NAT_PRI_PROCESSED			0x00000004
#define NAT_PRI_HALF_PROCESSED		0x00000008

#define NAT_PRE_RESERVED		0x00000100
#define RESERVE_EXPIRE_TIME	3	/*uinit:seconds*/

#define NAT_INUSE(_n_)				( ((_n_)->flags&(NAT_INBOUND|NAT_OUTBOUND)) )
#define SET_NAT_FLAGS(_n_, _v_)		((_n_)->flags |= (_v_))
#define CLR_NAT_FLAGS(_n_, _v_)		((_n_)->flags &= (~(_v_)))
#define	NAT_INVALID(_n_)			( ((_n_)->flags=0) )

#define MAX_EXTPORT_TRY_CNT 8

#define	RTL_NAPT_ACCELERATION_FAIL			-1
#define	RTL_NAPT_FULL_ACCELERATION			0
#define	RTL_NAPT_OUTBOUND_ACCELERATION 	1
#define 	RTL_NAPT_INBOUND_ACCELERATION		2

#define CONFIG_RTL_INBOUND_COLLISION_AVOIDANCE
#define CONFIG_RTL_HALF_NAPT_ACCELERATION

typedef struct _rtl865x_napt_entry
{
	uint32 protocol;	//RTL865X_PROTOCOL_UDP or RTL865X_PROTOCOL_TCP
	ipaddr_t intIp;
	uint32 intPort;
	ipaddr_t extIp;
	uint32 extPort;
	ipaddr_t remIp;
	uint32 remPort;
}rtl865x_napt_entry;

typedef struct _rtl865x_priority
{
	int32 uplinkPrio;
	int32 downlinkPrio;
}rtl865x_priority;

typedef struct _rtl865x_qos_mark
{
	int32 uplinkMark;
	int32 downlinkMark;
}rtl865x_qos_mark;

int32 rtl865x_nat_init(void);
int32 rtl865x_nat_reinit(void);
/*
@func enum RTL_RESULT | rtl865x_addNaptConnection | Add a NAPT Flow
@parm enum RTL_NP_PROTOCOL | protocol | The protocol to add
@parm ipaddr_t | intIp | Internal IP address
@parm uint32 | intPort | Internal Port
@parm ipaddr_t | extIp | External IP address
@parm uint32 | extPort | External Port
@parm ipaddr_t | remIp | Remote IP address
@parm uint32 | remPort | Remote Port
@parm enum RTL_NP_FLAGS | flags | reserved for future used
@rvalue RTL_SUCCESS | Add success (can be ASIC-accelerated)
@rvalue RTL_SUCCESS | Add success (cannot be ASIC-accelerated)
@rvalue RTL_ERROR_PARAMETER | Error parameter is given
@rvalue RTL_EXIST | Add an existed flow
@rvalue RTL_FAILED | General failure
@comm 
	Add a NAPT Flow Entry to L4 TCP/UDP NAPT Table(1024-Entry)
@devnote
	Insert into ip_nat_setup_info() function in file net/ipv4/netfilter/ip_nat_core.c
*/
int32 rtl865x_addNaptConnection(rtl865x_napt_entry *naptEntry, rtl865x_priority *prio);
/*
@func enum RTL_RESULT | rtl865x_delNaptConnection | Delete a NAPT Flow
@parm enum RTL_NP_PROTOCOL | protocol | The protocol to delete
@parm ipaddr_t | intIp | Internal IP address
@parm uint32 | intPort | Internal Port
@parm ipaddr_t | extIp | External IP address
@parm uint32 | extPort | External Port
@parm ipaddr_t | remIp | Remote IP address
@parm uint32 | remPort | Remote Port
@rvalue RTL_SUCCESS | Delete success
@rvalue RTL_NONEXIST | Delete a non-existed flow
@rvalue RTL_FAILED | General failure
@comm 
	Delete a NAPT Flow Entry of L4 TCP/UDP NAPT Table(1024-Entry)
@devnote
	Insert into ip_nat_cleanup_conntrack() function in file net/ipv4/netfilter/ip_nat_core.c
*/
int32 rtl865x_delNaptConnection(rtl865x_napt_entry *naptEntry);

int32 rtl865x_naptSync(rtl865x_napt_entry *naptEntry, uint32 refresh);

#if defined (CONFIG_RTL_INBOUND_COLLISION_AVOIDANCE)
int rtl865x_optimizeExtPort(unsigned short origDelta, unsigned int rangeSize, unsigned short *newDelta);

int rtl865x_getAsicNaptHashScore(rtl865x_napt_entry *naptEntry, 
					                        uint32 *naptHashScore);

int32 rtl865x_preReserveConn(rtl865x_napt_entry *naptEntry);

#endif
#if defined(CONFIG_RTL_HARDWARE_NAT)
int32 rtl_nat_expire_interval_update(int proto, int32 interval);
int32 rtl865x_nat_reinit(void);
#endif

#endif