This helper encloses the (simple) logic used by OpenVPN to determine if
the name passed to --dev has to be considered a fixed interface name or
just a pattern.
Having a helper is useful because when this logic is required elsewhere,
we can just re-use this logic without duplicating the code (which may
mean introducing bugs if a future logic change should not update all
spots).
The logic is actually fairly simple: check if the name contains a number
(i.e. tun0). If so, consider the name a fixed device name.
While at it make has_digit() accept a signed argument because strings
are normally signed (also isdigit() accepts a signed argument).
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <
20220712221655.19333-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24676.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
/* return true if string contains at least one numerical digit */
static inline bool
-has_digit(const unsigned char *src)
+has_digit(const char *src)
{
- unsigned char c;
+ char c;
while ((c = *src++))
{
if (isdigit(c))
}
#endif /* if defined (TARGET_OPENBSD) || (defined(TARGET_DARWIN) && HAVE_NET_IF_UTUN_H) */
+bool
+tun_name_is_fixed(const char *dev)
+{
+ return has_digit(dev);
+}
#if !(defined(_WIN32) || defined(TARGET_LINUX))
static void
else
#endif
- if (dynamic && !has_digit((unsigned char *)dev))
+ if (dynamic && !tun_name_is_fixed(dev))
{
int i;
for (i = 0; i < 256; ++i)
}
const char *tun_stat(const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc);
+bool tun_name_is_fixed(const char *dev);
#endif /* TUN_H */