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

Add packetcatpure feature #6756

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hangyan
Copy link
Member

@hangyan hangyan commented Oct 18, 2024

This is a refactor of #5821 (ovs based) which use gopacket(https://github.com/google/gopacket) https://github.com/packetcap/go-pcap to perform the capture.

Notes:

  1. this go library use custom parser for the BPF filter and it only support a subset filter. For example, tcpflags is not working. we may need to remove this from the spec too.

@hangyan hangyan force-pushed the topic/yhang/packet-capture-go branch from 524ea56 to 9130c40 Compare October 18, 2024 13:48
@hangyan
Copy link
Member Author

hangyan commented Oct 18, 2024

cc @tnqn @luolanzone

Can you help review this again? I may need to add more unittest and fix the golangci( libpcap issue) but please provide suggestions on the current code.

@@ -29,6 +29,9 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target=/root/.cache/go-build/ \
make antctl-linux && mv bin/antctl-linux bin/antctl


RUN apt-get update && apt-get install -y libpcap-dev && apt-get autoremove -y && rm -rf /var/cache/apt/* /var/lib/apt/lists/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the Dockerfile for the antrea/base-ubuntu: https://github.com/antrea-io/antrea/blob/main/build/images/base/Dockerfile#L53, maybe required in ubi Dockerfile as well: https://github.com/antrea-io/antrea/blob/main/build/images/base/Dockerfile.ubi. cc @tnqn @antoninbas to confirm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i'm not totally sure about introduce this libpcap and cgo thing because it required lots of changes in the build files. will move this part once it's confirmed.

docs/packetcapture-guide.md Outdated Show resolved Hide resolved
docs/packetcapture-guide.md Outdated Show resolved Hide resolved
docs/packetcapture-guide.md Outdated Show resolved Hide resolved
docs/packetcapture-guide.md Outdated Show resolved Hide resolved
@hangyan hangyan force-pushed the topic/yhang/packet-capture-go branch from 470a9f0 to 2c71de0 Compare October 21, 2024 03:57
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't finished reviewing all changes. There are several compilation error in the controller's implementation, I suppose it's not finished yet.

Comment on lines 324 to 352
if matchPacket.SourceIP != nil {
exp += "src " + matchPacket.SourceIP.String()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression wouldn't be correct when SourceIP is nil

Copy link
Member Author

@hangyan hangyan Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added check to make sure it's not nil. the current CRD has a oneOf(Pod, IP), so a valid ip address should be present.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means it doesn't support specifying destination only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can. i'm not sure how to express these fields requirements in crd schema. the following wont work

          properties:
            spec:
              type: object
              required:
                - captureConfig # removed source/destination 
              anyOf:
                - properties:
                    source:
                      required: [pod]
                - properties:
                    destination:
                      required: [pod]

A CR with no source and destination is valid upon this.

@luolanzone luolanzone added the action/release-note Indicates a PR that should be included in release notes. label Oct 21, 2024
@luolanzone luolanzone added this to the Antrea v2.2 release milestone Oct 21, 2024
@hangyan hangyan force-pushed the topic/yhang/packet-capture-go branch from 2c71de0 to bb18af7 Compare October 21, 2024 06:13
@hangyan
Copy link
Member Author

hangyan commented Oct 21, 2024

Haven't finished reviewing all changes. There are several compilation error in the controller's implementation, I suppose it's not finished yet.

caused by directly apply review suggestions (rename func) from github page. fixed. currently there are some issues on the arm platform image build. working on that.

docs/packetcapture-guide.md Outdated Show resolved Hide resolved
Comment on lines 400 to 388
}
if err := c.setPacketsFilePathStatus(pc.Name); err != nil {
return err
}
}
err = c.updatePacketCaptureStatus(pc, crdv1alpha1.PacketCaptureRunning, "", captureState.numCapturedPackets)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like setPacketsFilePathStatus will overwrite all status setting by updatePacketCaptureStatus if it's called later after updatePacketCaptureStatus?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setPacketsFilePathStatus will only be called before the final status sync. As it's status is still Running, not succeeded yet.


// initPacketCapture mark the PacketCapture as running
func (c *Controller) initPacketCapture(pc *crdv1alpha1.PacketCapture) error {
err := c.updatePacketCaptureStatus(pc, crdv1alpha1.PacketCaptureRunning, "", 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mark it as Running directly?
I feel this should be a validatePacketCapture() instead of initPacketCapture() to set it as running directly.
validatePacketCapture can set the status as failure and update the validation failure in the reason.
The failure during package capture should be updated during the PacketCaptureRunning status.
@tnqn any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion makes sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the validation has been handled by the CRD schema. Maybe the getPodIP part can be checked first?

@hangyan hangyan force-pushed the topic/yhang/packet-capture-go branch 5 times, most recently from 1c9e3f6 to d14a1a3 Compare October 23, 2024 02:15
Signed-off-by: Hang Yan <[email protected]>
@hangyan hangyan force-pushed the topic/yhang/packet-capture-go branch from d14a1a3 to 2768afa Compare October 23, 2024 10:24
Signed-off-by: Hang Yan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants