From f3a8e5e4089342b0013e8d8cb1bab43534147001 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 29 Dec 2011 16:06:48 +0100 Subject: src: add library documentation in doxygen This patch adds the library documentation in doxygen format. Signed-off-by: Pablo Neira Ayuso --- configure.ac | 2 +- doxygen.cfg.in | 184 ++++++++++++++++++++++++++++++++++++++++++++++++ src/libnetfilter_acct.c | 181 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 342 insertions(+), 25 deletions(-) create mode 100644 doxygen.cfg.in diff --git a/configure.ac b/configure.ac index 0f8da1f..80191fd 100644 --- a/configure.ac +++ b/configure.ac @@ -29,5 +29,5 @@ regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \ -Wformat=2 -pipe" AC_SUBST([regular_CPPFLAGS]) AC_SUBST([regular_CFLAGS]) -AC_CONFIG_FILES([Makefile src/Makefile include/Makefile include/libnetfilter_acct/Makefile include/linux/Makefile include/linux/netfilter/Makefile examples/Makefile libnetfilter_acct.pc]) +AC_CONFIG_FILES([Makefile src/Makefile include/Makefile include/libnetfilter_acct/Makefile include/linux/Makefile include/linux/netfilter/Makefile examples/Makefile libnetfilter_acct.pc doxygen.cfg]) AC_OUTPUT diff --git a/doxygen.cfg.in b/doxygen.cfg.in new file mode 100644 index 0000000..7f4bd04 --- /dev/null +++ b/doxygen.cfg.in @@ -0,0 +1,184 @@ +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = @PACKAGE@ +PROJECT_NUMBER = @VERSION@ +OUTPUT_DIRECTORY = doxygen +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = YES +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +TYPEDEF_HIDES_STRUCT = NO +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = NO +FILE_VERSION_FILTER = +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +INPUT = . +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.c libnetfilter_acct.h +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = */.git/* .*.d +EXCLUDE_SYMBOLS = EXPORT_SYMBOL nfacct +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +SOURCE_BROWSER = YES +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +HTML_DYNAMIC_SECTIONS = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NO +TREEVIEW_WIDTH = 250 +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +GENERATE_MAN = YES +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +GENERATE_AUTOGEN_DEF = NO +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = YES +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = YES +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +SEARCHENGINE = NO diff --git a/src/libnetfilter_acct.c b/src/libnetfilter_acct.c index 86d7b96..9fe7d51 100644 --- a/src/libnetfilter_acct.c +++ b/src/libnetfilter_acct.c @@ -20,6 +20,41 @@ #include +/** + * \mainpage + * + * libnetfilter_acct is the userspace library that provides a programming + * interface (API) to the extended accounting infrastructure. Basically, you + * can find here a set of helper functions that you can use together with + * libmnl. + * + * libnetfilter_acct homepage is: + * http://netfilter.org/projects/libnetfilter_acct/ + * + * \section Dependencies + * libnetfilter_acct requires libmnl >= 1.0.0 and the Linux kernel that + * includes the nfnetlink_acct subsystem (i.e. 3.3.x or any later). + * + * \section Main Features + * - listing/retrieving existing accounting objects. + * - atomically retrieving and reset accounting objects. + * - inserting/modifying/deleting accounting objects. + * + * \section Git Tree + * The current development version of libnetfilter_acct can be accessed at + * https://git.netfilter.org/cgi-bin/gitweb.cgi?p=libnetfilter_acct.git + * + * \section using Using libnetfilter_acct + * To write your own program using libnetfilter_acct, you should start by + * reading the documentation for libmnl to understand basic operation with + * Netlink sockets. Moreover, you may want to check the examples available + * under examples/ in the libnetfilter_acct source code. You can compile + * these examples by invoking `make check'. + * + * \section Authors + * libnetfilter_acct has been written by Pablo Neira Ayuso. + */ + struct nfacct { char name[NFACCT_NAME_MAX]; uint64_t pkts; @@ -27,18 +62,39 @@ struct nfacct { uint32_t bitset; }; +/** + * \defgroup nfacct Accounting object handling + * @{ + */ + +/** + * nfacct_alloc - allocate a new accounting object + * + * In case of success, this function returns a valid pointer, otherwise NULL + * s returned and errno is appropriately set. + */ struct nfacct *nfacct_alloc(void) { return calloc(1, sizeof(struct nfacct)); } EXPORT_SYMBOL(nfacct_alloc); +/** + * nfacct_free - release one accounting object + * \param nfacct pointer to the accounting object + */ void nfacct_free(struct nfacct *nfacct) { free(nfacct); } EXPORT_SYMBOL(nfacct_free); +/** + * nfacct_attr_set - set one attribute of the accounting object + * \param nfacct pointer to the accounting object + * \param type attribute type you want to set + * \param data pointer to data that will be used to set this attribute + */ void nfacct_attr_set(struct nfacct *nfacct, enum nfacct_attr_type type, const void *data) @@ -61,6 +117,12 @@ nfacct_attr_set(struct nfacct *nfacct, enum nfacct_attr_type type, } EXPORT_SYMBOL(nfacct_attr_set); +/** + * nfacct_attr_set_str - set one attribute the accounting object + * \param nfacct pointer to the accounting object + * \param type attribute type you want to set + * \param name string that will be used to set this attribute + */ void nfacct_attr_set_str(struct nfacct *nfacct, enum nfacct_attr_type type, const char *name) @@ -69,6 +131,12 @@ nfacct_attr_set_str(struct nfacct *nfacct, enum nfacct_attr_type type, } EXPORT_SYMBOL(nfacct_attr_set_str); +/** + * nfacct_attr_set_u64 - set one attribute the accounting object + * \param nfacct pointer to the accounting object + * \param type attribute type you want to set + * \param value unsigned 64-bits integer + */ void nfacct_attr_set_u64(struct nfacct *nfacct, enum nfacct_attr_type type, uint64_t value) @@ -77,6 +145,11 @@ nfacct_attr_set_u64(struct nfacct *nfacct, enum nfacct_attr_type type, } EXPORT_SYMBOL(nfacct_attr_set_u64); +/** + * nfacct_attr_unset - unset one attribute the accounting object + * \param nfacct pointer to the accounting object + * \param type attribute type you want to set + */ void nfacct_attr_unset(struct nfacct *nfacct, enum nfacct_attr_type type) { @@ -94,6 +167,14 @@ nfacct_attr_unset(struct nfacct *nfacct, enum nfacct_attr_type type) } EXPORT_SYMBOL(nfacct_attr_unset); +/** + * nfacct_attr_get - get one attribute the accounting object + * \param nfacct pointer to the accounting object + * \param type attribute type you want to set + * + * This function returns a valid pointer to the attribute data. If a + * unsupported attribute is used, this returns NULL. + */ const void *nfacct_attr_get(struct nfacct *nfacct, enum nfacct_attr_type type) { const void *ret = NULL; @@ -113,6 +194,14 @@ const void *nfacct_attr_get(struct nfacct *nfacct, enum nfacct_attr_type type) } EXPORT_SYMBOL(nfacct_attr_get); +/** + * nfacct_attr_get_str - get one attribute the accounting object + * \param nfacct pointer to the accounting object + * \param type attribute type you want to set + * + * This function returns a valid pointer to the beginning of the string. + * If the attribute is unsupported, this returns NULL. + */ const char * nfacct_attr_get_str(struct nfacct *nfacct, enum nfacct_attr_type type) { @@ -120,18 +209,66 @@ nfacct_attr_get_str(struct nfacct *nfacct, enum nfacct_attr_type type) } EXPORT_SYMBOL(nfacct_attr_get_str); +/** + * nfacct_attr_get_u64 - get one attribute the accounting object + * \param nfacct pointer to the accounting object + * \param type attribute type you want to set + * + * This function returns a unsigned 64-bits integer. If the attribute is + * unsupported, this returns NULL. + */ uint64_t nfacct_attr_get_u64(struct nfacct *nfacct, enum nfacct_attr_type type) { return *((uint64_t *)nfacct_attr_get(nfacct, type)); } EXPORT_SYMBOL(nfacct_attr_get_u64); +/** + * nfacct_snprintf - print accounting object into one buffer + * \param buf: pointer to buffer that is used to print the object + * \param size: size of the buffer (or remaining room in it). + * \param nfacct: pointer to a valid accounting object. + * \param flags: output flags (NFACCT_SNPRINTF_F_FULL). + * + * This function returns -1 in case that some mandatory attributes are + * missing. On sucess, it returns 0. + */ +int nfacct_snprintf(char *buf, size_t size, struct nfacct *nfacct, + unsigned int flags) +{ + int ret; + + if (flags & NFACCT_SNPRINTF_F_FULL) { + ret = snprintf(buf, size, + "%s = { pkts = %.12llu,\tbytes = %.12llu };", + nfacct_attr_get_str(nfacct, NFACCT_ATTR_NAME), + (unsigned long long) + nfacct_attr_get_u64(nfacct, NFACCT_ATTR_BYTES), + (unsigned long long) + nfacct_attr_get_u64(nfacct, NFACCT_ATTR_PKTS)); + } else { + ret = snprintf(buf, size, "%s\n", + nfacct_attr_get_str(nfacct, NFACCT_ATTR_NAME)); + } + return ret; +} +EXPORT_SYMBOL(nfacct_snprintf); + +/** + * @} + */ + +/** + * \defgroup nlmsg Netlink message helper functions + * @{ + */ + /** * nfacct_nlmsg_build_hdr - build netlink message header for nfacct subsystem - * @buf: buffer where this function outputs the netlink message. - * @cmd: nfacct nfnetlink command. - * @flags: netlink flags. - * @seq: sequence number for this message. + * \param buf: buffer where this function outputs the netlink message. + * \param cmd: nfacct nfnetlink command. + * \param flags: netlink flags. + * \param seq: sequence number for this message. * * Possible commands: * - NFNL_MSG_ACCT_NEW: new accounting object. @@ -174,6 +311,11 @@ nfacct_nlmsg_build_hdr(char *buf, uint8_t cmd, uint16_t flags, uint32_t seq) } EXPORT_SYMBOL(nfacct_nlmsg_build_hdr); +/** + * nfacct_nlmsg_build_payload - build payload from accounting object + * \param nlh: netlink message that you want to use to add the payload. + * \param nfacct: pointer to a accounting object + */ void nfacct_nlmsg_build_payload(struct nlmsghdr *nlh, struct nfacct *nfacct) { if (nfacct->name) @@ -219,6 +361,14 @@ static int nfacct_nlmsg_parse_attr_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } +/** + * nfacct_nlmsg_parse_payload - set accounting object attributes from message + * \param nlh: netlink message that you want to use to add the payload. + * \param nfacct: pointer to a accounting object + * + * This function returns -1 in case that some mandatory attributes are + * missing. On sucess, it returns 0. + */ int nfacct_nlmsg_parse_payload(const struct nlmsghdr *nlh, struct nfacct *nfacct) { @@ -240,23 +390,6 @@ nfacct_nlmsg_parse_payload(const struct nlmsghdr *nlh, struct nfacct *nfacct) } EXPORT_SYMBOL(nfacct_nlmsg_parse_payload); -int nfacct_snprintf(char *buf, size_t size, struct nfacct *nfacct, - unsigned int flags) -{ - int ret; - - if (flags & NFACCT_SNPRINTF_F_FULL) { - ret = snprintf(buf, size, - "%s = { pkts = %.12llu,\tbytes = %.12llu };", - nfacct_attr_get_str(nfacct, NFACCT_ATTR_NAME), - (unsigned long long) - nfacct_attr_get_u64(nfacct, NFACCT_ATTR_BYTES), - (unsigned long long) - nfacct_attr_get_u64(nfacct, NFACCT_ATTR_PKTS)); - } else { - ret = snprintf(buf, size, "%s\n", - nfacct_attr_get_str(nfacct, NFACCT_ATTR_NAME)); - } - return ret; -} -EXPORT_SYMBOL(nfacct_snprintf); +/** + * @} + */ -- cgit v1.2.3