Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/cfgutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,8 @@ processProtocolEntry(config_t* config, yaml_document_t* doc, yaml_node_t* node)
--g_prot_sequence;
destroyProtEntry(protocol_context);
DBG(NULL);
} else {
setExternalProto(protocol_context);
}
protocol_context = NULL;
}
Expand Down
40 changes: 40 additions & 0 deletions src/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,43 @@ scopeLogHex(cfg_log_level_t level, const void *data, size_t size, const char *fo
}
scopeLog(level, " %04x: %s %s", i-16, hex, txt);
}

void
scopeHexDump(cfg_log_level_t level, src_data_t dtype, void *buf, size_t len)
{
size_t dlen;

if (!buf) return;

if (dtype == BUF) {
// simple buffer, pass it through
dlen = len > 64 ? 64 : len;
scopeLogHex(level, buf, dlen, "BUF:");
} else if (dtype == MSG) {
// buffer is a msghdr for sendmsg/recvmsg
int i;
struct msghdr *msg = (struct msghdr *)buf;
struct iovec *iov;

for (i = 0; i < msg->msg_iovlen; i++) {
iov = &msg->msg_iov[i];
dlen = iov->iov_len > 64 ? 64 : iov->iov_len;
if (iov && iov->iov_base && (iov->iov_len > 0)) {
scopeLogHex(level, iov->iov_base, dlen, "MSG:");
}
}
} else if ( dtype == IOV) {
// buffer is an iovec, len is the iovcnt
int i;
struct iovec *iov = (struct iovec *)buf;

for (i = 0; i < len; i++) {
if (iov[i].iov_base && (iov[i].iov_len > 0)) {
dlen = iov[i].iov_len > 64 ? 64 : iov[i].iov_len;
scopeLogHex(level, iov[i].iov_base, dlen, "IOV:");
}
}
} else {
DBG(NULL); // just a note
}
}
2 changes: 2 additions & 0 deletions src/dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdio.h>
#include "log.h"
#include "scopetypes.h"
#include "state.h"

typedef struct _dbg_t dbg_t;

Expand Down Expand Up @@ -73,6 +74,7 @@ extern bool g_ismusl;
void scopeLog(cfg_log_level_t, const char *, ...) PRINTF_FORMAT(2,3);
void scopeLogHex(cfg_log_level_t, const void *, size_t, const char *, ...) PRINTF_FORMAT(4,5);
void scopeBacktrace(cfg_log_level_t);
void scopeHexDump(cfg_log_level_t, src_data_t, void *, size_t);

#define scopeLogError(...) scopeLog(CFG_LOG_ERROR, __VA_ARGS__)
#define scopeLogWarn(...) scopeLog(CFG_LOG_WARN, __VA_ARGS__)
Expand Down
9 changes: 9 additions & 0 deletions src/httpstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,15 @@ doHttpBuffer(http_state_t states[HTTP_NUM], net_info *net, char *buf, size_t len
return FALSE;
}

bool
detectHttp(void *buf, size_t len)
{
if ((len >= HTTP2_MAGIC_LEN && !scope_strncmp(buf, HTTP2_MAGIC, HTTP2_MAGIC_LEN)) ||
(searchExec(g_http_start, buf, len) != -1)) return TRUE;

return FALSE;
}

bool
doHttp(uint64_t id, int sockfd, net_info *net, char *buf, size_t len, metric_t src, src_data_t dtype)
{
Expand Down
1 change: 1 addition & 0 deletions src/httpstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
void initHttpState(void);
bool doHttp(uint64_t, int, net_info*, char*, size_t, metric_t, src_data_t);
void resetHttp(http_state_t httpstate[HTTP_NUM]);
bool detectHttp(void *, size_t);

#endif // __HTTPSTATE_H__
Loading