options_linux.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // WithIsBridge sets whether the interface is a bridge.
  23. func WithIsBridge(isBridge bool) IfaceOption {
  24. return func(i *Interface) error {
  25. i.bridge = isBridge
  26. return nil
  27. }
  28. }
  29. // WithMaster sets the master interface (if any) for this interface. The
  30. // master interface name should refer to the srcName of a previously added
  31. // interface of type bridge.
  32. func WithMaster(name string) IfaceOption {
  33. return func(i *Interface) error {
  34. i.master = name
  35. return nil
  36. }
  37. }
  38. // WithMACAddress sets the interface MAC-address.
  39. func WithMACAddress(mac net.HardwareAddr) IfaceOption {
  40. return func(i *Interface) error {
  41. i.mac = mac
  42. return nil
  43. }
  44. }
  45. // WithIPv4Address sets the IPv4 address of the interface.
  46. func WithIPv4Address(addr *net.IPNet) IfaceOption {
  47. return func(i *Interface) error {
  48. i.address = addr
  49. return nil
  50. }
  51. }
  52. // WithIPv6Address sets the IPv6 address of the interface.
  53. func WithIPv6Address(addr *net.IPNet) IfaceOption {
  54. return func(i *Interface) error {
  55. i.addressIPv6 = addr
  56. return nil
  57. }
  58. }
  59. // WithLinkLocalAddresses set the link-local IP addresses of the interface.
  60. func WithLinkLocalAddresses(list []*net.IPNet) IfaceOption {
  61. return func(i *Interface) error {
  62. i.llAddrs = list
  63. return nil
  64. }
  65. }
  66. // WithRoutes sets the interface routes.
  67. func WithRoutes(routes []*net.IPNet) IfaceOption {
  68. return func(i *Interface) error {
  69. i.routes = routes
  70. return nil
  71. }
  72. }