Home UC3M
Home IT

RFC 2131 implementation: Dynamic Host Configuration Protocol (DHCP)

 INTRODUCCIÓN


The objective of this practical assignment is to develop a reduced implementation of RFC 2131: Dynamic Host Configuration Protocol (DHCP), which enables networked devices (clients) to obtain the parameters necessary for operation in an Internet Protocol network. DHCP is a bootstrap protocol as well as an autoconfiguration protocol. It is a bootstrap protocol because it can get the parameters needed for a computer to start (for example, it makes possible to find an OS image for later download via TFTP). Also, it is an autoconfiguration protocol, because it defines the mechanisms for obtaining IP addresses and other parameters.

DHCP emerged as a standard protocol in October 1993 as defined in RFC 1531, succeeding the BOOTP protocol. The next update, RFC 2131 released in 1997 is the current DHCP definition. The latest proposed standard for DHCP over IPv6 (DHCPv6) can be found in RFC 3315. This practical assignment is focused exclusively on RFC 2131.

There will be seven lab sessions, that will be given in lab 4.1B01. Furthermore, there will be an additional theory class (on Tuesday, 14th) to explain brief notions about sockets programming and DHCP protocol.


 OBJECTIVES


The objectives of this practical assignment are:

  1. To face the implementation of a real application-level protocol, starting from its original specification and understanding the RFC.
  2. To acquire knowledgement about bootstrap and autoconfiguration protocols, like DHCP, BOOTP y RARP. BOOTP (BOOTstrap Protocol) is an standard that precedes DHCP and it is very similar to it (in fact, they both use the same message format). BOOTP is defined in RFC 1542 and its main inconvenient is that dynamic allocation of IP addresses is not allowed (supported). RARP (Reverse Address Resolution Protocol) is is a Link layer protocol used to obtain an IP address for a given link-layer address.
  3. To go deeper into the protocols studied in the theory classes.
  4. To acquire knowledgement about programming with UDP sockets, raw sockets and Broadcast messages.

 INSTRUCTIONS


The practical assignment must be developed in C programming language over Linux OS and your implementation must work on the Telemática lab computers, where the assessment will take place. Also, there are three hosts available if you want to connect remotely (ssh) from computers external to the university: monitor01.lab.it.uc3m.es, monitor02.lab.it.uc3m.es and monitor03.lab.it.uc3m.es.

It is mandatory the use of the gcc parameter -Wall in every compilation. The code must compile without warnings or errors. Also, the code must not have memory leaks (valgrind will be used to check this). The submission instructions will be published during the course. Basically, the source code (.c and .h files), a Makefile file to compile it, and a README file with some data (name, email address and group) have to be submitted. Practical assignments which do no meet these requirements will not be assessed, i.e., implementations containing memory leaks, compilation warnings or compilation errors, will not be assessed. The DHCPlab environment (manual can be downloaded from here) has been installed in the Telemática labs in order to carry out the practical assignment.

