PERFORCE change 124834 for review
Alexey Tarasov
taleks at FreeBSD.org
Tue Aug 7 09:17:02 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=124834
Change 124834 by taleks at taleks_th on 2007/08/07 16:16:08
all: most of all ip4 related uint32_t replaced by PXE_IPADDR. May be usefuil n future.
pxe_dhcp: updated pxe_dhcp_query() in case of bootp() call.
pxe_core: removed unused functions, updated pxe_core_init(), returned static buffers support.
loader.rc: added as example of .rc-script, used during testing of RAM drive loading.
Affected files ...
.. //depot/projects/soc2007/taleks-pxe_http/Makefile#13 edit
.. //depot/projects/soc2007/taleks-pxe_http/httpfs.c#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/libi386_mod/Makefile#1 add
.. //depot/projects/soc2007/taleks-pxe_http/libi386_mod/pxe.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/loader_mod/loader.rc#1 add
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#15 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.h#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_await.c#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#12 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.h#9 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#25 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#21 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.h#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.c#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.h#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.h#6 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_http.c#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_http.h#7 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#14 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.h#9 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#15 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.h#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_segment.c#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#18 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#16 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.c#13 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_udp.c#10 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_udp.h#7 edit
Differences ...
==== //depot/projects/soc2007/taleks-pxe_http/Makefile#13 (text+ko) ====
@@ -34,4 +34,7 @@
#CFLAGS+= -DPXE_HTTP_DEBUG
#CFLAGS+= -DPXE_HTTP_DEBUG_HELL
+# define to get more PXE related code and testing functions
+CFLAGS+= -DPXE_MORE
+
.include <bsd.lib.mk>
==== //depot/projects/soc2007/taleks-pxe_http/httpfs.c#6 (text+ko) ====
@@ -87,7 +87,7 @@
pxe_memset(httpfile, 0, sizeof(PXE_HTTP_HANDLE));
- httpfile->ip = pxe_get_ip32(PXE_IP_WWW);
+ pxe_memcpy(pxe_get_ip(PXE_IP_WWW), &httpfile->addr, sizeof(PXE_IPADDR));
httpfile->offset = 0;
httpfile->socket = -1;
@@ -100,10 +100,7 @@
/* TODO: may be implement getting name by PTR resource records */
- PXE_IPADDR server;
- server.ip = httpfile->ip;
-
- httpfile->servername = strdup(inet_ntoa(server.ip));
+ httpfile->servername = strdup(inet_ntoa(httpfile->addr.ip));
if (httpfile->servername == NULL) {
handle_cleanup(httpfile);
==== //depot/projects/soc2007/taleks-pxe_http/libi386_mod/pxe.c#3 (text+ko) ====
@@ -201,13 +201,17 @@
}
- if (pxe_get_ip32(PXE_IP_ROOT) == 0) {
+ const PXE_IPADDR *addr = pxe_get_ip(PXE_IP_ROOT);
+
+ if (addr->ip == 0) {
#ifdef PXE_BOOTP_USE_LIBSTAND
pxe_dhcp_query(0);
- if (pxe_get_ip32(PXE_IP_ROOT) == 0)
- pxe_set_ip32(PXE_IP_ROOT,
- pxe_get_ip32(PXE_IP_SERVER));
+ addr = pxe_get_ip(PXE_IP_ROOT);
+
+ if (addr->ip == 0)
+ pxe_set_ip(PXE_IP_ROOT,
+ pxe_get_ip(PXE_IP_SERVER));
#endif
if (!rootpath[1])
@@ -220,9 +224,12 @@
if (i && i != FNAME_SIZE && rootpath[i] == ':') {
rootpath[i++] = '\0';
- if (inet_addr(&rootpath[0]) != INADDR_NONE)
- pxe_set_ip32(PXE_IP_ROOT,
- inet_addr(&rootpath[0]));
+ if (inet_addr(&rootpath[0]) != INADDR_NONE) {
+
+ PXE_IPADDR root_addr;
+ root_addr.ip = inet_addr(&rootpath[0]);
+ pxe_set_ip(PXE_IP_ROOT, &root_addr);
+ }
pxe_memcpy(&rootpath[i], &temp[0],
strlen(&rootpath[i])+1);
@@ -233,7 +240,7 @@
struct in_addr tmp_in;
- tmp_in.s_addr = pxe_get_ip32(PXE_IP_ROOT);
+ tmp_in.s_addr = pxe_get_ip(PXE_IP_ROOT)->ip;
#ifdef PXE_DEBUG
printf("pxe_open: server addr: %s\n",
inet_ntoa(tmp_in));
@@ -241,17 +248,17 @@
setenv("boot.nfsroot.server",
inet_ntoa(tmp_in), 1);
- tmp_in.s_addr = pxe_get_ip32(PXE_IP_GATEWAY);
+ tmp_in.s_addr = pxe_get_ip(PXE_IP_GATEWAY)->ip;
setenv("boot.netif.gateway", inet_ntoa(tmp_in), 1);
#ifdef PXE_DEBUG
printf("pxe_open: server path: %s\n", rootpath);
printf("pxe_open: gateway ip: %s\n",
inet_ntoa(tmp_in));
#endif
- tmp_in.s_addr = pxe_get_ip32(PXE_IP_MY);
+ tmp_in.s_addr = pxe_get_ip(PXE_IP_MY)->ip;
setenv("boot.netif.ip", inet_ntoa(tmp_in), 1);
- tmp_in.s_addr = pxe_get_ip32(PXE_IP_NETMASK);
+ tmp_in.s_addr = pxe_get_ip(PXE_IP_NETMASK)->ip;
setenv("boot.netif.netmask", inet_ntoa(tmp_in), 1);
sprintf(temp, "%6D", pxe_get_mymac(), ":");
@@ -260,11 +267,11 @@
setenv("boot.nfsroot.path", rootpath, 1);
#ifdef PXEHTTP_UDP_FOR_LIBSTAND
- gateip.s_addr = pxe_get_ip32(PXE_IP_GATEWAY);
- rootip.s_addr = pxe_get_ip32(PXE_IP_ROOT);
- netmask = pxe_get_ip32(PXE_IP_NETMASK);
- myip.s_addr = pxe_get_ip32(PXE_IP_MY);
- nameip.s_addr = pxe_get_ip32(PXE_IP_NAMESERVER);
+ gateip.s_addr = pxe_get_ip(PXE_IP_GATEWAY)->ip;
+ rootip.s_addr = pxe_get_ip(PXE_IP_ROOT)->ip;
+ netmask = pxe_get_ip(PXE_IP_NETMASK)->ip;
+ myip.s_addr = pxe_get_ip(PXE_IP_MY)->ip;
+ nameip.s_addr = pxe_get_ip(PXE_IP_NAMESERVER)->ip;
#endif
}
}
@@ -328,7 +335,10 @@
t_PXENV_UDP_OPEN *udpopen_p = (t_PXENV_UDP_OPEN *)scratch_buffer;
bzero(udpopen_p, sizeof(*udpopen_p));
- udpopen_p->src_ip = pxe_get_ip32(PXE_IP_MY);
+
+ const PXE_IPADDR *my = pxe_get_ip(PXE_IP_MY);
+ udpopen_p->src_ip = my->ip;
+
pxe_core_call(PXENV_UDP_OPEN);
if (udpopen_p->status != 0) {
@@ -365,13 +375,14 @@
#ifdef PXE_DEBUG
printf("pxe_netif_init(): called.\n");
#endif
- uint8_t* mac = pxe_get_mymac();
+ uint8_t *mac = pxe_get_mymac();
int i;
for (i = 0; i < 6; ++i)
desc->myea[i] = mac[i];
-
- desc->xid = pxe_get_ip32(PXE_IP_MY);
+
+ const PXE_IPADDR *my = pxe_get_ip(PXE_IP_MY);
+ desc->xid = my->ip;
}
static int
@@ -458,8 +469,11 @@
inet_ntoa(h->destip), ntohs(h->destport));
#endif
void *ipdata = pkt - sizeof(PXE_UDP_PACKET);
+
+ PXE_IPADDR dst;
+ dst.ip = h->destip.s_addr;
- if (!pxe_udp_send(ipdata, h->destip.s_addr, ntohs(h->destport),
+ if (!pxe_udp_send(ipdata, &dst, ntohs(h->destport),
ntohs(h->myport), len + sizeof(PXE_UDP_PACKET)))
{
printf("sendudp(): failed\n");
==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#15 (text+ko) ====
@@ -68,11 +68,13 @@
/* filling source related data: client ip & MAC */
pxe_memcpy(pxe_get_mymac(), packet_to_send.body.src_hwaddr, 6);
- packet_to_send.body.src_paddr = pxe_get_ip32(PXE_IP_MY);
+
+ const PXE_IPADDR *addr = pxe_get_ip(PXE_IP_MY);;
+ packet_to_send.body.src_paddr = addr->ip;
/* filling entry for own ip/mac*/
pxe_memcpy(pxe_get_mymac(), arp_table[MAX_ARP_ENTRIES].mac, 6);
- arp_table[MAX_ARP_ENTRIES].ip4.ip = pxe_get_ip32(PXE_IP_MY);
+ arp_table[MAX_ARP_ENTRIES].addr.ip = addr->ip;
/* setting broadcast target address */
pxe_memset(packet_to_send.body.target_hwaddr, 0xff, 6);
@@ -96,7 +98,7 @@
for (; entry < MAX_ARP_ENTRIES + 1; ++entry) {
- if (arp_table[entry].ip4.ip == ip) {
+ if (arp_table[entry].addr.ip == ip) {
uint8_t *mac = &arp_table[entry].mac[0];
#ifdef PXE_ARP_DEBUG_HELL
@@ -124,21 +126,18 @@
for (; entry < limit; ++entry) {
- PXE_IPADDR ip;
- uint8_t *mac = arp_table[entry].mac;
- ip.ip = arp_table[entry].ip4.ip;
-
- if ( (ip.ip == 0) || (mac == NULL) )
+ if ( (arp_table[entry].addr.ip == 0) ||
+ (arp_table[entry].mac == NULL) )
continue;
- printf("%d.%d.%d.%d\t%2x:%2x:%2x:%2x:%2x:%2x\n",
- ip.octet[0], ip.octet[1], ip.octet[2], ip.octet[3],
- mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
- );
+ printf("%s\t%6D\n",
+ inet_ntoa(arp_table[entry].addr.ip),
+ arp_table[entry].mac, ":");
}
}
-#endif
+#endif /* PXE_MORE */
+
/*
* pxe_arp_protocol() - process received arp packet, this function is called in
* style of pxe_protocol_call function type, but last
@@ -162,12 +161,14 @@
uint8_t *mac_src = arp_reply->body.src_hwaddr;
uint8_t *mac_dst = arp_reply->body.target_hwaddr;
PXE_IPADDR ip4_src;
- PXE_IPADDR ip4_dst;
+ PXE_IPADDR ip4_dst;
+
+ const PXE_IPADDR *addr = pxe_get_ip(PXE_IP_MY);
ip4_src.ip = arp_reply->body.src_paddr;
ip4_dst.ip = arp_reply->body.target_paddr;
- if (ip4_src.ip == pxe_get_ip32(PXE_IP_MY)) {
+ if (ip4_src.ip == addr->ip) {
/* got broadcast send by us */
#ifdef PXE_ARP_DEBUG_HELL
printf("arp request from myself ignored.\n");
@@ -176,21 +177,15 @@
}
#ifdef PXE_ARP_DEBUG
- printf("arp request from %x:%x:%x:%x:%x:%x/%d.%d.%d.%d\n\t"
- " to: %x:%x:%x:%x:%x:%x/%d.%d.%d.%d\n",
- mac_src[0], mac_src[1], mac_src[2],
- mac_src[3], mac_src[4], mac_src[5],
- ip4_src.octet[0], ip4_src.octet[1],
- ip4_src.octet[2], ip4_src.octet[3],
- mac_dst[0], mac_dst[1], mac_dst[2],
- mac_dst[3], mac_dst[4], mac_dst[5],
- ip4_dst.octet[0], ip4_dst.octet[1],
- ip4_dst.octet[2], ip4_dst.octet[3]
- );
+ printf("arp request from %6D/%s\n\t",
+ mac_src, ":", inet_ntoa(ip4_src.ip));
+
+ printf("to: %6D/%s\n",
+ mac_dst, ":", inet_ntoa(ip4_dst.ip));
#endif
/* somebody is looking for us */
- if (ip4_dst.ip == arp_table[MAX_ARP_ENTRIES].ip4.ip) {
+ if (ip4_dst.ip == arp_table[MAX_ARP_ENTRIES].addr.ip) {
pxe_memcpy(arp_reply->body.src_hwaddr,
packet_to_send.body.target_hwaddr, 6);
@@ -262,7 +257,7 @@
pxe_memcpy(&arp_reply->body.src_hwaddr,
&arp_table[arp_usage % MAX_ARP_ENTRIES].mac, 6);
- arp_table[arp_usage % MAX_ARP_ENTRIES].ip4.ip =
+ arp_table[arp_usage % MAX_ARP_ENTRIES].addr.ip =
arp_reply->body.src_paddr;
++arp_usage;
@@ -325,7 +320,7 @@
switch (function) {
case PXE_AWAIT_STARTTRY: /* handle start of new try */
- if (!pxe_arp_send_whois(wait_data->ip)) {
+ if (!pxe_arp_send_whois(wait_data->addr.ip)) {
/* failed to send request, try once more
* after waiting a little
*/
@@ -338,7 +333,7 @@
/* check if ARP protocol was called and
* arp_table updated
*/
- res = pxe_arp_table_search(wait_data->ip);
+ res = pxe_arp_table_search(wait_data->addr.ip);
if (res != NULL) {
wait_data->mac = res;
return (PXE_AWAIT_COMPLETED);
@@ -370,9 +365,9 @@
* not NULL - pointer to MAC address
*/
const MAC_ADDR *
-pxe_arp_ip4mac(uint32_t ip)
+pxe_arp_ip4mac(const PXE_IPADDR *addr)
{
- const MAC_ADDR *res = pxe_arp_table_search(ip);
+ const MAC_ADDR *res = pxe_arp_table_search(addr->ip);
if (res != NULL)
return (res);
@@ -381,7 +376,7 @@
#endif
PXE_ARP_WAIT_DATA wait_data;
- wait_data.ip = ip;
+ wait_data.addr.ip = addr->ip;
wait_data.mac = NULL;
pxe_await(pxe_arp_await, PXE_MAX_ARP_TRY, PXE_TIME_TO_DIE, &wait_data);
==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.h#10 (text+ko) ====
@@ -52,7 +52,7 @@
#define PXE_ARP_SNIFF
typedef struct pxe_arp_entry {
- PXE_IPADDR ip4;
+ PXE_IPADDR addr;
MAC_ADDR mac;
} PXE_ARP_ENTRY;
@@ -61,7 +61,7 @@
void pxe_arp_init();
/* find MAC by provided ip */
-const MAC_ADDR *pxe_arp_ip4mac(uint32_t ip);
+const MAC_ADDR *pxe_arp_ip4mac(const PXE_IPADDR *addr);
/* protocol handler for received packets */
int pxe_arp_protocol(PXE_PACKET *pack, uint8_t function);
@@ -99,7 +99,7 @@
} __packed PXE_ARP_PACK_DATA;
typedef struct pxe_arp_wait_data {
- uint32_t ip;
+ PXE_IPADDR addr;
const MAC_ADDR *mac;
} PXE_ARP_WAIT_DATA;
==== //depot/projects/soc2007/taleks-pxe_http/pxe_await.c#4 (text+ko) ====
@@ -116,4 +116,3 @@
*/
return (0);
}
-
==== //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#12 (text+ko) ====
@@ -252,11 +252,11 @@
connection->dst_port = filter->src_port;
connection->src_port = filter->dst_port;
- connection->dst_ip = filter->src_ip;
+ connection->dst.ip = filter->src.ip;
connection->next_recv = 0;
/* NOTE: need to make more correct initial number */
- connection->iss = (filter->src_ip + filter->dst_ip) +
+ connection->iss = (filter->src.ip + filter->dst.ip) +
(uint32_t)pxe_get_secs();
connection->next_send = connection->iss;
@@ -688,4 +688,4 @@
connection->iss, connection->irs);
}
}
-#endif+#endif /* PXE_MORE */
==== //depot/projects/soc2007/taleks-pxe_http/pxe_connection.h#9 (text+ko) ====
@@ -79,7 +79,7 @@
uint16_t src_port; /* source port */
uint16_t dst_port; /* destination port */
- uint32_t dst_ip; /* destination ip */
+ PXE_IPADDR dst; /* destination ip */
PXE_BUFFER *recv; /* recieve buffer */
PXE_BUFFER *send; /* send buffer */
==== //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#25 (text+ko) ====
@@ -46,22 +46,22 @@
* the only difference - installation of isr, that was not needed in pxe.c.
*/
-/* calls PXE/UNDI API, registers of processor must be filled in with
- * appropriate values.
- */
-/* static int pxe_core_call(int func); */
/* stores data in packet */
static int pxe_core_recieve(PXE_PACKET *pack, void *data, size_t size);
uint8_t *scratch_buffer = NULL;
uint8_t *data_buffer = NULL;
+#ifdef PXE_CORE_STATIC_BUFFERS
+static uint8_t static_scratch_buffer[PXE_BUFFER_SIZE];
+static uint8_t static_data_buffer[PXE_BUFFER_SIZE];
+#endif
+
#ifdef PXE_EXCLUSIVE
static uint8_t exclusive_protocol = 0;
#endif
static pxenv_t *pxenv = NULL; /* PXENV+ */
static pxe_t *pxe = NULL; /* !PXE */
-/* static BOOTPLAYER* bootplayer; /* pointer PXE Cached information. */
/* pxe core structures*/
/* current processing packet */
@@ -76,61 +76,6 @@
static int pxe_state = PXE_DOWN;
-/* pxe_core_undi_startup() - performs UNDI startup call during pxe_core_init()
- * in:
- * none
- * out:
- * 1 - success
- * 0 - failed
- */
-int
-pxe_core_undi_startup()
-{
- t_PXENV_UNDI_STARTUP *undi_startup =
- (t_PXENV_UNDI_STARTUP *)scratch_buffer;
-
-#ifdef PXE_CORE_DEBUG
- printf("pxe_core_undi_startup(): started\n");
-#endif
-
- undi_startup->Status = 0;
-
- int status = pxe_core_call(PXENV_UNDI_STARTUP);
-
- if (!status)
- printf("pxe_core_undi_startup(): status 0x%x\n",
- undi_startup->Status);
-
- return (status);
-}
-
-/* pxe_core_undi_init() - performs UNDI initialization
- * in:
- * none
- * out:
- * 1 - success
- * 0 - failed
- */
-int pxe_core_undi_init()
-{
- t_PXENV_UNDI_INITIALIZE *undi_init =
- (t_PXENV_UNDI_INITIALIZE *)scratch_buffer;
-
-#ifdef PXE_CORE_DEBUG
- printf("pxe_core_undi_init(): started\n");
-#endif
-
- pxe_memset(undi_init, 0, sizeof(t_PXENV_UNDI_INITIALIZE));
-
- int status = pxe_core_call(PXENV_UNDI_INITIALIZE);
-
- if (!status)
- printf("pxe_core_undi_init(): status 0x%x\n",
- undi_init->Status);
-
- return (status);
-}
-
/* pxe_core_init() - performs initialization of all PXE related code
* in:
* pxenv_p - pointer to PXENV+ structure
@@ -162,6 +107,7 @@
pxenv = pxenv_p;
pxe = pxe_p;
+#ifndef PXE_CORE_STATIC_BUFFERS
/* 0. initing scratch and data buffers */
data_buffer = pxe_alloc(PXE_BUFFER_SIZE);
@@ -175,7 +121,10 @@
pxe_free(data_buffer);
return (0);
}
-
+#else
+ data_buffer = static_data_buffer;
+ scratch_buffer = static_scratch_buffer;
+#endif
/* 1. determine PXE API entry point */
if(pxenv_p == NULL)
return (0);
@@ -262,9 +211,9 @@
/* getting Boot Server Discovery reply */
/* pointer to PXE Cached information. */
- BOOTPLAYER* bootplayer = data_buffer;
+ BOOTPLAYER* bootplayer = (BOOTPLAYER *)data_buffer;
+
gci_p->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;
-
gci_p->BufferSize = sizeof(BOOTPLAYER);
gci_p->Buffer.segment = VTOPSEG(bootplayer);
gci_p->Buffer.offset = VTOPOFF(bootplayer);
@@ -302,30 +251,37 @@
}
/* showing information about NIC */
- PXE_IPADDR nic_ip;
-
- nic_ip.ip = bootplayer->yip; /* my ip */
- printf("my ip: %d.%d.%d.%d\n",
- nic_ip.octet[0], nic_ip.octet[1], nic_ip.octet[2], nic_ip.octet[3]);
+ PXE_IPADDR addr;
+ addr.ip = bootplayer->yip; /* my ip */
+
+ printf("my ip: %s\n", inet_ntoa(addr.ip));
/* my MAC */
pxe_memcpy(&bootplayer->CAddr, &nic_mac, MAC_ADDR_LEN);
printf("my MAC: %6D\n", nic_mac, ":");
/* setting default ips*/
- pxe_set_ip32(PXE_IP_MY, bootplayer->yip); /* nic ip */
- pxe_set_ip32(PXE_IP_SERVER, bootplayer->sip); /* boot server ip */
+ pxe_set_ip(PXE_IP_MY, &addr); /* nic ip */
+
+ addr.ip = bootplayer->sip; /* boot server ip */
+ pxe_set_ip(PXE_IP_SERVER, &addr);
+
+ /* setting next to default ip (boot server ip) */
+ /* nameserver ip*/
+ pxe_set_ip(PXE_IP_NAMESERVER, &addr);
+ /* gateway ip */
+ pxe_set_ip(PXE_IP_GATEWAY, &addr);
+
- /* nameserver ip, default to 192.168.0.1 */
- pxe_set_ip32(PXE_IP_NAMESERVER, 0x0100a8c0);
- /* gateway ip, default to 192.168.0.1 */
- pxe_set_ip32(PXE_IP_GATEWAY, 0x0100a8c0);
+ /* web server */
+ addr.ip = 0;
+ pxe_set_ip(PXE_IP_WWW, &addr);
+
+ addr.ip = 0xffffffff;
/* netmask, default to 255.255.255.0 */
- pxe_set_ip32(PXE_IP_NETMASK, 0x00ffffff);
+ pxe_set_ip(PXE_IP_NETMASK, &addr);
/* broadcast address, default to 255.255.255.255 */
- pxe_set_ip32(PXE_IP_BROADCAST, 0xffffffff);
- /* web server */
- pxe_set_ip32(PXE_IP_WWW, 0x0);
+ pxe_set_ip(PXE_IP_BROADCAST, &addr);
/* initing modules */
pxe_arp_init();
@@ -345,7 +301,7 @@
pxe_dhcp_query(bootplayer->ident);
#endif
/* initing route tables, using DHCP reply data */
- pxe_ip_route_init(pxe_get_ip32(PXE_IP_GATEWAY));
+ pxe_ip_route_init(pxe_get_ip(PXE_IP_GATEWAY));
#ifdef PXE_CORE_DEBUG
printf("pxe_core_init(): ended.\n");
@@ -492,13 +448,14 @@
t_PXENV_UNDI_SHUTDOWN *undi_shutdown_p =
(t_PXENV_UNDI_SHUTDOWN *)scratch_buffer;
-
-/* pxe_core_call(PXENV_UNDI_SHUTDOWN);
+/*
+ pxe_core_call(PXENV_UNDI_SHUTDOWN);
pxe_core_call(PXENV_UNLOAD_STACK);
*/
+#ifndef PXE_CORE_STATIC_BUFFERS
pxe_free(scratch_buffer);
pxe_free(data_buffer);
-
+#endif
/* make pxe_core_call() unavailable */
pxe_state = PXE_DOWN;
@@ -1030,22 +987,22 @@
return (const MAC_ADDR *)&nic_mac;
}
-/* pxe_get_ip32() - returns ip related data, specified by id parameter
+/* pxe_get_ip() - returns ip related data, specified by id parameter
* in:
* id - id of needed data (PXE_IP_ constants)
* out:
* associated with this id value
*/
-uint32_t
-pxe_get_ip32(uint8_t id)
+const PXE_IPADDR *
+pxe_get_ip(uint8_t id)
{
if (id < PXE_IP_MAX)
- return (core_ips[id].ip);
+ return (&core_ips[id]);
return (0);
}
-/* pxe_set_ip32() - sets ip related data, specified by id parameter
+/* pxe_set_ip() - sets ip related data, specified by id parameter
* in:
* id - id of needed data (PXE_IP_ constants)
* new_ip - new uint32_t data
@@ -1053,10 +1010,10 @@
* none
*/
void
-pxe_set_ip32(uint8_t id, uint32_t new_ip)
+pxe_set_ip(uint8_t id, const PXE_IPADDR *new_ip)
{
if (id < PXE_IP_MAX) {
- core_ips[id].ip = new_ip;
+ pxe_memcpy(new_ip, &core_ips[id], sizeof(PXE_IPADDR));
}
}
==== //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#21 (text+ko) ====
@@ -37,9 +37,16 @@
#include <stddef.h>
#include "../libi386/pxe.h"
+#include "pxe_ip.h"
#define PXE_BUFFER_SIZE 0x0800
+/* define to use statically allocated buffers */
+#define PXE_CORE_STATIC_BUFFERS
+
+/* packet states for packets, used by pxe_core.
+ * Currently (only one packet at any time) - is unused.
+ */
#define PXE_PACKET_STATE_FREE 0
#define PXE_PACKET_STATE_USING 1
@@ -134,8 +141,8 @@
#define PXE_IP_WWW 7
#define PXE_IP_ROOT 7
#define PXE_IP_MAX 8
-uint32_t pxe_get_ip32(uint8_t id);
-void pxe_set_ip32(uint8_t id, uint32_t ip);
+const PXE_IPADDR *pxe_get_ip(uint8_t id);
+void pxe_set_ip(uint8_t id, const PXE_IPADDR *ip);
/* returns time in seconds */
time_t pxe_get_secs();
==== //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#8 (text+ko) ====
@@ -29,6 +29,7 @@
#include "pxe_core.h"
#include "pxe_dhcp.h"
+#include "pxe_ip.h"
#ifdef PXE_BOOTP_USE_LIBSTAND
#include <netinet/in.h>
@@ -96,19 +97,19 @@
case PXE_DHCP_OPT_NETMASK:
printf("netmask: %d.%d.%d.%d\n",
*(p + 1), *(p + 2), *(p + 3), *(p + 4));
- result->netmask = *((uint32_t *)(p + 1));
+ result->netmask.ip = *((uint32_t *)(p + 1));
break;
case PXE_DHCP_OPT_ROUTER:
printf("first router: %d.%d.%d.%d\n",
*(p + 1), *(p + 2), *(p + 3), *(p + 4));
- result->gw = *((uint32_t *)(p + 1));
+ result->gw.ip = *((uint32_t *)(p + 1));
break;
case PXE_DHCP_OPT_NAMESERVER:
printf("first nameserver: %d.%d.%d.%d\n",
*(p + 1), *(p + 2), *(p + 3), *(p + 4));
- result->ns = *((uint32_t *)(p + 1));
+ result->ns.ip = *((uint32_t *)(p + 1));
break;
case PXE_DHCP_OPT_TYPE:
@@ -122,7 +123,7 @@
case PXE_DHCP_OPT_WWW_SERVER:
printf("www server ip: %d.%d.%d.%d\n",
*(p + 1), *(p + 2), *(p + 3), *(p + 4));
- result->www = *((uint32_t *)(p + 1));
+ result->www.ip = *((uint32_t *)(p + 1));
break;
case PXE_DHCP_OPT_ROOTPATH:
@@ -154,7 +155,7 @@
case PXE_DHCP_OPT_BROADCAST_IP:
printf("broadcast: %d.%d.%d.%d\n",
*(p + 1), *(p + 2), *(p + 3), *(p + 4));
- result->bcast_addr = *((uint32_t *)(p + 1));
+ result->bcast_addr.ip = *((uint32_t *)(p + 1));
break;
case PXE_DHCP_OPT_ID:
@@ -205,7 +206,9 @@
dhcp_hdr->hops = 0;
dhcp_hdr->secs = 0;
dhcp_hdr->xid = wait_data->xid;
- dhcp_hdr->ciaddr = pxe_get_ip32(PXE_IP_MY);
+
+ const PXE_IPADDR *my = pxe_get_ip(PXE_IP_MY);
+ dhcp_hdr->ciaddr = my->ip;
dhcp_hdr->magic = htonl(PXE_MAGIC_DHCP);
pxe_memcpy(pxe_get_mymac(), dhcp_hdr->chaddr, dhcp_hdr->hlen);
@@ -233,10 +236,10 @@
options = add_option(options, PXE_DHCP_OPT_TYPE, &message_type, 1);
/* requesting for my ip */
- uint32_t client_ip = pxe_get_ip32(PXE_IP_MY);
+ const PXE_IPADDR *client_ip = pxe_get_ip(PXE_IP_MY);
options = add_option(options, PXE_DHCP_OPT_REQUEST_IP,
- &client_ip, sizeof(client_ip));
+ &(client_ip->ip), sizeof(client_ip->ip));
/* end of options */
options = add_option(options, PXE_DHCP_OPT_END, NULL, 0);
@@ -258,7 +261,10 @@
return (0);
}
- if (send_size != pxe_sendto(socket, PXE_IP_BCAST, PXE_DHCP_SERVER_PORT,
+ PXE_IPADDR bcast;
+ bcast.ip = PXE_IP_BCAST;
+
+ if (send_size != pxe_sendto(socket, &bcast, PXE_DHCP_SERVER_PORT,
wait_data->data, send_size))
{
printf("dhcp_send_request(): failed to send DHCP request.\n");
@@ -314,20 +320,20 @@
}
/* if successfuly parsed, setting appropriate ip data */
- if (opts_result.ns)
- pxe_set_ip32(PXE_IP_NAMESERVER, opts_result.ns);
+ if (opts_result.ns.ip)
+ pxe_set_ip(PXE_IP_NAMESERVER, &opts_result.ns);
- if (opts_result.gw)
- pxe_set_ip32(PXE_IP_GATEWAY, opts_result.gw);
+ if (opts_result.gw.ip)
+ pxe_set_ip(PXE_IP_GATEWAY, &opts_result.gw);
- if (opts_result.netmask)
- pxe_set_ip32(PXE_IP_NETMASK, opts_result.netmask);
+ if (opts_result.netmask.ip)
+ pxe_set_ip(PXE_IP_NETMASK, &opts_result.netmask);
- if (opts_result.bcast_addr)
- pxe_set_ip32(PXE_IP_BROADCAST, opts_result.bcast_addr);
+ if (opts_result.bcast_addr.ip)
+ pxe_set_ip(PXE_IP_BROADCAST, &opts_result.bcast_addr);
- if (opts_result.www)
- pxe_set_ip32(PXE_IP_WWW, opts_result.www);
+ if (opts_result.www.ip)
+ pxe_set_ip(PXE_IP_WWW, &opts_result.www);
if (opts_result.rootpath[0])
strcpy(PXENFSROOTPATH, opts_result.rootpath);
@@ -423,10 +429,28 @@
printf("pxe_dhcp_query(): starting libstand bootp()\n");
bootp(pxe_sock, BOOTP_PXE);
- pxe_set_ip32(PXE_IP_NAMESERVER, nameip.s_addr);
- pxe_set_ip32(PXE_IP_GATEWAY, gateip.s_addr);
- pxe_set_ip32(PXE_IP_NETMASK, netmask);
- pxe_set_ip32(PXE_IP_ROOT, rootip.s_addr);
+ /* setting pxe_core variables */
+ PXE_IPADDR addr;
+
+ addr.ip = nameip.s_addr;
+ pxe_set_ip(PXE_IP_NAMESERVER, &addr);
+
+ addr.ip = netmask;
+ pxe_set_ip(PXE_IP_NETMASK, &addr);
+
+ addr.ip = rootip.s_addr;
+ pxe_set_ip(PXE_IP_ROOT, &addr);
+
+ /* "network route". direct connect for those addresses */
+ pxe_ip_route_add(pxe_get_ip(PXE_IP_MY), netmask, NULL);
+
+ addr.ip = gateip.s_addr;
+ pxe_set_ip(PXE_IP_GATEWAY, &addr);
+
+ /* need update gateway information, cause it's already set to default */
+ pxe_ip_route_default(&addr);
+
+
}
#endif /* PXE_BOOTP_USE_LIBSTAND */
==== //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.h#8 (text+ko) ====
@@ -37,7 +37,7 @@
/* define if want use bootp() instead of functions, provided by
* pxe_dhcp module */
-/* #define PXE_BOOTP_USE_LIBSTAND */
+#define PXE_BOOTP_USE_LIBSTAND
/* DHCP request/reply packet header */
typedef struct pxe_dhcp_hdr {
@@ -123,11 +123,11 @@
} PXE_DHCP_WAIT_DATA;
typedef struct pxe_dhcp_parse_result {
- uint32_t netmask;
- uint32_t bcast_addr;
- uint32_t ns;
- uint32_t gw;
- uint32_t www;
+ PXE_IPADDR netmask;
+ PXE_IPADDR bcast_addr;
+ PXE_IPADDR ns;
+ PXE_IPADDR gw;
+ PXE_IPADDR www;
char rootpath[256];
uint8_t message_type;
} PXE_DHCP_PARSE_RESULT;
==== //depot/projects/soc2007/taleks-pxe_http/pxe_dns.c#7 (text+ko) ====
@@ -33,6 +33,8 @@
#include "pxe_ip.h"
#include "pxe_sock.h"
+static PXE_DNS_WAIT_DATA static_wait_data;
+
/* write_question_for()- writes labels for provided domain name
* in:
* question - where to write
@@ -85,18 +87,19 @@
/* create_dns_packet()- creates DNS request packet
* in:
- * name - domain name to resolve
- * data - buffer for request packet.
- * max_size - size of buffer [NOT IMPLEMENTED]
+ * wd - pointer to wait data structure
* id - request id to distinguish requests
* out:
* 0 - failed
* >0 - size of created packet
*/
int
-create_dns_packet(char *name, void *data, int max_size, uint16_t id,
- uint16_t query_type)
+create_dns_packet(PXE_DNS_WAIT_DATA *wd, uint16_t id, uint16_t query_type)
{
+ char *name = wd->name;
+ void *data = wd->data;
+ int max_size = wd->size;
+
PXE_DNS_REQUEST_HDR *request = (PXE_DNS_REQUEST_HDR *)data;
pxe_memset(request, 0, sizeof(PXE_DNS_REQUEST_HDR));
@@ -175,17 +178,19 @@
/* parse_dns_reply() - parses reply from DNS server
* in:
- * data - pointer to buffer, containing packet data
- * size - buffer size
- * name - domain name to resolve
- * canme - where to store cname if found.
+ * wd - pointer to waiting data structure
* out:
* 0 - parsing failed, or packet has no information about our domain
- * ip - success, 32bit ip4 address
+ * 1 - success, wait_data->result contains ip
*/
-uint32_t
-parse_dns_reply(uint8_t* data, int size, char *name, uint16_t id, uint8_t *cname)
+int
+parse_dns_reply(PXE_DNS_WAIT_DATA *wd)
{
+ uint8_t *data = wd->data;
+ int size = wd->size;
+ char *name = wd->name;
+ uint16_t id = wd->id;
+ uint8_t *cname = wd->cname;
cname[0] = 0;
@@ -331,19 +336,15 @@
}
/* answer points to rdata = ip4 */
- PXE_IPADDR ret;
-
- ret.octet[0] = answer[0];
- ret.octet[1] = answer[1];
- ret.octet[2] = answer[2];
- ret.octet[3] = answer[3];
+
+ wd->result.octet[0] = answer[0];
+ wd->result.octet[1] = answer[1];
+ wd->result.octet[2] = answer[2];
+ wd->result.octet[3] = answer[3];
#ifdef PXE_DEBUG
- printf(" = %d.%d.%d.%d\n",
- ret.octet[0], ret.octet[1],
- ret.octet[2], ret.octet[3]
- );
+ printf(" = %s\n", inet_ntoa(wd->result.ip));
#endif
- return ret.ip;
+ return (1);
}
#ifdef PXE_DEBUG
@@ -433,8 +434,8 @@
return (0);
}
- uint16_t size = create_dns_packet(wait_data->name, wait_data->data,
- wait_data->size, wait_data->id, PXE_DNS_QUERY_A);
+ uint16_t size = create_dns_packet(wait_data, wait_data->id,
+ PXE_DNS_QUERY_A);
if (size == 0) {
printf("dns_request(): failed to create request.\n");
@@ -442,7 +443,7 @@
return (0);
}
- if (size != pxe_sendto(socket, pxe_get_ip32(PXE_IP_NAMESERVER), 53,
+ if (size != pxe_sendto(socket, pxe_get_ip(PXE_IP_NAMESERVER), 53,
wait_data->data, size))
{
printf("dns_request(): failed to send DNS request.\n");
@@ -494,12 +495,9 @@
printf("dns_await(): Received DNS reply (%d bytes).\n",
size);
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list