Skip to content

Commit

Permalink
sync w/ internal repo.
Browse files Browse the repository at this point in the history
Summary:
in this sync:
1) updated kernel's includes
2) added support for ICMP "packet too big" generation if recved packet
is bigger then MAX_PCKT_SIZE (turned off by default as this requires
bpf_xdp_adjust_tail helper from 4.17)
3) unittests for #2
4) formating/renaming of few internal structs
  • Loading branch information
Nikita V. Shirokov authored and tehnerd committed Jun 7, 2018
1 parent f9513f6 commit 9bc4004
Show file tree
Hide file tree
Showing 22 changed files with 2,223 additions and 728 deletions.
1 change: 1 addition & 0 deletions build_bpf_modules_opensource.sh
Expand Up @@ -28,5 +28,6 @@ cp ./katran/lib/Makefile-bpf ./deps/linux/bpfprog/Makefile
cp -r ./katran/lib/bpf ./deps/linux/bpfprog/
cp ./katran/lib/linux_includes/bpf_helpers.h ./deps/linux/bpfprog/include/
cd ./deps/linux/bpfprog && LD_LIBRARY_PATH="${CLANG_PATH}/lib" make \
EXTRA_CFLAGS="$*" \
LLC="${CLANG_PATH}/bin/llc" CLANG="${CLANG_PATH}/bin/clang"
echo "BPF BUILD COMPLITED"
33 changes: 20 additions & 13 deletions katran/lib/BpfAdapter.cpp
Expand Up @@ -93,7 +93,7 @@ BpfAdapter::BpfAdapter(bool set_limits) {
struct rlimit lck_mem = {};
lck_mem.rlim_cur = RLIM_INFINITY;
lck_mem.rlim_max = RLIM_INFINITY;
if(setrlimit(RLIMIT_MEMLOCK, &lck_mem)) {
if (setrlimit(RLIMIT_MEMLOCK, &lck_mem)) {
LOG(ERROR) << "Can't change limit for locked memory";
throw std::runtime_error("error while setting limit for locked memory");
}
Expand Down Expand Up @@ -131,7 +131,7 @@ int BpfAdapter::createNamedBpfMap(
int numa_node) {
const char* name_ptr = !name.empty() ? name.c_str() : nullptr;

return bpf_create_map_node(
return ebpf_create_map_node(
static_cast<enum bpf_map_type>(type),
name_ptr,
key_size,
Expand All @@ -154,43 +154,43 @@ int BpfAdapter::bpfUpdateMap(
void* key,
void* value,
unsigned long long flags) {
auto bpfError = bpf_update_elem(map_fd, key, value, flags);
auto bpfError = ebpf_update_elem(map_fd, key, value, flags);
if (bpfError) {
VLOG(4) << "Error while updating value in map: " << std::strerror(errno);
}
return bpfError;
}

int BpfAdapter::bpfMapLookupElement(int map_fd, void* key, void* value) {
auto bpfError = bpf_lookup_elem(map_fd, key, value);
auto bpfError = ebpf_lookup_elem(map_fd, key, value);
if (bpfError) {
VLOG(4) << "Error while geting value from map: " << std::strerror(errno);
}
return bpfError;
}

int BpfAdapter::bpfMapDeleteElement(int map_fd, void* key) {
auto bpfError = bpf_delete_elem(map_fd, key);
auto bpfError = ebpf_delete_elem(map_fd, key);
if (bpfError) {
VLOG(4) << "Error while deleting key from map: " << std::strerror(errno);
}
return bpfError;
}

int BpfAdapter::bpfMapGetNextKey(int map_fd, void* key, void* next_key) {
auto bpfError = bpf_get_next_key(map_fd, key, next_key);
auto bpfError = ebpf_get_next_key(map_fd, key, next_key);
if (bpfError) {
VLOG(4) << "Error getting next key from map: " << std::strerror(errno);
}
return bpfError;
}

int BpfAdapter::pinBpfObject(int fd, const std::string& path) {
return bpf_obj_pin(fd, path.c_str());
return ebpf_obj_pin(fd, path.c_str());
}

int BpfAdapter::getPinnedBpfObject(const std::string& path) {
return bpf_obj_get(path.c_str());
return ebpf_obj_get(path.c_str());
}

int BpfAdapter::getInterfaceIndex(const std::string& interface_name) {
Expand Down Expand Up @@ -298,7 +298,7 @@ int BpfAdapter::testXdpProg(
uint32_t* size_out,
uint32_t* retval,
uint32_t* duration) {
return bpf_prog_test_run(
return ebpf_prog_test_run(
prog_fd, repeat, data, data_size, data_out, size_out, retval, duration);
}

Expand Down Expand Up @@ -460,7 +460,14 @@ int BpfAdapter::modifyTcBpfFilter(
const int prog_fd,
const unsigned int ifindex,
const std::string& bpf_name,
const int direction) {
const int direction)
// TODO: T30063437 fix null-pointer-use undefined behavior
#if defined(__has_feature)
#if __has_feature(__address_sanitizer__)
__attribute__((__no_sanitize__("null")))
#endif
#endif
{
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr* nlh;
struct tcmsg* tc;
Expand Down Expand Up @@ -572,7 +579,7 @@ int BpfAdapter::attachCgroupProg(
SCOPE_EXIT {
::close(target_fd);
};
return bpf_prog_attach(prog_fd, target_fd, type, flags);
return ebpf_prog_attach(prog_fd, target_fd, type, flags);
}

int BpfAdapter::detachCgroupProg(
Expand All @@ -585,7 +592,7 @@ int BpfAdapter::detachCgroupProg(
SCOPE_EXIT {
::close(target_fd);
};
return bpf_prog_detach(target_fd, type);
return ebpf_prog_detach(target_fd, type);
}

int BpfAdapter::detachCgroupProg(
Expand All @@ -599,7 +606,7 @@ int BpfAdapter::detachCgroupProg(
SCOPE_EXIT {
::close(target_fd);
};
return bpf_prog_detach2(prog_fd, target_fd, type);
return ebpf_prog_detach2(prog_fd, target_fd, type);
}

} // namespace katran
2 changes: 1 addition & 1 deletion katran/lib/BpfAdapter.h
Expand Up @@ -52,7 +52,7 @@ constexpr unsigned int kBpfMapTypeHashOfMaps = 13;
*/
class BpfAdapter {
public:
explicit BpfAdapter(bool set_limits=true);
explicit BpfAdapter(bool set_limits = true);

// BpfAdapter is not thread safe. Discourage unsafe use by disabling copy
// construction/assignment.
Expand Down
8 changes: 4 additions & 4 deletions katran/lib/BpfLoader.cpp
Expand Up @@ -225,14 +225,14 @@ int BpfLoader::loadMaps(Elf* elf) {
<< "map-in-map prototype";
return 1;
}
map_fd = bpf_create_map_in_map(
map_fd = ebpf_create_map_in_map(
static_cast<enum bpf_map_type>(maps[i].type),
maps[i].key_size,
inner_map_fd,
maps[i].max_entries,
maps[i].map_flags);
} else {
map_fd = bpf_create_map(
map_fd = ebpf_create_map(
static_cast<enum bpf_map_type>(maps[i].type),
maps[i].key_size,
maps[i].value_size,
Expand Down Expand Up @@ -579,7 +579,7 @@ int BpfLoader::loadBpfProgs() {
<< "\nlicense: " << license_
<< "\nkernel version: " << kernelVersion_;
std::string bpf_log_buf(kLogBufSize, '\0');
auto prog_fd = bpf_prog_load(
auto prog_fd = ebpf_prog_load(
prog_iter.second.type,
prog_iter.second.insns,
prog_iter.second.size,
Expand Down Expand Up @@ -607,7 +607,7 @@ int BpfLoader::loadBpfFile(const std::string& path, const bpf_prog_type type) {
int fd = -1;
SCOPE_EXIT {
elf_end(elf_);
if (0 < fd) {
if (fd > 0) {
::close(fd);
}
};
Expand Down
13 changes: 7 additions & 6 deletions katran/lib/KatranLb.cpp
Expand Up @@ -668,18 +668,19 @@ lb_stats KatranLb::getStatsForVip(const VipKey& vip) {
}

lb_stats KatranLb::getLruStats() {
uint32_t lru_cntr_pos = maxVips_ + kLruCntrOffset;
return getLbStats(lru_cntr_pos);
return getLbStats(maxVips_ + kLruCntrOffset);
}

lb_stats KatranLb::getLruMissStats() {
uint32_t lru_miss_pos = maxVips_ + kLruMissOffset;
return getLbStats(lru_miss_pos);
return getLbStats(maxVips_ + kLruMissOffset);
}

lb_stats KatranLb::getLruFallbackStats() {
uint32_t lru_fallback_pos = maxVips_ + kLruFallbackOffset;
return getLbStats(lru_fallback_pos);
return getLbStats(maxVips_ + kLruFallbackOffset);
}

lb_stats KatranLb::getIcmpTooBigStats() {
return getLbStats(maxVips_ + kIcmpTooBigOffset);
}

lb_stats KatranLb::getLbStats(uint32_t position) {
Expand Down
20 changes: 15 additions & 5 deletions katran/lib/KatranLb.h
Expand Up @@ -45,6 +45,7 @@ constexpr int kMainIntfPos = 3;
constexpr uint32_t kLruCntrOffset = 0;
constexpr uint32_t kLruMissOffset = 1;
constexpr uint32_t kLruFallbackOffset = 3;
constexpr uint32_t kIcmpTooBigOffset = 4;

/**
* LRU map related constants
Expand Down Expand Up @@ -213,7 +214,7 @@ class KatranLb {
* @param VipKey vip
* @return struct lb_stats w/ statistic for specified vip
*
* helper function which return totall ammount of pkts and bytes which
* helper function which return total ammount of pkts and bytes which
* has been sent to specified vip. it's up to external entity to calculate
* actual speed in pps/bps
*/
Expand All @@ -222,7 +223,7 @@ class KatranLb {
/**
* @return struct lb_stats w/ statistics for lru misses
*
* helper function which returns totall amount of processed packets and
* helper function which returns total amount of processed packets and
* how much of em was lru misses (when we wasnt able to find entry in
* connection table)
*/
Expand All @@ -231,19 +232,28 @@ class KatranLb {
/**
* @return struct lb_stats w/ statistic of the reasons for lru misses
*
* helper function which return totall amount of tcp lru misses because of
* helper function which returns total amount of tcp lru misses because of
* the tcp syns (v1) or non-syns (v2)
*/
lb_stats getLruMissStats();

/**
* @return struct lb_stats w/ statistic of fallback lru hits
*
* helper function which return totall amount of numbers when we fel back
* helper function which return total amount of numbers when we fel back
* to fallback_lru (v1);
*/
lb_stats getLruFallbackStats();

/**
* @return struct lb_stats w/ statistic of icmp packet too big packets
*
* helper function which returns how many icmpv4/icmpv6 packet too big
* has been generated after we have received packet, which is bigger then
* maximum supported size.
*/
lb_stats getIcmpTooBigStats();

/**
* @param uint32_t somark of the packet
* @param std::string dst for a packed w/ specified so_mark
Expand Down Expand Up @@ -473,7 +483,7 @@ class KatranLb {
std::vector<int> lruMapsFd_;

/**
* totall LRUs map size; each forwarding cpu/core will have
* total LRUs map size; each forwarding cpu/core will have
* total_size/forwarding_cores entries
*/
uint64_t totalLruSize_;
Expand Down
136 changes: 0 additions & 136 deletions katran/lib/TARGETS

This file was deleted.

0 comments on commit 9bc4004

Please sign in to comment.