Skip to content
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

HLD: DHCPv4 - Specify dhcp relay's Gateway explicitly with Primary address. #1470

Merged
merged 3 commits into from
May 22, 2024

Conversation

pushpraj
Copy link
Contributor

@pushpraj pushpraj commented Sep 12, 2023

This document describes the High Level Design of 'Secondary' interfaces of vlan. These secondary interfaces are also excluded in use in dhcpv4 relay.

A vlan can have more than one subnet assigned to it. Such additional interfaces should be tagged as 'secondary'. Sonic OS should support dhcpv4 over non-secondary interfaces.

Use case: We want to increase the IP addresses range supported by a live switch. These additional IPs are to be used for new scenarios on existing physical server by additional IP addresses.

Challenge: DHCPv4 is affected when sonic switch is configured with multiple interfaces in a vlan. When a dhcpv4 packet is forwarded via dhcprelayagent, it embeds its own gateway address as 'giaddr' for return communication.
In case of multiple interfaces, dhcprelayagent randomizes giaddr among all interfaces.

This behavior is fixed by marking additional subnets as 'secondary' and explicitly specifying the primary interface as gateway for dhcpv4.

Repo PR title State
sonic-buildimage Adding new secondary field to VLAN_INTERFACE table table GitHub issue/pull request detail
sonic-utilities Add new cli to add a interface ip as secondary address GitHub issue/pull request detail
sonic-buildimage Modify dhcp relay to pick primary address GitHub issue/pull request detail
sonic-buildimage Added new test case to check docker-dhcp-relay file GitHub issue/pull request detail
sonic-mgmt Modify dhcp_relay test case GitHub issue/pull request detail

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 12, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Collaborator

@venkatmahalingam venkatmahalingam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the solution to the problem, the dhcp relay code expects just the interface and IP address but the config from SONiC conflicts.

@santoshdoke
Copy link

In case of multiple interfaces, dhcprelayagent misconfigures this giaddr to any of the interfaces.

Can you please explain more about this problem? DHCP relay is enabled on a given VLAN/Interface and the 'giaddr' is populated using the IP address assigned to that VLAN/interface. So where are the "multiple interfaces" coming from? Are you referring to a scenario whether a given VLAN/interface can have multiple IP addresses (one primary and several secondary)?

@pushpraj
Copy link
Contributor Author

In case of multiple interfaces, dhcprelayagent misconfigures this giaddr to any of the interfaces.

Can you please explain more about this problem? DHCP relay is enabled on a given VLAN/Interface and the 'giaddr' is populated using the IP address assigned to that VLAN/interface. So where are the "multiple interfaces" coming from? Are you referring to a scenario whether a given VLAN/interface can have multiple IP addresses (one primary and several secondary)?

Yes. this is the scenario where one VLAN can have multiple IP addresses. We have updated the design to mark such additional addresses as 'secondary' now.

In case of multiple interfaces, dhcprelayagent misconfigures this giaddr to any of the interfaces.

Can you please explain more about this problem? DHCP relay is enabled on a given VLAN/Interface and the 'giaddr' is populated using the IP address assigned to that VLAN/interface. So where are the "multiple interfaces" coming from? Are you referring to a scenario whether a given VLAN/interface can have multiple IP addresses (one primary and several secondary)?

Yes.

1. Support a new member 'secondary' of VLAN_INTERFACE in config_db.
2. Support parsing and assignment of subnets from minigraph/json to config_db.
3. Support specifying non-secondary interfaces' gateway address to command line arguments to /usr/sbin/dhcrelay as -g.
4. isc-dhcp/dhcrelay to support '-g gateway' argument, by porting an existing patch.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope we handle any on-the-fly primary/secondary flag changes in CONFIG_DB for VLAN interface? i.e restarting the DHCP relay to pickup right primary IP address.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhangyanzhao
Copy link
Collaborator

@pushpraj pushpraj force-pushed the dhcpv4_gateway_explicit branch from 53f77b7 to fbb584e Compare November 1, 2023 10:24
@pushpraj pushpraj changed the title HLD: DHCPv4 - Specify Gateway explicitly HLD: DHCPv4 - Specify dhcp relay's Gateway explicitly with Primary address. Nov 1, 2023
@pushpraj
Copy link
Contributor Author

@venkatmahalingam can you please review this hld, and respective PRs too? thank you.

lguohan pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Nov 22, 2023
This is change taken as part of the HLD: sonic-net/SONiC#1470 and this is a follow up on the PR #16827 where in the docker-dhcp we pick the value of primary gateway of the interface from the VLAN_Interface table which has "secondary" flag set in the config_db

Microsoft ADO (number only): 16784946

How did I do it
-  Changes in the j2 file to add a new "-pg" parameter in the dhcpv4-relay.agents.j2, the ip would be retrieved from the config db's vlan_interface table such that the interface which are picked will have secondary field set.

- Changes in isc-dhcp to re-order the addresses of the discovered interface and which has the ip which has the passed parameter.
lguohan pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Nov 22, 2023
This is change taken as part of the HLD: sonic-net/SONiC#1470.
In this PR we add the logic to parse the SecondarySubnets field in the minigraph and add a flag in "secondary" in the vlan_interface table of the config db.

Microsoft ADO (number only): 16784946

How I did it
Made changes in the minigraph.py to parse the xml entry and add the parsed value to the config db

How to verify it
Added python tests in the sonic-config-engine folder to test the config db entries.
yxieca pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Dec 4, 2023
This is change taken as part of the HLD: sonic-net/SONiC#1470 and this is a follow up on the PR #16827 where in the docker-dhcp we pick the value of primary gateway of the interface from the VLAN_Interface table which has "secondary" flag set in the config_db

Microsoft ADO (number only): 16784946

How did I do it
-  Changes in the j2 file to add a new "-pg" parameter in the dhcpv4-relay.agents.j2, the ip would be retrieved from the config db's vlan_interface table such that the interface which are picked will have secondary field set.

- Changes in isc-dhcp to re-order the addresses of the discovered interface and which has the ip which has the passed parameter.
yxieca pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Dec 4, 2023
This is change taken as part of the HLD: sonic-net/SONiC#1470.
In this PR we add the logic to parse the SecondarySubnets field in the minigraph and add a flag in "secondary" in the vlan_interface table of the config db.

Microsoft ADO (number only): 16784946

How I did it
Made changes in the minigraph.py to parse the xml entry and add the parsed value to the config db

How to verify it
Added python tests in the sonic-config-engine folder to test the config db entries.
@nmoray
Copy link

nmoray commented Jan 16, 2024

@pushpraj I tried back-porting this feature on 202111. I see that it is working. But I observed one weird behaviour.

Topology:  dhcp client <----> dhcp-relay  <-----> DHCP server (172.19.5.x)

Config:
    "VLAN_INTERFACE": {
        "Vlan2": {},
        "Vlan2|1.1.1.1/24": {
            "secondary": "true"
        },
        "Vlan2|172.19.5.1/24": {},
        "Vlan2|fd5a:200:100:5::1/64": {}
    }

Issue: During the normal scenario it works fine as expected. But after reboot of the device, dhcp-relay honours the primary address and forwards the dhcp request via the correct subnet / gateway (172.19.5.x). But when it receives the dhcp reply from the server, dhcp-relay forwards the IP back to the client via 1.1.1.x gateway (secondary) in place of 172.19.5.x.

LOGS:


root@labaz01-ra0122:/usr/local/lib/python3.9/dist-packages/show# show ip int
Interface    Master    IPv4 address/mask    Admin/Oper    BGP Neighbor    Neighbor IP
-----------  --------  -------------------  ------------  --------------  -------------
Ethernet184            172.21.237.21/31     up/up         N/A             N/A
Ethernet185            172.21.237.23/31     up/down       N/A             N/A
Ethernet224            172.21.235.139/31    up/up         N/A             N/A
Ethernet232            172.21.232.75/31     up/down       N/A             N/A
Ethernet240            172.21.229.11/31     up/up         N/A             N/A
Ethernet248            172.21.225.203/31    up/up         N/A             N/A
Loopback0              172.21.241.217/32    up/up         N/A             N/A
Vlan2                  1.1.1.1/24           up/down       N/A             N/A
                       172.19.5.1/24                      N/A             N/A

