/** * Logs the contents of ipth. * * @param ipth [in] pointer to the IP table handler structure * * @return 0 on success. 1 on failure. */ int ipt_handler_print(ipt_handler *ipth) { int i = 0, j = 0, k = 0, count = 0; if (!ipth || !ipth->init) { return (1); } if (log_level_get() == EUCA_LOG_TRACE) { for (i = 0; i < ipth->max_tables; i++) { LOGTRACE("TABLE (%d of %d): %s\n", i, ipth->max_tables, ipth->tables[i].name); for (j = 0; j < ipth->tables[i].max_chains; j++) { LOGTRACE("\tCHAIN: (%d of %d, flushed=%d, refcount=%d): %s %s %s\n", j, ipth->tables[i].max_chains, ipth->tables[i].chains[j].flushed, ipth->tables[i].chains[j].ref_count, ipth->tables[i].chains[j].name, ipth->tables[i].chains[j].policyname, ipth->tables[i].chains[j].counters); count = 1; for (k = 0; k < ipth->tables[i].chains[j].max_rules; k++) { LOGTRACE("\t\tRULE (%d of %d, idx=%d,flushed=%d,ruleorder=%d): %s (%s)\n", count, ipth->tables[i].chains[j].max_rules, k, ipth->tables[i].chains[j].rules[k].flushed, ipth->tables[i].chains[j].rules[k].order, ipth->tables[i].chains[j].rules[k].iptrule, ipth->tables[i].chains[j].rules[k].counterstr); count++; } } } } return (0); }
static int lua_log(lua_State *L) { int nargs = lua_gettop(L); ASSERT_MSG(nargs >= 1, "Not enough arguments passed to log()"); enum log_level level = log_level_get(lua_tostring(L, 1)); int depth = luaL_checkinteger(L, 2); // Depth to ignore and report upper location if (depth < 0) return luaL_error(L, "Second argument mustn't be less then zero"); struct lua_Debug ldebug; lua_getstack(L, depth + 1, &ldebug); // get informations about caller lua_getinfo(L, "Sln", &ldebug); size_t sum = 1; size_t sizes[nargs - 2]; const char *strs[nargs - 2]; for (int i = 3; i <= nargs; i ++) { if (lua_isnil(L, i)) strs[i - 3] = "<nil>"; else if((strs[i - 3] = lua_tostring(L, i)) == NULL) // If it is not nil nor string or number, it is function or table so too complex just for simple log function strs[i - 3] = "<complex-type>"; sizes[i - 3] = strlen(strs[i - 3]); sum += sizes[i - 3]; } char *message = alloca(sum); size_t pos = 0; for (size_t i = 0; i < (unsigned)nargs - 2; i ++) { memcpy(message + pos, strs[i], sizes[i]); pos += sizes[i]; } message[pos] = '\0'; char *file = aprintf("%s.lua", ldebug.source); log_internal(level, file, ldebug.currentline, ldebug.name ? ldebug.name : "Globals", "%s", message); return 0; }
static int cmd_log_level(struct re_printf *pf, void *unused) { int level; (void)unused; level = log_level_get(); --level; if (level < LEVEL_DEBUG) level = LEVEL_ERROR; log_level_set(level); return re_hprintf(pf, "Log level '%s'\n", log_level_name(level)); }
//! //! Function description. //! //! @param[in] ipsh pointer to the IP set handler structure //! //! @return //! //! @see //! //! @pre //! //! @post //! //! @note //! int ips_handler_print(ips_handler * ipsh) { int i, j; char *strptra = NULL; if (!ipsh) { return (1); } if (log_level_get() == EUCA_LOG_TRACE) { for (i = 0; i < ipsh->max_sets; i++) { LOGTRACE("IPSET NAME: %s\n", ipsh->sets[i].name); for (j = 0; j < ipsh->sets[i].max_member_ips; j++) { strptra = hex2dot(ipsh->sets[i].member_ips[j]); LOGTRACE("\t MEMBER IP: %s/%d\n", strptra, ipsh->sets[i].member_nms[j]); EUCA_FREE(strptra); } } } return (0); }
//! //! Function description. //! //! @param[in] ebth pointer to the EB table handler structure //! //! @return 0 on success or 1 if any failure occured //! //! @see //! //! @pre //! //! @post //! //! @note //! int ebt_handler_print(ebt_handler * ebth) { int i, j, k; if (!ebth || !ebth->init) { return (1); } if (log_level_get() == EUCA_LOG_TRACE) { for (i = 0; i < ebth->max_tables; i++) { LOGTRACE("TABLE (%d of %d): %s\n", i, ebth->max_tables, ebth->tables[i].name); for (j = 0; j < ebth->tables[i].max_chains; j++) { LOGTRACE("\tCHAIN: (%d of %d, refcount=%d): %s policy=%s counters=%s\n", j, ebth->tables[i].max_chains, ebth->tables[i].chains[j].ref_count, ebth->tables[i].chains[j].name, ebth->tables[i].chains[j].policyname, ebth->tables[i].chains[j].counters); for (k = 0; k < ebth->tables[i].chains[j].max_rules; k++) { LOGTRACE("\t\tRULE (%d of %d): %s\n", k, ebth->tables[i].chains[j].max_rules, ebth->tables[i].chains[j].rules[k].ebtrule); } } } } return (0); }