Skip to content
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

route: fix address parsing of messages on Darwin #220

Commits on Sep 5, 2024

  1. route: fix address parsing of messages on Darwin

    sizeofSockaddrInet is 16, but first byte of sockaddr specifies actual
    size of sockaddr.
    
    Although, 16 works for most cases, it fails for Netmasks addresses. On
    Darwin only the significant bits of the netmask are in the msg.
    
    Take this route message as an example
    
    ```
    // rt_msg_hdr
    88 00 05 01 00 00 00 00
    41 08 00 00 07 00 00 00
    92 7b 00 00 01 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00
    
    // metrics
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    
    // SOCKADDRS - DST  (100.113.0.0)
    10 02 00 00 64 71 00 00
    00 00 00 00 00 00 00 00
    
    // GW  utun4319
    14 12 21 00 01 08 00 00
    75 74 75 6e 34 33 31 39
    00 00 00 00
    
    // NETMASK 255.255.0.0
    06 02 00 00 ff ff
    
    // NULL
    00 00
    ```
    
    i.e. ipv4
    ```
    06 02 00 00 ff ff
    ```
    
    The above byte sequence is for a sockaddr that is 6 bytes long
    representing an ipv4 for address that is 255.255.0.0.
    
    i.e. ipv6 netmask
    ```
    0e 1e 00 00 00 00 00 00 ff ff ff ff ff ff 00 00
    ```
    
    The above is `/48` netmask that should also be parsed using `b[0]` of the
    sockaddr that contains the length.
    
    Confirmed by using `route monitor`.
    
    Fixes golang/go#44740
    
    sources:
    https://github.com/apple/darwin-xnu/blob/main/bsd/net/route.h
    https://github.com/apple/darwin-xnu/blob/main/bsd/sys/socket.h#L603
    hurricanehrndz committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    61924c1 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f7b9253 View commit details
    Browse the repository at this point in the history