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

lib: msg: make short-circuit connections guaranteed #14576

Merged
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
17 changes: 8 additions & 9 deletions lib/mgmt_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ static void msg_client_sched_connect(struct msg_client *client,
&client->conn_retry_tmr);
}

static bool msg_client_connect_short_circuit(struct msg_client *client)
static int msg_client_connect_short_circuit(struct msg_client *client)
{
struct msg_conn *server_conn;
struct msg_server *server;
Expand All @@ -648,18 +648,17 @@ static bool msg_client_connect_short_circuit(struct msg_client *client)
break;
if (!server) {
MGMT_MSG_DBG(dbgtag,
"no short-circuit connection available for %s",
"no short-circuit server available yet for %s",
client->sopath);

return false;
return -1;
}

if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets)) {
MGMT_MSG_ERR(
&client->conn.mstate,
"socketpair failed trying to short-circuit connection on %s: %s",
client->sopath, safe_strerror(errno));
return false;
return -1;
}

/* client side */
Expand Down Expand Up @@ -687,7 +686,7 @@ static bool msg_client_connect_short_circuit(struct msg_client *client)
client->sopath, client->conn.mstate.idtag, client->conn.fd,
server_conn->mstate.idtag, server_conn->fd);

return true;
return 0;
}


Expand All @@ -697,11 +696,12 @@ static void msg_client_connect(struct msg_client *client)
struct msg_conn *conn = &client->conn;
const char *dbgtag = conn->debug ? conn->mstate.idtag : NULL;

if (!client->short_circuit_ok ||
!msg_client_connect_short_circuit(client))
if (!client->short_circuit_ok)
conn->fd =
mgmt_msg_connect(client->sopath, MSG_CONN_SEND_BUF_SIZE,
MSG_CONN_RECV_BUF_SIZE, dbgtag);
else if (msg_client_connect_short_circuit(client))
conn->fd = -1;
idryzhov marked this conversation as resolved.
Show resolved Hide resolved

if (conn->fd == -1)
/* retry the connection */
Expand Down Expand Up @@ -741,7 +741,6 @@ void msg_client_init(struct msg_client *client, struct event_loop *tm,
mgmt_msg_init(&conn->mstate, max_read_buf, max_write_buf, max_msg_sz,
idtag);

/* XXX maybe just have client kick this off */
/* Start trying to connect to server */
msg_client_sched_connect(client, 0);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/mgmt_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ struct msg_client {
extern void msg_client_cleanup(struct msg_client *client);

/*
* If `short_circuit_ok` is true, then the client-server connection will use a
* socketpair() rather than a unix-domain socket. This must be passed true if
* you wish to send messages short-circuit later.
*
* `notify_disconnect` is not called when the user `msg_client_cleanup` is
* called for a client which is currently connected. The socket is closed
* but there is no notification.
Expand Down
17 changes: 13 additions & 4 deletions mgmtd/mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,26 @@ void mgmt_init(void)
/* Initialize the MGMTD Frontend Adapter Module */
mgmt_fe_adapter_init(mm->master);

/* Initialize the CLI frontend client */
/*
* Initialize the CLI frontend client -- this queues an event for the
* client to short-circuit connect to the server (ourselves).
*/
vty_init_mgmt_fe();

/* MGMTD VTY commands installation. */
/*
* MGMTD VTY commands installation -- the frr lib code will queue an
* event to read the config files which needs to happen after the
* connect from above is made.
*/
mgmt_vty_init();

/*
* Initialize the MGMTD Backend Adapter Module
*
* We do this after the FE stuff so that we always read our config file
* prior to any BE connection.
* We do this after the FE stuff so that we have read our config file
* prior to any BE connection. Setting up the server will queue a
* "socket read" event to accept BE connections. So the code is counting
* on the above 2 events to run prior to any `accept` event from here.
*/
mgmt_be_adapter_init(mm->master);
}
Expand Down
9 changes: 8 additions & 1 deletion mgmtd/mgmt_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,14 @@ DEFPY(debug_mgmt, debug_mgmt_cmd,

static void mgmt_config_read_in(struct event *event)
{
mgmt_vty_read_configs();
if (vty_mgmt_fe_enabled())
mgmt_vty_read_configs();
else {
zlog_warn("%s: no connection to front-end server, retry in 1s",
__func__);
event_add_timer(mm->master, mgmt_config_read_in, NULL, 1,
&mgmt_daemon_info->read_in);
}
}

void mgmt_vty_init(void)
Expand Down
Loading