From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Sun, 21 Apr 96 13:42 PDT From: Eric Smith Subject: inet patches for multihomed hosts (and IP aliasing) This isn't really Alpha-specific (or even Linux-specific) but since I got it working on Red Hat Linux AXP 2.1, I thought I'd share it in case anyone else is trying to use an Alpha as an internet server platform. I upgraded my server machine to the 1.3.90 and turned on IP aliasing. The Apache web server can be easily configured to serve separate directory heirarchies to the multiple IP addresses. However, I also want different FTP directories, and I don't want other services (such as Telnet) showing up on all the IP addresses. I came up with a patch (below) to inetd, which adds the ability to specify a secific host name or address for each service. Note that this doesn't solve the problem for other services such as named, since they aren't started by inetd. Rather than patch all such programs, I think I will hack the library so that when bind() is called, if the IP addrees is 0 and an environment variable (FORCE_IP_ADDR) is defined, that the value of the latter gets substituted. Cheers, Eric ----------------------------------------------------------------------------- --- inetd.c.orig Mon May 23 02:04:45 1994 +++ inetd.c Sun Apr 21 13:37:11 1996 @@ -87,6 +87,29 @@ * Comment lines are indicated by a `#' in column 1. */ +#ifdef MULTIHOME +/* + * Multihome patch by Eric Smith, 4/19/96 + * + * With this patch enabled, the first field on a line (for non-RPC services) + * may be of the format host_name:service_name. On a multi-homed host, this + * is useful to restrict a service to accept connections on only one IP + * address, or to run different instances of a service on different IP + * addresses. + * + * If the host name is given as a DNS name, it has to be resolved when inetd + * is started (and restarted). On many systems DNS isn't operational that + * early in the boot process; in this case there should be /etc/hosts entries. + * Alternatively the host can be specified using dotted decimal notation. + * + * If no colon is present, or if the host is specified as "*", the original + * behavior of wildcarding the address is used. + * + * This patch has been tested on a Digital UDB (aka Multia) running + * Red Hat Linux/AXP 2.1 and Linux kernel version 1.3.90. + */ +#endif /* MULTIHOME */ + /* * Here's the scoop concerning the user.group feature: * @@ -185,6 +208,9 @@ #endif struct servtab { +#ifdef MULTIHOME + char *se_host; /* hostname */ +#endif /* MULTIHOME */ char *se_service; /* name of service */ int se_socktype; /* type of socket to use */ int se_family; /* address family */ @@ -272,6 +298,32 @@ } #endif + +#ifdef MULTIHOME +void get_host_addr (char *cp, struct in_addr *a) +{ + int tmp; + struct hostent *host; + + a->s_addr = 0; + + if ((!cp) || (*cp == '\0') || (strcmp (cp, "*") == 0)) + a->s_addr = 0; + else if ((tmp = inet_addr(cp)) != -1) + a->s_addr = tmp; + else if (host = gethostbyname (cp)) + { + if (host->h_addrtype == AF_INET) + memcpy (a, host->h_addr, sizeof (struct in_addr)); + else + syslog(LOG_WARNING, "non-IP host '%s'\n", cp); + } + else + syslog(LOG_WARNING, "can't resolve host '%s'\n", cp); + return; +} +#endif /* MULTIHOME */ + main(argc, argv, envp) int argc; char *argv[], *envp[]; @@ -617,6 +669,9 @@ case AF_INET: sep->se_ctrladdr_in.sin_family = AF_INET; sep->se_ctrladdr_size = sizeof sep->se_ctrladdr_in; +#ifdef MULTIHOME + get_host_addr (sep->se_host, & sep->se_ctrladdr_in.sin_addr); +#endif /* MULTIHOME */ if (isrpcservice(sep)) { struct rpcent *rp; @@ -880,6 +935,9 @@ register struct servtab *sep = &serv; int argc; char *cp, *arg, *newstr(); +#ifdef MULTIHOME + char *cp2; +#endif /* MULTIHOME */ more: #ifdef MULOG @@ -918,6 +976,16 @@ return ((struct servtab *)0); bzero((char *)sep, sizeof *sep); sep->se_service = newstr(skip(&cp)); +#ifdef MULTIHOME + if (cp2 = strchr (sep->se_service, ':')) + { + sep->se_host = sep->se_service; + sep->se_service = newstr (cp2+1); + *cp2 = '\0'; + } + else + sep->se_host = newstr ("*"); +#endif /* MULTIHOME */ arg = skip(&cp); if (arg == NULL) goto more; @@ -1049,6 +1117,10 @@ { int i; +#ifdef MULTIHOME + if (cp->se_host) + free(cp->se_host); +#endif MULTIHOME if (cp->se_service) free(cp->se_service); if (cp->se_proto)