You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt""net""os""github.com/mdlayher/netlink""github.com/florianl/go-tc"
)
funcmain() {
// open a rtnetlink socketrtnl, err:=tc.Open(&tc.Config{})
iferr!=nil {
fmt.Fprintf(os.Stderr, "could not open rtnetlink socket: %v\n", err)
return
}
deferfunc() {
iferr:=rtnl.Close(); err!=nil {
fmt.Fprintf(os.Stderr, "could not close rtnetlink socket: %v\n", err)
}
}()
// For enhanced error messages from the kernel, it is recommended to set// option `NETLINK_EXT_ACK`, which is supported since 4.12 kernel.//// If not supported, `unix.ENOPROTOOPT` is returned.err=rtnl.SetOption(netlink.ExtendedAcknowledge, true)
iferr!=nil {
fmt.Fprintf(os.Stderr, "could not set option ExtendedAcknowledge: %v\n", err)
return
}
// get all the qdiscs from all interfacesqdiscs, err:=rtnl.Qdisc().Get()
iferr!=nil {
fmt.Fprintf(os.Stderr, "could not get qdiscs: %v\n", err)
return
}
for_, qdisc:=rangeqdiscs {
iface, err:=net.InterfaceByIndex(int(qdisc.Ifindex))
iferr!=nil {
fmt.Fprintf(os.Stderr, "could not get interface from id %d: %v", qdisc.Ifindex, err)
return
}
fmt.Printf("%20s\t%s\n", iface.Name, qdisc.Kind)
}
}
This package processes information directly from the kernel and therefore it requires special privileges. You can provide this privileges by adjusting the CAP_NET_ADMIN capabilities.
setcap 'cap_net_admin=+ep' /your/executable
About
traffic control in pure go - it allows to read and alter queues, filters and classes