• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubeovn / kube-ovn / 21576803349

02 Feb 2026 03:56AM UTC coverage: 22.931% (-0.002%) from 22.933%
21576803349

push

github

web-flow
fix localnet port should not be static "patch-localnet." (#6244)

* fix localnet port

Signed-off-by: clyi <clyi@alauda.io>

0 of 23 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

12330 of 53770 relevant lines covered (22.93%)

0.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/daemon/flow_rules_linux.go
1
package daemon
2

3
import (
4
        "fmt"
5
        "strconv"
6
        "strings"
7

8
        "k8s.io/klog/v2"
9

10
        kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
11
        "github.com/kubeovn/kube-ovn/pkg/ovs"
12
        "github.com/kubeovn/kube-ovn/pkg/util"
13
)
14

15
const flowKindUnderlayService = "usvc"
16

NEW
17
func (c *Controller) AddOrUpdateUnderlaySubnetSvcLocalFlowCache(serviceIP string, port uint16, protocol, dstMac, underlayNic, bridgeName, subnetName string) error {
×
NEW
18
        inPort, err := c.getPortID(underlayNic)
×
19
        if err != nil {
×
20
                return err
×
21
        }
×
22

NEW
23
        patchPortName := fmt.Sprintf("patch-localnet.%s-to-br-int", subnetName)
×
NEW
24
        outPort, err := c.getPortID(patchPortName)
×
25
        if err != nil {
×
NEW
26
                klog.V(5).Infof("patch-localnet port %s not found on bridge %s, skipping underlay service flow for %s:%d (subnet %s may not have pods on this node yet)", patchPortName, bridgeName, serviceIP, port, subnetName)
×
27
                return nil
×
28
        }
×
29

30
        isIPv6 := util.CheckProtocol(serviceIP) == kubeovnv1.ProtocolIPv6
×
31
        protoStr := ""
×
32
        switch strings.ToUpper(protocol) {
×
33
        case "TCP":
×
34
                protoStr = "tcp"
×
35
                if isIPv6 {
×
36
                        protoStr = "tcp6"
×
37
                }
×
38
        case "UDP":
×
39
                protoStr = "udp"
×
40
                if isIPv6 {
×
41
                        protoStr = "udp6"
×
42
                }
×
43
        default:
×
44
                return fmt.Errorf("unsupported protocol %s", protocol)
×
45
        }
46

47
        cookie := fmt.Sprintf("0x%x", util.UnderlaySvcLocalOpenFlowCookieV4)
×
48
        nwDst := "nw_dst"
×
49
        if isIPv6 {
×
50
                cookie = fmt.Sprintf("0x%x", util.UnderlaySvcLocalOpenFlowCookieV6)
×
51
                nwDst = "ipv6_dst"
×
52
        }
×
53

54
        flow := fmt.Sprintf("cookie=%s,priority=%d,in_port=%d,%s,%s=%s,tp_dst=%d "+
×
55
                "actions=mod_dl_dst:%s,output:%d",
×
56
                cookie, util.UnderlaySvcLocalOpenFlowPriority, inPort, protoStr, nwDst, serviceIP, port, dstMac, outPort)
×
57

×
58
        key := buildFlowKey(flowKindUnderlayService, serviceIP, port, protocol, "")
×
59
        c.setFlowCache(c.flowCache, bridgeName, key, []string{flow})
×
60

×
61
        klog.V(5).Infof("updated underlay flow cache for service %s", key)
×
62
        c.requestFlowSync()
×
63
        return nil
×
64
}
65

66
func (c *Controller) deleteUnderlaySubnetSvcLocalFlowCache(bridgeName, serviceIP string, port uint16, protocol string) {
×
67
        key := buildFlowKey(flowKindUnderlayService, serviceIP, port, protocol, "")
×
68

×
69
        c.deleteFlowCache(c.flowCache, bridgeName, key)
×
70

×
71
        klog.V(5).Infof("deleted underlay flow cache for service %s", key)
×
72
        c.requestFlowSync()
×
73
}
×
74

75
func buildFlowKey(kind, ip string, port uint16, protocol, extra string) string {
×
76
        if extra == "" {
×
77
                return fmt.Sprintf("%s-%s-%s-%d", kind, ip, protocol, port)
×
78
        }
×
79
        return fmt.Sprintf("%s-%s-%s-%d-%s", kind, ip, protocol, port, extra)
×
80
}
81

NEW
82
func (c *Controller) getPortID(portName string) (int, error) {
×
NEW
83
        ofportStr, err := ovs.Get("Interface", portName, "ofport", "", true)
×
NEW
84
        if err != nil {
×
NEW
85
                return 0, fmt.Errorf("failed to get ofport for interface %s: %w", portName, err)
×
UNCOV
86
        }
×
87

NEW
88
        portID, err := strconv.Atoi(strings.TrimSpace(ofportStr))
×
89
        if err != nil {
×
NEW
90
                return 0, fmt.Errorf("failed to parse ofport %q: %w", ofportStr, err)
×
91
        }
×
92

NEW
93
        return portID, nil
×
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc