Skip to content

Commit 6c00e9f

Browse files
authored
Merge branch 'rust-netlink:main' into netkit
2 parents 98fa3ca + 0bd7abd commit 6c00e9f

File tree

4 files changed

+118
-5
lines changed

4 files changed

+118
-5
lines changed

src/neighbour/attribute.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use netlink_packet_core::{
66
ParseableParametrized,
77
};
88

9-
use super::{NeighbourAddress, NeighbourCacheInfo, NeighbourCacheInfoBuffer};
9+
use super::{
10+
NeighbourAddress, NeighbourCacheInfo, NeighbourCacheInfoBuffer,
11+
NeighbourExtFlags,
12+
};
1013
use crate::{route::RouteProtocol, AddressFamily};
1114

1215
const NDA_DST: u16 = 1;
@@ -24,6 +27,7 @@ const NDA_SRC_VNI: u16 = 11;
2427
const NDA_PROTOCOL: u16 = 12;
2528
// const NDA_NH_ID: u16 = 13;
2629
// const NDA_FDB_EXT_ATTRS: u16 = 14;
30+
const NDA_FLAGS_EXT: u16 = 15;
2731

2832
#[derive(Debug, PartialEq, Eq, Clone)]
2933
#[non_exhaustive]
@@ -40,6 +44,7 @@ pub enum NeighbourAttribute {
4044
LinkNetNsId(u32),
4145
SourceVni(u32),
4246
Protocol(RouteProtocol),
47+
ExtFlags(NeighbourExtFlags),
4348
Other(DefaultNla),
4449
}
4550

@@ -56,7 +61,8 @@ impl Nla for NeighbourAttribute {
5661
| Self::Controller(_)
5762
| Self::Vni(_)
5863
| Self::IfIndex(_)
59-
| Self::SourceVni(_) => 4,
64+
| Self::SourceVni(_)
65+
| Self::ExtFlags(_) => 4,
6066
Self::Other(attr) => attr.value_len(),
6167
}
6268
}
@@ -76,6 +82,7 @@ impl Nla for NeighbourAttribute {
7682
| Self::Vni(value)
7783
| Self::IfIndex(value)
7884
| Self::SourceVni(value) => emit_u32(buffer, *value).unwrap(),
85+
Self::ExtFlags(v) => emit_u32(buffer, v.bits()).unwrap(),
7986
Self::Protocol(v) => v.emit(buffer),
8087
Self::Other(attr) => attr.emit_value(buffer),
8188
}
@@ -95,6 +102,7 @@ impl Nla for NeighbourAttribute {
95102
Self::LinkNetNsId(_) => NDA_LINK_NETNSID,
96103
Self::SourceVni(_) => NDA_SRC_VNI,
97104
Self::Protocol(_) => NDA_PROTOCOL,
105+
Self::ExtFlags(_) => NDA_FLAGS_EXT,
98106
Self::Other(nla) => nla.kind(),
99107
}
100108
}
@@ -146,6 +154,13 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
146154
format!("invalid NDA_PROTOCOL value {payload:?}"),
147155
)?)
148156
}
157+
NDA_FLAGS_EXT => {
158+
Self::ExtFlags(NeighbourExtFlags::from_bits_retain(
159+
parse_u32(payload).context(format!(
160+
"invalid NDA_FLAGS_EXT value {payload:?}"
161+
))?,
162+
))
163+
}
149164
_ => Self::Other(
150165
DefaultNla::parse(buf)
151166
.context("invalid link NLA value (unknown type)")?,

src/neighbour/flags.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,18 @@ bitflags! {
2525
const _ = !0;
2626
}
2727
}
28+
29+
const NTF_EXT_MANAGED: u32 = 1 << 0;
30+
const NTF_EXT_LOCKED: u32 = 1 << 1;
31+
const NTF_EXT_EXT_VALIDATED: u32 = 1 << 2;
32+
33+
bitflags! {
34+
#[derive(Clone, Eq, PartialEq, Debug, Copy, Default)]
35+
#[non_exhaustive]
36+
pub struct NeighbourExtFlags: u32 {
37+
const Managed = NTF_EXT_MANAGED;
38+
const Locked = NTF_EXT_LOCKED;
39+
const ExtValidated = NTF_EXT_EXT_VALIDATED;
40+
const _ = !0;
41+
}
42+
}

