netlink-bindings 0.3.3

Type-safe Rust bindings for Netlink generated from YAML specifications
Documentation
use crate::utils::*;

use crate::tc;
use crate::tc::*;

#[test]
fn tc_qdisc_add_priomap() {
    // Last netlink message generated by:
    // `tc qdisc add dev wg0 root handle 1: prio bands 8 priomap 7 6 5 4 3 2 1 0`
    #[cfg_attr(any(), rustfmt::skip)]
    let payload = &[
        0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff,
        0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x01, 0x00, 0x70, 0x72, 0x69, 0x6f, 0x00, 0x00, 0x00, 0x00,
        0x1c, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
    //  ^ "prio" submessage     ^ fixed header
        0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, 0x02, 0x00,
    //                                                  ^^^^^^^^^^^^^^^^^^^^^^
    //                                                  these bytes are junk, but still accepted by
    //                                                  both kernel and ynl C library
    ];

    dump_hex(payload);
    let (header, attrs) = tc::OpNewqdiscDo::decode_request(payload);

    assert_eq!(header.family, 0);
    assert_eq!(header.ifindex, 44);
    assert_eq!(header.handle, 65536);
    assert_eq!(header.parent, 4294967295);
    assert_eq!(header.info, 0);

    assert_eq!(attrs.get_kind(), Ok(c"prio"));
    let OptionsMsg::Prio(prio) = attrs.get_options().unwrap() else {
        unreachable!()
    };
    assert_eq!(prio.bands, 8);
    assert_eq!(
        prio.priomap,
        [7, 6, 5, 4, 3, 2, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,]
    );
}