summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/flowspec.c28
-rw-r--r--lib/flowspec.h3
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/flowspec.c b/lib/flowspec.c
index e9290b88..ef19aa96 100644
--- a/lib/flowspec.c
+++ b/lib/flowspec.c
@@ -243,12 +243,37 @@ flow6_next_part(const byte *pos, const byte *end)
return flow_next_part(pos, end, 1);
}
+static const byte *
+flow_get_part(const byte *data, uint dlen, uint type, int ipv6)
+{
+ const byte *part;
+
+ for (part = flow_first_part(data);
+ part && (part[0] <= type);
+ part = flow_next_part(part, data+dlen, ipv6))
+ if (part[0] == type)
+ return part;
+
+ return NULL;
+}
+
+const byte *
+flow4_get_part(const net_addr_flow4 *f, uint type)
+{
+ return flow_get_part(f->data, f->length - sizeof(net_addr_flow4), type, 0);
+}
+
+const byte *
+flow6_get_part(const net_addr_flow6 *f, uint type)
+{
+ return flow_get_part(f->data, f->length - sizeof(net_addr_flow6), type, 1);
+}
+
/*
* Flowspec accessors
*/
-
static inline ip4_addr
flow_read_ip4(const byte *px, uint pxlen)
{
@@ -282,7 +307,6 @@ flow_read_ip6_part(const byte *part)
}
-
/*
* Flowspec validation
*/
diff --git a/lib/flowspec.h b/lib/flowspec.h
index d486cda0..9bafc52e 100644
--- a/lib/flowspec.h
+++ b/lib/flowspec.h
@@ -83,6 +83,8 @@ const byte *flow4_first_part(const net_addr_flow4 *f);
const byte *flow6_first_part(const net_addr_flow6 *f);
const byte *flow4_next_part(const byte *pos, const byte *end);
const byte *flow6_next_part(const byte *pos, const byte *end);
+const byte *flow4_get_part(const net_addr_flow4 *f, uint type);
+const byte *flow6_get_part(const net_addr_flow6 *f, uint type);
/*
@@ -91,6 +93,7 @@ const byte *flow6_next_part(const byte *pos, const byte *end);
ip4_addr flow_read_ip4_part(const byte *part);
ip6_addr flow_read_ip6_part(const byte *part);
+static inline int flow_read_pxlen(const byte *part) { return part[1]; }
/*