diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ChangeLog | 50 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/command.h | 9 | ||||
-rw-r--r-- | lib/if.h | 1 | ||||
-rw-r--r-- | lib/memory.c | 117 | ||||
-rw-r--r-- | lib/memory.h | 6 | ||||
-rw-r--r-- | lib/memtypes.awk | 6 | ||||
-rw-r--r-- | lib/memtypes.c | 3 | ||||
-rw-r--r-- | lib/privs.c | 38 | ||||
-rw-r--r-- | lib/workqueue.c | 5 | ||||
-rw-r--r-- | lib/workqueue.h | 3 |
11 files changed, 209 insertions, 31 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog index e3833526..9e6dc852 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,53 @@ +2006-03-30 Paul Jakma <paul.jakma@sun.com> + + * command.h: (DEFUN_CMD_FUNC_TEXT) Annotate arguments as + potentially being unused. + * workqueue.c: (work_queue_run) fix line length of comment + +2006-03-27 Paul Jakma <paul.jakma@sun.com> + + * memtypes.awk: Fix gensub call, g should be a string.. + +2006-03-25 Paul Jakma <paul.jakma@sun.com> + + * workqueue.h: (struct work_queue) Remove status field and + state flag, no longer used. + +2006-03-19 Paul Jakma <paul.jakma@sun.com> + + * memtypes.c: Add MTYPE_BGP_SYNCHRONISE. + +2006-03-16 Paul Jakma <paul.jakma@sun.com> + + * Makefile.am: Fix -version-info argument. + +2006-03-15 Paul Jakma <paul.jakma@sun.com> + + * memory.c: (mtype_memstr) new helper function to + return human friendly string for a byte count. + (mtype_stats_alloc) new function, for users to retrieve + number of objects allocated. + (show_memory_mallinfo) New function, show mallinfo statistics + if available. + (show_memory_all_cmd) Call show_memory_mallinfo, if mallinfo + is available. + * memory.h: Export mtype_memstr and mtype_stats_alloc. + Provide a define for a reasonable buffer size for + mtype_memstr. + +2006-03-14 Paul Jakma <paul.jakma@sun.com> + + * privs.c: (zprivs_caps_init) Change user IDs before lowering + privileges, while this seems to work on Linux, on Solaris + it rightfully refuses due to PRIV_PROC_SETID having been + dropped. + * command.h: Add the struct host global exported from command.c + +2006-03-06 Paul Jakma <paul.jakma@sun.com> + + * if.h: export show_address_cmd, for anyone who wishes to use + it. + 2006-02-21 Paul Jakma <paul.jakma@sun.com> * sockunion.c: (sockunion_{su2str,log}) Use XSTRDUP. diff --git a/lib/Makefile.am b/lib/Makefile.am index 5162de54..ec7ca00f 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,7 +4,7 @@ INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" lib_LTLIBRARIES = libzebra.la -libzebra_la_LDFLAGS = -version 0:0:0 +libzebra_la_LDFLAGS = -version-info 0:0:0 libzebra_la_SOURCES = \ network.c pid_output.c getopt.c getopt1.c daemon.c \ diff --git a/lib/command.h b/lib/command.h index fbe6a0a1..99aec332 100644 --- a/lib/command.h +++ b/lib/command.h @@ -183,7 +183,10 @@ struct desc #define DEFUN_CMD_FUNC_TEXT(funcname) \ static int funcname \ - (struct cmd_element *self, struct vty *vty, int argc, const char *argv[]) + (struct cmd_element *self __attribute__ ((unused)), \ + struct vty *vty __attribute__ ((unused)), \ + int argc __attribute__ ((unused)), \ + const char *argv[] __attribute__ ((unused)) ) /* DEFUN for vty command interafce. Little bit hacky ;-). */ #define DEFUN(funcname, cmdname, cmdstr, helpstr) \ @@ -351,5 +354,7 @@ extern char *host_config_file (void); extern void host_config_set (char *); extern void print_version (const char *); - + +/* struct host global, ick */ +extern struct host host; #endif /* _ZEBRA_COMMAND_H */ @@ -288,5 +288,6 @@ extern struct cmd_element interface_cmd; extern struct cmd_element no_interface_cmd; extern struct cmd_element interface_pseudo_cmd; extern struct cmd_element no_interface_pseudo_cmd; +extern struct cmd_element show_address_cmd; #endif /* _ZEBRA_IF_H */ diff --git a/lib/memory.c b/lib/memory.c index dae2b9ae..802c07f2 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -21,6 +21,7 @@ */ #include <zebra.h> +#include <malloc.h> #include "log.h" #include "memory.h" @@ -278,6 +279,47 @@ show_memory_vty (struct vty *vty, struct memory_list *list) return needsep; } +#ifdef HAVE_MALLINFO +static int +show_memory_mallinfo (struct vty *vty) +{ + struct mallinfo minfo = mallinfo(); + char buf[MTYPE_MEMSTR_LEN]; + + vty_out (vty, "System allocator statistics:%s", VTY_NEWLINE); + vty_out (vty, " Total heap allocated: %s%s", + mtype_memstr (buf, MTYPE_MEMSTR_LEN, minfo.arena), + VTY_NEWLINE); + vty_out (vty, " Holding block headers: %s%s", + mtype_memstr (buf, MTYPE_MEMSTR_LEN, minfo.hblkhd), + VTY_NEWLINE); + vty_out (vty, " Used small blocks: %s%s", + mtype_memstr (buf, MTYPE_MEMSTR_LEN, minfo.usmblks), + VTY_NEWLINE); + vty_out (vty, " Used ordinary blocks: %s%s", + mtype_memstr (buf, MTYPE_MEMSTR_LEN, minfo.uordblks), + VTY_NEWLINE); + vty_out (vty, " Free small blocks: %s%s", + mtype_memstr (buf, MTYPE_MEMSTR_LEN, minfo.fsmblks), + VTY_NEWLINE); + vty_out (vty, " Free ordinary blocks: %s%s", + mtype_memstr (buf, MTYPE_MEMSTR_LEN, minfo.fordblks), + VTY_NEWLINE); + vty_out (vty, " Ordinary blocks: %ld%s", + (unsigned long)minfo.ordblks, + VTY_NEWLINE); + vty_out (vty, " Small blocks: %ld%s", + (unsigned long)minfo.smblks, + VTY_NEWLINE); + vty_out (vty, " Holding blocks: %ld%s", + (unsigned long)minfo.hblks, + VTY_NEWLINE); + vty_out (vty, "(see system documentation for 'mallinfo' for meaning)%s", + VTY_NEWLINE); + return 1; +} +#endif /* HAVE_MALLINFO */ + DEFUN (show_memory_all, show_memory_all_cmd, "show memory all", @@ -287,7 +329,11 @@ DEFUN (show_memory_all, { struct mlist *ml; int needsep = 0; - + +#ifdef HAVE_MALLINFO + needsep = show_memory_mallinfo (vty); +#endif /* HAVE_MALLINFO */ + for (ml = mlists; ml->list; ml++) { if (needsep) @@ -416,3 +462,72 @@ memory_init (void) install_element (ENABLE_NODE, &show_memory_ospf6_cmd); install_element (ENABLE_NODE, &show_memory_isis_cmd); } + +/* Stats querying from users */ +/* Return a pointer to a human friendly string describing + * the byte count passed in. E.g: + * "0 bytes", "2048 bytes", "110kB", "500MiB", "11GiB", etc. + * Up to 4 significant figures will be given. + * The pointer returned may be NULL (indicating an error) + * or point to the given buffer, or point to static storage. + */ +const char * +mtype_memstr (char *buf, size_t len, unsigned long bytes) +{ + unsigned int t, g, m, k; + + /* easy cases */ + if (!bytes) + return "0 bytes"; + if (bytes == 1) + return "1 byte"; + + if (sizeof (unsigned long) >= 8) + /* Hacked to make it not warn on ILP32 machines + * Shift will always be 40 at runtime. See below too */ + t = bytes >> (sizeof (unsigned long) >= 8 ? 40 : 0); + else + t = 0; + g = bytes >> 30; + m = bytes >> 20; + k = bytes >> 10; + + if (t > 10) + { + /* The shift will always be 39 at runtime. + * Just hacked to make it not warn on 'smaller' machines. + * Static compiler analysis should mean no extra code + */ + if (bytes & (1 << (sizeof (unsigned long) >= 8 ? 39 : 0))) + t++; + snprintf (buf, len, "%4d TiB", t); + } + else if (g > 10) + { + if (bytes & (1 << 29)) + g++; + snprintf (buf, len, "%d GiB", g); + } + else if (m > 10) + { + if (bytes & (1 << 19)) + m++; + snprintf (buf, len, "%d MiB", m); + } + else if (k > 10) + { + if (bytes & (1 << 9)) + k++; + snprintf (buf, len, "%d KiB", k); + } + else + snprintf (buf, len, "%ld bytes", bytes); + + return buf; +} + +unsigned long +mtype_stats_alloc (int type) +{ + return mstat[type].alloc; +} diff --git a/lib/memory.h b/lib/memory.h index ef20b8c9..071f394e 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -79,4 +79,10 @@ extern char *mtype_zstrdup (const char *file, int line, int type, const char *str); extern void memory_init (void); +/* return number of allocations outstanding for the type */ +extern unsigned long mtype_stats_alloc (int); + +/* Human friendly string for given byte count */ +#define MTYPE_MEMSTR_LEN 20 +extern const char *mtype_memstr (char *, size_t, unsigned long); #endif /* _ZEBRA_MEMORY_H */ diff --git a/lib/memtypes.awk b/lib/memtypes.awk index 59a7ab2d..5429f6e8 100644 --- a/lib/memtypes.awk +++ b/lib/memtypes.awk @@ -1,4 +1,4 @@ -# $Id: memtypes.awk,v 1.3 2005/05/23 12:33:58 paul Exp $ +# $Id: memtypes.awk,v 1.4 2006/03/30 14:30:19 paul Exp $ # # Scan a file of memory definitions (see eg memtypes.c) and generate # a corresponding header file with an enum of the MTYPE's and declarations @@ -44,13 +44,13 @@ BEGIN { # catch lines beginning with 'struct memory list ' and try snag the # memory_list name. Has to be 3rd field. ($0 ~ /^struct memory_list /) && (NF >= 3) { - mlists[lcount++] = gensub(mlistregex,"\\1",g,$3); + mlists[lcount++] = gensub(mlistregex, "\\1", "g",$3); } # snag the MTYPE, it must self-standing and the second field, # though we do manage to tolerate the , C seperator being appended ($1 !~ /^\/?\*/) && ($2 ~ /^MTYPE_/) { - mtype[tcount++] = gensub(mtyperegex,"\\1",1, $2); + mtype[tcount++] = gensub(mtyperegex, "\\1", "g", $2); } END { diff --git a/lib/memtypes.c b/lib/memtypes.c index d9a1a623..5a685e0e 100644 --- a/lib/memtypes.c +++ b/lib/memtypes.c @@ -6,7 +6,7 @@ * The script is sensitive to the format (though not whitespace), see * the top of memtypes.awk for more details. * - * $Id: memtypes.c,v 1.10 2005/11/03 11:04:07 paul Exp $ + * $Id: memtypes.c,v 1.11 2006/03/30 14:09:38 paul Exp $ */ #include "zebra.h" @@ -107,6 +107,7 @@ struct memory_list memory_list_bgp[] = { MTYPE_BGP_STATIC, "BGP static" }, { MTYPE_BGP_ADVERTISE_ATTR, "BGP adv attr" }, { MTYPE_BGP_ADVERTISE, "BGP adv" }, + { MTYPE_BGP_SYNCHRONISE, "BGP synchronise" }, { MTYPE_BGP_ADJ_IN, "BGP adj in" }, { MTYPE_BGP_ADJ_OUT, "BGP adj out" }, { 0, NULL }, diff --git a/lib/privs.c b/lib/privs.c index 8ed39f4f..f4117e26 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -249,13 +249,6 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) "but no capabilities supplied\n"); } - if ( !(zprivs_state.caps = cap_init()) ) - { - fprintf (stderr, "privs_init: failed to cap_init, %s\n", - safe_strerror (errno)); - exit (1); - } - /* we have caps, we have no need to ever change back the original user */ if (zprivs_state.zuid) { @@ -267,6 +260,13 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) } } + if ( !(zprivs_state.caps = cap_init()) ) + { + fprintf (stderr, "privs_init: failed to cap_init, %s\n", + safe_strerror (errno)); + exit (1); + } + if ( cap_clear (zprivs_state.caps) ) { fprintf (stderr, "privs_init: failed to cap_clear, %s\n", @@ -483,6 +483,19 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) /* need either valid or empty sets for both p and i.. */ assert (zprivs_state.syscaps_i && zprivs_state.syscaps_p); + /* we have caps, we have no need to ever change back the original user + * change real, effective and saved to the specified user. + */ + if (zprivs_state.zuid) + { + if ( setreuid (zprivs_state.zuid, zprivs_state.zuid) ) + { + fprintf (stderr, "%s: could not setreuid, %s\n", + __func__, safe_strerror (errno)); + exit (1); + } + } + /* set the permitted set */ if (setppriv (PRIV_SET, PRIV_PERMITTED, zprivs_state.syscaps_p)) { @@ -499,17 +512,6 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) exit (1); } - /* we have caps, we have no need to ever change back the original user */ - if (zprivs_state.zuid) - { - if ( setreuid (zprivs_state.zuid, zprivs_state.zuid) ) - { - fprintf (stderr, "%s: could not setreuid, %s\n", - __func__, safe_strerror (errno)); - exit (1); - } - } - /* now clear the effective set and we're ready to go */ if (setppriv (PRIV_SET, PRIV_EFFECTIVE, empty)) { diff --git a/lib/workqueue.c b/lib/workqueue.c index 1fa16ded..a0f48bc8 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -254,8 +254,9 @@ work_queue_run (struct thread *thread) * * Best: starts low, can only increase * - * Granularity: starts at WORK_QUEUE_MIN_GRANULARITY, can be decreased if we run to end of time - * slot, can increase otherwise by a small factor. + * Granularity: starts at WORK_QUEUE_MIN_GRANULARITY, can be decreased + * if we run to end of time slot, can increase otherwise + * by a small factor. * * We could use just the average and save some work, however we want to be * able to adjust quickly to CPU pressure. Average wont shift much if diff --git a/lib/workqueue.h b/lib/workqueue.h index c06f481f..7e0e78ab 100644 --- a/lib/workqueue.h +++ b/lib/workqueue.h @@ -102,9 +102,6 @@ struct work_queue /* private state */ enum work_queue_flags flags; /* user set flag */ - char status; /* internal status */ -#define WQ_STATE_FLOODED (1 << 0) - }; /* User API */ |