github.com/sagernet/netlink@v0.0.0-20240612041022-b9a21c07ac6a/nl/bridge_linux.go (about) 1 package nl 2 3 import ( 4 "fmt" 5 "unsafe" 6 ) 7 8 const ( 9 SizeofBridgeVlanInfo = 0x04 10 ) 11 12 /* Bridge Flags */ 13 const ( 14 BRIDGE_FLAGS_MASTER = iota + 1 /* Bridge command to/from master */ 15 BRIDGE_FLAGS_SELF /* Bridge command to/from lowerdev */ 16 ) 17 18 /* Bridge management nested attributes 19 * [IFLA_AF_SPEC] = { 20 * [IFLA_BRIDGE_FLAGS] 21 * [IFLA_BRIDGE_MODE] 22 * [IFLA_BRIDGE_VLAN_INFO] 23 * } 24 */ 25 const ( 26 IFLA_BRIDGE_FLAGS = iota 27 IFLA_BRIDGE_MODE 28 IFLA_BRIDGE_VLAN_INFO 29 ) 30 31 const ( 32 BRIDGE_VLAN_INFO_MASTER = 1 << iota 33 BRIDGE_VLAN_INFO_PVID 34 BRIDGE_VLAN_INFO_UNTAGGED 35 BRIDGE_VLAN_INFO_RANGE_BEGIN 36 BRIDGE_VLAN_INFO_RANGE_END 37 ) 38 39 // struct bridge_vlan_info { 40 // __u16 flags; 41 // __u16 vid; 42 // }; 43 44 type BridgeVlanInfo struct { 45 Flags uint16 46 Vid uint16 47 } 48 49 func (b *BridgeVlanInfo) Serialize() []byte { 50 return (*(*[SizeofBridgeVlanInfo]byte)(unsafe.Pointer(b)))[:] 51 } 52 53 func DeserializeBridgeVlanInfo(b []byte) *BridgeVlanInfo { 54 return (*BridgeVlanInfo)(unsafe.Pointer(&b[0:SizeofBridgeVlanInfo][0])) 55 } 56 57 func (b *BridgeVlanInfo) PortVID() bool { 58 return b.Flags&BRIDGE_VLAN_INFO_PVID > 0 59 } 60 61 func (b *BridgeVlanInfo) EngressUntag() bool { 62 return b.Flags&BRIDGE_VLAN_INFO_UNTAGGED > 0 63 } 64 65 func (b *BridgeVlanInfo) String() string { 66 return fmt.Sprintf("%+v", *b) 67 } 68 69 /* New extended info filters for IFLA_EXT_MASK */ 70 const ( 71 RTEXT_FILTER_VF = 1 << iota 72 RTEXT_FILTER_BRVLAN 73 RTEXT_FILTER_BRVLAN_COMPRESSED 74 )