Replace nl.NewRtAttrChild with method on struct

This commit is contained in:
Julian Kornberger
2018-09-30 22:46:00 +02:00
committed by Alessandro Boch
parent 3b1c596ccb
commit e137ed6e2c
6 changed files with 231 additions and 224 deletions

View File

@@ -96,7 +96,7 @@ func (h *Handle) bridgeVlanModify(cmd int, link Link, vid uint16, pvid, untagged
flags |= nl.BRIDGE_FLAGS_MASTER flags |= nl.BRIDGE_FLAGS_MASTER
} }
if flags > 0 { if flags > 0 {
nl.NewRtAttrChild(br, nl.IFLA_BRIDGE_FLAGS, nl.Uint16Attr(flags)) br.AddRtAttr(nl.IFLA_BRIDGE_FLAGS, nl.Uint16Attr(flags))
} }
vlanInfo := &nl.BridgeVlanInfo{Vid: vid} vlanInfo := &nl.BridgeVlanInfo{Vid: vid}
if pvid { if pvid {
@@ -105,7 +105,7 @@ func (h *Handle) bridgeVlanModify(cmd int, link Link, vid uint16, pvid, untagged
if untagged { if untagged {
vlanInfo.Flags |= nl.BRIDGE_VLAN_INFO_UNTAGGED vlanInfo.Flags |= nl.BRIDGE_VLAN_INFO_UNTAGGED
} }
nl.NewRtAttrChild(br, nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize()) br.AddRtAttr(nl.IFLA_BRIDGE_VLAN_INFO, vlanInfo.Serialize())
req.AddData(br) req.AddData(br)
_, err := req.Execute(unix.NETLINK_ROUTE, 0) _, err := req.Execute(unix.NETLINK_ROUTE, 0)
if err != nil { if err != nil {

View File

@@ -173,18 +173,18 @@ func classPayload(req *nl.NetlinkRequest, class Class) error {
return errors.New("HTB: failed to calculate ceil rate table") return errors.New("HTB: failed to calculate ceil rate table")
} }
opt.Ceil = tcceil opt.Ceil = tcceil
nl.NewRtAttrChild(options, nl.TCA_HTB_PARMS, opt.Serialize()) options.AddRtAttr(nl.TCA_HTB_PARMS, opt.Serialize())
nl.NewRtAttrChild(options, nl.TCA_HTB_RTAB, SerializeRtab(rtab)) options.AddRtAttr(nl.TCA_HTB_RTAB, SerializeRtab(rtab))
nl.NewRtAttrChild(options, nl.TCA_HTB_CTAB, SerializeRtab(ctab)) options.AddRtAttr(nl.TCA_HTB_CTAB, SerializeRtab(ctab))
case "hfsc": case "hfsc":
hfsc := class.(*HfscClass) hfsc := class.(*HfscClass)
opt := nl.HfscCopt{} opt := nl.HfscCopt{}
opt.Rsc.Set(hfsc.Rsc.Attrs()) opt.Rsc.Set(hfsc.Rsc.Attrs())
opt.Fsc.Set(hfsc.Fsc.Attrs()) opt.Fsc.Set(hfsc.Fsc.Attrs())
opt.Usc.Set(hfsc.Usc.Attrs()) opt.Usc.Set(hfsc.Usc.Attrs())
nl.NewRtAttrChild(options, nl.TCA_HFSC_RSC, nl.SerializeHfscCurve(&opt.Rsc)) options.AddRtAttr(nl.TCA_HFSC_RSC, nl.SerializeHfscCurve(&opt.Rsc))
nl.NewRtAttrChild(options, nl.TCA_HFSC_FSC, nl.SerializeHfscCurve(&opt.Fsc)) options.AddRtAttr(nl.TCA_HFSC_FSC, nl.SerializeHfscCurve(&opt.Fsc))
nl.NewRtAttrChild(options, nl.TCA_HFSC_USC, nl.SerializeHfscCurve(&opt.Usc)) options.AddRtAttr(nl.TCA_HFSC_USC, nl.SerializeHfscCurve(&opt.Usc))
} }
req.AddData(options) req.AddData(options)
return nil return nil

View File

@@ -168,20 +168,20 @@ func (h *Handle) FilterAdd(filter Filter) error {
} }
} }
sel.Nkeys = uint8(len(sel.Keys)) sel.Nkeys = uint8(len(sel.Keys))
nl.NewRtAttrChild(options, nl.TCA_U32_SEL, sel.Serialize()) options.AddRtAttr(nl.TCA_U32_SEL, sel.Serialize())
if filter.ClassId != 0 { if filter.ClassId != 0 {
nl.NewRtAttrChild(options, nl.TCA_U32_CLASSID, nl.Uint32Attr(filter.ClassId)) options.AddRtAttr(nl.TCA_U32_CLASSID, nl.Uint32Attr(filter.ClassId))
} }
if filter.Divisor != 0 { if filter.Divisor != 0 {
if (filter.Divisor-1)&filter.Divisor != 0 { if (filter.Divisor-1)&filter.Divisor != 0 {
return fmt.Errorf("illegal divisor %d. Must be a power of 2.", filter.Divisor) return fmt.Errorf("illegal divisor %d. Must be a power of 2.", filter.Divisor)
} }
nl.NewRtAttrChild(options, nl.TCA_U32_DIVISOR, nl.Uint32Attr(filter.Divisor)) options.AddRtAttr(nl.TCA_U32_DIVISOR, nl.Uint32Attr(filter.Divisor))
} }
if filter.Hash != 0 { if filter.Hash != 0 {
nl.NewRtAttrChild(options, nl.TCA_U32_HASH, nl.Uint32Attr(filter.Hash)) options.AddRtAttr(nl.TCA_U32_HASH, nl.Uint32Attr(filter.Hash))
} }
actionsAttr := nl.NewRtAttrChild(options, nl.TCA_U32_ACT, nil) actionsAttr := options.AddRtAttr(nl.TCA_U32_ACT, nil)
// backwards compatibility // backwards compatibility
if filter.RedirIndex != 0 { if filter.RedirIndex != 0 {
filter.Actions = append([]Action{NewMirredAction(filter.RedirIndex)}, filter.Actions...) filter.Actions = append([]Action{NewMirredAction(filter.RedirIndex)}, filter.Actions...)
@@ -193,51 +193,51 @@ func (h *Handle) FilterAdd(filter Filter) error {
if filter.Mask != 0 { if filter.Mask != 0 {
b := make([]byte, 4) b := make([]byte, 4)
native.PutUint32(b, filter.Mask) native.PutUint32(b, filter.Mask)
nl.NewRtAttrChild(options, nl.TCA_FW_MASK, b) options.AddRtAttr(nl.TCA_FW_MASK, b)
} }
if filter.InDev != "" { if filter.InDev != "" {
nl.NewRtAttrChild(options, nl.TCA_FW_INDEV, nl.ZeroTerminated(filter.InDev)) options.AddRtAttr(nl.TCA_FW_INDEV, nl.ZeroTerminated(filter.InDev))
} }
if (filter.Police != nl.TcPolice{}) { if (filter.Police != nl.TcPolice{}) {
police := nl.NewRtAttrChild(options, nl.TCA_FW_POLICE, nil) police := options.AddRtAttr(nl.TCA_FW_POLICE, nil)
nl.NewRtAttrChild(police, nl.TCA_POLICE_TBF, filter.Police.Serialize()) police.AddRtAttr(nl.TCA_POLICE_TBF, filter.Police.Serialize())
if (filter.Police.Rate != nl.TcRateSpec{}) { if (filter.Police.Rate != nl.TcRateSpec{}) {
payload := SerializeRtab(filter.Rtab) payload := SerializeRtab(filter.Rtab)
nl.NewRtAttrChild(police, nl.TCA_POLICE_RATE, payload) police.AddRtAttr(nl.TCA_POLICE_RATE, payload)
} }
if (filter.Police.PeakRate != nl.TcRateSpec{}) { if (filter.Police.PeakRate != nl.TcRateSpec{}) {
payload := SerializeRtab(filter.Ptab) payload := SerializeRtab(filter.Ptab)
nl.NewRtAttrChild(police, nl.TCA_POLICE_PEAKRATE, payload) police.AddRtAttr(nl.TCA_POLICE_PEAKRATE, payload)
} }
} }
if filter.ClassId != 0 { if filter.ClassId != 0 {
b := make([]byte, 4) b := make([]byte, 4)
native.PutUint32(b, filter.ClassId) native.PutUint32(b, filter.ClassId)
nl.NewRtAttrChild(options, nl.TCA_FW_CLASSID, b) options.AddRtAttr(nl.TCA_FW_CLASSID, b)
} }
case *BpfFilter: case *BpfFilter:
var bpfFlags uint32 var bpfFlags uint32
if filter.ClassId != 0 { if filter.ClassId != 0 {
nl.NewRtAttrChild(options, nl.TCA_BPF_CLASSID, nl.Uint32Attr(filter.ClassId)) options.AddRtAttr(nl.TCA_BPF_CLASSID, nl.Uint32Attr(filter.ClassId))
} }
if filter.Fd >= 0 { if filter.Fd >= 0 {
nl.NewRtAttrChild(options, nl.TCA_BPF_FD, nl.Uint32Attr((uint32(filter.Fd)))) options.AddRtAttr(nl.TCA_BPF_FD, nl.Uint32Attr((uint32(filter.Fd))))
} }
if filter.Name != "" { if filter.Name != "" {
nl.NewRtAttrChild(options, nl.TCA_BPF_NAME, nl.ZeroTerminated(filter.Name)) options.AddRtAttr(nl.TCA_BPF_NAME, nl.ZeroTerminated(filter.Name))
} }
if filter.DirectAction { if filter.DirectAction {
bpfFlags |= nl.TCA_BPF_FLAG_ACT_DIRECT bpfFlags |= nl.TCA_BPF_FLAG_ACT_DIRECT
} }
nl.NewRtAttrChild(options, nl.TCA_BPF_FLAGS, nl.Uint32Attr(bpfFlags)) options.AddRtAttr(nl.TCA_BPF_FLAGS, nl.Uint32Attr(bpfFlags))
case *MatchAll: case *MatchAll:
actionsAttr := nl.NewRtAttrChild(options, nl.TCA_MATCHALL_ACT, nil) actionsAttr := options.AddRtAttr(nl.TCA_MATCHALL_ACT, nil)
if err := EncodeActions(actionsAttr, filter.Actions); err != nil { if err := EncodeActions(actionsAttr, filter.Actions); err != nil {
return err return err
} }
if filter.ClassId != 0 { if filter.ClassId != 0 {
nl.NewRtAttrChild(options, nl.TCA_MATCHALL_CLASSID, nl.Uint32Attr(filter.ClassId)) options.AddRtAttr(nl.TCA_MATCHALL_CLASSID, nl.Uint32Attr(filter.ClassId))
} }
} }
@@ -375,34 +375,34 @@ func EncodeActions(attr *nl.RtAttr, actions []Action) error {
default: default:
return fmt.Errorf("unknown action type %s", action.Type()) return fmt.Errorf("unknown action type %s", action.Type())
case *MirredAction: case *MirredAction:
table := nl.NewRtAttrChild(attr, tabIndex, nil) table := attr.AddRtAttr(tabIndex, nil)
tabIndex++ tabIndex++
nl.NewRtAttrChild(table, nl.TCA_ACT_KIND, nl.ZeroTerminated("mirred")) table.AddRtAttr(nl.TCA_ACT_KIND, nl.ZeroTerminated("mirred"))
aopts := nl.NewRtAttrChild(table, nl.TCA_ACT_OPTIONS, nil) aopts := table.AddRtAttr(nl.TCA_ACT_OPTIONS, nil)
mirred := nl.TcMirred{ mirred := nl.TcMirred{
Eaction: int32(action.MirredAction), Eaction: int32(action.MirredAction),
Ifindex: uint32(action.Ifindex), Ifindex: uint32(action.Ifindex),
} }
toTcGen(action.Attrs(), &mirred.TcGen) toTcGen(action.Attrs(), &mirred.TcGen)
nl.NewRtAttrChild(aopts, nl.TCA_MIRRED_PARMS, mirred.Serialize()) aopts.AddRtAttr(nl.TCA_MIRRED_PARMS, mirred.Serialize())
case *BpfAction: case *BpfAction:
table := nl.NewRtAttrChild(attr, tabIndex, nil) table := attr.AddRtAttr(tabIndex, nil)
tabIndex++ tabIndex++
nl.NewRtAttrChild(table, nl.TCA_ACT_KIND, nl.ZeroTerminated("bpf")) table.AddRtAttr(nl.TCA_ACT_KIND, nl.ZeroTerminated("bpf"))
aopts := nl.NewRtAttrChild(table, nl.TCA_ACT_OPTIONS, nil) aopts := table.AddRtAttr(nl.TCA_ACT_OPTIONS, nil)
gen := nl.TcGen{} gen := nl.TcGen{}
toTcGen(action.Attrs(), &gen) toTcGen(action.Attrs(), &gen)
nl.NewRtAttrChild(aopts, nl.TCA_ACT_BPF_PARMS, gen.Serialize()) aopts.AddRtAttr(nl.TCA_ACT_BPF_PARMS, gen.Serialize())
nl.NewRtAttrChild(aopts, nl.TCA_ACT_BPF_FD, nl.Uint32Attr(uint32(action.Fd))) aopts.AddRtAttr(nl.TCA_ACT_BPF_FD, nl.Uint32Attr(uint32(action.Fd)))
nl.NewRtAttrChild(aopts, nl.TCA_ACT_BPF_NAME, nl.ZeroTerminated(action.Name)) aopts.AddRtAttr(nl.TCA_ACT_BPF_NAME, nl.ZeroTerminated(action.Name))
case *GenericAction: case *GenericAction:
table := nl.NewRtAttrChild(attr, tabIndex, nil) table := attr.AddRtAttr(tabIndex, nil)
tabIndex++ tabIndex++
nl.NewRtAttrChild(table, nl.TCA_ACT_KIND, nl.ZeroTerminated("gact")) table.AddRtAttr(nl.TCA_ACT_KIND, nl.ZeroTerminated("gact"))
aopts := nl.NewRtAttrChild(table, nl.TCA_ACT_OPTIONS, nil) aopts := table.AddRtAttr(nl.TCA_ACT_OPTIONS, nil)
gen := nl.TcGen{} gen := nl.TcGen{}
toTcGen(action.Attrs(), &gen) toTcGen(action.Attrs(), &gen)
nl.NewRtAttrChild(aopts, nl.TCA_GACT_PARMS, gen.Serialize()) aopts.AddRtAttr(nl.TCA_GACT_PARMS, gen.Serialize())
} }
} }
return nil return nil

