1*fcf59617SAndrey V. Elsukov /*- 2*fcf59617SAndrey V. Elsukov * Copyright (c) 2016 Yandex LLC 3*fcf59617SAndrey V. Elsukov * Copyright (c) 2016 Andrey V. Elsukov <ae@FreeBSD.org> 4*fcf59617SAndrey V. Elsukov * All rights reserved. 5*fcf59617SAndrey V. Elsukov * 6*fcf59617SAndrey V. Elsukov * Redistribution and use in source and binary forms, with or without 7*fcf59617SAndrey V. Elsukov * modification, are permitted provided that the following conditions 8*fcf59617SAndrey V. Elsukov * are met: 9*fcf59617SAndrey V. Elsukov * 10*fcf59617SAndrey V. Elsukov * 1. Redistributions of source code must retain the above copyright 11*fcf59617SAndrey V. Elsukov * notice, this list of conditions and the following disclaimer. 12*fcf59617SAndrey V. Elsukov * 2. Redistributions in binary form must reproduce the above copyright 13*fcf59617SAndrey V. Elsukov * notice, this list of conditions and the following disclaimer in the 14*fcf59617SAndrey V. Elsukov * documentation and/or other materials provided with the distribution. 15*fcf59617SAndrey V. Elsukov * 16*fcf59617SAndrey V. Elsukov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17*fcf59617SAndrey V. Elsukov * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18*fcf59617SAndrey V. Elsukov * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19*fcf59617SAndrey V. Elsukov * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20*fcf59617SAndrey V. Elsukov * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21*fcf59617SAndrey V. Elsukov * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22*fcf59617SAndrey V. Elsukov * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23*fcf59617SAndrey V. Elsukov * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*fcf59617SAndrey V. Elsukov * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25*fcf59617SAndrey V. Elsukov * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*fcf59617SAndrey V. Elsukov */ 27*fcf59617SAndrey V. Elsukov 28*fcf59617SAndrey V. Elsukov #include <sys/cdefs.h> 29*fcf59617SAndrey V. Elsukov __FBSDID("$FreeBSD$"); 30*fcf59617SAndrey V. Elsukov 31*fcf59617SAndrey V. Elsukov #include <sys/param.h> 32*fcf59617SAndrey V. Elsukov #include <sys/ioctl.h> 33*fcf59617SAndrey V. Elsukov #include <sys/socket.h> 34*fcf59617SAndrey V. Elsukov #include <sys/sockio.h> 35*fcf59617SAndrey V. Elsukov #include <sys/stdint.h> 36*fcf59617SAndrey V. Elsukov 37*fcf59617SAndrey V. Elsukov #include <stdlib.h> 38*fcf59617SAndrey V. Elsukov #include <unistd.h> 39*fcf59617SAndrey V. Elsukov 40*fcf59617SAndrey V. Elsukov #include <net/ethernet.h> 41*fcf59617SAndrey V. Elsukov #include <net/if.h> 42*fcf59617SAndrey V. Elsukov #include <net/if_ipsec.h> 43*fcf59617SAndrey V. Elsukov #include <net/route.h> 44*fcf59617SAndrey V. Elsukov 45*fcf59617SAndrey V. Elsukov #include <ctype.h> 46*fcf59617SAndrey V. Elsukov #include <stdio.h> 47*fcf59617SAndrey V. Elsukov #include <string.h> 48*fcf59617SAndrey V. Elsukov #include <err.h> 49*fcf59617SAndrey V. Elsukov #include <errno.h> 50*fcf59617SAndrey V. Elsukov 51*fcf59617SAndrey V. Elsukov #include "ifconfig.h" 52*fcf59617SAndrey V. Elsukov 53*fcf59617SAndrey V. Elsukov static void 54*fcf59617SAndrey V. Elsukov ipsec_status(int s) 55*fcf59617SAndrey V. Elsukov { 56*fcf59617SAndrey V. Elsukov uint32_t reqid; 57*fcf59617SAndrey V. Elsukov 58*fcf59617SAndrey V. Elsukov ifr.ifr_data = (caddr_t)&reqid; 59*fcf59617SAndrey V. Elsukov if (ioctl(s, IPSECGREQID, &ifr) == -1) 60*fcf59617SAndrey V. Elsukov return; 61*fcf59617SAndrey V. Elsukov printf("\treqid: %u\n", reqid); 62*fcf59617SAndrey V. Elsukov } 63*fcf59617SAndrey V. Elsukov 64*fcf59617SAndrey V. Elsukov static 65*fcf59617SAndrey V. Elsukov DECL_CMD_FUNC(setreqid, val, arg) 66*fcf59617SAndrey V. Elsukov { 67*fcf59617SAndrey V. Elsukov char *ep; 68*fcf59617SAndrey V. Elsukov uint32_t v; 69*fcf59617SAndrey V. Elsukov 70*fcf59617SAndrey V. Elsukov v = strtoul(val, &ep, 0); 71*fcf59617SAndrey V. Elsukov if (*ep != '\0') { 72*fcf59617SAndrey V. Elsukov warn("Invalid reqid value %s", val); 73*fcf59617SAndrey V. Elsukov return; 74*fcf59617SAndrey V. Elsukov } 75*fcf59617SAndrey V. Elsukov ifr.ifr_data = (char *)&v; 76*fcf59617SAndrey V. Elsukov if (ioctl(s, IPSECSREQID, &ifr) == -1) { 77*fcf59617SAndrey V. Elsukov warn("ioctl(IPSECSREQID)"); 78*fcf59617SAndrey V. Elsukov return; 79*fcf59617SAndrey V. Elsukov } 80*fcf59617SAndrey V. Elsukov } 81*fcf59617SAndrey V. Elsukov 82*fcf59617SAndrey V. Elsukov static struct cmd ipsec_cmds[] = { 83*fcf59617SAndrey V. Elsukov DEF_CMD_ARG("reqid", setreqid), 84*fcf59617SAndrey V. Elsukov }; 85*fcf59617SAndrey V. Elsukov 86*fcf59617SAndrey V. Elsukov static struct afswtch af_ipsec = { 87*fcf59617SAndrey V. Elsukov .af_name = "af_ipsec", 88*fcf59617SAndrey V. Elsukov .af_af = AF_UNSPEC, 89*fcf59617SAndrey V. Elsukov .af_other_status = ipsec_status, 90*fcf59617SAndrey V. Elsukov }; 91*fcf59617SAndrey V. Elsukov 92*fcf59617SAndrey V. Elsukov static __constructor void 93*fcf59617SAndrey V. Elsukov ipsec_ctor(void) 94*fcf59617SAndrey V. Elsukov { 95*fcf59617SAndrey V. Elsukov size_t i; 96*fcf59617SAndrey V. Elsukov 97*fcf59617SAndrey V. Elsukov for (i = 0; i < nitems(ipsec_cmds); i++) 98*fcf59617SAndrey V. Elsukov cmd_register(&ipsec_cmds[i]); 99*fcf59617SAndrey V. Elsukov af_register(&af_ipsec); 100*fcf59617SAndrey V. Elsukov #undef N 101*fcf59617SAndrey V. Elsukov } 102