github.com/sagernet/netlink@v0.0.0-20240612041022-b9a21c07ac6a/protinfo.go (about)

     1  package netlink
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // Protinfo represents bridge flags from netlink.
     8  type 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
    20  func (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  
    53  func boolToByte(x bool) []byte {
    54  	if x {
    55  		return []byte{1}
    56  	}
    57  	return []byte{0}
    58  }
    59  
    60  func byteToBool(x byte) bool {
    61  	return uint8(x) != 0
    62  }