Skip to content

Multiple fixes for BSD get_gateway code, remove libdnet#772

Merged
phillip-stephens merged 4 commits intozmap:mainfrom
droe:droe/fix-bsd-get_iface_hw_addr
Feb 5, 2024
Merged

Multiple fixes for BSD get_gateway code, remove libdnet#772
phillip-stephens merged 4 commits intozmap:mainfrom
droe:droe/fix-bsd-get_iface_hw_addr

Conversation

@droe
Copy link
Contributor

@droe droe commented Feb 2, 2024

Fixes and modernisations for BSD get_gateway code:

  • Fix get_iface_hw_addr() on macOS, where --source-mac was needed in at least some cases, depending on libdnet, by rewriting it using getifaddrs(3) in lieu of libdnet. getifaddrs(3) is generally portable across all BSD variants and it had already been used for get_iface_ip.
  • Fix get_hw_addr() on FreeBSD, where --gateway-mac was needed, by rewriting it using sysctl(2) in lieu of libdnet.
  • While here, fix two file descriptor leaks and one memory leak in get_default_iface and get_default_gw.
  • Remove the libdnet dependency; it had already been removed for Linux, now it is no longer needed for macOS / BSD either.

Tested on macOS Sonoma as well as FreeBSD 14.0.

(Apologies for extending the scope of an already open PR, but it seemed to make more sense to reason about these changes as a whole, not separately. Happy to split into multiple PRs if you prefer.)

droe added 4 commits February 3, 2024 00:25
Fixes get_iface_hw_addr() on macOS, where --source-mac was needed in at
least some cases.  Tested on macOS 14.2.1 and FreeBSD 14.0, but
getifaddrs(3) is generally portable across all BSD variants.
Fixes get_hw_addr on FreeBSD where the approach used by libdnet,
PF_ROUTE with RTF_LLINFO, no longer works and -G was needed.
@droe droe changed the title Rewrite BSD get_iface_hw_addr using getifaddrs(3) in lieu of libdnet Multiple fixes for BSD get_gateway code, remove libdnet Feb 3, 2024
@phillip-stephens
Copy link
Contributor

This looks good, definitely going to be nice to not have to supply --source-mac on MacOS. Thanks @droe!!! I've checked out the branch and sanity tested it, seems good. Merging.

@phillip-stephens phillip-stephens self-requested a review February 5, 2024 22:21
Copy link
Contributor

@phillip-stephens phillip-stephens left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @droe !

@phillip-stephens phillip-stephens merged commit c76dfdd into zmap:main Feb 5, 2024
droe added a commit to droe/zmap that referenced this pull request Feb 7, 2024
This leftover bit was the result of a collision of two in-flight PRs.
The last use of _SYSTYPE_BSD was removed along with libdnet in zmap#772,
while zmap#771 concurrently added the -D_SYSTYPE_BSD to CMakeLists.txt.

_SYSTYPE_BSD is a rather archaic define.  libdnet might have used it for
compat with now historical systems/compilers, but I do not think it
served any purpose beyond that.  Certainly, modern FreeBSD, NetBSD and
macOS do not reference it.  It seems safe to remove.
zakird pushed a commit that referenced this pull request Feb 7, 2024
This leftover bit was the result of a collision of two in-flight PRs.
The last use of _SYSTYPE_BSD was removed along with libdnet in #772,
while #771 concurrently added the -D_SYSTYPE_BSD to CMakeLists.txt.

_SYSTYPE_BSD is a rather archaic define.  libdnet might have used it for
compat with now historical systems/compilers, but I do not think it
served any purpose beyond that.  Certainly, modern FreeBSD, NetBSD and
macOS do not reference it.  It seems safe to remove.
@droe droe deleted the droe/fix-bsd-get_iface_hw_addr branch March 11, 2024 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants