summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2020-06-22 19:59:01 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2020-06-22 19:59:01 +0200
commitadeb067232387f42635a2fe1bfb58ea6311ffb67 (patch)
tree94facbdefb24894637ddfd0c62dc0f881bc620ab /lib
parentMerge pull request #6600 from mjstapp/fix_ldp_zlog_tmp (diff)
downloadfrr-adeb067232387f42635a2fe1bfb58ea6311ffb67.tar.xz
frr-adeb067232387f42635a2fe1bfb58ea6311ffb67.zip
lib: clarify usage of prefix_bit function
"prefixlen" is really a bit index Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/prefix.c6
-rw-r--r--lib/prefix.h12
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/prefix.c b/lib/prefix.c
index 112630e9c..0900100be 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -75,10 +75,10 @@ bool is_mcast_mac(const struct ethaddr *mac)
return false;
}
-unsigned int prefix_bit(const uint8_t *prefix, const uint16_t prefixlen)
+unsigned int prefix_bit(const uint8_t *prefix, const uint16_t bit_index)
{
- unsigned int offset = prefixlen / 8;
- unsigned int shift = 7 - (prefixlen % 8);
+ unsigned int offset = bit_index / 8;
+ unsigned int shift = 7 - (bit_index % 8);
return (prefix[offset] >> shift) & 1;
}
diff --git a/lib/prefix.h b/lib/prefix.h
index 506efffb9..0bd457cc2 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -392,8 +392,16 @@ extern const char *family2str(int family);
extern const char *safi2str(safi_t safi);
extern const char *afi2str(afi_t afi);
-/* Check bit of the prefix. */
-extern unsigned int prefix_bit(const uint8_t *prefix, const uint16_t prefixlen);
+/*
+ * Check bit of the prefix.
+ *
+ * prefix
+ * byte buffer
+ *
+ * bit_index
+ * which bit to fetch from byte buffer, 0 indexed.
+ */
+extern unsigned int prefix_bit(const uint8_t *prefix, const uint16_t bit_index);
extern struct prefix *prefix_new(void);
extern void prefix_free(struct prefix **p);