diff options
Diffstat (limited to 'ripngd')
-rw-r--r-- | ripngd/.cvsignore | 7 | ||||
-rw-r--r-- | ripngd/ChangeLog | 216 | ||||
-rw-r--r-- | ripngd/Makefile.am | 37 | ||||
-rw-r--r-- | ripngd/Makefile.in | 487 | ||||
-rw-r--r-- | ripngd/ripng_debug.c | 292 | ||||
-rw-r--r-- | ripngd/ripng_debug.h | 52 | ||||
-rw-r--r-- | ripngd/ripng_interface.c | 835 | ||||
-rw-r--r-- | ripngd/ripng_main.c | 252 | ||||
-rw-r--r-- | ripngd/ripng_route.c | 157 | ||||
-rw-r--r-- | ripngd/ripng_route.h | 53 | ||||
-rw-r--r-- | ripngd/ripng_routemap.c | 342 | ||||
-rw-r--r-- | ripngd/ripng_zebra.c | 877 | ||||
-rw-r--r-- | ripngd/ripngd.c | 2526 | ||||
-rw-r--r-- | ripngd/ripngd.conf.sample | 22 | ||||
-rw-r--r-- | ripngd/ripngd.h | 318 |
15 files changed, 6473 insertions, 0 deletions
diff --git a/ripngd/.cvsignore b/ripngd/.cvsignore new file mode 100644 index 00000000..cd9e0832 --- /dev/null +++ b/ripngd/.cvsignore @@ -0,0 +1,7 @@ +Makefile +*.o +ripngd +ripngd.conf +tags +TAGS +.deps diff --git a/ripngd/ChangeLog b/ripngd/ChangeLog new file mode 100644 index 00000000..07e3d761 --- /dev/null +++ b/ripngd/ChangeLog @@ -0,0 +1,216 @@ +2002-07-07 Kunihiro Ishiguro <kunihiro@ipinfusion.com> + + * zebra-0.93 released. + +2001-08-28 NOGUCHI Kay <kay@v6.access.co.jp> + + * ripngd.c (no_ripng_route): route_unlock_node () is not needed. + +2001-08-26 NOGUCHI Kay <kay@v6.access.co.jp> + + * ripngd.h (struct ripng_interface): Add passive interface option. + +2001-08-19 Kunihiro Ishiguro <kunihiro@ipinfusion.com> + + * zebra-0.92a released. + +2001-08-15 Kunihiro Ishiguro <kunihiro@ipinfusion.com> + + * zebra-0.92 released. + +2001-08-07 Akira Kato <kato@wide.ad.jp> + + * ripngd.c (ripng_timers): "timers basic" argument is fixed. + +2001-02-01 Kunihiro Ishiguro <kunihiro@zebra.org> + + * zebra-0.91 is released. + +2001-01-09 Kunihiro Ishiguro <kunihiro@zebra.org> + + * zebra-0.90 is released. + +2001-01-01 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.h (RIPNG_VTYSH_PATH): Change "/tmp/ripngd" to + "/tmp/.ripngd". + +2000-10-02 Kunihiro Ishiguro <kunihiro@zebra.org> + + * zebra-0.89 is released. + +2000-09-20 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_send_packet): Use CMSG_SPACE instead of sizeof + hack. Revert privious alignment patch. + +2000-09-20 URA Hiroshi <ura@hiru.aoba.yokohama.jp> + + * ripngd.c (ripng_send_packet): Fix an alignment bug. Thus ripngd + can't send packets. + +2000-09-10 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripng_interface.c (ripng_interface_address_delete): Connected + address delete treatment added. + +2000-08-22 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripng_routemap.c (route_set_metric_compile): When checking '-' + character, argv[1] should be argv[0]. Reported by SHIRASAKI + Yasuhiro <yasuhiro@ocn.v6.ntt.net>. + +2000-08-17 Kunihiro Ishiguro <kunihiro@zebra.org> + + * zebra-0.88 is released. + +2000-06-06 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_route_process): Clear prefix_ipv6 before using + it. + (ripng_redistribute_delete): Fix bug of missing + route_unlock_node() when redistribute route is not found. + (ripng_redistribute_delete): Make it sure that timers are off. + (ripng_redistribute_delete): Likewise. + +2000-01-19 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_route_process): Fix bug of mis-checking of same + route. + (show_ipv6_ripng): Include ifindex to "show ipv6 ripng" output. + +1999-11-12 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_output_process): Use MINMTU when mtu value is + not available. + +1999-11-05 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_output_process): Calculate max RTE count from + interface MTU value. + +1999-09-29 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_distribute_update): Fix bug of updating + access-list and prefix-list. + +1999-09-07 URA Hiroshi <ura@hiru.aoba.yokohama.jp> + + * ripngd.c (ripng_recv_packet): Change CMSG_DATA cast from (u_char + *) to (int *). (u_char *) does not work for NetBSD-currnet on + SparcStation 10. + +1999-08-15 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_request_process): When request packet comes, + check RIPng process is enabled on the interface. + (ripng_redistribute_withdraw): Delete routes when `no + redistribute' is executed. + +1999-08-13 Yasuhiro Ohara <yasu@sfc.wide.ad.jp> + + * ripng_zebra.c (ripng_redistribute_ospf6_cmd): Add OSPF6 + redistribute command. + +1999-07-21 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (default_information_originate): Add + default-information command. + +1999-07-19 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_route_process): rip_add_route() and + rip_delete_route() are deleted. Both functions are integrated + into ripng_route_process(). + (ripng_request_process): Proper reply for request message. + + * ripng_routemap.c: New file added. + +1999-07-18 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_nexthop_rte): RIPng next hop routine is + rewritten. + (show_ipv6_ripng): Change `show ip ripng' to `show ipv6 ripng'. + (ripng_response_process): RIPng incoming packet's hop count check + added. + (ripng_response_process): Add strict RTE checking. + +1999-07-03 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_add_route): Fix metric compare bug. + +1999-06-25 itojun@iijlab.net + + * ripngd.c (ripng_distribute_in): "distribute in" filter in ripngd + actually work. + +1999-05-25 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_zebra): Send each ripng information by separate + zebra packet. + +1999-05-15 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripng_interface.c (if_add_multicast): Change log to zlog. + +1999-05-10 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripng_interface.c (ripng_zebra_get_interface): Add function. + + * ripng_zebra.c (redistribute_ripng): Delete function because + redistirbute the routes to the zebra daemon is now default + behavior. + +1999-05-09 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.conf.sample: Change network to route statement. + +1999-03-25 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c: Old non Advanced API version ripng_send_packet and + ripng_recv_packet is removed. + * ripng_radix.c: File removed. + +1998-12-15 Kunihiro Ishiguro <kunihiro@zebra.org> + + * Now I assume KAME support Advanced API and use sendmsg/recvmsg. + +1998-12-13 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripng_interface.c: Delete old ifa (interface address) related + functions. + +1998-12-10 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripng_debug.[ch]: New file. + + * ripngd.c (ripng_supply): Do not send header only RIPng packet. + Change `network' statement to `route' statement. + (ripng_request_process): Reply to RIPng REQUEST packet. + +1998-12-09 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripngd.c (ripng_config_write): Delete vector v argument. + * ripng_zebra.c (zebra_config_write): Likewise. + * ripng_interface.c (interface_config_write): Likewise. + +1998-12-07 Kunihiro Ishiguro <kunihiro@zebra.org> + + * ripng_route.h: New file. + + * ripng_interface.c: Delete #include <linux/in6.h>. + ripng_main.c: likewise. + ripng_radix.c: likewise. + ripng_route.c: likewise. + ripng_zebra.c: likewise. + ripngd.c: likewise. + +1998-12-06 Yasuhiro Ohara <yasu@sfc.wide.ad.jp> + + * ripngd.h (IPV6_ADD_MEMBERSHIP): If IPV6_ADD_MEMBERSHIP is not + defined. Define IPV6_ADD_MEMBERSHIP as IPV6_JOIN_GROUP. + +1998-09-15 HEO SeonMeyong <seirios@matrix.iri.co.jp> + + * all Hydrangea define is changed to KAME. + diff --git a/ripngd/Makefile.am b/ripngd/Makefile.am new file mode 100644 index 00000000..2835aa24 --- /dev/null +++ b/ripngd/Makefile.am @@ -0,0 +1,37 @@ +## Process this file with automake to produce Makefile.in. + +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib +DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" +INSTALL_SDATA=@INSTALL@ -m 600 + +noinst_LIBRARIES = libripng.a +sbin_PROGRAMS = ripngd + +libripng_a_SOURCES = \ + ripng_interface.c ripngd.c ripng_zebra.c ripng_route.c ripng_debug.c \ + ripng_routemap.c + +noinst_HEADERS = \ + ripng_debug.h ripng_route.h ripngd.h + +ripngd_SOURCES = \ + ripng_main.c $(libripng_a_SOURCES) + +ripngd_LDADD = ../lib/libzebra.a + +sysconf_DATA = ripngd.conf.sample + +EXTRA_DIST = $(sysconf_DATA) + +install-sysconfDATA: $(sysconf_DATA) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(sysconfdir) + @list='$(sysconf_DATA)'; for p in $$list; do \ + if test -f $(srcdir)/$$p; then \ + echo " $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p"; \ + $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p; \ + else if test -f $$p; then \ + echo " $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p"; \ + $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p; \ + fi; fi; \ + done diff --git a/ripngd/Makefile.in b/ripngd/Makefile.in new file mode 100644 index 00000000..61e0df21 --- /dev/null +++ b/ripngd/Makefile.in @@ -0,0 +1,487 @@ +# Makefile.in generated by automake 1.7 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 +# Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BGPD = @BGPD@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CURSES = @CURSES@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +IF_METHOD = @IF_METHOD@ +IF_PROC = @IF_PROC@ + +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +IPFORWARD = @IPFORWARD@ +KERNEL_METHOD = @KERNEL_METHOD@ +LDFLAGS = @LDFLAGS@ +LIBPAM = @LIBPAM@ +LIBS = @LIBS@ +LIB_IPV6 = @LIB_IPV6@ +LIB_REGEX = @LIB_REGEX@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MULTIPATH_NUM = @MULTIPATH_NUM@ +OBJEXT = @OBJEXT@ +OSPF6D = @OSPF6D@ +OSPFD = @OSPFD@ +OTHER_METHOD = @OTHER_METHOD@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +RIPD = @RIPD@ +RIPNGD = @RIPNGD@ +RTREAD_METHOD = @RTREAD_METHOD@ +RT_METHOD = @RT_METHOD@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +VTYSH = @VTYSH@ +ZEBRA = @ZEBRA@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__include = @am__include@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +INSTALL_SDATA = @INSTALL@ -m 600 + +noinst_LIBRARIES = libripng.a +sbin_PROGRAMS = ripngd + +libripng_a_SOURCES = \ + ripng_interface.c ripngd.c ripng_zebra.c ripng_route.c ripng_debug.c \ + ripng_routemap.c + + +noinst_HEADERS = \ + ripng_debug.h ripng_route.h ripngd.h + + +ripngd_SOURCES = \ + ripng_main.c $(libripng_a_SOURCES) + + +ripngd_LDADD = ../lib/libzebra.a + +sysconf_DATA = ripngd.conf.sample + +EXTRA_DIST = $(sysconf_DATA) +subdir = ripngd +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LIBRARIES = $(noinst_LIBRARIES) + +libripng_a_AR = $(AR) cru +libripng_a_LIBADD = +am_libripng_a_OBJECTS = ripng_interface.$(OBJEXT) ripngd.$(OBJEXT) \ + ripng_zebra.$(OBJEXT) ripng_route.$(OBJEXT) \ + ripng_debug.$(OBJEXT) ripng_routemap.$(OBJEXT) +libripng_a_OBJECTS = $(am_libripng_a_OBJECTS) +sbin_PROGRAMS = ripngd$(EXEEXT) +PROGRAMS = $(sbin_PROGRAMS) + +am__objects_1 = ripng_interface.$(OBJEXT) ripngd.$(OBJEXT) \ + ripng_zebra.$(OBJEXT) ripng_route.$(OBJEXT) \ + ripng_debug.$(OBJEXT) ripng_routemap.$(OBJEXT) +am_ripngd_OBJECTS = ripng_main.$(OBJEXT) $(am__objects_1) +ripngd_OBJECTS = $(am_ripngd_OBJECTS) +ripngd_DEPENDENCIES = ../lib/libzebra.a +ripngd_LDFLAGS = + +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/ripng_debug.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/ripng_interface.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/ripng_main.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/ripng_route.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/ripng_routemap.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/ripng_zebra.Po ./$(DEPDIR)/ripngd.Po +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +DIST_SOURCES = $(libripng_a_SOURCES) $(ripngd_SOURCES) +DATA = $(sysconf_DATA) + +HEADERS = $(noinst_HEADERS) + +DIST_COMMON = $(noinst_HEADERS) ChangeLog Makefile.am Makefile.in +SOURCES = $(libripng_a_SOURCES) $(ripngd_SOURCES) + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign ripngd/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) +libripng.a: $(libripng_a_OBJECTS) $(libripng_a_DEPENDENCIES) + -rm -f libripng.a + $(libripng_a_AR) libripng.a $(libripng_a_OBJECTS) $(libripng_a_LIBADD) + $(RANLIB) libripng.a +sbinPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +install-sbinPROGRAMS: $(sbin_PROGRAMS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(sbindir) + @list='$(sbin_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + ; then \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(sbinPROGRAMS_INSTALL) $$p $(DESTDIR)$(sbindir)/$$f"; \ + $(INSTALL_PROGRAM_ENV) $(sbinPROGRAMS_INSTALL) $$p $(DESTDIR)$(sbindir)/$$f || exit 1; \ + else :; fi; \ + done + +uninstall-sbinPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(sbin_PROGRAMS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f $(DESTDIR)$(sbindir)/$$f"; \ + rm -f $(DESTDIR)$(sbindir)/$$f; \ + done + +clean-sbinPROGRAMS: + -test -z "$(sbin_PROGRAMS)" || rm -f $(sbin_PROGRAMS) +ripngd$(EXEEXT): $(ripngd_OBJECTS) $(ripngd_DEPENDENCIES) + @rm -f ripngd$(EXEEXT) + $(LINK) $(ripngd_LDFLAGS) $(ripngd_OBJECTS) $(ripngd_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) core *.core + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ripng_debug.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ripng_interface.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ripng_main.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ripng_route.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ripng_routemap.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ripng_zebra.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ripngd.Po@am__quote@ + +distclean-depend: + -rm -rf ./$(DEPDIR) + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ +@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \ +@am__fastdepCC_TRUE@ then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \ +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ +@am__fastdepCC_TRUE@ fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ +@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'`; \ +@am__fastdepCC_TRUE@ then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \ +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ +@am__fastdepCC_TRUE@ fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'` +uninstall-info-am: +sysconfDATA_INSTALL = $(INSTALL_DATA) + +uninstall-sysconfDATA: + @$(NORMAL_UNINSTALL) + @list='$(sysconf_DATA)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f $(DESTDIR)$(sysconfdir)/$$f"; \ + rm -f $(DESTDIR)$(sysconfdir)/$$f; \ + done + +ETAGS = etags +ETAGSFLAGS = + +CTAGS = ctags +CTAGSFLAGS = + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique + +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkinstalldirs) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(DATA) $(HEADERS) + +installdirs: + $(mkinstalldirs) $(DESTDIR)$(sbindir) $(DESTDIR)$(sysconfdir) + +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-noinstLIBRARIES clean-sbinPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + +distclean-am: clean-am distclean-compile distclean-depend \ + distclean-generic distclean-tags + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: install-sbinPROGRAMS install-sysconfDATA + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am uninstall-sbinPROGRAMS \ + uninstall-sysconfDATA + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-noinstLIBRARIES clean-sbinPROGRAMS ctags distclean \ + distclean-compile distclean-depend distclean-generic \ + distclean-tags distdir dvi dvi-am info info-am install \ + install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-sbinPROGRAMS install-strip install-sysconfDATA \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-info-am uninstall-sbinPROGRAMS \ + uninstall-sysconfDATA + + +install-sysconfDATA: $(sysconf_DATA) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(sysconfdir) + @list='$(sysconf_DATA)'; for p in $$list; do \ + if test -f $(srcdir)/$$p; then \ + echo " $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p"; \ + $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p; \ + else if test -f $$p; then \ + echo " $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p"; \ + $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p; \ + fi; fi; \ + done +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/ripngd/ripng_debug.c b/ripngd/ripng_debug.c new file mode 100644 index 00000000..51314bc2 --- /dev/null +++ b/ripngd/ripng_debug.c @@ -0,0 +1,292 @@ +/* + * RIPng debug output routines + * Copyright (C) 1998 Kunihiro Ishiguro + * + * 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 "command.h" +#include "ripngd/ripng_debug.h" + +/* For debug statement. */ +unsigned long ripng_debug_event = 0; +unsigned long ripng_debug_packet = 0; +unsigned long ripng_debug_zebra = 0; + +DEFUN (show_debugging_ripng, + show_debugging_ripng_cmd, + "show debugging ripng", + SHOW_STR + "RIPng configuration\n" + "Debugging information\n") +{ + vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE); + + if (IS_RIPNG_DEBUG_EVENT) + vty_out (vty, " RIPng event debugging is on%s", VTY_NEWLINE); + + if (IS_RIPNG_DEBUG_PACKET) + { + if (IS_RIPNG_DEBUG_SEND && IS_RIPNG_DEBUG_RECV) + { + vty_out (vty, " RIPng packet%s debugging is on%s", + IS_RIPNG_DEBUG_DETAIL ? " detail" : "", + VTY_NEWLINE); + } + else + { + if (IS_RIPNG_DEBUG_SEND) + vty_out (vty, " RIPng packet send%s debugging is on%s", + IS_RIPNG_DEBUG_DETAIL ? " detail" : "", + VTY_NEWLINE); + else + vty_out (vty, " RIPng packet receive%s debugging is on%s", + IS_RIPNG_DEBUG_DETAIL ? " detail" : "", + VTY_NEWLINE); + } + } + + if (IS_RIPNG_DEBUG_ZEBRA) + vty_out (vty, " RIPng zebra debugging is on%s", VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN (debug_ripng_events, + debug_ripng_events_cmd, + "debug ripng events", + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng events\n") +{ + ripng_debug_event = RIPNG_DEBUG_EVENT; + return CMD_WARNING; +} + +DEFUN (debug_ripng_packet, + debug_ripng_packet_cmd, + "debug ripng packet", + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng packet\n") +{ + ripng_debug_packet = RIPNG_DEBUG_PACKET; + ripng_debug_packet |= RIPNG_DEBUG_SEND; + ripng_debug_packet |= RIPNG_DEBUG_RECV; + return CMD_SUCCESS; +} + +DEFUN (debug_ripng_packet_direct, + debug_ripng_packet_direct_cmd, + "debug ripng packet (recv|send)", + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng packet\n" + "Debug option set for receive packet\n" + "Debug option set for send packet\n") +{ + ripng_debug_packet |= RIPNG_DEBUG_PACKET; + if (strncmp ("send", argv[0], strlen (argv[0])) == 0) + ripng_debug_packet |= RIPNG_DEBUG_SEND; + if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) + ripng_debug_packet |= RIPNG_DEBUG_RECV; + ripng_debug_packet &= ~RIPNG_DEBUG_DETAIL; + return CMD_SUCCESS; +} + +DEFUN (debug_ripng_packet_detail, + debug_ripng_packet_detail_cmd, + "debug ripng packet (recv|send) detail", + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng packet\n" + "Debug option set for receive packet\n" + "Debug option set for send packet\n" + "Debug option set detaied information\n") +{ + ripng_debug_packet |= RIPNG_DEBUG_PACKET; + if (strncmp ("send", argv[0], strlen (argv[0])) == 0) + ripng_debug_packet |= RIPNG_DEBUG_SEND; + if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) + ripng_debug_packet |= RIPNG_DEBUG_RECV; + ripng_debug_packet |= RIPNG_DEBUG_DETAIL; + return CMD_SUCCESS; +} + +DEFUN (debug_ripng_zebra, + debug_ripng_zebra_cmd, + "debug ripng zebra", + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng and zebra communication\n") +{ + ripng_debug_zebra = RIPNG_DEBUG_ZEBRA; + return CMD_WARNING; +} + +DEFUN (no_debug_ripng_events, + no_debug_ripng_events_cmd, + "no debug ripng events", + NO_STR + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng events\n") +{ + ripng_debug_event = 0; + return CMD_SUCCESS; +} + +DEFUN (no_debug_ripng_packet, + no_debug_ripng_packet_cmd, + "no debug ripng packet", + NO_STR + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng packet\n") +{ + ripng_debug_packet = 0; + return CMD_SUCCESS; +} + +DEFUN (no_debug_ripng_packet_direct, + no_debug_ripng_packet_direct_cmd, + "no debug ripng packet (recv|send)", + NO_STR + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng packet\n" + "Debug option set for receive packet\n" + "Debug option set for send packet\n") +{ + if (strncmp ("send", argv[0], strlen (argv[0])) == 0) + { + if (IS_RIPNG_DEBUG_RECV) + ripng_debug_packet &= ~RIPNG_DEBUG_SEND; + else + ripng_debug_packet = 0; + } + else if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) + { + if (IS_RIPNG_DEBUG_SEND) + ripng_debug_packet &= ~RIPNG_DEBUG_RECV; + else + ripng_debug_packet = 0; + } + return CMD_SUCCESS; +} + +DEFUN (no_debug_ripng_zebra, + no_debug_ripng_zebra_cmd, + "no debug ripng zebra", + NO_STR + DEBUG_STR + "RIPng configuration\n" + "Debug option set for ripng and zebra communication\n") +{ + ripng_debug_zebra = 0; + return CMD_WARNING; +} + +/* Debug node. */ +struct cmd_node debug_node = +{ + DEBUG_NODE, + "" /* Debug node has no interface. */ +}; + +int +config_write_debug (struct vty *vty) +{ + int write = 0; + + if (IS_RIPNG_DEBUG_EVENT) + { + vty_out (vty, "debug ripng events%s", VTY_NEWLINE); + write++; + } + if (IS_RIPNG_DEBUG_PACKET) + { + if (IS_RIPNG_DEBUG_SEND && IS_RIPNG_DEBUG_RECV) + { + vty_out (vty, "debug ripng packet%s%s", + IS_RIPNG_DEBUG_DETAIL ? " detail" : "", + VTY_NEWLINE); + write++; + } + else + { + if (IS_RIPNG_DEBUG_SEND) + vty_out (vty, "debug ripng packet send%s%s", + IS_RIPNG_DEBUG_DETAIL ? " detail" : "", + VTY_NEWLINE); + else + vty_out (vty, "debug ripng packet recv%s%s", + IS_RIPNG_DEBUG_DETAIL ? " detail" : "", + VTY_NEWLINE); + write++; + } + } + if (IS_RIPNG_DEBUG_ZEBRA) + { + vty_out (vty, "debug ripng zebra%s", VTY_NEWLINE); + write++; + } + return write; +} + +void +ripng_debug_reset () +{ + ripng_debug_event = 0; + ripng_debug_packet = 0; + ripng_debug_zebra = 0; +} + +void +ripng_debug_init () +{ + ripng_debug_event = 0; + ripng_debug_packet = 0; + ripng_debug_zebra = 0; + + install_node (&debug_node, config_write_debug); + + install_element (VIEW_NODE, &show_debugging_ripng_cmd); + + install_element (ENABLE_NODE, &show_debugging_ripng_cmd); + install_element (ENABLE_NODE, &debug_ripng_events_cmd); + install_element (ENABLE_NODE, &debug_ripng_packet_cmd); + install_element (ENABLE_NODE, &debug_ripng_packet_direct_cmd); + install_element (ENABLE_NODE, &debug_ripng_packet_detail_cmd); + install_element (ENABLE_NODE, &debug_ripng_zebra_cmd); + install_element (ENABLE_NODE, &no_debug_ripng_events_cmd); + install_element (ENABLE_NODE, &no_debug_ripng_packet_cmd); + install_element (ENABLE_NODE, &no_debug_ripng_packet_direct_cmd); + install_element (ENABLE_NODE, &no_debug_ripng_zebra_cmd); + + install_element (CONFIG_NODE, &debug_ripng_events_cmd); + install_element (CONFIG_NODE, &debug_ripng_packet_cmd); + install_element (CONFIG_NODE, &debug_ripng_packet_direct_cmd); + install_element (CONFIG_NODE, &debug_ripng_packet_detail_cmd); + install_element (CONFIG_NODE, &debug_ripng_zebra_cmd); + install_element (CONFIG_NODE, &no_debug_ripng_events_cmd); + install_element (CONFIG_NODE, &no_debug_ripng_packet_cmd); + install_element (CONFIG_NODE, &no_debug_ripng_packet_direct_cmd); + install_element (CONFIG_NODE, &no_debug_ripng_zebra_cmd); +} diff --git a/ripngd/ripng_debug.h b/ripngd/ripng_debug.h new file mode 100644 index 00000000..6713a151 --- /dev/null +++ b/ripngd/ripng_debug.h @@ -0,0 +1,52 @@ +/* + * RIPng debug output routines + * Copyright (C) 1998, 1999 Kunihiro Ishiguro + * + * 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. + */ + +#ifndef _ZEBRA_RIPNG_DEBUG_H +#define _ZEBRA_RIPNG_DEBUG_H + +/* Debug flags. */ +#define RIPNG_DEBUG_EVENT 0x01 + +#define RIPNG_DEBUG_PACKET 0x01 +#define RIPNG_DEBUG_SEND 0x20 +#define RIPNG_DEBUG_RECV 0x40 +#define RIPNG_DEBUG_DETAIL 0x80 + +#define RIPNG_DEBUG_ZEBRA 0x01 + +/* Debug related macro. */ +#define IS_RIPNG_DEBUG_EVENT (ripng_debug_event & RIPNG_DEBUG_EVENT) + +#define IS_RIPNG_DEBUG_PACKET (ripng_debug_packet & RIPNG_DEBUG_PACKET) +#define IS_RIPNG_DEBUG_SEND (ripng_debug_packet & RIPNG_DEBUG_SEND) +#define IS_RIPNG_DEBUG_RECV (ripng_debug_packet & RIPNG_DEBUG_RECV) +#define IS_RIPNG_DEBUG_DETAIL (ripng_debug_packet & RIPNG_DEBUG_DETAIL) + +#define IS_RIPNG_DEBUG_ZEBRA (ripng_debug_zebra & RIPNG_DEBUG_ZEBRA) + +extern unsigned long ripng_debug_event; +extern unsigned long ripng_debug_packet; +extern unsigned long ripng_debug_zebra; + +void ripng_debug_init (); + +#endif /* _ZEBRA_RIPNG_DEBUG_H */ diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c new file mode 100644 index 00000000..c177381a --- /dev/null +++ b/ripngd/ripng_interface.c @@ -0,0 +1,835 @@ +/* + * Interface related function for RIPng. + * Copyright (C) 1998 Kunihiro Ishiguro + * + * 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 "linklist.h" +#include "if.h" +#include "prefix.h" +#include "memory.h" +#include "network.h" +#include "filter.h" +#include "log.h" +#include "stream.h" +#include "zclient.h" +#include "command.h" +#include "table.h" +#include "thread.h" + +#include "ripngd/ripngd.h" +#include "ripngd/ripng_debug.h" + +/* If RFC2133 definition is used. */ +#ifndef IPV6_JOIN_GROUP +#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP +#endif +#ifndef IPV6_LEAVE_GROUP +#define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP +#endif + +/* Static utility function. */ +static void ripng_enable_apply (struct interface *); +static void ripng_passive_interface_apply (struct interface *); + +/* Join to the all rip routers multicast group. */ +int +ripng_multicast_join (struct interface *ifp) +{ + int ret; + struct ipv6_mreq mreq; + + memset (&mreq, 0, sizeof (mreq)); + inet_pton(AF_INET6, RIPNG_GROUP, &mreq.ipv6mr_multiaddr); + mreq.ipv6mr_interface = ifp->ifindex; + + ret = setsockopt (ripng->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, + (char *) &mreq, sizeof (mreq)); + if (ret < 0) + zlog_warn ("can't setsockopt IPV6_JOIN_GROUP: %s", strerror (errno)); + + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng %s join to all-rip-routers multicast group", ifp->name); + + return ret; +} + +/* Leave from the all rip routers multicast group. */ +int +ripng_multicast_leave (struct interface *ifp) +{ + int ret; + struct ipv6_mreq mreq; + + memset (&mreq, 0, sizeof (mreq)); + inet_pton(AF_INET6, RIPNG_GROUP, &mreq.ipv6mr_multiaddr); + mreq.ipv6mr_interface = ifp->ifindex; + + ret = setsockopt (ripng->sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP, + (char *) &mreq, sizeof (mreq)); + if (ret < 0) + zlog_warn ("can't setsockopt IPV6_LEAVE_GROUP: %s\n", strerror (errno)); + + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng %s leave from all-rip-routers multicast group", + ifp->name); + + return ret; +} + +/* Check max mtu size. */ +int +ripng_check_max_mtu () +{ + listnode node; + struct interface *ifp; + int mtu; + + mtu = 0; + for (node = listhead (iflist); node; nextnode (node)) + { + ifp = getdata (node); + if (mtu < ifp->mtu) + mtu = ifp->mtu; + } + return mtu; +} + +int +ripng_if_down (struct interface *ifp) +{ + struct route_node *rp; + struct ripng_info *rinfo; + struct ripng_interface *ri; + + if (ripng->table) + { + for (rp = route_top (ripng->table); rp; rp = route_next (rp)) + if ((rinfo = rp->info) != NULL) + { + /* Routes got through this interface. */ + if (rinfo->ifindex == ifp->ifindex + && rinfo->type == ZEBRA_ROUTE_RIPNG + && rinfo->sub_type == RIPNG_ROUTE_RTE) + { + ripng_zebra_ipv6_delete ((struct prefix_ipv6 *) &rp->p, + &rinfo->nexthop, + rinfo->ifindex); + + RIPNG_TIMER_OFF (rinfo->t_timeout); + RIPNG_TIMER_OFF (rinfo->t_garbage_collect); + + rp->info = NULL; + route_unlock_node (rp); + + ripng_info_free (rinfo); + } + else + { + /* All redistributed routes got through this interface. */ + if (rinfo->ifindex == ifp->ifindex) + ripng_redistribute_delete (rinfo->type, rinfo->sub_type, + (struct prefix_ipv6 *) &rp->p, + rinfo->ifindex); + } + } + } + + ri = ifp->info; + + if (ripng && ri->running) + { + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("turn off %s", ifp->name); + + /* Leave from multicast group. */ + ripng_multicast_leave (ifp); + + ri->running = 0; + } + + return 0; +} + +/* Inteface link up message processing. */ +int +ripng_interface_up (int command, struct zclient *zclient, zebra_size_t length) +{ + struct stream *s; + struct interface *ifp; + + /* zebra_interface_state_read() updates interface structure in iflist. */ + s = zclient->ibuf; + ifp = zebra_interface_state_read (s); + + if (ifp == NULL) + return 0; + + if (IS_RIPNG_DEBUG_ZEBRA) + zlog_info ("interface up %s index %d flags %ld metric %d mtu %d", + ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); + + /* Check if this interface is RIPng enabled or not. */ + ripng_enable_apply (ifp); + + /* Check for a passive interface. */ + ripng_passive_interface_apply (ifp); + + /* Apply distribute list to the all interface. */ + ripng_distribute_update_interface (ifp); + + return 0; +} + +/* Inteface link down message processing. */ +int +ripng_interface_down (int command, struct zclient *zclient, + zebra_size_t length) +{ + struct stream *s; + struct interface *ifp; + + /* zebra_interface_state_read() updates interface structure in iflist. */ + s = zclient->ibuf; + ifp = zebra_interface_state_read (s); + + if (ifp == NULL) + return 0; + + ripng_if_down (ifp); + + if (IS_RIPNG_DEBUG_ZEBRA) + zlog_info ("interface down %s index %d flags %ld metric %d mtu %d", + ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); + + return 0; +} + +/* Inteface addition message from zebra. */ +int +ripng_interface_add (int command, struct zclient *zclient, zebra_size_t length) +{ + struct interface *ifp; + + ifp = zebra_interface_add_read (zclient->ibuf); + + if (IS_RIPNG_DEBUG_ZEBRA) + zlog_info ("RIPng interface add %s index %d flags %ld metric %d mtu %d", + ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); + + /* Check is this interface is RIP enabled or not.*/ + ripng_enable_apply (ifp); + + /* Apply distribute list to the interface. */ + ripng_distribute_update_interface (ifp); + + /* Check interface routemap. */ + ripng_if_rmap_update_interface (ifp); + + return 0; +} + +int +ripng_interface_delete (int command, struct zclient *zclient, + zebra_size_t length) +{ + return 0; +} + +int +ripng_interface_address_add (int command, struct zclient *zclient, + zebra_size_t length) +{ + struct connected *c; + struct prefix *p; + char buf[INET6_ADDRSTRLEN]; + + c = zebra_interface_address_add_read (zclient->ibuf); + + if (c == NULL) + return 0; + + p = c->address; + + if (p->family == AF_INET6) + { + if (IS_RIPNG_DEBUG_ZEBRA) + zlog_info ("RIPng connected address %s/%d add", + inet_ntop (AF_INET6, &p->u.prefix6, buf, INET6_ADDRSTRLEN), + p->prefixlen); + + /* Check is this interface is RIP enabled or not.*/ + ripng_enable_apply (c->ifp); + } + + return 0; +} + +int +ripng_interface_address_delete (int command, struct zclient *zclient, + zebra_size_t length) +{ + struct connected *ifc; + struct prefix *p; + char buf[INET6_ADDRSTRLEN]; + + ifc = zebra_interface_address_delete_read (zclient->ibuf); + + if (ifc) + { + p = ifc->address; + + if (p->family == AF_INET6) + { + if (IS_RIPNG_DEBUG_ZEBRA) + zlog_info ("RIPng connected address %s/%d delete", + inet_ntop (AF_INET6, &p->u.prefix6, buf, + INET6_ADDRSTRLEN), + p->prefixlen); + + /* Check is this interface is RIP enabled or not.*/ + ripng_enable_apply (ifc->ifp); + } + connected_free (ifc); + } + + return 0; +} + +/* RIPng enable interface vector. */ +vector ripng_enable_if; + +/* RIPng enable network table. */ +struct route_table *ripng_enable_network; + +/* Lookup RIPng enable network. */ +int +ripng_enable_network_lookup (struct interface *ifp) +{ + listnode listnode; + struct connected *connected; + + for (listnode = listhead (ifp->connected); listnode; nextnode (listnode)) + if ((connected = getdata (listnode)) != NULL) + { + struct prefix *p; + struct route_node *node; + + p = connected->address; + + if (p->family == AF_INET6) + { + node = route_node_match (ripng_enable_network, p); + if (node) + { + route_unlock_node (node); + return 1; + } + } + } + return -1; +} + +/* Add RIPng enable network. */ +int +ripng_enable_network_add (struct prefix *p) +{ + struct route_node *node; + + node = route_node_get (ripng_enable_network, p); + + if (node->info) + { + route_unlock_node (node); + return -1; + } + else + node->info = "enabled"; + + return 1; +} + +/* Delete RIPng enable network. */ +int +ripng_enable_network_delete (struct prefix *p) +{ + struct route_node *node; + + node = route_node_lookup (ripng_enable_network, p); + if (node) + { + node->info = NULL; + + /* Unlock info lock. */ + route_unlock_node (node); + + /* Unlock lookup lock. */ + route_unlock_node (node); + + return 1; + } + return -1; +} + +/* Lookup function. */ +int +ripng_enable_if_lookup (char *ifname) +{ + int i; + char *str; + + for (i = 0; i < vector_max (ripng_enable_if); i++) + if ((str = vector_slot (ripng_enable_if, i)) != NULL) + if (strcmp (str, ifname) == 0) + return i; + return -1; +} + +/* Add interface to ripng_enable_if. */ +int +ripng_enable_if_add (char *ifname) +{ + int ret; + + ret = ripng_enable_if_lookup (ifname); + if (ret >= 0) + return -1; + + vector_set (ripng_enable_if, strdup (ifname)); + + return 1; +} + +/* Delete interface from ripng_enable_if. */ +int +ripng_enable_if_delete (char *ifname) +{ + int index; + char *str; + + index = ripng_enable_if_lookup (ifname); + if (index < 0) + return -1; + + str = vector_slot (ripng_enable_if, index); + free (str); + vector_unset (ripng_enable_if, index); + + return 1; +} + +/* Wake up interface. */ +int +ripng_interface_wakeup (struct thread *t) +{ + struct interface *ifp; + struct ripng_interface *ri; + + /* Get interface. */ + ifp = THREAD_ARG (t); + + ri = ifp->info; + ri->t_wakeup = NULL; + + /* Join to multicast group. */ + ripng_multicast_join (ifp); + + /* Send RIP request to the interface. */ + ripng_request (ifp); + + return 0; +} + +/* Check RIPng is enabed on this interface. */ +void +ripng_enable_apply (struct interface *ifp) +{ + int ret; + struct ripng_interface *ri = NULL; + + /* Check interface. */ + if (if_is_loopback (ifp)) + return; + + if (! if_is_up (ifp)) + return; + + ri = ifp->info; + + /* Check network configuration. */ + ret = ripng_enable_network_lookup (ifp); + + /* If the interface is matched. */ + if (ret > 0) + ri->enable_network = 1; + else + ri->enable_network = 0; + + /* Check interface name configuration. */ + ret = ripng_enable_if_lookup (ifp->name); + if (ret >= 0) + ri->enable_interface = 1; + else + ri->enable_interface = 0; + + /* Update running status of the interface. */ + if (ri->enable_network || ri->enable_interface) + { + if (! ri->running) + { + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng turn on %s", ifp->name); + + /* Add interface wake up thread. */ + if (! ri->t_wakeup) + ri->t_wakeup = thread_add_timer (master, ripng_interface_wakeup, + ifp, 1); +#if 0 + /* Join to multicast group. */ + ripng_multicast_join (ifp); + + /* Send RIP request to the interface. */ + ripng_request (ifp); +#endif /* 0 */ + + ri->running = 1; + } + } + else + { + if (ri->running) + { + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng turn off %s", ifp->name); + + /* Leave from multicast group. */ + ripng_multicast_leave (ifp); + + ri->running = 0; + } + } +} + +/* Set distribute list to all interfaces. */ +static void +ripng_enable_apply_all () +{ + struct interface *ifp; + listnode node; + + for (node = listhead (iflist); node; nextnode (node)) + { + ifp = getdata (node); + ripng_enable_apply (ifp); + } +} + +/* Vector to store passive-interface name. */ +vector Vripng_passive_interface; + +/* Utility function for looking up passive interface settings. */ +int +ripng_passive_interface_lookup (char *ifname) +{ + int i; + char *str; + + for (i = 0; i < vector_max (Vripng_passive_interface); i++) + if ((str = vector_slot (Vripng_passive_interface, i)) != NULL) + if (strcmp (str, ifname) == 0) + return i; + return -1; +} + +void +ripng_passive_interface_apply (struct interface *ifp) +{ + int ret; + struct ripng_interface *ri; + + ri = ifp->info; + + ret = ripng_passive_interface_lookup (ifp->name); + if (ret < 0) + ri->passive = 0; + else + ri->passive = 1; +} + +void +ripng_passive_interface_apply_all (void) +{ + struct interface *ifp; + listnode node; + + for (node = listhead (iflist); node; nextnode (node)) + { + ifp = getdata (node); + ripng_passive_interface_apply (ifp); + } +} + +/* Passive interface. */ +int +ripng_passive_interface_set (struct vty *vty, char *ifname) +{ + if (ripng_passive_interface_lookup (ifname) >= 0) + return CMD_WARNING; + + vector_set (Vripng_passive_interface, strdup (ifname)); + + ripng_passive_interface_apply_all (); + + return CMD_SUCCESS; +} + +int +ripng_passive_interface_unset (struct vty *vty, char *ifname) +{ + int i; + char *str; + + i = ripng_passive_interface_lookup (ifname); + if (i < 0) + return CMD_WARNING; + + str = vector_slot (Vripng_passive_interface, i); + free (str); + vector_unset (Vripng_passive_interface, i); + + ripng_passive_interface_apply_all (); + + return CMD_SUCCESS; +} + +/* Free all configured RIP passive-interface settings. */ +void +ripng_passive_interface_clean (void) +{ + int i; + char *str; + + for (i = 0; i < vector_max (Vripng_passive_interface); i++) + if ((str = vector_slot (Vripng_passive_interface, i)) != NULL) + { + free (str); + vector_slot (Vripng_passive_interface, i) = NULL; + } + ripng_passive_interface_apply_all (); +} + +/* Write RIPng enable network and interface to the vty. */ +int +ripng_network_write (struct vty *vty) +{ + int i; + char *str; + char *ifname; + struct route_node *node; + char buf[BUFSIZ]; + + /* Write enable network. */ + for (node = route_top (ripng_enable_network); node; node = route_next (node)) + if (node->info) + { + struct prefix *p = &node->p; + vty_out (vty, " network %s/%d%s", + inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), + p->prefixlen, + VTY_NEWLINE); + + } + + /* Write enable interface. */ + for (i = 0; i < vector_max (ripng_enable_if); i++) + if ((str = vector_slot (ripng_enable_if, i)) != NULL) + vty_out (vty, " network %s%s", str, + VTY_NEWLINE); + + /* Write passive interface. */ + for (i = 0; i < vector_max (Vripng_passive_interface); i++) + if ((ifname = vector_slot (Vripng_passive_interface, i)) != NULL) + vty_out (vty, " passive-interface %s%s", ifname, VTY_NEWLINE); + + return 0; +} + +/* RIPng enable on specified interface or matched network. */ +DEFUN (ripng_network, + ripng_network_cmd, + "network IF_OR_ADDR", + "RIPng enable on specified interface or network.\n" + "Interface or address") +{ + int ret; + struct prefix p; + + ret = str2prefix (argv[0], &p); + + /* Given string is IPv6 network or interface name. */ + if (ret) + ret = ripng_enable_network_add (&p); + else + ret = ripng_enable_if_add (argv[0]); + + if (ret < 0) + { + vty_out (vty, "There is same network configuration %s%s", argv[0], + VTY_NEWLINE); + return CMD_WARNING; + } + + ripng_enable_apply_all (); + + return CMD_SUCCESS; +} + +/* RIPng enable on specified interface or matched network. */ +DEFUN (no_ripng_network, + no_ripng_network_cmd, + "no network IF_OR_ADDR", + NO_STR + "RIPng enable on specified interface or network.\n" + "Interface or address") +{ + int ret; + struct prefix p; + + ret = str2prefix (argv[0], &p); + + /* Given string is interface name. */ + if (ret) + ret = ripng_enable_network_delete (&p); + else + ret = ripng_enable_if_delete (argv[0]); + + if (ret < 0) + { + vty_out (vty, "can't find network %s%s", argv[0], + VTY_NEWLINE); + return CMD_WARNING; + } + + ripng_enable_apply_all (); + + return CMD_SUCCESS; +} + +DEFUN (ripng_passive_interface, + ripng_passive_interface_cmd, + "passive-interface IFNAME", + "Suppress routing updates on an interface\n" + "Interface name\n") +{ + return ripng_passive_interface_set (vty, argv[0]); +} + +DEFUN (no_ripng_passive_interface, + no_ripng_passive_interface_cmd, + "no passive-interface IFNAME", + NO_STR + "Suppress routing updates on an interface\n" + "Interface name\n") +{ + return ripng_passive_interface_unset (vty, argv[0]); +} + +struct ripng_interface * +ri_new () +{ + struct ripng_interface *ri; + ri = XCALLOC (MTYPE_IF, sizeof (struct ripng_interface)); + return ri; +} + +int +ripng_if_new_hook (struct interface *ifp) +{ + ifp->info = ri_new (); + return 0; +} + +/* Configuration write function for ripngd. */ +int +interface_config_write (struct vty *vty) +{ + listnode node; + struct interface *ifp; + struct ripng_interface *ri; + int write = 0; + + for (node = listhead (iflist); node; nextnode (node)) + { + ifp = getdata (node); + ri = ifp->info; + + vty_out (vty, "interface %s%s", ifp->name, + VTY_NEWLINE); + if (ifp->desc) + vty_out (vty, " description %s%s", ifp->desc, + VTY_NEWLINE); + + vty_out (vty, "!%s", VTY_NEWLINE); + + write++; + } + return write; +} + +/* ripngd's interface node. */ +struct cmd_node interface_node = +{ + INTERFACE_NODE, + "%s(config-if)# ", +}; + +/* Initialization of interface. */ +void +ripng_if_init () +{ + /* Interface initialize. */ + iflist = list_new (); + if_add_hook (IF_NEW_HOOK, ripng_if_new_hook); + + /* RIPng enable network init. */ + ripng_enable_network = route_table_init (); + + /* RIPng enable interface init. */ + ripng_enable_if = vector_init (1); + + /* RIPng passive interface. */ + Vripng_passive_interface = vector_init (1); + + /* Install interface node. */ + install_node (&interface_node, interface_config_write); + + install_element (CONFIG_NODE, &interface_cmd); + install_element (INTERFACE_NODE, &config_end_cmd); + install_element (INTERFACE_NODE, &config_exit_cmd); + install_element (INTERFACE_NODE, &config_help_cmd); + install_element (INTERFACE_NODE, &interface_desc_cmd); + install_element (INTERFACE_NODE, &no_interface_desc_cmd); + + install_element (RIPNG_NODE, &ripng_network_cmd); + install_element (RIPNG_NODE, &no_ripng_network_cmd); + install_element (RIPNG_NODE, &ripng_passive_interface_cmd); + install_element (RIPNG_NODE, &no_ripng_passive_interface_cmd); +} diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c new file mode 100644 index 00000000..aec74bb4 --- /dev/null +++ b/ripngd/ripng_main.c @@ -0,0 +1,252 @@ +/* + * RIPngd main routine. + * Copyright (C) 1998, 1999 Kunihiro Ishiguro + * + * 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 "version.h" +#include "getopt.h" +#include "vector.h" +#include "vty.h" +#include "command.h" +#include "thread.h" +#include "log.h" +#include "prefix.h" +#include "if.h" + +#include "ripngd/ripngd.h" + +/* Configuration filename and directory. */ +char config_current[] = RIPNG_DEFAULT_CONFIG; +char config_default[] = SYSCONFDIR RIPNG_DEFAULT_CONFIG; + +/* RIPngd options. */ +struct option longopts[] = +{ + { "daemon", no_argument, NULL, 'd'}, + { "config_file", required_argument, NULL, 'f'}, + { "pid_file", required_argument, NULL, 'i'}, + { "log_mode", no_argument, NULL, 'l'}, + { "help", no_argument, NULL, 'h'}, + { "vty_addr", required_argument, NULL, 'A'}, + { "vty_port", required_argument, NULL, 'P'}, + { "retain", no_argument, NULL, 'r'}, + { "version", no_argument, NULL, 'v'}, + { 0 } +}; + +/* RIPngd program name */ + +/* Route retain mode flag. */ +int retain_mode = 0; + +/* Master of threads. */ +struct thread_master *master; + +/* Process ID saved for use by init system */ +char *pid_file = PATH_RIPNGD_PID; + +/* Help information display. */ +static void +usage (char *progname, int status) +{ + if (status != 0) + fprintf (stderr, "Try `%s --help' for more information.\n", progname); + else + { + printf ("Usage : %s [OPTION...]\n\ +Daemon which manages RIPng.\n\n\ +-d, --daemon Runs in daemon mode\n\ +-f, --config_file Set configuration file name\n\ +-i, --pid_file Set process identifier file name\n\ +-l. --log_mode Set verbose log mode flag\n\ +-A, --vty_addr Set vty's bind address\n\ +-P, --vty_port Set vty's port number\n\ +-r, --retain When program terminates, retain added route by ripngd.\n\ +-v, --version Print program version\n\ +-h, --help Display this help and exit\n\ +\n\ +Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS); + } + exit (status); +} + +/* SIGHUP handler. */ +void +sighup (int sig) +{ + zlog (NULL, LOG_INFO, "SIGHUP received"); +} + +/* SIGINT handler. */ +void +sigint (int sig) +{ + zlog (NULL, LOG_INFO, "Terminating on signal"); + + if (! retain_mode) + ripng_terminate (); + + exit (0); +} + +/* SIGUSR1 handler. */ +void +sigusr1 (int sig) +{ + zlog_rotate (NULL); +} + +/* Signale wrapper. */ +RETSIGTYPE * +signal_set (int signo, void (*func)(int)) +{ + int ret; + struct sigaction sig; + struct sigaction osig; + + sig.sa_handler = func; + sigemptyset (&sig.sa_mask); + sig.sa_flags = 0; +#ifdef SA_RESTART + sig.sa_flags |= SA_RESTART; +#endif /* SA_RESTART */ + + ret = sigaction (signo, &sig, &osig); + + if (ret < 0) + return (SIG_ERR); + else + return (osig.sa_handler); +} + +/* Initialization of signal handles. */ +void +signal_init () +{ + signal_set (SIGHUP, sighup); + signal_set (SIGINT, sigint); + signal_set (SIGTERM, sigint); + signal_set (SIGPIPE, SIG_IGN); + signal_set (SIGUSR1, sigusr1); +} + +/* RIPngd main routine. */ +int +main (int argc, char **argv) +{ + char *p; + char *vty_addr = NULL; + int vty_port = 0; + int daemon_mode = 0; + char *config_file = NULL; + char *progname; + struct thread thread; + + /* Set umask before anything for security */ + umask (0027); + + /* get program name */ + progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); + + zlog_default = openzlog(progname, ZLOG_NOLOG, ZLOG_RIPNG, + LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); + + while (1) + { + int opt; + + opt = getopt_long (argc, argv, "dlf:hA:P:v", longopts, 0); + + if (opt == EOF) + break; + + switch (opt) + { + case 0: + break; + case 'd': + daemon_mode = 1; + break; + case 'l': + /* log_mode = 1; */ + break; + case 'f': + config_file = optarg; + break; + case 'A': + vty_addr = optarg; + break; + case 'i': + pid_file = optarg; + break; + case 'P': + vty_port = atoi (optarg); + break; + case 'r': + retain_mode = 1; + break; + case 'v': + print_version (progname); + exit (0); + break; + case 'h': + usage (progname, 0); + break; + default: + usage (progname, 1); + break; + } + } + + master = thread_master_create (); + + /* Library inits. */ + signal_init (); + cmd_init (1); + vty_init (); + + /* RIPngd inits. */ + ripng_init (); + zebra_init (); + sort_node (); + + /* Get configuration file. */ + vty_read_config (config_file, config_current, config_default); + + /* Change to the daemon program. */ + if (daemon_mode) + daemon (0, 0); + + /* Create VTY socket */ + vty_serv_sock (vty_addr, + vty_port ? vty_port : RIPNG_VTY_PORT, RIPNG_VTYSH_PATH); + + /* Process id file create. */ + pid_output (pid_file); + + /* Fetch next active thread. */ + while (thread_fetch (master, &thread)) + thread_call (&thread); + + /* Not reached. */ + exit (0); +} diff --git a/ripngd/ripng_route.c b/ripngd/ripng_route.c new file mode 100644 index 00000000..27475f05 --- /dev/null +++ b/ripngd/ripng_route.c @@ -0,0 +1,157 @@ +/* + * RIPng routes function. + * Copyright (C) 1998 Kunihiro Ishiguro + * + * 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 "prefix.h" +#include "table.h" +#include "memory.h" +#include "if.h" + +#include "ripngd/ripngd.h" +#include "ripngd/ripng_route.h" + +struct ripng_aggregate * +ripng_aggregate_new () +{ + struct ripng_aggregate *new; + + new = XCALLOC (MTYPE_RIPNG_AGGREGATE, sizeof (struct ripng_aggregate)); + return new; +} + +void +ripng_aggregate_free (struct ripng_aggregate *aggregate) +{ + XFREE (MTYPE_RIPNG_AGGREGATE, aggregate); +} + +/* Aggregate count increment check. */ +void +ripng_aggregate_increment (struct route_node *child, struct ripng_info *rinfo) +{ + struct route_node *np; + struct ripng_aggregate *aggregate; + + for (np = child; np; np = np->parent) + if ((aggregate = np->aggregate) != NULL) + { + aggregate->count++; + rinfo->suppress++; + } +} + +/* Aggregate count decrement check. */ +void +ripng_aggregate_decrement (struct route_node *child, struct ripng_info *rinfo) +{ + struct route_node *np; + struct ripng_aggregate *aggregate; + + for (np = child; np; np = np->parent) + if ((aggregate = np->aggregate) != NULL) + { + aggregate->count--; + rinfo->suppress--; + } +} + +/* RIPng routes treatment. */ +int +ripng_aggregate_add (struct prefix *p) +{ + struct route_node *top; + struct route_node *rp; + struct ripng_info *rinfo; + struct ripng_aggregate *aggregate; + struct ripng_aggregate *sub; + + /* Get top node for aggregation. */ + top = route_node_get (ripng->table, p); + + /* Allocate new aggregate. */ + aggregate = ripng_aggregate_new (); + aggregate->metric = 1; + + top->aggregate = aggregate; + + /* Suppress routes match to the aggregate. */ + for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top)) + { + /* Suppress normal route. */ + if ((rinfo = rp->info) != NULL) + { + aggregate->count++; + rinfo->suppress++; + } + /* Suppress aggregate route. This may not need. */ + if (rp != top && (sub = rp->aggregate) != NULL) + { + aggregate->count++; + sub->suppress++; + } + } + + return 0; +} + +/* Delete RIPng static route. */ +int +ripng_aggregate_delete (struct prefix *p) +{ + struct route_node *top; + struct route_node *rp; + struct ripng_info *rinfo; + struct ripng_aggregate *aggregate; + struct ripng_aggregate *sub; + + /* Get top node for aggregation. */ + top = route_node_get (ripng->table, p); + + /* Allocate new aggregate. */ + aggregate = top->aggregate; + + /* Suppress routes match to the aggregate. */ + for (rp = route_lock_node (top); rp; rp = route_next_until (rp, top)) + { + /* Suppress normal route. */ + if ((rinfo = rp->info) != NULL) + { + aggregate->count--; + rinfo->suppress--; + } + + if (rp != top && (sub = rp->aggregate) != NULL) + { + aggregate->count--; + sub->suppress--; + } + } + + top->aggregate = NULL; + ripng_aggregate_free (aggregate); + + route_unlock_node (top); + route_unlock_node (top); + + return 0; +} diff --git a/ripngd/ripng_route.h b/ripngd/ripng_route.h new file mode 100644 index 00000000..283d8268 --- /dev/null +++ b/ripngd/ripng_route.h @@ -0,0 +1,53 @@ +/* + * RIPng daemon + * Copyright (C) 1998 Kunihiro Ishiguro + * + * 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. + */ + +#ifndef _ZEBRA_RIPNG_ROUTE_H +#define _ZEBRA_RIPNG_ROUTE_H + +struct ripng_aggregate +{ + /* Aggregate route count. */ + unsigned int count; + + /* Suppressed route count. */ + unsigned int suppress; + + /* Metric of this route. */ + u_char metric; + + /* Tag field of RIPng packet.*/ + u_short tag; +}; + +void +ripng_aggregate_increment (struct route_node *rp, struct ripng_info *rinfo); + +void +ripng_aggregate_decrement (struct route_node *rp, struct ripng_info *rinfo); + +int +ripng_aggregate_add (struct prefix *p); + +int +ripng_aggregate_delete (struct prefix *p); + +#endif /* _ZEBRA_RIPNG_ROUTE_H */ diff --git a/ripngd/ripng_routemap.c b/ripngd/ripng_routemap.c new file mode 100644 index 00000000..f237e6b6 --- /dev/null +++ b/ripngd/ripng_routemap.c @@ -0,0 +1,342 @@ +/* RIPng routemap. + * Copyright (C) 1999 Kunihiro Ishiguro + * + * 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 "if.h" +#include "memory.h" +#include "prefix.h" +#include "routemap.h" +#include "command.h" + +#include "ripngd/ripngd.h" + +#if 0 +/* `match interface IFNAME' */ +route_map_result_t +route_match_interface (void *rule, struct prefix *prefix, + route_map_object_t type, void *object) +{ + struct ripng_info *rinfo; + struct interface *ifp; + char *ifname; + + if (type == ROUTE_MAP_RIPNG) + { + ifname = rule; + ifp = if_lookup_by_name(ifname); + + if (!ifp) + return RM_NOMATCH; + + rinfo = object; + + if (rinfo->ifindex == ifp->ifindex) + return RM_MATCH; + else + return RM_NOMATCH; + } + return RM_NOMATCH; +} + +void * +route_match_interface_compile (char *arg) +{ + return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); +} + +void +route_match_interface_free (void *rule) +{ + XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); +} + +struct route_map_rule_cmd route_match_interface_cmd = +{ + "interface", + route_match_interface, + route_match_interface_compile, + route_match_interface_free +}; +#endif /* 0 */ + +struct rip_metric_modifier +{ + enum + { + metric_increment, + metric_decrement, + metric_absolute + } type; + + u_char metric; +}; + +route_map_result_t +route_set_metric (void *rule, struct prefix *prefix, + route_map_object_t type, void *object) +{ + if (type == RMAP_RIPNG) + { + struct rip_metric_modifier *mod; + struct ripng_info *rinfo; + + mod = rule; + rinfo = object; + + if (mod->type == metric_increment) + rinfo->metric += mod->metric; + else if (mod->type == metric_decrement) + rinfo->metric -= mod->metric; + else if (mod->type == metric_absolute) + rinfo->metric = mod->metric; + + if (rinfo->metric < 1) + rinfo->metric = 1; + if (rinfo->metric > RIPNG_METRIC_INFINITY) + rinfo->metric = RIPNG_METRIC_INFINITY; + + rinfo->metric_set = 1; + } + return RMAP_OKAY; +} + +void * +route_set_metric_compile (char *arg) +{ + int len; + char *pnt; + int type; + long metric; + char *endptr = NULL; + struct rip_metric_modifier *mod; + + len = strlen (arg); + pnt = arg; + + if (len == 0) + return NULL; + + /* Examine first character. */ + if (arg[0] == '+') + { + type = metric_increment; + pnt++; + } + else if (arg[0] == '-') + { + type = metric_decrement; + pnt++; + } + else + type = metric_absolute; + + /* Check beginning with digit string. */ + if (*pnt < '0' || *pnt > '9') + return NULL; + + /* Convert string to integer. */ + metric = strtol (pnt, &endptr, 10); + + if (metric == LONG_MAX || *endptr != '\0') + return NULL; + if (metric < 0 || metric > RIPNG_METRIC_INFINITY) + return NULL; + + mod = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, + sizeof (struct rip_metric_modifier)); + mod->type = type; + mod->metric = metric; + + return mod; +} + +void +route_set_metric_free (void *rule) +{ + XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); +} + +struct route_map_rule_cmd route_set_metric_cmd = +{ + "metric", + route_set_metric, + route_set_metric_compile, + route_set_metric_free, +}; + +int +ripng_route_match_add (struct vty *vty, struct route_map_index *index, + char *command, char *arg) +{ + int ret; + + ret = route_map_add_match (index, command, arg); + if (ret) + { + switch (ret) + { + case RMAP_RULE_MISSING: + vty_out (vty, "Can't find rule.%s", VTY_NEWLINE); + return CMD_WARNING; + break; + case RMAP_COMPILE_ERROR: + vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE); + return CMD_WARNING; + break; + } + } + return CMD_SUCCESS; +} + +int +ripng_route_match_delete (struct vty *vty, struct route_map_index *index, + char *command, char *arg) +{ + int ret; + + ret = route_map_delete_match (index, command, arg); + if (ret) + { + switch (ret) + { + case RMAP_RULE_MISSING: + vty_out (vty, "Can't find rule.%s", VTY_NEWLINE); + return CMD_WARNING; + break; + case RMAP_COMPILE_ERROR: + vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE); + return CMD_WARNING; + break; + } + } + return CMD_SUCCESS; +} + +int +ripng_route_set_add (struct vty *vty, struct route_map_index *index, + char *command, char *arg) +{ + int ret; + + ret = route_map_add_set (index, command, arg); + if (ret) + { + switch (ret) + { + case RMAP_RULE_MISSING: + vty_out (vty, "Can't find rule.%s", VTY_NEWLINE); + return CMD_WARNING; + break; + case RMAP_COMPILE_ERROR: + vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE); + return CMD_WARNING; + break; + } + } + return CMD_SUCCESS; +} + +int +ripng_route_set_delete (struct vty *vty, struct route_map_index *index, + char *command, char *arg) +{ + int ret; + + ret = route_map_delete_set (index, command, arg); + if (ret) + { + switch (ret) + { + case RMAP_RULE_MISSING: + vty_out (vty, "Can't find rule.%s", VTY_NEWLINE); + return CMD_WARNING; + break; + case RMAP_COMPILE_ERROR: + vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE); + return CMD_WARNING; + break; + } + } + return CMD_SUCCESS; +} + +#if 0 +DEFUN (match_interface, + match_interface_cmd, + "match interface WORD", + "Match value\n" + "Interface\n" + "Interface name\n") +{ + return ripng_route_match_add (vty, vty->index, "interface", argv[0]); +} + +DEFUN (no_match_interface, + no_match_interface_cmd, + "no match interface WORD", + NO_STR + "Match value\n" + "Interface\n" + "Interface name\n") +{ + return ripng_route_match_delete (vty, vty->index, "interface", argv[0]); +} +#endif /* 0 */ + +DEFUN (set_metric, + set_metric_cmd, + "set metric <0-4294967295>", + "Set value\n" + "Metric\n" + "METRIC value\n") +{ + return ripng_route_set_add (vty, vty->index, "metric", argv[0]); +} + +DEFUN (no_set_metric, + no_set_metric_cmd, + "no set metric <0-4294967295>", + NO_STR + "Set value\n" + "Metric\n" + "METRIC value\n") +{ + return ripng_route_set_delete (vty, vty->index, "metric", argv[0]); +} + +void +ripng_route_map_init () +{ + route_map_init (); + route_map_init_vty (); + + /* route_map_install_match (&route_match_interface_cmd); */ + route_map_install_set (&route_set_metric_cmd); + + /* + install_element (RMAP_NODE, &match_interface_cmd); + install_element (RMAP_NODE, &no_match_interface_cmd); + */ + + install_element (RMAP_NODE, &set_metric_cmd); + install_element (RMAP_NODE, &no_set_metric_cmd); +} diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c new file mode 100644 index 00000000..4d8a48d3 --- /dev/null +++ b/ripngd/ripng_zebra.c @@ -0,0 +1,877 @@ +/* + * RIPngd and zebra interface. + * Copyright (C) 1998, 1999 Kunihiro Ishiguro + * + * 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 "command.h" +#include "prefix.h" +#include "stream.h" +#include "routemap.h" +#include "zclient.h" +#include "log.h" + +#include "ripngd/ripngd.h" + +/* All information about zebra. */ +struct zclient *zclient = NULL; + +/* Callback prototypes for zebra client service. */ +int ripng_interface_up (int, struct zclient *, zebra_size_t); +int ripng_interface_down (int, struct zclient *, zebra_size_t); +int ripng_interface_add (int, struct zclient *, zebra_size_t); +int ripng_interface_delete (int, struct zclient *, zebra_size_t); +int ripng_interface_address_add (int, struct zclient *, zebra_size_t); +int ripng_interface_address_delete (int, struct zclient *, zebra_size_t); + +void +ripng_zebra_ipv6_add (struct prefix_ipv6 *p, struct in6_addr *nexthop, + unsigned int ifindex) +{ + struct zapi_ipv6 api; + + if (zclient->redist[ZEBRA_ROUTE_RIPNG]) + { + api.type = ZEBRA_ROUTE_RIPNG; + api.flags = 0; + api.message = 0; + SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); + api.nexthop_num = 1; + api.nexthop = &nexthop; + SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); + api.ifindex_num = 1; + api.ifindex = &ifindex; + + zapi_ipv6_add (zclient, p, &api); + } +} + +void +ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop, + unsigned int ifindex) +{ + struct zapi_ipv6 api; + + if (zclient->redist[ZEBRA_ROUTE_RIPNG]) + { + api.type = ZEBRA_ROUTE_RIPNG; + api.flags = 0; + api.message = 0; + SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); + api.nexthop_num = 1; + api.nexthop = &nexthop; + SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); + api.ifindex_num = 1; + api.ifindex = &ifindex; + + zapi_ipv6_delete (zclient, p, &api); + } +} + +/* Zebra route add and delete treatment. */ +int +ripng_zebra_read_ipv6 (int command, struct zclient *zclient, + zebra_size_t length) +{ + struct stream *s; + struct zapi_ipv6 api; + unsigned long ifindex; + struct in6_addr nexthop; + struct prefix_ipv6 p; + + s = zclient->ibuf; + ifindex = 0; + memset (&nexthop, 0, sizeof (struct in6_addr)); + + /* Type, flags, message. */ + api.type = stream_getc (s); + api.flags = stream_getc (s); + api.message = stream_getc (s); + + /* IPv6 prefix. */ + memset (&p, 0, sizeof (struct prefix_ipv6)); + p.family = AF_INET6; + p.prefixlen = stream_getc (s); + stream_get (&p.prefix, s, PSIZE (p.prefixlen)); + + /* Nexthop, ifindex, distance, metric. */ + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) + { + api.nexthop_num = stream_getc (s); + stream_get (&nexthop, s, 16); + } + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) + { + api.ifindex_num = stream_getc (s); + ifindex = stream_getl (s); + } + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) + api.distance = stream_getc (s); + else + api.distance = 0; + if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) + api.metric = stream_getl (s); + else + api.metric = 0; + + if (command == ZEBRA_IPV6_ROUTE_ADD) + ripng_redistribute_add (api.type, 0, &p, ifindex); + else + ripng_redistribute_delete (api.type, 0, &p, ifindex); + + return 0; +} + +int +ripng_redistribute_unset (int type) +{ + if (! zclient->redist[type]) + return CMD_SUCCESS; + + zclient->redist[type] = 0; + + if (zclient->sock > 0) + zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type); + + ripng_redistribute_withdraw (type); + + return CMD_SUCCESS; +} + +void +ripng_redistribute_metric_set (int type, int metric) +{ + ripng->route_map[type].metric_config = 1; + ripng->route_map[type].metric = metric; +} + +void +ripng_redistribute_metric_unset (int type) +{ + ripng->route_map[type].metric_config = 0; + ripng->route_map[type].metric = 0; +} + +void +ripng_redistribute_routemap_set (int type, char *name) +{ + if (ripng->route_map[type].name) + free (ripng->route_map[type].name); + + ripng->route_map[type].name = strdup (name); + ripng->route_map[type].map = route_map_lookup_by_name (name); +} + +void +ripng_redistribute_routemap_unset (int type) +{ + if (ripng->route_map[type].name) + free (ripng->route_map[type].name); + + ripng->route_map[type].name = NULL; + ripng->route_map[type].map = NULL; +} + + +DEFUN (router_zebra, + router_zebra_cmd, + "router zebra", + "Enable a routing process\n" + "Make connection to zebra daemon\n") +{ + vty->node = ZEBRA_NODE; + zclient->enable = 1; + zclient_start (zclient); + return CMD_SUCCESS; +} + +DEFUN (no_router_zebra, + no_router_zebra_cmd, + "no router zebra", + NO_STR + "Disable a routing process\n" + "Stop connection to zebra daemon\n") +{ + zclient->enable = 0; + zclient_stop (zclient); + return CMD_SUCCESS; +} + +DEFUN (ripng_redistribute_ripng, + ripng_redistribute_ripng_cmd, + "redistribute ripng", + "Redistribute information from another routing protocol\n" + "RIPng route\n") +{ + zclient->redist[ZEBRA_ROUTE_RIPNG] = 1; + return CMD_SUCCESS; +} + +DEFUN (no_ripng_redistribute_ripng, + no_ripng_redistribute_ripng_cmd, + "no redistribute ripng", + NO_STR + "Redistribute information from another routing protocol\n" + "RIPng route\n") +{ + zclient->redist[ZEBRA_ROUTE_RIPNG] = 0; + return CMD_SUCCESS; +} + +DEFUN (ripng_redistribute_static, + ripng_redistribute_static_cmd, + "redistribute static", + "Redistribute information from another routing protocol\n" + "Static routes\n") +{ + zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC); + return CMD_SUCCESS; +} + +DEFUN (no_ripng_redistribute_static, + no_ripng_redistribute_static_cmd, + "no redistribute static", + NO_STR + "Redistribute information from another routing protocol\n" + "Static routes\n") +{ + ripng_redistribute_metric_unset (ZEBRA_ROUTE_STATIC); + ripng_redistribute_routemap_unset (ZEBRA_ROUTE_STATIC); + return ripng_redistribute_unset (ZEBRA_ROUTE_STATIC); +} + +DEFUN (ripng_redistribute_kernel, + ripng_redistribute_kernel_cmd, + "redistribute kernel", + "Redistribute information from another routing protocol\n" + "Kernel routes\n") +{ + zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL); + return CMD_SUCCESS; +} + +DEFUN (no_ripng_redistribute_kernel, + no_ripng_redistribute_kernel_cmd, + "no redistribute kernel", + NO_STR + "Redistribute information from another routing protocol\n" + "Kernel routes\n") +{ + ripng_redistribute_metric_unset (ZEBRA_ROUTE_KERNEL); + ripng_redistribute_routemap_unset (ZEBRA_ROUTE_KERNEL); + return ripng_redistribute_unset (ZEBRA_ROUTE_KERNEL); +} + +DEFUN (ripng_redistribute_connected, + ripng_redistribute_connected_cmd, + "redistribute connected", + "Redistribute information from another routing protocol\n" + "Connected\n") +{ + zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT); + return CMD_SUCCESS; +} + +DEFUN (no_ripng_redistribute_connected, + no_ripng_redistribute_connected_cmd, + "no redistribute connected", + NO_STR + "Redistribute information from another routing protocol\n" + "Connected\n") +{ + ripng_redistribute_metric_unset (ZEBRA_ROUTE_CONNECT); + ripng_redistribute_routemap_unset (ZEBRA_ROUTE_CONNECT); + return ripng_redistribute_unset (ZEBRA_ROUTE_CONNECT); +} + +DEFUN (ripng_redistribute_bgp, + ripng_redistribute_bgp_cmd, + "redistribute bgp", + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n") +{ + zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP); + return CMD_SUCCESS; +} + +DEFUN (no_ripng_redistribute_bgp, + no_ripng_redistribute_bgp_cmd, + "no redistribute bgp", + NO_STR + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n") +{ + ripng_redistribute_metric_unset (ZEBRA_ROUTE_BGP); + ripng_redistribute_routemap_unset (ZEBRA_ROUTE_BGP); + return ripng_redistribute_unset (ZEBRA_ROUTE_BGP); +} + +DEFUN (ripng_redistribute_ospf6, + ripng_redistribute_ospf6_cmd, + "redistribute ospf6", + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n") +{ + zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6); + return CMD_SUCCESS; +} + +DEFUN (no_ripng_redistribute_ospf6, + no_ripng_redistribute_ospf6_cmd, + "no redistribute ospf6", + NO_STR + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n") +{ + ripng_redistribute_metric_unset (ZEBRA_ROUTE_OSPF6); + ripng_redistribute_routemap_unset (ZEBRA_ROUTE_OSPF6); + return ripng_redistribute_unset (ZEBRA_ROUTE_OSPF6); +} + +DEFUN (ripng_redistribute_kernel_metric, + ripng_redistribute_kernel_metric_cmd, + "redistribute kernel metric <0-16>", + "Redistribute information from another routing protocol\n" + "Kernel routes\n" + "Metric\n" + "Metric value\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_KERNEL, atoi (argv[0])); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_kernel, + no_ripng_redistribute_kernel_metric_cmd, + "no redistribute kernel metric", + NO_STR + "Redistribute information from another routing protocol\n" + "Kernel routes\n" + "Metric\n") + +ALIAS (no_ripng_redistribute_kernel, + no_ripng_redistribute_kernel_metric_val_cmd, + "no redistribute kernel metric <0-16>", + NO_STR + "Redistribute information from another routing protocol\n" + "Kernel routes\n" + "Metric\n" + "Metric value\n") + +DEFUN (ripng_redistribute_connected_metric, + ripng_redistribute_connected_metric_cmd, + "redistribute connected metric <0-16>", + "Redistribute information from another routing protocol\n" + "Connected\n" + "Metric\n" + "Metric value\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_CONNECT, atoi (argv[0])); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_connected, + no_ripng_redistribute_connected_metric_cmd, + "no redistribute connected metric", + NO_STR + "Redistribute information from another routing protocol\n" + "Connected\n" + "Metric\n") + +ALIAS (no_ripng_redistribute_connected, + no_ripng_redistribute_connected_metric_val_cmd, + "no redistribute connected metric <0-16>", + NO_STR + "Redistribute information from another routing protocol\n" + "Connected\n" + "Metric\n" + "Metric value\n") + +DEFUN (ripng_redistribute_static_metric, + ripng_redistribute_static_metric_cmd, + "redistribute static metric <0-16>", + "Redistribute information from another routing protocol\n" + "Static routes\n" + "Metric\n" + "Metric value\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_STATIC, atoi (argv[0])); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_static, + no_ripng_redistribute_static_metric_cmd, + "no redistribute static metric", + NO_STR + "Redistribute information from another routing protocol\n" + "Static routes\n" + "Metric\n") + +ALIAS (no_ripng_redistribute_static, + no_ripng_redistribute_static_metric_val_cmd, + "no redistribute static metric <0-16>", + NO_STR + "Redistribute information from another routing protocol\n" + "Static routes\n" + "Metric\n" + "Metric value\n") + +DEFUN (ripng_redistribute_ospf6_metric, + ripng_redistribute_ospf6_metric_cmd, + "redistribute ospf6 metric <0-16>", + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n" + "Metric\n" + "Metric value\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_OSPF6, atoi (argv[0])); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_ospf6, + no_ripng_redistribute_ospf6_metric_cmd, + "no redistribute ospf6 metric", + NO_STR + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n" + "Metric\n") + +ALIAS (no_ripng_redistribute_ospf6, + no_ripng_redistribute_ospf6_metric_val_cmd, + "no redistribute ospf6 metric <0-16>", + NO_STR + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n" + "Metric\n" + "Metric value\n") + +DEFUN (ripng_redistribute_bgp_metric, + ripng_redistribute_bgp_metric_cmd, + "redistribute bgp metric <0-16>", + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n" + "Metric\n" + "Metric value\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_BGP, atoi (argv[0])); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_bgp, + no_ripng_redistribute_bgp_metric_cmd, + "no redistribute bgp metric", + NO_STR + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n" + "Metric\n") + +ALIAS (no_ripng_redistribute_bgp, + no_ripng_redistribute_bgp_metric_val_cmd, + "no redistribute bgp metric <0-16>", + NO_STR + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n" + "Metric\n" + "Metric value\n") + +DEFUN (ripng_redistribute_kernel_routemap, + ripng_redistribute_kernel_routemap_cmd, + "redistribute kernel route-map WORD", + "Redistribute information from another routing protocol\n" + "Kernel routes\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_routemap_set (ZEBRA_ROUTE_KERNEL, argv[0]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_kernel, + no_ripng_redistribute_kernel_routemap_cmd, + "no redistribute kernel route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "Kernel routes\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_connected_routemap, + ripng_redistribute_connected_routemap_cmd, + "redistribute connected route-map WORD", + "Redistribute information from another routing protocol\n" + "Connected\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_routemap_set (ZEBRA_ROUTE_CONNECT, argv[0]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_connected, + no_ripng_redistribute_connected_routemap_cmd, + "no redistribute connected route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "Connected\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_static_routemap, + ripng_redistribute_static_routemap_cmd, + "redistribute static route-map WORD", + "Redistribute information from another routing protocol\n" + "Static routes\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_routemap_set (ZEBRA_ROUTE_STATIC, argv[0]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_static, + no_ripng_redistribute_static_routemap_cmd, + "no redistribute static route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "Static routes\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_ospf6_routemap, + ripng_redistribute_ospf6_routemap_cmd, + "redistribute ospf6 route-map WORD", + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_routemap_set (ZEBRA_ROUTE_OSPF6, argv[0]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_ospf6, + no_ripng_redistribute_ospf6_routemap_cmd, + "no redistribute ospf6 route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_bgp_routemap, + ripng_redistribute_bgp_routemap_cmd, + "redistribute bgp route-map WORD", + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_routemap_set (ZEBRA_ROUTE_BGP, argv[0]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_bgp, + no_ripng_redistribute_bgp_routemap_cmd, + "no redistribute bgp route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_kernel_metric_routemap, + ripng_redistribute_kernel_metric_routemap_cmd, + "redistribute kernel metric <0-16> route-map WORD", + "Redistribute information from another routing protocol\n" + "Kernel routes\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_KERNEL, atoi (argv[0])); + ripng_redistribute_routemap_set (ZEBRA_ROUTE_KERNEL, argv[1]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_kernel, + no_ripng_redistribute_kernel_metric_routemap_cmd, + "no redistribute kernel metric <0-16> route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "Kernel routes\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_connected_metric_routemap, + ripng_redistribute_connected_metric_routemap_cmd, + "redistribute connected metric <0-16> route-map WORD", + "Redistribute information from another routing protocol\n" + "Connected\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_CONNECT, atoi (argv[0])); + ripng_redistribute_routemap_set (ZEBRA_ROUTE_CONNECT, argv[1]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_connected, + no_ripng_redistribute_connected_metric_routemap_cmd, + "no redistribute connected metric <0-16> route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "Connected\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_static_metric_routemap, + ripng_redistribute_static_metric_routemap_cmd, + "redistribute static metric <0-16> route-map WORD", + "Redistribute information from another routing protocol\n" + "Static routes\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_STATIC, atoi (argv[0])); + ripng_redistribute_routemap_set (ZEBRA_ROUTE_STATIC, argv[1]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_static, + no_ripng_redistribute_static_metric_routemap_cmd, + "no redistribute static metric <0-16> route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "Static routes\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_ospf6_metric_routemap, + ripng_redistribute_ospf6_metric_routemap_cmd, + "redistribute ospf6 metric <0-16> route-map WORD", + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_OSPF6, atoi (argv[0])); + ripng_redistribute_routemap_set (ZEBRA_ROUTE_OSPF6, argv[1]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_ospf6, + no_ripng_redistribute_ospf6_metric_routemap_cmd, + "no redistribute ospf6 metric <0-16> route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "IPv6 Open Shortest Path First (OSPFv3)\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +DEFUN (ripng_redistribute_bgp_metric_routemap, + ripng_redistribute_bgp_metric_routemap_cmd, + "redistribute bgp metric <0-16> route-map WORD", + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + ripng_redistribute_metric_set (ZEBRA_ROUTE_BGP, atoi (argv[0])); + ripng_redistribute_routemap_set (ZEBRA_ROUTE_BGP, argv[1]); + zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP); + return CMD_SUCCESS; +} + +ALIAS (no_ripng_redistribute_bgp, + no_ripng_redistribute_bgp_metric_routemap_cmd, + "no redistribute bgp metric <0-16> route-map WORD", + NO_STR + "Redistribute information from another routing protocol\n" + "Border Gateway Protocol (BGP)\n" + "Metric\n" + "Metric value\n" + "Route map reference\n" + "Pointer to route-map entries\n") + +void +ripng_redistribute_write (struct vty *vty) +{ + int i; + char *str[] = { "system", "kernel", "connected", "static", "rip", + "ripng", "ospf", "ospf6", "bgp"}; + + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) + if (i != zclient->redist_default && zclient->redist[i]) + { + if (ripng->route_map[i].metric_config) + { + if (ripng->route_map[i].name) + vty_out (vty, " redistribute %s metric %d route-map %s%s", + str[i], ripng->route_map[i].metric, + ripng->route_map[i].name, VTY_NEWLINE); + else + vty_out (vty, " redistribute %s metric %d%s", + str[i], ripng->route_map[i].metric, VTY_NEWLINE); + } + else + { + if (ripng->route_map[i].name) + vty_out (vty, " redistribute %s route-map %s%s", + str[i], ripng->route_map[i].name, VTY_NEWLINE); + else + vty_out (vty, " redistribute %s%s", str[i], VTY_NEWLINE); + } + } +} + +/* RIPng configuration write function. */ +int +zebra_config_write (struct vty *vty) +{ + if (! zclient->enable) + { + vty_out (vty, "no router zebra%s", VTY_NEWLINE); + return 1; + } + else if (! zclient->redist[ZEBRA_ROUTE_RIPNG]) + { + vty_out (vty, "router zebra%s", VTY_NEWLINE); + vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE); + return 1; + } + return 0; +} + +/* Zebra node structure. */ +struct cmd_node zebra_node = +{ + ZEBRA_NODE, + "%s(config-router)# ", +}; + +/* Initialize zebra structure and it's commands. */ +void +zebra_init () +{ + /* Allocate zebra structure. */ + zclient = zclient_new (); + zclient_init (zclient, ZEBRA_ROUTE_RIPNG); + + zclient->interface_up = ripng_interface_up; + zclient->interface_down = ripng_interface_down; + zclient->interface_add = ripng_interface_add; + zclient->interface_delete = ripng_interface_delete; + zclient->interface_address_add = ripng_interface_address_add; + zclient->interface_address_delete = ripng_interface_address_delete; + zclient->ipv6_route_add = ripng_zebra_read_ipv6; + zclient->ipv6_route_delete = ripng_zebra_read_ipv6; + + /* Install zebra node. */ + install_node (&zebra_node, zebra_config_write); + + /* Install command element for zebra node. */ + install_element (CONFIG_NODE, &router_zebra_cmd); + install_element (CONFIG_NODE, &no_router_zebra_cmd); + install_default (ZEBRA_NODE); + install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd); + install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_static_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_static_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_kernel_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_connected_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_connected_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_bgp_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_ospf6_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_kernel_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_metric_val_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_connected_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_connected_metric_cmd); + install_element (RIPNG_NODE, + &no_ripng_redistribute_connected_metric_val_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_static_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_static_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_static_metric_val_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_ospf6_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_metric_val_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_bgp_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_val_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_kernel_routemap_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_routemap_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_connected_routemap_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_connected_routemap_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_static_routemap_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_static_routemap_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_ospf6_routemap_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_routemap_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_bgp_routemap_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_routemap_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_kernel_metric_routemap_cmd); + install_element (RIPNG_NODE, + &no_ripng_redistribute_kernel_metric_routemap_cmd); + install_element (RIPNG_NODE, + &ripng_redistribute_connected_metric_routemap_cmd); + install_element (RIPNG_NODE, + &no_ripng_redistribute_connected_metric_routemap_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_static_metric_routemap_cmd); + install_element (RIPNG_NODE, + &no_ripng_redistribute_static_metric_routemap_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_ospf6_metric_routemap_cmd); + install_element (RIPNG_NODE, + &no_ripng_redistribute_ospf6_metric_routemap_cmd); + install_element (RIPNG_NODE, &ripng_redistribute_bgp_metric_routemap_cmd); + install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_routemap_cmd); +} diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c new file mode 100644 index 00000000..81f0ecad --- /dev/null +++ b/ripngd/ripngd.c @@ -0,0 +1,2526 @@ +/* RIPng daemon + * Copyright (C) 1998, 1999 Kunihiro Ishiguro + * + * 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> + +/* For struct udphdr. */ +#include <netinet/udp.h> + +#include "prefix.h" +#include "filter.h" +#include "log.h" +#include "thread.h" +#include "memory.h" +#include "if.h" +#include "stream.h" +#include "table.h" +#include "command.h" +#include "sockopt.h" +#include "distribute.h" +#include "plist.h" +#include "routemap.h" +#include "if_rmap.h" + +#include "ripngd/ripngd.h" +#include "ripngd/ripng_route.h" +#include "ripngd/ripng_debug.h" + +#define min(a, b) ((a) < (b) ? (a) : (b)) + +/* RIPng structure which includes many parameters related to RIPng + protocol. If ripng couldn't active or ripng doesn't configured, + ripng->fd must be negative value. */ +struct ripng *ripng = NULL; + +enum +{ + ripng_all_route, + ripng_changed_route, + ripng_split_horizon, + ripng_no_split_horizon +}; + +/* Prototypes. */ +void +ripng_output_process (struct interface *, struct sockaddr_in6 *, int, int); + +int +ripng_triggered_update (struct thread *); + +/* RIPng next hop specification. */ +struct ripng_nexthop +{ + enum ripng_nexthop_type + { + RIPNG_NEXTHOP_UNSPEC, + RIPNG_NEXTHOP_ADDRESS + } flag; + struct in6_addr address; +}; + +/* Utility function for making IPv6 address string. */ +const char * +inet6_ntop (struct in6_addr *p) +{ + static char buf[INET6_ADDRSTRLEN]; + + inet_ntop (AF_INET6, p, buf, INET6_ADDRSTRLEN); + + return buf; +} + +/* Allocate new ripng information. */ +struct ripng_info * +ripng_info_new () +{ + struct ripng_info *new; + + new = XCALLOC (MTYPE_RIPNG_ROUTE, sizeof (struct ripng_info)); + return new; +} + +/* Free ripng information. */ +void +ripng_info_free (struct ripng_info *rinfo) +{ + XFREE (MTYPE_RIPNG_ROUTE, rinfo); +} + +static int +setsockopt_so_recvbuf (int sock, int size) +{ + int ret; + + ret = setsockopt (sock, SOL_SOCKET, SO_RCVBUF, (char *) &size, sizeof (int)); + if (ret < 0) + zlog (NULL, LOG_ERR, "can't setsockopt SO_RCVBUF"); + return ret; +} + +/* Create ripng socket. */ +int +ripng_make_socket (void) +{ + int ret; + int sock; + struct sockaddr_in6 ripaddr; + + sock = socket (AF_INET6, SOCK_DGRAM, 0); + if (sock < 0) + { + zlog (NULL, LOG_ERR, "Can't make ripng socket"); + return sock; + } + + ret = setsockopt_so_recvbuf (sock, 8096); + if (ret < 0) + return ret; + ret = setsockopt_ipv6_pktinfo (sock, 1); + if (ret < 0) + return ret; + ret = setsockopt_ipv6_multicast_hops (sock, 255); + if (ret < 0) + return ret; + ret = setsockopt_ipv6_multicast_loop (sock, 0); + if (ret < 0) + return ret; + ret = setsockopt_ipv6_hoplimit (sock, 1); + if (ret < 0) + return ret; + + memset (&ripaddr, 0, sizeof (ripaddr)); + ripaddr.sin6_family = AF_INET6; +#ifdef SIN6_LEN + ripaddr.sin6_len = sizeof (struct sockaddr_in6); +#endif /* SIN6_LEN */ + ripaddr.sin6_port = htons (RIPNG_PORT_DEFAULT); + + ret = bind (sock, (struct sockaddr *) &ripaddr, sizeof (ripaddr)); + if (ret < 0) + { + zlog (NULL, LOG_ERR, "Can't bind ripng socket: %s.", strerror (errno)); + return ret; + } + return sock; +} + +/* Send RIPng packet. */ +int +ripng_send_packet (caddr_t buf, int bufsize, struct sockaddr_in6 *to, + struct interface *ifp) +{ + int ret; + struct msghdr msg; + struct iovec iov; + struct cmsghdr *cmsgptr; + char adata [256]; + struct in6_pktinfo *pkt; + struct sockaddr_in6 addr; + +#ifdef DEBUG + if (to) + zlog_info ("DEBUG RIPng: send to %s", inet6_ntop (&to->sin6_addr)); + zlog_info ("DEBUG RIPng: send if %s", ifp->name); + zlog_info ("DEBUG RIPng: send packet size %d", bufsize); +#endif /* DEBUG */ + + memset (&addr, 0, sizeof (struct sockaddr_in6)); + addr.sin6_family = AF_INET6; +#ifdef SIN6_LEN + addr.sin6_len = sizeof (struct sockaddr_in6); +#endif /* SIN6_LEN */ + addr.sin6_flowinfo = htonl (RIPNG_PRIORITY_DEFAULT); + + /* When destination is specified. */ + if (to != NULL) + { + addr.sin6_addr = to->sin6_addr; + addr.sin6_port = to->sin6_port; + } + else + { + inet_pton(AF_INET6, RIPNG_GROUP, &addr.sin6_addr); + addr.sin6_port = htons (RIPNG_PORT_DEFAULT); + } + + msg.msg_name = (void *) &addr; + msg.msg_namelen = sizeof (struct sockaddr_in6); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = (void *) adata; + msg.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)); + + iov.iov_base = buf; + iov.iov_len = bufsize; + + cmsgptr = (struct cmsghdr *)adata; + cmsgptr->cmsg_len = CMSG_LEN(sizeof (struct in6_pktinfo)); + cmsgptr->cmsg_level = IPPROTO_IPV6; + cmsgptr->cmsg_type = IPV6_PKTINFO; + + pkt = (struct in6_pktinfo *) CMSG_DATA (cmsgptr); + memset (&pkt->ipi6_addr, 0, sizeof (struct in6_addr)); + pkt->ipi6_ifindex = ifp->ifindex; + + ret = sendmsg (ripng->sock, &msg, 0); + + if (ret < 0) + zlog_warn ("RIPng send fail on %s: %s", ifp->name, strerror (errno)); + + return ret; +} + +/* Receive UDP RIPng packet from socket. */ +int +ripng_recv_packet (int sock, u_char *buf, int bufsize, + struct sockaddr_in6 *from, unsigned int *ifindex, + int *hoplimit) +{ + int ret; + struct msghdr msg; + struct iovec iov; + struct cmsghdr *cmsgptr; + struct in6_addr dst; + + /* Ancillary data. This store cmsghdr and in6_pktinfo. But at this + point I can't determine size of cmsghdr */ + char adata[1024]; + + /* Fill in message and iovec. */ + msg.msg_name = (void *) from; + msg.msg_namelen = sizeof (struct sockaddr_in6); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = (void *) adata; + msg.msg_controllen = sizeof adata; + iov.iov_base = buf; + iov.iov_len = bufsize; + + /* If recvmsg fail return minus value. */ + ret = recvmsg (sock, &msg, 0); + if (ret < 0) + return ret; + + for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; + cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) + { + /* I want interface index which this packet comes from. */ + if (cmsgptr->cmsg_level == IPPROTO_IPV6 && + cmsgptr->cmsg_type == IPV6_PKTINFO) + { + struct in6_pktinfo *ptr; + + ptr = (struct in6_pktinfo *) CMSG_DATA (cmsgptr); + *ifindex = ptr->ipi6_ifindex; + dst = ptr->ipi6_addr; + + if (*ifindex == 0) + zlog_warn ("Interface index returned by IPV6_PKTINFO is zero"); + } + + /* Incoming packet's multicast hop limit. */ + if (cmsgptr->cmsg_level == IPPROTO_IPV6 && + cmsgptr->cmsg_type == IPV6_HOPLIMIT) + *hoplimit = *((int *) CMSG_DATA (cmsgptr)); + } + + /* Hoplimit check shold be done when destination address is + multicast address. */ + if (! IN6_IS_ADDR_MULTICAST (&dst)) + *hoplimit = -1; + + return ret; +} + +/* Dump rip packet */ +void +ripng_packet_dump (struct ripng_packet *packet, int size, char *sndrcv) +{ + caddr_t lim; + struct rte *rte; + char *command_str; + + /* Set command string. */ + if (packet->command == RIPNG_REQUEST) + command_str = "request"; + else if (packet->command == RIPNG_RESPONSE) + command_str = "response"; + else + command_str = "unknown"; + + /* Dump packet header. */ + zlog_info ("%s %s version %d packet size %d", + sndrcv, command_str, packet->version, size); + + /* Dump each routing table entry. */ + rte = packet->rte; + + for (lim = (caddr_t) packet + size; (caddr_t) rte < lim; rte++) + { + if (rte->metric == RIPNG_METRIC_NEXTHOP) + zlog_info (" nexthop %s/%d", inet6_ntop (&rte->addr), rte->prefixlen); + else + zlog_info (" %s/%d metric %d tag %d", + inet6_ntop (&rte->addr), rte->prefixlen, + rte->metric, ntohs (rte->tag)); + } +} + +/* RIPng next hop address RTE (Route Table Entry). */ +void +ripng_nexthop_rte (struct rte *rte, + struct sockaddr_in6 *from, + struct ripng_nexthop *nexthop) +{ + char buf[INET6_BUFSIZ]; + + /* Logging before checking RTE. */ + if (IS_RIPNG_DEBUG_RECV) + zlog_info ("RIPng nexthop RTE address %s tag %d prefixlen %d", + inet6_ntop (&rte->addr), ntohs (rte->tag), rte->prefixlen); + + /* RFC2080 2.1.1 Next Hop: + The route tag and prefix length in the next hop RTE must be + set to zero on sending and ignored on receiption. */ + if (ntohs (rte->tag) != 0) + zlog_warn ("RIPng nexthop RTE with non zero tag value %d from %s", + ntohs (rte->tag), inet6_ntop (&from->sin6_addr)); + + if (rte->prefixlen != 0) + zlog_warn ("RIPng nexthop RTE with non zero prefixlen value %d from %s", + rte->prefixlen, inet6_ntop (&from->sin6_addr)); + + /* Specifying a value of 0:0:0:0:0:0:0:0 in the prefix field of a + next hop RTE indicates that the next hop address should be the + originator of the RIPng advertisement. An address specified as a + next hop must be a link-local address. */ + if (IN6_IS_ADDR_UNSPECIFIED (&rte->addr)) + { + nexthop->flag = RIPNG_NEXTHOP_UNSPEC; + memset (&nexthop->address, 0, sizeof (struct in6_addr)); + return; + } + + if (IN6_IS_ADDR_LINKLOCAL (&rte->addr)) + { + nexthop->flag = RIPNG_NEXTHOP_ADDRESS; + IPV6_ADDR_COPY (&nexthop->address, &rte->addr); + return; + } + + /* The purpose of the next hop RTE is to eliminate packets being + routed through extra hops in the system. It is particularly useful + when RIPng is not being run on all of the routers on a network. + Note that next hop RTE is "advisory". That is, if the provided + information is ignored, a possibly sub-optimal, but absolutely + valid, route may be taken. If the received next hop address is not + a link-local address, it should be treated as 0:0:0:0:0:0:0:0. */ + zlog_warn ("RIPng nexthop RTE with non link-local address %s from %s", + inet6_ntop (&rte->addr), + inet_ntop (AF_INET6, &from->sin6_addr, buf, INET6_BUFSIZ)); + + nexthop->flag = RIPNG_NEXTHOP_UNSPEC; + memset (&nexthop->address, 0, sizeof (struct in6_addr)); + + return; +} + +/* If ifp has same link-local address then return 1. */ +int +ripng_lladdr_check (struct interface *ifp, struct in6_addr *addr) +{ + listnode listnode; + struct connected *connected; + struct prefix *p; + + for (listnode = listhead (ifp->connected); listnode; nextnode (listnode)) + if ((connected = getdata (listnode)) != NULL) + { + p = connected->address; + + if (p->family == AF_INET6 && + IN6_IS_ADDR_LINKLOCAL (&p->u.prefix6) && + IN6_ARE_ADDR_EQUAL (&p->u.prefix6, addr)) + return 1; + } + return 0; +} + +/* RIPng route garbage collect timer. */ +int +ripng_garbage_collect (struct thread *t) +{ + struct ripng_info *rinfo; + struct route_node *rp; + + rinfo = THREAD_ARG (t); + rinfo->t_garbage_collect = NULL; + + /* Off timeout timer. */ + RIPNG_TIMER_OFF (rinfo->t_timeout); + + /* Get route_node pointer. */ + rp = rinfo->rp; + + /* Delete this route from the kernel. */ + ripng_zebra_ipv6_delete ((struct prefix_ipv6 *)&rp->p, + &rinfo->nexthop, rinfo->ifindex); + rinfo->flags &= ~RIPNG_RTF_FIB; + + /* Aggregate count decrement. */ + ripng_aggregate_decrement (rp, rinfo); + + /* Unlock route_node. */ + rp->info = NULL; + route_unlock_node (rp); + + /* Free RIPng routing information. */ + ripng_info_free (rinfo); + + return 0; +} + +/* Timeout RIPng routes. */ +int +ripng_timeout (struct thread *t) +{ + struct ripng_info *rinfo; + struct route_node *rp; + + rinfo = THREAD_ARG (t); + rinfo->t_timeout = NULL; + + /* Get route_node pointer. */ + rp = rinfo->rp; + + /* - The garbage-collection timer is set for 120 seconds. */ + RIPNG_TIMER_ON (rinfo->t_garbage_collect, ripng_garbage_collect, + ripng->garbage_time); + + /* - The metric for the route is set to 16 (infinity). This causes + the route to be removed from service. */ + rinfo->metric = RIPNG_METRIC_INFINITY; + + /* - The route change flag is to indicate that this entry has been + changed. */ + rinfo->flags |= RIPNG_RTF_CHANGED; + + /* - The output process is signalled to trigger a response. */ + ripng_event (RIPNG_TRIGGERED_UPDATE, 0); + + return 0; +} + +void +ripng_timeout_update (struct ripng_info *rinfo) +{ + if (rinfo->metric != RIPNG_METRIC_INFINITY) + { + RIPNG_TIMER_OFF (rinfo->t_timeout); + RIPNG_TIMER_ON (rinfo->t_timeout, ripng_timeout, ripng->timeout_time); + } +} + +/* Process RIPng route according to RFC2080. */ +void +ripng_route_process (struct rte *rte, struct sockaddr_in6 *from, + struct ripng_nexthop *ripng_nexthop, + struct interface *ifp) +{ + struct prefix_ipv6 p; + struct route_node *rp; + struct ripng_info *rinfo; + struct ripng_interface *ri; + struct in6_addr *nexthop; + u_char oldmetric; + int same = 0; + + /* Make prefix structure. */ + memset (&p, 0, sizeof (struct prefix_ipv6)); + p.family = AF_INET6; + /* p.prefix = rte->addr; */ + IPV6_ADDR_COPY (&p.prefix, &rte->addr); + p.prefixlen = rte->prefixlen; + + /* Make sure mask is applied. */ + /* XXX We have to check the prefix is valid or not before call + apply_mask_ipv6. */ + apply_mask_ipv6 (&p); + + /* Apply input filters. */ + ri = ifp->info; + + if (ri->list[RIPNG_FILTER_IN]) + { + if (access_list_apply (ri->list[RIPNG_FILTER_IN], &p) == FILTER_DENY) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by distribute in", + inet6_ntop (&p.prefix), p.prefixlen); + return; + } + } + if (ri->prefix[RIPNG_FILTER_IN]) + { + if (prefix_list_apply (ri->prefix[RIPNG_FILTER_IN], &p) == PREFIX_DENY) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by prefix-list in", + inet6_ntop (&p.prefix), p.prefixlen); + return; + } + } + + /* Modify entry. */ + if (ri->routemap[RIPNG_FILTER_IN]) + { + int ret; + struct ripng_info newinfo; + + memset (&rinfo, 0, sizeof (struct ripng_info)); + newinfo.metric = rte->metric; + + ret = route_map_apply (ri->routemap[RIPNG_FILTER_IN], + (struct prefix *)&p, RMAP_RIPNG, &newinfo); + + if (ret == RMAP_DENYMATCH) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by route-map in", + inet6_ntop (&p.prefix), p.prefixlen); + return; + } + + rte->metric = newinfo.metric; + } + + /* Set nexthop pointer. */ + if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS) + nexthop = &ripng_nexthop->address; + else + nexthop = &from->sin6_addr; + + /* Lookup RIPng routing table. */ + rp = route_node_get (ripng->table, (struct prefix *) &p); + + if (rp->info == NULL) + { + /* Now, check to see whether there is already an explicit route + for the destination prefix. If there is no such route, add + this route to the routing table, unless the metric is + infinity (there is no point in adding a route which + unusable). */ + if (rte->metric != RIPNG_METRIC_INFINITY) + { + rinfo = ripng_info_new (); + + /* - Setting the destination prefix and length to those in + the RTE. */ + rp->info = rinfo; + rinfo->rp = rp; + + /* - Setting the metric to the newly calculated metric (as + described above). */ + rinfo->metric = rte->metric; + rinfo->tag = ntohs (rte->tag); + + /* - Set the next hop address to be the address of the router + from which the datagram came or the next hop address + specified by a next hop RTE. */ + IPV6_ADDR_COPY (&rinfo->nexthop, nexthop); + IPV6_ADDR_COPY (&rinfo->from, &from->sin6_addr); + rinfo->ifindex = ifp->ifindex; + + /* - Initialize the timeout for the route. If the + garbage-collection timer is running for this route, stop it. */ + ripng_timeout_update (rinfo); + + /* - Set the route change flag. */ + rinfo->flags |= RIPNG_RTF_CHANGED; + + /* - Signal the output process to trigger an update (see section + 2.5). */ + ripng_event (RIPNG_TRIGGERED_UPDATE, 0); + + /* Finally, route goes into the kernel. */ + rinfo->type = ZEBRA_ROUTE_RIPNG; + rinfo->sub_type = RIPNG_ROUTE_RTE; + + ripng_zebra_ipv6_add (&p, &rinfo->nexthop, rinfo->ifindex); + rinfo->flags |= RIPNG_RTF_FIB; + + /* Aggregate check. */ + ripng_aggregate_increment (rp, rinfo); + } + } + else + { + rinfo = rp->info; + + /* If there is an existing route, compare the next hop address + to the address of the router from which the datagram came. + If this datagram is from the same router as the existing + route, reinitialize the timeout. */ + same = (IN6_ARE_ADDR_EQUAL (&rinfo->from, &from->sin6_addr) + && (rinfo->ifindex == ifp->ifindex)); + + if (same) + ripng_timeout_update (rinfo); + + /* Next, compare the metrics. If the datagram is from the same + router as the existing route, and the new metric is different + than the old one; or, if the new metric is lower than the old + one; do the following actions: */ + if ((same && rinfo->metric != rte->metric) || + rte->metric < rinfo->metric) + { + /* - Adopt the route from the datagram. That is, put the + new metric in, and adjust the next hop address (if + necessary). */ + oldmetric = rinfo->metric; + rinfo->metric = rte->metric; + rinfo->tag = ntohs (rte->tag); + + if (! IN6_ARE_ADDR_EQUAL (&rinfo->nexthop, nexthop)) + { + ripng_zebra_ipv6_delete (&p, &rinfo->nexthop, rinfo->ifindex); + ripng_zebra_ipv6_add (&p, nexthop, ifp->ifindex); + rinfo->flags |= RIPNG_RTF_FIB; + + IPV6_ADDR_COPY (&rinfo->nexthop, nexthop); + } + IPV6_ADDR_COPY (&rinfo->from, &from->sin6_addr); + rinfo->ifindex = ifp->ifindex; + + /* - Set the route change flag and signal the output process + to trigger an update. */ + rinfo->flags |= RIPNG_RTF_CHANGED; + ripng_event (RIPNG_TRIGGERED_UPDATE, 0); + + /* - If the new metric is infinity, start the deletion + process (described above); */ + if (rinfo->metric == RIPNG_METRIC_INFINITY) + { + /* If the new metric is infinity, the deletion process + begins for the route, which is no longer used for + routing packets. Note that the deletion process is + started only when the metric is first set to + infinity. If the metric was already infinity, then a + new deletion process is not started. */ + if (oldmetric != RIPNG_METRIC_INFINITY) + { + /* - The garbage-collection timer is set for 120 seconds. */ + RIPNG_TIMER_ON (rinfo->t_garbage_collect, + ripng_garbage_collect, ripng->garbage_time); + RIPNG_TIMER_OFF (rinfo->t_timeout); + + /* - The metric for the route is set to 16 + (infinity). This causes the route to be removed + from service.*/ + /* - The route change flag is to indicate that this + entry has been changed. */ + /* - The output process is signalled to trigger a + response. */ + ; /* Above processes are already done previously. */ + } + } + else + { + /* otherwise, re-initialize the timeout. */ + ripng_timeout_update (rinfo); + + /* Should a new route to this network be established + while the garbage-collection timer is running, the + new route will replace the one that is about to be + deleted. In this case the garbage-collection timer + must be cleared. */ + RIPNG_TIMER_OFF (rinfo->t_garbage_collect); + } + } + /* Unlock tempolary lock of the route. */ + route_unlock_node (rp); + } +} + +/* Add redistributed route to RIPng table. */ +void +ripng_redistribute_add (int type, int sub_type, struct prefix_ipv6 *p, + unsigned int ifindex) +{ + struct route_node *rp; + struct ripng_info *rinfo; + + /* Redistribute route */ + if (IN6_IS_ADDR_LINKLOCAL (&p->prefix)) + return; + if (IN6_IS_ADDR_LOOPBACK (&p->prefix)) + return; + + rp = route_node_get (ripng->table, (struct prefix *) p); + rinfo = rp->info; + + if (rinfo) + { + RIPNG_TIMER_OFF (rinfo->t_timeout); + RIPNG_TIMER_OFF (rinfo->t_garbage_collect); + route_unlock_node (rp); + } + else + { + rinfo = ripng_info_new (); + ripng_aggregate_increment (rp, rinfo); + } + + rinfo->type = type; + rinfo->sub_type = sub_type; + rinfo->ifindex = ifindex; + rinfo->metric = 1; + rinfo->flags |= RIPNG_RTF_FIB; + + rinfo->rp = rp; + rp->info = rinfo; +} + +/* Delete redistributed route to RIPng table. */ +void +ripng_redistribute_delete (int type, int sub_type, struct prefix_ipv6 *p, + unsigned int ifindex) +{ + struct route_node *rp; + struct ripng_info *rinfo; + + if (IN6_IS_ADDR_LINKLOCAL (&p->prefix)) + return; + if (IN6_IS_ADDR_LOOPBACK (&p->prefix)) + return; + + rp = route_node_lookup (ripng->table, (struct prefix *) p); + + if (rp) + { + rinfo = rp->info; + + if (rinfo != NULL + && rinfo->type == type + && rinfo->sub_type == sub_type + && rinfo->ifindex == ifindex) + { + rp->info = NULL; + + RIPNG_TIMER_OFF (rinfo->t_timeout); + RIPNG_TIMER_OFF (rinfo->t_garbage_collect); + + ripng_info_free (rinfo); + + route_unlock_node (rp); + } + + /* For unlock route_node_lookup (). */ + route_unlock_node (rp); + } +} + +/* Withdraw redistributed route. */ +void +ripng_redistribute_withdraw (int type) +{ + struct route_node *rp; + struct ripng_info *rinfo; + + for (rp = route_top (ripng->table); rp; rp = route_next (rp)) + if ((rinfo = rp->info) != NULL) + { + if (rinfo->type == type) + { + rp->info = NULL; + + RIPNG_TIMER_OFF (rinfo->t_timeout); + RIPNG_TIMER_OFF (rinfo->t_garbage_collect); + + ripng_info_free (rinfo); + + route_unlock_node (rp); + } + } +} + +/* RIP routing information. */ +void +ripng_response_process (struct ripng_packet *packet, int size, + struct sockaddr_in6 *from, struct interface *ifp, + int hoplimit) +{ + caddr_t lim; + struct rte *rte; + struct ripng_nexthop nexthop; + + /* RFC2080 2.4.2 Response Messages: + The Response must be ignored if it is not from the RIPng port. */ + if (ntohs (from->sin6_port) != RIPNG_PORT_DEFAULT) + { + zlog_warn ("RIPng packet comes from non RIPng port %d from %s", + ntohs (from->sin6_port), inet6_ntop (&from->sin6_addr)); + return; + } + + /* The datagram's IPv6 source address should be checked to see + whether the datagram is from a valid neighbor; the source of the + datagram must be a link-local address. */ + if (! IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr)) + { + zlog_warn ("RIPng packet comes from non link local address %s", + inet6_ntop (&from->sin6_addr)); + return; + } + + /* It is also worth checking to see whether the response is from one + of the router's own addresses. Interfaces on broadcast networks + may receive copies of their own multicasts immediately. If a + router processes its own output as new input, confusion is likely, + and such datagrams must be ignored. */ + if (ripng_lladdr_check (ifp, &from->sin6_addr)) + { + zlog_warn ("RIPng packet comes from my own link local address %s", + inet6_ntop (&from->sin6_addr)); + return; + } + + /* As an additional check, periodic advertisements must have their + hop counts set to 255, and inbound, multicast packets sent from the + RIPng port (i.e. periodic advertisement or triggered update + packets) must be examined to ensure that the hop count is 255. */ + if (hoplimit >= 0 && hoplimit != 255) + { + zlog_warn ("RIPng packet comes with non 255 hop count %d from %s", + hoplimit, inet6_ntop (&from->sin6_addr)); + return; + } + + /* Reset nexthop. */ + memset (&nexthop, 0, sizeof (struct ripng_nexthop)); + nexthop.flag = RIPNG_NEXTHOP_UNSPEC; + + /* Set RTE pointer. */ + rte = packet->rte; + + for (lim = ((caddr_t) packet) + size; (caddr_t) rte < lim; rte++) + { + /* First of all, we have to check this RTE is next hop RTE or + not. Next hop RTE is completely different with normal RTE so + we need special treatment. */ + if (rte->metric == RIPNG_METRIC_NEXTHOP) + { + ripng_nexthop_rte (rte, from, &nexthop); + continue; + } + + /* RTE information validation. */ + + /* - is the destination prefix valid (e.g., not a multicast + prefix and not a link-local address) A link-local address + should never be present in an RTE. */ + if (IN6_IS_ADDR_MULTICAST (&rte->addr)) + { + zlog_warn ("Destination prefix is a multicast address %s/%d [%d]", + inet6_ntop (&rte->addr), rte->prefixlen, rte->metric); + continue; + } + if (IN6_IS_ADDR_LINKLOCAL (&rte->addr)) + { + zlog_warn ("Destination prefix is a link-local address %s/%d [%d]", + inet6_ntop (&rte->addr), rte->prefixlen, rte->metric); + continue; + } + if (IN6_IS_ADDR_LOOPBACK (&rte->addr)) + { + zlog_warn ("Destination prefix is a loopback address %s/%d [%d]", + inet6_ntop (&rte->addr), rte->prefixlen, rte->metric); + continue; + } + + /* - is the prefix length valid (i.e., between 0 and 128, + inclusive) */ + if (rte->prefixlen > 128) + { + zlog_warn ("Invalid prefix length %s/%d from %s%%%s", + inet6_ntop (&rte->addr), rte->prefixlen, + inet6_ntop (&from->sin6_addr), ifp->name); + continue; + } + + /* - is the metric valid (i.e., between 1 and 16, inclusive) */ + if (! (rte->metric >= 1 && rte->metric <= 16)) + { + zlog_warn ("Invalid metric %d from %s%%%s", rte->metric, + inet6_ntop (&from->sin6_addr), ifp->name); + continue; + } + + /* Metric calculation. */ + rte->metric += ifp->metric; + if (rte->metric > RIPNG_METRIC_INFINITY) + rte->metric = RIPNG_METRIC_INFINITY; + + /* Routing table updates. */ + ripng_route_process (rte, from, &nexthop, ifp); + } +} + +/* Response to request message. */ +void +ripng_request_process (struct ripng_packet *packet,int size, + struct sockaddr_in6 *from, struct interface *ifp) +{ + caddr_t lim; + struct rte *rte; + struct prefix_ipv6 p; + struct route_node *rp; + struct ripng_info *rinfo; + struct ripng_interface *ri; + + /* Check RIPng process is enabled on this interface. */ + ri = ifp->info; + if (! ri->running) + return; + + /* When passive interface is specified, suppress responses */ + if (ri->passive) + return; + + lim = ((caddr_t) packet) + size; + rte = packet->rte; + + /* The Request is processed entry by entry. If there are no + entries, no response is given. */ + if (lim == (caddr_t) rte) + return; + + /* There is one special case. If there is exactly one entry in the + request, and it has a destination prefix of zero, a prefix length + of zero, and a metric of infinity (i.e., 16), then this is a + request to send the entire routing table. In that case, a call + is made to the output process to send the routing table to the + requesting address/port. */ + if (lim == ((caddr_t) (rte + 1)) && + IN6_IS_ADDR_UNSPECIFIED (&rte->addr) && + rte->prefixlen == 0 && + rte->metric == RIPNG_METRIC_INFINITY) + { + /* All route with split horizon */ + ripng_output_process (ifp, from, ripng_all_route, ripng_split_horizon); + } + else + { + /* Except for this special case, processing is quite simple. + Examine the list of RTEs in the Request one by one. For each + entry, look up the destination in the router's routing + database and, if there is a route, put that route's metric in + the metric field of the RTE. If there is no explicit route + to the specified destination, put infinity in the metric + field. Once all the entries have been filled in, change the + command from Request to Response and send the datagram back + to the requestor. */ + memset (&p, 0, sizeof (struct prefix_ipv6)); + p.family = AF_INET6; + + for (; ((caddr_t) rte) < lim; rte++) + { + p.prefix = rte->addr; + p.prefixlen = rte->prefixlen; + apply_mask_ipv6 (&p); + + rp = route_node_lookup (ripng->table, (struct prefix *) &p); + + if (rp) + { + rinfo = rp->info; + rte->metric = rinfo->metric; + route_unlock_node (rp); + } + else + rte->metric = RIPNG_METRIC_INFINITY; + } + packet->command = RIPNG_RESPONSE; + + ripng_send_packet ((caddr_t) packet, size, from, ifp); + } +} + +/* First entry point of reading RIPng packet. */ +int +ripng_read (struct thread *thread) +{ + int len; + int sock; + struct sockaddr_in6 from; + struct ripng_packet *packet; + unsigned int ifindex; + struct interface *ifp; + int hoplimit = -1; + + /* Check ripng is active and alive. */ + assert (ripng != NULL); + assert (ripng->sock >= 0); + + /* Fetch thread data and set read pointer to empty for event + managing. `sock' sould be same as ripng->sock. */ + sock = THREAD_FD (thread); + ripng->t_read = NULL; + + /* Add myself to the next event. */ + ripng_event (RIPNG_READ, sock); + + /* Read RIPng packet. */ + len = ripng_recv_packet (sock, STREAM_DATA (ripng->ibuf), + STREAM_SIZE (ripng->ibuf), &from, &ifindex, + &hoplimit); + if (len < 0) + { + zlog_warn ("RIPng recvfrom failed: %s.", strerror (errno)); + return len; + } + + /* Check RTE boundary. RTE size (Packet length - RIPng header size + (4)) must be multiple size of one RTE size (20). */ + if (((len - 4) % 20) != 0) + { + zlog_warn ("RIPng invalid packet size %d from %s", len, + inet6_ntop (&from.sin6_addr)); + return 0; + } + + packet = (struct ripng_packet *) STREAM_DATA (ripng->ibuf); + ifp = if_lookup_by_index (ifindex); + + /* RIPng packet received. */ + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng packet received from %s port %d on %s", + inet6_ntop (&from.sin6_addr), ntohs (from.sin6_port), + ifp ? ifp->name : "unknown"); + + /* Logging before packet checking. */ + if (IS_RIPNG_DEBUG_RECV) + ripng_packet_dump (packet, len, "RECV"); + + /* Packet comes from unknown interface. */ + if (ifp == NULL) + { + zlog_warn ("RIPng packet comes from unknown interface %d", ifindex); + return 0; + } + + /* Packet version mismatch checking. */ + if (packet->version != ripng->version) + { + zlog_warn ("RIPng packet version %d doesn't fit to my version %d", + packet->version, ripng->version); + return 0; + } + + /* Process RIPng packet. */ + switch (packet->command) + { + case RIPNG_REQUEST: + ripng_request_process (packet, len, &from, ifp); + break; + case RIPNG_RESPONSE: + ripng_response_process (packet, len, &from, ifp, hoplimit); + break; + default: + zlog_warn ("Invalid RIPng command %d", packet->command); + break; + } + return 0; +} + +/* Walk down the RIPng routing table then clear changed flag. */ +void +ripng_clear_changed_flag () +{ + struct route_node *rp; + struct ripng_info *rinfo; + + for (rp = route_top (ripng->table); rp; rp = route_next (rp)) + if ((rinfo = rp->info) != NULL) + if (rinfo->flags & RIPNG_RTF_CHANGED) + rinfo->flags &= ~RIPNG_RTF_CHANGED; +} + +/* Regular update of RIPng route. Send all routing formation to RIPng + enabled interface. */ +int +ripng_update (struct thread *t) +{ + listnode node; + struct interface *ifp; + struct ripng_interface *ri; + + /* Clear update timer thread. */ + ripng->t_update = NULL; + + /* Logging update event. */ + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng update timer expired!"); + + /* Supply routes to each interface. */ + for (node = listhead (iflist); node; nextnode (node)) + { + ifp = getdata (node); + ri = ifp->info; + + if (if_is_loopback (ifp) || ! if_is_up (ifp)) + continue; + + if (! ri->running) + continue; + + /* When passive interface is specified, suppress announce to the + interface. */ + if (ri->passive) + continue; + +#if RIPNG_ADVANCED + if (ri->ri_send == RIPNG_SEND_OFF) + { + if (IS_RIPNG_DEBUG_EVENT) + zlog (NULL, LOG_INFO, + "[Event] RIPng send to if %d is suppressed by config", + ifp->ifindex); + continue; + } +#endif /* RIPNG_ADVANCED */ + + ripng_output_process (ifp, NULL, ripng_all_route, ripng_split_horizon); + } + + /* Triggered updates may be suppressed if a regular update is due by + the time the triggered update would be sent. */ + if (ripng->t_triggered_interval) + { + thread_cancel (ripng->t_triggered_interval); + ripng->t_triggered_interval = NULL; + } + ripng->trigger = 0; + + /* Reset flush event. */ + ripng_event (RIPNG_UPDATE_EVENT, 0); + + return 0; +} + +/* Triggered update interval timer. */ +int +ripng_triggered_interval (struct thread *t) +{ + ripng->t_triggered_interval = NULL; + + if (ripng->trigger) + { + ripng->trigger = 0; + ripng_triggered_update (t); + } + return 0; +} + +/* Execute triggered update. */ +int +ripng_triggered_update (struct thread *t) +{ + listnode node; + struct interface *ifp; + struct ripng_interface *ri; + int interval; + + ripng->t_triggered_update = NULL; + + /* Cancel interval timer. */ + if (ripng->t_triggered_interval) + { + thread_cancel (ripng->t_triggered_interval); + ripng->t_triggered_interval = NULL; + } + ripng->trigger = 0; + + /* Logging triggered update. */ + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng triggered update!"); + + /* Split Horizon processing is done when generating triggered + updates as well as normal updates (see section 2.6). */ + for (node = listhead (iflist); node; nextnode (node)) + { + ifp = getdata (node); + ri = ifp->info; + + if (if_is_loopback (ifp) || ! if_is_up (ifp)) + continue; + + if (! ri->running) + continue; + + /* When passive interface is specified, suppress announce to the + interface. */ + if (ri->passive) + continue; + + ripng_output_process (ifp, NULL, ripng_changed_route, + ripng_split_horizon); + } + + /* Once all of the triggered updates have been generated, the route + change flags should be cleared. */ + ripng_clear_changed_flag (); + + /* After a triggered update is sent, a timer should be set for a + random interval between 1 and 5 seconds. If other changes that + would trigger updates occur before the timer expires, a single + update is triggered when the timer expires. */ + interval = (random () % 5) + 1; + + ripng->t_triggered_interval = + thread_add_timer (master, ripng_triggered_interval, NULL, interval); + + return 0; +} + +/* Write routing table entry to the stream and return next index of + the routing table entry in the stream. */ +int +ripng_write_rte (int num, struct stream *s, struct prefix_ipv6 *p, + u_int16_t tag, u_char metric) +{ + /* RIPng packet header. */ + if (num == 0) + { + stream_putc (s, RIPNG_RESPONSE); + stream_putc (s, RIPNG_V1); + stream_putw (s, 0); + } + + /* Write routing table entry. */ + stream_write (s, (caddr_t) &p->prefix, sizeof (struct in6_addr)); + stream_putw (s, tag); + stream_putc (s, p->prefixlen); + stream_putc (s, metric); + + return ++num; +} + +/* Send RESPONSE message to specified destination. */ +void +ripng_output_process (struct interface *ifp, struct sockaddr_in6 *to, + int route_type, int split_horizon) +{ + int ret; + struct stream *s; + struct route_node *rp; + struct ripng_info *rinfo; + struct ripng_interface *ri; + struct ripng_aggregate *aggregate; + struct prefix_ipv6 *p; + int num; + int mtu; + int rtemax; + u_char metric; + u_char metric_set; + + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng update routes on interface %s", ifp->name); + + /* Output stream get from ripng structre. XXX this should be + interface structure. */ + s = ripng->obuf; + + /* Reset stream and RTE counter. */ + stream_reset (s); + num = 0; + + mtu = ifp->mtu; + if (mtu < 0) + mtu = IFMINMTU; + + rtemax = (min (mtu, RIPNG_MAX_PACKET_SIZE) - + IPV6_HDRLEN - + sizeof (struct udphdr) - + sizeof (struct ripng_packet) + + sizeof (struct rte)) / sizeof (struct rte); + +#ifdef DEBUG + zlog_info ("DEBUG RIPng: ifmtu is %d", ifp->mtu); + zlog_info ("DEBUG RIPng: rtemax is %d", rtemax); +#endif /* DEBUG */ + + /* Get RIPng interface. */ + ri = ifp->info; + + for (rp = route_top (ripng->table); rp; rp = route_next (rp)) + { + if ((rinfo = rp->info) != NULL && rinfo->suppress == 0) + { + p = (struct prefix_ipv6 *) &rp->p; + metric = rinfo->metric; + + /* Changed route only output. */ + if (route_type == ripng_changed_route && + (! (rinfo->flags & RIPNG_RTF_CHANGED))) + continue; + + /* Split horizon. */ + if (split_horizon == ripng_split_horizon && + rinfo->ifindex == ifp->ifindex) + continue; + + /* Apply output filters.*/ + if (ri->list[RIPNG_FILTER_OUT]) + { + if (access_list_apply (ri->list[RIPNG_FILTER_OUT], + (struct prefix *) p) == FILTER_DENY) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by distribute out", + inet6_ntop (&p->prefix), p->prefixlen); + continue; + } + } + if (ri->prefix[RIPNG_FILTER_OUT]) + { + if (prefix_list_apply (ri->prefix[RIPNG_FILTER_OUT], + (struct prefix *) p) == PREFIX_DENY) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by prefix-list out", + inet6_ntop (&p->prefix), p->prefixlen); + continue; + } + } + + /* Preparation for route-map. */ + metric_set = 0; + + /* Route-map */ + if (ri->routemap[RIPNG_FILTER_OUT]) + { + int ret; + struct ripng_info newinfo; + + memset (&newinfo, 0, sizeof (struct ripng_info)); + newinfo.metric = metric; + + ret = route_map_apply (ri->routemap[RIPNG_FILTER_OUT], + (struct prefix *) p, RMAP_RIPNG, + &newinfo); + + if (ret == RMAP_DENYMATCH) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by route-map out", + inet6_ntop (&p->prefix), p->prefixlen); + return; + } + + metric = newinfo.metric; + metric_set = newinfo.metric_set; + } + + /* When the interface route-map does not set metric */ + if (! metric_set) + { + /* and the redistribute route-map is set. */ + if (ripng->route_map[rinfo->type].name) + { + int ret; + struct ripng_info newinfo; + + memset (&newinfo, 0, sizeof (struct ripng_info)); + newinfo.metric = metric; + + ret = route_map_apply (ripng->route_map[rinfo->type].map, + (struct prefix *) p, RMAP_RIPNG, + &newinfo); + + if (ret == RMAP_DENYMATCH) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by route-map", + inet6_ntop (&p->prefix), p->prefixlen); + continue; + } + + metric = newinfo.metric; + metric_set = newinfo.metric_set; + } + + /* When the redistribute route-map does not set metric. */ + if (! metric_set) + { + /* If the redistribute metric is set. */ + if (ripng->route_map[rinfo->type].metric_config + && rinfo->metric != RIPNG_METRIC_INFINITY) + { + metric = ripng->route_map[rinfo->type].metric; + } + else + { + /* If the route is not connected or localy generated + one, use default-metric value */ + if (rinfo->type != ZEBRA_ROUTE_RIPNG + && rinfo->type != ZEBRA_ROUTE_CONNECT + && rinfo->metric != RIPNG_METRIC_INFINITY) + metric = ripng->default_metric; + } + } + } + + /* Write RTE to the stream. */ + num = ripng_write_rte (num, s, p, rinfo->tag, metric); + if (num == rtemax) + { + ret = ripng_send_packet (STREAM_DATA (s), stream_get_endp (s), + to, ifp); + + if (ret >= 0 && IS_RIPNG_DEBUG_SEND) + ripng_packet_dump ((struct ripng_packet *)STREAM_DATA (s), + stream_get_endp(s), "SEND"); + num = 0; + stream_reset (s); + } + } + if ((aggregate = rp->aggregate) != NULL && + aggregate->count > 0 && + aggregate->suppress == 0) + { + p = (struct prefix_ipv6 *) &rp->p; + metric = aggregate->metric; + + /* Apply output filters.*/ + if (ri->list[RIPNG_FILTER_OUT]) + { + if (access_list_apply (ri->list[RIPNG_FILTER_OUT], + (struct prefix *) p) == FILTER_DENY) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by distribute out", + inet6_ntop (&p->prefix), p->prefixlen); + continue; + } + } + if (ri->prefix[RIPNG_FILTER_OUT]) + { + if (prefix_list_apply (ri->prefix[RIPNG_FILTER_OUT], + (struct prefix *) p) == PREFIX_DENY) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by prefix-list out", + inet6_ntop (&p->prefix), p->prefixlen); + continue; + } + } + + /* Route-map */ + if (ri->routemap[RIPNG_FILTER_OUT]) + { + int ret; + struct ripng_info newinfo; + + memset (&newinfo, 0, sizeof (struct ripng_info)); + newinfo.metric = metric; + + ret = route_map_apply (ri->routemap[RIPNG_FILTER_OUT], + (struct prefix *) p, RMAP_RIPNG, + &newinfo); + + if (ret == RMAP_DENYMATCH) + { + if (IS_RIPNG_DEBUG_PACKET) + zlog_info ("RIPng %s/%d is filtered by route-map out", + inet6_ntop (&p->prefix), p->prefixlen); + return; + } + + metric = newinfo.metric; + } + + /* Changed route only output. */ + if (route_type == ripng_changed_route) + continue; + + /* Write RTE to the stream. */ + num = ripng_write_rte (num, s, p, aggregate->tag, metric); + if (num == rtemax) + { + ret = ripng_send_packet (STREAM_DATA (s), stream_get_endp (s), + to, ifp); + + if (ret >= 0 && IS_RIPNG_DEBUG_SEND) + ripng_packet_dump ((struct ripng_packet *)STREAM_DATA (s), + stream_get_endp(s), "SEND"); + num = 0; + stream_reset (s); + } + } + + } + + /* If unwritten RTE exist, flush it. */ + if (num != 0) + { + ret = ripng_send_packet (STREAM_DATA (s), stream_get_endp (s), + to, ifp); + + if (ret >= 0 && IS_RIPNG_DEBUG_SEND) + ripng_packet_dump ((struct ripng_packet *)STREAM_DATA (s), + stream_get_endp (s), "SEND"); + num = 0; + stream_reset (s); + } +} + +/* Create new RIPng instance and set it to global variable. */ +int +ripng_create () +{ + /* ripng should be NULL. */ + assert (ripng == NULL); + + /* Allocaste RIPng instance. */ + ripng = XMALLOC (0, sizeof (struct ripng)); + memset (ripng, 0, sizeof (struct ripng)); + + /* Default version and timer values. */ + ripng->version = RIPNG_V1; + ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT; + ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT; + ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT; + ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT; + + /* Make buffer. */ + ripng->ibuf = stream_new (RIPNG_MAX_PACKET_SIZE * 5); + ripng->obuf = stream_new (RIPNG_MAX_PACKET_SIZE); + + /* Initialize RIPng routig table. */ + ripng->table = route_table_init (); + ripng->route = route_table_init (); + ripng->aggregate = route_table_init (); + + /* Make socket. */ + ripng->sock = ripng_make_socket (); + if (ripng->sock < 0) + return ripng->sock; + + /* Threads. */ + ripng_event (RIPNG_READ, ripng->sock); + ripng_event (RIPNG_UPDATE_EVENT, 1); + + return 0; +} + +/* Sned RIPng request to the interface. */ +int +ripng_request (struct interface *ifp) +{ + struct rte *rte; + struct ripng_packet ripng_packet; + + if (IS_RIPNG_DEBUG_EVENT) + zlog_info ("RIPng send request to %s", ifp->name); + + memset (&ripng_packet, 0, sizeof (ripng_packet)); + ripng_packet.command = RIPNG_REQUEST; + ripng_packet.version = RIPNG_V1; + rte = ripng_packet.rte; + rte->metric = RIPNG_METRIC_INFINITY; + + return ripng_send_packet ((caddr_t) &ripng_packet, sizeof (ripng_packet), + NULL, ifp); +} + +/* Clean up installed RIPng routes. */ +void +ripng_terminate () +{ + struct route_node *rp; + struct ripng_info *rinfo; + + for (rp = route_top (ripng->table); rp; rp = route_next (rp)) + if ((rinfo = rp->info) != NULL) + { + if (rinfo->type == ZEBRA_ROUTE_RIPNG && + rinfo->sub_type == RIPNG_ROUTE_RTE) + ripng_zebra_ipv6_delete ((struct prefix_ipv6 *)&rp->p, + &rinfo->nexthop, rinfo->ifindex); + } +} + +int +ripng_update_jitter (int time) +{ + return ((rand () % (time + 1)) - (time / 2)); +} + +void +ripng_event (enum ripng_event event, int sock) +{ + int ripng_request_all (struct thread *); + int jitter = 0; + + switch (event) + { + case RIPNG_READ: + if (!ripng->t_read) + ripng->t_read = thread_add_read (master, ripng_read, NULL, sock); + break; + case RIPNG_UPDATE_EVENT: + if (ripng->t_update) + { + thread_cancel (ripng->t_update); + ripng->t_update = NULL; + } + /* Update timer jitter. */ + jitter = ripng_update_jitter (ripng->update_time); + + ripng->t_update = + thread_add_timer (master, ripng_update, NULL, + sock ? 2 : ripng->update_time + jitter); + break; + case RIPNG_TRIGGERED_UPDATE: + if (ripng->t_triggered_interval) + ripng->trigger = 1; + else if (! ripng->t_triggered_update) + ripng->t_triggered_update = + thread_add_event (master, ripng_triggered_update, NULL, 0); + break; + default: + break; + } +} + +/* Each route type's strings and default preference. */ +struct +{ + int key; + char *str; + char *str_long; + int distance; +} route_info[] = +{ + { ZEBRA_ROUTE_SYSTEM, "X", "system", 10}, + { ZEBRA_ROUTE_KERNEL, "K", "kernel", 20}, + { ZEBRA_ROUTE_CONNECT, "C", "connected", 30}, + { ZEBRA_ROUTE_STATIC, "S", "static", 40}, + { ZEBRA_ROUTE_RIP, "R", "rip", 50}, + { ZEBRA_ROUTE_RIPNG, "R", "ripng", 50}, + { ZEBRA_ROUTE_OSPF, "O", "ospf", 60}, + { ZEBRA_ROUTE_OSPF6, "O", "ospf6", 60}, + { ZEBRA_ROUTE_BGP, "B", "bgp", 70}, +}; + +/* For messages. */ +struct message ripng_route_info[] = +{ + { RIPNG_ROUTE_RTE, " "}, + { RIPNG_ROUTE_STATIC, "S"}, + { RIPNG_ROUTE_AGGREGATE, "a"} +}; + +/* Print out routes update time. */ +static void +ripng_vty_out_uptime (struct vty *vty, struct ripng_info *rinfo) +{ + struct timeval timer_now; + time_t clock; + struct tm *tm; +#define TIME_BUF 25 + char timebuf [TIME_BUF]; + struct thread *thread; + + gettimeofday (&timer_now, NULL); + + if ((thread = rinfo->t_timeout) != NULL) + { + clock = thread->u.sands.tv_sec - timer_now.tv_sec; + tm = gmtime (&clock); + strftime (timebuf, TIME_BUF, "%M:%S", tm); + vty_out (vty, "%5s", timebuf); + } + else if ((thread = rinfo->t_garbage_collect) != NULL) + { + clock = thread->u.sands.tv_sec - timer_now.tv_sec; + tm = gmtime (&clock); + strftime (timebuf, TIME_BUF, "%M:%S", tm); + vty_out (vty, "%5s", timebuf); + } +} + +DEFUN (show_ipv6_ripng, + show_ipv6_ripng_cmd, + "show ipv6 ripng", + SHOW_STR + IP_STR + "Show RIPng routes\n") +{ + struct route_node *rp; + struct ripng_info *rinfo; + struct ripng_aggregate *aggregate; + struct prefix_ipv6 *p; + int len; + + /* Header of display. */ + vty_out (vty, "%sCodes: R - RIPng%s%s" + " Network " + "Next Hop If Met Tag Time%s", VTY_NEWLINE, + VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE); + + for (rp = route_top (ripng->table); rp; rp = route_next (rp)) + { + if ((aggregate = rp->aggregate) != NULL) + { + p = (struct prefix_ipv6 *) &rp->p; + +#ifdef DEBUG + len = vty_out (vty, "Ra %d/%d %s/%d ", + aggregate->count, aggregate->suppress, + inet6_ntop (&p->prefix), p->prefixlen); +#else + len = vty_out (vty, "Ra %s/%d ", + inet6_ntop (&p->prefix), p->prefixlen); +#endif /* DEBUG */ + + len = 37 - len; + if (len > 0) + vty_out (vty, "%*s", len, " "); + + vty_out (vty, "%*s", 26, " "); + vty_out (vty, "%4d %3d%s", aggregate->metric, + aggregate->tag, + VTY_NEWLINE); + } + + if ((rinfo = rp->info) != NULL) + { + p = (struct prefix_ipv6 *) &rp->p; + +#ifdef DEBUG + len = vty_out (vty, "%s%s 0/%d %s/%d ", + route_info[rinfo->type].str, + rinfo->suppress ? "s" : " ", + rinfo->suppress, + inet6_ntop (&p->prefix), p->prefixlen); +#else + len = vty_out (vty, "%s%s %s/%d ", + route_info[rinfo->type].str, + rinfo->suppress ? "s" : " ", + inet6_ntop (&p->prefix), p->prefixlen); +#endif /* DEBUG */ + len = 37 - len; + if (len > 0) + vty_out (vty, "%*s", len, " "); + + len = vty_out (vty, "%s", inet6_ntop (&rinfo->nexthop)); + + len = 26 - len; + if (len > 0) + vty_out (vty, "%*s", len, " "); + + vty_out (vty, "%2d %2d %3d ", + rinfo->ifindex, rinfo->metric, rinfo->tag); + + if (rinfo->sub_type == RIPNG_ROUTE_RTE) + ripng_vty_out_uptime (vty, rinfo); + + vty_out (vty, "%s", VTY_NEWLINE); + } + } + + return CMD_SUCCESS; +} + +DEFUN (router_ripng, + router_ripng_cmd, + "router ripng", + "Enable a routing process\n" + "Make RIPng instance command\n") +{ + int ret; + + vty->node = RIPNG_NODE; + + if (!ripng) + { + ret = ripng_create (); + + /* Notice to user we couldn't create RIPng. */ + if (ret < 0) + { + zlog_warn ("can't create RIPng"); + return CMD_WARNING; + } + } + + return CMD_SUCCESS; +} + +DEFUN (ripng_route, + ripng_route_cmd, + "route IPV6ADDR", + "Static route setup\n" + "Set static RIPng route announcement\n") +{ + int ret; + struct prefix_ipv6 p; + struct route_node *rp; + + ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *)&p); + if (ret <= 0) + { + vty_out (vty, "Malformed address%s", VTY_NEWLINE); + return CMD_WARNING; + } + apply_mask_ipv6 (&p); + + rp = route_node_get (ripng->route, (struct prefix *) &p); + if (rp->info) + { + vty_out (vty, "There is already same static route.%s", VTY_NEWLINE); + route_unlock_node (rp); + return CMD_WARNING; + } + rp->info = (void *)1; + + ripng_redistribute_add (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0); + + return CMD_SUCCESS; +} + +DEFUN (no_ripng_route, + no_ripng_route_cmd, + "no route IPV6ADDR", + NO_STR + "Static route setup\n" + "Delete static RIPng route announcement\n") +{ + int ret; + struct prefix_ipv6 p; + struct route_node *rp; + + ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *)&p); + if (ret <= 0) + { + vty_out (vty, "Malformed address%s", VTY_NEWLINE); + return CMD_WARNING; + } + apply_mask_ipv6 (&p); + + rp = route_node_lookup (ripng->route, (struct prefix *) &p); + if (! rp) + { + vty_out (vty, "Can't find static route.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0); + route_unlock_node (rp); + + rp->info = NULL; + route_unlock_node (rp); + + return CMD_SUCCESS; +} + +DEFUN (ripng_aggregate_address, + ripng_aggregate_address_cmd, + "aggregate-address X:X::X:X/M", + "Set aggregate RIPng route announcement\n" + "Aggregate network\n") +{ + int ret; + struct prefix p; + struct route_node *node; + + ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *)&p); + if (ret <= 0) + { + vty_out (vty, "Malformed address%s", VTY_NEWLINE); + return CMD_WARNING; + } + + /* Check aggregate alredy exist or not. */ + node = route_node_get (ripng->aggregate, &p); + if (node->info) + { + vty_out (vty, "There is already same aggregate route.%s", VTY_NEWLINE); + route_unlock_node (node); + return CMD_WARNING; + } + node->info = (void *)1; + + ripng_aggregate_add (&p); + + return CMD_SUCCESS; +} + +DEFUN (no_ripng_aggregate_address, + no_ripng_aggregate_address_cmd, + "no aggregate-address X:X::X:X/M", + NO_STR + "Delete aggregate RIPng route announcement\n" + "Aggregate network") +{ + int ret; + struct prefix p; + struct route_node *rn; + + ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *) &p); + if (ret <= 0) + { + vty_out (vty, "Malformed address%s", VTY_NEWLINE); + return CMD_WARNING; + } + + rn = route_node_lookup (ripng->aggregate, &p); + if (! rn) + { + vty_out (vty, "Can't find aggregate route.%s", VTY_NEWLINE); + return CMD_WARNING; + } + route_unlock_node (rn); + rn->info = NULL; + route_unlock_node (rn); + + ripng_aggregate_delete (&p); + + return CMD_SUCCESS; +} + +DEFUN (ripng_default_metric, + ripng_default_metric_cmd, + "default-metric <1-16>", + "Set a metric of redistribute routes\n" + "Default metric\n") +{ + if (ripng) + { + ripng->default_metric = atoi (argv[0]); + } + return CMD_SUCCESS; +} + +DEFUN (no_ripng_default_metric, + no_ripng_default_metric_cmd, + "no default-metric", + NO_STR + "Set a metric of redistribute routes\n" + "Default metric\n") +{ + if (ripng) + { + ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT; + } + return CMD_SUCCESS; +} + +ALIAS (no_ripng_default_metric, + no_ripng_default_metric_val_cmd, + "no default-metric <1-16>", + NO_STR + "Set a metric of redistribute routes\n" + "Default metric\n") + +#if 0 +/* RIPng update timer setup. */ +DEFUN (ripng_update_timer, + ripng_update_timer_cmd, + "update-timer SECOND", + "Set RIPng update timer in seconds\n" + "Seconds\n") +{ + unsigned long update; + char *endptr = NULL; + + update = strtoul (argv[0], &endptr, 10); + if (update == ULONG_MAX || *endptr != '\0') + { + vty_out (vty, "update timer value error%s", VTY_NEWLINE); + return CMD_WARNING; + } + + ripng->update_time = update; + + ripng_event (RIPNG_UPDATE_EVENT, 0); + return CMD_SUCCESS; +} + +DEFUN (no_ripng_update_timer, + no_ripng_update_timer_cmd, + "no update-timer SECOND", + NO_STR + "Unset RIPng update timer in seconds\n" + "Seconds\n") +{ + ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT; + ripng_event (RIPNG_UPDATE_EVENT, 0); + return CMD_SUCCESS; +} + +/* RIPng timeout timer setup. */ +DEFUN (ripng_timeout_timer, + ripng_timeout_timer_cmd, + "timeout-timer SECOND", + "Set RIPng timeout timer in seconds\n" + "Seconds\n") +{ + unsigned long timeout; + char *endptr = NULL; + + timeout = strtoul (argv[0], &endptr, 10); + if (timeout == ULONG_MAX || *endptr != '\0') + { + vty_out (vty, "timeout timer value error%s", VTY_NEWLINE); + return CMD_WARNING; + } + + ripng->timeout_time = timeout; + + return CMD_SUCCESS; +} + +DEFUN (no_ripng_timeout_timer, + no_ripng_timeout_timer_cmd, + "no timeout-timer SECOND", + NO_STR + "Unset RIPng timeout timer in seconds\n" + "Seconds\n") +{ + ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT; + return CMD_SUCCESS; +} + +/* RIPng garbage timer setup. */ +DEFUN (ripng_garbage_timer, + ripng_garbage_timer_cmd, + "garbage-timer SECOND", + "Set RIPng garbage timer in seconds\n" + "Seconds\n") +{ + unsigned long garbage; + char *endptr = NULL; + + garbage = strtoul (argv[0], &endptr, 10); + if (garbage == ULONG_MAX || *endptr != '\0') + { + vty_out (vty, "garbage timer value error%s", VTY_NEWLINE); + return CMD_WARNING; + } + + ripng->garbage_time = garbage; + + return CMD_SUCCESS; +} + +DEFUN (no_ripng_garbage_timer, + no_ripng_garbage_timer_cmd, + "no garbage-timer SECOND", + NO_STR + "Unset RIPng garbage timer in seconds\n" + "Seconds\n") +{ + ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT; + return CMD_SUCCESS; +} +#endif /* 0 */ + +DEFUN (ripng_timers, + ripng_timers_cmd, + "timers basic <0-65535> <0-65535> <0-65535>", + "RIPng timers setup\n" + "Basic timer\n" + "Routing table update timer value in second. Default is 30.\n" + "Routing information timeout timer. Default is 180.\n" + "Garbage collection timer. Default is 120.\n") +{ + unsigned long update; + unsigned long timeout; + unsigned long garbage; + char *endptr = NULL; + + update = strtoul (argv[0], &endptr, 10); + if (update == ULONG_MAX || *endptr != '\0') + { + vty_out (vty, "update timer value error%s", VTY_NEWLINE); + return CMD_WARNING; + } + + timeout = strtoul (argv[1], &endptr, 10); + if (timeout == ULONG_MAX || *endptr != '\0') + { + vty_out (vty, "timeout timer value error%s", VTY_NEWLINE); + return CMD_WARNING; + } + + garbage = strtoul (argv[2], &endptr, 10); + if (garbage == ULONG_MAX || *endptr != '\0') + { + vty_out (vty, "garbage timer value error%s", VTY_NEWLINE); + return CMD_WARNING; + } + + /* Set each timer value. */ + ripng->update_time = update; + ripng->timeout_time = timeout; + ripng->garbage_time = garbage; + + /* Reset update timer thread. */ + ripng_event (RIPNG_UPDATE_EVENT, 0); + + return CMD_SUCCESS; +} + +DEFUN (no_ripng_timers, + no_ripng_timers_cmd, + "no timers basic", + NO_STR + "RIPng timers setup\n" + "Basic timer\n") +{ + /* Set each timer value to the default. */ + ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT; + ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT; + ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT; + + /* Reset update timer thread. */ + ripng_event (RIPNG_UPDATE_EVENT, 0); + + return CMD_SUCCESS; +} + + +DEFUN (show_ipv6_protocols, show_ipv6_protocols_cmd, + "show ipv6 protocols", + SHOW_STR + IP_STR + "Routing protocol information") +{ + if (! ripng) + return CMD_SUCCESS; + + vty_out (vty, "Routing Protocol is \"ripng\"%s", VTY_NEWLINE); + + vty_out (vty, "Sending updates every %ld seconds, next due in %d seconds%s", + ripng->update_time, 0, + VTY_NEWLINE); + + vty_out (vty, "Timerout after %ld seconds, garbage correct %ld%s", + ripng->timeout_time, + ripng->garbage_time, + VTY_NEWLINE); + + vty_out (vty, "Outgoing update filter list for all interfaces is not set"); + vty_out (vty, "Incoming update filter list for all interfaces is not set"); + + return CMD_SUCCESS; +} + +/* Please be carefull to use this command. */ +DEFUN (default_information_originate, + default_information_originate_cmd, + "default-information originate", + "Default route information\n" + "Distribute default route\n") +{ + struct prefix_ipv6 p; + + ripng->default_information = 1; + + str2prefix_ipv6 ("::/0", &p); + ripng_redistribute_add (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0); + + return CMD_SUCCESS; +} + +DEFUN (no_default_information_originate, + no_default_information_originate_cmd, + "no default-information originate", + NO_STR + "Default route information\n" + "Distribute default route\n") +{ + struct prefix_ipv6 p; + + ripng->default_information = 0; + + str2prefix_ipv6 ("::/0", &p); + ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0); + + return CMD_SUCCESS; +} + +/* RIPng configuration write function. */ +int +ripng_config_write (struct vty *vty) +{ + int ripng_network_write (struct vty *); + void ripng_redistribute_write (struct vty *); + int write = 0; + struct route_node *rp; + + if (ripng) + { + + /* RIPng router. */ + vty_out (vty, "router ripng%s", VTY_NEWLINE); + + if (ripng->default_information) + vty_out (vty, " default-information originate%s", VTY_NEWLINE); + + ripng_network_write (vty); + + /* RIPng default metric configuration */ + if (ripng->default_metric != RIPNG_DEFAULT_METRIC_DEFAULT) + vty_out (vty, " default-metric %d%s", + ripng->default_metric, VTY_NEWLINE); + + ripng_redistribute_write (vty); + + /* RIPng aggregate routes. */ + for (rp = route_top (ripng->aggregate); rp; rp = route_next (rp)) + if (rp->info != NULL) + vty_out (vty, " aggregate-address %s/%d%s", + inet6_ntop (&rp->p.u.prefix6), + rp->p.prefixlen, + + VTY_NEWLINE); + + /* RIPng static routes. */ + for (rp = route_top (ripng->route); rp; rp = route_next (rp)) + if (rp->info != NULL) + vty_out (vty, " route %s/%d%s", inet6_ntop (&rp->p.u.prefix6), + rp->p.prefixlen, + VTY_NEWLINE); + + /* RIPng timers configuration. */ + if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT || + ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT || + ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT) + { + vty_out (vty, " timers basic %ld %ld %ld%s", + ripng->update_time, + ripng->timeout_time, + ripng->garbage_time, + VTY_NEWLINE); + } +#if 0 + if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT) + vty_out (vty, " update-timer %d%s", ripng->update_time, + VTY_NEWLINE); + if (ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT) + vty_out (vty, " timeout-timer %d%s", ripng->timeout_time, + VTY_NEWLINE); + if (ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT) + vty_out (vty, " garbage-timer %d%s", ripng->garbage_time, + VTY_NEWLINE); +#endif /* 0 */ + + write += config_write_distribute (vty); + + write += config_write_if_rmap (vty); + + write++; + } + return write; +} + +/* RIPng node structure. */ +struct cmd_node cmd_ripng_node = +{ + RIPNG_NODE, + "%s(config-router)# ", + 1, +}; + +void +ripng_distribute_update (struct distribute *dist) +{ + struct interface *ifp; + struct ripng_interface *ri; + struct access_list *alist; + struct prefix_list *plist; + + if (! dist->ifname) + return; + + ifp = if_lookup_by_name (dist->ifname); + if (ifp == NULL) + return; + + ri = ifp->info; + + if (dist->list[DISTRIBUTE_IN]) + { + alist = access_list_lookup (AFI_IP6, dist->list[DISTRIBUTE_IN]); + if (alist) + ri->list[RIPNG_FILTER_IN] = alist; + else + ri->list[RIPNG_FILTER_IN] = NULL; + } + else + ri->list[RIPNG_FILTER_IN] = NULL; + + if (dist->list[DISTRIBUTE_OUT]) + { + alist = access_list_lookup (AFI_IP6, dist->list[DISTRIBUTE_OUT]); + if (alist) + ri->list[RIPNG_FILTER_OUT] = alist; + else + ri->list[RIPNG_FILTER_OUT] = NULL; + } + else + ri->list[RIPNG_FILTER_OUT] = NULL; + + if (dist->prefix[DISTRIBUTE_IN]) + { + plist = prefix_list_lookup (AFI_IP6, dist->prefix[DISTRIBUTE_IN]); + if (plist) + ri->prefix[RIPNG_FILTER_IN] = plist; + else + ri->prefix[RIPNG_FILTER_IN] = NULL; + } + else + ri->prefix[RIPNG_FILTER_IN] = NULL; + + if (dist->prefix[DISTRIBUTE_OUT]) + { + plist = prefix_list_lookup (AFI_IP6, dist->prefix[DISTRIBUTE_OUT]); + if (plist) + ri->prefix[RIPNG_FILTER_OUT] = plist; + else + ri->prefix[RIPNG_FILTER_OUT] = NULL; + } + else + ri->prefix[RIPNG_FILTER_OUT] = NULL; +} +void +ripng_distribute_update_interface (struct interface *ifp) +{ + struct distribute *dist; + + dist = distribute_lookup (ifp->name); + if (dist) + ripng_distribute_update (dist); +} + +/* Update all interface's distribute list. */ +void +ripng_distribute_update_all () +{ + struct interface *ifp; + listnode node; + + for (node = listhead (iflist); node; nextnode (node)) + { + ifp = getdata (node); + ripng_distribute_update_interface (ifp); + } +} + +void +ripng_if_rmap_update (struct if_rmap *if_rmap) +{ + struct interface *ifp; + struct ripng_interface *ri; + struct route_map *rmap; + + ifp = if_lookup_by_name (if_rmap->ifname); + if (ifp == NULL) + return; + + ri = ifp->info; + + if (if_rmap->routemap[IF_RMAP_IN]) + { + rmap = route_map_lookup_by_name (if_rmap->routemap[IF_RMAP_IN]); + if (rmap) + ri->routemap[IF_RMAP_IN] = rmap; + else + ri->routemap[IF_RMAP_IN] = NULL; + } + else + ri->routemap[RIPNG_FILTER_IN] = NULL; + + if (if_rmap->routemap[IF_RMAP_OUT]) + { + rmap = route_map_lookup_by_name (if_rmap->routemap[IF_RMAP_OUT]); + if (rmap) + ri->routemap[IF_RMAP_OUT] = rmap; + else + ri->routemap[IF_RMAP_OUT] = NULL; + } + else + ri->routemap[RIPNG_FILTER_OUT] = NULL; +} + +void +ripng_if_rmap_update_interface (struct interface *ifp) +{ + struct if_rmap *if_rmap; + + if_rmap = if_rmap_lookup (ifp->name); + if (if_rmap) + ripng_if_rmap_update (if_rmap); +} + +void +ripng_routemap_update_redistribute (void) +{ + int i; + + if (ripng) + { + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) + { + if (ripng->route_map[i].name) + ripng->route_map[i].map = + route_map_lookup_by_name (ripng->route_map[i].name); + } + } +} + +void +ripng_routemap_update () +{ + struct interface *ifp; + listnode node; + + for (node = listhead (iflist); node; nextnode (node)) + { + ifp = getdata (node); + ripng_if_rmap_update_interface (ifp); + } + + ripng_routemap_update_redistribute (); +} + +/* Initialize ripng structure and set commands. */ +void +ripng_init () +{ + /* Randomize. */ + srand (time (NULL)); + + /* Install RIPNG_NODE. */ + install_node (&cmd_ripng_node, ripng_config_write); + + /* Install ripng commands. */ + install_element (VIEW_NODE, &show_ipv6_ripng_cmd); + + install_element (ENABLE_NODE, &show_ipv6_ripng_cmd); + + install_element (CONFIG_NODE, &router_ripng_cmd); + + install_default (RIPNG_NODE); + install_element (RIPNG_NODE, &ripng_route_cmd); + install_element (RIPNG_NODE, &no_ripng_route_cmd); + install_element (RIPNG_NODE, &ripng_aggregate_address_cmd); + install_element (RIPNG_NODE, &no_ripng_aggregate_address_cmd); + + install_element (RIPNG_NODE, &ripng_default_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_default_metric_cmd); + install_element (RIPNG_NODE, &no_ripng_default_metric_val_cmd); + + install_element (RIPNG_NODE, &ripng_timers_cmd); + install_element (RIPNG_NODE, &no_ripng_timers_cmd); +#if 0 + install_element (RIPNG_NODE, &ripng_update_timer_cmd); + install_element (RIPNG_NODE, &no_ripng_update_timer_cmd); + install_element (RIPNG_NODE, &ripng_timeout_timer_cmd); + install_element (RIPNG_NODE, &no_ripng_timeout_timer_cmd); + install_element (RIPNG_NODE, &ripng_garbage_timer_cmd); + install_element (RIPNG_NODE, &no_ripng_garbage_timer_cmd); +#endif /* 0 */ + + install_element (RIPNG_NODE, &default_information_originate_cmd); + install_element (RIPNG_NODE, &no_default_information_originate_cmd); + + ripng_if_init (); + ripng_debug_init (); + + /* Access list install. */ + access_list_init (); + access_list_add_hook (ripng_distribute_update_all); + access_list_delete_hook (ripng_distribute_update_all); + + /* Prefix list initialize.*/ + prefix_list_init (); + prefix_list_add_hook (ripng_distribute_update_all); + prefix_list_delete_hook (ripng_distribute_update_all); + + /* Distribute list install. */ + distribute_list_init (RIPNG_NODE); + distribute_list_add_hook (ripng_distribute_update); + distribute_list_delete_hook (ripng_distribute_update); + + /* Route-map for interface. */ + ripng_route_map_init (); + route_map_add_hook (ripng_routemap_update); + route_map_delete_hook (ripng_routemap_update); + + if_rmap_init (RIPNG_NODE); + if_rmap_hook_add (ripng_if_rmap_update); + if_rmap_hook_delete (ripng_if_rmap_update); +} diff --git a/ripngd/ripngd.conf.sample b/ripngd/ripngd.conf.sample new file mode 100644 index 00000000..ad673e57 --- /dev/null +++ b/ripngd/ripngd.conf.sample @@ -0,0 +1,22 @@ +! -*- rip -*- +! +! RIPngd sample configuration file +! +! $Id: ripngd.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ +! +hostname ripngd +password zebra +! +! debug ripng events +! debug ripng packet +! +! +router ripng +! network sit1 +! route 3ffe:506::0/32 +! distribute-list local-only out sit1 +! +!ipv6 access-list local-only permit 3ffe:506::0/32 +!ipv6 access-list local-only deny any +! +log stdout diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h new file mode 100644 index 00000000..2509bdd5 --- /dev/null +++ b/ripngd/ripngd.h @@ -0,0 +1,318 @@ +/* + * RIPng related value and structure. + * Copyright (C) 1998 Kunihiro Ishiguro + * + * 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. + */ + +#ifndef _ZEBRA_RIPNG_RIPNGD_H +#define _ZEBRA_RIPNG_RIPNGD_H + +/* RIPng version and port number. */ +#define RIPNG_V1 1 +#define RIPNG_PORT_DEFAULT 521 +#define RIPNG_VTY_PORT 2603 +#define RIPNG_VTYSH_PATH "/tmp/.ripngd" +#define RIPNG_MAX_PACKET_SIZE 1500 +#define RIPNG_PRIORITY_DEFAULT 0 + +/* RIPng commands. */ +#define RIPNG_REQUEST 1 +#define RIPNG_RESPONSE 2 + +/* RIPng metric and multicast group address. */ +#define RIPNG_METRIC_INFINITY 16 +#define RIPNG_METRIC_NEXTHOP 0xff +#define RIPNG_GROUP "ff02::9" + +/* RIPng timers. */ +#define RIPNG_UPDATE_TIMER_DEFAULT 30 +#define RIPNG_TIMEOUT_TIMER_DEFAULT 180 +#define RIPNG_GARBAGE_TIMER_DEFAULT 120 + +/* Default config file name. */ +#define RIPNG_DEFAULT_CONFIG "ripngd.conf" + +/* RIPng route types. */ +#define RIPNG_ROUTE_RTE 0 +#define RIPNG_ROUTE_STATIC 1 +#define RIPNG_ROUTE_AGGREGATE 2 + +/* Interface send/receive configuration. */ +#define RIPNG_SEND_UNSPEC 0 +#define RIPNG_SEND_OFF 1 +#define RIPNG_RECEIVE_UNSPEC 0 +#define RIPNG_RECEIVE_OFF 1 + +/* Split horizon definitions. */ +#define RIPNG_SPLIT_HORIZON_UNSPEC 0 +#define RIPNG_SPLIT_HORIZON_NONE 1 +#define RIPNG_SPLIT_HORIZON 2 +#define RIPNG_SPLIT_HORIZON_POISONED 3 + +/* RIP default route's accept/announce methods. */ +#define RIPNG_DEFAULT_ADVERTISE_UNSPEC 0 +#define RIPNG_DEFAULT_ADVERTISE_NONE 1 +#define RIPNG_DEFAULT_ADVERTISE 2 + +#define RIPNG_DEFAULT_ACCEPT_UNSPEC 0 +#define RIPNG_DEFAULT_ACCEPT_NONE 1 +#define RIPNG_DEFAULT_ACCEPT 2 + +/* Default value for "default-metric" command. */ +#define RIPNG_DEFAULT_METRIC_DEFAULT 1 + +/* For max RTE calculation. */ +#ifndef IPV6_HDRLEN +#define IPV6_HDRLEN 40 +#endif /* IPV6_HDRLEN */ + +#ifndef IFMINMTU +#define IFMINMTU 576 +#endif /* IFMINMTU */ + +/* RIPng structure. */ +struct ripng +{ + /* RIPng socket. */ + int sock; + + /* RIPng Parameters.*/ + u_char command; + u_char version; + unsigned long update_time; + unsigned long timeout_time; + unsigned long garbage_time; + int max_mtu; + int default_metric; + int default_information; + + /* Input/output buffer of RIPng. */ + struct stream *ibuf; + struct stream *obuf; + + /* RIPng routing information base. */ + struct route_table *table; + + /* RIPng only static route information. */ + struct route_table *route; + + /* RIPng aggregate route information. */ + struct route_table *aggregate; + + /* RIPng threads. */ + struct thread *t_read; + struct thread *t_write; + struct thread *t_update; + struct thread *t_garbage; + struct thread *t_zebra; + + /* Triggered update hack. */ + int trigger; + struct thread *t_triggered_update; + struct thread *t_triggered_interval; + + /* For redistribute route map. */ + struct + { + char *name; + struct route_map *map; + int metric_config; + u_int32_t metric; + } route_map[ZEBRA_ROUTE_MAX]; +}; + +/* Routing table entry. */ +struct rte +{ + struct in6_addr addr; + u_short tag; + u_char prefixlen; + u_char metric; +}; + +/* RIPNG send packet. */ +struct ripng_packet +{ + u_char command; + u_char version; + u_int16_t zero; + struct rte rte[1]; +}; + +/* Each route's information. */ +struct ripng_info +{ + /* This route's type. Static, ripng or aggregate. */ + u_char type; + + /* Sub type for static route. */ + u_char sub_type; + + /* RIPng specific information */ + struct in6_addr nexthop; + struct in6_addr from; + + /* Which interface does this route come from. */ + unsigned int ifindex; + + /* Metric of this route. */ + u_char metric; + + /* Tag field of RIPng packet.*/ + u_int16_t tag; + + /* For aggregation. */ + unsigned int suppress; + + /* Flags of RIPng route. */ +#define RIPNG_RTF_FIB 1 +#define RIPNG_RTF_CHANGED 2 + u_char flags; + + /* Garbage collect timer. */ + struct thread *t_timeout; + struct thread *t_garbage_collect; + + /* Route-map features - this variables can be changed. */ + u_char metric_set; + + struct route_node *rp; +}; + +/* RIPng tag structure. */ +struct ripng_tag +{ + /* Tag value. */ + u_int16_t tag; + + /* Port. */ + u_int16_t port; + + /* Multicast group. */ + struct in6_addr maddr; + + /* Table number. */ + int table; + + /* Distance. */ + int distance; + + /* Split horizon. */ + u_char split_horizon; + + /* Poison reverse. */ + u_char poison_reverse; +}; + +/* RIPng specific interface configuration. */ +struct ripng_interface +{ + /* RIPng is enabled on this interface. */ + int enable_network; + int enable_interface; + + /* RIPng is running on this interface. */ + int running; + + /* For filter type slot. */ +#define RIPNG_FILTER_IN 0 +#define RIPNG_FILTER_OUT 1 +#define RIPNG_FILTER_MAX 2 + + /* Access-list. */ + struct access_list *list[RIPNG_FILTER_MAX]; + + /* Prefix-list. */ + struct prefix_list *prefix[RIPNG_FILTER_MAX]; + + /* Route-map. */ + struct route_map *routemap[RIPNG_FILTER_MAX]; + + /* RIPng tag configuration. */ + struct ripng_tag *rtag; + + /* Default information originate. */ + u_char default_originate; + + /* Default information only. */ + u_char default_only; + + /* Wake up thread. */ + struct thread *t_wakeup; + + /* Passive interface. */ + int passive; +}; + +/* All RIPng events. */ +enum ripng_event +{ + RIPNG_READ, + RIPNG_ZEBRA, + RIPNG_REQUEST_EVENT, + RIPNG_UPDATE_EVENT, + RIPNG_TRIGGERED_UPDATE, +}; + +/* RIPng timer on/off macro. */ +#define RIPNG_TIMER_ON(T,F,V) \ +do { \ + if (!(T)) \ + (T) = thread_add_timer (master, (F), rinfo, (V)); \ +} while (0) + +#define RIPNG_TIMER_OFF(T) \ +do { \ + if (T) \ + { \ + thread_cancel(T); \ + (T) = NULL; \ + } \ +} while (0) + +/* Count prefix size from mask length */ +#define PSIZE(a) (((a) + 7) / (8)) + +/* Extern variables. */ +extern struct ripng *ripng; + +extern struct thread_master *master; + +/* Prototypes. */ +void ripng_init (); +void ripng_if_init (); +void ripng_terminate (); +void ripng_zclient_start (); +void zebra_init (); +struct ripng_info * ripng_info_new (); +void ripng_info_free (struct ripng_info *rinfo); +void ripng_event (enum ripng_event, int); +int ripng_request (struct interface *ifp); +void ripng_redistribute_add (int, int, struct prefix_ipv6 *, unsigned int); +void ripng_redistribute_delete (int, int, struct prefix_ipv6 *, unsigned int); +void ripng_redistribute_withdraw (int type); + +void ripng_distribute_update_interface (struct interface *); +void ripng_if_rmap_update_interface (struct interface *); + +void ripng_zebra_ipv6_add (struct prefix_ipv6 *p, struct in6_addr *nexthop, unsigned int ifindex); +void ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop, unsigned int ifindex); +void ripng_route_map_init (); + +#endif /* _ZEBRA_RIPNG_RIPNGD_H */ |