nfnetlink 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nfnetlink.rb +18 -8
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56759251fb9b704112db8a1489cc29f3e652c97a
4
- data.tar.gz: b2c3d5c831ee7114c28551a202e4b750de6113d2
3
+ metadata.gz: 858662c2cf953828c843f5c428d2965bf1efdc34
4
+ data.tar.gz: 78fff9a32a61269f6c83031c6ed22702c15d20f6
5
5
  SHA512:
6
- metadata.gz: 759bce571acea422ec8efd3d48d4f1359190fbdbe2d381fe4a5d0a866455010939b3bd9b8b780719783b966f3fd3d2ca74aeff51a0630ff7a60eb8dbfaa49c83
7
- data.tar.gz: 092ad37e73975bf62e6b7a6398009833b1b32cf51753ad059447480e9cc9a30a22bb02a84e2c1355ba70d431aa7275a321645e03b3c4295d99b8608508daa873
6
+ metadata.gz: 085f219d11c690f624acce281308581016537b1e9143d91e18c35a04ce34808a23768f4ad3a05652f989166ce18be54ace086433e152b045016936bd1ba1ea7a
7
+ data.tar.gz: 16a87834ea7a813bcc5825d5523c3c902d089329da8464099220f68c968074ce3e2a22ac1248220fda045ca36c1c1ff1f85fe45bdfa15d8e04ea88b12a289e06
@@ -27,6 +27,7 @@
27
27
 
28
28
  require 'rubygems'
29
29
  require 'ffi'
30
+ require 'thread'
30
31
 
31
32
  module Netfilter
32
33
 
@@ -86,6 +87,7 @@ module Netfilter
86
87
  }
87
88
 
88
89
  def initialize
90
+ @lock = Mutex.new
89
91
  @nlif_handle = Netlink.nlif_open
90
92
  raise NetlinkError, "nlif_open has failed" if @nlif_handle.null?
91
93
 
@@ -99,21 +101,25 @@ module Netfilter
99
101
  # Returns nil if interface does not exist.
100
102
  #
101
103
  def [](index)
102
- update_table
103
- get_iface(index)
104
+ @lock.synchronize {
105
+ update_table
106
+ get_iface(index)
107
+ }
104
108
  end
105
109
 
106
110
  #
107
111
  # Enumerator for the list of interfaces.
108
112
  #
109
113
  def each
110
- update_table
111
- for index in 1..65535
112
- iface = get_iface(index)
113
- next if iface.nil?
114
+ @lock.synchronize {
115
+ update_table
116
+ for index in 1..65535
117
+ iface = get_iface(index)
118
+ next if iface.nil?
114
119
 
115
- yield(iface)
116
- end
120
+ yield(iface)
121
+ end
122
+ }
117
123
  end
118
124
 
119
125
  private
@@ -126,6 +132,8 @@ module Netfilter
126
132
  raise NetlinkError, "nlif_fd has failed" if nlif_fd < 0
127
133
 
128
134
  nlif_io = IO.new(nlif_fd)
135
+ nlif_io.autoclose = false
136
+
129
137
  rs, _ws, _es = IO.select([nlif_io], [], [], 0)
130
138
 
131
139
  if rs and rs.length > 0 and rs[0] == nlif_io
@@ -133,6 +141,8 @@ module Netfilter
133
141
  raise NetlinkError, "nlif_catch has failed"
134
142
  end
135
143
  end
144
+
145
+ nlif_io.close
136
146
  end
137
147
 
138
148
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nfnetlink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Delugré