Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: gw: indicate and count deleted frames due to misconfiguration

Add a statistic counter to detect deleted frames due to misconfiguration with
a new read-only CGW_DELETED netlink attribute for the CAN gateway.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Oliver Hartkopp and committed by
Marc Kleine-Budde
e6afa00a be286baf

+12 -1
+1
include/uapi/linux/can/gw.h
··· 44 44 CGW_SRC_IF, /* ifindex of source network interface */ 45 45 CGW_DST_IF, /* ifindex of destination network interface */ 46 46 CGW_FILTER, /* specify struct can_filter on source CAN device */ 47 + CGW_DELETED, /* number of deleted CAN frames (see max_hops param) */ 47 48 __CGW_MAX 48 49 }; 49 50
+11 -1
net/can/gw.c
··· 131 131 struct rcu_head rcu; 132 132 u32 handled_frames; 133 133 u32 dropped_frames; 134 + u32 deleted_frames; 134 135 struct cf_mod mod; 135 136 union { 136 137 /* CAN frame data source */ ··· 368 367 369 368 BUG_ON(skb->ip_summed != CHECKSUM_UNNECESSARY); 370 369 371 - if (cgw_hops(skb) >= max_hops) 370 + if (cgw_hops(skb) >= max_hops) { 371 + /* indicate deleted frames due to misconfiguration */ 372 + gwj->deleted_frames++; 372 373 return; 374 + } 373 375 374 376 if (!(gwj->dst.dev->flags & IFF_UP)) { 375 377 gwj->dropped_frames++; ··· 501 497 502 498 if (gwj->dropped_frames) { 503 499 if (nla_put_u32(skb, CGW_DROPPED, gwj->dropped_frames) < 0) 500 + goto cancel; 501 + } 502 + 503 + if (gwj->deleted_frames) { 504 + if (nla_put_u32(skb, CGW_DELETED, gwj->deleted_frames) < 0) 504 505 goto cancel; 505 506 } 506 507 ··· 808 799 809 800 gwj->handled_frames = 0; 810 801 gwj->dropped_frames = 0; 802 + gwj->deleted_frames = 0; 811 803 gwj->flags = r->flags; 812 804 gwj->gwtype = r->gwtype; 813 805