rsmnl_linux/
neighbour.rs

1use errno::Errno;
2use libc;
3use mnl::{Attr, AttrTbl, MsgVec, Result};
4use std::net::{Ipv4Addr, Ipv6Addr};
5
6#[repr(C)]
7#[derive(Debug, Copy, Clone)]
8pub struct Ndmsg {
9    pub ndm_family: u8,
10    pub ndm_pad1: u8,
11    pub ndm_pad2: u16,
12    pub ndm_ifindex: i32,
13    pub ndm_state: u16,
14    pub ndm_flags: u8,
15    pub ndm_type: u8,
16}
17
18#[repr(u16)]
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
20#[tbname = "NdaTbl"]
21pub enum Nda {
22    Unspec,
23
24    #[nla_type(Ipv4Addr, v4dst)]
25    #[nla_type(Ipv6Addr, v6dst)]
26    Dst,
27
28    #[nla_type(bytes, lladdr)]
29    Lladdr,
30
31    #[nla_type(NdaCacheinfo, cacheinfo)]
32    Cacheinfo,
33
34    #[nla_type(u32, probes)]
35    Probes,
36
37    #[nla_type(u16, vlan)]
38    Vlan,
39
40    #[nla_type(u16, port)]
41    Port,
42
43    #[nla_type(u32, vni)]
44    Vni,
45
46    #[nla_type(u32, ifindex)]
47    Ifindex,
48
49    #[nla_type(u32, master)]
50    Master,
51
52    #[nla_type(i32, link_netnsid)]
53    LinkNetnsid,
54
55    #[nla_type(u32, src_vni)]
56    SrcVni,
57
58    #[nla_type(u8, protocol)]
59    Protocol,
60
61    #[nla_type(u32, nh_id)]
62    NhId,
63
64    #[nla_nest(NfeaTbl, fdb_ext_attrs)]
65    FdbExtAttrs,
66
67    _MAX,
68}
69
70/*
71 *	Neighbor Cache Entry Flags
72 */
73pub const NTF_USE: u8 = 0x01;
74pub const NTF_SELF: u8 = 0x02;
75pub const NTF_MASTER: u8 = 0x04;
76pub const NTF_PROXY: u8		= 0x08	/* == ATF_PUBL */;
77pub const NTF_EXT_LEARNED: u8 = 0x10;
78pub const NTF_OFFLOADED: u8 = 0x20;
79pub const NTF_STICKY: u8 = 0x40;
80pub const NTF_ROUTER: u8 = 0x80;
81
82/*
83 *	Neighbor Cache Entry States.
84 */
85pub const NUD_INCOMPLETE: u8 = 0x01;
86pub const NUD_REACHABLE: u8 = 0x02;
87pub const NUD_STALE: u8 = 0x04;
88pub const NUD_DELAY: u8 = 0x08;
89pub const NUD_PROBE: u8 = 0x10;
90pub const NUD_FAILED: u8 = 0x20;
91
92// Dummy states
93pub const NUD_NOARP: u8 = 0x40;
94pub const NUD_PERMANENT: u8 = 0x80;
95pub const NUD_NONE: u8 = 0x00;
96
97/* NUD_NOARP & NUD_PERMANENT are pseudostates, they never change
98 * and make no address resolution or NUD.
99 * NUD_PERMANENT also cannot be deleted by garbage collectors.
100 * When NTF_EXT_LEARNED is set for a bridge fdb entry the different cache entry
101 * states don't make sense and thus are ignored. Such entries don't age and
102 * can roam.
103 */
104
105#[repr(C)]
106#[derive(Debug, Copy, Clone)]
107pub struct NdaCacheinfo {
108    pub ndm_confirmed: u32,
109    pub ndm_used: u32,
110    pub ndm_updated: u32,
111    pub ndm_refcnt: u32,
112}
113
114/*****************************************************************
115 *		Neighbour tables specific messages.
116 *
117 * To retrieve the neighbour tables send RTM_GETNEIGHTBL with the
118 * NLM_F_DUMP flag set. Every neighbour table configuration is
119 * spread over multiple messages to avoid running into message
120 * size limits on systems with many interfaces. The first message
121 * in the sequence transports all not device specific data such as
122 * statistics, configuration, and the default parameter set.
123 * This message is followed by 0..n messages carrying device
124 * specific parameter sets.
125 * Although the ordering should be sufficient, NDTA_NAME can be
126 * used to identify sequences. The initial message can be identified
127 * by checking for NDTA_CONFIG. The device specific messages do
128 * not contain this TLV but have NDTPA_IFINDEX set to the
129 * corresponding interface index.
130 *
131 * To change neighbour table attributes, send RTM_SETNEIGHTBL
132 * with NDTA_NAME set. Changeable attribute include NDTA_THRESH[1-3],
133 * NDTA_GC_INTERVAL, and all TLVs in NDTA_PARMS unless marked
134 * otherwise. Device specific parameter sets can be changed by
135 * setting NDTPA_IFINDEX to the interface index of the corresponding
136 * device.
137 ****/
138#[repr(C)]
139#[derive(Debug, Copy, Clone)]
140pub struct NdtStats {
141    pub ndts_allocs: u64,
142    pub ndts_destroys: u64,
143    pub ndts_hash_grows: u64,
144    pub ndts_res_failed: u64,
145    pub ndts_lookups: u64,
146    pub ndts_hits: u64,
147    pub ndts_rcv_probes_mcast: u64,
148    pub ndts_rcv_probes_ucast: u64,
149    pub ndts_periodic_gc_runs: u64,
150    pub ndts_forced_gc_runs: u64,
151    pub ndts_table_fulls: u64,
152}
153
154#[repr(u16)]
155#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
156#[tbname = "NdtpaTbl"]
157pub enum Ndtpa {
158    Unspec,
159
160    #[nla_type(u32, ifindex)]
161    Ifindex, // u32
162
163    #[nla_type(u32, refcnt)]
164    Refcnt, // u32
165
166    #[nla_type(u64, reachable_time)]
167    ReachableTime, // u64
168
169    #[nla_type(u64, base_reachable_time)]
170    BaseReachableTime, // u64
171
172    #[nla_type(u64, retrans_time)]
173    RetransTime, // u64
174
175    #[nla_type(u64, gc_staletime)]
176    GcStaletime, // u64
177
178    #[nla_type(u64, delay_probe_time)]
179    DelayProbeTime, // u64
180
181    #[nla_type(u64, queue_len)]
182    QueueLen, // u32
183
184    #[nla_type(u64, app_probes)]
185    AppProbes, // u32
186
187    #[nla_type(u32, ucast_probes)]
188    UcastProbes, // u32
189
190    #[nla_type(u32, mcast_probes)]
191    McastProbes, // u32
192
193    #[nla_type(u64, anycast_delay)]
194    AnycastDelay, // u64
195
196    #[nla_type(u64, proxy_delay)]
197    ProxyDelay, // u64
198
199    #[nla_type(u32, proxy_qlen)]
200    ProxyQlen, // u32
201
202    #[nla_type(u64, locktime)]
203    Locktime, // u64
204
205    #[nla_type(u32, queue_lenbytes)]
206    QueueLenbytes, // u32
207
208    #[nla_type(u32, mcast_reprobes)]
209    McastReprobes, // u32
210
211    PAD,
212    _MAX,
213}
214
215#[repr(C)]
216#[derive(Debug, Copy, Clone)]
217pub struct Ndtmsg {
218    pub ndtm_family: u8,
219    pub ndtm_pad1: u8,
220    pub ndtm_pad2: u16,
221}
222
223#[repr(C)]
224#[derive(Debug, Copy, Clone)]
225pub struct NdtConfig {
226    pub ndtc_key_len: u16,
227    pub ndtc_entry_size: u16,
228    pub ndtc_entries: u32,
229    pub ndtc_last_flush: u32, // delta to now in msecs
230    pub ndtc_last_rand: u32,
231    pub ndtc_hash_rnd: u32,
232    pub ndtc_hash_mask: u32,
233    pub ndtc_hash_chain_gc: u32,
234    pub ndtc_proxy_qlen: u32,
235}
236
237#[repr(u16)]
238#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
239#[tbname = "NdtaTbl"]
240pub enum Ndta {
241    Unspec,
242
243    #[nla_type(str, name)]
244    Name,
245
246    #[nla_type(u32, thresh1)]
247    Thresh1,
248
249    #[nla_type(u32, thresh2)]
250    Thresh2,
251
252    #[nla_type(u32, thresh3)]
253    Thresh3,
254
255    #[nla_type(NdtConfig, config)]
256    Config,
257
258    #[nla_nest(NdtpaTbl, parms)]
259    Parms,
260
261    #[nla_type(NdtStats, stats)]
262    Stats,
263
264    #[nla_type(u64, gc_interval)]
265    GcInterval,
266    Pad,
267    _MAX,
268}
269
270// FDB activity notification bits used in NFEA_ACTIVITY_NOTIFY:
271// - FDB_NOTIFY_BIT - notify on activity/expire for any entry
272// - FDB_NOTIFY_INACTIVE_BIT - mark as inactive to avoid multiple notifications
273#[repr(u8)]
274#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
275pub enum Fdb {
276    NotifyBit = 1 << 0,
277    NotifyInactiveBit = 1 << 1,
278    _MAX,
279}
280
281// embedded into NDA_FDB_EXT_ATTRS:
282// [NDA_FDB_EXT_ATTRS] = {
283//     [NFEA_ACTIVITY_NOTIFY]
284//     ...
285// }
286#[repr(u16)]
287#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
288#[tbname = "NfeaTbl"]
289pub enum Nfea {
290    Unspec,
291
292    #[nla_type(u8, activity_notify)]
293    ActivityNotify,
294
295    #[nla_type(flag, dont_refresh)]
296    DontRefresh,
297
298    _MAX,
299}