|
@@ -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
|
/**
|