Browse Source

Factorise out common code

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
b49de73950
1 changed files with 23 additions and 25 deletions
  1. 23
    25
      src/net/ipv4.c

+ 23
- 25
src/net/ipv4.c View File

@@ -97,6 +97,27 @@ void del_ipv4_address ( struct net_device *netdev ) {
97 97
 	}
98 98
 }
99 99
 
100
+/**
101
+ * Dump IPv4 packet header
102
+ *
103
+ * @v iphdr	IPv4 header
104
+ */
105
+static void ipv4_dump ( struct iphdr *iphdr __unused ) {
106
+	DBG ( "IP4 header at %p+%zx\n", iphdr, sizeof ( *iphdr ) );
107
+	DBG ( "\tVersion = %d\n", ( iphdr->verhdrlen & IP_MASK_VER ) / 16 );
108
+	DBG ( "\tHeader length = %d\n", iphdr->verhdrlen & IP_MASK_HLEN );
109
+	DBG ( "\tService = %d\n", iphdr->service );
110
+	DBG ( "\tTotal length = %d\n", iphdr->len );
111
+	DBG ( "\tIdent = %d\n", iphdr->ident );
112
+	DBG ( "\tFrags/Offset = %d\n", iphdr->frags );
113
+	DBG ( "\tIP TTL = %d\n", iphdr->ttl );
114
+	DBG ( "\tProtocol = %d\n", iphdr->protocol );
115
+	DBG ( "\tHeader Checksum (at %p) = %x\n", &iphdr->chksum,
116
+	      iphdr->chksum );
117
+	DBG ( "\tSource = %s\n", inet_ntoa ( iphdr->src ) );
118
+	DBG ( "\tDestination = %s\n", inet_ntoa ( iphdr->dest ) );
119
+}
120
+
100 121
 /**
101 122
  * Complete the transport-layer checksum
102 123
  *
@@ -271,19 +292,7 @@ int ipv4_tx ( struct pk_buff *pkb, uint16_t trans_proto, struct in_addr *dest )
271 292
 	ipv4_tx_csum ( pkb, trans_proto );
272 293
 
273 294
 	/* Print IP4 header for debugging */
274
-	DBG ( "IP4 header at %#x + %d\n", iphdr, IP_HLEN  );
275
-	DBG ( "\tVersion = %d\n", ( iphdr->verhdrlen & IP_MASK_VER ) / 16 );
276
-	DBG ( "\tHeader length = %d\n", iphdr->verhdrlen & IP_MASK_HLEN );
277
-	DBG ( "\tService = %d\n", iphdr->service );
278
-	DBG ( "\tTotal length = %d\n", iphdr->len );
279
-	DBG ( "\tIdent = %d\n", iphdr->ident );
280
-	DBG ( "\tFrags/Offset = %d\n", iphdr->frags );
281
-	DBG ( "\tIP TTL = %d\n", iphdr->ttl );
282
-	DBG ( "\tProtocol = %d\n", iphdr->protocol );
283
-	DBG ( "\tHeader Checksum (at %#x) = %x\n", &iphdr->chksum, iphdr->chksum );
284
-	DBG ( "\tSource = %s\n", inet_ntoa ( iphdr->src) );
285
-	DBG ( "\tDestination = %s\n", inet_ntoa ( iphdr->dest ) );
286
-
295
+	ipv4_dump ( iphdr );
287 296
 
288 297
 	/* Determine link-layer destination address */
289 298
 	if ( next_hop.s_addr == INADDR_BROADCAST ) {
@@ -370,18 +379,7 @@ void ipv4_rx ( struct pk_buff *pkb, struct net_device *netdev __unused,
370 379
 	uint16_t chksum;
371 380
 
372 381
 	/* Print IP4 header for debugging */
373
-	DBG ( "IP4 header at %#x + %d\n", iphdr, IP_HLEN  );
374
-	DBG ( "\tVersion = %d\n", ( iphdr->verhdrlen & IP_MASK_VER ) / 16 );
375
-	DBG ( "\tHeader length = %d\n", iphdr->verhdrlen & IP_MASK_HLEN );
376
-	DBG ( "\tService = %d\n", iphdr->service );
377
-	DBG ( "\tTotal length = %d\n", iphdr->len );
378
-	DBG ( "\tIdent = %d\n", iphdr->ident );
379
-	DBG ( "\tFrags/Offset = %d\n", iphdr->frags );
380
-	DBG ( "\tIP TTL = %d\n", iphdr->ttl );
381
-	DBG ( "\tProtocol = %d\n", iphdr->protocol );
382
-	DBG ( "\tHeader Checksum (at %#x) = %x\n", &iphdr->chksum, iphdr->chksum );
383
-	DBG ( "\tSource = %s\n", inet_ntoa ( iphdr->src) );
384
-	DBG ( "\tDestination = %s\n", inet_ntoa ( iphdr->dest ) );
382
+	ipv4_dump ( iphdr );
385 383
 
386 384
 	/* Process headers */
387 385
 	if ( iphdr->verhdrlen != 0x45 ) {

Loading…
Cancel
Save