diff --git a/tc-cgroup.sh b/tc-cgroup.sh new file mode 100755 index 0000000..98f6a05 --- /dev/null +++ b/tc-cgroup.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Make sure only root can run our script +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +if [ ! -d "/sys/fs/cgroup/net_prio" ]; then + echo "Your kernel needs to have the cls_prio cgroup loaded!" 1>&2 + exit 1 +fi + +if [ ! -d "/sys/fs/cgroup/net_prio/netem" ]; then + cgcreate -g net_prio:netem + + for i in $(ls /sys/class/net/); + do + echo "$i 15" > /sys/fs/cgroup/net_prio/netem/net_prio.ifpriomap + done +fi + +cgexec -g net_prio:netem $@ diff --git a/tc.c b/tc.c index 8ddfff8..76f58a9 100644 --- a/tc.c +++ b/tc.c @@ -34,7 +34,7 @@ int tc_prio(struct nl_sock *sock, struct rtnl_link *link, struct rtnl_tc **tc) { /* This is the default priomap +1 for every entry. * The first band (value == 0) with the highest priority is reserved for the netem traffic */ - uint8_t map[] = { 2, 3, 3, 3, 2, 3, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 }; + uint8_t map[] = { 2, 3, 3, 3, 2, 3, 1, 1, 2, 2, 2, 2, 2, 2, 2, 0 }; struct rtnl_qdisc *q = rtnl_qdisc_alloc(); @@ -44,7 +44,7 @@ int tc_prio(struct nl_sock *sock, struct rtnl_link *link, struct rtnl_tc **tc) rtnl_tc_set_kind(TC_CAST(q), "prio"); rtnl_qdisc_prio_set_bands(q, 3+1); - rtnl_qdisc_prio_set_priomap(q, map, sizeof(map) / sizeof(map[0])); + rtnl_qdisc_prio_set_priomap(q, map, 7); int ret = rtnl_qdisc_add(sock, q, NLM_F_CREATE);