PERFORCE change 118882 for review
Alexey Tarasov
taleks at FreeBSD.org
Fri Apr 27 15:25:08 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=118882
Change 118882 by taleks at taleks_th on 2007/04/27 15:24:14
Updated to be more style compliant
Affected files ...
.. //depot/projects/soc2007/taleks-pxe_http/pxe_conv.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_conv.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#4 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_http.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#3 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_mem.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_mem.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_mutex.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_mutex.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#2 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.h#2 edit
Differences ...
==== //depot/projects/soc2007/taleks-pxe_http/pxe_conv.c#2 (text+ko) ====
@@ -1,18 +1,20 @@
#include "pxe_conv.h"
+inline uint32_t
+le2be32(uint32_t x)
+{
-
-inline uint32_t le2be32(uint32_t x) {
-
- return ((0x000000ff & x) << 24) |
- ((0x0000ff00 & x) << 8) |
- ((0x00ff0000 & x) >> 8) |
- ((0xff000000 & x) >> 24 );
+ return ((0x000000ff & x) << 24)|
+ ((0x0000ff00 & x) << 8) |
+ ((0x00ff0000 & x) >> 8) |
+ ((0xff000000 & x) >> 24 );
}
-inline uint16_t le2be16(uint16_t x) {
+inline uint16_t
+le2be16(uint16_t x)
+{
- return ((0x00ff & x) << 8) |
- ((0xff00 & x) >> 8);
+ return ((0x00ff & x) << 8) |
+ ((0xff00 & x) >> 8);
}
==== //depot/projects/soc2007/taleks-pxe_http/pxe_conv.h#2 (text+ko) ====
@@ -4,19 +4,17 @@
#include <stdint.h>
/*
- here I'm assumming PXE code is started on x86 arch,
- so host machine arch uses little endian byte order
-*/
+ * here I'm assumming PXE code is started on x86 arch,
+ * so host machine arch uses little endian byte order
+ */
-/* change order for 32bit unsigned int*/
+/* change order for 32bit unsigned int */
uint32_t le2be32(uint32_t x);
-/* change order for 16bit unsigned int*/
+/* change order for 16bit unsigned int */
uint16_t le2be16(uint16_t x);
-/*
- in fact the same functions
-*/
+/* in fact the same functions */
#define be2le32 le2be32
#define be2le16 le2be16
==== //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#4 (text+ko) ====
@@ -1,84 +1,86 @@
#include <stand.h>
#include <string.h>
-#include "pxe_core.h"
-#include "pxe_mem.h"
-#include "pxe_ip.h"
-#include "pxe_mutex.h"
#include "btxv86.h"
#include "pxe.h"
+#include "pxe_core.h"
+#include "pxe_ip.h"
+#include "pxe_mem.h"
+#include "pxe_mutex.h"
/* PXE API calls here will be made in same way as in pxeboot.
- the only difference - installation of isr, that was not needed in pxe.c.
- main problem is that, v86 monitors reflects interrupts,
- we need to change IDT, for correct irq and call pxe_core_isr() from it.
-*/
+ * the only difference - installation of isr, that was not needed in pxe.c.
+ * main problem is that, v86 monitors reflects interrupts,
+ * we need to change IDT, for correct irq and call pxe_core_isr() from it.
+ */
/* NOTE: to think about using of this buffers */
#define PXE_BUFFER_SIZE 0x2000
#define PXE_TFTP_BUFFER_SIZE 512
static char scratch_buffer[PXE_BUFFER_SIZE];
static char data_buffer[PXE_BUFFER_SIZE];
-static pxenv_t *pxenv_p = NULL; /* PXENV+ */
-static pxe_t *pxe_p = NULL; /* !PXE */
-static BOOTPLAYER bootplayer; /* PXE Cached information. */
+static pxenv_t *pxenv_p = NULL; /* PXENV+ */
+static pxe_t *pxe_p = NULL; /* !PXE */
+static BOOTPLAYER bootplayer; /* PXE Cached information. */
/* defined in pxetramp.s */
-extern u_int16_t __bangpxeseg;
-extern u_int16_t __bangpxeoff;
-extern void __bangpxeentry(void);
-extern u_int16_t __pxenvseg;
-extern u_int16_t __pxenvoff;
-extern void __pxenventry(void);
+extern uint16_t __bangpxeseg;
+extern uint16_t __bangpxeoff;
+extern void __bangpxeentry(void);
+extern uint16_t __pxenvseg;
+extern uint16_t __pxenvoff;
+extern void __pxenventry(void);
-/**/
-pxe_packet core_packets[PXE_MAX_PACKETS];
-pxe_protocol_call core_protocol[256];
-pxe_mutex core_mutex={0,0};
+/* pxe core structures*/
+pxe_packet core_packets[PXE_MAX_PACKETS]; /* buffered packets */
+pxe_protocol_call core_protocol[256]; /* protocol's callback fuctions */
+pxe_mutex core_mutex = {0, 0}; /* mutex used in packet allocation */
/* NIC info */
-pxe_ipaddr nic_ip={0};
+pxe_ipaddr nic_ip = {0};
-uint32_t packets_dropped=0;
-uint32_t packets_sent=0;
-uint32_t packets_received=0;
+/* core packet statistics */
+uint32_t packets_dropped = 0;
+uint32_t packets_sent = 0;
+uint32_t packets_received = 0;
-int pxe_core_init() {
+int
+pxe_core_init()
+{
+/* int i = 1; /* packet index during initialization loop */
+ int counter = 0;
+ uint8_t checksum = 0;
+ uint8_t *checkptr = NULL;
-/* int i=1; /* packet index during initialization loop */
- int counter=0;
- uint8_t checksum=0;
- uint8_t *checkptr=NULL;
- t_PXENV_GET_CACHED_INFO *gci_p=NULL;
+ t_PXENV_GET_CACHED_INFO *gci_p = NULL;
- pxe_memset(core_packets, 0, sizeof(core_packets));
- pxe_memset(core_protocol, 0, sizeof(core_protocol));
- nic_ip.ip=0;
+ pxe_memset(core_packets, 0, sizeof(core_packets));
+ pxe_memset(core_protocol, 0, sizeof(core_protocol));
+ nic_ip.ip = 0;
- /* creating 2-linked list of packets */
-/* for (; i<PXE_MAX_PACKETS; ++i) {
- core_packets[i].prev=&core_packets[i-1];
- core_packets[i-1].next=&core_packets[i];
- }
+ /* creating 2-linked list of packets */
+/* for (; i < PXE_MAX_PACKETS; ++i) {
+ core_packets[i].prev = &core_packets[i-1];
+ core_packets[i-1].next = &core_packets[i];
+ }
*/
- /* 1. determine PXE API entry point */
+ /* 1. determine PXE API entry point */
- /*
- pxe_env is originally is got by pxe_enable() call from
- void
- pxe_enable(void *pxeinfo) {
- pxenv_p = (pxenv_t *)pxeinfo;
- pxe_p = (pxe_t *)PTOV(pxenv_p->PXEPtr.segment * 16 +
- pxenv_p->PXEPtr.offset);
- pxe_call = NULL;
- }
-
- in my case, I must decide how to get this. May be it's best way
- to use same mechanism. or, if I'll not use BTX code, it'll be
- provided other way. So a plenty of things to think.
-
- */
+ /*
+ * pxe_env is originally is got by pxe_enable() call from
+ * void
+ * pxe_enable(void *pxeinfo) {
+ * pxenv_p = (pxenv_t *)pxeinfo;
+ * pxe_p = (pxe_t *)PTOV(pxenv_p->PXEPtr.segment * 16 +
+ * pxenv_p->PXEPtr.offset);
+ * pxe_call = NULL;
+ * }
+ *
+ * in my case, I must decide how to get this. May be it's best way
+ * to use same mechanism. or, if I'll not use BTX code, it'll be
+ * provided other way. So a plenty of things to think.
+ */
if(pxenv_p == NULL)
return (0);
@@ -114,7 +116,6 @@
* PXENV+ passed, so use that if !PXE is not available or
* the checksum fails.
*/
- pxe_call = pxenv_call;
if (pxenv_p->Version >= 0x0200) {
for (;;) {
if (bcmp((void *)pxe_p->Signature, S_SIZE("!PXE"))) {
@@ -130,7 +131,7 @@
pxe_p = NULL;
break;
}
- pxe_call = bangpxe_call;
+/* pxe_call = bangpxe_call;*/
break;
}
}
@@ -149,7 +150,7 @@
*/
gci_p = (t_PXENV_GET_CACHED_INFO *) scratch_buffer;
bzero(gci_p, sizeof(*gci_p));
- gci_p->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;
+ gci_p->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;
pxe_core_call(PXENV_GET_CACHED_INFO);
@@ -162,53 +163,63 @@
bcopy(PTOV((gci_p->Buffer.segment << 4) + gci_p->Buffer.offset),
&bootplayer, gci_p->BufferSize);
- /* 2. install isr */
- pxe_core_install_isr();
+ /* 2. install isr */
+ pxe_core_install_isr();
- /* 3. additional start UNDI */
+ /* 3. additional start UNDI */
- return 1;
+ return (1);
}
-void pxe_core_install_isr() {
+void
+pxe_core_install_isr()
+{
+
}
-void pxe_core_remove_isr() {
+void
+pxe_core_remove_isr()
+{
+
}
-int pxe_core_shutdown() {
+int
+pxe_core_shutdown()
+{
+ int i = 1;
- int i=1;
+ for (; i < PXE_MAX_PACKETS; ++i) {
- for (; i<PXE_MAX_PACKETS; ++i) {
+ if (core_packets[i].data)
+ pxe_free(core_packets[i].data);
+ }
- if (core_packets[i].data)
- pxe_free(core_packets[i].data);
- }
+ /* 1. uninstall isr */
+ pxe_core_remove_isr();
- /* 1. uninstall isr */
- pxe_core_remove_isr();
-
- /* 2. shutdown PXE */
+ /* 2. shutdown PXE */
t_PXENV_UNLOAD_STACK *unload_stack_p =
(t_PXENV_UNLOAD_STACK *)scratch_buffer;
+
t_PXENV_UNDI_SHUTDOWN *undi_shutdown_p =
(t_PXENV_UNDI_SHUTDOWN *)scratch_buffer;
pxe_core_call(PXENV_UNDI_SHUTDOWN);
pxe_core_call(PXENV_UNLOAD_STACK);
- return 1;
+ return (1);
}
/*
- function code is taken from bangpxe_call(), /sys/boot/libi386/pxe.c
- needs pxetramp.s wrapper and vm86int() support.
- I'll see later , may be it's simplier to do own v86 monitor,
- than using provided with BTX.
-*/
-void pxe_core_call(int func) {
+ * function code is taken from bangpxe_call(), /sys/boot/libi386/pxe.c
+ * needs pxetramp.s wrapper and vm86int() support.
+ * I'll see later , may be it's simplier to do own v86 monitor,
+ * than using provided with BTX.
+ */
+void
+pxe_core_call(int func)
+{
bzero(&v86, sizeof(v86));
bzero(data_buffer, sizeof(data_buffer));
@@ -225,211 +236,226 @@
v86.ctl = V86_FLAGS;
}
-int pxe_core_transmit(pxe_packet* pack) {
+int
+pxe_core_transmit(pxe_packet *pack)
+{
- /* UNDI transmit ip packet call*/
+ /* UNDI transmit ip packet call*/
- return 0;
+ return (0);
}
/* flushes pending, aborted, wrong and etc packets */
-int pxe_core_flush_packets() {
+int
+pxe_core_flush_packets()
+{
+ int i = 0;
- int i=0;
+ for (; i < PXE_MAX_PACKETS; ++i) {
+ pxe_ip *iphdr=(pxe_ip *)(core_packets[i].data);
- for (; i<PXE_MAX_PACKETS; ++i) {
+ if (iphdr == NULL) { /* dummy packet */
+ continue;
+ }
- pxe_ip* iphdr=(pxe_ip*)(core_packets[i].data);
+ if (core_protocol[iphdr->protocol]) { /* protocol registered */
+ core_protocol[iphdr->protocol](&core_packets[i],
+ PXE_CORE_CHECK, NULL);
+ }
+ }
- if (!iphdr) { /* dummy packet */
+ return (1);
+}
- continue;
- }
+void
+pxe_core_isr()
+{
+ int buffer_size = 0; /* total size of packet*/
+ int protocol = 0; /* protocol */
+ int recieved = 0; /* bytes received to buffer */
- if (core_protocol[iphdr->protocol]) { /* protocol registered */
+ void *frame_data = NULL;/* pointer to frame data */
+ int frame_size = 0; /* size of frame */
- core_protocol[iphdr->protocol](&core_packets[i], PXE_CORE_CHECK, NULL);
- }
- }
+ pxe_packet *pack=NULL; /* allocated packet */
+ pxe_packet dummy_pack; /* temporary struct, used to mimic
+ * real packet struct
+ */
- return 1;
-}
+ /*
+ * TODO: UNDI get buffer size & etc
+ */
-void pxe_core_isr() {
- /*
- TODO: UNDI get buffer size & etc
- */
+ /* we are yet not interested in non-ip packets */
- int buffer_size=0; /* total size of packet*/
- int protocol=0; /* protocol */
- int recieved=0; /* bytes received to buffer */
+ if (protocol != PXE_PROTOCOL_IP) {
+ ++packets_dropped;
+ return;
+ }
- void* frame_data=NULL;/* pointer to frame data */
- int frame_size=0; /* size of frame */
-
- pxe_packet* pack=NULL; /* allocated packet */
- pxe_packet dummy_pack; /* temporary struct, used to mimic real packet struct*/
-
- /* we are yet not interested in non-ip packets */
+ /* checking first fragment, this may help to avoid memory allocation
+ * and memblock copy
+ */
- if (protocol!=PXE_PROTOCOL_IP) {
- ++packets_dropped;
- return;
- }
-
- /* checking first fragment, this may help to avoid memory allocation and memblock copy */
/* if (buffer_size==frame_size) {
- pxe_ip* iphdr=(pxe_ip*)frame_data;
+ pxe_ip *iphdr = (pxe_ip *)frame_data;
- dummy_pack.protocol=protocol;
- dummy_pack.state=PXE_PACKET_STATE_USING;
- dummy_pack.data=frame_data;
- dummy_pack.data_size=frame_size;
- dummy_pack.user_data=NULL;
+ dummy_pack.protocol = protocol;
+ dummy_pack.state = PXE_PACKET_STATE_USING;
+ dummy_pack.data = frame_data;
+ dummy_pack.data_size = frame_size;
+ dummy_pack.user_data = NULL;
/* TODO: calc ip checksum /
if (core_protocol[iphdr->protocol]) {
-
- if (core_protocol[iphdr->protocol](&dummy_pack, PXE_CORE_FRAG, NULL)) {
- return;
- }
-
- }
+ if (core_protocol[iphdr->protocol](&dummy_pack, PXE_CORE_FRAG,
+ NULL)) {
+ return;
+ }
+ }
*/
- pack=pxe_core_alloc_packet(buffer_size);
+ pack = pxe_core_alloc_packet(buffer_size);
- if (!pack) {
+ if (pack == NULL) {
+ pxe_core_flush_packets();
- pxe_core_flush_packets();
+ /* trying to get free packets by sending and dropping */
+ pack = pxe_core_alloc_packet(buffer_size);
- /* trying to get free packets by sending and dropping */
- pack=pxe_core_alloc_packet(buffer_size);
+ /* failed to alloc packet, dropping packet */
+ if (pack == NULL) {
+ ++packets_dropped;
+ return;
+ }
+ }
- if (!pack) { /* failed to alloc packet, dropping packet */
- ++packets_dropped;
- return;
- }
- }
+ /* pointing user_data to beginning of data.
+ * It's used by pxe_core_receive() during receiving packet.
+ */
+ pack->user_data = pack->data;
+ while (recieved < buffer_size) {
+ /*
+ * UNDI get frame
+ */
- /* pointing user_data to beginning of data.
- It's used by pxe_core_receive() during receiving packet.
- */
- pack->user_data=pack->data;
+ frame_size=0;
- while (recieved<buffer_size) {
+ pxe_core_recieve(pack, frame_data, frame_size);
- /*
- UNDI get frame
- */
- frame_size=0;
+ recieved += frame_size;
+ }
- pxe_core_recieve(pack, frame_data, frame_size);
+ pack->user_data = NULL;
+ ++packets_received;
- recieved+=frame_size;
- }
+ pxe_ip *iphdr=(pxe_ip *)pack->data;
- pack->user_data=NULL;
- ++packets_received;
+ /* TODO: calc ip checksum */
+ pack->protocol = protocol;
- pxe_ip* iphdr=(pxe_ip*)pack->data;
+ if (core_protocol[iphdr->protocol]) { /* protocol registered */
+ if (core_protocol[iphdr->protocol](pack, PXE_CORE_HANDLE,
+ NULL)) {
+ return;
+ }
+ }
- /* TODO: calc ip checksum */
- pack->protocol=protocol;
-
- if (core_protocol[iphdr->protocol]) { /* protocol registered */
-
- if (core_protocol[iphdr->protocol](pack, PXE_CORE_HANDLE, NULL)) {
- return;
- }
- }
-
- /* no such protocol registered or protocol not interested in it */
- pxe_core_drop(pack);
+ /* no such protocol registered or protocol not interested in it */
+ pxe_core_drop(pack);
}
/*
- recieves in packet data
-*/
-int pxe_core_recieve(pxe_packet* pack, void* frame_data, size_t frame_size) {
+ * recieves in packet data
+ */
+int
+pxe_core_recieve(pxe_packet *pack, void *frame_data, size_t frame_size)
+{
- /* check to be sure */
- if (pack->user_data==NULL)
- pack->user_data=pack->data;
+ /* check to be sure */
+ if (pack->user_data == NULL)
+ pack->user_data = pack->data;
- /* sanity check */
- if ( (pack->user_data-pack->data) +frame_size > pack->data_size)
- return 0; /* This must not ever be*/
+ /* sanity check */
+ if ( (pack->user_data - pack->data) + frame_size > pack->data_size)
+ return (0); /* This must not ever be*/
- pxe_memcpy(pack->user_data, frame_data, frame_size);
+ pxe_memcpy(pack->user_data, frame_data, frame_size);
- return 1;
+ return (1);
}
/*
- allocates packet, creates buffer for data if necessary
-*/
-pxe_packet* pxe_core_alloc_packet(size_t packet_size) {
+ * allocates packet, creates buffer for data if necessary
+ */
+pxe_packet *
+pxe_core_alloc_packet(size_t packet_size)
+{
+ int i = 1; /* packet index */
- int i=1; /* packet index */
+ pxe_mutex_own(&core_mutex, PXE_OWNER_CORE);
- pxe_mutex_own(&core_mutex, PXE_OWNER_CORE);
+ /* searching free packets structures */
+ for (; i < PXE_MAX_PACKETS; ++i) {
+ if (core_packets[i].state == PXE_PACKET_STATE_FREE) {
+ /* packet structure seems to be free */
+ /* mark it busy */
+ core_packets[i].state = PXE_PACKET_STATE_USING;
- /* searching free packets structures */
- for (; i<PXE_MAX_PACKETS; ++i) {
+ if (core_packets[i].data_size < packet_size) {
+ /* packet contains less memmory than needed */
+ void *data = pxe_alloc(packet_size);
+ pxe_free(core_packets[i].data);
+ core_packets[i].data = data;
- if (core_packets[i].state==PXE_PACKET_STATE_FREE) { /* packet structure seems to be free */
+ /* failed to allocate enough memory for packet */
+ if (data == NULL) {
+ core_packets[i].data_size = 0;
+ return (NULL);
+ }
- core_packets[i].state=PXE_PACKET_STATE_USING; /* mark it busy */
+ core_packets[i].data_size = packet_size;
+ }
- if (core_packets[i].data_size<packet_size) { /* packet contains less memmory than needed */
+ pxe_mutex_free(&core_mutex, PXE_OWNER_CORE);
+ return &core_packets[i];
+ }
+ }
- pxe_free(core_packets[i].data);
-
- void* data=pxe_alloc(packet_size);
- core_packets[i].data=data;
-
- if (!data) { /* failed to allocate enough memory for packet */
- core_packets[i].data_size=0;
- return NULL;
- }
-
- core_packets[i].data_size=packet_size;
- }
-
- pxe_mutex_free(&core_mutex, PXE_OWNER_CORE);
- return &core_packets[i];
- }
-
- }
-
- pxe_mutex_free(&core_mutex, PXE_OWNER_CORE);
- return NULL;
+ pxe_mutex_free(&core_mutex, PXE_OWNER_CORE);
+ return (NULL);
}
/*
- drops choosed packet
-*/
-void pxe_core_drop(pxe_packet* pack) {
+ * drops choosed packet
+ */
+void
+pxe_core_drop(pxe_packet *pack)
+{
- pxe_mutex_own(&core_mutex, PXE_OWNER_CORE);
- pack->state=PXE_PACKET_STATE_FREE;
- ++packets_dropped;
- pxe_mutex_free(&core_mutex, PXE_OWNER_CORE);
+ pxe_mutex_own(&core_mutex, PXE_OWNER_CORE);
+ pack->state = PXE_PACKET_STATE_FREE;
+ ++packets_dropped;
+ pxe_mutex_free(&core_mutex, PXE_OWNER_CORE);
}
+
/*
- registers protocol in protocols table
-*/
-void pxe_core_register(uint8_t proto, pxe_protocol_call proc) {
+ * registers protocol in protocols table
+ */
+void
+pxe_core_register(uint8_t proto, pxe_protocol_call proc)
+{
core_protocol[proto]=proc;
}
-uint32_t pxe_get_myip32() {
+uint32_t
+pxe_get_myip32()
+{
return nic_ip.ip;
}
==== //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#4 (text+ko) ====
@@ -9,36 +9,37 @@
*/
/*
- contains wrappers for UNDI functions
-*/
+ * contains wrappers for UNDI functions
+ */
-#define PXE_MAX_PACKETS 32
+#define PXE_MAX_PACKETS 32
-#define PXE_PACKET_STATE_FREE 0
-#define PXE_PACKET_STATE_USING 1
-#define PXE_PACKET_STATE_RECIEVED 2
-#define PXE_PACKET_STATE_SENT 3
-#define PXE_PACKET_STATE_PENDING 4
-#define PXE_PACKET_STATE_ABORTED 5
+#define PXE_PACKET_STATE_FREE 0
+#define PXE_PACKET_STATE_USING 1
+#define PXE_PACKET_STATE_RECIEVED 2
+#define PXE_PACKET_STATE_SENT 3
+#define PXE_PACKET_STATE_PENDING 4
+#define PXE_PACKET_STATE_ABORTED 5
/*
- structure, used in queueing packets in pxe_core
+ * structure, used in queueing packets in pxe_core
*/
-typedef struct {
+typedef struct pxe_packet {
/* pxe_packet* next; /* NOT IMPLEMENTED: two-linked list */
/* pxe_packet* prev; /* NOT IMPLEMENTED: two-linked list */
-
uint8_t protocol; /* protocol, used in packet */
uint8_t state; /* state of packet (PXE_PACKET_STATE_ ... ) */
- void* data; /* pointer to buffer with packet data*/
+ void* data; /* pointer to buffer with packet data */
size_t data_size; /* size of packet data */
- void* user_data; /* pointer to user data. used by higher level protocols */
-} pxe_packet;
+ void* user_data; /* pointer to user data.
+ * used by higher level protocols
+ */
+} PXE_PACKET;
#define PXE_PROTOCOL_UNKNOWN 0
#define PXE_PROTOCOL_IP 1
@@ -53,19 +54,19 @@
int pxe_core_shutdown();
/* sends packet to a network */
-int pxe_core_transmit(pxe_packet* pack);
+int pxe_core_transmit(pxe_packet *pack);
/* commits that packet will not be used */
-void pxe_core_commit(pxe_packet* pack);
+void pxe_core_commit(pxe_packet *pack);
/* allocates buffer for packet */
-pxe_packet* pxe_core_alloc_packet(size_t packet_size);
+pxe_packet *pxe_core_alloc_packet(size_t packet_size);
/* interrupt handler function, that used to get new packets */
void pxe_core_isr();
/* calls PXE/UNDI API, registers of processor must be filled in with
- appropriate values.
+ * appropriate values.
*/
void pxe_core_call(int func);
@@ -76,10 +77,10 @@
void pxe_core_remove_isr();
/* stores data in packet */
-int pxe_core_recieve(pxe_packet* pack, void* data, size_t size);
+int pxe_core_recieve(pxe_packet *pack, void *data, size_t size);
/* drops allocated packet, updates drop count */
-void pxe_core_drop(pxe_packet* pack);
+void pxe_core_drop(pxe_packet *pack);
/* debug function that shows different information about usage */
void pxe_core_stats();
@@ -87,7 +88,8 @@
#define PXE_CORE_HANDLE 0x0
#define PXE_CORE_CHECK 0x1
#define PXE_CORE_FRAG 0x2
-typedef int (*pxe_protocol_call)(pxe_packet* pack, uint8_t function, void* data);
+typedef int (*pxe_protocol_call)(pxe_packet *pack, uint8_t function, void *data);
+
/* registers protocol */
void pxe_core_register(uint8_t proto, pxe_protocol_call proc);
==== //depot/projects/soc2007/taleks-pxe_http/pxe_http.c#2 (text+ko) ====
@@ -1,20 +1,21 @@
#include <stand.h>
+
#include "pxe_core.h"
+#include "pxe_icmp.h"
#include "pxe_ip.h"
-#include "pxe_icmp.h"
-int pxe_test_main() {
+int
+pxe_test_main()
+{
+ pxe_ipaddr ip;
+ ip.ip=0xC0A80001;
printf("pxe icmp dummy test.\n");
pxe_core_init();
pxe_icmp_init();
- pxe_ipaddr ip;
-
- ip.ip=0xC0A80001;
-
pxe_ping(&ip, 0);
- return 0;
+ return (0);
}
==== //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#3 (text+ko) ====
@@ -1,164 +1,176 @@
#include <stand.h>
+
+#include "pxe_conv.h"
+#include "pxe_core.h"
+#include "pxe_icmp.h"
#include "pxe_ip.h"
-#include "pxe_icmp.h"
-#include "pxe_core.h"
-#include "pxe_conv.h"
+
/* used in echo replying */
-static pinging=0;
+static pinging = 0;
-int pxe_icmp_callback(pxe_packet* pack, uint8_t function, void* data) {
+int
+pxe_icmp_callback(pxe_packet *pack, uint8_t function, void *data)
+{
+ /* we don't store icmp packets, so they cannot steal memory
+ * in pxe core packet table
+ */
- if (function==PXE_CORE_CHECK) {
- /* we don't store icmp packets, so they cannot steal memory
- in pxe core packet table */
- return 0;
- }
+ if (function == PXE_CORE_CHECK) {
+ return (0);
+ }
- /* PXE_CORE_HANDLE - to handle packet
- PXE_CORE_FRAG - to handle fragment of packet, may be useful for fast
- dropping of invalid packet.
- */
+ /* PXE_CORE_HANDLE - to handle packet
+ * PXE_CORE_FRAG - to handle fragment of packet, may be useful
+ * for fast dropping of invalid packet.
+ */
+ /* icmp header*/
+ pxe_ip *iphdr = pack->data;
+ size_t iphdr_len = (iphdr->ver_ihl & 0x0f) * 4;
+ size_t data_size = iphdr->length - iphdr_len - sizeof(pxe_ip);
+ pxe_icmp *icmphdr = pack->data + sizeof(pxe_ip) + iphdr_len;
- /* icmp header*/
- pxe_ip* iphdr=pack->data;
- size_t iphdr_len=(iphdr->ver_ihl & 0x0f)*4;
- size_t data_size=iphdr->length-iphdr_len-sizeof(pxe_ip);
- pxe_icmp* icmphdr=pack->data+sizeof(pxe_ip)+iphdr_len;
+ /* TODO: verify checksum */
- /* TODO: verify checksum */
+ /* reply */
+ pxe_packet *pack_out = NULL;
+ pxe_ip *reply_iphdr = NULL;
+ pxe_icmp *reply_icmphdr = NULL;
+ size_t reply_size = sizeof(pxe_ip) + sizeof(pxe_icmp) + data_size;
- /* reply */
- pxe_packet* pack_out=NULL;
- pxe_ip* reply_iphdr=NULL;
- pxe_icmp* reply_icmphdr=NULL;
- size_t reply_size=sizeof(pxe_ip)+sizeof(pxe_icmp)+data_size;
-
- /* we are interested only in echo related packets*/
- switch(icmphdr->code) {
- case PXE_ICMP_ECHO_REQUEST:
- case PXE_ICMP_ECHO_REPLY:
- /* case PXE_ICMP_DEST_UNREACHABLE:
- case PXE_ICMP_REDIRECT_MESSAGE:
+ /* we are interested only in echo related packets*/
+ switch(icmphdr->code) {
+ case PXE_ICMP_ECHO_REQUEST:
+ case PXE_ICMP_ECHO_REPLY:
+ /* case PXE_ICMP_DEST_UNREACHABLE:
+ case PXE_ICMP_REDIRECT_MESSAGE:
*/
- break;
+ break;
+ default:
+ return (0); /* instruct pxe core to drop packet*/
+ };
- default:
- return 0; /* instruct pxe core to drop packet*/
- };
+ if (icmphdr->code == PXE_ICMP_ECHO_REPLY) {
+ if (pinging == be2le32(iphdr->src_ip))
+ printf("\necho reply from %x, seq=%ld.",
+ iphdr->src_ip, icmphdr->seq_num);
+ else /* we are not interested in this reply*/
+ printf("\nlame echo reply from %x, seq=%ld.",
+ iphdr->src_ip, icmphdr->seq_num);
+ return (0);
+ }
+ /* all we need now is echo reply */
- if (icmphdr->code==PXE_ICMP_ECHO_REPLY) {
+ pxe_packet* pack_out = pxe_core_alloc_packet(reply_size);
- if (pinging==be2le32(iphdr->src_ip))
- printf("\necho reply from %x, seq=%ld.", iphdr->src_ip, icmphdr->seq_num);
- else /* we are not interested in this reply*/
- printf("\nlame echo reply from %x, seq=%ld.", iphdr->src_ip, icmphdr->seq_num);
- return 0;
- }
- /* all we need now is echo reply */
- pxe_packet* pack_out=pxe_core_alloc_packet(reply_size);
+ if (pack == NULL) {
+ /* TO THINK: failed to allocate packet,
+ * may be it's better to use
+ * statically allocated packet.
+ */
+ return 0;
+ }
- if (!pack) { /* TO THINK: failed to allocate packet,
- may be it's better to use
- statically allocated packet. */
+ reply_iphdr = (pxe_ip *)pack_out->data;
+ reply_icmphdr = (pxe_icmp *)(reply_iphdr + 1);
- return 0;
- }
+ reply_icmphdr->type = PXE_ICMP_ECHO_REPLY;
- reply_iphdr=(pxe_ip*)pack_out->data;
- reply_icmphdr=(pxe_icmp*)(reply_iphdr+1);
+ /* copying same values */
+ reply_icmphdr->code = icmphdr->code;
+ reply_icmphdr->seq_num = icmphdr->seq_num;
+ reply_icmphdr->packet_id = icmphdr->reply_icmphdr;
+ reply_icmphdr->checksum = 0;
+ reply_icmphdr->checksum =
+ ~(le2be16(pxe_ip_checksum(reply_icmphdr, sizeof(pxe_icmp))));
- reply_icmphdr->type=PXE_ICMP_ECHO_REPLY;
+ pxe_ip_hdr(pack_out->data, iphdr->src_ip, 0x01, reply_size, 0);
- /* copying same values */
+ /* copying all data from request packet to reply packet,
+ * starting after headers
+ */
+ pxe_memcpy(reply_icmphdr + 1, pack->data + iphdr_len + sizeof(pxe_icmp),
+ data_size);
- reply_icmphdr->code=icmphdr->code;
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list