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 */
flow_num_op:
TRUE { $$ = 0b000; }
| '=' { $$ = 0b001; }
| NEQ { $$ = 0b110; }
| '<' { $$ = 0b100; }
| LEQ { $$ = 0b101; }
| '>' { $$ = 0b010; }
| GEQ { $$ = 0b011; }
| FALSE { $$ = 0b111; }
TRUE { $$ = FLOW_OP_TRUE; }
| '=' { $$ = FLOW_OP_EQ; }
| NEQ { $$ = FLOW_OP_NEQ; }
| '<' { $$ = FLOW_OP_LT; }
| LEQ { $$ = FLOW_OP_LEQ; }
| '>' { $$ = FLOW_OP_GT; }
| GEQ { $$ = FLOW_OP_GEQ; }
| FALSE { $$ = FLOW_OP_FALSE; }
;
flow_logic_op:
OR { $$ = 0x00; }
| AND { $$ = 0x40; }
OR { $$ = FLOW_OP_OR; }
| AND { $$ = FLOW_OP_AND; }
;
flow_num_type_:
@ -97,13 +97,13 @@ flow_num_opts:
flow_num_opt_ext_expr:
expr {
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 {
flow_check_cf_value_length(this_flow, $1);
flow_check_cf_value_length(this_flow, $3);
flow_builder_add_op_val(this_flow, 0b011, $1); /* >= */
flow_builder_add_op_val(this_flow, 0x40 | 0b101, $3); /* AND <= */
flow_builder_add_op_val(this_flow, FLOW_OP_GEQ, $1);
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)
{
flow_builder_add_op_val(fb, op ^ 0x01, a);
op |= 0x40;
op |= FLOW_OP_AND;
}
if (b)
@ -897,28 +897,20 @@ flow_builder_clear(struct flow_builder *fb)
*/
/* 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 *
num_op_str(const byte *op)
{
switch (*op & 0x07)
{
case FLOW_TRUE: return "true";
case FLOW_EQ: return "=";
case FLOW_GT: return ">";
case FLOW_GTE: return ">=";
case FLOW_LT: return "<";
case FLOW_LTE: return "<=";
case FLOW_NEQ: return "!=";
case FLOW_FALSE: return "false";
case FLOW_OP_TRUE: return "true";
case FLOW_OP_EQ: return "=";
case FLOW_OP_GT: return ">";
case FLOW_OP_GEQ: return ">=";
case FLOW_OP_LT: return "<";
case FLOW_OP_LEQ: return "<=";
case FLOW_OP_NEQ: return "!=";
case FLOW_OP_FALSE: return "false";
}
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 */
if (!isset_and(op) &&
((num_op( op) == FLOW_EQ) || (num_op( op) == FLOW_GTE)) &&
((num_op(last_op) == FLOW_EQ) || (num_op(last_op) == FLOW_LTE)))
((num_op( op) == FLOW_OP_EQ) || (num_op( op) == FLOW_OP_GEQ)) &&
((num_op(last_op) == FLOW_OP_EQ) || (num_op(last_op) == FLOW_OP_LEQ)))
{
b->pos--; /* Remove last char (it is a space) */
buffer_puts(b, ",");
@ -1002,7 +994,7 @@ net_format_flow_num(buffer *b, const byte *part)
val = get_value(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 */
buffer_print(b, "%u..", val);
@ -1011,7 +1003,7 @@ net_format_flow_num(buffer *b, const byte *part)
val = get_value(op+1, len);
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);
}

View file

@ -14,6 +14,20 @@
#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 */
enum flow_type {
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 char *proto_state_name(struct proto *p);
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)

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 */
u32 csn = ntohl(auth->csn);
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))))
{
/* 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 */
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;
/* 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);
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;
if (new->check_link != old->check_link)

View file

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

View file

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