Skip to content

net: ethernet: strip vlan headers if id is zero #83734

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

Merged
merged 2 commits into from
Jan 22, 2025

Conversation

clamattia
Copy link
Collaborator

Allow to receive vlan frames with id zero even when the vlan interface is disabled. They are forwarded to the native interface or in other words, the vlan header is simply stripped and ignored.

#83662

@maass-hamburg
Copy link
Collaborator

It might be a good idea to have this behavior behind a Kconfig and not by default. What do the others think?

@clamattia
Copy link
Collaborator Author

It might be a good idea to have this behavior behind a Kconfig and not by default. What do the others think?

I do not have a copy of the standard at hand. But it is my understanding, that this is the ieee 802.1q standardized behavior. Can someone confirm?

If so, I believe it should be the hard-coded option and not behind a feature flag.

@clamattia
Copy link
Collaborator Author

This would also fix issue #83277 for me.

@jukkar
Copy link
Member

jukkar commented Jan 9, 2025

I could not locate the spec where this is described. The feature is called VLAN 0 priority tagging, some notes about this can be found in
https://en.wikipedia.org/wiki/IEEE_802.1Q
and
https://www.cisco.com/c/en/us/td/docs/switches/connectedgrid/cg-switch-sw-master/software/configuration/guide/vlan0/b_vlan_0.html

We should enable this unconditionally so no Kconfig option for this is needed.

@clamattia
Copy link
Collaborator Author

Does someone have time to help with the tests?

Comment on lines 120 to 128
#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
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? If VLAN is disabled, then we only support normal Ethernet header lengths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The hole point of this PR is to allow to receive VLAN 0 priority tagged frames, even if VLAN is disabled. This can only be achieved, if there is enough space in the header for the priority tagged header.
In practice, if this is not adjusted, the frames with maximum length can not be received (see linked issue in stm driver).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I reverted this. Users, who want to receive priority tagged frames need to enable CONFIG_NET_VLAN now.

enum net_verdict verdict;

net_pkt_set_vlan_tci(pkt, ntohs(hdr_vlan->vlan.tci));
if (type == NET_ETH_PTYPE_VLAN) {
Copy link
Member

Choose a reason for hiding this comment

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

If VLAN is disabled, then we should never receive VLAN frames. So with this in mind, I think we do need to have the config option check, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have assumed, that we want to receive priority tagged VLAN even if it is disabled.
An alternative approach would be, that it has to be enabled, but the VLAN_COUNT=0 of actual virtual interfaces is zero. Is this what you have in mind?

Ie. If someone whats to receive priority tagged vlan headers, they need to enable CONFIG_NET_VLAN but they will not have any actual virtual LAN interface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As mentioned above. I reverted this logic. User must now enable CONFIG_NET_VLAN to receive priority tagged frames.

@clamattia
Copy link
Collaborator Author

@jukkar If someone whats to receive vlan 0 priority tagged frames. Should they set:

CONFIG_NET_VLAN=y
CONFIG_NET_VLAN_COUNT=0

?
For now minimum of CONFIG_NET_VLAN_COUNT is 1. I have assumed, that they will always want this feature. Let me know what you think?

Also CONFIG_NET_CONFIG_MY_VLAN_ID defaulting to 0 is likely an issue.

@clamattia
Copy link
Collaborator Author

@jukkar If someone whats to receive vlan 0 priority tagged frames. Should they set:

CONFIG_NET_VLAN=y
CONFIG_NET_VLAN_COUNT=0

? For now minimum of CONFIG_NET_VLAN_COUNT is 1. I have assumed, that they will always want this feature. Let me know what you think?

Also CONFIG_NET_CONFIG_MY_VLAN_ID defaulting to 0 is likely an issue.

@jukkar One reason, that speaks against that solution is, that we do not actually need/want vlan.c in the build in this situation. Should vlan.c only be build in, if VLAN_COUNT>0?

I am curious about your preferred way forward?

@clamattia clamattia force-pushed the vlan_natively_tagged branch from a1d8cbc to 68ff9bf Compare January 13, 2025 13:39
@clamattia
Copy link
Collaborator Author

clamattia commented Jan 13, 2025

Idea is now, that configuration to receive only priority tagged frames without actually enabling a virtual interface looks like:

CONFIG_NET_VLAN=y
CONFIG_NET_VLAN_COUNT=0

I will have to test, if this actually works.

Feedback is welcome :)

