#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <net/route.h>
#include <netinet/in.h>
}
- if (!(fp = fopen(SECRET, "w")))
+ /* Ensure that only the dhcpcd user can read the secret.
+ * Write permission is also denied as chaning it would remove
+ * it's stability. */
+ if ((fp = fopen(SECRET, "w")) == NULL ||
+ chmod(SECRET, S_IRUSR) == -1)
goto eexit;
x = fprintf(fp, "%s\n",
hwaddr_ntoa(ctx->secret, ctx->secret_len, line, sizeof(line)));
}
/* RFC7217 */
-int
-ipv6_makestableprivate(struct in6_addr *addr,
+static int
+ipv6_makestableprivate1(struct in6_addr *addr,
const struct in6_addr *prefix, int prefix_len,
const unsigned char *netiface, size_t netiface_len,
const char *netid, size_t netid_len,
return 0;
}
+int
+ipv6_makestableprivate(struct in6_addr *addr,
+ const struct in6_addr *prefix, int prefix_len,
+ const struct interface *ifp,
+ uint32_t dad_counter)
+{
+
+ /* For our implementation, we shall set the hardware address
+ * as the interface identifier */
+
+ return ipv6_makestableprivate1(addr, prefix, prefix_len,
+ ifp->hwaddr, ifp->hwlen,
+ ifp->ssid, strlen(ifp->ssid),
+ dad_counter,
+ ifp->ctx->secret, ifp->ctx->secret_len);
+}
+
int
ipv6_makeaddr(struct in6_addr *addr, const struct interface *ifp,
const struct in6_addr *prefix, int prefix_len)
if (ipv6_readsecret(ifp->ctx) == -1)
return -1;
}
- if (ipv6_makestableprivate(addr, prefix, prefix_len,
- ifp->options->iaid, sizeof(ifp->options->iaid),
- ifp->ssid, strlen(ifp->ssid),
- 0, /* DAD counter starts at 0 */
- ifp->ctx->secret, ifp->ctx->secret_len) == -1)
+ if (ipv6_makestableprivate(addr,
+ prefix, prefix_len, ifp, 0) == -1)
return -1;
return 0;
}
ssize_t ipv6_printaddr(char *, size_t, const uint8_t *, const char *);
int ipv6_makestableprivate(struct in6_addr *addr,
const struct in6_addr *prefix, int prefix_len,
- const unsigned char *netiface, size_t netiface_len,
- const char *netid, size_t netid_len,
- uint32_t dad_counter,
- const unsigned char *secret, size_t secret_len);
+ const struct interface *ifp, uint32_t dad_counter);
int ipv6_makeaddr(struct in6_addr *, const struct interface *,
const struct in6_addr *, int);
int ipv6_makeprefix(struct in6_addr *, const struct in6_addr *, int);
syslog(LOG_ERR, "if_deladdress6: %m");
if (ipv6_makestableprivate(&ap->addr,
&ap->prefix, ap->prefix_len,
- ifp->options->iaid, sizeof(ifp->options->iaid),
- ifp->ssid, strlen(ifp->ssid),
- ap->dadcounter,
- ifp->ctx->secret, ifp->ctx->secret_len) == -1)
+ ifp, ap->dadcounter) == -1)
{
syslog(LOG_ERR,
"%s: ipv6_makestableprivate: %m",