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

No way to differentiate between layer 3 device and loopback device #12

Open
weskoerber opened this issue Sep 12, 2024 · 2 comments · May be fixed by #13
Open

No way to differentiate between layer 3 device and loopback device #12

weskoerber opened this issue Sep 12, 2024 · 2 comments · May be fixed by #13

Comments

@weskoerber
Copy link
Owner

This is sort of a follow-up from #9.

Layer 3 network devices aren't assigned a MAC address since they're not at the physical data link layer. This can cause confusion between a MAC address that is the loopback and a MAC address that's a layer 3 device.

Consider the following:

❯ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute 
       valid_lft forever preferred_lft forever
2: tailscale0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1280 qdisc fq_codel state UNKNOWN group default qlen 500
    link/none 
    inet 100.107.149.105/32 scope global tailscale0
       valid_lft forever preferred_lft forever
    inet6 fd7a:115c:a1e0:ab12:4843:cd96:626b:9569/128 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::4c60:e0c2:4fc:cab1/64 scope link stable-privacy proto kernel_ll 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:37:65:32:3d brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

In this example, the first non-loopback device is tailscale0 whose MAC address is 00:00:00:00:00:00. How is the user supposed to know the difference between this and the loopback?

I think the data field in the MacAddress struct should be optional, and set to null if the device doesn't have a MAC address. This would disambiguate the loopback device from a layer 3 device, while also being more true to form.

However, this library is called "mac_address". If layer 3 devices do not have MAC addresses, should we even consider them at all?

@weskoerber
Copy link
Owner Author

The interface flag IFF_NOARP may identify layer 3 devices:

Via man netdevice:

              IFF_NOARP         No arp protocol, L2 destination address not set.

Also in net/if.h:

/* Standard interface flags. */
enum {
// -- snip --
    IFF_NOARP = 0x80,		/* No address resolution protocol.  */
// -- snip --
};

@weskoerber
Copy link
Owner Author

weskoerber commented Sep 12, 2024

The linux kernel explicitly zeroes out the memory for devices with IFF_LOOPBACK and IFF_NOARP flags:

https://github.com/torvalds/linux/blob/77f587896757708780a7e8792efe62939f25a5ab/net/ethernet/eth.c#L107-L110:

	if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
		eth_zero_addr(eth->h_dest);
		return ETH_HLEN;
	}

From Wikipedia on ARP:

The Address Resolution Protocol (ARP) is a communication protocol used for discovering the link layer address, such as a MAC address, associated with a given internet layer address, typically an IPv4 address.

So from all this I conclude that we can exclude devices with the IFF_NOARP flag.

@weskoerber weskoerber linked a pull request Sep 12, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant