📄 if.c
字号:
get_ifNumber(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){/* test that we have an instance with a single oid which is equal to 0 */if ((tcount != 1) || (*tlist != 0)) getproc_nosuchins(pktp, vbp);else getproc_got_int32(pktp, vbp, (INT_32_T)ifnumber);return;}void get_iftable_info(OIDC_T last_match, SNMP_PKT_T *pktp, VB_T *vbp, struct lif *lifp, OIDC_T indx){static OIDC_T none[] = {0, 0};read_if(lifp);switch (last_match) { case LM_ifIndex: getproc_got_int32(pktp, vbp, (INT_32_T)indx); break; case LM_ifDescr: getproc_got_string(pktp, vbp, strlen(lifp->name), (OCTET_T *)lifp->name, 0, VT_STRING); break; case LM_ifType: getproc_got_int32(pktp, vbp, lifp->type); break; case LM_ifMTU: getproc_got_int32(pktp, vbp, lifp->ifp->if_mtu); break; case LM_ifSpeed: getproc_got_uint32(pktp, vbp, lifp->speed, VT_GAUGE); break; case LM_ifPhysAddress: if (lifp->flags & LIF_HAS_PHYSADDR) getproc_got_string(pktp, vbp, sizeof(struct ether_addr), (OCTET_T *)&(lifp->ac_enaddr), 0, VT_STRING); else getproc_got_string(pktp, vbp, 0, 0, 0, VT_STRING); break; case LM_ifAdminStatus: getproc_got_int32(pktp, vbp, lifp->status); break; case LM_ifOperStatus: getproc_got_int32(pktp, vbp, (lifp->ifp->if_flags & IFF_UP ? 1 : 2)); break; case LM_ifLastChange: /* The OS doesn't keep track of when interface states change. The best we can do is to track when SNMP change the state. */ getproc_got_uint32(pktp, vbp, lifp->change_time, VT_TIMETICKS); break; case LM_ifInOctets: case LM_ifInNUcastPkts: case LM_ifInDiscards: case LM_ifInUnknownProtos: case LM_ifOutOctets: case LM_ifOutNUcastPkts: case LM_ifOutDiscards: getproc_got_uint32(pktp, vbp, 0, VT_COUNTER); break; case LM_ifInUcastPkts: getproc_got_uint32(pktp, vbp, lifp->ifp->if_ipackets, VT_COUNTER); break; case LM_ifInErrors: getproc_got_uint32(pktp, vbp, lifp->ifp->if_ierrors, VT_COUNTER); break; case LM_ifOutUcastPkts: getproc_got_uint32(pktp, vbp, lifp->ifp->if_opackets, VT_COUNTER); break; case LM_ifOutErrors: getproc_got_uint32(pktp, vbp, lifp->ifp->if_oerrors + lifp->ifp->if_collisions, VT_COUNTER); break; case LM_ifOutQLen: getproc_got_uint32(pktp, vbp, lifp->ifp->if_snd.ifq_len, VT_GAUGE); break; case LM_ifSpecific: getproc_got_object_id(pktp, vbp, sizeof(none)/sizeof(OIDC_T), none, 0); break; }return;}/****************************************************************************NAME: iftable_getPURPOSE: Find the appropriate entry in the if 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 iftable_get(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct lif *lifp;int i;/* Test the instance information to see if it is well formed, there must be exactly 1 unused component and which must be between 1 and ifnumber (inclusive) */if ((tcount != 1) || (tlist[0] < 1) || (tlist[0] > ifnumber)) { getproc_nosuchins(pktp, vbp); return; }for (lifp = lif, i = (int)tlist[0]; lifp && --i; lifp = lifp->next) ;if (lifp == 0) { getproc_nosuchins(pktp, vbp); return; }get_iftable_info(last_match, pktp, vbp, lifp, tlist[0]);return;}/****************************************************************************NAME: iftable_nextPURPOSE: Find the appropriate entry in the if 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 iftable_next(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct lif *lifp;int i;OIDC_T indx;if (tcount == 0) indx = 1;else if (tlist[0] < ifnumber) indx = tlist[0] + 1;else { nextproc_no_next(pktp, vbp); return; }for (lifp = lif, i = (int)indx; lifp && --i; lifp = lifp->next) ;if (lifp == 0) { nextproc_error(pktp, vbp, GEN_ERR); return; }get_iftable_info(last_match, pktp, vbp, lifp, indx);nextproc_next_instance(pktp, vbp, 1, &indx);return;}/****************************************************************************NAME: iftable_setPURPOSE: Perform the set of the if table (if admin status is the only settable object).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 iftable_set(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct lif *lifp;int i;struct ifreq if_req;struct timeval now_is;unsigned long tticks_now;for (lifp = lif, i = tlist[0]; lifp && --i; lifp = lifp->next) ;/* This shouldn't happen because the interface was checked by the test function already. */if (lifp == 0) { setproc_error(pktp, vbp, COMMIT_FAILED); return; }(void)strncpy(if_req.ifr_name, lifp->name, IFNAMSIZ);(void)ioctl(snmp_socket, SIOCGIFFLAGS, &if_req);(void) gettimeofday(&now_is, 0);tticks_now = (unsigned long)(((now_is.tv_sec - boot_at.tv_sec) * 100) + (now_is.tv_usec / 10000));switch(vbp->value_u.v_number) { case 1: /* Turn interface on */ lifp->ifp->if_flags |= IFF_UP; invalidate_ifcache_entry(lifp); if (if_req.ifr_flags & IFF_UP) break; /* Already up */ if_req.ifr_flags |= IFF_UP; lifp->change_time = tticks_now; (void)ioctl(snmp_socket, SIOCSIFFLAGS, &if_req); break; case 2: /* Turn interface off */ case 3: /* Turn interface to "test mode" */ lifp->ifp->if_flags &= ~IFF_UP; invalidate_ifcache_entry(lifp); if (!(if_req.ifr_flags & IFF_UP)) break; /* Already down */ if_req.ifr_flags &= ~IFF_UP; lifp->change_time = tticks_now; (void)ioctl(snmp_socket, SIOCSIFFLAGS, &if_req); break; }/* mark the vbp as having successfully completed */setproc_good(pktp, vbp);return;}/****************************************************************************NAME: iftable_testPURPOSE: Test if the if object is settable.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 iftable_test(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){if ((vbp->value_u.v_number < 1) || (vbp->value_u.v_number > 3)) { testproc_error(pktp, vbp, WRONG_VALUE); return; }/* Test the instance information to see if it is well formed, there must be exactly 1 unused component and which must be between 1 and if number (inclusive) */if ((tcount != 1) || (tlist[0] < 1) || (tlist[0] > ifnumber)) { testproc_error(pktp, vbp, NO_CREATION); return; }testproc_good(pktp, vbp);return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -