Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New set of changes. Please review #4

Merged
merged 5 commits into from Aug 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion include/netlink/version.h.in
@@ -1,5 +1,5 @@
/*
* netlink/version.h Compile Time Versioning Information
* netlink/version.h Versioning Information
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -12,6 +12,8 @@
#ifndef NETLINK_VERSION_H_
#define NETLINK_VERSION_H_

/* Compile Time Versioning Information */

#define LIBNL_STRING "@PACKAGE_STRING@"
#define LIBNL_VERSION "@PACKAGE_VERSION@"

Expand All @@ -25,4 +27,11 @@
#define LIBNL_REVISION @LT_REVISION@
#define LIBNL_AGE @LT_AGE@

/* Run-time version information */

extern const int nl_ver_num;
extern const int nl_ver_maj;
extern const int nl_ver_min;
extern const int nl_ver_mic;

#endif
1 change: 1 addition & 0 deletions lib/.gitignore
@@ -1,2 +1,3 @@
libnl.so*
libnl-*.so*
lex.yy.c
3 changes: 2 additions & 1 deletion lib/Makefile.am
Expand Up @@ -17,7 +17,8 @@ lib_LTLIBRARIES = \

libnl_3_la_SOURCES = \
addr.c attr.c cache.c cache_mngr.c cache_mngt.c data.c \
error.c handlers.c msg.c nl.c object.c socket.c utils.c
error.c handlers.c msg.c nl.c object.c socket.c utils.c \
version.c

libnl_genl_3_la_LIBADD = libnl-3.la
libnl_genl_3_la_SOURCES = \
Expand Down
6 changes: 3 additions & 3 deletions lib/netfilter/ct_obj.c
Expand Up @@ -267,8 +267,8 @@ static void ct_dump_stats(struct nl_object *a, struct nl_dump_params *p)
!nfnl_ct_test_bytes(ct, 1) ||
!nfnl_ct_test_packets(ct, 1))
{
nl_dump_line(p, " Statics are not available.\n");
nl_dump_line(p, " Please set sysctl net.netfilter.nf_conntrack_acct = 1\n");
nl_dump_line(p, " Statistics are not available.\n");
nl_dump_line(p, " Please set sysctl net.netfilter.nf_conntrack_acct=1\n");
nl_dump_line(p, " (Require kernel 2.6.27)\n");
return;
}
Expand All @@ -277,7 +277,7 @@ static void ct_dump_stats(struct nl_object *a, struct nl_dump_params *p)
for (i=0; i<=1; i++) {
res = nl_cancel_down_bytes(nfnl_ct_get_bytes(ct, i), &unit);
packets = nfnl_ct_get_packets(ct, i);
nl_dump_line(p, " %s %10llu %7.2f %s\n", names[i], packets, res, unit);
nl_dump_line(p, " %s %10" PRIu64 " %7.2f %s\n", names[i], packets, res, unit);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/route/cls/u32.c
Expand Up @@ -306,7 +306,7 @@ static void u32_dump_stats(struct rtnl_tc *tc, void *data,
if (u->cu_mask & U32_ATTR_PCNT) {
struct tc_u32_pcnt *pc = u->cu_pcnt->d_data;
nl_dump(p, "\n");
nl_dump_line(p, " hit %8llu count %8llu\n",
nl_dump_line(p, " hit %8" PRIu64 " count %8" PRIu64 "\n",
pc->rhit, pc->rcnt);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/route/link.c
Expand Up @@ -662,7 +662,7 @@ static void link_dump_stats(struct nl_object *obj, struct nl_dump_params *p)

res = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_RX_BYTES], &unit);

strcpy(fmt, " RX %X.2f %s %10llu %10llu %10llu %10llu %10llu\n");
strcpy(fmt, " RX %X.2f %s %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 "\n");
fmt[9] = *unit == 'B' ? '9' : '7';

nl_dump_line(p, fmt, res, unit,
Expand All @@ -674,7 +674,7 @@ static void link_dump_stats(struct nl_object *obj, struct nl_dump_params *p)

res = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_TX_BYTES], &unit);

strcpy(fmt, " TX %X.2f %s %10llu %10llu %10llu %10llu %10llu\n");
strcpy(fmt, " TX %X.2f %s %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 "\n");
fmt[9] = *unit == 'B' ? '9' : '7';

nl_dump_line(p, fmt, res, unit,
Expand Down
38 changes: 19 additions & 19 deletions lib/route/link/inet6.c
Expand Up @@ -242,108 +242,108 @@ static void inet6_dump_stats(struct rtnl_link *link,

nl_dump(p, " IPv6: InPkts InOctets "
" InDiscards InDelivers\n");
nl_dump(p, " %18llu ", link->l_stats[RTNL_LINK_IP6_INPKTS]);
nl_dump(p, " %18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_INPKTS]);

octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_INOCTETS],
&octetsUnit);
if (octets)
nl_dump(p, "%14.2f %3s ", octets, octetsUnit);
else
nl_dump(p, "%16llu B ", 0);
nl_dump(p, "%16" PRIu64 " B ", 0);

nl_dump(p, "%18llu %18llu\n",
nl_dump(p, "%18" PRIu64 " %18" PRIu64 "\n",
link->l_stats[RTNL_LINK_IP6_INDISCARDS],
link->l_stats[RTNL_LINK_IP6_INDELIVERS]);

nl_dump(p, " OutPkts OutOctets "
" OutDiscards OutForwards\n");

nl_dump(p, " %18llu ", link->l_stats[RTNL_LINK_IP6_OUTPKTS]);
nl_dump(p, " %18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_OUTPKTS]);

octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_OUTOCTETS],
&octetsUnit);
if (octets)
nl_dump(p, "%14.2f %3s ", octets, octetsUnit);
else
nl_dump(p, "%16llu B ", 0);
nl_dump(p, "%16" PRIu64 " B ", 0);

nl_dump(p, "%18llu %18llu\n",
nl_dump(p, "%18" PRIu64 " %18" PRIu64 "\n",
link->l_stats[RTNL_LINK_IP6_OUTDISCARDS],
link->l_stats[RTNL_LINK_IP6_OUTFORWDATAGRAMS]);

nl_dump(p, " InMcastPkts InMcastOctets "
" InBcastPkts InBcastOctests\n");

nl_dump(p, " %18llu ", link->l_stats[RTNL_LINK_IP6_INMCASTPKTS]);
nl_dump(p, " %18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_INMCASTPKTS]);

octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_INMCASTOCTETS],
&octetsUnit);
if (octets)
nl_dump(p, "%14.2f %3s ", octets, octetsUnit);
else
nl_dump(p, "%16llu B ", 0);
nl_dump(p, "%16" PRIu64 " B ", 0);

nl_dump(p, "%18llu ", link->l_stats[RTNL_LINK_IP6_INBCASTPKTS]);
nl_dump(p, "%18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_INBCASTPKTS]);
octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_INBCASTOCTETS],
&octetsUnit);
if (octets)
nl_dump(p, "%14.2f %3s\n", octets, octetsUnit);
else
nl_dump(p, "%16llu B\n", 0);
nl_dump(p, "%16" PRIu64 " B\n", 0);

nl_dump(p, " OutMcastPkts OutMcastOctets "
" OutBcastPkts OutBcastOctests\n");

nl_dump(p, " %18llu ", link->l_stats[RTNL_LINK_IP6_OUTMCASTPKTS]);
nl_dump(p, " %18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_OUTMCASTPKTS]);

octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_OUTMCASTOCTETS],
&octetsUnit);
if (octets)
nl_dump(p, "%14.2f %3s ", octets, octetsUnit);
else
nl_dump(p, "%16llu B ", 0);
nl_dump(p, "%16" PRIu64 " B ", 0);

nl_dump(p, "%18llu ", link->l_stats[RTNL_LINK_IP6_OUTBCASTPKTS]);
nl_dump(p, "%18" PRIu64 " ", link->l_stats[RTNL_LINK_IP6_OUTBCASTPKTS]);
octets = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_IP6_OUTBCASTOCTETS],
&octetsUnit);
if (octets)
nl_dump(p, "%14.2f %3s\n", octets, octetsUnit);
else
nl_dump(p, "%16llu B\n", 0);
nl_dump(p, "%16" PRIu64 " B\n", 0);

