summaryrefslogtreecommitdiff
path: root/usr.sbin/ospf6d/interface.c
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2007-12-13 08:54:06 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2007-12-13 08:54:06 +0000
commitfafcca9d0e42d9a6e03ef570d77dca5315942a58 (patch)
tree596faa7402ccb9033dc9f620dd603a29a2a3d367 /usr.sbin/ospf6d/interface.c
parent5d7de864ea3c020d02a9416491971c124d8daf39 (diff)
Monster commit of stuff I did mostly last month. What it does:
* removes kif and uses iface for everything interface related. This removes unneeded data redundancy which makes the code more complex. * adds the link local prefix to struct iface and attaches a list with the other prefixes to the struct iface. This is needed to generate the link LSA. * disconnects struct iface from struct area (the backpointer is gone) this will make the reload code a bit easier. norby@ agrees with the direction we're heading with this
Diffstat (limited to 'usr.sbin/ospf6d/interface.c')
-rw-r--r--usr.sbin/ospf6d/interface.c112
1 files changed, 76 insertions, 36 deletions
diff --git a/usr.sbin/ospf6d/interface.c b/usr.sbin/ospf6d/interface.c
index a527d88a72f..76d859aa050 100644
--- a/usr.sbin/ospf6d/interface.c
+++ b/usr.sbin/ospf6d/interface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interface.c,v 1.7 2007/11/27 11:29:34 claudio Exp $ */
+/* $OpenBSD: interface.c,v 1.8 2007/12/13 08:54:05 claudio Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -70,6 +70,8 @@ struct {
static int vlink_cnt = 0;
+TAILQ_HEAD(, iface) iflist;
+
const char * const if_event_names[] = {
"NOTHING",
"UP",
@@ -138,7 +140,7 @@ if_fsm(struct iface *iface, enum iface_event event)
iface->state = new_state;
if (iface->state != old_state)
- orig_rtr_lsa(iface->area);
+ orig_rtr_lsa(iface);
if (old_state & (IF_STA_MULTI | IF_STA_POINTTOPOINT) &&
(iface->state & (IF_STA_MULTI | IF_STA_POINTTOPOINT)) == 0)
@@ -155,8 +157,41 @@ if_fsm(struct iface *iface, enum iface_event event)
return (ret);
}
+int
+if_init(void)
+{
+ TAILQ_INIT(&iflist);
+
+ return (fetchifs(0));
+}
+
+/* XXX using a linked list should be OK for now */
struct iface *
-if_new(struct kif *kif, struct kif_addr *ka)
+if_find(unsigned int ifindex)
+{
+ struct iface *iface;
+
+ TAILQ_FOREACH(iface, &iflist, list) {
+ if (ifindex == iface->ifindex)
+ return (iface);
+ }
+ return (NULL);
+}
+
+struct iface *
+if_findname(char *name)
+{
+ struct iface *iface;
+
+ TAILQ_FOREACH(iface, &iflist, list) {
+ if (!strcmp(name, iface->name))
+ return (iface);
+ }
+ return (NULL);
+}
+
+struct iface *
+if_new(u_short ifindex, char *ifname)
{
struct iface *iface;
@@ -166,10 +201,11 @@ if_new(struct kif *kif, struct kif_addr *ka)
iface->state = IF_STA_DOWN;
LIST_INIT(&iface->nbr_list);
+ TAILQ_INIT(&iface->ifa_list);
TAILQ_INIT(&iface->ls_ack_list);
RB_INIT(&iface->lsa_tree);
- if (kif == NULL) {
+ if (ifname == NULL) {
iface->type = IF_TYPE_VIRTUALLINK;
snprintf(iface->name, sizeof(iface->name), "vlink%d",
vlink_cnt++);
@@ -178,34 +214,33 @@ if_new(struct kif *kif, struct kif_addr *ka)
return (iface);
}
- strlcpy(iface->name, kif->ifname, sizeof(iface->name));
+ strlcpy(iface->name, ifname, sizeof(iface->name));
+ iface->ifindex = ifindex;
+
+ TAILQ_INSERT_TAIL(&iflist, iface, list);
+
+ return (iface);
+}
- /* get type */
- if (kif->flags & IFF_POINTOPOINT)
+void
+if_update(struct iface *iface, int mtu, int flags, u_int8_t type,
+ u_int8_t state, u_int64_t rate)
+{
+ iface->mtu = mtu;
+ iface->flags = flags;
+ iface->media_type = type;
+ iface->linkstate = state;
+ iface->baudrate = rate;
+
+ /* set type */
+ if (flags & IFF_POINTOPOINT)
iface->type = IF_TYPE_POINTOPOINT;
- if (kif->flags & IFF_BROADCAST &&
- kif->flags & IFF_MULTICAST)
+ if (flags & IFF_BROADCAST && flags & IFF_MULTICAST)
iface->type = IF_TYPE_BROADCAST;
- if (kif->flags & IFF_LOOPBACK) {
+ if (flags & IFF_LOOPBACK) {
iface->type = IF_TYPE_POINTOPOINT;
iface->state = IF_STA_LOOPBACK;
}
-
- /* get mtu, index and flags */
- iface->mtu = kif->mtu;
- iface->ifindex = kif->ifindex;
- iface->flags = kif->flags;
- iface->linkstate = kif->link_state;
- iface->media_type = kif->media_type;
- iface->baudrate = kif->baudrate;
-
- /* set address, mask and p2p addr */
- iface->addr = ka->addr;
- if (kif->flags & IFF_POINTOPOINT) {
- iface->dst = ka->dstbrd;
- }
-
- return (iface);
}
void
@@ -231,11 +266,12 @@ if_del(struct iface *iface)
evtimer_del(&iface->lsack_tx_timer);
ls_ack_list_clr(iface);
+ TAILQ_REMOVE(&iflist, iface, list);
free(iface);
}
void
-if_init(struct ospfd_conf *xconf, struct iface *iface)
+if_start(struct ospfd_conf *xconf, struct iface *iface)
{
/* init the dummy local neighbor */
iface->self = nbr_new(ospfe_router_id(), iface, 1);
@@ -248,6 +284,9 @@ if_init(struct ospfd_conf *xconf, struct iface *iface)
iface->fd = xconf->ospf_socket;
ospfe_demote_iface(iface, 0);
+
+ if (if_fsm(iface, IF_EVT_UP))
+ log_debug("error starting interface %s", iface->name);
}
/* timers */
@@ -327,16 +366,17 @@ if_act_start(struct iface *iface)
return (0);
}
- if (iface->media_type == IFT_CARP && iface->passive == 0) {
+ if (iface->media_type == IFT_CARP &&
+ !(iface->cflags & F_IFACE_PASSIVE)) {
/* force passive mode on carp interfaces */
log_warnx("if_act_start: forcing interface %s to passive",
iface->name);
- iface->passive = 1;
+ iface->cflags |= F_IFACE_PASSIVE;
}
- if (iface->passive) {
+ if (iface->cflags & F_IFACE_PASSIVE) {
/* for an update of stub network entries */
- orig_rtr_lsa(iface->area);
+ orig_rtr_lsa(iface);
return (0);
}
@@ -513,7 +553,7 @@ start:
nbr_fsm(nbr, NBR_EVT_ADJ_OK);
}
- orig_rtr_lsa(iface->area);
+ orig_rtr_lsa(iface);
if (iface->state & IF_STA_DR || old_state & IF_STA_DR)
orig_net_lsa(iface);
}
@@ -528,9 +568,9 @@ if_act_reset(struct iface *iface)
struct nbr *nbr = NULL;
struct in6_addr addr;
- if (iface->passive) {
+ if (iface->cflags & F_IFACE_PASSIVE) {
/* for an update of stub network entries */
- orig_rtr_lsa(iface->area);
+ orig_rtr_lsa(iface);
return (0);
}
@@ -594,7 +634,7 @@ if_to_ctl(struct iface *iface)
memcpy(ictl.name, iface->name, sizeof(ictl.name));
memcpy(&ictl.addr, &iface->addr, sizeof(ictl.addr));
ictl.rtr_id.s_addr = ospfe_router_id();
- memcpy(&ictl.area, &iface->area->id, sizeof(ictl.area));
+ memcpy(&ictl.area, &iface->area_id, sizeof(ictl.area));
if (iface->dr) {
memcpy(&ictl.dr_id, &iface->dr->id, sizeof(ictl.dr_id));
memcpy(&ictl.dr_addr, &iface->dr->addr, sizeof(ictl.dr_addr));
@@ -626,7 +666,7 @@ if_to_ctl(struct iface *iface)
ictl.linkstate = iface->linkstate;
ictl.mediatype = iface->media_type;
ictl.priority = iface->priority;
- ictl.passive = iface->passive;
+ ictl.passive = (iface->cflags & F_IFACE_PASSIVE) == F_IFACE_PASSIVE;
gettimeofday(&now, NULL);
if (evtimer_pending(&iface->hello_timer, &tv)) {