Minor fix up to label release and withdrawl processing. Main change
[mpls-ldp-portable.git] / zebra-ldp.diff
blobc4b854981058d6815715fc1385e035932532d932
1 diff --exclude=.p4config -uNr zebra/bgpd/bgpd.c zebra-ldp/bgpd/bgpd.c
2 --- zebra/bgpd/bgpd.c 2003-03-29 18:14:53.000000000 -0600
3 +++ zebra-ldp/bgpd/bgpd.c 2003-03-10 14:56:26.000000000 -0600
4 @@ -63,6 +63,8 @@
5 /* BGP process wide configuration. */
6 static struct bgp_master bgp_master;
8 +extern struct in_addr router_id_zebra;
10 /* BGP process wide configuration pointer to export. */
11 struct bgp_master *bm;
13 @@ -179,38 +181,6 @@
14 return 0;
17 -/* Unset BGP router identifier. */
18 -int
19 -bgp_router_id_unset (struct bgp *bgp)
21 - struct peer *peer;
22 - struct listnode *nn;
24 - if (! bgp_config_check (bgp, BGP_CONFIG_ROUTER_ID))
25 - return 0;
27 - bgp->router_id.s_addr = 0;
28 - bgp_config_unset (bgp, BGP_CONFIG_ROUTER_ID);
30 - /* Clear peer router id configuration. */
31 - LIST_LOOP (bgp->peer, peer, nn)
32 - {
33 - peer->local_id.s_addr = 0;
34 - }
36 - /* Set router-id from interface's address. */
37 - bgp_if_update_all ();
39 - /* Reset all BGP sessions to use new router-id. */
40 - LIST_LOOP (bgp->peer, peer, nn)
41 - {
42 - if (peer->status == Established)
43 - bgp_notify_send (peer, BGP_NOTIFY_CEASE,
44 - BGP_NOTIFY_CEASE_CONFIG_CHANGE);
45 - }
47 - return 0;
50 /* BGP's cluster-id control. */
51 int
52 @@ -1728,7 +1698,7 @@
54 bgp = bgp_create (as, name);
55 listnode_add (bm->bgp, bgp);
56 - bgp_if_update_all ();
57 + bgp_router_id_set(bgp, &router_id_zebra);
58 *bgp_val = bgp;
60 return 0;
61 diff --exclude=.p4config -uNr zebra/bgpd/bgpd.h zebra-ldp/bgpd/bgpd.h
62 --- zebra/bgpd/bgpd.h 2003-03-29 18:14:54.000000000 -0600
63 +++ zebra-ldp/bgpd/bgpd.h 2003-03-10 14:56:27.000000000 -0600
64 @@ -74,6 +74,7 @@
66 /* BGP router identifier. */
67 struct in_addr router_id;
68 + struct in_addr router_id_static;
70 /* BGP route reflector cluster ID. */
71 struct in_addr cluster_id;
72 diff --exclude=.p4config -uNr zebra/bgpd/bgp_vty.c zebra-ldp/bgpd/bgp_vty.c
73 --- zebra/bgpd/bgp_vty.c 2003-03-29 18:14:52.000000000 -0600
74 +++ zebra-ldp/bgpd/bgp_vty.c 2003-03-10 14:56:22.000000000 -0600
75 @@ -39,6 +39,8 @@
76 #include "bgpd/bgp_route.h"
77 #include "bgpd/bgp_zebra.h"
79 +extern struct in_addr router_id_zebra;
81 /* Utility function to get address family from current node. */
82 afi_t
83 bgp_node_afi (struct vty *vty)
84 @@ -398,6 +400,7 @@
85 return CMD_WARNING;
88 + bgp->router_id_static = id;
89 bgp_router_id_set (bgp, &id);
91 return CMD_SUCCESS;
92 @@ -425,14 +428,15 @@
93 return CMD_WARNING;
96 - if (! IPV4_ADDR_SAME (&bgp->router_id, &id))
97 + if (! IPV4_ADDR_SAME (&bgp->router_id_static, &id))
99 vty_out (vty, "%% BGP router-id doesn't match%s", VTY_NEWLINE);
100 return CMD_WARNING;
104 - bgp_router_id_unset (bgp);
105 + bgp->router_id_static.s_addr = 0;
106 + bgp_router_id_set (bgp, &router_id_zebra);
108 return CMD_SUCCESS;
110 diff --exclude=.p4config -uNr zebra/bgpd/bgp_zebra.c zebra-ldp/bgpd/bgp_zebra.c
111 --- zebra/bgpd/bgp_zebra.c 2003-03-29 18:14:52.000000000 -0600
112 +++ zebra-ldp/bgpd/bgp_zebra.c 2003-03-10 14:56:23.000000000 -0600
113 @@ -39,61 +39,24 @@
115 /* All information about zebra. */
116 static struct zclient *zclient = NULL;
117 +struct in_addr router_id_zebra;
119 -/* Update default router id. */
120 +/* Router-id update message from zebra. */
122 -bgp_if_update (struct interface *ifp)
123 +bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length)
125 - struct bgp *bgp;
126 - listnode cn;
127 + struct prefix router_id;
128 struct listnode *nn;
129 - struct listnode *nm;
130 - struct peer *peer;
132 - for (cn = listhead (ifp->connected); cn; nextnode (cn))
134 - struct connected *co;
135 - struct in_addr addr;
137 - co = getdata (cn);
139 - if (co->address->family == AF_INET)
141 - addr = co->address->u.prefix4;
143 - /* Ignore NET127. */
144 - if (IPV4_NET127 (ntohl (addr.s_addr)))
145 - continue;
146 + struct bgp *bgp;
148 - LIST_LOOP (bm->bgp, bgp, nn)
150 - /* Respect configured router id */
151 - if (! (bgp->config & BGP_CONFIG_ROUTER_ID))
152 - if (ntohl (bgp->router_id.s_addr) < ntohl (addr.s_addr))
154 - bgp->router_id = addr;
155 - LIST_LOOP (bgp->peer, peer, nm)
157 - peer->local_id = addr;
163 - return 0;
165 + zebra_router_id_update_read(zclient->ibuf,&router_id);
166 + router_id_zebra = router_id.u.prefix4;
168 -int
169 -bgp_if_update_all ()
171 - listnode node;
172 - struct interface *ifp;
173 + LIST_LOOP (bm->bgp, bgp, nn) {
174 + if (!bgp->router_id_static.s_addr)
175 + bgp_router_id_set (bgp, &router_id.u.prefix4);
178 - for (node = listhead (iflist); node; node = nextnode (node))
180 - ifp = getdata (node);
181 - bgp_if_update (ifp);
183 return 0;
186 @@ -104,7 +67,6 @@
187 struct interface *ifp;
189 ifp = zebra_interface_add_read (zclient->ibuf);
190 - bgp_if_update (ifp);
192 return 0;
194 @@ -206,8 +168,6 @@
195 if (ifc == NULL)
196 return 0;
198 - bgp_if_update (ifc->ifp);
200 if (if_is_up (ifc->ifp))
201 bgp_connected_add (ifc);
203 @@ -225,8 +185,6 @@
204 if (ifc == NULL)
205 return 0;
207 - bgp_if_update (ifc->ifp);
209 if (if_is_up (ifc->ifp))
210 bgp_connected_delete (ifc);
212 @@ -983,6 +941,7 @@
213 /* Set default values. */
214 zclient = zclient_new ();
215 zclient_init (zclient, ZEBRA_ROUTE_BGP);
216 + zclient->router_id_update = bgp_router_id_update;
217 zclient->interface_add = bgp_interface_add;
218 zclient->interface_delete = bgp_interface_delete;
219 zclient->interface_address_add = bgp_interface_address_add;
220 diff --exclude=.p4config -uNr zebra/config.h.in zebra-ldp/config.h.in
221 --- zebra/config.h.in 2003-03-29 18:26:22.000000000 -0600
222 +++ zebra-ldp/config.h.in 2003-03-29 18:33:43.000000000 -0600
223 @@ -291,6 +291,9 @@
224 /* bgpd PID */
225 #undef PATH_BGPD_PID
227 +/* mplsd PID */
228 +#undef PATH_MPLSD_PID
230 /* ospf6d PID */
231 #undef PATH_OSPF6D_PID
233 diff --exclude=.p4config -uNr zebra/configure.ac zebra-ldp/configure.ac
234 --- zebra/configure.ac 2003-03-29 18:14:56.000000000 -0600
235 +++ zebra-ldp/configure.ac 2003-03-16 16:45:05.000000000 -0600
236 @@ -71,6 +71,8 @@
237 [ --disable-ospfd do not build ospfd])
238 AC_ARG_ENABLE(ospf6d,
239 [ --disable-ospf6d do not build ospf6d])
240 +AC_ARG_ENABLE(mplsd,
241 +[ --disable-mplsd do not build mplsd])
242 AC_ARG_ENABLE(bgp-announce,
243 [ --disable-bgp-announce, turn off BGP route announcement])
244 AC_ARG_ENABLE(netlink,
245 @@ -534,6 +536,12 @@
246 OSPFD="ospfd"
249 +if test "${enable_mpsld}" = "no";then
250 + MPLSD=""
251 +else
252 + MPLSD="mplsd"
255 case "${enable_ripngd}" in
256 "yes") RIPNGD="ripngd";;
257 "no" ) RIPNGD="";;
258 @@ -556,6 +564,7 @@
259 AC_SUBST(RIPNGD)
260 AC_SUBST(OSPFD)
261 AC_SUBST(OSPF6D)
262 +AC_SUBST(MPLSD)
263 AC_SUBST(VTYSH)
264 AC_SUBST(INCLUDES)
265 AC_SUBST(CURSES)
266 @@ -777,6 +786,7 @@
267 AC_DEFINE_UNQUOTED(PATH_BGPD_PID, "$ac_piddir/bgpd.pid",bgpd PID)
268 AC_DEFINE_UNQUOTED(PATH_OSPFD_PID, "$ac_piddir/ospfd.pid",ospfd PID)
269 AC_DEFINE_UNQUOTED(PATH_OSPF6D_PID, "$ac_piddir/ospf6d.pid",ospf6d PID)
270 +AC_DEFINE_UNQUOTED(PATH_MPLSD_PID, "$ac_piddir/mplsd.pid",mplsd PID)
273 dnl ---------------------------
274 @@ -798,7 +808,7 @@
275 ac_cv_htonl_works=no)])
276 AC_MSG_RESULT($ac_cv_htonl_works)
278 -AC_OUTPUT(Makefile lib/Makefile zebra/Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile ospfd/Makefile ospf6d/Makefile vtysh/Makefile doc/Makefile)
279 +AC_OUTPUT(Makefile lib/Makefile zebra/Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile ospfd/Makefile ospf6d/Makefile mplsd/Makefile vtysh/Makefile doc/Makefile)
281 echo "
282 zebra configuration
283 diff --exclude=.p4config -uNr zebra/lib/command.c zebra-ldp/lib/command.c
284 --- zebra/lib/command.c 2003-03-29 18:15:18.000000000 -0600
285 +++ zebra-ldp/lib/command.c 2003-03-29 01:12:01.000000000 -0600
286 @@ -2080,12 +2080,24 @@
287 case RIPNG_NODE:
288 case OSPF_NODE:
289 case OSPF6_NODE:
290 + case MPLS_STATIC_NODE:
291 + case MPLS_RSVPTE_NODE:
292 + case MPLS_LDP_NODE:
293 + case MPLS_IF_NODE:
294 case KEYCHAIN_NODE:
295 case MASC_NODE:
296 case RMAP_NODE:
297 case VTY_NODE:
298 vty->node = CONFIG_NODE;
299 break;
300 + case MPLS_IN_INSTR_NODE:
301 + case MPLS_OUT_INSTR_NODE:
302 + vty->node = MPLS_STATIC_NODE;
303 + break;
304 + case MPLS_RSVPTE_IF_NODE:
305 + case MPLS_LDP_IF_NODE:
306 + vty->node = INTERFACE_NODE;
307 + break;
308 case BGP_VPNV4_NODE:
309 case BGP_IPV4_NODE:
310 case BGP_IPV4M_NODE:
311 @@ -2132,6 +2144,14 @@
312 case RMAP_NODE:
313 case OSPF_NODE:
314 case OSPF6_NODE:
315 + case MPLS_IF_NODE:
316 + case MPLS_RSVPTE_NODE:
317 + case MPLS_LDP_NODE:
318 + case MPLS_RSVPTE_IF_NODE:
319 + case MPLS_LDP_IF_NODE:
320 + case MPLS_STATIC_NODE:
321 + case MPLS_IN_INSTR_NODE:
322 + case MPLS_OUT_INSTR_NODE:
323 case KEYCHAIN_NODE:
324 case KEYCHAIN_KEY_NODE:
325 case MASC_NODE:
326 diff --exclude=.p4config -uNr zebra/lib/command.h zebra-ldp/lib/command.h
327 --- zebra/lib/command.h 2003-03-29 18:15:18.000000000 -0600
328 +++ zebra-ldp/lib/command.h 2003-03-29 01:12:01.000000000 -0600
329 @@ -75,6 +75,14 @@
330 AAA_NODE, /* AAA node. */
331 KEYCHAIN_NODE, /* Key-chain node. */
332 KEYCHAIN_KEY_NODE, /* Key-chain key node. */
333 + MPLS_IF_NODE, /* MPLS tunnel interface node */
334 + MPLS_LDP_NODE, /* MPLS LDP protocol node */
335 + MPLS_LDP_IF_NODE, /* MPLS LDP interface node */
336 + MPLS_RSVPTE_IF_NODE, /* MPLS RSVP-TE interface node */
337 + MPLS_STATIC_NODE, /* static MPLS protocol mode */
338 + MPLS_RSVPTE_NODE, /* RSVP-TE MPLS protocol mode */
339 + MPLS_IN_INSTR_NODE, /* MPLS in-seg instructions */
340 + MPLS_OUT_INSTR_NODE, /* MPLS out-seg instructions */
341 INTERFACE_NODE, /* Interface mode node. */
342 ZEBRA_NODE, /* zebra connection node. */
343 TABLE_NODE, /* rtm_table selection node. */
344 diff --exclude=.p4config -uNr zebra/lib/if.c zebra-ldp/lib/if.c
345 --- zebra/lib/if.c 2003-03-29 18:15:20.000000000 -0600
346 +++ zebra-ldp/lib/if.c 2003-03-10 14:56:58.000000000 -0600
347 @@ -594,6 +594,30 @@
349 #endif
351 +struct interface *if_getfirst()
353 + listnode node = listhead(iflist);
354 + return getdata(node);
357 +struct interface *if_getnext(struct interface *old)
359 + struct interface *ifp;
360 + listnode node;
361 + int flag = 0;
363 + for (node = listhead(iflist); node; nextnode(node)) {
364 + ifp = getdata(node);
365 + if (flag) {
366 + return ifp;
368 + if (ifp->ifindex == old->ifindex) {
369 + flag = 1;
372 + return NULL;
375 #ifndef HAVE_IF_INDEXTONAME
376 char *
377 if_indextoname (unsigned int ifindex, char *name)
378 diff --exclude=.p4config -uNr zebra/lib/if.h zebra-ldp/lib/if.h
379 --- zebra/lib/if.h 2003-03-29 18:15:20.000000000 -0600
380 +++ zebra-ldp/lib/if.h 2003-03-10 14:56:58.000000000 -0600
381 @@ -204,6 +204,9 @@
382 struct connected *connected_delete_by_prefix (struct interface *, struct prefix *);
383 int ifc_pointopoint (struct connected *);
385 +struct interface *if_getfirst();
386 +struct interface *if_getnext(struct interface*);
388 #ifndef HAVE_IF_NAMETOINDEX
389 unsigned int if_nametoindex (const char *);
390 #endif
391 diff --exclude=.p4config -uNr zebra/lib/linklist.h zebra-ldp/lib/linklist.h
392 --- zebra/lib/linklist.h 2003-03-29 18:15:21.000000000 -0600
393 +++ zebra-ldp/lib/linklist.h 2003-03-10 14:57:00.000000000 -0600
394 @@ -43,6 +43,7 @@
396 #define nextnode(X) ((X) = (X)->next)
397 #define listhead(X) ((X)->head)
398 +#define listtail(X) ((X)->tail)
399 #define listcount(X) ((X)->count)
400 #define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL)
401 #define getdata(X) ((X)->data)
402 diff --exclude=.p4config -uNr zebra/lib/log.c zebra-ldp/lib/log.c
403 --- zebra/lib/log.c 2003-03-29 18:15:21.000000000 -0600
404 +++ zebra-ldp/lib/log.c 2003-03-10 14:57:00.000000000 -0600
405 @@ -37,6 +37,7 @@
406 "OSPF",
407 "RIPNG",
408 "OSPF6",
409 + "MPLS",
410 "MASC",
411 NULL,
413 diff --exclude=.p4config -uNr zebra/lib/log.h zebra-ldp/lib/log.h
414 --- zebra/lib/log.h 2003-03-29 18:15:21.000000000 -0600
415 +++ zebra-ldp/lib/log.h 2003-03-10 14:57:00.000000000 -0600
416 @@ -47,6 +47,7 @@
417 ZLOG_OSPF,
418 ZLOG_RIPNG,
419 ZLOG_OSPF6,
420 + ZLOG_MPLS,
421 ZLOG_MASC
422 } zlog_proto_t;
424 diff --exclude=.p4config -uNr zebra/lib/memory.c zebra-ldp/lib/memory.c
425 --- zebra/lib/memory.c 2003-03-29 18:15:22.000000000 -0600
426 +++ zebra-ldp/lib/memory.c 2003-03-29 01:12:01.000000000 -0600
427 @@ -373,6 +373,17 @@
428 { -1, NULL },
431 +struct memory_list memory_list_mpls[] =
433 + { MTYPE_MPLS_TOP, "MPLS " },
434 + { MTYPE_MPLS_IF, "MPLS IF " },
435 + { MTYPE_MPLS_STATIC, "MPLS static " },
436 + { MTYPE_MPLS_RSVPTE, "MPLS rsvpte " },
437 + { MTYPE_MPLS_LDP, "LDP " },
438 + { MTYPE_MPLS_RIB, "RIB " },
439 + { -1, NULL },
442 struct memory_list memory_list_separator[] =
444 { 0, NULL},
445 @@ -407,6 +418,7 @@
446 show_memory_vty (vty, memory_list_ospf6);
447 show_memory_vty (vty, memory_list_separator);
448 show_memory_vty (vty, memory_list_bgp);
449 + show_memory_vty (vty, memory_list_mpls);
451 return CMD_SUCCESS;
453 @@ -450,6 +462,17 @@
454 return CMD_SUCCESS;
457 +DEFUN (show_memory_mpls,
458 + show_memory_mpls_cmd,
459 + "show memory mpls",
460 + SHOW_STR
461 + "Memory statistics\n"
462 + "MPLS memory\n")
464 + show_memory_vty (vty, memory_list_mpls);
465 + return CMD_SUCCESS;
468 DEFUN (show_memory_ospf,
469 show_memory_ospf_cmd,
470 "show memory ospf",
471 @@ -480,6 +503,7 @@
472 install_element (VIEW_NODE, &show_memory_lib_cmd);
473 install_element (VIEW_NODE, &show_memory_rip_cmd);
474 install_element (VIEW_NODE, &show_memory_bgp_cmd);
475 + install_element (VIEW_NODE, &show_memory_mpls_cmd);
476 install_element (VIEW_NODE, &show_memory_ospf_cmd);
477 install_element (VIEW_NODE, &show_memory_ospf6_cmd);
479 @@ -488,6 +512,7 @@
480 install_element (ENABLE_NODE, &show_memory_lib_cmd);
481 install_element (ENABLE_NODE, &show_memory_rip_cmd);
482 install_element (ENABLE_NODE, &show_memory_bgp_cmd);
483 + install_element (ENABLE_NODE, &show_memory_mpls_cmd);
484 install_element (ENABLE_NODE, &show_memory_ospf_cmd);
485 install_element (ENABLE_NODE, &show_memory_ospf6_cmd);
487 diff --exclude=.p4config -uNr zebra/lib/memory.h zebra-ldp/lib/memory.h
488 --- zebra/lib/memory.h 2003-03-29 18:15:22.000000000 -0600
489 +++ zebra-ldp/lib/memory.h 2003-03-29 01:12:01.000000000 -0600
490 @@ -170,6 +170,13 @@
491 MTYPE_COMMUNITY_LIST_ENTRY,
492 MTYPE_COMMUNITY_LIST_CONFIG,
494 + MTYPE_MPLS_TOP,
495 + MTYPE_MPLS_IF,
496 + MTYPE_MPLS_STATIC,
497 + MTYPE_MPLS_LDP,
498 + MTYPE_MPLS_RSVPTE,
499 + MTYPE_MPLS_RIB,
501 MTYPE_RIP,
502 MTYPE_RIP_INTERFACE,
503 MTYPE_RIP_DISTANCE,
504 diff --exclude=.p4config -uNr zebra/lib/table.c zebra-ldp/lib/table.c
505 --- zebra/lib/table.c 2003-03-29 18:15:28.000000000 -0600
506 +++ zebra-ldp/lib/table.c 2003-03-10 14:57:17.000000000 -0600
507 @@ -311,6 +311,36 @@
508 return NULL;
511 +struct route_node *
512 +route_node_lookup2 (struct route_table *table, struct prefix *p)
514 + struct route_node *rn_in, *rn_tmp;
516 + if (!(rn_in = route_node_lookup(table,p))) {
517 + /* walk as far down the tree as we can */
518 + rn_in = table->top;
519 + while (rn_in && rn_in->p.prefixlen <= p->prefixlen &&
520 + prefix_match(&rn_in->p, p)) {
521 + rn_tmp = rn_in->link[check_bit(&p->u.prefix, rn_in->p.prefixlen)];
522 + if (!rn_tmp) {
523 + break;
525 + rn_in = rn_tmp;
527 + route_lock_node(rn_in);
529 + /* rn_in is either the actual node or the furthest node in the tree */
530 + /* so get the 'next' one with 'info' */
531 + rn_in = route_next2(rn_in);
534 + if (rn_in && !rn_in->info) {
535 + route_unlock_node(rn_in);
536 + rn_in = NULL;
538 + return rn_in;
541 /* Add node to routing table. */
542 struct route_node *
543 route_node_get (struct route_table *table, struct prefix *p)
544 @@ -461,6 +491,22 @@
545 return NULL;
548 +struct route_node *
549 +route_next2 (struct route_node *rn_in)
551 + struct route_node *rn = rn_in;
552 + struct route_node *rn2;
553 + do {
554 + rn2 = route_next(rn);
555 + rn = rn2;
556 + } while(rn && !rn->info);
558 + if (rn && rn->info) {
559 + return rn;
561 + return NULL;
564 /* Unlock current node and lock next node until limit. */
565 struct route_node *
566 route_next_until (struct route_node *node, struct route_node *limit)
567 diff --exclude=.p4config -uNr zebra/lib/table.h zebra-ldp/lib/table.h
568 --- zebra/lib/table.h 2003-03-29 18:15:28.000000000 -0600
569 +++ zebra-ldp/lib/table.h 2003-03-10 14:57:17.000000000 -0600
570 @@ -23,6 +23,8 @@
571 #ifndef _ZEBRA_TABLE_H
572 #define _ZEBRA_TABLE_H
574 +#include "prefix.h"
576 /* Routing table top structure. */
577 struct route_table
579 @@ -59,9 +61,11 @@
580 void route_node_delete (struct route_node *node);
581 struct route_node *route_top (struct route_table *);
582 struct route_node *route_next (struct route_node *);
583 +struct route_node *route_next2 (struct route_node *);
584 struct route_node *route_next_until (struct route_node *, struct route_node *);
585 struct route_node *route_node_get (struct route_table *, struct prefix *);
586 struct route_node *route_node_lookup (struct route_table *, struct prefix *);
587 +struct route_node *route_node_lookup2 (struct route_table *, struct prefix *);
588 struct route_node *route_lock_node (struct route_node *node);
589 struct route_node *route_node_match (struct route_table *, struct prefix *);
590 struct route_node *route_node_match_ipv4 (struct route_table *,
591 diff --exclude=.p4config -uNr zebra/lib/thread.c zebra-ldp/lib/thread.c
592 --- zebra/lib/thread.c 2003-03-29 18:15:29.000000000 -0600
593 +++ zebra-ldp/lib/thread.c 2003-03-10 14:57:18.000000000 -0600
594 @@ -117,10 +117,26 @@
595 sizeof (struct thread_master));
598 +static int thread_in_list(struct thread_list *list, struct thread *thread)
600 + struct thread *tt;
602 + for (tt = list->head; tt; tt = tt->next)
604 + if (tt == thread)
606 + return 1;
609 + return 0;
612 /* Add a new thread to the list. */
613 static void
614 thread_list_add (struct thread_list *list, struct thread *thread)
616 + assert(!thread_in_list(list,thread));
618 thread->next = NULL;
619 thread->prev = list->tail;
620 if (list->tail)
621 @@ -137,6 +153,8 @@
622 struct thread *point,
623 struct thread *thread)
625 + assert(!thread_in_list(list,thread));
627 thread->next = point;
628 thread->prev = point->prev;
629 if (point->prev)
630 @@ -151,6 +169,8 @@
631 static struct thread *
632 thread_list_delete (struct thread_list *list, struct thread *thread)
634 + assert(thread_in_list(list,thread));
636 if (thread->next)
637 thread->next->prev = thread->prev;
638 else
639 diff --exclude=.p4config -uNr zebra/lib/vty.c zebra-ldp/lib/vty.c
640 --- zebra/lib/vty.c 2003-03-29 18:15:30.000000000 -0600
641 +++ zebra-ldp/lib/vty.c 2003-03-29 01:12:02.000000000 -0600
642 @@ -624,6 +624,12 @@
643 case RMAP_NODE:
644 case OSPF_NODE:
645 case OSPF6_NODE:
646 + case MPLS_IF_NODE:
647 + case MPLS_IN_INSTR_NODE:
648 + case MPLS_OUT_INSTR_NODE:
649 + case MPLS_STATIC_NODE:
650 + case MPLS_RSVPTE_NODE:
651 + case MPLS_LDP_NODE:
652 case KEYCHAIN_NODE:
653 case KEYCHAIN_KEY_NODE:
654 case MASC_NODE:
655 @@ -1028,6 +1034,11 @@
656 case RMAP_NODE:
657 case OSPF_NODE:
658 case OSPF6_NODE:
659 + case MPLS_IF_NODE:
660 + case MPLS_IN_INSTR_NODE:
661 + case MPLS_OUT_INSTR_NODE:
662 + case MPLS_STATIC_NODE:
663 + case MPLS_LDP_NODE:
664 case KEYCHAIN_NODE:
665 case KEYCHAIN_KEY_NODE:
666 case MASC_NODE:
667 diff --exclude=.p4config -uNr zebra/lib/zclient.c zebra-ldp/lib/zclient.c
668 --- zebra/lib/zclient.c 2003-03-29 18:15:30.000000000 -0600
669 +++ zebra-ldp/lib/zclient.c 2003-03-10 14:57:21.000000000 -0600
670 @@ -260,6 +260,9 @@
671 /* We need interface information. */
672 zebra_message_send (zclient, ZEBRA_INTERFACE_ADD);
674 + /* We need router-id information. */
675 + zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD);
677 /* Flush all redistribute request. */
678 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
679 if (i != zclient->redist_default && zclient->redist[i])
680 @@ -289,6 +292,38 @@
684 +zapi_ipv4_set_mplsindex (struct zclient *zclient, struct prefix_ipv4 *p,
685 + struct in_addr *nexthop, unsigned int ifindex,
686 + unsigned int mplsindex)
688 + int psize;
689 + struct stream *s;
691 + /* Reset stream. */
692 + s = zclient->obuf;
693 + stream_reset (s);
695 + /* Length place holder. */
696 + stream_putw (s, 0);
698 + /* Put command, type and nexthop. */
699 + stream_putc (s, ZEBRA_IPV4_SET_MPLSINDEX);
701 + /* Put prefix information. */
702 + psize = PSIZE (p->prefixlen);
703 + stream_putc (s, p->prefixlen);
704 + stream_write (s, (u_char *)&p->prefix, psize);
705 + stream_put_in_addr (s, nexthop);
706 + stream_putl (s, ifindex);
707 + stream_putl (s, mplsindex);
709 + /* Put length at the first point of the stream. */
710 + stream_putw_at (s, 0, stream_get_endp (s));
712 + return writen (zclient->sock, s->data, stream_get_endp (s));
715 +int
716 zapi_ipv4_add (struct zclient *zclient, struct prefix_ipv4 *p,
717 struct zapi_ipv4 *api)
719 @@ -540,6 +575,20 @@
720 return ret;
723 +/* Router-id update from zebra daemon. */
724 +void
725 +zebra_router_id_update_read (struct stream *s, struct prefix *rid)
727 + int plen;
729 + /* Fetch interface address. */
730 + rid->family = stream_getc (s);
732 + plen = prefix_blen (rid);
733 + stream_get (&rid->u.prefix, s, plen);
734 + rid->prefixlen = stream_getc (s);
737 /* Interface addition from zebra daemon. */
738 struct interface *
739 zebra_interface_add_read (struct stream *s)
740 @@ -608,6 +657,19 @@
741 return ifp;
744 +void
745 +zebra_interface_if_set_value (struct stream *s, struct interface *ifp)
747 + /* Read interface's index. */
748 + ifp->ifindex = stream_getl (s);
750 + /* Read interface's value. */
751 + ifp->flags = stream_getl (s);
752 + ifp->metric = stream_getl (s);
753 + ifp->mtu = stream_getl (s);
754 + ifp->bandwidth = stream_getl (s);
757 struct connected *
758 zebra_interface_address_add_read (struct stream *s)
760 @@ -772,6 +834,10 @@
762 switch (command)
764 + case ZEBRA_ROUTER_ID_UPDATE:
765 + if (zclient->router_id_update)
766 + ret = (*zclient->router_id_update) (command, zclient, length);
767 + break;
768 case ZEBRA_INTERFACE_ADD:
769 if (zclient->interface_add)
770 ret = (*zclient->interface_add) (command, zclient, length);
771 diff --exclude=.p4config -uNr zebra/lib/zclient.h zebra-ldp/lib/zclient.h
772 --- zebra/lib/zclient.h 2003-03-29 18:15:30.000000000 -0600
773 +++ zebra-ldp/lib/zclient.h 2003-03-10 14:57:21.000000000 -0600
774 @@ -24,6 +24,7 @@
776 /* For struct interface and struct connected. */
777 #include "if.h"
778 +#include "prefix.h"
780 /* For input/output buffer to zebra. */
781 #define ZEBRA_MAX_PACKET_SIZ 4096
782 @@ -62,6 +63,7 @@
783 u_char default_information;
785 /* Pointer to the callback functions. */
786 + int (*router_id_update) (int, struct zclient *, zebra_size_t);
787 int (*interface_add) (int, struct zclient *, zebra_size_t);
788 int (*interface_delete) (int, struct zclient *, zebra_size_t);
789 int (*interface_up) (int, struct zclient *, zebra_size_t);
790 @@ -100,6 +102,9 @@
791 u_int32_t metric;
794 +int zapi_ipv4_set_mplsindex (struct zclient *, struct prefix_ipv4 *,
795 + struct in_addr*, unsigned int, unsigned int);
798 zapi_ipv4_add (struct zclient *, struct prefix_ipv4 *, struct zapi_ipv4 *);
800 @@ -127,8 +132,11 @@
802 struct interface *zebra_interface_add_read (struct stream *);
803 struct interface *zebra_interface_state_read (struct stream *s);
804 +void zebra_interface_if_set_value (struct stream *, struct interface *);
805 struct connected *zebra_interface_address_add_read (struct stream *);
806 struct connected *zebra_interface_address_delete_read (struct stream *);
807 +void zebra_router_id_update_read (struct stream *s, struct prefix *rid);
810 #ifdef HAVE_IPV6
811 /* IPv6 prefix add and delete function prototype. */
812 diff --exclude=.p4config -uNr zebra/lib/zebra.h zebra-ldp/lib/zebra.h
813 --- zebra/lib/zebra.h 2003-03-29 18:15:30.000000000 -0600
814 +++ zebra-ldp/lib/zebra.h 2003-03-14 10:28:01.000000000 -0600
815 @@ -226,7 +226,11 @@
816 #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
817 #define ZEBRA_IPV4_IMPORT_LOOKUP 17
818 #define ZEBRA_IPV6_IMPORT_LOOKUP 18
819 -#define ZEBRA_MESSAGE_MAX 19
820 +#define ZEBRA_ROUTER_ID_ADD 19
821 +#define ZEBRA_ROUTER_ID_DELETE 20
822 +#define ZEBRA_ROUTER_ID_UPDATE 21
823 +#define ZEBRA_IPV4_SET_MPLSINDEX 22
824 +#define ZEBRA_MESSAGE_MAX 23
826 /* Zebra route's types. */
827 #define ZEBRA_ROUTE_SYSTEM 0
828 @@ -238,7 +242,8 @@
829 #define ZEBRA_ROUTE_OSPF 6
830 #define ZEBRA_ROUTE_OSPF6 7
831 #define ZEBRA_ROUTE_BGP 8
832 -#define ZEBRA_ROUTE_MAX 9
833 +#define ZEBRA_ROUTE_MPLS 9
834 +#define ZEBRA_ROUTE_MAX 10
836 /* Zebra's family types. */
837 #define ZEBRA_FAMILY_IPV4 1
838 @@ -259,6 +264,7 @@
839 #define ZEBRA_FLAG_SELECTED 0x10
840 #define ZEBRA_FLAG_CHANGED 0x20
841 #define ZEBRA_FLAG_STATIC 0x40
842 +#define ZEBRA_FLAG_MPLS_CHANGED 0x80
844 /* Zebra nexthop flags. */
845 #define ZEBRA_NEXTHOP_IFINDEX 1
846 diff --exclude=.p4config -uNr zebra/Makefile.am zebra-ldp/Makefile.am
847 --- zebra/Makefile.am 2003-03-29 18:14:28.000000000 -0600
848 +++ zebra-ldp/Makefile.am 2003-03-10 14:55:26.000000000 -0600
849 @@ -1,6 +1,6 @@
850 ## Process this file with automake to produce Makefile.in.
852 -SUBDIRS = lib @ZEBRA@ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @VTYSH@ doc
853 +SUBDIRS = lib @ZEBRA@ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @MPLSD@ @VTYSH@ doc
855 EXTRA_DIST = aclocal.m4 SERVICES TODO REPORTING-BUGS vtysh/Makefile.in \
856 vtysh/Makefile.am update-autotools
857 diff --exclude=.p4config -uNr zebra/mplsd/create-links zebra-ldp/mplsd/create-links
858 --- zebra/mplsd/create-links 1969-12-31 18:00:00.000000000 -0600
859 +++ zebra-ldp/mplsd/create-links 2003-03-30 23:45:13.000000000 -0600
860 @@ -0,0 +1,117 @@
861 +#!/bin/sh
863 +DEFSRC=/home/jleu/personal/clients/ldp-portable
864 +if [ "x${1}" = "x" ]; then
865 + SRC=${DEFSRC}
866 +else
867 + SRC=${1}
870 +[ -d "${SRC}" ] || {
871 + echo $"$0: directory not found: ${1}" >&2
872 + echo $"Usage: $0 [<direcory>] (default is ${DEFSRC})" >&2
873 + exit 1
876 +ln -s $SRC/ldp/ldp_addr.c
877 +ln -s $SRC/ldp/ldp_addr.h
878 +ln -s $SRC/ldp/ldp_adj.c
879 +ln -s $SRC/ldp/ldp_adj.h
880 +ln -s $SRC/ldp/ldp_attr.c
881 +ln -s $SRC/ldp/ldp_attr.h
882 +ln -s $SRC/ldp/ldp_buf.c
883 +ln -s $SRC/ldp/ldp_buf.h
884 +ln -s $SRC/ldp/ldp_cfg.c
885 +ln -s $SRC/ldp/ldp_cfg.h
886 +ln -s $SRC/ldp/ldp_defaults.h
887 +ln -s $SRC/ldp/ldp_entity.c
888 +ln -s $SRC/ldp/ldp_entity.h
889 +ln -s $SRC/ldp/ldp_fec.c
890 +ln -s $SRC/ldp/ldp_fec.h
891 +ln -s $SRC/ldp/ldp_global.c
892 +ln -s $SRC/ldp/ldp_global.h
893 +ln -s $SRC/ldp/ldp_hello.c
894 +ln -s $SRC/ldp/ldp_hello.h
895 +ln -s $SRC/ldp/ldp_hop.c
896 +ln -s $SRC/ldp/ldp_hop.h
897 +ln -s $SRC/ldp/ldp_hop_list.c
898 +ln -s $SRC/ldp/ldp_hop_list.h
899 +ln -s $SRC/ldp/ldp_if.c
900 +ln -s $SRC/ldp/ldp_if.h
901 +ln -s $SRC/ldp/ldp_inet_addr.c
902 +ln -s $SRC/ldp/ldp_inet_addr.h
903 +ln -s $SRC/ldp/ldp_init.c
904 +ln -s $SRC/ldp/ldp_init.h
905 +ln -s $SRC/ldp/ldp_inlabel.c
906 +ln -s $SRC/ldp/ldp_inlabel.h
907 +ln -s $SRC/ldp/ldp_keepalive.c
908 +ln -s $SRC/ldp/ldp_keepalive.h
909 +ln -s $SRC/ldp/ldp_l2cc.c
910 +ln -s $SRC/ldp/ldp_l2cc.h
911 +ln -s $SRC/ldp/ldp_label_abort.c
912 +ln -s $SRC/ldp/ldp_label_abort.h
913 +ln -s $SRC/ldp/ldp_label_mapping.c
914 +ln -s $SRC/ldp/ldp_label_mapping.h
915 +ln -s $SRC/ldp/ldp_label_rel_with.c
916 +ln -s $SRC/ldp/ldp_label_rel_with.h
917 +ln -s $SRC/ldp/ldp_label_request.c
918 +ln -s $SRC/ldp/ldp_label_request.h
919 +ln -s $SRC/ldp/ldp_mesg.c
920 +ln -s $SRC/ldp/ldp_mesg.h
921 +ln -s $SRC/ldp/ldp_nortel.c
922 +ln -s $SRC/ldp/ldp_nortel.h
923 +ln -s $SRC/ldp/ldp_notif.c
924 +ln -s $SRC/ldp/ldp_notif.h
925 +ln -s $SRC/ldp/ldp_outlabel.c
926 +ln -s $SRC/ldp/ldp_outlabel.h
927 +ln -s $SRC/ldp/ldp_pdu.h
928 +ln -s $SRC/ldp/ldp_pdu_setup.c
929 +ln -s $SRC/ldp/ldp_pdu_setup.h
930 +ln -s $SRC/ldp/ldp_peer.c
931 +ln -s $SRC/ldp/ldp_peer.h
932 +ln -s $SRC/ldp/ldp_resource.c
933 +ln -s $SRC/ldp/ldp_resource.h
934 +ln -s $SRC/ldp/ldp_session.c
935 +ln -s $SRC/ldp/ldp_session.h
936 +ln -s $SRC/ldp/ldp_state_funcs.c
937 +ln -s $SRC/ldp/ldp_state_machine.c
938 +ln -s $SRC/ldp/ldp_state_machine.h
939 +ln -s $SRC/ldp/ldp_struct.h
940 +ln -s $SRC/ldp/ldp_tunnel.c
941 +ln -s $SRC/ldp/ldp_tunnel.h
943 +ln -s $SRC/lsr/lsr_cfg.c
944 +ln -s $SRC/lsr/lsr_cfg.h
945 +ln -s $SRC/lsr/lsr_defaults.h
946 +ln -s $SRC/lsr/lsr_global.c
947 +ln -s $SRC/lsr/lsr_global.h
948 +ln -s $SRC/lsr/lsr_if.c
949 +ln -s $SRC/lsr/lsr_if.h
950 +ln -s $SRC/lsr/lsr_insegment.c
951 +ln -s $SRC/lsr/lsr_insegment.h
952 +ln -s $SRC/lsr/lsr_labelmanager.c
953 +ln -s $SRC/lsr/lsr_labelmanager.h
954 +ln -s $SRC/lsr/lsr_outsegment.c
955 +ln -s $SRC/lsr/lsr_outsegment.h
956 +ln -s $SRC/lsr/lsr_struct.h
957 +ln -s $SRC/lsr/lsr_xconnect.c
958 +ln -s $SRC/lsr/lsr_xconnect.h
959 +ln -s $SRC/lsr/lsr_ftn.c
960 +ln -s $SRC/lsr/lsr_ftn.h
962 +ln -s $SRC/common/mpls_struct.h
963 +ln -s $SRC/common/mpls_assert.h
964 +ln -s $SRC/common/mpls_fib_impl.h
965 +ln -s $SRC/common/mpls_ifmgr_impl.h
966 +ln -s $SRC/common/mpls_mm_impl.h
967 +ln -s $SRC/common/mpls_mpls_impl.h
968 +ln -s $SRC/common/mpls_policy_impl.h
969 +ln -s $SRC/common/mpls_refcnt.h
970 +ln -s $SRC/common/mpls_socket_impl.h
971 +ln -s $SRC/common/mpls_timer_impl.h
972 +ln -s $SRC/common/mpls_trace_impl.h
973 +ln -s $SRC/common/mpls_tree_impl.h
974 +ln -s $SRC/common/mpls_list.h
975 +ln -s $SRC/common/mpls_lock_impl.h
976 +ln -s $SRC/common/mpls_compare.h
977 +ln -s $SRC/common/mpls_compare.c
978 diff --exclude=.p4config -uNr zebra/mplsd/delete-links zebra-ldp/mplsd/delete-links
979 --- zebra/mplsd/delete-links 1969-12-31 18:00:00.000000000 -0600
980 +++ zebra-ldp/mplsd/delete-links 2003-03-29 01:16:17.000000000 -0600
981 @@ -0,0 +1,104 @@
982 +#!/bin/sh
984 +rm -f ldp_addr.c
985 +rm -f ldp_addr.h
986 +rm -f ldp_adj.c
987 +rm -f ldp_adj.h
988 +rm -f ldp_attr.c
989 +rm -f ldp_attr.h
990 +rm -f ldp_buf.c
991 +rm -f ldp_buf.h
992 +rm -f ldp_cfg.c
993 +rm -f ldp_cfg.h
994 +rm -f ldp_defaults.h
995 +rm -f ldp_entity.c
996 +rm -f ldp_entity.h
997 +rm -f ldp_fec.c
998 +rm -f ldp_fec.h
999 +rm -f ldp_global.c
1000 +rm -f ldp_global.h
1001 +rm -f ldp_hello.c
1002 +rm -f ldp_hello.h
1003 +rm -f ldp_hop.c
1004 +rm -f ldp_hop.h
1005 +rm -f ldp_hop_list.c
1006 +rm -f ldp_hop_list.h
1007 +rm -f ldp_if.c
1008 +rm -f ldp_if.h
1009 +rm -f ldp_inet_addr.c
1010 +rm -f ldp_inet_addr.h
1011 +rm -f ldp_init.c
1012 +rm -f ldp_init.h
1013 +rm -f ldp_inlabel.c
1014 +rm -f ldp_inlabel.h
1015 +rm -f ldp_keepalive.c
1016 +rm -f ldp_keepalive.h
1017 +rm -f ldp_l2cc.c
1018 +rm -f ldp_l2cc.h
1019 +rm -f ldp_label_abort.c
1020 +rm -f ldp_label_abort.h
1021 +rm -f ldp_label_mapping.c
1022 +rm -f ldp_label_mapping.h
1023 +rm -f ldp_label_rel_with.c
1024 +rm -f ldp_label_rel_with.h
1025 +rm -f ldp_label_request.c
1026 +rm -f ldp_label_request.h
1027 +rm -f ldp_mesg.c
1028 +rm -f ldp_mesg.h
1029 +rm -f ldp_nortel.c
1030 +rm -f ldp_nortel.h
1031 +rm -f ldp_notif.c
1032 +rm -f ldp_notif.h
1033 +rm -f ldp_outlabel.c
1034 +rm -f ldp_outlabel.h
1035 +rm -f ldp_pdu.h
1036 +rm -f ldp_pdu_setup.c
1037 +rm -f ldp_pdu_setup.h
1038 +rm -f ldp_peer.c
1039 +rm -f ldp_peer.h
1040 +rm -f ldp_resource.c
1041 +rm -f ldp_resource.h
1042 +rm -f ldp_session.c
1043 +rm -f ldp_session.h
1044 +rm -f ldp_state_funcs.c
1045 +rm -f ldp_state_machine.c
1046 +rm -f ldp_state_machine.h
1047 +rm -f ldp_struct.h
1048 +rm -f ldp_tunnel.c
1049 +rm -f ldp_tunnel.h
1051 +rm -f lsr_cfg.c
1052 +rm -f lsr_cfg.h
1053 +rm -f lsr_defaults.h
1054 +rm -f lsr_global.c
1055 +rm -f lsr_global.h
1056 +rm -f lsr_if.c
1057 +rm -f lsr_if.h
1058 +rm -f lsr_insegment.c
1059 +rm -f lsr_insegment.h
1060 +rm -f lsr_labelmanager.c
1061 +rm -f lsr_labelmanager.h
1062 +rm -f lsr_outsegment.c
1063 +rm -f lsr_outsegment.h
1064 +rm -f lsr_struct.h
1065 +rm -f lsr_xconnect.c
1066 +rm -f lsr_xconnect.h
1067 +rm -f lsr_ftn.c
1068 +rm -f lsr_ftn.h
1070 +rm -f mpls_struct.h
1071 +rm -f mpls_assert.h
1072 +rm -f mpls_fib_impl.h
1073 +rm -f mpls_ifmgr_impl.h
1074 +rm -f mpls_mm_impl.h
1075 +rm -f mpls_mpls_impl.h
1076 +rm -f mpls_policy_impl.h
1077 +rm -f mpls_refcnt.h
1078 +rm -f mpls_socket_impl.h
1079 +rm -f mpls_timer_impl.h
1080 +rm -f mpls_trace_impl.h
1081 +rm -f mpls_tree_impl.h
1082 +rm -f mpls_list.h
1083 +rm -f mpls_lock_impl.h
1084 +rm -f mpls_compare.h
1085 +rm -f mpls_compare.c
1086 diff --exclude=.p4config -uNr zebra/mplsd/impl_fib.c zebra-ldp/mplsd/impl_fib.c
1087 --- zebra/mplsd/impl_fib.c 1969-12-31 18:00:00.000000000 -0600
1088 +++ zebra-ldp/mplsd/impl_fib.c 2003-03-10 14:57:23.000000000 -0600
1089 @@ -0,0 +1,296 @@
1090 +#include <zebra.h>
1091 +#include "prefix.h"
1092 +#include "table.h"
1093 +#include "if.h"
1094 +#include "memory.h"
1096 +#include "mpls.h"
1097 +#include "mpls_compare.h"
1099 +#include "ldp.h"
1100 +#include "ldp_struct.h"
1102 +void mpls_fib_close(mpls_fib_handle handle)
1106 +void mpls_fib_update_close(mpls_fib_handle handle)
1110 +mpls_fib_handle mpls_fib_open(const mpls_instance_handle handle,
1111 + const mpls_cfg_handle cfg, ldp_fib_callback callback)
1113 + struct mpls *mpls = mpls_get();
1114 + mpls->fib_callback = callback;
1115 + return mpls;
1118 +void mpls_fec2zebra_prefix(mpls_fec *lp, struct prefix *p)
1120 + switch(lp->type) {
1121 + case MPLS_FEC_PREFIX:
1122 + p->prefixlen = lp->u.prefix.length;
1123 + p->u.prefix4.s_addr = htonl(lp->u.prefix.network.u.ipv4);
1124 + break;
1125 + case MPLS_FEC_HOST:
1126 + p->prefixlen = 32;
1127 + p->u.prefix4.s_addr = htonl(lp->u.host.u.ipv4);
1128 + break;
1129 + default:
1130 + break;
1134 +void zebra_prefix2mpls_fec(struct prefix *p, struct mpls_nexthop *nh, mpls_fec *fec)
1136 + fec->u.prefix.length = p->prefixlen;
1137 + fec->type = MPLS_FEC_PREFIX;
1138 + fec->u.prefix.network.type = MPLS_FAMILY_IPV4;
1139 + fec->u.prefix.network.u.ipv4 = ntohl(p->u.prefix4.s_addr);
1140 + memcpy(&fec->nh, nh, sizeof(struct mpls_nexthop));
1143 +int list2fec(struct list *list, struct prefix *p, mpls_fec *entry, int num) {
1144 + struct listnode* ln;
1145 + struct mpls_nexthop* head;
1146 + struct mpls_nexthop* nh;
1147 + int count = 0;
1149 + head = listhead(list) ? getdata(listhead(list)) : NULL;
1151 + LIST_LOOP(list, nh, ln) {
1152 + if (head->distance == nh->distance && head->metric == nh->metric) {
1153 + zebra_prefix2mpls_fec(p,nh,&entry[count]);
1154 + } else {
1155 + break;
1157 + count++;
1158 + if (count >= num) {
1159 + break;
1162 + return count;
1165 +int mpls_fib_get_route(mpls_fib_handle handle, const int num,
1166 + const mpls_fec * fec, mpls_fec * entry)
1168 + struct prefix p;
1169 + struct route_node *rn;
1170 + int count = 0;
1172 + mpls_fec2zebra_prefix((mpls_fec*)fec,&p);
1174 + if ((rn = route_node_lookup(handle->table,&p))) {
1175 + count = list2fec((struct list*)rn->info,&rn->p,entry,num);
1176 + route_unlock_node(rn);
1177 + return count;
1179 + return 0;
1182 +int mpls_fib_get_best_route(mpls_fib_handle handle, const int num,
1183 + const mpls_fec * dest, mpls_fec * entry)
1185 + struct route_node *rn;
1186 + struct prefix p;
1187 + int count = 0;
1188 + int len;
1190 + mpls_fec2zebra_prefix((mpls_fec*)dest,&p);
1192 + for (len = 32; len >= 0 ; len--) {
1193 + p.prefixlen = len;
1194 + if ((rn = route_node_lookup(handle->table,&p))) {
1195 + count = list2fec((struct list*)rn->info,&rn->p,entry,num);
1196 + route_unlock_node(rn);
1199 + return count;
1202 +mpls_return_enum mpls_fib_getfirst_route(mpls_fib_handle handle, mpls_fec * dest)
1204 + struct route_node *rn;
1206 + if ((rn = route_top(handle->table))) {
1207 + if (!rn->info) {
1208 + rn = route_next2(rn);
1211 + if (rn) {
1212 + list2fec((struct list*)rn->info,&rn->p,dest,1);
1213 + route_unlock_node(rn);
1214 + return MPLS_SUCCESS;
1218 + return MPLS_FAILURE;
1221 +mpls_return_enum mpls_fib_getnext_route(mpls_fib_handle handle, mpls_fec * dest)
1223 + struct route_node *rn_in;
1224 + struct listnode* ln;
1225 + struct list* list;
1226 + struct mpls_nexthop* nh;
1227 + struct prefix p;
1228 + int next = 0;
1230 + mpls_fec2zebra_prefix(dest,&p);
1232 + if (!(rn_in = route_node_lookup2(handle->table,&p))) {
1233 + return MPLS_FAILURE;
1236 + list = (struct list*)rn_in->info;
1237 + LIST_LOOP(list, nh, ln) {
1238 + if (next) {
1239 + zebra_prefix2mpls_fec(&p, nh, dest);
1240 + route_unlock_node(rn_in);
1241 + return MPLS_SUCCESS;
1243 + if (!mpls_nexthop_compare(nh,&dest->nh)) {
1244 + next = 1;
1248 + if ((rn_in = route_next2(rn_in))) {
1249 + list2fec((struct list*)rn_in->info,&rn_in->p,dest,1);
1250 + route_unlock_node(rn_in);
1251 + return MPLS_SUCCESS;
1254 + return MPLS_FAILURE;
1257 +static struct mpls_nexthop* mpls_nexthop_create(struct mpls_nexthop* dup) {
1258 + struct mpls_nexthop *nh;
1259 + nh = XMALLOC (MTYPE_MPLS_TOP, sizeof (struct mpls_nexthop));
1260 + if (dup) {
1261 + memcpy(nh, dup, sizeof(struct mpls_nexthop));
1262 + } else {
1263 + memset(nh, 0, sizeof(struct mpls_nexthop));
1265 + return nh;
1268 +static void mpls_nexthop_delete(void* v) {
1269 + XFREE(MTYPE_MPLS_TOP, v);
1272 +static int local_mpls_nexthop_compare(void* a,void* b) {
1273 + return mpls_nexthop_compare((struct mpls_nexthop*)a,(struct mpls_nexthop*)b);
1276 +void ldp_ipv4_add(struct mpls *mpls, struct prefix_ipv4 *p,
1277 + struct mpls_nexthop *nexthop) {
1278 + mpls_fec dest;
1279 + struct route_node *rn;
1280 + struct list *list;
1281 + struct mpls_nexthop *active;
1282 + struct mpls_nexthop *head;
1283 + struct mpls_nexthop *nh = mpls_nexthop_create(nexthop);
1285 + if ((rn = route_node_lookup(mpls->table,(struct prefix*)p))) {
1286 + list = (struct list*)rn->info;
1287 + active = listhead(list) ? getdata(listhead(list)) : NULL;
1288 + } else {
1289 + rn = route_node_get(mpls->table,(struct prefix*)p);
1290 + route_lock_node(rn);
1291 + list = list_new();
1292 + rn->info = list;
1293 + active = NULL;
1294 + list->cmp = local_mpls_nexthop_compare;
1296 + listnode_add_sort(list, nh);
1297 + head = getdata(listhead(list));
1299 + /* if the new route isn't the active route, do nothing */
1300 + if (nh != head) {
1301 + if (rn) {
1302 + route_unlock_node(rn);
1304 + return;
1307 + /* we only get here is the new nh is the active one, which means we need
1308 + * to delete the only nh, THEN send in the new nh */
1309 + if (mpls->ldp && mpls->fib_callback) {
1310 + memset(&dest,0,sizeof(dest));
1312 + /* if their was a previouly active route, delete it */
1313 + if (active) {
1314 + zebra_prefix2mpls_fec((struct prefix*)p, active, &dest);
1315 + mpls->fib_callback(mpls->ldp->h, MPLS_UPDATE_DEL, &dest);
1318 + /* add the new route */
1319 + zebra_prefix2mpls_fec((struct prefix*)p, nh, &dest);
1320 + mpls->fib_callback(mpls->ldp->h, MPLS_UPDATE_ADD, &dest);
1322 + if (rn) {
1323 + route_unlock_node(rn);
1327 +void ldp_ipv4_delete(struct mpls* mpls, struct prefix_ipv4* p,
1328 + struct mpls_nexthop* nexthop) {
1329 + struct route_node* rn;
1330 + struct list* list = NULL;
1331 + struct listnode* ln;
1332 + struct mpls_nexthop *active = NULL;
1333 + struct mpls_nexthop *head = NULL;
1334 + struct mpls_nexthop* nh = NULL;
1335 + mpls_fec dest;
1337 + if ((rn = route_node_lookup(mpls->table,(struct prefix*)p))) {
1338 + list = (struct list*)rn->info;
1339 + active = listhead(list) ? getdata(listhead(list)) : NULL;
1340 + LIST_LOOP(list, nh, ln) {
1341 + /* if they match, remove it */
1342 + if (!mpls_nexthop_compare(nh, nexthop)) {
1343 + list_delete_node(list, ln);
1344 + break;
1347 + if (list_isempty(list)) {
1348 + rn->info = NULL;
1349 + route_unlock_node(rn);
1350 + list_free(list);
1351 + list = NULL;
1355 + head = (list && listhead(list)) ? getdata(listhead(list)) : NULL;
1357 + if (!nh) {
1358 + /* if we do not know about the route, do nothing */
1359 + if (rn) {
1360 + route_unlock_node(rn);
1362 + return;
1365 + /* otherwise, if we have a callback */
1366 + if (mpls->ldp && mpls->fib_callback) {
1367 + memset(&dest,0,sizeof(dest));
1369 + /* did we we just removed the active nexthop */
1370 + if (active == nh) {
1371 + /* if so send in a delete */
1372 + zebra_prefix2mpls_fec((struct prefix*)p, nexthop, &dest);
1373 + mpls->fib_callback(mpls->ldp->h, MPLS_UPDATE_DEL, &dest);
1374 + mpls_nexthop_delete(nh);
1376 + /* is there a active nexthop? */
1377 + if (head) {
1378 + /* if so, send in a add */
1379 + zebra_prefix2mpls_fec((struct prefix*)p, head, &dest);
1380 + mpls->fib_callback(mpls->ldp->h, MPLS_UPDATE_ADD, &dest);
1384 + route_unlock_node(rn);
1386 diff --exclude=.p4config -uNr zebra/mplsd/impl_fib.h zebra-ldp/mplsd/impl_fib.h
1387 --- zebra/mplsd/impl_fib.h 1969-12-31 18:00:00.000000000 -0600
1388 +++ zebra-ldp/mplsd/impl_fib.h 2003-03-10 14:57:23.000000000 -0600
1389 @@ -0,0 +1,16 @@
1390 +#ifndef LDP_IMPL_FIB_H
1391 +#define LDP_IMPL_FIB_H
1393 +#include <zebra.h>
1395 +#include "ldp_struct.h"
1396 +#include "mpls.h"
1398 +extern void mpls_fec2zebra_prefix(mpls_fec *lp, struct prefix *p);
1399 +extern void zebra_prefix2mpls_fec(struct prefix *p, mpls_fec *lp);
1400 +void ldp_ipv4_add(struct mpls *mpls, struct prefix_ipv4 *p,
1401 + struct mpls_nexthop *nexthop);
1402 +void ldp_ipv4_delete(struct mpls *mpls, struct prefix_ipv4 *p,
1403 + struct mpls_nexthop *nexthop);
1405 +#endif
1406 diff --exclude=.p4config -uNr zebra/mplsd/impl_ifmgr.c zebra-ldp/mplsd/impl_ifmgr.c
1407 --- zebra/mplsd/impl_ifmgr.c 1969-12-31 18:00:00.000000000 -0600
1408 +++ zebra-ldp/mplsd/impl_ifmgr.c 2003-03-10 14:57:24.000000000 -0600
1409 @@ -0,0 +1,163 @@
1410 +#include <zebra.h>
1411 +#include "if.h"
1413 +#include "ldp.h"
1414 +#include "ldp_struct.h"
1416 +#include "mpls.h"
1418 +static ldp_ifmgr_callback ifmgr_callback;
1419 +static int opened = 0;
1421 +static unsigned int mask_array[33] = { 0x00000000,
1422 + 0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,
1423 + 0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,
1424 + 0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,
1425 + 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
1426 + 0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,
1427 + 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,
1428 + 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,
1429 + 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF };
1431 +mpls_ifmgr_handle mpls_ifmgr_open(mpls_instance_handle handle,
1432 + mpls_cfg_handle cfg, ldp_ifmgr_callback callback)
1434 + if (callback) {
1435 + ifmgr_callback = callback;
1436 + opened = 1;
1438 + return 0xdeadbeef;
1441 +void mpls_ifmgr_close(mpls_ifmgr_handle ifmgr_handle)
1443 + opened = 0;
1446 +mpls_if_handle mpls_ifmgr_open_if(mpls_ifmgr_handle ifmgr_handle, const char *name)
1448 + mpls_if_handle ifh;
1449 + char name2[IFNAMSIZ + 1];
1450 + strncpy(name2,name,IFNAMSIZ);
1452 + ifh = if_lookup_by_name(name2);
1454 + return ifh;
1457 +mpls_return_enum mpls_ifmgr_get_address(mpls_ifmgr_handle ifmgr_handle,
1458 + mpls_if_handle if_handle, mpls_inet_addr * addr, mpls_inet_addr * mask,
1459 + uint32_t * flags)
1461 + struct connected *ifc;
1462 + listnode node;
1463 + int loop = 0;
1465 + if (flags) {
1466 + *flags = if_handle->flags;
1469 + for (node = listhead(if_handle->connected); node; nextnode(node)) {
1470 + ifc = getdata(node);
1471 + if (ifc->address->u.prefix4.s_addr == htonl(INADDR_LOOPBACK)) {
1472 + loop = 1;
1473 + continue;
1475 + if (!loop && (ifc->flags & ZEBRA_IFA_SECONDARY)) {
1476 + continue;
1478 + if (addr) {
1479 + addr->type = MPLS_FAMILY_IPV4;
1480 + addr->u.ipv4 = ntohl(ifc->address->u.prefix4.s_addr);
1482 + if (mask) {
1483 + mask->type = MPLS_FAMILY_IPV4;
1484 + mask->u.ipv4 = mask_array[ifc->address->prefixlen];
1486 + return MPLS_SUCCESS;
1488 + return MPLS_FAILURE;
1491 +mpls_return_enum mpls_ifmgr_get_mtu(mpls_ifmgr_handle ifmgr_handle,
1492 + mpls_if_handle if_handle, int *mtu)
1494 + *mtu = if_handle->mtu;
1495 + return MPLS_SUCCESS;
1498 +void mpls_ifmgr_close_if(mpls_ifmgr_handle ifmgr_handle, mpls_if_handle if_handle)
1502 +mpls_return_enum mpls_ifmgr_getnext_address(mpls_ifmgr_handle ifmgr_handle,
1503 + mpls_if_handle *handle, mpls_inet_addr *addr)
1505 + struct connected *ifc;
1506 + listnode node;
1507 + int next = 0;
1509 + while ((*handle)) {
1510 + for (node = listhead((*handle)->connected); node; nextnode(node)) {
1511 + ifc = getdata(node);
1512 + if (ifc->address->u.prefix4.s_addr != htonl(INADDR_LOOPBACK)) {
1513 + if (next) {
1514 + addr->type = MPLS_FAMILY_IPV4;
1515 + addr->u.ipv4 = ntohl(ifc->address->u.prefix4.s_addr);
1516 + return MPLS_SUCCESS;
1517 + } else if (addr->u.ipv4 == ntohl(ifc->address->u.prefix4.s_addr)) {
1518 + next = 1;
1522 + (*handle) = if_getnext(*handle);
1523 + next = 1;
1525 + return MPLS_END_OF_LIST;
1528 +mpls_return_enum mpls_ifmgr_getfirst_address(mpls_ifmgr_handle ifmgr_handle,
1529 + mpls_if_handle *handle, mpls_inet_addr *addr)
1531 + struct connected *ifc;
1532 + listnode node;
1534 + (*handle) = if_getfirst();
1535 + while ((*handle)) {
1536 + for (node = listhead((*handle)->connected); node; nextnode(node)) {
1537 + ifc = getdata(node);
1538 + if (ifc->address->u.prefix4.s_addr != htonl(INADDR_LOOPBACK)) {
1539 + addr->type = MPLS_FAMILY_IPV4;
1540 + addr->u.ipv4 = ntohl(ifc->address->u.prefix4.s_addr);
1541 + return MPLS_SUCCESS;
1544 + (*handle) = if_getnext(*handle);
1546 + return MPLS_END_OF_LIST;
1549 +int ldp_address_add_callback(struct mpls *mpls, struct connected *c) {
1550 + mpls_inet_addr addr;
1552 + if (opened) {
1553 + addr.type = MPLS_FAMILY_IPV4;
1554 + addr.u.ipv4 = ntohl(c->address->u.prefix4.s_addr);
1556 + ifmgr_callback(mpls->ldp->h,MPLS_UPDATE_ADD,&addr);
1559 + return 0;
1562 +int ldp_address_delete_callback(struct mpls *mpls, struct connected *c) {
1563 + mpls_inet_addr addr;
1565 + if (opened) {
1566 + addr.type = MPLS_FAMILY_IPV4;
1567 + addr.u.ipv4 = ntohl(c->address->u.prefix4.s_addr);
1569 + ifmgr_callback(mpls->ldp->h,MPLS_UPDATE_DEL,&addr);
1571 + return 0;
1573 diff --exclude=.p4config -uNr zebra/mplsd/impl_ifmgr.h zebra-ldp/mplsd/impl_ifmgr.h
1574 --- zebra/mplsd/impl_ifmgr.h 1969-12-31 18:00:00.000000000 -0600
1575 +++ zebra-ldp/mplsd/impl_ifmgr.h 2003-03-10 14:57:24.000000000 -0600
1576 @@ -0,0 +1,10 @@
1577 +#ifndef LDP_IMPL_IFMGR_H
1578 +#define LDP_IMPL_IFMGR_H
1580 +#include <zebra.h>
1581 +#include "ldp_struct.h"
1583 +int ldp_address_add_callback(struct mpls *mpls, struct connected *c);
1584 +int ldp_address_delete_callback(struct mpls *mpls, struct connected *c);
1586 +#endif
1587 diff --exclude=.p4config -uNr zebra/mplsd/impl_lock.c zebra-ldp/mplsd/impl_lock.c
1588 --- zebra/mplsd/impl_lock.c 1969-12-31 18:00:00.000000000 -0600
1589 +++ zebra-ldp/mplsd/impl_lock.c 2003-03-10 14:57:24.000000000 -0600
1590 @@ -0,0 +1,28 @@
1591 +#include "ldp_struct.h"
1592 +#include "mpls_assert.h"
1593 +#include "mpls_mm_impl.h"
1595 +mpls_lock_handle mpls_lock_create(mpls_lock_key_type key)
1597 + int *i = mpls_malloc(sizeof(int));
1599 + *i = 0;
1600 + return i;
1603 +void mpls_lock_get(mpls_lock_handle handle)
1605 + MPLS_ASSERT(*handle == 0);
1606 + (*handle)++;
1609 +void mpls_lock_release(mpls_lock_handle handle)
1611 + MPLS_ASSERT(*handle == 1);
1612 + (*handle)--;
1615 +void mpls_lock_delete(mpls_lock_handle handle)
1617 + mpls_free(handle);
1619 diff --exclude=.p4config -uNr zebra/mplsd/impl_mm.c zebra-ldp/mplsd/impl_mm.c
1620 --- zebra/mplsd/impl_mm.c 1969-12-31 18:00:00.000000000 -0600
1621 +++ zebra-ldp/mplsd/impl_mm.c 2003-03-10 14:57:24.000000000 -0600
1622 @@ -0,0 +1,28 @@
1623 +#include "ldp_struct.h"
1624 +#include "mpls_mm_impl.h"
1625 +#include <stdio.h>
1626 +#include <stdlib.h>
1628 +#include "memory.h"
1630 +static int _mm_count = 0;
1632 +void *mpls_malloc(mpls_size_type size)
1634 + void *mem = XMALLOC(MTYPE_MPLS_LDP, size);
1635 + if (mem) {
1636 + _mm_count++;
1638 + return mem;
1641 +void mpls_free(void *mem)
1643 + _mm_count--;
1644 + XFREE(MTYPE_MPLS_LDP,mem);
1647 +void mpls_mm_results()
1649 + fprintf(stderr, "LDP MM RESULTS: %d\n", _mm_count);
1651 diff --exclude=.p4config -uNr zebra/mplsd/impl_mpls.c zebra-ldp/mplsd/impl_mpls.c
1652 --- zebra/mplsd/impl_mpls.c 1969-12-31 18:00:00.000000000 -0600
1653 +++ zebra-ldp/mplsd/impl_mpls.c 2003-03-10 14:57:24.000000000 -0600
1654 @@ -0,0 +1,262 @@
1655 +#include <mplsd/ldp.h>
1656 +#include <zebra.h>
1658 +#include "stream.h"
1659 +#include "prefix.h"
1660 +#include "log.h"
1661 +#include "zclient.h"
1662 +#include "if.h"
1664 +#include "ldp_struct.h"
1665 +#include "ldp_entity.h"
1666 +#include "mpls_mpls_impl.h"
1667 +#include "mpls_socket_impl.h"
1668 +#include <linux/mpls.h>
1670 +#include "mpls_interface.h"
1671 +#include "impl_fib.h"
1673 +static int label = 10000;
1674 +extern struct zclient *zclient;
1675 +static int mplsd_socket = 0;
1677 +#define MPLS_LINUX 1
1679 +int mplsd_ioctl (u_long request, caddr_t buffer) {
1680 + int ret = 0;
1681 + int err = 0;
1683 + if (!mplsd_socket) {
1684 + mplsd_socket = socket (AF_INET, SOCK_DGRAM, 0);
1685 + if (mplsd_socket < 0) {
1686 + perror ("socket");
1687 + exit (1);
1691 + ret = ioctl (mplsd_socket, request, buffer);
1692 + if (ret < 0) {
1693 + err = errno;
1696 + if (ret < 0) {
1697 + errno = err;
1698 + return ret;
1700 + return 0;
1703 +int do_mpls_labelspace(struct mpls_interface *mi) {
1704 + struct mpls_labelspace_req mls;
1706 + if (!mi || !mi->ifp->ifindex) {
1707 + return 1;
1710 + memset(&mls,0,sizeof(struct mpls_labelspace_req));
1711 + mls.mls_ifindex = mi->ifp->ifindex;
1712 + mls.mls_labelspace = mi->labelspace;
1713 + if (mplsd_ioctl(SIOCSLABELSPACEMPLS,(caddr_t)&mls)) {
1714 + return 1;
1717 + return 0;
1720 +mpls_mpls_handle mpls_mpls_open(mpls_instance_handle user_data)
1722 + return socket(AF_INET, SOCK_STREAM, 0);
1725 +void mpls_mpls_close(mpls_mpls_handle handle)
1727 + close(handle);
1730 +mpls_return_enum mpls_mpls_outsegment_add(mpls_mpls_handle handle, mpls_outsegment * o)
1732 +#ifdef MPLS_LINUX
1733 + struct mpls_out_label_req oreq;
1734 + struct mpls_instruction_req mir;
1735 + struct sockaddr_in sin;
1736 + int result;
1738 + memset(&oreq,0,sizeof(oreq));
1739 + memset(&mir,0,sizeof(mir));
1740 + oreq.mol_label.ml_type = MPLS_LABEL_KEY;
1741 + result = ioctl(handle,SIOCMPLSNHLFEADD,&oreq);
1742 + o->handle = oreq.mol_label.u.ml_key;
1744 + mir.mir_direction = MPLS_OUT;
1745 + mir.mir_label.ml_type = MPLS_LABEL_KEY;
1746 + mir.mir_label.u.ml_key = o->handle;
1747 + mir.mir_instruction[0].mir_opcode = MPLS_OP_PUSH;
1748 + mir.mir_instruction[0].mir_data.push.ml_type = MPLS_LABEL_GEN;
1749 + mir.mir_instruction[0].mir_data.push.u.ml_gen = o->label.u.gen;
1751 + mir.mir_instruction[1].mir_opcode = MPLS_OP_SET;
1752 + mir.mir_instruction[1].mir_data.set.mni_if = o->nexthop.if_handle->ifindex;
1753 + sin.sin_addr.s_addr = htonl(o->nexthop.ip.u.ipv4);
1754 + sin.sin_family = AF_INET;
1755 + memcpy(&mir.mir_instruction[1].mir_data.set.mni_addr,
1756 + &sin,sizeof(struct sockaddr));
1758 + mir.mir_instruction_length = 2;
1759 + result = ioctl(handle,SIOCSMPLSOUTINSTR,&mir);
1761 +#if 0
1762 + struct ifreq ifr;
1763 + sprintf(ifr.ifr_name,"mpls%d",o->handle);
1764 + memcpy(&ifr.ifr_data,&oreq.mol_label,sizeof(struct mpls_label));
1765 + result = ioctl(handle,SIOCMPLSTUNNELADD,&ifr);
1766 + ifr.ifr_flags = IFF_UP | IFF_POINTOPOINT | IFF_NOARP | IFF_RUNNING;
1767 + result = ioctl(handle,SIOCSIFFLAGS,&ifr);
1768 +#endif
1769 +#endif
1770 + return MPLS_SUCCESS;
1773 +void mpls_mpls_outsegment_del(mpls_mpls_handle handle, mpls_outsegment * o)
1775 +#ifdef MPLS_LINUX
1776 + struct mpls_out_label_req oreq;
1777 + int result;
1779 +#if 0
1780 + struct ifreq ifr;
1781 + sprintf(ifr.ifr_name,"mpls%d",o->handle);
1782 + result = ioctl(handle,SIOCMPLSTUNNELDEL,&ifr);
1783 +#endif
1785 + oreq.mol_label.ml_type = MPLS_LABEL_KEY;
1786 + oreq.mol_label.u.ml_key = o->handle;
1787 + result = ioctl(handle,SIOCMPLSNHLFEDEL,&oreq);
1789 +#endif
1792 +mpls_return_enum mpls_mpls_insegment_add(mpls_mpls_handle handle,
1793 + mpls_insegment * i)
1795 +#ifdef MPLS_LINUX
1796 + struct mpls_in_label_req ireq;
1797 + int result;
1798 +#endif
1800 + if (i->label.type == MPLS_LABEL_TYPE_NONE) {
1801 + i->label.type = MPLS_LABEL_TYPE_GENERIC;
1802 + i->label.u.gen = label++;
1805 +#ifdef MPLS_LINUX
1806 + ireq.mil_label.ml_type = MPLS_LABEL_GEN;
1807 + ireq.mil_label.u.ml_gen = i->label.u.gen;
1808 + ireq.mil_label.ml_index = i->labelspace;
1809 + i->handle = 0;
1811 + result = ioctl(handle,SIOCMPLSILMADD,&ireq);
1813 +#endif
1814 + return MPLS_SUCCESS;
1817 +void mpls_mpls_insegment_del(mpls_mpls_handle handle, mpls_insegment * i)
1819 +#ifdef MPLS_LINUX
1820 + struct mpls_in_label_req ireq;
1821 + int result;
1823 + ireq.mil_label.ml_type = MPLS_LABEL_GEN;
1824 + ireq.mil_label.u.ml_gen = i->label.u.gen;
1825 + ireq.mil_label.ml_index = i->labelspace;
1827 + result = ioctl(handle,SIOCMPLSILMDEL,&ireq);
1828 +#endif
1831 +mpls_return_enum mpls_mpls_xconnect_add(mpls_mpls_handle handle, mpls_insegment * i, mpls_outsegment * o)
1833 +#ifdef MPLS_LINUX
1834 + struct mpls_xconnect_req xreq;
1835 + int result;
1837 + xreq.mx_in.ml_type = MPLS_LABEL_GEN;
1838 + xreq.mx_in.u.ml_gen = i->label.u.gen;
1839 + xreq.mx_in.ml_index = i->labelspace;
1841 + xreq.mx_out.ml_type = MPLS_LABEL_KEY;
1842 + xreq.mx_out.u.ml_key = o->handle;
1844 + result = ioctl(handle,SIOCMPLSXCADD,&xreq);
1846 +#endif
1848 + return MPLS_SUCCESS;
1851 +void mpls_mpls_xconnect_del(mpls_mpls_handle handle, mpls_insegment * i,
1852 + mpls_outsegment * o)
1854 +#ifdef MPLS_LINUX
1855 + struct mpls_xconnect_req xreq;
1856 + int result;
1858 + xreq.mx_in.ml_type = MPLS_LABEL_GEN;
1859 + xreq.mx_in.u.ml_gen = i->label.u.gen;
1860 + xreq.mx_in.ml_index = i->labelspace;
1862 + xreq.mx_out.ml_type = MPLS_LABEL_KEY;
1863 + xreq.mx_out.u.ml_key = o->handle;
1865 + result = ioctl(handle,SIOCMPLSXCDEL,&xreq);
1867 +#endif
1870 +mpls_return_enum mpls_mpls_fec2out_add(mpls_mpls_handle handle, mpls_fec * f,
1871 + mpls_outsegment * o)
1873 + struct prefix p;
1874 + struct in_addr addr;
1875 + unsigned int ifindex;
1876 + unsigned int mplsindex;
1877 + int retval;
1879 + mplsindex = o->handle;
1880 + ifindex = o->nexthop.if_handle->ifindex;
1881 + addr.s_addr = htonl(o->nexthop.ip.u.ipv4);
1883 + mpls_fec2zebra_prefix(f,&p);
1884 + retval = zapi_ipv4_set_mplsindex(zclient,(struct prefix_ipv4*)&p,
1885 + &addr,ifindex,mplsindex);
1887 + return MPLS_SUCCESS;
1890 +void mpls_mpls_fec2out_del(mpls_mpls_handle handle, mpls_fec * f,
1891 + mpls_outsegment * o)
1893 + struct prefix p;
1894 + struct in_addr addr;
1895 + unsigned int ifindex;
1896 + unsigned int mplsindex;
1897 + int retval;
1899 + mplsindex = o->handle;
1900 + ifindex = o->nexthop.if_handle->ifindex;
1901 + addr.s_addr = htonl(o->nexthop.ip.u.ipv4);
1903 + mpls_fec2zebra_prefix(f,&p);
1904 + retval = zapi_ipv4_set_mplsindex(zclient,(struct prefix_ipv4*)&p,
1905 + &addr,ifindex,0);
1908 +mpls_return_enum mpls_mpls_get_label_space_range(mpls_mpls_handle handle,
1909 + mpls_range * r)
1911 + r->type = MPLS_LABEL_RANGE_GENERIC;
1912 + r->min.u.gen = 16;
1913 + r->max.u.gen = 0xFFFFF;
1915 + return MPLS_SUCCESS;
1917 diff --exclude=.p4config -uNr zebra/mplsd/impl_mpls.h zebra-ldp/mplsd/impl_mpls.h
1918 --- zebra/mplsd/impl_mpls.h 1969-12-31 18:00:00.000000000 -0600
1919 +++ zebra-ldp/mplsd/impl_mpls.h 2003-03-10 14:57:25.000000000 -0600
1920 @@ -0,0 +1,6 @@
1921 +#ifndef IMPL_MPLS_H
1922 +#define IMPL_MPLS_H
1924 +int do_mpls_labelspace(struct mpls_interface *mi);
1926 +#endif
1927 diff --exclude=.p4config -uNr zebra/mplsd/impl_policy.c zebra-ldp/mplsd/impl_policy.c
1928 --- zebra/mplsd/impl_policy.c 1969-12-31 18:00:00.000000000 -0600
1929 +++ zebra-ldp/mplsd/impl_policy.c 2003-03-10 14:57:25.000000000 -0600
1930 @@ -0,0 +1,87 @@
1931 +#include <zebra.h>
1933 +#include "ldp_struct.h"
1934 +#include "mpls_interface.h"
1935 +#include "impl_fib.h"
1936 +#include "table.h"
1938 +mpls_bool mpls_policy_import_check(mpls_instance_handle handle, mpls_fec * f,
1939 + ldp_addr * nh)
1941 + return MPLS_BOOL_TRUE;
1944 +mpls_bool mpls_policy_ingress_check(mpls_instance_handle handle, mpls_fec * f, ldp_addr * nh)
1946 + return MPLS_BOOL_TRUE;
1949 +mpls_bool mpls_policy_egress_check(mpls_instance_handle handle, mpls_fec * fec)
1951 + struct ldp *ldp = handle;
1952 + int result = MPLS_BOOL_FALSE;
1954 + switch(ldp->egress) {
1955 + case LDP_EGRESS_ALL:
1956 + result = MPLS_BOOL_TRUE;
1957 + break;
1958 + case LDP_EGRESS_LSRID:
1959 + case LDP_EGRESS_CONNECTED:
1961 + struct route_node *rn;
1962 + struct prefix p;
1964 + mpls_fec2zebra_prefix(fec,&p);
1965 + if ((rn = route_node_lookup(ldp->mpls->table,&p))) {
1966 + if (ldp->egress == LDP_EGRESS_LSRID) {
1967 + if (prefix_match(&rn->p, &ldp->mpls->router_id)) {
1968 + result = MPLS_BOOL_TRUE;
1970 + } else {
1971 + struct mpls_nexthop* nh =
1972 + (struct mpls_nexthop*)getdata(listhead((struct list*)rn->info));
1973 + result = nh->attached;
1975 + route_unlock_node(rn);
1977 + break;
1979 + default:
1980 + break;
1982 + return result;
1985 +mpls_bool mpls_policy_export_check(mpls_instance_handle handle, mpls_fec * f, ldp_addr * nh)
1987 + return MPLS_BOOL_TRUE;
1990 +mpls_bool mpls_policy_address_export_check(mpls_instance_handle handle,
1991 + mpls_inet_addr *addr) {
1992 + struct ldp *ldp = handle;
1993 + mpls_bool flag = MPLS_BOOL_FALSE;
1994 + struct interface *ifp;
1995 + struct in_addr in;
1997 + in.s_addr = htonl(addr->u.ipv4);
2000 + switch (ldp->address) {
2001 + case LDP_ADDRESS_LDP:
2002 + if ((ifp = if_lookup_exact_address(in)) &&
2003 + ((struct mpls_interface*)(ifp->info))->ldp) {
2004 + flag = MPLS_BOOL_TRUE;
2006 + /* fall through */
2007 + case LDP_ADDRESS_LSRID:
2008 + if (in.s_addr == ldp->mpls->router_id.u.prefix4.s_addr) {
2009 + flag = MPLS_BOOL_TRUE;
2011 + break;
2012 + case LDP_ADDRESS_ALL:
2013 + flag = MPLS_BOOL_TRUE;
2014 + break;
2016 + return flag;
2018 diff --exclude=.p4config -uNr zebra/mplsd/impl_socket.c zebra-ldp/mplsd/impl_socket.c
2019 --- zebra/mplsd/impl_socket.c 1969-12-31 18:00:00.000000000 -0600
2020 +++ zebra-ldp/mplsd/impl_socket.c 2003-03-29 01:12:02.000000000 -0600
2021 @@ -0,0 +1,444 @@
2022 +#include <zebra.h>
2023 +#include "thread.h"
2024 +#include "sockopt.h"
2026 +#include "mpls.h"
2028 +#include "ldp_struct.h"
2029 +#include "ldp_state_machine.h"
2030 +#include "mpls_mm_impl.h"
2032 +extern struct thread_master *master;
2034 +struct mpls_socket {
2035 + int fd;
2036 + int type;
2037 + struct thread *read;
2038 + struct thread *write;
2039 + void *extra;
2042 +void _sockaddr2mpls_dest(const struct sockaddr *addr, mpls_dest * dest)
2044 + dest->addr.type = MPLS_FAMILY_IPV4;
2045 + switch (dest->addr.type) {
2046 + case MPLS_FAMILY_IPV4:
2047 + dest->port = ntohs(((struct sockaddr_in *)addr)->sin_port);
2048 + dest->addr.u.ipv4 = ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr);
2049 + break;
2050 + default:
2051 + assert(0);
2055 +void _mpls_dest2sockaddr(const mpls_dest * dest, struct sockaddr *addr)
2057 + memset(addr, 0, sizeof(struct sockaddr));
2059 + switch (dest->addr.type) {
2060 + case MPLS_FAMILY_IPV4:
2062 + addr->sa_family = AF_INET;
2063 + ((struct sockaddr_in *)addr)->sin_port = htons(dest->port);
2064 + ((struct sockaddr_in *)addr)->sin_addr.s_addr = htonl(dest->addr.u.ipv4);
2065 + break;
2067 + default:
2069 + assert(0);
2074 +int mplsd_read(struct thread *thread) {
2075 + int retval;
2076 + struct mpls *mpls = mpls_get();
2077 + mpls_socket_handle socket;
2079 + MPLS_ASSERT(thread);
2081 + socket = THREAD_ARG(thread);
2082 + socket->read = thread_add_read(master,mplsd_read,socket,socket->fd);
2084 + if (!mpls || !mpls->ldp) {
2085 + return 0;
2088 + switch (socket->type) {
2089 + case MPLS_SOCKET_TCP_DATA:
2091 + retval = ldp_event(mpls->ldp->h, socket, socket->extra,
2092 + LDP_EVENT_TCP_DATA);
2093 + break;
2095 + case MPLS_SOCKET_TCP_LISTEN:
2097 + retval = ldp_event(mpls->ldp->h, socket, socket->extra,
2098 + LDP_EVENT_TCP_LISTEN);
2099 + break;
2101 + case MPLS_SOCKET_UDP_DATA:
2103 + retval = ldp_event(mpls->ldp->h, socket, socket->extra,
2104 + LDP_EVENT_UDP_DATA);
2105 + break;
2107 + default:
2109 + assert(0);
2112 + return 0;
2115 +int mplsd_write(struct thread *thread) {
2116 + struct mpls *mpls = mpls_get();
2117 + int retval;
2118 + mpls_socket_handle socket;
2120 + MPLS_ASSERT(thread);
2122 + socket = THREAD_ARG(thread);
2123 + socket->write = thread_add_write(master,mplsd_write,socket,socket->fd);
2124 + if (socket->type != MPLS_SOCKET_TCP_CONNECT) {
2125 + assert(0);
2127 + retval = ldp_event(mpls->ldp->h, socket, socket->extra,
2128 + LDP_EVENT_TCP_CONNECT);
2130 + return 0;
2133 +mpls_socket_mgr_handle mpls_socket_mgr_open(mpls_instance_handle user_data)
2135 + return 0xdeadbeef;
2138 +void mpls_socket_mgr_close(mpls_socket_mgr_handle handle)
2142 +void mpls_socket_close(mpls_socket_mgr_handle handle, mpls_socket_handle socket)
2144 + if (socket) {
2145 + close(socket->fd);
2146 + mpls_free(socket);
2150 +mpls_socket_handle mpls_socket_create_tcp(mpls_socket_mgr_handle handle)
2152 + struct mpls_socket *sock;
2153 + sock = mpls_malloc(sizeof(struct mpls_socket));
2154 + memset(sock,0,sizeof(struct mpls_socket));
2155 + sock->fd = socket(AF_INET, SOCK_STREAM, 0);
2156 + MPLS_ASSERT(sock->fd > -1);
2157 + return sock;
2160 +mpls_socket_handle mpls_socket_create_udp(mpls_socket_mgr_handle handle)
2162 + struct mpls_socket *sock;
2163 + u_char one = 1;
2165 + sock = mpls_malloc(sizeof(struct mpls_socket));
2166 + memset(sock,0,sizeof(struct mpls_socket));
2167 + sock->fd = socket(AF_INET, SOCK_DGRAM, 0);
2168 + MPLS_ASSERT(sock->fd > -1);
2169 + if (setsockopt(sock->fd,IPPROTO_IP,IP_PKTINFO,&one,sizeof(one)) < 0) {
2170 + perror("PKTINFO");
2171 + mpls_free(sock);
2172 + return NULL;
2174 + return sock;
2177 +mpls_socket_handle mpls_socket_tcp_accept(mpls_socket_mgr_handle handle,
2178 + mpls_socket_handle socket, mpls_dest * from)
2180 + struct mpls_socket *sock = mpls_malloc(sizeof(struct mpls_socket));
2181 + struct sockaddr addr;
2182 + int size = sizeof(addr);
2184 + if ((sock->fd = accept(socket->fd,&addr,&size)) < 0) {
2185 + return NULL;
2188 + _sockaddr2mpls_dest(&addr, from);
2189 + return sock;
2192 +mpls_return_enum mpls_socket_bind(mpls_socket_mgr_handle handle,
2193 + mpls_socket_handle socket, const mpls_dest * local)
2195 + struct sockaddr addr;
2197 + _mpls_dest2sockaddr(local, &addr);
2199 + if (bind(socket->fd, &addr, sizeof(struct sockaddr_in)) < 0) {
2200 + return MPLS_FAILURE;
2203 + return MPLS_SUCCESS;
2206 +mpls_return_enum mpls_socket_tcp_listen(mpls_socket_mgr_handle handle,
2207 + mpls_socket_handle socket, int depth)
2209 + if (listen(socket->fd, depth) < 0) {
2210 + return MPLS_FAILURE;
2212 + return MPLS_SUCCESS;
2215 +mpls_return_enum mpls_socket_tcp_connect(mpls_socket_mgr_handle handle,
2216 + mpls_socket_handle socket, const mpls_dest * to)
2218 + struct sockaddr addr, *iaddr = NULL;
2220 + if (to != NULL) {
2221 + _mpls_dest2sockaddr(to, &addr);
2222 + iaddr = &addr;
2223 + } else {
2224 + iaddr = NULL;
2227 + if (connect(socket->fd, iaddr, sizeof(struct sockaddr)) < 0) {
2228 + if (errno == EINPROGRESS) {
2229 + return MPLS_NON_BLOCKING;
2232 + if (errno == EALREADY) {
2233 + return MPLS_SUCCESS;
2235 + perror("connect");
2236 + return MPLS_FAILURE;
2238 + return MPLS_SUCCESS;
2241 +mpls_return_enum mpls_socket_connect_status(mpls_socket_mgr_handle handle,
2242 + mpls_socket_handle socket)
2244 + int size = sizeof(int);
2245 + int num = 1;
2247 + if (getsockopt(socket->fd, SOL_SOCKET, SO_ERROR, &num, &size) < 0) {
2248 + perror("getsockopt");
2249 + return MPLS_FAILURE;
2251 + if (!num) {
2252 + return MPLS_SUCCESS;
2254 + perror("getsockopt");
2255 + return MPLS_NON_BLOCKING;
2258 +int mpls_socket_get_errno(const mpls_socket_mgr_handle handle,
2259 + mpls_socket_handle socket)
2261 + return errno;
2264 +mpls_return_enum mpls_socket_options(mpls_socket_mgr_handle handle,
2265 + mpls_socket_handle socket, uint32_t flag)
2267 + int one = 1;
2269 + if (flag & MPLS_SOCKOP_REUSE) {
2270 + if (setsockopt(socket->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one,
2271 + sizeof(one)) < 0) {
2272 + return MPLS_FAILURE;
2275 + if (flag & MPLS_SOCKOP_NONBLOCK) {
2276 + if (fcntl(socket->fd, F_SETFL, O_NONBLOCK) < 0) {
2277 + return MPLS_FAILURE;
2280 + return MPLS_SUCCESS;
2283 +mpls_return_enum mpls_socket_multicast_options(mpls_socket_mgr_handle handle,
2284 + mpls_socket_handle socket, int ttl, int loop)
2286 + int zero = loop;
2287 + int one = ttl;
2289 + if (setsockopt(socket->fd,IPPROTO_IP,IP_MULTICAST_TTL,&one,sizeof(one))<0) {
2290 + return MPLS_FAILURE;
2293 + if (setsockopt(socket->fd,IPPROTO_IP,IP_MULTICAST_LOOP,&zero,sizeof(zero))<0) {
2294 + return MPLS_FAILURE;
2297 + return MPLS_SUCCESS;
2300 +mpls_return_enum mpls_socket_multicast_if_tx(mpls_socket_mgr_handle handle,
2301 + mpls_socket_handle socket, const ldp_if * iff)
2303 + struct in_addr addr;
2304 + unsigned int ifindex = 0;
2305 + addr.s_addr = 0;
2307 + if (iff == NULL) {
2308 + addr.s_addr = ntohl(INADDR_ANY);
2309 + } else {
2310 + ifindex = iff->handle->ifindex;
2313 + if (setsockopt_multicast_ipv4(socket->fd,IP_MULTICAST_IF,addr,0,ifindex)<0) {
2314 + return MPLS_FAILURE;
2317 + return MPLS_SUCCESS;
2320 +mpls_return_enum mpls_socket_multicast_if_join(mpls_socket_mgr_handle handle,
2321 + mpls_socket_handle socket, const ldp_if * iff, const mpls_inet_addr * mult)
2323 + struct in_addr addr;
2324 + unsigned int ifindex = 0;
2325 + addr.s_addr = 0;
2327 + if (iff == NULL) {
2328 + addr.s_addr = ntohl(INADDR_ANY);
2329 + } else {
2330 + ifindex = iff->handle->ifindex;
2333 + if (setsockopt_multicast_ipv4(socket->fd,IP_ADD_MEMBERSHIP,addr,
2334 + htonl(mult->u.ipv4),ifindex)<0) {
2335 + return MPLS_FAILURE;
2338 + return MPLS_SUCCESS;
2341 +void mpls_socket_multicast_if_drop(mpls_socket_mgr_handle handle,
2342 + mpls_socket_handle socket, const ldp_if * iff, const mpls_inet_addr * mult)
2344 + struct in_addr addr;
2345 + unsigned int ifindex = 0;
2346 + addr.s_addr = 0;
2348 + if (iff == NULL) {
2349 + addr.s_addr = ntohl(INADDR_ANY);
2350 + } else {
2351 + ifindex = iff->handle->ifindex;
2354 + if (setsockopt_multicast_ipv4(socket->fd,IP_DROP_MEMBERSHIP,addr,
2355 + htonl(mult->u.ipv4),ifindex)<0) {
2356 + return;
2359 + return;
2362 +mpls_return_enum mpls_socket_readlist_add(mpls_socket_mgr_handle handle,
2363 + mpls_socket_handle socket, void *extra, mpls_socket_enum type)
2365 + socket->type = type;
2366 + socket->extra = extra;
2367 + MPLS_ASSERT(socket && (socket->fd > -1));
2368 + socket->read = thread_add_read(master,mplsd_read,socket,socket->fd);
2369 + MPLS_ASSERT(socket->read);
2370 + return MPLS_SUCCESS;
2373 +void mpls_socket_readlist_del(mpls_socket_mgr_handle handle,
2374 + mpls_socket_handle socket)
2376 + if (socket && socket->read) {
2377 + thread_cancel(socket->read);
2378 + socket->read = NULL;
2382 +mpls_return_enum mpls_socket_writelist_add(mpls_socket_mgr_handle handle,
2383 + mpls_socket_handle socket, void *extra, mpls_socket_enum type)
2385 + socket->type = type;
2386 + socket->extra = extra;
2387 + MPLS_ASSERT(socket && (socket->fd > -1));
2388 + socket->write = thread_add_write(master,mplsd_write,socket,socket->fd);
2389 + MPLS_ASSERT(socket->write);
2390 + return MPLS_SUCCESS;
2393 +void mpls_socket_writelist_del(mpls_socket_mgr_handle handle,
2394 + mpls_socket_handle socket)
2396 + if (socket) {
2397 + thread_cancel(socket->write);
2398 + socket->write = NULL;
2402 +int mpls_socket_tcp_read(mpls_socket_mgr_handle handle, mpls_socket_handle socket,
2403 + uint8_t * buffer, int size)
2405 + int ret = read(socket->fd,buffer,size);
2406 + if (ret < 0 && errno != EAGAIN) {
2407 + perror("mpls_socket_tcp_read");
2408 + return 0;
2410 + return ret;
2413 +int mpls_socket_tcp_write(mpls_socket_mgr_handle handle, mpls_socket_handle socket,
2414 + uint8_t * buffer, int size)
2416 + return write(socket->fd,buffer,size);
2419 +int mpls_socket_udp_sendto(mpls_socket_mgr_handle handle,
2420 + mpls_socket_handle socket, uint8_t * buffer, int size, const mpls_dest * to)
2422 + struct sockaddr addr;
2423 + int retval;
2425 + _mpls_dest2sockaddr(to, &addr);
2427 + retval = sendto(socket->fd,buffer,size,0,&addr,sizeof(struct sockaddr));
2429 + return retval;
2432 +int mpls_socket_udp_recvfrom(mpls_socket_mgr_handle handle,
2433 + mpls_socket_handle socket, uint8_t * buffer, int size, mpls_dest * from)
2435 + int ret;
2436 + unsigned int ifindex = 0;
2437 + struct iovec iov;
2438 + struct cmsghdr *cmsg;
2439 + struct in_pktinfo *pktinfo;
2440 + struct sockaddr addr;
2441 + char buff [sizeof (*cmsg) + sizeof (*pktinfo)];
2442 + struct msghdr msgh = {&addr, sizeof(struct sockaddr), &iov, 1, buff,
2443 + sizeof (*cmsg) + sizeof (*pktinfo), 0};
2445 + iov.iov_base = buffer;
2446 + iov.iov_len = size;
2447 + ret = recvmsg(socket->fd,&msgh,0);
2449 + if (ret < 0 && errno != EAGAIN) {
2450 + return 0;
2453 + cmsg = CMSG_FIRSTHDR(&msgh);
2455 + if (cmsg != NULL &&
2456 + cmsg->cmsg_level == IPPROTO_IP &&
2457 + cmsg->cmsg_type == IP_PKTINFO) {
2458 + pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg);
2459 + ifindex = pktinfo->ipi_ifindex;
2460 + from->if_handle = if_lookup_by_index(ifindex);
2461 + _sockaddr2mpls_dest((const struct sockaddr*)&addr, from);
2464 + return ret;
2466 diff --exclude=.p4config -uNr zebra/mplsd/impl_timer.c zebra-ldp/mplsd/impl_timer.c
2467 --- zebra/mplsd/impl_timer.c 1969-12-31 18:00:00.000000000 -0600
2468 +++ zebra-ldp/mplsd/impl_timer.c 2003-03-10 14:57:25.000000000 -0600
2469 @@ -0,0 +1,93 @@
2470 +#include "ldp_struct.h"
2471 +#include "mpls_timer_impl.h"
2472 +#include "mpls_mm_impl.h"
2474 +#include "thread.h"
2476 +struct mpls_timer {
2477 + struct thread *timer;
2478 + mpls_time_unit_enum unit;
2479 + int duration;
2480 + int type;
2481 + void *extra;
2482 + mpls_cfg_handle g;
2483 + void (*callback) (mpls_timer_handle timer, void *extra, mpls_cfg_handle g);
2484 + int active;
2487 +extern struct thread_master *master;
2489 +int mpls_timer(struct thread* thread) {
2490 + mpls_timer_handle timer = THREAD_ARG(thread);
2492 + timer->active = 0;
2493 + if (timer->type == MPLS_TIMER_REOCCURRING) {
2494 + timer->timer = thread_add_timer(master,mpls_timer,timer,timer->duration);
2495 + timer->active = 1;
2497 + timer->callback(timer,timer->extra,timer->g);
2499 + return 0;
2502 +mpls_timer_mgr_handle mpls_timer_open(mpls_instance_handle user_data)
2504 + return 0xdeadbeef;
2507 +void mpls_timer_close(mpls_timer_mgr_handle handle)
2511 +mpls_timer_handle mpls_timer_create(mpls_timer_mgr_handle handle,
2512 + mpls_time_unit_enum unit, int duration, void *extra, mpls_cfg_handle g,
2513 + void (*callback) (mpls_timer_handle timer, void *extra, mpls_cfg_handle g))
2515 + struct mpls_timer *timer;
2516 + timer = mpls_malloc(sizeof(struct mpls_timer));
2517 + timer->unit = unit;
2518 + timer->duration = duration;
2519 + timer->extra = extra;
2520 + timer->g = g;
2521 + timer->callback = callback;
2522 + timer->active = 0;
2524 + return timer;
2527 +mpls_return_enum mpls_timer_modify(mpls_timer_mgr_handle handle,
2528 + mpls_timer_handle timer, int duration)
2530 + if (!timer) {
2531 + return MPLS_FAILURE;
2533 + timer->duration = duration;
2534 + return MPLS_SUCCESS;
2537 +void mpls_timer_delete(mpls_timer_mgr_handle handle, mpls_timer_handle timer)
2539 + if (timer) {
2540 + mpls_free(timer);
2544 +mpls_return_enum mpls_timer_start(mpls_timer_mgr_handle handle,
2545 + mpls_timer_handle timer, mpls_timer_type_enum type)
2547 + if (!timer) {
2548 + return MPLS_FAILURE;
2550 + timer->type = type;
2551 + timer->timer = thread_add_timer(master,mpls_timer,timer,timer->duration);
2552 + timer->active = 1;
2553 + return MPLS_SUCCESS;
2556 +void mpls_timer_stop(mpls_timer_mgr_handle handle, mpls_timer_handle timer)
2558 + if (timer && timer->active) {
2559 + thread_cancel(timer->timer);
2560 + timer->timer = NULL;
2563 diff --exclude=.p4config -uNr zebra/mplsd/impl_tree.c zebra-ldp/mplsd/impl_tree.c
2564 --- zebra/mplsd/impl_tree.c 1969-12-31 18:00:00.000000000 -0600
2565 +++ zebra-ldp/mplsd/impl_tree.c 2003-03-10 14:57:25.000000000 -0600
2566 @@ -0,0 +1,158 @@
2567 +#include <zebra.h>
2568 +#include "table.h"
2570 +#include "ldp_struct.h"
2571 +#include "mpls_mm_impl.h"
2572 +#include "mpls_tree_impl.h"
2574 +mpls_tree_handle mpls_tree_create(int depth)
2576 + return route_table_init();
2579 +mpls_return_enum mpls_tree_insert(mpls_tree_handle tree, uint32_t key, int length,
2580 + void *info)
2582 + struct route_node *node;
2583 + struct prefix p;
2585 + p.family = AF_INET;
2586 + p.prefixlen = length;
2587 + p.u.prefix4.s_addr = key;
2589 + if ((node = route_node_get(tree,&p))) {
2590 + /* result is that the node is 'held', it will be held */
2591 + /* until it is deleted from the tree */
2592 + node->info = info;
2593 + return MPLS_SUCCESS;
2595 + return MPLS_FAILURE;
2598 +mpls_return_enum mpls_tree_remove(mpls_tree_handle tree, uint32_t key, int length,
2599 + void **info)
2601 + struct route_node *node;
2602 + struct prefix p;
2604 + p.family = AF_INET;
2605 + p.prefixlen = length;
2606 + p.u.prefix4.s_addr = key;
2608 + if ((node = route_node_lookup(tree,&p))) {
2609 + *info = node->info;
2610 + node->info = NULL;
2611 + route_unlock_node(node);
2612 + route_unlock_node(node);
2613 + return MPLS_SUCCESS;
2615 + return MPLS_FAILURE;
2618 +mpls_return_enum mpls_tree_replace(mpls_tree_handle tree, uint32_t key, int length,
2619 + void *new, void **old)
2621 + struct route_node *node;
2622 + struct prefix p;
2624 + p.family = AF_INET;
2625 + p.prefixlen = length;
2626 + p.u.prefix4.s_addr = key;
2628 + if ((node = route_node_lookup(tree,&p))) {
2629 + *old = node->info;
2630 + node->info = new;
2631 + route_unlock_node(node);
2632 + return MPLS_SUCCESS;
2634 + return MPLS_FAILURE;
2637 +mpls_return_enum mpls_tree_get(mpls_tree_handle tree, uint32_t key, int length,
2638 + void **info)
2640 + struct route_node *node;
2641 + struct prefix p;
2643 + p.family = AF_INET;
2644 + p.prefixlen = length;
2645 + p.u.prefix4.s_addr = key;
2647 + if ((node = route_node_lookup(tree,&p))) {
2648 + *info = node->info;
2649 + route_unlock_node(node);
2650 + return MPLS_SUCCESS;
2652 + return MPLS_FAILURE;
2655 +mpls_return_enum mpls_tree_get_longest(mpls_tree_handle tree, uint32_t key,
2656 + void **info)
2658 + struct route_node *node;
2659 + struct prefix p;
2661 + p.family = AF_INET;
2662 + p.prefixlen = 0;
2663 + p.u.prefix4.s_addr = key;
2665 + if ((node = route_node_match(tree,&p))) {
2666 + *info = node->info;
2667 + route_unlock_node(node);
2668 + return MPLS_SUCCESS;
2670 + return MPLS_FAILURE;
2673 +void mpls_tree_dump(const mpls_tree_handle tree, ldp_tree_callback callback)
2677 +void mpls_tree_delete(mpls_tree_handle tree)
2679 + route_table_finish(tree);
2682 +mpls_return_enum mpls_tree_getfirst(mpls_tree_handle tree, uint32_t * key,
2683 + int *length, void **info)
2685 + struct route_node *node;
2686 + struct prefix p;
2688 + p.family = AF_INET;
2689 + p.prefixlen = 0;
2690 + p.u.prefix4.s_addr = 0;
2692 + if ((node = route_node_match(tree,&p))) {
2693 + *info = node->info;
2694 + *length = node->p.prefixlen;
2695 + *key = node->p.u.prefix4.s_addr;
2696 + route_unlock_node(node);
2697 + return MPLS_SUCCESS;
2699 + return MPLS_FAILURE;
2702 +mpls_return_enum mpls_tree_getnext(mpls_tree_handle tree, uint32_t * key,
2703 + int *length, void **info)
2705 + struct route_node *node;
2706 + struct prefix p;
2708 + p.family = AF_INET;
2709 + p.prefixlen = *length;
2710 + p.u.prefix4.s_addr = *key;
2712 + if (!(node = route_node_match(tree,&p))) {
2713 + return MPLS_FAILURE;
2716 + if ((node = route_next(node))) {
2717 + *info = node->info;
2718 + *length = node->p.prefixlen;
2719 + *key = node->p.u.prefix4.s_addr;
2720 + route_unlock_node(node);
2721 + return MPLS_SUCCESS;
2723 + return MPLS_FAILURE;
2725 diff --exclude=.p4config -uNr zebra/mplsd/l2cc_interface.c zebra-ldp/mplsd/l2cc_interface.c
2726 --- zebra/mplsd/l2cc_interface.c 1969-12-31 18:00:00.000000000 -0600
2727 +++ zebra-ldp/mplsd/l2cc_interface.c 2003-03-29 01:12:02.000000000 -0600
2728 @@ -0,0 +1,106 @@
2729 +#include <zebra.h>
2730 +#include "memory.h"
2732 +#include "ldp.h"
2733 +#include "ldp_cfg.h"
2734 +#include "ldp_struct.h"
2736 +#include "mpls.h"
2737 +#include "mpls_interface.h"
2739 +struct l2cc_interface *l2cc_if_new(struct mpls_interface *mi) {
2740 + struct l2cc_interface *li;
2742 + li = XMALLOC(MTYPE_MPLS_LDP, sizeof(struct l2cc_interface));
2743 + memset(li, 0, sizeof(struct l2cc_interface));
2744 + li->mi = mi;
2746 + li->admin_up = MPLS_BOOL_TRUE;
2747 + li->create_on_hold = MPLS_BOOL_FALSE;
2749 + return li;
2752 +void l2cc_if_free(struct l2cc_interface *li) {
2753 + XFREE(MTYPE_MPLS_LDP, li);
2756 +void l2cc_interface_create(struct mpls_interface *mi) {
2757 + struct ldp *ldp = mi->mpls->ldp;
2759 + mi->l2cc->create_on_hold = MPLS_BOOL_FALSE;
2760 + mi->l2cc->l2cc.admin_state = MPLS_ADMIN_DISABLE;
2762 + ldp_cfg_l2cc_set(ldp->h, &mi->l2cc->l2cc,
2763 + LDP_CFG_ADD | LDP_L2CC_CFG_PEER_ADDR |
2764 + LDP_ENTITY_CFG_ADMIN_STATE | LDP_L2CC_CFG_FEC);
2766 + ldp_cfg_l2cc_get(ldp->h, &mi->l2cc->l2cc, 0xFFFFFFFF);
2768 + l2cc_interface_admin_state_finish(mi);
2771 +void l2cc_interface_delete(struct mpls_interface *mi) {
2772 + struct ldp *ldp = mi->mpls->ldp;
2774 + mi->l2cc->create_on_hold = MPLS_BOOL_TRUE;
2775 + mi->l2cc->l2cc.admin_state = MPLS_ADMIN_DISABLE;
2777 + if (ldp) {
2778 + l2cc_interface_admin_state_start(mi);
2779 + ldp_cfg_l2cc_set(ldp->h, &mi->l2cc->l2cc, LDP_CFG_DEL);
2781 + mi->l2cc->l2cc.index = 0;
2784 +int l2cc_interface_startup(struct mpls_interface *mi) {
2785 + struct ldp *ldp = mi->mpls->ldp;
2787 + if (!mi->l2cc->l2cc.index) {
2788 + return MPLS_FAILURE;
2791 + mi->l2cc->l2cc.admin_state = MPLS_ADMIN_ENABLE;
2792 + ldp_cfg_l2cc_set(ldp->h, &mi->l2cc->l2cc, LDP_L2CC_CFG_ADMIN_STATE);
2794 + return MPLS_SUCCESS;
2797 +int l2cc_interface_shutdown(struct mpls_interface *mi) {
2798 + struct ldp *ldp = mi->mpls->ldp;
2800 + if (!mi->l2cc->l2cc.index) {
2801 + return MPLS_FAILURE;
2804 + mi->l2cc->l2cc.admin_state = MPLS_ADMIN_DISABLE;
2805 + ldp_cfg_l2cc_set(ldp->h, &mi->l2cc->l2cc, LDP_L2CC_CFG_ADMIN_STATE);
2807 + return MPLS_SUCCESS;
2810 +int l2cc_interface_admin_state_start(struct mpls_interface *mi) {
2811 + if (mi->l2cc->admin_up == MPLS_BOOL_TRUE && mpls_if_is_up(mi)) {
2812 + return l2cc_interface_shutdown(mi);
2814 + return MPLS_SUCCESS;
2817 +int l2cc_interface_admin_state_finish(struct mpls_interface *mi) {
2818 + if (mi->l2cc->admin_up == MPLS_BOOL_TRUE && mpls_if_is_up(mi)) {
2819 + return l2cc_interface_startup(mi);
2821 + return MPLS_SUCCESS;
2824 +void l2cc_if_up(struct mpls_interface *mi) {
2825 + if (mi->l2cc && mi->l2cc->admin_up == MPLS_BOOL_TRUE) {
2826 + l2cc_interface_startup(mi);
2830 +void l2cc_if_down(struct mpls_interface *mi) {
2831 + if (mi->l2cc && mi->l2cc->admin_up == MPLS_BOOL_TRUE) {
2832 + l2cc_interface_shutdown(mi);
2835 diff --exclude=.p4config -uNr zebra/mplsd/l2cc_interface.h zebra-ldp/mplsd/l2cc_interface.h
2836 --- zebra/mplsd/l2cc_interface.h 1969-12-31 18:00:00.000000000 -0600
2837 +++ zebra-ldp/mplsd/l2cc_interface.h 2003-03-29 01:12:02.000000000 -0600
2838 @@ -0,0 +1,30 @@
2839 +#ifndef L2CC_IF_H
2840 +#define L2CC_IF_H
2842 +#include "ldp_struct.h"
2844 +struct mpls_interface;
2846 +struct l2cc_interface {
2847 + struct mpls_interface *mi;
2848 + ldp_l2cc l2cc;
2849 + mpls_bool admin_up;
2850 + mpls_bool create_on_hold;
2853 +struct l2cc_interface *l2cc_if_new(struct mpls_interface *mi);
2854 +void l2cc_if_free(struct l2cc_interface *li);
2856 +void l2cc_if_up(struct mpls_interface *mi);
2857 +void l2cc_if_down(struct mpls_interface *mi);
2859 +int l2cc_interface_startup(struct mpls_interface *mi);
2860 +int l2cc_interface_shutdown(struct mpls_interface *mi);
2862 +void l2cc_interface_create(struct mpls_interface *mi);
2863 +void l2cc_interface_delete(struct mpls_interface *mi);
2864 +int l2cc_interface_admin_state_start(struct mpls_interface *mi);
2865 +int l2cc_interface_admin_state_finish(struct mpls_interface *mi);
2868 +#endif
2869 diff --exclude=.p4config -uNr zebra/mplsd/ldp.c zebra-ldp/mplsd/ldp.c
2870 --- zebra/mplsd/ldp.c 1969-12-31 18:00:00.000000000 -0600
2871 +++ zebra-ldp/mplsd/ldp.c 2003-03-29 01:12:02.000000000 -0600
2872 @@ -0,0 +1,141 @@
2873 +#include <zebra.h>
2875 +#include "memory.h"
2876 +#include "log.h"
2878 +#include "ldp.h"
2879 +#include "ldp_cfg.h"
2880 +#include "ldp_struct.h"
2881 +#include "ldp_interface.h"
2883 +#include "mpls.h"
2884 +#include "mpls_interface.h"
2886 +int ldp_shutdown(struct ldp *ldp) {
2887 + ldp_global g;
2889 + g.admin_state = MPLS_ADMIN_DISABLE;
2890 + return ldp_cfg_global_set(ldp->h,&g,LDP_GLOBAL_CFG_ADMIN_STATE);
2893 +int ldp_startup(struct ldp *ldp) {
2894 + ldp_global g;
2896 + g.admin_state = MPLS_ADMIN_ENABLE;
2897 + return ldp_cfg_global_set(ldp->h,&g,LDP_GLOBAL_CFG_ADMIN_STATE);
2900 +int ldp_admin_state_start(struct ldp *ldp) {
2901 + if (ldp->admin_up == MPLS_BOOL_TRUE) {
2902 + return ldp_shutdown(ldp);
2904 + return MPLS_SUCCESS;
2907 +int ldp_admin_state_finish(struct ldp *ldp) {
2908 + if (ldp->admin_up == MPLS_BOOL_TRUE) {
2909 + return ldp_startup(ldp);
2911 + return MPLS_SUCCESS;
2914 +int do_ldp_router_id_update(struct ldp *ldp, unsigned int router_id) {
2915 + ldp_global g;
2916 + g.lsr_identifier.type = MPLS_FAMILY_IPV4;
2917 + g.lsr_identifier.u.ipv4 = router_id;
2918 + g.transport_address.type = MPLS_FAMILY_IPV4;
2919 + g.transport_address.u.ipv4 = router_id;
2920 + return ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LSR_IDENTIFIER|LDP_GLOBAL_CFG_TRANS_ADDR);
2923 +int ldp_router_id_update(struct ldp *ldp, struct prefix *router_id) {
2925 + zlog_info("router-id update %s", inet_ntoa(router_id->u.prefix4));
2927 + if (!ldp->lsr_id_is_static) {
2928 + ldp_admin_state_start(ldp);
2930 + do_ldp_router_id_update(ldp, ntohl(router_id->u.prefix4.s_addr));
2932 + ldp_admin_state_finish(ldp);
2934 + return 0;
2937 +static struct ldp *ldp_new(struct mpls *mpls) {
2938 + struct ldp *new = XMALLOC(MTYPE_MPLS_LDP, sizeof(struct ldp));
2939 + ldp_global g;
2941 + memset(new,0,sizeof(*new));
2943 + new->h = ldp_cfg_open(new);
2944 + new->admin_up = MPLS_BOOL_TRUE;
2945 + new->lsr_id_is_static = 0;
2946 + new->mpls = mpls;
2947 + new->egress = LDP_EGRESS_CONNECTED;
2948 + new->address = LDP_ADDRESS_ALL;
2949 + new->peer_list = list_new();
2951 + g.lsr_identifier.type = MPLS_FAMILY_IPV4;
2952 + g.lsr_identifier.u.ipv4 = ntohl(mpls->router_id.u.prefix4.s_addr);
2953 + g.transport_address.type = MPLS_FAMILY_IPV4;
2954 + g.transport_address.u.ipv4 = ntohl(mpls->router_id.u.prefix4.s_addr);
2955 + g.admin_state = MPLS_ADMIN_ENABLE;
2956 +#if MPLS_USE_LSR
2957 + g.lsr_handle = mpls->h;
2958 +#endif
2959 + ldp_cfg_global_set(new->h,&g,
2960 + LDP_GLOBAL_CFG_LSR_IDENTIFIER|LDP_GLOBAL_CFG_LSR_HANDLE|
2961 + LDP_GLOBAL_CFG_ADMIN_STATE|LDP_GLOBAL_CFG_TRANS_ADDR);
2963 + return new;
2966 +struct ldp *ldp_get() {
2967 + struct mpls_interface *mi;
2968 + struct interface *ifp;
2969 + listnode node;
2971 + struct mpls *mpls = mpls_get();
2972 + if (mpls->ldp) {
2973 + return mpls->ldp;
2976 + mpls->ldp = ldp_new(mpls);
2977 + for (node = listhead(mpls->iflist); node; nextnode(node)) {
2978 + ifp = getdata(node);
2979 + mi = (struct mpls_interface*)ifp->info;
2980 + if (mi->ldp && mi->ldp->create_on_hold == MPLS_BOOL_TRUE) {
2981 + ldp_interface_create(mi);
2983 + if (mi->l2cc && mi->l2cc->create_on_hold == MPLS_BOOL_TRUE) {
2984 + l2cc_interface_create(mi);
2988 + return mpls->ldp;
2991 +void ldp_finish(struct ldp *ldp) {
2992 + struct mpls *mpls = ldp->mpls;
2993 + struct interface *ifp;
2994 + struct mpls_interface *mi;
2995 + listnode node;
2997 + for (node = listhead(mpls->iflist); node; nextnode(node)) {
2998 + ifp = getdata(node);
2999 + mi = (struct mpls_interface*)ifp->info;
3000 + if (mi->ldp && mi->ldp->entity.index) {
3001 + ldp_interface_delete(mi);
3003 + if (mi->l2cc && mi->l2cc->l2cc.index) {
3004 + l2cc_interface_delete(mi);
3008 + ldp_admin_state_start(ldp);
3009 + ldp_cfg_close(ldp->h);
3010 + XFREE(MTYPE_MPLS_LDP,ldp);
3011 + mpls->ldp = NULL;
3012 + list_free(ldp->peer_list);
3014 diff --exclude=.p4config -uNr zebra/mplsd/ldp.h zebra-ldp/mplsd/ldp.h
3015 --- zebra/mplsd/ldp.h 1969-12-31 18:00:00.000000000 -0600
3016 +++ zebra-ldp/mplsd/ldp.h 2003-03-29 01:12:02.000000000 -0600
3017 @@ -0,0 +1,42 @@
3018 +#ifndef LDP_H
3019 +#define LDP_H
3021 +#include <zebra.h>
3022 +#include "prefix.h"
3024 +#include "ldp_struct.h"
3026 +struct mpls;
3028 +typedef enum {
3029 + LDP_EGRESS_ALL,
3030 + LDP_EGRESS_LSRID,
3031 + LDP_EGRESS_CONNECTED
3032 +} ldp_egress_mode;
3034 +typedef enum {
3035 + LDP_ADDRESS_ALL,
3036 + LDP_ADDRESS_LSRID,
3037 + LDP_ADDRESS_LDP
3038 +} ldp_address_mode;
3040 +struct ldp {
3041 + struct mpls *mpls;
3042 + struct list *peer_list;
3043 + mpls_cfg_handle h;
3044 + mpls_bool admin_up;
3045 + mpls_bool lsr_id_is_static;
3046 + ldp_egress_mode egress;
3047 + ldp_address_mode address;
3050 +struct ldp *ldp_get();
3051 +void ldp_init();
3052 +int ldp_router_id_update(struct ldp *ldp, struct prefix *router_id);
3053 +int do_ldp_router_id_update(struct ldp *ldp, unsigned int router_id);
3054 +void ldp_finish(struct ldp *ldp);
3056 +int ldp_admin_state_start(struct ldp *ldp);
3057 +int ldp_admin_state_finish(struct ldp *ldp);
3059 +#endif
3060 diff --exclude=.p4config -uNr zebra/mplsd/ldp_interface.c zebra-ldp/mplsd/ldp_interface.c
3061 --- zebra/mplsd/ldp_interface.c 1969-12-31 18:00:00.000000000 -0600
3062 +++ zebra-ldp/mplsd/ldp_interface.c 2003-03-29 01:12:02.000000000 -0600
3063 @@ -0,0 +1,119 @@
3064 +#include <zebra.h>
3065 +#include "memory.h"
3067 +#include "ldp.h"
3068 +#include "ldp_cfg.h"
3069 +#include "ldp_struct.h"
3071 +#include "mpls.h"
3072 +#include "mpls_interface.h"
3074 +struct ldp_interface *ldp_if_new(struct mpls_interface *mi) {
3075 + struct ldp_interface *li;
3077 + li = XMALLOC(MTYPE_MPLS_LDP, sizeof(struct ldp_interface));
3078 + memset(li, 0, sizeof(struct ldp_interface));
3079 + li->mi = mi;
3081 + li->admin_up = MPLS_BOOL_TRUE;
3082 + li->create_on_hold = MPLS_BOOL_FALSE;
3083 + ldp_entity_set_defaults(&li->entity);
3085 + return li;
3088 +void ldp_if_free(struct ldp_interface *li) {
3089 + XFREE(MTYPE_MPLS_LDP, li);
3092 +void ldp_interface_create(struct mpls_interface *mi) {
3093 + struct ldp *ldp = mi->mpls->ldp;
3095 + mi->ldp->create_on_hold = MPLS_BOOL_FALSE;
3097 + strncpy(mi->ldp->iff.name,mi->ifp->name,IFNAMSIZ);
3098 + mi->ldp->iff.label_space = mi->labelspace;
3100 + ldp_cfg_if_set(ldp->h, &mi->ldp->iff, LDP_CFG_ADD | LDP_IF_CFG_LABEL_SPACE);
3102 + mi->ldp->entity.sub_index = mi->ldp->iff.index;
3103 + mi->ldp->entity.entity_type = LDP_DIRECT;
3104 + mi->ldp->entity.admin_state = MPLS_ADMIN_DISABLE;
3105 + mi->ldp->entity.transport_address.type = MPLS_FAMILY_NONE;
3107 + ldp_cfg_entity_set(ldp->h, &mi->ldp->entity,
3108 + LDP_CFG_ADD | LDP_ENTITY_CFG_SUB_INDEX |
3109 + LDP_ENTITY_CFG_ADMIN_STATE | LDP_ENTITY_CFG_TRANS_ADDR);
3111 + ldp_cfg_entity_get(ldp->h, &mi->ldp->entity, 0xFFFFFFFF);
3112 + ldp_cfg_if_get(ldp->h, &mi->ldp->iff, 0xFFFFFFFF);
3114 + ldp_interface_admin_state_finish(mi);
3117 +void ldp_interface_delete(struct mpls_interface *mi) {
3118 + struct ldp *ldp = mi->mpls->ldp;
3120 + mi->ldp->create_on_hold = MPLS_BOOL_TRUE;
3121 + mi->ldp->entity.admin_state = MPLS_ADMIN_DISABLE;
3123 + if (ldp) {
3124 + ldp_interface_admin_state_start(mi);
3125 + ldp_cfg_entity_set(ldp->h, &mi->ldp->entity, LDP_CFG_DEL);
3126 + ldp_cfg_if_set(ldp->h, &mi->ldp->iff, LDP_CFG_DEL);
3128 + mi->ldp->entity.index = 0;
3129 + mi->ldp->iff.index = 0;
3132 +int ldp_interface_startup(struct mpls_interface *mi) {
3133 + struct ldp *ldp = mi->mpls->ldp;
3135 + if (!mi->ldp->iff.index) {
3136 + return MPLS_FAILURE;
3139 + mi->ldp->entity.admin_state = MPLS_ADMIN_ENABLE;
3140 + ldp_cfg_entity_set(ldp->h, &mi->ldp->entity, LDP_ENTITY_CFG_ADMIN_STATE);
3142 + return MPLS_SUCCESS;
3145 +int ldp_interface_shutdown(struct mpls_interface *mi) {
3146 + struct ldp *ldp = mi->mpls->ldp;
3148 + if (!mi->ldp->iff.index) {
3149 + return MPLS_FAILURE;
3152 + mi->ldp->entity.admin_state = MPLS_ADMIN_DISABLE;
3153 + ldp_cfg_entity_set(ldp->h, &mi->ldp->entity, LDP_ENTITY_CFG_ADMIN_STATE);
3155 + return MPLS_SUCCESS;
3158 +int ldp_interface_admin_state_start(struct mpls_interface *mi) {
3159 + if (mi->ldp->admin_up == MPLS_BOOL_TRUE && mpls_if_is_up(mi)) {
3160 + return ldp_interface_shutdown(mi);
3162 + return MPLS_SUCCESS;
3165 +int ldp_interface_admin_state_finish(struct mpls_interface *mi) {
3166 + if (mi->ldp->admin_up == MPLS_BOOL_TRUE && mpls_if_is_up(mi)) {
3167 + return ldp_interface_startup(mi);
3169 + return MPLS_SUCCESS;
3172 +void ldp_if_up(struct mpls_interface *mi) {
3173 + if (mi->ldp && mi->ldp->admin_up == MPLS_BOOL_TRUE) {
3174 + ldp_interface_startup(mi);
3178 +void ldp_if_down(struct mpls_interface *mi) {
3179 + if (mi->ldp && mi->ldp->admin_up == MPLS_BOOL_TRUE) {
3180 + ldp_interface_shutdown(mi);
3183 diff --exclude=.p4config -uNr zebra/mplsd/ldp_interface.h zebra-ldp/mplsd/ldp_interface.h
3184 --- zebra/mplsd/ldp_interface.h 1969-12-31 18:00:00.000000000 -0600
3185 +++ zebra-ldp/mplsd/ldp_interface.h 2003-03-29 01:12:02.000000000 -0600
3186 @@ -0,0 +1,31 @@
3187 +#ifndef LDP_IF_H
3188 +#define LDP_IF_H
3190 +#include "ldp_struct.h"
3192 +struct mpls_interface;
3194 +struct ldp_interface {
3195 + struct mpls_interface *mi;
3196 + ldp_entity entity;
3197 + ldp_if iff;
3198 + mpls_bool admin_up;
3199 + mpls_bool create_on_hold;
3202 +struct ldp_interface *ldp_if_new(struct mpls_interface *mi);
3203 +void ldp_if_free(struct ldp_interface *li);
3205 +void ldp_if_up(struct mpls_interface *mi);
3206 +void ldp_if_down(struct mpls_interface *mi);
3208 +int ldp_interface_startup(struct mpls_interface *mi);
3209 +int ldp_interface_shutdown(struct mpls_interface *mi);
3211 +void ldp_interface_create(struct mpls_interface *mi);
3212 +void ldp_interface_delete(struct mpls_interface *mi);
3213 +int ldp_interface_admin_state_start(struct mpls_interface *mi);
3214 +int ldp_interface_admin_state_finish(struct mpls_interface *mi);
3217 +#endif
3218 diff --exclude=.p4config -uNr zebra/mplsd/ldp_remote_peer.c zebra-ldp/mplsd/ldp_remote_peer.c
3219 --- zebra/mplsd/ldp_remote_peer.c 1969-12-31 18:00:00.000000000 -0600
3220 +++ zebra-ldp/mplsd/ldp_remote_peer.c 2003-03-29 01:12:02.000000000 -0600
3221 @@ -0,0 +1,131 @@
3222 +#include <zebra.h>
3223 +#include "memory.h"
3225 +#include "ldp.h"
3226 +#include "ldp_cfg.h"
3227 +#include "ldp_struct.h"
3228 +#include "mpls_compare.h"
3230 +#include "mpls.h"
3231 +#include "ldp_remote_peer.h"
3233 +struct ldp_remote_peer *ldp_remote_peer_find(struct ldp *ldp,
3234 + struct mpls_dest *dest) {
3235 + struct ldp_remote_peer *rp;
3236 + struct listnode *ln;
3238 + LIST_LOOP(ldp->peer_list,rp,ln) {
3239 + rp->peer.dest.if_handle = 0;
3240 + dest->if_handle = 0;
3241 + if (!mpls_dest_compare(&rp->peer.dest,dest)) {
3242 + return rp;
3245 + return NULL;
3248 +struct ldp_remote_peer *ldp_remote_peer_new(struct ldp *ldp) {
3249 + struct ldp_remote_peer *rp;
3251 + rp = XMALLOC(MTYPE_MPLS_LDP, sizeof(struct ldp_remote_peer));
3252 + memset(rp, 0, sizeof(struct ldp_remote_peer));
3253 + rp->ldp = ldp;
3255 + rp->admin_up = MPLS_BOOL_TRUE;
3256 + ldp_entity_set_defaults(&rp->entity);
3258 + return rp;
3261 +void ldp_remote_peer_free(struct ldp_remote_peer *rp) {
3262 + XFREE(MTYPE_MPLS_LDP, rp);
3265 +void ldp_remote_peer_create(struct ldp_remote_peer *rp,
3266 + struct mpls_dest *dest) {
3267 + struct in_addr addr;
3268 + char *dest_name;
3270 + addr.s_addr = htonl(dest->addr.u.ipv4);
3271 + dest_name = inet_ntoa(addr);
3272 + strncpy(rp->peer.peer_name,dest_name,IFNAMSIZ);
3273 + rp->peer.label_space = 0;
3274 + memcpy(&rp->peer.dest,dest,sizeof(struct mpls_dest));
3276 + ldp_cfg_peer_set(rp->ldp->h, &rp->peer, LDP_CFG_ADD |
3277 + LDP_IF_CFG_LABEL_SPACE | LDP_PEER_CFG_DEST_ADDR | LDP_PEER_CFG_PEER_NAME);
3279 + rp->entity.sub_index = rp->peer.index;
3280 + rp->entity.entity_type = LDP_INDIRECT;
3281 + rp->entity.admin_state = MPLS_OPER_DOWN;
3282 + rp->entity.transport_address.type = MPLS_FAMILY_NONE;
3284 + ldp_cfg_entity_set(rp->ldp->h, &rp->entity,
3285 + LDP_CFG_ADD | LDP_ENTITY_CFG_SUB_INDEX |
3286 + LDP_ENTITY_CFG_ADMIN_STATE | LDP_ENTITY_CFG_TRANS_ADDR);
3288 + ldp_cfg_entity_get(rp->ldp->h, &rp->entity, 0xFFFFFFFF);
3289 + ldp_cfg_peer_get(rp->ldp->h, &rp->peer, 0xFFFFFFFF);
3291 + ldp_remote_peer_admin_state_finish(rp);
3294 +void ldp_remote_peer_delete(struct ldp_remote_peer *rp) {
3295 + rp->entity.admin_state = MPLS_OPER_DOWN;
3297 + if (rp->ldp) {
3298 + ldp_remote_peer_admin_state_start(rp);
3299 + ldp_cfg_entity_set(rp->ldp->h, &rp->entity, LDP_CFG_DEL);
3300 + ldp_cfg_peer_set(rp->ldp->h, &rp->peer, LDP_CFG_DEL);
3302 + rp->entity.index = 0;
3303 + rp->peer.index = 0;
3306 +int ldp_remote_peer_startup(struct ldp_remote_peer *rp) {
3307 + if (!rp->peer.index) {
3308 + return MPLS_FAILURE;
3311 + rp->entity.admin_state = MPLS_OPER_UP;
3312 + ldp_cfg_entity_set(rp->ldp->h, &rp->entity, LDP_ENTITY_CFG_ADMIN_STATE);
3314 + return MPLS_SUCCESS;
3317 +int ldp_remote_peer_shutdown(struct ldp_remote_peer *rp) {
3318 + if (!rp->peer.index) {
3319 + return MPLS_FAILURE;
3322 + rp->entity.admin_state = MPLS_ADMIN_DISABLE;
3323 + ldp_cfg_entity_set(rp->ldp->h, &rp->entity, LDP_ENTITY_CFG_ADMIN_STATE);
3325 + return MPLS_SUCCESS;
3328 +int ldp_remote_peer_admin_state_start(struct ldp_remote_peer *rp) {
3329 + if (rp->admin_up == MPLS_BOOL_TRUE) {
3330 + return ldp_remote_peer_shutdown(rp);
3332 + return MPLS_SUCCESS;
3335 +int ldp_remote_peer_admin_state_finish(struct ldp_remote_peer *rp) {
3336 + if (rp->admin_up == MPLS_BOOL_TRUE) {
3337 + return ldp_remote_peer_startup(rp);
3339 + return MPLS_SUCCESS;
3342 +void ldp_remote_peer_up(struct ldp_remote_peer *rp) {
3343 + if (rp->ldp && rp->admin_up == MPLS_BOOL_TRUE) {
3344 + ldp_remote_peer_startup(rp);
3348 +void ldp_remote_peer_down(struct ldp_remote_peer *rp) {
3349 + if (rp->ldp && rp->admin_up == MPLS_BOOL_TRUE) {
3350 + ldp_remote_peer_shutdown(rp);
3353 diff --exclude=.p4config -uNr zebra/mplsd/ldp_remote_peer.h zebra-ldp/mplsd/ldp_remote_peer.h
3354 --- zebra/mplsd/ldp_remote_peer.h 1969-12-31 18:00:00.000000000 -0600
3355 +++ zebra-ldp/mplsd/ldp_remote_peer.h 2003-03-29 01:12:02.000000000 -0600
3356 @@ -0,0 +1,28 @@
3357 +#ifndef LDP_REMOTE_PEER_H
3358 +#define LDP_REMOTE_PEER_H
3360 +#include "ldp_struct.h"
3362 +struct ldp_remote_peer {
3363 + struct ldp *ldp;
3364 + ldp_entity entity;
3365 + ldp_peer peer;
3366 + mpls_bool admin_up;
3369 +struct ldp_remote_peer *ldp_remote_peer_find(struct ldp*, struct mpls_dest*);
3370 +struct ldp_remote_peer *ldp_remote_peer_new(struct ldp *ldp);
3371 +void ldp_remote_peer_free(struct ldp_remote_peer *rp);
3373 +void ldp_remote_peer_up(struct ldp_remote_peer *rp);
3374 +void ldp_remote_peer_down(struct ldp_remote_peer *rp);
3376 +int ldp_remote_peer_startup(struct ldp_remote_peer *rp);
3377 +int ldp_remote_peer_shutdown(struct ldp_remote_peer *rp);
3379 +void ldp_remote_peer_create(struct ldp_remote_peer*, struct mpls_dest*);
3380 +void ldp_remote_peer_delete(struct ldp_remote_peer *rp);
3381 +int ldp_remote_peer_admin_state_start(struct ldp_remote_peer *rp);
3382 +int ldp_remote_peer_admin_state_finish(struct ldp_remote_peer *rp);
3384 +#endif
3385 diff --exclude=.p4config -uNr zebra/mplsd/ldp_vty.c zebra-ldp/mplsd/ldp_vty.c
3386 --- zebra/mplsd/ldp_vty.c 1969-12-31 18:00:00.000000000 -0600
3387 +++ zebra-ldp/mplsd/ldp_vty.c 2003-03-29 01:12:03.000000000 -0600
3388 @@ -0,0 +1,2180 @@
3389 +#include <zebra.h>
3391 +#include "ldp.h"
3392 +#include "ldp_cfg.h"
3393 +#include "ldp_struct.h"
3394 +#include "ldp_interface.h"
3395 +#include "ldp_remote_peer.h"
3397 +#include "impl_mpls.h"
3399 +#include "mpls.h"
3400 +#include "mpls_interface.h"
3401 +#include "mpls_vty.h"
3403 +#include "command.h"
3404 +#include "zclient.h"
3405 +#include "vty.h"
3407 +uint32_t ldp_traceflags = 0;
3408 +uint8_t trace_buffer[16834];
3409 +int trace_buffer_len = 0;
3411 +char *session_state[6] = { "NONE", "NON-EXIST", "INIT",
3412 + "OPENSENT", "OPENRECV", "OPERATIONAL" };
3413 +char *adj_role[3] = { "INVALID", "PASSIVE", "ACTIVE" };
3414 +char *attr_state[12] = { "REQ_RECV", "REQ_SENT", "MAP_RECV", "MAP_SENT",
3415 + "WITH_SENT", "WITH_RECV", "NO_LABEL_RESOURCE_SENT",
3416 + "NO_LABEL_RESOURCE_RECV", "ABORT_SENT", "ABORT_RECV",
3417 + "NOTIF_SENT", "NOTIF_RECV" };
3418 +char *oper_state[2] = { "UP", "DOWN" };
3419 +char *control_mode[3] = { "UNKNOWN", "INDEPENDENT", "ORDERED" };
3420 +char *retention_mode[3] = { "UNKNOWN", "LIBERAL", "CONSERVATIVE" };
3421 +char *repair_mode[3] = { "UNKNOWN", "LOCAL", "GLOBAL" };
3422 +char *loop_detect_mode[5] = { "NONE", "HOPCOUNT", "PATHVECTOR",
3423 + "HOPCOUNT PATHVECTOR", "OTHER" };
3424 +char *bool[2] = { "FALSE", "TRUE" };
3425 +char *admin_state[3] = { "NONE", "ENABLED", "DISABLED" };
3426 +char *distribution_mode[2] = { "UNSOLICITED", "ONDEMAND" };
3428 +extern struct zclient *zclient;
3430 +DEFUN (mpls_ldp,
3431 + mpls_ldp_cmd,
3432 + "mpls ldp",
3433 + "MPLS configuration\n"
3434 + "Start LDP configuration\n") {
3436 + vty->node = MPLS_LDP_NODE;
3437 + vty->index = ldp_get();
3439 + return CMD_SUCCESS;
3442 +DEFUN (no_mpls_ldp,
3443 + no_mpls_ldp_cmd,
3444 + "no mpls ldp",
3445 + NO_STR
3446 + "MPLS configuration\n"
3447 + "Global LDP configuration\n") {
3448 + struct mpls *mpls = mpls_get();
3450 + if (!mpls->ldp) {
3451 + vty_out (vty, "There isn't active an LDP instance.%s", VTY_NEWLINE);
3452 + return CMD_WARNING;
3455 + ldp_finish(mpls->ldp);
3456 + return CMD_SUCCESS;
3459 +DEFUN (mpls_ldp_lsrid,
3460 + mpls_ldp_lsrid_cmd,
3461 + "lsr-id A.B.C.D",
3462 + "LDP Label Switch Router Identifier\n"
3463 + "IP Address\n") {
3464 + struct ldp *ldp = (struct ldp*)vty->index;
3466 + ldp->lsr_id_is_static = MPLS_BOOL_TRUE;
3468 + ldp_admin_state_start(ldp);
3469 + do_ldp_router_id_update(ldp, ntohl(inet_addr(argv[0])));
3470 + ldp_admin_state_finish(ldp);
3472 + return CMD_SUCCESS;
3475 +DEFUN (no_mpls_ldp_lsrid,
3476 + no_mpls_ldp_lsrid_cmd,
3477 + "no lsr-id",
3478 + NO_STR
3479 + "LDP LSRID\n") {
3480 + struct ldp *ldp = (struct ldp*)vty->index;
3482 + ldp->lsr_id_is_static = MPLS_BOOL_FALSE;
3484 + ldp_admin_state_start(ldp);
3485 + do_ldp_router_id_update(ldp, ntohl(ldp->mpls->router_id.u.prefix4.s_addr));
3486 + ldp_admin_state_finish(ldp);
3488 + return CMD_SUCCESS;
3491 +DEFUN (mpls_ldp_disable,
3492 + mpls_ldp_disable_cmd,
3493 + "disable",
3494 + "Disable\n") {
3495 + struct ldp *ldp = (struct ldp*)vty->index;
3497 + ldp_admin_state_start(ldp);
3498 + ldp->admin_up = MPLS_BOOL_FALSE;
3499 + ldp_admin_state_finish(ldp);
3501 + return CMD_SUCCESS;
3504 +DEFUN (no_mpls_ldp_disable,
3505 + no_mpls_ldp_disable_cmd,
3506 + "no disable",
3507 + NO_STR
3508 + "Disable\n") {
3509 + struct ldp *ldp = (struct ldp*)vty->index;
3511 + ldp_admin_state_start(ldp);
3512 + ldp->admin_up = MPLS_BOOL_TRUE;
3513 + ldp_admin_state_finish(ldp);
3515 + return CMD_SUCCESS;
3518 +DEFUN (mpls_ldp_lsp_control_mode,
3519 + mpls_ldp_lsp_control_mode_cmd,
3520 + "lsp-control-mode (independent|ordered)",
3521 + "control mode\n"
3522 + "independent or ordered control mode\n") {
3523 + struct ldp *ldp = (struct ldp*)vty->index;
3524 + ldp_global g;
3526 + if (!strcmp(argv[0],"independent")) {
3527 + g.lsp_control_mode = LDP_CONTROL_INDEPENDENT;
3528 + } else if (!strcmp(argv[0],"ordered")) {
3529 + g.lsp_control_mode = LDP_CONTROL_ORDERED;
3530 + } else {
3531 + return CMD_WARNING;
3534 + ldp_admin_state_start(ldp);
3535 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_CONTROL_MODE);
3536 + ldp_admin_state_finish(ldp);
3538 + return CMD_SUCCESS;
3541 +DEFUN (no_mpls_ldp_lsp_control_mode,
3542 + no_mpls_ldp_lsp_control_mode_cmd,
3543 + "no lsp-control-mode",
3544 + NO_STR
3545 + "control mode\n") {
3546 + struct ldp *ldp = (struct ldp*)vty->index;
3547 + ldp_global g;
3549 + g.lsp_control_mode = LDP_GLOBAL_DEF_CONTROL_MODE;
3551 + ldp_admin_state_start(ldp);
3552 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_CONTROL_MODE);
3553 + ldp_admin_state_finish(ldp);
3555 + return CMD_SUCCESS;
3558 +DEFUN (mpls_ldp_label_retention_mode,
3559 + mpls_ldp_label_retention_mode_cmd,
3560 + "label-retention-mode (liberal|conservative)",
3561 + "label retention mode\n"
3562 + "liberal or conservative retention mode\n") {
3563 + struct ldp *ldp = (struct ldp*)vty->index;
3564 + ldp_global g;
3566 + if (!strcmp(argv[0],"liberal")) {
3567 + g.label_retention_mode = LDP_RETENTION_LIBERAL;
3568 + } else if (!strcmp(argv[0],"conservative")) {
3569 + g.label_retention_mode = LDP_RETENTION_CONSERVATIVE;
3570 + } else {
3571 + return CMD_WARNING;
3574 + ldp_admin_state_start(ldp);
3575 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_RETENTION_MODE);
3576 + ldp_admin_state_finish(ldp);
3578 + return CMD_SUCCESS;
3581 +DEFUN (no_mpls_ldp_label_retention_mode,
3582 + no_mpls_ldp_label_retention_mode_cmd,
3583 + "no label-retention-mode",
3584 + NO_STR
3585 + "label retiontion mode\n") {
3586 + struct ldp *ldp = (struct ldp*)vty->index;
3587 + ldp_global g;
3589 + g.label_retention_mode = LDP_GLOBAL_DEF_RETENTION_MODE;
3591 + ldp_admin_state_start(ldp);
3592 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_RETENTION_MODE);
3593 + ldp_admin_state_finish(ldp);
3595 + return CMD_SUCCESS;
3598 +DEFUN (mpls_ldp_lsp_repair_mode,
3599 + mpls_ldp_lsp_repair_mode_cmd,
3600 + "lsp-repair-mode (local|global)",
3601 + "repair mode\n"
3602 + "local or global repair mode\n") {
3603 + struct ldp *ldp = (struct ldp*)vty->index;
3604 + ldp_global g;
3606 + if (!strcmp(argv[0],"local")) {
3607 + g.lsp_repair_mode = LDP_REPAIR_LOCAL;
3608 + } else if (!strcmp(argv[0],"global")) {
3609 + g.lsp_repair_mode = LDP_REPAIR_GLOBAL;
3610 + } else {
3611 + return CMD_WARNING;
3613 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_REPAIR_MODE);
3615 + return CMD_SUCCESS;
3618 +DEFUN (no_mpls_ldp_lsp_repair_mode,
3619 + no_mpls_ldp_lsp_repair_mode_cmd,
3620 + "no lsp-repair-mode",
3621 + NO_STR
3622 + "repair mode\n") {
3623 + struct ldp *ldp = (struct ldp*)vty->index;
3624 + ldp_global g;
3626 + g.lsp_repair_mode = LDP_GLOBAL_DEF_REPAIR_MODE;
3627 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_REPAIR_MODE);
3629 + return CMD_SUCCESS;
3632 +DEFUN (mpls_ldp_propogate_release,
3633 + mpls_ldp_propogate_release_cmd,
3634 + "propagate-release",
3635 + "propagate release\n") {
3636 + struct ldp *ldp = (struct ldp*)vty->index;
3637 + ldp_global g;
3639 + g.propagate_release = MPLS_BOOL_TRUE;
3640 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_PROPOGATE_RELEASE);
3642 + return CMD_SUCCESS;
3645 +DEFUN (no_mpls_ldp_propogate_release,
3646 + no_mpls_ldp_propogate_release_cmd,
3647 + "no propagate-release",
3648 + NO_STR
3649 + "propagate release\n") {
3650 + struct ldp *ldp = (struct ldp*)vty->index;
3651 + ldp_global g;
3653 + g.propagate_release = MPLS_BOOL_FALSE;
3654 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_PROPOGATE_RELEASE);
3656 + return CMD_SUCCESS;
3659 +DEFUN (mpls_ldp_label_merge,
3660 + mpls_ldp_label_merge_cmd,
3661 + "label-merge",
3662 + "label merge\n") {
3663 + struct ldp *ldp = (struct ldp*)vty->index;
3664 + ldp_global g;
3666 + g.label_merge = MPLS_BOOL_TRUE;
3668 + ldp_admin_state_start(ldp);
3669 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LABEL_MERGE);
3670 + ldp_admin_state_finish(ldp);
3672 + return CMD_SUCCESS;
3675 +DEFUN (no_mpls_ldp_label_merge,
3676 + no_mpls_ldp_label_merge_cmd,
3677 + "no label-merge",
3678 + NO_STR
3679 + "label merge\n") {
3680 + struct ldp *ldp = (struct ldp*)vty->index;
3681 + ldp_global g;
3683 + g.label_merge = MPLS_BOOL_FALSE;
3685 + ldp_admin_state_start(ldp);
3686 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LABEL_MERGE);
3687 + ldp_admin_state_finish(ldp);
3689 + return CMD_SUCCESS;
3692 +DEFUN (mpls_ldp_loop_detection_mode,
3693 + mpls_ldp_loop_detection_mode_cmd,
3694 + "loop-detection-mode (hop|path|both)",
3695 + "loop detection\n"
3696 + "Path Vector, Hop Count, or both\n") {
3697 + struct ldp *ldp = (struct ldp*)vty->index;
3698 + ldp_global g;
3700 + if (!strncmp(argv[0],"hop",3)) {
3701 + g.loop_detection_mode = LDP_LOOP_HOPCOUNT;
3702 + } else if (!strncmp(argv[0],"path",4)) {
3703 + g.loop_detection_mode = LDP_LOOP_PATHVECTOR;
3704 + } else if (!strncmp(argv[0],"both",4)) {
3705 + g.loop_detection_mode = LDP_LOOP_HOPCOUNT_PATHVECTOR;
3706 + } else {
3707 + return CMD_WARNING;
3709 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOOP_DETECTION_MODE);
3711 + return CMD_SUCCESS;
3714 +DEFUN (no_mpls_ldp_loop_detection_mode,
3715 + no_mpls_ldp_loop_detection_mode_cmd,
3716 + "no loop-detection-mode (path|hop|both)",
3717 + NO_STR
3718 + "loop detection\n") {
3719 + struct ldp *ldp = (struct ldp*)vty->index;
3720 + ldp_global g;
3722 + g.loop_detection_mode = LDP_LOOP_NONE;
3723 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOOP_DETECTION_MODE);
3725 + return CMD_SUCCESS;
3728 +DEFUN (mpls_ldp_ttl_less_domain,
3729 + mpls_ldp_ttl_less_domain_cmd,
3730 + "ttl-less-domain",
3731 + "TTL-less domain\n") {
3732 + struct ldp *ldp = (struct ldp*)vty->index;
3733 + ldp_global g;
3735 + g.ttl_less_domain = MPLS_BOOL_TRUE;
3736 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_TTLLESS_DOMAIN);
3738 + return CMD_SUCCESS;
3741 +DEFUN (no_mpls_ldp_ttl_less_domain,
3742 + no_mpls_ldp_ttl_less_domain_cmd,
3743 + "no ttl-less-domain",
3744 + NO_STR
3745 + "TTL-less domain\n") {
3746 + struct ldp *ldp = (struct ldp*)vty->index;
3747 + ldp_global g;
3749 + g.ttl_less_domain = MPLS_BOOL_FALSE;
3750 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_TTLLESS_DOMAIN);
3752 + return CMD_SUCCESS;
3755 +DEFUN (mpls_ldp_local_tcp_port,
3756 + mpls_ldp_local_tcp_port_cmd,
3757 + "local-tcp-port <1-65535>",
3758 + "local TCP port\n"
3759 + "TCP port number\n") {
3760 + struct ldp *ldp = (struct ldp*)vty->index;
3761 + ldp_global g;
3763 + g.local_tcp_port = atoi(argv[0]);
3765 + ldp_admin_state_start(ldp);
3766 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOCAL_TCP_PORT);
3767 + ldp_admin_state_finish(ldp);
3769 + return CMD_SUCCESS;
3772 +DEFUN (no_mpls_ldp_local_tcp_port,
3773 + no_mpls_ldp_local_tcp_port_cmd,
3774 + "no local-tcp-port",
3775 + NO_STR
3776 + "local TCP port\n") {
3777 + struct ldp *ldp = (struct ldp*)vty->index;
3778 + ldp_global g;
3780 + g.local_tcp_port = LDP_GLOBAL_DEF_LOCAL_TCP_PORT;
3782 + ldp_admin_state_start(ldp);
3783 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOCAL_TCP_PORT);
3784 + ldp_admin_state_finish(ldp);
3786 + return CMD_SUCCESS;
3789 +DEFUN (mpls_ldp_local_udp_port,
3790 + mpls_ldp_local_udp_port_cmd,
3791 + "local-udp-port <1-65535>",
3792 + "local UDP port\n"
3793 + "UDP port number\n") {
3794 + struct ldp *ldp = (struct ldp*)vty->index;
3795 + ldp_global g;
3797 + g.local_udp_port = atoi(argv[0]);
3799 + ldp_admin_state_start(ldp);
3800 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOCAL_UDP_PORT);
3801 + ldp_admin_state_finish(ldp);
3803 + return CMD_SUCCESS;
3806 +DEFUN (no_mpls_ldp_local_udp_port,
3807 + no_mpls_ldp_local_udp_port_cmd,
3808 + "no local-udp-port",
3809 + NO_STR
3810 + "local UDP port\n") {
3811 + struct ldp *ldp = (struct ldp*)vty->index;
3812 + ldp_global g;
3814 + g.local_udp_port = LDP_GLOBAL_DEF_LOCAL_UDP_PORT;
3816 + ldp_admin_state_start(ldp);
3817 + ldp_cfg_global_set(ldp->h,&g, LDP_GLOBAL_CFG_LOCAL_UDP_PORT);
3818 + ldp_admin_state_finish(ldp);
3820 + return CMD_SUCCESS;
3823 +DEFUN (mpls_ldp_trace_address,
3824 + mpls_ldp_trace_address_cmd,
3825 + "trace address",
3826 + "LDP debugging\n"
3827 + "Address PDUs\n") {
3828 + ldp_traceflags |= LDP_TRACE_FLAG_ADDRESS;
3829 + return CMD_SUCCESS;
3832 +DEFUN (mpls_ldp_trace_binding,
3833 + mpls_ldp_trace_binding_cmd,
3834 + "trace binding",
3835 + "LDP debugging\n"
3836 + "Label Bindings\n") {
3837 + ldp_traceflags |= LDP_TRACE_FLAG_BINDING;
3838 + return CMD_SUCCESS;
3841 +DEFUN (mpls_ldp_trace_debug,
3842 + mpls_ldp_trace_debug_cmd,
3843 + "trace debug",
3844 + "LDP debugging\n"
3845 + "Debug Messages\n") {
3846 + ldp_traceflags |= LDP_TRACE_FLAG_DEBUG;
3847 + return CMD_SUCCESS;
3850 +DEFUN (mpls_ldp_trace_error,
3851 + mpls_ldp_trace_error_cmd,
3852 + "trace error",
3853 + "LDP debugging\n"
3854 + "Error Conditions\n") {
3855 + ldp_traceflags |= LDP_TRACE_FLAG_ERROR;
3856 + return CMD_SUCCESS;
3859 +DEFUN (mpls_ldp_trace_event,
3860 + mpls_ldp_trace_event_cmd,
3861 + "trace event",
3862 + "LDP debugging\n"
3863 + "LDP Events\n") {
3864 + ldp_traceflags |= LDP_TRACE_FLAG_EVENT;
3865 + return CMD_SUCCESS;
3868 +DEFUN (mpls_ldp_trace_general,
3869 + mpls_ldp_trace_general_cmd,
3870 + "trace general",
3871 + "LDP debugging\n"
3872 + "General Messages\n") {
3873 + ldp_traceflags |= LDP_TRACE_FLAG_GENERAL;
3874 + return CMD_SUCCESS;
3877 +DEFUN (mpls_ldp_trace_init,
3878 + mpls_ldp_trace_init_cmd,
3879 + "trace init",
3880 + "LDP debugging\n"
3881 + "Init PDUs\n") {
3882 + ldp_traceflags |= LDP_TRACE_FLAG_INIT;
3883 + return CMD_SUCCESS;
3886 +DEFUN (mpls_ldp_trace_label,
3887 + mpls_ldp_trace_label_cmd,
3888 + "trace label",
3889 + "LDP debugging\n"
3890 + "Label PDUs\n") {
3891 + ldp_traceflags |= LDP_TRACE_FLAG_LABEL;
3892 + return CMD_SUCCESS;
3895 +DEFUN (mpls_ldp_trace_normal,
3896 + mpls_ldp_trace_normal_cmd,
3897 + "trace normal",
3898 + "LDP debugging\n"
3899 + "Normal Messages\n") {
3900 + ldp_traceflags |= LDP_TRACE_FLAG_NORMAL;
3901 + return CMD_SUCCESS;
3904 +DEFUN (mpls_ldp_trace_notif,
3905 + mpls_ldp_trace_notif_cmd,
3906 + "trace notification",
3907 + "LDP debugging\n"
3908 + "Notification PDUs\n") {
3909 + ldp_traceflags |= LDP_TRACE_FLAG_NOTIF;
3910 + return CMD_SUCCESS;
3913 +DEFUN (mpls_ldp_trace_packet_dump,
3914 + mpls_ldp_trace_packet_dump_cmd,
3915 + "trace packet-dump",
3916 + "LDP debugging\n"
3917 + "Packet Dump\n") {
3918 + ldp_traceflags |= LDP_TRACE_FLAG_PACKET_DUMP;
3919 + return CMD_SUCCESS;
3922 +DEFUN (mpls_ldp_trace_packet,
3923 + mpls_ldp_trace_packet_cmd,
3924 + "trace packet",
3925 + "LDP debugging\n"
3926 + "Packet tracing\n") {
3927 + ldp_traceflags |= LDP_TRACE_FLAG_PACKET;
3928 + return CMD_SUCCESS;
3931 +DEFUN (mpls_ldp_trace_path,
3932 + mpls_ldp_trace_path_cmd,
3933 + "trace path",
3934 + "LDP debugging\n"
3935 + "PATH Info\n") {
3936 + ldp_traceflags |= LDP_TRACE_FLAG_PATH;
3937 + return CMD_SUCCESS;
3940 +DEFUN (mpls_ldp_trace_periodic,
3941 + mpls_ldp_trace_periodic_cmd,
3942 + "trace periodic",
3943 + "LDP debugging\n"
3944 + "Periodic PDUs\n") {
3945 + ldp_traceflags |= LDP_TRACE_FLAG_PERIODIC;
3946 + return CMD_SUCCESS;
3949 +DEFUN (mpls_ldp_trace_policy,
3950 + mpls_ldp_trace_policy_cmd,
3951 + "trace policy",
3952 + "LDP debugging\n"
3953 + "Policy tracing\n") {
3954 + ldp_traceflags |= LDP_TRACE_FLAG_POLICY;
3955 + return CMD_SUCCESS;
3958 +DEFUN (mpls_ldp_trace_route,
3959 + mpls_ldp_trace_route_cmd,
3960 + "trace route",
3961 + "LDP debugging\n"
3962 + "Route Lookup tracing\n") {
3963 + ldp_traceflags |= LDP_TRACE_FLAG_ROUTE;
3964 + return CMD_SUCCESS;
3967 +DEFUN (mpls_ldp_trace_state,
3968 + mpls_ldp_trace_state_cmd,
3969 + "trace state",
3970 + "LDP debugging\n"
3971 + "State transitions\n") {
3972 + ldp_traceflags |= LDP_TRACE_FLAG_STATE;
3973 + return CMD_SUCCESS;
3976 +DEFUN (mpls_ldp_trace_task,
3977 + mpls_ldp_trace_task_cmd,
3978 + "trace task",
3979 + "LDP debugging\n"
3980 + "Task tracing\n") {
3981 + ldp_traceflags |= LDP_TRACE_FLAG_TASK;
3982 + return CMD_SUCCESS;
3985 +DEFUN (mpls_ldp_trace_timer,
3986 + mpls_ldp_trace_timer_cmd,
3987 + "trace timer",
3988 + "LDP debugging\n"
3989 + "Timer tracing\n") {
3990 + ldp_traceflags |= LDP_TRACE_FLAG_TIMER;
3991 + return CMD_SUCCESS;
3994 +DEFUN (mpls_ldp_trace_all,
3995 + mpls_ldp_trace_all_cmd,
3996 + "trace all",
3997 + "LDP debugging\n"
3998 + "All tracing\n") {
3999 + ldp_traceflags |= LDP_TRACE_FLAG_ALL;
4000 + return CMD_SUCCESS;
4003 +DEFUN (mpls_ldp_trace_none,
4004 + mpls_ldp_trace_none_cmd,
4005 + "trace none",
4006 + "LDP debugging\n"
4007 + "Turn off all tracing\n") {
4008 + ldp_traceflags = 0;
4009 + return CMD_SUCCESS;
4012 +/* address and egress changes should result in an event which goes through
4013 + all of the existing FECs/addresses and decides which to withdrawl and then
4014 + ask the system for which additional FECs/addresses should be sent */
4016 +DEFUN (mpls_ldp_address,
4017 + mpls_ldp_address_cmd,
4018 + "address-mode (lsr-id|ldp)",
4019 + "Addresses this LSR will announce\n"
4020 + "LSR-ID only\n"
4021 + "Only LDP interfaces\n") {
4022 + struct ldp *ldp = (struct ldp*)vty->index;
4023 + if (!strncmp(argv[0], "lsr-id",6)) {
4024 + ldp->address = LDP_ADDRESS_LSRID;
4025 + } else if (!strncmp(argv[0], "ldp",3)) {
4026 + ldp->address = LDP_ADDRESS_LDP;
4027 + } else {
4028 + return CMD_WARNING;
4030 + return CMD_SUCCESS;
4033 +DEFUN (no_mpls_ldp_address,
4034 + no_mpls_ldp_address_cmd,
4035 + "no address-mode",
4036 + NO_STR
4037 + "Addresses this LSR will announce\n") {
4038 + struct ldp *ldp = (struct ldp*)vty->index;
4039 + ldp->address = LDP_ADDRESS_ALL;
4040 + return CMD_SUCCESS;
4043 +DEFUN (mpls_ldp_egress,
4044 + mpls_ldp_egress_cmd,
4045 + "egress (lsr-id|connected)",
4046 + "Filter FECs this LSR will send mappings for\n"
4047 + "LSR-ID only\n"
4048 + "All connected subnets\n") {
4049 + struct ldp *ldp = (struct ldp*)vty->index;
4050 + if (!strncmp(argv[0], "lsr-id",6)) {
4051 + ldp->egress = LDP_EGRESS_LSRID;
4052 + } else if (!strncmp(argv[0], "connected", 9)) {
4053 + ldp->egress = LDP_EGRESS_CONNECTED;
4054 + } else {
4055 + return CMD_WARNING;
4057 + return CMD_SUCCESS;
4060 +DEFUN (no_mpls_ldp_egress,
4061 + no_mpls_ldp_egress_cmd,
4062 + "no egress",
4063 + NO_STR
4064 + "Filter FECs this LSR will send mappings for\n") {
4065 + struct ldp *ldp = (struct ldp*)vty->index;
4066 + ldp->egress = LDP_EGRESS_ALL;
4067 + return CMD_SUCCESS;
4070 +#if 0
4071 +DEFUN (mpls_ldp_egress_list,
4072 + mpls_ldp_egress_list_cmd,
4073 + "egress access-list (<1-199>|<1300-2699>|WORD)",
4074 + "Filter FECs this LSR will send mappings for\n"
4075 + "IP access-list number\n"
4076 + "IP access-list number (expanded range)\n"
4077 + "IP Access-list name\n") {
4078 + return CMD_SUCCESS;
4081 +DEFUN (no_mpls_ldp_egress_list,
4082 + no_mpls_ldp_egress_list_cmd,
4083 + "no egress access-list (<1-199>|<1300-2699>|WORD)",
4084 + NO_STR
4085 + "Filter FECs this LSR will send mappings for\n"
4086 + "IP access-list number\n"
4087 + "IP access-list number (expanded range)\n"
4088 + "IP Access-list name\n") {
4089 + return CMD_SUCCESS;
4091 +#endif
4093 +DEFUN (mpls_show_ldp, mpls_show_ldp_cmd,
4094 + "show ldp",
4095 + SHOW_STR
4096 + "LDP global setting\n") {
4097 + struct mpls *mpls = mpls_get();
4098 + ldp_global g;
4100 + if (!mpls->ldp) {
4101 + vty_out (vty, "There isn't an active LDP instance.%s", VTY_NEWLINE);
4102 + return CMD_WARNING;
4105 + ldp_cfg_global_get(mpls->ldp->h,&g,0xFFFFFFFF);
4107 + vty_out(vty, "LSR-ID: %08x Admin State: %s%s",
4108 + g.lsr_identifier.u.ipv4, admin_state[g.admin_state], VTY_NEWLINE);
4109 + vty_out(vty, "Transport Address: %08x%s", g.transport_address.u.ipv4,
4110 + VTY_NEWLINE);
4111 + vty_out(vty, "Control Mode: %s\tRepair Mode: %s%s",
4112 + control_mode[g.lsp_control_mode], repair_mode[g.lsp_repair_mode],
4113 + VTY_NEWLINE);
4114 + vty_out(vty, "Propogate Release: %s\tLabel Merge: %s%s",
4115 + bool[g.propagate_release], bool[g.label_merge], VTY_NEWLINE);
4116 + vty_out(vty, "Retention Mode: %s\tLoop Detection Mode: %s%s",
4117 + retention_mode[g.label_retention_mode],
4118 + loop_detect_mode[g.loop_detection_mode], VTY_NEWLINE);
4119 + vty_out(vty, "TTL-less-domain: %s%s", bool[g.ttl_less_domain],
4120 + VTY_NEWLINE);
4121 + vty_out(vty, "Local TCP Port: %d\tLocal UDP Port: %d%s",
4122 + g.local_tcp_port, g.local_udp_port, VTY_NEWLINE);
4123 + vty_out(vty, "Keep-alive Time: %d\tKeep-alive Interval: %d%s",
4124 + g.keepalive_timer, g.keepalive_interval, VTY_NEWLINE);
4125 + vty_out(vty, "Hello Time: %d\tHello Interval: %d%s",
4126 + g.hellotime_timer, g.hellotime_interval, VTY_NEWLINE);
4128 + return CMD_SUCCESS;
4131 +void convert_seconds_to_string(uint32_t secs, char* buf) {
4132 + div_t mins;
4133 + div_t hours;
4134 + div_t days;
4135 + int h = 0;
4136 + int m = 0;
4137 + int s = 0;
4139 + if (secs >= 60) {
4140 + mins = div(secs, 60);
4141 + if (mins.quot >= 60) {
4142 + hours = div(mins.quot, 60);
4143 + if (hours.quot >= 24) {
4144 + days = div(hours.quot, 24);
4145 + h = days.rem;
4146 + m = hours.rem;
4147 + s = mins.rem;
4148 + sprintf(buf, "%dd %02d:%02d:%02d", days.quot, h, m, s);
4149 + return;
4150 + } else {
4151 + h = hours.quot;
4152 + m = hours.rem;
4153 + s = mins.rem;
4155 + } else {
4156 + h = 0;
4157 + m = mins.quot;
4158 + s = mins.rem;
4160 + } else {
4161 + h = 0;
4162 + m = 0;
4163 + s = secs;
4165 + sprintf(buf,"%02d:%02d:%02d", h, m, s);
4168 +DEFUN (mpls_show_ldp_neighbor, mpls_show_ldp_neighbor_cmd,
4169 + "show ldp neighbor",
4170 + SHOW_STR
4171 + "LDP related commands\n"
4172 + "Discovered neighbors\n"
4173 + "LDP identifier\n") {
4174 + struct mpls *mpls = mpls_get();
4175 + struct ldp *ldp = mpls->ldp;
4176 + ldp_adj adj;
4177 + ldp_addr addr;
4178 + ldp_entity e;
4179 + ldp_global g;
4180 + ldp_session s;
4181 + int count;
4182 + int addr_count;
4183 + uint32_t time_now;
4184 + char time_buf[13];
4185 + struct in_addr lsr;
4186 + struct in_addr src;
4187 + struct in_addr tr;
4188 + int label_space = 0;
4189 + ldp_if iff;
4190 + ldp_peer peer;
4192 +#if 0
4194 +Peer LDP Ident: 7.1.1.1:0; Local LDP Ident 8.1.1.1:0
4195 + TCP connection: 7.1.1.1.646 - 8.1.1.1.11006
4196 + State: Oper; Msgs sent/rcvd: 4/411; Downstream
4197 + Up time: 00:00:52
4198 + LDP discovery sources:
4199 + Ethernet1/0/0
4200 + Addresses bound to peer LDP Ident:
4201 + 2.0.0.29 7.1.1.1 59.0.0.199 212.10.1.1
4202 + 10.205.0.9
4204 +#endif
4206 + if (!ldp) {
4207 + vty_out (vty, "There isn't an active LDP instance.%s", VTY_NEWLINE);
4208 + return CMD_WARNING;
4211 + ldp_cfg_global_get(ldp->h,&g,0xFFFFFFFF);
4213 + count = 0;
4214 + adj.index = 0;
4215 + while (ldp_cfg_adj_getnext(ldp->h, &adj, 0xFFFFFFFF) ==
4216 + MPLS_SUCCESS) {
4217 + count++;
4219 + if (adj.entity_index) {
4220 + e.index = adj.entity_index;
4221 + ldp_cfg_entity_get(ldp->h,&e,0xFFFFFFFF);
4222 + if (e.entity_type == LDP_DIRECT) {
4223 + iff.index = e.sub_index;
4224 + ldp_cfg_if_get(ldp->h,&iff,0xFFFFFFFF);
4225 + label_space = iff.label_space;
4226 + } else {
4227 + peer.index = e.sub_index;
4228 + ldp_cfg_peer_get(ldp->h,&peer,0xFFFFFFFF);
4229 + label_space = peer.label_space;
4233 + lsr.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
4234 + vty_out(vty, "Peer LDP Ident: %s:%d; Local LDP Ident: ", inet_ntoa(lsr),
4235 + adj.remote_label_space);
4236 + lsr.s_addr = htonl(g.lsr_identifier.u.ipv4);
4237 + vty_out(vty, "%s:%d%s", inet_ntoa(lsr), label_space, VTY_NEWLINE);
4239 + if (adj.session_index) {
4240 + s.index = adj.session_index;
4242 + if (ldp_cfg_session_get(ldp->h,&s,0xFFFFFFFF) != MPLS_SUCCESS) {
4243 + continue;
4246 + tr.s_addr = 0;
4247 + vty_out(vty, "\tTCP connection: %s.%d", inet_ntoa(tr),
4248 + g.local_tcp_port);
4250 + src.s_addr = htonl(s.remote_dest.addr.u.ipv4);
4251 + vty_out(vty, " - %s.%d%s", inet_ntoa(src), s.remote_dest.port,
4252 + VTY_NEWLINE);
4254 + vty_out(vty, "\tState: %s; Msgs sent/recv: %d/%d; %s%s",
4255 + session_state[s.state], s.mesg_tx, s.mesg_rx,
4256 + distribution_mode[s.oper_distribution_mode], VTY_NEWLINE);
4257 + time_now = time(NULL);
4258 + convert_seconds_to_string(time_now - s.oper_up, time_buf);
4259 + vty_out(vty, "\tUp time: %s%s", time_buf, VTY_NEWLINE);
4261 + vty_out(vty, "\tLDP discovery sources:%s", VTY_NEWLINE);
4262 + } else {
4263 + vty_out(vty, "\tTCP connection: %s%s", "n/a", VTY_NEWLINE);
4264 + vty_out(vty, "\tState: discovery; Msgs sent/recv: -/-;%s",VTY_NEWLINE);
4265 + vty_out(vty, "\tUp time: %s%s", "-", VTY_NEWLINE);
4266 + vty_out(vty, "\tLDP discovery sources:%s", VTY_NEWLINE);
4268 + vty_out(vty, "\t ");
4270 + if (e.entity_type == LDP_DIRECT) {
4271 + vty_out(vty, "%s ", iff.name);
4272 + } else {
4273 + vty_out(vty, "%s ", peer.peer_name);
4275 + vty_out(vty, "%s", VTY_NEWLINE);
4277 + if (adj.session_index) {
4278 + vty_out(vty, "\tAddresses bound to peer:%s", VTY_NEWLINE);
4280 + addr.index = 0;
4281 + addr_count = 0;
4282 + while (ldp_cfg_session_raddr_getnext(ldp->h, &s, &addr, 0xFFFFFFFF) ==
4283 + MPLS_SUCCESS) {
4284 + lsr.s_addr = htonl(addr.address.u.ipv4);
4285 + vty_out(vty, "\t");
4286 + if (!addr_count) {
4287 + vty_out(vty, " ");
4290 + vty_out(vty, "%s",inet_ntoa(lsr));
4291 + addr_count++;
4293 + if (addr_count == 4) {
4294 + vty_out(vty, "%s", VTY_NEWLINE);
4295 + addr_count = 0;
4298 + vty_out(vty, "%s", VTY_NEWLINE);
4301 + vty_out(vty, "%s", VTY_NEWLINE);
4302 + if (count == 0) {
4303 + vty_out(vty, "\tNo discovered neighbors%s", VTY_NEWLINE);
4305 + vty_out(vty, "%s", VTY_NEWLINE);
4307 + return CMD_SUCCESS;
4310 +DEFUN (mpls_show_ldp_session, mpls_show_ldp_session_cmd,
4311 + "show ldp session [A.B.C.D:E]",
4312 + SHOW_STR
4313 + "LDP related commands\n"
4314 + "Session information\n"
4315 + "LDP identifier\n") {
4316 + struct mpls *mpls = mpls_get();
4317 + struct ldp *ldp = mpls->ldp;
4318 + ldp_session session;
4319 + ldp_addr addr;
4320 + struct in_addr in;
4321 + int count = 0;
4323 + if (!ldp) {
4324 + vty_out (vty, "There isn't active LDP instance.%s", VTY_NEWLINE);
4325 + return CMD_WARNING;
4328 + session.index = 0;
4329 + while (ldp_cfg_session_getnext(ldp->h, &session, 0xFFFFFFFF) == MPLS_SUCCESS) {
4330 + count++;
4331 + in.s_addr = htonl(session.remote_dest.addr.u.ipv4);
4332 + vty_out(vty, "%-2d %s %-3d %s%s", session.index,
4333 + inet_ntoa(in), session.oper_keepalive,
4334 + session_state[session.state], VTY_NEWLINE);
4335 + addr.index = 0;
4336 + while (ldp_cfg_session_raddr_getnext(ldp->h, &session,
4337 + &addr, 0xFFFFFFFF) == MPLS_SUCCESS) {
4338 + in.s_addr = htonl(addr.address.u.ipv4);
4339 + vty_out(vty, "\t%s%s",inet_ntoa(in), VTY_NEWLINE);
4342 + if (count == 0) {
4343 + vty_out(vty, " no established sessions%s", VTY_NEWLINE);
4346 + return CMD_SUCCESS;
4349 +DEFUN (mpls_show_ldp_discovery, mpls_show_ldp_discovery_cmd,
4350 + "show ldp discovery",
4351 + SHOW_STR
4352 + "LDP related commands\n"
4353 + "Discovery information\n") {
4354 + struct mpls *mpls = mpls_get();
4355 + struct ldp *ldp = mpls->ldp;
4356 + ldp_if iff;
4357 + int count;
4358 + ldp_global g;
4359 + ldp_adj adj;
4360 + ldp_entity entity;
4361 + ldp_peer peer;
4362 + struct in_addr dst;
4363 + int first;
4365 + if (!ldp) {
4366 + vty_out (vty, "There isn't an active LDP instance.%s", VTY_NEWLINE);
4367 + return CMD_WARNING;
4370 + vty_out(vty, "%s", VTY_NEWLINE);
4372 + ldp_cfg_global_get(ldp->h,&g,0xFFFFFFFF);
4373 + dst.s_addr = htonl(g.lsr_identifier.u.ipv4);
4374 + vty_out(vty, "Local LSR Identifier: %s%s", inet_ntoa(dst), VTY_NEWLINE);
4375 + vty_out(vty, "%s", VTY_NEWLINE);
4376 + vty_out(vty, "Interface Discovery Sources:%s", VTY_NEWLINE);
4378 + count = 0;
4379 + iff.index = 0;
4380 + while (ldp_cfg_if_getnext(ldp->h, &iff, 0xFFFFFFFF) == MPLS_SUCCESS) {
4381 + first = 1;
4382 + count++;
4383 + vty_out(vty, "\t%s: ", iff.name);
4384 + if (iff.oper_state != MPLS_OPER_UP) {
4385 + vty_out(vty, "down");
4386 + } else {
4387 + vty_out(vty, "xmit");
4388 + entity.index = iff.entity_index;
4389 + if (ldp_cfg_entity_get(ldp->h, &entity, 0xFFFFFFFF) != MPLS_SUCCESS) {
4390 + continue;
4392 + do {
4393 + adj.index = entity.adj_index;
4394 + if (ldp_cfg_adj_get(ldp->h, &adj, 0xFFFFFFFF) == MPLS_SUCCESS) {
4395 + if (first) {
4396 + vty_out(vty, "/recv%s", VTY_NEWLINE);
4397 + first = 0;
4399 + dst.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
4400 + vty_out(vty, "\t LDP Id: %s:%d%s ", inet_ntoa(dst),
4401 + adj.remote_label_space, VTY_NEWLINE);
4403 + } while (ldp_cfg_entity_adj_getnext(ldp->h, &entity) == MPLS_SUCCESS);
4405 + if (first) {
4406 + vty_out(vty, "%s", VTY_NEWLINE);
4409 + if (count == 0) {
4410 + vty_out(vty, "\tNo configured interfaces%s", VTY_NEWLINE);
4413 + vty_out(vty, "%s", VTY_NEWLINE);
4414 + vty_out(vty, "Targeted Discovery Sources:%s", VTY_NEWLINE);
4416 + count = 0;
4417 + peer.index = 0;
4418 + while (ldp_cfg_peer_getnext(ldp->h, &peer, 0xFFFFFFFF) ==
4419 + MPLS_SUCCESS) {
4420 + first = 1;
4421 + count++;
4422 + dst.s_addr = htonl(peer.dest.addr.u.ipv4);
4423 + vty_out(vty, "\t%s: xmit ", inet_ntoa(dst));
4424 + while (ldp_cfg_adj_getnext(ldp->h, &adj, 0xFFFFFFFF) == MPLS_SUCCESS) {
4425 + if (peer.entity_index == adj.entity_index) {
4426 + if (first) {
4427 + vty_out(vty, "/recv%s", VTY_NEWLINE);
4428 + first = 0;
4430 + dst.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
4431 + vty_out(vty, "\t LDP Id: %s:%d%s ", inet_ntoa(dst),
4432 + adj.remote_label_space, VTY_NEWLINE);
4435 + if (first) {
4436 + vty_out(vty, "%s", VTY_NEWLINE);
4439 + if (count == 0) {
4440 + vty_out(vty, "\tNo configured peers%s", VTY_NEWLINE);
4442 + vty_out(vty, "%s", VTY_NEWLINE);
4444 + return CMD_SUCCESS;
4447 +void ldp_print_label(struct vty *vty, mpls_label_struct *l) {
4448 + switch(l->type) {
4449 + case MPLS_LABEL_TYPE_NONE:
4450 + vty_out(vty, "label: unknown");
4451 + break;
4452 + case MPLS_LABEL_TYPE_GENERIC:
4453 + vty_out(vty, "label: gen %d",l->u.gen);
4454 + break;
4455 + case MPLS_LABEL_TYPE_ATM:
4456 + vty_out(vty, "label: atm %d/%d",l->u.atm.vpi,l->u.atm.vci);
4457 + break;
4458 + case MPLS_LABEL_TYPE_FR:
4459 + vty_out(vty, "label: dlci %d",l->u.fr.dlci);
4460 + break;
4464 +DEFUN (mpls_show_ldp_database, mpls_show_ldp_database_cmd,
4465 + "show ldp database [A.B.C.D:E]",
4466 + SHOW_STR
4467 + "LDP related commands\n"
4468 + "Labeling information\n"
4469 + "LDP identifier\n") {
4470 + struct mpls *mpls = mpls_get();
4471 + struct ldp *ldp = mpls->ldp;
4472 + ldp_session session;
4473 + ldp_outlabel out;
4474 + ldp_inlabel in;
4475 + ldp_attr attr;
4476 + ldp_adj adj;
4477 + int count = 0;
4478 + struct in_addr fec;
4480 + if (!ldp) {
4481 + vty_out (vty, "There isn't an active LDP instance.%s", VTY_NEWLINE);
4482 + return CMD_WARNING;
4485 + attr.index = 0;
4486 + while (ldp_cfg_attr_getnext(ldp->h, &attr, 0xFFFFFFFF) == MPLS_SUCCESS) {
4487 + count++;
4489 + fec.s_addr = htonl(attr.fecTlv.fecElArray[0].addressEl.address);
4491 + vty_out(vty, " %s/%d ", inet_ntoa(fec),
4492 + attr.fecTlv.fecElArray[0].addressEl.preLen);
4494 + session.index = attr.session_index;
4495 + if (ldp_cfg_session_get(ldp->h, &session, 0xFFFFFFFF) != MPLS_SUCCESS) {
4496 + vty_out(vty, "no session%s",VTY_NEWLINE);
4497 + continue;
4500 + adj.index = session.adj_index;
4501 + if (ldp_cfg_adj_get(ldp->h, &adj, 0xFFFFFFFF) != MPLS_SUCCESS) {
4502 + vty_out(vty, "no adj%s",VTY_NEWLINE);
4503 + continue;
4506 + switch(attr.state) {
4507 + case LDP_LSP_STATE_MAP_RECV:
4508 + vty_out(vty, "remote binding: ");
4509 + out.index = attr.outlabel_index;
4510 + if (ldp_cfg_outlabel_get(ldp->h, &out, 0xFFFFFFFF) != MPLS_SUCCESS) {
4511 + vty_out(vty, "no outlabel");
4512 + } else {
4513 + ldp_print_label(vty,&out.info.label);
4515 + fec.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
4516 + vty_out(vty, " lsr: %s:%d ", inet_ntoa(fec), adj.remote_label_space);
4517 + if (attr.ingress == MPLS_BOOL_TRUE) {
4518 + vty_out(vty, "ingress");
4520 + break;
4521 + case LDP_LSP_STATE_MAP_SENT:
4522 + in.index = attr.inlabel_index;
4523 + if (ldp_cfg_inlabel_get(ldp->h, &in, 0xFFFFFFFF) != MPLS_SUCCESS) {
4524 + vty_out(vty, "no inlabel%s", VTY_NEWLINE);
4525 + continue;
4527 + vty_out(vty, "local binding: ");
4528 + ldp_print_label(vty,&in.info.label);
4529 + break;
4530 + case LDP_LSP_STATE_WITH_SENT:
4531 + case LDP_LSP_STATE_WITH_RECV:
4532 + case LDP_LSP_STATE_NO_LABEL_RESOURCE_SENT:
4533 + case LDP_LSP_STATE_NO_LABEL_RESOURCE_RECV:
4534 + case LDP_LSP_STATE_ABORT_SENT:
4535 + case LDP_LSP_STATE_ABORT_RECV:
4536 + case LDP_LSP_STATE_NOTIF_SENT:
4537 + case LDP_LSP_STATE_NOTIF_RECV:
4538 + case LDP_LSP_STATE_REQ_RECV:
4539 + case LDP_LSP_STATE_REQ_SENT:
4540 + vty_out(vty, "%s:\t", attr_state[attr.state]);
4541 + fec.s_addr = htonl(adj.remote_lsr_address.u.ipv4);
4542 + vty_out(vty, "lsr: %s:%d", inet_ntoa(fec), adj.remote_label_space);
4543 + break;
4544 + default:
4545 + break;
4547 + vty_out(vty, "%s", VTY_NEWLINE);
4549 + if (count == 0) {
4550 + vty_out(vty, " no labeling info has been exchanged%s", VTY_NEWLINE);
4553 + return CMD_SUCCESS;
4556 +DEFUN(ldp_intf,
4557 + ldp_intf_cmd,
4558 + "mpls ldp",
4559 + "MPLS interface configuration\n"
4560 + "Enable LDP\n") {
4561 + struct interface *ifp = vty->index;
4562 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4563 + struct mpls *mpls = mi->mpls;
4565 + if (mi->l2cc) {
4566 + return CMD_WARNING;
4569 + if (!mi->ldp) {
4570 + /* user is trying to create a new LDP interface */
4571 + /* if a labelspace hasn't been set yet, set it to 0 */
4572 + if (mi->labelspace == -1) {
4573 + mi->labelspace = 0;
4574 + do_mpls_labelspace(mi);
4576 + mi->ldp = ldp_if_new(mi);
4579 + /* if the global LDP has been created, go ahead and tell LDP about it
4580 + * otherwise just mark the interface as "on hold"
4581 + */
4582 + if (mpls->ldp) {
4583 + ldp_interface_create(mi);
4584 + } else {
4585 + mi->ldp->create_on_hold = MPLS_BOOL_TRUE;
4588 + vty->node = MPLS_LDP_IF_NODE;
4590 + return CMD_SUCCESS;
4593 +DEFUN(no_ldp_intf,
4594 + no_ldp_intf_cmd,
4595 + "no mpls ldp",
4596 + NO_STR
4597 + "MPLS interface configuration\n"
4598 + "remove LDP\n") {
4599 + struct interface *ifp = vty->index;
4600 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4602 + if (mi->ldp) {
4603 + ldp_interface_delete(mi);
4604 + ldp_if_free(mi->ldp);
4605 + mi->ldp = NULL;
4607 + return CMD_SUCCESS;
4610 +DEFUN(ldp_l2cc_intf,
4611 + ldp_l2cc_intf_cmd,
4612 + "mpls l2cc peer IPADDR vc-id VCID <group-id GROUPID>",
4613 + "MPLS interface configuration\n"
4614 + "Create a Layer 2 Cross Connect\n"
4615 + "Remote Peer\n"
4616 + "IP Address\n"
4617 + "Virtual Circuit ID\n"
4618 + "<0-255>\n"
4619 + "Optional Group ID\n"
4620 + "<0-255>\n") {
4621 + struct interface *ifp = vty->index;
4622 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4623 + struct mpls *mpls = mi->mpls;
4624 + uint32_t peer_addr;
4625 + int vcid = 0;
4626 + int gid = -1;
4628 + if (mi->ldp) {
4629 + return CMD_WARNING;
4632 + if (!mi->l2cc) {
4633 + /* user is trying to create a new L2CC interface */
4634 + mi->l2cc = l2cc_if_new(mi);
4637 + VTY_GET_IPV4_ADDRESS("IPADDR",peer_addr,argv[0]);
4638 + VTY_GET_UINT32_RANGE("VCID",vcid,argv[1],0,255);
4639 + if (argc > 2) {
4640 + VTY_GET_UINT32_RANGE("GROUPID",gid,argv[2],0,255);
4643 + /* if the global LDP has been created, go ahead and tell LDP about it
4644 + * otherwise just mark the cross connect as "on hold"
4645 + */
4646 + if (mpls->ldp) {
4647 + l2cc_interface_create(mi);
4648 + } else {
4649 + mi->l2cc->create_on_hold = MPLS_BOOL_TRUE;
4651 + return CMD_SUCCESS;
4654 +DEFUN(no_ldp_l2cc_intf,
4655 + no_ldp_l2cc_intf_cmd,
4656 + "no mpls l2cc",
4657 + NO_STR
4658 + "MPLS interface configuration\n"
4659 + "Delete a Layer 2 Cross Connect\n") {
4660 + struct interface *ifp = vty->index;
4661 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4663 + if (mi->l2cc) {
4664 + l2cc_interface_delete(mi);
4665 + l2cc_if_free(mi->ldp);
4666 + mi->l2cc = NULL;
4668 + return CMD_SUCCESS;
4671 +DEFUN(ldp_remote_peer,
4672 + ldp_remote_peer_cmd,
4673 + "peer IPADDR",
4674 + "MPLS peer configuration\n"
4675 + "Peer's IPv4 Address\n") {
4676 + struct ldp *ldp = vty->index;
4677 + struct mpls_dest dest;
4678 + struct ldp_remote_peer *rp;
4680 + dest.addr.type = MPLS_FAMILY_IPV4;
4681 + VTY_GET_IPV4_ADDRESS("IPADDR",dest.addr.u.ipv4,argv[0]);
4682 + dest.port = 646;
4684 + if (ldp_remote_peer_find(ldp,&dest)) {
4685 + return CMD_WARNING;
4688 + rp = ldp_remote_peer_new(ldp);
4689 + listnode_add(ldp->peer_list, rp);
4690 + ldp_remote_peer_create(rp,&dest);
4691 + return CMD_SUCCESS;
4694 +DEFUN(no_ldp_remote_peer,
4695 + no_ldp_remote_peer_cmd,
4696 + "no peer IPADDR",
4697 + NO_STR
4698 + "MPLS peer configuration\n"
4699 + "Peer's IPv4 Address\n") {
4700 + struct ldp *ldp = vty->index;
4701 + struct mpls_dest dest;
4702 + struct ldp_remote_peer *rp;
4704 + dest.addr.type = MPLS_FAMILY_IPV4;
4705 + dest.addr.u.ipv4 = ntohl(inet_addr(argv[0]));
4706 + dest.port = 646;
4708 + if ((rp = ldp_remote_peer_find(ldp,&dest))) {
4709 + listnode_delete(ldp->peer_list, rp);
4710 + ldp_remote_peer_delete(rp);
4711 + ldp_remote_peer_free(rp);
4713 + return CMD_SUCCESS;
4716 +DEFUN(ldp_if_distribution_mode,
4717 + ldp_if_distribution_mode_cmd,
4718 + "distribution-mode (dod|du)",
4719 + "MPLS interface configuration\n"
4720 + "distribution mode\n"
4721 + "Downstream on Demand or Downstream unsolicited\n") {
4722 + struct interface *ifp = vty->index;
4723 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4724 + struct ldp_interface *li = mi->ldp;
4725 + struct mpls *mpls = mi->mpls;
4726 + struct ldp *ldp = mpls->ldp;
4728 + if (!strncmp(argv[0],"dod",3)) {
4729 + li->entity.label_distribution_mode = LDP_DISTRIBUTION_ONDEMAND;
4730 + } else if (!strncmp(argv[0],"du",2)) {
4731 + li->entity.label_distribution_mode = LDP_DISTRIBUTION_UNSOLICITED;
4732 + } else {
4733 + return CMD_WARNING;
4736 + if (!ldp) {
4737 + li->create_on_hold = MPLS_BOOL_TRUE;
4738 + return CMD_SUCCESS;
4740 + ldp_interface_admin_state_start(mi);
4741 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_DISTRIBUTION_MODE);
4742 + ldp_interface_admin_state_finish(mi);
4743 + return CMD_SUCCESS;
4746 +DEFUN(no_ldp_if_distribution_mode,
4747 + no_ldp_if_distribution_mode_cmd,
4748 + "no distribution-mode",
4749 + NO_STR
4750 + "MPLS interface configuration\n"
4751 + "distribution mode\n") {
4752 + struct interface *ifp = vty->index;
4753 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4754 + struct ldp_interface *li = mi->ldp;
4755 + struct mpls *mpls = mi->mpls;
4756 + struct ldp *ldp = mpls->ldp;
4758 + li->entity.label_distribution_mode = LDP_ENTITY_DEF_DISTRIBUTION_MODE;
4759 + if (!ldp) {
4760 + li->create_on_hold = MPLS_BOOL_TRUE;
4761 + return CMD_SUCCESS;
4764 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_DISTRIBUTION_MODE);
4765 + return CMD_SUCCESS;
4768 +DEFUN(ldp_if_remote_tcp_port,
4769 + ldp_if_remote_tcp_port_cmd,
4770 + "remote-tcp-port <1-65535>",
4771 + "MPLS interface configuration\n"
4772 + "remote LDP port\n"
4773 + "port number\n") {
4774 + struct interface *ifp = vty->index;
4775 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4776 + struct ldp_interface *li = mi->ldp;
4777 + struct mpls *mpls = mi->mpls;
4778 + struct ldp *ldp = mpls->ldp;
4780 + li->entity.remote_tcp_port = atoi(argv[0]);
4781 + if (!ldp) {
4782 + li->create_on_hold = MPLS_BOOL_TRUE;
4783 + return CMD_SUCCESS;
4786 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REMOTE_TCP);
4787 + return CMD_SUCCESS;
4790 +DEFUN(no_ldp_if_remote_tcp_port,
4791 + no_ldp_if_remote_tcp_port_cmd,
4792 + "no remote-tcp-port",
4793 + NO_STR
4794 + "MPLS interface configuration\n"
4795 + "remote LDP port\n") {
4796 + struct interface *ifp = vty->index;
4797 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4798 + struct ldp_interface *li = mi->ldp;
4799 + struct mpls *mpls = mi->mpls;
4801 + li->entity.remote_tcp_port = LDP_ENTITY_DEF_REMOTE_TCP;
4802 + if (!mpls->ldp) {
4803 + li->create_on_hold = MPLS_BOOL_TRUE;
4804 + return CMD_SUCCESS;
4807 + ldp_cfg_entity_set(mpls->ldp->h, &li->entity, LDP_ENTITY_CFG_REMOTE_TCP);
4808 + return CMD_SUCCESS;
4811 +DEFUN(ldp_if_remote_udp_port,
4812 + ldp_if_remote_udp_port_cmd,
4813 + "remote-udp-port <1-65535>",
4814 + "MPLS interface configuration\n"
4815 + "remote LDP port\n"
4816 + "port number\n") {
4817 + struct interface *ifp = vty->index;
4818 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4819 + struct ldp_interface *li = mi->ldp;
4820 + struct mpls *mpls = mi->mpls;
4821 + struct ldp *ldp = mpls->ldp;
4823 + li->entity.remote_udp_port = atoi(argv[0]);
4824 + if (!ldp) {
4825 + li->create_on_hold = MPLS_BOOL_TRUE;
4826 + return CMD_SUCCESS;
4829 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REMOTE_UDP);
4830 + return CMD_SUCCESS;
4833 +DEFUN(no_ldp_if_remote_udp_port,
4834 + no_ldp_if_remote_udp_port_cmd,
4835 + "no remote-udp-port",
4836 + NO_STR
4837 + "MPLS interface configuration\n"
4838 + "remote LDP port\n") {
4839 + struct interface *ifp = vty->index;
4840 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4841 + struct ldp_interface *li = mi->ldp;
4842 + struct mpls *mpls = mi->mpls;
4843 + struct ldp *ldp = mpls->ldp;
4845 + li->entity.remote_udp_port = LDP_ENTITY_DEF_REMOTE_UDP;
4846 + if (!ldp) {
4847 + li->create_on_hold = MPLS_BOOL_TRUE;
4848 + return CMD_SUCCESS;
4851 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REMOTE_UDP);
4852 + return CMD_SUCCESS;
4855 +DEFUN(ldp_if_max_pdu,
4856 + ldp_if_max_pdu_cmd,
4857 + "max-pdu <64-9182>",
4858 + "MPLS interface configuration\n"
4859 + "maximum LDP PDU size\n"
4860 + "PDU size\n") {
4861 + struct interface *ifp = vty->index;
4862 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4863 + struct ldp_interface *li = mi->ldp;
4864 + struct mpls *mpls = mi->mpls;
4865 + struct ldp *ldp = mpls->ldp;
4867 + li->entity.max_pdu = atoi(argv[0]);
4868 + if (!ldp) {
4869 + li->create_on_hold = MPLS_BOOL_TRUE;
4870 + return CMD_SUCCESS;
4873 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_MAX_PDU);
4874 + return CMD_SUCCESS;
4877 +DEFUN(no_ldp_if_max_pdu,
4878 + no_ldp_if_max_pdu_cmd,
4879 + "no max-pdu",
4880 + NO_STR
4881 + "MPLS interface configuration\n"
4882 + "maximum LDP pdu size\n") {
4883 + struct interface *ifp = vty->index;
4884 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4885 + struct ldp_interface *li = mi->ldp;
4886 + struct mpls *mpls = mi->mpls;
4887 + struct ldp *ldp = mpls->ldp;
4889 + li->entity.max_pdu = LDP_ENTITY_DEF_MAX_PDU;
4890 + if (!ldp) {
4891 + li->create_on_hold = MPLS_BOOL_TRUE;
4892 + return CMD_SUCCESS;
4895 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_MAX_PDU);
4896 + return CMD_SUCCESS;
4899 +DEFUN(ldp_if_hello_interval,
4900 + ldp_if_hello_interval_cmd,
4901 + "hello-interval <1-60>",
4902 + "MPLS interface configuration\n"
4903 + "hello interval\n"
4904 + "interval in seconds\n") {
4905 + struct interface *ifp = vty->index;
4906 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4907 + struct ldp_interface *li = mi->ldp;
4908 + struct mpls *mpls = mi->mpls;
4909 + struct ldp *ldp = mpls->ldp;
4911 + li->entity.hellotime_interval = atoi(argv[0]);
4912 + if (!ldp) {
4913 + li->create_on_hold = MPLS_BOOL_TRUE;
4914 + return CMD_SUCCESS;
4917 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_HELLOTIME_INTERVAL);
4918 + return CMD_SUCCESS;
4921 +DEFUN(no_ldp_if_hello_interval,
4922 + no_ldp_if_hello_interval_cmd,
4923 + "no hello-interval",
4924 + NO_STR
4925 + "MPLS interface configuration\n"
4926 + "hello interval\n") {
4927 + struct interface *ifp = vty->index;
4928 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4929 + struct ldp_interface *li = mi->ldp;
4930 + struct mpls *mpls = mi->mpls;
4931 + struct ldp *ldp = mpls->ldp;
4933 + li->entity.hellotime_interval = LDP_ENTITY_DEF_HELLOTIME_INTERVAL;
4934 + if (!ldp) {
4935 + li->create_on_hold = MPLS_BOOL_TRUE;
4936 + return CMD_SUCCESS;
4939 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_HELLOTIME_INTERVAL);
4940 + return CMD_SUCCESS;
4943 +DEFUN(ldp_if_keepalive_interval,
4944 + ldp_if_keepalive_interval_cmd,
4945 + "keepalive-interval <1-60>",
4946 + "MPLS interface configuration\n"
4947 + "keepalive interval\n"
4948 + "interval in seconds\n") {
4949 + struct interface *ifp = vty->index;
4950 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4951 + struct ldp_interface *li = mi->ldp;
4952 + struct mpls *mpls = mi->mpls;
4953 + struct ldp *ldp = mpls->ldp;
4955 + li->entity.keepalive_interval = atoi(argv[0]);
4956 + if (!ldp) {
4957 + li->create_on_hold = MPLS_BOOL_TRUE;
4958 + return CMD_SUCCESS;
4961 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_KEEPALIVE_INTERVAL);
4962 + return CMD_SUCCESS;
4965 +DEFUN(no_ldp_if_keepalive_interval,
4966 + no_ldp_if_keepalive_interval_cmd,
4967 + "no keepalive-interval",
4968 + NO_STR
4969 + "MPLS interface configuration\n"
4970 + "keepalive interval\n") {
4971 + struct interface *ifp = vty->index;
4972 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4973 + struct ldp_interface *li = mi->ldp;
4974 + struct mpls *mpls = mi->mpls;
4975 + struct ldp *ldp = mpls->ldp;
4977 + li->entity.keepalive_interval = LDP_ENTITY_DEF_KEEPALIVE_INTERVAL;
4978 + if (!ldp) {
4979 + li->create_on_hold = MPLS_BOOL_TRUE;
4980 + return CMD_SUCCESS;
4983 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_KEEPALIVE_INTERVAL);
4984 + return CMD_SUCCESS;
4987 +DEFUN(ldp_if_max_session_attempt,
4988 + ldp_if_max_session_attempt_cmd,
4989 + "max-session-attempt <0-1024>",
4990 + "MPLS interface configuration\n"
4991 + "maximum LDP session setup attempt\n"
4992 + "Number of attempts (0 means keep trying)\n") {
4993 + struct interface *ifp = vty->index;
4994 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
4995 + struct ldp_interface *li = mi->ldp;
4996 + struct mpls *mpls = mi->mpls;
4997 + struct ldp *ldp = mpls->ldp;
4999 + li->entity.session_setup_count = atoi(argv[0]);
5000 + if (!ldp) {
5001 + li->create_on_hold = MPLS_BOOL_TRUE;
5002 + return CMD_SUCCESS;
5005 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_SESSION_SETUP_COUNT);
5006 + return CMD_SUCCESS;
5009 +DEFUN(no_ldp_if_max_session_attempt,
5010 + no_ldp_if_max_session_attempt_cmd,
5011 + "no max-session-attempt\n",
5012 + NO_STR
5013 + "MPLS interface configuration\n"
5014 + "maximum LDP session setup attempt\n") {
5015 + struct interface *ifp = vty->index;
5016 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5017 + struct ldp_interface *li = mi->ldp;
5018 + struct mpls *mpls = mi->mpls;
5019 + struct ldp *ldp = mpls->ldp;
5021 + li->entity.session_setup_count = LDP_ENTITY_DEF_SESSIONSETUP_COUNT;
5022 + if (!ldp) {
5023 + li->create_on_hold = MPLS_BOOL_TRUE;
5024 + return CMD_SUCCESS;
5027 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_SESSION_SETUP_COUNT);
5028 + return CMD_SUCCESS;
5031 +DEFUN(ldp_if_max_path_vector,
5032 + ldp_if_max_path_vector_cmd,
5033 + "max-path-vector <1-255>",
5034 + "MPLS interface configuration\n"
5035 + "maximum path vector\n"
5036 + "number of entries\n") {
5037 + struct interface *ifp = vty->index;
5038 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5039 + struct ldp_interface *li = mi->ldp;
5040 + struct mpls *mpls = mi->mpls;
5041 + struct ldp *ldp = mpls->ldp;
5043 + li->entity.path_vector_limit = atoi(argv[0]);
5044 + if (!ldp) {
5045 + li->create_on_hold = MPLS_BOOL_TRUE;
5046 + return CMD_SUCCESS;
5049 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_PATHVECTOR_LIMIT);
5050 + return CMD_SUCCESS;
5053 +DEFUN(no_ldp_if_max_path_vector,
5054 + no_ldp_if_max_path_vector_cmd,
5055 + "no max-path-vector",
5056 + NO_STR
5057 + "MPLS interface configuration\n"
5058 + "maximum path vector\n") {
5059 + struct interface *ifp = vty->index;
5060 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5061 + struct ldp_interface *li = mi->ldp;
5062 + struct mpls *mpls = mi->mpls;
5063 + struct ldp *ldp = mpls->ldp;
5065 + li->entity.path_vector_limit = LDP_ENTITY_DEF_PATHVECTOR_LIMIT;
5066 + if (!ldp) {
5067 + li->create_on_hold = MPLS_BOOL_TRUE;
5068 + return CMD_SUCCESS;
5071 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_PATHVECTOR_LIMIT);
5072 + return CMD_SUCCESS;
5075 +DEFUN(ldp_if_max_hop_count,
5076 + ldp_if_max_hop_count_cmd,
5077 + "max-hop-count <1-1024>",
5078 + "MPLS interface configuration\n"
5079 + "maximum hop count\n"
5080 + "number of hops\n") {
5081 + struct interface *ifp = vty->index;
5082 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5083 + struct ldp_interface *li = mi->ldp;
5084 + struct mpls *mpls = mi->mpls;
5085 + struct ldp *ldp = mpls->ldp;
5087 + li->entity.hop_count_limit = atoi(argv[0]);
5088 + if (!ldp) {
5089 + li->create_on_hold = MPLS_BOOL_TRUE;
5090 + return CMD_SUCCESS;
5093 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_HOPCOUNT_LIMIT);
5094 + return CMD_SUCCESS;
5097 +DEFUN(no_ldp_if_max_hop_count,
5098 + no_ldp_if_max_hop_count_cmd,
5099 + "no max-hop-count",
5100 + NO_STR
5101 + "MPLS interface configuration\n"
5102 + "maximum hop count\n") {
5103 + struct interface *ifp = vty->index;
5104 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5105 + struct ldp_interface *li = mi->ldp;
5106 + struct mpls *mpls = mi->mpls;
5107 + struct ldp *ldp = mpls->ldp;
5109 + li->entity.hop_count_limit = LDP_ENTITY_DEF_HOPCOUNT_LIMIT;
5110 + if (!ldp) {
5111 + li->create_on_hold = MPLS_BOOL_TRUE;
5112 + return CMD_SUCCESS;
5115 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_HOPCOUNT_LIMIT);
5116 + return CMD_SUCCESS;
5119 +DEFUN(ldp_if_max_label_requests,
5120 + ldp_if_max_label_requests_cmd,
5121 + "max-label-requests <0-1024>",
5122 + "MPLS interface configuration\n"
5123 + "maximum times to make a request for a FEC\n"
5124 + "Number of attempts (0 means keep trying)\n") {
5125 + struct interface *ifp = vty->index;
5126 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5127 + struct ldp_interface *li = mi->ldp;
5128 + struct mpls *mpls = mi->mpls;
5129 + struct ldp *ldp = mpls->ldp;
5131 + li->entity.label_request_count = atoi(argv[0]);
5132 + if (!ldp) {
5133 + li->create_on_hold = MPLS_BOOL_TRUE;
5134 + return CMD_SUCCESS;
5137 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REQUEST_COUNT);
5138 + return CMD_SUCCESS;
5141 +DEFUN(no_ldp_if_max_label_requests,
5142 + no_ldp_if_max_label_requests_cmd,
5143 + "no max-label-requests",
5144 + NO_STR
5145 + "MPLS interface configuration\n"
5146 + "maximum times to make a request for a FEC\n") {
5147 + struct interface *ifp = vty->index;
5148 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5149 + struct ldp_interface *li = mi->ldp;
5150 + struct mpls *mpls = mi->mpls;
5151 + struct ldp *ldp = mpls->ldp;
5153 + li->entity.label_request_count = LDP_ENTITY_DEF_REQUEST_COUNT;
5154 + if (!ldp) {
5155 + li->create_on_hold = MPLS_BOOL_TRUE;
5156 + return CMD_SUCCESS;
5159 + ldp_cfg_entity_set(ldp->h, &li->entity, LDP_ENTITY_CFG_REQUEST_COUNT);
5160 + return CMD_SUCCESS;
5163 +#if 0
5164 +DEFUN(ldp_if_ttl_less_domain,
5165 + ldp_if_ttl_less_domain_cmd,
5166 + "ttl-less-domain",
5167 + "MPLS interface configuration\n"
5168 + "TTL less domain\n") {
5169 + struct interface *ifp = vty->index;
5170 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5171 + struct ldp_interface *li = mi->ldp;
5172 + struct mpls *mpls = mi->mpls;
5173 + struct ldp *ldp = mpls->ldp;
5175 + li->entity.remote_in_ttl_less_domain = MPLS_BOOL_TRUE;
5176 + if (!ldp) {
5177 + li->create_on_hold = MPLS_BOOL_TRUE;
5178 + return CMD_SUCCESS;
5181 + return CMD_SUCCESS;
5184 +DEFUN(no_ldp_if_ttl_less_domain,
5185 + no_ldp_if_ttl_less_domain_cmd,
5186 + "no ttl-less-domain",
5187 + NO_STR
5188 + "MPLS interface configuration\n"
5189 + "TTL less domain\n") {
5190 + struct interface *ifp = vty->index;
5191 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
5192 + struct ldp_interface *li = mi->ldp;
5193 + struct mpls *mpls = mi->mpls;
5194 + struct ldp *ldp = mpls->ldp;
5196 + li->entity.remote_in_ttl_less_domain = MPLS_BOOL_FALSE;
5197 + if (!ldp) {
5198 + return CMD_SUCCESS;
5201 + return CMD_SUCCESS;
5203 +#endif
5205 +static int ldp_if_config_write (struct vty *vty) {
5206 + return 0;
5209 +static int ldp_config_write (struct vty *vty) {
5210 + struct mpls *mpls = mpls_get();
5211 + struct ldp *ldp = mpls->ldp;
5212 + struct ldp_remote_peer *rp;
5213 + struct listnode *ln;
5214 + ldp_global g;
5215 + int write = 0;
5216 + struct in_addr addr;
5218 + if (ldp) {
5219 + vty_out (vty, "!%s", VTY_NEWLINE);
5220 + vty_out (vty, "mpls ldp%s", VTY_NEWLINE);
5221 + write++;
5223 + LIST_LOOP(ldp->peer_list,rp,ln) {
5224 + addr.s_addr = htonl(rp->peer.dest.addr.u.ipv4);
5225 + vty_out (vty, " peer %s%s", inet_ntoa(addr), VTY_NEWLINE);
5228 + if (ldp_traceflags & LDP_TRACE_FLAG_ADDRESS)
5229 + vty_out (vty, " trace address%s", VTY_NEWLINE);
5230 + if (ldp_traceflags & LDP_TRACE_FLAG_BINDING)
5231 + vty_out (vty, " trace binding%s", VTY_NEWLINE);
5232 + if (ldp_traceflags & LDP_TRACE_FLAG_DEBUG)
5233 + vty_out (vty, " trace debug%s", VTY_NEWLINE);
5234 + if (ldp_traceflags & LDP_TRACE_FLAG_ERROR)
5235 + vty_out (vty, " trace error%s", VTY_NEWLINE);
5236 + if (ldp_traceflags & LDP_TRACE_FLAG_EVENT)
5237 + vty_out (vty, " trace event%s", VTY_NEWLINE);
5238 + if (ldp_traceflags & LDP_TRACE_FLAG_GENERAL)
5239 + vty_out (vty, " trace general%s", VTY_NEWLINE);
5240 + if (ldp_traceflags & LDP_TRACE_FLAG_INIT)
5241 + vty_out (vty, " trace init%s", VTY_NEWLINE);
5242 + if (ldp_traceflags & LDP_TRACE_FLAG_LABEL)
5243 + vty_out (vty, " trace label%s", VTY_NEWLINE);
5244 + if (ldp_traceflags & LDP_TRACE_FLAG_NORMAL)
5245 + vty_out (vty, " trace normal%s", VTY_NEWLINE);
5246 + if (ldp_traceflags & LDP_TRACE_FLAG_NOTIF)
5247 + vty_out (vty, " trace notification%s", VTY_NEWLINE);
5248 + if (ldp_traceflags & LDP_TRACE_FLAG_PACKET_DUMP)
5249 + vty_out (vty, " trace packet-dump%s", VTY_NEWLINE);
5250 + if (ldp_traceflags & LDP_TRACE_FLAG_PACKET)
5251 + vty_out (vty, " trace packet%s", VTY_NEWLINE);
5252 + if (ldp_traceflags & LDP_TRACE_FLAG_PATH)
5253 + vty_out (vty, " trace path%s", VTY_NEWLINE);
5254 + if (ldp_traceflags & LDP_TRACE_FLAG_PERIODIC)
5255 + vty_out (vty, " trace periodic%s", VTY_NEWLINE);
5256 + if (ldp_traceflags & LDP_TRACE_FLAG_POLICY)
5257 + vty_out (vty, " trace policy%s", VTY_NEWLINE);
5258 + if (ldp_traceflags & LDP_TRACE_FLAG_ROUTE)
5259 + vty_out (vty, " trace route%s", VTY_NEWLINE);
5260 + if (ldp_traceflags & LDP_TRACE_FLAG_STATE)
5261 + vty_out (vty, " trace state%s", VTY_NEWLINE);
5262 + if (ldp_traceflags & LDP_TRACE_FLAG_TASK)
5263 + vty_out (vty, " trace task%s", VTY_NEWLINE);
5264 + if (ldp_traceflags & LDP_TRACE_FLAG_TIMER)
5265 + vty_out (vty, " trace timer%s", VTY_NEWLINE);
5267 + ldp_cfg_global_get(ldp->h,&g, 0xFFFFFFFF);
5269 + if (g.lsp_control_mode != LDP_GLOBAL_DEF_CONTROL_MODE) {
5270 + vty_out (vty, " lsp-control-mode ");
5271 + if (g.lsp_control_mode == LDP_CONTROL_INDEPENDENT) {
5272 + vty_out (vty, "independent%s", VTY_NEWLINE);
5273 + } else {
5274 + vty_out (vty, "ordered%s", VTY_NEWLINE);
5277 + if (g.label_retention_mode != LDP_GLOBAL_DEF_RETENTION_MODE) {
5278 + vty_out (vty, " label-retention-mode ");
5279 + if (g.label_retention_mode == LDP_RETENTION_LIBERAL) {
5280 + vty_out (vty, "liberal%s", VTY_NEWLINE);
5281 + } else {
5282 + vty_out (vty, "conservative%s", VTY_NEWLINE);
5285 + if (g.lsp_repair_mode != LDP_GLOBAL_DEF_REPAIR_MODE) {
5286 + vty_out (vty, " lsp-repair-mode ");
5287 + if (g.lsp_repair_mode == LDP_REPAIR_LOCAL) {
5288 + vty_out (vty, "local%s", VTY_NEWLINE);
5289 + } else {
5290 + vty_out (vty, "global%s", VTY_NEWLINE);
5293 + if (g.propagate_release != LDP_GLOBAL_DEF_PROPOGATE_RELEASE) {
5294 + if (g.propagate_release == MPLS_BOOL_TRUE) {
5295 + vty_out (vty, " propagate-release%s", VTY_NEWLINE);
5296 + } else {
5297 + vty_out (vty, " no propagate-release%s", VTY_NEWLINE);
5300 + if (g.label_merge != LDP_GLOBAL_DEF_LABEL_MERGE) {
5301 + if (g.label_merge == MPLS_BOOL_TRUE) {
5302 + vty_out (vty, " label-merge%s", VTY_NEWLINE);
5303 + } else {
5304 + vty_out (vty, " no label-merge%s", VTY_NEWLINE);
5307 + if (g.loop_detection_mode != LDP_GLOBAL_DEF_LOOP_DETECTION_MODE) {
5308 + if (g.loop_detection_mode == LDP_LOOP_HOPCOUNT) {
5309 + vty_out (vty, " loop-detection-mode hop%s", VTY_NEWLINE);
5310 + } else if (g.loop_detection_mode == LDP_LOOP_PATHVECTOR) {
5311 + vty_out (vty, " loop-detection-mode path%s", VTY_NEWLINE);
5312 + } else if (g.loop_detection_mode == LDP_LOOP_HOPCOUNT_PATHVECTOR) {
5313 + vty_out (vty, " loop-detection-mode both%s", VTY_NEWLINE);
5314 + } else {
5315 + vty_out (vty, " no loop-detection-mode%s", VTY_NEWLINE);
5318 + if (g.ttl_less_domain != MPLS_BOOL_FALSE) {
5319 + vty_out (vty, " ttl-less-domain%s", VTY_NEWLINE);
5321 + if (g.local_tcp_port != LDP_GLOBAL_DEF_LOCAL_TCP_PORT) {
5322 + vty_out (vty, " local-tcp-port %d%s", g.local_tcp_port, VTY_NEWLINE);
5324 + if (g.local_udp_port != LDP_GLOBAL_DEF_LOCAL_UDP_PORT) {
5325 + vty_out (vty, " local-udp-port %d%s", g.local_udp_port, VTY_NEWLINE);
5328 + switch (ldp->egress) {
5329 + case LDP_EGRESS_LSRID:
5330 + vty_out (vty, " egress lsr-id%s", VTY_NEWLINE);
5331 + break;
5332 + case LDP_EGRESS_CONNECTED:
5333 + vty_out (vty, " egress connected%s", VTY_NEWLINE);
5334 + break;
5335 + default:
5336 + break;
5339 + switch (ldp->address) {
5340 + case LDP_ADDRESS_LSRID:
5341 + vty_out (vty, " address-mode lsr-id%s", VTY_NEWLINE);
5342 + break;
5343 + case LDP_ADDRESS_LDP:
5344 + vty_out (vty, " address-mode ldp%s", VTY_NEWLINE);
5345 + break;
5346 + default:
5347 + break;
5350 + return write;
5353 +int ldp_interface_config_write(struct vty *vty, struct mpls_interface *mi) {
5354 + struct ldp_interface *li;
5355 + struct mpls *mpls;
5356 + struct ldp *ldp;
5357 + ldp_entity e;
5358 + int write = 0;
5360 + if (mi && mi->ldp) {
5361 + li = mi->ldp;
5362 + mpls = mi->mpls;
5363 + ldp = mpls->ldp;
5365 + if (li->entity.index) {
5366 + e.index = li->entity.index;
5367 + ldp_cfg_entity_get(ldp->h, &e, 0xFFFFFFFF);
5368 + } else {
5369 + memcpy(&e,&li->entity,sizeof(ldp_entity));
5372 + vty_out(vty, " mpls ldp%s", VTY_NEWLINE);
5373 + write++;
5375 + if (e.label_distribution_mode != LDP_ENTITY_DEF_DISTRIBUTION_MODE) {
5376 + vty_out(vty, " distribution-mode ");
5377 + if (e.label_distribution_mode == LDP_DISTRIBUTION_ONDEMAND) {
5378 + vty_out(vty, "dod%s", VTY_NEWLINE);
5379 + } else {
5380 + vty_out(vty, "du%s", VTY_NEWLINE);
5383 + if (e.remote_tcp_port != LDP_ENTITY_DEF_REMOTE_TCP) {
5384 + vty_out(vty, " remote-tcp-port %d%s", e.remote_tcp_port,
5385 + VTY_NEWLINE);
5387 + if (e.remote_udp_port != LDP_ENTITY_DEF_REMOTE_UDP) {
5388 + vty_out(vty, " remote-udp-port %d%s", e.remote_udp_port,
5389 + VTY_NEWLINE);
5391 + if (e.max_pdu != LDP_ENTITY_DEF_MAX_PDU) {
5392 + vty_out(vty, " max-pdu %d%s", e.max_pdu, VTY_NEWLINE);
5394 + if (e.hellotime_interval != LDP_ENTITY_DEF_HELLOTIME_INTERVAL) {
5395 + vty_out(vty, " hello-interval %d%s", e.hellotime_interval,
5396 + VTY_NEWLINE);
5398 + if (e.keepalive_interval != LDP_ENTITY_DEF_KEEPALIVE_INTERVAL) {
5399 + vty_out(vty, " keepalive-interval %d%s",
5400 + e.keepalive_interval, VTY_NEWLINE);
5402 + if (e.session_setup_count != LDP_ENTITY_DEF_SESSIONSETUP_COUNT) {
5403 + vty_out(vty, " max-session-attempt %d%s",
5404 + e.session_setup_count, VTY_NEWLINE);
5406 + if (e.path_vector_limit != LDP_ENTITY_DEF_PATHVECTOR_LIMIT) {
5407 + vty_out(vty, " max-path-vector %d%s",
5408 + e.path_vector_limit, VTY_NEWLINE);
5410 + if (e.hop_count_limit != LDP_ENTITY_DEF_HOPCOUNT_LIMIT) {
5411 + vty_out(vty, " max-hop-count %d%s",
5412 + e.hop_count_limit, VTY_NEWLINE);
5414 + if (e.label_request_count != LDP_ENTITY_DEF_REQUEST_COUNT) {
5415 + vty_out(vty, " max-label-requests %d%s",
5416 + e.label_request_count, VTY_NEWLINE);
5418 + vty_out(vty, " !%s",VTY_NEWLINE);
5421 + return write;
5424 +void ldp_vty_show_init() {
5426 + install_element(VIEW_NODE, &mpls_show_ldp_cmd);
5427 + install_element(ENABLE_NODE, &mpls_show_ldp_cmd);
5429 + install_element(VIEW_NODE, &mpls_show_ldp_neighbor_cmd);
5430 + install_element(ENABLE_NODE, &mpls_show_ldp_neighbor_cmd);
5432 + install_element(VIEW_NODE, &mpls_show_ldp_session_cmd);
5433 + install_element(ENABLE_NODE, &mpls_show_ldp_session_cmd);
5435 + install_element(VIEW_NODE, &mpls_show_ldp_discovery_cmd);
5436 + install_element(ENABLE_NODE, &mpls_show_ldp_discovery_cmd);
5438 + install_element(VIEW_NODE, &mpls_show_ldp_database_cmd);
5439 + install_element(ENABLE_NODE, &mpls_show_ldp_database_cmd);
5442 +static struct cmd_node ldp_if_node = {MPLS_LDP_IF_NODE,"%s(config-if-ldp)# ",1};
5444 +void ldp_vty_if_init() {
5446 + install_node (&ldp_if_node, ldp_if_config_write);
5447 + install_default (MPLS_LDP_IF_NODE);
5449 + install_element(INTERFACE_NODE,&ldp_intf_cmd);
5450 + install_element(INTERFACE_NODE,&no_ldp_intf_cmd);
5452 + install_element(MPLS_LDP_IF_NODE,&ldp_l2cc_intf_cmd);
5453 + install_element(MPLS_LDP_IF_NODE,&no_ldp_l2cc_intf_cmd);
5455 + install_element(MPLS_LDP_IF_NODE,&ldp_if_remote_tcp_port_cmd);
5456 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_remote_tcp_port_cmd);
5458 + install_element(MPLS_LDP_IF_NODE,&ldp_if_remote_udp_port_cmd);
5459 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_remote_udp_port_cmd);
5461 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_pdu_cmd);
5462 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_pdu_cmd);
5464 + install_element(MPLS_LDP_IF_NODE,&ldp_if_hello_interval_cmd);
5465 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_hello_interval_cmd);
5467 + install_element(MPLS_LDP_IF_NODE,&ldp_if_keepalive_interval_cmd);
5468 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_keepalive_interval_cmd);
5470 +#if 0
5471 + install_element(MPLS_LDP_IF_NODE,&ldp_if_loop_detect_mode_cmd);
5472 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_loop_detect_mode_cmd);
5473 +#endif
5475 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_session_attempt_cmd);
5476 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_session_attempt_cmd);
5478 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_path_vector_cmd);
5479 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_path_vector_cmd);
5481 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_hop_count_cmd);
5482 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_hop_count_cmd);
5484 + install_element(MPLS_LDP_IF_NODE,&ldp_if_max_label_requests_cmd);
5485 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_max_label_requests_cmd);
5487 + install_element(MPLS_LDP_IF_NODE,&ldp_if_distribution_mode_cmd);
5488 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_distribution_mode_cmd);
5490 +#if 0
5491 + install_element(MPLS_LDP_IF_NODE,&ldp_if_ttl_less_domain_cmd);
5492 + install_element(MPLS_LDP_IF_NODE,&no_ldp_if_ttl_less_domain_cmd);
5493 +#endif
5496 +static struct cmd_node ldp_node = {MPLS_LDP_NODE,"%s(config-ldp)# ",1};
5498 +void ldp_vty_init () {
5500 + install_node (&ldp_node, ldp_config_write);
5501 + install_default (MPLS_LDP_NODE);
5503 + install_element (CONFIG_NODE, &mpls_ldp_cmd);
5504 + install_element (CONFIG_NODE, &no_mpls_ldp_cmd);
5506 + install_element (MPLS_LDP_NODE, &ldp_remote_peer_cmd);
5507 + install_element (MPLS_LDP_NODE, &no_ldp_remote_peer_cmd);
5509 + install_element (MPLS_LDP_NODE, &mpls_ldp_disable_cmd);
5510 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_disable_cmd);
5512 + install_element (MPLS_LDP_NODE, &mpls_ldp_lsrid_cmd);
5513 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_lsrid_cmd);
5515 + install_element (MPLS_LDP_NODE, &mpls_ldp_lsp_control_mode_cmd);
5516 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_lsp_control_mode_cmd);
5518 + install_element (MPLS_LDP_NODE, &mpls_ldp_label_retention_mode_cmd);
5519 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_label_retention_mode_cmd);
5521 + install_element (MPLS_LDP_NODE, &mpls_ldp_lsp_repair_mode_cmd);
5522 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_lsp_repair_mode_cmd);
5524 + install_element (MPLS_LDP_NODE, &mpls_ldp_propogate_release_cmd);
5525 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_propogate_release_cmd);
5527 + install_element (MPLS_LDP_NODE, &mpls_ldp_label_merge_cmd);
5528 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_label_merge_cmd);
5530 + install_element (MPLS_LDP_NODE, &mpls_ldp_loop_detection_mode_cmd);
5531 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_loop_detection_mode_cmd);
5533 + install_element (MPLS_LDP_NODE, &mpls_ldp_ttl_less_domain_cmd);
5534 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_ttl_less_domain_cmd);
5536 + install_element (MPLS_LDP_NODE, &mpls_ldp_local_tcp_port_cmd);
5537 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_local_tcp_port_cmd);
5539 + install_element (MPLS_LDP_NODE, &mpls_ldp_local_udp_port_cmd);
5540 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_local_udp_port_cmd);
5542 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_address_cmd);
5543 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_binding_cmd);
5544 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_debug_cmd);
5545 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_error_cmd);
5546 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_event_cmd);
5547 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_general_cmd);
5548 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_init_cmd);
5549 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_label_cmd);
5550 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_normal_cmd);
5551 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_notif_cmd);
5552 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_packet_dump_cmd);
5553 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_packet_cmd);
5554 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_path_cmd);
5555 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_periodic_cmd);
5556 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_policy_cmd);
5557 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_route_cmd);
5558 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_state_cmd);
5559 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_task_cmd);
5560 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_timer_cmd);
5561 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_all_cmd);
5562 + install_element (MPLS_LDP_NODE, &mpls_ldp_trace_none_cmd);
5564 + install_element (MPLS_LDP_NODE, &mpls_ldp_egress_cmd);
5565 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_egress_cmd);
5566 + install_element (MPLS_LDP_NODE, &mpls_ldp_address_cmd);
5567 + install_element (MPLS_LDP_NODE, &no_mpls_ldp_address_cmd);
5569 diff --exclude=.p4config -uNr zebra/mplsd/ldp_vty.h zebra-ldp/mplsd/ldp_vty.h
5570 --- zebra/mplsd/ldp_vty.h 1969-12-31 18:00:00.000000000 -0600
5571 +++ zebra-ldp/mplsd/ldp_vty.h 2003-03-10 14:57:28.000000000 -0600
5572 @@ -0,0 +1,11 @@
5573 +#ifndef LDP_VTY_H
5574 +#define LDP_VTY_H
5576 +#include "mpls_interface.h"
5578 +int ldp_interface_config_write(struct vty *vty, struct mpls_interface *mi);
5579 +void ldp_vty_show_init();
5580 +void ldp_vty_if_init();
5581 +void ldp_vty_init();
5583 +#endif
5584 diff --exclude=.p4config -uNr zebra/mplsd/Makefile.am zebra-ldp/mplsd/Makefile.am
5585 --- zebra/mplsd/Makefile.am 1969-12-31 18:00:00.000000000 -0600
5586 +++ zebra-ldp/mplsd/Makefile.am 2003-03-29 01:12:02.000000000 -0600
5587 @@ -0,0 +1,68 @@
5588 +## Process this file with automake to produce Makefile.in.
5590 +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib
5591 +DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\"
5592 +INSTALL_SDATA=@INSTALL@ -m 600
5594 +sbin_PROGRAMS = mplsd
5596 +mplsd_SOURCES = \
5597 +impl_fib.c impl_ifmgr.c impl_lock.c impl_mm.c impl_mpls.c \
5598 +impl_policy.c impl_socket.c impl_timer.c impl_tree.c \
5599 +mpls.c mpls_interface.c mpls_zebra.c mpls_main.c mpls_vty.c\
5600 +static.c static_vty.c \
5601 +ldp.c ldp_interface.c ldp_vty.c ldp_remote_peer.c l2cc_interface.c \
5602 +ldp_addr.c ldp_adj.c \
5603 +ldp_attr.c ldp_buf.c ldp_cfg.c ldp_entity.c ldp_fec.c ldp_global.c \
5604 +ldp_hello.c ldp_hop.c ldp_hop_list.c ldp_if.c ldp_inet_addr.c \
5605 +ldp_init.c ldp_inlabel.c ldp_keepalive.c ldp_label_abort.c \
5606 +ldp_label_mapping.c ldp_label_rel_with.c ldp_label_request.c \
5607 +ldp_mesg.c ldp_nortel.c ldp_notif.c ldp_outlabel.c \
5608 +ldp_pdu_setup.c ldp_peer.c ldp_l2cc.c \
5609 +ldp_resource.c ldp_session.c ldp_state_funcs.c \
5610 +ldp_state_machine.c ldp_tunnel.c \
5611 +mpls_compare.c \
5612 +lsr_cfg.c lsr_global.c lsr_if.c lsr_insegment.c lsr_labelmanager.c \
5613 +lsr_outsegment.c lsr_xconnect.c lsr_ftn.c \
5614 +rsvpte.c rsvpte_vty.c rsvpte_interface.c
5617 +noinst_HEADERS = \
5618 +mpls.h mpls_interface.h mpls_zebra.h mpls_vty.h \
5619 +ldp.h ldp_interface.h ldp_vty.h ldp_remote_peer.h l2cc_interface.h \
5620 +static.h static_vty.h \
5621 +ldp_addr.h ldp_adj.h ldp_attr.h ldp_buf.h ldp_cfg.h \
5622 +ldp_defaults.h ldp_entity.h ldp_fec.h \
5623 +ldp_global.h mpls_handle_type.h ldp_hello.h ldp_hop.h \
5624 +ldp_hop_list.h ldp_if.h ldp_inet_addr.h \
5625 +ldp_init.h ldp_inlabel.h ldp_keepalive.h ldp_label_abort.h \
5626 +ldp_label_mapping.h ldp_label_rel_with.h ldp_label_request.h \
5627 +ldp_mesg.h ldp_nortel.h ldp_notif.h ldp_outlabel.h ldp_pdu.h \
5628 +ldp_pdu_setup.h ldp_peer.h ldp_l2cc.h mpls_refcnt.h ldp_resource.h \
5629 +ldp_session.h ldp_state_machine.h ldp_struct.h ldp_tunnel.h \
5630 +mpls_tree_impl.h mpls_mm_impl.h mpls_mpls_impl.h mpls_trace_impl.h \
5631 +mpls_assert.h mpls_fib_impl.h mpls_ifmgr_impl.h mpls_list.h mpls_lock_impl.h \
5632 +mpls_policy_impl.h mpls_socket_impl.h mpls_timer_impl.h mpls_trace.h \
5633 +mpls_struct.h mpls_compare.h \
5634 +lsr_cfg.h lsr_defaults.h lsr_global.h lsr_if.h lsr_insegment.h \
5635 +lsr_labelmanager.h lsr_outsegment.h lsr_struct.h lsr_xconnect.h lsr_ftn.h \
5636 +rsvpte.h rsvpte_vty.h rsvpte_interface.h
5638 +mplsd_LDADD = ../lib/libzebra.a
5640 +sysconf_DATA = mplsd.conf.sample
5642 +EXTRA_DIST = $(sysconf_DATA)
5644 +install-sysconfDATA: $(sysconf_DATA)
5645 + @$(NORMAL_INSTALL)
5646 + $(mkinstalldirs) $(DESTDIR)$(sysconfdir)
5647 + @list='$(sysconf_DATA)'; for p in $$list; do \
5648 + if test -f $(srcdir)/$$p; then \
5649 + echo " $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p"; \
5650 + $(INSTALL_SDATA) $(srcdir)/$$p $(DESTDIR)$(sysconfdir)/$$p; \
5651 + else if test -f $$p; then \
5652 + echo " $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p"; \
5653 + $(INSTALL_SDATA) $$p $(DESTDIR)$(sysconfdir)/$$p; \
5654 + fi; fi; \
5655 + done
5656 diff --exclude=.p4config -uNr zebra/mplsd/mpls.c zebra-ldp/mplsd/mpls.c
5657 --- zebra/mplsd/mpls.c 1969-12-31 18:00:00.000000000 -0600
5658 +++ zebra-ldp/mplsd/mpls.c 2003-03-29 01:12:03.000000000 -0600
5659 @@ -0,0 +1,81 @@
5660 +#include <zebra.h>
5662 +#include "thread.h"
5663 +#include "memory.h"
5664 +#include "prefix.h"
5665 +#include "table.h"
5666 +#include "linklist.h"
5667 +#include "filter.h"
5668 +#include "vty.h"
5669 +#include "plist.h"
5671 +#include "mpls.h"
5672 +#include "ldp.h"
5673 +#include "rsvpte.h"
5674 +#include "static.h"
5675 +#include "lsr_cfg.h"
5677 +/* MPLS instance top. */
5678 +struct mpls *mpls_top = NULL;
5680 +struct mpls *mpls_new() {
5681 + lsr_global global;
5682 + struct mpls *new = XMALLOC(MTYPE_MPLS_TOP, sizeof (struct mpls));
5684 + memset(new,0,sizeof(*new));
5686 + new->h = lsr_cfg_open(new);
5687 + global.admin_state = MPLS_ADMIN_ENABLE;
5688 + lsr_cfg_global_set(new->h, &global, LSR_GLOBAL_CFG_ADMIN_STATE);
5690 + new->router_id.family = AF_INET;
5691 + new->router_id.prefixlen = 32;
5693 + new->iflist = iflist;
5694 + new->table = route_table_init();
5696 + return new;
5699 +struct mpls *mpls_get() {
5700 + if (mpls_top) {
5701 + return mpls_top;
5704 + mpls_top = mpls_new();
5705 + return mpls_top;
5708 +void mpls_finish(struct mpls *mpls) {
5710 + lsr_global global;
5712 + ldp_finish(mpls->ldp);
5713 + static_finish(mpls->mstatic);
5714 + rsvpte_finish(mpls->rsvpte);
5716 + global.admin_state = MPLS_ADMIN_DISABLE;
5717 + lsr_cfg_global_set(mpls->h, &global, LSR_GLOBAL_CFG_ADMIN_STATE);
5718 + lsr_cfg_close(mpls->h);
5720 + XFREE(MTYPE_MPLS_TOP, mpls);
5721 + mpls_top = NULL;
5724 +/* Update access-list list. */
5725 +void mpls_access_list_update(struct access_list *access) {
5728 +/* Update prefix-list list. */
5729 +void mpls_prefix_list_update(struct prefix_list *plist) {
5732 +void mpls_init() {
5734 +#if 0
5735 + access_list_init();
5736 + access_list_add_hook(mpls_access_list_update);
5737 + access_list_delete_hook(mpls_access_list_update);
5738 +#endif
5741 diff --exclude=.p4config -uNr zebra/mplsd/mplsd.conf.sample zebra-ldp/mplsd/mplsd.conf.sample
5742 --- zebra/mplsd/mplsd.conf.sample 1969-12-31 18:00:00.000000000 -0600
5743 +++ zebra-ldp/mplsd/mplsd.conf.sample 2003-03-10 14:57:29.000000000 -0600
5744 @@ -0,0 +1,17 @@
5746 +! Zebra configuration saved from vty
5747 +! 2002/03/23 17:07:30
5749 +hostname uml-1
5750 +password root
5751 +enable password root
5753 +mpls ldp
5755 +interface lo
5757 +interface eth0
5758 + mpls ldp
5760 +line vty
5762 diff --exclude=.p4config -uNr zebra/mplsd/mpls.h zebra-ldp/mplsd/mpls.h
5763 --- zebra/mplsd/mpls.h 1969-12-31 18:00:00.000000000 -0600
5764 +++ zebra-ldp/mplsd/mpls.h 2003-03-29 01:12:03.000000000 -0600
5765 @@ -0,0 +1,44 @@
5766 +#ifndef _MPLSD_H
5767 +#define _MPLSD_H
5769 +#include "sockunion.h"
5770 +#include "prefix.h"
5771 +#include "zclient.h"
5772 +#include "linklist.h"
5773 +#include "if.h"
5775 +#include "ldp.h"
5776 +#include "static.h"
5777 +#include "rsvpte.h"
5779 +#define MPLS_DEFAULT_CONFIG "mplsd.conf"
5781 +#define MPLS_VTY_PORT 2610
5782 +#define MPLS_VTYSH_PATH "/tmp/.mplsd"
5784 +enum mplsd_instr_types {
5785 + MPLS_FWD = 1,
5786 + MPLS_PUSH,
5787 + MPLS_SET
5790 +struct mplsd_set {
5791 + char ifname[INTERFACE_NAMSIZ + 1];
5792 + union sockunion nexthop;
5795 +struct mpls {
5796 + list iflist;
5797 + mpls_cfg_handle h;
5798 + struct route_table *table;
5799 + struct ldp *ldp;
5800 + struct rsvpte *rsvpte;
5801 + struct mpls_static *mstatic;
5802 + struct prefix router_id;
5803 + ldp_fib_callback fib_callback;
5806 +void mpls_init();
5807 +struct mpls *mpls_get();
5809 +#endif
5810 diff --exclude=.p4config -uNr zebra/mplsd/mpls_handle_type.h zebra-ldp/mplsd/mpls_handle_type.h
5811 --- zebra/mplsd/mpls_handle_type.h 1969-12-31 18:00:00.000000000 -0600
5812 +++ zebra-ldp/mplsd/mpls_handle_type.h 2003-03-10 14:57:28.000000000 -0600
5813 @@ -0,0 +1,94 @@
5814 +#ifndef _LDP_HANDLE_TYPE_H_
5815 +#define _LDP_HANDLE_TYPE_H_
5817 +#define MPLS_USE_LSR 1
5819 +#if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0))
5820 +#if 0
5821 +typedef unsigned char uint8_t;
5822 +typedef unsigned short uint16_t;
5823 +typedef unsigned int uint32_t;
5824 +#endif
5825 +#else
5826 +#include <stdint.h>
5827 +#endif
5829 +#include <zebra.h>
5830 +#include "if.h"
5832 +struct ldp;
5833 +struct ldp_timer;
5834 +struct ldp_socket;
5836 +#define ptr_verify(x) (x ? MPLS_BOOL_TRUE : MPLS_BOOL_FALSE)
5838 +typedef void *mpls_tree_handle;
5839 +#define mpls_tree_handle_compare(x,y) (x != y)
5840 +#define mpls_tree_handle_verify(x) ptr_verify(x)
5842 +typedef void *mpls_instance_handle;
5843 +#define mpls_instance_handle_compare(x,y) (x != y)
5844 +#define mpls_instance_handle_verify(x) ptr_verify(x)
5846 +typedef struct mpls* mpls_fib_handle;
5847 +#define mpls_fib_handle_compare(x,y) (x == y)
5848 +#define mpls_fib_handle_verify(x) ptr_verify(x)
5850 +typedef int mpls_ifmgr_handle;
5851 +#define mpls_ifmgr_handle_compare(x,y) (x == y)
5852 +#define mpls_ifmgr_handle_verify(x) ptr_verify(x)
5854 +typedef struct interface* mpls_if_handle;
5855 +#define mpls_if_handle_compare(x,y) \
5856 + ((x->ifindex == y->ifindex) ? 0 : (x->ifindex > y->ifindex ? 1 : -1))
5857 +#define mpls_if_handle_verify(m,x) ptr_verify(x)
5859 +typedef int mpls_timer_mgr_handle;
5860 +#define mpls_timer_mgr_handle_compare(x,y) (x != y)
5861 +#define mpls_timer_mgr_handle_verify(x) ptr_verify(x)
5863 +typedef struct mpls_timer* mpls_timer_handle;
5864 +#define mpls_timer_handle_compare(x,y) (x != y)
5865 +#define mpls_timer_handle_verify(m,x) ptr_verify(x)
5867 +typedef int mpls_socket_mgr_handle;
5868 +#define mpls_socket_mgr_handle_compare(x,y) (x != y)
5869 +#define mpls_socket_mgr_handle_verify(x) MPLS_BOOL_TRUE
5871 +typedef struct mpls_socket* mpls_socket_handle;
5872 +#define mpls_socket_handle_compare(x,y) (x->fd != y->fd)
5873 +#define mpls_socket_handle_verify(m,x) ptr_verify(x)
5875 +typedef int mpls_mpls_handle;
5876 +#define mpls_mpls_handle_compare(x,y) (x != y)
5877 +#define mpls_mpls_handle_verify(x) ptr_verify(x)
5879 +typedef int mpls_insegment_handle;
5880 +#define mpls_insegment_handle_compare(x,y) (x != y)
5881 +#define mpls_insegment_handle_verify(m,x) ptr_verify(x)
5883 +typedef int mpls_outsegment_handle;
5884 +#define mpls_outsegment_handle_compare(x,y) (x != y)
5885 +#define mpls_outsegment_handle_verify(m,x) ptr_verify(x)
5887 +typedef int mpls_xconnect_handle;
5888 +#define mpls_xconnect_handle_compare(x,y) (x != y)
5889 +#define mpls_xconnect_handle_verify(m,x) ptr_verify(x)
5891 +typedef int *mpls_lock_handle;
5892 +#define mpls_lock_handle_compare(x,y) (x != y)
5893 +#define mpls_lock_handle_verify(x) ptr_verify(x)
5895 +typedef int mpls_tunnel_handle;
5896 +#define mpls_tunnel_handle_compare(x,y) (x != y)
5898 +typedef int mpls_policy_handle;
5899 +#define mpls_policy_handle_compare(x,y) (x != y)
5901 +typedef int mpls_trace_handle;
5902 +#define mpls_trace_handle_compare(x,y) (x != y)
5904 +typedef char *mpls_lock_key_type;
5905 +typedef int mpls_size_type;
5907 +#endif
5908 diff --exclude=.p4config -uNr zebra/mplsd/mpls_interface.c zebra-ldp/mplsd/mpls_interface.c
5909 --- zebra/mplsd/mpls_interface.c 1969-12-31 18:00:00.000000000 -0600
5910 +++ zebra-ldp/mplsd/mpls_interface.c 2003-03-29 01:12:03.000000000 -0600
5911 @@ -0,0 +1,72 @@
5912 +#include <zebra.h>
5914 +#include "if.h"
5915 +#include "memory.h"
5917 +#include "mpls.h"
5918 +#include "mpls_interface.h"
5919 +#include "impl_mpls.h"
5921 +struct mpls_interface *mpls_if_new(struct interface *ifp) {
5922 + struct mpls_interface *mi;
5923 + struct mpls *mpls = mpls_get();
5925 + mi = XMALLOC(MTYPE_MPLS_IF, sizeof(struct mpls_interface));
5926 + memset(mi, 0, sizeof(struct mpls_interface));
5928 + /* Set zebra interface pointer. */
5929 + mi->ifp = ifp;
5930 + mi->labelspace = -1;
5932 + mi->mpls = mpls;
5933 + return mi;
5936 +void mpls_if_free(struct mpls_interface *mi) {
5937 + XFREE(MTYPE_MPLS_IF, mi);
5940 +int mpls_if_is_up(struct mpls_interface *mi) {
5941 + return if_is_up(mi->ifp);
5944 +int mpls_if_new_hook(struct interface *ifp) {
5945 + ifp->info = mpls_if_new(ifp);
5946 + return 0;
5949 +int mpls_if_delete_hook(struct interface *ifp) {
5950 + mpls_if_free(ifp->info);
5951 + ifp->info = NULL;
5952 + return 0;
5955 +int mpls_if_up(struct mpls_interface *mi) {
5956 + if (!mi) {
5957 + return 0;
5959 + if (mi->labelspace != -1) {
5960 + do_mpls_labelspace(mi);
5962 + ldp_if_up(mi);
5963 + l2cc_if_up(mi);
5964 + //static_if_up(mi);
5965 + return 1;
5968 +int mpls_if_down(struct mpls_interface *mi) {
5969 + if (!mi) {
5970 + return 0;
5972 + ldp_if_down(mi);
5973 + l2cc_if_down(mi);
5974 + //static_if_down(mi);
5975 + return 1;
5978 +void mpls_if_init() {
5979 + /* Initialize Zebra interface data structure. */
5980 + if_init();
5981 + if_add_hook(IF_NEW_HOOK, mpls_if_new_hook);
5982 + if_add_hook(IF_DELETE_HOOK, mpls_if_delete_hook);
5984 diff --exclude=.p4config -uNr zebra/mplsd/mpls_interface.h zebra-ldp/mplsd/mpls_interface.h
5985 --- zebra/mplsd/mpls_interface.h 1969-12-31 18:00:00.000000000 -0600
5986 +++ zebra-ldp/mplsd/mpls_interface.h 2003-03-29 01:12:03.000000000 -0600
5987 @@ -0,0 +1,37 @@
5988 +#ifndef MPLS_INTERFACE_H
5989 +#define MPLS_INTERFACE_H
5991 +#include <zebra.h>
5993 +#include "if.h"
5994 +#include "command.h"
5995 +#include "prefix.h"
5996 +#include "zclient.h"
5998 +#include "ldp.h"
5999 +#include "ldp_struct.h"
6000 +#include "ldp_interface.h"
6001 +#include "l2cc_interface.h"
6003 +struct mpls_interface {
6004 + struct mpls *mpls;
6006 + struct interface *ifp;
6007 + int labelspace;
6009 + struct connected *connected;
6011 + struct ldp_interface *ldp;
6012 + struct l2cc_interface *l2cc;
6013 + struct rsvpte_interface *rsvpte;
6014 +// struct static_interface static;
6017 +struct mpls_interface *mpls_if_new();
6018 +void mpls_if_free(struct mpls_interface *);
6019 +int mpls_if_is_up(struct mpls_interface *);
6020 +int mpls_if_up(struct mpls_interface *mi);
6021 +int mpls_if_down(struct mpls_interface *mi);
6022 +void mpls_if_init();
6024 +#endif
6025 diff --exclude=.p4config -uNr zebra/mplsd/mpls_main.c zebra-ldp/mplsd/mpls_main.c
6026 --- zebra/mplsd/mpls_main.c 1969-12-31 18:00:00.000000000 -0600
6027 +++ zebra-ldp/mplsd/mpls_main.c 2003-03-10 14:57:28.000000000 -0600
6028 @@ -0,0 +1,228 @@
6029 +#include <zebra.h>
6031 +#include "version.h"
6032 +#include "getopt.h"
6033 +#include "command.h"
6034 +#include "thread.h"
6035 +#include "filter.h"
6036 +#include "memory.h"
6037 +#include "prefix.h"
6038 +#include "log.h"
6040 +#include "mpls.h"
6041 +#include "mpls_vty.h"
6042 +#include "mpls_zebra.h"
6043 +#include "mpls_interface.h"
6045 +/* Configuration filename and directory. */
6046 +char config_current[] = MPLS_DEFAULT_CONFIG;
6047 +char config_default[] = SYSCONFDIR MPLS_DEFAULT_CONFIG;
6049 +/* Command line options. */
6050 +struct option longopts[] =
6052 + { "daemon", no_argument, NULL, 'd'},
6053 + { "config_file", required_argument, NULL, 'f'},
6054 + { "log_mode", no_argument, NULL, 'l'},
6055 + { "help", no_argument, NULL, 'h'},
6056 + { "vty_port", required_argument, NULL, 'P'},
6057 + { "vty_addr", required_argument, NULL, 'A'},
6058 + { "version", no_argument, NULL, 'v'},
6059 + { 0 }
6062 +/* Master of threads. */
6063 +struct thread_master *master = NULL;
6065 +/* Process ID saved for use by init system */
6066 +char *pid_file = PATH_MPLSD_PID;
6068 +/* Help information display. */
6069 +static void
6070 +usage (char *progname, int status)
6072 + if (status != 0)
6073 + fprintf (stderr, "Try `%s --help' for more information.\n", progname);
6074 + else
6075 + {
6076 + printf ("Usage : %s [OPTION...]\n\n\
6077 +Daemon which manages MPLS related configuration.\n\n\
6078 +-d, --daemon Runs in daemon mode\n\
6079 +-f, --config_file Set configuration file name\n\
6080 +-l, --log_mode Set verbose log mode flag\n\
6081 +-h, --help Display this help and exit\n\
6082 +-P, --vty_port Set vty's port number\n\
6083 +-A, --vty_addr Set vty's bind address\n\
6084 +-v, --version Print program version\n\
6085 +\n\
6086 +Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
6089 + exit (status);
6092 +/* SIGHUP handler. */
6093 +void
6094 +sighup (int sig)
6096 + zlog_info ("SIGHUP received");
6098 + /* Reload of config file. */
6102 +/* SIGINT handler. */
6103 +void
6104 +sigint (int sig)
6106 + zlog_info ("Terminating on signal");
6108 + exit (0);
6111 +/* SIGUSR1 handler. */
6112 +void
6113 +sigusr1 (int sig)
6115 + zlog_rotate (NULL);
6118 +/* Signale wrapper. */
6119 +RETSIGTYPE *
6120 +signal_set (int signo, void (*func)(int))
6122 + int ret;
6123 + struct sigaction sig;
6124 + struct sigaction osig;
6126 + sig.sa_handler = func;
6127 + sigemptyset (&sig.sa_mask);
6128 + sig.sa_flags = 0;
6129 +#ifdef SA_RESTART
6130 + sig.sa_flags |= SA_RESTART;
6131 +#endif /* SA_RESTART */
6133 + ret = sigaction (signo, &sig, &osig);
6135 + if (ret < 0)
6136 + return (SIG_ERR);
6137 + else
6138 + return (osig.sa_handler);
6141 +/* Initialization of signal handles. */
6142 +void
6143 +signal_init ()
6145 + signal_set (SIGHUP, sighup);
6146 + signal_set (SIGINT, sigint);
6147 + signal_set (SIGTERM, sigint);
6148 + signal_set (SIGPIPE, SIG_IGN);
6149 + signal_set (SIGUSR1, sigusr1);
6152 +/* Main startup routine. */
6153 +int
6154 +main (int argc, char **argv)
6156 + char *p;
6157 + int vty_port = 0;
6158 + char *vty_addr = NULL;
6159 + int daemon_mode = 0;
6160 + char *config_file = NULL;
6161 + char *progname;
6162 + struct thread thread;
6164 + /* Set umask before anything for security */
6165 + umask (0027);
6167 + /* preserve my name */
6168 + progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
6170 + zlog_default = openzlog (progname, ZLOG_STDOUT, ZLOG_MPLS,
6171 + LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
6173 + while (1)
6175 + int opt;
6177 + opt = getopt_long (argc, argv, "bdklf:hP:rv", longopts, 0);
6179 + if (opt == EOF)
6180 + break;
6182 + switch (opt)
6184 + case 0:
6185 + break;
6186 + case 'd':
6187 + daemon_mode = 1;
6188 + break;
6189 + case 'l':
6190 + /* log_mode = 1; */
6191 + break;
6192 + case 'f':
6193 + config_file = optarg;
6194 + break;
6195 + case 'A':
6196 + vty_addr = optarg;
6197 + break;
6198 + case 'P':
6199 + vty_port = atoi (optarg);
6200 + break;
6201 + case 'v':
6202 + print_version (progname);
6203 + exit (0);
6204 + break;
6205 + case 'h':
6206 + usage (progname, 0);
6207 + break;
6208 + default:
6209 + usage (progname, 1);
6210 + break;
6214 + /* Make master thread emulator. */
6215 + master = thread_master_create();
6217 + /* Vty related initialize. */
6218 + signal_init();
6219 + cmd_init(1);
6220 + vty_init();
6221 + memory_init();
6223 + /* MPLSs inits */
6224 + mpls_init();
6225 + mpls_if_init();
6226 + mpls_vty_init();
6227 + mpls_vty_show_init();
6228 + mpls_zebra_init();
6230 + sort_node();
6232 + /* Configuration file read*/
6233 + vty_read_config(config_file, config_current, config_default);
6235 + /* Daemonize. */
6236 + if (daemon_mode) {
6237 + daemon(0, 0);
6240 + /* Output pid of zebra. */
6241 + pid_output(pid_file);
6243 + /* Create VTY socket */
6244 + vty_serv_sock(vty_addr,
6245 + vty_port ? vty_port : MPLS_VTY_PORT, MPLS_VTYSH_PATH);
6247 + /* Print banner. */
6248 + zlog(NULL, LOG_INFO, "MPLSd (%s) starts", ZEBRA_VERSION);
6250 + while(thread_fetch(master, &thread)) {
6251 + thread_call(&thread);
6254 + /* Not reached... */
6255 + exit (0);
6257 diff --exclude=.p4config -uNr zebra/mplsd/mpls_trace.h zebra-ldp/mplsd/mpls_trace.h
6258 --- zebra/mplsd/mpls_trace.h 1969-12-31 18:00:00.000000000 -0600
6259 +++ zebra-ldp/mplsd/mpls_trace.h 2003-03-10 14:57:28.000000000 -0600
6260 @@ -0,0 +1,60 @@
6261 +#ifndef _LDP_TRACE_H_
6262 +#define _LDP_TRACE_H_
6264 +#include <stdio.h>
6265 +#include "ldp_struct.h"
6267 +extern uint32_t ldp_traceflags;
6268 +extern uint8_t trace_buffer[16834];
6269 +extern int trace_buffer_len;
6271 +#if 0
6272 +1 2 3 4 5 6 7 8
6273 + 12345678901234567890123456789012345678901234567890123456789012345678901234567890
6274 +#endif
6275 +#define LDP_TRACE_OUT(handle,args...) { \
6276 + if(trace_buffer_len == 0) { \
6277 + trace_buffer_len += sprintf(trace_buffer,"OUT: " args);\
6278 + } else { \
6279 + trace_buffer_len += sprintf(trace_buffer+trace_buffer_len,args);\
6280 + } \
6281 + if(trace_buffer[strlen(trace_buffer)-1] == '\n') { \
6282 + fprintf(stderr,"%s",trace_buffer); \
6283 + trace_buffer_len = 0; \
6284 + } \
6286 +#define LDP_TRACE_LOG(handle,class,type,args...) { \
6287 + if(type & ldp_traceflags) { \
6288 + LDP_TRACE_OUT(handle,args); \
6289 + } \
6291 +#define LDP_TRACE_PKT(handle,class,type,header,body) { \
6292 + if(type & ldp_traceflags) { \
6293 + header; \
6294 + body; \
6295 + } \
6297 +#define LDP_DUMP_PKT(handle,class,type,func) { \
6298 + if(type & ldp_traceflags) { \
6299 + func; \
6300 + } \
6302 +#define LDP_PRINT(data,args...) { \
6303 + if(ldp_traceflags & LDP_TRACE_FLAG_DEBUG) { \
6304 + fprintf(stderr, "PRT: " args); \
6305 + } \
6307 +#define LDP_ENTER(data,args...) { \
6308 + if(ldp_traceflags & LDP_TRACE_FLAG_DEBUG) { \
6309 + fprintf(stderr, "ENTER: " args); \
6310 + fprintf(stderr, "\n"); \
6311 + } \
6313 +#define LDP_EXIT(data,args...) { \
6314 + if(ldp_traceflags & LDP_TRACE_FLAG_DEBUG) { \
6315 + fprintf(stderr, "EXIT: " args); \
6316 + fprintf(stderr, "\n"); \
6317 + } \
6320 +#endif
6321 diff --exclude=.p4config -uNr zebra/mplsd/mpls_vty.c zebra-ldp/mplsd/mpls_vty.c
6322 --- zebra/mplsd/mpls_vty.c 1969-12-31 18:00:00.000000000 -0600
6323 +++ zebra-ldp/mplsd/mpls_vty.c 2003-03-29 01:12:03.000000000 -0600
6324 @@ -0,0 +1,159 @@
6325 +#include <zebra.h>
6327 +#include "vty.h"
6328 +#include "command.h"
6330 +#include "mpls.h"
6331 +#include "mpls_interface.h"
6333 +#include "ldp.h"
6334 +#include "ldp_cfg.h"
6335 +#include "ldp_vty.h"
6336 +#include "ldp_interface.h"
6337 +#include "static_vty.h"
6338 +#include "rsvpte_vty.h"
6340 +#include "impl_mpls.h"
6342 +DEFUN (mpls_show_lsr_id, mpls_show_lsr_id_cmd,
6343 + "show lsr-id",
6344 + SHOW_STR
6345 + "LSR identifier\n") {
6347 + struct mpls *mpls = mpls_get();
6349 + vty_out(vty, "lsr-id: %s%s", inet_ntoa(mpls->router_id.u.prefix4),
6350 + VTY_NEWLINE);
6351 + return CMD_SUCCESS;
6354 +DEFUN(interface_mpls_labelspace,
6355 + interface_mpls_labelspace_cmd,
6356 + "mpls labelspace <1-255>",
6357 + "MPLS interface configuration\n"
6358 + "labelspace\n"
6359 + "labelspace number\n") {
6360 + struct interface *ifp = vty->index;
6361 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
6362 + struct mpls *mpls = mpls_get();
6363 + struct mpls_range range;
6365 + if ((range.label_space = atoi(argv[0])) < 0) {
6366 + return CMD_WARNING;
6369 + mi->labelspace = range.label_space;
6370 + do_mpls_labelspace(mi);
6372 + if (mpls->ldp && mi->ldp && mi->ldp->entity.index) {
6373 + ldp_interface_admin_state_start(mi);
6374 + mi->ldp->iff.label_space = mi->labelspace;
6375 + ldp_cfg_if_set(mpls->ldp->h, &mi->ldp->iff, LDP_IF_CFG_LABEL_SPACE);
6376 + ldp_interface_admin_state_finish(mi);
6379 + return CMD_SUCCESS;
6382 +DEFUN(no_interface_mpls_labelspace,
6383 + no_interface_mpls_labelspace_cmd,
6384 + "no mpls labelspace",
6385 + NO_STR
6386 + "MPLS interface configuration\n"
6387 + "labelspace\n") {
6388 + struct interface *ifp = vty->index;
6389 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
6390 + struct mpls *mpls = mpls_get();
6392 + mi->labelspace = -1;
6393 + do_mpls_labelspace(mi);
6395 + if (mpls->ldp && mi->ldp && mi->ldp->entity.index) {
6396 + ldp_interface_admin_state_start(mi);
6397 + mi->ldp->iff.label_space = mi->labelspace;
6398 + ldp_cfg_if_set(mpls->ldp->h, &mi->ldp->iff, LDP_IF_CFG_LABEL_SPACE);
6399 + ldp_interface_admin_state_finish(mi);
6401 + return CMD_SUCCESS;
6404 +int mpls_interface_config_write(struct vty *vty) {
6405 + listnode node;
6406 + struct interface *ifp;
6407 + struct mpls_interface *mi;
6408 + struct mpls *mpls = mpls_get();
6410 + for (node = listhead(mpls->iflist); node; nextnode(node)) {
6411 + ifp = getdata(node);
6413 + vty_out(vty, "interface %s%s", ifp->name, VTY_NEWLINE);
6415 + if (ifp->desc) {
6416 + vty_out(vty, " description %s%s", ifp->desc, VTY_NEWLINE);
6419 + if ((mi = (struct mpls_interface*)ifp->info)) {
6420 + if (mi->labelspace > -1) {
6421 + vty_out(vty, " mpls labelspace %d%s", mi->labelspace, VTY_NEWLINE);
6422 + } else {
6423 + vty_out(vty, " no mpls labelspace%s", VTY_NEWLINE);
6425 + ldp_interface_config_write(vty, mi);
6427 + vty_out(vty, "!%s", VTY_NEWLINE);
6429 + return 0;
6432 +void mpls_vty_show_init () {
6434 + install_element(VIEW_NODE, &mpls_show_lsr_id_cmd);
6435 + install_element(ENABLE_NODE, &mpls_show_lsr_id_cmd);
6437 +#if 0
6438 + install_element (VIEW_NODE, &show_ip_route_cmd);
6439 + install_element (VIEW_NODE, &show_ip_route_addr_cmd);
6440 + install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
6441 + install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
6442 + install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
6443 + install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
6444 + install_element (ENABLE_NODE, &show_ip_route_cmd);
6445 + install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
6446 + install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
6447 + install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
6448 + install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
6449 + install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
6450 +#endif
6452 + ldp_vty_show_init();
6453 + static_vty_show_init();
6454 + rsvpte_vty_show_init();
6457 +struct cmd_node interface_node = { INTERFACE_NODE, "%s(config-if)# ", 1, };
6459 +void mpls_vty_if_init() {
6461 + install_node(&interface_node, mpls_interface_config_write);
6463 + install_element(CONFIG_NODE, &interface_cmd);
6464 + install_default(INTERFACE_NODE);
6466 + install_element(INTERFACE_NODE,&interface_desc_cmd);
6467 + install_element(INTERFACE_NODE,&no_interface_desc_cmd);
6469 + install_element(INTERFACE_NODE,&interface_mpls_labelspace_cmd);
6470 + install_element(INTERFACE_NODE,&no_interface_mpls_labelspace_cmd);
6472 + ldp_vty_if_init();
6473 + rsvpte_vty_if_init();
6476 +void mpls_vty_init () {
6478 + ldp_vty_init();
6479 + rsvpte_vty_init();
6480 + static_vty_init();
6482 + mpls_vty_if_init();
6484 diff --exclude=.p4config -uNr zebra/mplsd/mpls_vty.h zebra-ldp/mplsd/mpls_vty.h
6485 --- zebra/mplsd/mpls_vty.h 1969-12-31 18:00:00.000000000 -0600
6486 +++ zebra-ldp/mplsd/mpls_vty.h 2003-03-29 01:12:03.000000000 -0600
6487 @@ -0,0 +1,42 @@
6488 +#ifndef ZEBRA_MPLS_VTY_H
6489 +#define ZEBRA_MPLS_VTY_H
6491 +#define VTY_GET_UINT32(NAME,V,STR) \
6492 +{ \
6493 + char *endptr = NULL; \
6494 + (V) = strtoul ((STR), &endptr, 10); \
6495 + if (*endptr != '\0' || ((V) == ULONG_MAX && errno == ERANGE)) \
6496 + { \
6497 + vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
6498 + return CMD_WARNING; \
6499 + } \
6502 +#define VTY_GET_UINT32_RANGE(NAME,V,STR,IMIN,IMAX) \
6503 +{ \
6504 + VTY_GET_UINT32(NAME,V,STR); \
6505 + if (((V) < IMIN) || ((V) > IMAX)) \
6506 + { \
6507 + vty_out (vty, "%% Invalid %s value. Valid range is (%d ... %d)%s", \
6508 + NAME, IMIN, IMAX, VTY_NEWLINE); \
6509 + return CMD_WARNING; \
6510 + } \
6513 +#define VTY_GET_IPV4_ADDRESS(NAME,V,STR) \
6514 +{ \
6515 + struct in_addr addr; \
6516 + int retv; \
6517 + retv = inet_aton ((STR), &addr); \
6518 + if (!retv) \
6519 + { \
6520 + vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
6521 + return CMD_WARNING; \
6522 + } \
6523 + (V) = ntohl(addr.s_addr); \
6526 +void mpls_vty_init();
6527 +void mpls_vty_show_init();
6529 +#endif
6530 diff --exclude=.p4config -uNr zebra/mplsd/mpls_zebra.c zebra-ldp/mplsd/mpls_zebra.c
6531 --- zebra/mplsd/mpls_zebra.c 1969-12-31 18:00:00.000000000 -0600
6532 +++ zebra-ldp/mplsd/mpls_zebra.c 2003-03-10 14:57:29.000000000 -0600
6533 @@ -0,0 +1,311 @@
6534 +#include <zebra.h>
6536 +#include "command.h"
6537 +#include "prefix.h"
6538 +#include "stream.h"
6539 +#include "table.h"
6540 +#include "memory.h"
6541 +#include "zclient.h"
6542 +#include "log.h"
6544 +#include "ldp.h"
6545 +#include "mpls_interface.h"
6546 +#include "impl_fib.h"
6547 +#include "impl_ifmgr.h"
6548 +#include "impl_mpls.h"
6550 +/* All information about zebra. */
6551 +struct zclient *zclient = NULL;
6553 +/* For registering threads. */
6554 +extern struct thread_master *master;
6556 +/* Router-id update message from zebra. */
6557 +int mpls_router_id_update_zebra(int command, struct zclient *zclient,
6558 + zebra_size_t length) {
6559 + struct mpls *mpls = mpls_get();
6561 + zebra_router_id_update_read(zclient->ibuf,&mpls->router_id);
6563 + zlog_info("router-id change %s",
6564 + inet_ntoa(mpls->router_id.u.prefix4));
6566 + if (mpls && mpls->ldp) {
6567 + ldp_router_id_update(mpls->ldp, &mpls->router_id);
6569 + return 0;
6572 +/* Inteface addition message from zebra. */
6573 +int mpls_interface_add(int command, struct zclient *zclient,
6574 + zebra_size_t length) {
6575 + struct interface *ifp;
6576 + struct mpls_interface *mi;
6578 + if (!(ifp = zebra_interface_add_read(zclient->ibuf))) {
6579 + return 1;
6582 + mi = (struct mpls_interface*)ifp->info;
6583 + if (mi && mi->ldp) {
6584 + /* Initialize labelspace to kernel */
6585 + /* If the labelspace has been set yet via the CLI */
6586 + /* the result will be that the kernel labelspace will */
6587 + /* be un-set, which doesn't hurt anything */
6588 + do_mpls_labelspace(mi);
6591 + zlog_info("interface add %s index %d flags %ld metric %d mtu %d",
6592 + ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
6594 + return 0;
6597 +int mpls_interface_delete(int command, struct zclient *zclient,
6598 + zebra_size_t length) {
6599 + struct interface *ifp;
6600 + struct stream *s;
6602 + s = zclient->ibuf;
6603 + /* zebra_interface_state_read() updates interface structure in iflist */
6604 + ifp = zebra_interface_state_read(s);
6606 + if (ifp == NULL) {
6607 + return 0;
6610 + if (if_is_up(ifp)) {
6611 + zlog_warn("got delete of %s, but interface is still up",
6612 + ifp->name);
6615 + zlog_info("interface delete %s index %d flags %ld metric %d mtu %d", ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
6617 + if_delete(ifp);
6619 + return 0;
6622 +struct interface * zebra_interface_if_lookup(struct stream *s) {
6623 + struct interface *ifp;
6624 + u_char ifname_tmp[INTERFACE_NAMSIZ];
6626 + /* Read interface name. */
6627 + stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
6629 + /* Lookup this by interface index. */
6630 + ifp = if_lookup_by_name(ifname_tmp);
6632 + /* If such interface does not exist, indicate an error */
6633 + if (!ifp) {
6634 + return NULL;
6637 + return ifp;
6640 +int mpls_interface_state_up(int command, struct zclient *zclient,
6641 + zebra_size_t length) {
6642 + struct interface *ifp;
6643 + struct interface if_tmp;
6645 + ifp = zebra_interface_if_lookup(zclient->ibuf);
6646 + if (ifp == NULL) {
6647 + return 0;
6650 + /* Interface is already up. */
6651 + if (if_is_up (ifp)) {
6652 + /* Temporarily keep ifp values. */
6653 + memcpy (&if_tmp, ifp, sizeof (struct interface));
6655 + zebra_interface_if_set_value (zclient->ibuf, ifp);
6657 + zlog_info ("Interface[%s] state update.", ifp->name);
6659 + return 0;
6662 + zebra_interface_if_set_value(zclient->ibuf, ifp);
6664 + zlog_info ("Interface[%s] state change to up.", ifp->name);
6666 + mpls_if_up(ifp->info);
6668 + return 0;
6671 +int mpls_interface_state_down(int command, struct zclient *zclient,
6672 + zebra_size_t length) {
6673 + struct interface *ifp;
6675 + ifp = zebra_interface_state_read (zclient->ibuf);
6676 + if (ifp == NULL) {
6677 + return 0;
6680 + zlog_info ("Interface[%s] state change to down.", ifp->name);
6682 + mpls_if_down(ifp->info);
6684 + return 0;
6687 +int mpls_interface_address_add(int command, struct zclient *zclient,
6688 + zebra_size_t length) {
6689 + struct mpls *mpls = mpls_get();
6690 + struct connected *c;
6691 + struct interface *ifp;
6692 + struct prefix *p;
6694 + c = zebra_interface_address_add_read(zclient->ibuf);
6695 + if (c == NULL) {
6696 + return 0;
6699 + ifp = c->ifp;
6700 + p = c->address;
6702 + zlog_info("address add %s to interface %s",inet_ntoa(p->u.prefix4),
6703 + ifp->name);
6705 + if (mpls->ldp) {
6706 + ldp_address_add_callback(mpls, c);
6709 + return 0;
6712 +int mpls_interface_address_delete(int command, struct zclient *zclient,
6713 + zebra_size_t length) {
6714 + struct mpls *mpls = mpls_get();
6715 + struct connected *c;
6716 + struct interface *ifp;
6717 + struct prefix *p;
6719 + c = zebra_interface_address_delete_read(zclient->ibuf);
6720 + if (c == NULL) {
6721 + return 0;
6724 + ifp = c->ifp;
6725 + p = c->address;
6727 + zlog_info("address delete %s from interface %s",
6728 + inet_ntoa(p->u.prefix4), ifp->name);
6730 + if (mpls->ldp) {
6731 + ldp_address_delete_callback(mpls, c);
6734 + connected_free(c);
6736 + return 0;
6739 +static void mpls_read_ipv4(struct zclient *client, u_short length,
6740 + struct prefix_ipv4* p, struct mpls_nexthop* nexthop) {
6741 + struct stream *s;
6742 + int ifindex_num;
6743 + int nexthop_num;
6744 + int message;
6745 + int flags;
6746 + int type;
6748 + s = client->ibuf;
6749 + memset(nexthop,0,sizeof(nexthop));
6751 + /* Type, flags, message. */
6752 + type = stream_getc(s);
6753 + flags = stream_getc(s);
6754 + message = stream_getc(s);
6756 + if (type == ZEBRA_ROUTE_CONNECT) {
6757 + nexthop->attached = MPLS_BOOL_TRUE;
6760 + /* IPv4 prefix. */
6761 + memset (p, 0, sizeof(struct prefix_ipv4));
6762 + p->family = AF_INET;
6763 + p->prefixlen = stream_getc (s);
6764 + stream_get(&p->prefix, s, PSIZE(p->prefixlen));
6766 + /* Nexthop, ifindex, distance, metric. */
6767 + if (CHECK_FLAG(message, ZAPI_MESSAGE_NEXTHOP)) {
6768 + nexthop_num = stream_getc(s);
6769 + assert(nexthop_num == 1);
6770 + nexthop->ip.u.ipv4 = ntohl(stream_get_ipv4(s));
6771 + if (nexthop->ip.u.ipv4) {
6772 + nexthop->ip.type = MPLS_FAMILY_IPV4;
6773 + nexthop->type |= MPLS_NH_IP;
6777 + if (CHECK_FLAG(message, ZAPI_MESSAGE_IFINDEX)) {
6778 + ifindex_num = stream_getc(s);
6779 + assert(ifindex_num == 1);
6780 + nexthop->if_handle = if_lookup_by_index(stream_getl(s));
6781 + nexthop->type |= MPLS_NH_IF;
6784 + /* Distance. */
6785 + if (CHECK_FLAG(message, ZAPI_MESSAGE_DISTANCE)) {
6786 + nexthop->distance = stream_getc(s);
6789 + /* Metric. */
6790 + if (CHECK_FLAG(message, ZAPI_MESSAGE_METRIC)) {
6791 + nexthop->metric = stream_getl(s);
6795 +int mpls_zebra_read_ipv4(int command, struct zclient *client,
6796 + zebra_size_t length) {
6797 + struct mpls_nexthop nexthop;
6798 + struct prefix_ipv4 p;
6799 + struct mpls *mpls = mpls_get();
6800 + struct in_addr tmp;
6802 + mpls_read_ipv4(client, length, &p, &nexthop);
6804 + if (command == ZEBRA_IPV4_ROUTE_ADD) {
6805 + zlog_info("route add %s/%d", inet_ntoa(p.prefix), p.prefixlen);
6806 + } else {
6807 + zlog_info("route delete %s/%d", inet_ntoa(p.prefix), p.prefixlen);
6810 + if (nexthop.type & MPLS_NH_IP) {
6811 + tmp.s_addr = htonl(nexthop.ip.u.ipv4);
6812 + zlog_info("\tnexthop %s", inet_ntoa(tmp));
6814 + if (nexthop.type & MPLS_NH_IF) {
6815 + zlog_info("\tifindex %d", nexthop.if_handle->ifindex);
6818 + if (command == ZEBRA_IPV4_ROUTE_ADD) {
6819 + ldp_ipv4_add(mpls, &p, &nexthop);
6820 + } else {
6821 + ldp_ipv4_delete(mpls, &p, &nexthop);
6823 + return 0;
6826 +void mpls_zebra_init() {
6827 + int i;
6829 + /* Allocate zebra structure. */
6830 + zclient = zclient_new();
6831 + zclient_init(zclient, ZEBRA_ROUTE_MPLS);
6832 + for (i = 0;i < ZEBRA_ROUTE_MAX;i++) {
6833 + zclient->redist[i] = 1;
6835 + zclient->router_id_update = mpls_router_id_update_zebra;
6836 + zclient->interface_add = mpls_interface_add;
6837 + zclient->interface_delete = mpls_interface_delete;
6838 + zclient->interface_up = mpls_interface_state_up;
6839 + zclient->interface_down = mpls_interface_state_down;
6840 + zclient->interface_address_add = mpls_interface_address_add;
6841 + zclient->interface_address_delete = mpls_interface_address_delete;
6842 + zclient->ipv4_route_add = mpls_zebra_read_ipv4;
6843 + zclient->ipv4_route_delete = mpls_zebra_read_ipv4;
6845 diff --exclude=.p4config -uNr zebra/mplsd/mpls_zebra.h zebra-ldp/mplsd/mpls_zebra.h
6846 --- zebra/mplsd/mpls_zebra.h 1969-12-31 18:00:00.000000000 -0600
6847 +++ zebra-ldp/mplsd/mpls_zebra.h 2003-03-10 14:57:29.000000000 -0600
6848 @@ -0,0 +1,8 @@
6849 +#ifndef _ZEBRA_MPLS_ZEBRA_H
6850 +#define _ZEBRA_MPLS_ZEBRA_H
6852 +#include "prefix.h"
6854 +void mpls_zebra_init();
6856 +#endif
6857 diff --exclude=.p4config -uNr zebra/mplsd/rsvpte.c zebra-ldp/mplsd/rsvpte.c
6858 --- zebra/mplsd/rsvpte.c 1969-12-31 18:00:00.000000000 -0600
6859 +++ zebra-ldp/mplsd/rsvpte.c 2003-03-29 01:12:03.000000000 -0600
6860 @@ -0,0 +1,105 @@
6861 +#include <zebra.h>
6863 +#include "memory.h"
6864 +#include "log.h"
6866 +#include "rsvpte.h"
6867 +#include "rsvpte_interface.h"
6869 +#include "mpls.h"
6870 +#include "mpls_interface.h"
6872 +int rsvpte_shutdown(struct rsvpte *rsvpte) {
6873 + return MPLS_SUCCESS;
6876 +int rsvpte_startup(struct rsvpte *rsvpte) {
6877 + /* setup sockets and recv threads, setup zebra mesg handlers */
6878 + /* setup label manager */
6880 + return MPLS_SUCCESS;
6883 +int rsvpte_admin_state_start(struct rsvpte *rsvpte) {
6884 + if (rsvpte->admin_up == MPLS_BOOL_TRUE) {
6885 + return rsvpte_shutdown(rsvpte);
6887 + return MPLS_SUCCESS;
6890 +int rsvpte_admin_state_finish(struct rsvpte *rsvpte) {
6891 + if (rsvpte->admin_up == MPLS_BOOL_TRUE) {
6892 + return rsvpte_startup(rsvpte);
6894 + return MPLS_SUCCESS;
6897 +int do_rsvpte_router_id_update(struct rsvpte *rsvpte, unsigned int router_id) {
6898 + return MPLS_SUCCESS;
6901 +int rsvpte_router_id_update(struct rsvpte *rsvpte, struct prefix *router_id) {
6903 + zlog_info("router-id update %s", inet_ntoa(router_id->u.prefix4));
6905 + if (!rsvpte->lsr_id_is_static) {
6906 + rsvpte_admin_state_start(rsvpte);
6908 + do_rsvpte_router_id_update(rsvpte, ntohl(router_id->u.prefix4.s_addr));
6910 + rsvpte_admin_state_finish(rsvpte);
6912 + return 0;
6915 +static struct rsvpte *rsvpte_new(struct mpls *mpls) {
6916 + struct rsvpte *new = XMALLOC(MTYPE_MPLS_RSVPTE, sizeof(struct rsvpte));
6917 + memset(new,0,sizeof(*new));
6919 + new->admin_up = MPLS_BOOL_TRUE;
6920 + new->lsr_id_is_static = 0;
6921 + new->mpls = mpls;
6923 + return new;
6926 +struct rsvpte *rsvpte_get() {
6927 + struct mpls_interface *mi;
6928 + struct interface *ifp;
6929 + listnode node;
6931 + struct mpls *mpls = mpls_get();
6932 + if (mpls->rsvpte) {
6933 + return mpls->rsvpte;
6936 + mpls->rsvpte = rsvpte_new(mpls);
6937 + for (node = listhead(mpls->iflist); node; nextnode(node)) {
6938 + ifp = getdata(node);
6939 + mi = (struct mpls_interface*)ifp->info;
6940 + if (mi->rsvpte && mi->rsvpte->create_on_hold == MPLS_BOOL_TRUE) {
6941 + rsvpte_interface_create(mi);
6945 + return mpls->rsvpte;
6948 +void rsvpte_finish(struct rsvpte *rsvpte) {
6949 + struct mpls *mpls = rsvpte->mpls;
6950 + struct interface *ifp;
6951 + struct mpls_interface *mi;
6952 + listnode node;
6954 + for (node = listhead(mpls->iflist); node; nextnode(node)) {
6955 + ifp = getdata(node);
6956 + mi = (struct mpls_interface*)ifp->info;
6957 + if (mi->rsvpte) {
6958 + rsvpte_interface_delete(mi);
6962 + rsvpte_admin_state_start(rsvpte);
6963 + XFREE(MTYPE_MPLS_RSVPTE,rsvpte);
6964 + mpls->rsvpte = NULL;
6966 diff --exclude=.p4config -uNr zebra/mplsd/rsvpte.h zebra-ldp/mplsd/rsvpte.h
6967 --- zebra/mplsd/rsvpte.h 1969-12-31 18:00:00.000000000 -0600
6968 +++ zebra-ldp/mplsd/rsvpte.h 2003-03-29 01:12:03.000000000 -0600
6969 @@ -0,0 +1,26 @@
6970 +#ifndef RSVPTE_H
6971 +#define RSVPTE_H
6973 +#include <zebra.h>
6974 +#include "prefix.h"
6976 +#include "mpls_struct.h"
6978 +struct mpls;
6980 +struct rsvpte {
6981 + struct mpls *mpls;
6982 + mpls_bool admin_up;
6983 + mpls_bool lsr_id_is_static;
6986 +struct rsvpte *rsvpte_get();
6987 +void rsvpte_init();
6988 +int rsvpte_router_id_update(struct rsvpte *rsvpte, struct prefix *router_id);
6989 +int do_rsvpte_router_id_update(struct rsvpte *rsvpte, unsigned int router_id);
6990 +void rsvpte_finish(struct rsvpte *rsvpte);
6992 +int rsvpte_admin_state_start(struct rsvpte *rsvpte);
6993 +int rsvpte_admin_state_finish(struct rsvpte *rsvpte);
6995 +#endif
6996 diff --exclude=.p4config -uNr zebra/mplsd/rsvpte_interface.c zebra-ldp/mplsd/rsvpte_interface.c
6997 --- zebra/mplsd/rsvpte_interface.c 1969-12-31 18:00:00.000000000 -0600
6998 +++ zebra-ldp/mplsd/rsvpte_interface.c 2003-03-29 01:12:03.000000000 -0600
6999 @@ -0,0 +1,75 @@
7000 +#include <zebra.h>
7001 +#include "memory.h"
7003 +#include "rsvpte.h"
7004 +#include "rsvpte_interface.h"
7006 +#include "mpls.h"
7007 +#include "mpls_interface.h"
7009 +struct rsvpte_interface *rsvpte_if_new(struct mpls_interface *mi) {
7010 + struct rsvpte_interface *li;
7012 + li = XMALLOC(MTYPE_MPLS_RSVPTE, sizeof(struct rsvpte_interface));
7013 + memset(li, 0, sizeof(struct rsvpte_interface));
7014 + li->mi = mi;
7016 + li->admin_up = MPLS_BOOL_TRUE;
7017 + li->create_on_hold = MPLS_BOOL_FALSE;
7019 + return li;
7022 +void rsvpte_if_free(struct rsvpte_interface *li) {
7023 + XFREE(MTYPE_MPLS_RSVPTE, li);
7026 +void rsvpte_interface_create(struct mpls_interface *mi) {
7027 + mi->rsvpte->create_on_hold = MPLS_BOOL_FALSE;
7029 + rsvpte_interface_admin_state_finish(mi);
7032 +void rsvpte_interface_delete(struct mpls_interface *mi) {
7033 + struct rsvpte *rsvpte = mi->mpls->rsvpte;
7035 + mi->rsvpte->create_on_hold = MPLS_BOOL_TRUE;
7037 + if (rsvpte) {
7038 + rsvpte_interface_admin_state_start(mi);
7042 +int rsvpte_interface_startup(struct mpls_interface *mi) {
7043 + return MPLS_SUCCESS;
7046 +int rsvpte_interface_shutdown(struct mpls_interface *mi) {
7047 + return MPLS_SUCCESS;
7050 +int rsvpte_interface_admin_state_start(struct mpls_interface *mi) {
7051 + if (mi->rsvpte->admin_up == MPLS_BOOL_TRUE && mpls_if_is_up(mi)) {
7052 + return rsvpte_interface_shutdown(mi);
7054 + return MPLS_SUCCESS;
7057 +int rsvpte_interface_admin_state_finish(struct mpls_interface *mi) {
7058 + if (mi->rsvpte->admin_up == MPLS_BOOL_TRUE && mpls_if_is_up(mi)) {
7059 + return rsvpte_interface_startup(mi);
7061 + return MPLS_SUCCESS;
7064 +void rsvpte_if_up(struct mpls_interface *mi) {
7065 + if (mi->rsvpte && mi->rsvpte->admin_up == MPLS_BOOL_TRUE) {
7066 + rsvpte_interface_startup(mi);
7070 +void rsvpte_if_down(struct mpls_interface *mi) {
7071 + if (mi->rsvpte && mi->rsvpte->admin_up == MPLS_BOOL_TRUE) {
7072 + rsvpte_interface_shutdown(mi);
7075 diff --exclude=.p4config -uNr zebra/mplsd/rsvpte_interface.h zebra-ldp/mplsd/rsvpte_interface.h
7076 --- zebra/mplsd/rsvpte_interface.h 1969-12-31 18:00:00.000000000 -0600
7077 +++ zebra-ldp/mplsd/rsvpte_interface.h 2003-03-29 01:12:03.000000000 -0600
7078 @@ -0,0 +1,29 @@
7079 +#ifndef RSVPTE_IF_H
7080 +#define RSVPTE_IF_H
7082 +#include "mpls_struct.h"
7084 +struct mpls_interface;
7086 +struct rsvpte_interface {
7087 + struct mpls_interface *mi;
7088 + mpls_bool admin_up;
7089 + mpls_bool create_on_hold;
7092 +struct rsvpte_interface *rsvpte_if_new(struct mpls_interface *mi);
7093 +void rsvpte_if_free(struct rsvpte_interface *li);
7095 +void rsvpte_if_up(struct mpls_interface *mi);
7096 +void rsvpte_if_down(struct mpls_interface *mi);
7098 +int rsvpte_interface_startup(struct mpls_interface *mi);
7099 +int rsvpte_interface_shutdown(struct mpls_interface *mi);
7101 +void rsvpte_interface_create(struct mpls_interface *mi);
7102 +void rsvpte_interface_delete(struct mpls_interface *mi);
7103 +int rsvpte_interface_admin_state_start(struct mpls_interface *mi);
7104 +int rsvpte_interface_admin_state_finish(struct mpls_interface *mi);
7107 +#endif
7108 diff --exclude=.p4config -uNr zebra/mplsd/rsvpte_vty.c zebra-ldp/mplsd/rsvpte_vty.c
7109 --- zebra/mplsd/rsvpte_vty.c 1969-12-31 18:00:00.000000000 -0600
7110 +++ zebra-ldp/mplsd/rsvpte_vty.c 2003-03-29 01:12:03.000000000 -0600
7111 @@ -0,0 +1,261 @@
7112 +#include <zebra.h>
7114 +#include "rsvpte.h"
7115 +#include "rsvpte_interface.h"
7117 +#include "impl_mpls.h"
7119 +#include "mpls.h"
7120 +#include "mpls_interface.h"
7122 +#include "command.h"
7123 +#include "zclient.h"
7124 +#include "vty.h"
7126 +extern struct zclient *zclient;
7128 +DEFUN (mpls_rsvpte,
7129 + mpls_rsvpte_cmd,
7130 + "mpls rsvpte",
7131 + "MPLS configuration\n"
7132 + "Start RSVPTE configuration\n") {
7134 + vty->node = MPLS_RSVPTE_NODE;
7135 + vty->index = rsvpte_get();
7137 + return CMD_SUCCESS;
7140 +DEFUN (no_mpls_rsvpte,
7141 + no_mpls_rsvpte_cmd,
7142 + "no mpls rsvpte",
7143 + NO_STR
7144 + "MPLS configuration\n"
7145 + "Global RSVPTE configuration\n") {
7146 + struct mpls *mpls = mpls_get();
7148 + if (!mpls->rsvpte) {
7149 + vty_out (vty, "There isn't active an RSVPTE instance.%s", VTY_NEWLINE);
7150 + return CMD_WARNING;
7153 + rsvpte_finish(mpls->rsvpte);
7154 + return CMD_SUCCESS;
7157 +DEFUN (mpls_rsvpte_lsrid,
7158 + mpls_rsvpte_lsrid_cmd,
7159 + "lsr-id A.B.C.D",
7160 + "RSVPTE Label Switch Router Identifier\n"
7161 + "IP Address\n") {
7162 + struct rsvpte *rsvpte = (struct rsvpte*)vty->index;
7164 + rsvpte->lsr_id_is_static = MPLS_BOOL_TRUE;
7166 + rsvpte_admin_state_start(rsvpte);
7167 + do_rsvpte_router_id_update(rsvpte, ntohl(inet_addr(argv[0])));
7168 + rsvpte_admin_state_finish(rsvpte);
7170 + return CMD_SUCCESS;
7173 +DEFUN (no_mpls_rsvpte_lsrid,
7174 + no_mpls_rsvpte_lsrid_cmd,
7175 + "no lsr-id",
7176 + NO_STR
7177 + "RSVPTE LSRID\n") {
7178 + struct rsvpte *rsvpte = (struct rsvpte*)vty->index;
7180 + rsvpte->lsr_id_is_static = MPLS_BOOL_FALSE;
7182 + rsvpte_admin_state_start(rsvpte);
7183 + do_rsvpte_router_id_update(rsvpte, ntohl(rsvpte->mpls->router_id.u.prefix4.s_addr));
7184 + rsvpte_admin_state_finish(rsvpte);
7186 + return CMD_SUCCESS;
7189 +DEFUN (mpls_rsvpte_disable,
7190 + mpls_rsvpte_disable_cmd,
7191 + "disable",
7192 + "Disable\n") {
7193 + struct rsvpte *rsvpte = (struct rsvpte*)vty->index;
7195 + rsvpte_admin_state_start(rsvpte);
7196 + rsvpte->admin_up = MPLS_BOOL_FALSE;
7197 + rsvpte_admin_state_finish(rsvpte);
7199 + return CMD_SUCCESS;
7202 +DEFUN (no_mpls_rsvpte_disable,
7203 + no_mpls_rsvpte_disable_cmd,
7204 + "no disable",
7205 + NO_STR
7206 + "Disable\n") {
7207 + struct rsvpte *rsvpte = (struct rsvpte*)vty->index;
7209 + rsvpte_admin_state_start(rsvpte);
7210 + rsvpte->admin_up = MPLS_BOOL_TRUE;
7211 + rsvpte_admin_state_finish(rsvpte);
7213 + return CMD_SUCCESS;
7216 +DEFUN (mpls_show_rsvpte, mpls_show_rsvpte_cmd,
7217 + "show rsvpte",
7218 + SHOW_STR
7219 + "RSVPTE global setting\n") {
7220 + struct mpls *mpls = mpls_get();
7222 + if (!mpls->rsvpte) {
7223 + vty_out (vty, "There isn't an active RSVPTE instance.%s", VTY_NEWLINE);
7224 + return CMD_WARNING;
7227 + return CMD_SUCCESS;
7230 +extern void convert_seconds_to_string(uint32_t secs, char* buf);
7232 +void rsvpte_print_label(struct vty *vty, mpls_label_struct *l) {
7233 + switch(l->type) {
7234 + case MPLS_LABEL_TYPE_NONE:
7235 + vty_out(vty, "label: unknown");
7236 + break;
7237 + case MPLS_LABEL_TYPE_GENERIC:
7238 + vty_out(vty, "label: gen %d",l->u.gen);
7239 + break;
7240 + case MPLS_LABEL_TYPE_ATM:
7241 + vty_out(vty, "label: atm %d/%d",l->u.atm.vpi,l->u.atm.vci);
7242 + break;
7243 + case MPLS_LABEL_TYPE_FR:
7244 + vty_out(vty, "label: dlci %d",l->u.fr.dlci);
7245 + break;
7249 +DEFUN(rsvpte_intf,
7250 + rsvpte_intf_cmd,
7251 + "mpls rsvpte",
7252 + "MPLS interface configuration\n"
7253 + "Enable RSVPTE\n") {
7254 + struct interface *ifp = vty->index;
7255 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7256 + struct mpls *mpls = mi->mpls;
7258 + if (!mi->rsvpte) {
7259 + /* user is trying to create a new RSVPTE interface */
7260 + /* if a labelspace hasn't been set yet, set it to 0 */
7261 + if (mi->labelspace == -1) {
7262 + mi->labelspace = 0;
7263 + do_mpls_labelspace(mi);
7265 + mi->rsvpte = rsvpte_if_new(mi);
7268 + /* if the global RSVPTE has been created, go ahead and tell RSVPTE about it
7269 + * otherwise just mark the interface as "on hold"
7270 + */
7271 + if (mpls->rsvpte) {
7272 + rsvpte_interface_create(mi);
7273 + } else {
7274 + mi->rsvpte->create_on_hold = MPLS_BOOL_TRUE;
7277 + vty->node = MPLS_RSVPTE_IF_NODE;
7279 + return CMD_SUCCESS;
7282 +DEFUN(no_rsvpte_intf,
7283 + no_rsvpte_intf_cmd,
7284 + "no mpls rsvpte",
7285 + NO_STR
7286 + "MPLS interface configuration\n"
7287 + "remove RSVPTE\n") {
7288 + struct interface *ifp = vty->index;
7289 + struct mpls_interface *mi = (struct mpls_interface*)ifp->info;
7291 + if (mi->rsvpte) {
7292 + rsvpte_interface_delete(mi);
7293 + rsvpte_if_free(mi->rsvpte);
7294 + mi->rsvpte = NULL;
7296 + return CMD_SUCCESS;
7299 +static int rsvpte_if_config_write (struct vty *vty) {
7300 + return 0;
7303 +static int rsvpte_config_write (struct vty *vty) {
7304 + struct mpls *mpls = mpls_get();
7305 + struct rsvpte *rsvpte = mpls->rsvpte;
7306 + int write = 0;
7308 + if (rsvpte) {
7309 + vty_out (vty, "!%s", VTY_NEWLINE);
7310 + vty_out (vty, "mpls rsvpte%s", VTY_NEWLINE);
7311 + write++;
7313 + return write;
7316 +int rsvpte_interface_config_write(struct vty *vty, struct mpls_interface *mi) {
7317 + struct rsvpte_interface *li;
7318 + struct mpls *mpls;
7319 + struct rsvpte *rsvpte;
7320 + int write = 0;
7322 + if (mi && mi->rsvpte) {
7323 + li = mi->rsvpte;
7324 + mpls = mi->mpls;
7325 + rsvpte = mpls->rsvpte;
7327 + vty_out(vty, " mpls rsvpte%s", VTY_NEWLINE);
7328 + write++;
7330 + vty_out(vty, " !%s",VTY_NEWLINE);
7333 + return write;
7336 +void rsvpte_vty_show_init() {
7338 + install_element(VIEW_NODE, &mpls_show_rsvpte_cmd);
7339 + install_element(ENABLE_NODE, &mpls_show_rsvpte_cmd);
7343 +static struct cmd_node rsvpte_if_node = {MPLS_RSVPTE_IF_NODE,"%s(config-if-rsvpte)# ",1};
7345 +void rsvpte_vty_if_init() {
7347 + install_node (&rsvpte_if_node, rsvpte_if_config_write);
7348 + install_default (MPLS_RSVPTE_IF_NODE);
7350 + install_element(INTERFACE_NODE,&rsvpte_intf_cmd);
7351 + install_element(INTERFACE_NODE,&no_rsvpte_intf_cmd);
7355 +static struct cmd_node rsvpte_node = {MPLS_RSVPTE_NODE,"%s(config-rsvpte)# ",1};
7357 +void rsvpte_vty_init () {
7359 + fprintf(stderr,"rsvpte_vty_init\n");
7361 + install_node (&rsvpte_node, rsvpte_config_write);
7362 + install_default (MPLS_RSVPTE_NODE);
7364 + install_element (CONFIG_NODE, &mpls_rsvpte_cmd);
7365 + install_element (CONFIG_NODE, &no_mpls_rsvpte_cmd);
7367 + install_element (MPLS_RSVPTE_NODE, &mpls_rsvpte_disable_cmd);
7368 + install_element (MPLS_RSVPTE_NODE, &no_mpls_rsvpte_disable_cmd);
7370 + install_element (MPLS_RSVPTE_NODE, &mpls_rsvpte_lsrid_cmd);
7371 + install_element (MPLS_RSVPTE_NODE, &no_mpls_rsvpte_lsrid_cmd);
7373 diff --exclude=.p4config -uNr zebra/mplsd/rsvpte_vty.h zebra-ldp/mplsd/rsvpte_vty.h
7374 --- zebra/mplsd/rsvpte_vty.h 1969-12-31 18:00:00.000000000 -0600
7375 +++ zebra-ldp/mplsd/rsvpte_vty.h 2003-03-29 01:12:03.000000000 -0600
7376 @@ -0,0 +1,11 @@
7377 +#ifndef RSVPTE_VTY_H
7378 +#define RSVPTE_VTY_H
7380 +#include "mpls_interface.h"
7382 +int rsvpte_interface_config_write(struct vty *vty, struct mpls_interface *mi);
7383 +void rsvpte_vty_show_init();
7384 +void rsvpte_vty_if_init();
7385 +void rsvpte_vty_init();
7387 +#endif
7388 diff --exclude=.p4config -uNr zebra/mplsd/static.c zebra-ldp/mplsd/static.c
7389 --- zebra/mplsd/static.c 1969-12-31 18:00:00.000000000 -0600
7390 +++ zebra-ldp/mplsd/static.c 2003-03-10 14:57:29.000000000 -0600
7391 @@ -0,0 +1,101 @@
7392 +#include <zebra.h>
7394 +#include "vty.h"
7395 +#include "command.h"
7396 +#include "memory.h"
7398 +#include "static.h"
7400 +static struct static_outsegment *static_outsegment_new(struct mpls_static *mstatic) {
7401 + struct static_outsegment *new = XMALLOC(MTYPE_MPLS_STATIC, sizeof(*new));
7402 + memset(new,0,sizeof(*new));
7403 + new->node.data = new;
7404 + new->mstatic = mstatic;
7405 + return new;
7408 +struct static_outsegment *static_outsegment_get(struct mpls_static *mstatic,
7409 + unsigned int index, char create) {
7410 + struct listnode *tmp;
7411 + struct static_outsegment *out;
7413 + LIST_LOOP(mstatic->outsegment,out,tmp) {
7414 + if (out->index == index) {
7415 + return out;
7419 + if (create) {
7420 + out = static_outsegment_new(mstatic);
7421 + out->index = index;
7422 + LISTNODE_ADD(mstatic->outsegment, &out->node);
7423 + return out;
7425 + return NULL;
7428 +void static_outsegment_finish(struct static_outsegment *out) {
7429 + LISTNODE_DELETE(out->mstatic->outsegment, &out->node);
7430 + XFREE(MTYPE_MPLS_STATIC,out);
7433 +static struct static_insegment *static_insegment_new(struct mpls_static *mstatic) {
7434 + struct static_insegment *new = XMALLOC(MTYPE_MPLS_STATIC, sizeof(*new));
7435 + memset(new,0,sizeof(*new));
7436 + new->node.data = new;
7437 + new->mstatic = mstatic;
7438 + return new;
7441 +struct static_insegment *static_insegment_get(struct mpls_static *mstatic,
7442 + unsigned int index, char create) {
7443 + struct listnode *tmp;
7444 + struct static_insegment *in;
7446 + LIST_LOOP(mstatic->insegment,in,tmp) {
7447 + if (in->index == index) {
7448 + return in;
7452 + if (create) {
7453 + in = static_insegment_new(mstatic);
7454 + in->index = index;
7455 + LISTNODE_ADD(mstatic->insegment, &in->node);
7456 + return in;
7458 + return NULL;
7461 +void static_insegment_finish(struct static_insegment *in) {
7462 + LISTNODE_DELETE(in->mstatic->insegment, &in->node);
7463 + XFREE(MTYPE_MPLS_STATIC,in);
7466 +static struct mpls_static *static_new(struct mpls *mpls) {
7467 + struct mpls_static *new = XMALLOC(MTYPE_MPLS_STATIC, sizeof(*new));
7469 + memset(new,0,sizeof(*new));
7470 + new->mpls = mpls;
7471 + new->outsegment = list_new();
7472 + new->insegment = list_new();
7474 + return new;
7477 +struct mpls_static *static_get() {
7478 + struct mpls *mpls = mpls_get();
7479 + if (mpls->mstatic) {
7480 + return mpls->mstatic;
7483 + mpls->mstatic = static_new(mpls);
7484 + return mpls->mstatic;
7487 +void static_finish(struct mpls_static *mstatic) {
7488 + struct mpls *mpls = mstatic->mpls;
7490 + XFREE(MTYPE_MPLS_STATIC,mstatic);
7491 + mpls->mstatic = NULL;
7493 diff --exclude=.p4config -uNr zebra/mplsd/static.h zebra-ldp/mplsd/static.h
7494 --- zebra/mplsd/static.h 1969-12-31 18:00:00.000000000 -0600
7495 +++ zebra-ldp/mplsd/static.h 2003-03-10 14:57:29.000000000 -0600
7496 @@ -0,0 +1,42 @@
7497 +#ifndef STATIC_H
7498 +#define STATIC_H
7500 +#include <zebra.h>
7501 +#include "linklist.h"
7503 +#include "mpls.h"
7504 +#include "lsr_struct.h"
7506 +struct mpls_static {
7507 + struct mpls *mpls;
7508 + mpls_cfg_handle h;
7509 + struct list *insegment;
7510 + struct list *outsegment;
7513 +struct static_insegment {
7514 + struct listnode node;
7515 + struct mpls_static *mstatic;
7516 + unsigned int index;
7517 + lsr_insegment in;
7518 + lsr_xconnect xc;
7519 + unsigned int out_index;
7522 +struct static_outsegment {
7523 + struct listnode node;
7524 + struct mpls_static *mstatic;
7525 + unsigned int index;
7526 + lsr_outsegment out;
7529 +struct mpls_static *static_get();
7530 +void static_finish(struct mpls_static *mstatic);
7531 +struct static_outsegment *static_outsegment_get(struct mpls_static *mstatic,
7532 + unsigned int index, char create);
7533 +void static_outsegment_finish(struct static_outsegment *out);
7534 +struct static_insegment *static_insegment_get(struct mpls_static *mstatic,
7535 + unsigned int index, char create);
7536 +void static_insegment_finish(struct static_insegment *in);
7538 +#endif
7539 diff --exclude=.p4config -uNr zebra/mplsd/static_tunnel.c zebra-ldp/mplsd/static_tunnel.c
7540 --- zebra/mplsd/static_tunnel.c 1969-12-31 18:00:00.000000000 -0600
7541 +++ zebra-ldp/mplsd/static_tunnel.c 2003-03-10 14:57:29.000000000 -0600
7542 @@ -0,0 +1,260 @@
7543 +#include <zebra.h>
7545 +#include "if.h"
7546 +#include "vty.h"
7547 +#include "command.h"
7548 +#include "memory.h"
7549 +#include "out-segment.h"
7551 +#include "tunnel.h"
7552 +#include "interface.h"
7553 +#include "utility.h"
7554 +#include <linux/mpls.h>
7556 +struct list *mplsd_tunnel_list;
7558 +struct mplsd_tunnel *mplsd_tunnel_lookup_by_name(char *name) {
7559 + listnode node;
7560 + struct mplsd_tunnel *ifp;
7562 + for (node = listhead(mplsd_tunnel_list); node; nextnode(node)) {
7563 + ifp = getdata(node);
7564 + if (strncmp(name, ifp->iff.name, sizeof(ifp->iff.name)) == 0) {
7565 + return ifp;
7568 + return NULL;
7571 +struct mplsd_tunnel *mplsd_tunnel_create(char *name, int mode) {
7572 + struct mplsd_tunnel *ifp;
7573 + struct ifreq ifr;
7574 + int result;
7576 + ifp = XMALLOC(MTYPE_MPLS_STATIC, sizeof(struct mplsd_tunnel));
7577 + if(!ifp) return NULL;
7578 + memset(ifp, 0, sizeof(struct mplsd_tunnel));
7580 + listnode_add(mplsd_tunnel_list, ifp);
7582 + strncpy(ifr.ifr_name,name,IFNAMSIZ);
7583 + if(mode) {
7584 + result = mplsd_ioctl(SIOCMPLSTUNNELADD, (caddr_t)&ifr);
7586 + result = mplsd_ioctl(SIOCGIFINDEX, (caddr_t)&ifr);
7587 + strncpy(ifp->iff.name, name, INTERFACE_NAMSIZ);
7588 + ifp->iff.ifindex = ifr.ifr_ifindex;
7589 + return ifp;
7592 +void mplsd_tunnel_delete(struct mplsd_tunnel *ifp, int mode) {
7594 + listnode_delete(mplsd_tunnel_list, ifp);
7596 + if (mode) {
7597 + struct ifreq ifr;
7598 + int result;
7600 + strncpy(ifr.ifr_name,ifp->iff.name,IFNAMSIZ);
7601 + result = mplsd_ioctl(SIOCMPLSTUNNELDEL, (caddr_t)&ifr);
7604 + XFREE(MTYPE_MPLS_STATIC, ifp);
7607 +DEFUN (mplsd_tunnel,
7608 + mplsd_tunnel_cmd,
7609 + "tunnel IFNAME",
7610 + "Create a pseudo tunnel\n"
7611 + "Tunnel's name\n") {
7612 + struct mplsd_interface_wait *wait;
7613 + struct interface *ifp;
7614 + struct mplsd_tunnel *tun;
7615 + int num;
7617 + if(sscanf(argv[0],"mpls%d",&num) != 1) {
7618 + vty_out (vty, "Tunnel names must be in the form 'mpls%%d'%s", VTY_NEWLINE);
7619 + return CMD_WARNING;
7622 + if (!(tun = mplsd_tunnel_lookup_by_name(argv[0]))) {
7623 + tun = mplsd_tunnel_create(argv[0], 1);
7625 + if (!(wait = mplsd_interface_wait_new())) {
7626 + vty_out(vty, "Unable to register for interface%s", VTY_NEWLINE);
7627 + return CMD_ERR_INCOMPLETE;
7630 + wait->data[0] = tun;
7631 + strncpy(wait->ifname, argv[0], INTERFACE_NAMSIZ);
7632 + tun->wait = wait;
7634 + if (!(ifp = if_lookup_by_name(argv[0]))) {
7635 +#if 0
7636 + wait->callback = mplsd_tunnel_callback_add;
7637 + mplsd_interface_add_wait_add(wait);
7638 +#endif
7639 + } else {
7640 +#if 0
7641 + wait->callback = mplsd_tunnel_callback_delete;
7642 + mplsd_interface_add_wait_del(wait);
7643 +#endif
7647 + vty->index = tun;
7648 + vty->node = MPLS_IF_NODE;
7650 + return CMD_SUCCESS;
7653 +DEFUN (no_mplsd_tunnel,
7654 + no_mplsd_tunnel_cmd,
7655 + "no tunnel IFNAME",
7656 + "Delete a pseudo tunnel's configuration\n"
7657 + "Tunnel's name\n") {
7658 + struct mplsd_tunnel *tun;
7660 + tun = mplsd_tunnel_lookup_by_name(argv[0]);
7661 + if (!tun) {
7662 + vty_out (vty, "Tunnel %s does not exist%s", argv[0], VTY_NEWLINE);
7663 + return CMD_WARNING;
7666 +#if 0
7667 + mplsd_interface_remove_wait_add(tun->wait);
7668 + mplsd_interface_remove_wait_del(tun->wait);
7669 +#endif
7671 + /* Delete tunnel */
7672 + mplsd_tunnel_delete(tun, 1);
7674 + return CMD_SUCCESS;
7677 +extern struct mplsd_static_info *mplsd_static_info;
7679 +DEFUN (mplsd_tunnel_out_segment,
7680 + mplsd_tunnel_out_segment_cmd,
7681 + "out-segment INDEX",
7682 + "Assign an out-segment to this tunnel\n"
7683 + "MPLS out-segment index\n") {
7685 + struct mplsd_out_segment *out_old;
7686 + struct mplsd_out_segment *out;
7687 + struct interface *tun;
7688 + struct mpls_label ml;
7689 + struct ifreq ifr;
7691 + tun = vty->index;
7693 + if (!(out = mplsd_out_segment_lookup_by_index(mplsd_static_info,
7694 + atoi(argv[0])))) {
7695 + vty_out(vty, "Unable to find out-segment %s%s", argv[0], VTY_NEWLINE);
7696 + return CMD_WARNING;
7699 + out_old = (struct mplsd_out_segment*)tun->info;
7700 + if (out_old) {
7701 + mos2ml(out_old,&ml);
7702 + memcpy(&ifr.ifr_data,&ml,sizeof(struct mpls_label));
7703 + mplsd_ioctl(SIOCMPLSTUNNELDELOUT,(caddr_t)&ifr);
7706 + mos2ml(out,&ml);
7707 + memcpy(&ifr.ifr_data,&ml,sizeof(struct mpls_label));
7708 + if (mplsd_ioctl(SIOCMPLSTUNNELADDOUT,(caddr_t)&ifr)) {
7709 + vty_out(vty, "Unable to set out-segment %s on tunnel %s%s", argv[0],
7710 + tun->name, VTY_NEWLINE);
7711 + return CMD_WARNING;
7713 + tun->info = out;
7714 + return CMD_SUCCESS;
7717 +DEFUN (no_mplsd_tunnel_out_segment,
7718 + no_mplsd_tunnel_out_segment_cmd,
7719 + "no out-segment",
7720 + "Delete the out-segment associated with this tunnel\n"
7721 + "MPLS out-segment index\n") {
7723 + struct interface *tun;
7725 + tun = vty->index;
7727 + if (tun->info) {
7728 + struct mplsd_out_segment *out = tun->info;
7729 + struct mpls_label ml;
7730 + struct ifreq ifr;
7732 + mos2ml(out,&ml);
7733 + memcpy(&ifr.ifr_data,&ml,sizeof(struct mpls_label));
7734 + mplsd_ioctl(SIOCMPLSTUNNELDELOUT,(caddr_t)&ifr);
7737 + return CMD_SUCCESS;
7740 +static void mplsd_dump_tunnel_vty(struct vty *vty, struct mplsd_tunnel *ifp) {
7741 + vty_out (vty, "Tunnel %s%s", ifp->iff.name, VTY_NEWLINE);
7742 + if (ifp->iff.desc) {
7743 + vty_out (vty, " Description: %s%s", ifp->iff.desc, VTY_NEWLINE);
7745 + if (ifp->iff.ifindex <= 0) {
7746 + vty_out(vty, " index %d pseudo tunnel%s", ifp->iff.ifindex, VTY_NEWLINE);
7748 + vty_out (vty, "%s", VTY_NEWLINE);
7751 +DEFUN (mplsd_show_tunnel, mplsd_show_tunnel_cmd,
7752 + "show tunnel [IFNAME]",
7753 + SHOW_STR
7754 + "MPLS Tunnel status and configuration\n"
7755 + "Inteface name\n") {
7756 + listnode node;
7757 + struct mplsd_tunnel *ifp;
7759 + if (argc != 0) {
7760 + ifp = mplsd_tunnel_lookup_by_name(argv[0]);
7761 + if (ifp == NULL) {
7762 + vty_out(vty, "%% Can't find tunnel %s%s", argv[0], VTY_NEWLINE);
7763 + return CMD_WARNING;
7765 + mplsd_dump_tunnel_vty(vty, ifp);
7766 + return CMD_SUCCESS;
7769 + for (node = listhead(mplsd_tunnel_list); node; nextnode(node)) {
7770 + mplsd_dump_tunnel_vty(vty, getdata(node));
7773 + return CMD_SUCCESS;
7776 +static int mplsd_tunnel_config_write(struct vty *vty) {
7777 + listnode node;
7778 + struct interface *ifp;
7780 + for (node = listhead(mplsd_tunnel_list); node; nextnode(node)) {
7781 + ifp = getdata(node);
7782 + vty_out (vty, "tunnel %s%s", ifp->name, VTY_NEWLINE);
7785 + vty_out (vty, "!%s", VTY_NEWLINE);
7786 + return 0;
7789 +static struct cmd_node mplsd_tunnel_node = {MPLS_IF_NODE, "%s(config-tun)# ", 1};
7791 +void mplsd_tunnel_init () {
7792 + mplsd_tunnel_list = list_new();
7794 + install_node(&mplsd_tunnel_node, mplsd_tunnel_config_write);
7795 + install_default(MPLS_IF_NODE);
7797 + install_element(VIEW_NODE, &mplsd_show_tunnel_cmd);
7798 + install_element(ENABLE_NODE, &mplsd_show_tunnel_cmd);
7800 + install_element(CONFIG_NODE, &mplsd_tunnel_cmd);
7801 + install_element(CONFIG_NODE, &no_mplsd_tunnel_cmd);
7803 diff --exclude=.p4config -uNr zebra/mplsd/static_tunnel.h zebra-ldp/mplsd/static_tunnel.h
7804 --- zebra/mplsd/static_tunnel.h 1969-12-31 18:00:00.000000000 -0600
7805 +++ zebra-ldp/mplsd/static_tunnel.h 2003-03-10 14:57:29.000000000 -0600
7806 @@ -0,0 +1,17 @@
7807 +#ifndef MPLS_TUNNEL_H
7808 +#define MPLS_TUNNEL_H
7809 +#include <zebra.h>
7810 +#include "if.h"
7812 +struct mplsd_tunnel {
7813 + struct interface iff;
7814 + struct mplsd_interface_wait *wait;
7815 + struct mplsd_out_segment *out;
7818 +extern void mplsd_tunnel_init();
7819 +extern struct mplsd_tunnel *mplsd_tunnel_lookup_by_name(char *name);
7820 +extern struct mplsd_tunnel *mplsd_tunnel_create(char *name, int mode);
7821 +extern void mplsd_tunnel_delete(struct mplsd_tunnel *ifp, int mode);
7823 +#endif
7824 diff --exclude=.p4config -uNr zebra/mplsd/static_vty.c zebra-ldp/mplsd/static_vty.c
7825 --- zebra/mplsd/static_vty.c 1969-12-31 18:00:00.000000000 -0600
7826 +++ zebra-ldp/mplsd/static_vty.c 2003-03-29 01:12:03.000000000 -0600
7827 @@ -0,0 +1,581 @@
7828 +#include <zebra.h>
7830 +#include "vty.h"
7831 +#include "command.h"
7833 +#include "mpls.h"
7834 +#include "mpls_vty.h"
7835 +#include "static.h"
7837 +#include "lsr_cfg.h"
7839 +char *owner_name[4] = { "LDP", "CR-LDP", "STATIC", "RSVP" };
7841 +DEFUN (mpls_static,
7842 + mpls_static_cmd,
7843 + "mpls static",
7844 + "MPLS configuration\n"
7845 + "Static MPLS configuration\n") {
7847 + vty->node = MPLS_STATIC_NODE;
7848 + vty->index = static_get();
7850 + return CMD_SUCCESS;
7853 +DEFUN (no_mpls_static,
7854 + no_mpls_static_cmd,
7855 + "no mpls static",
7856 + NO_STR
7857 + "MPLS configuration\n"
7858 + "Static MPLS configuration\n") {
7859 + struct mpls *mpls = mpls_get();
7861 + if (!mpls->mstatic) {
7862 + vty_out (vty, "There isn't an active static MPLS instance.%s",
7863 + VTY_NEWLINE);
7864 + return CMD_WARNING;
7867 + static_finish(mpls->mstatic);
7868 + return CMD_SUCCESS;
7871 +static int do_mpls_static_insegment(struct static_insegment *in,
7872 + unsigned int label, unsigned int labelspace) {
7873 + in->in.info.label.type = MPLS_LABEL_TYPE_GENERIC;
7874 + in->in.info.label.u.gen = label;
7875 + in->in.info.labelspace = labelspace;
7876 + in->in.info.owner = MPLS_OWNER_STATIC;
7877 + in->in.info.family = MPLS_FAMILY_IPV4;
7878 + in->in.info.npop = 1;
7879 + return lsr_cfg_insegment_set(in->mstatic->mpls->h,&in->in,LSR_CFG_ADD|
7880 + LSR_INSEGMENT_CFG_NPOP|LSR_INSEGMENT_CFG_FAMILY|
7881 + LSR_INSEGMENT_CFG_LABELSPACE|LSR_INSEGMENT_CFG_LABEL|
7882 + LSR_INSEGMENT_CFG_OWNER);
7885 +static int do_mpls_static_outsegment(struct static_outsegment *out,
7886 + unsigned int label, mpls_nexthop *nh) {
7887 + out->out.info.label.type = MPLS_LABEL_TYPE_GENERIC;
7888 + out->out.info.label.u.gen = label;
7889 + out->out.info.owner = MPLS_OWNER_STATIC;
7890 + out->out.info.push_label = MPLS_BOOL_TRUE;
7891 + memcpy(&out->out.info.nexthop, nh, sizeof(mpls_nexthop));
7893 + return lsr_cfg_outsegment_set(out->mstatic->mpls->h,&out->out, LSR_CFG_ADD|
7894 + LSR_OUTSEGMENT_CFG_PUSH_LABEL|LSR_OUTSEGMENT_CFG_OWNER|
7895 + LSR_OUTSEGMENT_CFG_LABEL|LSR_OUTSEGMENT_CFG_NEXTHOP);
7898 +static int do_mpls_static_xconnect(struct static_insegment *in,
7899 + struct static_outsegment *out) {
7900 + in->xc.insegment_index = in->in.index;
7901 + in->xc.outsegment_index = out->out.index;
7902 + in->xc.info.owner = MPLS_OWNER_STATIC;
7903 + in->xc.info.lspid = 1;
7904 + return lsr_cfg_xconnect_set2(in->mstatic->mpls->h, &in->xc, LSR_CFG_ADD|
7905 + LSR_XCONNECT_CFG_OUTSEGMENT|LSR_XCONNECT_CFG_INSEGMENT|
7906 + LSR_XCONNECT_CFG_LSPID|LSR_XCONNECT_CFG_OWNER);
7909 +DEFUN (mpls_static_in_segment,
7910 + mpls_static_in_segment_cmd,
7911 + "in-segment INDEX generic LABEL LABELSPACE",
7912 + "Create an MPLS in-segment\n"
7913 + "Insegment index\n"
7914 + "Generic label family\n"
7915 + "Generic label value\n"
7916 + "LabelSpace\n") {
7917 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
7918 + struct static_insegment *in;
7919 + unsigned int index;
7920 + unsigned int label;
7921 + unsigned int labelspace;
7923 + VTY_GET_UINT32("INDEX",index,argv[0]);
7924 + VTY_GET_UINT32_RANGE("LABEL",label,argv[1],16,0xFFFFF);
7925 + VTY_GET_UINT32_RANGE("LABELSPACE",labelspace,argv[2],0,255);
7927 + if ((in = static_insegment_get(mstatic, index, 0))) {
7928 + vty_out (vty, "There is an insegment with index %d already.%s", index,
7929 + VTY_NEWLINE);
7930 + return CMD_WARNING;
7933 + in = static_insegment_get(mstatic, index, 1);
7934 + do_mpls_static_insegment(in, label, labelspace);
7935 + return CMD_SUCCESS;
7938 +DEFUN (mpls_static_in_segment_xc,
7939 + mpls_static_in_segment_xc_cmd,
7940 + "in-segment INDEX generic LABEL LABELSPACE cross-connect OUTINDEX",
7941 + "Create an MPLS in-segment\n"
7942 + "Insegment index\n"
7943 + "Generic label family\n"
7944 + "Generic label value\n"
7945 + "LabelSpace\n"
7946 + "Cross Connect\n"
7947 + "Outsegment Index\n") {
7948 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
7949 + struct static_insegment *in;
7950 + struct static_outsegment *out;
7951 + unsigned int index;
7952 + unsigned int label;
7953 + unsigned int labelspace;
7954 + unsigned int out_index;
7956 + VTY_GET_UINT32("INDEX",index,argv[0]);
7957 + VTY_GET_UINT32_RANGE("LABEL",label,argv[1],16,0xFFFFF);
7958 + VTY_GET_UINT32_RANGE("LABELSPACE",labelspace,argv[2],0,255);
7959 + VTY_GET_UINT32("OUTINDEX",out_index,argv[3]);
7961 + if (!(out = static_outsegment_get(mstatic, out_index, 0))) {
7962 + vty_out (vty, "There isn't an outsegment with index %d.%s", out_index,
7963 + VTY_NEWLINE);
7964 + return CMD_WARNING;
7967 + in = static_insegment_get(mstatic, index, 1);
7968 + if (in->in.index) {
7969 + if (in->in.info.label.type != MPLS_LABEL_TYPE_GENERIC ||
7970 + in->in.info.label.u.gen != label ||
7971 + in->in.info.labelspace != labelspace ||
7972 + in->in.info.owner != MPLS_OWNER_STATIC) {
7973 + vty_out (vty, "There is an insegment with index %d, label %d,"
7974 + "and labelspace %d already.%s", index, label, labelspace,
7975 + VTY_NEWLINE);
7976 + return CMD_WARNING;
7978 + } else {
7979 + do_mpls_static_insegment(in, label, labelspace);
7982 + if (in->out_index) {
7983 + vty_out (vty, "Insegment %d is already cross-connect to "
7984 + "outsegment %d.%s", index, in->out_index, VTY_NEWLINE);
7985 + return CMD_WARNING;
7987 + in->out_index = out_index;
7988 + do_mpls_static_xconnect(in, out);
7990 + return CMD_SUCCESS;
7993 +DEFUN (mpls_static_in_segment_xc2,
7994 + mpls_static_in_segment_xc2_cmd,
7995 + "in-segment INDEX cross-connect OUTINDEX",
7996 + "Create an MPLS in-segment\n"
7997 + "Insegment index\n"
7998 + "Cross Connect\n"
7999 + "Outsegment Index\n") {
8000 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
8001 + struct static_insegment *in;
8002 + struct static_outsegment *out;
8003 + unsigned int index;
8004 + unsigned int out_index;
8006 + VTY_GET_UINT32("INDEX",index,argv[0]);
8007 + VTY_GET_UINT32("OUTINDEX",out_index,argv[1]);
8009 + if (!(in = static_insegment_get(mstatic, index, 0))) {
8010 + vty_out (vty, "There isn't an insegment with index %d.%s", index,
8011 + VTY_NEWLINE);
8012 + return CMD_WARNING;
8015 + if (!(out = static_outsegment_get(mstatic, out_index, 0))) {
8016 + vty_out (vty, "There isn't an outsegment with index %d.%s", out_index,
8017 + VTY_NEWLINE);
8018 + return CMD_WARNING;
8021 + do_mpls_static_xconnect(in, out);
8023 + return CMD_SUCCESS;
8026 +DEFUN (no_mpls_static_in_segment,
8027 + no_mpls_static_in_segment_cmd,
8028 + "no in-segment INDEX",
8029 + NO_STR
8030 + "Delete an MPLS in-segment\n"
8031 + "Index of In-segment\n") {
8032 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
8033 + struct static_insegment *in;
8034 + int index;
8036 + VTY_GET_UINT32("INDEX",index,argv[0]);
8038 + if (!(in = static_insegment_get(mstatic, index, 0))) {
8039 + vty_out (vty, "There isn't an insegment with the index %d.%s", index,
8040 + VTY_NEWLINE);
8041 + return CMD_WARNING;
8043 + lsr_cfg_insegment_set(in->mstatic->mpls->h,&in->in,LSR_CFG_DEL);
8044 + static_insegment_finish(in);
8045 + return CMD_SUCCESS;
8048 +DEFUN (no_mpls_static_in_segment_xc,
8049 + no_mpls_static_in_segment_xc_cmd,
8050 + "no in-segment INDEX cross-connect",
8051 + NO_STR
8052 + "Delete an MPLS in-segment\n"
8053 + "Index of In-segment\n"
8054 + "Cross Connect\n") {
8055 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
8056 + struct static_insegment *in;
8057 + int index;
8059 + VTY_GET_UINT32("INDEX",index,argv[0]);
8061 + if (!(in = static_insegment_get(mstatic, index, 0))) {
8062 + vty_out (vty, "There isn't an insegment with the index %d.%s", index,
8063 + VTY_NEWLINE);
8064 + return CMD_WARNING;
8066 + if (!in->out_index) {
8067 + vty_out (vty, "Insegment %d is not cross-conencted to anything.%s",
8068 + index, VTY_NEWLINE);
8069 + return CMD_WARNING;
8071 + lsr_cfg_xconnect_set(in->mstatic->mpls->h,&in->xc,LSR_CFG_DEL);
8072 + in->out_index = 0;
8073 + return CMD_SUCCESS;
8076 +DEFUN (mpls_static_out_segment_nh_ipaddr,
8077 + mpls_static_out_segment_nh_ipaddr_cmd,
8078 + "out-segment INDEX generic LABEL next-hop IPADDR",
8079 + "Create an MPLS out-segment\n"
8080 + "Index for the out-segment\n"
8081 + "Generic label family\n"
8082 + "Generic label value\n"
8083 + "Next Hop\n"
8084 + "IP Address\n") {
8085 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
8086 + struct static_outsegment *out;
8087 + struct interface *iff;
8088 + unsigned int index;
8089 + unsigned int label;
8090 + struct in_addr ip;
8091 + mpls_nexthop nh;
8093 + VTY_GET_UINT32("INDEX",index,argv[0]);
8094 + VTY_GET_UINT32("LABEL",label,argv[1]);
8095 + VTY_GET_IPV4_ADDRESS("NEXTHOP",nh.ip.u.ipv4,argv[2]);
8096 + ip.s_addr = htonl(nh.ip.u.ipv4);
8098 + if ((out = static_outsegment_get(mstatic, index, 0))) {
8099 + vty_out (vty, "There is an insegment with index %d already.%s", index,
8100 + VTY_NEWLINE);
8101 + return CMD_WARNING;
8104 + out = static_outsegment_get(mstatic, index, 1);
8105 + iff = if_lookup_address(ip);
8106 + nh.type = MPLS_NH_IP|MPLS_NH_IF;
8107 + nh.if_handle = iff;
8109 + do_mpls_static_outsegment(out, label, &nh);
8111 + return CMD_SUCCESS;
8114 +DEFUN (mpls_static_out_segment_nh_intf,
8115 + mpls_static_out_segment_nh_intf_cmd,
8116 + "out-segment INDEX generic LABEL interface IFNAME",
8117 + "Create an MPLS out-segment\n"
8118 + "Index for the out-segment\n"
8119 + "Generic label family\n"
8120 + "Generic label value\n"
8121 + "Next Hop\n"
8122 + "Interface\n") {
8123 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
8124 + struct static_outsegment *out;
8125 + struct interface *iff;
8126 + unsigned int index;
8127 + unsigned int label;
8128 + mpls_nexthop nh;
8130 + VTY_GET_UINT32("INDEX",index,argv[0]);
8131 + VTY_GET_UINT32("LABEL",label,argv[1]);
8133 + if ((out = static_outsegment_get(mstatic, index, 0))) {
8134 + vty_out (vty, "There is an insegment with index %d already.%s", index,
8135 + VTY_NEWLINE);
8136 + return CMD_WARNING;
8139 + out = static_outsegment_get(mstatic, index, 1);
8140 + iff = if_lookup_by_name(argv[2]);
8141 + nh.type = MPLS_NH_IF;
8142 + nh.if_handle = iff;
8144 + do_mpls_static_outsegment(out, label, &nh);
8146 + return CMD_SUCCESS;
8149 +DEFUN (no_mpls_static_out_segment,
8150 + no_mpls_static_out_segment_cmd,
8151 + "no out-segment INDEX",
8152 + NO_STR
8153 + "Delete an MPLS out-segment\n"
8154 + "Index of the out-segment\n") {
8155 + struct mpls_static *mstatic = (struct mpls_static*)vty->index;
8156 + struct static_outsegment *out;
8157 + unsigned int index;
8159 + VTY_GET_UINT32("INDEX",index,argv[0]);
8161 + if (!(out = static_outsegment_get(mstatic, index, 0))) {
8162 + vty_out (vty, "There isn't an outsegment with the index %d.%s", index,
8163 + VTY_NEWLINE);
8164 + return CMD_WARNING;
8167 + lsr_cfg_outsegment_set(out->mstatic->mpls->h,&out->out,LSR_CFG_DEL);
8168 + static_outsegment_finish(out);
8169 + return CMD_SUCCESS;
8172 +DEFUN (mpls_show_mpls_fwd, mpls_show_mpls_fwd_cmd,
8173 + "show mpls forwarding",
8174 + SHOW_STR
8175 + "MPLS related commands\n"
8176 + "MPLS forwarding table\n") {
8177 + struct mpls *mpls = mpls_get();
8178 + struct lsr_outsegment out;
8179 + struct lsr_insegment in;
8180 + struct lsr_xconnect xc;
8181 + struct in_addr ip;
8182 + struct interface *iff;
8183 + int count;
8185 + if (!mpls) {
8186 + vty_out (vty, "There isn't an active MPLS instance.%s",
8187 + VTY_NEWLINE);
8188 + return CMD_WARNING;
8191 + vty_out(vty, "Insegments:%s",VTY_NEWLINE);
8193 + count = 0;
8194 + in.index = 0;
8195 + while (lsr_cfg_insegment_getnext(mpls->h,&in,0xFFFFFFFF)==MPLS_SUCCESS) {
8196 + if (!count) {
8197 + vty_out(vty, " Lbl Spc Label Owner%s", VTY_NEWLINE);
8199 + vty_out(vty, " %-3d %7d %-6s%s", in.info.labelspace,
8200 + in.info.label.u.gen, owner_name[in.info.owner], VTY_NEWLINE);
8201 + count++;
8203 + if (!count) {
8204 + vty_out(vty, "%s", VTY_NEWLINE);
8206 + vty_out(vty, "Total %d%s",count, VTY_NEWLINE);
8207 + vty_out(vty, "%s", VTY_NEWLINE);
8209 + vty_out(vty, "Outsegments:%s",VTY_NEWLINE);
8210 + count = 0;
8211 + out.index = 0;
8212 + while (lsr_cfg_outsegment_getnext(mpls->h,&out,0xFFFFFFFF)==MPLS_SUCCESS) {
8213 + if (!count) {
8214 + vty_out(vty, " Interface Label Next Hop Owner%s",
8215 + VTY_NEWLINE);
8217 + if (out.info.nexthop.type & MPLS_NH_IP) {
8218 + ip.s_addr = htonl(out.info.nexthop.ip.u.ipv4);
8219 + } else {
8220 + ip.s_addr = 0;
8222 + if (out.info.nexthop.type & MPLS_NH_IF) {
8223 + iff = out.info.nexthop.if_handle;
8224 + } else {
8225 + iff = NULL;
8227 + vty_out(vty, " %-16s %7d %-15s %-6s%s",iff->name,
8228 + out.info.label.u.gen, inet_ntoa(ip), owner_name[out.info.owner],
8229 + VTY_NEWLINE);
8230 + count++;
8232 + if (!count) {
8233 + vty_out(vty, "%s", VTY_NEWLINE);
8235 + vty_out(vty, "Total %d%s",count, VTY_NEWLINE);
8236 + vty_out(vty, "%s", VTY_NEWLINE);
8238 + vty_out(vty, "Cross Connects:%s",VTY_NEWLINE);
8239 + count = 0;
8240 + xc.index = 0;
8241 + while (lsr_cfg_xconnect_getnext(mpls->h,&xc,0xFFFFFFFF) == MPLS_SUCCESS) {
8242 + if (!count) {
8243 + vty_out(vty, " Lbl Spc In Label Out Label Interface "
8244 + "Next Hop Owner%s", VTY_NEWLINE);
8247 + in.index = xc.insegment_index;
8248 + lsr_cfg_insegment_get(mpls->h,&in,0xFFFFFFFF);
8250 + out.index = xc.outsegment_index;
8251 + lsr_cfg_outsegment_get(mpls->h,&out,0xFFFFFFFF);
8252 + if (out.info.nexthop.type & MPLS_NH_IP) {
8253 + ip.s_addr = htonl(out.info.nexthop.ip.u.ipv4);
8254 + } else {
8255 + ip.s_addr = 0;
8257 + if (out.info.nexthop.type & MPLS_NH_IF) {
8258 + iff = out.info.nexthop.if_handle;
8259 + } else {
8260 + iff = NULL;
8263 + vty_out(vty, " %-3d %7d %7d %-16s %-15s %-6s%s",
8264 + in.info.labelspace, in.info.label.u.gen, out.info.label.u.gen,
8265 + iff->name, inet_ntoa(ip), owner_name[in.info.owner], VTY_NEWLINE);
8266 + count++;
8268 + if (!count) {
8269 + vty_out(vty, "%s", VTY_NEWLINE);
8271 + vty_out(vty, "Total %d%s",count, VTY_NEWLINE);
8272 + vty_out(vty, "%s", VTY_NEWLINE);
8274 + return CMD_SUCCESS;
8277 +DEFUN (mpls_show_mpls_ftn, mpls_show_mpls_ftn_cmd,
8278 + "show mpls ftn",
8279 + SHOW_STR
8280 + "MPLS related commands\n"
8281 + "MPLS FTN bindings\n") {
8282 + struct mpls *mpls = mpls_get();
8283 + lsr_outsegment out;
8284 + char buf[24];
8285 + struct interface *iff;
8286 + struct in_addr ip;
8287 + lsr_ftn ftn;
8288 + int count = 0;
8290 + vty_out(vty, "FTNs:%s",VTY_NEWLINE);
8291 + ftn.index = 0;
8292 + while (lsr_cfg_ftn_getnext(mpls->h,&ftn,0xFFFFFFFF) == MPLS_SUCCESS) {
8293 + if (!count) {
8294 + vty_out(vty, " FEC Out Label Interface "
8295 + "Next Hop Owner%s", VTY_NEWLINE);
8298 + out.index = ftn.outsegment_index;
8299 + lsr_cfg_outsegment_get(mpls->h,&out,0xFFFFFFFF);
8301 + vty_out(vty, " ");
8302 + switch(ftn.fec.type) {
8303 + case MPLS_FEC_PREFIX:
8304 + ip.s_addr = htonl(ftn.fec.u.prefix.network.u.ipv4);
8305 + sprintf(buf, "%s/%d", inet_ntoa(ip),ftn.fec.u.prefix.length);
8306 + vty_out(vty, "%-18s", buf);
8307 + break;
8308 + case MPLS_FEC_HOST:
8309 + ip.s_addr = htonl(ftn.fec.u.host.u.ipv4);
8310 + vty_out(vty, "%-18s", inet_ntoa(ip));
8311 + break;
8312 + case MPLS_FEC_L2CC:
8313 + default:
8314 + vty_out(vty, "%-18s", "(unknown)");
8316 + vty_out(vty, " ");
8318 + if (out.info.nexthop.type & MPLS_NH_IP) {
8319 + ip.s_addr = htonl(out.info.nexthop.ip.u.ipv4);
8320 + } else {
8321 + ip.s_addr = 0;
8323 + if (out.info.nexthop.type & MPLS_NH_IF) {
8324 + iff = out.info.nexthop.if_handle;
8325 + } else {
8326 + iff = NULL;
8328 + vty_out(vty, "%7d %-15s %-15s %-6s%s", out.info.label.u.gen,
8329 + iff->name, inet_ntoa(ip), owner_name[out.info.owner], VTY_NEWLINE);
8331 + count++;
8334 + if (!count) {
8335 + vty_out(vty, "%s", VTY_NEWLINE);
8337 + vty_out(vty, "Total %d%s",count, VTY_NEWLINE);
8338 + vty_out(vty, "%s", VTY_NEWLINE);
8339 + return CMD_SUCCESS;
8342 +static int mpls_static_config_write (struct vty *vty) {
8343 + struct mpls *mpls = mpls_get();
8344 + struct mpls_static *mstatic = mpls->mstatic;
8345 + struct static_outsegment *out;
8346 + struct static_insegment *in;
8347 + struct listnode *tmp;
8349 + if (!mstatic) {
8350 + return 0;
8353 + vty_out(vty, "mpls static%s", VTY_NEWLINE);
8355 + LIST_LOOP(mstatic->outsegment, out, tmp) {
8356 + vty_out(vty, " out-segment %d generic %d", out->index,
8357 + out->out.info.label.u.gen);
8358 + if (out->out.info.nexthop.type & MPLS_NH_IF) {
8359 + vty_out(vty, " interface %s",
8360 + out->out.info.nexthop.if_handle->name);
8362 + if (out->out.info.nexthop.type & MPLS_NH_IP) {
8363 + struct in_addr ip;
8364 + ip.s_addr = htonl(out->out.info.nexthop.ip.u.ipv4);
8365 + vty_out(vty, " next-hop %s", inet_ntoa(ip));
8367 + vty_out(vty,"%s", VTY_NEWLINE);
8370 + LIST_LOOP(mstatic->insegment, in, tmp) {
8371 + vty_out(vty, " in-segment %d generic %d %d", in->index,
8372 + in->in.info.label.u.gen, in->in.info.labelspace);
8373 + if (in->out_index) {
8374 + vty_out(vty, " cross-connect %d", in->out_index);
8376 + vty_out(vty, "%s", VTY_NEWLINE);
8378 + vty_out(vty,"!%s", VTY_NEWLINE);
8379 + return 0;
8382 +static struct cmd_node static_node = {MPLS_STATIC_NODE,"%s(config-mpls)# ",1};
8384 +void static_vty_show_init() {
8385 + install_element (VIEW_NODE, &mpls_show_mpls_fwd_cmd);
8386 + install_element (ENABLE_NODE, &mpls_show_mpls_fwd_cmd);
8388 + install_element (VIEW_NODE, &mpls_show_mpls_ftn_cmd);
8389 + install_element (ENABLE_NODE, &mpls_show_mpls_ftn_cmd);
8392 +void static_vty_init () {
8394 + install_node (&static_node, mpls_static_config_write);
8395 + install_default (MPLS_STATIC_NODE);
8397 + install_element (CONFIG_NODE, &mpls_static_cmd);
8398 + install_element (CONFIG_NODE, &no_mpls_static_cmd);
8400 + install_element(MPLS_STATIC_NODE, &mpls_static_in_segment_cmd);
8401 + install_element(MPLS_STATIC_NODE, &mpls_static_in_segment_xc_cmd);
8402 + install_element(MPLS_STATIC_NODE, &no_mpls_static_in_segment_cmd);
8403 + install_element(MPLS_STATIC_NODE, &no_mpls_static_in_segment_xc_cmd);
8405 + install_element(MPLS_STATIC_NODE, &mpls_static_out_segment_nh_ipaddr_cmd);
8406 + install_element(MPLS_STATIC_NODE, &mpls_static_out_segment_nh_intf_cmd);
8407 + install_element(MPLS_STATIC_NODE, &no_mpls_static_out_segment_cmd);
8409 diff --exclude=.p4config -uNr zebra/mplsd/static_vty.h zebra-ldp/mplsd/static_vty.h
8410 --- zebra/mplsd/static_vty.h 1969-12-31 18:00:00.000000000 -0600
8411 +++ zebra-ldp/mplsd/static_vty.h 2003-03-10 14:57:30.000000000 -0600
8412 @@ -0,0 +1,7 @@
8413 +#ifndef STATIC_VTY_H
8414 +#define STATIC_VTY_H
8416 +void static_vty_init();
8417 +void static_vty_show_init();
8419 +#endif
8420 diff --exclude=.p4config -uNr zebra/ospfd/ospfd.c zebra-ldp/ospfd/ospfd.c
8421 --- zebra/ospfd/ospfd.c 2003-03-29 18:16:22.000000000 -0600
8422 +++ zebra-ldp/ospfd/ospfd.c 2003-03-10 14:58:38.000000000 -0600
8423 @@ -56,6 +56,7 @@
8424 struct ospf *ospf_top;
8426 extern struct zclient *zclient;
8427 +extern struct in_addr router_id_zebra;
8430 void ospf_remove_vls_through_area (struct ospf_area *);
8431 @@ -63,33 +64,6 @@
8432 void ospf_area_free (struct ospf_area *);
8433 void ospf_network_run (struct ospf *, struct prefix *, struct ospf_area *);
8435 -/* Get Router ID from ospf interface list. */
8436 -struct in_addr
8437 -ospf_router_id_get (list if_list)
8439 - listnode node;
8440 - struct in_addr router_id;
8442 - memset (&router_id, 0, sizeof (struct in_addr));
8444 - for (node = listhead (if_list); node; nextnode (node))
8446 - struct ospf_interface *oi = getdata (node);
8448 - if (!if_is_up (oi->ifp) ||
8449 - OSPF_IF_PARAM (oi, passive_interface) == OSPF_IF_PASSIVE)
8450 - continue;
8452 - /* Ignore virtual link interface. */
8453 - if (oi->type != OSPF_IFTYPE_VIRTUALLINK &&
8454 - oi->type != OSPF_IFTYPE_LOOPBACK)
8455 - if (IPV4_ADDR_CMP (&router_id, &oi->address->u.prefix4) < 0)
8456 - router_id = oi->address->u.prefix4;
8459 - return router_id;
8462 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
8464 void
8465 @@ -106,7 +80,7 @@
8466 if (ospf_top->router_id_static.s_addr != 0)
8467 router_id = ospf_top->router_id_static;
8468 else
8469 - router_id = ospf_router_id_get (ospf_top->oiflist);
8470 + router_id = router_id_zebra;
8472 ospf_top->router_id = router_id;
8474 diff --exclude=.p4config -uNr zebra/ospfd/ospf_lsdb.c zebra-ldp/ospfd/ospf_lsdb.c
8475 --- zebra/ospfd/ospf_lsdb.c 2003-03-29 18:15:59.000000000 -0600
8476 +++ zebra-ldp/ospfd/ospf_lsdb.c 2003-03-10 14:58:06.000000000 -0600
8477 @@ -284,8 +284,8 @@
8480 struct ospf_lsa *
8481 -foreach_lsa (struct route_table *table, void *p_arg, int int_arg,
8482 - int (*callback) (struct ospf_lsa *, void *, int))
8483 +foreach_lsa (struct route_table *table, void *p_arg, int int_arg,
8484 + int (*callback) (struct ospf_lsa *, void *, int))
8486 struct route_node *rn;
8487 struct ospf_lsa *lsa;
8488 @@ -293,6 +293,21 @@
8489 for (rn = route_top (table); rn; rn = route_next (rn))
8490 if ((lsa = rn->info) != NULL)
8491 if (callback (lsa, p_arg, int_arg))
8492 + return lsa;
8494 + return NULL;
8497 +struct ospf_lsa *
8498 +foreach_lsa_sum (struct route_table *table, void *p_arg, int *sum, int int_arg,
8499 + int (*callback) (struct ospf_lsa *, void *, int*, int))
8501 + struct route_node *rn;
8502 + struct ospf_lsa *lsa;
8504 + for (rn = route_top (table); rn; rn = route_next (rn))
8505 + if ((lsa = rn->info) != NULL)
8506 + if (callback (lsa, p_arg, sum, int_arg))
8507 return lsa;
8509 return NULL;
8510 diff --exclude=.p4config -uNr zebra/ospfd/ospf_lsdb.h zebra-ldp/ospfd/ospf_lsdb.h
8511 --- zebra/ospfd/ospf_lsdb.h 2003-03-29 18:15:59.000000000 -0600
8512 +++ zebra-ldp/ospfd/ospf_lsdb.h 2003-03-10 14:58:06.000000000 -0600
8513 @@ -79,5 +79,7 @@
8514 unsigned long ospf_lsdb_isempty (struct ospf_lsdb *);
8515 struct ospf_lsa *foreach_lsa (struct route_table *, void *, int,
8516 int (*callback) (struct ospf_lsa *, void *, int));
8517 +struct ospf_lsa *foreach_lsa_sum (struct route_table *, void *, int *, int,
8518 + int (*callback) (struct ospf_lsa *, void *, int *, int));
8520 #endif /* _ZEBRA_OSPF_LSDB_H */
8521 diff --exclude=.p4config -uNr zebra/ospfd/ospf_vty.c zebra-ldp/ospfd/ospf_vty.c
8522 --- zebra/ospfd/ospf_vty.c 2003-03-29 18:16:18.000000000 -0600
8523 +++ zebra-ldp/ospfd/ospf_vty.c 2003-03-10 14:58:35.000000000 -0600
8524 @@ -3046,7 +3046,7 @@
8526 /* Show functions */
8528 -show_lsa_summary (struct ospf_lsa *lsa, void *v, int self)
8529 +show_lsa_summary (struct ospf_lsa *lsa, void *v, int *sum, int self)
8531 struct vty *vty = (struct vty *) v;
8532 struct router_lsa *rl;
8533 @@ -3059,6 +3059,7 @@
8534 if (self == 0 || IS_LSA_SELF (lsa))
8536 /* LSA common part show. */
8537 + (*sum) += ntohs (lsa->data->checksum);
8538 vty_out (vty, "%-15s ", inet_ntoa (lsa->data->id));
8539 vty_out (vty, "%-15s %4d 0x%08lx 0x%04x",
8540 inet_ntoa (lsa->data->adv_router), LS_AGE (lsa),
8541 @@ -3592,6 +3593,7 @@
8542 void
8543 show_ip_ospf_database_summary (struct vty *vty, int self)
8545 + unsigned int sum;
8546 listnode node;
8547 int type;
8549 @@ -3619,9 +3621,10 @@
8550 VTY_NEWLINE, VTY_NEWLINE);
8551 vty_out (vty, "%s%s", show_database_header[type], VTY_NEWLINE);
8553 - foreach_lsa (AREA_LSDB (area, type), vty, self, show_lsa_summary);
8555 - vty_out (vty, "%s", VTY_NEWLINE);
8556 + sum = 0;
8557 + foreach_lsa_sum (AREA_LSDB (area, type), vty, &sum, self, show_lsa_summary);
8558 + vty_out (vty, "%s Sum of CkSum: 0x%08x%s%s",
8559 + VTY_NEWLINE, sum, VTY_NEWLINE, VTY_NEWLINE);
8563 @@ -3646,8 +3649,11 @@
8564 VTY_NEWLINE, VTY_NEWLINE);
8565 vty_out (vty, "%s%s", show_database_header[type],
8566 VTY_NEWLINE);
8567 - foreach_lsa (AS_LSDB (ospf_top, type), vty, self, show_lsa_summary);
8568 - vty_out (vty, "%s", VTY_NEWLINE);
8570 + sum = 0;
8571 + foreach_lsa_sum (AS_LSDB (ospf_top, type), vty, &sum, self, show_lsa_summary);
8572 + vty_out (vty, "%s Sum of CkSum: 0x%08x%s%s",
8573 + VTY_NEWLINE, sum, VTY_NEWLINE, VTY_NEWLINE);
8577 diff --exclude=.p4config -uNr zebra/ospfd/ospf_zebra.c zebra-ldp/ospfd/ospf_zebra.c
8578 --- zebra/ospfd/ospf_zebra.c 2003-03-29 18:16:20.000000000 -0600
8579 +++ zebra-ldp/ospfd/ospf_zebra.c 2003-03-10 14:58:36.000000000 -0600
8580 @@ -53,6 +53,23 @@
8582 /* For registering threads. */
8583 extern struct thread_master *master;
8584 +struct in_addr router_id_zebra;
8586 +/* Router-id update message from zebra. */
8587 +int
8588 +ospf_router_id_update_zebra (int command, struct zclient *zclient,
8589 + zebra_size_t length)
8591 + struct prefix router_id;
8592 + zebra_router_id_update_read(zclient->ibuf,&router_id);
8594 + router_id_zebra = router_id.u.prefix4;
8596 + if (ospf_top && ospf_top->t_router_id_update == NULL)
8597 + ospf_top->t_router_id_update = thread_add_timer (master,
8598 + ospf_router_id_update_timer, ospf_top, OSPF_ROUTER_ID_UPDATE_DELAY);
8599 + return 0;
8602 /* Inteface addition message from zebra. */
8604 @@ -147,19 +164,6 @@
8605 return ifp;
8608 -void
8609 -zebra_interface_if_set_value (struct stream *s, struct interface *ifp)
8611 - /* Read interface's index. */
8612 - ifp->ifindex = stream_getl (s);
8614 - /* Read interface's value. */
8615 - ifp->flags = stream_getl (s);
8616 - ifp->metric = stream_getl (s);
8617 - ifp->mtu = stream_getl (s);
8618 - ifp->bandwidth = stream_getl (s);
8622 ospf_interface_state_up (int command, struct zclient *zclient,
8623 zebra_size_t length)
8624 @@ -1166,6 +1170,7 @@
8625 /* Allocate zebra structure. */
8626 zclient = zclient_new ();
8627 zclient_init (zclient, ZEBRA_ROUTE_OSPF);
8628 + zclient->router_id_update = ospf_router_id_update_zebra;
8629 zclient->interface_add = ospf_interface_add;
8630 zclient->interface_delete = ospf_interface_delete;
8631 zclient->interface_up = ospf_interface_state_up;
8632 diff --exclude=.p4config -uNr zebra/zebra/main.c zebra-ldp/zebra/main.c
8633 --- zebra/zebra/main.c 2003-03-29 18:17:22.000000000 -0600
8634 +++ zebra-ldp/zebra/main.c 2003-03-10 14:59:27.000000000 -0600
8635 @@ -34,7 +34,7 @@
8636 #include "zebra/rib.h"
8637 #include "zebra/zserv.h"
8638 #include "zebra/debug.h"
8639 -#include "zebra/rib.h"
8640 +#include "zebra/router-id.h"
8642 /* Master of threads. */
8643 struct thread_master *master;
8644 @@ -258,6 +258,7 @@
8645 rib_init ();
8646 zebra_if_init ();
8647 zebra_debug_init ();
8648 + router_id_init();
8649 zebra_vty_init ();
8650 access_list_init ();
8651 rtadv_init ();
8652 diff --exclude=.p4config -uNr zebra/zebra/Makefile.am zebra-ldp/zebra/Makefile.am
8653 --- zebra/zebra/Makefile.am 2003-03-29 18:17:16.000000000 -0600
8654 +++ zebra-ldp/zebra/Makefile.am 2003-03-10 14:59:23.000000000 -0600
8655 @@ -21,11 +21,11 @@
8657 zebra_SOURCES = \
8658 zserv.c main.c interface.c connected.c ioctl.c zebra_rib.c \
8659 - redistribute.c debug.c rtadv.c zebra_snmp.c zebra_vty.c
8660 + redistribute.c debug.c rtadv.c zebra_snmp.c zebra_vty.c router-id.c
8662 noinst_HEADERS = \
8663 connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \
8664 - interface.h ipforward.h
8665 + interface.h ipforward.h router-id.h
8667 zebra_LDADD = ../lib/libzebra.a $(otherobj) $(LIB_IPV6)
8669 diff --exclude=.p4config -uNr zebra/zebra/redistribute.c zebra-ldp/zebra/redistribute.c
8670 --- zebra/zebra/redistribute.c 2003-03-29 18:17:22.000000000 -0600
8671 +++ zebra-ldp/zebra/redistribute.c 2003-03-10 14:59:27.000000000 -0600
8672 @@ -35,6 +35,7 @@
8673 #include "zebra/zserv.h"
8674 #include "zebra/redistribute.h"
8675 #include "zebra/debug.h"
8676 +#include "zebra/router-id.h"
8679 zebra_check_addr (struct prefix *p)
8680 @@ -379,6 +380,8 @@
8681 p->prefixlen, ifc->ifp->name);
8684 + router_id_add_address(ifc);
8686 for (node = listhead (client_list); node; nextnode (node))
8687 if ((client = getdata (node)) != NULL)
8688 if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
8689 @@ -403,6 +406,8 @@
8690 p->prefixlen, ifc->ifp->name);
8693 + router_id_del_address(ifc);
8695 for (node = listhead (client_list); node; nextnode (node))
8696 if ((client = getdata (node)) != NULL)
8697 if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
8698 diff --exclude=.p4config -uNr zebra/zebra/rib.h zebra-ldp/zebra/rib.h
8699 --- zebra/zebra/rib.h 2003-03-29 18:17:23.000000000 -0600
8700 +++ zebra-ldp/zebra/rib.h 2003-03-10 14:59:27.000000000 -0600
8701 @@ -135,6 +135,9 @@
8702 unsigned int ifindex;
8703 char *ifname;
8705 + /* MPLS index */
8706 + unsigned int mplsindex;
8708 /* Nexthop address or interface name. */
8709 union
8711 @@ -147,6 +150,7 @@
8712 /* Recursive lookup nexthop. */
8713 u_char rtype;
8714 unsigned int rifindex;
8715 + unsigned int rmplsindex;
8716 union
8718 struct in_addr ipv4;
8719 @@ -215,6 +219,11 @@
8720 void rib_close ();
8721 void rib_init ();
8723 +#include "prefix.h"
8724 +#include "table.h"
8726 +void rib_process (struct route_node *rn, struct rib *del);
8729 static_add_ipv4 (struct prefix *p, struct in_addr *gate, char *ifname,
8730 u_char distance, u_int32_t vrf_id);
8731 diff --exclude=.p4config -uNr zebra/zebra/router-id.c zebra-ldp/zebra/router-id.c
8732 --- zebra/zebra/router-id.c 1969-12-31 18:00:00.000000000 -0600
8733 +++ zebra-ldp/zebra/router-id.c 2003-03-10 14:59:28.000000000 -0600
8734 @@ -0,0 +1,239 @@
8735 +#include <zebra.h>
8737 +#include "if.h"
8738 +#include "vty.h"
8739 +#include "sockunion.h"
8740 +#include "prefix.h"
8741 +#include "stream.h"
8742 +#include "command.h"
8743 +#include "memory.h"
8744 +#include "ioctl.h"
8745 +#include "connected.h"
8746 +#include "network.h"
8747 +#include "log.h"
8748 +#include "table.h"
8749 +#include "rib.h"
8751 +#include "zebra/zserv.h"
8753 +static struct list rid_all_sorted_list;
8754 +static struct list rid_lo_sorted_list;
8755 +static struct prefix rid_user_assigned;
8756 +extern struct list *client_list;
8758 +static struct connected *router_id_find_node(struct list *l,
8759 + struct connected *ifc) {
8760 + struct listnode *node;
8761 + struct connected *c;
8763 + for (node = l->head; node; node = node->next) {
8764 + c = (struct connected*)getdata(node);
8765 + if (prefix_same(ifc->address,c->address)) {
8766 + return c;
8769 + return NULL;
8772 +static int router_id_bad_address(struct connected *ifc) {
8773 + struct prefix n;
8775 + n.u.prefix4.s_addr = htonl(INADDR_LOOPBACK);
8776 + n.prefixlen = 8;
8777 + n.family = AF_INET;
8779 + if (prefix_match(&n,ifc->address)) {
8780 + return 1;
8782 + return 0;
8785 +void router_id_get(struct prefix *p) {
8786 + struct listnode *node;
8787 + struct connected *c;
8789 + p->u.prefix4.s_addr = 0;
8790 + p->family = AF_INET;
8791 + p->prefixlen = 32;
8793 + if (rid_user_assigned.u.prefix4.s_addr) {
8794 + p->u.prefix4.s_addr = rid_user_assigned.u.prefix4.s_addr;
8795 + } else if (!list_isempty(&rid_lo_sorted_list)) {
8796 + node = listtail(&rid_lo_sorted_list);
8797 + c = getdata(node);
8798 + p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
8799 + } else if (!list_isempty(&rid_all_sorted_list)) {
8800 + node = listtail(&rid_all_sorted_list);
8801 + c = getdata(node);
8802 + p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
8806 +static void router_id_set(struct prefix *p) {
8807 + struct prefix p2;
8808 + struct listnode *node;
8809 + struct zserv *client;
8811 + rid_user_assigned.u.prefix4.s_addr = p->u.prefix4.s_addr;
8813 + router_id_get(&p2);
8814 + for (node = listhead(client_list); node; nextnode(node))
8815 + if ((client = getdata(node)) != NULL)
8816 + zsend_router_id_update(client,&p2);
8819 +void router_id_add_address(struct connected *ifc) {
8820 + struct list *l = NULL;
8821 + struct listnode *node;
8822 + struct prefix before;
8823 + struct prefix after;
8824 + struct zserv *client;
8826 + if (router_id_bad_address(ifc)) {
8827 + return;
8830 + router_id_get(&before);
8832 + if (!strncmp(ifc->ifp->name,"lo",2) || !strncmp(ifc->ifp->name,"dummy",5)) {
8833 + l = &rid_lo_sorted_list;
8834 + } else {
8835 + l = &rid_all_sorted_list;
8837 + if (!router_id_find_node(l,ifc)) {
8838 + listnode_add(l,ifc);
8841 + router_id_get(&after);
8843 + if (prefix_same(&before, &after)) {
8844 + return;
8847 + for (node = listhead(client_list); node; nextnode(node))
8848 + if ((client = getdata(node)) != NULL)
8849 + zsend_router_id_update(client,&after);
8852 +void router_id_del_address(struct connected *ifc) {
8853 + struct connected *c;
8854 + struct list *l;
8855 + struct prefix after;
8856 + struct prefix before;
8857 + struct listnode *node;
8858 + struct zserv *client;
8860 + if (router_id_bad_address(ifc)) {
8861 + return;
8864 + router_id_get(&before);
8866 + if (!strncmp(ifc->ifp->name,"lo",2) || !strncmp(ifc->ifp->name,"dummy",5)) {
8867 + l = &rid_lo_sorted_list;
8868 + } else {
8869 + l = &rid_all_sorted_list;
8872 + if ((c = router_id_find_node(l,ifc))) {
8873 + listnode_delete(l,c);
8876 + router_id_get(&after);
8878 + if (prefix_same(&before, &after)) {
8879 + return;
8882 + for (node = listhead(client_list); node; nextnode(node))
8883 + if ((client = getdata(node)) != NULL)
8884 + zsend_router_id_update(client,&after);
8887 +void router_id_write(struct vty *vty) {
8888 + if (rid_user_assigned.u.prefix4.s_addr) {
8889 + vty_out(vty, "router-id %s%s", inet_ntoa(rid_user_assigned.u.prefix4),
8890 + VTY_NEWLINE);
8894 +DEFUN (router_id,
8895 + router_id_cmd,
8896 + "router-id A.B.C.D",
8897 + "Manually set the router-id\n"
8898 + "IP address to use for router-id\n")
8900 + struct prefix rid;
8902 + rid.u.prefix4.s_addr = inet_addr(argv[0]);
8903 + if (!rid.u.prefix4.s_addr) {
8904 + return CMD_WARNING;
8906 + rid.prefixlen = 32;
8907 + rid.family = AF_INET;
8909 + router_id_set(&rid);
8911 + return CMD_SUCCESS;
8914 +DEFUN (no_router_id,
8915 + no_router_id_cmd,
8916 + "no router-id",
8917 + NO_STR
8918 + "Remove the manually configured router-id\n")
8920 + struct prefix rid;
8922 + rid.u.prefix4.s_addr = 0;
8923 + rid.prefixlen = 0;
8924 + rid.family = AF_INET;
8926 + router_id_set(&rid);
8928 + return CMD_SUCCESS;
8931 +DEFUN (show_router_id,
8932 + show_router_id_cmd,
8933 + "show router-id",
8934 + SHOW_STR
8935 + "current router ID\n")
8937 + struct prefix rid;
8938 + router_id_get(&rid);
8940 + vty_out(vty, "router-id: %s%s", inet_ntoa(rid.u.prefix4),VTY_NEWLINE);
8941 + return CMD_SUCCESS;
8944 +int router_id_cmp(void *a, void *b) {
8945 + unsigned int A, B;
8947 + A = ((struct connected*)a)->address->u.prefix4.s_addr;
8948 + B = ((struct connected*)b)->address->u.prefix4.s_addr;
8950 + if (A > B) {
8951 + return 1;
8952 + } else if (A < B) {
8953 + return -1;
8955 + return 0;
8958 +void router_id_init(void) {
8959 + install_element(VIEW_NODE, &show_router_id_cmd);
8960 + install_element(ENABLE_NODE, &show_router_id_cmd);
8961 + install_element(CONFIG_NODE, &router_id_cmd);
8962 + install_element(CONFIG_NODE, &no_router_id_cmd);
8964 + memset(&rid_all_sorted_list,0,sizeof(rid_all_sorted_list));
8965 + memset(&rid_lo_sorted_list,0,sizeof(rid_lo_sorted_list));
8966 + memset(&rid_user_assigned,0,sizeof(rid_user_assigned));
8968 + rid_all_sorted_list.cmp = router_id_cmp;
8969 + rid_lo_sorted_list.cmp = router_id_cmp;
8971 + rid_user_assigned.family = AF_INET;
8972 + rid_user_assigned.prefixlen = 32;
8974 diff --exclude=.p4config -uNr zebra/zebra/router-id.h zebra-ldp/zebra/router-id.h
8975 --- zebra/zebra/router-id.h 1969-12-31 18:00:00.000000000 -0600
8976 +++ zebra-ldp/zebra/router-id.h 2003-03-10 14:59:28.000000000 -0600
8977 @@ -0,0 +1,20 @@
8978 +#ifndef _ROUTER_ID_H_
8979 +#define _ROUTER_ID_H_
8981 +#include <zebra.h>
8983 +#include "memory.h"
8984 +#include "prefix.h"
8985 +#include "zclient.h"
8986 +#include "if.h"
8988 +extern void router_id_add_address(struct connected *);
8989 +extern void router_id_del_address(struct connected *);
8990 +extern void router_id_init(void);
8991 +extern void router_id_write(struct vty *);
8992 +extern void router_id_get(struct prefix *);
8994 +extern void zread_router_id_add(struct zserv *, u_short);
8995 +extern void zread_router_id_delete(struct zserv *, u_short);
8997 +#endif
8998 diff --exclude=.p4config -uNr zebra/zebra/rt_netlink.c zebra-ldp/zebra/rt_netlink.c
8999 --- zebra/zebra/rt_netlink.c 2003-03-29 18:17:24.000000000 -0600
9000 +++ zebra-ldp/zebra/rt_netlink.c 2003-03-10 14:59:30.000000000 -0600
9001 @@ -606,6 +606,7 @@
9003 char anyaddr[16] = {0};
9005 + unsigned int mplsindex;
9006 int index;
9007 int table;
9008 void *dest;
9009 @@ -662,10 +663,14 @@
9010 return 0;
9013 + mplsindex = 0;
9014 index = 0;
9015 dest = NULL;
9016 gate = NULL;
9018 + if (tb[RTA_LSP])
9019 + mplsindex = *(unsigned int *) RTA_DATA (tb[RTA_LSP]);
9021 if (tb[RTA_OIF])
9022 index = *(int *) RTA_DATA (tb[RTA_OIF]);
9024 @@ -1208,6 +1213,10 @@
9025 || nexthop->rtype == NEXTHOP_TYPE_IPV6_IFNAME)
9026 addattr32 (&req.n, sizeof req, RTA_OIF,
9027 nexthop->rifindex);
9029 + if (nexthop->rmplsindex)
9030 + addattr32 (&req.n, sizeof req, RTA_LSP,
9031 + nexthop->rmplsindex);
9033 else
9035 @@ -1228,6 +1237,11 @@
9036 || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX
9037 || nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
9038 addattr32 (&req.n, sizeof req, RTA_OIF, nexthop->ifindex);
9040 + if (nexthop->mplsindex) {
9041 +fprintf(stderr,"Adding RTA_LSP = 0x%x\n",nexthop->mplsindex);
9042 + addattr32 (&req.n, sizeof req, RTA_LSP, nexthop->mplsindex);
9046 if (cmd == RTM_NEWROUTE)
9047 @@ -1290,6 +1304,9 @@
9048 rtnh->rtnh_ifindex = nexthop->rifindex;
9049 else
9050 rtnh->rtnh_ifindex = 0;
9052 + if (nexthop->rmplsindex)
9053 + rtnh->rtnh_lsp = nexthop->rmplsindex;
9055 else
9057 @@ -1316,6 +1333,11 @@
9058 rtnh->rtnh_ifindex = nexthop->ifindex;
9059 else
9060 rtnh->rtnh_ifindex = 0;
9062 + if (nexthop->mplsindex) {
9063 +fprintf(stderr,"Setting rtnh_lsp = 0x%x\n",nexthop->mplsindex);
9064 + rtnh->rtnh_lsp = nexthop->mplsindex;
9067 rtnh = RTNH_NEXT(rtnh);
9069 diff --exclude=.p4config -uNr zebra/zebra/zebra_rib.c zebra-ldp/zebra/zebra_rib.c
9070 --- zebra/zebra/zebra_rib.c 2003-03-29 18:17:27.000000000 -0600
9071 +++ zebra-ldp/zebra/zebra_rib.c 2003-03-13 22:09:09.000000000 -0600
9072 @@ -396,6 +396,7 @@
9074 SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
9075 nexthop->rtype = newhop->type;
9076 + nexthop->rmplsindex = newhop->mplsindex;
9077 if (newhop->type == NEXTHOP_TYPE_IPV4 ||
9078 newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
9079 nexthop->rgate.ipv4 = newhop->gate.ipv4;
9080 @@ -494,6 +495,7 @@
9082 SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
9083 nexthop->rtype = newhop->type;
9084 + nexthop->rmplsindex = newhop->mplsindex;
9085 if (newhop->type == NEXTHOP_TYPE_IPV6
9086 || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX
9087 || newhop->type == NEXTHOP_TYPE_IPV6_IFNAME)
9088 @@ -763,6 +765,9 @@
9089 rib->nexthop_active_num += nexthop_active_check (rn, rib, nexthop, set);
9090 if (active != CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
9091 SET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED);
9093 + if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_MPLS_CHANGED))
9094 + SET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED);
9096 return rib->nexthop_active_num;
9098 @@ -840,7 +845,9 @@
9100 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
9102 - redistribute_delete (&rn->p, rib);
9103 + if (!CHECK_FLAG (rib->flags, ZEBRA_FLAG_MPLS_CHANGED))
9104 + redistribute_delete (&rn->p, rib);
9106 if (! RIB_SYSTEM_ROUTE (rib))
9107 rib_uninstall_kernel (rn, rib);
9108 UNSET_FLAG (rib->flags, ZEBRA_FLAG_SELECTED);
9109 @@ -887,7 +894,9 @@
9111 if (CHECK_FLAG (select->flags, ZEBRA_FLAG_CHANGED))
9113 - redistribute_delete (&rn->p, select);
9114 + if (!CHECK_FLAG (select->flags, ZEBRA_FLAG_MPLS_CHANGED))
9115 + redistribute_delete (&rn->p, select);
9117 if (! RIB_SYSTEM_ROUTE (select))
9118 rib_uninstall_kernel (rn, select);
9120 @@ -896,7 +905,11 @@
9122 if (! RIB_SYSTEM_ROUTE (select))
9123 rib_install_kernel (rn, select);
9124 - redistribute_add (&rn->p, select);
9126 + if (!CHECK_FLAG (select->flags, ZEBRA_FLAG_MPLS_CHANGED))
9127 + redistribute_add (&rn->p, select);
9129 + UNSET_FLAG (select->flags, ZEBRA_FLAG_MPLS_CHANGED);
9131 return;
9133 diff --exclude=.p4config -uNr zebra/zebra/zebra_vty.c zebra-ldp/zebra/zebra_vty.c
9134 --- zebra/zebra/zebra_vty.c 2003-03-29 18:17:29.000000000 -0600
9135 +++ zebra-ldp/zebra/zebra_vty.c 2003-03-10 14:59:35.000000000 -0600
9136 @@ -345,6 +345,10 @@
9137 default:
9138 break;
9141 + if (nexthop->mplsindex)
9142 + vty_out (vty, " MPLS 0x%x", nexthop->mplsindex);
9144 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
9145 vty_out (vty, " inactive");
9147 @@ -356,16 +360,21 @@
9149 case NEXTHOP_TYPE_IPV4:
9150 case NEXTHOP_TYPE_IPV4_IFINDEX:
9151 - vty_out (vty, " via %s)", inet_ntoa (nexthop->rgate.ipv4));
9152 + vty_out (vty, " via %s", inet_ntoa (nexthop->rgate.ipv4));
9153 break;
9154 case NEXTHOP_TYPE_IFINDEX:
9155 case NEXTHOP_TYPE_IFNAME:
9156 - vty_out (vty, " is directly connected, %s)",
9157 + vty_out (vty, " is directly connected, %s",
9158 ifindex2ifname (nexthop->rifindex));
9159 break;
9160 default:
9161 break;
9164 + if (nexthop->rmplsindex)
9165 + vty_out (vty, " MPLS 0x%x", nexthop->rmplsindex);
9167 + vty_out (vty, ")");
9169 vty_out (vty, "%s", VTY_NEWLINE);
9171 @@ -427,6 +436,10 @@
9172 default:
9173 break;
9176 + if (nexthop->mplsindex)
9177 + vty_out (vty, " MPLS 0x%x", nexthop->mplsindex);
9179 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
9180 vty_out (vty, " inactive");
9182 @@ -438,16 +451,21 @@
9184 case NEXTHOP_TYPE_IPV4:
9185 case NEXTHOP_TYPE_IPV4_IFINDEX:
9186 - vty_out (vty, " via %s)", inet_ntoa (nexthop->rgate.ipv4));
9187 + vty_out (vty, " via %s", inet_ntoa (nexthop->rgate.ipv4));
9188 break;
9189 case NEXTHOP_TYPE_IFINDEX:
9190 case NEXTHOP_TYPE_IFNAME:
9191 - vty_out (vty, " is directly connected, %s)",
9192 + vty_out (vty, " is directly connected, %s",
9193 ifindex2ifname (nexthop->rifindex));
9194 break;
9195 default:
9196 break;
9199 + if (nexthop->rmplsindex)
9200 + vty_out (vty, " MPLS 0x%x", nexthop->rmplsindex);
9202 + vty_out (vty, ")");
9205 if (rib->type == ZEBRA_ROUTE_RIP
9206 @@ -1072,6 +1090,10 @@
9207 default:
9208 break;
9211 + if (nexthop->mplsindex)
9212 + vty_out (vty, " MPLS 0x%x", nexthop->mplsindex);
9214 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
9215 vty_out (vty, " inactive");
9217 @@ -1084,7 +1106,7 @@
9218 case NEXTHOP_TYPE_IPV6:
9219 case NEXTHOP_TYPE_IPV6_IFINDEX:
9220 case NEXTHOP_TYPE_IPV6_IFNAME:
9221 - vty_out (vty, " via %s)",
9222 + vty_out (vty, " via %s",
9223 inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
9224 buf, BUFSIZ));
9225 if (nexthop->rifindex)
9226 @@ -1092,12 +1114,17 @@
9227 break;
9228 case NEXTHOP_TYPE_IFINDEX:
9229 case NEXTHOP_TYPE_IFNAME:
9230 - vty_out (vty, " is directly connected, %s)",
9231 + vty_out (vty, " is directly connected, %s",
9232 ifindex2ifname (nexthop->rifindex));
9233 break;
9234 default:
9235 break;
9238 + if (nexthop->rmplsindex)
9239 + vty_out (vty, " MPLS 0x%x", nexthop->rmplsindex);
9241 + vty_out (vty, ")");
9243 vty_out (vty, "%s", VTY_NEWLINE);
9245 diff --exclude=.p4config -uNr zebra/zebra/zserv.c zebra-ldp/zebra/zserv.c
9246 --- zebra/zebra/zserv.c 2003-03-29 18:17:29.000000000 -0600
9247 +++ zebra-ldp/zebra/zserv.c 2003-03-10 14:59:35.000000000 -0600
9248 @@ -35,6 +35,7 @@
9249 #include "zclient.h"
9251 #include "zebra/zserv.h"
9252 +#include "zebra/router-id.h"
9253 #include "zebra/redistribute.h"
9254 #include "zebra/debug.h"
9255 #include "zebra/ipforward.h"
9256 @@ -73,7 +74,11 @@
9257 "ZEBRA_IPV4_NEXTHOP_LOOKUP",
9258 "ZEBRA_IPV6_NEXTHOP_LOOKUP",
9259 "ZEBRA_IPV4_IMPORT_LOOKUP",
9260 - "ZEBRA_IPV6_IMPORT_LOOKUP"
9261 + "ZEBRA_IPV6_IMPORT_LOOKUP",
9262 + "ZEBRA_ROUTER_ID_ADD",
9263 + "ZEBRA_ROUTER_ID_DELETE",
9264 + "ZEBRA_ROUTER_ID_UPDATE",
9265 + "ZEBRA_IPV4_SET_MPLSINDEX"
9268 struct zebra_message_queue
9269 @@ -983,6 +988,38 @@
9270 return 0;
9273 +/* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */
9274 +int
9275 +zsend_router_id_update (struct zserv *client, struct prefix *p)
9277 + struct stream *s;
9278 + int blen;
9280 + /* Check this client need interface information. */
9281 + if (!client->ridinfo)
9282 + return -1;
9284 + s = client->obuf;
9285 + stream_reset (s);
9287 + /* Place holder for size. */
9288 + stream_putw (s, 0);
9290 + /* Message type. */
9291 + stream_putc (s, ZEBRA_ROUTER_ID_UPDATE);
9293 + /* Prefix information. */
9294 + stream_putc (s, p->family);
9295 + blen = prefix_blen (p);
9296 + stream_put (s, &p->u.prefix, blen);
9297 + stream_putc (s, p->prefixlen);
9299 + /* Write packet size. */
9300 + stream_putw_at (s, 0, stream_get_endp (s));
9302 + return writen (client->sock, s->data, stream_get_endp (s));
9305 /* Register zebra server interface information. Send current all
9306 interface and address information. */
9307 void
9308 @@ -1022,6 +1059,71 @@
9309 client->ifinfo = 0;
9312 +void
9313 +zread_ipv4_set_mplsindex (struct zserv *client, u_short length)
9315 + struct prefix_ipv4 p;
9316 + struct in_addr gate;
9317 + struct stream *s;
9318 + unsigned int mplsindex;
9319 + unsigned int ifindex;
9320 + struct route_node *rn;
9321 + struct rib *rib;
9322 + struct nexthop *nexthop;
9323 + struct route_table *table;
9325 + /* Get input stream. */
9326 + s = client->ibuf;
9328 + /* IPv4 prefix. */
9329 + memset (&p, 0, sizeof (struct prefix_ipv4));
9330 + p.family = AF_INET;
9331 + p.prefixlen = stream_getc (s);
9332 + stream_get (&p.prefix, s, PSIZE (p.prefixlen));
9334 + /* Nexthop info */
9335 + gate.s_addr = stream_get_ipv4 (s);
9336 + ifindex = stream_getl (s);
9338 + /* the MPLS index */
9339 + mplsindex = stream_getl (s);
9341 + apply_mask_ipv4 (&p);
9343 + /* Lookup table. */
9344 + table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
9345 + if (! table)
9346 + return;
9348 + rn = route_node_get (table, (struct prefix *)&p);
9349 + if (!rn)
9350 + return;
9352 + for (rib = rn->info; rib; rib = rib->next)
9354 + if (!CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
9356 + continue;
9359 + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
9361 + if (!CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
9363 + continue;
9365 + if (nexthop->ifindex == ifindex
9366 + && nexthop->gate.ipv4.s_addr == gate.s_addr)
9368 + SET_FLAG (rib->flags, ZEBRA_FLAG_MPLS_CHANGED);
9369 + nexthop->mplsindex = mplsindex;
9374 + rib_process (rn, NULL);
9377 /* This function support multiple nexthop. */
9378 void
9379 zread_ipv4_add (struct zserv *client, u_short length)
9380 @@ -1113,7 +1215,7 @@
9381 u_char nexthop_num;
9382 u_char nexthop_type;
9383 u_char ifname_len;
9386 s = client->ibuf;
9387 ifindex = 0;
9388 nexthop.s_addr = 0;
9389 @@ -1207,7 +1309,7 @@
9390 struct in6_addr nexthop;
9391 unsigned long ifindex;
9392 struct prefix_ipv6 p;
9395 s = client->ibuf;
9396 ifindex = 0;
9397 memset (&nexthop, 0, sizeof (struct in6_addr));
9398 @@ -1271,7 +1373,7 @@
9399 struct in6_addr nexthop;
9400 unsigned long ifindex;
9401 struct prefix_ipv6 p;
9404 s = client->ibuf;
9405 ifindex = 0;
9406 memset (&nexthop, 0, sizeof (struct in6_addr));
9407 @@ -1379,6 +1481,27 @@
9409 #endif /* HAVE_IPV6 */
9411 +/* Register zebra server router-id information. Send current router-id */
9412 +void
9413 +zread_router_id_add (struct zserv *client, u_short length)
9415 + struct prefix p;
9417 + /* Router-id information is needed. */
9418 + client->ridinfo = 1;
9420 + router_id_get (&p);
9422 + zsend_router_id_update (client,&p);
9425 +/* Unregister zebra server router-id information. */
9426 +void
9427 +zread_router_id_delete (struct zserv *client, u_short length)
9429 + client->ridinfo = 0;
9432 /* Close zebra client. */
9433 void
9434 zebra_client_close (struct zserv *client)
9435 @@ -1490,6 +1613,15 @@
9437 switch (command)
9439 + case ZEBRA_IPV4_SET_MPLSINDEX:
9440 + zread_ipv4_set_mplsindex (client, length);
9441 + break;
9442 + case ZEBRA_ROUTER_ID_ADD:
9443 + zread_router_id_add (client, length);
9444 + break;
9445 + case ZEBRA_ROUTER_ID_DELETE:
9446 + zread_router_id_delete (client, length);
9447 + break;
9448 case ZEBRA_INTERFACE_ADD:
9449 zread_interface_add (client, length);
9450 break;
9451 diff --exclude=.p4config -uNr zebra/zebra/zserv.h zebra-ldp/zebra/zserv.h
9452 --- zebra/zebra/zserv.h 2003-03-29 18:17:29.000000000 -0600
9453 +++ zebra-ldp/zebra/zserv.h 2003-03-10 14:59:35.000000000 -0600
9454 @@ -56,6 +56,9 @@
9456 /* Interface information. */
9457 u_char ifinfo;
9459 + /* Router-id information. */
9460 + u_char ridinfo;
9463 /* Count prefix size from mask length */
9464 @@ -126,6 +129,9 @@
9466 #endif /* HAVE_IPV6 */
9468 +int
9469 +zsend_router_id_update(struct zserv *, struct prefix *);
9471 extern pid_t pid;
9472 extern pid_t old_pid;