diff options
author | Jan Moskyto Matejka <mq@ucw.cz> | 2017-02-22 11:58:04 +0100 |
---|---|---|
committer | Jan Moskyto Matejka <mq@ucw.cz> | 2017-02-22 11:58:04 +0100 |
commit | c609d039860f97f400d2cf0e9ca2b4e87b3fd1cc (patch) | |
tree | 6141291f6d6fbc0a90320f39c01bde49a119eadf /lib | |
parent | 62e64905b76b88da72c522eac9276a74f60c9592 (diff) | |
parent | 2be9218a3b1dfcc8e42c8d118e95f2074d9f7a7c (diff) |
Merge branch 'int-new' into nexthop-merged
Diffstat (limited to 'lib')
-rw-r--r-- | lib/flowspec.c | 6 | ||||
-rw-r--r-- | lib/flowspec.h | 7 | ||||
-rw-r--r-- | lib/flowspec_test.c | 11 | ||||
-rw-r--r-- | lib/hash.h | 6 |
4 files changed, 17 insertions, 13 deletions
diff --git a/lib/flowspec.c b/lib/flowspec.c index b72bc7fc..ea55b736 100644 --- a/lib/flowspec.c +++ b/lib/flowspec.c @@ -957,7 +957,7 @@ fragment_val_str(u8 val) return "???"; } -static int +static uint net_format_flow(char *buf, uint blen, const byte *data, uint dlen, int ipv6) { buffer b = { @@ -1125,7 +1125,7 @@ net_format_flow(char *buf, uint blen, const byte *data, uint dlen, int ipv6) * of written chars. If final string is too large, the string will ends the with * ' ...}' sequence and zero-terminator. */ -int +uint flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f) { return net_format_flow(buf, blen, f->data, f->length - sizeof(net_addr_flow4), 0); @@ -1141,7 +1141,7 @@ flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f) * of written chars. If final string is too large, the string will ends the with * ' ...}' sequence and zero-terminator. */ -int +uint flow6_net_format(char *buf, uint blen, const net_addr_flow6 *f) { return net_format_flow(buf, blen, f->data, f->length - sizeof(net_addr_flow6), 1); diff --git a/lib/flowspec.h b/lib/flowspec.h index 57809bec..9150ca91 100644 --- a/lib/flowspec.h +++ b/lib/flowspec.h @@ -42,6 +42,9 @@ const char *flow_type_str(enum flow_type type, int ipv6); uint flow_write_length(byte *data, u16 len); +static inline u16 flow_hdr_length(const byte *data) +{ return ((*data & 0xf0) == 0xf0) ? 2 : 1; } + static inline u16 flow_read_length(const byte *data) { return ((*data & 0xf0) == 0xf0) ? get_u16(data) & 0x0fff : *data; } @@ -128,7 +131,7 @@ void flow6_validate_cf(net_addr_flow6 *f); * Net Formatting */ -int flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f); -int flow6_net_format(char *buf, uint blen, const net_addr_flow6 *f); +uint flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f); +uint flow6_net_format(char *buf, uint blen, const net_addr_flow6 *f); #endif /* _BIRD_FLOWSPEC_H_ */ diff --git a/lib/flowspec_test.c b/lib/flowspec_test.c index 93364dfe..36336104 100644 --- a/lib/flowspec_test.c +++ b/lib/flowspec_test.c @@ -30,20 +30,17 @@ t_read_length(void) { byte data[] = { 0xcc, 0xcc, 0xcc }; - u16 get; - u16 expect; - for (uint expect = 0; expect < 0xf0; expect++) { *data = expect; - get = flow_read_length(data); + uint get = flow_read_length(data); bt_assert_msg(get == expect, "Testing get length 0x%02x (get 0x%02x)", expect, get); } for (uint expect = 0; expect <= 0xfff; expect++) { put_u16(data, expect | 0xf000); - get = flow_read_length(data); + uint get = flow_read_length(data); bt_assert_msg(get == expect, "Testing get length 0x%03x (get 0x%03x)", expect, get); } @@ -54,12 +51,10 @@ static int t_write_length(void) { byte data[] = { 0xcc, 0xcc, 0xcc }; - uint offset; - byte *c; for (uint expect = 0; expect <= 0xfff; expect++) { - offset = flow_write_length(data, expect); + uint offset = flow_write_length(data, expect); uint set = (expect < 0xf0) ? *data : (get_u16(data) & 0x0fff); bt_assert_msg(set == expect, "Testing set length 0x%03x (set 0x%03x)", expect, set); @@ -25,6 +25,12 @@ (v).data = mb_allocz(pool, HASH_SIZE(v) * sizeof(* (v).data)); \ }) +#define HASH_FREE(v) \ + ({ \ + mb_free((v).data); \ + (v) = (typeof(v)){ }; \ + }) + #define HASH_FIND(v,id,key...) \ ({ \ u32 _h = HASH_FN(v, id, key); \ |