-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Allow gPTP over VLAN #8615
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
Allow gPTP over VLAN #8615
Conversation
tbursztyka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't this eth header filling be factorized? it's the same exact code copy pasted all over.
well in short having a higher level protocol messing up with link layer is a super mess. It's what we've been doing so far and that's going to disappear (it has to, better have a single place for filling in l2 header than scattered everywhere).
| NET_ASSERT(iface); | ||
|
|
||
| #if defined(CONFIG_NET_VLAN) | ||
| eth_ctx = net_if_l2_data(iface); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't you be using net_eth_is_vlan_enabled() here?
Btw, I can't recall why net_eth_is_vlan_enabled() has to take the context in parameter? Since we pass the iface, it can get the context. Or is this function meant to be used with a context that does not belong to the iface? (which sounds a bit weird)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be more than one (vlan) interface specified in one context.
| struct gptp_hdr *hdr; | ||
|
|
||
| #if defined(CONFIG_NET_VLAN) | ||
| struct net_eth_vlan_hdr *hdr_vlan; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move that after line 202
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think that is against the coding style. Meaning we should introduce variables at the beginning of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it's not against if you do:
if (net_eth_get_vlan_info(iface, ð_len)) {
struct net_eth_vlan_hdr *hdr_vlan;
...
}
Actually all can go in that if, no need of the vlan_enabled at all.
Just move all that at line 213
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be done because hdr_vlan is filled later in the function. For that we also need the vlan_enabled flag.
|
|
||
| #if defined(CONFIG_NET_VLAN) | ||
| if (vlan_enabled) { | ||
| hdr_vlan = (struct net_eth_vlan_hdr *)NET_ETH_HDR(pkt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move that after line 202
| struct net_buf *frag; | ||
|
|
||
| #if defined(CONFIG_NET_VLAN) | ||
| struct net_eth_vlan_hdr *hdr_vlan; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, move after line 317
| #if defined(CONFIG_NET_VLAN) | ||
| if (vlan_enabled) { | ||
| hdr_vlan = (struct net_eth_vlan_hdr *)NET_ETH_HDR(pkt); | ||
| net_pkt_set_vlan_tag(pkt, net_pkt_vlan_tag(sync)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move these 2 lines after 317
| struct gptp_hdr *hdr; | ||
|
|
||
| #if defined(CONFIG_NET_VLAN) | ||
| struct net_eth_vlan_hdr *hdr_vlan; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well you know the song now.
Codecov Report
@@ Coverage Diff @@
## master #8615 +/- ##
==========================================
- Coverage 52.24% 52.22% -0.02%
==========================================
Files 195 195
Lines 24655 24673 +18
Branches 5123 5124 +1
==========================================
+ Hits 12880 12886 +6
- Misses 9709 9721 +12
Partials 2066 2066
Continue to review full report at Codecov.
|
Send network management event if VLAN tag is enabled or disabled. Signed-off-by: Jukka Rissanen <[email protected]>
| void ethernet_mgmt_raise_vlan_enabled_event(struct net_if *iface, u16_t tag) | ||
| { | ||
| #if defined(CONFIG_NET_MGMT_EVENT_INFO) | ||
| net_mgmt_event_notify_with_info(NET_EVENT_ETHERNET_VLAN_TAG_ENABLED, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need that version? Because it's possible to retrieve the tag from the iface right? So then no need to give it through the mgmt interface as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For enabled event we could get it from iface, but that would not work for disabled event. Thus in order to keep the functions looking similar, I opted to have the tag in the enabled API.
| struct gptp_hdr *hdr; | ||
|
|
||
| #if defined(CONFIG_NET_VLAN) | ||
| struct net_eth_vlan_hdr *hdr_vlan; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it's not against if you do:
if (net_eth_get_vlan_info(iface, ð_len)) {
struct net_eth_vlan_hdr *hdr_vlan;
...
}
Actually all can go in that if, no need of the vlan_enabled at all.
Just move all that at line 213
subsys/net/l2/ethernet/ethernet.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the fact it does 2 things: saying it's vlan enabled and returning the eth header size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets get rid of that second parameter, it is not really needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it would be:
if (IS_ENABLED(CONFIG_NET_GPTP_VLAN)) {
setup_eth_vlan_hdr(iface, pkt);
} else {
eth->type = htons(NET_ETH_PTYPE_PTP);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 166:
frag = gptp_get_frag() and make that function, aware of vlan so reserving the right amount etc...
Then no need of eth_len being set here if vlan or not. This logic is repeated all over below, so it's worth getting 1 place doing it.
|
More refactoring done |
A small helper function will return information whether a given network interface has VLAN enabled or not. Signed-off-by: Jukka Rissanen <[email protected]>
Allow this setup as Linux supports this too. Signed-off-by: Jukka Rissanen <[email protected]>
By default gPTP is not run over VLAN but if needed that can be done by setting CONFIG_NET_GPTP_VLAN and CONFIG_NET_GPTP_VLAN_TAG options. Signed-off-by: Jukka Rissanen <[email protected]>
tbursztyka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah now it's just right
No description provided.