From 96522ed98d17b31c02ed17a19dd23ef669c6fd5d Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 10 Feb 2018 05:59:06 +0000 Subject: [PATCH] installer bits for RFC 7217 support OK rpe, tb, naddy, sthen --- distrib/miniroot/install.sub | 5 +++- distrib/special/sysctl/sysctl.c | 50 ++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index cfbdc13ebfd..4110cb45a24 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,5 +1,5 @@ #!/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 @@ -3112,6 +3112,9 @@ do_upgrade() { 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 diff --git a/distrib/special/sysctl/sysctl.c b/distrib/special/sysctl/sysctl.c index 6f3e333ac21..151284524fe 100644 --- a/distrib/special/sysctl/sysctl.c +++ b/distrib/special/sysctl/sysctl.c @@ -1,4 +1,4 @@ -/* $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 @@ -18,14 +18,19 @@ */ #include +#include #include #include +#include + #include #include #include #include +#define SOIIKEY_LEN 16 + struct var { char *name; int (*print)(struct var *); @@ -86,6 +91,39 @@ pstring(struct var *v) 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[]) { @@ -113,6 +151,16 @@ 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) { -- 2.20.1