Giter Club home page Giter Club logo

dhcp-lease's Introduction

DHCP Lease Module

This module provide many funcions for leasing IP and getting IP from pools.

Goals

getting ip from pool

What this fucntion works ?

  1. pick up pool
  2. get first non-reserved ip and return
  3. if ip requested check on leases and :
    • if exists send ip
    • if does not exists search to leases and if this ip doesn't reserved, send ip

in depth of operation

First of all we should get the first no reserved ip address with this query :

SELECT id, conf_id, ip FROM pool WHERE lease_flag = 0 LIMIT 1;

We need id for updating on ack, conf_id for sending typical options and ip for sending on replay packets.

Another fields like mac, host and lease_flag sets to zero or NULL.

leasing ip address to pool

  • update lease flag to true
  • fill mac address field
  • fill hostname field

After getting request and when sending ack, we should update non reserved ip address on previous step.

We have an id and required parameters like mac, host and lease_flag :

UPDATE pool SET mac = "some-mac-address", host = "some-hostname", lease_flag = 1 WHERE id = 1;

Database schema

config table

CREATE TABLE config (
	id INTEGER PRIMARY KEY AUTOINCREMENT,
	mask TEXT NOT NULL,
	router TEXT NOT NULL,
	domain TEXT NOT NULL,
	lease_time INTEGER NOT NULL DEFAULT 600
);
                        config table
---------------------------------------------------------
|      NAME     |                  TYPE                 |
---------------------------------------------------------
| id            | INTEGER PRIMARY KEY AUTOINCREMENT     |
---------------------------------------------------------
| mask          | TEXT NOT NULL                         |
---------------------------------------------------------
| router        | TEXT NOT NULL                         |
---------------------------------------------------------
| domain        | TEXT NOT NULL UNIQUE                  |
---------------------------------------------------------
| lease_time    | INTEGER NOT NULL DEFAULT 0            |
---------------------------------------------------------

pool table

CREATE TABLE pool ( 
	id INTEGER PRIMARY KEY AUTOINCREMENT,
	conf_id INTEGER NOT NULL,
	ip TEXT NOT NULL,
	host TEXT NOT NULL,
	mac TEXT NOT NULL,
	lease_time INTEGER NOT NULL DEFAULT 600,
	FOREIGN KEY (conf_id) REFERENCES config(id)
);
                        pool table
---------------------------------------------------------
|      NAME     |                  TYPE                 |
---------------------------------------------------------
| id            | INTEGER PRIMARY KEY AUTOINCREMENT     |
---------------------------------------------------------
| config_id     | INTEGER NOT NULL                      |
---------------------------------------------------------
| hostname      | TEXT NOT NULL                         |
---------------------------------------------------------
| mac           | TEXT NOT NULL UNIQUE                  |
---------------------------------------------------------
| lease_flag    | INTEGER NOT NULL DEFAULT 0            |
---------------------------------------------------------
| FOREIGN KEY   | (conf_id) REFERENCES config (id)      |
---------------------------------------------------------

resolve dependencies

pip3 install -r tests/scripts/requirements.txt

build & run

mkdir build
cd build
cmake ..

tests

./tests/lease_test

dhcp-lease's People

Contributors

alirezaarzehgar avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

m4github

dhcp-lease's Issues

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.