-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Make mcast/bcast consistent across stacks #3382
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
|
So we have a new API function mg_multicast_restore and the only thing it does, it copies into c->rem? |
If we don't do something like that, then, users have to either save or re-generate the MAC themselves, but only for net_builtin. Then, multicast/broadcast user code will be different when using net_builtin. The other way I can think of is to check on every send, it is way less efficient as we're penalizing regular unicast UDP traffic, AND, the "hack" is still needed at the IP level. |
|
What is the anticipated usage of mg_multicast_restore() ? Could you drop a little snippet that demonstrates it please? |
mongoose/tutorials/udp/ssdp-search/main.c Lines 31 to 35 in 9280110
Line 507 in 9280110
|
|
Ok LGTM |
Well, it is not c-> but the mDNS request struct, which is by definition multicast (hence the 'm'). The non-usual case is when the request is explicit to perform a unicast response instead of the usual standard multicast response; so the name and usage. |
Fix net_builtin inconsistency
When working with UDP multicast/broadcast, we can send to a multicast/broadcast address and get unicast or multicast/broadcast responses.
When getting a response,
c->remgets filled with the respondent IP data.To be able to send multicast/broadcast again, we need to copy back to
c->remthe original IP information.mg_connect: we instruct to savec->remcontents somewhere (e.g.:c->data), and then copy back (SSDP tutorial)mg_listen: we can copy back fromc->loc, that's what our mDNS code doesWith net_builtin, the same happens with the l2addr (MAC); if we don't restore it, we end up sending to the multicast/broadcast IP but to the requester MAC (mDNS, this just works but is wrong), or last respondent MAC (SSDP, blatantly wrong).
The fix is simple, but, in this case, it is not necessary to save the MAC, as it can be mapped (again) from the multicast/broadcast IP.
So, to keep consistency across stacks, we add
mg_multicast_restore(c, from). This is the function to be called in both cases. Internally, this function copiesfrom-->c->remand for net_builtin also maps the MAC again.