Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create dhcp #415

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ libpacketgraph_la_SOURCES = \
src/switch.c\
src/pmtud.c\
src/thread.c\
src/ip-fragment.c
src/ip-fragment.c\
src/iprange.c\
src/dhcp.c

pkginclude_HEADERS = \
include/packetgraph/common.h\
Expand All @@ -63,7 +65,8 @@ pkginclude_HEADERS = \
include/packetgraph/queue.h\
include/packetgraph/pmtud.h\
include/packetgraph/ip-fragment.h\
include/packetgraph/errors.h
include/packetgraph/errors.h\
include/packetgraph/dhcp.h

libpacketgraph_la_LIBADD = $(RTE_SDK_LIBS) $(GLIB_LIBS)
# FIXME '^pg_[^_]' does not take all symbols needed (i.e. __pg_error_*)
Expand All @@ -76,7 +79,7 @@ include npfmakefile.am

dist_doc_DATA = README.md

check_PROGRAMS = tests-antispoof tests-core tests-diode tests-rxtx tests-firewall tests-integration tests-nic tests-print tests-queue tests-switch tests-vhost tests-vtep tests-pmtud tests-tap tests-ip-fragment tests-thread
check_PROGRAMS = tests-antispoof tests-core tests-diode tests-rxtx tests-firewall tests-integration tests-nic tests-print tests-queue tests-switch tests-vhost tests-vtep tests-pmtud tests-tap tests-ip-fragment tests-thread tests-dhcp

noinst_LTLIBRARIES += libpacketgraph-dev.la
libpacketgraph_dev_la_SOURCES = $(libpacketgraph_la_SOURCES)
Expand Down Expand Up @@ -195,6 +198,12 @@ tests_thread_CFLAGS = $(libpacketgraph_dev_la_CFLAGS)
tests_thread_LDFLAGS = libpacketgraph-dev.la
EXTRA_tests_thread_DEPENDENCIES = libpacketgraph-dev.la

tests_dhcp_SOURCES = \
tests/dhcp/tests.c
tests_dhcp_CFLAGS = $(libpacketgraph_dev_la_CFLAGS)
tests_dhcp_LDFLAGS = libpacketgraph-dev.la
EXTRA_tests_thread_DEPENDENCIES = libpacketgraph-dev.la

TESTS = \
tests/antispoof/test.sh\
tests/core/test.sh\
Expand All @@ -211,7 +220,8 @@ TESTS = \
tests/tap/test.sh\
tests/thread/test.sh\
tests/integration/test.sh\
tests/vhost/test.sh
tests/vhost/test.sh\
tests/dhcp/test.sh

noinst_PROGRAMS =

Expand Down Expand Up @@ -408,4 +418,4 @@ doc: doxygen.conf
$(srcdir)/doc/deploy_documentation.sh

# libtoolize recommanded this
ACLOCAL_AMFLAGS = -I m4
ACLOCAL_AMFLAGS = -I
5 changes: 1 addition & 4 deletions configure_clang
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash
export CC="clang"
export AR="llvm-ar"
export NM="llvm-nm"
export RANLIB="llvm-ranlib"
root=$(cd "$(dirname $0)" && pwd)
$root/configure ${@:1}
$root/configure CFLAGS="-O0 -g" ${@:1}
77 changes: 77 additions & 0 deletions include/packetgraph/dhcp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* Copyright 2017 Outscale SAS
*
* This file is part of Butterfly.
*
* Butterfly is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* Butterfly is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Butterfly. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _PG_DHCP_H
#define _PG_DHCP_H

#include <packetgraph/common.h>
#include <packetgraph/errors.h>
#include <arpa/inet.h>

/**
* Create a new dhcp brick.
* dhcp brick allow ip adress to mac adresses
* @name: name of the brick
* @cidr: range of ip adresses
* @errp: set in case of an error
* @return: a pointer to a brick structure on success, NULL on error
**/

struct pg_brick *pg_dhcp_new(const char *name, const char *cidr,
struct ether_addr mac_dhcp,
struct pg_error **errp);

