summaryrefslogtreecommitdiff
path: root/sys/netinet6/in6_ifattach.c
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2017-09-01 16:48:28 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2017-09-01 16:48:28 +0000
commitf7d24970f329668044723c14a26b3d8cd2d36d3a (patch)
tree2b649ac61bc5d036a2b21353fc3fae51f7d50b80 /sys/netinet6/in6_ifattach.c
parentac8265d2920c4d46285a136d6791d20eae204c45 (diff)
Use in6_get_rand_ifid() instead of get_last_resort_ifid() and delete the
get_last_resort_ifid() function because eww. Also if your system is so constraint that you end up in in6_get_rand_ifid() you don't deserve a random ifid that stays stable over reboots. Simplify code a bit since get_ifid() can no longer fail. It couldn't fail before either because that code path was #if 0'ed. While here sprinkle in some in6_ prefixes, pointed out by stsp. OK stsp
Diffstat (limited to 'sys/netinet6/in6_ifattach.c')
-rw-r--r--sys/netinet6/in6_ifattach.c83
1 files changed, 16 insertions, 67 deletions
diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c
index 89acde9c6a4..87614373686 100644
--- a/sys/netinet6/in6_ifattach.c
+++ b/sys/netinet6/in6_ifattach.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_ifattach.c,v 1.103 2017/07/11 12:51:05 florian Exp $ */
+/* $OpenBSD: in6_ifattach.c,v 1.104 2017/09/01 16:48:27 florian Exp $ */
/* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */
/*
@@ -56,10 +56,10 @@
#include <netinet6/ip6_mroute.h>
#endif
-int get_last_resort_ifid(struct ifnet *, struct in6_addr *);
-int get_hw_ifid(struct ifnet *, struct in6_addr *);
-int get_ifid(struct ifnet *, struct in6_addr *);
-int in6_ifattach_loopback(struct ifnet *);
+void in6_get_rand_ifid(struct ifnet *, struct in6_addr *);
+int in6_get_hw_ifid(struct ifnet *, struct in6_addr *);
+void in6_get_ifid(struct ifnet *, struct in6_addr *);
+int in6_ifattach_loopback(struct ifnet *);
#define EUI64_GBIT 0x01
#define EUI64_UBIT 0x02
@@ -73,45 +73,6 @@ int in6_ifattach_loopback(struct ifnet *);
#define IFID_UNIVERSAL(in6) (!EUI64_UNIVERSAL(in6))
/*
- * Generate a last-resort interface identifier, when the machine has no
- * IEEE802/EUI64 address sources.
- * The goal here is to get an interface identifier that is
- * (1) random enough and (2) does not change across reboot.
- * We currently use SHA512(hostname) for it.
- *
- * in6 - upper 64bits are preserved
- */
-int
-get_last_resort_ifid(struct ifnet *ifp, struct in6_addr *in6)
-{
- SHA2_CTX ctx;
- u_int8_t digest[SHA512_DIGEST_LENGTH];
-
-#if 0
- /* we need at least several letters as seed for ifid */
- if (hostnamelen < 3)
- return -1;
-#endif
-
- /* generate 8 bytes of pseudo-random value. */
- SHA512Init(&ctx);
- SHA512Update(&ctx, hostname, hostnamelen);
- SHA512Final(digest, &ctx);
-
- /* assumes sizeof(digest) > sizeof(ifid) */
- bcopy(digest, &in6->s6_addr[8], 8);
-
- /* make sure to set "u" bit to local, and "g" bit to individual. */
- in6->s6_addr[8] &= ~EUI64_GBIT; /* g bit to "individual" */
- in6->s6_addr[8] |= EUI64_UBIT; /* u bit to "local" */
-
- /* convert EUI64 into IPv6 interface identifier */
- EUI64_TO_IFID(in6);
-
- return 0;
-}
-
-/*
* Generate a random interface identifier.
*
* in6 - upper 64bits are preserved
@@ -135,7 +96,7 @@ in6_get_rand_ifid(struct ifnet *ifp, struct in6_addr *in6)
* in6 - upper 64bits are preserved
*/
int
-get_hw_ifid(struct ifnet *ifp, struct in6_addr *in6)
+in6_get_hw_ifid(struct ifnet *ifp, struct in6_addr *in6)
{
struct sockaddr_dl *sdl;
char *addr;
@@ -235,13 +196,13 @@ get_hw_ifid(struct ifnet *ifp, struct in6_addr *in6)
* available on ifp0, borrow interface identifier from other information
* sources.
*/
-int
-get_ifid(struct ifnet *ifp0, struct in6_addr *in6)
+void
+in6_get_ifid(struct ifnet *ifp0, struct in6_addr *in6)
{
struct ifnet *ifp;
/* first, try to get it from the interface itself */
- if (get_hw_ifid(ifp0, in6) == 0) {
+ if (in6_get_hw_ifid(ifp0, in6) == 0) {
nd6log((LOG_DEBUG, "%s: got interface identifier from itself\n",
ifp0->if_xname));
goto success;
@@ -251,7 +212,7 @@ get_ifid(struct ifnet *ifp0, struct in6_addr *in6)
TAILQ_FOREACH(ifp, &ifnet, if_list) {
if (ifp == ifp0)
continue;
- if (get_hw_ifid(ifp, in6) != 0)
+ if (in6_get_hw_ifid(ifp, in6) != 0)
continue;
/*
@@ -267,22 +228,15 @@ get_ifid(struct ifnet *ifp0, struct in6_addr *in6)
}
/* last resort: get from random number source */
- if (get_last_resort_ifid(ifp, in6) == 0) {
- nd6log((LOG_DEBUG,
- "%s: interface identifier generated by random number\n",
- ifp0->if_xname));
- goto success;
- }
-
- printf("%s: failed to get interface identifier\n", ifp0->if_xname);
- return -1;
-
+ in6_get_rand_ifid(ifp, in6);
+ nd6log((LOG_DEBUG,
+ "%s: interface identifier generated by random number\n",
+ ifp0->if_xname));
success:
nd6log((LOG_INFO, "%s: ifid: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
ifp0->if_xname, in6->s6_addr[8], in6->s6_addr[9], in6->s6_addr[10],
in6->s6_addr[11], in6->s6_addr[12], in6->s6_addr[13],
in6->s6_addr[14], in6->s6_addr[15]));
- return 0;
}
/*
@@ -318,13 +272,8 @@ in6_ifattach_linklocal(struct ifnet *ifp, struct in6_addr *ifid)
ifra.ifra_addr.sin6_addr.s6_addr32[1] = 0;
ifra.ifra_addr.sin6_addr.s6_addr[8] &= ~EUI64_GBIT;
ifra.ifra_addr.sin6_addr.s6_addr[8] |= EUI64_UBIT;
- } else {
- if (get_ifid(ifp, &ifra.ifra_addr.sin6_addr) != 0) {
- nd6log((LOG_ERR,
- "%s: no ifid available\n", ifp->if_xname));
- return (-1);
- }
- }
+ } else
+ in6_get_ifid(ifp, &ifra.ifra_addr.sin6_addr);
ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
ifra.ifra_prefixmask.sin6_family = AF_INET6;