📄 avp.c
字号:
}#endif size = raw[0] & 0x0FFF; if (size > MAXSTRLEN - 1) { if (DEBUG) log (LOG_DEBUG, "%s: truncating reported dialing number (size is %d)\n", __FUNCTION__, size); size = MAXSTRLEN - 1; } safe_copy (t->call_head->dialing, (char *) &raw[3], size); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer reports dialing number '%s'\n", __FUNCTION__, t->call_head->dialing); } return 0;}int dialed_number_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What is the peer's name? */ int size; _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case OCRQ: case ICRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: dialed number not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen < 6) { if (DEBUG) log (LOG_DEBUG, "%s: avp is too small. %d < 6\n", __FUNCTION__, datalen); wrong_length (c, "Dialed Number", 6, datalen, 1); return -EINVAL; } }#endif size = raw[0] & 0x0FFF; if (size > MAXSTRLEN - 1) { if (DEBUG) log (LOG_DEBUG, "%s: truncating reported dialed number (size is %d)\n", __FUNCTION__, size); size = MAXSTRLEN - 1; } safe_copy (t->call_head->dialed, (char *) &raw[3], size); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer reports dialed number '%s'\n", __FUNCTION__, t->call_head->dialed); } return 0;}int sub_address_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What is the peer's name? */ int size; _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case OCRP: case ICRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: sub_address not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen < 6) { if (DEBUG) log (LOG_DEBUG, "%s: avp is too small. %d < 6\n", __FUNCTION__, datalen); wrong_length (c, "Sub-address", 6, datalen, 1); return -EINVAL; } }#endif size = raw[0] & 0x0FFF; if (size > MAXSTRLEN - 1) { if (DEBUG) log (LOG_DEBUG, "%s: truncating reported sub address (size is %d)\n", __FUNCTION__, size); size = MAXSTRLEN - 1; } safe_copy (t->call_head->subaddy, (char *) &raw[3], size); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer reports subaddress '%s'\n", __FUNCTION__, t->call_head->subaddy); } return 0;}int vendor_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What vendor makes the other end? */ int size; _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case SCCRP: case SCCRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: vendor not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen < 6) { if (DEBUG) log (LOG_DEBUG, "%s: avp is too small. %d < 6\n", __FUNCTION__, datalen); wrong_length (c, "Vendor", 6, datalen, 1); return -EINVAL; } }#endif size = raw[0] & 0x0FFF; if (size > MAXSTRLEN - 1) { if (DEBUG) log (LOG_DEBUG, "%s: truncating reported vendor (size is %d)\n", __FUNCTION__, size); size = MAXSTRLEN - 1; } safe_copy (t->vendor, (char *) &raw[3], size); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer reports vendor '%s'\n", __FUNCTION__, t->vendor); } return 0;}int challenge_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * We are sent a challenge */ _u16 *raw = data; int size;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case SCCRP: case SCCRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: challenge not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen < 6) { if (DEBUG) log (LOG_DEBUG, "%s: avp is too small. %d < 6\n", __FUNCTION__, datalen); wrong_length (c, "challenge", 6, datalen, 1); return -EINVAL; } }#endif /* size = raw[0] & 0x0FFF; */ /* length field of AVP's is only 10 bits long, not 12 */ size = raw[0] & 0x03FF; size -= sizeof (struct avp_hdr); /* if (size != MD_SIG_SIZE) { log (LOG_DEBUG, "%s: Challenge is not the right length (%d != %d)\n", __FUNCTION__, size, MD_SIG_SIZE); return -EINVAL; } */ t->chal_us.challenge = malloc(size+1); if (t->chal_us.challenge == NULL) { return -ENOMEM; } memset(t->chal_us.challenge, 0, size+1); bcopy (&raw[3], (t->chal_us.challenge), size); t->chal_us.state = STATE_CHALLENGED; if (debug_avp) { log (LOG_DEBUG, "%s: challenge avp found\n", __FUNCTION__); } return 0;}int chalresp_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * We are sent a challenge */ _u16 *raw = data; int size;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case SCCRP: case SCCCN: break; default: if (DEBUG) log (LOG_DEBUG, "%s: challenge response not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen < 6) { if (DEBUG) log (LOG_DEBUG, "%s: avp is too small. %d < 6\n", __FUNCTION__, datalen); wrong_length (c, "challenge", 6, datalen, 1); return -EINVAL; } }#endif size = raw[0] & 0x0FFF; size -= sizeof (struct avp_hdr); if (size != MD_SIG_SIZE) { log (LOG_DEBUG, "%s: Challenge is not the right length (%d != %d)\n", __FUNCTION__, size, MD_SIG_SIZE); return -EINVAL; } bcopy (&raw[3], t->chal_them.reply, MD_SIG_SIZE); if (debug_avp) { log (LOG_DEBUG, "%s: Challenge reply found\n", __FUNCTION__); } return 0;}int assigned_tunnel_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What is their TID that we must use from now on? */ _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case SCCRP: case SCCRQ: case StopCCN: break; default: if (DEBUG) log (LOG_DEBUG, "%s: tunnel ID not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen != 8) { if (DEBUG) log (LOG_DEBUG, "%s: avp is wrong size. %d != 8\n", __FUNCTION__, datalen); wrong_length (c, "Assigned Tunnel ID", 8, datalen, 0); return -EINVAL; } }#endif if (c->msgtype == StopCCN) { t->qtid = ntohs (raw[3]); } else { t->tid = ntohs (raw[3]); } if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: using peer's tunnel %d\n", __FUNCTION__, ntohs (raw[3])); } return 0;}int assigned_call_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What is their CID that we must use from now on? */ _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case CDN: case ICRP: case ICRQ: case OCRP: /* jz: deleting the debug message */ break; case OCRQ: default: if (DEBUG) log (LOG_DEBUG, "%s: call ID not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen != 8) { if (DEBUG) log (LOG_DEBUG, "%s: avp is wrong size. %d != 8\n", __FUNCTION__, datalen); wrong_length (c, "Assigned Call ID", 8, datalen, 0); return -EINVAL; } }#endif if (c->msgtype == CDN) { c->qcid = ntohs (raw[3]); } else if (c->msgtype == ICRQ) { t->call_head->cid = ntohs (raw[3]); } else if (c->msgtype == ICRP) { c->cid = ntohs (raw[3]); } else if (c->msgtype == OCRP) { /* jz: copy callid to c->cid */ c->cid = ntohs (raw[3]); } else { log (LOG_DEBUG, "%s: Dunno what to do when it's state %s!\n", __FUNCTION__, msgtypes[c->msgtype]); } if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: using peer's call %d\n", __FUNCTION__, ntohs (raw[3])); } return 0;}int packet_delay_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What is their CID that we must use from now on? */ _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case ICRP: case OCRQ: case ICCN: case OCRP: case OCCN: break; default: if (DEBUG) log (LOG_DEBUG, "%s: packet delay not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen != 8) { if (DEBUG)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -