#iptables #netfilter #bindings

rust-iptables

A iptables bindings for Rust

2 releases

0.0.2 Oct 25, 2021
0.0.1 Oct 22, 2021

#6 in #iptables

Download history 2/week @ 2022-01-28 2/week @ 2022-02-04 2/week @ 2022-02-11 4/week @ 2022-02-18 3/week @ 2022-02-25 2/week @ 2022-03-04 7/week @ 2022-03-11 12/week @ 2022-03-18 2/week @ 2022-03-25 4/week @ 2022-04-01 4/week @ 2022-04-08 4/week @ 2022-04-15 5/week @ 2022-04-22 16/week @ 2022-04-29 16/week @ 2022-05-06 36/week @ 2022-05-13

75 downloads per month
Used in leicester

MIT/Apache

14KB
387 lines

rust-iptables

A iptables bindings for Rust.

Overview

Rust bindings for iptables, it provides a few major components:

  • high-level handles, such as save/restore
  • table/chain/rule support
  • IPv4/IPv6 support

Example

A basic chain/table example.

[dependencies]
rust-iptables = { version = "0.0.2" }

Then, on your main.rs:

use rust_iptables::iptables;

fn main() {
    let ipt = iptables::new().unwrap();

    assert!(ipt.new_chain("nat", "TESTINGCHAIN").is_ok());
    assert!(ipt.append("nat", "TESTINGCHAIN", "-j ACCEPT").is_ok());
    assert!(ipt.exists("nat", "TESTINGCHAIN", "-j ACCEPT").unwrap());
    assert!(ipt.delete("nat", "TESTINGCHAIN", "-j ACCEPT").is_ok());
    assert!(ipt.save_all("test").is_ok());
    assert!(ipt.restore_all("test").is_ok());
    assert!(ipt.delete_chain("nat", "TESTINGCHAIN").is_ok());

    assert!(ipt.change_policy("filter", "FORWARD", "ACCEPT").is_ok());
}

More examples can be found here.

Supported Rust Versions

This library is verified to work in rustc 1.51.0 (nightly), and the support of other versions needs more testing.

License

This project is licensed under the Apache License 2.0.

Dependencies

~2.5MB
~66K SLoC