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.
- checksums.yaml +4 -4
- data/lib/nfnetlink.rb +18 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 858662c2cf953828c843f5c428d2965bf1efdc34
|
4
|
+
data.tar.gz: 78fff9a32a61269f6c83031c6ed22702c15d20f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 085f219d11c690f624acce281308581016537b1e9143d91e18c35a04ce34808a23768f4ad3a05652f989166ce18be54ace086433e152b045016936bd1ba1ea7a
|
7
|
+
data.tar.gz: 16a87834ea7a813bcc5825d5523c3c902d089329da8464099220f68c968074ce3e2a22ac1248220fda045ca36c1c1ff1f85fe45bdfa15d8e04ea88b12a289e06
|
data/lib/nfnetlink.rb
CHANGED
@@ -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
|
-
|
103
|
-
|
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
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
116
|
-
|
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
|
#
|