diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-09-28 21:50:27 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-28 21:50:27 +0300 |
| commit | 50c54c477624d5a9b668225fde2b9844d362760a (patch) | |
| tree | d1fe53a3c637f8b963027aa483053ae7afb55b5e /tests/unit/lcp_safeguards_test.c | |
| parent | c9d938173838d6955c824d141f24672d7037eb4e (diff) | |
| parent | 06aa0ef737d6993fd18e7db1bc8fc35601079505 (diff) | |
| download | accel-ppp-master.tar.gz accel-ppp-master.zip | |
Additional safeguards
Diffstat (limited to 'tests/unit/lcp_safeguards_test.c')
| -rw-r--r-- | tests/unit/lcp_safeguards_test.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/unit/lcp_safeguards_test.c b/tests/unit/lcp_safeguards_test.c new file mode 100644 index 00000000..32a14dfb --- /dev/null +++ b/tests/unit/lcp_safeguards_test.c @@ -0,0 +1,40 @@ +/* Exercise production Echo-Reply handling at the negotiated MTU. */ +#include <assert.h> +#include "triton.h" +#undef DEFINE_INIT +#define DEFINE_INIT(o, f) +#include "../../accel-pppd/ppp/ppp_lcp.c" + +int conf_ppp_verbose; +static int sent, sent_len; +void log_ppp_debug(const char *fmt, ...) {} +int ppp_chan_send(struct ppp_t *ppp, void *buf, int size) +{ + const struct lcp_hdr_t *hdr = buf; + assert(size == ntohs(hdr->len) + 2); + assert(hdr->code == ECHOREP); + sent++; + sent_len = size; + return 0; +} +int main(void) +{ + unsigned char buf[1502] = {0}; + struct ppp_t ppp = {.buf = buf, .buf_size = sizeof(buf), .mtu = 1492}; + struct ppp_lcp_t lcp = {.ppp = &ppp, .magic = 0x12345678}; + struct lcp_hdr_t *hdr = (void *)buf; + + hdr->len = htons(1493); + hdr->code = ECHOREQ; + send_echo_reply(&lcp); + assert(!sent && hdr->code == ECHOREQ); + hdr->len = htons(1492); + send_echo_reply(&lcp); + assert(sent == 1 && sent_len == 1494); + assert(u_read_be32(hdr + 1) == lcp.magic); + hdr->len = htons(8); + send_echo_reply(&lcp); + assert(sent == 2 && sent_len == 10); + puts("LCP safeguards: PASS"); + return 0; +} |
