1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI_LINUX_NEXTHOP_H
3 #define _UAPI_LINUX_NEXTHOP_H
4 
5 #include <linux/types.h>
6 
7 struct nhmsg {
8 	unsigned char	nh_family;
9 	unsigned char	nh_scope;     /* return only */
10 	unsigned char	nh_protocol;  /* Routing protocol that installed nh */
11 	unsigned char	resvd;
12 	unsigned int	nh_flags;     /* RTNH_F flags */
13 };
14 
15 /* entry in a nexthop group */
16 struct nexthop_grp {
17 	__u32	id;	  /* nexthop id - must exist */
18 	__u8	weight;   /* weight of this nexthop */
19 	__u8	weight_high;	/* high order bits of weight */
20 	__u16	resvd2;
21 };
22 
nexthop_grp_weight(const struct nexthop_grp * entry)23 static inline __u16 nexthop_grp_weight(const struct nexthop_grp *entry)
24 {
25 	return ((entry->weight_high << 8) | entry->weight) + 1;
26 }
27 
28 enum {
29 	NEXTHOP_GRP_TYPE_MPATH,  /* hash-threshold nexthop group
30 				  * default type if not specified
31 				  */
32 	NEXTHOP_GRP_TYPE_RES,    /* resilient nexthop group */
33 	__NEXTHOP_GRP_TYPE_MAX,
34 };
35 
36 #define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1)
37 
38 #define NHA_OP_FLAG_DUMP_STATS		BIT(0)
39 #define NHA_OP_FLAG_DUMP_HW_STATS	BIT(1)
40 
41 /* Response OP_FLAGS. */
42 #define NHA_OP_FLAG_RESP_GRP_RESVD_0	BIT(31)	/* Dump clears resvd fields. */
43 
44 enum {
45 	NHA_UNSPEC,
46 	NHA_ID,		/* u32; id for nexthop. id == 0 means auto-assign */
47 
48 	NHA_GROUP,	/* array of nexthop_grp */
49 	NHA_GROUP_TYPE,	/* u16 one of NEXTHOP_GRP_TYPE */
50 	/* if NHA_GROUP attribute is added, no other attributes can be set */
51 
52 	NHA_BLACKHOLE,	/* flag; nexthop used to blackhole packets */
53 	/* if NHA_BLACKHOLE is added, OIF, GATEWAY, ENCAP can not be set */
54 
55 	NHA_OIF,	/* u32; nexthop device */
56 	NHA_GATEWAY,	/* be32 (IPv4) or in6_addr (IPv6) gw address */
57 	NHA_ENCAP_TYPE, /* u16; lwt encap type */
58 	NHA_ENCAP,	/* lwt encap data */
59 
60 	/* NHA_OIF can be appended to dump request to return only
61 	 * nexthops using given device
62 	 */
63 	NHA_GROUPS,	/* flag; only return nexthop groups in dump */
64 	NHA_MASTER,	/* u32;  only return nexthops with given master dev */
65 
66 	NHA_FDB,	/* flag; nexthop belongs to a bridge fdb */
67 	/* if NHA_FDB is added, OIF, BLACKHOLE, ENCAP cannot be set */
68 
69 	/* nested; resilient nexthop group attributes */
70 	NHA_RES_GROUP,
71 	/* nested; nexthop bucket attributes */
72 	NHA_RES_BUCKET,
73 
74 	/* u32; operation-specific flags */
75 	NHA_OP_FLAGS,
76 
77 	/* nested; nexthop group stats */
78 	NHA_GROUP_STATS,
79 
80 	/* u32; nexthop hardware stats enable */
81 	NHA_HW_STATS_ENABLE,
82 
83 	/* u32; read-only; whether any driver collects HW stats */
84 	NHA_HW_STATS_USED,
85 
86 	__NHA_MAX,
87 };
88 
89 #define NHA_MAX	(__NHA_MAX - 1)
90 
91 enum {
92 	NHA_RES_GROUP_UNSPEC,
93 	/* Pad attribute for 64-bit alignment. */
94 	NHA_RES_GROUP_PAD = NHA_RES_GROUP_UNSPEC,
95 
96 	/* u16; number of nexthop buckets in a resilient nexthop group */
97 	NHA_RES_GROUP_BUCKETS,
98 	/* clock_t as u32; nexthop bucket idle timer (per-group) */
99 	NHA_RES_GROUP_IDLE_TIMER,
100 	/* clock_t as u32; nexthop unbalanced timer */
101 	NHA_RES_GROUP_UNBALANCED_TIMER,
102 	/* clock_t as u64; nexthop unbalanced time */
103 	NHA_RES_GROUP_UNBALANCED_TIME,
104 
105 	__NHA_RES_GROUP_MAX,
106 };
107 
108 #define NHA_RES_GROUP_MAX	(__NHA_RES_GROUP_MAX - 1)
109 
110 enum {
111 	NHA_RES_BUCKET_UNSPEC,
112 	/* Pad attribute for 64-bit alignment. */
113 	NHA_RES_BUCKET_PAD = NHA_RES_BUCKET_UNSPEC,
114 
115 	/* u16; nexthop bucket index */
116 	NHA_RES_BUCKET_INDEX,
117 	/* clock_t as u64; nexthop bucket idle time */
118 	NHA_RES_BUCKET_IDLE_TIME,
119 	/* u32; nexthop id assigned to the nexthop bucket */
120 	NHA_RES_BUCKET_NH_ID,
121 
122 	__NHA_RES_BUCKET_MAX,
123 };
124 
125 #define NHA_RES_BUCKET_MAX	(__NHA_RES_BUCKET_MAX - 1)
126 
127 enum {
128 	NHA_GROUP_STATS_UNSPEC,
129 
130 	/* nested; nexthop group entry stats */
131 	NHA_GROUP_STATS_ENTRY,
132 
133 	__NHA_GROUP_STATS_MAX,
134 };
135 
136 #define NHA_GROUP_STATS_MAX	(__NHA_GROUP_STATS_MAX - 1)
137 
138 enum {
139 	NHA_GROUP_STATS_ENTRY_UNSPEC,
140 
141 	/* u32; nexthop id of the nexthop group entry */
142 	NHA_GROUP_STATS_ENTRY_ID,
143 
144 	/* uint; number of packets forwarded via the nexthop group entry */
145 	NHA_GROUP_STATS_ENTRY_PACKETS,
146 
147 	/* uint; number of packets forwarded via the nexthop group entry in
148 	 * hardware
149 	 */
150 	NHA_GROUP_STATS_ENTRY_PACKETS_HW,
151 
152 	__NHA_GROUP_STATS_ENTRY_MAX,
153 };
154 
155 #define NHA_GROUP_STATS_ENTRY_MAX	(__NHA_GROUP_STATS_ENTRY_MAX - 1)
156 
157 #endif
158