Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NetworkPolicy logging for IPv6 connections #1990

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove dependency on pkg/apis/ops/v1alpha1 for packetin handling
And add support for the IPv6-ICMP protocol
  • Loading branch information
antoninbas committed Mar 25, 2021
commit 42397396026750d722f86d4aacddc07d10312389
6 changes: 4 additions & 2 deletions pkg/agent/controller/networkpolicy/packetin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (

"github.com/vmware-tanzu/antrea/pkg/agent/config"
"github.com/vmware-tanzu/antrea/pkg/agent/openflow"
opsv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/ops/v1alpha1"
binding "github.com/vmware-tanzu/antrea/pkg/ovs/openflow"
"github.com/vmware-tanzu/antrea/pkg/util/ip"
)

const (
Expand Down Expand Up @@ -232,7 +232,9 @@ func getPacketInfo(pktIn *ofctrl.PacketIn, ob *logInfo) error {
default:
return errors.New("unsupported packet-in: should be a valid IPv4 or IPv6 packet")
}
ob.protocolStr = opsv1alpha1.ProtocolsToString[int32(prot)]

ob.protocolStr = ip.IPProtocolNumberToString(prot, "UnknownProtocol")

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/ovs/openflow/ofctrl_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,13 @@ func (a *ofLearnAction) MatchLearnedUDPv6DstPort() LearnAction {
return a.MatchTransportDst(ProtocolUDPv6)
}

// MatchLearnedSTCPDstPort specifies that the sctp_dst field in the learned flow
// MatchLearnedSCTPDstPort specifies that the sctp_dst field in the learned flow
// must match the sctp_dst of the packet currently being processed.
func (a *ofLearnAction) MatchLearnedSCTPDstPort() LearnAction {
return a.MatchTransportDst(ProtocolSCTP)
}

// MatchLearnedSTCPv6DstPort specifies that the sctp_dst field in the learned flow
// MatchLearnedSCTPv6DstPort specifies that the sctp_dst field in the learned flow
// must match the sctp_dst of the packet currently being processed.
func (a *ofLearnAction) MatchLearnedSCTPv6DstPort() LearnAction {
return a.MatchTransportDst(ProtocolSCTPv6)
Expand Down
27 changes: 27 additions & 0 deletions pkg/util/ip/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,30 @@ func IPNetToNetIPNet(ipNet *v1beta2.IPNet) *net.IPNet {
maskedIP := ip.Mask(mask)
return &net.IPNet{IP: maskedIP, Mask: mask}
}

const (
ICMPProtocol = 1
TCPProtocol = 6
UDPProtocol = 17
ICMPv6Protocol = 58
SCTPProtocol = 132
)

// IPProtocolNumberToString returns the string name of the IP protocol with number protocolNum. If
// the number does not match a "known" protocol, we return the defaultValue string.
func IPProtocolNumberToString(protocolNum uint8, defaultValue string) string {
switch protocolNum {
case ICMPProtocol:
return "ICMP"
case TCPProtocol:
return "TCP"
case UDPProtocol:
return "UDP"
case ICMPv6Protocol:
return "IPv6-ICMP"
case SCTPProtocol:
return "SCTP"
default:
return defaultValue
}
}
6 changes: 6 additions & 0 deletions pkg/util/ip/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,9 @@ func TestIPNetToNetIPNet(t *testing.T) {
})
}
}

func TestIPProtocolNumberToString(t *testing.T) {
const defaultValue = "UnknownProtocol"
assert.Equal(t, "IPv6-ICMP", IPProtocolNumberToString(ICMPv6Protocol, defaultValue))
assert.Equal(t, defaultValue, IPProtocolNumberToString(44, defaultValue))
}