132672Sache/*- 232672Sache * Copyright (c) 2016 Yandex LLC 332672Sache * Copyright (c) 2016 Andrey V. Elsukov <ae@FreeBSD.org> 432672Sache * All rights reserved. 532672Sache * 632672Sache * Redistribution and use in source and binary forms, with or without 732672Sache * modification, are permitted provided that the following conditions 832672Sache * are met: 932672Sache * 1032672Sache * 1. Redistributions of source code must retain the above copyright 1132672Sache * notice, this list of conditions and the following disclaimer. 1232672Sache * 2. Redistributions in binary form must reproduce the above copyright 1332672Sache * notice, this list of conditions and the following disclaimer in the 1432672Sache * documentation and/or other materials provided with the distribution. 1532672Sache * 1632672Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1732672Sache * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1832672Sache * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1932672Sache * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2032672Sache * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2132672Sache * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2232672Sache * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2332672Sache * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2432672Sache * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2532672Sache * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2632672Sache */ 2732672Sache 2832672Sache#include <sys/param.h> 2932672Sache#include <sys/ioctl.h> 3032672Sache#include <sys/socket.h> 3132672Sache#include <sys/sockio.h> 3232672Sache#include <sys/stdint.h> 3332672Sache 3432672Sache#include <stdlib.h> 3532672Sache#include <unistd.h> 3632672Sache 3732672Sache#include <net/ethernet.h> 3832672Sache#include <net/if.h> 3932672Sache#include <net/if_ipsec.h> 4032672Sache#include <net/route.h> 4132672Sache 4232672Sache#include <ctype.h> 4332672Sache#include <stdio.h> 4432672Sache#include <string.h> 4532672Sache#include <err.h> 4632672Sache#include <errno.h> 4732672Sache 4832672Sache#include "ifconfig.h" 4932672Sache 5032672Sachestatic void 5132672Sacheipsec_status(if_ctx *ctx) 5232672Sache{ 5332672Sache uint32_t reqid; 5432672Sache struct ifreq ifr = { .ifr_data = (caddr_t)&reqid }; 5532672Sache 5632672Sache if (ioctl_ctx_ifr(ctx, IPSECGREQID, &ifr) == -1) 5732672Sache return; 5832672Sache printf("\treqid: %u\n", reqid); 5932672Sache} 6032672Sache 6132672Sachestatic void 6232672Sachesetreqid(if_ctx *ctx, const char *val, int dummy __unused) 6332672Sache{ 6432672Sache char *ep; 6532672Sache uint32_t v; 6632672Sache struct ifreq ifr = { .ifr_data = (caddr_t)&v }; 6732672Sache 6832672Sache v = strtoul(val, &ep, 0); 6932672Sache if (*ep != '\0') { 7032672Sache warn("Invalid reqid value %s", val); 7132672Sache return; 7232672Sache } 7332672Sache if (ioctl_ctx_ifr(ctx, IPSECSREQID, &ifr) == -1) { 7432672Sache warn("ioctl(IPSECSREQID)"); 7532672Sache return; 7632672Sache } 7732672Sache} 7832672Sache 7932672Sachestatic struct cmd ipsec_cmds[] = { 8032672Sache DEF_CMD_ARG("reqid", setreqid), 8132672Sache}; 8232672Sache 8332672Sachestatic struct afswtch af_ipsec = { 8432672Sache .af_name = "af_ipsec", 8532672Sache .af_af = AF_UNSPEC, 8632672Sache .af_other_status = ipsec_status, 8732672Sache}; 8832672Sache 8932672Sachestatic __constructor void 9032672Sacheipsec_ctor(void) 9132672Sache{ 9232672Sache size_t i; 9332672Sache 9432672Sache for (i = 0; i < nitems(ipsec_cmds); i++) 9532672Sache cmd_register(&ipsec_cmds[i]); 9632672Sache af_register(&af_ipsec); 9732672Sache#undef N 9832672Sache} 9932672Sache