Cleanup NLB dead auth fields and tighten error handling

Remove unused hdr_auth/opaque_auth_ready state left after hs-key-only
envelope auth, trigger ESP/SSL reconnect on opaque refresh failure,
and log outbound NLB encap failures at ERR level.
This commit is contained in:
Kevin Yue committed 2026-07-04 18:37:14 +08:00
1 parent 81fcd253d3
commit 3c16026acc
1 file changed
+146
@@ -0,0 +1,146 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kevin Yue <[email protected]>
Date: Thu, 26 Jun 2026 01:00:00 +0800
Subject: [PATCH 18/18] Cleanup NLB dead fields and error handling
Remove unused hdr_auth/opaque_auth_ready state, reconnect on opaque
refresh failure, and log outbound NLB encap failures at ERR level.
---
--- a/gpst_nlb.c
+++ b/gpst_nlb.c
@@ -84,12 +84,8 @@
#define GP_NLB_BLOB_CIPHER_OFF 28
#define GP_NLB_ENC_HS_KEY_CIPHER_LEN 36
#define GP_NLB_HDR_AUTH_LEN 6
-#define GP_NLB_OPAQUE_AUTH_OFF 8
#define GP_NLB_HDR_SIGN_LEN 10
-static void gp_nlb_apply_decrypted_opaque(struct openconnect_info *vpninfo,
- struct gp_nlb_config *nlb);
-
static int gp_nlb_is_ipv4(const char *s)
{
struct in_addr a;
@@ -146,8 +142,6 @@
nlb->decrypted_opaque_len = 0;
memset(nlb->opaque_key, 0, sizeof(nlb->opaque_key));
nlb->opaque_key_len = 0;
- memset(nlb->hdr_auth, 0, sizeof(nlb->hdr_auth));
- nlb->opaque_auth_ready = 0;
}
static void gp_nlb_clear_opaque_blob(struct gp_nlb_config *nlb)
@@ -241,38 +235,11 @@
gp_nlb_clear_decrypted_opaque(nlb);
nlb->decrypted_opaque = out;
nlb->decrypted_opaque_len = out_len;
- gp_nlb_apply_decrypted_opaque(vpninfo, nlb);
vpn_progress(vpninfo, PRG_DEBUG,
_("Decrypted tunnel-opaque body (%d bytes)\n"), out_len);
return 0;
}
-static void gp_nlb_apply_decrypted_opaque(struct openconnect_info *vpninfo,
- struct gp_nlb_config *nlb)
-{
- if (!nlb->decrypted_opaque) {
- vpn_progress(vpninfo, PRG_DEBUG,
- _("NLB decrypted opaque missing; cannot extract hdr auth material\n"));
- return;
- }
- if (nlb->decrypted_opaque_len < GP_NLB_OPAQUE_AUTH_OFF + GP_NLB_HDR_AUTH_LEN) {
- vpn_progress(vpninfo, PRG_INFO,
- _("NLB decrypted opaque too short (%d bytes, need %d); auth material unavailable\n"),
- nlb->decrypted_opaque_len,
- GP_NLB_OPAQUE_AUTH_OFF + GP_NLB_HDR_AUTH_LEN);
- return;
- }
-
- memcpy(nlb->hdr_auth,
- nlb->decrypted_opaque + GP_NLB_OPAQUE_AUTH_OFF,
- GP_NLB_HDR_AUTH_LEN);
- nlb->opaque_auth_ready = 1;
- vpn_progress(vpninfo, PRG_DEBUG,
- _("NLB tunnel-opaque auth material ready (offset %d, %d bytes)\n"),
- GP_NLB_OPAQUE_AUTH_OFF, GP_NLB_HDR_AUTH_LEN);
- dump_buf_hex(vpninfo, PRG_DEBUG, '=', nlb->hdr_auth, GP_NLB_HDR_AUTH_LEN);
-}
-
static void gp_nlb_write_hdr(unsigned char *hdr, struct gp_nlb_config *nlb,
uint16_t inner_len, uint8_t type)
{
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -410,8 +410,6 @@
uint32_t blob_session_id;
unsigned char opaque_key[48];
int opaque_key_len;
- unsigned char hdr_auth[6];
- int opaque_auth_ready;
uint16_t wire_seq;
int keepalive_sent;
};
--- a/gpst.c
+++ b/gpst.c
@@ -1343,7 +1343,12 @@
/* fall through */
case DTLS_ESTABLISHED:
/* Rekey or check-and-resubmit HIP if needed */
- if (gpst_nlb_maintenance(vpninfo, timeout) > 0)
+ ret = gpst_nlb_maintenance(vpninfo, timeout);
+ if (ret < 0) {
+ vpninfo->dtls_need_reconnect = 1;
+ return 1;
+ }
+ if (ret > 0)
return 1;
if (keepalive_action(&vpninfo->ssl_times, timeout) == KA_REKEY)
goto do_rekey;
@@ -1375,7 +1380,10 @@
;
}
- if (gpst_nlb_maintenance(vpninfo, timeout) > 0)
+ ret = gpst_nlb_maintenance(vpninfo, timeout);
+ if (ret < 0)
+ goto do_reconnect;
+ if (ret > 0)
work_done = 1;
if (vpninfo->ssl_fd == -1)
@@ -1801,7 +1809,7 @@
if (pktlen < 0)
vpn_progress(vpninfo, PRG_DEBUG, _("Failed to send ESP probe\n"));
else if (vpninfo->gp_nlb.enabled && gpst_nlb_esp_encap(vpninfo, pkt, &pktlen) < 0)
- vpn_progress(vpninfo, PRG_DEBUG, _("Failed to NLB-wrap ESP probe\n"));
+ vpn_progress(vpninfo, PRG_ERR, _("Failed to NLB-wrap ESP probe\n"));
else if (send(vpninfo->dtls_fd, (void *)&pkt->esp, pktlen, 0) < 0)
vpn_progress(vpninfo, PRG_DEBUG, _("Failed to send ESP probe\n"));
--- a/esp.c
+++ b/esp.c
@@ -360,8 +360,13 @@
vpninfo->dtls_times.last_tx = now;
}
- if (vpninfo->proto->proto == PROTO_GPST && gpst_nlb_maintenance(vpninfo, timeout) > 0)
- work_done = 1;
+ if (vpninfo->proto->proto == PROTO_GPST) {
+ ret = gpst_nlb_maintenance(vpninfo, timeout);
+ if (ret < 0)
+ goto need_reconnect;
+ if (ret > 0)
+ work_done = 1;
+ }
if (vpninfo->dtls_state != DTLS_ESTABLISHED)
return work_done;
@@ -459,6 +464,8 @@
if (vpninfo->proto->proto == PROTO_GPST && vpninfo->gp_nlb.enabled &&
gpst_nlb_esp_encap(vpninfo, this, &len) < 0) {
+ vpn_progress(vpninfo, PRG_ERR,
+ _("Failed to NLB-wrap outbound ESP packet\n"));
free_pkt(vpninfo, this);
work_done = 1;
continue;