summaryrefslogtreecommitdiff
path: root/tests/unit/lcp_safeguards_test.c
blob: 32a14dfb8b06cc05c88d04a4f0478ab64a75cd80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}