Skip to content

Feature: implement DHCP options provider and parser #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

valentinalexeev
Copy link

I have implemented a feature to allow Ethernet library user to supply and read DHCP options.

This functionality is very useful when you need to provide run-time configuration to the Arduino board. Since objective of DHCP is "host configuration" it is an ideal choice to use to pass parameters to the board. This commit also allows board to send additional options as part of the request. In my case, for example, it was necessary to provide additional Vendor Class Identifier (option 60) for the DHCP server to answer.

Here is a sample code:

// Define two functions to provide the DHCP options:

/** DHCP custom option parser.
 * At the moment will extract DNS domain (option 15) and store it separately).
 *
 * \warning The code must read() through the option even if it is unknown.
 * @param optionType DHCP option type as per standard.
 * @param dhcpUdpSocket Reference to UDP socket where to read the data from.
 */
void dhcpOptionParser(const uint8_t optionType, EthernetUDP *dhcpUdpSocket) {
    uint8_t opt_len = dhcpUdpSocket->read();

    if (optionType == 15) { // domain name
        // read the value with dhcpUdpSocket->read()
    } else {
        while (opt_len--) {
            dhcpUdpSocket->read();
        }        
    }
}

/** DHCP option provider.
 * Send Vendor Class Identifier (60) option as part of DHCP request.
 * @param messageType type of outgoing DHCP message
 * @param dhcpUdpSocket socket to write to
 */
void dhcpOptionProvider(const uint8_t messageType, EthernetUDP *dhcpUdpSocket) {
    uint8_t buffer[] = {
        dhcpClassIdentifier,
        0x08,
        'M','S','F','T',' ','5','.','0'
    };
    dhcpUdpSocket->write(buffer, 10);
}

//...

// Initialize the Ethernet library in setup() phase
void setup() {
    // ...
    Ethernet.begin(mac, (DhcpOptionParser *) &dhcpOptionParser, (DhcpOptionProvider *) &dhcpOptionProvider);
    // ...
}

Please refer to dhcp-options(5) http://linux.die.net/man/5/dhcp-options chapter "Defining New Options" for an example on how to provide custom options with isc-dhcp server. Other DHCP servers should have similar support.

@ffissore ffissore added the New label Feb 27, 2014
@cmaglie cmaglie added feature request A request to make an enhancement (not a bug fix) Library: Ethernet The Ethernet Arduino library labels Feb 20, 2015
@koenvdheuvel
Copy link

koenvdheuvel commented Jan 20, 2018

Is this ever going to be implemented? This feature would be really useful.

@valentinalexeev
Copy link
Author

@koenvdheuvel I’m not sure if my patch is still compatible with the current Arduino code base. It may require FF and rework in my repo first.

Feel free to resubmit PR if you have working code for the same and then this PR can be closed.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Valentin Alexeev seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A request to make an enhancement (not a bug fix) Library: Ethernet The Ethernet Arduino library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants