parse-util: extend the maximum length of nftable identifiers
Since kernel v4.14, more specifically, after the following four commits, https://github.com/torvalds/linux/commit/e46abbcc05aa8a16b0e7f5c94e86d11af9aa2770 https://github.com/torvalds/linux/commit/b7263e071aba736cea9e71cdf2e76dfa7aebd039 https://github.com/torvalds/linux/commit/387454901bd62022ac1b04e15bd8d4fcc60bbed4 https://github.com/torvalds/linux/commit/615095752100748e221028fc96163c2b78185ae4 the maximum length of nftable identifiers are extended to 255. Now, our kernel baseline is 5.4, hence we can freely use the extended name length. This also modernizes code a bit, and adds test cases. Closes #36542.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <linux/ipv6.h>
|
||||
#include <linux/netfilter/nf_tables.h>
|
||||
#include <net/if.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -777,18 +778,14 @@ int parse_loadavg_fixed_point(const char *s, loadavg_t *ret) {
|
||||
/* Limitations are described in https://www.netfilter.org/projects/nftables/manpage.html and
|
||||
* https://bugzilla.netfilter.org/show_bug.cgi?id=1175 */
|
||||
bool nft_identifier_valid(const char *id) {
|
||||
if (!id)
|
||||
if (isempty(id))
|
||||
return false;
|
||||
|
||||
size_t len = strlen(id);
|
||||
if (len == 0 || len > 31)
|
||||
if (strlen(id) >= NFT_NAME_MAXLEN)
|
||||
return false;
|
||||
|
||||
if (!ascii_isalpha(id[0]))
|
||||
return false;
|
||||
|
||||
for (size_t i = 1; i < len; i++)
|
||||
if (!ascii_isalpha(id[i]) && !ascii_isdigit(id[i]) && !IN_SET(id[i], '/', '\\', '_', '.'))
|
||||
return false;
|
||||
return true;
|
||||
return in_charset(id + 1, ALPHANUMERICAL "/\\_.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user