From: John Mulligan Date: Wed, 11 Jun 2025 18:57:34 +0000 (-0400) Subject: mgr/smb: add validation function for smb cluster custom ports X-Git-Tag: v20.1.0~42^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e3150e40d3ca36c0d09c45772ccd0013725bedd6;p=ceph.git mgr/smb: add validation function for smb cluster custom ports Add a function that will be used to validate the smb cluster's custom port values (when provided). Signed-off-by: John Mulligan (cherry picked from commit 81a5081b7b22aea2371f3c3f9e5003ba3643e947) --- diff --git a/src/pybind/mgr/smb/validation.py b/src/pybind/mgr/smb/validation.py index f9607cddcdf..8d83e24b4f9 100644 --- a/src/pybind/mgr/smb/validation.py +++ b/src/pybind/mgr/smb/validation.py @@ -112,3 +112,25 @@ def check_access_name(name: str) -> None: ) if len(name) > 128: raise ValueError('login name may not exceed 128 characters') + + +PORT_SERVICES = {"smb", "ctdb", "smbmetrics"} +_MAX_PORT = (1 << 16) - 1 + + +def check_custom_ports(ports: Optional[Dict[str, int]]) -> None: + if ports is None: + return + other = set(ports) - PORT_SERVICES + if other: + raise ValueError( + "invalid service names for custom ports:" + f' {", ".join(sorted(other))}' + ) + invalid = {str(p) for p in ports.values() if not 0 < p <= _MAX_PORT} + if invalid: + raise ValueError( + f'invalid port number(s): {", ".join(sorted(invalid))}' + ) + if len(ports) != len(set(ports.values())): + raise ValueError('port numbers must not be repeated')