13 unstable releases (6 breaking)

new 0.7.1 May 8, 2024
0.6.0 Dec 7, 2023
0.5.0 Oct 13, 2023
0.4.0 May 22, 2023
0.1.2 Jan 6, 2023

#444 in Network programming

40 downloads per month

MIT license

250KB
7.5K SLoC

IPSet

Build Status GitHub issues GitHub license Releases

A library wrapper for libipset.
Support the following options:

  • sorted -> EnvOption::Sorted
  • exist -> EnvOption::Exist
  • quiet -> EnvOption::Quiet
  • resolve -> EnvOption::Resolve
  • name -> EnvOption::ListSetName
  • terse -> EnvOption::ListHeader

Support the following commands:

  • add
  • del
  • test
  • create
  • list
  • destroy
  • flush
  • save
  • restore

Support the following type:

  • BitmapIp
  • BitmapIpMac
  • BitmapPort
  • HashIp
  • HashIpMac
  • HashIpMark
  • HashIpPort
  • HashIpPortIp
  • HashIpPortNet
  • HashMac
  • HashNet
  • HashNetIface
  • HashNetNet
  • HashNetPort
  • HashNetPortNet
  • ListSet,

Example

use std::net::IpAddr;

use ipset::{Error, HashIp, IPSet, Session};

fn main() -> Result<(), Error> {
  let mut session: Session<HashIp> = Session::<HashIp>::new("test".to_string());
  let ip: IpAddr = "192.168.3.1".parse().unwrap();
  session.create(|builder| builder.with_ipv6(false)?.build())?;

  let ret = session.add(ip, None)?;
  println!("add {}", ret);

  let exists = session.test(ip)?;
  println!("test {}", exists);

  let ips = session.list()?;
  for ip in ips {
      println!("list {}", ip);
  }

  let ret = session.save("test.ipset")?;
  println!("save {}", ret);

  let ret = session.del(ip)?;
  println!("del {}", ret);

  let ret = session.flush()?;
  println!("flush {}", ret);

  let ret = session.destroy()?;
  println!("destroy {}", ret);

  let set = IPSet::new();
  set.restore("test.ipset")?;

  Ok(())
}

Dependencies

~0.4–2.8MB
~58K SLoC