options_linux.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package osl
  2. import "net"
  3. func (nh *neigh) processNeighOptions(options ...NeighOption) {
  4. for _, opt := range options {
  5. if opt != nil {
  6. opt(nh)
  7. }
  8. }
  9. }
  10. // WithLinkName sets the srcName of the link to use in the neighbor entry.
  11. func WithLinkName(name string) NeighOption {
  12. return func(nh *neigh) {
  13. nh.linkName = name
  14. }
  15. }
  16. // WithFamily sets the address-family for the neighbor entry. e.g. [syscall.AF_BRIDGE].
  17. func WithFamily(family int) NeighOption {
  18. return func(nh *neigh) {
  19. nh.family = family
  20. }
  21. }
  22. func (i *nwIface) processInterfaceOptions(options ...IfaceOption) error {
  23. for _, opt := range options {
  24. if opt != nil {
  25. // TODO(thaJeztah): use multi-error instead of returning early.
  26. if err := opt(i); err != nil {
  27. return err
  28. }
  29. }
  30. }
  31. return nil
  32. }
  33. // WithIsBridge sets whether the interface is a bridge.
  34. func WithIsBridge(isBridge bool) IfaceOption {
  35. return func(i *nwIface) error {
  36. i.bridge = isBridge
  37. return nil
  38. }
  39. }
  40. // WithMaster sets the master interface (if any) for this interface. The
  41. // master interface name should refer to the srcName of a previously added
  42. // interface of type bridge.
  43. func WithMaster(name string) IfaceOption {
  44. return func(i *nwIface) error {
  45. i.master = name
  46. return nil
  47. }
  48. }
  49. // WithMACAddress sets the interface MAC-address.
  50. func WithMACAddress(mac net.HardwareAddr) IfaceOption {
  51. return func(i *nwIface) error {
  52. i.mac = mac
  53. return nil
  54. }
  55. }
  56. // WithIPv4Address sets the IPv4 address of the interface.
  57. func WithIPv4Address(addr *net.IPNet) IfaceOption {
  58. return func(i *nwIface) error {
  59. i.address = addr
  60. return nil
  61. }
  62. }
  63. // WithIPv6Address sets the IPv6 address of the interface.
  64. func WithIPv6Address(addr *net.IPNet) IfaceOption {
  65. return func(i *nwIface) error {
  66. i.addressIPv6 = addr
  67. return nil
  68. }
  69. }
  70. // WithLinkLocalAddresses set the link-local IP addresses of the interface.
  71. func WithLinkLocalAddresses(list []*net.IPNet) IfaceOption {
  72. return func(i *nwIface) error {
  73. i.llAddrs = list
  74. return nil
  75. }
  76. }
  77. // WithRoutes sets the interface routes.
  78. func WithRoutes(routes []*net.IPNet) IfaceOption {
  79. return func(i *nwIface) error {
  80. i.routes = routes
  81. return nil
  82. }
  83. }