Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | "os/exec" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 7 | "strings" |
| 8 | |
| 9 | "go.fd.io/govpp/binapi/ethernet_types" |
| 10 | "go.fd.io/govpp/binapi/interface_types" |
| 11 | "go.fd.io/govpp/binapi/ip_types" |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 12 | ) |
| 13 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 14 | type ( |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 15 | Cmd = exec.Cmd |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 16 | MacAddress = ethernet_types.MacAddress |
| 17 | AddressWithPrefix = ip_types.AddressWithPrefix |
| 18 | IP4AddressWithPrefix = ip_types.IP4AddressWithPrefix |
| 19 | InterfaceIndex = interface_types.InterfaceIndex |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 20 | |
| 21 | NetConfig interface { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 22 | configure() error |
| 23 | unconfigure() |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 24 | Name() string |
| 25 | Type() string |
| 26 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 27 | |
| 28 | NetConfigBase struct { |
| 29 | name string |
| 30 | category string // what else to call this when `type` is reserved? |
| 31 | } |
| 32 | |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 33 | NetInterface struct { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 34 | NetConfigBase |
Maros Ondrejicka | 300f70d | 2023-02-21 10:53:20 +0100 | [diff] [blame] | 35 | addresser *Addresser |
| 36 | ip4Address string // this will have form 10.10.10.1/24 |
| 37 | index InterfaceIndex |
| 38 | hwAddress MacAddress |
| 39 | networkNamespace string |
| 40 | networkNumber int |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 41 | peer *NetInterface |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | NetworkNamespace struct { |
| 45 | NetConfigBase |
| 46 | } |
| 47 | |
| 48 | NetworkBridge struct { |
| 49 | NetConfigBase |
| 50 | networkNamespace string |
| 51 | interfaces []string |
| 52 | } |
| 53 | ) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 54 | |
| 55 | const ( |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 56 | NetNs string = "netns" |
| 57 | Veth string = "veth" |
| 58 | Tap string = "tap" |
| 59 | Bridge string = "bridge" |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 60 | ) |
| 61 | |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 62 | type InterfaceAdder func(n *NetInterface) *Cmd |
| 63 | |
| 64 | var ( |
| 65 | ipCommandMap = map[string]InterfaceAdder{ |
| 66 | Veth: func(n *NetInterface) *Cmd { |
| 67 | return exec.Command("ip", "link", "add", n.name, "type", "veth", "peer", "name", n.peer.name) |
| 68 | }, |
| 69 | Tap: func(n *NetInterface) *Cmd { |
| 70 | return exec.Command("ip", "tuntap", "add", n.name, "mode", "tap") |
| 71 | }, |
| 72 | } |
| 73 | ) |
| 74 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 75 | func newNetworkInterface(cfg NetDevConfig, a *Addresser) (*NetInterface, error) { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 76 | var newInterface *NetInterface = &NetInterface{} |
| 77 | var err error |
| 78 | newInterface.addresser = a |
| 79 | newInterface.name = cfg["name"].(string) |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 80 | newInterface.networkNumber = DEFAULT_NETWORK_NUM |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 81 | |
| 82 | if interfaceType, ok := cfg["type"]; ok { |
| 83 | newInterface.category = interfaceType.(string) |
| 84 | } |
| 85 | |
| 86 | if presetHwAddress, ok := cfg["preset-hw-address"]; ok { |
| 87 | newInterface.hwAddress, err = ethernet_types.ParseMacAddress(presetHwAddress.(string)) |
| 88 | if err != nil { |
| 89 | return &NetInterface{}, err |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if netns, ok := cfg["netns"]; ok { |
| 94 | newInterface.networkNamespace = netns.(string) |
| 95 | } |
| 96 | |
| 97 | if ip, ok := cfg["ip4"]; ok { |
| 98 | if n, ok := ip.(NetDevConfig)["network"]; ok { |
| 99 | newInterface.networkNumber = n.(int) |
| 100 | } |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 101 | newInterface.ip4Address, err = newInterface.addresser.newIp4Address( |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 102 | newInterface.networkNumber, |
| 103 | ) |
| 104 | if err != nil { |
| 105 | return &NetInterface{}, err |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if _, ok := cfg["peer"]; !ok { |
| 110 | return newInterface, nil |
| 111 | } |
| 112 | |
| 113 | peer := cfg["peer"].(NetDevConfig) |
| 114 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 115 | if newInterface.peer, err = newNetworkInterface(peer, a); err != nil { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 116 | return &NetInterface{}, err |
| 117 | } |
| 118 | |
| 119 | return newInterface, nil |
| 120 | } |
| 121 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 122 | func (n *NetInterface) configureUpState() error { |
| 123 | err := setDevUp(n.Name(), "") |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 124 | if err != nil { |
| 125 | return fmt.Errorf("set link up failed: %v", err) |
| 126 | } |
| 127 | return nil |
| 128 | } |
| 129 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 130 | func (n *NetInterface) configureNetworkNamespace() error { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 131 | if n.networkNamespace != "" { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 132 | err := linkSetNetns(n.name, n.networkNamespace) |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 133 | if err != nil { |
| 134 | return err |
| 135 | } |
| 136 | } |
| 137 | return nil |
| 138 | } |
| 139 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 140 | func (n *NetInterface) configureAddress() error { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 141 | if n.ip4Address != "" { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 142 | if err := addAddress( |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 143 | n.Name(), |
| 144 | n.ip4Address, |
| 145 | n.networkNamespace, |
| 146 | ); err != nil { |
| 147 | return err |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | return nil |
| 152 | } |
| 153 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 154 | func (n *NetInterface) configure() error { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 155 | cmd := ipCommandMap[n.Type()](n) |
| 156 | _, err := cmd.CombinedOutput() |
| 157 | if err != nil { |
| 158 | return fmt.Errorf("creating interface '%v' failed: %v", n.Name(), err) |
| 159 | } |
| 160 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 161 | if err := n.configureUpState(); err != nil { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 162 | return err |
| 163 | } |
| 164 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 165 | if err := n.configureNetworkNamespace(); err != nil { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 166 | return err |
| 167 | } |
| 168 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 169 | if err := n.configureAddress(); err != nil { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 170 | return err |
| 171 | } |
| 172 | |
| 173 | if n.peer != nil && n.peer.name != "" { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 174 | if err := n.peer.configureUpState(); err != nil { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 175 | return err |
| 176 | } |
| 177 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 178 | if err := n.peer.configureNetworkNamespace(); err != nil { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 179 | return err |
| 180 | } |
| 181 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 182 | if err := n.peer.configureAddress(); err != nil { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 183 | return err |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return nil |
| 188 | } |
| 189 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 190 | func (n *NetInterface) unconfigure() { |
| 191 | delLink(n.name) |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | func (n *NetInterface) Name() string { |
| 195 | return n.name |
| 196 | } |
| 197 | |
| 198 | func (n *NetInterface) Type() string { |
| 199 | return n.category |
| 200 | } |
| 201 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 202 | func (n *NetInterface) addressWithPrefix() AddressWithPrefix { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 203 | address, _ := ip_types.ParseAddressWithPrefix(n.ip4Address) |
| 204 | return address |
| 205 | } |
| 206 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 207 | func (n *NetInterface) ip4AddressWithPrefix() IP4AddressWithPrefix { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 208 | ip4Prefix, _ := ip_types.ParseIP4Prefix(n.ip4Address) |
| 209 | ip4AddressWithPrefix := ip_types.IP4AddressWithPrefix(ip4Prefix) |
| 210 | return ip4AddressWithPrefix |
| 211 | } |
| 212 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 213 | func (n *NetInterface) ip4AddressString() string { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 214 | return strings.Split(n.ip4Address, "/")[0] |
| 215 | } |
| 216 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 217 | func (b *NetConfigBase) Name() string { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 218 | return b.name |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 221 | func (b *NetConfigBase) Type() string { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 222 | return b.category |
| 223 | } |
| 224 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 225 | func newNetNamespace(cfg NetDevConfig) (NetworkNamespace, error) { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 226 | var networkNamespace NetworkNamespace |
| 227 | networkNamespace.name = cfg["name"].(string) |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 228 | networkNamespace.category = NetNs |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 229 | return networkNamespace, nil |
| 230 | } |
| 231 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 232 | func (ns *NetworkNamespace) configure() error { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 233 | return addDelNetns(ns.name, true) |
| 234 | } |
| 235 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 236 | func (ns *NetworkNamespace) unconfigure() { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 237 | addDelNetns(ns.name, false) |
| 238 | } |
| 239 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 240 | func newBridge(cfg NetDevConfig) (NetworkBridge, error) { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 241 | var bridge NetworkBridge |
| 242 | bridge.name = cfg["name"].(string) |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 243 | bridge.category = Bridge |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 244 | for _, v := range cfg["interfaces"].([]interface{}) { |
| 245 | bridge.interfaces = append(bridge.interfaces, v.(string)) |
| 246 | } |
Maros Ondrejicka | 300f70d | 2023-02-21 10:53:20 +0100 | [diff] [blame] | 247 | |
| 248 | bridge.networkNamespace = "" |
| 249 | if netns, ok := cfg["netns"]; ok { |
| 250 | bridge.networkNamespace = netns.(string) |
| 251 | } |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 252 | return bridge, nil |
| 253 | } |
| 254 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 255 | func (b *NetworkBridge) configure() error { |
| 256 | return addBridge(b.name, b.interfaces, b.networkNamespace) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 259 | func (b *NetworkBridge) unconfigure() { |
| 260 | delBridge(b.name, b.networkNamespace) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 263 | func delBridge(brName, ns string) error { |
| 264 | err := setDevDown(brName, ns) |
Maros Ondrejicka | b5c7317 | 2023-03-01 09:43:24 +0100 | [diff] [blame] | 265 | if err != nil { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 266 | return err |
| 267 | } |
| 268 | |
| 269 | err = addDelBridge(brName, ns, false) |
| 270 | if err != nil { |
| 271 | return err |
| 272 | } |
| 273 | |
| 274 | return nil |
| 275 | } |
| 276 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 277 | func setDevUp(dev, ns string) error { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 278 | return setDevUpDown(dev, ns, true) |
| 279 | } |
| 280 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 281 | func setDevDown(dev, ns string) error { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 282 | return setDevUpDown(dev, ns, false) |
| 283 | } |
| 284 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 285 | func delLink(ifName string) { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 286 | cmd := exec.Command("ip", "link", "del", ifName) |
| 287 | cmd.Run() |
| 288 | } |
| 289 | |
| 290 | func setDevUpDown(dev, ns string, isUp bool) error { |
| 291 | var op string |
| 292 | if isUp { |
| 293 | op = "up" |
| 294 | } else { |
| 295 | op = "down" |
| 296 | } |
| 297 | c := []string{"ip", "link", "set", "dev", dev, op} |
| 298 | cmd := appendNetns(c, ns) |
| 299 | err := cmd.Run() |
| 300 | if err != nil { |
| 301 | s := fmt.Sprintf("error bringing %s device %s!", dev, op) |
| 302 | return errors.New(s) |
| 303 | } |
| 304 | return nil |
| 305 | } |
| 306 | |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 307 | func addDelNetns(name string, isAdd bool) error { |
| 308 | var op string |
| 309 | if isAdd { |
| 310 | op = "add" |
| 311 | } else { |
| 312 | op = "del" |
| 313 | } |
| 314 | cmd := exec.Command("ip", "netns", op, name) |
| 315 | _, err := cmd.CombinedOutput() |
| 316 | if err != nil { |
| 317 | return errors.New("add/del netns failed") |
| 318 | } |
| 319 | return nil |
| 320 | } |
| 321 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 322 | func linkSetNetns(ifName, ns string) error { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 323 | cmd := exec.Command("ip", "link", "set", "dev", ifName, "up", "netns", ns) |
| 324 | err := cmd.Run() |
| 325 | if err != nil { |
| 326 | return fmt.Errorf("error setting device '%s' to netns '%s: %v", ifName, ns, err) |
| 327 | } |
| 328 | return nil |
| 329 | } |
| 330 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 331 | func newCommand(s []string, ns string) *exec.Cmd { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 332 | return appendNetns(s, ns) |
| 333 | } |
| 334 | |
| 335 | func appendNetns(s []string, ns string) *exec.Cmd { |
| 336 | var cmd *exec.Cmd |
| 337 | if ns == "" { |
| 338 | // use default namespace |
| 339 | cmd = exec.Command(s[0], s[1:]...) |
| 340 | } else { |
| 341 | var args = []string{"netns", "exec", ns} |
| 342 | args = append(args, s[:]...) |
| 343 | cmd = exec.Command("ip", args...) |
| 344 | } |
| 345 | return cmd |
| 346 | } |
| 347 | |
| 348 | func addDelBridge(brName, ns string, isAdd bool) error { |
| 349 | var op string |
| 350 | if isAdd { |
| 351 | op = "addbr" |
| 352 | } else { |
| 353 | op = "delbr" |
| 354 | } |
| 355 | var c = []string{"brctl", op, brName} |
| 356 | cmd := appendNetns(c, ns) |
| 357 | err := cmd.Run() |
| 358 | if err != nil { |
| 359 | s := fmt.Sprintf("%s %s failed!", op, brName) |
| 360 | return errors.New(s) |
| 361 | } |
| 362 | return nil |
| 363 | } |
| 364 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 365 | func addBridge(brName string, ifs []string, ns string) error { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 366 | err := addDelBridge(brName, ns, true) |
| 367 | if err != nil { |
| 368 | return err |
| 369 | } |
| 370 | |
| 371 | for _, v := range ifs { |
| 372 | c := []string{"brctl", "addif", brName, v} |
| 373 | cmd := appendNetns(c, ns) |
| 374 | err = cmd.Run() |
| 375 | if err != nil { |
| 376 | s := fmt.Sprintf("error adding %s to bridge %s: %v", v, brName, err) |
| 377 | return errors.New(s) |
| 378 | } |
| 379 | } |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 380 | err = setDevUp(brName, ns) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 381 | if err != nil { |
| 382 | return err |
| 383 | } |
| 384 | return nil |
| 385 | } |