Skip to content

Commit e6afa00

Browse files
hartkoppmarckleinebudde
authored andcommitted
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>
1 parent be286ba commit e6afa00

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎include/uapi/linux/can/gw.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum {
4444
CGW_SRC_IF, /* ifindex of source network interface */
4545
CGW_DST_IF, /* ifindex of destination network interface */
4646
CGW_FILTER, /* specify struct can_filter on source CAN device */
47+
CGW_DELETED, /* number of deleted CAN frames (see max_hops param) */
4748
__CGW_MAX
4849
};
4950

‎net/can/gw.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct cgw_job {
131131
struct rcu_head rcu;
132132
u32 handled_frames;
133133
u32 dropped_frames;
134+
u32 deleted_frames;
134135
struct cf_mod mod;
135136
union {
136137
/* CAN frame data source */
@@ -367,8 +368,11 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)
367368

368369
BUG_ON(skb->ip_summed != CHECKSUM_UNNECESSARY);
369370

370-
if (cgw_hops(skb) >= max_hops)
371+
if (cgw_hops(skb) >= max_hops) {
372+
/* indicate deleted frames due to misconfiguration */
373+
gwj->deleted_frames++;
371374
return;
375+
}
372376

373377
if (!(gwj->dst.dev->flags & IFF_UP)) {
374378
gwj->dropped_frames++;
@@ -500,6 +504,11 @@ static int cgw_put_job(struct sk_buff *skb, struct cgw_job *gwj, int type,
500504
goto cancel;
501505
}
502506

507+
if (gwj->deleted_frames) {
508+
if (nla_put_u32(skb, CGW_DELETED, gwj->deleted_frames) < 0)
509+
goto cancel;
510+
}
511+
503512
/* check non default settings of attributes */
504513

505514
if (gwj->mod.modtype.and) {
@@ -799,6 +808,7 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh,
799808

800809
gwj->handled_frames = 0;
801810
gwj->dropped_frames = 0;
811+
gwj->deleted_frames = 0;
802812
gwj->flags = r->flags;
803813
gwj->gwtype = r->gwtype;
804814

0 commit comments

Comments
 (0)