How TCP/IP selects a source IP address

TCP/IP uses the following sequence to select the source IP address for an outbound packet. For detailed information about the TCP/IP profile (PROFILE.TCPIP) and configuration statements, see z/OS Communications Server: IP Configuration Reference.

  1. Sendmsg that specifies the source address in the ancillary IPV6_PKTINFO data

    If this is a UDP or RAW socket, and IPV6_PKTINFO ancillary data is specified on sendmsg() with a nonzero source IP address, this address is used as the source IP address.

  2. Setsockopt IPV6_PKTINFO

    If this is a UDP or RAW socket, and the IPV6_PKTINFO socket option is set and it contains a nonzero source IP address, this address is used as the source IP address.

  3. Explicit bind to a specific local address

    If the socket is already bound to a specific local IP address other than INADDR_ANY or in6addr_any, TCP/IP uses this specific local IP address.

  4. bind2addrsel socket function (IPv6 only)

    The bind2addrsel socket function, which is available only to AF_INET6 sockets, binds a socket to a stack-selected local address and port that is appropriate to communicate with a given destination address.

  5. PORT profile statement with the BIND parameter

    If the socket is bound to a source port and to the INADDR_ANY or in6addr_any IP address, and there is a corresponding PORT profile statement with the BIND parameter specified, TCP/IP uses the address specified by the BIND parameter.

  6. SRCIP profile statement

    If this is a TCP socket and either the socket is not yet bound or the socket is bound to the INADDR_ANY or in6addr_any IP address, TCP/IP checks the job name and destination IP address against the SRCIP entries in the following order:

    1. JOBNAME entries, other than JOBNAME *
    2. DESTINATION entries
    3. JOBNAME * entries

    If a match is found, TCP/IP uses the designated source in the most specific matching entry to provide the source IP address to be used.

    Restriction: JOBNAME entries that specify a source of PUBLICADDRS or TEMPADDRS apply to only IPv6 source IP address selection. The JOBNAME entries do not influence the setting of the source IP address during this step of the source IP address selection sequence. For information about how PUBLICADDRS or TEMPADDRS entries influence the selection of the source IP address and the default source address selection algorithm, see z/OS Communications Server: IPv6 Network and Application Design Guide.
  7. TCPSTACKSOURCEVIPA parameter on the IPCONFIG or IPCONFIG6 profile statement

    All of the following conditions must be met:

    • This is a TCP socket.
    • SOURCEVIPA is enabled on IPCONFIG or IPCONFIG6.
    • SOURCEVIPA is not disabled for the socket.
    • The application has not issued a specific bind for this socket, even to the INADDR_ANY or in6addr_any IP address.
    • The address specified on the TCPSTACKSOURCEVIPA parameter is a static VIPA or active dynamic VIPA.

    If these conditions are met and this is an IPv4 packet, TCP/IP uses the address specified on the TCPSTACKSOURCEVIPA parameter.

    If these conditions are met and this is an IPv6 packet, TCP/IP uses the default source address selection algorithm to select one of the addresses configured for the VIPA interface referenced by the TCPSTACKSOURCEVIPA parameter. For information about the default source address selection algorithm, see z/OS Communications Server: IPv6 Network and Application Design Guide.

    Guideline: Because the SRCIP profile statement provides all of the functionality of the TCPSTACKSOURCEVIPA parameter and additional granularity, consider using the SRCIP statement instead of specifying the TCPSTACKSOURCEVIPA parameter. Specifying JOBNAME * in a SRCIP profile statement provides the same result as specifying the TCPSTACKSOURCEVIPA parameter for implicit bind scenarios, and also applies to applications that issue a bind to the INADDR_ANY or in6addr_any IP address.
  8. SOURCEVIPA: Static VIPA address from the HOME list (IPv4 interface defined with the LINK statement) or from the SOURCEVIPAINTERFACE parameter (IPv6 or IPv4 interface defined with the INTERFACE statement)

    All of the following conditions must be met:

    • SOURCEVIPA is enabled on IPCONFIG or IPCONFIG6.
    • SOURCEVIPA is not disabled for the socket.
    • Either the socket is not yet bound, or the socket is bound to the INADDR_ANY or in6addr_any IP address.

    If these conditions are met, TCP/IP determines the interface over which the initial packet will be sent.

    • For an IPv4 packet sent over an interface that is defined with the LINK statement, TCP/IP takes the following actions:
      1. Locates that interface in the HOME list.
      2. Searches backward in the HOME list for a static VIPA.
      3. If a static VIPA is found in the HOME list, TCP/IP uses the first static VIPA found as the source IP address.
    • For an IPv4 packet sent over an interface that is defined with the INTERFACE statement, TCP/IP takes the following actions:
      1. Determines whether a SOURCEVIPAINTERFACE parameter was specified for the selected interface.
      2. If a SOURCEVIPAINTERFACE parameter was specified, TCP/IP uses the address of the VIPA interface that is referenced by the SOURCEVIPAINTERFACE parameter.
    • For an IPv6 packet, TCP/IP takes the following actions:
      1. Determines whether a SOURCEVIPAINTERFACE parameter was specified for the selected interface.
      2. If a SOURCEVIPAINTERFACE parameter was specified, TCP/IP uses the default source address selection algorithm to select one of the addresses that are configured for the VIPA interface that is referenced by the SOURCEVIPAINTERFACE parameter. For information about the default source address selection algorithm, see z/OS Communications Server: IPv6 Network and Application Design Guide.
  9. HOME IP address of the link over which the packet is sent

    For an IPv4 packet, TCP/IP uses the HOME IP address of the link over which the initial packet is sent.

    For an IPv6 packet, TCP/IP uses the default source address selection algorithm to select one of the addresses configured for the interface over which the initial packet is sent. For information about the default source address selection algorithm, see z/OS Communications Server: IPv6 Network and Application Design Guide.