diff --git a/CMakeLists.txt b/CMakeLists.txt index e2c52d8..435be93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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_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(ifchd) diff --git a/Makefile b/Makefile index 83ae976..65aad04 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ NCM_OBJS = $(NCM_SRCS:.c=.o) IFCHD_OBJS = $(IFCHD_SRCS:.c=.o) NDHC_OBJS = $(NDHC_SRCS:.c=.o) NCM_INC = -I./ncmlib +IFCH_INC = -I./ifchd BUILD_DIR = build 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 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 diff --git a/ifchd/ifchd.c b/ifchd/ifchd.c index b7cad32..3969169 100644 --- a/ifchd/ifchd.c +++ b/ifchd/ifchd.c @@ -47,7 +47,7 @@ #include "pidfile.h" #include "signals.h" #include "strlist.h" -#include "ifproto.h" +#include "ifch_proto.h" #include "strl.h" #include "cap.h" #include "io.h" diff --git a/ifchd/linux.c b/ifchd/linux.c index a281f2c..f71248b 100644 --- a/ifchd/linux.c +++ b/ifchd/linux.c @@ -40,7 +40,7 @@ #include "ifchd-defines.h" #include "log.h" #include "strlist.h" -#include "ifproto.h" +#include "ifch_proto.h" #include "strl.h" /* Symbolic name of the interface associated with a connection. */ diff --git a/ndhc/ifchange.c b/ndhc/ifchange.c index 5c9e586..4baafb4 100644 --- a/ndhc/ifchange.c +++ b/ndhc/ifchange.c @@ -39,6 +39,7 @@ #include "io.h" #include "strl.h" #include "ifchange.h" +#include "ifch_proto.h" static int cfg_deconfig; // Set if the interface has already been deconfigured. static struct dhcpmsg cfg_packet; // Copy of the current configuration packet. @@ -167,9 +168,9 @@ void ifchange_deconfig(void) 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); - log_line("Sent to ifchd: ip:0.0.0.0:"); + log_line("Resetting %s IP configuration.", client_config.interface); sockwrite(sockfd, buf, strlen(buf)); cfg_deconfig = 1; @@ -223,7 +224,7 @@ void ifchange_bind(struct dhcpmsg *packet) if (!packet) 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_cmd(buf, sizeof buf, packet, DHCP_SUBNET); tbs |= send_cmd(buf, sizeof buf, packet, DHCP_ROUTER); diff --git a/ndhc/options.c b/ndhc/options.c index fcbe2dd..954775c 100644 --- a/ndhc/options.c +++ b/ndhc/options.c @@ -24,6 +24,7 @@ #include "options.h" #include "log.h" +#include "ifch_proto.h" struct dhcp_option { char name[10]; @@ -36,35 +37,30 @@ struct dhcp_option { #define OPTION_REQ 16 // Marks an option that can be sent as a list of multiple items. #define OPTION_LIST 32 + static const struct dhcp_option options[] = { // name[10] type code - {"subnet" , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x01}, - {"timezone" , OPTION_S32, 0x02}, - {"router" , OPTION_IP | OPTION_REQ, 0x03}, - {"timesvr" , OPTION_IP | OPTION_LIST, 0x04}, - {"namesvr" , OPTION_IP | OPTION_LIST, 0x05}, - {"dns" , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06}, - {"logsvr" , OPTION_IP | OPTION_LIST, 0x07}, - {"cookiesvr", OPTION_IP | OPTION_LIST, 0x08}, - {"lprsvr" , OPTION_IP | OPTION_LIST, 0x09}, - {"hostname" , OPTION_STRING | OPTION_REQ, 0x0c}, - {"bootsize" , OPTION_U16, 0x0d}, - {"domain" , OPTION_STRING | OPTION_REQ, 0x0f}, - {"swapsvr" , OPTION_IP, 0x10}, - {"rootpath" , OPTION_STRING, 0x11}, - {"ipttl" , OPTION_U8, 0x17}, - {"mtu" , OPTION_U16, 0x1a}, - {"broadcast", OPTION_IP | OPTION_REQ, 0x1c}, - {"ntpsrv" , OPTION_IP | OPTION_LIST, 0x2a}, - {"wins" , OPTION_IP | OPTION_LIST, 0x2c}, + {CMD_SUBNET , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x01}, + {CMD_TIMEZONE , OPTION_S32, 0x02}, + {CMD_ROUTER , OPTION_IP | OPTION_REQ, 0x03}, + {CMD_TIMESVR , OPTION_IP | OPTION_LIST, 0x04}, + {CMD_DNS , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06}, + {CMD_LPRSVR , OPTION_IP | OPTION_LIST, 0x09}, + {CMD_HOSTNAME , OPTION_STRING | OPTION_REQ, 0x0c}, + {CMD_DOMAIN , OPTION_STRING | OPTION_REQ, 0x0f}, + {CMD_IPTTL , OPTION_U8, 0x17}, + {CMD_MTU , OPTION_U16, 0x1a}, + {CMD_BROADCAST, OPTION_IP | OPTION_REQ, 0x1c}, + {CMD_NTPSRV , OPTION_IP | OPTION_LIST, 0x2a}, + {CMD_WINS , OPTION_IP | OPTION_LIST, 0x2c}, +// Past this point, these options are not useful for client configuration +// and contain DHCP protocol metadata. Perhaps they can be removed. {"requestip", OPTION_IP, 0x32}, {"lease" , OPTION_U32, 0x33}, {"dhcptype" , OPTION_U8, 0x35}, {"serverid" , OPTION_IP, 0x36}, {"message" , OPTION_STRING, 0x38}, {"maxsize" , OPTION_U16, 0x39}, - {"tftp" , OPTION_STRING, 0x42}, - {"bootfile" , OPTION_STRING, 0x43}, {"NONE" , OPTION_NONE, 0x00} };