]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Packet.pm
10 CMD_REQUEST
=> 0, # Named request message
11 CMD_RESPONSE
=> 1, # Unnamed response message for a request
12 CMD_UNKNOWN
=> 2, # Unnamed response if requested command is unknown
13 EVENT_REGISTER
=> 3, # Named event registration request
14 EVENT_UNREGISTER
=> 4, # Named event de-registration request
15 EVENT_CONFIRM
=> 5, # Unnamed confirmation for event (de-)registration
16 EVENT_UNKNOWN
=> 6, # Unnamed response if event (de-)registration failed
17 EVENT
=> 7, # Named event message
24 Transport
=> Vici
::Transport
->new($socket),
31 my ($self, $command, $vars) = @_;
32 my $out = defined $vars ?
$vars->encode() : '';
33 my $request = pack('CC/a*a*', CMD_REQUEST
, $command, $out);
34 $self->{'Transport'}->send($request);
36 my $response = $self->{'Transport'}->receive();
37 my ($type, $data) = unpack('Ca*', $response);
39 if ( $type == CMD_RESPONSE
)
41 return Vici
::Message
->from_data($data);
43 elsif ( $type == CMD_UNKNOWN
)
45 die "unknown command '", $command, "'\n"
49 die "invalid response type\n"
54 my ($self, $event) = @_;
55 my $request = pack('CC/a*a*', EVENT_REGISTER
, $event);
56 $self->{'Transport'}->send($request);
58 my $response = $self->{'Transport'}->receive();
59 my ($type, $data) = unpack('Ca*', $response);
61 if ( $type == EVENT_CONFIRM
)
65 elsif ( $type == EVENT_UNKNOWN
)
67 die "unknown event '", $event, "'\n"
71 die "invalid response type\n"
76 my ($self, $event) = @_;
77 my $request = pack('CC/a*a*', EVENT_UNREGISTER
, $event);
78 $self->{'Transport'}->send($request);
80 my $response = $self->{'Transport'}->receive();
81 my ($type, $data) = unpack('Ca*', $response);
83 if ( $type == EVENT_CONFIRM
)
87 elsif ( $type == EVENT_UNKNOWN
)
89 die "unknown event '", $event, "'\n"
93 die "invalid response type\n"
97 sub streamed_request
{
98 my ($self, $command, $event, $vars) = @_;
99 my $out = defined $vars ?
$vars->encode() : '';
101 $self->register($event);
103 my $request = pack('CC/a*a*', CMD_REQUEST
, $command, $out);
104 $self->{'Transport'}->send($request);
110 my $response = $self->{'Transport'}->receive();
111 my ($type, $data) = unpack('Ca*', $response);
113 if ( $type == EVENT
)
115 (my $event_name, $data) = unpack('C/a*a*', $data);
117 if ($event_name eq $event)
119 my $msg = Vici
::Message
->from_data($data);
123 elsif ( $type == CMD_RESPONSE
)
125 $self->unregister($event);
130 $self->unregister($event);
131 die "invalid response type\n";
141 Vici::Packet - Perl extension for sending and receiving strongSwan VICI packets
149 The Vici::Packet module is needed by the Vici::Session module to send and
150 receive packets used in the communication with the open source strongSwan IPsec
151 daemon (https://www.strongswan.com) via the documented Versatile IKE
152 Configuration Interface (VICI). VICI allows the configuration, management and
153 monitoring of multiple IPsec connections.
161 strongSwan Wiki: https://wiki.strongswan.org/projects/strongswan/wiki/Vici
163 strongSwan Mailing list: users@lists.strongswan.org
167 Andreas Steffen, E<lt>andreas.steffen@strongswan.orgE<gt>
169 =head1 COPYRIGHT AND LICENSE
171 Copyright (C) 2015 by Andreas Steffen
173 Permission is hereby granted, free of charge, to any person obtaining a copy
174 of this software and associated documentation files (the "Software"), to deal
175 in the Software without restriction, including without limitation the rights
176 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
177 copies of the Software, and to permit persons to whom the Software is
178 furnished to do so, subject to the following conditions:
180 The above copyright notice and this permission notice shall be included in
181 all copies or substantial portions of the Software.
183 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
184 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
186 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
187 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
188 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN