summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2023-07-28 06:25:43 +0300
committerJakub Kicinski <kuba@kernel.org>2023-07-28 06:25:43 +0300
commit5908a4c47c9c8d7898841dc3dd2e70aa5d91bc05 (patch)
tree0d59427f1cb92e87258a88af324e3f5d781f2d4e /lib
parentbb85e12f8fce8f31f661cd904ede8ecf9ce843d6 (diff)
parent86e9c9aa2358a74bcc5e63f9fc69c2d01e64c002 (diff)
downloadlinux-5908a4c47c9c8d7898841dc3dd2e70aa5d91bc05.tar.xz
Merge tag 'nf-next-23-07-27' of https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next
Florian Westphal says: ==================== netfilter updates for net-next 1. silence a harmless warning for CONFIG_NF_CONNTRACK_PROCFS=n builds, from Zhu Wang. 2, 3: Allow NLA_POLICY_MASK to be used with BE16/BE32 types, and replace a few manual checks with nla_policy based one in nf_tables, from myself. 4: cleanup in ctnetlink to validate while parsing rather than using two steps, from Lin Ma. 5: refactor boyer-moore textsearch by moving a small chunk to a helper function, rom Jeremy Sowden. * tag 'nf-next-23-07-27' of https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next: lib/ts_bm: add helper to reduce indentation and improve readability netfilter: conntrack: validate cta_ip via parsing netfilter: nf_tables: use NLA_POLICY_MASK to test for valid flag options netlink: allow be16 and be32 types in all uint policy checks nf_conntrack: fix -Wunused-const-variable= ==================== Link: https://lore.kernel.org/r/20230727133604.8275-1-fw@strlen.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/nlattr.c6
-rw-r--r--lib/ts_bm.c43
2 files changed, 36 insertions, 13 deletions
diff --git a/lib/nlattr.c b/lib/nlattr.c
index 489e15bde5c1..7a2b6c38fd59 100644
--- a/lib/nlattr.c
+++ b/lib/nlattr.c
@@ -355,6 +355,12 @@ static int nla_validate_mask(const struct nla_policy *pt,
case NLA_U64:
value = nla_get_u64(nla);
break;
+ case NLA_BE16:
+ value = ntohs(nla_get_be16(nla));
+ break;
+ case NLA_BE32:
+ value = ntohl(nla_get_be32(nla));
+ break;
default:
return -EINVAL;
}
diff --git a/lib/ts_bm.c b/lib/ts_bm.c
index c8ecbf74ef29..e5f30f9177df 100644
--- a/lib/ts_bm.c
+++ b/lib/ts_bm.c
@@ -55,6 +55,24 @@ struct ts_bm
unsigned int good_shift[];
};
+static unsigned int matchpat(const u8 *pattern, unsigned int patlen,
+ const u8 *text, bool icase)
+{
+ unsigned int i;
+
+ for (i = 0; i < patlen; i++) {
+ u8 t = *(text-i);
+
+ if (icase)
+ t = toupper(t);
+
+ if (t != *(pattern-i))
+ break;
+ }
+
+ return i;
+}
+
static unsigned int bm_find(struct ts_config *conf, struct ts_state *state)
{
struct ts_bm *bm = ts_config_priv(conf);
@@ -72,19 +90,18 @@ static unsigned int bm_find(struct ts_config *conf, struct ts_state *state)
break;
while (shift < text_len) {
- DEBUGP("Searching in position %d (%c)\n",
- shift, text[shift]);
- for (i = 0; i < bm->patlen; i++)
- if ((icase ? toupper(text[shift-i])
- : text[shift-i])
- != bm->pattern[bm->patlen-1-i])
- goto next;
-
- /* London calling... */
- DEBUGP("found!\n");
- return consumed + (shift-(bm->patlen-1));
-
-next: bs = bm->bad_shift[text[shift-i]];
+ DEBUGP("Searching in position %d (%c)\n",
+ shift, text[shift]);
+
+ i = matchpat(&bm->pattern[bm->patlen-1], bm->patlen,
+ &text[shift], icase);
+ if (i == bm->patlen) {
+ /* London calling... */
+ DEBUGP("found!\n");
+ return consumed + (shift-(bm->patlen-1));
+ }
+
+ bs = bm->bad_shift[text[shift-i]];
/* Now jumping to... */
shift = max_t(int, shift-i+bs, shift+bm->good_shift[i]);