createVethPair creates a veth pair with the given names.
(parentVethName, peerVethName string, options ...linkOption)
| 685 | |
| 686 | // createVethPair creates a veth pair with the given names. |
| 687 | func createVethPair(parentVethName, peerVethName string, options ...linkOption) error { |
| 688 | linkAttrs := netlink.NewLinkAttrs() |
| 689 | linkAttrs.Name = parentVethName |
| 690 | for _, option := range options { |
| 691 | linkAttrs = option(linkAttrs) |
| 692 | } |
| 693 | veth := &netlink.Veth{ |
| 694 | LinkAttrs: linkAttrs, |
| 695 | PeerName: peerVethName, |
| 696 | } |
| 697 | |
| 698 | err := netlink.LinkAdd(veth) |
| 699 | if err != nil { |
| 700 | return xerrors.Errorf("LinkAdd(type: veth, name: %q, peerName: %q): %w", parentVethName, peerVethName, err) |
| 701 | } |
| 702 | |
| 703 | return nil |
| 704 | } |
| 705 | |
| 706 | // setVethNetNS moves the veth interface to the specified network namespace. |
| 707 | func setVethNetNS(vethName string, netNSFd int) error { |
no test coverage detected