[syslinux:elflink] Revert "pxe: resolve names via DNS from protected-mode code"

syslinux-bot for Matt Fleming matt.fleming at intel.com
Tue Jun 26 09:54:09 PDT 2012


Commit-ID:  f6e0c5e552ccbb17489097829116da03677a9270
Gitweb:     http://www.syslinux.org/commit/f6e0c5e552ccbb17489097829116da03677a9270
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Wed, 13 Jun 2012 11:17:29 +0100
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Wed, 20 Jun 2012 16:35:35 +0100

Revert "pxe: resolve names via DNS from protected-mode code"

This reverts commit 6aba981cd9310bae94587d3e51106261bf0e27b9.

dns_resolv() is only implemented for PXELINUX, meaning that if we try
to execute any module that references it under SYSLINUX, EXTLINUX or
ISOLINUX it fails to run because it cannot resolve the symbol.

We need a way to implement DNS resolution so that it works for
PXELINUX but returns an error for SYSLINUX/EXTLINUX or ISOLINUX,
without introducing undefined symbols. The old COMBOOT API method
worked splendidly for this, so revert until someone provides a better
solution.

Conflicts:

	com32/lib/Makefile
	com32/modules/host.c
	mk/elf.mk

Cc: Paulo Alcantara <pcacjr at zytor.com>
Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/include/syslinux/pxe.h                       |    4 +-
 com32/lib/Makefile                                 |    1 +
 core/include/pxe.h => com32/lib/syslinux/pxe_dns.c |   50 ++++++++++++++++----
 com32/libupload/upload_tftp.c                      |    2 +-
 com32/modules/host.c                               |   35 +-------------
 com32/modules/pxechn.c                             |    4 +-
 com32/samples/resolv.c                             |   21 +++++++--
 mk/com32.mk                                        |    3 +-
 8 files changed, 68 insertions(+), 52 deletions(-)

diff --git a/com32/include/syslinux/pxe.h b/com32/include/syslinux/pxe.h
index 156f4cf..4e8a336 100644
--- a/com32/include/syslinux/pxe.h
+++ b/com32/include/syslinux/pxe.h
@@ -34,11 +34,11 @@
 #ifndef _SYSLINUX_PXE_H
 #define _SYSLINUX_PXE_H
 
-#include <pxe.h>
 #include <syslinux/pxe_api.h>
 
 /* SYSLINUX-defined PXE utility functions */
 int pxe_get_cached_info(int level, void **buf, size_t *len);
-int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE *gnt);
+int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE * gnt);
+uint32_t pxe_dns(const char *hostname);
 
 #endif /* _SYSLINUX_PXE_H */
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index b9c1494..57e9c2f 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -49,6 +49,7 @@ LIBSYSLINUX_OBJS = \
 	syslinux/features.o syslinux/config.o	\
 	syslinux/version.o	\
 	syslinux/pxe_get_cached.o syslinux/pxe_get_nic.o		\
+	syslinux/pxe_dns.o						\
 	syslinux/video/fontquery.o syslinux/video/reportmode.o
 
 LIBLOAD_OBJS = \
diff --git a/core/include/pxe.h b/com32/lib/syslinux/pxe_dns.c
similarity index 62%
rename from core/include/pxe.h
rename to com32/lib/syslinux/pxe_dns.c
index 86d6cfc..6620396 100644
--- a/core/include/pxe.h
+++ b/com32/lib/syslinux/pxe_dns.c
@@ -1,7 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
  *   Copyright 2010 Intel Corporation; author: H. Peter Anvin
- *   Copyright 2012 Paulo Alcantara <pcacjr at zytor.com>
  *
  *   Permission is hereby granted, free of charge, to any person
  *   obtaining a copy of this software and associated documentation
@@ -26,18 +25,51 @@
  *
  * ----------------------------------------------------------------------- */
 
-#ifndef PXE_H_
-#define PXE_H_
+/*
+ * pxe_dns.c
+ *
+ * Resolve a hostname via DNS
+ */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <stdint.h>
+#include <string.h>
+#include <com32.h>
 
-extern uint32_t dns_resolv(const char *);
+#include <syslinux/pxe.h>
 
-/* Resolve a hostname via DNS */
-static inline uint32_t pxe_dns_resolv(const char *name)
+/* Returns the status code from PXE (0 on success),
+   or -1 on invocation failure */
+uint32_t pxe_dns(const char *hostname)
 {
-    return dns_resolv(name);
-}
+    com32sys_t regs;
+    union {
+	unsigned char b[4];
+	uint32_t ip;
+    } q;
+    char *lm_hostname;
+
+    /* Is this a dot-quad? */
+    if (sscanf(hostname, "%hhu.%hhu.%hhu.%hhu",
+	       &q.b[0], &q.b[1], &q.b[2], &q.b[3]) == 4)
+	return q.ip;
+
+    lm_hostname = lstrdup(hostname);
+    if (!lm_hostname)
+	return 0;
+
+    memset(&regs, 0, sizeof regs);
+    regs.eax.w[0] = 0x0010;
+    regs.es = SEG(lm_hostname);
+    /* regs.ebx.w[0] = OFFS(lm_hostname); */
 
