#!/bin/ksh
-# $OpenBSD: install.sub,v 1.1058 2018/02/06 22:14:52 sthen Exp $
+# $OpenBSD: install.sub,v 1.1059 2018/02/10 05:59:06 florian Exp $
#
# Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback
# Copyright (c) 2015, Robert Peichaer <rpe@openbsd.org>
THESETS="$THESETS site$VERSION-$(hostname -s).tgz"
export PS1='\h# '
+ _f=/mnt/etc/soii.key
+ [[ ! -f $_f ]] || sysctl net.inet6.ip6.soiikey=$(<$_f)
+
# Configure the network.
enable_network
-/* $OpenBSD: sysctl.c,v 1.9 2015/01/16 06:39:34 deraadt Exp $ */
+/* $OpenBSD: sysctl.c,v 1.10 2018/02/10 05:59:06 florian Exp $ */
/*
* Copyright (c) 2009 Theo de Raadt <deraadt@openbsd.org>
*/
#include <sys/types.h>
+#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/uio.h>
+#include <netinet/in.h>
+
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#define SOIIKEY_LEN 16
+
struct var {
char *name;
int (*print)(struct var *);
return (1);
}
+int
+parse_hex_char(char ch)
+{
+ if (ch >= '0' && ch <= '9')
+ return (ch - '0');
+
+ ch = tolower((unsigned char)ch);
+ if (ch >= 'a' && ch <= 'f')
+ return (ch - 'a' + 10);
+
+ return (-1);
+}
+
+int
+set_soii_key(char *src)
+{
+ uint8_t key[SOIIKEY_LEN];
+ int mib[4] = {CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_SOIIKEY};
+ int i, c;
+
+ for(i = 0; i < SOIIKEY_LEN; i++) {
+ if ((c = parse_hex_char(src[2 * i])) == -1)
+ return (-1);
+ key[i] = c << 4;
+ if ((c = parse_hex_char(src[2 * i + 1])) == -1)
+ return (-1);
+ key[i] |= c;
+ }
+
+ return sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, NULL, key,
+ SOIIKEY_LEN);
+}
+
int
main(int argc, char *argv[])
{
while (argc--) {
name = *argv++;
+ /*
+ * strlen("net.inet6.ip6.soiikey="
+ * "00000000000000000000000000000000") == 54
+ * strlen("net.inet6.ip6.soiikey=") == 22
+ */
+ if (strlen(name) == 54 && strncmp(name,
+ "net.inet6.ip6.soiikey=", 22) == 0) {
+ set_soii_key(name + 22);
+ continue;
+ }
for (i = 0; i < sizeof(vars)/sizeof(vars[0]); i++) {
if (strcmp(name, vars[i].name) == 0) {