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

Function handle_proxy_header

sql/net_serv.cc:752–800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

750#undef IGNORE /* for Windows */
751typedef enum { RETRY, ABORT, IGNORE} handle_proxy_header_result;
752static handle_proxy_header_result handle_proxy_header(NET *net)
753{
754#if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)
755 return IGNORE;
756#else
757 THD *thd= (THD *)net->thd;
758
759 if (!has_proxy_protocol_header(net) || !thd ||
760 thd->get_command() != COM_CONNECT)
761 return IGNORE;
762
763 /*
764 Proxy information found in the first 4 bytes received so far.
765 Read and parse proxy header , change peer ip address and port in THD.
766 */
767 proxy_peer_info peer_info;
768
769 if (!thd->net.vio)
770 {
771 DBUG_ASSERT(0);
772 return ABORT;
773 }
774
775 if (!is_proxy_protocol_allowed((sockaddr *)&(thd->net.vio->remote)))
776 {
777 /* proxy-protocol-networks variable needs to be set to allow this remote address */
778 my_printf_error(ER_HOST_NOT_PRIVILEGED, "Proxy header is not accepted from %s",
779 MYF(0), thd->main_security_ctx.ip);
780 return ABORT;
781 }
782
783 if (parse_proxy_protocol_header(net, &peer_info))
784 {
785 /* Failed to parse proxy header*/
786 my_printf_error(ER_UNKNOWN_ERROR, "Failed to parse proxy header", MYF(0));
787 return ABORT;
788 }
789
790 if (peer_info.is_local_command)
791 /* proxy header indicates LOCAL connection, no action necessary */
792 return RETRY;
793 /* Change peer address in THD and ACL structures.*/
794 uint host_errors;
795 net->using_proxy_protocol= 1;
796 return (handle_proxy_header_result)thd_set_peer_addr(thd,
797 &(peer_info.peer_addr), NULL, peer_info.port,
798 false, &host_errors);
799#endif
800}
801
802/**
803 Reads one packet to net->buff + net->where_b.

Callers 1

my_real_readFunction · 0.85

Calls 6

my_printf_errorFunction · 0.85
thd_set_peer_addrFunction · 0.85
get_commandMethod · 0.80

Tested by

no test coverage detected