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: vlan: Allow VLAN count to be set to 0 #84873

Merged

Conversation

jukkar
Copy link
Member

@jukkar jukkar commented Jan 29, 2025

If VLAN count is set to 0, then only priority tagged VLAN frames that have tag value 0 can be received. Also this means that VLAN interfaces are not created which can save memory if you do not need to receive any other VLAN frames than those tagged with value 0.

Fixes #84023

Signed-off-by: Jukka Rissanen [email protected]

Copy link
Contributor

@clamattia clamattia left a comment

Choose a reason for hiding this comment

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

Thank your for tackling this issue. Just one comment came to mind.

/* Dummy functions if VLAN is not really used. This is only needed
* if priority tagged frames (tag 0) are supported.
*/
bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
Copy link
Contributor

Choose a reason for hiding this comment

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

What if an additional vlan-interface (count > 0) is enabled at compile time, but it is not (yet) enabled at runtime? priority-tagged frames should still be received. I expect changes to ethernet_recv are needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

No changes are needed here as this use case was already handled by #83734, I also just verified that it works as expected.

Copy link
Contributor

Choose a reason for hiding this comment

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

I expect, we would not enter this if:

if (IS_ENABLED(CONFIG_NET_VLAN) && type == NET_ETH_PTYPE_VLAN) {
		if (net_eth_is_vlan_enabled(ctx, iface) &&
		    !eth_is_vlan_tag_stripped(iface)) {

under those circumstances, but we should?

Copy link
Member Author

Choose a reason for hiding this comment

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

We enter this branch in this case so that the Ethernet header size get set properly so that the Ethernet header is removed properly. The VLAN is enabled in this scenario, it is just that all the other tags than 0 are not in use.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, that I understand. I mean in the case, that CONFIG_VLAN>0 but not yet net_eth_is_vlan_enabled?
Maybe it is and edge case, that is not relevant. Just wanted to point it out.

Copy link
Member Author

Choose a reason for hiding this comment

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

This works because by default the tag is unspecified (we have not yet parsed the VLAN header at this point) when we enter this branch. The naming of net_eth_is_vlan_enabled() is slightly misleading, it checks in this case that the Ethernet interface has VLAN enabled bit on. It is only after a call to
net_pkt_set_vlan_tci(pkt, ntohs(hdr_vlan->vlan.tci)); the tag is set to 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the explanation.
So net_eth_is_vlan_enabled() will return true, even if it has not yet been enabled at runtime using net_eth_vlan_enable?
If so, all is clear. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is the case here. Without this, the code would not work as you noticed.

@clamattia
Copy link
Contributor

This works as intended for count == 0 for my use-case, thank you 👍

If VLAN count is set to 0, then only priority tagged VLAN frames
that have tag value 0 can be received. Also this means that VLAN
interfaces are not created which can save memory if you do not need
to receive any other VLAN frames than those tagged with value 0.

Fixes zephyrproject-rtos#84023

Signed-off-by: Jukka Rissanen <[email protected]>
Make sure the tests work if VLAN count is set to 0. This means
that only priority tagged (tag 0) VLAN frames can be received.

Signed-off-by: Jukka Rissanen <[email protected]>
No point trying to initialize VLAN interfaces if the VLAN
interface count is zero.

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar force-pushed the devel/priority-tagging-with-zero-vlan branch from 462c6ea to 593e1e9 Compare January 30, 2025 08:30
@zephyrbot zephyrbot added the area: Sockets Networking sockets label Jan 30, 2025
@jukkar
Copy link
Member Author

jukkar commented Jan 30, 2025

  • Found some issues while testing this
  • Updated to latest main

@zephyrbot zephyrbot added the area: Samples Samples label Jan 30, 2025
@zephyrbot zephyrbot requested review from kartben and nashif January 30, 2025 08:30
Copy link
Contributor

@clamattia clamattia left a comment

Choose a reason for hiding this comment

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

Thank you

Copy link
Contributor

@clamattia clamattia left a comment

Choose a reason for hiding this comment

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

Thank you

@@ -988,7 +993,7 @@ int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
*
* @return 0 if ok, <0 if error
*/
#if defined(CONFIG_NET_VLAN)
#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if this should be reduced to simply:

Suggested change
#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
#if NET_VLAN_MAX_COUNT > 0

Copy link
Member Author

Choose a reason for hiding this comment

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

I suppose that could be done too. The values are linked together although if not careful by the developer, the NET_VLAN_MAX_COUNT could be set to a value >0 even if CONFIG_NET_VLAN is not set (yes, this is an error and would probably not happen in practice).
I kind of prefer this as it is now easy to understand what the check means, so VLAN needs to be enabled and the VLAN count > 0.

@kartben kartben merged commit 6a19162 into zephyrproject-rtos:main Jan 31, 2025
31 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: ethernet: allow receive priority tagged vlan frames without needing a virtual interface
6 participants