change tc instead of replacing it

This commit is contained in:
2022-07-05 12:11:35 +02:00
parent 1599f3b537
commit ffeb13abd5
2 changed files with 1 additions and 16 deletions

View File

@@ -8,6 +8,5 @@ ppp: 5
conformation_ppp: 30 conformation_ppp: 30
log_level: DEBUG log_level: DEBUG
upload_interface: "enp1s0f1" upload_interface: "enp1s0f1"
cake_options: "docsis diffserv4 ack-filter nat"
throttle_ping_threshold: 50 throttle_ping_threshold: 50
try_restoring_after: 30 try_restoring_after: 30

16
main.go
View File

@@ -12,7 +12,6 @@ import (
"os/signal" "os/signal"
"regexp" "regexp"
"strconv" "strconv"
"strings"
"syscall" "syscall"
"time" "time"
) )
@@ -29,7 +28,6 @@ type Conf struct {
ConformationPPP int `yaml:"conformation_ppp"` ConformationPPP int `yaml:"conformation_ppp"`
LogLevel string `yaml:"log_level"` LogLevel string `yaml:"log_level"`
UploadInterface string `yaml:"upload_interface"` UploadInterface string `yaml:"upload_interface"`
CakeOptions string `yaml:"cake_options"`
ThrottlePingThreshold int64 `yaml:"throttle_ping_threshold"` ThrottlePingThreshold int64 `yaml:"throttle_ping_threshold"`
TryRestoringAfter int `yaml:"try_restoring_after"` TryRestoringAfter int `yaml:"try_restoring_after"`
} }
@@ -62,10 +60,7 @@ func (m UploadManager) Upload() (int, error) {
} }
func (m UploadManager) SetUpload(upload int) (int, error) { func (m UploadManager) SetUpload(upload int) (int, error) {
m.clearTC() tcCmd := exec.Command("tc", "qdisc", "change", "dev", conf.UploadInterface, "root", "cake", "bandwidth", fmt.Sprintf("%dMbit", upload))
args := []string{"qdisc", "add", "dev", conf.UploadInterface, "root", "cake", "bandwidth", fmt.Sprintf("%dMbit", upload)}
args = append(args, strings.Split(conf.CakeOptions, " ")...)
tcCmd := exec.Command("tc", args...)
log.Debugf("[TC] exec %s", tcCmd.String()) log.Debugf("[TC] exec %s", tcCmd.String())
out, err := tcCmd.CombinedOutput() out, err := tcCmd.CombinedOutput()
if err != nil { if err != nil {
@@ -75,15 +70,6 @@ func (m UploadManager) SetUpload(upload int) (int, error) {
return upload, nil return upload, nil
} }
func (m UploadManager) clearTC() {
tcCmd := exec.Command("tc", "qdisc", "del", "dev", conf.UploadInterface, "root")
log.Debugf("[TC] exec %s", tcCmd.String())
out, err := tcCmd.CombinedOutput()
if err != nil {
log.Debugf("[TC] executing %s failed with: %v (%s)", tcCmd.String(), err, out)
}
}
func doPing(host string, count int, interval time.Duration) (*ping.Statistics, error) { func doPing(host string, count int, interval time.Duration) (*ping.Statistics, error) {
log.Debugf("[PING] starting to ping %s with %d packages", host, count) log.Debugf("[PING] starting to ping %s with %d packages", host, count)
pinger, err := ping.NewPinger(host) pinger, err := ping.NewPinger(host)