Skip to content

Commit b15c391

Browse files
author
Volodymyr Huti
committed
eigrp: reimplement passive-interface [default] command
Maintain a vector of mappings [if_name -> if_passive]. Otherwise, if topo is not already convereged, configuration does not apply, since iface is missing from the iface list. Fixes: #11301 Signed-off-by: Volodymyr Huti <v.huti@vyos.io>
1 parent a95b83c commit b15c391

8 files changed

+264
-56
lines changed

eigrpd/eigrp_cli.c

+47-5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ void eigrp_cli_show_router_id(struct vty *vty, const struct lyd_node *dnode,
120120
vty_out(vty, " eigrp router-id %s\n", router_id);
121121
}
122122

123+
/*
124+
* XPath: /frr-ripd:ripd/instance/passive-default
125+
*/
126+
DEFPY_YANG(
127+
eigrp_passive_default,
128+
eigrp_passive_default_cmd,
129+
"[no] passive-interface default",
130+
NO_STR
131+
"Suppress routing updates on an interface\n"
132+
"default for all interfaces\n")
133+
{
134+
nb_cli_enqueue_change(vty, "./passive-default", NB_OP_MODIFY,
135+
no ? "false" : "true");
136+
137+
return nb_cli_apply_changes(vty, NULL);
138+
}
139+
123140
/*
124141
* XPath: /frr-eigrpd:eigrpd/instance/passive-interface
125142
*/
@@ -131,12 +148,19 @@ DEFPY_YANG(
131148
"Suppress routing updates on an interface\n"
132149
"Interface to suppress on\n")
133150
{
134-
if (no)
135-
nb_cli_enqueue_change(vty, "./passive-interface",
136-
NB_OP_DESTROY, ifname);
137-
else
151+
bool passive_default =
152+
yang_dnode_get_bool(vty->candidate_config->dnode, "%s%s",
153+
VTY_CURR_XPATH, "/passive-default");
154+
155+
if (passive_default) {
156+
nb_cli_enqueue_change(vty, "./non-passive-interface",
157+
no ? NB_OP_CREATE : NB_OP_DESTROY,
158+
ifname);
159+
} else {
138160
nb_cli_enqueue_change(vty, "./passive-interface",
139-
NB_OP_CREATE, ifname);
161+
no ? NB_OP_DESTROY : NB_OP_CREATE,
162+
ifname);
163+
}
140164

141165
return nb_cli_apply_changes(vty, NULL);
142166
}
@@ -150,6 +174,15 @@ void eigrp_cli_show_passive_interface(struct vty *vty,
150174
vty_out(vty, " passive-interface %s\n", ifname);
151175
}
152176

177+
void eigrp_cli_show_non_passive_interface(struct vty *vty,
178+
const struct lyd_node *dnode,
179+
bool show_defaults)
180+
{
181+
const char *ifname = yang_dnode_get_string(dnode, NULL);
182+
183+
vty_out(vty, "no passive-interface %s\n", ifname);
184+
}
185+
153186
/*
154187
* XPath: /frr-eigrpd:eigrpd/instance/active-time
155188
*/
@@ -826,6 +859,14 @@ void eigrp_cli_show_keychain(struct vty *vty, const struct lyd_node *dnode,
826859
keychain);
827860
}
828861

862+
void eigrpd_cli_show_passive_default(struct vty *vty, const struct lyd_node *dnode,
863+
bool show_defaults)
864+
{
865+
if (!yang_dnode_get_bool(dnode, NULL))
866+
vty_out(vty, " no");
867+
868+
vty_out(vty, " passive-interface default\n");
869+
}
829870

830871
/*
831872
* CLI installation procedures.
@@ -865,6 +906,7 @@ eigrp_cli_init(void)
865906
install_element(EIGRP_NODE, &eigrp_router_id_cmd);
866907
install_element(EIGRP_NODE, &no_eigrp_router_id_cmd);
867908
install_element(EIGRP_NODE, &eigrp_passive_interface_cmd);
909+
install_element(EIGRP_NODE, &eigrp_passive_default_cmd);
868910
install_element(EIGRP_NODE, &eigrp_timers_active_cmd);
869911
install_element(EIGRP_NODE, &no_eigrp_timers_active_cmd);
870912
install_element(EIGRP_NODE, &eigrp_variance_cmd);

eigrpd/eigrp_cli.h

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ extern void eigrp_cli_show_authentication(struct vty *vty,
6161
extern void eigrp_cli_show_keychain(struct vty *vty,
6262
const struct lyd_node *dnode,
6363
bool show_defaults);
64+
void eigrpd_cli_show_passive_default(struct vty *vty,
65+
const struct lyd_node *dnode,
66+
bool show_defaults);
67+
void eigrp_cli_show_non_passive_interface(struct vty *vty,
68+
const struct lyd_node *dnode,
69+
bool show_defaults);
6470
extern void eigrp_cli_init(void);
6571

6672
#endif /*EIGRP_CLI_H_ */

eigrpd/eigrp_interface.c

+106-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "network.h"
2626
#include "command.h"
2727
#include "stream.h"
28-
#include "log.h"
28+
#include "zlog.h"
2929
#include "keychain.h"
3030
#include "vrf.h"
3131

@@ -44,6 +44,9 @@
4444
#include "eigrpd/eigrp_metric.h"
4545

4646
DEFINE_MTYPE_STATIC(EIGRPD, EIGRP_IF, "EIGRP interface");
47+
DEFINE_MTYPE_STATIC(EIGRPD, EIGRP_IF_STRING, "EIGRP Interface String");
48+
49+
static void eigrp_passive_interface_apply(struct interface *ifp);
4750

