diff options
author | Guy Harris <guy@alum.mit.edu> | 2019-03-30 19:26:06 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-03-30 19:26:06 -0700 |
commit | 6da51b3ec9fc858728e5ea981757d05f970958e0 (patch) | |
tree | 47fbafa3ad50cb420844dae1ae53a394ae41b1d2 /netdissect.c | |
parent | 3d9ae63197107f1edce8c117b49332306e3ed8fb (diff) | |
download | tcpdump-6da51b3ec9fc858728e5ea981757d05f970958e0.tar.gz |
Introduce a buffer stack, and use it for ESP decryption.
If a dissector has to process its input - decryption, decompression,
etc. - rather than dissect the raw input, it should push the processed
input onto the buffer stack. As soon as the dissection is done, the
stack should be popped, to free the buffer into which the processing was
done, and restore the "pointer to packet data" and "pointer to end of
packet data" members of the netdissect_options structure, so the code
can go back to dissecting the original data.
The stack will get everything popped off it when dissection is done.
Use this mechanism in the ESP decryption code rather than scribbling on
top of the input packet data.
Diffstat (limited to 'netdissect.c')
-rw-r--r-- | netdissect.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/netdissect.c b/netdissect.c index d32de4e9..08a3280c 100644 --- a/netdissect.c +++ b/netdissect.c @@ -144,3 +144,46 @@ nd_smi_version_string(void) return (NULL); #endif } + + +int +nd_push_buffer(netdissect_options *ndo, u_char *new_buffer, + const u_char *new_packetp, const u_char *new_snapend) +{ + struct netdissect_saved_info *ndsi; + + ndsi = (struct netdissect_saved_info *)malloc(sizeof(struct netdissect_saved_info)); + if (ndsi == NULL) + return (0); /* fail */ + ndsi->ndsi_buffer = new_buffer; + ndsi->ndsi_packetp = ndo->ndo_packetp; + ndsi->ndsi_snapend = ndo->ndo_snapend; + ndsi->ndsi_prev = ndo->ndo_buffer_stack; + + ndo->ndo_packetp = new_packetp; + ndo->ndo_snapend = new_snapend; + ndo->ndo_buffer_stack = ndsi; + + return (1); /* success */ +} + +void +nd_pop_buffer(netdissect_options *ndo) +{ + struct netdissect_saved_info *ndsi; + + ndsi = ndo->ndo_buffer_stack; + ndo->ndo_packetp = ndsi->ndsi_packetp; + ndo->ndo_snapend = ndsi->ndsi_snapend; + ndo->ndo_buffer_stack = ndsi->ndsi_prev; + + free(ndsi->ndsi_buffer); + free(ndsi); +} + +void +nd_pop_all_buffers(netdissect_options *ndo) +{ + while (ndo->ndo_buffer_stack != NULL) + nd_pop_buffer(ndo); +} |