Hello qemu-devel, This patch series adds support of vendor-specific info option to built-in (slirp) DHCP server. This feature would be useful for those who develop and test DHCP-based systems (e.g. auto-configuration) using QEMU.
Vendor-specific information option is defined in RFC2132 - this is Option 43 of DHCP. It allows setting vendor-specific information as a single option in "raw bytes" form or as multiple options in tag-length-value (TLV) form. User interface: To pass vendor-specific information to built-in DHCP server, QEMU command-line suboption [,dhcpvendopt=optstring] is added to "-net user" option. The optstring should be provided in the following form: "tag1:value1;tag2:value2", i.e. each option is separated by semicolon (Note: on most terminals it must be escaped '\;'), option tag and value are separated by ':' colon. Accepted tag values are [1-254]. Single tag-less option "value" is also supported. Zero tag "0:" can be used to 'escape' special single options beginning with tag-like value (e.g. single MAC address can be specified as "0:10:FE:20:AB:CD:78"). Design details: This vendor-specific info optstring is passed to slirp initialization functions and parsed by translate_dhcp_vendopt() function from dhcp_vendopt.c module. The result buffer of bytes (unit8_t's) is stored in the global instance of Slirp. Later it is added to the end of DHCP Offer and ACK packets. Testing: 1. This patch was manually tested on x86_64-softmmu system with Fedora 20 guest. DHCP Offer and ACK packets were checked using Wireshark. 2. Unit test is written for the dhcp_vendopt.c translator. It contains 27 tests with 100% coverage of dhcp_vendopt.c as reported by gcov. 3. checkpatch.pl reports no errors. There is a number of warnings "line over 80 characters" for test-dhcp-vendopt.c which are excusable (long test data; but the number can be decreased) This is my first patch to QEMU, sorry if I've missed something. I'll try to answer to your comments and fix issues promptly. Fedor Lyakhov (7): slirp: Move BOOTP/DHCP protocol defines to a separate header slirp: Add header inclusion guard to slirp/debug.h slirp: Add new command-line suboption "[,dhcpvendopt=optstring]" to "-net user" slirp: Add translator of DHCP vendor option string to DHCP TLV representation slirp: Add DHCP vendor option to DHCP Offer/Ack packet slirp: Add description of new "dhcpvendopt" suboption to the help and man page slirp: Add unit test for slirp/dhcp_vendopt.c module net/slirp.c | 9 +- qapi-schema.json | 3 + qemu-options.hx | 16 +++- slirp/Makefile.objs | 1 + slirp/bootp.c | 16 +++- slirp/bootp.h | 95 +--------------------- slirp/bootp_defines.h | 99 ++++++++++++++++++++++ slirp/debug.h | 5 ++ slirp/dhcp_vendopt.c | 163 +++++++++++++++++++++++++++++++++++++ slirp/dnssearch.c | 3 +- slirp/libslirp.h | 3 +- slirp/slirp.c | 7 +- slirp/slirp.h | 5 ++ tests/Makefile | 3 + tests/test-dhcp-vendopt.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 526 insertions(+), 105 deletions(-) create mode 100644 slirp/bootp_defines.h create mode 100644 slirp/dhcp_vendopt.c create mode 100644 tests/test-dhcp-vendopt.c -- 1.8.4.5