- Restconf bind: continue with other sockets if bind fails, print address on log

- Multi-yang: Look in CLICON_YANG_MAIN_DIR, not only CLICON_MAIN_DIRs for old yangs
  - Backend -q quit option enhanced for multi-yang case
This commit is contained in:
Olof hagsand 2021-04-13 16:23:20 +02:00
parent 5af7ea9b38
commit c43e216d67
13 changed files with 343 additions and 82 deletions

View file

@ -208,6 +208,14 @@ startup_common(clicon_handle h,
if ((ret = xmldb_get0(h, db, YB_MODULE, NULL, "/", 0, &xt, msdiff, &xerr)) < 0)
goto done;
if (ret == 0){ /* ret should not be 0 */
/* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */
if (clicon_quit_upgrade_get(h) == 1){
xml_print(stderr, xerr);
clicon_err(OE_XML, 0, "invalid configuration before upgrade");
exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding
* See similar clause below
*/
}
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
goto done;
goto fail;
@ -236,10 +244,10 @@ startup_common(clicon_handle h,
if (ret == 0)
goto fail;
}
/* Print upgraded db: -q backend switch */
/* Print upgraded db: -q backend switch for debugging/ showing upgraded config only */
if (clicon_quit_upgrade_get(h) == 1){
/* bind yang */
if ((ret = (xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 1)){
if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 1){
if (ret == 0){
/* invalid */
clicon_err(OE_XML, EFAULT, "invalid configuration");
@ -249,7 +257,6 @@ startup_common(clicon_handle h,
xml_print(stderr, xret);
clicon_err(OE_XML, 0, "%s: YANG binding error", __func__);
}
} /* sort yang */
else if (xml_sort_recurse(xt) < 0) {
clicon_err(OE_XML, EFAULT, "Yang sort error");

View file

@ -682,7 +682,7 @@ compare_xmls(cxobj *xc1,
close(fd);
if ((fd = mkstemp(filename2)) < 0){
clicon_err(OE_UNDEF, errno, "mkstemp: %s", strerror (errno));
clicon_err(OE_UNDEF, errno, "mkstemp: %s", strerror(errno));
goto done;
}
if ((f = fdopen(fd, "w")) == NULL)

View file

@ -645,7 +645,7 @@ restconf_config_init(clicon_handle h,
/*! Create and bind restconf socket
*
* @param[in] netns0 Network namespace, special value "default" is same as NULL
* @param[in] addr Address as string, eg "0.0.0.0", "::"
* @param[in] addrstr Address as string, eg "0.0.0.0", "::"
* @param[in] addrtype One of inet:ipv4-address or inet:ipv6-address
* @param[in] port TCP port
* @param[in] backlog Listen backlog, queie of pending connections
@ -654,7 +654,7 @@ restconf_config_init(clicon_handle h,
*/
int
restconf_socket_init(const char *netns0,
const char *addr,
const char *addrstr,
const char *addrtype,
uint16_t port,
int backlog,
@ -668,7 +668,7 @@ restconf_socket_init(const char *netns0,
size_t sin_len;
const char *netns;
clicon_debug(1, "%s %s %s %s %hu", __FUNCTION__, netns0, addrtype, addr, port);
clicon_debug(1, "%s %s %s %s %hu", __FUNCTION__, netns0, addrtype, addrstr, port);
/* netns default -> NULL */
if (netns0 != NULL && strcmp(netns0, "default")==0)
netns = NULL;
@ -679,14 +679,14 @@ restconf_socket_init(const char *netns0,
sin6.sin6_port = htons(port);
sin6.sin6_family = AF_INET6;
inet_pton(AF_INET6, addr, &sin6.sin6_addr);
inet_pton(AF_INET6, addrstr, &sin6.sin6_addr);
sa = (struct sockaddr *)&sin6;
}
else if (strcmp(addrtype, "inet:ipv4-address") == 0) {
sin_len = sizeof(struct sockaddr_in);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = inet_addr(addr);
sin.sin_addr.s_addr = inet_addr(addrstr);
sa = (struct sockaddr *)&sin;
}
@ -694,7 +694,7 @@ restconf_socket_init(const char *netns0,
clicon_err(OE_XML, EINVAL, "Unexpected addrtype: %s", addrtype);
return -1;
}
if (clixon_netns_socket(netns, sa, sin_len, backlog, flags, ss) < 0)
if (clixon_netns_socket(netns, sa, sin_len, backlog, flags, addrstr, ss) < 0)
goto done;
clicon_debug(1, "%s ss=%d", __FUNCTION__, *ss);
retval = 0;

View file

@ -84,7 +84,7 @@ char *restconf_uripath(clicon_handle h);
int restconf_drop_privileges(clicon_handle h, char *user);
int restconf_authentication_cb(clicon_handle h, void *req, int pretty, restconf_media media_out);
int restconf_config_init(clicon_handle h, cxobj *xrestconf);
int restconf_socket_init(const char *netns0, const char *addr, const char *addrtype, uint16_t port, int backlog, int flags, int *ss);
int restconf_socket_init(const char *netns0, const char *addrstr, const char *addrtype, uint16_t port, int backlog, int flags, int *ss);
int restconf_socket_extract(clicon_handle h, cxobj *xs, cvec *nsc, char **namespace, char **address, char **addrtype, uint16_t *port, uint16_t *ssl);
#endif /* _RESTCONF_LIB_H_ */

View file

@ -1338,7 +1338,6 @@ restconf_clixon_backend(clicon_handle h,
goto done;
}
/*! Per-socket openssl inits
* @param[in] h Clicon handle
* @param[in] xs XML config of single restconf socket
@ -1492,8 +1491,13 @@ restconf_openssl_init(clicon_handle h,
if (xpath_vec(xrestconf, nsc, "socket", &vec, &veclen) < 0)
goto done;
for (i=0; i<veclen; i++){
if (openssl_init_socket(h, vec[i], nsc) < 0)
goto done;
if (openssl_init_socket(h, vec[i], nsc) < 0){
/* Bind errors are ignored, proceed with next after log */
if (clicon_errno == OE_UNIX && clicon_suberrno == EADDRNOTAVAIL)
clicon_err_reset();
else
goto done;
}
}
retval = 1;
done: