This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
RedBoot - merge in network gateway support
- From: Gary Thomas <gary at chez-thomas dot org>
- To: eCos patches <ecos-patches at sources dot redhat dot com>
- Cc: Grant Edwards <grante at visi dot com>
- Date: 09 Jul 2002 14:24:56 -0600
- Subject: RedBoot - merge in network gateway support
Index: redboot/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.58
diff -u -5 -p -r1.58 ChangeLog
--- redboot/current/ChangeLog 1 Jul 2002 20:55:25 -0000 1.58
+++ redboot/current/ChangeLog 9 Jul 2002 20:23:20 -0000
@@ -1,5 +1,18 @@
+2002-07-09 Gary Thomas <gary@chez-thomas.org>
+2002-07-09 Grant Edwards <grante@visi.com>
+
+ * src/net/udp.c:
+ * src/net/net_io.c:
+ * src/net/ip.c:
+ * src/net/bootp.c:
+ * src/net/arp.c:
+ * include/net/net.h:
+ * include/net/bootp.h:
+ * cdl/redboot.cdl: Add basic support for non-local networking
+ using a single gateway. Based on contribution from Grant Edwards.
+
2002-07-01 Gary Thomas <gary@chez-thomas.org>
* src/net/tftp_client.c:
* src/net/http_client.c:
* src/fs/disk.c:
Index: redboot/current/cdl/redboot.cdl
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/cdl/redboot.cdl,v
retrieving revision 1.38
diff -u -5 -p -r1.38 redboot.cdl
--- redboot/current/cdl/redboot.cdl 1 Jul 2002 20:55:26 -0000 1.38
+++ redboot/current/cdl/redboot.cdl 9 Jul 2002 20:09:41 -0000
@@ -216,10 +216,45 @@ cdl_package CYGPKG_REDBOOT {
timeout. This option is overriden by the
configuration stored in flash."
}
}
+ cdl_component CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY {
+ display "Use a gateway for non-local IP traffic"
+ flavor bool
+ default_value 1
+ description "
+ Enabling this option will allow the RedBoot networking
+ stack to use a \[single\] gateway to reach a non-local
+ IP address. If disabled, RedBoot will only be able to
+ reach nodes on the same subnet."
+
+ cdl_component CYGDAT_REDBOOT_DEFAULT_GATEWAY_IP_ADDR {
+ display "Default gateway IP address"
+ flavor booldata
+ default_value CYGSEM_REDBOOT_FLASH_CONFIG ? 0 : \
+ { "0, 0, 0, 0" }
+ description "
+ This IP address is the default used by RedBoot if a BOOTP/DHCP
+ server does not respond. The numbers should be separated by
+ *commas*, and not dots. If an IP address is configured into
+ the Flash configuration, that will be used in preference."
+ }
+
+ cdl_component CYGDAT_REDBOOT_DEFAULT_IP_ADDR_MASK {
+ display "Default IP address mask"
+ flavor booldata
+ default_value CYGSEM_REDBOOT_FLASH_CONFIG ? 0 : \
+ { "255, 255, 255, 0" }
+ description "
+ This IP address mask is the default used by RedBoot if a BOOTP/DHCP
+ server does not respond. The numbers should be separated by
+ *commas*, and not dots. If an IP address is configured into
+ the Flash configuration, that will be used in preference."
+ }
+ }
+
cdl_option CYGNUM_REDBOOT_NETWORKING_TCP_PORT {
display "TCP port to listen for incoming connections"
flavor data
default_value 9000
description "
Index: redboot/current/include/net/bootp.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/include/net/bootp.h,v
retrieving revision 1.3
diff -u -5 -p -r1.3 bootp.h
--- redboot/current/include/net/bootp.h 23 May 2002 23:08:29 -0000 1.3
+++ redboot/current/include/net/bootp.h 9 Jul 2002 20:20:17 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2002 Gary Thomas
//
// eCos 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; either version 2 or (at your option) any later version.
//
@@ -86,11 +87,11 @@ SOFTWARE.
*/
#define BP_CHADDR_LEN 16
#define BP_SNAME_LEN 64
#define BP_FILE_LEN 128
-#define BP_VEND_LEN 64
+#define BP_VEND_LEN 312
#define BP_MINPKTSZ 300 /* to check sizeof(struct bootp) */
typedef struct bootp {
unsigned char bp_op; /* packet opcode type */
unsigned char bp_htype; /* hardware addr type */
Index: redboot/current/include/net/net.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/include/net/net.h,v
retrieving revision 1.13
diff -u -5 -p -r1.13 net.h
--- redboot/current/include/net/net.h 23 May 2002 23:08:29 -0000 1.13
+++ redboot/current/include/net/net.h 9 Jul 2002 20:20:25 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2002 Gary Thomas
//
// eCos 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; either version 2 or (at your option) any later version.
//
@@ -96,10 +97,11 @@ extern unsigned long ntohs(unsigned sho
/*
* Minimum ethernet packet length.
*/
#define ETH_MIN_PKTLEN 60
#define ETH_MAX_PKTLEN (1540-14)
+#define ETH_HDR_SIZE 14
typedef unsigned char enet_addr_t[6];
typedef unsigned char ip_addr_t[4];
typedef unsigned char octet;
@@ -182,11 +184,11 @@ typedef struct {
enet_addr_t target_enet;
ip_addr_t target_ip;
} arp_header_t;
-#define ARP_PKT_SIZE (sizeof(arp_header_t) + sizeof(eth_header_t))
+#define ARP_PKT_SIZE (sizeof(arp_header_t) + ETH_HDR_SIZE)
/*
* Internet Protocol header.
*/
typedef struct {
@@ -210,11 +212,11 @@ typedef struct {
ip_addr_t source;
ip_addr_t destination;
} ip_header_t;
-#define IP_PKT_SIZE (60 + sizeof(eth_header_t))
+#define IP_PKT_SIZE (60 + ETH_HDR_SIZE)
/*
* A IP<->ethernet address mapping.
*/
@@ -349,11 +351,14 @@ typedef struct _tcp_socket {
/*
* Our address.
*/
extern enet_addr_t __local_enet_addr;
extern ip_addr_t __local_ip_addr;
-
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+extern ip_addr_t __local_ip_gate;
+extern ip_addr_t __local_ip_mask;
+#endif
/*
* Set a timer. Caller is responsible for providing the timer_t struct.
*/
extern void __timer_set(timer_t *t, unsigned long delay,
@@ -408,10 +413,16 @@ extern void __enet_poll(void);
/*
* Send an ethernet packet.
*/
extern void __enet_send(pktbuf_t *pkt, enet_addr_t *dest, int eth_type);
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+/*
+ * return true if addr is on local subnet
+ */
+extern int __ip_addr_local(ip_addr_t *addr);
+#endif
/*
* Handle incoming ARP packets.
*/
extern void __arp_handler(pktbuf_t *pkt);
@@ -452,13 +463,13 @@ extern void __ip_handler(pktbuf_t *pkt,
* Send an IP packet.
*
* The IP data field should contain pkt->pkt_bytes of data.
* pkt->[udp|tcp|icmp]_hdr points to the IP data field. Any
* IP options are assumed to be already in place in the IP
- * options field.
+ * options field. Returns 0 for success.
*/
-extern void __ip_send(pktbuf_t *pkt, int protocol, ip_route_t *dest);
+extern int __ip_send(pktbuf_t *pkt, int protocol, ip_route_t *dest);
/*
* Handle incoming ICMP packets.
*/
@@ -485,11 +496,11 @@ extern int __udp_install_listener(udp_so
extern void __udp_remove_listener(word port);
/*
* Send a UDP packet.
*/
-extern void __udp_send(char *buf, int len, ip_route_t *dest_ip,
+extern int __udp_send(char *buf, int len, ip_route_t *dest_ip,
word dest_port, word src_port);
// Send a UDP packet
extern int __udp_sendto(char *buf, int len,
struct sockaddr_in *server, struct sockaddr_in *local);
Index: redboot/current/src/net/arp.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/arp.c,v
retrieving revision 1.5
diff -u -5 -p -r1.5 arp.c
--- redboot/current/src/net/arp.c 23 May 2002 23:08:34 -0000 1.5
+++ redboot/current/src/net/arp.c 9 Jul 2002 20:20:34 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2002 Gary Thomas
//
// eCos 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; either version 2 or (at your option) any later version.
//
@@ -187,10 +188,19 @@ __arp_lookup(ip_addr_t *host, ip_route_t
memcpy(rt, &routes[i], sizeof(*rt));
return 0;
}
}
memcpy(&rt->ip_addr, host, sizeof(*host));
+ if (((*host)[0] == 0xFF) && ((*host)[1] == 0xFF) && ((*host)[2] == 0xFF)) {
+ memset(&rt->enet_addr, 0xFF, sizeof(&rt->enet_addr));
+ return 0;
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+ } else if (!__ip_addr_local(host)) {
+ // non-local IP address -- look up Gateway's Ethernet address
+ host = &__local_ip_gate;
+#endif
+ }
if (__arp_request(host, &rt->enet_addr) < 0) {
return -1;
} else {
memcpy(&routes[next_arp], rt, sizeof(*rt));
if (++next_arp == NUM_ARP) next_arp = 0;
Index: redboot/current/src/net/bootp.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/bootp.c,v
retrieving revision 1.7
diff -u -5 -p -r1.7 bootp.c
--- redboot/current/src/net/bootp.c 23 May 2002 23:08:35 -0000 1.7
+++ redboot/current/src/net/bootp.c 9 Jul 2002 20:20:44 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2002 Gary Thomas
//
// eCos 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; either version 2 or (at your option) any later version.
//
@@ -63,30 +64,81 @@ extern int net_debug;
/* How many milliseconds to wait before retrying the request */
#define RETRY_TIME 1000
#define MAX_RETRIES 30
static bootp_header_t *bp_info;
+
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+static const unsigned char dhcpCookie[] = {99,130,83,99};
+static const unsigned char dhcpEndOption[] = {255};
+static const unsigned char dhcpRequestOption[] = {52,1,3};
+#endif
static void
bootp_handler(udp_socket_t *skt, char *buf, int len,
ip_route_t *src_route, word src_port)
{
bootp_header_t *b;
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+ unsigned char *p,*end;
+ int optlen;
+#endif
b = (bootp_header_t *)buf;
if (bp_info) {
+ memset(bp_info,0,sizeof *bp_info);
if (len > sizeof *bp_info)
len = sizeof *bp_info;
memcpy(bp_info, b, len);
}
- if (b->bp_op == BOOTREPLY &&
- !memcmp(b->bp_chaddr, __local_enet_addr, 6)) {
- memcpy(__local_ip_addr, &b->bp_yiaddr, 4);
+ // Only accept pure REPLY responses
+ if (b->bp_op != BOOTREPLY)
+ return;
+
+ // Must be sent to me, as well!
+ if (memcmp(b->bp_chaddr, __local_enet_addr, 6))
+ return;
+
+ memcpy(__local_ip_addr, &b->bp_yiaddr, 4);
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+ memcpy(__local_ip_gate, &b->bp_giaddr, 4);
+
+ if (memcmp(b->bp_vend, dhcpCookie, sizeof(dhcpCookie)))
+ return;
+
+ optlen = len - (b->bp_vend - ((unsigned char*)b));
+
+ p = b->bp_vend+4;
+ end = ((unsigned char*)b) + len;
+
+ while (p < end) {
+ unsigned char tag = *p;
+ if (tag == TAG_END)
+ break;
+ if (tag == TAG_PAD)
+ optlen = 1;
+ else {
+ optlen = p[1];
+ p += 2;
+ switch (tag) {
+ case TAG_SUBNET_MASK: // subnet mask
+ memcpy(__local_ip_mask,p,4);
+ break;
+ case TAG_GATEWAY: // router
+ memcpy(__local_ip_gate,p,4);
+ break;
+ default:
+ break;
+ }
+ }
+ p += optlen;
}
+#endif
}
+#define AddOption(p,d) do {memcpy(p,d,sizeof d); p += sizeof d;} while (0)
/*
* Find our IP address and copy to __local_ip_addr.
* Return zero if successful, -1 if not.
*/
@@ -97,19 +149,35 @@ __bootp_find_local_ip(bootp_header_t *in
bootp_header_t b;
ip_route_t r;
int retry;
unsigned long start;
ip_addr_t saved_ip_addr;
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+ unsigned char *p;
+#endif
+ int txSize;
bp_info = info;
memset(&b, 0, sizeof(b));
b.bp_op = BOOTREQUEST;
b.bp_htype = HTYPE_ETHERNET;
b.bp_hlen = 6;
b.bp_xid = SHOULD_BE_RANDOM;
+
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+ p = b.bp_vend;
+
+ AddOption(p,dhcpCookie);
+ AddOption(p,dhcpRequestOption);
+ AddOption(p,dhcpEndOption);
+
+ txSize = p - (unsigned char*)&b;
+#else
+ txSize = sizeof(b);
+#endif
memcpy( saved_ip_addr, __local_ip_addr, sizeof(__local_ip_addr) );
memset( __local_ip_addr, 0, sizeof(__local_ip_addr) );
memcpy(b.bp_chaddr, __local_enet_addr, 6);
@@ -131,11 +199,11 @@ __bootp_find_local_ip(bootp_header_t *in
retry = MAX_RETRIES;
while (retry-- > 0) {
start = MS_TICKS();
- __udp_send((char *)&b, sizeof(b), &r, IPPORT_BOOTPS, IPPORT_BOOTPC);
+ __udp_send((char *)&b, txSize, &r, IPPORT_BOOTPS, IPPORT_BOOTPC);
do {
__enet_poll();
if (__local_ip_addr[0] || __local_ip_addr[1] ||
__local_ip_addr[2] || __local_ip_addr[3]) {
@@ -147,10 +215,10 @@ __bootp_find_local_ip(bootp_header_t *in
}
/* timed out */
__udp_remove_listener(IPPORT_BOOTPC);
net_debug = 0;
- memcpy( __local_ip_addr, saved_ip_addr, sizeof(__local_ip_addr) );
+ memcpy( __local_ip_addr, saved_ip_addr, sizeof(__local_ip_addr));
return -1;
}
Index: redboot/current/src/net/ip.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/ip.c,v
retrieving revision 1.4
diff -u -5 -p -r1.4 ip.c
--- redboot/current/src/net/ip.c 23 May 2002 23:08:35 -0000 1.4
+++ redboot/current/src/net/ip.c 9 Jul 2002 20:20:53 -0000
@@ -11,10 +11,11 @@
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos 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; either version 2 or (at your option) any later version.
+// Copyright (C) 2002 Gary Thomas
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
@@ -55,15 +56,39 @@
#include <net/net.h>
#ifndef CYGDAT_REDBOOT_DEFAULT_IP_ADDR
# define CYGDAT_REDBOOT_DEFAULT_IP_ADDR 0, 0, 0, 0
#endif
+#ifndef CYGDAT_REDBOOT_DEFAULT_IP_ADDR_MASK
+# define CYGDAT_REDBOOT_DEFAULT_IP_ADDR_MASK 255, 255, 255, 0
+#endif
+#ifndef CYGDAT_REDBOOT_DEFAULT_GATEWAY_IP_ADDR
+# define CYGDAT_REDBOOT_DEFAULT_GATEWAY_IP_ADDR 0, 0, 0, 0
+#endif
ip_addr_t __local_ip_addr = { CYGDAT_REDBOOT_DEFAULT_IP_ADDR };
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+ip_addr_t __local_ip_mask = { CYGDAT_REDBOOT_DEFAULT_IP_ADDR_MASK };
+ip_addr_t __local_ip_gate = { CYGDAT_REDBOOT_DEFAULT_GATEWAY_IP_ADDR };
+#endif
static word ip_ident;
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+/*
+ * See if an address is on the local network
+ */
+int
+__ip_addr_local(ip_addr_t *addr)
+{
+ return !(
+ ((__local_ip_addr[0] ^ (*addr)[0]) & __local_ip_mask[0]) |
+ ((__local_ip_addr[1] ^ (*addr)[1]) & __local_ip_mask[1]) |
+ ((__local_ip_addr[2] ^ (*addr)[2]) & __local_ip_mask[2]) |
+ ((__local_ip_addr[3] ^ (*addr)[3]) & __local_ip_mask[3]));
+}
+#endif
/*
* Match given IP address to our address.
* Check for broadcast matches as well.
*/
@@ -150,11 +175,11 @@ __ip_handler(pktbuf_t *pkt, enet_addr_t
* The IP data field should contain pkt->pkt_bytes of data.
* pkt->[udp|tcp|icmp]_hdr points to the IP data field. Any
* IP options are assumed to be already in place in the IP
* options field.
*/
-void
+int
__ip_send(pktbuf_t *pkt, int protocol, ip_route_t *dest)
{
ip_header_t *ip = pkt->ip_hdr;
int hdr_bytes;
unsigned short cksum;
@@ -183,8 +208,9 @@ __ip_send(pktbuf_t *pkt, int protocol, i
memcpy(ip->destination, dest->ip_addr, sizeof(ip_addr_t));
cksum = __sum((word *)ip, hdr_bytes, 0);
ip->checksum = htons(cksum);
__enet_send(pkt, &dest->enet_addr, ETH_TYPE_IP);
+ return 0;
}
Index: redboot/current/src/net/net_io.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/net_io.c,v
retrieving revision 1.24
diff -u -5 -p -r1.24 net_io.c
--- redboot/current/src/net/net_io.c 23 May 2002 23:08:35 -0000 1.24
+++ redboot/current/src/net/net_io.c 9 Jul 2002 20:21:01 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2002 Gary Thomas
//
// eCos 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; either version 2 or (at your option) any later version.
//
@@ -92,10 +93,24 @@ RedBoot_config_option("Local IP address"
bootp_my_ip,
"bootp", false,
CONFIG_IP,
0
);
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+RedBoot_config_option("Local IP address mask",
+ bootp_my_ip_mask,
+ "bootp", false,
+ CONFIG_IP,
+ 0
+ );
+RedBoot_config_option("Gateway IP address",
+ bootp_my_gateway_ip,
+ "bootp", false,
+ CONFIG_IP,
+ 0
+ );
+#endif
RedBoot_config_option("Default server IP address",
bootp_server_ip,
"bootp", false,
CONFIG_IP,
0
@@ -560,10 +575,25 @@ show_addrs(void)
show_dns();
#endif
diag_printf("\n");
}
+static void
+flash_get_IP(char *id, ip_addr_t *val)
+{
+ ip_addr_t my_ip;
+ int i;
+
+ flash_get_config(id, &my_ip, CONFIG_IP);
+ if (my_ip[0] != 0 || my_ip[1] != 0 ||
+ my_ip[2] != 0 || my_ip[3] != 0) {
+ // 'id' is set to something so let it override any static IP
+ for (i=0; i<4; i++)
+ (*val)[i] = my_ip[i];
+ }
+}
+
void
net_init(void)
{
cyg_netdevtab_entry_t *t;
@@ -584,19 +614,15 @@ net_init(void)
flash_get_config("net_debug", &net_debug, CONFIG_BOOL);
flash_get_config("gdb_port", &gdb_port, CONFIG_INT);
flash_get_config("bootp", &use_bootp, CONFIG_BOOL);
if (!use_bootp)
{
- ip_addr_t bootp_my_ip;
- int i;
- flash_get_config("bootp_my_ip", &bootp_my_ip, CONFIG_IP);
- if (bootp_my_ip[0] != 0 || bootp_my_ip[1] != 0 ||
- bootp_my_ip[2] != 0 || bootp_my_ip[3] != 0) {
- // bootp_my_ip is set to something so let it override any static IP
- for (i=0; i<4; i++)
- __local_ip_addr[i] = bootp_my_ip[i];
- }
+ flash_get_IP("bootp_my_ip", &__local_ip_addr);
+#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
+ flash_get_IP("bootp_my_ip_mask", &__local_ip_mask);
+ flash_get_IP("bootp_my_gateway_ip", &__local_ip_gate);
+#endif
flash_get_config("bootp_server_ip", &my_bootp_info.bp_siaddr,
CONFIG_IP);
}
#endif
# ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
Index: redboot/current/src/net/udp.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/udp.c,v
retrieving revision 1.8
diff -u -5 -p -r1.8 udp.c
--- redboot/current/src/net/udp.c 23 May 2002 23:08:36 -0000 1.8
+++ redboot/current/src/net/udp.c 9 Jul 2002 20:21:09 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2002 Gary Thomas
//
// eCos 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; either version 2 or (at your option) any later version.
//
@@ -60,11 +61,11 @@ static int udp_rx_total;
static int udp_rx_handled;
static int udp_rx_cksum;
static int udp_rx_dropped;
#endif
-#define MAX_UDP_DATA (ETH_MAX_PKTLEN - (sizeof(eth_header_t) + \
+#define MAX_UDP_DATA (ETH_MAX_PKTLEN - (ETH_HDR_SIZE + \
sizeof(ip_header_t) + \
sizeof(udp_header_t)))
/*
* A major assumption is that only a very small number of sockets will
@@ -149,27 +150,27 @@ __udp_handler(pktbuf_t *pkt, ip_route_t
/*
* Send a UDP packet.
*/
-void
+int
__udp_send(char *buf, int len, ip_route_t *dest_ip,
word dest_port, word src_port)
{
pktbuf_t *pkt;
udp_header_t *udp;
ip_header_t *ip;
unsigned short cksum;
-
+ int ret;
/* dumb */
if (len > MAX_UDP_DATA)
- return;
+ return -1;
/* just drop it if can't get a buffer */
if ((pkt = __pktbuf_alloc(ETH_MAX_PKTLEN)) == NULL)
- return;
+ return -1;
udp = pkt->udp_hdr;
ip = pkt->ip_hdr;
pkt->pkt_bytes = len + sizeof(udp_header_t);
@@ -188,28 +189,28 @@ __udp_send(char *buf, int len, ip_route_
ip->length = udp->length;
cksum = __sum((word *)udp, pkt->pkt_bytes, __pseudo_sum(ip));
udp->checksum = htons(cksum);
- __ip_send(pkt, IP_PROTO_UDP, dest_ip);
-
+ ret = __ip_send(pkt, IP_PROTO_UDP, dest_ip);
__pktbuf_free(pkt);
+ return ret;
}
int
__udp_sendto(char *data, int len, struct sockaddr_in *server,
struct sockaddr_in *local)
{
ip_route_t rt;
- if (__arp_lookup((ip_addr_t *)&server->sin_addr, &rt) < 0) {
- diag_printf("%s: Can't find address of server\n", __FUNCTION__);
- return -1;
- } else {
- __udp_send(data, len, &rt, ntohs(server->sin_port), ntohs(local->sin_port));
- return 0;
- }
+ if (__arp_lookup((ip_addr_t *)&server->sin_addr, &rt) < 0) {
+ diag_printf("%s: Can't find address of server\n", __FUNCTION__);
+ return -1;
+ } else {
+ __udp_send(data, len, &rt, ntohs(server->sin_port), ntohs(local->sin_port));
+ return 0;
+ }
}
static char *recvfrom_buf;
static int recvfrom_len;
static struct sockaddr_in *recvfrom_server;