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