xref: /freebsd/sys/netlink/route/ifaddrs.h (revision 3d6a94db1010319dc65736100089d6dd5ff90e46)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 /*
29  * Interface address-related (RTM_<NEW|DEL|GET>ADDR) message header and attributes.
30  */
31 
32 #ifndef _NETLINK_ROUTE_IFADDRS_H_
33 #define _NETLINK_ROUTE_IFADDRS_H_
34 
35 /* Base header for all of the relevant messages */
36 struct ifaddrmsg {
37 	uint8_t		ifa_family;	/* Address family */
38 	uint8_t		ifa_prefixlen;	/* Prefix length */
39 	uint8_t		ifa_flags;	/* Address-specific flags */
40 	uint8_t		ifa_scope;	/* Address scope */
41 	uint32_t	ifa_index;	/* Link ifindex */
42 };
43 
44 #ifndef _KERNEL
45 #define	_NL_IFA_HDRLEN		((int)sizeof(struct ifaddrmsg))
46 #define	IFA_RTA(_ifa)		((struct rtattr *)(NL_ITEM_DATA(_ifa, _NL_IFA_HDRLEN)))
47 #define	IFA_PAYLOAD(_hdr)	NLMSG_PAYLOAD(_hdr, _NL_IFA_HDRLEN)
48 #endif
49 
50 /* Defined attributes */
51 enum {
52 	IFA_UNSPEC,
53 	IFA_ADDRESS		= 1, /* binary, prefix address (destination for p2p) */
54 	IFA_LOCAL		= 2, /* binary, interface address */
55 	IFA_LABEL		= 3, /* string, interface name */
56 	IFA_BROADCAST		= 4, /* binary, broadcast ifa */
57 	IFA_ANYCAST		= 5, /* not supported */
58 	IFA_CACHEINFO		= 6, /* not supported */
59 	IFA_MULTICAST		= 7, /* not supported */
60 	IFA_FLAGS		= 8, /* not supported */
61 	IFA_RT_PRIORITY		= 9, /* not supported */
62 	IFA_TARGET_NETNSID	= 10, /* not supported */
63 	IFA_FREEBSD		= 11, /* nested, FreeBSD-specific */
64 	__IFA_MAX,
65 };
66 #define IFA_MAX		(__IFA_MAX - 1)
67 
68 enum {
69 	IFAF_UNSPEC,
70 	IFAF_VHID		= 1, /* u32: carp vhid */
71 	IFAF_FLAGS		= 2, /* u32: FreeBSD-specific ifa flags */
72 	__IFAF_MAX,
73 };
74 #define IFAF_MAX	(__IFAF_MAX - 1)
75 
76 /* IFA_FLAGS attribute flags */
77 #define IFA_F_SECONDARY		0x0001
78 #define IFA_F_TEMPORARY		IFA_F_SECONDARY
79 #define IFA_F_NODAD		0x0002
80 #define IFA_F_OPTIMISTIC	0x0004
81 #define IFA_F_DADFAILED		0x0008
82 #define IFA_F_HOMEADDRESS	0x0010
83 #define IFA_F_DEPRECATED	0x0020
84 #define IFA_F_TENTATIVE		0x0040
85 #define IFA_F_PERMANENT		0x0080
86 #define IFA_F_MANAGETEMPADDR	0x0100
87 #define IFA_F_NOPREFIXROUTE	0x0200
88 #define IFA_F_MCAUTOJOIN	0x0400
89 #define IFA_F_STABLE_PRIVACY	0x0800
90 
91 /* IFA_CACHEINFO value */
92 struct ifa_cacheinfo {
93 	uint32_t ifa_prefered;	/* seconds till the end of the prefix considered preferred */
94 	uint32_t ifa_valid;	/* seconds till the end of the prefix considered valid */
95 	uint32_t cstamp;	/* creation time in 1ms intervals from the boot time */
96 	uint32_t tstamp;	/* update time in 1ms intervals from the boot time */
97 };
98 
99 #endif
100