X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=libs%2Fcore%2Fluasrc%2Fip.lua;h=77aecd2832c2e2df39079e38566374215d5f9bfd;hb=e351f43f0c8ab59cc7df238881dcc335ef3ba36c;hp=3b0ca6799b51afa7897311ec5d21c67411c9d585;hpb=e3a39de81a4f818ba5e4896bfc4c073885488981;p=project%2Fluci.git diff --git a/libs/core/luasrc/ip.lua b/libs/core/luasrc/ip.lua index 3b0ca6799..77aecd283 100644 --- a/libs/core/luasrc/ip.lua +++ b/libs/core/luasrc/ip.lua @@ -334,6 +334,26 @@ function cidr.is4( self ) return self[1] == FAMILY_INET4 end +--- Test whether this instance is an IPv4 RFC1918 private address +-- @return Boolean indicating whether this instance is an RFC1918 address +function cidr.is4rfc1918( self ) + if self[1] == FAMILY_INET4 then + return ((self[2][1] >= 0x0A00) and (self[2][1] <= 0x0AFF)) or + ((self[2][1] >= 0xAC10) and (self[2][1] <= 0xAC1F)) or + (self[2][1] == 0xC0A8) + end + return false +end + +--- Test whether this instance is an IPv4 link-local address (Zeroconf) +-- @return Boolean indicating whether this instance is IPv4 link-local +function cidr.is4linklocal( self ) + if self[1] == FAMILY_INET4 then + return (self[2][1] == 0xA9FE) + end + return false +end + --- Test whether the instance is a IPv6 address. -- @return Boolean indicating a IPv6 address type -- @see cidr.is4 @@ -341,6 +361,15 @@ function cidr.is6( self ) return self[1] == FAMILY_INET6 end +--- Test whether this instance is an IPv6 link-local address +-- @return Boolean indicating whether this instance is IPv6 link-local +function cidr.is6linklocal( self ) + if self[1] == FAMILY_INET6 then + return (self[2][1] >= 0xFE80) and (self[2][1] <= 0xFEBF) + end + return false +end + --- Return a corresponding string representation of the instance. -- If the prefix length is lower then the maximum possible prefix length for the -- corresponding address type then the address is returned in CIDR notation,