]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Kernel preferred interface address updater decoupled from the lib
authorMaria Matejka <mq@ucw.cz>
Mon, 2 Sep 2024 09:52:00 +0000 (11:52 +0200)
committerMaria Matejka <mq@ucw.cz>
Sun, 23 Feb 2025 17:28:45 +0000 (18:28 +0100)
nest/iface.c
nest/iface.h
sysdep/bsd/krt-sock.c
sysdep/linux/netlink.c
sysdep/unix/krt.Y
sysdep/unix/krt.c
sysdep/unix/krt.h

index 9071809765ac212bdf49cd46caf65310b8866902..92da1213ce1c5aaecf426bdb32e860f088f2eee5 100644 (file)
@@ -32,7 +32,6 @@
 #include "lib/string.h"
 #include "lib/locking.h"
 #include "conf/conf.h"
-#include "sysdep/unix/krt.h"
 
 DOMAIN(attrs) iface_domain;
 
@@ -784,6 +783,8 @@ if_set_preferred(struct ifa **pos, struct ifa *new)
   *pos = new;
 }
 
+int (*kif_update_sysdep_addr)(struct iface *) = NULL;
+
 static void
 if_recalc_preferred(struct iface *i)
 {
@@ -793,14 +794,14 @@ if_recalc_preferred(struct iface *i)
    * 2) Sysdep IPv4 address (BSD)
    * 3) Old preferred address
    * 4) First address in list
-   */
+  */
 
-  struct kif_iface_config *ic = kif_get_iface_config(i);
+  struct iface_config *ic = i->cf;
   struct ifa *a4 = i->addr4, *a6 = i->addr6, *ll = i->llv6;
   ip_addr pref_v4 = ic->pref_v4;
   uint change = 0;
 
-  if (kif_update_sysdep_addr(i))
+  if (kif_update_sysdep_addr && kif_update_sysdep_addr(i))
     change |= IF_CHANGE_SYSDEP;
 
   /* BSD sysdep address */
index a065a2263d5f4b8242aad2ed17f743ba6d8030f8..ca084df6571367b03d617ca41a6f6161a8c55033 100644 (file)
@@ -46,10 +46,14 @@ struct iface {
   struct ifa *addr6;                   /* Primary address for IPv6 */
   struct ifa *llv6;                    /* Primary link-local address for IPv6 */
   ip4_addr sysdep;                     /* Arbitrary IPv4 address for internal sysdep use */
+  struct iface_config *cf;             /* Attached configuration */
   list neighbors;                      /* All neighbors on this interface */
   unsigned uc;                         /* Use (link) count */
 };
 
+/* Sysdep address updater */
+extern int (*kif_update_sysdep_addr)(struct iface *);
+
 #define IF_UP 1                                /* Currently just IF_ADMIN_UP */
 #define IF_MULTIACCESS 2
 #define IF_BROADCAST 4
@@ -284,6 +288,15 @@ int iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a);
 struct iface_patt *iface_patt_find(list *l, struct iface *i, struct ifa *a);
 int iface_patts_equal(list *, list *, int (*)(struct iface_patt *, struct iface_patt *));
 
+/* Basic interface configuration */
+struct iface_config {
+  struct iface_patt i;
+
+  ip_addr pref_v4;
+  ip_addr pref_v6;
+  ip_addr pref_ll;
+};
+
 
 u32 if_choose_router_id(struct iface_patt *mask, u32 old_id);
 
index d80ac0df3ec1175cec48facde7210a48f68f03d7..097979bb3f0799f9814e6fa41d4b384f998c0953 100644 (file)
@@ -721,6 +721,8 @@ krt_read_ifinfo(struct ks_msg *msg, int scan)
   if (fl & IFF_MULTICAST)
     f.flags |= IF_MULTICAST;
 
+  f.cf = kif_get_iface_config(&f);
+
   iface = if_update(&f);
 
   if (!scan)
@@ -1196,19 +1198,14 @@ void krt_sys_copy_config(struct krt_config *d, struct krt_config *s)
 
 /* KIF misc code */
 
-void
-kif_sys_start(struct kif_proto *p UNUSED)
-{
-}
-
 void
 kif_sys_shutdown(struct kif_proto *p)
 {
   krt_buffer_release(&p->p);
 }
 
-int
-kif_update_sysdep_addr(struct iface *i)
+static int
+kif_update_sysdep_addr_(struct iface *i)
 {
   static int fd = -1;
 
@@ -1228,3 +1225,10 @@ kif_update_sysdep_addr(struct iface *i)
 
   return !ip4_equal(i->sysdep, old);
 }
+
+void
+kif_sys_start(struct kif_proto *p UNUSED)
+{
+  /* Setup sysdep address updater */
+  kif_update_sysdep_addr = kif_update_sysdep_addr_;
+}
index 1703a67595d5ae7957381882da07466b59875d56..4d85f79025842337d15ad3b6b036cc1dd326b287 100644 (file)
@@ -1110,6 +1110,8 @@ nl_parse_link(struct nlmsghdr *h, int scan)
       if (kind && !strcmp(kind, "vrf"))
        f.flags |= IF_VRF;
 
+      f.cf = kif_get_iface_config(&f);
+
       ifi = if_update(&f);
 
       if (!scan)
@@ -1363,6 +1365,8 @@ kif_do_scan(struct kif_proto *p UNUSED)
 
       if (f.master != i->master)
       {
+       f.cf = kif_get_iface_config(&f);
+
        memcpy(f.name, i->name, sizeof(f.name));
        if_update_locked(&f);
       }
@@ -2254,9 +2258,3 @@ void
 kif_sys_shutdown(struct kif_proto *p UNUSED)
 {
 }
-
-int
-kif_update_sysdep_addr(struct iface *i UNUSED)
-{
-  return 0;
-}
index 7b58c657422df57d43a9af0ce108fb9ff3e1a502..80a85ba09b4dd594bb1daaf03f080b633720a34f 100644 (file)
@@ -14,7 +14,7 @@ CF_DEFINES
 
 #define THIS_KRT ((struct krt_config *) this_proto)
 #define THIS_KIF ((struct kif_config *) this_proto)
-#define KIF_IFACE ((struct kif_iface_config *) this_ipatt)
+#define KIF_IFACE ((struct iface_config *) this_ipatt)
 
 static void
 kif_set_preferred(ip_addr ip)
@@ -112,7 +112,7 @@ kif_item:
 
 kif_iface_start:
 {
-  this_ipatt = cfg_allocz(sizeof(struct kif_iface_config));
+  this_ipatt = cfg_allocz(sizeof(struct iface_config));
   add_tail(&THIS_KIF->iface_list, NODE this_ipatt);
   init_list(&this_ipatt->ipn_list);
 }
index 81c073cfd056c38e43913dcd08ed02ef96cdd570..37c3ae0d929a51bee22d15bd4e4587bb62f324b9 100644 (file)
@@ -89,13 +89,13 @@ static struct kif_config *kif_cf;
 static timer *kif_scan_timer;
 static btime kif_last_shot;
 
-static struct kif_iface_config kif_default_iface = {};
+static struct iface_config kif_default_iface = {};
 
-struct kif_iface_config *
+struct iface_config *
 kif_get_iface_config(struct iface *iface)
 {
   struct kif_config *cf = (void *) (kif_proto->p.cf);
-  struct kif_iface_config *ic = (void *) iface_patt_find(&cf->iface_list, iface, NULL);
+  struct iface_config *ic = (void *) iface_patt_find(&cf->iface_list, iface, NULL);
   return ic ?: &kif_default_iface;
 }
 
@@ -232,7 +232,7 @@ kif_copy_config(struct proto_config *dest, struct proto_config *src)
   struct kif_config *s = (struct kif_config *) src;
 
   /* Copy interface config list */
-  cfg_copy_list(&d->iface_list, &s->iface_list, sizeof(struct kif_iface_config));
+  cfg_copy_list(&d->iface_list, &s->iface_list, sizeof(struct iface_config));
 
   /* Fix sysdep parts */
   kif_sys_copy_config(d, s);
index e16a4cc8c7d08498187b0d0c8f17475b904c15aa..350d4973c7674d22787e434397690047ad9a1993 100644 (file)
@@ -105,18 +105,10 @@ struct kif_config {
   struct proto_config c;
   struct kif_params sys;       /* Sysdep params */
 
-  list iface_list;             /* List of iface configs (struct kif_iface_config) */
+  list iface_list;             /* List of iface configs (struct iface_config) */
   btime scan_time;             /* How often we re-scan interfaces */
 };
 
-struct kif_iface_config {
-  struct iface_patt i;
-
-  ip_addr pref_v4;
-  ip_addr pref_v6;
-  ip_addr pref_ll;
-};
-
 struct kif_proto {
   struct proto p;
   struct kif_state sys;                /* Sysdep state */
@@ -126,7 +118,7 @@ extern struct kif_proto *kif_proto;
 
 #define KIF_CF ((struct kif_config *)p->p.cf)
 
-struct kif_iface_config * kif_get_iface_config(struct iface *iface);
+struct iface_config * kif_get_iface_config(struct iface *iface);
 struct proto_config * krt_init_config(int class);
 
 
@@ -161,6 +153,4 @@ void kif_sys_copy_config(struct kif_config *, struct kif_config *);
 
 void kif_do_scan(struct kif_proto *);
 
-int kif_update_sysdep_addr(struct iface *i);
-
 #endif