Skip to contentSkip to conversation

dhcpv6: support rapid commit dhcp6 option

PATCH Superseded Yuxiao Zhang 2 participants 3 messages Aug 19 – Aug 25 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dhcpv6: support rapid commit dhcp6 option

Support rapid commit option code 14 which bypass the advertise and request state. The option is enabled by DHCP6_RAPID_COMMIT.

---

 cmd/Kconfig  |  8 ++++++++
 net/dhcpv6.c | 39 ++++++++++++++++++++++++++++++++-------
 net/dhcpv6.h |  2 ++
 3 files changed, 42 insertions(+), 7 deletions(-)
cmd/Kconfig +8 -0
index ff90a87024c..b3cf3a6d8b6 100644
@@ -1996,6 +1996,14 @@ config DHCP6_ENTERPRISE_ID
 	int "Enterprise ID to send in DHCPv6 Vendor Class Option"
 	default 0
 
+config DHCP6_RAPID_COMMIT
+	bool "Request Rapid Commit (2-message exchange) from DHCPv6 server"
+	default n
+	help
+	  Request the Rapid Commit option (option 14) in DHCPv6 Solicit
+	  messages to enable a 2-message exchange (Solicit-Reply) rather
+	  than the default 4-message exchange.
+
 endif
 
 config BOOTP_MAY_FAIL
net/dhcpv6.c +32 -7
index 640f089a2e1..1e51e6de256 100644
@@ -115,6 +115,9 @@ static int dhcp6_add_option(int option_id, uchar *pkt)
 
 		opt_len = sizeof(struct dhcp6_option_ia_na);
 		break;
+	case DHCP6_OPTION_RAPID_COMMIT:
+		opt_len = 0;
+		break;
 	case DHCP6_OPTION_ORO:
 		oro_opt = (struct dhcp6_option_oro *)dhcp_option_start;
 		oro_opt->req_option_code[num_oro++] = htons(DHCP6_OPTION_OPT_BOOTFILE_URL);
@@ -194,6 +197,8 @@ static void dhcp6_send_solicit_packet(void)
 	pkt += dhcp6_add_option(DHCP6_OPTION_ELAPSED_TIME, pkt);
 	pkt += dhcp6_add_option(DHCP6_OPTION_IA_NA, pkt);
 	pkt += dhcp6_add_option(DHCP6_OPTION_ORO, pkt);
+	if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT))
+		pkt += dhcp6_add_option(DHCP6_OPTION_RAPID_COMMIT, pkt);
 	if (CONFIG_DHCP_PXE_CLIENTARCH != 0xFF)
 		pkt += dhcp6_add_option(DHCP6_OPTION_CLIENT_ARCH_TYPE, pkt);
 	pkt += dhcp6_add_option(DHCP6_OPTION_VENDOR_CLASS, pkt);
@@ -448,6 +453,12 @@ static void dhcp6_parse_options(uchar *rx_pkt, unsigned int len)
 			}
 			sm_params.rx_status.preference = *option_ptr;
 			break;
+		case DHCP6_OPTION_RAPID_COMMIT:
+			if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT)) {
+				debug("DHCP6_OPTION_RAPID_COMMIT FOUND\n");
+				sm_params.rx_status.rapid_commit_found = true;
+			}
+			break;
 		default:
 			debug("Unknown Option ID: %d, skipping parsing\n",
 			      ntohs(option_hdr->option_id));
@@ -618,14 +629,28 @@ static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)
 		break;
 	case DHCP6_SOLICIT:
 		if (!timeout) {
-			/* check the rx packet and determine if we can transition to next
-			 * state.
-			 */
-			if (dhcp6_check_advertise_packet(rx_pkt, len))
-				return;
+			struct dhcp6_hdr *dhcp6_hdr = (struct dhcp6_hdr *)rx_pkt;
+
+			if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT) &&
+			    dhcp6_hdr && dhcp6_hdr->msg_type == DHCP6_MSG_REPLY) {
+				if (dhcp6_check_reply_packet(rx_pkt, len))
+					return;
+				if (!sm_params.rx_status.rapid_commit_found) {
+					debug("[DHCPv6] REPLY received without Rapid Commit option, ignoring\n");
+					return;
+				}
+				debug("REPLY (Rapid Commit) good, transition to DONE\n");
+				sm_params.next_state = DHCP6_DONE;
+			} else {
+				/* check the rx packet and determine if we can transition to next
+				 * state.
+				 */
+				if (dhcp6_check_advertise_packet(rx_pkt, len))
+					return;
 
-			debug("ADVERTISE good, transition to REQUEST\n");
-			sm_params.next_state = DHCP6_REQUEST;
+				debug("ADVERTISE good, transition to REQUEST\n");
+				sm_params.next_state = DHCP6_REQUEST;
+			}
 		} else if (sm_params.retry_cnt == 1)  {
 			/* If a server UID was received in the first SOLICIT period
 			 * transition to REQUEST
net/dhcpv6.h +2 -0
index d41a3c30615..49f20390730 100644
@@ -24,6 +24,7 @@
 #define DHCP6_OPTION_PREFERENCE		7
 #define DHCP6_OPTION_ELAPSED_TIME	8
 #define DHCP6_OPTION_STATUS_CODE	13
+#define DHCP6_OPTION_RAPID_COMMIT	14
 #define DHCP6_OPTION_OPT_BOOTFILE_URL	59
 #define DHCP6_OPTION_OPT_BOOTFILE_PARAM	60
 #define DHCP6_OPTION_SOL_MAX_RT		82
@@ -152,6 +153,7 @@ struct dhcp6_rx_pkt_status {
 	enum dhcp6_status	ia_status_code;
 	enum dhcp6_status	status_code;
 	u8			preference;
+	bool			rapid_commit_found;
 };
 
 /**

---
base-commit: 527115ef6783cec49e5610c523c124b399011361
branch: main

Signature · 1 line
2.55.0.737.g08866a6d13-goog
#1 lore raw

Hi Yuxiao,

Two minor comments below. Thanks!

Quoted 54 lines · Yuxiao Zhang

Support rapid commit option code 14 which bypass the advertise and request state. The option is enabled by DHCP6_RAPID_COMMIT.

---

 cmd/Kconfig  |  8 ++++++++
 net/dhcpv6.c | 39 ++++++++++++++++++++++++++++++++-------
 net/dhcpv6.h |  2 ++
 3 files changed, 42 insertions(+), 7 deletions(-)
cmd/Kconfig +8 -0
index ff90a87024c..b3cf3a6d8b6 100644
@@ -1996,6 +1996,14 @@ config DHCP6_ENTERPRISE_ID
 	int "Enterprise ID to send in DHCPv6 Vendor Class Option"
 	default 0
 
+config DHCP6_RAPID_COMMIT
+	bool "Request Rapid Commit (2-message exchange) from DHCPv6 server"
+	default n
+	help
+	  Request the Rapid Commit option (option 14) in DHCPv6 Solicit
+	  messages to enable a 2-message exchange (Solicit-Reply) rather
+	  than the default 4-message exchange.
+
 endif
 
 config BOOTP_MAY_FAIL
net/dhcpv6.c +5 -0
index 640f089a2e1..1e51e6de256 100644
@@ -115,6 +115,9 @@ static int dhcp6_add_option(int option_id, uchar *pkt)
 
 		opt_len = sizeof(struct dhcp6_option_ia_na);
 		break;
+	case DHCP6_OPTION_RAPID_COMMIT:
+		opt_len = 0;
+		break;
 	case DHCP6_OPTION_ORO:
 		oro_opt = (struct dhcp6_option_oro *)dhcp_option_start;
 		oro_opt->req_option_code[num_oro++] = htons(DHCP6_OPTION_OPT_BOOTFILE_URL);
@@ -194,6 +197,8 @@ static void dhcp6_send_solicit_packet(void)
 	pkt += dhcp6_add_option(DHCP6_OPTION_ELAPSED_TIME, pkt);
 	pkt += dhcp6_add_option(DHCP6_OPTION_IA_NA, pkt);
 	pkt += dhcp6_add_option(DHCP6_OPTION_ORO, pkt);
+	if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT))
+		pkt += dhcp6_add_option(DHCP6_OPTION_RAPID_COMMIT, pkt);
 	if (CONFIG_DHCP_PXE_CLIENTARCH != 0xFF)
 		pkt += dhcp6_add_option(DHCP6_OPTION_CLIENT_ARCH_TYPE, pkt);
 	pkt += dhcp6_add_option(DHCP6_OPTION_VENDOR_CLASS, pkt);

net/dhcpv6.c static void dhcp6_parse_options(uchar *rx_pkt, unsigned int len) · line 457

Quoted 5 lines
net/dhcpv6.c +2 -0
@@ -448,6 +453,12 @@ static void dhcp6_parse_options(uchar *rx_pkt, unsigned int len)
 			}
 			sm_params.rx_status.preference = *option_ptr;
 			break;
+		case DHCP6_OPTION_RAPID_COMMIT:
+			if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT)) {

option_len != 0 should probably be rejected here

Quoted 10 lines
net/dhcpv6.c +4 -0
+				debug("DHCP6_OPTION_RAPID_COMMIT FOUND\n");
+				sm_params.rx_status.rapid_commit_found = true;
+			}
+			break;
 		default:
 			debug("Unknown Option ID: %d, skipping parsing\n",
 			      ntohs(option_hdr->option_id));
@@ -618,14 +629,28 @@ static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)
 		break;
 	case DHCP6_SOLICIT:

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len) · line 635

Quoted 10 lines
net/dhcpv6.c +4 -5
 		if (!timeout) {
-			/* check the rx packet and determine if we can transition to next
-			 * state.
-			 */
-			if (dhcp6_check_advertise_packet(rx_pkt, len))
-				return;
+			struct dhcp6_hdr *dhcp6_hdr = (struct dhcp6_hdr *)rx_pkt;
+
+			if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT) &&
+			    dhcp6_hdr && dhcp6_hdr->msg_type == DHCP6_MSG_REPLY) {

dhcp6_hdr is necessarily non-NULL here, so please drop "dhcp6_hdr &&"

Quoted 47 lines
net/dhcpv6.c +17 -2
+				if (dhcp6_check_reply_packet(rx_pkt, len))
+					return;
+				if (!sm_params.rx_status.rapid_commit_found) {
+					debug("[DHCPv6] REPLY received without Rapid Commit option, ignoring\n");
+					return;
+				}
+				debug("REPLY (Rapid Commit) good, transition to DONE\n");
+				sm_params.next_state = DHCP6_DONE;
+			} else {
+				/* check the rx packet and determine if we can transition to next
+				 * state.
+				 */
+				if (dhcp6_check_advertise_packet(rx_pkt, len))
+					return;
 
-			debug("ADVERTISE good, transition to REQUEST\n");
-			sm_params.next_state = DHCP6_REQUEST;
+				debug("ADVERTISE good, transition to REQUEST\n");
+				sm_params.next_state = DHCP6_REQUEST;
+			}
 		} else if (sm_params.retry_cnt == 1)  {
 			/* If a server UID was received in the first SOLICIT period
 			 * transition to REQUEST
net/dhcpv6.h +2 -1
index d41a3c30615..49f20390730 100644
@@ -24,6 +24,7 @@
 #define DHCP6_OPTION_PREFERENCE		7
 #define DHCP6_OPTION_ELAPSED_TIME	8
 #define DHCP6_OPTION_STATUS_CODE	13
+#define DHCP6_OPTION_RAPID_COMMIT	14
 #define DHCP6_OPTION_OPT_BOOTFILE_URL	59
 #define DHCP6_OPTION_OPT_BOOTFILE_PARAM	60
 #define DHCP6_OPTION_SOL_MAX_RT		82
@@ -152,6 +153,7 @@ struct dhcp6_rx_pkt_status {
 	enum dhcp6_status	ia_status_code;
 	enum dhcp6_status	status_code;
 	u8			preference;
+	bool			rapid_commit_found;
 };
 
 /**
---

base-commit: 527115ef6783cec49e5610c523c124b399011361
branch: main

Signature · 1 line
Jerome
#2 lore raw

Thank you for the reviewing. Addressed the comments in patch V2.

Thanks,
-Yuxiao

Quoted 157 lines · Jerome Forissier

Hi Yuxiao,

Two minor comments below. Thanks!

net/dhcpv6.c static int dhcp6_add_option(int option_id, uchar

Quoted 35 lines · Yuxiao Zhang

Support rapid commit option code 14 which bypass the advertise and request state. The option is enabled by DHCP6_RAPID_COMMIT.

---

 cmd/Kconfig  |  8 ++++++++
 net/dhcpv6.c | 39 ++++++++++++++++++++++++++++++++-------
 net/dhcpv6.h |  2 ++
 3 files changed, 42 insertions(+), 7 deletions(-)
cmd/Kconfig +8 -0
index ff90a87024c..b3cf3a6d8b6 100644
@@ -1996,6 +1996,14 @@ config DHCP6_ENTERPRISE_ID
      int "Enterprise ID to send in DHCPv6 Vendor Class Option"
      default 0
 
+config DHCP6_RAPID_COMMIT
+     bool "Request Rapid Commit (2-message exchange) from DHCPv6 server"
+     default n
+     help
+       Request the Rapid Commit option (option 14) in DHCPv6 Solicit
+       messages to enable a 2-message exchange (Solicit-Reply) rather
+       than the default 4-message exchange.
+
 endif
 
 config BOOTP_MAY_FAIL
net/dhcpv6.c +0 -0
index 640f089a2e1..1e51e6de256 100644
@@ -115,6 +115,9 @@ static int dhcp6_add_option(int option_id, uchar

*pkt)

net/dhcpv6.c static int dhcp6_add_option(int option_id, uchar *pkt)

Quoted 9 lines
net/dhcpv6.c +3 -0
              opt_len = sizeof(struct dhcp6_option_ia_na);
              break;
+     case DHCP6_OPTION_RAPID_COMMIT:
+             opt_len = 0;
+             break;
      case DHCP6_OPTION_ORO:
              oro_opt = (struct dhcp6_option_oro *)dhcp_option_start;
              oro_opt->req_option_code[num_oro++] =

htons(DHCP6_OPTION_OPT_BOOTFILE_URL);

net/dhcpv6.c static void dhcp6_send_solicit_packet(void) · line 203

Quoted 8 lines
net/dhcpv6.c +2 -0
@@ -194,6 +197,8 @@ static void dhcp6_send_solicit_packet(void)
      pkt += dhcp6_add_option(DHCP6_OPTION_ELAPSED_TIME, pkt);
      pkt += dhcp6_add_option(DHCP6_OPTION_IA_NA, pkt);
      pkt += dhcp6_add_option(DHCP6_OPTION_ORO, pkt);
+     if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT))
+             pkt += dhcp6_add_option(DHCP6_OPTION_RAPID_COMMIT, pkt);
      if (CONFIG_DHCP_PXE_CLIENTARCH != 0xFF)
              pkt += dhcp6_add_option(DHCP6_OPTION_CLIENT_ARCH_TYPE,

pkt);

net/dhcpv6.c static void dhcp6_parse_options(uchar *rx_pkt,

Quoted 2 lines
net/dhcpv6.c +0 -0
      pkt += dhcp6_add_option(DHCP6_OPTION_VENDOR_CLASS, pkt);
@@ -448,6 +453,12 @@ static void dhcp6_parse_options(uchar *rx_pkt,

unsigned int len)

net/dhcpv6.c static void dhcp6_parse_options(uchar *rx_pkt, unsigned int len) · line 457

Quoted 5 lines
net/dhcpv6.c +2 -0
                      }
                      sm_params.rx_status.preference = *option_ptr;
                      break;
+             case DHCP6_OPTION_RAPID_COMMIT:
+                     if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT)) {

option_len != 0 should probably be rejected here

net/dhcpv6.c static void dhcp6_parse_options(uchar *rx_pkt, · line 459

Quoted 2 lines
net/dhcpv6.c +2 -0
+                             debug("DHCP6_OPTION_RAPID_COMMIT FOUND\n");
+                             sm_params.rx_status.rapid_commit_found =

true;

net/dhcpv6.c static void dhcp6_state_machine(bool timeout,

Quoted 6 lines
net/dhcpv6.c +2 -0
+                     }
+                     break;
              default:
                      debug("Unknown Option ID: %d, skipping parsing\n",
                            ntohs(option_hdr->option_id));
@@ -618,14 +629,28 @@ static void dhcp6_state_machine(bool timeout,

uchar *rx_pkt, unsigned int len)

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 4 lines
net/dhcpv6.c +0 -1
              break;
      case DHCP6_SOLICIT:
              if (!timeout) {
-                     /* check the rx packet and determine if we can

transition to next

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 5 lines
net/dhcpv6.c +1 -4
-                      * state.
-                      */
-                     if (dhcp6_check_advertise_packet(rx_pkt, len))
-                             return;
+                     struct dhcp6_hdr *dhcp6_hdr = (struct dhcp6_hdr

*)rx_pkt;

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 3 lines
net/dhcpv6.c +3 -0
+
+                     if (IS_ENABLED(CONFIG_DHCP6_RAPID_COMMIT) &&
+                         dhcp6_hdr && dhcp6_hdr->msg_type ==

DHCP6_MSG_REPLY) {

dhcp6_hdr is necessarily non-NULL here, so please drop "dhcp6_hdr &&"

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 3 lines
net/dhcpv6.c +3 -0
+                             if (dhcp6_check_reply_packet(rx_pkt, len))
+                                     return;
+                             if

(!sm_params.rx_status.rapid_commit_found) {

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, · line 639

Quoted 1 line
net/dhcpv6.c +1 -0
+                                     debug("[DHCPv6] REPLY received

without Rapid Commit option, ignoring\n");

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 3 lines
net/dhcpv6.c +3 -0
+                                     return;
+                             }
+                             debug("REPLY (Rapid Commit) good,

transition to DONE\n");

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 3 lines
net/dhcpv6.c +3 -0
+                             sm_params.next_state = DHCP6_DONE;
+                     } else {
+                             /* check the rx packet and determine if we

can transition to next

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 3 lines
net/dhcpv6.c +3 -0
+                              * state.
+                              */
+                             if (dhcp6_check_advertise_packet(rx_pkt,

len))

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 5 lines
net/dhcpv6.c +2 -2
+                                     return;
 
-                     debug("ADVERTISE good, transition to REQUEST\n");
-                     sm_params.next_state = DHCP6_REQUEST;
+                             debug("ADVERTISE good, transition to

REQUEST\n");

net/dhcpv6.c static void dhcp6_state_machine(bool timeout, uchar *rx_pkt, unsigned int len)

Quoted 4 lines
net/dhcpv6.c +2 -0
+                             sm_params.next_state = DHCP6_REQUEST;
+                     }
              } else if (sm_params.retry_cnt == 1)  {
                      /* If a server UID was received in the first

SOLICIT period

Quoted 22 lines
net/dhcpv6.c +0 -0
                       * transition to REQUEST
net/dhcpv6.h +2 -1
index d41a3c30615..49f20390730 100644
@@ -24,6 +24,7 @@
 #define DHCP6_OPTION_PREFERENCE              7
 #define DHCP6_OPTION_ELAPSED_TIME    8
 #define DHCP6_OPTION_STATUS_CODE     13
+#define DHCP6_OPTION_RAPID_COMMIT    14
 #define DHCP6_OPTION_OPT_BOOTFILE_URL        59
 #define DHCP6_OPTION_OPT_BOOTFILE_PARAM      60
 #define DHCP6_OPTION_SOL_MAX_RT              82
@@ -152,6 +153,7 @@ struct dhcp6_rx_pkt_status {
      enum dhcp6_status       ia_status_code;
      enum dhcp6_status       status_code;
      u8                      preference;
+     bool                    rapid_commit_found;
 };
 
 /**
---
Quoted 3 lines

base-commit: 527115ef6783cec49e5610c523c124b399011361
branch: main

--
Jerome