aboutsummaryrefslogtreecommitdiff
path: root/src/recon.h
blob: ede96009e036721379b76755901afed2a07965bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/** \file
 * \brief The recon worker
 */
/*
* Copyright (c) 2019-2021 David Timber <mieabby@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include "pth.h"
#include "protocol.h"

#include <mbedtls/ctr_drbg.h>


/* Alias and forward declarations */
/**
 * \brief The opauqe handle type to an instance of the recon worker. Reserved
 * 	for future use.
 */
typedef struct prne_recon prne_recon_t;
typedef struct prne_recon_param prne_recon_param_t;
typedef struct prne_recon_network prne_recon_network_t;
typedef void(*prne_recon_evt_ft)(void *ctx, const prne_net_endpoint_t *ep);

// The recon network object
struct prne_recon_network {
	prne_ip_addr_t addr;
	uint8_t mask[16]; // The netmask bits in the network order
};

// The recon worker parameter object
struct prne_recon_param {
	// The blacklisted networks
	struct {
		prne_recon_network_t *arr;
		size_t cnt;
	} blist;
	// The target networks
	struct {
		prne_recon_network_t *arr;
		size_t cnt;
	} target;
	// The destination ports in SYN packets
	struct {
		uint16_t *arr;
		size_t cnt;
	} ports;
	prne_recon_evt_ft evt_cb; // The discovery event callback function
	void *cb_ctx; // The context object for event callbacks
	/*
	 * True if the object has the responsibility of freeing the dynamically
	 * allocated members
	 */
	bool ownership;
};

/**
 * \brief Allocate resources and start an instance of the recon worker
 * \param wkr The initialised worker object
 * \param ctr_drbg The CTR DRBG object to use for initial random values
 * \param param The recon worker parameter object
 * \return A handle to the instance
 * \retval NULL if an error occurred. \c errno set.
 */
prne_recon_t *prne_alloc_recon (
	prne_worker_t *wkr,
	mbedtls_ctr_drbg_context *ctr_drbg,
	const prne_recon_param_t *param);
/**
 * \brief Initialise the recon worker parameter object
 * \note Initialises the members of \p p to initial values. Prepares \p p so
 * 	that it can be freed using \c prne_free_recon_param()
 */
void prne_init_recon_param (prne_recon_param_t *p);
/**
 * \brief Free the resources allocated for the recon worker parameter object
 * \param p The pointer to the object that has been initialised using
 * 	\c prne_init_recon_param()
 */
void prne_free_recon_param (prne_recon_param_t *p);
/**
 * \brief Allocate dynamically allocated members in the recon worker parameter
 * 	object
 * \param p The pointer to the recon worker parameter object
 * \param blist The number of blacklisted networks
 * \param target The number of target networks
 * \param ports The number of the destination ports in SYN packets
 * \retval true if allocation was successful
 * \retval false otherwise and \c errno is set to \c ENOMEM
 */
bool prne_alloc_recon_param (
	prne_recon_param_t *p,
	const size_t blist,
	const size_t target,
	const size_t ports);