Skip to content

Commit cdd61ff

Browse files
flichtenheldcron2
authored andcommitted
socket: Create socket_util with non-socket functions
This extracts a lot of the helper functions that do not actually work on sockets, but instead on addresses or similar. This includes - openvpn_getaddrinfo and related functions - print_* - setenv_* And lots of the inline functions. This move will make it easier to add unit tests for these moved functions. Change-Id: I7393459b975fb9b3e0a42743f58645f769d1be5a Signed-off-by: Frank Lichtenheld <[email protected]> Acked-by: Gert Doering <[email protected]> Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg32727.html Signed-off-by: Gert Doering <[email protected]>
1 parent 1cc3525 commit cdd61ff

File tree

20 files changed

+1443
-1380
lines changed

20 files changed

+1443
-1380
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ set(SOURCE_FILES
555555
src/openvpn/sig.h
556556
src/openvpn/socket.c
557557
src/openvpn/socket.h
558+
src/openvpn/socket_util.c
559+
src/openvpn/socket_util.h
558560
src/openvpn/socks.c
559561
src/openvpn/socks.h
560562
src/openvpn/ssl.c

src/openvpn/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ openvpn_SOURCES = \
128128
shaper.c shaper.h \
129129
sig.c sig.h \
130130
socket.c socket.h \
131+
socket_util.c socket_util.h \
131132
socks.c socks.h \
132133
ssl.c ssl.h ssl_backend.h \
133134
ssl_openssl.c ssl_openssl.h \

src/openvpn/clinat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include "clinat.h"
3030
#include "proto.h"
31-
#include "socket.h"
31+
#include "socket_util.h"
3232
#include "memdbg.h"
3333

3434
static bool

src/openvpn/dhcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "syshead.h"
2828

2929
#include "dhcp.h"
30-
#include "socket.h"
30+
#include "socket_util.h"
3131
#include "error.h"
3232

3333
#include "memdbg.h"

src/openvpn/dns.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "syshead.h"
2828

2929
#include "dns.h"
30-
#include "socket.h"
30+
#include "socket_util.h"
3131
#include "options.h"
3232
#include "run_command.h"
3333

src/openvpn/manage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
#include "misc.h"
5050
#include "event.h"
51-
#include "socket.h"
51+
#include "socket_util.h"
5252
#include "mroute.h"
5353

5454
#define MANAGEMENT_VERSION 5

src/openvpn/misc.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,6 @@ set_std_files_to_null(bool stdin_only)
7272
#endif
7373
}
7474

75-
/*
76-
* Prepend a random string to hostname to prevent DNS caching.
77-
* For example, foo.bar.gov would be modified to <random-chars>.foo.bar.gov.
78-
* Of course, this requires explicit support in the DNS server (wildcard).
79-
*/
80-
const char *
81-
hostname_randomize(const char *hostname, struct gc_arena *gc)
82-
{
83-
#define n_rnd_bytes 6
84-
85-
uint8_t rnd_bytes[n_rnd_bytes];
86-
const char *rnd_str;
87-
struct buffer hname = alloc_buf_gc(strlen(hostname) + sizeof(rnd_bytes) * 2 + 4, gc);
88-
89-
prng_bytes(rnd_bytes, sizeof(rnd_bytes));
90-
rnd_str = format_hex_ex(rnd_bytes, sizeof(rnd_bytes), 40, 0, NULL, gc);
91-
buf_printf(&hname, "%s.%s", rnd_str, hostname);
92-
return BSTR(&hname);
93-
#undef n_rnd_bytes
94-
}
95-
9675
#ifdef ENABLE_MANAGEMENT
9776
/* Get username/password from the management interface */
9877
static bool

src/openvpn/misc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ const char **make_arg_array(const char *first, const char *parms, struct gc_aren
4444

4545
const char **make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc);
4646

47-
/* prepend a random prefix to hostname */
48-
const char *hostname_randomize(const char *hostname, struct gc_arena *gc);
49-
5047
/*
5148
* Get and store a username/password
5249
*/

src/openvpn/mroute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "mroute.h"
3131
#include "proto.h"
3232
#include "error.h"
33-
#include "socket.h"
33+
#include "socket_util.h"
3434

3535
#include "memdbg.h"
3636

src/openvpn/mss.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "proto.h"
2727
#include "error.h"
2828
#include "mtu.h"
29+
#include "socket.h"
2930
#include "ssl_common.h"
3031

3132
void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss);

0 commit comments

Comments
 (0)