chiark / gitweb /
introduce MayRoute (loop prevention)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Aug 2021 23:16:59 +0000 (00:16 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Aug 2021 23:16:59 +0000 (00:16 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
server/server.rs
server/suser.rs
server/sweb.rs

index cfceef6e2783ca7913285b1de42169aa49186392..309368456f1a76f07bd0c7142d8000a39039a8f0 100644 (file)
@@ -38,10 +38,21 @@ pub struct RoutedPacket {
 // not MIME data, valid SLIP (checked)
 pub type RoutedPacketData = Box<[u8]>;
 
+// loop prevention
+mod may_route {
+  #[derive(Clone,Debug)]
+  pub struct MayRoute(());
+  impl MayRoute {
+    pub fn came_from_outside_hippotatd() -> Self { Self(()) }
+  }
+}
+pub use may_route::MayRoute;
+
 #[throws(PacketError)]
 pub async fn route_packet(global: &Global,
                           conn: &str, source: Option<&ClientName>,
-                          packet: RoutedPacketData, daddr: IpAddr)
+                          packet: RoutedPacketData, daddr: IpAddr,
+                          _may_route: MayRoute)
 {
   let c = &global.config;
   let len = packet.len();
index dec1a5aacd4cce857193fcc1cbe80afe224f48da..5b7ab0fae5895d0e8d80c8fd036599c671152048 100644 (file)
@@ -66,7 +66,7 @@ pub async fn run(global: Arc<Global>,
         let WebRequest {
           initial, initial_remaining, length_hint, mut body,
           boundary_finder,
-          reply_to, conn, mut warnings,
+          reply_to, conn, mut warnings, may_route,
         } = req.ok_or_else(|| anyhow!("webservers all shut down!"))?;
 
         match async {
@@ -142,7 +142,8 @@ pub async fn run(global: Arc<Global>,
               let daddr = ip_packet_addr::<true>(header)?;
               Ok(daddr)
             }, |(daddr,packet)| route_packet(
-              &global, &conn, Some(&ic.link.client), daddr,packet
+              &global, &conn, Some(&ic.link.client), daddr,
+              packet, may_route.clone(),
             ),
               |e| Ok::<_,SlipFramesError<_>>({ warnings.add(&e)?; })
             ).await?;
index 157261abe7864c2541f16439b837c73401f29914..d4e825e0886f60b093cf99e455379cc38b6a6153 100644 (file)
@@ -19,6 +19,7 @@ pub struct WebRequest {
   pub reply_to: oneshot::Sender<WebResponse>,
   pub warnings: Warnings,
   pub conn: Arc<String>,
+  pub may_route: MayRoute,
 }
 
 /// Reply from client task to hyper worker pool task
@@ -188,6 +189,7 @@ pub async fn handle(
       warnings: mem::take(&mut warnings),
       reply_to,
       conn: conn.clone(),
+      may_route: MayRoute::came_from_outside_hippotatd(),
     };
 
     client.web.try_send(wreq)