- 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

@ -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: