2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 * Author: Harti Brandt <harti@freebsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $Begemot: bsnmp/snmp_mibII/mibII_nettomedia.c,v 1.8 2004/08/06 08:47:03 brandt Exp $
31 * Read-only implementation of the Arp table (ipNetToMediaTable)
33 * The problem with the table is, that we don't receive routing message
34 * when a) an arp table entry is resolved and b) when an arp table entry is
35 * deleted automatically. Therefor we need to poll the table from time to
39 #include "mibII_oid.h"
44 mib_find_arp(const struct mibif *ifp, struct in_addr in)
47 uint32_t a = ntohl(in.s_addr);
49 if (get_ticks() >= mibarpticks + ARPREFRESH)
52 TAILQ_FOREACH(at, &mibarp_list, link)
53 if (at->index.subs[0] == ifp->index &&
54 (at->index.subs[1] == ((a >> 24) & 0xff)) &&
55 (at->index.subs[2] == ((a >> 16) & 0xff)) &&
56 (at->index.subs[3] == ((a >> 8) & 0xff)) &&
57 (at->index.subs[4] == ((a >> 0) & 0xff)))
63 mib_arp_create(const struct mibif *ifp, struct in_addr in, const u_char *phys,
67 uint32_t a = ntohl(in.s_addr);
69 if ((at = malloc(sizeof(*at))) == NULL)
74 at->index.subs[0] = ifp->index;
75 at->index.subs[1] = (a >> 24) & 0xff;
76 at->index.subs[2] = (a >> 16) & 0xff;
77 at->index.subs[3] = (a >> 8) & 0xff;
78 at->index.subs[4] = (a >> 0) & 0xff;
79 if ((at->physlen = physlen) > sizeof(at->phys))
80 at->physlen = sizeof(at->phys);
81 memcpy(at->phys, phys, at->physlen);
83 INSERT_OBJECT_OID(at, &mibarp_list);
89 mib_arp_delete(struct mibarp *at)
91 TAILQ_REMOVE(&mibarp_list, at, link);
96 op_nettomedia(struct snmp_context *ctx __unused, struct snmp_value *value,
97 u_int sub, u_int iidx __unused, enum snmp_op op)
103 if (get_ticks() >= mibarpticks + ARPREFRESH)
108 case SNMP_OP_GETNEXT:
109 if ((at = NEXT_OBJECT_OID(&mibarp_list, &value->var, sub)) == NULL)
110 return (SNMP_ERR_NOSUCHNAME);
111 index_append(&value->var, sub, &at->index);
115 if ((at = FIND_OBJECT_OID(&mibarp_list, &value->var, sub)) == NULL)
116 return (SNMP_ERR_NOSUCHNAME);
120 if ((at = FIND_OBJECT_OID(&mibarp_list, &value->var, sub)) == NULL)
121 return (SNMP_ERR_NO_CREATION);
122 return (SNMP_ERR_NOT_WRITEABLE);
124 case SNMP_OP_ROLLBACK:
129 switch (value->var.subs[sub - 1]) {
131 case LEAF_ipNetToMediaIfIndex:
132 value->v.integer = at->index.subs[0];
135 case LEAF_ipNetToMediaPhysAddress:
136 return (string_get(value, at->phys, at->physlen));
138 case LEAF_ipNetToMediaNetAddress:
139 value->v.ipaddress[0] = at->index.subs[1];
140 value->v.ipaddress[1] = at->index.subs[2];
141 value->v.ipaddress[2] = at->index.subs[3];
142 value->v.ipaddress[3] = at->index.subs[4];
145 case LEAF_ipNetToMediaType:
146 value->v.integer = (at->flags & MIBARP_PERM) ? 4 : 3;
149 return (SNMP_ERR_NOERROR);