1d8caf56eSAndrey V. Elsukov /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3002cae78SAndrey V. Elsukov *
4002cae78SAndrey V. Elsukov * Copyright (c) 2015-2019 Yandex LLC
5d8caf56eSAndrey V. Elsukov * Copyright (c) 2015-2016 Alexander V. Chernikov <melifaro@FreeBSD.org>
6002cae78SAndrey V. Elsukov * Copyright (c) 2015-2019 Andrey V. Elsukov <ae@FreeBSD.org>
7d8caf56eSAndrey V. Elsukov *
8d8caf56eSAndrey V. Elsukov * Redistribution and use in source and binary forms, with or without
9d8caf56eSAndrey V. Elsukov * modification, are permitted provided that the following conditions
10d8caf56eSAndrey V. Elsukov * are met:
11d8caf56eSAndrey V. Elsukov *
12d8caf56eSAndrey V. Elsukov * 1. Redistributions of source code must retain the above copyright
13d8caf56eSAndrey V. Elsukov * notice, this list of conditions and the following disclaimer.
14d8caf56eSAndrey V. Elsukov * 2. Redistributions in binary form must reproduce the above copyright
15d8caf56eSAndrey V. Elsukov * notice, this list of conditions and the following disclaimer in the
16d8caf56eSAndrey V. Elsukov * documentation and/or other materials provided with the distribution.
17d8caf56eSAndrey V. Elsukov *
18d8caf56eSAndrey V. Elsukov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19d8caf56eSAndrey V. Elsukov * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20d8caf56eSAndrey V. Elsukov * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21d8caf56eSAndrey V. Elsukov * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22d8caf56eSAndrey V. Elsukov * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23d8caf56eSAndrey V. Elsukov * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24d8caf56eSAndrey V. Elsukov * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25d8caf56eSAndrey V. Elsukov * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26d8caf56eSAndrey V. Elsukov * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27d8caf56eSAndrey V. Elsukov * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28d8caf56eSAndrey V. Elsukov */
29d8caf56eSAndrey V. Elsukov
30d8caf56eSAndrey V. Elsukov #include <sys/types.h>
31d8caf56eSAndrey V. Elsukov #include <sys/socket.h>
32d8caf56eSAndrey V. Elsukov
33d8caf56eSAndrey V. Elsukov #include "ipfw2.h"
34d8caf56eSAndrey V. Elsukov
35d8caf56eSAndrey V. Elsukov #include <ctype.h>
36d8caf56eSAndrey V. Elsukov #include <err.h>
37d8caf56eSAndrey V. Elsukov #include <errno.h>
38c5e85276SAndrey V. Elsukov #include <inttypes.h>
39d8caf56eSAndrey V. Elsukov #include <netdb.h>
40d8caf56eSAndrey V. Elsukov #include <stdio.h>
41d8caf56eSAndrey V. Elsukov #include <stdlib.h>
42d8caf56eSAndrey V. Elsukov #include <string.h>
43d8caf56eSAndrey V. Elsukov #include <sysexits.h>
44d8caf56eSAndrey V. Elsukov
45d8caf56eSAndrey V. Elsukov #include <net/if.h>
46d8caf56eSAndrey V. Elsukov #include <netinet/in.h>
47d8caf56eSAndrey V. Elsukov #include <netinet/ip_fw.h>
48d8caf56eSAndrey V. Elsukov #include <netinet6/ip_fw_nat64.h>
49d8caf56eSAndrey V. Elsukov #include <arpa/inet.h>
50d8caf56eSAndrey V. Elsukov
51d8caf56eSAndrey V. Elsukov static void nat64lsn_fill_ntlv(ipfw_obj_ntlv *ntlv, const char *name,
52d8caf56eSAndrey V. Elsukov uint8_t set);
53d8caf56eSAndrey V. Elsukov typedef int (nat64lsn_cb_t)(ipfw_nat64lsn_cfg *cfg, const char *name,
54d8caf56eSAndrey V. Elsukov uint8_t set);
55d8caf56eSAndrey V. Elsukov static int nat64lsn_foreach(nat64lsn_cb_t *f, const char *name, uint8_t set,
56d8caf56eSAndrey V. Elsukov int sort);
57d8caf56eSAndrey V. Elsukov
58d8caf56eSAndrey V. Elsukov static void nat64lsn_create(const char *name, uint8_t set, int ac, char **av);
59d8caf56eSAndrey V. Elsukov static void nat64lsn_config(const char *name, uint8_t set, int ac, char **av);
60d8caf56eSAndrey V. Elsukov static void nat64lsn_destroy(const char *name, uint8_t set);
61d8caf56eSAndrey V. Elsukov static void nat64lsn_stats(const char *name, uint8_t set);
62d8caf56eSAndrey V. Elsukov static void nat64lsn_reset_stats(const char *name, uint8_t set);
63d8caf56eSAndrey V. Elsukov static int nat64lsn_show_cb(ipfw_nat64lsn_cfg *cfg, const char *name,
64d8caf56eSAndrey V. Elsukov uint8_t set);
65d8caf56eSAndrey V. Elsukov static int nat64lsn_destroy_cb(ipfw_nat64lsn_cfg *cfg, const char *name,
66d8caf56eSAndrey V. Elsukov uint8_t set);
67d8caf56eSAndrey V. Elsukov static int nat64lsn_states_cb(ipfw_nat64lsn_cfg *cfg, const char *name,
68d8caf56eSAndrey V. Elsukov uint8_t set);
69d8caf56eSAndrey V. Elsukov
70d8caf56eSAndrey V. Elsukov static struct _s_x nat64cmds[] = {
71d8caf56eSAndrey V. Elsukov { "create", TOK_CREATE },
72d8caf56eSAndrey V. Elsukov { "config", TOK_CONFIG },
73d8caf56eSAndrey V. Elsukov { "destroy", TOK_DESTROY },
74d8caf56eSAndrey V. Elsukov { "list", TOK_LIST },
75d8caf56eSAndrey V. Elsukov { "show", TOK_LIST },
76d8caf56eSAndrey V. Elsukov { "stats", TOK_STATS },
77d8caf56eSAndrey V. Elsukov { NULL, 0 }
78d8caf56eSAndrey V. Elsukov };
79d8caf56eSAndrey V. Elsukov
80d8caf56eSAndrey V. Elsukov static uint64_t
nat64lsn_print_states(void * buf)81d8caf56eSAndrey V. Elsukov nat64lsn_print_states(void *buf)
82d8caf56eSAndrey V. Elsukov {
83d8caf56eSAndrey V. Elsukov char s[INET6_ADDRSTRLEN], a[INET_ADDRSTRLEN], f[INET_ADDRSTRLEN];
8456707beeSMark Johnston const char *proto;
8556707beeSMark Johnston char sflags[4], *sf;
86d8caf56eSAndrey V. Elsukov ipfw_obj_header *oh;
87d8caf56eSAndrey V. Elsukov ipfw_obj_data *od;
88d18c1f26SAndrey V. Elsukov ipfw_nat64lsn_stg_v1 *stg;
89d18c1f26SAndrey V. Elsukov ipfw_nat64lsn_state_v1 *ste;
90d8caf56eSAndrey V. Elsukov uint64_t next_idx;
9156707beeSMark Johnston uint32_t i;
9256707beeSMark Johnston int sz;
93d8caf56eSAndrey V. Elsukov
94d8caf56eSAndrey V. Elsukov oh = (ipfw_obj_header *)buf;
95d8caf56eSAndrey V. Elsukov od = (ipfw_obj_data *)(oh + 1);
96d18c1f26SAndrey V. Elsukov stg = (ipfw_nat64lsn_stg_v1 *)(od + 1);
97d8caf56eSAndrey V. Elsukov sz = od->head.length - sizeof(*od);
98d8caf56eSAndrey V. Elsukov next_idx = 0;
99268a20a0SAdrian Chadd proto = NULL;
100d8caf56eSAndrey V. Elsukov while (sz > 0 && next_idx != 0xFF) {
101d18c1f26SAndrey V. Elsukov next_idx = stg->next.index;
102d8caf56eSAndrey V. Elsukov sz -= sizeof(*stg);
103d8caf56eSAndrey V. Elsukov if (stg->count == 0) {
104d8caf56eSAndrey V. Elsukov stg++;
105d8caf56eSAndrey V. Elsukov continue;
106d8caf56eSAndrey V. Elsukov }
107d18c1f26SAndrey V. Elsukov /*
108d18c1f26SAndrey V. Elsukov * NOTE: addresses are in network byte order,
109d18c1f26SAndrey V. Elsukov * ports are in host byte order.
110d18c1f26SAndrey V. Elsukov */
111d6369c2dSAndrey V. Elsukov inet_ntop(AF_INET, &stg->alias4, a, sizeof(a));
112d18c1f26SAndrey V. Elsukov ste = (ipfw_nat64lsn_state_v1 *)(stg + 1);
113d6369c2dSAndrey V. Elsukov for (i = 0; i < stg->count && sz > 0; i++) {
114d6369c2dSAndrey V. Elsukov sf = sflags;
115d18c1f26SAndrey V. Elsukov inet_ntop(AF_INET6, &ste->host6, s, sizeof(s));
116d6369c2dSAndrey V. Elsukov inet_ntop(AF_INET, &ste->daddr, f, sizeof(f));
117d18c1f26SAndrey V. Elsukov switch (ste->proto) {
118d18c1f26SAndrey V. Elsukov case IPPROTO_TCP:
119d18c1f26SAndrey V. Elsukov proto = "TCP";
120d8caf56eSAndrey V. Elsukov if (ste->flags & 0x02)
121d8caf56eSAndrey V. Elsukov *sf++ = 'S';
122d8caf56eSAndrey V. Elsukov if (ste->flags & 0x04)
123d8caf56eSAndrey V. Elsukov *sf++ = 'E';
124d8caf56eSAndrey V. Elsukov if (ste->flags & 0x01)
125d8caf56eSAndrey V. Elsukov *sf++ = 'F';
126d18c1f26SAndrey V. Elsukov break;
127d18c1f26SAndrey V. Elsukov case IPPROTO_UDP:
128d18c1f26SAndrey V. Elsukov proto = "UDP";
129d18c1f26SAndrey V. Elsukov break;
130d18c1f26SAndrey V. Elsukov case IPPROTO_ICMP:
131d18c1f26SAndrey V. Elsukov proto = "ICMPv6";
132d18c1f26SAndrey V. Elsukov break;
133d8caf56eSAndrey V. Elsukov }
134d8caf56eSAndrey V. Elsukov *sf = '\0';
135d18c1f26SAndrey V. Elsukov switch (ste->proto) {
136d8caf56eSAndrey V. Elsukov case IPPROTO_TCP:
137d8caf56eSAndrey V. Elsukov case IPPROTO_UDP:
138d8caf56eSAndrey V. Elsukov printf("%s:%d\t%s:%d\t%s\t%s\t%d\t%s:%d\n",
139d8caf56eSAndrey V. Elsukov s, ste->sport, a, ste->aport, proto,
140d8caf56eSAndrey V. Elsukov sflags, ste->idle, f, ste->dport);
141d8caf56eSAndrey V. Elsukov break;
142d18c1f26SAndrey V. Elsukov case IPPROTO_ICMP:
143d8caf56eSAndrey V. Elsukov printf("%s\t%s\t%s\t\t%d\t%s\n",
144d8caf56eSAndrey V. Elsukov s, a, proto, ste->idle, f);
145d8caf56eSAndrey V. Elsukov break;
146d8caf56eSAndrey V. Elsukov default:
147d8caf56eSAndrey V. Elsukov printf("%s\t%s\t%d\t\t%d\t%s\n",
148d18c1f26SAndrey V. Elsukov s, a, ste->proto, ste->idle, f);
149d8caf56eSAndrey V. Elsukov }
150d8caf56eSAndrey V. Elsukov ste++;
151d8caf56eSAndrey V. Elsukov sz -= sizeof(*ste);
152d8caf56eSAndrey V. Elsukov }
153d18c1f26SAndrey V. Elsukov stg = (ipfw_nat64lsn_stg_v1 *)ste;
154d8caf56eSAndrey V. Elsukov }
155d8caf56eSAndrey V. Elsukov return (next_idx);
156d8caf56eSAndrey V. Elsukov }
157d8caf56eSAndrey V. Elsukov
158d8caf56eSAndrey V. Elsukov static int
nat64lsn_states_cb(ipfw_nat64lsn_cfg * cfg,const char * name,uint8_t set)159d8caf56eSAndrey V. Elsukov nat64lsn_states_cb(ipfw_nat64lsn_cfg *cfg, const char *name, uint8_t set)
160d8caf56eSAndrey V. Elsukov {
161d8caf56eSAndrey V. Elsukov ipfw_obj_header *oh;
162d8caf56eSAndrey V. Elsukov ipfw_obj_data *od;
163d8caf56eSAndrey V. Elsukov void *buf;
164d8caf56eSAndrey V. Elsukov uint64_t next_idx;
165d8caf56eSAndrey V. Elsukov size_t sz;
166d8caf56eSAndrey V. Elsukov
167d8caf56eSAndrey V. Elsukov if (name != NULL && strcmp(cfg->name, name) != 0)
168d8caf56eSAndrey V. Elsukov return (ESRCH);
169d8caf56eSAndrey V. Elsukov
170d8caf56eSAndrey V. Elsukov if (set != 0 && cfg->set != set)
171d8caf56eSAndrey V. Elsukov return (ESRCH);
172d8caf56eSAndrey V. Elsukov
173d8caf56eSAndrey V. Elsukov next_idx = 0;
174d8caf56eSAndrey V. Elsukov sz = 4096;
175d8caf56eSAndrey V. Elsukov if ((buf = calloc(1, sz)) == NULL)
176d8caf56eSAndrey V. Elsukov err(EX_OSERR, NULL);
177d8caf56eSAndrey V. Elsukov do {
178d8caf56eSAndrey V. Elsukov oh = (ipfw_obj_header *)buf;
179d18c1f26SAndrey V. Elsukov oh->opheader.version = 1; /* Force using ov new API */
180d8caf56eSAndrey V. Elsukov od = (ipfw_obj_data *)(oh + 1);
181d8caf56eSAndrey V. Elsukov nat64lsn_fill_ntlv(&oh->ntlv, cfg->name, set);
182d8caf56eSAndrey V. Elsukov od->head.type = IPFW_TLV_OBJDATA;
183d8caf56eSAndrey V. Elsukov od->head.length = sizeof(*od) + sizeof(next_idx);
184d8caf56eSAndrey V. Elsukov *((uint64_t *)(od + 1)) = next_idx;
185d8caf56eSAndrey V. Elsukov if (do_get3(IP_FW_NAT64LSN_LIST_STATES, &oh->opheader, &sz))
186d8caf56eSAndrey V. Elsukov err(EX_OSERR, "Error reading nat64lsn states");
187d8caf56eSAndrey V. Elsukov next_idx = nat64lsn_print_states(buf);
188d8caf56eSAndrey V. Elsukov sz = 4096;
189d8caf56eSAndrey V. Elsukov memset(buf, 0, sz);
190d8caf56eSAndrey V. Elsukov } while (next_idx != 0xFF);
191d8caf56eSAndrey V. Elsukov
192d8caf56eSAndrey V. Elsukov free(buf);
193d8caf56eSAndrey V. Elsukov return (0);
194d8caf56eSAndrey V. Elsukov }
195d8caf56eSAndrey V. Elsukov
196d8caf56eSAndrey V. Elsukov static struct _s_x nat64statscmds[] = {
197d8caf56eSAndrey V. Elsukov { "reset", TOK_RESET },
198d8caf56eSAndrey V. Elsukov { NULL, 0 }
199d8caf56eSAndrey V. Elsukov };
200d8caf56eSAndrey V. Elsukov
201d8caf56eSAndrey V. Elsukov static void
ipfw_nat64lsn_stats_handler(const char * name,uint8_t set,int ac,char * av[])202d8caf56eSAndrey V. Elsukov ipfw_nat64lsn_stats_handler(const char *name, uint8_t set, int ac, char *av[])
203d8caf56eSAndrey V. Elsukov {
204d8caf56eSAndrey V. Elsukov int tcmd;
205d8caf56eSAndrey V. Elsukov
206d8caf56eSAndrey V. Elsukov if (ac == 0) {
207d8caf56eSAndrey V. Elsukov nat64lsn_stats(name, set);
208d8caf56eSAndrey V. Elsukov return;
209d8caf56eSAndrey V. Elsukov }
210d8caf56eSAndrey V. Elsukov NEED1("nat64lsn stats needs command");
211d8caf56eSAndrey V. Elsukov tcmd = get_token(nat64statscmds, *av, "nat64lsn stats command");
212d8caf56eSAndrey V. Elsukov switch (tcmd) {
213d8caf56eSAndrey V. Elsukov case TOK_RESET:
214d8caf56eSAndrey V. Elsukov nat64lsn_reset_stats(name, set);
215d8caf56eSAndrey V. Elsukov }
216d8caf56eSAndrey V. Elsukov }
217d8caf56eSAndrey V. Elsukov
218d8caf56eSAndrey V. Elsukov static struct _s_x nat64listcmds[] = {
219d8caf56eSAndrey V. Elsukov { "states", TOK_STATES },
220d8caf56eSAndrey V. Elsukov { "config", TOK_CONFIG },
221d8caf56eSAndrey V. Elsukov { NULL, 0 }
222d8caf56eSAndrey V. Elsukov };
223d8caf56eSAndrey V. Elsukov
224d8caf56eSAndrey V. Elsukov static void
ipfw_nat64lsn_list_handler(const char * name,uint8_t set,int ac,char * av[])225d8caf56eSAndrey V. Elsukov ipfw_nat64lsn_list_handler(const char *name, uint8_t set, int ac, char *av[])
226d8caf56eSAndrey V. Elsukov {
227d8caf56eSAndrey V. Elsukov int tcmd;
228d8caf56eSAndrey V. Elsukov
229d8caf56eSAndrey V. Elsukov if (ac == 0) {
230d8caf56eSAndrey V. Elsukov nat64lsn_foreach(nat64lsn_show_cb, name, set, 1);
231d8caf56eSAndrey V. Elsukov return;
232d8caf56eSAndrey V. Elsukov }
233d8caf56eSAndrey V. Elsukov NEED1("nat64lsn list needs command");
234d8caf56eSAndrey V. Elsukov tcmd = get_token(nat64listcmds, *av, "nat64lsn list command");
235d8caf56eSAndrey V. Elsukov switch (tcmd) {
236d8caf56eSAndrey V. Elsukov case TOK_STATES:
237d8caf56eSAndrey V. Elsukov nat64lsn_foreach(nat64lsn_states_cb, name, set, 1);
238d8caf56eSAndrey V. Elsukov break;
239d8caf56eSAndrey V. Elsukov case TOK_CONFIG:
240d8caf56eSAndrey V. Elsukov nat64lsn_foreach(nat64lsn_show_cb, name, set, 1);
241d8caf56eSAndrey V. Elsukov }
242d8caf56eSAndrey V. Elsukov }
243d8caf56eSAndrey V. Elsukov
244d8caf56eSAndrey V. Elsukov /*
245d8caf56eSAndrey V. Elsukov * This one handles all nat64lsn-related commands
246d8caf56eSAndrey V. Elsukov * ipfw [set N] nat64lsn NAME {create | config} ...
247d8caf56eSAndrey V. Elsukov * ipfw [set N] nat64lsn NAME stats
248d8caf56eSAndrey V. Elsukov * ipfw [set N] nat64lsn {NAME | all} destroy
249d8caf56eSAndrey V. Elsukov * ipfw [set N] nat64lsn {NAME | all} {list | show} [config | states]
250d8caf56eSAndrey V. Elsukov */
251d8caf56eSAndrey V. Elsukov #define nat64lsn_check_name table_check_name
252d8caf56eSAndrey V. Elsukov void
ipfw_nat64lsn_handler(int ac,char * av[])253d8caf56eSAndrey V. Elsukov ipfw_nat64lsn_handler(int ac, char *av[])
254d8caf56eSAndrey V. Elsukov {
255d8caf56eSAndrey V. Elsukov const char *name;
256d8caf56eSAndrey V. Elsukov int tcmd;
257d8caf56eSAndrey V. Elsukov uint8_t set;
258d8caf56eSAndrey V. Elsukov
25956707beeSMark Johnston if (g_co.use_set != 0)
26056707beeSMark Johnston set = g_co.use_set - 1;
261d8caf56eSAndrey V. Elsukov else
262d8caf56eSAndrey V. Elsukov set = 0;
263d8caf56eSAndrey V. Elsukov ac--; av++;
264d8caf56eSAndrey V. Elsukov
265d8caf56eSAndrey V. Elsukov NEED1("nat64lsn needs instance name");
266d8caf56eSAndrey V. Elsukov name = *av;
267d8caf56eSAndrey V. Elsukov if (nat64lsn_check_name(name) != 0) {
268d8caf56eSAndrey V. Elsukov if (strcmp(name, "all") == 0)
269d8caf56eSAndrey V. Elsukov name = NULL;
270d8caf56eSAndrey V. Elsukov else
271d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "nat64lsn instance name %s is invalid",
272d8caf56eSAndrey V. Elsukov name);
273d8caf56eSAndrey V. Elsukov }
274d8caf56eSAndrey V. Elsukov ac--; av++;
275d8caf56eSAndrey V. Elsukov NEED1("nat64lsn needs command");
276d8caf56eSAndrey V. Elsukov
277d8caf56eSAndrey V. Elsukov tcmd = get_token(nat64cmds, *av, "nat64lsn command");
278d8caf56eSAndrey V. Elsukov if (name == NULL && tcmd != TOK_DESTROY && tcmd != TOK_LIST)
279d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "nat64lsn instance name required");
280d8caf56eSAndrey V. Elsukov switch (tcmd) {
281d8caf56eSAndrey V. Elsukov case TOK_CREATE:
282d8caf56eSAndrey V. Elsukov ac--; av++;
283d8caf56eSAndrey V. Elsukov nat64lsn_create(name, set, ac, av);
284d8caf56eSAndrey V. Elsukov break;
285d8caf56eSAndrey V. Elsukov case TOK_CONFIG:
286d8caf56eSAndrey V. Elsukov ac--; av++;
287d8caf56eSAndrey V. Elsukov nat64lsn_config(name, set, ac, av);
288d8caf56eSAndrey V. Elsukov break;
289d8caf56eSAndrey V. Elsukov case TOK_LIST:
290d8caf56eSAndrey V. Elsukov ac--; av++;
291d8caf56eSAndrey V. Elsukov ipfw_nat64lsn_list_handler(name, set, ac, av);
292d8caf56eSAndrey V. Elsukov break;
293d8caf56eSAndrey V. Elsukov case TOK_DESTROY:
294d8caf56eSAndrey V. Elsukov if (name == NULL)
295d8caf56eSAndrey V. Elsukov nat64lsn_foreach(nat64lsn_destroy_cb, NULL, set, 0);
296d8caf56eSAndrey V. Elsukov else
297d8caf56eSAndrey V. Elsukov nat64lsn_destroy(name, set);
298d8caf56eSAndrey V. Elsukov break;
299d8caf56eSAndrey V. Elsukov case TOK_STATS:
300d8caf56eSAndrey V. Elsukov ac--; av++;
301d8caf56eSAndrey V. Elsukov ipfw_nat64lsn_stats_handler(name, set, ac, av);
302d8caf56eSAndrey V. Elsukov }
303d8caf56eSAndrey V. Elsukov }
304d8caf56eSAndrey V. Elsukov
305d8caf56eSAndrey V. Elsukov static void
nat64lsn_fill_ntlv(ipfw_obj_ntlv * ntlv,const char * name,uint8_t set)306d8caf56eSAndrey V. Elsukov nat64lsn_fill_ntlv(ipfw_obj_ntlv *ntlv, const char *name, uint8_t set)
307d8caf56eSAndrey V. Elsukov {
308d8caf56eSAndrey V. Elsukov
309d8caf56eSAndrey V. Elsukov ntlv->head.type = IPFW_TLV_EACTION_NAME(1); /* it doesn't matter */
310d8caf56eSAndrey V. Elsukov ntlv->head.length = sizeof(ipfw_obj_ntlv);
311d8caf56eSAndrey V. Elsukov ntlv->idx = 1;
312d8caf56eSAndrey V. Elsukov ntlv->set = set;
313d8caf56eSAndrey V. Elsukov strlcpy(ntlv->name, name, sizeof(ntlv->name));
314d8caf56eSAndrey V. Elsukov }
315d8caf56eSAndrey V. Elsukov
316d8caf56eSAndrey V. Elsukov static void
nat64lsn_apply_mask(int af,void * prefix,uint16_t plen)317d8caf56eSAndrey V. Elsukov nat64lsn_apply_mask(int af, void *prefix, uint16_t plen)
318d8caf56eSAndrey V. Elsukov {
319d8caf56eSAndrey V. Elsukov struct in6_addr mask6, *p6;
320d8caf56eSAndrey V. Elsukov struct in_addr mask4, *p4;
321d8caf56eSAndrey V. Elsukov
322d8caf56eSAndrey V. Elsukov if (af == AF_INET) {
323d8caf56eSAndrey V. Elsukov p4 = (struct in_addr *)prefix;
324d8caf56eSAndrey V. Elsukov mask4.s_addr = htonl(~((1 << (32 - plen)) - 1));
325d8caf56eSAndrey V. Elsukov p4->s_addr &= mask4.s_addr;
326d8caf56eSAndrey V. Elsukov } else if (af == AF_INET6) {
327d8caf56eSAndrey V. Elsukov p6 = (struct in6_addr *)prefix;
328d8caf56eSAndrey V. Elsukov n2mask(&mask6, plen);
329d8caf56eSAndrey V. Elsukov APPLY_MASK(p6, &mask6);
330d8caf56eSAndrey V. Elsukov }
331d8caf56eSAndrey V. Elsukov }
332d8caf56eSAndrey V. Elsukov
333d8caf56eSAndrey V. Elsukov static void
nat64lsn_parse_prefix(const char * arg,int af,void * prefix,uint16_t * plen)334d8caf56eSAndrey V. Elsukov nat64lsn_parse_prefix(const char *arg, int af, void *prefix, uint16_t *plen)
335d8caf56eSAndrey V. Elsukov {
336d8caf56eSAndrey V. Elsukov char *p, *l;
337d8caf56eSAndrey V. Elsukov
338d8caf56eSAndrey V. Elsukov p = strdup(arg);
339d8caf56eSAndrey V. Elsukov if (p == NULL)
340d8caf56eSAndrey V. Elsukov err(EX_OSERR, NULL);
341d8caf56eSAndrey V. Elsukov if ((l = strchr(p, '/')) != NULL)
342d8caf56eSAndrey V. Elsukov *l++ = '\0';
343d8caf56eSAndrey V. Elsukov if (l == NULL)
344d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "Prefix length required");
345d8caf56eSAndrey V. Elsukov if (inet_pton(af, p, prefix) != 1)
346d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "Bad prefix: %s", p);
347d8caf56eSAndrey V. Elsukov *plen = (uint16_t)strtol(l, &l, 10);
348d8caf56eSAndrey V. Elsukov if (*l != '\0' || *plen == 0 || (af == AF_INET && *plen > 32) ||
349d8caf56eSAndrey V. Elsukov (af == AF_INET6 && *plen > 96))
350d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "Bad prefix length: %s", arg);
351d8caf56eSAndrey V. Elsukov nat64lsn_apply_mask(af, prefix, *plen);
352d8caf56eSAndrey V. Elsukov free(p);
353d8caf56eSAndrey V. Elsukov }
354d8caf56eSAndrey V. Elsukov
355d8caf56eSAndrey V. Elsukov static uint32_t
nat64lsn_parse_int(const char * arg,const char * desc)356d8caf56eSAndrey V. Elsukov nat64lsn_parse_int(const char *arg, const char *desc)
357d8caf56eSAndrey V. Elsukov {
358d8caf56eSAndrey V. Elsukov char *p;
359d8caf56eSAndrey V. Elsukov uint32_t val;
360d8caf56eSAndrey V. Elsukov
361d8caf56eSAndrey V. Elsukov val = (uint32_t)strtol(arg, &p, 10);
362d8caf56eSAndrey V. Elsukov if (*p != '\0')
363d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "Invalid %s value: %s\n", desc, arg);
364d8caf56eSAndrey V. Elsukov return (val);
365d8caf56eSAndrey V. Elsukov }
366d8caf56eSAndrey V. Elsukov
367d8caf56eSAndrey V. Elsukov static struct _s_x nat64newcmds[] = {
368d8caf56eSAndrey V. Elsukov { "prefix6", TOK_PREFIX6 },
369d8caf56eSAndrey V. Elsukov { "jmaxlen", TOK_JMAXLEN },
370d8caf56eSAndrey V. Elsukov { "prefix4", TOK_PREFIX4 },
371d8caf56eSAndrey V. Elsukov { "host_del_age", TOK_HOST_DEL_AGE },
372d8caf56eSAndrey V. Elsukov { "pg_del_age", TOK_PG_DEL_AGE },
373d8caf56eSAndrey V. Elsukov { "tcp_syn_age", TOK_TCP_SYN_AGE },
374d8caf56eSAndrey V. Elsukov { "tcp_close_age",TOK_TCP_CLOSE_AGE },
375d8caf56eSAndrey V. Elsukov { "tcp_est_age", TOK_TCP_EST_AGE },
376d8caf56eSAndrey V. Elsukov { "udp_age", TOK_UDP_AGE },
377d8caf56eSAndrey V. Elsukov { "icmp_age", TOK_ICMP_AGE },
378d18c1f26SAndrey V. Elsukov { "states_chunks",TOK_STATES_CHUNKS },
379d8caf56eSAndrey V. Elsukov { "log", TOK_LOG },
380d8caf56eSAndrey V. Elsukov { "-log", TOK_LOGOFF },
381b11efc1eSAndrey V. Elsukov { "allow_private", TOK_PRIVATE },
382b11efc1eSAndrey V. Elsukov { "-allow_private", TOK_PRIVATEOFF },
383*4a77657cSAndrey V. Elsukov { "swap_conf", TOK_SWAPCONF },
384*4a77657cSAndrey V. Elsukov { "-swap_conf", TOK_SWAPCONFOFF },
385d18c1f26SAndrey V. Elsukov /* for compatibility with old configurations */
386d18c1f26SAndrey V. Elsukov { "max_ports", TOK_MAX_PORTS }, /* unused */
387d8caf56eSAndrey V. Elsukov { NULL, 0 }
388d8caf56eSAndrey V. Elsukov };
389d8caf56eSAndrey V. Elsukov
390d8caf56eSAndrey V. Elsukov /*
391d8caf56eSAndrey V. Elsukov * Creates new nat64lsn instance
392d8caf56eSAndrey V. Elsukov * ipfw nat64lsn <NAME> create
393d8caf56eSAndrey V. Elsukov * [ max_ports <N> ]
394d8caf56eSAndrey V. Elsukov * Request: [ ipfw_obj_lheader ipfw_nat64lsn_cfg ]
395d8caf56eSAndrey V. Elsukov */
396d8caf56eSAndrey V. Elsukov #define NAT64LSN_HAS_PREFIX4 0x01
397d8caf56eSAndrey V. Elsukov #define NAT64LSN_HAS_PREFIX6 0x02
398d8caf56eSAndrey V. Elsukov static void
nat64lsn_create(const char * name,uint8_t set,int ac,char ** av)399d8caf56eSAndrey V. Elsukov nat64lsn_create(const char *name, uint8_t set, int ac, char **av)
400d8caf56eSAndrey V. Elsukov {
401d8caf56eSAndrey V. Elsukov char buf[sizeof(ipfw_obj_lheader) + sizeof(ipfw_nat64lsn_cfg)];
402d8caf56eSAndrey V. Elsukov ipfw_nat64lsn_cfg *cfg;
403d8caf56eSAndrey V. Elsukov ipfw_obj_lheader *olh;
404d8caf56eSAndrey V. Elsukov int tcmd, flags;
405d8caf56eSAndrey V. Elsukov char *opt;
406d8caf56eSAndrey V. Elsukov
407d8caf56eSAndrey V. Elsukov memset(&buf, 0, sizeof(buf));
408d8caf56eSAndrey V. Elsukov olh = (ipfw_obj_lheader *)buf;
409d8caf56eSAndrey V. Elsukov cfg = (ipfw_nat64lsn_cfg *)(olh + 1);
410d8caf56eSAndrey V. Elsukov
411d8caf56eSAndrey V. Elsukov /* Some reasonable defaults */
412d8caf56eSAndrey V. Elsukov inet_pton(AF_INET6, "64:ff9b::", &cfg->prefix6);
413d8caf56eSAndrey V. Elsukov cfg->plen6 = 96;
414d8caf56eSAndrey V. Elsukov cfg->set = set;
415d8caf56eSAndrey V. Elsukov cfg->max_ports = NAT64LSN_MAX_PORTS;
416d8caf56eSAndrey V. Elsukov cfg->jmaxlen = NAT64LSN_JMAXLEN;
417d8caf56eSAndrey V. Elsukov cfg->nh_delete_delay = NAT64LSN_HOST_AGE;
418d8caf56eSAndrey V. Elsukov cfg->pg_delete_delay = NAT64LSN_PG_AGE;
419d8caf56eSAndrey V. Elsukov cfg->st_syn_ttl = NAT64LSN_TCP_SYN_AGE;
420d8caf56eSAndrey V. Elsukov cfg->st_estab_ttl = NAT64LSN_TCP_EST_AGE;
421d8caf56eSAndrey V. Elsukov cfg->st_close_ttl = NAT64LSN_TCP_FIN_AGE;
422d8caf56eSAndrey V. Elsukov cfg->st_udp_ttl = NAT64LSN_UDP_AGE;
423d8caf56eSAndrey V. Elsukov cfg->st_icmp_ttl = NAT64LSN_ICMP_AGE;
424d8caf56eSAndrey V. Elsukov flags = NAT64LSN_HAS_PREFIX6;
425d8caf56eSAndrey V. Elsukov while (ac > 0) {
426d8caf56eSAndrey V. Elsukov tcmd = get_token(nat64newcmds, *av, "option");
427d8caf56eSAndrey V. Elsukov opt = *av;
428d8caf56eSAndrey V. Elsukov ac--; av++;
429d8caf56eSAndrey V. Elsukov
430d8caf56eSAndrey V. Elsukov switch (tcmd) {
431d8caf56eSAndrey V. Elsukov case TOK_PREFIX4:
432d8caf56eSAndrey V. Elsukov NEED1("IPv4 prefix required");
433d8caf56eSAndrey V. Elsukov nat64lsn_parse_prefix(*av, AF_INET, &cfg->prefix4,
434d8caf56eSAndrey V. Elsukov &cfg->plen4);
435d8caf56eSAndrey V. Elsukov flags |= NAT64LSN_HAS_PREFIX4;
436d8caf56eSAndrey V. Elsukov ac--; av++;
437d8caf56eSAndrey V. Elsukov break;
438d8caf56eSAndrey V. Elsukov case TOK_PREFIX6:
439d8caf56eSAndrey V. Elsukov NEED1("IPv6 prefix required");
440d8caf56eSAndrey V. Elsukov nat64lsn_parse_prefix(*av, AF_INET6, &cfg->prefix6,
441d8caf56eSAndrey V. Elsukov &cfg->plen6);
442782360deSAndrey V. Elsukov if (ipfw_check_nat64prefix(&cfg->prefix6,
443d18c1f26SAndrey V. Elsukov cfg->plen6) != 0 &&
444d18c1f26SAndrey V. Elsukov !IN6_IS_ADDR_UNSPECIFIED(&cfg->prefix6))
445782360deSAndrey V. Elsukov errx(EX_USAGE, "Bad prefix6 %s", *av);
446782360deSAndrey V. Elsukov
447d8caf56eSAndrey V. Elsukov ac--; av++;
448d8caf56eSAndrey V. Elsukov break;
449d8caf56eSAndrey V. Elsukov case TOK_JMAXLEN:
450d8caf56eSAndrey V. Elsukov NEED1("job queue length required");
451d8caf56eSAndrey V. Elsukov cfg->jmaxlen = nat64lsn_parse_int(*av, opt);
452d8caf56eSAndrey V. Elsukov ac--; av++;
453d8caf56eSAndrey V. Elsukov break;
454d8caf56eSAndrey V. Elsukov case TOK_MAX_PORTS:
455d8caf56eSAndrey V. Elsukov NEED1("Max per-user ports required");
456d8caf56eSAndrey V. Elsukov cfg->max_ports = nat64lsn_parse_int(*av, opt);
457d8caf56eSAndrey V. Elsukov ac--; av++;
458d8caf56eSAndrey V. Elsukov break;
459d8caf56eSAndrey V. Elsukov case TOK_HOST_DEL_AGE:
460d8caf56eSAndrey V. Elsukov NEED1("host delete delay required");
461d8caf56eSAndrey V. Elsukov cfg->nh_delete_delay = (uint16_t)nat64lsn_parse_int(
462d8caf56eSAndrey V. Elsukov *av, opt);
463d8caf56eSAndrey V. Elsukov ac--; av++;
464d8caf56eSAndrey V. Elsukov break;
465d8caf56eSAndrey V. Elsukov case TOK_PG_DEL_AGE:
466d8caf56eSAndrey V. Elsukov NEED1("portgroup delete delay required");
467d8caf56eSAndrey V. Elsukov cfg->pg_delete_delay = (uint16_t)nat64lsn_parse_int(
468d8caf56eSAndrey V. Elsukov *av, opt);
469d8caf56eSAndrey V. Elsukov ac--; av++;
470d8caf56eSAndrey V. Elsukov break;
471d8caf56eSAndrey V. Elsukov case TOK_TCP_SYN_AGE:
472d8caf56eSAndrey V. Elsukov NEED1("tcp syn age required");
473d8caf56eSAndrey V. Elsukov cfg->st_syn_ttl = (uint16_t)nat64lsn_parse_int(
474d8caf56eSAndrey V. Elsukov *av, opt);
475d8caf56eSAndrey V. Elsukov ac--; av++;
476d8caf56eSAndrey V. Elsukov break;
477d8caf56eSAndrey V. Elsukov case TOK_TCP_CLOSE_AGE:
478d8caf56eSAndrey V. Elsukov NEED1("tcp close age required");
479d8caf56eSAndrey V. Elsukov cfg->st_close_ttl = (uint16_t)nat64lsn_parse_int(
480d8caf56eSAndrey V. Elsukov *av, opt);
481d8caf56eSAndrey V. Elsukov ac--; av++;
482d8caf56eSAndrey V. Elsukov break;
483d8caf56eSAndrey V. Elsukov case TOK_TCP_EST_AGE:
484d8caf56eSAndrey V. Elsukov NEED1("tcp est age required");
485d8caf56eSAndrey V. Elsukov cfg->st_estab_ttl = (uint16_t)nat64lsn_parse_int(
486d8caf56eSAndrey V. Elsukov *av, opt);
487d8caf56eSAndrey V. Elsukov ac--; av++;
488d8caf56eSAndrey V. Elsukov break;
489d8caf56eSAndrey V. Elsukov case TOK_UDP_AGE:
490d8caf56eSAndrey V. Elsukov NEED1("udp age required");
491d8caf56eSAndrey V. Elsukov cfg->st_udp_ttl = (uint16_t)nat64lsn_parse_int(
492d8caf56eSAndrey V. Elsukov *av, opt);
493d8caf56eSAndrey V. Elsukov ac--; av++;
494d8caf56eSAndrey V. Elsukov break;
495d8caf56eSAndrey V. Elsukov case TOK_ICMP_AGE:
496d8caf56eSAndrey V. Elsukov NEED1("icmp age required");
497d8caf56eSAndrey V. Elsukov cfg->st_icmp_ttl = (uint16_t)nat64lsn_parse_int(
498d8caf56eSAndrey V. Elsukov *av, opt);
499d8caf56eSAndrey V. Elsukov ac--; av++;
500d8caf56eSAndrey V. Elsukov break;
501d18c1f26SAndrey V. Elsukov case TOK_STATES_CHUNKS:
502d18c1f26SAndrey V. Elsukov NEED1("number of chunks required");
503d18c1f26SAndrey V. Elsukov cfg->states_chunks = (uint8_t)nat64lsn_parse_int(
504d18c1f26SAndrey V. Elsukov *av, opt);
505d18c1f26SAndrey V. Elsukov ac--; av++;
506d18c1f26SAndrey V. Elsukov break;
507d8caf56eSAndrey V. Elsukov case TOK_LOG:
508d8caf56eSAndrey V. Elsukov cfg->flags |= NAT64_LOG;
509d8caf56eSAndrey V. Elsukov break;
510d8caf56eSAndrey V. Elsukov case TOK_LOGOFF:
511d8caf56eSAndrey V. Elsukov cfg->flags &= ~NAT64_LOG;
512d8caf56eSAndrey V. Elsukov break;
513b11efc1eSAndrey V. Elsukov case TOK_PRIVATE:
514b11efc1eSAndrey V. Elsukov cfg->flags |= NAT64_ALLOW_PRIVATE;
515b11efc1eSAndrey V. Elsukov break;
516b11efc1eSAndrey V. Elsukov case TOK_PRIVATEOFF:
517b11efc1eSAndrey V. Elsukov cfg->flags &= ~NAT64_ALLOW_PRIVATE;
518b11efc1eSAndrey V. Elsukov break;
519*4a77657cSAndrey V. Elsukov case TOK_SWAPCONF:
520*4a77657cSAndrey V. Elsukov cfg->flags |= NAT64LSN_ALLOW_SWAPCONF;
521*4a77657cSAndrey V. Elsukov break;
522*4a77657cSAndrey V. Elsukov case TOK_SWAPCONFOFF:
523*4a77657cSAndrey V. Elsukov cfg->flags &= ~NAT64LSN_ALLOW_SWAPCONF;
524*4a77657cSAndrey V. Elsukov break;
525d8caf56eSAndrey V. Elsukov }
526d8caf56eSAndrey V. Elsukov }
527d8caf56eSAndrey V. Elsukov
528d8caf56eSAndrey V. Elsukov /* Check validness */
529d8caf56eSAndrey V. Elsukov if ((flags & NAT64LSN_HAS_PREFIX4) != NAT64LSN_HAS_PREFIX4)
530d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "prefix4 required");
531d8caf56eSAndrey V. Elsukov
532d8caf56eSAndrey V. Elsukov olh->count = 1;
533d8caf56eSAndrey V. Elsukov olh->objsize = sizeof(*cfg);
534d8caf56eSAndrey V. Elsukov olh->size = sizeof(buf);
535d8caf56eSAndrey V. Elsukov strlcpy(cfg->name, name, sizeof(cfg->name));
536d8caf56eSAndrey V. Elsukov if (do_set3(IP_FW_NAT64LSN_CREATE, &olh->opheader, sizeof(buf)) != 0)
537d8caf56eSAndrey V. Elsukov err(EX_OSERR, "nat64lsn instance creation failed");
538d8caf56eSAndrey V. Elsukov }
539d8caf56eSAndrey V. Elsukov
540d8caf56eSAndrey V. Elsukov /*
541d8caf56eSAndrey V. Elsukov * Configures existing nat64lsn instance
542d8caf56eSAndrey V. Elsukov * ipfw nat64lsn <NAME> config <options>
543d8caf56eSAndrey V. Elsukov * Request: [ ipfw_obj_header ipfw_nat64lsn_cfg ]
544d8caf56eSAndrey V. Elsukov */
545d8caf56eSAndrey V. Elsukov static void
nat64lsn_config(const char * name,uint8_t set,int ac,char ** av)546d8caf56eSAndrey V. Elsukov nat64lsn_config(const char *name, uint8_t set, int ac, char **av)
547d8caf56eSAndrey V. Elsukov {
548d8caf56eSAndrey V. Elsukov char buf[sizeof(ipfw_obj_header) + sizeof(ipfw_nat64lsn_cfg)];
549d8caf56eSAndrey V. Elsukov ipfw_nat64lsn_cfg *cfg;
550d8caf56eSAndrey V. Elsukov ipfw_obj_header *oh;
551d8caf56eSAndrey V. Elsukov size_t sz;
552d8caf56eSAndrey V. Elsukov char *opt;
553d8caf56eSAndrey V. Elsukov int tcmd;
554d8caf56eSAndrey V. Elsukov
555d8caf56eSAndrey V. Elsukov if (ac == 0)
556d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "config options required");
557d8caf56eSAndrey V. Elsukov memset(&buf, 0, sizeof(buf));
558d8caf56eSAndrey V. Elsukov oh = (ipfw_obj_header *)buf;
559d8caf56eSAndrey V. Elsukov cfg = (ipfw_nat64lsn_cfg *)(oh + 1);
560d8caf56eSAndrey V. Elsukov sz = sizeof(buf);
561d8caf56eSAndrey V. Elsukov
562d8caf56eSAndrey V. Elsukov nat64lsn_fill_ntlv(&oh->ntlv, name, set);
563d8caf56eSAndrey V. Elsukov if (do_get3(IP_FW_NAT64LSN_CONFIG, &oh->opheader, &sz) != 0)
564d8caf56eSAndrey V. Elsukov err(EX_OSERR, "failed to get config for instance %s", name);
565d8caf56eSAndrey V. Elsukov
566d8caf56eSAndrey V. Elsukov while (ac > 0) {
567d8caf56eSAndrey V. Elsukov tcmd = get_token(nat64newcmds, *av, "option");
568d8caf56eSAndrey V. Elsukov opt = *av;
569d8caf56eSAndrey V. Elsukov ac--; av++;
570d8caf56eSAndrey V. Elsukov
571d8caf56eSAndrey V. Elsukov switch (tcmd) {
572d8caf56eSAndrey V. Elsukov case TOK_MAX_PORTS:
573d8caf56eSAndrey V. Elsukov NEED1("Max per-user ports required");
574d8caf56eSAndrey V. Elsukov cfg->max_ports = nat64lsn_parse_int(*av, opt);
575d8caf56eSAndrey V. Elsukov ac--; av++;
576d8caf56eSAndrey V. Elsukov break;
577d8caf56eSAndrey V. Elsukov case TOK_JMAXLEN:
578d8caf56eSAndrey V. Elsukov NEED1("job queue length required");
579d8caf56eSAndrey V. Elsukov cfg->jmaxlen = nat64lsn_parse_int(*av, opt);
580d8caf56eSAndrey V. Elsukov ac--; av++;
581d8caf56eSAndrey V. Elsukov break;
582d8caf56eSAndrey V. Elsukov case TOK_HOST_DEL_AGE:
583d8caf56eSAndrey V. Elsukov NEED1("host delete delay required");
584d8caf56eSAndrey V. Elsukov cfg->nh_delete_delay = (uint16_t)nat64lsn_parse_int(
585d8caf56eSAndrey V. Elsukov *av, opt);
586d8caf56eSAndrey V. Elsukov ac--; av++;
587d8caf56eSAndrey V. Elsukov break;
588d8caf56eSAndrey V. Elsukov case TOK_PG_DEL_AGE:
589d8caf56eSAndrey V. Elsukov NEED1("portgroup delete delay required");
590d8caf56eSAndrey V. Elsukov cfg->pg_delete_delay = (uint16_t)nat64lsn_parse_int(
591d8caf56eSAndrey V. Elsukov *av, opt);
592d8caf56eSAndrey V. Elsukov ac--; av++;
593d8caf56eSAndrey V. Elsukov break;
594d8caf56eSAndrey V. Elsukov case TOK_TCP_SYN_AGE:
595d8caf56eSAndrey V. Elsukov NEED1("tcp syn age required");
596d8caf56eSAndrey V. Elsukov cfg->st_syn_ttl = (uint16_t)nat64lsn_parse_int(
597d8caf56eSAndrey V. Elsukov *av, opt);
598d8caf56eSAndrey V. Elsukov ac--; av++;
599d8caf56eSAndrey V. Elsukov break;
600d8caf56eSAndrey V. Elsukov case TOK_TCP_CLOSE_AGE:
601d8caf56eSAndrey V. Elsukov NEED1("tcp close age required");
602d8caf56eSAndrey V. Elsukov cfg->st_close_ttl = (uint16_t)nat64lsn_parse_int(
603d8caf56eSAndrey V. Elsukov *av, opt);
604d8caf56eSAndrey V. Elsukov ac--; av++;
605d8caf56eSAndrey V. Elsukov break;
606d8caf56eSAndrey V. Elsukov case TOK_TCP_EST_AGE:
607d8caf56eSAndrey V. Elsukov NEED1("tcp est age required");
608d8caf56eSAndrey V. Elsukov cfg->st_estab_ttl = (uint16_t)nat64lsn_parse_int(
609d8caf56eSAndrey V. Elsukov *av, opt);
610d8caf56eSAndrey V. Elsukov ac--; av++;
611d8caf56eSAndrey V. Elsukov break;
612d8caf56eSAndrey V. Elsukov case TOK_UDP_AGE:
613d8caf56eSAndrey V. Elsukov NEED1("udp age required");
614d8caf56eSAndrey V. Elsukov cfg->st_udp_ttl = (uint16_t)nat64lsn_parse_int(
615d8caf56eSAndrey V. Elsukov *av, opt);
616d8caf56eSAndrey V. Elsukov ac--; av++;
617d8caf56eSAndrey V. Elsukov break;
618d8caf56eSAndrey V. Elsukov case TOK_ICMP_AGE:
619d8caf56eSAndrey V. Elsukov NEED1("icmp age required");
620d8caf56eSAndrey V. Elsukov cfg->st_icmp_ttl = (uint16_t)nat64lsn_parse_int(
621d8caf56eSAndrey V. Elsukov *av, opt);
622d8caf56eSAndrey V. Elsukov ac--; av++;
623d8caf56eSAndrey V. Elsukov break;
624d18c1f26SAndrey V. Elsukov case TOK_STATES_CHUNKS:
625d18c1f26SAndrey V. Elsukov NEED1("number of chunks required");
626d18c1f26SAndrey V. Elsukov cfg->states_chunks = (uint8_t)nat64lsn_parse_int(
627d18c1f26SAndrey V. Elsukov *av, opt);
628d18c1f26SAndrey V. Elsukov ac--; av++;
629d18c1f26SAndrey V. Elsukov break;
630d8caf56eSAndrey V. Elsukov case TOK_LOG:
631d8caf56eSAndrey V. Elsukov cfg->flags |= NAT64_LOG;
632d8caf56eSAndrey V. Elsukov break;
633d8caf56eSAndrey V. Elsukov case TOK_LOGOFF:
634d8caf56eSAndrey V. Elsukov cfg->flags &= ~NAT64_LOG;
635d8caf56eSAndrey V. Elsukov break;
636b11efc1eSAndrey V. Elsukov case TOK_PRIVATE:
637b11efc1eSAndrey V. Elsukov cfg->flags |= NAT64_ALLOW_PRIVATE;
638b11efc1eSAndrey V. Elsukov break;
639b11efc1eSAndrey V. Elsukov case TOK_PRIVATEOFF:
640b11efc1eSAndrey V. Elsukov cfg->flags &= ~NAT64_ALLOW_PRIVATE;
641b11efc1eSAndrey V. Elsukov break;
642*4a77657cSAndrey V. Elsukov case TOK_SWAPCONF:
643*4a77657cSAndrey V. Elsukov cfg->flags |= NAT64LSN_ALLOW_SWAPCONF;
644*4a77657cSAndrey V. Elsukov break;
645*4a77657cSAndrey V. Elsukov case TOK_SWAPCONFOFF:
646*4a77657cSAndrey V. Elsukov cfg->flags &= ~NAT64LSN_ALLOW_SWAPCONF;
647*4a77657cSAndrey V. Elsukov break;
648d8caf56eSAndrey V. Elsukov default:
649d8caf56eSAndrey V. Elsukov errx(EX_USAGE, "Can't change %s option", opt);
650d8caf56eSAndrey V. Elsukov }
651d8caf56eSAndrey V. Elsukov }
652d8caf56eSAndrey V. Elsukov
653d8caf56eSAndrey V. Elsukov if (do_set3(IP_FW_NAT64LSN_CONFIG, &oh->opheader, sizeof(buf)) != 0)
654d8caf56eSAndrey V. Elsukov err(EX_OSERR, "nat64lsn instance configuration failed");
655d8caf56eSAndrey V. Elsukov }
656d8caf56eSAndrey V. Elsukov
657d8caf56eSAndrey V. Elsukov /*
658d8caf56eSAndrey V. Elsukov * Reset nat64lsn instance statistics specified by @oh->ntlv.
659d8caf56eSAndrey V. Elsukov * Request: [ ipfw_obj_header ]
660d8caf56eSAndrey V. Elsukov */
661d8caf56eSAndrey V. Elsukov static void
nat64lsn_reset_stats(const char * name,uint8_t set)662d8caf56eSAndrey V. Elsukov nat64lsn_reset_stats(const char *name, uint8_t set)
663d8caf56eSAndrey V. Elsukov {
664d8caf56eSAndrey V. Elsukov ipfw_obj_header oh;
665d8caf56eSAndrey V. Elsukov
666d8caf56eSAndrey V. Elsukov memset(&oh, 0, sizeof(oh));
667d8caf56eSAndrey V. Elsukov nat64lsn_fill_ntlv(&oh.ntlv, name, set);
668d8caf56eSAndrey V. Elsukov if (do_set3(IP_FW_NAT64LSN_RESET_STATS, &oh.opheader, sizeof(oh)) != 0)
669d8caf56eSAndrey V. Elsukov err(EX_OSERR, "failed to reset stats for instance %s", name);
670d8caf56eSAndrey V. Elsukov }
671d8caf56eSAndrey V. Elsukov
672d8caf56eSAndrey V. Elsukov /*
673d8caf56eSAndrey V. Elsukov * Destroys nat64lsn instance specified by @oh->ntlv.
674d8caf56eSAndrey V. Elsukov * Request: [ ipfw_obj_header ]
675d8caf56eSAndrey V. Elsukov */
676d8caf56eSAndrey V. Elsukov static void
nat64lsn_destroy(const char * name,uint8_t set)677d8caf56eSAndrey V. Elsukov nat64lsn_destroy(const char *name, uint8_t set)
678d8caf56eSAndrey V. Elsukov {
679d8caf56eSAndrey V. Elsukov ipfw_obj_header oh;
680d8caf56eSAndrey V. Elsukov
681d8caf56eSAndrey V. Elsukov memset(&oh, 0, sizeof(oh));
682d8caf56eSAndrey V. Elsukov nat64lsn_fill_ntlv(&oh.ntlv, name, set);
683d8caf56eSAndrey V. Elsukov if (do_set3(IP_FW_NAT64LSN_DESTROY, &oh.opheader, sizeof(oh)) != 0)
684d8caf56eSAndrey V. Elsukov err(EX_OSERR, "failed to destroy nat instance %s", name);
685d8caf56eSAndrey V. Elsukov }
686d8caf56eSAndrey V. Elsukov
687d8caf56eSAndrey V. Elsukov /*
688d8caf56eSAndrey V. Elsukov * Get nat64lsn instance statistics.
689d8caf56eSAndrey V. Elsukov * Request: [ ipfw_obj_header ]
690d8caf56eSAndrey V. Elsukov * Reply: [ ipfw_obj_header ipfw_obj_ctlv [ uint64_t x N ] ]
691d8caf56eSAndrey V. Elsukov */
692d8caf56eSAndrey V. Elsukov static int
nat64lsn_get_stats(const char * name,uint8_t set,struct ipfw_nat64lsn_stats * stats)693d8caf56eSAndrey V. Elsukov nat64lsn_get_stats(const char *name, uint8_t set,
694d8caf56eSAndrey V. Elsukov struct ipfw_nat64lsn_stats *stats)
695d8caf56eSAndrey V. Elsukov {
696d8caf56eSAndrey V. Elsukov ipfw_obj_header *oh;
697d8caf56eSAndrey V. Elsukov ipfw_obj_ctlv *oc;
698d8caf56eSAndrey V. Elsukov size_t sz;
699d8caf56eSAndrey V. Elsukov
700d8caf56eSAndrey V. Elsukov sz = sizeof(*oh) + sizeof(*oc) + sizeof(*stats);
701d8caf56eSAndrey V. Elsukov oh = calloc(1, sz);
702d8caf56eSAndrey V. Elsukov nat64lsn_fill_ntlv(&oh->ntlv, name, set);
703d8caf56eSAndrey V. Elsukov if (do_get3(IP_FW_NAT64LSN_STATS, &oh->opheader, &sz) == 0) {
704d8caf56eSAndrey V. Elsukov oc = (ipfw_obj_ctlv *)(oh + 1);
705d8caf56eSAndrey V. Elsukov memcpy(stats, oc + 1, sizeof(*stats));
706d8caf56eSAndrey V. Elsukov free(oh);
707d8caf56eSAndrey V. Elsukov return (0);
708d8caf56eSAndrey V. Elsukov }
709d8caf56eSAndrey V. Elsukov free(oh);
710d8caf56eSAndrey V. Elsukov return (-1);
711d8caf56eSAndrey V. Elsukov }
712d8caf56eSAndrey V. Elsukov
713d8caf56eSAndrey V. Elsukov static void
nat64lsn_stats(const char * name,uint8_t set)714d8caf56eSAndrey V. Elsukov nat64lsn_stats(const char *name, uint8_t set)
715d8caf56eSAndrey V. Elsukov {
716d8caf56eSAndrey V. Elsukov struct ipfw_nat64lsn_stats stats;
717d8caf56eSAndrey V. Elsukov
718d8caf56eSAndrey V. Elsukov if (nat64lsn_get_stats(name, set, &stats) != 0)
719d8caf56eSAndrey V. Elsukov err(EX_OSERR, "Error retrieving stats");
720d8caf56eSAndrey V. Elsukov
72156707beeSMark Johnston if (g_co.use_set != 0 || set != 0)
722c5e85276SAndrey V. Elsukov printf("set %u ", set);
723c5e85276SAndrey V. Elsukov printf("nat64lsn %s\n", name);
724c5e85276SAndrey V. Elsukov printf("\t%ju packets translated from IPv6 to IPv4\n",
725c5e85276SAndrey V. Elsukov (uintmax_t)stats.opcnt64);
726c5e85276SAndrey V. Elsukov printf("\t%ju packets translated from IPv4 to IPv6\n",
727c5e85276SAndrey V. Elsukov (uintmax_t)stats.opcnt46);
728c5e85276SAndrey V. Elsukov printf("\t%ju IPv6 fragments created\n",
729c5e85276SAndrey V. Elsukov (uintmax_t)stats.ofrags);
730c5e85276SAndrey V. Elsukov printf("\t%ju IPv4 fragments received\n",
731c5e85276SAndrey V. Elsukov (uintmax_t)stats.ifrags);
732c5e85276SAndrey V. Elsukov printf("\t%ju output packets dropped due to no bufs, etc.\n",
733c5e85276SAndrey V. Elsukov (uintmax_t)stats.oerrors);
734c5e85276SAndrey V. Elsukov printf("\t%ju output packets discarded due to no IPv4 route\n",
735c5e85276SAndrey V. Elsukov (uintmax_t)stats.noroute4);
736c5e85276SAndrey V. Elsukov printf("\t%ju output packets discarded due to no IPv6 route\n",
737c5e85276SAndrey V. Elsukov (uintmax_t)stats.noroute6);
738c5e85276SAndrey V. Elsukov printf("\t%ju packets discarded due to unsupported protocol\n",
739c5e85276SAndrey V. Elsukov (uintmax_t)stats.noproto);
740c5e85276SAndrey V. Elsukov printf("\t%ju packets discarded due to memory allocation problems\n",
741c5e85276SAndrey V. Elsukov (uintmax_t)stats.nomem);
742c5e85276SAndrey V. Elsukov printf("\t%ju packets discarded due to some errors\n",
743c5e85276SAndrey V. Elsukov (uintmax_t)stats.dropped);
744c5e85276SAndrey V. Elsukov printf("\t%ju packets not matched with IPv4 prefix\n",
745c5e85276SAndrey V. Elsukov (uintmax_t)stats.nomatch4);
746d8caf56eSAndrey V. Elsukov
747c5e85276SAndrey V. Elsukov printf("\t%ju mbufs queued for post processing\n",
748c5e85276SAndrey V. Elsukov (uintmax_t)stats.jreinjected);
749c5e85276SAndrey V. Elsukov printf("\t%ju times the job queue was processed\n",
750c5e85276SAndrey V. Elsukov (uintmax_t)stats.jcalls);
751c5e85276SAndrey V. Elsukov printf("\t%ju job requests queued\n",
752c5e85276SAndrey V. Elsukov (uintmax_t)stats.jrequests);
753c5e85276SAndrey V. Elsukov printf("\t%ju job requests queue limit reached\n",
754c5e85276SAndrey V. Elsukov (uintmax_t)stats.jmaxlen);
755c5e85276SAndrey V. Elsukov printf("\t%ju job requests failed due to memory allocation problems\n",
756c5e85276SAndrey V. Elsukov (uintmax_t)stats.jnomem);
757c5e85276SAndrey V. Elsukov
758c5e85276SAndrey V. Elsukov printf("\t%ju hosts allocated\n", (uintmax_t)stats.hostcount);
759c5e85276SAndrey V. Elsukov printf("\t%ju hosts requested\n", (uintmax_t)stats.jhostsreq);
760c5e85276SAndrey V. Elsukov printf("\t%ju host requests failed\n", (uintmax_t)stats.jhostfails);
761c5e85276SAndrey V. Elsukov
762c5e85276SAndrey V. Elsukov printf("\t%ju portgroups requested\n", (uintmax_t)stats.jportreq);
763c5e85276SAndrey V. Elsukov printf("\t%ju portgroups allocated\n", (uintmax_t)stats.spgcreated);
764c5e85276SAndrey V. Elsukov printf("\t%ju portgroups deleted\n", (uintmax_t)stats.spgdeleted);
765c5e85276SAndrey V. Elsukov printf("\t%ju portgroup requests failed\n",
766c5e85276SAndrey V. Elsukov (uintmax_t)stats.jportfails);
767c5e85276SAndrey V. Elsukov printf("\t%ju portgroups allocated for TCP\n",
768c5e85276SAndrey V. Elsukov (uintmax_t)stats.tcpchunks);
769c5e85276SAndrey V. Elsukov printf("\t%ju portgroups allocated for UDP\n",
770c5e85276SAndrey V. Elsukov (uintmax_t)stats.udpchunks);
771c5e85276SAndrey V. Elsukov printf("\t%ju portgroups allocated for ICMP\n",
772c5e85276SAndrey V. Elsukov (uintmax_t)stats.icmpchunks);
773c5e85276SAndrey V. Elsukov
774c5e85276SAndrey V. Elsukov printf("\t%ju states created\n", (uintmax_t)stats.screated);
775c5e85276SAndrey V. Elsukov printf("\t%ju states deleted\n", (uintmax_t)stats.sdeleted);
776d8caf56eSAndrey V. Elsukov }
777d8caf56eSAndrey V. Elsukov
778d8caf56eSAndrey V. Elsukov static int
nat64lsn_show_cb(ipfw_nat64lsn_cfg * cfg,const char * name,uint8_t set)779d8caf56eSAndrey V. Elsukov nat64lsn_show_cb(ipfw_nat64lsn_cfg *cfg, const char *name, uint8_t set)
780d8caf56eSAndrey V. Elsukov {
781d8caf56eSAndrey V. Elsukov char abuf[INET6_ADDRSTRLEN];
782d8caf56eSAndrey V. Elsukov
783d8caf56eSAndrey V. Elsukov if (name != NULL && strcmp(cfg->name, name) != 0)
784d8caf56eSAndrey V. Elsukov return (ESRCH);
785d8caf56eSAndrey V. Elsukov
78656707beeSMark Johnston if (g_co.use_set != 0 && cfg->set != set)
787d8caf56eSAndrey V. Elsukov return (ESRCH);
788d8caf56eSAndrey V. Elsukov
78956707beeSMark Johnston if (g_co.use_set != 0 || cfg->set != 0)
790d8caf56eSAndrey V. Elsukov printf("set %u ", cfg->set);
791d8caf56eSAndrey V. Elsukov inet_ntop(AF_INET, &cfg->prefix4, abuf, sizeof(abuf));
792d8caf56eSAndrey V. Elsukov printf("nat64lsn %s prefix4 %s/%u", cfg->name, abuf, cfg->plen4);
793d8caf56eSAndrey V. Elsukov inet_ntop(AF_INET6, &cfg->prefix6, abuf, sizeof(abuf));
794d8caf56eSAndrey V. Elsukov printf(" prefix6 %s/%u", abuf, cfg->plen6);
79556707beeSMark Johnston if (g_co.verbose || cfg->states_chunks > 1)
796d18c1f26SAndrey V. Elsukov printf(" states_chunks %u", cfg->states_chunks);
79756707beeSMark Johnston if (g_co.verbose || cfg->nh_delete_delay != NAT64LSN_HOST_AGE)
798d6369c2dSAndrey V. Elsukov printf(" host_del_age %u", cfg->nh_delete_delay);
79956707beeSMark Johnston if (g_co.verbose || cfg->pg_delete_delay != NAT64LSN_PG_AGE)
800d6369c2dSAndrey V. Elsukov printf(" pg_del_age %u", cfg->pg_delete_delay);
80156707beeSMark Johnston if (g_co.verbose || cfg->st_syn_ttl != NAT64LSN_TCP_SYN_AGE)
802d6369c2dSAndrey V. Elsukov printf(" tcp_syn_age %u", cfg->st_syn_ttl);
80356707beeSMark Johnston if (g_co.verbose || cfg->st_close_ttl != NAT64LSN_TCP_FIN_AGE)
804d6369c2dSAndrey V. Elsukov printf(" tcp_close_age %u", cfg->st_close_ttl);
80556707beeSMark Johnston if (g_co.verbose || cfg->st_estab_ttl != NAT64LSN_TCP_EST_AGE)
806d6369c2dSAndrey V. Elsukov printf(" tcp_est_age %u", cfg->st_estab_ttl);
80756707beeSMark Johnston if (g_co.verbose || cfg->st_udp_ttl != NAT64LSN_UDP_AGE)
808d6369c2dSAndrey V. Elsukov printf(" udp_age %u", cfg->st_udp_ttl);
80956707beeSMark Johnston if (g_co.verbose || cfg->st_icmp_ttl != NAT64LSN_ICMP_AGE)
810d6369c2dSAndrey V. Elsukov printf(" icmp_age %u", cfg->st_icmp_ttl);
81156707beeSMark Johnston if (g_co.verbose || cfg->jmaxlen != NAT64LSN_JMAXLEN)
812d18c1f26SAndrey V. Elsukov printf(" jmaxlen %u", cfg->jmaxlen);
813*4a77657cSAndrey V. Elsukov if (cfg->flags & NAT64LSN_ALLOW_SWAPCONF)
814*4a77657cSAndrey V. Elsukov printf(" swap_conf");
815d8caf56eSAndrey V. Elsukov if (cfg->flags & NAT64_LOG)
816d8caf56eSAndrey V. Elsukov printf(" log");
817b11efc1eSAndrey V. Elsukov if (cfg->flags & NAT64_ALLOW_PRIVATE)
818b11efc1eSAndrey V. Elsukov printf(" allow_private");
819d8caf56eSAndrey V. Elsukov printf("\n");
820d8caf56eSAndrey V. Elsukov return (0);
821d8caf56eSAndrey V. Elsukov }
822d8caf56eSAndrey V. Elsukov
823d8caf56eSAndrey V. Elsukov static int
nat64lsn_destroy_cb(ipfw_nat64lsn_cfg * cfg,const char * name __unused,uint8_t set)82456707beeSMark Johnston nat64lsn_destroy_cb(ipfw_nat64lsn_cfg *cfg, const char *name __unused,
82556707beeSMark Johnston uint8_t set)
826d8caf56eSAndrey V. Elsukov {
827d8caf56eSAndrey V. Elsukov
82856707beeSMark Johnston if (g_co.use_set != 0 && cfg->set != set)
829d8caf56eSAndrey V. Elsukov return (ESRCH);
830d8caf56eSAndrey V. Elsukov
831d8caf56eSAndrey V. Elsukov nat64lsn_destroy(cfg->name, cfg->set);
832d8caf56eSAndrey V. Elsukov return (0);
833d8caf56eSAndrey V. Elsukov }
834d8caf56eSAndrey V. Elsukov
835d8caf56eSAndrey V. Elsukov
836d8caf56eSAndrey V. Elsukov /*
837d8caf56eSAndrey V. Elsukov * Compare nat64lsn instances names.
838d8caf56eSAndrey V. Elsukov * Honor number comparison.
839d8caf56eSAndrey V. Elsukov */
840d8caf56eSAndrey V. Elsukov static int
nat64name_cmp(const void * a,const void * b)841d8caf56eSAndrey V. Elsukov nat64name_cmp(const void *a, const void *b)
842d8caf56eSAndrey V. Elsukov {
84356707beeSMark Johnston const ipfw_nat64lsn_cfg *ca, *cb;
844d8caf56eSAndrey V. Elsukov
84556707beeSMark Johnston ca = (const ipfw_nat64lsn_cfg *)a;
84656707beeSMark Johnston cb = (const ipfw_nat64lsn_cfg *)b;
847d8caf56eSAndrey V. Elsukov
848d8caf56eSAndrey V. Elsukov if (ca->set > cb->set)
849d8caf56eSAndrey V. Elsukov return (1);
850d8caf56eSAndrey V. Elsukov else if (ca->set < cb->set)
851d8caf56eSAndrey V. Elsukov return (-1);
852d8caf56eSAndrey V. Elsukov return (stringnum_cmp(ca->name, cb->name));
853d8caf56eSAndrey V. Elsukov }
854d8caf56eSAndrey V. Elsukov
855d8caf56eSAndrey V. Elsukov /*
856d8caf56eSAndrey V. Elsukov * Retrieves nat64lsn instance list from kernel,
857d8caf56eSAndrey V. Elsukov * optionally sorts it and calls requested function for each instance.
858d8caf56eSAndrey V. Elsukov *
859d8caf56eSAndrey V. Elsukov * Request: [ ipfw_obj_lheader ]
860d8caf56eSAndrey V. Elsukov * Reply: [ ipfw_obj_lheader ipfw_nat64lsn_cfg x N ]
861d8caf56eSAndrey V. Elsukov */
862d8caf56eSAndrey V. Elsukov static int
nat64lsn_foreach(nat64lsn_cb_t * f,const char * name,uint8_t set,int sort)863d8caf56eSAndrey V. Elsukov nat64lsn_foreach(nat64lsn_cb_t *f, const char *name, uint8_t set, int sort)
864d8caf56eSAndrey V. Elsukov {
865d8caf56eSAndrey V. Elsukov ipfw_obj_lheader *olh;
866d8caf56eSAndrey V. Elsukov ipfw_nat64lsn_cfg *cfg;
867d8caf56eSAndrey V. Elsukov size_t sz;
86856707beeSMark Johnston uint32_t i;
869d8caf56eSAndrey V. Elsukov
870d8caf56eSAndrey V. Elsukov /* Start with reasonable default */
871d8caf56eSAndrey V. Elsukov sz = sizeof(*olh) + 16 * sizeof(ipfw_nat64lsn_cfg);
872d8caf56eSAndrey V. Elsukov
873d8caf56eSAndrey V. Elsukov for (;;) {
874d8caf56eSAndrey V. Elsukov if ((olh = calloc(1, sz)) == NULL)
875d8caf56eSAndrey V. Elsukov return (ENOMEM);
876d8caf56eSAndrey V. Elsukov
877d8caf56eSAndrey V. Elsukov olh->size = sz;
878d8caf56eSAndrey V. Elsukov if (do_get3(IP_FW_NAT64LSN_LIST, &olh->opheader, &sz) != 0) {
879d8caf56eSAndrey V. Elsukov sz = olh->size;
880d8caf56eSAndrey V. Elsukov free(olh);
881d8caf56eSAndrey V. Elsukov if (errno != ENOMEM)
882d8caf56eSAndrey V. Elsukov return (errno);
883d8caf56eSAndrey V. Elsukov continue;
884d8caf56eSAndrey V. Elsukov }
885d8caf56eSAndrey V. Elsukov
886d8caf56eSAndrey V. Elsukov if (sort != 0)
887d8caf56eSAndrey V. Elsukov qsort(olh + 1, olh->count, olh->objsize,
888d8caf56eSAndrey V. Elsukov nat64name_cmp);
889d8caf56eSAndrey V. Elsukov
890d8caf56eSAndrey V. Elsukov cfg = (ipfw_nat64lsn_cfg *)(olh + 1);
891d8caf56eSAndrey V. Elsukov for (i = 0; i < olh->count; i++) {
892f5e73306SJohn Baldwin (void)f(cfg, name, set); /* Ignore errors for now */
893d8caf56eSAndrey V. Elsukov cfg = (ipfw_nat64lsn_cfg *)((caddr_t)cfg +
894d8caf56eSAndrey V. Elsukov olh->objsize);
895d8caf56eSAndrey V. Elsukov }
896d8caf56eSAndrey V. Elsukov free(olh);
897d8caf56eSAndrey V. Elsukov break;
898d8caf56eSAndrey V. Elsukov }
899d8caf56eSAndrey V. Elsukov return (0);
900d8caf56eSAndrey V. Elsukov }
901d8caf56eSAndrey V. Elsukov
902