MySQL 26.10.0
Source Code Documentation
sock_probe.cc File Reference
#include <netdb.h>
#include <cstdlib>
#include <string_view>
#include "xcom/node_no.h"
#include "xcom/server_struct.h"
#include "xcom/simset.h"
#include "xcom/site_struct.h"
#include "xcom/task.h"
#include "xcom/x_platform.h"
#include "xcom/xcom_cfg.h"
#include "xcom/xcom_detector.h"
#include "xcom/xcom_memory.h"
#include "xcom/xcom_profile.h"
#include "xcom/xcom_scope_guard.h"
#include "xdr_gen/xcom_vp.h"
#include "xcom/sock_probe_ix.h"

Functions

bool_t sockaddr_default_eq (struct sockaddr *x, struct sockaddr *y)
 
void set_port_matcher (port_matcher x)
 
port_matcher get_port_matcher ()
 
static struct addrinfo * probe_get_addrinfo (const char *name)
 
static void probe_free_addrinfo (struct addrinfo *addr)
 
static bool is_xcom_identity_configured ()
 Check whether an explicit XCom identity is currently configured. More...
 
static bool is_address_on_valid_local_interface (sock_probe *s, struct sockaddr *candidate_addr, bool using_net_ns)
 Check whether one resolved address matches a valid local interface in the current network context. More...
 
static bool has_address_on_valid_local_interface (sock_probe *s, struct addrinfo *candidate_addr, bool using_net_ns)
 Check whether any resolved address in an addrinfo list matches a valid local interface in the current network context. More...
 
static bool is_candidate_endpoint_configured_self (sock_probe *s, bool using_net_ns, char const *candidate_host_or_ip, xcom_port candidate_port)
 Check whether a candidate endpoint is the configured XCom identity in the current network context. More...
 
node_no xcom_find_node_index (node_list *nodes)
 Find the index of the local node within a node_list. More...
 
node_no xcom_mynode_match (const char *name, xcom_port port)
 Check whether a candidate endpoint identifies this local node. More...
 

Variables

static port_matcher match_port
 

Function Documentation

◆ get_port_matcher()

port_matcher get_port_matcher ( )

◆ has_address_on_valid_local_interface()

static bool has_address_on_valid_local_interface ( sock_probe *  s,
struct addrinfo *  candidate_addr,
bool  using_net_ns 
)
static

Check whether any resolved address in an addrinfo list matches a valid local interface in the current network context.

This helper iterates over all addresses in the supplied addrinfo chain and applies is_address_on_valid_local_interface() to each entry until one valid local match is found.

This helper assumes the caller has already switched to the intended network namespace, if any, before creating the sock_probe passed here.

Parameters
[in]sThe socket probe snapshot that exposes the local interfaces to check against.
[in]candidate_addrThe head of the resolved addrinfo list to validate.
[in]using_net_nsWhether the caller is running inside a configured network namespace. When true, interfaces in the probe are not filtered by active state.
Return values
trueAt least one resolved address in the list matches a valid local interface in the current network context.
falseNo resolved address in the list matches a valid local interface, or the list is empty.

◆ is_address_on_valid_local_interface()

static bool is_address_on_valid_local_interface ( sock_probe *  s,
struct sockaddr *  candidate_addr,
bool  using_net_ns 
)
static

Check whether one resolved address matches a valid local interface in the current network context.

This helper compares a single resolved socket address against the interfaces currently visible through the supplied sock_probe. When a configured network namespace is active, all interfaces in the probe are considered eligible; otherwise, only interfaces reported as active are accepted.

This helper assumes the caller has already switched to the intended network namespace, if any, before creating the sock_probe passed here.

Parameters
[in]sThe socket probe snapshot that exposes the local interfaces to check against.
[in]candidate_addrThe resolved socket address to validate as local.
[in]using_net_nsWhether the caller is running inside a configured network namespace. When true, interfaces in the probe are not filtered by active state.
Return values
trueThe resolved address matches a valid local interface in the current network context.
falseThe resolved address is null, does not match any visible local interface, or only matches interfaces that are not valid for the current network context.

◆ is_candidate_endpoint_configured_self()

static bool is_candidate_endpoint_configured_self ( sock_probe *  s,
bool  using_net_ns,
char const *  candidate_host_or_ip,
xcom_port  candidate_port 
)
static

