]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - nest/rt-dev.c
KRT: Remove KRF_INSTALLED flag
[thirdparty/bird.git] / nest / rt-dev.c
index a996f4fc4b868e6c55fd1c4395498768100db822..61f025cea8a28a974e9542dc579db83934f5184e 100644 (file)
@@ -31,9 +31,10 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad)
   struct rt_dev_proto *p = (void *) P;
   struct rt_dev_config *cf = (void *) P->cf;
   struct channel *c;
+  net_addr *net = &ad->prefix;
 
   if (!EMPTY_LIST(cf->iface_list) &&
-      !iface_patt_find(&cf->iface_list, ad->iface, ad->iface->addr))
+      !iface_patt_find(&cf->iface_list, ad->iface, ad))
     /* Empty list is automatically treated as "*" */
     return;
 
@@ -53,30 +54,31 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad)
   if (!c)
     return;
 
+  /* For IPv6 SADR, replace regular prefix with SADR prefix */
+  if (c->net_type == NET_IP6_SADR)
+  {
+    net = alloca(sizeof(net_addr_ip6_sadr));
+    net_fill_ip6_sadr(net, net6_prefix(&ad->prefix), net6_pxlen(&ad->prefix), IP6_NONE, 0);
+  }
+
   if (flags & IF_CHANGE_DOWN)
     {
-      net *n;
-
       DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
-      n = net_find(c->table, &ad->prefix);
-      if (!n)
-       {
-         DBG("dev_if_notify: device shutdown: prefix not found\n");
-         return;
-       }
 
       /* Use iface ID as local source ID */
       struct rte_src *src = rt_get_source(P, ad->iface->index);
-      rte_update2(c, n, NULL, src);
+      rte_update2(c, net, NULL, src);
     }
   else if (flags & IF_CHANGE_UP)
     {
       rta *a;
-      net *n;
       rte *e;
 
       DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
 
+      if (cf->check_link && !(ad->iface->flags & IF_LINK_UP))
+       return;
+
       /* Use iface ID as local source ID */
       struct rte_src *src = rt_get_source(P, ad->iface->index);
 
@@ -84,30 +86,63 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad)
        .src = src,
        .source = RTS_DEVICE,
        .scope = SCOPE_UNIVERSE,
-       .cast = RTC_UNICAST,
-       .dest = RTD_DEVICE,
-       .iface = ad->iface
+       .dest = RTD_UNICAST,
+       .nh.iface = ad->iface,
       };
 
       a = rta_lookup(&a0);
-      n = net_get(c->table, &ad->prefix);
       e = rte_get_temp(a);
-      e->net = n;
       e->pflags = 0;
-      rte_update2(c, n, e, src);
+      rte_update2(c, net, e, src);
     }
 }
 
+static void
+dev_if_notify(struct proto *p, uint c, struct iface *iface)
+{
+  struct rt_dev_config *cf = (void *) p->cf;
+
+  if (c & (IF_CHANGE_UP | IF_CHANGE_DOWN))
+    return;
+
+  if ((c & IF_CHANGE_LINK) && cf->check_link)
+  {
+    uint ac = (iface->flags & IF_LINK_UP) ? IF_CHANGE_UP : IF_CHANGE_DOWN;
+
+    struct ifa *a;
+    WALK_LIST(a, iface->addrs)
+      dev_ifa_notify(p, ac, a);
+  }
+}
+
+static void
+dev_postconfig(struct proto_config *CF)
+{
+  struct rt_dev_config *cf = (void *) CF;
+  struct channel_config *ip4, *ip6, *ip6_sadr;
+
+  ip4 = proto_cf_find_channel(CF, NET_IP4);
+  ip6 = proto_cf_find_channel(CF, NET_IP6);
+  ip6_sadr = proto_cf_find_channel(CF, NET_IP6_SADR);
+
+  if (ip6 && ip6_sadr)
+    cf_error("Both ipv6 and ipv6-sadr channels");
+
+  cf->ip4_channel = ip4;
+  cf->ip6_channel = ip6 ?: ip6_sadr;
+}
+
 static struct proto *
 dev_init(struct proto_config *CF)
 {
   struct proto *P = proto_new(CF);
   struct rt_dev_proto *p = (void *) P;
-  // struct rt_dev_config *cf = (void *) CF;
+  struct rt_dev_config *cf = (void *) CF;
 
-  proto_configure_channel(P, &p->ip4_channel, proto_cf_find_channel(CF, NET_IP4));
-  proto_configure_channel(P, &p->ip6_channel, proto_cf_find_channel(CF, NET_IP6));
+  proto_configure_channel(P, &p->ip4_channel, cf->ip4_channel);
+  proto_configure_channel(P, &p->ip6_channel, cf->ip6_channel);
 
+  P->if_notify = dev_if_notify;
   P->ifa_notify = dev_ifa_notify;
 
   return P;
@@ -120,12 +155,13 @@ dev_reconfigure(struct proto *P, struct proto_config *CF)
   struct rt_dev_config *o = (void *) P->cf;
   struct rt_dev_config *n = (void *) CF;
 
-  if (!iface_patts_equal(&o->iface_list, &n->iface_list, NULL))
+  if (!iface_patts_equal(&o->iface_list, &n->iface_list, NULL) ||
+      (o->check_link != n->check_link))
     return 0;
 
   return
-    proto_configure_channel(P, &p->ip4_channel, proto_cf_find_channel(CF, NET_IP4)) &&
-    proto_configure_channel(P, &p->ip6_channel, proto_cf_find_channel(CF, NET_IP6));
+    proto_configure_channel(P, &p->ip4_channel, n->ip4_channel) &&
+    proto_configure_channel(P, &p->ip6_channel, n->ip6_channel);
 
   return 1;
 }
@@ -142,16 +178,20 @@ dev_copy_config(struct proto_config *dest, struct proto_config *src)
    * old nodes cannot be modified (although they contain internal lists).
    */
   cfg_copy_list(&d->iface_list, &s->iface_list, sizeof(struct iface_patt));
+
+  d->check_link = s->check_link;
 }
 
 struct protocol proto_device = {
-  .name =              "Direct",
-  .template =          "direct%d",
+  .name =              "Direct",
+  .template =          "direct%d",
+  .class =             PROTOCOL_DIRECT,
   .preference =                DEF_PREF_DIRECT,
-  .channel_mask =      NB_IP,
+  .channel_mask =      NB_IP | NB_IP6_SADR,
   .proto_size =                sizeof(struct rt_dev_proto),
   .config_size =       sizeof(struct rt_dev_config),
-  .init =              dev_init,
-  .reconfigure =       dev_reconfigure,
-  .copy_config =       dev_copy_config
+  .postconfig =                dev_postconfig,
+  .init =              dev_init,
+  .reconfigure =       dev_reconfigure,
+  .copy_config =       dev_copy_config
 };