diff options
| author | Christian Hopps <chopps@labn.net> | 2024-09-22 00:46:48 -0400 |
|---|---|---|
| committer | Christian Hopps <chopps@labn.net> | 2025-03-03 11:42:07 +0000 |
| commit | fff9e3fbcb856b198a61a62e5f91ea08ee60b213 (patch) | |
| tree | 14afb621b1ce98207f480f5863e06fce2639d81b /rustbind/rustbin_main.rs | |
| parent | dfc2f24cb325e71b9f58c38768637e8f28674fa2 (diff) | |
rustbind: capture rust binary based daemon skeleton code work
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'rustbind/rustbin_main.rs')
| -rw-r--r-- | rustbind/rustbin_main.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/rustbind/rustbin_main.rs b/rustbind/rustbin_main.rs new file mode 100644 index 0000000000..acbe930e65 --- /dev/null +++ b/rustbind/rustbin_main.rs @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// +// September 9 2024, Christian Hopps <chopps@labn.net> +// +// Copyright (C) 2024 LabN Consulting, L.L.C. +// + +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +use std::ffi::{CStr, CString}; +use std::os::raw::c_char; + +// #[path = "rust_server.rs"] +// pub mod rust; +// Need to figure best way to do shared source files +// #[path = "../lib/rust_msg.rs"] +// pub mod msg; + +use tracing::debug; + +extern "C" { + // This is our C init function we use to handle the complex compiler tricks + // FRR uses for initializing the daemon info structure. + fn rust_get_daemon_info() -> *mut frr_daemon_info; +} + +/// +/// Setup the trace logging. +/// +fn setup_logging() { + /* + * Enable some logging + */ + let subscriber = tracing_subscriber::FmtSubscriber::builder() + .with_max_level(tracing::Level::TRACE) + .finish(); + tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); +} + +/// +/// Main Function :) +/// +fn main() { + setup_logging(); + + // Initialize FRR. + + // create a vector of zero terminated CLI arg strings + let args = std::env::args() + .map(|arg| CString::new(arg).unwrap()) + .collect::<Vec<CString>>(); + + // convert the strings to raw pointers + let c_args = args + .iter() + .map(|arg| arg.as_ptr()) + .collect::<Vec<*const c_char>>(); + + // Get frr_daemon_info from our C init module + let di = unsafe { rust_get_daemon_info() }; + + // Initialize FRR + unsafe { frr_preinit(di, c_args.len() as i32, c_args.as_ptr() as *mut *mut i8) } + + debug!("daemon name is {:?}", unsafe { + CStr::from_ptr((*di).progname) + }); + + let master = unsafe { frr_init() }; + debug!("master thread: {:?}", master); + + // Run! + debug!("Running main FRR loop"); + unsafe { frr_run(master) }; +} |
