MCPcopy Create free account
hub / github.com/MariaDB/server / is_proxy_protocol_allowed

Function is_proxy_protocol_allowed

sql/proxy_protocol.cc:525–571  ·  view source on GitHub ↗

Check whether proxy header from client is allowed, as per specification in 'proxy_protocol_networks' server variable. The non-TCP "localhost" clients (unix socket, shared memory, pipes) are accepted whenever 127.0.0.1 accepted in 'proxy_protocol_networks' */

Source from the content-addressed store, hash-verified

523 are accepted whenever 127.0.0.1 accepted in 'proxy_protocol_networks'
524*/
525bool is_proxy_protocol_allowed(const sockaddr *addr)
526{
527 if (proxy_protocol_subnet_count == 0)
528 return false;
529
530 sockaddr_storage addr_storage;
531 struct sockaddr *normalized_addr= (struct sockaddr *)&addr_storage;
532
533 /*
534 Non-TCP addresses (unix domain socket, windows pipe and shared memory
535 gets translated to TCP4 localhost address.
536
537 Note, that vio remote addresses are initialized with binary zeros
538 for these protocols (which is AF_UNSPEC everywhere).
539 */
540 switch(addr->sa_family)
541 {
542 case AF_UNSPEC:
543 case AF_UNIX:
544 normalized_addr->sa_family= AF_UNIX;
545 break;
546 case AF_INET:
547 case AF_INET6:
548 {
549 size_t len=
550 (addr->sa_family == AF_INET)?sizeof(sockaddr_in):sizeof (sockaddr_in6);
551 vio_get_normalized_ip(addr, len,normalized_addr);
552 }
553 break;
554 default:
555 DBUG_ASSERT(0);
556 }
557
558 bool ret= false;
559 mysql_rwlock_rdlock(&lock);
560 for (size_t i= 0; i < proxy_protocol_subnet_count; i++)
561 {
562 if (addr_matches_subnet(normalized_addr, &proxy_protocol_subnets[i]))
563 {
564 ret= true;
565 break;
566 }
567 }
568 mysql_rwlock_unlock(&lock);
569
570 return ret;
571}
572
573
574int init_proxy_protocol_networks(const char *spec)

Callers 2

handle_proxy_headerFunction · 0.85
thd_set_peer_addrFunction · 0.85

Calls 2

vio_get_normalized_ipFunction · 0.85
addr_matches_subnetFunction · 0.85

Tested by

no test coverage detected