Skip to content

net/ethernet/ethernet.c: Handle ieee 802.1q (vlan) headers with id 0 (even if CONFIG_VLAN is not enabled) #83662

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

Closed
clamattia opened this issue Jan 7, 2025 · 6 comments
Labels
area: Ethernet Enhancement Changes/Updates/Additions to existing features

Comments

@clamattia
Copy link
Collaborator

clamattia commented Jan 7, 2025

Is your enhancement proposal related to a problem? Please describe.
Handle ieee 802.1q headers with vlan id 0 correctly, by forwarding them to the native default interface. This is as far as I could gather the intended use for the vlan-id 0. This is also required for some industrial protocols.

Describe the solution you'd like
Ethernet Frames tagged with id 0 should be stripped or in other words forwarded to the native interface, even if the CONFIG_VLAN is not enabled.
I am experimenting with something like:

	if (type == NET_ETH_PTYPE_VLAN) {
		struct net_eth_vlan_hdr *hdr_vlan = (struct net_eth_vlan_hdr *)NET_ETH_HDR(pkt);
		uint16_t tci = ntohs(hdr_vlan->vlan.tci);
		uint16_t tag = net_eth_vlan_get_vid(tci);
		if (tag == 0) {
			type = ntohs(hdr_vlan->type);
			hdr_len = sizeof(struct net_eth_vlan_hdr);
		}
	}

Describe alternatives you've considered
None, as this is as far as I know the standardized behavior. If someone can confirm, this would be great.

@clamattia
Copy link
Collaborator Author

Please also note, that this will have to be adjusted:
ethernet.h

#if defined(CONFIG_NET_VLAN)
#define _NET_ETH_MAX_HDR_SIZE		(sizeof(struct net_eth_vlan_hdr))
#else
#define _NET_ETH_MAX_HDR_SIZE		(sizeof(struct net_eth_hdr))
#endif

It assumes, that the drivers need not be able to receive vlan-tagged frames except, when CONFIG_NET_VLAN is enabled.
See related issue in stm32 driver: #83277

@jukkar
Copy link
Member

jukkar commented Jan 9, 2025

It assumes, that the drivers need not be able to receive vlan-tagged frames except, when CONFIG_NET_VLAN is enabled.

I think this is a good assumption, after all if VLAN is not enabled the driver can just drop VLAN frames.

@jukkar
Copy link
Member

jukkar commented Jan 9, 2025

Handle ieee 802.1q headers with vlan id 0 correctly, by forwarding them to the native default interface. This is as far as I could gather the intended use for the vlan-id 0. This is also required for some industrial protocols.

This is a good point, the VLAN 0 should be passed to native interface. Would you be able to send a PR for it?

@clamattia
Copy link
Collaborator Author

Handle ieee 802.1q headers with vlan id 0 correctly, by forwarding them to the native default interface. This is as far as I could gather the intended use for the vlan-id 0. This is also required for some industrial protocols.

This is a good point, the VLAN 0 should be passed to native interface. Would you be able to send a PR for it?

Yes, I have prepared a PR. Please have a look.

@clamattia
Copy link
Collaborator Author

It assumes, that the drivers need not be able to receive vlan-tagged frames except, when CONFIG_NET_VLAN is enabled.

I think this is a good assumption, after all if VLAN is not enabled the driver can just drop VLAN frames.

This assumption is no longer valid, if the proposal of this issue is implemented. See proposal in PR.

@clamattia
Copy link
Collaborator Author

Completed by: #83734
Enhancement tracked by: #84023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Ethernet Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

No branches or pull requests

3 participants