Commit 45475df1 authored by Maria Matejka's avatar Maria Matejka Committed by Maria Matejka
Browse files

Internal API change: passing all the rt_notify() data as a single structure.

parent 1cddde9f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ struct proto {

  void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
  void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
  void (*rt_notify)(struct proto *, struct channel *, struct network *net, struct rte *new, struct rte *old);
  void (*rt_notify)(struct channel *, struct rte_export *);
  void (*neigh_notify)(struct neighbor *neigh);
  int (*preexport)(struct proto *, struct rte **rt, struct linpool *pool);
  void (*reload_routes)(struct channel *);
+10 −0
Original line number Diff line number Diff line
@@ -238,6 +238,16 @@ typedef struct rte {
  btime lastmod;			/* Last modified */
} rte;

/* Route export structure. Protocols get this structure as an information about
 * new routes on the channel. */
struct rte_export {
  net *net;				/* Network information */
  struct rte_src *new_src;		/* New route src (NULL for withdraw) */
  rte *new;				/* New route (NULL for withdraw) */
  struct rte_src *old_src;		/* Old route src */
  rte *old;				/* Old route */
};

#define REF_COW		1		/* Copy this rte on write */
#define REF_FILTERED	2		/* Route is rejected by import filter */
#define REF_STALE	4		/* Route is stale in a refresh cycle */
+9 −1
Original line number Diff line number Diff line
@@ -551,7 +551,15 @@ do_rt_notify(struct channel *c, net *net, rte *new, rte *old, int refeed)
      rte_trace_out(D_ROUTES, c, old, "removed");
  }

  p->rt_notify(p, c, net, new, old);
  struct rte_export export = {
    .net = net,
    .new_src = new ? new->attrs->src : NULL,
    .new = new,
    .old_src = old ? old->attrs->src : NULL,
    .old = old,
  };

  p->rt_notify(c, &export);

  if (c->out_table && old_exported)
    rte_free_quick(old_exported);
+12 −18
Original line number Diff line number Diff line
@@ -2116,38 +2116,32 @@ babel_preexport(struct proto *P, struct rte **new, struct linpool *pool UNUSED)
 * so store it into our data structures.
 */
static void
babel_rt_notify(struct proto *P, struct channel *c UNUSED, struct network *net,
		struct rte *new, struct rte *old UNUSED)
babel_rt_notify(struct channel *c, struct rte_export *export)
{
  struct babel_proto *p = (void *) P;
  struct babel_proto *p = (void *) c->proto;
  struct babel_entry *e;

  if (new)
  if (export->new)
  {
    /* Update */
    uint rt_seqno;
    uint rt_metric = ea_get_int(new->attrs->eattrs, EA_BABEL_METRIC, 0);
    uint rt_metric = ea_get_int(export->new->attrs->eattrs, EA_BABEL_METRIC, 0);
    uint rt_seqno = ea_get_int(export->new->attrs->eattrs, EA_BABEL_SEQNO, p->update_seqno);
    u64 rt_router_id;

    if (new->attrs->src->proto == P)
    {
      rt_seqno = ea_find(new->attrs->eattrs, EA_BABEL_SEQNO)->u.data;
      memcpy(&rt_router_id, ea_find(new->attrs->eattrs, EA_BABEL_ROUTER_ID)->u.ptr->data, sizeof(u64));
    }
    eattr *ea;
    if (ea = ea_find(export->new->attrs->eattrs, EA_BABEL_ROUTER_ID))
      memcpy(&rt_router_id, ea->u.ptr->data, sizeof(u64));
    else
    {
      rt_seqno = p->router_id;
      rt_router_id = p->router_id; 
    }

    if (rt_metric > BABEL_INFINITY)
    {
      log(L_WARN "%s: Invalid babel_metric value %u for route %N",
	  p->p.name, rt_metric, net->n.addr);
	  p->p.name, rt_metric, export->net->n.addr);
      rt_metric = BABEL_INFINITY;
    }

    e = babel_get_entry(p, net->n.addr);
    e = babel_get_entry(p, export->net->n.addr);

    /* Activate triggered updates */
    if ((e->valid != BABEL_ENTRY_VALID) ||
@@ -2165,7 +2159,7 @@ babel_rt_notify(struct proto *P, struct channel *c UNUSED, struct network *net,
  else
  {
    /* Withdraw */
    e = babel_find_entry(p, net->n.addr);
    e = babel_find_entry(p, export->net->n.addr);

    if (!e || e->valid != BABEL_ENTRY_VALID)
      return;
+7 −7
Original line number Diff line number Diff line
@@ -1833,31 +1833,31 @@ bgp_update_attrs(struct bgp_proto *p, struct bgp_channel *c, rte *e, ea_list *at
}

void
bgp_rt_notify(struct proto *P, struct channel *C, net *n, rte *new, rte *old)
bgp_rt_notify(struct channel *C, struct rte_export *e)
{
  struct bgp_proto *p = (void *) P;
  struct bgp_proto *p = (void *) C->proto;
  struct bgp_channel *c = (void *) C;
  struct bgp_bucket *buck;
  struct bgp_prefix *px;
  u32 path;

  if (new)
  if (e->new)
  {
    struct ea_list *attrs = bgp_update_attrs(p, c, new, new->attrs->eattrs, bgp_linpool2);
    struct ea_list *attrs = bgp_update_attrs(p, c, e->new, e->new->attrs->eattrs, bgp_linpool2);

    /* If attributes are invalid, we fail back to withdraw */
    buck = attrs ? bgp_get_bucket(c, attrs) : bgp_get_withdraw_bucket(c);
    path = new->attrs->src->global_id;
    path = e->new_src->global_id;

    lp_flush(bgp_linpool2);
  }
  else
  {
    buck = bgp_get_withdraw_bucket(c);
    path = old->attrs->src->global_id;
    path = e->old_src->global_id;
  }

  px = bgp_get_prefix(c, n->n.addr, c->add_path_tx ? path : 0);
  px = bgp_get_prefix(c, e->net->n.addr, c->add_path_tx ? path : 0);
  add_tail(&buck->prefixes, &px->buck_node);

  bgp_schedule_packet(p->conn, c, PKT_UPDATE);
Loading