shell_commands: adapt ping6 to original-ping-like implementation#9523
Conversation
b887d79 to
e36c0cd
Compare
|
(I originally looked at the busybox-implementation [that's where the original title of this PR came from, because the commit had still the name ^^"], but since that is licensed under 4-clause BSD and thus incompatible to (L)GPL, I needed to dig deeper and was able to reconstruct my own version from the original ping's source [public domain; can be found on wayback machine] and inetutil's [licensed under GPLv3] and thus my version is now rather inspired by those works than the busybox one) |
e36c0cd to
2d73d12
Compare
|
For the record: this implementation is also more efficient than the old one. On a Cortex-M4 platform it uses ~200 byte less ROM and 56 byte less RAM than the previous implementation. |
|
(picked |
a0218ec to
5dac3d3
Compare
|
I'm running it without arguments and it's spitting a stream of random bytes to the terminal. |
On which application and which board? |
|
|
|
mh curious, yesterday it was working... |
|
@jcarrano can you try again please? |
|
@miri64 Yes, it's fixed. I could run it. I can't test hoplimit because my test setup is quite simple. I'll start looking at the code. |
https://www.iot-lab.info/ ;-) |
jcarrano
left a comment
There was a problem hiding this comment.
I'm submitting a partial review of only the parsing code. The network part will take me more time as I'm not familiar with the apis.
| } | ||
| ++argv; | ||
| /* parse command line arguments */ | ||
| for (; argc > 0; argc--, argv++) { |
There was a problem hiding this comment.
I find this simultaneous decrementing and incrementing kind of fragile. Why not use an explicit index?
There was a problem hiding this comment.
For argc/argv I find this usually ok, but let me try with explicit index.
There was a problem hiding this comment.
Ok, going for explicit index.
| "of any responses, otherwise wait for two RTTs"); | ||
| } | ||
|
|
||
| static int _configure(int argc, char **argv, _ping_data_t *data) |
There was a problem hiding this comment.
ping6 -c 3 without hostname fails. I have some quite lightweight code for parsing command line arguments that I wrote several years ago. If there's interest I can bring it back to life. I think there's no point in everyone hacking together their own parser.
There was a problem hiding this comment.
I have some quite lightweight code for parsing command line arguments that I wrote several years ago. If there's interest I can bring it back to life. I think there's no point in everyone hacking together their own parser.
While I agree, but that opens a similar can of worms as the POSIX networking part, as some libc-variants already provide getopt and some don't. Since the shell is purely a debugging feature (and shell commands should also have as less dependencies as possible), I'd rather prefer every shell command to handle parsing for itself.
There was a problem hiding this comment.
getopt posix-only, and does not support long options (getopt_long is a GNU extension).
I'd rather prefer every shell command to handle parsing for itself.
I would rephrase that as "I'd prefer every shell command to have it's own parsing bugs".
There was a problem hiding this comment.
getopt posix-only, and does not support long options (getopt_long is a GNU extension).
At least my version of newlib supports it:
$ grep -R getopt /usr/arm-none-eabi/include/
/usr/arm-none-eabi/include/getopt.h:getopt.h - Read command line options
/usr/arm-none-eabi/include/getopt.h:The getopt() function parses the command line arguments. Its arguments argc
/usr/arm-none-eabi/include/getopt.h:The getopt_long() function works like getopt() except that it also accepts
/usr/arm-none-eabi/include/getopt.h:The getopt() function returns the option character if the option was found
/usr/arm-none-eabi/include/getopt.h:The getopt_long() function's return value is described below.
/usr/arm-none-eabi/include/getopt.h:The function getopt_long_only() is identical to getopt_long(), except that a
/usr/arm-none-eabi/include/getopt.h:getopt() and friends to return EOF with optind != argc.
/usr/arm-none-eabi/include/getopt.h:This file and the accompanying getopt.c implementation file are hereby
/usr/arm-none-eabi/include/getopt.h: int *flag; /* determines if getopt_long() returns a
/usr/arm-none-eabi/include/getopt.h:/* While getopt.h is a glibc extension, the following are newlib extensions.
/usr/arm-none-eabi/include/getopt.h: * They are optionally included via the __need_getopt_newlib flag. */
/usr/arm-none-eabi/include/getopt.h:#ifdef __need_getopt_newlib
/usr/arm-none-eabi/include/getopt.h: allocated variable of type struct getopt_data. */
/usr/arm-none-eabi/include/getopt.h: #define getopt_r __getopt_r
/usr/arm-none-eabi/include/getopt.h: #define getopt_long_r __getopt_long_r
/usr/arm-none-eabi/include/getopt.h: #define getopt_long_only_r __getopt_long_only_r
/usr/arm-none-eabi/include/getopt.h: /* The getopt_data structure is for reentrancy. Its members are similar to
/usr/arm-none-eabi/include/getopt.h: typedef struct getopt_data
/usr/arm-none-eabi/include/getopt.h: } getopt_data;
/usr/arm-none-eabi/include/getopt.h:#endif /* __need_getopt_newlib */
/usr/arm-none-eabi/include/getopt.h: int _EXFUN (getopt,
/usr/arm-none-eabi/include/getopt.h: int _EXFUN (getopt_long,
/usr/arm-none-eabi/include/getopt.h: int _EXFUN (getopt_long_only,
/usr/arm-none-eabi/include/getopt.h:#ifdef __need_getopt_newlib
/usr/arm-none-eabi/include/getopt.h: int _EXFUN (__getopt_r,
/usr/arm-none-eabi/include/getopt.h: struct getopt_data * __data));
/usr/arm-none-eabi/include/getopt.h: int _EXFUN (__getopt_long_r,
/usr/arm-none-eabi/include/getopt.h: struct getopt_data * __data));
/usr/arm-none-eabi/include/getopt.h: int _EXFUN (__getopt_long_only_r,
/usr/arm-none-eabi/include/getopt.h: struct getopt_data * __data));
/usr/arm-none-eabi/include/getopt.h:#endif /* __need_getopt_newlib */
/usr/arm-none-eabi/include/getopt.h:/* END OF FILE getopt.h */
/usr/arm-none-eabi/include/sys/unistd.h:# include <getopt.h>
/usr/arm-none-eabi/include/sys/unistd.h:extern char *optarg; /* getopt(3) external variables */
/usr/arm-none-eabi/include/sys/unistd.h:int getopt(int, char * const [], const char *);
/usr/arm-none-eabi/include/sys/unistd.h:extern int optreset; /* getopt(3) external variable */
Compare e.g. AVRlibc:
$ grep -R getopt /usr/lib/avr/include/
|
|
@cgundogan maybe you can test this on IoTLab? |
|
ping @jcarrano |
|
@miri64 I was not able to perform the test. I would have to learn how to use IOTLab and I'm lacking time ATM. |
|
@jcarrano you can also use two native nodes or two of the many IEEE 802.15.4 capable nodes on your desk ;-) |
|
@miri64 Sorry for leaving this PR hanging. I have since given up reviewing network-related stuff which, not being in my main area of expertise, takes me too much time while I have little to offer in terms of a valuable review. My own reviews in this PR were mainly related to command line parsing, and they have been addressed, so I will dismiss myself if you don't mind. |
Sure. I understand. |
5bbaa96 to
90a621b
Compare
|
Rebased to current master. Also allowed for delay of |
|
@miri64 I have tested the |
The man page to
So I would say it's redundant in a pure IPv6 scenario. |
Yes, was just a question whether we should have it in addition to the |
I'd say no. One way to define the interface is enough IMHO (contrary to iputil's ping you can also use the |
| goto finish; | ||
| default: | ||
| /* requeue wrong packets */ | ||
| msg_send(&msg, sched_active_pid); |
There was a problem hiding this comment.
What other messages can appear here? Shouldn't they be dropped instead of requeued? I can't see another msg_recv anywhere here that handles other types of messages, so the queue would get full with garbage ..
There was a problem hiding this comment.
I can research that, but on first glance I would say: remember that this is the main thread. Other application specific messages might land in the queue.
There was a problem hiding this comment.
(I did it because the current version in master does it as well:
RIOT/sys/shell/commands/sc_icmpv6_echo.c
Lines 302 to 305 in 1d69340
There was a problem hiding this comment.
remember that this is the main thread. Other application specific messages might land in the queue.
yes, sounds sensible. Please research that anyway (:
There was a problem hiding this comment.
Ok, I had in memory, that this line existed because someone asked for it, but apparently I introduced it myself in #2555. Anyway, given that this is main and that we didn't face any problems with this until now, I think the line is here correctly.
|
squashing needed |
We should this however do in a follow-up IMHO |
|
Squashed |
90a621b to
1ec9591
Compare
Loosely based on [the original ping] and [netutil]'s ping New features (compared to old RIOT version): - non-positional parameters - Better duplicate detection (addresses RIOT-OS#9387) - Better asynchronous behavior - Potential for future move to `sock_ip` - (Optional) DNS-support - Multithreading-safe (in case shell-command handler gets called from multiple threads) [the original ping]: http://ftp.arl.army.mil/~mike/ping.html [netutil]: https://www.gnu.org/software/inetutils/
1ec9591 to
45ec766
Compare
|
And rebased. |
|
Alright. Murdock also agrees! |
@cgundogan the wiki page you referenced is already marked as outdated. Should we really fix it there? (all other occurrences I found, I fixed). |
|
(it even mentions |
Contribution description
Loosely based on the original ping and netutil's ping
New features (compared to old RIOT version):
ping6doesn't display duplicate packages #9387)sock_ipfrom multiple threads)
Issues/PRs references
Resolves #9387.