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