Skip to content

Commit d322775

Browse files
authored
Merge pull request #1181 from TheMasterOfDisasters/feature/ip-blacklist-cidr-support
feat: support CIDR ranges in imported IP blacklists
2 parents 8dad721 + 388c564 commit d322775

11 files changed

Lines changed: 161 additions & 365 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
All Sniffnet releases with the relative changes are documented in this file.
44

55
## [UNRELEASED]
6+
- Support CIDR ranges in imported IP blacklists ([#1181](https://github.com/GyulyVGC/sniffnet/pull/1181))
67
- Updated some of the existing translations to v1.5:
78
- Ukrainian ([#1039](https://github.com/GyulyVGC/sniffnet/pull/1039))
89
- German ([#1122](https://github.com/GyulyVGC/sniffnet/pull/1122))

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ ctrlc = { version = "3.5.2", features = ["termination"] }
4646
dns-lookup = "3.0.1"
4747
etherparse = "0.20.1"
4848
iced = { version = "0.14.0", features = ["tokio", "svg", "advanced", "lazy", "image"] }
49+
ipnet = "2.12.0"
4950
listeners = "0.5.1"
5051
maxminddb = "0.28.1"
5152
pcap = "2.4.0"
@@ -54,6 +55,7 @@ phf_shared = "0.13.1"
5455
picon = "0.1.0"
5556
plotters = { version = "0.3.7", default-features = false, features = ["area_series", "line_series"] }
5657
plotters-iced2 = "0.14.0"
58+
prefix-trie = { version = "0.8.3", features = ["ipnet"] }
5759
reqwest = { version = "0.13.3", features = ["json"] }
5860
rfd = "0.17.2"
5961
rodio = { version = "0.22.2", default-features = false, features = ["mp3", "playback"] }

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,3 @@ Follow the <a href="https://sniffnet.net/news"><b>news</b></a> and Sniffnet soci
195195
</td>
196196
</tr>
197197
</table>
198-
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
209.186.20.0/22
2+
209.186.24.0/21
3+
209.186.224.0/21
4+
209.186.232.0/22
5+
209.186.236.0/24
6+
209.233.156.0/22
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.2.3.0/24
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
8.8.8.8
2+
2001:db8::1
3+
1.2.3.0/24
4+
2001:db9::/32 # IPv6 test network
5+
5.6.7.0/24 ; SBL123456
6+
9.9.9.0/24 # inline hash comment
7+
# full-line hash comment
8+
; full-line semicolon comment
9+
invalid text that should be ignored

src/networking/types/bogon.rs

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,134 @@
1-
use crate::networking::types::ip_collection::IpCollection;
1+
use ipnet::IpNet;
22
use std::net::IpAddr;
33

44
pub struct Bogon {
5-
pub range: IpCollection,
5+
pub ranges: Vec<IpNet>,
66
pub description: &'static str,
77
}
88

99
// IPv4 bogons
1010

1111
static THIS_NETWORK: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
12-
range: IpCollection::new("0.0.0.0-0.255.255.255").unwrap(),
12+
ranges: vec!["0.0.0.0/8".parse().unwrap()],
1313
description: "\"this\" network",
1414
});
1515

1616
static PRIVATE_USE: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
17-
range: IpCollection::new(
18-
"10.0.0.0-10.255.255.255, 172.16.0.0-172.31.255.255, 192.168.0.0-192.168.255.255",
19-
)
20-
.unwrap(),
17+
ranges: vec![
18+
"10.0.0.0/8".parse().unwrap(),
19+
"172.16.0.0/12".parse().unwrap(),
20+
"192.168.0.0/16".parse().unwrap(),
21+
],
2122
description: "private-use",
2223
});
2324

2425
static CARRIER_GRADE: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
25-
range: IpCollection::new("100.64.0.0-100.127.255.255").unwrap(),
26+
ranges: vec!["100.64.0.0/10".parse().unwrap()],
2627
description: "carrier-grade NAT",
2728
});
2829

2930
static LOOPBACK: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
30-
range: IpCollection::new("127.0.0.0-127.255.255.255").unwrap(),
31+
ranges: vec!["127.0.0.0/8".parse().unwrap()],
3132
description: "loopback",
3233
});
3334

3435
static LINK_LOCAL: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
35-
range: IpCollection::new("169.254.0.0-169.254.255.255").unwrap(),
36+
ranges: vec!["169.254.0.0/16".parse().unwrap()],
3637
description: "link local",
3738
});
3839

3940
static IETF_PROTOCOL: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
40-
range: IpCollection::new("192.0.0.0-192.0.0.255").unwrap(),
41+
ranges: vec!["192.0.0.0/24".parse().unwrap()],
4142
description: "IETF protocol assignments",
4243
});
4344

4445
static TEST_NET_1: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
45-
range: IpCollection::new("192.0.2.0-192.0.2.255").unwrap(),
46+
ranges: vec!["192.0.2.0/24".parse().unwrap()],
4647
description: "TEST-NET-1",
4748
});
4849

4950
static NETWORK_INTERCONNECT: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
50-
range: IpCollection::new("198.18.0.0-198.19.255.255").unwrap(),
51+
ranges: vec!["198.18.0.0/15".parse().unwrap()],
5152
description: "network interconnect device benchmark testing",
5253
});
5354

5455
static TEST_NET_2: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
55-
range: IpCollection::new("198.51.100.0-198.51.100.255").unwrap(),
56+
ranges: vec!["198.51.100.0/24".parse().unwrap()],
5657
description: "TEST-NET-2",
5758
});
5859

5960
static TEST_NET_3: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
60-
range: IpCollection::new("203.0.113.0-203.0.113.255").unwrap(),
61+
ranges: vec!["203.0.113.0/24".parse().unwrap()],
6162
description: "TEST-NET-3",
6263
});
6364

6465
static MULTICAST: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
65-
range: IpCollection::new("224.0.0.0-239.255.255.255").unwrap(),
66+
ranges: vec!["224.0.0.0/4".parse().unwrap()],
6667
description: "multicast",
6768
});
6869

6970
static FUTURE_USE: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
70-
range: IpCollection::new("240.0.0.0-255.255.255.255").unwrap(),
71+
ranges: vec!["240.0.0.0/4".parse().unwrap()],
7172
description: "future use",
7273
});
7374

7475
// IPv6 bogons
7576

7677
static NODE_SCOPE_UNSPECIFIED: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
77-
range: IpCollection::new("::").unwrap(),
78+
ranges: vec!["::/128".parse().unwrap()],
7879
description: "node-scope unicast unspecified",
7980
});
8081

8182
static NODE_SCOPE_LOOPBACK: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
82-
range: IpCollection::new("::1").unwrap(),
83+
ranges: vec!["::1/128".parse().unwrap()],
8384
description: "node-scope unicast loopback",
8485
});
8586

8687
static IPV4_MAPPED: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
87-
range: IpCollection::new("::ffff:0.0.0.0-::ffff:255.255.255.255").unwrap(),
88+
ranges: vec!["::ffff:0.0.0.0/96".parse().unwrap()],
8889
description: "IPv4-mapped",
8990
});
9091

9192
static IPV4_COMPATIBLE: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
92-
range: IpCollection::new("::-::255.255.255.255").unwrap(),
93+
ranges: vec!["::/96".parse().unwrap()],
9394
description: "IPv4-compatible",
9495
});
9596

9697
static REMOTELY_TRIGGERED: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
97-
range: IpCollection::new("100::-100::ffff:ffff:ffff:ffff").unwrap(),
98+
ranges: vec!["100::/64".parse().unwrap()],
9899
description: "remotely triggered black hole",
99100
});
100101

101102
static ORCHID: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
102-
range: IpCollection::new("2001:10::-2001:1f:ffff:ffff:ffff:ffff:ffff:ffff").unwrap(),
103+
ranges: vec!["2001:10::/28".parse().unwrap()],
103104
description: "ORCHID",
104105
});
105106

106-
static DOCUMENTATION_PREFIX: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| {
107-
Bogon {
108-
range: IpCollection::new("2001:db8::-2001:db8:ffff:ffff:ffff:ffff:ffff:ffff, 3fff::-3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff")
109-
.unwrap(),
107+
static DOCUMENTATION_PREFIX: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
108+
ranges: vec![
109+
"2001:db8::/32".parse().unwrap(),
110+
"3fff::/20".parse().unwrap(),
111+
],
110112
description: "documentation prefix",
111-
}
112113
});
113114

114115
static ULA: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
115-
range: IpCollection::new("fc00::-fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").unwrap(),
116+
ranges: vec!["fc00::/7".parse().unwrap()],
116117
description: "ULA",
117118
});
118119

119120
static LINK_LOCAL_UNICAST: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
120-
range: IpCollection::new("fe80::-febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff").unwrap(),
121+
ranges: vec!["fe80::/10".parse().unwrap()],
121122
description: "link-local unicast",
122123
});
123124

124125
static SITE_LOCAL_UNICAST: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
125-
range: IpCollection::new("fec0::-feff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").unwrap(),
126+
ranges: vec!["fec0::/10".parse().unwrap()],
126127
description: "site-local unicast",
127128
});
128129

129130
static MULTICAST_V6: std::sync::LazyLock<Bogon> = std::sync::LazyLock::new(|| Bogon {
130-
range: IpCollection::new("ff00::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").unwrap(),
131+
ranges: vec!["ff00::/8".parse().unwrap()],
131132
description: "multicast v6",
132133
});
133134

@@ -163,7 +164,7 @@ static BOGONS: std::sync::LazyLock<Vec<&'static Bogon>> = std::sync::LazyLock::n
163164

164165
pub fn is_bogon(address: &IpAddr) -> Option<&'static str> {
165166
for bogon in BOGONS.iter() {
166-
if bogon.range.contains(address) {
167+
if bogon.ranges.iter().any(|net| net.contains(address)) {
167168
return Some(bogon.description);
168169
}
169170
}

0 commit comments

Comments
 (0)