1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#[macro_use]
extern crate bitflags;
#[derive(Debug)]
pub enum Error {
UnexpectedEof,
PrefixTooLarge,
}
#[derive(Debug)]
pub struct AddressBlock<'a> {
pub num_addr: usize,
pub head: Option<&'a [u8]>,
pub tail: Option<&'a [u8]>,
pub mid: Option<&'a [u8]>,
pub prefix_lengths: Option<&'a [u8]>,
}
bitflags! {
struct AddressBlockFlags: u8 {
const HAS_HEAD = 0x80;
const HAS_FULL_TAIL = 0x40;
const HAS_ZERO_TAIL = 0x20;
const HAS_SINGLE_PRELEN = 0x10;
const HAS_MULTI_PRELEN = 0x08;
const RESERVED0 = 0x04;
const RESERVED1 = 0x02;
const RESERVED2 = 0x01;
}
}
pub struct Tlv<'a> {
pub r#type: u8,
pub type_ext: Option<u8>,
pub start_index: Option<u8>,
pub stop_index: Option<u8>,
pub value: Option<&'a [u8]>,
}
bitflags! {
struct TlvFlags: u8 {
const HAS_TYPE_EXT = 0x80;
const HAS_SINGLE_INDEX = 0x40;
const HAS_MULTI_INDEX = 0x20;
const HAS_VALUE = 0x10;
const HAS_EXT_LEN = 0x08;
const IS_MULTI_VALUE = 0x04;
const RESERVED0 = 0x02;
const RESERVED1 = 0x01;
}
}
pub mod parser;