Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
misje committed May 9, 2019
2 parents 69a33ca + 7252b5f commit 0ef6605
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 0.5.2 - 2019-05-09
### Added
- Add example output "screenshot" to README.

### Changed
- Create PID file after initialising signal handler.
- Remove incompatible compiler warning option when using clang.
- Use a variable for the project/binary name in CMakeLists.txt.

### Fixed
- Indicate that configuration file is an optional argument in usage output.
- Fix error message output when passing option/keyward too many times.
- Improve wording in configuration file parsing error messages.

## 0.5.1 - 2019-04-16
### Changed
- Use 1-byte alignment on DHCP options.
- Refer to salsa.debian.org for deb package source.
- Remove old bug reference in README.

### Fixed
- Allow optional values to configuration file keywords (corretly support
- Allow optional values to configuration file keywords (correctly support
"pid-file" as on the command line).

## 0.5.0 - 2019-04-09
Expand Down
26 changes: 19 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.0)
# Allow setting PROJECT_VERSION through project():
cmake_policy(SET CMP0048 NEW)

# Don't bother writing the project name all the time:
set(PROJECT dhcpoptinj)

if(DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, Debug or Release")
else()
Expand All @@ -13,7 +16,12 @@ else()
set(CMAKE_INSTALL_PREFIX /usr CACHE STRING "Choose install prefix")
endif()

project(dhcpoptinj LANGUAGES C VERSION 0.5.1)
project(
${PROJECT}
VERSION 0.5.2
DESCRIPTION "DHCP option injector"
LANGUAGES C
)
add_definitions(-DDHCPOPTINJ_VERSION="${PROJECT_VERSION}")
set(SOURCES
src/config.c
Expand All @@ -29,9 +37,9 @@ set(HEADERS
src/options.h
src/udp.h
)
add_executable(dhcpoptinj ${SOURCES} ${HEADERS})
set_property(TARGET dhcpoptinj PROPERTY C_STANDARD 99)
target_compile_options(dhcpoptinj PRIVATE
add_executable(${PROJECT} ${SOURCES} ${HEADERS})
set_property(TARGET ${PROJECT} PROPERTY C_STANDARD 99)
target_compile_options(${PROJECT} PRIVATE
-Wall
-Wextra
-pedantic
Expand All @@ -40,7 +48,6 @@ target_compile_options(dhcpoptinj PRIVATE
-Wdisabled-optimization
-Wformat=2
-Winit-self
-Wlogical-op
-Wmissing-declarations
-Wmissing-include-dirs
-Wredundant-decls
Expand All @@ -62,10 +69,15 @@ target_compile_options(dhcpoptinj PRIVATE
-D_DEFAULT_SOURCE
-D_FORTIFY_SOURCE=2
)
# Only add -Wlogical-op if using gcc; clang does not support this warning option:
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(${PROJECT} PRIVATE "-Wlogical-op")
endif()

find_library(NFQ_LIB netfilter_queue REQUIRED)
target_link_libraries(dhcpoptinj ${NFQ_LIB})
install(TARGETS dhcpoptinj DESTINATION sbin)
target_link_libraries(${PROJECT} ${NFQ_LIB})

install(TARGETS ${PROJECT} DESTINATION sbin)
# Add uninstall target, since cmake does not:
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
Expand Down
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ nor does it check whether your option code exists. It does however forbid you
to use the option code 255 (the terminating end option). dhcpoptinj inserts
this option as the last option automatically.

## Screenshot
```
dhcpoptinj -f -d -q42 -r -o'0C 66 6A 61 73 65 68 6F 73 74' -o'52 01 04 46 6A 61 73' -o 320A141E28
```
```
3 DHCP option(s) to inject (with a total of 25 bytes): 12 (0x0C) (Hostname), 82 (0x52) (Relay Agent Information), 50 (0x32) (Address Request)
Existing options will be removed
Initialising netfilter queue
Initialising signal handler
Initialisation completed. Waiting for packets to mangle on queue 42
Received 416 bytes
Inspecting 328-byte DHCP packet from B6:40:FE:41:30:DC to 255.255.255.255:67
Mangling packet
Found option 53 (0x35) (DHCP message type) DHCPREQUEST (copying)
Found option 54 (0x36) (DHCP Server Id) with 4-byte payload 0A 14 1E 01 (copying)
Found option 50 (0x32) (Address Request) with 4-byte payload 0A 14 1E 28 (removing)
Found option 12 (0x0C) (Hostname) with 12-byte payload 33 31 36 64 65 39 31 34 64 61 62 34 (removing)
Found option 55 (0x37) (Parameter List) with 13-byte payload 01 1C 02 03 0F 06 77 0C 2C 2F 1A 79 2A (copying)
Found END option (removing)
Injecting option 12 (0x0C) (Hostname) with 9-byte payload 66 6A 61 73 65 68 6F 73 74
Injecting option 82 (0x52) (Relay Agent Information) with 6-byte payload 01 04 46 6A 61 73
Injecting option 50 (0x32) (Address Request) with 4-byte payload 0A 14 1E 28
Inserting END option
Padding with 10 byte(s) to meet minimal BOOTP payload size
Sending mangled packet
```

## Installing

dhcpoptinj is submitted to Debian and will hopefully make it to unstable (and
Expand Down Expand Up @@ -129,7 +157,7 @@ The options *version*, *help* and *conf-file* are not accepted in a
configuration file.

Example:
```conf
```apache
# Run in foreground:
foreground
# Enable debug output:
Expand Down
10 changes: 5 additions & 5 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static void printUsage(void)
printf(
"\n"
"Usage: %s [-df] [--forward-on-fail] [-i|-r] [-p [pid_file]] \n"
" %*s [-c config_file]\n"
" %*s [-c [config_file]]\n"
" %*s -q queue_num -o dhcp_option [(-o dhcp_option) ...]\n"
" %s -h|-v\n"
,
Expand Down Expand Up @@ -572,8 +572,8 @@ static void validateOptionCombinations(void)
{
fprintf(stderr, "%s%s can only be %s once\n",
source == SOURCE_CMD_LINE ? "Option --" : "Keyword ",
source == SOURCE_CMD_LINE ? "passed" : "specified",
options[option].name);
options[option].name,
source == SOURCE_CMD_LINE ? "passed" : "specified");
printUsage();
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -633,13 +633,13 @@ static int parseKeyValue(const char *key, const char *value, const char *filePat

if (options[option].has_arg == required_argument && !value)
{
fprintf(stderr, "Failed to parse \"%s\" at line %u: %s requires an argument\n",
fprintf(stderr, "Failed to parse \"%s\" at line %u: keyword \"%s\" requires an argument\n",
filePath, lineNo, options[option].name);
exit(EXIT_FAILURE);
}
else if (!options[option].has_arg && value)
{
fprintf(stderr, "Failed to parse \"%s\" at line %u: %s does not take an argument\n",
fprintf(stderr, "Failed to parse \"%s\" at line %u: keyword \"%s\" does not take an argument\n",
filePath, lineNo, options[option].name);
exit(EXIT_FAILURE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/dhcpoptinj.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ int main(int argc, char *argv[])
umask(022);
daemonised = true;
}
writePID();

initSignalHandler();
writePID();

if (config->debug)
logMessage(LOG_DEBUG, "Initialisation completed. Waiting for packets to "
Expand Down

0 comments on commit 0ef6605

Please sign in to comment.