summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/basic/socket-util.c12
-rw-r--r--src/basic/socket-util.h5
-rw-r--r--src/test/test-socket-util.c1
3 files changed, 14 insertions, 4 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index 19dd053e36..64bc79712f 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
+#include <linux/if.h>
#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 48a22415df..17c20abc32 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 b36e005264..2489d00e26 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) {