View File

@@ -202,24 +202,24 @@ func (h *Handle) macvlanMACAddrChange(link Link, addrs []net.HardwareAddr, mode
req.AddData(msg) req.AddData(msg)
linkInfo := nl.NewRtAttr(unix.IFLA_LINKINFO, nil) linkInfo := nl.NewRtAttr(unix.IFLA_LINKINFO, nil)
nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_KIND, nl.NonZeroTerminated(link.Type())) linkInfo.AddRtAttr(nl.IFLA_INFO_KIND, nl.NonZeroTerminated(link.Type()))
inner := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) inner := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
// IFLA_MACVLAN_MACADDR_MODE = mode // IFLA_MACVLAN_MACADDR_MODE = mode
b := make([]byte, 4) b := make([]byte, 4)
native.PutUint32(b, mode) native.PutUint32(b, mode)
nl.NewRtAttrChild(inner, nl.IFLA_MACVLAN_MACADDR_MODE, b) inner.AddRtAttr(nl.IFLA_MACVLAN_MACADDR_MODE, b)
// populate message with MAC addrs, if necessary // populate message with MAC addrs, if necessary
switch mode { switch mode {
case nl.MACVLAN_MACADDR_ADD, nl.MACVLAN_MACADDR_DEL: case nl.MACVLAN_MACADDR_ADD, nl.MACVLAN_MACADDR_DEL:
if len(addrs) == 1 { if len(addrs) == 1 {
nl.NewRtAttrChild(inner, nl.IFLA_MACVLAN_MACADDR, []byte(addrs[0])) inner.AddRtAttr(nl.IFLA_MACVLAN_MACADDR, []byte(addrs[0]))
} }
case nl.MACVLAN_MACADDR_SET: case nl.MACVLAN_MACADDR_SET:
mad := nl.NewRtAttrChild(inner, nl.IFLA_MACVLAN_MACADDR_DATA, nil) mad := inner.AddRtAttr(nl.IFLA_MACVLAN_MACADDR_DATA, nil)
for _, addr := range addrs { for _, addr := range addrs {
nl.NewRtAttrChild(mad, nl.IFLA_MACVLAN_MACADDR, []byte(addr)) mad.AddRtAttr(nl.IFLA_MACVLAN_MACADDR, []byte(addr))
} }
} }
@@ -423,12 +423,12 @@ func (h *Handle) LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAdd
req.AddData(msg) req.AddData(msg)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfMac{ vfmsg := nl.VfMac{
Vf: uint32(vf), Vf: uint32(vf),
} }
copy(vfmsg.Mac[:], []byte(hwaddr)) copy(vfmsg.Mac[:], []byte(hwaddr))
nl.NewRtAttrChild(info, nl.IFLA_VF_MAC, vfmsg.Serialize()) info.AddRtAttr(nl.IFLA_VF_MAC, vfmsg.Serialize())
req.AddData(data) req.AddData(data)
_, err := req.Execute(unix.NETLINK_ROUTE, 0) _, err := req.Execute(unix.NETLINK_ROUTE, 0)
@@ -453,12 +453,12 @@ func (h *Handle) LinkSetVfVlan(link Link, vf, vlan int) error {
req.AddData(msg) req.AddData(msg)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfVlan{ vfmsg := nl.VfVlan{
Vf: uint32(vf), Vf: uint32(vf),
Vlan: uint32(vlan), Vlan: uint32(vlan),
} }
nl.NewRtAttrChild(info, nl.IFLA_VF_VLAN, vfmsg.Serialize()) info.AddRtAttr(nl.IFLA_VF_VLAN, vfmsg.Serialize())
req.AddData(data) req.AddData(data)
_, err := req.Execute(unix.NETLINK_ROUTE, 0) _, err := req.Execute(unix.NETLINK_ROUTE, 0)
@@ -483,12 +483,12 @@ func (h *Handle) LinkSetVfTxRate(link Link, vf, rate int) error {
req.AddData(msg) req.AddData(msg)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfTxRate{ vfmsg := nl.VfTxRate{
Vf: uint32(vf), Vf: uint32(vf),
Rate: uint32(rate), Rate: uint32(rate),
} }
nl.NewRtAttrChild(info, nl.IFLA_VF_TX_RATE, vfmsg.Serialize()) info.AddRtAttr(nl.IFLA_VF_TX_RATE, vfmsg.Serialize())
req.AddData(data) req.AddData(data)
_, err := req.Execute(unix.NETLINK_ROUTE, 0) _, err := req.Execute(unix.NETLINK_ROUTE, 0)
@@ -514,7 +514,7 @@ func (h *Handle) LinkSetVfSpoofchk(link Link, vf int, check bool) error {
req.AddData(msg) req.AddData(msg)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil)
if check { if check {
setting = 1 setting = 1
} }
@@ -522,7 +522,7 @@ func (h *Handle) LinkSetVfSpoofchk(link Link, vf int, check bool) error {
Vf: uint32(vf), Vf: uint32(vf),
Setting: setting, Setting: setting,
} }
nl.NewRtAttrChild(info, nl.IFLA_VF_SPOOFCHK, vfmsg.Serialize()) info.AddRtAttr(nl.IFLA_VF_SPOOFCHK, vfmsg.Serialize())
req.AddData(data) req.AddData(data)
_, err := req.Execute(unix.NETLINK_ROUTE, 0) _, err := req.Execute(unix.NETLINK_ROUTE, 0)
@@ -548,7 +548,7 @@ func (h *Handle) LinkSetVfTrust(link Link, vf int, state bool) error {
req.AddData(msg) req.AddData(msg)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil)
if state { if state {
setting = 1 setting = 1
} }
@@ -556,7 +556,7 @@ func (h *Handle) LinkSetVfTrust(link Link, vf int, state bool) error {
Vf: uint32(vf), Vf: uint32(vf),
Setting: setting, Setting: setting,
} }
nl.NewRtAttrChild(info, nl.IFLA_VF_TRUST, vfmsg.Serialize()) info.AddRtAttr(nl.IFLA_VF_TRUST, vfmsg.Serialize())
req.AddData(data) req.AddData(data)
_, err := req.Execute(unix.NETLINK_ROUTE, 0) _, err := req.Execute(unix.NETLINK_ROUTE, 0)
@@ -595,12 +595,12 @@ func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidT
req.AddData(msg) req.AddData(msg)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil) data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil) info := data.AddRtAttr(nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfGUID{ vfmsg := nl.VfGUID{
Vf: uint32(vf), Vf: uint32(vf),
GUID: guid, GUID: guid,
} }
nl.NewRtAttrChild(info, guidType, vfmsg.Serialize()) info.AddRtAttr(guidType, vfmsg.Serialize())
req.AddData(data) req.AddData(data)
_, err = req.Execute(unix.NETLINK_ROUTE, 0) _, err = req.Execute(unix.NETLINK_ROUTE, 0)
@@ -761,69 +761,69 @@ type vxlanPortRange struct {
} }
func addVxlanAttrs(vxlan *Vxlan, linkInfo *nl.RtAttr) { func addVxlanAttrs(vxlan *Vxlan, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
if vxlan.FlowBased { if vxlan.FlowBased {
vxlan.VxlanId = 0 vxlan.VxlanId = 0
} }
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_ID, nl.Uint32Attr(uint32(vxlan.VxlanId))) data.AddRtAttr(nl.IFLA_VXLAN_ID, nl.Uint32Attr(uint32(vxlan.VxlanId)))
if vxlan.VtepDevIndex != 0 { if vxlan.VtepDevIndex != 0 {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LINK, nl.Uint32Attr(uint32(vxlan.VtepDevIndex))) data.AddRtAttr(nl.IFLA_VXLAN_LINK, nl.Uint32Attr(uint32(vxlan.VtepDevIndex)))
} }
if vxlan.SrcAddr != nil { if vxlan.SrcAddr != nil {
ip := vxlan.SrcAddr.To4() ip := vxlan.SrcAddr.To4()
if ip != nil { if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LOCAL, []byte(ip)) data.AddRtAttr(nl.IFLA_VXLAN_LOCAL, []byte(ip))
} else { } else {
ip = vxlan.SrcAddr.To16() ip = vxlan.SrcAddr.To16()
if ip != nil { if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LOCAL6, []byte(ip)) data.AddRtAttr(nl.IFLA_VXLAN_LOCAL6, []byte(ip))
} }
} }
} }
if vxlan.Group != nil { if vxlan.Group != nil {
group := vxlan.Group.To4() group := vxlan.Group.To4()
if group != nil { if group != nil {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_GROUP, []byte(group)) data.AddRtAttr(nl.IFLA_VXLAN_GROUP, []byte(group))
} else { } else {
group = vxlan.Group.To16() group = vxlan.Group.To16()
if group != nil { if group != nil {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_GROUP6, []byte(group)) data.AddRtAttr(nl.IFLA_VXLAN_GROUP6, []byte(group))
} }
} }
} }
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_TTL, nl.Uint8Attr(uint8(vxlan.TTL))) data.AddRtAttr(nl.IFLA_VXLAN_TTL, nl.Uint8Attr(uint8(vxlan.TTL)))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_TOS, nl.Uint8Attr(uint8(vxlan.TOS))) data.AddRtAttr(nl.IFLA_VXLAN_TOS, nl.Uint8Attr(uint8(vxlan.TOS)))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LEARNING, boolAttr(vxlan.Learning)) data.AddRtAttr(nl.IFLA_VXLAN_LEARNING, boolAttr(vxlan.Learning))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_PROXY, boolAttr(vxlan.Proxy)) data.AddRtAttr(nl.IFLA_VXLAN_PROXY, boolAttr(vxlan.Proxy))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_RSC, boolAttr(vxlan.RSC)) data.AddRtAttr(nl.IFLA_VXLAN_RSC, boolAttr(vxlan.RSC))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_L2MISS, boolAttr(vxlan.L2miss)) data.AddRtAttr(nl.IFLA_VXLAN_L2MISS, boolAttr(vxlan.L2miss))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_L3MISS, boolAttr(vxlan.L3miss)) data.AddRtAttr(nl.IFLA_VXLAN_L3MISS, boolAttr(vxlan.L3miss))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_UDP_ZERO_CSUM6_TX, boolAttr(vxlan.UDP6ZeroCSumTx)) data.AddRtAttr(nl.IFLA_VXLAN_UDP_ZERO_CSUM6_TX, boolAttr(vxlan.UDP6ZeroCSumTx))
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_UDP_ZERO_CSUM6_RX, boolAttr(vxlan.UDP6ZeroCSumRx)) data.AddRtAttr(nl.IFLA_VXLAN_UDP_ZERO_CSUM6_RX, boolAttr(vxlan.UDP6ZeroCSumRx))
if vxlan.UDPCSum { if vxlan.UDPCSum {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_UDP_CSUM, boolAttr(vxlan.UDPCSum)) data.AddRtAttr(nl.IFLA_VXLAN_UDP_CSUM, boolAttr(vxlan.UDPCSum))
} }
if vxlan.GBP { if vxlan.GBP {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_GBP, []byte{}) data.AddRtAttr(nl.IFLA_VXLAN_GBP, []byte{})
} }
if vxlan.FlowBased { if vxlan.FlowBased {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_FLOWBASED, boolAttr(vxlan.FlowBased)) data.AddRtAttr(nl.IFLA_VXLAN_FLOWBASED, boolAttr(vxlan.FlowBased))
} }
if vxlan.NoAge { if vxlan.NoAge {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_AGEING, nl.Uint32Attr(0)) data.AddRtAttr(nl.IFLA_VXLAN_AGEING, nl.Uint32Attr(0))
} else if vxlan.Age > 0 { } else if vxlan.Age > 0 {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_AGEING, nl.Uint32Attr(uint32(vxlan.Age))) data.AddRtAttr(nl.IFLA_VXLAN_AGEING, nl.Uint32Attr(uint32(vxlan.Age)))
} }
if vxlan.Limit > 0 { if vxlan.Limit > 0 {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_LIMIT, nl.Uint32Attr(uint32(vxlan.Limit))) data.AddRtAttr(nl.IFLA_VXLAN_LIMIT, nl.Uint32Attr(uint32(vxlan.Limit)))
} }
if vxlan.Port > 0 { if vxlan.Port > 0 {
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_PORT, htons(uint16(vxlan.Port))) data.AddRtAttr(nl.IFLA_VXLAN_PORT, htons(uint16(vxlan.Port)))
} }
if vxlan.PortLow > 0 || vxlan.PortHigh > 0 { if vxlan.PortLow > 0 || vxlan.PortHigh > 0 {
pr := vxlanPortRange{uint16(vxlan.PortLow), uint16(vxlan.PortHigh)} pr := vxlanPortRange{uint16(vxlan.PortLow), uint16(vxlan.PortHigh)}
@@ -831,100 +831,100 @@ func addVxlanAttrs(vxlan *Vxlan, linkInfo *nl.RtAttr) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, &pr) binary.Write(buf, binary.BigEndian, &pr)
nl.NewRtAttrChild(data, nl.IFLA_VXLAN_PORT_RANGE, buf.Bytes()) data.AddRtAttr(nl.IFLA_VXLAN_PORT_RANGE, buf.Bytes())
} }
} }
func addBondAttrs(bond *Bond, linkInfo *nl.RtAttr) { func addBondAttrs(bond *Bond, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
if bond.Mode >= 0 { if bond.Mode >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_MODE, nl.Uint8Attr(uint8(bond.Mode))) data.AddRtAttr(nl.IFLA_BOND_MODE, nl.Uint8Attr(uint8(bond.Mode)))
} }
if bond.ActiveSlave >= 0 { if bond.ActiveSlave >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_ACTIVE_SLAVE, nl.Uint32Attr(uint32(bond.ActiveSlave))) data.AddRtAttr(nl.IFLA_BOND_ACTIVE_SLAVE, nl.Uint32Attr(uint32(bond.ActiveSlave)))
} }
if bond.Miimon >= 0 { if bond.Miimon >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_MIIMON, nl.Uint32Attr(uint32(bond.Miimon))) data.AddRtAttr(nl.IFLA_BOND_MIIMON, nl.Uint32Attr(uint32(bond.Miimon)))
} }
if bond.UpDelay >= 0 { if bond.UpDelay >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_UPDELAY, nl.Uint32Attr(uint32(bond.UpDelay))) data.AddRtAttr(nl.IFLA_BOND_UPDELAY, nl.Uint32Attr(uint32(bond.UpDelay)))
} }
if bond.DownDelay >= 0 { if bond.DownDelay >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_DOWNDELAY, nl.Uint32Attr(uint32(bond.DownDelay))) data.AddRtAttr(nl.IFLA_BOND_DOWNDELAY, nl.Uint32Attr(uint32(bond.DownDelay)))
} }
if bond.UseCarrier >= 0 { if bond.UseCarrier >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_USE_CARRIER, nl.Uint8Attr(uint8(bond.UseCarrier))) data.AddRtAttr(nl.IFLA_BOND_USE_CARRIER, nl.Uint8Attr(uint8(bond.UseCarrier)))
} }
if bond.ArpInterval >= 0 { if bond.ArpInterval >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_ARP_INTERVAL, nl.Uint32Attr(uint32(bond.ArpInterval))) data.AddRtAttr(nl.IFLA_BOND_ARP_INTERVAL, nl.Uint32Attr(uint32(bond.ArpInterval)))
} }
if bond.ArpIpTargets != nil { if bond.ArpIpTargets != nil {
msg := nl.NewRtAttrChild(data, nl.IFLA_BOND_ARP_IP_TARGET, nil) msg := data.AddRtAttr(nl.IFLA_BOND_ARP_IP_TARGET, nil)
for i := range bond.ArpIpTargets { for i := range bond.ArpIpTargets {
ip := bond.ArpIpTargets[i].To4() ip := bond.ArpIpTargets[i].To4()
if ip != nil { if ip != nil {
nl.NewRtAttrChild(msg, i, []byte(ip)) msg.AddRtAttr(i, []byte(ip))
continue continue
} }
ip = bond.ArpIpTargets[i].To16() ip = bond.ArpIpTargets[i].To16()
if ip != nil { if ip != nil {
nl.NewRtAttrChild(msg, i, []byte(ip)) msg.AddRtAttr(i, []byte(ip))
} }
} }
} }
if bond.ArpValidate >= 0 { if bond.ArpValidate >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_ARP_VALIDATE, nl.Uint32Attr(uint32(bond.ArpValidate))) data.AddRtAttr(nl.IFLA_BOND_ARP_VALIDATE, nl.Uint32Attr(uint32(bond.ArpValidate)))
} }
if bond.ArpAllTargets >= 0 { if bond.ArpAllTargets >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_ARP_ALL_TARGETS, nl.Uint32Attr(uint32(bond.ArpAllTargets))) data.AddRtAttr(nl.IFLA_BOND_ARP_ALL_TARGETS, nl.Uint32Attr(uint32(bond.ArpAllTargets)))
} }
if bond.Primary >= 0 { if bond.Primary >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_PRIMARY, nl.Uint32Attr(uint32(bond.Primary))) data.AddRtAttr(nl.IFLA_BOND_PRIMARY, nl.Uint32Attr(uint32(bond.Primary)))
} }
if bond.PrimaryReselect >= 0 { if bond.PrimaryReselect >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_PRIMARY_RESELECT, nl.Uint8Attr(uint8(bond.PrimaryReselect))) data.AddRtAttr(nl.IFLA_BOND_PRIMARY_RESELECT, nl.Uint8Attr(uint8(bond.PrimaryReselect)))
} }
if bond.FailOverMac >= 0 { if bond.FailOverMac >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_FAIL_OVER_MAC, nl.Uint8Attr(uint8(bond.FailOverMac))) data.AddRtAttr(nl.IFLA_BOND_FAIL_OVER_MAC, nl.Uint8Attr(uint8(bond.FailOverMac)))
} }
if bond.XmitHashPolicy >= 0 { if bond.XmitHashPolicy >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_XMIT_HASH_POLICY, nl.Uint8Attr(uint8(bond.XmitHashPolicy))) data.AddRtAttr(nl.IFLA_BOND_XMIT_HASH_POLICY, nl.Uint8Attr(uint8(bond.XmitHashPolicy)))
} }
if bond.ResendIgmp >= 0 { if bond.ResendIgmp >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_RESEND_IGMP, nl.Uint32Attr(uint32(bond.ResendIgmp))) data.AddRtAttr(nl.IFLA_BOND_RESEND_IGMP, nl.Uint32Attr(uint32(bond.ResendIgmp)))
} }
if bond.NumPeerNotif >= 0 { if bond.NumPeerNotif >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_NUM_PEER_NOTIF, nl.Uint8Attr(uint8(bond.NumPeerNotif))) data.AddRtAttr(nl.IFLA_BOND_NUM_PEER_NOTIF, nl.Uint8Attr(uint8(bond.NumPeerNotif)))
} }
if bond.AllSlavesActive >= 0 { if bond.AllSlavesActive >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_ALL_SLAVES_ACTIVE, nl.Uint8Attr(uint8(bond.AllSlavesActive))) data.AddRtAttr(nl.IFLA_BOND_ALL_SLAVES_ACTIVE, nl.Uint8Attr(uint8(bond.AllSlavesActive)))
} }
if bond.MinLinks >= 0 { if bond.MinLinks >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_MIN_LINKS, nl.Uint32Attr(uint32(bond.MinLinks))) data.AddRtAttr(nl.IFLA_BOND_MIN_LINKS, nl.Uint32Attr(uint32(bond.MinLinks)))
} }
if bond.LpInterval >= 0 { if bond.LpInterval >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_LP_INTERVAL, nl.Uint32Attr(uint32(bond.LpInterval))) data.AddRtAttr(nl.IFLA_BOND_LP_INTERVAL, nl.Uint32Attr(uint32(bond.LpInterval)))
} }
if bond.PackersPerSlave >= 0 { if bond.PackersPerSlave >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_PACKETS_PER_SLAVE, nl.Uint32Attr(uint32(bond.PackersPerSlave))) data.AddRtAttr(nl.IFLA_BOND_PACKETS_PER_SLAVE, nl.Uint32Attr(uint32(bond.PackersPerSlave)))
} }
if bond.LacpRate >= 0 { if bond.LacpRate >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_LACP_RATE, nl.Uint8Attr(uint8(bond.LacpRate))) data.AddRtAttr(nl.IFLA_BOND_AD_LACP_RATE, nl.Uint8Attr(uint8(bond.LacpRate)))
} }
if bond.AdSelect >= 0 { if bond.AdSelect >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_SELECT, nl.Uint8Attr(uint8(bond.AdSelect))) data.AddRtAttr(nl.IFLA_BOND_AD_SELECT, nl.Uint8Attr(uint8(bond.AdSelect)))
} }
if bond.AdActorSysPrio >= 0 { if bond.AdActorSysPrio >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_ACTOR_SYS_PRIO, nl.Uint16Attr(uint16(bond.AdActorSysPrio))) data.AddRtAttr(nl.IFLA_BOND_AD_ACTOR_SYS_PRIO, nl.Uint16Attr(uint16(bond.AdActorSysPrio)))
} }
if bond.AdUserPortKey >= 0 { if bond.AdUserPortKey >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_USER_PORT_KEY, nl.Uint16Attr(uint16(bond.AdUserPortKey))) data.AddRtAttr(nl.IFLA_BOND_AD_USER_PORT_KEY, nl.Uint16Attr(uint16(bond.AdUserPortKey)))
} }
if bond.AdActorSystem != nil { if bond.AdActorSystem != nil {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_ACTOR_SYSTEM, []byte(bond.AdActorSystem)) data.AddRtAttr(nl.IFLA_BOND_AD_ACTOR_SYSTEM, []byte(bond.AdActorSystem))
} }
if bond.TlbDynamicLb >= 0 { if bond.TlbDynamicLb >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_TLB_DYNAMIC_LB, nl.Uint8Attr(uint8(bond.TlbDynamicLb))) data.AddRtAttr(nl.IFLA_BOND_TLB_DYNAMIC_LB, nl.Uint8Attr(uint8(bond.TlbDynamicLb)))
} }
} }
@@ -1137,24 +1137,24 @@ func (h *Handle) linkModify(link Link, flags int) error {
} }
linkInfo := nl.NewRtAttr(unix.IFLA_LINKINFO, nil) linkInfo := nl.NewRtAttr(unix.IFLA_LINKINFO, nil)
nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_KIND, nl.NonZeroTerminated(link.Type())) linkInfo.AddRtAttr(nl.IFLA_INFO_KIND, nl.NonZeroTerminated(link.Type()))
switch link := link.(type) { switch link := link.(type) {
case *Vlan: case *Vlan:
b := make([]byte, 2) b := make([]byte, 2)
native.PutUint16(b, uint16(link.VlanId)) native.PutUint16(b, uint16(link.VlanId))
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_VLAN_ID, b) data.AddRtAttr(nl.IFLA_VLAN_ID, b)
case *Veth: case *Veth:
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
peer := nl.NewRtAttrChild(data, nl.VETH_INFO_PEER, nil) peer := data.AddRtAttr(nl.VETH_INFO_PEER, nil)
nl.NewIfInfomsgChild(peer, unix.AF_UNSPEC) nl.NewIfInfomsgChild(peer, unix.AF_UNSPEC)
nl.NewRtAttrChild(peer, unix.IFLA_IFNAME, nl.ZeroTerminated(link.PeerName)) peer.AddRtAttr(unix.IFLA_IFNAME, nl.ZeroTerminated(link.PeerName))
if base.TxQLen >= 0 { if base.TxQLen >= 0 {
nl.NewRtAttrChild(peer, unix.IFLA_TXQLEN, nl.Uint32Attr(uint32(base.TxQLen))) peer.AddRtAttr(unix.IFLA_TXQLEN, nl.Uint32Attr(uint32(base.TxQLen)))
} }
if base.MTU > 0 { if base.MTU > 0 {
nl.NewRtAttrChild(peer, unix.IFLA_MTU, nl.Uint32Attr(uint32(base.MTU))) peer.AddRtAttr(unix.IFLA_MTU, nl.Uint32Attr(uint32(base.MTU)))
} }
case *Vxlan: case *Vxlan:
@@ -1162,17 +1162,17 @@ func (h *Handle) linkModify(link Link, flags int) error {
case *Bond: case *Bond:
addBondAttrs(link, linkInfo) addBondAttrs(link, linkInfo)
case *IPVlan: case *IPVlan:
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_IPVLAN_MODE, nl.Uint16Attr(uint16(link.Mode))) data.AddRtAttr(nl.IFLA_IPVLAN_MODE, nl.Uint16Attr(uint16(link.Mode)))
case *Macvlan: case *Macvlan:
if link.Mode != MACVLAN_MODE_DEFAULT { if link.Mode != MACVLAN_MODE_DEFAULT {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[link.Mode])) data.AddRtAttr(nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[link.Mode]))
} }
case *Macvtap: case *Macvtap:
if link.Mode != MACVLAN_MODE_DEFAULT { if link.Mode != MACVLAN_MODE_DEFAULT {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[link.Mode])) data.AddRtAttr(nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[link.Mode]))
} }
case *Gretap: case *Gretap:
addGretapAttrs(link, linkInfo) addGretapAttrs(link, linkInfo)
@@ -1767,7 +1767,7 @@ func (h *Handle) setProtinfoAttr(link Link, mode bool, attr int) error {
req.AddData(msg) req.AddData(msg)
br := nl.NewRtAttr(unix.IFLA_PROTINFO|unix.NLA_F_NESTED, nil) br := nl.NewRtAttr(unix.IFLA_PROTINFO|unix.NLA_F_NESTED, nil)
nl.NewRtAttrChild(br, attr, boolToByte(mode)) br.AddRtAttr(attr, boolToByte(mode))
req.AddData(br) req.AddData(br)
_, err := req.Execute(unix.NETLINK_ROUTE, 0) _, err := req.Execute(unix.NETLINK_ROUTE, 0)
if err != nil { if err != nil {
@@ -2001,11 +2001,11 @@ func linkFlags(rawFlags uint32) net.Flags {
} }
func addGretapAttrs(gretap *Gretap, linkInfo *nl.RtAttr) { func addGretapAttrs(gretap *Gretap, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
if gretap.FlowBased { if gretap.FlowBased {
// In flow based mode, no other attributes need to be configured // In flow based mode, no other attributes need to be configured
nl.NewRtAttrChild(data, nl.IFLA_GRE_COLLECT_METADATA, boolAttr(gretap.FlowBased)) data.AddRtAttr(nl.IFLA_GRE_COLLECT_METADATA, boolAttr(gretap.FlowBased))
return return
} }
@@ -2013,40 +2013,40 @@ func addGretapAttrs(gretap *Gretap, linkInfo *nl.RtAttr) {
if ip.To4() != nil { if ip.To4() != nil {
ip = ip.To4() ip = ip.To4()
} }
nl.NewRtAttrChild(data, nl.IFLA_GRE_LOCAL, []byte(ip)) data.AddRtAttr(nl.IFLA_GRE_LOCAL, []byte(ip))
} }
if ip := gretap.Remote; ip != nil { if ip := gretap.Remote; ip != nil {
if ip.To4() != nil { if ip.To4() != nil {
ip = ip.To4() ip = ip.To4()
} }
nl.NewRtAttrChild(data, nl.IFLA_GRE_REMOTE, []byte(ip)) data.AddRtAttr(nl.IFLA_GRE_REMOTE, []byte(ip))
} }
if gretap.IKey != 0 { if gretap.IKey != 0 {
nl.NewRtAttrChild(data, nl.IFLA_GRE_IKEY, htonl(gretap.IKey)) data.AddRtAttr(nl.IFLA_GRE_IKEY, htonl(gretap.IKey))
gretap.IFlags |= uint16(nl.GRE_KEY) gretap.IFlags |= uint16(nl.GRE_KEY)
} }
if gretap.OKey != 0 { if gretap.OKey != 0 {
nl.NewRtAttrChild(data, nl.IFLA_GRE_OKEY, htonl(gretap.OKey)) data.AddRtAttr(nl.IFLA_GRE_OKEY, htonl(gretap.OKey))
gretap.OFlags |= uint16(nl.GRE_KEY) gretap.OFlags |= uint16(nl.GRE_KEY)
} }
nl.NewRtAttrChild(data, nl.IFLA_GRE_IFLAGS, htons(gretap.IFlags)) data.AddRtAttr(nl.IFLA_GRE_IFLAGS, htons(gretap.IFlags))
nl.NewRtAttrChild(data, nl.IFLA_GRE_OFLAGS, htons(gretap.OFlags)) data.AddRtAttr(nl.IFLA_GRE_OFLAGS, htons(gretap.OFlags))
if gretap.Link != 0 { if gretap.Link != 0 {
nl.NewRtAttrChild(data, nl.IFLA_GRE_LINK, nl.Uint32Attr(gretap.Link)) data.AddRtAttr(nl.IFLA_GRE_LINK, nl.Uint32Attr(gretap.Link))
} }
nl.NewRtAttrChild(data, nl.IFLA_GRE_PMTUDISC, nl.Uint8Attr(gretap.PMtuDisc)) data.AddRtAttr(nl.IFLA_GRE_PMTUDISC, nl.Uint8Attr(gretap.PMtuDisc))
nl.NewRtAttrChild(data, nl.IFLA_GRE_TTL, nl.Uint8Attr(gretap.Ttl)) data.AddRtAttr(nl.IFLA_GRE_TTL, nl.Uint8Attr(gretap.Ttl))
nl.NewRtAttrChild(data, nl.IFLA_GRE_TOS, nl.Uint8Attr(gretap.Tos)) data.AddRtAttr(nl.IFLA_GRE_TOS, nl.Uint8Attr(gretap.Tos))
nl.NewRtAttrChild(data, nl.IFLA_GRE_ENCAP_TYPE, nl.Uint16Attr(gretap.EncapType)) data.AddRtAttr(nl.IFLA_GRE_ENCAP_TYPE, nl.Uint16Attr(gretap.EncapType))
nl.NewRtAttrChild(data, nl.IFLA_GRE_ENCAP_FLAGS, nl.Uint16Attr(gretap.EncapFlags)) data.AddRtAttr(nl.IFLA_GRE_ENCAP_FLAGS, nl.Uint16Attr(gretap.EncapFlags))
nl.NewRtAttrChild(data, nl.IFLA_GRE_ENCAP_SPORT, htons(gretap.EncapSport)) data.AddRtAttr(nl.IFLA_GRE_ENCAP_SPORT, htons(gretap.EncapSport))
nl.NewRtAttrChild(data, nl.IFLA_GRE_ENCAP_DPORT, htons(gretap.EncapDport)) data.AddRtAttr(nl.IFLA_GRE_ENCAP_DPORT, htons(gretap.EncapDport))
} }
func parseGretapData(link Link, data []syscall.NetlinkRouteAttr) { func parseGretapData(link Link, data []syscall.NetlinkRouteAttr) {
@@ -2088,46 +2088,46 @@ func parseGretapData(link Link, data []syscall.NetlinkRouteAttr) {
} }
func addGretunAttrs(gre *Gretun, linkInfo *nl.RtAttr) { func addGretunAttrs(gre *Gretun, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
if ip := gre.Local; ip != nil { if ip := gre.Local; ip != nil {
if ip.To4() != nil { if ip.To4() != nil {
ip = ip.To4() ip = ip.To4()
} }
nl.NewRtAttrChild(data, nl.IFLA_GRE_LOCAL, []byte(ip)) data.AddRtAttr(nl.IFLA_GRE_LOCAL, []byte(ip))
} }
if ip := gre.Remote; ip != nil { if ip := gre.Remote; ip != nil {
if ip.To4() != nil { if ip.To4() != nil {
ip = ip.To4() ip = ip.To4()
} }
nl.NewRtAttrChild(data, nl.IFLA_GRE_REMOTE, []byte(ip)) data.AddRtAttr(nl.IFLA_GRE_REMOTE, []byte(ip))
} }
if gre.IKey != 0 { if gre.IKey != 0 {
nl.NewRtAttrChild(data, nl.IFLA_GRE_IKEY, htonl(gre.IKey)) data.AddRtAttr(nl.IFLA_GRE_IKEY, htonl(gre.IKey))
gre.IFlags |= uint16(nl.GRE_KEY) gre.IFlags |= uint16(nl.GRE_KEY)
} }
if gre.OKey != 0 { if gre.OKey != 0 {
nl.NewRtAttrChild(data, nl.IFLA_GRE_OKEY, htonl(gre.OKey)) data.AddRtAttr(nl.IFLA_GRE_OKEY, htonl(gre.OKey))
gre.OFlags |= uint16(nl.GRE_KEY) gre.OFlags |= uint16(nl.GRE_KEY)
} }
nl.NewRtAttrChild(data, nl.IFLA_GRE_IFLAGS, htons(gre.IFlags)) data.AddRtAttr(nl.IFLA_GRE_IFLAGS, htons(gre.IFlags))
nl.NewRtAttrChild(data, nl.IFLA_GRE_OFLAGS, htons(gre.OFlags)) data.AddRtAttr(nl.IFLA_GRE_OFLAGS, htons(gre.OFlags))
if gre.Link != 0 { if gre.Link != 0 {
nl.NewRtAttrChild(data, nl.IFLA_GRE_LINK, nl.Uint32Attr(gre.Link)) data.AddRtAttr(nl.IFLA_GRE_LINK, nl.Uint32Attr(gre.Link))
} }
nl.NewRtAttrChild(data, nl.IFLA_GRE_PMTUDISC, nl.Uint8Attr(gre.PMtuDisc)) data.AddRtAttr(nl.IFLA_GRE_PMTUDISC, nl.Uint8Attr(gre.PMtuDisc))
nl.NewRtAttrChild(data, nl.IFLA_GRE_TTL, nl.Uint8Attr(gre.Ttl)) data.AddRtAttr(nl.IFLA_GRE_TTL, nl.Uint8Attr(gre.Ttl))
nl.NewRtAttrChild(data, nl.IFLA_GRE_TOS, nl.Uint8Attr(gre.Tos)) data.AddRtAttr(nl.IFLA_GRE_TOS, nl.Uint8Attr(gre.Tos))
nl.NewRtAttrChild(data, nl.IFLA_GRE_ENCAP_TYPE, nl.Uint16Attr(gre.EncapType)) data.AddRtAttr(nl.IFLA_GRE_ENCAP_TYPE, nl.Uint16Attr(gre.EncapType))
nl.NewRtAttrChild(data, nl.IFLA_GRE_ENCAP_FLAGS, nl.Uint16Attr(gre.EncapFlags)) data.AddRtAttr(nl.IFLA_GRE_ENCAP_FLAGS, nl.Uint16Attr(gre.EncapFlags))
nl.NewRtAttrChild(data, nl.IFLA_GRE_ENCAP_SPORT, htons(gre.EncapSport)) data.AddRtAttr(nl.IFLA_GRE_ENCAP_SPORT, htons(gre.EncapSport))
nl.NewRtAttrChild(data, nl.IFLA_GRE_ENCAP_DPORT, htons(gre.EncapDport)) data.AddRtAttr(nl.IFLA_GRE_ENCAP_DPORT, htons(gre.EncapDport))
} }
func parseGretunData(link Link, data []syscall.NetlinkRouteAttr) { func parseGretunData(link Link, data []syscall.NetlinkRouteAttr) {
@@ -2176,11 +2176,11 @@ func addXdpAttrs(xdp *LinkXdp, req *nl.NetlinkRequest) {
attrs := nl.NewRtAttr(unix.IFLA_XDP|unix.NLA_F_NESTED, nil) attrs := nl.NewRtAttr(unix.IFLA_XDP|unix.NLA_F_NESTED, nil)
b := make([]byte, 4) b := make([]byte, 4)
native.PutUint32(b, uint32(xdp.Fd)) native.PutUint32(b, uint32(xdp.Fd))
nl.NewRtAttrChild(attrs, nl.IFLA_XDP_FD, b) attrs.AddRtAttr(nl.IFLA_XDP_FD, b)
if xdp.Flags != 0 { if xdp.Flags != 0 {
b := make([]byte, 4) b := make([]byte, 4)
native.PutUint32(b, xdp.Flags) native.PutUint32(b, xdp.Flags)
nl.NewRtAttrChild(attrs, nl.IFLA_XDP_FLAGS, b) attrs.AddRtAttr(nl.IFLA_XDP_FLAGS, b)
} }
req.AddData(attrs) req.AddData(attrs)
} }
@@ -2209,32 +2209,32 @@ func parseLinkXdp(data []byte) (*LinkXdp, error) {
func addIptunAttrs(iptun *Iptun, linkInfo *nl.RtAttr) { func addIptunAttrs(iptun *Iptun, linkInfo *nl.RtAttr) {
if iptun.FlowBased { if iptun.FlowBased {
// In flow based mode, no other attributes need to be configured // In flow based mode, no other attributes need to be configured
nl.NewRtAttrChild(linkInfo, nl.IFLA_IPTUN_COLLECT_METADATA, boolAttr(iptun.FlowBased)) linkInfo.AddRtAttr(nl.IFLA_IPTUN_COLLECT_METADATA, boolAttr(iptun.FlowBased))
return return
} }
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
ip := iptun.Local.To4() ip := iptun.Local.To4()
if ip != nil { if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_LOCAL, []byte(ip)) data.AddRtAttr(nl.IFLA_IPTUN_LOCAL, []byte(ip))
} }
ip = iptun.Remote.To4() ip = iptun.Remote.To4()
if ip != nil { if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_REMOTE, []byte(ip)) data.AddRtAttr(nl.IFLA_IPTUN_REMOTE, []byte(ip))
} }
if iptun.Link != 0 { if iptun.Link != 0 {
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_LINK, nl.Uint32Attr(iptun.Link)) data.AddRtAttr(nl.IFLA_IPTUN_LINK, nl.Uint32Attr(iptun.Link))
} }
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_PMTUDISC, nl.Uint8Attr(iptun.PMtuDisc)) data.AddRtAttr(nl.IFLA_IPTUN_PMTUDISC, nl.Uint8Attr(iptun.PMtuDisc))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_TTL, nl.Uint8Attr(iptun.Ttl)) data.AddRtAttr(nl.IFLA_IPTUN_TTL, nl.Uint8Attr(iptun.Ttl))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_TOS, nl.Uint8Attr(iptun.Tos)) data.AddRtAttr(nl.IFLA_IPTUN_TOS, nl.Uint8Attr(iptun.Tos))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_ENCAP_TYPE, nl.Uint16Attr(iptun.EncapType)) data.AddRtAttr(nl.IFLA_IPTUN_ENCAP_TYPE, nl.Uint16Attr(iptun.EncapType))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_ENCAP_FLAGS, nl.Uint16Attr(iptun.EncapFlags)) data.AddRtAttr(nl.IFLA_IPTUN_ENCAP_FLAGS, nl.Uint16Attr(iptun.EncapFlags))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_ENCAP_SPORT, htons(iptun.EncapSport)) data.AddRtAttr(nl.IFLA_IPTUN_ENCAP_SPORT, htons(iptun.EncapSport))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_ENCAP_DPORT, htons(iptun.EncapDport)) data.AddRtAttr(nl.IFLA_IPTUN_ENCAP_DPORT, htons(iptun.EncapDport))
} }
func parseIptunData(link Link, data []syscall.NetlinkRouteAttr) { func parseIptunData(link Link, data []syscall.NetlinkRouteAttr) {
@@ -2266,33 +2266,33 @@ func parseIptunData(link Link, data []syscall.NetlinkRouteAttr) {
} }
func addSittunAttrs(sittun *Sittun, linkInfo *nl.RtAttr) { func addSittunAttrs(sittun *Sittun, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
if sittun.Link != 0 { if sittun.Link != 0 {
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_LINK, nl.Uint32Attr(sittun.Link)) data.AddRtAttr(nl.IFLA_IPTUN_LINK, nl.Uint32Attr(sittun.Link))
} }
ip := sittun.Local.To4() ip := sittun.Local.To4()
if ip != nil { if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_LOCAL, []byte(ip)) data.AddRtAttr(nl.IFLA_IPTUN_LOCAL, []byte(ip))
} }
ip = sittun.Remote.To4() ip = sittun.Remote.To4()
if ip != nil { if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_REMOTE, []byte(ip)) data.AddRtAttr(nl.IFLA_IPTUN_REMOTE, []byte(ip))
} }
if sittun.Ttl > 0 { if sittun.Ttl > 0 {
// Would otherwise fail on 3.10 kernel // Would otherwise fail on 3.10 kernel
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_TTL, nl.Uint8Attr(sittun.Ttl)) data.AddRtAttr(nl.IFLA_IPTUN_TTL, nl.Uint8Attr(sittun.Ttl))
} }
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_TOS, nl.Uint8Attr(sittun.Tos)) data.AddRtAttr(nl.IFLA_IPTUN_TOS, nl.Uint8Attr(sittun.Tos))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_PMTUDISC, nl.Uint8Attr(sittun.PMtuDisc)) data.AddRtAttr(nl.IFLA_IPTUN_PMTUDISC, nl.Uint8Attr(sittun.PMtuDisc))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_ENCAP_TYPE, nl.Uint16Attr(sittun.EncapType)) data.AddRtAttr(nl.IFLA_IPTUN_ENCAP_TYPE, nl.Uint16Attr(sittun.EncapType))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_ENCAP_FLAGS, nl.Uint16Attr(sittun.EncapFlags)) data.AddRtAttr(nl.IFLA_IPTUN_ENCAP_FLAGS, nl.Uint16Attr(sittun.EncapFlags))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_ENCAP_SPORT, htons(sittun.EncapSport)) data.AddRtAttr(nl.IFLA_IPTUN_ENCAP_SPORT, htons(sittun.EncapSport))
nl.NewRtAttrChild(data, nl.IFLA_IPTUN_ENCAP_DPORT, htons(sittun.EncapDport)) data.AddRtAttr(nl.IFLA_IPTUN_ENCAP_DPORT, htons(sittun.EncapDport))
} }
func parseSittunData(link Link, data []syscall.NetlinkRouteAttr) { func parseSittunData(link Link, data []syscall.NetlinkRouteAttr) {
@@ -2322,7 +2322,7 @@ func parseSittunData(link Link, data []syscall.NetlinkRouteAttr) {
} }
func addVtiAttrs(vti *Vti, linkInfo *nl.RtAttr) { func addVtiAttrs(vti *Vti, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
family := FAMILY_V4 family := FAMILY_V4
if vti.Local.To4() == nil { if vti.Local.To4() == nil {
@@ -2337,7 +2337,7 @@ func addVtiAttrs(vti *Vti, linkInfo *nl.RtAttr) {
ip = vti.Local ip = vti.Local
} }
if ip != nil { if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_VTI_LOCAL, []byte(ip)) data.AddRtAttr(nl.IFLA_VTI_LOCAL, []byte(ip))
} }
if family == FAMILY_V4 { if family == FAMILY_V4 {
@@ -2346,15 +2346,15 @@ func addVtiAttrs(vti *Vti, linkInfo *nl.RtAttr) {
ip = vti.Remote ip = vti.Remote
} }
if ip != nil { if ip != nil {
nl.NewRtAttrChild(data, nl.IFLA_VTI_REMOTE, []byte(ip)) data.AddRtAttr(nl.IFLA_VTI_REMOTE, []byte(ip))
} }
if vti.Link != 0 { if vti.Link != 0 {
nl.NewRtAttrChild(data, nl.IFLA_VTI_LINK, nl.Uint32Attr(vti.Link)) data.AddRtAttr(nl.IFLA_VTI_LINK, nl.Uint32Attr(vti.Link))
} }
nl.NewRtAttrChild(data, nl.IFLA_VTI_IKEY, htonl(vti.IKey)) data.AddRtAttr(nl.IFLA_VTI_IKEY, htonl(vti.IKey))
nl.NewRtAttrChild(data, nl.IFLA_VTI_OKEY, htonl(vti.OKey)) data.AddRtAttr(nl.IFLA_VTI_OKEY, htonl(vti.OKey))
} }
func parseVtiData(link Link, data []syscall.NetlinkRouteAttr) { func parseVtiData(link Link, data []syscall.NetlinkRouteAttr) {
@@ -2374,10 +2374,10 @@ func parseVtiData(link Link, data []syscall.NetlinkRouteAttr) {
} }
func addVrfAttrs(vrf *Vrf, linkInfo *nl.RtAttr) { func addVrfAttrs(vrf *Vrf, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
b := make([]byte, 4) b := make([]byte, 4)
native.PutUint32(b, uint32(vrf.Table)) native.PutUint32(b, uint32(vrf.Table))
nl.NewRtAttrChild(data, nl.IFLA_VRF_TABLE, b) data.AddRtAttr(nl.IFLA_VRF_TABLE, b)
} }
func parseVrfData(link Link, data []syscall.NetlinkRouteAttr) { func parseVrfData(link Link, data []syscall.NetlinkRouteAttr) {
@@ -2391,15 +2391,15 @@ func parseVrfData(link Link, data []syscall.NetlinkRouteAttr) {
} }
func addBridgeAttrs(bridge *Bridge, linkInfo *nl.RtAttr) { func addBridgeAttrs(bridge *Bridge, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
if bridge.MulticastSnooping != nil { if bridge.MulticastSnooping != nil {
nl.NewRtAttrChild(data, nl.IFLA_BR_MCAST_SNOOPING, boolToByte(*bridge.MulticastSnooping)) data.AddRtAttr(nl.IFLA_BR_MCAST_SNOOPING, boolToByte(*bridge.MulticastSnooping))
} }
if bridge.HelloTime != nil { if bridge.HelloTime != nil {
nl.NewRtAttrChild(data, nl.IFLA_BR_HELLO_TIME, nl.Uint32Attr(*bridge.HelloTime)) data.AddRtAttr(nl.IFLA_BR_HELLO_TIME, nl.Uint32Attr(*bridge.HelloTime))
} }
if bridge.VlanFiltering != nil { if bridge.VlanFiltering != nil {
nl.NewRtAttrChild(data, nl.IFLA_BR_VLAN_FILTERING, boolToByte(*bridge.VlanFiltering)) data.AddRtAttr(nl.IFLA_BR_VLAN_FILTERING, boolToByte(*bridge.VlanFiltering))
} }
} }
@@ -2421,12 +2421,12 @@ func parseBridgeData(bridge Link, data []syscall.NetlinkRouteAttr) {
} }
func addGTPAttrs(gtp *GTP, linkInfo *nl.RtAttr) { func addGTPAttrs(gtp *GTP, linkInfo *nl.RtAttr) {
data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
nl.NewRtAttrChild(data, nl.IFLA_GTP_FD0, nl.Uint32Attr(uint32(gtp.FD0))) data.AddRtAttr(nl.IFLA_GTP_FD0, nl.Uint32Attr(uint32(gtp.FD0)))
nl.NewRtAttrChild(data, nl.IFLA_GTP_FD1, nl.Uint32Attr(uint32(gtp.FD1))) data.AddRtAttr(nl.IFLA_GTP_FD1, nl.Uint32Attr(uint32(gtp.FD1)))
nl.NewRtAttrChild(data, nl.IFLA_GTP_PDP_HASHSIZE, nl.Uint32Attr(131072)) data.AddRtAttr(nl.IFLA_GTP_PDP_HASHSIZE, nl.Uint32Attr(131072))
if gtp.Role != nl.GTP_ROLE_GGSN { if gtp.Role != nl.GTP_ROLE_GGSN {
nl.NewRtAttrChild(data, nl.IFLA_GTP_ROLE, nl.Uint32Attr(uint32(gtp.Role))) data.AddRtAttr(nl.IFLA_GTP_ROLE, nl.Uint32Attr(uint32(gtp.Role)))
} }
} }

View File

@@ -275,10 +275,17 @@ func NewRtAttr(attrType int, data []byte) *RtAttr {
} }
} }
// Create a new RtAttr obj anc add it as a child of an existing object // NewRtAttrChild adds an RtAttr as a child to the parent and returns the new attribute
//
// Deprecated: Use AddRtAttr() on the parent object
func NewRtAttrChild(parent *RtAttr, attrType int, data []byte) *RtAttr { func NewRtAttrChild(parent *RtAttr, attrType int, data []byte) *RtAttr {
return parent.AddRtAttr(attrType, data)
}
// AddRtAttr adds an RtAttr as a child and returns the new attribute
func (a *RtAttr) AddRtAttr(attrType int, data []byte) *RtAttr {
attr := NewRtAttr(attrType, data) attr := NewRtAttr(attrType, data)
parent.children = append(parent.children, attr) a.children = append(a.children, attr)
return attr return attr
} }

View File

@@ -175,15 +175,15 @@ func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
opt.Peakrate.Rate = uint32(qdisc.Peakrate) opt.Peakrate.Rate = uint32(qdisc.Peakrate)
opt.Limit = qdisc.Limit opt.Limit = qdisc.Limit
opt.Buffer = qdisc.Buffer opt.Buffer = qdisc.Buffer
nl.NewRtAttrChild(options, nl.TCA_TBF_PARMS, opt.Serialize()) options.AddRtAttr(nl.TCA_TBF_PARMS, opt.Serialize())
if qdisc.Rate >= uint64(1<<32) { if qdisc.Rate >= uint64(1<<32) {
nl.NewRtAttrChild(options, nl.TCA_TBF_RATE64, nl.Uint64Attr(qdisc.Rate)) options.AddRtAttr(nl.TCA_TBF_RATE64, nl.Uint64Attr(qdisc.Rate))
} }
if qdisc.Peakrate >= uint64(1<<32) { if qdisc.Peakrate >= uint64(1<<32) {
nl.NewRtAttrChild(options, nl.TCA_TBF_PRATE64, nl.Uint64Attr(qdisc.Peakrate)) options.AddRtAttr(nl.TCA_TBF_PRATE64, nl.Uint64Attr(qdisc.Peakrate))
} }
if qdisc.Peakrate > 0 { if qdisc.Peakrate > 0 {
nl.NewRtAttrChild(options, nl.TCA_TBF_PBURST, nl.Uint32Attr(qdisc.Minburst)) options.AddRtAttr(nl.TCA_TBF_PBURST, nl.Uint32Attr(qdisc.Minburst))
} }
case *Htb: case *Htb:
opt := nl.TcHtbGlob{} opt := nl.TcHtbGlob{}
@@ -193,8 +193,8 @@ func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
// TODO: Handle Debug properly. For now default to 0 // TODO: Handle Debug properly. For now default to 0
opt.Debug = qdisc.Debug opt.Debug = qdisc.Debug
opt.DirectPkts = qdisc.DirectPkts opt.DirectPkts = qdisc.DirectPkts
nl.NewRtAttrChild(options, nl.TCA_HTB_INIT, opt.Serialize()) options.AddRtAttr(nl.TCA_HTB_INIT, opt.Serialize())
// nl.NewRtAttrChild(options, nl.TCA_HTB_DIRECT_QLEN, opt.Serialize()) // options.AddRtAttr(nl.TCA_HTB_DIRECT_QLEN, opt.Serialize())
case *Hfsc: case *Hfsc:
opt := nl.TcHfscOpt{} opt := nl.TcHfscOpt{}
opt.Defcls = qdisc.Defcls opt.Defcls = qdisc.Defcls
@@ -215,21 +215,21 @@ func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
corr.DupCorr = qdisc.DuplicateCorr corr.DupCorr = qdisc.DuplicateCorr
if corr.DelayCorr > 0 || corr.LossCorr > 0 || corr.DupCorr > 0 { if corr.DelayCorr > 0 || corr.LossCorr > 0 || corr.DupCorr > 0 {
nl.NewRtAttrChild(options, nl.TCA_NETEM_CORR, corr.Serialize()) options.AddRtAttr(nl.TCA_NETEM_CORR, corr.Serialize())
} }
// Corruption // Corruption
corruption := nl.TcNetemCorrupt{} corruption := nl.TcNetemCorrupt{}
corruption.Probability = qdisc.CorruptProb corruption.Probability = qdisc.CorruptProb
corruption.Correlation = qdisc.CorruptCorr corruption.Correlation = qdisc.CorruptCorr
if corruption.Probability > 0 { if corruption.Probability > 0 {
nl.NewRtAttrChild(options, nl.TCA_NETEM_CORRUPT, corruption.Serialize()) options.AddRtAttr(nl.TCA_NETEM_CORRUPT, corruption.Serialize())
} }
// Reorder // Reorder
reorder := nl.TcNetemReorder{} reorder := nl.TcNetemReorder{}
reorder.Probability = qdisc.ReorderProb reorder.Probability = qdisc.ReorderProb
reorder.Correlation = qdisc.ReorderCorr reorder.Correlation = qdisc.ReorderCorr
if reorder.Probability > 0 { if reorder.Probability > 0 {
nl.NewRtAttrChild(options, nl.TCA_NETEM_REORDER, reorder.Serialize()) options.AddRtAttr(nl.TCA_NETEM_REORDER, reorder.Serialize())
} }
case *Ingress: case *Ingress:
// ingress filters must use the proper handle // ingress filters must use the proper handle
@@ -237,46 +237,46 @@ func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
return fmt.Errorf("Ingress filters must set Parent to HANDLE_INGRESS") return fmt.Errorf("Ingress filters must set Parent to HANDLE_INGRESS")
} }
case *FqCodel: case *FqCodel:
nl.NewRtAttrChild(options, nl.TCA_FQ_CODEL_ECN, nl.Uint32Attr((uint32(qdisc.ECN)))) options.AddRtAttr(nl.TCA_FQ_CODEL_ECN, nl.Uint32Attr((uint32(qdisc.ECN))))
if qdisc.Limit > 0 { if qdisc.Limit > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_CODEL_LIMIT, nl.Uint32Attr((uint32(qdisc.Limit)))) options.AddRtAttr(nl.TCA_FQ_CODEL_LIMIT, nl.Uint32Attr((uint32(qdisc.Limit))))
} }
if qdisc.Interval > 0 { if qdisc.Interval > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_CODEL_INTERVAL, nl.Uint32Attr((uint32(qdisc.Interval)))) options.AddRtAttr(nl.TCA_FQ_CODEL_INTERVAL, nl.Uint32Attr((uint32(qdisc.Interval))))
} }
if qdisc.Flows > 0 { if qdisc.Flows > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_CODEL_FLOWS, nl.Uint32Attr((uint32(qdisc.Flows)))) options.AddRtAttr(nl.TCA_FQ_CODEL_FLOWS, nl.Uint32Attr((uint32(qdisc.Flows))))
} }
if qdisc.Quantum > 0 { if qdisc.Quantum > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_CODEL_QUANTUM, nl.Uint32Attr((uint32(qdisc.Quantum)))) options.AddRtAttr(nl.TCA_FQ_CODEL_QUANTUM, nl.Uint32Attr((uint32(qdisc.Quantum))))
} }
case *Fq: case *Fq:
nl.NewRtAttrChild(options, nl.TCA_FQ_RATE_ENABLE, nl.Uint32Attr((uint32(qdisc.Pacing)))) options.AddRtAttr(nl.TCA_FQ_RATE_ENABLE, nl.Uint32Attr((uint32(qdisc.Pacing))))
if qdisc.Buckets > 0 { if qdisc.Buckets > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_BUCKETS_LOG, nl.Uint32Attr((uint32(qdisc.Buckets)))) options.AddRtAttr(nl.TCA_FQ_BUCKETS_LOG, nl.Uint32Attr((uint32(qdisc.Buckets))))
} }
if qdisc.LowRateThreshold > 0 { if qdisc.LowRateThreshold > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_LOW_RATE_THRESHOLD, nl.Uint32Attr((uint32(qdisc.LowRateThreshold)))) options.AddRtAttr(nl.TCA_FQ_LOW_RATE_THRESHOLD, nl.Uint32Attr((uint32(qdisc.LowRateThreshold))))
} }
if qdisc.Quantum > 0 { if qdisc.Quantum > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_QUANTUM, nl.Uint32Attr((uint32(qdisc.Quantum)))) options.AddRtAttr(nl.TCA_FQ_QUANTUM, nl.Uint32Attr((uint32(qdisc.Quantum))))
} }
if qdisc.InitialQuantum > 0 { if qdisc.InitialQuantum > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_INITIAL_QUANTUM, nl.Uint32Attr((uint32(qdisc.InitialQuantum)))) options.AddRtAttr(nl.TCA_FQ_INITIAL_QUANTUM, nl.Uint32Attr((uint32(qdisc.InitialQuantum))))
} }
if qdisc.FlowRefillDelay > 0 { if qdisc.FlowRefillDelay > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_FLOW_REFILL_DELAY, nl.Uint32Attr((uint32(qdisc.FlowRefillDelay)))) options.AddRtAttr(nl.TCA_FQ_FLOW_REFILL_DELAY, nl.Uint32Attr((uint32(qdisc.FlowRefillDelay))))
} }
if qdisc.FlowPacketLimit > 0 { if qdisc.FlowPacketLimit > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_FLOW_PLIMIT, nl.Uint32Attr((uint32(qdisc.FlowPacketLimit)))) options.AddRtAttr(nl.TCA_FQ_FLOW_PLIMIT, nl.Uint32Attr((uint32(qdisc.FlowPacketLimit))))
} }
if qdisc.FlowMaxRate > 0 { if qdisc.FlowMaxRate > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_FLOW_MAX_RATE, nl.Uint32Attr((uint32(qdisc.FlowMaxRate)))) options.AddRtAttr(nl.TCA_FQ_FLOW_MAX_RATE, nl.Uint32Attr((uint32(qdisc.FlowMaxRate))))
} }
if qdisc.FlowDefaultRate > 0 { if qdisc.FlowDefaultRate > 0 {
nl.NewRtAttrChild(options, nl.TCA_FQ_FLOW_DEFAULT_RATE, nl.Uint32Attr((uint32(qdisc.FlowDefaultRate)))) options.AddRtAttr(nl.TCA_FQ_FLOW_DEFAULT_RATE, nl.Uint32Attr((uint32(qdisc.FlowDefaultRate))))
} }
default: default:
options = nil options = nil