Mbuf CcpDataInput(Bund b, Mbuf comp) { CcpState const ccp = &b->ccp; Mbuf plain; LogDumpBp(LG_FRAME, comp, "[%s] %s: recv comp", Pref(&ccp->fsm), Fsm(&ccp->fsm)); /* Decompress packet */ if ((!ccp->recv) || (!ccp->recv->Decompress)) { Log(LG_ERR, ("[%s] %s: no compression for recv", Pref(&ccp->fsm), Fsm(&ccp->fsm))); mbfree(comp); return(NULL); } plain = (*ccp->recv->Decompress)(b, comp); /* Encrypted ok? */ if (plain == NULL) { Log(LG_CCP, ("[%s] %s: decompression failed", Pref(&ccp->fsm), Fsm(&ccp->fsm))); return(NULL); } LogDumpBp(LG_FRAME, plain, "[%s] %s: recv plain", Pref(&ccp->fsm), Fsm(&ccp->fsm)); return(plain); }
void ConvertITP(char exp[]){ int i; int len=strlen(exp); Node* stack=(Node*)malloc(sizeof(Node)); stack->top=-1; stack->capacity=len; stack->Array=(int*)malloc(sizeof(int)*len); for(i=0;i<len;i++){ if(IsOperand(exp[i])){ printf("%c",exp[i]); } else if(exp[i]=='('){ Push(stack,exp[i]); } else if(exp[i]==')'){ while(!IsStackEmpty(stack) && Peek(stack)!='('){ printf("%c",Pop(stack)); } if(!IsStackEmpty(stack) && Peek(stack)!='('){ printf("\nError"); return; }else{ Pop(stack); } } else{ while(!IsStackEmpty(stack) && Pref(exp[i])<=Pref(Peek(stack))){ printf("%c",Pop(stack)); } Push(stack,exp[i]); } } while(!IsStackEmpty(stack)){ printf("%c",Pop(stack)); } }
int CcpStat(Context ctx, int ac, char *av[], void *arg) { CcpState const ccp = &ctx->bund->ccp; char buf[64]; Printf("[%s] %s [%s]\r\n", Pref(&ccp->fsm), Fsm(&ccp->fsm), FsmStateName(ccp->fsm.state)); Printf("Enabled protocols:\r\n"); OptStat(ctx, &ccp->options, gConfList); #ifdef CCP_MPPC MppcStat(ctx, ac, av, arg); #endif Printf("Outgoing compression:\r\n"); Printf("\tProto\t: %s (%s)\r\n", !ccp->xmit ? "none" : ccp->xmit->name, (ccp->xmit && ccp->xmit->Describe) ? (*ccp->xmit->Describe)(ctx->bund, COMP_DIR_XMIT, buf, sizeof(buf)) : ""); if (ccp->xmit && ccp->xmit->Stat) ccp->xmit->Stat(ctx, COMP_DIR_XMIT); Printf("\tResets\t: %d\r\n", ccp->xmit_resets); Printf("Incoming decompression:\r\n"); Printf("\tProto\t: %s (%s)\r\n", !ccp->recv ? "none" : ccp->recv->name, (ccp->recv && ccp->recv->Describe) ? (*ccp->recv->Describe)(ctx->bund, COMP_DIR_RECV, buf, sizeof(buf)) : ""); if (ccp->recv && ccp->recv->Stat) ccp->recv->Stat(ctx, COMP_DIR_RECV); Printf("\tResets\t: %d\r\n", ccp->recv_resets); return(0); }
Mbuf CcpDataOutput(Bund b, Mbuf plain) { CcpState const ccp = &b->ccp; Mbuf comp; LogDumpBp(LG_FRAME, plain, "[%s] %s: xmit plain", Pref(&ccp->fsm), Fsm(&ccp->fsm)); /* Compress packet */ if ((!ccp->xmit) || (!ccp->xmit->Compress)) { Log(LG_ERR, ("[%s] %s: no encryption for xmit", Pref(&ccp->fsm), Fsm(&ccp->fsm))); mbfree(plain); return(NULL); } comp = (*ccp->xmit->Compress)(b, plain); LogDumpBp(LG_FRAME, comp, "[%s] %s: xmit comp", Pref(&ccp->fsm), Fsm(&ccp->fsm)); return(comp); }
void CcpSendResetReq(Bund b) { CcpState const ccp = &b->ccp; CompType const ct = ccp->recv; Fsm const fp = &ccp->fsm; Mbuf bp = NULL; if (ct == NULL) { Log(LG_ERR, ("[%s] %s: CcpSendResetReq() call from undefined decompressor!", Pref(fp), Fsm(fp))); return; } ccp->recv_resets++; if (ct->SendResetReq) bp = (*ct->SendResetReq)(b); Log(LG_CCP, ("[%s] %s: SendResetReq #%d link %d (%s)", Pref(fp), Fsm(fp), fp->reqid, 0, FsmStateName(fp->state))); FsmOutputMbuf(fp, CODE_RESETREQ, fp->reqid++, bp); }
static int CcpCheckEncryption(Bund b) { #if 0 CcpState const ccp = &b->ccp; /* Already checked? */ if (ccp->crypt_check) return(0); ccp->crypt_check = 1; /* Is encryption required? */ if (Enabled(&ccp->options, gMppePolicy)) { if (b->params.msoft.policy != MPPE_POLICY_REQUIRED) return(0); } else { if (!Enabled(&b->conf.options, BUND_CONF_CRYPT_REQD)) return(0); } /* Was MPPE encryption enabled? If not, ignore requirement */ if (!Enabled(&ccp->options, gMppe40) && !Enabled(&ccp->options, gMppe56) && !Enabled(&ccp->options, gMppe128) && !Enabled(&ccp->options, gMppePolicy)) return(0); /* Make sure MPPE was negotiated in both directions */ if (!OPEN_STATE(ccp->fsm.state) || !ccp->xmit || ccp->xmit->type != CCP_TY_MPPC || !ccp->recv || ccp->recv->type != CCP_TY_MPPC #ifdef CCP_MPPC || !(ccp->mppc.recv_bits & MPPE_BITS) || !(ccp->mppc.xmit_bits & MPPE_BITS) #endif ) goto fail; /* Looks OK */ return(0); fail: Log(LG_ERR, ("[%s] %s: encryption required, but MPPE was not" " negotiated in both directions", Pref(&ccp->fsm), Fsm(&ccp->fsm))); FsmFailure(&ccp->fsm, FAIL_CANT_ENCRYPT); FsmFailure(&b->ipcp.fsm, FAIL_CANT_ENCRYPT); FsmFailure(&b->ipv6cp.fsm, FAIL_CANT_ENCRYPT); return(-1); #endif return (0); }
void CcpRecvMsg(Bund b, struct ng_mesg *msg, int len) { CcpState const ccp = &b->ccp; Fsm const fp = &ccp->fsm; switch (msg->header.typecookie) { #ifdef USE_NG_MPPC case NGM_MPPC_COOKIE: switch (msg->header.cmd) { case NGM_MPPC_RESETREQ: { CcpSendResetReq(b); return; } default: break; } break; #endif #ifdef USE_NG_DEFLATE case NGM_DEFLATE_COOKIE: switch (msg->header.cmd) { case NGM_DEFLATE_RESETREQ: { CcpSendResetReq(b); return; } default: break; } break; #endif #ifdef USE_NG_PRED1 case NGM_PRED1_COOKIE: switch (msg->header.cmd) { case NGM_PRED1_RESETREQ: { CcpSendResetReq(b); return; } default: break; } break; #endif default: break; } /* Unknown! */ Log(LG_ERR, ("[%s] %s: rec'd unknown netgraph message: cookie=%d, cmd=%d", Pref(fp), Fsm(fp), msg->header.typecookie, msg->header.cmd)); }
static void CcpRecvResetReq(Fsm fp, int id, Mbuf bp) { Bund b = (Bund)fp->arg; CcpState const ccp = &b->ccp; CompType const ct = ccp->xmit; int noAck = 0; ccp->xmit_resets++; bp = (ct && ct->RecvResetReq) ? (*ct->RecvResetReq)(b, id, bp, &noAck) : NULL; if (!noAck) { Log(LG_CCP, ("[%s] %s: SendResetAck #%d link %d (%s)", Pref(fp), Fsm(fp), id, 0, FsmStateName(fp->state))); FsmOutputMbuf(fp, CODE_RESETACK, id, bp); } }
int Ipv6cpStat(Context ctx, int ac, char *av[], void *arg) { Ipv6cpState const ipv6cp = &ctx->bund->ipv6cp; Fsm fp = &ipv6cp->fsm; Printf("[%s] %s [%s]\r\n", Pref(fp), Fsm(fp), FsmStateName(fp->state)); Printf("Interface identificators:\r\n"); Printf("\tSelf: %02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n", ipv6cp->myintid[0], ipv6cp->myintid[1], ipv6cp->myintid[2], ipv6cp->myintid[3], ipv6cp->myintid[4], ipv6cp->myintid[5], ipv6cp->myintid[6], ipv6cp->myintid[7]); Printf("\tPeer: %02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n", ipv6cp->hisintid[0], ipv6cp->hisintid[1], ipv6cp->hisintid[2], ipv6cp->hisintid[3], ipv6cp->hisintid[4], ipv6cp->hisintid[5], ipv6cp->hisintid[6], ipv6cp->hisintid[7]); Printf("IPV6CP Options:\r\n"); OptStat(ctx, &ipv6cp->conf.options, gConfList); return (0); }
static void CcpLayerUp(Fsm fp) { Bund b = (Bund)fp->arg; CcpState const ccp = &b->ccp; struct ngm_connect cn; char buf[64]; /* If nothing was negotiated in either direction, close CCP */ if ((!ccp->recv || !(*ccp->recv->Negotiated)(b, COMP_DIR_RECV)) && (!ccp->xmit || !(*ccp->xmit->Negotiated)(b, COMP_DIR_XMIT))) { Log(LG_CCP, ("[%s] %s: No compression negotiated", Pref(fp), Fsm(fp))); FsmFailure(fp, FAIL_NEGOT_FAILURE); return; } /* Check for required encryption */ if (CcpCheckEncryption(b) < 0) { return; } /* Initialize each direction */ if (ccp->xmit != NULL && ccp->xmit->Init != NULL && (*ccp->xmit->Init)(b, COMP_DIR_XMIT) < 0) { Log(LG_CCP, ("[%s] %s: compression init failed", Pref(fp), Fsm(fp))); FsmFailure(fp, FAIL_NEGOT_FAILURE); /* XXX */ return; } if (ccp->recv != NULL && ccp->recv->Init != NULL && (*ccp->recv->Init)(b, COMP_DIR_RECV) < 0) { Log(LG_CCP, ("[%s] %s: decompression init failed", Pref(fp), Fsm(fp))); FsmFailure(fp, FAIL_NEGOT_FAILURE); /* XXX */ return; } if (ccp->xmit != NULL && ccp->xmit->Compress != NULL) { /* Connect a hook from the ppp node to our socket node */ snprintf(cn.path, sizeof(cn.path), "[%x]:", b->nodeID); snprintf(cn.ourhook, sizeof(cn.ourhook), "c%d", b->id); strcpy(cn.peerhook, NG_PPP_HOOK_COMPRESS); if (NgSendMsg(gCcpCsock, ".:", NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) { Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"", b->name, ".:", cn.ourhook, cn.path, cn.peerhook); } } if (ccp->recv != NULL && ccp->recv->Decompress != NULL) { /* Connect a hook from the ppp node to our socket node */ snprintf(cn.path, sizeof(cn.path), "[%x]:", b->nodeID); snprintf(cn.ourhook, sizeof(cn.ourhook), "d%d", b->id); strcpy(cn.peerhook, NG_PPP_HOOK_DECOMPRESS); if (NgSendMsg(gCcpCsock, ".:", NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) { Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"", b->name, ".:", cn.ourhook, cn.path, cn.peerhook); } } /* Report what we're doing */ Log(LG_CCP, ("[%s] CCP: Compress using: %s (%s)", b->name, !ccp->xmit ? "none" : ccp->xmit->name, (ccp->xmit && ccp->xmit->Describe) ? (*ccp->xmit->Describe)(b, COMP_DIR_XMIT, buf, sizeof(buf)) : "")); Log(LG_CCP, ("[%s] CCP: Decompress using: %s (%s)", b->name, !ccp->recv ? "none" : ccp->recv->name, (ccp->recv && ccp->recv->Describe) ? (*ccp->recv->Describe)(b, COMP_DIR_RECV, buf, sizeof(buf)) : "")); /* Update PPP node config */ b->pppConfig.bund.enableCompression = (ccp->xmit != NULL)?ccp->xmit->mode:0; b->pppConfig.bund.enableDecompression = (ccp->recv != NULL)?ccp->recv->mode:0; NgFuncSetConfig(b); /* Update interface MTU */ BundUpdateParams(b); }
int IpcpStat(Context ctx, int ac, char *av[], void *arg) { #ifdef USE_NG_VJC char path[NG_PATHSIZ]; #endif IpcpState const ipcp = &ctx->bund->ipcp; Fsm fp = &ipcp->fsm; #ifdef USE_NG_VJC union { u_char buf[sizeof(struct ng_mesg) + sizeof(struct slcompress)]; struct ng_mesg reply; } u; struct slcompress *const sls = (struct slcompress *)(void *)u.reply.data; #endif char buf[48]; Printf("[%s] %s [%s]\r\n", Pref(fp), Fsm(fp), FsmStateName(fp->state)); Printf("Allowed IP address ranges:\r\n"); if (ipcp->conf.self_ippool[0]) { Printf("\tPeer: ippool %s\r\n", ipcp->conf.self_ippool); } else { Printf("\tSelf: %s\r\n", u_rangetoa(&ipcp->conf.self_allow,buf,sizeof(buf))); } if (ipcp->conf.ippool[0]) { Printf("\tPeer: ippool %s\r\n", ipcp->conf.ippool); } else { Printf("\tPeer: %s\r\n", u_rangetoa(&ipcp->conf.peer_allow,buf,sizeof(buf))); } Printf("IPCP Options:\r\n"); OptStat(ctx, &ipcp->conf.options, gConfList); Printf("Current addressing:\r\n"); Printf("\tSelf: %s\r\n", inet_ntoa(ipcp->want_addr)); Printf("\tPeer: %s\r\n", inet_ntoa(ipcp->peer_addr)); #ifdef USE_NG_VJC Printf("Compression:\r\n"); Printf("\tSelf: "); if (ipcp->want_comp.proto != 0) Printf("%s, %d compression channels, CID %scompressible\r\n", ProtoName(ntohs(ipcp->want_comp.proto)), ipcp->want_comp.maxchan + 1, ipcp->want_comp.compcid ? "" : "not "); else Printf("None\r\n"); Printf("\tPeer: "); if (ipcp->peer_comp.proto != 0) Printf("%s, %d compression channels, CID %scompressible\n", ProtoName(ntohs(ipcp->peer_comp.proto)), ipcp->peer_comp.maxchan + 1, ipcp->peer_comp.compcid ? "" : "not "); else Printf("None\r\n"); #endif /* USE_NG_VJC */ Printf("Server info we give to peer:\r\n"); Printf("DNS servers : %15s", inet_ntoa(ipcp->conf.peer_dns[0])); Printf(" %15s\r\n", inet_ntoa(ipcp->conf.peer_dns[1])); Printf("NBNS servers: %15s", inet_ntoa(ipcp->conf.peer_nbns[0])); Printf(" %15s\r\n", inet_ntoa(ipcp->conf.peer_nbns[1])); Printf("Server info peer gave to us:\r\n"); Printf("DNS servers : %15s", inet_ntoa(ipcp->want_dns[0])); Printf(" %15s\r\n", inet_ntoa(ipcp->want_dns[1])); Printf("NBNS servers: %15s", inet_ntoa(ipcp->want_nbns[0])); Printf(" %15s\r\n", inet_ntoa(ipcp->want_nbns[1])); #ifdef USE_NG_VJC /* Get VJC state */ snprintf(path, sizeof(path), "mpd%d-%s:%s", gPid, ctx->bund->name, NG_PPP_HOOK_VJC_IP); if (NgFuncSendQuery(path, NGM_VJC_COOKIE, NGM_VJC_GET_STATE, NULL, 0, &u.reply, sizeof(u), NULL) < 0) return(0); Printf("VJ Compression:\r\n"); Printf("\tOut comp : %d\r\n", sls->sls_compressed); Printf("\tOut total: %d\r\n", sls->sls_packets); Printf("\tMissed : %d\r\n", sls->sls_misses); Printf("\tSearched : %d\r\n", sls->sls_searches); Printf("\tIn comp : %d\r\n", sls->sls_compressedin); Printf("\tIn uncomp: %d\r\n", sls->sls_uncompressedin); Printf("\tIn error : %d\r\n", sls->sls_errorin); Printf("\tIn tossed: %d\r\n", sls->sls_tossed); #endif /* USE_NG_VJC */ return(0); }