Browse Source

Added ipv4_pseudo_header structure

tags/v0.9.3
Nikhil Chandru Rao 18 years ago
parent
commit
6e2c97b0c0
2 changed files with 16 additions and 21 deletions
  1. 8
    10
      src/include/gpxe/ip.h
  2. 8
    11
      src/net/ipv4.c

+ 8
- 10
src/include/gpxe/ip.h View File

11
 
11
 
12
 /* IP constants */
12
 /* IP constants */
13
 
13
 
14
-#define IP_HLEN 	20
15
 #define IP_VER		4
14
 #define IP_VER		4
16
 #define IP_MASK_VER	0xf0
15
 #define IP_MASK_VER	0xf0
17
 #define IP_MASK_HLEN 	0x0f
16
 #define IP_MASK_HLEN 	0x0f
21
 #define IP_TOS		0
20
 #define IP_TOS		0
22
 #define IP_TTL		64
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
 struct pk_buff;
32
 struct pk_buff;
29
 struct net_device;
33
 struct net_device;
30
 struct net_protocol;
34
 struct net_protocol;
31
 
35
 
32
 extern struct net_protocol ipv4_protocol;
36
 extern struct net_protocol ipv4_protocol;
33
-extern struct net_protocol ipv6_protocol;
34
 
37
 
35
 extern int add_ipv4_address ( struct net_device *netdev,
38
 extern int add_ipv4_address ( struct net_device *netdev,
36
 			      struct in_addr address, struct in_addr netmask,
39
 			      struct in_addr address, struct in_addr netmask,
38
 extern void del_ipv4_address ( struct net_device *netdev );
41
 extern void del_ipv4_address ( struct net_device *netdev );
39
 
42
 
40
 extern int ipv4_uip_tx ( struct pk_buff *pkb );
43
 extern int ipv4_uip_tx ( struct pk_buff *pkb );
41
-
42
 extern int ipv4_tx ( struct pk_buff *pkb, uint16_t trans_proto, struct in_addr *dest );
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
 #endif /* _GPXE_IP_H */
46
 #endif /* _GPXE_IP_H */

+ 8
- 11
src/net/ipv4.c View File

124
 void ipv4_tx_csum ( struct pk_buff *pkb, uint8_t trans_proto ) {
124
 void ipv4_tx_csum ( struct pk_buff *pkb, uint8_t trans_proto ) {
125
 
125
 
126
 	struct iphdr *iphdr = pkb->data;
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
 	/* Calculate pseudo header */
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
 	/* Update the checksum value */
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…
Cancel
Save