Skip to content
Merged

Perf #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions addr_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func AddrAdd(link Link, addr *Addr) error {
// If `net.IPv4zero` is given as the broadcast address, broadcast is disabled.
func (h *Handle) AddrAdd(link Link, addr *Addr) error {
req := h.newNetlinkRequest(unix.RTM_NEWADDR, unix.NLM_F_CREATE|unix.NLM_F_EXCL|unix.NLM_F_ACK)
return h.addrHandle(link, addr, req)
return h.addrHandle(req, link, addr)
}

// AddrReplace will replace (or, if not present, add) an IP address on a link device.
Expand All @@ -54,7 +54,7 @@ func AddrReplace(link Link, addr *Addr) error {
// If `net.IPv4zero` is given as the broadcast address, broadcast is disabled.
func (h *Handle) AddrReplace(link Link, addr *Addr) error {
req := h.newNetlinkRequest(unix.RTM_NEWADDR, unix.NLM_F_CREATE|unix.NLM_F_REPLACE|unix.NLM_F_ACK)
return h.addrHandle(link, addr, req)
return h.addrHandle(req, link, addr)
}

// AddrDel will delete an IP address from a link device.
Expand All @@ -69,10 +69,10 @@ func AddrDel(link Link, addr *Addr) error {
// Equivalent to: `ip addr del $addr dev $link`
func (h *Handle) AddrDel(link Link, addr *Addr) error {
req := h.newNetlinkRequest(unix.RTM_DELADDR, unix.NLM_F_ACK)
return h.addrHandle(link, addr, req)
return h.addrHandle(req, link, addr)
}

func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error {
func (h *Handle) addrHandle(req nl.NetlinkRequest, link Link, addr *Addr) error {
family := nl.GetIPFamily(addr.IP)
msg := nl.NewIfAddrmsg(family)
msg.Scope = uint8(addr.Scope)
Expand Down Expand Up @@ -364,7 +364,7 @@ func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-c
unix.NLM_F_DUMP)
infmsg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(infmsg)
if err := s.Send(req); err != nil {
if err := s.Send(req.Serialize()); err != nil {
return err
}
}
Expand Down
13 changes: 7 additions & 6 deletions class_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,17 @@ func (h *Handle) classModify(cmd, flags int, class Class) error {
}
req.AddData(msg)

var err error
if cmd != unix.RTM_DELTCLASS {
if err := classPayload(req, class); err != nil {
if req, err = classPayload(req, class); err != nil {
return err
}
}
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
_, err = req.Execute(unix.NETLINK_ROUTE, 0)
return err
}

func classPayload(req *nl.NetlinkRequest, class Class) error {
func classPayload(req nl.NetlinkRequest, class Class) (nl.NetlinkRequest, error) {
req.AddData(nl.NewRtAttr(nl.TCA_KIND, nl.ZeroTerminated(class.Type())))

options := nl.NewRtAttr(nl.TCA_OPTIONS, nil)
Expand All @@ -165,12 +166,12 @@ func classPayload(req *nl.NetlinkRequest, class Class) error {
var ctab [256]uint32
tcrate := nl.TcRateSpec{Rate: uint32(htb.Rate)}
if CalcRtable(&tcrate, rtab[:], cellLog, uint32(mtu), linklayer) < 0 {
return errors.New("HTB: failed to calculate rate table")
return nl.NetlinkRequest{}, errors.New("HTB: failed to calculate rate table")
}
opt.Rate = tcrate
tcceil := nl.TcRateSpec{Rate: uint32(htb.Ceil)}
if CalcRtable(&tcceil, ctab[:], ccellLog, uint32(mtu), linklayer) < 0 {
return errors.New("HTB: failed to calculate ceil rate table")
return nl.NetlinkRequest{}, errors.New("HTB: failed to calculate ceil rate table")
}
opt.Ceil = tcceil
options.AddRtAttr(nl.TCA_HTB_PARMS, opt.Serialize())
Expand All @@ -196,7 +197,7 @@ func classPayload(req *nl.NetlinkRequest, class Class) error {
options.AddRtAttr(nl.TCA_HFSC_USC, nl.SerializeHfscCurve(&opt.Usc))
}
req.AddData(options)
return nil
return req, nil
}

// ClassList gets a list of classes in the system.
Expand Down
Loading
Loading