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