nl_dump(p, " ReasmOKs ReasmFails "
" ReasmReqds ReasmTimeout\n");
nl_dump(p, " %18llu %18llu %18llu %18llu\n",
nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n",
link->l_stats[RTNL_LINK_IP6_REASMOKS],
link->l_stats[RTNL_LINK_IP6_REASMFAILS],
link->l_stats[RTNL_LINK_IP6_REASMREQDS],
link->l_stats[RTNL_LINK_IP6_REASMTIMEOUT]);

nl_dump(p, " FragOKs FragFails "
" FragCreates\n");
nl_dump(p, " %18llu %18llu %18llu\n",
nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n",
link->l_stats[RTNL_LINK_IP6_FRAGOKS],
link->l_stats[RTNL_LINK_IP6_FRAGFAILS],
link->l_stats[RTNL_LINK_IP6_FRAGCREATES]);

nl_dump(p, " InHdrErrors InTooBigErrors "
" InNoRoutes InAddrErrors\n");
nl_dump(p, " %18llu %18llu %18llu %18llu\n",
nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n",
link->l_stats[RTNL_LINK_IP6_INHDRERRORS],
link->l_stats[RTNL_LINK_IP6_INTOOBIGERRORS],
link->l_stats[RTNL_LINK_IP6_INNOROUTES],
link->l_stats[RTNL_LINK_IP6_INADDRERRORS]);

