aboutsummaryrefslogtreecommitdiffstats
path: root/driver/main.c
blob: b2f305f17a926865b74229ea306c3ed438f7b43c (plain) (blame)
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
/* SPDX-License-Identifier: GPL-2.0
 *
 * Copyright (C) 2015-2021 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
 */

#include "device.h"
#include "noise.h"
#include "queueing.h"
#include "ratelimiter.h"
#include "rcu.h"
#include "socket.h"
#include "logging.h"
#include "crypto.h"
#include <wsk.h>
#include <ndis.h>

DRIVER_INITIALIZE DriverEntry;
#ifdef ALLOC_PRAGMA
#    pragma alloc_text(INIT, DriverEntry)
#endif
_Use_decl_annotations_
NTSTATUS
DriverEntry(DRIVER_OBJECT *DriverObject, UNICODE_STRING *RegistryPath)
{
    NTSTATUS Ret;

    ExInitializeDriverRuntime(DrvRtPoolNxOptIn);

    CryptoDriverEntry();
    NoiseDriverEntry();

    Ret = MemDriverEntry();
    if (!NT_SUCCESS(Ret))
        return Ret;

    Ret = RcuDriverEntry();
    if (!NT_SUCCESS(Ret))
        goto cleanupMem;

    Ret = AllowedIpsDriverEntry();
    if (!NT_SUCCESS(Ret))
        goto cleanupRcu;

    Ret = RatelimiterDriverEntry();
    if (!NT_SUCCESS(Ret))
        goto cleanupAllowedIps;

    Ret = PeerDriverEntry();
    if (!NT_SUCCESS(Ret))
        goto cleanupRatelimiter;

    Ret = DeviceDriverEntry(DriverObject, RegistryPath);
    if (!NT_SUCCESS(Ret))
        goto cleanupPeer;

#ifdef DBG
    if (!CryptoSelftest() || !AllowedIpsSelftest() || !PacketCounterSelftest() || !RatelimiterSelftest())
    {
        Ret = STATUS_INTERNAL_ERROR;
        goto cleanupDevice;
    }
#endif
    return 0;

#ifdef DBG
cleanupDevice:
    DeviceUnload();
#endif
cleanupPeer:
    PeerUnload();
cleanupRatelimiter:
    RatelimiterUnload();
cleanupAllowedIps:
    AllowedIpsUnload();
cleanupRcu:
    RcuUnload();
cleanupMem:
    MemUnload();
    return Ret;
}

MINIPORT_UNLOAD Unload;
_Use_decl_annotations_
VOID
Unload(PDRIVER_OBJECT DriverObject)
{
    DeviceUnload();
    WskUnload();
    PeerUnload();
    RatelimiterUnload();
    AllowedIpsUnload();
    RcuUnload();
    MemUnload();
}