|
1 | 1 | use anyhow::Error; |
2 | 2 | use anyhow::Ok; |
3 | 3 | use aya::Bpf; |
| 4 | +use aya::maps::HashMap; |
4 | 5 | use aya::maps::Map; |
| 6 | +use k8s_openapi::api::core::v1::ConfigMap; |
| 7 | +use kube::{Api, Client}; |
5 | 8 | use std::net::Ipv4Addr; |
6 | 9 | use std::path::PathBuf; |
7 | 10 | use std::str::FromStr; |
8 | 11 | use std::sync::Arc; |
9 | 12 | use std::sync::Mutex; |
10 | 13 | use tokio::fs; |
11 | 14 | use tracing::{error, info}; |
12 | | -use aya::maps::HashMap; |
13 | | -use k8s_openapi::api::core::v1::ConfigMap; |
14 | | -use kube::{Api, Client}; |
15 | 15 |
|
16 | 16 | pub fn init_bpf_maps(bpf: Arc<Mutex<Bpf>>) -> Result<(Map, Map, Map), anyhow::Error> { |
17 | 17 | // this function init the bpfs maps used in the main program |
@@ -81,19 +81,16 @@ pub async fn populate_blocklist(map: &mut Map) -> Result<(), Error> { |
81 | 81 | info!("[CONFIGMAP]: {:?} ", configs); |
82 | 82 | if let Some(data) = configs.data { |
83 | 83 | if let Some(blocklist) = data.get("blocklist") { |
84 | | - match serde_yaml::from_str::<Vec<String>>(&blocklist) { |
85 | | - std::result::Result::Ok(addresses) => { |
86 | | - info!("Inserting addresses: {:?}", addresses); |
87 | | - |
88 | | - for item in addresses{ |
89 | | - let addr = Ipv4Addr::from_str(&item)?.octets(); |
90 | | - let _ = blocklist_map.insert(addr,addr,0); |
91 | | - } |
92 | | - |
93 | | - } |
94 | | - std::result::Result::Err(e) => { |
95 | | - error!("Error during blocklist addresses import: {}", e); |
96 | | - } |
| 84 | + let addresses: Vec<String> = blocklist |
| 85 | + .lines() |
| 86 | + .map(|s| s.trim().to_string()) |
| 87 | + .filter(|s| !s.is_empty()) |
| 88 | + .collect(); |
| 89 | + //String parsing from "x y" to ["x","y"] |
| 90 | + info!("Inserting addresses: {:?}", addresses); |
| 91 | + for item in addresses { |
| 92 | + let addr = Ipv4Addr::from_str(&item)?.octets(); |
| 93 | + let _ = blocklist_map.insert(addr, addr, 0); |
97 | 94 | } |
98 | 95 | } |
99 | 96 | } |
|
0 commit comments