-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper function to validate interface name length (#931)
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com> Co-authored-by: afeigin <afeigin@nvidia.com>
- Loading branch information
1 parent
dc75f23
commit b686bb0
Showing
4 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef __INTERFACE__ | ||
#define __INTERFACE__ | ||
|
||
#include <string> | ||
#include <net/if.h> | ||
|
||
namespace swss | ||
{ | ||
|
||
const size_t IFACE_NAME_MAX_LEN = IFNAMSIZ - 1; | ||
|
||
bool isInterfaceNameValid(const std::string &ifaceName) | ||
{ | ||
return !ifaceName.empty() && (ifaceName.length() < IFNAMSIZ); | ||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from swsscommon import swsscommon | ||
|
||
def test_is_interface_name_valid(): | ||
invalid_interface_name = "TooLongInterfaceName" | ||
assert not swsscommon.isInterfaceNameValid(invalid_interface_name) | ||
|
||
validInterfaceName = "OkInterfaceName" | ||
assert swsscommon.isInterfaceNameValid(validInterfaceName) |