protinfo.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. ProxyArp bool
  14. ProxyArpWiFi bool
  15. Isolated bool
  16. NeighSuppress bool
  17. VlanTunnel bool
  18. }
  19. // String returns a list of enabled flags
  20. func (prot *Protinfo) String() string {
  21. if prot == nil {
  22. return "<nil>"
  23. }
  24. var boolStrings []string
  25. if prot.Hairpin {
  26. boolStrings = append(boolStrings, "Hairpin")
  27. }
  28. if prot.Guard {
  29. boolStrings = append(boolStrings, "Guard")
  30. }
  31. if prot.FastLeave {
  32. boolStrings = append(boolStrings, "FastLeave")
  33. }
  34. if prot.RootBlock {
  35. boolStrings = append(boolStrings, "RootBlock")
  36. }
  37. if prot.Learning {
  38. boolStrings = append(boolStrings, "Learning")
  39. }
  40. if prot.Flood {
  41. boolStrings = append(boolStrings, "Flood")
  42. }
  43. if prot.ProxyArp {
  44. boolStrings = append(boolStrings, "ProxyArp")
  45. }
  46. if prot.ProxyArpWiFi {
  47. boolStrings = append(boolStrings, "ProxyArpWiFi")
  48. }
  49. if prot.Isolated {
  50. boolStrings = append(boolStrings, "Isolated")
  51. }
  52. if prot.NeighSuppress {
  53. boolStrings = append(boolStrings, "NeighSuppress")
  54. }
  55. if prot.VlanTunnel {
  56. boolStrings = append(boolStrings, "VlanTunnel")
  57. }
  58. return strings.Join(boolStrings, " ")
  59. }
  60. func boolToByte(x bool) []byte {
  61. if x {
  62. return []byte{1}
  63. }
  64. return []byte{0}
  65. }
  66. func byteToBool(x byte) bool {
  67. return uint8(x) != 0
  68. }