Skip to content

Commit

Permalink
Add "srcPodIP" field in Traceflow observations
Browse files Browse the repository at this point in the history
Signed-off-by: Kumar Atish <[email protected]>
  • Loading branch information
Atish-iaf committed Apr 25, 2024
1 parent 9a9db6f commit 8449791
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 14 deletions.
2 changes: 2 additions & 0 deletions build/charts/antrea/crds/traceflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ spec:
type: string
egressNode:
type: string
srcPodIP:
type: string
capturedPacket:
properties:
srcIP:
Expand Down
2 changes: 2 additions & 0 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,8 @@ spec:
type: string
egressNode:
type: string
srcPodIP:
type: string
capturedPacket:
properties:
srcIP:
Expand Down
2 changes: 2 additions & 0 deletions build/yamls/antrea-crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3074,6 +3074,8 @@ spec:
type: string
egressNode:
type: string
srcPodIP:
type: string
capturedPacket:
properties:
srcIP:
Expand Down
2 changes: 2 additions & 0 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,8 @@ spec:
type: string
egressNode:
type: string
srcPodIP:
type: string
capturedPacket:
properties:
srcIP:
Expand Down
2 changes: 2 additions & 0 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,8 @@ spec:
type: string
egressNode:
type: string
srcPodIP:
type: string
capturedPacket:
properties:
srcIP:
Expand Down
2 changes: 2 additions & 0 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,8 @@ spec:
type: string
egressNode:
type: string
srcPodIP:
type: string
capturedPacket:
properties:
srcIP:
Expand Down
2 changes: 2 additions & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,8 @@ spec:
type: string
egressNode:
type: string
srcPodIP:
type: string
capturedPacket:
properties:
srcIP:
Expand Down
5 changes: 5 additions & 0 deletions pkg/agent/controller/traceflow/packetin.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func (c *Controller) parsePacketIn(pktIn *ofctrl.PacketIn) (*crdv1beta1.Traceflo
ob := new(crdv1beta1.Observation)
ob.Component = crdv1beta1.ComponentSpoofGuard
ob.Action = crdv1beta1.ActionForwarded
if isValidCtNw(ctNwSrc) {
ob.SrcPodIP = ctNwSrc
} else {
ob.SrcPodIP = ipSrc
}
obs = append(obs, *ob)
} else {
ob := new(crdv1beta1.Observation)
Expand Down
23 changes: 17 additions & 6 deletions pkg/agent/controller/traceflow/packetin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ func getTestPacketBytes(dstIP string) []byte {
Protocol: uint8(8),
DSCP: 1,
Length: 20,
NWSrc: net.IP(pod1IPv4),
NWDst: net.IP(dstIP),
NWSrc: net.ParseIP(pod1IPv4),
NWDst: net.ParseIP(dstIP),
}
ethernetPkt := protocol.NewEthernet()
ethernetPkt.HWSrc = pod1MAC
Expand Down Expand Up @@ -238,6 +238,13 @@ func TestParsePacketIn(t *testing.T) {
Data: 1,
},
}
matchCTSrc := &openflow15.MatchField{
Class: openflow15.OXM_CLASS_NXM_1,
Field: openflow15.NXM_NX_CT_NW_SRC,
Value: &openflow15.Ipv4SrcField{
Ipv4Src: net.ParseIP(pod1IPv4),
},
}
matchTunDst := openflow15.NewTunnelIpv4DstField(net.ParseIP(egressIP), nil)

conjData := make([]byte, 8)
Expand Down Expand Up @@ -298,7 +305,7 @@ func TestParsePacketIn(t *testing.T) {
PacketIn: &openflow15.PacketIn{
TableId: openflow.OutputTable.GetID(),
Match: openflow15.Match{
Fields: []openflow15.MatchField{*matchOutPort, *matchPktMark},
Fields: []openflow15.MatchField{*matchOutPort, *matchPktMark, *matchCTSrc},
},
Data: util.NewBuffer(pktBytesPodToIP),
},
Expand Down Expand Up @@ -329,6 +336,7 @@ func TestParsePacketIn(t *testing.T) {
{
Component: crdv1beta1.ComponentSpoofGuard,
Action: crdv1beta1.ActionForwarded,
SrcPodIP: pod1IPv4,
},
{
Component: crdv1beta1.ComponentEgress,
Expand Down Expand Up @@ -365,7 +373,7 @@ func TestParsePacketIn(t *testing.T) {
PacketIn: &openflow15.PacketIn{
TableId: openflow.OutputTable.GetID(),
Match: openflow15.Match{
Fields: []openflow15.MatchField{*matchTunDst, *matchOutPort},
Fields: []openflow15.MatchField{*matchTunDst, *matchOutPort, *matchCTSrc},
},
Data: util.NewBuffer(pktBytesPodToIP),
},
Expand Down Expand Up @@ -396,6 +404,7 @@ func TestParsePacketIn(t *testing.T) {
{
Component: crdv1beta1.ComponentSpoofGuard,
Action: crdv1beta1.ActionForwarded,
SrcPodIP: pod1IPv4,
},
{
Component: crdv1beta1.ComponentEgress,
Expand Down Expand Up @@ -489,7 +498,7 @@ func TestParsePacketIn(t *testing.T) {
PacketIn: &openflow15.PacketIn{
TableId: openflow.EgressRuleTable.GetID(),
Match: openflow15.Match{
Fields: []openflow15.MatchField{*matchTFEgressConjID},
Fields: []openflow15.MatchField{*matchTFEgressConjID, *matchCTSrc},
},
Data: util.NewBuffer(pktBytesPodToPod),
},
Expand Down Expand Up @@ -531,6 +540,7 @@ func TestParsePacketIn(t *testing.T) {
{
Component: crdv1beta1.ComponentSpoofGuard,
Action: crdv1beta1.ActionForwarded,
SrcPodIP: pod1IPv4,
},
{
Component: crdv1beta1.ComponentNetworkPolicy,
Expand Down Expand Up @@ -618,7 +628,7 @@ func TestParsePacketIn(t *testing.T) {
PacketIn: &openflow15.PacketIn{
TableId: openflow.EgressMetricTable.GetID(),
Match: openflow15.Match{
Fields: []openflow15.MatchField{*matchAPConjID},
Fields: []openflow15.MatchField{*matchAPConjID, *matchCTSrc},
},
Data: util.NewBuffer(pktBytesPodToPod),
},
Expand Down Expand Up @@ -658,6 +668,7 @@ func TestParsePacketIn(t *testing.T) {
{
Component: crdv1beta1.ComponentSpoofGuard,
Action: crdv1beta1.ActionForwarded,
SrcPodIP: pod1IPv4,
},
{
Component: crdv1beta1.ComponentNetworkPolicy,
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/crd/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,8 @@ type Observation struct {
EgressIP string `json:"egressIP,omitempty" yaml:"egressIP,omitempty"`
// EgressNode is the name of the Egress Node.
EgressNode string `json:"egressNode,omitempty" yaml:"egressNode,omitempty"`
// SrcPodIP is the IP of source Pod.
SrcPodIP string `json:"srcPodIP,omitempty" yaml:"srcPodIP,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
7 changes: 7 additions & 0 deletions pkg/apiserver/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8449791

Please sign in to comment.