aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2021-05-18 19:54:18 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2021-05-18 19:54:18 +0200
commitdd8481cc1c92af32ec69cded42b985b7bad40b26 (patch)
tree3ff60df9e9c75dc61b3d0ca6857c3b2205ddf1db /lib
parente5468d16855600aeb8172e29936789c46ea58da0 (diff)
downloadbird-dd8481cc1c92af32ec69cded42b985b7bad40b26.tar.gz
Flowspec: Do not use comma for bitmask operators
For numeric operators, comma is used for disjunction in expressions like "10, 20, 30..40". But for bitmask operators, comma is used for conjunction in a way that does not really make much sense. Use always explicit logical operators (&& and ||) to connect bitmask operators. Thanks to Matt Corallo for the bugreport.
Diffstat (limited to 'lib')
-rw-r--r--lib/flowspec.c13
-rw-r--r--lib/flowspec_test.c2
2 files changed, 3 insertions, 12 deletions
diff --git a/lib/flowspec.c b/lib/flowspec.c
index e47fb7e2..1445435a 100644
--- a/lib/flowspec.c
+++ b/lib/flowspec.c
@@ -1278,17 +1278,8 @@ net_format_flow_bitmask(buffer *b, const byte *part)
while (1)
{
if (!first)
- {
- if (isset_and(op))
- {
- b->pos--; /* Remove last char (it is a space) */
- buffer_puts(b, ",");
- }
- else
- {
- buffer_puts(b, "|| ");
- }
- }
+ buffer_puts(b, isset_and(op) ? "&& " : "|| ");
+
first = 0;
len = get_value_length(op);
diff --git a/lib/flowspec_test.c b/lib/flowspec_test.c
index b6b4d7b8..2285075c 100644
--- a/lib/flowspec_test.c
+++ b/lib/flowspec_test.c
@@ -630,7 +630,7 @@ t_formatting4(void)
net_addr_flow4 *input;
NET_ADDR_FLOW4_(input, ip4_build(5, 6, 7, 0), 24, nlri);
- const char *expect = "flow4 { dst 10.0.0.0/8; proto 23; dport > 24 && < 30 || 40..50,60..70,80 && >= 90; sport > 24 && < 30 || 40,50,60..70,80; icmp type 80; icmp code 90; tcp flags 0x3/0x3,0x0/0xc; length 0..65535; dscp 63; fragment dont_fragment || !is_fragment; }";
+ const char *expect = "flow4 { dst 10.0.0.0/8; proto 23; dport > 24 && < 30 || 40..50,60..70,80 && >= 90; sport > 24 && < 30 || 40,50,60..70,80; icmp type 80; icmp code 90; tcp flags 0x3/0x3 && 0x0/0xc; length 0..65535; dscp 63; fragment dont_fragment || !is_fragment; }";
bt_assert(flow4_net_format(b, sizeof(b), input) == strlen(expect));
bt_debug(" expect: '%s',\n output: '%s'\n", expect, b);