use super::{
QDiscDelRequest,
QDiscGetRequest,
QDiscNewRequest,
TrafficChainGetRequest,
TrafficClassGetRequest,
TrafficFilterGetRequest,
TrafficFilterNewRequest,
};
use crate::{
packet::{TcMessage, NLM_F_CREATE, NLM_F_EXCL, NLM_F_REPLACE},
Handle,
};
pub struct QDiscHandle(Handle);
impl QDiscHandle {
pub fn new(handle: Handle) -> Self {
QDiscHandle(handle)
}
pub fn get(&mut self) -> QDiscGetRequest {
QDiscGetRequest::new(self.0.clone())
}
pub fn add(&mut self, index: i32) -> QDiscNewRequest {
let msg = TcMessage::with_index(index);
QDiscNewRequest::new(self.0.clone(), msg, NLM_F_EXCL | NLM_F_CREATE)
}
pub fn change(&mut self, index: i32) -> QDiscNewRequest {
let msg = TcMessage::with_index(index);
QDiscNewRequest::new(self.0.clone(), msg, 0)
}
pub fn replace(&mut self, index: i32) -> QDiscNewRequest {
let msg = TcMessage::with_index(index);
QDiscNewRequest::new(self.0.clone(), msg, NLM_F_CREATE | NLM_F_REPLACE)
}
pub fn link(&mut self, index: i32) -> QDiscNewRequest {
let msg = TcMessage::with_index(index);
QDiscNewRequest::new(self.0.clone(), msg, NLM_F_REPLACE)
}
pub fn del(&mut self, index: i32) -> QDiscDelRequest {
let msg = TcMessage::with_index(index);
QDiscDelRequest::new(self.0.clone(), msg)
}
}
pub struct TrafficClassHandle {
handle: Handle,
ifindex: i32,
}
impl TrafficClassHandle {
pub fn new(handle: Handle, ifindex: i32) -> Self {
TrafficClassHandle { handle, ifindex }
}
pub fn get(&mut self) -> TrafficClassGetRequest {
TrafficClassGetRequest::new(self.handle.clone(), self.ifindex)
}
}
pub struct TrafficFilterHandle {
handle: Handle,
ifindex: i32,
}
impl TrafficFilterHandle {
pub fn new(handle: Handle, ifindex: i32) -> Self {
TrafficFilterHandle { handle, ifindex }
}
pub fn get(&mut self) -> TrafficFilterGetRequest {
TrafficFilterGetRequest::new(self.handle.clone(), self.ifindex)
}
pub fn add(&mut self) -> TrafficFilterNewRequest {
TrafficFilterNewRequest::new(self.handle.clone(), self.ifindex, NLM_F_EXCL | NLM_F_CREATE)
}
pub fn change(&mut self) -> TrafficFilterNewRequest {
TrafficFilterNewRequest::new(self.handle.clone(), self.ifindex, 0)
}
pub fn replace(&mut self) -> TrafficFilterNewRequest {
TrafficFilterNewRequest::new(self.handle.clone(), self.ifindex, NLM_F_CREATE)
}
}
pub struct TrafficChainHandle {
handle: Handle,
ifindex: i32,
}
impl TrafficChainHandle {
pub fn new(handle: Handle, ifindex: i32) -> Self {
TrafficChainHandle { handle, ifindex }
}
pub fn get(&mut self) -> TrafficChainGetRequest {
TrafficChainGetRequest::new(self.handle.clone(), self.ifindex)
}
}