📄 avp.c
字号:
{ if (DEBUG) log (LOG_DEBUG, "%s: avp is incorrect size. %d < 10\n", __FUNCTION__, datalen); wrong_length (c, "Result Code", 10, datalen, 1); return -EINVAL; } switch (c->msgtype) { case CDN: case StopCCN: break; default: if (DEBUG) log (LOG_DEBUG, "%s: result code not appropriate for %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } }#endif result = ntohs (raw[3]); error = ntohs (raw[4]); if ((c->msgtype == StopCCN) && ((result > 7) || (result < 1))) { if (DEBUG) log (LOG_DEBUG, "%s: result code out of range (%d %d %d). Ignoring.\n", __FUNCTION__, result, error, datalen); return 0; } if ((c->msgtype == CDN) && ((result > 11) || (result < 1))) { if (DEBUG) log (LOG_DEBUG, "%s: result code out of range (%d %d %d). Ignoring.\n", __FUNCTION__, result, error, datalen); return 0; } c->error = error; c->result = result; safe_copy (c->errormsg, (char *) &raw[5], datalen - 10); if (debug_avp) { if (DEBUG && (c->msgtype == StopCCN)) { log (LOG_DEBUG, "%s: peer closing for reason %d (%s), error = %d (%s)\n", __FUNCTION__, result, stopccn_result_codes[result], error, c->errormsg); } else { log (LOG_DEBUG, "%s: peer closing for reason %d (%s), error = %d (%s)\n", __FUNCTION__, result, cdn_result_codes[result], error, c->errormsg); } } return 0;}int protocol_version_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * Find out what version of l2tp the other side is using. * I'm not sure what we're supposed to do with this but whatever.. */ int ver; _u16 *raw = data;#ifdef SANITY if (t->sanity) { if (datalen != 8) { if (DEBUG) log (LOG_DEBUG, "%s: avp is incorrect size. %d != 8\n", __FUNCTION__, datalen); wrong_length (c, "Protocol Version", 8, datalen, 1); return -EINVAL; } switch (c->msgtype) { case SCCRP: case SCCRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: protocol version not appropriate for %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } }#endif ver = ntohs (raw[3]); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer is using version %d, revision %d.\n", __FUNCTION__, (ver >> 8), ver & 0xFF); } return 0;}int framing_caps_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * Retrieve the framing capabilities * from the peer */ int caps; _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case SCCRP: case SCCRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: framing capabilities not appropriate for %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen != 10) { if (DEBUG) log (LOG_DEBUG, "%s: avp is incorrect size. %d != 10\n", __FUNCTION__, datalen); wrong_length (c, "Framming Capabilities", 10, datalen, 0); return -EINVAL; } }#endif caps = ntohs (raw[4]); if (debug_avp) if (DEBUG) log (LOG_DEBUG, "%s: supported peer frames:%s%s\n", __FUNCTION__, caps & ASYNC_FRAMING ? " async" : "", caps & SYNC_FRAMING ? " sync" : ""); t->fc = caps & (ASYNC_FRAMING | SYNC_FRAMING); return 0;}int bearer_caps_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What kind of bearer channels does our peer support? */ int caps; _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case SCCRP: case SCCRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: bearer capabilities not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen != 10) { if (DEBUG) log (LOG_DEBUG, "%s: avp is incorrect size. %d != 10\n", __FUNCTION__, datalen); wrong_length (c, "Bearer Capabilities", 10, datalen, 0); return -EINVAL; } }#endif caps = ntohs (raw[4]); if (debug_avp) { if (DEBUG) { log (LOG_DEBUG, "%s: supported peer bearers:%s%s\n", __FUNCTION__, caps & ANALOG_BEARER ? " analog" : "", caps & DIGITAL_BEARER ? " digital" : ""); } } t->bc = caps & (ANALOG_BEARER | DIGITAL_BEARER); return 0;}/* FIXME: I need to handle tie breakers eventually */int firmware_rev_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * Report and record remote firmware version */ int ver; _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case SCCRP: case SCCRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: firmware revision not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen != 8) { if (DEBUG) log (LOG_DEBUG, "%s: avp is incorrect size. %d != 8\n", __FUNCTION__, datalen); wrong_length (c, "Firmware Revision", 8, datalen, 0); return -EINVAL; } }#endif ver = ntohs (raw[3]); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer reports firmware version %d (0x%.4x)\n", __FUNCTION__, ver, ver); } t->firmware = ver; return 0;}int bearer_type_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What kind of bearer channel is the call on? */ int b; _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case ICRQ: case OCRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: bearer type not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen != 10) { if (DEBUG) log (LOG_DEBUG, "%s: avp is incorrect size. %d != 10\n", __FUNCTION__, datalen); wrong_length (c, "Bearer Type", 10, datalen, 0); return -EINVAL; } }#endif b = ntohs (raw[4]); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer bears:%s\n", __FUNCTION__, b & ANALOG_BEARER ? " analog" : "digital"); } t->call_head->bearer = b; return 0;}int frame_type_avp (struct tunnel *t, struct call *c, void *data, int datalen){ /* * What kind of frame channel is the call on? */ int b; _u16 *raw = data;#ifdef SANITY if (t->sanity) { switch (c->msgtype) { case ICCN: case OCRQ: case OCCN: break; default: if (DEBUG) log (LOG_DEBUG, "%s: frame type not appropriate for message %s. Ignoring.\n", __FUNCTION__, msgtypes[c->msgtype]); return 0; } if (datalen != 10) { if (DEBUG) log (LOG_DEBUG, "%s: avp is incorrect size. %d != 10\n", __FUNCTION__, datalen); wrong_length (c, "Frame Type", 10, datalen, 0); return -EINVAL; } }#endif b = ntohs (raw[4]); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer uses:%s frames\n", __FUNCTION__, b & ASYNC_FRAMING ? " async" : "sync"); } c->frame = b; return 0;}int hostname_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 SCCRP: case SCCRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: hostname 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, "Hostname", 6, datalen, 1); return -EINVAL; } }#endif size = raw[0] & 0x0FFF; if (size > MAXSTRLEN - 1) { if (DEBUG) log (LOG_DEBUG, "%s: truncating reported hostname (size is %d)\n", __FUNCTION__, size); size = MAXSTRLEN - 1; } safe_copy (t->hostname, (char *) &raw[3], size - 6); if (debug_avp) { if (DEBUG) log (LOG_DEBUG, "%s: peer reports hostname '%s'\n", __FUNCTION__, t->hostname); } return 0;}int dialing_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 ICRQ: break; default: if (DEBUG) log (LOG_DEBUG, "%s: dialing 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, "Dialing Number", 6, datalen, 1); return -EINVAL; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -