| 1 |
// Render with Asciidoctor |
| 2 |
|
| 3 |
= barectf Linux FS platform |
| 4 |
Philippe Proulx |
| 5 |
23 September 2020 |
| 6 |
:toc: left |
| 7 |
|
| 8 |
The barectf Linux FS platform is a very simple platform used to |
| 9 |
demonstrate barectf. |
| 10 |
|
| 11 |
The platform writes the CTF packets to a data stream file on the file |
| 12 |
system. |
| 13 |
|
| 14 |
This platform can also simulate a full back-end randomly with a |
| 15 |
configurable ratio. |
| 16 |
|
| 17 |
== barectf configuration requirements |
| 18 |
|
| 19 |
* The default `barectf` file name prefix. |
| 20 |
|
| 21 |
* The default `barectf_` identifier prefix. |
| 22 |
|
| 23 |
* A single data stream type named `default`: |
| 24 |
|
| 25 |
** No extra packet context field type members. |
| 26 |
** A default clock type named `default`: |
| 27 |
Frequency:::: 1000000000 (default) |
| 28 |
Offsets:::: 0 (default) |
| 29 |
Origin is Unix epoch?:::: Yes (default) |
| 30 |
C{nbsp}type:::: `uint64_t` |
| 31 |
|
| 32 |
.Compatible YAML configuration |
| 33 |
==== |
| 34 |
[source,yaml] |
| 35 |
---- |
| 36 |
--- !<tag:barectf.org,2020/3/config> |
| 37 |
trace: |
| 38 |
type: |
| 39 |
$include: |
| 40 |
- stdint.yaml |
| 41 |
target-byte-order: le |
| 42 |
clock-types: |
| 43 |
default: |
| 44 |
$c-type: uint64_t |
| 45 |
data-stream-types: |
| 46 |
default: |
| 47 |
$is-default: true |
| 48 |
$default-clock-type-name: default |
| 49 |
event-record-types: |
| 50 |
my_event: |
| 51 |
payload-field-type: |
| 52 |
class: struct |
| 53 |
members: |
| 54 |
- number: uint32 |
| 55 |
---- |
| 56 |
==== |
| 57 |
|
| 58 |
== C API |
| 59 |
|
| 60 |
=== Initialization |
| 61 |
|
| 62 |
==== Prototype |
| 63 |
|
| 64 |
[source,c] |
| 65 |
---- |
| 66 |
struct barectf_platform_linux_fs_ctx *barectf_platform_linux_fs_init( |
| 67 |
unsigned int buf_size, const char *data_stream_file_path, |
| 68 |
int simulate_full_backend, unsigned int full_backend_rand_max, |
| 69 |
unsigned int full_backend_rand_lt); |
| 70 |
---- |
| 71 |
|
| 72 |
==== Parameters |
| 73 |
|
| 74 |
[cols="d,a"] |
| 75 |
|==== |
| 76 |
|Name |Description |
| 77 |
|
| 78 |
|`buf_size` |
| 79 |
|Size of the packet buffer to allocate (bytes). |
| 80 |
|
| 81 |
|`data_stream_file_path` |
| 82 |
|Path of the data stream file to which to append packets. |
| 83 |
|
| 84 |
|`simulate_full_backend` |
| 85 |
| |
| 86 |
0:: |
| 87 |
Disable full back-end simulation. |
| 88 |
|
| 89 |
1:: |
| 90 |
Enable full back-end simulation. |
| 91 |
|
| 92 |
|`full_backend_rand_max` |
| 93 |
|If `simulate_full_backend` is 1, maximum random value. |
| 94 |
|
| 95 |
|`full_backend_rand_lt` |
| 96 |
|If `simulate_full_backend` is 1, the back-end is considered full |
| 97 |
if the random value is less than `full_backend_rand_lt`. |
| 98 |
|==== |
| 99 |
|
| 100 |
When `simulate_full_backend` is 1, `full_backend_rand_lt` and |
| 101 |
`full_backend_rand_max` form a ratio. For example, if |
| 102 |
`full_backend_rand_max` is 5 and `full_backend_rand_lt` is 3, then the |
| 103 |
probability of having a full back-end is 3/5. |
| 104 |
|
| 105 |
==== Return |
| 106 |
|
| 107 |
Success:: |
| 108 |
An allocated Linux FS platform context. |
| 109 |
+ |
| 110 |
Call <<api-fini,`+barectf_platform_linux_fs_fini()+`>> to finalize and |
| 111 |
free it. |
| 112 |
|
| 113 |
Failure:: |
| 114 |
`NULL`. |
| 115 |
|
| 116 |
[[api-fini]] |
| 117 |
=== Finalization |
| 118 |
|
| 119 |
==== Prototype |
| 120 |
|
| 121 |
[source,c] |
| 122 |
---- |
| 123 |
void barectf_platform_linux_fs_fini(struct barectf_platform_linux_fs_ctx *ctx); |
| 124 |
---- |
| 125 |
|
| 126 |
==== Parameter |
| 127 |
|
| 128 |
|==== |
| 129 |
|Name |Description |
| 130 |
|
| 131 |
|`ctx` |
| 132 |
|Linux FS platform context to finalize and free. |
| 133 |
|==== |
| 134 |
|
| 135 |
=== barectf context access |
| 136 |
|
| 137 |
==== Prototype |
| 138 |
|
| 139 |
[source,c] |
| 140 |
---- |
| 141 |
struct barectf_default_ctx *barectf_platform_linux_fs_get_barectf_ctx( |
| 142 |
struct barectf_platform_linux_fs_ctx *ctx); |
| 143 |
---- |
| 144 |
|
| 145 |
==== Parameter |
| 146 |
|
| 147 |
|==== |
| 148 |
|Name |Description |
| 149 |
|
| 150 |
|`ctx` |
| 151 |
|Linux FS platform context. |
| 152 |
|==== |
| 153 |
|
| 154 |
==== Return |
| 155 |
|
| 156 |
The barectf context to pass to your tracing functions |
| 157 |
(`+barectf_default_trace_*()+`). |
| 158 |
|
| 159 |
== Usage example |
| 160 |
|
| 161 |
.`config.yaml` |
| 162 |
[source,yaml] |
| 163 |
---- |
| 164 |
--- !<tag:barectf.org,2020/3/config> |
| 165 |
trace: |
| 166 |
type: |
| 167 |
$include: |
| 168 |
- stdint.yaml |
| 169 |
target-byte-order: le |
| 170 |
clock-types: |
| 171 |
default: |
| 172 |
$c-type: uint64_t |
| 173 |
data-stream-types: |
| 174 |
default: |
| 175 |
$is-default: true |
| 176 |
$default-clock-type-name: default |
| 177 |
event-record-types: |
| 178 |
my_event: |
| 179 |
payload-field-type: |
| 180 |
class: struct |
| 181 |
members: |
| 182 |
- number: uint32 |
| 183 |
---- |
| 184 |
|
| 185 |
.`example.c` |
| 186 |
[source,c] |
| 187 |
---- |
| 188 |
#include <assert.h> |
| 189 |
|
| 190 |
#include "barectf-platform-linux-fs.h" |
| 191 |
#include "barectf.h" |
| 192 |
|
| 193 |
int main(void) |
| 194 |
{ |
| 195 |
struct barectf_platform_linux_fs_ctx *platform_ctx; |
| 196 |
struct barectf_default_ctx *barectf_ctx; |
| 197 |
unsigned int i; |
| 198 |
|
| 199 |
platform_ctx = barectf_platform_linux_fs_init(256, "trace/stream", |
| 200 |
0, 0, 0); |
| 201 |
assert(platform_ctx); |
| 202 |
barectf_ctx = barectf_platform_linux_fs_get_barectf_ctx(platform_ctx); |
| 203 |
|
| 204 |
for (i = 0; i < 50; ++i) { |
| 205 |
barectf_trace_my_event(barectf_ctx, i); |
| 206 |
} |
| 207 |
|
| 208 |
barectf_platform_linux_fs_fini(platform_ctx); |
| 209 |
return 0; |
| 210 |
} |
| 211 |
---- |
| 212 |
|
| 213 |
.Command lines to build and execute the example |
| 214 |
---- |
| 215 |
$ mkdir trace |
| 216 |
$ barectf --metadata-dir=trace config.yaml |
| 217 |
$ gcc -o example -I. example.c barectf.c barectf-platform-linux-fs.c |
| 218 |
$ ./example |
| 219 |
---- |
| 220 |
|
| 221 |
The complete CTF trace is the `trace` directory. |
| 222 |
|
| 223 |
Read it with https://babeltrace.org/[Babeltrace{nbsp}2], for example: |
| 224 |
|
| 225 |
---- |
| 226 |
$ babeltrace2 trace |
| 227 |
---- |
| 228 |
|
| 229 |
---- |
| 230 |
[20:55:29.539931489] (+?.?????????) my_event: { number = 0 } |
| 231 |
[20:55:29.539932347] (+0.000000858) my_event: { number = 1 } |
| 232 |
[20:55:29.539932698] (+0.000000351) my_event: { number = 2 } |
| 233 |
[20:55:29.539932985] (+0.000000287) my_event: { number = 3 } |
| 234 |
[20:55:29.539933379] (+0.000000394) my_event: { number = 4 } |
| 235 |
[20:55:29.539933684] (+0.000000305) my_event: { number = 5 } |
| 236 |
... |
| 237 |
[20:55:29.539965071] (+0.000000277) my_event: { number = 44 } |
| 238 |
[20:55:29.539965356] (+0.000000285) my_event: { number = 45 } |
| 239 |
[20:55:29.539965622] (+0.000000266) my_event: { number = 46 } |
| 240 |
[20:55:29.539965903] (+0.000000281) my_event: { number = 47 } |
| 241 |
[20:55:29.539966181] (+0.000000278) my_event: { number = 48 } |
| 242 |
[20:55:29.539966518] (+0.000000337) my_event: { number = 49 } |
| 243 |
---- |