createBridge creates a bridge in the given network namespace. The bridge is automatically brought up.
(netNS *os.File, name string)
| 647 | // createBridge creates a bridge in the given network namespace. The bridge is |
| 648 | // automatically brought up. |
| 649 | func createBridge(netNS *os.File, name string) error { |
| 650 | // While it might be possible to create a bridge directly in a NetNS or move |
| 651 | // an existing bridge to a NetNS, I couldn't figure out a way to do it. |
| 652 | // Creating it directly within the NetNS is the simplest way. |
| 653 | _, err := commandInNetNS(netNS, "ip", []string{"link", "add", name, "type", "bridge"}).Output() |
| 654 | if err != nil { |
| 655 | return xerrors.Errorf("create bridge %q in netns: %w", name, wrapExitErr(err)) |
| 656 | } |
| 657 | |
| 658 | _, err = commandInNetNS(netNS, "ip", []string{"link", "set", name, "up"}).Output() |
| 659 | if err != nil { |
| 660 | return xerrors.Errorf("set bridge %q up in netns: %w", name, wrapExitErr(err)) |
| 661 | } |
| 662 | |
| 663 | return nil |
| 664 | } |
| 665 | |
| 666 | // setInterfaceBridge sets the master of the given interface to the specified |
| 667 | // bridge. |
no test coverage detected