?? input.c
字號:
{ /* * If the metric changed then we should change our * route. Also if this is a valid update with * metric of 15 and we have already deleted the * route from the routing database we should * revalidate the route in our table and add it * back to the system database */ if ((n->rip_metric != rt->rt_metric) || (n->rip_metric == HOPCNT_INFINITY)) { /* * If this is a repeat advertisement of an * unreachable destination, ignore it. * Ignore it also if we have already expired * this route and are being informed that it * has expired. We have acted on it once already. */ if ((origMetric == HOPCNT_INFINITY) && (rt->rt_metric == HOPCNT_INFINITY) && !rt->inKernel && (rt->rt_timer >= ripState.expire)) break; /* * If the advertised metric is (HOPCNT_INFINITY -1), * a valid metric, check to see what we should * do with it. If we already have the route * in the system table, reset the timer, * else trick rtchange() into adding the route back */ if (origMetric == (HOPCNT_INFINITY - 1)) { if (rt->inKernel) { rt->rt_timer = 0; /* Update age for IP group MIB. */ ripRouteAgeUpdate (rt); break; } else n->rip_metric++; } if (rip->rip_vers > 1) { rtchange(rt, &gateway, n->rip_metric, &netmask, tag, 0, NULL); } else { rtchange(rt, from, n->rip_metric, NULL, 0, 0, NULL); } changes++; rt->rt_timer = 0; if (origMetric == HOPCNT_INFINITY) rt->rt_timer = ripState.expire; else if (rt->inKernel) { /* Update age for IP group MIB. */ ripRouteAgeUpdate (rt); } } else if (rt->rt_metric < HOPCNT_INFINITY) { rt->rt_timer = 0; /* Update age for IP group MIB. */ if (rt->inKernel) ripRouteAgeUpdate (rt); /* * Metric is same. Check if either the next hop * or the tag changed, for a V2 packet. If it did, * we need to record the change */ if ((rip->rip_vers > 1) && ((((RIP2PKT *)n)->tag != rt->rt_tag) || (memcmp(&gateway, &(rt->rt_router), sizeof(gateway)) != 0))) { rtchange(rt, &gateway, n->rip_metric, &netmask, tag, 0, NULL); } } } else if ((unsigned) n->rip_metric < rt->rt_metric || (rt->rt_metric == n->rip_metric && rt->rt_timer > (ripState.expire/2) && (unsigned) origMetric < HOPCNT_INFINITY)) { if (rip->rip_vers > 1) { rtchange(rt, &gateway, n->rip_metric, &netmask, tag, ((struct sockaddr_in *)from)-> sin_addr.s_addr, NULL); } else { rtchange(rt, from, n->rip_metric, NULL, 0, ((struct sockaddr_in *)from)-> sin_addr.s_addr, NULL); } changes++; rt->rt_timer = 0; /* Update age for IP group MIB. */ if (rt->inKernel) ripRouteAgeUpdate (rt); } } break; default: /* * Ignore any unrecognized commands. Return from the routine * to prevent any possibility of scheduling a triggered update. */ pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } /* * This section of code schedules triggered updates whenever entries in * the routing table change. No updates are sent for silent RIP * configurations and are also suppressed if a regular update will * occur within the next MAX_WAITTIME seconds. */ if (changes && ripState.supplier && ripState.now.tv_sec - ripState.lastfullupdate.tv_sec < ripState.supplyInterval - MAX_WAITTIME) { /* * No regular update is imminent. Check the elapsed time since * the previous (regular or triggered) update and the time limit * of the "nextbcast" quiet period which restricts the update * frequency. */ if (ripState.now.tv_sec - ripState.lastbcast.tv_sec >= MIN_WAITTIME && (ripState.nextbcast.tv_sec < ripState.now.tv_sec)) { /* * All conditions have been met. Send a triggered update over the * interfaces which did not receive the RIP response. The message * sent over each interface only includes routes which changed * since the last message sent. */ if (routedDebug) logMsg ("send dynamic update\n", 0, 0, 0, 0, 0, 0); ifp->ifStat.rip2IfStatSentUpdates++; toall (supply, RTS_CHANGED, ifp); ripState.lastbcast = ripState.now; ripState.needupdate = 0; ripState.nextbcast.tv_sec = 0; } else { /* * The triggered update can't be sent because of frequency * limitations imposed to prevent excessive network traffic. * Set the delayed update indicator so that the update will * be sent when possible. */ ripState.needupdate++; } if (ripState.nextbcast.tv_sec == 0) { /* * Select the earliest possible time for the next triggered * update. A random value is used to avoid periodic network * congestion from synchronized routers. */ u_long delay = RANDOMDELAY(); ripState.nextbcast.tv_sec = delay / 1000000; ripState.nextbcast.tv_usec = delay % 100000; timevaladd (&ripState.nextbcast, &ripState.now); /* * If the earliest allowable update occurs within MIN_WAITTIME * seconds before the next regular update, force the delay past * that point to avoid a redundant triggered update. */ if (ripState.nextbcast.tv_sec > ripState.lastfullupdate.tv_sec + ripState.supplyInterval - MIN_WAITTIME) { ripState.nextbcast.tv_sec = ripState.lastfullupdate.tv_sec + ripState.supplyInterval + 1; } } } }/* * This pseudo-random number generator restricts the frequency of triggered * updates. It was plagiarized shamelessly from FreeBSD 2.1.7 where it was * used for the same purpose by routed. */LOCAL u_long ripRandTime (void) { register long x, hi, lo, t; /* * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1). * From "Random number generators: good ones are hard to find", * Park and Miller, Communications of the ACM, vol. 31, no. 10, * October 1988, p. 1195. */ x = ripRandTimeSeed; hi = x / 127773; lo = x % 127773; t = 16807 * lo - 2836 * hi; if (t <= 0) t += 0x7fffffff; ripRandTimeSeed = t; return (t); }/****************************************************************************** ripRouteAgeUpdate - update the age for the RIP route** This routine updates the age of the RIP route that is kept in the* system Routing database.* The parameter <pRtEntry> describes the RIP route that is kept in RIP's* private database.** This routine constructs a ROUTE DESCRIPTOR structure from the supplied* parameter <pRtEntry> that describes the route whose age is to be updated* and calls the routing extensions function routeAgeSet() to set the new* age. tickGet() is used to get the current tick count and is used as the* new age.** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/LOCAL void ripRouteAgeUpdate ( struct rt_entry * pRtEntry /* Route entry describing the */ /* RIP route to update */ ) { struct sockaddr_in * pDsin; struct sockaddr_in * pGsin; struct sockaddr_in * pNsin; /* * Retrieve the destination and netmask values from the * corresponding fields in the RIP route entry structure */ ripRouteToAddrs (pRtEntry, &pDsin, &pGsin, &pNsin); /* * If it is a host route, set netmask to NULL. RIP internally * assigns a host route the netmask of the interface. But the system * overrides that and stores the route as a host route with a NULL mask. * (which is the right thing to do). So we set the netmask field to * NULL so that the route lookup happens fine. */ if (pRtEntry->rt_flags & RTF_HOST) pNsin = NULL; if (routedDebug > 2) { logMsg ("ripRouteAgeUpdate: setting new age = %d for\n", tickGet (), 0, 0, 0, 0, 0); ripSockaddrPrint ((struct sockaddr *)pDsin); ripSockaddrPrint ((struct sockaddr *)pNsin); ripSockaddrPrint ((struct sockaddr *)pGsin); } /* Now set the route age */ if (routeAgeSet ((struct sockaddr *)pDsin, (struct sockaddr *)pNsin, M2_ipRouteProto_rip, tickGet ()) == ERROR) { if (routedDebug) logMsg ("Couldn't set age for rtEntry = %x.\n", (int)pRtEntry, 0, 0, 0, 0, 0); } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -