static void ipv6cp_DecodeConfig(struct fsm *fp, u_char *cp, u_char *end, int mode_type, struct fsm_decode *dec) { /* Deal with incoming PROTO_IPV6CP */ struct ipv6cp *ipv6cp = fsm2ipv6cp(fp); int n; char tbuff[100]; u_char ifid[IPV6CP_IFIDLEN], zero[IPV6CP_IFIDLEN]; struct fsm_opt *opt; memset(zero, 0, IPV6CP_IFIDLEN); while (end - cp >= (int)sizeof(opt->hdr)) { if ((opt = fsm_readopt(&cp)) == NULL) break; snprintf(tbuff, sizeof tbuff, " %s[%d]", protoname(opt->hdr.id), opt->hdr.len); switch (opt->hdr.id) { case TY_TOKEN: memcpy(ifid, opt->data, IPV6CP_IFIDLEN); log_Printf(LogIPV6CP, "%s 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", tbuff, ifid[0], ifid[1], ifid[2], ifid[3], ifid[4], ifid[5], ifid[6], ifid[7]); switch (mode_type) { case MODE_REQ: ipv6cp->peer_tokenreq = 1; ipv6cp_ValidateInterfaceID(ipv6cp, ifid, dec); break; case MODE_NAK: if (memcmp(ifid, zero, IPV6CP_IFIDLEN) == 0) { log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE, "0x0000000000000000: Unacceptable IntefaceID!\n"); fsm_Close(&ipv6cp->fsm); } else if (memcmp(ifid, ipv6cp->his_ifid, IPV6CP_IFIDLEN) == 0) { log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE, "0x%02x%02x%02x%02x%02x%02x%02x%02x: " "Unacceptable IntefaceID!\n", ifid[0], ifid[1], ifid[2], ifid[3], ifid[4], ifid[5], ifid[6], ifid[7]); } else if (memcmp(ifid, ipv6cp->my_ifid, IPV6CP_IFIDLEN) != 0) { n = 100; while (n && !ipcp_SetIPv6address(ipv6cp, ifid, ipv6cp->his_ifid)) { do { n--; SetInterfaceID(ifid, 1); } while (n && memcmp(ifid, ipv6cp->his_ifid, IPV6CP_IFIDLEN) == 0); } if (n == 0) { log_Printf(log_IsKept(LogIPV6CP) ? LogIPV6CP : LogPHASE, "0x0000000000000000: Unacceptable IntefaceID!\n"); fsm_Close(&ipv6cp->fsm); } else { log_Printf(LogIPV6CP, "%s changing IntefaceID: " "0x%02x%02x%02x%02x%02x%02x%02x%02x " "--> 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", tbuff, ipv6cp->my_ifid[0], ipv6cp->my_ifid[1], ipv6cp->my_ifid[2], ipv6cp->my_ifid[3], ipv6cp->my_ifid[4], ipv6cp->my_ifid[5], ipv6cp->my_ifid[6], ipv6cp->my_ifid[7], ifid[0], ifid[1], ifid[2], ifid[3], ifid[4], ifid[5], ifid[6], ifid[7]); memcpy(ipv6cp->my_ifid, ifid, IPV6CP_IFIDLEN); bundle_AdjustFilters(fp->bundle, &ipv6cp->myaddr, NULL); } } break; case MODE_REJ: ipv6cp->his_reject |= (1 << opt->hdr.id); break; } break; default: if (mode_type != MODE_NOP) { ipv6cp->my_reject |= (1 << opt->hdr.id); fsm_rej(dec, opt); } break; } } if (mode_type != MODE_NOP) { if (mode_type == MODE_REQ && !ipv6cp->peer_tokenreq) { if (dec->rejend == dec->rej && dec->nakend == dec->nak) { /* * Pretend the peer has requested a TOKEN. * We do this to ensure that we only send one NAK if the only * reason for the NAK is because the peer isn't sending a * TY_TOKEN REQ. This stops us from repeatedly trying to tell * the peer that we have to have an IP address on their end. */ ipv6cp->peer_tokenreq = 1; } memset(ifid, 0, IPV6CP_IFIDLEN); ipv6cp_ValidateInterfaceID(ipv6cp, ifid, dec); } fsm_opt_normalise(dec); } }
static void CcpDecodeConfig(struct fsm *fp, u_char *cp, u_char *end, int mode_type, struct fsm_decode *dec) { /* Deal with incoming data */ struct ccp *ccp = fsm2ccp(fp); int f; const char *disp; struct fsm_opt *opt; if (mode_type == MODE_REQ) ccp->in.algorithm = -1; /* In case we've received two REQs in a row */ while (end >= cp + sizeof(opt->hdr)) { if ((opt = fsm_readopt(&cp)) == NULL) break; for (f = NALGORITHMS-1; f > -1; f--) if (algorithm[f]->id == opt->hdr.id) break; disp = f == -1 ? "" : (*algorithm[f]->Disp)(opt); if (disp == NULL) disp = ""; log_Printf(LogCCP, " %s[%d] %s\n", protoname(opt->hdr.id), opt->hdr.len, disp); if (f == -1) { /* Don't understand that :-( */ if (mode_type == MODE_REQ) { ccp->my_reject |= (1 << opt->hdr.id); fsm_rej(dec, opt); } } else { struct ccp_opt *o; switch (mode_type) { case MODE_REQ: if (IsAccepted(ccp->cfg.neg[algorithm[f]->Neg]) && (*algorithm[f]->Usable)(fp) && ccp->in.algorithm == -1) { memcpy(&ccp->in.opt, opt, opt->hdr.len); switch ((*algorithm[f]->i.Set)(fp->bundle, &ccp->in.opt, &ccp->cfg)) { case MODE_REJ: fsm_rej(dec, &ccp->in.opt); break; case MODE_NAK: fsm_nak(dec, &ccp->in.opt); break; case MODE_ACK: fsm_ack(dec, &ccp->in.opt); ccp->his_proto = opt->hdr.id; ccp->in.algorithm = (int)f; /* This one'll do :-) */ break; } } else { fsm_rej(dec, opt); } break; case MODE_NAK: for (o = ccp->out.opt; o != NULL; o = o->next) if (o->val.hdr.id == opt->hdr.id) break; if (o == NULL) log_Printf(LogCCP, "%s: Warning: Ignoring peer NAK of unsent" " option\n", fp->link->name); else { memcpy(&o->val, opt, opt->hdr.len); if ((*algorithm[f]->o.Set)(fp->bundle, &o->val, &ccp->cfg) == MODE_ACK) ccp->my_proto = algorithm[f]->id; else { ccp->his_reject |= (1 << opt->hdr.id); ccp->my_proto = -1; if (algorithm[f]->Required(fp)) { log_Printf(LogWARN, "%s: Cannot understand peers (required)" " %s negotiation\n", fp->link->name, protoname(algorithm[f]->id)); fsm_Close(&fp->link->lcp.fsm); } } } break; case MODE_REJ: ccp->his_reject |= (1 << opt->hdr.id); ccp->my_proto = -1; if (algorithm[f]->Required(fp)) { log_Printf(LogWARN, "%s: Peer rejected (required) %s negotiation\n", fp->link->name, protoname(algorithm[f]->id)); fsm_Close(&fp->link->lcp.fsm); } break; } } } if (mode_type != MODE_NOP) { fsm_opt_normalise(dec); if (dec->rejend != dec->rej || dec->nakend != dec->nak) { if (ccp->in.state == NULL) { ccp->his_proto = -1; ccp->in.algorithm = -1; } } } }