Skip to content

potats0/lua-resty-ipmatcher2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Name

High-performance IP address matching with prefix-trie for OpenResty Lua. support longest prefix match

Table of Contents

Synopsis

location / {
    content_by_lua_block {
            local ipmatcher = require "resty.ipmatcher"
            local m = ipmatcher.new()
            m:insert_ipv4_with_mask("192.168.3.1/24", 1)
            m:remove_ipv4_with_mask("192.168.3.1/24")
            local a = m:match_ipv4("192.168.3.1")
            ngx.say(a)
    }
}

Back to TOC

Methods

ipmatcher.new

Creates a new hash table to store IP addresses.

Usage

ok = ipmatcher.new()

Example

local ip= ipmatcher.new()

Back to TOC

ipmatcher.insert_ipv4_host

add a host ipv4 to prefix-trie

Usage

ip is a ipv4 address such as '192.168.1.1' action is a number, such as 1 'allow' or 'deny' 2 delay is a number of automatic aging, default is 0 whichmeans never auto-aging

ipmatcher.insert_ipv4_host(ip, action, delay)

Example

local ip = ipmatcher.new()
ip:insert_ipv4_host("192.168.3.1", 1, 1)

Back to TOC

ipmatcher.insert_ipv4_with_mask

add a CIDR into a prefix-trie

Usage

ip is a CIDR address such as '192.168.1.0/24' action is a number, such as 1 'allow' or 'deny' 2 delay is a number of automatic aging, default is 0 whichmeans never auto-aging

ipmatcher.insert_ipv4_with_mask(ip, action, delay)

Example

local ip = ipmatcher.new()
ip:insert_ipv4_with_mask("192.168.3.0/24", 1, 1)

Back to TOC

ipmatcher:match_ipv4

check whether a ipv4 address matches a prefix-trie

Usage

ip is a host ipv4, "192.168.3.1"

local res = ipmatcher.match_ipv4(ip)

return action of the ip.

Example

local ip = ipmatcher.new()
ip:insert_ipv4_with_mask("192.168.3.0/24", 1, 1)
local res = ipmatcher.match_ipv4('192.168.3.1')
local res = ipmatcher.match_ipv4('192.168.3.2')

Back to TOC

ipmatcher:remove_host

remove a ipv4 host from the prefix-trie

Usage

ip is a host ipv4, "192.168.3.1"

local res = ipmatcher.remove_host(ip)

Example

local ip = ipmatcher.new()
ip:insert_ipv4_host("192.168.3.1", 1, 1)
ip:remove_host("192.168.3.1")

Back to TOC

ipmatcher:remove_ipv4_with_mask

remove a CIDR from the prefix-trie

Usage

ip is a CIDR ipv4, "192.168.3.1/24"

local res = ipmatcher.remove_ipv4_with_mask(ip)

Example

local ip = ipmatcher.new()
ip:insert_ipv4_with_mask("192.168.3.0/24", 1, 1)
ip:remove_ipv4_with_mask("192.168.3.0/24")

Back to TOC

Installation

you need besure installed the rust stable version before compile the lua-resty-ipmatcher2

From LuaRocks

luarocks install lua-resty-ipmatcher2

From Source

make install

Back to TOC

About

yet another lua-resty-ipmatcher

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published