* Updated "evhtp" restconf mode

* No reliance on libevent or libevhtp, but on libssl >= 1.1 directly
    * Moved out event handling to clixon event handling
    * Moved out all ssl calls to clixon
  * New code MUST use libevhtp from https://github.com/clixon/clixon-libevhtp.git
    * This does NOT work: libevhtp from https://github.com/criticalstack/libevhtp.git
This commit is contained in:
Olof hagsand 2021-03-19 09:39:55 +01:00
parent 95a820c862
commit c7e7598e3b
26 changed files with 1506 additions and 944 deletions

View file

@ -117,6 +117,7 @@ static struct errvec EV[] = {
{"Routing demon error", OE_ROUTING},
{"XML error", OE_XML},
{"OpenSSL error", OE_SSL},
{"RESTCONF error", OE_RESTCONF},
{"Plugins", OE_PLUGIN},
{"Yang error", OE_YANG},
{"FATAL", OE_FATAL},

View file

@ -85,7 +85,7 @@ static FILE *_logfile = NULL;
* if CLICON_LOG_SYSLOG, then print logs to syslog
* You can do a combination of both
* @code
* clicon_log_init(h, __PROGRAM__, LOG_INFO, CLICON_LOG_STDERR);
* clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR);
* @endcode
*/
int

View file

@ -109,12 +109,14 @@ get_sock(int usock,
* @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] flags Socket flags Or:ed in with the socket(2) type parameter
* @param[out] sock Server socket (bound for accept)
*/
int
static int
create_socket(struct sockaddr *sa,
size_t sin_len,
int backlog,
int flags,
int *sock)
{
int retval = -1;
@ -128,7 +130,7 @@ create_socket(struct sockaddr *sa,
}
/* create inet socket */
if ((s = socket(sa->sa_family,
SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
SOCK_STREAM | SOCK_CLOEXEC | flags,
0)) < 0) {
clicon_err(OE_UNIX, errno, "socket");
goto done;
@ -141,6 +143,7 @@ create_socket(struct sockaddr *sa,
clicon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR");
goto done;
}
/* only bind ipv6, otherwise it may bind to ipv4 as well which is strange but seems default */
if (sa->sa_family == AF_INET6 &&
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
@ -151,7 +154,7 @@ create_socket(struct sockaddr *sa,
clicon_err(OE_UNIX, errno, "bind");
goto done;
}
if (listen(s, backlog) < 0){
if (listen(s, backlog ) < 0){
clicon_err(OE_UNIX, errno, "listen");
goto done;
}
@ -171,13 +174,15 @@ create_socket(struct sockaddr *sa,
* @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] flags Socket flags OR:ed in with the socket(2) type parameter
* @param[out] sock Server socket (bound for accept)
*/
int
static int
fork_netns_socket(const char *netns,
struct sockaddr *sa,
size_t sin_len,
int backlog,
int flags,
int *sock)
{
int retval = -1;
@ -220,7 +225,7 @@ fork_netns_socket(const char *netns,
#endif
close(fd);
/* Create socket in this namespace */
if (create_socket(sa, sin_len, backlog, &s) < 0)
if (create_socket(sa, sin_len, backlog, flags, &s) < 0)
return -1;
/* Send socket to parent */
if (send_sock(sp[1], s) < 0)
@ -247,6 +252,7 @@ fork_netns_socket(const char *netns,
* @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] flags Socket flags OR:ed in with the socket(2) type parameter
* @param[out] sock Server socket (bound for accept)
*/
int
@ -254,19 +260,20 @@ clixon_netns_socket(const char *netns,
struct sockaddr *sa,
size_t sin_len,
int backlog,
int flags,
int *sock)
{
int retval = -1;
clicon_debug(1, "%s", __FUNCTION__);
if (netns == NULL){
if (create_socket(sa, sin_len, backlog, sock) < 0)
if (create_socket(sa, sin_len, backlog, flags, sock) < 0)
goto done;
goto ok;
}
else {
#ifdef HAVE_SETNS
if (fork_netns_socket(netns, sa, sin_len, backlog, sock) < 0)
if (fork_netns_socket(netns, sa, sin_len, backlog, flags, sock) < 0)
goto done;
#else
clicon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns);

View file

@ -1419,7 +1419,7 @@ xml_child_rm(cxobj *xp,
/*! Remove this xml node from parent xml node. No freeing and node is new root
* @param[in] xc xml child node to be removed
* @retval 0 OK
* @retval -1
* @retval -1 Error
* @note you should not remove xchild in loop (unless yoy keep track of xprev)
*
* @see xml_child_rm Remove a child of a node