Skip to content

Commit

Permalink
Merge branch 'main' into refactor/make-sockctl-data-const
Browse files Browse the repository at this point in the history
  • Loading branch information
mereacre committed Sep 14, 2022
2 parents 0ffd8de + 99e47d8 commit 3ceef03
Show file tree
Hide file tree
Showing 10 changed files with 545 additions and 66 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
"firewall_config.h": "c",
"crypt_service.h": "c",
"header_middleware.h": "c",
"*.c.in": "c"
"*.c.in": "c",
"pcap.h": "c",
"pcap-inttypes.h": "c",
"bpf.h": "c",
"types.h": "c",
"time_t.h": "c"
}
}
41 changes: 41 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@
"BUILD_OPENSSL_LIB": false
}
},
{
"name": "linux/header",
"inherits": "linux",
"displayName": "Linux Header",
"description": "Linux header (with header middlewares)",
"cacheVariables": {
"USE_CLEANER_MIDDLEWARE": false,
"USE_HEADER_MIDDLEWARE": true,
"USE_PCAP_MIDDLEWARE": false
}
},
{
"name": "recap",
"inherits": "default",
"displayName": "recap tool",
"description": "recap tool",
"cacheVariables": {
"BUILD_MNL_LIB": false,
"BUILD_NETLINK_LIB": false,
"USE_NETLINK_SERVICE": false,
"USE_UCI_SERVICE": false,
"USE_GENERIC_IP_SERVICE": true,
"USE_RADIUS_SERVICE": false,
"BUILD_HOSTAPD": false,
"USE_CRYPTO_SERVICE": false,
"BUILD_OPENSSL_LIB": false,
"USE_HEADER_MIDDLEWARE": true,
"USE_CAPTURE_SERVICE": true,
"BUILD_SQLITE_LIB": true,
"BUILD_UUID_LIB": true,
"BUILD_PCAP_LIB": true
}
},
{
"name": "linux-with-crypt",
"inherits": "linux",
Expand Down Expand Up @@ -152,6 +185,14 @@
"name": "linux",
"configurePreset": "linux"
},
{
"name": "recap",
"configurePreset": "recap"
},
{
"name": "linux/header",
"configurePreset": "linux/header"
},
{
"name": "linux-with-crypt",
"configurePreset": "linux-with-crypt"
Expand Down
10 changes: 7 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ add_subdirectory(supervisor)
add_subdirectory(ap)
add_subdirectory(dhcp)
add_subdirectory(firewall)
if (USE_RADIUS_SERVICE)
add_subdirectory(radius)
endif ()
add_subdirectory(radius EXCLUDE_FROM_ALL)
if (USE_CRYPTO_SERVICE)
add_subdirectory(crypt)
endif ()
Expand Down Expand Up @@ -50,3 +48,9 @@ endif ()
target_link_libraries(edgesec PRIVATE eloop config runctl minIni os hashmap Threads::Threads)
# link time optimization
set_target_properties(edgesec PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)

if (USE_CAPTURE_SERVICE)
add_executable(recap recap.c)
target_link_libraries(recap PRIVATE packet_queue packet_decoder sqlite_header os log SQLite::SQLite3)
target_include_directories(recap PRIVATE ${PROJECT_BINARY_DIR})
endif()
2 changes: 1 addition & 1 deletion src/capture/middleware.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct capture_middleware {
* @retval 0 on success
* @retval -1 on failure
*/
int (*const process)(struct middleware_context *context, char *ltype,
int (*const process)(struct middleware_context *context, const char *ltype,
struct pcap_pkthdr *header, uint8_t *packet,
char *ifname);

Expand Down
6 changes: 3 additions & 3 deletions src/capture/middlewares/header_middleware/header_middleware.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ struct middleware_context *init_header_middleware(sqlite3 *db, char *db_path,
return context;
}

int process_header_middleware(struct middleware_context *context, char *ltype,
struct pcap_pkthdr *header, uint8_t *packet,
char *ifname) {
int process_header_middleware(struct middleware_context *context,
const char *ltype, struct pcap_pkthdr *header,
uint8_t *packet, char *ifname) {
struct packet_queue *queue;
int npackets;
char cap_id[MAX_RANDOM_UUID_LEN];
Expand Down
2 changes: 1 addition & 1 deletion src/capture/middlewares/header_middleware/packet_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ int decode_packet(const struct pcap_pkthdr *header, const uint8_t *packet,
return count;
}

int extract_packets(char *ltype, const struct pcap_pkthdr *header,
int extract_packets(const char *ltype, const struct pcap_pkthdr *header,
const uint8_t *packet, char *interface, char *id,
UT_array *tp_array) {
(void)ltype;
Expand Down
2 changes: 1 addition & 1 deletion src/capture/middlewares/header_middleware/packet_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ struct capture_packet {
* @param tp_array The array of returned packet tuples
* @return int Total count of packet tuples
*/
int extract_packets(char *ltype, const struct pcap_pkthdr *header,
int extract_packets(const char *ltype, const struct pcap_pkthdr *header,
const uint8_t *packet, char *interface, char *id,
UT_array *tp_array);

Expand Down
23 changes: 6 additions & 17 deletions src/edgesec.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <pthread.h>
#include <stdbool.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <libgen.h>
#include <pthread.h>

#include "version.h"
#include "utils/log.h"
Expand Down Expand Up @@ -51,8 +51,6 @@ const char description_string[] =
" credentials/MAC address.\n"
" 6. State machine: Networking monitoring and management.\n";

static __thread char version_buf[10];

pthread_mutex_t log_lock;

void log_lock_fun(bool lock) {
Expand All @@ -74,23 +72,14 @@ void sighup_handler(int sig, void *ctx) {
}
}

char *get_static_version_string(uint8_t major, uint8_t minor, uint8_t patch) {
int ret = snprintf(version_buf, 10, "%d.%d.%d", major, minor, patch);

if (ret < 0) {
fprintf(stderr, "snprintf");
return NULL;
}
void show_app_version(void) {
char buf[32];

return version_buf;
snprintf(buf, ARRAY_SIZE(buf), "%d.%d.%d", EDGESEC_VERSION_MAJOR,
EDGESEC_VERSION_MINOR, EDGESEC_VERSION_PATCH);
fprintf(stdout, "edgesec app version %s\n", buf);
}

void show_app_version(void) {
fprintf(stdout, "edgesec app version %s\n",
get_static_version_string(EDGESEC_VERSION_MAJOR,
EDGESEC_VERSION_MINOR,
EDGESEC_VERSION_PATCH));
}
void show_app_help(char *app_name) {
show_app_version();
fprintf(stdout, "Usage:\n");
Expand Down
Loading

0 comments on commit 3ceef03

Please sign in to comment.