📄 iprte.c
字号:
0xffffffffL, /* Class D */#endif }; address_bytes.long_addr = ia.s_addr; return masks[((address_bytes.byte_addr[0] >> 5) & 0x07)];}static unsigned long route_mask(struct in_addr ipaddr){ struct lif *lp; unsigned long netmask;#if defined(DEBUG) struct in_addr foo;#endif netmask = ip_net_mask(ipaddr); #if defined(DEBUG) foo.s_addr = netmask; printf("Start with %15s ", (char *)inet_ntoa(ipaddr)); printf("%15s (%08X)\n", (char *)inet_ntoa(foo), netmask); fflush(stdout);#endif for (lp = lif; lp; lp = lp->next) { read_if(lp); if (lp->ifp->if_addrlist == 0) continue; #if defined(DEBUG) foo.s_addr = ipaddr.s_addr & netmask; printf(" %15s ==? ", (char *)inet_ntoa(foo)); foo.s_addr = (((struct sockaddr_in *)(&(lp->ifp->if_addrlist->ifa_addr)))-> sin_addr.s_addr) & netmask; printf(" %15s\n", (char *)inet_ntoa(foo)); fflush(stdout);#endif if ((ipaddr.s_addr & netmask) == ( (((struct sockaddr_in *)(&(lp->ifp->if_addrlist->ifa_addr)))-> sin_addr.s_addr) & netmask) ) {#if defined(DEBUG) printf("***\n"); printf("Returning located mask %08.8X\n", lp->netmask.s_addr); fflush(stdout);#endif return (unsigned long)(lp->netmask.s_addr); } }#if defined(DEBUG) printf("Returning basic mask %08.8X\n", netmask); fflush(stdout);#endif return netmask;}static struct rte * ip_rte_lookup(struct in_addr ia){ struct rte *rtep; for (rtep = rt_list; rtep != 0; rtep = rtep->rte_next) { if (ia.s_addr == ((struct sockaddr_in *)(&rtep->rt_ent.rt_dst))-> sin_addr.s_addr) return rtep; } return 0;}void get_iproute_info(OIDC_T last_match, SNMP_PKT_T *pktp, VB_T *vbp, struct rte *rt){UINT_32_T mask;switch(last_match) { case LM_ipRouteDest: getproc_got_ip_address(pktp, vbp, ((struct sockaddr_in *)(&rt->rt_ent.rt_dst))->sin_addr.s_addr); break; case LM_ipRouteIfIndex: getproc_got_int32(pktp, vbp, get_interface_number((off_t)rt->rt_ent.rt_ifp)); break; case LM_ipRouteMetric1: case LM_ipRouteMetric2: case LM_ipRouteMetric3: case LM_ipRouteMetric4: getproc_got_int32(pktp, vbp, -1); break; case LM_ipRouteNextHop: getproc_got_ip_address(pktp, vbp, ((struct sockaddr_in *)(&rt->rt_ent.rt_gateway))->sin_addr.s_addr); break; case LM_ipRouteType: getproc_got_int32(pktp, vbp, rt->rt_ent.rt_flags & RTF_GATEWAY ? 4 : 3); break; case LM_ipRouteProto: getproc_got_int32(pktp, vbp, rt->rt_ent.rt_flags & RTF_DYNAMIC ? 4 : 2); break; case LM_ipRouteAge: getproc_got_int32(pktp, vbp, 0); break; case LM_ipRouteMask: mask = route_mask(((struct sockaddr_in *) (&rt->rt_ent.rt_dst))->sin_addr); getproc_got_ip_address(pktp, vbp, mask); break; case LM_ipRouteMetric5: getproc_got_int32(pktp, vbp, -1); break; case LM_ipRouteInfo: getproc_got_object_id(pktp, vbp, sizeof(iprte_route_info_compl)/sizeof(OIDC_T), iprte_route_info_compl, 0); break; }return;}/****************************************************************************NAME: ipRouteTable_getPURPOSE: Find the appropriate entry in the ip routing table and attach information from it to the vbp using the getproc_got_* functions. If we can't find an entry indicate that by calling getproc_nosuchins.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void ipRouteTable_get(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct in_addr ipaddr;struct rte *rt;/* Check the instance to see if it is formed properly There must be 4 unused components, and they must be a valid ip address */if ((tcount != INSTANCE_LEN) || oid_to_ip(4, tlist, &ipaddr.s_addr)) { getproc_nosuchins(pktp, vbp); return; }read_routing();#if defined(DEBUG)pr_iprte();#endifif ((rt = ip_rte_lookup(ipaddr)) == 0) { getproc_nosuchins(pktp, vbp); return; }get_iproute_info(last_match, pktp, vbp, rt);return;}/****************************************************************************NAME: ipRouteTable_setPURPOSE: Commit the sets, that were tested in the test routinePARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void ipRouteTable_set(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct in_addr ipaddr;struct rte *rt;/* We only have to do anything if the new value is "invalid" */if (vbp->value_u.v_number == 2) {#if defined(DEBUG) printf("Looking to delete route destination %d.%d.%d.%d\n", tlist[0], tlist[1], tlist[2], tlist[3]); fflush(stdout);#endif oid_to_ip(4, tlist, &ipaddr.s_addr); if ((rt = ip_rte_lookup(ipaddr)) == 0) { setproc_error(pktp, vbp, COMMIT_FAILED); return; } #if defined(DEBUG) printf("found entry\n");#endif (void) zap_route(ipaddr, rt); }setproc_good(pktp, vbp);return;}/****************************************************************************NAME: ipRouteTable_testPURPOSE: Find the appropriate entry in the ip routing table and determine if we are allowed to set the given information (the values are correct and consistent).PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void ipRouteTable_test(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct in_addr ipaddr;struct rte *rt;/* Currently the only object in the routine table we allow to be set is the type. Check the vbp's value and see if it is within range */if ((vbp->value_u.v_number != 2) && (vbp->value_u.v_number != 3)) { testproc_error(pktp, vbp, WRONG_VALUE); return; }/* Check the instance to see if it is formed properly There must be 4 unused components, and they must be a valid ip address */if ((tcount != INSTANCE_LEN) || oid_to_ip(4, tlist, &ipaddr.s_addr)) { testproc_error(pktp, vbp, NO_CREATION); return; }read_routing();if ((rt = ip_rte_lookup(ipaddr)) == 0) { testproc_error(pktp, vbp, NO_CREATION); return; }testproc_good(pktp, vbp);return;}/****************************************************************************NAME: ipRouteTable_nextPURPOSE: Locate the "next" object in the IP Routing tablePARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/void ipRouteTable_next(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct rte *rtep, *best = 0;OIDC_T bra[INSTANCE_LEN], pra[INSTANCE_LEN];int j; read_routing(); /* Now find the lowest value larger than the instance part */for (rtep = rt_list; rtep; rtep = rtep->rte_next) { ip_to_rlist(((struct sockaddr_in *) &(rtep->rt_ent.rt_dst))->sin_addr.s_addr, pra); if (oidcmp2(INSTANCE_LEN, pra, tcount, tlist) <= 0) continue; if (!best || (oidorder(pra, bra, INSTANCE_LEN) < 0)) { best = rtep; for (j = 0; j < INSTANCE_LEN; j++) bra[j] = pra[j]; } } if (best) { nextproc_next_instance(pktp, vbp, INSTANCE_LEN, bra); get_iproute_info(last_match, pktp, vbp, best); }else nextproc_no_next(pktp, vbp);return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -