#include "lib/string.h"
#include "lib/locking.h"
#include "conf/conf.h"
-#include "sysdep/unix/krt.h"
DOMAIN(attrs) iface_domain;
*pos = new;
}
+int (*kif_update_sysdep_addr)(struct iface *) = NULL;
+
static void
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 */
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
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);
if (fl & IFF_MULTICAST)
f.flags |= IF_MULTICAST;
+ f.cf = kif_get_iface_config(&f);
+
iface = if_update(&f);
if (!scan)
/* 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;
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_;
+}
if (kind && !strcmp(kind, "vrf"))
f.flags |= IF_VRF;
+ f.cf = kif_get_iface_config(&f);
+
ifi = if_update(&f);
if (!scan)
if (f.master != i->master)
{
+ f.cf = kif_get_iface_config(&f);
+
memcpy(f.name, i->name, sizeof(f.name));
if_update_locked(&f);
}
kif_sys_shutdown(struct kif_proto *p UNUSED)
{
}
-
-int
-kif_update_sysdep_addr(struct iface *i UNUSED)
-{
- return 0;
-}
#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)
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);
}
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;
}
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);
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 */
#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);
void kif_do_scan(struct kif_proto *);
-int kif_update_sysdep_addr(struct iface *i);
-
#endif