+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <err.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <netpacket/packet.h>
-#include <net/if.h>
-#include <net/ethernet.h>
-#include <arpa/inet.h>
-
-#include "../lldp.h"
-
-#define IF "lan"
-#define LLDPMAC {0x01,0x80,0xC2,0x00,0x00,0x0E}
-#define MTU 1500
-
-int set_multi(int add) {
- int s;
- struct ifreq ifr;
- const char lldpaddr[] = LLDPMAC;
-
- if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- return -1;
- bzero(&ifr, sizeof(ifr));
- strncpy(ifr.ifr_name, IF, IFNAMSIZ);
- bcopy(lldpaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
- if (ioctl(s, add ? SIOCADDMULTI : SIOCDELMULTI, &ifr) < 0)
- return -1;
- return 0;
-}
-
-void dump(const char *frame, int s) {
- int i = 0;
- while (s != i) {
- printf("%02hhx ", frame[i++]);
- if (i % 20 == 0)
- printf("\n");
- }
- printf("\n");
-}
-
-int check_mac(const char *frame, int s) {
- const char lldpaddr[] = LLDPMAC;
- if (s < sizeof(lldpaddr))
- return -1;
- if (memcmp(frame, lldpaddr, sizeof(lldpaddr)) == 0) {
- return 1;
- }
- return -1;
-}
-
-int check_protocol(const char *frame, int s) {
- const char proto[] = { 0x88, 0xcc };
- if (s < 2 * ETH_ALEN + 2)
- return -1;
- if (memcmp(frame + 2 * ETH_ALEN, proto, sizeof(proto)) == 0) {
- return 1;
- }
- return -1;
-}
-
-int check_tlv_end(const char *frame, int s) {
- if (s != 0) {
- warnx("End of LLDPDU is too large (%d > 0)", s);
- return -1;
- }
- return 0;
-}
-
-int check_tlv_chassisid(const char *frame, int s) {
- u_int8_t subtype;
- if (s < 2) {
- warnx("Chassis ID TLV too small (%d < 2)", s);
- return -1;
- }
- subtype = *(u_int8_t*)frame;
- switch (subtype) {
- case LLDP_CHASSISID_SUBTYPE_CHASSIS:
- case LLDP_CHASSISID_SUBTYPE_IFALIAS:
- case LLDP_CHASSISID_SUBTYPE_PORT:
- case LLDP_CHASSISID_SUBTYPE_ADDR:
- case LLDP_CHASSISID_SUBTYPE_IFNAME:
- case LLDP_CHASSISID_SUBTYPE_LOCAL:
- printf("Unhandled chassis ID type (%x)\n", subtype);
- break;
- case LLDP_CHASSISID_SUBTYPE_LLADDR:
- if (s != 7) {
- warnx("Incorrect MAC address size (%d != 6)", s-1);
- return -1;
- }
- printf("Chassis mac address:\n %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
- *(char *)(frame + 1),
- *(char *)(frame + 2),
- *(char *)(frame + 3),
- *(char *)(frame + 4),
- *(char *)(frame + 5),
- *(char *)(frame + 6));
- break;
- default:
- warnx("Unknown Chassis ID subtype (%x)", subtype);
- }
- return 0;
-}
-
-int check_tlv_portid(const char *frame, int s) {
- u_int8_t subtype;
- if (s < 2) {
- warnx("Port ID TLV too small (%d < 2)", s);
- return -1;
- }
- subtype = *(u_int8_t*)frame;
- switch (subtype) {
- case LLDP_PORTID_SUBTYPE_IFALIAS:
- case LLDP_PORTID_SUBTYPE_PORT:
- case LLDP_PORTID_SUBTYPE_ADDR:
- case LLDP_PORTID_SUBTYPE_IFNAME:
- case LLDP_PORTID_SUBTYPE_LOCAL:
- printf("Unhandled Port ID type (%x)\n", subtype);
- break;
- case LLDP_PORTID_SUBTYPE_LLADDR:
- if (s != 7) {
- warnx("Incorrect MAC address size (%d != 6)", s-1);
- return -1;
- }
- printf("Port mac address:\n %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
- *(char *)(frame + 1),
- *(char *)(frame + 2),
- *(char *)(frame + 3),
- *(char *)(frame + 4),
- *(char *)(frame + 5),
- *(char *)(frame + 6));
- break;
- default:
- warnx("Unknown Port ID subtype (%x)", subtype);
- }
- return 0;
-}
-
-int check_tlv_ttl(const char *frame, int s) {
- if (s != 2) {
- warnx("Incorrect TTL length (%d != 2)", s);
- return -1;
- }
- printf("TTL:\n %d\n", ntohs(*(u_int16_t*)frame));
- return 0;
-}
-
-int check_tlv_simplestring(const char *frame, int s, char *what) {
- char *desc;
- if (s < 1) {
- warnx("Incorrect %s length (%d < 1)", what, s);
- return -1;
- }
- if (!(desc = (char *)malloc(s+1))) {
- warnx("Not able to allocate memory");
- return -1;
- }
- strncpy(desc, frame, s);
- desc[s] = 0;
- printf("%s:\n %s\n", what, desc);
- free(desc);
- return 0;
-}
-
-int check_tlv_portdescr(const char *frame, int s) {
- return check_tlv_simplestring(frame, s, "Port description");
-}
-
-int check_tlv_systemname(const char *frame, int s) {
- return check_tlv_simplestring(frame, s, "System name");
-}
-
-int check_tlv_systemdescr(const char *frame, int s) {
- return check_tlv_simplestring(frame, s, "System description");
-}
-
-int check_tlv_systemcap(const char *frame, int s) {
- if (s != 4) {
- warnx("Incorrect system capabilities length (%d != 4)", s);
- return -1;
- }
- printf("System capabilities (available/enabled):\n %x %x\n",
- ntohs(*(u_int16_t*)frame),
- ntohs(*(u_int16_t*)(frame+2)));
- return 0;
-}
-
-int check_tlv_manaddr(const char *frame, int s) {
- return 0;
-}
-
-int check_tlv_dot1(const char *frame, int s) {
- int subtype;
- int l;
- char *vlanname;
- if (s < 1) {
- warnx("DOT1 frame too short (%d < 1)", s);
- return -1;
- }
- subtype = *(u_int8_t*)frame;
- switch (subtype) {
- case LLDP_TLV_DOT1_PPVID:
- case LLDP_TLV_DOT1_PI:
- warnx("Unhandled dot1 subtype");
- break;
- case LLDP_TLV_DOT1_PVID:
- if (s < 3) {
- warnx("DOT1 PVID frame too short (%d < 3)", s);
- return -1;
- }
- printf("PVID:\n %d\n", ntohs(*(u_int16_t*)(frame + 1)));
- break;
- case LLDP_TLV_DOT1_VLANNAME:
- if (s < 4) {
- warnx("DOT1 VLAN name frame too short (%d < 4)", s);
- return -1;
- }
- l = *(u_int8_t*)(frame + 3);
- if (s < 4 + l) {
- warnx("DOT1 VLAN name frame too short (%d < 4 + %d)", s, l);
- return -1;
- }
- vlanname = (char *)malloc(l + 1);
- strncpy(vlanname, frame+4, l);
- vlanname[l] = 0;
- printf("VLAN name/id:\n %s/%d\n", vlanname, ntohs(*(u_int16_t*)(frame + 1)));
- break;
- default:
- warnx("Unknown dot1 subtype (%d)", subtype);
- return -1;
- }
- return 0;
-}
-
-int check_tlv_dot3(const char *frame, int s) {
- warnx("Do nothing for dot3");
- return 0;
-}
-
-int check_tlv_org(const char *frame, int s) {
- char dot1[] = LLDP_TLV_ORG_DOT1;
- char dot3[] = LLDP_TLV_ORG_DOT3;
- if (s < 3) {
- warnx("Frame too short (3)");
- return -1;
- }
- if (memcmp(dot1, frame, 3) == 0)
- return check_tlv_dot1(frame + 3, s - 3);
- if (memcmp(dot3, frame, 3) == 0)
- return check_tlv_dot3(frame + 3, s - 3);
-
- warnx("Unknown org code");
- return -1;
-}
-
-int check_tlv(const char *frame, int offset, int s) {
- int (*sub_tlv[])(const char *frame, int s) = {
- check_tlv_end,
- check_tlv_chassisid,
- check_tlv_portid,
- check_tlv_ttl,
- check_tlv_portdescr,
- check_tlv_systemname,
- check_tlv_systemdescr,
- check_tlv_systemcap,
- check_tlv_manaddr,
- NULL };
- int size;
- int type;
- int i = 0;
- int rc = 0;
-
- if (offset + 2 > s) {
- warnx("Frame too short (1)");
- return -1;
- }
- size = ntohs(*(u_int16_t*)(frame + offset)) & 0x1ff;
- type = ntohs(*(u_int16_t*)(frame + offset)) >> 9;
- if (offset + size > s) {
- warnx("Frame too short (2)");
- return -1;
- }
-
- switch (type) {
- case LLDP_TLV_ORG:
- rc = check_tlv_org(frame + offset + 2, size);
- break;
- default:
- while (sub_tlv[i] != NULL) {
- if (type == i) {
- rc = (*sub_tlv[i])(frame + offset + 2, size);
- break;
- } else i++;
- }
- if (sub_tlv[i] == NULL) {
- warnx("Unknown TLV type (%x)", type);
- return -1;
- }
- }
-
- if (rc < 0)
- return rc;
- return offset + size + 2;
-}
-
-int main() {
- int s, l, i;
- struct sockaddr_ll sa;
- char frame[MTU];
-
- if (set_multi(1) < 0)
- err(1, "Unable to set multicast address");
-
- if ((s = socket(PF_PACKET, SOCK_RAW, htons(0x88cc))) < 0) {
- warn("Unable to create socket");
- goto end;
- }
-
- bzero(&sa, sizeof(sa));
- sa.sll_family = AF_PACKET;
- sa.sll_protocol = 0;
- sa.sll_ifindex = if_nametoindex(IF);
- if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0) {
- warn("Unable to bind");
- goto end;
- }
-
- while (1) {
- l = recv(s, frame, MTU, 0);
- dump(frame, l);
- if (check_mac(frame, l) < 0) {
- warnx("Not LLDP MAC address");
- continue;
- }
- if (check_protocol(frame, l) < 0) {
- warnx("Not LLDP protocol");
- continue;
- }
- i = 2 * ETH_ALEN + 2;
- while (i < l) {
- i = check_tlv(frame, i, l);
- if (i < 0)
- break;
- }
- }
-
-
- end:
- if (set_multi(0) < 0)
- err(1, "Unable to unset multicast address");
-
- return 0;
-}
+++ /dev/null
-/* gcc -Wall $(net-snmp-config --base-cflags) test-snmp.c $(net-snmp-config --agent-libs) -o test-snmp */
-
-#include <sys/queue.h>
-
-#define USING_AGENTX_SUBAGENT_MODULE 1
-
-#include <net-snmp/net-snmp-config.h>
-#include <net-snmp/net-snmp-includes.h>
-#include <net-snmp/agent/net-snmp-agent-includes.h>
-#include <net-snmp/agent/snmp_vars.h>
-
-#include "../lldp.h"
-
-typedef struct lldpGlobal {
- int32_t messageTxInterval;
- int32_t messageTxHoldMultiplier;
- int32_t reinitDelay;
- int32_t txDelay;
- int32_t notificationInterval;
-} lldpGlobal;
-
-struct lldpGlobal global = {
- .messageTxInterval = 30,
- .messageTxHoldMultiplier = 4,
- .reinitDelay = 2,
- .txDelay = 5,
- .notificationInterval = 5
-};
-
-oid messageTxInterval_oid[] = {1, 0, 8802, 1, 1, 2, 1, 1, 1, 0};
-oid messageTxHoldMultiplier_oid[] = {1, 0, 8802, 1, 1, 2, 1, 1, 2, 0};
-oid reinitDelay_oid[] = {1, 0, 8802, 1, 1, 2, 1, 1, 3, 0};
-oid txDelay_oid[] = {1, 0, 8802, 1, 1, 2, 1, 1, 4, 0};
-oid notificationInterval_oid[] = {1, 0, 8802, 1, 1, 2, 1, 1, 5, 0};
-
-typedef struct lldpStats {
- u_int32_t lastChangeTime;
- u_int32_t inserts;
- u_int32_t deletes;
- u_int32_t drops;
- u_int32_t ageouts;
-} lldpStats;
-
-struct lldpStats stats = {
- .lastChangeTime = 4575120,
- .inserts = 1451,
- .deletes = 12,
- .drops = 0,
- .ageouts = 2
-};
-
-oid lastChangeTime_oid[] = {1, 0, 8802, 1, 1, 2, 1, 2, 1, 0};
-oid inserts_oid[] = {1, 0, 8802, 1, 1, 2, 1, 2, 2, 0};
-oid deletes_oid[] = {1, 0, 8802, 1, 1, 2, 1, 2, 3, 0};
-oid drops_oid[] = {1, 0, 8802, 1, 1, 2, 1, 2, 4, 0};
-oid ageouts_oid[] = {1, 0, 8802, 1, 1, 2, 1, 2, 5, 0};
-
-typedef struct lldpChassis {
- int chassisIdSubtype;
- u_int8_t chassisId[256];
- int chassisId_len;
- char sysName[256];
- char sysDesc[256];
- u_int8_t sysCapSupported;
- u_int8_t sysCapEnabled;
-} lldpChassis;
-
-struct lldpChassis local = {
- .chassisIdSubtype = LLDP_CHASSISID_SUBTYPE_LLADDR,
- .chassisId = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
- .chassisId_len = 6,
- .sysName = "neo.luffy.cx",
- .sysDesc = "Linux neo 2.6.25-2-amd64 #1 SMP Thu Jun 12 15:38:32 UTC 2008 x86_64 GNU/Linux",
- .sysCapSupported = LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_ROUTER,
- .sysCapEnabled = LLDP_CAP_ROUTER
-};
-
-oid chassisIdSubtype_oid[] = {1, 0, 8802, 1, 1, 2, 1, 3, 1, 0};
-oid chassisId_oid[] = {1, 0, 8802, 1, 1, 2, 1, 3, 2, 0};
-oid sysName_oid[] = {1, 0, 8802, 1, 1, 2, 1, 3, 3, 0};
-oid sysDesc_oid[] = {1, 0, 8802, 1, 1, 2, 1, 3, 4, 0};
-oid sysCapSupported_oid[] = {1, 0, 8802, 1, 1, 2, 1, 3, 5, 0};
-oid sysCapEnabled_oid[] = {1, 0, 8802, 1, 1, 2, 1, 3, 6, 0};
-
-typedef struct snmp_type {
- u_char *value;
- int *value_size;
- int type;
-} snmp_type;
-
-struct lldpPort {
- int portIdSubtype;
- u_int8_t portId[256];
- int portId_len;
- char portDesc[256];
-} lldpPort;
-
-struct lldpRemote {
- /* Index values */
- u_int32_t lldpRemTimeMark;
- int lldpRemLocalPortNum;
- int lldpRemIndex;
-
- struct lldpPort port;
- struct lldpChassis remote;
-
- TAILQ_ENTRY(lldpRemote) next;
-} lldpRemote;
-
-TAILQ_HEAD(, lldpRemote) r_entries;
-
-struct lldpRemote r1 = {
- .lldpRemTimeMark = 4121,
- .lldpRemLocalPortNum = 1,
- .lldpRemIndex = 1,
- .port = {
- .portIdSubtype = LLDP_PORTID_SUBTYPE_LLADDR,
- .portId = { 0x00, 0x05, 0x06, 0x07, 0x0a, 0x01 },
- .portId_len = 6,
- .portDesc = "eth0"
- },
- .remote = {
- .chassisIdSubtype = LLDP_CHASSISID_SUBTYPE_LLADDR,
- .chassisId = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x06 },
- .chassisId_len = 6,
- .sysName = "titi.luffy.cx",
- .sysDesc = "Linux titi 2.6.25-2-amd64 #1 SMP Thu Jun 12 15:38:32 UTC 2008 x86_64 GNU/Linux",
- .sysCapSupported = LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_ROUTER,
- .sysCapEnabled = LLDP_CAP_ROUTER
- }
-};
-
-struct lldpRemote r2 = {
- .lldpRemTimeMark = 4127,
- .lldpRemLocalPortNum = 3,
- .lldpRemIndex = 2,
- .port = {
- .portIdSubtype = LLDP_PORTID_SUBTYPE_LLADDR,
- .portId = { 0x00, 0x05, 0x06, 0x07, 0x0a, 0x03 },
- .portId_len = 6,
- .portDesc = "en4"
- },
- .remote = {
- .chassisIdSubtype = LLDP_CHASSISID_SUBTYPE_LLADDR,
- .chassisId = { 0x07, 0x01, 0x02, 0x03, 0x04, 0x06 },
- .chassisId_len = 6,
- .sysName = "tito.luffy.cx",
- .sysDesc = "Linux tito 2.6.25-2-amd64 #1 SMP Thu Jun 12 15:38:32 UTC 2008 x86_64 GNU/Linux",
- .sysCapSupported = LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_ROUTER,
- .sysCapEnabled = LLDP_CAP_ROUTER
- }
-};
-
-int lldpRemTable_handler(
- netsnmp_mib_handler *handler,
- netsnmp_handler_registration *reginfo,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests) {
-
- netsnmp_request_info *request;
- netsnmp_table_request_info *table_info;
- struct lldpRemote *table_entry;
-
- switch (reqinfo->mode) {
- case MODE_GET:
- for (request=requests; request; request=request->next) {
- table_entry = (struct lldpRemote *)
- netsnmp_extract_iterator_context(request);
- table_info = netsnmp_extract_table_info(request);
-
- if (!table_entry) {
- netsnmp_set_request_error(reqinfo, request,
- SNMP_NOSUCHINSTANCE);
- continue;
- }
-
- switch (table_info->colnum) {
- case 4:
- snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
- table_entry->remote.chassisIdSubtype);
- break;
- case 5:
- snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
- (u_char*)table_entry->remote.chassisId,
- table_entry->remote.chassisId_len);
- break;
- case 6:
- snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
- table_entry->port.portIdSubtype);
- break;
- case 7:
- snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
- (u_char*)table_entry->port.portId,
- table_entry->port.portId_len);
- break;
- case 8:
- snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
- (u_char*)table_entry->port.portDesc,
- strlen(table_entry->port.portDesc));
- break;
- case 9:
- snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
- (u_char*)table_entry->remote.sysName,
- strlen(table_entry->remote.sysName));
- break;
- case 10:
- snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
- (u_char*)table_entry->remote.sysDesc,
- strlen(table_entry->remote.sysDesc));
- break;
- case 11:
- snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
- (u_char*)&(table_entry->remote.sysCapSupported),
- 1);
- break;
- case 12:
- snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
- (u_char*)&(table_entry->remote.sysCapEnabled),
- 1);
- break;
- default:
- netsnmp_set_request_error(reqinfo, request,
- SNMP_NOSUCHOBJECT);
- break;
- }
- }
- break;
-
- }
- return SNMP_ERR_NOERROR;
-}
-
-netsnmp_variable_list *lldpRemTable_get_next_data_point(void **my_loop_context,
- void **my_data_context,
- netsnmp_variable_list *put_index_data,
- netsnmp_iterator_info *mydata) {
- struct lldpRemote *entry = (struct lldpRemote*)*my_loop_context;
- netsnmp_variable_list *idx = put_index_data;
-
- if (entry) {
- snmp_set_var_typed_integer( idx, ASN_TIMETICKS, entry->lldpRemTimeMark );
- idx = idx->next_variable;
- snmp_set_var_typed_integer( idx, ASN_INTEGER, entry->lldpRemLocalPortNum );
- idx = idx->next_variable;
- snmp_set_var_typed_integer( idx, ASN_INTEGER, entry->lldpRemIndex );
- idx = idx->next_variable;
- *my_data_context = (void *)entry;
- *my_loop_context = TAILQ_NEXT(entry, next);
- return put_index_data;
- } else {
- return NULL;
- }
-}
-
-netsnmp_variable_list *lldpRemTable_get_first_data_point(void **my_loop_context,
- void **my_data_context,
- netsnmp_variable_list *put_index_data,
- netsnmp_iterator_info *mydata) {
- *my_loop_context = TAILQ_FIRST(&r_entries);
- return lldpRemTable_get_next_data_point(my_loop_context, my_data_context,
- put_index_data, mydata);
-}
-
-void populate_r_entries() {
- static oid lldpRemTable_oid[] = {1,0,8802,1,1,2,1,4,1};
- size_t lldpRemTable_oid_len = OID_LENGTH(lldpRemTable_oid);
- netsnmp_handler_registration *reg;
- netsnmp_iterator_info *iinfo;
- netsnmp_table_registration_info *table_info;
-
- reg = netsnmp_create_handler_registration(
- "lldpRemTable", lldpRemTable_handler,
- lldpRemTable_oid, lldpRemTable_oid_len,
- HANDLER_CAN_RONLY
- );
-
- table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
- netsnmp_table_helper_add_indexes(table_info,
- ASN_TIMETICKS, /* index: lldpRemTimeMark */
- ASN_INTEGER, /* index: lldpRemLocalPortNum */
- ASN_INTEGER, /* index: lldpRemIndex */
- 0);
- table_info->min_column = 1;
- table_info->max_column = 12;
-
- iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
- iinfo->get_first_data_point = lldpRemTable_get_first_data_point;
- iinfo->get_next_data_point = lldpRemTable_get_next_data_point;
- iinfo->table_reginfo = table_info;
-
- netsnmp_register_table_iterator( reg, iinfo );
-
- TAILQ_INIT(&r_entries);
- TAILQ_INSERT_TAIL(&r_entries, &r1, next);
- TAILQ_INSERT_TAIL(&r_entries, &r2, next);
-}
-
-int netsnmp_instance_universal_handler(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *reginfo,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests) {
- struct snmp_type *st = (struct snmp_type *) handler->myvoid;
- int size;
-
- switch (reqinfo->mode) {
- case MODE_GET:
- if (st->value_size == NULL) {
- /* Try to guess */
- switch (st->type) {
- case ASN_COUNTER:
- case ASN_TIMETICKS:
- case ASN_INTEGER:
- case ASN_GAUGE:
- size = 4;
- break;
- case ASN_OCTET_STR:
- size = strlen((char*)st->value);
- break;
- default:
- size = 1;
- }
- } else
- size = *(st->value_size);
- snmp_set_var_typed_value(requests->requestvb, st->type,
- st->value, size);
- break;
- default:
- snmp_log(LOG_ERR,
- "netsnmp_instance_universal_handler: illegal mode\n");
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
- return SNMP_ERR_NOERROR;
- }
- if (handler->next && handler->next->access_method)
- return netsnmp_call_next_handler(handler, reginfo, reqinfo,
- requests);
- return SNMP_ERR_NOERROR;
-}
-
-int netsnmp_register_read_only_universal_instance(const char *name,
- oid * reg_oid,
- size_t reg_oid_len,
- void *value,
- int *value_size,
- int type) {
- netsnmp_handler_registration *myreg;
- struct snmp_type *st;
-
- /* We will leak memory... */
- st = (struct snmp_type *)malloc(sizeof(struct snmp_type));
- st->value = value;
- st->value_size = value_size;
- st->type = type;
-
- myreg =
- netsnmp_create_handler_registration(name,
- netsnmp_instance_universal_handler,
- reg_oid, reg_oid_len,
- HANDLER_CAN_RONLY);
- myreg->handler->myvoid = (void *) st;
-
- return netsnmp_register_read_only_instance(myreg);
-}
-
-#define REGISTER(variable, name, type) \
- netsnmp_register_read_only_universal_instance(#name, \
- name ## _oid, \
- OID_LENGTH(name ## _oid), \
- &variable.name, NULL, type)
-
-#define REGISTER_S(variable, name, type) \
- netsnmp_register_read_only_universal_instance(#name, \
- name ## _oid, \
- OID_LENGTH(name ## _oid), \
- &variable.name, &variable.name ## _len, type)
-
-#define REGISTER_FS(variable, name, size, type) \
- netsnmp_register_read_only_universal_instance(#name, \
- name ## _oid, \
- OID_LENGTH(name ## _oid), \
- &variable.name, &size, type)
-
-int one = 1;
-int two = 2;
-int three = 3;
-int interfaces[] = {1, 2, 3, 4};
-char stuff[] = { 0xf0 };
-
-void register_lldpPortConfig() {
- int i;
- static oid lldpPortConfigTable_oid[] = {1,0,8802,1,1,2,1,1,6};
- size_t lldpPortConfigTable_oid_len = OID_LENGTH(lldpPortConfigTable_oid);
- netsnmp_table_data_set *table_set;
- netsnmp_table_row *row;
- table_set = netsnmp_create_table_data_set("lldpPortConfigTable");
- netsnmp_table_set_add_indexes(table_set,
- ASN_INTEGER,
- 0);
- netsnmp_table_set_multi_add_default_row(table_set,
- 2, ASN_INTEGER, 0, NULL, 0,
- 3, ASN_INTEGER, 0, NULL, 0,
- 4, ASN_OCTET_STR, 0, NULL, 0,
- 0);
- netsnmp_register_table_data_set(
- netsnmp_create_handler_registration("lldpPortConfigTable", NULL,
- lldpPortConfigTable_oid,
- lldpPortConfigTable_oid_len,
- HANDLER_CAN_RONLY),
- table_set, NULL);
- for (i=0; i < sizeof(interfaces)/sizeof(int); i++) {
- row = netsnmp_create_table_data_row();
- netsnmp_table_row_add_index(row, ASN_INTEGER, (u_char*)(&interfaces[i]), sizeof(int));
- netsnmp_set_row_column(row, 2, ASN_INTEGER, (char*)&three, sizeof(three));
- netsnmp_set_row_column(row, 3, ASN_INTEGER, (char*)&two, sizeof(two));
- netsnmp_set_row_column(row, 4, ASN_OCTET_STR, stuff, 1);
-
- netsnmp_table_dataset_add_row(table_set, row);
- }
- netsnmp_register_auto_data_table(table_set, NULL);
-
-}
-
-int main (int argc, char **argv) {
-
- netsnmp_enable_subagent();
- snmp_disable_log();
- snmp_enable_stderrlog();
-
- init_agent("lldpAgent");
-
- REGISTER(global, messageTxInterval, ASN_INTEGER);
- REGISTER(global, messageTxHoldMultiplier, ASN_INTEGER);
- REGISTER(global, reinitDelay, ASN_INTEGER);
- REGISTER(global, txDelay, ASN_INTEGER);
- REGISTER(global, notificationInterval, ASN_INTEGER);
-
- REGISTER(stats, lastChangeTime, ASN_TIMETICKS);
- REGISTER(stats, inserts, ASN_GAUGE);
- REGISTER(stats, deletes, ASN_GAUGE);
- REGISTER(stats, drops, ASN_GAUGE);
- REGISTER(stats, ageouts, ASN_GAUGE);
-
- REGISTER(local, chassisIdSubtype, ASN_INTEGER);
- REGISTER_S(local, chassisId, ASN_OCTET_STR);
- REGISTER(local, sysName, ASN_OCTET_STR);
- REGISTER(local, sysDesc, ASN_OCTET_STR);
- REGISTER_FS(local, sysCapSupported, one, ASN_OCTET_STR);
- REGISTER_FS(local, sysCapEnabled, one, ASN_OCTET_STR);
-
- register_lldpPortConfig();
-
- populate_r_entries();
-
- init_snmp("lldpAgent");
-
- while(1)
- agent_check_and_process(1);
-
- snmp_shutdown("lldpAgent");
-
- return 0;
-}
-
-