diff options
author | Mathieu Sauve-Frankel <msf@cvs.openbsd.org> | 2005-09-17 20:03:36 +0000 |
---|---|---|
committer | Mathieu Sauve-Frankel <msf@cvs.openbsd.org> | 2005-09-17 20:03:36 +0000 |
commit | c9c2fe62e362a702c65ef453e373b7e5530b0fbb (patch) | |
tree | b7cde13de9d05ddff03fabf78ba2aa28e555935f | |
parent | 26cfcca5489626640cdd8936655643f2aad98bde (diff) |
- add get_rtr_id() based on bgpd's get_bgpid()
- remove rtr_id from struct iface we don't need to keep a copy of this value
per interface
- replace all references to iface->rtr_id.s_addr with calls to ospfe_rtr_id()
ok claudio@ norby@
-rw-r--r-- | usr.sbin/ospfd/database.c | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/hello.c | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/interface.c | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 3 | ||||
-rw-r--r-- | usr.sbin/ospfd/packet.c | 4 | ||||
-rw-r--r-- | usr.sbin/ospfd/parse.y | 36 |
6 files changed, 43 insertions, 12 deletions
diff --git a/usr.sbin/ospfd/database.c b/usr.sbin/ospfd/database.c index 518f0277822..7f3be686aa8 100644 --- a/usr.sbin/ospfd/database.c +++ b/usr.sbin/ospfd/database.c @@ -1,4 +1,4 @@ -/* $OpenBSD: database.c,v 1.12 2005/05/27 05:51:22 norby Exp $ */ +/* $OpenBSD: database.c,v 1.13 2005/09/17 20:03:35 msf Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -215,7 +215,7 @@ recv_db_description(struct nbr *nbr, char *buf, u_int16_t len) if (dd_hdr.bits == (OSPF_DBD_I | OSPF_DBD_M | OSPF_DBD_MS)) { /* if nbr Router ID is larger than own -> slave */ if ((ntohl(nbr->id.s_addr)) > - ntohl(nbr->iface->rtr_id.s_addr)) { + ntohl(ospfe_router_id())) { /* slave */ nbr->master = 0; nbr->dd_seq_num = ntohl(dd_hdr.dd_seq_num); diff --git a/usr.sbin/ospfd/hello.c b/usr.sbin/ospfd/hello.c index 35c43164e46..eba687512ac 100644 --- a/usr.sbin/ospfd/hello.c +++ b/usr.sbin/ospfd/hello.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hello.c,v 1.9 2005/08/30 21:07:58 claudio Exp $ */ +/* $OpenBSD: hello.c,v 1.10 2005/09/17 20:03:35 msf Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -203,7 +203,7 @@ recv_hello(struct iface *iface, struct in_addr src, u_int32_t rtr_id, char *buf, while (len >= sizeof(nbr_id)) { memcpy(&nbr_id, buf, sizeof(nbr_id)); - if (nbr_id == iface->rtr_id.s_addr) { + if (nbr_id == ospfe_router_id()) { /* seen myself */ if (nbr->state & NBR_STA_PRELIM) nbr_fsm(nbr, NBR_EVT_2_WAY_RCVD); diff --git a/usr.sbin/ospfd/interface.c b/usr.sbin/ospfd/interface.c index 3c783df5c8f..ccb81f54e52 100644 --- a/usr.sbin/ospfd/interface.c +++ b/usr.sbin/ospfd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.32 2005/09/15 19:42:51 claudio Exp $ */ +/* $OpenBSD: interface.c,v 1.33 2005/09/17 20:03:35 msf Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -598,7 +598,7 @@ if_to_ctl(struct iface *iface) memcpy(ictl.name, iface->name, sizeof(ictl.name)); memcpy(&ictl.addr, &iface->addr, sizeof(ictl.addr)); memcpy(&ictl.mask, &iface->mask, sizeof(ictl.mask)); - memcpy(&ictl.rtr_id, &iface->rtr_id, sizeof(ictl.rtr_id)); + ictl.rtr_id.s_addr = ospfe_router_id(); memcpy(&ictl.area, &iface->area->id, sizeof(ictl.area)); if (iface->dr) { memcpy(&ictl.dr_id, &iface->dr->id, sizeof(ictl.dr_id)); diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index 09718b3a11b..1a772d5f304 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.35 2005/06/26 19:22:12 claudio Exp $ */ +/* $OpenBSD: ospfd.h,v 1.36 2005/09/17 20:03:35 msf Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -302,7 +302,6 @@ struct iface { struct in_addr addr; struct in_addr dst; struct in_addr mask; - struct in_addr rtr_id; struct in_addr abr_id; char *auth_key; struct nbr *dr; /* designated router */ diff --git a/usr.sbin/ospfd/packet.c b/usr.sbin/ospfd/packet.c index 24b79074dda..bdfe4a6846e 100644 --- a/usr.sbin/ospfd/packet.c +++ b/usr.sbin/ospfd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.11 2005/08/11 16:28:07 henning Exp $ */ +/* $OpenBSD: packet.c,v 1.12 2005/09/17 20:03:35 msf Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -49,7 +49,7 @@ gen_ospf_hdr(struct buf *buf, struct iface *iface, u_int8_t type) bzero(&ospf_hdr, sizeof(ospf_hdr)); ospf_hdr.version = OSPF_VERSION; ospf_hdr.type = type; - ospf_hdr.rtr_id = iface->rtr_id.s_addr; + ospf_hdr.rtr_id = ospfe_router_id(); if (iface->type != IF_TYPE_VIRTUALLINK) ospf_hdr.area_id = iface->area->id.s_addr; ospf_hdr.auth_type = htons(iface->auth_type); diff --git a/usr.sbin/ospfd/parse.y b/usr.sbin/ospfd/parse.y index 90cd81b6bae..d9b1864c064 100644 --- a/usr.sbin/ospfd/parse.y +++ b/usr.sbin/ospfd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.17 2005/09/15 20:24:46 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.18 2005/09/17 20:03:35 msf Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -31,6 +31,7 @@ #include <ctype.h> #include <err.h> #include <errno.h> +#include <ifaddrs.h> #include <stdarg.h> #include <stdio.h> #include <string.h> @@ -62,6 +63,7 @@ int findeol(void); int yylex(void); void clear_config(struct ospfd_conf *xconf); int check_file_secrecy(int fd, const char *fname); +u_int32_t get_rtr_id(void); static struct { u_int32_t dead_interval; @@ -430,7 +432,6 @@ interface : INTERFACE STRING { iface->area = area; LIST_INSERT_HEAD(&area->iface_list, iface, entry); - iface->rtr_id = conf->rtr_id; iface->passive = 0; } interface_block { iface = NULL; @@ -821,6 +822,9 @@ parse_config(char *filename, int opts) return (NULL); } + if (conf->rtr_id.s_addr == 0) + conf->rtr_id.s_addr = get_rtr_id(); + return (conf); } @@ -969,3 +973,31 @@ clear_config(struct ospfd_conf *xconf) /* XXX clear conf */ /* ... */ } + +u_int32_t +get_rtr_id(void) +{ + struct ifaddrs *ifap, *ifa; + u_int32_t ip = 0, cur, localnet; + + localnet = htonl(INADDR_LOOPBACK & IN_CLASSA_NET); + + if (getifaddrs(&ifap) == -1) + fatal("getifaddrs"); + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (ifa->ifa_addr->sa_family != AF_INET) + continue; + cur = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; + if ((cur & localnet) == localnet) /* skip 127/8 */ + continue; + if (cur > ip || ip == 0) + ip = cur; + } + freeifaddrs(ifap); + + if (ip == 0) + fatal("router-id is 0.0.0.0"); + + return (ip); +} |