Skip to content

Refactor DHCP implementation to comply with RFC 2131#57

Merged
grossmj merged 1 commit intoGNS3:masterfrom
acd407:master
Nov 23, 2025
Merged

Refactor DHCP implementation to comply with RFC 2131#57
grossmj merged 1 commit intoGNS3:masterfrom
acd407:master

Conversation

@acd407
Copy link
Copy Markdown
Contributor

@acd407 acd407 commented Nov 22, 2025

This commit refactors the DHCP functionality in VPCS to better align with RFC 2131 specifications:

  1. Renamed the boolean 'renew' parameter to enum 'stage' in dhcp4_request() to properly distinguish between DHCP phases:

    • stage = 0: Initial DHCP request (INIT)
    • stage = 1: Renewing request (RENEWING)
    • stage = 2: Rebinding request (REBINDING)
  2. Corrected IP address handling for each phase:

    • INIT phase (stage = 0): Source IP set to 0.0.0.0
    • RENEWING phase (stage = 1): Source IP set to client's current IP
    • REBINDING phase (stage = 2): Source IP set to client's current IP
  3. Updated all dhcp4_request() calls to pass appropriate stage values:

    • run_dhcp_new() selects stage based on user input
    • dhcp_renew() passes stage = 1
    • dhcp_rebind() passes stage = 2
  4. Maintained backward compatibility by keeping the 'renew' parameter in dhcp4_discover()

  5. Improved code documentation and removed redundant comments

These changes ensure proper DHCP behavior according to RFC 2131 while maintaining compatibility with existing code.

This commit refactors the DHCP functionality in VPCS to better align
with RFC 2131 specifications:

1. Renamed the boolean 'renew' parameter to enum 'stage' in
dhcp4_request() to properly distinguish between DHCP phases:
   - stage = 0: Initial DHCP request (INIT)
   - stage = 1: Renewing request (RENEWING)
   - stage = 2: Rebinding request (REBINDING)

2. Corrected IP address handling for each phase:
   - INIT phase (stage = 0): Source IP set to 0.0.0.0
   - RENEWING phase (stage = 1): Source IP set to client's current IP
   - REBINDING phase (stage = 2): Source IP set to client's current IP

3. Updated all dhcp4_request() calls to pass appropriate stage values:
   - run_dhcp_new() selects stage based on user input
   - dhcp_renew() passes stage = 1
   - dhcp_rebind() passes stage = 2

4. Maintained backward compatibility by keeping the 'renew' parameter in
dhcp4_discover()

5. Improved code documentation and removed redundant comments

These changes ensure proper DHCP behavior according to RFC 2131 while
maintaining compatibility with existing code.
@acd407
Copy link
Copy Markdown
Contributor Author

acd407 commented Nov 22, 2025

Before this commit, systemd-resolved did not accept DHCP requests from VPCS, like this:

PC1> dhcp -d
Opcode: 1 (REQUEST)
Client IP Address: 0.0.0.0
Your IP Address: 0.0.0.0
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Discover
Option 12: Host Name = PC1
Option 61: Client Identifier = Hardware Type=Ethernet MAC Address = 00:50:79:66:68:00

Opcode: 2 (REPLY)
Client IP Address: 0.0.0.0
Your IP Address: 192.168.16.64
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Offer
Option 51: Lease Time = 3600
Option 1: Subnet Mask = 255.255.255.0
Option 3: Router = 192.168.16.1
Option 6: DNS Server = 192.168.16.1 
Option 54: DHCP Server = 192.168.16.1

Opcode: 1 (REQUEST)
Client IP Address: 192.168.16.64
Your IP Address: 0.0.0.0
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Request
Option 54: DHCP Server = 192.168.16.1
Option 50: Requested IP Address = 192.168.16.64
Option 61: Client Identifier = Hardware Type=Ethernet MAC Address = 00:50:79:66:68:00
Option 12: Host Name = PC1

Opcode: 1 (REQUEST)
Client IP Address: 192.168.16.64
Your IP Address: 0.0.0.0
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Request
Option 54: DHCP Server = 192.168.16.1
Option 50: Requested IP Address = 192.168.16.64
Option 61: Client Identifier = Hardware Type=Ethernet MAC Address = 00:50:79:66:68:00
Option 12: Host Name = PC1

Opcode: 1 (REQUEST)
Client IP Address: 192.168.16.64
Your IP Address: 0.0.0.0
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Request
Option 54: DHCP Server = 192.168.16.1
Option 50: Requested IP Address = 192.168.16.64
Option 61: Client Identifier = Hardware Type=Ethernet MAC Address = 00:50:79:66:68:00
Option 12: Host Name = PC1


Can't get ip address from dhcp server

After this commit, DHCP can proceed normally:

PC1> dhcp -d
Opcode: 1 (REQUEST)
Client IP Address: 0.0.0.0
Your IP Address: 0.0.0.0
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Discover
Option 12: Host Name = PC1
Option 61: Client Identifier = Hardware Type=Ethernet MAC Address = 00:50:79:66:68:00

Opcode: 2 (REPLY)
Client IP Address: 0.0.0.0
Your IP Address: 192.168.16.64
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Offer
Option 51: Lease Time = 3600
Option 1: Subnet Mask = 255.255.255.0
Option 3: Router = 192.168.16.1
Option 6: DNS Server = 192.168.16.1 
Option 54: DHCP Server = 192.168.16.1

Opcode: 1 (REQUEST)
Client IP Address: 0.0.0.0
Your IP Address: 0.0.0.0
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Request
Option 54: DHCP Server = 192.168.16.1
Option 50: Requested IP Address = 192.168.16.64
Option 61: Client Identifier = Hardware Type=Ethernet MAC Address = 00:50:79:66:68:00
Option 12: Host Name = PC1

Opcode: 2 (REPLY)
Client IP Address: 0.0.0.0
Your IP Address: 192.168.16.64
Server IP Address: 0.0.0.0
Gateway IP Address: 0.0.0.0
Client MAC Address: 00:50:79:66:68:00
Option 53: Message Type = Ack
Option 51: Lease Time = 3600
Option 1: Subnet Mask = 255.255.255.0
Option 3: Router = 192.168.16.1
Option 6: DNS Server = 192.168.16.1 
Option 54: DHCP Server = 192.168.16.1

 IP 192.168.16.64/24 GW 192.168.16.1

@grossmj grossmj merged commit fd92890 into GNS3:master Nov 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants