NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
app_shield_agent_core.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2024 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 #include <stdlib.h>
26 #include <unistd.h>
27 
28 #include <doca_argp.h>
29 #include <doca_log.h>
30 
31 #include <samples/common.h>
32 
33 #include <utils.h>
34 
35 #include "app_shield_agent_core.h"
36 
37 DOCA_LOG_REGISTER(APSH_APP::Core);
38 
39 /* This value is guaranteed to be 253 on Linux, and 16 bytes on Windows */
40 #define MAX_HOSTNAME_LEN 253
41 
42 /*
43  * ARGP Callback - Handle target process PID parameter
44  *
45  * @param [in]: Input parameter
46  * @config [in/out]: Program configuration context
47  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
48  */
49 static doca_error_t pid_callback(void *param, void *config)
50 {
51  struct apsh_config *conf = (struct apsh_config *)config;
52 
53  conf->pid = *(DOCA_APSH_PROCESS_PID_TYPE *)param;
54  return DOCA_SUCCESS;
55 }
56 
57 /*
58  * ARGP Callback - Handle hash.zip path parameter
59  *
60  * @param [in]: Input parameter
61  * @config [in/out]: Program configuration context
62  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
63  */
64 static doca_error_t hash_map_callback(void *param, void *config)
65 {
66  struct apsh_config *conf = (struct apsh_config *)config;
67  size_t size = sizeof(conf->exec_hash_map_path);
68 
69  if (strnlen(param, size) >= size) {
70  DOCA_LOG_ERR("Execute hash map argument too long, must be <=%zu long", size - 1);
72  }
73  strcpy(conf->exec_hash_map_path, param);
74 
75  if (access(conf->exec_hash_map_path, F_OK) == -1) {
76  DOCA_LOG_ERR("Execute hash map json file not found %s", conf->exec_hash_map_path);
77  return DOCA_ERROR_NOT_FOUND;
78  }
79  return DOCA_SUCCESS;
80 }
81 
82 /*
83  * ARGP Callback - Handle mem_regions.json path parameter
84  *
85  * @param [in]: Input parameter
86  * @config [in/out]: Program configuration context
87  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
88  */
89 static doca_error_t memr_callback(void *param, void *config)
90 {
91  struct apsh_config *conf = (struct apsh_config *)config;
92  size_t size = sizeof(conf->system_mem_region_path);
93 
94  if (strnlen(param, size) >= size) {
95  DOCA_LOG_ERR("System memory regions map argument too long, must be <=%zu long", size - 1);
97  }
98  strcpy(conf->system_mem_region_path, param);
99 
100  if (access(conf->system_mem_region_path, F_OK) == -1) {
101  DOCA_LOG_ERR("System memory regions map json file not found %s", conf->system_mem_region_path);
102  return DOCA_ERROR_NOT_FOUND;
103  }
104  return DOCA_SUCCESS;
105 }
106 
107 /*
108  * ARGP Callback - Handle VUID parameter
109  *
110  * @param [in]: Input parameter
111  * @config [in/out]: Program configuration context
112  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
113  */
114 static doca_error_t vuid_callback(void *param, void *config)
115 {
116  struct apsh_config *conf = (struct apsh_config *)config;
117  size_t size = sizeof(conf->system_vuid);
118 
119  if (strnlen(param, size) >= size) {
120  DOCA_LOG_ERR("System VUID argument too long, must be <=%zu long", size - 1);
122  }
123  strcpy(conf->system_vuid, param);
124  return DOCA_SUCCESS;
125 }
126 
127 /*
128  * ARGP Callback - Handle DMA device name parameter
129  *
130  * @param [in]: Input parameter
131  * @config [in/out]: Program configuration context
132  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
133  */
134 static doca_error_t dma_callback(void *param, void *config)
135 {
136  struct apsh_config *conf = (struct apsh_config *)config;
137  size_t size = sizeof(conf->dma_dev_name);
138 
139  if (strnlen(param, size) >= size) {
140  DOCA_LOG_ERR("DMA device name argument too long, must be <=%zu long", size - 1);
142  }
143  strcpy(conf->dma_dev_name, param);
144  return DOCA_SUCCESS;
145 }
146 
147 /*
148  * ARGP Callback - Handle os_symbols.json path parameter
149  *
150  * @param [in]: Input parameter
151  * @config [in/out]: Program configuration context
152  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
153  */
154 static doca_error_t os_syms_callback(void *param, void *config)
155 {
156  struct apsh_config *conf = (struct apsh_config *)config;
157  size_t size = sizeof(conf->system_os_symbol_map_path);
158 
159  if (strnlen(param, size) >= size) {
160  DOCA_LOG_ERR("System os symbols map argument too long, must be <=%zu long", size - 1);
162  }
163  strcpy(conf->system_os_symbol_map_path, param);
164 
165  if (access(conf->system_os_symbol_map_path, F_OK) == -1) {
166  DOCA_LOG_ERR("System os symbols map json file not found %s", conf->system_os_symbol_map_path);
167  return DOCA_ERROR_NOT_FOUND;
168  }
169  return DOCA_SUCCESS;
170 }
171 
172 /*
173  * ARGP Callback - Handle target OS type parameter
174  *
175  * @param [in]: Input parameter
176  * @config [in/out]: Program configuration context
177  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
178  */
179 static doca_error_t os_type_callback(void *param, void *config)
180 {
181  struct apsh_config *conf = (struct apsh_config *)config;
182  char *str_param = (char *)param;
183 
184  if (!strcasecmp(str_param, "windows"))
186  else if (!strcasecmp(str_param, "linux"))
188  else {
189  DOCA_LOG_ERR("OS type is not windows/linux (case insensitive)");
191  }
192  return DOCA_SUCCESS;
193 }
194 
195 /*
196  * ARGP Callback - Handle time between attestations parameter
197  *
198  * @param [in]: Input parameter
199  * @config [in/out]: Program configuration context
200  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
201  */
202 static doca_error_t time_callback(void *param, void *config)
203 {
204  struct apsh_config *conf = (struct apsh_config *)config;
205 
206  conf->time_interval = *(int *)param;
207  return DOCA_SUCCESS;
208 }
209 
211 {
213  struct doca_argp_param *pid_param, *hash_map_param, *memr_param, *vuid_param, *dma_param, *os_syms_param;
214  struct doca_argp_param *time_param, *os_type_param;
215 
216  /* Create and register pid param */
217  result = doca_argp_param_create(&pid_param);
218  if (result != DOCA_SUCCESS) {
219  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
220  return result;
221  }
222  doca_argp_param_set_short_name(pid_param, "p");
223  doca_argp_param_set_long_name(pid_param, "pid");
224  doca_argp_param_set_description(pid_param, "Process ID of process to be attested");
228  result = doca_argp_register_param(pid_param);
229  if (result != DOCA_SUCCESS) {
230  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
231  return result;
232  }
233 
234  /* Create and register process hash map param for attestation */
235  result = doca_argp_param_create(&hash_map_param);
236  if (result != DOCA_SUCCESS) {
237  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
238  return result;
239  }
240  doca_argp_param_set_short_name(hash_map_param, "e");
241  doca_argp_param_set_long_name(hash_map_param, "ehm");
242  doca_argp_param_set_arguments(hash_map_param, "<path>");
243  doca_argp_param_set_description(hash_map_param, "Exec hash map path");
246  doca_argp_param_set_mandatory(hash_map_param);
247  result = doca_argp_register_param(hash_map_param);
248  if (result != DOCA_SUCCESS) {
249  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
250  return result;
251  }
252 
253  /* Create and register system memory map param */
254  result = doca_argp_param_create(&memr_param);
255  if (result != DOCA_SUCCESS) {
256  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
257  return result;
258  }
259  doca_argp_param_set_short_name(memr_param, "m");
260  doca_argp_param_set_long_name(memr_param, "memr");
261  doca_argp_param_set_arguments(memr_param, "<path>");
262  doca_argp_param_set_description(memr_param, "System memory regions map");
265  doca_argp_param_set_mandatory(memr_param);
266  result = doca_argp_register_param(memr_param);
267  if (result != DOCA_SUCCESS) {
268  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
269  return result;
270  }
271 
272  /* Create and register VUID param */
273  result = doca_argp_param_create(&vuid_param);
274  if (result != DOCA_SUCCESS) {
275  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
276  return result;
277  }
278  doca_argp_param_set_short_name(vuid_param, "f");
279  doca_argp_param_set_long_name(vuid_param, "vuid");
280  doca_argp_param_set_description(vuid_param, "VUID of the System device");
283  doca_argp_param_set_mandatory(vuid_param);
284  result = doca_argp_register_param(vuid_param);
285  if (result != DOCA_SUCCESS) {
286  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
287  return result;
288  }
289 
290  /* Create and register DMA param */
291  result = doca_argp_param_create(&dma_param);
292  if (result != DOCA_SUCCESS) {
293  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
294  return result;
295  }
296  doca_argp_param_set_short_name(dma_param, "d");
297  doca_argp_param_set_long_name(dma_param, "dma");
298  doca_argp_param_set_description(dma_param, "DMA device name");
302  result = doca_argp_register_param(dma_param);
303  if (result != DOCA_SUCCESS) {
304  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
305  return result;
306  }
307 
308  /* Create and register system OS map param */
309  result = doca_argp_param_create(&os_syms_param);
310  if (result != DOCA_SUCCESS) {
311  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
312  return result;
313  }
314  doca_argp_param_set_short_name(os_syms_param, "o");
315  doca_argp_param_set_long_name(os_syms_param, "osym");
316  doca_argp_param_set_arguments(os_syms_param, "<path>");
317  doca_argp_param_set_description(os_syms_param, "System OS symbol map path");
320  doca_argp_param_set_mandatory(os_syms_param);
321  result = doca_argp_register_param(os_syms_param);
322  if (result != DOCA_SUCCESS) {
323  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
324  return result;
325  }
326 
327  /* Create and register system OS type param */
328  result = doca_argp_param_create(&os_type_param);
329  if (result != DOCA_SUCCESS) {
330  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
331  return result;
332  }
333  doca_argp_param_set_short_name(os_type_param, "s");
334  doca_argp_param_set_long_name(os_type_param, "osty");
335  doca_argp_param_set_arguments(os_type_param, "<windows|linux>");
336  doca_argp_param_set_description(os_type_param, "System OS type - windows/linux");
339  doca_argp_param_set_mandatory(os_type_param);
340  result = doca_argp_register_param(os_type_param);
341  if (result != DOCA_SUCCESS) {
342  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
343  return result;
344  }
345 
346  /* Create and register time interval param */
347  result = doca_argp_param_create(&time_param);
348  if (result != DOCA_SUCCESS) {
349  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
350  return result;
351  }
352  doca_argp_param_set_short_name(time_param, "t");
353  doca_argp_param_set_long_name(time_param, "time");
354  doca_argp_param_set_arguments(time_param, "<seconds>");
355  doca_argp_param_set_description(time_param, "Scan time interval in seconds");
358  doca_argp_param_set_mandatory(time_param);
359  result = doca_argp_register_param(time_param);
360  if (result != DOCA_SUCCESS) {
361  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
362  return result;
363  }
364 
366  if (result != DOCA_SUCCESS) {
367  DOCA_LOG_ERR("Failed to register version callback: %s", doca_error_get_descr(result));
368  return result;
369  }
370  return DOCA_SUCCESS;
371 }
372 
373 /*
374  * Creates and starts a DOCA Apsh context, in order to make the library usable.
375  *
376  * @conf [in]: Configuration used for init process
377  * @resources [out]: Memory storage for the context pointer
378  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
379  *
380  * @NOTE: On failure all lib Apsh resources are freed
381  */
383 {
385 
386  /* Create a new apsh context */
387  resources->ctx = doca_apsh_create();
388  if (resources->ctx == NULL) {
389  DOCA_LOG_ERR("Create lib APSH context failed");
391  }
392 
393  /* Get dma device */
395  strlen(conf->dma_dev_name),
396  NULL,
397  &resources->dma_device);
398  if (result != DOCA_SUCCESS) {
400  DOCA_LOG_ERR("Failed to open dma device");
401  return result;
402  }
403 
404  /* Start apsh context */
405  /* set the DMA device */
406  result = doca_apsh_dma_dev_set(resources->ctx, resources->dma_device);
407  if (result != DOCA_SUCCESS) {
409  DOCA_LOG_ERR("Set dma device failed");
410  return result;
411  }
412 
413  /* Start apsh handler and init connection to devices */
415  if (result != DOCA_SUCCESS) {
417  DOCA_LOG_ERR("Start APSH failed");
418  return result;
419  }
420 
421  /* return value */
422  return DOCA_SUCCESS;
423 }
424 
425 /*
426  * Creates and starts a DOCA Apsh System context, in order to apply the library on a specific target system.
427  *
428  * @conf [in]: Configuration used for init process
429  * @resources [out]: Memory storage for the system context pointer
430  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
431  *
432  * @NOTE: On failure all lib Apsh resources are freed
433  */
435 {
437 
440  (uint8_t *)conf->system_vuid,
441  strlen(conf->system_vuid),
442  &resources->system_device);
443  if (result != DOCA_SUCCESS) {
445  DOCA_LOG_ERR("Failed to open representor device");
446  return result;
447  }
448 
449  /* Create a new system handler to introspect */
451  if (resources->sys == NULL) {
453  DOCA_LOG_ERR("Create system context failed");
454  return result;
455  }
456 
457  /* Start system context - bare-metal */
458  /* Set the system os symbol map */
460  if (result != DOCA_SUCCESS) {
462  DOCA_LOG_ERR("Set os symbols map failed");
463  return result;
464  }
465 
466  /* Set the system memory region the apsh handler is allowed to access */
468  if (result != DOCA_SUCCESS) {
470  DOCA_LOG_ERR("Set mem regions map failed");
471  return result;
472  }
473 
474  /* Set the system device for the apsh handler to use */
475  result = doca_apsh_sys_dev_set(resources->sys, resources->system_device);
476  if (result != DOCA_SUCCESS) {
478  DOCA_LOG_ERR("Set system device failed");
479  return result;
480  }
481 
482  /* Set the system os type - linux/widows */
484  if (result != DOCA_SUCCESS) {
486  DOCA_LOG_ERR("Set system os type failed");
487  return result;
488  }
489 
490  /* Start system handler and init connection to the system and the devices */
492  if (result != DOCA_SUCCESS) {
494  DOCA_LOG_ERR("Start system failed");
495  return result;
496  }
497 
498  /* return value */
499  return DOCA_SUCCESS;
500 }
501 
503 {
505  /* Init basic apsh handlers */
506  memset(resources, 0, sizeof(*resources));
507  result = apsh_ctx_init(conf, resources);
508  if (result != DOCA_SUCCESS)
509  return result;
511  if (result != DOCA_SUCCESS)
512  return result;
513  return DOCA_SUCCESS;
514 }
515 
517 {
518  /* free the system handler and disconnect from the devices */
519  if (resources->sys != NULL) {
521  resources->sys = NULL;
522  }
523 
524  /* free the apsh handler and disconnect from the devices */
525  if (resources->ctx != NULL) {
527  resources->ctx = NULL;
528  }
529 
530  /* Close the devices */
531  if (resources->dma_device != NULL) {
532  doca_dev_close(resources->dma_device);
533  resources->dma_device = NULL;
534  }
535  if (resources->system_device != NULL) {
536  doca_dev_rep_close(resources->system_device);
537  resources->system_device = NULL;
538  }
539 }
540 
542  struct apsh_config *apsh_conf,
543  struct doca_apsh_process ***pslist,
544  struct doca_apsh_process **process)
545 {
546  struct doca_apsh_process **processes;
548  int proc_count, process_idx;
549  typeof(apsh_conf->pid) cur_proc_pid = 0;
550 
551  /* Create list of processes on remote system */
552  result = doca_apsh_processes_get(resources->sys, &processes, &proc_count);
553  if (result == DOCA_SUCCESS)
554  *pslist = processes;
555  else {
557  DOCA_LOG_ERR("Get processes failed");
558  return result;
559  }
560 
561  /* Search for the process 'pid' */
562  for (process_idx = 0; process_idx < proc_count; process_idx++) {
563  cur_proc_pid = doca_apsh_process_info_get(processes[process_idx], DOCA_APSH_PROCESS_PID);
564 
565  if (apsh_conf->pid == cur_proc_pid) {
566  *process = processes[process_idx];
567  break;
568  }
569  }
570  if (*process == NULL) {
571  doca_apsh_processes_free(processes);
573  DOCA_LOG_ERR("Process (%d) was not found", apsh_conf->pid);
574  return DOCA_ERROR_NOT_FOUND;
575  }
576 
577  *pslist = processes;
578  return DOCA_SUCCESS;
579 }
580 
581 /*
582  * Register an attestation event to the Telemetry schema
583  *
584  * @schema [in]: Created DOCA Telemetry schema
585  * @type_index [out]: Memory storage for the Telemetry index created for the event
586  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
587  */
588 static doca_error_t telemetry_register_attest_event(struct doca_telemetry_exporter_schema *schema,
590 {
592  /* Event type for schema. Should be consistent with event struct */
593  struct doca_telemetry_exporter_type *type;
594  struct doca_telemetry_exporter_field *field;
595  const int nb_fields = 5;
596  int idx = 0;
597  struct {
598  const char *name;
599  const char *desc;
600  const char *type_name;
601  uint16_t len;
602  } fields_info[] = {
603  {"timestamp", "Event timestamp", DOCA_TELEMETRY_EXPORTER_FIELD_TYPE_TIMESTAMP, 1},
604  {"pid", "Pid", DOCA_TELEMETRY_EXPORTER_FIELD_TYPE_INT32, 1},
605  {"result", "Result", DOCA_TELEMETRY_EXPORTER_FIELD_TYPE_INT32, 1},
606  {"scan_count", "Scan Count", DOCA_TELEMETRY_EXPORTER_FIELD_TYPE_UINT64, 1},
608  };
609 
611  if (result != DOCA_SUCCESS)
612  return result;
613 
614  for (idx = 0; idx < nb_fields; idx++) {
616  if (result != DOCA_SUCCESS) {
617  DOCA_LOG_ERR("Failed to create field");
619  return result;
620  }
621  doca_telemetry_exporter_field_set_name(field, fields_info[idx].name);
622  doca_telemetry_exporter_field_set_description(field, fields_info[idx].desc);
623  doca_telemetry_exporter_field_set_type_name(field, fields_info[idx].type_name);
624  doca_telemetry_exporter_field_set_array_len(field, fields_info[idx].len);
625 
627  if (result != DOCA_SUCCESS) {
628  DOCA_LOG_ERR("Failed to add field to type");
631  return result;
632  }
633  }
634 
635  /* Register type */
636  result = doca_telemetry_exporter_schema_add_type(schema, "attestation_event", type, type_index);
637  if (result != DOCA_SUCCESS) {
638  DOCA_LOG_ERR("Failed to add type to schema");
640  }
641  return result;
642 }
643 
644 doca_error_t telemetry_start(struct doca_telemetry_exporter_schema **telemetry_schema,
645  struct doca_telemetry_exporter_source **telemetry_source,
646  struct event_indexes *indexes)
647 {
649  struct doca_telemetry_exporter_schema *schema = NULL;
650  struct doca_telemetry_exporter_source *source = NULL;
651  char source_id_buf[MAX_HOSTNAME_LEN + 1], source_tag_buf[MAX_HOSTNAME_LEN + strlen("_tag") + 1];
652 
653  /* Creating telemetry schema */
654  result = doca_telemetry_exporter_schema_init("app_shield_agent_telemetry", &schema);
655  if (result != DOCA_SUCCESS) {
656  DOCA_LOG_ERR("Failed to init the doca telemetry schema");
657  return result;
658  }
659 
660  /* Register all currently supported events */
662  if (result != DOCA_SUCCESS) {
663  DOCA_LOG_ERR("Failed to register attestation event in the telemetry schema");
664  goto schema_error;
665  }
666 
667  /* Enable file write during the app development.
668  * Check written files under data root to make sure that data format is correct.
669  * Default max_file_size is 1 Mb, default max_file_age is 1 hour.
670  */
673  doca_telemetry_exporter_schema_set_file_write_max_age(schema, 60 * 60 * 1000000L);
674 
675  /* Activate the schema */
677  if (result != DOCA_SUCCESS) {
678  DOCA_LOG_ERR("Failed to start the doca telemetry schema");
679  goto schema_error;
680  }
681 
682  /* Open a telemetry connection with custom source id and tag */
684  if (result != DOCA_SUCCESS) {
685  DOCA_LOG_ERR("Failed to create a source end point to the telemetry");
686  goto schema_error;
687  }
688 
689  /* Creating a unique tag and id per host */
690  if (gethostname(source_id_buf, sizeof(source_id_buf)) < 0) {
691  DOCA_LOG_ERR("Gethostname failed, can't create a unique source tag and id");
693  goto source_error;
694  }
695 
696  strlcpy(source_tag_buf, source_id_buf, sizeof(source_tag_buf));
697  strlcat(source_tag_buf, "_tag", sizeof(source_tag_buf));
698  doca_telemetry_exporter_source_set_id(source, source_id_buf);
699  doca_telemetry_exporter_source_set_tag(source, source_tag_buf);
700 
701  /* Initiate the DOCA telemetry source */
703  if (result != DOCA_SUCCESS) {
704  DOCA_LOG_ERR("Failed to establish a source connection to the telemetry");
705  goto source_error;
706  }
707 
708  /* Success init, return handlers */
709  *telemetry_schema = schema;
710  *telemetry_source = source;
711  return DOCA_SUCCESS;
712 
713 source_error:
715 schema_error:
717  return result;
718 }
719 
720 void telemetry_destroy(struct doca_telemetry_exporter_schema *telemetry_schema,
721  struct doca_telemetry_exporter_source *telemetry_source)
722 {
723  doca_telemetry_exporter_source_destroy(telemetry_source);
724  doca_telemetry_exporter_schema_destroy(telemetry_schema);
725 }
#define NULL
Definition: __stddef_null.h:26
static doca_error_t time_callback(void *param, void *config)
static doca_error_t os_syms_callback(void *param, void *config)
static doca_error_t os_type_callback(void *param, void *config)
doca_error_t get_process_by_pid(struct apsh_resources *resources, struct apsh_config *apsh_conf, struct doca_apsh_process ***pslist, struct doca_apsh_process **process)
doca_error_t app_shield_agent_init(struct apsh_config *conf, struct apsh_resources *resources)
static doca_error_t memr_callback(void *param, void *config)
static doca_error_t dma_callback(void *param, void *config)
static doca_error_t telemetry_register_attest_event(struct doca_telemetry_exporter_schema *schema, doca_telemetry_exporter_type_index_t *type_index)
static doca_error_t pid_callback(void *param, void *config)
static doca_error_t apsh_ctx_init(struct apsh_config *conf, struct apsh_resources *resources)
doca_error_t telemetry_start(struct doca_telemetry_exporter_schema **telemetry_schema, struct doca_telemetry_exporter_source **telemetry_source, struct event_indexes *indexes)
void app_shield_agent_cleanup(struct apsh_resources *resources)
static doca_error_t apsh_system_init(struct apsh_config *conf, struct apsh_resources *resources)
static doca_error_t vuid_callback(void *param, void *config)
#define MAX_HOSTNAME_LEN
DOCA_LOG_REGISTER(APSH_APP::Core)
doca_error_t register_apsh_params(void)
void telemetry_destroy(struct doca_telemetry_exporter_schema *telemetry_schema, struct doca_telemetry_exporter_source *telemetry_source)
static doca_error_t hash_map_callback(void *param, void *config)
int32_t result
#define MAX_PATH_LEN
doca_error_t pslist(const char *dma_device_name, const char *pci_vuid, enum doca_apsh_system_os os_type, const char *mem_region, const char *os_symbols)
doca_error_t open_doca_device_rep_with_vuid(struct doca_dev *local, enum doca_devinfo_rep_filter filter, const uint8_t *value, size_t val_size, struct doca_dev_rep **retval)
Definition: common.c:222
doca_error_t open_doca_device_with_ibdev_name(const uint8_t *value, size_t val_size, tasks_check func, struct doca_dev **retval)
Definition: common.c:84
uint64_t len
if(bitoffset % 64+bitlength > 64) result|
struct rdma_resources resources
uint32_t DOCA_APSH_PROCESS_PID_TYPE
process pid type
@ DOCA_APSH_SYSTEM_WINDOWS
@ DOCA_APSH_SYSTEM_LINUX
@ DOCA_APSH_PROCESS_PID
DOCA_EXPERIMENTAL doca_error_t doca_apsh_sys_mem_region_set(struct doca_apsh_system *system, const char *system_mem_region_path)
Set system allowed memory regions.
DOCA_EXPERIMENTAL doca_error_t doca_apsh_sys_dev_set(struct doca_apsh_system *system, struct doca_dev_rep *dev)
Set system device.
DOCA_EXPERIMENTAL doca_error_t doca_apsh_processes_get(struct doca_apsh_system *system, struct doca_apsh_process ***processes, int *processes_size)
Get array of current processes running on the system.
DOCA_EXPERIMENTAL doca_error_t doca_apsh_start(struct doca_apsh_ctx *ctx)
Start apsh handler.
DOCA_EXPERIMENTAL doca_error_t doca_apsh_sys_os_type_set(struct doca_apsh_system *system, enum doca_apsh_system_os os_type)
Set system os type.
DOCA_EXPERIMENTAL struct doca_apsh_ctx * doca_apsh_create(void)
Create a new apsh handler.
DOCA_EXPERIMENTAL doca_error_t doca_apsh_dma_dev_set(struct doca_apsh_ctx *ctx, struct doca_dev *dma_dev)
Set apsh dma device.
DOCA_EXPERIMENTAL struct doca_apsh_system * doca_apsh_system_create(struct doca_apsh_ctx *ctx)
Create a new system handler.
DOCA_EXPERIMENTAL doca_error_t doca_apsh_sys_os_symbol_map_set(struct doca_apsh_system *system, const char *system_os_symbol_map_path)
Set system os symbol map.
DOCA_EXPERIMENTAL void doca_apsh_destroy(struct doca_apsh_ctx *ctx)
Free the APSH memory and close connections.
#define doca_apsh_process_info_get(process, attr)
Get attribute value for a process.
Definition: doca_apsh.h:618
DOCA_EXPERIMENTAL void doca_apsh_processes_free(struct doca_apsh_process **processes)
Destroys a process context.
DOCA_EXPERIMENTAL void doca_apsh_system_destroy(struct doca_apsh_system *system)
Destroy system handler.
DOCA_EXPERIMENTAL doca_error_t doca_apsh_system_start(struct doca_apsh_system *system)
Start system handler.
DOCA_EXPERIMENTAL void doca_argp_param_set_description(struct doca_argp_param *param, const char *description)
Set the description of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_long_name(struct doca_argp_param *param, const char *name)
Set the long name of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_arguments(struct doca_argp_param *param, const char *arguments)
Set the description of the expected arguments of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_callback(struct doca_argp_param *param, doca_argp_param_cb_t callback)
Set the callback function of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_mandatory(struct doca_argp_param *param)
Mark the program param as mandatory.
DOCA_EXPERIMENTAL doca_error_t doca_argp_param_create(struct doca_argp_param **param)
Create new program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_type(struct doca_argp_param *param, enum doca_argp_type type)
Set the type of the param arguments.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_version_callback(doca_argp_param_cb_t callback)
Register an alternative version callback.
DOCA_EXPERIMENTAL void doca_argp_param_set_short_name(struct doca_argp_param *param, const char *name)
Set the short name of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_param(struct doca_argp_param *input_param)
Register a program flag.
@ DOCA_ARGP_TYPE_STRING
Definition: doca_argp.h:56
@ DOCA_ARGP_TYPE_INT
Definition: doca_argp.h:57
DOCA_STABLE doca_error_t doca_dev_rep_close(struct doca_dev_rep *dev)
Destroy allocated representor device instance.
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
@ DOCA_DEVINFO_REP_FILTER_NET
Definition: doca_dev.h:67
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
Definition: doca_error.h:44
@ DOCA_ERROR_INITIALIZATION
Definition: doca_error.h:46
@ DOCA_ERROR_OPERATING_SYSTEM
Definition: doca_error.h:58
@ DOCA_ERROR_NOT_FOUND
Definition: doca_error.h:54
@ DOCA_ERROR_NOT_SUPPORTED
Definition: doca_error.h:42
@ DOCA_SUCCESS
Definition: doca_error.h:38
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_TELEMETRY_EXPORTER_FIELD_TYPE_TIMESTAMP
DOCA telemetry timestamp type.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_schema_init(const char *schema_name, struct doca_telemetry_exporter_schema **doca_schema)
Initialize DOCA schema to prepare it for setting attributes and adding types. DOCA schema is used to ...
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_type_destroy(struct doca_telemetry_exporter_type *type)
Destroy doca telemetry type previously created by doca_telemetry_exporter_type_create()
DOCA_EXPERIMENTAL void doca_telemetry_exporter_field_set_type_name(struct doca_telemetry_exporter_field *field_info, const char *type)
Set doca telemetry field type.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_source_destroy(struct doca_telemetry_exporter_source *doca_source)
Destructor for DOCA source.
DOCA_EXPERIMENTAL void doca_telemetry_exporter_field_set_description(struct doca_telemetry_exporter_field *field_info, const char *desc)
Set doca telemetry field description.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_field_destroy(struct doca_telemetry_exporter_field *field)
Destroy field previously created by doca_telemetry_exporter_field_create()
#define DOCA_TELEMETRY_EXPORTER_FIELD_TYPE_INT32
DOCA telemetry int32 type.
DOCA_EXPERIMENTAL void doca_telemetry_exporter_source_set_id(struct doca_telemetry_exporter_source *doca_source, const char *source_id)
Set source id.
#define DOCA_TELEMETRY_EXPORTER_FIELD_TYPE_UINT64
DOCA telemetry uint64 type.
uint8_t doca_telemetry_exporter_type_index_t
DOCA schema field type index.
DOCA_EXPERIMENTAL void doca_telemetry_exporter_field_set_array_len(struct doca_telemetry_exporter_field *field_info, uint16_t len)
Set doca telemetry field length.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_schema_add_type(struct doca_telemetry_exporter_schema *doca_schema, const char *new_type_name, struct doca_telemetry_exporter_type *type, doca_telemetry_exporter_type_index_t *type_index)
Add user-defined fields to create new type in DOCA schema. The users loses the ownership of the type ...
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_source_create(struct doca_telemetry_exporter_schema *doca_schema, struct doca_telemetry_exporter_source **doca_source)
Creates a single DOCA source from schema.
DOCA_EXPERIMENTAL void doca_telemetry_exporter_field_set_name(struct doca_telemetry_exporter_field *field_info, const char *name)
Set doca telemetry field name.
#define DOCA_TELEMETRY_EXPORTER_FIELD_TYPE_CHAR
DOCA telemetry char type.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_type_create(struct doca_telemetry_exporter_type **type)
Create new telemetry type.
DOCA_EXPERIMENTAL void doca_telemetry_exporter_schema_set_file_write_max_age(struct doca_telemetry_exporter_schema *doca_schema, doca_telemetry_exporter_timestamp_t max_age)
Set file maximum age Default value is 1 hour.
DOCA_EXPERIMENTAL void doca_telemetry_exporter_source_set_tag(struct doca_telemetry_exporter_source *doca_source, const char *source_tag)
Set source tag.
DOCA_EXPERIMENTAL void doca_telemetry_exporter_schema_set_file_write_max_size(struct doca_telemetry_exporter_schema *doca_schema, size_t size)
Set file maximum size Default value is 1MB.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_field_create(struct doca_telemetry_exporter_field **field)
Create new telemetry field.
DOCA_EXPERIMENTAL void doca_telemetry_exporter_schema_set_file_write_enabled(struct doca_telemetry_exporter_schema *doca_schema)
Enable file write file write is disabled by default.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_schema_destroy(struct doca_telemetry_exporter_schema *doca_schema)
Destructor for DOCA schema.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_schema_start(struct doca_telemetry_exporter_schema *doca_schema)
Finalizes schema setup to start creating Doca Sources from the schema.
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_type_add_field(struct doca_telemetry_exporter_type *type, struct doca_telemetry_exporter_field *field)
Add DOCA telemetry field to type. The users loses the ownership of the field after a successful invoc...
DOCA_EXPERIMENTAL doca_error_t doca_telemetry_exporter_source_start(struct doca_telemetry_exporter_source *doca_source)
Applies source attribute and starts DOCA source.
uint8_t type
Definition: packets.h:0
char system_vuid[DOCA_DEVINFO_VUID_SIZE+1]
char exec_hash_map_path[MAX_PATH_LEN]
DOCA_APSH_PROCESS_PID_TYPE pid
char dma_dev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE+1]
char system_mem_region_path[MAX_PATH_LEN]
char system_os_symbol_map_path[MAX_PATH_LEN]
enum doca_apsh_system_os os_type
doca_telemetry_exporter_type_index_t attest_index
size_t strlcat(char *dst, const char *src, size_t size)
Definition: utils.c:144
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: utils.c:123
noreturn doca_error_t sdk_version_callback(void *param, void *doca_config)
Definition: utils.c:41