Skip to content

Commit

Permalink
use netlink functions
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl committed Nov 16, 2024
1 parent 485e89f commit 5012c1b
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions nest.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,19 @@ func marshalAttributes(options []tcOption) ([]byte, error) {
case vtFlag:
ad.Flag(option.Type, true)
case vtInt8:
data := bytes.NewBuffer(make([]byte, 0, 1))
err := binary.Write(data, nativeEndian, (option.Data).(int8))
multiError = concatError(multiError, err)
ad.Bytes(option.Type, data.Bytes())
ad.Int8(option.Type, (option.Data).(int8))
case vtInt16:
data := bytes.NewBuffer(make([]byte, 0, 2))
err := binary.Write(data, nativeEndian, (option.Data).(int16))
multiError = concatError(multiError, err)
ad.Bytes(option.Type, data.Bytes())
ad.Int16(option.Type, (option.Data).(int16))
case vtInt32:
data := bytes.NewBuffer(make([]byte, 0, 4))
err := binary.Write(data, nativeEndian, (option.Data).(int32))
multiError = concatError(multiError, err)
ad.Bytes(option.Type, data.Bytes())
ad.Int32(option.Type, (option.Data).(int32))
case vtInt64:
data := bytes.NewBuffer(make([]byte, 0, 8))
err := binary.Write(data, nativeEndian, (option.Data).(int64))
multiError = concatError(multiError, err)
ad.Bytes(option.Type, data.Bytes())
ad.Int64(option.Type, (option.Data).(int64))
case vtUint16Be:
data := bytes.NewBuffer(make([]byte, 0, 2))
err := binary.Write(data, binary.BigEndian, (option.Data).(uint16))
multiError = concatError(multiError, err)
ad.Bytes(option.Type, data.Bytes())
ad.Uint16(option.Type, endianSwapUint16((option.Data).(uint16)))
case vtUint32Be:
data := bytes.NewBuffer(make([]byte, 0, 4))
err := binary.Write(data, binary.BigEndian, (option.Data).(uint32))
multiError = concatError(multiError, err)
ad.Bytes(option.Type, data.Bytes())
ad.Uint32(option.Type, endianSwapUint32((option.Data).(uint32)))
case vtInt16Be:
data := bytes.NewBuffer(make([]byte, 0, 2))
err := binary.Write(data, binary.BigEndian, (option.Data).(int16))
multiError = concatError(multiError, err)
ad.Bytes(option.Type, data.Bytes())
ad.Uint16(option.Type, endianSwapUint16(uint16((option.Data).(int16))))
default:
multiError = fmt.Errorf("unknown interpretation (%d)", option.Interpretation)
}
Expand Down

0 comments on commit 5012c1b

Please sign in to comment.