4851
int eigrp_if_new_hook(struct interface *ifp)
4952
{
@@ -114,6 +117,7 @@ static int eigrp_ifp_create(struct interface *ifp)
114117

115118
ei->params.type = eigrp_default_iftype(ifp);
116119

120+
eigrp_passive_interface_apply(ifp);
117121
eigrp_if_update(ifp);
118122

119123
return 0;
@@ -154,6 +158,7 @@ static int eigrp_ifp_up(struct interface *ifp)
154158
return 0;
155159
}
156160

161+
eigrp_passive_interface_apply(ifp);
157162
eigrp_if_up(ifp->info);
158163

159164
return 0;
@@ -368,6 +373,106 @@ bool eigrp_if_is_passive(struct eigrp_interface *ei)
368373
return true;
369374
}
370375

376+
377+
/* Utility function for looking up passive interface settings. */
378+
static int eigrp_passive_nondefault_lookup(struct eigrp *eigrp, const char *ifname)
379+
{
380+
unsigned int i;
381+
char *str;
382+
383+
for (i = 0; i < vector_active(eigrp->passive_nondefault); i++)
384+
if ((str = vector_slot(eigrp->passive_nondefault, i)) != NULL)
385+
if (strcmp(str, ifname) == 0)
386+
return i;
387+
return -1;
388+
}
389+
390+
static void eigrp_passive_interface_apply(struct interface *ifp)
391+
{
392+
struct eigrp_interface *ei = ifp->info;
393+
struct eigrp *eigrp;
394+
int ifidx;
395+
396+
if (!ei || !ei->eigrp)
397+
return;
398+
399+
eigrp = ei->eigrp;
400+
ifidx = (eigrp_passive_nondefault_lookup(eigrp, ifp->name));
401+
ei->params.passive_interface = (ifidx < 0) ? eigrp->passive_interface_default
402+
: !eigrp->passive_interface_default;
403+
if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE))
404+
zlog_debug("interface %s: passive = %d", ifp->name,
405+
ei->params.passive_interface);
406+
407+
}
408+
409+
static void eigrp_passive_interface_apply_all(struct eigrp *eigrp)
410+
{
411+
struct interface *ifp;
412+
struct vrf *vrf;
413+
414+
vrf = vrf_lookup_by_id(eigrp->vrf_id);
415+
FOR_ALL_INTERFACES (vrf, ifp)
416+
eigrp_passive_interface_apply(ifp);
417+
}
418+
419+
420+
/* Passive interface. */
421+
int eigrp_passive_nondefault_set(struct eigrp *eigrp, const char *ifname)
422+
{
423+
if (eigrp_passive_nondefault_lookup(eigrp, ifname) >= 0)
424+
/*
425+
* Don't return an error, this can happen after changing
426+
* 'passive-default'.
427+
*/
428+
return NB_OK;
429+
430+
vector_set(eigrp->passive_nondefault,
431+
XSTRDUP(MTYPE_EIGRP_IF_STRING, ifname));
432+
433+
eigrp_passive_interface_apply_all(eigrp);
434+
435+
return NB_OK;
436+
}
437+
438+
int eigrp_passive_nondefault_unset(struct eigrp *eigrp, const char *ifname)
439+
{
440+
int i;
441+
char *str;
442+
443+
i = eigrp_passive_nondefault_lookup(eigrp, ifname);
444+
if (i < 0)
445+
/*
446+
* Don't return an error, this can happen after changing
447+
* 'passive-default'.
448+
*/
449+
return NB_OK;
450+
451+
str = vector_slot(eigrp->passive_nondefault, i);
452+
XFREE(MTYPE_EIGRP_IF_STRING, str);
453+
vector_unset(eigrp->passive_nondefault, i);
454+
455+
eigrp_passive_interface_apply_all(eigrp);
456+
457+
return NB_OK;
458+
}
459+
460+
461+
/* Free all configured eigrp passive-interface settings. */
462+
void eigrp_passive_nondefault_clean(struct eigrp *eigrp)
463+
{
464+
unsigned int i;
465+
char *str;
466+
467+
for (i = 0; i < vector_active(eigrp->passive_nondefault); i++)
468+
if ((str = vector_slot(eigrp->passive_nondefault, i)) != NULL) {
469+
XFREE(MTYPE_EIGRP_IF_STRING, str);
470+
vector_slot(eigrp->passive_nondefault, i) = NULL;
471+
}
472+
eigrp_passive_interface_apply_all(eigrp);
473+
}
474+
475+
371476
void eigrp_if_set_multicast(struct eigrp_interface *ei)
372477
{
373478
if (!eigrp_if_is_passive(ei)) {

eigrpd/eigrp_interface.h

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ extern void eigrp_if_free(struct eigrp_interface *, int);
3232
extern int eigrp_if_down(struct eigrp_interface *);
3333
extern void eigrp_if_stream_unset(struct eigrp_interface *);
3434

35+
extern void eigrp_passive_nondefault_clean(struct eigrp *);
36+
extern int eigrp_passive_nondefault_set(struct eigrp *, const char *);
37+
extern int eigrp_passive_nondefault_unset(struct eigrp *, const char *);
38+
3539
extern struct eigrp_interface *eigrp_if_lookup_by_local_addr(struct eigrp *,
3640
struct interface *,
3741
struct in_addr);

0 commit comments

Comments
 (0)