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

net: arp: Add support for gratuitous ARP transmission #71873

Merged
merged 2 commits into from May 8, 2024

Conversation

rlubos
Copy link
Contributor

@rlubos rlubos commented Apr 24, 2024

Add support for gratuitous ARP transmission by Zephyr network stack.
This allows to prematurely fill the peer ARP table, so there's no need
to send an explicit request when peer needs to send an actual packet.

The gratuitous ARP is send when the network interface is brought up
(joins the network) or a new IP address is added. The gratuitous ARP
request is also sent periodically, with a configurable interval time.
The gratuitous ARP should also be sent whenever MAC address of the
interface is changed, but as Zephyr only allows to do this when
interface is down, this is already covered by the first case (interface
brought up).

Resolves #57839

@rlubos rlubos requested review from jukkar and krish2718 April 24, 2024 11:51
@rlubos rlubos added the DNM This PR should not be merged (Do Not Merge) label Apr 24, 2024
@rlubos
Copy link
Contributor Author

rlubos commented Apr 24, 2024

Temporarily pelase DNM.

Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

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

Tested it and it works ok, we just need to add some checks for VLAN interfaces.

depends on NET_MGMT_EVENT_INFO

config NET_ARP_GRATUITOUS_INTERVAL
int "Time interval [s] between sending gratuitous ARP requests"
Copy link
Member

Choose a reason for hiding this comment

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

[s] is confusing, I actually missed first what it was suppose to mean. Perhaps we could have here or at the end in sec instead, or have a proper help text that could even mention the relevant RFC https://datatracker.ietf.org/doc/html/rfc5227

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the description.

{
struct in_addr *ipaddr;

if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
Copy link
Member

Choose a reason for hiding this comment

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

We need to check also if the interface is VLAN one.

@@ -542,7 +542,8 @@ static void iface_event_handler(struct net_mgmt_event_callback *cb,
 {
        ARG_UNUSED(cb);
 
-       if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
+       if (!(net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET) ||
+             net_eth_is_vlan_interface(iface))) {
                return;
        }
 
@@ -558,7 +559,8 @@ static void ipv4_event_handler(struct net_mgmt_event_callback *cb,
 {
        struct in_addr *ipaddr;
 
-       if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
+       if (!(net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET) ||
+             net_eth_is_vlan_interface(iface))) {
                return;
        }
 
@@ -583,7 +585,8 @@ static void iface_cb(struct net_if *iface, void *user_data)
 {
        ARG_UNUSED(user_data);
 
-       if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
+       if (!(net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET) ||
+             net_eth_is_vlan_interface(iface))) {
                return;
        }

This requires #71909 which contains the helper function returning this information, I had missed implementing it.

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

rlubos added 2 commits May 7, 2024 11:57
Add support for gratuitous ARP transmission by Zephyr network stack.
This allows to prematurely fill the peer ARP table, so there's no need
to send an explicit request when peer needs to send an actual packet.

The gratuitous ARP is send when the network interface is brought up
(joins the network) or a new IP address is added. The gratuitous ARP
request is also sent periodically, with a configurable interval time.
The gratuitous ARP should also be sent whenever MAC address of the
interface is changed, but as Zephyr only allows to do this when
interface is down, this is already covered by the first case (interface
brought up).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add you config to the build-all net tests, to make sure everything build
properly.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
@rlubos
Copy link
Contributor Author

rlubos commented May 7, 2024

I've addressed the comments and fixed the build error.

@rlubos
Copy link
Contributor Author

rlubos commented May 8, 2024

Passed internal verification, removing DNM.

@rlubos rlubos removed the DNM This PR should not be merged (Do Not Merge) label May 8, 2024
@nashif nashif merged commit f003087 into zephyrproject-rtos:main May 8, 2024
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

net: Implement sending gratuitous ARP once network interface is operational
5 participants