Coder Social home page Coder Social logo

lua-resty-ipmatcher2's Introduction

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

lua-resty-ipmatcher2's People

Contributors

membphis avatar spacewander avatar potapo avatar sagrada1788 avatar elvinefendi avatar pottekkat avatar rocfang avatar opswill avatar tzssangglass avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.