-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isotpsniffer: option for no quitting on invalid message received #550
base: master
Are you sure you want to change the base?
Conversation
isotpsniffer.c
Outdated
@@ -79,6 +79,7 @@ void print_usage(char *prg) | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to use '-i' analog to cangen:
-i (ignore syscall errors to receive malformed PDUs)
isotpsniffer.c
Outdated
@@ -189,6 +190,7 @@ int main(int argc, char **argv) | |||
int head = 0; | |||
int timestamp = 0; | |||
int format = FORMAT_DEFAULT; | |||
int noquit = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -371,29 +377,35 @@ int main(int argc, char **argv) | |||
if (nbytes < 0) { | |||
perror("read socket s"); | |||
r = 1; | |||
goto out; | |||
if(!noquit) | |||
goto out; | |||
} | |||
if (nbytes > 4095) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (nbytes > PDU_BUF_SIZE - 1)
isotpsniffer.c
Outdated
} | ||
|
||
if (FD_ISSET(t, &rdfs)) { | ||
nbytes = read(t, buffer, 4096); | ||
if (nbytes < 0) { | ||
perror("read socket t"); | ||
r = 1; | ||
goto out; | ||
if(!noquit) | ||
goto out; | ||
} | ||
if (nbytes > 4095) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (nbytes > PDU_BUF_SIZE - 1)
isotpsniffer.c
Outdated
@@ -249,6 +251,10 @@ int main(int argc, char **argv) | |||
} | |||
break; | |||
|
|||
case 'q': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-i ...
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 |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
....and as Oliver suggested, please merge both patches.
@@ -59,13 +59,16 @@ | |||
#include <linux/can.h> | |||
#include <linux/can/isotp.h> | |||
#include <linux/sockios.h> | |||
#include <errno.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please sort alphabetically
int noquit = 0; | ||
int ignore_errors = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool
case 'q': | ||
noquit = 1; | ||
case 'i': | ||
ignore_errors = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
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.