Permalink
Browse files

socket api plumbing + deterboot

This commit introduces the minimal changes necessary to expose the udp
portion of the lwip sockets api to a syslinux module. Additionally it
shows the use of this exposed portion of the api through the deterboot
module. At the time of this commit, the deterboot module itself is
trivial and only verifies that sendto and recvfrom work as expected.

In the commits that follow:
- testing will be added for the lwip udp sockets api
- the deterboot module will be actually implemented

It is not our expectation that syslinux will incorporate the deterboot
module on the basis of its general applicability as it is only useful
within the context of the deter testbed. However, it may prove to be a
useful form of documentation by example for using the newly exposed
sockets api.
  • Loading branch information...
rcgoodfellow committed Mar 26, 2017
1 parent 346d227 commit fefda68aaa9502af60987d12fa4254728e13b33b
@@ -54,3 +54,6 @@
/bios
/efi32
/efi64
*.sw*
tags
@@ -1,5 +1,5 @@
SUBDIRS = tools lib libutil gpllib libupload elflink/ldlinux modules mboot \
menu samples elflink rosh cmenu hdt gfxboot sysdump lua/src chain
menu samples elflink rosh cmenu hdt gfxboot sysdump lua/src chain deterboot
.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)
@@ -0,0 +1,46 @@
## -----------------------------------------------------------------------
##
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
## Boston MA 02110-1301, USA; either version 2 of the License, or
## (at your option) any later version; incorporated herein by reference.
##
## -----------------------------------------------------------------------
##
## Deterboot module
##
VPATH = $(SRC)
include $(MAKEDIR)/elf.mk
#LNXLIBS = $(objdir)/com32/libutil/libutil_lnx.a
MODULES = deterboot.c32
TESTFILES =
CFLAGS += -I$(topdir)/core
CFLAGS += -I$(topdir)/core/lwip/src/include
CFLAGS += -I$(topdir)/core/lwip/src/include/ipv4
OBJS = deterboot.o
all: $(MODULES) $(TESTFILES)
deterboot.elf : $(OBJS) $(C_LIBS)
$(LD) $(LDFLAGS) -o $@ $^
tidy dist:
rm -f *.o *.lo *.a *.lst *.elf .*.d *.tmp
clean: tidy
rm -f *.lnx
spotless: clean
rm -f *.lss *.c32 *.com
rm -f *~ \#*
install:
-include .*.d
@@ -0,0 +1,104 @@
/* -------------------------------------------------------------------------- *
*
* Copyright 2017 Deter-Project - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* deterboot.c
*
* This module implements the Deter stage-0 boot loader
*/
#include <string.h>
#include <stdio.h>
#include <consoles.h>
#include <syslinux/pxe.h>
#include <dhcp.h>
#include <net.h>
#include <netinet/in.h>
#include <lwip/sockets.h>
struct NetInfo
{
struct in_addr myAddr,
bossAddr;
};
int getNetInfo(struct NetInfo *);
int main()
{
console_ansi_std();
printf("Deter Boot\n");
struct NetInfo netinfo;
int err = getNetInfo(&netinfo);
if(err) return 1;
struct sockaddr_in dest;
dest.sin_family = AF_INET;
dest.sin_port = htons(4747);
dest.sin_addr = netinfo.bossAddr;
printf("preparing muffin man\n");
lwip_socket_init();
int sock = socket(AF_INET, SOCK_DGRAM, 0);
char *data = "do you know the muffin man?";
int n = sendto(
sock,
(void*)data, strlen(data),
0,
(struct sockaddr*)&dest, sizeof(dest)
);
printf("muffin man sent (%d)\n", n);
printf("awating muffin response\n");
char buf[128];
n = recvfrom(
sock,
buf,
sizeof(buf),
0,
(struct sockaddr*)&dest, sizeof(dest)
);
printf("muffin response (%d) %.*s\n", n, n, buf);
return 0;
}
int getNetInfo(struct NetInfo *info)
{
void *dhcpdata = NULL;
size_t dhcplen = 0;
int err = pxe_get_cached_info(
PXENV_PACKET_TYPE_DHCP_ACK,
&dhcpdata,
&dhcplen);
if(err)
{
printf("Failed to get network information\n");
return err;
}
struct dhcp_packet *pkt = (struct dhcp_packet*)dhcpdata;
info->myAddr.s_addr = pkt->yiaddr;
info->bossAddr.s_addr = pkt->siaddr;
printf("me: %s\n", inet_ntoa(info->myAddr));
printf("boss: %s\n", inet_ntoa(info->bossAddr));
return 0;
}
@@ -180,6 +180,7 @@ static void lwip_setsockopt_internal(void *arg);
* Initialize this module. This function has to be called before any other
* functions in this module!
*/
__export
void
lwip_socket_init(void)
{
@@ -545,6 +546,7 @@ lwip_listen(int s, int backlog)
return 0;
}
__export
int
lwip_recvfrom(int s, void *mem, size_t len, int flags,
struct sockaddr *from, socklen_t *fromlen)
@@ -784,6 +786,7 @@ lwip_send(int s, const void *data, size_t size, int flags)
return (err == ERR_OK ? (int)size : -1);
}
__export
int
lwip_sendto(int s, const void *data, size_t size, int flags,
const struct sockaddr *to, socklen_t tolen)
@@ -931,6 +934,7 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
return (err == ERR_OK ? short_size : -1);
}
__export
int
lwip_socket(int domain, int type, int protocol)
{
@@ -257,6 +257,7 @@ ipaddr_aton(const char *cp, ip_addr_t *addr)
* @return pointer to a global static (!) buffer that holds the ASCII
* represenation of addr
*/
__export
char *
ipaddr_ntoa(const ip_addr_t *addr)
{
@@ -20,7 +20,8 @@
#define DEFAULT_TCP_RECVMBOX_SIZE 128
#define DEFAULT_ACCEPTMBOX_SIZE 4
#define LWIP_SOCKET 0
#define LWIP_SOCKET 1
#define LWIP_COMPAT_SOCKETS 1
#define MEM_LIBC_MALLOC 0
#define MEMP_MEM_MALLOC 0
@@ -0,0 +1,23 @@
### Syslinux Boot Process
### ~~~~~~~~~~~~~~~~~~~~~
_start1 [ pxelinux.asm #init screen, pxe, fs
| load_env32() [ load_env32.c
| init_module_subsystem() [ " #add core module
| start_ldlinux() [ "
| spawn_load(LDLINUX) [ exec.c #load & start ldlinux (ldlinux.c32, ldlinux.e32 or ldlinux.e64)
| module_load [ elf_module.c
| exit(module->main) [ exit.c #exit the current module and jump into the one being loaded
~ [
| main [ ldlinux.c
| parse_configs() [ readconfig.c
| load_kernel() [ ldlinux.c
| execute() [ execute.c
| create_args_and_load(cmd) [ load_env32.c
| spawn_load(cmd) [ exec.c
| module_load [ elf_module.c
| exit(module->main) [ exit.c
~
| <your module runs here>
@@ -191,7 +191,7 @@ CORELIBOBJS = \
memcpy.o memset.o memcmp.o printf.o strncmp.o vfprintf.o \
strlen.o vsnprintf.o snprintf.o stpcpy.o strcmp.o strdup.o \
strcpy.o strncpy.o setjmp.o fopen.o fread.o fread2.o puts.o \
strtoul.o strntoumax.o strcasecmp.o \
strtoul.o atoi.o strntoumax.o strcasecmp.o \
sprintf.o strlcat.o strchr.o strlcpy.o strncasecmp.o ctypes.o \
fputs.o fwrite2.o fwrite.o fgetc.o fclose.o lmalloc.o \
sys/err_read.o sys/err_write.o sys/null_read.o \

0 comments on commit fefda68

Please sign in to comment.