This file should have been deleted what ldp-portable was
[mpls-ldp-portable.git] / zebra-ldp.diff
blobaf1ece7ca8cc3bf50ded75a5571ad14701e6b2a8
1 diff -uNr --exclude=CVS zebra/Makefile.am zebra-ldp/Makefile.am
2 --- zebra/Makefile.am Sat Aug 24 00:14:53 2002
3 +++ zebra-ldp/Makefile.am Sat Aug 24 00:14:37 2002
4 @@ -1,6 +1,6 @@
5 ## Process this file with automake to produce Makefile.in.
7 -SUBDIRS = lib @ZEBRA@ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @VTYSH@ doc
8 +SUBDIRS = lib @ZEBRA@ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @MPLSD@ @VTYSH@ doc
10 EXTRA_DIST = aclocal.m4 SERVICES TODO REPORTING-BUGS vtysh/Makefile.in \
11 vtysh/Makefile.am update-autotools
12 diff -uNr --exclude=CVS zebra/Makefile.in zebra-ldp/Makefile.in
13 --- zebra/Makefile.in Sat Aug 24 00:14:53 2002
14 +++ zebra-ldp/Makefile.in Tue Nov 19 22:21:13 2002
15 @@ -82,6 +82,7 @@
16 LIBPAM = @LIBPAM@
17 LIB_IPV6 = @LIB_IPV6@
18 LIB_REGEX = @LIB_REGEX@
19 +MPLSD = @MPLSD@
20 MULTIPATH_NUM = @MULTIPATH_NUM@
21 OSPF6D = @OSPF6D@
22 OSPFD = @OSPFD@
23 @@ -100,7 +101,7 @@
24 am__quote = @am__quote@
25 install_sh = @install_sh@
27 -SUBDIRS = lib @ZEBRA@ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @VTYSH@ doc
28 +SUBDIRS = lib @ZEBRA@ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @MPLSD@ @VTYSH@ doc
30 EXTRA_DIST = aclocal.m4 SERVICES TODO REPORTING-BUGS vtysh/Makefile.in \
31 vtysh/Makefile.am update-autotools
32 diff -uNr --exclude=CVS zebra/acconfig.h zebra-ldp/acconfig.h
33 --- zebra/acconfig.h Sat Aug 24 00:14:53 2002
34 +++ zebra-ldp/acconfig.h Sat Aug 24 00:14:37 2002
35 @@ -130,6 +130,7 @@
36 #undef PATH_RIPD_PID
37 #undef PATH_RIPNGD_PID
38 #undef PATH_BGPD_PID
39 +#undef PATH_MPLSD_PID
40 #undef PATH_OSPFD_PID
41 #undef PATH_OSPF6D_PID
43 diff -uNr --exclude=CVS zebra/bgpd/Makefile.in zebra-ldp/bgpd/Makefile.in
44 --- zebra/bgpd/Makefile.in Sat Aug 24 00:14:53 2002
45 +++ zebra-ldp/bgpd/Makefile.in Tue Nov 19 22:21:13 2002
46 @@ -83,6 +83,7 @@
47 LIBPAM = @LIBPAM@
48 LIB_IPV6 = @LIB_IPV6@
49 LIB_REGEX = @LIB_REGEX@
50 +MPLSD = @MPLSD@
51 MULTIPATH_NUM = @MULTIPATH_NUM@
52 OSPF6D = @OSPF6D@
53 OSPFD = @OSPFD@
54 diff -uNr --exclude=CVS zebra/bgpd/bgp_nexthop.c zebra-ldp/bgpd/bgp_nexthop.c
55 --- zebra/bgpd/bgp_nexthop.c Sat Aug 24 00:14:53 2002
56 +++ zebra-ldp/bgpd/bgp_nexthop.c Sat Oct 12 11:41:43 2002
57 @@ -28,6 +28,7 @@
58 #include "network.h"
59 #include "log.h"
60 #include "memory.h"
61 +#include "rib.h"
63 #include "bgpd/bgpd.h"
64 #include "bgpd/bgp_table.h"
65 @@ -36,7 +37,6 @@
66 #include "bgpd/bgp_nexthop.h"
67 #include "bgpd/bgp_debug.h"
68 #include "bgpd/bgp_damp.h"
69 -#include "zebra/rib.h"
70 #include "zebra/zserv.h" /* For ZEBRA_SERV_PATH. */
72 struct bgp_nexthop_cache *zlookup_query (struct in_addr);
73 diff -uNr --exclude=CVS zebra/bgpd/bgp_vty.c zebra-ldp/bgpd/bgp_vty.c
74 --- zebra/bgpd/bgp_vty.c Sat Aug 24 00:14:53 2002
75 +++ zebra-ldp/bgpd/bgp_vty.c Sat Aug 24 00:14:38 2002
76 @@ -39,6 +39,8 @@
77 #include "bgpd/bgp_route.h"
78 #include "bgpd/bgp_zebra.h"
80 +extern struct in_addr router_id_zebra;
82 /* Utility function to get address family from current node. */
83 afi_t
84 bgp_node_afi (struct vty *vty)
85 @@ -398,6 +400,7 @@
86 return CMD_WARNING;
89 + bgp->router_id_static = id;
90 bgp_router_id_set (bgp, &id);
92 return CMD_SUCCESS;
93 @@ -425,14 +428,15 @@
94 return CMD_WARNING;
97 - if (! IPV4_ADDR_SAME (&bgp->router_id, &id))
98 + if (! IPV4_ADDR_SAME (&bgp->router_id_static, &id))
100 vty_out (vty, "%% BGP router-id doesn't match%s", VTY_NEWLINE);
101 return CMD_WARNING;
105 - bgp_router_id_unset (bgp);
106 + bgp->router_id_static.s_addr = 0;
107 + bgp_router_id_set (bgp, &router_id_zebra);
109 return CMD_SUCCESS;
111 diff -uNr --exclude=CVS zebra/bgpd/bgp_zebra.c zebra-ldp/bgpd/bgp_zebra.c
112 --- zebra/bgpd/bgp_zebra.c Sat Aug 24 00:14:53 2002
113 +++ zebra-ldp/bgpd/bgp_zebra.c Sun Aug 25 21:50:18 2002
114 @@ -39,61 +39,24 @@
116 /* All information about zebra. */
117 static struct zclient *zclient = NULL;
118 +struct in_addr router_id_zebra;
120 -/* Update default router id. */
121 +/* Router-id update message from zebra. */
123 -bgp_if_update (struct interface *ifp)
124 +bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length)
126 - struct bgp *bgp;
127 - listnode cn;
128 + struct prefix router_id;
129 struct listnode *nn;
130 - struct listnode *nm;
131 - struct peer *peer;
133 - for (cn = listhead (ifp->connected); cn; nextnode (cn))
135 - struct connected *co;
136 - struct in_addr addr;
138 - co = getdata (cn);
140 - if (co->address->family == AF_INET)
142 - addr = co->address->u.prefix4;
144 - /* Ignore NET127. */
145 - if (IPV4_NET127 (ntohl (addr.s_addr)))
146 - continue;
147 + struct bgp *bgp;
149 - LIST_LOOP (bm->bgp, bgp, nn)
151 - /* Respect configured router id */
152 - if (! (bgp->config & BGP_CONFIG_ROUTER_ID))
153 - if (ntohl (bgp->router_id.s_addr) < ntohl (addr.s_addr))
155 - bgp->router_id = addr;
156 - LIST_LOOP (bgp->peer, peer, nm)
158 - peer->local_id = addr;
164 - return 0;
166 + zebra_router_id_update_read(zclient->ibuf,&router_id);
167 + router_id_zebra = router_id.u.prefix4;
169 -int
170 -bgp_if_update_all ()
172 - listnode node;
173 - struct interface *ifp;
174 + LIST_LOOP (bm->bgp, bgp, nn) {
175 + if (!bgp->router_id_static.s_addr)
176 + bgp_router_id_set (bgp, &router_id.u.prefix4);
179 - for (node = listhead (iflist); node; node = nextnode (node))
181 - ifp = getdata (node);
182 - bgp_if_update (ifp);
184 return 0;
187 @@ -104,7 +67,6 @@
188 struct interface *ifp;
190 ifp = zebra_interface_add_read (zclient->ibuf);
191 - bgp_if_update (ifp);
193 return 0;
195 @@ -206,8 +168,6 @@
196 if (ifc == NULL)
197 return 0;
199 - bgp_if_update (ifc->ifp);
201 if (if_is_up (ifc->ifp))
202 bgp_connected_add (ifc);
204 @@ -225,8 +185,6 @@
205 if (ifc == NULL)
206 return 0;
208 - bgp_if_update (ifc->ifp);
210 if (if_is_up (ifc->ifp))
211 bgp_connected_delete (ifc);
213 @@ -983,6 +941,7 @@
214 /* Set default values. */
215 zclient = zclient_new ();
216 zclient_init (zclient, ZEBRA_ROUTE_BGP);
217 + zclient->router_id_update = bgp_router_id_update;
218 zclient->interface_add = bgp_interface_add;
219 zclient->interface_delete = bgp_interface_delete;
220 zclient->interface_address_add = bgp_interface_address_add;
221 diff -uNr --exclude=CVS zebra/bgpd/bgpd.c zebra-ldp/bgpd/bgpd.c
222 --- zebra/bgpd/bgpd.c Sat Aug 24 00:14:53 2002
223 +++ zebra-ldp/bgpd/bgpd.c Sat Aug 24 00:14:38 2002
224 @@ -63,6 +63,8 @@
225 /* BGP process wide configuration. */
226 static struct bgp_master bgp_master;
228 +extern struct in_addr router_id_zebra;
230 /* BGP process wide configuration pointer to export. */
231 struct bgp_master *bm;
233 @@ -179,38 +181,6 @@
234 return 0;
237 -/* Unset BGP router identifier. */
238 -int
239 -bgp_router_id_unset (struct bgp *bgp)
241 - struct peer *peer;
242 - struct listnode *nn;
244 - if (! bgp_config_check (bgp, BGP_CONFIG_ROUTER_ID))
245 - return 0;
247 - bgp->router_id.s_addr = 0;
248 - bgp_config_unset (bgp, BGP_CONFIG_ROUTER_ID);
250 - /* Clear peer router id configuration. */
251 - LIST_LOOP (bgp->peer, peer, nn)
253 - peer->local_id.s_addr = 0;
256 - /* Set router-id from interface's address. */
257 - bgp_if_update_all ();
259 - /* Reset all BGP sessions to use new router-id. */
260 - LIST_LOOP (bgp->peer, peer, nn)
262 - if (peer->status == Established)
263 - bgp_notify_send (peer, BGP_NOTIFY_CEASE,
264 - BGP_NOTIFY_CEASE_CONFIG_CHANGE);
267 - return 0;
270 /* BGP's cluster-id control. */
272 @@ -1721,7 +1691,7 @@
274 bgp = bgp_create (as, name);
275 listnode_add (bm->bgp, bgp);
276 - bgp_if_update_all ();
277 + bgp_router_id_set(bgp, &router_id_zebra);
278 *bgp_val = bgp;
280 return 0;
281 diff -uNr --exclude=CVS zebra/bgpd/bgpd.h zebra-ldp/bgpd/bgpd.h
282 --- zebra/bgpd/bgpd.h Sat Aug 24 00:14:53 2002
283 +++ zebra-ldp/bgpd/bgpd.h Sat Aug 24 00:14:38 2002
284 @@ -74,6 +74,7 @@
286 /* BGP router identifier. */
287 struct in_addr router_id;
288 + struct in_addr router_id_static;
290 /* BGP route reflector cluster ID. */
291 struct in_addr cluster_id;
292 diff -uNr --exclude=CVS zebra/config.h.in zebra-ldp/config.h.in
293 --- zebra/config.h.in Sat Aug 24 00:14:53 2002
294 +++ zebra-ldp/config.h.in Tue Nov 19 22:21:10 2002
295 @@ -131,6 +131,7 @@
296 #undef PATH_RIPD_PID
297 #undef PATH_RIPNGD_PID
298 #undef PATH_BGPD_PID
299 +#undef PATH_MPLSD_PID
300 #undef PATH_OSPFD_PID
301 #undef PATH_OSPF6D_PID
303 diff -uNr --exclude=CVS zebra/configure zebra-ldp/configure
304 --- zebra/configure Sat Aug 24 00:14:53 2002
305 +++ zebra-ldp/configure Tue Nov 19 22:21:11 2002
306 @@ -837,6 +837,7 @@
307 --disable-ipv6 turn off IPv6 related features and daemons
308 --disable-zebra do not build zebra daemon
309 --disable-bgpd do not build bgpd
310 + --disable-mplsd do not build mplsd
311 --disable-ripd do not build ripd
312 --disable-ripngd do not build ripngd
313 --disable-ospfd do not build ospfd
314 @@ -3088,6 +3089,11 @@
315 enableval="$enable_bgpd"
318 +# Check whether --enable-mplsd or --disable-mplsd was given.
319 +if test "${enable_mplsd+set}" = set; then
320 + enableval="$enable_mplsd"
322 +fi;
323 # Check whether --enable-ripd or --disable-ripd was given.
324 if test "${enable_ripd+set}" = set; then
325 enableval="$enable_ripd"
326 @@ -5502,6 +5508,12 @@
327 BGPD="bgpd"
330 +if test "${enable_mplsd}" = "no";then
331 + MPLSD=""
332 +else
333 + MPLSD="mplsd"
336 if test "${enable_ripd}" = "no";then
337 RIPD=""
338 else
339 @@ -5542,6 +5554,7 @@
344 echo "$as_me:$LINENO: checking for inet_ntop in -lc" >&5
345 echo $ECHO_N "checking for inet_ntop in -lc... $ECHO_C" >&6
346 if test "${ac_cv_lib_c_inet_ntop+set}" = set; then
347 @@ -6939,6 +6952,10 @@
348 _ACEOF
350 cat >>confdefs.h <<_ACEOF
351 +#define PATH_MPLSD_PID "$ac_piddir/mplsd.pid"
352 +_ACEOF
354 +cat >>confdefs.h <<_ACEOF
355 #define PATH_OSPFD_PID "$ac_piddir/ospfd.pid"
356 _ACEOF
358 @@ -7004,7 +7021,7 @@
359 echo "$as_me:$LINENO: result: $ac_cv_htonl_works" >&5
360 echo "${ECHO_T}$ac_cv_htonl_works" >&6
362 -ac_config_files="$ac_config_files Makefile lib/Makefile zebra/Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile ospfd/Makefile ospf6d/Makefile vtysh/Makefile doc/Makefile"
363 +ac_config_files="$ac_config_files Makefile lib/Makefile zebra/Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile mplsd/Makefile ospfd/Makefile ospf6d/Makefile vtysh/Makefile doc/Makefile"
364 cat >confcache <<\_ACEOF
365 # This file is a shell script that caches the results of configure
366 # tests run on this system so they can be shared between configure
367 @@ -7499,6 +7516,7 @@
368 "ripd/Makefile" ) CONFIG_FILES="$CONFIG_FILES ripd/Makefile" ;;
369 "ripngd/Makefile" ) CONFIG_FILES="$CONFIG_FILES ripngd/Makefile" ;;
370 "bgpd/Makefile" ) CONFIG_FILES="$CONFIG_FILES bgpd/Makefile" ;;
371 + "mplsd/Makefile" ) CONFIG_FILES="$CONFIG_FILES mplsd/Makefile" ;;
372 "ospfd/Makefile" ) CONFIG_FILES="$CONFIG_FILES ospfd/Makefile" ;;
373 "ospf6d/Makefile" ) CONFIG_FILES="$CONFIG_FILES ospf6d/Makefile" ;;
374 "vtysh/Makefile" ) CONFIG_FILES="$CONFIG_FILES vtysh/Makefile" ;;
375 @@ -7643,6 +7661,7 @@
376 s,@LIB_IPV6@,$LIB_IPV6,;t t
377 s,@ZEBRA@,$ZEBRA,;t t
378 s,@BGPD@,$BGPD,;t t
379 +s,@MPLSD@,$MPLSD,;t t
380 s,@RIPD@,$RIPD,;t t
381 s,@RIPNGD@,$RIPNGD,;t t
382 s,@OSPFD@,$OSPFD,;t t
383 diff -uNr --exclude=CVS zebra/configure.in zebra-ldp/configure.in
384 --- zebra/configure.in Sat Aug 24 00:14:53 2002
385 +++ zebra-ldp/configure.in Sat Aug 24 00:14:38 2002
386 @@ -63,6 +63,8 @@
387 [ --disable-zebra do not build zebra daemon])
388 AC_ARG_ENABLE(bgpd,
389 [ --disable-bgpd do not build bgpd])
390 +AC_ARG_ENABLE(mplsd,
391 +[ --disable-mplsd do not build mplsd])
392 AC_ARG_ENABLE(ripd,
393 [ --disable-ripd do not build ripd])
394 AC_ARG_ENABLE(ripngd,
395 @@ -572,6 +574,12 @@
396 BGPD="bgpd"
399 +if test "${enable_mplsd}" = "no";then
400 + MPLSD=""
401 +else
402 + MPLSD="mplsd"
405 if test "${enable_ripd}" = "no";then
406 RIPD=""
407 else
408 @@ -602,6 +610,7 @@
410 AC_SUBST(ZEBRA)
411 AC_SUBST(BGPD)
412 +AC_SUBST(MPLSD)
413 AC_SUBST(RIPD)
414 AC_SUBST(RIPNGD)
415 AC_SUBST(OSPFD)
416 @@ -836,6 +845,7 @@
417 AC_DEFINE_UNQUOTED(PATH_RIPD_PID, "$ac_piddir/ripd.pid")
418 AC_DEFINE_UNQUOTED(PATH_RIPNGD_PID, "$ac_piddir/ripngd.pid")
419 AC_DEFINE_UNQUOTED(PATH_BGPD_PID, "$ac_piddir/bgpd.pid")
420 +AC_DEFINE_UNQUOTED(PATH_MPLSD_PID, "$ac_piddir/mplsd.pid")
421 AC_DEFINE_UNQUOTED(PATH_OSPFD_PID, "$ac_piddir/ospfd.pid")
422 AC_DEFINE_UNQUOTED(PATH_OSPF6D_PID, "$ac_piddir/ospf6d.pid")
424 @@ -859,7 +869,7 @@
425 ac_cv_htonl_works=no)])
426 AC_MSG_RESULT($ac_cv_htonl_works)
428 -AC_OUTPUT(Makefile lib/Makefile zebra/Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile ospfd/Makefile ospf6d/Makefile vtysh/Makefile doc/Makefile)
429 +AC_OUTPUT(Makefile lib/Makefile zebra/Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile mplsd/Makefile ospfd/Makefile ospf6d/Makefile vtysh/Makefile doc/Makefile)
431 echo "
432 zebra configuration
433 diff -uNr --exclude=CVS zebra/doc/Makefile.in zebra-ldp/doc/Makefile.in
434 --- zebra/doc/Makefile.in Sat Aug 24 00:14:53 2002
435 +++ zebra-ldp/doc/Makefile.in Tue Nov 19 22:21:14 2002
436 @@ -82,6 +82,7 @@
437 LIBPAM = @LIBPAM@
438 LIB_IPV6 = @LIB_IPV6@
439 LIB_REGEX = @LIB_REGEX@
440 +MPLSD = @MPLSD@
441 MULTIPATH_NUM = @MULTIPATH_NUM@
442 OSPF6D = @OSPF6D@
443 OSPFD = @OSPFD@
444 @@ -190,8 +191,8 @@
445 done
447 mostlyclean-aminfo:
448 - -rm -f zebra.aux zebra.cp zebra.dvi zebra.fn zebra.ky zebra.log zebra.pg \
449 - zebra.ps zebra.toc zebra.tp zebra.vr
450 + -rm -f zebra.aux zebra.cp zebra.cps zebra.dvi zebra.fn zebra.ky zebra.log \
451 + zebra.op zebra.pg zebra.ps zebra.toc zebra.tp zebra.vr
453 maintainer-clean-aminfo:
454 cd $(srcdir) && \
455 diff -uNr --exclude=CVS zebra/lib/Makefile.am zebra-ldp/lib/Makefile.am
456 --- zebra/lib/Makefile.am Sat Aug 24 00:14:54 2002
457 +++ zebra-ldp/lib/Makefile.am Sat Aug 24 00:14:44 2002
458 @@ -10,7 +10,7 @@
459 print_version.c checksum.c vector.c linklist.c vty.c command.c \
460 sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.c \
461 filter.c routemap.c distribute.c stream.c str.c log.c plist.c \
462 - zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c
463 + zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c rib.c
465 libzebra_a_DEPENDENCIES = @LIB_REGEX@
467 @@ -20,7 +20,7 @@
468 buffer.h command.h filter.h getopt.h hash.h if.h linklist.h log.h \
469 memory.h network.h prefix.h routemap.h distribute.h sockunion.h \
470 str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \
471 - plist.h zclient.h sockopt.h smux.h md5-gnu.h if_rmap.h keychain.h
472 + plist.h zclient.h sockopt.h smux.h md5-gnu.h if_rmap.h keychain.h rib.h
474 EXTRA_DIST = regex.c regex-gnu.h
476 diff -uNr --exclude=CVS zebra/lib/Makefile.in zebra-ldp/lib/Makefile.in
477 --- zebra/lib/Makefile.in Sat Aug 24 00:14:54 2002
478 +++ zebra-ldp/lib/Makefile.in Tue Nov 19 22:21:14 2002
479 @@ -83,6 +83,7 @@
480 LIBPAM = @LIBPAM@
481 LIB_IPV6 = @LIB_IPV6@
482 LIB_REGEX = @LIB_REGEX@
483 +MPLSD = @MPLSD@
484 MULTIPATH_NUM = @MULTIPATH_NUM@
485 OSPF6D = @OSPF6D@
486 OSPFD = @OSPFD@
487 @@ -109,7 +110,7 @@
488 print_version.c checksum.c vector.c linklist.c vty.c command.c \
489 sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.c \
490 filter.c routemap.c distribute.c stream.c str.c log.c plist.c \
491 - zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c
492 + zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c rib.c
495 libzebra_a_DEPENDENCIES = @LIB_REGEX@
496 @@ -120,7 +121,7 @@
497 buffer.h command.h filter.h getopt.h hash.h if.h linklist.h log.h \
498 memory.h network.h prefix.h routemap.h distribute.h sockunion.h \
499 str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \
500 - plist.h zclient.h sockopt.h smux.h md5-gnu.h if_rmap.h keychain.h
501 + plist.h zclient.h sockopt.h smux.h md5-gnu.h if_rmap.h keychain.h rib.h
504 EXTRA_DIST = regex.c regex-gnu.h
505 @@ -141,7 +142,7 @@
506 routemap.$(OBJEXT) distribute.$(OBJEXT) stream.$(OBJEXT) \
507 str.$(OBJEXT) log.$(OBJEXT) plist.$(OBJEXT) zclient.$(OBJEXT) \
508 sockopt.$(OBJEXT) smux.$(OBJEXT) md5.$(OBJEXT) \
509 - if_rmap.$(OBJEXT) keychain.$(OBJEXT)
510 + if_rmap.$(OBJEXT) keychain.$(OBJEXT) rib.$(OBJEXT)
511 libzebra_a_OBJECTS = $(am_libzebra_a_OBJECTS)
512 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
513 CPPFLAGS = @CPPFLAGS@
514 @@ -159,7 +160,7 @@
515 @AMDEP_TRUE@ ./$(DEPDIR)/md5.Po ./$(DEPDIR)/memory.Po \
516 @AMDEP_TRUE@ ./$(DEPDIR)/network.Po ./$(DEPDIR)/pid_output.Po \
517 @AMDEP_TRUE@ ./$(DEPDIR)/plist.Po ./$(DEPDIR)/prefix.Po \
518 -@AMDEP_TRUE@ ./$(DEPDIR)/print_version.Po \
519 +@AMDEP_TRUE@ ./$(DEPDIR)/print_version.Po ./$(DEPDIR)/rib.Po \
520 @AMDEP_TRUE@ ./$(DEPDIR)/routemap.Po ./$(DEPDIR)/smux.Po \
521 @AMDEP_TRUE@ ./$(DEPDIR)/sockopt.Po ./$(DEPDIR)/sockunion.Po \
522 @AMDEP_TRUE@ ./$(DEPDIR)/str.Po ./$(DEPDIR)/stream.Po \
523 @@ -221,6 +222,7 @@
524 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plist.Po@am__quote@
525 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prefix.Po@am__quote@
526 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print_version.Po@am__quote@
527 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rib.Po@am__quote@
528 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/routemap.Po@am__quote@
529 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smux.Po@am__quote@
530 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sockopt.Po@am__quote@
531 diff -uNr --exclude=CVS zebra/lib/command.c zebra-ldp/lib/command.c
532 --- zebra/lib/command.c Sat Aug 24 00:14:54 2002
533 +++ zebra-ldp/lib/command.c Fri Oct 11 14:35:14 2002
534 @@ -2080,12 +2080,22 @@
535 case RIPNG_NODE:
536 case OSPF_NODE:
537 case OSPF6_NODE:
538 + case MPLS_STATIC_NODE:
539 + case MPLS_LDP_NODE:
540 + case MPLS_IF_NODE:
541 case KEYCHAIN_NODE:
542 case MASC_NODE:
543 case RMAP_NODE:
544 case VTY_NODE:
545 vty->node = CONFIG_NODE;
546 break;
547 + case MPLS_IN_INSTR_NODE:
548 + case MPLS_OUT_INSTR_NODE:
549 + vty->node = MPLS_STATIC_NODE;
550 + break;
551 + case MPLS_LDP_IF_NODE:
552 + vty->node = INTERFACE_NODE;
553 + break;
554 case BGP_VPNV4_NODE:
555 case BGP_IPV4_NODE:
556 case BGP_IPV4M_NODE:
557 @@ -2132,6 +2142,12 @@
558 case RMAP_NODE:
559 case OSPF_NODE:
560 case OSPF6_NODE:
561 + case MPLS_IF_NODE:
562 + case MPLS_LDP_NODE:
563 + case MPLS_LDP_IF_NODE:
564 + case MPLS_STATIC_NODE:
565 + case MPLS_IN_INSTR_NODE:
566 + case MPLS_OUT_INSTR_NODE:
567 case KEYCHAIN_NODE:
568 case KEYCHAIN_KEY_NODE:
569 case MASC_NODE:
570 diff -uNr --exclude=CVS zebra/lib/command.h zebra-ldp/lib/command.h
571 --- zebra/lib/command.h Sat Aug 24 00:14:54 2002
572 +++ zebra-ldp/lib/command.h Sat Oct 12 11:23:54 2002
573 @@ -75,6 +75,12 @@
574 AAA_NODE, /* AAA node. */
575 KEYCHAIN_NODE, /* Key-chain node. */
576 KEYCHAIN_KEY_NODE, /* Key-chain key node. */
577 + MPLS_IF_NODE, /* MPLS tunnel interface node */
578 + MPLS_LDP_NODE, /* MPLS LDP protocol node */
579 + MPLS_LDP_IF_NODE, /* MPLS LDP interface node */
580 + MPLS_STATIC_NODE, /* static MPLS protocol mode */
581 + MPLS_IN_INSTR_NODE, /* MPLS in-seg instructions */
582 + MPLS_OUT_INSTR_NODE, /* MPLS out-seg instructions */
583 INTERFACE_NODE, /* Interface mode node. */
584 ZEBRA_NODE, /* zebra connection node. */
585 TABLE_NODE, /* rtm_table selection node. */
586 diff -uNr --exclude=CVS zebra/lib/if.c zebra-ldp/lib/if.c
587 --- zebra/lib/if.c Sat Aug 24 00:14:54 2002
588 +++ zebra-ldp/lib/if.c Sat Aug 24 00:14:45 2002
589 @@ -594,6 +594,30 @@
591 #endif
593 +struct interface *if_getfirst()
595 + listnode node = listhead(iflist);
596 + return getdata(node);
599 +struct interface *if_getnext(struct interface *old)
601 + struct interface *ifp;
602 + listnode node;
603 + int flag = 0;
605 + for (node = listhead(iflist); node; nextnode(node)) {
606 + ifp = getdata(node);
607 + if (flag) {
608 + return ifp;
610 + if (ifp->ifindex == old->ifindex) {
611 + flag = 1;
614 + return NULL;
617 #ifndef HAVE_IF_INDEXTONAME
618 char *
619 if_indextoname (unsigned int ifindex, char *name)
620 diff -uNr --exclude=CVS zebra/lib/if.h zebra-ldp/lib/if.h
621 --- zebra/lib/if.h Sat Aug 24 00:14:54 2002
622 +++ zebra-ldp/lib/if.h Sat Aug 24 00:14:45 2002
623 @@ -204,6 +204,9 @@
624 struct connected *connected_delete_by_prefix (struct interface *, struct prefix *);
625 int ifc_pointopoint (struct connected *);
627 +struct interface *if_getfirst();
628 +struct interface *if_getnext(struct interface*);
630 #ifndef HAVE_IF_NAMETOINDEX
631 unsigned int if_nametoindex (const char *);
632 #endif
633 diff -uNr --exclude=CVS zebra/lib/linklist.h zebra-ldp/lib/linklist.h
634 --- zebra/lib/linklist.h Sat Aug 24 00:14:54 2002
635 +++ zebra-ldp/lib/linklist.h Sat Aug 24 00:14:45 2002
636 @@ -43,6 +43,7 @@
638 #define nextnode(X) ((X) = (X)->next)
639 #define listhead(X) ((X)->head)
640 +#define listtail(X) ((X)->tail)
641 #define listcount(X) ((X)->count)
642 #define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL)
643 #define getdata(X) ((X)->data)
644 diff -uNr --exclude=CVS zebra/lib/log.c zebra-ldp/lib/log.c
645 --- zebra/lib/log.c Sat Aug 24 00:14:54 2002
646 +++ zebra-ldp/lib/log.c Sat Aug 24 00:14:45 2002
647 @@ -37,6 +37,7 @@
648 "OSPF",
649 "RIPNG",
650 "OSPF6",
651 + "MPLS",
652 "MASC",
653 NULL,
655 diff -uNr --exclude=CVS zebra/lib/log.h zebra-ldp/lib/log.h
656 --- zebra/lib/log.h Sat Aug 24 00:14:54 2002
657 +++ zebra-ldp/lib/log.h Sat Aug 24 00:14:45 2002
658 @@ -47,6 +47,7 @@
659 ZLOG_OSPF,
660 ZLOG_RIPNG,
661 ZLOG_OSPF6,
662 + ZLOG_MPLS,
663 ZLOG_MASC
664 } zlog_proto_t;
666 diff -uNr --exclude=CVS zebra/lib/memory.c zebra-ldp/lib/memory.c
667 --- zebra/lib/memory.c Sat Aug 24 00:14:54 2002
668 +++ zebra-ldp/lib/memory.c Thu Oct 10 21:42:47 2002
669 @@ -373,6 +373,16 @@
670 { -1, NULL },
673 +struct memory_list memory_list_mpls[] =
675 + { MTYPE_MPLS_TOP, "MPLS " },
676 + { MTYPE_MPLS_IF, "MPLS IF " },
677 + { MTYPE_MPLS_STATIC, "MPLS static " },
678 + { MTYPE_MPLS_LDP, "LDP " },
679 + { MTYPE_MPLS_RIB, "RIB " },
680 + { -1, NULL },
683 struct memory_list memory_list_separator[] =
685 { 0, NULL},
686 @@ -407,6 +417,7 @@
687 show_memory_vty (vty, memory_list_ospf6);
688 show_memory_vty (vty, memory_list_separator);
689 show_memory_vty (vty, memory_list_bgp);
690 + show_memory_vty (vty, memory_list_mpls);
692 return CMD_SUCCESS;
694 @@ -450,6 +461,17 @@
695 return CMD_SUCCESS;
698 +DEFUN (show_memory_mpls,
699 + show_memory_mpls_cmd,
700 + "show memory mpls",
701 + SHOW_STR
702 + "Memory statistics\n"
703 + "MPLS memory\n")
705 + show_memory_vty (vty, memory_list_mpls);
706 + return CMD_SUCCESS;
709 DEFUN (show_memory_ospf,
710 show_memory_ospf_cmd,
711 "show memory ospf",
712 @@ -480,6 +502,7 @@
713 install_element (VIEW_NODE, &show_memory_lib_cmd);
714 install_element (VIEW_NODE, &show_memory_rip_cmd);
715 install_element (VIEW_NODE, &show_memory_bgp_cmd);
716 + install_element (VIEW_NODE, &show_memory_mpls_cmd);
717 install_element (VIEW_NODE, &show_memory_ospf_cmd);
718 install_element (VIEW_NODE, &show_memory_ospf6_cmd);
720 @@ -488,6 +511,7 @@
721 install_element (ENABLE_NODE, &show_memory_lib_cmd);
722 install_element (ENABLE_NODE, &show_memory_rip_cmd);
723 install_element (ENABLE_NODE, &show_memory_bgp_cmd);
724 + install_element (ENABLE_NODE, &show_memory_mpls_cmd);
725 install_element (ENABLE_NODE, &show_memory_ospf_cmd);
726 install_element (ENABLE_NODE, &show_memory_ospf6_cmd);
728 diff -uNr --exclude=CVS zebra/lib/memory.h zebra-ldp/lib/memory.h
729 --- zebra/lib/memory.h Sat Aug 24 00:14:54 2002
730 +++ zebra-ldp/lib/memory.h Sat Oct 12 11:44:59 2002
731 @@ -170,6 +170,12 @@
732 MTYPE_COMMUNITY_LIST_ENTRY,
733 MTYPE_COMMUNITY_LIST_CONFIG,
735 + MTYPE_MPLS_TOP,
736 + MTYPE_MPLS_IF,
737 + MTYPE_MPLS_STATIC,
738 + MTYPE_MPLS_LDP,
739 + MTYPE_MPLS_RIB,
741 MTYPE_RIP,
742 MTYPE_RIP_INTERFACE,
743 MTYPE_RIP_DISTANCE,
744 diff -uNr --exclude=CVS zebra/lib/rib.c zebra-ldp/lib/rib.c
745 --- zebra/lib/rib.c Wed Dec 31 19:00:00 1969
746 +++ zebra-ldp/lib/rib.c Sun Aug 25 22:46:23 2002
747 @@ -0,0 +1,2278 @@
748 +/* Routing Information Base.
749 + * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro
751 + * This file is part of GNU Zebra.
753 + * GNU Zebra is free software; you can redistribute it and/or modify it
754 + * under the terms of the GNU General Public License as published by the
755 + * Free Software Foundation; either version 2, or (at your option) any
756 + * later version.
758 + * GNU Zebra is distributed in the hope that it will be useful, but
759 + * WITHOUT ANY WARRANTY; without even the implied warranty of
760 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
761 + * General Public License for more details.
763 + * You should have received a copy of the GNU General Public License
764 + * along with GNU Zebra; see the file COPYING. If not, write to the Free
765 + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
766 + * 02111-1307, USA.
767 + */
769 +#include <zebra.h>
771 +#include "stream.h"
772 +#include "prefix.h"
773 +#include "table.h"
774 +#include "memory.h"
775 +#include "vty.h"
776 +#include "str.h"
777 +#include "command.h"
778 +#include "linklist.h"
779 +#include "if.h"
780 +#include "log.h"
781 +#include "sockunion.h"
782 +#include "zclient.h"
783 +#include "rib.h"
785 +#define RIB_DEBUG 1
787 +/* Routing information base and static table for IPv4. */
788 +struct rib_table *rib_table_ipv4;
790 +/* Routing information base and static table for IPv6. */
791 +#ifdef HAVE_IPV6
792 +struct rib_table *rib_table_ipv6;
793 +#endif /* HAVE_IPV6 */
795 +/* Each route type's string and default distance value. */
796 +struct
798 + int key;
799 + char c;
800 + char *str;
801 + int distance;
802 +} route_info[] =
804 + {ZEBRA_ROUTE_SYSTEM, 'X', "system", 0},
805 + {ZEBRA_ROUTE_KERNEL, 'K', "kernel", 0},
806 + {ZEBRA_ROUTE_CONNECT, 'C', "connected", 0},
807 + {ZEBRA_ROUTE_STATIC, 'S', "static", 1},
808 + {ZEBRA_ROUTE_RIP, 'R', "rip", 120},
809 + {ZEBRA_ROUTE_RIPNG, 'R', "ripng", 120},
810 + {ZEBRA_ROUTE_OSPF, 'O', "ospf", 110},
811 + {ZEBRA_ROUTE_OSPF6, 'O', "ospf6", 110},
812 + {ZEBRA_ROUTE_BGP, 'B', "bgp", 20 /* IBGP is 200. */}
815 +/* Add nexthop to the end of the list. */
816 +void
817 +nexthop_add (struct rib *rib, struct nexthop *nexthop)
819 + struct nexthop *last;
821 + for (last = rib->nexthop; last && last->next; last = last->next)
823 + if (last)
824 + last->next = nexthop;
825 + else
826 + rib->nexthop = nexthop;
827 + nexthop->prev = last;
829 + rib->nexthop_num++;
832 +/* Delete specified nexthop from the list. */
833 +void
834 +nexthop_delete (struct rib *rib, struct nexthop *nexthop)
836 + if (nexthop->next)
837 + nexthop->next->prev = nexthop->prev;
838 + if (nexthop->prev)
839 + nexthop->prev->next = nexthop->next;
840 + else
841 + rib->nexthop = nexthop->next;
842 + rib->nexthop_num--;
845 +/* Free nexthop. */
846 +void
847 +nexthop_free (struct nexthop *nexthop)
849 + if (nexthop->type == NEXTHOP_TYPE_IFNAME && nexthop->ifname)
850 + free (nexthop->ifname);
851 + XFREE (MTYPE_NEXTHOP, nexthop);
854 +struct nexthop *
855 +nexthop_ifindex_add (struct rib *rib, unsigned int ifindex)
857 + struct nexthop *nexthop;
859 + nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
860 + memset (nexthop, 0, sizeof (struct nexthop));
861 + nexthop->type = NEXTHOP_TYPE_IFINDEX;
862 + nexthop->ifindex = ifindex;
864 + nexthop_add (rib, nexthop);
866 + return nexthop;
869 +struct nexthop *
870 +nexthop_ifname_add (struct rib *rib, char *ifname)
872 + struct nexthop *nexthop;
874 + nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
875 + memset (nexthop, 0, sizeof (struct nexthop));
876 + nexthop->type = NEXTHOP_TYPE_IFNAME;
877 + nexthop->ifname = strdup (ifname);
879 + nexthop_add (rib, nexthop);
881 + return nexthop;
884 +struct nexthop *
885 +nexthop_ipv4_add (struct rib *rib, struct in_addr *ipv4)
887 + struct nexthop *nexthop;
889 + nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
890 + memset (nexthop, 0, sizeof (struct nexthop));
891 + nexthop->type = NEXTHOP_TYPE_IPV4;
892 + nexthop->gate.ipv4 = *ipv4;
894 + nexthop_add (rib, nexthop);
896 + return nexthop;
899 +struct nexthop *
900 +nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr *ipv4,
901 + unsigned int ifindex)
903 + struct nexthop *nexthop;
905 + nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
906 + memset (nexthop, 0, sizeof (struct nexthop));
907 + nexthop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
908 + nexthop->gate.ipv4 = *ipv4;
909 + nexthop->ifindex = ifindex;
911 + nexthop_add (rib, nexthop);
913 + return nexthop;
916 +#ifdef HAVE_IPV6
917 +struct nexthop *
918 +nexthop_ipv6_add (struct rib *rib, struct in6_addr *ipv6)
920 + struct nexthop *nexthop;
922 + nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
923 + memset (nexthop, 0, sizeof (struct nexthop));
924 + nexthop->type = NEXTHOP_TYPE_IPV6;
925 + nexthop->gate.ipv6 = *ipv6;
927 + nexthop_add (rib, nexthop);
929 + return nexthop;
932 +struct nexthop *
933 +nexthop_ipv6_ifname_add (struct rib *rib, struct in6_addr *ipv6,
934 + char *ifname)
936 + struct nexthop *nexthop;
938 + nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
939 + memset (nexthop, 0, sizeof (struct nexthop));
940 + nexthop->type = NEXTHOP_TYPE_IPV6_IFNAME;
941 + nexthop->gate.ipv6 = *ipv6;
942 + nexthop->ifname = XSTRDUP (0, ifname);
944 + nexthop_add (rib, nexthop);
946 + return nexthop;
949 +struct nexthop *
950 +nexthop_ipv6_ifindex_add (struct rib *rib, struct in6_addr *ipv6,
951 + unsigned int ifindex)
953 + struct nexthop *nexthop;
955 + nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
956 + memset (nexthop, 0, sizeof (struct nexthop));
957 + nexthop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
958 + nexthop->gate.ipv6 = *ipv6;
959 + nexthop->ifindex = ifindex;
961 + nexthop_add (rib, nexthop);
963 + return nexthop;
965 +#endif /* HAVE_IPV6 */
967 +/* If force flag is not set, do not modify falgs at all for uninstall
968 + the route from FIB. */
969 +int
970 +nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
971 + struct route_node *top)
973 + struct prefix_ipv4 p;
974 + struct route_node *rn;
975 + struct rib *match;
976 + struct nexthop *newhop;
978 + if (nexthop->type == NEXTHOP_TYPE_IPV4)
979 + nexthop->ifindex = 0;
981 + if (set)
982 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
984 + /* Make lookup prefix. */
985 + memset (&p, 0, sizeof (struct prefix_ipv4));
986 + p.family = AF_INET;
987 + p.prefixlen = IPV4_MAX_PREFIXLEN;
988 + p.prefix = nexthop->gate.ipv4;
990 + rn = route_node_match (rib_table_ipv4->table, (struct prefix *) &p);
991 + while (rn)
993 + route_unlock_node (rn);
995 + /* If lookup self prefix return immidiately. */
996 + if (rn == top)
997 + return 0;
999 + /* Pick up selected route. */
1000 + for (match = rn->info; match; match = match->next)
1001 + if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
1002 + break;
1004 + /* If there is no selected route or matched route is EGP, go up
1005 + tree. */
1006 + if (! match
1007 + || match->type == ZEBRA_ROUTE_BGP)
1009 + do {
1010 + rn = rn->parent;
1011 + } while (rn && rn->info == NULL);
1012 + if (rn)
1013 + route_lock_node (rn);
1015 + else
1017 + if (match->type == ZEBRA_ROUTE_CONNECT)
1019 + /* Directly point connected route. */
1020 + newhop = match->nexthop;
1021 + if (newhop && nexthop->type == NEXTHOP_TYPE_IPV4)
1022 + nexthop->ifindex = newhop->ifindex;
1024 + return 1;
1026 + else if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_INTERNAL))
1028 + for (newhop = match->nexthop; newhop; newhop = newhop->next)
1029 + if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB)
1030 + && ! CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_RECURSIVE))
1032 + if (set)
1034 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
1035 + nexthop->rtype = newhop->type;
1036 + nexthop->rmplsindex = newhop->mplsindex;
1037 + if (newhop->type == NEXTHOP_TYPE_IPV4 ||
1038 + newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
1039 + nexthop->rgate.ipv4 = newhop->gate.ipv4;
1040 + if (newhop->type == NEXTHOP_TYPE_IFINDEX
1041 + || newhop->type == NEXTHOP_TYPE_IFNAME
1042 + || newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
1043 + nexthop->rifindex = newhop->ifindex;
1045 + return 1;
1047 + return 0;
1049 + else
1051 + return 0;
1055 + return 0;
1058 +#ifdef HAVE_IPV6
1059 +/* If force flag is not set, do not modify falgs at all for uninstall
1060 + the route from FIB. */
1061 +int
1062 +nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
1063 + struct route_node *top)
1065 + struct prefix_ipv6 p;
1066 + struct route_node *rn;
1067 + struct rib *match;
1068 + struct nexthop *newhop;
1070 + if (nexthop->type == NEXTHOP_TYPE_IPV6)
1071 + nexthop->ifindex = 0;
1073 + if (set)
1074 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
1076 + /* Make lookup prefix. */
1077 + memset (&p, 0, sizeof (struct prefix_ipv6));
1078 + p.family = AF_INET6;
1079 + p.prefixlen = IPV6_MAX_PREFIXLEN;
1080 + p.prefix = nexthop->gate.ipv6;
1082 + rn = route_node_match (rib_table_ipv6->table, (struct prefix *) &p);
1083 + while (rn)
1085 + route_unlock_node (rn);
1087 + /* If lookup self prefix return immidiately. */
1088 + if (rn == top)
1089 + return 0;
1091 + /* Pick up selected route. */
1092 + for (match = rn->info; match; match = match->next)
1093 + if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
1094 + break;
1096 + /* If there is no selected route or matched route is EGP, go up
1097 + tree. */
1098 + if (! match
1099 + || match->type == ZEBRA_ROUTE_BGP)
1101 + do {
1102 + rn = rn->parent;
1103 + } while (rn && rn->info == NULL);
1104 + if (rn)
1105 + route_lock_node (rn);
1107 + else
1109 + if (match->type == ZEBRA_ROUTE_CONNECT)
1111 + /* Directly point connected route. */
1112 + newhop = match->nexthop;
1114 + if (newhop && nexthop->type == NEXTHOP_TYPE_IPV6)
1115 + nexthop->ifindex = newhop->ifindex;
1117 + return 1;
1119 + else if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_INTERNAL))
1121 + for (newhop = match->nexthop; newhop; newhop = newhop->next)
1122 + if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB)
1123 + && ! CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_RECURSIVE))
1125 + if (set)
1127 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
1128 + nexthop->rtype = newhop->type;
1129 + nexthop->rmplsindex = newhop->mplsindex;
1130 + if (newhop->type == NEXTHOP_TYPE_IPV6
1131 + || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX
1132 + || newhop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1133 + nexthop->rgate.ipv6 = newhop->gate.ipv6;
1134 + if (newhop->type == NEXTHOP_TYPE_IFINDEX
1135 + || newhop->type == NEXTHOP_TYPE_IFNAME
1136 + || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX
1137 + || newhop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1138 + nexthop->rifindex = newhop->ifindex;
1140 + return 1;
1142 + return 0;
1144 + else
1146 + return 0;
1150 + return 0;
1152 +#endif /* HAVE_IPV6 */
1154 +struct rib *
1155 +rib_match_ipv4 (struct in_addr addr)
1157 + struct prefix_ipv4 p;
1158 + struct route_node *rn;
1159 + struct rib *match;
1160 + struct nexthop *newhop;
1162 + memset (&p, 0, sizeof (struct prefix_ipv4));
1163 + p.family = AF_INET;
1164 + p.prefixlen = IPV4_MAX_PREFIXLEN;
1165 + p.prefix = addr;
1167 + rn = route_node_match (rib_table_ipv4->table, (struct prefix *) &p);
1169 + while (rn)
1171 + route_unlock_node (rn);
1173 + /* Pick up selected route. */
1174 + for (match = rn->info; match; match = match->next)
1175 + if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
1176 + break;
1178 + /* If there is no selected route or matched route is EGP, go up
1179 + tree. */
1180 + if (! match
1181 + || match->type == ZEBRA_ROUTE_BGP)
1183 + do {
1184 + rn = rn->parent;
1185 + } while (rn && rn->info == NULL);
1186 + if (rn)
1187 + route_lock_node (rn);
1189 + else
1191 + if (match->type == ZEBRA_ROUTE_CONNECT)
1192 + /* Directly point connected route. */
1193 + return match;
1194 + else
1196 + for (newhop = match->nexthop; newhop; newhop = newhop->next)
1197 + if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB))
1198 + return match;
1199 + return NULL;
1203 + return NULL;
1206 +struct rib *
1207 +rib_lookup_ipv4 (struct prefix_ipv4 *p)
1209 + struct route_node *rn;
1210 + struct rib *match;
1211 + struct nexthop *nexthop;
1213 + rn = route_node_lookup (rib_table_ipv4->table, (struct prefix *) p);
1215 + /* No route for this prefix. */
1216 + if (! rn)
1217 + return NULL;
1219 + /* Unlock node. */
1220 + route_unlock_node (rn);
1222 + /* Pick up selected route. */
1223 + for (match = rn->info; match; match = match->next)
1224 + if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
1225 + break;
1227 + if (! match || match->type == ZEBRA_ROUTE_BGP)
1228 + return NULL;
1230 + if (match->type == ZEBRA_ROUTE_CONNECT)
1231 + return match;
1233 + for (nexthop = match->nexthop; nexthop; nexthop = nexthop->next)
1234 + if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1235 + return match;
1237 + return NULL;
1240 +#ifdef HAVE_IPV6
1241 +struct rib *
1242 +rib_match_ipv6 (struct in6_addr *addr)
1244 + struct prefix_ipv6 p;
1245 + struct route_node *rn;
1246 + struct rib *match;
1247 + struct nexthop *newhop;
1249 + memset (&p, 0, sizeof (struct prefix_ipv6));
1250 + p.family = AF_INET6;
1251 + p.prefixlen = IPV6_MAX_PREFIXLEN;
1252 + IPV6_ADDR_COPY (&p.prefix, addr);
1254 + rn = route_node_match (rib_table_ipv6->table, (struct prefix *) &p);
1256 + while (rn)
1258 + route_unlock_node (rn);
1260 + /* Pick up selected route. */
1261 + for (match = rn->info; match; match = match->next)
1262 + if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
1263 + break;
1265 + /* If there is no selected route or matched route is EGP, go up
1266 + tree. */
1267 + if (! match
1268 + || match->type == ZEBRA_ROUTE_BGP)
1270 + do {
1271 + rn = rn->parent;
1272 + } while (rn && rn->info == NULL);
1273 + if (rn)
1274 + route_lock_node (rn);
1276 + else
1278 + if (match->type == ZEBRA_ROUTE_CONNECT)
1279 + /* Directly point connected route. */
1280 + return match;
1281 + else
1283 + for (newhop = match->nexthop; newhop; newhop = newhop->next)
1284 + if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB))
1285 + return match;
1286 + return NULL;
1290 + return NULL;
1292 +#endif /* HAVE_IPV6 */
1294 +int
1295 +nexthop_active_check (struct route_node *rn, struct rib *rib,
1296 + struct nexthop *nexthop, int set)
1298 + struct interface *ifp;
1300 + switch (nexthop->type)
1302 + case NEXTHOP_TYPE_IFINDEX:
1303 + ifp = if_lookup_by_index (nexthop->ifindex);
1304 + if (ifp && if_is_up (ifp))
1305 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1306 + else
1307 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1308 + break;
1309 + case NEXTHOP_TYPE_IFNAME:
1310 + case NEXTHOP_TYPE_IPV6_IFNAME:
1311 + ifp = if_lookup_by_name (nexthop->ifname);
1312 + if (ifp && if_is_up (ifp))
1314 + if (set)
1315 + nexthop->ifindex = ifp->ifindex;
1316 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1318 + else
1320 + if (set)
1321 + nexthop->ifindex = 0;
1322 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1324 + break;
1325 + case NEXTHOP_TYPE_IPV4:
1326 + case NEXTHOP_TYPE_IPV4_IFINDEX:
1327 + if (nexthop_active_ipv4 (rib, nexthop, set, rn))
1328 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1329 + else
1330 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1331 + break;
1332 +#ifdef HAVE_IPV6
1333 + case NEXTHOP_TYPE_IPV6:
1334 + if (nexthop_active_ipv6 (rib, nexthop, set, rn))
1335 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1336 + else
1337 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1338 + break;
1339 + case NEXTHOP_TYPE_IPV6_IFINDEX:
1340 + if (IN6_IS_ADDR_LINKLOCAL (&nexthop->gate.ipv6))
1342 + ifp = if_lookup_by_index (nexthop->ifindex);
1343 + if (ifp && if_is_up (ifp))
1344 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1345 + else
1346 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1348 + else
1350 + if (nexthop_active_ipv6 (rib, nexthop, set, rn))
1351 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1352 + else
1353 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1355 + break;
1356 +#endif /* HAVE_IPV6 */
1357 + default:
1358 + break;
1360 + return CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1363 +int
1364 +nexthop_active_update (struct route_node *rn, struct rib *rib, int set)
1366 + struct nexthop *nexthop;
1367 + int active;
1369 + rib->nexthop_active_num = 0;
1370 + UNSET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED);
1372 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1374 + active = CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
1375 + rib->nexthop_active_num += nexthop_active_check (rn, rib, nexthop, set);
1376 + if (active != CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1377 + SET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED);
1379 + if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_MPLS_CHANGED))
1380 + SET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED);
1382 + return rib->nexthop_active_num;
1385 +#define RIB_SYSTEM_ROUTE(R) \
1386 + ((R)->type == ZEBRA_ROUTE_KERNEL || (R)->type == ZEBRA_ROUTE_CONNECT)
1388 +void
1389 +newrib_free (struct rib *rib)
1391 + struct nexthop *nexthop;
1392 + struct nexthop *next;
1394 + for (nexthop = rib->nexthop; nexthop; nexthop = next)
1396 + next = nexthop->next;
1397 + nexthop_free (nexthop);
1399 + XFREE (MTYPE_RIB, rib);
1402 +void
1403 +rib_install_lower (struct route_node *rn, struct rib *rib)
1405 + int ret = 0;
1406 + struct nexthop *nexthop;
1408 + if (rib->rib_table->rib_install_kernel)
1409 + ret = rib->rib_table->rib_install_kernel(rn,rib);
1411 + if (ret < 0)
1412 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1413 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
1416 +/* Uninstall the route from kernel. */
1417 +int
1418 +rib_uninstall_lower (struct route_node *rn, struct rib *rib)
1420 + int ret = 0;
1421 + struct nexthop *nexthop;
1423 + if (rib->rib_table->rib_uninstall_kernel)
1424 + ret = rib->rib_table->rib_uninstall_kernel(rn,rib);
1426 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1427 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
1429 + return ret;
1432 +/* Uninstall the route from kernel. */
1433 +void
1434 +rib_uninstall (struct route_node *rn, struct rib *rib)
1436 + if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1438 + if (rib->rib_table->redistribute_delete)
1439 + rib->rib_table->redistribute_delete (&rn->p, rib);
1441 + if (! RIB_SYSTEM_ROUTE (rib))
1442 + rib_uninstall_lower (rn, rib);
1444 + UNSET_FLAG (rib->flags, ZEBRA_FLAG_SELECTED);
1448 +/* Core function for processing routing information base. */
1449 +void
1450 +rib_process (struct route_node *rn, struct rib *del)
1452 + struct rib *rib;
1453 + struct rib *next;
1454 + struct rib *fib = NULL;
1455 + struct rib *select = NULL;
1457 + for (rib = rn->info; rib; rib = next)
1459 + next = rib->next;
1461 + /* Currently installed rib. */
1462 + if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1463 + fib = rib;
1465 + /* Skip unreachable nexthop. */
1466 + if (! nexthop_active_update (rn, rib, 0))
1467 + continue;
1469 + /* Infinit distance. */
1470 + if (rib->distance == DISTANCE_INFINITY)
1471 + continue;
1473 + /* Newly selected rib. */
1474 + if (! select || rib->distance < select->distance
1475 + || rib->type == ZEBRA_ROUTE_CONNECT)
1476 + select = rib;
1479 + /* Deleted route check. */
1480 + if (del && CHECK_FLAG (del->flags, ZEBRA_FLAG_SELECTED))
1481 + fib = del;
1483 + /* Same route is selected. */
1484 + if (select && select == fib)
1486 + if (CHECK_FLAG (select->flags, ZEBRA_FLAG_CHANGED))
1489 + if (select->rib_table->redistribute_delete
1490 + && !CHECK_FLAG (select->flags, ZEBRA_FLAG_MPLS_CHANGED))
1491 + select->rib_table->redistribute_delete (&rn->p, select);
1493 + if (! RIB_SYSTEM_ROUTE (select))
1494 + rib_uninstall_lower (rn, select);
1496 + /* Set real nexthop. */
1497 + nexthop_active_update (rn, select, 1);
1499 + if (! RIB_SYSTEM_ROUTE (select))
1500 + rib_install_lower (rn, select);
1502 + if (select->rib_table->redistribute_add
1503 + && !CHECK_FLAG (select->flags, ZEBRA_FLAG_MPLS_CHANGED))
1504 + select->rib_table->redistribute_add (&rn->p, select);
1506 + UNSET_FLAG (select->flags, ZEBRA_FLAG_MPLS_CHANGED);
1508 + return;
1511 + /* Uninstall old rib from forwarding table. */
1512 + if (fib)
1514 + if (fib->rib_table->redistribute_delete)
1515 + fib->rib_table->redistribute_delete (&rn->p, fib);
1517 + if (! RIB_SYSTEM_ROUTE (fib))
1518 + rib_uninstall_lower (rn, fib);
1519 + UNSET_FLAG (fib->flags, ZEBRA_FLAG_SELECTED);
1521 + /* Set real nexthop. */
1522 + nexthop_active_update (rn, fib, 1);
1525 + /* Install new rib into forwarding table. */
1526 + if (select)
1528 + /* Set real nexthop. */
1529 + nexthop_active_update (rn, select, 1);
1531 + if (! RIB_SYSTEM_ROUTE (select))
1532 + rib_install_lower (rn, select);
1534 + SET_FLAG (select->flags, ZEBRA_FLAG_SELECTED);
1535 + if (select->rib_table->redistribute_add)
1536 + select->rib_table->redistribute_add (&rn->p, select);
1540 +/* Add RIB to head of the route node. */
1541 +void
1542 +rib_addnode (struct route_node *rn, struct rib *rib)
1544 + struct rib *head;
1546 + head = rn->info;
1547 + if (head)
1548 + head->prev = rib;
1549 + rib->next = head;
1550 + rn->info = rib;
1553 +void
1554 +rib_delnode (struct route_node *rn, struct rib *rib)
1556 + if (rib->next)
1557 + rib->next->prev = rib->prev;
1558 + if (rib->prev)
1559 + rib->prev->next = rib->next;
1560 + else
1561 + rn->info = rib->next;
1564 +int
1565 +rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
1566 + struct in_addr *gate, unsigned int ifindex, int table,
1567 + u_int32_t metric, u_char distance)
1569 + struct rib *rib;
1570 + struct rib *same = NULL;
1571 + struct route_node *rn;
1572 + struct nexthop *nexthop;
1574 + /* Make it sure prefixlen is applied to the prefix. */
1575 + apply_mask_ipv4 (p);
1577 + /* Set default distance by route type. */
1578 + if (distance == 0)
1580 + distance = route_info[type].distance;
1582 + /* iBGP distance is 200. */
1583 + if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP))
1584 + distance = 200;
1587 + /* Lookup route node.*/
1588 + rn = route_node_get (rib_table_ipv4->table, (struct prefix *) p);
1590 + /* If same type of route are installed, treat it as a implicit
1591 + withdraw. */
1592 + for (rib = rn->info; rib; rib = rib->next)
1594 + if (rib->type == ZEBRA_ROUTE_CONNECT)
1596 + nexthop = rib->nexthop;
1598 + /* Duplicate connected route comes in. */
1599 + if (rib->type == type
1600 + && (! table || rib->table == table)
1601 + && nexthop && nexthop->type == NEXTHOP_TYPE_IFINDEX
1602 + && nexthop->ifindex == ifindex)
1604 + rib->refcnt++;
1605 + return 0 ;
1608 + else if (rib->type == type
1609 + && (! table || rib->table == table))
1611 + same = rib;
1612 + rib_delnode (rn, same);
1613 + route_unlock_node (rn);
1614 + break;
1618 + /* Allocate new rib structure. */
1619 + rib = XMALLOC (MTYPE_RIB, sizeof (struct rib));
1620 + memset (rib, 0, sizeof (struct rib));
1621 + rib->type = type;
1622 + rib->distance = distance;
1623 + rib->flags = flags;
1624 + rib->metric = metric;
1625 + rib->rib_table = rib_table_ipv4;
1626 + rib->table = table;
1627 + rib->nexthop_num = 0;
1628 + rib->uptime = time (NULL);
1630 + /* Nexthop settings. */
1631 + if (gate)
1633 + if (ifindex)
1634 + nexthop_ipv4_ifindex_add (rib, gate, ifindex);
1635 + else
1636 + nexthop_ipv4_add (rib, gate);
1638 + else
1639 + nexthop_ifindex_add (rib, ifindex);
1641 + /* If this route is kernel route, set FIB flag to the route. */
1642 + if (type == ZEBRA_ROUTE_KERNEL || type == ZEBRA_ROUTE_CONNECT)
1643 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1644 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
1646 + /* Link new rib to node.*/
1647 + rib_addnode (rn, rib);
1649 + /* Process this route node. */
1650 + rib_process (rn, same);
1652 + /* Free implicit route.*/
1653 + if (same)
1654 + newrib_free (same);
1656 + return 0;
1659 +int
1660 +rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib)
1662 + struct route_node *rn;
1663 + struct rib *same;
1664 + struct nexthop *nexthop;
1666 + /* Make it sure prefixlen is applied to the prefix. */
1667 + apply_mask_ipv4 (p);
1669 + /* Set default distance by route type. */
1670 + if (rib->distance == 0)
1672 + rib->distance = route_info[rib->type].distance;
1674 + /* iBGP distance is 200. */
1675 + if (rib->type == ZEBRA_ROUTE_BGP
1676 + && CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1677 + rib->distance = 200;
1680 + /* Lookup route node.*/
1681 + rn = route_node_get (rib_table_ipv4->table, (struct prefix *) p);
1683 + /* If same type of route are installed, treat it as a implicit
1684 + withdraw. */
1685 + for (same = rn->info; same; same = same->next)
1687 + if (same->type == rib->type && same->table == rib->table
1688 + && same->type != ZEBRA_ROUTE_CONNECT)
1690 + rib_delnode (rn, same);
1691 + route_unlock_node (rn);
1692 + break;
1696 + /* If this route is kernel route, set FIB flag to the route. */
1697 + if (rib->type == ZEBRA_ROUTE_KERNEL || rib->type == ZEBRA_ROUTE_CONNECT)
1698 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1699 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
1701 + /* Link new rib to node.*/
1702 + rib_addnode (rn, rib);
1704 + /* Process this route node. */
1705 + rib_process (rn, same);
1707 + /* Free implicit route.*/
1708 + if (same)
1709 + newrib_free (same);
1711 + return 0;
1714 +int
1715 +rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
1716 + struct in_addr *gate, unsigned int ifindex, int table)
1718 + struct route_node *rn;
1719 + struct rib *rib;
1720 + struct rib *fib = NULL;
1721 + struct rib *same = NULL;
1722 + struct nexthop *nexthop;
1723 + char buf1[BUFSIZ];
1724 + char buf2[BUFSIZ];
1726 + /* Apply mask. */
1727 + apply_mask_ipv4 (p);
1729 + /* Lookup route node. */
1730 + rn = route_node_lookup (rib_table_ipv4->table, (struct prefix *) p);
1731 + if (! rn)
1733 + if (RIB_DEBUG)
1735 + if (gate)
1736 + zlog_info ("route %s/%d via %s ifindex %d doesn't exist in rib",
1737 + inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
1738 + p->prefixlen,
1739 + inet_ntop (AF_INET, gate, buf2, BUFSIZ),
1740 + ifindex);
1741 + else
1742 + zlog_info ("route %s/%d ifindex %d doesn't exist in rib",
1743 + inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
1744 + p->prefixlen,
1745 + ifindex);
1747 + return ZEBRA_ERR_RTNOEXIST;
1750 + /* Lookup same type route. */
1751 + for (rib = rn->info; rib; rib = rib->next)
1753 + if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1754 + fib = rib;
1756 + if (rib->type == ZEBRA_ROUTE_CONNECT)
1758 + nexthop = rib->nexthop;
1760 + if (rib->type == type
1761 + && (! table || rib->table == table)
1762 + && nexthop && nexthop->type == NEXTHOP_TYPE_IFINDEX
1763 + && nexthop->ifindex == ifindex)
1765 + if (rib->refcnt)
1767 + rib->refcnt--;
1768 + route_unlock_node (rn);
1769 + route_unlock_node (rn);
1770 + return 0;
1772 + same = rib;
1773 + break;
1776 + else
1778 + if (rib->type == type
1779 + && (!table || rib->table == table))
1781 + same = rib;
1782 + break;
1787 + /* If same type of route can't be found and this message is from
1788 + kernel. */
1789 + if (! same)
1791 + if (fib && type == ZEBRA_ROUTE_KERNEL)
1793 + /* Unset flags. */
1794 + for (nexthop = fib->nexthop; nexthop; nexthop = nexthop->next)
1795 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
1797 + UNSET_FLAG (fib->flags, ZEBRA_FLAG_SELECTED);
1799 + else
1801 + if (RIB_DEBUG)
1803 + if (gate)
1804 + zlog_info ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
1805 + inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
1806 + p->prefixlen,
1807 + inet_ntop (AF_INET, gate, buf2, BUFSIZ),
1808 + ifindex,
1809 + type);
1810 + else
1811 + zlog_info ("route %s/%d ifindex %d type %d doesn't exist in rib",
1812 + inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
1813 + p->prefixlen,
1814 + ifindex,
1815 + type);
1817 + route_unlock_node (rn);
1818 + return ZEBRA_ERR_RTNOEXIST;
1822 + if (same)
1823 + rib_delnode (rn, same);
1825 + /* Process changes. */
1826 + rib_process (rn, same);
1828 + if (same)
1830 + newrib_free (same);
1831 + route_unlock_node (rn);
1834 + route_unlock_node (rn);
1836 + return 0;
1839 +/* Delete all added route and close rib. */
1840 +void
1841 +rib_close_ipv4 ()
1843 + struct route_node *rn;
1844 + struct rib *rib;
1846 + for (rn = route_top (rib_table_ipv4->table); rn; rn = route_next (rn))
1847 + for (rib = rn->info; rib; rib = rib->next)
1848 + if (! RIB_SYSTEM_ROUTE (rib)
1849 + && CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1850 + rib_uninstall_lower (rn, rib);
1853 +/* New RIB. Detailed information for IPv4 route. */
1854 +void
1855 +vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
1857 + struct rib *rib;
1858 + struct nexthop *nexthop;
1860 + for (rib = rn->info; rib; rib = rib->next)
1862 + vty_out (vty, "Routing entry for %s/%d%s",
1863 + inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
1864 + VTY_NEWLINE);
1865 + vty_out (vty, " Known via \"%s\"", route_info[rib->type].str);
1866 + vty_out (vty, ", distance %d, metric %d", rib->distance, rib->metric);
1867 + if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1868 + vty_out (vty, ", best");
1869 + if (rib->refcnt)
1870 + vty_out (vty, ", refcnt %ld", rib->refcnt);
1871 + vty_out (vty, "%s", VTY_NEWLINE);
1873 +#define ONE_DAY_SECOND 60*60*24
1874 +#define ONE_WEEK_SECOND 60*60*24*7
1875 + if (rib->type == ZEBRA_ROUTE_RIP
1876 + || rib->type == ZEBRA_ROUTE_OSPF
1877 + || rib->type == ZEBRA_ROUTE_BGP)
1879 + time_t uptime;
1880 + struct tm *tm;
1882 + uptime = time (NULL);
1883 + uptime -= rib->uptime;
1884 + tm = gmtime (&uptime);
1886 + vty_out (vty, " Last update ");
1888 + if (uptime < ONE_DAY_SECOND)
1889 + vty_out (vty, "%02d:%02d:%02d",
1890 + tm->tm_hour, tm->tm_min, tm->tm_sec);
1891 + else if (uptime < ONE_WEEK_SECOND)
1892 + vty_out (vty, "%dd%02dh%02dm",
1893 + tm->tm_yday, tm->tm_hour, tm->tm_min);
1894 + else
1895 + vty_out (vty, "%02dw%dd%02dh",
1896 + tm->tm_yday/7,
1897 + tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1898 + vty_out (vty, " ago%s", VTY_NEWLINE);
1901 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1903 + vty_out (vty, " %c",
1904 + CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ');
1906 + switch (nexthop->type)
1908 + case NEXTHOP_TYPE_IPV4:
1909 + case NEXTHOP_TYPE_IPV4_IFINDEX:
1910 + vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
1911 + if (nexthop->ifindex)
1912 + vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
1913 + break;
1914 + case NEXTHOP_TYPE_IFINDEX:
1915 + vty_out (vty, " directly connected, %s",
1916 + ifindex2ifname (nexthop->ifindex));
1917 + break;
1918 + case NEXTHOP_TYPE_IFNAME:
1919 + vty_out (vty, " directly connected, %s",
1920 + nexthop->ifname);
1921 + break;
1922 + default:
1923 + break;
1926 + if (nexthop->mplsindex)
1927 + vty_out (vty, " MPLS 0x%x", nexthop->mplsindex);
1929 + if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1930 + vty_out (vty, " inactive");
1932 + if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
1934 + vty_out (vty, " (recursive");
1936 + switch (nexthop->rtype)
1938 + case NEXTHOP_TYPE_IPV4:
1939 + case NEXTHOP_TYPE_IPV4_IFINDEX:
1940 + vty_out (vty, " via %s", inet_ntoa (nexthop->rgate.ipv4));
1941 + break;
1942 + case NEXTHOP_TYPE_IFINDEX:
1943 + case NEXTHOP_TYPE_IFNAME:
1944 + vty_out (vty, " is directly connected, %s",
1945 + ifindex2ifname (nexthop->rifindex));
1946 + break;
1947 + default:
1948 + break;
1951 + if (nexthop->rmplsindex)
1952 + vty_out (vty, " MPLS 0x%x", nexthop->rmplsindex);
1954 + vty_out (vty, ")");
1957 + vty_out (vty, "%s", VTY_NEWLINE);
1959 + vty_out (vty, "%s", VTY_NEWLINE);
1963 +void
1964 +vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
1966 + struct nexthop *nexthop;
1967 + int len = 0;
1968 + char buf[BUFSIZ];
1970 + /* Nexthop information. */
1971 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1973 + if (nexthop == rib->nexthop)
1975 + /* Prefix information. */
1976 + len = vty_out (vty, "%c%c%c %s/%d",
1977 + route_info[rib->type].c,
1978 + CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
1979 + ? '>' : ' ',
1980 + CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1981 + ? '*' : ' ',
1982 + inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ),
1983 + rn->p.prefixlen);
1985 + /* Distance and metric display. */
1986 + if (rib->type != ZEBRA_ROUTE_CONNECT
1987 + && rib->type != ZEBRA_ROUTE_KERNEL)
1988 + len += vty_out (vty, " [%d/%d]", rib->distance,
1989 + rib->metric);
1991 + else
1992 + vty_out (vty, " %c%*c",
1993 + CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1994 + ? '*' : ' ',
1995 + len - 3, ' ');
1997 + switch (nexthop->type)
1999 + case NEXTHOP_TYPE_IPV4:
2000 + case NEXTHOP_TYPE_IPV4_IFINDEX:
2001 + vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
2002 + if (nexthop->ifindex)
2003 + vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
2004 + break;
2005 + case NEXTHOP_TYPE_IFINDEX:
2006 + vty_out (vty, " is directly connected, %s",
2007 + ifindex2ifname (nexthop->ifindex));
2008 + break;
2009 + case NEXTHOP_TYPE_IFNAME:
2010 + vty_out (vty, " is directly connected, %s",
2011 + nexthop->ifname);
2012 + break;
2013 + default:
2014 + break;
2017 + if (nexthop->mplsindex)
2018 + vty_out (vty, " MPLS 0x%x", nexthop->mplsindex);
2020 + if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
2021 + vty_out (vty, " inactive");
2023 + if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
2025 + vty_out (vty, " (recursive");
2027 + switch (nexthop->rtype)
2029 + case NEXTHOP_TYPE_IPV4:
2030 + case NEXTHOP_TYPE_IPV4_IFINDEX:
2031 + vty_out (vty, " via %s", inet_ntoa (nexthop->rgate.ipv4));
2032 + break;
2033 + case NEXTHOP_TYPE_IFINDEX:
2034 + case NEXTHOP_TYPE_IFNAME:
2035 + vty_out (vty, " is directly connected, %s",
2036 + ifindex2ifname (nexthop->rifindex));
2037 + break;
2038 + default:
2039 + break;
2041 + if (nexthop->rmplsindex)
2042 + vty_out (vty, " MPLS 0x%x", nexthop->rmplsindex);
2043 + vty_out (vty, ")");
2046 + if (rib->type == ZEBRA_ROUTE_RIP
2047 + || rib->type == ZEBRA_ROUTE_OSPF
2048 + || rib->type == ZEBRA_ROUTE_BGP)
2050 + time_t uptime;
2051 + struct tm *tm;
2053 + uptime = time (NULL);
2054 + uptime -= rib->uptime;
2055 + tm = gmtime (&uptime);
2057 +#define ONE_DAY_SECOND 60*60*24
2058 +#define ONE_WEEK_SECOND 60*60*24*7
2060 + if (uptime < ONE_DAY_SECOND)
2061 + vty_out (vty, ", %02d:%02d:%02d",
2062 + tm->tm_hour, tm->tm_min, tm->tm_sec);
2063 + else if (uptime < ONE_WEEK_SECOND)
2064 + vty_out (vty, ", %dd%02dh%02dm",
2065 + tm->tm_yday, tm->tm_hour, tm->tm_min);
2066 + else
2067 + vty_out (vty, ", %02dw%dd%02dh",
2068 + tm->tm_yday/7,
2069 + tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
2071 + vty_out (vty, "%s", VTY_NEWLINE);
2075 +#define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,%s B - BGP, > - selected route, * - FIB route%s%s"
2077 +DEFUN (show_ip_route,
2078 + show_ip_route_cmd,
2079 + "show ip route",
2080 + SHOW_STR
2081 + IP_STR
2082 + "IP routing table\n")
2084 + struct route_node *rn;
2085 + struct rib *rib;
2086 + int first = 1;
2088 + /* Show all IPv4 routes. */
2089 + for (rn = route_top (rib_table_ipv4->table); rn; rn = route_next (rn))
2090 + for (rib = rn->info; rib; rib = rib->next)
2092 + if (first)
2094 + vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
2095 + first = 0;
2097 + vty_show_ip_route (vty, rn, rib);
2099 + return CMD_SUCCESS;
2102 +DEFUN (show_ip_route_prefix_longer,
2103 + show_ip_route_prefix_longer_cmd,
2104 + "show ip route A.B.C.D/M longer-prefixes",
2105 + SHOW_STR
2106 + IP_STR
2107 + "IP routing table\n"
2108 + "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2109 + "Show route matching the specified Network/Mask pair only\n")
2111 + struct route_node *rn;
2112 + struct rib *rib;
2113 + struct prefix p;
2114 + int ret;
2115 + int first = 1;
2117 + ret = str2prefix (argv[0], &p);
2118 + if (! ret)
2120 + vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
2121 + return CMD_WARNING;
2124 + /* Show matched type IPv4 routes. */
2125 + for (rn = route_top (rib_table_ipv4->table); rn; rn = route_next (rn))
2126 + for (rib = rn->info; rib; rib = rib->next)
2127 + if (prefix_match (&p, &rn->p))
2129 + if (first)
2131 + vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
2132 + first = 0;
2134 + vty_show_ip_route (vty, rn, rib);
2136 + return CMD_SUCCESS;
2139 +DEFUN (show_ip_route_supernets,
2140 + show_ip_route_supernets_cmd,
2141 + "show ip route supernets-only",
2142 + SHOW_STR
2143 + IP_STR
2144 + "IP routing table\n"
2145 + "Show supernet entries only\n")
2147 + struct route_node *rn;
2148 + struct rib *rib;
2149 + u_int32_t addr;
2150 + int first = 1;
2153 + /* Show matched type IPv4 routes. */
2154 + for (rn = route_top (rib_table_ipv4->table); rn; rn = route_next (rn))
2155 + for (rib = rn->info; rib; rib = rib->next)
2157 + addr = ntohl (rn->p.u.prefix4.s_addr);
2159 + if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
2160 + || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
2161 + || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
2163 + if (first)
2165 + vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
2166 + first = 0;
2168 + vty_show_ip_route (vty, rn, rib);
2171 + return CMD_SUCCESS;
2175 +DEFUN (show_ip_route_protocol,
2176 + show_ip_route_protocol_cmd,
2177 + "show ip route (bgp|connected|kernel|ospf|rip|static)",
2178 + SHOW_STR
2179 + IP_STR
2180 + "IP routing table\n"
2181 + "Border Gateway Protocol (BGP)\n"
2182 + "Connected\n"
2183 + "Kernel\n"
2184 + "Open Shortest Path First (OSPF)\n"
2185 + "Routing Information Protocol (RIP)\n"
2186 + "Static routes\n")
2188 + int type;
2189 + struct route_node *rn;
2190 + struct rib *rib;
2191 + int first = 1;
2193 + if (strncmp (argv[0], "b", 1) == 0)
2194 + type = ZEBRA_ROUTE_BGP;
2195 + else if (strncmp (argv[0], "c", 1) == 0)
2196 + type = ZEBRA_ROUTE_CONNECT;
2197 + else if (strncmp (argv[0], "k", 1) ==0)
2198 + type = ZEBRA_ROUTE_KERNEL;
2199 + else if (strncmp (argv[0], "o", 1) == 0)
2200 + type = ZEBRA_ROUTE_OSPF;
2201 + else if (strncmp (argv[0], "r", 1) == 0)
2202 + type = ZEBRA_ROUTE_RIP;
2203 + else if (strncmp (argv[0], "s", 1) == 0)
2204 + type = ZEBRA_ROUTE_STATIC;
2205 + else
2207 + vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
2208 + return CMD_WARNING;
2211 + /* Show matched type IPv4 routes. */
2212 + for (rn = route_top (rib_table_ipv4->table); rn; rn = route_next (rn))
2213 + for (rib = rn->info; rib; rib = rib->next)
2214 + if (rib->type == type)
2216 + if (first)
2218 + vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
2219 + first = 0;
2221 + vty_show_ip_route (vty, rn, rib);
2223 + return CMD_SUCCESS;
2226 +DEFUN (show_ip_route_addr,
2227 + show_ip_route_addr_cmd,
2228 + "show ip route A.B.C.D",
2229 + SHOW_STR
2230 + IP_STR
2231 + "IP routing table\n"
2232 + "Network in the IP routing table to display\n")
2234 + int ret;
2235 + struct prefix_ipv4 p;
2236 + struct route_node *rn;
2238 + ret = str2prefix_ipv4 (argv[0], &p);
2239 + if (ret <= 0)
2241 + vty_out (vty, "Malformed IPv4 address%s", VTY_NEWLINE);
2242 + return CMD_WARNING;
2245 + rn = route_node_match (rib_table_ipv4->table, (struct prefix *) &p);
2246 + if (! rn)
2248 + vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2249 + return CMD_WARNING;
2252 + vty_show_ip_route_detail (vty, rn);
2254 + route_unlock_node (rn);
2256 + return CMD_SUCCESS;
2259 +DEFUN (show_ip_route_prefix,
2260 + show_ip_route_prefix_cmd,
2261 + "show ip route A.B.C.D/M",
2262 + SHOW_STR
2263 + IP_STR
2264 + "IP routing table\n"
2265 + "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2267 + int ret;
2268 + struct prefix_ipv4 p;
2269 + struct route_node *rn;
2271 + ret = str2prefix_ipv4 (argv[0], &p);
2272 + if (ret <= 0)
2274 + vty_out (vty, "Malformed IPv4 address%s", VTY_NEWLINE);
2275 + return CMD_WARNING;
2278 + rn = route_node_match (rib_table_ipv4->table, (struct prefix *) &p);
2279 + if (! rn || rn->p.prefixlen != p.prefixlen)
2281 + vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2282 + return CMD_WARNING;
2285 + vty_show_ip_route_detail (vty, rn);
2287 + route_unlock_node (rn);
2289 + return CMD_SUCCESS;
2292 +#ifdef HAVE_IPV6
2293 +int
2294 +rib_bogus_ipv6 (int type, struct prefix_ipv6 *p,
2295 + struct in6_addr *gate, unsigned int ifindex, int table)
2297 + if (type == ZEBRA_ROUTE_CONNECT && IN6_IS_ADDR_UNSPECIFIED (&p->prefix))
2298 + return 1;
2299 + if (type == ZEBRA_ROUTE_KERNEL && IN6_IS_ADDR_UNSPECIFIED (&p->prefix)
2300 + && p->prefixlen == 96 && gate && IN6_IS_ADDR_UNSPECIFIED (gate))
2302 + kernel_delete_ipv6_old (p, gate, ifindex, 0, table);
2303 + return 1;
2305 + return 0;
2308 +int
2309 +rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
2310 + struct in6_addr *gate, unsigned int ifindex, int table)
2312 + struct rib *rib;
2313 + struct rib *same = NULL;
2314 + struct route_node *rn;
2315 + struct nexthop *nexthop;
2317 + int distance;
2318 + u_int32_t metric = 0;
2320 + /* Make sure mask is applied. */
2321 + apply_mask_ipv6 (p);
2323 + /* Set default distance by route type. */
2324 + distance = route_info[type].distance;
2326 + if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP))
2327 + distance = 200;
2329 + /* Make new rib. */
2330 + if (!table)
2331 + table = RT_TABLE_MAIN;
2333 + /* Filter bogus route. */
2334 + if (rib_bogus_ipv6 (type, p, gate, ifindex, table))
2335 + return 0;
2337 + /* Lookup route node.*/
2338 + rn = route_node_get (rib_table_ipv6->table, (struct prefix *) p);
2340 + /* If same type of route are installed, treat it as a implicit
2341 + withdraw. */
2342 + for (rib = rn->info; rib; rib = rib->next)
2344 + if (rib->type == ZEBRA_ROUTE_CONNECT)
2346 + nexthop = rib->nexthop;
2348 + if (rib->type == type
2349 + && (! table || rib->table == table)
2350 + && nexthop && nexthop->type == NEXTHOP_TYPE_IFINDEX
2351 + && nexthop->ifindex == ifindex)
2353 + rib->refcnt++;
2354 + return 0;
2357 + else if (rib->type == type
2358 + && (! table || (rib->table == table)))
2360 + same = rib;
2361 + rib_delnode (rn, same);
2362 + route_unlock_node (rn);
2363 + break;
2367 + /* Allocate new rib structure. */
2368 + rib = XMALLOC (MTYPE_RIB, sizeof (struct rib));
2369 + memset (rib, 0, sizeof (struct rib));
2370 + rib->type = type;
2371 + rib->distance = distance;
2372 + rib->flags = flags;
2373 + rib->metric = metric;
2374 + rib->table = table;
2375 + rib->rib_table = rib_table_ipv6;
2376 + rib->nexthop_num = 0;
2377 + rib->uptime = time (NULL);
2379 + /* Nexthop settings. */
2380 + if (gate)
2382 + if (ifindex)
2383 + nexthop_ipv6_ifindex_add (rib, gate, ifindex);
2384 + else
2385 + nexthop_ipv6_add (rib, gate);
2387 + else
2388 + nexthop_ifindex_add (rib, ifindex);
2390 + /* If this route is kernel route, set FIB flag to the route. */
2391 + if (type == ZEBRA_ROUTE_KERNEL || type == ZEBRA_ROUTE_CONNECT)
2392 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
2393 + SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
2395 + /* Link new rib to node.*/
2396 + rib_addnode (rn, rib);
2398 + /* Process this route node. */
2399 + rib_process (rn, same);
2401 + /* Free implicit route.*/
2402 + if (same)
2403 + newrib_free (same);
2405 + return 0;
2408 +int
2409 +rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
2410 + struct in6_addr *gate, unsigned int ifindex, int table)
2412 + struct route_node *rn;
2413 + struct rib *rib;
2414 + struct rib *fib = NULL;
2415 + struct rib *same = NULL;
2416 + struct nexthop *nexthop;
2417 + char buf1[BUFSIZ];
2418 + char buf2[BUFSIZ];
2420 + /* Apply mask. */
2421 + apply_mask_ipv6 (p);
2423 + /* Lookup route node. */
2424 + rn = route_node_lookup (rib_table_ipv6->table, (struct prefix *) p);
2425 + if (! rn)
2427 + if (RIB_DEBUG)
2429 + if (gate)
2430 + zlog_info ("route %s/%d via %s ifindex %d doesn't exist in rib",
2431 + inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ),
2432 + p->prefixlen,
2433 + inet_ntop (AF_INET6, gate, buf2, BUFSIZ),
2434 + ifindex);
2435 + else
2436 + zlog_info ("route %s/%d ifindex %d doesn't exist in rib",
2437 + inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ),
2438 + p->prefixlen,
2439 + ifindex);
2441 + return ZEBRA_ERR_RTNOEXIST;
2444 + /* Lookup same type route. */
2445 + for (rib = rn->info; rib; rib = rib->next)
2447 + if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
2448 + fib = rib;
2450 + if (rib->type == ZEBRA_ROUTE_CONNECT)
2452 + nexthop = rib->nexthop;
2454 + if (rib->type == type
2455 + && (! table || rib->table == table)
2456 + && nexthop && nexthop->type == NEXTHOP_TYPE_IFINDEX
2457 + && nexthop->ifindex == ifindex)
2459 + if (rib->refcnt)
2461 + rib->refcnt--;
2462 + route_unlock_node (rn);
2463 + route_unlock_node (rn);
2464 + return 0;
2466 + same = rib;
2467 + break;
2470 + else
2472 + if (rib->type == type
2473 + && (! table || rib->table == table))
2475 + same = rib;
2476 + break;
2481 + /* If same type of route can't be found and this message is from
2482 + kernel. */
2483 + if (! same)
2485 + if (fib && type == ZEBRA_ROUTE_KERNEL)
2487 + /* Unset flags. */
2488 + for (nexthop = fib->nexthop; nexthop; nexthop = nexthop->next)
2489 + UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
2491 + UNSET_FLAG (fib->flags, ZEBRA_FLAG_SELECTED);
2493 + else
2495 + if (RIB_DEBUG)
2497 + if (gate)
2498 + zlog_info ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
2499 + inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ),
2500 + p->prefixlen,
2501 + inet_ntop (AF_INET6, gate, buf2, BUFSIZ),
2502 + ifindex,
2503 + type);
2504 + else
2505 + zlog_info ("route %s/%d ifindex %d type %d doesn't exist in rib",
2506 + inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ),
2507 + p->prefixlen,
2508 + ifindex,
2509 + type);
2511 + route_unlock_node (rn);
2512 + return ZEBRA_ERR_RTNOEXIST;
2516 + if (same)
2517 + rib_delnode (rn, same);
2519 + /* Process changes. */
2520 + rib_process (rn, same);
2522 + if (same)
2524 + newrib_free (same);
2525 + route_unlock_node (rn);
2528 + route_unlock_node (rn);
2530 + return 0;
2533 +/* Delete non system routes. */
2534 +void
2535 +rib_close_ipv6 ()
2537 + struct route_node *rn;
2538 + struct rib *rib;
2540 + for (rn = route_top (rib_table_ipv6->table); rn; rn = route_next (rn))
2541 + for (rib = rn->info; rib; rib = rib->next)
2542 + if (! RIB_SYSTEM_ROUTE (rib)
2543 + && CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
2544 + rib_uninstall_lower (rn, rib);
2547 +/* New RIB. Detailed information for IPv4 route. */
2548 +void
2549 +vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
2551 + struct rib *rib;
2552 + struct nexthop *nexthop;
2553 + char buf[BUFSIZ];
2555 + for (rib = rn->info; rib; rib = rib->next)
2557 + vty_out (vty, "Routing entry for %s/%d%s",
2558 + inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
2559 + rn->p.prefixlen,
2560 + VTY_NEWLINE);
2561 + vty_out (vty, " Known via \"%s\"", route_info[rib->type].str);
2562 + vty_out (vty, ", distance %d, metric %d", rib->distance, rib->metric);
2563 + if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
2564 + vty_out (vty, ", best");
2565 + if (rib->refcnt)
2566 + vty_out (vty, ", refcnt %ld", rib->refcnt);
2567 + vty_out (vty, "%s", VTY_NEWLINE);
2569 +#define ONE_DAY_SECOND 60*60*24
2570 +#define ONE_WEEK_SECOND 60*60*24*7
2571 + if (rib->type == ZEBRA_ROUTE_RIPNG
2572 + || rib->type == ZEBRA_ROUTE_OSPF6
2573 + || rib->type == ZEBRA_ROUTE_BGP)
2575 + time_t uptime;
2576 + struct tm *tm;
2578 + uptime = time (NULL);
2579 + uptime -= rib->uptime;
2580 + tm = gmtime (&uptime);
2582 + vty_out (vty, " Last update ");
2584 + if (uptime < ONE_DAY_SECOND)
2585 + vty_out (vty, "%02d:%02d:%02d",
2586 + tm->tm_hour, tm->tm_min, tm->tm_sec);
2587 + else if (uptime < ONE_WEEK_SECOND)
2588 + vty_out (vty, "%dd%02dh%02dm",
2589 + tm->tm_yday, tm->tm_hour, tm->tm_min);
2590 + else
2591 + vty_out (vty, "%02dw%dd%02dh",
2592 + tm->tm_yday/7,
2593 + tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
2594 + vty_out (vty, " ago%s", VTY_NEWLINE);
2597 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
2599 + vty_out (vty, " %c",
2600 + CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ');
2602 + switch (nexthop->type)
2604 + case NEXTHOP_TYPE_IPV6:
2605 + case NEXTHOP_TYPE_IPV6_IFINDEX:
2606 + case NEXTHOP_TYPE_IPV6_IFNAME:
2607 + vty_out (vty, " %s",
2608 + inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
2609 + if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
2610 + vty_out (vty, ", %s", nexthop->ifname);
2611 + else if (nexthop->ifindex)
2612 + vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
2613 + break;
2614 + case NEXTHOP_TYPE_IFINDEX:
2615 + vty_out (vty, " directly connected, %s",
2616 + ifindex2ifname (nexthop->ifindex));
2617 + break;
2618 + case NEXTHOP_TYPE_IFNAME:
2619 + vty_out (vty, " directly connected, %s",
2620 + nexthop->ifname);
2621 + break;
2622 + default:
2623 + break;
2626 + if (nexthop->mplsindex)
2627 + vty_out (vty, " MPLS 0x%x", nexthop->mplsindex);
2629 + if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
2630 + vty_out (vty, " inactive");
2632 + if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
2634 + vty_out (vty, " (recursive");
2636 + switch (nexthop->rtype)
2638 + case NEXTHOP_TYPE_IPV6:
2639 + case NEXTHOP_TYPE_IPV6_IFINDEX:
2640 + case NEXTHOP_TYPE_IPV6_IFNAME:
2641 + vty_out (vty, " via %s",
2642 + inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
2643 + buf, BUFSIZ));
2644 + if (nexthop->rifindex)
2645 + vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
2646 + break;
2647 + case NEXTHOP_TYPE_IFINDEX:
2648 + case NEXTHOP_TYPE_IFNAME:
2649 + vty_out (vty, " is directly connected, %s",
2650 + ifindex2ifname (nexthop->rifindex));
2651 + break;
2652 + default:
2653 + break;
2655 + if (nexthop->rmplsindex)
2656 + vty_out (vty, " MPLS 0x%x", nexthop->rmplsindex);
2658 + vty_out (vty, ")");
2660 + vty_out (vty, "%s", VTY_NEWLINE);
2662 + vty_out (vty, "%s", VTY_NEWLINE);
2666 +void
2667 +vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
2668 + struct rib *rib)
2670 + struct nexthop *nexthop;
2671 + int len = 0;
2672 + char buf[BUFSIZ];
2674 + /* Nexthop information. */
2675 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
2677 + if (nexthop == rib->nexthop)
2679 + /* Prefix information. */
2680 + len = vty_out (vty, "%c%c%c %s/%d",
2681 + route_info[rib->type].c,
2682 + CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
2683 + ? '>' : ' ',
2684 + CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
2685 + ? '*' : ' ',
2686 + inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
2687 + rn->p.prefixlen);
2689 + /* Distance and metric display. */
2690 + if (rib->type != ZEBRA_ROUTE_CONNECT
2691 + && rib->type != ZEBRA_ROUTE_KERNEL)
2692 + len += vty_out (vty, " [%d/%d]", rib->distance,
2693 + rib->metric);
2695 + else
2696 + vty_out (vty, " %c%*c",
2697 + CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
2698 + ? '*' : ' ',
2699 + len - 3, ' ');
2701 + switch (nexthop->type)
2703 + case NEXTHOP_TYPE_IPV6:
2704 + case NEXTHOP_TYPE_IPV6_IFINDEX:
2705 + case NEXTHOP_TYPE_IPV6_IFNAME:
2706 + vty_out (vty, " via %s",
2707 + inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
2708 + if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
2709 + vty_out (vty, ", %s", nexthop->ifname);
2710 + else if (nexthop->ifindex)
2711 + vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
2712 + break;
2713 + case NEXTHOP_TYPE_IFINDEX:
2714 + vty_out (vty, " is directly connected, %s",
2715 + ifindex2ifname (nexthop->ifindex));
2716 + break;
2717 + case NEXTHOP_TYPE_IFNAME:
2718 + vty_out (vty, " is directly connected, %s",
2719 + nexthop->ifname);
2720 + break;
2721 + default:
2722 + break;
2724 + if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
2725 + vty_out (vty, " inactive");
2727 + if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
2729 + vty_out (vty, " (recursive");
2731 + switch (nexthop->rtype)
2733 + case NEXTHOP_TYPE_IPV6:
2734 + case NEXTHOP_TYPE_IPV6_IFINDEX:
2735 + case NEXTHOP_TYPE_IPV6_IFNAME:
2736 + vty_out (vty, " via %s)",
2737 + inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
2738 + buf, BUFSIZ));
2739 + if (nexthop->rifindex)
2740 + vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
2741 + break;
2742 + case NEXTHOP_TYPE_IFINDEX:
2743 + case NEXTHOP_TYPE_IFNAME:
2744 + vty_out (vty, " is directly connected, %s)",
2745 + ifindex2ifname (nexthop->rifindex));
2746 + break;
2747 + case NEXTHOP_TYPE_MPLS:
2748 + vty_out (vty, " LSP 0x%x", nexthop->rgate.lsp_index);
2749 + break;
2750 + default:
2751 + break;
2755 + if (rib->type == ZEBRA_ROUTE_RIPNG
2756 + || rib->type == ZEBRA_ROUTE_OSPF6
2757 + || rib->type == ZEBRA_ROUTE_BGP)
2759 + time_t uptime;
2760 + struct tm *tm;
2762 + uptime = time (NULL);
2763 + uptime -= rib->uptime;
2764 + tm = gmtime (&uptime);
2766 +#define ONE_DAY_SECOND 60*60*24
2767 +#define ONE_WEEK_SECOND 60*60*24*7
2769 + if (uptime < ONE_DAY_SECOND)
2770 + vty_out (vty, ", %02d:%02d:%02d",
2771 + tm->tm_hour, tm->tm_min, tm->tm_sec);
2772 + else if (uptime < ONE_WEEK_SECOND)
2773 + vty_out (vty, ", %dd%02dh%02dm",
2774 + tm->tm_yday, tm->tm_hour, tm->tm_min);
2775 + else
2776 + vty_out (vty, ", %02dw%dd%02dh",
2777 + tm->tm_yday/7,
2778 + tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
2780 + vty_out (vty, "%s", VTY_NEWLINE);
2784 +#define SHOW_ROUTE_V6_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3,%s B - BGP, * - FIB route.%s%s"
2786 +DEFUN (show_ipv6_route,
2787 + show_ipv6_route_cmd,
2788 + "show ipv6 route",
2789 + SHOW_STR
2790 + IP_STR
2791 + "IPv6 routing table\n")
2793 + struct route_node *rn;
2794 + struct rib *rib;
2795 + int first = 1;
2797 + /* Show all IPv6 route. */
2798 + for (rn = route_top (rib_table_ipv6->table); rn; rn = route_next (rn))
2799 + for (rib = rn->info; rib; rib = rib->next)
2801 + if (first)
2803 + vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
2804 + first = 0;
2806 + vty_show_ipv6_route (vty, rn, rib);
2808 + return CMD_SUCCESS;
2811 +DEFUN (show_ipv6_route_prefix_longer,
2812 + show_ipv6_route_prefix_longer_cmd,
2813 + "show ipv6 route X:X::X:X/M longer-prefixes",
2814 + SHOW_STR
2815 + IP_STR
2816 + "IPv6 routing table\n"
2817 + "IPv6 prefix\n"
2818 + "Show route matching the specified Network/Mask pair only\n")
2820 + struct route_node *rn;
2821 + struct rib *rib;
2822 + struct prefix p;
2823 + int ret;
2824 + int first = 1;
2826 + ret = str2prefix (argv[0], &p);
2827 + if (! ret)
2829 + vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
2830 + return CMD_WARNING;
2833 + /* Show matched type IPv6 routes. */
2834 + for (rn = route_top (rib_table_ipv6->table); rn; rn = route_next (rn))
2835 + for (rib = rn->info; rib; rib = rib->next)
2836 + if (prefix_match (&p, &rn->p))
2838 + if (first)
2840 + vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
2841 + first = 0;
2843 + vty_show_ipv6_route (vty, rn, rib);
2845 + return CMD_SUCCESS;
2848 +DEFUN (show_ipv6_route_protocol,
2849 + show_ipv6_route_protocol_cmd,
2850 + "show ipv6 route (bgp|connected|kernel|ospf6|ripng|static)",
2851 + SHOW_STR
2852 + IP_STR
2853 + "IP routing table\n"
2854 + "Border Gateway Protocol (BGP)\n"
2855 + "Connected\n"
2856 + "Kernel\n"
2857 + "Open Shortest Path First (OSPFv3)\n"
2858 + "Routing Information Protocol (RIPng)\n"
2859 + "Static routes\n")
2861 + int type;
2862 + struct route_node *rn;
2863 + struct rib *rib;
2864 + int first = 1;
2866 + if (strncmp (argv[0], "b", 1) == 0)
2867 + type = ZEBRA_ROUTE_BGP;
2868 + else if (strncmp (argv[0], "c", 1) == 0)
2869 + type = ZEBRA_ROUTE_CONNECT;
2870 + else if (strncmp (argv[0], "k", 1) ==0)
2871 + type = ZEBRA_ROUTE_KERNEL;
2872 + else if (strncmp (argv[0], "o", 1) == 0)
2873 + type = ZEBRA_ROUTE_OSPF6;
2874 + else if (strncmp (argv[0], "r", 1) == 0)
2875 + type = ZEBRA_ROUTE_RIPNG;
2876 + else if (strncmp (argv[0], "s", 1) == 0)
2877 + type = ZEBRA_ROUTE_STATIC;
2878 + else
2880 + vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
2881 + return CMD_WARNING;
2884 + /* Show matched type IPv6 routes. */
2885 + for (rn = route_top (rib_table_ipv6->table); rn; rn = route_next (rn))
2886 + for (rib = rn->info; rib; rib = rib->next)
2887 + if (rib->type == type)
2889 + if (first)
2891 + vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
2892 + first = 0;
2894 + vty_show_ipv6_route (vty, rn, rib);
2896 + return CMD_SUCCESS;
2899 +DEFUN (show_ipv6_route_addr,
2900 + show_ipv6_route_addr_cmd,
2901 + "show ipv6 route X:X::X:X",
2902 + SHOW_STR
2903 + IP_STR
2904 + "IPv6 routing table\n"
2905 + "IPv6 Address\n")
2907 + int ret;
2908 + struct prefix_ipv6 p;
2909 + struct route_node *rn;
2911 + ret = str2prefix_ipv6 (argv[0], &p);
2912 + if (ret <= 0)
2914 + vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
2915 + return CMD_WARNING;
2918 + rn = route_node_match (rib_table_ipv6->table, (struct prefix *) &p);
2919 + if (! rn)
2921 + vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2922 + return CMD_WARNING;
2925 + vty_show_ipv6_route_detail (vty, rn);
2927 + route_unlock_node (rn);
2929 + return CMD_SUCCESS;
2932 +DEFUN (show_ipv6_route_prefix,
2933 + show_ipv6_route_prefix_cmd,
2934 + "show ipv6 route X:X::X:X/M",
2935 + SHOW_STR
2936 + IP_STR
2937 + "IPv6 routing table\n"
2938 + "IPv6 prefix\n")
2940 + int ret;
2941 + struct prefix_ipv6 p;
2942 + struct route_node *rn;
2944 + ret = str2prefix_ipv6 (argv[0], &p);
2945 + if (ret <= 0)
2947 + vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
2948 + return CMD_WARNING;
2951 + rn = route_node_match (rib_table_ipv6->table, (struct prefix *) &p);
2952 + if (! rn || rn->p.prefixlen != p.prefixlen)
2954 + vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2955 + return CMD_WARNING;
2958 + vty_show_ipv6_route_detail (vty, rn);
2960 + route_unlock_node (rn);
2962 + return CMD_SUCCESS;
2964 +#endif /* HAVE_IPV6 */
2966 +/* RIB update function. */
2967 +void
2968 +rib_update ()
2970 + struct route_node *rn;
2972 + for (rn = route_top (rib_table_ipv4->table); rn; rn = route_next (rn))
2973 + /* Update reachability. */
2974 + rib_process (rn, NULL);
2976 +#ifdef HAVE_IPV6
2977 + for (rn = route_top (rib_table_ipv6->table); rn; rn = route_next (rn))
2978 + rib_process (rn, NULL);
2979 +#endif /* HAVE_IPV6 */
2982 +/* Interface goes up. */
2983 +void
2984 +rib_if_up (struct interface *ifp)
2986 + rib_update ();
2989 +/* Interface goes down. */
2990 +void
2991 +rib_if_down (struct interface *ifp)
2993 + rib_update ();
2996 +/* Close rib when zebra terminates. */
2997 +void
2998 +rib_close ()
3000 + rib_close_ipv4 ();
3001 +#ifdef HAVE_IPV6
3002 + rib_close_ipv6 ();
3003 +#endif /* HAVE_IPV6 */
3006 +struct rib_table *rib_table_init() {
3007 + struct rib_table *rt;
3008 + rt = XCALLOC (MTYPE_ROUTE_TABLE, sizeof (struct rib_table));
3009 + memset(rt,0,sizeof (struct rib_table));
3010 + rt->table = route_table_init();
3011 + return rt;
3014 +/* Routing information base initialize. */
3015 +void
3016 +rib_init ()
3019 + rib_table_ipv4 = rib_table_init ();
3021 +#ifdef HAVE_IPV6
3022 + rib_table_ipv6 = rib_table_init ();
3024 +#endif /* HAVE_IPV6 */
3026 diff -uNr --exclude=CVS zebra/lib/rib.h zebra-ldp/lib/rib.h
3027 --- zebra/lib/rib.h Wed Dec 31 19:00:00 1969
3028 +++ zebra-ldp/lib/rib.h Wed Oct 9 23:47:40 2002
3029 @@ -0,0 +1,199 @@
3031 + * Routing Information Base header
3032 + * Copyright (C) 1997 Kunihiro Ishiguro
3034 + * This file is part of GNU Zebra.
3036 + * GNU Zebra is free software; you can redistribute it and/or modify it
3037 + * under the terms of the GNU General Public License as published by the
3038 + * Free Software Foundation; either version 2, or (at your option) any
3039 + * later version.
3041 + * GNU Zebra is distributed in the hope that it will be useful, but
3042 + * WITHOUT ANY WARRANTY; without even the implied warranty of
3043 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3044 + * General Public License for more details.
3046 + * You should have received a copy of the GNU General Public License
3047 + * along with GNU Zebra; see the file COPYING. If not, write to the Free
3048 + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3049 + * 02111-1307, USA.
3050 + */
3052 +#ifndef _LIB_RIB_H
3053 +#define _LIB_RIB_H
3055 +#include "table.h"
3057 +#define DISTANCE_INFINITY 255
3059 +/* Routing information base. */
3060 +struct rib
3062 + /* Link list. */
3063 + struct rib *next;
3064 + struct rib *prev;
3065 + struct rib_table *rib_table;
3067 + /* Which routing table */
3068 + int table;
3070 + /* Type fo this route. */
3071 + int type;
3073 + /* Distance. */
3074 + u_char distance;
3076 + /* Flags of this route. This flag's definition is in lib/zebra.h
3077 + ZEBRA_FLAG_* */
3078 + u_char flags;
3080 + /* Metric */
3081 + u_int32_t metric;
3083 + /* Uptime. */
3084 + time_t uptime;
3086 + /* Refrence count. */
3087 + unsigned long refcnt;
3089 + /* Nexthop information. */
3090 + u_char nexthop_num;
3091 + u_char nexthop_active_num;
3092 + u_char nexthop_fib_num;
3094 + struct nexthop *nexthop;
3097 +/* Nexthop structure. */
3098 +struct nexthop
3100 + struct nexthop *next;
3101 + struct nexthop *prev;
3103 + u_char type;
3104 +#define NEXTHOP_TYPE_IFINDEX 1 /* Directly connected. */
3105 +#define NEXTHOP_TYPE_IFNAME 2 /* Interface route. */
3106 +#define NEXTHOP_TYPE_IPV4 3 /* IPv4 nexthop. */
3107 +#define NEXTHOP_TYPE_IPV4_IFINDEX 4 /* IPv4 nexthop with ifindex. */
3108 +#define NEXTHOP_TYPE_IPV4_IFNAME 5 /* IPv4 nexthop with ifname. */
3109 +#define NEXTHOP_TYPE_IPV6 6 /* IPv6 nexthop. */
3110 +#define NEXTHOP_TYPE_IPV6_IFINDEX 7 /* IPv6 nexthop with ifindex. */
3111 +#define NEXTHOP_TYPE_IPV6_IFNAME 8 /* IPv6 nexthop with ifname. */
3113 + u_char flags;
3114 +#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
3115 +#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
3116 +#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
3118 + /* Interface index. */
3119 + unsigned int ifindex;
3120 + char *ifname;
3122 + /* MPLS index */
3123 + unsigned int mplsindex;
3125 + /* Nexthop address or interface name. */
3126 + union
3128 + struct in_addr ipv4;
3129 +#ifdef HAVE_IPV6
3130 + struct in6_addr ipv6;
3131 +#endif /* HAVE_IPV6*/
3132 + } gate;
3134 + /* Recursive lookup nexthop. */
3135 + u_char rtype;
3136 + unsigned int rifindex;
3137 + unsigned int rmplsindex;
3138 + union
3140 + struct in_addr ipv4;
3141 +#ifdef HAVE_IPV6
3142 + struct in6_addr ipv6;
3143 +#endif /* HAVE_IPV6 */
3144 + } rgate;
3146 + struct nexthop *indirect;
3149 +struct rib_table {
3151 + struct route_table *table;
3152 + void (*redistribute_add) (struct prefix *p, struct rib *rib);
3153 + void (*redistribute_delete) (struct prefix *p, struct rib *rib);
3154 + int (*rib_install_kernel) (struct route_node *rn, struct rib *rib);
3155 + int (*rib_uninstall_kernel) (struct route_node *rn, struct rib *rib);
3158 +struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
3159 +struct nexthop *nexthop_ifname_add (struct rib *, char *);
3160 +struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
3161 +struct nexthop *nexthop_ipv4_ifindex_add (struct rib *, struct in_addr *,
3162 + unsigned int);
3163 +#ifdef HAVE_IPV6
3164 +struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
3165 +#endif /* HAVE_IPV6 */
3167 +void rib_uninstall (struct route_node *rn, struct rib *rib);
3168 +void rib_process (struct route_node *rn, struct rib *del);
3169 +void rib_addnode (struct route_node *rn, struct rib *rib);
3170 +void rib_delnode (struct route_node *rn, struct rib *rib);
3171 +void newrib_free (struct rib *rib);
3172 +void nexthop_delete (struct rib *rib, struct nexthop *nexthop);
3173 +void nexthop_free (struct nexthop *nexthop);
3174 +struct rib_table *rib_table_init ();
3176 +int
3177 +rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
3178 + struct in_addr *gate, unsigned int ifindex, int table,
3179 + u_int32_t, u_char);
3181 +int
3182 +rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
3184 +int
3185 +rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
3186 + struct in_addr *gate, unsigned int ifindex, int table);
3188 +struct rib *
3189 +rib_match_ipv4 (struct in_addr);
3191 +struct rib *
3192 +rib_lookup_ipv4 (struct prefix_ipv4 *);
3194 +void rib_update ();
3195 +void rib_close ();
3196 +void rib_init ();
3198 +extern struct rib_table *rib_table_ipv4;
3199 +extern struct cmd_element show_ip_route_cmd;
3200 +extern struct cmd_element show_ip_route_prefix_longer_cmd;
3201 +extern struct cmd_element show_ip_route_supernets_cmd;
3202 +extern struct cmd_element show_ip_route_protocol_cmd;
3203 +extern struct cmd_element show_ip_route_addr_cmd;
3204 +extern struct cmd_element show_ip_route_prefix_cmd;
3207 +#ifdef HAVE_IPV6
3208 +int
3209 +rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
3210 + struct in6_addr *gate, unsigned int ifindex, int table);
3212 +int
3213 +rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
3214 + struct in6_addr *gate, unsigned int ifindex, int table);
3216 +struct rib *rib_lookup_ipv6 (struct in6_addr *);
3218 +struct rib *rib_match_ipv6 (struct in6_addr *);
3220 +extern struct rib_table *rib_table_ipv6;
3221 +extern struct cmd_element show_ipv6_route_cmd;
3222 +extern struct cmd_element show_ipv6_route_prefix_longer_cmd;
3223 +extern struct cmd_element show_ipv6_route_protocol_cmd;
3224 +extern struct cmd_element show_ipv6_route_addr_cmd;
3225 +extern struct cmd_element show_ipv6_route_prefix_cmd;
3226 +#endif /* HAVE_IPV6 */
3228 +#endif /*_LIB_RIB_H */
3229 diff -uNr --exclude=CVS zebra/lib/table.c zebra-ldp/lib/table.c
3230 --- zebra/lib/table.c Sat Aug 24 00:14:54 2002
3231 +++ zebra-ldp/lib/table.c Sat Aug 24 00:14:45 2002
3232 @@ -311,6 +311,36 @@
3233 return NULL;
3236 +struct route_node *
3237 +route_node_lookup2 (struct route_table *table, struct prefix *p)
3239 + struct route_node *rn_in, *rn_tmp;
3241 + if (!(rn_in = route_node_lookup(table,p))) {
3242 + /* walk as far down the tree as we can */
3243 + rn_in = table->top;
3244 + while (rn_in && rn_in->p.prefixlen <= p->prefixlen &&
3245 + prefix_match(&rn_in->p, p)) {
3246 + rn_tmp = rn_in->link[check_bit(&p->u.prefix, rn_in->p.prefixlen)];
3247 + if (!rn_tmp) {
3248 + break;
3250 + rn_in = rn_tmp;
3252 + route_lock_node(rn_in);
3254 + /* rn_in is either the actual node or the furthest node in the tree */
3255 + /* so get the 'next' one with 'info' */
3256 + rn_in = route_next2(rn_in);
3259 + if (rn_in && !rn_in->info) {
3260 + route_unlock_node(rn_in);
3261 + rn_in = NULL;
3263 + return rn_in;
3266 /* Add node to routing table. */
3267 struct route_node *
3268 route_node_get (struct route_table *table, struct prefix *p)
3269 @@ -458,6 +488,22 @@
3270 node = node->parent;
3272 route_unlock_node (start);
3273 + return NULL;
3276 +struct route_node *
3277 +route_next2 (struct route_node *rn_in)
3279 + struct route_node *rn = rn_in;
3280 + struct route_node *rn2;
3281 + do {
3282 + rn2 = route_next(rn);
3283 + rn = rn2;
3284 + } while(rn && !rn->info);
3286 + if (rn && rn->info) {
3287 + return rn;
3289 return NULL;
3292 diff -uNr --exclude=CVS zebra/lib/table.h zebra-ldp/lib/table.h
3293 --- zebra/lib/table.h Sat Aug 24 00:14:54 2002
3294 +++ zebra-ldp/lib/table.h Thu Oct 10 21:45:55 2002
3295 @@ -23,6 +23,8 @@
3296 #ifndef _ZEBRA_TABLE_H
3297 #define _ZEBRA_TABLE_H
3299 +#include "prefix.h"
3301 /* Routing table top structure. */
3302 struct route_table
3304 @@ -59,9 +61,11 @@
3305 void route_node_delete (struct route_node *node);
3306 struct route_node *route_top (struct route_table *);
3307 struct route_node *route_next (struct route_node *);
3308 +struct route_node *route_next2 (struct route_node *);
3309 struct route_node *route_next_until (struct route_node *, struct route_node *);
3310 struct route_node *route_node_get (struct route_table *, struct prefix *);
3311 struct route_node *route_node_lookup (struct route_table *, struct prefix *);
3312 +struct route_node *route_node_lookup2 (struct route_table *, struct prefix *);
3313 struct route_node *route_lock_node (struct route_node *node);
3314 struct route_node *route_node_match (struct route_table *, struct prefix *);
3315 struct route_node *route_node_match_ipv4 (struct route_table *,
3316 diff -uNr --exclude=CVS zebra/lib/thread.c zebra-ldp/lib/thread.c
3317 --- zebra/lib/thread.c Sat Aug 24 00:14:54 2002
3318 +++ zebra-ldp/lib/thread.c Sat Aug 24 00:14:45 2002
3319 @@ -117,10 +117,26 @@
3320 sizeof (struct thread_master));
3323 +static int thread_in_list(struct thread_list *list, struct thread *thread)
3325 + struct thread *tt;
3327 + for (tt = list->head; tt; tt = tt->next)
3329 + if (tt == thread)
3331 + return 1;
3334 + return 0;
3337 /* Add a new thread to the list. */
3338 static void
3339 thread_list_add (struct thread_list *list, struct thread *thread)
3341 + assert(!thread_in_list(list,thread));
3343 thread->next = NULL;
3344 thread->prev = list->tail;
3345 if (list->tail)
3346 @@ -137,6 +153,8 @@
3347 struct thread *point,
3348 struct thread *thread)
3350 + assert(!thread_in_list(list,thread));
3352 thread->next = point;
3353 thread->prev = point->prev;
3354 if (point->prev)
3355 @@ -151,6 +169,8 @@
3356 static struct thread *
3357 thread_list_delete (struct thread_list *list, struct thread *thread)
3359 + assert(thread_in_list(list,thread));
3361 if (thread->next)
3362 thread->next->prev = thread->prev;
3363 else
3364 diff -uNr --exclude=CVS zebra/lib/vty.c zebra-ldp/lib/vty.c
3365 --- zebra/lib/vty.c Sat Aug 24 00:14:54 2002
3366 +++ zebra-ldp/lib/vty.c Sat Aug 24 00:14:45 2002
3367 @@ -624,6 +624,11 @@
3368 case RMAP_NODE:
3369 case OSPF_NODE:
3370 case OSPF6_NODE:
3371 + case MPLS_IF_NODE:
3372 + case MPLS_IN_INSTR_NODE:
3373 + case MPLS_OUT_INSTR_NODE:
3374 + case MPLS_STATIC_NODE:
3375 + case MPLS_LDP_NODE:
3376 case KEYCHAIN_NODE:
3377 case KEYCHAIN_KEY_NODE:
3378 case MASC_NODE:
3379 @@ -1028,6 +1033,11 @@
3380 case RMAP_NODE:
3381 case OSPF_NODE:
3382 case OSPF6_NODE:
3383 + case MPLS_IF_NODE:
3384 + case MPLS_IN_INSTR_NODE:
3385 + case MPLS_OUT_INSTR_NODE:
3386 + case MPLS_STATIC_NODE:
3387 + case MPLS_LDP_NODE:
3388 case KEYCHAIN_NODE:
3389 case KEYCHAIN_KEY_NODE:
3390 case MASC_NODE:
3391 diff -uNr --exclude=CVS zebra/lib/zclient.c zebra-ldp/lib/zclient.c
3392 --- zebra/lib/zclient.c Sat Aug 24 00:14:54 2002
3393 +++ zebra-ldp/lib/zclient.c Sat Aug 24 00:14:45 2002
3394 @@ -30,8 +30,8 @@
3395 #include "zclient.h"
3396 #include "memory.h"
3397 #include "table.h"
3398 +#include "rib.h"
3400 -#include "zebra/rib.h"
3401 #include "zebra/zserv.h"
3403 /* Zebra client events. */
3404 @@ -260,6 +260,9 @@
3405 /* We need interface information. */
3406 zebra_message_send (zclient, ZEBRA_INTERFACE_ADD);
3408 + /* We need router-id information. */
3409 + zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD);
3411 /* Flush all redistribute request. */
3412 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
3413 if (i != zclient->redist_default && zclient->redist[i])
3414 @@ -289,6 +292,38 @@
3418 +zapi_ipv4_set_mplsindex (struct zclient *zclient, struct prefix_ipv4 *p,
3419 + struct in_addr *nexthop, unsigned int ifindex,
3420 + unsigned int mplsindex)
3422 + int psize;
3423 + struct stream *s;
3425 + /* Reset stream. */
3426 + s = zclient->obuf;
3427 + stream_reset (s);
3429 + /* Length place holder. */
3430 + stream_putw (s, 0);
3432 + /* Put command, type and nexthop. */
3433 + stream_putc (s, ZEBRA_IPV4_SET_MPLSINDEX);
3435 + /* Put prefix information. */
3436 + psize = PSIZE (p->prefixlen);
3437 + stream_putc (s, p->prefixlen);
3438 + stream_write (s, (u_char *)&p->prefix, psize);
3439 + stream_put_in_addr (s, nexthop);
3440 + stream_putl (s, ifindex);
3441 + stream_putl (s, mplsindex);
3443 + /* Put length at the first point of the stream. */
3444 + stream_putw_at (s, 0, stream_get_endp (s));
3446 + return writen (zclient->sock, s->data, stream_get_endp (s));
3449 +int
3450 zapi_ipv4_add (struct zclient *zclient, struct prefix_ipv4 *p,
3451 struct zapi_ipv4 *api)
3453 @@ -528,6 +563,20 @@
3454 return ret;
3457 +/* Router-id update from zebra daemon. */
3458 +void
3459 +zebra_router_id_update_read (struct stream *s, struct prefix *rid)
3461 + int plen;
3463 + /* Fetch interface address. */
3464 + rid->family = stream_getc (s);
3466 + plen = prefix_blen (rid);
3467 + stream_get (&rid->u.prefix, s, plen);
3468 + rid->prefixlen = stream_getc (s);
3471 /* Interface addition from zebra daemon. */
3472 struct interface *
3473 zebra_interface_add_read (struct stream *s)
3474 @@ -596,6 +645,19 @@
3475 return ifp;
3478 +void
3479 +zebra_interface_if_set_value (struct stream *s, struct interface *ifp)
3481 + /* Read interface's index. */
3482 + ifp->ifindex = stream_getl (s);
3484 + /* Read interface's value. */
3485 + ifp->flags = stream_getl (s);
3486 + ifp->metric = stream_getl (s);
3487 + ifp->mtu = stream_getl (s);
3488 + ifp->bandwidth = stream_getl (s);
3491 struct connected *
3492 zebra_interface_address_add_read (struct stream *s)
3494 @@ -760,6 +822,10 @@
3496 switch (command)
3498 + case ZEBRA_ROUTER_ID_UPDATE:
3499 + if (zclient->router_id_update)
3500 + ret = (*zclient->router_id_update) (command, zclient, length);
3501 + break;
3502 case ZEBRA_INTERFACE_ADD:
3503 if (zclient->interface_add)
3504 ret = (*zclient->interface_add) (command, zclient, length);
3505 diff -uNr --exclude=CVS zebra/lib/zclient.h zebra-ldp/lib/zclient.h
3506 --- zebra/lib/zclient.h Sat Aug 24 00:14:54 2002
3507 +++ zebra-ldp/lib/zclient.h Thu Oct 10 22:14:45 2002
3508 @@ -24,6 +24,7 @@
3510 /* For struct interface and struct connected. */
3511 #include "if.h"
3512 +#include "prefix.h"
3514 /* For input/output buffer to zebra. */
3515 #define ZEBRA_MAX_PACKET_SIZ 4096
3516 @@ -62,6 +63,7 @@
3517 u_char default_information;
3519 /* Pointer to the callback functions. */
3520 + int (*router_id_update) (int, struct zclient *, zebra_size_t);
3521 int (*interface_add) (int, struct zclient *, zebra_size_t);
3522 int (*interface_delete) (int, struct zclient *, zebra_size_t);
3523 int (*interface_up) (int, struct zclient *, zebra_size_t);
3524 @@ -100,6 +102,9 @@
3525 u_int32_t metric;
3528 +int zapi_ipv4_set_mplsindex (struct zclient *, struct prefix_ipv4 *,
3529 + struct in_addr*, unsigned int, unsigned int);
3532 zapi_ipv4_add (struct zclient *, struct prefix_ipv4 *, struct zapi_ipv4 *);
3534 @@ -127,8 +132,11 @@
3536 struct interface *zebra_interface_add_read (struct stream *);
3537 struct interface *zebra_interface_state_read (struct stream *s);
3538 +void zebra_interface_if_set_value (struct stream *, struct interface *);
3539 struct connected *zebra_interface_address_add_read (struct stream *);
3540 struct connected *zebra_interface_address_delete_read (struct stream *);
3541 +void zebra_router_id_update_read (struct stream *s, struct prefix *rid);
3544 #ifdef HAVE_IPV6
3545 /* IPv6 prefix add and delete function prototype. */
3546 diff -uNr --exclude=CVS zebra/lib/zebra.h zebra-ldp/lib/zebra.h
3547 --- zebra/lib/zebra.h Sat Aug 24 00:14:54 2002
3548 +++ zebra-ldp/lib/zebra.h Sat Aug 24 00:14:46 2002
3549 @@ -219,7 +219,11 @@
3550 #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
3551 #define ZEBRA_IPV4_IMPORT_LOOKUP 17
3552 #define ZEBRA_IPV6_IMPORT_LOOKUP 18
3553 -#define ZEBRA_MESSAGE_MAX 19
3554 +#define ZEBRA_ROUTER_ID_ADD 19
3555 +#define ZEBRA_ROUTER_ID_DELETE 20
3556 +#define ZEBRA_ROUTER_ID_UPDATE 21
3557 +#define ZEBRA_IPV4_SET_MPLSINDEX 22
3558 +#define ZEBRA_MESSAGE_MAX 23
3560 /* Zebra route's types. */
3561 #define ZEBRA_ROUTE_SYSTEM 0
3562 @@ -231,7 +235,8 @@
3563 #define ZEBRA_ROUTE_OSPF 6
3564 #define ZEBRA_ROUTE_OSPF6 7
3565 #define ZEBRA_ROUTE_BGP 8
3566 -#define ZEBRA_ROUTE_MAX 9
3567 +#define ZEBRA_ROUTE_MPLS 9
3568 +#define ZEBRA_ROUTE_MAX 10
3570 /* Zebra's family types. */
3571 #define ZEBRA_FAMILY_IPV4 1
3572 @@ -252,6 +257,7 @@
3573 #define ZEBRA_FLAG_SELECTED 0x10
3574 #define ZEBRA_FLAG_CHANGED 0x20
3575 #define ZEBRA_FLAG_STATIC 0x40
3576 +#define ZEBRA_FLAG_MPLS_CHANGED 0x80
3578 /* Zebra nexthop flags. */
3579 #define ZEBRA_NEXTHOP_IFINDEX 1
3580 diff -uNr --exclude=CVS zebra/mplsd/Makefile.am zebra-ldp/mplsd/Makefile.am
3581 --- zebra/mplsd/Makefile.am Wed Dec 31 19:00:00 1969
3582 +++ zebra-ldp/mplsd/Makefile.am Tue Nov 19 22:20:07 2002
3583 @@ -0,0 +1,65 @@
3584 +## Process this file with automake to produce Makefile.in.
3586 +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib
3587 +DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
3588 +INSTALL_SDATA=@INSTALL@ -m 600
3590 +sbin_PROGRAMS = mplsd
3592 +mplsd_SOURCES = \
3593 +impl_fib.c impl_ifmgr.c impl_lock.c impl_mm.c impl_mpls.c \
3594 +impl_policy.c impl_socket.c impl_timer.c impl_tree.c \
3595 +mpls.c mpls_interface.c mpls_zebra.c mpls_main.c mpls_vty.c\
3596 +static.c static_vty.c \
3597 +ldp.c ldp_interface.c ldp_vty.c\
3598 +ldp_addr.c ldp_adj.c \
3599 +ldp_attr.c ldp_buf.c ldp_cfg.c ldp_entity.c ldp_fec.c ldp_global.c \
3600 +ldp_hello.c ldp_hop.c ldp_hop_list.c ldp_if.c ldp_inet_addr.c \
3601 +ldp_init.c ldp_inlabel.c ldp_keepalive.c ldp_label_abort.c \
3602 +ldp_label_mapping.c ldp_label_rel_with.c ldp_label_request.c \
3603 +ldp_mesg.c ldp_nortel.c ldp_notif.c ldp_outlabel.c \
3604 +ldp_pdu_setup.c ldp_peer.c \
3605 +ldp_resource.c ldp_session.c ldp_state_funcs.c \
3606 +ldp_state_machine.c ldp_tunnel.c \
3607 +lsr_cfg.c lsr_global.c lsr_if.c lsr_insegment.c lsr_labelmanager.c \
3608 +lsr_outsegment.c lsr_xconnect.c lsr_ftn.c
3611 +noinst_HEADERS = \
3612 +mpls.h mpls_interface.h mpls_zebra.h mpls_vty.h \
3613 +ldp.h ldp_interface.h ldp_vty.h \
3614 +static.h static_vty.h \
3615 +ldp_addr.h ldp_adj.h ldp_attr.h ldp_buf.h ldp_cfg.h \
3616 +ldp_defaults.h ldp_entity.h ldp_fec.h \
3617 +ldp_global.h mpls_handle_type.h ldp_hello.h ldp_hop.h \
3618 +ldp_hop_list.h ldp_if.h ldp_inet_addr.h \
3619 +ldp_init.h ldp_inlabel.h ldp_keepalive.h ldp_label_abort.h \
3620 +ldp_label_mapping.h ldp_label_rel_with.h ldp_label_request.h \
3621 +ldp_mesg.h ldp_nortel.h ldp_notif.h ldp_outlabel.h ldp_pdu.h \
3622 +ldp_pdu_setup.h ldp_peer.h mpls_refcnt.h ldp_resource.h \
3623 +ldp_session.h ldp_state_machine.h ldp_struct.h ldp_tunnel.h \
3624 +mpls_tree_impl.h mpls_mm_impl.h mpls_mpls_impl.h mpls_trace_impl.h \
3625 +mpls_assert.h mpls_fib_impl.h mpls_ifmgr_impl.h mpls_list.h mpls_lock_impl.h \
3626 +mpls_policy_impl.h mpls_socket_impl.h mpls_timer_impl.h mpls_trace.h \
3627 +mpls_struct.h \
3628 +lsr_cfg.h lsr_defaults.h lsr_global.h lsr_if.h lsr_insegment.h \
3629 +lsr_labelmanager.h lsr_outsegment.h lsr_struct.h lsr_xconnect.h lsr_ftn.h
3631 +mplsd_LDADD = ../lib/libzebra.a
3633 +sysconf_DATA = mplsd.conf.sample
3635 +EXTRA_DIST = $(sysconf_DATA)
3637 +install-sysconfDATA: $(sysconf_DATA)
3638 + @$(NORMAL_INSTALL)
3639 + $(mkinstalldirs) $(DESTDIR)$(sysconfdir)
3640 + @list='$(sysconf_DATA)'; for p in $$list; do \
3641 + if test -f $(srcdir)/$$p; then \
3642 + echo " $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p"; \
3643 + $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p; \
3644 + else if test -f $$p; then \
3645 + echo " $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p"; \
3646 + $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p; \
3647 + fi; fi; \
3648 + done
3649 diff -uNr --exclude=CVS zebra/mplsd/Makefile.in zebra-ldp/mplsd/Makefile.in
3650 --- zebra/mplsd/Makefile.in Wed Dec 31 19:00:00 1969
3651 +++ zebra-ldp/mplsd/Makefile.in Tue Nov 19 22:21:14 2002
3652 @@ -0,0 +1,532 @@
3653 +# Makefile.in generated by automake 1.6.2 from Makefile.am.
3654 +# @configure_input@
3656 +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3657 +# Free Software Foundation, Inc.
3658 +# This Makefile.in is free software; the Free Software Foundation
3659 +# gives unlimited permission to copy and/or distribute it,
3660 +# with or without modifications, as long as this notice is preserved.
3662 +# This program is distributed in the hope that it will be useful,
3663 +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
3664 +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
3665 +# PARTICULAR PURPOSE.
3667 +@SET_MAKE@
3668 +SHELL = @SHELL@
3670 +srcdir = @srcdir@
3671 +top_srcdir = @top_srcdir@
3672 +VPATH = @srcdir@
3673 +prefix = @prefix@
3674 +exec_prefix = @exec_prefix@
3676 +bindir = @bindir@
3677 +sbindir = @sbindir@
3678 +libexecdir = @libexecdir@
3679 +datadir = @datadir@
3680 +sysconfdir = @sysconfdir@
3681 +sharedstatedir = @sharedstatedir@
3682 +localstatedir = @localstatedir@
3683 +libdir = @libdir@
3684 +infodir = @infodir@
3685 +mandir = @mandir@
3686 +includedir = @includedir@
3687 +oldincludedir = /usr/include
3688 +pkgdatadir = $(datadir)/@PACKAGE@
3689 +pkglibdir = $(libdir)/@PACKAGE@
3690 +pkgincludedir = $(includedir)/@PACKAGE@
3691 +top_builddir = ..
3693 +ACLOCAL = @ACLOCAL@
3694 +AUTOCONF = @AUTOCONF@
3695 +AUTOMAKE = @AUTOMAKE@
3696 +AUTOHEADER = @AUTOHEADER@
3698 +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
3699 +INSTALL = @INSTALL@
3700 +INSTALL_PROGRAM = @INSTALL_PROGRAM@
3701 +INSTALL_DATA = @INSTALL_DATA@
3702 +install_sh_DATA = $(install_sh) -c -m 644
3703 +install_sh_PROGRAM = $(install_sh) -c
3704 +install_sh_SCRIPT = $(install_sh) -c
3705 +INSTALL_SCRIPT = @INSTALL_SCRIPT@
3706 +INSTALL_HEADER = $(INSTALL_DATA)
3707 +transform = @program_transform_name@
3708 +NORMAL_INSTALL = :
3709 +PRE_INSTALL = :
3710 +POST_INSTALL = :
3711 +NORMAL_UNINSTALL = :
3712 +PRE_UNINSTALL = :
3713 +POST_UNINSTALL = :
3714 +host_alias = @host_alias@
3715 +host_triplet = @host@
3717 +EXEEXT = @EXEEXT@
3718 +OBJEXT = @OBJEXT@
3719 +PATH_SEPARATOR = @PATH_SEPARATOR@
3720 +AMTAR = @AMTAR@
3721 +AR = @AR@
3722 +AWK = @AWK@
3723 +BGPD = @BGPD@
3724 +CC = @CC@
3725 +CPP = @CPP@
3726 +CURSES = @CURSES@
3727 +DEPDIR = @DEPDIR@
3728 +IF_METHOD = @IF_METHOD@
3729 +IF_PROC = @IF_PROC@
3731 +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib
3732 +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
3733 +IPFORWARD = @IPFORWARD@
3734 +KERNEL_METHOD = @KERNEL_METHOD@
3735 +LIBPAM = @LIBPAM@
3736 +LIB_IPV6 = @LIB_IPV6@
3737 +LIB_REGEX = @LIB_REGEX@
3738 +MPLSD = @MPLSD@
3739 +MULTIPATH_NUM = @MULTIPATH_NUM@
3740 +OSPF6D = @OSPF6D@
3741 +OSPFD = @OSPFD@
3742 +OTHER_METHOD = @OTHER_METHOD@
3743 +PACKAGE = @PACKAGE@
3744 +RANLIB = @RANLIB@
3745 +RIPD = @RIPD@
3746 +RIPNGD = @RIPNGD@
3747 +RTREAD_METHOD = @RTREAD_METHOD@
3748 +RT_METHOD = @RT_METHOD@
3749 +STRIP = @STRIP@
3750 +VERSION = @VERSION@
3751 +VTYSH = @VTYSH@
3752 +ZEBRA = @ZEBRA@
3753 +am__include = @am__include@
3754 +am__quote = @am__quote@
3755 +install_sh = @install_sh@
3756 +DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
3757 +INSTALL_SDATA = @INSTALL@ -m 600
3759 +sbin_PROGRAMS = mplsd
3761 +mplsd_SOURCES = \
3762 +impl_fib.c impl_ifmgr.c impl_lock.c impl_mm.c impl_mpls.c \
3763 +impl_policy.c impl_socket.c impl_timer.c impl_tree.c \
3764 +mpls.c mpls_interface.c mpls_zebra.c mpls_main.c mpls_vty.c\
3765 +static.c static_vty.c \
3766 +ldp.c ldp_interface.c ldp_vty.c\
3767 +ldp_addr.c ldp_adj.c \
3768 +ldp_attr.c ldp_buf.c ldp_cfg.c ldp_entity.c ldp_fec.c ldp_global.c \
3769 +ldp_hello.c ldp_hop.c ldp_hop_list.c ldp_if.c ldp_inet_addr.c \
3770 +ldp_init.c ldp_inlabel.c ldp_keepalive.c ldp_label_abort.c \
3771 +ldp_label_mapping.c ldp_label_rel_with.c ldp_label_request.c \
3772 +ldp_mesg.c ldp_nortel.c ldp_notif.c ldp_outlabel.c \
3773 +ldp_pdu_setup.c ldp_peer.c \
3774 +ldp_resource.c ldp_session.c ldp_state_funcs.c \
3775 +ldp_state_machine.c ldp_tunnel.c \
3776 +lsr_cfg.c lsr_global.c lsr_if.c lsr_insegment.c lsr_labelmanager.c \
3777 +lsr_outsegment.c lsr_xconnect.c lsr_ftn.c
3780 +noinst_HEADERS = \
3781 +mpls.h mpls_interface.h mpls_zebra.h mpls_vty.h \
3782 +ldp.h ldp_interface.h ldp_vty.h \
3783 +static.h static_vty.h \
3784 +ldp_addr.h ldp_adj.h ldp_attr.h ldp_buf.h ldp_cfg.h \
3785 +ldp_defaults.h ldp_entity.h ldp_fec.h \
3786 +ldp_global.h mpls_handle_type.h ldp_hello.h ldp_hop.h \
3787 +ldp_hop_list.h ldp_if.h ldp_inet_addr.h \
3788 +ldp_init.h ldp_inlabel.h ldp_keepalive.h ldp_label_abort.h \
3789 +ldp_label_mapping.h ldp_label_rel_with.h ldp_label_request.h \
3790 +ldp_mesg.h ldp_nortel.h ldp_notif.h ldp_outlabel.h ldp_pdu.h \
3791 +ldp_pdu_setup.h ldp_peer.h mpls_refcnt.h ldp_resource.h \
3792 +ldp_session.h ldp_state_machine.h ldp_struct.h ldp_tunnel.h \
3793 +mpls_tree_impl.h mpls_mm_impl.h mpls_mpls_impl.h mpls_trace_impl.h \
3794 +mpls_assert.h mpls_fib_impl.h mpls_ifmgr_impl.h mpls_list.h mpls_lock_impl.h \
3795 +mpls_policy_impl.h mpls_socket_impl.h mpls_timer_impl.h mpls_trace.h \
3796 +mpls_struct.h \
3797 +lsr_cfg.h lsr_defaults.h lsr_global.h lsr_if.h lsr_insegment.h \
3798 +lsr_labelmanager.h lsr_outsegment.h lsr_struct.h lsr_xconnect.h lsr_ftn.h
3801 +mplsd_LDADD = ../lib/libzebra.a
3803 +sysconf_DATA = mplsd.conf.sample
3805 +EXTRA_DIST = $(sysconf_DATA)
3806 +subdir = mplsd
3807 +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
3808 +CONFIG_HEADER = $(top_builddir)/config.h
3809 +CONFIG_CLEAN_FILES =
3810 +sbin_PROGRAMS = mplsd$(EXEEXT)
3811 +PROGRAMS = $(sbin_PROGRAMS)
3813 +am_mplsd_OBJECTS = impl_fib.$(OBJEXT) impl_ifmgr.$(OBJEXT) \
3814 + impl_lock.$(OBJEXT) impl_mm.$(OBJEXT) impl_mpls.$(OBJEXT) \
3815 + impl_policy.$(OBJEXT) impl_socket.$(OBJEXT) \
3816 + impl_timer.$(OBJEXT) impl_tree.$(OBJEXT) mpls.$(OBJEXT) \
3817 + mpls_interface.$(OBJEXT) mpls_zebra.$(OBJEXT) \
3818 + mpls_main.$(OBJEXT) mpls_vty.$(OBJEXT) static.$(OBJEXT) \
3819 + static_vty.$(OBJEXT) ldp.$(OBJEXT) ldp_interface.$(OBJEXT) \
3820 + ldp_vty.$(OBJEXT) ldp_addr.$(OBJEXT) ldp_adj.$(OBJEXT) \
3821 + ldp_attr.$(OBJEXT) ldp_buf.$(OBJEXT) ldp_cfg.$(OBJEXT) \
3822 + ldp_entity.$(OBJEXT) ldp_fec.$(OBJEXT) ldp_global.$(OBJEXT) \
3823 + ldp_hello.$(OBJEXT) ldp_hop.$(OBJEXT) ldp_hop_list.$(OBJEXT) \
3824 + ldp_if.$(OBJEXT) ldp_inet_addr.$(OBJEXT) ldp_init.$(OBJEXT) \
3825 + ldp_inlabel.$(OBJEXT) ldp_keepalive.$(OBJEXT) \
3826 + ldp_label_abort.$(OBJEXT) ldp_label_mapping.$(OBJEXT) \
3827 + ldp_label_rel_with.$(OBJEXT) ldp_label_request.$(OBJEXT) \
3828 + ldp_mesg.$(OBJEXT) ldp_nortel.$(OBJEXT) ldp_notif.$(OBJEXT) \
3829 + ldp_outlabel.$(OBJEXT) ldp_pdu_setup.$(OBJEXT) \
3830 + ldp_peer.$(OBJEXT) ldp_resource.$(OBJEXT) ldp_session.$(OBJEXT) \
3831 + ldp_state_funcs.$(OBJEXT) ldp_state_machine.$(OBJEXT) \
3832 + ldp_tunnel.$(OBJEXT) lsr_cfg.$(OBJEXT) lsr_global.$(OBJEXT) \
3833 + lsr_if.$(OBJEXT) lsr_insegment.$(OBJEXT) \
3834 + lsr_labelmanager.$(OBJEXT) lsr_outsegment.$(OBJEXT) \
3835 + lsr_xconnect.$(OBJEXT) lsr_ftn.$(OBJEXT)
3836 +mplsd_OBJECTS = $(am_mplsd_OBJECTS)
3837 +mplsd_DEPENDENCIES = ../lib/libzebra.a
3838 +mplsd_LDFLAGS =
3839 +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
3840 +CPPFLAGS = @CPPFLAGS@
3841 +LDFLAGS = @LDFLAGS@
3842 +LIBS = @LIBS@
3843 +depcomp = $(SHELL) $(top_srcdir)/depcomp
3844 +am__depfiles_maybe = depfiles
3845 +@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/impl_fib.Po \
3846 +@AMDEP_TRUE@ ./$(DEPDIR)/impl_ifmgr.Po ./$(DEPDIR)/impl_lock.Po \
3847 +@AMDEP_TRUE@ ./$(DEPDIR)/impl_mm.Po ./$(DEPDIR)/impl_mpls.Po \
3848 +@AMDEP_TRUE@ ./$(DEPDIR)/impl_policy.Po \
3849 +@AMDEP_TRUE@ ./$(DEPDIR)/impl_socket.Po \
3850 +@AMDEP_TRUE@ ./$(DEPDIR)/impl_timer.Po ./$(DEPDIR)/impl_tree.Po \
3851 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp.Po ./$(DEPDIR)/ldp_addr.Po \
3852 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_adj.Po ./$(DEPDIR)/ldp_attr.Po \
3853 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_buf.Po ./$(DEPDIR)/ldp_cfg.Po \
3854 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_entity.Po ./$(DEPDIR)/ldp_fec.Po \
3855 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_global.Po ./$(DEPDIR)/ldp_hello.Po \
3856 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_hop.Po ./$(DEPDIR)/ldp_hop_list.Po \
3857 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_if.Po ./$(DEPDIR)/ldp_inet_addr.Po \
3858 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_init.Po ./$(DEPDIR)/ldp_inlabel.Po \
3859 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_interface.Po \
3860 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_keepalive.Po \
3861 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_label_abort.Po \
3862 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_label_mapping.Po \
3863 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_label_rel_with.Po \
3864 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_label_request.Po \
3865 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_mesg.Po ./$(DEPDIR)/ldp_nortel.Po \
3866 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_notif.Po \
3867 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_outlabel.Po \
3868 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_pdu_setup.Po \
3869 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_peer.Po ./$(DEPDIR)/ldp_resource.Po \
3870 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_session.Po \
3871 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_state_funcs.Po \
3872 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_state_machine.Po \
3873 +@AMDEP_TRUE@ ./$(DEPDIR)/ldp_tunnel.Po ./$(DEPDIR)/ldp_vty.Po \
3874 +@AMDEP_TRUE@ ./$(DEPDIR)/lsr_cfg.Po ./$(DEPDIR)/lsr_ftn.Po \
3875 +@AMDEP_TRUE@ ./$(DEPDIR)/lsr_global.Po ./$(DEPDIR)/lsr_if.Po \
3876 +@AMDEP_TRUE@ ./$(DEPDIR)/lsr_insegment.Po \
3877 +@AMDEP_TRUE@ ./$(DEPDIR)/lsr_labelmanager.Po \
3878 +@AMDEP_TRUE@ ./$(DEPDIR)/lsr_outsegment.Po \
3879 +@AMDEP_TRUE@ ./$(DEPDIR)/lsr_xconnect.Po ./$(DEPDIR)/mpls.Po \
3880 +@AMDEP_TRUE@ ./$(DEPDIR)/mpls_interface.Po \
3881 +@AMDEP_TRUE@ ./$(DEPDIR)/mpls_main.Po ./$(DEPDIR)/mpls_vty.Po \
3882 +@AMDEP_TRUE@ ./$(DEPDIR)/mpls_zebra.Po ./$(DEPDIR)/static.Po \
3883 +@AMDEP_TRUE@ ./$(DEPDIR)/static_vty.Po
3884 +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
3885 + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
3886 +CCLD = $(CC)
3887 +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
3888 +CFLAGS = @CFLAGS@
3889 +DIST_SOURCES = $(mplsd_SOURCES)
3890 +DATA = $(sysconf_DATA)
3892 +HEADERS = $(noinst_HEADERS)
3894 +DIST_COMMON = $(noinst_HEADERS) Makefile.am Makefile.in
3895 +SOURCES = $(mplsd_SOURCES)
3897 +all: all-am
3899 +.SUFFIXES:
3900 +.SUFFIXES: .c .o .obj
3901 +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
3902 + cd $(top_srcdir) && \
3903 + $(AUTOMAKE) --foreign mplsd/Makefile
3904 +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
3905 + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
3906 +sbinPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
3907 +install-sbinPROGRAMS: $(sbin_PROGRAMS)
3908 + @$(NORMAL_INSTALL)
3909 + $(mkinstalldirs) $(DESTDIR)$(sbindir)
3910 + @list='$(sbin_PROGRAMS)'; for p in $$list; do \
3911 + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
3912 + if test -f $$p \
3913 + ; then \
3914 + p1=`echo "$$p1" | sed -e 's,^.*/,,'`; \
3915 + f=`echo $$p1|sed '$(transform);s/$$/$(EXEEXT)/'`; \
3916 + echo " $(INSTALL_PROGRAM_ENV) $(sbinPROGRAMS_INSTALL) $$p $(DESTDIR)$(sbindir)/$$f"; \
3917 + $(INSTALL_PROGRAM_ENV) $(sbinPROGRAMS_INSTALL) $$p $(DESTDIR)$(sbindir)/$$f; \
3918 + else :; fi; \
3919 + done
3921 +uninstall-sbinPROGRAMS:
3922 + @$(NORMAL_UNINSTALL)
3923 + @list='$(sbin_PROGRAMS)'; for p in $$list; do \
3924 + f=`echo $$p|sed 's/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
3925 + f=`echo "$$f" | sed -e 's,^.*/,,'`; \
3926 + echo " rm -f $(DESTDIR)$(sbindir)/$$f"; \
3927 + rm -f $(DESTDIR)$(sbindir)/$$f; \
3928 + done
3930 +clean-sbinPROGRAMS:
3931 + -test -z "$(sbin_PROGRAMS)" || rm -f $(sbin_PROGRAMS)
3932 +mplsd$(EXEEXT): $(mplsd_OBJECTS) $(mplsd_DEPENDENCIES)
3933 + @rm -f mplsd$(EXEEXT)
3934 + $(LINK) $(mplsd_LDFLAGS) $(mplsd_OBJECTS) $(mplsd_LDADD) $(LIBS)
3936 +mostlyclean-compile:
3937 + -rm -f *.$(OBJEXT) core *.core
3939 +distclean-compile:
3940 + -rm -f *.tab.c
3942 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_fib.Po@am__quote@
3943 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_ifmgr.Po@am__quote@
3944 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_lock.Po@am__quote@
3945 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_mm.Po@am__quote@
3946 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_mpls.Po@am__quote@
3947 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_policy.Po@am__quote@
3948 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_socket.Po@am__quote@
3949 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_timer.Po@am__quote@
3950 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/impl_tree.Po@am__quote@
3951 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp.Po@am__quote@
3952 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_addr.Po@am__quote@
3953 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_adj.Po@am__quote@
3954 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_attr.Po@am__quote@
3955 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_buf.Po@am__quote@
3956 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_cfg.Po@am__quote@
3957 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_entity.Po@am__quote@
3958 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_fec.Po@am__quote@
3959 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_global.Po@am__quote@
3960 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_hello.Po@am__quote@
3961 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_hop.Po@am__quote@
3962 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_hop_list.Po@am__quote@
3963 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_if.Po@am__quote@
3964 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_inet_addr.Po@am__quote@
3965 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_init.Po@am__quote@
3966 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_inlabel.Po@am__quote@
3967 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_interface.Po@am__quote@
3968 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_keepalive.Po@am__quote@
3969 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_label_abort.Po@am__quote@
3970 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_label_mapping.Po@am__quote@
3971 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_label_rel_with.Po@am__quote@
3972 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_label_request.Po@am__quote@
3973 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_mesg.Po@am__quote@
3974 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_nortel.Po@am__quote@
3975 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_notif.Po@am__quote@
3976 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_outlabel.Po@am__quote@
3977 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_pdu_setup.Po@am__quote@
3978 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_peer.Po@am__quote@
3979 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_resource.Po@am__quote@
3980 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_session.Po@am__quote@
3981 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_state_funcs.Po@am__quote@
3982 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_state_machine.Po@am__quote@
3983 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_tunnel.Po@am__quote@
3984 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldp_vty.Po@am__quote@
3985 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsr_cfg.Po@am__quote@
3986 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsr_ftn.Po@am__quote@
3987 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsr_global.Po@am__quote@
3988 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsr_if.Po@am__quote@
3989 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsr_insegment.Po@am__quote@
3990 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsr_labelmanager.Po@am__quote@
3991 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsr_outsegment.Po@am__quote@
3992 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lsr_xconnect.Po@am__quote@
3993 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mpls.Po@am__quote@
3994 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mpls_interface.Po@am__quote@
3995 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mpls_main.Po@am__quote@
3996 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mpls_vty.Po@am__quote@
3997 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mpls_zebra.Po@am__quote@
3998 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/static.Po@am__quote@
3999 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/static_vty.Po@am__quote@
4001 +distclean-depend:
4002 + -rm -rf ./$(DEPDIR)
4004 +.c.o:
4005 +@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
4006 +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
4007 +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
4008 + $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
4010 +.c.obj:
4011 +@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
4012 +@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
4013 +@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
4014 + $(COMPILE) -c `cygpath -w $<`
4015 +CCDEPMODE = @CCDEPMODE@
4016 +uninstall-info-am:
4017 +sysconfDATA_INSTALL = $(INSTALL_DATA)
4019 +uninstall-sysconfDATA:
4020 + @$(NORMAL_UNINSTALL)
4021 + @list='$(sysconf_DATA)'; for p in $$list; do \
4022 + f="`echo $$p | sed -e 's|^.*/||'`"; \
4023 + echo " rm -f $(DESTDIR)$(sysconfdir)/$$f"; \
4024 + rm -f $(DESTDIR)$(sysconfdir)/$$f; \
4025 + done
4027 +ETAGS = etags
4028 +ETAGSFLAGS =
4030 +tags: TAGS
4032 +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
4033 + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
4034 + unique=`for i in $$list; do \
4035 + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
4036 + done | \
4037 + $(AWK) ' { files[$$0] = 1; } \
4038 + END { for (i in files) print i; }'`; \
4039 + mkid -fID $$unique
4041 +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
4042 + $(TAGS_FILES) $(LISP)
4043 + tags=; \
4044 + here=`pwd`; \
4045 + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
4046 + unique=`for i in $$list; do \
4047 + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
4048 + done | \
4049 + $(AWK) ' { files[$$0] = 1; } \
4050 + END { for (i in files) print i; }'`; \
4051 + test -z "$(ETAGS_ARGS)$$tags$$unique" \
4052 + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
4053 + $$tags $$unique
4055 +GTAGS:
4056 + here=`$(am__cd) $(top_builddir) && pwd` \
4057 + && cd $(top_srcdir) \
4058 + && gtags -i $(GTAGS_ARGS) $$here
4060 +distclean-tags:
4061 + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
4062 +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
4064 +top_distdir = ..
4065 +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
4067 +distdir: $(DISTFILES)
4068 + @list='$(DISTFILES)'; for file in $$list; do \
4069 + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
4070 + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
4071 + if test "$$dir" != "$$file" && test "$$dir" != "."; then \
4072 + dir="/$$dir"; \
4073 + $(mkinstalldirs) "$(distdir)$$dir"; \
4074 + else \
4075 + dir=''; \
4076 + fi; \
4077 + if test -d $$d/$$file; then \
4078 + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
4079 + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
4080 + fi; \
4081 + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
4082 + else \
4083 + test -f $(distdir)/$$file \
4084 + || cp -p $$d/$$file $(distdir)/$$file \
4085 + || exit 1; \
4086 + fi; \
4087 + done
4088 +check-am: all-am
4089 +check: check-am
4090 +all-am: Makefile $(PROGRAMS) $(DATA) $(HEADERS)
4092 +installdirs:
4093 + $(mkinstalldirs) $(DESTDIR)$(sbindir) $(DESTDIR)$(sysconfdir)
4095 +install: install-am
4096 +install-exec: install-exec-am
4097 +install-data: install-data-am
4098 +uninstall: uninstall-am
4100 +install-am: all-am
4101 + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
4103 +installcheck: installcheck-am
4104 +install-strip:
4105 + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
4106 + INSTALL_STRIP_FLAG=-s \
4107 + `test -z '$(STRIP)' || \
4108 + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
4109 +mostlyclean-generic:
4111 +clean-generic:
4113 +distclean-generic:
4114 + -rm -f Makefile $(CONFIG_CLEAN_FILES)
4116 +maintainer-clean-generic:
4117 + @echo "This command is intended for maintainers to use"
4118 + @echo "it deletes files that may require special tools to rebuild."
4119 +clean: clean-am
4121 +clean-am: clean-generic clean-sbinPROGRAMS mostlyclean-am
4123 +distclean: distclean-am
4125 +distclean-am: clean-am distclean-compile distclean-depend \
4126 + distclean-generic distclean-tags
4128 +dvi: dvi-am
4130 +dvi-am:
4132 +info: info-am
4134 +info-am:
4136 +install-data-am:
4138 +install-exec-am: install-sbinPROGRAMS install-sysconfDATA
4140 +install-info: install-info-am
4142 +install-man:
4144 +installcheck-am:
4146 +maintainer-clean: maintainer-clean-am
4148 +maintainer-clean-am: distclean-am maintainer-clean-generic
4150 +mostlyclean: mostlyclean-am
4152 +mostlyclean-am: mostlyclean-compile mostlyclean-generic
4154 +uninstall-am: uninstall-info-am uninstall-sbinPROGRAMS \
4155 + uninstall-sysconfDATA
4157 +.PHONY: GTAGS all all-am check check-am clean clean-generic \
4158 + clean-sbinPROGRAMS distclean distclean-compile distclean-depend \
4159 + distclean-generic distclean-tags distdir dvi dvi-am info \
4160 + info-am install install-am install-data install-data-am \
4161 + install-exec install-exec-am install-info install-info-am \
4162 + install-man install-sbinPROGRAMS install-strip \
4163 + install-sysconfDATA installcheck installcheck-am installdirs \
4164 + maintainer-clean maintainer-clean-generic mostlyclean \
4165 + mostlyclean-compile mostlyclean-generic tags uninstall \
4166 + uninstall-am uninstall-info-am uninstall-sbinPROGRAMS \
4167 + uninstall-sysconfDATA
4170 +install-sysconfDATA: $(sysconf_DATA)
4171 + @$(NORMAL_INSTALL)
4172 + $(mkinstalldirs) $(DESTDIR)$(sysconfdir)
4173 + @list='$(sysconf_DATA)'; for p in $$list; do \
4174 + if test -f $(srcdir)/$$p; then \
4175 + echo " $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p"; \
4176 + $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p; \
4177 + else if test -f $$p; then \
4178 + echo " $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p"; \
4179 + $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p; \
4180 + fi; fi; \
4181 + done
4182 +# Tell versions [3.59,3.63) of GNU make to not export all variables.
4183 +# Otherwise a system limit (for SysV at least) may be exceeded.
4184 +.NOEXPORT:
4185 diff -uNr --exclude=CVS zebra/mplsd/create-links zebra-ldp/mplsd/create-links
4186 --- zebra/mplsd/create-links Wed Dec 31 19:00:00 1969
4187 +++ zebra-ldp/mplsd/create-links Thu Nov 21 21:11:56 2002
4188 @@ -0,0 +1,102 @@
4189 +#!/bin/sh
4191 +SRC=/home/jleu/ldp-portable-fix/
4193 +ln -s $SRC/ldp/ldp_addr.c
4194 +ln -s $SRC/ldp/ldp_addr.h
4195 +ln -s $SRC/ldp/ldp_adj.c
4196 +ln -s $SRC/ldp/ldp_adj.h
4197 +ln -s $SRC/ldp/ldp_attr.c
4198 +ln -s $SRC/ldp/ldp_attr.h
4199 +ln -s $SRC/ldp/ldp_buf.c
4200 +ln -s $SRC/ldp/ldp_buf.h
4201 +ln -s $SRC/ldp/ldp_cfg.c
4202 +ln -s $SRC/ldp/ldp_cfg.h
4203 +ln -s $SRC/ldp/ldp_defaults.h
4204 +ln -s $SRC/ldp/ldp_entity.c
4205 +ln -s $SRC/ldp/ldp_entity.h
4206 +ln -s $SRC/ldp/ldp_fec.c
4207 +ln -s $SRC/ldp/ldp_fec.h
4208 +ln -s $SRC/ldp/ldp_global.c
4209 +ln -s $SRC/ldp/ldp_global.h
4210 +ln -s $SRC/ldp/ldp_hello.c
4211 +ln -s $SRC/ldp/ldp_hello.h
4212 +ln -s $SRC/ldp/ldp_hop.c
4213 +ln -s $SRC/ldp/ldp_hop.h
4214 +ln -s $SRC/ldp/ldp_hop_list.c
4215 +ln -s $SRC/ldp/ldp_hop_list.h
4216 +ln -s $SRC/ldp/ldp_if.c
4217 +ln -s $SRC/ldp/ldp_if.h
4218 +ln -s $SRC/ldp/ldp_inet_addr.c
4219 +ln -s $SRC/ldp/ldp_inet_addr.h
4220 +ln -s $SRC/ldp/ldp_init.c
4221 +ln -s $SRC/ldp/ldp_init.h
4222 +ln -s $SRC/ldp/ldp_inlabel.c
4223 +ln -s $SRC/ldp/ldp_inlabel.h
4224 +ln -s $SRC/ldp/ldp_keepalive.c
4225 +ln -s $SRC/ldp/ldp_keepalive.h
4226 +ln -s $SRC/ldp/ldp_label_abort.c
4227 +ln -s $SRC/ldp/ldp_label_abort.h
4228 +ln -s $SRC/ldp/ldp_label_mapping.c
4229 +ln -s $SRC/ldp/ldp_label_mapping.h
4230 +ln -s $SRC/ldp/ldp_label_rel_with.c
4231 +ln -s $SRC/ldp/ldp_label_rel_with.h
4232 +ln -s $SRC/ldp/ldp_label_request.c
4233 +ln -s $SRC/ldp/ldp_label_request.h
4234 +ln -s $SRC/ldp/ldp_mesg.c
4235 +ln -s $SRC/ldp/ldp_mesg.h
4236 +ln -s $SRC/ldp/ldp_nortel.c
4237 +ln -s $SRC/ldp/ldp_nortel.h
4238 +ln -s $SRC/ldp/ldp_notif.c
4239 +ln -s $SRC/ldp/ldp_notif.h
4240 +ln -s $SRC/ldp/ldp_outlabel.c
4241 +ln -s $SRC/ldp/ldp_outlabel.h
4242 +ln -s $SRC/ldp/ldp_pdu.h
4243 +ln -s $SRC/ldp/ldp_pdu_setup.c
4244 +ln -s $SRC/ldp/ldp_pdu_setup.h
4245 +ln -s $SRC/ldp/ldp_peer.c
4246 +ln -s $SRC/ldp/ldp_peer.h
4247 +ln -s $SRC/ldp/ldp_resource.c
4248 +ln -s $SRC/ldp/ldp_resource.h
4249 +ln -s $SRC/ldp/ldp_session.c
4250 +ln -s $SRC/ldp/ldp_session.h
4251 +ln -s $SRC/ldp/ldp_state_funcs.c
4252 +ln -s $SRC/ldp/ldp_state_machine.c
4253 +ln -s $SRC/ldp/ldp_state_machine.h
4254 +ln -s $SRC/ldp/ldp_struct.h
4255 +ln -s $SRC/ldp/ldp_tunnel.c
4256 +ln -s $SRC/ldp/ldp_tunnel.h
4258 +ln -s $SRC/lsr/lsr_cfg.c
4259 +ln -s $SRC/lsr/lsr_cfg.h
4260 +ln -s $SRC/lsr/lsr_defaults.h
4261 +ln -s $SRC/lsr/lsr_global.c
4262 +ln -s $SRC/lsr/lsr_global.h
4263 +ln -s $SRC/lsr/lsr_if.c
4264 +ln -s $SRC/lsr/lsr_if.h
4265 +ln -s $SRC/lsr/lsr_insegment.c
4266 +ln -s $SRC/lsr/lsr_insegment.h
4267 +ln -s $SRC/lsr/lsr_labelmanager.c
4268 +ln -s $SRC/lsr/lsr_labelmanager.h
4269 +ln -s $SRC/lsr/lsr_outsegment.c
4270 +ln -s $SRC/lsr/lsr_outsegment.h
4271 +ln -s $SRC/lsr/lsr_struct.h
4272 +ln -s $SRC/lsr/lsr_xconnect.c
4273 +ln -s $SRC/lsr/lsr_xconnect.h
4274 +ln -s $SRC/lsr/lsr_ftn.c
4275 +ln -s $SRC/lsr/lsr_ftn.h
4277 +ln -s $SRC/common/mpls_struct.h
4278 +ln -s $SRC/common/mpls_assert.h
4279 +ln -s $SRC/common/mpls_fib_impl.h
4280 +ln -s $SRC/common/mpls_ifmgr_impl.h
4281 +ln -s $SRC/common/mpls_mm_impl.h
4282 +ln -s $SRC/common/mpls_mpls_impl.h
4283 +ln -s $SRC/common/mpls_policy_impl.h
4284 +ln -s $SRC/common/mpls_refcnt.h
4285 +ln -s $SRC/common/mpls_socket_impl.h
4286 +ln -s $SRC/common/mpls_timer_impl.h
4287 +ln -s $SRC/common/mpls_trace_impl.h
4288 +ln -s $SRC/common/mpls_tree_impl.h
4289 +ln -s $SRC/common/mpls_list.h
4290 +ln -s $SRC/common/mpls_lock_impl.h
4291 diff -uNr --exclude=CVS zebra/mplsd/delete-links zebra-ldp/mplsd/delete-links
4292 --- zebra/mplsd/delete-links Wed Dec 31 19:00:00 1969
4293 +++ zebra-ldp/mplsd/delete-links Mon Nov 4 21:01:54 2002
4294 @@ -0,0 +1,100 @@
4295 +#!/bin/sh
4297 +rm ldp_addr.c
4298 +rm ldp_addr.h
4299 +rm ldp_adj.c
4300 +rm ldp_adj.h
4301 +rm ldp_attr.c
4302 +rm ldp_attr.h
4303 +rm ldp_buf.c
4304 +rm ldp_buf.h
4305 +rm ldp_cfg.c
4306 +rm ldp_cfg.h
4307 +rm ldp_defaults.h
4308 +rm ldp_entity.c
4309 +rm ldp_entity.h
4310 +rm ldp_fec.c
4311 +rm ldp_fec.h
4312 +rm ldp_global.c
4313 +rm ldp_global.h
4314 +rm ldp_hello.c
4315 +rm ldp_hello.h
4316 +rm ldp_hop.c
4317 +rm ldp_hop.h
4318 +rm ldp_hop_list.c
4319 +rm ldp_hop_list.h
4320 +rm ldp_if.c
4321 +rm ldp_if.h
4322 +rm ldp_inet_addr.c
4323 +rm ldp_inet_addr.h
4324 +rm ldp_init.c
4325 +rm ldp_init.h
4326 +rm ldp_inlabel.c
4327 +rm ldp_inlabel.h
4328 +rm ldp_keepalive.c
4329 +rm ldp_keepalive.h
4330 +rm ldp_label_abort.c
4331 +rm ldp_label_abort.h
4332 +rm ldp_label_mapping.c
4333 +rm ldp_label_mapping.h
4334 +rm ldp_label_rel_with.c
4335 +rm ldp_label_rel_with.h
4336 +rm ldp_label_request.c
4337 +rm ldp_label_request.h
4338 +rm ldp_mesg.c
4339 +rm ldp_mesg.h
4340 +rm ldp_nortel.c
4341 +rm ldp_nortel.h
4342 +rm ldp_notif.c
4343 +rm ldp_notif.h
4344 +rm ldp_outlabel.c
4345 +rm ldp_outlabel.h
4346 +rm ldp_pdu.h
4347 +rm ldp_pdu_setup.c
4348 +rm ldp_pdu_setup.h
4349 +rm ldp_peer.c
4350 +rm ldp_peer.h
4351 +rm ldp_resource.c
4352 +rm ldp_resource.h
4353 +rm ldp_session.c
4354 +rm ldp_session.h
4355 +rm ldp_state_funcs.c
4356 +rm ldp_state_machine.c
4357 +rm ldp_state_machine.h
4358 +rm ldp_struct.h
4359 +rm ldp_tunnel.c
4360 +rm ldp_tunnel.h
4362 +rm lsr_cfg.c
4363 +rm lsr_cfg.h
4364 +rm lsr_defaults.h
4365 +rm lsr_global.c
4366 +rm lsr_global.h
4367 +rm lsr_if.c
4368 +rm lsr_if.h
4369 +rm lsr_insegment.c
4370 +rm lsr_insegment.h
4371 +rm lsr_labelmanager.c
4372 +rm lsr_labelmanager.h
4373 +rm lsr_outsegment.c
4374 +rm lsr_outsegment.h
4375 +rm lsr_struct.h
4376 +rm lsr_xconnect.c
4377 +rm lsr_xconnect.h
4378 +rm lsr_ftn.c
4379 +rm lsr_ftn.h
4381 +rm mpls_struct.h
4382 +rm mpls_assert.h
4383 +rm mpls_fib_impl.h
4384 +rm mpls_ifmgr_impl.h
4385 +rm mpls_mm_impl.h
4386 +rm mpls_mpls_impl.h
4387 +rm mpls_policy_impl.h
4388 +rm mpls_refcnt.h
4389 +rm mpls_socket_impl.h
4390 +rm mpls_timer_impl.h
4391 +rm mpls_trace_impl.h
4392 +rm mpls_tree_impl.h
4393 +rm mpls_list.h
4394 +rm mpls_lock_impl.h
4395 diff -uNr --exclude=CVS zebra/mplsd/impl_fib.c zebra-ldp/mplsd/impl_fib.c
4396 --- zebra/mplsd/impl_fib.c Wed Dec 31 19:00:00 1969
4397 +++ zebra-ldp/mplsd/impl_fib.c Sun Nov 24 22:35:39 2002
4398 @@ -0,0 +1,241 @@
4399 +#include <zebra.h>
4400 +#include "rib.h"
4401 +#include "if.h"
4403 +#include "mpls.h"
4405 +#include "ldp.h"
4406 +#include "ldp_struct.h"
4408 +static ldp_fib_callback fib_callback = NULL;
4410 +void mpls_fib_close(mpls_fib_handle handle)
4414 +void mpls_fib_update_close(mpls_fib_handle handle)
4418 +mpls_bool mpls_fib_handle_verify(mpls_fib_handle handle)
4420 + return MPLS_BOOL_TRUE;
4423 +mpls_fib_handle mpls_fib_open(const mpls_instance_handle handle,
4424 + const mpls_cfg_handle cfg, ldp_fib_callback callback)
4426 + struct mpls *mpls = mpls_get();
4427 + fib_callback = callback;
4428 + return mpls->rib;
4431 +void mpls_fec2zebra_prefix(mpls_fec *lp, struct prefix *p)
4433 + switch(lp->type) {
4434 + case MPLS_FEC_PREFIX:
4435 + p->prefixlen = lp->u.prefix.length;
4436 + p->u.prefix4.s_addr = htonl(lp->u.prefix.network.u.ipv4);
4437 + break;
4438 + case MPLS_FEC_HOST:
4439 + p->prefixlen = 32;
4440 + p->u.prefix4.s_addr = htonl(lp->u.host.u.ipv4);
4441 + break;
4442 + default:
4446 +void zebra_prefix2mpls_fec(struct prefix *p, struct nexthop *newhop, mpls_fec *lp)
4448 + lp->u.prefix.length = p->prefixlen;
4449 + lp->type = MPLS_FEC_PREFIX;
4450 + lp->u.prefix.network.type = MPLS_FAMILY_IPV4;
4451 + lp->u.prefix.network.u.ipv4 = ntohl(p->u.prefix4.s_addr);
4453 + switch(newhop->type) {
4454 + case NEXTHOP_TYPE_IPV4:
4455 + lp->nh.type = MPLS_NH_IP;
4456 + lp->nh.u.ip.type = MPLS_FAMILY_IPV4;
4457 + lp->nh.u.ip.u.ipv4 = ntohl(newhop->gate.ipv4.s_addr);
4458 + break;
4459 + case NEXTHOP_TYPE_IFINDEX:
4460 + lp->nh.type = MPLS_NH_IF;
4461 + lp->nh.u.if_handle = if_lookup_by_index(newhop->ifindex);
4462 + lp->nh.u.ip.u.ipv4 = ntohl(newhop->gate.ipv4.s_addr);
4463 + break;
4464 + case NEXTHOP_TYPE_IPV4_IFINDEX:
4465 + lp->nh.type = MPLS_NH_IPIF;
4466 + lp->nh.u.ipif.if_handle = if_lookup_by_index(newhop->ifindex);
4467 + lp->nh.u.ipif.ip.type = MPLS_FAMILY_IPV4;
4468 + lp->nh.u.ipif.ip.u.ipv4 = ntohl(newhop->gate.ipv4.s_addr);
4469 + break;
4470 + default:
4471 + fprintf(stderr,"zebra_prefix2mpls_fec: unknown zebra next hop\n");
4475 +int nexthopCMPinet_addr(struct nexthop *newhop, mpls_nexthop *nh) {
4476 + unsigned int a;
4477 + unsigned int b;
4479 + switch(newhop->type) {
4480 + case NEXTHOP_TYPE_IPV4:
4481 + case NEXTHOP_TYPE_IPV4_IFINDEX:
4482 + a = newhop->gate.ipv4.s_addr;
4483 + break;
4484 + default:
4485 + a = 0;
4486 + break;
4489 + switch(nh->type) {
4490 + case MPLS_NH_IP:
4491 + b = htonl(nh->u.ip.u.ipv4);
4492 + break;
4493 + case MPLS_NH_IPIF:
4494 + b = htonl(nh->u.ipif.ip.u.ipv4);
4495 + break;
4496 + default:
4497 + b = 0;
4500 + if (a == b) {
4501 + return 1;
4503 + return 0;
4506 +int rib2fec(struct rib *match, struct prefix *p, mpls_fec *entry, int num) {
4507 + struct nexthop *newhop;
4508 + int count = 0;
4510 + for (newhop = match->nexthop; newhop && (count < num);
4511 + newhop = newhop->next, count++) {
4512 + if (match->type == ZEBRA_ROUTE_CONNECT) {
4513 + entry[count].attached = MPLS_BOOL_TRUE;
4515 + zebra_prefix2mpls_fec(p,newhop,&entry[count]);
4517 + return count;
4520 +int mpls_fib_get_route(mpls_fib_handle handle, const int num,
4521 + const mpls_fec * fec, mpls_fec * entry)
4523 + struct prefix p;
4524 + struct route_node *rn;
4525 + int count = 0;
4527 + mpls_fec2zebra_prefix((mpls_fec*)fec,&p);
4529 + if ((rn = route_node_lookup(handle->table,&p))) {
4530 + count = rib2fec((struct rib*)rn->info,&rn->p,entry,num);
4531 + route_unlock_node(rn);
4532 + return count;
4534 + return 0;
4537 +int mpls_fib_get_best_route(mpls_fib_handle handle, const int num,
4538 + const mpls_fec * dest, mpls_fec * entry)
4540 + struct route_node *rn;
4541 + struct prefix p;
4542 + int count = 0;
4543 + int len;
4545 + mpls_fec2zebra_prefix((mpls_fec*)dest,&p);
4547 + for (len = 32; len >= 0 ; len--) {
4548 + p.prefixlen = len;
4549 + if ((rn = route_node_lookup(handle->table,&p))) {
4550 + count = rib2fec((struct rib*)rn->info,&rn->p,entry,num);
4551 + route_unlock_node(rn);
4554 + return count;
4557 +mpls_return_enum mpls_fib_getfirst_route(mpls_fib_handle handle, mpls_fec * dest)
4559 + struct route_node *rn;
4561 + if ((rn = route_top(handle->table))) {
4562 + if (!rn->info) {
4563 + rn = route_next2(rn);
4566 + if (rn) {
4567 + rib2fec((struct rib*)rn->info,&rn->p,dest,1);
4568 + route_unlock_node(rn);
4569 + return MPLS_SUCCESS;
4572 + return MPLS_FAILURE;
4575 +mpls_return_enum mpls_fib_getnext_route(mpls_fib_handle handle, mpls_fec * dest)
4577 + struct route_node *rn_in;
4578 + struct rib *match;
4579 + struct nexthop *newhop;
4580 + struct prefix p;
4581 + int next = 0;
4583 + mpls_fec2zebra_prefix(dest,&p);
4585 + if (!(rn_in = route_node_lookup2(handle->table,&p))) {
4586 + return MPLS_FAILURE;
4589 + match = rn_in->info;
4590 + for (newhop = match->nexthop; newhop; newhop = newhop->next) {
4591 + if (next) {
4592 + if (match->type == ZEBRA_ROUTE_CONNECT) {
4593 + dest->attached = MPLS_BOOL_TRUE;
4595 + zebra_prefix2mpls_fec(&p, newhop, dest);
4596 + route_unlock_node(rn_in);
4597 + return MPLS_SUCCESS;
4599 + if (nexthopCMPinet_addr(newhop,&dest->nh)) {
4600 + next = 1;
4604 + if ((rn_in = route_next2(rn_in))) {
4605 + rib2fec((struct rib*)rn_in->info,&rn_in->p,dest,1);
4606 + route_unlock_node(rn_in);
4607 + return MPLS_SUCCESS;
4610 + return MPLS_FAILURE;
4613 +void ldp_ipv4_add(struct mpls *mpls, int type, struct prefix_ipv4 *p,
4614 + struct nexthop *nexthop) {
4615 + mpls_fec dest;
4617 + if (mpls->ldp && fib_callback) {
4618 + memset(&dest,0,sizeof(dest));
4619 + if (type == ZEBRA_ROUTE_CONNECT) {
4620 + dest.attached = MPLS_BOOL_TRUE;
4622 + zebra_prefix2mpls_fec((struct prefix*)p, nexthop, &dest);
4623 + fib_callback(mpls->ldp->h, MPLS_UPDATE_ADD, &dest);
4627 +void ldp_ipv4_delete(struct mpls *mpls, int type, struct prefix_ipv4 *p,
4628 + struct nexthop *nexthop) {
4629 + mpls_fec dest;
4631 + if (mpls->ldp && fib_callback) {
4632 + memset(&dest,0,sizeof(dest));
4633 + if (type == ZEBRA_ROUTE_CONNECT) {
4634 + dest.attached = MPLS_BOOL_TRUE;
4636 + zebra_prefix2mpls_fec((struct prefix*)p, nexthop, &dest);
4637 + fib_callback(mpls->ldp->h, MPLS_UPDATE_DEL, &dest);
4640 diff -uNr --exclude=CVS zebra/mplsd/impl_fib.h zebra-ldp/mplsd/impl_fib.h
4641 --- zebra/mplsd/impl_fib.h Wed Dec 31 19:00:00 1969
4642 +++ zebra-ldp/mplsd/impl_fib.h Sun Nov 24 22:35:57 2002
4643 @@ -0,0 +1,17 @@
4644 +#ifndef LDP_IMPL_FIB_H
4645 +#define LDP_IMPL_FIB_H
4647 +#include <zebra.h>
4648 +#include "rib.h"
4650 +#include "ldp_struct.h"
4651 +#include "mpls.h"
4653 +extern void mpls_fec2zebra_prefix(mpls_fec *lp, struct prefix *p);
4654 +extern void zebra_prefix2mpls_fec(struct prefix *p, mpls_fec *lp);
4655 +void ldp_ipv4_add(struct mpls *mpls, int, struct prefix_ipv4 *p,
4656 + struct nexthop *nexthop);
4657 +void ldp_ipv4_delete(struct mpls *mpls, int, struct prefix_ipv4 *p,
4658 + struct nexthop *nexthop);
4660 +#endif
4661 diff -uNr --exclude=CVS zebra/mplsd/impl_ifmgr.c zebra-ldp/mplsd/impl_ifmgr.c
4662 --- zebra/mplsd/impl_ifmgr.c Wed Dec 31 19:00:00 1969
4663 +++ zebra-ldp/mplsd/impl_ifmgr.c Mon Nov 18 22:33:49 2002
4664 @@ -0,0 +1,187 @@
4665 +#include <zebra.h>
4666 +#include "if.h"
4668 +#include "ldp.h"
4669 +#include "ldp_struct.h"
4671 +#include "mpls.h"
4673 +static ldp_ifmgr_callback ifmgr_callback;
4674 +static int opened = 0;
4676 +static unsigned int mask_array[33] = { 0x00000000,
4677 + 0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,
4678 + 0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,
4679 + 0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,
4680 + 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
4681 + 0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,
4682 + 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,
4683 + 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,
4684 + 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF };
4686 +mpls_bool mpls_ifmgr_handle_verify(mpls_ifmgr_handle handle)
4688 + return MPLS_BOOL_TRUE;
4691 +mpls_bool mpls_if_handle_verify(mpls_ifmgr_handle ifmgr_handle, mpls_if_handle iff)
4693 + if (iff) {
4694 + return MPLS_BOOL_TRUE;
4696 + return MPLS_BOOL_FALSE;
4699 +mpls_ifmgr_handle mpls_ifmgr_open(mpls_instance_handle handle,
4700 + mpls_cfg_handle cfg, ldp_ifmgr_callback callback)
4702 + if (callback) {
4703 + ifmgr_callback = callback;
4704 + opened = 1;
4706 + return 0;
4709 +void mpls_ifmgr_close(mpls_ifmgr_handle ifmgr_handle)
4711 + opened = 0;
4714 +mpls_if_handle mpls_ifmgr_open_if(mpls_ifmgr_handle ifmgr_handle, const char *name)
4716 + mpls_if_handle ifh;
4717 + char name2[IFNAMSIZ + 1];
4718 + strncpy(name2,name,IFNAMSIZ);
4720 + ifh = if_lookup_by_name(name2);
4722 + return ifh;
4725 +mpls_return_enum mpls_ifmgr_get_address(mpls_ifmgr_handle ifmgr_handle,
4726 + mpls_if_handle if_handle, mpls_inet_addr * addr, mpls_inet_addr * mask,
4727 + uint32_t * flags)
4729 + struct connected *ifc;
4730 + listnode node;
4731 + int loop = 0;
4733 + if (flags) {
4734 + *flags = if_handle->flags;
4737 + for (node = listhead(if_handle->connected); node; nextnode(node)) {
4738 + ifc = getdata(node);
4739 + if (ifc->address->u.prefix4.s_addr == htonl(INADDR_LOOPBACK)) {
4740 + loop = 1;
4741 + continue;
4743 + if (!loop && (ifc->flags & ZEBRA_IFA_SECONDARY)) {
4744 + continue;
4746 + if (addr) {
4747 + addr->type = MPLS_FAMILY_IPV4;
4748 + addr->u.ipv4 = ntohl(ifc->address->u.prefix4.s_addr);
4750 + if (mask) {
4751 + mask->type = MPLS_FAMILY_IPV4;
4752 + mask->u.ipv4 = mask_array[ifc->address->prefixlen];
4754 + return MPLS_SUCCESS;
4756 + return MPLS_FAILURE;
4759 +mpls_return_enum mpls_ifmgr_get_mtu(mpls_ifmgr_handle ifmgr_handle,
4760 + mpls_if_handle if_handle, int *mtu)
4762 + *mtu = if_handle->mtu;
4763 + return MPLS_SUCCESS;
4766 +void mpls_ifmgr_close_if(mpls_ifmgr_handle ifmgr_handle, mpls_if_handle if_handle)
4770 +mpls_return_enum mpls_ifmgr_getnext_address(mpls_ifmgr_handle ifmgr_handle,
4771 + mpls_if_handle *handle, mpls_inet_addr *addr)
4773 + struct connected *ifc;
4774 + listnode node;
4775 + int next = 0;
4777 + while ((*handle)) {
4778 + for (node = listhead((*handle)->connected); node; nextnode(node)) {
4779 + ifc = getdata(node);
4780 + if (ifc->address->u.prefix4.s_addr != htonl(INADDR_LOOPBACK)) {
4781 + if (next) {
4782 + addr->type = MPLS_FAMILY_IPV4;
4783 + addr->u.ipv4 = ntohl(ifc->address->u.prefix4.s_addr);
4784 + return MPLS_SUCCESS;
4785 + } else if (addr->u.ipv4 == ntohl(ifc->address->u.prefix4.s_addr)) {
4786 + next = 1;
4790 + (*handle) = if_getnext(*handle);
4791 + next = 1;
4793 + return MPLS_END_OF_LIST;
4796 +mpls_return_enum mpls_ifmgr_getfirst_address(mpls_ifmgr_handle ifmgr_handle,
4797 + mpls_if_handle *handle, mpls_inet_addr *addr)
4799 + struct connected *ifc;
4800 + listnode node;
4802 + (*handle) = if_getfirst();
4803 + while ((*handle)) {
4804 + for (node = listhead((*handle)->connected); node; nextnode(node)) {
4805 + ifc = getdata(node);
4806 + if (ifc->address->u.prefix4.s_addr != htonl(INADDR_LOOPBACK)) {
4807 + addr->type = MPLS_FAMILY_IPV4;
4808 + addr->u.ipv4 = ntohl(ifc->address->u.prefix4.s_addr);
4809 + return MPLS_SUCCESS;
4812 + (*handle) = if_getnext(*handle);
4814 + return MPLS_END_OF_LIST;
4817 +int ldp_address_add_callback(struct mpls *mpls, struct connected *c) {
4818 + mpls_inet_addr addr;
4820 + if (opened) {
4821 + addr.type = MPLS_FAMILY_IPV4;
4822 + addr.u.ipv4 = ntohl(c->address->u.prefix4.s_addr);
4824 + ifmgr_callback(mpls->ldp->h,MPLS_UPDATE_ADD,&addr);
4827 + return 0;
4830 +int ldp_address_delete_callback(struct mpls *mpls, struct connected *c) {
4831 + mpls_inet_addr addr;
4833 + if (opened) {
4834 + addr.type = MPLS_FAMILY_IPV4;
4835 + addr.u.ipv4 = ntohl(c->address->u.prefix4.s_addr);
4837 + ifmgr_callback(mpls->ldp->h,MPLS_UPDATE_DEL,&addr);
4839 + return 0;
4842 +int mpls_if_handle_compare(mpls_ifmgr_handle ifmgr_handle, mpls_if_handle a,
4843 + mpls_if_handle b)
4845 + if (a == b) {
4846 + return 0;
4847 + } else if (a < b) {
4848 + return -1;
4850 + return 1;
4852 diff -uNr --exclude=CVS zebra/mplsd/impl_ifmgr.h zebra-ldp/mplsd/impl_ifmgr.h
4853 --- zebra/mplsd/impl_ifmgr.h Wed Dec 31 19:00:00 1969
4854 +++ zebra-ldp/mplsd/impl_ifmgr.h Sun Oct 13 19:27:32 2002
4855 @@ -0,0 +1,10 @@
4856 +#ifndef LDP_IMPL_IFMGR_H
4857 +#define LDP_IMPL_IFMGR_H
4859 +#include <zebra.h>
4860 +#include "ldp_struct.h"
4862 +int ldp_address_add_callback(struct mpls *mpls, struct connected *c);
4863 +int ldp_address_delete_callback(struct mpls *mpls, struct connected *c);
4865 +#endif
4866 diff -uNr --exclude=CVS zebra/mplsd/impl_lock.c zebra-ldp/mplsd/impl_lock.c
4867 --- zebra/mplsd/impl_lock.c Wed Dec 31 19:00:00 1969
4868 +++ zebra-ldp/mplsd/impl_lock.c Wed Oct 30 17:50:44 2002
4869 @@ -0,0 +1,35 @@
4870 +#include "ldp_struct.h"
4871 +#include "mpls_assert.h"
4872 +#include "mpls_mm_impl.h"
4874 +mpls_bool mpls_lock_handle_verify(mpls_lock_handle handle)
4876 + return MPLS_BOOL_TRUE;
4879 +mpls_lock_handle mpls_lock_create(mpls_lock_key_type key)
4881 + int *i = mpls_malloc(sizeof(int));
4883 + *i = 0;
4884 + return i;
4887 +void mpls_lock_get(mpls_lock_handle handle)
4889 + MPLS_ASSERT(*handle == 0);
4890 + // fprintf(stderr,"lock get\n");
4891 + (*handle)++;
4894 +void mpls_lock_release(mpls_lock_handle handle)
4896 + MPLS_ASSERT(*handle == 1);
4897 + // fprintf(stderr,"lock release\n");
4898 + (*handle)--;
4901 +void mpls_lock_delete(mpls_lock_handle handle)
4903 + mpls_free(handle);
4905 diff -uNr --exclude=CVS zebra/mplsd/impl_mm.c zebra-ldp/mplsd/impl_mm.c
4906 --- zebra/mplsd/impl_mm.c Wed Dec 31 19:00:00 1969
4907 +++ zebra-ldp/mplsd/impl_mm.c Wed Oct 23 21:40:25 2002
4908 @@ -0,0 +1,27 @@
4909 +#include "ldp_struct.h"
4910 +#include "mpls_mm_impl.h"
4911 +#include <stdio.h>
4912 +#include <stdlib.h>
4914 +#include "memory.h"
4916 +static int _mm_count = 0;
4918 +void *mpls_malloc(mpls_size_type size)
4920 + _mm_count++;
4921 +// fprintf(stderr,"malloc: %d\n",_mm_count);
4922 + return XMALLOC(MTYPE_MPLS_LDP, size);
4925 +void mpls_free(void *mem)
4927 +// fprintf(stderr,"free: %d\n",_mm_count);
4928 + _mm_count--;
4929 + XFREE(MTYPE_MPLS_LDP,mem);
4932 +void mpls_mm_results()
4934 + fprintf(stderr, "LDP MM RESULTS: %d\n", _mm_count);
4936 diff -uNr --exclude=CVS zebra/mplsd/impl_mpls.c zebra-ldp/mplsd/impl_mpls.c
4937 --- zebra/mplsd/impl_mpls.c Wed Dec 31 19:00:00 1969
4938 +++ zebra-ldp/mplsd/impl_mpls.c Wed Nov 20 23:35:05 2002
4939 @@ -0,0 +1,276 @@
4940 +#include <mplsd/ldp.h>
4941 +#include <zebra.h>
4943 +#include "stream.h"
4944 +#include "prefix.h"
4945 +#include "log.h"
4946 +#include "zclient.h"
4947 +#include "if.h"
4949 +#include "ldp_struct.h"
4950 +#include "ldp_entity.h"
4951 +#include "mpls_mpls_impl.h"
4952 +#include "mpls_socket_impl.h"
4953 +#include <linux/mpls.h>
4955 +#include "mpls_interface.h"
4956 +#include "impl_fib.h"
4958 +static int label = 10000;
4959 +extern struct zclient *zclient;
4960 +static int mplsd_socket;
4962 +#define MPLS_LINUX 1
4964 +int mplsd_ioctl (u_long request, caddr_t buffer) {
4965 + int ret = 0;
4966 + int err = 0;
4968 + if (!mplsd_socket) {
4969 + mplsd_socket = socket (AF_INET, SOCK_DGRAM, 0);
4970 + if (mplsd_socket < 0) {
4971 + perror ("socket");
4972 + exit (1);
4976 + ret = ioctl (mplsd_socket, request, buffer);
4977 + if (ret < 0) {
4978 + err = errno;
4981 + if (ret < 0) {
4982 + errno = err;
4983 + return ret;
4985 + return 0;
4988 +int do_mpls_labelspace(struct mpls_interface *mi) {
4989 + struct mpls_labelspace_req mls;
4991 + if (!mi || !mi->ifp->ifindex) {
4992 + return 1;
4995 + memset(&mls,0,sizeof(struct mpls_labelspace_req));
4996 + mls.mls_ifindex = mi->ifp->ifindex;
4997 + mls.mls_labelspace = mi->labelspace;
4998 + if (mplsd_ioctl(SIOCSLABELSPACEMPLS,(caddr_t)&mls)) {
4999 + return 1;
5002 + return 0;
5005 +mpls_bool mpls_mpls_handle_verify(mpls_mpls_handle handle)
5007 + if (handle < 0) {
5008 + return MPLS_BOOL_FALSE;
5010 + return MPLS_BOOL_TRUE;
5013 +mpls_mpls_handle mpls_mpls_open(mpls_instance_handle user_data)
5015 + return socket(AF_INET, SOCK_STREAM, 0);
5018 +void mpls_mpls_close(mpls_mpls_handle handle)
5020 + close(handle);
5023 +mpls_return_enum mpls_mpls_outsegment_add(mpls_mpls_handle handle, mpls_outsegment * o)
5025 +#ifdef MPLS_LINUX
5026 + struct mpls_out_label_req oreq;
5027 + struct mpls_instruction_req mir;
5028 + struct sockaddr_in sin;
5029 + int result;
5031 + memset(&oreq,0,sizeof(oreq));
5032 + memset(&mir,0,sizeof(mir));
5033 + oreq.mol_label.ml_type = MPLS_LABEL_KEY;
5034 + result = ioctl(handle,SIOCMPLSNHLFEADD,&oreq);
5035 + o->handle = oreq.mol_label.u.ml_key;
5037 + mir.mir_direction = MPLS_OUT;
5038 + mir.mir_label.ml_type = MPLS_LABEL_KEY;
5039 + mir.mir_label.u.ml_key = o->handle;
5040 + mir.mir_instruction[0].mir_opcode = MPLS_OP_PUSH;
5041 + mir.mir_instruction[0].mir_data.push.ml_type = MPLS_LABEL_GEN;
5042 + mir.mir_instruction[0].mir_data.push.u.ml_gen = o->label.u.gen;
5044 + mir.mir_instruction[1].mir_opcode = MPLS_OP_SET;
5045 + mir.mir_instruction[1].mir_data.set.mni_if = o->nexthop.u.ipif.if_handle->ifindex;
5046 + sin.sin_addr.s_addr = htonl(o->nexthop.u.ipif.ip.u.ipv4);
5047 + sin.sin_family = AF_INET;
5048 + memcpy(&mir.mir_instruction[1].mir_data.set.mni_addr,
5049 + &sin,sizeof(struct sockaddr));
5051 + mir.mir_instruction_length = 2;
5052 + result = ioctl(handle,SIOCSMPLSOUTINSTR,&mir);
5054 +#if 0
5055 + struct ifreq ifr;
5056 + sprintf(ifr.ifr_name,"mpls%d",o->handle);
5057 + memcpy(&ifr.ifr_data,&oreq.mol_label,sizeof(struct mpls_label));
5058 + result = ioctl(handle,SIOCMPLSTUNNELADD,&ifr);
5059 + ifr.ifr_flags = IFF_UP | IFF_POINTOPOINT | IFF_NOARP | IFF_RUNNING;
5060 + result = ioctl(handle,SIOCSIFFLAGS,&ifr);
5061 +#endif
5062 +#endif
5063 + return MPLS_SUCCESS;
5066 +void mpls_mpls_outsegment_del(mpls_mpls_handle handle, mpls_outsegment * o)
5068 +#ifdef MPLS_LINUX
5069 + struct mpls_out_label_req oreq;
5070 + int result;
5072 +#if 0
5073 + struct ifreq ifr;
5074 + sprintf(ifr.ifr_name,"mpls%d",o->handle);
5075 + result = ioctl(handle,SIOCMPLSTUNNELDEL,&ifr);
5076 +#endif
5078 + oreq.mol_label.ml_type = MPLS_LABEL_KEY;
5079 + oreq.mol_label.u.ml_key = o->handle;
5080 + result = ioctl(handle,SIOCMPLSNHLFEDEL,&oreq);
5082 +#endif
5085 +mpls_return_enum mpls_mpls_insegment_add(mpls_mpls_handle handle,
5086 + mpls_insegment * i)
5088 +#ifdef MPLS_LINUX
5089 + struct mpls_in_label_req ireq;
5090 + int result;
5091 +#endif
5093 + if (i->label.type == MPLS_LABEL_TYPE_NONE) {
5094 + i->label.type = MPLS_LABEL_TYPE_GENERIC;
5095 + i->label.u.gen = label++;
5098 +#ifdef MPLS_LINUX
5099 + ireq.mil_label.ml_type = MPLS_LABEL_GEN;
5100 + ireq.mil_label.u.ml_gen = i->label.u.gen;
5101 + ireq.mil_label.ml_index = i->labelspace;
5102 + i->handle = 0;
5104 + result = ioctl(handle,SIOCMPLSILMADD,&ireq);
5106 +#endif
5107 + return MPLS_SUCCESS;
5110 +void mpls_mpls_insegment_del(mpls_mpls_handle handle, mpls_insegment * i)
5112 +#ifdef MPLS_LINUX
5113 + struct mpls_in_label_req ireq;
5114 + int result;
5116 + ireq.mil_label.ml_type = MPLS_LABEL_GEN;
5117 + ireq.mil_label.u.ml_gen = i->label.u.gen;
5118 + ireq.mil_label.ml_index = i->labelspace;
5120 + result = ioctl(handle,SIOCMPLSILMDEL,&ireq);
5121 +#endif
5124 +mpls_return_enum mpls_mpls_xconnect_add(mpls_mpls_handle handle, mpls_insegment * i, mpls_outsegment * o)
5126 +#ifdef MPLS_LINUX
5127 + struct mpls_xconnect_req xreq;
5128 + int result;
5130 + fprintf(stderr, "mpls_mpls_xconnect_add: %d <-> %d\n", i->label.u.gen,
5131 + o->label.u.gen);
5133 + xreq.mx_in.ml_type = MPLS_LABEL_GEN;
5134 + xreq.mx_in.u.ml_gen = i->label.u.gen;
5135 + xreq.mx_in.ml_index = i->labelspace;
5137 + xreq.mx_out.ml_type = MPLS_LABEL_KEY;
5138 + xreq.mx_out.u.ml_key = o->handle;
5140 + result = ioctl(handle,SIOCMPLSXCADD,&xreq);
5142 +#endif
5144 + return MPLS_SUCCESS;
5147 +void mpls_mpls_xconnect_del(mpls_mpls_handle handle, mpls_insegment * i,
5148 + mpls_outsegment * o)
5150 +#ifdef MPLS_LINUX
5151 + struct mpls_xconnect_req xreq;
5152 + int result;
5154 + fprintf(stderr, "ldp_mpls_in2out_del: %d <-> %d\n", i->label.u.gen,
5155 + o->label.u.gen);
5157 + xreq.mx_in.ml_type = MPLS_LABEL_GEN;
5158 + xreq.mx_in.u.ml_gen = i->label.u.gen;
5159 + xreq.mx_in.ml_index = i->labelspace;
5161 + xreq.mx_out.ml_type = MPLS_LABEL_KEY;
5162 + xreq.mx_out.u.ml_key = o->handle;
5164 + result = ioctl(handle,SIOCMPLSXCDEL,&xreq);
5166 +#endif
5169 +mpls_return_enum mpls_mpls_fec2out_add(mpls_mpls_handle handle, mpls_fec * f,
5170 + mpls_outsegment * o)
5172 + struct prefix p;
5173 + struct in_addr addr;
5174 + unsigned int ifindex;
5175 + unsigned int mplsindex;
5176 + int retval;
5178 + mplsindex = o->handle;
5179 + ifindex = o->nexthop.u.ipif.if_handle->ifindex;
5180 + addr.s_addr = htonl(o->nexthop.u.ipif.ip.u.ipv4);
5182 + mpls_fec2zebra_prefix(f,&p);
5183 + retval = zapi_ipv4_set_mplsindex(zclient,(struct prefix_ipv4*)&p,
5184 + &addr,ifindex,mplsindex);
5186 + return MPLS_SUCCESS;
5189 +void mpls_mpls_fec2out_del(mpls_mpls_handle handle, mpls_fec * f,
5190 + mpls_outsegment * o)
5192 + struct prefix p;
5193 + struct in_addr addr;
5194 + unsigned int ifindex;
5195 + unsigned int mplsindex;
5196 + int retval;
5198 + mplsindex = o->handle;
5199 + ifindex = o->nexthop.u.ipif.if_handle->ifindex;
5200 + addr.s_addr = htonl(o->nexthop.u.ipif.ip.u.ipv4);
5202 + mpls_fec2zebra_prefix(f,&p);
5203 + retval = zapi_ipv4_set_mplsindex(zclient,(struct prefix_ipv4*)&p,
5204 + &addr,ifindex,0);
5207 +mpls_return_enum mpls_mpls_get_label_space_range(mpls_mpls_handle handle,
5208 + mpls_range * r)
5210 + r->type = MPLS_LABEL_RANGE_GENERIC;
5211 + r->min.gen = 16;
5212 + r->max.gen = 0xFFFFF;
5214 + return MPLS_SUCCESS;
5216 diff -uNr --exclude=CVS zebra/mplsd/impl_mpls.h zebra-ldp/mplsd/impl_mpls.h
5217 --- zebra/mplsd/impl_mpls.h Wed Dec 31 19:00:00 1969
5218 +++ zebra-ldp/mplsd/impl_mpls.h Thu Oct 10 21:53:01 2002
5219 @@ -0,0 +1,6 @@
5220 +#ifndef IMPL_MPLS_H
5221 +#define IMPL_MPLS_H
5223 +int do_mpls_labelspace(struct mpls_interface *mi);
5225 +#endif
5226 diff -uNr --exclude=CVS zebra/mplsd/impl_policy.c zebra-ldp/mplsd/impl_policy.c
5227 --- zebra/mplsd/impl_policy.c Wed Dec 31 19:00:00 1969
5228 +++ zebra-ldp/mplsd/impl_policy.c Wed Nov 20 18:33:01 2002
5229 @@ -0,0 +1,89 @@
5230 +#include <zebra.h>
5232 +#include "rib.h"
5234 +#include "ldp_struct.h"
5235 +#include "mpls_interface.h"
5236 +#include "impl_fib.h"
5238 +mpls_bool mpls_policy_import_check(mpls_instance_handle handle, mpls_fec * f,
5239 + ldp_addr * nh)
5241 + return MPLS_BOOL_TRUE;
5244 +mpls_bool mpls_policy_ingress_check(mpls_instance_handle handle, mpls_fec * f, ldp_addr * nh)
5246 + return MPLS_BOOL_TRUE;
5249 +mpls_bool mpls_policy_egress_check(mpls_instance_handle handle, mpls_fec * fec)
5251 + struct ldp *ldp = handle;
5252 + int result = MPLS_BOOL_FALSE;
5254 + switch(ldp->egress) {
5255 + case LDP_EGRESS_ALL:
5256 + result = MPLS_BOOL_TRUE;
5257 + break;
5258 + case LDP_EGRESS_LSRID:
5259 + case LDP_EGRESS_CONNECTED:
5261 + struct route_node *rn;
5262 + struct prefix p;
5264 + mpls_fec2zebra_prefix(fec,&p);
5265 + if ((rn = route_node_lookup(rib_table_ipv4->table,&p))) {
5266 + if (ldp->egress == LDP_EGRESS_LSRID) {
5267 + if (prefix_match(&rn->p, &ldp->mpls->router_id)) {
5268 + result = MPLS_BOOL_TRUE;
5270 + } else {
5271 + struct rib *rib = rn->info;
5272 + if (rib->type == ZEBRA_ROUTE_CONNECT) {
5273 + result = MPLS_BOOL_TRUE;
5276 + route_unlock_node(rn);
5278 + break;
5280 + default:
5281 + break;
5283 + return result;
5286 +mpls_bool mpls_policy_export_check(mpls_instance_handle handle, mpls_fec * f, ldp_addr * nh)
5288 + return MPLS_BOOL_TRUE;
5291 +mpls_bool mpls_policy_address_export_check(mpls_instance_handle handle,
5292 + mpls_inet_addr *addr) {
5293 + struct ldp *ldp = handle;
5294 + mpls_bool flag = MPLS_BOOL_FALSE;
5295 + struct interface *ifp;
5296 + struct in_addr in;
5298 + in.s_addr = htonl(addr->u.ipv4);
5301 + switch (ldp->address) {
5302 + case LDP_ADDRESS_LDP:
5303 + if ((ifp = if_lookup_exact_address(in)) &&
5304 + ((struct mpls_interface*)(ifp->info))->ldp) {
5305 + flag = MPLS_BOOL_TRUE;
5307 + /* fall through */
5308 + case LDP_ADDRESS_LSRID:
5309 + if (in.s_addr == ldp->mpls->router_id.u.prefix4.s_addr) {
5310 + flag = MPLS_BOOL_TRUE;
5312 + break;
5313 + case LDP_ADDRESS_ALL:
5314 + flag = MPLS_BOOL_TRUE;
5315 + break;
5317 + return flag;
5319 diff -uNr --exclude=CVS zebra/mplsd/impl_socket.c zebra-ldp/mplsd/impl_socket.c
5320 --- zebra/mplsd/impl_socket.c Wed Dec 31 19:00:00 1969
5321 +++ zebra-ldp/mplsd/impl_socket.c Wed Oct 30 18:53:40 2002
5322 @@ -0,0 +1,427 @@
5323 +#include <zebra.h>
5324 +#include "thread.h"
5325 +#include "sockopt.h"
5327 +#include "mpls.h"
5329 +#include "ldp_struct.h"
5330 +#include "ldp_state_machine.h"
5331 +#include "mpls_mm_impl.h"
5333 +extern struct thread_master *master;
5335 +struct mpls_socket {
5336 + int fd;
5337 + int type;
5338 + struct thread *read;
5339 + struct thread *write;
5340 + void *extra;
5343 +void _sockaddr2mpls_dest(const struct sockaddr *addr, mpls_dest * dest)
5345 + dest->addr.type = MPLS_FAMILY_IPV4;
5346 + switch (dest->addr.type) {
5347 + case MPLS_FAMILY_IPV4:
5348 + dest->port = ntohs(((struct sockaddr_in *)addr)->sin_port);
5349 + dest->addr.u.ipv4 = ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr);
5350 + break;
5351 + default:
5352 + assert(0);
5356 +void _mpls_dest2sockaddr(const mpls_dest * dest, struct sockaddr *addr)
5358 + memset(addr, 0, sizeof(struct sockaddr));
5360 + switch (dest->addr.type) {
5361 + case MPLS_FAMILY_IPV4:
5363 + addr->sa_family = AF_INET;
5364 + ((struct sockaddr_in *)addr)->sin_port = htons(dest->port);
5365 + ((struct sockaddr_in *)addr)->sin_addr.s_addr = htonl(dest->addr.u.ipv4);
5366 + break;
5368 + default:
5370 + assert(0);
5375 +int mplsd_read(struct thread *thread) {
5376 + int retval;
5377 + struct mpls *mpls = mpls_get();
5378 + mpls_socket_handle socket = THREAD_ARG(thread);
5380 + socket->read = thread_add_read(master,mplsd_read,socket,socket->fd);
5382 + switch (socket->type) {
5383 + case MPLS_SOCKET_TCP_DATA:
5385 + retval = ldp_event(mpls->ldp->h, socket, NULL, 0, NULL,
5386 + socket->extra, LDP_EVENT_TCP_DATA);
5387 + break;
5389 + case MPLS_SOCKET_TCP_LISTEN:
5391 + retval = ldp_event(mpls->ldp->h, socket, NULL, 0, NULL,
5392 + socket->extra, LDP_EVENT_TCP_LISTEN);
5393 + break;
5395 + case MPLS_SOCKET_UDP_DATA:
5397 + retval = ldp_event(mpls->ldp->h, socket, NULL, 0, NULL,
5398 + socket->extra, LDP_EVENT_UDP_DATA);
5399 + break;
5401 + default:
5403 + assert(0);
5406 + return 0;
5409 +int mplsd_write(struct thread *thread) {
5410 + struct mpls *mpls = mpls_get();
5411 + int retval;
5412 + mpls_socket_handle socket = THREAD_ARG(thread);
5413 + socket->write = thread_add_write(master,mplsd_write,socket,socket->fd);
5414 + if (socket->type != MPLS_SOCKET_TCP_CONNECT) {
5415 + assert(0);
5417 + retval = ldp_event(mpls->ldp->h, socket, NULL, 0, NULL, socket->extra,
5418 + LDP_EVENT_TCP_CONNECT);
5420 + return 0;
5423 +mpls_bool mpls_socket_mgr_handle_verify(mpls_socket_mgr_handle handle)
5425 + return MPLS_BOOL_TRUE;
5428 +mpls_bool mpls_socket_handle_verify(mpls_socket_mgr_handle handle, mpls_socket_handle socket)
5430 + if (socket) {
5431 + return MPLS_BOOL_TRUE;
5433 + return MPLS_BOOL_FALSE;
5436 +mpls_socket_mgr_handle mpls_socket_mgr_open(mpls_instance_handle user_data)
5438 + return 0;
5441 +void mpls_socket_mgr_close(mpls_socket_mgr_handle handle)
5445 +void mpls_socket_close(mpls_socket_mgr_handle handle, mpls_socket_handle socket)
5447 + if (socket) {
5448 + close(socket->fd);
5449 + mpls_free(socket);
5453 +mpls_socket_handle mpls_socket_create_tcp(mpls_socket_mgr_handle handle)
5455 + struct mpls_socket *sock;
5456 + sock = mpls_malloc(sizeof(struct mpls_socket));
5457 + sock->fd = socket(AF_INET, SOCK_STREAM, 0);
5458 + return sock;
5461 +mpls_socket_handle mpls_socket_create_udp(mpls_socket_mgr_handle handle)
5463 + struct mpls_socket *sock;
5464 + u_char one = 1;
5466 + sock = mpls_malloc(sizeof(struct mpls_socket));
5467 + sock->fd = socket(AF_INET, SOCK_DGRAM, 0);
5468 + if (setsockopt(sock->fd,IPPROTO_IP,IP_PKTINFO,&one,sizeof(one)) < 0) {
5469 + perror("PKTINFO");
5470 + mpls_free(sock);
5471 + return NULL;
5473 + return sock;
5476 +mpls_socket_handle mpls_socket_tcp_accept(mpls_socket_mgr_handle handle,
5477 + mpls_socket_handle socket, mpls_dest * from)
5479 + struct mpls_socket *sock = mpls_malloc(sizeof(struct mpls_socket));
5480 + struct sockaddr addr;
5481 + int size = sizeof(addr);
5483 + if ((sock->fd = accept(socket->fd,&addr,&size)) < 0) {
5484 + return NULL;
5487 + _sockaddr2mpls_dest(&addr, from);
5488 + return sock;
5491 +mpls_return_enum mpls_socket_bind(mpls_socket_mgr_handle handle,
5492 + mpls_socket_handle socket, const mpls_dest * local)
5494 + struct sockaddr addr;
5496 + _mpls_dest2sockaddr(local, &addr);
5498 + if (bind(socket->fd, &addr, sizeof(struct sockaddr_in)) < 0) {
5499 + return MPLS_FAILURE;
5502 + return MPLS_SUCCESS;
5505 +mpls_return_enum mpls_socket_tcp_listen(mpls_socket_mgr_handle handle,
5506 + mpls_socket_handle socket, int depth)
5508 + if (listen(socket->fd, depth) < 0) {
5509 + return MPLS_FAILURE;
5511 + return MPLS_SUCCESS;
5514 +mpls_return_enum mpls_socket_tcp_connect(mpls_socket_mgr_handle handle,
5515 + mpls_socket_handle socket, const mpls_dest * to)
5517 + struct sockaddr addr, *iaddr = NULL;
5519 + if (to != NULL) {
5520 + _mpls_dest2sockaddr(to, &addr);
5521 + iaddr = &addr;
5522 + } else {
5523 + iaddr = NULL;
5526 + if (connect(socket->fd, iaddr, sizeof(struct sockaddr)) < 0) {
5527 + if (errno == EINPROGRESS) {
5528 + return MPLS_NON_BLOCKING;
5531 + if (errno == EALREADY) {
5532 + return MPLS_SUCCESS;
5534 + perror("connect");
5535 + return MPLS_FAILURE;
5537 + return MPLS_SUCCESS;
5540 +mpls_return_enum mpls_socket_connect_status(mpls_socket_mgr_handle handle,
5541 + mpls_socket_handle socket)
5543 + int size = sizeof(int);
5544 + int num = 1;
5546 + if (getsockopt(socket->fd, SOL_SOCKET, SO_ERROR, &num, &size) < 0) {
5547 + perror("getsockopt");
5549 + if (!num) {
5550 + return MPLS_SUCCESS;
5552 + return MPLS_FAILURE;
5555 +int mpls_socket_get_errno(const mpls_socket_mgr_handle handle,
5556 + mpls_socket_handle socket)
5558 + return errno;
5561 +mpls_return_enum mpls_socket_options(mpls_socket_mgr_handle handle,
5562 + mpls_socket_handle socket, uint32_t flag)
5564 + int one = 1;
5566 + if (flag & MPLS_SOCKOP_REUSE) {
5567 + if (setsockopt(socket->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one,
5568 + sizeof(one)) < 0) {
5569 + return MPLS_FAILURE;
5572 + if (flag & MPLS_SOCKOP_NONBLOCK) {
5573 + if (fcntl(socket->fd, F_SETFL, O_NONBLOCK) < 0) {
5574 + return MPLS_FAILURE;
5577 + return MPLS_SUCCESS;
5580 +mpls_return_enum mpls_socket_multicast_options(mpls_socket_mgr_handle handle,
5581 + mpls_socket_handle socket, int ttl, int loop)
5583 + int zero = loop;
5584 + int one = ttl;
5586 + if (setsockopt(socket->fd,IPPROTO_IP,IP_MULTICAST_TTL,&one,sizeof(one))<0) {
5587 + return MPLS_FAILURE;
5590 + if (setsockopt(socket->fd,IPPROTO_IP,IP_MULTICAST_LOOP,&zero,sizeof(zero))<0) {
5591 + return MPLS_FAILURE;
5594 + return MPLS_SUCCESS;
5597 +mpls_return_enum mpls_socket_multicast_if_tx(mpls_socket_mgr_handle handle,
5598 + mpls_socket_handle socket, const ldp_if * iff)
5600 + struct in_addr addr;
5601 + unsigned int ifindex = 0;
5602 + addr.s_addr = 0;
5604 + if (iff == NULL) {
5605 + addr.s_addr = ntohl(INADDR_ANY);
5606 + } else {
5607 + ifindex = iff->handle->ifindex;
5610 + if (setsockopt_multicast_ipv4(socket->fd,IP_MULTICAST_IF,addr,0,ifindex)<0) {
5611 + return MPLS_FAILURE;
5614 + return MPLS_SUCCESS;
5617 +mpls_return_enum mpls_socket_multicast_if_join(mpls_socket_mgr_handle handle,
5618 + mpls_socket_handle socket, const ldp_if * iff, const mpls_inet_addr * mult)
5620 + struct in_addr addr;
5621 + unsigned int ifindex = 0;
5622 + addr.s_addr = 0;
5624 + if (iff == NULL) {
5625 + addr.s_addr = ntohl(INADDR_ANY);
5626 + } else {
5627 + ifindex = iff->handle->ifindex;
5630 + if (setsockopt_multicast_ipv4(socket->fd,IP_ADD_MEMBERSHIP,addr,
5631 + htonl(mult->u.ipv4),ifindex)<0) {
5632 + return MPLS_FAILURE;
5635 + return MPLS_SUCCESS;
5638 +void mpls_socket_multicast_if_drop(mpls_socket_mgr_handle handle,
5639 + mpls_socket_handle socket, const ldp_if * iff, const mpls_inet_addr * mult)
5641 + struct in_addr addr;
5642 + unsigned int ifindex = 0;
5643 + addr.s_addr = 0;
5645 + if (iff == NULL) {
5646 + addr.s_addr = ntohl(INADDR_ANY);
5647 + } else {
5648 + ifindex = iff->handle->ifindex;
5651 + if (setsockopt_multicast_ipv4(socket->fd,IP_DROP_MEMBERSHIP,addr,
5652 + htonl(mult->u.ipv4),ifindex)<0) {
5653 + return;
5656 + return;
5659 +mpls_return_enum mpls_socket_readlist_add(mpls_socket_mgr_handle handle,
5660 + mpls_socket_handle socket, void *extra, mpls_socket_enum type)
5662 + socket->type = type;
5663 + socket->extra = extra;
5664 + socket->read = thread_add_read(master,mplsd_read,socket,socket->fd);
5665 + return MPLS_SUCCESS;
5668 +void mpls_socket_readlist_del(mpls_socket_mgr_handle handle,
5669 + mpls_socket_handle socket)
5671 + if (socket) {
5672 + thread_cancel(socket->read);
5673 + socket->read = NULL;
5677 +mpls_return_enum mpls_socket_writelist_add(mpls_socket_mgr_handle handle,
5678 + mpls_socket_handle socket, void *extra, mpls_socket_enum type)
5680 + socket->type = type;
5681 + socket->extra = extra;
5682 + socket->write = thread_add_write(master,mplsd_write,socket,socket->fd);
5683 + return MPLS_SUCCESS;
5686 +void mpls_socket_writelist_del(mpls_socket_mgr_handle handle,
5687 + mpls_socket_handle socket)
5689 + if (socket) {
5690 + thread_cancel(socket->write);
5691 + socket->write = NULL;
5695 +int mpls_socket_tcp_read(mpls_socket_mgr_handle handle, mpls_socket_handle socket,
5696 + uint8_t * buffer, int size)
5698 + return read(socket->fd,buffer,size);
5701 +int mpls_socket_tcp_write(mpls_socket_mgr_handle handle, mpls_socket_handle socket,
5702 + uint8_t * buffer, int size)
5704 + return write(socket->fd,buffer,size);
5707 +int mpls_socket_udp_sendto(mpls_socket_mgr_handle handle,
5708 + mpls_socket_handle socket, uint8_t * buffer, int size, const mpls_dest * to)
5710 + struct sockaddr addr;
5711 + int retval;
5713 + _mpls_dest2sockaddr(to, &addr);
5715 + retval = sendto(socket->fd,buffer,size,0,&addr,sizeof(struct sockaddr));
5717 + return retval;
5720 +int mpls_socket_udp_recvfrom(mpls_socket_mgr_handle handle,
5721 + mpls_socket_handle socket, uint8_t * buffer, int size, mpls_dest * from)
5723 + int ret;
5724 + unsigned int ifindex = 0;
5725 + struct iovec iov;
5726 + struct cmsghdr *cmsg;
5727 + struct in_pktinfo *pktinfo;
5728 + struct sockaddr addr;
5729 + char buff [sizeof (*cmsg) + sizeof (*pktinfo)];
5730 + struct msghdr msgh = {&addr, sizeof(struct sockaddr), &iov, 1, buff,
5731 + sizeof (*cmsg) + sizeof (*pktinfo), 0};
5733 + iov.iov_base = buffer;
5734 + iov.iov_len = size;
5735 + ret = recvmsg(socket->fd,&msgh,0);
5737 + cmsg = CMSG_FIRSTHDR(&msgh);
5739 + if (cmsg != NULL &&
5740 + cmsg->cmsg_level == IPPROTO_IP &&
5741 + cmsg->cmsg_type == IP_PKTINFO) {
5742 + pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg);
5743 + ifindex = pktinfo->ipi_ifindex;
5744 + from->if_handle = if_lookup_by_index(ifindex);
5745 + _sockaddr2mpls_dest((const struct sockaddr*)&addr, from);
5748 + return ret;
5750 diff -uNr --exclude=CVS zebra/mplsd/impl_timer.c zebra-ldp/mplsd/impl_timer.c
5751 --- zebra/mplsd/impl_timer.c Wed Dec 31 19:00:00 1969
5752 +++ zebra-ldp/mplsd/impl_timer.c Sun Nov 3 15:28:39 2002
5753 @@ -0,0 +1,107 @@
5754 +#include "ldp_struct.h"
5755 +#include "mpls_timer_impl.h"
5756 +#include "mpls_mm_impl.h"
5758 +#include "thread.h"
5760 +struct mpls_timer {
5761 + struct thread *timer;
5762 + mpls_time_unit_enum unit;
5763 + int duration;
5764 + int type;
5765 + void *extra;
5766 + mpls_cfg_handle g;
5767 + void (*callback) (mpls_timer_handle timer, void *extra, mpls_cfg_handle g);
5768 + int active;
5771 +extern struct thread_master *master;
5773 +int mpls_timer(struct thread* thread) {
5774 + mpls_timer_handle timer = THREAD_ARG(thread);
5776 + timer->active = 0;
5777 + if (timer->type == MPLS_TIMER_REOCCURRING) {
5778 + timer->timer = thread_add_timer(master,mpls_timer,timer,timer->duration);
5779 + timer->active = 1;
5781 + timer->callback(timer,timer->extra,timer->g);
5783 + return 0;
5786 +mpls_bool mpls_timer_mgr_handle_verify(mpls_timer_mgr_handle handle)
5788 + return MPLS_BOOL_TRUE;
5791 +mpls_bool
5792 +mpls_timer_handle_verify(mpls_timer_mgr_handle handle, mpls_timer_handle timer)
5794 + if (timer) {
5795 + return MPLS_BOOL_TRUE;
5797 + return MPLS_BOOL_FALSE;
5800 +mpls_timer_mgr_handle mpls_timer_open(mpls_instance_handle user_data)
5802 + return 0;
5805 +void mpls_timer_close(mpls_timer_mgr_handle handle)
5809 +mpls_timer_handle mpls_timer_create(mpls_timer_mgr_handle handle,
5810 + mpls_time_unit_enum unit, int duration, void *extra, mpls_cfg_handle g,
5811 + void (*callback) (mpls_timer_handle timer, void *extra, mpls_cfg_handle g))
5813 + struct mpls_timer *timer;
5814 + timer = mpls_malloc(sizeof(struct mpls_timer));
5815 + timer->unit = unit;
5816 + timer->duration = duration;
5817 + timer->extra = extra;
5818 + timer->g = g;
5819 + timer->callback = callback;
5820 + timer->active = 0;
5822 + return timer;
5825 +mpls_return_enum mpls_timer_modify(mpls_timer_mgr_handle handle,
5826 + mpls_timer_handle timer, int duration)
5828 + if (!timer) {
5829 + return MPLS_FAILURE;
5831 + timer->duration = duration;
5832 + return MPLS_SUCCESS;
5835 +void mpls_timer_delete(mpls_timer_mgr_handle handle, mpls_timer_handle timer)
5837 + if (timer) {
5838 + mpls_free(timer);
5842 +mpls_return_enum mpls_timer_start(mpls_timer_mgr_handle handle,
5843 + mpls_timer_handle timer, mpls_timer_type_enum type)
5845 + if (!timer) {
5846 + return MPLS_FAILURE;
5848 + timer->type = type;
5849 + timer->timer = thread_add_timer(master,mpls_timer,timer,timer->duration);
5850 + timer->active = 1;
5851 + return MPLS_SUCCESS;
5854 +void mpls_timer_stop(mpls_timer_mgr_handle handle, mpls_timer_handle timer)
5856 + if (timer && timer->active) {
5857 + thread_cancel(timer->timer);
5858 + timer->timer = NULL;
5861 diff -uNr --exclude=CVS zebra/mplsd/impl_tree.c zebra-ldp/mplsd/impl_tree.c
5862 --- zebra/mplsd/impl_tree.c Wed Dec 31 19:00:00 1969
5863 +++ zebra-ldp/mplsd/impl_tree.c Wed Oct 30 17:50:49 2002
5864 @@ -0,0 +1,166 @@
5865 +#include <zebra.h>
5866 +#include "table.h"
5868 +#include "ldp_struct.h"
5869 +#include "mpls_mm_impl.h"
5870 +#include "mpls_tree_impl.h"
5872 +mpls_bool mpls_tree_handle_verify(mpls_tree_handle handle)
5874 + if (handle) {
5875 + return MPLS_BOOL_TRUE;
5877 + return MPLS_BOOL_FALSE;
5880 +mpls_tree_handle mpls_tree_create(int depth)
5882 + return route_table_init();
5885 +mpls_return_enum mpls_tree_insert(mpls_tree_handle tree, uint32_t key, int length,
5886 + void *info)
5888 + struct route_node *node;
5889 + struct prefix p;
5891 + p.family = AF_INET;
5892 + p.prefixlen = length;
5893 + p.u.prefix4.s_addr = key;
5895 + if ((node = route_node_get(tree,&p))) {
5896 + /* result is that the node is 'held', it will be held */
5897 + /* until it is deleted from the tree */
5898 + node->info = info;
5899 + return MPLS_SUCCESS;
5901 + return MPLS_FAILURE;
5904 +mpls_return_enum mpls_tree_remove(mpls_tree_handle tree, uint32_t key, int length,
5905 + void **info)
5907 + struct route_node *node;
5908 + struct prefix p;
5910 + p.family = AF_INET;
5911 + p.prefixlen = length;
5912 + p.u.prefix4.s_addr = key;
5914 + if ((node = route_node_lookup(tree,&p))) {
5915 + *info = node->info;
5916 + node->info = NULL;
5917 + route_unlock_node(node);
5918 + route_unlock_node(node);
5919 + return MPLS_SUCCESS;
5921 + return MPLS_FAILURE;
5924 +mpls_return_enum mpls_tree_replace(mpls_tree_handle tree, uint32_t key, int length,
5925 + void *new, void **old)
5927 + struct route_node *node;
5928 + struct prefix p;
5930 + p.family = AF_INET;
5931 + p.prefixlen = length;
5932 + p.u.prefix4.s_addr = key;
5934 + if ((node = route_node_lookup(tree,&p))) {
5935 + *old = node->info;
5936 + node->info = new;
5937 + route_unlock_node(node);
5938 + return MPLS_SUCCESS;
5940 + return MPLS_FAILURE;
5943 +mpls_return_enum mpls_tree_get(mpls_tree_handle tree, uint32_t key, int length,
5944 + void **info)
5946 + struct route_node *node;
5947 + struct prefix p;
5949 + p.family = AF_INET;
5950 + p.prefixlen = length;
5951 + p.u.prefix4.s_addr = key;
5953 + if ((node = route_node_lookup(tree,&p))) {
5954 + *info = node->info;
5955 + route_unlock_node(node);
5956 + return MPLS_SUCCESS;
5958 + return MPLS_FAILURE;
5961 +mpls_return_enum mpls_tree_get_longest(mpls_tree_handle tree, uint32_t key,
5962 + void **info)
5964 + struct route_node *node;
5965 + struct prefix p;
5967 + p.family = AF_INET;
5968 + p.prefixlen = 0;
5969 + p.u.prefix4.s_addr = key;
5971 + if ((node = route_node_match(tree,&p))) {
5972 + *info = node->info;
5973 + route_unlock_node(node);
5974 + return MPLS_SUCCESS;
5976 + return MPLS_FAILURE;
5979 +void mpls_tree_dump(const mpls_tree_handle tree, ldp_tree_callback callback)
5983 +void mpls_tree_delete(mpls_tree_handle tree)
5985 + route_table_finish(tree);
5988 +mpls_return_enum mpls_tree_getfirst(mpls_tree_handle tree, uint32_t * key,
5989 + int *length, void **info)
5991 + struct route_node *node;
5992 + struct prefix p;
5994 + p.family = AF_INET;
5995 + p.prefixlen = 0;
5996 + p.u.prefix4.s_addr = 0;
5998 + if ((node = route_node_match(tree,&p))) {
5999 + *info = node->info;
6000 + *length = node->p.prefixlen;
6001 + *key = node->p.u.prefix4.s_addr;
6002 + route_unlock_node(node);
6003 + return MPLS_SUCCESS;
6005 + return MPLS_FAILURE;
6008 +mpls_return_enum mpls_tree_getnext(mpls_tree_handle tree, uint32_t * key,
6009 + int *length, void **info)
6011 + struct route_node *node;
6012 + struct prefix p;
6014 + p.family = AF_INET;
6015 + p.prefixlen = *length;
6016 + p.u.prefix4.s_addr = *key;
6018 + if (!(node = route_node_match(tree,&p))) {
6019 + return MPLS_FAILURE;
6022 + if ((node = route_next(node))) {
6023 + *info = node->info;
6024 + *length = node->p.prefixlen;
6025 + *key = node->p.u.prefix4.s_addr;
6026 + route_unlock_node(node);
6027 + return MPLS_SUCCESS;
6029 + return MPLS_FAILURE;
6031 diff -uNr --exclude=CVS zebra/mplsd/ldp.c zebra-ldp/mplsd/ldp.c
6032 --- zebra/mplsd/ldp.c Wed Dec 31 19:00:00 1969
6033 +++ zebra-ldp/mplsd/ldp.c Thu Nov 21 22:45:07 2002
6034 @@ -0,0 +1,129 @@
6035 +#include <zebra.h>
6037 +#include "memory.h"
6038 +#include "log.h"
6040 +#include "ldp.h"
6041 +#include "ldp_cfg.h"
6042 +#include "ldp_struct.h"
6043 +#include "ldp_interface.h"
6045 +#include "mpls.h"
6046 +#include "mpls_interface.h"
6048 +int ldp_shutdown(struct ldp *ldp) {
6049 + ldp_global g;
6051 + g.admin_state = MPLS_ADMIN_DISABLE;
6052 + return ldp_cfg_global_set(ldp->h,&g,LDP_GLOBAL_CFG_ADMIN_STATE);
6055 +int ldp_startup(struct ldp *ldp) {
6056 + ldp_global g;
6058 + g.admin_state = MPLS_ADMIN_ENABLE;
6059 + return ldp_cfg_global_set(ldp->h,&g,LDP_GLOBAL_CFG_ADMIN_STATE);
6062 +int ldp_admin_state_start(struct ldp *ldp) {
6063 + if (ldp->admin_up == MPLS_BOOL_TRUE) {
6064 + return ldp_shutdown(ldp);
6066 + return MPLS_SUCCESS;
6069 +int ldp_admin_state_finish(struct ldp *ldp) {
6070 + if (ldp->admin_up == MPLS_BOOL_TRUE) {
6071 + return ldp_startup(ldp);
6073 + return MPLS_SUCCESS;
6076 +int do_ldp_router_id_update(struct ldp *ldp, unsigned int router_id) {
6077 + ldp_global g;
6078 + g.lsr_identifier.type = MPLS_FAMILY_IPV4;
6079 + g.lsr_identifier.u.ipv4 = router_id;
6080 + return ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LSR_IDENTIFIER);
6083 +int ldp_router_id_update(struct ldp *ldp, struct prefix *router_id) {
6085 + zlog_info("router-id update %s", inet_ntoa(router_id->u.prefix4));
6087 + if (!ldp->lsr_id_is_static) {
6088 + ldp_admin_state_start(ldp);
6090 + do_ldp_router_id_update(ldp, ntohl(router_id->u.prefix4.s_addr));
6092 + ldp_admin_state_finish(ldp);
6094 + return 0;
6097 +static struct ldp *ldp_new(struct mpls *mpls) {
6098 + struct ldp *new = XMALLOC(MTYPE_MPLS_LDP, sizeof(struct ldp));
6099 + ldp_global g;
6101 + memset(new,0,sizeof(*new));
6103 + new->h = ldp_cfg_open(new);
6104 + new->admin_up = MPLS_BOOL_TRUE;
6105 + new->lsr_id_is_static = 0;
6106 + new->mpls = mpls;
6107 + new->egress = LDP_EGRESS_CONNECTED;
6108 + new->address = LDP_ADDRESS_ALL;
6110 + g.lsr_identifier.type = MPLS_FAMILY_IPV4;
6111 + g.lsr_identifier.u.ipv4 = ntohl(mpls->router_id.u.prefix4.s_addr);
6112 + g.admin_state = MPLS_ADMIN_ENABLE;
6113 +#if MPLS_USE_LSR
6114 + g.lsr_handle = mpls->h;
6115 +#endif
6116 + ldp_cfg_global_set(new->h,&g,
6117 + LDP_GLOBAL_CFG_LSR_IDENTIFIER|LDP_GLOBAL_CFG_LSR_HANDLE|
6118 + LDP_GLOBAL_CFG_ADMIN_STATE);
6120 + return new;
6123 +struct ldp *ldp_get() {
6124 + struct mpls_interface *mi;
6125 + struct interface *ifp;
6126 + listnode node;
6128 + struct mpls *mpls = mpls_get();
6129 + if (mpls->ldp) {
6130 + return mpls->ldp;
6133 + mpls->ldp = ldp_new(mpls);
6134 + for (node = listhead(mpls->iflist); node; nextnode(node)) {
6135 + ifp = getdata(node);
6136 + mi = (struct mpls_interface*)ifp->info;
6137 + if (mi->ldp && mi->ldp->create_on_hold == MPLS_BOOL_TRUE) {
6138 + ldp_interface_create(mi);
6142 + return mpls->ldp;
6145 +void ldp_finish(struct ldp *ldp) {
6146 + struct mpls *mpls = ldp->mpls;
6147 + struct interface *ifp;
6148 + struct mpls_interface *mi;
6149 + listnode node;
6151 + for (node = listhead(mpls->iflist); node; nextnode(node)) {
6152 + ifp = getdata(node);
6153 + mi = (struct mpls_interface*)ifp->info;
6154 + if (mi->ldp && mi->ldp->entity.index) {
6155 + ldp_interface_delete(mi);
6159 + ldp_admin_state_start(ldp);
6160 + ldp_cfg_close(ldp->h);
6161 + XFREE(MTYPE_MPLS_LDP,ldp);
6162 + mpls->ldp = NULL;
6164 diff -uNr --exclude=CVS zebra/mplsd/ldp.h zebra-ldp/mplsd/ldp.h
6165 --- zebra/mplsd/ldp.h Wed Dec 31 19:00:00 1969
6166 +++ zebra-ldp/mplsd/ldp.h Wed Nov 13 22:15:21 2002
6167 @@ -0,0 +1,41 @@
6168 +#ifndef LDP_H
6169 +#define LDP_H
6171 +#include <zebra.h>
6172 +#include "prefix.h"
6174 +#include "ldp_struct.h"
6176 +struct mpls;
6178 +typedef enum {
6179 + LDP_EGRESS_ALL,
6180 + LDP_EGRESS_LSRID,
6181 + LDP_EGRESS_CONNECTED
6182 +} ldp_egress_mode;
6184 +typedef enum {
6185 + LDP_ADDRESS_ALL,
6186 + LDP_ADDRESS_LSRID,
6187 + LDP_ADDRESS_LDP
6188 +} ldp_address_mode;
6190 +struct ldp {
6191 + struct mpls *mpls;
6192 + mpls_cfg_handle h;
6193 + mpls_bool admin_up;
6194 + mpls_bool lsr_id_is_static;
6195 + ldp_egress_mode egress;
6196 + ldp_address_mode address;
6199 +struct ldp *ldp_get();
6200 +void ldp_init();
6201 +int ldp_router_id_update(struct ldp *ldp, struct prefix *router_id);
6202 +int do_ldp_router_id_update(struct ldp *ldp, unsigned int router_id);
6203 +void ldp_finish(struct ldp *ldp);
6205 +int ldp_admin_state_start(struct ldp *ldp);
6206 +int ldp_admin_state_finish(struct ldp *ldp);
6208 +#endif
6209 diff -uNr --exclude=CVS zebra/mplsd/ldp_interface.c zebra-ldp/mplsd/ldp_interface.c
6210 --- zebra/mplsd/ldp_interface.c Wed Dec 31 19:00:00 1969
6211 +++ zebra-ldp/mplsd/ldp_interface.c Wed Oct 30 17:55:14 2002
6212 @@ -0,0 +1,120 @@
6213 +#include <zebra.h>
6214 +#include "memory.h"
6216 +#include "ldp.h"
6217 +#include "ldp_cfg.h"
6218 +#include "ldp_struct.h"
6220 +#include "mpls.h"
6221 +#include "mpls_interface.h"
6223 +struct ldp_interface *ldp_if_new(struct mpls_interface *mi) {
6224 + struct ldp_interface *li;
6226 +fprintf(stderr,"ldp_if_new:\n");
6228 + li = XMALLOC(MTYPE_MPLS_LDP, sizeof(struct ldp_interface));
6229 + memset(li, 0, sizeof(struct ldp_interface));
6230 + li->mi = mi;
6232 + li->admin_up = MPLS_BOOL_TRUE;
6233 + li->create_on_hold = MPLS_BOOL_FALSE;
6234 + ldp_entity_set_defaults(&li->entity);
6236 + return li;
6239 +void ldp_if_free(struct ldp_interface *li) {
6240 +fprintf(stderr,"ldp_if_free:\n");
6241 + XFREE(MTYPE_MPLS_LDP, li);
6244 +void ldp_interface_create(struct mpls_interface *mi) {
6245 + struct ldp *ldp = mi->mpls->ldp;
6247 + mi->ldp->create_on_hold = MPLS_BOOL_FALSE;
6249 + strncpy(mi->ldp->iff.name,mi->ifp->name,IFNAMSIZ);
6250 + mi->ldp->iff.label_space = mi->labelspace;
6252 + ldp_cfg_if_set(ldp->h, &mi->ldp->iff, LDP_CFG_ADD | LDP_IF_CFG_LABEL_SPACE);
6254 + mi->ldp->entity.sub_index = mi->ldp->iff.index;
6255 + mi->ldp->entity.entity_type = LDP_DIRECT;
6256 + mi->ldp->entity.admin_state = MPLS_OPER_DOWN;
6258 + ldp_cfg_entity_set(ldp->h, &mi->ldp->entity,
6259 + LDP_CFG_ADD | LDP_ENTITY_CFG_SUB_INDEX | LDP_ENTITY_CFG_ADMIN_STATE);
6261 + ldp_cfg_entity_get(ldp->h, &mi->ldp->entity, 0xFFFFFFFF);
6262 + ldp_cfg_if_get(ldp->h, &mi->ldp->iff, 0xFFFFFFFF);
6264 + ldp_interface_admin_state_finish(mi);
6267 +void ldp_interface_delete(struct mpls_interface *mi) {
6268 + struct ldp *ldp = mi->mpls->ldp;
6270 + mi->ldp->create_on_hold = MPLS_BOOL_TRUE;
6271 + mi->ldp->entity.admin_state = MPLS_OPER_DOWN;
6273 + if (ldp) {
6274 + ldp_interface_admin_state_start(mi);
6275 + ldp_cfg_entity_set(ldp->h, &mi->ldp->entity, LDP_CFG_DEL);
6276 + ldp_cfg_if_set(ldp->h, &mi->ldp->iff, LDP_CFG_DEL);
6278 + mi->ldp->entity.index = 0;
6279 + mi->ldp->iff.index = 0;
6282 +int ldp_interface_startup(struct mpls_interface *mi) {
6283 + struct ldp *ldp = mi->mpls->ldp;
6285 + if (!mi->ldp->iff.index) {
6286 + return MPLS_FAILURE;
6289 + mi->ldp->entity.admin_state = MPLS_OPER_UP;
6290 + ldp_cfg_entity_set(ldp->h, &mi->ldp->entity, LDP_ENTITY_CFG_ADMIN_STATE);
6292 + return MPLS_SUCCESS;
6295 +int ldp_interface_shutdown(struct mpls_interface *mi) {
6296 + struct ldp *ldp = mi->mpls->ldp;
6298 + if (!mi->ldp->iff.index) {
6299 + return MPLS_FAILURE;
6302 + mi->ldp->entity.admin_state = MPLS_OPER_DOWN;
6303 + ldp_cfg_entity_set(ldp->h, &mi->ldp->entity, LDP_ENTITY_CFG_ADMIN_STATE);
6305 + return MPLS_SUCCESS;
6308 +int ldp_interface_admin_state_start(struct mpls_interface *mi) {
6309 + if (mi->ldp->admin_up == MPLS_BOOL_TRUE && mpls_if_is_up(mi)) {
6310 + return ldp_interface_shutdown(mi);
6312 + return MPLS_SUCCESS;
6315 +int ldp_interface_admin_state_finish(struct mpls_interface *mi) {
6316 + if (mi->ldp->admin_up == MPLS_BOOL_TRUE && mpls_if_is_up(mi)) {
6317 + return ldp_interface_startup(mi);
6319 + return MPLS_SUCCESS;
6322 +void ldp_if_up(struct mpls_interface *mi) {
6323 + if (mi->ldp && mi->ldp->admin_up == MPLS_BOOL_TRUE) {
6324 + ldp_interface_startup(mi);
6328 +void ldp_if_down(struct mpls_interface *mi) {
6329 + if (mi->ldp && mi->ldp->admin_up == MPLS_BOOL_TRUE) {
6330 + ldp_interface_shutdown(mi);
6333 diff -uNr --exclude=CVS zebra/mplsd/ldp_interface.h zebra-ldp/mplsd/ldp_interface.h
6334 --- zebra/mplsd/ldp_interface.h Wed Dec 31 19:00:00 1969
6335 +++ zebra-ldp/mplsd/ldp_interface.h Thu Oct 24 09:05:40 2002
6336 @@ -0,0 +1,31 @@
6337 +#ifndef LDP_IF_H
6338 +#define LDP_IF_H
6340 +#include "ldp_struct.h"
6342 +struct mpls_interface;
6344 +struct ldp_interface {
6345 + struct mpls_interface *mi;
6346 + ldp_entity entity;
6347 + ldp_if iff;
6348 + mpls_bool admin_up;
6349 + mpls_bool create_on_hold;
6352 +struct ldp_interface *ldp_if_new(struct mpls_interface *mi);
6353 +void ldp_if_free(struct ldp_interface *li);
6355 +void ldp_if_up(struct mpls_interface *mi);
6356 +void ldp_if_down(struct mpls_interface *mi);
6358 +int ldp_interface_startup(struct mpls_interface *mi);
6359 +int ldp_interface_shutdown(struct mpls_interface *mi);
6361 +void ldp_interface_create(struct mpls_interface *mi);
6362 +void ldp_interface_delete(struct mpls_interface *mi);
6363 +int ldp_interface_admin_state_start(struct mpls_interface *mi);
6364 +int ldp_interface_admin_state_finish(struct mpls_interface *mi);
6367 +#endif
6368 diff -uNr --exclude=CVS zebra/mplsd/ldp_vty.c zebra-ldp/mplsd/ldp_vty.c
6369 --- zebra/mplsd/ldp_vty.c Wed Dec 31 19:00:00 1969
6370 +++ zebra-ldp/mplsd/ldp_vty.c Fri Nov 22 13:42:49 2002
6371 @@ -0,0 +1,1994 @@
6372 +#include <zebra.h>
6374 +#include "ldp.h"
6375 +#include "ldp_cfg.h"
6376 +#include "ldp_struct.h"
6377 +#include "ldp_interface.h"
6379 +#include "impl_mpls.h"
6381 +#include "mpls.h"
6382 +#include "mpls_interface.h"
6384 +#include "command.h"
6385 +#include "zclient.h"
6386 +#include "vty.h"
6388 +uint32_t ldp_traceflags = 0;
6389 +uint8_t trace_buffer[16834];
6390 +int trace_buffer_len = 0;
6392 +char *session_state[6] = { "NONE", "NON-EXIST", "INIT",
6393 + "OPENSENT", "OPENRECV", "OPERATIONAL" };
6394 +char *adj_role[3] = { "INVALID", "PASSIVE", "ACTIVE" };
6395 +char *attr_state[12] = { "REQ_RECV", "REQ_SENT", "MAP_RECV", "MAP_SENT",
6396 + "WITH_SENT", "WITH_RECV", "NO_LABEL_RESOURCE_SENT",
6397 + "NO_LABEL_RESOURCE_RECV", "ABORT_SENT", "ABORT_RECV",
6398 + "NOTIF_SENT", "NOTIF_RECV" };
6399 +char *oper_state[2] = { "UP", "DOWN" };
6400 +char *control_mode[3] = { "UNKNOWN", "INDEPENDENT", "ORDERED" };
6401 +char *retention_mode[3] = { "UNKNOWN", "LIBERAL", "CONSERVATIVE" };
6402 +char *repair_mode[3] = { "UNKNOWN", "LOCAL", "GLOBAL" };
6403 +char *loop_detect_mode[5] = { "NONE", "HOPCOUNT", "PATHVECTOR",
6404 + "HOPCOUNT PATHVECTOR", "OTHER" };
6405 +char *bool[2] = { "FALSE", "TRUE" };
6406 +char *admin_state[3] = { "NONE", "ENABLED", "DISABLED" };
6407 +char *distribution_mode[2] = { "UNSOLICITED", "ONDEMAND" };
6409 +extern struct zclient *zclient;
6411 +DEFUN (mpls_ldp,
6412 + mpls_ldp_cmd,
6413 + "mpls ldp",
6414 + "MPLS configuration\n"
6415 + "Start LDP configuration\n") {
6417 + vty->node = MPLS_LDP_NODE;
6418 + vty->index = ldp_get();
6420 + return CMD_SUCCESS;
6423 +DEFUN (no_mpls_ldp,
6424 + no_mpls_ldp_cmd,
6425 + "no mpls ldp",
6426 + NO_STR
6427 + "MPLS configuration\n"
6428 + "Global LDP configuration\n") {
6429 + struct mpls *mpls = mpls_get();
6431 + if (!mpls->ldp) {
6432 + vty_out (vty, "There isn't active an LDP instance.%s", VTY_NEWLINE);
6433 + return CMD_WARNING;
6436 + ldp_finish(mpls->ldp);
6437 + return CMD_SUCCESS;
6440 +DEFUN (mpls_ldp_lsrid,
6441 + mpls_ldp_lsrid_cmd,
6442 + "lsr-id A.B.C.D",
6443 + "LDP Label Switch Router Identifier\n"
6444 + "IP Address\n") {
6445 + struct ldp *ldp = (struct ldp*)vty->index;
6447 + ldp->lsr_id_is_static = MPLS_BOOL_TRUE;
6449 + ldp_admin_state_start(ldp);
6450 + do_ldp_router_id_update(ldp, ntohl(inet_addr(argv[0])));
6451 + ldp_admin_state_finish(ldp);
6453 + return CMD_SUCCESS;
6456 +DEFUN (no_mpls_ldp_lsrid,
6457 + no_mpls_ldp_lsrid_cmd,
6458 + "no lsr-id",
6459 + NO_STR
6460 + "LDP LSRID\n") {
6461 + struct ldp *ldp = (struct ldp*)vty->index;
6463 + ldp->lsr_id_is_static = MPLS_BOOL_FALSE;
6465 + ldp_admin_state_start(ldp);
6466 + do_ldp_router_id_update(ldp, ntohl(ldp->mpls->router_id.u.prefix4.s_addr));
6467 + ldp_admin_state_finish(ldp);
6469 + return CMD_SUCCESS;
6472 +DEFUN (mpls_ldp_disable,
6473 + mpls_ldp_disable_cmd,
6474 + "disable",
6475 + "Disable\n") {
6476 + struct ldp *ldp = (struct ldp*)vty->index;
6478 + ldp_admin_state_start(ldp);
6479 + ldp->admin_up = MPLS_BOOL_FALSE;
6480 + ldp_admin_state_finish(ldp);
6482 + return CMD_SUCCESS;
6485 +DEFUN (no_mpls_ldp_disable,
6486 + no_mpls_ldp_disable_cmd,
6487 + "no disable",
6488 + NO_STR
6489 + "Disable\n") {
6490 + struct ldp *ldp = (struct ldp*)vty->index;
6492 + ldp_admin_state_start(ldp);
6493 + ldp->admin_up = MPLS_BOOL_TRUE;
6494 + ldp_admin_state_finish(ldp);
6496 + return CMD_SUCCESS;
6499 +DEFUN (mpls_ldp_lsp_control_mode,
6500 + mpls_ldp_lsp_control_mode_cmd,
6501 + "lsp-control-mode (independent|ordered)",
6502 + "control mode\n"
6503 + "independent or ordered control mode\n") {
6504 + struct ldp *ldp = (struct ldp*)vty->index;
6505 + ldp_global g;
6507 + if (!strcmp(argv[0],"independent")) {
6508 + g.lsp_control_mode = LDP_CONTROL_INDEPENDENT;
6509 + } else if (!strcmp(argv[0],"ordered")) {
6510 + g.lsp_control_mode = LDP_CONTROL_ORDERED;
6511 + } else {
6512 + return CMD_WARNING;
6515 + ldp_admin_state_start(ldp);
6516 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_CONTROL_MODE);
6517 + ldp_admin_state_finish(ldp);
6519 + return CMD_SUCCESS;
6522 +DEFUN (no_mpls_ldp_lsp_control_mode,
6523 + no_mpls_ldp_lsp_control_mode_cmd,
6524 + "no lsp-control-mode",
6525 + NO_STR
6526 + "control mode\n") {
6527 + struct ldp *ldp = (struct ldp*)vty->index;
6528 + ldp_global g;
6530 + g.lsp_control_mode = LDP_GLOBAL_DEF_CONTROL_MODE;
6532 + ldp_admin_state_start(ldp);
6533 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_CONTROL_MODE);
6534 + ldp_admin_state_finish(ldp);
6536 + return CMD_SUCCESS;
6539 +DEFUN (mpls_ldp_label_retention_mode,
6540 + mpls_ldp_label_retention_mode_cmd,
6541 + "label-retention-mode (liberal|conservative)",
6542 + "label retention mode\n"
6543 + "liberal or conservative retention mode\n") {
6544 + struct ldp *ldp = (struct ldp*)vty->index;
6545 + ldp_global g;
6547 + if (!strcmp(argv[0],"liberal")) {
6548 + g.label_retention_mode = LDP_RETENTION_LIBERAL;
6549 + } else if (!strcmp(argv[0],"conservative")) {
6550 + g.label_retention_mode = LDP_RETENTION_CONSERVATIVE;
6551 + } else {
6552 + return CMD_WARNING;
6555 + ldp_admin_state_start(ldp);
6556 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_RETENTION_MODE);
6557 + ldp_admin_state_finish(ldp);
6559 + return CMD_SUCCESS;
6562 +DEFUN (no_mpls_ldp_label_retention_mode,
6563 + no_mpls_ldp_label_retention_mode_cmd,
6564 + "no label-retention-mode",
6565 + NO_STR
6566 + "label retiontion mode\n") {
6567 + struct ldp *ldp = (struct ldp*)vty->index;
6568 + ldp_global g;
6570 + g.label_retention_mode = LDP_GLOBAL_DEF_RETENTION_MODE;
6572 + ldp_admin_state_start(ldp);
6573 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_RETENTION_MODE);
6574 + ldp_admin_state_finish(ldp);
6576 + return CMD_SUCCESS;
6579 +DEFUN (mpls_ldp_lsp_repair_mode,
6580 + mpls_ldp_lsp_repair_mode_cmd,
6581 + "lsp-repair-mode (local|global)",
6582 + "repair mode\n"
6583 + "local or global repair mode\n") {
6584 + struct ldp *ldp = (struct ldp*)vty->index;
6585 + ldp_global g;
6587 + if (!strcmp(argv[0],"local")) {
6588 + g.lsp_repair_mode = LDP_REPAIR_LOCAL;
6589 + } else if (!strcmp(argv[0],"global")) {
6590 + g.lsp_repair_mode = LDP_REPAIR_GLOBAL;
6591 + } else {
6592 + return CMD_WARNING;
6594 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_REPAIR_MODE);
6596 + return CMD_SUCCESS;
6599 +DEFUN (no_mpls_ldp_lsp_repair_mode,
6600 + no_mpls_ldp_lsp_repair_mode_cmd,
6601 + "no lsp-repair-mode",
6602 + NO_STR
6603 + "repair mode\n") {
6604 + struct ldp *ldp = (struct ldp*)vty->index;
6605 + ldp_global g;
6607 + g.lsp_repair_mode = LDP_GLOBAL_DEF_REPAIR_MODE;
6608 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_REPAIR_MODE);
6610 + return CMD_SUCCESS;
6613 +DEFUN (mpls_ldp_propogate_release,
6614 + mpls_ldp_propogate_release_cmd,
6615 + "propagate-release",
6616 + "propagate release\n") {
6617 + struct ldp *ldp = (struct ldp*)vty->index;
6618 + ldp_global g;
6620 + g.propagate_release = MPLS_BOOL_TRUE;
6621 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_PROPOGATE_RELEASE);
6623 + return CMD_SUCCESS;
6626 +DEFUN (no_mpls_ldp_propogate_release,
6627 + no_mpls_ldp_propogate_release_cmd,
6628 + "no propagate-release",
6629 + NO_STR
6630 + "propagate release\n") {
6631 + struct ldp *ldp = (struct ldp*)vty->index;
6632 + ldp_global g;
6634 + g.propagate_release = MPLS_BOOL_FALSE;
6635 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_PROPOGATE_RELEASE);
6637 + return CMD_SUCCESS;
6640 +DEFUN (mpls_ldp_label_merge,
6641 + mpls_ldp_label_merge_cmd,
6642 + "label-merge",
6643 + "label merge\n") {
6644 + struct ldp *ldp = (struct ldp*)vty->index;
6645 + ldp_global g;
6647 + g.label_merge = MPLS_BOOL_TRUE;
6649 + ldp_admin_state_start(ldp);
6650 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LABEL_MERGE);
6651 + ldp_admin_state_finish(ldp);
6653 + return CMD_SUCCESS;
6656 +DEFUN (no_mpls_ldp_label_merge,
6657 + no_mpls_ldp_label_merge_cmd,
6658 + "no label-merge",
6659 + NO_STR
6660 + "label merge\n") {
6661 + struct ldp *ldp = (struct ldp*)vty->index;
6662 + ldp_global g;
6664 + g.label_merge = MPLS_BOOL_FALSE;
6666 + ldp_admin_state_start(ldp);
6667 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LABEL_MERGE);
6668 + ldp_admin_state_finish(ldp);
6670 + return CMD_SUCCESS;
6673 +DEFUN (mpls_ldp_loop_detection_mode,
6674 + mpls_ldp_loop_detection_mode_cmd,
6675 + "loop-detection-mode (hop|path|both)",
6676 + "loop detection\n"
6677 + "Path Vector, Hop Count, or both\n") {
6678 + struct ldp *ldp = (struct ldp*)vty->index;
6679 + ldp_global g;
6681 + if (!strncmp(argv[0],"hop",3)) {
6682 + g.loop_detection_mode = LDP_LOOP_HOPCOUNT;
6683 + } else if (!strncmp(argv[0],"path",4)) {
6684 + g.loop_detection_mode = LDP_LOOP_PATHVECTOR;
6685 + } else if (!strncmp(argv[0],"both",4)) {
6686 + g.loop_detection_mode = LDP_LOOP_HOPCOUNT_PATHVECTOR;
6687 + } else {
6688 + return CMD_WARNING;
6690 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOOP_DETECTION_MODE);
6692 + return CMD_SUCCESS;
6695 +DEFUN (no_mpls_ldp_loop_detection_mode,
6696 + no_mpls_ldp_loop_detection_mode_cmd,
6697 + "no loop-detection-mode (path|hop|both)",
6698 + NO_STR
6699 + "loop detection\n") {
6700 + struct ldp *ldp = (struct ldp*)vty->index;
6701 + ldp_global g;
6703 + g.loop_detection_mode = LDP_LOOP_NONE;
6704 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOOP_DETECTION_MODE);
6706 + return CMD_SUCCESS;
6709 +DEFUN (mpls_ldp_ttl_less_domain,
6710 + mpls_ldp_ttl_less_domain_cmd,
6711 + "ttl-less-domain",
6712 + "TTL-less domain\n") {
6713 + struct ldp *ldp = (struct ldp*)vty->index;
6714 + ldp_global g;
6716 + g.ttl_less_domain = MPLS_BOOL_TRUE;
6717 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_TTLLESS_DOMAIN);
6719 + return CMD_SUCCESS;
6722 +DEFUN (no_mpls_ldp_ttl_less_domain,
6723 + no_mpls_ldp_ttl_less_domain_cmd,
6724 + "no ttl-less-domain",
6725 + NO_STR
6726 + "TTL-less domain\n") {
6727 + struct ldp *ldp = (struct ldp*)vty->index;
6728 + ldp_global g;
6730 + g.ttl_less_domain = MPLS_BOOL_FALSE;
6731 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_TTLLESS_DOMAIN);
6733 + return CMD_SUCCESS;
6736 +DEFUN (mpls_ldp_local_tcp_port,
6737 + mpls_ldp_local_tcp_port_cmd,
6738 + "local-tcp-port <1-65535>",
6739 + "local TCP port\n"
6740 + "TCP port number\n") {
6741 + struct ldp *ldp = (struct ldp*)vty->index;
6742 + ldp_global g;
6744 + g.local_tcp_port = atoi(argv[0]);
6746 + ldp_admin_state_start(ldp);
6747 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOCAL_TCP_PORT);
6748 + ldp_admin_state_finish(ldp);
6750 + return CMD_SUCCESS;
6753 +DEFUN (no_mpls_ldp_local_tcp_port,
6754 + no_mpls_ldp_local_tcp_port_cmd,
6755 + "no local-tcp-port",
6756 + NO_STR
6757 + "local TCP port\n") {
6758 + struct ldp *ldp = (struct ldp*)vty->index;
6759 + ldp_global g;
6761 + g.local_tcp_port = LDP_GLOBAL_DEF_LOCAL_TCP_PORT;
6763 + ldp_admin_state_start(ldp);
6764 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOCAL_TCP_PORT);
6765 + ldp_admin_state_finish(ldp);
6767 + return CMD_SUCCESS;
6770 +DEFUN (mpls_ldp_local_udp_port,
6771 + mpls_ldp_local_udp_port_cmd,
6772 + "local-udp-port <1-65535>",
6773 + "local UDP port\n"
6774 + "UDP port number\n") {
6775 + struct ldp *ldp = (struct ldp*)vty->index;
6776 + ldp_global g;
6778 + g.local_udp_port = atoi(argv[0]);
6780 + ldp_admin_state_start(ldp);
6781 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOCAL_UDP_PORT);
6782 + ldp_admin_state_finish(ldp);
6784 + return CMD_SUCCESS;
6787 +DEFUN (no_mpls_ldp_local_udp_port,
6788 + no_mpls_ldp_local_udp_port_cmd,
6789 + "no local-udp-port",
6790 + NO_STR
6791 + "local UDP port\n") {
6792 + struct ldp *ldp = (struct ldp*)vty->index;
6793 + ldp_global g;
6795 + g.local_udp_port = LDP_GLOBAL_DEF_LOCAL_UDP_PORT;
6797 + ldp_admin_state_start(ldp);
6798 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOCAL_UDP_PORT);
6799 + ldp_admin_state_finish(ldp);
6801 + return CMD_SUCCESS;
6804 +DEFUN (mpls_ldp_trace_address,
6805 + mpls_ldp_trace_address_cmd,
6806 + "trace address",
6807 + "LDP debugging\n"
6808 + "Address PDUs\n") {
6809 + ldp_traceflags |= LDP_TRACE_FLAG_ADDRESS;
6810 + return CMD_SUCCESS;
6813 +DEFUN (mpls_ldp_trace_binding,
6814 + mpls_ldp_trace_binding_cmd,
6815 + "trace binding",
6816 + "LDP debugging\n"
6817 + "Label Bindings\n") {
6818 + ldp_traceflags |= LDP_TRACE_FLAG_BINDING;
6819 + return CMD_SUCCESS;
6822 +DEFUN (mpls_ldp_trace_debug,
6823 + mpls_ldp_trace_debug_cmd,
6824 + "trace debug",
6825 + "LDP debugging\n"
6826 + "Debug Messages\n") {
6827 + ldp_traceflags |= LDP_TRACE_FLAG_DEBUG;
6828 + return CMD_SUCCESS;
6831 +DEFUN (mpls_ldp_trace_error,
6832 + mpls_ldp_trace_error_cmd,
6833 + "trace error",
6834 + "LDP debugging\n"
6835 + "Error Conditions\n") {
6836 + ldp_traceflags |= LDP_TRACE_FLAG_ERROR;
6837 + return CMD_SUCCESS;
6840 +DEFUN (mpls_ldp_trace_event,
6841 + mpls_ldp_trace_event_cmd,
6842 + "trace event",
6843 + "LDP debugging\n"
6844 + "LDP Events\n") {
6845 + ldp_traceflags |= LDP_TRACE_FLAG_EVENT;
6846 + return CMD_SUCCESS;
6849 +DEFUN (mpls_ldp_trace_general,
6850 + mpls_ldp_trace_general_cmd,
6851 + "trace general",
6852 + "LDP debugging\n"
6853 + "General Messages\n") {
6854 + ldp_traceflags |= LDP_TRACE_FLAG_GENERAL;
6855 + return CMD_SUCCESS;
6858 +DEFUN (mpls_ldp_trace_init,
6859 + mpls_ldp_trace_init_cmd,
6860 + "trace init",
6861 + "LDP debugging\n"
6862 + "Init PDUs\n") {
6863 + ldp_traceflags |= LDP_TRACE_FLAG_INIT;
6864 + return CMD_SUCCESS;
6867 +DEFUN (mpls_ldp_trace_label,
6868 + mpls_ldp_trace_label_cmd,
6869 + "trace label",
6870 + "LDP debugging\n"
6871 + "Label PDUs\n") {
6872 + ldp_traceflags |= LDP_TRACE_FLAG_LABEL;
6873 + return CMD_SUCCESS;
6876 +DEFUN (mpls_ldp_trace_normal,
6877 + mpls_ldp_trace_normal_cmd,
6878 + "trace normal",
6879 + "LDP debugging\n"
6880 + "Normal Messages\n") {
6881 + ldp_traceflags |= LDP_TRACE_FLAG_NORMAL;
6882 + return CMD_SUCCESS;
6885 +DEFUN (mpls_ldp_trace_notif,
6886 + mpls_ldp_trace_notif_cmd,
6887 + "trace notification",
6888 + "LDP debugging\n"
6889 + "Notification PDUs\n") {
6890 + ldp_traceflags |= LDP_TRACE_FLAG_NOTIF;
6891 + return CMD_SUCCESS;
6894 +DEFUN (mpls_ldp_trace_packet_dump,
6895 + mpls_ldp_trace_packet_dump_cmd,
6896 + "trace packet-dump",
6897 + "LDP debugging\n"
6898 + "Packet Dump\n") {
6899 + ldp_traceflags |= LDP_TRACE_FLAG_PACKET_DUMP;
6900 + return CMD_SUCCESS;
6903 +DEFUN (mpls_ldp_trace_packet,
6904 + mpls_ldp_trace_packet_cmd,
6905 + "trace packet",
6906 + "LDP debugging\n"
6907 + "Packet tracing\n") {
6908 + ldp_traceflags |= LDP_TRACE_FLAG_PACKET;
6909 + return CMD_SUCCESS;
6912 +DEFUN (mpls_ldp_trace_path,
6913 + mpls_ldp_trace_path_cmd,
6914 + "trace path",
6915 + "LDP debugging\n"
6916 + "PATH Info\n") {
6917 + ldp_traceflags |= LDP_TRACE_FLAG_PATH;
6918 + return CMD_SUCCESS;
6921 +DEFUN (mpls_ldp_trace_periodic,
6922 + mpls_ldp_trace_periodic_cmd,
6923 + "trace periodic",
6924 + "LDP debugging\n"
6925 + "Periodic PDUs\n") {
6926 + ldp_traceflags |= LDP_TRACE_FLAG_PERIODIC;
6927 + return CMD_SUCCESS;
6930 +DEFUN (mpls_ldp_trace_policy,
6931 + mpls_ldp_trace_policy_cmd,
6932 + "trace policy",
6933 + "LDP debugging\n"
6934 + "Policy tracing\n") {
6935 + ldp_traceflags |= LDP_TRACE_FLAG_POLICY;
6936 + return CMD_SUCCESS;
6939 +DEFUN (mpls_ldp_trace_route,
6940 + mpls_ldp_trace_route_cmd,
6941 + "trace route",
6942 + "LDP debugging\n"
6943 + "Route Lookup tracing\n") {
6944 + ldp_traceflags |= LDP_TRACE_FLAG_ROUTE;
6945 + return CMD_SUCCESS;
6948 +DEFUN (mpls_ldp_trace_state,
6949 + mpls_ldp_trace_state_cmd,
6950 + "trace state",
6951 + "LDP debugging\n"
6952 + "State transitions\n") {
6953 + ldp_traceflags |= LDP_TRACE_FLAG_STATE;
6954 + return CMD_SUCCESS;
6957 +DEFUN (mpls_ldp_trace_task,
6958 + mpls_ldp_trace_task_cmd,
6959 + "trace task",
6960 + "LDP debugging\n"
6961 + "Task tracing\n") {
6962 + ldp_traceflags |= LDP_TRACE_FLAG_TASK;
6963 + return CMD_SUCCESS;
6966 +DEFUN (mpls_ldp_trace_timer,
6967 + mpls_ldp_trace_timer_cmd,
6968 + "trace timer",
6969 + "LDP debugging\n"
6970 + "Timer tracing\n") {
6971 + ldp_traceflags |= LDP_TRACE_FLAG_TIMER;
6972 + return CMD_SUCCESS;
6975 +DEFUN (mpls_ldp_trace_all,
6976 + mpls_ldp_trace_all_cmd,
6977 + "trace all",
6978 + "LDP debugging\n"
6979 + "All tracing\n") {
6980 + ldp_traceflags |= LDP_TRACE_FLAG_ALL;
6981 + return CMD_SUCCESS;
6984 +DEFUN (mpls_ldp_trace_none,
6985 + mpls_ldp_trace_none_cmd,
6986 + "trace none",
6987 + "LDP debugging\n"
6988 + "Turn off all tracing\n") {
6989 + ldp_traceflags = 0;
6990 + return CMD_SUCCESS;
6993 +/* address and egress changes should result in an event which goes through
6994 + all of the existing FECs/addresses and decides which to withdrawl and then
6995 + ask the system for which additional FECs/addresses should be sent */
6997 +DEFUN (mpls_ldp_address,
6998 + mpls_ldp_address_cmd,
6999 + "address-mode (lsr-id|ldp)",
7000 + "Addresses this LSR will announce\n"
7001 + "LSR-ID only\n"
7002 + "Only LDP interfaces\n") {
7003 + struct ldp *ldp = (struct ldp*)vty->index;
7004 + if (!strncmp(argv[0], "lsr-id",6)) {
7005 + ldp->address = LDP_ADDRESS_LSRID;
7006 + } else if (!strncmp(argv[0], "ldp",3)) {
7007 + ldp->address = LDP_ADDRESS_LDP;
7008 + } else {
7009 + return CMD_WARNING;
7011 + return CMD_SUCCESS;
7014 +DEFUN (no_mpls_ldp_address,
7015 + no_mpls_ldp_address_cmd,
7016 + "no address-mode",
7017 + NO_STR
7018 + "Addresses this LSR will announce\n") {
7019 + struct ldp *ldp = (struct ldp*)vty->index;
7020 + ldp->address = LDP_ADDRESS_ALL;
7021 + return CMD_SUCCESS;
7024 +DEFUN (mpls_ldp_egress,
7025 + mpls_ldp_egress_cmd,
7026 + "egress (lsr-id|connected)",
7027 + "Filter FECs this LSR will send mappings for\n"
7028 + "LSR-ID only\n"
7029 + "All connected subnets\n") {
7030 + struct ldp *ldp = (struct ldp*)vty->index;
7031 + if (!strncmp(argv[0], "lsr-id",6)) {
7032 + ldp->egress = LDP_EGRESS_LSRID;
7033 + } else if (!strncmp(argv[0], "connected", 9)) {
7034 + ldp->egress = LDP_EGRESS_CONNECTED;
7035 + } else {
7036 + return CMD_WARNING;
7038 + return CMD_SUCCESS;
7041 +DEFUN (no_mpls_ldp_egress,
7042 + no_mpls_ldp_egress_cmd,
7043 + "no egress",
7044 + NO_STR
7045 + "Filter FECs this LSR will send mappings for\n") {
7046 + struct ldp *ldp = (struct ldp*)vty->index;
7047 + ldp->egress = LDP_EGRESS_ALL;
7048 + return CMD_SUCCESS;
7051 +#if 0
7052 +DEFUN (mpls_ldp_egress_list,
7053 + mpls_ldp_egress_list_cmd,
7054 + "egress access-list (<1-199>|<1300-2699>|WORD)",
7055 + "Filter FECs this LSR will send mappings for\n"
7056 + "IP access-list number\n"
7057 + "IP access-list number (expanded range)\n"
7058 + "IP Access-list name\n") {
7059 + return CMD_SUCCESS;
7062 +DEFUN (no_mpls_ldp_egress_list,
7063 + no_mpls_ldp_egress_list_cmd,
7064 + "no egress access-list (<1-199>|<1300-2699>|WORD)",
7065 + NO_STR
7066 + "Filter FECs this LSR will send mappings for\n"
7067 + "IP access-list number\n"
7068 + "IP access-list number (expanded range)\n"
7069 + "IP Access-list name\n") {
7070 + return CMD_SUCCESS;
7072 +#endif
7074 +DEFUN (mpls_show_ldp, mpls_show_ldp_cmd,
7075 + "show ldp",
7076 + SHOW_STR
7077 + "LDP global setting\n") {
7078 + struct mpls *mpls = mpls_get();
7079 + ldp_global g;
7081 + if (!mpls->ldp) {
7082 + vty_out (vty, "There isn't an active LDP instance.%s", VTY_NEWLINE);
7083 + return CMD_WARNING;
7086 + ldp_cfg_global_get(mpls->ldp->h,&g,0xFFFFFFFF);
7088 + vty_out(vty, "LSR-ID: %08x Admin State: %s%s",
7089 + g.lsr_identifier.u.ipv4, admin_state[g.admin_state], VTY_NEWLINE);
7090 + vty_out(vty, "Transport Address: %08x%s", g.transport_address.u.ipv4,
7091 + VTY_NEWLINE);
7092 + vty_out(vty, "Control Mode: %s\tRepair Mode: %s%s",
7093 + control_mode[g.lsp_control_mode], repair_mode[g.lsp_repair_mode],
7094 + VTY_NEWLINE);
7095 + vty_out(vty, "Propogate Release: %s\tLabel Merge: %s%s",
7096 + bool[g.propagate_release], bool[g.label_merge], VTY_NEWLINE);
7097 + vty_out(vty, "Retention Mode: %s\tLoop Detection Mode: %s%s",
7098 + retention_mode[g.label_retention_mode],
7099 + loop_detect_mode[g.loop_detection_mode], VTY_NEWLINE);
7100 + vty_out(vty, "TTL-less-domain: %s%s", bool[g.ttl_less_domain],
7101 + VTY_NEWLINE);
7102 + vty_out(vty, "Local TCP Port: %d\tLocal UDP Port: %d%s",
7103 + g.local_tcp_port, g.local_udp_port, VTY_NEWLINE);
7104 + vty_out(vty, "Keep-alive Time: %d\tKeep-alive Interval: %d%s",
7105 + g.keepalive_timer, g.keepalive_interval, VTY_NEWLINE);
7106 + vty_out(vty, "Hello Time: %d\tHello Interval: %d%s",
7107 + g.hellotime_timer, g.hellotime_interval, VTY_NEWLINE);
7109 + return CMD_SUCCESS;
7112 +DEFUN (mpls_show_ldp_neighbor, mpls_show_ldp_neighbor_cmd,
7113 + "show ldp neighbor [A.B.C.D:E]",
7114 + SHOW_STR
7115 + "LDP related commands\n"
7116 + "Discovered neighbors\n"
7117 + "LDP identifier\n") {
7118 + struct mpls *mpls = mpls_get();
7119 + struct ldp *ldp = mpls->ldp;
7120 + ldp_adj adj;
7121 + ldp_addr addr;
7122 + ldp_entity e;
7123 + ldp_global g;
7124 + ldp_session s;
7125 + int count;
7126 + int addr_count;
7127 + struct in_addr lsr;
7128 + int labelspace;
7129 + char name[32];
7131 +#if 0
7132 + struct in_addr src;
7133 + struct in_addr tr;
7135 +Peer LDP Ident: 7.1.1.1:0; Local LDP Ident 8.1.1.1:0
7136 + TCP connection: 7.1.1.1.646 - 8.1.1.1.11006
7137 + State: Oper; Msgs sent/rcvd: 4/411; Downstream
7138 + Up time: 00:00:52
7139 + LDP discovery sources:
7140 + Ethernet1/0/0
7141 + Addresses bound to peer LDP Ident:
7142 + 2.0.0.29 7.1.1.1 59.0.0.199 212.10.1.1
7143 + 10.205.0.9
7145 + tr.s_addr = htonl(adj.remote_transport_address.u.ipv4);
7146 + src.s_addr = htonl(adj.remote_source_address.u.ipv4);
7147 + vty_out(vty, "%s %s %d ", inet_ntoa(src), inet_ntoa(tr), adj.remote_csn);
7148 + vty_out(vty, "%d %d %d ", adj.remote_hellotime, adj.entity_index,
7149 + adj.session_index);
7150 + vty_out(vty, "%s %d%s", adj_role[adj.role], adj.backoff, VTY_NEWLINE);
7151 +#endif
7153 + if (!ldp) {
7154 + vty_out (vty, "There isn't an active LDP instance.%s", VTY_NEWLINE);
7155 + return CMD_WARNING;
7158 + ldp_cfg_global_get(ldp->h,&g,0xFFFFFFFF);
7160 + count = 0;
7161 + adj.index = 0;
7162 + while (ldp_cfg_adj_getnext(ldp->h, &adj, 0xFFFFFFFF) ==
7163 + MPLS_SUCCESS) {
7164 + count++;
7166 + e.index = adj.entity_index;
7167 + ldp_cfg_entity_get(ldp->h,&e,0xFFFFFFFF);
7168 + if (e.entity_type == LDP_DIRECT) {
7169 + ldp_if iff;
7170 + iff.index = e.sub_index;
7171 + ldp_cfg_if_get(ldp->h,&iff,0xFFFFFFFF);
7172 + labelspace = iff.label_space;
7173 + strncpy(name,iff.name,sizeof(name) - 1);
7174 + } else {
7175 + ldp_peer peer;
7176 + peer.index = e.sub_index;
7177 + ldp_cfg_peer_get(ldp->h,&peer,0xFFFFFFFF);
7178 + labelspace = peer.label_space;
7179 + strncpy(name,peer.peer_name,sizeof(name) - 1);
7182 + lsr.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
7183 + vty_out(vty, "Peer LDP Ident: %s:%d; Local LDP Ident: ", inet_ntoa(lsr),
7184 + adj.remote_label_space);
7185 + lsr.s_addr = htonl(g.lsr_identifier.u.ipv4);
7186 + vty_out(vty, "%s:%d%s", inet_ntoa(lsr), labelspace, VTY_NEWLINE);
7188 + if (adj.session_index) {
7189 + s.index = adj.session_index;
7191 + if (ldp_cfg_session_get(ldp->h,&s,0xFFFFFFFF) != MPLS_SUCCESS) {
7192 + continue;
7195 + vty_out(vty, "\tTCP connection: %s%s", "n/a", VTY_NEWLINE);
7196 + vty_out(vty, "\tState: %s; Msgs sent/recv: %d/%d; %s%s",
7197 + session_state[s.state], s.mesg_tx, s.mesg_rx,
7198 + distribution_mode[s.oper_distribution_mode], VTY_NEWLINE);
7199 + vty_out(vty, "\tUp time: %s%s", "n/a", VTY_NEWLINE);
7200 + vty_out(vty, "\tLDP discovery sources:%s", VTY_NEWLINE);
7201 + vty_out(vty, "\t %s%s", name, VTY_NEWLINE);
7202 + vty_out(vty, "\tAddresses bound to peer:%s", VTY_NEWLINE);
7204 + addr.index = 0;
7205 + addr_count = 0;
7206 + while (ldp_cfg_session_raddr_getnext(ldp->h, &s, &addr, 0xFFFFFFFF) ==
7207 + MPLS_SUCCESS) {
7208 + lsr.s_addr = htonl(addr.address.u.ipv4);
7209 + vty_out(vty, "\t");
7210 + if (!addr_count) {
7211 + vty_out(vty, " ");
7214 + vty_out(vty, "%s",inet_ntoa(lsr));
7215 + addr_count++;
7217 + if (addr_count == 4) {
7218 + vty_out(vty, "%s", VTY_NEWLINE);
7219 + addr_count = 0;
7222 + vty_out(vty, "%s", VTY_NEWLINE);
7223 + } else {
7224 + vty_out(vty, "\tTCP connection: %s%s", "n/a", VTY_NEWLINE);
7225 + vty_out(vty, "\tState: discovery; Msgs sent/recv: -/-;%s",VTY_NEWLINE);
7226 + vty_out(vty, "\tUp time: %s%s", "-", VTY_NEWLINE);
7227 + vty_out(vty, "\tLDP discovery sources:%s", VTY_NEWLINE);
7228 + vty_out(vty, "\t %s%s", name, VTY_NEWLINE);
7231 + vty_out(vty, "%s", VTY_NEWLINE);
7232 + if (count == 0) {
7233 + vty_out(vty, "\tNo discovered neighbors%s", VTY_NEWLINE);
7235 + vty_out(vty, "%s", VTY_NEWLINE);
7237 + return CMD_SUCCESS;
7240 +DEFUN (mpls_show_ldp_session, mpls_show_ldp_session_cmd,
7241 + "show ldp session [A.B.C.D:E]",
7242 + SHOW_STR
7243 + "LDP related commands\n"
7244 + "Session information\n"
7245 + "LDP identifier\n") {
7246 + struct mpls *mpls = mpls_get();
7247 + struct ldp *ldp = mpls->ldp;
7248 + ldp_session session;
7249 + ldp_addr addr;
7250 + struct in_addr in;
7251 + int count = 0;
7253 + if (!ldp) {
7254 + vty_out (vty, "There isn't active LDP instance.%s", VTY_NEWLINE);
7255 + return CMD_WARNING;
7258 + session.index = 0;
7259 + while (ldp_cfg_session_getnext(ldp->h, &session, 0xFFFFFFFF) == MPLS_SUCCESS) {
7260 + count++;
7261 + in.s_addr = htonl(session.remote_dest.addr.u.ipv4);
7262 + vty_out(vty, "%-2d %s %-3d %s%s", session.index,
7263 + inet_ntoa(in), session.oper_keepalive,
7264 + session_state[session.state], VTY_NEWLINE);
7265 + addr.index = 0;
7266 + while (ldp_cfg_session_raddr_getnext(ldp->h, &session,
7267 + &addr, 0xFFFFFFFF) == MPLS_SUCCESS) {
7268 + in.s_addr = htonl(addr.address.u.ipv4);
7269 + vty_out(vty, "\t%s%s",inet_ntoa(in), VTY_NEWLINE);
7272 + if (count == 0) {
7273 + vty_out(vty, " no established sessions%s", VTY_NEWLINE);
7276 + return CMD_SUCCESS;
7279 +DEFUN (mpls_show_ldp_discovery, mpls_show_ldp_discovery_cmd,
7280 + "show ldp discovery",
7281 + SHOW_STR
7282 + "LDP related commands\n"
7283 + "Discovery information\n") {
7284 + struct mpls *mpls = mpls_get();
7285 + struct ldp *ldp = mpls->ldp;
7286 + ldp_if iff;
7287 + int count;
7288 + ldp_global g;
7289 + ldp_adj adj;
7290 + ldp_peer peer;
7291 + struct in_addr dst;
7292 + int first;
7294 + if (!ldp) {
7295 + vty_out (vty, "There isn't an active LDP instance.%s", VTY_NEWLINE);
7296 + return CMD_WARNING;
7299 + vty_out(vty, "%s", VTY_NEWLINE);
7301 + ldp_cfg_global_get(ldp->h,&g,0xFFFFFFFF);
7302 + dst.s_addr = htonl(g.lsr_identifier.u.ipv4);
7303 + vty_out(vty, "Local LSR Identifier: %s%s", inet_ntoa(dst), VTY_NEWLINE);
7304 + vty_out(vty, "%s", VTY_NEWLINE);
7305 + vty_out(vty, "Interface Discovery Sources:%s", VTY_NEWLINE);
7307 + count = 0;
7308 + iff.index = 0;
7309 + while (ldp_cfg_if_getnext(ldp->h, &iff, 0xFFFFFFFF) == MPLS_SUCCESS) {
7310 + first = 1;
7311 + count++;
7312 + vty_out(vty, "\t%s: ", iff.name);
7313 + if (iff.oper_state != MPLS_OPER_UP) {
7314 + vty_out(vty, "down");
7315 + } else {
7316 + vty_out(vty, "xmit");
7317 + while (ldp_cfg_adj_getnext(ldp->h, &adj, 0xFFFFFFFF) == MPLS_SUCCESS) {
7318 + if (iff.entity_index == adj.entity_index) {
7319 + if (first) {
7320 + vty_out(vty, "/recv%s", VTY_NEWLINE);
7321 + first = 0;
7323 + dst.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
7324 + vty_out(vty, "\t LDP Id: %s:%d%s ", inet_ntoa(dst),
7325 + adj.remote_label_space, VTY_NEWLINE);
7329 + if (first) {
7330 + vty_out(vty, "%s", VTY_NEWLINE);
7333 + if (count == 0) {
7334 + vty_out(vty, "\tNo configured interfaces%s", VTY_NEWLINE);
7337 + vty_out(vty, "%s", VTY_NEWLINE);
7338 + vty_out(vty, "Targeted Discovery Sources:%s", VTY_NEWLINE);
7340 + count = 0;
7341 + peer.index = 0;
7342 + while (ldp_cfg_peer_getnext(ldp->h, &peer, 0xFFFFFFFF) ==
7343 + MPLS_SUCCESS) {
7344 + first = 1;
7345 + count++;
7346 + dst.s_addr = htonl(peer.dest.addr.u.ipv4);
7347 + vty_out(vty, "\t%s: xmit ", inet_ntoa(dst));
7348 + while (ldp_cfg_adj_getnext(ldp->h, &adj, 0xFFFFFFFF) == MPLS_SUCCESS) {
7349 + if (peer.entity_index == adj.entity_index) {
7350 + if (first) {
7351 + vty_out(vty, "/recv%s", VTY_NEWLINE);
7352 + first = 0;
7354 + dst.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
7355 + vty_out(vty, "\t LDP Id: %s:%d%s ", inet_ntoa(dst),
7356 + adj.remote_label_space, VTY_NEWLINE);
7359 + if (first) {
7360 + vty_out(vty, "%s", VTY_NEWLINE);
7363 + if (count == 0) {
7364 + vty_out(vty, "\tNo configured peers%s", VTY_NEWLINE);
7366 + vty_out(vty, "%s", VTY_NEWLINE);
7368 + return CMD_SUCCESS;
7371 +void ldp_print_label(struct vty *vty, mpls_label_struct *l) {
7372 + switch(l->type) {
7373 + case MPLS_LABEL_TYPE_NONE:
7374 + vty_out(vty, "label: unknown");
7375 + break;
7376 + case MPLS_LABEL_TYPE_GENERIC:
7377 + vty_out(vty, "label: gen %d",l->u.gen);
7378 + break;
7379 + case MPLS_LABEL_TYPE_ATM:
7380 + vty_out(vty, "label: atm %d/%d",l->u.atm.vpi,l->u.atm.vci);
7381 + break;
7382 + case MPLS_LABEL_TYPE_FR:
7383 + vty_out(vty, "label: dlci %d",l->u.fr.dlci);
7384 + break;
7388 +DEFUN (mpls_show_ldp_database, mpls_show_ldp_database_cmd,
7389 + "show ldp database [A.B.C.D:E]",
7390 + SHOW_STR
7391 + "LDP related commands\n"
7392 + "Labeling information\n"
7393 + "LDP identifier\n") {
7394 + struct mpls *mpls = mpls_get();
7395 + struct ldp *ldp = mpls->ldp;
7396 + ldp_session session;
7397 + ldp_outlabel out;
7398 + ldp_inlabel in;
7399 + ldp_attr attr;
7400 + ldp_adj adj;
7401 + int count = 0;
7402 + struct in_addr fec;
7404 + if (!ldp) {
7405 + vty_out (vty, "There isn't an active LDP instance.%s", VTY_NEWLINE);
7406 + return CMD_WARNING;
7409 + attr.index = 0;
7410 + while (ldp_cfg_attr_getnext(ldp->h, &attr, 0xFFFFFFFF) == MPLS_SUCCESS) {
7411 + count++;
7413 + fec.s_addr = htonl(attr.fecTlv.fecElArray[0].addressEl.address);
7415 + vty_out(vty, " %s/%d ", inet_ntoa(fec),
7416 + attr.fecTlv.fecElArray[0].addressEl.preLen);
7418 + session.index = attr.session_index;
7419 + if (ldp_cfg_session_get(ldp->h, &session, 0xFFFFFFFF) != MPLS_SUCCESS) {
7420 + vty_out(vty, "no session%s",VTY_NEWLINE);
7421 + continue;
7424 + adj.index = session.adj_index;
7425 + if (ldp_cfg_adj_get(ldp->h, &adj, 0xFFFFFFFF) != MPLS_SUCCESS) {
7426 + vty_out(vty, "no adj%s",VTY_NEWLINE);
7427 + continue;
7430 + switch(attr.state) {
7431 + case LDP_LSP_STATE_MAP_RECV:
7432 + vty_out(vty, "remote binding: ");
7433 + out.index = attr.outlabel_index;
7434 + if (ldp_cfg_outlabel_get(ldp->h, &out, 0xFFFFFFFF) != MPLS_SUCCESS) {
7435 + vty_out(vty, "no outlabel");
7436 + } else {
7437 + ldp_print_label(vty,&out.info.label);
7439 + fec.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
7440 + vty_out(vty, " lsr: %s:%d ", inet_ntoa(fec), adj.remote_label_space);
7441 + if (attr.ingress == MPLS_BOOL_TRUE) {
7442 + vty_out(vty, "ingress");
7444 + break;
7445 + case LDP_LSP_STATE_MAP_SENT:
7446 + in.index = attr.inlabel_index;
7447 + if (ldp_cfg_inlabel_get(ldp->h, &in, 0xFFFFFFFF) != MPLS_SUCCESS) {
7448 + vty_out(vty, "no inlabel%s", VTY_NEWLINE);
7449 + continue;
7451 + vty_out(vty, "local binding: ");
7452 + ldp_print_label(vty,&in.info.label);
7453 + break;
7454 + case LDP_LSP_STATE_WITH_SENT:
7455 + case LDP_LSP_STATE_WITH_RECV:
7456 + case LDP_LSP_STATE_NO_LABEL_RESOURCE_SENT:
7457 + case LDP_LSP_STATE_NO_LABEL_RESOURCE_RECV:
7458 + case LDP_LSP_STATE_ABORT_SENT:
7459 + case LDP_LSP_STATE_ABORT_RECV:
7460 + case LDP_LSP_STATE_NOTIF_SENT:
7461 + case LDP_LSP_STATE_NOTIF_RECV:
7462 + case LDP_LSP_STATE_REQ_RECV:
7463 + case LDP_LSP_STATE_REQ_SENT:
7464 + vty_out(vty, "%s:\t", attr_state[attr.state]);
7465 + fec.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
7466 + vty_out(vty, "lsr: %s:%d", inet_ntoa(fec), adj.remote_label_space);
7467 + break;
7468 + default:
7470 + vty_out(vty, "%s", VTY_NEWLINE);
7472 + if (count == 0) {
7473 + vty_out(vty, " no labeling info has been exchanged%s", VTY_NEWLINE);
7476 + return CMD_SUCCESS;
7479 +DEFUN(ldp_intf,
7480 + ldp_intf_cmd,
7481 + "mpls ldp",
7482 + "MPLS interface configuration\n"
7483 + "Enable LDP\n") {
7484 + struct interface *ifp = vty->index;
7485 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7486 + struct mpls *mpls = mi->mpls;
7488 + if (!mi->ldp) {
7489 + /* user is trying to create a new LDP interface */
7490 + /* if a labelspace hasn't been set yet, set it to 0 */
7491 + if (mi->labelspace == -1) {
7492 + mi->labelspace = 0;
7493 + do_mpls_labelspace(mi);
7495 + mi->ldp = ldp_if_new(mi);
7498 + /* if the global LDP has been created, go ahead and tell LDP about it
7499 + * otherwise just mark the interface as "on hold"
7500 + */
7501 + if (mpls->ldp) {
7502 + ldp_interface_create(mi);
7503 + } else {
7504 + mi->ldp->create_on_hold = MPLS_BOOL_TRUE;
7507 + vty->node = MPLS_LDP_IF_NODE;
7509 + return CMD_SUCCESS;
7512 +DEFUN(no_ldp_intf,
7513 + no_ldp_intf_cmd,
7514 + "no mpls ldp",
7515 + NO_STR
7516 + "MPLS interface configuration\n"
7517 + "remove LDP\n") {
7518 + struct interface *ifp = vty->index;
7519 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7521 + if (mi->ldp) {
7522 + ldp_interface_delete(mi);
7523 + ldp_if_free(mi->ldp);
7524 + mi->ldp = NULL;
7526 + return CMD_SUCCESS;
7529 +DEFUN(ldp_if_distribution_mode,
7530 + ldp_if_distribution_mode_cmd,
7531 + "distribution-mode (dod|du)",
7532 + "MPLS interface configuration\n"
7533 + "distribution mode\n"
7534 + "Downstream on Demand or Downstream unsolicited\n") {
7535 + struct interface *ifp = vty->index;
7536 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7537 + struct ldp_interface *li = mi->ldp;
7538 + struct mpls *mpls = mi->mpls;
7539 + struct ldp *ldp = mpls->ldp;
7541 + if (!strncmp(argv[0],"dod",3)) {
7542 + li->entity.label_distribution_mode = LDP_DISTRIBUTION_ONDEMAND;
7543 + } else if (!strncmp(argv[0],"du",2)) {
7544 + li->entity.label_distribution_mode = LDP_DISTRIBUTION_UNSOLICITED;
7545 + } else {
7546 + return CMD_WARNING;
7549 + if (!ldp) {
7550 + li->create_on_hold = MPLS_BOOL_TRUE;
7551 + return CMD_SUCCESS;
7553 + ldp_interface_admin_state_start(mi);
7554 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_DISTRIBUTION_MODE);
7555 + ldp_interface_admin_state_finish(mi);
7556 + return CMD_SUCCESS;
7559 +DEFUN(no_ldp_if_distribution_mode,
7560 + no_ldp_if_distribution_mode_cmd,
7561 + "no distribution-mode",
7562 + NO_STR
7563 + "MPLS interface configuration\n"
7564 + "distribution mode\n") {
7565 + struct interface *ifp = vty->index;
7566 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7567 + struct ldp_interface *li = mi->ldp;
7568 + struct mpls *mpls = mi->mpls;
7569 + struct ldp *ldp = mpls->ldp;
7571 + li->entity.label_distribution_mode = LDP_ENTITY_DEF_DISTRIBUTION_MODE;
7572 + if (!ldp) {
7573 + li->create_on_hold = MPLS_BOOL_TRUE;
7574 + return CMD_SUCCESS;
7577 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_DISTRIBUTION_MODE);
7578 + return CMD_SUCCESS;
7581 +DEFUN(ldp_if_remote_tcp_port,
7582 + ldp_if_remote_tcp_port_cmd,
7583 + "remote-tcp-port <1-65535>",
7584 + "MPLS interface configuration\n"
7585 + "remote LDP port\n"
7586 + "port number\n") {
7587 + struct interface *ifp = vty->index;
7588 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7589 + struct ldp_interface *li = mi->ldp;
7590 + struct mpls *mpls = mi->mpls;
7591 + struct ldp *ldp = mpls->ldp;
7593 + li->entity.remote_tcp_port = atoi(argv[0]);
7594 + if (!ldp) {
7595 + li->create_on_hold = MPLS_BOOL_TRUE;
7596 + return CMD_SUCCESS;
7599 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REMOTE_TCP);
7600 + return CMD_SUCCESS;
7603 +DEFUN(no_ldp_if_remote_tcp_port,
7604 + no_ldp_if_remote_tcp_port_cmd,
7605 + "no remote-tcp-port",
7606 + NO_STR
7607 + "MPLS interface configuration\n"
7608 + "remote LDP port\n") {
7609 + struct interface *ifp = vty->index;
7610 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7611 + struct ldp_interface *li = mi->ldp;
7612 + struct mpls *mpls = mi->mpls;
7614 + li->entity.remote_tcp_port = LDP_ENTITY_DEF_REMOTE_TCP;
7615 + if (!mpls->ldp) {
7616 + li->create_on_hold = MPLS_BOOL_TRUE;
7617 + return CMD_SUCCESS;
7620 + ldp_cfg_entity_set(mpls->ldp->h, &li->entity, LDP_ENTITY_CFG_REMOTE_TCP);
7621 + return CMD_SUCCESS;
7624 +DEFUN(ldp_if_remote_udp_port,
7625 + ldp_if_remote_udp_port_cmd,
7626 + "remote-udp-port <1-65535>",
7627 + "MPLS interface configuration\n"
7628 + "remote LDP port\n"
7629 + "port number\n") {
7630 + struct interface *ifp = vty->index;
7631 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7632 + struct ldp_interface *li = mi->ldp;
7633 + struct mpls *mpls = mi->mpls;
7634 + struct ldp *ldp = mpls->ldp;
7636 + li->entity.remote_udp_port = atoi(argv[0]);
7637 + if (!ldp) {
7638 + li->create_on_hold = MPLS_BOOL_TRUE;
7639 + return CMD_SUCCESS;
7642 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REMOTE_UDP);
7643 + return CMD_SUCCESS;
7646 +DEFUN(no_ldp_if_remote_udp_port,
7647 + no_ldp_if_remote_udp_port_cmd,
7648 + "no remote-udp-port",
7649 + NO_STR
7650 + "MPLS interface configuration\n"
7651 + "remote LDP port\n") {
7652 + struct interface *ifp = vty->index;
7653 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7654 + struct ldp_interface *li = mi->ldp;
7655 + struct mpls *mpls = mi->mpls;
7656 + struct ldp *ldp = mpls->ldp;
7658 + li->entity.remote_udp_port = LDP_ENTITY_DEF_REMOTE_UDP;
7659 + if (!ldp) {
7660 + li->create_on_hold = MPLS_BOOL_TRUE;
7661 + return CMD_SUCCESS;
7664 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REMOTE_UDP);
7665 + return CMD_SUCCESS;
7668 +DEFUN(ldp_if_max_pdu,
7669 + ldp_if_max_pdu_cmd,
7670 + "max-pdu <64-9182>",
7671 + "MPLS interface configuration\n"
7672 + "maximum LDP PDU size\n"
7673 + "PDU size\n") {
7674 + struct interface *ifp = vty->index;
7675 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7676 + struct ldp_interface *li = mi->ldp;
7677 + struct mpls *mpls = mi->mpls;
7678 + struct ldp *ldp = mpls->ldp;
7680 + li->entity.max_pdu = atoi(argv[0]);
7681 + if (!ldp) {
7682 + li->create_on_hold = MPLS_BOOL_TRUE;
7683 + return CMD_SUCCESS;
7686 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_MAX_PDU);
7687 + return CMD_SUCCESS;
7690 +DEFUN(no_ldp_if_max_pdu,
7691 + no_ldp_if_max_pdu_cmd,
7692 + "no max-pdu",
7693 + NO_STR
7694 + "MPLS interface configuration\n"
7695 + "maximum LDP pdu size\n") {
7696 + struct interface *ifp = vty->index;
7697 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7698 + struct ldp_interface *li = mi->ldp;
7699 + struct mpls *mpls = mi->mpls;
7700 + struct ldp *ldp = mpls->ldp;
7702 + li->entity.max_pdu = LDP_ENTITY_DEF_MAX_PDU;
7703 + if (!ldp) {
7704 + li->create_on_hold = MPLS_BOOL_TRUE;
7705 + return CMD_SUCCESS;
7708 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_MAX_PDU);
7709 + return CMD_SUCCESS;
7712 +DEFUN(ldp_if_hello_interval,
7713 + ldp_if_hello_interval_cmd,
7714 + "hello-interval <1-60>",
7715 + "MPLS interface configuration\n"
7716 + "hello interval\n"
7717 + "interval in seconds\n") {
7718 + struct interface *ifp = vty->index;
7719 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7720 + struct ldp_interface *li = mi->ldp;
7721 + struct mpls *mpls = mi->mpls;
7722 + struct ldp *ldp = mpls->ldp;
7724 + li->entity.hellotime_interval = atoi(argv[0]);
7725 + if (!ldp) {
7726 + li->create_on_hold = MPLS_BOOL_TRUE;
7727 + return CMD_SUCCESS;
7730 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_HELLOTIME_INTERVAL);
7731 + return CMD_SUCCESS;
7734 +DEFUN(no_ldp_if_hello_interval,
7735 + no_ldp_if_hello_interval_cmd,
7736 + "no hello-interval",
7737 + NO_STR
7738 + "MPLS interface configuration\n"
7739 + "hello interval\n") {
7740 + struct interface *ifp = vty->index;
7741 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7742 + struct ldp_interface *li = mi->ldp;
7743 + struct mpls *mpls = mi->mpls;
7744 + struct ldp *ldp = mpls->ldp;
7746 + li->entity.hellotime_interval = LDP_ENTITY_DEF_HELLOTIME_INTERVAL;
7747 + if (!ldp) {
7748 + li->create_on_hold = MPLS_BOOL_TRUE;
7749 + return CMD_SUCCESS;
7752 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_HELLOTIME_INTERVAL);
7753 + return CMD_SUCCESS;
7756 +DEFUN(ldp_if_keepalive_interval,
7757 + ldp_if_keepalive_interval_cmd,
7758 + "keepalive-interval <1-60>",
7759 + "MPLS interface configuration\n"
7760 + "keepalive interval\n"
7761 + "interval in seconds\n") {
7762 + struct interface *ifp = vty->index;
7763 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7764 + struct ldp_interface *li = mi->ldp;
7765 + struct mpls *mpls = mi->mpls;
7766 + struct ldp *ldp = mpls->ldp;
7768 + li->entity.keepalive_interval = atoi(argv[0]);
7769 + if (!ldp) {
7770 + li->create_on_hold = MPLS_BOOL_TRUE;
7771 + return CMD_SUCCESS;
7774 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_KEEPALIVE_INTERVAL);
7775 + return CMD_SUCCESS;
7778 +DEFUN(no_ldp_if_keepalive_interval,
7779 + no_ldp_if_keepalive_interval_cmd,
7780 + "no keepalive-interval",
7781 + NO_STR
7782 + "MPLS interface configuration\n"
7783 + "keepalive interval\n") {
7784 + struct interface *ifp = vty->index;
7785 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7786 + struct ldp_interface *li = mi->ldp;
7787 + struct mpls *mpls = mi->mpls;
7788 + struct ldp *ldp = mpls->ldp;
7790 + li->entity.keepalive_interval = LDP_ENTITY_DEF_KEEPALIVE_INTERVAL;
7791 + if (!ldp) {
7792 + li->create_on_hold = MPLS_BOOL_TRUE;
7793 + return CMD_SUCCESS;
7796 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_KEEPALIVE_INTERVAL);
7797 + return CMD_SUCCESS;
7800 +DEFUN(ldp_if_max_session_attempt,
7801 + ldp_if_max_session_attempt_cmd,
7802 + "max-session-attempt <0-1024>",
7803 + "MPLS interface configuration\n"
7804 + "maximum LDP session setup attempt\n"
7805 + "Number of attempts (0 means keep trying)\n") {
7806 + struct interface *ifp = vty->index;
7807 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7808 + struct ldp_interface *li = mi->ldp;
7809 + struct mpls *mpls = mi->mpls;
7810 + struct ldp *ldp = mpls->ldp;
7812 + li->entity.session_setup_count = atoi(argv[0]);
7813 + if (!ldp) {
7814 + li->create_on_hold = MPLS_BOOL_TRUE;
7815 + return CMD_SUCCESS;
7818 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_SESSION_SETUP_COUNT);
7819 + return CMD_SUCCESS;
7822 +DEFUN(no_ldp_if_max_session_attempt,
7823 + no_ldp_if_max_session_attempt_cmd,
7824 + "no max-session-attempt\n",
7825 + NO_STR
7826 + "MPLS interface configuration\n"
7827 + "maximum LDP session setup attempt\n") {
7828 + struct interface *ifp = vty->index;
7829 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7830 + struct ldp_interface *li = mi->ldp;
7831 + struct mpls *mpls = mi->mpls;
7832 + struct ldp *ldp = mpls->ldp;
7834 + li->entity.session_setup_count = LDP_ENTITY_DEF_SESSIONSETUP_COUNT;
7835 + if (!ldp) {
7836 + li->create_on_hold = MPLS_BOOL_TRUE;
7837 + return CMD_SUCCESS;
7840 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_SESSION_SETUP_COUNT);
7841 + return CMD_SUCCESS;
7844 +DEFUN(ldp_if_max_path_vector,
7845 + ldp_if_max_path_vector_cmd,
7846 + "max-path-vector <1-255>",
7847 + "MPLS interface configuration\n"
7848 + "maximum path vector\n"
7849 + "number of entries\n") {
7850 + struct interface *ifp = vty->index;
7851 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7852 + struct ldp_interface *li = mi->ldp;
7853 + struct mpls *mpls = mi->mpls;
7854 + struct ldp *ldp = mpls->ldp;
7856 + li->entity.path_vector_limit = atoi(argv[0]);
7857 + if (!ldp) {
7858 + li->create_on_hold = MPLS_BOOL_TRUE;
7859 + return CMD_SUCCESS;
7862 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_PATHVECTOR_LIMIT);
7863 + return CMD_SUCCESS;
7866 +DEFUN(no_ldp_if_max_path_vector,
7867 + no_ldp_if_max_path_vector_cmd,
7868 + "no max-path-vector",
7869 + NO_STR
7870 + "MPLS interface configuration\n"
7871 + "maximum path vector\n") {
7872 + struct interface *ifp = vty->index;
7873 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7874 + struct ldp_interface *li = mi->ldp;
7875 + struct mpls *mpls = mi->mpls;
7876 + struct ldp *ldp = mpls->ldp;
7878 + li->entity.path_vector_limit = LDP_ENTITY_DEF_PATHVECTOR_LIMIT;
7879 + if (!ldp) {
7880 + li->create_on_hold = MPLS_BOOL_TRUE;
7881 + return CMD_SUCCESS;
7884 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_PATHVECTOR_LIMIT);
7885 + return CMD_SUCCESS;
7888 +DEFUN(ldp_if_max_hop_count,
7889 + ldp_if_max_hop_count_cmd,
7890 + "max-hop-count <1-1024>",
7891 + "MPLS interface configuration\n"
7892 + "maximum hop count\n"
7893 + "number of hops\n") {
7894 + struct interface *ifp = vty->index;
7895 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7896 + struct ldp_interface *li = mi->ldp;
7897 + struct mpls *mpls = mi->mpls;
7898 + struct ldp *ldp = mpls->ldp;
7900 + li->entity.hop_count_limit = atoi(argv[0]);
7901 + if (!ldp) {
7902 + li->create_on_hold = MPLS_BOOL_TRUE;
7903 + return CMD_SUCCESS;
7906 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_HOPCOUNT_LIMIT);
7907 + return CMD_SUCCESS;
7910 +DEFUN(no_ldp_if_max_hop_count,
7911 + no_ldp_if_max_hop_count_cmd,
7912 + "no max-hop-count",
7913 + NO_STR
7914 + "MPLS interface configuration\n"
7915 + "maximum hop count\n") {
7916 + struct interface *ifp = vty->index;
7917 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7918 + struct ldp_interface *li = mi->ldp;
7919 + struct mpls *mpls = mi->mpls;
7920 + struct ldp *ldp = mpls->ldp;
7922 + li->entity.hop_count_limit = LDP_ENTITY_DEF_HOPCOUNT_LIMIT;
7923 + if (!ldp) {
7924 + li->create_on_hold = MPLS_BOOL_TRUE;
7925 + return CMD_SUCCESS;
7928 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_HOPCOUNT_LIMIT);
7929 + return CMD_SUCCESS;
7932 +DEFUN(ldp_if_max_label_requests,
7933 + ldp_if_max_label_requests_cmd,
7934 + "max-label-requests <0-1024>",
7935 + "MPLS interface configuration\n"
7936 + "maximum times to make a request for a FEC\n"
7937 + "Number of attempts (0 means keep trying)\n") {
7938 + struct interface *ifp = vty->index;
7939 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7940 + struct ldp_interface *li = mi->ldp;
7941 + struct mpls *mpls = mi->mpls;
7942 + struct ldp *ldp = mpls->ldp;
7944 + li->entity.label_request_count = atoi(argv[0]);
7945 + if (!ldp) {
7946 + li->create_on_hold = MPLS_BOOL_TRUE;
7947 + return CMD_SUCCESS;
7950 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REQUEST_COUNT);
7951 + return CMD_SUCCESS;
7954 +DEFUN(no_ldp_if_max_label_requests,
7955 + no_ldp_if_max_label_requests_cmd,
7956 + "no max-label-requests",
7957 + NO_STR
7958 + "MPLS interface configuration\n"
7959 + "maximum times to make a request for a FEC\n") {
7960 + struct interface *ifp = vty->index;
7961 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7962 + struct ldp_interface *li = mi->ldp;
7963 + struct mpls *mpls = mi->mpls;
7964 + struct ldp *ldp = mpls->ldp;
7966 + li->entity.label_request_count = LDP_ENTITY_DEF_REQUEST_COUNT;
7967 + if (!ldp) {
7968 + li->create_on_hold = MPLS_BOOL_TRUE;
7969 + return CMD_SUCCESS;
7972 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REQUEST_COUNT);
7973 + return CMD_SUCCESS;
7976 +#if 0
7977 +DEFUN(ldp_if_ttl_less_domain,
7978 + ldp_if_ttl_less_domain_cmd,
7979 + "ttl-less-domain",
7980 + "MPLS interface configuration\n"
7981 + "TTL less domain\n") {
7982 + struct interface *ifp = vty->index;
7983 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7984 + struct ldp_interface *li = mi->ldp;
7985 + struct mpls *mpls = mi->mpls;
7986 + struct ldp *ldp = mpls->ldp;
7988 + li->entity.remote_in_ttl_less_domain = MPLS_BOOL_TRUE;
7989 + if (!ldp) {
7990 + li->create_on_hold = MPLS_BOOL_TRUE;
7991 + return CMD_SUCCESS;
7994 + return CMD_SUCCESS;
7997 +DEFUN(no_ldp_if_ttl_less_domain,
7998 + no_ldp_if_ttl_less_domain_cmd,
7999 + "no ttl-less-domain",
8000 + NO_STR
8001 + "MPLS interface configuration\n"
8002 + "TTL less domain\n") {
8003 + struct interface *ifp = vty->index;
8004 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
8005 + struct ldp_interface *li = mi->ldp;
8006 + struct mpls *mpls = mi->mpls;
8007 + struct ldp *ldp = mpls->ldp;
8009 + li->entity.remote_in_ttl_less_domain = MPLS_BOOL_FALSE;
8010 + if (!ldp) {
8011 + return CMD_SUCCESS;
8014 + return CMD_SUCCESS;
8016 +#endif
8018 +static int ldp_if_config_write (struct vty *vty) {
8019 + return 0;
8022 +static int ldp_config_write (struct vty *vty) {
8023 + struct mpls *mpls = mpls_get();
8024 + struct ldp *ldp = mpls->ldp;
8025 + ldp_global g;
8026 + int write = 0;
8028 + if (ldp) {
8029 + vty_out (vty, "!%s", VTY_NEWLINE);
8030 + vty_out (vty, "mpls ldp%s", VTY_NEWLINE);
8031 + write++;
8033 + if (ldp_traceflags & LDP_TRACE_FLAG_ADDRESS)
8034 + vty_out (vty, " trace address%s", VTY_NEWLINE);
8035 + if (ldp_traceflags & LDP_TRACE_FLAG_BINDING)
8036 + vty_out (vty, " trace binding%s", VTY_NEWLINE);
8037 + if (ldp_traceflags & LDP_TRACE_FLAG_DEBUG)
8038 + vty_out (vty, " trace debug%s", VTY_NEWLINE);
8039 + if (ldp_traceflags & LDP_TRACE_FLAG_ERROR)
8040 + vty_out (vty, " trace error%s", VTY_NEWLINE);
8041 + if (ldp_traceflags & LDP_TRACE_FLAG_EVENT)
8042 + vty_out (vty, " trace event%s", VTY_NEWLINE);
8043 + if (ldp_traceflags & LDP_TRACE_FLAG_GENERAL)
8044 + vty_out (vty, " trace general%s", VTY_NEWLINE);
8045 + if (ldp_traceflags & LDP_TRACE_FLAG_INIT)
8046 + vty_out (vty, " trace init%s", VTY_NEWLINE);
8047 + if (ldp_traceflags & LDP_TRACE_FLAG_LABEL)
8048 + vty_out (vty, " trace label%s", VTY_NEWLINE);
8049 + if (ldp_traceflags & LDP_TRACE_FLAG_NORMAL)
8050 + vty_out (vty, " trace normal%s", VTY_NEWLINE);
8051 + if (ldp_traceflags & LDP_TRACE_FLAG_NOTIF)
8052 + vty_out (vty, " trace notification%s", VTY_NEWLINE);
8053 + if (ldp_traceflags & LDP_TRACE_FLAG_PACKET_DUMP)
8054 + vty_out (vty, " trace packet-dump%s", VTY_NEWLINE);
8055 + if (ldp_traceflags & LDP_TRACE_FLAG_PACKET)
8056 + vty_out (vty, " trace packet%s", VTY_NEWLINE);
8057 + if (ldp_traceflags & LDP_TRACE_FLAG_PATH)
8058 + vty_out (vty, " trace path%s", VTY_NEWLINE);
8059 + if (ldp_traceflags & LDP_TRACE_FLAG_PERIODIC)
8060 + vty_out (vty, " trace periodic%s", VTY_NEWLINE);
8061 + if (ldp_traceflags & LDP_TRACE_FLAG_POLICY)
8062 + vty_out (vty, " trace policy%s", VTY_NEWLINE);
8063 + if (ldp_traceflags & LDP_TRACE_FLAG_ROUTE)
8064 + vty_out (vty, " trace route%s", VTY_NEWLINE);
8065 + if (ldp_traceflags & LDP_TRACE_FLAG_STATE)
8066 + vty_out (vty, " trace state%s", VTY_NEWLINE);
8067 + if (ldp_traceflags & LDP_TRACE_FLAG_TASK)
8068 + vty_out (vty, " trace task%s", VTY_NEWLINE);
8069 + if (ldp_traceflags & LDP_TRACE_FLAG_TIMER)
8070 + vty_out (vty, " trace timer%s", VTY_NEWLINE);
8072 + ldp_cfg_global_get(ldp->h,&g, 0xFFFFFFFF);
8074 + if (g.lsp_control_mode != LDP_GLOBAL_DEF_CONTROL_MODE) {
8075 + vty_out (vty, " lsp-control-mode ");
8076 + if (g.lsp_control_mode == LDP_CONTROL_INDEPENDENT) {
8077 + vty_out (vty, "independent%s", VTY_NEWLINE);
8078 + } else {
8079 + vty_out (vty, "ordered%s", VTY_NEWLINE);
8082 + if (g.label_retention_mode != LDP_GLOBAL_DEF_RETENTION_MODE) {
8083 + vty_out (vty, " label-retention-mode ");
8084 + if (g.label_retention_mode == LDP_RETENTION_LIBERAL) {
8085 + vty_out (vty, "liberal%s", VTY_NEWLINE);
8086 + } else {
8087 + vty_out (vty, "conservative%s", VTY_NEWLINE);
8090 + if (g.lsp_repair_mode != LDP_GLOBAL_DEF_REPAIR_MODE) {
8091 + vty_out (vty, " lsp-repair-mode ");
8092 + if (g.lsp_repair_mode == LDP_REPAIR_LOCAL) {
8093 + vty_out (vty, "local%s", VTY_NEWLINE);
8094 + } else {
8095 + vty_out (vty, "global%s", VTY_NEWLINE);
8098 + if (g.propagate_release != LDP_GLOBAL_DEF_PROPOGATE_RELEASE) {
8099 + if (g.propagate_release == MPLS_BOOL_TRUE) {
8100 + vty_out (vty, " propagate-release%s", VTY_NEWLINE);
8101 + } else {
8102 + vty_out (vty, " no propagate-release%s", VTY_NEWLINE);
8105 + if (g.label_merge != LDP_GLOBAL_DEF_LABEL_MERGE) {
8106 + if (g.label_merge == MPLS_BOOL_TRUE) {
8107 + vty_out (vty, " label-merge%s", VTY_NEWLINE);
8108 + } else {
8109 + vty_out (vty, " no label-merge%s", VTY_NEWLINE);
8112 + if (g.loop_detection_mode != LDP_GLOBAL_DEF_LOOP_DETECTION_MODE) {
8113 + if (g.loop_detection_mode == LDP_LOOP_HOPCOUNT) {
8114 + vty_out (vty, " loop-detection-mode hop%s", VTY_NEWLINE);
8115 + } else if (g.loop_detection_mode == LDP_LOOP_PATHVECTOR) {
8116 + vty_out (vty, " loop-detection-mode path%s", VTY_NEWLINE);
8117 + } else if (g.loop_detection_mode == LDP_LOOP_HOPCOUNT_PATHVECTOR) {
8118 + vty_out (vty, " loop-detection-mode both%s", VTY_NEWLINE);
8119 + } else {
8120 + vty_out (vty, " no loop-detection-mode%s", VTY_NEWLINE);
8123 + if (g.ttl_less_domain != MPLS_BOOL_FALSE) {
8124 + vty_out (vty, " ttl-less-domain%s", VTY_NEWLINE);
8126 + if (g.local_tcp_port != LDP_GLOBAL_DEF_LOCAL_TCP_PORT) {
8127 + vty_out (vty, " local-tcp-port %d%s", g.local_tcp_port, VTY_NEWLINE);
8129 + if (g.local_udp_port != LDP_GLOBAL_DEF_LOCAL_UDP_PORT) {
8130 + vty_out (vty, " local-udp-port %d%s", g.local_udp_port, VTY_NEWLINE);
8133 + switch (ldp->egress) {
8134 + case LDP_EGRESS_LSRID:
8135 + vty_out (vty, " egress lsr-id%s", VTY_NEWLINE);
8136 + break;
8137 + case LDP_EGRESS_CONNECTED:
8138 + vty_out (vty, " egress connected%s", VTY_NEWLINE);
8139 + break;
8140 + default:
8143 + switch (ldp->address) {
8144 + case LDP_ADDRESS_LSRID:
8145 + vty_out (vty, " address-mode lsr-id%s", VTY_NEWLINE);
8146 + break;
8147 + case LDP_ADDRESS_LDP:
8148 + vty_out (vty, " address-mode ldp%s", VTY_NEWLINE);
8149 + break;
8150 + default:
8153 + return write;
8156 +int ldp_interface_config_write(struct vty *vty, struct mpls_interface *mi) {
8157 + struct ldp_interface *li;
8158 + struct mpls *mpls;
8159 + struct ldp *ldp;
8160 + ldp_entity e;
8161 + int write = 0;
8163 + if (mi && mi->ldp) {
8164 + li = mi->ldp;
8165 + mpls = mi->mpls;
8166 + ldp = mpls->ldp;
8168 + if (li->entity.index) {
8169 + e.index = li->entity.index;
8170 + ldp_cfg_entity_get(ldp->h, &e, 0xFFFFFFFF);
8171 + } else {
8172 + memcpy(&e,&li->entity,sizeof(ldp_entity));
8175 + vty_out(vty, " mpls ldp%s", VTY_NEWLINE);
8176 + write++;
8178 + if (e.label_distribution_mode != LDP_ENTITY_DEF_DISTRIBUTION_MODE) {
8179 + vty_out(vty, " distribution-mode ");
8180 + if (e.label_distribution_mode == LDP_DISTRIBUTION_ONDEMAND) {
8181 + vty_out(vty, "dod%s", VTY_NEWLINE);
8182 + } else {
8183 + vty_out(vty, "du%s", VTY_NEWLINE);
8186 + if (e.remote_tcp_port != LDP_ENTITY_DEF_REMOTE_TCP) {
8187 + vty_out(vty, " remote-tcp-port %d%s", e.remote_tcp_port,
8188 + VTY_NEWLINE);
8190 + if (e.remote_udp_port != LDP_ENTITY_DEF_REMOTE_UDP) {
8191 + vty_out(vty, " remote-udp-port %d%s", e.remote_udp_port,
8192 + VTY_NEWLINE);
8194 + if (e.max_pdu != LDP_ENTITY_DEF_MAX_PDU) {
8195 + vty_out(vty, " max-pdu %d%s", e.max_pdu, VTY_NEWLINE);
8197 + if (e.hellotime_interval != LDP_ENTITY_DEF_HELLOTIME_INTERVAL) {
8198 + vty_out(vty, " hello-interval %d%s", e.hellotime_interval,
8199 + VTY_NEWLINE);
8201 + if (e.keepalive_interval != LDP_ENTITY_DEF_KEEPALIVE_INTERVAL) {
8202 + vty_out(vty, " keepalive-interval %d%s",
8203 + e.keepalive_interval, VTY_NEWLINE);
8205 + if (e.session_setup_count != LDP_ENTITY_DEF_SESSIONSETUP_COUNT) {
8206 + vty_out(vty, " max-session-attempt %d%s",
8207 + e.session_setup_count, VTY_NEWLINE);
8209 + if (e.path_vector_limit != LDP_ENTITY_DEF_PATHVECTOR_LIMIT) {
8210 + vty_out(vty, " max-path-vector %d%s",
8211 + e.path_vector_limit, VTY_NEWLINE);
8213 + if (e.hop_count_limit != LDP_ENTITY_DEF_HOPCOUNT_LIMIT) {
8214 + vty_out(vty, " max-hop-count %d%s",
8215 + e.hop_count_limit, VTY_NEWLINE);
8217 + if (e.label_request_count != LDP_ENTITY_DEF_REQUEST_COUNT) {
8218 + vty_out(vty, " max-label-requests %d%s",
8219 + e.label_request_count, VTY_NEWLINE);
8221 + vty_out(vty, " !%s",VTY_NEWLINE);
8224 + return write;
8227 +void ldp_vty_show_init() {
8229 + install_element(VIEW_NODE, &mpls_show_ldp_cmd);
8230 + install_element(ENABLE_NODE, &mpls_show_ldp_cmd);
8232 + install_element(VIEW_NODE, &mpls_show_ldp_neighbor_cmd);
8233 + install_element(ENABLE_NODE, &mpls_show_ldp_neighbor_cmd);
8235 + install_element(VIEW_NODE, &mpls_show_ldp_session_cmd);
8236 + install_element(ENABLE_NODE, &mpls_show_ldp_session_cmd);
8238 + install_element(VIEW_NODE, &mpls_show_ldp_discovery_cmd);
8239 + install_element(ENABLE_NODE, &mpls_show_ldp_discovery_cmd);
8241 + install_element(VIEW_NODE, &mpls_show_ldp_database_cmd);
8242 + install_element(ENABLE_NODE, &mpls_show_ldp_database_cmd);
8245 +static struct cmd_node ldp_if_node = {MPLS_LDP_IF_NODE,"%s(config-if-ldp)# ",1};
8247 +void ldp_vty_if_init() {
8249 + install_node (&ldp_if_node, ldp_if_config_write);
8250 + install_default (MPLS_LDP_IF_NODE);
8252 + install_element(INTERFACE_NODE,&ldp_intf_cmd);
8253 + install_element(INTERFACE_NODE,&no_ldp_intf_cmd);
8255 + install_element(MPLS_LDP_IF_NODE,&ldp_if_remote_tcp_port_cmd);
8256 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_remote_tcp_port_cmd);
8258 + install_element(MPLS_LDP_IF_NODE,&ldp_if_remote_udp_port_cmd);
8259 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_remote_udp_port_cmd);
8261 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_pdu_cmd);
8262 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_pdu_cmd);
8264 + install_element(MPLS_LDP_IF_NODE,&ldp_if_hello_interval_cmd);
8265 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_hello_interval_cmd);
8267 + install_element(MPLS_LDP_IF_NODE,&ldp_if_keepalive_interval_cmd);
8268 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_keepalive_interval_cmd);
8270 +#if 0
8271 + install_element(MPLS_LDP_IF_NODE,&ldp_if_loop_detect_mode_cmd);
8272 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_loop_detect_mode_cmd);
8273 +#endif
8275 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_session_attempt_cmd);
8276 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_session_attempt_cmd);
8278 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_path_vector_cmd);
8279 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_path_vector_cmd);
8281 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_hop_count_cmd);
8282 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_hop_count_cmd);
8284 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_label_requests_cmd);
8285 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_label_requests_cmd);
8287 + install_element(MPLS_LDP_IF_NODE,&ldp_if_distribution_mode_cmd);
8288 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_distribution_mode_cmd);
8290 +#if 0
8291 + install_element(MPLS_LDP_IF_NODE,&ldp_if_ttl_less_domain_cmd);
8292 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_ttl_less_domain_cmd);
8293 +#endif
8296 +static struct cmd_node ldp_node = {MPLS_LDP_NODE,"%s(config-ldp)# ",1};
8298 +void ldp_vty_init () {
8300 + install_node (&ldp_node, ldp_config_write);
8301 + install_default (MPLS_LDP_NODE);
8303 + install_element (CONFIG_NODE, &mpls_ldp_cmd);
8304 + install_element (CONFIG_NODE, &no_mpls_ldp_cmd);
8306 + install_element (MPLS_LDP_NODE, &mpls_ldp_disable_cmd);
8307 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_disable_cmd);
8309 + install_element (MPLS_LDP_NODE, &mpls_ldp_lsrid_cmd);
8310 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_lsrid_cmd);
8312 + install_element (MPLS_LDP_NODE, &mpls_ldp_lsp_control_mode_cmd);
8313 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_lsp_control_mode_cmd);
8315 + install_element (MPLS_LDP_NODE, &mpls_ldp_label_retention_mode_cmd);
8316 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_label_retention_mode_cmd);
8318 + install_element (MPLS_LDP_NODE, &mpls_ldp_lsp_repair_mode_cmd);
8319 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_lsp_repair_mode_cmd);
8321 + install_element (MPLS_LDP_NODE, &mpls_ldp_propogate_release_cmd);
8322 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_propogate_release_cmd);
8324 + install_element (MPLS_LDP_NODE, &mpls_ldp_label_merge_cmd);
8325 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_label_merge_cmd);
8327 + install_element (MPLS_LDP_NODE, &mpls_ldp_loop_detection_mode_cmd);
8328 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_loop_detection_mode_cmd);
8330 + install_element (MPLS_LDP_NODE, &mpls_ldp_ttl_less_domain_cmd);
8331 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_ttl_less_domain_cmd);
8333 + install_element (MPLS_LDP_NODE, &mpls_ldp_local_tcp_port_cmd);
8334 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_local_tcp_port_cmd);
8336 + install_element (MPLS_LDP_NODE, &mpls_ldp_local_udp_port_cmd);
8337 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_local_udp_port_cmd);
8339 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_address_cmd);
8340 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_binding_cmd);
8341 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_debug_cmd);
8342 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_error_cmd);
8343 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_event_cmd);
8344 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_general_cmd);
8345 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_init_cmd);
8346 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_label_cmd);
8347 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_normal_cmd);
8348 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_notif_cmd);
8349 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_packet_dump_cmd);
8350 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_packet_cmd);
8351 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_path_cmd);
8352 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_periodic_cmd);
8353 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_policy_cmd);
8354 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_route_cmd);
8355 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_state_cmd);
8356 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_task_cmd);
8357 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_timer_cmd);
8358 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_all_cmd);
8359 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_none_cmd);
8361 + install_element (MPLS_LDP_NODE, &mpls_ldp_egress_cmd);
8362 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_egress_cmd);
8363 + install_element (MPLS_LDP_NODE, &mpls_ldp_address_cmd);
8364 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_address_cmd);
8366 diff -uNr --exclude=CVS zebra/mplsd/ldp_vty.h zebra-ldp/mplsd/ldp_vty.h
8367 --- zebra/mplsd/ldp_vty.h Wed Dec 31 19:00:00 1969
8368 +++ zebra-ldp/mplsd/ldp_vty.h Thu Oct 10 21:56:22 2002
8369 @@ -0,0 +1,11 @@
8370 +#ifndef LDP_VTY_H
8371 +#define LDP_VTY_H
8373 +#include "mpls_interface.h"
8375 +int ldp_interface_config_write(struct vty *vty, struct mpls_interface *mi);
8376 +void ldp_vty_show_init();
8377 +void ldp_vty_if_init();
8378 +void ldp_vty_init();
8380 +#endif
8381 diff -uNr --exclude=CVS zebra/mplsd/lsr_handle_type.h zebra-ldp/mplsd/lsr_handle_type.h
8382 --- zebra/mplsd/lsr_handle_type.h Wed Dec 31 19:00:00 1969
8383 +++ zebra-ldp/mplsd/lsr_handle_type.h Sun Nov 3 13:01:05 2002
8384 @@ -0,0 +1,18 @@
8385 +#ifndef _LSR_HANDLE_TYPE_H_
8386 +#define _LSR_HANDLE_TYPE_H_
8388 +#if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0))
8389 +#if 0
8390 +typedef unsigned char uint8_t;
8391 +typedef unsigned short uint16_t;
8392 +typedef unsigned int uint32_t;
8393 +#endif
8394 +#else
8395 +#include <stdint.h>
8396 +#endif
8398 +typedef int lsr_insegment_handle;
8399 +typedef int lsr_outsegment_handle;
8400 +typedef int lsr_xconnect_handle;
8402 +#endif
8403 diff -uNr --exclude=CVS zebra/mplsd/mpls.c zebra-ldp/mplsd/mpls.c
8404 --- zebra/mplsd/mpls.c Wed Dec 31 19:00:00 1969
8405 +++ zebra-ldp/mplsd/mpls.c Wed Nov 20 18:33:36 2002
8406 @@ -0,0 +1,79 @@
8407 +#include <zebra.h>
8409 +#include "thread.h"
8410 +#include "memory.h"
8411 +#include "prefix.h"
8412 +#include "rib.h"
8413 +#include "linklist.h"
8414 +#include "filter.h"
8415 +#include "vty.h"
8416 +#include "plist.h"
8418 +#include "mpls.h"
8419 +#include "ldp.h"
8420 +#include "static.h"
8421 +#include "lsr_cfg.h"
8423 +/* MPLS instance top. */
8424 +struct mpls *mpls_top = NULL;
8426 +struct mpls *mpls_new() {
8427 + lsr_global global;
8428 + struct mpls *new = XMALLOC(MTYPE_MPLS_TOP, sizeof (struct mpls));
8430 + memset(new,0,sizeof(*new));
8432 + new->h = lsr_cfg_open(new);
8433 + global.admin_state = MPLS_ADMIN_ENABLE;
8434 + lsr_cfg_global_set(new->h, &global, LSR_GLOBAL_CFG_ADMIN_STATE);
8436 + new->router_id.family = AF_INET;
8437 + new->router_id.prefixlen = 32;
8439 + new->iflist = iflist;
8440 + new->rib = rib_table_ipv4;
8442 + return new;
8445 +struct mpls *mpls_get() {
8446 + if (mpls_top) {
8447 + return mpls_top;
8450 + mpls_top = mpls_new();
8451 + return mpls_top;
8454 +void mpls_finish(struct mpls *mpls) {
8456 + lsr_global global;
8458 + ldp_finish(mpls->ldp);
8459 + static_finish(mpls->mstatic);
8461 + global.admin_state = MPLS_ADMIN_DISABLE;
8462 + lsr_cfg_global_set(mpls->h, &global, LSR_GLOBAL_CFG_ADMIN_STATE);
8463 + lsr_cfg_close(mpls->h);
8465 + XFREE(MTYPE_MPLS_TOP, mpls);
8466 + mpls_top = NULL;
8469 +/* Update access-list list. */
8470 +void mpls_access_list_update(struct access_list *access) {
8473 +/* Update prefix-list list. */
8474 +void mpls_prefix_list_update(struct prefix_list *plist) {
8477 +void mpls_init() {
8478 + rib_init();
8480 +#if 0
8481 + access_list_init();
8482 + access_list_add_hook(mpls_access_list_update);
8483 + access_list_delete_hook(mpls_access_list_update);
8484 +#endif
8486 diff -uNr --exclude=CVS zebra/mplsd/mpls.h zebra-ldp/mplsd/mpls.h
8487 --- zebra/mplsd/mpls.h Wed Dec 31 19:00:00 1969
8488 +++ zebra-ldp/mplsd/mpls.h Wed Nov 20 18:26:59 2002
8489 @@ -0,0 +1,42 @@
8490 +#ifndef _MPLSD_H
8491 +#define _MPLSD_H
8493 +#include "sockunion.h"
8494 +#include "prefix.h"
8495 +#include "zclient.h"
8496 +#include "linklist.h"
8497 +#include "if.h"
8499 +#include "ldp.h"
8500 +#include "static.h"
8502 +#define MPLS_DEFAULT_CONFIG "mplsd.conf"
8504 +#define MPLS_VTY_PORT 2610
8505 +#define MPLS_VTYSH_PATH "/tmp/.mplsd"
8507 +enum mplsd_instr_types {
8508 + MPLS_FWD = 1,
8509 + MPLS_PUSH,
8510 + MPLS_SET
8513 +struct mplsd_set {
8514 + char ifname[INTERFACE_NAMSIZ + 1];
8515 + union sockunion nexthop;
8518 +struct mpls {
8519 + list iflist;
8520 + list miflist;
8521 + mpls_cfg_handle h;
8522 + struct rib_table *rib;
8523 + struct ldp *ldp;
8524 + struct mpls_static *mstatic;
8525 + struct prefix router_id;
8528 +void mpls_init();
8529 +struct mpls *mpls_get();
8531 +#endif
8532 diff -uNr --exclude=CVS zebra/mplsd/mpls_handle_type.h zebra-ldp/mplsd/mpls_handle_type.h
8533 --- zebra/mplsd/mpls_handle_type.h Wed Dec 31 19:00:00 1969
8534 +++ zebra-ldp/mplsd/mpls_handle_type.h Thu Nov 21 23:07:06 2002
8535 @@ -0,0 +1,47 @@
8536 +#ifndef _LDP_HANDLE_TYPE_H_
8537 +#define _LDP_HANDLE_TYPE_H_
8539 +#define MPLS_USE_LSR 1
8541 +#if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0))
8542 +#if 0
8543 +typedef unsigned char uint8_t;
8544 +typedef unsigned short uint16_t;
8545 +typedef unsigned int uint32_t;
8546 +#endif
8547 +#else
8548 +#include <stdint.h>
8549 +#endif
8551 +#include <zebra.h>
8552 +#include "rib.h"
8553 +#include "if.h"
8555 +struct ldp;
8556 +struct ldp_timer;
8557 +struct ldp_socket;
8559 +typedef void *mpls_tree_handle;
8560 +typedef void *mpls_instance_handle;
8561 +typedef struct rib_table* mpls_fib_handle;
8562 +typedef struct route_table* mpls_ifmgr_handle;
8563 +typedef struct interface* mpls_if_handle;
8564 +typedef struct mpls_timer* mpls_timer_handle;
8565 +typedef struct mpls_socket* mpls_socket_handle;
8566 +typedef int mpls_socket_mgr_handle;
8567 +typedef int mpls_mpls_handle;
8568 +typedef int mpls_outlabel_handle;
8569 +typedef int mpls_insegment_handle;
8570 +typedef int mpls_outsegment_handle;
8571 +typedef int mpls_xconnect_handle;
8573 +typedef int *mpls_lock_handle;
8574 +typedef int mpls_timer_mgr_handle;
8575 +typedef int mpls_tunnel_handle;
8576 +typedef int mpls_policy_handle;
8577 +typedef int mpls_trace_handle;
8579 +typedef char *mpls_lock_key_type;
8580 +typedef int mpls_size_type;
8582 +#endif
8583 diff -uNr --exclude=CVS zebra/mplsd/mpls_interface.c zebra-ldp/mplsd/mpls_interface.c
8584 --- zebra/mplsd/mpls_interface.c Wed Dec 31 19:00:00 1969
8585 +++ zebra-ldp/mplsd/mpls_interface.c Mon Nov 18 21:18:15 2002
8586 @@ -0,0 +1,68 @@
8587 +#include <zebra.h>
8589 +#include "if.h"
8590 +#include "memory.h"
8592 +#include "mpls.h"
8593 +#include "mpls_interface.h"
8595 +struct mpls_interface *mpls_if_new(struct interface *ifp) {
8596 + struct mpls_interface *mi;
8597 + struct mpls *mpls = mpls_get();
8599 + mi = XMALLOC(MTYPE_MPLS_IF, sizeof(struct mpls_interface));
8600 + memset(mi, 0, sizeof(struct mpls_interface));
8602 + /* Set zebra interface pointer. */
8603 + mi->ifp = ifp;
8604 + mi->labelspace = -1;
8606 + mi->mpls = mpls;
8607 + return mi;
8610 +void mpls_if_free(struct mpls_interface *mi) {
8612 + listnode_delete(mi->mpls->miflist, mi);
8613 + XFREE(MTYPE_MPLS_IF, mi);
8616 +int mpls_if_is_up(struct mpls_interface *mi) {
8617 + return if_is_up(mi->ifp);
8620 +int mpls_if_new_hook(struct interface *ifp) {
8621 + ifp->info = mpls_if_new(ifp);
8622 + return 0;
8625 +int mpls_if_delete_hook(struct interface *ifp) {
8626 + mpls_if_free(ifp->info);
8627 + ifp->info = NULL;
8628 + return 0;
8631 +int mpls_if_up(struct mpls_interface *mi) {
8632 + if (!mi) {
8633 + return 0;
8635 + ldp_if_up(mi);
8636 + //static_if_up(mi);
8637 + return 1;
8640 +int mpls_if_down(struct mpls_interface *mi) {
8641 + if (!mi) {
8642 + return 0;
8644 + ldp_if_down(mi);
8645 + //static_if_down(mi);
8646 + return 1;
8649 +void mpls_if_init() {
8650 + /* Initialize Zebra interface data structure. */
8651 + if_init();
8652 + if_add_hook(IF_NEW_HOOK, mpls_if_new_hook);
8653 + if_add_hook(IF_DELETE_HOOK, mpls_if_delete_hook);
8655 diff -uNr --exclude=CVS zebra/mplsd/mpls_interface.h zebra-ldp/mplsd/mpls_interface.h
8656 --- zebra/mplsd/mpls_interface.h Wed Dec 31 19:00:00 1969
8657 +++ zebra-ldp/mplsd/mpls_interface.h Fri Oct 11 13:35:48 2002
8658 @@ -0,0 +1,34 @@
8659 +#ifndef MPLS_INTERFACE_H
8660 +#define MPLS_INTERFACE_H
8662 +#include <zebra.h>
8664 +#include "if.h"
8665 +#include "command.h"
8666 +#include "prefix.h"
8667 +#include "zclient.h"
8669 +#include "ldp.h"
8670 +#include "ldp_struct.h"
8671 +#include "ldp_interface.h"
8673 +struct mpls_interface {
8674 + struct mpls *mpls;
8676 + struct interface *ifp;
8677 + int labelspace;
8679 + struct connected *connected;
8681 + struct ldp_interface *ldp;
8682 +// struct static_interface static;
8685 +struct mpls_interface *mpls_if_new();
8686 +void mpls_if_free(struct mpls_interface *);
8687 +int mpls_if_is_up(struct mpls_interface *);
8688 +int mpls_if_up(struct mpls_interface *mi);
8689 +int mpls_if_down(struct mpls_interface *mi);
8690 +void mpls_if_init();
8692 +#endif
8693 diff -uNr --exclude=CVS zebra/mplsd/mpls_main.c zebra-ldp/mplsd/mpls_main.c
8694 --- zebra/mplsd/mpls_main.c Wed Dec 31 19:00:00 1969
8695 +++ zebra-ldp/mplsd/mpls_main.c Fri Oct 11 19:08:53 2002
8696 @@ -0,0 +1,229 @@
8697 +#include <zebra.h>
8699 +#include "version.h"
8700 +#include "getopt.h"
8701 +#include "command.h"
8702 +#include "thread.h"
8703 +#include "filter.h"
8704 +#include "memory.h"
8705 +#include "prefix.h"
8706 +#include "log.h"
8708 +#include "mpls.h"
8709 +#include "mpls_vty.h"
8710 +#include "mpls_zebra.h"
8711 +#include "mpls_interface.h"
8713 +/* Configuration filename and directory. */
8714 +char config_current[] = MPLS_DEFAULT_CONFIG;
8715 +char config_default[] = SYSCONFDIR MPLS_DEFAULT_CONFIG;
8717 +/* Command line options. */
8718 +struct option longopts[] =
8720 + { "daemon", no_argument, NULL, 'd'},
8721 + { "config_file", required_argument, NULL, 'f'},
8722 + { "log_mode", no_argument, NULL, 'l'},
8723 + { "help", no_argument, NULL, 'h'},
8724 + { "vty_port", required_argument, NULL, 'P'},
8725 + { "vty_addr", required_argument, NULL, 'A'},
8726 + { "version", no_argument, NULL, 'v'},
8727 + { 0 }
8730 +/* Master of threads. */
8731 +struct thread_master *master = NULL;
8733 +/* Process ID saved for use by init system */
8734 +char *pid_file = PATH_MPLSD_PID;
8736 +/* Help information display. */
8737 +static void
8738 +usage (char *progname, int status)
8740 + if (status != 0)
8741 + fprintf (stderr, "Try `%s --help' for more information.\n", progname);
8742 + else
8743 + {
8744 + printf ("Usage : %s [OPTION...]\n\n\
8745 +Daemon which manages MPLS related configuration.\n\n\
8746 +-d, --daemon Runs in daemon mode\n\
8747 +-f, --config_file Set configuration file name\n\
8748 +-l, --log_mode Set verbose log mode flag\n\
8749 +-h, --help Display this help and exit\n\
8750 +-P, --vty_port Set vty's port number\n\
8751 +-A, --vty_addr Set vty's bind address\n\
8752 +-v, --version Print program version\n\
8753 +\n\
8754 +Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
8757 + exit (status);
8760 +/* SIGHUP handler. */
8761 +void
8762 +sighup (int sig)
8764 + zlog_info ("SIGHUP received");
8766 + /* Reload of config file. */
8770 +/* SIGINT handler. */
8771 +void
8772 +sigint (int sig)
8774 + zlog_info ("Terminating on signal");
8776 + exit (0);
8779 +/* SIGUSR1 handler. */
8780 +void
8781 +sigusr1 (int sig)
8783 + zlog_rotate (NULL);
8786 +/* Signale wrapper. */
8787 +RETSIGTYPE *
8788 +signal_set (int signo, void (*func)(int))
8790 + int ret;
8791 + struct sigaction sig;
8792 + struct sigaction osig;
8794 + sig.sa_handler = func;
8795 + sigemptyset (&sig.sa_mask);
8796 + sig.sa_flags = 0;
8797 +#ifdef SA_RESTART
8798 + sig.sa_flags |= SA_RESTART;
8799 +#endif /* SA_RESTART */
8801 + ret = sigaction (signo, &sig, &osig);
8803 + if (ret < 0)
8804 + return (SIG_ERR);
8805 + else
8806 + return (osig.sa_handler);
8809 +/* Initialization of signal handles. */
8810 +void
8811 +signal_init ()
8813 + signal_set (SIGHUP, sighup);
8814 + signal_set (SIGINT, sigint);
8815 + signal_set (SIGTERM, sigint);
8816 + signal_set (SIGPIPE, SIG_IGN);
8817 + signal_set (SIGUSR1, sigusr1);
8820 +/* Main startup routine. */
8821 +int
8822 +main (int argc, char **argv)
8824 + char *p;
8825 + int vty_port = 0;
8826 + char *vty_addr = NULL;
8827 + int daemon_mode = 0;
8828 + char *config_file = NULL;
8829 + char *progname;
8830 + struct thread thread;
8831 + void rib_weed_tables ();
8833 + /* Set umask before anything for security */
8834 + umask (0027);
8836 + /* preserve my name */
8837 + progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
8839 + zlog_default = openzlog (progname, ZLOG_STDOUT, ZLOG_MPLS,
8840 + LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
8842 + while (1)
8844 + int opt;
8846 + opt = getopt_long (argc, argv, "bdklf:hP:rv", longopts, 0);
8848 + if (opt == EOF)
8849 + break;
8851 + switch (opt)
8853 + case 0:
8854 + break;
8855 + case 'd':
8856 + daemon_mode = 1;
8857 + break;
8858 + case 'l':
8859 + /* log_mode = 1; */
8860 + break;
8861 + case 'f':
8862 + config_file = optarg;
8863 + break;
8864 + case 'A':
8865 + vty_addr = optarg;
8866 + break;
8867 + case 'P':
8868 + vty_port = atoi (optarg);
8869 + break;
8870 + case 'v':
8871 + print_version (progname);
8872 + exit (0);
8873 + break;
8874 + case 'h':
8875 + usage (progname, 0);
8876 + break;
8877 + default:
8878 + usage (progname, 1);
8879 + break;
8883 + /* Make master thread emulator. */
8884 + master = thread_master_create();
8886 + /* Vty related initialize. */
8887 + signal_init();
8888 + cmd_init(1);
8889 + vty_init();
8890 + memory_init();
8892 + /* MPLSs inits */
8893 + mpls_init();
8894 + mpls_if_init();
8895 + mpls_vty_init();
8896 + mpls_vty_show_init();
8897 + mpls_zebra_init();
8899 + sort_node();
8901 + /* Configuration file read*/
8902 + vty_read_config(config_file, config_current, config_default);
8904 + /* Daemonize. */
8905 + if (daemon_mode) {
8906 + daemon(0, 0);
8909 + /* Output pid of zebra. */
8910 + pid_output(pid_file);
8912 + /* Create VTY socket */
8913 + vty_serv_sock(vty_addr,
8914 + vty_port ? vty_port : MPLS_VTY_PORT, MPLS_VTYSH_PATH);
8916 + /* Print banner. */
8917 + zlog(NULL, LOG_INFO, "MPLSd (%s) starts", ZEBRA_VERSION);
8919 + while(thread_fetch(master, &thread)) {
8920 + thread_call(&thread);
8923 + /* Not reached... */
8924 + exit (0);
8926 diff -uNr --exclude=CVS zebra/mplsd/mpls_trace.h zebra-ldp/mplsd/mpls_trace.h
8927 --- zebra/mplsd/mpls_trace.h Wed Dec 31 19:00:00 1969
8928 +++ zebra-ldp/mplsd/mpls_trace.h Thu Oct 24 12:51:17 2002
8929 @@ -0,0 +1,61 @@
8930 +#ifndef _LDP_TRACE_H_
8931 +#define _LDP_TRACE_H_
8933 +#include <stdio.h>
8934 +#include "ldp_struct.h"
8936 +extern uint32_t ldp_traceflags;
8937 +extern uint8_t trace_buffer[16834];
8938 +extern int trace_buffer_len;
8940 +#if 0
8941 +1 2 3 4 5 6 7 8
8942 + 12345678901234567890123456789012345678901234567890123456789012345678901234567890
8943 +#endif
8944 +#define LDP_TRACE_OUT(handle,args...) { \
8945 + if(trace_buffer_len == 0) { \
8946 + trace_buffer_len += sprintf(trace_buffer,"OUT: " args);\
8947 + } else { \
8948 + trace_buffer_len += sprintf(trace_buffer+trace_buffer_len,args);\
8949 + } \
8950 + if(trace_buffer[strlen(trace_buffer)-1] == '\n') { \
8951 + fprintf(stderr,"%s",trace_buffer); \
8952 + trace_buffer_len = 0; \
8953 + } \
8955 +#define LDP_TRACE_LOG(handle,class,type,args...) { \
8956 + if(type & ldp_traceflags) { \
8957 + LDP_TRACE_OUT(handle,args); \
8958 + } \
8960 +#define LDP_TRACE_PKT(handle,class,type,header,body) { \
8961 + if(type & ldp_traceflags) { \
8962 + header; \
8963 + body; \
8964 + } \
8966 +#define LDP_DUMP_PKT(handle,class,type,func) { \
8967 + if(type & ldp_traceflags) { \
8968 + func; \
8969 + } \
8971 +#define LDP_PRINT(data,args...) { \
8972 + if(ldp_traceflags & LDP_TRACE_FLAG_DEBUG) { \
8973 + fprintf(stderr, "PRT: " args); \
8974 + fprintf(stderr, "\n"); \
8975 + } \
8977 +#define LDP_ENTER(data,args...) { \
8978 + if(ldp_traceflags & LDP_TRACE_FLAG_DEBUG) { \
8979 + fprintf(stderr, "ENTER: " args); \
8980 + fprintf(stderr, "\n"); \
8981 + } \
8983 +#define LDP_EXIT(data,args...) { \
8984 + if(ldp_traceflags & LDP_TRACE_FLAG_DEBUG) { \
8985 + fprintf(stderr, "EXIT: " args); \
8986 + fprintf(stderr, "\n"); \
8987 + } \
8990 +#endif
8991 diff -uNr --exclude=CVS zebra/mplsd/mpls_vty.c zebra-ldp/mplsd/mpls_vty.c
8992 --- zebra/mplsd/mpls_vty.c Wed Dec 31 19:00:00 1969
8993 +++ zebra-ldp/mplsd/mpls_vty.c Wed Nov 20 18:34:05 2002
8994 @@ -0,0 +1,154 @@
8995 +#include <zebra.h>
8997 +#include "vty.h"
8998 +#include "command.h"
8999 +#include "rib.h"
9001 +#include "mpls.h"
9002 +#include "mpls_interface.h"
9004 +#include "ldp.h"
9005 +#include "ldp_cfg.h"
9006 +#include "ldp_vty.h"
9007 +#include "ldp_interface.h"
9008 +#include "static_vty.h"
9010 +#include "impl_mpls.h"
9012 +DEFUN (mpls_show_lsr_id, mpls_show_lsr_id_cmd,
9013 + "show lsr-id",
9014 + SHOW_STR
9015 + "LSR identifier\n") {
9017 + struct mpls *mpls = mpls_get();
9019 + vty_out(vty, "lsr-id: %s%s", inet_ntoa(mpls->router_id.u.prefix4),
9020 + VTY_NEWLINE);
9021 + return CMD_SUCCESS;
9024 +DEFUN(interface_mpls_labelspace,
9025 + interface_mpls_labelspace_cmd,
9026 + "mpls labelspace <1-255>",
9027 + "MPLS interface configuration\n"
9028 + "labelspace\n"
9029 + "labelspace number\n") {
9030 + struct interface *ifp = vty->index;
9031 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
9032 + struct mpls *mpls = mpls_get();
9033 + struct mpls_range range;
9035 + if ((range.label_space = atoi(argv[0])) < 0) {
9036 + return CMD_WARNING;
9039 + mi->labelspace = range.label_space;
9040 + do_mpls_labelspace(mi);
9042 + if (mpls->ldp && mi->ldp && mi->ldp->entity.index) {
9043 + ldp_interface_admin_state_start(mi);
9044 + mi->ldp->iff.label_space = mi->labelspace;
9045 + ldp_cfg_if_set(mpls->ldp->h, &mi->ldp->iff, LDP_IF_CFG_LABEL_SPACE);
9046 + ldp_interface_admin_state_finish(mi);
9049 + return CMD_SUCCESS;
9052 +DEFUN(no_interface_mpls_labelspace,
9053 + no_interface_mpls_labelspace_cmd,
9054 + "no mpls labelspace",
9055 + NO_STR
9056 + "MPLS interface configuration\n"
9057 + "labelspace\n") {
9058 + struct interface *ifp = vty->index;
9059 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
9060 + struct mpls *mpls = mpls_get();
9062 + mi->labelspace = 0;
9063 + do_mpls_labelspace(mi);
9065 + if (mpls->ldp && mi->ldp && mi->ldp->entity.index) {
9066 + ldp_interface_admin_state_start(mi);
9067 + mi->ldp->iff.label_space = mi->labelspace;
9068 + ldp_cfg_if_set(mpls->ldp->h, &mi->ldp->iff, LDP_IF_CFG_LABEL_SPACE);
9069 + ldp_interface_admin_state_finish(mi);
9071 + return CMD_SUCCESS;
9074 +int mpls_interface_config_write(struct vty *vty) {
9075 + listnode node;
9076 + struct interface *ifp;
9077 + struct mpls_interface *mi;
9078 + struct mpls *mpls = mpls_get();
9080 + for (node = listhead(mpls->iflist); node; nextnode(node)) {
9081 + ifp = getdata(node);
9083 + vty_out(vty, "interface %s%s", ifp->name, VTY_NEWLINE);
9085 + if (ifp->desc) {
9086 + vty_out(vty, " description %s%s", ifp->desc, VTY_NEWLINE);
9089 + if ((mi = (struct mpls_interface*)ifp->info)) {
9090 + if (mi->labelspace > -1) {
9091 + vty_out(vty, " mpls labelspace %d%s", mi->labelspace, VTY_NEWLINE);
9092 + } else {
9093 + vty_out(vty, " no mpls labelspace%s", VTY_NEWLINE);
9095 + ldp_interface_config_write(vty, mi);
9097 + vty_out(vty, "!%s", VTY_NEWLINE);
9099 + return 0;
9102 +void mpls_vty_show_init () {
9104 + install_element(VIEW_NODE, &mpls_show_lsr_id_cmd);
9105 + install_element(ENABLE_NODE, &mpls_show_lsr_id_cmd);
9107 + install_element (VIEW_NODE, &show_ip_route_cmd);
9108 + install_element (VIEW_NODE, &show_ip_route_addr_cmd);
9109 + install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
9110 + install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
9111 + install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
9112 + install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
9113 + install_element (ENABLE_NODE, &show_ip_route_cmd);
9114 + install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
9115 + install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
9116 + install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
9117 + install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
9118 + install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
9120 + ldp_vty_show_init();
9121 + static_vty_show_init();
9124 +struct cmd_node interface_node = { INTERFACE_NODE, "%s(config-if)# ", 1, };
9126 +void mpls_vty_if_init() {
9128 + install_node(&interface_node, mpls_interface_config_write);
9130 + install_element(CONFIG_NODE, &interface_cmd);
9131 + install_default(INTERFACE_NODE);
9133 + install_element(INTERFACE_NODE,&interface_desc_cmd);
9134 + install_element(INTERFACE_NODE,&no_interface_desc_cmd);
9136 + install_element(INTERFACE_NODE,&interface_mpls_labelspace_cmd);
9137 + install_element(INTERFACE_NODE,&no_interface_mpls_labelspace_cmd);
9139 + ldp_vty_if_init();
9142 +void mpls_vty_init () {
9144 + ldp_vty_init();
9145 + static_vty_init();
9146 + mpls_vty_if_init();
9149 diff -uNr --exclude=CVS zebra/mplsd/mpls_vty.h zebra-ldp/mplsd/mpls_vty.h
9150 --- zebra/mplsd/mpls_vty.h Wed Dec 31 19:00:00 1969
9151 +++ zebra-ldp/mplsd/mpls_vty.h Wed Nov 20 20:11:59 2002
9152 @@ -0,0 +1,40 @@
9153 +#ifndef ZEBRA_MPLS_VTY_H
9154 +#define ZEBRA_MPLS_VTY_H
9156 +#define VTY_GET_UINT32(NAME,V,STR) \
9157 +{ \
9158 + char *endptr = NULL; \
9159 + (V) = strtoul ((STR), &endptr, 10); \
9160 + if (*endptr != '\0' || ((V) == ULONG_MAX && errno == ERANGE)) \
9161 + { \
9162 + vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
9163 + return CMD_WARNING; \
9164 + } \
9167 +#define VTY_GET_UINT32_RANGE(NAME,V,STR,IMIN,IMAX) \
9168 +{ \
9169 + VTY_GET_UINT32(NAME,V,STR); \
9170 + if (((V) < IMIN) || ((V) > IMAX)) \
9171 + { \
9172 + vty_out (vty, "%% Invalid %s value. Valid range is (%d ... %d)%s", \
9173 + NAME, IMIN, IMAX, VTY_NEWLINE); \
9174 + return CMD_WARNING; \
9175 + } \
9178 +#define VTY_GET_IPV4_ADDRESS(NAME,V,STR) \
9179 +{ \
9180 + int retv; \
9181 + retv = inet_aton ((STR), &(V)); \
9182 + if (!retv) \
9183 + { \
9184 + vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
9185 + return CMD_WARNING; \
9186 + } \
9189 +void mpls_vty_init();
9190 +void mpls_vty_show_init();
9192 +#endif
9193 diff -uNr --exclude=CVS zebra/mplsd/mpls_zebra.c zebra-ldp/mplsd/mpls_zebra.c
9194 --- zebra/mplsd/mpls_zebra.c Wed Dec 31 19:00:00 1969
9195 +++ zebra-ldp/mplsd/mpls_zebra.c Sun Nov 24 22:34:29 2002
9196 @@ -0,0 +1,378 @@
9197 +#include <zebra.h>
9199 +#include "command.h"
9200 +#include "prefix.h"
9201 +#include "stream.h"
9202 +#include "table.h"
9203 +#include "memory.h"
9204 +#include "zclient.h"
9205 +#include "log.h"
9207 +#include "ldp.h"
9208 +#include "mpls_interface.h"
9209 +#include "impl_fib.h"
9210 +#include "impl_ifmgr.h"
9211 +#include "impl_mpls.h"
9213 +/* All information about zebra. */
9214 +struct zclient *zclient = NULL;
9216 +/* For registering threads. */
9217 +extern struct thread_master *master;
9219 +/* Router-id update message from zebra. */
9220 +int mpls_router_id_update_zebra(int command, struct zclient *zclient,
9221 + zebra_size_t length) {
9222 + struct mpls *mpls = mpls_get();
9224 + zebra_router_id_update_read(zclient->ibuf,&mpls->router_id);
9226 + zlog_info("router-id change %s",
9227 + inet_ntoa(mpls->router_id.u.prefix4));
9229 + if (mpls && mpls->ldp) {
9230 + ldp_router_id_update(mpls->ldp, &mpls->router_id);
9232 + return 0;
9235 +/* Inteface addition message from zebra. */
9236 +int mpls_interface_add(int command, struct zclient *zclient,
9237 + zebra_size_t length) {
9238 + struct interface *ifp;
9239 + struct mpls_interface *mi;
9241 + if (!(ifp = zebra_interface_add_read(zclient->ibuf))) {
9242 + return 1;
9245 + mi = (struct mpls_interface*)ifp->info;
9246 + if (mi && mi->ldp) {
9247 + /* Initialize labelspace to kernel */
9248 + /* If the labelspace has been set yet via the CLI */
9249 + /* the result will be that the kernel labelspace will */
9250 + /* be un-set, which doesn't hurt anything */
9251 + do_mpls_labelspace(mi);
9254 + zlog_info("interface add %s index %d flags %ld metric %d mtu %d",
9255 + ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
9257 + return 0;
9260 +int mpls_interface_delete(int command, struct zclient *zclient,
9261 + zebra_size_t length) {
9262 + struct interface *ifp;
9263 + struct stream *s;
9265 + s = zclient->ibuf;
9266 + /* zebra_interface_state_read() updates interface structure in iflist */
9267 + ifp = zebra_interface_state_read(s);
9269 + if (ifp == NULL) {
9270 + return 0;
9273 + if (if_is_up(ifp)) {
9274 + zlog_warn("got delete of %s, but interface is still up",
9275 + ifp->name);
9278 + zlog_info("interface delete %s index %d flags %ld metric %d mtu %d", ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
9280 + if_delete(ifp);
9282 + return 0;
9285 +struct interface * zebra_interface_if_lookup(struct stream *s) {
9286 + struct interface *ifp;
9287 + u_char ifname_tmp[INTERFACE_NAMSIZ];
9289 + /* Read interface name. */
9290 + stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
9292 + /* Lookup this by interface index. */
9293 + ifp = if_lookup_by_name(ifname_tmp);
9295 + /* If such interface does not exist, indicate an error */
9296 + if (!ifp) {
9297 + return NULL;
9300 + return ifp;
9303 +int mpls_interface_state_up(int command, struct zclient *zclient,
9304 + zebra_size_t length) {
9305 + struct interface *ifp;
9306 + struct interface if_tmp;
9308 + ifp = zebra_interface_if_lookup(zclient->ibuf);
9309 + if (ifp == NULL) {
9310 + return 0;
9313 + /* Interface is already up. */
9314 + if (if_is_up (ifp)) {
9315 + /* Temporarily keep ifp values. */
9316 + memcpy (&if_tmp, ifp, sizeof (struct interface));
9318 + zebra_interface_if_set_value (zclient->ibuf, ifp);
9320 + zlog_info ("Interface[%s] state update.", ifp->name);
9322 + return 0;
9325 + zebra_interface_if_set_value(zclient->ibuf, ifp);
9327 + zlog_info ("Interface[%s] state change to up.", ifp->name);
9329 + mpls_if_up(ifp->info);
9331 + return 0;
9334 +int mpls_interface_state_down(int command, struct zclient *zclient,
9335 + zebra_size_t length) {
9336 + struct interface *ifp;
9338 + ifp = zebra_interface_state_read (zclient->ibuf);
9339 + if (ifp == NULL) {
9340 + return 0;
9343 + zlog_info ("Interface[%s] state change to down.", ifp->name);
9345 + mpls_if_down(ifp->info);
9347 + return 0;
9350 +int mpls_interface_address_add(int command, struct zclient *zclient,
9351 + zebra_size_t length) {
9352 + struct mpls *mpls = mpls_get();
9353 + struct connected *c;
9354 + struct interface *ifp;
9355 + struct prefix *p;
9357 + c = zebra_interface_address_add_read(zclient->ibuf);
9358 + if (c == NULL) {
9359 + return 0;
9362 + ifp = c->ifp;
9363 + p = c->address;
9365 + zlog_info("address add %s to interface %s",inet_ntoa(p->u.prefix4),
9366 + ifp->name);
9368 + if (mpls->ldp) {
9369 + ldp_address_add_callback(mpls, c);
9372 + return 0;
9375 +int mpls_interface_address_delete(int command, struct zclient *zclient,
9376 + zebra_size_t length) {
9377 + struct mpls *mpls = mpls_get();
9378 + struct connected *c;
9379 + struct interface *ifp;
9380 + struct prefix *p;
9382 + c = zebra_interface_address_delete_read(zclient->ibuf);
9383 + if (c == NULL) {
9384 + return 0;
9387 + ifp = c->ifp;
9388 + p = c->address;
9390 + zlog_info("address delete %s from interface %s",
9391 + inet_ntoa(p->u.prefix4), ifp->name);
9393 + if (mpls->ldp) {
9394 + ldp_address_delete_callback(mpls, c);
9397 + connected_free(c);
9399 + return 0;
9402 +void mpls_zread_ipv4_add(struct zclient *client, u_short length) {
9403 + struct mpls *mpls = mpls_get();
9404 + struct rib *rib;
9405 + struct prefix_ipv4 p;
9406 + u_char message;
9407 + int nexthop_num;
9408 + int ifindex_num;
9409 + struct nexthop nexthop;
9410 + struct stream *s;
9412 + /* Get input stream. */
9413 + s = client->ibuf;
9414 + memset(&nexthop,0,sizeof(nexthop));
9416 + /* Allocate new rib. */
9417 + rib = XMALLOC(MTYPE_MPLS_RIB, sizeof(struct rib));
9418 + memset(rib, 0, sizeof(struct rib));
9420 + /* Type, flags, message. */
9421 + rib->type = stream_getc(s);
9422 + rib->flags = stream_getc(s);
9423 + message = stream_getc(s);
9424 + rib->rib_table = mpls->rib;
9425 + rib->uptime = time(NULL);
9427 + /* IPv4 prefix. */
9428 + memset (&p, 0, sizeof(struct prefix_ipv4));
9429 + p.family = AF_INET;
9430 + p.prefixlen = stream_getc(s);
9431 + stream_get(&p.prefix, s, PSIZE (p.prefixlen));
9433 + zlog_info("router add %s/%d", inet_ntoa(p.prefix), p.prefixlen);
9435 + /* Nexthop parse. */
9436 + if (CHECK_FLAG(message, ZAPI_MESSAGE_NEXTHOP)) {
9437 + nexthop_num = stream_getc(s);
9438 + nexthop.gate.ipv4.s_addr = stream_get_ipv4(s);
9439 + zlog_info("\tnexthop %s", inet_ntoa(nexthop.gate.ipv4));
9441 + if (CHECK_FLAG(message, ZAPI_MESSAGE_IFINDEX)) {
9442 + ifindex_num = stream_getc(s);
9443 + nexthop.ifindex = stream_getl(s);
9444 + zlog_info("\tifindex %d", nexthop.ifindex);
9446 + if (CHECK_FLAG(message, ZAPI_MESSAGE_IFINDEX) &&
9447 + CHECK_FLAG(message, ZAPI_MESSAGE_NEXTHOP) &&
9448 + nexthop.gate.ipv4.s_addr) {
9449 + nexthop.type = NEXTHOP_TYPE_IPV4_IFINDEX;
9450 + nexthop_ipv4_ifindex_add(rib, &nexthop.gate.ipv4, nexthop.ifindex);
9451 + } else if (CHECK_FLAG(message, ZAPI_MESSAGE_NEXTHOP) &&
9452 + nexthop.gate.ipv4.s_addr) {
9453 + nexthop.type = NEXTHOP_TYPE_IPV4;
9454 + nexthop_ipv4_add(rib, &nexthop.gate.ipv4);
9455 + } else if (CHECK_FLAG(message, ZAPI_MESSAGE_IFINDEX)) {
9456 + nexthop.type = NEXTHOP_TYPE_IFINDEX;
9457 + nexthop_ifindex_add(rib, nexthop.ifindex);
9458 + } else {
9459 + fprintf(stderr,"Invalid nexthop\n");
9462 + /* Distance. */
9463 + if (CHECK_FLAG(message, ZAPI_MESSAGE_DISTANCE)) {
9464 + rib->distance = stream_getc (s);
9467 + /* Metric. */
9468 + if (CHECK_FLAG(message, ZAPI_MESSAGE_METRIC)) {
9469 + rib->metric = stream_getl (s);
9472 + rib_add_ipv4_multipath(&p, rib);
9474 + /* ldp stuff */
9475 + ldp_ipv4_add(mpls, rib->type, &p, &nexthop);
9478 +void mpls_zread_ipv4_delete(struct zclient *client, u_short length) {
9479 + struct mpls *mpls = mpls_get();
9480 + struct stream *s;
9481 + struct zapi_ipv4 api;
9482 + struct nexthop nexthop;
9483 + struct prefix_ipv4 p;
9485 + memset(&api,0,sizeof(api));
9487 + s = client->ibuf;
9488 + memset(&nexthop,0,sizeof(nexthop));
9490 + /* Type, flags, message. */
9491 + api.type = stream_getc(s);
9492 + api.flags = stream_getc(s);
9493 + api.message = stream_getc(s);
9495 + /* IPv4 prefix. */
9496 + memset (&p, 0, sizeof(struct prefix_ipv4));
9497 + p.family = AF_INET;
9498 + p.prefixlen = stream_getc (s);
9499 + stream_get(&p.prefix, s, PSIZE(p.prefixlen));
9501 + zlog_info("router delete %s/%d", inet_ntoa(p.prefix), p.prefixlen);
9503 + /* Nexthop, ifindex, distance, metric. */
9504 + if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) {
9505 + api.nexthop_num = stream_getc(s);
9506 + nexthop.gate.ipv4.s_addr = stream_get_ipv4(s);
9507 + zlog_info("\tnexthop %s", inet_ntoa(nexthop.gate.ipv4));
9510 + if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) {
9511 + api.ifindex_num = stream_getc(s);
9512 + nexthop.ifindex = stream_getl(s);
9513 + zlog_info("\tifindex %d", nexthop.ifindex);
9516 + if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) &&
9517 + CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) &&
9518 + nexthop.gate.ipv4.s_addr) {
9519 + nexthop.type = NEXTHOP_TYPE_IPV4_IFINDEX;
9520 + } else if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) &&
9521 + nexthop.gate.ipv4.s_addr) {
9522 + nexthop.type = NEXTHOP_TYPE_IPV4;
9523 + } else if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) {
9524 + nexthop.type = NEXTHOP_TYPE_IFINDEX;
9525 + } else {
9526 + fprintf(stderr,"Invalid nexthop\n");
9529 + /* Distance. */
9530 + if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE))
9531 + api.distance = stream_getc(s);
9533 + /* Metric. */
9534 + if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC)) {
9535 + api.metric = stream_getl(s);
9538 + rib_delete_ipv4(api.type, api.flags, &p, &nexthop.gate.ipv4,
9539 + nexthop.ifindex, 0);
9541 + /* ldp stuff */
9542 + ldp_ipv4_delete(mpls, api.type, &p, &nexthop);
9545 +int mpls_zebra_read_ipv4(int command, struct zclient *client,
9546 + zebra_size_t length) {
9548 + if (command == ZEBRA_IPV4_ROUTE_ADD) {
9549 + mpls_zread_ipv4_add(client, length);
9550 + } else {
9551 + mpls_zread_ipv4_delete(client, length);
9553 + return 0;
9556 +void mpls_zebra_init() {
9557 + int i;
9559 + /* Allocate zebra structure. */
9560 + zclient = zclient_new();
9561 + zclient_init(zclient, ZEBRA_ROUTE_MPLS);
9562 + for (i = 0;i < ZEBRA_ROUTE_MAX;i++) {
9563 + zclient->redist[i] = 1;
9565 + zclient->router_id_update = mpls_router_id_update_zebra;
9566 + zclient->interface_add = mpls_interface_add;
9567 + zclient->interface_delete = mpls_interface_delete;
9568 + zclient->interface_up = mpls_interface_state_up;
9569 + zclient->interface_down = mpls_interface_state_down;
9570 + zclient->interface_address_add = mpls_interface_address_add;
9571 + zclient->interface_address_delete = mpls_interface_address_delete;
9572 + zclient->ipv4_route_add = mpls_zebra_read_ipv4;
9573 + zclient->ipv4_route_delete = mpls_zebra_read_ipv4;
9575 diff -uNr --exclude=CVS zebra/mplsd/mpls_zebra.h zebra-ldp/mplsd/mpls_zebra.h
9576 --- zebra/mplsd/mpls_zebra.h Wed Dec 31 19:00:00 1969
9577 +++ zebra-ldp/mplsd/mpls_zebra.h Thu Oct 10 21:58:56 2002
9578 @@ -0,0 +1,6 @@
9579 +#ifndef _ZEBRA_MPLS_ZEBRA_H
9580 +#define _ZEBRA_MPLS_ZEBRA_H
9582 +void mpls_zebra_init();
9584 +#endif
9585 diff -uNr --exclude=CVS zebra/mplsd/mplsd.conf.sample zebra-ldp/mplsd/mplsd.conf.sample
9586 --- zebra/mplsd/mplsd.conf.sample Wed Dec 31 19:00:00 1969
9587 +++ zebra-ldp/mplsd/mplsd.conf.sample Sat Oct 12 12:42:37 2002
9588 @@ -0,0 +1,17 @@
9590 +! Zebra configuration saved from vty
9591 +! 2002/03/23 17:07:30
9593 +hostname uml-1
9594 +password root
9595 +enable password root
9597 +mpls ldp
9599 +interface lo
9601 +interface eth0
9602 + mpls ldp
9604 +line vty
9606 diff -uNr --exclude=CVS zebra/mplsd/static.c zebra-ldp/mplsd/static.c
9607 --- zebra/mplsd/static.c Wed Dec 31 19:00:00 1969
9608 +++ zebra-ldp/mplsd/static.c Wed Nov 20 20:32:57 2002
9609 @@ -0,0 +1,101 @@
9610 +#include <zebra.h>
9612 +#include "vty.h"
9613 +#include "command.h"
9614 +#include "memory.h"
9616 +#include "static.h"
9618 +static struct static_outsegment *static_outsegment_new(struct mpls_static *mstatic) {
9619 + struct static_outsegment *new = XMALLOC(MTYPE_MPLS_STATIC, sizeof(*new));
9620 + memset(new,0,sizeof(*new));
9621 + new->node.data = new;
9622 + new->mstatic = mstatic;
9623 + return new;
9626 +struct static_outsegment *static_outsegment_get(struct mpls_static *mstatic,
9627 + unsigned int index, char create) {
9628 + struct listnode *tmp;
9629 + struct static_outsegment *out;
9631 + LIST_LOOP(mstatic->outsegment,out,tmp) {
9632 + if (out->index == index) {
9633 + return out;
9637 + if (create) {
9638 + out = static_outsegment_new(mstatic);
9639 + out->index = index;
9640 + LISTNODE_ADD(mstatic->outsegment, &out->node);
9641 + return out;
9643 + return NULL;
9646 +void static_outsegment_finish(struct static_outsegment *out) {
9647 + LISTNODE_DELETE(out->mstatic->outsegment, &out->node);
9648 + XFREE(MTYPE_MPLS_STATIC,out);
9651 +static struct static_insegment *static_insegment_new(struct mpls_static *mstatic) {
9652 + struct static_insegment *new = XMALLOC(MTYPE_MPLS_STATIC, sizeof(*new));
9653 + memset(new,0,sizeof(*new));
9654 + new->node.data = new;
9655 + new->mstatic = mstatic;
9656 + return new;
9659 +struct static_insegment *static_insegment_get(struct mpls_static *mstatic,
9660 + unsigned int index, char create) {
9661 + struct listnode *tmp;
9662 + struct static_insegment *in;
9664 + LIST_LOOP(mstatic->insegment,in,tmp) {
9665 + if (in->index == index) {
9666 + return in;
9670 + if (create) {
9671 + in = static_insegment_new(mstatic);
9672 + in->index = index;
9673 + LISTNODE_ADD(mstatic->insegment, &in->node);
9674 + return in;
9676 + return NULL;
9679 +void static_insegment_finish(struct static_insegment *in) {
9680 + LISTNODE_DELETE(in->mstatic->insegment, &in->node);
9681 + XFREE(MTYPE_MPLS_STATIC,in);
9684 +static struct mpls_static *static_new(struct mpls *mpls) {
9685 + struct mpls_static *new = XMALLOC(MTYPE_MPLS_STATIC, sizeof(*new));
9687 + memset(new,0,sizeof(*new));
9688 + new->mpls = mpls;
9689 + new->outsegment = list_new();
9690 + new->insegment = list_new();
9692 + return new;
9695 +struct mpls_static *static_get() {
9696 + struct mpls *mpls = mpls_get();
9697 + if (mpls->mstatic) {
9698 + return mpls->mstatic;
9701 + mpls->mstatic = static_new(mpls);
9702 + return mpls->mstatic;
9705 +void static_finish(struct mpls_static *mstatic) {
9706 + struct mpls *mpls = mstatic->mpls;
9708 + XFREE(MTYPE_MPLS_STATIC,mstatic);
9709 + mpls->mstatic = NULL;
9711 diff -uNr --exclude=CVS zebra/mplsd/static.h zebra-ldp/mplsd/static.h
9712 --- zebra/mplsd/static.h Wed Dec 31 19:00:00 1969
9713 +++ zebra-ldp/mplsd/static.h Wed Nov 20 19:16:49 2002
9714 @@ -0,0 +1,42 @@
9715 +#ifndef STATIC_H
9716 +#define STATIC_H
9718 +#include <zebra.h>
9719 +#include "linklist.h"
9721 +#include "mpls.h"
9722 +#include "lsr_struct.h"
9724 +struct mpls_static {
9725 + struct mpls *mpls;
9726 + mpls_cfg_handle h;
9727 + struct list *insegment;
9728 + struct list *outsegment;
9731 +struct static_insegment {
9732 + struct listnode node;
9733 + struct mpls_static *mstatic;
9734 + unsigned int index;
9735 + lsr_insegment in;
9736 + lsr_xconnect xc;
9737 + unsigned int out_index;
9740 +struct static_outsegment {
9741 + struct listnode node;
9742 + struct mpls_static *mstatic;
9743 + unsigned int index;
9744 + lsr_outsegment out;
9747 +struct mpls_static *static_get();
9748 +void static_finish(struct mpls_static *mstatic);
9749 +struct static_outsegment *static_outsegment_get(struct mpls_static *mstatic,
9750 + unsigned int index, char create);
9751 +void static_outsegment_finish(struct static_outsegment *out);
9752 +struct static_insegment *static_insegment_get(struct mpls_static *mstatic,
9753 + unsigned int index, char create);
9754 +void static_insegment_finish(struct static_insegment *in);
9756 +#endif
9757 diff -uNr --exclude=CVS zebra/mplsd/static_tunnel.c zebra-ldp/mplsd/static_tunnel.c
9758 --- zebra/mplsd/static_tunnel.c Wed Dec 31 19:00:00 1969
9759 +++ zebra-ldp/mplsd/static_tunnel.c Wed Oct 9 18:18:24 2002
9760 @@ -0,0 +1,260 @@
9761 +#include <zebra.h>
9763 +#include "if.h"
9764 +#include "vty.h"
9765 +#include "command.h"
9766 +#include "memory.h"
9767 +#include "out-segment.h"
9769 +#include "tunnel.h"
9770 +#include "interface.h"
9771 +#include "utility.h"
9772 +#include <linux/mpls.h>
9774 +struct list *mplsd_tunnel_list;
9776 +struct mplsd_tunnel *mplsd_tunnel_lookup_by_name(char *name) {
9777 + listnode node;
9778 + struct mplsd_tunnel *ifp;
9780 + for (node = listhead(mplsd_tunnel_list); node; nextnode(node)) {
9781 + ifp = getdata(node);
9782 + if (strncmp(name, ifp->iff.name, sizeof(ifp->iff.name)) == 0) {
9783 + return ifp;
9786 + return NULL;
9789 +struct mplsd_tunnel *mplsd_tunnel_create(char *name, int mode) {
9790 + struct mplsd_tunnel *ifp;
9791 + struct ifreq ifr;
9792 + int result;
9794 + ifp = XMALLOC(MTYPE_MPLS_STATIC, sizeof(struct mplsd_tunnel));
9795 + if(!ifp) return NULL;
9796 + memset(ifp, 0, sizeof(struct mplsd_tunnel));
9798 + listnode_add(mplsd_tunnel_list, ifp);
9800 + strncpy(ifr.ifr_name,name,IFNAMSIZ);
9801 + if(mode) {
9802 + result = mplsd_ioctl(SIOCMPLSTUNNELADD, (caddr_t)&ifr);
9804 + result = mplsd_ioctl(SIOCGIFINDEX, (caddr_t)&ifr);
9805 + strncpy(ifp->iff.name, name, INTERFACE_NAMSIZ);
9806 + ifp->iff.ifindex = ifr.ifr_ifindex;
9807 + return ifp;
9810 +void mplsd_tunnel_delete(struct mplsd_tunnel *ifp, int mode) {
9812 + listnode_delete(mplsd_tunnel_list, ifp);
9814 + if (mode) {
9815 + struct ifreq ifr;
9816 + int result;
9818 + strncpy(ifr.ifr_name,ifp->iff.name,IFNAMSIZ);
9819 + result = mplsd_ioctl(SIOCMPLSTUNNELDEL, (caddr_t)&ifr);
9822 + XFREE(MTYPE_MPLS_STATIC, ifp);
9825 +DEFUN (mplsd_tunnel,
9826 + mplsd_tunnel_cmd,
9827 + "tunnel IFNAME",
9828 + "Create a pseudo tunnel\n"
9829 + "Tunnel's name\n") {
9830 + struct mplsd_interface_wait *wait;
9831 + struct interface *ifp;
9832 + struct mplsd_tunnel *tun;
9833 + int num;
9835 + if(sscanf(argv[0],"mpls%d",&num) != 1) {
9836 + vty_out (vty, "Tunnel names must be in the form 'mpls%%d'%s", VTY_NEWLINE);
9837 + return CMD_WARNING;
9840 + if (!(tun = mplsd_tunnel_lookup_by_name(argv[0]))) {
9841 + tun = mplsd_tunnel_create(argv[0], 1);
9843 + if (!(wait = mplsd_interface_wait_new())) {
9844 + vty_out(vty, "Unable to register for interface%s", VTY_NEWLINE);
9845 + return CMD_ERR_INCOMPLETE;
9848 + wait->data[0] = tun;
9849 + strncpy(wait->ifname, argv[0], INTERFACE_NAMSIZ);
9850 + tun->wait = wait;
9852 + if (!(ifp = if_lookup_by_name(argv[0]))) {
9853 +#if 0
9854 + wait->callback = mplsd_tunnel_callback_add;
9855 + mplsd_interface_add_wait_add(wait);
9856 +#endif
9857 + } else {
9858 +#if 0
9859 + wait->callback = mplsd_tunnel_callback_delete;
9860 + mplsd_interface_add_wait_del(wait);
9861 +#endif
9865 + vty->index = tun;
9866 + vty->node = MPLS_IF_NODE;
9868 + return CMD_SUCCESS;
9871 +DEFUN (no_mplsd_tunnel,
9872 + no_mplsd_tunnel_cmd,
9873 + "no tunnel IFNAME",
9874 + "Delete a pseudo tunnel's configuration\n"
9875 + "Tunnel's name\n") {
9876 + struct mplsd_tunnel *tun;
9878 + tun = mplsd_tunnel_lookup_by_name(argv[0]);
9879 + if (!tun) {
9880 + vty_out (vty, "Tunnel %s does not exist%s", argv[0], VTY_NEWLINE);
9881 + return CMD_WARNING;
9884 +#if 0
9885 + mplsd_interface_remove_wait_add(tun->wait);
9886 + mplsd_interface_remove_wait_del(tun->wait);
9887 +#endif
9889 + /* Delete tunnel */
9890 + mplsd_tunnel_delete(tun, 1);
9892 + return CMD_SUCCESS;
9895 +extern struct mplsd_static_info *mplsd_static_info;
9897 +DEFUN (mplsd_tunnel_out_segment,
9898 + mplsd_tunnel_out_segment_cmd,
9899 + "out-segment INDEX",
9900 + "Assign an out-segment to this tunnel\n"
9901 + "MPLS out-segment index\n") {
9903 + struct mplsd_out_segment *out_old;
9904 + struct mplsd_out_segment *out;
9905 + struct interface *tun;
9906 + struct mpls_label ml;
9907 + struct ifreq ifr;
9909 + tun = vty->index;
9911 + if (!(out = mplsd_out_segment_lookup_by_index(mplsd_static_info,
9912 + atoi(argv[0])))) {
9913 + vty_out(vty, "Unable to find out-segment %s%s", argv[0], VTY_NEWLINE);
9914 + return CMD_WARNING;
9917 + out_old = (struct mplsd_out_segment*)tun->info;
9918 + if (out_old) {
9919 + mos2ml(out_old,&ml);
9920 + memcpy(&ifr.ifr_data,&ml,sizeof(struct mpls_label));
9921 + mplsd_ioctl(SIOCMPLSTUNNELDELOUT,(caddr_t)&ifr);
9924 + mos2ml(out,&ml);
9925 + memcpy(&ifr.ifr_data,&ml,sizeof(struct mpls_label));
9926 + if (mplsd_ioctl(SIOCMPLSTUNNELADDOUT,(caddr_t)&ifr)) {
9927 + vty_out(vty, "Unable to set out-segment %s on tunnel %s%s", argv[0],
9928 + tun->name, VTY_NEWLINE);
9929 + return CMD_WARNING;
9931 + tun->info = out;
9932 + return CMD_SUCCESS;
9935 +DEFUN (no_mplsd_tunnel_out_segment,
9936 + no_mplsd_tunnel_out_segment_cmd,
9937 + "no out-segment",
9938 + "Delete the out-segment associated with this tunnel\n"
9939 + "MPLS out-segment index\n") {
9941 + struct interface *tun;
9943 + tun = vty->index;
9945 + if (tun->info) {
9946 + struct mplsd_out_segment *out = tun->info;
9947 + struct mpls_label ml;
9948 + struct ifreq ifr;
9950 + mos2ml(out,&ml);
9951 + memcpy(&ifr.ifr_data,&ml,sizeof(struct mpls_label));
9952 + mplsd_ioctl(SIOCMPLSTUNNELDELOUT,(caddr_t)&ifr);
9955 + return CMD_SUCCESS;
9958 +static void mplsd_dump_tunnel_vty(struct vty *vty, struct mplsd_tunnel *ifp) {
9959 + vty_out (vty, "Tunnel %s%s", ifp->iff.name, VTY_NEWLINE);
9960 + if (ifp->iff.desc) {
9961 + vty_out (vty, " Description: %s%s", ifp->iff.desc, VTY_NEWLINE);
9963 + if (ifp->iff.ifindex <= 0) {
9964 + vty_out(vty, " index %d pseudo tunnel%s", ifp->iff.ifindex, VTY_NEWLINE);
9966 + vty_out (vty, "%s", VTY_NEWLINE);
9969 +DEFUN (mplsd_show_tunnel, mplsd_show_tunnel_cmd,
9970 + "show tunnel [IFNAME]",
9971 + SHOW_STR
9972 + "MPLS Tunnel status and configuration\n"
9973 + "Inteface name\n") {
9974 + listnode node;
9975 + struct mplsd_tunnel *ifp;
9977 + if (argc != 0) {
9978 + ifp = mplsd_tunnel_lookup_by_name(argv[0]);
9979 + if (ifp == NULL) {
9980 + vty_out(vty, "%% Can't find tunnel %s%s", argv[0], VTY_NEWLINE);
9981 + return CMD_WARNING;
9983 + mplsd_dump_tunnel_vty(vty, ifp);
9984 + return CMD_SUCCESS;
9987 + for (node = listhead(mplsd_tunnel_list); node; nextnode(node)) {
9988 + mplsd_dump_tunnel_vty(vty, getdata(node));
9991 + return CMD_SUCCESS;
9994 +static int mplsd_tunnel_config_write(struct vty *vty) {
9995 + listnode node;
9996 + struct interface *ifp;
9998 + for (node = listhead(mplsd_tunnel_list); node; nextnode(node)) {
9999 + ifp = getdata(node);
10000 + vty_out (vty, "tunnel %s%s", ifp->name, VTY_NEWLINE);
10003 + vty_out (vty, "!%s", VTY_NEWLINE);
10004 + return 0;
10007 +static struct cmd_node mplsd_tunnel_node = {MPLS_IF_NODE, "%s(config-tun)# ", 1};
10009 +void mplsd_tunnel_init () {
10010 + mplsd_tunnel_list = list_new();
10012 + install_node(&mplsd_tunnel_node, mplsd_tunnel_config_write);
10013 + install_default(MPLS_IF_NODE);
10015 + install_element(VIEW_NODE, &mplsd_show_tunnel_cmd);
10016 + install_element(ENABLE_NODE, &mplsd_show_tunnel_cmd);
10018 + install_element(CONFIG_NODE, &mplsd_tunnel_cmd);
10019 + install_element(CONFIG_NODE, &no_mplsd_tunnel_cmd);
10021 diff -uNr --exclude=CVS zebra/mplsd/static_tunnel.h zebra-ldp/mplsd/static_tunnel.h
10022 --- zebra/mplsd/static_tunnel.h Wed Dec 31 19:00:00 1969
10023 +++ zebra-ldp/mplsd/static_tunnel.h Wed Oct 9 18:18:31 2002
10024 @@ -0,0 +1,17 @@
10025 +#ifndef MPLS_TUNNEL_H
10026 +#define MPLS_TUNNEL_H
10027 +#include <zebra.h>
10028 +#include "if.h"
10030 +struct mplsd_tunnel {
10031 + struct interface iff;
10032 + struct mplsd_interface_wait *wait;
10033 + struct mplsd_out_segment *out;
10036 +extern void mplsd_tunnel_init();
10037 +extern struct mplsd_tunnel *mplsd_tunnel_lookup_by_name(char *name);
10038 +extern struct mplsd_tunnel *mplsd_tunnel_create(char *name, int mode);
10039 +extern void mplsd_tunnel_delete(struct mplsd_tunnel *ifp, int mode);
10041 +#endif
10042 diff -uNr --exclude=CVS zebra/mplsd/static_vty.c zebra-ldp/mplsd/static_vty.c
10043 --- zebra/mplsd/static_vty.c Wed Dec 31 19:00:00 1969
10044 +++ zebra-ldp/mplsd/static_vty.c Mon Nov 25 21:18:52 2002
10045 @@ -0,0 +1,571 @@
10046 +#include <zebra.h>
10048 +#include "vty.h"
10049 +#include "command.h"
10051 +#include "mpls.h"
10052 +#include "mpls_vty.h"
10053 +#include "static.h"
10055 +#include "lsr_cfg.h"
10057 +char *owner_name[4] = { "LDP", "CR-LDP", "STATIC", "RSVP" };
10059 +DEFUN (mpls_static,
10060 + mpls_static_cmd,
10061 + "mpls static",
10062 + "MPLS configuration\n"
10063 + "Static MPLS configuration\n") {
10065 + vty->node = MPLS_STATIC_NODE;
10066 + vty->index = static_get();
10068 + return CMD_SUCCESS;
10071 +DEFUN (no_mpls_static,
10072 + no_mpls_static_cmd,
10073 + "no mpls static",
10074 + NO_STR
10075 + "MPLS configuration\n"
10076 + "Static MPLS configuration\n") {
10077 + struct mpls *mpls = mpls_get();
10079 + if (!mpls->mstatic) {
10080 + vty_out (vty, "There isn't an active static MPLS instance.%s",
10081 + VTY_NEWLINE);
10082 + return CMD_WARNING;
10085 + static_finish(mpls->mstatic);
10086 + return CMD_SUCCESS;
10089 +static int do_mpls_static_insegment(struct static_insegment *in,
10090 + unsigned int label, unsigned int labelspace) {
10091 + in->in.info.label.type = MPLS_LABEL_TYPE_GENERIC;
10092 + in->in.info.label.u.gen = label;
10093 + in->in.info.labelspace = labelspace;
10094 + in->in.info.owner = MPLS_OWNER_STATIC;
10095 + in->in.info.family = MPLS_FAMILY_IPV4;
10096 + in->in.info.npop = 1;
10097 + return lsr_cfg_insegment_set(in->mstatic->mpls->h,&in->in,LSR_CFG_ADD|
10098 + LSR_INSEGMENT_CFG_NPOP|LSR_INSEGMENT_CFG_FAMILY|
10099 + LSR_INSEGMENT_CFG_LABELSPACE|LSR_INSEGMENT_CFG_LABEL|
10100 + LSR_INSEGMENT_CFG_OWNER);
10103 +static int do_mpls_static_outsegment(struct static_outsegment *out,
10104 + unsigned int label, mpls_nexthop *nh) {
10105 + out->out.info.label.type = MPLS_LABEL_TYPE_GENERIC;
10106 + out->out.info.label.u.gen = label;
10107 + out->out.info.owner = MPLS_OWNER_STATIC;
10108 + out->out.info.push_label = MPLS_BOOL_TRUE;
10109 + memcpy(&out->out.info.nexthop, nh, sizeof(mpls_nexthop));
10111 + return lsr_cfg_outsegment_set(out->mstatic->mpls->h,&out->out, LSR_CFG_ADD|
10112 + LSR_OUTSEGMENT_CFG_PUSH_LABEL|LSR_OUTSEGMENT_CFG_OWNER|
10113 + LSR_OUTSEGMENT_CFG_LABEL|LSR_OUTSEGMENT_CFG_NEXTHOP);
10116 +static int do_mpls_static_xconnect(struct static_insegment *in,
10117 + struct static_outsegment *out) {
10118 + in->xc.insegment_index = in->in.index;
10119 + in->xc.outsegment_index = out->out.index;
10120 + in->xc.info.owner = MPLS_OWNER_STATIC;
10121 + in->xc.info.lspid = 1;
10122 + return lsr_cfg_xconnect_set2(in->mstatic->mpls->h, &in->xc, LSR_CFG_ADD|
10123 + LSR_XCONNECT_CFG_OUTSEGMENT|LSR_XCONNECT_CFG_INSEGMENT|
10124 + LSR_XCONNECT_CFG_LSPID|LSR_XCONNECT_CFG_OWNER);
10127 +DEFUN (mpls_static_in_segment,
10128 + mpls_static_in_segment_cmd,
10129 + "in-segment INDEX generic LABEL LABELSPACE",
10130 + "Create an MPLS in-segment\n"
10131 + "Insegment index\n"
10132 + "Generic label family\n"
10133 + "Generic label value\n"
10134 + "LabelSpace\n") {
10135 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
10136 + struct static_insegment *in;
10137 + unsigned int index;
10138 + unsigned int label;
10139 + unsigned int labelspace;
10141 + VTY_GET_UINT32("INDEX",index,argv[0]);
10142 + VTY_GET_UINT32_RANGE("LABEL",label,argv[1],16,0xFFFFF);
10143 + VTY_GET_UINT32_RANGE("LABELSPACE",labelspace,argv[2],0,255);
10145 + if ((in = static_insegment_get(mstatic, index, 0))) {
10146 + vty_out (vty, "There is an insegment with index %d already.%s", index,
10147 + VTY_NEWLINE);
10148 + return CMD_WARNING;
10151 + in = static_insegment_get(mstatic, index, 1);
10152 + do_mpls_static_insegment(in, label, labelspace);
10153 + return CMD_SUCCESS;
10156 +DEFUN (mpls_static_in_segment_xc,
10157 + mpls_static_in_segment_xc_cmd,
10158 + "in-segment INDEX generic LABEL LABELSPACE cross-connect OUTINDEX",
10159 + "Create an MPLS in-segment\n"
10160 + "Insegment index\n"
10161 + "Generic label family\n"
10162 + "Generic label value\n"
10163 + "LabelSpace\n"
10164 + "Cross Connect\n"
10165 + "Outsegment Index\n") {
10166 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
10167 + struct static_insegment *in;
10168 + struct static_outsegment *out;
10169 + unsigned int index;
10170 + unsigned int label;
10171 + unsigned int labelspace;
10172 + unsigned int out_index;
10174 + VTY_GET_UINT32("INDEX",index,argv[0]);
10175 + VTY_GET_UINT32_RANGE("LABEL",label,argv[1],16,0xFFFFF);
10176 + VTY_GET_UINT32_RANGE("LABELSPACE",labelspace,argv[2],0,255);
10177 + VTY_GET_UINT32("OUTINDEX",out_index,argv[3]);
10179 + if (!(out = static_outsegment_get(mstatic, out_index, 0))) {
10180 + vty_out (vty, "There isn't an outsegment with index %d.%s", out_index,
10181 + VTY_NEWLINE);
10182 + return CMD_WARNING;
10185 + in = static_insegment_get(mstatic, index, 1);
10186 + if (in->in.index) {
10187 + if (in->in.info.label.type != MPLS_LABEL_TYPE_GENERIC ||
10188 + in->in.info.label.u.gen != label ||
10189 + in->in.info.labelspace != labelspace ||
10190 + in->in.info.owner != MPLS_OWNER_STATIC) {
10191 + vty_out (vty, "There is an insegment with index %d, label %d,"
10192 + "and labelspace %d already.%s", index, label, labelspace,
10193 + VTY_NEWLINE);
10194 + return CMD_WARNING;
10196 + } else {
10197 + do_mpls_static_insegment(in, label, labelspace);
10200 + if (in->out_index) {
10201 + vty_out (vty, "Insegment %d is already cross-connect to "
10202 + "outsegment %d.%s", index, in->out_index, VTY_NEWLINE);
10203 + return CMD_WARNING;
10205 + in->out_index = out_index;
10206 + do_mpls_static_xconnect(in, out);
10208 + return CMD_SUCCESS;
10211 +DEFUN (mpls_static_in_segment_xc2,
10212 + mpls_static_in_segment_xc2_cmd,
10213 + "in-segment INDEX cross-connect OUTINDEX",
10214 + "Create an MPLS in-segment\n"
10215 + "Insegment index\n"
10216 + "Cross Connect\n"
10217 + "Outsegment Index\n") {
10218 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
10219 + struct static_insegment *in;
10220 + struct static_outsegment *out;
10221 + unsigned int index;
10222 + unsigned int out_index;
10224 + VTY_GET_UINT32("INDEX",index,argv[0]);
10225 + VTY_GET_UINT32("OUTINDEX",out_index,argv[1]);
10227 + if (!(in = static_insegment_get(mstatic, index, 0))) {
10228 + vty_out (vty, "There isn't an insegment with index %d.%s", index,
10229 + VTY_NEWLINE);
10230 + return CMD_WARNING;
10233 + if (!(out = static_outsegment_get(mstatic, out_index, 0))) {
10234 + vty_out (vty, "There isn't an outsegment with index %d.%s", out_index,
10235 + VTY_NEWLINE);
10236 + return CMD_WARNING;
10239 + do_mpls_static_xconnect(in, out);
10241 + return CMD_SUCCESS;
10244 +DEFUN (no_mpls_static_in_segment,
10245 + no_mpls_static_in_segment_cmd,
10246 + "no in-segment INDEX",
10247 + NO_STR
10248 + "Delete an MPLS in-segment\n"
10249 + "Index of In-segment\n") {
10250 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
10251 + struct static_insegment *in;
10252 + int index;
10254 + VTY_GET_UINT32("INDEX",index,argv[0]);
10256 + if (!(in = static_insegment_get(mstatic, index, 0))) {
10257 + vty_out (vty, "There isn't an insegment with the index %d.%s", index,
10258 + VTY_NEWLINE);
10259 + return CMD_WARNING;
10261 + lsr_cfg_insegment_set(in->mstatic->mpls->h,&in->in,LSR_CFG_DEL);
10262 + static_insegment_finish(in);
10263 + return CMD_SUCCESS;
10266 +DEFUN (no_mpls_static_in_segment_xc,
10267 + no_mpls_static_in_segment_xc_cmd,
10268 + "no in-segment INDEX cross-connect",
10269 + NO_STR
10270 + "Delete an MPLS in-segment\n"
10271 + "Index of In-segment\n"
10272 + "Cross Connect\n") {
10273 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
10274 + struct static_insegment *in;
10275 + int index;
10277 + VTY_GET_UINT32("INDEX",index,argv[0]);
10279 + if (!(in = static_insegment_get(mstatic, index, 0))) {
10280 + vty_out (vty, "There isn't an insegment with the index %d.%s", index,
10281 + VTY_NEWLINE);
10282 + return CMD_WARNING;
10284 + if (!in->out_index) {
10285 + vty_out (vty, "Insegment %d is not cross-conencted to anything.%s",
10286 + index, VTY_NEWLINE);
10287 + return CMD_WARNING;
10289 + lsr_cfg_xconnect_set(in->mstatic->mpls->h,&in->xc,LSR_CFG_DEL);
10290 + in->out_index = 0;
10291 + return CMD_SUCCESS;
10294 +DEFUN (mpls_static_out_segment_nh_ipaddr,
10295 + mpls_static_out_segment_nh_ipaddr_cmd,
10296 + "out-segment INDEX generic LABEL next-hop IPADDR",
10297 + "Create an MPLS out-segment\n"
10298 + "Index for the out-segment\n"
10299 + "Generic label family\n"
10300 + "Generic label value\n"
10301 + "Next Hop\n"
10302 + "IP Address\n") {
10303 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
10304 + struct static_outsegment *out;
10305 + struct interface *iff;
10306 + unsigned int index;
10307 + unsigned int label;
10308 + struct in_addr ip;
10309 + mpls_nexthop nh;
10311 + VTY_GET_UINT32("INDEX",index,argv[0]);
10312 + VTY_GET_UINT32("LABEL",label,argv[1]);
10313 + VTY_GET_IPV4_ADDRESS("NEXTHOP",ip,argv[2]);
10315 + if ((out = static_outsegment_get(mstatic, index, 0))) {
10316 + vty_out (vty, "There is an insegment with index %d already.%s", index,
10317 + VTY_NEWLINE);
10318 + return CMD_WARNING;
10321 + out = static_outsegment_get(mstatic, index, 1);
10322 + iff = if_lookup_address(ip);
10323 + nh.type = MPLS_NH_IPIF;
10324 + nh.u.ipif.if_handle = iff;
10325 + nh.u.ipif.ip.u.ipv4 = ntohl(ip.s_addr);
10327 + do_mpls_static_outsegment(out, label, &nh);
10329 + return CMD_SUCCESS;
10332 +DEFUN (mpls_static_out_segment_nh_intf,
10333 + mpls_static_out_segment_nh_intf_cmd,
10334 + "out-segment INDEX generic LABEL interface IFNAME",
10335 + "Create an MPLS out-segment\n"
10336 + "Index for the out-segment\n"
10337 + "Generic label family\n"
10338 + "Generic label value\n"
10339 + "Next Hop\n"
10340 + "Interface\n") {
10341 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
10342 + struct static_outsegment *out;
10343 + struct interface *iff;
10344 + unsigned int index;
10345 + unsigned int label;
10346 + mpls_nexthop nh;
10348 + VTY_GET_UINT32("INDEX",index,argv[0]);
10349 + VTY_GET_UINT32("LABEL",label,argv[1]);
10351 + if ((out = static_outsegment_get(mstatic, index, 0))) {
10352 + vty_out (vty, "There is an insegment with index %d already.%s", index,
10353 + VTY_NEWLINE);
10354 + return CMD_WARNING;
10357 + out = static_outsegment_get(mstatic, index, 1);
10358 + iff = if_lookup_by_name(argv[2]);
10359 + nh.type = MPLS_NH_IF;
10360 + nh.u.if_handle = iff;
10362 + do_mpls_static_outsegment(out, label, &nh);
10364 + return CMD_SUCCESS;
10367 +DEFUN (no_mpls_static_out_segment,
10368 + no_mpls_static_out_segment_cmd,
10369 + "no out-segment INDEX",
10370 + NO_STR
10371 + "Delete an MPLS out-segment\n"
10372 + "Index of the out-segment\n") {
10373 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
10374 + struct static_outsegment *out;
10375 + unsigned int index;
10377 + VTY_GET_UINT32("INDEX",index,argv[0]);
10379 + if (!(out = static_outsegment_get(mstatic, index, 0))) {
10380 + vty_out (vty, "There isn't an outsegment with the index %d.%s", index,
10381 + VTY_NEWLINE);
10382 + return CMD_WARNING;
10385 + lsr_cfg_outsegment_set(out->mstatic->mpls->h,&out->out,LSR_CFG_DEL);
10386 + static_outsegment_finish(out);
10387 + return CMD_SUCCESS;
10390 +DEFUN (mpls_show_mpls_fwd, mpls_show_mpls_fwd_cmd,
10391 + "show mpls forwarding",
10392 + SHOW_STR
10393 + "MPLS related commands\n"
10394 + "MPLS forwarding table\n") {
10395 + struct mpls *mpls = mpls_get();
10396 + struct lsr_outsegment out;
10397 + struct lsr_insegment in;
10398 + struct lsr_xconnect xc;
10399 + struct in_addr ip;
10400 + struct interface *iff;
10401 + int count;
10403 + if (!mpls) {
10404 + vty_out (vty, "There isn't an active MPLS instance.%s",
10405 + VTY_NEWLINE);
10406 + return CMD_WARNING;
10409 + vty_out(vty, "Insegments:%s",VTY_NEWLINE);
10411 + count = 0;
10412 + in.index = 0;
10413 + while (lsr_cfg_insegment_getnext(mpls->h,&in,0xFFFFFFFF)==MPLS_SUCCESS) {
10414 + if (!count) {
10415 + vty_out(vty, " Lbl Spc Label Owner%s", VTY_NEWLINE);
10417 + vty_out(vty, " %-3d %7d %-6s%s", in.info.labelspace,
10418 + in.info.label.u.gen, owner_name[in.info.owner], VTY_NEWLINE);
10419 + count++;
10421 + if (!count) {
10422 + vty_out(vty, "%s", VTY_NEWLINE);
10424 + vty_out(vty, "Total %d%s",count, VTY_NEWLINE);
10425 + vty_out(vty, "%s", VTY_NEWLINE);
10427 + vty_out(vty, "Outsegments:%s",VTY_NEWLINE);
10428 + count = 0;
10429 + out.index = 0;
10430 + while (lsr_cfg_outsegment_getnext(mpls->h,&out,0xFFFFFFFF)==MPLS_SUCCESS) {
10431 + if (!count) {
10432 + vty_out(vty, " Interface Label Next Hop Owner%s",
10433 + VTY_NEWLINE);
10435 + if (out.info.nexthop.type == MPLS_NH_IPIF) {
10436 + iff = out.info.nexthop.u.ipif.if_handle;
10437 + ip.s_addr = htonl(out.info.nexthop.u.ipif.ip.u.ipv4);
10438 + } else {
10439 + iff = out.info.nexthop.u.if_handle;
10440 + ip.s_addr = 0;
10442 + vty_out(vty, " %-16s %7d %-15s %-6s%s",iff->name,
10443 + out.info.label.u.gen, inet_ntoa(ip), owner_name[out.info.owner],
10444 + VTY_NEWLINE);
10445 + count++;
10447 + if (!count) {
10448 + vty_out(vty, "%s", VTY_NEWLINE);
10450 + vty_out(vty, "Total %d%s",count, VTY_NEWLINE);
10451 + vty_out(vty, "%s", VTY_NEWLINE);
10453 + vty_out(vty, "Cross Connects:%s",VTY_NEWLINE);
10454 + count = 0;
10455 + xc.index = 0;
10456 + while (lsr_cfg_xconnect_getnext(mpls->h,&xc,0xFFFFFFFF) == MPLS_SUCCESS) {
10457 + if (!count) {
10458 + vty_out(vty, " Lbl Spc In Label Out Label Interface "
10459 + "Next Hop Owner%s", VTY_NEWLINE);
10462 + in.index = xc.insegment_index;
10463 + lsr_cfg_insegment_get(mpls->h,&in,0xFFFFFFFF);
10465 + out.index = xc.outsegment_index;
10466 + lsr_cfg_outsegment_get(mpls->h,&out,0xFFFFFFFF);
10467 + if (out.info.nexthop.type == MPLS_NH_IPIF) {
10468 + iff = out.info.nexthop.u.ipif.if_handle;
10469 + ip.s_addr = htonl(out.info.nexthop.u.ipif.ip.u.ipv4);
10470 + } else {
10471 + iff = out.info.nexthop.u.if_handle;
10472 + ip.s_addr = 0;
10475 + vty_out(vty, " %-3d %7d %7d %-16s %-15s %-6s%s",
10476 + in.info.labelspace, in.info.label.u.gen, out.info.label.u.gen,
10477 + iff->name, inet_ntoa(ip), owner_name[in.info.owner], VTY_NEWLINE);
10478 + count++;
10480 + if (!count) {
10481 + vty_out(vty, "%s", VTY_NEWLINE);
10483 + vty_out(vty, "Total %d%s",count, VTY_NEWLINE);
10484 + vty_out(vty, "%s", VTY_NEWLINE);
10486 + return CMD_SUCCESS;
10489 +DEFUN (mpls_show_mpls_ftn, mpls_show_mpls_ftn_cmd,
10490 + "show mpls ftn",
10491 + SHOW_STR
10492 + "MPLS related commands\n"
10493 + "MPLS FTN bindings\n") {
10494 + struct mpls *mpls = mpls_get();
10495 + lsr_outsegment out;
10496 + char buf[24];
10497 + struct interface *iff;
10498 + struct in_addr ip;
10499 + lsr_ftn ftn;
10500 + int count = 0;
10502 + vty_out(vty, "FTNs:%s",VTY_NEWLINE);
10503 + ftn.index = 0;
10504 + while (lsr_cfg_ftn_getnext(mpls->h,&ftn,0xFFFFFFFF) == MPLS_SUCCESS) {
10505 + if (!count) {
10506 + vty_out(vty, " FEC Out Label Interface "
10507 + "Next Hop Owner%s", VTY_NEWLINE);
10510 + out.index = ftn.outsegment_index;
10511 + lsr_cfg_outsegment_get(mpls->h,&out,0xFFFFFFFF);
10513 + vty_out(vty, " ");
10514 + switch(ftn.fec.type) {
10515 + case MPLS_FEC_PREFIX:
10516 + ip.s_addr = htonl(ftn.fec.u.prefix.network.u.ipv4);
10517 + sprintf(buf, "%s/%d", inet_ntoa(ip),ftn.fec.u.prefix.length);
10518 + vty_out(vty, "%-18s", buf);
10519 + break;
10520 + case MPLS_FEC_HOST:
10521 + ip.s_addr = htonl(ftn.fec.u.host.u.ipv4);
10522 + vty_out(vty, "%-18s", inet_ntoa(ip));
10523 + break;
10524 + case MPLS_FEC_L2CC:
10525 + default:
10526 + vty_out(vty, "%-18s", "(unknown)");
10528 + vty_out(vty, " ");
10530 + if (out.info.nexthop.type == MPLS_NH_IPIF) {
10531 + iff = out.info.nexthop.u.ipif.if_handle;
10532 + ip.s_addr = htonl(out.info.nexthop.u.ipif.ip.u.ipv4);
10533 + } else {
10534 + iff = out.info.nexthop.u.if_handle;
10535 + ip.s_addr = 0;
10537 + vty_out(vty, "%7d %-15s %-15s %-6s%s", out.info.label.u.gen,
10538 + iff->name, inet_ntoa(ip), owner_name[out.info.owner], VTY_NEWLINE);
10540 + count++;
10543 + if (!count) {
10544 + vty_out(vty, "%s", VTY_NEWLINE);
10546 + vty_out(vty, "Total %d%s",count, VTY_NEWLINE);
10547 + vty_out(vty, "%s", VTY_NEWLINE);
10548 + return CMD_SUCCESS;
10551 +static int mpls_static_config_write (struct vty *vty) {
10552 + struct mpls *mpls = mpls_get();
10553 + struct mpls_static *mstatic = mpls->mstatic;
10554 + struct static_outsegment *out;
10555 + struct static_insegment *in;
10556 + struct listnode *tmp;
10558 + if (!mstatic) {
10559 + return 0;
10562 + vty_out(vty, "mpls static%s", VTY_NEWLINE);
10564 + LIST_LOOP(mstatic->outsegment, out, tmp) {
10565 + vty_out(vty, " out-segment %d generic %d", out->index,
10566 + out->out.info.label.u.gen);
10567 + if (out->out.info.nexthop.type == MPLS_NH_IF) {
10568 + vty_out(vty, " interface %s",
10569 + out->out.info.nexthop.u.if_handle->name);
10570 + } else {
10571 + struct in_addr ip;
10572 + ip.s_addr = htonl(out->out.info.nexthop.u.ipif.ip.u.ipv4);
10573 + vty_out(vty, " next-hop %s", inet_ntoa(ip));
10575 + vty_out(vty,"%s", VTY_NEWLINE);
10578 + LIST_LOOP(mstatic->insegment, in, tmp) {
10579 + vty_out(vty, " in-segment %d generic %d %d", in->index,
10580 + in->in.info.label.u.gen, in->in.info.labelspace);
10581 + if (in->out_index) {
10582 + vty_out(vty, " cross-connect %d", in->out_index);
10584 + vty_out(vty, "%s", VTY_NEWLINE);
10586 + vty_out(vty,"!%s", VTY_NEWLINE);
10587 + return 0;
10590 +static struct cmd_node static_node = {MPLS_STATIC_NODE,"%s(config-mpls)# ",1};
10592 +void static_vty_show_init() {
10593 + install_element (VIEW_NODE, &mpls_show_mpls_fwd_cmd);
10594 + install_element (ENABLE_NODE, &mpls_show_mpls_fwd_cmd);
10596 + install_element (VIEW_NODE, &mpls_show_mpls_ftn_cmd);
10597 + install_element (ENABLE_NODE, &mpls_show_mpls_ftn_cmd);
10600 +void static_vty_init () {
10602 + install_node (&static_node, mpls_static_config_write);
10603 + install_default (MPLS_STATIC_NODE);
10605 + install_element (CONFIG_NODE, &mpls_static_cmd);
10606 + install_element (CONFIG_NODE, &no_mpls_static_cmd);
10608 + install_element(MPLS_STATIC_NODE, &mpls_static_in_segment_cmd);
10609 + install_element(MPLS_STATIC_NODE, &mpls_static_in_segment_xc_cmd);
10610 + install_element(MPLS_STATIC_NODE, &no_mpls_static_in_segment_cmd);
10611 + install_element(MPLS_STATIC_NODE, &no_mpls_static_in_segment_xc_cmd);
10613 + install_element(MPLS_STATIC_NODE, &mpls_static_out_segment_nh_ipaddr_cmd);
10614 + install_element(MPLS_STATIC_NODE, &mpls_static_out_segment_nh_intf_cmd);
10615 + install_element(MPLS_STATIC_NODE, &no_mpls_static_out_segment_cmd);
10617 diff -uNr --exclude=CVS zebra/mplsd/static_vty.h zebra-ldp/mplsd/static_vty.h
10618 --- zebra/mplsd/static_vty.h Wed Dec 31 19:00:00 1969
10619 +++ zebra-ldp/mplsd/static_vty.h Tue Nov 19 22:15:33 2002
10620 @@ -0,0 +1,7 @@
10621 +#ifndef STATIC_VTY_H
10622 +#define STATIC_VTY_H
10624 +void static_vty_init();
10625 +void static_vty_show_init();
10627 +#endif
10628 diff -uNr --exclude=CVS zebra/ospf6d/Makefile.in zebra-ldp/ospf6d/Makefile.in
10629 --- zebra/ospf6d/Makefile.in Sat Aug 24 00:14:54 2002
10630 +++ zebra-ldp/ospf6d/Makefile.in Tue Nov 19 22:21:15 2002
10631 @@ -83,6 +83,7 @@
10632 LIBPAM = @LIBPAM@
10633 LIB_IPV6 = @LIB_IPV6@
10634 LIB_REGEX = @LIB_REGEX@
10635 +MPLSD = @MPLSD@
10636 MULTIPATH_NUM = @MULTIPATH_NUM@
10637 OSPF6D = @OSPF6D@
10638 OSPFD = @OSPFD@
10639 diff -uNr --exclude=CVS zebra/ospfd/Makefile.in zebra-ldp/ospfd/Makefile.in
10640 --- zebra/ospfd/Makefile.in Sat Aug 24 00:14:54 2002
10641 +++ zebra-ldp/ospfd/Makefile.in Tue Nov 19 22:21:15 2002
10642 @@ -83,6 +83,7 @@
10643 LIBPAM = @LIBPAM@
10644 LIB_IPV6 = @LIB_IPV6@
10645 LIB_REGEX = @LIB_REGEX@
10646 +MPLSD = @MPLSD@
10647 MULTIPATH_NUM = @MULTIPATH_NUM@
10648 OSPF6D = @OSPF6D@
10649 OSPFD = @OSPFD@
10650 diff -uNr --exclude=CVS zebra/ospfd/ospf_lsdb.c zebra-ldp/ospfd/ospf_lsdb.c
10651 --- zebra/ospfd/ospf_lsdb.c Sat Aug 24 00:14:55 2002
10652 +++ zebra-ldp/ospfd/ospf_lsdb.c Tue Sep 10 21:40:25 2002
10653 @@ -284,8 +284,8 @@
10656 struct ospf_lsa *
10657 -foreach_lsa (struct route_table *table, void *p_arg, int int_arg,
10658 - int (*callback) (struct ospf_lsa *, void *, int))
10659 +foreach_lsa (struct route_table *table, void *p_arg, int int_arg,
10660 + int (*callback) (struct ospf_lsa *, void *, int))
10662 struct route_node *rn;
10663 struct ospf_lsa *lsa;
10664 @@ -293,6 +293,21 @@
10665 for (rn = route_top (table); rn; rn = route_next (rn))
10666 if ((lsa = rn->info) != NULL)
10667 if (callback (lsa, p_arg, int_arg))
10668 + return lsa;
10670 + return NULL;
10673 +struct ospf_lsa *
10674 +foreach_lsa_sum (struct route_table *table, void *p_arg, int *sum, int int_arg,
10675 + int (*callback) (struct ospf_lsa *, void *, int*, int))
10677 + struct route_node *rn;
10678 + struct ospf_lsa *lsa;
10680 + for (rn = route_top (table); rn; rn = route_next (rn))
10681 + if ((lsa = rn->info) != NULL)
10682 + if (callback (lsa, p_arg, sum, int_arg))
10683 return lsa;
10685 return NULL;
10686 diff -uNr --exclude=CVS zebra/ospfd/ospf_lsdb.h zebra-ldp/ospfd/ospf_lsdb.h
10687 --- zebra/ospfd/ospf_lsdb.h Sat Aug 24 00:14:55 2002
10688 +++ zebra-ldp/ospfd/ospf_lsdb.h Tue Sep 10 21:40:28 2002
10689 @@ -79,5 +79,7 @@
10690 unsigned long ospf_lsdb_isempty (struct ospf_lsdb *);
10691 struct ospf_lsa *foreach_lsa (struct route_table *, void *, int,
10692 int (*callback) (struct ospf_lsa *, void *, int));
10693 +struct ospf_lsa *foreach_lsa_sum (struct route_table *, void *, int *, int,
10694 + int (*callback) (struct ospf_lsa *, void *, int *, int));
10696 #endif /* _ZEBRA_OSPF_LSDB_H */
10697 diff -uNr --exclude=CVS zebra/ospfd/ospf_vty.c zebra-ldp/ospfd/ospf_vty.c
10698 --- zebra/ospfd/ospf_vty.c Sat Aug 24 00:14:55 2002
10699 +++ zebra-ldp/ospfd/ospf_vty.c Tue Sep 10 21:52:37 2002
10700 @@ -3046,7 +3046,7 @@
10702 /* Show functions */
10704 -show_lsa_summary (struct ospf_lsa *lsa, void *v, int self)
10705 +show_lsa_summary (struct ospf_lsa *lsa, void *v, int *sum, int self)
10707 struct vty *vty = (struct vty *) v;
10708 struct router_lsa *rl;
10709 @@ -3059,6 +3059,7 @@
10710 if (self == 0 || IS_LSA_SELF (lsa))
10712 /* LSA common part show. */
10713 + (*sum) += ntohs (lsa->data->checksum);
10714 vty_out (vty, "%-15s ", inet_ntoa (lsa->data->id));
10715 vty_out (vty, "%-15s %4d 0x%08lx 0x%04x",
10716 inet_ntoa (lsa->data->adv_router), LS_AGE (lsa),
10717 @@ -3592,6 +3593,7 @@
10718 void
10719 show_ip_ospf_database_summary (struct vty *vty, int self)
10721 + unsigned int sum;
10722 listnode node;
10723 int type;
10725 @@ -3619,9 +3621,10 @@
10726 VTY_NEWLINE, VTY_NEWLINE);
10727 vty_out (vty, "%s%s", show_database_header[type], VTY_NEWLINE);
10729 - foreach_lsa (AREA_LSDB (area, type), vty, self, show_lsa_summary);
10731 - vty_out (vty, "%s", VTY_NEWLINE);
10732 + sum = 0;
10733 + foreach_lsa_sum (AREA_LSDB (area, type), vty, &sum, self, show_lsa_summary);
10734 + vty_out (vty, "%s Sum of CkSum: 0x%08x%s%s",
10735 + VTY_NEWLINE, sum, VTY_NEWLINE, VTY_NEWLINE);
10739 @@ -3646,8 +3649,11 @@
10740 VTY_NEWLINE, VTY_NEWLINE);
10741 vty_out (vty, "%s%s", show_database_header[type],
10742 VTY_NEWLINE);
10743 - foreach_lsa (AS_LSDB (ospf_top, type), vty, self, show_lsa_summary);
10744 - vty_out (vty, "%s", VTY_NEWLINE);
10746 + sum = 0;
10747 + foreach_lsa_sum (AS_LSDB (ospf_top, type), vty, &sum, self, show_lsa_summary);
10748 + vty_out (vty, "%s Sum of CkSum: 0x%08x%s%s",
10749 + VTY_NEWLINE, sum, VTY_NEWLINE, VTY_NEWLINE);
10753 diff -uNr --exclude=CVS zebra/ospfd/ospf_zebra.c zebra-ldp/ospfd/ospf_zebra.c
10754 --- zebra/ospfd/ospf_zebra.c Sat Aug 24 00:14:57 2002
10755 +++ zebra-ldp/ospfd/ospf_zebra.c Sun Aug 25 21:52:16 2002
10756 @@ -53,6 +53,23 @@
10758 /* For registering threads. */
10759 extern struct thread_master *master;
10760 +struct in_addr router_id_zebra;
10762 +/* Router-id update message from zebra. */
10763 +int
10764 +ospf_router_id_update_zebra (int command, struct zclient *zclient,
10765 + zebra_size_t length)
10767 + struct prefix router_id;
10768 + zebra_router_id_update_read(zclient->ibuf,&router_id);
10770 + router_id_zebra = router_id.u.prefix4;
10772 + if (ospf_top && ospf_top->t_router_id_update == NULL)
10773 + ospf_top->t_router_id_update = thread_add_timer (master,
10774 + ospf_router_id_update_timer, ospf_top, OSPF_ROUTER_ID_UPDATE_DELAY);
10775 + return 0;
10778 /* Inteface addition message from zebra. */
10780 @@ -147,19 +164,6 @@
10781 return ifp;
10784 -void
10785 -zebra_interface_if_set_value (struct stream *s, struct interface *ifp)
10787 - /* Read interface's index. */
10788 - ifp->ifindex = stream_getl (s);
10790 - /* Read interface's value. */
10791 - ifp->flags = stream_getl (s);
10792 - ifp->metric = stream_getl (s);
10793 - ifp->mtu = stream_getl (s);
10794 - ifp->bandwidth = stream_getl (s);
10798 ospf_interface_state_up (int command, struct zclient *zclient,
10799 zebra_size_t length)
10800 @@ -1178,6 +1182,7 @@
10801 /* Allocate zebra structure. */
10802 zclient = zclient_new ();
10803 zclient_init (zclient, ZEBRA_ROUTE_OSPF);
10804 + zclient->router_id_update = ospf_router_id_update_zebra;
10805 zclient->interface_add = ospf_interface_add;
10806 zclient->interface_delete = ospf_interface_delete;
10807 zclient->interface_up = ospf_interface_state_up;
10808 diff -uNr --exclude=CVS zebra/ospfd/ospfd.c zebra-ldp/ospfd/ospfd.c
10809 --- zebra/ospfd/ospfd.c Sat Aug 24 00:14:57 2002
10810 +++ zebra-ldp/ospfd/ospfd.c Sat Aug 24 00:14:47 2002
10811 @@ -56,6 +56,7 @@
10812 struct ospf *ospf_top;
10814 extern struct zclient *zclient;
10815 +extern struct in_addr router_id_zebra;
10818 void ospf_remove_vls_through_area (struct ospf_area *);
10819 @@ -63,33 +64,6 @@
10820 void ospf_area_free (struct ospf_area *);
10821 void ospf_network_run (struct ospf *, struct prefix *, struct ospf_area *);
10823 -/* Get Router ID from ospf interface list. */
10824 -struct in_addr
10825 -ospf_router_id_get (list if_list)
10827 - listnode node;
10828 - struct in_addr router_id;
10830 - memset (&router_id, 0, sizeof (struct in_addr));
10832 - for (node = listhead (if_list); node; nextnode (node))
10834 - struct ospf_interface *oi = getdata (node);
10836 - if (!if_is_up (oi->ifp) ||
10837 - OSPF_IF_PARAM (oi, passive_interface) == OSPF_IF_PASSIVE)
10838 - continue;
10840 - /* Ignore virtual link interface. */
10841 - if (oi->type != OSPF_IFTYPE_VIRTUALLINK &&
10842 - oi->type != OSPF_IFTYPE_LOOPBACK)
10843 - if (IPV4_ADDR_CMP (&router_id, &oi->address->u.prefix4) < 0)
10844 - router_id = oi->address->u.prefix4;
10847 - return router_id;
10850 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
10852 void
10853 @@ -106,7 +80,7 @@
10854 if (ospf_top->router_id_static.s_addr != 0)
10855 router_id = ospf_top->router_id_static;
10856 else
10857 - router_id = ospf_router_id_get (ospf_top->oiflist);
10858 + router_id = router_id_zebra;
10860 ospf_top->router_id = router_id;
10862 diff -uNr --exclude=CVS zebra/ripd/Makefile.in zebra-ldp/ripd/Makefile.in
10863 --- zebra/ripd/Makefile.in Sat Aug 24 00:14:57 2002
10864 +++ zebra-ldp/ripd/Makefile.in Tue Nov 19 22:21:16 2002
10865 @@ -83,6 +83,7 @@
10866 LIBPAM = @LIBPAM@
10867 LIB_IPV6 = @LIB_IPV6@
10868 LIB_REGEX = @LIB_REGEX@
10869 +MPLSD = @MPLSD@
10870 MULTIPATH_NUM = @MULTIPATH_NUM@
10871 OSPF6D = @OSPF6D@
10872 OSPFD = @OSPFD@
10873 diff -uNr --exclude=CVS zebra/ripngd/Makefile.in zebra-ldp/ripngd/Makefile.in
10874 --- zebra/ripngd/Makefile.in Sat Aug 24 00:14:58 2002
10875 +++ zebra-ldp/ripngd/Makefile.in Tue Nov 19 22:21:16 2002
10876 @@ -83,6 +83,7 @@
10877 LIBPAM = @LIBPAM@
10878 LIB_IPV6 = @LIB_IPV6@
10879 LIB_REGEX = @LIB_REGEX@
10880 +MPLSD = @MPLSD@
10881 MULTIPATH_NUM = @MULTIPATH_NUM@
10882 OSPF6D = @OSPF6D@
10883 OSPFD = @OSPFD@
10884 diff -uNr --exclude=CVS zebra/vtysh/Makefile.in zebra-ldp/vtysh/Makefile.in
10885 --- zebra/vtysh/Makefile.in Sat Aug 24 00:14:58 2002
10886 +++ zebra-ldp/vtysh/Makefile.in Tue Nov 19 22:21:16 2002
10887 @@ -83,6 +83,7 @@
10888 LIBPAM = @LIBPAM@
10889 LIB_IPV6 = @LIB_IPV6@
10890 LIB_REGEX = @LIB_REGEX@
10891 +MPLSD = @MPLSD@
10892 MULTIPATH_NUM = @MULTIPATH_NUM@
10893 OSPF6D = @OSPF6D@
10894 OSPFD = @OSPFD@
10895 diff -uNr --exclude=CVS zebra/zebra/Makefile.am zebra-ldp/zebra/Makefile.am
10896 --- zebra/zebra/Makefile.am Sat Aug 24 00:14:58 2002
10897 +++ zebra-ldp/zebra/Makefile.am Sat Aug 24 00:14:49 2002
10898 @@ -20,12 +20,12 @@
10899 sbin_PROGRAMS = zebra
10901 zebra_SOURCES = \
10902 - zserv.c main.c interface.c connected.c ioctl.c rib.c redistribute.c \
10903 - debug.c rtadv.c zebra_snmp.c
10904 + zserv.c main.c interface.c connected.c ioctl.c zrib.c redistribute.c \
10905 + debug.c rtadv.c zebra_snmp.c router-id.c
10907 noinst_HEADERS = \
10908 - connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \
10909 - interface.h ipforward.h irdp.h
10910 + connected.h ioctl.h zrib.h rt.h zserv.h redistribute.h debug.h rtadv.h \
10911 + interface.h ipforward.h irdp.h router-id.h
10913 zebra_LDADD = ../lib/libzebra.a $(otherobj) $(LIB_IPV6)
10915 diff -uNr --exclude=CVS zebra/zebra/Makefile.in zebra-ldp/zebra/Makefile.in
10916 --- zebra/zebra/Makefile.in Sat Aug 24 00:14:58 2002
10917 +++ zebra-ldp/zebra/Makefile.in Tue Nov 19 22:21:17 2002
10918 @@ -84,6 +84,7 @@
10920 LIB_IPV6 = @LIB_IPV6@
10921 LIB_REGEX = @LIB_REGEX@
10922 +MPLSD = @MPLSD@
10923 MULTIPATH_NUM = @MULTIPATH_NUM@
10924 OSPF6D = @OSPF6D@
10925 OSPFD = @OSPFD@
10926 @@ -119,13 +120,13 @@
10927 sbin_PROGRAMS = zebra
10929 zebra_SOURCES = \
10930 - zserv.c main.c interface.c connected.c ioctl.c rib.c redistribute.c \
10931 - debug.c rtadv.c zebra_snmp.c
10932 + zserv.c main.c interface.c connected.c ioctl.c zrib.c redistribute.c \
10933 + debug.c rtadv.c zebra_snmp.c router-id.c
10936 noinst_HEADERS = \
10937 - connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \
10938 - interface.h ipforward.h irdp.h
10939 + connected.h ioctl.h zrib.h rt.h zserv.h redistribute.h debug.h rtadv.h \
10940 + interface.h ipforward.h irdp.h router-id.h
10943 zebra_LDADD = ../lib/libzebra.a $(otherobj) $(LIB_IPV6)
10944 @@ -149,9 +150,9 @@
10945 PROGRAMS = $(sbin_PROGRAMS)
10947 am_zebra_OBJECTS = zserv.$(OBJEXT) main.$(OBJEXT) interface.$(OBJEXT) \
10948 - connected.$(OBJEXT) ioctl.$(OBJEXT) rib.$(OBJEXT) \
10949 + connected.$(OBJEXT) ioctl.$(OBJEXT) zrib.$(OBJEXT) \
10950 redistribute.$(OBJEXT) debug.$(OBJEXT) rtadv.$(OBJEXT) \
10951 - zebra_snmp.$(OBJEXT)
10952 + zebra_snmp.$(OBJEXT) router-id.$(OBJEXT)
10953 zebra_OBJECTS = $(am_zebra_OBJECTS)
10954 zebra_LDFLAGS =
10955 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
10956 @@ -163,8 +164,9 @@
10957 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/connected.Po ./$(DEPDIR)/debug.Po \
10958 @AMDEP_TRUE@ ./$(DEPDIR)/interface.Po ./$(DEPDIR)/ioctl.Po \
10959 @AMDEP_TRUE@ ./$(DEPDIR)/main.Po ./$(DEPDIR)/redistribute.Po \
10960 -@AMDEP_TRUE@ ./$(DEPDIR)/rib.Po ./$(DEPDIR)/rtadv.Po \
10961 -@AMDEP_TRUE@ ./$(DEPDIR)/zebra_snmp.Po ./$(DEPDIR)/zserv.Po
10962 +@AMDEP_TRUE@ ./$(DEPDIR)/router-id.Po ./$(DEPDIR)/rtadv.Po \
10963 +@AMDEP_TRUE@ ./$(DEPDIR)/zebra_snmp.Po ./$(DEPDIR)/zrib.Po \
10964 +@AMDEP_TRUE@ ./$(DEPDIR)/zserv.Po
10965 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
10966 $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
10967 CCLD = $(CC)
10968 @@ -229,9 +231,10 @@
10969 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ioctl.Po@am__quote@
10970 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
10971 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/redistribute.Po@am__quote@
10972 -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rib.Po@am__quote@
10973 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/router-id.Po@am__quote@
10974 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rtadv.Po@am__quote@
10975 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zebra_snmp.Po@am__quote@
10976 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zrib.Po@am__quote@
10977 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zserv.Po@am__quote@
10979 distclean-depend:
10980 diff -uNr --exclude=CVS zebra/zebra/interface.c zebra-ldp/zebra/interface.c
10981 --- zebra/zebra/interface.c Sat Aug 24 00:14:58 2002
10982 +++ zebra-ldp/zebra/interface.c Sat Aug 24 00:14:49 2002
10983 @@ -32,10 +32,12 @@
10984 #include "connected.h"
10985 #include "log.h"
10986 #include "zclient.h"
10987 +#include "table.h"
10988 +#include "rib.h"
10990 #include "zebra/interface.h"
10991 #include "zebra/rtadv.h"
10992 -#include "zebra/rib.h"
10993 +#include "zebra/zrib.h"
10994 #include "zebra/zserv.h"
10995 #include "zebra/redistribute.h"
10996 #include "zebra/debug.h"
10997 diff -uNr --exclude=CVS zebra/zebra/ioctl.c zebra-ldp/zebra/ioctl.c
10998 --- zebra/zebra/ioctl.c Sat Aug 24 00:14:58 2002
10999 +++ zebra-ldp/zebra/ioctl.c Sat Aug 24 00:14:49 2002
11000 @@ -27,8 +27,10 @@
11001 #include "prefix.h"
11002 #include "ioctl.h"
11003 #include "log.h"
11004 +#include "table.h"
11005 +#include "rib.h"
11007 -#include "zebra/rib.h"
11008 +#include "zebra/zrib.h"
11009 #include "zebra/rt.h"
11011 /* clear and set interface name string */
11012 diff -uNr --exclude=CVS zebra/zebra/main.c zebra-ldp/zebra/main.c
11013 --- zebra/zebra/main.c Sat Aug 24 00:14:58 2002
11014 +++ zebra-ldp/zebra/main.c Sat Aug 24 00:14:49 2002
11015 @@ -30,11 +30,14 @@
11016 #include "memory.h"
11017 #include "prefix.h"
11018 #include "log.h"
11019 +#include "table.h"
11020 +#include "rib.h"
11022 -#include "zebra/rib.h"
11023 +#include "zebra/zrib.h"
11024 #include "zebra/zserv.h"
11025 #include "zebra/debug.h"
11026 -#include "zebra/rib.h"
11027 +#include "zebra/zrib.h"
11028 +#include "zebra/router-id.h"
11030 /* Master of threads. */
11031 struct thread_master *master;
11032 @@ -254,9 +257,10 @@
11034 /* Zebra related initialize. */
11035 zebra_init ();
11036 - rib_init ();
11037 + zebra_rib_init ();
11038 zebra_if_init ();
11039 zebra_debug_init ();
11040 + router_id_init ();
11041 access_list_init ();
11042 rtadv_init ();
11044 @@ -277,13 +281,13 @@
11046 /* Clean up self inserted route. */
11047 if (! keep_kernel_mode)
11048 - rib_sweep_route ();
11049 + zrib_sweep_route ();
11051 /* Configuration file read*/
11052 vty_read_config (config_file, config_current, config_default);
11054 /* Clean up rib. */
11055 - rib_weed_tables ();
11056 + zrib_weed_tables ();
11058 /* Exit when zebra is working in batch mode. */
11059 if (batch_mode)
11060 diff -uNr --exclude=CVS zebra/zebra/redistribute.c zebra-ldp/zebra/redistribute.c
11061 --- zebra/zebra/redistribute.c Sat Aug 24 00:14:58 2002
11062 +++ zebra-ldp/zebra/redistribute.c Sat Aug 24 00:14:49 2002
11063 @@ -30,11 +30,13 @@
11064 #include "zclient.h"
11065 #include "linklist.h"
11066 #include "log.h"
11067 +#include "rib.h"
11069 -#include "zebra/rib.h"
11070 +#include "zebra/zrib.h"
11071 #include "zebra/zserv.h"
11072 #include "zebra/redistribute.h"
11073 #include "zebra/debug.h"
11074 +#include "zebra/router-id.h"
11077 zebra_check_addr (struct prefix *p)
11078 @@ -92,7 +94,7 @@
11079 memset (&p, 0, sizeof (struct prefix_ipv4));
11080 p.family = AF_INET;
11082 - rn = route_node_lookup (rib_table_ipv4, (struct prefix *)&p);
11083 + rn = route_node_lookup (rib_table_ipv4->table, (struct prefix *)&p);
11084 if (rn)
11086 for (newrib = rn->info; newrib; newrib = newrib->next)
11087 @@ -107,7 +109,7 @@
11088 memset (&p6, 0, sizeof (struct prefix_ipv6));
11089 p6.family = AF_INET6;
11091 - rn = route_node_lookup (rib_table_ipv6, (struct prefix *)&p6);
11092 + rn = route_node_lookup (rib_table_ipv6->table, (struct prefix *)&p6);
11093 if (rn)
11095 for (newrib = rn->info; newrib; newrib = newrib->next)
11096 @@ -126,7 +128,7 @@
11097 struct rib *newrib;
11098 struct route_node *rn;
11100 - for (rn = route_top (rib_table_ipv4); rn; rn = route_next (rn))
11101 + for (rn = route_top (rib_table_ipv4->table); rn; rn = route_next (rn))
11102 for (newrib = rn->info; newrib; newrib = newrib->next)
11103 if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED)
11104 && newrib->type == type
11105 @@ -135,7 +137,7 @@
11106 zsend_ipv4_add_multipath (client, &rn->p, newrib);
11108 #ifdef HAVE_IPV6
11109 - for (rn = route_top (rib_table_ipv6); rn; rn = route_next (rn))
11110 + for (rn = route_top (rib_table_ipv6->table); rn; rn = route_next (rn))
11111 for (newrib = rn->info; newrib; newrib = newrib->next)
11112 if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED)
11113 && newrib->type == type
11114 @@ -362,6 +364,8 @@
11115 p->prefixlen, ifc->ifp->name);
11118 + router_id_add_address(ifc);
11120 for (node = listhead (client_list); node; nextnode (node))
11121 if ((client = getdata (node)) != NULL)
11122 if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
11123 @@ -385,6 +389,8 @@
11124 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
11125 p->prefixlen, ifc->ifp->name);
11128 + router_id_del_address(ifc);
11130 for (node = listhead (client_list); node; nextnode (node))
11131 if ((client = getdata (node)) != NULL)
11132 diff -uNr --exclude=CVS zebra/zebra/rib.c zebra-ldp/zebra/rib.c
11133 --- zebra/zebra/rib.c Sat Aug 24 00:14:58 2002
11134 +++ zebra-ldp/zebra/rib.c Wed Dec 31 19:00:00 1969
11135 @@ -1,3307 +0,0 @@
11136 -/* Routing Information Base.
11137 - * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro
11139 - * This file is part of GNU Zebra.
11141 - * GNU Zebra is free software; you can redistribute it and/or modify it
11142 - * under the terms of the GNU General Public License as published by the
11143 - * Free Software Foundation; either version 2, or (at your option) any
11144 - * later version.
11146 - * GNU Zebra is distributed in the hope that it will be useful, but
11147 - * WITHOUT ANY WARRANTY; without even the implied warranty of
11148 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11149 - * General Public License for more details.
11151 - * You should have received a copy of the GNU General Public License
11152 - * along with GNU Zebra; see the file COPYING. If not, write to the Free
11153 - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
11154 - * 02111-1307, USA.
11155 - */
11157 -#include <zebra.h>
11159 -#include "prefix.h"
11160 -#include "table.h"
11161 -#include "memory.h"
11162 -#include "vty.h"
11163 -#include "str.h"
11164 -#include "command.h"
11165 -#include "linklist.h"
11166 -#include "if.h"
11167 -#include "log.h"
11168 -#include "sockunion.h"
11170 -#include "zebra/rib.h"
11171 -#include "zebra/rt.h"
11172 -#include "zebra/zserv.h"
11173 -#include "zebra/redistribute.h"
11174 -#include "zebra/debug.h"
11176 -/* Routing information base and static table for IPv4. */
11177 -struct route_table *rib_table_ipv4;
11178 -struct route_table *static_table_ipv4;
11180 -/* Routing information base and static table for IPv6. */
11181 -#ifdef HAVE_IPV6
11182 -struct route_table *rib_table_ipv6;
11183 -struct route_table *static_table_ipv6;
11184 -#endif /* HAVE_IPV6 */
11186 -/* Default rtm_table for all clients */
11187 -extern int rtm_table_default;
11189 -/* Each route type's string and default distance value. */
11190 -struct
11192 - int key;
11193 - char c;
11194 - char *str;
11195 - int distance;
11196 -} route_info[] =
11198 - {ZEBRA_ROUTE_SYSTEM, 'X', "system", 0},
11199 - {ZEBRA_ROUTE_KERNEL, 'K', "kernel", 0},
11200 - {ZEBRA_ROUTE_CONNECT, 'C', "connected", 0},
11201 - {ZEBRA_ROUTE_STATIC, 'S', "static", 1},
11202 - {ZEBRA_ROUTE_RIP, 'R', "rip", 120},
11203 - {ZEBRA_ROUTE_RIPNG, 'R', "ripng", 120},
11204 - {ZEBRA_ROUTE_OSPF, 'O', "ospf", 110},
11205 - {ZEBRA_ROUTE_OSPF6, 'O', "ospf6", 110},
11206 - {ZEBRA_ROUTE_BGP, 'B', "bgp", 20 /* IBGP is 200. */}
11209 -/* Add nexthop to the end of the list. */
11210 -void
11211 -nexthop_add (struct rib *rib, struct nexthop *nexthop)
11213 - struct nexthop *last;
11215 - for (last = rib->nexthop; last && last->next; last = last->next)
11217 - if (last)
11218 - last->next = nexthop;
11219 - else
11220 - rib->nexthop = nexthop;
11221 - nexthop->prev = last;
11223 - rib->nexthop_num++;
11226 -/* Delete specified nexthop from the list. */
11227 -void
11228 -nexthop_delete (struct rib *rib, struct nexthop *nexthop)
11230 - if (nexthop->next)
11231 - nexthop->next->prev = nexthop->prev;
11232 - if (nexthop->prev)
11233 - nexthop->prev->next = nexthop->next;
11234 - else
11235 - rib->nexthop = nexthop->next;
11236 - rib->nexthop_num--;
11239 -/* Free nexthop. */
11240 -void
11241 -nexthop_free (struct nexthop *nexthop)
11243 - if (nexthop->type == NEXTHOP_TYPE_IFNAME && nexthop->ifname)
11244 - free (nexthop->ifname);
11245 - XFREE (MTYPE_NEXTHOP, nexthop);
11248 -struct nexthop *
11249 -nexthop_ifindex_add (struct rib *rib, unsigned int ifindex)
11251 - struct nexthop *nexthop;
11253 - nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
11254 - memset (nexthop, 0, sizeof (struct nexthop));
11255 - nexthop->type = NEXTHOP_TYPE_IFINDEX;
11256 - nexthop->ifindex = ifindex;
11258 - nexthop_add (rib, nexthop);
11260 - return nexthop;
11263 -struct nexthop *
11264 -nexthop_ifname_add (struct rib *rib, char *ifname)
11266 - struct nexthop *nexthop;
11268 - nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
11269 - memset (nexthop, 0, sizeof (struct nexthop));
11270 - nexthop->type = NEXTHOP_TYPE_IFNAME;
11271 - nexthop->ifname = strdup (ifname);
11273 - nexthop_add (rib, nexthop);
11275 - return nexthop;
11278 -struct nexthop *
11279 -nexthop_ipv4_add (struct rib *rib, struct in_addr *ipv4)
11281 - struct nexthop *nexthop;
11283 - nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
11284 - memset (nexthop, 0, sizeof (struct nexthop));
11285 - nexthop->type = NEXTHOP_TYPE_IPV4;
11286 - nexthop->gate.ipv4 = *ipv4;
11288 - nexthop_add (rib, nexthop);
11290 - return nexthop;
11293 -struct nexthop *
11294 -nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr *ipv4,
11295 - unsigned int ifindex)
11297 - struct nexthop *nexthop;
11299 - nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
11300 - memset (nexthop, 0, sizeof (struct nexthop));
11301 - nexthop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
11302 - nexthop->gate.ipv4 = *ipv4;
11303 - nexthop->ifindex = ifindex;
11305 - nexthop_add (rib, nexthop);
11307 - return nexthop;
11310 -#ifdef HAVE_IPV6
11311 -struct nexthop *
11312 -nexthop_ipv6_add (struct rib *rib, struct in6_addr *ipv6)
11314 - struct nexthop *nexthop;
11316 - nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
11317 - memset (nexthop, 0, sizeof (struct nexthop));
11318 - nexthop->type = NEXTHOP_TYPE_IPV6;
11319 - nexthop->gate.ipv6 = *ipv6;
11321 - nexthop_add (rib, nexthop);
11323 - return nexthop;
11326 -struct nexthop *
11327 -nexthop_ipv6_ifname_add (struct rib *rib, struct in6_addr *ipv6,
11328 - char *ifname)
11330 - struct nexthop *nexthop;
11332 - nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
11333 - memset (nexthop, 0, sizeof (struct nexthop));
11334 - nexthop->type = NEXTHOP_TYPE_IPV6_IFNAME;
11335 - nexthop->gate.ipv6 = *ipv6;
11336 - nexthop->ifname = XSTRDUP (0, ifname);
11338 - nexthop_add (rib, nexthop);
11340 - return nexthop;
11343 -struct nexthop *
11344 -nexthop_ipv6_ifindex_add (struct rib *rib, struct in6_addr *ipv6,
11345 - unsigned int ifindex)
11347 - struct nexthop *nexthop;
11349 - nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
11350 - memset (nexthop, 0, sizeof (struct nexthop));
11351 - nexthop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
11352 - nexthop->gate.ipv6 = *ipv6;
11353 - nexthop->ifindex = ifindex;
11355 - nexthop_add (rib, nexthop);
11357 - return nexthop;
11359 -#endif /* HAVE_IPV6 */
11361 -/* If force flag is not set, do not modify falgs at all for uninstall
11362 - the route from FIB. */
11363 -int
11364 -nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
11365 - struct route_node *top)
11367 - struct prefix_ipv4 p;
11368 - struct route_node *rn;
11369 - struct rib *match;
11370 - struct nexthop *newhop;
11372 - if (nexthop->type == NEXTHOP_TYPE_IPV4)
11373 - nexthop->ifindex = 0;
11375 - if (set)
11376 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
11378 - /* Make lookup prefix. */
11379 - memset (&p, 0, sizeof (struct prefix_ipv4));
11380 - p.family = AF_INET;
11381 - p.prefixlen = IPV4_MAX_PREFIXLEN;
11382 - p.prefix = nexthop->gate.ipv4;
11384 - rn = route_node_match (rib_table_ipv4, (struct prefix *) &p);
11385 - while (rn)
11387 - route_unlock_node (rn);
11389 - /* If lookup self prefix return immidiately. */
11390 - if (rn == top)
11391 - return 0;
11393 - /* Pick up selected route. */
11394 - for (match = rn->info; match; match = match->next)
11395 - if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
11396 - break;
11398 - /* If there is no selected route or matched route is EGP, go up
11399 - tree. */
11400 - if (! match
11401 - || match->type == ZEBRA_ROUTE_BGP)
11403 - do {
11404 - rn = rn->parent;
11405 - } while (rn && rn->info == NULL);
11406 - if (rn)
11407 - route_lock_node (rn);
11409 - else
11411 - if (match->type == ZEBRA_ROUTE_CONNECT)
11413 - /* Directly point connected route. */
11414 - newhop = match->nexthop;
11415 - if (newhop && nexthop->type == NEXTHOP_TYPE_IPV4)
11416 - nexthop->ifindex = newhop->ifindex;
11418 - return 1;
11420 - else if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_INTERNAL))
11422 - for (newhop = match->nexthop; newhop; newhop = newhop->next)
11423 - if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB)
11424 - && ! CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_RECURSIVE))
11426 - if (set)
11428 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
11429 - nexthop->rtype = newhop->type;
11430 - if (newhop->type == NEXTHOP_TYPE_IPV4 ||
11431 - newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
11432 - nexthop->rgate.ipv4 = newhop->gate.ipv4;
11433 - if (newhop->type == NEXTHOP_TYPE_IFINDEX
11434 - || newhop->type == NEXTHOP_TYPE_IFNAME
11435 - || newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
11436 - nexthop->rifindex = newhop->ifindex;
11438 - return 1;
11440 - return 0;
11442 - else
11444 - return 0;
11448 - return 0;
11451 -#ifdef HAVE_IPV6
11452 -/* If force flag is not set, do not modify falgs at all for uninstall
11453 - the route from FIB. */
11454 -int
11455 -nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
11456 - struct route_node *top)
11458 - struct prefix_ipv6 p;
11459 - struct route_node *rn;
11460 - struct rib *match;
11461 - struct nexthop *newhop;
11463 - if (nexthop->type == NEXTHOP_TYPE_IPV6)
11464 - nexthop->ifindex = 0;
11466 - if (set)
11467 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
11469 - /* Make lookup prefix. */
11470 - memset (&p, 0, sizeof (struct prefix_ipv6));
11471 - p.family = AF_INET6;
11472 - p.prefixlen = IPV6_MAX_PREFIXLEN;
11473 - p.prefix = nexthop->gate.ipv6;
11475 - rn = route_node_match (rib_table_ipv6, (struct prefix *) &p);
11476 - while (rn)
11478 - route_unlock_node (rn);
11480 - /* If lookup self prefix return immidiately. */
11481 - if (rn == top)
11482 - return 0;
11484 - /* Pick up selected route. */
11485 - for (match = rn->info; match; match = match->next)
11486 - if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
11487 - break;
11489 - /* If there is no selected route or matched route is EGP, go up
11490 - tree. */
11491 - if (! match
11492 - || match->type == ZEBRA_ROUTE_BGP)
11494 - do {
11495 - rn = rn->parent;
11496 - } while (rn && rn->info == NULL);
11497 - if (rn)
11498 - route_lock_node (rn);
11500 - else
11502 - if (match->type == ZEBRA_ROUTE_CONNECT)
11504 - /* Directly point connected route. */
11505 - newhop = match->nexthop;
11507 - if (newhop && nexthop->type == NEXTHOP_TYPE_IPV6)
11508 - nexthop->ifindex = newhop->ifindex;
11510 - return 1;
11512 - else if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_INTERNAL))
11514 - for (newhop = match->nexthop; newhop; newhop = newhop->next)
11515 - if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB)
11516 - && ! CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_RECURSIVE))
11518 - if (set)
11520 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
11521 - nexthop->rtype = newhop->type;
11522 - if (newhop->type == NEXTHOP_TYPE_IPV6
11523 - || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX
11524 - || newhop->type == NEXTHOP_TYPE_IPV6_IFNAME)
11525 - nexthop->rgate.ipv6 = newhop->gate.ipv6;
11526 - if (newhop->type == NEXTHOP_TYPE_IFINDEX
11527 - || newhop->type == NEXTHOP_TYPE_IFNAME
11528 - || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX
11529 - || newhop->type == NEXTHOP_TYPE_IPV6_IFNAME)
11530 - nexthop->rifindex = newhop->ifindex;
11532 - return 1;
11534 - return 0;
11536 - else
11538 - return 0;
11542 - return 0;
11544 -#endif /* HAVE_IPV6 */
11546 -struct rib *
11547 -rib_match_ipv4 (struct in_addr addr)
11549 - struct prefix_ipv4 p;
11550 - struct route_node *rn;
11551 - struct rib *match;
11552 - struct nexthop *newhop;
11554 - memset (&p, 0, sizeof (struct prefix_ipv4));
11555 - p.family = AF_INET;
11556 - p.prefixlen = IPV4_MAX_PREFIXLEN;
11557 - p.prefix = addr;
11559 - rn = route_node_match (rib_table_ipv4, (struct prefix *) &p);
11561 - while (rn)
11563 - route_unlock_node (rn);
11565 - /* Pick up selected route. */
11566 - for (match = rn->info; match; match = match->next)
11567 - if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
11568 - break;
11570 - /* If there is no selected route or matched route is EGP, go up
11571 - tree. */
11572 - if (! match
11573 - || match->type == ZEBRA_ROUTE_BGP)
11575 - do {
11576 - rn = rn->parent;
11577 - } while (rn && rn->info == NULL);
11578 - if (rn)
11579 - route_lock_node (rn);
11581 - else
11583 - if (match->type == ZEBRA_ROUTE_CONNECT)
11584 - /* Directly point connected route. */
11585 - return match;
11586 - else
11588 - for (newhop = match->nexthop; newhop; newhop = newhop->next)
11589 - if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB))
11590 - return match;
11591 - return NULL;
11595 - return NULL;
11598 -struct rib *
11599 -rib_lookup_ipv4 (struct prefix_ipv4 *p)
11601 - struct route_node *rn;
11602 - struct rib *match;
11603 - struct nexthop *nexthop;
11605 - rn = route_node_lookup (rib_table_ipv4, (struct prefix *) p);
11607 - /* No route for this prefix. */
11608 - if (! rn)
11609 - return NULL;
11611 - /* Unlock node. */
11612 - route_unlock_node (rn);
11614 - /* Pick up selected route. */
11615 - for (match = rn->info; match; match = match->next)
11616 - if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
11617 - break;
11619 - if (! match || match->type == ZEBRA_ROUTE_BGP)
11620 - return NULL;
11622 - if (match->type == ZEBRA_ROUTE_CONNECT)
11623 - return match;
11625 - for (nexthop = match->nexthop; nexthop; nexthop = nexthop->next)
11626 - if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
11627 - return match;
11629 - return NULL;
11632 -#ifdef HAVE_IPV6
11633 -struct rib *
11634 -rib_match_ipv6 (struct in6_addr *addr)
11636 - struct prefix_ipv6 p;
11637 - struct route_node *rn;
11638 - struct rib *match;
11639 - struct nexthop *newhop;
11641 - memset (&p, 0, sizeof (struct prefix_ipv6));
11642 - p.family = AF_INET6;
11643 - p.prefixlen = IPV6_MAX_PREFIXLEN;
11644 - IPV6_ADDR_COPY (&p.prefix, addr);
11646 - rn = route_node_match (rib_table_ipv6, (struct prefix *) &p);
11648 - while (rn)
11650 - route_unlock_node (rn);
11652 - /* Pick up selected route. */
11653 - for (match = rn->info; match; match = match->next)
11654 - if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED))
11655 - break;
11657 - /* If there is no selected route or matched route is EGP, go up
11658 - tree. */
11659 - if (! match
11660 - || match->type == ZEBRA_ROUTE_BGP)
11662 - do {
11663 - rn = rn->parent;
11664 - } while (rn && rn->info == NULL);
11665 - if (rn)
11666 - route_lock_node (rn);
11668 - else
11670 - if (match->type == ZEBRA_ROUTE_CONNECT)
11671 - /* Directly point connected route. */
11672 - return match;
11673 - else
11675 - for (newhop = match->nexthop; newhop; newhop = newhop->next)
11676 - if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB))
11677 - return match;
11678 - return NULL;
11682 - return NULL;
11684 -#endif /* HAVE_IPV6 */
11686 -int
11687 -nexthop_active_check (struct route_node *rn, struct rib *rib,
11688 - struct nexthop *nexthop, int set)
11690 - struct interface *ifp;
11692 - switch (nexthop->type)
11694 - case NEXTHOP_TYPE_IFINDEX:
11695 - ifp = if_lookup_by_index (nexthop->ifindex);
11696 - if (ifp && if_is_up (ifp))
11697 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11698 - else
11699 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11700 - break;
11701 - case NEXTHOP_TYPE_IFNAME:
11702 - case NEXTHOP_TYPE_IPV6_IFNAME:
11703 - ifp = if_lookup_by_name (nexthop->ifname);
11704 - if (ifp && if_is_up (ifp))
11706 - if (set)
11707 - nexthop->ifindex = ifp->ifindex;
11708 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11710 - else
11712 - if (set)
11713 - nexthop->ifindex = 0;
11714 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11716 - break;
11717 - case NEXTHOP_TYPE_IPV4:
11718 - case NEXTHOP_TYPE_IPV4_IFINDEX:
11719 - if (nexthop_active_ipv4 (rib, nexthop, set, rn))
11720 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11721 - else
11722 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11723 - break;
11724 -#ifdef HAVE_IPV6
11725 - case NEXTHOP_TYPE_IPV6:
11726 - if (nexthop_active_ipv6 (rib, nexthop, set, rn))
11727 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11728 - else
11729 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11730 - break;
11731 - case NEXTHOP_TYPE_IPV6_IFINDEX:
11732 - if (IN6_IS_ADDR_LINKLOCAL (&nexthop->gate.ipv6))
11734 - ifp = if_lookup_by_index (nexthop->ifindex);
11735 - if (ifp && if_is_up (ifp))
11736 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11737 - else
11738 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11740 - else
11742 - if (nexthop_active_ipv6 (rib, nexthop, set, rn))
11743 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11744 - else
11745 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11747 - break;
11748 -#endif /* HAVE_IPV6 */
11749 - default:
11750 - break;
11752 - return CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11755 -int
11756 -nexthop_active_update (struct route_node *rn, struct rib *rib, int set)
11758 - struct nexthop *nexthop;
11759 - int active;
11761 - rib->nexthop_active_num = 0;
11762 - UNSET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED);
11764 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
11766 - active = CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
11767 - rib->nexthop_active_num += nexthop_active_check (rn, rib, nexthop, set);
11768 - if (active != CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
11769 - SET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED);
11771 - return rib->nexthop_active_num;
11774 -#define RIB_SYSTEM_ROUTE(R) \
11775 - ((R)->type == ZEBRA_ROUTE_KERNEL || (R)->type == ZEBRA_ROUTE_CONNECT)
11777 -void
11778 -newrib_free (struct rib *rib)
11780 - struct nexthop *nexthop;
11781 - struct nexthop *next;
11783 - for (nexthop = rib->nexthop; nexthop; nexthop = next)
11785 - next = nexthop->next;
11786 - nexthop_free (nexthop);
11788 - XFREE (MTYPE_RIB, rib);
11791 -void
11792 -rib_install_kernel (struct route_node *rn, struct rib *rib)
11794 - int ret = 0;
11795 - struct nexthop *nexthop;
11797 - switch (PREFIX_FAMILY (&rn->p))
11799 - case AF_INET:
11800 - ret = kernel_add_ipv4 (&rn->p, rib);
11801 - break;
11802 -#ifdef HAVE_IPV6
11803 - case AF_INET6:
11804 - ret = kernel_add_ipv6 (&rn->p, rib);
11805 - break;
11806 -#endif /* HAVE_IPV6 */
11809 - if (ret < 0)
11811 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
11812 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
11816 -/* Uninstall the route from kernel. */
11817 -int
11818 -rib_uninstall_kernel (struct route_node *rn, struct rib *rib)
11820 - int ret = 0;
11821 - struct nexthop *nexthop;
11823 - switch (PREFIX_FAMILY (&rn->p))
11825 - case AF_INET:
11826 - ret = kernel_delete_ipv4 (&rn->p, rib);
11827 - break;
11828 -#ifdef HAVE_IPV6
11829 - case AF_INET6:
11830 - ret = kernel_delete_ipv6 (&rn->p, rib);
11831 - break;
11832 -#endif /* HAVE_IPV6 */
11835 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
11836 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
11838 - return ret;
11841 -/* Uninstall the route from kernel. */
11842 -void
11843 -rib_uninstall (struct route_node *rn, struct rib *rib)
11845 - if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
11847 - redistribute_delete (&rn->p, rib);
11848 - if (! RIB_SYSTEM_ROUTE (rib))
11849 - rib_uninstall_kernel (rn, rib);
11850 - UNSET_FLAG (rib->flags, ZEBRA_FLAG_SELECTED);
11854 -/* Core function for processing routing information base. */
11855 -void
11856 -rib_process (struct route_node *rn, struct rib *del)
11858 - struct rib *rib;
11859 - struct rib *next;
11860 - struct rib *fib = NULL;
11861 - struct rib *select = NULL;
11863 - for (rib = rn->info; rib; rib = next)
11865 - next = rib->next;
11867 - /* Currently installed rib. */
11868 - if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
11869 - fib = rib;
11871 - /* Skip unreachable nexthop. */
11872 - if (! nexthop_active_update (rn, rib, 0))
11873 - continue;
11875 - /* Infinit distance. */
11876 - if (rib->distance == DISTANCE_INFINITY)
11877 - continue;
11879 - /* Newly selected rib. */
11880 - if (! select || rib->distance < select->distance
11881 - || rib->type == ZEBRA_ROUTE_CONNECT)
11882 - select = rib;
11885 - /* Deleted route check. */
11886 - if (del && CHECK_FLAG (del->flags, ZEBRA_FLAG_SELECTED))
11887 - fib = del;
11889 - /* Same route is selected. */
11890 - if (select && select == fib)
11892 - if (CHECK_FLAG (select->flags, ZEBRA_FLAG_CHANGED))
11894 - redistribute_delete (&rn->p, select);
11895 - if (! RIB_SYSTEM_ROUTE (select))
11896 - rib_uninstall_kernel (rn, select);
11898 - /* Set real nexthop. */
11899 - nexthop_active_update (rn, select, 1);
11901 - if (! RIB_SYSTEM_ROUTE (select))
11902 - rib_install_kernel (rn, select);
11903 - redistribute_add (&rn->p, select);
11905 - return;
11908 - /* Uninstall old rib from forwarding table. */
11909 - if (fib)
11911 - redistribute_delete (&rn->p, fib);
11912 - if (! RIB_SYSTEM_ROUTE (fib))
11913 - rib_uninstall_kernel (rn, fib);
11914 - UNSET_FLAG (fib->flags, ZEBRA_FLAG_SELECTED);
11916 - /* Set real nexthop. */
11917 - nexthop_active_update (rn, fib, 1);
11920 - /* Install new rib into forwarding table. */
11921 - if (select)
11923 - /* Set real nexthop. */
11924 - nexthop_active_update (rn, select, 1);
11926 - if (! RIB_SYSTEM_ROUTE (select))
11927 - rib_install_kernel (rn, select);
11928 - SET_FLAG (select->flags, ZEBRA_FLAG_SELECTED);
11929 - redistribute_add (&rn->p, select);
11933 -/* Add RIB to head of the route node. */
11934 -void
11935 -rib_addnode (struct route_node *rn, struct rib *rib)
11937 - struct rib *head;
11939 - head = rn->info;
11940 - if (head)
11941 - head->prev = rib;
11942 - rib->next = head;
11943 - rn->info = rib;
11946 -void
11947 -rib_delnode (struct route_node *rn, struct rib *rib)
11949 - if (rib->next)
11950 - rib->next->prev = rib->prev;
11951 - if (rib->prev)
11952 - rib->prev->next = rib->next;
11953 - else
11954 - rn->info = rib->next;
11957 -int
11958 -rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
11959 - struct in_addr *gate, unsigned int ifindex, int table,
11960 - u_int32_t metric, u_char distance)
11962 - struct rib *rib;
11963 - struct rib *same = NULL;
11964 - struct route_node *rn;
11965 - struct nexthop *nexthop;
11967 - /* Make it sure prefixlen is applied to the prefix. */
11968 - apply_mask_ipv4 (p);
11970 - /* Set default distance by route type. */
11971 - if (distance == 0)
11973 - distance = route_info[type].distance;
11975 - /* iBGP distance is 200. */
11976 - if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP))
11977 - distance = 200;
11980 - /* Lookup route node.*/
11981 - rn = route_node_get (rib_table_ipv4, (struct prefix *) p);
11983 - /* If same type of route are installed, treat it as a implicit
11984 - withdraw. */
11985 - for (rib = rn->info; rib; rib = rib->next)
11987 - if (rib->type == ZEBRA_ROUTE_CONNECT)
11989 - nexthop = rib->nexthop;
11991 - /* Duplicate connected route comes in. */
11992 - if (rib->type == type
11993 - && (! table || rib->table == table)
11994 - && nexthop && nexthop->type == NEXTHOP_TYPE_IFINDEX
11995 - && nexthop->ifindex == ifindex)
11997 - rib->refcnt++;
11998 - return 0 ;
12001 - else if (rib->type == type
12002 - && (! table || rib->table == table))
12004 - same = rib;
12005 - rib_delnode (rn, same);
12006 - route_unlock_node (rn);
12007 - break;
12011 - /* Allocate new rib structure. */
12012 - rib = XMALLOC (MTYPE_RIB, sizeof (struct rib));
12013 - memset (rib, 0, sizeof (struct rib));
12014 - rib->type = type;
12015 - rib->distance = distance;
12016 - rib->flags = flags;
12017 - rib->metric = metric;
12018 - rib->table = table;
12019 - rib->nexthop_num = 0;
12020 - rib->uptime = time (NULL);
12022 - /* Nexthop settings. */
12023 - if (gate)
12025 - if (ifindex)
12026 - nexthop_ipv4_ifindex_add (rib, gate, ifindex);
12027 - else
12028 - nexthop_ipv4_add (rib, gate);
12030 - else
12031 - nexthop_ifindex_add (rib, ifindex);
12033 - /* If this route is kernel route, set FIB flag to the route. */
12034 - if (type == ZEBRA_ROUTE_KERNEL || type == ZEBRA_ROUTE_CONNECT)
12035 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
12036 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
12038 - /* Link new rib to node.*/
12039 - rib_addnode (rn, rib);
12041 - /* Process this route node. */
12042 - rib_process (rn, same);
12044 - /* Free implicit route.*/
12045 - if (same)
12046 - newrib_free (same);
12048 - return 0;
12051 -int
12052 -rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib)
12054 - struct route_node *rn;
12055 - struct rib *same;
12056 - struct nexthop *nexthop;
12058 - /* Make it sure prefixlen is applied to the prefix. */
12059 - apply_mask_ipv4 (p);
12061 - /* Set default distance by route type. */
12062 - if (rib->distance == 0)
12064 - rib->distance = route_info[rib->type].distance;
12066 - /* iBGP distance is 200. */
12067 - if (rib->type == ZEBRA_ROUTE_BGP
12068 - && CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
12069 - rib->distance = 200;
12072 - /* Lookup route node.*/
12073 - rn = route_node_get (rib_table_ipv4, (struct prefix *) p);
12075 - /* If same type of route are installed, treat it as a implicit
12076 - withdraw. */
12077 - for (same = rn->info; same; same = same->next)
12079 - if (same->type == rib->type && same->table == rib->table
12080 - && same->type != ZEBRA_ROUTE_CONNECT)
12082 - rib_delnode (rn, same);
12083 - route_unlock_node (rn);
12084 - break;
12088 - /* If this route is kernel route, set FIB flag to the route. */
12089 - if (rib->type == ZEBRA_ROUTE_KERNEL || rib->type == ZEBRA_ROUTE_CONNECT)
12090 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
12091 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
12093 - /* Link new rib to node.*/
12094 - rib_addnode (rn, rib);
12096 - /* Process this route node. */
12097 - rib_process (rn, same);
12099 - /* Free implicit route.*/
12100 - if (same)
12101 - newrib_free (same);
12103 - return 0;
12106 -int
12107 -rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
12108 - struct in_addr *gate, unsigned int ifindex, int table)
12110 - struct route_node *rn;
12111 - struct rib *rib;
12112 - struct rib *fib = NULL;
12113 - struct rib *same = NULL;
12114 - struct nexthop *nexthop;
12115 - char buf1[BUFSIZ];
12116 - char buf2[BUFSIZ];
12118 - /* Apply mask. */
12119 - apply_mask_ipv4 (p);
12121 - /* Lookup route node. */
12122 - rn = route_node_lookup (rib_table_ipv4, (struct prefix *) p);
12123 - if (! rn)
12125 - if (IS_ZEBRA_DEBUG_KERNEL)
12127 - if (gate)
12128 - zlog_info ("route %s/%d via %s ifindex %d doesn't exist in rib",
12129 - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
12130 - p->prefixlen,
12131 - inet_ntop (AF_INET, gate, buf2, BUFSIZ),
12132 - ifindex);
12133 - else
12134 - zlog_info ("route %s/%d ifindex %d doesn't exist in rib",
12135 - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
12136 - p->prefixlen,
12137 - ifindex);
12139 - return ZEBRA_ERR_RTNOEXIST;
12142 - /* Lookup same type route. */
12143 - for (rib = rn->info; rib; rib = rib->next)
12145 - if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
12146 - fib = rib;
12148 - if (rib->type == ZEBRA_ROUTE_CONNECT)
12150 - nexthop = rib->nexthop;
12152 - if (rib->type == type
12153 - && (! table || rib->table == table)
12154 - && nexthop && nexthop->type == NEXTHOP_TYPE_IFINDEX
12155 - && nexthop->ifindex == ifindex)
12157 - if (rib->refcnt)
12159 - rib->refcnt--;
12160 - route_unlock_node (rn);
12161 - route_unlock_node (rn);
12162 - return 0;
12164 - same = rib;
12165 - break;
12168 - else
12170 - if (rib->type == type
12171 - && (!table || rib->table == table))
12173 - same = rib;
12174 - break;
12179 - /* If same type of route can't be found and this message is from
12180 - kernel. */
12181 - if (! same)
12183 - if (fib && type == ZEBRA_ROUTE_KERNEL)
12185 - /* Unset flags. */
12186 - for (nexthop = fib->nexthop; nexthop; nexthop = nexthop->next)
12187 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
12189 - UNSET_FLAG (fib->flags, ZEBRA_FLAG_SELECTED);
12191 - else
12193 - if (IS_ZEBRA_DEBUG_KERNEL)
12195 - if (gate)
12196 - zlog_info ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
12197 - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
12198 - p->prefixlen,
12199 - inet_ntop (AF_INET, gate, buf2, BUFSIZ),
12200 - ifindex,
12201 - type);
12202 - else
12203 - zlog_info ("route %s/%d ifindex %d type %d doesn't exist in rib",
12204 - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
12205 - p->prefixlen,
12206 - ifindex,
12207 - type);
12209 - route_unlock_node (rn);
12210 - return ZEBRA_ERR_RTNOEXIST;
12214 - if (same)
12215 - rib_delnode (rn, same);
12217 - /* Process changes. */
12218 - rib_process (rn, same);
12220 - if (same)
12222 - newrib_free (same);
12223 - route_unlock_node (rn);
12226 - route_unlock_node (rn);
12228 - return 0;
12231 -/* Delete all added route and close rib. */
12232 -void
12233 -rib_close_ipv4 ()
12235 - struct route_node *rn;
12236 - struct rib *rib;
12238 - for (rn = route_top (rib_table_ipv4); rn; rn = route_next (rn))
12239 - for (rib = rn->info; rib; rib = rib->next)
12240 - if (! RIB_SYSTEM_ROUTE (rib)
12241 - && CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
12242 - rib_uninstall_kernel (rn, rib);
12245 -/* Install static route into rib. */
12246 -void
12247 -static_ipv4_install (struct prefix_ipv4 *p, struct static_ipv4 *si)
12249 - struct rib *rib;
12250 - struct route_node *rn;
12252 - /* Lookup existing route */
12253 - rn = route_node_get (rib_table_ipv4, (struct prefix *) p);
12254 - for (rib = rn->info; rib; rib = rib->next)
12255 - if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
12256 - break;
12258 - if (rib)
12260 - /* Same distance static route is there. Update it with new
12261 - nexthop. */
12262 - rib_uninstall (rn, rib);
12263 - route_unlock_node (rn);
12265 - switch (si->type)
12267 - case STATIC_IPV4_GATEWAY:
12268 - nexthop_ipv4_add (rib, &si->gate.ipv4);
12269 - break;
12270 - case STATIC_IPV4_IFNAME:
12271 - nexthop_ifname_add (rib, si->gate.ifname);
12272 - break;
12274 - rib_process (rn, NULL);
12276 - else
12278 - /* This is new static route. */
12279 - rib = XMALLOC (MTYPE_RIB, sizeof (struct rib));
12280 - memset (rib, 0, sizeof (struct rib));
12282 - rib->type = ZEBRA_ROUTE_STATIC;
12283 - rib->distance = si->distance;
12284 - rib->metric = 0;
12285 - rib->nexthop_num = 0;
12287 - switch (si->type)
12289 - case STATIC_IPV4_GATEWAY:
12290 - nexthop_ipv4_add (rib, &si->gate.ipv4);
12291 - break;
12292 - case STATIC_IPV4_IFNAME:
12293 - nexthop_ifname_add (rib, si->gate.ifname);
12294 - break;
12297 - /* Link this rib to the tree. */
12298 - rib_addnode (rn, rib);
12300 - /* Process this prefix. */
12301 - rib_process (rn, NULL);
12305 -int
12306 -static_ipv4_nexthop_same (struct nexthop *nexthop, struct static_ipv4 *si)
12308 - if (nexthop->type == NEXTHOP_TYPE_IPV4
12309 - && si->type == STATIC_IPV4_GATEWAY
12310 - && IPV4_ADDR_SAME (&nexthop->gate.ipv4, &si->gate.ipv4))
12311 - return 1;
12312 - if (nexthop->type == NEXTHOP_TYPE_IFNAME
12313 - && si->type == STATIC_IPV4_IFNAME
12314 - && strcmp (nexthop->ifname, si->gate.ifname) == 0)
12315 - return 1;
12316 - return 0;;
12319 -/* Uninstall static route from RIB. */
12320 -void
12321 -static_ipv4_uninstall (struct prefix_ipv4 *p, struct static_ipv4 *si)
12323 - struct route_node *rn;
12324 - struct rib *rib;
12325 - struct nexthop *nexthop;
12327 - /* Lookup existing route with type and distance. */
12328 - rn = route_node_lookup (rib_table_ipv4, (struct prefix *) p);
12329 - if (! rn)
12330 - return;
12332 - for (rib = rn->info; rib; rib = rib->next)
12333 - if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
12334 - break;
12335 - if (! rib)
12337 - route_unlock_node (rn);
12338 - return;
12341 - /* Lookup nexthop. */
12342 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
12343 - if (static_ipv4_nexthop_same (nexthop, si))
12344 - break;
12346 - /* Can't find nexthop. */
12347 - if (! nexthop)
12349 - route_unlock_node (rn);
12350 - return;
12353 - /* Check nexthop. */
12354 - if (rib->nexthop_num == 1)
12356 - rib_delnode (rn, rib);
12357 - rib_process (rn, rib);
12358 - newrib_free (rib);
12359 - route_unlock_node (rn);
12361 - else
12363 - rib_uninstall (rn, rib);
12364 - nexthop_delete (rib, nexthop);
12365 - nexthop_free (nexthop);
12366 - rib_process (rn, rib);
12369 - /* Unlock node. */
12370 - route_unlock_node (rn);
12373 -/* Add static route into static route configuration. */
12374 -int
12375 -static_ipv4_add (struct prefix_ipv4 *p, struct in_addr *gate, char *ifname,
12376 - u_char distance, int table)
12378 - u_char type = 0;
12379 - struct route_node *rn;
12380 - struct static_ipv4 *si;
12381 - struct static_ipv4 *pp;
12382 - struct static_ipv4 *cp;
12384 - /* Lookup static route prefix. */
12385 - rn = route_node_get (static_table_ipv4, (struct prefix *) p);
12387 - /* Make flags. */
12388 - if (gate)
12389 - type = STATIC_IPV4_GATEWAY;
12390 - if (ifname)
12391 - type = STATIC_IPV4_IFNAME;
12393 - /* Do nothing if there is a same static route. */
12394 - for (si = rn->info; si; si = si->next)
12396 - if (distance == si->distance
12397 - && type == si->type
12398 - && (! gate || IPV4_ADDR_SAME (gate, &si->gate.ipv4))
12399 - && (! ifname || strcmp (ifname, si->gate.ifname) == 0))
12401 - route_unlock_node (rn);
12402 - return 0;
12406 - /* Make new static route structure. */
12407 - si = XMALLOC (MTYPE_STATIC_IPV4, sizeof (struct static_ipv4));
12408 - memset (si, 0, sizeof (struct static_ipv4));
12410 - si->type = type;
12411 - si->distance = distance;
12413 - if (gate)
12414 - si->gate.ipv4 = *gate;
12415 - if (ifname)
12416 - si->gate.ifname = XSTRDUP (0, ifname);
12418 - /* Add new static route information to the tree with sort by
12419 - distance value and gateway address. */
12420 - for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next)
12422 - if (si->distance < cp->distance)
12423 - break;
12424 - if (si->distance > cp->distance)
12425 - continue;
12426 - if (si->type == STATIC_IPV4_GATEWAY && cp->type == STATIC_IPV4_GATEWAY)
12428 - if (ntohl (si->gate.ipv4.s_addr) < ntohl (cp->gate.ipv4.s_addr))
12429 - break;
12430 - if (ntohl (si->gate.ipv4.s_addr) > ntohl (cp->gate.ipv4.s_addr))
12431 - continue;
12435 - /* Make linked list. */
12436 - if (pp)
12437 - pp->next = si;
12438 - else
12439 - rn->info = si;
12440 - if (cp)
12441 - cp->prev = si;
12442 - si->prev = pp;
12443 - si->next = cp;
12445 - /* Install into rib. */
12446 - static_ipv4_install (p, si);
12448 - return 1;
12451 -/* Delete static route from static route configuration. */
12452 -int
12453 -static_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *gate, char *ifname,
12454 - u_char distance, int table)
12456 - u_char type = 0;
12457 - struct route_node *rn;
12458 - struct static_ipv4 *si;
12460 - /* Lookup static route prefix. */
12461 - rn = route_node_lookup (static_table_ipv4, (struct prefix *) p);
12462 - if (! rn)
12463 - return 0;
12465 - /* Make flags. */
12466 - if (gate)
12467 - type = STATIC_IPV4_GATEWAY;
12468 - if (ifname)
12469 - type = STATIC_IPV4_IFNAME;
12471 - /* Find same static route is the tree */
12472 - for (si = rn->info; si; si = si->next)
12473 - if (distance == si->distance
12474 - && type == si->type
12475 - && (! gate || IPV4_ADDR_SAME (gate, &si->gate.ipv4))
12476 - && (! ifname || strcmp (ifname, si->gate.ifname) == 0))
12477 - break;
12479 - /* Can't find static route. */
12480 - if (! si)
12482 - route_unlock_node (rn);
12483 - return 0;
12486 - /* Install into rib. */
12487 - static_ipv4_uninstall (p, si);
12489 - /* Unlink static route from linked list. */
12490 - if (si->prev)
12491 - si->prev->next = si->next;
12492 - else
12493 - rn->info = si->next;
12494 - if (si->next)
12495 - si->next->prev = si->prev;
12497 - /* Free static route configuration. */
12498 - XFREE (MTYPE_STATIC_IPV4, si);
12500 - return 1;
12503 -/* Write IPv4 static route configuration. */
12504 -int
12505 -static_ipv4_write (struct vty *vty)
12507 - struct route_node *rn;
12508 - struct static_ipv4 *si;
12509 - int write;
12511 - write = 0;
12513 - for (rn = route_top (static_table_ipv4); rn; rn = route_next (rn))
12514 - for (si = rn->info; si; si = si->next)
12516 - vty_out (vty, "ip route %s/%d", inet_ntoa (rn->p.u.prefix4),
12517 - rn->p.prefixlen);
12519 - switch (si->type)
12521 - case STATIC_IPV4_GATEWAY:
12522 - vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
12523 - break;
12524 - case STATIC_IPV4_IFNAME:
12525 - vty_out (vty, " %s", si->gate.ifname);
12526 - break;
12529 - if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
12530 - vty_out (vty, " %d", si->distance);
12531 - vty_out (vty, "%s", VTY_NEWLINE);
12533 - write = 1;
12535 - return write;
12538 -/* General fucntion for static route. */
12539 -int
12540 -static_ipv4_func (struct vty *vty, int add_cmd,
12541 - char *dest_str, char *mask_str, char *gate_str,
12542 - char *distance_str)
12544 - int ret;
12545 - u_char distance;
12546 - struct prefix_ipv4 p;
12547 - struct in_addr gate;
12548 - struct in_addr mask;
12549 - char *ifname;
12550 - int table = rtm_table_default;
12552 - ret = str2prefix_ipv4 (dest_str, &p);
12553 - if (ret <= 0)
12555 - vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
12556 - return CMD_WARNING;
12559 - /* Cisco like mask notation. */
12560 - if (mask_str)
12562 - ret = inet_aton (mask_str, &mask);
12563 - if (ret == 0)
12565 - vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
12566 - return CMD_WARNING;
12568 - p.prefixlen = ip_masklen (mask);
12571 - /* Apply mask for given prefix. */
12572 - apply_mask_ipv4 (&p);
12574 - /* Administrative distance. */
12575 - if (distance_str)
12576 - distance = atoi (distance_str);
12577 - else
12578 - distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
12580 - /* When gateway is A.B.C.D format, gate is treated as nexthop
12581 - address other case gate is treated as interface name. */
12582 - ret = inet_aton (gate_str, &gate);
12583 - if (ret)
12584 - ifname = NULL;
12585 - else
12586 - ifname = gate_str;
12588 - if (add_cmd)
12589 - static_ipv4_add (&p, ifname ? NULL : &gate, ifname, distance, table);
12590 - else
12591 - static_ipv4_delete (&p, ifname ? NULL : &gate, ifname, distance, table);
12593 - return CMD_SUCCESS;
12596 -/* Static route configuration. */
12597 -DEFUN (ip_route,
12598 - ip_route_cmd,
12599 - "ip route A.B.C.D/M (A.B.C.D|INTERFACE)",
12600 - IP_STR
12601 - "Establish static routes\n"
12602 - "IP destination prefix (e.g. 10.0.0.0/8)\n"
12603 - "IP gateway address\n"
12604 - "IP gateway interface name\n")
12606 - return static_ipv4_func (vty, 1, argv[0], NULL, argv[1], NULL);
12609 -DEFUN (ip_route_mask,
12610 - ip_route_mask_cmd,
12611 - "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE)",
12612 - IP_STR
12613 - "Establish static routes\n"
12614 - "IP destination prefix\n"
12615 - "IP destination prefix mask\n"
12616 - "IP gateway address\n"
12617 - "IP gateway interface name\n")
12619 - return static_ipv4_func (vty, 1, argv[0], argv[1], argv[2], NULL);
12622 -DEFUN (ip_route_pref,
12623 - ip_route_pref_cmd,
12624 - "ip route A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
12625 - IP_STR
12626 - "Establish static routes\n"
12627 - "IP destination prefix (e.g. 10.0.0.0/8)\n"
12628 - "IP gateway address\n"
12629 - "IP gateway interface name\n"
12630 - "Distance value for this route\n")
12632 - return static_ipv4_func (vty, 1, argv[0], NULL, argv[1], argv[2]);
12635 -DEFUN (ip_route_mask_pref,
12636 - ip_route_mask_pref_cmd,
12637 - "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) <1-255>",
12638 - IP_STR
12639 - "Establish static routes\n"
12640 - "IP destination prefix\n"
12641 - "IP destination prefix mask\n"
12642 - "IP gateway address\n"
12643 - "IP gateway interface name\n"
12644 - "Distance value for this route\n")
12646 - return static_ipv4_func (vty, 1, argv[0], argv[1], argv[2], argv[3]);
12649 -DEFUN (no_ip_route,
12650 - no_ip_route_cmd,
12651 - "no ip route A.B.C.D/M (A.B.C.D|INTERFACE)",
12652 - NO_STR
12653 - IP_STR
12654 - "Establish static routes\n"
12655 - "IP destination prefix (e.g. 10.0.0.0/8)\n"
12656 - "IP gateway address\n"
12657 - "IP gateway interface name\n")
12659 - return static_ipv4_func (vty, 0, argv[0], NULL, argv[1], NULL);
12662 -DEFUN (no_ip_route_mask,
12663 - no_ip_route_mask_cmd,
12664 - "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE)",
12665 - NO_STR
12666 - IP_STR
12667 - "Establish static routes\n"
12668 - "IP destination prefix\n"
12669 - "IP destination prefix mask\n"
12670 - "IP gateway address\n"
12671 - "IP gateway interface name\n")
12673 - return static_ipv4_func (vty, 0, argv[0], argv[1], argv[2], NULL);
12676 -DEFUN (no_ip_route_pref,
12677 - no_ip_route_pref_cmd,
12678 - "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
12679 - NO_STR
12680 - IP_STR
12681 - "Establish static routes\n"
12682 - "IP destination prefix (e.g. 10.0.0.0/8)\n"
12683 - "IP gateway address\n"
12684 - "IP gateway interface name\n"
12685 - "Distance value for this route\n")
12687 - return static_ipv4_func (vty, 0, argv[0], NULL, argv[1], argv[2]);
12690 -DEFUN (no_ip_route_mask_pref,
12691 - no_ip_route_mask_pref_cmd,
12692 - "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) <1-255>",
12693 - NO_STR
12694 - IP_STR
12695 - "Establish static routes\n"
12696 - "IP destination prefix\n"
12697 - "IP destination prefix mask\n"
12698 - "IP gateway address\n"
12699 - "IP gateway interface name\n"
12700 - "Distance value for this route\n")
12702 - return static_ipv4_func (vty, 0, argv[0], argv[1], argv[2], argv[3]);
12705 -/* New RIB. Detailed information for IPv4 route. */
12706 -void
12707 -vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
12709 - struct rib *rib;
12710 - struct nexthop *nexthop;
12712 - for (rib = rn->info; rib; rib = rib->next)
12714 - vty_out (vty, "Routing entry for %s/%d%s",
12715 - inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12716 - VTY_NEWLINE);
12717 - vty_out (vty, " Known via \"%s\"", route_info[rib->type].str);
12718 - vty_out (vty, ", distance %d, metric %d", rib->distance, rib->metric);
12719 - if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
12720 - vty_out (vty, ", best");
12721 - if (rib->refcnt)
12722 - vty_out (vty, ", refcnt %ld", rib->refcnt);
12723 - vty_out (vty, "%s", VTY_NEWLINE);
12725 -#define ONE_DAY_SECOND 60*60*24
12726 -#define ONE_WEEK_SECOND 60*60*24*7
12727 - if (rib->type == ZEBRA_ROUTE_RIP
12728 - || rib->type == ZEBRA_ROUTE_OSPF
12729 - || rib->type == ZEBRA_ROUTE_BGP)
12731 - time_t uptime;
12732 - struct tm *tm;
12734 - uptime = time (NULL);
12735 - uptime -= rib->uptime;
12736 - tm = gmtime (&uptime);
12738 - vty_out (vty, " Last update ");
12740 - if (uptime < ONE_DAY_SECOND)
12741 - vty_out (vty, "%02d:%02d:%02d",
12742 - tm->tm_hour, tm->tm_min, tm->tm_sec);
12743 - else if (uptime < ONE_WEEK_SECOND)
12744 - vty_out (vty, "%dd%02dh%02dm",
12745 - tm->tm_yday, tm->tm_hour, tm->tm_min);
12746 - else
12747 - vty_out (vty, "%02dw%dd%02dh",
12748 - tm->tm_yday/7,
12749 - tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
12750 - vty_out (vty, " ago%s", VTY_NEWLINE);
12753 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
12755 - vty_out (vty, " %c",
12756 - CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ');
12758 - switch (nexthop->type)
12760 - case NEXTHOP_TYPE_IPV4:
12761 - case NEXTHOP_TYPE_IPV4_IFINDEX:
12762 - vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
12763 - if (nexthop->ifindex)
12764 - vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
12765 - break;
12766 - case NEXTHOP_TYPE_IFINDEX:
12767 - vty_out (vty, " directly connected, %s",
12768 - ifindex2ifname (nexthop->ifindex));
12769 - break;
12770 - case NEXTHOP_TYPE_IFNAME:
12771 - vty_out (vty, " directly connected, %s",
12772 - nexthop->ifname);
12773 - break;
12774 - default:
12775 - break;
12777 - if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
12778 - vty_out (vty, " inactive");
12780 - if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
12782 - vty_out (vty, " (recursive");
12784 - switch (nexthop->rtype)
12786 - case NEXTHOP_TYPE_IPV4:
12787 - case NEXTHOP_TYPE_IPV4_IFINDEX:
12788 - vty_out (vty, " via %s)", inet_ntoa (nexthop->rgate.ipv4));
12789 - break;
12790 - case NEXTHOP_TYPE_IFINDEX:
12791 - case NEXTHOP_TYPE_IFNAME:
12792 - vty_out (vty, " is directly connected, %s)",
12793 - ifindex2ifname (nexthop->rifindex));
12794 - break;
12795 - default:
12796 - break;
12799 - vty_out (vty, "%s", VTY_NEWLINE);
12801 - vty_out (vty, "%s", VTY_NEWLINE);
12805 -void
12806 -vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
12808 - struct nexthop *nexthop;
12809 - int len = 0;
12810 - char buf[BUFSIZ];
12812 - /* Nexthop information. */
12813 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
12815 - if (nexthop == rib->nexthop)
12817 - /* Prefix information. */
12818 - len = vty_out (vty, "%c%c%c %s/%d",
12819 - route_info[rib->type].c,
12820 - CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
12821 - ? '>' : ' ',
12822 - CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
12823 - ? '*' : ' ',
12824 - inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ),
12825 - rn->p.prefixlen);
12827 - /* Distance and metric display. */
12828 - if (rib->type != ZEBRA_ROUTE_CONNECT
12829 - && rib->type != ZEBRA_ROUTE_KERNEL)
12830 - len += vty_out (vty, " [%d/%d]", rib->distance,
12831 - rib->metric);
12833 - else
12834 - vty_out (vty, " %c%*c",
12835 - CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
12836 - ? '*' : ' ',
12837 - len - 3, ' ');
12839 - switch (nexthop->type)
12841 - case NEXTHOP_TYPE_IPV4:
12842 - case NEXTHOP_TYPE_IPV4_IFINDEX:
12843 - vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
12844 - if (nexthop->ifindex)
12845 - vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
12846 - break;
12847 - case NEXTHOP_TYPE_IFINDEX:
12848 - vty_out (vty, " is directly connected, %s",
12849 - ifindex2ifname (nexthop->ifindex));
12850 - break;
12851 - case NEXTHOP_TYPE_IFNAME:
12852 - vty_out (vty, " is directly connected, %s",
12853 - nexthop->ifname);
12854 - break;
12855 - default:
12856 - break;
12858 - if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
12859 - vty_out (vty, " inactive");
12861 - if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
12863 - vty_out (vty, " (recursive");
12865 - switch (nexthop->rtype)
12867 - case NEXTHOP_TYPE_IPV4:
12868 - case NEXTHOP_TYPE_IPV4_IFINDEX:
12869 - vty_out (vty, " via %s)", inet_ntoa (nexthop->rgate.ipv4));
12870 - break;
12871 - case NEXTHOP_TYPE_IFINDEX:
12872 - case NEXTHOP_TYPE_IFNAME:
12873 - vty_out (vty, " is directly connected, %s)",
12874 - ifindex2ifname (nexthop->rifindex));
12875 - break;
12876 - default:
12877 - break;
12881 - if (rib->type == ZEBRA_ROUTE_RIP
12882 - || rib->type == ZEBRA_ROUTE_OSPF
12883 - || rib->type == ZEBRA_ROUTE_BGP)
12885 - time_t uptime;
12886 - struct tm *tm;
12888 - uptime = time (NULL);
12889 - uptime -= rib->uptime;
12890 - tm = gmtime (&uptime);
12892 -#define ONE_DAY_SECOND 60*60*24
12893 -#define ONE_WEEK_SECOND 60*60*24*7
12895 - if (uptime < ONE_DAY_SECOND)
12896 - vty_out (vty, ", %02d:%02d:%02d",
12897 - tm->tm_hour, tm->tm_min, tm->tm_sec);
12898 - else if (uptime < ONE_WEEK_SECOND)
12899 - vty_out (vty, ", %dd%02dh%02dm",
12900 - tm->tm_yday, tm->tm_hour, tm->tm_min);
12901 - else
12902 - vty_out (vty, ", %02dw%dd%02dh",
12903 - tm->tm_yday/7,
12904 - tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
12906 - vty_out (vty, "%s", VTY_NEWLINE);
12910 -#define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,%s B - BGP, > - selected route, * - FIB route%s%s"
12912 -DEFUN (show_ip_route,
12913 - show_ip_route_cmd,
12914 - "show ip route",
12915 - SHOW_STR
12916 - IP_STR
12917 - "IP routing table\n")
12919 - struct route_node *rn;
12920 - struct rib *rib;
12921 - int first = 1;
12923 - /* Show all IPv4 routes. */
12924 - for (rn = route_top (rib_table_ipv4); rn; rn = route_next (rn))
12925 - for (rib = rn->info; rib; rib = rib->next)
12927 - if (first)
12929 - vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12930 - first = 0;
12932 - vty_show_ip_route (vty, rn, rib);
12934 - return CMD_SUCCESS;
12937 -DEFUN (show_ip_route_prefix_longer,
12938 - show_ip_route_prefix_longer_cmd,
12939 - "show ip route A.B.C.D/M longer-prefixes",
12940 - SHOW_STR
12941 - IP_STR
12942 - "IP routing table\n"
12943 - "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
12944 - "Show route matching the specified Network/Mask pair only\n")
12946 - struct route_node *rn;
12947 - struct rib *rib;
12948 - struct prefix p;
12949 - int ret;
12950 - int first = 1;
12952 - ret = str2prefix (argv[0], &p);
12953 - if (! ret)
12955 - vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
12956 - return CMD_WARNING;
12959 - /* Show matched type IPv4 routes. */
12960 - for (rn = route_top (rib_table_ipv4); rn; rn = route_next (rn))
12961 - for (rib = rn->info; rib; rib = rib->next)
12962 - if (prefix_match (&p, &rn->p))
12964 - if (first)
12966 - vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12967 - first = 0;
12969 - vty_show_ip_route (vty, rn, rib);
12971 - return CMD_SUCCESS;
12974 -DEFUN (show_ip_route_supernets,
12975 - show_ip_route_supernets_cmd,
12976 - "show ip route supernets-only",
12977 - SHOW_STR
12978 - IP_STR
12979 - "IP routing table\n"
12980 - "Show supernet entries only\n")
12982 - struct route_node *rn;
12983 - struct rib *rib;
12984 - u_int32_t addr;
12985 - int first = 1;
12988 - /* Show matched type IPv4 routes. */
12989 - for (rn = route_top (rib_table_ipv4); rn; rn = route_next (rn))
12990 - for (rib = rn->info; rib; rib = rib->next)
12992 - addr = ntohl (rn->p.u.prefix4.s_addr);
12994 - if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
12995 - || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
12996 - || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
12998 - if (first)
13000 - vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
13001 - first = 0;
13003 - vty_show_ip_route (vty, rn, rib);
13006 - return CMD_SUCCESS;
13010 -DEFUN (show_ip_route_protocol,
13011 - show_ip_route_protocol_cmd,
13012 - "show ip route (bgp|connected|kernel|ospf|rip|static)",
13013 - SHOW_STR
13014 - IP_STR
13015 - "IP routing table\n"
13016 - "Border Gateway Protocol (BGP)\n"
13017 - "Connected\n"
13018 - "Kernel\n"
13019 - "Open Shortest Path First (OSPF)\n"
13020 - "Routing Information Protocol (RIP)\n"
13021 - "Static routes\n")
13023 - int type;
13024 - struct route_node *rn;
13025 - struct rib *rib;
13026 - int first = 1;
13028 - if (strncmp (argv[0], "b", 1) == 0)
13029 - type = ZEBRA_ROUTE_BGP;
13030 - else if (strncmp (argv[0], "c", 1) == 0)
13031 - type = ZEBRA_ROUTE_CONNECT;
13032 - else if (strncmp (argv[0], "k", 1) ==0)
13033 - type = ZEBRA_ROUTE_KERNEL;
13034 - else if (strncmp (argv[0], "o", 1) == 0)
13035 - type = ZEBRA_ROUTE_OSPF;
13036 - else if (strncmp (argv[0], "r", 1) == 0)
13037 - type = ZEBRA_ROUTE_RIP;
13038 - else if (strncmp (argv[0], "s", 1) == 0)
13039 - type = ZEBRA_ROUTE_STATIC;
13040 - else
13042 - vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
13043 - return CMD_WARNING;
13046 - /* Show matched type IPv4 routes. */
13047 - for (rn = route_top (rib_table_ipv4); rn; rn = route_next (rn))
13048 - for (rib = rn->info; rib; rib = rib->next)
13049 - if (rib->type == type)
13051 - if (first)
13053 - vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
13054 - first = 0;
13056 - vty_show_ip_route (vty, rn, rib);
13058 - return CMD_SUCCESS;
13061 -DEFUN (show_ip_route_addr,
13062 - show_ip_route_addr_cmd,
13063 - "show ip route A.B.C.D",
13064 - SHOW_STR
13065 - IP_STR
13066 - "IP routing table\n"
13067 - "Network in the IP routing table to display\n")
13069 - int ret;
13070 - struct prefix_ipv4 p;
13071 - struct route_node *rn;
13073 - ret = str2prefix_ipv4 (argv[0], &p);
13074 - if (ret <= 0)
13076 - vty_out (vty, "Malformed IPv4 address%s", VTY_NEWLINE);
13077 - return CMD_WARNING;
13080 - rn = route_node_match (rib_table_ipv4, (struct prefix *) &p);
13081 - if (! rn)
13083 - vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
13084 - return CMD_WARNING;
13087 - vty_show_ip_route_detail (vty, rn);
13089 - route_unlock_node (rn);
13091 - return CMD_SUCCESS;
13094 -DEFUN (show_ip_route_prefix,
13095 - show_ip_route_prefix_cmd,
13096 - "show ip route A.B.C.D/M",
13097 - SHOW_STR
13098 - IP_STR
13099 - "IP routing table\n"
13100 - "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13102 - int ret;
13103 - struct prefix_ipv4 p;
13104 - struct route_node *rn;
13106 - ret = str2prefix_ipv4 (argv[0], &p);
13107 - if (ret <= 0)
13109 - vty_out (vty, "Malformed IPv4 address%s", VTY_NEWLINE);
13110 - return CMD_WARNING;
13113 - rn = route_node_match (rib_table_ipv4, (struct prefix *) &p);
13114 - if (! rn || rn->p.prefixlen != p.prefixlen)
13116 - vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
13117 - return CMD_WARNING;
13120 - vty_show_ip_route_detail (vty, rn);
13122 - route_unlock_node (rn);
13124 - return CMD_SUCCESS;
13127 -#ifdef HAVE_IPV6
13128 -int
13129 -rib_bogus_ipv6 (int type, struct prefix_ipv6 *p,
13130 - struct in6_addr *gate, unsigned int ifindex, int table)
13132 - if (type == ZEBRA_ROUTE_CONNECT && IN6_IS_ADDR_UNSPECIFIED (&p->prefix))
13133 - return 1;
13134 - if (type == ZEBRA_ROUTE_KERNEL && IN6_IS_ADDR_UNSPECIFIED (&p->prefix)
13135 - && p->prefixlen == 96 && gate && IN6_IS_ADDR_UNSPECIFIED (gate))
13137 - kernel_delete_ipv6_old (p, gate, ifindex, 0, table);
13138 - return 1;
13140 - return 0;
13143 -int
13144 -rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
13145 - struct in6_addr *gate, unsigned int ifindex, int table)
13147 - struct rib *rib;
13148 - struct rib *same = NULL;
13149 - struct route_node *rn;
13150 - struct nexthop *nexthop;
13152 - int distance;
13153 - u_int32_t metric = 0;
13155 - /* Make sure mask is applied. */
13156 - apply_mask_ipv6 (p);
13158 - /* Set default distance by route type. */
13159 - distance = route_info[type].distance;
13161 - if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP))
13162 - distance = 200;
13164 - /* Make new rib. */
13165 - if (!table)
13166 - table = RT_TABLE_MAIN;
13168 - /* Filter bogus route. */
13169 - if (rib_bogus_ipv6 (type, p, gate, ifindex, table))
13170 - return 0;
13172 - /* Lookup route node.*/
13173 - rn = route_node_get (rib_table_ipv6, (struct prefix *) p);
13175 - /* If same type of route are installed, treat it as a implicit
13176 - withdraw. */
13177 - for (rib = rn->info; rib; rib = rib->next)
13179 - if (rib->type == ZEBRA_ROUTE_CONNECT)
13181 - nexthop = rib->nexthop;
13183 - if (rib->type == type
13184 - && (! table || rib->table == table)
13185 - && nexthop && nexthop->type == NEXTHOP_TYPE_IFINDEX
13186 - && nexthop->ifindex == ifindex)
13188 - rib->refcnt++;
13189 - return 0;
13192 - else if (rib->type == type
13193 - && (! table || (rib->table == table)))
13195 - same = rib;
13196 - rib_delnode (rn, same);
13197 - route_unlock_node (rn);
13198 - break;
13202 - /* Allocate new rib structure. */
13203 - rib = XMALLOC (MTYPE_RIB, sizeof (struct rib));
13204 - memset (rib, 0, sizeof (struct rib));
13205 - rib->type = type;
13206 - rib->distance = distance;
13207 - rib->flags = flags;
13208 - rib->metric = metric;
13209 - rib->table = table;
13210 - rib->nexthop_num = 0;
13211 - rib->uptime = time (NULL);
13213 - /* Nexthop settings. */
13214 - if (gate)
13216 - if (ifindex)
13217 - nexthop_ipv6_ifindex_add (rib, gate, ifindex);
13218 - else
13219 - nexthop_ipv6_add (rib, gate);
13221 - else
13222 - nexthop_ifindex_add (rib, ifindex);
13224 - /* If this route is kernel route, set FIB flag to the route. */
13225 - if (type == ZEBRA_ROUTE_KERNEL || type == ZEBRA_ROUTE_CONNECT)
13226 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
13227 - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
13229 - /* Link new rib to node.*/
13230 - rib_addnode (rn, rib);
13232 - /* Process this route node. */
13233 - rib_process (rn, same);
13235 - /* Free implicit route.*/
13236 - if (same)
13237 - newrib_free (same);
13239 - return 0;
13242 -int
13243 -rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
13244 - struct in6_addr *gate, unsigned int ifindex, int table)
13246 - struct route_node *rn;
13247 - struct rib *rib;
13248 - struct rib *fib = NULL;
13249 - struct rib *same = NULL;
13250 - struct nexthop *nexthop;
13251 - char buf1[BUFSIZ];
13252 - char buf2[BUFSIZ];
13254 - /* Apply mask. */
13255 - apply_mask_ipv6 (p);
13257 - /* Lookup route node. */
13258 - rn = route_node_lookup (rib_table_ipv6, (struct prefix *) p);
13259 - if (! rn)
13261 - if (IS_ZEBRA_DEBUG_KERNEL)
13263 - if (gate)
13264 - zlog_info ("route %s/%d via %s ifindex %d doesn't exist in rib",
13265 - inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ),
13266 - p->prefixlen,
13267 - inet_ntop (AF_INET6, gate, buf2, BUFSIZ),
13268 - ifindex);
13269 - else
13270 - zlog_info ("route %s/%d ifindex %d doesn't exist in rib",
13271 - inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ),
13272 - p->prefixlen,
13273 - ifindex);
13275 - return ZEBRA_ERR_RTNOEXIST;
13278 - /* Lookup same type route. */
13279 - for (rib = rn->info; rib; rib = rib->next)
13281 - if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
13282 - fib = rib;
13284 - if (rib->type == ZEBRA_ROUTE_CONNECT)
13286 - nexthop = rib->nexthop;
13288 - if (rib->type == type
13289 - && (! table || rib->table == table)
13290 - && nexthop && nexthop->type == NEXTHOP_TYPE_IFINDEX
13291 - && nexthop->ifindex == ifindex)
13293 - if (rib->refcnt)
13295 - rib->refcnt--;
13296 - route_unlock_node (rn);
13297 - route_unlock_node (rn);
13298 - return 0;
13300 - same = rib;
13301 - break;
13304 - else
13306 - if (rib->type == type
13307 - && (! table || rib->table == table))
13309 - same = rib;
13310 - break;
13315 - /* If same type of route can't be found and this message is from
13316 - kernel. */
13317 - if (! same)
13319 - if (fib && type == ZEBRA_ROUTE_KERNEL)
13321 - /* Unset flags. */
13322 - for (nexthop = fib->nexthop; nexthop; nexthop = nexthop->next)
13323 - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
13325 - UNSET_FLAG (fib->flags, ZEBRA_FLAG_SELECTED);
13327 - else
13329 - if (IS_ZEBRA_DEBUG_KERNEL)
13331 - if (gate)
13332 - zlog_info ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
13333 - inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ),
13334 - p->prefixlen,
13335 - inet_ntop (AF_INET6, gate, buf2, BUFSIZ),
13336 - ifindex,
13337 - type);
13338 - else
13339 - zlog_info ("route %s/%d ifindex %d type %d doesn't exist in rib",
13340 - inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ),
13341 - p->prefixlen,
13342 - ifindex,
13343 - type);
13345 - route_unlock_node (rn);
13346 - return ZEBRA_ERR_RTNOEXIST;
13350 - if (same)
13351 - rib_delnode (rn, same);
13353 - /* Process changes. */
13354 - rib_process (rn, same);
13356 - if (same)
13358 - newrib_free (same);
13359 - route_unlock_node (rn);
13362 - route_unlock_node (rn);
13364 - return 0;
13367 -/* Delete non system routes. */
13368 -void
13369 -rib_close_ipv6 ()
13371 - struct route_node *rn;
13372 - struct rib *rib;
13374 - for (rn = route_top (rib_table_ipv6); rn; rn = route_next (rn))
13375 - for (rib = rn->info; rib; rib = rib->next)
13376 - if (! RIB_SYSTEM_ROUTE (rib)
13377 - && CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
13378 - rib_uninstall_kernel (rn, rib);
13381 -/* Install static route into rib. */
13382 -void
13383 -static_ipv6_install (struct prefix_ipv6 *p, struct static_ipv6 *si)
13385 - struct rib *rib;
13386 - struct route_node *rn;
13388 - /* Lookup existing route */
13389 - rn = route_node_get (rib_table_ipv6, (struct prefix *) p);
13390 - for (rib = rn->info; rib; rib = rib->next)
13391 - if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
13392 - break;
13394 - if (rib)
13396 - /* Same distance static route is there. Update it with new
13397 - nexthop. */
13398 - rib_uninstall (rn, rib);
13399 - route_unlock_node (rn);
13401 - switch (si->type)
13403 - case STATIC_IPV6_GATEWAY:
13404 - nexthop_ipv6_add (rib, &si->ipv6);
13405 - break;
13406 - case STATIC_IPV6_IFNAME:
13407 - nexthop_ifname_add (rib, si->ifname);
13408 - break;
13409 - case STATIC_IPV6_GATEWAY_IFNAME:
13410 - nexthop_ipv6_ifname_add (rib, &si->ipv6, si->ifname);
13411 - break;
13413 - rib_process (rn, NULL);
13415 - else
13417 - /* This is new static route. */
13418 - rib = XMALLOC (MTYPE_RIB, sizeof (struct rib));
13419 - memset (rib, 0, sizeof (struct rib));
13421 - rib->type = ZEBRA_ROUTE_STATIC;
13422 - rib->distance = si->distance;
13423 - rib->metric = 0;
13424 - rib->nexthop_num = 0;
13426 - switch (si->type)
13428 - case STATIC_IPV6_GATEWAY:
13429 - nexthop_ipv6_add (rib, &si->ipv6);
13430 - break;
13431 - case STATIC_IPV6_IFNAME:
13432 - nexthop_ifname_add (rib, si->ifname);
13433 - break;
13434 - case STATIC_IPV6_GATEWAY_IFNAME:
13435 - nexthop_ipv6_ifname_add (rib, &si->ipv6, si->ifname);
13436 - break;
13439 - /* Link this rib to the tree. */
13440 - rib_addnode (rn, rib);
13442 - /* Process this prefix. */
13443 - rib_process (rn, NULL);
13447 -int
13448 -static_ipv6_nexthop_same (struct nexthop *nexthop, struct static_ipv6 *si)
13450 - if (nexthop->type == NEXTHOP_TYPE_IPV6
13451 - && si->type == STATIC_IPV6_GATEWAY
13452 - && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->ipv6))
13453 - return 1;
13454 - if (nexthop->type == NEXTHOP_TYPE_IFNAME
13455 - && si->type == STATIC_IPV6_IFNAME
13456 - && strcmp (nexthop->ifname, si->ifname) == 0)
13457 - return 1;
13458 - if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME
13459 - && si->type == STATIC_IPV6_GATEWAY_IFNAME
13460 - && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->ipv6)
13461 - && strcmp (nexthop->ifname, si->ifname) == 0)
13462 - return 1;
13463 - return 0;;
13466 -void
13467 -static_ipv6_uninstall (struct prefix_ipv6 *p, struct static_ipv6 *si)
13469 - struct route_node *rn;
13470 - struct rib *rib;
13471 - struct nexthop *nexthop;
13473 - /* Lookup existing route with type and distance. */
13474 - rn = route_node_lookup (rib_table_ipv6, (struct prefix *) p);
13475 - if (! rn)
13476 - return;
13478 - for (rib = rn->info; rib; rib = rib->next)
13479 - if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
13480 - break;
13481 - if (! rib)
13483 - route_unlock_node (rn);
13484 - return;
13487 - /* Lookup nexthop. */
13488 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
13489 - if (static_ipv6_nexthop_same (nexthop, si))
13490 - break;
13492 - /* Can't find nexthop. */
13493 - if (! nexthop)
13495 - route_unlock_node (rn);
13496 - return;
13499 - /* Check nexthop. */
13500 - if (rib->nexthop_num == 1)
13502 - rib_delnode (rn, rib);
13503 - rib_process (rn, rib);
13504 - newrib_free (rib);
13505 - route_unlock_node (rn);
13507 - else
13509 - rib_uninstall (rn, rib);
13510 - nexthop_delete (rib, nexthop);
13511 - nexthop_free (nexthop);
13512 - rib_process (rn, rib);
13515 - /* Unlock node. */
13516 - route_unlock_node (rn);
13519 -/* Add static route into static route configuration. */
13520 -int
13521 -static_ipv6_add (struct prefix_ipv6 *p, u_char type, struct in6_addr *gate,
13522 - char *ifname, u_char distance, int table)
13524 - struct route_node *rn;
13525 - struct static_ipv6 *si;
13526 - struct static_ipv6 *pp;
13527 - struct static_ipv6 *cp;
13529 - /* Lookup static route prefix. */
13530 - rn = route_node_get (static_table_ipv6, (struct prefix *) p);
13532 - /* Do nothing if there is a same static route. */
13533 - for (si = rn->info; si; si = si->next)
13535 - if (distance == si->distance
13536 - && type == si->type
13537 - && (! gate || IPV6_ADDR_SAME (gate, &si->ipv6))
13538 - && (! ifname || strcmp (ifname, si->ifname) == 0))
13540 - route_unlock_node (rn);
13541 - return 0;
13545 - /* Make new static route structure. */
13546 - si = XMALLOC (MTYPE_STATIC_IPV6, sizeof (struct static_ipv6));
13547 - memset (si, 0, sizeof (struct static_ipv6));
13549 - si->type = type;
13550 - si->distance = distance;
13552 - switch (type)
13554 - case STATIC_IPV6_GATEWAY:
13555 - si->ipv6 = *gate;
13556 - break;
13557 - case STATIC_IPV6_IFNAME:
13558 - si->ifname = XSTRDUP (0, ifname);
13559 - break;
13560 - case STATIC_IPV6_GATEWAY_IFNAME:
13561 - si->ipv6 = *gate;
13562 - si->ifname = XSTRDUP (0, ifname);
13563 - break;
13566 - /* Add new static route information to the tree with sort by
13567 - distance value and gateway address. */
13568 - for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next)
13570 - if (si->distance < cp->distance)
13571 - break;
13572 - if (si->distance > cp->distance)
13573 - continue;
13576 - /* Make linked list. */
13577 - if (pp)
13578 - pp->next = si;
13579 - else
13580 - rn->info = si;
13581 - if (cp)
13582 - cp->prev = si;
13583 - si->prev = pp;
13584 - si->next = cp;
13586 - /* Install into rib. */
13587 - static_ipv6_install (p, si);
13589 - return 1;
13592 -/* Delete static route from static route configuration. */
13593 -int
13594 -static_ipv6_delete (struct prefix_ipv6 *p, u_char type, struct in6_addr *gate,
13595 - char *ifname, u_char distance, int table)
13597 - struct route_node *rn;
13598 - struct static_ipv6 *si;
13600 - /* Lookup static route prefix. */
13601 - rn = route_node_lookup (static_table_ipv6, (struct prefix *) p);
13602 - if (! rn)
13603 - return 0;
13605 - /* Find same static route is the tree */
13606 - for (si = rn->info; si; si = si->next)
13607 - if (distance == si->distance
13608 - && type == si->type
13609 - && (! gate || IPV6_ADDR_SAME (gate, &si->ipv6))
13610 - && (! ifname || strcmp (ifname, si->ifname) == 0))
13611 - break;
13613 - /* Can't find static route. */
13614 - if (! si)
13616 - route_unlock_node (rn);
13617 - return 0;
13620 - /* Install into rib. */
13621 - static_ipv6_uninstall (p, si);
13623 - /* Unlink static route from linked list. */
13624 - if (si->prev)
13625 - si->prev->next = si->next;
13626 - else
13627 - rn->info = si->next;
13628 - if (si->next)
13629 - si->next->prev = si->prev;
13631 - /* Free static route configuration. */
13632 - XFREE (MTYPE_STATIC_IPV6, si);
13634 - return 1;
13637 -/* General fucntion for IPv6 static route. */
13638 -int
13639 -static_ipv6_func (struct vty *vty, int add_cmd, char *dest_str,
13640 - char *gate_str, char *ifname, char *distance_str)
13642 - int ret;
13643 - u_char distance;
13644 - struct prefix_ipv6 p;
13645 - struct in6_addr *gate = NULL;
13646 - struct in6_addr gate_addr;
13647 - u_char type = 0;
13648 - int table = rtm_table_default;
13650 - ret = str2prefix_ipv6 (dest_str, &p);
13651 - if (ret <= 0)
13653 - vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
13654 - return CMD_WARNING;
13657 - /* Apply mask for given prefix. */
13658 - apply_mask_ipv6 (&p);
13660 - /* Administrative distance. */
13661 - if (distance_str)
13662 - distance = atoi (distance_str);
13663 - else
13664 - distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
13666 - /* When gateway is valid IPv6 addrees, then gate is treated as
13667 - nexthop address other case gate is treated as interface name. */
13668 - ret = inet_pton (AF_INET6, gate_str, &gate_addr);
13670 - if (ifname)
13672 - /* When ifname is specified. It must be come with gateway
13673 - address. */
13674 - if (ret != 1)
13676 - vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
13677 - return CMD_WARNING;
13679 - type = STATIC_IPV6_GATEWAY_IFNAME;
13680 - gate = &gate_addr;
13682 - else
13684 - if (ret == 1)
13686 - type = STATIC_IPV6_GATEWAY;
13687 - gate = &gate_addr;
13689 - else
13691 - type = STATIC_IPV6_IFNAME;
13692 - ifname = gate_str;
13696 - if (add_cmd)
13697 - static_ipv6_add (&p, type, gate, ifname, distance, table);
13698 - else
13699 - static_ipv6_delete (&p, type, gate, ifname, distance, table);
13701 - return CMD_SUCCESS;
13704 -/* Write IPv6 static route configuration. */
13705 -int
13706 -static_ipv6_write (struct vty *vty)
13708 - struct route_node *rn;
13709 - struct static_ipv6 *si;
13710 - int write;
13711 - char buf[BUFSIZ];
13713 - write = 0;
13715 - for (rn = route_top (static_table_ipv6); rn; rn = route_next (rn))
13716 - for (si = rn->info; si; si = si->next)
13718 - vty_out (vty, "ipv6 route %s/%d",
13719 - inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
13720 - rn->p.prefixlen);
13722 - switch (si->type)
13724 - case STATIC_IPV6_GATEWAY:
13725 - vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
13726 - break;
13727 - case STATIC_IPV6_IFNAME:
13728 - vty_out (vty, " %s", si->ifname);
13729 - break;
13730 - case STATIC_IPV6_GATEWAY_IFNAME:
13731 - vty_out (vty, " %s %s",
13732 - inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
13733 - break;
13736 - if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
13737 - vty_out (vty, " %d", si->distance);
13738 - vty_out (vty, "%s", VTY_NEWLINE);
13740 - write = 1;
13742 - return write;
13745 -DEFUN (ipv6_route,
13746 - ipv6_route_cmd,
13747 - "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
13748 - IP_STR
13749 - "Establish static routes\n"
13750 - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
13751 - "IPv6 gateway address\n"
13752 - "IPv6 gateway interface name\n")
13754 - return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL);
13757 -DEFUN (ipv6_route_ifname,
13758 - ipv6_route_ifname_cmd,
13759 - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
13760 - IP_STR
13761 - "Establish static routes\n"
13762 - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
13763 - "IPv6 gateway address\n"
13764 - "IPv6 gateway interface name\n")
13766 - return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL);
13769 -DEFUN (ipv6_route_pref,
13770 - ipv6_route_pref_cmd,
13771 - "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
13772 - IP_STR
13773 - "Establish static routes\n"
13774 - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
13775 - "IPv6 gateway address\n"
13776 - "IPv6 gateway interface name\n"
13777 - "Distance value for this prefix\n")
13779 - return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2]);
13782 -DEFUN (ipv6_route_ifname_pref,
13783 - ipv6_route_ifname_pref_cmd,
13784 - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
13785 - IP_STR
13786 - "Establish static routes\n"
13787 - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
13788 - "IPv6 gateway address\n"
13789 - "IPv6 gateway interface name\n"
13790 - "Distance value for this prefix\n")
13792 - return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3]);
13795 -DEFUN (no_ipv6_route,
13796 - no_ipv6_route_cmd,
13797 - "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
13798 - NO_STR
13799 - IP_STR
13800 - "Establish static routes\n"
13801 - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
13802 - "IPv6 gateway address\n"
13803 - "IPv6 gateway interface name\n")
13805 - return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL);
13808 -DEFUN (no_ipv6_route_ifname,
13809 - no_ipv6_route_ifname_cmd,
13810 - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
13811 - NO_STR
13812 - IP_STR
13813 - "Establish static routes\n"
13814 - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
13815 - "IPv6 gateway address\n"
13816 - "IPv6 gateway interface name\n")
13818 - return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL);
13821 -DEFUN (no_ipv6_route_pref,
13822 - no_ipv6_route_pref_cmd,
13823 - "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
13824 - NO_STR
13825 - IP_STR
13826 - "Establish static routes\n"
13827 - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
13828 - "IPv6 gateway address\n"
13829 - "IPv6 gateway interface name\n"
13830 - "Distance value for this prefix\n")
13832 - return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2]);
13835 -DEFUN (no_ipv6_route_ifname_pref,
13836 - no_ipv6_route_ifname_pref_cmd,
13837 - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
13838 - NO_STR
13839 - IP_STR
13840 - "Establish static routes\n"
13841 - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
13842 - "IPv6 gateway address\n"
13843 - "IPv6 gateway interface name\n"
13844 - "Distance value for this prefix\n")
13846 - return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3]);
13849 -/* New RIB. Detailed information for IPv4 route. */
13850 -void
13851 -vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
13853 - struct rib *rib;
13854 - struct nexthop *nexthop;
13855 - char buf[BUFSIZ];
13857 - for (rib = rn->info; rib; rib = rib->next)
13859 - vty_out (vty, "Routing entry for %s/%d%s",
13860 - inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
13861 - rn->p.prefixlen,
13862 - VTY_NEWLINE);
13863 - vty_out (vty, " Known via \"%s\"", route_info[rib->type].str);
13864 - vty_out (vty, ", distance %d, metric %d", rib->distance, rib->metric);
13865 - if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
13866 - vty_out (vty, ", best");
13867 - if (rib->refcnt)
13868 - vty_out (vty, ", refcnt %ld", rib->refcnt);
13869 - vty_out (vty, "%s", VTY_NEWLINE);
13871 -#define ONE_DAY_SECOND 60*60*24
13872 -#define ONE_WEEK_SECOND 60*60*24*7
13873 - if (rib->type == ZEBRA_ROUTE_RIPNG
13874 - || rib->type == ZEBRA_ROUTE_OSPF6
13875 - || rib->type == ZEBRA_ROUTE_BGP)
13877 - time_t uptime;
13878 - struct tm *tm;
13880 - uptime = time (NULL);
13881 - uptime -= rib->uptime;
13882 - tm = gmtime (&uptime);
13884 - vty_out (vty, " Last update ");
13886 - if (uptime < ONE_DAY_SECOND)
13887 - vty_out (vty, "%02d:%02d:%02d",
13888 - tm->tm_hour, tm->tm_min, tm->tm_sec);
13889 - else if (uptime < ONE_WEEK_SECOND)
13890 - vty_out (vty, "%dd%02dh%02dm",
13891 - tm->tm_yday, tm->tm_hour, tm->tm_min);
13892 - else
13893 - vty_out (vty, "%02dw%dd%02dh",
13894 - tm->tm_yday/7,
13895 - tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
13896 - vty_out (vty, " ago%s", VTY_NEWLINE);
13899 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
13901 - vty_out (vty, " %c",
13902 - CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ');
13904 - switch (nexthop->type)
13906 - case NEXTHOP_TYPE_IPV6:
13907 - case NEXTHOP_TYPE_IPV6_IFINDEX:
13908 - case NEXTHOP_TYPE_IPV6_IFNAME:
13909 - vty_out (vty, " %s",
13910 - inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
13911 - if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
13912 - vty_out (vty, ", %s", nexthop->ifname);
13913 - else if (nexthop->ifindex)
13914 - vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
13915 - break;
13916 - case NEXTHOP_TYPE_IFINDEX:
13917 - vty_out (vty, " directly connected, %s",
13918 - ifindex2ifname (nexthop->ifindex));
13919 - break;
13920 - case NEXTHOP_TYPE_IFNAME:
13921 - vty_out (vty, " directly connected, %s",
13922 - nexthop->ifname);
13923 - break;
13924 - default:
13925 - break;
13927 - if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
13928 - vty_out (vty, " inactive");
13930 - if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
13932 - vty_out (vty, " (recursive");
13934 - switch (nexthop->rtype)
13936 - case NEXTHOP_TYPE_IPV6:
13937 - case NEXTHOP_TYPE_IPV6_IFINDEX:
13938 - case NEXTHOP_TYPE_IPV6_IFNAME:
13939 - vty_out (vty, " via %s)",
13940 - inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
13941 - buf, BUFSIZ));
13942 - if (nexthop->rifindex)
13943 - vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
13944 - break;
13945 - case NEXTHOP_TYPE_IFINDEX:
13946 - case NEXTHOP_TYPE_IFNAME:
13947 - vty_out (vty, " is directly connected, %s)",
13948 - ifindex2ifname (nexthop->rifindex));
13949 - break;
13950 - default:
13951 - break;
13954 - vty_out (vty, "%s", VTY_NEWLINE);
13956 - vty_out (vty, "%s", VTY_NEWLINE);
13960 -void
13961 -vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
13962 - struct rib *rib)
13964 - struct nexthop *nexthop;
13965 - int len = 0;
13966 - char buf[BUFSIZ];
13968 - /* Nexthop information. */
13969 - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
13971 - if (nexthop == rib->nexthop)
13973 - /* Prefix information. */
13974 - len = vty_out (vty, "%c%c%c %s/%d",
13975 - route_info[rib->type].c,
13976 - CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
13977 - ? '>' : ' ',
13978 - CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
13979 - ? '*' : ' ',
13980 - inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
13981 - rn->p.prefixlen);
13983 - /* Distance and metric display. */
13984 - if (rib->type != ZEBRA_ROUTE_CONNECT
13985 - && rib->type != ZEBRA_ROUTE_KERNEL)
13986 - len += vty_out (vty, " [%d/%d]", rib->distance,
13987 - rib->metric);
13989 - else
13990 - vty_out (vty, " %c%*c",
13991 - CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
13992 - ? '*' : ' ',
13993 - len - 3, ' ');
13995 - switch (nexthop->type)
13997 - case NEXTHOP_TYPE_IPV6:
13998 - case NEXTHOP_TYPE_IPV6_IFINDEX:
13999 - case NEXTHOP_TYPE_IPV6_IFNAME:
14000 - vty_out (vty, " via %s",
14001 - inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
14002 - if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
14003 - vty_out (vty, ", %s", nexthop->ifname);
14004 - else if (nexthop->ifindex)
14005 - vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
14006 - break;
14007 - case NEXTHOP_TYPE_IFINDEX:
14008 - vty_out (vty, " is directly connected, %s",
14009 - ifindex2ifname (nexthop->ifindex));
14010 - break;
14011 - case NEXTHOP_TYPE_IFNAME:
14012 - vty_out (vty, " is directly connected, %s",
14013 - nexthop->ifname);
14014 - break;
14015 - default:
14016 - break;
14018 - if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
14019 - vty_out (vty, " inactive");
14021 - if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
14023 - vty_out (vty, " (recursive");
14025 - switch (nexthop->rtype)
14027 - case NEXTHOP_TYPE_IPV6:
14028 - case NEXTHOP_TYPE_IPV6_IFINDEX:
14029 - case NEXTHOP_TYPE_IPV6_IFNAME:
14030 - vty_out (vty, " via %s)",
14031 - inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
14032 - buf, BUFSIZ));
14033 - if (nexthop->rifindex)
14034 - vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
14035 - break;
14036 - case NEXTHOP_TYPE_IFINDEX:
14037 - case NEXTHOP_TYPE_IFNAME:
14038 - vty_out (vty, " is directly connected, %s)",
14039 - ifindex2ifname (nexthop->rifindex));
14040 - break;
14041 - default:
14042 - break;
14046 - if (rib->type == ZEBRA_ROUTE_RIPNG
14047 - || rib->type == ZEBRA_ROUTE_OSPF6
14048 - || rib->type == ZEBRA_ROUTE_BGP)
14050 - time_t uptime;
14051 - struct tm *tm;
14053 - uptime = time (NULL);
14054 - uptime -= rib->uptime;
14055 - tm = gmtime (&uptime);
14057 -#define ONE_DAY_SECOND 60*60*24
14058 -#define ONE_WEEK_SECOND 60*60*24*7
14060 - if (uptime < ONE_DAY_SECOND)
14061 - vty_out (vty, ", %02d:%02d:%02d",
14062 - tm->tm_hour, tm->tm_min, tm->tm_sec);
14063 - else if (uptime < ONE_WEEK_SECOND)
14064 - vty_out (vty, ", %dd%02dh%02dm",
14065 - tm->tm_yday, tm->tm_hour, tm->tm_min);
14066 - else
14067 - vty_out (vty, ", %02dw%dd%02dh",
14068 - tm->tm_yday/7,
14069 - tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
14071 - vty_out (vty, "%s", VTY_NEWLINE);
14075 -#define SHOW_ROUTE_V6_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3,%s B - BGP, * - FIB route.%s%s"
14077 -DEFUN (show_ipv6_route,
14078 - show_ipv6_route_cmd,
14079 - "show ipv6 route",
14080 - SHOW_STR
14081 - IP_STR
14082 - "IPv6 routing table\n")
14084 - struct route_node *rn;
14085 - struct rib *rib;
14086 - int first = 1;
14088 - /* Show all IPv6 route. */
14089 - for (rn = route_top (rib_table_ipv6); rn; rn = route_next (rn))
14090 - for (rib = rn->info; rib; rib = rib->next)
14092 - if (first)
14094 - vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
14095 - first = 0;
14097 - vty_show_ipv6_route (vty, rn, rib);
14099 - return CMD_SUCCESS;
14102 -DEFUN (show_ipv6_route_prefix_longer,
14103 - show_ipv6_route_prefix_longer_cmd,
14104 - "show ipv6 route X:X::X:X/M longer-prefixes",
14105 - SHOW_STR
14106 - IP_STR
14107 - "IPv6 routing table\n"
14108 - "IPv6 prefix\n"
14109 - "Show route matching the specified Network/Mask pair only\n")
14111 - struct route_node *rn;
14112 - struct rib *rib;
14113 - struct prefix p;
14114 - int ret;
14115 - int first = 1;
14117 - ret = str2prefix (argv[0], &p);
14118 - if (! ret)
14120 - vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
14121 - return CMD_WARNING;
14124 - /* Show matched type IPv6 routes. */
14125 - for (rn = route_top (rib_table_ipv6); rn; rn = route_next (rn))
14126 - for (rib = rn->info; rib; rib = rib->next)
14127 - if (prefix_match (&p, &rn->p))
14129 - if (first)
14131 - vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
14132 - first = 0;
14134 - vty_show_ipv6_route (vty, rn, rib);
14136 - return CMD_SUCCESS;
14139 -DEFUN (show_ipv6_route_protocol,
14140 - show_ipv6_route_protocol_cmd,
14141 - "show ipv6 route (bgp|connected|kernel|ospf6|ripng|static)",
14142 - SHOW_STR
14143 - IP_STR
14144 - "IP routing table\n"
14145 - "Border Gateway Protocol (BGP)\n"
14146 - "Connected\n"
14147 - "Kernel\n"
14148 - "Open Shortest Path First (OSPFv3)\n"
14149 - "Routing Information Protocol (RIPng)\n"
14150 - "Static routes\n")
14152 - int type;
14153 - struct route_node *rn;
14154 - struct rib *rib;
14155 - int first = 1;
14157 - if (strncmp (argv[0], "b", 1) == 0)
14158 - type = ZEBRA_ROUTE_BGP;
14159 - else if (strncmp (argv[0], "c", 1) == 0)
14160 - type = ZEBRA_ROUTE_CONNECT;
14161 - else if (strncmp (argv[0], "k", 1) ==0)
14162 - type = ZEBRA_ROUTE_KERNEL;
14163 - else if (strncmp (argv[0], "o", 1) == 0)
14164 - type = ZEBRA_ROUTE_OSPF6;
14165 - else if (strncmp (argv[0], "r", 1) == 0)
14166 - type = ZEBRA_ROUTE_RIPNG;
14167 - else if (strncmp (argv[0], "s", 1) == 0)
14168 - type = ZEBRA_ROUTE_STATIC;
14169 - else
14171 - vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
14172 - return CMD_WARNING;
14175 - /* Show matched type IPv6 routes. */
14176 - for (rn = route_top (rib_table_ipv6); rn; rn = route_next (rn))
14177 - for (rib = rn->info; rib; rib = rib->next)
14178 - if (rib->type == type)
14180 - if (first)
14182 - vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
14183 - first = 0;
14185 - vty_show_ipv6_route (vty, rn, rib);
14187 - return CMD_SUCCESS;
14190 -DEFUN (show_ipv6_route_addr,
14191 - show_ipv6_route_addr_cmd,
14192 - "show ipv6 route X:X::X:X",
14193 - SHOW_STR
14194 - IP_STR
14195 - "IPv6 routing table\n"
14196 - "IPv6 Address\n")
14198 - int ret;
14199 - struct prefix_ipv6 p;
14200 - struct route_node *rn;
14202 - ret = str2prefix_ipv6 (argv[0], &p);
14203 - if (ret <= 0)
14205 - vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
14206 - return CMD_WARNING;
14209 - rn = route_node_match (rib_table_ipv6, (struct prefix *) &p);
14210 - if (! rn)
14212 - vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
14213 - return CMD_WARNING;
14216 - vty_show_ipv6_route_detail (vty, rn);
14218 - route_unlock_node (rn);
14220 - return CMD_SUCCESS;
14223 -DEFUN (show_ipv6_route_prefix,
14224 - show_ipv6_route_prefix_cmd,
14225 - "show ipv6 route X:X::X:X/M",
14226 - SHOW_STR
14227 - IP_STR
14228 - "IPv6 routing table\n"
14229 - "IPv6 prefix\n")
14231 - int ret;
14232 - struct prefix_ipv6 p;
14233 - struct route_node *rn;
14235 - ret = str2prefix_ipv6 (argv[0], &p);
14236 - if (ret <= 0)
14238 - vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
14239 - return CMD_WARNING;
14242 - rn = route_node_match (rib_table_ipv6, (struct prefix *) &p);
14243 - if (! rn || rn->p.prefixlen != p.prefixlen)
14245 - vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
14246 - return CMD_WARNING;
14249 - vty_show_ipv6_route_detail (vty, rn);
14251 - route_unlock_node (rn);
14253 - return CMD_SUCCESS;
14255 -#endif /* HAVE_IPV6 */
14257 -/* RIB update function. */
14258 -void
14259 -rib_update ()
14261 - struct route_node *rn;
14263 - for (rn = route_top (rib_table_ipv4); rn; rn = route_next (rn))
14264 - /* Update reachability. */
14265 - rib_process (rn, NULL);
14267 -#ifdef HAVE_IPV6
14268 - for (rn = route_top (rib_table_ipv6); rn; rn = route_next (rn))
14269 - rib_process (rn, NULL);
14270 -#endif /* HAVE_IPV6 */
14273 -/* Interface goes up. */
14274 -void
14275 -rib_if_up (struct interface *ifp)
14277 - rib_update ();
14280 -/* Interface goes down. */
14281 -void
14282 -rib_if_down (struct interface *ifp)
14284 - rib_update ();
14287 -/* Clean up routines. */
14288 -void
14289 -rib_weed_table (struct route_table *rib_table)
14291 - struct route_node *rn;
14292 - struct rib *rib;
14293 - struct rib *next;
14295 - for (rn = route_top (rib_table); rn; rn = route_next (rn))
14296 - for (rib = rn->info; rib; rib = next)
14298 - next = rib->next;
14300 - if (rib->table != rtm_table_default &&
14301 - rib->table != RT_TABLE_MAIN)
14303 - rib_delnode (rn, rib);
14304 - newrib_free (rib);
14305 - route_unlock_node (rn);
14310 -/* Delete all routes from unmanaged tables. */
14311 -void
14312 -rib_weed_tables ()
14314 - rib_weed_table (rib_table_ipv4);
14315 -#ifdef HAVE_IPV6
14316 - rib_weed_table (rib_table_ipv6);
14317 -#endif /* HAVE_IPV6 */
14320 -void
14321 -rib_sweep_table (struct route_table *rib_table)
14323 - struct route_node *rn;
14324 - struct rib *rib;
14325 - struct rib *next;
14326 - int ret = 0;
14328 - for (rn = route_top (rib_table); rn; rn = route_next (rn))
14329 - for (rib = rn->info; rib; rib = next)
14331 - next = rib->next;
14333 - if ((rib->type == ZEBRA_ROUTE_KERNEL) &&
14334 - CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELFROUTE))
14336 - ret = rib_uninstall_kernel (rn, rib);
14338 - if (! ret)
14340 - rib_delnode (rn, rib);
14341 - newrib_free (rib);
14342 - route_unlock_node (rn);
14348 -void
14349 -rib_sweep_route ()
14351 - rib_sweep_table (rib_table_ipv4);
14352 -#ifdef HAVE_IPV6
14353 - rib_sweep_table (rib_table_ipv6);
14354 -#endif /* HAVE_IPV6 */
14357 -/* Close rib when zebra terminates. */
14358 -void
14359 -rib_close ()
14361 - rib_close_ipv4 ();
14362 -#ifdef HAVE_IPV6
14363 - rib_close_ipv6 ();
14364 -#endif /* HAVE_IPV6 */
14367 -/* Static ip route configuration write function. */
14368 -int
14369 -config_write_ip (struct vty *vty)
14371 - int write = 0;
14373 - write += static_ipv4_write (vty);
14374 -#ifdef HAVE_IPV6
14375 - write += static_ipv6_write (vty);
14376 -#endif /* HAVE_IPV6 */
14378 - return write;
14381 -/* IP node for static routes. */
14382 -struct cmd_node ip_node =
14384 - IP_NODE,
14385 - "", /* This node has no interface. */
14389 -/* Routing information base initialize. */
14390 -void
14391 -rib_init ()
14393 - install_node (&ip_node, config_write_ip);
14395 - rib_table_ipv4 = route_table_init ();
14396 - static_table_ipv4 = route_table_init ();
14398 - install_element (VIEW_NODE, &show_ip_route_cmd);
14399 - install_element (VIEW_NODE, &show_ip_route_addr_cmd);
14400 - install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
14401 - install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
14402 - install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
14403 - install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
14404 - install_element (ENABLE_NODE, &show_ip_route_cmd);
14405 - install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
14406 - install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
14407 - install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
14408 - install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
14409 - install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
14410 - install_element (CONFIG_NODE, &ip_route_cmd);
14411 - install_element (CONFIG_NODE, &ip_route_mask_cmd);
14412 - install_element (CONFIG_NODE, &no_ip_route_cmd);
14413 - install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
14414 - install_element (CONFIG_NODE, &ip_route_pref_cmd);
14415 - install_element (CONFIG_NODE, &ip_route_mask_pref_cmd);
14416 - install_element (CONFIG_NODE, &no_ip_route_pref_cmd);
14417 - install_element (CONFIG_NODE, &no_ip_route_mask_pref_cmd);
14419 -#ifdef HAVE_IPV6
14420 - rib_table_ipv6 = route_table_init ();
14421 - static_table_ipv6 = route_table_init ();
14423 - install_element (CONFIG_NODE, &ipv6_route_cmd);
14424 - install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
14425 - install_element (CONFIG_NODE, &no_ipv6_route_cmd);
14426 - install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
14427 - install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
14428 - install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
14429 - install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
14430 - install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
14431 - install_element (VIEW_NODE, &show_ipv6_route_cmd);
14432 - install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
14433 - install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
14434 - install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
14435 - install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
14436 - install_element (ENABLE_NODE, &show_ipv6_route_cmd);
14437 - install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
14438 - install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
14439 - install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
14440 - install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
14441 -#endif /* HAVE_IPV6 */
14443 diff -uNr --exclude=CVS zebra/zebra/rib.h zebra-ldp/zebra/rib.h
14444 --- zebra/zebra/rib.h Sat Aug 24 00:14:58 2002
14445 +++ zebra-ldp/zebra/rib.h Wed Dec 31 19:00:00 1969
14446 @@ -1,207 +0,0 @@
14448 - * Routing Information Base header
14449 - * Copyright (C) 1997 Kunihiro Ishiguro
14451 - * This file is part of GNU Zebra.
14453 - * GNU Zebra is free software; you can redistribute it and/or modify it
14454 - * under the terms of the GNU General Public License as published by the
14455 - * Free Software Foundation; either version 2, or (at your option) any
14456 - * later version.
14458 - * GNU Zebra is distributed in the hope that it will be useful, but
14459 - * WITHOUT ANY WARRANTY; without even the implied warranty of
14460 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14461 - * General Public License for more details.
14463 - * You should have received a copy of the GNU General Public License
14464 - * along with GNU Zebra; see the file COPYING. If not, write to the Free
14465 - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
14466 - * 02111-1307, USA.
14467 - */
14469 -#ifndef _ZEBRA_RIB_H
14470 -#define _ZEBRA_RIB_H
14472 -#define DISTANCE_INFINITY 255
14474 -/* Routing information base. */
14475 -struct rib
14477 - /* Link list. */
14478 - struct rib *next;
14479 - struct rib *prev;
14481 - /* Type fo this route. */
14482 - int type;
14484 - /* Which routing table */
14485 - int table;
14487 - /* Distance. */
14488 - u_char distance;
14490 - /* Flags of this route. This flag's definition is in lib/zebra.h
14491 - ZEBRA_FLAG_* */
14492 - u_char flags;
14494 - /* Metric */
14495 - u_int32_t metric;
14497 - /* Uptime. */
14498 - time_t uptime;
14500 - /* Refrence count. */
14501 - unsigned long refcnt;
14503 - /* Nexthop information. */
14504 - u_char nexthop_num;
14505 - u_char nexthop_active_num;
14506 - u_char nexthop_fib_num;
14508 - struct nexthop *nexthop;
14511 -/* Static route information. */
14512 -struct static_ipv4
14514 - /* For linked list. */
14515 - struct static_ipv4 *prev;
14516 - struct static_ipv4 *next;
14518 - /* Administrative distance. */
14519 - u_char distance;
14521 - /* Flag for this static route's type. */
14522 - u_char type;
14523 -#define STATIC_IPV4_GATEWAY 1
14524 -#define STATIC_IPV4_IFNAME 2
14526 - /* Nexthop value. */
14527 - union
14529 - struct in_addr ipv4;
14530 - char *ifname;
14531 - } gate;
14534 -#ifdef HAVE_IPV6
14535 -/* Static route information. */
14536 -struct static_ipv6
14538 - /* For linked list. */
14539 - struct static_ipv6 *prev;
14540 - struct static_ipv6 *next;
14542 - /* Administrative distance. */
14543 - u_char distance;
14545 - /* Flag for this static route's type. */
14546 - u_char type;
14547 -#define STATIC_IPV6_GATEWAY 1
14548 -#define STATIC_IPV6_GATEWAY_IFNAME 2
14549 -#define STATIC_IPV6_IFNAME 3
14551 - /* Nexthop value. */
14552 - struct in6_addr ipv6;
14553 - char *ifname;
14555 -#endif /* HAVE_IPV6 */
14557 -/* Nexthop structure. */
14558 -struct nexthop
14560 - struct nexthop *next;
14561 - struct nexthop *prev;
14563 - u_char type;
14564 -#define NEXTHOP_TYPE_IFINDEX 1 /* Directly connected. */
14565 -#define NEXTHOP_TYPE_IFNAME 2 /* Interface route. */
14566 -#define NEXTHOP_TYPE_IPV4 3 /* IPv4 nexthop. */
14567 -#define NEXTHOP_TYPE_IPV4_IFINDEX 4 /* IPv4 nexthop with ifindex. */
14568 -#define NEXTHOP_TYPE_IPV4_IFNAME 5 /* IPv4 nexthop with ifname. */
14569 -#define NEXTHOP_TYPE_IPV6 6 /* IPv6 nexthop. */
14570 -#define NEXTHOP_TYPE_IPV6_IFINDEX 7 /* IPv6 nexthop with ifindex. */
14571 -#define NEXTHOP_TYPE_IPV6_IFNAME 8 /* IPv6 nexthop with ifname. */
14573 - u_char flags;
14574 -#define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
14575 -#define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
14576 -#define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
14578 - /* Interface index. */
14579 - unsigned int ifindex;
14580 - char *ifname;
14582 - /* Nexthop address or interface name. */
14583 - union
14585 - struct in_addr ipv4;
14586 -#ifdef HAVE_IPV6
14587 - struct in6_addr ipv6;
14588 -#endif /* HAVE_IPV6*/
14589 - } gate;
14591 - /* Recursive lookup nexthop. */
14592 - u_char rtype;
14593 - unsigned int rifindex;
14594 - union
14596 - struct in_addr ipv4;
14597 -#ifdef HAVE_IPV6
14598 - struct in6_addr ipv6;
14599 -#endif /* HAVE_IPV6 */
14600 - } rgate;
14602 - struct nexthop *indirect;
14605 -struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int);
14606 -struct nexthop *nexthop_ifname_add (struct rib *, char *);
14607 -struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *);
14608 -#ifdef HAVE_IPV6
14609 -struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *);
14610 -#endif /* HAVE_IPV6 */
14612 -int
14613 -rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
14614 - struct in_addr *gate, unsigned int ifindex, int table,
14615 - u_int32_t, u_char);
14617 -int
14618 -rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *);
14620 -int
14621 -rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
14622 - struct in_addr *gate, unsigned int ifindex, int table);
14624 -struct rib *
14625 -rib_match_ipv4 (struct in_addr);
14627 -struct rib *
14628 -rib_lookup_ipv4 (struct prefix_ipv4 *);
14630 -void rib_update ();
14631 -void rib_sweep_route ();
14632 -void rib_close ();
14633 -void rib_init ();
14635 -extern struct route_table *rib_table_ipv4;
14637 -#ifdef HAVE_IPV6
14638 -int
14639 -rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
14640 - struct in6_addr *gate, unsigned int ifindex, int table);
14642 -int
14643 -rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
14644 - struct in6_addr *gate, unsigned int ifindex, int table);
14646 -struct rib *rib_lookup_ipv6 (struct in6_addr *);
14648 -struct rib *rib_match_ipv6 (struct in6_addr *);
14650 -extern struct route_table *rib_table_ipv6;
14651 -#endif /* HAVE_IPV6 */
14653 -#endif /*_ZEBRA_RIB_H */
14654 diff -uNr --exclude=CVS zebra/zebra/router-id.c zebra-ldp/zebra/router-id.c
14655 --- zebra/zebra/router-id.c Wed Dec 31 19:00:00 1969
14656 +++ zebra-ldp/zebra/router-id.c Sun Oct 13 22:39:48 2002
14657 @@ -0,0 +1,240 @@
14658 +#include <zebra.h>
14660 +#include "if.h"
14661 +#include "vty.h"
14662 +#include "sockunion.h"
14663 +#include "prefix.h"
14664 +#include "stream.h"
14665 +#include "command.h"
14666 +#include "memory.h"
14667 +#include "ioctl.h"
14668 +#include "connected.h"
14669 +#include "network.h"
14670 +#include "log.h"
14671 +#include "table.h"
14672 +#include "rib.h"
14674 +#include "zebra/zrib.h"
14675 +#include "zebra/zserv.h"
14677 +static struct list rid_all_sorted_list;
14678 +static struct list rid_lo_sorted_list;
14679 +static struct prefix rid_user_assigned;
14680 +extern struct list *client_list;
14682 +static struct connected *router_id_find_node(struct list *l,
14683 + struct connected *ifc) {
14684 + struct listnode *node;
14685 + struct connected *c;
14687 + for (node = l->head; node; node = node->next) {
14688 + c = (struct connected*)getdata(node);
14689 + if (prefix_same(ifc->address,c->address)) {
14690 + return c;
14693 + return NULL;
14696 +static int router_id_bad_address(struct connected *ifc) {
14697 + struct prefix n;
14699 + n.u.prefix4.s_addr = htonl(INADDR_LOOPBACK);
14700 + n.prefixlen = 8;
14701 + n.family = AF_INET;
14703 + if (prefix_match(&n,ifc->address)) {
14704 + return 1;
14706 + return 0;
14709 +void router_id_get(struct prefix *p) {
14710 + struct listnode *node;
14711 + struct connected *c;
14713 + p->u.prefix4.s_addr = 0;
14714 + p->family = AF_INET;
14715 + p->prefixlen = 32;
14717 + if (rid_user_assigned.u.prefix4.s_addr) {
14718 + p->u.prefix4.s_addr = rid_user_assigned.u.prefix4.s_addr;
14719 + } else if (!list_isempty(&rid_lo_sorted_list)) {
14720 + node = listtail(&rid_lo_sorted_list);
14721 + c = getdata(node);
14722 + p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
14723 + } else if (!list_isempty(&rid_all_sorted_list)) {
14724 + node = listtail(&rid_all_sorted_list);
14725 + c = getdata(node);
14726 + p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
14730 +static void router_id_set(struct prefix *p) {
14731 + struct prefix p2;
14732 + struct listnode *node;
14733 + struct zserv *client;
14735 + rid_user_assigned.u.prefix4.s_addr = p->u.prefix4.s_addr;
14737 + router_id_get(&p2);
14738 + for (node = listhead(client_list); node; nextnode(node))
14739 + if ((client = getdata(node)) != NULL)
14740 + zsend_router_id_update(client,&p2);
14743 +void router_id_add_address(struct connected *ifc) {
14744 + struct list *l = NULL;
14745 + struct listnode *node;
14746 + struct prefix before;
14747 + struct prefix after;
14748 + struct zserv *client;
14750 + if (router_id_bad_address(ifc)) {
14751 + return;
14754 + router_id_get(&before);
14756 + if (!strncmp(ifc->ifp->name,"lo",2) || !strncmp(ifc->ifp->name,"dummy",5)) {
14757 + l = &rid_lo_sorted_list;
14758 + } else {
14759 + l = &rid_all_sorted_list;
14761 + if (!router_id_find_node(l,ifc)) {
14762 + listnode_add(l,ifc);
14765 + router_id_get(&after);
14767 + if (prefix_same(&before, &after)) {
14768 + return;
14771 + for (node = listhead(client_list); node; nextnode(node))
14772 + if ((client = getdata(node)) != NULL)
14773 + zsend_router_id_update(client,&after);
14776 +void router_id_del_address(struct connected *ifc) {
14777 + struct connected *c;
14778 + struct list *l;
14779 + struct prefix after;
14780 + struct prefix before;
14781 + struct listnode *node;
14782 + struct zserv *client;
14784 + if (router_id_bad_address(ifc)) {
14785 + return;
14788 + router_id_get(&before);
14790 + if (!strncmp(ifc->ifp->name,"lo",2) || !strncmp(ifc->ifp->name,"dummy",5)) {
14791 + l = &rid_lo_sorted_list;
14792 + } else {
14793 + l = &rid_all_sorted_list;
14796 + if ((c = router_id_find_node(l,ifc))) {
14797 + listnode_delete(l,c);
14800 + router_id_get(&after);
14802 + if (prefix_same(&before, &after)) {
14803 + return;
14806 + for (node = listhead(client_list); node; nextnode(node))
14807 + if ((client = getdata(node)) != NULL)
14808 + zsend_router_id_update(client,&after);
14811 +void router_id_write(struct vty *vty) {
14812 + if (rid_user_assigned.u.prefix4.s_addr) {
14813 + vty_out(vty, "router-id %s%s", inet_ntoa(rid_user_assigned.u.prefix4),
14814 + VTY_NEWLINE);
14818 +DEFUN (router_id,
14819 + router_id_cmd,
14820 + "router-id A.B.C.D",
14821 + "Manually set the router-id\n"
14822 + "IP address to use for router-id\n")
14824 + struct prefix rid;
14826 + rid.u.prefix4.s_addr = inet_addr(argv[0]);
14827 + if (!rid.u.prefix4.s_addr) {
14828 + return CMD_WARNING;
14830 + rid.prefixlen = 32;
14831 + rid.family = AF_INET;
14833 + router_id_set(&rid);
14835 + return CMD_SUCCESS;
14838 +DEFUN (no_router_id,
14839 + no_router_id_cmd,
14840 + "no router-id",
14841 + NO_STR
14842 + "Remove the manually configured router-id\n")
14844 + struct prefix rid;
14846 + rid.u.prefix4.s_addr = 0;
14847 + rid.prefixlen = 0;
14848 + rid.family = AF_INET;
14850 + router_id_set(&rid);
14852 + return CMD_SUCCESS;
14855 +DEFUN (show_router_id,
14856 + show_router_id_cmd,
14857 + "show router-id",
14858 + SHOW_STR
14859 + "current router ID\n")
14861 + struct prefix rid;
14862 + router_id_get(&rid);
14864 + vty_out(vty, "router-id: %s%s", inet_ntoa(rid.u.prefix4),VTY_NEWLINE);
14865 + return CMD_SUCCESS;
14868 +int router_id_cmp(void *a, void *b) {
14869 + unsigned int A, B;
14871 + A = ((struct connected*)a)->address->u.prefix4.s_addr;
14872 + B = ((struct connected*)b)->address->u.prefix4.s_addr;
14874 + if (A > B) {
14875 + return 1;
14876 + } else if (A < B) {
14877 + return -1;
14879 + return 0;
14882 +void router_id_init(void) {
14883 + install_element(VIEW_NODE, &show_router_id_cmd);
14884 + install_element(ENABLE_NODE, &show_router_id_cmd);
14885 + install_element(CONFIG_NODE, &router_id_cmd);
14886 + install_element(CONFIG_NODE, &no_router_id_cmd);
14888 + memset(&rid_all_sorted_list,0,sizeof(rid_all_sorted_list));
14889 + memset(&rid_lo_sorted_list,0,sizeof(rid_lo_sorted_list));
14890 + memset(&rid_user_assigned,0,sizeof(rid_user_assigned));
14892 + rid_all_sorted_list.cmp = router_id_cmp;
14893 + rid_lo_sorted_list.cmp = router_id_cmp;
14895 + rid_user_assigned.family = AF_INET;
14896 + rid_user_assigned.prefixlen = 32;
14898 diff -uNr --exclude=CVS zebra/zebra/router-id.h zebra-ldp/zebra/router-id.h
14899 --- zebra/zebra/router-id.h Wed Dec 31 19:00:00 1969
14900 +++ zebra-ldp/zebra/router-id.h Sat Aug 24 00:14:49 2002
14901 @@ -0,0 +1,20 @@
14902 +#ifndef _ROUTER_ID_H_
14903 +#define _ROUTER_ID_H_
14905 +#include <zebra.h>
14907 +#include "memory.h"
14908 +#include "prefix.h"
14909 +#include "zclient.h"
14910 +#include "if.h"
14912 +extern void router_id_add_address(struct connected *);
14913 +extern void router_id_del_address(struct connected *);
14914 +extern void router_id_init(void);
14915 +extern void router_id_write(struct vty *);
14916 +extern void router_id_get(struct prefix *);
14918 +extern void zread_router_id_add(struct zserv *, u_short);
14919 +extern void zread_router_id_delete(struct zserv *, u_short);
14921 +#endif
14922 diff -uNr --exclude=CVS zebra/zebra/rt_netlink.c zebra-ldp/zebra/rt_netlink.c
14923 --- zebra/zebra/rt_netlink.c Sat Aug 24 00:14:58 2002
14924 +++ zebra-ldp/zebra/rt_netlink.c Sat Aug 24 00:14:49 2002
14925 @@ -606,6 +606,7 @@
14927 char anyaddr[16] = {0};
14929 + unsigned int mplsindex;
14930 int index;
14931 int table;
14932 void *dest;
14933 @@ -662,10 +663,14 @@
14934 return 0;
14937 + mplsindex = 0;
14938 index = 0;
14939 dest = NULL;
14940 gate = NULL;
14942 + if (tb[RTA_LSP])
14943 + mplsindex = *(unsigned int *) RTA_DATA (tb[RTA_LSP]);
14945 if (tb[RTA_OIF])
14946 index = *(int *) RTA_DATA (tb[RTA_OIF]);
14948 @@ -1204,6 +1209,10 @@
14949 || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFNAME)
14950 addattr32 (&req.n, sizeof req, RTA_OIF,
14951 nexthop->rifindex);
14953 + if (nexthop->rmplsindex)
14954 + addattr32 (&req.n, sizeof req, RTA_LSP,
14955 + nexthop->rmplsindex);
14957 else
14959 @@ -1224,6 +1233,11 @@
14960 || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX
14961 || nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
14962 addattr32 (&req.n, sizeof req, RTA_OIF, nexthop->ifindex);
14964 + if (nexthop->mplsindex) {
14965 +fprintf(stderr,"Adding RTA_LSP = 0x%x\n",nexthop->mplsindex);
14966 + addattr32 (&req.n, sizeof req, RTA_LSP, nexthop->mplsindex);
14970 if (cmd == RTM_NEWROUTE)
14971 @@ -1286,6 +1300,9 @@
14972 rtnh->rtnh_ifindex = nexthop->rifindex;
14973 else
14974 rtnh->rtnh_ifindex = 0;
14976 + if (nexthop->rmplsindex)
14977 + rtnh->rtnh_lsp = nexthop->rmplsindex;
14979 else
14981 @@ -1312,6 +1329,11 @@
14982 rtnh->rtnh_ifindex = nexthop->ifindex;
14983 else
14984 rtnh->rtnh_ifindex = 0;
14986 + if (nexthop->mplsindex) {
14987 +fprintf(stderr,"Setting rtnh_lsp = 0x%x\n",nexthop->mplsindex);
14988 + rtnh->rtnh_lsp = nexthop->mplsindex;
14991 rtnh = RTNH_NEXT(rtnh);
14993 diff -uNr --exclude=CVS zebra/zebra/zrib.c zebra-ldp/zebra/zrib.c
14994 --- zebra/zebra/zrib.c Wed Dec 31 19:00:00 1969
14995 +++ zebra-ldp/zebra/zrib.c Mon Nov 4 07:58:09 2002
14996 @@ -0,0 +1,1194 @@
14997 +/* Routing Information Base.
14998 + * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro
15000 + * This file is part of GNU Zebra.
15002 + * GNU Zebra is free software; you can redistribute it and/or modify it
15003 + * under the terms of the GNU General Public License as published by the
15004 + * Free Software Foundation; either version 2, or (at your option) any
15005 + * later version.
15007 + * GNU Zebra is distributed in the hope that it will be useful, but
15008 + * WITHOUT ANY WARRANTY; without even the implied warranty of
15009 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15010 + * General Public License for more details.
15012 + * You should have received a copy of the GNU General Public License
15013 + * along with GNU Zebra; see the file COPYING. If not, write to the Free
15014 + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
15015 + * 02111-1307, USA.
15016 + */
15018 +#include <zebra.h>
15020 +#include "prefix.h"
15021 +#include "table.h"
15022 +#include "memory.h"
15023 +#include "vty.h"
15024 +#include "str.h"
15025 +#include "command.h"
15026 +#include "linklist.h"
15027 +#include "if.h"
15028 +#include "log.h"
15029 +#include "sockunion.h"
15030 +#include "rib.h"
15032 +#include "zebra/zrib.h"
15033 +#include "zebra/rt.h"
15034 +#include "zebra/zserv.h"
15035 +#include "zebra/redistribute.h"
15036 +#include "zebra/debug.h"
15037 +#include "zebra/router-id.h"
15039 +/* Routing information base and static table for IPv4. */
15040 +struct rib_table *static_table_ipv4;
15042 +/* Routing information base and static table for IPv6. */
15043 +#ifdef HAVE_IPV6
15044 +struct rib_table *static_table_ipv6;
15045 +#endif /* HAVE_IPV6 */
15047 +/* Default rtm_table for all clients */
15048 +extern int rtm_table_default;
15050 +int
15051 +rib_install_kernel (struct route_node *rn, struct rib *rib)
15053 + int ret = 0;
15055 + switch (PREFIX_FAMILY (&rn->p))
15057 + case AF_INET:
15058 + ret = kernel_add_ipv4 (&rn->p, rib);
15059 + break;
15060 +#ifdef HAVE_IPV6
15061 + case AF_INET6:
15062 + ret = kernel_add_ipv6 (&rn->p, rib);
15063 + break;
15064 +#endif /* HAVE_IPV6 */
15067 + return ret;
15070 +/* Uninstall the route from kernel. */
15071 +int
15072 +rib_uninstall_kernel (struct route_node *rn, struct rib *rib)
15074 + int ret = 0;
15076 + switch (PREFIX_FAMILY (&rn->p))
15078 + case AF_INET:
15079 + ret = kernel_delete_ipv4 (&rn->p, rib);
15080 + break;
15081 +#ifdef HAVE_IPV6
15082 + case AF_INET6:
15083 + ret = kernel_delete_ipv6 (&rn->p, rib);
15084 + break;
15085 +#endif /* HAVE_IPV6 */
15088 + return ret;
15092 +/* Install static route into rib. */
15093 +void
15094 +static_ipv4_install (struct prefix_ipv4 *p, struct static_ipv4 *si)
15096 + struct rib *rib;
15097 + struct route_node *rn;
15099 + /* Lookup existing route */
15100 + rn = route_node_get (rib_table_ipv4->table, (struct prefix *) p);
15101 + for (rib = rn->info; rib; rib = rib->next)
15102 + if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
15103 + break;
15105 + if (rib)
15107 + /* Same distance static route is there. Update it with new
15108 + nexthop. */
15109 + rib_uninstall (rn, rib);
15110 + route_unlock_node (rn);
15112 + switch (si->type)
15114 + case STATIC_IPV4_GATEWAY:
15115 + nexthop_ipv4_add (rib, &si->gate.ipv4);
15116 + break;
15117 + case STATIC_IPV4_IFNAME:
15118 + nexthop_ifname_add (rib, si->gate.ifname);
15119 + break;
15121 + rib_process (rn, NULL);
15123 + else
15125 + /* This is new static route. */
15126 + rib = XMALLOC (MTYPE_RIB, sizeof (struct rib));
15127 + memset (rib, 0, sizeof (struct rib));
15129 + rib->type = ZEBRA_ROUTE_STATIC;
15130 + rib->distance = si->distance;
15131 + rib->metric = 0;
15132 + rib->rib_table = rib_table_ipv4;
15133 + rib->nexthop_num = 0;
15135 + switch (si->type)
15137 + case STATIC_IPV4_GATEWAY:
15138 + nexthop_ipv4_add (rib, &si->gate.ipv4);
15139 + break;
15140 + case STATIC_IPV4_IFNAME:
15141 + nexthop_ifname_add (rib, si->gate.ifname);
15142 + break;
15145 + /* Link this rib to the tree. */
15146 + rib_addnode (rn, rib);
15148 + /* Process this prefix. */
15149 + rib_process (rn, NULL);
15153 +int
15154 +static_ipv4_nexthop_same (struct nexthop *nexthop, struct static_ipv4 *si)
15156 + if (nexthop->type == NEXTHOP_TYPE_IPV4
15157 + && si->type == STATIC_IPV4_GATEWAY
15158 + && IPV4_ADDR_SAME (&nexthop->gate.ipv4, &si->gate.ipv4))
15159 + return 1;
15160 + if (nexthop->type == NEXTHOP_TYPE_IFNAME
15161 + && si->type == STATIC_IPV4_IFNAME
15162 + && strcmp (nexthop->ifname, si->gate.ifname) == 0)
15163 + return 1;
15164 + return 0;;
15167 +/* Uninstall static route from RIB. */
15168 +void
15169 +static_ipv4_uninstall (struct prefix_ipv4 *p, struct static_ipv4 *si)
15171 + struct route_node *rn;
15172 + struct rib *rib;
15173 + struct nexthop *nexthop;
15175 + /* Lookup existing route with type and distance. */
15176 + rn = route_node_lookup (rib_table_ipv4->table, (struct prefix *) p);
15177 + if (! rn)
15178 + return;
15180 + for (rib = rn->info; rib; rib = rib->next)
15181 + if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
15182 + break;
15183 + if (! rib)
15185 + route_unlock_node (rn);
15186 + return;
15189 + /* Lookup nexthop. */
15190 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
15191 + if (static_ipv4_nexthop_same (nexthop, si))
15192 + break;
15194 + /* Can't find nexthop. */
15195 + if (! nexthop)
15197 + route_unlock_node (rn);
15198 + return;
15201 + /* Check nexthop. */
15202 + if (rib->nexthop_num == 1)
15204 + rib_delnode (rn, rib);
15205 + rib_process (rn, rib);
15206 + newrib_free (rib);
15207 + route_unlock_node (rn);
15209 + else
15211 + rib_uninstall (rn, rib);
15212 + nexthop_delete (rib, nexthop);
15213 + nexthop_free (nexthop);
15214 + rib_process (rn, rib);
15217 + /* Unlock node. */
15218 + route_unlock_node (rn);
15221 +/* Add static route into static route configuration. */
15222 +int
15223 +static_ipv4_add (struct prefix_ipv4 *p, struct in_addr *gate, char *ifname,
15224 + u_char distance, int table)
15226 + u_char type = 0;
15227 + struct route_node *rn;
15228 + struct static_ipv4 *si;
15229 + struct static_ipv4 *pp;
15230 + struct static_ipv4 *cp;
15232 + /* Lookup static route prefix. */
15233 + rn = route_node_get (static_table_ipv4->table, (struct prefix *) p);
15235 + /* Make flags. */
15236 + if (gate)
15237 + type = STATIC_IPV4_GATEWAY;
15238 + if (ifname)
15239 + type = STATIC_IPV4_IFNAME;
15241 + /* Do nothing if there is a same static route. */
15242 + for (si = rn->info; si; si = si->next)
15244 + if (distance == si->distance
15245 + && type == si->type
15246 + && (! gate || IPV4_ADDR_SAME (gate, &si->gate.ipv4))
15247 + && (! ifname || strcmp (ifname, si->gate.ifname) == 0))
15249 + route_unlock_node (rn);
15250 + return 0;
15254 + /* Make new static route structure. */
15255 + si = XMALLOC (MTYPE_STATIC_IPV4, sizeof (struct static_ipv4));
15256 + memset (si, 0, sizeof (struct static_ipv4));
15258 + si->type = type;
15259 + si->distance = distance;
15261 + if (gate)
15262 + si->gate.ipv4 = *gate;
15263 + if (ifname)
15264 + si->gate.ifname = XSTRDUP (0, ifname);
15266 + /* Add new static route information to the tree with sort by
15267 + distance value and gateway address. */
15268 + for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next)
15270 + if (si->distance < cp->distance)
15271 + break;
15272 + if (si->distance > cp->distance)
15273 + continue;
15274 + if (si->type == STATIC_IPV4_GATEWAY && cp->type == STATIC_IPV4_GATEWAY)
15276 + if (ntohl (si->gate.ipv4.s_addr) < ntohl (cp->gate.ipv4.s_addr))
15277 + break;
15278 + if (ntohl (si->gate.ipv4.s_addr) > ntohl (cp->gate.ipv4.s_addr))
15279 + continue;
15283 + /* Make linked list. */
15284 + if (pp)
15285 + pp->next = si;
15286 + else
15287 + rn->info = si;
15288 + if (cp)
15289 + cp->prev = si;
15290 + si->prev = pp;
15291 + si->next = cp;
15293 + /* Install into rib. */
15294 + static_ipv4_install (p, si);
15296 + return 1;
15299 +/* Delete static route from static route configuration. */
15300 +int
15301 +static_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *gate, char *ifname,
15302 + u_char distance, int table)
15304 + u_char type = 0;
15305 + struct route_node *rn;
15306 + struct static_ipv4 *si;
15308 + /* Lookup static route prefix. */
15309 + rn = route_node_lookup (static_table_ipv4->table, (struct prefix *) p);
15310 + if (! rn)
15311 + return 0;
15313 + /* Make flags. */
15314 + if (gate)
15315 + type = STATIC_IPV4_GATEWAY;
15316 + if (ifname)
15317 + type = STATIC_IPV4_IFNAME;
15319 + /* Find same static route is the tree */
15320 + for (si = rn->info; si; si = si->next)
15321 + if (distance == si->distance
15322 + && type == si->type
15323 + && (! gate || IPV4_ADDR_SAME (gate, &si->gate.ipv4))
15324 + && (! ifname || strcmp (ifname, si->gate.ifname) == 0))
15325 + break;
15327 + /* Can't find static route. */
15328 + if (! si)
15330 + route_unlock_node (rn);
15331 + return 0;
15334 + /* Install into rib. */
15335 + static_ipv4_uninstall (p, si);
15337 + /* Unlink static route from linked list. */
15338 + if (si->prev)
15339 + si->prev->next = si->next;
15340 + else
15341 + rn->info = si->next;
15342 + if (si->next)
15343 + si->next->prev = si->prev;
15345 + /* Free static route configuration. */
15346 + XFREE (MTYPE_STATIC_IPV4, si);
15348 + return 1;
15351 +/* Write IPv4 static route configuration. */
15352 +int
15353 +static_ipv4_write (struct vty *vty)
15355 + struct route_node *rn;
15356 + struct static_ipv4 *si;
15357 + int write;
15359 + write = 0;
15361 + for (rn = route_top (static_table_ipv4->table); rn; rn = route_next (rn))
15362 + for (si = rn->info; si; si = si->next)
15364 + vty_out (vty, "ip route %s/%d", inet_ntoa (rn->p.u.prefix4),
15365 + rn->p.prefixlen);
15367 + switch (si->type)
15369 + case STATIC_IPV4_GATEWAY:
15370 + vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
15371 + break;
15372 + case STATIC_IPV4_IFNAME:
15373 + vty_out (vty, " %s", si->gate.ifname);
15374 + break;
15377 + if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
15378 + vty_out (vty, " %d", si->distance);
15379 + vty_out (vty, "%s", VTY_NEWLINE);
15381 + write = 1;
15383 + return write;
15386 +/* General fucntion for static route. */
15387 +int
15388 +static_ipv4_func (struct vty *vty, int add_cmd,
15389 + char *dest_str, char *mask_str, char *gate_str,
15390 + char *distance_str)
15392 + int ret;
15393 + u_char distance;
15394 + struct prefix_ipv4 p;
15395 + struct in_addr gate;
15396 + struct in_addr mask;
15397 + char *ifname;
15398 + int table = rtm_table_default;
15400 + ret = str2prefix_ipv4 (dest_str, &p);
15401 + if (ret <= 0)
15403 + vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
15404 + return CMD_WARNING;
15407 + /* Cisco like mask notation. */
15408 + if (mask_str)
15410 + ret = inet_aton (mask_str, &mask);
15411 + if (ret == 0)
15413 + vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
15414 + return CMD_WARNING;
15416 + p.prefixlen = ip_masklen (mask);
15419 + /* Apply mask for given prefix. */
15420 + apply_mask_ipv4 (&p);
15422 + /* Administrative distance. */
15423 + if (distance_str)
15424 + distance = atoi (distance_str);
15425 + else
15426 + distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
15428 + /* When gateway is A.B.C.D format, gate is treated as nexthop
15429 + address other case gate is treated as interface name. */
15430 + ret = inet_aton (gate_str, &gate);
15431 + if (ret)
15432 + ifname = NULL;
15433 + else
15434 + ifname = gate_str;
15436 + if (add_cmd)
15437 + static_ipv4_add (&p, ifname ? NULL : &gate, ifname, distance, table);
15438 + else
15439 + static_ipv4_delete (&p, ifname ? NULL : &gate, ifname, distance, table);
15441 + return CMD_SUCCESS;
15444 +/* Static route configuration. */
15445 +DEFUN (ip_route,
15446 + ip_route_cmd,
15447 + "ip route A.B.C.D/M (A.B.C.D|INTERFACE)",
15448 + IP_STR
15449 + "Establish static routes\n"
15450 + "IP destination prefix (e.g. 10.0.0.0/8)\n"
15451 + "IP gateway address\n"
15452 + "IP gateway interface name\n")
15454 + return static_ipv4_func (vty, 1, argv[0], NULL, argv[1], NULL);
15457 +DEFUN (ip_route_mask,
15458 + ip_route_mask_cmd,
15459 + "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE)",
15460 + IP_STR
15461 + "Establish static routes\n"
15462 + "IP destination prefix\n"
15463 + "IP destination prefix mask\n"
15464 + "IP gateway address\n"
15465 + "IP gateway interface name\n")
15467 + return static_ipv4_func (vty, 1, argv[0], argv[1], argv[2], NULL);
15470 +DEFUN (ip_route_pref,
15471 + ip_route_pref_cmd,
15472 + "ip route A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
15473 + IP_STR
15474 + "Establish static routes\n"
15475 + "IP destination prefix (e.g. 10.0.0.0/8)\n"
15476 + "IP gateway address\n"
15477 + "IP gateway interface name\n"
15478 + "Distance value for this route\n")
15480 + return static_ipv4_func (vty, 1, argv[0], NULL, argv[1], argv[2]);
15483 +DEFUN (ip_route_mask_pref,
15484 + ip_route_mask_pref_cmd,
15485 + "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) <1-255>",
15486 + IP_STR
15487 + "Establish static routes\n"
15488 + "IP destination prefix\n"
15489 + "IP destination prefix mask\n"
15490 + "IP gateway address\n"
15491 + "IP gateway interface name\n"
15492 + "Distance value for this route\n")
15494 + return static_ipv4_func (vty, 1, argv[0], argv[1], argv[2], argv[3]);
15497 +DEFUN (no_ip_route,
15498 + no_ip_route_cmd,
15499 + "no ip route A.B.C.D/M (A.B.C.D|INTERFACE)",
15500 + NO_STR
15501 + IP_STR
15502 + "Establish static routes\n"
15503 + "IP destination prefix (e.g. 10.0.0.0/8)\n"
15504 + "IP gateway address\n"
15505 + "IP gateway interface name\n")
15507 + return static_ipv4_func (vty, 0, argv[0], NULL, argv[1], NULL);
15510 +DEFUN (no_ip_route_mask,
15511 + no_ip_route_mask_cmd,
15512 + "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE)",
15513 + NO_STR
15514 + IP_STR
15515 + "Establish static routes\n"
15516 + "IP destination prefix\n"
15517 + "IP destination prefix mask\n"
15518 + "IP gateway address\n"
15519 + "IP gateway interface name\n")
15521 + return static_ipv4_func (vty, 0, argv[0], argv[1], argv[2], NULL);
15524 +DEFUN (no_ip_route_pref,
15525 + no_ip_route_pref_cmd,
15526 + "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
15527 + NO_STR
15528 + IP_STR
15529 + "Establish static routes\n"
15530 + "IP destination prefix (e.g. 10.0.0.0/8)\n"
15531 + "IP gateway address\n"
15532 + "IP gateway interface name\n"
15533 + "Distance value for this route\n")
15535 + return static_ipv4_func (vty, 0, argv[0], NULL, argv[1], argv[2]);
15538 +DEFUN (no_ip_route_mask_pref,
15539 + no_ip_route_mask_pref_cmd,
15540 + "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) <1-255>",
15541 + NO_STR
15542 + IP_STR
15543 + "Establish static routes\n"
15544 + "IP destination prefix\n"
15545 + "IP destination prefix mask\n"
15546 + "IP gateway address\n"
15547 + "IP gateway interface name\n"
15548 + "Distance value for this route\n")
15550 + return static_ipv4_func (vty, 0, argv[0], argv[1], argv[2], argv[3]);
15553 +#ifdef HAVE_IPV6
15554 +/* Install static route into rib. */
15555 +void
15556 +static_ipv6_install (struct prefix_ipv6 *p, struct static_ipv6 *si)
15558 + struct rib *rib;
15559 + struct route_node *rn;
15561 + /* Lookup existing route */
15562 + rn = route_node_get (rib_table_ipv6->table, (struct prefix *) p);
15563 + for (rib = rn->info; rib; rib = rib->next)
15564 + if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
15565 + break;
15567 + if (rib)
15569 + /* Same distance static route is there. Update it with new
15570 + nexthop. */
15571 + rib_uninstall (rn, rib);
15572 + route_unlock_node (rn);
15574 + switch (si->type)
15576 + case STATIC_IPV6_GATEWAY:
15577 + nexthop_ipv6_add (rib, &si->ipv6);
15578 + break;
15579 + case STATIC_IPV6_IFNAME:
15580 + nexthop_ifname_add (rib, si->ifname);
15581 + break;
15582 + case STATIC_IPV6_GATEWAY_IFNAME:
15583 + nexthop_ipv6_ifname_add (rib, &si->ipv6, si->ifname);
15584 + break;
15586 + rib_process (rn, NULL);
15588 + else
15590 + /* This is new static route. */
15591 + rib = XMALLOC (MTYPE_RIB, sizeof (struct rib));
15592 + memset (rib, 0, sizeof (struct rib));
15594 + rib->type = ZEBRA_ROUTE_STATIC;
15595 + rib->distance = si->distance;
15596 + rib->rib_table = rib_table_ipv6;
15597 + rib->metric = 0;
15598 + rib->nexthop_num = 0;
15600 + switch (si->type)
15602 + case STATIC_IPV6_GATEWAY:
15603 + nexthop_ipv6_add (rib, &si->ipv6);
15604 + break;
15605 + case STATIC_IPV6_IFNAME:
15606 + nexthop_ifname_add (rib, si->ifname);
15607 + break;
15608 + case STATIC_IPV6_GATEWAY_IFNAME:
15609 + nexthop_ipv6_ifname_add (rib, &si->ipv6, si->ifname);
15610 + break;
15613 + /* Link this rib to the tree. */
15614 + rib_addnode (rn, rib);
15616 + /* Process this prefix. */
15617 + rib_process (rn, NULL);
15621 +int
15622 +static_ipv6_nexthop_same (struct nexthop *nexthop, struct static_ipv6 *si)
15624 + if (nexthop->type == NEXTHOP_TYPE_IPV6
15625 + && si->type == STATIC_IPV6_GATEWAY
15626 + && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->ipv6))
15627 + return 1;
15628 + if (nexthop->type == NEXTHOP_TYPE_IFNAME
15629 + && si->type == STATIC_IPV6_IFNAME
15630 + && strcmp (nexthop->ifname, si->ifname) == 0)
15631 + return 1;
15632 + if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME
15633 + && si->type == STATIC_IPV6_GATEWAY_IFNAME
15634 + && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->ipv6)
15635 + && strcmp (nexthop->ifname, si->ifname) == 0)
15636 + return 1;
15637 + return 0;;
15640 +void
15641 +static_ipv6_uninstall (struct prefix_ipv6 *p, struct static_ipv6 *si)
15643 + struct route_node *rn;
15644 + struct rib *rib;
15645 + struct nexthop *nexthop;
15647 + /* Lookup existing route with type and distance. */
15648 + rn = route_node_lookup (rib_table_ipv6->table, (struct prefix *) p);
15649 + if (! rn)
15650 + return;
15652 + for (rib = rn->info; rib; rib = rib->next)
15653 + if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
15654 + break;
15655 + if (! rib)
15657 + route_unlock_node (rn);
15658 + return;
15661 + /* Lookup nexthop. */
15662 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
15663 + if (static_ipv6_nexthop_same (nexthop, si))
15664 + break;
15666 + /* Can't find nexthop. */
15667 + if (! nexthop)
15669 + route_unlock_node (rn);
15670 + return;
15673 + /* Check nexthop. */
15674 + if (rib->nexthop_num == 1)
15676 + rib_delnode (rn, rib);
15677 + rib_process (rn, rib);
15678 + newrib_free (rib);
15679 + route_unlock_node (rn);
15681 + else
15683 + rib_uninstall (rn, rib);
15684 + nexthop_delete (rib, nexthop);
15685 + nexthop_free (nexthop);
15686 + rib_process (rn, rib);
15689 + /* Unlock node. */
15690 + route_unlock_node (rn);
15693 +/* Add static route into static route configuration. */
15694 +int
15695 +static_ipv6_add (struct prefix_ipv6 *p, u_char type, struct in6_addr *gate,
15696 + char *ifname, u_char distance, int table)
15698 + struct route_node *rn;
15699 + struct static_ipv6 *si;
15700 + struct static_ipv6 *pp;
15701 + struct static_ipv6 *cp;
15703 + /* Lookup static route prefix. */
15704 + rn = route_node_get (static_table_ipv6->table, (struct prefix *) p);
15706 + /* Do nothing if there is a same static route. */
15707 + for (si = rn->info; si; si = si->next)
15709 + if (distance == si->distance
15710 + && type == si->type
15711 + && (! gate || IPV6_ADDR_SAME (gate, &si->ipv6))
15712 + && (! ifname || strcmp (ifname, si->ifname) == 0))
15714 + route_unlock_node (rn);
15715 + return 0;
15719 + /* Make new static route structure. */
15720 + si = XMALLOC (MTYPE_STATIC_IPV6, sizeof (struct static_ipv6));
15721 + memset (si, 0, sizeof (struct static_ipv6));
15723 + si->type = type;
15724 + si->distance = distance;
15726 + switch (type)
15728 + case STATIC_IPV6_GATEWAY:
15729 + si->ipv6 = *gate;
15730 + break;
15731 + case STATIC_IPV6_IFNAME:
15732 + si->ifname = XSTRDUP (0, ifname);
15733 + break;
15734 + case STATIC_IPV6_GATEWAY_IFNAME:
15735 + si->ipv6 = *gate;
15736 + si->ifname = XSTRDUP (0, ifname);
15737 + break;
15740 + /* Add new static route information to the tree with sort by
15741 + distance value and gateway address. */
15742 + for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next)
15744 + if (si->distance < cp->distance)
15745 + break;
15746 + if (si->distance > cp->distance)
15747 + continue;
15750 + /* Make linked list. */
15751 + if (pp)
15752 + pp->next = si;
15753 + else
15754 + rn->info = si;
15755 + if (cp)
15756 + cp->prev = si;
15757 + si->prev = pp;
15758 + si->next = cp;
15760 + /* Install into rib. */
15761 + static_ipv6_install (p, si);
15763 + return 1;
15766 +/* Delete static route from static route configuration. */
15767 +int
15768 +static_ipv6_delete (struct prefix_ipv6 *p, u_char type, struct in6_addr *gate,
15769 + char *ifname, u_char distance, int table)
15771 + struct route_node *rn;
15772 + struct static_ipv6 *si;
15774 + /* Lookup static route prefix. */
15775 + rn = route_node_lookup (static_table_ipv6->table, (struct prefix *) p);
15776 + if (! rn)
15777 + return 0;
15779 + /* Find same static route is the tree */
15780 + for (si = rn->info; si; si = si->next)
15781 + if (distance == si->distance
15782 + && type == si->type
15783 + && (! gate || IPV6_ADDR_SAME (gate, &si->ipv6))
15784 + && (! ifname || strcmp (ifname, si->ifname) == 0))
15785 + break;
15787 + /* Can't find static route. */
15788 + if (! si)
15790 + route_unlock_node (rn);
15791 + return 0;
15794 + /* Install into rib. */
15795 + static_ipv6_uninstall (p, si);
15797 + /* Unlink static route from linked list. */
15798 + if (si->prev)
15799 + si->prev->next = si->next;
15800 + else
15801 + rn->info = si->next;
15802 + if (si->next)
15803 + si->next->prev = si->prev;
15805 + /* Free static route configuration. */
15806 + XFREE (MTYPE_STATIC_IPV6, si);
15808 + return 1;
15811 +/* General fucntion for IPv6 static route. */
15812 +int
15813 +static_ipv6_func (struct vty *vty, int add_cmd, char *dest_str,
15814 + char *gate_str, char *ifname, char *distance_str)
15816 + int ret;
15817 + u_char distance;
15818 + struct prefix_ipv6 p;
15819 + struct in6_addr *gate = NULL;
15820 + struct in6_addr gate_addr;
15821 + u_char type = 0;
15822 + int table = rtm_table_default;
15824 + ret = str2prefix_ipv6 (dest_str, &p);
15825 + if (ret <= 0)
15827 + vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
15828 + return CMD_WARNING;
15831 + /* Apply mask for given prefix. */
15832 + apply_mask_ipv6 (&p);
15834 + /* Administrative distance. */
15835 + if (distance_str)
15836 + distance = atoi (distance_str);
15837 + else
15838 + distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
15840 + /* When gateway is valid IPv6 addrees, then gate is treated as
15841 + nexthop address other case gate is treated as interface name. */
15842 + ret = inet_pton (AF_INET6, gate_str, &gate_addr);
15844 + if (ifname)
15846 + /* When ifname is specified. It must be come with gateway
15847 + address. */
15848 + if (ret != 1)
15850 + vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
15851 + return CMD_WARNING;
15853 + type = STATIC_IPV6_GATEWAY_IFNAME;
15854 + gate = &gate_addr;
15856 + else
15858 + if (ret == 1)
15860 + type = STATIC_IPV6_GATEWAY;
15861 + gate = &gate_addr;
15863 + else
15865 + type = STATIC_IPV6_IFNAME;
15866 + ifname = gate_str;
15870 + if (add_cmd)
15871 + static_ipv6_add (&p, type, gate, ifname, distance, table);
15872 + else
15873 + static_ipv6_delete (&p, type, gate, ifname, distance, table);
15875 + return CMD_SUCCESS;
15878 +/* Write IPv6 static route configuration. */
15879 +int
15880 +static_ipv6_write (struct vty *vty)
15882 + struct route_node *rn;
15883 + struct static_ipv6 *si;
15884 + int write;
15885 + char buf[BUFSIZ];
15887 + write = 0;
15889 + for (rn = route_top (static_table_ipv6->table); rn; rn = route_next (rn))
15890 + for (si = rn->info; si; si = si->next)
15892 + vty_out (vty, "ipv6 route %s/%d",
15893 + inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
15894 + rn->p.prefixlen);
15896 + switch (si->type)
15898 + case STATIC_IPV6_GATEWAY:
15899 + vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
15900 + break;
15901 + case STATIC_IPV6_IFNAME:
15902 + vty_out (vty, " %s", si->ifname);
15903 + break;
15904 + case STATIC_IPV6_GATEWAY_IFNAME:
15905 + vty_out (vty, " %s %s",
15906 + inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
15907 + break;
15910 + if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
15911 + vty_out (vty, " %d", si->distance);
15912 + vty_out (vty, "%s", VTY_NEWLINE);
15914 + write = 1;
15916 + return write;
15919 +DEFUN (ipv6_route,
15920 + ipv6_route_cmd,
15921 + "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
15922 + IP_STR
15923 + "Establish static routes\n"
15924 + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
15925 + "IPv6 gateway address\n"
15926 + "IPv6 gateway interface name\n")
15928 + return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL);
15931 +DEFUN (ipv6_route_ifname,
15932 + ipv6_route_ifname_cmd,
15933 + "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
15934 + IP_STR
15935 + "Establish static routes\n"
15936 + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
15937 + "IPv6 gateway address\n"
15938 + "IPv6 gateway interface name\n")
15940 + return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL);
15943 +DEFUN (ipv6_route_pref,
15944 + ipv6_route_pref_cmd,
15945 + "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
15946 + IP_STR
15947 + "Establish static routes\n"
15948 + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
15949 + "IPv6 gateway address\n"
15950 + "IPv6 gateway interface name\n"
15951 + "Distance value for this prefix\n")
15953 + return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2]);
15956 +DEFUN (ipv6_route_ifname_pref,
15957 + ipv6_route_ifname_pref_cmd,
15958 + "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
15959 + IP_STR
15960 + "Establish static routes\n"
15961 + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
15962 + "IPv6 gateway address\n"
15963 + "IPv6 gateway interface name\n"
15964 + "Distance value for this prefix\n")
15966 + return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3]);
15969 +DEFUN (no_ipv6_route,
15970 + no_ipv6_route_cmd,
15971 + "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
15972 + NO_STR
15973 + IP_STR
15974 + "Establish static routes\n"
15975 + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
15976 + "IPv6 gateway address\n"
15977 + "IPv6 gateway interface name\n")
15979 + return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL);
15982 +DEFUN (no_ipv6_route_ifname,
15983 + no_ipv6_route_ifname_cmd,
15984 + "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
15985 + NO_STR
15986 + IP_STR
15987 + "Establish static routes\n"
15988 + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
15989 + "IPv6 gateway address\n"
15990 + "IPv6 gateway interface name\n")
15992 + return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL);
15995 +DEFUN (no_ipv6_route_pref,
15996 + no_ipv6_route_pref_cmd,
15997 + "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
15998 + NO_STR
15999 + IP_STR
16000 + "Establish static routes\n"
16001 + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
16002 + "IPv6 gateway address\n"
16003 + "IPv6 gateway interface name\n"
16004 + "Distance value for this prefix\n")
16006 + return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2]);
16009 +DEFUN (no_ipv6_route_ifname_pref,
16010 + no_ipv6_route_ifname_pref_cmd,
16011 + "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
16012 + NO_STR
16013 + IP_STR
16014 + "Establish static routes\n"
16015 + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
16016 + "IPv6 gateway address\n"
16017 + "IPv6 gateway interface name\n"
16018 + "Distance value for this prefix\n")
16020 + return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3]);
16022 +#endif /* HAVE_IPV6 */
16025 +/* Clean up routines. */
16026 +void
16027 +rib_weed_table (struct route_table *rib_table)
16029 + struct route_node *rn;
16030 + struct rib *rib;
16031 + struct rib *next;
16033 + for (rn = route_top (rib_table); rn; rn = route_next (rn))
16034 + for (rib = rn->info; rib; rib = next)
16036 + next = rib->next;
16038 + if (rib->table != rtm_table_default &&
16039 + rib->table != RT_TABLE_MAIN)
16041 + rib_delnode (rn, rib);
16042 + newrib_free (rib);
16043 + route_unlock_node (rn);
16048 +/* Delete all routes from unmanaged tables. */
16049 +void
16050 +zrib_weed_tables ()
16052 + rib_weed_table (rib_table_ipv4->table);
16053 +#ifdef HAVE_IPV6
16054 + rib_weed_table (rib_table_ipv6->table);
16055 +#endif /* HAVE_IPV6 */
16058 +void
16059 +rib_sweep_table (struct route_table *rib_table)
16061 + struct route_node *rn;
16062 + struct rib *rib;
16063 + struct rib *next;
16064 + int ret = 0;
16066 + for (rn = route_top (rib_table); rn; rn = route_next (rn))
16067 + for (rib = rn->info; rib; rib = next)
16069 + next = rib->next;
16071 + if ((rib->type == ZEBRA_ROUTE_KERNEL) &&
16072 + CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELFROUTE))
16074 + ret = rib_uninstall_kernel (rn, rib);
16076 + if (! ret)
16078 + rib_delnode (rn, rib);
16079 + newrib_free (rib);
16080 + route_unlock_node (rn);
16086 +void
16087 +zrib_sweep_route ()
16089 + rib_sweep_table (rib_table_ipv4->table);
16090 +#ifdef HAVE_IPV6
16091 + rib_sweep_table (rib_table_ipv6->table);
16092 +#endif /* HAVE_IPV6 */
16095 +/* Static ip route configuration write function. */
16096 +int
16097 +config_write_ip (struct vty *vty)
16099 + int write = 0;
16101 + router_id_write (vty);
16103 + write += static_ipv4_write (vty);
16104 +#ifdef HAVE_IPV6
16105 + write += static_ipv6_write (vty);
16106 +#endif /* HAVE_IPV6 */
16108 + return write;
16111 +/* IP node for static routes. */
16112 +struct cmd_node ip_node =
16114 + IP_NODE,
16115 + "", /* This node has no interface. */
16119 +/* Routing information base initialize. */
16120 +void
16121 +zebra_rib_init ()
16123 + install_node (&ip_node, config_write_ip);
16125 + rib_table_ipv4 = rib_table_init();
16126 + rib_table_ipv4->redistribute_add = redistribute_add;
16127 + rib_table_ipv4->redistribute_delete = redistribute_delete;
16128 + rib_table_ipv4->rib_install_kernel = rib_install_kernel;
16129 + rib_table_ipv4->rib_uninstall_kernel = rib_uninstall_kernel;
16131 + static_table_ipv4 = rib_table_init();
16132 + static_table_ipv4->redistribute_add = redistribute_add;
16133 + static_table_ipv4->redistribute_delete = redistribute_delete;
16134 + static_table_ipv4->rib_install_kernel = rib_install_kernel;
16135 + static_table_ipv4->rib_uninstall_kernel = rib_uninstall_kernel;
16137 + install_element (VIEW_NODE, &show_ip_route_cmd);
16138 + install_element (VIEW_NODE, &show_ip_route_addr_cmd);
16139 + install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
16140 + install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
16141 + install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
16142 + install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
16143 + install_element (ENABLE_NODE, &show_ip_route_cmd);
16144 + install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
16145 + install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
16146 + install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
16147 + install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
16148 + install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
16149 + install_element (CONFIG_NODE, &ip_route_cmd);
16150 + install_element (CONFIG_NODE, &ip_route_mask_cmd);
16151 + install_element (CONFIG_NODE, &no_ip_route_cmd);
16152 + install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
16153 + install_element (CONFIG_NODE, &ip_route_pref_cmd);
16154 + install_element (CONFIG_NODE, &ip_route_mask_pref_cmd);
16155 + install_element (CONFIG_NODE, &no_ip_route_pref_cmd);
16156 + install_element (CONFIG_NODE, &no_ip_route_mask_pref_cmd);
16158 +#ifdef HAVE_IPV6
16159 + rib_table_ipv6 = rib_table_init();
16160 + rib_table_ipv6->redistribute_add = redistribute_add;
16161 + rib_table_ipv6->redistribute_delete = redistribute_delete;
16162 + rib_table_ipv6->rib_install_kernel = rib_install_kernel;
16163 + rib_table_ipv6->rib_uninstall_kernel = rib_uninstall_kernel;
16165 + static_table_ipv6 = rib_table_init();
16166 + static_table_ipv6->redistribute_add = redistribute_add;
16167 + static_table_ipv6->redistribute_delete = redistribute_delete;
16168 + static_table_ipv6->rib_install_kernel = rib_install_kernel;
16169 + static_table_ipv6->rib_uninstall_kernel = rib_uninstall_kernel;
16171 + install_element (CONFIG_NODE, &ipv6_route_cmd);
16172 + install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
16173 + install_element (CONFIG_NODE, &no_ipv6_route_cmd);
16174 + install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
16175 + install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
16176 + install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
16177 + install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
16178 + install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
16179 + install_element (VIEW_NODE, &show_ipv6_route_cmd);
16180 + install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
16181 + install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
16182 + install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
16183 + install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
16184 + install_element (ENABLE_NODE, &show_ipv6_route_cmd);
16185 + install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
16186 + install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
16187 + install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
16188 + install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
16189 +#endif /* HAVE_IPV6 */
16191 diff -uNr --exclude=CVS zebra/zebra/zrib.h zebra-ldp/zebra/zrib.h
16192 --- zebra/zebra/zrib.h Wed Dec 31 19:00:00 1969
16193 +++ zebra-ldp/zebra/zrib.h Sat Aug 24 00:14:49 2002
16194 @@ -0,0 +1,76 @@
16196 + * Routing Information Base header
16197 + * Copyright (C) 1997 Kunihiro Ishiguro
16199 + * This file is part of GNU Zebra.
16201 + * GNU Zebra is free software; you can redistribute it and/or modify it
16202 + * under the terms of the GNU General Public License as published by the
16203 + * Free Software Foundation; either version 2, or (at your option) any
16204 + * later version.
16206 + * GNU Zebra is distributed in the hope that it will be useful, but
16207 + * WITHOUT ANY WARRANTY; without even the implied warranty of
16208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16209 + * General Public License for more details.
16211 + * You should have received a copy of the GNU General Public License
16212 + * along with GNU Zebra; see the file COPYING. If not, write to the Free
16213 + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16214 + * 02111-1307, USA.
16215 + */
16217 +#ifndef _ZEBRA_RIB_H
16218 +#define _ZEBRA_RIB_H
16220 +/* Static route information. */
16221 +struct static_ipv4
16223 + /* For linked list. */
16224 + struct static_ipv4 *prev;
16225 + struct static_ipv4 *next;
16227 + /* Administrative distance. */
16228 + u_char distance;
16230 + /* Flag for this static route's type. */
16231 + u_char type;
16232 +#define STATIC_IPV4_GATEWAY 1
16233 +#define STATIC_IPV4_IFNAME 2
16235 + /* Nexthop value. */
16236 + union
16238 + struct in_addr ipv4;
16239 + char *ifname;
16240 + } gate;
16243 +#ifdef HAVE_IPV6
16244 +/* Static route information. */
16245 +struct static_ipv6
16247 + /* For linked list. */
16248 + struct static_ipv6 *prev;
16249 + struct static_ipv6 *next;
16251 + /* Administrative distance. */
16252 + u_char distance;
16254 + /* Flag for this static route's type. */
16255 + u_char type;
16256 +#define STATIC_IPV6_GATEWAY 1
16257 +#define STATIC_IPV6_GATEWAY_IFNAME 2
16258 +#define STATIC_IPV6_IFNAME 3
16260 + /* Nexthop value. */
16261 + struct in6_addr ipv6;
16262 + char *ifname;
16264 +#endif /* HAVE_IPV6 */
16266 +void zrib_weed_tables ();
16267 +void zrib_sweep_route ();
16268 +void zebra_rib_init ();
16270 +#endif /*_ZEBRA_RIB_H */
16271 diff -uNr --exclude=CVS zebra/zebra/zserv.c zebra-ldp/zebra/zserv.c
16272 --- zebra/zebra/zserv.c Sat Aug 24 00:14:58 2002
16273 +++ zebra-ldp/zebra/zserv.c Sun Aug 25 21:54:08 2002
16274 @@ -35,6 +35,7 @@
16275 #include "zclient.h"
16277 #include "zebra/zserv.h"
16278 +#include "zebra/router-id.h"
16279 #include "zebra/redistribute.h"
16280 #include "zebra/debug.h"
16281 #include "zebra/ipforward.h"
16282 @@ -71,7 +72,11 @@
16283 "ZEBRA_IPV4_NEXTHOP_LOOKUP",
16284 "ZEBRA_IPV6_NEXTHOP_LOOKUP",
16285 "ZEBRA_IPV4_IMPORT_LOOKUP",
16286 - "ZEBRA_IPV6_IMPORT_LOOKUP"
16287 + "ZEBRA_IPV6_IMPORT_LOOKUP",
16288 + "ZEBRA_ROUTER_ID_ADD",
16289 + "ZEBRA_ROUTER_ID_DELETE",
16290 + "ZEBRA_ROUTER_ID_UPDATE",
16291 + "ZEBRA_IPV4_SET_MPLSINDEX"
16294 /* Interface is added. Send ZEBRA_INTERFACE_ADD to client. */
16295 @@ -850,6 +855,38 @@
16296 return writen (client->sock, s->data, stream_get_endp (s));
16299 +/* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */
16300 +int
16301 +zsend_router_id_update (struct zserv *client, struct prefix *p)
16303 + struct stream *s;
16304 + int blen;
16306 + /* Check this client need interface information. */
16307 + if (!client->ridinfo)
16308 + return -1;
16310 + s = client->obuf;
16311 + stream_reset (s);
16313 + /* Place holder for size. */
16314 + stream_putw (s, 0);
16316 + /* Message type. */
16317 + stream_putc (s, ZEBRA_ROUTER_ID_UPDATE);
16319 + /* Prefix information. */
16320 + stream_putc (s, p->family);
16321 + blen = prefix_blen (p);
16322 + stream_put (s, &p->u.prefix, blen);
16323 + stream_putc (s, p->prefixlen);
16325 + /* Write packet size. */
16326 + stream_putw_at (s, 0, stream_get_endp (s));
16328 + return writen (client->sock, s->data, stream_get_endp (s));
16331 /* Register zebra server interface information. Send current all
16332 interface and address information. */
16333 void
16334 @@ -889,6 +926,64 @@
16335 client->ifinfo = 0;
16338 +void
16339 +zread_ipv4_set_mplsindex (struct zserv *client, u_short length)
16341 + struct prefix_ipv4 p;
16342 + struct in_addr gate;
16343 + struct stream *s;
16344 + unsigned int mplsindex;
16345 + unsigned int ifindex;
16346 + struct route_node *rn;
16347 + struct rib *rib;
16348 + struct nexthop *nexthop;
16350 + /* Get input stream. */
16351 + s = client->ibuf;
16353 + /* IPv4 prefix. */
16354 + memset (&p, 0, sizeof (struct prefix_ipv4));
16355 + p.family = AF_INET;
16356 + p.prefixlen = stream_getc (s);
16357 + stream_get (&p.prefix, s, PSIZE (p.prefixlen));
16359 + /* Nexthop info */
16360 + gate.s_addr = stream_get_ipv4 (s);
16361 + ifindex = stream_getl (s);
16363 + /* the MPLS index */
16364 + mplsindex = stream_getl (s);
16366 + apply_mask_ipv4 (&p);
16367 + rn = route_node_get (rib_table_ipv4->table, (struct prefix *)&p);
16368 + if (!rn)
16369 + return;
16371 + for (rib = rn->info; rib; rib = rib->next)
16373 + if (!CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
16375 + continue;
16378 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
16380 + if (!CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
16382 + continue;
16384 + if (nexthop->ifindex == ifindex
16385 + && nexthop->gate.ipv4.s_addr == gate.s_addr)
16387 + SET_FLAG (rib->flags, ZEBRA_FLAG_MPLS_CHANGED);
16388 + nexthop->mplsindex = mplsindex;
16393 + rib_process (rn, NULL);
16396 /* This function support multiple nexthop. */
16397 void
16398 zread_ipv4_add (struct zserv *client, u_short length)
16399 @@ -914,6 +1009,7 @@
16400 /* Type, flags, message. */
16401 rib->type = stream_getc (s);
16402 rib->flags = stream_getc (s);
16403 + rib->rib_table = rib_table_ipv4;
16404 message = stream_getc (s);
16405 rib->uptime = time (NULL);
16407 @@ -977,7 +1073,7 @@
16408 u_char nexthop_num;
16409 u_char nexthop_type;
16410 u_char ifname_len;
16413 s = client->ibuf;
16414 ifindex = 0;
16415 nexthop.s_addr = 0;
16416 @@ -1071,7 +1167,7 @@
16417 struct in6_addr nexthop;
16418 unsigned long ifindex;
16419 struct prefix_ipv6 p;
16422 s = client->ibuf;
16423 ifindex = 0;
16424 memset (&nexthop, 0, sizeof (struct in6_addr));
16425 @@ -1135,7 +1231,7 @@
16426 struct in6_addr nexthop;
16427 unsigned long ifindex;
16428 struct prefix_ipv6 p;
16431 s = client->ibuf;
16432 ifindex = 0;
16433 memset (&nexthop, 0, sizeof (struct in6_addr));
16434 @@ -1243,6 +1339,27 @@
16436 #endif /* HAVE_IPV6 */
16438 +/* Register zebra server router-id information. Send current router-id */
16439 +void
16440 +zread_router_id_add (struct zserv *client, u_short length)
16442 + struct prefix p;
16444 + /* Router-id information is needed. */
16445 + client->ridinfo = 1;
16447 + router_id_get (&p);
16449 + zsend_router_id_update (client,&p);
16452 +/* Unregister zebra server router-id information. */
16453 +void
16454 +zread_router_id_delete (struct zserv *client, u_short length)
16456 + client->ridinfo = 0;
16459 /* Close zebra client. */
16460 void
16461 zebra_client_close (struct zserv *client)
16462 @@ -1354,6 +1471,15 @@
16464 switch (command)
16466 + case ZEBRA_IPV4_SET_MPLSINDEX:
16467 + zread_ipv4_set_mplsindex (client, length);
16468 + break;
16469 + case ZEBRA_ROUTER_ID_ADD:
16470 + zread_router_id_add (client, length);
16471 + break;
16472 + case ZEBRA_ROUTER_ID_DELETE:
16473 + zread_router_id_delete (client, length);
16474 + break;
16475 case ZEBRA_INTERFACE_ADD:
16476 zread_interface_add (client, length);
16477 break;
16478 diff -uNr --exclude=CVS zebra/zebra/zserv.h zebra-ldp/zebra/zserv.h
16479 --- zebra/zebra/zserv.h Sat Aug 24 00:14:58 2002
16480 +++ zebra-ldp/zebra/zserv.h Sat Aug 24 00:14:49 2002
16481 @@ -56,6 +56,9 @@
16483 /* Interface information. */
16484 u_char ifinfo;
16486 + /* Router-id information. */
16487 + u_char ridinfo;
16490 /* Count prefix size from mask length */
16491 @@ -125,6 +128,9 @@
16492 zsend_ipv6_delete_multipath (struct zserv *, struct prefix *, struct rib *);
16494 #endif /* HAVE_IPV6 */
16496 +int
16497 +zsend_router_id_update(struct zserv *, struct prefix *);
16499 extern pid_t pid;
16500 extern pid_t old_pid;