-
Notifications
You must be signed in to change notification settings - Fork 2.1k
netif: Initial import of a common network interface API (second try) #8841
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
Conversation
sys/net/gnrc/netif/_netif.c
Outdated
if (netif != NULL) { | ||
res += fmt_str(name, "if"); | ||
res += fmt_u16_dec(&name[res], netif->pid); | ||
} |
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.
does this need to be null-terminated?
sys/net/gnrc/netif/_netif.c
Outdated
{ | ||
gnrc_netif_t *netif = NULL; | ||
|
||
if ((strlen(name) > 2) && (name[0] == 'i') && (name[1] == 'f')) { |
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 (strncmp(name, "if", 2) == 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.
I have the feeling this would result in bigger code size, but I agree that this is better readable.
sys/net/gnrc/netif/_netif.c
Outdated
|
||
if ((strlen(name) > 2) && (name[0] == 'i') && (name[1] == 'f')) { | ||
while ((netif = gnrc_netif_iter(netif)) != NULL) { | ||
char pidstr[2]; |
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 think it would be more efficient to convert the pid part of name
to uint16 before the loop and then compare within the loop:
uint16_t _pid = scn_u32_dec(&name[2], 2));
if (_pid) {
while ((netif = gnrc_netif_iter(netif)) != NULL) {
if (_pid == netif->pid) {
return (netif_t) _pid);
}
}
sys/include/net/netif.h
Outdated
/** | ||
* @brief Network interface enumeration type | ||
*/ | ||
typedef intptr_t netif_t; |
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 this typedef would be in the stack-specific implementation part, the API would be way more flexible.
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.
Agreed, I wanted to do this after thinking about it a bit anyway ;-)
Maybe an interface like this makes more sense with specific functions instead of netopt get/set? |
Does it? This would explode the API to a lot of functions (as well as the adaption layer, remember: for most stacks this is mostly piped through to the |
Addressed comments. |
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 like the idea of having a common interface to interact with different network interfaces. I am questioning the benefit of the gnrc specific netif_get_name()
function, though .. IMO interface names are meant for a better user experience. Just converting a 0
to an if0
isn't cutting it. I'd suggest something like wpan0
, eth0
, ... instead. I am not blocking this PR because of such trivialities, though.
Regarding @kaspar030's comment: I am leaning more towards @miri64's answer. Having a getter/setter for each option in the API will produce clutter.
So, I suggest we get this merged as soon as my minor doc related comments are addressed.
* @return next network interface. | ||
* @return @ref NETIF_INVALID, if there is no interface after @p last | ||
*/ | ||
netif_t netif_iter(netif_t last); |
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.
doxygen will certainly complain here, because last
is undocumented.
sys/include/net/netif.h
Outdated
* | ||
* @param[in] netif A network interface. | ||
* @param[out] name The name of the interface. Must not be `NULL`. Must at least | ||
* hold @ref NETIF_NAMELENMAX bytes. |
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'd like a note here, that name
must be null-terminated afterwards. At least this is what the gnrc specific function is doing.
sys/include/net/netif.h
Outdated
* | ||
* @note Supposed to be implemented by the networking module | ||
* | ||
* @param[in] name The name of an interface. Must not be `NULL`. |
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.
Here again I would expect a note about null-termination. The GNRC specific function doesn't need this, e.g., but another network stack may depend on it.
Ok, I thought about it, me too. 😄 |
Wanna dismiss your review then? (: |
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.
untested ACK.
Since this would require some extra logic, I could prefer to do this as a feature later-on if it is wanted. |
@cgundogan I addressed your and Travis' comments. |
@miri64 okay, looks good. please squash |
adf7ab7
to
21427fe
Compare
Squashed |
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.
ACK
21427fe
to
f97db64
Compare
Fixed murdock issues. |
Only failing tests were |
Contribution description
This is a way simpler redo of #6413. There is no network interface initialization (yet), but I plan to provide one in a follow-up. This PR just focusses on names, options and a exemplary GNRC implementation.
Issues/PRs references
Supersedes #6413.