diff options
author | 2005-04-25 11:31:50 +0000 | |
---|---|---|
committer | 2005-04-25 11:31:50 +0000 | |
commit | 1d887742b0815eb847efb955aea4710530da28cf (patch) | |
tree | b672bebb8b09b637886fe3a7bd4781576829f825 | |
parent | Move the creation of the ospf_socket from if_init() directly into ospfe(). (diff) | |
download | wireguard-openbsd-1d887742b0815eb847efb955aea4710530da28cf.tar.xz wireguard-openbsd-1d887742b0815eb847efb955aea4710530da28cf.zip |
Call if_init() later and for each interface separately.
Move code from if_act_start() to if_init() that needs to be called only
once per interface. Especially event_set should be called only once as it
initializes struct event and so may cause corruption of the event queue if
called twice.
-rw-r--r-- | usr.sbin/ospfd/interface.c | 64 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.c | 6 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.h | 4 |
3 files changed, 31 insertions, 43 deletions
diff --git a/usr.sbin/ospfd/interface.c b/usr.sbin/ospfd/interface.c index ffa8654624e..f8fdeac424b 100644 --- a/usr.sbin/ospfd/interface.c +++ b/usr.sbin/ospfd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.19 2005/04/25 09:55:18 claudio Exp $ */ +/* $OpenBSD: interface.c,v 1.20 2005/04/25 11:31:50 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -236,35 +236,34 @@ if_del(struct iface *iface) return (-1); } -int -if_init(struct ospfd_conf *xconf) +void +if_init(struct ospfd_conf *xconf, struct iface *iface) { - struct area *area = NULL; - struct iface *iface = NULL; - - LIST_FOREACH(area, &xconf->area_list, entry) { - LIST_FOREACH(iface, &area->iface_list, entry) { - switch (iface->type) { - case IF_TYPE_POINTOPOINT: - iface->fd = xconf->ospf_socket; - break; - case IF_TYPE_BROADCAST: - /* all bcast interfaces use the same socket */ - iface->fd = xconf->ospf_socket; - break; - case IF_TYPE_NBMA: - break; - case IF_TYPE_POINTOMULTIPOINT: - break; - case IF_TYPE_VIRTUALLINK: - break; - default: - fatalx("if_init: unknown interface type"); - } - } - } + /* init the dummy local neighbor */ + iface->self = nbr_new(ospfe_router_id(), iface, 1); - return (0); + /* set event handlers for interface */ + evtimer_set(&iface->lsack_tx_timer, ls_ack_tx_timer, iface); + evtimer_set(&iface->hello_timer, if_hello_timer, iface); + evtimer_set(&iface->wait_timer, if_wait_timer, iface); + + switch (iface->type) { + case IF_TYPE_POINTOPOINT: + iface->fd = xconf->ospf_socket; + break; + case IF_TYPE_BROADCAST: + /* all bcast interfaces use the same socket */ + iface->fd = xconf->ospf_socket; + break; + case IF_TYPE_NBMA: + break; + case IF_TYPE_POINTOMULTIPOINT: + break; + case IF_TYPE_VIRTUALLINK: + break; + default: + fatalx("if_init: unknown interface type"); + } } int @@ -352,15 +351,6 @@ if_act_start(struct iface *iface) return (0); } - /* init the dummy local neighbor */ - if (iface->self == NULL) - iface->self = nbr_new(ospfe_router_id(), iface, 1); - - /* set event handlers for interface */ - evtimer_set(&iface->lsack_tx_timer, ls_ack_tx_timer, iface); - evtimer_set(&iface->hello_timer, if_hello_timer, iface); - evtimer_set(&iface->wait_timer, if_wait_timer, iface); - switch (iface->type) { case IF_TYPE_POINTOPOINT: inet_aton(AllSPFRouters, &addr); diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c index 72db7f8d89b..a3b5688417d 100644 --- a/usr.sbin/ospfd/ospfe.c +++ b/usr.sbin/ospfd/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.16 2005/04/25 09:55:18 claudio Exp $ */ +/* $OpenBSD: ospfe.c,v 1.17 2005/04/25 11:31:50 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -104,9 +104,6 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2], if (if_set_tos(xconf->ospf_socket, IPTOS_PREC_INTERNETCONTROL) == -1) fatal("if_set_tos"); - if (if_init(xconf)) - fatalx("error initializing interfaces"); - oeconf = xconf; if ((pw = getpwnam(OSPFD_USER)) == NULL) @@ -173,6 +170,7 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2], /* start interfaces */ LIST_FOREACH(area, &oeconf->area_list, entry) { LIST_FOREACH(iface, &area->iface_list, entry) { + if_init(xconf, iface); if (if_fsm(iface, IF_EVT_UP)) { log_debug("error starting interface %s", iface->name); diff --git a/usr.sbin/ospfd/ospfe.h b/usr.sbin/ospfd/ospfe.h index 23254b5e100..0a84c3b6c3d 100644 --- a/usr.sbin/ospfd/ospfe.h +++ b/usr.sbin/ospfd/ospfe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.h,v 1.13 2005/04/25 09:55:18 claudio Exp $ */ +/* $OpenBSD: ospfe.h,v 1.14 2005/04/25 11:31:50 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -187,7 +187,7 @@ int if_fsm(struct iface *, enum iface_event); struct iface *if_new(struct kif *); int if_del(struct iface *); -int if_init(struct ospfd_conf *); +void if_init(struct ospfd_conf *, struct iface *); int if_shutdown(struct ospfd_conf *); int if_act_start(struct iface *); |