patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 341b7ff5c2406146101216bcba0e203ce3293112 1797 bytes (raw)
name: tools/router/src/protocol.rs 	 # note: path name is non-authoritative(*)

 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,
}

debug log:

solving 341b7ff ...
found 341b7ff in https://inbox.spectrum-os.org/spectrum-devel/20251128223038.97536-5-yureka@cyberchaos.dev/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20251129194404.37773-7-yureka@cyberchaos.dev/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20251129181514.20296-7-yureka@cyberchaos.dev/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20251128223038.97536-5-yureka@cyberchaos.dev/
diff --git a/tools/router/src/protocol.rs b/tools/router/src/protocol.rs
new file mode 100644
index 0000000..341b7ff

Checking patch tools/router/src/protocol.rs...
Applied patch tools/router/src/protocol.rs cleanly.

skipping https://inbox.spectrum-os.org/spectrum-devel/20251129194404.37773-7-yureka@cyberchaos.dev/ for 341b7ff
skipping https://inbox.spectrum-os.org/spectrum-devel/20251129181514.20296-7-yureka@cyberchaos.dev/ for 341b7ff
index at:
100644 341b7ff5c2406146101216bcba0e203ce3293112	tools/router/src/protocol.rs

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).