/*-1* Copyright (c) 2016 Yandex LLC2* Copyright (c) 2016 Andrey V. Elsukov <[email protected]>3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#include <sys/param.h>28#include <sys/ioctl.h>29#include <sys/socket.h>30#include <sys/sockio.h>31#include <sys/stdint.h>3233#include <stdlib.h>34#include <unistd.h>3536#include <net/ethernet.h>37#include <net/if.h>38#include <net/if_ipsec.h>39#include <net/route.h>4041#include <ctype.h>42#include <stdio.h>43#include <string.h>44#include <err.h>45#include <errno.h>4647#include "ifconfig.h"4849static void50ipsec_status(if_ctx *ctx)51{52uint32_t reqid;53struct ifreq ifr = { .ifr_data = (caddr_t)&reqid };5455if (ioctl_ctx_ifr(ctx, IPSECGREQID, &ifr) == -1)56return;57printf("\treqid: %u\n", reqid);58}5960static void61setreqid(if_ctx *ctx, const char *val, int dummy __unused)62{63char *ep;64uint32_t v;65struct ifreq ifr = { .ifr_data = (caddr_t)&v };6667v = strtoul(val, &ep, 0);68if (*ep != '\0') {69warn("Invalid reqid value %s", val);70return;71}72if (ioctl_ctx_ifr(ctx, IPSECSREQID, &ifr) == -1) {73warn("ioctl(IPSECSREQID)");74return;75}76}7778static struct cmd ipsec_cmds[] = {79DEF_CMD_ARG("reqid", setreqid),80};8182static struct afswtch af_ipsec = {83.af_name = "af_ipsec",84.af_af = AF_UNSPEC,85.af_other_status = ipsec_status,86};8788static __constructor void89ipsec_ctor(void)90{91size_t i;9293for (i = 0; i < nitems(ipsec_cmds); i++)94cmd_register(&ipsec_cmds[i]);95af_register(&af_ipsec);96#undef N97}9899100