diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2006-12-16 18:50:34 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2006-12-16 18:50:34 +0000 |
commit | 19d82ea2d7751a0b7ec8fa66d2a2053a369f0403 (patch) | |
tree | d91fc3a03e096ac77beaf625f8687d85b92e7b05 /usr.sbin/hostated | |
parent | eb9e468ffdd8750ab38d6914ccb20acb388e2102 (diff) |
- allow to use host/service/table names instead of Ids in hostatectl.
- minor change of the "hostatectl show" command output
- increase the max service and tag names (max pf tag name size is 64 now!)
thanks to pyr who found a bug in my initial diff
Diffstat (limited to 'usr.sbin/hostated')
-rw-r--r-- | usr.sbin/hostated/control.c | 16 | ||||
-rw-r--r-- | usr.sbin/hostated/hostated.c | 37 | ||||
-rw-r--r-- | usr.sbin/hostated/hostated.h | 28 | ||||
-rw-r--r-- | usr.sbin/hostated/pfe.c | 76 |
4 files changed, 116 insertions, 41 deletions
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); |