protinfo.go 946 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package netlink
  2. import (
  3. "strings"
  4. )
  5. // Protinfo represents bridge flags from netlink.
  6. type Protinfo struct {
  7. Hairpin bool
  8. Guard bool
  9. FastLeave bool
  10. RootBlock bool
  11. Learning bool
  12. Flood bool
  13. }
  14. // String returns a list of enabled flags
  15. func (prot *Protinfo) String() string {
  16. var boolStrings []string
  17. if prot.Hairpin {
  18. boolStrings = append(boolStrings, "Hairpin")
  19. }
  20. if prot.Guard {
  21. boolStrings = append(boolStrings, "Guard")
  22. }
  23. if prot.FastLeave {
  24. boolStrings = append(boolStrings, "FastLeave")
  25. }
  26. if prot.RootBlock {
  27. boolStrings = append(boolStrings, "RootBlock")
  28. }
  29. if prot.Learning {
  30. boolStrings = append(boolStrings, "Learning")
  31. }
  32. if prot.Flood {
  33. boolStrings = append(boolStrings, "Flood")
  34. }
  35. return strings.Join(boolStrings, " ")
  36. }
  37. func boolToByte(x bool) []byte {
  38. if x {
  39. return []byte{1}
  40. }
  41. return []byte{0}
  42. }
  43. func byteToBool(x byte) bool {
  44. if uint8(x) != 0 {
  45. return true
  46. }
  47. return false
  48. }