mirror of
https://github.com/DaLaw2/NetGuardia.git
synced 2026-08-24 14:10:28 +09:00
Rename some function and module
This commit is contained in:
parent
1da26de01c
commit
63a13e6176
@ -1,5 +1,5 @@
|
||||
pub mod access_control;
|
||||
pub mod defence;
|
||||
pub mod monitor;
|
||||
pub mod sampling;
|
||||
pub mod service;
|
||||
pub mod statistics;
|
||||
|
||||
@ -3,15 +3,14 @@
|
||||
mod action;
|
||||
mod utils;
|
||||
|
||||
use crate::action::{defence, service};
|
||||
use crate::utils::parsing;
|
||||
use action::{access_control, monitor};
|
||||
use action::{access_control, defence, statistics, service};
|
||||
use aya_ebpf::macros::{map, xdp};
|
||||
use aya_ebpf::maps::{PerCpuArray, ProgramArray};
|
||||
use aya_ebpf::{bindings::xdp_action, programs::XdpContext};
|
||||
use aya_log_ebpf::error;
|
||||
use net_guardia_common::model::event::Event;
|
||||
use network_types::eth::EtherType;
|
||||
use utils::parsing;
|
||||
|
||||
#[map]
|
||||
static PROGRAM_ARRAY: ProgramArray = ProgramArray::with_max_entries(8, 0);
|
||||
@ -159,24 +158,24 @@ unsafe fn try_sampling(ctx: XdpContext) -> Result<u32, ()> {
|
||||
}
|
||||
|
||||
#[xdp]
|
||||
pub fn monitor(ctx: XdpContext) -> u32 {
|
||||
match unsafe { try_monitor(ctx) } {
|
||||
pub fn statistics(ctx: XdpContext) -> u32 {
|
||||
match unsafe { try_statistics(ctx) } {
|
||||
Ok(ret) => ret,
|
||||
Err(_) => xdp_action::XDP_PASS,
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn try_monitor(_: XdpContext) -> Result<u32, ()> {
|
||||
unsafe fn try_statistics(_: XdpContext) -> Result<u32, ()> {
|
||||
let ptr = PARSED_PACKET.get_ptr(0).ok_or(())?;
|
||||
let parsed_packet = ptr.read();
|
||||
match parsed_packet.eth_type {
|
||||
EtherType::Ipv4 => {
|
||||
let event = parsed_packet.into_ipv4_event();
|
||||
monitor::ipv4_update_stats(&event);
|
||||
statistics::ipv4_update_stats(&event);
|
||||
}
|
||||
EtherType::Ipv6 => {
|
||||
let event = parsed_packet.into_ipv6_event();
|
||||
monitor::ipv6_update_stats(&event);
|
||||
statistics::ipv6_update_stats(&event);
|
||||
}
|
||||
_ => Err(())?,
|
||||
}
|
||||
|
||||
@ -15,14 +15,14 @@ use std::sync::OnceLock;
|
||||
use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use tracing::info;
|
||||
|
||||
static ACCESS_LIST: OnceLock<RwLock<AccessList>> = OnceLock::new();
|
||||
static ACCESS_CONTROL: OnceLock<RwLock<AccessControl>> = OnceLock::new();
|
||||
|
||||
pub struct AccessList {
|
||||
pub struct AccessControl {
|
||||
ipv4_maps: StdHashMap<(Direction, ListType), AccessMap<IPv4>>,
|
||||
ipv6_maps: StdHashMap<(Direction, ListType), AccessMap<IPv6>>,
|
||||
}
|
||||
|
||||
impl AccessList {
|
||||
impl AccessControl {
|
||||
const MAP_CONFIGS: [((Direction, ListType), (&'static str, &'static str)); 4] = [
|
||||
(
|
||||
(Direction::Source, ListType::White),
|
||||
@ -62,8 +62,8 @@ impl AccessList {
|
||||
},
|
||||
);
|
||||
}
|
||||
ACCESS_LIST.get_or_init(|| {
|
||||
RwLock::new(AccessList {
|
||||
ACCESS_CONTROL.get_or_init(|| {
|
||||
RwLock::new(AccessControl {
|
||||
ipv4_maps,
|
||||
ipv6_maps,
|
||||
})
|
||||
@ -73,14 +73,14 @@ impl AccessList {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub async fn instance() -> RwLockReadGuard<'static, AccessList> {
|
||||
let once_lock = ACCESS_LIST.get().unwrap();
|
||||
pub async fn instance() -> RwLockReadGuard<'static, AccessControl> {
|
||||
let once_lock = ACCESS_CONTROL.get().unwrap();
|
||||
once_lock.read().await
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub async fn instance_mut() -> RwLockWriteGuard<'static, AccessList> {
|
||||
let once_lock = ACCESS_LIST.get().unwrap();
|
||||
pub async fn instance_mut() -> RwLockWriteGuard<'static, AccessControl> {
|
||||
let once_lock = ACCESS_CONTROL.get().unwrap();
|
||||
once_lock.write().await
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ impl AccessList {
|
||||
direction: Direction,
|
||||
list_type: ListType,
|
||||
) -> StdHashMap<Ipv4Addr, Vec<Port>> {
|
||||
let access_list = AccessList::instance().await;
|
||||
let access_list = AccessControl::instance().await;
|
||||
access_list
|
||||
.ipv4_maps
|
||||
.get(&(direction, list_type))
|
||||
@ -100,7 +100,7 @@ impl AccessList {
|
||||
direction: Direction,
|
||||
list_type: ListType,
|
||||
) -> StdHashMap<Ipv6Addr, Vec<Port>> {
|
||||
let access_list = AccessList::instance().await;
|
||||
let access_list = AccessControl::instance().await;
|
||||
access_list
|
||||
.ipv6_maps
|
||||
.get(&(direction, list_type))
|
||||
@ -115,7 +115,7 @@ impl AccessList {
|
||||
) -> anyhow::Result<()> {
|
||||
let ip: u32 = (*address.ip()).into();
|
||||
let port = address.port();
|
||||
let mut access_list = AccessList::instance_mut().await;
|
||||
let mut access_list = AccessControl::instance_mut().await;
|
||||
let map = access_list
|
||||
.ipv4_maps
|
||||
.get_mut(&(direction, list_type))
|
||||
@ -130,7 +130,7 @@ impl AccessList {
|
||||
) -> anyhow::Result<()> {
|
||||
let ip: u128 = (*address.ip()).into();
|
||||
let port = address.port();
|
||||
let mut access_list = AccessList::instance_mut().await;
|
||||
let mut access_list = AccessControl::instance_mut().await;
|
||||
let map = access_list
|
||||
.ipv6_maps
|
||||
.get_mut(&(direction, list_type))
|
||||
@ -145,7 +145,7 @@ impl AccessList {
|
||||
) -> anyhow::Result<()> {
|
||||
let ip: u32 = (*address.ip()).into();
|
||||
let port = address.port();
|
||||
let mut access_list = AccessList::instance_mut().await;
|
||||
let mut access_list = AccessControl::instance_mut().await;
|
||||
let map = access_list
|
||||
.ipv4_maps
|
||||
.get_mut(&(direction, list_type))
|
||||
@ -160,7 +160,7 @@ impl AccessList {
|
||||
) -> anyhow::Result<()> {
|
||||
let ip: u128 = (*address.ip()).into();
|
||||
let port = address.port();
|
||||
let mut access_list = AccessList::instance_mut().await;
|
||||
let mut access_list = AccessControl::instance_mut().await;
|
||||
let map = access_list
|
||||
.ipv6_maps
|
||||
.get_mut(&(direction, list_type))
|
||||
@ -1,9 +1,9 @@
|
||||
use crate::core::control::access_list::AccessList;
|
||||
use crate::core::control::access_control::AccessControl;
|
||||
use crate::core::control::defence::Defence;
|
||||
use crate::core::control::sampling::Sampling;
|
||||
use crate::core::control::service::Service;
|
||||
|
||||
pub mod access_list;
|
||||
pub mod access_control;
|
||||
pub mod defence;
|
||||
pub mod service;
|
||||
pub mod sampling;
|
||||
@ -12,7 +12,7 @@ pub struct Control;
|
||||
|
||||
impl Control {
|
||||
pub async fn initialize() -> anyhow::Result<()> {
|
||||
AccessList::initialize().await?;
|
||||
AccessControl::initialize().await?;
|
||||
Defence::initialize().await?;
|
||||
Sampling::initialize().await?;
|
||||
Service::initialize().await
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pub mod config_manager;
|
||||
pub mod control;
|
||||
pub mod monitor;
|
||||
pub mod statistics;
|
||||
pub mod system;
|
||||
|
||||
@ -12,9 +12,9 @@ use std::sync::OnceLock;
|
||||
use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use tracing::info;
|
||||
|
||||
static MONITOR: OnceLock<RwLock<Monitor>> = OnceLock::new();
|
||||
static STATISTICS: OnceLock<RwLock<Statistics>> = OnceLock::new();
|
||||
|
||||
pub struct Monitor {
|
||||
pub struct Statistics {
|
||||
terminate: bool,
|
||||
ipv4_src_1min: AyaHashMap<MapData, EbpfAddrPortV4, EbpfFlowStats>,
|
||||
ipv4_src_10min: AyaHashMap<MapData, EbpfAddrPortV4, EbpfFlowStats>,
|
||||
@ -30,12 +30,12 @@ pub struct Monitor {
|
||||
ipv6_dst_1hour: AyaHashMap<MapData, EbpfAddrPortV6, EbpfFlowStats>,
|
||||
}
|
||||
|
||||
impl Monitor {
|
||||
impl Statistics {
|
||||
pub async fn initialize() -> anyhow::Result<()> {
|
||||
info!("{}", SystemEntry::Initializing);
|
||||
let mut system = System::instance_mut().await;
|
||||
let ebpf = &mut system.ebpf;
|
||||
let monitor = Monitor {
|
||||
let monitor = Statistics {
|
||||
terminate: false,
|
||||
ipv4_src_1min: AyaHashMap::try_from(ebpf.take_map("IPV4_SRC_1MIN").unwrap())?,
|
||||
ipv4_src_10min: AyaHashMap::try_from(ebpf.take_map("IPV4_SRC_10MIN").unwrap())?,
|
||||
@ -50,23 +50,23 @@ impl Monitor {
|
||||
ipv6_dst_10min: AyaHashMap::try_from(ebpf.take_map("IPV6_DST_10MIN").unwrap())?,
|
||||
ipv6_dst_1hour: AyaHashMap::try_from(ebpf.take_map("IPV6_DST_1HOUR").unwrap())?,
|
||||
};
|
||||
MONITOR.get_or_init(|| RwLock::new(monitor));
|
||||
STATISTICS.get_or_init(|| RwLock::new(monitor));
|
||||
info!("{}", SystemEntry::InitializeComplete);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub async fn instance() -> RwLockReadGuard<'static, Monitor> {
|
||||
pub async fn instance() -> RwLockReadGuard<'static, Statistics> {
|
||||
// Initialization has been ensured
|
||||
let once_lock = MONITOR.get().unwrap();
|
||||
let once_lock = STATISTICS.get().unwrap();
|
||||
// There is no lock acquired multiple times, so this is safe
|
||||
once_lock.read().await
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub async fn instance_mut() -> RwLockWriteGuard<'static, Monitor> {
|
||||
pub async fn instance_mut() -> RwLockWriteGuard<'static, Statistics> {
|
||||
// Initialization has been ensured
|
||||
let once_lock = MONITOR.get().unwrap();
|
||||
let once_lock = STATISTICS.get().unwrap();
|
||||
// There is no lock acquired multiple times, so this is safe
|
||||
once_lock.write().await
|
||||
}
|
||||
@ -74,14 +74,14 @@ impl Monitor {
|
||||
pub async fn run() {
|
||||
tokio::spawn(async {
|
||||
loop {
|
||||
Monitor::cleanup_expired_flows().await;
|
||||
Statistics::cleanup_expired_flows().await;
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub async fn terminate() {
|
||||
let mut monitor = Monitor::instance_mut().await;
|
||||
let mut monitor = Statistics::instance_mut().await;
|
||||
monitor.terminate = true;
|
||||
}
|
||||
|
||||
@ -90,24 +90,24 @@ impl Monitor {
|
||||
const TEN_MIN: u64 = 10 * ONE_MIN;
|
||||
const ONE_HOUR: u64 = 60 * ONE_MIN;
|
||||
|
||||
let mut monitor = Monitor::instance_mut().await;
|
||||
let mut monitor = Statistics::instance_mut().await;
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos() as u64;
|
||||
|
||||
Monitor::cleanup_map(&mut monitor.ipv4_src_1min, now, ONE_MIN).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv4_dst_1min, now, ONE_MIN).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv4_src_10min, now, TEN_MIN).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv4_dst_10min, now, TEN_MIN).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv4_src_1hour, now, ONE_HOUR).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv4_dst_1hour, now, ONE_HOUR).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv6_src_1min, now, ONE_MIN).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv6_dst_1min, now, ONE_MIN).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv6_src_10min, now, TEN_MIN).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv6_dst_10min, now, TEN_MIN).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv6_src_1hour, now, ONE_HOUR).await;
|
||||
Monitor::cleanup_map(&mut monitor.ipv6_dst_1hour, now, ONE_HOUR).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv4_src_1min, now, ONE_MIN).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv4_dst_1min, now, ONE_MIN).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv4_src_10min, now, TEN_MIN).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv4_dst_10min, now, TEN_MIN).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv4_src_1hour, now, ONE_HOUR).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv4_dst_1hour, now, ONE_HOUR).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv6_src_1min, now, ONE_MIN).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv6_dst_1min, now, ONE_MIN).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv6_src_10min, now, TEN_MIN).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv6_dst_10min, now, TEN_MIN).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv6_src_1hour, now, ONE_HOUR).await;
|
||||
Statistics::cleanup_map(&mut monitor.ipv6_dst_1hour, now, ONE_HOUR).await;
|
||||
}
|
||||
|
||||
async fn cleanup_map<K>(map: &mut AyaHashMap<MapData, K, EbpfFlowStats>, now: u64, window: u64)
|
||||
@ -137,7 +137,7 @@ impl Monitor {
|
||||
pub async fn get_ipv4_flow_data(
|
||||
ipv4_flow_type: IPv4FlowType,
|
||||
) -> StdHashMap<SocketAddrV4, FlowStats> {
|
||||
let monitor = Monitor::instance().await;
|
||||
let monitor = Statistics::instance().await;
|
||||
let iter = match ipv4_flow_type {
|
||||
IPv4FlowType::Src1Min => monitor.ipv4_src_1min.iter(),
|
||||
IPv4FlowType::Src10Min => monitor.ipv4_src_10min.iter(),
|
||||
@ -158,7 +158,7 @@ impl Monitor {
|
||||
pub async fn get_ipv6_flow_data(
|
||||
ipv6_flow_type: IPv6FlowType,
|
||||
) -> StdHashMap<SocketAddrV6, FlowStats> {
|
||||
let monitor = Monitor::instance().await;
|
||||
let monitor = Statistics::instance().await;
|
||||
let iter = match ipv6_flow_type {
|
||||
IPv6FlowType::Src1Min => monitor.ipv6_src_1min.iter(),
|
||||
IPv6FlowType::Src10Min => monitor.ipv6_src_10min.iter(),
|
||||
@ -1,10 +1,10 @@
|
||||
use crate::core::config_manager::ConfigManager;
|
||||
use crate::core::control::Control;
|
||||
use crate::core::monitor::Monitor;
|
||||
use crate::core::statistics::Statistics;
|
||||
use crate::utils::log_entry::ebpf::EbpfEntry;
|
||||
use crate::utils::log_entry::system::SystemEntry;
|
||||
use crate::utils::logging::Logging;
|
||||
use crate::web::api::{control, default, misc, monitor};
|
||||
use crate::web::api::{control, default, misc, statistics};
|
||||
use actix_web::web::route;
|
||||
use actix_web::{App, HttpServer};
|
||||
use anyhow::Context;
|
||||
@ -31,7 +31,7 @@ impl System {
|
||||
info!("{}", SystemEntry::Initializing);
|
||||
ConfigManager::initialization().await?;
|
||||
System::ebpf_initialize().await?;
|
||||
Monitor::initialize().await?;
|
||||
Statistics::initialize().await?;
|
||||
Control::initialize().await?;
|
||||
info!("{}", SystemEntry::InitializeComplete);
|
||||
Ok(())
|
||||
@ -55,7 +55,7 @@ impl System {
|
||||
Self::load_program(&mut ebpf, &mut program_array, "service", 1)?;
|
||||
// Self::load_program(&mut ebpf, &mut program_array, "defence", 2)?;
|
||||
Self::load_program(&mut ebpf, &mut program_array, "sampling", 3)?;
|
||||
Self::load_program(&mut ebpf, &mut program_array, "monitor", 4)?;
|
||||
Self::load_program(&mut ebpf, &mut program_array, "statistics", 4)?;
|
||||
let program: &mut Xdp = ebpf.program_mut("net_guardia").unwrap().try_into()?;
|
||||
program.load()?;
|
||||
program
|
||||
@ -98,7 +98,7 @@ impl System {
|
||||
|
||||
pub async fn run() -> anyhow::Result<()> {
|
||||
info!("{}", SystemEntry::Online);
|
||||
Monitor::run().await;
|
||||
Statistics::run().await;
|
||||
let config = ConfigManager::now().await;
|
||||
HttpServer::new(|| {
|
||||
let cors = actix_cors::Cors::default()
|
||||
@ -108,7 +108,7 @@ impl System {
|
||||
.max_age(3600);
|
||||
App::new()
|
||||
.wrap(cors)
|
||||
.service(monitor::initialize())
|
||||
.service(statistics::initialize())
|
||||
.service(control::initialize())
|
||||
.service(misc::initialize())
|
||||
.default_service(route().to(default::default_route))
|
||||
@ -121,7 +121,7 @@ impl System {
|
||||
|
||||
pub async fn terminate() -> anyhow::Result<()> {
|
||||
info!("{}", SystemEntry::Terminating);
|
||||
Monitor::terminate().await;
|
||||
Statistics::terminate().await;
|
||||
info!("{}", SystemEntry::TerminateComplete);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
use crate::core::control::access_list::AccessList;
|
||||
use crate::core::control::access_control::AccessControl;
|
||||
use crate::model::direction::Direction;
|
||||
use crate::model::list_type::ListType;
|
||||
use actix_web::{delete, get, put, web, HttpResponse, Responder, Scope};
|
||||
use std::net::{SocketAddrV4, SocketAddrV6};
|
||||
|
||||
pub fn initialize() -> Scope {
|
||||
web::scope("/access_list")
|
||||
web::scope("/access_control")
|
||||
.service(get_ipv4_list)
|
||||
.service(get_ipv6_list)
|
||||
.service(add_ipv4_list)
|
||||
@ -17,14 +17,14 @@ pub fn initialize() -> Scope {
|
||||
#[get("/ipv4/{direction}/{list_type}")]
|
||||
async fn get_ipv4_list(path: web::Path<(Direction, ListType)>) -> impl Responder {
|
||||
let (direction, list_type) = path.into_inner();
|
||||
let list = AccessList::get_ipv4_list(direction, list_type).await;
|
||||
let list = AccessControl::get_ipv4_list(direction, list_type).await;
|
||||
HttpResponse::Ok().json(list)
|
||||
}
|
||||
|
||||
#[get("/ipv6/{direction}/{list_type}")]
|
||||
async fn get_ipv6_list(path: web::Path<(Direction, ListType)>) -> impl Responder {
|
||||
let (direction, list_type) = path.into_inner();
|
||||
let list = AccessList::get_ipv6_list(direction, list_type).await;
|
||||
let list = AccessControl::get_ipv6_list(direction, list_type).await;
|
||||
HttpResponse::Ok().json(list)
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ async fn get_ipv6_list(path: web::Path<(Direction, ListType)>) -> impl Responder
|
||||
async fn add_ipv4_list(address: web::Json<SocketAddrV4>, path: web::Path<(Direction, ListType)>) -> impl Responder {
|
||||
let address = address.into_inner();
|
||||
let (direction, list_type) = path.into_inner();
|
||||
match AccessList::add_ipv4_list(direction, list_type, address).await {
|
||||
match AccessControl::add_ipv4_list(direction, list_type, address).await {
|
||||
Ok(_) => HttpResponse::Ok().finish(),
|
||||
Err(e) => HttpResponse::InternalServerError().body(e.to_string()),
|
||||
}
|
||||
@ -42,7 +42,7 @@ async fn add_ipv4_list(address: web::Json<SocketAddrV4>, path: web::Path<(Direct
|
||||
async fn add_ipv6_list(address: web::Json<SocketAddrV6>, path: web::Path<(Direction, ListType)>) -> impl Responder {
|
||||
let address = address.into_inner();
|
||||
let (direction, list_type) = path.into_inner();
|
||||
match AccessList::add_ipv6_list(direction, list_type, address).await {
|
||||
match AccessControl::add_ipv6_list(direction, list_type, address).await {
|
||||
Ok(_) => HttpResponse::Ok().finish(),
|
||||
Err(e) => HttpResponse::InternalServerError().body(e.to_string()),
|
||||
}
|
||||
@ -52,7 +52,7 @@ async fn add_ipv6_list(address: web::Json<SocketAddrV6>, path: web::Path<(Direct
|
||||
async fn remove_ipv4_list(address: web::Json<SocketAddrV4>, path: web::Path<(Direction, ListType)>) -> impl Responder {
|
||||
let address = address.into_inner();
|
||||
let (direction, list_type) = path.into_inner();
|
||||
match AccessList::remove_ipv4_list(direction, list_type, address).await {
|
||||
match AccessControl::remove_ipv4_list(direction, list_type, address).await {
|
||||
Ok(_) => HttpResponse::Ok().finish(),
|
||||
Err(e) => HttpResponse::InternalServerError().body(e.to_string()),
|
||||
}
|
||||
@ -62,7 +62,7 @@ async fn remove_ipv4_list(address: web::Json<SocketAddrV4>, path: web::Path<(Dir
|
||||
async fn remove_ipv6_list(address: web::Json<SocketAddrV6>, path: web::Path<(Direction, ListType)>) -> impl Responder {
|
||||
let address = address.into_inner();
|
||||
let (direction, list_type) = path.into_inner();
|
||||
match AccessList::remove_ipv6_list(direction, list_type, address).await {
|
||||
match AccessControl::remove_ipv6_list(direction, list_type, address).await {
|
||||
Ok(_) => HttpResponse::Ok().finish(),
|
||||
Err(e) => HttpResponse::InternalServerError().body(e.to_string()),
|
||||
}
|
||||
@ -1,13 +1,13 @@
|
||||
use actix_web::{web, Scope};
|
||||
|
||||
pub mod access_list;
|
||||
pub mod access_control;
|
||||
pub mod defence;
|
||||
pub mod sampling;
|
||||
pub mod service;
|
||||
|
||||
pub fn initialize() -> Scope {
|
||||
web::scope("/control")
|
||||
.service(access_list::initialize())
|
||||
.service(access_control::initialize())
|
||||
.service(defence::initialize())
|
||||
.service(sampling::initialize())
|
||||
.service(service::initialize())
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
pub mod default;
|
||||
pub mod control;
|
||||
pub mod misc;
|
||||
pub mod monitor;
|
||||
pub mod statistics;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
use crate::core::monitor::Monitor;
|
||||
use crate::core::statistics::Statistics;
|
||||
use crate::model::flow_type::{IPv4FlowType, IPv6FlowType};
|
||||
use actix_web::{get, web, Error, HttpRequest, HttpResponse, Responder, Scope};
|
||||
use actix_web_actors::ws::start;
|
||||
use crate::web::utils::flow_websocket::{IPv4FlowWebSocket, IPv6FlowWebSocket};
|
||||
|
||||
pub fn initialize() -> Scope {
|
||||
web::scope("/monitor")
|
||||
web::scope("/statistics")
|
||||
.service(get_ipv4_src_1min)
|
||||
.service(get_ipv4_src_10min)
|
||||
.service(get_ipv4_src_1hour)
|
||||
@ -24,73 +24,73 @@ pub fn initialize() -> Scope {
|
||||
|
||||
#[get("/get/ipv4/src/1min")]
|
||||
async fn get_ipv4_src_1min() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv4_flow_data(IPv4FlowType::Src1Min).await;
|
||||
let flow_data = Statistics::get_ipv4_flow_data(IPv4FlowType::Src1Min).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv4/src/10min")]
|
||||
async fn get_ipv4_src_10min() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv4_flow_data(IPv4FlowType::Src10Min).await;
|
||||
let flow_data = Statistics::get_ipv4_flow_data(IPv4FlowType::Src10Min).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv4/src/1hour")]
|
||||
async fn get_ipv4_src_1hour() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv4_flow_data(IPv4FlowType::Src1Hour).await;
|
||||
let flow_data = Statistics::get_ipv4_flow_data(IPv4FlowType::Src1Hour).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv6/src/1min")]
|
||||
async fn get_ipv6_src_1min() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv6_flow_data(IPv6FlowType::Src1Min).await;
|
||||
let flow_data = Statistics::get_ipv6_flow_data(IPv6FlowType::Src1Min).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv6/src/10min")]
|
||||
async fn get_ipv6_src_10min() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv6_flow_data(IPv6FlowType::Src10Min).await;
|
||||
let flow_data = Statistics::get_ipv6_flow_data(IPv6FlowType::Src10Min).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv6/src/1hour")]
|
||||
async fn get_ipv6_src_1hour() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv6_flow_data(IPv6FlowType::Src1Hour).await;
|
||||
let flow_data = Statistics::get_ipv6_flow_data(IPv6FlowType::Src1Hour).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv4/dst/1min")]
|
||||
async fn get_ipv4_dst_1min() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv4_flow_data(IPv4FlowType::Dst1Min).await;
|
||||
let flow_data = Statistics::get_ipv4_flow_data(IPv4FlowType::Dst1Min).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv4/dst/10min")]
|
||||
async fn get_ipv4_dst_10min() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv4_flow_data(IPv4FlowType::Dst10Min).await;
|
||||
let flow_data = Statistics::get_ipv4_flow_data(IPv4FlowType::Dst10Min).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv4/dst/1hour")]
|
||||
async fn get_ipv4_dst_1hour() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv4_flow_data(IPv4FlowType::Dst1Hour).await;
|
||||
let flow_data = Statistics::get_ipv4_flow_data(IPv4FlowType::Dst1Hour).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv6/dst/1min")]
|
||||
async fn get_ipv6_dst_1min() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv6_flow_data(IPv6FlowType::Src1Min).await;
|
||||
let flow_data = Statistics::get_ipv6_flow_data(IPv6FlowType::Src1Min).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv6/dst/10min")]
|
||||
async fn get_ipv6_dst_10min() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv6_flow_data(IPv6FlowType::Src10Min).await;
|
||||
let flow_data = Statistics::get_ipv6_flow_data(IPv6FlowType::Src10Min).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
#[get("/get/ipv6/dst/1hour")]
|
||||
async fn get_ipv6_dst_1hour() -> impl Responder {
|
||||
let flow_data = Monitor::get_ipv6_flow_data(IPv6FlowType::Src1Hour).await;
|
||||
let flow_data = Statistics::get_ipv6_flow_data(IPv6FlowType::Src1Hour).await;
|
||||
HttpResponse::Ok().json(web::Json(flow_data))
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::core::config_manager::ConfigManager;
|
||||
use crate::core::monitor::Monitor;
|
||||
use crate::core::statistics::Statistics;
|
||||
use crate::model::flow_type::{IPv4FlowType, IPv6FlowType};
|
||||
use actix::prelude::*;
|
||||
use actix_web_actors::ws;
|
||||
@ -19,7 +19,7 @@ impl Actor for IPv4FlowWebSocket {
|
||||
let interval = ctx.run_interval(refresh_interval, |actor, ctx| {
|
||||
let flow_type = actor.flow_type.clone();
|
||||
let future = async move {
|
||||
Monitor::get_ipv4_flow_data(flow_type).await
|
||||
Statistics::get_ipv4_flow_data(flow_type).await
|
||||
};
|
||||
ctx.wait(future.into_actor(actor).map(|flow_data, _, ctx| {
|
||||
if let Ok(json) = serde_json::to_string(&flow_data) {
|
||||
@ -65,7 +65,7 @@ impl Actor for IPv6FlowWebSocket {
|
||||
let interval = ctx.run_interval(refresh_interval, |actor, ctx| {
|
||||
let flow_type = actor.flow_type.clone();
|
||||
let future = async move {
|
||||
Monitor::get_ipv6_flow_data(flow_type).await
|
||||
Statistics::get_ipv6_flow_data(flow_type).await
|
||||
};
|
||||
ctx.wait(future.into_actor(actor).map(|flow_data, _, ctx| {
|
||||
if let Ok(json) = serde_json::to_string(&flow_data) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user