MeterLogger
lwip_napt.h
Go to the documentation of this file.
1 #ifndef __LWIP_NAPT_H__
2 #define __LWIP_NAPT_H__
3 
4 #include "lwip/opt.h"
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 #if IP_FORWARD
11 #if IP_NAPT
12 
13 /* Default size of the tables used for NAPT */
14 #define IP_NAPT_MAX 512
15 #define IP_PORTMAP_MAX 32
16 
17 /* Timeouts in sec for the various protocol types */
18 #define IP_NAPT_TIMEOUT_MS_TCP (30*60*1000)
19 #define IP_NAPT_TIMEOUT_MS_TCP_DISCON (20*1000)
20 #define IP_NAPT_TIMEOUT_MS_UDP (2*1000)
21 #define IP_NAPT_TIMEOUT_MS_ICMP (2*1000)
22 
23 #define IP_NAPT_PORT_RANGE_START 49152
24 #define IP_NAPT_PORT_RANGE_END 61439
25 
26 struct napt_table {
27  u32_t last;
28  u32_t src;
29  u32_t dest;
30  u16_t sport;
31  u16_t dport;
32  u16_t mport;
33  u8_t proto;
34  u8_t fin1 : 1;
35  u8_t fin2 : 1;
36  u8_t finack1 : 1;
37  u8_t finack2 : 1;
38  u8_t synack : 1;
39  u8_t rst : 1;
40  u16_t next, prev;
41 };
42 
43 struct portmap_table {
44  u32_t maddr;
45  u32_t daddr;
46  u16_t mport;
47  u16_t dport;
48  u8_t proto;
49  u8 valid;
50 };
51 
52 extern struct portmap_table *ip_portmap_table;
53 
54 /**
55  * Allocates and initializes the NAPT tables.
56  *
57  * @param max_nat max number of enties in the NAPT table (use IP_NAPT_MAX if in doubt)
58  * @param max_portmap max number of enties in the NAPT table (use IP_PORTMAP_MAX if in doubt)
59  */
61 ip_napt_init(uint16_t max_nat, uint8_t max_portmap);
62 
63 
64 /**
65  * Enable/Disable NAPT for a specified interface.
66  *
67  * @param addr ip address of the interface
68  * @param enable non-zero to enable NAPT, or 0 to disable.
69  */
71 ip_napt_enable(u32_t addr, int enable);
72 
73 
74 /**
75  * Enable/Disable NAPT for a specified interface.
76  *
77  * @param netif number of the interface
78  * @param enable non-zero to enable NAPT, or 0 to disable.
79  */
81 ip_napt_enable_no(u8_t number, int enable);
82 
83 
84 /**
85  * Register port mapping on the external interface to internal interface.
86  * When the same port mapping is registered again, the old mapping is overwritten.
87  * In this implementation, only 1 unique port mapping can be defined for each target address/port.
88  *
89  * @param proto target protocol
90  * @param maddr ip address of the external interface
91  * @param mport mapped port on the external interface, in host byte order.
92  * @param daddr destination ip address
93  * @param dport destination port, in host byte order.
94  */
96 ip_portmap_add(u8_t proto, u32_t maddr, u16_t mport, u32_t daddr, u16_t dport);
97 
98 
99 /**
100  * Unregister port mapping on the external interface to internal interface.
101  *
102  * @param proto target protocol
103  * @param maddr ip address of the external interface
104  */
106 ip_portmap_remove(u8_t proto, u16_t mport);
107 
108 #endif /* IP_NAPT */
109 #endif /* IP_FORWARD */
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* __LWIP_NAPT_H__ */
#define ICACHE_FLASH_ATTR
Definition: c_types.h:99
unsigned long u32_t
Definition: cc.h:56
unsigned char u8
Definition: c_types.h:46
unsigned char u8_t
Definition: cc.h:52
unsigned short u16_t
Definition: cc.h:54