From 66dbdbd993115c57acafdb776d2165d0b4a90a45 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Sat, 1 Oct 2016 12:50:29 +0200 Subject: BGP: Support for large communities Add support for large communities (draft-ietf-idr-large-community), 96bit alternative to RFC 1997 communities. Thanks to Matt Griswold for the original patch. --- filter/config.Y | 43 +++++++++++++- filter/filter.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- filter/filter.h | 18 +++++- filter/test.conf | 17 ++++++ 4 files changed, 243 insertions(+), 6 deletions(-) (limited to 'filter') diff --git a/filter/config.Y b/filter/config.Y index 9fffd651..79e274ab 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -36,6 +36,7 @@ f_valid_set_type(int type) case T_ENUM: case T_IP: case T_EC: + case T_LC: return 1; default: @@ -148,6 +149,9 @@ f_generate_empty(struct f_inst *dyn) case EAF_TYPE_EC_SET: e->aux = T_ECLIST; break; + case EAF_TYPE_LC_SET: + e->aux = T_LCLIST; + break; default: cf_error("Can't empty that attribute"); } @@ -268,14 +272,44 @@ f_generate_ec(u16 kind, struct f_inst *tk, struct f_inst *tv) return rv; } +static inline struct f_inst * +f_generate_lc(struct f_inst *t1, struct f_inst *t2, struct f_inst *t3) +{ + struct f_inst *rv; + + if ((t1->code == 'c') && (t2->code == 'c') && (t3->code == 'c')) { + if ((t1->aux != T_INT) || (t2->aux != T_INT) || (t3->aux != T_INT)) + cf_error( "LC - Can't operate with value of non-integer type in tuple constructor"); + + rv = f_new_inst(); + rv->code = 'C'; + + NEW_F_VAL; + rv->a1.p = val; + val->type = T_LC; + val->val.lc = (lcomm) { t1->a2.i, t2->a2.i, t3->a2.i }; + } + else + { + rv = cfg_allocz(sizeof(struct f_inst3)); + rv->lineno = ifs->lino; + rv->code = P('m','l'); + rv->a1.p = t1; + rv->a2.p = t2; + INST3(rv).p = t3; + } + + return rv; +} + CF_DECLS CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, ACCEPT, REJECT, ERROR, QUITBIRD, - INT, BOOL, IP, PREFIX, PAIR, QUAD, EC, - SET, STRING, BGPMASK, BGPPATH, CLIST, ECLIST, + INT, BOOL, IP, PREFIX, PAIR, QUAD, EC, LC, + SET, STRING, BGPMASK, BGPPATH, CLIST, ECLIST, LCLIST, IF, THEN, ELSE, CASE, TRUE, FALSE, RT, RO, UNKNOWN, GENERIC, FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, CAST, DEST, IFNAME, IFINDEX, @@ -327,17 +361,20 @@ type: | PAIR { $$ = T_PAIR; } | QUAD { $$ = T_QUAD; } | EC { $$ = T_EC; } + | LC { $$ = T_LC; } | STRING { $$ = T_STRING; } | BGPMASK { $$ = T_PATH_MASK; } | BGPPATH { $$ = T_PATH; } | CLIST { $$ = T_CLIST; } | ECLIST { $$ = T_ECLIST; } + | LCLIST { $$ = T_LCLIST; } | type SET { switch ($1) { case T_INT: case T_PAIR: case T_QUAD: case T_EC: + case T_LC: case T_IP: $$ = T_SET; break; @@ -657,6 +694,7 @@ constant: constructor: '(' term ',' term ')' { $$ = f_generate_dpair($2, $4); } | '(' ec_kind ',' term ',' term ')' { $$ = f_generate_ec($2, $4, $6); } + | '(' term ',' term ',' term ')' { $$ = f_generate_lc($2, $4, $6); } ; @@ -767,6 +805,7 @@ term: | '+' EMPTY '+' { $$ = f_new_inst(); $$->code = 'E'; $$->aux = T_PATH; } | '-' EMPTY '-' { $$ = f_new_inst(); $$->code = 'E'; $$->aux = T_CLIST; } | '-' '-' EMPTY '-' '-' { $$ = f_new_inst(); $$->code = 'E'; $$->aux = T_ECLIST; } + | '-' '-' '-' EMPTY '-' '-' '-' { $$ = f_new_inst(); $$->code = 'E'; $$->aux = T_LCLIST; } | PREPEND '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('A','p'); $$->a1.p = $3; $$->a2.p = $5; } | ADD '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('C','a'); $$->a1.p = $3; $$->a2.p = $5; $$->aux = 'a'; } | DELETE '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('C','a'); $$->a1.p = $3; $$->a2.p = $5; $$->aux = 'd'; } diff --git a/filter/filter.c b/filter/filter.c index 2f5f00d8..510303a7 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -106,6 +106,18 @@ u64_cmp(u64 i1, u64 i2) return (int)(i1 > i2) - (int)(i1 < i2); } +static inline int +lcomm_cmp(lcomm v1, lcomm v2) +{ + if (v1.asn != v2.asn) + return (v1.asn > v2.asn) ? 1 : -1; + if (v1.ldp1 != v2.ldp1) + return (v1.ldp1 > v2.ldp1) ? 1 : -1; + if (v1.ldp2 != v2.ldp2) + return (v1.ldp2 > v2.ldp2) ? 1 : -1; + return 0; +} + /** * val_compare - compare two values * @v1: first value @@ -149,6 +161,8 @@ val_compare(struct f_val v1, struct f_val v2) return uint_cmp(v1.val.i, v2.val.i); case T_EC: return u64_cmp(v1.val.ec, v2.val.ec); + case T_LC: + return lcomm_cmp(v1.val.lc, v2.val.lc); case T_IP: return ipa_compare(v1.val.px.ip, v2.val.px.ip); case T_PREFIX: @@ -214,6 +228,7 @@ val_same(struct f_val v1, struct f_val v2) case T_PATH: case T_CLIST: case T_ECLIST: + case T_LCLIST: return adata_same(v1.val.ad, v2.val.ad); case T_SET: return same_tree(v1.val.t, v2.val.t); @@ -266,6 +281,10 @@ static inline int eclist_set_type(struct f_tree *set) { return set->from.type == T_EC; } +static inline int +lclist_set_type(struct f_tree *set) +{ return set->from.type == T_LC; } + static int clist_match_set(struct adata *clist, struct f_tree *set) { @@ -311,6 +330,30 @@ eclist_match_set(struct adata *list, struct f_tree *set) return 0; } +static int +lclist_match_set(struct adata *list, struct f_tree *set) +{ + if (!list) + return 0; + + if (!lclist_set_type(set)) + return CMP_ERROR; + + struct f_val v; + u32 *l = int_set_get_data(list); + int len = int_set_get_size(list); + int i; + + v.type = T_LC; + for (i = 0; i < len; i += 3) { + v.val.lc = lc_get(l, i); + if (find_tree(set, v)) + return 1; + } + + return 0; +} + static struct adata * clist_filter(struct linpool *pool, struct adata *list, struct f_val set, int pos) { @@ -380,6 +423,38 @@ eclist_filter(struct linpool *pool, struct adata *list, struct f_val set, int po return res; } +static struct adata * +lclist_filter(struct linpool *pool, struct adata *list, struct f_val set, int pos) +{ + if (!list) + return NULL; + + int tree = (set.type == T_SET); /* 1 -> set is T_SET, 0 -> set is T_CLIST */ + struct f_val v; + + int len = int_set_get_size(list); + u32 *l = int_set_get_data(list); + u32 tmp[len]; + u32 *k = tmp; + int i; + + v.type = T_LC; + for (i = 0; i < len; i += 3) { + v.val.lc = lc_get(l, i); + /* pos && member(val, set) || !pos && !member(val, set), member() depends on tree */ + if ((tree ? !!find_tree(set.val.t, v) : lc_set_contains(set.val.ad, v.val.lc)) == pos) + k = lc_copy(k, l+i); + } + + int nl = (k - tmp) * 4; + if (nl == list->length) + return list; + + struct adata *res = adata_empty(pool, nl); + memcpy(res->data, tmp, nl); + return res; +} + /** * val_in_range - implement |~| operator * @v1: element @@ -407,6 +482,9 @@ val_in_range(struct f_val v1, struct f_val v2) if ((v1.type == T_EC) && (v2.type == T_ECLIST)) return ec_set_contains(v2.val.ad, v1.val.ec); + if ((v1.type == T_LC) && (v2.type == T_LCLIST)) + return lc_set_contains(v2.val.ad, v1.val.lc); + if ((v1.type == T_STRING) && (v2.type == T_STRING)) return patmatch(v2.val.s, v1.val.s); @@ -433,6 +511,9 @@ val_in_range(struct f_val v1, struct f_val v2) if (v1.type == T_ECLIST) return eclist_match_set(v1.val.ad, v2.val.t); + if (v1.type == T_LCLIST) + return lclist_match_set(v1.val.ad, v2.val.t); + if (v1.type == T_PATH) return as_path_match_set(v1.val.ad, v2.val.t); @@ -457,12 +538,14 @@ val_format(struct f_val v, buffer *buf) case T_PAIR: buffer_print(buf, "(%u,%u)", v.val.i >> 16, v.val.i & 0xffff); return; case T_QUAD: buffer_print(buf, "%R", v.val.i); return; case T_EC: ec_format(buf2, v.val.ec); buffer_print(buf, "%s", buf2); return; + case T_LC: lc_format(buf2, v.val.lc); buffer_print(buf, "%s", buf2); return; case T_PREFIX_SET: trie_format(v.val.ti, buf); return; case T_SET: tree_format(v.val.t, buf); return; case T_ENUM: buffer_print(buf, "(enum %x)%u", v.type, v.val.i); return; case T_PATH: as_path_format(v.val.ad, buf2, 1000); buffer_print(buf, "(path %s)", buf2); return; case T_CLIST: int_set_format(v.val.ad, 1, -1, buf2, 1000); buffer_print(buf, "(clist %s)", buf2); return; case T_ECLIST: ec_set_format(v.val.ad, -1, buf2, 1000); buffer_print(buf, "(eclist %s)", buf2); return; + case T_LCLIST: lc_set_format(v.val.ad, -1, buf2, 1000); buffer_print(buf, "(lclist %s)", buf2); return; case T_PATH_MASK: pm_format(v.val.path_mask, buf); return; default: buffer_print(buf, "[unknown type %x]", v.type); return; } @@ -656,6 +739,7 @@ interpret(struct f_inst *what) runtime("Can't operate with value of non-integer type in EC constructor"); val = v2.val.i; + /* XXXX */ res.type = T_EC; if (what->aux == EC_GENERIC) { @@ -677,6 +761,24 @@ interpret(struct f_inst *what) break; } + case P('m','l'): + { + TWOARGS; + + /* Third argument hack */ + struct f_val v3 = interpret(INST3(what).p); + if (v3.type & T_RETURN) + return v3; + + if ((v1.type != T_INT) || (v2.type != T_INT) || (v3.type != T_INT)) + runtime( "Can't operate with value of non-integer type in LC constructor" ); + + res.type = T_LC; + res.val.lc = (lcomm) { v1.val.i, v2.val.i, v3.val.i }; + + break; + } + /* Relational operators */ #define COMPARE(x) \ @@ -912,6 +1014,13 @@ interpret(struct f_inst *what) break; } + /* The same special case for lc_set */ + if ((what->aux & EAF_TYPE_MASK) == EAF_TYPE_LC_SET) { + res.type = T_LCLIST; + res.val.ad = adata_empty(f_pool, 0); + break; + } + /* Undefined value */ res.type = T_VOID; break; @@ -951,6 +1060,10 @@ interpret(struct f_inst *what) res.type = T_ECLIST; res.val.ad = e->u.ptr; break; + case EAF_TYPE_LC_SET: + res.type = T_LCLIST; + res.val.ad = e->u.ptr; + break; case EAF_TYPE_UNDEF: res.type = T_VOID; break; @@ -1041,6 +1154,11 @@ interpret(struct f_inst *what) runtime( "Setting eclist attribute to non-eclist value" ); l->attrs[0].u.ptr = v1.val.ad; break; + case EAF_TYPE_LC_SET: + if (v1.type != T_LCLIST) + runtime( "Setting lclist attribute to non-lclist value" ); + l->attrs[0].u.ptr = v1.val.ad; + break; case EAF_TYPE_UNDEF: if (v1.type != T_VOID) runtime( "Setting void attribute to non-void value" ); @@ -1082,6 +1200,7 @@ interpret(struct f_inst *what) case T_PATH: res.val.i = as_path_getlen(v1.val.ad); break; case T_CLIST: res.val.i = int_set_get_size(v1.val.ad); break; case T_ECLIST: res.val.i = ec_set_get_size(v1.val.ad); break; + case T_LCLIST: res.val.i = lc_set_get_size(v1.val.ad); break; default: runtime( "Prefix, path, clist or eclist expected" ); } break; @@ -1277,7 +1396,7 @@ interpret(struct f_inst *what) else if (v2.type == T_ECLIST) arg_set = 2; else if (v2.type != T_EC) - runtime("Can't add/delete non-pair"); + runtime("Can't add/delete non-ec"); res.type = T_ECLIST; switch (what->aux) @@ -1308,8 +1427,50 @@ interpret(struct f_inst *what) bug("unknown Ca operation"); } } + else if (v1.type == T_LCLIST) + { + /* Large community list */ + int arg_set = 0; + + /* v2.val is either LC or LC-set */ + if ((v2.type == T_SET) && lclist_set_type(v2.val.t)) + arg_set = 1; + else if (v2.type == T_LCLIST) + arg_set = 2; + else if (v2.type != T_LC) + runtime("Can't add/delete non-lc"); + + res.type = T_LCLIST; + switch (what->aux) + { + case 'a': + if (arg_set == 1) + runtime("Can't add set"); + else if (!arg_set) + res.val.ad = lc_set_add(f_pool, v1.val.ad, v2.val.lc); + else + res.val.ad = lc_set_union(f_pool, v1.val.ad, v2.val.ad); + break; + + case 'd': + if (!arg_set) + res.val.ad = lc_set_del(f_pool, v1.val.ad, v2.val.lc); + else + res.val.ad = lclist_filter(f_pool, v1.val.ad, v2, 0); + break; + + case 'f': + if (!arg_set) + runtime("Can't filter lc"); + res.val.ad = lclist_filter(f_pool, v1.val.ad, v2, 1); + break; + + default: + bug("unknown Ca operation"); + } + } else - runtime("Can't add/delete to non-(e)clist"); + runtime("Can't add/delete to non-[e|l]clist"); break; @@ -1401,6 +1562,12 @@ i_same(struct f_inst *f1, struct f_inst *f2) case '~': TWOARGS; break; case P('d','e'): ONEARG; break; + case P('m','l'): + TWOARGS; + if (!i_same(INST3(f1).p, INST3(f2).p)) + return 0; + break; + case 's': ARG(v2, a2.p); { diff --git a/filter/filter.h b/filter/filter.h index e59c8226..e0f34e4f 100644 --- a/filter/filter.h +++ b/filter/filter.h @@ -38,6 +38,17 @@ struct f_inst_roa_check { struct roa_table_config *rtc; }; +struct f_inst3 { + struct f_inst i; + union { + int i; + void *p; + } a3; +}; + +#define INST3(x) (((struct f_inst3 *) x)->a3) + + struct f_prefix { ip_addr ip; int len; @@ -53,6 +64,7 @@ struct f_val { union { uint i; u64 ec; + lcomm lc; /* ip_addr ip; Folded into prefix */ struct f_prefix px; char *s; @@ -168,8 +180,10 @@ void val_format(struct f_val v, buffer *buf); #define T_PATH_MASK 0x23 /* mask for BGP path */ #define T_PATH 0x24 /* BGP path */ #define T_CLIST 0x25 /* Community list */ -#define T_ECLIST 0x26 /* Extended community list */ -#define T_EC 0x27 /* Extended community value, u64 */ +#define T_EC 0x26 /* Extended community value, u64 */ +#define T_ECLIST 0x27 /* Extended community list */ +#define T_LC 0x28 /* Large community value, lcomm */ +#define T_LCLIST 0x29 /* Large community list */ #define T_RETURN 0x40 #define T_SET 0x80 diff --git a/filter/test.conf b/filter/test.conf index f61f0658..e8873fbf 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -27,6 +27,11 @@ function 'mkpair-a'(int a) return (1, a); } +function mktrip(int a) +{ + return (a, 2*a, 3*a); +} + function mkpath(int a; int b) { return [= a b 3 2 1 =]; @@ -89,6 +94,7 @@ clist l; clist l2; eclist el; eclist el2; +lclist ll; { print "Entering path test..."; pm1 = / 4 3 2 1 /; @@ -203,6 +209,17 @@ eclist el2; print "eclist A isect B: ", filter( el, el2 ); print "eclist A \ B: ", delete( el, el2 ); + ll = --- empty ---; + ll = add(ll, (ten, 20, 30)); + ll = add(ll, (1000, 2000, 3000)); + ll = add(ll, mktrip(100000)); + print "LC list (10, 20, 30) (1000, 2000, 3000) (100000, 200000, 300000):"; + print ll; + print "LC len: ", el.len; + print "Should be true: ", mktrip(1000) ~ ll, " ", ll ~ [(5,10,15), (10,20,30)], " ", ll ~ [(10,15..25,*)], " ", ll ~ [(ten, *, *)]; + print "Should be false: ", mktrip(100) ~ ll, " ", ll ~ [(5,10,15), (10,21,30)], " ", ll ~ [(10,21..25,*)], " ", ll ~ [(11, *, *)]; + print "LC filtered: ", filter(ll, [(5..15, *, *), (100000, 500..500000, *)]); + # test_roa(); } -- cgit v1.2.3 From 60566c5c804070c145fafd75ef2c17efb489a1eb Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Sat, 1 Oct 2016 22:31:01 +0200 Subject: Filter: large community sets Add support for lc sets to filter code. Grammar of (small) community sets has to be updated to avoid parser collisions. --- filter/config.Y | 94 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 32 deletions(-) (limited to 'filter') diff --git a/filter/config.Y b/filter/config.Y index 79e274ab..29e3a734 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -67,6 +67,14 @@ f_merge_items(struct f_tree *a, struct f_tree *b) static inline struct f_tree * f_new_pair_item(int fa, int ta, int fb, int tb) { + check_u16(fa); + check_u16(ta); + check_u16(fb); + check_u16(tb); + + if ((ta < fa) || (tb < fb)) + cf_error( "From value cannot be higher that To value in pair sets"); + struct f_tree *t = f_new_tree(); t->right = t; t->from.type = t->to.type = T_PAIR; @@ -78,22 +86,26 @@ f_new_pair_item(int fa, int ta, int fb, int tb) static inline struct f_tree * f_new_pair_set(int fa, int ta, int fb, int tb) { - struct f_tree *lst = NULL; - int i; + check_u16(fa); + check_u16(ta); + check_u16(fb); + check_u16(tb); - if ((fa == ta) || ((fb == 0) && (tb == 0xFFFF))) - return f_new_pair_item(fa, ta, fb, tb); - if ((ta < fa) || (tb < fb)) cf_error( "From value cannot be higher that To value in pair sets"); + struct f_tree *lst = NULL; + int i; + for (i = fa; i <= ta; i++) lst = f_merge_items(lst, f_new_pair_item(i, i, fb, tb)); return lst; } +#define CC_ALL 0xFFFF #define EC_ALL 0xFFFFFFFF +#define LC_ALL 0xFFFFFFFF static struct f_tree * f_new_ec_item(u32 kind, u32 ipv4_used, u32 key, u32 vf, u32 vt) @@ -133,6 +145,17 @@ f_new_ec_item(u32 kind, u32 ipv4_used, u32 key, u32 vf, u32 vt) return t; } +static struct f_tree * +f_new_lc_item(u32 f1, u32 t1, u32 f2, u32 t2, u32 f3, u32 t3) +{ + struct f_tree *t = f_new_tree(); + t->right = t; + t->from.type = t->to.type = T_LC; + t->from.val.lc = (lcomm) {f1, f2, f3}; + t->to.val.lc = (lcomm) {t1, t2, t3}; + return t; +} + static inline struct f_inst * f_generate_empty(struct f_inst *dyn) { @@ -327,9 +350,9 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, %type term block cmds cmds_int cmd function_body constant constructor print_one print_list var_list var_listn dynamic_attr static_attr function_call symbol bgp_path_expr %type filter filter_body where_filter -%type type break_command pair_expr ec_kind -%type pair_atom ec_expr -%type pair_item ec_item set_item switch_item set_items switch_items switch_body +%type type break_command ec_kind +%type cnum +%type pair_item ec_item lc_item set_item switch_item set_items switch_items switch_body %type fprefix_set %type set_atom switch_atom fprefix fprefix_s fipa %type decls declsn one_decl function_params @@ -550,30 +573,23 @@ switch_atom: | ENUM { $$.type = pair_a($1); $$.val.i = pair_b($1); } ; -pair_expr: - term { $$ = f_eval_int($1); check_u16($$); } - -pair_atom: - pair_expr { $$ = pair($1, $1); } - | pair_expr DDOT pair_expr { $$ = pair($1, $3); } - | '*' { $$ = 0xFFFF; } - ; +cnum: + term { $$ = f_eval_int($1); } pair_item: - '(' pair_atom ',' pair_atom ')' { - $$ = f_new_pair_set(pair_a($2), pair_b($2), pair_a($4), pair_b($4)); - } - | '(' pair_atom ',' pair_atom ')' DDOT '(' pair_expr ',' pair_expr ')' { - /* Hack: $2 and $4 should be pair_expr, but that would cause shift/reduce conflict */ - if ((pair_a($2) != pair_b($2)) || (pair_a($4) != pair_b($4))) - cf_error("syntax error"); - $$ = f_new_pair_item(pair_b($2), $8, pair_b($4), $10); - } + '(' cnum ',' cnum ')' { $$ = f_new_pair_item($2, $2, $4, $4); } + | '(' cnum ',' cnum DDOT cnum ')' { $$ = f_new_pair_item($2, $2, $4, $6); } + | '(' cnum ',' '*' ')' { $$ = f_new_pair_item($2, $2, 0, CC_ALL); } + | '(' cnum DDOT cnum ',' cnum ')' { $$ = f_new_pair_set($2, $4, $6, $6); } + | '(' cnum DDOT cnum ',' cnum DDOT cnum ')' { $$ = f_new_pair_set($2, $4, $6, $8); } + | '(' cnum DDOT cnum ',' '*' ')' { $$ = f_new_pair_item($2, $4, 0, CC_ALL); } + | '(' '*' ',' cnum ')' { $$ = f_new_pair_set(0, CC_ALL, $4, $4); } + | '(' '*' ',' cnum DDOT cnum ')' { $$ = f_new_pair_set(0, CC_ALL, $4, $6); } + | '(' '*' ',' '*' ')' { $$ = f_new_pair_item(0, CC_ALL, 0, CC_ALL); } + | '(' cnum ',' cnum ')' DDOT '(' cnum ',' cnum ')' + { $$ = f_new_pair_item($2, $8, $4, $10); } ; -ec_expr: - term { $$ = f_eval_int($1); } - ec_kind: RT { $$ = EC_RT; } | RO { $$ = EC_RO; } @@ -582,14 +598,27 @@ ec_kind: ; ec_item: - '(' ec_kind ',' ec_expr ',' ec_expr ')' { $$ = f_new_ec_item($2, 0, $4, $6, $6); } - | '(' ec_kind ',' ec_expr ',' ec_expr DDOT ec_expr ')' { $$ = f_new_ec_item($2, 0, $4, $6, $8); } - | '(' ec_kind ',' ec_expr ',' '*' ')' { $$ = f_new_ec_item($2, 0, $4, 0, EC_ALL); } - ; + '(' ec_kind ',' cnum ',' cnum ')' { $$ = f_new_ec_item($2, 0, $4, $6, $6); } + | '(' ec_kind ',' cnum ',' cnum DDOT cnum ')' { $$ = f_new_ec_item($2, 0, $4, $6, $8); } + | '(' ec_kind ',' cnum ',' '*' ')' { $$ = f_new_ec_item($2, 0, $4, 0, EC_ALL); } + ; + +lc_item: + '(' cnum ',' cnum ',' cnum ')' { $$ = f_new_lc_item($2, $2, $4, $4, $6, $6); } + | '(' cnum ',' cnum ',' cnum DDOT cnum ')' { $$ = f_new_lc_item($2, $2, $4, $4, $6, $8); } + | '(' cnum ',' cnum ',' '*' ')' { $$ = f_new_lc_item($2, $2, $4, $4, 0, LC_ALL); } + | '(' cnum ',' cnum DDOT cnum ',' '*' ')' { $$ = f_new_lc_item($2, $2, $4, $6, 0, LC_ALL); } + | '(' cnum ',' '*' ',' '*' ')' { $$ = f_new_lc_item($2, $2, 0, LC_ALL, 0, LC_ALL); } + | '(' cnum DDOT cnum ',' '*' ',' '*' ')' { $$ = f_new_lc_item($2, $4, 0, LC_ALL, 0, LC_ALL); } + | '(' '*' ',' '*' ',' '*' ')' { $$ = f_new_lc_item(0, LC_ALL, 0, LC_ALL, 0, LC_ALL); } + | '(' cnum ',' cnum ',' cnum ')' DDOT '(' cnum ',' cnum ',' cnum ')' + { $$ = f_new_lc_item($2, $10, $4, $12, $6, $14); } +; set_item: pair_item | ec_item + | lc_item | set_atom { $$ = f_new_item($1, $1); } | set_atom DDOT set_atom { $$ = f_new_item($1, $3); } ; @@ -597,6 +626,7 @@ set_item: switch_item: pair_item | ec_item + | lc_item | switch_atom { $$ = f_new_item($1, $1); } | switch_atom DDOT switch_atom { $$ = f_new_item($1, $3); } ; -- cgit v1.2.3 From a998836d4bd4df8820e67f51e16d81a5a8dc9e9b Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 4 Oct 2016 23:19:35 +0200 Subject: Filter: fix missing separator --- filter/trie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'filter') diff --git a/filter/trie.c b/filter/trie.c index 8af9015e..fba395d1 100644 --- a/filter/trie.c +++ b/filter/trie.c @@ -297,7 +297,7 @@ trie_format(struct f_trie *t, buffer *buf) buffer_puts(buf, "["); if (t->zero) - buffer_print(buf, "%I/%d", IPA_NONE, 0); + buffer_print(buf, "%I/%d, ", IPA_NONE, 0); trie_node_format(t->root, buf); /* Undo last separator */ -- cgit v1.2.3 From c2564d34af9e01a828c24b0be7f269e5b036b5da Mon Sep 17 00:00:00 2001 From: Pavel Tvrdik Date: Sat, 1 Oct 2016 12:50:29 +0200 Subject: Tree/Trie: Check the end of buffer We set buffer->pos to buffer->end in function buffer_print() when bvsnprintf() failed, so there would be uninitialized memory between the old buffer->pos and the current buffer->pos. --- filter/tree.c | 3 +++ filter/trie.c | 3 +++ 2 files changed, 6 insertions(+) (limited to 'filter') diff --git a/filter/tree.c b/filter/tree.c index 328c7184..1196e630 100644 --- a/filter/tree.c +++ b/filter/tree.c @@ -165,6 +165,9 @@ tree_format(struct f_tree *t, buffer *buf) tree_node_format(t, buf); + if (buf->pos == buf->end) + return; + /* Undo last separator */ if (buf->pos[-1] != '[') buf->pos -= 2; diff --git a/filter/trie.c b/filter/trie.c index fba395d1..565ae82f 100644 --- a/filter/trie.c +++ b/filter/trie.c @@ -300,6 +300,9 @@ trie_format(struct f_trie *t, buffer *buf) buffer_print(buf, "%I/%d, ", IPA_NONE, 0); trie_node_format(t->root, buf); + if (buf->pos == buf->end) + return; + /* Undo last separator */ if (buf->pos[-1] != '[') buf->pos -= 2; -- cgit v1.2.3 From 5fd7dacadc3cd8f91f66cb56e3a9ef81028aa102 Mon Sep 17 00:00:00 2001 From: Pavel Tvrdik Date: Thu, 13 Oct 2016 15:17:41 +0200 Subject: Filter: Expand testing of large community sets --- filter/test.conf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'filter') diff --git a/filter/test.conf b/filter/test.conf index e8873fbf..7623953a 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -95,6 +95,7 @@ clist l2; eclist el; eclist el2; lclist ll; +lclist ll2; { print "Entering path test..."; pm1 = / 4 3 2 1 /; @@ -220,6 +221,22 @@ lclist ll; print "Should be false: ", mktrip(100) ~ ll, " ", ll ~ [(5,10,15), (10,21,30)], " ", ll ~ [(10,21..25,*)], " ", ll ~ [(11, *, *)]; print "LC filtered: ", filter(ll, [(5..15, *, *), (100000, 500..500000, *)]); + ll = --- empty ---; + ll = add(ll, (10, 10, 10)); + ll = add(ll, (20, 20, 20)); + ll = add(ll, (30, 30, 30)); + + ll2 = --- empty ---; + ll2 = add(ll2, (20, 20, 20)); + ll2 = add(ll2, (30, 30, 30)); + ll2 = add(ll2, (40, 40, 40)); + + print "lclist A (10,20,30): ", ll; + print "lclist B (30,40,50): ", ll2; + print "lclist A union B: ", add(ll, ll2); + print "lclist A isect B: ", filter(ll, ll2); + print "lclist A \ B: ", delete(ll, ll2); + # test_roa(); } -- cgit v1.2.3 From c68e8cd374f16a1d659c80f9ebe503f2dd0d4acb Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 18 Oct 2016 13:06:05 +0200 Subject: Filter: Minor formatting changes in test.conf --- filter/test.conf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'filter') diff --git a/filter/test.conf b/filter/test.conf index 7623953a..676b47d1 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -161,7 +161,7 @@ lclist ll2; print "Community list (1,2) (3,1) (3,5) ", l, " len: ", l.len; l = add( l, (3,2) ); l = add( l, (4,5) ); - print "Community list (1,2) (3,1) (3,2) (3,5) (4,5) ", l, " len: ", l.len; + print "Community list (1,2) (3,1) (3,5) (3,2) (4,5) ", l, " len: ", l.len; print "Should be true: ", l ~ [(*,2)], " ", l ~ [(*,5)], " ", l ~ [(*, one)]; print "Should be false: ", l ~ [(*,3)], " ", l ~ [(*,(one+6))], " ", l ~ [(*, (one+one+one))]; l = delete( l, [(*,(one+onef(3)))] ); @@ -176,7 +176,7 @@ lclist ll2; print "clist B (3..6): ", l2; print "clist A union B: ", add( l2, l ); print "clist A isect B: ", filter( l, l2 ); - print "clist A \ B: ", delete( l, l2 ); + print "clist A \ B: ", delete( l, l2 ); el = -- empty --; el = add(el, (rt, 10, 20)); @@ -208,7 +208,7 @@ lclist ll2; print "eclist B (30,40,50): ", el2; print "eclist A union B: ", add( el2, el ); print "eclist A isect B: ", filter( el, el2 ); - print "eclist A \ B: ", delete( el, el2 ); + print "eclist A \ B: ", delete( el, el2 ); ll = --- empty ---; ll = add(ll, (ten, 20, 30)); @@ -232,10 +232,10 @@ lclist ll2; ll2 = add(ll2, (40, 40, 40)); print "lclist A (10,20,30): ", ll; - print "lclist B (30,40,50): ", ll2; + print "lclist B (20,30,40): ", ll2; print "lclist A union B: ", add(ll, ll2); print "lclist A isect B: ", filter(ll, ll2); - print "lclist A \ B: ", delete(ll, ll2); + print "lclist A \ B: ", delete(ll, ll2); # test_roa(); } -- cgit v1.2.3 From 3e236955c9369475872b9b86a58502fa777b50b9 Mon Sep 17 00:00:00 2001 From: Jan Moskyto Matejka Date: Fri, 14 Oct 2016 15:37:04 +0200 Subject: Build: switch on -Wextra, get rid of most of the warnings There are several unresolved -Wmissing-field-initializers on older versions of GCC than 5.1, all of them false positive. --- client/birdcl.c | 2 +- client/util.c | 2 +- conf/Makefile | 2 ++ conf/conf.c | 2 +- configure.in | 4 ++- filter/filter.c | 6 ++-- lib/birdlib.h | 7 +++++ lib/hash.h | 8 ++--- lib/socket.h | 2 +- nest/a-path.c | 2 +- nest/bfd.h | 2 +- nest/iface.c | 2 +- nest/locks.c | 3 +- nest/route.h | 1 - nest/rt-attr.c | 4 +-- nest/rt-table.c | 18 +++++------ proto/babel/babel.c | 4 +-- proto/babel/babel.h | 2 +- proto/babel/packets.c | 84 ++++++++++++++++++++++++++------------------------ proto/bfd/bfd.c | 6 ++-- proto/bfd/packets.c | 4 +-- proto/bgp/attrs.c | 2 +- proto/bgp/bgp.c | 2 +- proto/bgp/bgp.h | 4 +-- proto/bgp/packets.c | 29 +++++++++-------- proto/ospf/dbdes.c | 2 +- proto/ospf/hello.c | 5 ++- proto/ospf/lsalib.c | 2 +- proto/ospf/lsalib.h | 2 +- proto/ospf/lsupd.c | 6 ++-- proto/ospf/neighbor.c | 2 +- proto/ospf/ospf.h | 8 ++--- proto/ospf/packet.c | 4 +-- proto/ospf/rt.c | 2 +- proto/ospf/topology.c | 8 ++--- proto/radv/packets.c | 6 ++-- proto/radv/radv.c | 2 +- proto/radv/radv.h | 2 +- proto/rip/packets.c | 8 ++--- proto/rip/rip.c | 4 +-- proto/static/static.c | 4 +-- sysdep/bsd/krt-sock.c | 6 ++-- sysdep/bsd/krt-sys.h | 2 +- sysdep/bsd/sysio.h | 19 +++++++----- sysdep/linux/krt-sys.h | 2 +- sysdep/linux/netlink.c | 4 +-- sysdep/unix/io.c | 12 ++++---- sysdep/unix/krt.c | 4 +-- sysdep/unix/main.c | 6 ++-- sysdep/unix/unix.h | 10 +++--- 50 files changed, 179 insertions(+), 157 deletions(-) (limited to 'filter') diff --git a/client/birdcl.c b/client/birdcl.c index 7b567a9f..4508185c 100644 --- a/client/birdcl.c +++ b/client/birdcl.c @@ -125,7 +125,7 @@ more_end(void) } static void -sig_handler(int signal) +sig_handler(int signal UNUSED) { cleanup(); exit(0); diff --git a/client/util.c b/client/util.c index 2d6c074d..1d83e518 100644 --- a/client/util.c +++ b/client/util.c @@ -24,7 +24,7 @@ vlog(const char *msg, va_list args) int n = vsnprintf(buf, sizeof(buf), msg, args); if (n < 0) snprintf(buf, sizeof(buf), "???"); - if (n >= sizeof(buf)) + else if (n >= (int) sizeof(buf)) snprintf(buf + sizeof(buf) - 100, 100, " ... "); fputs(buf, stderr); fputc('\n', stderr); diff --git a/conf/Makefile b/conf/Makefile index 5d729a42..cd78c821 100644 --- a/conf/Makefile +++ b/conf/Makefile @@ -29,3 +29,5 @@ cf-lex.c: cf-lex.l $(FLEX) $(FLEX_DEBUG) -s -B -8 -ocf-lex.c -Pcf_ cf-lex.l depend: keywords.h commands.h cf-parse.tab.c cf-lex.c + +cf-lex.o: CFLAGS+=-Wno-sign-compare -Wno-unused-function diff --git a/conf/conf.c b/conf/conf.c index efaeedeb..029814c6 100644 --- a/conf/conf.c +++ b/conf/conf.c @@ -450,7 +450,7 @@ config_undo(void) extern void cmd_reconfig_undo_notify(void); static void -config_timeout(struct timer *t) +config_timeout(struct timer *t UNUSED) { log(L_INFO "Config timeout expired, starting undo"); cmd_reconfig_undo_notify(); diff --git a/configure.in b/configure.in index 16a0b414..57fa0079 100644 --- a/configure.in +++ b/configure.in @@ -111,11 +111,13 @@ fi if test "$bird_cflags_default" = yes ; then BIRD_CHECK_GCC_OPTION(bird_cv_c_option_wno_pointer_sign, -Wno-pointer-sign, -Wall) + BIRD_CHECK_GCC_OPTION(bird_cv_c_option_wno_missing_init, -Wno-missing-field-initializers, -Wall -Wextra) BIRD_CHECK_GCC_OPTION(bird_cv_c_option_fno_strict_aliasing, -fno-strict-aliasing) BIRD_CHECK_GCC_OPTION(bird_cv_c_option_fno_strict_overflow, -fno-strict-overflow) - CFLAGS="$CFLAGS -Wall -Wstrict-prototypes -Wno-parentheses" + CFLAGS="$CFLAGS -Wall -Wextra -Wstrict-prototypes -Wno-parentheses" BIRD_ADD_GCC_OPTION(bird_cv_c_option_wno_pointer_sign, -Wno-pointer-sign) + BIRD_ADD_GCC_OPTION(bird_cv_c_option_wno_missing_init, -Wno-missing-field-initializers) BIRD_ADD_GCC_OPTION(bird_cv_c_option_fno_strict_aliasing, -fno-strict-aliasing) BIRD_ADD_GCC_OPTION(bird_cv_c_option_fno_strict_overflow, -fno-strict-overflow) fi diff --git a/filter/filter.c b/filter/filter.c index 510303a7..85a06258 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -380,7 +380,7 @@ clist_filter(struct linpool *pool, struct adata *list, struct f_val set, int pos *k++ = v.val.i; } - int nl = (k - tmp) * 4; + uint nl = (k - tmp) * sizeof(u32); if (nl == list->length) return list; @@ -414,7 +414,7 @@ eclist_filter(struct linpool *pool, struct adata *list, struct f_val set, int po } } - int nl = (k - tmp) * 4; + uint nl = (k - tmp) * sizeof(u32); if (nl == list->length) return list; @@ -446,7 +446,7 @@ lclist_filter(struct linpool *pool, struct adata *list, struct f_val set, int po k = lc_copy(k, l+i); } - int nl = (k - tmp) * 4; + uint nl = (k - tmp) * sizeof(u32); if (nl == list->length) return list; diff --git a/lib/birdlib.h b/lib/birdlib.h index 904544cb..37337078 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -62,6 +62,13 @@ #define UNUSED __attribute__((unused)) #define PACKED __attribute__((packed)) +#ifdef IPV6 +#define UNUSED4 +#define UNUSED6 UNUSED +#else +#define UNUSED4 UNUSED +#define UNUSED6 +#endif /* Microsecond time */ diff --git a/lib/hash.h b/lib/hash.h index a73f647a..fc5fea14 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -2,7 +2,7 @@ #define HASH(type) struct { type **data; uint count, order; } #define HASH_TYPE(v) typeof(** (v).data) -#define HASH_SIZE(v) (1 << (v).order) +#define HASH_SIZE(v) (1U << (v).order) #define HASH_EQ(v,id,k1,k2...) (id##_EQ(k1, k2)) #define HASH_FN(v,id,key...) ((u32) (id##_FN(key)) >> (32 - (v).order)) @@ -116,12 +116,12 @@ #define HASH_MAY_RESIZE_DOWN_(v,pool,rehash_fn,args) \ ({ \ - int _o = (v).order; \ - while (((v).count < ((1 << _o) REHASH_LO_MARK(args))) && \ + uint _o = (v).order; \ + while (((v).count < ((1U << _o) REHASH_LO_MARK(args))) && \ (_o > (REHASH_LO_BOUND(args)))) \ _o -= (REHASH_LO_STEP(args)); \ if (_o < (v).order) \ - rehash_fn(&(v), pool, _o - (int) (v).order); \ + rehash_fn(&(v), pool, _o - (v).order); \ }) diff --git a/lib/socket.h b/lib/socket.h index 6babfa7b..2da52127 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -30,7 +30,7 @@ typedef struct birdsock { byte *rbuf, *rpos; /* NULL=allocate automatically */ uint fast_rx; /* RX has higher priority in event loop */ uint rbsize; - int (*rx_hook)(struct birdsock *, int size); /* NULL=receiving turned off, returns 1 to clear rx buffer */ + int (*rx_hook)(struct birdsock *, uint size); /* NULL=receiving turned off, returns 1 to clear rx buffer */ byte *tbuf, *tpos; /* NULL=allocate automatically */ byte *ttx; /* Internal */ diff --git a/nest/a-path.c b/nest/a-path.c index e1031b7b..b453f702 100644 --- a/nest/a-path.c +++ b/nest/a-path.c @@ -370,7 +370,7 @@ as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 } } - int nl = d - buf; + uint nl = d - buf; if (nl == path->length) return path; diff --git a/nest/bfd.h b/nest/bfd.h index f1e95cb2..b0ebe31d 100644 --- a/nest/bfd.h +++ b/nest/bfd.h @@ -42,7 +42,7 @@ struct bfd_request { struct bfd_request * bfd_request_session(pool *p, ip_addr addr, ip_addr local, struct iface *iface, void (*hook)(struct bfd_request *), void *data); -static inline void cf_check_bfd(int use) { } +static inline void cf_check_bfd(int use UNUSED) { } #else diff --git a/nest/iface.c b/nest/iface.c index 4d73c2a4..a23cdf4f 100644 --- a/nest/iface.c +++ b/nest/iface.c @@ -584,7 +584,7 @@ ifa_delete(struct ifa *a) } u32 -if_choose_router_id(struct iface_patt *mask, u32 old_id) +if_choose_router_id(struct iface_patt *mask UNUSED6, u32 old_id UNUSED6) { #ifndef IPV6 struct iface *i; diff --git a/nest/locks.c b/nest/locks.c index ad2af493..84b8b0ae 100644 --- a/nest/locks.c +++ b/nest/locks.c @@ -100,7 +100,8 @@ static struct resclass olock_class = { sizeof(struct object_lock), olock_free, olock_dump, - NULL + NULL, + NULL, }; /** diff --git a/nest/route.h b/nest/route.h index 07320566..383f4def 100644 --- a/nest/route.h +++ b/nest/route.h @@ -274,7 +274,6 @@ rte *rte_find(net *net, struct rte_src *src); rte *rte_get_temp(struct rta *); void rte_update2(struct announce_hook *ah, net *net, rte *new, struct rte_src *src); static inline void rte_update(struct proto *p, net *net, rte *new) { rte_update2(p->main_ahook, net, new, p->main_source); } -void rte_discard(rtable *tab, rte *old); int rt_examine(rtable *t, ip_addr prefix, int pxlen, struct proto *p, struct filter *filter); rte *rt_export_merged(struct announce_hook *ah, net *net, rte **rt_free, struct ea_list **tmpa, linpool *pool, int silent); void rt_refresh_begin(rtable *t, struct announce_hook *ah); diff --git a/nest/rt-attr.c b/nest/rt-attr.c index 9aeca846..edf27d44 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -103,7 +103,7 @@ static inline int u32_cto(uint x) { return ffs(~x) - 1; } static inline u32 rte_src_alloc_id(void) { - int i, j; + uint i, j; for (i = src_id_pos; i < src_id_size; i++) if (src_ids[i] != 0xffffffff) goto found; @@ -785,7 +785,7 @@ static inline void opaque_format(struct adata *ad, byte *buf, uint size) { byte *bound = buf + size - 10; - int i; + uint i; for(i = 0; i < ad->length; i++) { diff --git a/nest/rt-table.c b/nest/rt-table.c index 00476069..c6e48c38 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -1282,8 +1282,8 @@ rte_announce_i(rtable *tab, unsigned type, net *net, rte *new, rte *old, rte_update_unlock(); } -void -rte_discard(rtable *t, rte *old) /* Non-filtered route deletion, used during garbage collection */ +static inline void +rte_discard(rte *old) /* Non-filtered route deletion, used during garbage collection */ { rte_update_lock(); rte_recalculate(old->sender, old->net, NULL, old->attrs->src); @@ -1606,7 +1606,7 @@ again: return 0; } - rte_discard(tab, e); + rte_discard(e); (*limit)--; goto rescan; @@ -1712,7 +1712,7 @@ rta_apply_hostentry(rta *a, struct hostentry *he) } static inline rte * -rt_next_hop_update_rte(rtable *tab, rte *old) +rt_next_hop_update_rte(rtable *tab UNUSED, rte *old) { rta a; memcpy(&a, old->attrs, sizeof(rta)); @@ -2104,11 +2104,11 @@ hc_remove(struct hostcache *hc, struct hostentry *he) static void hc_alloc_table(struct hostcache *hc, unsigned order) { - unsigned hsize = 1 << order; + uint hsize = 1 << order; hc->hash_order = order; hc->hash_shift = 16 - order; - hc->hash_max = (order >= HC_HI_ORDER) ? ~0 : (hsize HC_HI_MARK); - hc->hash_min = (order <= HC_LO_ORDER) ? 0 : (hsize HC_LO_MARK); + hc->hash_max = (order >= HC_HI_ORDER) ? ~0U : (hsize HC_HI_MARK); + hc->hash_min = (order <= HC_LO_ORDER) ? 0U : (hsize HC_LO_MARK); hc->hash_table = mb_allocz(rt_table_pool, hsize * sizeof(struct hostentry *)); } @@ -2116,10 +2116,10 @@ hc_alloc_table(struct hostcache *hc, unsigned order) static void hc_resize(struct hostcache *hc, unsigned new_order) { - unsigned old_size = 1 << hc->hash_order; struct hostentry **old_table = hc->hash_table; struct hostentry *he, *hen; - int i; + uint old_size = 1 << hc->hash_order; + uint i; hc_alloc_table(hc, new_order); for (i = 0; i < old_size; i++) diff --git a/proto/babel/babel.c b/proto/babel/babel.c index 9d73a264..38be6909 100644 --- a/proto/babel/babel.c +++ b/proto/babel/babel.c @@ -1723,7 +1723,7 @@ babel_dump(struct proto *P) } static void -babel_get_route_info(rte *rte, byte *buf, ea_list *attrs) +babel_get_route_info(rte *rte, byte *buf, ea_list *attrs UNUSED) { buf += bsprintf(buf, " (%d/%d) [%lR]", rte->pref, rte->u.babel.metric, rte->u.babel.router_id); } @@ -1965,7 +1965,7 @@ babel_store_tmp_attrs(struct rte *rt, struct ea_list *attrs) */ static void babel_rt_notify(struct proto *P, struct rtable *table UNUSED, struct network *net, - struct rte *new, struct rte *old, struct ea_list *attrs) + struct rte *new, struct rte *old UNUSED, struct ea_list *attrs UNUSED) { struct babel_proto *p = (void *) P; struct babel_entry *e; diff --git a/proto/babel/babel.h b/proto/babel/babel.h index 481c88a7..6a95d82f 100644 --- a/proto/babel/babel.h +++ b/proto/babel/babel.h @@ -111,7 +111,7 @@ struct babel_iface_config { u16 rxcost; u8 type; u8 check_link; - int port; + uint port; u16 hello_interval; u16 ihu_interval; u16 update_interval; diff --git a/proto/babel/packets.c b/proto/babel/packets.c index 65dd6853..08054832 100644 --- a/proto/babel/packets.c +++ b/proto/babel/packets.c @@ -146,6 +146,7 @@ struct babel_write_state { #define TLV_HDR(tlv,t,l) ({ tlv->type = t; tlv->length = l - sizeof(struct babel_tlv); }) #define TLV_HDR0(tlv,t) TLV_HDR(tlv, t, tlv_data[t].min_length) +#define BYTES(n) ((((uint) n) + 7) / 8) static inline u16 get_time16(const void *p) @@ -161,18 +162,18 @@ put_time16(void *p, u16 v) } static inline ip6_addr -get_ip6_px(const void *p, int plen) +get_ip6_px(const void *p, uint plen) { ip6_addr addr = IPA_NONE; - memcpy(&addr, p, (plen + 7) / 8); + memcpy(&addr, p, BYTES(plen)); return ip6_ntoh(addr); } static inline void -put_ip6_px(void *p, ip6_addr addr, int plen) +put_ip6_px(void *p, ip6_addr addr, uint plen) { addr = ip6_hton(addr); - memcpy(p, &addr, (plen + 7) / 8); + memcpy(p, &addr, BYTES(plen)); } static inline ip6_addr @@ -202,21 +203,21 @@ static int babel_read_update(struct babel_tlv *hdr, union babel_msg *msg, struct static int babel_read_route_request(struct babel_tlv *hdr, union babel_msg *msg, struct babel_parse_state *state); static int babel_read_seqno_request(struct babel_tlv *hdr, union babel_msg *msg, struct babel_parse_state *state); -static int babel_write_ack(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, int max_len); -static int babel_write_hello(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, int max_len); -static int babel_write_ihu(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, int max_len); -static int babel_write_update(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, int max_len); -static int babel_write_route_request(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, int max_len); -static int babel_write_seqno_request(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, int max_len); +static uint babel_write_ack(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, uint max_len); +static uint babel_write_hello(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, uint max_len); +static uint babel_write_ihu(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, uint max_len); +static uint babel_write_update(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, uint max_len); +static uint babel_write_route_request(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, uint max_len); +static uint babel_write_seqno_request(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, uint max_len); struct babel_tlv_data { u8 min_length; int (*read_tlv)(struct babel_tlv *hdr, union babel_msg *m, struct babel_parse_state *state); - int (*write_tlv)(struct babel_tlv *hdr, union babel_msg *m, struct babel_write_state *state, int max_len); + uint (*write_tlv)(struct babel_tlv *hdr, union babel_msg *m, struct babel_write_state *state, uint max_len); void (*handle_tlv)(union babel_msg *m, struct babel_iface *ifa); }; -const static struct babel_tlv_data tlv_data[BABEL_TLV_MAX] = { +static const struct babel_tlv_data tlv_data[BABEL_TLV_MAX] = { [BABEL_TLV_ACK_REQ] = { sizeof(struct babel_tlv_ack_req), babel_read_ack_req, @@ -291,9 +292,9 @@ babel_read_ack_req(struct babel_tlv *hdr, union babel_msg *m, return PARSE_SUCCESS; } -static int +static uint babel_write_ack(struct babel_tlv *hdr, union babel_msg *m, - struct babel_write_state *state, int max_len) + struct babel_write_state *state UNUSED, uint max_len UNUSED) { struct babel_tlv_ack *tlv = (void *) hdr; struct babel_msg_ack *msg = &m->ack; @@ -319,9 +320,9 @@ babel_read_hello(struct babel_tlv *hdr, union babel_msg *m, return PARSE_SUCCESS; } -static int +static uint babel_write_hello(struct babel_tlv *hdr, union babel_msg *m, - struct babel_write_state *state, int max_len) + struct babel_write_state *state UNUSED, uint max_len UNUSED) { struct babel_tlv_hello *tlv = (void *) hdr; struct babel_msg_hello *msg = &m->hello; @@ -363,9 +364,9 @@ babel_read_ihu(struct babel_tlv *hdr, union babel_msg *m, return PARSE_SUCCESS; } -static int +static uint babel_write_ihu(struct babel_tlv *hdr, union babel_msg *m, - struct babel_write_state *state, int max_len) + struct babel_write_state *state UNUSED, uint max_len) { struct babel_tlv_ihu *tlv = (void *) hdr; struct babel_msg_ihu *msg = &m->ihu; @@ -401,9 +402,9 @@ babel_read_router_id(struct babel_tlv *hdr, union babel_msg *m UNUSED, } /* This is called directly from babel_write_update() */ -static int +static uint babel_write_router_id(struct babel_tlv *hdr, u64 router_id, - struct babel_write_state *state, int max_len UNUSED) + struct babel_write_state *state, uint max_len UNUSED) { struct babel_tlv_router_id *tlv = (void *) hdr; @@ -467,10 +468,10 @@ babel_read_update(struct babel_tlv *hdr, union babel_msg *m, msg->metric = get_u16(&tlv->metric); /* Length of received prefix data without omitted part */ - int len = (tlv->plen + 7)/8 - (int) tlv->omitted; + int len = BYTES(tlv->plen) - (int) tlv->omitted; u8 buf[16] = {}; - if ((len < 0) || (len > TLV_OPT_LENGTH(tlv))) + if ((len < 0) || ((uint) len > TLV_OPT_LENGTH(tlv))) return PARSE_ERROR; switch (tlv->ae) @@ -536,13 +537,13 @@ babel_read_update(struct babel_tlv *hdr, union babel_msg *m, return PARSE_SUCCESS; } -static int +static uint babel_write_update(struct babel_tlv *hdr, union babel_msg *m, - struct babel_write_state *state, int max_len) + struct babel_write_state *state, uint max_len) { struct babel_tlv_update *tlv = (void *) hdr; struct babel_msg_update *msg = &m->update; - int len0 = 0; + uint len0 = 0; /* * When needed, we write Router-ID TLV before Update TLV and return size of @@ -558,7 +559,7 @@ babel_write_update(struct babel_tlv *hdr, union babel_msg *m, tlv = (struct babel_tlv_update *) NEXT_TLV(tlv); } - int len = sizeof(struct babel_tlv_update) + (msg->plen + 7)/8; + uint len = sizeof(struct babel_tlv_update) + BYTES(msg->plen); if (len0 + len > max_len) return 0; @@ -587,7 +588,7 @@ babel_write_update(struct babel_tlv *hdr, union babel_msg *m, static int babel_read_route_request(struct babel_tlv *hdr, union babel_msg *m, - struct babel_parse_state *state) + struct babel_parse_state *state UNUSED) { struct babel_tlv_route_request *tlv = (void *) hdr; struct babel_msg_route_request *msg = &m->route_request; @@ -612,7 +613,7 @@ babel_read_route_request(struct babel_tlv *hdr, union babel_msg *m, if (tlv->plen > MAX_PREFIX_LENGTH) return PARSE_ERROR; - if (TLV_OPT_LENGTH(tlv) < (tlv->plen + 7)/8) + if (TLV_OPT_LENGTH(tlv) < BYTES(tlv->plen)) return PARSE_ERROR; msg->plen = tlv->plen; @@ -629,14 +630,14 @@ babel_read_route_request(struct babel_tlv *hdr, union babel_msg *m, return PARSE_IGNORE; } -static int +static uint babel_write_route_request(struct babel_tlv *hdr, union babel_msg *m, - struct babel_write_state *state, int max_len) + struct babel_write_state *state UNUSED, uint max_len) { struct babel_tlv_route_request *tlv = (void *) hdr; struct babel_msg_route_request *msg = &m->route_request; - int len = sizeof(struct babel_tlv_route_request) + (msg->plen + 7)/8; + uint len = sizeof(struct babel_tlv_route_request) + BYTES(msg->plen); if (len > max_len) return 0; @@ -687,7 +688,7 @@ babel_read_seqno_request(struct babel_tlv *hdr, union babel_msg *m, if (tlv->plen > MAX_PREFIX_LENGTH) return PARSE_ERROR; - if (TLV_OPT_LENGTH(tlv) < (tlv->plen + 7)/8) + if (TLV_OPT_LENGTH(tlv) < BYTES(tlv->plen)) return PARSE_ERROR; msg->plen = tlv->plen; @@ -704,14 +705,14 @@ babel_read_seqno_request(struct babel_tlv *hdr, union babel_msg *m, return PARSE_IGNORE; } -static int +static uint babel_write_seqno_request(struct babel_tlv *hdr, union babel_msg *m, - struct babel_write_state *state, int max_len) + struct babel_write_state *state UNUSED, uint max_len) { struct babel_tlv_seqno_request *tlv = (void *) hdr; struct babel_msg_seqno_request *msg = &m->seqno_request; - int len = sizeof(struct babel_tlv_seqno_request) + (msg->plen + 7)/8; + uint len = sizeof(struct babel_tlv_seqno_request) + BYTES(msg->plen); if (len > max_len) return 0; @@ -744,11 +745,11 @@ babel_read_tlv(struct babel_tlv *hdr, return tlv_data[hdr->type].read_tlv(hdr, msg, state); } -static int +static uint babel_write_tlv(struct babel_tlv *hdr, union babel_msg *msg, struct babel_write_state *state, - int max_len) + uint max_len) { if ((msg->type <= BABEL_TLV_PADN) || (msg->type >= BABEL_TLV_MAX) || @@ -792,7 +793,7 @@ babel_send_to(struct babel_iface *ifa, ip_addr dest) * * The TLVs in the queue are freed after they are written to the buffer. */ -static int +static uint babel_write_queue(struct babel_iface *ifa, list *queue) { struct babel_proto *p = ifa->proto; @@ -813,6 +814,9 @@ babel_write_queue(struct babel_iface *ifa, list *queue) struct babel_msg_node *msg; WALK_LIST_FIRST(msg, *queue) { + if (pos >= end) + break; + int len = babel_write_tlv((struct babel_tlv *) pos, &msg->msg, &state, end - pos); if (!len) @@ -823,7 +827,7 @@ babel_write_queue(struct babel_iface *ifa, list *queue) sl_free(p->msg_slab, msg); } - int plen = pos - (byte *) pkt; + uint plen = pos - (byte *) pkt; put_u16(&pkt->length, plen - sizeof(struct babel_pkt_header)); return plen; @@ -1027,7 +1031,7 @@ babel_tx_hook(sock *sk) static int -babel_rx_hook(sock *sk, int len) +babel_rx_hook(sock *sk, uint len) { struct babel_iface *ifa = sk->data; struct babel_proto *p = ifa->proto; diff --git a/proto/bfd/bfd.c b/proto/bfd/bfd.c index 5de2f556..e7be6a8a 100644 --- a/proto/bfd/bfd.c +++ b/proto/bfd/bfd.c @@ -796,7 +796,7 @@ bfd_start_neighbor(struct bfd_proto *p, struct bfd_neighbor *n) } static void -bfd_stop_neighbor(struct bfd_proto *p, struct bfd_neighbor *n) +bfd_stop_neighbor(struct bfd_proto *p UNUSED, struct bfd_neighbor *n) { if (n->neigh) n->neigh->data = NULL; @@ -853,7 +853,7 @@ void pipe_drain(int fd); void pipe_kick(int fd); static int -bfd_notify_hook(sock *sk, int len) +bfd_notify_hook(sock *sk, uint len UNUSED) { struct bfd_proto *p = sk->data; struct bfd_session *s; @@ -1060,7 +1060,7 @@ bfd_preconfig(struct protocol *P UNUSED, struct config *c UNUSED) } static void -bfd_copy_config(struct proto_config *dest, struct proto_config *src) +bfd_copy_config(struct proto_config *dest, struct proto_config *src UNUSED) { struct bfd_config *d = (struct bfd_config *) dest; // struct bfd_config *s = (struct bfd_config *) src; diff --git a/proto/bfd/packets.c b/proto/bfd/packets.c index cb40bcda..deb501fc 100644 --- a/proto/bfd/packets.c +++ b/proto/bfd/packets.c @@ -39,7 +39,7 @@ static inline u8 bfd_pkt_get_diag(struct bfd_ctl_packet *pkt) static inline u8 bfd_pkt_get_state(struct bfd_ctl_packet *pkt) { return pkt->flags >> 6; } -static inline void bfd_pkt_set_state(struct bfd_ctl_packet *pkt, u8 val) +static inline void UNUSED bfd_pkt_set_state(struct bfd_ctl_packet *pkt, u8 val) { pkt->flags = val << 6; } @@ -97,7 +97,7 @@ bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final) #define DROP(DSC,VAL) do { err_dsc = DSC; err_val = VAL; goto drop; } while(0) static int -bfd_rx_hook(sock *sk, int len) +bfd_rx_hook(sock *sk, uint len) { struct bfd_proto *p = sk->data; struct bfd_ctl_packet *pkt = (struct bfd_ctl_packet *) sk->rbuf; diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index 6fe34e56..0309c1f7 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -191,7 +191,7 @@ validate_as4_path(struct bgp_proto *p, struct adata *path) } static int -bgp_check_next_hop(struct bgp_proto *p UNUSED, byte *a, int len) +bgp_check_next_hop(struct bgp_proto *p UNUSED, byte *a UNUSED6, int len UNUSED6) { #ifdef IPV6 return IGNORE; diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 2014525e..8ef4b990 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -807,7 +807,7 @@ bgp_find_proto(sock *sk) * closes the new connection by sending a Notification message. */ static int -bgp_incoming_connection(sock *sk, int dummy UNUSED) +bgp_incoming_connection(sock *sk, uint dummy UNUSED) { struct bgp_proto *p; int acc, hops; diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index a865b99d..b4067f3a 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -191,7 +191,7 @@ struct bgp_bucket { #define BGP_RX_BUFFER_EXT_SIZE 65535 #define BGP_TX_BUFFER_EXT_SIZE 65535 -static inline int bgp_max_packet_length(struct bgp_proto *p) +static inline uint bgp_max_packet_length(struct bgp_proto *p) { return p->ext_messages ? BGP_MAX_EXT_MSG_LENGTH : BGP_MAX_MESSAGE_LENGTH; } extern struct linpool *bgp_linpool; @@ -268,7 +268,7 @@ void mrt_dump_bgp_state_change(struct bgp_conn *conn, unsigned old, unsigned new void bgp_schedule_packet(struct bgp_conn *conn, int type); void bgp_kick_tx(void *vconn); void bgp_tx(struct birdsock *sk); -int bgp_rx(struct birdsock *sk, int size); +int bgp_rx(struct birdsock *sk, uint size); const char * bgp_error_dsc(unsigned code, unsigned subcode); void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsigned subcode, byte *data, unsigned len); diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 0cf38edf..3e816839 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -191,7 +191,7 @@ bgp_put_cap_gr1(struct bgp_proto *p, byte *buf) } static byte * -bgp_put_cap_gr2(struct bgp_proto *p, byte *buf) +bgp_put_cap_gr2(struct bgp_proto *p UNUSED, byte *buf) { *buf++ = 64; /* Capability 64: Support for graceful restart */ *buf++ = 2; /* Capability data length */ @@ -931,7 +931,7 @@ bgp_parse_options(struct bgp_conn *conn, byte *opt, int len) } static void -bgp_rx_open(struct bgp_conn *conn, byte *pkt, int len) +bgp_rx_open(struct bgp_conn *conn, byte *pkt, uint len) { struct bgp_conn *other; struct bgp_proto *p = conn->bgp; @@ -944,7 +944,7 @@ bgp_rx_open(struct bgp_conn *conn, byte *pkt, int len) { bgp_error(conn, 5, fsm_err_subcode[conn->state], NULL, 0); return; } /* Check message contents */ - if (len < 29 || len != 29 + pkt[28]) + if (len < 29 || len != 29U + pkt[28]) { bgp_error(conn, 1, 2, pkt+16, 2); return; } if (pkt[19] != BGP_VERSION) { bgp_error(conn, 2, 1, pkt+19, 1); return; } /* RFC 1771 says 16 bits, draft-09 tells to use 8 */ @@ -1256,16 +1256,15 @@ bgp_do_rx_update(struct bgp_conn *conn, #else /* IPv6 version */ #define DO_NLRI(name) \ - start = x = p->name##_start; \ + x = p->name##_start; \ len = len0 = p->name##_len; \ if (len) \ { \ if (len < 3) { err=9; goto done; } \ af = get_u16(x); \ - sub = x[2]; \ x += 3; \ len -= 3; \ - DBG("\tNLRI AF=%d sub=%d len=%d\n", af, sub, len);\ + DBG("\tNLRI AF=%d sub=%d len=%d\n", af, x[-1], len);\ } \ else \ af = 0; \ @@ -1291,15 +1290,15 @@ bgp_attach_next_hop(rta *a0, byte *x) static void bgp_do_rx_update(struct bgp_conn *conn, - byte *withdrawn, int withdrawn_len, - byte *nlri, int nlri_len, + byte *withdrawn UNUSED, int withdrawn_len, + byte *nlri UNUSED, int nlri_len, byte *attrs, int attr_len) { struct bgp_proto *p = conn->bgp; struct rte_src *src = p->p.main_source; - byte *start, *x; + byte *x; int len, len0; - unsigned af, sub; + unsigned af; rta *a0, *a = NULL; ip_addr prefix; int pxlen, err = 0; @@ -1375,11 +1374,11 @@ bgp_do_rx_update(struct bgp_conn *conn, #endif static void -bgp_rx_update(struct bgp_conn *conn, byte *pkt, int len) +bgp_rx_update(struct bgp_conn *conn, byte *pkt, uint len) { struct bgp_proto *p = conn->bgp; byte *withdrawn, *attrs, *nlri; - int withdrawn_len, attr_len, nlri_len; + uint withdrawn_len, attr_len, nlri_len; BGP_TRACE_RL(&rl_rcv_update, D_PACKETS, "Got UPDATE"); @@ -1525,7 +1524,7 @@ bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsigned } static void -bgp_rx_notification(struct bgp_conn *conn, byte *pkt, int len) +bgp_rx_notification(struct bgp_conn *conn, byte *pkt, uint len) { struct bgp_proto *p = conn->bgp; if (len < 21) @@ -1591,7 +1590,7 @@ bgp_rx_keepalive(struct bgp_conn *conn) } static void -bgp_rx_route_refresh(struct bgp_conn *conn, byte *pkt, int len) +bgp_rx_route_refresh(struct bgp_conn *conn, byte *pkt, uint len) { struct bgp_proto *p = conn->bgp; @@ -1680,7 +1679,7 @@ bgp_rx_packet(struct bgp_conn *conn, byte *pkt, unsigned len) * bgp_rx_packet(). */ int -bgp_rx(sock *sk, int size) +bgp_rx(sock *sk, uint size) { struct bgp_conn *conn = sk->data; struct bgp_proto *p = conn->bgp; diff --git a/proto/ospf/dbdes.c b/proto/ospf/dbdes.c index 195b03ad..d6904343 100644 --- a/proto/ospf/dbdes.c +++ b/proto/ospf/dbdes.c @@ -39,7 +39,7 @@ struct ospf_dbdes3_packet static inline uint -ospf_dbdes_hdrlen(struct ospf_proto *p) +ospf_dbdes_hdrlen(struct ospf_proto *p UNUSED4 UNUSED6) { return ospf_is_v2(p) ? sizeof(struct ospf_dbdes2_packet) : sizeof(struct ospf_dbdes3_packet); diff --git a/proto/ospf/hello.c b/proto/ospf/hello.c index 50cf1407..e00487dc 100644 --- a/proto/ospf/hello.c +++ b/proto/ospf/hello.c @@ -222,9 +222,12 @@ ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa, rcv_priority = ps->priority; int pxlen = u32_masklen(ntohl(ps->netmask)); + if (pxlen < 0) + DROP("prefix garbled", ntohl(ps->netmask)); + if ((ifa->type != OSPF_IT_VLINK) && (ifa->type != OSPF_IT_PTP) && - (pxlen != ifa->addr->pxlen)) + ((uint) pxlen != ifa->addr->pxlen)) DROP("prefix length mismatch", pxlen); neighbors = ps->neighbors; diff --git a/proto/ospf/lsalib.c b/proto/ospf/lsalib.c index 1bbd1372..cb7b186a 100644 --- a/proto/ospf/lsalib.c +++ b/proto/ospf/lsalib.c @@ -463,7 +463,7 @@ lsa_validate_sum3_net(struct ospf_lsa_header *lsa, struct ospf_lsa_sum3_net *bod } static int -lsa_validate_sum3_rt(struct ospf_lsa_header *lsa, struct ospf_lsa_sum3_rt *body) +lsa_validate_sum3_rt(struct ospf_lsa_header *lsa, struct ospf_lsa_sum3_rt *body UNUSED) { if (lsa->length != (HDRLEN + sizeof(struct ospf_lsa_sum3_rt))) return 0; diff --git a/proto/ospf/lsalib.h b/proto/ospf/lsalib.h index ae6af044..638b3525 100644 --- a/proto/ospf/lsalib.h +++ b/proto/ospf/lsalib.h @@ -41,7 +41,7 @@ void lsa_get_type_domain_(u32 itype, struct ospf_iface *ifa, u32 *otype, u32 *do static inline void lsa_get_type_domain(struct ospf_lsa_header *lsa, struct ospf_iface *ifa, u32 *otype, u32 *domain) { lsa_get_type_domain_(lsa->type_raw, ifa, otype, domain); } -static inline u32 lsa_get_etype(struct ospf_lsa_header *h, struct ospf_proto *p) +static inline u32 lsa_get_etype(struct ospf_lsa_header *h, struct ospf_proto *p UNUSED4 UNUSED6) { return ospf_is_v2(p) ? (h->type_raw & LSA_T_V2_MASK) : h->type_raw; } diff --git a/proto/ospf/lsupd.c b/proto/ospf/lsupd.c index c6a734ca..157d9628 100644 --- a/proto/ospf/lsupd.c +++ b/proto/ospf/lsupd.c @@ -105,7 +105,7 @@ invalid: static inline void -ospf_lsa_lsrq_down(struct top_hash_entry *req, struct ospf_neighbor *n, struct ospf_neighbor *from) +ospf_lsa_lsrq_down(struct top_hash_entry *req, struct ospf_neighbor *n) { if (req == n->lsrqi) n->lsrqi = SNODE_NEXT(req); @@ -188,7 +188,7 @@ ospf_enqueue_lsa(struct ospf_proto *p, struct top_hash_entry *en, struct ospf_if { /* If we already have full queue, we send some packets */ uint sent = ospf_flood_lsupd(p, ifa->flood_queue, ifa->flood_queue_used, ifa->flood_queue_used / 2, ifa); - int i; + uint i; for (i = 0; i < sent; i++) ifa->flood_queue[i]->ret_count--; @@ -275,7 +275,7 @@ ospf_flood_lsa(struct ospf_proto *p, struct top_hash_entry *en, struct ospf_neig /* If same or newer, remove LSA from the link state request list */ if (cmp > CMP_OLDER) - ospf_lsa_lsrq_down(req, n, from); + ospf_lsa_lsrq_down(req, n); /* If older or same, skip processing of this neighbor */ if (cmp < CMP_NEWER) diff --git a/proto/ospf/neighbor.c b/proto/ospf/neighbor.c index 0223ccdf..9fe3c028 100644 --- a/proto/ospf/neighbor.c +++ b/proto/ospf/neighbor.c @@ -359,7 +359,7 @@ can_do_adj(struct ospf_neighbor *n) } -static inline u32 neigh_get_id(struct ospf_proto *p, struct ospf_neighbor *n) +static inline u32 neigh_get_id(struct ospf_proto *p UNUSED4 UNUSED6, struct ospf_neighbor *n) { return ospf_is_v2(p) ? ipa_to_u32(n->ip) : n->rid; } static struct ospf_neighbor * diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h index a4e525ec..ca30e4e0 100644 --- a/proto/ospf/ospf.h +++ b/proto/ospf/ospf.h @@ -766,7 +766,7 @@ lsa_get_ipv6_addr(u32 *buf, ip_addr *addr) } static inline u32 * -put_ipv6_prefix(u32 *buf, ip_addr addr, u8 pxlen, u8 pxopts, u16 lh) +put_ipv6_prefix(u32 *buf, ip_addr addr UNUSED4, u8 pxlen UNUSED4, u8 pxopts UNUSED4, u16 lh UNUSED4) { #ifdef IPV6 *buf++ = ((pxlen << 24) | (pxopts << 16) | lh); @@ -840,7 +840,7 @@ static inline int ospf_is_v2(struct ospf_proto *p) static inline int ospf_is_v3(struct ospf_proto *p) { return ! p->ospf2; } */ -static inline int ospf_get_version(struct ospf_proto *p) +static inline int ospf_get_version(struct ospf_proto *p UNUSED4 UNUSED6) { return ospf_is_v2(p) ? 2 : 3; } struct ospf_area *ospf_find_area(struct ospf_proto *p, u32 aid); @@ -897,7 +897,7 @@ void ospf_sh_neigh_info(struct ospf_neighbor *n); /* packet.c */ void ospf_pkt_fill_hdr(struct ospf_iface *ifa, void *buf, u8 h_type); uint ospf_pkt_maxsize(struct ospf_iface *ifa); -int ospf_rx_hook(sock * sk, int size); +int ospf_rx_hook(sock * sk, uint size); // void ospf_tx_hook(sock * sk); void ospf_err_hook(sock * sk, int err); void ospf_verr_hook(sock *sk, int err); @@ -922,7 +922,7 @@ static inline void ospf_send_to_des(struct ospf_iface *ifa) #define SKIP(DSC) do { err_dsc = DSC; goto skip; } while(0) #endif -static inline uint ospf_pkt_hdrlen(struct ospf_proto *p) +static inline uint ospf_pkt_hdrlen(struct ospf_proto *p UNUSED4 UNUSED6) { return ospf_is_v2(p) ? (sizeof(struct ospf_packet) + sizeof(union ospf_auth)) : sizeof(struct ospf_packet); } static inline void * ospf_tx_buffer(struct ospf_iface *ifa) diff --git a/proto/ospf/packet.c b/proto/ospf/packet.c index 04f0d47c..aa90aa51 100644 --- a/proto/ospf/packet.c +++ b/proto/ospf/packet.c @@ -124,7 +124,7 @@ ospf_pkt_finalize(struct ospf_iface *ifa, struct ospf_packet *pkt) /* We assume OSPFv2 in ospf_pkt_checkauth() */ static int -ospf_pkt_checkauth(struct ospf_neighbor *n, struct ospf_iface *ifa, struct ospf_packet *pkt, int len) +ospf_pkt_checkauth(struct ospf_neighbor *n, struct ospf_iface *ifa, struct ospf_packet *pkt, uint len) { struct ospf_proto *p = ifa->oa->po; union ospf_auth *auth = (void *) (pkt + 1); @@ -214,7 +214,7 @@ drop: * non generic functions. */ int -ospf_rx_hook(sock *sk, int len) +ospf_rx_hook(sock *sk, uint len) { /* We want just packets from sk->iface. Unfortunately, on BSD we cannot filter out other packets at kernel level and we receive all packets on all sockets */ diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index cdf8012a..8b3feda9 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -1049,7 +1049,7 @@ check_sum_rt_lsa(struct ospf_proto *p, ort *nf) } static inline int -decide_nssa_lsa(struct ospf_proto *p, ort *nf, struct ospf_lsa_ext_local *rt) +decide_nssa_lsa(struct ospf_proto *p UNUSED4 UNUSED6, ort *nf, struct ospf_lsa_ext_local *rt) { struct ospf_area *oa = nf->n.oa; struct top_hash_entry *en = nf->n.en; diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c index 7558d4a0..341eff87 100644 --- a/proto/ospf/topology.c +++ b/proto/ospf/topology.c @@ -515,7 +515,7 @@ ospf_update_lsadb(struct ospf_proto *p) static inline u32 -ort_to_lsaid(struct ospf_proto *p, ort *nf) +ort_to_lsaid(struct ospf_proto *p UNUSED4 UNUSED6, ort *nf) { /* * In OSPFv2, We have to map IP prefixes to u32 in such manner that resulting @@ -607,7 +607,7 @@ lsab_offset(struct ospf_proto *p, uint offset) return ((byte *) p->lsab) + offset; } -static inline void * +static inline void * UNUSED lsab_end(struct ospf_proto *p) { return ((byte *) p->lsab) + p->lsab_used; @@ -1545,7 +1545,7 @@ static void add_link_lsa(struct ospf_proto *p, struct ospf_lsa_link *ll, int offset, int *pxc) { u32 *pxb = ll->rest; - int j; + uint j; for (j = 0; j < ll->pxcount; pxb = prefix_advance(pxb), j++) { @@ -1748,7 +1748,7 @@ ospf_top_hash(struct top_graph *f, u32 domain, u32 lsaid, u32 rtrid, u32 type) * and request lists of OSPF neighbors. */ struct top_graph * -ospf_top_new(struct ospf_proto *p, pool *pool) +ospf_top_new(struct ospf_proto *p UNUSED4 UNUSED6, pool *pool) { struct top_graph *f; diff --git a/proto/radv/packets.c b/proto/radv/packets.c index 3862af8d..4bf960c3 100644 --- a/proto/radv/packets.c +++ b/proto/radv/packets.c @@ -157,12 +157,12 @@ radv_process_domain(struct radv_dnssl_config *cf) char *dom = cf->domain; char *dom_end = dom; /* Just to */ u8 *dlen_save = &cf->dlen_first; - int len; + uint len; while (dom_end) { dom_end = strchr(dom, '.'); - len = dom_end ? (dom_end - dom) : strlen(dom); + len = dom_end ? (uint)(dom_end - dom) : strlen(dom); if (len < 1 || len > 63) return -1; @@ -348,7 +348,7 @@ radv_send_ra(struct radv_iface *ifa, int shutdown) static int -radv_rx_hook(sock *sk, int size) +radv_rx_hook(sock *sk, uint size) { struct radv_iface *ifa = sk->data; struct proto_radv *ra = ifa->ra; diff --git a/proto/radv/radv.c b/proto/radv/radv.c index 6370e006..5c52217d 100644 --- a/proto/radv/radv.c +++ b/proto/radv/radv.c @@ -240,7 +240,7 @@ radv_if_notify(struct proto *p, unsigned flags, struct iface *iface) } static void -radv_ifa_notify(struct proto *p, unsigned flags, struct ifa *a) +radv_ifa_notify(struct proto *p, unsigned flags UNUSED, struct ifa *a) { struct proto_radv *ra = (struct proto_radv *) p; diff --git a/proto/radv/radv.h b/proto/radv/radv.h index 48ba9c1a..e2bf07ba 100644 --- a/proto/radv/radv.h +++ b/proto/radv/radv.h @@ -84,7 +84,7 @@ struct radv_prefix_config { node n; ip_addr prefix; - int pxlen; + uint pxlen; u8 skip; /* Do not include this prefix to RA */ u8 onlink; /* Standard options from RFC 4261 */ diff --git a/proto/rip/packets.c b/proto/rip/packets.c index 9f10fd67..e026eaea 100644 --- a/proto/rip/packets.c +++ b/proto/rip/packets.c @@ -108,7 +108,7 @@ static inline uint rip_pkt_hdrlen(struct rip_iface *ifa) { return sizeof(struct rip_packet) + (ifa->cf->auth_type ? RIP_BLOCK_LENGTH : 0); } static inline void -rip_put_block(struct rip_proto *p, byte *pos, struct rip_block *rte) +rip_put_block(struct rip_proto *p UNUSED4 UNUSED6, byte *pos, struct rip_block *rte) { if (rip_is_v2(p)) { @@ -131,7 +131,7 @@ rip_put_block(struct rip_proto *p, byte *pos, struct rip_block *rte) } static inline void -rip_put_next_hop(struct rip_proto *p, byte *pos, struct rip_block *rte) +rip_put_next_hop(struct rip_proto *p UNUSED, byte *pos, struct rip_block *rte UNUSED4) { struct rip_block_ng *block = (void *) pos; block->prefix = ip6_hton(ipa_to_ip6(rte->next_hop)); @@ -141,7 +141,7 @@ rip_put_next_hop(struct rip_proto *p, byte *pos, struct rip_block *rte) } static inline int -rip_get_block(struct rip_proto *p, byte *pos, struct rip_block *rte) +rip_get_block(struct rip_proto *p UNUSED4 UNUSED6, byte *pos, struct rip_block *rte) { if (rip_is_v2(p)) { @@ -630,7 +630,7 @@ rip_receive_response(struct rip_proto *p, struct rip_iface *ifa, struct rip_pack } static int -rip_rx_hook(sock *sk, int len) +rip_rx_hook(sock *sk, uint len) { struct rip_iface *ifa = sk->data; struct rip_proto *p = ifa->rip; diff --git a/proto/rip/rip.c b/proto/rip/rip.c index 36527253..37cfa9ac 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -1027,7 +1027,7 @@ rip_prepare_attrs(struct linpool *pool, ea_list *next, u8 metric, u16 tag) } static int -rip_import_control(struct proto *P, struct rte **rt, struct ea_list **attrs, struct linpool *pool) +rip_import_control(struct proto *P UNUSED, struct rte **rt, struct ea_list **attrs, struct linpool *pool) { /* Prepare attributes with initial values */ if ((*rt)->attrs->source != RTS_RIP) @@ -1144,7 +1144,7 @@ rip_reconfigure(struct proto *P, struct proto_config *c) } static void -rip_get_route_info(rte *rte, byte *buf, ea_list *attrs) +rip_get_route_info(rte *rte, byte *buf, ea_list *attrs UNUSED) { buf += bsprintf(buf, " (%d/%d)", rte->pref, rte->u.rip.metric); diff --git a/proto/static/static.c b/proto/static/static.c index d54302a8..0c088cd7 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -250,7 +250,7 @@ static_add(struct proto *p, struct static_config *cf, struct static_route *r) } static void -static_rte_cleanup(struct proto *p, struct static_route *r) +static_rte_cleanup(struct proto *p UNUSED, struct static_route *r) { struct static_route *r2; @@ -435,7 +435,7 @@ static_if_notify(struct proto *p, unsigned flags, struct iface *i) } int -static_rte_mergable(rte *pri, rte *sec) +static_rte_mergable(rte *pri UNUSED, rte *sec UNUSED) { return 1; } diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c index f2ae81c3..9c9df51d 100644 --- a/sysdep/bsd/krt-sock.c +++ b/sysdep/bsd/krt-sock.c @@ -898,7 +898,7 @@ kif_do_scan(struct kif_proto *p) /* Kernel sockets */ static int -krt_sock_hook(sock *sk, int size UNUSED) +krt_sock_hook(sock *sk, uint size UNUSED) { struct ks_msg msg; int l = read(sk->fd, (char *)&msg, sizeof(msg)); @@ -918,7 +918,7 @@ krt_sock_err_hook(sock *sk, int e UNUSED) } static sock * -krt_sock_open(pool *pool, void *data, int table_id) +krt_sock_open(pool *pool, void *data, int table_id UNUSED) { sock *sk; int fd; @@ -1074,7 +1074,7 @@ kif_sys_shutdown(struct kif_proto *p) struct ifa * -kif_get_primary_ip(struct iface *i) +kif_get_primary_ip(struct iface *i UNUSED6) { #ifndef IPV6 static int fd = -1; diff --git a/sysdep/bsd/krt-sys.h b/sysdep/bsd/krt-sys.h index a63f8caf..353ffcec 100644 --- a/sysdep/bsd/krt-sys.h +++ b/sysdep/bsd/krt-sys.h @@ -45,7 +45,7 @@ struct krt_state { static inline void krt_sys_io_init(void) { } static inline void krt_sys_init(struct krt_proto *p UNUSED) { } -static inline int krt_sys_get_attr(eattr *a UNUSED, byte *buf UNUSED, int buflen UNUSED) { } +static inline int krt_sys_get_attr(eattr *a UNUSED, byte *buf UNUSED, int buflen UNUSED) { return 0; } #endif diff --git a/sysdep/bsd/sysio.h b/sysdep/bsd/sysio.h index 6c20733f..8d87a3c3 100644 --- a/sysdep/bsd/sysio.h +++ b/sysdep/bsd/sysio.h @@ -28,7 +28,9 @@ #endif +#ifndef SA_LEN #define SA_LEN(x) (x).sa.sa_len +#endif /* @@ -133,12 +135,12 @@ sk_process_cmsg4_ttl(sock *s, struct cmsghdr *cm) s->rcv_ttl = * (byte *) CMSG_DATA(cm); } +#ifdef IP_SENDSRCADDR static inline void sk_prepare_cmsgs4(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen) { /* Unfortunately, IP_SENDSRCADDR does not work for raw IP sockets on BSD kernels */ -#ifdef IP_SENDSRCADDR struct cmsghdr *cm; struct in_addr *sa; int controllen = 0; @@ -156,10 +158,13 @@ sk_prepare_cmsgs4(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen) *sa = ipa_to_in4(s->saddr); msg->msg_controllen = controllen; -#endif } +#else +static inline void +sk_prepare_cmsgs4(sock *s UNUSED, struct msghdr *msg UNUSED, void *cbuf UNUSED, size_t cbuflen UNUSED) { } +#endif -static void +static void UNUSED sk_prepare_ip_header(sock *s, void *hdr, int dlen) { struct ip *ip = hdr; @@ -200,7 +205,7 @@ sk_prepare_ip_header(sock *s, void *hdr, int dlen) #endif int -sk_set_md5_auth(sock *s, ip_addr local, ip_addr remote, struct iface *ifa, char *passwd, int setkey UNUSED) +sk_set_md5_auth(sock *s, ip_addr local UNUSED, ip_addr remote UNUSED, struct iface *ifa UNUSED, char *passwd, int setkey UNUSED) { #ifdef USE_MD5SIG_SETKEY if (setkey) @@ -235,20 +240,20 @@ sk_set_min_ttl4(sock *s, int ttl) } static inline int -sk_set_min_ttl6(sock *s, int ttl) +sk_set_min_ttl6(sock *s, int ttl UNUSED) { ERR_MSG("Kernel does not support IPv6 TTL security"); } static inline int -sk_disable_mtu_disc4(sock *s) +sk_disable_mtu_disc4(sock *s UNUSED) { /* TODO: Set IP_DONTFRAG to 0 ? */ return 0; } static inline int -sk_disable_mtu_disc6(sock *s) +sk_disable_mtu_disc6(sock *s UNUSED) { /* TODO: Set IPV6_DONTFRAG to 0 ? */ return 0; diff --git a/sysdep/linux/krt-sys.h b/sysdep/linux/krt-sys.h index 6d6586d1..76ae29b7 100644 --- a/sysdep/linux/krt-sys.h +++ b/sysdep/linux/krt-sys.h @@ -27,7 +27,7 @@ static inline void kif_sys_postconfig(struct kif_config *c UNUSED) { } static inline void kif_sys_init_config(struct kif_config *c UNUSED) { } static inline void kif_sys_copy_config(struct kif_config *d UNUSED, struct kif_config *s UNUSED) { } -static inline struct ifa * kif_get_primary_ip(struct iface *i) { return NULL; } +static inline struct ifa * kif_get_primary_ip(struct iface *i UNUSED) { return NULL; } /* Kernel routes */ diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index 79dd1405..368e0ef9 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -487,7 +487,7 @@ nl_parse_multipath(struct krt_proto *p, struct rtattr *ra) struct rtattr *a[BIRD_RTA_MAX]; struct rtnexthop *nh = RTA_DATA(ra); struct mpnh *rv, *first, **last; - int len = RTA_PAYLOAD(ra); + unsigned len = RTA_PAYLOAD(ra); first = NULL; last = &first; @@ -1473,7 +1473,7 @@ nl_async_msg(struct nlmsghdr *h) } static int -nl_async_hook(sock *sk, int size UNUSED) +nl_async_hook(sock *sk, uint size UNUSED) { struct iovec iov = { nl_async_rx_buffer, NL_RX_SIZE }; struct sockaddr_nl sa; diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 3ceadd98..873b5805 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -507,11 +507,11 @@ tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t) * Sockaddr helper functions */ -static inline int sockaddr_length(int af) +static inline int UNUSED sockaddr_length(int af) { return (af == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); } static inline void -sockaddr_fill4(struct sockaddr_in *sa, ip_addr a, struct iface *ifa, uint port) +sockaddr_fill4(struct sockaddr_in *sa, ip_addr a, uint port) { memset(sa, 0, sizeof(struct sockaddr_in)); #ifdef HAVE_SIN_LEN @@ -542,7 +542,7 @@ void sockaddr_fill(sockaddr *sa, int af, ip_addr a, struct iface *ifa, uint port) { if (af == AF_INET) - sockaddr_fill4((struct sockaddr_in *) sa, a, ifa, port); + sockaddr_fill4((struct sockaddr_in *) sa, a, port); else if (af == AF_INET6) sockaddr_fill6((struct sockaddr_in6 *) sa, a, ifa, port); else @@ -550,7 +550,7 @@ sockaddr_fill(sockaddr *sa, int af, ip_addr a, struct iface *ifa, uint port) } static inline void -sockaddr_read4(struct sockaddr_in *sa, ip_addr *a, struct iface **ifa, uint *port) +sockaddr_read4(struct sockaddr_in *sa, ip_addr *a, uint *port) { *port = ntohs(sa->sin_port); *a = ipa_from_in4(sa->sin_addr); @@ -573,7 +573,7 @@ sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *port) goto fail; if (af == AF_INET) - sockaddr_read4((struct sockaddr_in *) sa, a, ifa, port); + sockaddr_read4((struct sockaddr_in *) sa, a, port); else if (af == AF_INET6) sockaddr_read6((struct sockaddr_in6 *) sa, a, ifa, port); else @@ -770,7 +770,7 @@ sk_set_tos6(sock *s, int tos) } static inline int -sk_set_high_port(sock *s) +sk_set_high_port(sock *s UNUSED) { /* Port range setting is optional, ignore it if not supported */ diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index ef98cb3a..07a55c0d 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -909,7 +909,7 @@ krt_scan_timer_start(struct krt_proto *p) } static void -krt_scan_timer_stop(struct krt_proto *p) +krt_scan_timer_stop(struct krt_proto *p UNUSED) { krt_scan_count--; @@ -998,7 +998,7 @@ krt_store_tmp_attrs(rte *rt, struct ea_list *attrs) } static int -krt_import_control(struct proto *P, rte **new, ea_list **attrs, struct linpool *pool) +krt_import_control(struct proto *P, rte **new, ea_list **attrs UNUSED, struct linpool *pool UNUSED) { struct krt_proto *p = (struct krt_proto *) P; rte *e = *new; diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index a7989920..35bc3fd1 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -73,7 +73,7 @@ async_dump(void) #else static inline void -drop_uid(uid_t uid) +drop_uid(uid_t uid UNUSED) { die("Cannot change user on this platform"); } @@ -419,7 +419,7 @@ cli_get_command(cli *c) } static int -cli_rx(sock *s, int size UNUSED) +cli_rx(sock *s, uint size UNUSED) { cli_kick(s->data); return 0; @@ -439,7 +439,7 @@ cli_err(sock *s, int err) } static int -cli_connect(sock *s, int size UNUSED) +cli_connect(sock *s, uint size UNUSED) { cli *c; diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h index 4e0ff841..3ef2e3ef 100644 --- a/sysdep/unix/unix.h +++ b/sysdep/unix/unix.h @@ -63,16 +63,16 @@ typedef struct sockaddr_bird { #endif -static inline ip_addr ipa_from_in4(struct in_addr a) +static inline ip_addr ipa_from_in4(struct in_addr a UNUSED6) { return ipa_from_u32(ntohl(a.s_addr)); } -static inline ip_addr ipa_from_in6(struct in6_addr a) +static inline ip_addr ipa_from_in6(struct in6_addr a UNUSED4) { return ipa_build6(ntohl(a.s6_addr32[0]), ntohl(a.s6_addr32[1]), ntohl(a.s6_addr32[2]), ntohl(a.s6_addr32[3])); } -static inline ip_addr ipa_from_sa4(sockaddr *sa) +static inline ip_addr ipa_from_sa4(sockaddr *sa UNUSED6) { return ipa_from_in4(((struct sockaddr_in *) sa)->sin_addr); } -static inline ip_addr ipa_from_sa6(sockaddr *sa) +static inline ip_addr ipa_from_sa6(sockaddr *sa UNUSED4) { return ipa_from_in6(((struct sockaddr_in6 *) sa)->sin6_addr); } static inline struct in_addr ipa_to_in4(ip_addr a) @@ -83,7 +83,7 @@ static inline struct in6_addr ipa_to_in6(ip_addr a) { return (struct in6_addr) { .s6_addr32 = { htonl(_I0(a)), htonl(_I1(a)), htonl(_I2(a)), htonl(_I3(a)) } }; } #else /* Temporary dummy */ -static inline struct in6_addr ipa_to_in6(ip_addr a) +static inline struct in6_addr ipa_to_in6(ip_addr a UNUSED) { return (struct in6_addr) { .s6_addr32 = { 0, 0, 0, 0 } }; } #endif -- cgit v1.2.3 From c8cafc8ebb5320ac7c6117c17e6460036f0fdf62 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 8 Nov 2016 17:46:29 +0100 Subject: Minor code cleanups --- conf/cf-lex.l | 2 +- conf/conf.c | 6 +++--- conf/conf.h | 6 +++--- conf/confbase.Y | 2 +- filter/config.Y | 26 +++++++++++++------------- filter/filter.h | 24 ++++++++++++------------ filter/tree.c | 6 +++--- lib/buffer.h | 16 +++++++++++++++- lib/hash.h | 13 ++++++++++++- proto/ospf/rt.c | 4 ++-- sysdep/linux/syspriv.h | 9 +++++++++ sysdep/unix/io.c | 5 ++++- sysdep/unix/main.c | 4 +++- 13 files changed, 81 insertions(+), 42 deletions(-) (limited to 'filter') diff --git a/conf/cf-lex.l b/conf/cf-lex.l index d2aa6402..e9e385a6 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -589,7 +589,7 @@ cf_lex_init(int is_cli, struct config *c) cf_lex_init_kh(); ifs_head = ifs = push_ifs(NULL); - if (!is_cli) + if (!is_cli) { ifs->file_name = c->file_name; ifs->fd = c->file_fd; diff --git a/conf/conf.c b/conf/conf.c index 029814c6..0a4e3f8c 100644 --- a/conf/conf.c +++ b/conf/conf.c @@ -85,7 +85,7 @@ int undo_available; /* Undo was not requested from last reconfiguration */ * further use. Returns a pointer to the structure. */ struct config * -config_alloc(byte *name) +config_alloc(const byte *name) { pool *p = rp_new(&root_pool, "Config"); linpool *l = lp_new(p, 4080); @@ -405,7 +405,7 @@ config_confirm(void) * if it's been queued due to another reconfiguration being in progress now, * %CONF_UNQUEUED if a scheduled reconfiguration is removed, %CONF_NOTHING * if there is no relevant configuration to undo (the previous config request - * was config_undo() too) or %CONF_SHUTDOWN if BIRD is in shutdown mode and + * was config_undo() too) or %CONF_SHUTDOWN if BIRD is in shutdown mode and * no new configuration changes are accepted. */ int @@ -530,7 +530,7 @@ cf_error(char *msg, ...) * and we want to preserve it for further use. */ char * -cfg_strdup(char *c) +cfg_strdup(const char *c) { int l = strlen(c) + 1; char *z = cfg_allocu(l); diff --git a/conf/conf.h b/conf/conf.h index 89a2c5b7..41cb434f 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -21,7 +21,7 @@ struct config { list protos; /* Configured protocol instances (struct proto_config) */ list tables; /* Configured routing tables (struct rtable_config) */ list roa_tables; /* Configured ROA tables (struct roa_table_config) */ - list logfiles; /* Configured log fils (sysdep) */ + list logfiles; /* Configured log files (sysdep) */ int mrtdump_file; /* Configured MRTDump file (sysdep, fd in unix) */ char *syslog_name; /* Name used for syslog (NULL -> no syslog) */ @@ -61,7 +61,7 @@ struct config { extern struct config *config; /* Currently active configuration */ extern struct config *new_config; /* Configuration being parsed */ -struct config *config_alloc(byte *name); +struct config *config_alloc(const byte *name); int config_parse(struct config *); int cli_parse(struct config *); void config_free(struct config *); @@ -95,7 +95,7 @@ extern linpool *cfg_mem; #define cfg_alloc(size) lp_alloc(cfg_mem, size) #define cfg_allocu(size) lp_allocu(cfg_mem, size) #define cfg_allocz(size) lp_allocz(cfg_mem, size) -char *cfg_strdup(char *c); +char *cfg_strdup(const char *c); void cfg_copy_list(list *dest, list *src, unsigned node_size); /* Lexer */ diff --git a/conf/confbase.Y b/conf/confbase.Y index c14c23c7..96b32028 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -138,7 +138,7 @@ expr_us: /* Switches */ bool: - expr {$$ = !!$1; } + expr { $$ = !!$1; } | ON { $$ = 1; } | YES { $$ = 1; } | OFF { $$ = 0; } diff --git a/filter/config.Y b/filter/config.Y index 29e3a734..5ea83f81 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -158,7 +158,7 @@ f_new_lc_item(u32 f1, u32 t1, u32 f2, u32 t2, u32 f3, u32 t3) static inline struct f_inst * f_generate_empty(struct f_inst *dyn) -{ +{ struct f_inst *e = f_new_inst(); e->code = 'E'; @@ -261,7 +261,7 @@ f_generate_ec(u16 kind, struct f_inst *tk, struct f_inst *tv) if (c1 && c2) { u64 ec; - + if (kind == EC_GENERIC) { ec = ec_generic(key, val2); } @@ -280,7 +280,7 @@ f_generate_ec(u16 kind, struct f_inst *tk, struct f_inst *tv) NEW_F_VAL; rv = f_new_inst(); rv->code = 'C'; - rv->a1.p = val; + rv->a1.p = val; val->type = T_EC; val->val.ec = ec; } @@ -355,7 +355,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, %type pair_item ec_item lc_item set_item switch_item set_items switch_items switch_body %type fprefix_set %type set_atom switch_atom fprefix fprefix_s fipa -%type decls declsn one_decl function_params +%type decls declsn one_decl function_params %type bgp_path bgp_path_tail1 bgp_path_tail2 CF_GRAMMAR @@ -391,7 +391,7 @@ type: | CLIST { $$ = T_CLIST; } | ECLIST { $$ = T_ECLIST; } | LCLIST { $$ = T_LCLIST; } - | type SET { + | type SET { switch ($1) { case T_INT: case T_PAIR: @@ -506,7 +506,7 @@ function_def: } function_params function_body { $2->def = $5; $2->aux2 = $4; - DBG("Hmm, we've got one function here - %s\n", $2->name); + DBG("Hmm, we've got one function here - %s\n", $2->name); cf_pop_scope(); } ; @@ -652,7 +652,7 @@ fprefix: fprefix_s { $$ = $1; } | fprefix_s '+' { $$ = $1; $$.val.px.len |= LEN_PLUS; } | fprefix_s '-' { $$ = $1; $$.val.px.len |= LEN_MINUS; } - | fprefix_s '{' NUM ',' NUM '}' { + | fprefix_s '{' NUM ',' NUM '}' { if (! ((0 <= $3) && ($3 <= $5) && ($5 <= MAX_PREFIX_LENGTH))) cf_error("Invalid prefix pattern range: {%d, %d}.", $3, $5); $$ = $1; $$.val.px.len |= LEN_RANGE | ($3 << 16) | ($5 << 8); } @@ -671,7 +671,7 @@ switch_body: /* EMPTY */ { $$ = NULL; } t->data = $4; $$ = f_merge_items($1, $2); } - | switch_body ELSECOL cmds { + | switch_body ELSECOL cmds { struct f_tree *t = f_new_tree(); t->from.type = t->to.type = T_VOID; t->right = t; @@ -683,7 +683,7 @@ switch_body: /* EMPTY */ { $$ = NULL; } /* CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT; $$->a2.i = $3; } */ bgp_path_expr: - symbol { $$ = $1; } + symbol { $$ = $1; } | '(' term ')' { $$ = $2; } ; @@ -836,8 +836,8 @@ term: | '-' EMPTY '-' { $$ = f_new_inst(); $$->code = 'E'; $$->aux = T_CLIST; } | '-' '-' EMPTY '-' '-' { $$ = f_new_inst(); $$->code = 'E'; $$->aux = T_ECLIST; } | '-' '-' '-' EMPTY '-' '-' '-' { $$ = f_new_inst(); $$->code = 'E'; $$->aux = T_LCLIST; } - | PREPEND '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('A','p'); $$->a1.p = $3; $$->a2.p = $5; } - | ADD '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('C','a'); $$->a1.p = $3; $$->a2.p = $5; $$->aux = 'a'; } + | PREPEND '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('A','p'); $$->a1.p = $3; $$->a2.p = $5; } + | ADD '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('C','a'); $$->a1.p = $3; $$->a2.p = $5; $$->aux = 'a'; } | DELETE '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('C','a'); $$->a1.p = $3; $$->a2.p = $5; $$->aux = 'd'; } | FILTER '(' term ',' term ')' { $$ = f_new_inst(); $$->code = P('C','a'); $$->a1.p = $3; $$->a2.p = $5; $$->aux = 'f'; } @@ -892,7 +892,7 @@ print_list: /* EMPTY */ { $$ = NULL; } } ; -var_listn: term { +var_listn: term { $$ = f_new_inst(); $$->code = 's'; $$->a1.p = NULL; @@ -960,7 +960,7 @@ cmd: $$ = f_new_inst(); $$->code = P('P','S'); $$->a1.p = $3; - } + } | UNSET '(' rtadot dynamic_attr ')' ';' { $$ = $4; $$->aux = EAF_TYPE_UNDEF | EAF_TEMP; diff --git a/filter/filter.h b/filter/filter.h index e0f34e4f..049ceb76 100644 --- a/filter/filter.h +++ b/filter/filter.h @@ -35,7 +35,7 @@ struct f_inst { /* Instruction */ /* Not enough fields in f_inst for three args used by roa_check() */ struct f_inst_roa_check { struct f_inst i; - struct roa_table_config *rtc; + struct roa_table_config *rtc; }; struct f_inst3 { @@ -65,7 +65,7 @@ struct f_val { uint i; u64 ec; lcomm lc; - /* ip_addr ip; Folded into prefix */ + /* ip_addr ip; Folded into prefix */ struct f_prefix px; char *s; struct f_tree *t; @@ -190,16 +190,16 @@ void val_format(struct f_val v, buffer *buf); #define T_PREFIX_SET 0x81 -#define SA_FROM 1 -#define SA_GW 2 -#define SA_NET 3 -#define SA_PROTO 4 -#define SA_SOURCE 5 -#define SA_SCOPE 6 -#define SA_CAST 7 -#define SA_DEST 8 -#define SA_IFNAME 9 -#define SA_IFINDEX 10 +#define SA_FROM 1 +#define SA_GW 2 +#define SA_NET 3 +#define SA_PROTO 4 +#define SA_SOURCE 5 +#define SA_SCOPE 6 +#define SA_CAST 7 +#define SA_DEST 8 +#define SA_IFNAME 9 +#define SA_IFINDEX 10 struct f_tree { diff --git a/filter/tree.c b/filter/tree.c index 1196e630..f8379fa8 100644 --- a/filter/tree.c +++ b/filter/tree.c @@ -63,7 +63,7 @@ tree_compare(const void *p1, const void *p2) * build_tree * @from: degenerated tree (linked by @tree->left) to be transformed into form suitable for find_tree() * - * Transforms denerated tree into balanced tree. + * Transforms degenerated tree into balanced tree. */ struct f_tree * build_tree(struct f_tree *from) @@ -162,7 +162,7 @@ void tree_format(struct f_tree *t, buffer *buf) { buffer_puts(buf, "["); - + tree_node_format(t, buf); if (buf->pos == buf->end) @@ -171,6 +171,6 @@ tree_format(struct f_tree *t, buffer *buf) /* Undo last separator */ if (buf->pos[-1] != '[') buf->pos -= 2; - + buffer_puts(buf, "]"); } diff --git a/lib/buffer.h b/lib/buffer.h index cf073e88..2a53f211 100644 --- a/lib/buffer.h +++ b/lib/buffer.h @@ -1,3 +1,17 @@ +/* + * BIRD Library -- Generic Buffer Structure + * + * (c) 2013 Ondrej Zajicek + * (c) 2013 CZ.NIC z.s.p.o. + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#ifndef _BIRD_BUFFER_H_ +#define _BIRD_BUFFER_H_ + +#include "lib/resource.h" +#include "sysdep/config.h" #define BUFFER(type) struct { type *data; uint used, size; } @@ -32,4 +46,4 @@ #define BUFFER_FLUSH(v) ({ (v).used = 0; }) - +#endif /* _BIRD_BUFFER_H_ */ diff --git a/lib/hash.h b/lib/hash.h index fc5fea14..4239b1d8 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -1,4 +1,14 @@ - +/* + * BIRD Library -- Generic Hash Table + * + * (c) 2013 Ondrej Zajicek + * (c) 2013 CZ.NIC z.s.p.o. + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#ifndef _BIRD_HASH_H_ +#define _BIRD_HASH_H_ #define HASH(type) struct { type **data; uint count, order; } #define HASH_TYPE(v) typeof(** (v).data) @@ -178,3 +188,4 @@ #define HASH_WALK_FILTER_END } while (0) +#endif diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index 8b3feda9..19f2d074 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -678,7 +678,7 @@ link_back(struct ospf_area *oa, struct top_hash_entry *en, struct top_hash_entry which may be later used as the next hop. */ /* In OSPFv2, en->lb is set here. In OSPFv3, en->lb is just cleared here, - it is set in process_prefixes() to any global addres in the area */ + it is set in process_prefixes() to any global address in the area */ en->lb = IPA_NONE; en->lb_id = 0; @@ -930,7 +930,7 @@ ospf_rt_sum_tr(struct ospf_area *oa) } } -/* Decide about originating or flushing summary LSAs for condended area networks */ +/* Decide about originating or flushing summary LSAs for condensed area networks */ static int decide_anet_lsa(struct ospf_area *oa, struct area_net *anet, struct ospf_area *anet_oa) { diff --git a/sysdep/linux/syspriv.h b/sysdep/linux/syspriv.h index d2ba95dd..8b210f06 100644 --- a/sysdep/linux/syspriv.h +++ b/sysdep/linux/syspriv.h @@ -1,4 +1,11 @@ +#ifndef _BIRD_SYSPRIV_H_ +#define _BIRD_SYSPRIV_H_ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include #include #include @@ -70,3 +77,5 @@ drop_uid(uid_t uid) if (setresuid(uid, uid, uid) < 0) die("setresuid: %m"); } + +#endif /* _BIRD_SYSPRIV_H_ */ diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 873b5805..644a4fcd 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -9,7 +9,9 @@ /* Unfortunately, some glibc versions hide parts of RFC 3542 API if _GNU_SOURCE is not defined. */ -#define _GNU_SOURCE 1 +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include #include @@ -2046,6 +2048,7 @@ watchdog_stop(void) volatile int async_config_flag; /* Asynchronous reconfiguration/dump scheduled */ volatile int async_dump_flag; +volatile int async_shutdown_flag; void io_init(void) diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 35bc3fd1..8aa19fce 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -8,7 +8,9 @@ #undef LOCAL_DEBUG -#define _GNU_SOURCE 1 +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include #include -- cgit v1.2.3