summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/hostatectl/hostatectl.814
-rw-r--r--usr.sbin/hostatectl/hostatectl.c10
-rw-r--r--usr.sbin/hostatectl/parser.c26
-rw-r--r--usr.sbin/hostatectl/parser.h4
-rw-r--r--usr.sbin/hostated/control.c16
-rw-r--r--usr.sbin/hostated/hostated.c37
-rw-r--r--usr.sbin/hostated/hostated.h28
-rw-r--r--usr.sbin/hostated/pfe.c76
-rw-r--r--usr.sbin/hoststatectl/hoststatectl.814
-rw-r--r--usr.sbin/hoststatectl/hoststatectl.c10
-rw-r--r--usr.sbin/hoststatectl/parser.c26
-rw-r--r--usr.sbin/hoststatectl/parser.h4
-rw-r--r--usr.sbin/hoststated/control.c16
-rw-r--r--usr.sbin/hoststated/hoststated.c37
-rw-r--r--usr.sbin/hoststated/hoststated.h28
-rw-r--r--usr.sbin/hoststated/pfe.c76
-rw-r--r--usr.sbin/relayctl/parser.c26
-rw-r--r--usr.sbin/relayctl/parser.h4
-rw-r--r--usr.sbin/relayctl/relayctl.814
-rw-r--r--usr.sbin/relayctl/relayctl.c10
-rw-r--r--usr.sbin/relayd/control.c16
-rw-r--r--usr.sbin/relayd/pfe.c76
-rw-r--r--usr.sbin/relayd/relayd.c37
-rw-r--r--usr.sbin/relayd/relayd.h28
24 files changed, 438 insertions, 195 deletions
diff --git a/usr.sbin/hostatectl/hostatectl.8 b/usr.sbin/hostatectl/hostatectl.8
index 7b97135a8dc..2b5fe52a00e 100644
--- a/usr.sbin/hostatectl/hostatectl.8
+++ b/usr.sbin/hostatectl/hostatectl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hostatectl.8,v 1.2 2006/12/16 11:48:38 reyk Exp $
+.\" $OpenBSD: hostatectl.8,v 1.3 2006/12/16 18:50:33 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
.\"
@@ -36,32 +36,32 @@ The following commands are available:
.It Cm show
.It Cm show summary
Show status of services, tables and hosts.
-.It Cm service disable id
+.It Cm service disable Op Ar name | id
Disable a service.
If it has
.Xr pf 4
redirection rules installed, remove them.
Mark the service's main table and -
if applicable - backup table disabled as well.
-.It Cm service enable id
+.It Cm service enable Op Ar name | id
Enable a service.
Mark the service's main table and - if applicable - backup
table enabled as well.
-.It Cm table disable id
+.It Cm table disable Op Ar name | id
Disable a table.
Consider all hosts disabled.
If it is a main table of a service which has a non-empty backup table,
swap the contents of the
.Xr pf 4
table with those of the backup table.
-.It Cm table enable id
+.It Cm table enable Op Ar name | id
Enable a table.
Start doing checks for all hosts that aren't individually disabled
again.
-.It Cm host disable id
+.It Cm host disable Op Ar name | id
Disable a host.
Treat it as though it were always down.
-.It Cm host enable id
+.It Cm host enable Op Ar name | id
Enable the host.
Start checking its health again.
.El
diff --git a/usr.sbin/hostatectl/hostatectl.c b/usr.sbin/hostatectl/hostatectl.c
index 8c5813fa722..740e72645e6 100644
--- a/usr.sbin/hostatectl/hostatectl.c
+++ b/usr.sbin/hostatectl/hostatectl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hostatectl.c,v 1.5 2006/12/16 17:52:21 deraadt Exp $ */
+/* $OpenBSD: hostatectl.c,v 1.6 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -100,7 +100,7 @@ main(int argc, char *argv[])
/* not reached */
case SHOW_SUM:
imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, NULL, 0);
- printf("type\t%4s\t%-16s\tstatus\n\n", "id", "name");
+ printf("Type\t%4s\t%-24s\tStatus\n", "Id", "Name");
break;
case SERV_ENABLE:
imsg_compose(ibuf, IMSG_CTL_SERVICE_ENABLE, 0, 0,
@@ -185,20 +185,20 @@ show_summary_msg(struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_CTL_SERVICE:
service = imsg->data;
- printf("service\t%4u\t%-16s\t%s\n",
+ printf("service\t%4u\t%-24s\t%s\n",
service->id, service->name,
print_service_status(service->flags));
break;
case IMSG_CTL_TABLE:
table = imsg->data;
- printf("table\t%4u\t%-16s\t%s",
+ printf("table\t%4u\t%-24s\t%s",
table->id, table->name,
print_table_status(table->up, table->flags));
printf("\n");
break;
case IMSG_CTL_HOST:
host = imsg->data;
- printf("host\t%4u\t%-16s\t%s\n",
+ printf("host\t%4u\t%-24s\t%s\n",
host->id, host->name,
print_host_status(host->up, host->flags));
break;
diff --git a/usr.sbin/hostatectl/parser.c b/usr.sbin/hostatectl/parser.c
index 2f535990ed9..43703a6622b 100644
--- a/usr.sbin/hostatectl/parser.c
+++ b/usr.sbin/hostatectl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.3 2006/12/16 17:53:03 deraadt Exp $ */
+/* $OpenBSD: parser.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -166,23 +166,29 @@ match_token(const char *word, const struct token table[])
}
break;
case HOSTID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "host id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
case TABLEID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "table id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
case SERVICEID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "service id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
diff --git a/usr.sbin/hostatectl/parser.h b/usr.sbin/hostatectl/parser.h
index 2fef7464faf..1f1c8e879e1 100644
--- a/usr.sbin/hostatectl/parser.h
+++ b/usr.sbin/hostatectl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: parser.h,v 1.2 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -30,7 +30,7 @@ enum actions {
};
struct parse_result {
- objid_t id;
+ struct ctl_id id;
enum actions action;
};
diff --git a/usr.sbin/hostated/control.c b/usr.sbin/hostated/control.c
index eb499d1abb6..4f58a7654e3 100644
--- a/usr.sbin/hostated/control.c
+++ b/usr.sbin/hostated/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.3 2006/12/16 15:25:40 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -190,7 +190,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
{
struct ctl_conn *c;
struct imsg imsg;
- objid_t id;
+ struct ctl_id id;
int n;
if ((c = control_connbyfd(fd)) == NULL) {
@@ -233,7 +233,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_service(c, id))
+ if (disable_service(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -244,7 +244,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_service(c, id))
+ if (enable_service(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -255,7 +255,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_table(c, id))
+ if (disable_table(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -266,7 +266,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_table(c, id))
+ if (enable_table(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -277,7 +277,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_host(c, id))
+ if (disable_host(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -288,7 +288,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_host(c, id))
+ if (enable_host(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
diff --git a/usr.sbin/hostated/hostated.c b/usr.sbin/hostated/hostated.c
index fdbab845a79..337099dc7ba 100644
--- a/usr.sbin/hostated/hostated.c
+++ b/usr.sbin/hostated/hostated.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hostated.c,v 1.3 2006/12/16 14:07:29 reyk Exp $ */
+/* $OpenBSD: hostated.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -374,3 +374,38 @@ service_find(struct hostated *env, objid_t id)
return (service);
return (NULL);
}
+
+struct host *
+host_findbyname(struct hostated *env, const char *name)
+{
+ struct table *table;
+ struct host *host;
+
+ TAILQ_FOREACH(table, &env->tables, entry)
+ TAILQ_FOREACH(host, &table->hosts, entry)
+ if (strcmp(host->name, name) == 0)
+ return (host);
+ return (NULL);
+}
+
+struct table *
+table_findbyname(struct hostated *env, const char *name)
+{
+ struct table *table;
+
+ TAILQ_FOREACH(table, &env->tables, entry)
+ if (strcmp(table->name, name) == 0)
+ return (table);
+ return (NULL);
+}
+
+struct service *
+service_findbyname(struct hostated *env, const char *name)
+{
+ struct service *service;
+
+ TAILQ_FOREACH(service, &env->services, entry)
+ if (strcmp(service->name, name) == 0)
+ return (service);
+ return (NULL);
+}
diff --git a/usr.sbin/hostated/hostated.h b/usr.sbin/hostated/hostated.h
index 0191df4100c..2187d838a3f 100644
--- a/usr.sbin/hostated/hostated.h
+++ b/usr.sbin/hostated/hostated.h
@@ -23,9 +23,11 @@
#define CONNECT_TIMEOUT 200
#define CHECK_INTERVAL 10
#define EMPTY_TABLE UINT_MAX
-#define TABLE_NAME_SIZE 16
-#define TAG_NAME_SIZE 16
-#define SRV_NAME_SIZE 16
+#define EMPTY_ID UINT_MAX
+#define TABLE_NAME_SIZE 32
+#define TAG_NAME_SIZE 64
+#define SRV_NAME_SIZE 64
+#define MAX_NAME_SIZE 64
#define SRV_MAX_VIRTS 16
#define READ_BUF_SIZE 65535
@@ -113,6 +115,11 @@ struct ctl_status {
int up;
};
+struct ctl_id {
+ objid_t id;
+ char name[MAX_NAME_SIZE];
+};
+
struct address {
struct sockaddr_storage ss;
in_port_t port;
@@ -275,12 +282,12 @@ void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
/* pfe.c */
pid_t pfe(struct hostated *, int [2], int [2], int [2]);
void show(struct ctl_conn *);
-int enable_service(struct ctl_conn *, objid_t);
-int enable_table(struct ctl_conn *, objid_t);
-int enable_host(struct ctl_conn *, objid_t);
-int disable_service(struct ctl_conn *, objid_t);
-int disable_table(struct ctl_conn *, objid_t);
-int disable_host(struct ctl_conn *, objid_t);
+int enable_service(struct ctl_conn *, struct ctl_id *);
+int enable_table(struct ctl_conn *, struct ctl_id *);
+int enable_host(struct ctl_conn *, struct ctl_id *);
+int disable_service(struct ctl_conn *, struct ctl_id *);
+int disable_table(struct ctl_conn *, struct ctl_id *);
+int disable_host(struct ctl_conn *, struct ctl_id *);
/* pfe_filter.c */
void init_filter(struct hostated *);
@@ -308,3 +315,6 @@ int check_http_digest(struct host *, struct table *);
struct host *host_find(struct hostated *, objid_t);
struct table *table_find(struct hostated *, objid_t);
struct service *service_find(struct hostated *, objid_t);
+struct host *host_findbyname(struct hostated *, const char *);
+struct table *table_findbyname(struct hostated *, const char *);
+struct service *service_findbyname(struct hostated *, const char *);
diff --git a/usr.sbin/hostated/pfe.c b/usr.sbin/hostated/pfe.c
index 3fe5f29039a..a4575ad17bd 100644
--- a/usr.sbin/hostated/pfe.c
+++ b/usr.sbin/hostated/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.3 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -303,11 +303,15 @@ show(struct ctl_conn *c)
int
-disable_service(struct ctl_conn *c, objid_t id)
+disable_service(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
- if ((service = service_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ service = service_findbyname(env, id->name);
+ else
+ service = service_find(env, id->id);
+ if (service == NULL)
return (-1);
if (service->flags & F_DISABLE)
@@ -323,11 +327,16 @@ disable_service(struct ctl_conn *c, objid_t id)
}
int
-enable_service(struct ctl_conn *c, objid_t id)
+enable_service(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
+ struct ctl_id eid;
- if ((service = service_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ service = service_findbyname(env, id->name);
+ else
+ service = service_find(env, id->id);
+ if (service == NULL)
return (-1);
if (!(service->flags & F_DISABLE))
@@ -338,24 +347,30 @@ enable_service(struct ctl_conn *c, objid_t id)
service->flags |= F_ADD;
log_debug("enable_service: enabled service %d", service->id);
+ bzero(&eid, sizeof(eid));
+
/* XXX: we're syncing twice */
- if (enable_table(c, service->table->id))
+ eid.id = service->table->id;
+ if (enable_table(c, &eid) == -1)
return (-1);
- if (enable_table(c, service->backup->id))
+ eid.id = service->backup->id;
+ if (enable_table(c, &eid) == -1)
return (-1);
return (0);
}
int
-disable_table(struct ctl_conn *c, objid_t id)
+disable_table(struct ctl_conn *c, struct ctl_id *id)
{
struct table *table;
struct service *service;
struct host *host;
- if (id == EMPTY_TABLE)
- return (-1);
- if ((table = table_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ table = table_findbyname(env, id->name);
+ else
+ table = table_find(env, id->id);
+ if (table == NULL)
return (-1);
if ((service = service_find(env, table->serviceid)) == NULL)
fatalx("disable_table: desynchronised");
@@ -366,23 +381,27 @@ disable_table(struct ctl_conn *c, objid_t id)
table->up = 0;
TAILQ_FOREACH(host, &table->hosts, entry)
host->up = HOST_UNKNOWN;
- imsg_compose(ibuf_hce, IMSG_TABLE_DISABLE, 0, 0, &id, sizeof(id));
+ imsg_compose(ibuf_hce, IMSG_TABLE_DISABLE, 0, 0,
+ &table->id, sizeof(table->id));
log_debug("disable_table: disabled table %d", table->id);
pfe_sync();
return (0);
}
int
-enable_table(struct ctl_conn *c, objid_t id)
+enable_table(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
struct table *table;
struct host *host;
- if (id == EMPTY_TABLE)
- return (-1);
- if ((table = table_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ table = table_findbyname(env, id->name);
+ else
+ table = table_find(env, id->id);
+ if (table == NULL)
return (-1);
+
if ((service = service_find(env, table->serviceid)) == NULL)
fatalx("enable_table: desynchronised");
@@ -393,19 +412,24 @@ enable_table(struct ctl_conn *c, objid_t id)
table->up = 0;
TAILQ_FOREACH(host, &table->hosts, entry)
host->up = HOST_UNKNOWN;
- imsg_compose(ibuf_hce, IMSG_TABLE_ENABLE, 0, 0, &id, sizeof(id));
+ imsg_compose(ibuf_hce, IMSG_TABLE_ENABLE, 0, 0,
+ &table->id, sizeof(table->id));
log_debug("enable_table: enabled table %d", table->id);
pfe_sync();
return (0);
}
int
-disable_host(struct ctl_conn *c, objid_t id)
+disable_host(struct ctl_conn *c, struct ctl_id *id)
{
struct host *host;
struct table *table;
- if ((host = host_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ host = host_findbyname(env, id->name);
+ else
+ host = host_find(env, id->id);
+ if (host == NULL)
return (-1);
if (host->flags & F_DISABLE)
@@ -423,18 +447,23 @@ disable_host(struct ctl_conn *c, objid_t id)
host->flags |= F_DEL;
host->flags &= ~(F_ADD);
- imsg_compose(ibuf_hce, IMSG_HOST_DISABLE, 0, 0, &id, sizeof (id));
+ imsg_compose(ibuf_hce, IMSG_HOST_DISABLE, 0, 0,
+ &host->id, sizeof(host->id));
log_debug("disable_host: disabled host %d", host->id);
pfe_sync();
return (0);
}
int
-enable_host(struct ctl_conn *c, objid_t id)
+enable_host(struct ctl_conn *c, struct ctl_id *id)
{
struct host *host;
- if ((host = host_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ host = host_findbyname(env, id->name);
+ else
+ host = host_find(env, id->id);
+ if (host == NULL)
return (-1);
if (!(host->flags & F_DISABLE))
@@ -445,7 +474,8 @@ enable_host(struct ctl_conn *c, objid_t id)
host->flags &= ~(F_DEL);
host->flags &= ~(F_ADD);
- imsg_compose(ibuf_hce, IMSG_HOST_ENABLE, 0, 0, &id, sizeof (id));
+ imsg_compose(ibuf_hce, IMSG_HOST_ENABLE, 0, 0,
+ &host->id, sizeof (host->id));
log_debug("enable_host: enabled host %d", host->id);
pfe_sync();
return (0);
diff --git a/usr.sbin/hoststatectl/hoststatectl.8 b/usr.sbin/hoststatectl/hoststatectl.8
index 686148f9574..c511bc9da66 100644
--- a/usr.sbin/hoststatectl/hoststatectl.8
+++ b/usr.sbin/hoststatectl/hoststatectl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hoststatectl.8,v 1.2 2006/12/16 11:48:38 reyk Exp $
+.\" $OpenBSD: hoststatectl.8,v 1.3 2006/12/16 18:50:33 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
.\"
@@ -36,32 +36,32 @@ The following commands are available:
.It Cm show
.It Cm show summary
Show status of services, tables and hosts.
-.It Cm service disable id
+.It Cm service disable Op Ar name | id
Disable a service.
If it has
.Xr pf 4
redirection rules installed, remove them.
Mark the service's main table and -
if applicable - backup table disabled as well.
-.It Cm service enable id
+.It Cm service enable Op Ar name | id
Enable a service.
Mark the service's main table and - if applicable - backup
table enabled as well.
-.It Cm table disable id
+.It Cm table disable Op Ar name | id
Disable a table.
Consider all hosts disabled.
If it is a main table of a service which has a non-empty backup table,
swap the contents of the
.Xr pf 4
table with those of the backup table.
-.It Cm table enable id
+.It Cm table enable Op Ar name | id
Enable a table.
Start doing checks for all hosts that aren't individually disabled
again.
-.It Cm host disable id
+.It Cm host disable Op Ar name | id
Disable a host.
Treat it as though it were always down.
-.It Cm host enable id
+.It Cm host enable Op Ar name | id
Enable the host.
Start checking its health again.
.El
diff --git a/usr.sbin/hoststatectl/hoststatectl.c b/usr.sbin/hoststatectl/hoststatectl.c
index ca9c0917d6a..9c81a0f6811 100644
--- a/usr.sbin/hoststatectl/hoststatectl.c
+++ b/usr.sbin/hoststatectl/hoststatectl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststatectl.c,v 1.5 2006/12/16 17:52:21 deraadt Exp $ */
+/* $OpenBSD: hoststatectl.c,v 1.6 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -100,7 +100,7 @@ main(int argc, char *argv[])
/* not reached */
case SHOW_SUM:
imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, NULL, 0);
- printf("type\t%4s\t%-16s\tstatus\n\n", "id", "name");
+ printf("Type\t%4s\t%-24s\tStatus\n", "Id", "Name");
break;
case SERV_ENABLE:
imsg_compose(ibuf, IMSG_CTL_SERVICE_ENABLE, 0, 0,
@@ -185,20 +185,20 @@ show_summary_msg(struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_CTL_SERVICE:
service = imsg->data;
- printf("service\t%4u\t%-16s\t%s\n",
+ printf("service\t%4u\t%-24s\t%s\n",
service->id, service->name,
print_service_status(service->flags));
break;
case IMSG_CTL_TABLE:
table = imsg->data;
- printf("table\t%4u\t%-16s\t%s",
+ printf("table\t%4u\t%-24s\t%s",
table->id, table->name,
print_table_status(table->up, table->flags));
printf("\n");
break;
case IMSG_CTL_HOST:
host = imsg->data;
- printf("host\t%4u\t%-16s\t%s\n",
+ printf("host\t%4u\t%-24s\t%s\n",
host->id, host->name,
print_host_status(host->up, host->flags));
break;
diff --git a/usr.sbin/hoststatectl/parser.c b/usr.sbin/hoststatectl/parser.c
index 2f535990ed9..43703a6622b 100644
--- a/usr.sbin/hoststatectl/parser.c
+++ b/usr.sbin/hoststatectl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.3 2006/12/16 17:53:03 deraadt Exp $ */
+/* $OpenBSD: parser.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -166,23 +166,29 @@ match_token(const char *word, const struct token table[])
}
break;
case HOSTID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "host id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
case TABLEID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "table id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
case SERVICEID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "service id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
diff --git a/usr.sbin/hoststatectl/parser.h b/usr.sbin/hoststatectl/parser.h
index 2fef7464faf..1f1c8e879e1 100644
--- a/usr.sbin/hoststatectl/parser.h
+++ b/usr.sbin/hoststatectl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: parser.h,v 1.2 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -30,7 +30,7 @@ enum actions {
};
struct parse_result {
- objid_t id;
+ struct ctl_id id;
enum actions action;
};
diff --git a/usr.sbin/hoststated/control.c b/usr.sbin/hoststated/control.c
index eb499d1abb6..4f58a7654e3 100644
--- a/usr.sbin/hoststated/control.c
+++ b/usr.sbin/hoststated/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.3 2006/12/16 15:25:40 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -190,7 +190,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
{
struct ctl_conn *c;
struct imsg imsg;
- objid_t id;
+ struct ctl_id id;
int n;
if ((c = control_connbyfd(fd)) == NULL) {
@@ -233,7 +233,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_service(c, id))
+ if (disable_service(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -244,7 +244,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_service(c, id))
+ if (enable_service(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -255,7 +255,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_table(c, id))
+ if (disable_table(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -266,7 +266,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_table(c, id))
+ if (enable_table(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -277,7 +277,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_host(c, id))
+ if (disable_host(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -288,7 +288,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_host(c, id))
+ if (enable_host(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
diff --git a/usr.sbin/hoststated/hoststated.c b/usr.sbin/hoststated/hoststated.c
index cd593ef6873..223eb1eadad 100644
--- a/usr.sbin/hoststated/hoststated.c
+++ b/usr.sbin/hoststated/hoststated.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.c,v 1.3 2006/12/16 14:07:29 reyk Exp $ */
+/* $OpenBSD: hoststated.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -374,3 +374,38 @@ service_find(struct hostated *env, objid_t id)
return (service);
return (NULL);
}
+
+struct host *
+host_findbyname(struct hostated *env, const char *name)
+{
+ struct table *table;
+ struct host *host;
+
+ TAILQ_FOREACH(table, &env->tables, entry)
+ TAILQ_FOREACH(host, &table->hosts, entry)
+ if (strcmp(host->name, name) == 0)
+ return (host);
+ return (NULL);
+}
+
+struct table *
+table_findbyname(struct hostated *env, const char *name)
+{
+ struct table *table;
+
+ TAILQ_FOREACH(table, &env->tables, entry)
+ if (strcmp(table->name, name) == 0)
+ return (table);
+ return (NULL);
+}
+
+struct service *
+service_findbyname(struct hostated *env, const char *name)
+{
+ struct service *service;
+
+ TAILQ_FOREACH(service, &env->services, entry)
+ if (strcmp(service->name, name) == 0)
+ return (service);
+ return (NULL);
+}
diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h
index 0191df4100c..2187d838a3f 100644
--- a/usr.sbin/hoststated/hoststated.h
+++ b/usr.sbin/hoststated/hoststated.h
@@ -23,9 +23,11 @@
#define CONNECT_TIMEOUT 200
#define CHECK_INTERVAL 10
#define EMPTY_TABLE UINT_MAX
-#define TABLE_NAME_SIZE 16
-#define TAG_NAME_SIZE 16
-#define SRV_NAME_SIZE 16
+#define EMPTY_ID UINT_MAX
+#define TABLE_NAME_SIZE 32
+#define TAG_NAME_SIZE 64
+#define SRV_NAME_SIZE 64
+#define MAX_NAME_SIZE 64
#define SRV_MAX_VIRTS 16
#define READ_BUF_SIZE 65535
@@ -113,6 +115,11 @@ struct ctl_status {
int up;
};
+struct ctl_id {
+ objid_t id;
+ char name[MAX_NAME_SIZE];
+};
+
struct address {
struct sockaddr_storage ss;
in_port_t port;
@@ -275,12 +282,12 @@ void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
/* pfe.c */
pid_t pfe(struct hostated *, int [2], int [2], int [2]);
void show(struct ctl_conn *);
-int enable_service(struct ctl_conn *, objid_t);
-int enable_table(struct ctl_conn *, objid_t);
-int enable_host(struct ctl_conn *, objid_t);
-int disable_service(struct ctl_conn *, objid_t);
-int disable_table(struct ctl_conn *, objid_t);
-int disable_host(struct ctl_conn *, objid_t);
+int enable_service(struct ctl_conn *, struct ctl_id *);
+int enable_table(struct ctl_conn *, struct ctl_id *);
+int enable_host(struct ctl_conn *, struct ctl_id *);
+int disable_service(struct ctl_conn *, struct ctl_id *);
+int disable_table(struct ctl_conn *, struct ctl_id *);
+int disable_host(struct ctl_conn *, struct ctl_id *);
/* pfe_filter.c */
void init_filter(struct hostated *);
@@ -308,3 +315,6 @@ int check_http_digest(struct host *, struct table *);
struct host *host_find(struct hostated *, objid_t);
struct table *table_find(struct hostated *, objid_t);
struct service *service_find(struct hostated *, objid_t);
+struct host *host_findbyname(struct hostated *, const char *);
+struct table *table_findbyname(struct hostated *, const char *);
+struct service *service_findbyname(struct hostated *, const char *);
diff --git a/usr.sbin/hoststated/pfe.c b/usr.sbin/hoststated/pfe.c
index 3fe5f29039a..a4575ad17bd 100644
--- a/usr.sbin/hoststated/pfe.c
+++ b/usr.sbin/hoststated/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.3 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -303,11 +303,15 @@ show(struct ctl_conn *c)
int
-disable_service(struct ctl_conn *c, objid_t id)
+disable_service(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
- if ((service = service_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ service = service_findbyname(env, id->name);
+ else
+ service = service_find(env, id->id);
+ if (service == NULL)
return (-1);
if (service->flags & F_DISABLE)
@@ -323,11 +327,16 @@ disable_service(struct ctl_conn *c, objid_t id)
}
int
-enable_service(struct ctl_conn *c, objid_t id)
+enable_service(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
+ struct ctl_id eid;
- if ((service = service_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ service = service_findbyname(env, id->name);
+ else
+ service = service_find(env, id->id);
+ if (service == NULL)
return (-1);
if (!(service->flags & F_DISABLE))
@@ -338,24 +347,30 @@ enable_service(struct ctl_conn *c, objid_t id)
service->flags |= F_ADD;
log_debug("enable_service: enabled service %d", service->id);
+ bzero(&eid, sizeof(eid));
+
/* XXX: we're syncing twice */
- if (enable_table(c, service->table->id))
+ eid.id = service->table->id;
+ if (enable_table(c, &eid) == -1)
return (-1);
- if (enable_table(c, service->backup->id))
+ eid.id = service->backup->id;
+ if (enable_table(c, &eid) == -1)
return (-1);
return (0);
}
int
-disable_table(struct ctl_conn *c, objid_t id)
+disable_table(struct ctl_conn *c, struct ctl_id *id)
{
struct table *table;
struct service *service;
struct host *host;
- if (id == EMPTY_TABLE)
- return (-1);
- if ((table = table_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ table = table_findbyname(env, id->name);
+ else
+ table = table_find(env, id->id);
+ if (table == NULL)
return (-1);
if ((service = service_find(env, table->serviceid)) == NULL)
fatalx("disable_table: desynchronised");
@@ -366,23 +381,27 @@ disable_table(struct ctl_conn *c, objid_t id)
table->up = 0;
TAILQ_FOREACH(host, &table->hosts, entry)
host->up = HOST_UNKNOWN;
- imsg_compose(ibuf_hce, IMSG_TABLE_DISABLE, 0, 0, &id, sizeof(id));
+ imsg_compose(ibuf_hce, IMSG_TABLE_DISABLE, 0, 0,
+ &table->id, sizeof(table->id));
log_debug("disable_table: disabled table %d", table->id);
pfe_sync();
return (0);
}
int
-enable_table(struct ctl_conn *c, objid_t id)
+enable_table(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
struct table *table;
struct host *host;
- if (id == EMPTY_TABLE)
- return (-1);
- if ((table = table_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ table = table_findbyname(env, id->name);
+ else
+ table = table_find(env, id->id);
+ if (table == NULL)
return (-1);
+
if ((service = service_find(env, table->serviceid)) == NULL)
fatalx("enable_table: desynchronised");
@@ -393,19 +412,24 @@ enable_table(struct ctl_conn *c, objid_t id)
table->up = 0;
TAILQ_FOREACH(host, &table->hosts, entry)
host->up = HOST_UNKNOWN;
- imsg_compose(ibuf_hce, IMSG_TABLE_ENABLE, 0, 0, &id, sizeof(id));
+ imsg_compose(ibuf_hce, IMSG_TABLE_ENABLE, 0, 0,
+ &table->id, sizeof(table->id));
log_debug("enable_table: enabled table %d", table->id);
pfe_sync();
return (0);
}
int
-disable_host(struct ctl_conn *c, objid_t id)
+disable_host(struct ctl_conn *c, struct ctl_id *id)
{
struct host *host;
struct table *table;
- if ((host = host_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ host = host_findbyname(env, id->name);
+ else
+ host = host_find(env, id->id);
+ if (host == NULL)
return (-1);
if (host->flags & F_DISABLE)
@@ -423,18 +447,23 @@ disable_host(struct ctl_conn *c, objid_t id)
host->flags |= F_DEL;
host->flags &= ~(F_ADD);
- imsg_compose(ibuf_hce, IMSG_HOST_DISABLE, 0, 0, &id, sizeof (id));
+ imsg_compose(ibuf_hce, IMSG_HOST_DISABLE, 0, 0,
+ &host->id, sizeof(host->id));
log_debug("disable_host: disabled host %d", host->id);
pfe_sync();
return (0);
}
int
-enable_host(struct ctl_conn *c, objid_t id)
+enable_host(struct ctl_conn *c, struct ctl_id *id)
{
struct host *host;
- if ((host = host_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ host = host_findbyname(env, id->name);
+ else
+ host = host_find(env, id->id);
+ if (host == NULL)
return (-1);
if (!(host->flags & F_DISABLE))
@@ -445,7 +474,8 @@ enable_host(struct ctl_conn *c, objid_t id)
host->flags &= ~(F_DEL);
host->flags &= ~(F_ADD);
- imsg_compose(ibuf_hce, IMSG_HOST_ENABLE, 0, 0, &id, sizeof (id));
+ imsg_compose(ibuf_hce, IMSG_HOST_ENABLE, 0, 0,
+ &host->id, sizeof (host->id));
log_debug("enable_host: enabled host %d", host->id);
pfe_sync();
return (0);
diff --git a/usr.sbin/relayctl/parser.c b/usr.sbin/relayctl/parser.c
index 2f535990ed9..43703a6622b 100644
--- a/usr.sbin/relayctl/parser.c
+++ b/usr.sbin/relayctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.3 2006/12/16 17:53:03 deraadt Exp $ */
+/* $OpenBSD: parser.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -166,23 +166,29 @@ match_token(const char *word, const struct token table[])
}
break;
case HOSTID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "host id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
case TABLEID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "table id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
case SERVICEID:
- res.id = strtonum(word, 0, UINT_MAX, &errstr);
- if (errstr)
- errx(1, "service id %s is %s", word, errstr);
+ res.id.id = strtonum(word, 0, UINT_MAX, &errstr);
+ if (errstr) {
+ strlcpy(res.id.name, word, sizeof(res.id.name));
+ res.id.id = EMPTY_ID;
+ }
t = &table[i];
match++;
break;
diff --git a/usr.sbin/relayctl/parser.h b/usr.sbin/relayctl/parser.h
index 2fef7464faf..1f1c8e879e1 100644
--- a/usr.sbin/relayctl/parser.h
+++ b/usr.sbin/relayctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: parser.h,v 1.2 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -30,7 +30,7 @@ enum actions {
};
struct parse_result {
- objid_t id;
+ struct ctl_id id;
enum actions action;
};
diff --git a/usr.sbin/relayctl/relayctl.8 b/usr.sbin/relayctl/relayctl.8
index 18038c6c368..68ba60ffa02 100644
--- a/usr.sbin/relayctl/relayctl.8
+++ b/usr.sbin/relayctl/relayctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: relayctl.8,v 1.2 2006/12/16 11:48:38 reyk Exp $
+.\" $OpenBSD: relayctl.8,v 1.3 2006/12/16 18:50:33 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
.\"
@@ -36,32 +36,32 @@ The following commands are available:
.It Cm show
.It Cm show summary
Show status of services, tables and hosts.
-.It Cm service disable id
+.It Cm service disable Op Ar name | id
Disable a service.
If it has
.Xr pf 4
redirection rules installed, remove them.
Mark the service's main table and -
if applicable - backup table disabled as well.
-.It Cm service enable id
+.It Cm service enable Op Ar name | id
Enable a service.
Mark the service's main table and - if applicable - backup
table enabled as well.
-.It Cm table disable id
+.It Cm table disable Op Ar name | id
Disable a table.
Consider all hosts disabled.
If it is a main table of a service which has a non-empty backup table,
swap the contents of the
.Xr pf 4
table with those of the backup table.
-.It Cm table enable id
+.It Cm table enable Op Ar name | id
Enable a table.
Start doing checks for all hosts that aren't individually disabled
again.
-.It Cm host disable id
+.It Cm host disable Op Ar name | id
Disable a host.
Treat it as though it were always down.
-.It Cm host enable id
+.It Cm host enable Op Ar name | id
Enable the host.
Start checking its health again.
.El
diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c
index 4de38d73807..0fb2c655b67 100644
--- a/usr.sbin/relayctl/relayctl.c
+++ b/usr.sbin/relayctl/relayctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayctl.c,v 1.5 2006/12/16 17:52:21 deraadt Exp $ */
+/* $OpenBSD: relayctl.c,v 1.6 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -100,7 +100,7 @@ main(int argc, char *argv[])
/* not reached */
case SHOW_SUM:
imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, NULL, 0);
- printf("type\t%4s\t%-16s\tstatus\n\n", "id", "name");
+ printf("Type\t%4s\t%-24s\tStatus\n", "Id", "Name");
break;
case SERV_ENABLE:
imsg_compose(ibuf, IMSG_CTL_SERVICE_ENABLE, 0, 0,
@@ -185,20 +185,20 @@ show_summary_msg(struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_CTL_SERVICE:
service = imsg->data;
- printf("service\t%4u\t%-16s\t%s\n",
+ printf("service\t%4u\t%-24s\t%s\n",
service->id, service->name,
print_service_status(service->flags));
break;
case IMSG_CTL_TABLE:
table = imsg->data;
- printf("table\t%4u\t%-16s\t%s",
+ printf("table\t%4u\t%-24s\t%s",
table->id, table->name,
print_table_status(table->up, table->flags));
printf("\n");
break;
case IMSG_CTL_HOST:
host = imsg->data;
- printf("host\t%4u\t%-16s\t%s\n",
+ printf("host\t%4u\t%-24s\t%s\n",
host->id, host->name,
print_host_status(host->up, host->flags));
break;
diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c
index eb499d1abb6..4f58a7654e3 100644
--- a/usr.sbin/relayd/control.c
+++ b/usr.sbin/relayd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.3 2006/12/16 15:25:40 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -190,7 +190,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
{
struct ctl_conn *c;
struct imsg imsg;
- objid_t id;
+ struct ctl_id id;
int n;
if ((c = control_connbyfd(fd)) == NULL) {
@@ -233,7 +233,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_service(c, id))
+ if (disable_service(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -244,7 +244,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_service(c, id))
+ if (enable_service(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -255,7 +255,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_table(c, id))
+ if (disable_table(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -266,7 +266,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_table(c, id))
+ if (enable_table(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -277,7 +277,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (disable_host(c, id))
+ if (disable_host(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
@@ -288,7 +288,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
fatalx("invalid imsg header len");
memcpy(&id, imsg.data, sizeof(id));
- if (enable_host(c, id))
+ if (enable_host(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
else
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 3fe5f29039a..a4575ad17bd 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.3 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -303,11 +303,15 @@ show(struct ctl_conn *c)
int
-disable_service(struct ctl_conn *c, objid_t id)
+disable_service(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
- if ((service = service_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ service = service_findbyname(env, id->name);
+ else
+ service = service_find(env, id->id);
+ if (service == NULL)
return (-1);
if (service->flags & F_DISABLE)
@@ -323,11 +327,16 @@ disable_service(struct ctl_conn *c, objid_t id)
}
int
-enable_service(struct ctl_conn *c, objid_t id)
+enable_service(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
+ struct ctl_id eid;
- if ((service = service_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ service = service_findbyname(env, id->name);
+ else
+ service = service_find(env, id->id);
+ if (service == NULL)
return (-1);
if (!(service->flags & F_DISABLE))
@@ -338,24 +347,30 @@ enable_service(struct ctl_conn *c, objid_t id)
service->flags |= F_ADD;
log_debug("enable_service: enabled service %d", service->id);
+ bzero(&eid, sizeof(eid));
+
/* XXX: we're syncing twice */
- if (enable_table(c, service->table->id))
+ eid.id = service->table->id;
+ if (enable_table(c, &eid) == -1)
return (-1);
- if (enable_table(c, service->backup->id))
+ eid.id = service->backup->id;
+ if (enable_table(c, &eid) == -1)
return (-1);
return (0);
}
int
-disable_table(struct ctl_conn *c, objid_t id)
+disable_table(struct ctl_conn *c, struct ctl_id *id)
{
struct table *table;
struct service *service;
struct host *host;
- if (id == EMPTY_TABLE)
- return (-1);
- if ((table = table_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ table = table_findbyname(env, id->name);
+ else
+ table = table_find(env, id->id);
+ if (table == NULL)
return (-1);
if ((service = service_find(env, table->serviceid)) == NULL)
fatalx("disable_table: desynchronised");
@@ -366,23 +381,27 @@ disable_table(struct ctl_conn *c, objid_t id)
table->up = 0;
TAILQ_FOREACH(host, &table->hosts, entry)
host->up = HOST_UNKNOWN;
- imsg_compose(ibuf_hce, IMSG_TABLE_DISABLE, 0, 0, &id, sizeof(id));
+ imsg_compose(ibuf_hce, IMSG_TABLE_DISABLE, 0, 0,
+ &table->id, sizeof(table->id));
log_debug("disable_table: disabled table %d", table->id);
pfe_sync();
return (0);
}
int
-enable_table(struct ctl_conn *c, objid_t id)
+enable_table(struct ctl_conn *c, struct ctl_id *id)
{
struct service *service;
struct table *table;
struct host *host;
- if (id == EMPTY_TABLE)
- return (-1);
- if ((table = table_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ table = table_findbyname(env, id->name);
+ else
+ table = table_find(env, id->id);
+ if (table == NULL)
return (-1);
+
if ((service = service_find(env, table->serviceid)) == NULL)
fatalx("enable_table: desynchronised");
@@ -393,19 +412,24 @@ enable_table(struct ctl_conn *c, objid_t id)
table->up = 0;
TAILQ_FOREACH(host, &table->hosts, entry)
host->up = HOST_UNKNOWN;
- imsg_compose(ibuf_hce, IMSG_TABLE_ENABLE, 0, 0, &id, sizeof(id));
+ imsg_compose(ibuf_hce, IMSG_TABLE_ENABLE, 0, 0,
+ &table->id, sizeof(table->id));
log_debug("enable_table: enabled table %d", table->id);
pfe_sync();
return (0);
}
int
-disable_host(struct ctl_conn *c, objid_t id)
+disable_host(struct ctl_conn *c, struct ctl_id *id)
{
struct host *host;
struct table *table;
- if ((host = host_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ host = host_findbyname(env, id->name);
+ else
+ host = host_find(env, id->id);
+ if (host == NULL)
return (-1);
if (host->flags & F_DISABLE)
@@ -423,18 +447,23 @@ disable_host(struct ctl_conn *c, objid_t id)
host->flags |= F_DEL;
host->flags &= ~(F_ADD);
- imsg_compose(ibuf_hce, IMSG_HOST_DISABLE, 0, 0, &id, sizeof (id));
+ imsg_compose(ibuf_hce, IMSG_HOST_DISABLE, 0, 0,
+ &host->id, sizeof(host->id));
log_debug("disable_host: disabled host %d", host->id);
pfe_sync();
return (0);
}
int
-enable_host(struct ctl_conn *c, objid_t id)
+enable_host(struct ctl_conn *c, struct ctl_id *id)
{
struct host *host;
- if ((host = host_find(env, id)) == NULL)
+ if (id->id == EMPTY_ID)
+ host = host_findbyname(env, id->name);
+ else
+ host = host_find(env, id->id);
+ if (host == NULL)
return (-1);
if (!(host->flags & F_DISABLE))
@@ -445,7 +474,8 @@ enable_host(struct ctl_conn *c, objid_t id)
host->flags &= ~(F_DEL);
host->flags &= ~(F_ADD);
- imsg_compose(ibuf_hce, IMSG_HOST_ENABLE, 0, 0, &id, sizeof (id));
+ imsg_compose(ibuf_hce, IMSG_HOST_ENABLE, 0, 0,
+ &host->id, sizeof (host->id));
log_debug("enable_host: enabled host %d", host->id);
pfe_sync();
return (0);
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index cbd38057b46..ddbc0dcb983 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.3 2006/12/16 14:07:29 reyk Exp $ */
+/* $OpenBSD: relayd.c,v 1.4 2006/12/16 18:50:33 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -374,3 +374,38 @@ service_find(struct hostated *env, objid_t id)
return (service);
return (NULL);
}
+
+struct host *
+host_findbyname(struct hostated *env, const char *name)
+{
+ struct table *table;
+ struct host *host;
+
+ TAILQ_FOREACH(table, &env->tables, entry)
+ TAILQ_FOREACH(host, &table->hosts, entry)
+ if (strcmp(host->name, name) == 0)
+ return (host);
+ return (NULL);
+}
+
+struct table *
+table_findbyname(struct hostated *env, const char *name)
+{
+ struct table *table;
+
+ TAILQ_FOREACH(table, &env->tables, entry)
+ if (strcmp(table->name, name) == 0)
+ return (table);
+ return (NULL);
+}
+
+struct service *
+service_findbyname(struct hostated *env, const char *name)
+{
+ struct service *service;
+
+ TAILQ_FOREACH(service, &env->services, entry)
+ if (strcmp(service->name, name) == 0)
+ return (service);
+ return (NULL);
+}
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 0191df4100c..2187d838a3f 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -23,9 +23,11 @@
#define CONNECT_TIMEOUT 200
#define CHECK_INTERVAL 10
#define EMPTY_TABLE UINT_MAX
-#define TABLE_NAME_SIZE 16
-#define TAG_NAME_SIZE 16
-#define SRV_NAME_SIZE 16
+#define EMPTY_ID UINT_MAX
+#define TABLE_NAME_SIZE 32
+#define TAG_NAME_SIZE 64
+#define SRV_NAME_SIZE 64
+#define MAX_NAME_SIZE 64
#define SRV_MAX_VIRTS 16
#define READ_BUF_SIZE 65535
@@ -113,6 +115,11 @@ struct ctl_status {
int up;
};
+struct ctl_id {
+ objid_t id;
+ char name[MAX_NAME_SIZE];
+};
+
struct address {
struct sockaddr_storage ss;
in_port_t port;
@@ -275,12 +282,12 @@ void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
/* pfe.c */
pid_t pfe(struct hostated *, int [2], int [2], int [2]);
void show(struct ctl_conn *);
-int enable_service(struct ctl_conn *, objid_t);
-int enable_table(struct ctl_conn *, objid_t);
-int enable_host(struct ctl_conn *, objid_t);
-int disable_service(struct ctl_conn *, objid_t);
-int disable_table(struct ctl_conn *, objid_t);
-int disable_host(struct ctl_conn *, objid_t);
+int enable_service(struct ctl_conn *, struct ctl_id *);
+int enable_table(struct ctl_conn *, struct ctl_id *);
+int enable_host(struct ctl_conn *, struct ctl_id *);
+int disable_service(struct ctl_conn *, struct ctl_id *);
+int disable_table(struct ctl_conn *, struct ctl_id *);
+int disable_host(struct ctl_conn *, struct ctl_id *);
/* pfe_filter.c */
void init_filter(struct hostated *);
@@ -308,3 +315,6 @@ int check_http_digest(struct host *, struct table *);
struct host *host_find(struct hostated *, objid_t);
struct table *table_find(struct hostated *, objid_t);
struct service *service_find(struct hostated *, objid_t);
+struct host *host_findbyname(struct hostated *, const char *);
+struct table *table_findbyname(struct hostated *, const char *);
+struct service *service_findbyname(struct hostated *, const char *);