]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
can: gw: use can_gw_hops instead of sk_buff::csum_start
authorOliver Hartkopp <socketcan@hartkopp.net>
Sun, 1 Feb 2026 14:33:21 +0000 (15:33 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 5 Feb 2026 10:58:40 +0000 (11:58 +0100)
As CAN skbs don't use IP checksums the skb->csum_start variable was used to
store the can-gw CAN frame time-to-live counter together with
skb->ip_summed set to CHECKSUM_UNNECESSARY.

Remove the 'hack' using the skb->csum_start variable and move the content
to can_skb_ext::can_gw_hops of the CAN skb extensions.

The module parameter 'max_hops' has been reduced to a single byte to fit
can_skb_ext::can_gw_hops as the maximum value to be stored is 6.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260201-can_skb_ext-v8-6-3635d790fe8b@hartkopp.net
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/can/vxcan.c
net/can/gw.c

index ac2211f8070c7c96fbba6b638eb47761d2e0034a..e882250180ef65acfe7337d256bf183b9f23e587 100644 (file)
@@ -77,7 +77,7 @@ static netdev_tx_t vxcan_xmit(struct sk_buff *oskb, struct net_device *dev)
        }
 
        /* reset CAN GW hop counter */
-       skb->csum_start = 0;
+       csx->can_gw_hops = 0;
        skb->pkt_type   = PACKET_BROADCAST;
        skb->dev        = peer;
        skb->ip_summed  = CHECKSUM_UNNECESSARY;
index 816154a978c1bad0f50c21484ba96a79afddc4e2..61a1e6b1b83f1aa0b925b1e9cfbf956aaad544d0 100644 (file)
@@ -71,8 +71,8 @@ MODULE_ALIAS(CAN_GW_NAME);
 #define CGW_MAX_HOPS 6
 #define CGW_DEFAULT_HOPS 1
 
-static unsigned int max_hops __read_mostly = CGW_DEFAULT_HOPS;
-module_param(max_hops, uint, 0444);
+static unsigned char max_hops __read_mostly = CGW_DEFAULT_HOPS;
+module_param(max_hops, byte, 0444);
 MODULE_PARM_DESC(max_hops,
                 "maximum " CAN_GW_NAME " routing hops for CAN frames "
                 "(valid values: " __stringify(CGW_MIN_HOPS) "-"
@@ -480,19 +480,8 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)
        /* Do not handle CAN frames routed more than 'max_hops' times.
         * In general we should never catch this delimiter which is intended
         * to cover a misconfiguration protection (e.g. circular CAN routes).
-        *
-        * The Controller Area Network controllers only accept CAN frames with
-        * correct CRCs - which are not visible in the controller registers.
-        * According to skbuff.h documentation the csum_start element for IP
-        * checksums is undefined/unused when ip_summed == CHECKSUM_UNNECESSARY.
-        * Only CAN skbs can be processed here which already have this property.
         */
-
-#define cgw_hops(skb) ((skb)->csum_start)
-
-       BUG_ON(skb->ip_summed != CHECKSUM_UNNECESSARY);
-
-       if (cgw_hops(skb) >= max_hops) {
+       if (csx->can_gw_hops >= max_hops) {
                /* indicate deleted frames due to misconfiguration */
                gwj->deleted_frames++;
                return;
@@ -536,11 +525,11 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)
        }
 
        /* put the incremented hop counter in the cloned skb */
-       cgw_hops(nskb) = cgw_hops(skb) + 1;
+       ncsx->can_gw_hops = csx->can_gw_hops + 1;
 
        /* first processing of this CAN frame -> adjust to private hop limit */
-       if (gwj->limit_hops && cgw_hops(nskb) == 1)
-               cgw_hops(nskb) = max_hops - gwj->limit_hops + 1;
+       if (gwj->limit_hops && ncsx->can_gw_hops == 1)
+               ncsx->can_gw_hops = max_hops - gwj->limit_hops + 1;
 
        nskb->dev = gwj->dst.dev;