Commit a15dab76 authored by Ondrej Zajicek's avatar Ondrej Zajicek
Browse files

Implements 'allow local as' option.

Similar to allowas-in option on other routers.
parent f8cc7396
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1486,6 +1486,16 @@ for each neighbor using the following configuration parameters:
	This option requires that the connected routing table is
	<ref id="dsc-sorted" name="sorted">. Default: off.

	<tag>allow local as [<m/number/]</tag> 
	BGP prevents routing loops by rejecting received routes with
	the local AS number in the AS path. This option allows to
	loose or disable the check. Optional <cf/number/ argument can
	be used to specify the maximum number of local ASNs in the AS
	path that is allowed for received routes. When the option is
	used without the argument, the check is completely disabled
	and you should ensure loop-free behavior by some other means.
	Default: 0 (no local AS number allowed).

	<tag>enable route refresh <m/switch/</tag> When BGP speaker
	changes its import filter, it has to re-examine all routes
	received from its neighbor against the new filter. As these
+1 −1
Original line number Diff line number Diff line
@@ -392,7 +392,7 @@ val_in_range(struct f_val v1, struct f_val v2)
    return as_path_match(v1.val.ad, v2.val.path_mask);

  if ((v1.type == T_INT) && (v2.type == T_PATH))
    return as_path_is_member(v2.val.ad, v1.val.i);
    return as_path_contains(v2.val.ad, v1.val.i, 1);

  if (((v1.type == T_PAIR) || (v1.type == T_QUAD)) && (v2.type == T_CLIST))
    return int_set_contains(v2.val.ad, v1.val.i);
+4 −2
Original line number Diff line number Diff line
@@ -244,10 +244,11 @@ as_path_get_first(struct adata *path, u32 *last_as)
}

int
as_path_is_member(struct adata *path, u32 as)
as_path_contains(struct adata *path, u32 as, int min)
{
  u8 *p = path->data;
  u8 *q = p+path->length;
  int num = 0;
  int i, n;

  while (p<q)
@@ -257,6 +258,7 @@ as_path_is_member(struct adata *path, u32 as)
      for(i=0; i<n; i++)
	{
	  if (get_as(p) == as)
	    if (++num == min)
	      return 1;
	  p += BS;
	}
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ int as_path_getlen(struct adata *path);
int as_path_getlen_int(struct adata *path, int bs);
int as_path_get_first(struct adata *path, u32 *orig_as);
int as_path_get_last(struct adata *path, u32 *last_as);
int as_path_is_member(struct adata *path, u32 as);
int as_path_contains(struct adata *path, u32 as, int min);
int as_path_match_set(struct adata *path, struct f_tree *set);
struct adata *as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 key, int pos);

+2 −1
Original line number Diff line number Diff line
@@ -950,8 +950,9 @@ bgp_create_attrs(struct bgp_proto *p, rte *e, ea_list **attrs, struct linpool *p
static inline int
bgp_as_path_loopy(struct bgp_proto *p, rta *a)
{
  int num = p->cf->allow_local_as + 1;
  eattr *e = ea_find(a->eattrs, EA_CODE(EAP_BGP, BA_AS_PATH));
  return (e && as_path_is_member(e->u.ptr, p->local_as));
  return (e && (num > 0) && as_path_contains(e->u.ptr, p->local_as, num));
}

static inline int
Loading