From: Craig Gallek <kraigatgoog@gmail.com>
To: Daniel Mack <daniel@zonque.org>, Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
"David S . Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH net-next 2/3] bpf: Add uniqueness invariant to trivial lpm test implementation
Date: Mon, 18 Sep 2017 15:30:56 -0400 [thread overview]
Message-ID: <20170918193057.37644-3-kraigatgoog@gmail.com> (raw)
In-Reply-To: <20170918193057.37644-1-kraigatgoog@gmail.com>
From: Craig Gallek <kraig@google.com>
The 'trivial' lpm implementation in this test allows equivalent nodes
to be added (that is, nodes consisting of the same prefix and prefix
length). For lookup operations, this is fine because insertion happens
at the head of the (singly linked) list and the first, best match is
returned. In order to support deletion, the tlpm data structue must
first enforce uniqueness. This change modifies the insertion algorithm
to search for equivalent nodes and remove them. Note: the
BPF_MAP_TYPE_LPM_TRIE already has a uniqueness invariant that is
implemented as node replacement.
Signed-off-by: Craig Gallek <kraig@google.com>
---
tools/testing/selftests/bpf/test_lpm_map.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/test_lpm_map.c b/tools/testing/selftests/bpf/test_lpm_map.c
index e97565243d59..a5ed7c4f1819 100644
--- a/tools/testing/selftests/bpf/test_lpm_map.c
+++ b/tools/testing/selftests/bpf/test_lpm_map.c
@@ -31,6 +31,10 @@ struct tlpm_node {
uint8_t key[];
};
+static struct tlpm_node *tlpm_match(struct tlpm_node *list,
+ const uint8_t *key,
+ size_t n_bits);
+
static struct tlpm_node *tlpm_add(struct tlpm_node *list,
const uint8_t *key,
size_t n_bits)
@@ -38,9 +42,17 @@ static struct tlpm_node *tlpm_add(struct tlpm_node *list,
struct tlpm_node *node;
size_t n;
+ n = (n_bits + 7) / 8;
+
+ /* 'overwrite' an equivalent entry if one already exists */
+ node = tlpm_match(list, key, n_bits);
+ if (node && node->n_bits == n_bits) {
+ memcpy(node->key, key, n);
+ return list;
+ }
+
/* add new entry with @key/@n_bits to @list and return new head */
- n = (n_bits + 7) / 8;
node = malloc(sizeof(*node) + n);
assert(node);
--
2.14.1.690.gbb1197296e-goog
next prev parent reply other threads:[~2017-09-18 19:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-18 19:30 [PATCH net-next 0/3] Implement delete for BPF LPM trie Craig Gallek
2017-09-18 19:30 ` [PATCH net-next 1/3] bpf: Implement map_delete_elem for BPF_MAP_TYPE_LPM_TRIE Craig Gallek
2017-09-18 22:53 ` Alexei Starovoitov
2017-09-19 15:08 ` Craig Gallek
2017-09-19 16:12 ` Daniel Borkmann
2017-09-19 19:48 ` Daniel Mack
2017-09-18 19:30 ` Craig Gallek [this message]
2017-09-18 22:54 ` [PATCH net-next 2/3] bpf: Add uniqueness invariant to trivial lpm test implementation Alexei Starovoitov
2017-09-19 16:12 ` Daniel Borkmann
2017-09-18 19:30 ` [PATCH net-next 3/3] bpf: Test deletion in BPF_MAP_TYPE_LPM_TRIE Craig Gallek
2017-09-18 22:54 ` Alexei Starovoitov
2017-09-19 16:12 ` Daniel Borkmann
2017-09-19 20:55 ` [PATCH net-next 0/3] Implement delete for BPF LPM trie David Miller
2017-09-19 21:13 ` Daniel Mack
2017-09-19 21:16 ` Craig Gallek
2017-09-19 21:29 ` David Miller
2017-09-19 21:31 ` Daniel Mack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170918193057.37644-3-kraigatgoog@gmail.com \
--to=kraigatgoog@gmail.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=daniel@zonque.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).