Skip to content

Commit

Permalink
multiboot2: add NetworkTag
Browse files Browse the repository at this point in the history
  • Loading branch information
phip1611 committed Sep 1, 2024
1 parent 6b5f896 commit e9f23cf
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions multiboot2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added missing tags:
- `ApmTag`
- `BootdevTag`
- `NetworkTag`

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

Expand Down
11 changes: 10 additions & 1 deletion multiboot2/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::apm::ApmTag;
use crate::bootdev::BootdevTag;
use crate::network::NetworkTag;
use crate::{
BasicMemoryInfoTag, BootInformationHeader, BootLoaderNameTag, CommandLineTag,
EFIBootServicesNotExitedTag, EFIImageHandle32Tag, EFIImageHandle64Tag, EFIMemoryMapTag,
Expand Down Expand Up @@ -31,7 +32,7 @@ pub struct Builder {
smbios: Vec<Box<SmbiosTag>>,
rsdpv1: Option<RsdpV1Tag>,
rsdpv2: Option<RsdpV2Tag>,
// missing: network
network: Option<Box<NetworkTag>>,
efi_mmap: Option<Box<EFIMemoryMapTag>>,
efi_bs: Option<EFIBootServicesNotExitedTag>,
efi32_ih: Option<EFIImageHandle32Tag>,
Expand Down Expand Up @@ -67,6 +68,7 @@ impl Builder {
rsdpv1: None,
rsdpv2: None,
efi_mmap: None,
network: None,
efi_bs: None,
efi32_ih: None,
efi64_ih: None,
Expand Down Expand Up @@ -187,6 +189,13 @@ impl Builder {
self
}

/// Sets the [`NetworkTag`] tag.
#[must_use]
pub fn network(mut self, network: Box<NetworkTag>) -> Self {
self.network = Some(network);
self
}

/// Sets the [`EFIBootServicesNotExitedTag`] tag.
#[must_use]
pub const fn efi_bs(mut self, efi_bs: EFIBootServicesNotExitedTag) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod framebuffer;
mod image_load_addr;
mod memory_map;
mod module;
mod network;
mod rsdp;
mod smbios;
mod tag;
Expand Down Expand Up @@ -108,6 +109,7 @@ pub use memory_map::{
MemoryArea, MemoryAreaType, MemoryAreaTypeId, MemoryMapTag,
};
pub use module::{ModuleIter, ModuleTag};
pub use network::NetworkTag;
pub use ptr_meta::Pointee;
pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
pub use smbios::SmbiosTag;
Expand Down
43 changes: 43 additions & 0 deletions multiboot2/src/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Module for [`NetworkTag`].
use crate::{TagHeader, TagType, TagTypeId};
#[cfg(feature = "builder")]
use alloc::boxed::Box;
use core::mem;
use multiboot2_common::{new_boxed, MaybeDynSized, Tag};
use ptr_meta::Pointee;

/// The end tag ends the information struct.
#[derive(Debug, Pointee)]
#[repr(C, align(8))]
pub struct NetworkTag {
typ: TagTypeId,
size: u32,
dhcpack: [u8],
}

impl NetworkTag {
/// Create a new network tag from the given DHCP package.
#[cfg(feature = "builder")]
#[must_use]
pub fn new(dhcp_pack: &[u8]) -> Box<Self> {
let header = TagHeader::new(Self::ID, 0);
new_boxed(header, &[dhcp_pack])
}
}

impl MaybeDynSized for NetworkTag {
type Header = TagHeader;

const BASE_SIZE: usize = mem::size_of::<TagHeader>();

fn dst_len(header: &TagHeader) -> usize {
header.size as usize - Self::BASE_SIZE
}
}

impl Tag for NetworkTag {
type IDType = TagType;

const ID: TagType = TagType::Network;
}

0 comments on commit e9f23cf

Please sign in to comment.