src/neighbour/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::{
1515
address::NeighbourAddress,
1616
attribute::NeighbourAttribute,
1717
cache_info::{NeighbourCacheInfo, NeighbourCacheInfoBuffer},
18-
flags::NeighbourFlags,
18+
flags::{NeighbourExtFlags, NeighbourFlags},
1919
header::{NeighbourHeader, NeighbourMessageBuffer},
2020
message::NeighbourMessage,
2121
state::NeighbourState,

src/neighbour/tests/ip.rs

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use netlink_packet_core::{Emitable, Parseable};
1010
use crate::{
1111
neighbour::{
1212
flags::NeighbourFlags, NeighbourAttribute, NeighbourCacheInfo,
13-
NeighbourHeader, NeighbourMessage, NeighbourMessageBuffer,
14-
NeighbourState,
13+
NeighbourExtFlags, NeighbourHeader, NeighbourMessage,
14+
NeighbourMessageBuffer, NeighbourState,
1515
},
1616
route::{RouteProtocol, RouteType},
1717
AddressFamily,
@@ -171,3 +171,86 @@ fn test_ipv4_neighbour_protocol_show() {
171171

172172
assert_eq!(buf, raw);
173173
}
174+
175+
#[test]
176+
fn test_ipv4_neighbour_add_ext_flags() {
177+
let raw = vec![
178+
0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179+
0x08, 0x00, 0x01, 0x00, 0xac, 0x11, 0x02, 0x01, 0x08, 0x00, 0x0f, 0x00,
180+
0x01, 0x00, 0x00, 0x00,
181+
];
182+
183+
let expected = NeighbourMessage {
184+
header: NeighbourHeader {
185+
family: AddressFamily::Inet,
186+
ifindex: 3,
187+
state: NeighbourState::None,
188+
flags: NeighbourFlags::empty(),
189+
kind: RouteType::Unspec,
190+
},
191+
attributes: vec![
192+
NeighbourAttribute::Destination(
193+
Ipv4Addr::from_str("172.17.2.1").unwrap().into(),
194+
),
195+
NeighbourAttribute::ExtFlags(NeighbourExtFlags::Managed),
196+
],
197+
};
198+
199+
assert_eq!(
200+
expected,
201+
NeighbourMessage::parse(&NeighbourMessageBuffer::new(&raw)).unwrap()
202+
);
203+
204+
let mut buf = vec![0; expected.buffer_len()];
205+
206+
expected.emit(&mut buf);
207+
208+
assert_eq!(buf, raw);
209+
}
210+
211+
#[test]
212+
fn test_ipv4_neighbour_show_ext_flags() {
213+
let raw = vec![
214+
0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01,
215+
0x08, 0x00, 0x01, 0x00, 0xac, 0x11, 0x02, 0x01, 0x0a, 0x00, 0x02, 0x00,
216+
0x48, 0x21, 0x0b, 0x3c, 0x1f, 0x01, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00,
217+
0x04, 0x00, 0x00, 0x00, 0x14, 0x00, 0x03, 0x00, 0x59, 0x02, 0x00, 0x00,
218+
0x33, 0x00, 0x00, 0x00, 0xf3, 0x17, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
219+
0x08, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x00, 0x00,
220+
];
221+
222+
let expected = NeighbourMessage {
223+
header: NeighbourHeader {
224+
family: AddressFamily::Inet,
225+
ifindex: 3,
226+
state: NeighbourState::Reachable,
227+
flags: NeighbourFlags::empty(),
228+
kind: RouteType::Unicast,
229+
},
230+
attributes: vec![
231+
NeighbourAttribute::Destination(
232+
Ipv4Addr::from_str("172.17.2.1").unwrap().into(),
233+
),
234+
NeighbourAttribute::LinkLocalAddress(vec![72, 33, 11, 60, 31, 1]),
235+
NeighbourAttribute::Probes(4),
236+
NeighbourAttribute::CacheInfo(NeighbourCacheInfo {
237+
confirmed: 601,
238+
used: 51,
239+
updated: 71667,
240+
refcnt: 1,
241+
}),
242+
NeighbourAttribute::ExtFlags(NeighbourExtFlags::Managed),
243+
],
244+
};
245+
246+
assert_eq!(
247+
expected,
248+
NeighbourMessage::parse(&NeighbourMessageBuffer::new(&raw)).unwrap()
249+
);
250+
251+
let mut buf = vec![0; expected.buffer_len()];
252+
253+
expected.emit(&mut buf);
254+
255+
assert_eq!(buf, raw);
256+
}

0 commit comments

Comments
 (0)