Skip to content

Commit

Permalink
feat: add Windows drop reasons (#406)
Browse files Browse the repository at this point in the history
# Description

Please provide a brief description of the changes made in this pull
request.

Add drop reasons specifically to windows builds.

## Related Issue

If this pull request is related to any issue, please mention it here.
Additionally, make sure that the issue is assigned to you before
submitting this pull request.

## Checklist

- [ ] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [ ] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [ ] I have correctly attributed the author(s) of the code.
- [ ] I have tested the changes locally.
- [ ] I have followed the project's style guidelines.
- [ ] I have updated the documentation, if necessary.
- [ ] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.
  • Loading branch information
matmerr authored Jun 17, 2024
1 parent 33482d6 commit da27278
Show file tree
Hide file tree
Showing 7 changed files with 2,890 additions and 10 deletions.
12 changes: 2 additions & 10 deletions pkg/utils/flow_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,8 @@ func AddDropReason(f *flow.Flow, meta *RetinaMetadata, dropReason uint32) {
// Retina drop reasons are different from the drop reasons available in flow library.
// We map the ones available in flow library to the ones available in Retina.
// Rest are set to UNKNOWN. The details are added in the metadata.
switch meta.GetDropReason() { //nolint:exhaustive // We are handling all the cases.
case DropReason_IPTABLE_RULE_DROP:
f.DropReasonDesc = flow.DropReason_POLICY_DENIED
case DropReason_IPTABLE_NAT_DROP:
f.DropReasonDesc = flow.DropReason_SNAT_NO_MAP_FOUND
case DropReason_CONNTRACK_ADD_DROP:
f.DropReasonDesc = flow.DropReason_UNKNOWN_CONNECTION_TRACKING_STATE
default:
f.DropReasonDesc = flow.DropReason_DROP_REASON_UNKNOWN
}

f.DropReasonDesc = GetDropReasonDesc(meta.GetDropReason())

f.EventType = &flow.CiliumEventType{
Type: int32(api.MessageTypeDrop),
Expand Down
File renamed without changes.
File renamed without changes.
2,357 changes: 2,357 additions & 0 deletions pkg/utils/metadata_windows.pb.go

Large diffs are not rendered by default.

497 changes: 497 additions & 0 deletions pkg/utils/metadata_windows.proto

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions pkg/utils/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"syscall"
"unsafe"

"github.com/cilium/cilium/api/v1/flow"
"github.com/pkg/errors"
"github.com/vishvananda/netlink"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -113,3 +114,20 @@ func isDefaultRoute(route netlink.Route) bool {

return false
}

func GetDropReasonDesc(dr DropReason) flow.DropReason {
// Set the drop reason.
// Retina drop reasons are different from the drop reasons available in flow library.
// We map the ones available in flow library to the ones available in Retina.
// Rest are set to UNKNOWN. The details are added in the metadata.
switch dr { //nolint:exhaustive // We are handling all the cases.
case DropReason_IPTABLE_RULE_DROP:
return flow.DropReason_POLICY_DENIED
case DropReason_IPTABLE_NAT_DROP:
return flow.DropReason_SNAT_NO_MAP_FOUND
case DropReason_CONNTRACK_ADD_DROP:
return flow.DropReason_UNKNOWN_CONNECTION_TRACKING_STATE
default:
return flow.DropReason_DROP_REASON_UNKNOWN
}
}
16 changes: 16 additions & 0 deletions pkg/utils/utils_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package utils

import (
"github.com/cilium/cilium/api/v1/flow"
)

func GetDropReasonDesc(dr DropReason) flow.DropReason {
switch dr { //nolint:exhaustive // We are handling all the cases.
case DropReason_Drop_INET_FinWait2:
return flow.DropReason_UNKNOWN_CONNECTION_TRACKING_STATE
default:
return flow.DropReason_DROP_REASON_UNKNOWN
}
}

0 comments on commit da27278

Please sign in to comment.