--wip-- [skip ci]
This commit is contained in:
Generated
+45
@@ -377,6 +377,7 @@ dependencies = [
|
|||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"udp_sas_async",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1459,6 +1460,16 @@ dependencies = [
|
|||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "os_socketaddr"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa149f3ec09cadeb41968390fcd71e6ea038a9a373d1d4eb070f4d9484d4b244"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking"
|
name = "parking"
|
||||||
version = "2.2.1"
|
version = "2.2.1"
|
||||||
@@ -2197,6 +2208,18 @@ version = "0.2.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "udp_sas_async"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "073390c0d7b1682a5f044db2f769b0564568f741b9a7e23b8494b79fc868d491"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"os_socketaddr",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.26"
|
version = "1.0.26"
|
||||||
@@ -2339,6 +2362,22 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-i686-pc-windows-gnu",
|
||||||
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-util"
|
name = "winapi-util"
|
||||||
version = "0.1.11"
|
version = "0.1.11"
|
||||||
@@ -2348,6 +2387,12 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-link"
|
name = "windows-link"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ thiserror = "2.0.21"
|
|||||||
tokio = { version = "1.52.1", features = ["full"] }
|
tokio = { version = "1.52.1", features = ["full"] }
|
||||||
ipxe = { path = "./ipxe" }
|
ipxe = { path = "./ipxe" }
|
||||||
axum = { version = "0.8.9", features = ["macros"] }
|
axum = { version = "0.8.9", features = ["macros"] }
|
||||||
|
udp_sas_async = { version = "0.2.0", features = ["async_tokio"] }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
test = false
|
test = false
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ fn main() {
|
|||||||
.get()
|
.get()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
])
|
])
|
||||||
|
.arg("DOWNLOAD_PROTO_HTTP=1")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"EMBED={}",
|
"EMBED={}",
|
||||||
manifest_dir
|
manifest_dir
|
||||||
|
|||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
#!ipxe
|
#!ipxe
|
||||||
|
|
||||||
dhcp
|
dhcp
|
||||||
|
chain boot.ipxe
|
||||||
echo "Hello, World!"
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{% set httpUrl = "http://192.168.1.1:8000" -%}
|
||||||
|
#!ipxe
|
||||||
|
echo Starting ${serial}
|
||||||
|
|
||||||
|
:start
|
||||||
|
goto node_${serial} || exit
|
||||||
|
# Default behavior (non install mode) is to exit iPXE script
|
||||||
|
|
||||||
|
{% for cluster in clusters%}
|
||||||
|
{% for _, node in cluster.nodes|items %}
|
||||||
|
{%- if node.install.serial -%}
|
||||||
|
# {{ cluster.name }}/{{ node.hostname }}
|
||||||
|
:node_{{ node.install.serial }}
|
||||||
|
imgfree
|
||||||
|
kernel https://pxe.factory.talos.dev/image/{{ node.schematic }}/v{{ cluster.version.talos }}/kernel-{{ node.arch }} {{ node.kernelArgs|join(" ") }} {% if node.install.auto %}talos.config={{httpUrl}}/talos/{{cluster.name}}/{{node.hostname}}.yaml{% endif +%}
|
||||||
|
initrd https://pxe.factory.talos.dev/image/{{ node.schematic }}/v{{ cluster.version.talos }}/initramfs-{{ node.arch }}.xz
|
||||||
|
boot
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
+8
-4
@@ -25,10 +25,7 @@ fn apply_netmask(
|
|||||||
Ok((*ip & *netmask).to_string())
|
Ok((*ip & *netmask).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PathEnvironment<'a> {
|
pub fn configure_environment(env: &mut Environment) {
|
||||||
pub fn new(path: &Path) -> Self {
|
|
||||||
let mut env = Environment::new();
|
|
||||||
|
|
||||||
// Configure jinja
|
// Configure jinja
|
||||||
env.set_trim_blocks(true);
|
env.set_trim_blocks(true);
|
||||||
env.set_lstrip_blocks(true);
|
env.set_lstrip_blocks(true);
|
||||||
@@ -65,6 +62,13 @@ impl<'a> PathEnvironment<'a> {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> PathEnvironment<'a> {
|
||||||
|
pub fn new(path: &Path) -> Self {
|
||||||
|
let mut env = Environment::new();
|
||||||
|
|
||||||
|
configure_environment(&mut env);
|
||||||
|
|
||||||
// Add path loader
|
// Add path loader
|
||||||
env.set_loader(path_loader(&path));
|
env.set_loader(path_loader(&path));
|
||||||
|
|||||||
+20
-3
@@ -10,14 +10,14 @@ use axum::{Router, debug_handler};
|
|||||||
use clap::{CommandFactory, Parser};
|
use clap::{CommandFactory, Parser};
|
||||||
use clap_complete::{Shell, generate as generate_complete};
|
use clap_complete::{Shell, generate as generate_complete};
|
||||||
use crete::cluster::Cluster;
|
use crete::cluster::Cluster;
|
||||||
use crete::environment::PathEnvironment;
|
use crete::environment::{PathEnvironment, configure_environment};
|
||||||
use crete::talosconfig::{get_current_context, set_context};
|
use crete::talosconfig::{get_current_context, set_context};
|
||||||
use crete::tftp::ServerError;
|
use crete::tftp::ServerError;
|
||||||
use crete::{get_configs_path, get_repo_path, set_repo_path, tftp};
|
use crete::{get_configs_path, get_repo_path, set_repo_path, tftp};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use ipxe::IPXE_DIR;
|
use ipxe::IPXE_DIR;
|
||||||
use minijinja::context;
|
use minijinja::{Environment, context};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::{StatusCode, header};
|
use reqwest::{StatusCode, header};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@@ -145,7 +145,24 @@ fn get_file(filename: impl Into<String>) -> impl Future<Output = Option<(Vec<u8>
|
|||||||
|
|
||||||
async move {
|
async move {
|
||||||
const IPXE_PATTERN: &str = "ipxe/";
|
const IPXE_PATTERN: &str = "ipxe/";
|
||||||
if let Some(filename) = filename.strip_prefix(IPXE_PATTERN) {
|
if filename == format!("{IPXE_PATTERN}boot.ipxe") {
|
||||||
|
let mut env = Environment::new();
|
||||||
|
|
||||||
|
configure_environment(&mut env);
|
||||||
|
|
||||||
|
let template = env
|
||||||
|
.template_from_str(include_str!("./boot.ipxe"))
|
||||||
|
.expect("Template should be valid");
|
||||||
|
|
||||||
|
let clusters = Cluster::get_all().await;
|
||||||
|
let content = template
|
||||||
|
.render(context! {
|
||||||
|
clusters => clusters.values().collect::<Vec<_>>(),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Some((content.into(), "text/plain; charset=utf-8"))
|
||||||
|
} else if let Some(filename) = filename.strip_prefix(IPXE_PATTERN) {
|
||||||
Some((
|
Some((
|
||||||
IPXE_DIR.get_file(filename)?.contents().to_owned(),
|
IPXE_DIR.get_file(filename)?.contents().to_owned(),
|
||||||
"application/octet-stream",
|
"application/octet-stream",
|
||||||
|
|||||||
+4
-5
@@ -3,7 +3,7 @@ use std::net::SocketAddr;
|
|||||||
|
|
||||||
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||||
use tokio::net::UdpSocket;
|
use udp_sas_async::tokio::UdpSocketSas;
|
||||||
|
|
||||||
use crate::tftp::Error;
|
use crate::tftp::Error;
|
||||||
|
|
||||||
@@ -309,16 +309,15 @@ impl Packet {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn recv_from(socket: &UdpSocket) -> Result<(Self, SocketAddr), Error> {
|
pub async fn recv_from(socket: &UdpSocketSas) -> Result<(Self, SocketAddr), Error> {
|
||||||
let mut buf = Vec::with_capacity(PACKET_SIZE);
|
let mut buf = Vec::with_capacity(PACKET_SIZE);
|
||||||
let (_, src) = socket.recv_buf_from(&mut buf).await?;
|
let (_, src) = socket.recv_from(&mut buf).await?;
|
||||||
|
|
||||||
let packet = buf.try_into()?;
|
let packet = buf.try_into()?;
|
||||||
|
|
||||||
Ok((packet, src))
|
Ok((packet, src))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_to(&self, socket: &UdpSocket, src: &SocketAddr) -> Result<(), Error> {
|
pub async fn send_to(&self, socket: &UdpSocketSas, src: SocketAddr) -> Result<(), Error> {
|
||||||
let buf: Vec<_> = self.try_into()?;
|
let buf: Vec<_> = self.try_into()?;
|
||||||
socket.send_to(&buf, src).await?;
|
socket.send_to(&buf, src).await?;
|
||||||
|
|
||||||
|
|||||||
+23
-17
@@ -1,9 +1,9 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::net::SocketAddr;
|
use std::net::{IpAddr, SocketAddr};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::net::UdpSocket;
|
use udp_sas_async::tokio::UdpSocketSas;
|
||||||
|
|
||||||
use crate::tftp::packet::{ErrorCode, Mode};
|
use crate::tftp::packet::{ErrorCode, Mode};
|
||||||
use crate::tftp::{self, Packet};
|
use crate::tftp::{self, Packet};
|
||||||
@@ -29,23 +29,25 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_connection<F, Fut>(
|
pub async fn handle_connection<F, Fut>(
|
||||||
src: SocketAddr,
|
|
||||||
packet: Packet,
|
packet: Packet,
|
||||||
|
src: SocketAddr,
|
||||||
|
dest: IpAddr,
|
||||||
callback: F,
|
callback: F,
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
F: Fn(&str) -> Fut,
|
F: Fn(&str) -> Fut,
|
||||||
Fut: Future<Output = Option<Vec<u8>>>,
|
Fut: Future<Output = Option<Vec<u8>>>,
|
||||||
{
|
{
|
||||||
let socket = UdpSocket::bind("0.0.0.0:0").await?;
|
let socket = UdpSocketSas::bind(
|
||||||
println!(
|
format!("{dest}:0")
|
||||||
"{src}: Connecting from {}",
|
.parse()
|
||||||
socket.local_addr().expect("Socket is bound")
|
.expect("Address should be valid"),
|
||||||
);
|
)?;
|
||||||
|
println!("{src}: Connecting from {}", socket.local_addr());
|
||||||
|
|
||||||
let Packet::Read(request) = packet else {
|
let Packet::Read(request) = packet else {
|
||||||
Packet::error(ErrorCode::NotDefined, "Operation not supported")
|
Packet::error(ErrorCode::NotDefined, "Operation not supported")
|
||||||
.send_to(&socket, &src)
|
.send_to(&socket, src)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Err(Error::UnsupportedOperation(packet));
|
return Err(Error::UnsupportedOperation(packet));
|
||||||
@@ -56,7 +58,7 @@ where
|
|||||||
|
|
||||||
let Some(data) = callback(filename).await else {
|
let Some(data) = callback(filename).await else {
|
||||||
Packet::error(ErrorCode::FileNotFound, "Unknown file")
|
Packet::error(ErrorCode::FileNotFound, "Unknown file")
|
||||||
.send_to(&socket, &src)
|
.send_to(&socket, src)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Err(Error::FileNotFound(filename.into()));
|
return Err(Error::FileNotFound(filename.into()));
|
||||||
@@ -72,7 +74,7 @@ where
|
|||||||
ErrorCode::NotDefined,
|
ErrorCode::NotDefined,
|
||||||
format!("Mode {mode:?} is not supported"),
|
format!("Mode {mode:?} is not supported"),
|
||||||
)
|
)
|
||||||
.send_to(&socket, &src)
|
.send_to(&socket, src)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Err(Error::UnsupportedMode(mode));
|
return Err(Error::UnsupportedMode(mode));
|
||||||
@@ -88,10 +90,9 @@ where
|
|||||||
// Send the first chunk
|
// Send the first chunk
|
||||||
if let Some((index, chunk)) = chunk {
|
if let Some((index, chunk)) = chunk {
|
||||||
Packet::data((index + 1) as u16, chunk)
|
Packet::data((index + 1) as u16, chunk)
|
||||||
.send_to(&socket, &src)
|
.send_to(&socket, src)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
recv = Packet::recv_from(&socket) => {
|
recv = Packet::recv_from(&socket) => {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
@@ -101,7 +102,7 @@ where
|
|||||||
// really know how to test it properly so we don't support it.
|
// really know how to test it properly so we don't support it.
|
||||||
if new_src != src {
|
if new_src != src {
|
||||||
Packet::error(ErrorCode::Illegal, "Source changed")
|
Packet::error(ErrorCode::Illegal, "Source changed")
|
||||||
.send_to(&socket, &src)
|
.send_to(&socket, src)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Err(Error::SourceChanged(new_src));
|
return Err(Error::SourceChanged(new_src));
|
||||||
@@ -122,7 +123,7 @@ where
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
Packet::error(ErrorCode::Illegal, "Unexpected packet")
|
Packet::error(ErrorCode::Illegal, "Unexpected packet")
|
||||||
.send_to(&socket, &src)
|
.send_to(&socket, src)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
||||||
@@ -150,16 +151,21 @@ where
|
|||||||
F: Fn(&str) -> Fut + Clone + Send + 'static,
|
F: Fn(&str) -> Fut + Clone + Send + 'static,
|
||||||
Fut: Future<Output = Option<Vec<u8>>> + Send + 'static,
|
Fut: Future<Output = Option<Vec<u8>>> + Send + 'static,
|
||||||
{
|
{
|
||||||
let socket = UdpSocket::bind("0.0.0.0:69").await?;
|
let socket = UdpSocketSas::bind("0.0.0.0:69".parse().expect("Address should be valid"))?;
|
||||||
|
|
||||||
println!("Server started");
|
println!("Server started");
|
||||||
loop {
|
loop {
|
||||||
|
let mut buf = Vec::with_capacity(0);
|
||||||
|
let (bytes, src, dest) = socket.recv_sas(&mut buf).await?;
|
||||||
|
println!("{src} -> {dest}");
|
||||||
|
println!("{bytes}, {}", buf.len());
|
||||||
|
|
||||||
let (packet, src) = Packet::recv_from(&socket).await?;
|
let (packet, src) = Packet::recv_from(&socket).await?;
|
||||||
|
|
||||||
let callback = callback.clone();
|
let callback = callback.clone();
|
||||||
tokio::spawn({
|
tokio::spawn({
|
||||||
async move {
|
async move {
|
||||||
if let Err(err) = handle_connection(src, packet, callback).await {
|
if let Err(err) = handle_connection(packet, src, dest, callback).await {
|
||||||
println!("{src}: {err}")
|
println!("{src}: {err}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user