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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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:
- JOBNAME entries, other than JOBNAME *
- DESTINATION entries
- 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. - 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.
For a static VIPA, it is defined on a DEVICE/LINK/HOME statement and not the INTERFACE statement.
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. - 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:
- Locates that interface in the HOME list.
- Starting with that interface, searches backward in the HOME list for the nearest static VIPA.
- If a static VIPA is found in the HOME list, TCP/IP uses that 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:
- Determines whether a SOURCEVIPAINTERFACE parameter was specified for the selected interface.
- 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:
- Determines whether a SOURCEVIPAINTERFACE parameter was specified for the selected interface.
- 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.
- Local IP address of the interface over which the
packet is sent
For an IPv4 packet, TCP/IP uses the local IP address of the interface 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.