diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2010-04-29 12:09:29 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2010-04-29 12:09:29 +0000 |
commit | 23c1ea05f4ae6acb3e67573d05298993f54af4c0 (patch) | |
tree | 258d8dbc368234429059195e43f9965d0a86d110 | |
parent | 84e7323137f5c27bbed25121c0003dcb2e4704e3 (diff) |
Remove some more ospfd-ism from the interface code. This time remove
of most of the IF_TYPE_ special cases and most interface types.
Point-to-point and broadcast still present because of find_iface()
which needs addtional fixing.
OK michele@
-rw-r--r-- | usr.sbin/ldpd/interface.c | 188 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpd.h | 7 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpe.c | 5 | ||||
-rw-r--r-- | usr.sbin/ldpd/log.c | 8 | ||||
-rw-r--r-- | usr.sbin/ldpd/packet.c | 34 |
5 files changed, 66 insertions, 176 deletions
diff --git a/usr.sbin/ldpd/interface.c b/usr.sbin/ldpd/interface.c index daa1c4dbda3..fb14edcbf8f 100644 --- a/usr.sbin/ldpd/interface.c +++ b/usr.sbin/ldpd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.4 2010/04/15 15:39:32 claudio Exp $ */ +/* $OpenBSD: interface.c,v 1.5 2010/04/29 12:09:28 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -57,8 +57,6 @@ struct { {-1, IF_EVT_NOTHING, IF_ACT_NOTHING, 0}, }; -static int vlink_cnt = 0; - const char * const if_event_names[] = { "NOTHING", "UP", @@ -138,15 +136,6 @@ if_new(struct kif *kif, struct kif_addr *ka) LIST_INIT(&iface->nbr_list); LIST_INIT(&iface->lde_nbr_list); - if (kif == NULL) { - iface->type = IF_TYPE_VIRTUALLINK; - snprintf(iface->name, sizeof(iface->name), "vlink%d", - vlink_cnt++); - iface->flags |= IFF_UP; - iface->mtu = IP_MSS; - return (iface); - } - strlcpy(iface->name, kif->ifname, sizeof(iface->name)); /* get type */ @@ -268,23 +257,10 @@ if_act_start(struct iface *iface) gettimeofday(&now, NULL); iface->uptime = now.tv_sec; - switch (iface->type) { - case IF_TYPE_VIRTUALLINK: - case IF_TYPE_POINTOMULTIPOINT: - case IF_TYPE_NBMA: - log_debug("if_act_start: type %s not supported, interface %s", - if_type_name(iface->type), iface->name); + inet_aton(AllRouters, &addr); + if (if_join_group(iface, &addr)) return (-1); - case IF_TYPE_POINTOPOINT: - case IF_TYPE_BROADCAST: - inet_aton(AllRouters, &addr); - if (if_join_group(iface, &addr)) - return (-1); - iface->state = IF_STA_DOWN; - break; - default: - fatalx("if_act_start: unknown interface type"); - } + iface->state = IF_STA_DOWN; /* hello timer needs to be started in any case */ if_start_hello_timer(iface); @@ -297,25 +273,10 @@ if_act_reset(struct iface *iface) /* struct nbr *nbr = NULL; */ struct in_addr addr; - switch (iface->type) { - case IF_TYPE_POINTOPOINT: - case IF_TYPE_BROADCAST: - inet_aton(AllRouters, &addr); - if (if_leave_group(iface, &addr)) { - log_warnx("if_act_reset: error leaving group %s, " - "interface %s", inet_ntoa(addr), iface->name); - } - break; - case IF_TYPE_VIRTUALLINK: - /* nothing */ - break; - case IF_TYPE_NBMA: - case IF_TYPE_POINTOMULTIPOINT: - log_debug("if_act_reset: type %s not supported, interface %s", - if_type_name(iface->type), iface->name); - return (-1); - default: - fatalx("if_act_reset: unknown interface type"); + inet_aton(AllRouters, &addr); + if (if_leave_group(iface, &addr)) { + log_warnx("if_act_reset: error leaving group %s, " + "interface %s", inet_ntoa(addr), iface->name); } /* LIST_FOREACH(nbr, &iface->nbr_list, entry) { @@ -453,46 +414,32 @@ if_join_group(struct iface *iface, struct in_addr *addr) struct ip_mreq mreq; struct if_group_count *ifg; - switch (iface->type) { - case IF_TYPE_POINTOPOINT: - case IF_TYPE_BROADCAST: - LIST_FOREACH(ifg, &ifglist, entry) - if (iface->ifindex == ifg->ifindex && - addr->s_addr == ifg->addr.s_addr) - break; - if (ifg == NULL) { - if ((ifg = calloc(1, sizeof(*ifg))) == NULL) - fatal("if_join_group"); - ifg->addr.s_addr = addr->s_addr; - ifg->ifindex = iface->ifindex; - LIST_INSERT_HEAD(&ifglist, ifg, entry); - } + LIST_FOREACH(ifg, &ifglist, entry) + if (iface->ifindex == ifg->ifindex && + addr->s_addr == ifg->addr.s_addr) + break; + if (ifg == NULL) { + if ((ifg = calloc(1, sizeof(*ifg))) == NULL) + fatal("if_join_group"); + ifg->addr.s_addr = addr->s_addr; + ifg->ifindex = iface->ifindex; + LIST_INSERT_HEAD(&ifglist, ifg, entry); + } - if (ifg->count++ != 0) - /* already joined */ - return (0); + if (ifg->count++ != 0) + /* already joined */ + return (0); - mreq.imr_multiaddr.s_addr = addr->s_addr; - mreq.imr_interface.s_addr = iface->addr.s_addr; + mreq.imr_multiaddr.s_addr = addr->s_addr; + mreq.imr_interface.s_addr = iface->addr.s_addr; - if (setsockopt(iface->discovery_fd, IPPROTO_IP, - IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) { - log_warn("if_join_group: error IP_ADD_MEMBERSHIP, " - "interface %s address %s", iface->name, - inet_ntoa(*addr)); - return (-1); - } - break; - case IF_TYPE_POINTOMULTIPOINT: - case IF_TYPE_VIRTUALLINK: - case IF_TYPE_NBMA: - log_debug("if_join_group: type %s not supported, interface %s", - if_type_name(iface->type), iface->name); + if (setsockopt(iface->discovery_fd, IPPROTO_IP, + IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) { + log_warn("if_join_group: error IP_ADD_MEMBERSHIP, " + "interface %s address %s", iface->name, + inet_ntoa(*addr)); return (-1); - default: - fatalx("if_join_group: unknown interface type"); } - return (0); } @@ -502,69 +449,42 @@ if_leave_group(struct iface *iface, struct in_addr *addr) struct ip_mreq mreq; struct if_group_count *ifg; - switch (iface->type) { - case IF_TYPE_POINTOPOINT: - case IF_TYPE_BROADCAST: - LIST_FOREACH(ifg, &ifglist, entry) - if (iface->ifindex == ifg->ifindex && - addr->s_addr == ifg->addr.s_addr) - break; - - /* if interface is not found just try to drop membership */ - if (ifg && --ifg->count != 0) - /* others still joined */ - return (0); - - mreq.imr_multiaddr.s_addr = addr->s_addr; - mreq.imr_interface.s_addr = iface->addr.s_addr; - - if (setsockopt(iface->discovery_fd, IPPROTO_IP, - IP_DROP_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) { - log_warn("if_leave_group: error IP_DROP_MEMBERSHIP, " - "interface %s address %s", iface->name, - inet_ntoa(*addr)); - return (-1); - } + LIST_FOREACH(ifg, &ifglist, entry) + if (iface->ifindex == ifg->ifindex && + addr->s_addr == ifg->addr.s_addr) + break; - if (ifg) { - LIST_REMOVE(ifg, entry); - free(ifg); - } - break; - case IF_TYPE_POINTOMULTIPOINT: - case IF_TYPE_VIRTUALLINK: - case IF_TYPE_NBMA: - log_debug("if_leave_group: type %s not supported, interface %s", - if_type_name(iface->type), iface->name); + /* if interface is not found just try to drop membership */ + if (ifg && --ifg->count != 0) + /* others still joined */ + return (0); + + mreq.imr_multiaddr.s_addr = addr->s_addr; + mreq.imr_interface.s_addr = iface->addr.s_addr; + + if (setsockopt(iface->discovery_fd, IPPROTO_IP, + IP_DROP_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) { + log_warn("if_leave_group: error IP_DROP_MEMBERSHIP, " + "interface %s address %s", iface->name, + inet_ntoa(*addr)); return (-1); - default: - fatalx("if_leave_group: unknown interface type"); } + if (ifg) { + LIST_REMOVE(ifg, entry); + free(ifg); + } return (0); } int if_set_mcast(struct iface *iface) { - switch (iface->type) { - case IF_TYPE_POINTOPOINT: - case IF_TYPE_BROADCAST: - if (setsockopt(iface->discovery_fd, IPPROTO_IP, IP_MULTICAST_IF, - &iface->addr.s_addr, sizeof(iface->addr.s_addr)) < 0) { - log_debug("if_set_mcast: error setting " - "IP_MULTICAST_IF, interface %s", iface->name); - return (-1); - } - break; - case IF_TYPE_POINTOMULTIPOINT: - case IF_TYPE_VIRTUALLINK: - case IF_TYPE_NBMA: - log_debug("if_set_mcast: type %s not supported, interface %s", - if_type_name(iface->type), iface->name); + if (setsockopt(iface->discovery_fd, IPPROTO_IP, IP_MULTICAST_IF, + &iface->addr.s_addr, sizeof(iface->addr.s_addr)) < 0) { + log_debug("if_set_mcast: error setting " + "IP_MULTICAST_IF, interface %s", iface->name); return (-1); - default: - fatalx("if_set_mcast: unknown interface type"); } return (0); diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h index 9a6d335aead..8b7c4d3e19a 100644 --- a/usr.sbin/ldpd/ldpd.h +++ b/usr.sbin/ldpd/ldpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.h,v 1.14 2010/04/15 15:44:37 claudio Exp $ */ +/* $OpenBSD: ldpd.h,v 1.15 2010/04/29 12:09:28 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -135,10 +135,7 @@ enum iface_action { /* interface types */ enum iface_type { IF_TYPE_POINTOPOINT, - IF_TYPE_BROADCAST, - IF_TYPE_NBMA, - IF_TYPE_POINTOMULTIPOINT, - IF_TYPE_VIRTUALLINK + IF_TYPE_BROADCAST }; /* neighbor states */ diff --git a/usr.sbin/ldpd/ldpe.c b/usr.sbin/ldpd/ldpe.c index 7910a5a2119..22fce4a716a 100644 --- a/usr.sbin/ldpd/ldpe.c +++ b/usr.sbin/ldpd/ldpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.c,v 1.6 2010/04/15 15:04:23 claudio Exp $ */ +/* $OpenBSD: ldpe.c,v 1.7 2010/04/29 12:09:28 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -313,8 +313,7 @@ ldpe_dispatch_main(int fd, short event, void *bula) kif->media_type != IFT_CARP)); LIST_FOREACH(iface, &leconf->iface_list, entry) { - if (kif->ifindex == iface->ifindex && - iface->type != IF_TYPE_VIRTUALLINK) { + if (kif->ifindex == iface->ifindex) { iface->flags = kif->flags; iface->linkstate = kif->link_state; diff --git a/usr.sbin/ldpd/log.c b/usr.sbin/ldpd/log.c index 02a042af5c4..b654a91ea01 100644 --- a/usr.sbin/ldpd/log.c +++ b/usr.sbin/ldpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.4 2010/04/15 15:44:37 claudio Exp $ */ +/* $OpenBSD: log.c,v 1.5 2010/04/29 12:09:28 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -217,12 +217,6 @@ if_type_name(enum iface_type type) return ("POINTOPOINT"); case IF_TYPE_BROADCAST: return ("BROADCAST"); - case IF_TYPE_NBMA: - return ("NBMA"); - case IF_TYPE_POINTOMULTIPOINT: - return ("POINTOMULTIPOINT"); - case IF_TYPE_VIRTUALLINK: - return ("VIRTUALLINK"); } /* NOTREACHED */ return ("UNKNOWN"); diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c index 1df9ae4d204..d87bf6a7fdf 100644 --- a/usr.sbin/ldpd/packet.c +++ b/usr.sbin/ldpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.8 2010/04/15 15:37:51 claudio Exp $ */ +/* $OpenBSD: packet.c,v 1.9 2010/04/29 12:09:28 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -210,22 +210,12 @@ ldp_hdr_sanity_check(struct ldp_hdr *ldp_hdr, u_int16_t len, { struct in_addr addr; - if (iface->type != IF_TYPE_VIRTUALLINK) { - if (ldp_hdr->lspace_id != iface->lspace_id) { - addr.s_addr = ldp_hdr->lspace_id; - log_debug("ldp_hdr_sanity_check: invalid label space " - "ID %s, interface %s", inet_ntoa(addr), - iface->name); - return (-1); - } - } else { - if (ldp_hdr->lspace_id != 0) { - addr.s_addr = ldp_hdr->lspace_id; - log_debug("ldp_hdr_sanity_check: invalid label space " - "ID %s, interface %s", inet_ntoa(addr), - iface->name); - return (-1); - } + if (ldp_hdr->lspace_id != iface->lspace_id) { + addr.s_addr = ldp_hdr->lspace_id; + log_debug("ldp_hdr_sanity_check: invalid label space " + "ID %s, interface %s", inet_ntoa(addr), + iface->name); + return (-1); } return (ntohs(ldp_hdr->length)); @@ -239,11 +229,6 @@ find_iface(struct ldpd_conf *xconf, unsigned int ifindex, struct in_addr src) /* returned interface needs to be active */ LIST_FOREACH(iface, &xconf->iface_list, entry) { switch (iface->type) { - case IF_TYPE_VIRTUALLINK: - if ((src.s_addr == iface->dst.s_addr) && - !iface->passive) - return (iface); - break; case IF_TYPE_POINTOPOINT: if (ifindex == iface->ifindex && iface->dst.s_addr == src.s_addr && @@ -482,11 +467,6 @@ session_find_iface(struct ldpd_conf *xconf, struct in_addr src) /* returned interface needs to be active */ LIST_FOREACH(iface, &xconf->iface_list, entry) { switch (iface->type) { - case IF_TYPE_VIRTUALLINK: - if ((src.s_addr == iface->dst.s_addr) && - !iface->passive) - return (iface); - break; case IF_TYPE_POINTOPOINT: if (iface->dst.s_addr == src.s_addr && !iface->passive) |