]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Moved advertising router info (FROM attribute) to eattrs
authorMaria Matejka <mq@ucw.cz>
Wed, 20 Apr 2022 11:56:04 +0000 (13:56 +0200)
committerMaria Matejka <mq@ucw.cz>
Wed, 4 May 2022 13:39:21 +0000 (15:39 +0200)
filter/config.Y
filter/data.h
filter/f-inst.c
lib/route.h
nest/rt-attr.c
nest/rt-show.c
nest/rt-table.c
proto/babel/babel.c
proto/bgp/packets.c
proto/rip/rip.c

index dcfae7881ce5b9797674a6d17afa0c25496e3313..e24233aa10ec9af5004bc3939bccb77ac9d20818 100644 (file)
@@ -762,8 +762,7 @@ symbol_value: CF_SYM_KNOWN
  ;
 
 static_attr:
-   FROM    { $$ = f_new_static_attr(T_IP,         SA_FROM,     0); }
- | GW      { $$ = f_new_static_attr(T_IP,         SA_GW,       0); }
+   GW      { $$ = f_new_static_attr(T_IP,         SA_GW,       0); }
  | NET     { $$ = f_new_static_attr(T_NET,       SA_NET,       1); }
  | PROTO   { $$ = f_new_static_attr(T_STRING,     SA_PROTO,    1); }
  | SOURCE  { $$ = f_new_static_attr(T_ENUM_RTS,   SA_SOURCE,   1); }
index 0e25ccd94a8e31be99024e72e4f931ad22f3cc0f..a0a164ed0f9de8c8be3b0b3c3209ec40527c06d9 100644 (file)
@@ -22,8 +22,7 @@ struct f_val {
 #define fputip(a)   ({ ip_addr *ax = falloc(sizeof(*ax)); *ax = (a); ax; })
 
 enum f_sa_code {
-  SA_FROM = 1,
-  SA_GW,
+  SA_GW = 1,
   SA_NET,
   SA_PROTO,
   SA_SOURCE,
index 9530d9ad8271ff461170667dcecc3660f36cc247..7158d22e6eddcf151d79887880616e0490a0ac3d 100644 (file)
 
       switch (sa.sa_code)
       {
-      case SA_FROM:    RESULT(sa.type, ip, rta->from); break;
       case SA_GW:      RESULT(sa.type, ip, rta->nh.gw); break;
       case SA_NET:     RESULT(sa.type, net, (*fs->rte)->net->n.addr); break;
       case SA_PROTO:   RESULT(sa.type, s, (*fs->rte)->src->proto->name); break;
 
       switch (sa.sa_code)
       {
-      case SA_FROM:
-       rta->from = v1.val.ip;
-       break;
-
       case SA_GW:
        {
          ip_addr ip = v1.val.ip;
index be72bb16341c063861e4008e1e3160c4495166e4..e02c63b30bca9d00c2dd517c9a482c07b1757543 100644 (file)
@@ -84,7 +84,6 @@ typedef struct rta {
   u32 hash_key;                                /* Hash over important fields */
   struct ea_list *eattrs;              /* Extended Attribute chain */
   struct hostentry *hostentry;         /* Hostentry for recursive next-hops */
-  ip_addr from;                                /* Advertising router */
   u16 cached:1;                                /* Are attributes cached? */
   u16 source:7;                                /* Route source (RTS_...) */
   u16 scope:4;                         /* Route scope (SCOPE_... -- see ip.h) */
@@ -219,6 +218,13 @@ static inline eattr *ea_find_by_name(ea_list *l, const char *name)
     (ea ? ea->u.data : (_def)); \
     })
 
+#define ea_get_ip(_l, _ident, _def)  ({ \
+    struct ea_class *cls = ea_class_find((_ident)); \
+    ASSERT_DIE(cls->type == T_IP); \
+    const eattr *ea = ea_find((_l), cls->id); \
+    (ea ? *((const ip_addr *) ea->u.ptr->data) : (_def)); \
+    })
+
 eattr *ea_walk(struct ea_walk_state *s, uint id, uint max);
 void ea_dump(ea_list *);
 int ea_same(ea_list *x, ea_list *y);   /* Test whether two ea_lists are identical */
@@ -300,6 +306,8 @@ u32 rt_get_igp_metric(rte *rt);
 #define IGP_METRIC_UNKNOWN 0x80000000  /* Default igp_metric used when no other
                                           protocol-specific metric is availabe */
 
+/* From: Advertising router */
+extern struct ea_class ea_gen_from;
 
 /* Next hop structures */
 
index e5d87b536bfb557b5ff956d47766c5ff9f99168b..87f54b0d27efbd917999e1fb13f4baf9c9633926 100644 (file)
@@ -70,6 +70,11 @@ struct ea_class ea_gen_preference = {
   .type = T_INT,
 };
 
+struct ea_class ea_gen_from = {
+  .name = "from",
+  .type = T_IP,
+};
+
 const char * const rta_src_names[RTS_MAX] = {
   [RTS_STATIC]         = "static",
   [RTS_INHERIT]                = "inherit",
@@ -1229,7 +1234,6 @@ rta_hash(rta *a)
 #define MIX(f) mem_hash_mix(&h, &(a->f), sizeof(a->f));
 #define BMIX(f) mem_hash_mix_num(&h, a->f);
   MIX(hostentry);
-  MIX(from);
   BMIX(source);
   BMIX(scope);
   BMIX(dest);
@@ -1244,7 +1248,6 @@ rta_same(rta *x, rta *y)
   return (x->source == y->source &&
          x->scope == y->scope &&
          x->dest == y->dest &&
-         ipa_equal(x->from, y->from) &&
          x->hostentry == y->hostentry &&
          nexthop_same(&(x->nh), &(y->nh)) &&
          ea_same(x->eattrs, y->eattrs));
@@ -1398,7 +1401,6 @@ rta_dump(rta *a)
        rtd[a->dest], a->hash_key);
   if (!a->cached)
     debug(" !CACHED");
-  debug(" <-%I", a->from);
   if (a->dest == RTD_UNICAST)
     for (struct nexthop *nh = &(a->nh); nh; nh = nh->next)
       {
@@ -1475,6 +1477,7 @@ rta_init(void)
 
   ea_register_init(&ea_gen_preference);
   ea_register_init(&ea_gen_igp_metric);
+  ea_register_init(&ea_gen_from);
 }
 
 /*
index 1c764d8caa0ce2d60709ec4d9fb66856234e5493..be4c01862c1b8f2d75e7a5933b699ff505841c83 100644 (file)
@@ -48,8 +48,9 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary
   struct nexthop *nh;
 
   tm_format_time(tm, &config->tf_route, e->lastmod);
-  if (ipa_nonzero(a->from) && !ipa_equal(a->from, a->nh.gw))
-    bsprintf(from, " from %I", a->from);
+  ip_addr a_from = ea_get_ip(a->eattrs, &ea_gen_from, IPA_NONE);
+  if (ipa_nonzero(a_from) && !ipa_equal(a_from, a->nh.gw))
+    bsprintf(from, " from %I", a_from);
   else
     from[0] = 0;
 
index 919576bdeb83423021af43a89555f9d79dc0e452..e8b04e0b5adbd0f28b7792f2242029c3f45f2957 100644 (file)
@@ -2596,7 +2596,10 @@ rt_flowspec_check(rtable *tab_ip, rtable *tab_flow, const net_addr *n, rta *a, i
   u32 orig_b = ea_get_int(rb->attrs->eattrs, "bgp_originator_id", 0);
 
   /* Originator is either ORIGINATOR_ID (if present), or BGP neighbor address (if not) */
-  if ((orig_a != orig_b) || (!orig_a && !orig_b && !ipa_equal(a->from, rb->attrs->from)))
+  if ((orig_a != orig_b) || (!orig_a && !orig_b && !ipa_equal(
+         ea_get_ip(a->eattrs, &ea_gen_from, IPA_NONE),
+         ea_get_ip(rb->attrs->eattrs, &ea_gen_from, IPA_NONE)
+         )))
     return 0;
 
 
index afd0b1e104544622a010d7ad278b011e6a7d3994..f4503b99048986b3822cf3db8a7f6af214f85627 100644 (file)
@@ -645,11 +645,12 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
   {
     struct {
       ea_list l;
-      eattr a[4];
+      eattr a[5];
     } eattrs = {
       .l.count = ARRAY_SIZE(eattrs.a),
       .a = {
        EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, c->preference),
+       EA_LITERAL_STORE_ADATA(&ea_gen_from, 0, &r->neigh->addr, sizeof(r->neigh->addr)),
        EA_LITERAL_EMBEDDED(&ea_babel_metric, 0, r->metric),
        EA_LITERAL_STORE_ADATA(&ea_babel_router_id, 0, &r->router_id, sizeof(r->router_id)),
        EA_LITERAL_EMBEDDED(&ea_babel_seqno, 0, r->seqno),
@@ -660,7 +661,6 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
       .source = RTS_BABEL,
       .scope = SCOPE_UNIVERSE,
       .dest = RTD_UNICAST,
-      .from = r->neigh->addr,
       .nh.gw = r->next_hop,
       .nh.iface = r->neigh->ifa->iface,
       .eattrs = &eattrs.l,
index 45a4b1deee0fdeb1c71a0dc7ad4d794d82191bce..9760ebeedef767d949909ad285b6a575afaedf48 100644 (file)
@@ -2476,8 +2476,9 @@ bgp_decode_nlri(struct bgp_parse_state *s, u32 afi, byte *nlri, uint len, ea_lis
 
     a->source = RTS_BGP;
     a->scope = SCOPE_UNIVERSE;
-    a->from = s->proto->remote_ip;
     a->eattrs = ea;
+
+    ea_set_attr_data(&a->eattrs, &ea_gen_from, 0, &s->proto->remote_ip, sizeof(ip_addr));
     ea_set_attr_u32(&a->eattrs, &ea_gen_preference, 0, c->c.preference);
 
     c->desc->decode_next_hop(s, nh, nh_len, a);
index 244bcd0aa8bb52c71a829c5edd73da1aa84b6b83..7c097a92579ccac58b7b0768ccf8b3a2e63151c3 100644 (file)
@@ -157,7 +157,18 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
       .dest = RTD_UNICAST,
     };
 
-    u8 rt_metric = rt->metric;
+    struct {
+      ea_list l;
+      eattr a[2];
+    } ea_block = {
+      .l.count = ARRAY_SIZE(ea_block.a),
+      .a = {
+       EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, p->p.main_channel->preference),
+       EA_LITERAL_EMBEDDED(&ea_rip_metric, 0, rt->metric),
+      },
+    };
+    a0.eattrs = &ea_block.l;
+
     u16 rt_tag = rt->tag;
 
     if (p->ecmp)
@@ -189,30 +200,19 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
     else
     {
       /* Unipath route */
-      a0.from = rt->from->nbr->addr;
       a0.nh.gw = rt->next_hop;
       a0.nh.iface = rt->from->ifa->iface;
+      ea_set_attr_data(&a0.eattrs, &ea_gen_from, 0, &rt->from->nbr->addr, sizeof(ip_addr));
     }
 
-    struct {
-      ea_list l;
-      eattr a[4];
-      struct rip_iface_adata riad;
-    } ea_block = {
-      .l.count = ARRAY_SIZE(ea_block.a),
-      .a = {
-       EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, p->p.main_channel->preference),
-       EA_LITERAL_EMBEDDED(&ea_rip_metric, 0, rt_metric),
-       EA_LITERAL_EMBEDDED(&ea_rip_tag, 0, rt_tag),
-       EA_LITERAL_DIRECT_ADATA(&ea_rip_from, 0, &ea_block.riad.ad),
-      },
-      .riad = {
-       .ad = { .length = sizeof(struct rip_iface_adata) - sizeof(struct adata) },
-       .iface = a0.nh.iface,
-      },
-    };
+    ea_set_attr_u32(&a0.eattrs, &ea_rip_tag, 0, rt_tag);
 
-    a0.eattrs = &ea_block.l;
+    struct rip_iface_adata riad = {
+      .ad = { .length = sizeof(struct rip_iface_adata) - sizeof(struct adata) },
+      .iface = a0.nh.iface,
+    };
+    ea_set_attr(&a0.eattrs,
+       EA_LITERAL_DIRECT_ADATA(&ea_rip_from, 0, &riad.ad));
 
     rta *a = rta_lookup(&a0);
     rte *e = rte_get_temp(a, p->p.main_source);