2 * Copyright (c) 2014 Yandex LLC
3 * Copyright (c) 2014 Alexander V. Chernikov
5 * Redistribution and use in source forms, with and without modification,
6 * are permitted provided that this entire comment appears intact.
8 * Redistribution in binary form may occur without any restrictions.
9 * Obviously, it would be nice if you gave credit where credit is due
10 * but requiring it would be too onerous.
12 * This software is provided ``AS IS'' without any warranties of any kind.
14 * in-kernel ipfw tables support.
20 #include <sys/types.h>
21 #include <sys/param.h>
22 #include <sys/socket.h>
23 #include <sys/sysctl.h>
35 #include <netinet/in.h>
36 #include <netinet/ip_fw.h>
37 #include <arpa/inet.h>
42 static void table_modify_record(ipfw_obj_header *oh, int ac, char *av[],
43 int add, int quiet, int update, int atomic);
44 static int table_flush(ipfw_obj_header *oh);
45 static int table_destroy(ipfw_obj_header *oh);
46 static int table_do_create(ipfw_obj_header *oh, ipfw_xtable_info *i);
47 static int table_do_modify(ipfw_obj_header *oh, ipfw_xtable_info *i);
48 static int table_do_swap(ipfw_obj_header *oh, char *second);
49 static void table_create(ipfw_obj_header *oh, int ac, char *av[]);
50 static void table_modify(ipfw_obj_header *oh, int ac, char *av[]);
51 static void table_lookup(ipfw_obj_header *oh, int ac, char *av[]);
52 static void table_lock(ipfw_obj_header *oh, int lock);
53 static int table_swap(ipfw_obj_header *oh, char *second);
54 static int table_get_info(ipfw_obj_header *oh, ipfw_xtable_info *i);
55 static int table_show_info(ipfw_xtable_info *i, void *arg);
57 static int table_destroy_one(ipfw_xtable_info *i, void *arg);
58 static int table_flush_one(ipfw_xtable_info *i, void *arg);
59 static int table_show_one(ipfw_xtable_info *i, void *arg);
60 static int table_do_get_list(ipfw_xtable_info *i, ipfw_obj_header **poh);
61 static void table_show_list(ipfw_obj_header *oh, int need_header);
62 static void table_show_entry(ipfw_xtable_info *i, ipfw_obj_tentry *tent);
64 static void tentry_fill_key(ipfw_obj_header *oh, ipfw_obj_tentry *tent,
65 char *key, int add, uint8_t *ptype, uint32_t *pvmask, ipfw_xtable_info *xi);
66 static void tentry_fill_value(ipfw_obj_header *oh, ipfw_obj_tentry *tent,
67 char *arg, uint8_t type, uint32_t vmask);
68 static void table_show_value(char *buf, size_t bufsize, ipfw_table_value *v,
69 uint32_t vmask, int print_ip);
71 typedef int (table_cb_t)(ipfw_xtable_info *i, void *arg);
72 static int tables_foreach(table_cb_t *f, void *arg, int sort);
75 #define s6_addr32 __u6_addr.__u6_addr32
78 static struct _s_x tabletypes[] = {
79 { "addr", IPFW_TABLE_ADDR },
80 { "iface", IPFW_TABLE_INTERFACE },
81 { "number", IPFW_TABLE_NUMBER },
82 { "flow", IPFW_TABLE_FLOW },
86 /* Default algorithms for various table types */
87 static struct _s_x tablealgos[] = {
88 { "addr:radix", IPFW_TABLE_ADDR },
89 { "flow:hash", IPFW_TABLE_FLOW },
90 { "iface:array", IPFW_TABLE_INTERFACE },
91 { "number:array", IPFW_TABLE_NUMBER },
95 static struct _s_x tablevaltypes[] = {
96 { "skipto", IPFW_VTYPE_SKIPTO },
97 { "pipe", IPFW_VTYPE_PIPE },
98 { "fib", IPFW_VTYPE_FIB },
99 { "nat", IPFW_VTYPE_NAT },
100 { "dscp", IPFW_VTYPE_DSCP },
101 { "tag", IPFW_VTYPE_TAG },
102 { "divert", IPFW_VTYPE_DIVERT },
103 { "netgraph", IPFW_VTYPE_NETGRAPH },
104 { "limit", IPFW_VTYPE_LIMIT },
105 { "ipv4", IPFW_VTYPE_NH4 },
106 { "ipv6", IPFW_VTYPE_NH6 },
110 static struct _s_x tablecmds[] = {
112 { "delete", TOK_DEL },
113 { "create", TOK_CREATE },
114 { "destroy", TOK_DESTROY },
115 { "flush", TOK_FLUSH },
116 { "modify", TOK_MODIFY },
117 { "swap", TOK_SWAP },
118 { "info", TOK_INFO },
119 { "detail", TOK_DETAIL },
120 { "list", TOK_LIST },
121 { "lookup", TOK_LOOKUP },
122 { "atomic", TOK_ATOMIC },
123 { "lock", TOK_LOCK },
124 { "unlock", TOK_UNLOCK },
129 lookup_host (char *host, struct in_addr *ipaddr)
133 if (!inet_aton(host, ipaddr)) {
134 if ((he = gethostbyname(host)) == NULL)
136 *ipaddr = *(struct in_addr *)he->h_addr_list[0];
142 * This one handles all table-related commands
143 * ipfw table NAME create ...
144 * ipfw table NAME modify ...
145 * ipfw table {NAME | all} destroy
146 * ipfw table NAME swap NAME
147 * ipfw table NAME lock
148 * ipfw table NAME unlock
149 * ipfw table NAME add addr[/masklen] [value]
150 * ipfw table NAME add [addr[/masklen] value] [addr[/masklen] value] ..
151 * ipfw table NAME delete addr[/masklen] [addr[/masklen]] ..
152 * ipfw table NAME lookup addr
153 * ipfw table {NAME | all} flush
154 * ipfw table {NAME | all} list
155 * ipfw table {NAME | all} info
156 * ipfw table {NAME | all} detail
159 ipfw_table_handler(int ac, char *av[])
162 int atomic, error, tcmd;
169 memset(&oh, 0, sizeof(oh));
171 if (g_co.use_set != 0)
172 set = g_co.use_set - 1;
177 NEED1("table needs name");
180 if (table_check_name(tablename) == 0) {
181 table_fill_ntlv(&oh.ntlv, *av, set, 1);
184 if (strcmp(tablename, "all") == 0)
187 errx(EX_USAGE, "table name %s is invalid", tablename);
190 NEED1("table needs command");
192 tcmd = get_token(tablecmds, *av, "table command");
193 /* Check if atomic operation was requested */
195 if (tcmd == TOK_ATOMIC) {
197 NEED1("atomic needs command");
198 tcmd = get_token(tablecmds, *av, "table command");
203 errx(EX_USAGE, "atomic is not compatible with %s", *av);
217 errx(EX_USAGE, "table name required");
223 do_add = **av == 'a';
225 table_modify_record(&oh, ac, av, do_add, g_co.do_quiet,
226 g_co.do_quiet, atomic);
230 table_create(&oh, ac, av);
234 table_modify(&oh, ac, av);
238 if (table_destroy(&oh) == 0)
241 err(EX_OSERR, "failed to destroy table %s",
243 /* ESRCH isn't fatal, warn if not quiet mode */
244 if (g_co.do_quiet == 0)
245 warn("failed to destroy table %s", tablename);
247 error = tables_foreach(table_destroy_one, &oh, 1);
250 "failed to destroy tables list");
255 if ((error = table_flush(&oh)) == 0)
258 err(EX_OSERR, "failed to flush table %s info",
260 /* ESRCH isn't fatal, warn if not quiet mode */
261 if (g_co.do_quiet == 0)
262 warn("failed to flush table %s info",
265 error = tables_foreach(table_flush_one, &oh, 1);
267 err(EX_OSERR, "failed to flush tables list");
268 /* XXX: we ignore errors here */
273 NEED1("second table name required");
274 table_swap(&oh, *av);
278 table_lock(&oh, (tcmd == TOK_LOCK));
282 arg = (tcmd == TOK_DETAIL) ? (void *)1 : NULL;
284 if ((error = table_get_info(&oh, &i)) != 0)
285 err(EX_OSERR, "failed to request table info");
286 table_show_info(&i, arg);
288 error = tables_foreach(table_show_info, arg, 1);
290 err(EX_OSERR, "failed to request tables list");
294 arg = is_all ? (void*)1 : NULL;
296 if ((error = table_get_info(&oh, &i)) != 0)
297 err(EX_OSERR, "failed to request table info");
298 table_show_one(&i, arg);
300 error = tables_foreach(table_show_one, arg, 1);
302 err(EX_OSERR, "failed to request tables list");
307 table_lookup(&oh, ac, av);
313 table_fill_ntlv(ipfw_obj_ntlv *ntlv, const char *name, uint8_t set,
317 ntlv->head.type = IPFW_TLV_TBL_NAME;
318 ntlv->head.length = sizeof(ipfw_obj_ntlv);
321 strlcpy(ntlv->name, name, sizeof(ntlv->name));
325 table_fill_objheader(ipfw_obj_header *oh, ipfw_xtable_info *i)
329 table_fill_ntlv(&oh->ntlv, i->tablename, i->set, 1);
332 static struct _s_x tablenewcmds[] = {
333 { "type", TOK_TYPE },
334 { "valtype", TOK_VALTYPE },
335 { "algo", TOK_ALGO },
336 { "limit", TOK_LIMIT },
337 { "locked", TOK_LOCK },
338 { "missing", TOK_MISSING },
339 { "or-flush", TOK_ORFLUSH },
343 static struct _s_x flowtypecmds[] = {
344 { "src-ip", IPFW_TFFLAG_SRCIP },
345 { "proto", IPFW_TFFLAG_PROTO },
346 { "src-port", IPFW_TFFLAG_SRCPORT },
347 { "dst-ip", IPFW_TFFLAG_DSTIP },
348 { "dst-port", IPFW_TFFLAG_DSTPORT },
353 table_parse_type(uint8_t ttype, char *p, uint8_t *tflags)
355 uint32_t fset, fclear;
358 /* Parse type options */
360 case IPFW_TABLE_FLOW:
362 if (fill_flags(flowtypecmds, p, &e, &fset, &fclear) != 0)
364 "unable to parse flow option %s", e);
375 table_print_type(char *tbuf, size_t size, uint8_t type, uint8_t tflags)
380 if ((tname = match_value(tabletypes, type)) == NULL)
383 l = snprintf(tbuf, size, "%s", tname);
388 case IPFW_TABLE_FLOW:
392 print_flags_buffer(tbuf, size, flowtypecmds, tflags);
401 * ipfw table NAME create [ type { addr | iface | number | flow } ]
402 * [ algo algoname ] [missing] [or-flush]
405 table_create(ipfw_obj_header *oh, int ac, char *av[])
407 ipfw_xtable_info xi, xie;
408 int error, missing, orflush, tcmd, val;
409 uint32_t fset, fclear;
413 missing = orflush = 0;
414 memset(&xi, 0, sizeof(xi));
416 tcmd = get_token(tablenewcmds, *av, "option");
421 NEED1("limit value required");
422 xi.limit = strtol(*av, NULL, 10);
426 NEED1("table type required");
427 /* Type may have suboptions after ':' */
428 if ((p = strchr(*av, ':')) != NULL)
430 val = match_token(tabletypes, *av);
432 concat_tokens(tbuf, sizeof(tbuf), tabletypes,
435 "Unknown tabletype: %s. Supported: %s",
440 error = table_parse_type(val, p, &xi.tflags);
443 "Unsupported suboptions: %s", p);
448 NEED1("table value type required");
450 val = fill_flags(tablevaltypes, *av, &e, &fset, &fclear);
456 concat_tokens(tbuf, sizeof(tbuf), tablevaltypes, ", ");
457 errx(EX_USAGE, "Unknown value type: %s. Supported: %s",
461 NEED1("table algorithm name required");
462 if (strlen(*av) > sizeof(xi.algoname))
463 errx(EX_USAGE, "algorithm name too long");
464 strlcpy(xi.algoname, *av, sizeof(xi.algoname));
468 xi.flags |= IPFW_TGFLAGS_LOCKED;
479 /* Set some defaults to preserve compatibility. */
480 if (xi.algoname[0] == '\0') {
484 xi.type = IPFW_TABLE_ADDR;
485 algo = match_value(tablealgos, xi.type);
487 strlcpy(xi.algoname, algo, sizeof(xi.algoname));
490 xi.vmask = IPFW_VTYPE_LEGACY;
492 error = table_do_create(oh, &xi);
497 if (errno != EEXIST || missing == 0)
498 err(EX_OSERR, "Table creation failed");
500 /* Check that existing table is the same we are trying to create */
501 if (table_get_info(oh, &xie) != 0)
502 err(EX_OSERR, "Existing table check failed");
504 if (xi.limit != xie.limit || xi.type != xie.type ||
505 xi.tflags != xie.tflags || xi.vmask != xie.vmask || (
506 xi.algoname[0] != '\0' && strcmp(xi.algoname,
507 xie.algoname) != 0) || xi.flags != xie.flags)
508 errx(EX_DATAERR, "The existing table is not compatible "
509 "with one you are creating.");
511 /* Flush existing table if instructed to do so */
512 if (orflush != 0 && table_flush(oh) != 0)
513 err(EX_OSERR, "Table flush on creation failed");
519 * Request: [ ipfw_obj_header ipfw_xtable_info ]
521 * Returns 0 on success.
524 table_do_create(ipfw_obj_header *oh, ipfw_xtable_info *i)
526 char tbuf[sizeof(ipfw_obj_header) + sizeof(ipfw_xtable_info)];
529 memcpy(tbuf, oh, sizeof(*oh));
530 memcpy(tbuf + sizeof(*oh), i, sizeof(*i));
531 oh = (ipfw_obj_header *)tbuf;
533 error = do_set3(IP_FW_TABLE_XCREATE, &oh->opheader, sizeof(tbuf));
539 * Modifies existing table
541 * ipfw table NAME modify [ limit number ]
544 table_modify(ipfw_obj_header *oh, int ac, char *av[])
549 memset(&xi, 0, sizeof(xi));
552 tcmd = get_token(tablenewcmds, *av, "option");
557 NEED1("limit value required");
558 xi.limit = strtol(*av, NULL, 10);
559 xi.mflags |= IPFW_TMFLAGS_LIMIT;
563 errx(EX_USAGE, "cmd is not supported for modification");
567 if (table_do_modify(oh, &xi) != 0)
568 err(EX_OSERR, "Table modification failed");
572 * Modifies existing table.
574 * Request: [ ipfw_obj_header ipfw_xtable_info ]
576 * Returns 0 on success.
579 table_do_modify(ipfw_obj_header *oh, ipfw_xtable_info *i)
581 char tbuf[sizeof(ipfw_obj_header) + sizeof(ipfw_xtable_info)];
584 memcpy(tbuf, oh, sizeof(*oh));
585 memcpy(tbuf + sizeof(*oh), i, sizeof(*i));
586 oh = (ipfw_obj_header *)tbuf;
588 error = do_set3(IP_FW_TABLE_XMODIFY, &oh->opheader, sizeof(tbuf));
594 * Locks or unlocks given table
597 table_lock(ipfw_obj_header *oh, int lock)
601 memset(&xi, 0, sizeof(xi));
603 xi.mflags |= IPFW_TMFLAGS_LOCK;
604 xi.flags |= (lock != 0) ? IPFW_TGFLAGS_LOCKED : 0;
606 if (table_do_modify(oh, &xi) != 0)
607 err(EX_OSERR, "Table %s failed", lock != 0 ? "lock" : "unlock");
611 * Destroys given table specified by @oh->ntlv.
612 * Returns 0 on success.
615 table_destroy(ipfw_obj_header *oh)
618 if (do_set3(IP_FW_TABLE_XDESTROY, &oh->opheader, sizeof(*oh)) != 0)
625 table_destroy_one(ipfw_xtable_info *i, void *arg)
629 oh = (ipfw_obj_header *)arg;
630 table_fill_ntlv(&oh->ntlv, i->tablename, i->set, 1);
631 if (table_destroy(oh) != 0) {
632 if (g_co.do_quiet == 0)
633 warn("failed to destroy table(%s) in set %u",
634 i->tablename, i->set);
641 * Flushes given table specified by @oh->ntlv.
642 * Returns 0 on success.
645 table_flush(ipfw_obj_header *oh)
648 if (do_set3(IP_FW_TABLE_XFLUSH, &oh->opheader, sizeof(*oh)) != 0)
655 table_do_swap(ipfw_obj_header *oh, char *second)
657 char tbuf[sizeof(ipfw_obj_header) + sizeof(ipfw_obj_ntlv)];
660 memset(tbuf, 0, sizeof(tbuf));
661 memcpy(tbuf, oh, sizeof(*oh));
662 oh = (ipfw_obj_header *)tbuf;
663 table_fill_ntlv((ipfw_obj_ntlv *)(oh + 1), second, oh->ntlv.set, 1);
665 error = do_set3(IP_FW_TABLE_XSWAP, &oh->opheader, sizeof(tbuf));
671 * Swaps given table with @second one.
674 table_swap(ipfw_obj_header *oh, char *second)
677 if (table_check_name(second) != 0)
678 errx(EX_USAGE, "table name %s is invalid", second);
680 if (table_do_swap(oh, second) == 0)
685 errx(EX_USAGE, "Unable to swap table: check types");
687 errx(EX_USAGE, "Unable to swap table: check limits");
695 * Retrieves table in given table specified by @oh->ntlv.
697 * Returns 0 on success.
700 table_get_info(ipfw_obj_header *oh, ipfw_xtable_info *i)
702 char tbuf[sizeof(ipfw_obj_header) + sizeof(ipfw_xtable_info)];
706 memset(tbuf, 0, sizeof(tbuf));
707 memcpy(tbuf, oh, sizeof(*oh));
708 oh = (ipfw_obj_header *)tbuf;
710 if (do_get3(IP_FW_TABLE_XINFO, &oh->opheader, &sz) != 0)
713 if (sz < sizeof(tbuf))
716 *i = *(ipfw_xtable_info *)(oh + 1);
721 static struct _s_x tablealgoclass[] = {
722 { "hash", IPFW_TACLASS_HASH },
723 { "array", IPFW_TACLASS_ARRAY },
724 { "radix", IPFW_TACLASS_RADIX },
738 * Print global/per-AF table @i algorithm info.
741 table_show_tainfo(ipfw_xtable_info *i __unused, struct ta_cldata *d,
742 const char *af, const char *taclass)
745 switch (d->taclass) {
746 case IPFW_TACLASS_HASH:
747 case IPFW_TACLASS_ARRAY:
748 printf(" %salgorithm %s info\n", af, taclass);
749 if (d->itemsize == d->itemsize6)
750 printf(" size: %u items: %u itemsize: %u\n",
751 d->size, d->count, d->itemsize);
753 printf(" size: %u items: %u "
754 "itemsize4: %u itemsize6: %u\n",
756 d->itemsize, d->itemsize6);
758 case IPFW_TACLASS_RADIX:
759 printf(" %salgorithm %s info\n", af, taclass);
760 if (d->itemsize == d->itemsize6)
761 printf(" items: %u itemsize: %u\n",
762 d->count, d->itemsize);
765 "itemsize4: %u itemsize6: %u\n",
766 d->count, d->itemsize, d->itemsize6);
769 printf(" algo class: %s\n", taclass);
774 table_print_valheader(char *buf, size_t bufsize, uint32_t vmask)
777 if (vmask == IPFW_VTYPE_LEGACY) {
778 snprintf(buf, bufsize, "legacy");
782 memset(buf, 0, bufsize);
783 print_flags_buffer(buf, bufsize, tablevaltypes, vmask);
787 * Prints table info struct @i in human-readable form.
790 table_show_info(ipfw_xtable_info *i, void *arg)
793 ipfw_ta_tinfo *tainfo;
796 char ttype[64], tvtype[64];
798 table_print_type(ttype, sizeof(ttype), i->type, i->tflags);
799 table_print_valheader(tvtype, sizeof(tvtype), i->vmask);
801 printf("--- table(%s), set(%u) ---\n", i->tablename, i->set);
802 if ((i->flags & IPFW_TGFLAGS_LOCKED) != 0)
803 printf(" kindex: %d, type: %s, locked\n", i->kidx, ttype);
805 printf(" kindex: %d, type: %s\n", i->kidx, ttype);
806 printf(" references: %u, valtype: %s\n", i->refcnt, tvtype);
807 printf(" algorithm: %s\n", i->algoname);
808 printf(" items: %u, size: %u\n", i->count, i->size);
810 printf(" limit: %u\n", i->limit);
812 /* Print algo-specific info if requested & set */
816 if ((i->ta_info.flags & IPFW_TATFLAGS_DATA) == 0)
818 tainfo = &i->ta_info;
822 if (tainfo->flags & IPFW_TATFLAGS_AFDATA)
824 if (tainfo->flags & IPFW_TATFLAGS_AFITEM)
827 memset(&d, 0, sizeof(d));
828 d.taclass = tainfo->taclass4;
829 d.size = tainfo->size4;
830 d.count = tainfo->count4;
831 d.itemsize = tainfo->itemsize4;
832 if (afdata == 0 && afitem != 0)
833 d.itemsize6 = tainfo->itemsize6;
835 d.itemsize6 = d.itemsize;
836 if ((vtype = match_value(tablealgoclass, d.taclass)) == NULL)
840 table_show_tainfo(i, &d, "", vtype);
842 table_show_tainfo(i, &d, "IPv4 ", vtype);
843 memset(&d, 0, sizeof(d));
844 d.taclass = tainfo->taclass6;
845 if ((vtype = match_value(tablealgoclass, d.taclass)) == NULL)
847 d.size = tainfo->size6;
848 d.count = tainfo->count6;
849 d.itemsize = tainfo->itemsize6;
850 d.itemsize6 = d.itemsize;
851 table_show_tainfo(i, &d, "IPv6 ", vtype);
859 * Function wrappers which can be used either
860 * as is or as foreach function parameter.
864 table_show_one(ipfw_xtable_info *i, void *arg)
866 ipfw_obj_header *oh = NULL;
870 is_all = arg == NULL ? 0 : 1;
872 if ((error = table_do_get_list(i, &oh)) != 0) {
873 err(EX_OSERR, "Error requesting table %s list", i->tablename);
877 table_show_list(oh, is_all);
884 table_flush_one(ipfw_xtable_info *i, void *arg)
888 oh = (ipfw_obj_header *)arg;
890 table_fill_ntlv(&oh->ntlv, i->tablename, i->set, 1);
892 return (table_flush(oh));
896 table_do_modify_record(int cmd, ipfw_obj_header *oh,
897 ipfw_obj_tentry *tent, int count, int atomic)
900 ipfw_obj_tentry *tent_base;
902 char xbuf[sizeof(*oh) + sizeof(ipfw_obj_ctlv) + sizeof(*tent)];
906 sz = sizeof(*ctlv) + sizeof(*tent) * count;
908 memset(xbuf, 0, sizeof(xbuf));
911 if ((pbuf = calloc(1, sizeof(*oh) + sz)) == NULL)
915 memcpy(pbuf, oh, sizeof(*oh));
916 oh = (ipfw_obj_header *)pbuf;
917 oh->opheader.version = 1;
919 ctlv = (ipfw_obj_ctlv *)(oh + 1);
921 ctlv->head.length = sz;
923 ctlv->flags |= IPFW_CTF_ATOMIC;
926 memcpy(ctlv + 1, tent, sizeof(*tent) * count);
927 tent = (ipfw_obj_tentry *)(ctlv + 1);
928 for (i = 0; i < count; i++, tent++) {
929 tent->head.length = sizeof(ipfw_obj_tentry);
934 error = do_get3(cmd, &oh->opheader, &sz);
937 tent = (ipfw_obj_tentry *)(ctlv + 1);
938 /* Copy result back to provided buffer */
939 memcpy(tent_base, ctlv + 1, sizeof(*tent) * count);
948 table_modify_record(ipfw_obj_header *oh, int ac, char *av[], int add,
949 int quiet, int update, int atomic)
951 ipfw_obj_tentry *ptent, tent, *tent_buf;
953 const char *etxt, *px, *texterr;
956 int cmd, count, error, i, ignored;
959 errx(EX_USAGE, "address required");
962 cmd = IP_FW_TABLE_XADD;
963 texterr = "Adding record failed";
965 cmd = IP_FW_TABLE_XDEL;
966 texterr = "Deleting record failed";
970 * Calculate number of entries:
971 * Assume [key val] x N for add
975 count = (add != 0) ? ac / 2 + 1 : ac;
978 /* Adding single entry with/without value */
979 memset(&tent, 0, sizeof(tent));
983 if ((tent_buf = calloc(count, sizeof(tent))) == NULL)
985 "Unable to allocate memory for all entries");
989 memset(&xi, 0, sizeof(xi));
992 tentry_fill_key(oh, ptent, *av, add, &type, &vmask, &xi);
995 * Compatibility layer: auto-create table if not exists.
997 if (xi.tablename[0] == '\0') {
1000 strlcpy(xi.tablename, oh->ntlv.name,
1001 sizeof(xi.tablename));
1003 warnx("DEPRECATED: inserting data into "
1004 "non-existent table %s. (auto-created)",
1006 table_do_create(oh, &xi);
1009 oh->ntlv.type = type;
1012 if (add != 0 && ac > 0) {
1013 tentry_fill_value(oh, ptent, *av, type, vmask);
1018 ptent->head.flags |= IPFW_TF_UPDATE;
1024 error = table_do_modify_record(cmd, oh, tent_buf, count, atomic);
1027 * Compatibility stuff: do not yell on duplicate keys or
1030 if (error == 0 || (error == EEXIST && add != 0) ||
1031 (error == ENOENT && add == 0)) {
1033 if (tent_buf != &tent)
1039 /* Report results back */
1041 for (i = 0; i < count; ptent++, i++) {
1043 switch (ptent->result) {
1047 case IPFW_TR_DELETED:
1050 case IPFW_TR_UPDATED:
1061 case IPFW_TR_NOTFOUND:
1065 case IPFW_TR_EXISTS:
1069 case IPFW_TR_IGNORED:
1078 if (error != 0 && atomic != 0 && ignored == 0)
1079 printf("%s(reverted): ", px);
1083 table_show_entry(&xi, ptent);
1086 if (tent_buf != &tent)
1091 /* Get real OS error */
1094 /* Try to provide more human-readable error */
1097 etxt = "record already exists";
1103 etxt = "table not found";
1106 etxt = "record not found";
1109 etxt = "table is locked";
1112 etxt = strerror(error);
1115 errx(EX_OSERR, "%s: %s", texterr, etxt);
1119 table_do_lookup(ipfw_obj_header *oh, char *key, ipfw_xtable_info *xi,
1120 ipfw_obj_tentry *xtent)
1122 char xbuf[sizeof(ipfw_obj_header) + sizeof(ipfw_obj_tentry)];
1123 ipfw_obj_tentry *tent;
1128 memcpy(xbuf, oh, sizeof(*oh));
1129 oh = (ipfw_obj_header *)xbuf;
1130 tent = (ipfw_obj_tentry *)(oh + 1);
1132 memset(tent, 0, sizeof(*tent));
1133 tent->head.length = sizeof(*tent);
1136 tentry_fill_key(oh, tent, key, 0, &type, &vmask, xi);
1137 oh->ntlv.type = type;
1140 if (do_get3(IP_FW_TABLE_XFIND, &oh->opheader, &sz) != 0)
1143 if (sz < sizeof(xbuf))
1152 table_lookup(ipfw_obj_header *oh, int ac, char *av[])
1154 ipfw_obj_tentry xtent;
1155 ipfw_xtable_info xi;
1160 errx(EX_USAGE, "address required");
1162 strlcpy(key, *av, sizeof(key));
1164 memset(&xi, 0, sizeof(xi));
1165 error = table_do_lookup(oh, key, &xi, &xtent);
1171 errx(EX_UNAVAILABLE, "Table %s not found", oh->ntlv.name);
1173 errx(EX_UNAVAILABLE, "Entry %s not found", *av);
1175 errx(EX_UNAVAILABLE, "Table %s algo does not support "
1176 "\"lookup\" method", oh->ntlv.name);
1178 err(EX_OSERR, "getsockopt(IP_FW_TABLE_XFIND)");
1181 table_show_entry(&xi, &xtent);
1185 tentry_fill_key_type(char *arg, ipfw_obj_tentry *tentry, uint8_t type,
1190 struct in6_addr *paddr, tmp;
1191 struct tflow_entry *tfe;
1192 uint32_t key, *pkey;
1194 struct protoent *pent;
1195 struct servent *sent;
1200 paddr = (struct in6_addr *)&tentry->k;
1203 case IPFW_TABLE_ADDR:
1204 /* Remove / if exists */
1205 if ((p = strchr(arg, '/')) != NULL) {
1210 if (inet_pton(AF_INET, arg, paddr) == 1) {
1211 if (p != NULL && mask > 32)
1212 errx(EX_DATAERR, "bad IPv4 mask width: %s",
1215 masklen = p ? mask : 32;
1217 } else if (inet_pton(AF_INET6, arg, paddr) == 1) {
1218 if (IN6_IS_ADDR_V4COMPAT(paddr))
1220 "Use IPv4 instead of v4-compatible");
1221 if (p != NULL && mask > 128)
1222 errx(EX_DATAERR, "bad IPv6 mask width: %s",
1225 masklen = p ? mask : 128;
1229 if (lookup_host(arg, (struct in_addr *)paddr) != 0)
1230 errx(EX_NOHOST, "hostname ``%s'' unknown", arg);
1233 type = IPFW_TABLE_ADDR;
1237 case IPFW_TABLE_INTERFACE:
1238 /* Assume interface name. Copy significant data only */
1239 mask = MIN(strlen(arg), IF_NAMESIZE - 1);
1240 memcpy(paddr, arg, mask);
1241 /* Set mask to exact match */
1242 masklen = 8 * IF_NAMESIZE;
1244 case IPFW_TABLE_NUMBER:
1245 /* Port or any other key */
1246 key = strtol(arg, &p, 10);
1248 errx(EX_DATAERR, "Invalid number: %s", arg);
1250 pkey = (uint32_t *)paddr;
1254 case IPFW_TABLE_FLOW:
1255 /* Assume [src-ip][,proto][,src-port][,dst-ip][,dst-port] */
1256 tfe = &tentry->k.flow;
1259 /* Handle <ipv4|ipv6> */
1260 if ((tflags & IPFW_TFFLAG_SRCIP) != 0) {
1261 if ((p = strchr(arg, ',')) != NULL)
1263 /* Determine family using temporary storage */
1264 if (inet_pton(AF_INET, arg, &tmp) == 1) {
1265 if (af != 0 && af != AF_INET)
1267 "Inconsistent address family\n");
1269 memcpy(&tfe->a.a4.sip, &tmp, 4);
1270 } else if (inet_pton(AF_INET6, arg, &tmp) == 1) {
1271 if (af != 0 && af != AF_INET6)
1273 "Inconsistent address family\n");
1275 memcpy(&tfe->a.a6.sip6, &tmp, 16);
1281 /* Handle <proto-num|proto-name> */
1282 if ((tflags & IPFW_TFFLAG_PROTO) != 0) {
1284 errx(EX_DATAERR, "invalid key: proto missing");
1285 if ((p = strchr(arg, ',')) != NULL)
1288 key = strtol(arg, &pp, 10);
1290 if ((pent = getprotobyname(arg)) == NULL)
1291 errx(EX_DATAERR, "Unknown proto: %s",
1294 key = pent->p_proto;
1298 errx(EX_DATAERR, "Bad protocol number: %u",key);
1305 /* Handle <port-num|service-name> */
1306 if ((tflags & IPFW_TFFLAG_SRCPORT) != 0) {
1308 errx(EX_DATAERR, "invalid key: src port missing");
1309 if ((p = strchr(arg, ',')) != NULL)
1312 port = htons(strtol(arg, &pp, 10));
1314 if ((sent = getservbyname(arg, NULL)) == NULL)
1315 errx(EX_DATAERR, "Unknown service: %s",
1317 port = sent->s_port;
1323 /* Handle <ipv4|ipv6>*/
1324 if ((tflags & IPFW_TFFLAG_DSTIP) != 0) {
1326 errx(EX_DATAERR, "invalid key: dst ip missing");
1327 if ((p = strchr(arg, ',')) != NULL)
1329 /* Determine family using temporary storage */
1330 if (inet_pton(AF_INET, arg, &tmp) == 1) {
1331 if (af != 0 && af != AF_INET)
1333 "Inconsistent address family");
1335 memcpy(&tfe->a.a4.dip, &tmp, 4);
1336 } else if (inet_pton(AF_INET6, arg, &tmp) == 1) {
1337 if (af != 0 && af != AF_INET6)
1339 "Inconsistent address family");
1341 memcpy(&tfe->a.a6.dip6, &tmp, 16);
1347 /* Handle <port-num|service-name> */
1348 if ((tflags & IPFW_TFFLAG_DSTPORT) != 0) {
1350 errx(EX_DATAERR, "invalid key: dst port missing");
1351 if ((p = strchr(arg, ',')) != NULL)
1354 port = htons(strtol(arg, &pp, 10));
1356 if ((sent = getservbyname(arg, NULL)) == NULL)
1357 errx(EX_DATAERR, "Unknown service: %s",
1359 port = sent->s_port;
1370 errx(EX_DATAERR, "Unsupported table type: %d", type);
1373 tentry->subtype = af;
1374 tentry->masklen = masklen;
1378 * Tries to guess table key type.
1379 * This procedure is used in legacy table auto-create
1380 * code AND in `ipfw -n` ruleset checking.
1382 * Imported from old table_fill_xentry() parse code.
1385 guess_key_type(char *key, uint8_t *ptype)
1388 struct in6_addr addr;
1391 if (ishexnumber(*key) != 0 || *key == ':') {
1392 /* Remove / if exists */
1393 if ((p = strchr(key, '/')) != NULL)
1396 if ((inet_pton(AF_INET, key, &addr) == 1) ||
1397 (inet_pton(AF_INET6, key, &addr) == 1)) {
1398 *ptype = IPFW_TABLE_CIDR;
1403 /* Port or any other key */
1404 /* Skip non-base 10 entries like 'fa1' */
1405 kv = strtol(key, &p, 10);
1407 *ptype = IPFW_TABLE_NUMBER;
1409 } else if ((p != key) && (*p == '.')) {
1411 * Warn on IPv4 address strings
1412 * which are "valid" for inet_aton() but not
1415 * Typical examples: '10.5' or '10.0.0.05'
1422 if (strchr(key, '.') == NULL) {
1423 *ptype = IPFW_TABLE_INTERFACE;
1427 if (lookup_host(key, (struct in_addr *)&addr) != 0)
1430 *ptype = IPFW_TABLE_CIDR;
1435 tentry_fill_key(ipfw_obj_header *oh, ipfw_obj_tentry *tent, char *key,
1436 int add, uint8_t *ptype, uint32_t *pvmask, ipfw_xtable_info *xi)
1438 uint8_t type, tflags;
1446 if (xi->tablename[0] == '\0')
1447 error = table_get_info(oh, xi);
1452 if (g_co.test_only == 0) {
1455 tflags = xi->tflags;
1459 * We're running `ipfw -n`
1460 * Compatibility layer: try to guess key type
1463 if (guess_key_type(key, &type) != 0) {
1465 errx(EX_USAGE, "Cannot guess "
1466 "key '%s' type", key);
1468 vmask = IPFW_VTYPE_LEGACY;
1472 errx(EX_OSERR, "Error requesting table %s info",
1475 errx(EX_DATAERR, "Table %s does not exist",
1478 * Table does not exist
1479 * Compatibility layer: try to guess key type before failing.
1481 if (guess_key_type(key, &type) != 0) {
1483 errx(EX_USAGE, "Table %s does not exist, cannot guess "
1484 "key '%s' type", oh->ntlv.name, key);
1487 vmask = IPFW_VTYPE_LEGACY;
1490 tentry_fill_key_type(key, tent, type, tflags);
1497 set_legacy_value(uint32_t val, ipfw_table_value *v)
1507 v->dscp = (uint8_t)val;
1512 tentry_fill_value(ipfw_obj_header *oh __unused, ipfw_obj_tentry *tent,
1513 char *arg, uint8_t type __unused, uint32_t vmask)
1515 struct addrinfo hints, *res;
1516 struct in_addr ipaddr;
1518 char *comma, *e, *n, *p;
1519 uint32_t a4, flag, val;
1520 ipfw_table_value *v;
1526 /* Compat layer: keep old behavior for legacy value types */
1527 if (vmask == IPFW_VTYPE_LEGACY) {
1528 /* Try to interpret as number first */
1529 val = strtoul(arg, &p, 0);
1531 set_legacy_value(val, v);
1534 if (inet_pton(AF_INET, arg, &val) == 1) {
1535 set_legacy_value(ntohl(val), v);
1539 if (lookup_host(arg, &ipaddr) == 0) {
1540 set_legacy_value(ntohl(ipaddr.s_addr), v);
1543 errx(EX_OSERR, "Unable to parse value %s", arg);
1547 * Shorthands: handle single value if vmask consists
1548 * of numbers only. e.g.:
1549 * vmask = "fib,skipto" -> treat input "1" as "1,1"
1554 for (i = 1; i < (1u << 31); i *= 2) {
1555 if ((flag = (vmask & i)) == 0)
1559 if ((comma = strchr(n, ',')) != NULL)
1563 case IPFW_VTYPE_TAG:
1564 v->tag = strtol(n, &e, 10);
1568 case IPFW_VTYPE_PIPE:
1569 v->pipe = strtol(n, &e, 10);
1573 case IPFW_VTYPE_DIVERT:
1574 v->divert = strtol(n, &e, 10);
1578 case IPFW_VTYPE_SKIPTO:
1579 v->skipto = strtol(n, &e, 10);
1583 case IPFW_VTYPE_NETGRAPH:
1584 v->netgraph = strtol(n, &e, 10);
1588 case IPFW_VTYPE_FIB:
1589 v->fib = strtol(n, &e, 10);
1593 case IPFW_VTYPE_NAT:
1594 v->nat = strtol(n, &e, 10);
1598 case IPFW_VTYPE_LIMIT:
1599 v->limit = strtol(n, &e, 10);
1603 case IPFW_VTYPE_NH4:
1604 if (strchr(n, '.') != NULL &&
1605 inet_pton(AF_INET, n, &a4) == 1) {
1609 if (lookup_host(n, &ipaddr) == 0) {
1610 v->nh4 = ntohl(ipaddr.s_addr);
1615 case IPFW_VTYPE_DSCP:
1617 if ((dval = match_token(f_ipdscp, n)) != -1) {
1621 etype = "DSCP code";
1623 v->dscp = strtol(n, &e, 10);
1624 if (v->dscp > 63 || *e != '\0')
1625 etype = "DSCP value";
1628 case IPFW_VTYPE_NH6:
1629 if (strchr(n, ':') != NULL) {
1630 memset(&hints, 0, sizeof(hints));
1631 hints.ai_family = AF_INET6;
1632 hints.ai_flags = AI_NUMERICHOST;
1633 if (getaddrinfo(n, NULL, &hints, &res) == 0) {
1634 v->nh6 = ((struct sockaddr_in6 *)
1635 res->ai_addr)->sin6_addr;
1636 v->zoneid = ((struct sockaddr_in6 *)
1637 res->ai_addr)->sin6_scope_id;
1647 errx(EX_USAGE, "Unable to parse %s as %s", n, etype);
1652 if ((n = comma) != NULL)
1657 errx(EX_USAGE, "Not enough fields inside value");
1662 * Compare table names.
1663 * Honor number comparison.
1666 tablename_cmp(const void *a, const void *b)
1668 const ipfw_xtable_info *ia, *ib;
1670 ia = (const ipfw_xtable_info *)a;
1671 ib = (const ipfw_xtable_info *)b;
1673 return (stringnum_cmp(ia->tablename, ib->tablename));
1677 * Retrieves table list from kernel,
1678 * optionally sorts it and calls requested function for each table.
1679 * Returns 0 on success.
1682 tables_foreach(table_cb_t *f, void *arg, int sort)
1684 ipfw_obj_lheader *olh;
1685 ipfw_xtable_info *info;
1690 /* Start with reasonable default */
1691 sz = sizeof(*olh) + 16 * sizeof(ipfw_xtable_info);
1694 if ((olh = calloc(1, sz)) == NULL)
1698 if (do_get3(IP_FW_TABLES_XLIST, &olh->opheader, &sz) != 0) {
1701 if (errno != ENOMEM)
1707 qsort(olh + 1, olh->count, olh->objsize,
1710 info = (ipfw_xtable_info *)(olh + 1);
1711 for (i = 0; i < olh->count; i++) {
1712 if (g_co.use_set == 0 || info->set == g_co.use_set - 1)
1713 error = f(info, arg);
1714 info = (ipfw_xtable_info *)((caddr_t)info +
1725 * Retrieves all entries for given table @i in
1726 * eXtended format. Allocate buffer large enough
1727 * to store result. Called needs to free it later.
1729 * Returns 0 on success.
1732 table_do_get_list(ipfw_xtable_info *i, ipfw_obj_header **poh)
1734 ipfw_obj_header *oh;
1740 for (c = 0; c < 8; c++) {
1745 if ((oh = calloc(1, sz)) == NULL)
1747 table_fill_objheader(oh, i);
1748 oh->opheader.version = 1; /* Current version */
1749 if (do_get3(IP_FW_TABLE_XLIST, &oh->opheader, &sz) == 0) {
1754 if (errno != ENOMEM)
1763 * Shows all entries from @oh in human-readable format
1766 table_show_list(ipfw_obj_header *oh, int need_header)
1768 ipfw_obj_tentry *tent;
1770 ipfw_xtable_info *i;
1772 i = (ipfw_xtable_info *)(oh + 1);
1773 tent = (ipfw_obj_tentry *)(i + 1);
1776 printf("--- table(%s), set(%u) ---\n", i->tablename, i->set);
1780 table_show_entry(i, tent);
1781 tent = (ipfw_obj_tentry *)((caddr_t)tent + tent->head.length);
1787 table_show_value(char *buf, size_t bufsize, ipfw_table_value *v,
1788 uint32_t vmask, int print_ip)
1790 char abuf[INET6_ADDRSTRLEN + IF_NAMESIZE + 2];
1791 struct sockaddr_in6 sa6;
1792 uint32_t flag, i, l;
1799 * Some shorthands for printing values:
1800 * legacy assumes all values are equal, so keep the first one.
1802 if (vmask == IPFW_VTYPE_LEGACY) {
1803 if (print_ip != 0) {
1804 flag = htonl(v->tag);
1805 inet_ntop(AF_INET, &flag, buf, sz);
1807 snprintf(buf, sz, "%u", v->tag);
1811 for (i = 1; i < (1u << 31); i *= 2) {
1812 if ((flag = (vmask & i)) == 0)
1817 case IPFW_VTYPE_TAG:
1818 l = snprintf(buf, sz, "%u,", v->tag);
1820 case IPFW_VTYPE_PIPE:
1821 l = snprintf(buf, sz, "%u,", v->pipe);
1823 case IPFW_VTYPE_DIVERT:
1824 l = snprintf(buf, sz, "%d,", v->divert);
1826 case IPFW_VTYPE_SKIPTO:
1827 l = snprintf(buf, sz, "%d,", v->skipto);
1829 case IPFW_VTYPE_NETGRAPH:
1830 l = snprintf(buf, sz, "%u,", v->netgraph);
1832 case IPFW_VTYPE_FIB:
1833 l = snprintf(buf, sz, "%u,", v->fib);
1835 case IPFW_VTYPE_NAT:
1836 l = snprintf(buf, sz, "%u,", v->nat);
1838 case IPFW_VTYPE_LIMIT:
1839 l = snprintf(buf, sz, "%u,", v->limit);
1841 case IPFW_VTYPE_NH4:
1842 a4.s_addr = htonl(v->nh4);
1843 inet_ntop(AF_INET, &a4, abuf, sizeof(abuf));
1844 l = snprintf(buf, sz, "%s,", abuf);
1846 case IPFW_VTYPE_DSCP:
1847 l = snprintf(buf, sz, "%d,", v->dscp);
1849 case IPFW_VTYPE_NH6:
1850 sa6.sin6_family = AF_INET6;
1851 sa6.sin6_len = sizeof(sa6);
1852 sa6.sin6_addr = v->nh6;
1854 sa6.sin6_scope_id = v->zoneid;
1855 if (getnameinfo((const struct sockaddr *)&sa6,
1856 sa6.sin6_len, abuf, sizeof(abuf), NULL, 0,
1857 NI_NUMERICHOST) == 0)
1858 l = snprintf(buf, sz, "%s,", abuf);
1871 table_show_entry(ipfw_xtable_info *i, ipfw_obj_tentry *tent)
1873 char tbuf[128], pval[128];
1876 struct tflow_entry *tfe;
1878 table_show_value(pval, sizeof(pval), &tent->v.value, i->vmask,
1879 g_co.do_value_as_ip);
1882 case IPFW_TABLE_ADDR:
1883 /* IPv4 or IPv6 prefixes */
1884 inet_ntop(tent->subtype, &tent->k, tbuf, sizeof(tbuf));
1885 printf("%s/%u %s\n", tbuf, tent->masklen, pval);
1887 case IPFW_TABLE_INTERFACE:
1888 /* Interface names */
1889 printf("%s %s\n", tent->k.iface, pval);
1891 case IPFW_TABLE_NUMBER:
1893 printf("%u %s\n", tent->k.key, pval);
1895 case IPFW_TABLE_FLOW:
1897 tfe = &tent->k.flow;
1900 if ((i->tflags & IPFW_TFFLAG_SRCIP) != 0) {
1901 if (tfe->af == AF_INET)
1902 paddr = &tfe->a.a4.sip;
1904 paddr = &tfe->a.a6.sip6;
1906 inet_ntop(tfe->af, paddr, tbuf, sizeof(tbuf));
1907 printf("%s%s", comma, tbuf);
1911 if ((i->tflags & IPFW_TFFLAG_PROTO) != 0) {
1912 printf("%s%d", comma, tfe->proto);
1916 if ((i->tflags & IPFW_TFFLAG_SRCPORT) != 0) {
1917 printf("%s%d", comma, ntohs(tfe->sport));
1920 if ((i->tflags & IPFW_TFFLAG_DSTIP) != 0) {
1921 if (tfe->af == AF_INET)
1922 paddr = &tfe->a.a4.dip;
1924 paddr = &tfe->a.a6.dip6;
1926 inet_ntop(tfe->af, paddr, tbuf, sizeof(tbuf));
1927 printf("%s%s", comma, tbuf);
1931 if ((i->tflags & IPFW_TFFLAG_DSTPORT) != 0) {
1932 printf("%s%d", comma, ntohs(tfe->dport));
1936 printf(" %s\n", pval);
1941 table_do_get_stdlist(uint16_t opcode, ipfw_obj_lheader **polh)
1943 ipfw_obj_lheader req, *olh;
1946 memset(&req, 0, sizeof(req));
1949 if (do_get3(opcode, &req.opheader, &sz) != 0)
1950 if (errno != ENOMEM)
1954 if ((olh = calloc(1, sz)) == NULL)
1958 if (do_get3(opcode, &olh->opheader, &sz) != 0) {
1968 table_do_get_algolist(ipfw_obj_lheader **polh)
1971 return (table_do_get_stdlist(IP_FW_TABLES_ALIST, polh));
1975 table_do_get_vlist(ipfw_obj_lheader **polh)
1978 return (table_do_get_stdlist(IP_FW_TABLE_VLIST, polh));
1982 ipfw_list_ta(int ac __unused, char *av[] __unused)
1984 ipfw_obj_lheader *olh;
1990 error = table_do_get_algolist(&olh);
1992 err(EX_OSERR, "Unable to request algorithm list");
1994 info = (ipfw_ta_info *)(olh + 1);
1995 for (i = 0; i < olh->count; i++) {
1996 if ((atype = match_value(tabletypes, info->type)) == NULL)
1998 printf("--- %s ---\n", info->algoname);
1999 printf(" type: %s\n refcount: %u\n", atype, info->refcnt);
2001 info = (ipfw_ta_info *)((caddr_t)info + olh->objsize);
2008 /* Copy of current kernel table_value structure */
2009 struct _table_value {
2010 uint32_t tag; /* O_TAG/O_TAGGED */
2011 uint32_t pipe; /* O_PIPE/O_QUEUE */
2012 uint16_t divert; /* O_DIVERT/O_TEE */
2013 uint16_t skipto; /* skipto, CALLRET */
2014 uint32_t netgraph; /* O_NETGRAPH/O_NGTEE */
2015 uint32_t fib; /* O_SETFIB */
2016 uint32_t nat; /* O_NAT */
2021 /* -- 32 bytes -- */
2022 struct in6_addr nh6;
2023 uint32_t limit; /* O_LIMIT */
2025 uint64_t refcnt; /* Number of references */
2029 compare_values(const void *_a, const void *_b)
2031 const struct _table_value *a, *b;
2033 a = (const struct _table_value *)_a;
2034 b = (const struct _table_value *)_b;
2036 if (a->spare1 < b->spare1)
2038 else if (a->spare1 > b->spare1)
2045 ipfw_list_values(int ac __unused, char *av[] __unused)
2048 ipfw_obj_lheader *olh;
2049 struct _table_value *v;
2053 error = table_do_get_vlist(&olh);
2055 err(EX_OSERR, "Unable to request value list");
2057 vmask = 0x7FFFFFFF; /* Similar to IPFW_VTYPE_LEGACY */
2059 table_print_valheader(buf, sizeof(buf), vmask);
2060 printf("HEADER: %s\n", buf);
2061 v = (struct _table_value *)(olh + 1);
2062 qsort(v, olh->count, olh->objsize, compare_values);
2063 for (i = 0; i < olh->count; i++) {
2064 table_show_value(buf, sizeof(buf), (ipfw_table_value *)v,
2066 printf("[%u] refs=%lu %s\n", v->spare1, (u_long)v->refcnt, buf);
2067 v = (struct _table_value *)((caddr_t)v + olh->objsize);
2074 table_check_name(const char *tablename)
2077 if (ipfw_check_object_name(tablename) != 0)
2079 /* Restrict some 'special' names */
2080 if (strcmp(tablename, "all") == 0)