Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ CFLAGS+= \
-DNDEBUG
endif

ifeq ($(USE_IWYU),1)
IWYU ?= $(shell which iwyu || echo @true)
else
IWYU ?= @true
endif

prefix?=/usr
INSTALL = install
INSTALL_FILE = $(INSTALL) -D -p -m 644
Expand Down Expand Up @@ -89,8 +95,15 @@ clean:
style:
astyle --mode=c --options=none -s2 -f -j -k1 -W3 -p -U -H *.c *.h

iwyu:
${MAKE} USE_IWYU=1 clean all

install:
$(INSTALL_PROGRAM) ddhcpd $(DESTDIR)$(prefix)/sbin/ddhcpd
$(INSTALL_PROGRAM) ddhcpdctl $(DESTDIR)$(prefix)/sbin/ddhcpdctl

%.o: %.c %.h
${CC} ${CFLAGS} -c $< -o $@
${IWYU} -Xiwyu --no_comments -Xiwyu --no_fwd_decls -Xiwyu --mapping_file=ddhcpd.imp -DDDHCPD_STATISTICS -c $< -o $@ || true

-include *.d
10 changes: 9 additions & 1 deletion block.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#include "block.h"

#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <arpa/inet.h>

#include <sys/types.h>

#include "dhcp.h"
#include "list.h"
#include "logger.h"
#include "packet.h"
#include "statistics.h"
#include "tools.h"

Expand Down
8 changes: 3 additions & 5 deletions block.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _BLOCK_H
#define _BLOCK_H
#pragma once

#include <stdint.h>

#include "types.h"
#include "packet.h"

/**
* Allocate block.
Expand Down Expand Up @@ -83,5 +83,3 @@ ATTR_NONNULL_ALL void block_show_status(int fd, ddhcp_config* config);
* Reset needless markers in all blocks
*/
void block_unmark_needless(ddhcp_config* config);

#endif
7 changes: 6 additions & 1 deletion control.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#include "control.h"
#include "logger.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "block.h"
#include "dhcp_options.h"
#include "logger.h"
#include "statistics.h"

extern int log_level;
Expand Down
9 changes: 5 additions & 4 deletions control.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef _CONTROL_H
#define _CONTROL_H
#pragma once

#include <stdint.h>

#include <sys/types.h>

#include "types.h"

Expand All @@ -14,5 +17,3 @@ enum {
};

ATTR_NONNULL_ALL int handle_command(int socket, uint8_t* buffer, ssize_t msglen, ddhcp_config* config);

#endif
15 changes: 14 additions & 1 deletion ddhcp.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#include "ddhcp.h"

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "ddhcp.h"
#include <arpa/inet.h>

#include <netinet/in.h>

#include <sys/socket.h>

#include "block.h"
#include "dhcp.h"
#include "dhcp_packet.h"
#include "logger.h"
#include "packet.h"
#include "tools.h"
#include "statistics.h"

Expand Down
14 changes: 8 additions & 6 deletions ddhcp.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#ifndef _DDHCP_H
#define _DDHCP_H
#pragma once

#include <stdint.h>

#include <netinet/in.h>

#include <sys/types.h>

#include "packet.h"
#include "types.h"
#include "list.h"
#include "block.h"

/**
* Initialise the blocks data structure in the global configuration state.
Expand Down Expand Up @@ -65,5 +69,3 @@ ATTR_NONNULL_ALL void ddhcp_dhcp_release(struct ddhcp_mcast_packet* packet, ddhc
ATTR_NONNULL_ALL ddhcp_block* block_find_lease(ddhcp_config* config);

ATTR_NONNULL_ALL void house_keeping(ddhcp_config* config);

#endif
6 changes: 6 additions & 0 deletions ddhcpd.imp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{ include: [ "<bits/getopt_core.h>", "private", "<getopt.h>", "public" ] },
{ include: [ "<bits/stdint-intn.h>", "private", "<stdint.h>", "public" ] },
{ include: [ "<bits/stdint-uintn.h>", "private", "<stdint.h>", "public" ] },
{ include: [ "<bits/types/time_t.h>", "private", "<time.h>", "public" ] }
]
9 changes: 8 additions & 1 deletion dhcp.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#include "dhcp.h"

#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <arpa/inet.h>

#include <netinet/in.h>

#include "block.h"
#include "dhcp.h"
#include "dhcp_options.h"
#include "hook.h"
#include "logger.h"
Expand Down
12 changes: 7 additions & 5 deletions dhcp.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#ifndef _DHCP_H
#define _DHCP_H
#pragma once

/**
* DHCP Structures
*/

#include "types.h"
#include <stdint.h>

#include <sys/types.h>

#include "dhcp_packet.h"
#include "types.h"

