Minor cleanups and fixes

This commit is contained in:
Ondrej Zajicek (work) 2017-05-23 13:12:25 +02:00
parent bb7aa06a48
commit 734e9fb8a9
9 changed files with 48 additions and 40 deletions

View file

@ -44,19 +44,19 @@ CF_GRAMMAR
/* Network Flow Specification */ /* Network Flow Specification */
flow_num_op: flow_num_op:
TRUE { $$ = 0b000; } TRUE { $$ = FLOW_OP_TRUE; }
| '=' { $$ = 0b001; } | '=' { $$ = FLOW_OP_EQ; }
| NEQ { $$ = 0b110; } | NEQ { $$ = FLOW_OP_NEQ; }
| '<' { $$ = 0b100; } | '<' { $$ = FLOW_OP_LT; }
| LEQ { $$ = 0b101; } | LEQ { $$ = FLOW_OP_LEQ; }
| '>' { $$ = 0b010; } | '>' { $$ = FLOW_OP_GT; }
| GEQ { $$ = 0b011; } | GEQ { $$ = FLOW_OP_GEQ; }
| FALSE { $$ = 0b111; } | FALSE { $$ = FLOW_OP_FALSE; }
; ;
flow_logic_op: flow_logic_op:
OR { $$ = 0x00; } OR { $$ = FLOW_OP_OR; }
| AND { $$ = 0x40; } | AND { $$ = FLOW_OP_AND; }
; ;
flow_num_type_: flow_num_type_:
@ -97,13 +97,13 @@ flow_num_opts:
flow_num_opt_ext_expr: flow_num_opt_ext_expr:
expr { expr {
flow_check_cf_value_length(this_flow, $1); flow_check_cf_value_length(this_flow, $1);
flow_builder_add_op_val(this_flow, 0b001, $1); flow_builder_add_op_val(this_flow, FLOW_OP_EQ, $1);
} }
| expr DDOT expr { | expr DDOT expr {
flow_check_cf_value_length(this_flow, $1); flow_check_cf_value_length(this_flow, $1);
flow_check_cf_value_length(this_flow, $3); flow_check_cf_value_length(this_flow, $3);
flow_builder_add_op_val(this_flow, 0b011, $1); /* >= */ flow_builder_add_op_val(this_flow, FLOW_OP_GEQ, $1);
flow_builder_add_op_val(this_flow, 0x40 | 0b101, $3); /* AND <= */ flow_builder_add_op_val(this_flow, FLOW_OP_AND | FLOW_OP_LEQ, $3);
} }
; ;

View file

