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 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <sys/sockio.h>
40 #include <net/if.h> /* IFNAMSIZ */
41 #include <net/pfvar.h>
42 #include <netinet/ip_fw.h>
45 * Map between current altq queue id numbers and names.
47 static TAILQ_HEAD(, pf_altq) altq_entries =
48 TAILQ_HEAD_INITIALIZER(altq_entries);
51 altq_set_enabled(int enabled)
55 pffd = open("/dev/pf", O_RDWR);
58 "altq support opening pf(4) control device");
60 if (ioctl(pffd, DIOCSTARTALTQ) != 0 && errno != EEXIST)
61 err(EX_UNAVAILABLE, "enabling altq");
63 if (ioctl(pffd, DIOCSTOPALTQ) != 0 && errno != ENOENT)
64 err(EX_UNAVAILABLE, "disabling altq");
72 struct pfioc_altq pfioc;
76 static int altq_fetched = 0;
81 pffd = open("/dev/pf", O_RDONLY);
83 warn("altq support opening pf(4) control device");
86 bzero(&pfioc, sizeof(pfioc));
87 if (ioctl(pffd, DIOCGETALTQS, &pfioc) != 0) {
88 warn("altq support getting queue list");
93 for (pfioc.nr = 0; pfioc.nr < mnr; pfioc.nr++) {
94 if (ioctl(pffd, DIOCGETALTQ, &pfioc) != 0) {
97 warn("altq support getting queue list");
101 if (pfioc.altq.qid == 0)
103 altq = safe_calloc(1, sizeof(*altq));
105 TAILQ_INSERT_TAIL(&altq_entries, altq, entries);
111 altq_name_to_qid(const char *name)
113 struct pf_altq *altq;
116 TAILQ_FOREACH(altq, &altq_entries, entries)
117 if (strcmp(name, altq->qname) == 0)
120 errx(EX_DATAERR, "altq has no queue named `%s'", name);
125 altq_qid_to_name(u_int32_t qid)
127 struct pf_altq *altq;
130 TAILQ_FOREACH(altq, &altq_entries, entries)
131 if (qid == altq->qid)
139 print_altq_cmd(ipfw_insn_altq *altqptr)
144 qname = altq_qid_to_name(altqptr->qid);
146 printf(" altq ?<%u>", altqptr->qid);
148 printf(" altq %s", qname);