Skip to content

Commit

Permalink
bfdd: actually return validation error instead of logging
Browse files Browse the repository at this point in the history
Before:
```
(config-bfd)# peer fe80::a00:27ff:fea2:5803 multihop local-address fe80::a00:27ff:fea2:5802
% Configuration failed.

Error type: validation
```

After:
```
(config-bfd)# peer fe80::a00:27ff:fea2:5803 multihop local-address fe80::a00:27ff:fea2:5802
% Configuration failed.

Error type: validation
Error description: When using link-local you must specify an interface
```

Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov committed Mar 3, 2021
1 parent 4cce733 commit 5e4d0fb
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions bfdd/bfdd_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,35 @@ static void bfd_session_get_key(bool mhop, const struct lyd_node *dnode,
gen_bfd_key(bk, &psa, &lsa, mhop, ifname, vrfname);
}

static int bfd_session_create(enum nb_event event, const struct lyd_node *dnode,
union nb_resource *resource, bool mhop)
static int bfd_session_create(struct nb_cb_create_args *args, bool mhop)
{
struct bfd_session *bs;
const char *ifname;
struct bfd_key bk;
struct prefix p;

switch (event) {
switch (args->event) {
case NB_EV_VALIDATE:
/*
* When `dest-addr` is IPv6 and link-local we must
* require interface name, otherwise we can't figure
* which interface to use to send the packets.
*/
yang_dnode_get_prefix(&p, dnode, "./dest-addr");
yang_dnode_get_prefix(&p, args->dnode, "./dest-addr");

ifname = yang_dnode_get_string(dnode, "./interface");
ifname = yang_dnode_get_string(args->dnode, "./interface");

if (p.family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)
&& strcmp(ifname, "*") == 0) {
zlog_warn(
"%s: when using link-local you must specify an interface.",
__func__);
snprintf(
args->errmsg, args->errmsg_len,
"When using link-local you must specify an interface");
return NB_ERR_VALIDATION;
}
break;

case NB_EV_PREPARE:
bfd_session_get_key(mhop, dnode, &bk);
bfd_session_get_key(mhop, args->dnode, &bk);
bs = bfd_key_lookup(bk);

/* This session was already configured by another daemon. */
Expand All @@ -93,14 +92,14 @@ static int bfd_session_create(enum nb_event event, const struct lyd_node *dnode,
SET_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG);
bs->refcount++;

resource->ptr = bs;
args->resource->ptr = bs;
break;
}

bs = bfd_session_new();

/* Fill the session key. */
bfd_session_get_key(mhop, dnode, &bs->key);
bfd_session_get_key(mhop, args->dnode, &bs->key);

/* Set configuration flags. */
bs->refcount = 1;
Expand All @@ -110,23 +109,23 @@ static int bfd_session_create(enum nb_event event, const struct lyd_node *dnode,
if (bs->key.family == AF_INET6)
SET_FLAG(bs->flags, BFD_SESS_FLAG_IPV6);

resource->ptr = bs;
args->resource->ptr = bs;
break;

case NB_EV_APPLY:
bs = resource->ptr;
bs = args->resource->ptr;

/* Only attempt to registrate if freshly allocated. */
if (bs->discrs.my_discr == 0 && bs_registrate(bs) == NULL)
return NB_ERR_RESOURCE;

nb_running_set_entry(dnode, bs);
nb_running_set_entry(args->dnode, bs);
break;

case NB_EV_ABORT:
bs = resource->ptr;
bs = args->resource->ptr;
if (bs->refcount <= 1)
bfd_session_free(resource->ptr);
bfd_session_free(bs);
break;
}

Expand Down Expand Up @@ -474,8 +473,7 @@ int bfdd_bfd_profile_desired_echo_transmission_interval_modify(
*/
int bfdd_bfd_sessions_single_hop_create(struct nb_cb_create_args *args)
{
return bfd_session_create(args->event, args->dnode, args->resource,
false);
return bfd_session_create(args, false);
}

int bfdd_bfd_sessions_single_hop_destroy(struct nb_cb_destroy_args *args)
Expand Down Expand Up @@ -759,8 +757,7 @@ int bfdd_bfd_sessions_single_hop_desired_echo_transmission_interval_modify(
*/
int bfdd_bfd_sessions_multi_hop_create(struct nb_cb_create_args *args)
{
return bfd_session_create(args->event, args->dnode, args->resource,
true);
return bfd_session_create(args, true);
}

int bfdd_bfd_sessions_multi_hop_destroy(struct nb_cb_destroy_args *args)
Expand Down

0 comments on commit 5e4d0fb

Please sign in to comment.