Add option to drop all connections from banned IPs
This instantly disconnects clients from banned IPs. Clients won't be able to request or ping the server status. Clients won't get a kick message with their ban reason either. Clients simply get a 'Disconnected' message on login.
This commit is contained in:
parent
28dbcdbfd6
commit
a71b3cb24f
@ -46,6 +46,11 @@ command = "java -Xmx1G -Xms1G -jar server.jar --nogui"
|
|||||||
# Block banned IPs as listed in banned-ips.json in server directory.
|
# Block banned IPs as listed in banned-ips.json in server directory.
|
||||||
#block_banned_ips = true
|
#block_banned_ips = true
|
||||||
|
|
||||||
|
# Drop connections from banned IPs.
|
||||||
|
# Banned IPs won't be able to ping or request server status.
|
||||||
|
# On connect, clients show a 'Disconnected' message rather than the ban reason.
|
||||||
|
#drop_banned_ips = false
|
||||||
|
|
||||||
[time]
|
[time]
|
||||||
# Sleep after number of seconds.
|
# Sleep after number of seconds.
|
||||||
#sleep_after = 60
|
#sleep_after = 60
|
||||||
|
@ -184,6 +184,10 @@ pub struct Server {
|
|||||||
/// Block banned IPs as listed in banned-ips.json in server directory.
|
/// Block banned IPs as listed in banned-ips.json in server directory.
|
||||||
#[serde(default = "bool_true")]
|
#[serde(default = "bool_true")]
|
||||||
pub block_banned_ips: bool,
|
pub block_banned_ips: bool,
|
||||||
|
|
||||||
|
/// Drop connections from banned IPs.
|
||||||
|
#[serde(default)]
|
||||||
|
pub drop_banned_ips: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Time configuration.
|
/// Time configuration.
|
||||||
|
@ -79,8 +79,12 @@ fn route(inbound: TcpStream, config: Arc<Config>, server: Arc<Server>) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check ban state
|
// Check ban state, just drop connection if enabled
|
||||||
let banned = server.is_banned_ip_blocking(&peer.ip());
|
let banned = server.is_banned_ip_blocking(&peer.ip());
|
||||||
|
if config.server.drop_banned_ips {
|
||||||
|
warn!(target: "lazymc", "Connection from banned IP {}, dropping", peer.ip());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Route connection through proper channel
|
// Route connection through proper channel
|
||||||
let should_proxy =
|
let should_proxy =
|
||||||
@ -147,7 +151,7 @@ pub fn route_proxy_address_queue(inbound: TcpStream, addr: SocketAddr, queue: By
|
|||||||
/// If disabled or on error, an empty list is returned.
|
/// If disabled or on error, an empty list is returned.
|
||||||
fn load_banned_ips(config: &Config) -> BannedIps {
|
fn load_banned_ips(config: &Config) -> BannedIps {
|
||||||
// Blocking banned IPs must be enabled
|
// Blocking banned IPs must be enabled
|
||||||
if !config.server.block_banned_ips {
|
if !config.server.block_banned_ips && !config.server.drop_banned_ips {
|
||||||
return BannedIps::default();
|
return BannedIps::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user