- 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

@ -9,6 +9,6 @@
/*
* Prototypes
*/
int clixon_netns_socket(const char *netns, struct sockaddr *sa, size_t sin_len, int backlog, int flags, int *sock);
int clixon_netns_socket(const char *netns, struct sockaddr *sa, size_t sin_len, int backlog, int flags, const char *addrstr, int *sock);
#endif /* _CLIXON_NETNS_H_ */

View file

@ -541,7 +541,7 @@ xmldb_readfile(clicon_handle h,
continue;
/* Add old/deleted yangs not present in the loaded/running yangspec. */
if ((ymod = yang_find_module_by_namespace_revision(yspec, ns, rev)) == NULL){
/* Append it */
/* YANG Module not found, look for it and append if found */
if (yang_spec_parse_module(h, name, rev, yspec) < 0){
/* Special case: file-not-found errors */
if (clicon_suberrno == ENOENT){

View file

@ -112,6 +112,7 @@ get_sock(int usock,
* @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len
* @param[in] backlog Listen backlog, queie of pending connections
* @param[in] flags Socket flags Or:ed in with the socket(2) type parameter
* @param[in] addrstr Address string for debug
* @param[out] sock Server socket (bound for accept)
*/
static int
@ -119,6 +120,7 @@ create_socket(struct sockaddr *sa,
size_t sin_len,
int backlog,
int flags,
const char *addrstr,
int *sock)
{
int retval = -1;
@ -153,7 +155,8 @@ create_socket(struct sockaddr *sa,
goto done;
}
if (bind(s, sa, sin_len) == -1) {
clicon_err(OE_UNIX, errno, "bind");
/* Note may be ignored in upper layer by checking for EADDRNOTAVAIL, see eg restconf_openssl_init */
clicon_err(OE_UNIX, errno, "bind(%s)", addrstr);
goto done;
}
if (listen(s, backlog ) < 0){
@ -176,8 +179,9 @@ create_socket(struct sockaddr *sa,
* @param[in] netns Network namespace
* @param[in] sa Socketaddress
* @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len
* @param[in] backlog Listen backlog, queie of pending connections
* @param[in] backlog Listen backlog, queue of pending connections
* @param[in] flags Socket flags OR:ed in with the socket(2) type parameter
* @param[in] addrstr Address string for debug
* @param[out] sock Server socket (bound for accept)
*/
static int
@ -186,13 +190,14 @@ fork_netns_socket(const char *netns,
size_t sin_len,
int backlog,
int flags,
const char *addrstr,
int *sock)
{
int retval = -1;
int sp[2] = {-1, -1};
pid_t child;
int status = 0;
char nspath[MAXPATHLEN]; /* Path to namespace file */
int retval = -1;
int sp[2] = {-1, -1};
pid_t child;
int status = 0;
char nspath[MAXPATHLEN]; /* Path to namespace file */
struct stat st;
clicon_debug(1, "%s %s", __FUNCTION__, netns);
@ -228,7 +233,7 @@ fork_netns_socket(const char *netns,
#endif
close(fd);
/* Create socket in this namespace */
if (create_socket(sa, sin_len, backlog, flags, &s) < 0)
if (create_socket(sa, sin_len, backlog, flags, addrstr, &s) < 0)
return -1;
/* Send socket to parent */
if (send_sock(sp[1], s) < 0)
@ -257,6 +262,7 @@ fork_netns_socket(const char *netns,
* @param[in] sa_len Length of sa. Tecynicaliyu to be independent of sockaddr sa_len
* @param[in] backlog Listen backlog, queie of pending connections
* @param[in] flags Socket flags OR:ed in with the socket(2) type parameter
* @param[in] addrstr Address string for debug
* @param[out] sock Server socket (bound for accept)
*/
int
@ -265,19 +271,20 @@ clixon_netns_socket(const char *netns,
size_t sin_len,
int backlog,
int flags,
const char *addrstr,
int *sock)
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
if (netns == NULL){
if (create_socket(sa, sin_len, backlog, flags, sock) < 0)
if (create_socket(sa, sin_len, backlog, flags, addrstr, sock) < 0)
goto done;
goto ok;
}
else {
#ifdef HAVE_SETNS
if (fork_netns_socket(netns, sa, sin_len, backlog, flags, sock) < 0)
if (fork_netns_socket(netns, sa, sin_len, backlog, flags, addrstr, sock) < 0)
goto done;
#else
clicon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns);

View file

@ -828,7 +828,9 @@ yang_parse_find_match(clicon_handle h,
module);
xc = NULL;
while ((xc = xml_child_each(x, xc, CX_ELMNT)) != NULL) {
if (strcmp(xml_name(xc), "CLICON_YANG_DIR") != 0)
/* Skip if not yang dir */
if (strcmp(xml_name(xc), "CLICON_YANG_DIR") != 0 &&
strcmp(xml_name(xc), "CLICON_YANG_MAIN_DIR") != 0)
continue;
dir = xml_body(xc);
/* get all matching files in this directory */
@ -1425,6 +1427,7 @@ yang_spec_parse_module(clicon_handle h,
/* Do not load module if it already exists */
if (yang_find_module_by_name_revision(yspec, name, revision) != NULL)
goto ok;
/* Find a yang module and parse it and all its submodules */
if (yang_parse_module(h, name, revision, yspec) == NULL)
goto done;
if (yang_parse_post(h, yspec, modmin) < 0)