[1846] in Moira
stella support for ip-address lookups
daemon@ATHENA.MIT.EDU (John Hawkinson)
Mon Aug 20 13:04:20 2001
Date: Mon, 20 Aug 2001 13:04:19 -0400 (EDT)
Message-Id: <200108201704.NAA08552@coleco-sidewinder.mit.edu>
To: moiradev@mit.edu
From: John Hawkinson <jhawk@MIT.EDU>
Herein, do find support for performing stella lookups via IP address.
This is quite useful for the case of machines that have moved and the
DNS has not caught up, or other random situations where the DNS
is unavailable.
It performs an initial lookup if it has been handed an IP address, and then
erforms all other queries based on the returned hostname. This allows
(in theory) all queries that change stuff to still work, though it does
mean that the common case takes two moira queries instead of one (but the
oracle server should cache anyway).
In doing this, I notice again (to my continued horror) that
canonicalize_hostname() canonicalizes hostnames against the DNS,
rather than against moira. That means that if the DNS is inconsistent
with moira, it can be difficult to get what you want.
Is there any good reason why this is the case, and canonicalize_hostname()
does not do a moira-based canonicalization? kolya points out (over zephyr)
that it might be a problem with manual CNAMEs in the zone files. Also,
it might put more load on the moira server.
Anyhow, that's all a seperate discussion. Here's the aptch.
--jhawk
Index: stella.c
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/clients/stella/stella.c,v
retrieving revision 1.11
diff -u -r1.11 stella.c
--- stella.c 2001/08/16 21:31:42 1.11
+++ stella.c 2001/08/20 16:58:23
@@ -5,11 +5,17 @@
*
* Somewhat based on blanche
*
- * Copyright (C) 2000 by the Massachusetts Institute of Technology.
+ * Copyright (C) 2000, 2001 by the Massachusetts Institute of Technology.
* For copying and distribution information, please see the file
* <mit-copyright.h>.
*/
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
#include <mit-copyright.h>
#include <moira.h>
#include <moira_site.h>
@@ -62,6 +68,7 @@
char *newname, *address, *network, *h_status, *vendor, *model;
char *os, *location, *contact, *billing_contact, *adm_cmt, *op_cmt;
+in_addr_t ipaddress;
struct owner_type *owner;
void usage(char **argv);
@@ -320,6 +327,22 @@
}
if (status)
exit(2);
+
+ /* Perform the lookup by IP address if that's what we've been handed */
+ if ((ipaddress=inet_addr(hostname)) != -1) {
+ char *args[5];
+ char *argv[30];
+
+ args[1] = strdup(hostname);
+ args[0] = args[2] = args[3] = "*";
+ status = wrap_mr_query("get_host", 4, args, store_host_info, argv);
+
+ if (status) {
+ com_err(whoami, status, "while looking up IP address.");
+ } else {
+ hostname = argv[0];
+ }
+ }
/* create if needed */
if (create_flag)