Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 'exit' bug in config file processing, et al. (backport #13763) #13834

Merged
merged 7 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mgmt_be_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "lib/mgmt_be_client_clippy.c"

#define MGMTD_BE_CLIENT_DBG(fmt, ...) \
DEBUGD(&mgmt_dbg_be_client, "BE-CLIENT: %s:" fmt, __func__, \
DEBUGD(&mgmt_dbg_be_client, "BE-CLIENT: %s: " fmt, __func__, \
##__VA_ARGS__)
#define MGMTD_BE_CLIENT_ERR(fmt, ...) \
zlog_err("BE-CLIENT: %s: ERROR: " fmt, __func__, ##__VA_ARGS__)
Expand Down
5 changes: 1 addition & 4 deletions lib/mgmt_fe_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,15 @@ static int mgmt_fe_send_session_req(struct mgmt_fe_client *client,
{
Mgmtd__FeMessage fe_msg;
Mgmtd__FeSessionReq sess_req;
bool scok;

mgmtd__fe_session_req__init(&sess_req);
sess_req.create = create;
if (create) {
sess_req.id_case = MGMTD__FE_SESSION_REQ__ID_CLIENT_CONN_ID;
sess_req.client_conn_id = session->client_id;
scok = true;
} else {
sess_req.id_case = MGMTD__FE_SESSION_REQ__ID_SESSION_ID;
sess_req.session_id = session->session_id;
scok = false;
}

mgmtd__fe_message__init(&fe_msg);
Expand All @@ -146,7 +143,7 @@ static int mgmt_fe_send_session_req(struct mgmt_fe_client *client,
"Sending SESSION_REQ %s message for client-id %" PRIu64,
create ? "create" : "destroy", session->client_id);

return mgmt_fe_client_send_msg(client, &fe_msg, scok);
return mgmt_fe_client_send_msg(client, &fe_msg, true);
}

int mgmt_fe_send_lockds_req(struct mgmt_fe_client *client, uint64_t session_id,
Expand Down
2 changes: 1 addition & 1 deletion lib/mgmt_fe_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct mgmt_fe_client_cbs {
extern struct debug mgmt_dbg_fe_client;

#define MGMTD_FE_CLIENT_DBG(fmt, ...) \
DEBUGD(&mgmt_dbg_fe_client, "FE-CLIENT: %s:" fmt, __func__, \
DEBUGD(&mgmt_dbg_fe_client, "FE-CLIENT: %s: " fmt, __func__, \
##__VA_ARGS__)
#define MGMTD_FE_CLIENT_ERR(fmt, ...) \
zlog_err("FE-CLIENT: %s: ERROR: " fmt, __func__, ##__VA_ARGS__)
Expand Down
12 changes: 11 additions & 1 deletion lib/vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,14 @@ void vty_close(struct vty *vty)

vty->status = VTY_CLOSE;

/*
* If we reach here with pending config to commit we will be losing it
* so warn the user.
*/
if (vty->mgmt_num_pending_setcfg)
MGMTD_FE_CLIENT_ERR(
"vty closed, uncommitted config will be lost.");

if (mgmt_fe_client && vty->mgmt_session_id) {
MGMTD_FE_CLIENT_DBG("closing vty session");
mgmt_fe_destroy_client_session(mgmt_fe_client,
Expand Down Expand Up @@ -3445,7 +3453,9 @@ static void vty_mgmt_session_notify(struct mgmt_fe_client *client,
vty->mgmt_session_id = session_id;
} else {
vty->mgmt_session_id = 0;
vty_close(vty);
/* We may come here by way of vty_close() and short-circuits */
if (vty->status != VTY_CLOSE)
vty_close(vty);
}
}

Expand Down
2 changes: 1 addition & 1 deletion mgmtd/mgmt_be_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "mgmtd/mgmt_be_adapter.h"

#define MGMTD_BE_ADAPTER_DBG(fmt, ...) \
DEBUGD(&mgmt_debug_be, "BE-ADAPTER: %s:" fmt, __func__, ##__VA_ARGS__)
DEBUGD(&mgmt_debug_be, "BE-ADAPTER: %s: " fmt, __func__, ##__VA_ARGS__)
#define MGMTD_BE_ADAPTER_ERR(fmt, ...) \
zlog_err("BE-ADAPTER: %s: ERROR: " fmt, __func__, ##__VA_ARGS__)

Expand Down
2 changes: 1 addition & 1 deletion mgmtd/mgmt_ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "libyang/libyang.h"

#define MGMTD_DS_DBG(fmt, ...) \
DEBUGD(&mgmt_debug_ds, "%s:" fmt, __func__, ##__VA_ARGS__)
DEBUGD(&mgmt_debug_ds, "DS: %s: " fmt, __func__, ##__VA_ARGS__)
#define MGMTD_DS_ERR(fmt, ...) \
zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)

Expand Down
2 changes: 1 addition & 1 deletion mgmtd/mgmt_fe_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "mgmtd/mgmt_fe_adapter.h"

#define MGMTD_FE_ADAPTER_DBG(fmt, ...) \
DEBUGD(&mgmt_debug_fe, "FE-ADAPTER: %s:" fmt, __func__, ##__VA_ARGS__)
DEBUGD(&mgmt_debug_fe, "FE-ADAPTER: %s: " fmt, __func__, ##__VA_ARGS__)
#define MGMTD_FE_ADAPTER_ERR(fmt, ...) \
zlog_err("FE-ADAPTER: %s: ERROR: " fmt, __func__, ##__VA_ARGS__)

Expand Down
22 changes: 1 addition & 21 deletions mgmtd/mgmt_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "mgmtd/mgmt_txn.h"

#define MGMTD_TXN_DBG(fmt, ...) \
DEBUGD(&mgmt_debug_txn, "%s:" fmt, __func__, ##__VA_ARGS__)
DEBUGD(&mgmt_debug_txn, "TXN: %s: " fmt, __func__, ##__VA_ARGS__)
#define MGMTD_TXN_ERR(fmt, ...) \
zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)

Expand Down Expand Up @@ -2618,26 +2618,6 @@ int mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success,
return 0;
}

int mgmt_txn_send_commit_config_reply(uint64_t txn_id,
enum mgmt_result result,
const char *error_if_any)
{
struct mgmt_txn_ctx *txn;

txn = mgmt_txn_id2ctx(txn_id);
if (!txn)
return -1;

if (!txn->commit_cfg_req) {
MGMTD_TXN_ERR("NO commit in-progress txn-id: %" PRIu64
" session-id: %" PRIu64,
txn->txn_id, txn->session_id);
return -1;
}

return mgmt_txn_send_commit_cfg_reply(txn, result, error_if_any);
}

int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id,
Mgmtd__DatastoreId ds_id,
struct mgmt_ds_ctx *ds_ctx,
Expand Down
4 changes: 0 additions & 4 deletions mgmtd/mgmt_txn.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ extern int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id,
bool validate_only, bool abort,
bool implicit);

extern int mgmt_txn_send_commit_config_reply(uint64_t txn_id,
enum mgmt_result result,
const char *error_if_any);

/*
* Send get-config request to be processed later in transaction.
*
Expand Down
4 changes: 2 additions & 2 deletions staticd/static_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ struct event_loop *master;
struct mgmt_be_client *mgmt_be_client;

static struct frr_daemon_info staticd_di;

/* SIGHUP handler. */
static void sighup(void)
{
zlog_info("SIGHUP received");
vty_read_config(NULL, staticd_di.config_file, config_default);
zlog_info("SIGHUP received and ignored");
}

/* SIGINT / SIGTERM handler. */
Expand Down
6 changes: 6 additions & 0 deletions tests/topotests/mgmt_config/r1/early-end-zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
allow-external-route-update
end
ip multicast rpf-lookup-mode urib-only
end
ip table range 2 3
end
8 changes: 8 additions & 0 deletions tests/topotests/mgmt_config/r1/early-end.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ip route 15.1.0.0/24 101.0.0.2
end
ip route 15.2.0.0/24 101.0.0.2
end
ip route 15.3.0.0/24 101.0.0.2
end
ip route 15.4.0.0/24 101.0.0.2
end
7 changes: 7 additions & 0 deletions tests/topotests/mgmt_config/r1/early-end2-zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
conf t
allow-external-route-update
end
ip multicast rpf-lookup-mode urib-only
end
ip table range 2 3
end
9 changes: 9 additions & 0 deletions tests/topotests/mgmt_config/r1/early-end2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
conf t
ip route 16.1.0.0/24 101.0.0.2
end
ip route 16.2.0.0/24 101.0.0.2
end
ip route 16.3.0.0/24 101.0.0.2
end
ip route 16.4.0.0/24 101.0.0.2
end
6 changes: 6 additions & 0 deletions tests/topotests/mgmt_config/r1/early-exit-zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
allow-external-route-update
exit
ip multicast rpf-lookup-mode urib-only
exit
ip table range 2 3
exit
8 changes: 8 additions & 0 deletions tests/topotests/mgmt_config/r1/early-exit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ip route 13.1.0.0/24 101.0.0.2
exit
ip route 13.2.0.0/24 101.0.0.2
exit
ip route 13.3.0.0/24 101.0.0.2
exit
ip route 13.4.0.0/24 101.0.0.2
exit
7 changes: 7 additions & 0 deletions tests/topotests/mgmt_config/r1/early-exit2-zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
conf t
allow-external-route-update
exit
ip multicast rpf-lookup-mode urib-only
exit
ip table range 2 3
exit
9 changes: 9 additions & 0 deletions tests/topotests/mgmt_config/r1/early-exit2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
conf t
ip route 14.1.0.0/24 101.0.0.2
exit
ip route 14.2.0.0/24 101.0.0.2
exit
ip route 14.3.0.0/24 101.0.0.2
exit
ip route 14.4.0.0/24 101.0.0.2
exit
11 changes: 11 additions & 0 deletions tests/topotests/mgmt_config/r1/mgmtd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
debug northbound notifications
debug northbound libyang
debug northbound events
debug northbound callbacks
debug mgmt backend datastore frontend transaction
debug mgmt client backend
debug mgmt client frontend

ip route 12.0.0.0/24 101.0.0.2

ipv6 route 2012::/48 2101::2
8 changes: 8 additions & 0 deletions tests/topotests/mgmt_config/r1/normal-exit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ip route 13.1.0.0/24 101.0.0.2
exit
ip route 13.2.0.0/24 101.0.0.2
exit
ip route 13.3.0.0/24 101.0.0.2
exit
ip route 13.4.0.0/24 101.0.0.2
exit
3 changes: 3 additions & 0 deletions tests/topotests/mgmt_config/r1/one-exit-zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
allow-external-route-update
exit
ip multicast rpf-lookup-mode urib-only
3 changes: 3 additions & 0 deletions tests/topotests/mgmt_config/r1/one-exit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ip route 20.1.0.0/24 101.0.0.2
exit
ip route 20.2.0.0/24 101.0.0.2
4 changes: 4 additions & 0 deletions tests/topotests/mgmt_config/r1/one-exit2-zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
conf t
allow-external-route-update
exit
ip multicast rpf-lookup-mode urib-only
4 changes: 4 additions & 0 deletions tests/topotests/mgmt_config/r1/one-exit2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
conf t
ip route 21.1.0.0/24 101.0.0.2
exit
ip route 21.2.0.0/24 101.0.0.2
7 changes: 7 additions & 0 deletions tests/topotests/mgmt_config/r1/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
log timestamp precision 6
log file frr-r1.log debug

interface r1-eth0
ip address 101.0.0.1/24
ipv6 address 2101::1/64
exit
Loading