1 // Copyright 2021 Ian Jackson and contributors to Hippotat
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 // There is NO WARRANTY.
7 #[allow(dead_code)] // xxx
8 #[allow(unused_variables)] // xxx
9 pub async fn run(global: Arc<Global>,
10 rx: mpsc::Receiver<RoutedPacket>,
11 mut ipif: Ipif) -> Result<Void,AE> {
13 let mut goodness: i32 = 0;
14 const GOODNESS_SHIFT: u8 = 8;
15 const GOODNESS_MIN: i32 = -16;
21 // xxx something something rx something
23 data = Ipif::next_frame(&mut ipif.tx) =>
26 let may_route = MayRoute::came_from_outside_hippotatd();
28 goodness -= goodness >> GOODNESS_SHIFT;
30 match checkn(SlipNoConv, global.config.mtu, &data, |header|{
31 let saddr = ip_packet_addr::<false>(header)?;
32 let daddr = ip_packet_addr::<true>(header)?;
33 if ! global.config.vnetwork.iter().any(|n| n.contains(&saddr)) {
34 throw!(PE::Src(saddr))
37 }, |(data, daddr)| route_packet(
38 &global, "ipif", None,
39 data, daddr, may_route.clone()
40 ).map(Ok), |pe| Ok(match pe {
42 PE::Src(saddr) => trace!(
44 "ipif local discard outside-vnets saddr={:?}",
47 other => throw!(other),
49 Ok(()) => goodness += 1,
52 error!("[good={}] invalid data from local tx ipif {}",
54 if goodness < GOODNESS_MIN {
55 throw!(anyhow!("too many bad packets, too few good ones!"))
64 ipif.quitting(None).await;