Remove dhcpd.h.
This commit is contained in:
parent
ef9d9d26df
commit
13d9119f3a
@ -20,7 +20,6 @@
|
||||
#include "socket.h"
|
||||
#include "sys.h"
|
||||
#include "ifchange.h"
|
||||
#include "dhcpd.h"
|
||||
#include "log.h"
|
||||
#include "strl.h"
|
||||
#include "io.h"
|
||||
|
58
ndhc/dhcpd.h
58
ndhc/dhcpd.h
@ -1,58 +0,0 @@
|
||||
/* dhcpd.h */
|
||||
#ifndef DHCPD_H_
|
||||
#define DHCPD_H_
|
||||
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/udp.h>
|
||||
|
||||
/*****************************************************************/
|
||||
/* Do not modify below here unless you know what you are doing!! */
|
||||
/*****************************************************************/
|
||||
|
||||
/* DHCP protocol -- see RFC 2131 */
|
||||
#define SERVER_PORT 67
|
||||
#define CLIENT_PORT 68
|
||||
|
||||
#define DHCP_OPTIONS_BUFSIZE 308
|
||||
|
||||
enum {
|
||||
BOOTREQUEST = 1,
|
||||
BOOTREPLY = 2
|
||||
};
|
||||
|
||||
#define ETH_10MB 1
|
||||
#define ETH_10MB_LEN 6
|
||||
|
||||
enum {
|
||||
DHCPDISCOVER = 1,
|
||||
DHCPOFFER = 2,
|
||||
DHCPREQUEST = 3,
|
||||
DHCPDECLINE = 4,
|
||||
DHCPACK = 5,
|
||||
DHCPNAK = 6,
|
||||
DHCPRELEASE = 7,
|
||||
DHCPINFORM = 8
|
||||
};
|
||||
|
||||
#define BROADCAST_FLAG 0x8000
|
||||
|
||||
enum {
|
||||
OPTION_FIELD = 0,
|
||||
FILE_FIELD = 1,
|
||||
SNAME_FIELD = 2
|
||||
};
|
||||
|
||||
#define MAC_BCAST_ADDR (unsigned char *) "\xff\xff\xff\xff\xff\xff"
|
||||
|
||||
enum {
|
||||
OPT_CODE = 0,
|
||||
OPT_LEN = 1,
|
||||
OPT_DATA = 2
|
||||
};
|
||||
|
||||
struct option_set {
|
||||
unsigned char *data;
|
||||
struct option_set *next;
|
||||
};
|
||||
|
||||
#endif
|
@ -37,7 +37,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "dhcpd.h"
|
||||
#include "dhcpmsg.h"
|
||||
#include "packet.h"
|
||||
#include "options.h"
|
||||
#include "config.h"
|
||||
@ -74,9 +74,9 @@ uint32_t random_xid(void)
|
||||
static void init_header(struct dhcpMessage *packet, char type)
|
||||
{
|
||||
memset(packet, 0, DHCP_SIZE);
|
||||
packet->op = BOOTREQUEST; /* client */
|
||||
packet->htype = ETH_10MB;
|
||||
packet->hlen = ETH_10MB_LEN;
|
||||
packet->op = 1; // BOOTREQUEST (client)
|
||||
packet->htype = 1; // ETH_10MB
|
||||
packet->hlen = 6; // ETH_10MB_LEN
|
||||
packet->cookie = htonl(DHCP_MAGIC);
|
||||
packet->options[0] = DHCP_END;
|
||||
add_simple_option(packet->options, DHCP_MESSAGE_TYPE, type);
|
||||
@ -115,12 +115,14 @@ static void add_requests(struct dhcpMessage *packet)
|
||||
packet->options[end + OPT_DATA + len] = DHCP_END;
|
||||
}
|
||||
|
||||
#define MAC_BCAST_ADDR (unsigned char *) "\xff\xff\xff\xff\xff\xff"
|
||||
/* Wrapper that broadcasts a raw dhcp packet on the bound interface. */
|
||||
static int bcast_raw_packet(struct dhcpMessage *packet)
|
||||
{
|
||||
return raw_packet(packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
||||
return raw_packet(packet, INADDR_ANY, DHCP_CLIENT_PORT, INADDR_BROADCAST,
|
||||
DHCP_SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
||||
}
|
||||
#undef MAC_BCAST_ADDR
|
||||
|
||||
/* Broadcast a DHCP discover packet to the network, with an optionally
|
||||
* requested IP */
|
||||
@ -170,8 +172,8 @@ int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
|
||||
add_requests(&packet);
|
||||
log_line("Sending renew...");
|
||||
if (server)
|
||||
return kernel_packet(&packet, ciaddr, CLIENT_PORT,
|
||||
server, SERVER_PORT);
|
||||
return kernel_packet(&packet, ciaddr, DHCP_CLIENT_PORT, server,
|
||||
DHCP_SERVER_PORT);
|
||||
else
|
||||
return bcast_raw_packet(&packet);
|
||||
}
|
||||
@ -213,7 +215,8 @@ int send_release(uint32_t server, uint32_t ciaddr)
|
||||
add_simple_option(packet.options, DHCP_SERVER_ID, server);
|
||||
|
||||
log_line("Sending release...");
|
||||
return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
|
||||
return kernel_packet(&packet, ciaddr, DHCP_CLIENT_PORT, server,
|
||||
DHCP_SERVER_PORT);
|
||||
}
|
||||
|
||||
/* return -1 on errors that are fatal for the socket,
|
||||
@ -252,7 +255,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
|
||||
sleep(1);
|
||||
return -2;
|
||||
}
|
||||
if (packet.udp.dest != htons(CLIENT_PORT)) {
|
||||
if (packet.udp.dest != htons(DHCP_CLIENT_PORT)) {
|
||||
log_line("UDP destination port incorrect: %d", ntohs(packet.udp.dest));
|
||||
sleep(1);
|
||||
return -2;
|
||||
|
@ -2,9 +2,23 @@
|
||||
#define CLIENTPACKET_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "packet.h" // for struct dhcpMessage
|
||||
|
||||
#define DHCP_SERVER_PORT 67
|
||||
#define DHCP_CLIENT_PORT 68
|
||||
#define DHCP_MAGIC 0x63825363
|
||||
|
||||
enum {
|
||||
DHCPDISCOVER = 1,
|
||||
DHCPOFFER = 2,
|
||||
DHCPREQUEST = 3,
|
||||
DHCPDECLINE = 4,
|
||||
DHCPACK = 5,
|
||||
DHCPNAK = 6,
|
||||
DHCPRELEASE = 7,
|
||||
DHCPINFORM = 8
|
||||
};
|
||||
|
||||
uint32_t random_xid(void);
|
||||
int send_discover(uint32_t xid, uint32_t requested);
|
||||
int send_selecting(uint32_t xid, uint32_t server, uint32_t requested);
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "options.h"
|
||||
#include "dhcpd.h"
|
||||
#include "config.h"
|
||||
#include "packet.h"
|
||||
#include "options.h"
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include <grp.h>
|
||||
|
||||
#include "ndhc-defines.h"
|
||||
#include "dhcpd.h"
|
||||
#include "config.h"
|
||||
#include "options.h"
|
||||
#include "dhcpmsg.h"
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "dhcpd.h"
|
||||
#include "options.h"
|
||||
|
||||
/* supported options are easily added here */
|
||||
@ -63,6 +62,11 @@ uint8_t* get_option(struct dhcpMessage *packet, int code)
|
||||
{
|
||||
uint8_t *optionptr;
|
||||
int len, rem, overload = 0;
|
||||
enum {
|
||||
OPTION_FIELD = 0,
|
||||
FILE_FIELD = 1,
|
||||
SNAME_FIELD = 2
|
||||
};
|
||||
enum {
|
||||
FILE_FIELD101 = FILE_FIELD * 0x101,
|
||||
SNAME_FIELD101 = SNAME_FIELD * 0x101,
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#define TYPE_MASK 0x0F
|
||||
|
||||
#define DHCP_OPTIONS_BUFSIZE 308
|
||||
|
||||
/* DHCP option codes (partial list) */
|
||||
#define DHCP_PADDING 0x00
|
||||
#define DHCP_SUBNET 0x01
|
||||
@ -66,12 +68,23 @@ enum {
|
||||
#define OPTION_REQ 0x10 /* have the client request this option */
|
||||
#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */
|
||||
|
||||
enum {
|
||||
OPT_CODE = 0,
|
||||
OPT_LEN = 1,
|
||||
OPT_DATA = 2
|
||||
};
|
||||
|
||||
struct dhcp_option {
|
||||
char name[10];
|
||||
char flags;
|
||||
unsigned char code;
|
||||
};
|
||||
|
||||
struct option_set {
|
||||
unsigned char *data;
|
||||
struct option_set *next;
|
||||
};
|
||||
|
||||
extern struct dhcp_option options[];
|
||||
extern int option_lengths[];
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "sys.h"
|
||||
#include "log.h"
|
||||
#include "io.h"
|
||||
#include "dhcpd.h"
|
||||
#include "options.h"
|
||||
|
||||
/* Read a packet from socket fd, return -1 on read error, -2 on packet error */
|
||||
@ -187,7 +186,7 @@ void change_listen_mode(struct client_state_t *cs, int new_mode)
|
||||
cs->listenFd = -1;
|
||||
}
|
||||
if (new_mode == LM_KERNEL) {
|
||||
cs->listenFd = listen_socket(INADDR_ANY, CLIENT_PORT,
|
||||
cs->listenFd = listen_socket(INADDR_ANY, DHCP_CLIENT_PORT,
|
||||
client_config.interface);
|
||||
epoll_add(cs, cs->listenFd);
|
||||
}
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <linux/filter.h>
|
||||
#include "log.h"
|
||||
#include "strl.h"
|
||||
#include "dhcpd.h" /* For SERVER_PORT and CLIENT_PORT */
|
||||
|
||||
int set_sock_nonblock(int fd)
|
||||
{
|
||||
@ -142,13 +141,10 @@ int raw_socket(int ifindex)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (SERVER_PORT == 67 && CLIENT_PORT == 68) {
|
||||
/* Use only if standard ports are in use */
|
||||
/* Ignoring error (kernel may lack support for this) */
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
|
||||
sizeof filter_prog) >= 0)
|
||||
log_line("Attached filter to raw socket fd %d", fd);
|
||||
}
|
||||
|
||||
set_sock_nonblock(fd);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user