-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform.cc
118 lines (96 loc) · 3.46 KB
/
platform.cc
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
113
114
115
116
117
118
// Copyright 2023 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "secagentd/platform.h"
#include <net/if.h>
#include <memory>
#include <utility>
#include "base/files/file_descriptor_watcher_posix.h"
namespace secagentd {
namespace {
std::unique_ptr<PlatformInterface> platform{nullptr};
}
base::WeakPtr<PlatformInterface> SetPlatform(
std::unique_ptr<PlatformInterface> platform_in) {
platform = std::move(platform_in);
return platform->GetWeakPtr();
}
base::WeakPtr<PlatformInterface> GetPlatform() {
if (platform == nullptr) {
platform = std::make_unique<Platform>();
}
return platform->GetWeakPtr();
}
base::WeakPtr<PlatformInterface> Platform::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
int Platform::IfNameToIndex(const std::string& ifname) {
return if_nametoindex(ifname.c_str());
}
int Platform::BpfMapDeleteElem(struct bpf_map* map,
const void* key,
size_t key_sz,
__u64 flags) {
return bpf_map__delete_elem(map, key, key_sz, flags);
}
int Platform::BpfMapUpdateElem(const struct bpf_map* map,
const void* key,
size_t key_sz,
const void* value,
size_t value_sz,
__u64 flags) {
return bpf_map__update_elem(map, key, key_sz, value, value_sz, flags);
}
int Platform::BpfMapLookupElem(const struct bpf_map* map,
const void* key,
size_t key_sz,
void* value,
size_t value_sz,
__u64 flags) {
return bpf_map__lookup_elem(map, key, key_sz, value, value_sz, flags);
}
int Platform::BpfMapGetNextKey(const struct bpf_map* map,
const void* cur_key,
void* next_key,
size_t key_sz) {
return bpf_map__get_next_key(map, cur_key, next_key, key_sz);
}
int Platform::LibbpfSetStrictMode(enum libbpf_strict_mode mode) {
return libbpf_set_strict_mode(mode);
}
int Platform::BpfObjectLoadSkeleton(struct bpf_object_skeleton* s) {
return bpf_object__load_skeleton(s);
}
int Platform::BpfObjectAttachSkeleton(struct bpf_object_skeleton* s) {
return bpf_object__attach_skeleton(s);
}
void Platform::BpfObjectDetachSkeleton(struct bpf_object_skeleton* s) {
bpf_object__detach_skeleton(s);
}
void Platform::BpfObjectDestroySkeleton(struct bpf_object_skeleton* s) {
bpf_object__destroy_skeleton(s);
}
int Platform::BpfMapFd(const struct bpf_map* map) {
return bpf_map__fd(map);
}
struct ring_buffer* Platform::RingBufferNew(
int map_fd,
ring_buffer_sample_fn sample_cb,
void* ctx,
const struct ring_buffer_opts* opts) {
return ring_buffer__new(map_fd, sample_cb, ctx, opts);
}
int Platform::RingBufferEpollFd(const struct ring_buffer* rb) {
return ring_buffer__epoll_fd(rb);
}
int Platform::RingBufferConsume(struct ring_buffer* rb) {
return ring_buffer__consume(rb);
}
void Platform::RingBufferFree(struct ring_buffer* rb) {
ring_buffer__free(rb);
}
std::unique_ptr<base::FileDescriptorWatcher::Controller>
Platform::WatchReadable(int fd, const base::RepeatingClosure& callback) {
return base::FileDescriptorWatcher::WatchReadable(fd, callback);
}
} // namespace secagentd