Commit 5e1e83ce authored by Daniel Salzman's avatar Daniel Salzman

conf: allow multiple address and via with one remote

parent 5730745e
......@@ -787,7 +787,8 @@ int conf_user_txn(
conf_remote_t conf_remote_txn(
conf_t *conf,
namedb_txn_t *txn,
conf_val_t *id)
conf_val_t *id,
size_t index)
{
assert(id != NULL && id->item != NULL);
assert(id->item->type == YP_TSTR ||
......@@ -799,18 +800,24 @@ conf_remote_t conf_remote_txn(
conf_val_t rundir_val = conf_get_txn(conf, txn, C_SRV, C_RUNDIR);
char *rundir = conf_abs_path(&rundir_val, NULL);
// Get remote address.
// Get indexed remote address.
conf_val_t val = conf_id_get_txn(conf, txn, C_RMT, C_ADDR, id);
if (val.code != KNOT_EOK) {
CONF_LOG(LOG_ERR, "invalid remote");
free(rundir);
return out;
for (size_t i = 0; val.code == KNOT_EOK && i < index; i++) {
conf_val_next(&val);
}
// Index overflow causes empty socket.
out.addr = conf_addr(&val, rundir);
// Get outgoing address (optional).
// Get outgoing address if family matches (optional).
val = conf_id_get_txn(conf, txn, C_RMT, C_VIA, id);
out.via = conf_addr(&val, rundir);
while (val.code == KNOT_EOK) {
struct sockaddr_storage via = conf_addr(&val, rundir);
if (via.ss_family == out.addr.ss_family) {
out.via = conf_addr(&val, rundir);
break;
}
conf_val_next(&val);
}
// Get TSIG key (optional).
conf_val_t key_id = conf_id_get_txn(conf, txn, C_RMT, C_KEY, id);
......
......@@ -315,13 +315,15 @@ static inline int conf_user(
conf_remote_t conf_remote_txn(
conf_t *conf,
namedb_txn_t *txn,
conf_val_t *id
conf_val_t *id,
size_t index
);
static inline conf_remote_t conf_remote(
conf_t *conf,
conf_val_t *id)
conf_val_t *id,
size_t index)
{
return conf_remote_txn(conf, &conf->read_txn, id);
return conf_remote_txn(conf, &conf->read_txn, id, index);
}
......
......@@ -125,8 +125,8 @@ static const yp_item_t desc_control[] = {
static const yp_item_t desc_remote[] = {
{ C_ID, YP_TSTR, YP_VNONE },
{ C_ADDR, YP_TADDR, YP_VADDR = { 53 } },
{ C_VIA, YP_TADDR, YP_VNONE },
{ C_ADDR, YP_TADDR, YP_VADDR = { 53 }, YP_FMULTI },
{ C_VIA, YP_TADDR, YP_VNONE, YP_FMULTI },
{ C_KEY, YP_TREF, YP_VREF = { C_KEY }, YP_FNONE, { check_ref } },
{ C_COMMENT, YP_TSTR, YP_VNONE },
{ NULL }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment