]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
VRF setting reduced to one argument, using default dummy iface for default vrf
authorMaria Matejka <mq@ucw.cz>
Mon, 15 Nov 2021 09:53:58 +0000 (10:53 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 25 Jan 2023 12:33:31 +0000 (13:33 +0100)
12 files changed:
nest/config.Y
nest/iface.c
nest/iface.h
nest/neighbor.c
nest/proto.c
nest/protocol.h
proto/babel/babel.c
proto/bfd/bfd.c
proto/bgp/packets.c
proto/ospf/iface.c
proto/radv/radv.c
proto/rip/rip.c

index b2aa0906c0bcde7e183c54021b0c97bcc958bc20..558d7e85a12cd9199b71568189406999cd44ac7f 100644 (file)
@@ -291,8 +291,8 @@ proto_item:
  | MRTDUMP mrtdump_mask { this_proto->mrtdump = $2; }
  | ROUTER ID idval { this_proto->router_id = $3; }
  | DESCRIPTION text { this_proto->dsc = $2; }
- | VRF text { this_proto->vrf = if_get_by_name($2); this_proto->vrf_set = 1; }
- | VRF DEFAULT { this_proto->vrf = NULL; this_proto->vrf_set = 1; }
+ | VRF text { this_proto->vrf = if_get_by_name($2); }
+ | VRF DEFAULT { this_proto->vrf = &default_vrf; }
  ;
 
 
index 682340c56cff227e880187f4d7ac6eabe4795932..fc896e2667c164240c30c8bb696f911be0d0520e 100644 (file)
@@ -37,6 +37,7 @@
 static pool *if_pool;
 
 list iface_list;
+struct iface default_vrf;
 
 static void if_recalc_preferred(struct iface *i);
 
@@ -147,7 +148,7 @@ ifa_send_notify(struct proto *p, unsigned c, struct ifa *a)
 {
   if (p->ifa_notify &&
       (p->proto_state != PS_DOWN) &&
-      (!p->vrf_set || p->vrf == a->iface->master))
+      (!p->vrf || p->vrf == a->iface->master))
     {
       if (p->debug & D_IFACES)
        log(L_TRACE "%s < address %N on interface %s %s",
@@ -185,7 +186,7 @@ if_send_notify(struct proto *p, unsigned c, struct iface *i)
 {
   if (p->if_notify &&
       (p->proto_state != PS_DOWN) &&
-      (!p->vrf_set || p->vrf == i->master))
+      (!p->vrf || p->vrf == i->master))
     {
       if (p->debug & D_IFACES)
        log(L_TRACE "%s < interface %s %s", p->name, i->name,
@@ -243,7 +244,7 @@ if_recalc_flags(struct iface *i UNUSED, uint flags)
 {
   if ((flags & IF_ADMIN_UP) &&
       !(flags & (IF_SHUTDOWN | IF_TMP_DOWN)) &&
-      !(i->master_index && !i->master))
+      !(i->master_index && i->master == &default_vrf))
     flags |= IF_UP;
   else
     flags &= ~IF_UP;
@@ -301,6 +302,9 @@ if_update(struct iface *new)
   struct iface *i;
   unsigned c;
 
+  if (!new->master)
+    new->master = &default_vrf;
+
   WALK_LIST(i, iface_list)
     if (!strcmp(new->name, i->name))
       {
@@ -711,6 +715,7 @@ if_init(void)
 {
   if_pool = rp_new(&root_pool, "Interfaces");
   init_list(&iface_list);
+  strcpy(default_vrf.name, "default");
   neigh_init(if_pool);
 }
 
@@ -843,7 +848,7 @@ if_show(void)
        continue;
 
       char mbuf[16 + sizeof(i->name)] = {};
-      if (i->master)
+      if (i->master != &default_vrf)
        bsprintf(mbuf, " master=%s", i->master->name);
       else if (i->master_index)
        bsprintf(mbuf, " master=#%u", i->master_index);
index 1189cdd4cad49955339f3a665842e6f04f84a65d..13f3bd12e78f0649177677f1ee10fd2da96bd1f1 100644 (file)
@@ -28,6 +28,8 @@ struct ifa {                          /* Interface address */
   unsigned flags;                      /* Analogous to iface->flags */
 };
 
+extern struct iface default_vrf;
+
 struct iface {
   node n;
   char name[16];
index 7cf9c85d75e117a4cf65c9c27033c82e5b59fe5f..81da24d5b5867f9872babda5da197bced5939962 100644 (file)
@@ -142,7 +142,7 @@ if_connected(ip_addr a, struct iface *i, struct ifa **ap, uint flags)
 }
 
 static inline int
-if_connected_any(ip_addr a, struct iface *vrf, uint vrf_set, struct iface **iface, struct ifa **addr, uint flags)
+if_connected_any(ip_addr a, struct iface *vrf, struct iface **iface, struct ifa **addr, uint flags)
 {
   struct iface *i;
   struct ifa *b;
@@ -153,7 +153,7 @@ if_connected_any(ip_addr a, struct iface *vrf, uint vrf_set, struct iface **ifac
 
   /* Prefer SCOPE_HOST or longer prefix */
   WALK_LIST(i, iface_list)
-    if ((!vrf_set || vrf == i->master) && ((s = if_connected(a, i, &b, flags)) >= 0))
+    if ((!vrf || vrf == i->master) && ((s = if_connected(a, i, &b, flags)) >= 0))
       if (scope_better(s, scope) || (scope_remote(s, scope) && ifa_better(b, *addr)))
       {
        *iface = i;
@@ -245,7 +245,7 @@ neigh_find(struct proto *p, ip_addr a, struct iface *iface, uint flags)
     iface = (scope < 0) ? NULL : iface;
   }
   else
-    scope = if_connected_any(a, p->vrf, p->vrf_set, &iface, &addr, flags);
+    scope = if_connected_any(a, p->vrf, &iface, &addr, flags);
 
   /* scope < 0 means i don't know neighbor */
   /* scope >= 0  <=>  iface != NULL */
@@ -369,7 +369,7 @@ neigh_update(neighbor *n, struct iface *iface)
     return;
 
   /* VRF-bound neighbors ignore changes in other VRFs */
-  if (p->vrf_set && (p->vrf != iface->master))
+  if (p->vrf && (p->vrf != iface->master))
     return;
 
   scope = if_connected(n->addr, iface, &ifa, n->flags);
@@ -379,7 +379,7 @@ neigh_update(neighbor *n, struct iface *iface)
   {
     /* When neighbor is going down, try to respawn it on other ifaces */
     if ((scope < 0) && (n->scope >= 0) && !n->ifreq && (n->flags & NEF_STICKY))
-      scope = if_connected_any(n->addr, p->vrf, p->vrf_set, &iface, &ifa, n->flags);
+      scope = if_connected_any(n->addr, p->vrf, &iface, &ifa, n->flags);
   }
   else
   {
index 885a0b7523fa1017001e8abd4cd125c816a04bfd..26d648f3791831379e9359425462e4d242e8c19a 100644 (file)
@@ -1025,7 +1025,6 @@ proto_init(struct proto_config *c, node *n)
   p->proto_state = PS_DOWN;
   p->last_state_change = current_time();
   p->vrf = c->vrf;
-  p->vrf_set = c->vrf_set;
   insert_node(&p->n, n);
 
   p->event = ev_new_init(proto_pool, proto_event, p);
@@ -1193,8 +1192,7 @@ proto_reconfigure(struct proto *p, struct proto_config *oc, struct proto_config
   if ((nc->protocol != oc->protocol) ||
       (nc->net_type != oc->net_type) ||
       (nc->disabled != p->disabled) ||
-      (nc->vrf != oc->vrf) ||
-      (nc->vrf_set != oc->vrf_set))
+      (nc->vrf != oc->vrf))
     return 0;
 
   p->name = nc->name;
@@ -2075,8 +2073,8 @@ proto_cmd_show(struct proto *p, uintptr_t verbose, int cnt)
       cli_msg(-1006, "  Message:        %s", p->message);
     if (p->cf->router_id)
       cli_msg(-1006, "  Router ID:      %R", p->cf->router_id);
-    if (p->vrf_set)
-      cli_msg(-1006, "  VRF:            %s", p->vrf ? p->vrf->name : "default");
+    if (p->vrf)
+      cli_msg(-1006, "  VRF:            %s", p->vrf->name);
 
     if (p->proto->show_proto_info)
       p->proto->show_proto_info(p);
index fcbf0539afd686f400d2a26dfa1adaacc0b1ec8e..fef2cb917a441efb0497e5a3c637f6d381b26764 100644 (file)
@@ -120,7 +120,6 @@ struct proto_config {
   int class;                           /* SYM_PROTO or SYM_TEMPLATE */
   u8 net_type;                         /* Protocol network type (NET_*), 0 for undefined */
   u8 disabled;                         /* Protocol enabled/disabled by default */
-  u8 vrf_set;                          /* Related VRF instance (below) is defined */
   u32 debug, mrtdump;                  /* Debugging bitfields, both use D_* constants */
   u32 router_id;                       /* Protocol specific router ID */
 
@@ -177,7 +176,6 @@ struct proto {
   uint active_channels;                        /* Number of active channels */
   byte net_type;                       /* Protocol network type (NET_*), 0 for undefined */
   byte disabled;                       /* Manually disabled */
-  byte vrf_set;                                /* Related VRF instance (above) is defined */
   byte proto_state;                    /* Protocol state machine (PS_*, see below) */
   byte active;                         /* From PS_START to cleanup after PS_STOP */
   byte do_start;                       /* Start actions are scheduled */
index ff8b6b52ef4a3f3c06f1447ec452c246d2841716..ad7981f6087ca77728ceb5079c094f916c5a95be 100644 (file)
@@ -1946,7 +1946,7 @@ babel_reconfigure_ifaces(struct babel_proto *p, struct babel_config *cf)
 
   WALK_LIST(iface, iface_list)
   {
-    if (p->p.vrf_set && p->p.vrf != iface->master)
+    if (p->p.vrf && p->p.vrf != iface->master)
       continue;
 
     if (!(iface->flags & IF_UP))
index 873e2ed5cc80b18fcd975139b11c00b40cc4986e..69e42f3d9aeb3bd6d66063efba11606226c172ea 100644 (file)
@@ -659,7 +659,7 @@ bfd_add_request(struct bfd_proto *p, struct bfd_request *req)
 {
   struct bfd_config *cf = (struct bfd_config *) (p->p.cf);
 
-  if (p->p.vrf_set && (p->p.vrf != req->vrf))
+  if (p->p.vrf && (p->p.vrf != req->vrf))
     return 0;
 
   if (ipa_is_ip4(req->addr) ? !cf->accept_ipv4 : !cf->accept_ipv6)
index 16818cf39f9bbafd5a5f3b99091bfd0b4281db5e..6244b62fc7f67c4a7de79cbe71bbe403e00e9e72 100644 (file)
@@ -1130,7 +1130,7 @@ bgp_use_next_hop(struct bgp_export_state *s, eattr *a)
     return 0;
 
   /* Do not pass NEXT_HOP between different VRFs */
-  if (p->p.vrf_set && s->src && s->src->p.vrf_set && (p->p.vrf != s->src->p.vrf))
+  if (p->p.vrf && s->src && s->src->p.vrf && (p->p.vrf != s->src->p.vrf))
     return 0;
 
   /* Keep it when exported to internal peers */
@@ -1163,7 +1163,7 @@ bgp_use_gateway(struct bgp_export_state *s)
     return 0;
 
   /* Do not use gateway from different VRF */
-  if (p->p.vrf_set && ra->nh.iface && (p->p.vrf != ra->nh.iface->master))
+  if (p->p.vrf && ra->nh.iface && (p->p.vrf != ra->nh.iface->master))
     return 0;
 
   /* Use it when exported to internal peers */
index 87e3d95eb6aecbd8ab06b66216dc06c9b39c5cb7..84c53aa138440a1538c56035a22ae3b9c764cdeb 100644 (file)
@@ -1227,7 +1227,7 @@ ospf_reconfigure_ifaces2(struct ospf_proto *p)
 
   WALK_LIST(iface, iface_list)
   {
-    if (p->p.vrf_set && p->p.vrf != iface->master)
+    if (p->p.vrf && p->p.vrf != iface->master)
       continue;
 
     if (! (iface->flags & IF_UP))
@@ -1276,7 +1276,7 @@ ospf_reconfigure_ifaces3(struct ospf_proto *p)
 
   WALK_LIST(iface, iface_list)
   {
-    if (p->p.vrf_set && p->p.vrf != iface->master)
+    if (p->p.vrf && p->p.vrf != iface->master)
       continue;
 
     if (! (iface->flags & IF_UP))
index 119a8dc41c980d4cfe9209c1b2757a84cd3507ae..8b547f6d79b9419851decbc8d4a3adb145ff544e 100644 (file)
@@ -663,7 +663,7 @@ radv_reconfigure(struct proto *P, struct proto_config *CF)
   struct iface *iface;
   WALK_LIST(iface, iface_list)
   {
-    if (p->p.vrf_set && p->p.vrf != iface->master)
+    if (p->p.vrf && p->p.vrf != iface->master)
       continue;
 
     if (!(iface->flags & IF_UP))
index 8c2d5aebdee75829b13e0d8895b027f89552d515..ca21884630e0cd00535a2d5a32013b9b96bc6105 100644 (file)
@@ -797,7 +797,7 @@ rip_reconfigure_ifaces(struct rip_proto *p, struct rip_config *cf)
 
   WALK_LIST(iface, iface_list)
   {
-    if (p->p.vrf_set && p->p.vrf != iface->master)
+    if (p->p.vrf && p->p.vrf != iface->master)
       continue;
 
     if (!(iface->flags & IF_UP))