numerous changes and improvements in the user space library
PATCH 2/3 numerous changes and improvements in the user space library
The following is the second patch in a series of 3 patches, dealing with the libnetfilter_acct user space library changes as following:
* added over 15 possible format options for number formatting.
* added a new nfacct_snprintf_with_options function, allowing customized options to be specified, including column width and format to be used.
* added a variety of new interface functions to get/set nfacct option properties.
* added 4 new nfacct_snprintf formats:
- SAVE: for printing in a format suitable for 'restore';
- BONLY: for printing only the 'bytes' and 'name' columns of accounting
objects when list/get commands are specified;
- EXTENDED: for printing all properties of accounting objects; and
- NUMONLY: for printing "numbers-only" (formatted) of accounting objects, which is useful for determining the maximum column width of all accounting objects to be used when printed with the 'list' command.
* the output template format for the 'list' command has been changed slightly to accommodate new output (plain), which I think is better than the old one.
* backwards compatibility with the old (not updated) version of nfacct (executable) has been re-established.
* all accounting object names are now properly encoded and displayed with the 'list' and 'get' commands - this was one flaw with the current implementation which has now been corrected. It allowed account names which were not properly encoded (and containing '<' or '&' for example) to be displayed unencoded when xml output was selected. This was certain to brake xml parsers which were about to use this output as it did not conform to the xml specification.
* all plain-text output for each column (packets, bytes, byte threshold) can now be formatted, according to the maximum width used by all accounting objects. This wasn't possible before, which caused all values to be shown as zero-leading, fixed-width numbers, and that made reading very uncomfortable and difficult. With the new snprintf function, it is now possible to determine the width which needs to be used for each column and show the accounting object numbers properly aligned.
--- include/libnetfilter_acct/libnetfilter_acct.h | 55 ++ include/linux/netfilter/nfnetlink_acct.h | 2 + src/libnetfilter_acct.c | 763 ++++++++++++++++++++++++- src/libnetfilter_acct.map | 13 + 4 files changed, 812 insertions(+), 21 deletions(-)
include/libnetfilter_acct/libnetfilter_acct.h +55 -0
@@ -11,19 +11,67 @@ enum nfacct_attr_type {NFACCT_ATTR_NAME =0 ,NFACCT_ATTR_PKTS ,NFACCT_ATTR_BYTES , +NFACCT_ATTR_BTHR , + NFACCT_ATTR_FMT, +}; + +struct nfacct_options ; + +enum nfacct_option_type { +NFACCT_OPT_FMT =0 , +NFACCT_OPT_PCW , +NFACCT_OPT_BCW , +NFACCT_OPT_BTCW , +}; + +enum nfacct_format { +FMT_DEFAULT =0 , +FMT_NONE , +FMT_TRIPLETS , +FMT_IEC , +FMT_IEC_KIBIBYTE , +FMT_IEC_MEBIBYTE , +FMT_IEC_GIBIBYTE , +FMT_IEC_TEBIBYTE , +FMT_IEC_PEBIBYTE , +FMT_IEC_EXBIBYTE , +FMT_SI , +FMT_SI_KILOBYTE , +FMT_SI_MEGABYTE , +FMT_SI_GIGABYTE , +FMT_SI_TERABYTE , +FMT_SI_PETABYTE , +FMT_SI_EXABYTE , +FMT_MAX , };struct nfacct *nfacct_alloc (void );void nfacct_free (struct nfacct *nfacct); +struct nfacct_options *nfacct_options_alloc (void ); +void nfacct_options_free (struct nfacct_options *options); +void nfacct_attr_set (struct nfacct *nfacct,enum nfacct_attr_type type,const void *data);void nfacct_attr_set_str (struct nfacct *nfacct,enum nfacct_attr_type type,const char *name);void nfacct_attr_set_u64 (struct nfacct *nfacct,enum nfacct_attr_type type,uint64_t value); +void nfacct_attr_set_u32 (struct nfacct *nfacct,enum nfacct_attr_type type,uint32_t value);void nfacct_attr_unset (struct nfacct *nfacct,enum nfacct_attr_type type);const void *nfacct_attr_get (struct nfacct *nfacct,enum nfacct_attr_type type);const char *nfacct_attr_get_str (struct nfacct *nfacct,enum nfacct_attr_type type);uint64_t nfacct_attr_get_u64 (struct nfacct *nfacct,enum nfacct_attr_type type); +uint32_t nfacct_attr_get_u32 (struct nfacct *nfacct,enum nfacct_attr_type type); + +void nfacct_option_set (struct nfacct_options *options,enum nfacct_option_type type,const void *data); +void nfacct_option_set_u32 (struct nfacct_options *options,enum nfacct_option_type type,uint32_t value); +void nfacct_option_set_tsize (struct nfacct_options *options,enum nfacct_option_type type,size_t value); +void nfacct_option_unset (struct nfacct_options *options,enum nfacct_option_type type); + +const void *nfacct_option_get (struct nfacct_options *options,enum nfacct_option_type type); +uint32_t nfacct_option_get_u32 (struct nfacct_options *options,enum nfacct_option_type type); +size_t nfacct_option_get_tsize (struct nfacct_options *options,enum nfacct_option_type type); + +void parse_nfacct_name (char *buf,const char *name);struct nlmsghdr ;
@@ -33,10 +81,17 @@ int nfacct_nlmsg_parse_payload(const struct nlmsghdr *nlh, struct nfacct *nfacct#define NFACCT_SNPRINTF_F_FULL (1 << 0)#define NFACCT_SNPRINTF_F_TIME (1 << 1) +#define NFACCT_SNPRINTF_F_NUMONLY (1 << 2)/* print "numbers-only" (formatted), +useful for determining max column width */ +#define NFACCT_SNPRINTF_F_BONLY (1 << 3)/* print only the "bytes" and "name" columns */ +#define NFACCT_SNPRINTF_F_EXTENDED (1 << 4)/* print packets, bytes, threshold and names */ +#define NFACCT_SNPRINTF_F_SAVE (1 << 5)/* print in a format suitable for 'restore' */ #define NFACCT_SNPRINTF_T_PLAIN 0#define NFACCT_SNPRINTF_T_XML 1int nfacct_snprintf (char *buf,size_t size,struct nfacct *nfacct,uint16_t type,uint16_t flags); +int nfacct_snprintf_with_options (char *buf,size_t size,struct nfacct *nfacct, +uint16_t type,uint16_t flags,struct nfacct_options *options);#endif
include/linux/netfilter/nfnetlink_acct.h +2 -0
@@ -18,6 +18,8 @@ enum nfnl_acct_type {NFACCT_NAME ,NFACCT_PKTS ,NFACCT_BYTES , +NFACCT_BTHR , +NFACCT_FMT ,NFACCT_USE , __NFACCT_MAX };
src/libnetfilter_acct.c +742 -21
880 lines not on this page · raw message
src/libnetfilter_acct.map +13 -0
@@ -21,4 +21,17 @@ local: *; LIBNETFILTER_ACCT_1.1 { nfacct_snprintf; + nfacct_attr_set_u32; + nfacct_attr_get_u32; + nfacct_options_alloc; + nfacct_options_free; + nfacct_option_set; + nfacct_option_set_u32; + nfacct_option_set_tsize; + nfacct_option_unset; + nfacct_option_get; + nfacct_option_get_u32; + nfacct_option_get_tsize; + parse_nfacct_name; + nfacct_snprintf_with_options; } LIBNETFILTER_ACCT_1.0;