]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Nest: VRF of protocol can be explicitly specified as 'default'
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 31 Jul 2019 22:53:22 +0000 (00:53 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 31 Jul 2019 22:53:22 +0000 (00:53 +0200)
Protocol can have specified VRF, in such case it is restricted to a set
of ifaces associated with the VRF, otherwise it can use all interfaces.

The patch allows to specify VRF as 'default', in which case it is
restricted to a set of iface not associated with any VRF.

nest/config.Y
nest/iface.c
nest/neighbor.c
nest/proto.c
nest/protocol.h
proto/bfd/bfd.c

index 358c77455778c786bf286d5ce4278446b986a2d5..168bb397ebc7834f340aeebff7f2f1b0d66675c3 100644 (file)
@@ -55,7 +55,7 @@ get_passwords(void)
 CF_DECLS
 
 CF_KEYWORDS(ROUTER, ID, PROTOCOL, TEMPLATE, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
-CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, VRF, TABLE, STATES, ROUTES, FILTERS)
+CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, VRF, DEFAULT, TABLE, STATES, ROUTES, FILTERS)
 CF_KEYWORDS(RECEIVE, LIMIT, ACTION, WARN, BLOCK, RESTART, DISABLE, KEEP, FILTERED)
 CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
 CF_KEYWORDS(ALGORITHM, KEYED, HMAC, MD5, SHA1, SHA256, SHA384, SHA512)
@@ -227,7 +227,8 @@ proto_item:
  | IMPORT LIMIT limit_spec { this_proto->in_limit = $3; }
  | EXPORT LIMIT limit_spec { this_proto->out_limit = $3; }
  | IMPORT KEEP FILTERED bool { this_proto->in_keep_filtered = $4; }
- | VRF text { this_proto->vrf = if_get_by_name($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; }
  | TABLE rtable { this_proto->table = $2; }
  | ROUTER ID idval { this_proto->router_id = $3; }
  | DESCRIPTION text { this_proto->dsc = $2; }
index 1ef161858f8aaa7800b5689f07f5ba18f811a142..556778037afd46d53fe943070924d14c8e546fc9 100644 (file)
@@ -140,7 +140,7 @@ if_copy(struct iface *to, struct iface *from)
 static inline void
 ifa_send_notify(struct proto *p, unsigned c, struct ifa *a)
 {
-  if (p->ifa_notify && (!p->vrf || p->vrf == a->iface->master))
+  if (p->ifa_notify && (!p->vrf_set || p->vrf == a->iface->master))
     {
       if (p->debug & D_IFACES)
        log(L_TRACE "%s <%s address %I/%d on interface %s %s",
@@ -177,7 +177,7 @@ ifa_notify_change(unsigned c, struct ifa *a)
 static inline void
 if_send_notify(struct proto *p, unsigned c, struct iface *i)
 {
-  if (p->if_notify && (!p->vrf || p->vrf == i->master))
+  if (p->if_notify && (!p->vrf_set || p->vrf == i->master))
     {
       if (p->debug & D_IFACES)
        log(L_TRACE "%s < interface %s %s", p->name, i->name,
index f8159d35d4ecb0618bf3827d66e8a47de2f5e23e..1362ae26e04319c0ba1233d2b3de375ebc09a205 100644 (file)
@@ -153,7 +153,7 @@ neigh_find2(struct proto *p, ip_addr *a, struct iface *ifa, unsigned flags)
     }
   else
     WALK_LIST(i, iface_list)
-      if ((!p->vrf || p->vrf == i->master) &&
+      if ((!p->vrf_set || p->vrf == i->master) &&
          ((scope = if_connected(a, i, &addr)) >= 0))
         {
          ifa = i;
index 162441b6716893b867eecccc22fa91a9becacff3..66cb937d5e6b5b6de2469dadca42109cd4203299 100644 (file)
@@ -387,6 +387,7 @@ proto_init(struct proto_config *c)
   q->export_state = ES_DOWN;
   q->last_state_change = now;
   q->vrf = c->vrf;
+  q->vrf_set = c->vrf_set;
 
   add_tail(&initial_proto_list, &q->n);
 
@@ -411,6 +412,7 @@ proto_reconfigure(struct proto *p, struct proto_config *oc, struct proto_config
   if ((nc->protocol != oc->protocol) ||
       (nc->disabled != p->disabled) ||
       (nc->vrf != oc->vrf) ||
+      (nc->vrf_set != oc->vrf_set) ||
       (nc->table->table != oc->table->table))
     return 0;
 
@@ -1567,6 +1569,9 @@ proto_cmd_show(struct proto *p, uintptr_t verbose, int cnt)
       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->proto->show_proto_info)
        p->proto->show_proto_info(p);
       else
index cc1dd5caab8233d68ca0989a2a5e1607013381ff..02fd8d96d6377ff9da57cb539e7b632d7e75378c 100644 (file)
@@ -93,6 +93,7 @@ struct proto_config {
   int class;                           /* SYM_PROTO or SYM_TEMPLATE */
   u32 debug, mrtdump;                  /* Debugging bitfields, both use D_* constants */
   unsigned preference, disabled;       /* Generic parameters */
+  int vrf_set;                         /* Related VRF instance (below) is defined */
   int in_keep_filtered;                        /* Routes rejected in import filter are kept */
   u32 router_id;                       /* Protocol specific router ID */
   struct iface *vrf;                   /* Related VRF instance, NULL if global */
@@ -149,6 +150,7 @@ struct proto {
   unsigned preference;                 /* Default route preference */
   byte accept_ra_types;                        /* Which types of route announcements are accepted (RA_OPTIMAL or RA_ANY) */
   byte disabled;                       /* Manually disabled */
+  byte vrf_set;                                /* Related VRF instance (above) is defined */
   byte proto_state;                    /* Protocol state machine (PS_*, see below) */
   byte core_state;                     /* Core state machine (FS_*, see below) */
   byte export_state;                   /* Route export state (ES_*, see below) */
index c9f1a7e514dc7b8ef13e3c773ec43d3408d45d3c..3af8a2be3055b5ae3a650bbe3125e6ef72531d51 100644 (file)
@@ -624,7 +624,7 @@ bfd_request_notify(struct bfd_request *req, u8 state, u8 diag)
 static int
 bfd_add_request(struct bfd_proto *p, struct bfd_request *req)
 {
-  if (p->p.vrf && (p->p.vrf != req->vrf))
+  if (p->p.vrf_set && (p->p.vrf != req->vrf))
     return 0;
 
   struct bfd_session *s = bfd_find_session_by_addr(p, req->addr);