tcpdump: data link type LINUX_SLL2
tcpdump: listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
04:59:08.027050 Ethernet184 B   IP7 (invalid)
04:59:08.027050 Bridge B   IP7 (invalid)
04:59:08.027050 Vlan2 B   IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
    0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 5c:ff:35:e6:7f:7b, length 300, xid 0xa3f8df40, Flags [none] (0x0000)
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: Discover
	    Requested-IP (50), length 4: 172.19.5.104
	    Hostname (12), length 15: "labaz01-sb01221"
	    Parameter-Request (55), length 15: 
	      Subnet-Mask (1), BR (28), Time-Zone (2), Default-Gateway (3)
	      Domain-Name (15), Domain-Name-Server (6), Unknown (119), Hostname (12)
	      MTU (26), Classless-Static-Route (121), NTP (42), LOG (7)
	      Unknown (224), Unknown (225), Unknown (226)
04:59:08.034286 Ethernet248 Out IP (tos 0x0, ttl 64, id 61945, offset 0, flags [DF], proto UDP (17), length 355)
    172.21.241.217.67 > 10.119.128.139.67: [udp sum ok] BOOTP/DHCP, Request from 5c:ff:35:e6:7f:7b, length 327, hops 1, xid 0xa3f8df40, Flags [none] (0x0000)
	  Gateway-IP 172.19.5.1
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: Discover
	    Requested-IP (50), length 4: 172.19.5.104
	    Hostname (12), length 15: "labaz01-sb01221"
	    Parameter-Request (55), length 15: 
	      Subnet-Mask (1), BR (28), Time-Zone (2), Default-Gateway (3)
	      Domain-Name (15), Domain-Name-Server (6), Unknown (119), Hostname (12)
	      MTU (26), Classless-Static-Route (121), NTP (42), LOG (7)
	      Unknown (224), Unknown (225), Unknown (226)
	    Agent-Information (82), length 41: 
	      Circuit-ID SubOption 1, length 20: labaz01-ra0122:Eth24
	      Remote-ID SubOption 2, length 17: 5c:ff:35:e5:5f:05
04:59:08.052000 Ethernet248 In  IP (tos 0xe0, ttl 54, id 37789, offset 0, flags [DF], proto UDP (17), length 436)
    10.159.231.129.67 > 172.19.5.1.67: [udp sum ok] BOOTP/DHCP, Reply, length 408, hops 1, xid 0xa3f8df40, Flags [none] (0x0000)
	  Your-IP 172.19.5.104
	  Server-IP 10.177.84.55
	  Gateway-IP 172.19.5.1
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  file "undionly.kpxe"
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: Offer
	    Subnet-Mask (1), length 4: 255.255.255.0
	    Default-Gateway (3), length 4: 172.19.5.1
	    Domain-Name-Server (6), length 8: 10.5.5.5,10.5.5.6
	    Hostname (12), length 15: "labaz01-sb01221"
	    Domain-Name (15), length 12: "slc.ebay.com"
	    BR (28), length 4: 172.19.5.255
	    NTP (42), length 8: 10.5.5.123,10.5.5.124
	    Lease-Time (51), length 4: 3600
	    Server-ID (54), length 4: 10.159.231.129
	    Unknown (119), length 38: 883,27747,1125,25185,30979,25455,27904,886,26992,1125,25185,30979,25455,27904,1125,25185,30979,25455,27904
	    Agent-Information (82), length 41: 
	      Circuit-ID SubOption 1, length 20: labaz01-ra0122:Eth24
	      Remote-ID SubOption 2, length 17: 5c:ff:35:e5:5f:05
04:59:08.052174 Vlan2 Out IP (tos 0x0, ttl 64, id 57196, offset 0, flags [DF], proto UDP (17), length 393)
    1.1.1.1.67 > 255.255.255.255.68: [bad udp cksum 0x0388 -> 0x9538!] BOOTP/DHCP, Reply, length 365, hops 1, xid 0xa3f8df40, Flags [none] (0x0000)
	  Your-IP 172.19.5.104
	  Server-IP 10.177.84.55
	  Gateway-IP 172.19.5.1
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  file "undionly.kpxe"
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: Offer
	    Subnet-Mask (1), length 4: 255.255.255.0
	    Default-Gateway (3), length 4: 172.19.5.1
	    Domain-Name-Server (6), length 8: 10.5.5.5,10.5.5.6
	    Hostname (12), length 15: "labaz01-sb01221"
	    Domain-Name (15), length 12: "slc.ebay.com"
	    BR (28), length 4: 172.19.5.255
	    NTP (42), length 8: 10.5.5.123,10.5.5.124
	    Lease-Time (51), length 4: 3600
	    Server-ID (54), length 4: 10.159.231.129
	    Unknown (119), length 38: 883,27747,1125,25185,30979,25455,27904,886,26992,1125,25185,30979,25455,27904,1125,25185,30979,25455,27904
