On Mon, Dec 5, 2016 at 11:15 AM, Hans Leidekker hans@codeweavers.com wrote:
This doesn't work for a /25 network, for example. You really need to use the network mask here to calculate the broadcast address.
Hi, thanks for the review. As I wrote in the comments this is the most common estimate, it should be enough for the majority of home networks everywhere. So far there is only one application affected too which is a game. Checking if every packet is UDP and if every UDP packet is not in broadcast state and then checking if its address is a broadcast would be take too much time in a operation that has to be very fast. Unless I'm missing something as I said in the first version of the patch.
You are trading correctness for performance, and even with this filter the getsockopt calls are probably too expensive. I guess this information should somehow be cached.
I agree with you, it is a tradeoff. The filter is fast because the patch reduces the scope of the test to only a few handful of packets that are probably broadcast addresses, only then it will check the broadcast flag and in the kernel this is very fast because judging by the kernel source code. Only if previous conditions are met it will check if it really was a broadcast address.
A different approach would be to let it hit EACCES when sending and check for the error and only then do all tests, that would still work and still be only a handful of packets but then we could check for the broadcast address everytime without suffering from performance and getting perfect correctness. What do you think?