Skip to content

MacOS route netmasks are read incorrectly due to alignment issue, causing only default route to work #4894

@jhogg

Description

@jhogg

Brief description

MacOS is incorrectly populating the netmask in sockattr.sa_data for routes.

Instead of being left-justified in the buffer and little endian (current NetBSD setting), it is right justified in a 4-byte word aligned buffer and big endian.

This results in the routing only working for default route or named interfaces.

Patch being submitted to correct this issue.

Scapy version

2.7.0dev1 (and prior back to at least 2019)

Python version

3.10

Operating system

MacOS 10.15 through 14 (at least) on Intel

Additional environment information

No response

How to reproduce

Load scapy on MacOS and print(conf.route).

I've seen this in tickets from 2019 to current.

Actual result

Note the netmasks are wrong.

Network          Netmask          Gateway       Iface  Output IP      Metric
0.0.0.0          0.0.0.0          172.31.1.243  en0    172.31.1.155   1     
127.0.0.0        0.255.255.255    127.0.0.1     lo0    127.0.0.1      1     
169.254.0.0      255.255.255.255  0.0.0.0       en0    172.31.1.155   1     
169.254.0.0      255.255.255.255  0.0.0.0       en19   172.30.11.107  1     
172.16.0.0       240.255.255.255  172.30.11.5   en19   172.30.11.107  1     
172.30.11.0      255.255.255.255  0.0.0.0       en19   172.30.11.107  1     
172.30.11.107    255.255.255.255  0.0.0.0       en19   172.30.11.107  1     
172.30.11.255    255.255.255.255  0.0.0.0       en19   172.30.11.107  1     
172.31.1.0       255.255.255.255  0.0.0.0       en0    172.31.1.155   1     
172.31.1.155     255.255.255.255  0.0.0.0       en0    172.31.1.155   1     
172.31.1.243     255.255.255.255  0.0.0.0       en0    172.31.1.155   1     
172.31.1.255     255.255.255.255  0.0.0.0       en0    172.31.1.155   1     
224.0.0.0        0.240.255.255    0.0.0.0       en0    172.31.1.155   1     
224.0.0.0        0.240.255.255    0.0.0.0       en19   172.30.11.107  1     
255.255.255.255  255.255.255.255  0.0.0.0       en0    172.31.1.155   1     
255.255.255.255  255.255.255.255  0.0.0.0       en0    172.31.1.155   1     
255.255.255.255  255.255.255.255  0.0.0.0       en19   172.30.11.107  1     

Expected result

Network          Netmask          Gateway      Iface  Output IP      Metric
127.0.0.0        255.0.0.0        127.0.0.1    lo0    127.0.0.1      1     
169.254.0.0      255.255.0.0      0.0.0.0      en0    172.31.1.155   1     
169.254.0.0      255.255.0.0      0.0.0.0      en19   172.30.11.107  1     
172.16.0.0       255.240.0.0      172.30.11.5  en19   172.30.11.107  1     
172.30.11.0      255.255.255.0    0.0.0.0      en19   172.30.11.107  1     
172.30.11.107    255.255.255.255  0.0.0.0      en19   172.30.11.107  1     
172.30.11.255    255.255.255.255  0.0.0.0      en19   172.30.11.107  1     
172.31.1.0       255.255.255.0    0.0.0.0      en0    172.31.1.155   1     
172.31.1.155     255.255.255.255  0.0.0.0      en0    172.31.1.155   1     
172.31.1.243     255.255.255.255  0.0.0.0      en0    172.31.1.155   1     
172.31.1.255     255.255.255.255  0.0.0.0      en0    172.31.1.155   1     
224.0.0.0        240.0.0.0        0.0.0.0      en0    172.31.1.155   1     
224.0.0.0        240.0.0.0        0.0.0.0      en19   172.30.11.107  1     
255.255.255.255  255.255.255.255  0.0.0.0      en0    172.31.1.155   1     
255.255.255.255  255.255.255.255  0.0.0.0      en0    172.31.1.155   1     
255.255.255.255  255.255.255.255  0.0.0.0      en19   172.30.11.107  1     

Related resources

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions