diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2019-12-09 04:23:01 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2019-12-09 04:23:01 +0100 |
commit | ff2ca10cba9c5a3be690ec1a77a068e23395ef20 (patch) | |
tree | cd6b3d8f0a1b825755d5731e02925618725a0867 /lib | |
parent | 21d09632a524c0d2a7f44a51f877370ad07b983c (diff) |
Filter: Add support for src/dst accessors for Flowspec and SADR
Diffstat (limited to 'lib')
-rw-r--r-- | lib/flowspec.c | 28 | ||||
-rw-r--r-- | lib/flowspec.h | 3 |
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]; } /* |