diff options
Diffstat (limited to 'lib/vty.c')
| -rw-r--r-- | lib/vty.c | 62 |
1 files changed, 53 insertions, 9 deletions
@@ -345,8 +345,17 @@ int vty_out(struct vty *vty, const char *format, ...) case VTY_SHELL_SERV: case VTY_FILE: default: + vty->vty_buf_size_accumulated += strlen(filtered); /* print without crlf replacement */ buffer_put(vty->obuf, (uint8_t *)filtered, strlen(filtered)); + /* For every chunk of memory, we invoke vtysh_flush where we + * put the data of collective vty->obuf Linked List items on the + * socket and free the vty->obuf data. + */ + if (vty->vty_buf_size_accumulated >= VTY_MAX_INTERMEDIATE_FLUSH) { + vty->vty_buf_size_accumulated = 0; + vtysh_flush(vty); + } break; } @@ -390,6 +399,21 @@ int vty_json_no_pretty(struct vty *vty, struct json_object *json) return vty_json_helper(vty, json, JSON_C_TO_STRING_NOSLASHESCAPE); } + +void vty_json_key(struct vty *vty, const char *key, bool *first_key) +{ + vty_out(vty, "%s\"%s\":", *first_key ? "{" : ",", key); + *first_key = false; +} + +void vty_json_close(struct vty *vty, bool first_key) +{ + if (first_key) + /* JSON was not opened */ + vty_out(vty, "{"); + vty_out(vty, "}\n"); +} + void vty_json_empty(struct vty *vty, struct json_object *json) { json_object *jsonobj = json; @@ -2103,6 +2127,8 @@ static void vtysh_accept(struct event *thread) int client_len; struct sockaddr_un client; struct vty *vty; + int ret = 0; + uint32_t sndbufsize = VTY_SEND_BUF_MAX; vty_event_serv(VTYSH_SERV, vtyserv); @@ -2126,6 +2152,20 @@ static void vtysh_accept(struct event *thread) close(sock); return; } + + /* + * Increasing the SEND socket buffer size so that the socket can hold + * before sending it to VTY shell. + */ + ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&sndbufsize, + sizeof(sndbufsize)); + if (ret < 0) { + flog_err(EC_LIB_SOCKET, + "Cannot set socket %d send buffer size, %s", sock, + safe_strerror(errno)); + close(sock); + return; + } set_cloexec(sock); #ifdef VTYSH_DEBUG @@ -2212,6 +2252,7 @@ static int vtysh_flush(struct vty *vty) vty_close(vty); return -1; case BUFFER_EMPTY: + vty->vty_buf_size_accumulated = 0; break; } return 0; @@ -3487,7 +3528,7 @@ static void vty_mgmt_server_connected(struct mgmt_fe_client *client, /* Start or stop listening for vty connections */ if (connected) - frr_vty_serv_start(); + frr_vty_serv_start(true); else frr_vty_serv_stop(); } @@ -3576,8 +3617,9 @@ static void vty_mgmt_set_config_result_notified( vty_out(vty, "%s\n", errmsg_if_any); } else { debug_fe_client("SET_CONFIG request for client 0x%" PRIx64 - " req-id %" PRIu64 " was successfull", - client_id, req_id); + " req-id %" PRIu64 " was successfull%s%s", + client_id, req_id, errmsg_if_any ? ": " : "", + errmsg_if_any ?: ""); } if (implicit_commit) { @@ -3609,8 +3651,9 @@ static void vty_mgmt_commit_config_result_notified( vty_out(vty, "%s\n", errmsg_if_any); } else { debug_fe_client("COMMIT_CONFIG request for client 0x%" PRIx64 - " req-id %" PRIu64 " was successfull", - client_id, req_id); + " req-id %" PRIu64 " was successfull%s%s", + client_id, req_id, errmsg_if_any ? ": " : "", + errmsg_if_any ?: ""); if (errmsg_if_any) vty_out(vty, "MGMTD: %s\n", errmsg_if_any); } @@ -3641,8 +3684,9 @@ static int vty_mgmt_get_data_result_notified( } debug_fe_client("GET_DATA request succeeded, client 0x%" PRIx64 - " req-id %" PRIu64, - client_id, req_id); + " req-id %" PRIu64 "%s%s", + client_id, req_id, errmsg_if_any ? ": " : "", + errmsg_if_any ?: ""); if (req_id != mgmt_last_req_id) { mgmt_last_req_id = req_id; @@ -3885,7 +3929,7 @@ static int vty_mgmt_error_notified(struct mgmt_fe_client *client, const char *cname = mgmt_fe_client_name(client); if (!vty->mgmt_req_pending_cmd) { - debug_fe_client("Erorr with no pending command: %d returned for client %s 0x%" PRIx64 + debug_fe_client("Error with no pending command: %d returned for client %s 0x%" PRIx64 " session-id %" PRIu64 " req-id %" PRIu64 "error-str %s", error, cname, client_id, session_id, req_id, @@ -3896,7 +3940,7 @@ static int vty_mgmt_error_notified(struct mgmt_fe_client *client, return CMD_WARNING; } - debug_fe_client("Erorr %d returned for client %s 0x%" PRIx64 + debug_fe_client("Error %d returned for client %s 0x%" PRIx64 " session-id %" PRIu64 " req-id %" PRIu64 "error-str %s", error, cname, client_id, session_id, req_id, errstr); |
