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

chore(prog): Add attach/detach legacy api for xdp #438

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

chentao-kernel
Copy link
Contributor

The AttachXDP api use bpf link to attach xdp prog, AttachXDPLegacy/DetachXDPLegacy apis corresponds to bpf_xdp_attach/bpf_xdp_detach, which can be used on old kernel, so add it.

Copy link
Member

@geyslan geyslan left a comment

Choose a reason for hiding this comment

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

That's great. I placed some requests. As soon as they are addressed I will do the final tests. Tks.

prog.go Outdated
Comment on lines 312 to 315
optsC := &C.struct_bpf_xdp_attach_opts{
sz: C.ulong(unsafe.Sizeof(C.struct_bpf_xdp_attach_opts{})),
old_prog_fd: 0,
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you convert these instantiations to use the structure handlers pattern found in libbpfgo.h, since cgo has problems with structure packaging and field offsets? By instance:

  • cgo_bpf_xdp_attach_opts_new
  • cgo_bpf_xdp_attach_opts_free

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

prog.go Outdated
Comment on lines 332 to 334
optsC := &C.struct_bpf_xdp_attach_opts{
sz: C.ulong(unsafe.Sizeof(C.struct_bpf_xdp_attach_opts{})),
old_prog_fd: C.int(p.FileDescriptor()),
}
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

prog-common.go Outdated
Comment on lines 51 to 63
// XDPFlags
type XDPFlags uint32

const (
XDPFlagsUpdateIfNoExist XDPFlags = C.XDP_FLAGS_UPDATE_IF_NOEXIST
XDPFlagsSkbMode XDPFlags = C.XDP_FLAGS_SKB_MODE
XDPFlagsDrvMode XDPFlags = C.XDP_FLAGS_DRV_MODE
XDPFlagsHwMode XDPFlags = C.XDP_FLAGS_HW_MODE
XDPFlagsReplace XDPFlags = C.XDP_FLAGS_REPLACE
XDPFlagsModes XDPFlags = C.XDP_FLAGS_MODES
XDPFlagsMask XDPFlags = C.XDP_FLAGS_MASK
)

Copy link
Member

Choose a reason for hiding this comment

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

Please move this block to the end of the file following the comment pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@chentao-kernel
Copy link
Contributor Author

That's great. I placed some requests. As soon as they are addressed I will do the final tests. Tks.

Hi, geyslan, thank you for your reply, i will do it later!

The AttachXDP api use bpf link to attach xdp prog, AttachXDPLegacy/DetachXDPLegacy
apis corresponds to bpf_xdp_attach/bpf_xdp_detach, which can be used on
old kernel, so add it.

Signed-off-by: Tao Chen <[email protected]>
@geyslan geyslan added the feature New feature or request label Jun 13, 2024
Copy link
Member

@geyslan geyslan left a comment

Choose a reason for hiding this comment

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

LGTM. @chentao-kernel thanks a lot.

@geyslan geyslan merged commit d2c4549 into aquasecurity:main Jun 13, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants