Share ifchd command defines between ifchd and ndhc.

This commit is contained in:
Nicholas J. Kain 2011-07-25 02:01:38 -04:00
parent fe85e52a4b
commit 7e1e902b34
6 changed files with 28 additions and 28 deletions

View File

@ -5,7 +5,9 @@ cmake_minimum_required (VERSION 2.6)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s -std=gnu99 -pedantic -Wall -lcap -D_GNU_SOURCE -DHAVE_CLEARENV -DLINUX") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s -std=gnu99 -pedantic -Wall -lcap -D_GNU_SOURCE -DHAVE_CLEARENV -DLINUX")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -s -std=gnu99 -pedantic -Wall -lcap -D_GNU_SOURCE -DHAVE_CLEARENV -DLINUX") set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -s -std=gnu99 -pedantic -Wall -lcap -D_GNU_SOURCE -DHAVE_CLEARENV -DLINUX")
include_directories("${PROJECT_SOURCE_DIR}/ncmlib") include_directories(
"${PROJECT_SOURCE_DIR}/ncmlib"
"${PROJECT_SOURCE_DIR}/ifchd")
add_subdirectory(ncmlib) add_subdirectory(ncmlib)
add_subdirectory(ifchd) add_subdirectory(ifchd)

View File

@ -9,6 +9,7 @@ NCM_OBJS = $(NCM_SRCS:.c=.o)
IFCHD_OBJS = $(IFCHD_SRCS:.c=.o) IFCHD_OBJS = $(IFCHD_SRCS:.c=.o)
NDHC_OBJS = $(NDHC_SRCS:.c=.o) NDHC_OBJS = $(NDHC_SRCS:.c=.o)
NCM_INC = -I./ncmlib NCM_INC = -I./ncmlib
IFCH_INC = -I./ifchd
BUILD_DIR = build BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/objs OBJ_DIR = $(BUILD_DIR)/objs
@ -36,7 +37,7 @@ ifchd: $(IFCHD_OBJS)
$(CC) $(CFLAGS) $(NCM_INC) -o $(BUILD_DIR)/$@ $(subst ifchd/,$(OBJ_DIR)/ifchd/,$(IFCHD_OBJS)) $(BUILD_DIR)/ncmlib.a -lcap $(CC) $(CFLAGS) $(NCM_INC) -o $(BUILD_DIR)/$@ $(subst ifchd/,$(OBJ_DIR)/ifchd/,$(IFCHD_OBJS)) $(BUILD_DIR)/ncmlib.a -lcap
ndhc: $(NDHC_OBJS) ndhc: $(NDHC_OBJS)
$(CC) $(CFLAGS) $(NCM_INC) -o $(BUILD_DIR)/$@ $(subst ndhc/,$(OBJ_DIR)/ndhc/,$(NDHC_OBJS)) $(BUILD_DIR)/ncmlib.a -lcap $(CC) $(CFLAGS) $(IFCH_INC) $(NCM_INC) -o $(BUILD_DIR)/$@ $(subst ndhc/,$(OBJ_DIR)/ndhc/,$(NDHC_OBJS)) $(BUILD_DIR)/ncmlib.a -lcap
.PHONY: all clean .PHONY: all clean

View File

@ -47,7 +47,7 @@
#include "pidfile.h" #include "pidfile.h"
#include "signals.h" #include "signals.h"
#include "strlist.h" #include "strlist.h"
#include "ifproto.h" #include "ifch_proto.h"
#include "strl.h" #include "strl.h"
#include "cap.h" #include "cap.h"
#include "io.h" #include "io.h"

View File

@ -40,7 +40,7 @@
#include "ifchd-defines.h" #include "ifchd-defines.h"
#include "log.h" #include "log.h"
#include "strlist.h" #include "strlist.h"
#include "ifproto.h" #include "ifch_proto.h"
#include "strl.h" #include "strl.h"
/* Symbolic name of the interface associated with a connection. */ /* Symbolic name of the interface associated with a connection. */

View File