@clamattia clamattia requested a review from jukkar January 13, 2025 13:58
@clamattia
Copy link
Collaborator Author

Testing it leads to a problem.
With CONFIG_NET_VLAN_COUNT=1:

uart:~$ net iface
Hostname: xxx


Interface eth0 (0x20001ac0) (Ethernet) [1]
===================================
Link addr : 00:80:E1:96:0E:73
MTU       : 1500
Flags     : AUTO_START,IPv4
Device    : ethernet@40028000 (0x8076c44)
Ethernet capabilities supported:
        Virtual LAN
        10 Mbits
        100 Mbits
IPv4 unicast addresses (max 1):
        <none>
IPv4 multicast addresses (max 2):
        224.0.0.1
IPv4 gateway : 0.0.0.0

Interface net0 (0x20001ba4) (Virtual) [2]
==================================

With CONFIG_NET_VLAN_COUNT=0 gives:

uart:~$ net iface
Hostname: xxx


Interface eth0 (0x20001ab8) (Ethernet) [1]
===================================
Link addr : 00:80:E1:96:0E:73
MTU       : 1500
Flags     : AUTO_START,IPv4
Device    : ethernet@40028000 (0x8076780)
Ethernet capabilities supported:
	Virtual LAN
	10 Mbits
	100 Mbits
IPv4 not enabled for this interface.

Why does it say Ipv4 not enabled ? Probably CONFIG_NET_VLAN_COUNT=0 is breaking an assumption?

@jukkar
Copy link
Member

jukkar commented Jan 14, 2025

I am not really sure if my understanding of this feature is correct, but I thought about VLAN 0 like this:

  • The CONFIG_NET_VLAN must be enabled to receive VLAN frames. If VLAN is disabled, then user is not interested in VLAN support so VLAN 0 support is not needed either.
  • If we receive a VLAN frame with tag value 0, then the packet is fed into the underlying network interface instead of feeding it into VLAN interface.
  • Normal VLAN traffic (tags > 0) are placed to the proper VLAN interface
  • The CONFIG_NET_VLAN_COUNT is handled normally, IMHO it should have min value of 1 (because if 0, then basically VLAN is disabled which is not a point here).

WDYT?

@@ -41,7 +41,7 @@ config NET_VLAN
config NET_VLAN_COUNT
int "Max VLAN tags supported in the system"
default 1
range 1 $(UINT8_MAX)
range 0 $(UINT8_MAX)
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this is not needed because it basically disables VLAN

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See my explenation: #83734 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I try to find a way to make room for the use case of receiving VLAN 0 frames without having an actual virtual interface enabled. This is my use case.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I am not sure you need to enable the VLAN virtual interface. I mean the enabled indicates that the interface has a tag assigned to it. But to receive tag 0, this is not needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I am not sure you need to enable the VLAN virtual interface. I mean the enabled indicates that the interface has a tag assigned to it. But to receive tag 0, this is not needed.

Are you saying, that I should go back to initial draft of always (without CONFIG_VLAN enabled) forwarding tag 0 to the native interface?

This would be my preferred solution. But it has other consequences. It requires, the increase in the expected header size as in the initial draft for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have reverted. Solution no longer requires CONFIG_VLAN.

@clamattia
Copy link
Collaborator Author

clamattia commented Jan 14, 2025

  • The CONFIG_NET_VLAN must be enabled to receive VLAN frames. If VLAN is disabled, then user is not interested in VLAN support so VLAN 0 support is not needed either.

Fair enough. My initial draft wanted to not require the user to select CONFIG_NET_VLAN to have support for VLAN 0. But I can get down with this decision.

  • If we receive a VLAN frame with tag value 0, then the packet is fed into the underlying network interface instead of feeding it into VLAN interface.

