Selaa lähdekoodia

Added ipv4_pseudo_header structure

tags/v0.9.3
Nikhil Chandru Rao 18 vuotta sitten
vanhempi
commit
6e2c97b0c0
2 muutettua tiedostoa jossa 16 lisäystä ja 21 poistoa
  1. 8
    10
      src/include/gpxe/ip.h
  2. 8
    11
      src/net/ipv4.c

+ 8
- 10
src/include/gpxe/ip.h Näytä tiedosto

@@ -11,7 +11,6 @@
11 11
 
12 12
 /* IP constants */
13 13
 
14
-#define IP_HLEN 	20
15 14
 #define IP_VER		4
16 15
 #define IP_MASK_VER	0xf0
17 16
 #define IP_MASK_HLEN 	0x0f
@@ -21,16 +20,20 @@
21 20
 #define IP_TOS		0
22 21
 #define IP_TTL		64
23 22
 
24
-/* IP6 constants */
25
-
26
-#define IP6_HLEN	38
23
+/* IP4 pseudo header */
24
+struct ipv4_pseudo_header {
25
+	struct in_addr src;
26
+	struct in_addr dest;
27
+	uint8_t zero_padding;
28
+	uint8_t protocol;
29
+	uint16_t len;
30
+};
27 31
 
28 32
 struct pk_buff;
29 33
 struct net_device;
30 34
 struct net_protocol;
31 35
 
32 36
 extern struct net_protocol ipv4_protocol;
33
-extern struct net_protocol ipv6_protocol;
34 37
 
35 38
 extern int add_ipv4_address ( struct net_device *netdev,
36 39
 			      struct in_addr address, struct in_addr netmask,
@@ -38,11 +41,6 @@ extern int add_ipv4_address ( struct net_device *netdev,
38 41
 extern void del_ipv4_address ( struct net_device *netdev );
39 42
 
40 43
 extern int ipv4_uip_tx ( struct pk_buff *pkb );
41
-
42 44
 extern int ipv4_tx ( struct pk_buff *pkb, uint16_t trans_proto, struct in_addr *dest );
43
-extern int ipv6_tx ( struct pk_buff *pkb, uint16_t trans_proto, struct in6_addr *dest );
44
-
45
-extern void ipv4_rx ( struct pk_buff *pkb, struct net_device *netdev, const void *ll_source );
46
-extern void ipv6_rx ( struct pk_buff *pkb, struct net_device *netdev, const void *ll_source );
47 45
 
48 46
 #endif /* _GPXE_IP_H */

+ 8
- 11
src/net/ipv4.c Näytä tiedosto

@@ -124,21 +124,18 @@ static void ipv4_dump ( struct iphdr *iphdr __unused ) {
124 124
 void ipv4_tx_csum ( struct pk_buff *pkb, uint8_t trans_proto ) {
125 125
 
126 126
 	struct iphdr *iphdr = pkb->data;
127
-	void *pshdr = malloc ( IP_PSHLEN );
128
-	void *csum_offset = iphdr + IP_HLEN + ( trans_proto == IP_UDP ? 6 : 16 );
129
-	int offset = 0;
127
+	struct ipv4_pseudo_header pshdr;
128
+	void *csum_offset = iphdr + sizeof ( *iphdr ) + ( trans_proto == IP_UDP ? 6 : 16 );
130 129
 
131 130
 	/* Calculate pseudo header */
132
-	memcpy ( pshdr, &iphdr->src, sizeof ( in_addr ) );
133
-	offset += sizeof ( in_addr );
134
-	memcpy ( pshdr + offset, &iphdr->dest, sizeof ( in_addr ) );
135
-	offset += sizeof ( in_addr );
136
-	*( ( uint8_t* ) ( pshdr + offset++ ) ) = 0x00;
137
-	*( ( uint8_t* ) ( pshdr + offset++ ) ) = iphdr->protocol;
138
-	*( ( uint16_t* ) ( pshdr + offset ) ) = pkb_len ( pkb ) - IP_HLEN;
131
+	pshdr.src = iphdr->src;
132
+	pshdr.dest = iphdr->dest;
133
+	pshdr.zero_padding = 0x00;
134
+	pshdr.protocol = iphdr->protocol;
135
+	pshdr.len = htons ( pkb_len ( pkb ) - sizeof ( *iphdr ) );
139 136
 
140 137
 	/* Update the checksum value */
141
-	*( ( uint16_t* ) csum_offset ) = *( ( uint16_t* ) csum_offset ) + calc_chksum ( pshdr, IP_PSHLEN );
138
+	*( ( uint16_t* ) csum_offset ) = *( ( uint16_t* ) csum_offset ) + calc_chksum ( &pshdr, IP_PSHLEN );
142 139
 }
143 140
 
144 141
 /**

Loading…
Peruuta
Tallenna