From: Yu Watanabe Date: Sun, 15 Dec 2019 14:01:54 +0000 (+0900) Subject: util: introduce ifname_valid_full() X-Git-Tag: v245-rc1~263^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4252696aec9ec038ff312a164e25f039da25126f;p=thirdparty%2Fsystemd.git util: introduce ifname_valid_full() --- diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index 19dd053e362..64bc79712f1 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "alloc-util.h" #include "errno-util.h" @@ -909,7 +910,7 @@ static const char* const ip_tos_table[] = { DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ip_tos, int, 0xff); -bool ifname_valid(const char *p) { +bool ifname_valid_full(const char *p, bool alternative) { bool numeric = true; /* Checks whether a network interface name is valid. This is inspired by dev_valid_name() in the kernel sources @@ -919,8 +920,13 @@ bool ifname_valid(const char *p) { if (isempty(p)) return false; - if (strlen(p) >= IFNAMSIZ) - return false; + if (alternative) { + if (strlen(p) >= ALTIFNAMSIZ) + return false; + } else { + if (strlen(p) >= IFNAMSIZ) + return false; + } if (dot_or_dot_dot(p)) return false; diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h index 48a22415df9..17c20abc32f 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -130,7 +130,10 @@ int fd_inc_rcvbuf(int fd, size_t n); int ip_tos_to_string_alloc(int i, char **s); int ip_tos_from_string(const char *s); -bool ifname_valid(const char *p); +bool ifname_valid_full(const char *p, bool alternative); +static inline bool ifname_valid(const char *p) { + return ifname_valid_full(p, false); +} bool address_label_valid(const char *p); int getpeercred(int fd, struct ucred *ucred); diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index b36e0052645..2489d00e263 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -45,6 +45,7 @@ static void test_ifname_valid(void) { assert(ifname_valid("xxxxxxxxxxxxxxx")); assert(!ifname_valid("xxxxxxxxxxxxxxxx")); + assert(ifname_valid_full("xxxxxxxxxxxxxxxx", true)); } static void test_socket_address_parse_one(const char *in, int ret, int family, const char *expected) {