net:add customizable default max & min port
add customizable default max & min port Signed-off-by: wangchen <wangchen41@xiaomi.com>
This commit is contained in:
parent
7f1e80f0de
commit
b446a002db
4 changed files with 26 additions and 23 deletions
12
net/Kconfig
12
net/Kconfig
|
|
@ -57,6 +57,18 @@ config NET_PROMISCUOUS
|
|||
Force the Ethernet driver to operate in promiscuous mode (if supported
|
||||
by the Ethernet driver).
|
||||
|
||||
config NET_DEFAULT_MIN_PORT
|
||||
int "Net Default Min Port"
|
||||
default 4096
|
||||
---help---
|
||||
Default Network min port
|
||||
|
||||
config NET_DEFAULT_MAX_PORT
|
||||
int "Net Default Max Port"
|
||||
default 32000
|
||||
---help---
|
||||
Default Network max port
|
||||
|
||||
menu "Driver buffer configuration"
|
||||
|
||||
config NET_ETH_PKTSIZE
|
||||
|
|
|
|||
|
|
@ -40,15 +40,6 @@
|
|||
|
||||
#if defined(CONFIG_NET_NAT) && defined(CONFIG_NET_IPv4)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* TODO: Why we limit to 32000 in net stack? */
|
||||
|
||||
#define NAT_PORT_REASSIGN_MAX 32000
|
||||
#define NAT_PORT_REASSIGN_MIN 4096
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
|
@ -119,9 +110,9 @@ static uint16_t ipv4_nat_select_port_without_stack(
|
|||
uint16_t hport = NTOHS(portno);
|
||||
while (ipv4_nat_port_inuse(protocol, ip, portno))
|
||||
{
|
||||
if (++hport >= NAT_PORT_REASSIGN_MAX)
|
||||
if (++hport >= CONFIG_NET_DEFAULT_MAX_PORT)
|
||||
{
|
||||
hport = NAT_PORT_REASSIGN_MIN;
|
||||
hport = CONFIG_NET_DEFAULT_MIN_PORT;
|
||||
}
|
||||
|
||||
portno = HTONS(hport);
|
||||
|
|
@ -209,9 +200,9 @@ static uint16_t ipv4_nat_select_port(FAR struct net_driver_s *dev,
|
|||
while (icmp_findconn(dev, id) ||
|
||||
ipv4_nat_port_inuse(IP_PROTO_ICMP, dev->d_ipaddr, id))
|
||||
{
|
||||
if (++hid >= NAT_PORT_REASSIGN_MAX)
|
||||
if (++hid >= CONFIG_NET_DEFAULT_MAX_PORT)
|
||||
{
|
||||
hid = NAT_PORT_REASSIGN_MIN;
|
||||
hid = CONFIG_NET_DEFAULT_MIN_PORT;
|
||||
}
|
||||
|
||||
id = HTONS(hid);
|
||||
|
|
|
|||
|
|
@ -585,11 +585,11 @@ int tcp_selectport(uint8_t domain,
|
|||
{
|
||||
net_getrandom(&g_last_tcp_port, sizeof(uint16_t));
|
||||
|
||||
g_last_tcp_port = g_last_tcp_port % 32000;
|
||||
g_last_tcp_port = g_last_tcp_port % CONFIG_NET_DEFAULT_MAX_PORT;
|
||||
|
||||
if (g_last_tcp_port < 4096)
|
||||
if (g_last_tcp_port < CONFIG_NET_DEFAULT_MIN_PORT)
|
||||
{
|
||||
g_last_tcp_port += 4096;
|
||||
g_last_tcp_port += CONFIG_NET_DEFAULT_MIN_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -608,9 +608,9 @@ int tcp_selectport(uint8_t domain,
|
|||
* is within range.
|
||||
*/
|
||||
|
||||
if (++g_last_tcp_port >= 32000)
|
||||
if (++g_last_tcp_port >= CONFIG_NET_DEFAULT_MAX_PORT)
|
||||
{
|
||||
g_last_tcp_port = 4096;
|
||||
g_last_tcp_port = CONFIG_NET_DEFAULT_MIN_PORT;
|
||||
}
|
||||
|
||||
portno = HTONS(g_last_tcp_port);
|
||||
|
|
|
|||
|
|
@ -540,11 +540,11 @@ uint16_t udp_select_port(uint8_t domain, FAR union ip_binding_u *u)
|
|||
|
||||
if (g_last_udp_port == 0)
|
||||
{
|
||||
g_last_udp_port = clock_systime_ticks() % 32000;
|
||||
g_last_udp_port = clock_systime_ticks() % CONFIG_NET_DEFAULT_MAX_PORT;
|
||||
|
||||
if (g_last_udp_port < 4096)
|
||||
if (g_last_udp_port < CONFIG_NET_DEFAULT_MIN_PORT)
|
||||
{
|
||||
g_last_udp_port += 4096;
|
||||
g_last_udp_port += CONFIG_NET_DEFAULT_MIN_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -562,9 +562,9 @@ uint16_t udp_select_port(uint8_t domain, FAR union ip_binding_u *u)
|
|||
|
||||
/* Make sure that the port number is within range */
|
||||
|
||||
if (g_last_udp_port >= 32000)
|
||||
if (g_last_udp_port >= CONFIG_NET_DEFAULT_MAX_PORT)
|
||||
{
|
||||
g_last_udp_port = 4096;
|
||||
g_last_udp_port = CONFIG_NET_DEFAULT_MIN_PORT;
|
||||
}
|
||||
}
|
||||
while (udp_find_conn(domain, u, HTONS(g_last_udp_port), 0) != NULL
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue