| 
					
				 | 
			
			
				@@ -4,18 +4,21 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use aya_bpf::{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     bindings::xdp_action, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     macros::{map, xdp}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    maps::HashMap, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    maps::Array, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     programs::XdpContext, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use aya_log_ebpf::info; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use responder_ebpf::util::*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use responder_ebpf::bindings::tcphdr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use responder_common::*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use core::mem; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const TCP_HDR_LEN: usize = mem::size_of::<tcphdr>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const IPPROTO_TCP: u8 = 0x06; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #[inline(always)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 fn parse_tcphdr(ctx: &XdpContext, cursor: &mut usize) -> Option<*mut tcphdr> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let tcp = ptr_at_mut::<tcphdr>(&ctx, *cursor); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -44,18 +47,31 @@ unsafe fn bounce_tcp(_ctx: &XdpContext, tcp: *mut tcphdr) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #[map(name = "FILTER_MAP")] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-static FILTER_MAP: HashMap<u32, u8> = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    HashMap::<u32, u8>::with_max_entries(0x4000000, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+static FILTER_MAP: Array<bloom_filter::ChunkType> = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Array::<bloom_filter::ChunkType>::with_max_entries(bloom_filter::MAP_SIZE as u32, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #[inline(always)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-unsafe fn matches_filter(daddr: IpAddr) -> bool { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+unsafe fn matches_filter(_ctx: &XdpContext, daddr: IpAddr) -> bool { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     match daddr { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         IpAddr::V4(daddr) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if let Some(b) = FILTER_MAP.get(&daddr) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                *b == 1u8 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for hash_offset in 0..bloom_filter::HASH_COUNT { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let hash = bloom_filter::hash(daddr, hash_offset); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let map_i = hash >> (bloom_filter::ADDRESS_BITS_CHUNK as u32); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let chunk_i = hash & (bloom_filter::ADDRESS_MASK_CHUNK as u32); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // info!(ctx, "{:ipv4} {} {} {}",daddr, hash, map_i, chunk_i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let test = if let Some(b) = FILTER_MAP.get(map_i as u32) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    let word_i = chunk_i & (bloom_filter::ADDRESS_MASK_WORD as u32); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    let chunk_i = (chunk_i as usize) >> bloom_filter::ADDRESS_BITS_WORD; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    // info!(ctx, "{} [{}]", word_i, b[chunk_i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    (b[chunk_i] >> (bloom_filter::ADDRESS_MASK_WORD as u32 - word_i)) & 1 == 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if !test { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    return false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         IpAddr::V6(_daddr) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             false // TODO 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -79,8 +95,7 @@ fn try_responder(ctx: XdpContext) -> Result<xdp_action::Type, xdp_action::Type> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return Ok(xdp_action::XDP_PASS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if unsafe { !matches_filter(daddr) } { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if unsafe { !matches_filter(&ctx, daddr) } { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return Ok(xdp_action::XDP_DROP); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -92,11 +107,11 @@ fn try_responder(ctx: XdpContext) -> Result<xdp_action::Type, xdp_action::Type> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let tcp_syn = unsafe { (*tcp).syn() }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let tcp_ack = unsafe { (*tcp).ack() }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    match daddr { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        IpAddr::V4(ip) => info!(&ctx, "Received packet with matching daddr: {:ipv4}", ip), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        IpAddr::V6(ip) => unsafe { info!(&ctx, "Received packet with matching daddr: {:ipv6}", ip.in6_u.u6_addr8) } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    info!(&ctx, "and tcp with syn: {}, ack: {}", tcp_syn, tcp_ack); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // match daddr { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //     IpAddr::V4(ip) => info!(&ctx, "Received packet with matching daddr: {:ipv4}", ip), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //     IpAddr::V6(ip) => unsafe { info!(&ctx, "Received packet with matching daddr: {:ipv6}", ip.in6_u.u6_addr8) } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // info!(&ctx, "and tcp with syn: {}, ack: {}", tcp_syn, tcp_ack); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if tcp_syn == 0 || tcp_ack != 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return Ok(xdp_action::XDP_PASS); 
			 |