Skip to content

Commit e9f23cf

Browse files
committed
multiboot2: add NetworkTag
1 parent 6b5f896 commit e9f23cf

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

multiboot2/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added missing tags:
88
- `ApmTag`
99
- `BootdevTag`
10+
- `NetworkTag`
1011

1112
## v0.22.2 (2024-08-24)
1213

multiboot2/src/builder.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::apm::ApmTag;
44
use crate::bootdev::BootdevTag;
5+
use crate::network::NetworkTag;
56
use crate::{
67
BasicMemoryInfoTag, BootInformationHeader, BootLoaderNameTag, CommandLineTag,
78
EFIBootServicesNotExitedTag, EFIImageHandle32Tag, EFIImageHandle64Tag, EFIMemoryMapTag,
@@ -31,7 +32,7 @@ pub struct Builder {
3132
smbios: Vec<Box<SmbiosTag>>,
3233
rsdpv1: Option<RsdpV1Tag>,
3334
rsdpv2: Option<RsdpV2Tag>,
34-
// missing: network
35+
network: Option<Box<NetworkTag>>,
3536
efi_mmap: Option<Box<EFIMemoryMapTag>>,
3637
efi_bs: Option<EFIBootServicesNotExitedTag>,
3738
efi32_ih: Option<EFIImageHandle32Tag>,
@@ -67,6 +68,7 @@ impl Builder {
6768
rsdpv1: None,
6869
rsdpv2: None,
6970
efi_mmap: None,
71+
network: None,
7072
efi_bs: None,
7173
efi32_ih: None,
7274
efi64_ih: None,
@@ -187,6 +189,13 @@ impl Builder {
187189
self
188190
}
189191

192+
/// Sets the [`NetworkTag`] tag.
193+
#[must_use]
194+
pub fn network(mut self, network: Box<NetworkTag>) -> Self {
195+
self.network = Some(network);
196+
self
197+
}
198+
190199
/// Sets the [`EFIBootServicesNotExitedTag`] tag.
191200
#[must_use]
192201
pub const fn efi_bs(mut self, efi_bs: EFIBootServicesNotExitedTag) -> Self {

multiboot2/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ mod framebuffer;
7878
mod image_load_addr;
7979
mod memory_map;
8080
mod module;
81+
mod network;
8182
mod rsdp;
8283
mod smbios;
8384
mod tag;
@@ -108,6 +109,7 @@ pub use memory_map::{
108109
MemoryArea, MemoryAreaType, MemoryAreaTypeId, MemoryMapTag,
109110
};
110111
pub use module::{ModuleIter, ModuleTag};
112+
pub use network::NetworkTag;
111113
pub use ptr_meta::Pointee;
112114
pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
113115
pub use smbios::SmbiosTag;

multiboot2/src/network.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//! Module for [`NetworkTag`].
2+
3+
use crate::{TagHeader, TagType, TagTypeId};
4+
#[cfg(feature = "builder")]
5+
use alloc::boxed::Box;
6+
use core::mem;
7+
use multiboot2_common::{new_boxed, MaybeDynSized, Tag};
8+
use ptr_meta::Pointee;
9+
10+
/// The end tag ends the information struct.
11+
#[derive(Debug, Pointee)]
12+
#[repr(C, align(8))]
13+
pub struct NetworkTag {
14+
typ: TagTypeId,
15+
size: u32,
16+
dhcpack: [u8],
17+
}
18+
19+
impl NetworkTag {
20+
/// Create a new network tag from the given DHCP package.
21+
#[cfg(feature = "builder")]
22+
#[must_use]
23+
pub fn new(dhcp_pack: &[u8]) -> Box<Self> {
24+
let header = TagHeader::new(Self::ID, 0);
25+
new_boxed(header, &[dhcp_pack])
26+
}
27+
}
28+
29+
impl MaybeDynSized for NetworkTag {
30+
type Header = TagHeader;
31+
32+
const BASE_SIZE: usize = mem::size_of::<TagHeader>();
33+
34+
fn dst_len(header: &TagHeader) -> usize {
35+
header.size as usize - Self::BASE_SIZE
36+
}
37+
}
38+
39+
impl Tag for NetworkTag {
40+
type IDType = TagType;
41+
42+
const ID: TagType = TagType::Network;
43+
}

0 commit comments

Comments
 (0)