diff --git a/lib/linux/iptables.rb b/lib/linux/iptables.rb index 4a59f2a..6867ec2 100644 --- a/lib/linux/iptables.rb +++ b/lib/linux/iptables.rb @@ -36,6 +36,22 @@ module Linux def self.table(tablename = "filter") @tables[tablename] ||= new(tablename, socket) end + + def self.tables + proc_read(self::PROC_TABLES) + end + + def self.targets + proc_read(self::PROC_TARGETS) + end + + def self.matches + proc_read(self::PROC_MATCHES) + end + + def self.proc_read(filename) + File.readlines(filename).each { |x| x.chomp! } + end def initialize(name, socket) raise "Invalid table name" if name.bytesize > self.class::TABLE_MAXNAMELEN diff --git a/lib/linux/iptables4.rb b/lib/linux/iptables4.rb index 40ea2f1..fa22c10 100644 --- a/lib/linux/iptables4.rb +++ b/lib/linux/iptables4.rb @@ -60,6 +60,10 @@ module Linux # Class for handling iptables. Note that this doesn't actually use # Netlink at all :-( class Iptables4 < Iptables + PROC_TABLES = "/proc/net/ip_tables_names" + PROC_TARGETS = "/proc/net/ip_tables_targets" + PROC_MATCHES = "/proc/net/ip_tables_matches" + TABLE_MAXNAMELEN = IPT_TABLE_MAXNAMELEN TC_AF = Socket::AF_INET TC_IPPROTO = Socket::IPPROTO_IP @@ -73,5 +77,6 @@ end if __FILE__ == $0 require 'pp' + pp Linux::Iptables4.tables pp Linux::Iptables4.table("filter").rules end