net: added ng_udp implementation#2430
Conversation
346a286 to
62fe254
Compare
There was a problem hiding this comment.
Since there should only be one UDP thread it might be worth thinking about making this public.
I'm still not 100% sure, but thinking about it I came to 2 different solutions:
I more or less assumed the user application is setting this in the UDP header, also using some |
There was a problem hiding this comment.
Since port 0 is reserved, we maybe should use uint32_t as demux type and go to 0x10000 for ALL.
There was a problem hiding this comment.
I think exactly because it is reserved, we can use the 0 internally for "everyone who is interested in UDP general"...
And the pkt->type in the line above would be IP...
There was a problem hiding this comment.
And the pkt->type in the line above would be IP...
Ah, sure… but in context of #2430 (comment): can we be sure of this?
There was a problem hiding this comment.
I think exactly because it is reserved, we can use the 0 internally for "everyone who is interested in UDP general"...
Aren't we then exceptionally vulnerable against port 0 attacks?
|
Usually the transport layer decides the source port. As the transport layer in question is UDP, it should be the decision of the UDP module how to enable this (I suggest a |
|
Why does the network layer does this oO? |
|
Because I'm stupid ;) (comment updated) |
There was a problem hiding this comment.
Shouldn't the next header be set here somewhere? At least that's what the beginning of this function implies, where you start searching for the UDP header and stop if you don't find it. If yes, how do we get the length and the type of the next header?
Or do we pre-parse the packet in the link-layer/driver? If yes: why? The link-layer/driver then has to have knowledge of all header types, or it must be stored somewhere so the driver can handle it. And I'm wondering why we do it so complicated.
Can the UDP port change in "one transmission"? (since one transmission in UDP is normally exactly one packet, I think I know the answer :D) |
|
What do you mean with "one transmission"? At least for IPv4 you can have several fragmented IP packets for the same UDP datagram. |
|
I'm not sure either. I guess I meant a stream of data (yes I know there are streams in UDP)… Was more or less a brainfart. |
Since the Src[Port:IP]-Dst[Port:IP] tuple is an End-To-End connection, the port cannot change for "one transmission". However, after this transmission, a new Src[Port:IP]-Dst[Port:IP] tuple can be generated aka a new Socket can be created to serve as the new communication endpoint :) |
Since the fragmentation is below UDP, the port is fixed |
|
Sure, but can it be reused for a new "connection" to the same destination in parallel? |
No, once fixed to a socket a port cannot be reused if the respective socket was not closed. And a good implementation should not take the port immediatly after closing, but choose a random one thereafter |
|
That is why we need to keep track of the (source) ports in use. I thought the respective layer was a good point to do so. |
👍 |
I recently thought about this and came to the conclusion that it seems actually the most sensible to me to do the upper layer checksum calculation directly in IP itself. IP has to know about the upper layer anyway and it knows the correct source address, so there's no advantage of doing it in the upper layer (and having a probability that is has to be done again in IP). |
So we do the callback solution. Will find something in my IPv6 implementation :-) |
|
Actually, I was not talking about callbacks. Seems overkill to me, if the same function is called for every upper layer anyway. |
sys/include/net/ng_udp.h
Outdated
There was a problem hiding this comment.
I always think these macros are kind of redundant. The same value can be retrieved with sizeof(ng_udp_hdr_t) (and it is more portable).
There was a problem hiding this comment.
I'm staying with my redundancy argument. :D
|
ACK if travis is happy. |
|
lets merge this as is (otherwise it gets a neverending story) and then feel free to PR that change. Sound reasonable? |
|
👍 |
|
Sure, I didn't intend to stall anything. I have been using ng_udp for about a week now in mostly this form and it worked very well. |
sys/include/net/ng_udp.h
Outdated
There was a problem hiding this comment.
Doxygen has a problem finding the reference to NG_NETTYPE_UDP, since MODULE_NG_UDP in its scope is not defined.
Solutions for that: |
There was a problem hiding this comment.
#ifdef __cplusplus
}
#endifmissing
|
fixed issues (doxygen, indention, cplusplus closing bracket, param checking when sending) and rebased. |
|
Re-ACK |
|
(please SQUASH) |
|
squashed |
There was a problem hiding this comment.
cppcheck is complaining about len not being used for the #ifndef MODULE_NG_IPV6 build-path.
sys/net/transport_layer/ng_udp/ng_udp.c:71: style (unreadVariable): Variable 'len' is assigned a value that is never used.
we can fix this after merge, or you add a (void)len to this case and squash.
|
now cppcheck shouldn't complain anymore |
|
It doesn't => finally go! |
net: added ng_udp implementation
|
this was an easy one :-) |
this PR depends on many other
ng_PRs, will detail them out once this PR gets in a state of being testable/reviewable. I will try to provide a first approach for a socket implementation to make this code better understandable.While writing this code, I came across some issues we should think about:
1. how do we handle the checksum calculation when sending data and the src address is still unknown?2. where do we get the source port from, if not using sockets but talking directly to UDP via NETAPI?UPDATE: This implementation is now ready for testing
UPDATE 2: rebased on #2801