* [PATCH can-utils] cangen: allow to use -m on classical CAN interfaces
@ 2025-09-07 6:03 Vincent Mailhol
2025-09-08 11:10 ` Marc Kleine-Budde
0 siblings, 1 reply; 4+ messages in thread
From: Vincent Mailhol @ 2025-09-07 6:03 UTC (permalink / raw)
To: Oliver Hartkopp, Marc Kleine-Budde; +Cc: linux-can, Vincent Mailhol
The -m option currently only works on CAN FD or CAN XL interfaces.
There is a logic to add CAN XL to the mix only if supported but CAN FD
is always forced.
Modify the -m logic so that only the options supported by the
interface are added to the mix. This way:
- a Classical CAN interface only mixes -e and -R
- a CAN FD interface mixes -e, -R, -f, -b and -E
- a CAN XL interface mixes -e, -R, -f, -b, -E and -X
This provides a better user experience and also makes -m a good
default option for fuzzing any type of CAN interface.
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
cangen.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/cangen.c b/cangen.c
index 95ac32d..5715447 100644
--- a/cangen.c
+++ b/cangen.c
@@ -180,7 +180,7 @@ static void print_usage(char *prg)
fprintf(stderr, " -X (generate CAN XL CAN frames)\n");
fprintf(stderr, " -R (generate RTR frames)\n");
fprintf(stderr, " -8 (allow DLC values greater then 8 for Classic CAN frames)\n");
- fprintf(stderr, " -m (mix -e -f -b -E -R -X frames)\n");
+ fprintf(stderr, " -m (mix -e -R frames and -f -b -E if FD capable and -X if XL capable)\n");
fprintf(stderr, " -I <mode> (CAN ID generation mode - see below)\n");
fprintf(stderr, " -L <mode> (CAN data length code (dlc) generation mode - see below)\n");
fprintf(stderr, " -D <mode> (CAN data (payload) generation mode - see below)\n");
@@ -574,7 +574,6 @@ int main(int argc, char **argv)
case 'm':
mix = 1;
- canfd = 1; /* to switch the socket into CAN FD mode */
view |= CANLIB_VIEW_INDENT_SFF;
break;
@@ -777,7 +776,7 @@ int main(int argc, char **argv)
&loopback, sizeof(loopback));
}
- if (canfd || canxl) {
+ if (mix || canfd || canxl) {
/* check if the frame fits into the CAN netdevice */
if (ioctl(s, SIOCGIFMTU, &ifr) < 0) {
@@ -1084,10 +1083,13 @@ int main(int argc, char **argv)
if (mix) {
i = random();
extended = i & 1;
- canfd = i & 2;
- if (canfd) {
- brs = i & 4;
- esi = i & 8;
+ /* generate CAN FD traffic if the interface is capable */
+ if (ifr.ifr_mtu >= (int)CANFD_MTU) {
+ canfd = i & 2;
+ if (canfd) {
+ brs = i & 4;
+ esi = i & 8;
+ }
}
/* generate CAN XL traffic if the interface is capable */
if (ifr.ifr_mtu >= (int)CANXL_MIN_MTU)
--
2.49.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH can-utils] cangen: allow to use -m on classical CAN interfaces
2025-09-07 6:03 [PATCH can-utils] cangen: allow to use -m on classical CAN interfaces Vincent Mailhol
@ 2025-09-08 11:10 ` Marc Kleine-Budde
2025-09-08 11:27 ` Oliver Hartkopp
0 siblings, 1 reply; 4+ messages in thread
From: Marc Kleine-Budde @ 2025-09-08 11:10 UTC (permalink / raw)
To: Vincent Mailhol; +Cc: Oliver Hartkopp, linux-can
[-- Attachment #1: Type: text/plain, Size: 978 bytes --]
On 07.09.2025 15:03:30, Vincent Mailhol wrote:
> The -m option currently only works on CAN FD or CAN XL interfaces.
> There is a logic to add CAN XL to the mix only if supported but CAN FD
> is always forced.
>
> Modify the -m logic so that only the options supported by the
> interface are added to the mix. This way:
>
> - a Classical CAN interface only mixes -e and -R
> - a CAN FD interface mixes -e, -R, -f, -b and -E
> - a CAN XL interface mixes -e, -R, -f, -b, -E and -X
>
> This provides a better user experience and also makes -m a good
> default option for fuzzing any type of CAN interface.
I've created a PR on GH:
https://github.com/linux-can/can-utils/pull/599
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH can-utils] cangen: allow to use -m on classical CAN interfaces
2025-09-08 11:10 ` Marc Kleine-Budde
@ 2025-09-08 11:27 ` Oliver Hartkopp
2025-09-08 11:33 ` Marc Kleine-Budde
0 siblings, 1 reply; 4+ messages in thread
From: Oliver Hartkopp @ 2025-09-08 11:27 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol; +Cc: linux-can
Me too :-D
https://github.com/linux-can/can-utils/pull/600
The former concept mixed the actual frame format (canfd canxl) with the
switch whether FD/XL is enabled and operable.
So I reworked the idea from Vincent.
Best regards,
Oliver
On 08.09.25 13:10, Marc Kleine-Budde wrote:
> On 07.09.2025 15:03:30, Vincent Mailhol wrote:
>> The -m option currently only works on CAN FD or CAN XL interfaces.
>> There is a logic to add CAN XL to the mix only if supported but CAN FD
>> is always forced.
>>
>> Modify the -m logic so that only the options supported by the
>> interface are added to the mix. This way:
>>
>> - a Classical CAN interface only mixes -e and -R
>> - a CAN FD interface mixes -e, -R, -f, -b and -E
>> - a CAN XL interface mixes -e, -R, -f, -b, -E and -X
>>
>> This provides a better user experience and also makes -m a good
>> default option for fuzzing any type of CAN interface.
>
> I've created a PR on GH:
> https://github.com/linux-can/can-utils/pull/599
>
> Marc
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-08 11:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-07 6:03 [PATCH can-utils] cangen: allow to use -m on classical CAN interfaces Vincent Mailhol
2025-09-08 11:10 ` Marc Kleine-Budde
2025-09-08 11:27 ` Oliver Hartkopp
2025-09-08 11:33 ` Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox