protinfo.go 1.1 KB

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