| 383 | } |
| 384 | |
| 385 | func createEndpointSettings(p *types.Project, service types.ServiceConfig, serviceIndex int, networkKey string, links []string, useNetworkAliases bool) (*network.EndpointSettings, error) { |
| 386 | const ifname = "com.docker.network.endpoint.ifname" |
| 387 | |
| 388 | config := service.Networks[networkKey] |
| 389 | var ipam *network.EndpointIPAMConfig |
| 390 | var ( |
| 391 | ipv4Address netip.Addr |
| 392 | ipv6Address netip.Addr |
| 393 | macAddress string |
| 394 | driverOpts types.Options |
| 395 | gwPriority int |
| 396 | ) |
| 397 | if config != nil { |
| 398 | var err error |
| 399 | if config.Ipv4Address != "" { |
| 400 | ipv4Address, err = netip.ParseAddr(config.Ipv4Address) |
| 401 | if err != nil { |
| 402 | return nil, fmt.Errorf("invalid IPv4 address: %w", err) |
| 403 | } |
| 404 | } |
| 405 | if config.Ipv6Address != "" { |
| 406 | ipv6Address, err = netip.ParseAddr(config.Ipv6Address) |
| 407 | if err != nil { |
| 408 | return nil, fmt.Errorf("invalid IPv6 address: %w", err) |
| 409 | } |
| 410 | } |
| 411 | var linkLocalIPs []netip.Addr |
| 412 | for _, link := range config.LinkLocalIPs { |
| 413 | if link == "" { |
| 414 | continue |
| 415 | } |
| 416 | llIP, err := netip.ParseAddr(link) |
| 417 | if err != nil { |
| 418 | return nil, fmt.Errorf("invalid link-local IP: %w", err) |
| 419 | } |
| 420 | linkLocalIPs = append(linkLocalIPs, llIP) |
| 421 | } |
| 422 | |
| 423 | ipam = &network.EndpointIPAMConfig{ |
| 424 | IPv4Address: ipv4Address.Unmap(), |
| 425 | IPv6Address: ipv6Address, |
| 426 | LinkLocalIPs: linkLocalIPs, |
| 427 | } |
| 428 | macAddress = config.MacAddress |
| 429 | driverOpts = config.DriverOpts |
| 430 | if config.InterfaceName != "" { |
| 431 | if driverOpts == nil { |
| 432 | driverOpts = map[string]string{} |
| 433 | } |
| 434 | if name, ok := driverOpts[ifname]; ok && name != config.InterfaceName { |
| 435 | logrus.Warnf("ignoring services.%s.networks.%s.interface_name as %s driver_opts is already declared", service.Name, networkKey, ifname) |
| 436 | } |
| 437 | driverOpts[ifname] = config.InterfaceName |
| 438 | } |
| 439 | gwPriority = config.GatewayPriority |
| 440 | } |
| 441 | var ma network.HardwareAddr |
| 442 | if macAddress != "" { |