Skip to content

Commit

Permalink
Make interface name length validation more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
arfeigin committed May 30, 2024
1 parent f30d1e9 commit 462ab35
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion common/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ namespace swss {

inline bool isInterfaceNameLenOk(const std::string &ifaceName)
{
if (ifaceName.length() >= IFNAMSIZ)
if (!validate_interface_name_length(ifaceName))
{
SWSS_LOG_ERROR("Invalid interface name %s length, it must not exceed %d characters", ifaceName.c_str(), IFNAMSIZ);
return false;
}
return true;
}

#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
iface_name_max_length = IFNAMSIZ
def validate_interface_name_length(iface_name):
"""
Verify that interface name length does not exceed IFNAMSIZ
"""
if len(iface_name) == 0:
return False
return True if len(iface_name) < IFNAMSIZ else False
%}
#endif

}

#endif

0 comments on commit 462ab35

Please sign in to comment.