Skip to content

Commit b3d96f7

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> (cherry picked from commit bc813ee)
1 parent e22295b commit b3d96f7

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
@@ -421,7 +421,7 @@ func (c *Controller) handleAddIptablesDnatRule(key string) error {
421421
klog.Errorf("failed to get eip, %v", err)
422422
return err
423423
}
424-
if dup, err := c.isDnatDuplicated(eip.Spec.NatGwDp, dnat.Spec.EIP, dnat.Name, dnat.Spec.ExternalPort); dup || err != nil {
424+
if dup, err := c.isDnatDuplicated(eip.Spec.NatGwDp, dnat.Spec.EIP, dnat.Name, dnat.Spec.ExternalPort, dnat.Spec.Protocol); dup || err != nil {
425425
klog.Error(err)
426426
return err
427427
}
@@ -497,7 +497,7 @@ func (c *Controller) handleUpdateIptablesDnatRule(key string) error {
497497
klog.Errorf("failed to get eip, %v", err)
498498
return err
499499
}
500-
if dup, err := c.isDnatDuplicated(cachedDnat.Status.NatGwDp, cachedDnat.Spec.EIP, cachedDnat.Name, cachedDnat.Spec.ExternalPort); dup || err != nil {
500+
if dup, err := c.isDnatDuplicated(cachedDnat.Status.NatGwDp, cachedDnat.Spec.EIP, cachedDnat.Name, cachedDnat.Spec.ExternalPort, cachedDnat.Spec.Protocol); dup || err != nil {
501501
klog.Errorf("failed to update dnat, %v", err)
502502
return err
503503
}
@@ -1531,8 +1531,8 @@ func (c *Controller) snatChangeEip(snat *kubeovnv1.IptablesSnatRule, eip *kubeov
15311531
return false
15321532
}
15331533

1534-
func (c *Controller) isDnatDuplicated(gwName, eipName, dnatName, externalPort string) (bool, error) {
1535-
// check if eip:external port already used
1534+
func (c *Controller) isDnatDuplicated(gwName, eipName, dnatName, externalPort, protocol string) (bool, error) {
1535+
// Check if the tuple "eip:external port:protocol" is already used by another DNAT rule
15361536
dnats, err := c.iptablesDnatRulesLister.List(labels.SelectorFromSet(labels.Set{
15371537
util.VpcNatGatewayNameLabel: gwName,
15381538
util.VpcDnatEPortLabel: externalPort,
@@ -1544,8 +1544,8 @@ func (c *Controller) isDnatDuplicated(gwName, eipName, dnatName, externalPort st
15441544
}
15451545
if len(dnats) != 0 {
15461546
for _, d := range dnats {
1547-
if d.Name != dnatName && d.Spec.EIP == eipName {
1548-
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)
1547+
if d.Name != dnatName && d.Spec.EIP == eipName && d.Spec.Protocol == protocol {
1548+
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)
15491549
return true, err
15501550
}
15511551
}

0 commit comments

Comments
 (0)