Replacing AF_UNIX with AF_INET in those 2 files is not enough.

Firstly, if_nametoindex behaves weirdly:

--> (1st call)  Index of eth0: 1082589186, errno:2
--> (2nd call) Index of eth0: 2, errno:2

So it seems to fail in 2 consecutive calls each time and sets errno to 
ENENT but each time returns different index. Or maybe it does succeed but 
why return different index each time.

Now calling if_indextoname fails for both indexes and I think it happens 
because we do not handle SIOCGIFNAME 
in bsd/sys/compat/linux/linux_ioctl.cc, do we? 

Waldek

On Thursday, August 13, 2020 at 12:18:20 PM UTC-4 Waldek Kozaczuk wrote:

> Those two issues give more context - 
> https://github.com/cloudius-systems/osv/issues/355 and 
> https://github.com/cloudius-systems/osv/issues/351.
>
> On Thursday, August 13, 2020 at 12:10:25 PM UTC-4 Waldek Kozaczuk wrote:
>
>> As I have been working on trying to reduce files copied from musl, 
>> specifically those that use syscall by using the macro approach I described 
>> earlier, I have come across 3 files that use syscall but also use socket() 
>> call differently than musl.
>>
>> And I think we have a problem in 2 of those.
>>
>> In this commit 
>> https://github.com/cloudius-systems/osv/commit/c4df1043285b7597709f5199d619658909a22794,
>>  
>> Nadav copied if_nameindex.c from musl into libc/network but also changed 
>> socket call like this:
>>
>> <       int s = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
>> ---
>> >       int s = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);
>>
>> because AF_UNIX domain is not supported in OSv (read the commit).
>>
>> Now 2 other files - if_indextoname.c, if_nametoindex.c - have socket() 
>> call that uses AF_UNIX which most likely (we do not have unit tests for 
>> these) fails:
>>
>> socket(AF_UNIX, SOCK_DGRAM, 0))
>>
>> So I think we should change AF_UNIX to AF_INET in those as well, right?
>>
>> Also it seems these 2 files were copied from older musl and new musl adds 
>> protocol option  SOCK_CLOEXEC and there is no reason we should have it 
>> different - see this diff between OSv and musl:
>>
>> DIFF: [/network/if_indextoname.c]
>> 6c6
>> < #include "syscall.h"
>> ---
>> > #include "unistd.h"
>> 13c13
>> <       if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) 
>> return 0;
>> ---
>> >       if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) return 0;
>> 16c16
>> <       __syscall(SYS_close, fd);
>> ---
>> >       close(fd);
>>
>> Finally, I think we can solve the socket call changes (AF_UNIX->AF_INET) 
>> with --include libc/network/socket_mod.h option where this header looks 
>> like so:
>>
>> #include <sys/socket.h>
>> #undef socket
>> #define socket(domain,type,protocol) socket(AF_INET,type,protocol)
>>
>> We should also enhance existing tests/tst-ifaddrs.cc to test 
>> if_indextoname and if_nametoindex.
>>
>> Waldek
>>
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/fffe9fcc-9a5e-47fc-81c1-cfacf6dad8e1n%40googlegroups.com.

Reply via email to