2 * Copyright (C) 2016 by Open Source Routing.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
33 static void ldp_af_iface_config_write(struct vty
*, int);
34 static void ldp_af_config_write(struct vty
*, int, struct ldpd_conf
*,
35 struct ldpd_af_conf
*);
36 static void ldp_l2vpn_pw_config_write(struct vty
*, struct l2vpn_pw
*);
37 static int ldp_vty_get_af(struct vty
*);
38 static int ldp_iface_is_configured(struct ldpd_conf
*, const char *);
40 struct cmd_node ldp_node
=
47 struct cmd_node ldp_ipv4_node
=
50 "%s(config-ldp-af)# ",
54 struct cmd_node ldp_ipv6_node
=
57 "%s(config-ldp-af)# ",
61 struct cmd_node ldp_ipv4_iface_node
=
64 "%s(config-ldp-af-if)# ",
68 struct cmd_node ldp_ipv6_iface_node
=
71 "%s(config-ldp-af-if)# ",
75 struct cmd_node ldp_l2vpn_node
=
82 struct cmd_node ldp_pseudowire_node
=
85 "%s(config-l2vpn-pw)# ",
90 ldp_get_address(const char *str
, int *af
, union ldpd_addr
*addr
)
92 memset(addr
, 0, sizeof(*addr
));
94 if (inet_pton(AF_INET
, str
, &addr
->v4
) == 1) {
99 if (inet_pton(AF_INET6
, str
, &addr
->v6
) == 1) {
108 ldp_af_iface_config_write(struct vty
*vty
, int af
)
113 RB_FOREACH(iface
, iface_head
, &ldpd_conf
->iface_tree
) {
114 ia
= iface_af_get(iface
, af
);
118 vty_out (vty
, " !\n");
119 vty_out (vty
, " interface %s\n", iface
->name
);
121 if (ia
->hello_holdtime
!= LINK_DFLT_HOLDTIME
&&
122 ia
->hello_holdtime
!= 0)
123 vty_out (vty
, " discovery hello holdtime %u\n",
125 if (ia
->hello_interval
!= DEFAULT_HELLO_INTERVAL
&&
126 ia
->hello_interval
!= 0)
127 vty_out (vty
, " discovery hello interval %u\n",
133 ldp_af_config_write(struct vty
*vty
, int af
, struct ldpd_conf
*conf
,
134 struct ldpd_af_conf
*af_conf
)
138 if (!(af_conf
->flags
& F_LDPD_AF_ENABLED
))
141 vty_out (vty
, " !\n");
142 vty_out (vty
, " address-family %s\n", af_name(af
));
144 if (af_conf
->lhello_holdtime
!= LINK_DFLT_HOLDTIME
&&
145 af_conf
->lhello_holdtime
!= 0 )
146 vty_out (vty
, " discovery hello holdtime %u\n",
147 af_conf
->lhello_holdtime
);
148 if (af_conf
->lhello_interval
!= DEFAULT_HELLO_INTERVAL
&&
149 af_conf
->lhello_interval
!= 0)
150 vty_out (vty
, " discovery hello interval %u\n",
151 af_conf
->lhello_interval
);
153 if (af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) {
154 vty_out(vty
, " discovery targeted-hello accept");
155 if (af_conf
->acl_thello_accept_from
[0] != '\0')
156 vty_out(vty
, " from %s",
157 af_conf
->acl_thello_accept_from
);
161 if (af_conf
->thello_holdtime
!= TARGETED_DFLT_HOLDTIME
&&
162 af_conf
->thello_holdtime
!= 0)
163 vty_out (vty
, " discovery targeted-hello holdtime %u\n",
164 af_conf
->thello_holdtime
);
165 if (af_conf
->thello_interval
!= DEFAULT_HELLO_INTERVAL
&&
166 af_conf
->thello_interval
!= 0)
167 vty_out (vty
, " discovery targeted-hello interval %u\n",
168 af_conf
->thello_interval
);
170 if (ldp_addrisset(af
, &af_conf
->trans_addr
))
171 vty_out (vty
, " discovery transport-address %s\n",
172 log_addr(af
, &af_conf
->trans_addr
));
175 " ! Incomplete config, specify a discovery transport-address\n");
177 if ((af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
) ||
178 af_conf
->acl_label_allocate_for
[0] != '\0') {
179 vty_out(vty
, " label local allocate");
180 if (af_conf
->flags
& F_LDPD_AF_ALLOCHOSTONLY
)
181 vty_out(vty
, " host-routes");
183 vty_out(vty
, " for %s",
184 af_conf
->acl_label_allocate_for
);
188 if (af_conf
->acl_label_advertise_for
[0] != '\0' ||
189 af_conf
->acl_label_advertise_to
[0] != '\0') {
190 vty_out(vty
, " label local advertise");
191 if (af_conf
->acl_label_advertise_to
[0] != '\0')
192 vty_out(vty
, " to %s",
193 af_conf
->acl_label_advertise_to
);
194 if (af_conf
->acl_label_advertise_for
[0] != '\0')
195 vty_out(vty
, " for %s",
196 af_conf
->acl_label_advertise_for
);
200 if (af_conf
->flags
& F_LDPD_AF_EXPNULL
) {
201 vty_out(vty
, " label local advertise explicit-null");
202 if (af_conf
->acl_label_expnull_for
[0] != '\0')
203 vty_out(vty
, " for %s",
204 af_conf
->acl_label_expnull_for
);
208 if (af_conf
->acl_label_accept_for
[0] != '\0' ||
209 af_conf
->acl_label_accept_from
[0] != '\0') {
210 vty_out(vty
, " label remote accept");
211 if (af_conf
->acl_label_accept_from
[0] != '\0')
212 vty_out(vty
, " from %s",
213 af_conf
->acl_label_accept_from
);
214 if (af_conf
->acl_label_accept_for
[0] != '\0')
215 vty_out(vty
, " for %s",
216 af_conf
->acl_label_accept_for
);
220 if (af_conf
->flags
& F_LDPD_AF_NO_GTSM
)
221 vty_out (vty
, " ttl-security disable\n");
223 if (af_conf
->keepalive
!= DEFAULT_KEEPALIVE
)
224 vty_out (vty
, " session holdtime %u\n",af_conf
->keepalive
);
226 RB_FOREACH(tnbr
, tnbr_head
, &ldpd_conf
->tnbr_tree
) {
227 if (tnbr
->af
== af
) {
228 vty_out (vty
, " !\n");
229 vty_out (vty
, " neighbor %s targeted\n",
230 log_addr(tnbr
->af
, &tnbr
->addr
));
234 ldp_af_iface_config_write(vty
, af
);
236 vty_out(vty
, " !\n");
237 vty_out(vty
, " exit-address-family\n");
241 ldp_config_write(struct vty
*vty
)
243 struct nbr_params
*nbrp
;
245 if (!(ldpd_conf
->flags
& F_LDPD_ENABLED
))
248 vty_out (vty
, "mpls ldp\n");
250 if (ldpd_conf
->rtr_id
.s_addr
!= 0)
251 vty_out (vty
, " router-id %s\n",
252 inet_ntoa(ldpd_conf
->rtr_id
));
254 if (ldpd_conf
->lhello_holdtime
!= LINK_DFLT_HOLDTIME
&&
255 ldpd_conf
->lhello_holdtime
!= 0)
256 vty_out (vty
, " discovery hello holdtime %u\n",
257 ldpd_conf
->lhello_holdtime
);
258 if (ldpd_conf
->lhello_interval
!= DEFAULT_HELLO_INTERVAL
&&
259 ldpd_conf
->lhello_interval
!= 0)
260 vty_out (vty
, " discovery hello interval %u\n",
261 ldpd_conf
->lhello_interval
);
263 if (ldpd_conf
->thello_holdtime
!= TARGETED_DFLT_HOLDTIME
&&
264 ldpd_conf
->thello_holdtime
!= 0)
265 vty_out (vty
, " discovery targeted-hello holdtime %u\n",
266 ldpd_conf
->thello_holdtime
);
267 if (ldpd_conf
->thello_interval
!= DEFAULT_HELLO_INTERVAL
&&
268 ldpd_conf
->thello_interval
!= 0)
269 vty_out (vty
, " discovery targeted-hello interval %u\n",
270 ldpd_conf
->thello_interval
);
272 if (ldpd_conf
->trans_pref
== DUAL_STACK_LDPOV4
)
274 " dual-stack transport-connection prefer ipv4\n");
276 if (ldpd_conf
->flags
& F_LDPD_DS_CISCO_INTEROP
)
277 vty_out (vty
, " dual-stack cisco-interop\n");
279 RB_FOREACH(nbrp
, nbrp_head
, &ldpd_conf
->nbrp_tree
) {
280 if (nbrp
->flags
& F_NBRP_KEEPALIVE
)
281 vty_out (vty
, " neighbor %s session holdtime %u\n",
282 inet_ntoa(nbrp
->lsr_id
),nbrp
->keepalive
);
284 if (nbrp
->flags
& F_NBRP_GTSM
) {
285 if (nbrp
->gtsm_enabled
)
286 vty_out (vty
, " neighbor %s ttl-security hops "
287 "%u\n", inet_ntoa(nbrp
->lsr_id
),
290 vty_out (vty
, " neighbor %s ttl-security "
291 "disable\n",inet_ntoa(nbrp
->lsr_id
));
294 if (nbrp
->auth
.method
== AUTH_MD5SIG
)
295 vty_out (vty
, " neighbor %s password %s\n",
296 inet_ntoa(nbrp
->lsr_id
),nbrp
->auth
.md5key
);
299 ldp_af_config_write(vty
, AF_INET
, ldpd_conf
, &ldpd_conf
->ipv4
);
300 ldp_af_config_write(vty
, AF_INET6
, ldpd_conf
, &ldpd_conf
->ipv6
);
301 vty_out (vty
, " !\n");
302 vty_out (vty
, "!\n");
308 ldp_l2vpn_pw_config_write(struct vty
*vty
, struct l2vpn_pw
*pw
)
310 int missing_lsrid
= 0;
311 int missing_pwid
= 0;
313 vty_out (vty
, " !\n");
314 vty_out (vty
, " member pseudowire %s\n", pw
->ifname
);
316 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
)
317 vty_out (vty
, " neighbor lsr-id %s\n",inet_ntoa(pw
->lsr_id
));
321 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
322 vty_out (vty
, " neighbor address %s\n",
323 log_addr(pw
->af
, &pw
->addr
));
326 vty_out (vty
, " pw-id %u\n", pw
->pwid
);
330 if (!(pw
->flags
& F_PW_CWORD_CONF
))
331 vty_out (vty
, " control-word exclude\n");
333 if (!(pw
->flags
& F_PW_STATUSTLV_CONF
))
334 vty_out (vty
, " pw-status disable\n");
338 " ! Incomplete config, specify a neighbor lsr-id\n");
340 vty_out (vty
," ! Incomplete config, specify a pw-id\n");
344 ldp_l2vpn_config_write(struct vty
*vty
)
347 struct l2vpn_if
*lif
;
350 RB_FOREACH(l2vpn
, l2vpn_head
, &ldpd_conf
->l2vpn_tree
) {
351 vty_out (vty
, "l2vpn %s type vpls\n", l2vpn
->name
);
353 if (l2vpn
->pw_type
!= DEFAULT_PW_TYPE
)
354 vty_out (vty
, " vc type ethernet-tagged\n");
356 if (l2vpn
->mtu
!= DEFAULT_L2VPN_MTU
)
357 vty_out (vty
, " mtu %u\n", l2vpn
->mtu
);
359 if (l2vpn
->br_ifname
[0] != '\0')
360 vty_out (vty
, " bridge %s\n",l2vpn
->br_ifname
);
362 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
363 vty_out (vty
, " member interface %s\n",lif
->ifname
);
365 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
366 ldp_l2vpn_pw_config_write(vty
, pw
);
367 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
368 ldp_l2vpn_pw_config_write(vty
, pw
);
370 vty_out (vty
, " !\n");
371 vty_out (vty
, "!\n");
378 ldp_vty_get_af(struct vty
*vty
)
382 case LDP_IPV4_IFACE_NODE
:
385 case LDP_IPV6_IFACE_NODE
:
388 fatalx("ldp_vty_get_af: unexpected node");
393 ldp_iface_is_configured(struct ldpd_conf
*xconf
, const char *ifname
)
397 if (if_lookup_name(xconf
, ifname
))
400 RB_FOREACH(l2vpn
, l2vpn_head
, &xconf
->l2vpn_tree
) {
401 if (l2vpn_if_find(l2vpn
, ifname
))
403 if (l2vpn_pw_find(l2vpn
, ifname
))
411 ldp_vty_mpls_ldp(struct vty
*vty
, const char *negate
)
414 vty_conf
->flags
&= ~F_LDPD_ENABLED
;
416 vty
->node
= LDP_NODE
;
417 vty_conf
->flags
|= F_LDPD_ENABLED
;
420 ldp_config_apply(vty
, vty_conf
);
422 return (CMD_SUCCESS
);
426 ldp_vty_address_family(struct vty
*vty
, const char *negate
, const char *af_str
)
428 struct ldpd_af_conf
*af_conf
;
431 if (strcmp(af_str
, "ipv4") == 0) {
433 af_conf
= &vty_conf
->ipv4
;
434 } else if (strcmp(af_str
, "ipv6") == 0) {
436 af_conf
= &vty_conf
->ipv6
;
438 return (CMD_WARNING_CONFIG_FAILED
);
441 af_conf
->flags
&= ~F_LDPD_AF_ENABLED
;
442 ldp_config_apply(vty
, vty_conf
);
443 return (CMD_SUCCESS
);
448 vty
->node
= LDP_IPV4_NODE
;
451 vty
->node
= LDP_IPV6_NODE
;
454 fatalx("ldp_vty_address_family: unknown af");
456 af_conf
->flags
|= F_LDPD_AF_ENABLED
;
458 ldp_config_apply(vty
, vty_conf
);
460 return (CMD_SUCCESS
);
463 int ldp_vty_disc_holdtime(struct vty
*vty
, const char *negate
,
464 enum hello_type hello_type
, long secs
)
466 struct ldpd_af_conf
*af_conf
;
474 switch (hello_type
) {
476 vty_conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
479 vty_conf
->thello_holdtime
=
480 TARGETED_DFLT_HOLDTIME
;
484 switch (hello_type
) {
486 vty_conf
->lhello_holdtime
= secs
;
489 vty_conf
->thello_holdtime
= secs
;
493 ldp_config_apply(vty
, vty_conf
);
497 af
= ldp_vty_get_af(vty
);
498 af_conf
= ldp_af_conf_get(vty_conf
, af
);
501 switch (hello_type
) {
503 af_conf
->lhello_holdtime
= 0;
506 af_conf
->thello_holdtime
= 0;
510 switch (hello_type
) {
512 af_conf
->lhello_holdtime
= secs
;
515 af_conf
->thello_holdtime
= secs
;
519 ldp_config_apply(vty
, vty_conf
);
521 case LDP_IPV4_IFACE_NODE
:
522 case LDP_IPV6_IFACE_NODE
:
523 af
= ldp_vty_get_af(vty
);
524 iface
= VTY_GET_CONTEXT(iface
);
525 VTY_CHECK_CONTEXT(iface
);
527 ia
= iface_af_get(iface
, af
);
529 ia
->hello_holdtime
= 0;
531 ia
->hello_holdtime
= secs
;
533 ldp_config_apply(vty
, vty_conf
);
536 fatalx("ldp_vty_disc_holdtime: unexpected node");
539 return (CMD_SUCCESS
);
543 ldp_vty_disc_interval(struct vty
*vty
, const char *negate
,
544 enum hello_type hello_type
, long secs
)
546 struct ldpd_af_conf
*af_conf
;
554 switch (hello_type
) {
556 vty_conf
->lhello_interval
=
557 DEFAULT_HELLO_INTERVAL
;
560 vty_conf
->thello_interval
=
561 DEFAULT_HELLO_INTERVAL
;
565 switch (hello_type
) {
567 vty_conf
->lhello_interval
= secs
;
570 vty_conf
->thello_interval
= secs
;
574 ldp_config_apply(vty
, vty_conf
);
578 af
= ldp_vty_get_af(vty
);
579 af_conf
= ldp_af_conf_get(vty_conf
, af
);
582 switch (hello_type
) {
584 af_conf
->lhello_interval
= 0;
587 af_conf
->thello_interval
= 0;
591 switch (hello_type
) {
593 af_conf
->lhello_interval
= secs
;
596 af_conf
->thello_interval
= secs
;
600 ldp_config_apply(vty
, vty_conf
);
602 case LDP_IPV4_IFACE_NODE
:
603 case LDP_IPV6_IFACE_NODE
:
604 af
= ldp_vty_get_af(vty
);
605 iface
= VTY_GET_CONTEXT(iface
);
606 VTY_CHECK_CONTEXT(iface
);
608 ia
= iface_af_get(iface
, af
);
610 ia
->hello_interval
= 0;
612 ia
->hello_interval
= secs
;
614 ldp_config_apply(vty
, vty_conf
);
617 fatalx("ldp_vty_disc_interval: unexpected node");
620 return (CMD_SUCCESS
);
624 ldp_vty_targeted_hello_accept(struct vty
*vty
, const char *negate
,
625 const char *acl_from_str
)
627 struct ldpd_af_conf
*af_conf
;
630 af
= ldp_vty_get_af(vty
);
631 af_conf
= ldp_af_conf_get(vty_conf
, af
);
634 af_conf
->flags
&= ~F_LDPD_AF_THELLO_ACCEPT
;
635 af_conf
->acl_thello_accept_from
[0] = '\0';
637 af_conf
->flags
|= F_LDPD_AF_THELLO_ACCEPT
;
639 strlcpy(af_conf
->acl_thello_accept_from
, acl_from_str
,
640 sizeof(af_conf
->acl_thello_accept_from
));
642 af_conf
->acl_thello_accept_from
[0] = '\0';
645 ldp_config_apply(vty
, vty_conf
);
647 return (CMD_SUCCESS
);
651 ldp_vty_nbr_session_holdtime(struct vty
*vty
, const char *negate
,
652 struct in_addr lsr_id
, long secs
)
654 struct nbr_params
*nbrp
;
656 if (bad_addr_v4(lsr_id
)) {
657 vty_out (vty
, "%% Malformed address\n");
658 return (CMD_WARNING_CONFIG_FAILED
);
661 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
665 return (CMD_SUCCESS
);
668 nbrp
->flags
&= ~F_NBRP_KEEPALIVE
;
671 nbrp
= nbr_params_new(lsr_id
);
672 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
673 QOBJ_REG(nbrp
, nbr_params
);
674 } else if (nbrp
->keepalive
== secs
)
675 return (CMD_SUCCESS
);
677 nbrp
->keepalive
= secs
;
678 nbrp
->flags
|= F_NBRP_KEEPALIVE
;
681 ldp_config_apply(vty
, vty_conf
);
683 return (CMD_SUCCESS
);
687 ldp_vty_af_session_holdtime(struct vty
*vty
, const char *negate
, long secs
)
689 struct ldpd_af_conf
*af_conf
;
692 af
= ldp_vty_get_af(vty
);
693 af_conf
= ldp_af_conf_get(vty_conf
, af
);
696 af_conf
->keepalive
= DEFAULT_KEEPALIVE
;
698 af_conf
->keepalive
= secs
;
700 ldp_config_apply(vty
, vty_conf
);
702 return (CMD_SUCCESS
);
706 ldp_vty_interface(struct vty
*vty
, const char *negate
, const char *ifname
)
712 af
= ldp_vty_get_af(vty
);
713 iface
= if_lookup_name(vty_conf
, ifname
);
717 return (CMD_SUCCESS
);
719 ia
= iface_af_get(iface
, af
);
720 if (ia
->enabled
== 0)
721 return (CMD_SUCCESS
);
724 ia
->hello_holdtime
= 0;
725 ia
->hello_interval
= 0;
727 ldp_config_apply(vty
, vty_conf
);
729 return (CMD_SUCCESS
);
733 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
734 vty_out (vty
,"%% Interface is already in use\n");
735 return (CMD_SUCCESS
);
738 iface
= if_new(ifname
);
739 ia
= iface_af_get(iface
, af
);
741 RB_INSERT(iface_head
, &vty_conf
->iface_tree
, iface
);
742 QOBJ_REG(iface
, iface
);
744 ldp_config_apply(vty
, vty_conf
);
746 ia
= iface_af_get(iface
, af
);
749 ldp_config_apply(vty
, vty_conf
);
755 VTY_PUSH_CONTEXT(LDP_IPV4_IFACE_NODE
, iface
);
758 VTY_PUSH_CONTEXT(LDP_IPV6_IFACE_NODE
, iface
);
764 return (CMD_SUCCESS
);
768 ldp_vty_trans_addr(struct vty
*vty
, const char *negate
, const char *addr_str
)
770 struct ldpd_af_conf
*af_conf
;
773 af
= ldp_vty_get_af(vty
);
774 af_conf
= ldp_af_conf_get(vty_conf
, af
);
777 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
779 if (inet_pton(af
, addr_str
, &af_conf
->trans_addr
) != 1 ||
780 bad_addr(af
, &af_conf
->trans_addr
)) {
781 vty_out (vty
, "%% Malformed address\n");
782 return (CMD_SUCCESS
);
786 ldp_config_apply(vty
, vty_conf
);
788 return (CMD_SUCCESS
);
792 ldp_vty_neighbor_targeted(struct vty
*vty
, const char *negate
, const char *addr_str
)
795 union ldpd_addr addr
;
798 af
= ldp_vty_get_af(vty
);
800 if (inet_pton(af
, addr_str
, &addr
) != 1 ||
801 bad_addr(af
, &addr
)) {
802 vty_out (vty
, "%% Malformed address\n");
803 return (CMD_WARNING_CONFIG_FAILED
);
805 if (af
== AF_INET6
&& IN6_IS_SCOPE_EMBED(&addr
.v6
)) {
806 vty_out (vty
, "%% Address can not be link-local\n");
807 return (CMD_WARNING_CONFIG_FAILED
);
810 tnbr
= tnbr_find(vty_conf
, af
, &addr
);
814 return (CMD_SUCCESS
);
817 RB_REMOVE(tnbr_head
, &vty_conf
->tnbr_tree
, tnbr
);
820 ldp_config_apply(vty
, vty_conf
);
822 return (CMD_SUCCESS
);
826 return (CMD_SUCCESS
);
828 tnbr
= tnbr_new(af
, &addr
);
829 tnbr
->flags
|= F_TNBR_CONFIGURED
;
830 RB_INSERT(tnbr_head
, &vty_conf
->tnbr_tree
, tnbr
);
831 QOBJ_REG(tnbr
, tnbr
);
833 ldp_config_apply(vty
, vty_conf
);
835 return (CMD_SUCCESS
);
839 ldp_vty_label_advertise(struct vty
*vty
, const char *negate
, const char *acl_to_str
,
840 const char *acl_for_str
)
842 struct ldpd_af_conf
*af_conf
;
845 af
= ldp_vty_get_af(vty
);
846 af_conf
= ldp_af_conf_get(vty_conf
, af
);
849 af_conf
->acl_label_advertise_to
[0] = '\0';
850 af_conf
->acl_label_advertise_for
[0] = '\0';
853 strlcpy(af_conf
->acl_label_advertise_to
, acl_to_str
,
854 sizeof(af_conf
->acl_label_advertise_to
));
856 af_conf
->acl_label_advertise_to
[0] = '\0';
858 strlcpy(af_conf
->acl_label_advertise_for
, acl_for_str
,
859 sizeof(af_conf
->acl_label_advertise_for
));
861 af_conf
->acl_label_advertise_for
[0] = '\0';
864 ldp_config_apply(vty
, vty_conf
);
866 return (CMD_SUCCESS
);
870 ldp_vty_label_allocate(struct vty
*vty
, const char *negate
, const char *host_routes
,
871 const char *acl_for_str
)
873 struct ldpd_af_conf
*af_conf
;
876 af
= ldp_vty_get_af(vty
);
877 af_conf
= ldp_af_conf_get(vty_conf
, af
);
879 af_conf
->flags
&= ~F_LDPD_AF_ALLOCHOSTONLY
;
880 af_conf
->acl_label_allocate_for
[0] = '\0';
883 af_conf
->flags
|= F_LDPD_AF_ALLOCHOSTONLY
;
885 strlcpy(af_conf
->acl_label_allocate_for
, acl_for_str
,
886 sizeof(af_conf
->acl_label_allocate_for
));
889 ldp_config_apply(vty
, vty_conf
);
891 return (CMD_SUCCESS
);
895 ldp_vty_label_expnull(struct vty
*vty
, const char *negate
, const char *acl_for_str
)
897 struct ldpd_af_conf
*af_conf
;
900 af
= ldp_vty_get_af(vty
);
901 af_conf
= ldp_af_conf_get(vty_conf
, af
);
904 af_conf
->flags
&= ~F_LDPD_AF_EXPNULL
;
905 af_conf
->acl_label_expnull_for
[0] = '\0';
907 af_conf
->flags
|= F_LDPD_AF_EXPNULL
;
909 strlcpy(af_conf
->acl_label_expnull_for
, acl_for_str
,
910 sizeof(af_conf
->acl_label_expnull_for
));
912 af_conf
->acl_label_expnull_for
[0] = '\0';
915 ldp_config_apply(vty
, vty_conf
);
917 return (CMD_SUCCESS
);
921 ldp_vty_label_accept(struct vty
*vty
, const char *negate
, const char *acl_from_str
,
922 const char *acl_for_str
)
924 struct ldpd_af_conf
*af_conf
;
927 af
= ldp_vty_get_af(vty
);
928 af_conf
= ldp_af_conf_get(vty_conf
, af
);
931 af_conf
->acl_label_accept_from
[0] = '\0';
932 af_conf
->acl_label_accept_for
[0] = '\0';
935 strlcpy(af_conf
->acl_label_accept_from
, acl_from_str
,
936 sizeof(af_conf
->acl_label_accept_from
));
938 af_conf
->acl_label_accept_from
[0] = '\0';
940 strlcpy(af_conf
->acl_label_accept_for
, acl_for_str
,
941 sizeof(af_conf
->acl_label_accept_for
));
943 af_conf
->acl_label_accept_for
[0] = '\0';
946 ldp_config_apply(vty
, vty_conf
);
948 return (CMD_SUCCESS
);
952 ldp_vty_ttl_security(struct vty
*vty
, const char *negate
)
954 struct ldpd_af_conf
*af_conf
;
957 af
= ldp_vty_get_af(vty
);
958 af_conf
= ldp_af_conf_get(vty_conf
, af
);
961 af_conf
->flags
&= ~F_LDPD_AF_NO_GTSM
;
963 af_conf
->flags
|= F_LDPD_AF_NO_GTSM
;
965 ldp_config_apply(vty
, vty_conf
);
967 return (CMD_SUCCESS
);
971 ldp_vty_router_id(struct vty
*vty
, const char *negate
, struct in_addr address
)
974 vty_conf
->rtr_id
.s_addr
= INADDR_ANY
;
976 if (bad_addr_v4(address
)) {
977 vty_out (vty
, "%% Malformed address\n");
978 return (CMD_SUCCESS
);
980 vty_conf
->rtr_id
= address
;
983 ldp_config_apply(vty
, vty_conf
);
985 return (CMD_SUCCESS
);
989 ldp_vty_ds_cisco_interop(struct vty
*vty
, const char * negate
)
992 vty_conf
->flags
&= ~F_LDPD_DS_CISCO_INTEROP
;
994 vty_conf
->flags
|= F_LDPD_DS_CISCO_INTEROP
;
996 ldp_config_apply(vty
, vty_conf
);
998 return (CMD_SUCCESS
);
1002 ldp_vty_trans_pref_ipv4(struct vty
*vty
, const char *negate
)
1005 vty_conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1007 vty_conf
->trans_pref
= DUAL_STACK_LDPOV4
;
1009 ldp_config_apply(vty
, vty_conf
);
1011 return (CMD_SUCCESS
);
1015 ldp_vty_neighbor_password(struct vty
*vty
, const char *negate
, struct in_addr lsr_id
,
1016 const char *password_str
)
1018 size_t password_len
;
1019 struct nbr_params
*nbrp
;
1021 if (bad_addr_v4(lsr_id
)) {
1022 vty_out (vty
, "%% Malformed address\n");
1023 return (CMD_WARNING_CONFIG_FAILED
);
1026 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
1030 return (CMD_SUCCESS
);
1032 memset(&nbrp
->auth
, 0, sizeof(nbrp
->auth
));
1033 nbrp
->auth
.method
= AUTH_NONE
;
1036 nbrp
= nbr_params_new(lsr_id
);
1037 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1038 QOBJ_REG(nbrp
, nbr_params
);
1039 } else if (nbrp
->auth
.method
== AUTH_MD5SIG
&&
1040 strcmp(nbrp
->auth
.md5key
, password_str
) == 0)
1041 return (CMD_SUCCESS
);
1043 password_len
= strlcpy(nbrp
->auth
.md5key
, password_str
,
1044 sizeof(nbrp
->auth
.md5key
));
1045 if (password_len
>= sizeof(nbrp
->auth
.md5key
))
1046 vty_out(vty
, "%% password has been truncated to %zu "
1047 "characters.", sizeof(nbrp
->auth
.md5key
) - 1);
1048 nbrp
->auth
.md5key_len
= password_len
;
1049 nbrp
->auth
.method
= AUTH_MD5SIG
;
1052 ldp_config_apply(vty
, vty_conf
);
1054 return (CMD_SUCCESS
);
1058 ldp_vty_neighbor_ttl_security(struct vty
*vty
, const char *negate
,
1059 struct in_addr lsr_id
, const char *hops_str
)
1061 struct nbr_params
*nbrp
;
1065 if (bad_addr_v4(lsr_id
)) {
1066 vty_out (vty
, "%% Malformed address\n");
1067 return (CMD_WARNING_CONFIG_FAILED
);
1071 hops
= strtol(hops_str
, &ep
, 10);
1072 if (*ep
!= '\0' || hops
< 1 || hops
> 254) {
1073 vty_out (vty
, "%% Invalid hop count\n");
1074 return (CMD_SUCCESS
);
1078 nbrp
= nbr_params_find(vty_conf
, lsr_id
);
1082 return (CMD_SUCCESS
);
1084 nbrp
->flags
&= ~(F_NBRP_GTSM
|F_NBRP_GTSM_HOPS
);
1085 nbrp
->gtsm_enabled
= 0;
1086 nbrp
->gtsm_hops
= 0;
1089 nbrp
= nbr_params_new(lsr_id
);
1090 RB_INSERT(nbrp_head
, &vty_conf
->nbrp_tree
, nbrp
);
1091 QOBJ_REG(nbrp
, nbr_params
);
1094 nbrp
->flags
|= F_NBRP_GTSM
;
1095 nbrp
->flags
&= ~F_NBRP_GTSM_HOPS
;
1097 nbrp
->gtsm_enabled
= 1;
1098 nbrp
->gtsm_hops
= hops
;
1099 nbrp
->flags
|= F_NBRP_GTSM_HOPS
;
1101 nbrp
->gtsm_enabled
= 0;
1104 ldp_config_apply(vty
, vty_conf
);
1106 return (CMD_SUCCESS
);
1110 ldp_vty_l2vpn(struct vty
*vty
, const char *negate
, const char *name_str
)
1112 struct l2vpn
*l2vpn
;
1113 struct l2vpn_if
*lif
;
1114 struct l2vpn_pw
*pw
;
1116 l2vpn
= l2vpn_find(vty_conf
, name_str
);
1120 return (CMD_SUCCESS
);
1122 RB_FOREACH(lif
, l2vpn_if_head
, &l2vpn
->if_tree
)
1124 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_tree
)
1126 RB_FOREACH(pw
, l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)
1129 RB_REMOVE(l2vpn_head
, &vty_conf
->l2vpn_tree
, l2vpn
);
1132 ldp_config_apply(vty
, vty_conf
);
1134 return (CMD_SUCCESS
);
1138 VTY_PUSH_CONTEXT(LDP_L2VPN_NODE
, l2vpn
);
1139 return (CMD_SUCCESS
);
1142 l2vpn
= l2vpn_new(name_str
);
1143 l2vpn
->type
= L2VPN_TYPE_VPLS
;
1144 RB_INSERT(l2vpn_head
, &vty_conf
->l2vpn_tree
, l2vpn
);
1145 QOBJ_REG(l2vpn
, l2vpn
);
1147 VTY_PUSH_CONTEXT(LDP_L2VPN_NODE
, l2vpn
);
1149 ldp_config_apply(vty
, vty_conf
);
1151 return (CMD_SUCCESS
);
1155 ldp_vty_l2vpn_bridge(struct vty
*vty
, const char *negate
, const char *ifname
)
1157 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1160 memset(l2vpn
->br_ifname
, 0, sizeof(l2vpn
->br_ifname
));
1162 strlcpy(l2vpn
->br_ifname
, ifname
, sizeof(l2vpn
->br_ifname
));
1164 ldp_config_apply(vty
, vty_conf
);
1166 return (CMD_SUCCESS
);
1170 ldp_vty_l2vpn_mtu(struct vty
*vty
, const char *negate
, long mtu
)
1172 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1175 l2vpn
->mtu
= DEFAULT_L2VPN_MTU
;
1179 ldp_config_apply(vty
, vty_conf
);
1181 return (CMD_SUCCESS
);
1185 ldp_vty_l2vpn_pwtype(struct vty
*vty
, const char *negate
, const char *type_str
)
1187 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1190 if (strcmp(type_str
, "ethernet") == 0)
1191 pw_type
= PW_TYPE_ETHERNET
;
1193 pw_type
= PW_TYPE_ETHERNET_TAGGED
;
1196 l2vpn
->pw_type
= DEFAULT_PW_TYPE
;
1198 l2vpn
->pw_type
= pw_type
;
1200 ldp_config_apply(vty
, vty_conf
);
1202 return (CMD_SUCCESS
);
1206 ldp_vty_l2vpn_interface(struct vty
*vty
, const char *negate
, const char *ifname
)
1208 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1209 struct l2vpn_if
*lif
;
1211 lif
= l2vpn_if_find(l2vpn
, ifname
);
1215 return (CMD_SUCCESS
);
1218 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1221 ldp_config_apply(vty
, vty_conf
);
1223 return (CMD_SUCCESS
);
1227 return (CMD_SUCCESS
);
1229 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
1230 vty_out (vty
, "%% Interface is already in use\n");
1231 return (CMD_SUCCESS
);
1234 lif
= l2vpn_if_new(l2vpn
, ifname
);
1235 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1236 QOBJ_REG(lif
, l2vpn_if
);
1238 ldp_config_apply(vty
, vty_conf
);
1240 return (CMD_SUCCESS
);
1244 ldp_vty_l2vpn_pseudowire(struct vty
*vty
, const char *negate
, const char *ifname
)
1246 VTY_DECLVAR_CONTEXT(l2vpn
, l2vpn
);
1247 struct l2vpn_pw
*pw
;
1249 pw
= l2vpn_pw_find(l2vpn
, ifname
);
1253 return (CMD_SUCCESS
);
1256 if (pw
->lsr_id
.s_addr
== INADDR_ANY
|| pw
->pwid
== 0)
1257 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1259 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1262 ldp_config_apply(vty
, vty_conf
);
1264 return (CMD_SUCCESS
);
1268 VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE
, pw
);
1269 return (CMD_SUCCESS
);
1272 if (ldp_iface_is_configured(vty_conf
, ifname
)) {
1273 vty_out (vty
, "%% Interface is already in use\n");
1274 return (CMD_SUCCESS
);
1277 pw
= l2vpn_pw_new(l2vpn
, ifname
);
1278 pw
->flags
= F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
;
1279 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1280 QOBJ_REG(pw
, l2vpn_pw
);
1282 VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE
, pw
);
1284 ldp_config_apply(vty
, vty_conf
);
1286 return (CMD_SUCCESS
);
1290 ldp_vty_l2vpn_pw_cword(struct vty
*vty
, const char *negate
, const char *preference_str
)
1292 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1295 pw
->flags
|= F_PW_CWORD_CONF
;
1297 if (preference_str
[0] == 'e')
1298 pw
->flags
&= ~F_PW_CWORD_CONF
;
1300 pw
->flags
|= F_PW_CWORD_CONF
;
1303 ldp_config_apply(vty
, vty_conf
);
1305 return (CMD_SUCCESS
);
1309 ldp_vty_l2vpn_pw_nbr_addr(struct vty
*vty
, const char *negate
, const char *addr_str
)
1311 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1313 union ldpd_addr addr
;
1315 if (ldp_get_address(addr_str
, &af
, &addr
) == -1 ||
1316 bad_addr(af
, &addr
)) {
1317 vty_out (vty
, "%% Malformed address\n");
1318 return (CMD_WARNING_CONFIG_FAILED
);
1323 memset(&pw
->addr
, 0, sizeof(pw
->addr
));
1324 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1328 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1331 ldp_config_apply(vty
, vty_conf
);
1333 return (CMD_SUCCESS
);
1337 ldp_vty_l2vpn_pw_nbr_id(struct vty
*vty
, const char *negate
, struct in_addr lsr_id
)
1339 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1341 if (bad_addr_v4(lsr_id
)) {
1342 vty_out (vty
, "%% Malformed address\n");
1343 return (CMD_WARNING_CONFIG_FAILED
);
1347 pw
->lsr_id
.s_addr
= INADDR_ANY
;
1349 pw
->lsr_id
= lsr_id
;
1351 ldp_config_apply(vty
, vty_conf
);
1353 return (CMD_SUCCESS
);
1357 ldp_vty_l2vpn_pw_pwid(struct vty
*vty
, const char *negate
, long pwid
)
1359 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1366 ldp_config_apply(vty
, vty_conf
);
1368 return (CMD_SUCCESS
);
1372 ldp_vty_l2vpn_pw_pwstatus(struct vty
*vty
, const char *negate
)
1374 VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw
, pw
);
1377 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1379 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1381 ldp_config_apply(vty
, vty_conf
);
1383 return (CMD_SUCCESS
);
1387 iface_new_api(struct ldpd_conf
*conf
, const char *name
)
1389 const char *ifname
= name
;
1390 struct iface
*iface
;
1392 if (ldp_iface_is_configured(conf
, ifname
))
1395 iface
= if_new(name
);
1396 RB_INSERT(iface_head
, &conf
->iface_tree
, iface
);
1397 QOBJ_REG(iface
, iface
);
1402 iface_del_api(struct ldpd_conf
*conf
, struct iface
*iface
)
1405 RB_REMOVE(iface_head
, &conf
->iface_tree
, iface
);
1410 tnbr_new_api(struct ldpd_conf
*conf
, int af
, union ldpd_addr
*addr
)
1414 if (af
== AF_INET6
&& IN6_IS_SCOPE_EMBED(&addr
->v6
))
1417 if (tnbr_find(conf
, af
, addr
))
1420 tnbr
= tnbr_new(af
, addr
);
1421 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1422 RB_INSERT(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1423 QOBJ_REG(tnbr
, tnbr
);
1428 tnbr_del_api(struct ldpd_conf
*conf
, struct tnbr
*tnbr
)
1431 RB_REMOVE(tnbr_head
, &conf
->tnbr_tree
, tnbr
);
1436 nbrp_new_api(struct ldpd_conf
*conf
, struct in_addr lsr_id
)
1438 struct nbr_params
*nbrp
;
1440 if (nbr_params_find(conf
, lsr_id
))
1443 nbrp
= nbr_params_new(lsr_id
);
1444 RB_INSERT(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1445 QOBJ_REG(nbrp
, nbr_params
);
1450 nbrp_del_api(struct ldpd_conf
*conf
, struct nbr_params
*nbrp
)
1453 RB_REMOVE(nbrp_head
, &conf
->nbrp_tree
, nbrp
);
1458 l2vpn_new_api(struct ldpd_conf
*conf
, const char *name
)
1460 struct l2vpn
*l2vpn
;
1462 if (l2vpn_find(conf
, name
))
1465 l2vpn
= l2vpn_new(name
);
1466 l2vpn
->type
= L2VPN_TYPE_VPLS
;
1467 RB_INSERT(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1468 QOBJ_REG(l2vpn
, l2vpn
);
1473 l2vpn_del_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
)
1475 struct l2vpn_if
*lif
;
1476 struct l2vpn_pw
*pw
;
1478 while (!RB_EMPTY(l2vpn_if_head
, &l2vpn
->if_tree
)) {
1479 lif
= RB_ROOT(l2vpn_if_head
, &l2vpn
->if_tree
);
1482 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1485 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_tree
)) {
1486 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_tree
);
1489 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_tree
, pw
);
1492 while (!RB_EMPTY(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
)) {
1493 pw
= RB_ROOT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
);
1496 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1500 RB_REMOVE(l2vpn_head
, &conf
->l2vpn_tree
, l2vpn
);
1505 l2vpn_if_new_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
,
1508 struct l2vpn_if
*lif
;
1510 if (ldp_iface_is_configured(conf
, ifname
))
1513 lif
= l2vpn_if_new(l2vpn
, ifname
);
1514 RB_INSERT(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1515 QOBJ_REG(lif
, l2vpn_if
);
1520 l2vpn_if_del_api(struct l2vpn
*l2vpn
, struct l2vpn_if
*lif
)
1523 RB_REMOVE(l2vpn_if_head
, &l2vpn
->if_tree
, lif
);
1528 l2vpn_pw_new_api(struct ldpd_conf
*conf
, struct l2vpn
*l2vpn
,
1531 struct l2vpn_pw
*pw
;
1533 if (ldp_iface_is_configured(conf
, ifname
))
1536 pw
= l2vpn_pw_new(l2vpn
, ifname
);
1537 pw
->flags
= F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
;
1538 RB_INSERT(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);
1539 QOBJ_REG(pw
, l2vpn_pw
);
1544 l2vpn_pw_del_api(struct l2vpn
*l2vpn
, struct l2vpn_pw
*pw
)
1547 RB_REMOVE(l2vpn_pw_head
, &l2vpn
->pw_inactive_tree
, pw
);