mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2026-01-27 10:22:23 +00:00
ucentral: hex-encode DHCP vendor data before exporting VSI JSON
DHCP Option 43 vendor data may contain non-UTF8 or binary characters. Previously, this vendor string was written directly into /tmp/udhcpc-vsi.json and propagated into the uCentral connect payload. When the vendor value included non-ASCII or invalid escape sequences, this resulted in malformed JSON or invalid UTF-8, causing the uCentral controller to reject the connect message and immediately close the connection. This change introduces a helper function to safely normalize the vendor string into a hex-encoded representation before exporting it into VSI JSON. The function handles both hex-like strings and raw characters, ensuring the generated JSON is always valid and schema-safe. With this fix, uCentral connectivity remains stable even when DHCP Option 43 contains binary vendor data. Signed-off-by: Venkat Chimata <venkat@nearhop.com>
This commit is contained in:
@@ -10,6 +10,39 @@ let value = getenv("opt43");
|
||||
if (!ifname)
|
||||
exit(0);
|
||||
|
||||
function vendor_hex(vendor) {
|
||||
let hex = "";
|
||||
let firstchar = "";
|
||||
|
||||
// The string contains either special characters
|
||||
// or hex characters or any other alpha numberic character
|
||||
// If it is special character, consider first character to include in the hex string
|
||||
// If it is hex, consider two characters for the hex to include in the hex string.
|
||||
// For any other alpha numeric character, consider it as it is into the hex string
|
||||
|
||||
for (let i = 0; i < length(vendor); i++) {
|
||||
if (match(substr(vendor, i, 1), /[a-fA-F0-9]/)) {
|
||||
if (firstchar != "") {
|
||||
hex += firstchar + substr(vendor, i, 1);
|
||||
firstchar = "";
|
||||
} else {
|
||||
firstchar = substr(vendor, i, 1);
|
||||
}
|
||||
} else {
|
||||
if (firstchar != "") {
|
||||
hex += firstchar;
|
||||
}
|
||||
if (match(substr(vendor, i, 1), /[a-zA-Z0-9]/)) {
|
||||
hex += substr(vendor, i, 1);
|
||||
} else {
|
||||
hex += sprintf("%02x", ord(vendor, i));
|
||||
}
|
||||
firstchar = "";
|
||||
}
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
if (!vendor)
|
||||
vendor = "unknown";
|
||||
|
||||
@@ -32,6 +65,7 @@ if (cmd == "deconfig" || !vendor || !value) {
|
||||
}
|
||||
}
|
||||
else if (cmd == "bound") {
|
||||
let vendor = vendor_hex(vendor);
|
||||
let vsi = { vendor, value };
|
||||
|
||||
let vsi_list = {};
|
||||
|
||||
Reference in New Issue
Block a user