class Netfilter::Packet

This class represents a packet filtered by a Netfilter::Queue.

Constants

ACCEPT
DROP
QUEUE
REPEAT
STOLEN
STOP

Attributes

data[W]
id[R]
protocol[R]

Public Instance Methods

data() click to toggle source

The packet contents.

# File lib/nfqueue.rb, line 174
def data
    if @data.nil?
        pdata = FFI::MemoryPointer.new(:pointer, 1)
        size = Queue.nfq_get_payload(@nfad, pdata)
        if size < 0
            raise QueueError, "nfq_get_payload has failed"
        end
    
        @data = pdata.read_pointer.read_bytes(size)
    else
        @data
    end
end
hw_addr() click to toggle source

The source hardware address.

# File lib/nfqueue.rb, line 162
def hw_addr
    phw = Queue.nfq_get_packet_hw(@nfad)
    return nil if phw.null?

    hw = HardwareAddress.new(phw)
    hw_addrlen = [ hw[:hw_addrlen] ].pack('v').unpack('n')[0]
    hw[:hw_addr].to_ptr.read_bytes(hw_addrlen)
end
indev() click to toggle source

The index of the device the queued packet was received via. If the return index is 0, the packet was locally generated or the input interface is not known (ie. POSTROUTING?).

# File lib/nfqueue.rb, line 103
def indev
    Queue.nfq_get_indev(@nfad)
end
indev_name() click to toggle source

The name of the interface this packet was received through.

# File lib/nfqueue.rb, line 110
def indev_name
    get_interface_name(self.indev)
end
nfmark() click to toggle source

The netfilter mark.

# File lib/nfqueue.rb, line 82
def nfmark
    Queue.nfq_get_nfmark(@nfad)
end
outdev() click to toggle source

The index of the device the queued packet will be sent out. It the returned index is 0, the packet is destined for localhost or the output interface is not yet known (ie. PREROUTING?).

# File lib/nfqueue.rb, line 133
def outdev
    Queue.nfq_get_outdev(@nfad)
end
outdev_name() click to toggle source

The name of the interface this packet will be routed to.

# File lib/nfqueue.rb, line 140
def outdev_name
    get_interface_name(self.outdev)
end
phys_indev() click to toggle source

The index of the physical device the queued packet was received via. If the returned index is 0, the packet was locally generated or the physical input interface is no longer known (ie. POSTROUTING).

# File lib/nfqueue.rb, line 118
def phys_indev
    Queue.nfq_get_physindev(@nfad)
end
phys_indev_name() click to toggle source

The name of the physical interface this packet was received through.

# File lib/nfqueue.rb, line 125
def phys_indev_name
    get_interface_name(self.phys_indev)
end
phys_outdev() click to toggle source

The index of the physical device the queued packet will be sent out. If the returned index is 0, the packet is destined for localhost or the physical output interface is not yet known (ie. PREROUTING).

# File lib/nfqueue.rb, line 148
def phys_outdev
    Queue.nfq_get_physoutdev(@nfad)
end
phys_outdev_name() click to toggle source

The name of the physical interface this packet will be routed to.

# File lib/nfqueue.rb, line 155
def phys_outdev_name
    get_interface_name(self.phys_outdev)
end
timestamp() click to toggle source

The packet timestamp.

# File lib/nfqueue.rb, line 89
def timestamp
    ptv = FFI::MemoryPointer.new :pointer
    tv = Timeval.new(ptv)
    if Queue.nfq_get_timestamp(@nfad, ptv) < 0
        0
    else
        Time.at(tv[:tv_sec])
    end
end

Private Instance Methods

get_interface_name(index) click to toggle source
# File lib/nfqueue.rb, line 190
def get_interface_name(index)
    iface = @queue.net_interfaces[index]
    if iface
        iface[:name]
    end
end