Commit 5bff3b38 authored by Marek Vavrusa's avatar Marek Vavrusa

conf: removed custom address fields, usage of sockaddr_storage

throughout

- it is as good as the sockaddr_t previously, but standard
- subnets are only needed for ACLs
- common way to print addresses (even AF_UNIX)
parent 783e34ff
......@@ -116,14 +116,14 @@ src/knot/server/dthreads.c
src/knot/server/dthreads.h
src/knot/server/journal.c
src/knot/server/journal.h
src/knot/server/net.c
src/knot/server/net.h
src/knot/server/notify.c
src/knot/server/notify.h
src/knot/server/rrl.c
src/knot/server/rrl.h
src/knot/server/server.c
src/knot/server/server.h
src/knot/server/socket.c
src/knot/server/socket.h
src/knot/server/tcp-handler.c
src/knot/server/tcp-handler.h
src/knot/server/udp-handler.c
......
......@@ -232,8 +232,8 @@ libknotd_la_SOURCES = \
knot/server/rrl.h \
knot/server/server.c \
knot/server/server.h \
knot/server/socket.c \
knot/server/socket.h \
knot/server/net.c \
knot/server/net.h \
knot/server/tcp-handler.c \
knot/server/tcp-handler.h \
knot/server/udp-handler.c \
......
......@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <unistd.h>
#include "common/sockaddr.h"
#include "common/errcode.h"
......@@ -38,6 +37,15 @@ int sockaddr_len(const struct sockaddr_storage *ss)
}
}
int sockaddr_cmp(const struct sockaddr_storage *k1, const struct sockaddr_storage *k2)
{
if (k1->ss_family != k2->ss_family) {
return (int)k1->ss_family - (int)k2->ss_family;
}
return memcmp(k1, k2, sockaddr_len(k1));
}
int sockaddr_set(struct sockaddr_storage *ss, int family, const char *straddr, int port)
{
if (ss == NULL || straddr == NULL) {
......@@ -118,7 +126,7 @@ int sockaddr_tostr(const struct sockaddr_storage *ss, char *buf, size_t maxlen)
sprintf(&buf[written], "%d", port);
}
return KNOT_ERROR;
return KNOT_EOK;
}
int sockaddr_port(const struct sockaddr_storage *ss)
......
......@@ -38,6 +38,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdint.h>
#include <unistd.h>
/* Subnet maximum prefix length. */
#define IPV4_PREFIXLEN 32
......@@ -56,6 +57,13 @@
*/
int sockaddr_len(const struct sockaddr_storage *ss);
/*!
* \brief Compare address storages.
*
* \return like memcmp(3)
*/
int sockaddr_cmp(const struct sockaddr_storage *k1, const struct sockaddr_storage *k2);
/*!
* \brief Set address and port.
*
......
......@@ -64,7 +64,7 @@ static conf_log_map_t *this_logmap = 0;
#define SET_INT(out, in, name) SET_NUM(out, in, 0, INT_MAX, name);
#define SET_SIZE(out, in, name) SET_NUM(out, in, 0, SIZE_MAX, name);
static void conf_init_iface(void *scanner, char* ifname, int port)
static void conf_init_iface(void *scanner, char* ifname)
{
this_iface = malloc(sizeof(conf_iface_t));
if (this_iface == NULL) {
......@@ -73,12 +73,11 @@ static void conf_init_iface(void *scanner, char* ifname, int port)
}
memset(this_iface, 0, sizeof(conf_iface_t));
this_iface->name = ifname;
this_iface->port = port;
}
static void conf_start_iface(void *scanner, char* ifname)
{
conf_init_iface(scanner, ifname, -1);
conf_init_iface(scanner, ifname);
add_tail(&new_config->ifaces, &this_iface->n);
++new_config->ifaces_count;
}
......@@ -128,7 +127,7 @@ static void conf_remote_set_via(void *scanner, char *item) {
if (!found) {
cf_error(scanner, "interface '%s' is not defined", item);
} else {
sockaddr_set(&this_remote->via, found->family, found->address, 0);
memcpy(&this_remote->via, &found->addr, sizeof(struct sockaddr_storage));
}
}
......@@ -237,25 +236,26 @@ static bool set_remote_or_group(void *scanner, char *name,
static void conf_acl_item_install(void *scanner, conf_iface_t *found)
{
// silently skip duplicates
conf_remote_t *remote;
WALK_LIST (remote, *this_list) {
if (remote->remote == found) {
return;
}
}
// additional check for transfers
if ((this_list == &this_zone->acl.xfr_in ||
this_list == &this_zone->acl.notify_out) && found->port == 0)
if ((this_list == &this_zone->acl.xfr_in || this_list == &this_zone->acl.notify_out)
&& sockaddr_port(&found->addr) == 0)
{
cf_error(scanner, "remote specified for XFR/IN or "
"NOTIFY/OUT needs to have valid port!");
return;
}
// silently skip duplicates
conf_remote_t *remote;
WALK_LIST (remote, *this_list) {
if (remote->remote == found) {
return;
}
}
// add into the list
remote = malloc(sizeof(conf_remote_t));
......@@ -510,60 +510,34 @@ interface_start:
interface:
| interface PORT NUM ';' {
if (this_iface->port > 0) {
cf_error(scanner, "only one port definition is allowed in interface section\n");
if (this_iface->addr.ss_family == AF_UNSPEC) {
cf_error(scanner, "can't set port number before interface address\n");
} else {
SET_UINT16(this_iface->port, $3.i, "port");
sockaddr_port_set(&this_iface->addr, $3.i);
}
}
| interface ADDRESS IPA ';' {
if (this_iface->address != 0) {
cf_error(scanner, "only one address is allowed in interface section\n");
} else {
this_iface->address = $3.t;
this_iface->family = AF_INET;
}
sockaddr_set(&this_iface->addr, AF_INET, $3.t, CONFIG_DEFAULT_PORT);
free($3.t);
}
| interface ADDRESS IPA '@' NUM ';' {
if (this_iface->address != 0) {
cf_error(scanner, "only one address is allowed in interface section\n");
} else {
this_iface->address = $3.t;
this_iface->family = AF_INET;
if (this_iface->port > 0) {
cf_error(scanner, "only one port definition is allowed in interface section\n");
} else {
SET_UINT16(this_iface->port, $5.i, "port");
}
}
sockaddr_set(&this_iface->addr, AF_INET, $3.t, $5.i);
free($3.t);
}
| interface ADDRESS IPA6 ';' {
if (this_iface->address != 0) {
cf_error(scanner, "only one address is allowed in interface section\n");
} else {
this_iface->address = $3.t;
this_iface->family = AF_INET6;
}
sockaddr_set(&this_iface->addr, AF_INET6, $3.t, CONFIG_DEFAULT_PORT);
free($3.t);
}
| interface ADDRESS IPA6 '@' NUM ';' {
if (this_iface->address != 0) {
cf_error(scanner, "only one address is allowed in interface section\n");
} else {
this_iface->address = $3.t;
this_iface->family = AF_INET6;
if (this_iface->port > 0) {
cf_error(scanner, "only one port definition is allowed in interface section\n");
} else {
SET_UINT16(this_iface->port, $5.i, "port");
}
}
sockaddr_set(&this_iface->addr, AF_INET, $3.t, $5.i);
free($3.t);
}
;
interfaces:
INTERFACES '{'
| interfaces interface_start '{' interface '}' {
if (this_iface->address == 0) {
if (this_iface->addr.ss_family == AF_UNSPEC) {
cf_error(scanner, "interface '%s' has no defined address", this_iface->name);
}
}
......@@ -713,75 +687,41 @@ remote_start:
remote:
| remote PORT NUM ';' {
if (this_remote->port != 0) {
cf_error(scanner, "only one port definition is allowed in remote section\n");
if (this_remote->addr.ss_family == AF_UNSPEC) {
cf_error(scanner, "can't set port number before interface address\n");
} else {
SET_UINT16(this_remote->port, $3.i, "port");
sockaddr_port_set(&this_remote->addr, $3.i);
}
}
| remote ADDRESS IPA ';' {
if (this_remote->address != 0) {
cf_error(scanner, "only one address is allowed in remote section\n");
} else {
this_remote->address = $3.t;
this_remote->prefix = IPV4_PREFIXLEN;
this_remote->family = AF_INET;
}
sockaddr_set(&this_remote->addr, AF_INET, $3.t, CONFIG_DEFAULT_PORT);
this_remote->prefix = IPV4_PREFIXLEN;
free($3.t);
}
| remote ADDRESS IPA '/' NUM ';' {
sockaddr_set(&this_remote->addr, AF_INET, $3.t, 0);
SET_NUM(this_remote->prefix, $5.i, 0, IPV4_PREFIXLEN, "prefix length");
free($3.t);
}
| remote ADDRESS IPA '/' NUM ';' {
if (this_remote->address != 0) {
cf_error(scanner, "only one address is allowed in remote section\n");
} else {
this_remote->address = $3.t;
this_remote->family = AF_INET;
SET_NUM(this_remote->prefix, $5.i, 0, IPV4_PREFIXLEN, "prefix length");
}
}
| remote ADDRESS IPA '@' NUM ';' {
if (this_remote->address != 0) {
cf_error(scanner, "only one address is allowed in remote section\n");
} else {
this_remote->address = $3.t;
this_remote->family = AF_INET;
this_remote->prefix = IPV4_PREFIXLEN;
if (this_remote->port != 0) {
cf_error(scanner, "only one port definition is allowed in remote section\n");
} else {
SET_UINT16(this_remote->port, $5.i, "port");
}
}
sockaddr_set(&this_remote->addr, AF_INET, $3.t, $5.i);
this_remote->prefix = IPV4_PREFIXLEN;
free($3.t);
}
| remote ADDRESS IPA6 ';' {
if (this_remote->address != 0) {
cf_error(scanner, "only one address is allowed in remote section\n");
} else {
this_remote->address = $3.t;
this_remote->family = AF_INET6;
this_remote->prefix = IPV6_PREFIXLEN;
}
sockaddr_set(&this_remote->addr, AF_INET6, $3.t, CONFIG_DEFAULT_PORT);
this_remote->prefix = IPV6_PREFIXLEN;
free($3.t);
}
| remote ADDRESS IPA6 '/' NUM ';' {
sockaddr_set(&this_remote->addr, AF_INET6, $3.t, 0);
SET_NUM(this_remote->prefix, $5.i, 0, IPV6_PREFIXLEN, "prefix length");
free($3.t);
}
| remote ADDRESS IPA6 '/' NUM ';' {
if (this_remote->address != 0) {
cf_error(scanner, "only one address is allowed in remote section\n");
} else {
this_remote->address = $3.t;
this_remote->family = AF_INET6;
SET_NUM(this_remote->prefix, $5.i, 0, IPV6_PREFIXLEN, "prefix length");
}
}
| remote ADDRESS IPA6 '@' NUM ';' {
if (this_remote->address != 0) {
cf_error(scanner, "only one address is allowed in remote section\n");
} else {
this_remote->address = $3.t;
this_remote->family = AF_INET6;
this_remote->prefix = IPV6_PREFIXLEN;
if (this_remote->port != 0) {
cf_error(scanner, "only one port definition is allowed in remote section\n");
} else {
SET_UINT16(this_remote->port, $5.i, "port");
}
}
sockaddr_set(&this_remote->addr, AF_INET6, $3.t, $5.i);
this_remote->prefix = IPV6_PREFIXLEN;
free($3.t);
}
| remote KEY TEXT ';' {
if (this_remote->key != 0) {
......@@ -808,7 +748,7 @@ remote:
remotes:
REMOTES '{'
| remotes remote_start '{' remote '}' {
if (this_remote->address == 0) {
if (this_remote->addr.ss_family == AF_UNSPEC) {
cf_error(scanner, "remote '%s' has no defined address", this_remote->name);
}
}
......@@ -1081,7 +1021,7 @@ log: LOG { new_config->logs_count = 0; } '{' log_start log_end
;
ctl_listen_start:
LISTEN_ON { conf_init_iface(scanner, NULL, -1); }
LISTEN_ON { conf_init_iface(scanner, NULL); }
;
ctl_allow_start:
......@@ -1093,17 +1033,16 @@ ctl_allow_start:
control:
CONTROL '{' { new_config->ctl.have = true; }
| control ctl_listen_start '{' interface '}' {
if (this_iface->address == 0) {
if (this_iface->addr.ss_family == AF_UNSPEC) {
cf_error(scanner, "control interface has no defined address");
} else {
new_config->ctl.iface = this_iface;
}
}
| control ctl_listen_start TEXT ';' {
this_iface->address = $3.t;
this_iface->family = AF_UNIX;
this_iface->port = 0;
sockaddr_set(&this_iface->addr, AF_UNIX, $3.t, 0);
new_config->ctl.iface = this_iface;
free($3.t);
}
| control ctl_allow_start '{' zone_acl '}'
| control ctl_allow_start zone_acl_list
......
......@@ -217,36 +217,36 @@ static int conf_process(conf_t *conf)
conf->max_conn_reply = CONFIG_REPLY_WD;
}
// Postprocess interfaces
conf_iface_t *cfg_if = NULL;
WALK_LIST(cfg_if, conf->ifaces) {
if (cfg_if->port <= 0) {
cfg_if->port = CONFIG_DEFAULT_PORT;
}
}
/* Default interface. */
conf_iface_t *ctl_if = conf->ctl.iface;
if (!conf->ctl.have && ctl_if == NULL) {
ctl_if = malloc(sizeof(conf_iface_t));
memset(ctl_if, 0, sizeof(conf_iface_t));
ctl_if->family = AF_UNIX;
ctl_if->address = strdup("knot.sock");
sockaddr_set(&ctl_if->addr, AF_UNIX, "knot.sock", 0);
conf->ctl.iface = ctl_if;
}
/* Control interface. */
if (ctl_if) {
if (ctl_if->family == AF_UNIX) {
ctl_if->address = conf_abs_path(conf->rundir,
ctl_if->address);
if (ctl_if->addr.ss_family == AF_UNIX) {
char *full_path = malloc(SOCKADDR_STRLEN);
memset(full_path, 0, SOCKADDR_STRLEN);
sockaddr_tostr(&ctl_if->addr, full_path, SOCKADDR_STRLEN);
/* Convert to absolute path. */
full_path = conf_abs_path(conf->rundir, full_path);
if(full_path) {
sockaddr_set(&ctl_if->addr, AF_UNIX, full_path, 0);
free(full_path);
}
/* Check for ACL existence. */
if (!EMPTY_LIST(conf->ctl.allow)) {
log_server_warning("Control 'allow' statement "
"does not affect UNIX sockets.\n");
}
} else if (ctl_if->port <= 0) {
ctl_if->port = REMOTE_DPORT;
} else if (sockaddr_port(&ctl_if->addr) <= 0) {
sockaddr_port_set(&ctl_if->addr, REMOTE_DPORT);
}
}
......@@ -437,9 +437,7 @@ static int conf_process(conf_t *conf)
conf_remote_t *r = NULL;
WALK_LIST(r, conf->ctl.allow) {
conf_iface_t *i = r->remote;
struct sockaddr_storage ss;
sockaddr_set(&ss, i->family, i->address, 0);
acl_insert(conf->ctl.acl, &ss, i->prefix, i->key);
acl_insert(conf->ctl.acl, &i->addr, i->prefix, i->key);
}
return ret;
......@@ -463,9 +461,8 @@ void __attribute__ ((constructor)) conf_init()
/* Create default interface. */
conf_iface_t * iface = malloc(sizeof(conf_iface_t));
memset(iface, 0, sizeof(conf_iface_t));
sockaddr_set(&iface->addr, AF_INET, "127.0.0.1", CONFIG_DEFAULT_PORT);
iface->name = strdup("localhost");
iface->address = strdup("127.0.0.1");
iface->port = CONFIG_DEFAULT_PORT;
add_tail(&s_config->ifaces, &iface->n);
++s_config->ifaces_count;
......@@ -1024,7 +1021,6 @@ void conf_free_iface(conf_iface_t *iface)
}
free(iface->name);
free(iface->address);
free(iface);
}
......
......@@ -66,13 +66,11 @@
*/
typedef struct conf_iface_t {
node_t n;
char *name; /*!< Internal name for the interface. */
char *address; /*!< IP (IPv4/v6) address for this interface */
unsigned prefix; /*!< IP subnet prefix. */
int port; /*!< Port number for this interface */
int family; /*!< Address family. */
knot_tsig_key_t *key; /*!< TSIG key (only valid for remotes). */
struct sockaddr_storage via; /*!< Used for remotes to specify qry endpoint.*/
char *name; /*!< Internal name for the interface. */
knot_tsig_key_t *key; /*!< TSIG key (only applic for remotes). */
unsigned prefix; /*!< IP subnet prefix (only applic for remotes). */
struct sockaddr_storage addr; /*!< Interface address. */
struct sockaddr_storage via; /*!< Used for remotes to specify qry endpoint.*/
} conf_iface_t;
/*!
......
......@@ -32,7 +32,6 @@
#include "knot/ctl/remote.h"
#include "knot/conf/conf.h"
#include "knot/zone/zone-load.h"
#include "knot/server/socket.h"
#include "knot/server/tcp-handler.h"
#include "libknot/packet/wire.h"
#include "knot/server/zone-load.h"
......@@ -184,7 +183,7 @@ static int cmd_remote(const char *cmd, uint16_t rrt, int argc, char *argv[])
/* Check remote address. */
conf_iface_t *r = conf()->ctl.iface;
if (!r || !r->address) {
if (!r || r->addr.ss_family == AF_UNSPEC) {
log_server_error("No remote address for '%s' configured.\n",
cmd);
return 1;
......@@ -234,28 +233,39 @@ static int cmd_remote(const char *cmd, uint16_t rrt, int argc, char *argv[])
dbg_server("%s: sending query size %zu\n", __func__, pkt->size);
/* Send query. */
int s = socket_create(r->family, SOCK_STREAM, 0);
int conn_state = socket_connect(s, r->family, r->address, r->port);
if (conn_state != KNOT_EOK || tcp_send(s, pkt->wire, pkt->size) <= 0) {
char portstr[32] = { '\0' };
if (r->family != AF_UNIX)
snprintf(portstr, sizeof(portstr), "@%d", r->port);
log_server_error("Couldn't connect to remote host "
"%s%s\n", r->address, portstr);
rc = 1;
/* Connect to remote. */
char addr_str[SOCKADDR_STRLEN] = {0};
sockaddr_tostr(&r->addr, addr_str, sizeof(addr_str));
int s = net_connected_socket(SOCK_STREAM, &r->addr, &r->via);
if (s < 0) {
log_server_error("Couldn't connect to remote host '%s'.\n", addr_str);
knot_pkt_free(&pkt);
return 1;
}
/* Wait for availability. */
struct pollfd pfd = { s, POLLOUT, 0 };
poll(&pfd, 1, conf()->max_conn_reply);
/* Send and free packet. */
int ret = tcp_send(s, pkt->wire, pkt->size);
knot_pkt_free(&pkt);
/* Evaluate and wait for reply. */
if (ret <= 0) {
log_server_error("Couldn't connect to remote host '%s'.\n", addr_str);
return 1;
}
/* Wait for reply. */
if (rc == 0) {
int ret = KNOT_EOK;
while (ret == KNOT_EOK) {
ret = cmd_remote_reply(s);
if (ret != KNOT_EOK && ret != KNOT_ECONN) {
log_server_warning("Remote command reply: %s\n",
knot_strerror(ret));
rc = 1;
}
ret = KNOT_EOK;
while (ret == KNOT_EOK) {
ret = cmd_remote_reply(s);
if (ret != KNOT_EOK && ret != KNOT_ECONN) {
log_server_warning("Remote command reply: %s\n",
knot_strerror(ret));
rc = 1;
}
}
......@@ -265,8 +275,7 @@ static int cmd_remote(const char *cmd, uint16_t rrt, int argc, char *argv[])
}
/* Close connection. */
socket_close(s);
knot_pkt_free(&pkt);
close(s);
return rc;
}
......@@ -530,25 +539,26 @@ int main(int argc, char **argv)
/* Override from command line. */
if (r_addr) {
free(ctl_if->address);
ctl_if->address = strdup(r_addr);
ctl_if->family = AF_INET;
/* Check for v6 address. */
if (strchr(r_addr, ':'))
ctl_if->family = AF_INET6;
int family = AF_INET;
if (strchr(r_addr, ':')) {
family = AF_INET6;
}
/* Is a valid UNIX socket or at least contains slash ? */
struct stat st;
bool has_slash = strchr(r_addr, '/') != NULL;
bool is_file = stat(r_addr, &st) == 0;
if (has_slash || (is_file && S_ISSOCK(st.st_mode))) {
ctl_if->family = AF_UNIX;
r_port = 0; /* Override. */
family = AF_UNIX;
}
sockaddr_set(&ctl_if->addr, family, r_addr, sockaddr_port(&ctl_if->addr));
}
if (r_port > 0) {
sockaddr_port_set(&ctl_if->addr, r_port);
}
if (r_port > -1) ctl_if->port = r_port;
/* Verbose mode. */
if (has_flag(flags, F_VERBOSE)) {
......
......@@ -21,7 +21,7 @@
#include "common/fdset.h"
#include "knot/knot.h"
#include "knot/conf/conf.h"
#include "knot/server/socket.h"
#include "knot/server/net.h"
#include "knot/server/tcp-handler.h"
#include "knot/server/zones.h"
#include "libknot/packet/wire.h"
......@@ -399,71 +399,77 @@ static int remote_senderr(int c, uint8_t *qbuf, size_t buflen)
int remote_bind(conf_iface_t *desc)
{
if (!desc) {
return -1;
if (desc == NULL) {
return KNOT_EINVAL;
}
/* Create new socket. */
int s = socket_create(desc->family, SOCK_STREAM, 0);
if (s < 0) {
log_server_error("Couldn't create socket for remote "
"control interface - %s", knot_strerror(s));
return KNOT_ERROR;
}
char addr_str[SOCKADDR_STRLEN] = {0};
sockaddr_tostr(&desc->addr, addr_str, sizeof(addr_str));
log_server_info("Binding remote control interface to '%s'.\n", addr_str);
/* Bind to interface and start listening. */
/* Create new socket. */
mode_t old_umask = umask(KNOT_CTL_SOCKET_UMASK);
int r = socket_bind(s, desc->family, desc->address, desc->port);
int sock = net_bound_socket(SOCK_STREAM, &desc->addr);
umask(old_umask);
if (r == KNOT_EOK) {
r = socket_listen(s, TCP_BACKLOG_SIZE);
if (sock < 0) {
return sock;
}
if (r != KNOT_EOK) {
log_server_error("Could not bind to remote control interface.\n");
socket_close(s);
return r;
/* Start listening. */
int ret = listen(sock, TCP_BACKLOG_SIZE);
if (ret < 0) {
log_server_error("Could not bind to '%s'.\n", addr_str);
close(sock);
return ret;
}
return s;
return sock;
}
int remote_unbind(int r)
int remote_unbind(conf_iface_t *desc, int sock)
{
if (r < 0) {
if (desc == NULL || sock < 0) {
return KNOT_EINVAL;
}
return socket_close(r);
/* Remove control socket file. */
if (desc->addr.ss_family == AF_UNIX) {
char addr_str[SOCKADDR_STRLEN] = {0};
sockaddr_tostr(&desc->addr, addr_str, sizeof(addr_str));
unlink(addr_str);
}
return close(sock);
}
int remote_poll(int r)
int remote_poll(int sock)
{
/* Wait for events. */
fd_set rfds;
FD_ZERO(&rfds);
if (r > -1) {
FD_SET(r, &rfds);
if (sock > -1) {
FD_SET(sock, &rfds);
} else {
r = -1; /* Make sure n == r + 1 == 0 */
sock = -1; /* Make sure n == r + 1 == 0 */
}
return fdset_pselect(r + 1, &rfds, NULL, NULL, NULL, NULL);
return fdset_pselect(sock + 1, &rfds, NULL, NULL, NULL, NULL);
}
int remote_recv(int r, struct sockaddr *a, uint8_t* buf, size_t *buflen)
int remote_recv(int sock, struct sockaddr *addr, uint8_t* buf, size_t *buflen)
{
int c = tcp_accept(r);
int c = tcp_accept(sock);
if (c < 0) {
dbg_server("remote: couldn't accept incoming connection\n");
return c;
}
/* Receive data. */
int n = tcp_recv(c, buf, *buflen, a);
int n = tcp_recv(c, buf, *buflen, addr);
*buflen = n;
if (n <= 0) {
dbg_server("remote: failed to receive data\n");
socket_close(c);
close(c);
return KNOT_ECONNREFUSED;
}
......@@ -518,9 +524,9 @@ failed:
return ret;
}
int remote_answer(int fd, server_t *s, knot_pkt_t *pkt)
int remote_answer(int sock, server_t *s, knot_pkt_t *pkt)
{
if (fd < 0 || s == NULL || pkt == NULL) {
if (sock < 0 || s == NULL || pkt == NULL) {
return KNOT_EINVAL;
}
......@@ -583,12 +589,12 @@ int remote_answer(int fd, server_t *s, knot_pkt_t *pkt)
unsigned p = 0;
size_t chunk = 16384;
for (; p + chunk < args->rlen; p += chunk) {
remote_send_chunk(fd, pkt, args->resp + p, chunk);
remote_send_chunk(sock, pkt, args->resp + p, chunk);
}
unsigned r = args->rlen - p;
if (r > 0) {
remote_send_chunk(fd, pkt, args->resp + p, r);
remote_send_chunk(sock, pkt, args->resp + p, r);
}
free(args);
......@@ -620,7 +626,7 @@ int remote_process(server_t *s, conf_iface_t *ctl_if, int sock,
/* Parse packet and answer if OK. */
int ret = remote_parse(pkt);
if (ret == KNOT_EOK && ctl_if->family != AF_UNIX) {
if (ret == KNOT_EOK && ctl_if->addr.ss_family != AF_UNIX) {
/* Check ACL list. */
char addr_str[SOCKADDR_STRLEN] = {0};
......@@ -675,7 +681,7 @@ int remote_process(server_t *s, conf_iface_t *ctl_if, int sock,
finish:
knot_pkt_free(&pkt);
socket_close(client);
close(client);
return ret;
}
......
......@@ -38,6 +38,7 @@
/*!
* \brief Bind RC interface according to configuration.
*