2 * Copyright (C) 2016 by Open Source Routing.
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 static int interface_config_write(struct vty
*);
36 static void ldp_af_iface_config_write(struct vty
*, int);
37 static void ldp_af_config_write(struct vty
*, int, struct ldpd_conf
*,
38 struct ldpd_af_conf
*);
39 static void ldp_l2vpn_pw_config_write(struct vty
*, struct l2vpn_pw
*);
40 static int ldp_vty_get_af(struct vty
*);
41 static int ldp_iface_is_configured(struct ldpd_conf
*, const char *);
42 static int ldp_vty_nbr_session_holdtime(struct vty
*, struct vty_arg
*[]);
43 static int ldp_vty_af_session_holdtime(struct vty
*, struct vty_arg
*[]);
45 static struct cmd_node interface_node
=
52 struct cmd_node ldp_node
=
59 struct cmd_node ldp_ipv4_node
=
62 "%s(config-ldp-af)# ",
66 struct cmd_node ldp_ipv6_node
=
69 "%s(config-ldp-af)# ",
73 struct cmd_node ldp_ipv4_iface_node
=
76 "%s(config-ldp-af-if)# ",
80 struct cmd_node ldp_ipv6_iface_node
=
83 "%s(config-ldp-af-if)# ",
87 struct cmd_node ldp_l2vpn_node
=
94 struct cmd_node ldp_pseudowire_node
=
97 "%s(config-l2vpn-pw)# ",
102 ldp_get_address(const char *str
, int *af
, union ldpd_addr
*addr
)
104 memset(addr
, 0, sizeof(*addr
));
106 if (inet_pton(AF_INET
, str
, &addr
->v4
) == 1) {
111 if (inet_pton(AF_INET6
, str
, &addr
->v6
) == 1) {
120 interface_config_write(struct vty
*vty
)
122 struct listnode
*node
;
123 struct interface
*ifp
;
126 for (ALL_LIST_ELEMENTS_RO(vrf_iflist (VRF_DEFAULT
), node
, ifp
)) {
127 vty_out(vty
, "!%s", VTY_NEWLINE
);
128 vty_out(vty
, "interface %s%s", ifp
->name
, VTY_NEWLINE
);
130 vty_out(vty
, " description %s%s", ifp
->desc
,
140 ldp_af_iface_config_write(struct vty
*vty
, int af
)
145 RB_FOREACH(iface
, iface_head
, &ldpd_conf
->iface_tree
) {
146 ia
= iface_af_get(iface
, af
);
150 vty_out(vty
, " !%s", VTY_NEWLINE
);
151 vty_out(vty
, " interface %s%s", iface
->name
, VTY_NEWLINE
);
153 if (ia
->hello_holdtime
!= LINK_DFLT_HOLDTIME
&&
154 ia
->hello_holdtime
!= 0)
155 vty_out(vty
, " discovery hello holdtime %u%s",
156 ia
->hello_holdtime
, VTY_NEWLINE
);
157 if (ia
->hello_interval
!= DEFAULT_HELLO_INTERVAL
&&
158 ia
->hello_interval
!= 0)
159 vty_out(vty
, " discovery hello interval %u%s",
160 ia
->hello_interval
, VTY_NEWLINE
);
165 ldp_af_config_write(struct vty
*vty
, int af
, struct ldpd_conf
*conf
,
166 struct ldpd_af_conf
*af_conf
)
170 if (!(af_conf
->flags
& F_LDPD_AF_ENABLED
))
173 vty_out(vty
, " !%s", VTY_NEWLINE
);
174 vty_out(vty
, " address-family %s%s", af_name(af
), VTY_NEWLINE
);
176 if (af_conf
->lhello_holdtime
!= LINK_DFLT_HOLDTIME
&&
177 af_conf
->lhello_holdtime
!= 0 )
178 vty_out(vty
, " discovery hello holdtime %u%s",
179 af_conf
->lhello_holdtime
, VTY_NEWLINE
);
180 if (af_conf
->lhello_interval
!= DEFAULT_HELLO_INTERVAL
&&
181 af_conf
->lhello_interval
!= 0)
182 vty_out(vty
, " discovery hello interval %u%s",
183 af_conf
->lhello_interval
, VTY_NEWLINE
);
185 if (af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) {
186 vty_out(vty
, " discovery targeted-hello accept");
187 if (af_conf
->acl_thello_accept_from
[0] != '\0')
188 vty_out(vty
, " from %s",
189 af_conf
->acl_thello_accept_from
);
190 vty_out(vty
, "%s", VTY_NEWLINE
);
193 if (af_conf
->thello_holdtime
!= TARGETED_DFLT_HOLDTIME
&&
194 af_conf
->thello_holdtime
!= 0)
195 vty_out(vty
, " discovery targeted-hello holdtime %u%s",
196 af_conf
->thello_holdtime
, VTY_NEWLINE
);
197 if (af_conf
->thello_interval
!= DEFAULT_HELLO_INTERVAL
&&
198 af_conf
->thello_interval
!= 0)
199 vty_out(vty
, " discovery targeted-hello interval %u%s",
200 af_conf
->thello_interval
, VTY_NEWLINE
);
202 if (ldp_addrisset(af
, &af_conf
->trans_addr
))
203 vty_out(vty
, " discovery transport-address %s%s",
204 log_addr(af
, &af_conf
->trans_addr
), VTY_NEWLINE
);
206 vty_out(vty
, " ! Incomplete config, specify a discovery "
207 "transport-address%s", VTY_NEWLINE
);
209 if ((af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
) ||
210 af_conf
->acl_label_allocate_for
[0] != '\0') {
211 vty_out(vty
, " label local allocate");
212 if (af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
)
213 vty_out(vty
, " host-routes");
215 vty_out(vty
, " for %s",
216 af_conf
->acl_label_allocate_for
);
217 vty_out(vty
, "%s", VTY_NEWLINE
);
220 if (af_conf
->acl_label_advertise_for
[0] != '\0' ||
221 af_conf
->acl_label_advertise_to
[0] != '\0') {
222 vty_out(vty
, " label local advertise");
223 if (af_conf
->acl_label_advertise_to
[0] != '\0')
224 vty_out(vty
, " to %s",
225 af_conf
->acl_label_advertise_to
);
226 if (af_conf
->acl_label_advertise_for
[0] != '\0')
227 vty_out(vty
, " for %s",
228 af_conf
->acl_label_advertise_for
);
229 vty_out(vty
, "%s", VTY_NEWLINE
);
232 if (af_conf
->flags
& F_LDPD_AF_EXPNULL
) {
233 vty_out(vty
, " label local advertise explicit-null");
234 if (af_conf
->acl_label_expnull_for
[0] != '\0')
235 vty_out(vty
, " for %s",
236 af_conf
->acl_label_expnull_for
);
237 vty_out(vty
, "%s", VTY_NEWLINE
);
240 if (af_conf
->acl_label_accept_for
[0] != '\0' ||
241 af_conf
->acl_label_accept_from
[0] != '\0') {
242 vty_out(vty
, " label remote accept");
243 if (af_conf
->acl_label_accept_from
[0] != '\0')
244 vty_out(vty
, " from %s",
245 af_conf
->acl_label_accept_from
);
246 if (af_conf
->acl_label_accept_for
[0] != '\0')
247 vty_out(vty
, " for %s",
248 af_conf
->acl_label_accept_for
);
249 vty_out(vty
, "%s", VTY_NEWLINE
);
252 if (af_conf
->flags
& F_LDPD_AF_NO_GTSM
)
253 vty_out(vty
, " ttl-security disable%s", VTY_NEWLINE
);
255 if (af_conf
->keepalive
!= DEFAULT_KEEPALIVE
)
256 vty_out(vty
, " session holdtime %u%s", af_conf
->keepalive
,
259 RB_FOREACH(tnbr
, tnbr_head
, &ldpd_conf
->tnbr_tree
) {
260 if (tnbr
->af
== af
) {
261 vty_out(vty
, " !%s", VTY_NEWLINE
);
262 vty_out(vty
, " neighbor %s targeted%s",
263 log_addr(tnbr
->af
, &tnbr
->addr
), VTY_NEWLINE
);
267 ldp_af_iface_config_write(vty
, af
);
269 vty_out(vty
, " !%s", VTY_NEWLINE
);
273 ldp_config_write(struct vty
*vty
)
275 struct nbr_params
*nbrp
;
277 if (!(ldpd_conf
->flags
& F_LDPD_ENABLED
))
280 vty_out(vty
, "mpls ldp%s", VTY_NEWLINE
);
282 if (ldpd_conf
->rtr_id
.s_addr
!= 0)
283 vty_out(vty
, " router-id %s%s",
284 inet_ntoa(ldpd_conf
->rtr_id
), VTY_NEWLINE
);
286 if (ldpd_conf
->lhello_holdtime
!= LINK_DFLT_HOLDTIME
&&
287 ldpd_conf
->lhello_holdtime
!= 0)
288 vty_out(vty
, " discovery hello holdtime %u%s",
289 ldpd_conf
->lhello_holdtime
, VTY_NEWLINE
);
290 if (ldpd_conf
->lhello_interval
!= DEFAULT_HELLO_INTERVAL
&&
291 ldpd_conf
->lhello_interval
!= 0)
292 vty_out(vty
, " discovery hello interval %u%s",
293 ldpd_conf
->lhello_interval
, VTY_NEWLINE
);
295 if (ldpd_conf
->thello_holdtime
!= TARGETED_DFLT_HOLDTIME
&&
296 ldpd_conf
->thello_holdtime
!= 0)
297 vty_out(vty
, " discovery targeted-hello holdtime %u%s",
298 ldpd_conf
->thello_holdtime
, VTY_NEWLINE
);
299 if (ldpd_conf
->thello_interval
!= DEFAULT_HELLO_INTERVAL
&&
300 ldpd_conf
->thello_interval
!= 0)
301 vty_out(vty
, " discovery targeted-hello interval %u%s",
302 ldpd_conf
->thello_interval
, VTY_NEWLINE
);
304 if (ldpd_conf
->trans_pref
== DUAL_STACK_LDPOV4
)
305 vty_out(vty
, " dual-stack transport-connection prefer ipv4%s",
308 if (ldpd_conf
->flags
& F_LDPD_DS_CISCO_INTEROP
)
309 vty_out(vty
, " dual-stack cisco-interop%s", VTY_NEWLINE
);
311 RB_FOREACH(nbrp
, nbrp_head
, &ldpd_conf
->nbrp_tree
) {
312 if (nbrp
->flags
& F_NBRP_KEEPALIVE
)
313 vty_out(vty
, " neighbor %s session holdtime %u%s",
314 inet_ntoa(nbrp
->lsr_id
), nbrp
->keepalive
,
317 if (nbrp
->flags
& F_NBRP_GTSM
) {
318 if (nbrp
->gtsm_enabled
)
319 vty_out(vty
, " neighbor %s ttl-security hops "
320 "%u%s", inet_ntoa(nbrp
->lsr_id
),
321 nbrp
->gtsm_hops
, VTY_NEWLINE
);
323 vty_out(vty
, " neighbor %s ttl-security "
324 "disable%s", inet_ntoa(nbrp
->lsr_id
),
328 if (nbrp
->auth
.method
== AUTH_MD5SIG
)
329 vty_out(vty
, " neighbor %s password %s%s",
330 inet_ntoa(nbrp
->lsr_id
), nbrp
->auth
.md5key
,
334 ldp_af_config_write(vty
, AF_INET
, ldpd_conf
, &ldpd_conf
->ipv4
);
335 ldp_af_config_write(vty
, AF_INET6
, ldpd_conf
, &ldpd_conf
->ipv6
);
336 vty_out(vty
, " !%s", VTY_NEWLINE
);
337 vty_out(vty
, "!%s", VTY_NEWLINE
);
343 ldp_l2vpn_pw_config_write(struct vty
*vty
, struct l2vpn_pw
*pw
)
345 int missing_lsrid
= 0;
346 int missing_pwid
= 0;
348 vty_out(vty
, " !%s", VTY_NEWLINE
);
349 vty_out(vty
, " member pseudowire %s%s", pw
->ifname
, VTY_NEWLINE
);
351 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
)
352 vty_out(vty
, " neighbor lsr-id %s%s", inet_ntoa(pw
->lsr_id
),
357 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
358 vty_out(vty
, " neighbor address %s%s", log_addr(pw
->af
,
359 &pw
->addr
), VTY_NEWLINE
);
362 vty_out(vty
, " pw-id %u%s", pw
->pwid
, VTY_NEWLINE
);
366 if (!(pw
->flags
& F_PW_CWORD_CONF
))
367 vty_out(vty
, " control-word exclude%s", VTY_NEWLINE
);
369 if (!(pw
->flags
& F_PW_STATUSTLV_CONF
))
370 vty_out(vty
, " pw-status disable%s", VTY_NEWLINE
);
373 vty_out(vty
, " ! Incomplete config, specify a neighbor "
374 "lsr-id%s", VTY_NEWLINE
);
376 vty_out(vty
, " ! Incomplete config, specify a pw-id%s",
381 ldp_l2vpn_config_write(struct vty
*vty
)
384 struct l2vpn_if
*lif
;
387 RB_FOREACH(l2vpn
, l2vpn_head
, &ldpd_conf
->l2vpn_tree
) {
388 vty_out(vty
, "l2vpn %s type vpls%s", l2vpn
->name
, VTY_NEWLINE
);
390 if (l2vpn
->pw_type
!= DEFAULT_PW_TYPE
)
391 vty_out(vty
, " vc type ethernet-tagged%s", VTY_NEWLINE
);
393 if (l2vpn
->mtu
!= DEFAULT_L2VPN_MTU
)
394 vty_out(vty
, " mtu %u%s", l2vpn
->mtu
, VTY_NEWLINE
);
396 if (l2vpn
->br_ifname
[0] != '\0')
397 vty_out(vty
, " bridge %s%s", l2vpn
->br_ifname
,
400 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
401 vty_out(vty
, " member interface %s%s", lif
->ifname
,
404 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
405 ldp_l2vpn_pw_config_write(vty
, pw
);
406 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
407 ldp_l2vpn_pw_config_write(vty
, pw
);
409 vty_out(vty
, " !%s", VTY_NEWLINE
);
410 vty_out(vty
, "!%s", VTY_NEWLINE
);
417 ldp_vty_get_af(struct vty
*vty
)
421 case LDP_IPV4_IFACE_NODE
:
424 case LDP_IPV6_IFACE_NODE
:
427 fatalx("ldp_vty_get_af: unexpected node");
432 ldp_iface_is_configured(struct ldpd_conf
*xconf
, const char *ifname
)
436 if (if_lookup_name(xconf
, ifname
))
439 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
440 if (l2vpn_if_find_name(l2vpn
, ifname
))
442 if (l2vpn_pw_find_name(l2vpn
, ifname
))
450 ldp_vty_mpls_ldp(struct vty
*vty
, struct vty_arg
*args
[])
452 struct ldpd_conf
*vty_conf
;
455 vty_conf
= ldp_dup_config(ldpd_conf
);
457 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
460 vty_conf
->flags
&= ~F_LDPD_ENABLED
;
462 vty
->node
= LDP_NODE
;
463 vty_conf
->flags
|= F_LDPD_ENABLED
;
466 ldp_reload(vty_conf
);
468 return (CMD_SUCCESS
);
472 ldp_vty_address_family(struct vty
*vty
, struct vty_arg
*args
[])
474 struct ldpd_conf
*vty_conf
;
475 struct ldpd_af_conf
*af_conf
;
480 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
481 af_str
= vty_get_arg_value(args
, "address-family");
483 vty_conf
= ldp_dup_config(ldpd_conf
);
484 if (strcmp(af_str
, "ipv4") == 0) {
486 af_conf
= &vty_conf
->ipv4
;
487 } else if (strcmp(af_str
, "ipv6") == 0) {
489 af_conf
= &vty_conf
->ipv6
;
491 ldp_clear_config(vty_conf
);
492 return (CMD_WARNING
);
496 af_conf
->flags
&= ~F_LDPD_AF_ENABLED
;
497 ldp_reload(vty_conf
);
498 return (CMD_SUCCESS
);
503 vty
->node
= LDP_IPV4_NODE
;
506 vty
->node
= LDP_IPV6_NODE
;
509 fatalx("ldp_vty_address_family: unknown af");
511 af_conf
->flags
|= F_LDPD_AF_ENABLED
;
513 ldp_reload(vty_conf
);
515 return (CMD_SUCCESS
);
519 ldp_vty_disc_holdtime(struct vty
*vty
, struct vty_arg
*args
[])
521 struct ldpd_conf
*vty_conf
;
522 struct ldpd_af_conf
*af_conf
;
528 enum hello_type hello_type
;
529 const char *seconds_str
;
530 const char *hello_type_str
;
533 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
534 seconds_str
= vty_get_arg_value(args
, "seconds");
535 hello_type_str
= vty_get_arg_value(args
, "hello_type");
537 secs
= strtol(seconds_str
, &ep
, 10);
538 if (*ep
!= '\0' || secs
< MIN_HOLDTIME
|| secs
> MAX_HOLDTIME
) {
539 vty_out(vty
, "%% Invalid holdtime%s", VTY_NEWLINE
);
540 return (CMD_WARNING
);
543 if (hello_type_str
[0] == 'h')
544 hello_type
= HELLO_LINK
;
546 hello_type
= HELLO_TARGETED
;
550 vty_conf
= ldp_dup_config(ldpd_conf
);
552 switch (hello_type
) {
554 vty_conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
557 vty_conf
->thello_holdtime
=
558 TARGETED_DFLT_HOLDTIME
;
562 switch (hello_type
) {
564 vty_conf
->lhello_holdtime
= secs
;
567 vty_conf
->thello_holdtime
= secs
;
571 ldp_reload(vty_conf
);
575 vty_conf
= ldp_dup_config(ldpd_conf
);
576 af
= ldp_vty_get_af(vty
);
577 af_conf
= ldp_af_conf_get(vty_conf
, af
);
580 switch (hello_type
) {
582 af_conf
->lhello_holdtime
= 0;
585 af_conf
->thello_holdtime
= 0;
589 switch (hello_type
) {
591 af_conf
->lhello_holdtime
= secs
;
594 af_conf
->thello_holdtime
= secs
;
598 ldp_reload(vty_conf
);
600 case LDP_IPV4_IFACE_NODE
:
601 case LDP_IPV6_IFACE_NODE
:
602 af
= ldp_vty_get_af(vty
);
603 iface
= VTY_GET_CONTEXT(iface
);
604 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&iface
);
606 ia
= iface_af_get(iface
, af
);
608 ia
->hello_holdtime
= 0;
610 ia
->hello_holdtime
= secs
;
611 ldp_reload_ref(vty_conf
, (void **)&iface
);
614 fatalx("ldp_vty_disc_holdtime: unexpected node");
617 return (CMD_SUCCESS
);
621 ldp_vty_disc_interval(struct vty
*vty
, struct vty_arg
*args
[])
623 struct ldpd_conf
*vty_conf
;
624 struct ldpd_af_conf
*af_conf
;
630 enum hello_type hello_type
;
631 const char *seconds_str
;
632 const char *hello_type_str
;
635 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
636 seconds_str
= vty_get_arg_value(args
, "seconds");
637 hello_type_str
= vty_get_arg_value(args
, "hello_type");
639 secs
= strtol(seconds_str
, &ep
, 10);
640 if (*ep
!= '\0' || secs
< MIN_HELLO_INTERVAL
||
641 secs
> MAX_HELLO_INTERVAL
) {
642 vty_out(vty
, "%% Invalid interval%s", VTY_NEWLINE
);
643 return (CMD_WARNING
);
646 if (hello_type_str
[0] == 'h')
647 hello_type
= HELLO_LINK
;
649 hello_type
= HELLO_TARGETED
;
653 vty_conf
= ldp_dup_config(ldpd_conf
);
655 switch (hello_type
) {
657 vty_conf
->lhello_interval
= LINK_DFLT_HOLDTIME
;
660 vty_conf
->thello_interval
=
661 TARGETED_DFLT_HOLDTIME
;
665 switch (hello_type
) {
667 vty_conf
->lhello_interval
= secs
;
670 vty_conf
->thello_interval
= secs
;
674 ldp_reload(vty_conf
);
678 vty_conf
= ldp_dup_config(ldpd_conf
);
679 af
= ldp_vty_get_af(vty
);
680 af_conf
= ldp_af_conf_get(vty_conf
, af
);
683 switch (hello_type
) {
685 af_conf
->lhello_interval
= 0;
688 af_conf
->thello_interval
= 0;
692 switch (hello_type
) {
694 af_conf
->lhello_interval
= secs
;
697 af_conf
->thello_interval
= secs
;
701 ldp_reload(vty_conf
);
703 case LDP_IPV4_IFACE_NODE
:
704 case LDP_IPV6_IFACE_NODE
:
705 af
= ldp_vty_get_af(vty
);
706 iface
= VTY_GET_CONTEXT(iface
);
707 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&iface
);
709 ia
= iface_af_get(iface
, af
);
711 ia
->hello_interval
= 0;
713 ia
->hello_interval
= secs
;
714 ldp_reload_ref(vty_conf
, (void **)&iface
);
717 fatalx("ldp_vty_disc_interval: unexpected node");
720 return (CMD_SUCCESS
);
724 ldp_vty_targeted_hello_accept(struct vty
*vty
, struct vty_arg
*args
[])
726 struct ldpd_conf
*vty_conf
;
727 struct ldpd_af_conf
*af_conf
;
729 const char *acl_from_str
;
732 vty_conf
= ldp_dup_config(ldpd_conf
);
734 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
735 acl_from_str
= vty_get_arg_value(args
, "from_acl");
737 af
= ldp_vty_get_af(vty
);
738 af_conf
= ldp_af_conf_get(vty_conf
, af
);
741 af_conf
->flags
&= ~F_LDPD_AF_THELLO_ACCEPT
;
742 af_conf
->acl_thello_accept_from
[0] = '\0';
744 af_conf
->flags
|= F_LDPD_AF_THELLO_ACCEPT
;
746 strlcpy(af_conf
->acl_thello_accept_from
, acl_from_str
,
747 sizeof(af_conf
->acl_thello_accept_from
));
749 af_conf
->acl_thello_accept_from
[0] = '\0';
752 ldp_reload(vty_conf
);
754 return (CMD_SUCCESS
);
758 ldp_vty_nbr_session_holdtime(struct vty
*vty
, struct vty_arg
*args
[])
760 struct ldpd_conf
*vty_conf
;
763 struct in_addr lsr_id
;
764 struct nbr_params
*nbrp
;
765 const char *seconds_str
;
766 const char *lsr_id_str
;
769 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
770 seconds_str
= vty_get_arg_value(args
, "seconds");
771 lsr_id_str
= vty_get_arg_value(args
, "lsr_id");
773 if (inet_pton(AF_INET
, lsr_id_str
, &lsr_id
) != 1 ||
774 bad_addr_v4(lsr_id
)) {
775 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
776 return (CMD_WARNING
);
779 vty_conf
= ldp_dup_config(ldpd_conf
);
780 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
782 secs
= strtol(seconds_str
, &ep
, 10);
783 if (*ep
!= '\0' || secs
< MIN_KEEPALIVE
|| secs
> MAX_KEEPALIVE
) {
784 vty_out(vty
, "%% Invalid holdtime%s", VTY_NEWLINE
);
793 nbrp
->flags
&= ~F_NBRP_KEEPALIVE
;
796 nbrp
= nbr_params_new(lsr_id
);
797 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
798 } else if (nbrp
->keepalive
== secs
)
801 nbrp
->keepalive
= secs
;
802 nbrp
->flags
|= F_NBRP_KEEPALIVE
;
805 ldp_reload(vty_conf
);
807 return (CMD_SUCCESS
);
810 ldp_clear_config(vty_conf
);
811 return (CMD_SUCCESS
);
815 ldp_vty_af_session_holdtime(struct vty
*vty
, struct vty_arg
*args
[])
817 struct ldpd_conf
*vty_conf
;
818 struct ldpd_af_conf
*af_conf
;
822 const char *seconds_str
;
825 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
826 seconds_str
= vty_get_arg_value(args
, "seconds");
828 secs
= strtol(seconds_str
, &ep
, 10);
829 if (*ep
!= '\0' || secs
< MIN_KEEPALIVE
|| secs
> MAX_KEEPALIVE
) {
830 vty_out(vty
, "%% Invalid holdtime%s", VTY_NEWLINE
);
831 return (CMD_SUCCESS
);
834 vty_conf
= ldp_dup_config(ldpd_conf
);
835 af
= ldp_vty_get_af(vty
);
836 af_conf
= ldp_af_conf_get(vty_conf
, af
);
839 af_conf
->keepalive
= DEFAULT_KEEPALIVE
;
841 af_conf
->keepalive
= secs
;
843 ldp_reload(vty_conf
);
845 return (CMD_SUCCESS
);
849 ldp_vty_session_holdtime(struct vty
*vty
, struct vty_arg
*args
[])
853 return (ldp_vty_nbr_session_holdtime(vty
, args
));
856 return (ldp_vty_af_session_holdtime(vty
, args
));
858 fatalx("ldp_vty_session_holdtime: unexpected node");
863 ldp_vty_interface(struct vty
*vty
, struct vty_arg
*args
[])
865 struct ldpd_conf
*vty_conf
;
869 struct interface
*ifp
;
874 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
875 ifname
= vty_get_arg_value(args
, "ifname");
877 vty_conf
= ldp_dup_config(ldpd_conf
);
878 af
= ldp_vty_get_af(vty
);
879 iface
= if_lookup_name(vty_conf
, ifname
);
885 ia
= iface_af_get(iface
, af
);
886 if (ia
->enabled
== 0)
890 ia
->hello_holdtime
= 0;
891 ia
->hello_interval
= 0;
892 ldp_reload(vty_conf
);
893 return (CMD_SUCCESS
);
897 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
898 vty_out(vty
, "%% Interface is already in use%s",
903 ifp
= if_lookup_by_name(ifname
, VRF_DEFAULT
);
904 memset(&kif
, 0, sizeof(kif
));
905 strlcpy(kif
.ifname
, ifname
, sizeof(kif
.ifname
));
907 kif
.ifindex
= ifp
->ifindex
;
908 kif
.flags
= ifp
->flags
;
910 iface
= if_new(&kif
);
912 ia
= iface_af_get(iface
, af
);
914 RB_INSERT(iface_head
, &vty_conf
->iface_tree
, iface
);
915 ldp_reload_ref(vty_conf
, (void **)&iface
);
917 memset(&kif
, 0, sizeof(kif
));
918 strlcpy(kif
.ifname
, ifname
, sizeof(kif
.ifname
));
920 ia
= iface_af_get(iface
, af
);
923 ldp_reload_ref(vty_conf
, (void **)&iface
);
925 ldp_clear_config(vty_conf
);
930 VTY_PUSH_CONTEXT(LDP_IPV4_IFACE_NODE
, iface
);
933 VTY_PUSH_CONTEXT(LDP_IPV6_IFACE_NODE
, iface
);
939 return (CMD_SUCCESS
);
942 ldp_clear_config(vty_conf
);
943 return (CMD_SUCCESS
);
947 ldp_vty_trans_addr(struct vty
*vty
, struct vty_arg
*args
[])
949 struct ldpd_conf
*vty_conf
;
950 struct ldpd_af_conf
*af_conf
;
952 const char *addr_str
;
955 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
956 addr_str
= vty_get_arg_value(args
, "addr");
958 vty_conf
= ldp_dup_config(ldpd_conf
);
959 af
= ldp_vty_get_af(vty
);
960 af_conf
= ldp_af_conf_get(vty_conf
, af
);
963 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
965 if (inet_pton(af
, addr_str
, &af_conf
->trans_addr
) != 1 ||
966 bad_addr(af
, &af_conf
->trans_addr
)) {
967 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
972 ldp_reload(vty_conf
);
974 return (CMD_SUCCESS
);
977 ldp_clear_config(vty_conf
);
978 return (CMD_SUCCESS
);
982 ldp_vty_neighbor_targeted(struct vty
*vty
, struct vty_arg
*args
[])
984 struct ldpd_conf
*vty_conf
;
986 union ldpd_addr addr
;
988 const char *addr_str
;
991 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
992 addr_str
= vty_get_arg_value(args
, "addr");
994 af
= ldp_vty_get_af(vty
);
996 if (inet_pton(af
, addr_str
, &addr
) != 1 ||
997 bad_addr(af
, &addr
)) {
998 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
999 return (CMD_WARNING
);
1001 if (af
== AF_INET6
&& IN6_IS_SCOPE_EMBED(&addr
.v6
)) {
1002 vty_out(vty
, "%% Address can not be link-local%s", VTY_NEWLINE
);
1003 return (CMD_WARNING
);
1006 vty_conf
= ldp_dup_config(ldpd_conf
);
1007 tnbr
= tnbr_find(vty_conf
, af
, &addr
);
1013 RB_REMOVE(tnbr_head
, &vty_conf
->tnbr_tree
, tnbr
);
1015 ldp_reload(vty_conf
);
1016 return (CMD_SUCCESS
);
1022 tnbr
= tnbr_new(af
, &addr
);
1023 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1024 RB_INSERT(tnbr_head
, &vty_conf
->tnbr_tree
, tnbr
);
1026 ldp_reload(vty_conf
);
1028 return (CMD_SUCCESS
);
1031 ldp_clear_config(vty_conf
);
1032 return (CMD_SUCCESS
);
1036 ldp_vty_label_advertise(struct vty
*vty
, struct vty_arg
*args
[])
1038 struct ldpd_conf
*vty_conf
;
1039 struct ldpd_af_conf
*af_conf
;
1041 const char *acl_to_str
;
1042 const char *acl_for_str
;
1045 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1046 acl_to_str
= vty_get_arg_value(args
, "to_acl");
1047 acl_for_str
= vty_get_arg_value(args
, "for_acl");
1049 vty_conf
= ldp_dup_config(ldpd_conf
);
1050 af
= ldp_vty_get_af(vty
);
1051 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1054 af_conf
->acl_label_advertise_to
[0] = '\0';
1055 af_conf
->acl_label_advertise_for
[0] = '\0';
1058 strlcpy(af_conf
->acl_label_advertise_to
, acl_to_str
,
1059 sizeof(af_conf
->acl_label_advertise_to
));
1061 af_conf
->acl_label_advertise_to
[0] = '\0';
1063 strlcpy(af_conf
->acl_label_advertise_for
, acl_for_str
,
1064 sizeof(af_conf
->acl_label_advertise_for
));
1066 af_conf
->acl_label_advertise_for
[0] = '\0';
1069 ldp_reload(vty_conf
);
1071 return (CMD_SUCCESS
);
1075 ldp_vty_label_allocate(struct vty
*vty
, struct vty_arg
*args
[])
1077 struct ldpd_conf
*vty_conf
;
1078 struct ldpd_af_conf
*af_conf
;
1080 const char *acl_for_str
;
1081 const char *host_routes_str
;
1084 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1085 acl_for_str
= vty_get_arg_value(args
, "for_acl");
1086 host_routes_str
= vty_get_arg_value(args
, "host-routes");
1088 vty_conf
= ldp_dup_config(ldpd_conf
);
1089 af
= ldp_vty_get_af(vty
);
1090 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1092 af_conf
->flags
&= ~F_LDPD_AF_ALLOCHOSTONLY
;
1093 af_conf
->acl_label_allocate_for
[0] = '\0';
1095 if (host_routes_str
)
1096 af_conf
->flags
|= F_LDPD_AF_ALLOCHOSTONLY
;
1098 strlcpy(af_conf
->acl_label_allocate_for
, acl_for_str
,
1099 sizeof(af_conf
->acl_label_allocate_for
));
1102 ldp_reload(vty_conf
);
1104 return (CMD_SUCCESS
);
1108 ldp_vty_label_expnull(struct vty
*vty
, struct vty_arg
*args
[])
1110 struct ldpd_conf
*vty_conf
;
1111 struct ldpd_af_conf
*af_conf
;
1113 const char *acl_for_str
;
1116 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1117 acl_for_str
= vty_get_arg_value(args
, "for_acl");
1119 vty_conf
= ldp_dup_config(ldpd_conf
);
1120 af
= ldp_vty_get_af(vty
);
1121 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1124 af_conf
->flags
&= ~F_LDPD_AF_EXPNULL
;
1125 af_conf
->acl_label_expnull_for
[0] = '\0';
1127 af_conf
->flags
|= F_LDPD_AF_EXPNULL
;
1129 strlcpy(af_conf
->acl_label_expnull_for
, acl_for_str
,
1130 sizeof(af_conf
->acl_label_expnull_for
));
1132 af_conf
->acl_label_expnull_for
[0] = '\0';
1135 ldp_reload(vty_conf
);
1137 return (CMD_SUCCESS
);
1141 ldp_vty_label_accept(struct vty
*vty
, struct vty_arg
*args
[])
1143 struct ldpd_conf
*vty_conf
;
1144 struct ldpd_af_conf
*af_conf
;
1146 const char *acl_from_str
;
1147 const char *acl_for_str
;
1150 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1151 acl_from_str
= vty_get_arg_value(args
, "from_acl");
1152 acl_for_str
= vty_get_arg_value(args
, "for_acl");
1154 vty_conf
= ldp_dup_config(ldpd_conf
);
1155 af
= ldp_vty_get_af(vty
);
1156 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1159 af_conf
->acl_label_accept_from
[0] = '\0';
1160 af_conf
->acl_label_accept_for
[0] = '\0';
1163 strlcpy(af_conf
->acl_label_accept_from
, acl_from_str
,
1164 sizeof(af_conf
->acl_label_accept_from
));
1166 af_conf
->acl_label_accept_from
[0] = '\0';
1168 strlcpy(af_conf
->acl_label_accept_for
, acl_for_str
,
1169 sizeof(af_conf
->acl_label_accept_for
));
1171 af_conf
->acl_label_accept_for
[0] = '\0';
1174 ldp_reload(vty_conf
);
1176 return (CMD_SUCCESS
);
1180 ldp_vty_ttl_security(struct vty
*vty
, struct vty_arg
*args
[])
1182 struct ldpd_conf
*vty_conf
;
1183 struct ldpd_af_conf
*af_conf
;
1187 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1189 vty_conf
= ldp_dup_config(ldpd_conf
);
1190 af
= ldp_vty_get_af(vty
);
1191 af_conf
= ldp_af_conf_get(vty_conf
, af
);
1194 af_conf
->flags
&= ~F_LDPD_AF_NO_GTSM
;
1196 af_conf
->flags
|= F_LDPD_AF_NO_GTSM
;
1198 ldp_reload(vty_conf
);
1200 return (CMD_SUCCESS
);
1204 ldp_vty_router_id(struct vty
*vty
, struct vty_arg
*args
[])
1206 struct ldpd_conf
*vty_conf
;
1207 const char *addr_str
;
1210 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1211 addr_str
= vty_get_arg_value(args
, "addr");
1213 vty_conf
= ldp_dup_config(ldpd_conf
);
1216 vty_conf
->rtr_id
.s_addr
= INADDR_ANY
;
1218 if (inet_pton(AF_INET
, addr_str
, &vty_conf
->rtr_id
) != 1 ||
1219 bad_addr_v4(vty_conf
->rtr_id
)) {
1220 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1225 ldp_reload(vty_conf
);
1227 return (CMD_SUCCESS
);
1230 ldp_clear_config(vty_conf
);
1231 return (CMD_SUCCESS
);
1235 ldp_vty_ds_cisco_interop(struct vty
*vty
, struct vty_arg
*args
[])
1237 struct ldpd_conf
*vty_conf
;
1240 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1242 vty_conf
= ldp_dup_config(ldpd_conf
);
1245 vty_conf
->flags
&= ~F_LDPD_DS_CISCO_INTEROP
;
1247 vty_conf
->flags
|= F_LDPD_DS_CISCO_INTEROP
;
1249 ldp_reload(vty_conf
);
1251 return (CMD_SUCCESS
);
1255 ldp_vty_trans_pref_ipv4(struct vty
*vty
, struct vty_arg
*args
[])
1257 struct ldpd_conf
*vty_conf
;
1260 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1262 vty_conf
= ldp_dup_config(ldpd_conf
);
1265 vty_conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1267 vty_conf
->trans_pref
= DUAL_STACK_LDPOV4
;
1269 ldp_reload(vty_conf
);
1271 return (CMD_SUCCESS
);
1275 ldp_vty_neighbor_password(struct vty
*vty
, struct vty_arg
*args
[])
1277 struct ldpd_conf
*vty_conf
;
1278 struct in_addr lsr_id
;
1279 size_t password_len
;
1280 struct nbr_params
*nbrp
;
1281 const char *lsr_id_str
;
1282 const char *password_str
;
1285 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1286 lsr_id_str
= vty_get_arg_value(args
, "lsr_id");
1287 password_str
= vty_get_arg_value(args
, "password");
1289 if (inet_pton(AF_INET
, lsr_id_str
, &lsr_id
) != 1 ||
1290 bad_addr_v4(lsr_id
)) {
1291 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1292 return (CMD_WARNING
);
1295 vty_conf
= ldp_dup_config(ldpd_conf
);
1296 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
1302 memset(&nbrp
->auth
, 0, sizeof(nbrp
->auth
));
1303 nbrp
->auth
.method
= AUTH_NONE
;
1306 nbrp
= nbr_params_new(lsr_id
);
1307 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1308 } else if (nbrp
->auth
.method
== AUTH_MD5SIG
&&
1309 strcmp(nbrp
->auth
.md5key
, password_str
) == 0)
1312 password_len
= strlcpy(nbrp
->auth
.md5key
, password_str
,
1313 sizeof(nbrp
->auth
.md5key
));
1314 if (password_len
>= sizeof(nbrp
->auth
.md5key
))
1315 vty_out(vty
, "%% password has been truncated to %zu "
1316 "characters.", sizeof(nbrp
->auth
.md5key
) - 1);
1317 nbrp
->auth
.md5key_len
= password_len
;
1318 nbrp
->auth
.method
= AUTH_MD5SIG
;
1321 ldp_reload(vty_conf
);
1323 return (CMD_SUCCESS
);
1326 ldp_clear_config(vty_conf
);
1327 return (CMD_SUCCESS
);
1331 ldp_vty_neighbor_ttl_security(struct vty
*vty
, struct vty_arg
*args
[])
1333 struct ldpd_conf
*vty_conf
;
1334 struct in_addr lsr_id
;
1335 struct nbr_params
*nbrp
;
1338 const char *lsr_id_str
;
1339 const char *hops_str
;
1342 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1343 lsr_id_str
= vty_get_arg_value(args
, "lsr_id");
1344 hops_str
= vty_get_arg_value(args
, "hops");
1346 if (inet_pton(AF_INET
, lsr_id_str
, &lsr_id
) != 1 ||
1347 bad_addr_v4(lsr_id
)) {
1348 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1349 return (CMD_WARNING
);
1353 hops
= strtol(hops_str
, &ep
, 10);
1354 if (*ep
!= '\0' || hops
< 1 || hops
> 254) {
1355 vty_out(vty
, "%% Invalid hop count%s", VTY_NEWLINE
);
1356 return (CMD_SUCCESS
);
1360 vty_conf
= ldp_dup_config(ldpd_conf
);
1361 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
1367 nbrp
->flags
&= ~(F_NBRP_GTSM
|F_NBRP_GTSM_HOPS
);
1368 nbrp
->gtsm_enabled
= 0;
1369 nbrp
->gtsm_hops
= 0;
1372 nbrp
= nbr_params_new(lsr_id
);
1373 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1376 nbrp
->flags
|= F_NBRP_GTSM
;
1377 nbrp
->flags
&= ~F_NBRP_GTSM_HOPS
;
1379 nbrp
->gtsm_enabled
= 1;
1380 nbrp
->gtsm_hops
= hops
;
1381 nbrp
->flags
|= F_NBRP_GTSM_HOPS
;
1383 nbrp
->gtsm_enabled
= 0;
1386 ldp_reload(vty_conf
);
1388 return (CMD_SUCCESS
);
1391 ldp_clear_config(vty_conf
);
1392 return (CMD_SUCCESS
);
1396 ldp_vty_l2vpn(struct vty
*vty
, struct vty_arg
*args
[])
1398 struct ldpd_conf
*vty_conf
;
1399 struct l2vpn
*l2vpn
;
1400 const char *name_str
;
1403 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1404 name_str
= vty_get_arg_value(args
, "name");
1406 vty_conf
= ldp_dup_config(ldpd_conf
);
1407 l2vpn
= l2vpn_find(vty_conf
, name_str
);
1413 RB_REMOVE(l2vpn_head
, &vty_conf
->l2vpn_tree
, l2vpn
);
1415 ldp_reload(vty_conf
);
1416 return (CMD_SUCCESS
);
1420 VTY_PUSH_CONTEXT(LDP_L2VPN_NODE
, l2vpn
);
1424 l2vpn
= l2vpn_new(name_str
);
1425 l2vpn
->type
= L2VPN_TYPE_VPLS
;
1426 RB_INSERT(l2vpn_head
, &vty_conf
->l2vpn_tree
, l2vpn
);
1428 ldp_reload_ref(vty_conf
, (void **)&l2vpn
);
1429 VTY_PUSH_CONTEXT(LDP_L2VPN_NODE
, l2vpn
);
1431 return (CMD_SUCCESS
);
1434 ldp_clear_config(vty_conf
);
1435 return (CMD_SUCCESS
);
1439 ldp_vty_l2vpn_bridge(struct vty
*vty
, struct vty_arg
*args
[])
1441 struct ldpd_conf
*vty_conf
;
1442 struct l2vpn
*l2vpn
;
1446 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1447 ifname
= vty_get_arg_value(args
, "ifname");
1449 l2vpn
= VTY_GET_CONTEXT(l2vpn
);
1450 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&l2vpn
);
1453 memset(l2vpn
->br_ifname
, 0, sizeof(l2vpn
->br_ifname
));
1455 strlcpy(l2vpn
->br_ifname
, ifname
, sizeof(l2vpn
->br_ifname
));
1457 ldp_reload_ref(vty_conf
, (void **)&l2vpn
);
1459 return (CMD_SUCCESS
);
1463 ldp_vty_l2vpn_mtu(struct vty
*vty
, struct vty_arg
*args
[])
1465 struct ldpd_conf
*vty_conf
;
1466 struct l2vpn
*l2vpn
;
1469 const char *mtu_str
;
1472 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1473 mtu_str
= vty_get_arg_value(args
, "mtu");
1475 mtu
= strtol(mtu_str
, &ep
, 10);
1476 if (*ep
!= '\0' || mtu
< MIN_L2VPN_MTU
|| mtu
> MAX_L2VPN_MTU
) {
1477 vty_out(vty
, "%% Invalid MTU%s", VTY_NEWLINE
);
1478 return (CMD_WARNING
);
1481 l2vpn
= VTY_GET_CONTEXT(l2vpn
);
1482 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&l2vpn
);
1485 l2vpn
->mtu
= DEFAULT_L2VPN_MTU
;
1489 ldp_reload_ref(vty_conf
, (void **)&l2vpn
);
1491 return (CMD_SUCCESS
);
1495 ldp_vty_l2vpn_pwtype(struct vty
*vty
, struct vty_arg
*args
[])
1497 struct ldpd_conf
*vty_conf
;
1498 struct l2vpn
*l2vpn
;
1500 const char *type_str
;
1503 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1504 type_str
= vty_get_arg_value(args
, "type");
1506 if (strcmp(type_str
, "ethernet") == 0)
1507 pw_type
= PW_TYPE_ETHERNET
;
1509 pw_type
= PW_TYPE_ETHERNET_TAGGED
;
1511 l2vpn
= VTY_GET_CONTEXT(l2vpn
);
1512 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&l2vpn
);
1515 l2vpn
->pw_type
= DEFAULT_PW_TYPE
;
1517 l2vpn
->pw_type
= pw_type
;
1519 ldp_reload_ref(vty_conf
, (void **)&l2vpn
);
1521 return (CMD_SUCCESS
);
1525 ldp_vty_l2vpn_interface(struct vty
*vty
, struct vty_arg
*args
[])
1527 struct ldpd_conf
*vty_conf
;
1528 struct l2vpn
*l2vpn
;
1529 struct l2vpn_if
*lif
;
1530 struct interface
*ifp
;
1535 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1536 ifname
= vty_get_arg_value(args
, "ifname");
1538 l2vpn
= VTY_GET_CONTEXT(l2vpn
);
1539 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&l2vpn
);
1540 l2vpn
= l2vpn_find(vty_conf
, l2vpn
->name
);
1541 lif
= l2vpn_if_find_name(l2vpn
, ifname
);
1547 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1549 ldp_reload(vty_conf
);
1550 return (CMD_SUCCESS
);
1556 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
1557 vty_out(vty
, "%% Interface is already in use%s", VTY_NEWLINE
);
1561 ifp
= if_lookup_by_name(ifname
, VRF_DEFAULT
);
1562 memset(&kif
, 0, sizeof(kif
));
1563 strlcpy(kif
.ifname
, ifname
, sizeof(kif
.ifname
));
1565 kif
.ifindex
= ifp
->ifindex
;
1566 kif
.flags
= ifp
->flags
;
1569 lif
= l2vpn_if_new(l2vpn
, &kif
);
1570 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1572 ldp_reload_ref(vty_conf
, (void **)&l2vpn
);
1574 return (CMD_SUCCESS
);
1577 ldp_clear_config(vty_conf
);
1578 return (CMD_SUCCESS
);
1582 ldp_vty_l2vpn_pseudowire(struct vty
*vty
, struct vty_arg
*args
[])
1584 struct ldpd_conf
*vty_conf
;
1585 struct l2vpn
*l2vpn
;
1586 struct l2vpn_pw
*pw
;
1587 struct interface
*ifp
;
1592 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1593 ifname
= vty_get_arg_value(args
, "ifname");
1595 l2vpn
= VTY_GET_CONTEXT(l2vpn
);
1596 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&l2vpn
);
1597 pw
= l2vpn_pw_find_name(l2vpn
, ifname
);
1603 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1605 ldp_reload(vty_conf
);
1606 return (CMD_SUCCESS
);
1610 VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE
, pw
);
1614 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
1615 vty_out(vty
, "%% Interface is already in use%s", VTY_NEWLINE
);
1619 ifp
= if_lookup_by_name(ifname
, VRF_DEFAULT
);
1620 memset(&kif
, 0, sizeof(kif
));
1621 strlcpy(kif
.ifname
, ifname
, sizeof(kif
.ifname
));
1623 kif
.ifindex
= ifp
->ifindex
;
1624 kif
.flags
= ifp
->flags
;
1627 pw
= l2vpn_pw_new(l2vpn
, &kif
);
1628 pw
->flags
= F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
;
1629 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1631 ldp_reload_ref(vty_conf
, (void **)&pw
);
1632 VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE
, pw
);
1634 return (CMD_SUCCESS
);
1637 ldp_clear_config(vty_conf
);
1638 return (CMD_SUCCESS
);
1642 ldp_vty_l2vpn_pw_cword(struct vty
*vty
, struct vty_arg
*args
[])
1644 struct ldpd_conf
*vty_conf
;
1645 struct l2vpn_pw
*pw
;
1646 const char *preference_str
;
1649 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1650 preference_str
= vty_get_arg_value(args
, "preference");
1652 pw
= VTY_GET_CONTEXT_SUB(l2vpn_pw
);
1653 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&pw
);
1656 pw
->flags
|= F_PW_CWORD_CONF
;
1658 if (preference_str
[0] == 'e')
1659 pw
->flags
&= ~F_PW_CWORD_CONF
;
1661 pw
->flags
|= F_PW_CWORD_CONF
;
1664 ldp_reload_ref(vty_conf
, (void **)&pw
);
1666 return (CMD_SUCCESS
);
1670 ldp_vty_l2vpn_pw_nbr_addr(struct vty
*vty
, struct vty_arg
*args
[])
1672 struct ldpd_conf
*vty_conf
;
1673 struct l2vpn_pw
*pw
;
1675 union ldpd_addr addr
;
1676 const char *addr_str
;
1679 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1680 addr_str
= vty_get_arg_value(args
, "addr");
1682 if (ldp_get_address(addr_str
, &af
, &addr
) == -1 ||
1683 bad_addr(af
, &addr
)) {
1684 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1685 return (CMD_WARNING
);
1688 pw
= VTY_GET_CONTEXT_SUB(l2vpn_pw
);
1689 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&pw
);
1693 memset(&pw
->addr
, 0, sizeof(pw
->addr
));
1694 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1698 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1701 ldp_reload_ref(vty_conf
, (void **)&pw
);
1703 return (CMD_SUCCESS
);
1707 ldp_vty_l2vpn_pw_nbr_id(struct vty
*vty
, struct vty_arg
*args
[])
1709 struct ldpd_conf
*vty_conf
;
1710 struct l2vpn_pw
*pw
;
1711 struct in_addr lsr_id
;
1712 const char *lsr_id_str
;
1715 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1716 lsr_id_str
= vty_get_arg_value(args
, "lsr-id");
1718 if (inet_pton(AF_INET
, lsr_id_str
, &lsr_id
) != 1 ||
1719 bad_addr_v4(lsr_id
)) {
1720 vty_out(vty
, "%% Malformed address%s", VTY_NEWLINE
);
1721 return (CMD_WARNING
);
1724 pw
= VTY_GET_CONTEXT_SUB(l2vpn_pw
);
1725 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&pw
);
1728 pw
->lsr_id
.s_addr
= INADDR_ANY
;
1730 pw
->lsr_id
= lsr_id
;
1732 ldp_reload_ref(vty_conf
, (void **)&pw
);
1734 return (CMD_SUCCESS
);
1738 ldp_vty_l2vpn_pw_pwid(struct vty
*vty
, struct vty_arg
*args
[])
1740 struct ldpd_conf
*vty_conf
;
1741 struct l2vpn_pw
*pw
;
1744 const char *pwid_str
;
1747 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1748 pwid_str
= vty_get_arg_value(args
, "pwid");
1750 pwid
= strtol(pwid_str
, &ep
, 10);
1751 if (*ep
!= '\0' || pwid
< MIN_PWID_ID
|| pwid
> MAX_PWID_ID
) {
1752 vty_out(vty
, "%% Invalid pw-id%s", VTY_NEWLINE
);
1753 return (CMD_WARNING
);
1756 pw
= VTY_GET_CONTEXT_SUB(l2vpn_pw
);
1757 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&pw
);
1764 ldp_reload_ref(vty_conf
, (void **)&pw
);
1766 return (CMD_SUCCESS
);
1770 ldp_vty_l2vpn_pw_pwstatus(struct vty
*vty
, struct vty_arg
*args
[])
1772 struct ldpd_conf
*vty_conf
;
1773 struct l2vpn_pw
*pw
;
1776 disable
= (vty_get_arg_value(args
, "no")) ? 1 : 0;
1778 pw
= VTY_GET_CONTEXT_SUB(l2vpn_pw
);
1779 vty_conf
= ldp_dup_config_ref(ldpd_conf
, (void **)&pw
);
1782 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1784 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1786 ldp_reload_ref(vty_conf
, (void **)&pw
);
1788 return (CMD_SUCCESS
);
1792 ldp_vty_if_init(void)
1794 /* Install interface node. */
1795 install_node (&interface_node
, interface_config_write
);
1800 iface_new_api(struct ldpd_conf
*conf
, const char *name
)
1802 const char *ifname
= name
;
1803 struct iface
*iface
;
1804 struct interface
*ifp
;
1807 if (ldp_iface_is_configured(conf
, ifname
))
1810 memset(&kif
, 0, sizeof(kif
));
1811 strlcpy(kif
.ifname
, ifname
, sizeof(kif
.ifname
));
1812 ifp
= if_lookup_by_name(ifname
, VRF_DEFAULT
);
1814 kif
.ifindex
= ifp
->ifindex
;
1815 kif
.flags
= ifp
->flags
;
1818 iface
= if_new(&kif
);
1819 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1824 iface_del_api(struct ldpd_conf
*conf
, struct iface
*iface
)
1826 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1831 tnbr_new_api(struct ldpd_conf
*conf
, int af
, union ldpd_addr
*addr
)
1835 if (af
== AF_INET6
&& IN6_IS_SCOPE_EMBED(&addr
->v6
))
1838 if (tnbr_find(conf
, af
, addr
))
1841 tnbr
= tnbr_new(af
, addr
);
1842 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1843 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1848 tnbr_del_api(struct ldpd_conf
*conf
, struct tnbr
*tnbr
)
1850 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1855 nbrp_new_api(struct ldpd_conf
*conf
, struct in_addr lsr_id
)
1857 struct nbr_params
*nbrp
;
1859 if (nbr_params_find(conf
, lsr_id
))
1862 nbrp
= nbr_params_new(lsr_id
);
1863 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1868 nbrp_del_api(struct ldpd_conf
*conf
, struct nbr_params
*nbrp
)
1870 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1875 l2vpn_new_api(struct ldpd_conf
*conf
, const char *name
)
1877 struct l2vpn
*l2vpn
;
1879 if (l2vpn_find(conf
, name
))
1882 l2vpn
= l2vpn_new(name
);
1883 l2vpn
->type
= L2VPN_TYPE_VPLS
;
1884 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1889 l2vpn_del_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
)
1891 struct l2vpn_if
*lif
;
1892 struct l2vpn_pw
*pw
;
1894 while ((lif
= RB_ROOT(&l2vpn
->if_tree
)) != NULL
) {
1895 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1898 while ((pw
= RB_ROOT(&l2vpn
->pw_tree
)) != NULL
) {
1899 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1902 while ((pw
= RB_ROOT(&l2vpn
->pw_inactive_tree
)) != NULL
) {
1903 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1906 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1911 l2vpn_if_new_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
,
1914 struct l2vpn_if
*lif
;
1915 struct interface
*ifp
;
1918 if (ldp_iface_is_configured(conf
, ifname
))
1921 memset(&kif
, 0, sizeof(kif
));
1922 strlcpy(kif
.ifname
, ifname
, sizeof(kif
.ifname
));
1923 ifp
= if_lookup_by_name(ifname
, VRF_DEFAULT
);
1925 kif
.ifindex
= ifp
->ifindex
;
1926 kif
.flags
= ifp
->flags
;
1929 lif
= l2vpn_if_new(l2vpn
, &kif
);
1930 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1935 l2vpn_if_del_api(struct l2vpn
*l2vpn
, struct l2vpn_if
*lif
)
1937 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1942 l2vpn_pw_new_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
,
1945 struct l2vpn_pw
*pw
;
1946 struct interface
*ifp
;
1949 if (ldp_iface_is_configured(conf
, ifname
))
1952 memset(&kif
, 0, sizeof(kif
));
1953 strlcpy(kif
.ifname
, ifname
, sizeof(kif
.ifname
));
1954 ifp
= if_lookup_by_name(ifname
, VRF_DEFAULT
);
1956 kif
.ifindex
= ifp
->ifindex
;
1957 kif
.flags
= ifp
->flags
;
1960 pw
= l2vpn_pw_new(l2vpn
, &kif
);
1961 pw
->flags
= F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
;
1962 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1967 l2vpn_pw_del_api(struct l2vpn
*l2vpn
, struct l2vpn_pw
*pw
)
1969 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);