Agree.

  • Normal VLAN traffic (tags > 0) are placed to the proper VLAN interface

Agree.

  • The CONFIG_NET_VLAN_COUNT is handled normally, IMHO it should have min value of 1 (because if 0, then basically VLAN is disabled which is not a point here).

Disagree. How else is the user supposed to express their interest in selecting VLAN 0 without having any virtual interface for normal VLAN traffic (tags > 0). This is my usecase. I.E. They want VLAN 0 traffic but no actual proper virtual interface.

@clamattia clamattia requested a review from jukkar January 14, 2025 14:27
@jukkar
Copy link
Member

jukkar commented Jan 14, 2025

They want VLAN 0 traffic but no actual proper virtual interface.

I don't think this is really feasible without major changes (not fully sure about this). Fortunately you do not need to enable the virtual interface to support VLAN 0.

@clamattia
Copy link
Collaborator Author

They want VLAN 0 traffic but no actual proper virtual interface.

I don't think this is really feasible without major changes (not fully sure about this). Fortunately you do not need to enable the virtual interface to support VLAN 0.

Ok, will revert to initial draft about this respect. 👍

@clamattia clamattia force-pushed the vlan_natively_tagged branch 3 times, most recently from e5f6721 to 1fc86fe Compare January 14, 2025 15:00
@clamattia
Copy link
Collaborator Author

I have reverted this aspect. Now everyone will be able to receive vlan frames with id 0 on their native interface. No need to enable CONFIG_VLAN for this.

@clamattia
Copy link
Collaborator Author

Is it not compliant to reference a config (CONFIG_VLAN) in a comment?

Comment on lines 120 to 128
#if defined(CONFIG_NET_VLAN)
/*
* Leave enough space in the header for vlan, even if CONFIG_VLAN is not enabled,
* so that frames with a vlan-header and vlan-id NET_VLAN_ID_NATIVE can be
* forwarded to the native interface.
*/
#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
Copy link
Member

Choose a reason for hiding this comment

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

If we do this change (which I think is not needed), then the net_pkt tests would need to be fixed as they are failing because of this.
If CONFIG_NET_VLAN is disabled, then we should not be able to receive Ethernet frames that have the VLAN information in it. So we should not increase the max frame size in that case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I am not sure you need to enable the VLAN virtual interface. I mean the enabled indicates that the interface has a tag assigned to it. But to receive tag 0, this is not needed.

It is needed. Otherwise id 0 frames can not be received.

I can try to fix, but I would like to get your approval on the approach first.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reverted and created separate issue: #84023

@clamattia
Copy link
Collaborator Author

As discussed in discord, have reverted to more basic solution and added issue for optimized solution here: #84023

@clamattia clamattia force-pushed the vlan_natively_tagged branch from da5842f to 5903359 Compare January 20, 2025 08:58
@clamattia
Copy link
Collaborator Author

I rebased, please re-review @jukkar

Also, ideally, we would find a solution for #84023

@jukkar jukkar force-pushed the vlan_natively_tagged branch from 5903359 to 3ce3777 Compare January 21, 2025 11:42
@jukkar
Copy link
Member

jukkar commented Jan 21, 2025

I pushed my proposal over the original PR. It has changes from #84158 in order to make testing possible. The actual VLAN tag 0 handling can be found in the last commit 3ce3777

Packets are forwarded to the native interface or in other words,
the vlan header is simply stripped and ignored. This feature is called
'priority tagging'.

Signed-off-by: Cla Mattia Galliard <[email protected]>
Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar force-pushed the vlan_natively_tagged branch from 3ce3777 to 16c4735 Compare January 22, 2025 06:55
@jukkar
Copy link
Member

jukkar commented Jan 22, 2025

  • Added tests for VLAN tag 0
  • Rebased to latest main

Make sure we are able to receive VLAN tag 0 packet, and
verify that reply packet is sent correctly.

Signed-off-by: Jukka Rissanen <[email protected]>
@jukkar jukkar force-pushed the vlan_natively_tagged branch from 16c4735 to b918a3b Compare January 22, 2025 07:36
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.

7 participants