Skip to content

Commit

Permalink
dhcp : brick and tests (DON'T Merge)
Browse files Browse the repository at this point in the history
Signed-off-by: Tarrade Nicolas <[email protected]>
  • Loading branch information
outscale-nts committed Oct 23, 2017
1 parent b3e706e commit 1652b53
Show file tree
Hide file tree
Showing 4 changed files with 391 additions and 3 deletions.
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);
7 changes: 4 additions & 3 deletions src/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static int dhcp_burst(struct pg_brick *brick, enum pg_side from,

it_mask = pkts_mask;
for (; it_mask;) {
j = 0;
j = 1;
pg_low_bit_iterate_full(it_mask, bit, i);
tmp = pkts[i];
struct ether_hdr *eth = (struct ether_hdr *)
Expand All @@ -138,14 +138,14 @@ static int dhcp_burst(struct pg_brick *brick, enum pg_side from,
if (is_discover(tmp)) {
while(state->check_ip[j] != 0)
j++;
in_addr_t ip_offer =
uint32_t ip_offer =
state->addr_net + j;
pkt_offer =
pg_dhcp_packet_create(brick, 2,
eth->s_addr, ip_offer, 3600,
state->addr_net,
netmask(state->prefix));
return pg_brick_burst(s->edge.link,
return pg_brick_burst(s->edge.link,
from, s->edge.pair_index, pkt_offer,
pkts_mask, errp);
}
Expand All @@ -154,6 +154,7 @@ static int dhcp_burst(struct pg_brick *brick, enum pg_side from,
state->addr_net;
if (!state->check_ip[index])
{
printf("check \n");
pkt_offer =
pg_dhcp_packet_create(brick, 5,
eth->s_addr,
Expand Down
2 changes: 2 additions & 0 deletions tests/dhcp/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
sudo ./tests-dhcp -c1 -n1 --socket-mem 64 --no-shconf
Loading

0 comments on commit 1652b53

Please sign in to comment.