Skip to content

Commit f77d8ec

Browse files
cperera-audtmon-nordic
authored andcommitted
[nrf fromtree] net: ethernet: Fixes for ethernet stats reporting.
The following fixes were applied: - Multicast Rx packets stats were not recorded due not parsing the ethernet header. The function that tried to parse the ethernet header was parsing the ethernet packet beyond the ethernet header. - Added a new stats for unknown protocol which gets updated when the ethernet layer encounters an unknown ethernet packet type. Fixes #53994 Signed-off-by: Chamira Perera <[email protected]> (cherry picked from commit ce49beb)
1 parent 9c62553 commit f77d8ec

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

include/zephyr/net/net_stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ struct net_stats_eth {
452452
net_stats_t tx_dropped;
453453
net_stats_t tx_timeout_count;
454454
net_stats_t tx_restart_queue;
455+
net_stats_t unknown_protocol;
455456
#ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
456457
/** Array is terminated with an entry containing a NULL key */
457458
struct net_stats_eth_vendor *vendor;

subsys/net/l2/ethernet/eth_stats.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,24 @@ static inline void eth_stats_update_errors_tx(struct net_if *iface)
202202
stats->errors.tx++;
203203
}
204204

205+
static inline void eth_stats_update_unknown_protocol(struct net_if *iface)
206+
{
207+
struct net_stats_eth *stats;
208+
const struct ethernet_api *api = ((const struct ethernet_api *)
209+
net_if_get_device(iface)->api);
210+
211+
if (!api->get_stats) {
212+
return;
213+
}
214+
215+
stats = api->get_stats(net_if_get_device(iface));
216+
if (!stats) {
217+
return;
218+
}
219+
220+
stats->unknown_protocol++;
221+
}
222+
205223
#else /* CONFIG_NET_STATISTICS_ETHERNET */
206224

207225
#define eth_stats_update_bytes_rx(iface, bytes)
@@ -214,6 +232,7 @@ static inline void eth_stats_update_errors_tx(struct net_if *iface)
214232
#define eth_stats_update_multicast_tx(iface)
215233
#define eth_stats_update_errors_rx(iface)
216234
#define eth_stats_update_errors_tx(iface)
235+
#define eth_stats_update_unknown_protocol(iface)
217236

218237
#endif /* CONFIG_NET_STATISTICS_ETHERNET */
219238

subsys/net/l2/ethernet/ethernet.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,9 @@ static inline void ethernet_update_length(struct net_if *iface,
144144
}
145145

146146
static void ethernet_update_rx_stats(struct net_if *iface,
147-
struct net_pkt *pkt, size_t length)
147+
struct net_eth_hdr *hdr, size_t length)
148148
{
149149
#if defined(CONFIG_NET_STATISTICS_ETHERNET)
150-
struct net_eth_hdr *hdr = NET_ETH_HDR(pkt);
151-
152150
eth_stats_update_bytes_rx(iface, length);
153151
eth_stats_update_pkts_rx(iface);
154152

@@ -213,7 +211,7 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
213211
net_pkt_lladdr_dst(pkt)->addr = hdr->dst.addr;
214212
net_pkt_lladdr_dst(pkt)->len = sizeof(struct net_eth_addr);
215213
net_pkt_lladdr_dst(pkt)->type = NET_LINK_ETHERNET;
216-
ethernet_update_rx_stats(iface, pkt, net_pkt_get_len(pkt));
214+
ethernet_update_rx_stats(iface, hdr, net_pkt_get_len(pkt));
217215
return net_eth_bridge_input(ctx, pkt);
218216
}
219217

@@ -263,7 +261,8 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
263261
}
264262

265263
NET_DBG("Unknown hdr type 0x%04x iface %p", type, iface);
266-
goto drop;
264+
eth_stats_update_unknown_protocol(iface);
265+
return NET_DROP;
267266
}
268267

269268
/* Set the pointers to ll src and dst addresses */
@@ -320,7 +319,7 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
320319
goto drop;
321320
}
322321

323-
ethernet_update_rx_stats(iface, pkt, net_pkt_get_len(pkt) + hdr_len);
322+
ethernet_update_rx_stats(iface, hdr, net_pkt_get_len(pkt) + hdr_len);
324323

325324
if (IS_ENABLED(CONFIG_NET_ARP) &&
326325
family == AF_INET && type == NET_ETH_PTYPE_ARP) {

0 commit comments

Comments
 (0)