diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-06-20 12:16:49 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-06-20 12:16:49 -0700 |
commit | 8d95ee9f88945ee49932b1a9f7af5abe6048e6e6 (patch) | |
tree | f8e32626b815d715d6a82d96f848402d83da111b | |
parent | 13807d02a1bd95c2eab32bfa2102e902c61dcb06 (diff) | |
download | quagga-8d95ee9f88945ee49932b1a9f7af5abe6048e6e6.tar.bz2 quagga-8d95ee9f88945ee49932b1a9f7af5abe6048e6e6.tar.xz |
Revert "Backout all changes related to using kernel for linkdetect"
This reverts commit a182091782d22218942466b062c5ef2406853491.
More changes that should NOT go into hollywood
-rwxr-xr-x | configure.ac | 12 | ||||
-rwxr-xr-x | debian/rules | 1 | ||||
-rw-r--r-- | zebra/Makefile.am | 7 | ||||
-rw-r--r-- | zebra/if_linkdetect.c | 92 | ||||
-rw-r--r-- | zebra/interface.c | 13 | ||||
-rw-r--r-- | zebra/interface.h | 17 | ||||
-rw-r--r-- | zebra/linkdetect_null.c | 28 |
7 files changed, 167 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 9f18bd39..1d2b2a3a 100755 --- a/configure.ac +++ b/configure.ac @@ -208,6 +208,8 @@ AC_ARG_ENABLE(bgp-announce, [ --disable-bgp-announce, turn off BGP route announcement]) AC_ARG_ENABLE(netlink, [ --enable-netlink force to use Linux netlink interface]) +AC_ARG_ENABLE(linkdetect, +[ --enable-linkdetect use Linux link-detect configuration]) AC_ARG_ENABLE(broken-aliases, [ --enable-broken-aliases enable aliases as distinct interfaces for Linux 2.2.X]) AC_ARG_ENABLE(snmp, @@ -917,6 +919,16 @@ AC_CHECK_HEADER([net/if.h], QUAGGA_INCLUDES)], [], QUAGGA_INCLUDES ) + +dnl --------------------------------------------------------------- +dnl kernel link-detect enable via /proc/sys/net/ipv4/conf/ethX/link_detect +dnl --------------------------------------------------------------- +if test "${enable_linkdetect}" = "yes"; then + AC_DEFINE(HAVE_LINKDETECT,1,Enable Linux kernel linkdetect) + LINK_DETECT=if_linkdetect.o +fi +AC_SUBST(LINK_DETECT) + dnl ----------------------- dnl check proc file system. dnl ----------------------- diff --git a/debian/rules b/debian/rules index 772d2efa..c5b8cae4 100755 --- a/debian/rules +++ b/debian/rules @@ -61,6 +61,7 @@ configure += --enable-logfile-mask=0640 configure += --enable-rtadv configure += --enable-tcp-md5 configure += --enable-gcc-rdynamic +configure += --enable-linkdetect configure += $(xable_snmp) configure += --with-libpam configure += CFLAGS="$(CFLAGS)" diff --git a/zebra/Makefile.am b/zebra/Makefile.am index 5d8db411..8977c893 100644 --- a/zebra/Makefile.am +++ b/zebra/Makefile.am @@ -10,13 +10,14 @@ LIBCAP = @LIBCAP@ ipforward = @IPFORWARD@ if_method = @IF_METHOD@ if_proc = @IF_PROC@ +link_detect = @LINK_DETECT@ rt_method = @RT_METHOD@ rtread_method = @RTREAD_METHOD@ kernel_method = @KERNEL_METHOD@ other_method = @OTHER_METHOD@ ioctl_method = @IOCTL_METHOD@ -otherobj = $(ioctl_method) $(ipforward) $(if_method) $(if_proc) \ +otherobj = $(ioctl_method) $(ipforward) $(if_method) $(if_proc) $(link_detect) \ $(rt_method) $(rtread_method) $(kernel_method) $(other_method) sbin_PROGRAMS = zebra @@ -29,7 +30,7 @@ zebra_SOURCES = \ irdp_main.c irdp_interface.c irdp_packet.c router-id.c testzebra_SOURCES = test_main.c zebra_rib.c interface.c connected.c debug.c \ - zebra_vty.c \ + zebra_vty.c linkdetect_null.c \ kernel_null.c redistribute_null.c ioctl_null.c misc_null.c noinst_HEADERS = \ @@ -42,7 +43,7 @@ testzebra_LDADD = $(LIBCAP) $(LIB_IPV6) ../lib/libzebra.la zebra_DEPENDENCIES = $(otherobj) -EXTRA_DIST = if_ioctl.c if_ioctl_solaris.c if_netlink.c if_proc.c \ +EXTRA_DIST = if_ioctl.c if_ioctl_solaris.c if_linkdetect.c if_netlink.c if_proc.c \ if_sysctl.c ipforward_aix.c ipforward_ews.c ipforward_proc.c \ ipforward_solaris.c ipforward_sysctl.c rt_ioctl.c rt_netlink.c \ rt_socket.c rtread_netlink.c rtread_proc.c rtread_sysctl.c \ diff --git a/zebra/if_linkdetect.c b/zebra/if_linkdetect.c new file mode 100644 index 00000000..4f95c16e --- /dev/null +++ b/zebra/if_linkdetect.c @@ -0,0 +1,92 @@ +/* Interface link state tracking + * Copyright (C) 2008 Stephen Hemminger + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Zebra; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include <zebra.h> +#include "log.h" +#include "privs.h" +#include "prefix.h" + +#include "zebra/interface.h" + +extern struct zebra_privs_t zserv_privs; + +static int +linkdetect (const char *name, const char *ver, int onoff) +{ + FILE *fp; + int save_errno; + char proc_name[128]; + + snprintf(proc_name, sizeof(proc_name)-1, + "/proc/sys/net/%s/conf/%s/link_detect", ver, name); + + if ( zserv_privs.change(ZPRIVS_RAISE) ) + zlog_err ("Can't raise privileges, %s", safe_strerror (errno) ); + + fp = fopen (proc_name, "w"); + save_errno = errno; + if (!fp) + { + if ( zserv_privs.change(ZPRIVS_LOWER) ) + zlog_err ("Can't lower privileges, %s", safe_strerror (errno)); + + zlog_info("Can't %s link-detect, %s:%s", + onoff ? "enable" : "disable", + proc_name, safe_strerror(save_errno)); + return -1; + } + else + { + fprintf (fp, "%d\n", onoff); + fclose (fp); + + if ( zserv_privs.change(ZPRIVS_LOWER) ) + zlog_err ("Can't lower privileges, %s", safe_strerror (errno)); + + return onoff; + } +} + +int +if_linkdetect_on (const char *name) +{ + return linkdetect (name, "ipv4", 1); +} + +int +if_linkdetect_off (const char *name) +{ + return linkdetect (name, "ipv4", 0); +} + +#ifdef HAVE_IPV6 +int +if_linkdetect_ipv6_on (const char *name) +{ + return linkdetect (name, "ipv6", 1); +} + +int +if_linkdetect_ipv6_off (const char *name) +{ + return linkdetect (name, "ipv6", 0); +} +#endif diff --git a/zebra/interface.c b/zebra/interface.c index ce506056..916c58a6 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -32,6 +32,7 @@ #include "connected.h" #include "log.h" #include "zclient.h" +#include "ipforward.h" #include "zebra/interface.h" #include "zebra/rtadv.h" @@ -1031,6 +1032,12 @@ DEFUN (linkdetect, if_was_operative = if_is_operative(ifp); SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); + /* Enable FIB to remove kernel routes as well */ + if_linkdetect_on(ifp->name); +#ifdef HAVE_IPV6 + if_linkdetect_ipv6_on(ifp->name); +#endif + /* When linkdetection is enabled, if might come down */ if (!if_is_operative(ifp) && if_was_operative) if_down(ifp); @@ -1054,6 +1061,12 @@ DEFUN (no_linkdetect, if_was_operative = if_is_operative(ifp); UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); + /* Disable FIB update on link-detect */ + if_linkdetect_off(ifp->name); +#ifdef HAVE_IPV6 + if_linkdetect_ipv6_off(ifp->name); +#endif + /* Interface may come up after disabling link detection */ if (if_is_operative(ifp) && !if_was_operative) if_up(ifp); diff --git a/zebra/interface.h b/zebra/interface.h index 0a6b0365..114270e7 100644 --- a/zebra/interface.h +++ b/zebra/interface.h @@ -234,6 +234,23 @@ extern int interface_list_proc (void); extern int ifaddr_proc_ipv6 (void); #endif /* HAVE_PROC_NET_IF_INET6 */ +#ifdef HAVE_LINKDETECT +extern int if_linkdetect_on (const char *); +extern int if_linkdetect_off (const char *); +# ifdef HAVE_IPV6 +extern int if_linkdetect_ipv6_on (const char *); +extern int if_linkdetect_ipv6_off (const char *); +# endif +#else +#define if_linkdetect_on(name) +#define if_linkdetect_off(name) +# ifdef HAVE_IPV6 +#define if_linkdetect_ipv6_on(name) +#define if_linkdetect_ipv6_off(name) +# endif +#endif + + #ifdef BSDI extern int if_kvm_get_mtu (struct interface *); #endif /* BSDI */ diff --git a/zebra/linkdetect_null.c b/zebra/linkdetect_null.c new file mode 100644 index 00000000..1f160c8e --- /dev/null +++ b/zebra/linkdetect_null.c @@ -0,0 +1,28 @@ +/* NULL method for testing. */ + +#include <zebra.h> + + +int +if_linkdetect_on (const char *name) +{ + return 0; +} + +int +if_linkdetect_off (const char *name) +{ + return 0; +} + +int +if_linkdetect_ipv6_on (const char *name) +{ + return 0; +} + +int +if_linkdetect_ipv6_off (const char *name) +{ + return 0; +} |