04:59:08.052181 Bridge Out IP5 (invalid)
04:59:08.052200 Ethernet184 Out IP (tos 0x0, ttl 64, id 57196, offset 0, flags [DF], proto UDP (17), length 393)
    1.1.1.1.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 365, hops 1, xid 0xa3f8df40, Flags [none] (0x0000)
	  Your-IP 172.19.5.104
	  Server-IP 10.177.84.55
	  Gateway-IP 172.19.5.1
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  file "undionly.kpxe"
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: Offer
	    Subnet-Mask (1), length 4: 255.255.255.0
	    Default-Gateway (3), length 4: 172.19.5.1
	    Domain-Name-Server (6), length 8: 10.5.5.5,10.5.5.6
	    Hostname (12), length 15: "labaz01-sb01221"
	    Domain-Name (15), length 12: "slc.ebay.com"
	    BR (28), length 4: 172.19.5.255
	    NTP (42), length 8: 10.5.5.123,10.5.5.124
	    Lease-Time (51), length 4: 3600
	    Server-ID (54), length 4: 10.159.231.129
	    Unknown (119), length 38: 883,27747,1125,25185,30979,25455,27904,886,26992,1125,25185,30979,25455,27904,1125,25185,30979,25455,27904
04:59:08.052889 Ethernet184 B   IP7 (invalid)
04:59:08.052889 Bridge B   IP7 (invalid)
04:59:08.052889 Vlan2 B   IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
    0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 5c:ff:35:e6:7f:7b, length 300, xid 0xa3f8df40, Flags [none] (0x0000)
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: Request
	    Server-ID (54), length 4: 10.159.231.129
	    Requested-IP (50), length 4: 172.19.5.104
	    Hostname (12), length 15: "labaz01-sb01221"
	    Parameter-Request (55), length 15: 
	      Subnet-Mask (1), BR (28), Time-Zone (2), Default-Gateway (3)
	      Domain-Name (15), Domain-Name-Server (6), Unknown (119), Hostname (12)
	      MTU (26), Classless-Static-Route (121), NTP (42), LOG (7)
	      Unknown (224), Unknown (225), Unknown (226)
04:59:08.059871 Ethernet248 Out IP (tos 0x0, ttl 64, id 61952, offset 0, flags [DF], proto UDP (17), length 361)
    172.21.241.217.67 > 10.119.128.139.67: [udp sum ok] BOOTP/DHCP, Request from 5c:ff:35:e6:7f:7b, length 333, hops 1, xid 0xa3f8df40, Flags [none] (0x0000)
	  Gateway-IP 172.19.5.1
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: Request
	    Server-ID (54), length 4: 10.159.231.129
	    Requested-IP (50), length 4: 172.19.5.104
	    Hostname (12), length 15: "labaz01-sb01221"
	    Parameter-Request (55), length 15: 
	      Subnet-Mask (1), BR (28), Time-Zone (2), Default-Gateway (3)
	      Domain-Name (15), Domain-Name-Server (6), Unknown (119), Hostname (12)
	      MTU (26), Classless-Static-Route (121), NTP (42), LOG (7)
	      Unknown (224), Unknown (225), Unknown (226)
	    Agent-Information (82), length 41: 
	      Circuit-ID SubOption 1, length 20: labaz01-ra0122:Eth24
	      Remote-ID SubOption 2, length 17: 5c:ff:35:e5:5f:05