nl_dump(p, " InUnknownProtos InTruncatedPkts "
" OutNoRoutes\n");
nl_dump(p, " %18llu %18llu %18llu\n",
nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n",
link->l_stats[RTNL_LINK_IP6_INUNKNOWNPROTOS],
link->l_stats[RTNL_LINK_IP6_INTRUNCATEDPKTS],
link->l_stats[RTNL_LINK_IP6_OUTNOROUTES]);

nl_dump(p, " ICMPv6: InMsgs InErrors "
" OutMsgs OutErrors\n");
nl_dump(p, " %18llu %18llu %18llu %18llu\n",
nl_dump(p, " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 " %18" PRIu64 "\n",
link->l_stats[RTNL_LINK_ICMP6_INMSGS],
link->l_stats[RTNL_LINK_ICMP6_INERRORS],
link->l_stats[RTNL_LINK_ICMP6_OUTMSGS],
Expand Down
21 changes: 16 additions & 5 deletions lib/route/neightbl.c
Expand Up @@ -332,21 +332,32 @@ static void neightbl_dump_stats(struct nl_object *arg, struct nl_dump_params *p)
if (!(ntbl->ce_mask & NEIGHTBL_ATTR_STATS))
return;

nl_dump_line(p, " lookups %lld hits %lld failed %lld " \
"allocations %lld destroys %lld\n",
nl_dump_line(p, " " \
" lookups %" PRIu64 \
" hits %" PRIu64 \
" failed %" PRIu64 \
" allocations %" PRIu64 \
" destroys %" PRIu64 \
"\n",
ntbl->nt_stats.ndts_lookups,
ntbl->nt_stats.ndts_hits,
ntbl->nt_stats.ndts_res_failed,
ntbl->nt_stats.ndts_allocs,
ntbl->nt_stats.ndts_destroys);

nl_dump_line(p, " hash-grows %lld forced-gc-runs %lld " \
"periodic-gc-runs %lld\n",
nl_dump_line(p, " " \
" hash-grows %" PRIu64 \
" forced-gc-runs %" PRIu64 \
" periodic-gc-runs %" PRIu64 \
"\n",
ntbl->nt_stats.ndts_hash_grows,
ntbl->nt_stats.ndts_forced_gc_runs,
ntbl->nt_stats.ndts_periodic_gc_runs);

nl_dump_line(p, " rcv-unicast-probes %lld rcv-multicast-probes %lld\n",
nl_dump_line(p, " " \
" rcv-unicast-probes %" PRIu64 \
" rcv-multicast-probes %" PRIu64 \
"\n",
ntbl->nt_stats.ndts_rcv_probes_ucast,
ntbl->nt_stats.ndts_rcv_probes_mcast);
}
Expand Down
14 changes: 10 additions & 4 deletions lib/utils.c
Expand Up @@ -28,6 +28,7 @@
#include <netlink/netlink.h>
#include <netlink/utils.h>
#include <linux/socket.h>
#include <stdlib.h> /* exit() */

/**
* Global variable indicating the desired level of debugging output.
Expand Down Expand Up @@ -421,10 +422,15 @@ static void __init get_psched_settings(void)
strncpy(name, "/proc/net/psched", sizeof(name) - 1);

if ((fd = fopen(name, "r"))) {
uint32_t ns_per_usec, ns_per_tick, nom, denom;

fscanf(fd, "%08x %08x %08x %08x",
&ns_per_usec, &ns_per_tick, &nom, &denom);
unsigned int ns_per_usec, ns_per_tick, nom, denom;

if (fscanf(fd, "%08x %08x %08x %08x",
&ns_per_usec, &ns_per_tick, &nom, &denom) != 4) {
fprintf(stderr, "Fatal error: can not read psched settings from \"%s\". " \
"Try to set TICKS_PER_USEC, PROC_NET_PSCHED or PROC_ROOT " \
"environment variables\n", name);
exit(1);
}

ticks_per_usec = (double) ns_per_usec /
(double) ns_per_tick;
Expand Down
36 changes: 36 additions & 0 deletions lib/version.c
@@ -0,0 +1,36 @@
/*
* lib/version.c Run-time version information
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
*/

/**
* @ingroup core
* @defgroup utils Utilities
*
* Run-time version information
*
* @{
*/


/**
* @name Run-time version information
* @{
*/

#include <netlink/version.h>

const int nl_ver_num = LIBNL_VER_NUM;
const int nl_ver_maj = LIBNL_VER_MAJ;
const int nl_ver_min = LIBNL_VER_MIN;
const int nl_ver_mic = LIBNL_VER_MIC;

/** @} */

/** @} */
2 changes: 1 addition & 1 deletion src/nl-list-sockets.c
Expand Up @@ -30,7 +30,7 @@ int main(int argc, char *argv[])
while (fgets(buf, sizeof(buf), fd)) {
unsigned long sk, cb;
int ret, proto, pid, rmem, wmem, refcnt;
uint32_t groups;
unsigned int groups;

ret = sscanf(buf, "%lx %d %d %08x %d %d %lx %d\n",
&sk, &proto, &pid, &groups, &rmem, &wmem,
Expand Down