@ -39,6 +39,7 @@
#include "io.h" #include "io.h"
#include "strl.h" #include "strl.h"
#include "ifchange.h" #include "ifchange.h"
#include "ifch_proto.h"
static int cfg_deconfig; // Set if the interface has already been deconfigured. static int cfg_deconfig; // Set if the interface has already been deconfigured.
static struct dhcpmsg cfg_packet; // Copy of the current configuration packet. static struct dhcpmsg cfg_packet; // Copy of the current configuration packet.
@ -167,9 +168,9 @@ void ifchange_deconfig(void)
sockfd = open_ifch(); sockfd = open_ifch();
snprintf(buf, sizeof buf, "interface:%s:ip:0.0.0.0:", snprintf(buf, sizeof buf, CMD_INTERFACE ":%s:" CMD_IP ":0.0.0.0:",
client_config.interface); client_config.interface);
log_line("Sent to ifchd: ip:0.0.0.0:"); log_line("Resetting %s IP configuration.", client_config.interface);
sockwrite(sockfd, buf, strlen(buf)); sockwrite(sockfd, buf, strlen(buf));
cfg_deconfig = 1; cfg_deconfig = 1;
@ -223,7 +224,7 @@ void ifchange_bind(struct dhcpmsg *packet)
if (!packet) if (!packet)
return; return;
snprintf(buf, sizeof buf, "interface:%s:", client_config.interface); snprintf(buf, sizeof buf, CMD_INTERFACE ":%s:", client_config.interface);
tbs |= send_client_ip(buf, sizeof buf, packet); tbs |= send_client_ip(buf, sizeof buf, packet);
tbs |= send_cmd(buf, sizeof buf, packet, DHCP_SUBNET); tbs |= send_cmd(buf, sizeof buf, packet, DHCP_SUBNET);
tbs |= send_cmd(buf, sizeof buf, packet, DHCP_ROUTER); tbs |= send_cmd(buf, sizeof buf, packet, DHCP_ROUTER);

View File

@ -24,6 +24,7 @@
#include "options.h" #include "options.h"
#include "log.h" #include "log.h"
#include "ifch_proto.h"
struct dhcp_option { struct dhcp_option {
char name[10]; char name[10];
@ -36,35 +37,30 @@ struct dhcp_option {
#define OPTION_REQ 16 #define OPTION_REQ 16
// Marks an option that can be sent as a list of multiple items. // Marks an option that can be sent as a list of multiple items.
#define OPTION_LIST 32 #define OPTION_LIST 32
static const struct dhcp_option options[] = { static const struct dhcp_option options[] = {
// name[10] type code // name[10] type code
{"subnet" , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x01}, {CMD_SUBNET , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x01},
{"timezone" , OPTION_S32, 0x02}, {CMD_TIMEZONE , OPTION_S32, 0x02},
{"router" , OPTION_IP | OPTION_REQ, 0x03}, {CMD_ROUTER , OPTION_IP | OPTION_REQ, 0x03},
{"timesvr" , OPTION_IP | OPTION_LIST, 0x04}, {CMD_TIMESVR , OPTION_IP | OPTION_LIST, 0x04},
{"namesvr" , OPTION_IP | OPTION_LIST, 0x05}, {CMD_DNS , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06},
{"dns" , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06}, {CMD_LPRSVR , OPTION_IP | OPTION_LIST, 0x09},
{"logsvr" , OPTION_IP | OPTION_LIST, 0x07}, {CMD_HOSTNAME , OPTION_STRING | OPTION_REQ, 0x0c},
{"cookiesvr", OPTION_IP | OPTION_LIST, 0x08}, {CMD_DOMAIN , OPTION_STRING | OPTION_REQ, 0x0f},
{"lprsvr" , OPTION_IP | OPTION_LIST, 0x09}, {CMD_IPTTL , OPTION_U8, 0x17},
{"hostname" , OPTION_STRING | OPTION_REQ, 0x0c}, {CMD_MTU , OPTION_U16, 0x1a},
{"bootsize" , OPTION_U16, 0x0d}, {CMD_BROADCAST, OPTION_IP | OPTION_REQ, 0x1c},
{"domain" , OPTION_STRING | OPTION_REQ, 0x0f}, {CMD_NTPSRV , OPTION_IP | OPTION_LIST, 0x2a},
{"swapsvr" , OPTION_IP, 0x10}, {CMD_WINS , OPTION_IP | OPTION_LIST, 0x2c},
{"rootpath" , OPTION_STRING, 0x11}, // Past this point, these options are not useful for client configuration
{"ipttl" , OPTION_U8, 0x17}, // and contain DHCP protocol metadata. Perhaps they can be removed.
{"mtu" , OPTION_U16, 0x1a},
{"broadcast", OPTION_IP | OPTION_REQ, 0x1c},
{"ntpsrv" , OPTION_IP | OPTION_LIST, 0x2a},
{"wins" , OPTION_IP | OPTION_LIST, 0x2c},
{"requestip", OPTION_IP, 0x32}, {"requestip", OPTION_IP, 0x32},
{"lease" , OPTION_U32, 0x33}, {"lease" , OPTION_U32, 0x33},
{"dhcptype" , OPTION_U8, 0x35}, {"dhcptype" , OPTION_U8, 0x35},
{"serverid" , OPTION_IP, 0x36}, {"serverid" , OPTION_IP, 0x36},
{"message" , OPTION_STRING, 0x38}, {"message" , OPTION_STRING, 0x38},
{"maxsize" , OPTION_U16, 0x39}, {"maxsize" , OPTION_U16, 0x39},
{"tftp" , OPTION_STRING, 0x42},
{"bootfile" , OPTION_STRING, 0x43},
{"NONE" , OPTION_NONE, 0x00} {"NONE" , OPTION_NONE, 0x00}
}; };