// ClosePortOnSubnet closes the given port and protocol for the unit on the given
// subnet, which can be empty. When non-empty, subnetID must refer to an
// existing, alive subnet, otherwise an error is returned.
3224
func (u *Unit) ClosePortOnSubnet(subnetID, protocol string, number int) error {
	return u.ClosePortsOnSubnet(subnetID, protocol, number, number)
}
133908
func (e *Environ) Subnets(ctx envcontext.ProviderCallContext, id instance.Id, subnets []network.Id) ([]network.SubnetInfo, error) {
	var results []network.SubnetInfo
	subIdSet := set.NewStrings()
	for _, subId := range subnets {
		subIdSet.Add(string(subId))
	}

	allSubnets, err := e.allSubnetsAsMap(e.Config().UUID())
	if err != nil {
		providerCommon.HandleCredentialError(err, ctx)
		return nil, errors.Trace(err)
	}
	hasSubnetList := false
	if len(subIdSet) > 0 {
		hasSubnetList = true
	}
	if id != instance.UnknownId {
		oInst, err := e.getOCIInstance(ctx, id)
		if err != nil {
			providerCommon.HandleCredentialError(err, ctx)
			return nil, errors.Trace(err)
		}

		vnics, err := oInst.getVnics()
		if err != nil {
			providerCommon.HandleCredentialError(err, ctx)
			return nil, errors.Trace(err)
		}
		for _, nic := range vnics {
			if nic.Vnic.SubnetId == nil {
				continue
			}
			if hasSubnetList {
				if !subIdSet.Contains(*nic.Vnic.SubnetId) {
					continue
				} else {
					subIdSet.Remove(*nic.Vnic.SubnetId)
				}
			}
			subnet, ok := allSubnets[*nic.Vnic.SubnetId]
			if !ok {
				continue
			}
			info := network.SubnetInfo{
				CIDR:       *subnet.CidrBlock,
				ProviderId: network.Id(*nic.Vnic.SubnetId),
			}
			results = append(results, info)
		}
	} else {
		for subnetId, subnet := range allSubnets {
			if hasSubnetList {
				if !subIdSet.Contains(subnetId) {
					continue
				} else {
					subIdSet.Remove(subnetId)
				}
			}
			if info, err := makeSubnetInfo(subnet); err == nil {
				results = append(results, info)
			}
		}
	}
	if hasSubnetList && !subIdSet.IsEmpty() {
		return nil, errors.Errorf("failed to find the following subnet ids: %v", subIdSet.Values())
	}

	// Sort the list of subnets to ensure consistency in what we display
	// to the user
	sort.Slice(results, func(i, j int) bool {
		return results[i].ProviderId < results[j].ProviderId
	})

	return results, nil
}
849565
func (u *Unit) ClosePorts(protocol string, fromPort, toPort int) error {
	var result params.ErrorResults
	args := params.EntitiesPortRanges{
		Entities: []params.EntityPortRange{{
			Tag:      u.tag.String(),
			Protocol: protocol,
			FromPort: fromPort,
			ToPort:   toPort,
		}},
	}
	err := u.st.facade.FacadeCall("ClosePorts", args, &result)
	if err != nil {
		return err
	}
	return result.OneError()
}
627193
func (inst *environInstance) ClosePorts(ctx context.ProviderCallContext, machineID string, rules []network.IngressRule) error {
	return inst.changeIngressRules(ctx, false, rules)
}
65747
func (s *Service) RemovePort(application string, portAddr string) error {
	if s.Endpoints == nil {
		return fmt.Errorf("Service %s has no Endpoints", s.Name)
	}

	//find the matching endpoint
	for i := range s.Endpoints {
		ep := &s.Endpoints[i]

		if ep.Application == application && ep.Purpose == "export" {
			if len(ep.PortList) == 0 {
				break
			}

			portFound := false
			var ports = make([]servicedefinition.Port, 0)
			for _, port := range ep.PortList {
				if port.PortAddr != portAddr {
					ports = append(ports, port)
				} else {
					portFound = true
				}
			}

			//error removing an unknown port
			if !portFound {
				return fmt.Errorf("endpoint %s does not have a port endpoint %s", application, portAddr)
			}

			ep.PortList = ports
			return nil
		}
	}

	return fmt.Errorf("unable to find application %s in service: %s", application, s.Name)
}
43234
func (env *environ) Subnets(ctx context.ProviderCallContext, instId instance.Id, subnetIds []network.Id) ([]network.SubnetInfo, error) {
	if err := env.checkBroken("Subnets"); err != nil {
		return nil, err
	}

	estate, err := env.state()
	if err != nil {
		return nil, err
	}
	estate.mu.Lock()
	defer estate.mu.Unlock()

	if ok, _ := env.SupportsSpaceDiscovery(ctx); ok {
		// Space discovery needs more subnets to work with.
		return env.subnetsForSpaceDiscovery(estate)
	}

	allSubnets := []network.SubnetInfo{{
		CIDR:              "0.10.0.0/24",
		ProviderId:        "dummy-private",
		AvailabilityZones: []string{"zone1", "zone2"},
	}, {
		CIDR:       "0.20.0.0/24",
		ProviderId: "dummy-public",
	}}

	// Filter result by ids, if given.
	var result []network.SubnetInfo
	for _, subId := range subnetIds {
		switch subId {
		case "dummy-private":
			result = append(result, allSubnets[0])
		case "dummy-public":
			result = append(result, allSubnets[1])
		}
	}
	if len(subnetIds) == 0 {
		result = append([]network.SubnetInfo{}, allSubnets...)
	}
	if len(result) == 0 {
		// No results, so just return them now.
		estate.ops <- OpSubnets{
			Env:        env.name,
			InstanceId: instId,
			SubnetIds:  subnetIds,
			Info:       result,
		}
		return result, nil
	}

	estate.ops <- OpSubnets{
		Env:        env.name,
		InstanceId: instId,
		SubnetIds:  subnetIds,
		Info:       result,
	}
	return result, nil
}
602573
func (e *endpoint) Close() {
	// Issue a shutdown so that the peer knows we won't send any more data
	// if we're connected, or stop accepting if we're listening.
	e.Shutdown(tcpip.ShutdownWrite | tcpip.ShutdownRead)

	e.mu.Lock()

	// For listening sockets, we always release ports inline so that they
	// are immediately available for reuse after Close() is called. If also
	// registered, we unregister as well otherwise the next user would fail
	// in Listen() when trying to register.
	if e.state == stateListen && e.isPortReserved {
		if e.isRegistered {
			e.stack.UnregisterTransportEndpoint(e.boundNICID, e.effectiveNetProtos, ProtocolNumber, e.id, e)
			e.isRegistered = false
		}

		e.stack.ReleasePort(e.effectiveNetProtos, ProtocolNumber, e.id.LocalAddress, e.id.LocalPort)
		e.isPortReserved = false
	}

	// Either perform the local cleanup or kick the worker to make sure it
	// knows it needs to cleanup.
	tcpip.AddDanglingEndpoint(e)
	if !e.workerRunning {
		e.cleanupLocked()
	} else {
		e.workerCleanup = true
		e.notifyProtocolGoroutine(notifyClose)
	}

	e.mu.Unlock()
}
472908
func (m *model) closeConns(devs []protocol.DeviceID, err error) {
	conns := make([]connections.Connection, 0, len(devs))
	m.pmut.Lock()
	for _, dev := range devs {
		if conn, ok := m.conn[dev]; ok {
			conns = append(conns, conn)
		}
	}
	m.pmut.Unlock()
	for _, conn := range conns {
		conn.Close(err)
	}
}
44788
func (inst *azureInstance) ClosePorts(ctx context.ProviderCallContext, machineId string, rules []jujunetwork.IngressRule) error {
	securityRuleClient := network.SecurityRulesClient{inst.env.network}
	securityGroupName := internalSecurityGroupName

	// Delete rules one at a time; this is necessary to avoid trampling
	// on changes made by the provisioner.
	vmName := resourceName(names.NewMachineTag(machineId))
	prefix := instanceNetworkSecurityRulePrefix(instance.Id(vmName))
	sdkCtx := stdcontext.Background()

	singleSourceIngressRules := explodeIngressRules(rules)
	for _, rule := range singleSourceIngressRules {
		ruleName := securityRuleName(prefix, rule)
		logger.Debugf("deleting security rule %q", ruleName)
		future, err := securityRuleClient.Delete(
			stdcontext.Background(),
			inst.env.resourceGroup, securityGroupName, ruleName,
		)
		if err != nil {
			if !isNotFoundResponse(future.Response()) {
				return errors.Annotatef(err, "deleting security rule %q", ruleName)
			}
			continue
		}
		err = future.WaitForCompletionRef(sdkCtx, securityRuleClient.Client)
		if err != nil {
			return errors.Annotatef(err, "deleting security rule %q", ruleName)
		}
		result, err := future.Result(securityRuleClient)
		if err != nil && !isNotFoundResult(result) {
			return errorutils.HandleCredentialError(errors.Annotatef(err, "deleting security rule %q", ruleName), ctx)
		}
	}
	return nil
}
247882
func (conn *UnixConn) Close() error {
	close(conn.closeChan)
	return conn.unixConn.Close()
}
959261
func (inst *environInstance) ClosePorts(ctx context.ProviderCallContext, machineID string, rules []network.IngressRule) error {
	name, err := inst.env.namespace.Hostname(machineID)
	if err != nil {
		return errors.Trace(err)
	}
	err = inst.env.gce.ClosePorts(name, rules...)
	return google.HandleCredentialError(errors.Trace(err), ctx)
}
955935
func (f Firewall) ClosePorts(ctx context.ProviderCallContext, rules []network.IngressRule) error {
	groupName := f.globalGroupName()
	return f.closePortsOnList(ctx, f.client.ComposeName(groupName), rules)
}
1223886
func (c *Client) Close() error {
	c.Lock()
	defer c.Unlock()

	select {
	case <-c.quitChan:
		common.Log.Warnf(`client already closed`)
		return common.ErrClosed
	default:
		close(c.quitChan)
	}

	if err := c.SubscriptionProvider.Close(); err != nil {
		common.Log.Warnf("closing subscriptions: %v", err)
	}
	return c.protocol.Close()
}
1159517
func (d *Device) Close() error {
	d.Lock()
	defer d.Unlock()

	select {
	case <-d.quitChan:
		return common.ErrClosed
	default:
		close(d.quitChan)
		for seq, res := range d.responseMap {
			select {
			case res.ch <- &packet.Response{Error: common.ErrClosed}:
			case <-res.done:
			default:
				close(res.done)
			}
			res.wg.Wait()
			close(res.ch)
			delete(d.responseMap, seq)
		}
	}

	return d.SubscriptionProvider.Close()
}
42644
func (c *legacyNovaFirewaller) ClosePorts(ctx context.ProviderCallContext, rules []network.IngressRule) error {
	return c.closePorts(ctx, c.closePortsInGroup, rules)
}
910731
func (s *Stack) AddSubnet(id tcpip.NICID, protocol tcpip.NetworkProtocolNumber, subnet tcpip.Subnet) *tcpip.Error {
	s.mu.RLock()
	defer s.mu.RUnlock()

	if nic, ok := s.nics[id]; ok {
		nic.AddSubnet(protocol, subnet)
		return nil
	}

	return tcpip.ErrUnknownNICID
}
1326482
func (ep *endpoint) Close() {
	ep.mu.Lock()
	defer ep.mu.Unlock()

	if ep.closed {
		return
	}

	ep.stack.UnregisterRawTransportEndpoint(ep.registeredNIC, ep.netProto, ep.transProto, ep)

	ep.rcvMu.Lock()
	defer ep.rcvMu.Unlock()

	// Clear the receive list.
	ep.rcvClosed = true
	ep.rcvBufSize = 0
	for !ep.rcvList.Empty() {
		ep.rcvList.Remove(ep.rcvList.Front())
	}

	if ep.connected {
		ep.route.Release()
	}

	ep.waiterQueue.Notify(waiter.EventHUp | waiter.EventErr | waiter.EventIn | waiter.EventOut)
}