(n *opts.NetworkAttachmentOpts, copts *containerOptions)
| 815 | } |
| 816 | |
| 817 | func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOptions) error { //nolint:gocyclo |
| 818 | // TODO should we error if _any_ advanced option is used? (i.e. forbid to combine advanced notation with the "old" flags (`--network-alias`, `--link`, `--ip`, `--ip6`)? |
| 819 | if len(n.Aliases) > 0 && copts.aliases.Len() > 0 { |
| 820 | return errors.New("conflicting options: cannot specify both --network-alias and per-network alias") |
| 821 | } |
| 822 | if len(n.Links) > 0 && copts.links.Len() > 0 { |
| 823 | return errors.New("conflicting options: cannot specify both --link and per-network links") |
| 824 | } |
| 825 | if n.IPv4Address.IsValid() && copts.ipv4Address != nil { |
| 826 | return errors.New("conflicting options: cannot specify both --ip and per-network IPv4 address") |
| 827 | } |
| 828 | if n.IPv6Address.IsValid() && copts.ipv6Address != nil { |
| 829 | return errors.New("conflicting options: cannot specify both --ip6 and per-network IPv6 address") |
| 830 | } |
| 831 | if n.MacAddress != "" && copts.macAddress != "" { |
| 832 | return errors.New("conflicting options: cannot specify both --mac-address and per-network MAC address") |
| 833 | } |
| 834 | if len(n.LinkLocalIPs) > 0 && copts.linkLocalIPs.Len() > 0 { |
| 835 | return errors.New("conflicting options: cannot specify both --link-local-ip and per-network link-local IP addresses") |
| 836 | } |
| 837 | if copts.aliases.Len() > 0 { |
| 838 | n.Aliases = make([]string, copts.aliases.Len()) |
| 839 | copy(n.Aliases, copts.aliases.GetSlice()) |
| 840 | } |
| 841 | // For a user-defined network, "--link" is an endpoint option, it creates an alias. But, |
| 842 | // for the default bridge it defines a legacy-link. |
| 843 | if container.NetworkMode(n.Target).IsUserDefined() && copts.links.Len() > 0 { |
| 844 | n.Links = make([]string, copts.links.Len()) |
| 845 | copy(n.Links, copts.links.GetSlice()) |
| 846 | } |
| 847 | if copts.ipv4Address != nil { |
| 848 | if ipv4, ok := netip.AddrFromSlice(copts.ipv4Address.To4()); ok { |
| 849 | n.IPv4Address = ipv4 |
| 850 | } |
| 851 | } |
| 852 | if copts.ipv6Address != nil { |
| 853 | if ipv6, ok := netip.AddrFromSlice(copts.ipv6Address.To16()); ok { |
| 854 | n.IPv6Address = ipv6 |
| 855 | } |
| 856 | } |
| 857 | if copts.macAddress != "" { |
| 858 | n.MacAddress = copts.macAddress |
| 859 | } |
| 860 | if copts.linkLocalIPs.Len() > 0 { |
| 861 | n.LinkLocalIPs = toNetipAddrSlice(copts.linkLocalIPs.GetSlice()) |
| 862 | } |
| 863 | return nil |
| 864 | } |
| 865 | |
| 866 | func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.EndpointSettings, error) { |
| 867 | if strings.TrimSpace(ep.Target) == "" { |
no test coverage detected
searching dependent graphs…