Read list of tables/targets/matches
This commit is contained in:
@@ -36,6 +36,22 @@ module Linux
|
|||||||
def self.table(tablename = "filter")
|
def self.table(tablename = "filter")
|
||||||
@tables[tablename] ||= new(tablename, socket)
|
@tables[tablename] ||= new(tablename, socket)
|
||||||
end
|
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)
|
def initialize(name, socket)
|
||||||
raise "Invalid table name" if name.bytesize > self.class::TABLE_MAXNAMELEN
|
raise "Invalid table name" if name.bytesize > self.class::TABLE_MAXNAMELEN
|
||||||
|
@@ -60,6 +60,10 @@ module Linux
|
|||||||
# Class for handling iptables. Note that this doesn't actually use
|
# Class for handling iptables. Note that this doesn't actually use
|
||||||
# Netlink at all :-(
|
# Netlink at all :-(
|
||||||
class Iptables4 < Iptables
|
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
|
TABLE_MAXNAMELEN = IPT_TABLE_MAXNAMELEN
|
||||||
TC_AF = Socket::AF_INET
|
TC_AF = Socket::AF_INET
|
||||||
TC_IPPROTO = Socket::IPPROTO_IP
|
TC_IPPROTO = Socket::IPPROTO_IP
|
||||||
@@ -73,5 +77,6 @@ end
|
|||||||
|
|
||||||
if __FILE__ == $0
|
if __FILE__ == $0
|
||||||
require 'pp'
|
require 'pp'
|
||||||
|
pp Linux::Iptables4.tables
|
||||||
pp Linux::Iptables4.table("filter").rules
|
pp Linux::Iptables4.table("filter").rules
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user