cbcp.c (10be78d3ae11fbdd8fab4a4a34d5337ce071dd1d) cbcp.c (057f1760a8171825b260dad27502f74ed5f69faf)
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 136 unchanged lines hidden (view full) ---

145#define CBCP_RESPSENT (3) /* Waiting for an ACK */
146#define CBCP_ACKSENT (4) /* Waiting for an LCP Term REQ */
147
148static const char * const cbcpname[] = {
149 "closed", "stopped", "req-sent", "resp-sent", "ack-sent"
150};
151
152static const char *
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 136 unchanged lines hidden (view full) ---

145#define CBCP_RESPSENT (3) /* Waiting for an ACK */
146#define CBCP_ACKSENT (4) /* Waiting for an LCP Term REQ */
147
148static const char * const cbcpname[] = {
149 "closed", "stopped", "req-sent", "resp-sent", "ack-sent"
150};
151
152static const char *
153cbcpstate(int s)
153cbcpstate(unsigned s)
154{
155 if (s < sizeof cbcpname / sizeof cbcpname[0])
156 return cbcpname[s];
157 return HexStr(s, NULL, 0);
158}
159
160static void
161cbcp_NewPhase(struct cbcp *cbcp, int new)

--- 43 unchanged lines hidden (view full) ---

205 head->length = htons(sizeof *head + data->length);
206 memcpy(MBUF_CTOP(bp) + sizeof *head, data, data->length);
207 log_DumpBp(LogDEBUG, "cbcp_Output", bp);
208 link_PushPacket(&cbcp->p->link, bp, cbcp->p->dl->bundle,
209 LINK_QUEUES(&cbcp->p->link) - 1, PROTO_CBCP);
210}
211
212static const char *
154{
155 if (s < sizeof cbcpname / sizeof cbcpname[0])
156 return cbcpname[s];
157 return HexStr(s, NULL, 0);
158}
159
160static void
161cbcp_NewPhase(struct cbcp *cbcp, int new)

--- 43 unchanged lines hidden (view full) ---

205 head->length = htons(sizeof *head + data->length);
206 memcpy(MBUF_CTOP(bp) + sizeof *head, data, data->length);
207 log_DumpBp(LogDEBUG, "cbcp_Output", bp);
208 link_PushPacket(&cbcp->p->link, bp, cbcp->p->dl->bundle,
209 LINK_QUEUES(&cbcp->p->link) - 1, PROTO_CBCP);
210}
211
212static const char *
213cbcp_data_Type(int type)
213cbcp_data_Type(unsigned type)
214{
215 static const char * const types[] = {
216 "No callback", "User-spec", "Server-spec", "list"
217 };
218
219 if (type < 1 || type > sizeof types / sizeof types[0])
220 return HexStr(type, NULL, 0);
221 return types[type-1];

--- 388 unchanged lines hidden (view full) ---

610 cbcp_data_Show(&data);
611 cbcp_Output(cbcp, CBCP_ACK, &data);
612 cbcp->fsm.restart--;
613 cbcp_StartTimer(cbcp, cbcp->fsm.delay);
614 cbcp_NewPhase(cbcp, CBCP_ACKSENT); /* Wait for an ACK */
615}
616
617extern struct mbuf *
214{
215 static const char * const types[] = {
216 "No callback", "User-spec", "Server-spec", "list"
217 };
218
219 if (type < 1 || type > sizeof types / sizeof types[0])
220 return HexStr(type, NULL, 0);
221 return types[type-1];

--- 388 unchanged lines hidden (view full) ---

610 cbcp_data_Show(&data);
611 cbcp_Output(cbcp, CBCP_ACK, &data);
612 cbcp->fsm.restart--;
613 cbcp_StartTimer(cbcp, cbcp->fsm.delay);
614 cbcp_NewPhase(cbcp, CBCP_ACKSENT); /* Wait for an ACK */
615}
616
617extern struct mbuf *
618cbcp_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
618cbcp_Input(struct bundle *bundle __unused, struct link *l, struct mbuf *bp)
619{
620 struct physical *p = link2physical(l);
621 struct cbcp_header *head;
622 struct cbcp_data *data;
623 struct cbcp *cbcp = &p->dl->cbcp;
619{
620 struct physical *p = link2physical(l);
621 struct cbcp_header *head;
622 struct cbcp_data *data;
623 struct cbcp *cbcp = &p->dl->cbcp;
624 int len;
624 size_t len;
625
626 if (p == NULL) {
627 log_Printf(LogERROR, "cbcp_Input: Not a physical link - dropped\n");
628 m_freem(bp);
629 return NULL;
630 }
631
632 bp = m_pullup(bp);
633 len = m_length(bp);
634 if (len < sizeof(struct cbcp_header)) {
635 m_freem(bp);
636 return NULL;
637 }
638 head = (struct cbcp_header *)MBUF_CTOP(bp);
639 if (ntohs(head->length) != len) {
625
626 if (p == NULL) {
627 log_Printf(LogERROR, "cbcp_Input: Not a physical link - dropped\n");
628 m_freem(bp);
629 return NULL;
630 }
631
632 bp = m_pullup(bp);
633 len = m_length(bp);
634 if (len < sizeof(struct cbcp_header)) {
635 m_freem(bp);
636 return NULL;
637 }
638 head = (struct cbcp_header *)MBUF_CTOP(bp);
639 if (ntohs(head->length) != len) {
640 log_Printf(LogWARN, "Corrupt CBCP packet (code %d, length %d not %d)"
640 log_Printf(LogWARN, "Corrupt CBCP packet (code %d, length %u not %u)"
641 " - ignored\n", head->code, ntohs(head->length), len);
642 m_freem(bp);
643 return NULL;
644 }
645 m_settype(bp, MB_CBCPIN);
646
647 /* XXX check the id */
648

--- 111 unchanged lines hidden ---
641 " - ignored\n", head->code, ntohs(head->length), len);
642 m_freem(bp);
643 return NULL;
644 }
645 m_settype(bp, MB_CBCPIN);
646
647 /* XXX check the id */
648

--- 111 unchanged lines hidden ---