Read list of tables/targets/matches
This commit is contained in:
@@ -37,6 +37,22 @@ module Linux
|
||||
@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
|
||||
@name = name
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user