/**
* DHCP Process Packet
Expand Down Expand Up @@ -87,5 +91,3 @@ ATTR_NONNULL_ALL void dhcp_release_lease(uint32_t address, ddhcp_config* config)
* Return the number of free leases in the block.
*/
ATTR_NONNULL_ALL int dhcp_check_timeouts(ddhcp_block* block);

#endif
7 changes: 5 additions & 2 deletions dhcp_options.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "dhcp_options.h"

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <errno.h>
#include <netinet/in.h>

#include "dhcp_options.h"
#include "list.h"
#include "logger.h"
#include "tools.h"
Expand Down
8 changes: 4 additions & 4 deletions dhcp_options.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifndef _DHCP_OPTIONS_H
#define _DHCP_OPTIONS_H
#pragma once

#include <stddef.h>
#include <stdint.h>

#include "types.h"

Expand Down Expand Up @@ -90,5 +92,3 @@ ATTR_NONNULL_ALL int dhcp_options_init(ddhcp_config* config);
* Search for option in store and if found store it in the options list.
*/
ATTR_NONNULL_ALL int set_option_from_store(dhcp_option_list* store, dhcp_option* options, uint8_t len, uint8_t code);

#endif
15 changes: 14 additions & 1 deletion dhcp_packet.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#include <arpa/inet.h>
#include "dhcp_packet.h"

#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <arpa/inet.h>

#include <netinet/in.h>

#include <sys/socket.h>
#include <sys/types.h>

#include "list.h"
#include "types.h"
#include "logger.h"

Expand Down
14 changes: 8 additions & 6 deletions dhcp_packet.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#ifndef _DHCP_PACKET_H
#define _DHCP_PACKET_H
#pragma once

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <netinet/in.h>
#include "types.h"

#include <sys/types.h>

#include "list.h"

// List of dhcp_packet
typedef struct list_head dhcp_packet_list;
Expand Down Expand Up @@ -99,5 +103,3 @@ ATTR_NONNULL_ALL ssize_t ntoh_dhcp_packet(dhcp_packet* packet, uint8_t* buffer,
ATTR_NONNULL_ALL ssize_t dhcp_packet_send(int socket, dhcp_packet* packet);

ATTR_NONNULL_ALL uint8_t dhcp_packet_message_type(dhcp_packet* packet);

#endif
11 changes: 8 additions & 3 deletions hook.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#include "hook.h"
#include "logger.h"
#include "tools.h"

#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

#include <arpa/inet.h>

#include <sys/wait.h>

#include "logger.h"
#include "tools.h"

ATTR_NONNULL_ALL void hook(uint8_t type, struct in_addr* address, uint8_t* chaddr, ddhcp_config* config) {
#if LOG_LEVEL_LIMIT >= LOG_DEBUG
char* hwaddr = hwaddr2c(chaddr);
Expand Down
9 changes: 5 additions & 4 deletions hook.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef _HOOK_H
#define _HOOK_H
#pragma once

#include <stdint.h>

#include <netinet/in.h>

#include "types.h"

Expand All @@ -9,5 +12,3 @@

ATTR_NONNULL_ALL void hook(uint8_t type, struct in_addr* address, uint8_t* chaddr, ddhcp_config* config);
void hook_init();

#endif
9 changes: 3 additions & 6 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LINUX_LIST_H_
#define _LINUX_LIST_H_
#pragma once

#include <stddef.h>
#include <stdbool.h>
#include <stddef.h>

#include "types.h"
#include "macros.h"

#define prefetch(x)

Expand Down Expand Up @@ -207,5 +206,3 @@ list_splice_tail_init(struct list_head* list, struct list_head* head)
_list_splice(list, head->prev, head);
INIT_LIST_HEAD(list);
}

#endif /* _LINUX_LIST_H_ */
5 changes: 3 additions & 2 deletions logger.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <stdarg.h>

#include "logger.h"

#include <stdarg.h>
#include <stdio.h>

int log_level = LOG_LEVEL_DEFAULT;

ATTR_NONNULL_ALL void logger(int level, const char* prefix, ...) {
Expand Down
5 changes: 1 addition & 4 deletions logger.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _LOGGER_H
#define _LOGGER_H
#pragma once

/**
* A set of logging function which allow compile time and runtime logging decissions.
Expand Down Expand Up @@ -60,5 +59,3 @@ ATTR_NONNULL_ALL void logger(int level, const char* prefix, ...);
#else
#define DEBUG(...)
#endif

#endif
4 changes: 4 additions & 0 deletions macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#define ATTR_NONNULL_ALL __attribute__((nonnull))
#define ATTR_NONNULL(...) __attribute__((nonnull( __VA_ARGS__ )))
Loading