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
20 * $FreeBSD: head/sbin/ipfw/altq.c 187983 2009-02-01 16:00:49Z luigi $
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/in.h>
43 #include <netinet/ip_fw.h>
46 * Map between current altq queue id numbers and names.
48 static TAILQ_HEAD(, pf_altq) altq_entries =
49 TAILQ_HEAD_INITIALIZER(altq_entries);
52 altq_set_enabled(int enabled)
56 pffd = open("/dev/pf", O_RDWR);
59 "altq support opening pf(4) control device");
61 if (ioctl(pffd, DIOCSTARTALTQ) != 0 && errno != EEXIST)
62 err(EX_UNAVAILABLE, "enabling altq");
64 if (ioctl(pffd, DIOCSTOPALTQ) != 0 && errno != ENOENT)
65 err(EX_UNAVAILABLE, "disabling altq");
73 struct pfioc_altq pfioc;
77 static int altq_fetched = 0;
82 pffd = open("/dev/pf", O_RDONLY);
84 warn("altq support opening pf(4) control device");
87 bzero(&pfioc, sizeof(pfioc));
88 if (ioctl(pffd, DIOCGETALTQS, &pfioc) != 0) {
89 warn("altq support getting queue list");
94 for (pfioc.nr = 0; pfioc.nr < mnr; pfioc.nr++) {
95 if (ioctl(pffd, DIOCGETALTQ, &pfioc) != 0) {
98 warn("altq support getting queue list");
102 if (pfioc.altq.qid == 0)
104 altq = safe_calloc(1, sizeof(*altq));
106 TAILQ_INSERT_TAIL(&altq_entries, altq, entries);
112 altq_name_to_qid(const char *name)
114 struct pf_altq *altq;
117 TAILQ_FOREACH(altq, &altq_entries, entries)
118 if (strcmp(name, altq->qname) == 0)
121 errx(EX_DATAERR, "altq has no queue named `%s'", name);
126 altq_qid_to_name(u_int32_t qid)
128 struct pf_altq *altq;
131 TAILQ_FOREACH(altq, &altq_entries, entries)
132 if (qid == altq->qid)
140 print_altq_cmd(ipfw_insn_altq *altqptr)
145 qname = altq_qid_to_name(altqptr->qid);
147 printf(" altq ?<%u>", altqptr->qid);
149 printf(" altq %s", qname);