Check whether a candidate endpoint is the configured XCom identity in the current network context.

When XCom identity is configured, self-detection must use that configured endpoint instead of relying only on matching any local interface on the same port. Both the candidate endpoint and the configured identity may identify their host part either as a hostname or as an IP address. The configured identity is read from cfg_app_xcom_get_identity() and split into its host/IP part and port.

Matching is performed only when the candidate port equals the configured identity port. The host/IP parts are then compared in two stages: first, by direct textual comparison of the candidate host/IP part against the configured identity host/IP part; second, if the textual comparison does not match, by resolving both names and checking whether any resolved socket address is shared by both endpoints.

After an endpoint match is established, the configured identity address must still be validated against the local interfaces visible in the current network namespace.

This helper assumes the caller has already switched to the intended network namespace, if any, before creating the sock_probe passed here.

Parameters
[in]sThe socket probe snapshot used to validate that the matched address exists on a valid local interface.
[in]using_net_nsWhether the caller is running inside a configured network namespace. When true, interfaces in the probe are not filtered by active state.
[in]candidate_host_or_ipThe host or IP part of the candidate endpoint being checked. It may be either a hostname or an IP address.
[in]candidate_portThe port portion of the candidate endpoint being checked.
Return values
trueThe candidate endpoint matches the configured XCom identity and the matched address resolves to a valid local interface in the current network context.
falseThe candidate endpoint does not match the configured identity, the configured identity cannot be resolved or validated, or the matched address does not correspond to a valid local interface in the current network context.

◆ is_xcom_identity_configured()

static bool is_xcom_identity_configured ( )
inlinestatic

Check whether an explicit XCom identity is currently configured.

An identity is considered configured only when cfg_app_xcom_get_identity() returns a node address and that node address contains a non-null endpoint string.

Return values
trueXCom identity is configured and contains an address.
falseXCom identity is not configured or does not contain an address.

◆ probe_free_addrinfo()

static void probe_free_addrinfo ( struct addrinfo *  addr)
inlinestatic

◆ probe_get_addrinfo()

static struct addrinfo * probe_get_addrinfo ( const char *  name)
inlinestatic

◆ set_port_matcher()

void set_port_matcher ( port_matcher  x)

◆ sockaddr_default_eq()

bool_t sockaddr_default_eq ( struct sockaddr *  x,
struct sockaddr *  y 
)

◆ xcom_find_node_index()

node_no xcom_find_node_index ( node_list *  nodes)

Find the index of the local node within a node_list.

This function scans the supplied XCom node list and identifies the first entry that matches the local node. It first applies the globally configured port matcher. If an explicit XCom identity is configured, matching is based on that configured endpoint; otherwise, the function falls back to matching the candidate addresses against the local interfaces visible to the current process.

The function evaluates global XCom state, namely the installed port matcher, the configured XCom identity, and the configured network namespace manager. The caller does not need to switch to the configured network namespace before invoking this function; if a namespace is configured, the function enters and restores it internally before probing interfaces.

Parameters
[in]nodesThe node list to scan.
Returns
The index of the first entry classified as the local node, or VOID_NODE_NO if no entry matches, if no port matcher is installed, if the socket probe cannot be initialized, or if every candidate is rejected by parsing, port mismatch, configured-identity mismatch, or local-interface validation.

◆ xcom_mynode_match()

node_no xcom_mynode_match ( const char *  name,
xcom_port  port 
)

Check whether a candidate endpoint identifies this local node.

This function first applies the globally configured port matcher to the candidate port. If an explicit XCom identity is configured, matching is based on that configured endpoint; otherwise, the function falls back to resolving the candidate host/IP and comparing it against the local interfaces visible to the current process.

The function evaluates global XCom state, namely the installed port matcher, the configured XCom identity, and the configured network namespace manager. The caller does not need to switch to the configured network namespace before invoking this function; if a namespace is configured, the function enters and restores it internally before probing interfaces.

Parameters
[in]nameThe candidate host or IP to classify.
[in]portThe candidate XCom port to classify.
Return values
1The candidate endpoint was classified as this local node.
0The candidate endpoint was not classified as this local node, or the local probe state could not be initialized.

Variable Documentation

◆ match_port

port_matcher match_port
static