]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Adds igp_metric attribute.
authorOndrej Zajicek <santiago@crfreenet.org>
Mon, 2 Aug 2010 11:11:53 +0000 (13:11 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Mon, 2 Aug 2010 11:11:53 +0000 (13:11 +0200)
nest/config.Y
nest/route.h
nest/rt-attr.c
nest/rt-table.c
proto/ospf/ospf.c

index a8e6bf8cd74abb1e4daf9c39be828bd3e9668bbb..39cd9015f0f227fbab37d1b9a9a90caf0240b560 100644 (file)
@@ -45,7 +45,7 @@ CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILT
 CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
 CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREEXPORT, GENERATE)
 CF_KEYWORDS(LISTEN, BGP, V6ONLY, ADDRESS, PORT, PASSWORDS, DESCRIPTION)
-CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT, MEMORY)
+CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT, MEMORY, IGP_METRIC)
 
 CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
        RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
@@ -497,6 +497,9 @@ proto_patt2:
  | TEXT { $$.ptr = $1; $$.patt = 1; }
  ;
 
+CF_ADDTO(dynamic_attr, IGP_METRIC
+       { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_GEN_IGP_METRIC); })
+
 
 CF_CODE
 
index d062e60024235773e90ef132a9fdf1077e9126e4..a849bf0073efe71dcfbd3bdc0d2843ff0c418c15 100644 (file)
@@ -340,6 +340,8 @@ typedef struct eattr {
 #define EA_PROTO(ea) ((ea) >> 8)
 #define EA_ID(ea) ((ea) & 0xff)
 
+#define EA_GEN_IGP_METRIC EA_CODE(EAP_GENERIC, 0)
+
 #define EA_CODE_MASK 0xffff
 #define EA_ALLOW_UNDEF 0x10000         /* ea_find: allow EAF_TYPE_UNDEF */
 
index d71481889acd2a8ec2c6f334baa66bbc6fc9bdcc..ce6fe85d98e1f6f9e702d272b08685d52d015605 100644 (file)
@@ -362,6 +362,18 @@ ea_free(ea_list *o)
     }
 }
 
+static int
+get_generic_attr(eattr *a, byte **buf, int buflen UNUSED)
+{
+  if (a->id == EA_GEN_IGP_METRIC)
+    {
+      *buf += bsprintf(*buf, "igp_metric");
+      return GA_NAME;
+    }
+  return GA_UNKNOWN;
+}
+
 /**
  * ea_format - format an &eattr for printing
  * @e: attribute to be formatted
@@ -392,6 +404,9 @@ ea_format(eattr *e, byte *buf)
     }
   else if (EA_PROTO(e->id))
     buf += bsprintf(buf, "%02x.", EA_PROTO(e->id));
+  else 
+    status = get_generic_attr(e, &buf, end - buf);
+
   if (status < GA_NAME)
     buf += bsprintf(buf, "%02x", EA_ID(e->id));
   if (status < GA_FULL)
index b73f52fa63585b6aa030b62c4aea9c08ca3d4ce8..ef0704282ebee85e2388fadf13015f85df626e36 100644 (file)
@@ -1473,6 +1473,11 @@ if_local_addr(ip_addr a, struct iface *i)
 static u32 
 rt_get_igp_metric(rte *rt)
 {
+  eattr *ea = ea_find(rt->attrs->eattrs, EA_GEN_IGP_METRIC);
+
+  if (ea)
+    return ea->u.data;
+
   rta *a = rt->attrs;
   if ((a->source == RTS_OSPF) ||
       (a->source == RTS_OSPF_IA) ||
index 316d7292f6ff61b32327dd9fc91514d240925cfc..e1ba96a4f35cf2b0bce4eaec6cd97b62b3429180 100644 (file)
@@ -467,7 +467,11 @@ ospf_import_control(struct proto *p, rte ** new, ea_list ** attrs,
 
   if (p == e->attrs->proto)
     return -1;                 /* Reject our own routes */
-  *attrs = ospf_build_attrs(*attrs, pool, LSINFINITY, 10000, 0, 0);
+
+  eattr *ea = ea_find(e->attrs->eattrs, EA_GEN_IGP_METRIC);
+  u32 m1 = (ea && (ea->u.data < LSINFINITY)) ? ea->u.data : LSINFINITY;
+
+  *attrs = ospf_build_attrs(*attrs, pool, m1, 10000, 0, 0);
   return 0;                    /* Leave decision to the filters */
 }