The practical assignment consists of a simplified version of the RFC. Simplifications are listed below. The complete RFC specification can be found in the following link: RFC 2131. The RFC 2131 standard defines both the client and the server requirements for obtaining bootstrap and configuration parameters. However, in this practical assignment only the client implementation is required. Due to the fact that it is neccesary to be root in order to carry out the developement, a test environment will be provided, with all the software installed, including a basic DHCP server.

  • Basic operation:

    Next, the operation of the DHCP protocol will be briefly explained. A deeper explanation of the protocol is out of the scope of this document; it is the student, who should read the complete RFC and understand all the details required for a correct implementation.

    DHCP protocol deals with different kinds of packets DHCP maneja distintos tipos de paquetes de los cuales es obligatorio implementar/reconocer estos seis: DHCPDISCOVER, DHCPOFFER, DHCPREQUEST, DHCPACK, DHCPNACK y DHCPRELEASE.

    DHCP works only with UDP, and it is one of the few protocols that use static port numbers not only for servers (port 67), but also for clients (port 68). DHCP allows to obtain different parameters, such us IP address, subnetwork mask, boot file, DNS, printer server, etc... As an example, in order to obtain those parameters, the client and server mush exchange the following packets (see figure):

    • DHCPDISCOVER, sent by the client. It is an UDP multicast message which is received by DHCP servers.
    • DHCPOFFER, where IP addresses are offered by one or several servers. Client should choose one.
    • DHCPREQUEST, sent by the client. It is an UDP message (unicast or multicast) to request an specific address.
    • DHCPACK, sent by the server to confirm an IP.

    There are other messages, like DHCPNACK and DHCPRELEASE, which are not shown in the previous image but whose implementation/support is mandatory.

    So it is mandatory to implement a DHCP client taking these considerations into account:

  • Executable and parameters: The executable must be named dhcpcl and must support the following input parameters:
    dhcpcl interface [-t timeout] [-h hostname] [-a IP address] [-l leasetime] [-d] 
    
    • -t timeout: specifies (in seconds) how long the client will try to get an IP address. The default value is 64 seconds.
    • -h hostname: specifies the string that will appear in the hostname option field of the DHCP datagram.
    • -a IP address: indicates the last known IP address, so that it is sent in the DHCPDISCOVER message.
    • -l leasetime: specifies (in seconds and decimal) the value of the leasetime timer suggested to the server. Note the server can overwrite this value. If it is not specified, the default value is infinite.
    • -d: debugging mode. Developers must use this mode to isolate users from the implemented debugging output messages.


  • Examples and input/output format:

    • Obtaining of an IP address. The dhcpcl program must activate the interface first:
       ; ifconfig
        lo      Link encap:Local Loopback  
                inet addr:127.0.0.1  Mask:255.255.255.0
                UP LOOPBACK RUNNING  MTU:1500  Metric:1
                RX packets:306 errors:0 dropped:0 overruns:0 frame:0
                TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0 
                RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
         
        ; dhcpcl eth1 -t 15 -h zorak -a 192.168.100.25
        #[2008-10-11 15:30:34+02:00] (0x12345678) pid = 13086
        #[2008-10-11 15:30:39+02:00] (0x12345678) DHCPDISCOVER sent.
        #[2008-10-11 15:30:40+02:00] (0x12345678) DHCPOFFER received from 192.168.100.0 (offered 192.168.100.20).
        #[2008-10-11 15:30:40+02:00] (0x12345678) DHCPREQUEST sent to 192.168.100.0.
        #[2008-10-11 15:30:41+02:00] (0x12345678) DHCPACK received: 192.168.100.20 with leasing 86400 seconds.
        #[2008-10-11 15:30:41+02:00] IP 192.168.100.20; leasetime 86400; subnet mask 255.255.255.0; router: 192.168.10.2; server hostname: zorak; primary DNS: 192.168.10.2; secondary DNS: 192.168.10.10 
        #[2008-10-11 15:32:01+02:00] SIGINT received.
        
         
        ; ifconfig
        eth1    Link encap:Ethernet  HWaddr FE:FD:00:00:01:01
                inet addr:192.168.100.20  Bcast:192.168.100.255  Mask:255.255.255.0
                UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000
                RX bytes: 0 (0 kb)  TX bytes: 0 (0 Kb)
                Interrupt:28
         lo     Link encap:Local Loopback  
                inet addr:127.0.0.1  Mask:255.255.255.0
                UP LOOPBACK RUNNING  MTU:1500  Metric:1
                RX packets:5124 errors:0 dropped:0 overruns:0 frame:0
                TX packets:5124 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0 
                RX bytes:129504 (128.8 Kb)  TX bytes:129504 (128.8 Kb)
         
    • Obtaining an IP address. In this case, an error must be shown by the standard error output, since the interface is already up:
        ; ifconfig
         eth1   Link encap:Ethernet  HWaddr FE:FD:00:00:01:01
                inet addr:192.168.100.20  Bcast:192.168.100.255  Mask:255.255.255.0
                UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                RX packets:247 errors:1 dropped:0 overruns:0 frame:0
                TX packets:446 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000
                RX bytes: 176179 (167.98 kb)  TX bytes:287587 (273.79 kb)
                Interrupt:28
         lo     Link encap:Local Loopback  
                inet addr:127.0.0.1  Mask:255.255.255.0
                UP LOOPBACK RUNNING  MTU:1500  Metric:1
                RX packets:5124 errors:0 dropped:0 overruns:0 frame:0
                TX packets:5124 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0 
                RX bytes:129504 (128.8 Kb)  TX bytes:129504 (128.8 Kb)
        ; dhcpcl eth1 -t 15 -h zorak -a 192.168.100.25
        Error: eth1 is already enabled  
          
        ; ifconfig
        eth1    Link encap:Ethernet  HWaddr FE:FD:00:00:01:01
                inet addr:192.168.100.20  Bcast:192.168.100.255  Mask:255.255.255.0
                UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000
                RX bytes: 0 (0 kb)  TX bytes: 0 (0 Kb)
                Interrupt:28
         lo     Link encap:Local Loopback  
                inet addr:127.0.0.1  Mask:255.255.255.0
                UP LOOPBACK RUNNING  MTU:1500  Metric:1
                RX packets:5124 errors:0 dropped:0 overruns:0 frame:0
                TX packets:5124 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0 
                RX bytes:129504 (128.8 Kb)  TX bytes:129504 (128.8 Kb)
        
        
    • Cancellation of the IP address. The program must also disable the interface:
        ; ifconfig
        lo      Link encap:Local Loopback
                inet addr:127.0.0.1  Mask:255.255.255.0
                UP LOOPBACK RUNNING  MTU:1500  Metric:1
                RX packets:306 errors:0 dropped:0 overruns:0 frame:0
                TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0
                RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
      
        ; dhcpcl eth1 -t 15 -h zorak -a 192.168.100.25
        #[2008-10-11 15:30:34+02:00] (0x12345678) pid = 13086.
        #[2008-10-11 15:30:39+02:00] (0x12345678) DHCPDISCOVER sent.
        #[2008-10-11 15:30:40+02:00] (0x12345678) DHCPOFFER received from 192.168.100.0 (offered 192.168.100.20).
        #[2008-10-11 15:30:40+02:00] (0x12345678) DHCPREQUEST sent to 192.168.100.0.
        #[2008-10-11 15:30:41+02:00] (0x12345678) DHCPACK received: 192.168.100.20 with leasing 86400 seconds.
        #[2008-10-11 15:30:41+02:00] IP 192.168.100.20; leasetime 86400; subnet mask 255.255.255.0; router: 192.168.10.2; server hostname: zorak; primary DNS: 192.168.10.2; secondary DNS: 192.168.10.10
      
        ; ifconfig eth1
        eth1    Link encap:Ethernet  HWaddr FE:FD:00:00:01:01
                inet addr:192.168.100.20  Bcast:192.168.100.255  Mask:255.255.255.0
                UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                RX packets:247 errors:1 dropped:0 overruns:0 frame:0
                TX packets:446 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000
                RX bytes: 176179 (167.98 kb)  TX bytes:287587 (273.79 kb)
                Interrupt:28
      
        ; kill -SIGUSR2 13086
        #[2008-10-11 15:32:01+02:00] SIGUSR2 received.
        #[2008-10-11 15:30:41+02:00] (0x12345678) DHCPRELEASE sent 192.168.100.20 released.
      
        ; ifconfig
        lo      Link encap:Local Loopback
                inet addr:127.0.0.1  Mask:255.255.255.0
                UP LOOPBACK RUNNING  MTU:1500  Metric:1
                RX packets:306 errors:0 dropped:0 overruns:0 frame:0
                TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0
                RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
        
    • Cancellation of the IP address. In this case, an error must be shown by the standard error output, as the interface is already down:
        ; ifconfig
        lo      Link encap:Local Loopback
                inet addr:127.0.0.1  Mask:255.255.255.0
                UP LOOPBACK RUNNING  MTU:1500  Metric:1
                RX packets:306 errors:0 dropped:0 overruns:0 frame:0
                TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0
                RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
      
        ; dhcpcl eth1 -t 15 -h zorak -a 192.168.100.25
        #[2008-10-11 15:30:34+02:00] (0x12345678) pid = 13086.
        #[2008-10-11 15:30:39+02:00] (0x12345678) DHCPDISCOVER sent.
        #[2008-10-11 15:30:40+02:00] (0x12345678) DHCPOFFER received from 192.168.100.0 (offered 192.168.100.20).
        #[2008-10-11 15:30:40+02:00] (0x12345678) DHCPREQUEST sent to 192.168.100.0.
        #[2008-10-11 15:30:41+02:00] (0x12345678) DHCPACK received: 192.168.100.20 with leasing 86400 seconds.
        #[2008-10-11 15:30:41+02:00] IP 192.168.100.20; leasetime 86400; subnet mask 255.255.255.0; router: 192.168.10.2; server hostname: zorak; primary DNS: 192.168.10.2; secondary DNS: 192.168.10.10
      
        ; ifconfig eth1
        eth1    Link encap:Ethernet  HWaddr FE:FD:00:00:01:01
                inet addr:192.168.100.20  Bcast:192.168.100.255  Mask:255.255.255.0
                UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                RX packets:247 errors:1 dropped:0 overruns:0 frame:0
                TX packets:446 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000
                RX bytes: 176179 (167.98 kb)  TX bytes:287587 (273.79 kb)
                Interrupt:28
      
        ; ifconfig eth1 down 
        ; ifconfig
        lo      Link encap:Local Loopback
                inet addr:127.0.0.1  Mask:255.255.255.0
                UP LOOPBACK RUNNING  MTU:1500  Metric:1
                RX packets:306 errors:0 dropped:0 overruns:0 frame:0
                TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0
                RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
      
      
        ; kill -SIGUSR2 13086
        #[2008-10-11 15:32:01+02:00] SIGUSR2 received.
        Error: eth1 is already disabled.
        
      
      

    Notes:

    • Every message must be shown by the standard output, except error messages, which must be shown by the error standard output.
    • The execution of ifconfig is informative. It is not necessary to develop this command.
    • Once the parameters from the server are received, the client will only have to configure the IP address, the subnetwork mask and the gateway (router) address. Remaining data coming from the DHCP server can be ignored by the client.


  • Traces: the program must show traces to allow execution tracking. These traces must be shown by the standard output. dhcpcl exit code must be 0 if all the parameters were successfully obtained, 1 if there was no response from the server and -1 if there is any error. Traces corresponding to the DHCP messages (DISCOVER, OFFER, REQUEST, ACK, NACK, RELEASE) must be the following:
    #[timestamp] PID = pid.
    
    #[timestamp] (xid) DHCPDISCOVER sent. 
    
    #[timestamp] (xid) DHCPOFFER received from ip_s (offered ip_c).
    
    #[timestamp] (xid) DHCPREQUEST sent to ip_s. 
    
    #[timestamp] (xid) DHCPACK received: ip_c with leasing l seconds. 
    
    #[timestamp] (xid) DHCPNACK received.
    
    #[timestamp] (xid) DHCPRELEASE sent ip_c released.
    
    #[timestamp] IP ip_c; leasetime l; subnet mask subnet_mask; router: router; server hostname: server_hostname; primary DNS: primary_DNS; secondary DNS: secondary_DNS
    
    #[timestamp] SIGINT received.
    
    #[timestamp] SIGUSR2 received.

    Where:

    • timestamp: system time, according to the format defined under RFC 3339:
    •   ; date --rfc-3339=seconds
      
        2008-10-16 10:08:02+01:00
        
    • xid: transactionID field in the DHCP datagram.
    • ip_s: DHCP server IP address.
    • ip_c: IP address leased out by the server.
    • l: leasetime announced by the server.
    • Remaining parameters are self-explanatory.

  • Simplifications to the RFC:
    • It is not necessary to implement DHCPINFORM and DHCPDECLINE messages.
    • It is not necessary any implementation related to multi-homed hosts.
    • It is not necessary to implement REBINDING and RENEWING states, nor the use of the T1 and T2 timers (see RFC's Figure 5). According to the RFC, once the client is in BOUND state, there are three timers (T1 < T2 < leasetime) that start and lead to the transition to other states and the sending of some messages.
      • If T1 expires, the client enters in RENEWING state and sends unicast DHCPREQUEST asking for a longer leasetime.
      • If T2 expires without receiving DHCPACK, the client enters in REBINDING state and sends broadcast DHCPREQUEST.
      In this assignment, when in BOUND state, the program will finish once the leasetime is over (if no DHCPRELEASE is sent before due to SIGUSR2 signal).
    • It is not necessary that the client checks whether the obtained IP address is available by means of ARP.
    • The only mandatory link level is Ethernet.
    • If the client receives more than one answer from the present servers, it has to choose one of them. How it is selected, is left to the implementors decision.
    • Everything that appears in the RFC as MAY or SHOULD is optional. Everything that appears as MUST is mandatory for the assignment.


  • Considerations about timers and timeouts: the values will always be those marked as RECOMMENDED in the RFC.


  • Considerations about sockets: it is mandatory to use UDP sockets whenever is possible (e.g. DHCPRELEASE, DHCPDECLINE). When not possible (DHCPDISCOVER, DHCPREQUEST) raw sockets will be used. In short, the client implementation must make use of both socket types.

A manual page has been created for the proposed implementation of dhcpcl, that resumes the information about input, output and traces formats. It can also be downloaded in HTML format.



 ASSESSMENT

The assessment of this practical assignment will be in-class and the mark will be pondered as the 40% of the final mark of the course. In order to be included in it, the mark of the assignment must be 5 or over. In this case, it will be also kept for the September 2009 exams and for the following year 2009/10 (but not if the assignment is passed at the September exams).

Important dates:

  • January 9th, 2008, at 23.59: End of the handing in period, through Aula Global.

  • January 16th, 2009: In-class assessment in the laboratory.


 LINKS

FAQ

RFC

  • RFC 2131 (obsoletes 1541) "Dynamic Host Configuration Protocol". R. Droms, Bucknell University, March 1997
  • RFC 2132 "DHCP Options and BOOTP Vendor Extensions". S. Alexander, R. Droms, March 1997

Books

  • W. R. Stevens: "Unix network programming".Volume 1.Networking APIs-Sockets and XTI (L/S 004.451.9 UNIX STE )

Information about sockets





start | board| contact