version 1.1.1.1, 2013/07/22 08:44:29
|
version 1.1.1.2, 2021/03/17 00:39:23
|
Line 115 ppp_l2tp_avp_list_create(void)
|
Line 115 ppp_l2tp_avp_list_create(void)
|
*/ |
*/ |
int |
int |
ppp_l2tp_avp_list_insert(struct ppp_l2tp_avp_list *list, |
ppp_l2tp_avp_list_insert(struct ppp_l2tp_avp_list *list, |
struct ppp_l2tp_avp **avpp, int index) | struct ppp_l2tp_avp **avpp, unsigned index) |
{ |
{ |
struct ppp_l2tp_avp *const avp = *avpp; |
struct ppp_l2tp_avp *const avp = *avpp; |
void *mem; |
void *mem; |
Line 199 int
|
Line 199 int
|
ppp_l2tp_avp_list_find(const struct ppp_l2tp_avp_list *list, |
ppp_l2tp_avp_list_find(const struct ppp_l2tp_avp_list *list, |
u_int16_t vendor, u_int16_t type) |
u_int16_t vendor, u_int16_t type) |
{ |
{ |
int i; | unsigned i; |
|
|
for (i = 0; i < list->length; i++) { |
for (i = 0; i < list->length; i++) { |
const struct ppp_l2tp_avp *const avp = &list->avps[i]; |
const struct ppp_l2tp_avp *const avp = &list->avps[i]; |
Line 217 struct ppp_l2tp_avp_list *
|
Line 217 struct ppp_l2tp_avp_list *
|
ppp_l2tp_avp_list_copy(const struct ppp_l2tp_avp_list *orig) |
ppp_l2tp_avp_list_copy(const struct ppp_l2tp_avp_list *orig) |
{ |
{ |
struct ppp_l2tp_avp_list *list; |
struct ppp_l2tp_avp_list *list; |
int i; | unsigned i; |
|
|
list = ppp_l2tp_avp_list_create(); |
list = ppp_l2tp_avp_list_create(); |
for (i = 0; i < orig->length; i++) { |
for (i = 0; i < orig->length; i++) { |
Line 239 void
|
Line 239 void
|
ppp_l2tp_avp_list_destroy(struct ppp_l2tp_avp_list **listp) |
ppp_l2tp_avp_list_destroy(struct ppp_l2tp_avp_list **listp) |
{ |
{ |
struct ppp_l2tp_avp_list *const list = *listp; |
struct ppp_l2tp_avp_list *const list = *listp; |
int i; | unsigned i; |
|
|
if (list == NULL) |
if (list == NULL) |
return; |
return; |
Line 266 ppp_l2tp_avp_pack(const struct ppp_l2tp_avp_info *info
|
Line 266 ppp_l2tp_avp_pack(const struct ppp_l2tp_avp_info *info
|
{ |
{ |
uint32_t randvec; |
uint32_t randvec; |
int randsent = 0; |
int randsent = 0; |
int len; | int len = 0; |
int i; | unsigned i; |
|
|
/* Pack AVP's */ |
/* Pack AVP's */ |
for (len = i = 0; i < list->length; i++) { | for (i = 0; i < list->length; i++) { |
const struct ppp_l2tp_avp *const avp = &list->avps[i]; |
const struct ppp_l2tp_avp *const avp = &list->avps[i]; |
const struct ppp_l2tp_avp_info *desc; |
const struct ppp_l2tp_avp_info *desc; |
u_int16_t hdr[3]; |
u_int16_t hdr[3]; |
Line 516 struct ppp_l2tp_avp_ptrs *
|
Line 516 struct ppp_l2tp_avp_ptrs *
|
ppp_l2tp_avp_list2ptrs(const struct ppp_l2tp_avp_list *list) |
ppp_l2tp_avp_list2ptrs(const struct ppp_l2tp_avp_list *list) |
{ |
{ |
struct ppp_l2tp_avp_ptrs *ptrs; |
struct ppp_l2tp_avp_ptrs *ptrs; |
int i; | unsigned i; |
|
|
/* Macro to allocate one pointer structure */ | /* Macro to allocate one pointer structure. Malloc zeroes area. */ |
#define AVP_ALLOC(field) \ |
#define AVP_ALLOC(field) \ |
do { \ |
do { \ |
size_t _size = sizeof(*ptrs->field); \ |
size_t _size = sizeof(*ptrs->field); \ |
Line 530 do { \
|
Line 530 do { \
|
ptrs->field = Malloc(AVP_PTRS_MTYPE, _size); \ |
ptrs->field = Malloc(AVP_PTRS_MTYPE, _size); \ |
} while (0) |
} while (0) |
|
|
|
#define AVP_STORE8(field, offset) \ |
|
do { \ |
|
if (avp->vlen > offset) \ |
|
ptrs->field = ptr8[offset]; \ |
|
} while (0) |
|
|
|
#define AVP_STORE16(field, offset) \ |
|
do { \ |
|
if (avp->vlen >= (offset + 1) * sizeof(u_int16_t)) \ |
|
ptrs->field = ntohs(ptr16[offset]); \ |
|
} while (0) |
|
|
|
#define AVP_STORE32(field) \ |
|
do { \ |
|
if (avp->vlen >= sizeof(u_int32_t)) \ |
|
ptrs->field = ntohl(ptr32[0]); \ |
|
} while (0) |
|
|
|
#define AVP_MEMCPY_OFF(field, offset) \ |
|
do { \ |
|
if (avp->vlen > offset) \ |
|
memcpy(ptrs->field, (char *)avp->value + offset, avp->vlen - offset); \ |
|
} while (0) |
|
|
/* Create new pointers structure */ |
/* Create new pointers structure */ |
ptrs = Malloc(AVP_PTRS_MTYPE, sizeof(*ptrs)); |
ptrs = Malloc(AVP_PTRS_MTYPE, sizeof(*ptrs)); |
|
|
Line 545 do { \
|
Line 569 do { \
|
switch (avp->type) { |
switch (avp->type) { |
case AVP_MESSAGE_TYPE: |
case AVP_MESSAGE_TYPE: |
AVP_ALLOC(message); |
AVP_ALLOC(message); |
ptrs->message->mesgtype = ntohs(ptr16[0]); | AVP_STORE16(message->mesgtype, 0); |
break; |
break; |
case AVP_RESULT_CODE: |
case AVP_RESULT_CODE: |
AVP_ALLOC(errresultcode); |
AVP_ALLOC(errresultcode); |
ptrs->errresultcode->result = ntohs(ptr16[0]); | AVP_STORE16(errresultcode->result, 0); |
if (avp->vlen > 2) | AVP_STORE16(errresultcode->error, 1); |
ptrs->errresultcode->error = ntohs(ptr16[1]); | AVP_MEMCPY_OFF(errresultcode->errmsg, 4); |
if (avp->vlen > 4) { | |
memcpy(ptrs->errresultcode->errmsg, | |
(char *)avp->value + 4, avp->vlen - 4); | |
} | |
break; |
break; |
case AVP_PROTOCOL_VERSION: |
case AVP_PROTOCOL_VERSION: |
AVP_ALLOC(protocol); |
AVP_ALLOC(protocol); |
ptrs->protocol->version = ptr8[0]; | AVP_STORE8(protocol->version, 0); |
ptrs->protocol->revision = ptr8[1]; | AVP_STORE8(protocol->revision, 1); |
break; |
break; |
case AVP_FRAMING_CAPABILITIES: |
case AVP_FRAMING_CAPABILITIES: |
AVP_ALLOC(framingcap); |
AVP_ALLOC(framingcap); |
ptrs->framingcap->sync = | if (avp->vlen >= sizeof(u_int32_t)) { |
(ntohl(ptr32[0]) & L2TP_FRAMING_SYNC) != 0; | ptrs->framingcap->sync = |
ptrs->framingcap->async = | (ntohl(ptr32[0]) & L2TP_FRAMING_SYNC) != 0; |
(ntohl(ptr32[0]) & L2TP_FRAMING_ASYNC) != 0; | ptrs->framingcap->async = |
| (ntohl(ptr32[0]) & L2TP_FRAMING_ASYNC) != 0; |
| } |
break; |
break; |
case AVP_BEARER_CAPABILITIES: |
case AVP_BEARER_CAPABILITIES: |
AVP_ALLOC(bearercap); |
AVP_ALLOC(bearercap); |
ptrs->bearercap->digital = | if (avp->vlen >= sizeof(u_int32_t)) { |
(ntohl(ptr32[0]) & L2TP_BEARER_DIGITAL) != 0; | ptrs->bearercap->digital = |
ptrs->bearercap->analog = | (ntohl(ptr32[0]) & L2TP_BEARER_DIGITAL) != 0; |
(ntohl(ptr32[0]) & L2TP_BEARER_ANALOG) != 0; | ptrs->bearercap->analog = |
| (ntohl(ptr32[0]) & L2TP_BEARER_ANALOG) != 0; |
| } |
break; |
break; |
case AVP_TIE_BREAKER: |
case AVP_TIE_BREAKER: |
AVP_ALLOC(tiebreaker); |
AVP_ALLOC(tiebreaker); |
memcpy(ptrs->tiebreaker->value, avp->value, 8); | if (avp->vlen >= 8) |
| memcpy(ptrs->tiebreaker->value, |
| (char *)avp->value, 8); |
break; |
break; |
case AVP_FIRMWARE_REVISION: |
case AVP_FIRMWARE_REVISION: |
AVP_ALLOC(firmware); |
AVP_ALLOC(firmware); |
ptrs->firmware->revision = ntohs(ptr16[0]); | AVP_STORE16(firmware->revision, 0); |
break; |
break; |
case AVP_HOST_NAME: |
case AVP_HOST_NAME: |
AVP_ALLOC(hostname); |
AVP_ALLOC(hostname); |
Line 594 do { \
|
Line 620 do { \
|
break; |
break; |
case AVP_ASSIGNED_TUNNEL_ID: |
case AVP_ASSIGNED_TUNNEL_ID: |
AVP_ALLOC(tunnelid); |
AVP_ALLOC(tunnelid); |
ptrs->tunnelid->id = ntohs(ptr16[0]); | AVP_STORE16(tunnelid->id, 0); |
break; |
break; |
case AVP_RECEIVE_WINDOW_SIZE: |
case AVP_RECEIVE_WINDOW_SIZE: |
AVP_ALLOC(winsize); |
AVP_ALLOC(winsize); |
ptrs->winsize->size = ntohs(ptr16[0]); | AVP_STORE16(winsize->size, 0); |
break; |
break; |
case AVP_CHALLENGE: |
case AVP_CHALLENGE: |
AVP_ALLOC(challenge); |
AVP_ALLOC(challenge); |
Line 607 do { \
|
Line 633 do { \
|
break; |
break; |
case AVP_CAUSE_CODE: |
case AVP_CAUSE_CODE: |
AVP_ALLOC(causecode); |
AVP_ALLOC(causecode); |
ptrs->causecode->causecode = ntohs(ptr16[0]); | AVP_STORE16(causecode->causecode, 0); |
ptrs->causecode->causemsg = ptr8[3]; | AVP_STORE8(causecode->causemsg, 3); |
memcpy(ptrs->causecode->message, | AVP_MEMCPY_OFF(causecode->message, 4); |
(char *)avp->value + 3, avp->vlen - 3); | |
break; |
break; |
case AVP_CHALLENGE_RESPONSE: |
case AVP_CHALLENGE_RESPONSE: |
AVP_ALLOC(challengresp); |
AVP_ALLOC(challengresp); |
Line 619 do { \
|
Line 644 do { \
|
break; |
break; |
case AVP_ASSIGNED_SESSION_ID: |
case AVP_ASSIGNED_SESSION_ID: |
AVP_ALLOC(sessionid); |
AVP_ALLOC(sessionid); |
ptrs->sessionid->id = ntohs(ptr16[0]); | AVP_STORE16(sessionid->id, 0); |
break; |
break; |
case AVP_CALL_SERIAL_NUMBER: |
case AVP_CALL_SERIAL_NUMBER: |
AVP_ALLOC(serialnum); |
AVP_ALLOC(serialnum); |
ptrs->serialnum->serialnum = ntohl(ptr32[0]); | AVP_STORE32(serialnum->serialnum); |
break; |
break; |
case AVP_MINIMUM_BPS: |
case AVP_MINIMUM_BPS: |
AVP_ALLOC(minbps); |
AVP_ALLOC(minbps); |
ptrs->minbps->minbps = ntohl(ptr32[0]); | AVP_STORE32(minbps->minbps); |
break; |
break; |
case AVP_MAXIMUM_BPS: |
case AVP_MAXIMUM_BPS: |
AVP_ALLOC(maxbps); |
AVP_ALLOC(maxbps); |
ptrs->maxbps->maxbps = ntohl(ptr32[0]); | AVP_STORE32(maxbps->maxbps); |
break; |
break; |
case AVP_BEARER_TYPE: |
case AVP_BEARER_TYPE: |
AVP_ALLOC(bearer); |
AVP_ALLOC(bearer); |
ptrs->bearer->digital = | if (avp->vlen >= sizeof(u_int32_t)) { |
(ntohl(ptr32[0]) & L2TP_BEARER_DIGITAL) != 0; | ptrs->bearer->digital = |
ptrs->bearer->analog = | (ntohl(ptr32[0]) & L2TP_BEARER_DIGITAL) != 0; |
(ntohl(ptr32[0]) & L2TP_BEARER_ANALOG) != 0; | ptrs->bearer->analog = |
| (ntohl(ptr32[0]) & L2TP_BEARER_ANALOG) != 0; |
| } |
break; |
break; |
case AVP_FRAMING_TYPE: |
case AVP_FRAMING_TYPE: |
AVP_ALLOC(framing); |
AVP_ALLOC(framing); |
ptrs->framing->sync = | if (avp->vlen >= sizeof(u_int32_t)) { |
(ntohl(ptr32[0]) & L2TP_FRAMING_SYNC) != 0; | ptrs->framing->sync = |
ptrs->framing->async = | (ntohl(ptr32[0]) & L2TP_FRAMING_SYNC) != 0; |
(ntohl(ptr32[0]) & L2TP_FRAMING_ASYNC) != 0; | ptrs->framing->async = |
| (ntohl(ptr32[0]) & L2TP_FRAMING_ASYNC) != 0; |
| } |
break; |
break; |
case AVP_CALLED_NUMBER: |
case AVP_CALLED_NUMBER: |
AVP_ALLOC(callednum); |
AVP_ALLOC(callednum); |
Line 661 do { \
|
Line 690 do { \
|
break; |
break; |
case AVP_TX_CONNECT_SPEED: |
case AVP_TX_CONNECT_SPEED: |
AVP_ALLOC(txconnect); |
AVP_ALLOC(txconnect); |
ptrs->txconnect->bps = ntohl(ptr32[0]); | AVP_STORE32(txconnect->bps); |
break; |
break; |
case AVP_PHYSICAL_CHANNEL_ID: |
case AVP_PHYSICAL_CHANNEL_ID: |
AVP_ALLOC(channelid); |
AVP_ALLOC(channelid); |
ptrs->channelid->channel = ntohl(ptr32[0]); | AVP_STORE32(channelid->channel); |
break; |
break; |
case AVP_INITIAL_RECV_CONFREQ: |
case AVP_INITIAL_RECV_CONFREQ: |
AVP_ALLOC(recvlcp); |
AVP_ALLOC(recvlcp); |
Line 684 do { \
|
Line 713 do { \
|
break; |
break; |
case AVP_PROXY_AUTHEN_TYPE: |
case AVP_PROXY_AUTHEN_TYPE: |
AVP_ALLOC(proxyauth); |
AVP_ALLOC(proxyauth); |
ptrs->proxyauth->type = ntohs(ptr16[0]); | AVP_STORE16(proxyauth->type, 0); |
break; |
break; |
case AVP_PROXY_AUTHEN_NAME: |
case AVP_PROXY_AUTHEN_NAME: |
AVP_ALLOC(proxyname); |
AVP_ALLOC(proxyname); |
Line 699 do { \
|
Line 728 do { \
|
break; |
break; |
case AVP_PROXY_AUTHEN_ID: |
case AVP_PROXY_AUTHEN_ID: |
AVP_ALLOC(proxyid); |
AVP_ALLOC(proxyid); |
ptrs->proxyid->id = ntohs(ptr16[0]); | AVP_STORE16(proxyid->id, 0); |
break; |
break; |
case AVP_PROXY_AUTHEN_RESPONSE: |
case AVP_PROXY_AUTHEN_RESPONSE: |
AVP_ALLOC(proxyres); |
AVP_ALLOC(proxyres); |
Line 707 do { \
|
Line 736 do { \
|
memcpy(ptrs->proxyres->data, avp->value, avp->vlen); |
memcpy(ptrs->proxyres->data, avp->value, avp->vlen); |
break; |
break; |
case AVP_CALL_ERRORS: |
case AVP_CALL_ERRORS: |
{ |
|
u_int32_t vals[6]; |
|
|
|
memcpy(&vals, &ptr16[1], sizeof(vals)); |
|
AVP_ALLOC(callerror); |
AVP_ALLOC(callerror); |
ptrs->callerror->crc = ntohl(vals[0]); | if (avp->vlen >= |
ptrs->callerror->frame = ntohl(vals[1]); | sizeof(u_int16_t) + 6*sizeof(u_int32_t)) { |
ptrs->callerror->overrun = ntohl(vals[2]); | u_int32_t vals[6]; |
ptrs->callerror->buffer = ntohl(vals[3]); | |
ptrs->callerror->timeout = ntohl(vals[4]); | memcpy(&vals, &ptr16[1], sizeof(vals)); |
ptrs->callerror->alignment = ntohl(vals[5]); | ptrs->callerror->crc = ntohl(vals[0]); |
| ptrs->callerror->frame = ntohl(vals[1]); |
| ptrs->callerror->overrun = ntohl(vals[2]); |
| ptrs->callerror->buffer = ntohl(vals[3]); |
| ptrs->callerror->timeout = ntohl(vals[4]); |
| ptrs->callerror->alignment = ntohl(vals[5]); |
| } |
break; |
break; |
} |
|
case AVP_ACCM: |
case AVP_ACCM: |
{ |
|
u_int32_t vals[2]; |
|
|
|
memcpy(&vals, &ptr16[1], sizeof(vals)); |
|
AVP_ALLOC(accm); |
AVP_ALLOC(accm); |
ptrs->accm->xmit = ntohl(vals[0]); | if (avp->vlen >= |
ptrs->accm->recv = ntohl(vals[1]); | sizeof(u_int16_t) + 2*sizeof(u_int32_t)) { |
| u_int32_t vals[2]; |
| |
| memcpy(&vals, &ptr16[1], sizeof(vals)); |
| ptrs->accm->xmit = ntohl(vals[0]); |
| ptrs->accm->recv = ntohl(vals[1]); |
| } |
break; |
break; |
} |
|
case AVP_PRIVATE_GROUP_ID: |
case AVP_PRIVATE_GROUP_ID: |
AVP_ALLOC(groupid); |
AVP_ALLOC(groupid); |
ptrs->groupid->length = avp->vlen; |
ptrs->groupid->length = avp->vlen; |
Line 737 do { \
|
Line 768 do { \
|
break; |
break; |
case AVP_RX_CONNECT_SPEED: |
case AVP_RX_CONNECT_SPEED: |
AVP_ALLOC(rxconnect); |
AVP_ALLOC(rxconnect); |
ptrs->rxconnect->bps = ntohl(ptr32[0]); | AVP_STORE32(rxconnect->bps); |
break; |
break; |
case AVP_SEQUENCING_REQUIRED: |
case AVP_SEQUENCING_REQUIRED: |
AVP_ALLOC(seqrequired); |
AVP_ALLOC(seqrequired); |
Line 810 ppp_l2tp_avp_ptrs_destroy(struct ppp_l2tp_avp_ptrs **p
|
Line 841 ppp_l2tp_avp_ptrs_destroy(struct ppp_l2tp_avp_ptrs **p
|
#define DECODE_INITIAL(t) \ |
#define DECODE_INITIAL(t) \ |
void \ |
void \ |
ppp_l2tp_avp_decode_ ## t(const struct ppp_l2tp_avp_info *info, \ |
ppp_l2tp_avp_decode_ ## t(const struct ppp_l2tp_avp_info *info, \ |
const struct ppp_l2tp_avp *avp, char *buf, size_t bmax) \ | struct ppp_l2tp_avp *avp, char *buf, size_t bmax) \ |
{ \ |
{ \ |
const struct ppp_l2tp_avp_list list \ |
const struct ppp_l2tp_avp_list list \ |
= { 1, (struct ppp_l2tp_avp *)avp }; \ |
= { 1, (struct ppp_l2tp_avp *)avp }; \ |
struct ppp_l2tp_avp_ptrs *ptrs; \ |
struct ppp_l2tp_avp_ptrs *ptrs; \ |
\ |
\ |
|
(void)info; \ |
if ((ptrs = ppp_l2tp_avp_list2ptrs(&list)) == NULL) { \ |
if ((ptrs = ppp_l2tp_avp_list2ptrs(&list)) == NULL) { \ |
snprintf(buf, bmax, \ |
snprintf(buf, bmax, \ |
"decode failed: %s", strerror(errno)); \ |
"decode failed: %s", strerror(errno)); \ |
Line 830 done: \
|
Line 862 done: \
|
|
|
#define DECODE_BYTES(p, len) \ |
#define DECODE_BYTES(p, len) \ |
do { \ |
do { \ |
int _i; \ | u_int _i; \ |
\ |
\ |
for (_i = 0; _i < len; _i++) { \ |
for (_i = 0; _i < len; _i++) { \ |
snprintf(buf + strlen(buf), \ |
snprintf(buf + strlen(buf), \ |