options_linux.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // LinkName returns an option setter to set the srcName of the link that should
  11. // be used in the neighbor entry
  12. func (n *networkNamespace) LinkName(name string) NeighOption {
  13. return func(nh *neigh) {
  14. nh.linkName = name
  15. }
  16. }
  17. // Family returns an option setter to set the address family for the neighbor
  18. // entry. eg. AF_BRIDGE
  19. func (n *networkNamespace) Family(family int) NeighOption {
  20. return func(nh *neigh) {
  21. nh.family = family
  22. }
  23. }
  24. func (i *nwIface) processInterfaceOptions(options ...IfaceOption) {
  25. for _, opt := range options {
  26. if opt != nil {
  27. opt(i)
  28. }
  29. }
  30. }
  31. // Bridge returns an option setter to set if the interface is a bridge.
  32. func (n *networkNamespace) Bridge(isBridge bool) IfaceOption {
  33. return func(i *nwIface) {
  34. i.bridge = isBridge
  35. }
  36. }
  37. // Master returns an option setter to set the master interface if any for this
  38. // interface. The master interface name should refer to the srcname of a
  39. // previously added interface of type bridge.
  40. func (n *networkNamespace) Master(name string) IfaceOption {
  41. return func(i *nwIface) {
  42. i.master = name
  43. }
  44. }
  45. // MacAddress returns an option setter to set the MAC address.
  46. func (n *networkNamespace) MacAddress(mac net.HardwareAddr) IfaceOption {
  47. return func(i *nwIface) {
  48. i.mac = mac
  49. }
  50. }
  51. // Address returns an option setter to set IPv4 address.
  52. func (n *networkNamespace) Address(addr *net.IPNet) IfaceOption {
  53. return func(i *nwIface) {
  54. i.address = addr
  55. }
  56. }
  57. // AddressIPv6 returns an option setter to set IPv6 address.
  58. func (n *networkNamespace) AddressIPv6(addr *net.IPNet) IfaceOption {
  59. return func(i *nwIface) {
  60. i.addressIPv6 = addr
  61. }
  62. }
  63. // LinkLocalAddresses returns an option setter to set the link-local IP addresses.
  64. func (n *networkNamespace) LinkLocalAddresses(list []*net.IPNet) IfaceOption {
  65. return func(i *nwIface) {
  66. i.llAddrs = list
  67. }
  68. }
  69. // Routes returns an option setter to set interface routes.
  70. func (n *networkNamespace) Routes(routes []*net.IPNet) IfaceOption {
  71. return func(i *nwIface) {
  72. i.routes = routes
  73. }
  74. }