|
From: <ljs...@us...> - 2007-05-25 03:14:35
|
Revision: 409
http://svn.sourceforge.net/cadcdev/?rev=409&view=rev
Author: ljsebald
Date: 2007-05-24 20:14:34 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Made it so that the IPv4 input code does not pass around ethernet headers. Also, fixed a few little issues with ping packet sending.
Modified Paths:
--------------
kos/kernel/net/net_icmp.c
kos/kernel/net/net_icmp.h
kos/kernel/net/net_input.c
kos/kernel/net/net_ipv4.c
kos/kernel/net/net_ipv4.h
kos/kernel/net/net_udp.c
kos/kernel/net/net_udp.h
Modified: kos/kernel/net/net_icmp.c
===================================================================
--- kos/kernel/net/net_icmp.c 2007-05-25 01:37:40 UTC (rev 408)
+++ kos/kernel/net/net_icmp.c 2007-05-25 03:14:34 UTC (rev 409)
@@ -3,7 +3,7 @@
kernel/net/net_icmp.c
Copyright (C) 2002 Dan Potter
- Copyright (C) 2005, 2006 Lawrence Sebald
+ Copyright (C) 2005, 2006, 2007 Lawrence Sebald
*/
@@ -64,8 +64,8 @@
net_echo_cb net_icmp_echo_cb = icmp_default_echo_cb;
/* Handle Echo Reply (ICMP type 0) packets */
-static void net_icmp_input_0(netif_t *src, eth_hdr_t *eth, ip_hdr_t *ip,
- icmp_hdr_t *icmp, const uint8 *d, int s) {
+static void net_icmp_input_0(netif_t *src, ip_hdr_t *ip, icmp_hdr_t *icmp,
+ const uint8 *d, int s) {
uint64 tmr;
struct __ping_pkt *ping;
uint16 seq;
@@ -88,19 +88,13 @@
}
/* Handle Echo (ICMP type 8) packets */
-static void net_icmp_input_8(netif_t *src, eth_hdr_t *eth, ip_hdr_t *ip,
- icmp_hdr_t *icmp, const uint8 *d, int s) {
- uint8 tmp[6];
+static void net_icmp_input_8(netif_t *src, ip_hdr_t *ip, icmp_hdr_t *icmp,
+ const uint8 *d, int s) {
int i;
/* Set type to echo reply */
icmp->type = 0;
- /* Swap source and dest addresses */
- memcpy(tmp, eth->dest, 6);
- memcpy(eth->dest, eth->src, 6);
- memcpy(eth->src, tmp, 6);
-
/* Swap source and dest ip addresses */
i = ip->src;
ip->src = ip->dest;
@@ -117,15 +111,13 @@
2 - 2 * (ip->version_ihl & 0x0f));
/* Send it */
- memcpy(pktbuf, eth, 14);
- memcpy(pktbuf + 14, ip, 20);
- memcpy(pktbuf + 14 + 20, d, ntohs(ip->length) - 4 *
- (ip->version_ihl & 0x0F));
- src->if_tx(src, pktbuf, 14 + ntohs(ip->length), NETIF_BLOCK);
+ memcpy(pktbuf, ip, 20);
+ memcpy(pktbuf + 20, d, ntohs(ip->length) - 4 * (ip->version_ihl & 0x0F));
+ net_ipv4_send_packet(src, ip, pktbuf + 20, ntohs(ip->length) -
+ 4 * (ip->version_ihl & 0x0F));
}
-int net_icmp_input(netif_t *src, eth_hdr_t *eth, ip_hdr_t *ip, const uint8 *d,
- int s) {
+int net_icmp_input(netif_t *src, ip_hdr_t *ip, const uint8 *d, int s) {
icmp_hdr_t *icmp;
int i;
@@ -148,7 +140,7 @@
switch(icmp->type) {
case 0: /* Echo reply */
- net_icmp_input_0(src, eth, ip, icmp, d, s);
+ net_icmp_input_0(src, ip, icmp, d, s);
break;
case 3: /* Destination unreachable */
dbglog(DBG_KDEBUG, "net_icmp: Destination unreachable,"
@@ -156,7 +148,7 @@
break;
case 8: /* Echo */
- net_icmp_input_8(src, eth, ip, icmp, d, s);
+ net_icmp_input_8(src, ip, icmp, d, s);
break;
default:
@@ -184,7 +176,7 @@
icmp->checksum = 0;
icmp->misc[0] = (uint8) 'D';
icmp->misc[1] = (uint8) 'C';
- icmp->misc[2] = (uint8) (icmp_echo_seq >> 16);
+ icmp->misc[2] = (uint8) (icmp_echo_seq >> 8);
icmp->misc[3] = (uint8) (icmp_echo_seq & 0xFF);
memcpy(databuf + sizeof(icmp_hdr_t), data, size);
@@ -197,7 +189,12 @@
ip.ttl = 64;
ip.protocol = 1; /* ICMP */
ip.checksum = 0;
- ip.src = htonl(net_ipv4_address(net->ip_addr));
+
+ if(net_ipv4_address(ipaddr) == 0x7F000001)
+ ip.src = htonl(net_ipv4_address(ipaddr));
+ else
+ ip.src = htonl(net_ipv4_address(net->ip_addr));
+
ip.dest = htonl(net_ipv4_address(ipaddr));
/* Compute the ICMP Checksum */
Modified: kos/kernel/net/net_icmp.h
===================================================================
--- kos/kernel/net/net_icmp.h 2007-05-25 01:37:40 UTC (rev 408)
+++ kos/kernel/net/net_icmp.h 2007-05-25 03:14:34 UTC (rev 409)
@@ -2,10 +2,8 @@
kernel/net/net_icmp.h
Copyright (C) 2002 Dan Potter
- Copyright (C) 2005 Lawrence Sebald
+ Copyright (C) 2005, 2007 Lawrence Sebald
- $Id: net_icmp.h,v 1.2 2002/03/24 00:27:05 bardtx Exp $
-
*/
#ifndef __LOCAL_NET_ICMP_H
@@ -26,8 +24,7 @@
} icmp_hdr_t;
#undef packed
-int net_icmp_input(netif_t *src, eth_hdr_t *eh, ip_hdr_t *ih, const uint8 *data,
- int size);
+int net_icmp_input(netif_t *src, ip_hdr_t *ih, const uint8 *data, int size);
__END_DECLS
Modified: kos/kernel/net/net_input.c
===================================================================
--- kos/kernel/net/net_input.c 2007-05-25 01:37:40 UTC (rev 408)
+++ kos/kernel/net/net_input.c 2007-05-25 03:14:34 UTC (rev 409)
@@ -23,7 +23,8 @@
switch(ntohs(*proto)) {
case 0x0800:
- return net_ipv4_input(nif, data, len);
+ return net_ipv4_input(nif, data + sizeof(eth_hdr_t),
+ len - sizeof(eth_hdr_t));
case 0x0806:
return net_arp_input(nif, data, len);
default:
Modified: kos/kernel/net/net_ipv4.c
===================================================================
--- kos/kernel/net/net_ipv4.c 2007-05-25 01:37:40 UTC (rev 408)
+++ kos/kernel/net/net_ipv4.c 2007-05-25 03:14:34 UTC (rev 409)
@@ -2,7 +2,7 @@
kernel/net/net_ipv4.c
- Copyright (C) 2005, 2006 Lawrence Sebald
+ Copyright (C) 2005, 2006, 2007 Lawrence Sebald
Portions adapted from KOS' old net_icmp.c file:
Copyright (c) 2002 Dan Potter
@@ -119,25 +119,14 @@
}
int net_ipv4_input(netif_t *src, const uint8 *pkt, int pktsize) {
- eth_hdr_t *eth;
ip_hdr_t *ip;
int i;
uint8 *data;
- uint16 *ethproto;
/* Get pointers */
- eth = (eth_hdr_t*) (pkt);
- ip = (ip_hdr_t*) (pkt + sizeof(eth_hdr_t));
- data = (uint8 *) (pkt + sizeof(eth_hdr_t) + 4 *
- (ip->version_ihl & 0x0f));
- ethproto = (uint16 *) (pkt + 12);
+ ip = (ip_hdr_t*) pkt;
+ data = (uint8 *) (pkt + 4 * (ip->version_ihl & 0x0f));
- /* Make sure this packet is actually marked as an IP packet */
- if(ntohs(*ethproto) != 0x0800) {
- dbglog(DBG_KDEBUG, "net_ipv4: Discarding non IP packet\n");
- return 0;
- }
-
/* Check ip header checksum */
i = ip->checksum;
ip->checksum = 0;
@@ -152,11 +141,11 @@
switch(ip->protocol) {
case 1:
- net_icmp_input(src, eth, ip, data, ntohs(ip->length) -
+ net_icmp_input(src, ip, data, ntohs(ip->length) -
(ip->version_ihl & 0x0f) * 4);
break;
case 17:
- net_udp_input(src, eth, ip, data, ntohs(ip->length) -
+ net_udp_input(src, ip, data, ntohs(ip->length) -
(ip->version_ihl & 0x0f) * 4);
break;
default:
Modified: kos/kernel/net/net_ipv4.h
===================================================================
--- kos/kernel/net/net_ipv4.h 2007-05-25 01:37:40 UTC (rev 408)
+++ kos/kernel/net/net_ipv4.h 2007-05-25 03:14:34 UTC (rev 409)
@@ -1,7 +1,7 @@
/* KallistiOS ##version##
kernel/net/net_ipv4.h
- Copyright (C) 2005 Lawrence Sebald
+ Copyright (C) 2005, 2007 Lawrence Sebald
*/
Modified: kos/kernel/net/net_udp.c
===================================================================
--- kos/kernel/net/net_udp.c 2007-05-25 01:37:40 UTC (rev 408)
+++ kos/kernel/net/net_udp.c 2007-05-25 03:14:34 UTC (rev 409)
@@ -1,7 +1,7 @@
/* KallistiOS ##version##
kernel/net/net_udp.c
- Copyright (C) 2005, 2006 Lawrence Sebald
+ Copyright (C) 2005, 2006, 2007 Lawrence Sebald
*/
@@ -518,8 +518,7 @@
return 0;
}
-int net_udp_input(netif_t *src, eth_hdr_t *eh, ip_hdr_t *ip, const uint8 *data,
- int size) {
+int net_udp_input(netif_t *src, ip_hdr_t *ip, const uint8 *data, int size) {
uint8 buf[size + 13];
ip_pseudo_hdr_t *ps = (ip_pseudo_hdr_t *)buf;
uint16 checksum;
Modified: kos/kernel/net/net_udp.h
===================================================================
--- kos/kernel/net/net_udp.h 2007-05-25 01:37:40 UTC (rev 408)
+++ kos/kernel/net/net_udp.h 2007-05-25 03:14:34 UTC (rev 409)
@@ -1,7 +1,7 @@
/* KallistiOS ##version##
kernel/net/net_udp.h
- Copyright (C) 2005, 2006 Lawrence Sebald
+ Copyright (C) 2005, 2006, 2007 Lawrence Sebald
*/
@@ -20,8 +20,7 @@
} udp_hdr_t;
#undef packed
-int net_udp_input(netif_t *src, eth_hdr_t *eh, ip_hdr_t *ih, const uint8 *data,
- int size);
+int net_udp_input(netif_t *src, ip_hdr_t *ih, const uint8 *data, int size);
int net_udp_send_raw(netif_t *net, uint32 src_ip, uint16 src_port,
uint32 dst_ip, uint16 dst_port, const uint8 *data,
int size);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|