diff --git a/src/include/gpxe/ip.h b/src/include/gpxe/ip.h index 2212d8e5..e497dd79 100644 --- a/src/include/gpxe/ip.h +++ b/src/include/gpxe/ip.h @@ -11,7 +11,6 @@ /* IP constants */ -#define IP_HLEN 20 #define IP_VER 4 #define IP_MASK_VER 0xf0 #define IP_MASK_HLEN 0x0f @@ -21,16 +20,20 @@ #define IP_TOS 0 #define IP_TTL 64 -/* IP6 constants */ - -#define IP6_HLEN 38 +/* IP4 pseudo header */ +struct ipv4_pseudo_header { + struct in_addr src; + struct in_addr dest; + uint8_t zero_padding; + uint8_t protocol; + uint16_t len; +}; struct pk_buff; struct net_device; struct net_protocol; extern struct net_protocol ipv4_protocol; -extern struct net_protocol ipv6_protocol; extern int add_ipv4_address ( struct net_device *netdev, struct in_addr address, struct in_addr netmask, @@ -38,11 +41,6 @@ extern int add_ipv4_address ( struct net_device *netdev, extern void del_ipv4_address ( struct net_device *netdev ); extern int ipv4_uip_tx ( struct pk_buff *pkb ); - extern int ipv4_tx ( struct pk_buff *pkb, uint16_t trans_proto, struct in_addr *dest ); -extern int ipv6_tx ( struct pk_buff *pkb, uint16_t trans_proto, struct in6_addr *dest ); - -extern void ipv4_rx ( struct pk_buff *pkb, struct net_device *netdev, const void *ll_source ); -extern void ipv6_rx ( struct pk_buff *pkb, struct net_device *netdev, const void *ll_source ); #endif /* _GPXE_IP_H */ diff --git a/src/net/ipv4.c b/src/net/ipv4.c index 91b2d7ff..b770301a 100644 --- a/src/net/ipv4.c +++ b/src/net/ipv4.c @@ -124,21 +124,18 @@ static void ipv4_dump ( struct iphdr *iphdr __unused ) { void ipv4_tx_csum ( struct pk_buff *pkb, uint8_t trans_proto ) { struct iphdr *iphdr = pkb->data; - void *pshdr = malloc ( IP_PSHLEN ); - void *csum_offset = iphdr + IP_HLEN + ( trans_proto == IP_UDP ? 6 : 16 ); - int offset = 0; + struct ipv4_pseudo_header pshdr; + void *csum_offset = iphdr + sizeof ( *iphdr ) + ( trans_proto == IP_UDP ? 6 : 16 ); /* Calculate pseudo header */ - memcpy ( pshdr, &iphdr->src, sizeof ( in_addr ) ); - offset += sizeof ( in_addr ); - memcpy ( pshdr + offset, &iphdr->dest, sizeof ( in_addr ) ); - offset += sizeof ( in_addr ); - *( ( uint8_t* ) ( pshdr + offset++ ) ) = 0x00; - *( ( uint8_t* ) ( pshdr + offset++ ) ) = iphdr->protocol; - *( ( uint16_t* ) ( pshdr + offset ) ) = pkb_len ( pkb ) - IP_HLEN; + pshdr.src = iphdr->src; + pshdr.dest = iphdr->dest; + pshdr.zero_padding = 0x00; + pshdr.protocol = iphdr->protocol; + pshdr.len = htons ( pkb_len ( pkb ) - sizeof ( *iphdr ) ); /* Update the checksum value */ - *( ( uint16_t* ) csum_offset ) = *( ( uint16_t* ) csum_offset ) + calc_chksum ( pshdr, IP_PSHLEN ); + *( ( uint16_t* ) csum_offset ) = *( ( uint16_t* ) csum_offset ) + calc_chksum ( &pshdr, IP_PSHLEN ); } /**