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 AutoIP option to network options for link local addressing #27048

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/AP_Networking/AP_Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const AP_Param::GroupInfo AP_Networking::var_info[] = {
// @Param: OPTIONS
// @DisplayName: Networking options
// @Description: Networking options
// @Bitmask: 0:EnablePPP Ethernet gateway
// @Bitmask: 0:EnablePPP Ethernet gateway,1:Enable AUTOIP (Link Local IPv4 Addressing)
Ryanf55 marked this conversation as resolved.
Show resolved Hide resolved
// @RebootRequired: True
// @User: Advanced
AP_GROUPINFO("OPTIONS", 9, AP_Networking, param.options, 0),
Expand Down
15 changes: 15 additions & 0 deletions libraries/AP_Networking/AP_Networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ class AP_Networking
#endif
}


// returns true if AUTOIP is enabled
bool get_autoip_enabled() const
{
#if AP_NETWORKING_AUTOIP_AVAILABLE
return option_is_set(OPTION::AUTOIP);
#else
// AUTOIP is not available from our scope but could be enabled/controlled
// by the OS which is the case on Linux builds, including SITL
// TODO: ask the OS if link local IPv4 addressing is enabled
return false;
#endif
}

// Sets DHCP to be enabled or disabled
void set_dhcp_enable(const bool enable)
{
Expand Down Expand Up @@ -155,6 +169,7 @@ class AP_Networking

enum class OPTION {
PPP_ETHERNET_GATEWAY=(1U<<0),
AUTOIP=(1u<<1)
};
bool option_is_set(OPTION option) const {
return (param.options.get() & int32_t(option)) != 0;
Expand Down
10 changes: 10 additions & 0 deletions libraries/AP_Networking/AP_Networking_ChibiOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ void AP_Networking_ChibiOS::link_up_cb(void *p)
if (driver->frontend.get_dhcp_enabled()) {
dhcp_start(driver->thisif);
}
# if LWIP_AUTOIP
Copy link
Contributor

Choose a reason for hiding this comment

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

in lwipthread.c the lwipDefaultLinkUpCB/DownCB() functions perform the autoip before the dhcp. I don't think it matters but it would at least be nice to use the tested method that everyone else uses

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For sure, but I was just following the docs: https://lwip.fandom.com/wiki/AUTOIP

Copy link
Collaborator Author

@Ryanf55 Ryanf55 May 14, 2024

Choose a reason for hiding this comment

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

Looking at the source code comments, there's a different recommendation:
https://github.com/ARMmbed/lwip/blob/4059748b4789fbda5970261bb075657565a1f381/src/core/ipv4/autoip.c#L22

Seems like we need to conditionally call autoip_start depending on if DHCP is enabled or not.
That said, the implementation already handles cleanly calling it mulitple times, so I don't see why we don't call this regardless, as long as it's enabled.

Copy link
Collaborator Author

@Ryanf55 Ryanf55 May 15, 2024

Choose a reason for hiding this comment

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

If it's part of the default behavior, I would expect autoip to show up if DHCP is not available but enabled, but that's not the behavior I observe.

On master, with DHCP enabled, but no DHCP server, I observe no address reported in the console logs.
image
Because AP doesn't respond to broadcast, doesn't support MDNS, and doesn't log its current address, and the configured static address doesn't work when DHCP is enabled, I'm not quite sure what's going on.

if(driver->frontend.get_autoip_enabled()) {
autoip_start(driver->thisif);
}
#endif // LWIP_AUTOIP
#endif
}

Expand All @@ -158,6 +163,11 @@ void AP_Networking_ChibiOS::link_down_cb(void *p)
if (driver->frontend.get_dhcp_enabled()) {
dhcp_stop(driver->thisif);
}
# if LWIP_AUTOIP
if(driver->frontend.get_autoip_enabled()) {
autoip_stop(driver->thisif);
}
#endif // LWIP_AUTOIP
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Networking/AP_Networking_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
#define AP_NETWORKING_DHCP_AVAILABLE (AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS_ENABLED || AP_NETWORKING_BACKEND_CHIBIOS)
#endif

#ifndef AP_NETWORKING_AUTOIP_AVAILABLE
#define AP_NETWORKING_AUTOIP_AVAILABLE AP_NETWORKING_DHCP_AVAILABLE
#endif

// ---------------------------
// Below are default params
Expand Down