⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
                if ( ((*afp->af_checkhost)(&n->rip_dst, ifp)) == 0)                    {                    if (routedDebug)                        logMsg ("bad host in route from %s (af %d)\n",                             (int)(*afswitch[from->sa_family].af_format)(from),                                from->sa_family, 0, 0, 0, 0);                    pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                    continue;                    }                if ((n->rip_metric == 0) ||                    ((unsigned) n->rip_metric > HOPCNT_INFINITY))                    {                    if (memcmp(from, &badfrom2,                               sizeof(badfrom2)) != 0)                        {                        if (routedDebug)                            logMsg ("bad metric (%d) from %s\n", n->rip_metric,                             (int)(*afswitch[from->sa_family].af_format)(from),                                    0, 0, 0, 0);                        badfrom2 = *from;                        }                    pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                    continue;                    }                rt = rtlookup (&n->rip_dst);                /*                  * Do not allow a route learnt from other protocols to be                 * replaced                 */                if (rt && ((rt->rt_state & RTS_OTHER) != 0))                    continue;                                if (rt == 0 ||                    (rt->rt_state & (RTS_INTERNAL|RTS_INTERFACE)) ==                    (RTS_INTERNAL|RTS_INTERFACE))                    {                    /*                     * If we're hearing a logical network route                     * back from a peer to which we sent it,                     * ignore it.                     */                    if (rt && rt->rt_state & RTS_SUBNET &&                        (*afp->af_sendroute)(rt, from, ifp))                        {                        pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                        continue;                        }                    /*                     * Adjust metric according to incoming interface.                     */                    if ((unsigned)n->rip_metric < HOPCNT_INFINITY)                        {                        /*                         * Look for an equivalent route that                         * includes this one before adding                         * this route.                         */                        rt = rtfind(&n->rip_dst);                        if ((rt && equal(from, &rt->rt_router)) &&                            (rt->rt_metric <= n->rip_metric))                            continue;                        n->rip_metric += ifp->int_metric;                        if (rip->rip_vers < 2)                            {                            rtadd (&n->rip_dst, from, n->rip_metric,                                    0, NULL, M2_ipRouteProto_rip, 0,                                   ((struct sockaddr_in *)from)->                                    sin_addr.s_addr, pErrorIfp);                            }                        else                            {                            ripSplitPacket (ifp, (struct sockaddr_in *)from,                                             &n->rip_dst, &gateway, &netmask,                                            &tag);                            /*                             * RFC 1723, Section 3.4: check to see that the                              * gateway is directly reachable. If not, treat                              * that value as 0.0.0.0 by using the originator                              * as the gateway.                             */                            if ((((struct sockaddr_in *)&gateway)->                                 sin_addr.s_addr &                                  htonl (ifp->int_subnetmask)) !=                                 (((struct sockaddr_in *)&ifp->int_addr)->                                 sin_addr.s_addr &                                  htonl (ifp->int_subnetmask)))                                {                                ((struct sockaddr_in *)&gateway)->                                    sin_addr.s_addr =                                     ((struct sockaddr_in *)from)->                                    sin_addr.s_addr;                                }                            rtadd(&n->rip_dst, &gateway, n->rip_metric, 0,                                  &netmask, M2_ipRouteProto_rip, tag,                                  ((struct sockaddr_in *)from)->                                  sin_addr.s_addr, pErrorIfp);                            }                        changes++;                        }                    continue;                    }                /*                 * Update if from gateway and different,                 * shorter, or equivalent but old route                 * is getting stale.                 */                /*                 * If this was a pre-existinng route then we can                 * update it to be "infinite" and should.                 * ANVL 7.13.                 */                origMetric = n->rip_metric;                if ((unsigned) n->rip_metric < HOPCNT_INFINITY)                    n->rip_metric += ifp->int_metric;                if (n->rip_metric > HOPCNT_INFINITY)                    {                    pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                    continue;                    }                if (rip->rip_vers > 1)                    {                    ripSplitPacket(ifp, (struct sockaddr_in *)from,                                    &n->rip_dst, &gateway, &netmask,                                   &tag);                    if (((struct sockaddr_in *)&netmask)->                        sin_addr.s_addr == -1)                        {                        pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                        continue;                        }                    /*                     * RFC 1723, Section 3.4: check to see that the                      * gateway is directly reachable. If not, treat                      * that value as 0.0.0.0 by using the originator                      * as the gateway.                     */                    if ((((struct sockaddr_in *)&gateway)->sin_addr.s_addr &                          htonl (ifp->int_subnetmask)) !=                         (((struct sockaddr_in *)&ifp->int_addr)->                         sin_addr.s_addr & htonl (ifp->int_subnetmask)))                        {                        ((struct sockaddr_in *)&gateway)->sin_addr.s_addr =                             ((struct sockaddr_in *)from)->sin_addr.s_addr;                        }                    }                /*                 * We are making an assumption here that the address                 * is an internet address (4 bytes long). Since we currently                 * support only the AF_INET family its OK, but if that                 * changes, the following check will need to be changed                 * accordingly                 */                if (((struct sockaddr_in *)from)->sin_addr.s_addr ==                    rt->rt_orgrouter)                    {                    /*                      * 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))                             continue;			/*			 * If the advertised metric is (HOPCNT_INFINITY -1),			 * a valid metric, call rtchange() to update the                         * metric, and if needed to add the route back.                         * Bump up the metric past HOPCNT_INFINITY so that                         * rtchange doesn't treat this as a delete request.                         * rtchange will decrement it later on.			 */			if (origMetric == (HOPCNT_INFINITY - 1))                            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;          }    /*      * Send a triggered update if a route changed and RIP has been configured     * in supplier mode.      */    if ((changes > 0) && ripState.supplier)	ripTriggeredUpdateSend (ifp);    }/****************************************************************************** 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 + -