]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Caching eattrs in filters is not needed anymore.
authorMaria Matejka <mq@ucw.cz>
Wed, 21 Sep 2022 14:53:17 +0000 (16:53 +0200)
committerMaria Matejka <mq@ucw.cz>
Wed, 21 Sep 2022 15:48:31 +0000 (17:48 +0200)
After flattening the route attribute structure, the ea_list ** is derivable
from rte * by arithmetics. Caching the derived value doesn't help performance
and therefore is removed as unnecessary.

filter/f-inst.c
filter/filter.c

index 426b598f548b2aad0f5ca5f76e4651a730d78f06..801eceecfa2ebd0240f532bc0707cbac072912d8 100644 (file)
@@ -70,7 +70,6 @@
  *     m4_dnl    DYNAMIC_ATTR;                         dynamic attribute definition
  *     m4_dnl    RTC;                                  route table config
  *     m4_dnl    ACCESS_RTE;                           this instruction needs route
- *     m4_dnl    ACCESS_EATTRS;                        this instruction needs extended attributes
  *
  *     m4_dnl    FID_MEMBER(                           custom instruction member
  *     m4_dnl      C type,                             for storage in structs
  *     m4_dnl    fpool         -> the current linpool
  *     m4_dnl    NEVER_CONSTANT-> don't generate pre-interpretation code at all
  *     m4_dnl    ACCESS_RTE    -> check that route is available, also NEVER_CONSTANT
- *     m4_dnl    ACCESS_EATTRS -> pre-cache the eattrs; use only with ACCESS_RTE
  *
  *     m4_dnl  If you are stymied, see FI_CALL or FI_CONSTANT or just search for
  *     m4_dnl  the mentioned macros in this file to see what is happening there in wild.
     {
       STATIC_ATTR;
       ACCESS_RTE;
-      ACCESS_EATTRS;
 
       switch (sa.sa_code)
       {
       case SA_PROTO:   RESULT(sa.type, s, fs->rte->src->owner->name); break;
       default:
        {
-         struct eattr *nhea = ea_find(*fs->eattrs, &ea_gen_nexthop);
+         struct eattr *nhea = ea_find(fs->rte->attrs, &ea_gen_nexthop);
          struct nexthop_adata *nhad = nhea ? (struct nexthop_adata *) nhea->u.ptr : NULL;
          struct nexthop *nh = nhad ? &nhad->nh : NULL;
 
 
   INST(FI_RTA_SET, 1, 0) {
     ACCESS_RTE;
-    ACCESS_EATTRS;
     ARG_ANY(1);
     STATIC_ATTR;
     ARG_TYPE(1, sa.type);
        }
       case SA_GW:
        {
-         struct eattr *nh_ea = ea_find(*fs->eattrs, &ea_gen_nexthop);
+         struct eattr *nh_ea = ea_find(fs->rte->attrs, &ea_gen_nexthop);
 
          ip_addr ip = v1.val.ip;
          struct iface *ifa = (ipa_is_link_local(ip) && nh_ea) ?
          if (v1.val.i >= 0x100000)
            runtime( "Invalid MPLS label" );
 
-         struct eattr *nh_ea = ea_find(*fs->eattrs, &ea_gen_nexthop);
+         struct eattr *nh_ea = ea_find(fs->rte->attrs, &ea_gen_nexthop);
          if (!nh_ea)
            runtime( "No nexthop to add a MPLS label to" );
 
          if (i < 1 || i > 256)
            runtime( "Setting weight value out of bounds" );
 
-         struct eattr *nh_ea = ea_find(*fs->eattrs, &ea_gen_nexthop);
+         struct eattr *nh_ea = ea_find(fs->rte->attrs, &ea_gen_nexthop);
          if (!nh_ea)
            runtime( "No nexthop to set weight on" );
 
          NEXTHOP_WALK(nh, nhax)
            nh->weight = i - 1;
 
-         a = ea_set_attr(fs->eattrs,
+         a = ea_set_attr(&fs->rte->attrs,
              EA_LITERAL_DIRECT_ADATA(&ea_gen_nexthop, 0, &nhax->ad));
         }
        break;
       }
 
       if (!a)
-       a = ea_set_attr(fs->eattrs,
+       a = ea_set_attr(&fs->rte->attrs,
            EA_LITERAL_DIRECT_ADATA(&ea_gen_nexthop, 0, tmp_copy_adata(&nha.ad)));
 
       a->originated = 1;
   INST(FI_EA_GET, 0, 1) {      /* Access to extended attributes */
     DYNAMIC_ATTR;
     ACCESS_RTE;
-    ACCESS_EATTRS;
     RESULT_TYPE(da->type);
     {
       const struct f_val *empty;
-      const eattr *e = ea_find(*fs->eattrs, da->id);
+      const eattr *e = ea_find(fs->rte->attrs, da->id);
 
       if (e)
       {
 
   INST(FI_EA_SET, 1, 0) {
     ACCESS_RTE;
-    ACCESS_EATTRS;
     ARG_ANY(1);
     DYNAMIC_ATTR;
     ARG_TYPE(1, da->type);
        break;
 
       case T_IP:
-       a = ea_set_attr(fs->eattrs,
+       a = ea_set_attr(&fs->rte->attrs,
            EA_LITERAL_STORE_ADATA(da, 0, &v1.val.ip, sizeof(ip_addr)));
        break;
 
       default:
-       a = ea_set_attr(fs->eattrs,
+       a = ea_set_attr(&fs->rte->attrs,
            EA_LITERAL_GENERIC(da->id, da->type, 0, .u = v1.val.bval));
        break;
       }
   INST(FI_EA_UNSET, 0, 0) {
     DYNAMIC_ATTR;
     ACCESS_RTE;
-    ACCESS_EATTRS;
 
-    ea_unset_attr(fs->eattrs, 1, da);
+    ea_unset_attr(&fs->rte->attrs, 1, da);
   }
 
   INST(FI_DEFAULT, 2, 1) {
index 9a94545c9f29d92a70af80b6f597e219ac32b1f5..0aff4d30af0ff36c38738c1b95be76f7fa7d30b3 100644 (file)
@@ -76,9 +76,6 @@ struct filter_state {
   /* The route we are processing. This may be NULL to indicate no route available. */
   struct rte *rte;
 
-  /* Cached pointer to ea_list */
-  struct ea_list **eattrs;
-
   /* Buffer for log output */
   struct buffer buf;
 
@@ -94,11 +91,6 @@ void (*bt_assert_hook)(int result, const struct f_line_item *assert);
 
 #define f_stack_init(fs) ( _f_stack_init(fs, v, 128), _f_stack_init(fs, e, 128) )
 
-static inline void f_cache_eattrs(struct filter_state *fs)
-{
-  fs->eattrs = &(fs->rte->attrs);
-}
-
 static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS;
 
 /**
@@ -164,8 +156,6 @@ interpret(struct filter_state *fs, const struct f_line *line, struct f_val *val)
 #define falloc(size)   tmp_alloc(size)
 #define fpool          tmp_linpool
 
-#define ACCESS_EATTRS do { if (!fs->eattrs) f_cache_eattrs(fs); } while (0)
-
 #include "filter/inst-interpret.c"
 #undef res
 #undef v1
@@ -174,7 +164,6 @@ interpret(struct filter_state *fs, const struct f_line *line, struct f_val *val)
 #undef runtime
 #undef falloc
 #undef fpool
-#undef ACCESS_EATTRS
       }
     }