Skip to content

Conversation

@jukkar
Copy link
Member

@jukkar jukkar commented Jun 28, 2018

No description provided.

Copy link
Contributor

@tbursztyka tbursztyka left a 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);
Copy link
Contributor

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)

Copy link
Member Author

@jukkar jukkar Jul 2, 2018

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;
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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, &eth_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

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 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);
Copy link
Contributor

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;
Copy link
Contributor

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));
Copy link
Contributor

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;
Copy link
Contributor

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-io
Copy link

codecov-io commented Jun 28, 2018

Codecov Report

Merging #8615 into master will decrease coverage by 0.01%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
include/net/ethernet.h 38.46% <ø> (ø) ⬆️
subsys/net/l2/ethernet/ethernet_mgmt.c 43.85% <0%> (-5.16%) ⬇️
include/net/ethernet_mgmt.h 50% <100%> (+50%) ⬆️
subsys/net/l2/ethernet/ethernet.c 51.22% <25%> (-0.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 536d77a...dfe3194. Read the comment docs.

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,
Copy link
Contributor

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.

Copy link
Member Author

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;
Copy link
Contributor

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, &eth_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

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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);
}

Copy link
Contributor

@tbursztyka tbursztyka Jul 3, 2018

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.

@jukkar
Copy link
Member Author

jukkar commented Jul 3, 2018

More refactoring done

jukkar added 3 commits July 3, 2018 17:26
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]>
Copy link
Contributor

@tbursztyka tbursztyka left a 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

@jukkar jukkar merged commit ad15056 into zephyrproject-rtos:master Jul 3, 2018
@jukkar jukkar deleted the gptp-2 branch July 20, 2018 19:09
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.

3 participants