ripset
Pure Rust library for managing Linux ipset and nftables sets via the netlink protocol.
Features
- Zero external dependencies - No shelling out to
ipsetornftcommands - ipset support - Create, destroy, flush, list sets; add, delete, test IP addresses
- nftables support - Create/delete tables and sets; add, delete, test, list IP addresses
- IPv4 and IPv6 - Full support for both address families
- Timeout support - Add entries with optional expiration times
- Cross-platform stubs - Compiles on non-Linux platforms (returns
UnsupportedPlatformerror) - CLI tool - Optional
ripsetbinary for command-line management
Installation
Add to your Cargo.toml:
[]
= "0.1"
CLI Installation
To build the ripset CLI tool, enable the cli feature:
Library Usage
ipset Operations
use IpAddr;
use ;
// Create an ipset
let opts = IpSetCreateOptions ;
ipset_create?;
// Add an IP address
let addr: IpAddr = "192.168.1.1".parse?;
ipset_add?;
// Add with custom timeout
let entry = with_timeout;
ipset_add?;
// Test if IP exists
let exists = ipset_test?;
// List all entries
let entries = ipset_list?;
// Delete an IP
ipset_del?;
// Flush all entries
ipset_flush?;
// Destroy the set
ipset_destroy?;
nftables Operations
use IpAddr;
use ;
// Create a table
nftset_create_table?;
// List tables
let tables = nftset_list_tables?;
// Create a set
let opts = NftSetCreateOptions ;
nftset_create_set?;
// Add an IP address
let addr: IpAddr = "10.0.0.1".parse?;
nftset_add?;
// Test if IP exists
let exists = nftset_test?;
// List all entries
let entries = nftset_list?;
// Delete an IP
nftset_del?;
// Delete the set and table
nftset_delete_set?;
nftset_delete_table?;
CLI Usage
The ripset CLI tool supports both ipset and nftables backends.
Global Options
-b, --backend <ipset|nftables>- Backend to use (default: nftables)
Entry Operations
# Add an entry to a set
# Delete an entry from a set
# List all entries in a set
# Flush all entries from a set
Table.Set Syntax
For the nftables backend, you can use <table>.<set> syntax instead of the -t/--table flag:
# These are equivalent:
# Works with all commands
The explicit -t/--table flag takes precedence over the parsed table name. For the ipset backend, the table part is ignored (ipset doesn't use tables).
Set Management
# Create a new set
# Delete a set
Table Management (nftables only)
# Create a new table
# Delete a table
Examples
# nftables backend (default) - using table.set syntax
# nftables backend - using -t flag (equivalent)
# ipset backend (table part ignored if using table.set syntax)
Requirements
- Linux kernel with netfilter support
- Root privileges (CAP_NET_ADMIN) for all operations
- For ipset:
ip_setkernel module loaded - For nftables:
nf_tableskernel module loaded
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.