Skip to content

Commit 9ac4ac6

Browse files
SkalaNetworksoilbeater
authored andcommitted
fix(vpcnatgw): cannot DNAT same EIP and same external port on two different protocols (#6201)
You should be able to DNAT 1.1.1.1:22 TCP and 1.1.1.1:22 UDP on the same EIP, but the check doesn't check if it is two different protocols. On Windows, RDP asks to open both the UDP and TCP protocols on the same port. It cannot be done behind an EIP attached to a VPC NAT gateway because of this bug. Signed-off-by: SkalaNetworks <contact@skala.network>
1 parent 2f7908a commit 9ac4ac6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/controller/vpc_nat_gw_nat.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (c *Controller) handleAddIptablesDnatRule(key string) error {
419419
klog.Errorf("failed to get eip, %v", err)
420420
return err
421421
}
422-
if dup, err := c.isDnatDuplicated(eip.Spec.NatGwDp, eipName, dnat.Name, dnat.Spec.ExternalPort); dup || err != nil {
422+
if dup, err := c.isDnatDuplicated(eip.Spec.NatGwDp, dnat.Spec.EIP, dnat.Name, dnat.Spec.ExternalPort, dnat.Spec.Protocol); dup || err != nil {
423423
klog.Error(err)
424424
return err
425425
}
@@ -494,7 +494,7 @@ func (c *Controller) handleUpdateIptablesDnatRule(key string) error {
494494
klog.Errorf("failed to get eip, %v", err)
495495
return err
496496
}
497-
if dup, err := c.isDnatDuplicated(cachedDnat.Status.NatGwDp, eipName, cachedDnat.Name, cachedDnat.Spec.ExternalPort); dup || err != nil {
497+
if dup, err := c.isDnatDuplicated(cachedDnat.Status.NatGwDp, cachedDnat.Spec.EIP, cachedDnat.Name, cachedDnat.Spec.ExternalPort, cachedDnat.Spec.Protocol); dup || err != nil {
498498
klog.Errorf("failed to update dnat, %v", err)
499499
return err
500500
}
@@ -1536,8 +1536,8 @@ func (c *Controller) snatChangeEip(snat *kubeovnv1.IptablesSnatRule, eip *kubeov
15361536
return false
15371537
}
15381538

1539-
func (c *Controller) isDnatDuplicated(gwName, eipName, dnatName, externalPort string) (bool, error) {
1540-
// check if eip:external port already used
1539+
func (c *Controller) isDnatDuplicated(gwName, eipName, dnatName, externalPort, protocol string) (bool, error) {
1540+
// Check if the tuple "eip:external port:protocol" is already used by another DNAT rule
15411541
dnats, err := c.iptablesDnatRulesLister.List(labels.SelectorFromSet(labels.Set{
15421542
util.VpcNatGatewayNameLabel: gwName,
15431543
util.VpcDnatEPortLabel: externalPort,
@@ -1549,8 +1549,8 @@ func (c *Controller) isDnatDuplicated(gwName, eipName, dnatName, externalPort st
15491549
}
15501550
if len(dnats) != 0 {
15511551
for _, d := range dnats {
1552-
if d.Name != dnatName && d.Spec.EIP == eipName {
1553-
err = fmt.Errorf("failed to create dnat %s, duplicate, same eip %s, same external port '%s' is using by dnat %s", dnatName, eipName, externalPort, d.Name)
1552+
if d.Name != dnatName && d.Spec.EIP == eipName && d.Spec.Protocol == protocol {
1553+
err = fmt.Errorf("failed to create dnat %s, duplicate, same eip %s, same external port '%s', same protocol'%s' is using by dnat %s", dnatName, eipName, externalPort, protocol, d.Name)
15541554
return true, err
15551555
}
15561556
}

0 commit comments

Comments
 (0)