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

syslinux-bot for Paulo Alcantara pcacjr at zytor.com
Wed May 16 14:21:07 PDT 2012


Commit-ID:  6aba981cd9310bae94587d3e51106261bf0e27b9
Gitweb:     http://www.syslinux.org/commit/6aba981cd9310bae94587d3e51106261bf0e27b9
Author:     Paulo Alcantara <pcacjr at zytor.com>
AuthorDate: Fri, 4 May 2012 02:17:46 -0300
Committer:  Paulo Alcantara <pcacjr at zytor.com>
CommitDate: Sat, 12 May 2012 00:56:22 -0300

pxe: resolve names via DNS from protected-mode code

Syslinux used to call __intcall() for calling routines of the old
COMBOOT API to resolve names via DNS (INT 22h, AX=0x0010) that seemed
pointless, since INT 22h, AX=0x0010 does call the protected-mode
function pm_pxe_resolv_dns() when calling INT 22h, AX=0x0010. So, for
resolving names via DNS we must call pxe_dns_resolv() (a protected-mode
function) instead for now.

Signed-off-by: Paulo Alcantara <pcacjr at zytor.com>

---
 com32/include/syslinux/pxe.h              |    4 +-
 com32/lib/Makefile                        |    1 -
 com32/lib/syslinux/pxe_dns.c              |   75 -----------------------------
 com32/libupload/upload_tftp.c             |    2 +-
 com32/modules/host.c                      |   37 +++++++++++++--
 com32/samples/resolv.c                    |   21 ++-------
 com32/lib/lmalloc.c => core/include/pxe.h |   29 +++++-------
 mk/com32.mk                               |    3 +-
 mk/elf.mk                                 |    3 +-
 9 files changed, 56 insertions(+), 119 deletions(-)

diff --git a/com32/include/syslinux/pxe.h b/com32/include/syslinux/pxe.h
index 4e8a336..156f4cf 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);
-uint32_t pxe_dns(const char *hostname);
+int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE *gnt);
 
 #endif /* _SYSLINUX_PXE_H */
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index bee1a02..7bb2d3a 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -49,7 +49,6 @@ LIBSYSLINUX_OBJS = \
 	syslinux/features.o syslinux/config.o	\
 	syslinux/dsinfo.o syslinux/version.o	\
 	syslinux/pxe_get_cached.o syslinux/pxe_get_nic.o		\
-	syslinux/pxe_dns.o						\
 	syslinux/video/fontquery.o syslinux/video/forcetext.o		\
 	syslinux/video/reportmode.o
 
diff --git a/com32/lib/syslinux/pxe_dns.c b/com32/lib/syslinux/pxe_dns.c
deleted file mode 100644
index 6620396..0000000
--- a/com32/lib/syslinux/pxe_dns.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* ----------------------------------------------------------------------- *
- *
- *   Copyright 2010 Intel Corporation; author: H. Peter Anvin
- *
- *   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.
- *
- * ----------------------------------------------------------------------- */
-
-/*
- * pxe_dns.c
- *
- * Resolve a hostname via DNS
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <com32.h>
-
-#include <syslinux/pxe.h>
-
-/* Returns the status code from PXE (0 on success),
-   or -1 on invocation failure */
-uint32_t pxe_dns(const char *hostname)
-{
-    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); */
-
-    __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 5e73c1c..10427ac 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(be->argv[1]);
+	tftp.srv_ip = pxe_dns_resolv(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 c8560c3..b43bd43 100644
--- a/com32/modules/host.c
+++ b/com32/modules/host.c
@@ -1,13 +1,42 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   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 <console.h>
 #include <string.h>
-#include <netinet/in.h>
+#include <console.h>
 #include <com32.h>
+
+#include <netinet/in.h>
 #include <syslinux/pxe.h>
 
 static inline uint32_t dns_resolve(const char *hostname)
 {
-    return pxe_dns(hostname);
+    return pxe_dns_resolv(hostname);
 }
 
 static inline void usage(const char *s)
@@ -24,7 +53,7 @@ int main(int argc, char *argv[])
 
     if (argc < 2) {
         usage(argv[0]);
-        return 1;
+        exit(1);
     }
 
     for (i = 1; i < argc; i++) {
diff --git a/com32/samples/resolv.c b/com32/samples/resolv.c
index bd49d9f..3446bd6 100644
--- a/com32/samples/resolv.c
+++ b/com32/samples/resolv.c
@@ -22,23 +22,11 @@
 #include <stdlib.h>
 #include <com32.h>
 
-uint32_t resolv(const char *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);
+#include <syslinux/pxe.h>
 
-    __intcall(0x22, &reg, &reg);
-
-    if (reg.eflags.l & EFLAGS_CF)
-	return 0;
-    else
-	return reg.eax.l;
+static inline uint32_t resolv(const char *name)
+{
+    return pxe_dns_resolv(name);
 }
 
 int main(int argc, char *argv[])
@@ -53,7 +41,6 @@ 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/com32/lib/lmalloc.c b/core/include/pxe.h
similarity index 81%
copy from com32/lib/lmalloc.c
copy to core/include/pxe.h
index 3e69ac1..86d6cfc 100644
--- a/com32/lib/lmalloc.c
+++ b/core/include/pxe.h
@@ -1,6 +1,7 @@
 /* ----------------------------------------------------------------------- *
  *
  *   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
@@ -25,24 +26,18 @@
  *
  * ----------------------------------------------------------------------- */
 
-#include <com32.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslinux/pmapi.h>
+#ifndef PXE_H_
+#define PXE_H_
 
-void *lzalloc(size_t size)
-{
-    void *p;
-    p = lmalloc(size);
-    if (!p)
-	errno = ENOMEM;
-    else
-	memset(p, 0, size);
-    return p;
-}
+#include <stdio.h>
+#include <stdint.h>
 
-void lfree(void *ptr)
+extern uint32_t dns_resolv(const char *);
+
+/* Resolve a hostname via DNS */
+static inline uint32_t pxe_dns_resolv(const char *name)
 {
-    free(ptr);
+    return dns_resolv(name);
 }
+
+#endif /* PXE_H_ */
diff --git a/mk/com32.mk b/mk/com32.mk
index 262d2a6..6e7e9a6 100644
--- a/mk/com32.mk
+++ b/mk/com32.mk
@@ -48,7 +48,8 @@ endif
 CFLAGS     = $(GCCOPT) $(GCCWARN) -march=i386 \
 	     -fomit-frame-pointer -D__COM32__ \
 	     -nostdinc -iwithprefix include \
-	     -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE)
+	     -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE) \
+	     -I../../core/include
 SFLAGS     = $(GCCOPT) $(GCCWARN) -march=i386 \
 	     -fomit-frame-pointer -D__COM32__ \
 	     -nostdinc -iwithprefix include \
diff --git a/mk/elf.mk b/mk/elf.mk
index ca06115..c5d5055 100644
--- a/mk/elf.mk
+++ b/mk/elf.mk
@@ -44,7 +44,8 @@ endif
 CFLAGS     = $(GCCOPT) -W -Wall -march=i386 \
 	     -fomit-frame-pointer -D__COM32__ -DDYNAMIC_MODULE \
 	     -nostdinc -iwithprefix include \
-	     -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE)
+	     -I$(com32)/libutil/include -I$(com32)/include $(GPLINCLUDE) \
+	     -I../../core/include
 SFLAGS     = $(GCCOPT) -D__COM32__ -march=i386
 LDFLAGS    = -m elf_i386 -shared --hash-style=gnu -T $(com32)/lib/elf32.ld
 


More information about the Syslinux-commits mailing list