Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions agent/src/ebpf/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ ARCH ?= $(shell uname -m)
CC ?= gcc
CFLAGS ?= -std=gnu99 --static -g -O2 -ffunction-sections -fdata-sections -fPIC -fno-omit-frame-pointer -Wall -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers

EXECS := test_symbol test_offset test_insns_cnt test_bihash test_vec test_fetch_container_id test_parse_range test_set_ports_bitmap test_pid_check test_match_pids
EXECS := test_symbol test_offset test_insns_cnt test_bihash test_vec test_fetch_container_id test_parse_range test_set_ports_bitmap test_pid_check test_match_pids test_nic_config
ifeq ($(ARCH), x86_64)
#-lbcc -lstdc++
LDLIBS += ../libtrace.a ./libtrace_utils.a -ljattach -lbcc_bpf -lGoReSym -lbddisasm -ldwarf -lelf -lz -lpthread -lbcc -lstdc++ -ldl
LDLIBS += ../libtrace.a ./libtrace_utils.a -ljattach -lbcc_bpf -lGoReSym -lbddisasm -ldwarf -lelf -lz -lpthread -lbcc -lstdc++ -ldl -lm
else ifeq ($(ARCH), aarch64)
LDLIBS += ../libtrace.a ./libtrace_utils.a -ljattach -lGoReSym -lbcc_bpf -ldwarf -lelf -lz -lpthread -lbcc -lstdc++ -ldl
LDLIBS += ../libtrace.a ./libtrace_utils.a -ljattach -lGoReSym -lbcc_bpf -ldwarf -lelf -lz -lpthread -lbcc -lstdc++ -ldl -lm
endif

all: $(EXECS) libtrace_utils.a
Expand Down
74 changes: 74 additions & 0 deletions agent/src/ebpf/test/test_nic_config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2024 Yunshan Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "../user/types.h"
#include <bcc/perf_reader.h>
#include "../user/config.h"
#include "../user/common_utils.h"
#include "../user/utils.h"
#include "../user/mem.h"
#include "../user/log.h"
#include "../user/types.h"
#include "../user/vec.h"
#include "../user/tracer.h"
#include "../user/socket.h"
#include "../user/profile/perf_profiler.h"
#include "../user/elf.h"
#include "../user/load.h"

static const char *nic_name = "lo";

static int show_nic_info(const char *name)
{
struct nic_info_s *nic = malloc(sizeof(struct nic_info_s));
if (nic == NULL) {
fprintf(stderr, "malloc() failed.\n");
return -1;
}

memset(nic, 0, sizeof(*nic));
snprintf(nic->name, sizeof(nic->name), "%s", name);
retrieve_pci_info_by_nic(nic->name, nic->pci_device_address,
nic->driver, &nic->numa_node);
get_nic_channels(nic->name, &nic->rx_channels, &nic->tx_channels);
get_nic_ring_size(nic->name, &nic->rx_ring_size, &nic->tx_ring_size);
nic->promisc = is_promiscuous_mode(nic->name);
fprintf(stdout, "Device: %-8s\nAddress: %-14s\nDriver: %-8s\n"
"Rx-Channels: %-4d\nTx-Channels: %-4d\nRX-Ring-Size: %-5ld\nTX-Ring-Size: %-5ld\n"
"PROMISC: %-3d\nNumaNode: %d\n\n",
nic->name, nic->pci_device_address, nic->driver,
nic->rx_channels, nic->tx_channels, nic->rx_ring_size,
nic->tx_ring_size, nic->promisc, nic->numa_node);
fflush(stdout);
free(nic);
return ETR_OK;
}

int main(void)
{
bpf_tracer_init(NULL, true);
int is_promisc = is_promiscuous_mode(nic_name);
printf("Nic %s is_promisc : %d\n", nic_name, is_promisc);
show_nic_info(nic_name);
if (is_promisc == 0) {
printf("Set nic %s promisc mode.\n", nic_name);
set_promiscuous_mode(nic_name);
}
int ret = set_nic_ring_size(nic_name, 4096, 4096);
printf("ret %d\n-----------------\n", ret);
show_nic_info(nic_name);
return 0;
}
Loading
Loading