rt.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2018 Google LLC. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package expr
  15. import (
  16. "fmt"
  17. "github.com/google/nftables/binaryutil"
  18. "github.com/mdlayher/netlink"
  19. "golang.org/x/sys/unix"
  20. )
  21. type RtKey uint32
  22. const (
  23. RtClassid RtKey = unix.NFT_RT_CLASSID
  24. RtNexthop4 RtKey = unix.NFT_RT_NEXTHOP4
  25. RtNexthop6 RtKey = unix.NFT_RT_NEXTHOP6
  26. RtTCPMSS RtKey = unix.NFT_RT_TCPMSS
  27. )
  28. type Rt struct {
  29. Register uint32
  30. Key RtKey
  31. }
  32. func (e *Rt) marshal(fam byte) ([]byte, error) {
  33. data, err := netlink.MarshalAttributes([]netlink.Attribute{
  34. {Type: unix.NFTA_RT_KEY, Data: binaryutil.BigEndian.PutUint32(uint32(e.Key))},
  35. {Type: unix.NFTA_RT_DREG, Data: binaryutil.BigEndian.PutUint32(e.Register)},
  36. })
  37. if err != nil {
  38. return nil, err
  39. }
  40. return netlink.MarshalAttributes([]netlink.Attribute{
  41. {Type: unix.NFTA_EXPR_NAME, Data: []byte("rt\x00")},
  42. {Type: unix.NLA_F_NESTED | unix.NFTA_EXPR_DATA, Data: data},
  43. })
  44. }
  45. func (e *Rt) unmarshal(fam byte, data []byte) error {
  46. return fmt.Errorf("not yet implemented")
  47. }