diff mbox series

[ovs-dev,v3,2/3] conntrack: select correct sport range for well-known origin sport

Message ID 1631115206-6892-2-git-send-email-wenxu@ucloud.cn
State Superseded
Headers show
Series [ovs-dev,v3,1/3] conntrack: restore the origin sport for each round with new address | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

wenxu Sept. 8, 2021, 3:33 p.m. UTC
From: wenxu <wenxu@ucloud.cn>

Like the kernel datapath. The sport nat range for well-konwn origin
sport should limit in the well-known ports.

Signed-off-by: wenxu <wenxu@ucloud.cn>
---
 lib/conntrack.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/conntrack.c b/lib/conntrack.c
index 00906f8..f95532c 100644
--- a/lib/conntrack.c
+++ b/lib/conntrack.c
@@ -2261,8 +2261,16 @@  set_sport_range(struct nat_action_info_t *ni, const struct conn_key *k,
     if (((ni->nat_action & NAT_ACTION_SNAT_ALL) == NAT_ACTION_SRC) ||
         ((ni->nat_action & NAT_ACTION_DST))) {
         *curr = ntohs(k->src.port);
-        *min = MIN_NAT_EPHEMERAL_PORT;
-        *max = MAX_NAT_EPHEMERAL_PORT;
+        if (*curr < 512) {
+            *min = 1;
+            *max = 511;
+        } else if (*curr < 1024) {
+            *min = 600;
+            *max = 1023;
+        } else {
+            *min = MIN_NAT_EPHEMERAL_PORT;
+            *max = MAX_NAT_EPHEMERAL_PORT;
+        }
     } else {
         *min = ni->min_port;
         *max = ni->max_port;