mirror of
https://github.com/h3xduck/TripleCross.git
synced 2026-01-01 05:53:07 +08:00
Adapted makefile for user includes and new source files
This commit is contained in:
Binary file not shown.
16
src/Makefile
16
src/Makefile
@@ -5,6 +5,10 @@ LLVM_STRIP ?= llvm-strip
|
|||||||
BPFTOOL ?= $(abspath ./tools/bpftool)
|
BPFTOOL ?= $(abspath ./tools/bpftool)
|
||||||
LIBBPF_SRC := $(abspath ./libbpf/src)
|
LIBBPF_SRC := $(abspath ./libbpf/src)
|
||||||
LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a)
|
LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a)
|
||||||
|
USER_INCLUDES_DIR := $(abspath ./user/include/utils)
|
||||||
|
USER_INCLUDES_HDR := $(wildcard $(USER_INCLUDES_DIR)/**/*.h)
|
||||||
|
USER_INCLUDES_SRC := $(wildcard $(USER_INCLUDES_DIR)/**/*.c)
|
||||||
|
USER_INCLUDES_OBJ := $(USER_INCLUDES_SRC:.c=.o)
|
||||||
VMLINUX := ./vmlinux/newvmlinux.h
|
VMLINUX := ./vmlinux/newvmlinux.h
|
||||||
USER := user
|
USER := user
|
||||||
EBPF := ebpf
|
EBPF := ebpf
|
||||||
@@ -76,14 +80,20 @@ $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT)
|
|||||||
$(Q)$(BPFTOOL) gen skeleton $< > $@
|
$(Q)$(BPFTOOL) gen skeleton $< > $@
|
||||||
|
|
||||||
# Build user-space code
|
# Build user-space code
|
||||||
$(patsubst %,$(OUTPUT)/%.o,$(APPS)): %.o: %.skel.h
|
$(patsubst %,$(OUTPUT)/%.o, $(APPS)): %.o: %.skel.h
|
||||||
|
|
||||||
$(OUTPUT)/%.o: $(USER)/%.c $(wildcard $(USER)/%.h) | $(OUTPUT)
|
#User includes
|
||||||
|
$(USER_INCLUDES_OBJ): $(wildcard $(USER_INCLUDES_SRC)/**/*.h)| $(OUTPUT)
|
||||||
|
$(call msg,CC,$@)
|
||||||
|
$(Q)$(CC) $(CFLAGS) -I$(wildcard $(USER_INCLUDES_SRC)/*.h) -c $(wildcard $(USER_INCLUDES_SRC)/*.c) -o $@
|
||||||
|
|
||||||
|
#User code
|
||||||
|
$(OUTPUT)/%.o: $(USER)/%.c $(wildcard $(USER)/%.h)| $(OUTPUT)
|
||||||
$(call msg,CC,$@)
|
$(call msg,CC,$@)
|
||||||
$(Q)$(CC) $(CFLAGS) $(INCLUDES) $(COMMON_INCLUDES) -c $(filter $(USER)/%.c,$^) -o $@
|
$(Q)$(CC) $(CFLAGS) $(INCLUDES) $(COMMON_INCLUDES) -c $(filter $(USER)/%.c,$^) -o $@
|
||||||
|
|
||||||
# Build application binary
|
# Build application binary
|
||||||
$(APPS): %: $(OUTPUT)/%.o $(LIBBPF_OBJ) | $(OUTPUT)
|
$(APPS): %: $(OUTPUT)/%.o $(LIBBPF_OBJ) $(USER_INCLUDES_SRC)| $(OUTPUT)
|
||||||
$(call msg,BINARY,$@)
|
$(call msg,BINARY,$@)
|
||||||
$(Q)$(CC) $(CFLAGS) $^ -lelf -lz -o bin/$@
|
$(Q)$(CC) $(CFLAGS) $^ -lelf -lz -o bin/$@
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
100
src/user/include/utils/files/path.c
Normal file
100
src/user/include/utils/files/path.c
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
#define _XOPEN_SOURCE 700
|
||||||
|
#define _LARGEFILE64_SOURCE
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <ftw.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include "path.h"
|
||||||
|
#define USE_FDS 15
|
||||||
|
|
||||||
|
int print_entry(const char *filepath, const struct stat *info, const int typeflag, struct FTW *pathinfo){
|
||||||
|
/* const char *const filename = filepath + pathinfo->base; */
|
||||||
|
const double bytes = (double)info->st_size; /* Not exact if large! */
|
||||||
|
struct tm mtime;
|
||||||
|
|
||||||
|
localtime_r(&(info->st_mtime), &mtime);
|
||||||
|
|
||||||
|
printf("%04d-%02d-%02d %02d:%02d:%02d",
|
||||||
|
mtime.tm_year+1900, mtime.tm_mon+1, mtime.tm_mday,
|
||||||
|
mtime.tm_hour, mtime.tm_min, mtime.tm_sec);
|
||||||
|
|
||||||
|
if (bytes >= 1099511627776.0)
|
||||||
|
printf(" %9.3f TiB", bytes / 1099511627776.0);
|
||||||
|
else
|
||||||
|
if (bytes >= 1073741824.0)
|
||||||
|
printf(" %9.3f GiB", bytes / 1073741824.0);
|
||||||
|
else
|
||||||
|
if (bytes >= 1048576.0)
|
||||||
|
printf(" %9.3f MiB", bytes / 1048576.0);
|
||||||
|
else
|
||||||
|
if (bytes >= 1024.0)
|
||||||
|
printf(" %9.3f KiB", bytes / 1024.0);
|
||||||
|
else
|
||||||
|
printf(" %9.0f B ", bytes);
|
||||||
|
|
||||||
|
if (typeflag == FTW_SL) {
|
||||||
|
char *target;
|
||||||
|
size_t maxlen = 1023;
|
||||||
|
ssize_t len;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
|
||||||
|
target = malloc(maxlen + 1);
|
||||||
|
if (target == NULL)
|
||||||
|
return ENOMEM;
|
||||||
|
|
||||||
|
len = readlink(filepath, target, maxlen);
|
||||||
|
if (len == (ssize_t)-1) {
|
||||||
|
const int saved_errno = errno;
|
||||||
|
free(target);
|
||||||
|
return saved_errno;
|
||||||
|
}
|
||||||
|
if (len >= (ssize_t)maxlen) {
|
||||||
|
free(target);
|
||||||
|
maxlen += 1024;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
target[len] = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" %s -> %s\n", filepath, target);
|
||||||
|
free(target);
|
||||||
|
|
||||||
|
} else
|
||||||
|
if (typeflag == FTW_SLN)
|
||||||
|
printf(" %s (dangling symlink)\n", filepath);
|
||||||
|
else
|
||||||
|
if (typeflag == FTW_F)
|
||||||
|
printf(" %s\n", filepath);
|
||||||
|
else
|
||||||
|
if (typeflag == FTW_D || typeflag == FTW_DP)
|
||||||
|
printf(" %s/\n", filepath);
|
||||||
|
else
|
||||||
|
if (typeflag == FTW_DNR)
|
||||||
|
printf(" %s/ (unreadable)\n", filepath);
|
||||||
|
else
|
||||||
|
printf(" %s (unknown)\n", filepath);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int print_directory_tree(const char *const dirpath){
|
||||||
|
int result;
|
||||||
|
|
||||||
|
/* Invalid directory path? */
|
||||||
|
if (dirpath == NULL || *dirpath == '\0')
|
||||||
|
return errno = EINVAL;
|
||||||
|
|
||||||
|
result = nftw(dirpath, print_entry, USE_FDS, FTW_PHYS);
|
||||||
|
if (result >= 0)
|
||||||
|
errno = result;
|
||||||
|
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
7
src/user/include/utils/files/path.h
Normal file
7
src/user/include/utils/files/path.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef __PATH_H
|
||||||
|
#define __PATH_H
|
||||||
|
|
||||||
|
int print_directory_tree(const char *const dirpath);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
BIN
src/user/include/utils/files/path.o
Normal file
BIN
src/user/include/utils/files/path.o
Normal file
Binary file not shown.
@@ -10,11 +10,12 @@
|
|||||||
* @param size
|
* @param size
|
||||||
* @return FdList
|
* @return FdList
|
||||||
*/
|
*/
|
||||||
FdList FdList_create(int size){
|
FdList* FdList_create(int size){
|
||||||
FdList *fd_list = (FdList*)calloc(1, sizeof(FdList));
|
FdList *fd_list = (FdList*)calloc(1, sizeof(FdList));
|
||||||
fd_list->max_size = size;
|
fd_list->max_size = size;
|
||||||
fd_list->size = 0;
|
fd_list->size = 0;
|
||||||
fd_list->list = (int*)calloc(size, sizeof(int));
|
fd_list->list = (int*)calloc(size, sizeof(int));
|
||||||
|
return fd_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,6 +29,7 @@ int FdList_add(FdList *fd_list, int fd_new){
|
|||||||
if(fd_list->size+1 >= fd_list->max_size){
|
if(fd_list->size+1 >= fd_list->max_size){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,4 +53,5 @@ int FdList_extend(FdList *fd_list, int new_size){
|
|||||||
int FdList_destroy(FdList *fd_list){
|
int FdList_destroy(FdList *fd_list){
|
||||||
free(fd_list->list);
|
free(fd_list->list);
|
||||||
free(fd_list);
|
free(fd_list);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ typedef struct FdList{
|
|||||||
|
|
||||||
} FdList;
|
} FdList;
|
||||||
|
|
||||||
FdList FdList_create(int size);
|
FdList* FdList_create(int size);
|
||||||
|
|
||||||
int FdList_add(FdList *fd_list, int fd_new);
|
int FdList_add(FdList *fd_list, int fd_new);
|
||||||
|
|
||||||
BIN
src/user/include/utils/structures/fdlist.o
Normal file
BIN
src/user/include/utils/structures/fdlist.o
Normal file
Binary file not shown.
@@ -11,6 +11,7 @@
|
|||||||
#include "xdp_filter.skel.h"
|
#include "xdp_filter.skel.h"
|
||||||
#include "include/xdp_filter.h"
|
#include "include/xdp_filter.h"
|
||||||
#include "../constants/constants.h"
|
#include "../constants/constants.h"
|
||||||
|
#include "include/utils/files/path.h"
|
||||||
|
|
||||||
static struct env {
|
static struct env {
|
||||||
bool verbose;
|
bool verbose;
|
||||||
@@ -81,6 +82,14 @@ int main(int argc, char**argv){
|
|||||||
//struct ring_buffer *rb = NULL;
|
//struct ring_buffer *rb = NULL;
|
||||||
struct xdp_filter_bpf *skel;
|
struct xdp_filter_bpf *skel;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
for (int arg = 1; arg < argc; arg++) {
|
||||||
|
if (print_directory_tree(argv[arg])) {
|
||||||
|
fprintf(stderr, "%s.\n", strerror(errno));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int ifindex;
|
unsigned int ifindex;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user