isotpsniffer: option for no quitting on invalid message received#550
isotpsniffer: option for no quitting on invalid message received#550maziu wants to merge 2 commits intolinux-can:masterfrom
Conversation
isotpsniffer.c
Outdated
| fprintf(stderr, " -f <format> (1 = HEX, 2 = ASCII, 3 = HEX & ASCII - default: %d)\n", FORMAT_DEFAULT); | ||
| fprintf(stderr, " -L (set link layer options for CAN FD)\n"); | ||
| fprintf(stderr, " -h <len> (head: print only first <len> bytes)\n"); | ||
| fprintf(stderr, " -q (don't quit on read error, allows to receive malformed frames)\n"); |
There was a problem hiding this comment.
I would suggest to use '-i' analog to cangen:
-i (ignore syscall errors to receive malformed PDUs)
isotpsniffer.c
Outdated
| int head = 0; | ||
| int timestamp = 0; | ||
| int format = FORMAT_DEFAULT; | ||
| int noquit = 0; |
There was a problem hiding this comment.
To follow up with the '-i' option
ignore_errors = 0
isotpsniffer.c
Outdated
| } | ||
| if (nbytes > 4095) { | ||
| r = 1; | ||
| perror("read socket s too much data"); |
There was a problem hiding this comment.
PDU length %d longer than PDU buffer", nbytes)
isotpsniffer.c
Outdated
| } | ||
| if (nbytes > 4095) { | ||
| r = 1; | ||
| perror("read socket t too much data"); |
There was a problem hiding this comment.
PDU length %d longer than PDU buffer", nbytes)
isotpsniffer.c
Outdated
| @@ -197,7 +199,7 @@ int main(int argc, char **argv) | |||
| unsigned char buffer[4096]; | |||
There was a problem hiding this comment.
Can you add some
#define PDU_BUF_SIZE 8300
here which is then used for buffer[PDU_BUF_SIZE] and in the checks with '4095' below.
isotpsniffer.c
Outdated
| if(!noquit) | ||
| goto out; | ||
| } | ||
| if (nbytes > 4095) { |
There was a problem hiding this comment.
if (nbytes > PDU_BUF_SIZE - 1)
isotpsniffer.c
Outdated
| if(!noquit) | ||
| goto out; | ||
| } | ||
| if (nbytes > 4095) { |
There was a problem hiding this comment.
if (nbytes > PDU_BUF_SIZE - 1)
isotpsniffer.c
Outdated
| } | ||
| break; | ||
|
|
||
| case 'q': |
|
Sorry for the mess in this review. It was the first time where I not only added single comments but used the "start a review" button ... Thanks for the contribution! |
|
Provided changes you requested - sorry that it took so long |
|
Sorry for the force push. It was non-intentional change, I've modified github actions script on my fork and forgot that it will go also to this PR (facepalm). Force push reverted it to previous state |
| if (nbytes > (PDU_BUF_SIZE - 1)) { | ||
| r = 1; | ||
| perror("read socket s too much data"); | ||
| fprintf(stderr, "PDU length %d longer than PDU buffer: %s\n", nbytes, strerror(errno)); |
There was a problem hiding this comment.
fprintf(stderr, "PDU length %d longer than PDU buffer size %d\n", nbytes, PDU_BUF_SIZE - 1);
(same applies for line 406)
Additionally please set PDU_BUF_SIZE to 8300 as suggested in my previous review.
Can you finally please put all these things into one single patch for the PR.
If this turns out to be too complicated, feel free to create a new PR.
Many thanks!
marckleinebudde
left a comment
There was a problem hiding this comment.
....and as Oliver suggested, please merge both patches.
| #include <linux/can.h> | ||
| #include <linux/can/isotp.h> | ||
| #include <linux/sockios.h> | ||
| #include <errno.h> |
There was a problem hiding this comment.
please sort alphabetically
isotpsniffer.c
Outdated
| int noquit = 0; | ||
| int ignore_errors = 0; |
| case 'q': | ||
| noquit = 1; | ||
| case 'i': | ||
| ignore_errors = 1; |
Hello,
I was working with isotpsniffer, and found out that if invalid / incomplete / malformed iso tp message is received, isotpsniffer immediately quits:
This wasn't desired behaviour, as I had to use malformed frames for target debugging purposes
This PR address this issue and adds additional command line option (-q) to continue receiving if read command returns -1
As side effect, when socket is closed while isotpsniffer is working, isotpsniffer will NOT exit - that's why this is added as option, not default behaviour:
I see possibility to make decision about exit basing on errno value. What do you think about that? Any comments appreciated.