Skip to content

Commit

Permalink
Change net.IP to netip.Addr
Browse files Browse the repository at this point in the history
Signed-off-by: Yun-Tang Hsu <hsuy@vmware.com>
  • Loading branch information
yuntanghsu committed Nov 2, 2023
1 parent 038b556 commit 16b2b53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
24 changes: 15 additions & 9 deletions pkg/agent/controller/networkpolicy/packetin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package networkpolicy
import (
"errors"
"fmt"
"net"
"net/netip"
"time"

Expand Down Expand Up @@ -128,7 +129,8 @@ func (c *Controller) storeDenyConnection(pktIn *ofctrl.PacketIn) error {
denyConn.Mark = getCTMarkValue(matchers)
dstSvcAddress := getCTNwDstValue(matchers)
dstSvcPort := getCTTpDstValue(matchers)
if dstSvcAddress != nil {
klog.InfoS("dstSvcAddress info", "pktIn", pktIn, "dstSvcAddress", dstSvcAddress.String())
if dstSvcAddress.IsValid() {
denyConn.DestinationServiceAddress = dstSvcAddress
}
if dstSvcPort != 0 {
Expand Down Expand Up @@ -245,22 +247,26 @@ func getCTMarkValue(matchers *ofctrl.Matchers) uint32 {
return ctMarkValue
}

func getCTNwDstValue(matchers *ofctrl.Matchers) net.IP {
func getCTNwDstValue(matchers *ofctrl.Matchers) netip.Addr {
nwDst := matchers.GetMatchByName("NXM_NX_CT_NW_DST")
if nwDst != nil {
nwDstValue, ok := nwDst.GetValue().(net.IP)
if ok {
return nwDstValue
if nwDstValue, ok := nwDst.GetValue().(net.IPNet); ok {
aaa, _ := nwDst.GetValue().(net.IP)
klog.InfoS("nwDstValue", "nwDstValue", nwDstValue, "IP", nwDstValue.IP, "IPv4", nwDstValue.IP.To4(), "aaa", aaa, "aaa ipv4", aaa.To4())
if ip, ok := netip.AddrFromSlice(nwDstValue.IP.To4()); ok {
return ip
}
}
}
nwDst = matchers.GetMatchByName("NXM_NX_CT_IPV6_DST")
if nwDst != nil {
nwDstValue, ok := nwDst.GetValue().(net.IP)
if ok {
return nwDstValue
if nwDstValue, ok := nwDst.GetValue().(net.IP); ok {
if ip, ok := netip.AddrFromSlice(nwDstValue); ok {
return ip
}
}
}
return nil
return netip.Addr{}
}

func getCTTpDstValue(matchers *ofctrl.Matchers) uint16 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/flowexporter/exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ func getDenyConnection(isIPv6 bool, protoID uint8) *flowexporter.Connection {
tuple = flowexporter.Tuple{SourceAddress: srcIP, DestinationAddress: dstIP, Protocol: protoID, SourcePort: 65280, DestinationPort: 255}
}
conn := &flowexporter.Connection{
FlowKey: tuple,
FlowKey: tuple,
SourcePodName: "pod",
}
return conn
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/flowaggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func checkIntraNodeFlows(t *testing.T, data *TestData, podAIPs, podBIPs *PodIPs,
}

func testHelper(t *testing.T, data *TestData, isIPv6 bool) {
_, svcB, svcC, svcD, svcE, err := createPerftestServices(data, false)
_, svcB, svcC, svcD, svcE, err := createPerftestServices(data, isIPv6)
if err != nil {
t.Fatalf("Error when creating perftest Services: %v", err)
}
Expand Down Expand Up @@ -1489,7 +1489,7 @@ func getRecordsFromOutput(t *testing.T, output string, startTime time.Time) []st
result = append(result, record)
}
}
return recordSlices
return result
}

func deployK8sNetworkPolicies(t *testing.T, data *TestData, srcPod, dstPod string) (np1 *networkingv1.NetworkPolicy, np2 *networkingv1.NetworkPolicy) {
Expand Down

0 comments on commit 16b2b53

Please sign in to comment.