On Fri, Dec 12, 2008 at 5:50 PM, (private) HKS <hks.private@gmail.com> wrote:
quoted text > Below is a patch that moves this functionality to ifstated via the -l
> flag. The only known "issue" is that VLAN interfaces report the link
> status of their underlying physical interface, so you'll get messages
> that don't make total sense: "vlan10 up, link up full-duplex"
>
> I also realize that the carp state change logging is a bit redundant,
> but I left it in to keep the overall behavior consistent with ifstated.
>
> Again, feedback welcome.
>
> -HKS
>
>
>
> Index: ifstated/ifstated.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
> retrieving revision 1.33
> diff -u -r1.33 ifstated.c
> --- ifstated/ifstated.c 12 May 2008 19:15:02 -0000 1.33
> +++ ifstated/ifstated.c 12 Dec 2008 20:39:02 -0000
> @@ -29,6 +29,7 @@
> #include <sys/wait.h>
>
> #include <net/if.h>
> +#include <net/if_types.h>
> #include <net/route.h>
> #include <netinet/in.h>
>
> @@ -76,7 +77,7 @@
> {
> extern char *__progname;
>
> - fprintf(stderr, "usage: %s [-dhinv] [-D macro=value] [-f file]\n",
> + fprintf(stderr, "usage: %s [-dhilnv] [-D macro=value] [-f file]\n",
> __progname);
> exit(1);
> }
> @@ -90,7 +91,7 @@
>
> log_init(1);
>
> - while ((ch = getopt(argc, argv, "dD:f:hniv")) != -1) {
> + while ((ch = getopt(argc, argv, "dD:f:hnilv")) != -1) {
> switch (ch) {
> case 'd':
> debug = 1;
> @@ -112,6 +113,9 @@
> case 'i':
> opt_inhibit = 1;
> break;
> + case 'l':
> + opts |= IFSD_OPT_LOGSTATE;
> + break;
> case 'v':
> if (opts & IFSD_OPT_VERBOSE)
> opts |= IFSD_OPT_VERBOSE2;
> @@ -216,6 +220,9 @@
> struct rt_msghdr *rtm = (struct rt_msghdr *)&msg;
> struct if_msghdr ifm;
> int len;
> + char ifname[IF_NAMESIZE];
> + char *s_iflink;
> + int iflink;
>
> len = read(fd, msg, sizeof(msg));
>
> @@ -230,6 +237,59 @@
> return;
>
> memcpy(&ifm, rtm, sizeof(ifm));
> +
> + if (opts & IFSD_OPT_LOGSTATE)
> + {
> + iflink = ifm.ifm_data.ifi_link_state;
> + if_indextoname(ifm.ifm_index,ifname);
> +
> + switch (iflink) {
> + case LINK_STATE_UNKNOWN:
> + switch (ifm.ifm_data.ifi_type) {
> + case IFT_CARP:
> + s_iflink = "state init";
> + break;
> + default:
> + s_iflink = "link unknown";
> + break;
> + }
> + break;
> + case LINK_STATE_DOWN:
> + switch (ifm.ifm_data.ifi_type) {
> + case IFT_CARP:
> + s_iflink = "state backup";
> + break;
> + default:
> + s_iflink = "link down";
> + break;
> + }
> + break;
> + case LINK_STATE_UP:
> + switch (ifm.ifm_data.ifi_type) {
> + case IFT_CARP:
> + s_iflink = "state master";
> + break;
> + default:
> + s_iflink = "link up";
> + break;
> + }
> + break;
> + case LINK_STATE_HALF_DUPLEX:
> + s_iflink = "link up half-duplex";
> + break;
> + case LINK_STATE_FULL_DUPLEX:
> + s_iflink = "link up full-duplex";
> + break;
> + default:
> + s_iflink = "link unknown";
> + break;
> + }
> +
> + log_info("%s %s, %s", ifname,
> + ifm.ifm_flags & IFF_UP ? "up" : "down",
> + s_iflink);
> + }
> +
> scan_ifstate(ifm.ifm_index, ifm.ifm_data.ifi_link_state, 1);
> }
>
> Index: ifstated/ifstated.h
> ===================================================================
> RCS file: /cvs/src/usr.sbin/ifstated/ifstated.h,v
> retrieving revision 1.5
> diff -u -r1.5 ifstated.h
> --- ifstated/ifstated.h 25 Oct 2007 06:03:31 -0000 1.5
> +++ ifstated/ifstated.h 12 Dec 2008 20:39:02 -0000
> @@ -128,6 +128,7 @@
> #define IFSD_OPT_VERBOSE 0x00000001
> #define IFSD_OPT_VERBOSE2 0x00000002
> #define IFSD_OPT_NOACTION 0x00000004
> +#define IFSD_OPT_LOGSTATE 0x00000008
> int maxdepth;
> };
Is there any interest in this? I can simply apply this on my local
source tree, but I'd like to understand why interface state changes
are not considered critical (or at least useful) information.
-HKS