04:59:08.074906 Ethernet248 In  IP (tos 0xe0, ttl 54, id 37794, offset 0, flags [DF], proto UDP (17), length 436)
    10.159.231.129.67 > 172.19.5.1.67: [udp sum ok] BOOTP/DHCP, Reply, length 408, hops 1, xid 0xa3f8df40, Flags [none] (0x0000)
	  Your-IP 172.19.5.104
	  Server-IP 10.177.84.55
	  Gateway-IP 172.19.5.1
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  file "undionly.kpxe"
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: ACK
	    Subnet-Mask (1), length 4: 255.255.255.0
	    Default-Gateway (3), length 4: 172.19.5.1
	    Domain-Name-Server (6), length 8: 10.5.5.5,10.5.5.6
	    Hostname (12), length 15: "labaz01-sb01221"
	    Domain-Name (15), length 12: "slc.ebay.com"
	    BR (28), length 4: 172.19.5.255
	    NTP (42), length 8: 10.5.5.123,10.5.5.124
	    Lease-Time (51), length 4: 3600
	    Server-ID (54), length 4: 10.159.231.129
	    Unknown (119), length 38: 883,27747,1125,25185,30979,25455,27904,886,26992,1125,25185,30979,25455,27904,1125,25185,30979,25455,27904
	    Agent-Information (82), length 41: 
	      Circuit-ID SubOption 1, length 20: labaz01-ra0122:Eth24
	      Remote-ID SubOption 2, length 17: 5c:ff:35:e5:5f:05
04:59:08.075118 Vlan2 Out IP (tos 0x0, ttl 64, id 57198, offset 0, flags [DF], proto UDP (17), length 393)
    1.1.1.1.67 > 255.255.255.255.68: [bad udp cksum 0x0388 -> 0x9238!] BOOTP/DHCP, Reply, length 365, hops 1, xid 0xa3f8df40, Flags [none] (0x0000)
	  Your-IP 172.19.5.104
	  Server-IP 10.177.84.55
	  Gateway-IP 172.19.5.1
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  file "undionly.kpxe"
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: ACK
	    Subnet-Mask (1), length 4: 255.255.255.0
	    Default-Gateway (3), length 4: 172.19.5.1
	    Domain-Name-Server (6), length 8: 10.5.5.5,10.5.5.6
	    Hostname (12), length 15: "labaz01-sb01221"
	    Domain-Name (15), length 12: "slc.ebay.com"
	    BR (28), length 4: 172.19.5.255
	    NTP (42), length 8: 10.5.5.123,10.5.5.124
	    Lease-Time (51), length 4: 3600
	    Server-ID (54), length 4: 10.159.231.129
	    Unknown (119), length 38: 883,27747,1125,25185,30979,25455,27904,886,26992,1125,25185,30979,25455,27904,1125,25185,30979,25455,27904
04:59:08.075127 Bridge Out IP5 (invalid)
04:59:08.075145 Ethernet184 Out IP (tos 0x0, ttl 64, id 57198, offset 0, flags [DF], proto UDP (17), length 393)
    1.1.1.1.67 > 255.255.255.255.68: [udp sum ok] BOOTP/DHCP, Reply, length 365, hops 1, xid 0xa3f8df40, Flags [none] (0x0000)
	  Your-IP 172.19.5.104
	  Server-IP 10.177.84.55
	  Gateway-IP 172.19.5.1
	  Client-Ethernet-Address 5c:ff:35:e6:7f:7b
	  file "undionly.kpxe"
	  Vendor-rfc1048 Extensions
	    Magic Cookie 0x63825363
	    DHCP-Message (53), length 1: ACK
	    Subnet-Mask (1), length 4: 255.255.255.0
	    Default-Gateway (3), length 4: 172.19.5.1
	    Domain-Name-Server (6), length 8: 10.5.5.5,10.5.5.6
	    Hostname (12), length 15: "labaz01-sb01221"
	    Domain-Name (15), length 12: "slc.ebay.com"
	    BR (28), length 4: 172.19.5.255
	    NTP (42), length 8: 10.5.5.123,10.5.5.124
	    Lease-Time (51), length 4: 3600
	    Server-ID (54), length 4: 10.159.231.129
	    Unknown (119), length 38: 

Are you also seeing similar behaviour?

@zhangyanzhao
Copy link
Collaborator

@prsunny @venkatmahalingam can you please help to approve this PR if you are ok? Thanks.

@gord1306
Copy link

gord1306 commented Apr 3, 2024

@pushpraj I am wondering if it's possible to specify an IP address as the primary address for the DHCP relay service. In the current design, the 'secondary' parameter's meaning is applied under the interface, encompassing the entire interface view. However, this feature is intended only for the DHCP relay, not for the entire interface

@zhangyanzhao
Copy link
Collaborator

@prsunny @venkatmahalingam are you ok to merge this PR? Thanks.

@prsunny
Copy link
Contributor

prsunny commented Apr 29, 2024

yes @zhangyanzhao , we can merge this PR

@prsunny prsunny merged commit e14b245 into sonic-net:master May 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants