GithubHelp home page GithubHelp logo

dhcp-2's Introduction

This is an attempt to write a proper, liberally licensed DHCP server library in Erlang.

It is written as a extendable library, allowing to delegate the relevant calls on discover / request and release without burdening the implementation with the bookkeeping details required by DHCP.

Running it is pretty simple:

  • Start the dhcp app.
  • Implement a handler.
  • Register the handler via a call to dhcp_server:register_handler/2

The handler

The handler is a module implementing the dhcp_handler behaviour it has to export the functions, a handler is created for every release request (identified by xid and chaddr):

init/0

The initialising function it takes no parameters but has to return a tupel of the form: {ok, state(), server_id()} where the server_id() is the IP address used to identify the server.

discover/3

Discover is called on a discover request, it takes three parameters:

  • ReplyPkg - a minimal reply package with the values from the request already set.
  • RequestPkg - the original request package.
  • State - The state of the handler.

The function has to return either:

  • {ok, ReplyPkg} where ReplyPkg was filled 'manually'.
  • {ok, {offer, IP, Netmask[, GWs], ReplyPkg}, State} - where IP and Netmask are IP addresses to offer, GWs can either be omitted, be a single IP or a list of IP's and ReplyPkg is either the original package or has modification as additional options set on it.
  • {ok, State} - if no offer is send in reply.
  • {error, Reason} - an error that shuts down the related FSM.

request/3

A request in reply to the offer, it is already checked if the requested IP is equal to the offered IP, the parameters passed are in accordance with the discover function:

  • ReplyPkg - a minimal reply package with the values from the request already set.
  • RequestPkg - the original request package.
  • State - The state of the handler.

The funcion has to return:

  • {ok, ReplyPkg} where ReplyPkg was filled 'manually'.
  • {ok, {ack, [IP, Netmask[, GWs]], ReplyPkg}, State} - where IP and Netmask are IP addresses to offer, GWs can either be omitted, be a single IP or a list of IP's and ReplyPkg is either the original package or has modification as additional options set on it, all fiends but The ReplyPkg are optional.
  • {ok, {nck, ReplyPkg}, State} - The request is denied, details can be set in the ReplyPkg.
  • {error, Reason} - an error that shuts down the related FSM.

release/2

Only for informative reasons, the function does not have to return a package, it is passed it's state and the release package and can return either:

  • {ok, State} - return normal.
  • {error, Reason} - an error that shuts down the related FSM.

Configuration

There are three configuration options that can adjust the behavior of the FSM, namely the timeouts.

  • initial_timeout - the timeout in seconds until the FSM quits when no initial discover or request is received.
  • offer_timeout - the timeout in seconds before a offer has to be accepted or declined.

dhcp-2's People

Contributors

licenser avatar bfo avatar philipcristiano avatar puzza007 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.