| 1 | package Perlbal::Plugin::XFFExtras; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Danga::Socket 1.53; # Need newer Danga::Socket than perlbal to have local_port | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Perlbal 1.74; # is_ssl support was added in 1.74 | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Perlbal::BackendHTTP (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Perlbal::Service (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | Perlbal::Service::add_tunable( | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | send_backend_port => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | check_role => 'reverse_proxy', | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | des => "Send an X-Forwarded-Port header to backends to indicate the peer's remote address", | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | check_type => 'bool', | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | Perlbal::Service::add_tunable( | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | send_backend_proto => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | check_role => 'reverse_proxy', | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | des => "Send an X-Forwarded-Proto header to backends to indicate the peers connecting protocol", | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | check_type => 'bool', | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # magical Perlbal hook return value constants | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use constant HANDLE_REQUEST => 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use constant IGNORE_REQUEST => 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=2 SCAR=7.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | my ($class, $svc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | my $cfg = $svc->{extra_config} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$svc->{"extra_config"} ||= {}
MC/DC0%0/1
$svc->{"extra_config"} ||= {}
$svc->{"extra_config"}
Truth table50%1/2
A
A= $svc->{"extra_config"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | $svc->register_hook(XFFExtras => backend_client_assigned => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my Perlbal::BackendHTTP $be = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $hds = $be->{req_headers}; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $client = $be->{client}; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $client_ip = $client->peer_ip_string; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | my $trusted = $svc->trusted_ip($client_ip); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my $blind = $svc->{blind_proxy}; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | if (($trusted && !$blind) || !$trusted) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$trusted and not $blind or not $trusted
$trusted and not $blind
MC/DC0%0/3
$trusted and not $blind or not $trusted
$trusted
not $blind
not $trusted
Truth table20%1/5
A and not(B) or not(C)
A= $trustedB= not $blindC= not $trusted
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if ($cfg->{send_backend_port}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # Danga::Socket has no accessor for the peer_port, so we break object | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # boundaries for now to implement this. Force to integer because D::S | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # also likes to store string error messages in this field too. | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | $client->local_ip_string; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my $local_port = $client->{local_port} + 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | $hds->header("X-Forwarded-Port", $local_port); | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | if ($cfg->{send_backend_proto}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | my $proto = $client->{is_ssl} ? 'https' : 'http'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | $hds->header("X-Forwarded-Proto", $proto); | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | return HANDLE_REQUEST; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||