/**
* Calculate the number of potential adresses
* @ipcidr : ip adress with cidr to calculate the range
*/
int pg_calcul_range_ip(network_addr_t ipcidr);

/**
* Check if a packet is a dhcp discover packet
* @pkts : the packet to check
*/
bool is_discover(struct rte_mbuf *pkts);

/**
* Check if a packet is a dhcp discover packet
* @pkts : the packet to check
*/
bool is_request(struct rte_mbuf *pkts);

/**
* Create dhcp packet to burst
* @msg_type : dhcp message type : 1 : Discover
* 2 : Offer
* 3 : Request
* 4 : Decline
* 5 : Acknowledgment
* 6 : Negative Acknowledgment
* 7 : Realease
* 8 : Informationnal
* @mac : Mac adresse of the brick
* @ip_offer : ip to give to the brick
* @bail : number of seconds for bail of the ip adresse to the brick
* @ip_router : ip of the default gateaway
* @mask : subnet mask used by the client
*/
struct rte_mbuf **pg_dhcp_packet_create(struct pg_brick *brick,
uint8_t msg_type, struct ether_addr mac,
uint32_t ip_offer, int bail,
uint32_t ip_router, uint32_t mask);

#endif /* _PG_DHCP_H */
82 changes: 82 additions & 0 deletions include/packetgraph/iprange.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2003 Gabriel L. Somlo
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* To compile:
* on Linux:
* gcc -o iprange iprange.c -O2 -Wall
* on Solaris 8, Studio 8 CC:
* cc -xO5 -xarch=v8plusa -xdepend iprange.c -o iprange -lnsl -lresolv
*
* CHANGELOG :
* 2004-10-16 Paul Townsend (alpha alpha beta at purdue dot edu)
* more general input/output formatting
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

/*---------------------------------------------------------------------*/
/* network address type: one field for the net address, one for prefix */
/*---------------------------------------------------------------------*/
typedef struct network_addr {
in_addr_t addr;
int pfx;
} network_addr_t;

/*------------------------------------------------------------------*/
/* Set a bit to a given value (0 or 1); MSB is bit 1, LSB is bit 32 */
/*------------------------------------------------------------------*/
in_addr_t set_bit(in_addr_t addr, int bitno, int val);

/*----------------------------------------------------*/
/* Compute broadcast address given address and prefix */
/*----------------------------------------------------*/
in_addr_t broadcast(in_addr_t addr, int prefix);

/*--------------------------------------*/
/* Compute netmask address given prefix */
/*--------------------------------------*/
in_addr_t netmask(int prefix);

/*------------------------------------------------*/
/* Print out a 32-bit address in A.B.C.D/M format */
/*------------------------------------------------*/
void print_addr(in_addr_t addr, int prefix);

/*-----------------------------------------------------------*/
/* Convert an A.B.C.D address into a 32-bit host-order value */
/*-----------------------------------------------------------*/
in_addr_t a_to_hl(const char *ipstr);

/*--------------------------------------------------*/
/* Compute network address given address and prefix */
/*--------------------------------------------------*/
in_addr_t network(in_addr_t addr, int prefix);

/*-----------------------------------------------------------------*/
/* convert a network address char string into a host-order network */
/* address and an integer prefix value */
/*-----------------------------------------------------------------*/
int str_to_netaddr(const char *ipstr, network_addr_t *netaddr);

/*------------------------------------------------------*/
/* Print out an address range in a.b.c.d-A.B.C.D format */
/*------------------------------------------------------*/
void print_addr_range(in_addr_t lo, in_addr_t hi);
2 changes: 2 additions & 0 deletions include/packetgraph/packetgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@
#include <packetgraph/tap.h>
#include <packetgraph/pmtud.h>
#include <packetgraph/ip-fragment.h>
#include <packetgraph/iprange.h>
#include <packetgraph/dhcp.h>

#endif /* _PG_PACKETGRAPH_H */
Loading