static void SendPapCode(struct authinfo *authp, int code, const char *message) { struct fsmheader lh; struct mbuf *bp; u_char *cp; int plen, mlen; lh.code = code; lh.id = authp->id; mlen = strlen(message); plen = mlen + 1; lh.length = htons(plen + sizeof(struct fsmheader)); bp = m_get(plen + sizeof(struct fsmheader), MB_PAPOUT); memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader)); cp = MBUF_CTOP(bp) + sizeof(struct fsmheader); /* * If our message is longer than 255 bytes, truncate the length to * 255 and send the entire message anyway. Maybe the other end will * display it... (see pap_Input() !) */ *cp++ = mlen > 255 ? 255 : mlen; memcpy(cp, message, mlen); log_Printf(LogPHASE, "Pap Output: %s\n", papcodes[code]); link_PushPacket(&authp->physical->link, bp, authp->physical->dl->bundle, LINK_QUEUES(&authp->physical->link) - 1, PROTO_PAP); }
static void pap_Req(struct authinfo *authp) { struct bundle *bundle = authp->physical->dl->bundle; struct fsmheader lh; struct mbuf *bp; u_char *cp; int namelen, keylen, plen; namelen = strlen(bundle->cfg.auth.name); keylen = strlen(bundle->cfg.auth.key); plen = namelen + keylen + 2; log_Printf(LogDEBUG, "pap_Req: namelen = %d, keylen = %d\n", namelen, keylen); log_Printf(LogPHASE, "Pap Output: %s ********\n", bundle->cfg.auth.name); if (*bundle->cfg.auth.name == '\0') log_Printf(LogWARN, "Sending empty PAP authname!\n"); lh.code = PAP_REQUEST; lh.id = authp->id; lh.length = htons(plen + sizeof(struct fsmheader)); bp = m_get(plen + sizeof(struct fsmheader), MB_PAPOUT); memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader)); cp = MBUF_CTOP(bp) + sizeof(struct fsmheader); *cp++ = namelen; memcpy(cp, bundle->cfg.auth.name, namelen); cp += namelen; *cp++ = keylen; memcpy(cp, bundle->cfg.auth.key, keylen); link_PushPacket(&authp->physical->link, bp, bundle, LINK_QUEUES(&authp->physical->link) - 1, PROTO_PAP); }
/*fanzhibin f49086 add it end*/ #if(FEATURE_ON == FEATURE_PPP) static const VOS_CHAR * const papcodes[] = { "???", "REQUEST", "SUCCESS", "FAILURE" }; #define MAXPAPCODE (sizeof papcodes / sizeof papcodes[0] - 1) #if 0/*fanzhibin f49086 delete it*/ static void pap_Req(struct authinfo *authp) { struct bundle *bundle = authp->physical->dl->bundle; struct fsmheader lh; struct ppp_mbuf *bp; VOS_CHAR *cp; VOS_INT32 namelen, keylen, plen; namelen = strlen(bundle->cfg.auth.name); keylen = strlen(bundle->cfg.auth.key); plen = namelen + keylen + 2; PS_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "pap_Req: namelen = %d, keylen = %d\n", namelen, keylen); log_Printf(LogPHASE, "Pap Output: %s ********\n", bundle->cfg.auth.name); if (*bundle->cfg.auth.name == '\0') log_Printf(LogWARN, "Sending empty PAP authname!\n"); lh.code = PAP_REQUEST; lh.id = authp->id; lh.length = htons(plen + sizeof(struct fsmheader)); bp = ppp_m_get(plen + sizeof(struct fsmheader)); PS_MEM_CPY(PPP_MBUF_CTOP(bp), &lh, sizeof(struct fsmheader)); cp = PPP_MBUF_CTOP(bp) + sizeof(struct fsmheader); *cp++ = namelen; PS_MEM_CPY(cp, bundle->cfg.auth.name, namelen); cp += namelen; *cp++ = keylen; PS_MEM_CPY(cp, bundle->cfg.auth.key, keylen); link_PushPacket(&authp->physical->link, bp,/* bundle,*/ LINK_QUEUES(&authp->physical->link) - 1, PROTO_PAP); }
void link_PushPacket(struct link *l, struct mbuf *bp, struct bundle *b, int pri, u_short proto) { int layer; /* * When we ``push'' a packet into the link, it gets processed by the * ``push'' function in each layer starting at the top. * We never expect the result of a ``push'' to be more than one * packet (as we do with ``pull''s). */ if(pri < 0 || (unsigned)pri >= LINK_QUEUES(l)) pri = 0; for (layer = l->nlayers; layer && bp; layer--) if (l->layer[layer - 1]->push != NULL) bp = (*l->layer[layer - 1]->push)(b, l, bp, pri, &proto); if (bp) { link_AddOutOctets(l, m_length(bp)); log_Printf(LogDEBUG, "link_PushPacket: Transmit proto 0x%04x\n", proto); m_enqueue(l->Queue + pri, m_pullup(bp)); } }
size_t link_QueueLen(struct link *l) { unsigned i; size_t len; for (i = 0, len = 0; i < LINK_QUEUES(l); i++) len += l->Queue[i].len; return len; }
VOS_UINT32 link_QueueLen(struct link *l) { VOS_UINT32 i; VOS_UINT32 len; for (i = 0, len = 0; i < LINK_QUEUES(l); i++) { len += l->Queue[i].len; } return len; }
struct mbuf * link_Dequeue(struct link *l) { int pri; struct mbuf *bp; for (bp = NULL, pri = LINK_QUEUES(l) - 1; pri >= 0; pri--) if (l->Queue[pri].len) { bp = m_dequeue(l->Queue + pri); log_Printf(LogDEBUG, "link_Dequeue: Dequeued from queue %d," " containing %lu more packets\n", pri, (u_long)l->Queue[pri].len); break; } return bp; }
/*lint -e958*/ struct ppp_mbuf * link_Dequeue(struct link *l) { VOS_INT32 pri; struct ppp_mbuf *bp; for (bp = VOS_NULL_PTR, pri = LINK_QUEUES(l) - 1; pri >= 0; pri--) { if (l->Queue[pri].len) { bp = ppp_m_dequeue(l->Queue + pri); PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "pri <1>;length <2>\r\n", pri, (VOS_INT32)l->Queue[pri].len); break; } } return bp; }
size_t link_QueueBytes(struct link *l) { unsigned i; size_t len, bytes; struct mbuf *m; bytes = 0; for (i = 0, len = 0; i < LINK_QUEUES(l); i++) { len = l->Queue[i].len; m = l->Queue[i].top; while (len--) { bytes += m_length(m); m = m->m_nextpkt; } } return bytes; }
void SendPapCode(struct link *l, VOS_CHAR code, VOS_CHAR *message) { struct fsmheader lh; struct ppp_mbuf *bp; VOS_CHAR *cp; VOS_UINT32 plen, mlen; lh.code = code; lh.id = l->pap.auth.id; mlen = VOS_StrNLen(message,20); plen = mlen + 1; lh.length = (VOS_UINT16)VOS_HTONS(plen + sizeof(struct fsmheader)); bp = ppp_m_get(plen + PPP_RECIEVE_RESERVE_FOR_HEAD + PPP_RECIEVE_RESERVE_FOR_TAIL + sizeof(struct fsmheader)); if(bp == VOS_NULL) { PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "no mbuf"); return; } /*预留头部*/ bp->m_offset = PPP_RECIEVE_RESERVE_FOR_HEAD; /*头部与尾部都留出来了*/ bp->m_len = plen + sizeof(struct fsmheader); PS_MEM_CPY(PPP_MBUF_CTOP(bp), &lh, sizeof(struct fsmheader)); cp = PPP_MBUF_CTOP(bp) + sizeof(struct fsmheader); /* * If our message is longer than 255 bytes, truncate the length to * 255 and send the entire message anyway. Maybe the other end will * display it... (see pap_Input() !) */ *cp++ = (VOS_CHAR)(mlen > 255 ? 255 : mlen); PS_MEM_CPY(cp, message, mlen); PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Pap Output\r\n"); link_PushPacket(l, bp,/* authp->physical->dl->bundle,*/ LINK_QUEUES(l) - 1, PROTO_PAP); }
/*lint -e732*/ VOS_UINT32 link_QueueBytes(struct link *l) { VOS_UINT32 i; VOS_UINT32 len, bytes; struct ppp_mbuf *m; bytes = 0; for (i = 0, len = 0; i < LINK_QUEUES(l); i++) { len = l->Queue[i].len; m = l->Queue[i].top; while (len--) { bytes += ppp_m_length(m); m = m->m_nextpkt; } } return bytes; }
/***************************************************************************** 函 数 名 : ChapOutput 功能描述 : 构造CHAP帧并发送 输入参数 : l - PPP链接 code - 待填写到头部的Code值 id - 待填写到头部的Identifier值 ptr - 待填写的CHAP数据 count - 待填写的CHAP数据的长度, 单位: 字节 text - 字符串, 用于日志 输出参数 : 无 返 回 值 : NULL 调用函数 : 被调函数 : 说 明 : 不对ptr与code进行组合检查, 如code为某值时, ptr不应为空等等, 因为此函数为一通用函数, 支持生成所有的CHAP帧, 并能扩展为支持 MS-CHAP帧等, 各种code, ptr组合情况众多, 一切相关检查交由外部 调用者来完成 修改历史 : 1.日 期 : 2008年10月24日 作 者 : liukai 修改内容 : porting from BSD *****************************************************************************/ VOS_VOID ChapOutput(struct link *l, VOS_INT32 code, VOS_CHAR id, const VOS_UCHAR *ptr, VOS_UINT32 count, const VOS_CHAR *text) { VOS_UINT32 len; /* length of a CHAP frame */ struct fsmheader lh; struct ppp_mbuf *bp; len = sizeof(struct fsmheader) + count; lh.code = (VOS_CHAR)code; lh.id = id; lh.length = (VOS_UINT16)VOS_HTONS(len); bp = ppp_m_get((VOS_INT32)len); if (VOS_NULL_PTR == bp) { PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "no mbuf\r\n"); return; } PS_MEM_CPY(PPP_MBUF_CTOP(bp), &lh, sizeof(struct fsmheader)); if ((count > 0) && (VOS_NULL_PTR != ptr)) { PS_MEM_CPY(PPP_MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count); } if (VOS_NULL_PTR == text) { PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Chap Output: code %d\r\n", code); } else { PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL,"Chap Output: code %d with text\r\n", code); } /* now a CHAP frame is ready */ link_PushPacket(l, bp, LINK_QUEUES(l) - 1, PROTO_CHAP); return; } /* ChapOutput */
static void SendLqrData(struct lcp *lcp) { struct mbuf *bp; int extra; extra = proto_WrapperOctets(lcp, PROTO_LQR) + acf_WrapperOctets(lcp, PROTO_LQR); bp = m_get(sizeof(struct lqrdata) + extra, MB_LQROUT); bp->m_len -= extra; bp->m_offset += extra; /* * Send on the highest priority queue. We send garbage - the real data * is written by lqr_LayerPush() where we know how to fill in all the * fields. Note, lqr_LayerPush() ``knows'' that we're pushing onto the * highest priority queue, and factors out packet & octet values from * other queues! */ link_PushPacket(lcp->fsm.link, bp, lcp->fsm.bundle, LINK_QUEUES(lcp->fsm.link) - 1, PROTO_LQR); }
static void ChapOutput(struct physical *physical, u_int code, u_int id, const u_char *ptr, int count, const char *text) { int plen; struct fsmheader lh; struct mbuf *bp; plen = sizeof(struct fsmheader) + count; lh.code = code; lh.id = id; lh.length = htons(plen); bp = m_get(plen, MB_CHAPOUT); memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader)); if (count) memcpy(MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count); log_DumpBp(LogDEBUG, "ChapOutput", bp); if (text == NULL) log_Printf(LogPHASE, "Chap Output: %s\n", chapcodes[code]); else log_Printf(LogPHASE, "Chap Output: %s (%s)\n", chapcodes[code], text); link_PushPacket(&physical->link, bp, physical->dl->bundle, LINK_QUEUES(&physical->link) - 1, PROTO_CHAP); }