Skip to content

Commit

Permalink
Use early return
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-szweda committed Feb 22, 2024
1 parent 739dec1 commit 76cdd24
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions libebpfdiscoveryskel/src/SyscallProbes.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,29 +293,33 @@ __attribute__((always_inline)) inline static int handleSysRecvmsgExit(struct pt_
return 0;
}

if (bytesCount > 0) {
for (size_t i = 0; i < DISCOVERY_HANDLER_MAX_IOVLEN && i < readSyscallVectorArgsPtr->iovlen; i++) {
struct ReadSyscallScalarArgs readSyscallScalarArgs = {
.fd = readSyscallVectorArgsPtr->fd,
};

bpf_probe_read(&readSyscallScalarArgs.buf, sizeof(void*), &readSyscallVectorArgsPtr->iov[i].iov_base);
if (readSyscallScalarArgs.buf == NULL) {
handleNoMoreDataForReading(ctx, globalStatePtr, allSessionStatePtr, readSyscallScalarArgs.fd, pidTgid);
return 0;
}

size_t iovLen;
bpf_probe_read(&iovLen, sizeof(size_t), &readSyscallVectorArgsPtr->iov[i].iov_len);

struct ReadSyscallHandlerArgs readSyscallHandlerArgs = {
.fd = readSyscallScalarArgs.fd,
.buf = readSyscallScalarArgs.buf,
.bytesCount = (ssize_t) iovLen,
};

handleRead(ctx, globalStatePtr, allSessionStatePtr, &readSyscallHandlerArgs, pidTgid);
if (bytesCount <= 0) {
bpf_map_delete_elem(&runningReadSyscallVectorArgsMap, &pidTgid);

return 0;
}

for (size_t i = 0; i < DISCOVERY_HANDLER_MAX_IOVLEN && i < readSyscallVectorArgsPtr->iovlen; i++) {
struct ReadSyscallScalarArgs readSyscallScalarArgs = {
.fd = readSyscallVectorArgsPtr->fd,
};

bpf_probe_read(&readSyscallScalarArgs.buf, sizeof(void*), &readSyscallVectorArgsPtr->iov[i].iov_base);
if (readSyscallScalarArgs.buf == NULL) {
handleNoMoreDataForReading(ctx, globalStatePtr, allSessionStatePtr, readSyscallScalarArgs.fd, pidTgid);
return 0;
}

size_t iovLen;
bpf_probe_read(&iovLen, sizeof(size_t), &readSyscallVectorArgsPtr->iov[i].iov_len);

struct ReadSyscallHandlerArgs readSyscallHandlerArgs = {
.fd = readSyscallScalarArgs.fd,
.buf = readSyscallScalarArgs.buf,
.bytesCount = (ssize_t) iovLen,
};

handleRead(ctx, globalStatePtr, allSessionStatePtr, &readSyscallHandlerArgs, pidTgid);
}

bpf_map_delete_elem(&runningReadSyscallVectorArgsMap, &pidTgid);
Expand Down

0 comments on commit 76cdd24

Please sign in to comment.