netconf client was limited to 8K byte messages. Now limit is 2^32

This commit is contained in:
Olof hagsand 2017-09-13 22:30:35 +02:00
parent 4d82d4f6ea
commit 624b949b3f
11 changed files with 157 additions and 68 deletions

View file

@ -65,7 +65,9 @@
#include "clixon_yang.h"
#include "clixon_plugin.h"
#include "clixon_options.h"
#if CONFIGFILE_XML
#include "clixon_xml.h"
#endif
/*
* clicon_option_dump
* Print registry on file. For debugging.
@ -107,28 +109,56 @@ static int
clicon_option_readfile(clicon_hash_t *copt, const char *filename)
{
struct stat st;
char opt[1024], val[1024];
char line[1024], *cp;
FILE *f;
int retval = -1;
#if !CONFIGFILE_XML
char opt[1024];
char val[1024];
char line[1024];
char *cp;
#endif
FILE *f = NULL;
int retval = -1;
if (filename == NULL || !strlen(filename)){
clicon_err(OE_UNIX, 0, "Not specified");
return -1;
goto done;
}
if (stat(filename, &st) < 0){
clicon_err(OE_UNIX, errno, "%s", filename);
return -1;
goto done;
}
if (!S_ISREG(st.st_mode)){
clicon_err(OE_UNIX, 0, "%s is not a regular file", filename);
return -1;
goto done;
}
if ((f = fopen(filename, "r")) == NULL) {
clicon_err(OE_UNIX, errno, "configure file: %s", filename);
return -1;
}
clicon_debug(2, "Reading config file %s", __FUNCTION__, filename);
#if CONFIGFILE_XML
{
int fd = fileno(f);
cxobj *xt = NULL;
cxobj *x = NULL;
if (clicon_xml_parse_file(fd, &xt, "</clicon>") < 0)
goto done;
// yspec should be clicon/yang
// if (xml_apply(xt, CX_ELMNT, xml_spec_populate, yspec) < 0)
//goto done;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
fprintf(stderr, "%s\n", xml_name(x));
#if 0
if ((hash_add(copt,
opt,
val,
strlen(val)+1)) == NULL)
goto done;
#endif
}
}
#else
while (fgets(line, sizeof(line), f)) {
if ((cp = strchr(line, '\n')) != NULL) /* strip last \n */
*cp = '\0';
@ -141,11 +171,13 @@ clicon_option_readfile(clicon_hash_t *copt, const char *filename)
opt,
val,
strlen(val)+1)) == NULL)
goto catch;
goto done;
}
#endif
retval = 0;
catch:
fclose(f);
done:
if (f)
fclose(f);
return retval;
}
@ -217,7 +249,7 @@ clicon_option_sanity(clicon_hash_t *copt)
goto done;
}
if (!hash_lookup(copt, "CLICON_BACKEND_DIR")){
clicon_err(OE_UNIX, 0, "CLICON_BACKEND_PIDFILE not defined in config file");
clicon_err(OE_UNIX, 0, "CLICON_BACKEND_DIR not defined in config file");
goto done;
}
if (!hash_lookup(copt, "CLICON_NETCONF_DIR")){

View file

@ -130,8 +130,8 @@ struct clicon_msg *
clicon_msg_encode(char *format, ...)
{
va_list args;
int xmllen;
int len;
uint32_t xmllen;
uint32_t len;
struct clicon_msg *msg = NULL;
int hdrlen = sizeof(*msg);
@ -146,7 +146,7 @@ clicon_msg_encode(char *format, ...)
}
memset(msg, 0, len);
/* hdr */
msg->op_len = htons(len);
msg->op_len = htonl(len);
/* body */
va_start(args, format);
@ -267,7 +267,7 @@ msg_dump(struct clicon_msg *msg)
memset(buf2, 0, sizeof(buf2));
snprintf(buf2, sizeof(buf2), "%s:", __FUNCTION__);
for (i=0; i<ntohs(msg->op_len); i++){
for (i=0; i<ntohl(msg->op_len); i++){
snprintf(buf, sizeof(buf), "%s%02x", buf2, ((char*)msg)[i]&0xff);
if ((i+1)%32==0){
clicon_debug(2, buf);
@ -294,13 +294,13 @@ clicon_msg_send(int s,
int retval = -1;
clicon_debug(2, "%s: send msg len=%d",
__FUNCTION__, ntohs(msg->op_len));
__FUNCTION__, ntohl(msg->op_len));
if (debug > 2)
msg_dump(msg);
if (atomicio((ssize_t (*)(int, void *, size_t))write,
s, msg, ntohs(msg->op_len)) < 0){
s, msg, ntohl(msg->op_len)) < 0){
clicon_err(OE_CFG, errno, "%s", __FUNCTION__);
clicon_log(LOG_WARNING, "%s: write: %s len:%d msg:%s", __FUNCTION__,
clicon_log(LOG_WARNING, "%s: write: %s len:%u msg:%s", __FUNCTION__,
strerror(errno), ntohs(msg->op_len), msg->op_body);
goto done;
}
@ -309,7 +309,6 @@ clicon_msg_send(int s,
return retval;
}
/*! Receive a CLICON message
*
* XXX: timeout? and signals?
@ -333,9 +332,9 @@ clicon_msg_rcv(int s,
int retval = -1;
struct clicon_msg hdr;
int hlen;
int len2;
uint32_t len2;
sigfn_t oldhandler;
uint16_t mlen;
uint32_t mlen;
*eof = 0;
if (0)
@ -354,7 +353,7 @@ clicon_msg_rcv(int s,
clicon_err(OE_CFG, errno, "%s: header too short (%d)", __FUNCTION__, hlen);
goto done;
}
mlen = ntohs(hdr.op_len);
mlen = ntohl(hdr.op_len);
clicon_debug(2, "%s: rcv msg len=%d",
__FUNCTION__, mlen);
if ((*msg = (struct clicon_msg *)malloc(mlen)) == NULL){
@ -533,17 +532,17 @@ clicon_rpc(int s,
int
send_msg_reply(int s,
char *data,
uint16_t datalen)
uint32_t datalen)
{
int retval = -1;
struct clicon_msg *reply = NULL;
uint16_t len;
uint32_t len;
len = sizeof(*reply) + datalen;
if ((reply = (struct clicon_msg *)malloc(len)) == NULL)
goto done;
memset(reply, 0, len);
reply->op_len = htons(len);
reply->op_len = htonl(len);
if (datalen > 0)
memcpy(reply->op_body, data, datalen);
if (clicon_msg_send(s, reply) < 0)

View file

@ -1080,7 +1080,7 @@ FSM(char *tag,
* @retval -1 Error with clicon_err called
*
* @code
* cxobj *xt;
* cxobj *xt = NULL;
* clicon_xml_parse_file(0, &xt, "</clicon>");
* xml_free(xt);
* @endcode