[systemd-devel] [PATCH 00/28] Initial DHCP v4 library implementation

Patrik Flykt patrik.flykt at linux.intel.com
Wed Nov 13 13:22:28 PST 2013


	Hi,

This patch set implements a DHCPv4 client library named libsystemd-dhcp
to be used with systemd-network.

The code implements the DHCP protocol from the INIT state up to expiry,
T1 and T2 timer setting, but does nothing in response to the IP address
reacquisition T1 and T2 timers being triggered. Expiry timer is followed
and the DHCP client stopped when it triggers. INIT-REBOOT state is also
not yet implemented; both these missing parts are to be implemented next.

The code assumes that the caller can figure out the interface to use.
The code expects to be handed an sd_event loop, a MAC address and an
interface index. The outcome is a notification of an IP address being
acquired and the callback provider is expected to set the IP address,
netmask and default gateway. Higher level DHCP options such as DNS and
NTP servers are requested from the server by default, but the response
is not yet collected anywhere. I also don't know how detailed callback
information is needed, is there for example any need to know the protocol
state transitions or messages sent/received.

Two test programs are created, one for setting and getting options and
the other for client structure initialization and Discover message
verification. The intention is to pass further DHCP server responses and
verifying that the replies from the client make sense.

The socket part of the code is singled out into a file of its own in
order to be able to write some nice tests while having the DHCP client
code running as normally as possible.

A very small example client is also created, I used it to watch the client-
server interaction via Wireshark.


Please review and comment,


       Patrik


Patrik Flykt (28):
  dhcp: Add DHCP protocol structures and initial defines
  dhcp: Add DHCP client initialization
  dhcp: Add test for DHCP client initialization and parameter setting
  build: Add initial build support
  dhcp: Add option appending and parsing
  dhcp: Add buffer length and invalid cookie tests for DHCP options
  build: Add DHCP option test
  dhcp: Add tests for DHCP options, file and sname fields
  dhcp: Add option append tests
  dhcp: Add test function for computing checksum
  dhcp: Add function for sending a raw packet
  dhcp: Add DHCP discover sending
  build: Add libsystemd-dhcp
  dhcp: Add test for discover DHCP packet creation
  dhcp: Add example DHCP client test program
  build: Add example DHCP test program
  dhcp: Support seconds elapsed since start of DHCP negotiation
  dhcp: Add function to stop the DHCP client
  build: Add dependency on libsystemd-bus needed for main loop
  dhcp: Add timeout and main loop support
  dhcp: Handle received DHCP Offer message
  dhcp: Send DHCP Request to acquire an IP address
  dhcp: Add maximum message size option
  dhcp: Process DHCP Ack/Nak message
  dhcp: Compute expire, T1 and T2 timers
  dhcp: Add notification callback
  dhcp: Add function to free DHCP client data
  dhcp: Use callback in test client

 Makefile.am                    |   60 +++
 configure.ac                   |    9 +
 src/dhcp/Makefile              |    1 +
 src/dhcp/client.c              | 1033 ++++++++++++++++++++++++++++++++++++++++
 src/dhcp/client.h              |   55 +++
 src/dhcp/dhcp-example-client.c |  170 +++++++
 src/dhcp/internal.h            |   40 ++
 src/dhcp/network.c             |   66 +++
 src/dhcp/option.c              |  181 +++++++
 src/dhcp/protocol.h            |  106 +++++
 src/dhcp/test-dhcp-client.c    |  222 +++++++++
 src/dhcp/test-dhcp-option.c    |  381 +++++++++++++++
 12 files changed, 2324 insertions(+)
 create mode 120000 src/dhcp/Makefile
 create mode 100644 src/dhcp/client.c
 create mode 100644 src/dhcp/client.h
 create mode 100644 src/dhcp/dhcp-example-client.c
 create mode 100644 src/dhcp/internal.h
 create mode 100644 src/dhcp/network.c
 create mode 100644 src/dhcp/option.c
 create mode 100644 src/dhcp/protocol.h
 create mode 100644 src/dhcp/test-dhcp-client.c
 create mode 100644 src/dhcp/test-dhcp-option.c

-- 
1.7.10.4



More information about the systemd-devel mailing list