GithubHelp home page GithubHelp logo

libnetfilter_queue.nim's Introduction

libnetfilter_queue.nim

This is a high level wrapper of libnetfilter_queue, for low level C api access please import libnetfilter_queue/raw instead, and checkout libnetfilter_queue's documents for more details

This module helps you build your own custom firewall with libnetfilter_queue library.

Currently it does not support multithreading nor async processing yet. To improve performance, consider use iptables's --queue-balance flags and start multiple instances that listen on multiple queues

Installation

libnetfilter_queue1 is required, libnetfilter-queue-dev and libmnl-dev only required for development

# Install libnetfilter-queue1 and its development headers
$ apt install libnetfilter-queue1 libnetfilter-queue-dev libmnl-dev

# Install this wrapper from Nimble directory
$ nimble intall libnetfilter_queue

Usage

Route all imcoming traffic to NFQUEUE with your queue id (eg: 30)

$ iptables -t filter -A INPUT -j NFQUEUE --queue-num 30

Create a simple application to listen on queue id 30

import libnetfilter_queue, libnetfilter_queue/utils

proc cb(id: uint32, buffer: pointer, bufLen: int32, res: var Result) =
  echo "got packet id=", id, " with data size=", bufLen
  hexdump(cast[cstring](buffer), bufLen)
  # accept the packet and reinject it back to kernel
  res.verdict = NF_ACCEPT

var nfq: NetfilterQueue

setControlCHook(proc() {.noconv.} =
  echo "Ctrl+C pressed, exiting.."
  nfq.close()
)

nfq = initNetfilterQueue(20, cb)
nfq.run()

To stop routing traffic:

$ iptables -t filter -D INPUT -j NFQUEUE --queue-num 30

libnetfilter_queue.nim's People

Contributors

ba0f3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.