in cni/cni.go [307:362]
func (config *NetworkConfig) GetEndpointInfo(
networkInfo *network.NetworkInfo,
containerID string, netNs string) (*network.EndpointInfo, error) {
containerIDToUse := containerID
epInfo := &network.EndpointInfo{
Name: containerIDToUse + "_" + networkInfo.ID,
NetworkID: networkInfo.ID,
NamespaceID: netNs,
ContainerID: containerID,
}
epInfo.DNS = network.DNSInfo{
Domain: networkInfo.DNS.Domain,
Nameservers: networkInfo.DNS.Nameservers,
Search: networkInfo.DNS.Search,
Options: networkInfo.DNS.Options,
}
if len(networkInfo.Subnets) > 0 {
// This subnet is not used when constructing
// hcn.HostComputeEndpoint from EndpointInfo
epInfo.Subnet = networkInfo.Subnets[0].AddressPrefix
// Gateway field (below) will be updated to the ipam allocated value
// (if applicable) in allocateIpam
// The Gateway6 field (ipv6 gateway) is not derived like this and
// must be supplied through the ipam.
epInfo.Gateway = networkInfo.Subnets[0].GatewayAddress
}
runtimeConf := config.RuntimeConfig
logrus.Debugf("Parsing port mappings from %+v", runtimeConf.PortMappings)
flags := uint32(0)
if config.OptionalFlags.LocalRoutePortMapping {
flags = 1
}
var aclPriority uint16 = 1000
for _, mapping := range runtimeConf.PortMappings {
policy, err := network.GetPortMappingPolicy(mapping.HostPort, mapping.ContainerPort, mapping.Protocol, mapping.HostIp, flags)
if err != nil {
return nil, fmt.Errorf("failed during GetEndpointInfo from netconf: %v", err)
}
logrus.Debugf("Created raw policy from mapping: %+v --- %+v", mapping, policy)
epInfo.Policies = append(epInfo.Policies, policy)
if config.OptionalFlags.AllowAclPortMapping {
pol, err := getInACLRule(&mapping, aclPriority)
if err != nil {
return nil, fmt.Errorf("failed getInACLRule: %v", err)
}
epInfo.Policies = append(epInfo.Policies, *pol)
}
}
return epInfo, nil
}