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
| | // SPDX-License-Identifier: EUPL-1.2+
// SPDX-FileCopyrightText: 2025 Yureka Lilian <yureka@cyberchaos.dev>
use zerocopy::byteorder::network_endian::{U16, U32};
use zerocopy::*;
pub const ETHER_TYPE_IPV6: u16 = 0x86dd;
pub const ETHER_TYPE_802_1Q: u16 = 0x8100;
pub const IP_PROTO_ICMP6: u8 = 0x3a;
pub const ICMP6_TYPE_R_ADV: u8 = 134;
pub type MacAddr = [u8; 6];
pub fn is_multicast(mac: &MacAddr) -> bool {
match mac {
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff] => true,
[0x01, 0x80, 0xc2, _, _, _] => true, // 802 group
[0x33, 0x33, _, _, _, _] => true, // IPv6 multicast
_ => false,
}
}
#[derive(Debug, PartialEq, Eq, FromBytes, IntoBytes, KnownLayout, Immutable, Unaligned)]
#[repr(C)]
pub struct EtherFrame {
pub dst_addr: MacAddr,
pub src_addr: MacAddr,
}
pub type EtherType = U16;
#[derive(Debug, PartialEq, Eq, FromBytes, IntoBytes, KnownLayout, Immutable, Unaligned)]
#[repr(C)]
pub struct VlanTag {
pub ether_type: U16,
pub tag_control_information: U16,
}
#[derive(Debug, PartialEq, Eq, FromBytes, IntoBytes, KnownLayout, Immutable, Unaligned)]
#[repr(C)]
pub struct Ipv6Header {
pub version_traffic_class_flow_label: U32,
pub payload_length: U16,
pub next_header: u8,
pub hop_limit: u8,
pub src_addr: [u8; 16],
pub dst_addr: [u8; 16],
}
#[derive(Debug, PartialEq, Eq, FromBytes, IntoBytes, KnownLayout, Immutable, Unaligned)]
#[repr(C)]
pub struct Icmpv6Header {
pub msg_type: u8,
pub code: u8,
pub checksum: U16,
}
#[derive(Debug, PartialEq, Eq, FromBytes, IntoBytes, KnownLayout, Immutable, Unaligned)]
#[repr(C)]
pub struct Icmpv6RouterAdvertisement {
pub hop_limit: u8,
pub flags: u8,
pub router_lifetime: U16,
pub reachable_time: U32,
pub retrans_timer: U32,
}
|