Skip to content

Bugs in if_nametoindex/if_indextoname #1096

@wkozaczuk

Description

@wkozaczuk

The implementation of if_nametoindex()/if_indextoname() copied from musl under libc/network/if_nametoindex.c and libc/network/if_indextoname.c has number of problems:

  1. Both use AF_UNIX domain which is unsupported on OSv (see fd = socket(AF_UNIX, SOCK_DGRAM, 0)); instead we neeed to use AF_INET like if_nameindex uses - see c4df104)
  2. Even after fixing the above, if_nametoindex returns strangely high number like 1082589186 for eth0 and 1082589185 for lo0; most likely it is caused by not zero-ing the index field (for example zeroing ifr.ifr_ifindex in if_nametoindex.c before calling ioctl() makes the code return correct 2 and 1 index; the correct fix should be somewhere in bsd/linuz compatibility layer code (bsd/sys/compat/linux/linux_ioctl.cc or bsd/sys/kern/sys_socket.cc or bsd/sys/net/if.cc).
  3. The if_indextoname needs support in ioctl layer (see missing handling of SIOCGIFNAME in bsd/sys/compat/linux/linux_ioctl.cc).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions