symbol: set public symbols prefix

This commit is contained in:
zhuzhenjun
2023-10-12 15:05:58 +08:00
parent 7e1849233b
commit 8b8627b0d8
13 changed files with 64 additions and 67 deletions

View File

@@ -1,11 +1,11 @@
cmake_minimum_required (VERSION 2.8) cmake_minimum_required (VERSION 2.8)
set(lib_name osfp) set(lib_name MESA_osfp)
project (${lib_name}) project (${lib_name})
set(LIB_MAJOR_VERSION 1) set(LIB_MAJOR_VERSION 1)
set(LIB_MINOR_VERSION 0) set(LIB_MINOR_VERSION 1)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(Version) include(Version)
@@ -55,17 +55,17 @@ set_target_properties(${lib_name}_static PROPERTIES OUTPUT_NAME ${lib_name})
set(CMAKE_INSTALL_PREFIX /opt/MESA) set(CMAKE_INSTALL_PREFIX /opt/MESA)
install(FILES src/osfp.h DESTINATION install(FILES src/MESA_osfp.h DESTINATION
${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT devel) ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT devel)
install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES) install(TARGETS ${lib_name}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
install(FILES src/osfp.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER) install(FILES src/MESA_osfp.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/MESA COMPONENT HEADER)
install(FILES fp.json DESTINATION /var/lib/libosfp COMPONENT PROFILE) install(FILES fp.json DESTINATION /var/lib/MESA_osfp COMPONENT PROFILE)
add_executable(${lib_name}_sample example/sample.c) add_executable(${lib_name}_sample example/sample.c)
target_link_libraries(${lib_name}_sample ${lib_name}_shared) target_link_libraries(${lib_name}_sample ${lib_name}_shared)
add_executable(${lib_name}_example example/osfp_example.c) add_executable(${lib_name}_example example/osfp_example.c)
target_link_libraries(${lib_name}_example ${lib_name}_shared) target_link_libraries(${lib_name}_example ${lib_name}_static)
target_link_libraries(${lib_name}_example pcap) target_link_libraries(${lib_name}_example pcap)
add_executable(${lib_name}_test test/test.c) add_executable(${lib_name}_test test/test.c)
@@ -73,7 +73,7 @@ target_link_libraries(${lib_name}_test ${lib_name}_static)
enable_testing() enable_testing()
add_test(NAME sample COMMAND osfp_sample) add_test(NAME sample COMMAND MESA_osfp_sample)
add_test(NAME test COMMAND osfp_test -f ../fp.json -t ../data.json) add_test(NAME test COMMAND MESA_osfp_test -f ../fp.json -t ../data.json)
include(Package) include(Package)

View File

@@ -7,20 +7,19 @@ Libosfp is a C library for OS fingerprinting.
``` ```
# osfp_example depends on libpcap # osfp_example depends on libpcap
yum install -y libpcap-devel yum install -y libpcap-devel
# build and install BUILD_TYPE=Debug PACKAGE=1 ./ci/travis.sh
./build.sh yum install -y ./build/*.rpm
./package.sh
yum install package/*.rpm
``` ```
## library usage ## library usage
``` ```
gcc -I./src example/sample.c -o sample -L./build -losfp; cat example/sample.c gcc -I./src example/sample.c -o sample -L./build -lMESA_osfp; cat example/sample.c
LD_LIBRARY_PATH=${PWD}/build ./sample
``` ```
## run example ## run example
``` ```
# load the fingerprint file and capture on eth0, filter tcp port 8888 # load the fingerprint file and capture on eth0, filter tcp port 8888
osfp_example -f /var/lib/libosfp/fp.json -i eth0 "tcp port 8888" ./build/MESA_osfp_example -f /var/lib/MESA_osfp/fp.json -i eth0 "tcp port 8888"
``` ```

View File

@@ -10,7 +10,7 @@
#include <pcap.h> #include <pcap.h>
#include "osfp_common.h" #include "osfp_common.h"
#include "osfp.h" #include "MESA_osfp.h"
#include "osfp_log.h" #include "osfp_log.h"
#include "osfp_fingerprint.h" #include "osfp_fingerprint.h"
#include "osfp_score_db.h" #include "osfp_score_db.h"
@@ -450,9 +450,9 @@ void example_detect(struct osfp_db *osfp_db, Packet *p)
osfp_profile_get_cycle(c1); osfp_profile_get_cycle(c1);
if (iph) { if (iph) {
result = osfp_ipv4_identify(osfp_db, iph, tcph, tcph_len); result = MESA_osfp_ipv4_identify(osfp_db, iph, tcph, tcph_len);
} else if (ip6h) { } else if (ip6h) {
result = osfp_ipv6_identify(osfp_db, ip6h, tcph, tcph_len); result = MESA_osfp_ipv6_identify(osfp_db, ip6h, tcph, tcph_len);
} else { } else {
goto exit; goto exit;
} }
@@ -469,19 +469,19 @@ void example_detect(struct osfp_db *osfp_db, Packet *p)
result_os_count[result->likely_os_class]++; result_os_count[result->likely_os_class]++;
char *json = osfp_result_score_detail_export(result); char *json = MESA_osfp_result_score_detail_export(result);
if (1) { if (1) {
printf("Example ipv4 header detect: --------------------------\n"); printf("Example ipv4 header detect: --------------------------\n");
printf("Connection info: %s:%d -> %s:%d\n", p->srcip, p->sp, p->dstip, p->dp); printf("Connection info: %s:%d -> %s:%d\n", p->srcip, p->sp, p->dstip, p->dp);
printf("Most likely os class: %s\n", osfp_result_os_name_get(result)); printf("Most likely os class: %s\n", MESA_osfp_result_os_name_get(result));
printf("Details:\n"); printf("Details:\n");
printf("%s\n", json); printf("%s\n", json);
} }
exit: exit:
if (result) { if (result) {
osfp_result_free(result); MESA_osfp_result_free(result);
} }
return; return;
} }
@@ -670,7 +670,7 @@ int main(int argc, char *argv[])
osfp_profile_set(1); osfp_profile_set(1);
struct osfp_db *osfp_db = osfp_db_new(fp_file_path); struct osfp_db *osfp_db = MESA_osfp_db_new(fp_file_path);
if (osfp_db == NULL) { if (osfp_db == NULL) {
printf("could not create osfp context. fingerprints file: %s\n", fp_file_path); printf("could not create osfp context. fingerprints file: %s\n", fp_file_path);
exit(1); exit(1);
@@ -686,7 +686,7 @@ int main(int argc, char *argv[])
} }
// destroy osfp db // destroy osfp db
osfp_db_free(osfp_db); MESA_osfp_db_free(osfp_db);
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
#include "stdio.h" #include "stdio.h"
#include "osfp.h" #include "MESA_osfp.h"
char iph[] = { char iph[] = {
0x45, 0x00, 0x00, 0x34, 0x51, 0xc4, 0x40, 0x00, 0x45, 0x00, 0x00, 0x34, 0x51, 0xc4, 0x40, 0x00,
@@ -22,14 +22,14 @@ int main(int argc, char **argv)
struct tcphdr *l4_hdr = (struct tcphdr *)tcph; struct tcphdr *l4_hdr = (struct tcphdr *)tcph;
size_t l4_hdr_len = sizeof(tcph); size_t l4_hdr_len = sizeof(tcph);
struct osfp_db *db = osfp_db_new(json_file_path); struct osfp_db *db = MESA_osfp_db_new(json_file_path);
if (db) { if (db) {
struct osfp_result *result = osfp_ipv4_identify(db, l3_hdr, l4_hdr, l4_hdr_len); struct osfp_result *result = MESA_osfp_ipv4_identify(db, l3_hdr, l4_hdr, l4_hdr_len);
if (result) { if (result) {
printf("likely os: %s\n", osfp_result_os_name_get(result)); printf("likely os: %s\n", MESA_osfp_result_os_name_get(result));
printf("details: \n%s\n", osfp_result_score_detail_export(result)); printf("details: \n%s\n", MESA_osfp_result_score_detail_export(result));
osfp_result_free(result); MESA_osfp_result_free(result);
} }
osfp_db_free(db); MESA_osfp_db_free(db);
} }
} }

View File

@@ -1,6 +1,6 @@
#include "osfp_common.h" #include "osfp_common.h"
#include "osfp.h" #include "MESA_osfp.h"
#include "osfp_fingerprint.h" #include "osfp_fingerprint.h"
#include "osfp_score_db.h" #include "osfp_score_db.h"
#include "osfp_log.h" #include "osfp_log.h"
@@ -70,7 +70,7 @@ exit:
return NULL; return NULL;
} }
const char *osfp_result_os_name_get(struct osfp_result *result) const char *MESA_osfp_result_os_name_get(struct osfp_result *result)
{ {
enum osfp_os_class_id os_class; enum osfp_os_class_id os_class;
@@ -86,7 +86,7 @@ const char *osfp_result_os_name_get(struct osfp_result *result)
return osfp_os_class_id_to_name(os_class); return osfp_os_class_id_to_name(os_class);
} }
char *osfp_result_score_detail_export(struct osfp_result *result) char *MESA_osfp_result_score_detail_export(struct osfp_result *result)
{ {
int i; int i;
char *result_str = NULL; char *result_str = NULL;
@@ -150,7 +150,7 @@ exit:
return result_str; return result_str;
} }
void osfp_result_free(struct osfp_result *result) void MESA_osfp_result_free(struct osfp_result *result)
{ {
if (result) { if (result) {
if (result->json_str) { if (result->json_str) {
@@ -160,7 +160,7 @@ void osfp_result_free(struct osfp_result *result)
} }
} }
struct osfp_result *osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len) struct osfp_result *MESA_osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len)
{ {
int ret = OSFP_EINVAL; int ret = OSFP_EINVAL;
struct osfp_fingerprint fp; struct osfp_fingerprint fp;
@@ -203,7 +203,7 @@ exit:
return NULL; return NULL;
} }
struct osfp_result *osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len) struct osfp_result *MESA_osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len)
{ {
int ret = OSFP_EINVAL; int ret = OSFP_EINVAL;
struct osfp_fingerprint fp; struct osfp_fingerprint fp;
@@ -234,7 +234,7 @@ exit:
return NULL; return NULL;
} }
struct osfp_result *osfp_json_identify(struct osfp_db *db, const char *json_str) struct osfp_result *MESA_osfp_json_identify(struct osfp_db *db, const char *json_str)
{ {
int ret = OSFP_EINVAL; int ret = OSFP_EINVAL;
struct osfp_fingerprint fp; struct osfp_fingerprint fp;
@@ -265,7 +265,7 @@ exit:
return NULL; return NULL;
} }
struct osfp_db *osfp_db_new(const char *db_json_file) struct osfp_db *MESA_osfp_db_new(const char *db_json_file)
{ {
int ret; int ret;
struct osfp_db *db; struct osfp_db *db;
@@ -299,12 +299,12 @@ struct osfp_db *osfp_db_new(const char *db_json_file)
return db; return db;
exit: exit:
if (db) { if (db) {
osfp_db_free(db); MESA_osfp_db_free(db);
} }
return NULL; return NULL;
} }
void osfp_db_free(struct osfp_db *db) void MESA_osfp_db_free(struct osfp_db *db)
{ {
if (db) { if (db) {
if (db->db_json_path) { if (db->db_json_path) {

View File

@@ -23,14 +23,14 @@ struct osfp_db;
* @param db_json_path JSON * @param db_json_path JSON
* @return * @return
*/ */
struct osfp_db *osfp_db_new(const char *db_json_path); struct osfp_db *MESA_osfp_db_new(const char *db_json_path);
/** /**
* @brief * @brief
* *
* @param db * @param db
*/ */
void osfp_db_free(struct osfp_db *db); void MESA_osfp_db_free(struct osfp_db *db);
/** /**
* @brief IPv4 TCP * @brief IPv4 TCP
@@ -41,7 +41,7 @@ void osfp_db_free(struct osfp_db *db);
* @param l4_hdr_len TCP TCP选项部分 * @param l4_hdr_len TCP TCP选项部分
* @return * @return
*/ */
struct osfp_result *osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len); struct osfp_result *MESA_osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len);
/** /**
* @brief IPv6 TCP * @brief IPv6 TCP
@@ -52,7 +52,7 @@ struct osfp_result *osfp_ipv4_identify(struct osfp_db *db, struct iphdr* l3_hdr,
* @param l4_hdr_len TCP TCP选项部分 * @param l4_hdr_len TCP TCP选项部分
* @return 使 * @return 使
*/ */
struct osfp_result *osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len); struct osfp_result *MESA_osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hdr, struct tcphdr *l4_hdr, size_t l4_hdr_len);
/** /**
* @brief json * @brief json
@@ -61,7 +61,7 @@ struct osfp_result *osfp_ipv6_identify(struct osfp_db *db, struct ip6_hdr* l3_hd
* @param json_str * @param json_str
* @return 使 * @return 使
*/ */
struct osfp_result *osfp_json_identify(struct osfp_db *db, const char *json_str); struct osfp_result *MESA_osfp_json_identify(struct osfp_db *db, const char *json_str);
/** /**
* @brief * @brief
@@ -69,7 +69,7 @@ struct osfp_result *osfp_json_identify(struct osfp_db *db, const char *json_str)
* @param result * @param result
* @return osfp_result_free释放 * @return osfp_result_free释放
*/ */
const char *osfp_result_os_name_get(struct osfp_result *result); const char *MESA_osfp_result_os_name_get(struct osfp_result *result);
/** /**
* @brief * @brief
@@ -77,14 +77,14 @@ const char *osfp_result_os_name_get(struct osfp_result *result);
* @param result * @param result
* @return 使 * @return 使
*/ */
char *osfp_result_score_detail_export(struct osfp_result *result); char *MESA_osfp_result_score_detail_export(struct osfp_result *result);
/** /**
* @brief * @brief
* *
* @param result * @param result
*/ */
void osfp_result_free(struct osfp_result *result); void MESA_osfp_result_free(struct osfp_result *result);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -1,6 +1,6 @@
#include "osfp_common.h" #include "osfp_common.h"
#include "osfp.h" #include "MESA_osfp.h"
unsigned int osfp_profile_enable; unsigned int osfp_profile_enable;
@@ -19,6 +19,11 @@ struct osfp_profile_counter osfp_profile_score;
struct osfp_profile_counter osfp_profile_result_build; struct osfp_profile_counter osfp_profile_result_build;
struct osfp_profile_counter osfp_profile_result_export; struct osfp_profile_counter osfp_profile_result_export;
const char *osfp_os_class_id_to_name(enum osfp_os_class_id os_class)
{
return osfp_os_class_name[os_class];
}
void osfp_profile_counter_print(struct osfp_profile_counter *profile, const char *name) void osfp_profile_counter_print(struct osfp_profile_counter *profile, const char *name)
{ {
printf("profile %s: avg: %lu max: %lu min: %lu curr: %lu total: %lu count: %lu\n", printf("profile %s: avg: %lu max: %lu min: %lu curr: %lu total: %lu count: %lu\n",

View File

@@ -21,8 +21,6 @@
#include "cJSON.h" #include "cJSON.h"
#include "osfp.h"
static inline unsigned long long osfp_rdtsc(void) static inline unsigned long long osfp_rdtsc(void)
{ {
union { union {
@@ -197,10 +195,6 @@ struct osfp_db {
enum osfp_os_class_id osfp_os_class_name_to_id(char *name); enum osfp_os_class_id osfp_os_class_name_to_id(char *name);
extern const char *osfp_os_class_name[OSFP_OS_CLASS_MAX]; const char *osfp_os_class_id_to_name(enum osfp_os_class_id os_class);
static inline const char *osfp_os_class_id_to_name(enum osfp_os_class_id os_class)
{
return osfp_os_class_name[os_class];
}
#endif #endif

View File

@@ -1,6 +1,6 @@
#include "osfp_common.h" #include "osfp_common.h"
#include "osfp.h" #include "MESA_osfp.h"
#include "osfp_fingerprint.h" #include "osfp_fingerprint.h"
#include "osfp_log.h" #include "osfp_log.h"

View File

@@ -1,6 +1,6 @@
#include "osfp_common.h" #include "osfp_common.h"
#include "osfp.h" #include "MESA_osfp.h"
#include "osfp_fingerprint.h" #include "osfp_fingerprint.h"
#include "osfp_score_db.h" #include "osfp_score_db.h"
#include "osfp_log.h" #include "osfp_log.h"

View File

@@ -1,7 +1,6 @@
#ifndef __OSFP_SCORE_DB_H__ #ifndef __OSFP_SCORE_DB_H__
#define __OSFP_SCORE_DB_H__ #define __OSFP_SCORE_DB_H__
#include "osfp.h"
#include "osfp_fingerprint.h" #include "osfp_fingerprint.h"
#include "osfp_common.h" #include "osfp_common.h"

View File

@@ -1,4 +1,4 @@
{ {
global: osfp*;GIT_VERSION_*; global: MESA_osfp*;GIT_VERSION_*;
local: *; local: *;
}; };

View File

@@ -6,7 +6,7 @@
#include "cJSON.h" #include "cJSON.h"
#include "osfp.h" #include "MESA_osfp.h"
#include "osfp_fingerprint.h" #include "osfp_fingerprint.h"
#include "osfp_score_db.h" #include "osfp_score_db.h"
#include "osfp_log.h" #include "osfp_log.h"
@@ -105,7 +105,7 @@ void test_miss_rate()
osfp_log_level_set(OSFP_LOG_LEVEL_DEBUG); osfp_log_level_set(OSFP_LOG_LEVEL_DEBUG);
} }
struct osfp_db *osfp_db = osfp_db_new(db_file_path); struct osfp_db *osfp_db = MESA_osfp_db_new(db_file_path);
if (osfp_db == NULL) { if (osfp_db == NULL) {
printf("could not create osfp context. fingerprints file: %s\n", db_file_path); printf("could not create osfp context. fingerprints file: %s\n", db_file_path);
exit(1); exit(1);
@@ -123,7 +123,7 @@ void test_miss_rate()
const char *fp_str = cJSON_PrintUnformatted(entry); const char *fp_str = cJSON_PrintUnformatted(entry);
struct osfp_result *result = osfp_json_identify(osfp_db, fp_str); struct osfp_result *result = MESA_osfp_json_identify(osfp_db, fp_str);
if (result == NULL) { if (result == NULL) {
identify_failed_count++; identify_failed_count++;
continue; continue;
@@ -131,7 +131,7 @@ void test_miss_rate()
if (os_class == result->likely_os_class) { if (os_class == result->likely_os_class) {
verified_count++; verified_count++;
osfp_result_free(result); MESA_osfp_result_free(result);
continue; continue;
} }
@@ -145,16 +145,16 @@ void test_miss_rate()
unknown_count++; unknown_count++;
} }
fprintf(log_file_ptr, "expect: %s, result: %s\n", os_class_json->valuestring, osfp_result_os_name_get(result)); fprintf(log_file_ptr, "expect: %s, result: %s\n", os_class_json->valuestring, MESA_osfp_result_os_name_get(result));
char *result_json = osfp_result_score_detail_export(result); char *result_json = MESA_osfp_result_score_detail_export(result);
if (result_json) { if (result_json) {
fprintf(log_file_ptr, "%s\n", result_json); fprintf(log_file_ptr, "%s\n", result_json);
} else { } else {
fprintf(log_file_ptr, "result detail error:%p\n", result); fprintf(log_file_ptr, "result detail error:%p\n", result);
} }
fflush(log_file_ptr); fflush(log_file_ptr);
osfp_result_free(result); MESA_osfp_result_free(result);
} }
} }
@@ -165,7 +165,7 @@ void test_miss_rate()
printf("details in: %s\n", LOG_FILE_PATH); printf("details in: %s\n", LOG_FILE_PATH);
osfp_db_free(osfp_db); MESA_osfp_db_free(osfp_db);
} }
int main(int argc, char **argv) int main(int argc, char **argv)