-#endif /* PXE_H_ */
+    __intcall(0x22, &regs, &regs);
+
+    lfree(lm_hostname);
+
+    if (regs.eflags.l & EFLAGS_CF)
+	return 0;
+
+    return regs.eax.l;
+}
diff --git a/com32/libupload/upload_tftp.c b/com32/libupload/upload_tftp.c
index 10427ac..5e73c1c 100644
--- a/com32/libupload/upload_tftp.c
+++ b/com32/libupload/upload_tftp.c
@@ -153,7 +153,7 @@ static int upload_tftp_write(struct upload_backend *be)
     tftp.seq      = 0;
 
     if (be->argv[1]) {
-	tftp.srv_ip = pxe_dns_resolv(be->argv[1]);
+	tftp.srv_ip   = pxe_dns(be->argv[1]);
 	if (!tftp.srv_ip) {
 //	    printf("\nUnable to resolve hostname: %s\n", be->argv[1]);
 	    return -TFTP_ERR_UNABLE_TO_RESOLVE;
diff --git a/com32/modules/host.c b/com32/modules/host.c
index df51725..d70efff 100644
--- a/com32/modules/host.c
+++ b/com32/modules/host.c
@@ -1,43 +1,14 @@
-/* ----------------------------------------------------------------------- *
- *
- *   Copyright 2009 Liu Aleaxander <Aleaxander at gmail.com>
- *   Copyright 2012 Paulo Alcantara <pcacjr at zytor.com>
- *
- *   Permission is hereby granted, free of charge, to any person
- *   obtaining a copy of this software and associated documentation
- *   files (the "Software"), to deal in the Software without
- *   restriction, including without limitation the rights to use,
- *   copy, modify, merge, publish, distribute, sublicense, and/or
- *   sell copies of the Software, and to permit persons to whom
- *   the Software is furnished to do so, subject to the following
- *   conditions:
- *
- *   The above copyright notice and this permission notice shall
- *   be included in all copies or substantial portions of the Software.
- *
- *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- *   OTHER DEALINGS IN THE SOFTWARE.
- *
- * ----------------------------------------------------------------------- */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <console.h>
-#include <com32.h>
-
 #include <netinet/in.h>
+#include <com32.h>
 #include <syslinux/pxe.h>
 
 static inline uint32_t dns_resolve(const char *hostname)
 {
-    return pxe_dns_resolv(hostname);
+    return pxe_dns(hostname);
 }
 
 static inline void usage(const char *s)
@@ -54,7 +25,7 @@ int main(int argc, char *argv[])
 
     if (argc < 2) {
         usage(argv[0]);
-        exit(1);
+        return 1;
     }
 
     for (i = 1; i < argc; i++) {
diff --git a/com32/modules/pxechn.c b/com32/modules/pxechn.c
index 88a281e..1902d4e 100644
--- a/com32/modules/pxechn.c
+++ b/com32/modules/pxechn.c
@@ -402,7 +402,7 @@ int pxechn_parse_fn(char fn[], in_addr_t *fip, char *host, char *fp[])
 	hsep = strchr(host, '@');
 	if (!hsep)
 	    hsep = host;
-	tip = pxe_dns_resolv(hsep);
+	tip = pxe_dns(hsep);
     }
     if (tip != 0)
 	*fip = tip;
@@ -755,7 +755,7 @@ int pxechn_parse_args(int argc, char *argv[], struct pxelinux_opt *pxe,
 	    pxe->force = pxechn_parse_force(optarg);
 	    break;
 	case 'g':	/* gateway/DHCP relay */
-	    pxe->gip = pxe_dns_resolv(optarg);
+	    pxe->gip = pxe_dns(optarg);
 	    break;
 	case 'n':	/* native */
 	    break;
diff --git a/com32/samples/resolv.c b/com32/samples/resolv.c
index 3446bd6..bd49d9f 100644
--- a/com32/samples/resolv.c
+++ b/com32/samples/resolv.c
@@ -22,11 +22,23 @@
 #include <stdlib.h>
 #include <com32.h>
 
-#include <syslinux/pxe.h>
-
-static inline uint32_t resolv(const char *name)
+uint32_t resolv(const char *name)
 {
-    return pxe_dns_resolv(name);
+    com32sys_t reg;
+
+    strcpy((char *)__com32.cs_bounce, name);
+
+    memset(&reg, 0, sizeof reg);
+    reg.eax.w[0] = 0x0010;
+    reg.ebx.w[0] = OFFS(__com32.cs_bounce);
+    reg.es = SEG(__com32.cs_bounce);
+
+    __intcall(0x22, &reg, &reg);
+
+    if (reg.eflags.l & EFLAGS_CF)
+	return 0;
+    else
+	return reg.eax.l;
 }
 
 int main(int argc, char *argv[])
@@ -41,6 +53,7 @@ int main(int argc, char *argv[])
     }
 
     ip = resolv(argv[1]);
+
     if (ip) {
 	printf("%s = %u.%u.%u.%u\n", argv[1],
 	       (ip & 0xff), (ip >> 8) & 0xff,
diff --git a/mk/com32.mk b/mk/com32.mk
index 6e7e9a6..262d2a6 100644
--- a/mk/com32.mk
+++ b/mk/com32.mk
@@ -48,8 +48,7 @@ endif
 CFLAGS     = $(GCCOPT) $(GCCWARN) -march=i386 \
 	     -fomit-frame-pointer -D__COM32__ \
 	     -nostdinc -iwithprefix include \
-	     -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE) \
-	     -I../../core/include
+	     -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE)
 SFLAGS     = $(GCCOPT) $(GCCWARN) -march=i386 \
 	     -fomit-frame-pointer -D__COM32__ \
 	     -nostdinc -iwithprefix include \


More information about the Syslinux-commits mailing list