OpenVPN 3 Core Library
Loading...
Searching...
No Matches
tunspec.hpp
Go to the documentation of this file.
1
// OpenVPN -- An application to securely tunnel IP networks
2
// over a single port, with support for SSL/TLS-based
3
// session authentication and key exchange,
4
// packet encryption, packet authentication, and
5
// packet compression.
6
//
7
// Copyright (C) 2012- OpenVPN Inc.
8
//
9
// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10
//
11
12
// Parse the argument of a "tun" or "tap" directive. Also parse an optional
13
// "/v4" or "/v6" after the tun name to denote IPv4 or IPv6 usage.
14
15
#ifndef OPENVPN_TUN_TUNSPEC_H
16
#define OPENVPN_TUN_TUNSPEC_H
17
18
#include <string>
19
20
#include <
openvpn/common/split.hpp
>
21
22
namespace
openvpn
{
23
24
struct
ParseTunSpec
25
{
26
OPENVPN_EXCEPTION
(bad_tun_spec);
27
28
ParseTunSpec
(
const
std::string &tun_spec)
29
:
ipv6
(false)
30
{
31
std::vector<std::string> s = Split::by_char<std::vector<std::string>,
NullLex
,
Split::NullLimit
>(tun_spec,
'/'
);
32
if
(s.size() == 1)
33
{
34
tun_name
= s[0];
35
}
36
else
if
(s.size() == 2)
37
{
38
tun_name
= s[0];
39
if
(s[1] ==
"v4"
)
40
ipv6
=
false
;
41
else
if
(s[1] ==
"v6"
)
42
ipv6
=
true
;
43
else
44
throw
bad_tun_spec();
45
}
46
else
47
throw
bad_tun_spec();
48
}
49
bool
ipv6
;
50
std::string
tun_name
;
51
};
52
53
}
// namespace openvpn
54
55
#endif
// OPENVPN_TUN_TUNSPEC_H
openvpn::NullLex
Definition
lex.hpp:134
openvpn
Definition
ovpncli.cpp:97
split.hpp
openvpn::ParseTunSpec
Definition
tunspec.hpp:25
openvpn::ParseTunSpec::ParseTunSpec
ParseTunSpec(const std::string &tun_spec)
Definition
tunspec.hpp:28
openvpn::ParseTunSpec::tun_name
std::string tun_name
Definition
tunspec.hpp:50
openvpn::ParseTunSpec::ipv6
bool ipv6
Definition
tunspec.hpp:49
openvpn::ParseTunSpec::OPENVPN_EXCEPTION
OPENVPN_EXCEPTION(bad_tun_spec)
openvpn::Split::NullLimit
Definition
split.hpp:39
openvpn
tun
tunspec.hpp
Generated by
1.9.8