Class: Netfilter::Packet
- Inherits:
-
Object
- Object
- Netfilter::Packet
- Defined in:
- lib/nfqueue.rb
Overview
This class represents a packet filtered by a Netfilter::Queue.
Defined Under Namespace
Classes: HardwareAddress, Header, Timeval
Constant Summary collapse
- DROP =
0
- ACCEPT =
1
- STOLEN =
2
- QUEUE =
3
- REPEAT =
4
- STOP =
5
Instance Attribute Summary collapse
-
#data ⇒ Object
The packet contents.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Instance Method Summary collapse
-
#hw_addr ⇒ Object
The source hardware address.
-
#indev ⇒ Object
The index of the device the queued packet was received via.
-
#indev_name ⇒ Object
The name of the interface this packet was received through.
-
#initialize(queue, nfad) ⇒ Packet
constructor
:nodoc:.
-
#nfmark ⇒ Object
The netfilter mark.
-
#outdev ⇒ Object
The index of the device the queued packet will be sent out.
-
#outdev_name ⇒ Object
The name of the interface this packet will be routed to.
-
#phys_indev ⇒ Object
The index of the physical device the queued packet was received via.
-
#phys_indev_name ⇒ Object
The name of the physical interface this packet was received through.
-
#phys_outdev ⇒ Object
The index of the physical device the queued packet will be sent out.
-
#phys_outdev_name ⇒ Object
The name of the physical interface this packet will be routed to.
-
#timestamp ⇒ Object
The packet timestamp.
Constructor Details
#initialize(queue, nfad) ⇒ Packet
:nodoc:
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/nfqueue.rb', line 68 def initialize(queue, nfad) #:nodoc: @queue = queue @nfad = nfad phdr = Queue.nfq_get_msg_packet_hdr(nfad) hdr = Header.new(phdr) @id = [ hdr[:packet_id] ].pack("N").unpack("V")[0] @protocol = [ hdr[:hw_protocol] ].pack('n').unpack("v")[0] end |
Instance Attribute Details
#data ⇒ Object
The packet contents.
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# 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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
64 65 66 |
# File 'lib/nfqueue.rb', line 64 def id @id end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
65 66 67 |
# File 'lib/nfqueue.rb', line 65 def protocol @protocol end |
Instance Method Details
#hw_addr ⇒ Object
The source hardware address.
162 163 164 165 166 167 168 169 |
# 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 ⇒ Object
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?).
103 104 105 |
# File 'lib/nfqueue.rb', line 103 def indev Queue.nfq_get_indev(@nfad) end |
#indev_name ⇒ Object
The name of the interface this packet was received through.
110 111 112 |
# File 'lib/nfqueue.rb', line 110 def indev_name get_interface_name(self.indev) end |
#nfmark ⇒ Object
The netfilter mark.
82 83 84 |
# File 'lib/nfqueue.rb', line 82 def nfmark Queue.nfq_get_nfmark(@nfad) end |
#outdev ⇒ Object
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?).
133 134 135 |
# File 'lib/nfqueue.rb', line 133 def outdev Queue.nfq_get_outdev(@nfad) end |
#outdev_name ⇒ Object
The name of the interface this packet will be routed to.
140 141 142 |
# File 'lib/nfqueue.rb', line 140 def outdev_name get_interface_name(self.outdev) end |
#phys_indev ⇒ Object
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).
118 119 120 |
# File 'lib/nfqueue.rb', line 118 def phys_indev Queue.nfq_get_physindev(@nfad) end |
#phys_indev_name ⇒ Object
The name of the physical interface this packet was received through.
125 126 127 |
# File 'lib/nfqueue.rb', line 125 def phys_indev_name get_interface_name(self.phys_indev) end |
#phys_outdev ⇒ Object
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).
148 149 150 |
# File 'lib/nfqueue.rb', line 148 def phys_outdev Queue.nfq_get_physoutdev(@nfad) end |
#phys_outdev_name ⇒ Object
The name of the physical interface this packet will be routed to.
155 156 157 |
# File 'lib/nfqueue.rb', line 155 def phys_outdev_name get_interface_name(self.phys_outdev) end |