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

packetbeat/route: new package for obtaining default route information #31914

Merged
merged 3 commits into from
Jun 23, 2022

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented Jun 13, 2022

What does this PR do?

This adds a package to provide cross-platform default route interface information.

Why is it important?

This is necessary to be able to allow users to specify a host-agnostic default device.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc. This will come when the feature is wired in.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@efd6 efd6 self-assigned this Jun 13, 2022
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Jun 13, 2022
@botelastic
Copy link

botelastic bot commented Jun 13, 2022

This pull request doesn't have a Team:<team> label.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jun 13, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-06-23T04:10:30.399+0000

  • Duration: 50 min 51 sec

Test stats 🧪

Test Results
Failed 0
Passed 1660
Skipped 18
Total 1678

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@efd6 efd6 force-pushed the 31905-route branch 8 times, most recently from 549edd8 to 9a2e165 Compare June 14, 2022 00:53
@efd6 efd6 force-pushed the 31905-route branch 3 times, most recently from 1b2d9a8 to 85bf781 Compare June 14, 2022 02:43
@efd6 efd6 marked this pull request as ready for review June 14, 2022 03:38
@efd6 efd6 requested review from a team as code owners June 14, 2022 03:38
@efd6 efd6 requested review from cmacknz and faec and removed request for a team June 14, 2022 03:38
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

Comment on lines +48 to +55
// Windows interface naming is a dog's breakfast; on some
// builders the transport name obtained from getmac is not
// based on the LUID.
b, err := run("getmac")
if err != nil {
b = []byte(fmt.Sprintf("\nunable to recover getmac information: %v", err))
}
t.Logf("unexpected interface for family %d: got:%s want:%s\n%s", family, iface, wantIface, b)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This in particular is required to allow Windows 2016 to pass because on that builder getmac returns Teredo Tunneling Pseudo-Interface instead of \DEVICE\TCPIP_{<GUID>} for the IPv6 interface.

@cmacknz cmacknz removed request for cmacknz and faec June 14, 2022 13:51
"errors"

"golang.org/x/net/route"
"golang.org/x/sys/unix"
Copy link
Member

Choose a reason for hiding this comment

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

Is this implementation capable of working on other *bsd* variants? I'm thinking of the case where someone might be using it on freebsd. There used to be community maintained packages for freebsd (not sure if anyone is still doing that).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The relevant package is x/net/route which says

The package supports any version of Darwin, any version of DragonFly BSD, FreeBSD 7 and above, NetBSD 6 and above, and OpenBSD 5.6 and above.

I can make this have the same build constraints as that package:

//go:build darwin || dragonfly || freebsd || netbsd || openbsd
// +build darwin dragonfly freebsd netbsd openbsd

// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getbestinterfaceex
// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses
libiphlpapi = windows.NewLazySystemDLL("Iphlpapi.dll")
getBestInterfaceEx = libiphlpapi.NewProc("GetBestInterfaceEx")
Copy link
Member

Choose a reason for hiding this comment

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

These would be good candidates for github.com/elastic/go-windows if you wanted to go through the effort.

Copy link
Contributor Author

@efd6 efd6 Jun 23, 2022

Choose a reason for hiding this comment

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

I'll file an issue on that repo to migrate/copy these to there. It will need a minor modification to generalise it from 0.0.0.0.

@@ -0,0 +1,91 @@
// Licensed to Elasticsearch B.V. under one or more contributor
Copy link
Member

Choose a reason for hiding this comment

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

I think this file should have a build tag to match the OSes on which Default() is implemented.

@efd6 efd6 requested a review from andrewkroh June 23, 2022 05:21
@efd6
Copy link
Contributor Author

efd6 commented Jun 23, 2022

Looking into the move over to go-windows, it looks like one of the syscalls is implemented in x/sys/windows though not as completely (though we don't use the additional members). The other call would benefit from being added to x/sys/windows since the way that the sockaddr types are implemented their doesn't lend itself to external implementations. With that we could move a friendlier API to go-windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.4-candidate backport-skip Skip notification from the automated backport with mergify enhancement Packetbeat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants