📄 arp.c
字号:
SNMP_PKT_T * SNMP packet currently being processed. VB_T * Variable being processed.RETURNS: void****************************************************************************/void arptable_test(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct in_addr ipaddr;atab_t *tab;int i;OIDC_T iface;/* Check that the oid is well formed, it must have 6 unused components, be a request for the IP protocol, the ip address must be realistic, and we need to be able to read the arp table */if ((tcount != AT_INSTANCE_LEN) || (*(tlist+AT_PROT) != 1) || (oid_to_ip(4, tlist+AT_ADDR, &ipaddr.s_addr) != 0)) { setproc_error(pktp, vbp, NO_CREATION); return; }if (read_arptab(0) == -1) { testproc_error(pktp, vbp, GEN_ERR); return; }/* Look up entry */iface = tlist[AT_INTERFACE];for (tab = atabp, i = 0; i < atab_cnt; i++, tab++) { if ((ipaddr.s_addr == tab->a_iaddr.s_addr) && (iface == tab->a_ifnum)) { testproc_good(pktp, vbp); return; } }testproc_error(pktp, vbp, NO_CREATION);return;}/****************************************************************************NAME: arptable_nextPURPOSE: Locate the "next" object in the ARP 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 arptable_next(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){atab_t *tab, *best = 0;OIDC_T bra[AT_INSTANCE_LEN], vra[AT_INSTANCE_LEN];int i, j;struct in_addr vaddr;if (read_arptab(0) == -1) { nextproc_no_next(pktp, vbp); return; }/* Now find the lowest value larger than the given one */vra[AT_PROT] = 1; /* Only IP supported by ARP. */for (tab = atabp, i = atab_cnt; i; i--, tab++) { vaddr.s_addr = tab->a_iaddr.s_addr; ip_to_rlist(vaddr.s_addr, vra+AT_ADDR); vra[AT_INTERFACE] = tab->a_ifnum; if (oidcmp2(AT_INSTANCE_LEN, vra, tcount, tlist) <= 0) continue; if (!best || (oidorder(vra, bra, AT_INSTANCE_LEN) < 0)) { best = tab; for (j = 0; j < AT_INSTANCE_LEN; j++) bra[j] = vra[j]; } }if (best) { /* dig out the information */ get_arpinfo(last_match, pktp, vbp, best); /* and create the instance information */ nextproc_next_instance(pktp, vbp, AT_INSTANCE_LEN, bra); }else { /* no next found */ nextproc_no_next(pktp, vbp); }return;}void get_n2minfo(OIDC_T last_match, SNMP_PKT_T *pktp, VB_T *vbp, atab_t *tab){switch(last_match) { case n2mIfIndex: getproc_got_int32(pktp, vbp, tab->a_ifnum); break; case n2mPhysAddress: getproc_got_string(pktp, vbp, 6, tab->a_enaddr.ether_addr_octet, 0, VT_STRING); break; case n2mNetAddress: getproc_got_ip_address(pktp, vbp, tab->a_iaddr.s_addr); break; case n2mType: /* we only allow dynamic (3) for type */ getproc_got_int32(pktp, vbp, 3); break; }}/****************************************************************************NAME: n2mtable_getPURPOSE: Find the appropriate entry in the arp 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 n2mtable_get(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct in_addr ipaddr;atab_t *tab;int i;OIDC_T iface;/* Check that the oid is well formed, it must have 5 unused components, the ip address must be realistic, and we need to be able to read the arp table */if ((tcount != N2M_INSTANCE_LEN) || (oid_to_ip(4, tlist + N2M_ADDR, &ipaddr.s_addr) != 0) || (read_arptab(0) == -1)) { getproc_nosuchins(pktp, vbp); return; }/* Look up entry and call get_n2minfo to fill in the vbp */iface = tlist[N2M_INTERFACE];for (tab = atabp, i = 0; i < atab_cnt; i++, tab++) { if ((ipaddr.s_addr == tab->a_iaddr.s_addr) && (iface == tab->a_ifnum)) { get_n2minfo(last_match, pktp, vbp, tab); return; } }/* We fall through to here if there are no entries that match the request */getproc_nosuchins(pktp, vbp);return;}/****************************************************************************NAME: n2mtable_testPURPOSE: Test whether a given object exists in the ARP 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****************************************************************************/void n2mtable_test(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct in_addr ipaddr;atab_t *tab;int i;OIDC_T iface;/* See if the value is acceptable for the type */if ((last_match == n2mType) && ((vbp->value_u.v_number != 2) && (vbp->value_u.v_number != 3))) { testproc_error(pktp, vbp, WRONG_VALUE); return; }/* Check that the oid is well formed, it must have 5 unused components, the ip address must be realistic, and we need to be able to read the arp table */if ((tcount != N2M_INSTANCE_LEN) || (oid_to_ip(4, tlist + N2M_ADDR, &ipaddr.s_addr) != 0)) { setproc_error(pktp, vbp, NO_CREATION); return; }if (read_arptab(0) == -1) { testproc_error(pktp, vbp, GEN_ERR); return; }/* Look up entry */iface = tlist[N2M_INTERFACE];for (tab = atabp, i = 0; i < atab_cnt; i++, tab++) { if ((ipaddr.s_addr == tab->a_iaddr.s_addr) && (iface == tab->a_ifnum)) { /* we are happy, return */ testproc_good(pktp, vbp); return; } }testproc_error(pktp, vbp, NO_CREATION);return;}/****************************************************************************NAME: n2mtable_nextPURPOSE: Locate the "next" object in the ARP 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 n2mtable_next(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){atab_t *tab, *best = 0;OIDC_T bra[N2M_INSTANCE_LEN], vra[N2M_INSTANCE_LEN];int i, j;struct in_addr vaddr;if (read_arptab(0) == -1) { nextproc_no_next(pktp, vbp); return; }/* Now find the lowest value larger than the given one */for (tab = atabp, i = atab_cnt; i; i--, tab++) { vaddr.s_addr = tab->a_iaddr.s_addr; ip_to_rlist(vaddr.s_addr, vra + N2M_ADDR); vra[N2M_INTERFACE] = tab->a_ifnum; if (oidcmp2(N2M_INSTANCE_LEN, vra, tcount, tlist) <= 0) continue; if (!best || (oidorder(vra, bra, N2M_INSTANCE_LEN) < 0)) { best = tab; for (j = 0; j < N2M_INSTANCE_LEN; j++) bra[j] = vra[j]; } }if (best) { /* dig out the information */ get_n2minfo(last_match, pktp, vbp, best); /* and create the instance information */ nextproc_next_instance(pktp, vbp, N2M_INSTANCE_LEN, bra); }else { /* no next found */ nextproc_no_next(pktp, vbp); }return;}/****************************************************************************NAME: set_n2mTypePURPOSE: Perform the set of the net to media type, 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 set_n2mType(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct in_addr ipaddr;/* We only have to do anything if the new value is "invalid" */if (vbp->value_u.v_number == 2) { if (oid_to_ip(4, tlist + N2M_ADDR, &ipaddr.s_addr) == 0) zap_arp(ipaddr, (int)(tlist[N2M_INTERFACE]), 0, 0); }setproc_good(pktp, vbp);}/****************************************************************************NAME: set_n2mPhysAddressPURPOSE: Perform the set of the arp addressPARAMETERS: 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 set_n2mPhysAddress(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){struct in_addr ipaddr;if (oid_to_ip(4, tlist + N2M_ADDR, &ipaddr.s_addr) == 0) zap_arp(ipaddr, (int)(tlist[N2M_INTERFACE]), (char *)EBufferStart(&vbp->value_u.v_string), EBufferUsed(&vbp->value_u.v_string));setproc_good(pktp, vbp);return;}int arp_init(){if (find_loc(&arptab_size) == 0) return -1;if (find_loc(&arptab) == 0) return -1;krnl_atab_cnt = read_int((off_t)arptab_size.offset);#ifdef DEBUGprintf("Kernel maintains %d ARP entries\n", krnl_atab_cnt);#endifkrnl_atab_bytes = krnl_atab_cnt * sizeof(struct arptab);if ((krnl_atab = (struct arptab *)malloc(krnl_atab_bytes)) == 0) return -1;if ((atabp = (atab_t *)malloc(krnl_atab_cnt * sizeof(atab_t))) == 0) { free((char *)krnl_atab); return -1; }return read_arptab(ARP_FORCE);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -