2017-12-19 22:40:16 +00:00
|
|
|
/*-
|
2009-02-01 16:00:49 +00:00
|
|
|
* Copyright (c) 2002-2003 Luigi Rizzo
|
|
|
|
* Copyright (c) 1996 Alex Nash, Paul Traina, Poul-Henning Kamp
|
|
|
|
* Copyright (c) 1994 Ugen J.S.Antsilevich
|
|
|
|
*
|
|
|
|
* Idea and grammar partially left from:
|
|
|
|
* Copyright (c) 1993 Daniel Boulet
|
|
|
|
*
|
|
|
|
* Redistribution and use in source forms, with and without modification,
|
|
|
|
* are permitted provided that this entire comment appears intact.
|
|
|
|
*
|
|
|
|
* Redistribution in binary form may occur without any restrictions.
|
|
|
|
* Obviously, it would be nice if you gave credit where credit is due
|
|
|
|
* but requiring it would be too onerous.
|
|
|
|
*
|
|
|
|
* This software is provided ``AS IS'' without any warranties of any kind.
|
|
|
|
*
|
|
|
|
* NEW command line interface for IP firewall facility
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*
|
|
|
|
* altq interface
|
|
|
|
*/
|
|
|
|
|
2018-08-22 19:38:48 +00:00
|
|
|
#define PFIOC_USE_LATEST
|
|
|
|
|
2009-02-01 16:00:49 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
|
|
|
|
#include "ipfw2.h"
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sysexits.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <net/if.h> /* IFNAMSIZ */
|
|
|
|
#include <net/pfvar.h>
|
Bring in the most recent version of ipfw and dummynet, developed
and tested over the past two months in the ipfw3-head branch. This
also happens to be the same code available in the Linux and Windows
ports of ipfw and dummynet.
The major enhancement is a completely restructured version of
dummynet, with support for different packet scheduling algorithms
(loadable at runtime), faster queue/pipe lookup, and a much cleaner
internal architecture and kernel/userland ABI which simplifies
future extensions.
In addition to the existing schedulers (FIFO and WF2Q+), we include
a Deficit Round Robin (DRR or RR for brevity) scheduler, and a new,
very fast version of WF2Q+ called QFQ.
Some test code is also present (in sys/netinet/ipfw/test) that
lets you build and test schedulers in userland.
Also, we have added a compatibility layer that understands requests
from the RELENG_7 and RELENG_8 versions of the /sbin/ipfw binaries,
and replies correctly (at least, it does its best; sometimes you
just cannot tell who sent the request and how to answer).
The compatibility layer should make it possible to MFC this code in a
relatively short time.
Some minor glitches (e.g. handling of ipfw set enable/disable,
and a workaround for a bug in RELENG_7's /sbin/ipfw) will be
fixed with separate commits.
CREDITS:
This work has been partly supported by the ONELAB2 project, and
mostly developed by Riccardo Panicucci and myself.
The code for the qfq scheduler is mostly from Fabio Checconi,
and Marta Carbone and Francesco Magno have helped with testing,
debugging and some bug fixes.
2010-03-02 17:40:48 +00:00
|
|
|
#include <netinet/in.h> /* in_addr */
|
2009-02-01 16:00:49 +00:00
|
|
|
#include <netinet/ip_fw.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map between current altq queue id numbers and names.
|
|
|
|
*/
|
2011-04-18 21:18:22 +00:00
|
|
|
static TAILQ_HEAD(, pf_altq) altq_entries =
|
2009-02-01 16:00:49 +00:00
|
|
|
TAILQ_HEAD_INITIALIZER(altq_entries);
|
|
|
|
|
|
|
|
void
|
|
|
|
altq_set_enabled(int enabled)
|
|
|
|
{
|
|
|
|
int pffd;
|
|
|
|
|
|
|
|
pffd = open("/dev/pf", O_RDWR);
|
|
|
|
if (pffd == -1)
|
|
|
|
err(EX_UNAVAILABLE,
|
|
|
|
"altq support opening pf(4) control device");
|
|
|
|
if (enabled) {
|
|
|
|
if (ioctl(pffd, DIOCSTARTALTQ) != 0 && errno != EEXIST)
|
|
|
|
err(EX_UNAVAILABLE, "enabling altq");
|
|
|
|
} else {
|
|
|
|
if (ioctl(pffd, DIOCSTOPALTQ) != 0 && errno != ENOENT)
|
|
|
|
err(EX_UNAVAILABLE, "disabling altq");
|
|
|
|
}
|
|
|
|
close(pffd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
altq_fetch(void)
|
|
|
|
{
|
|
|
|
struct pfioc_altq pfioc;
|
|
|
|
struct pf_altq *altq;
|
|
|
|
int pffd;
|
|
|
|
unsigned int mnr;
|
|
|
|
static int altq_fetched = 0;
|
|
|
|
|
|
|
|
if (altq_fetched)
|
|
|
|
return;
|
|
|
|
altq_fetched = 1;
|
|
|
|
pffd = open("/dev/pf", O_RDONLY);
|
|
|
|
if (pffd == -1) {
|
|
|
|
warn("altq support opening pf(4) control device");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bzero(&pfioc, sizeof(pfioc));
|
2018-08-22 19:38:48 +00:00
|
|
|
pfioc.version = PFIOC_ALTQ_VERSION;
|
2009-02-01 16:00:49 +00:00
|
|
|
if (ioctl(pffd, DIOCGETALTQS, &pfioc) != 0) {
|
|
|
|
warn("altq support getting queue list");
|
|
|
|
close(pffd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mnr = pfioc.nr;
|
|
|
|
for (pfioc.nr = 0; pfioc.nr < mnr; pfioc.nr++) {
|
|
|
|
if (ioctl(pffd, DIOCGETALTQ, &pfioc) != 0) {
|
|
|
|
if (errno == EBUSY)
|
|
|
|
break;
|
|
|
|
warn("altq support getting queue list");
|
|
|
|
close(pffd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pfioc.altq.qid == 0)
|
|
|
|
continue;
|
|
|
|
altq = safe_calloc(1, sizeof(*altq));
|
|
|
|
*altq = pfioc.altq;
|
|
|
|
TAILQ_INSERT_TAIL(&altq_entries, altq, entries);
|
|
|
|
}
|
|
|
|
close(pffd);
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int32_t
|
|
|
|
altq_name_to_qid(const char *name)
|
|
|
|
{
|
|
|
|
struct pf_altq *altq;
|
|
|
|
|
|
|
|
altq_fetch();
|
|
|
|
TAILQ_FOREACH(altq, &altq_entries, entries)
|
|
|
|
if (strcmp(name, altq->qname) == 0)
|
|
|
|
break;
|
|
|
|
if (altq == NULL)
|
|
|
|
errx(EX_DATAERR, "altq has no queue named `%s'", name);
|
|
|
|
return altq->qid;
|
|
|
|
}
|
|
|
|
|
2009-03-05 08:01:19 +00:00
|
|
|
static const char *
|
2009-02-01 16:00:49 +00:00
|
|
|
altq_qid_to_name(u_int32_t qid)
|
|
|
|
{
|
|
|
|
struct pf_altq *altq;
|
|
|
|
|
|
|
|
altq_fetch();
|
|
|
|
TAILQ_FOREACH(altq, &altq_entries, entries)
|
|
|
|
if (qid == altq->qid)
|
|
|
|
break;
|
|
|
|
if (altq == NULL)
|
|
|
|
return NULL;
|
|
|
|
return altq->qname;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-23 17:37:18 +00:00
|
|
|
print_altq_cmd(struct buf_pr *bp, ipfw_insn_altq *altqptr)
|
2009-02-01 16:00:49 +00:00
|
|
|
{
|
2011-04-18 21:18:22 +00:00
|
|
|
if (altqptr) {
|
|
|
|
const char *qname;
|
2009-02-01 16:00:49 +00:00
|
|
|
|
2011-04-18 21:18:22 +00:00
|
|
|
qname = altq_qid_to_name(altqptr->qid);
|
|
|
|
if (qname == NULL)
|
2014-08-23 17:37:18 +00:00
|
|
|
bprintf(bp, " altq ?<%u>", altqptr->qid);
|
2011-04-18 21:18:22 +00:00
|
|
|
else
|
2014-08-23 17:37:18 +00:00
|
|
|
bprintf(bp, " altq %s", qname);
|
2011-04-18 21:18:22 +00:00
|
|
|
}
|
2009-02-01 16:00:49 +00:00
|
|
|
}
|