/* Unregister mib nodes from Lua */ static int snmpd_mib_node_unreg(lua_State *L) { oid_t *inst_id; int inst_id_len; int i; /* Check if the first argument is a table. */ luaL_checktype(L, 1, LUA_TTABLE); /* Get oid length */ inst_id_len = lua_objlen(L, 1); /* Get oid */ inst_id = xmalloc(inst_id_len * sizeof(oid_t)); for (i = 0; i < inst_id_len; i++) { lua_rawgeti(L, 1, i + 1); inst_id[i] = lua_tointeger(L, -1); lua_pop(L, 1); } /* Unregister node */ mib_node_unreg(inst_id, inst_id_len); free(inst_id); return 0; }
/* Unregister mib group node */ static int agentx_mib_node_unreg(const oid_t *grp_id, int id_len) { struct x_pdu_buf x_pdu; /* Check oid prefix */ if (id_len < 4 || grp_id[0] != 1 || grp_id[1] != 3 || grp_id[2] != 6 || grp_id[3] != 1) { SMARTSNMP_LOG(L_ERROR, "Oid prefix must be .1.3.6.1!"); return -1; } /* Send angentX register PDU */ x_pdu = agentx_unregister_pdu(&agentx_datagram, grp_id, id_len, NULL, 0, 0, 127, 0, 0); if (send(agentx_datagram.sock, x_pdu.buf, x_pdu.len, 0) == -1) { SMARTSNMP_LOG(L_ERROR, "Send agentX unregister PDU failure!"); return -1; } /* Receive agentX response PDU */ x_pdu.len = TRANS_BUF_SIZ; x_pdu.buf = xrealloc(x_pdu.buf, x_pdu.len); x_pdu.len = recv(agentx_datagram.sock, x_pdu.buf, x_pdu.len, 0); if (x_pdu.len == -1) { SMARTSNMP_LOG(L_ERROR, "Receive agentX unregister response PDU failure!\n"); return -1; } /* Verify register response PDU */ if (agentx_recv(x_pdu.buf, x_pdu.len) != AGENTX_ERR_OK) { SMARTSNMP_LOG(L_ERROR, "Unregister response error!"); return -1; } /* Unregister node */ mib_node_unreg(grp_id, id_len); return 0; }
/* Unregister mib group nodes */ static int snmpd_mib_node_unreg(const oid_t *grp_id, int id_len) { mib_node_unreg(grp_id, id_len); return 0; }