OpenVPN 3 Core Library
Loading...
Searching...
No Matches
test_iphelper.cpp
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
13#include <fstream>
14#include "test_common.hpp"
15
17#include <openvpn/win/call.hpp>
19
20using namespace openvpn;
21using namespace openvpn::TunWin::Util;
22
23namespace unittests {
24static std::string path_to_ip;
25
26class IpHelperTest : public testing::Test
27{
28 protected:
29 void SetUp() override
30 {
31 // get index of default network adapter
32 DWORD addr;
33 inet_pton(AF_INET, "8.8.8.8", &addr);
34 ::GetBestInterface(addr, &tap.index);
35 }
36
37 virtual void TearDown() override
38 {
40 remove_cmds.clear();
41 }
42
45 std::ostringstream os;
46};
47
48TEST_F(IpHelperTest, TestAddRoute4)
49{
50 const char *gw = "10.10.123.123";
51 const char *route = "10.10.0.0";
52 int route_prefix = 16;
53 int metric = 123;
54
55 TunIPHELPER::AddRoute4Cmd cmd{route, route_prefix, tap.index, tap.name, gw, metric, true};
56 remove_cmds.add(new TunIPHELPER::AddRoute4Cmd{route, route_prefix, tap.index, tap.name, gw, metric, false});
57
58 // add route
59 cmd.execute(os);
60
61 // get next hop for routed address
62 MIB_IPFORWARDROW row;
63 DWORD addr;
64 inet_pton(AF_INET, "10.10.0.3", &addr);
65 GetBestRoute(addr, 0, &row);
66 char next_hop[INET_ADDRSTRLEN];
67 inet_ntop(AF_INET, &row.dwForwardNextHop, next_hop, INET_ADDRSTRLEN);
68
69 // the next hop should equal route gw
70 ASSERT_STREQ(gw, next_hop);
71}
72} // namespace unittests
virtual std::unordered_set< std::string > execute(std::ostream &os)
Executes a sequence of actions and returns marks of failed actions.
Definition action.hpp:98
std::ostringstream os
virtual void TearDown() override
TEST_F(IpHelperTest, TestAddRoute4)
static std::string path_to_ip
const auto metric
std::ostringstream os