NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
file_integrity.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-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 
26 #include <string.h>
27 
28 #include <doca_argp.h>
29 #include <doca_log.h>
30 
31 #include <utils.h>
32 
33 #include "file_integrity_core.h"
34 
35 #define SERVER_NAME ("file_integrity_server") /* Comch server name */
36 
37 DOCA_LOG_REGISTER(FILE_INTEGRITY);
38 
39 /*
40  * File Integrity application main function
41  *
42  * @argc [in]: command line arguments size
43  * @argv [in]: array of command line arguments
44  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
45  */
46 int main(int argc, char **argv)
47 {
49  .mode = NO_VALID_INPUT,
50  };
51 
52  struct comch_cfg *comch_cfg;
53  struct doca_sha *sha_ctx = NULL;
54  struct program_core_objects state = {0};
56  struct doca_log_backend *sdk_log;
57  int exit_status = EXIT_SUCCESS;
58 
59 #ifdef DOCA_ARCH_HOST
60  app_cfg.mode = CLIENT;
61 #else
62  app_cfg.mode = SERVER;
63 #endif
64 
65  /* Register a logger backend */
67  if (result != DOCA_SUCCESS)
68  return EXIT_FAILURE;
69 
70  /* Register a logger backend for internal SDK errors and warnings */
72  if (result != DOCA_SUCCESS)
73  return EXIT_FAILURE;
75  if (result != DOCA_SUCCESS)
76  return EXIT_FAILURE;
77 
78  /* Parse cmdline/json arguments */
80  if (result != DOCA_SUCCESS) {
81  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
82  return EXIT_FAILURE;
83  }
84 
86  if (result != DOCA_SUCCESS) {
87  DOCA_LOG_ERR("Failed to register application params: %s", doca_error_get_descr(result));
88  exit_status = EXIT_FAILURE;
89  goto destroy_argp;
90  }
91 
92  result = doca_argp_start(argc, argv);
93  if (result != DOCA_SUCCESS) {
94  DOCA_LOG_ERR("Failed to parse application input: %s", doca_error_get_descr(result));
95  exit_status = EXIT_FAILURE;
96  goto destroy_argp;
97  }
98 
99  result = file_integrity_init(&app_cfg, &state, &sha_ctx);
100  if (result != DOCA_SUCCESS) {
101  exit_status = EXIT_FAILURE;
102  goto destroy_argp;
103  }
104 
106  app_cfg.cc_dev_pci_addr,
107  app_cfg.cc_dev_rep_pci_addr,
108  &app_cfg,
111  &comch_cfg);
112  if (result != DOCA_SUCCESS) {
113  exit_status = EXIT_FAILURE;
114  goto cleanup_file_integrity;
115  }
116 
117  /* Start client/server logic */
118  if (app_cfg.mode == CLIENT)
119  result = file_integrity_client(comch_cfg, &app_cfg, &state, sha_ctx);
120  else
121  result = file_integrity_server(comch_cfg, &app_cfg, &state, sha_ctx);
122 
123  if (result != DOCA_SUCCESS) {
124  DOCA_LOG_ERR("File integrity encountered errors");
125  exit_status = EXIT_FAILURE;
126  }
127 
129  if (result != DOCA_SUCCESS)
130  DOCA_LOG_ERR("Failed to destroy DOCA Comch");
131 
132 cleanup_file_integrity:
133  file_integrity_cleanup(&state, sha_ctx);
134 destroy_argp:
136 
137  return exit_status;
138 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
doca_error_t comch_utils_destroy(struct comch_cfg *comch_cfg)
Definition: comch_utils.c:592
doca_error_t comch_utils_init(const char *server_name, const char *pci_addr, const char *rep_pci_addr, void *user_data, doca_comch_event_msg_recv_cb_t client_recv_event_cb, doca_comch_event_msg_recv_cb_t server_recv_event_cb, struct comch_cfg **comch_cfg)
Definition: comch_utils.c:573
void server_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
void client_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
@ NO_VALID_INPUT
int main(int argc, char **argv)
DOCA_LOG_REGISTER(FILE_INTEGRITY)
#define SERVER_NAME
doca_error_t register_file_integrity_params(void)
doca_error_t file_integrity_server(struct comch_cfg *comch_cfg, struct file_integrity_config *app_cfg, struct program_core_objects *state, struct doca_sha *sha_ctx)
void file_integrity_cleanup(struct program_core_objects *state, struct doca_sha *sha_ctx)
doca_error_t file_integrity_init(struct file_integrity_config *app_cfg, struct program_core_objects *state, struct doca_sha **sha_ctx)
doca_error_t file_integrity_client(struct comch_cfg *comch_cfg, struct file_integrity_config *app_cfg, struct program_core_objects *state, struct doca_sha *sha_ctx)
static struct app_gpu_cfg app_cfg
DOCA_EXPERIMENTAL doca_error_t doca_argp_start(int argc, char **argv)
Parse incoming arguments (cmd line/json).
DOCA_EXPERIMENTAL doca_error_t doca_argp_init(const char *program_name, void *program_config)
Initialize the parser interface.
DOCA_EXPERIMENTAL doca_error_t doca_argp_destroy(void)
ARG Parser destroy.
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_SUCCESS
Definition: doca_error.h:38
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_standard(void)
Create default, non configurable backend for application messages.
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_with_file_sdk(FILE *fptr, struct doca_log_backend **backend)
Create a logging backend with a FILE* stream for SDK messages.
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_set_sdk_level(struct doca_log_backend *backend, uint32_t level)
Set the log level limit for SDK logging backends.
@ DOCA_LOG_LEVEL_WARNING
Definition: doca_log.h:47