Software /
code /
prosody
Comparison
util/ip.lua @ 8469:52d48cea1f60
util.ip: Remove redundant caching of method output (supposed to be done in ab9ddfb03d4d but lost somehow)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 09 Dec 2017 20:56:37 +0100 |
parent | 8468:5bfe58539b6c |
child | 9955:c74c89a96cbf |
comparison
equal
deleted
inserted
replaced
8468:5bfe58539b6c | 8469:52d48cea1f60 |
---|---|
170 local value = new_ip("::ffff:" .. self.normal); | 170 local value = new_ip("::ffff:" .. self.normal); |
171 return value; | 171 return value; |
172 end | 172 end |
173 | 173 |
174 function ip_methods:label() | 174 function ip_methods:label() |
175 local value; | |
176 if self.proto == "IPv4" then | 175 if self.proto == "IPv4" then |
177 value = label(self.toV4mapped); | 176 return label(self.toV4mapped); |
178 else | 177 else |
179 value = label(self); | 178 return label(self); |
180 end | 179 end |
181 self.label = value; | |
182 return value; | |
183 end | 180 end |
184 | 181 |
185 function ip_methods:precedence() | 182 function ip_methods:precedence() |
186 local value; | |
187 if self.proto == "IPv4" then | 183 if self.proto == "IPv4" then |
188 value = precedence(self.toV4mapped); | 184 return precedence(self.toV4mapped); |
189 else | 185 else |
190 value = precedence(self); | 186 return precedence(self); |
191 end | 187 end |
192 self.precedence = value; | |
193 return value; | |
194 end | 188 end |
195 | 189 |
196 function ip_methods:scope() | 190 function ip_methods:scope() |
197 local value; | |
198 if self.proto == "IPv4" then | 191 if self.proto == "IPv4" then |
199 value = v4scope(self); | 192 return v4scope(self); |
200 else | 193 else |
201 value = v6scope(self); | 194 return v6scope(self); |
202 end | 195 end |
203 self.scope = value; | |
204 return value; | |
205 end | 196 end |
206 | 197 |
207 local rfc1918_8 = new_ip("10.0.0.0"); | 198 local rfc1918_8 = new_ip("10.0.0.0"); |
208 local rfc1918_12 = new_ip("172.16.0.0"); | 199 local rfc1918_12 = new_ip("172.16.0.0"); |
209 local rfc1918_16 = new_ip("192.168.0.0"); | 200 local rfc1918_16 = new_ip("192.168.0.0"); |
210 local rfc6598 = new_ip("100.64.0.0"); | 201 local rfc6598 = new_ip("100.64.0.0"); |
211 | 202 |
212 function ip_methods:private() | 203 function ip_methods:private() |
213 local private = self.scope ~= 0xE; | 204 local private = self.scope ~= 0xE; |
214 if not private and self.proto == "IPv4" then | 205 if not private and self.proto == "IPv4" then |
215 private = match(self, rfc1918_8, 8) or match(self, rfc1918_12, 12) or match(self, rfc1918_16) or match(self, rfc6598, 10); | 206 return match(self, rfc1918_8, 8) or match(self, rfc1918_12, 12) or match(self, rfc1918_16) or match(self, rfc6598, 10); |
216 end | 207 end |
217 self.private = private; | |
218 return private; | 208 return private; |
219 end | 209 end |
220 | 210 |
221 local function parse_cidr(cidr) | 211 local function parse_cidr(cidr) |
222 local bits; | 212 local bits; |