@ -754,7 +754,7 @@ flow_builder_add_val_mask(struct flow_builder *fb, byte op, u32 value, u32 mask)
if (a) if (a)
{ {
flow_builder_add_op_val(fb, op ^ 0x01, a); flow_builder_add_op_val(fb, op ^ 0x01, a);
op |= 0x40; op |= FLOW_OP_AND;
} }
if (b) if (b)
@ -897,28 +897,20 @@ flow_builder_clear(struct flow_builder *fb)
*/ */
/* Flowspec operators for [op, value]+ pairs */ /* Flowspec operators for [op, value]+ pairs */
#define FLOW_TRUE 0b000
#define FLOW_EQ 0b001
#define FLOW_GT 0b010
#define FLOW_GTE 0b011
#define FLOW_LT 0b100
#define FLOW_LTE 0b101
#define FLOW_NEQ 0b110
#define FLOW_FALSE 0b111
static const char * static const char *
num_op_str(const byte *op) num_op_str(const byte *op)
{ {
switch (*op & 0x07) switch (*op & 0x07)
{ {
case FLOW_TRUE: return "true"; case FLOW_OP_TRUE: return "true";
case FLOW_EQ: return "="; case FLOW_OP_EQ: return "=";
case FLOW_GT: return ">"; case FLOW_OP_GT: return ">";
case FLOW_GTE: return ">="; case FLOW_OP_GEQ: return ">=";
case FLOW_LT: return "<"; case FLOW_OP_LT: return "<";
case FLOW_LTE: return "<="; case FLOW_OP_LEQ: return "<=";
case FLOW_NEQ: return "!="; case FLOW_OP_NEQ: return "!=";
case FLOW_FALSE: return "false"; case FLOW_OP_FALSE: return "false";
} }
return NULL; return NULL;
@ -985,8 +977,8 @@ net_format_flow_num(buffer *b, const byte *part)
{ {
/* XXX: I don't like this so complicated if-tree */ /* XXX: I don't like this so complicated if-tree */
if (!isset_and(op) && if (!isset_and(op) &&
((num_op( op) == FLOW_EQ) || (num_op( op) == FLOW_GTE)) && ((num_op( op) == FLOW_OP_EQ) || (num_op( op) == FLOW_OP_GEQ)) &&
((num_op(last_op) == FLOW_EQ) || (num_op(last_op) == FLOW_LTE))) ((num_op(last_op) == FLOW_OP_EQ) || (num_op(last_op) == FLOW_OP_LEQ)))
{ {
b->pos--; /* Remove last char (it is a space) */ b->pos--; /* Remove last char (it is a space) */
buffer_puts(b, ","); buffer_puts(b, ",");
@ -1002,7 +994,7 @@ net_format_flow_num(buffer *b, const byte *part)
val = get_value(op+1, len); val = get_value(op+1, len);
if (!isset_end(op) && !isset_and(op) && isset_and(op+1+len) && if (!isset_end(op) && !isset_and(op) && isset_and(op+1+len) &&
(num_op(op) == FLOW_GTE) && (num_op(op+1+len) == FLOW_LTE)) (num_op(op) == FLOW_OP_GEQ) && (num_op(op+1+len) == FLOW_OP_LEQ))
{ {
/* Display interval */ /* Display interval */
buffer_print(b, "%u..", val); buffer_print(b, "%u..", val);
@ -1011,7 +1003,7 @@ net_format_flow_num(buffer *b, const byte *part)
val = get_value(op+1, len); val = get_value(op+1, len);
buffer_print(b, "%u", val); buffer_print(b, "%u", val);
} }
else if (num_op(op) == FLOW_EQ) else if (num_op(op) == FLOW_OP_EQ)
{ {
buffer_print(b, "%u", val); buffer_print(b, "%u", val);
} }

View file

@ -14,6 +14,20 @@
#include "lib/net.h" #include "lib/net.h"
/* Flow component operators */
#define FLOW_OP_TRUE 0x00 /* 0b000 */
#define FLOW_OP_EQ 0x01 /* 0b001 */
#define FLOW_OP_GT 0x02 /* 0b010 */
#define FLOW_OP_GEQ 0x03 /* 0b011 */
#define FLOW_OP_LT 0x04 /* 0b100 */
#define FLOW_OP_LEQ 0x05 /* 0b101 */
#define FLOW_OP_NEQ 0x06 /* 0b110 */
#define FLOW_OP_FALSE 0x07 /* 0b111 */
#define FLOW_OP_OR 0x00
#define FLOW_OP_AND 0x40
/* Types of components in flowspec */ /* Types of components in flowspec */
enum flow_type { enum flow_type {
FLOW_TYPE_DST_PREFIX = 1, FLOW_TYPE_DST_PREFIX = 1,

View file

@ -47,7 +47,7 @@ static void proto_shutdown_loop(struct timer *);
static void proto_rethink_goal(struct proto *p); static void proto_rethink_goal(struct proto *p);
static char *proto_state_name(struct proto *p); static char *proto_state_name(struct proto *p);
static void channel_verify_limits(struct channel *c); static void channel_verify_limits(struct channel *c);
static void channel_reset_limit(struct channel_limit *l); static inline void channel_reset_limit(struct channel_limit *l);
static inline int proto_is_done(struct proto *p) static inline int proto_is_done(struct proto *p)

View file

@ -248,7 +248,7 @@ bfd_check_authentication(struct bfd_proto *p, struct bfd_session *s, struct bfd_
/* BFD CSNs are in 32-bit circular number space */ /* BFD CSNs are in 32-bit circular number space */
u32 csn = ntohl(auth->csn); u32 csn = ntohl(auth->csn);
if (s->rx_csn_known && if (s->rx_csn_known &&
(((csn - s->rx_csn) > (3 * s->detect_mult)) || (((csn - s->rx_csn) > (3 * (uint) s->detect_mult)) ||
(meticulous && (csn == s->rx_csn)))) (meticulous && (csn == s->rx_csn))))
{ {
/* We want to report both new and old CSN */ /* We want to report both new and old CSN */

View file

@ -450,7 +450,7 @@ rip_send_response(struct rip_proto *p, struct rip_iface *ifa)
/* Stale entries that should be removed */ /* Stale entries that should be removed */
if ((en->valid == RIP_ENTRY_STALE) && if ((en->valid == RIP_ENTRY_STALE) &&
((en->changed + ifa->cf->garbage_time) <= now)) ((en->changed + (bird_clock_t) ifa->cf->garbage_time) <= now))
goto next_entry; goto next_entry;
/* Triggered updates */ /* Triggered updates */

View file

@ -684,7 +684,7 @@ rip_reconfigure_iface(struct rip_proto *p, struct rip_iface *ifa, struct rip_ifa
rip_iface_update_buffers(ifa); rip_iface_update_buffers(ifa);
if (ifa->next_regular > (now + new->update_time)) if (ifa->next_regular > (now + (bird_clock_t) new->update_time))
ifa->next_regular = now + (random() % new->update_time) + 1; ifa->next_regular = now + (random() % new->update_time) + 1;
if (new->check_link != old->check_link) if (new->check_link != old->check_link)

View file

@ -62,8 +62,8 @@
#ifndef HAVE_STRUCT_RTVIA #ifndef HAVE_STRUCT_RTVIA
struct rtvia { struct rtvia {
__kernel_sa_family_t rtvia_family; unsigned short rtvia_family;
__u8 rtvia_addr[0]; u8 rtvia_addr[0];
}; };
#endif #endif

View file

@ -1344,6 +1344,7 @@ sk_tcp_connected(sock *s)
s->tx_hook(s); s->tx_hook(s);
} }
#ifdef HAVE_LIBSSH
static void static void
sk_ssh_connected(sock *s) sk_ssh_connected(sock *s)
{ {
@ -1351,6 +1352,7 @@ sk_ssh_connected(sock *s)
s->type = SK_SSH; s->type = SK_SSH;
s->tx_hook(s); s->tx_hook(s);
} }
#endif
static int static int
sk_passive_connected(sock *s, int type) sk_passive_connected(sock *s, int type)