2 * Copyright (c) 2002-2003 Luigi Rizzo
3 * Copyright (c) 1996 Alex Nash, Paul Traina, Poul-Henning Kamp
4 * Copyright (c) 1994 Ugen J.S.Antsilevich
6 * Idea and grammar partially left from:
7 * Copyright (c) 1993 Daniel Boulet
9 * Redistribution and use in source forms, with and without modification,
10 * are permitted provided that this entire comment appears intact.
12 * Redistribution in binary form may occur without any restrictions.
13 * Obviously, it would be nice if you gave credit where credit is due
14 * but requiring it would be too onerous.
16 * This software is provided ``AS IS'' without any warranties of any kind.
18 * NEW command line interface for IP firewall facility
25 #define PFIOC_USE_LATEST
27 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <sys/sockio.h>
42 #include <net/if.h> /* IFNAMSIZ */
43 #include <net/pfvar.h>
44 #include <netinet/in.h> /* in_addr */
45 #include <netinet/ip_fw.h>
48 * Map between current altq queue id numbers and names.
50 static TAILQ_HEAD(, pf_altq) altq_entries =
51 TAILQ_HEAD_INITIALIZER(altq_entries);
54 altq_set_enabled(int enabled)
58 pffd = open("/dev/pf", O_RDWR);
61 "altq support opening pf(4) control device");
63 if (ioctl(pffd, DIOCSTARTALTQ) != 0 && errno != EEXIST)
64 err(EX_UNAVAILABLE, "enabling altq");
66 if (ioctl(pffd, DIOCSTOPALTQ) != 0 && errno != ENOENT)
67 err(EX_UNAVAILABLE, "disabling altq");
75 struct pfioc_altq pfioc;
79 static int altq_fetched = 0;
84 pffd = open("/dev/pf", O_RDONLY);
86 warn("altq support opening pf(4) control device");
89 bzero(&pfioc, sizeof(pfioc));
90 pfioc.version = PFIOC_ALTQ_VERSION;
91 if (ioctl(pffd, DIOCGETALTQS, &pfioc) != 0) {
92 warn("altq support getting queue list");
97 for (pfioc.nr = 0; pfioc.nr < mnr; pfioc.nr++) {
98 if (ioctl(pffd, DIOCGETALTQ, &pfioc) != 0) {
101 warn("altq support getting queue list");
105 if (pfioc.altq.qid == 0)
107 altq = safe_calloc(1, sizeof(*altq));
109 TAILQ_INSERT_TAIL(&altq_entries, altq, entries);
115 altq_name_to_qid(const char *name)
117 struct pf_altq *altq;
120 TAILQ_FOREACH(altq, &altq_entries, entries)
121 if (strcmp(name, altq->qname) == 0)
124 errx(EX_DATAERR, "altq has no queue named `%s'", name);
129 altq_qid_to_name(u_int32_t qid)
131 struct pf_altq *altq;
134 TAILQ_FOREACH(altq, &altq_entries, entries)
135 if (qid == altq->qid)
143 print_altq_cmd(struct buf_pr *bp, const ipfw_insn_altq *altqptr)
148 qname = altq_qid_to_name(altqptr->qid);
150 bprintf(bp, " altq ?<%u>", altqptr->qid);
152 bprintf(bp, " altq %s", qname);