use std::net::Ipv4Addr;
use netlink_packet_core::{DefaultNla, Emitable, Parseable};
use crate::{
link::{
af_spec::In6AddrGenMode, link_flag::LinkFlags, AfSpecInet, AfSpecInet6,
AfSpecUnspec, DevlinkPort, DpllPin, Inet6CacheInfo, Inet6DevConf,
Inet6IfaceFlags, InetDevConf, InfoData, InfoKind, InfoVti,
LinkAttribute, LinkHeader, LinkInfo, LinkLayerType, LinkMessage,
LinkMessageBuffer, LinkMode, LinkXdp, Map, State, XdpAttached,
},
AddressFamily,
};
#[test]
fn test_parsing_link_vti() {
let raw = vec![
0x00, 0x00, 0x00, 0x03, 0x12, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x03, 0x00, 0x76, 0x74, 0x69, 0x30,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0d, 0x00, 0xe8, 0x03, 0x00, 0x00,
0x05, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x11, 0x00,
0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x04, 0x00, 0xc8, 0x05, 0x00, 0x00, 0x08, 0x00, 0x32, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x1e, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x1f, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x28, 0x00,
0xff, 0xff, 0x00, 0x00, 0x08, 0x00, 0x29, 0x00, 0x00, 0x00, 0x01, 0x00,
0x08, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x3f, 0x00,
0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00,
0x08, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x3c, 0x00,
0xff, 0xff, 0x00, 0x00, 0x08, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x21, 0x00,
0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x44, 0x00, 0x94, 0x00, 0x00, 0x00,
0x06, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x27, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0xc0, 0xa8, 0x01, 0x01,
0x08, 0x00, 0x02, 0x00, 0x0a, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x2b, 0x00,
0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x12, 0x00,
0x08, 0x00, 0x01, 0x00, 0x76, 0x74, 0x69, 0x00, 0x34, 0x00, 0x02, 0x00,
0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x64, 0x08, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x64,
0x08, 0x00, 0x04, 0x00, 0xc0, 0xa8, 0x01, 0x01, 0x08, 0x00, 0x05, 0x00,
0x0a, 0x00, 0x00, 0x01, 0x08, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x36, 0x00, 0xc0, 0xa8, 0x01, 0x01, 0x08, 0x00, 0x05, 0x00,
0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x06, 0x00, 0x6e, 0x6f, 0x6f, 0x70,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x1a, 0x00, 0x8c, 0x00, 0x02, 0x00,
0x88, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x27, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x30, 0x01, 0x0a, 0x00, 0x08, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x05, 0x00, 0xff, 0xff, 0x00, 0x00,
0x55, 0x4c, 0x86, 0x00, 0x28, 0x55, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00,
0xf4, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0xc8, 0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0xa0, 0x0f, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0xa3, 0x02, 0x00, 0x80, 0x51, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00,
0x58, 0x02, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x60, 0xea, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xee, 0x36, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x0e, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x3e, 0x80,
0x04, 0x00, 0x41, 0x80,
];
let expected = LinkMessage {
header: LinkHeader {
interface_family: AddressFamily::Unspec,
index: 18,
link_layer_type: LinkLayerType::Tunnel,
flags: LinkFlags::Pointopoint | LinkFlags::Noarp,
change_mask: LinkFlags::empty(),
},
attributes: vec![
LinkAttribute::IfName("vti0".to_string()),
LinkAttribute::TxQueueLen(1000),
LinkAttribute::OperState(State::Down),
LinkAttribute::Mode(LinkMode::Default),
LinkAttribute::NetnsImmutable(false),
LinkAttribute::Mtu(1480),
LinkAttribute::MinMtu(0),
LinkAttribute::MaxMtu(0),
LinkAttribute::Group(0),
LinkAttribute::Promiscuity(0),
LinkAttribute::AllMulticast(0),
LinkAttribute::NumTxQueues(1),
LinkAttribute::GsoMaxSegs(65535),
LinkAttribute::GsoMaxSize(65536),
LinkAttribute::GroMaxSize(65536),
LinkAttribute::GsoIpv4MaxSize(65536),
LinkAttribute::GroIpv4MaxSize(65536),
LinkAttribute::TsoMaxSize(65536),
LinkAttribute::TsoMaxSegs(65535),
LinkAttribute::Other(DefaultNla::new(66, vec![0, 0, 0, 0])),
LinkAttribute::NumRxQueues(1),
LinkAttribute::Carrier(1),
LinkAttribute::CarrierChanges(0),
LinkAttribute::CarrierUpCount(0),
LinkAttribute::CarrierDownCount(0),
LinkAttribute::Other(DefaultNla::new(68, vec![148, 0])),
LinkAttribute::Other(DefaultNla::new(69, vec![0, 0])),
LinkAttribute::ProtoDown(0),
LinkAttribute::Address(vec![192, 168, 1, 1]),
LinkAttribute::Broadcast(vec![10, 0, 0, 1]),
LinkAttribute::Xdp(vec![LinkXdp::Attached(XdpAttached::None)]),
LinkAttribute::LinkInfo(vec![
LinkInfo::Kind(InfoKind::Vti),
LinkInfo::Data(InfoData::Vti(vec![
InfoVti::Link(0),
InfoVti::IKey(100),
InfoVti::OKey(100),
InfoVti::Local(Ipv4Addr::new(192, 168, 1, 1).into()),
InfoVti::Remote(Ipv4Addr::new(10, 0, 0, 1).into()),
InfoVti::FwMark(0),
])),
]),
LinkAttribute::PermAddress(vec![192, 168, 1, 1]),
LinkAttribute::Link(0),
LinkAttribute::Qdisc("noop".to_string()),
LinkAttribute::AfSpecUnspec(vec![
AfSpecUnspec::Inet(vec![AfSpecInet::DevConf(InetDevConf {
accept_redirects: 1,
secure_redirects: 1,
send_redirects: 1,
shared_media: 1,
rp_filter: 2,
promote_secondaries: 1,
igmpv2_unsolicited_report_interval: 10000,
igmpv3_unsolicited_report_interval: 1000,
arp_evict_nocarrier: 1,
..Default::default()
})]),
AfSpecUnspec::Inet6(vec![
AfSpecInet6::Flags(Inet6IfaceFlags::empty()),
AfSpecInet6::CacheInfo(Inet6CacheInfo {
max_reasm_len: 65535,
tstamp: 8801365,
reachable_time: 21800,
retrans_time: 1000,
}),
AfSpecInet6::DevConf(Inet6DevConf {
hoplimit: 64,
mtu6: 1480,
accept_ra: 1,
accept_redirects: 1,
autoconf: 1,
dad_transmits: 1,
rtr_solicits: -1,
rtr_solicit_interval: 4000,
rtr_solicit_delay: 1000,
use_tempaddr: -1,
temp_valid_lft: 172800,
temp_prefered_lft: 86400,
regen_max_retry: 3,
max_desync_factor: 600,
max_addresses: 16,
accept_ra_defrtr: 1,
accept_ra_pinfo: 1,
accept_ra_rtr_pref: 1,
rtr_probe_interval: 60000,
accept_dad: -1,
mldv1_unsolicited_report_interval: 10000,
mldv2_unsolicited_report_interval: 1000,
suppress_frag_ndisc: 1,
accept_ra_mtu: 1,
accept_ra_min_hop_limit: 1,
rtr_solicit_max_interval: 3600000,
enhanced_dad: 1,
ra_defrtr_metric: 1024,
ioam6_id: 65535,
ioam6_id_wide: -1,
ndisc_evict_nocarrier: 1,
..Default::default()
}),
AfSpecInet6::Token(std::net::Ipv6Addr::UNSPECIFIED),
AfSpecInet6::AddrGenMode(In6AddrGenMode::Eui64),
]),
]),
LinkAttribute::Map(Map::default()),
LinkAttribute::DevlinkPort(Vec::<DevlinkPort>::new()),
LinkAttribute::DpllPin(Vec::<DpllPin>::new()),
],
};
assert_eq!(
expected,
LinkMessage::parse(&LinkMessageBuffer::new(&raw)).unwrap()
);
let mut buf = vec![0; expected.buffer_len()];
expected.emit(&mut buf);
assert_eq!(buf, raw);
}
#[test]
fn test_parsing_link_vti6() {
let raw = vec![
0x00, 0x00, 0x01, 0x03, 0x14, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x03, 0x00, 0x76, 0x74, 0x69, 0x36,
0x30, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0d, 0x00, 0xe8, 0x03, 0x00, 0x00,
0x05, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x11, 0x00,
0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x04, 0x00, 0x34, 0x05, 0x00, 0x00, 0x08, 0x00, 0x32, 0x00,
0x44, 0x00, 0x00, 0x00, 0x08, 0x00, 0x33, 0x00, 0xd7, 0xff, 0x00, 0x00,
0x08, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x1e, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x1f, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x28, 0x00,
0xff, 0xff, 0x00, 0x00, 0x08, 0x00, 0x29, 0x00, 0x00, 0x00, 0x01, 0x00,
0x08, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x3f, 0x00,
0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00,
0x08, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x3c, 0x00,
0xff, 0xff, 0x00, 0x00, 0x08, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x21, 0x00,
0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
0x06, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x27, 0x00,
0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, 0x20, 0x01, 0x0d, 0xb8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x14, 0x00, 0x02, 0x00, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x2b, 0x00,
0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x12, 0x00,
0x09, 0x00, 0x01, 0x00, 0x76, 0x74, 0x69, 0x36, 0x00, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x02, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x14, 0x00, 0x04, 0x00, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x14, 0x00, 0x05, 0x00,
0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x64,
0x08, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x64, 0x08, 0x00, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x36, 0x00, 0x66, 0xe7, 0x98, 0x48,
0x03, 0xe9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x06, 0x00,
0x6e, 0x6f, 0x6f, 0x70, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x1a, 0x00,
0x8c, 0x00, 0x02, 0x00, 0x88, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x01, 0x0a, 0x00,
0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x05, 0x00,
0xff, 0xff, 0x00, 0x00, 0xaf, 0x29, 0x87, 0x00, 0x06, 0x59, 0x00, 0x00,
0xe8, 0x03, 0x00, 0x00, 0xf4, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00, 0x34, 0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xa0, 0x0f, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0x00, 0xa3, 0x02, 0x00, 0x80, 0x51, 0x01, 0x00,
0x03, 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x60, 0xea, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00,
0xe8, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0xee, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x24, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x3e, 0x80, 0x04, 0x00, 0x41, 0x80,
];
let expected = LinkMessage {
header: LinkHeader {
interface_family: AddressFamily::Unspec,
index: 20,
link_layer_type: LinkLayerType::Tunnel6,
flags: LinkFlags::Pointopoint | LinkFlags::Noarp,
change_mask: LinkFlags::empty(),
},
attributes: vec![
LinkAttribute::IfName("vti60".to_string()),
LinkAttribute::TxQueueLen(1000),
LinkAttribute::OperState(State::Down),
LinkAttribute::Mode(LinkMode::Default),
LinkAttribute::NetnsImmutable(false),
LinkAttribute::Mtu(1332),
LinkAttribute::MinMtu(68),
LinkAttribute::MaxMtu(65495),
LinkAttribute::Group(0),
LinkAttribute::Promiscuity(0),
LinkAttribute::AllMulticast(0),
LinkAttribute::NumTxQueues(1),
LinkAttribute::GsoMaxSegs(65535),
LinkAttribute::GsoMaxSize(65536),
LinkAttribute::GroMaxSize(65536),
LinkAttribute::GsoIpv4MaxSize(65536),
LinkAttribute::GroIpv4MaxSize(65536),
LinkAttribute::TsoMaxSize(65536),
LinkAttribute::TsoMaxSegs(65535),
LinkAttribute::Other(DefaultNla::new(66, vec![0, 0, 0, 0])),
LinkAttribute::NumRxQueues(1),
LinkAttribute::Carrier(1),
LinkAttribute::CarrierChanges(0),
LinkAttribute::CarrierUpCount(0),
LinkAttribute::CarrierDownCount(0),
LinkAttribute::Other(DefaultNla::new(68, vec![0, 0])),
LinkAttribute::Other(DefaultNla::new(69, vec![0, 0])),
LinkAttribute::ProtoDown(0),
LinkAttribute::Address(vec![
32, 1, 13, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
]),
LinkAttribute::Broadcast(vec![
32, 1, 13, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
]),
LinkAttribute::Xdp(vec![LinkXdp::Attached(XdpAttached::None)]),
LinkAttribute::LinkInfo(vec![
LinkInfo::Kind(InfoKind::Vti6),
LinkInfo::Data(InfoData::Vti(vec![
InfoVti::Link(0),
InfoVti::Local(
std::net::Ipv6Addr::new(
0x2001, 0xdb8, 0, 0, 0, 0, 0, 2,
)
.into(),
),
InfoVti::Remote(
std::net::Ipv6Addr::new(
0x2001, 0xdb8, 0, 0, 0, 0, 0, 1,
)
.into(),
),
InfoVti::IKey(100),
InfoVti::OKey(100),
InfoVti::FwMark(0),
])),
]),
LinkAttribute::PermAddress(vec![
102, 231, 152, 72, 3, 233, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]),
LinkAttribute::Link(0),
LinkAttribute::Qdisc("noop".to_string()),
LinkAttribute::AfSpecUnspec(vec![
AfSpecUnspec::Inet(vec![AfSpecInet::DevConf(InetDevConf {
accept_redirects: 1,
secure_redirects: 1,
send_redirects: 1,
shared_media: 1,
rp_filter: 2,
promote_secondaries: 1,
igmpv2_unsolicited_report_interval: 10000,
igmpv3_unsolicited_report_interval: 1000,
arp_evict_nocarrier: 1,
..Default::default()
})]),
AfSpecUnspec::Inet6(vec![
AfSpecInet6::Flags(Inet6IfaceFlags::empty()),
AfSpecInet6::CacheInfo(Inet6CacheInfo {
max_reasm_len: 65535,
tstamp: 8858031,
reachable_time: 22790,
retrans_time: 1000,
}),
AfSpecInet6::DevConf(Inet6DevConf {
hoplimit: 64,
mtu6: 1332,
accept_ra: 1,
accept_redirects: 1,
autoconf: 1,
dad_transmits: 1,
rtr_solicits: -1,
rtr_solicit_interval: 4000,
rtr_solicit_delay: 1000,
use_tempaddr: -1,
temp_valid_lft: 172800,
temp_prefered_lft: 86400,
regen_max_retry: 3,
max_desync_factor: 600,
max_addresses: 16,
accept_ra_defrtr: 1,
accept_ra_pinfo: 1,
accept_ra_rtr_pref: 1,
rtr_probe_interval: 60000,
accept_dad: -1,
mldv1_unsolicited_report_interval: 10000,
mldv2_unsolicited_report_interval: 1000,
suppress_frag_ndisc: 1,
accept_ra_mtu: 1,
accept_ra_min_hop_limit: 1,
rtr_solicit_max_interval: 3600000,
enhanced_dad: 1,
ra_defrtr_metric: 1024,
ioam6_id: 65535,
ioam6_id_wide: -1,
ndisc_evict_nocarrier: 1,
..Default::default()
}),
AfSpecInet6::Token(std::net::Ipv6Addr::UNSPECIFIED),
AfSpecInet6::AddrGenMode(In6AddrGenMode::Eui64),
]),
]),
LinkAttribute::Map(Map::default()),
LinkAttribute::DevlinkPort(Vec::<DevlinkPort>::new()),
LinkAttribute::DpllPin(Vec::<DpllPin>::new()),
],
};
assert_eq!(
expected,
LinkMessage::parse(&LinkMessageBuffer::new(&raw)).unwrap()
);
let mut buf = vec![0; expected.buffer_len()];
expected.emit(&mut buf);
assert_eq!(buf, raw);
}