bridge_linux.go 1.4 KB

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