( t *testing.T, ns *namespaceFixture, iface string, clientPrivateKey string, clientWGIP string, serverPublicKey string, serverEndpointPort int, serverWGIP string, )
| 287 | } |
| 288 | |
| 289 | func configureNamespaceWGClient( |
| 290 | t *testing.T, |
| 291 | ns *namespaceFixture, |
| 292 | iface string, |
| 293 | clientPrivateKey string, |
| 294 | clientWGIP string, |
| 295 | serverPublicKey string, |
| 296 | serverEndpointPort int, |
| 297 | serverWGIP string, |
| 298 | ) { |
| 299 | t.Helper() |
| 300 | |
| 301 | keyFile, err := os.CreateTemp("", "wg-client-key-*") |
| 302 | if err != nil { |
| 303 | t.Fatalf("failed to create temp key file: %v", err) |
| 304 | } |
| 305 | if _, err = keyFile.WriteString(clientPrivateKey + "\n"); err != nil { |
| 306 | _ = keyFile.Close() |
| 307 | t.Fatalf("failed to write temp key file: %v", err) |
| 308 | } |
| 309 | if err = keyFile.Close(); err != nil { |
| 310 | t.Fatalf("failed to close temp key file: %v", err) |
| 311 | } |
| 312 | t.Cleanup(func() { |
| 313 | _ = os.Remove(keyFile.Name()) |
| 314 | }) |
| 315 | |
| 316 | runCommand(t, "ip", "netns", "exec", ns.name, "ip", "link", "add", "dev", iface, "type", "wireguard") |
| 317 | runCommand(t, "ip", "netns", "exec", ns.name, "ip", "address", "add", clientWGIP+"/32", "dev", iface) |
| 318 | |
| 319 | endpoint := fmt.Sprintf("%s:%d", ns.hostTransitIP, serverEndpointPort) |
| 320 | runCommand( |
| 321 | t, |
| 322 | "ip", "netns", "exec", ns.name, |
| 323 | "wg", "set", iface, |
| 324 | "private-key", keyFile.Name(), |
| 325 | "peer", serverPublicKey, |
| 326 | "endpoint", endpoint, |
| 327 | "allowed-ips", serverWGIP+"/32", |
| 328 | ) |
| 329 | |
| 330 | runCommand(t, "ip", "netns", "exec", ns.name, "ip", "link", "set", "up", "dev", iface) |
| 331 | runCommand(t, "ip", "netns", "exec", ns.name, "ip", "route", "replace", serverWGIP+"/32", "dev", iface) |
| 332 | } |
| 333 | |
| 334 | func configureNamespaceWGClientDualStack( |
| 335 | t *testing.T, |
no test coverage detected