ftth_rtnl/
route.rs

1#![allow(unreachable_patterns)]
2
3use std::net::{Ipv4Addr, Ipv6Addr};
4
5use ftth_common::channel::{AsyncWorldClient, AsyncWorldServer};
6
7pub(crate) type Client = AsyncWorldClient<RtnlRouteRequest, RtnlRouteResponse>;
8pub(crate) type Server = AsyncWorldServer<RtnlRouteRequest, RtnlRouteResponse>;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct Ipv4Route {
12    if_id: Option<u32>, // 0 is the same as None
13    gateway: Option<Ipv4Addr>,
14    route: crate::Ipv4Net,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct Ipv6Route {
19    if_id: Option<u32>, // 0 is the same as None
20    gateway: Option<Ipv6Addr>,
21    route: crate::Ipv6Net,
22}
23
24#[derive(Debug, Clone, PartialEq)]
25#[non_exhaustive]
26pub enum RtnlRouteRequest {
27    Ipv4RouteList,
28    Ipv6RouteList,
29    Ipv4RouteAdd(Ipv4Route),
30    Ipv6RouteAdd(Ipv6Route),
31    Ipv4RouteDel(Ipv4Route),
32    Ipv6RouteDel(Ipv6Route),
33    Ipv4RouteGet(Ipv4Addr),
34    Ipv6RouteGet(Ipv6Addr),
35}
36
37#[derive(Debug, Clone, PartialEq)]
38#[non_exhaustive]
39pub enum RtnlRouteResponse {
40    Success,
41    Failed,
42    NotImplemented,
43    NotFound,
44    Ipv4RouteList(Vec<Ipv4Route>),
45    Ipv6RouteList(Vec<Ipv6Route>),
46    Ipv4Route(Ipv4Route),
47    Ipv6Route(Ipv6Route),
48}
49
50#[derive(Debug, Clone, PartialEq, Eq, Hash)]
51pub struct RtnlRouteClient {
52    client: Client,
53}
54
55impl RtnlRouteClient {
56    pub(crate) fn new(client: Client) -> Self {
57        Self {
58            client,
59        }
60    }
61}
62
63pub(crate) async fn run_server(mut server: Server, _handle: rtnetlink::RouteHandle) {
64    while let Some((req, respond)) = server.accept().await {
65        match req {
66            _ => respond(RtnlRouteResponse::NotImplemented),
67        }
68    }
69}