Project-DHCPClient

advertisement
PROJECT
Study and Implementation of
“DHCP Client” as per RFC-2131
By
Manikanta Velaga
Senior Software Engineer
Sasken Communications Technologies
PART – A
Broad Subject:
Computer Networks
Area of Specialization:
Host Configuration
Expected Duration:
Principal Developer
i. Name:
Mr. Manikanta Velaga
iii. Sex:
Male
iii. Date of Birth:
05 -06-1982
iv. Qualification:
B.TECH, M.TECH
v. Designation:
Senior Software Engineer,
Sasken Communication Technologies,
Hyderabad, India
vi. Address (Office):
vii. Address (Residence):
Flat No: G-102,
Sai Krupa Lakshmi Nilaya,
Icrisat Colony, Chanda Nagar,
Hyderabad-500050, Andhra Pradesh,
India.
5. Co – Developer(s):
No
PART – B
Project Title: Study and Implementation of “DHCP Client”
Study Phase:
Every computer that uses the TCP/IP protocol suite needs to know the following things for
communication with computers of other networks.
 IP Address of the computer
 Subnet mask of the computer
 IP Address of the Router/Gateway
 IP Address of the name server [DNS Server]
DHCP is the formal protocol for host configuration, before that some other protocols were
used for this particular purpose, those are RARP and BOOTP.
RARP: It is used to translate a physical address to IP address. By using this protocol a
physical machine in a LAN can send a request to learn its IP address from the Gateway’s
ARP table or cache. A network administrator manually creates a table in a LAN’s
Gateway/Router that maps the physical addresses to corresponding IP addresses. When a
machine is booting, its RARP client sends a request for IP address to RARP server on the
gateway or router. If the entry has already been setup in the gateway’s table, RARP server of
gateway will return the machine’s IP address.
The main disadvantages of this protocol are RARP server must be present in each
network, and it can provide only IP addresses, not any other information like the IP address
of the gateway and IP address of the DNS server.
BOOTP: To overcome the deficiencies of the RARP protocol, BOOTP protocol has been
designed for host configuration. BOOTP server can be run anywhere in the internet, and it
also provides other information along with IP address. However it is a static configuration
protocol. When a client requests its IP address, the BOOTP server searches for an entry that
matches the physical address of the client, and it returns the corresponding IP address.
The binding/mapping between the physical address and the IP address of the client already
exists.
There are some situations, in which a host wants a temporary IP address to be used for
some time; BOOTP cannot handle such type of situations as because the mapping between
the physical address and IP address is already exists, these mappings are static and fixed, and
they can’t be changed dynamically until changed by the admin. As BOOTP is a static
configuration protocol, it can’t handle dynamic situations. DHCP has been introduced to
handle all such dynamic situations.
DHCP:
It is a client server protocol designed to provide IP address and necessary information to a
host for communicating with other network.
DHCP operation:
DHCP client sends a request to DHCP server while host’s booting process, when a DHCP
server receives a request from a client; it selects an IP address from a pool of addresses
present in its database and offers it to client. If client accepts the offer, that IP address is
given to client for a period of time.
Different scenarios/situations:
There are two scenarios, one is DHCP operation when DHCP server is on another network
and other one is DHCP operation when DHCP server is in the same network. When DHCP
server is present in the same network, DHCP DISCOVERY packet reaches the server, but
when the server is running in other network router/gateway does not allow broadcast packets
to other network, router discards such packets. So, DHCP relay agent has been introduced to
in between the client and server where the server is running on other network. DHCP relay
agent can be configured on any host of the same network or on the router. All the messages
would get exchanged between client and server via relay agent.
DHCP Message sequence in different scenarios:
During the process of acquiring IP address and other configuration information, some
sequence of messages would get exchanged between DHCP client and DHCP server.
Scenario 1:
A machine is booting first time, and it is initializing a DHCP client program while
booting. Two DHCP servers are running, one is running in the same subnetwork and another
server is running in different subnetwork and a DHCP relay agent is running in the router.
DHCP Relay agent is
running on router.
D
H
C
P
C
L
I
E
N
T
DHCP DISCOVER-->
DHCP DISCOVER -->
D
100
H
<--DHCP OFFER
C
P
200
DHCP DISCOVER-->
200
<--DHCP OFFER
D
H
C
P
<-DHCP OFFER
100
DHCP REQUEST-->
100
DHCP REQUEST-->
100
<--DHCP ACK
T1 is expired.
100
DHCP REQUEST-->
T2 is expired.
100
S
E
R
V
E
R
1
DHCP REQUEST-->
DHCP REQUEST-->
100
R
O
U
T
E
R
100
DHCP REQUEST-->
S
E
R
V
E
R
2
100
DHCP REQUEST-->
100
<--DHCP ACK
After initialization of the DHCP client, client would send a DHCP DISCOVER message as
broadcast message in its sub network to discover the server. This broadcast message reaches
Server1 and relay agent. Relay agent forwards this message to Server2.
DHCP Server1 blocks an IP address “100” from its pool of addresses and offers to client
machine. DHCP Server2 blocks an IP address “200” from its pool of addresses and offers to
client machine. DHCP client received offers “100” and “200” as IP addresses from the
servers, it selects one of the IP addresses. In this case it is selected 100 as IP address and
stored in client IP address field sends DHCPREQUEST message as broadcast message.
DHCP Server2 sees that the client has sent a DHCP Request but it has not selected the IP
address which it had offered, so the IP address 200 is returned to the free pool. DHCP
Server1 allocates IP address 100 and records this binding on the disk along with the lease
time. A timer is started for the duration of the lease for the IP address. DHCP Server1
responds by a unicast, this requires that ARP cache is updated with the hardware address for
the device.
After DHCP ACK is received, the client validates the information provided by the
DHCP Server1. Client sends an ARP request for the assigned IP address, if no machine
responds to the ARP request then it can sure that provided IP address is unique IP address.
Scenario 2:
Scenario 3:
Scenario 4:
DHCP Packet format:
During this entire operation of the DHCP protocol, same format should be followed to
exchange the packets/messages between client and server.
DHCP Packet format
Operation code | Hardware type| Hardware length| Hop count
Transaction ID
Number of seconds
| Flags
Client IP Address
Your IP Address
Server IP Address
Gateway IP Address
Client Hardware Address
Server name
Boot file name
Options
…..
…..
…..
…..
Operation code:
This 8-bit field defines the type of DHCP packet either it is request packet or reply packet.
For request packet its value would be 1 and for reply packet its value would be 2.
Hardware type:
This is an 8-bit field defines the type of physical network. One integer has been assigned for
each type of network. For Ethernet its value would be 1, as of now we are working on
Ethernet only.
Hardware length:
This is an 8-bit field defines the length of the physical address in bytes. For Ethernet it would
be 6.
Hop count:
This is an 8-bit field defines the maximum number of hops the packet can travel.
Transaction ID:
This is a 32-bit field stores an integer. This transaction id is set by the client and is used to
match the server’s reply with the request. The server returns the same value in its reply.
Number of seconds:
This is a 16-bit field stores the number of seconds elapsed/completed since the time the client
started to boot.
Flags:
This is a 16-bit field in which only the leftmost bit is used and the rest of the bits should be 0.
The left most bit specifies a forced broadcast reply from the server.
Clients IP address:
This is a 4 byte field that contains the client IP address. If the client does not have this
information, this field has a value of 0.
Your IP address:
This is a 4 byte field that contains the client IP address; it is filled by the server (in reply
message).
Server IP address:
This is a 4 byte field that contains the server IP address. It is filled by the server in a reply
message.
Gateway IP address:
This is a 4 byte field that contains the IP address of the router. It is filled by the server in a
reply message.
Client Hardware Address:
This is 16 byte field that contains the Physical address of the client. It is explicitly supplied
by the client in the request message.
Server name:
This is a 64 byte field that is optionally filled by the server in a reply packet. It contains a
null-terminated string consisting of the domain name of the server. If the server does not want
to fill this field with data, the server must fill it with all 0s.
Boot file name:
This is 128 byte field that can be optionally filled by the server in a reply packet. It contains a
null-terminated string consisting of the full pathname of the boot file. The client can use this
path to retrieve other booting information. If the server does not want to fill this field with
data, the server must fill it with all 0s.
Options:
Content of the DHCPDISCOVER message
Field Name
Length
Operation Code
Hardware Type
Hardware Length
Hop Count
Transaction ID
1 Byte
1 Byte
1 Byte
1 Byte
4 Bytes
Number of Seconds
Flags
Client IP Address
Your IP Address
Server IP Address
Gateway IP Address
Client Hardware
Address
Server Name
Boot File Name
MagicCookie
Tag
Length
DHCPMessageType
Tag
Length
Parameter Request List
2 Bytes
2 Bytes
4 Bytes
4 Bytes
4 Bytes
4 Bytes
16 Bytes
EndOfList
Value
Comments
1
1
6
0
To be generated randomly and
filled.
0 /*To be find out and filled*/
0 /*Left most bit should be 1*/
0
0
0
0
To be find out and filled
Mandatory
Mandatory
Mandatory
Mandatory
Mandatory
64 Bytes
128 Bytes
4 Bytes
1 Byte
1 Byte
1 Byte
1 Byte
1 Byte
4 Byte
0
0
99.130.83.99
53
1
1
55
4
01,28,03,15[0x01, 0x1C, 0x03,
0x0F]
Mandatory
Mandatory
Mandatory
1 Byte
255
Mandatory
Mandatory
Mandatory
Mandatory
Mandatory
Mandatory
Mandatory
Optional
Optional
Contents of a DHCPREQUEST message
Operation Code
Hardware Type
Hardware Length
Hop Count
Transaction ID
Number of Seconds
Flags
Client IP Address
Your IP Address
Server IP Address
Gateway IP Address
Client Hardware Address
Server Name
Boot File Name
Options
Contents of a DHCPOFFER message
Operation Code
Hardware Type
Hardware Length
Hop Count
Transaction ID
Number of Seconds
Flags
Client IP Address
Your IP Address
Server IP Address
Gateway IP Address
Client Hardware Address
Server Name
Boot File Name
Options
Contents of a DHCPACK message
Operation Code
Hardware Type
Hardware Length
Hop Count
Transaction ID
Number of Seconds
Flags
Client IP Address
Your IP Address
Server IP Address
Gateway IP Address
Client Hardware Address
Server Name
Boot File Name
Options
DHCP Client:
DHCP Client transition/state diagram:
Machine is booting
DHCP Client starts
INIT
Broadcasted
DHCPDISCOVER msg
SELECTING
Received offers and broadcasted
DHCPREQUEST msg
REQUESTING
Received DHCPACK and
started T1 and T2 timers
Received DHCPNACK
BOUND
T1 timer got expired and unicasted
DHCPREQUEST msg
RENEWING
Received DHCPACK
Not received DHCPACK
before T2 timer got expired
REBINDING
Software Design Details/Diagrams:
Testing Details:
Wireshark Diagrams should be included.
Result/Conclusion:
Download