History

net: Add new protocol attribute to IP addresses

This patch adds a new protocol attribute to IPv4 and IPv6 addresses. Inspiration was taken from the protocol attribute of routes. User space applications like iproute2 can set/get the protocol with the Netlink API. The attribute is stored as an 8-bit unsigned integer. The protocol attribute is set by kernel for these categories: - IPv4 and IPv6 loopback addresses - IPv6 addresses generated from router announcements - IPv6 link local addresses User space may pass custom protocols, not defined by the kernel. Grouping addresses on their origin is useful in scenarios where you want to distinguish between addresses based on who added them, e.g. kernel vs. user space. Tagging addresses with a string label is an existing feature that could be used as a solution. Unfortunately the max length of a label is 15 characters, and for compatibility reasons the label must be prefixed with the name of the device followed by a colon. Since device names also have a max length of 15 characters, only -1 characters is guaranteed to be available for any origin tag, which is not that much. A reference implementation of user space setting and getting protocols is available for iproute2: https://github.com/westermo/iproute2/commit/9a6ea18bd79f47f293e5edc7780f315ea42ff540

Jacques de Laval committed 4 years ago

Commit 47f0bd51 parent 6e2e59e6 files · +41 −7Browse files

Showing the changes to include/uapi (1 of 6 files). Show all

Unified · Split

include/uapi/linux/if_addr.h+8−1
@@ -33,8 +33,9 @@ enum { · 32 unmodified lines
3333 IFA_CACHEINFO,
3434 IFA_MULTICAST,
3535 IFA_FLAGS,
36− IFA_RT_PRIORITY, /* u32, priority/metric for prefix route */
36+ IFA_RT_PRIORITY, /* u32, priority/metric for prefix route */
3737 IFA_TARGET_NETNSID,
38+ IFA_PROTO, /* u8, address protocol */
3839 __IFA_MAX,
3940 };
4041
@@ -69,4 +70,10 @@ struct ifa_cacheinfo { · 28 unmodified lines
6970 #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
7071 #endif
7172
73+/* ifa_proto */
74+#define IFAPROT_UNSPEC 0
75+#define IFAPROT_KERNEL_LO 1 /* loopback */
76+#define IFAPROT_KERNEL_RA 2 /* set by kernel from router announcement */
77+#define IFAPROT_KERNEL_LL 3 /* link-local set by kernel */
78+
7279 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t