|
@@ -50,16 +50,16 @@ add_ipv4_miniroute ( struct net_device *netdev, struct in_addr address,
|
50
|
50
|
struct in_addr netmask, struct in_addr gateway ) {
|
51
|
51
|
struct ipv4_miniroute *miniroute;
|
52
|
52
|
|
53
|
|
- DBG ( "IPv4 add %s", inet_ntoa ( address ) );
|
54
|
|
- DBG ( "/%s ", inet_ntoa ( netmask ) );
|
|
53
|
+ DBGC ( netdev, "IPv4 add %s", inet_ntoa ( address ) );
|
|
54
|
+ DBGC ( netdev, "/%s ", inet_ntoa ( netmask ) );
|
55
|
55
|
if ( gateway.s_addr )
|
56
|
|
- DBG ( "gw %s ", inet_ntoa ( gateway ) );
|
57
|
|
- DBG ( "via %s\n", netdev->name );
|
|
56
|
+ DBGC ( netdev, "gw %s ", inet_ntoa ( gateway ) );
|
|
57
|
+ DBGC ( netdev, "via %s\n", netdev->name );
|
58
|
58
|
|
59
|
59
|
/* Allocate and populate miniroute structure */
|
60
|
60
|
miniroute = malloc ( sizeof ( *miniroute ) );
|
61
|
61
|
if ( ! miniroute ) {
|
62
|
|
- DBG ( "IPv4 could not add miniroute\n" );
|
|
62
|
+ DBGC ( netdev, "IPv4 could not add miniroute\n" );
|
63
|
63
|
return NULL;
|
64
|
64
|
}
|
65
|
65
|
|
|
@@ -87,12 +87,13 @@ add_ipv4_miniroute ( struct net_device *netdev, struct in_addr address,
|
87
|
87
|
* @v miniroute Routing table entry
|
88
|
88
|
*/
|
89
|
89
|
static void del_ipv4_miniroute ( struct ipv4_miniroute *miniroute ) {
|
|
90
|
+ struct net_device *netdev = miniroute->netdev;
|
90
|
91
|
|
91
|
|
- DBG ( "IPv4 del %s", inet_ntoa ( miniroute->address ) );
|
92
|
|
- DBG ( "/%s ", inet_ntoa ( miniroute->netmask ) );
|
|
92
|
+ DBGC ( netdev, "IPv4 del %s", inet_ntoa ( miniroute->address ) );
|
|
93
|
+ DBGC ( netdev, "/%s ", inet_ntoa ( miniroute->netmask ) );
|
93
|
94
|
if ( miniroute->gateway.s_addr )
|
94
|
|
- DBG ( "gw %s ", inet_ntoa ( miniroute->gateway ) );
|
95
|
|
- DBG ( "via %s\n", miniroute->netdev->name );
|
|
95
|
+ DBGC ( netdev, "gw %s ", inet_ntoa ( miniroute->gateway ) );
|
|
96
|
+ DBGC ( netdev, "via %s\n", miniroute->netdev->name );
|
96
|
97
|
|
97
|
98
|
netdev_put ( miniroute->netdev );
|
98
|
99
|
list_del ( &miniroute->list );
|
|
@@ -143,7 +144,8 @@ static void ipv4_fragment_expired ( struct retry_timer *timer,
|
143
|
144
|
container_of ( timer, struct ipv4_fragment, timer );
|
144
|
145
|
struct iphdr *iphdr = frag->iobuf->data;
|
145
|
146
|
|
146
|
|
- DBG ( "IPv4 fragment %04x expired\n", ntohs ( iphdr->ident ) );
|
|
147
|
+ DBGC ( iphdr->src, "IPv4 fragment %04x expired\n",
|
|
148
|
+ ntohs ( iphdr->ident ) );
|
147
|
149
|
free_iob ( frag->iobuf );
|
148
|
150
|
list_del ( &frag->list );
|
149
|
151
|
free ( frag );
|
|
@@ -192,8 +194,9 @@ static struct io_buffer * ipv4_reassemble ( struct io_buffer *iobuf ) {
|
192
|
194
|
/* Drop out-of-order fragments */
|
193
|
195
|
expected_offset = ( frag ? frag->offset : 0 );
|
194
|
196
|
if ( offset != expected_offset ) {
|
195
|
|
- DBG ( "IPv4 dropping out-of-sequence fragment %04x (%zd+%zd, "
|
196
|
|
- "expected %zd)\n", ntohs ( iphdr->ident ), offset,
|
|
197
|
+ DBGC ( iphdr->src, "IPv4 dropping out-of-sequence fragment "
|
|
198
|
+ "%04x (%zd+%zd, expected %zd)\n",
|
|
199
|
+ ntohs ( iphdr->ident ), offset,
|
197
|
200
|
( iob_len ( iobuf ) - hdrlen ), expected_offset );
|
198
|
201
|
goto drop;
|
199
|
202
|
}
|
|
@@ -217,9 +220,9 @@ static struct io_buffer * ipv4_reassemble ( struct io_buffer *iobuf ) {
|
217
|
220
|
new_iobuf = alloc_iob ( iob_len ( frag->iobuf ) +
|
218
|
221
|
iob_len ( iobuf ) );
|
219
|
222
|
if ( ! new_iobuf ) {
|
220
|
|
- DBG ( "IPv4 could not extend reassembly buffer to "
|
221
|
|
- "%zd bytes\n",
|
222
|
|
- ( iob_len ( frag->iobuf ) + iob_len ( iobuf ) ) );
|
|
223
|
+ DBGC ( iphdr->src, "IPv4 could not extend reassembly "
|
|
224
|
+ "buffer to %zd bytes\n",
|
|
225
|
+ iob_len ( frag->iobuf ) + iob_len ( iobuf ) );
|
223
|
226
|
goto drop;
|
224
|
227
|
}
|
225
|
228
|
memcpy ( iob_put ( new_iobuf, iob_len ( frag->iobuf ) ),
|
|
@@ -356,7 +359,8 @@ static int ipv4_tx ( struct io_buffer *iobuf,
|
356
|
359
|
netdev = miniroute->netdev;
|
357
|
360
|
}
|
358
|
361
|
if ( ! netdev ) {
|
359
|
|
- DBG ( "IPv4 has no route to %s\n", inet_ntoa ( iphdr->dest ) );
|
|
362
|
+ DBGC ( sin_dest->sin_addr, "IPv4 has no route to %s\n",
|
|
363
|
+ inet_ntoa ( iphdr->dest ) );
|
360
|
364
|
rc = -ENETUNREACH;
|
361
|
365
|
goto err;
|
362
|
366
|
}
|
|
@@ -372,8 +376,8 @@ static int ipv4_tx ( struct io_buffer *iobuf,
|
372
|
376
|
/* Determine link-layer destination address */
|
373
|
377
|
if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netmask, netdev,
|
374
|
378
|
ll_dest ) ) != 0 ) {
|
375
|
|
- DBG ( "IPv4 has no link-layer address for %s: %s\n",
|
376
|
|
- inet_ntoa ( next_hop ), strerror ( rc ) );
|
|
379
|
+ DBGC ( sin_dest->sin_addr, "IPv4 has no link-layer address for "
|
|
380
|
+ "%s: %s\n", inet_ntoa ( next_hop ), strerror ( rc ) );
|
377
|
381
|
/* Record error for diagnosis */
|
378
|
382
|
netdev_tx_err ( netdev, iob_disown ( iobuf ), rc );
|
379
|
383
|
goto err;
|
|
@@ -385,16 +389,17 @@ static int ipv4_tx ( struct io_buffer *iobuf,
|
385
|
389
|
iphdr->chksum = tcpip_chksum ( iphdr, sizeof ( *iphdr ) );
|
386
|
390
|
|
387
|
391
|
/* Print IP4 header for debugging */
|
388
|
|
- DBG ( "IPv4 TX %s->", inet_ntoa ( iphdr->src ) );
|
389
|
|
- DBG ( "%s len %d proto %d id %04x csum %04x\n",
|
390
|
|
- inet_ntoa ( iphdr->dest ), ntohs ( iphdr->len ), iphdr->protocol,
|
391
|
|
- ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
|
|
392
|
+ DBGC2 ( sin_dest->sin_addr, "IPv4 TX %s->", inet_ntoa ( iphdr->src ) );
|
|
393
|
+ DBGC2 ( sin_dest->sin_addr, "%s len %d proto %d id %04x csum %04x\n",
|
|
394
|
+ inet_ntoa ( iphdr->dest ), ntohs ( iphdr->len ),
|
|
395
|
+ iphdr->protocol, ntohs ( iphdr->ident ),
|
|
396
|
+ ntohs ( iphdr->chksum ) );
|
392
|
397
|
|
393
|
398
|
/* Hand off to link layer */
|
394
|
399
|
if ( ( rc = net_tx ( iobuf, netdev, &ipv4_protocol, ll_dest,
|
395
|
400
|
netdev->ll_addr ) ) != 0 ) {
|
396
|
|
- DBG ( "IPv4 could not transmit packet via %s: %s\n",
|
397
|
|
- netdev->name, strerror ( rc ) );
|
|
401
|
+ DBGC ( sin_dest->sin_addr, "IPv4 could not transmit packet "
|
|
402
|
+ "via %s: %s\n", netdev->name, strerror ( rc ) );
|
398
|
403
|
return rc;
|
399
|
404
|
}
|
400
|
405
|
|
|
@@ -472,39 +477,40 @@ static int ipv4_rx ( struct io_buffer *iobuf,
|
472
|
477
|
|
473
|
478
|
/* Sanity check the IPv4 header */
|
474
|
479
|
if ( iob_len ( iobuf ) < sizeof ( *iphdr ) ) {
|
475
|
|
- DBG ( "IPv4 packet too short at %zd bytes (min %zd bytes)\n",
|
476
|
|
- iob_len ( iobuf ), sizeof ( *iphdr ) );
|
|
480
|
+ DBGC ( iphdr->src, "IPv4 packet too short at %zd bytes (min "
|
|
481
|
+ "%zd bytes)\n", iob_len ( iobuf ), sizeof ( *iphdr ) );
|
477
|
482
|
goto err;
|
478
|
483
|
}
|
479
|
484
|
if ( ( iphdr->verhdrlen & IP_MASK_VER ) != IP_VER ) {
|
480
|
|
- DBG ( "IPv4 version %#02x not supported\n", iphdr->verhdrlen );
|
|
485
|
+ DBGC ( iphdr->src, "IPv4 version %#02x not supported\n",
|
|
486
|
+ iphdr->verhdrlen );
|
481
|
487
|
goto err;
|
482
|
488
|
}
|
483
|
489
|
hdrlen = ( ( iphdr->verhdrlen & IP_MASK_HLEN ) * 4 );
|
484
|
490
|
if ( hdrlen < sizeof ( *iphdr ) ) {
|
485
|
|
- DBG ( "IPv4 header too short at %zd bytes (min %zd bytes)\n",
|
486
|
|
- hdrlen, sizeof ( *iphdr ) );
|
|
491
|
+ DBGC ( iphdr->src, "IPv4 header too short at %zd bytes (min "
|
|
492
|
+ "%zd bytes)\n", hdrlen, sizeof ( *iphdr ) );
|
487
|
493
|
goto err;
|
488
|
494
|
}
|
489
|
495
|
if ( hdrlen > iob_len ( iobuf ) ) {
|
490
|
|
- DBG ( "IPv4 header too long at %zd bytes "
|
491
|
|
- "(packet is %zd bytes)\n", hdrlen, iob_len ( iobuf ) );
|
|
496
|
+ DBGC ( iphdr->src, "IPv4 header too long at %zd bytes "
|
|
497
|
+ "(packet is %zd bytes)\n", hdrlen, iob_len ( iobuf ) );
|
492
|
498
|
goto err;
|
493
|
499
|
}
|
494
|
500
|
if ( ( csum = tcpip_chksum ( iphdr, hdrlen ) ) != 0 ) {
|
495
|
|
- DBG ( "IPv4 checksum incorrect (is %04x including checksum "
|
496
|
|
- "field, should be 0000)\n", csum );
|
|
501
|
+ DBGC ( iphdr->src, "IPv4 checksum incorrect (is %04x "
|
|
502
|
+ "including checksum field, should be 0000)\n", csum );
|
497
|
503
|
goto err;
|
498
|
504
|
}
|
499
|
505
|
len = ntohs ( iphdr->len );
|
500
|
506
|
if ( len < hdrlen ) {
|
501
|
|
- DBG ( "IPv4 length too short at %zd bytes "
|
502
|
|
- "(header is %zd bytes)\n", len, hdrlen );
|
|
507
|
+ DBGC ( iphdr->src, "IPv4 length too short at %zd bytes "
|
|
508
|
+ "(header is %zd bytes)\n", len, hdrlen );
|
503
|
509
|
goto err;
|
504
|
510
|
}
|
505
|
511
|
if ( len > iob_len ( iobuf ) ) {
|
506
|
|
- DBG ( "IPv4 length too long at %zd bytes "
|
507
|
|
- "(packet is %zd bytes)\n", len, iob_len ( iobuf ) );
|
|
512
|
+ DBGC ( iphdr->src, "IPv4 length too long at %zd bytes "
|
|
513
|
+ "(packet is %zd bytes)\n", len, iob_len ( iobuf ) );
|
508
|
514
|
goto err;
|
509
|
515
|
}
|
510
|
516
|
|
|
@@ -512,17 +518,17 @@ static int ipv4_rx ( struct io_buffer *iobuf,
|
512
|
518
|
iob_unput ( iobuf, ( iob_len ( iobuf ) - len ) );
|
513
|
519
|
|
514
|
520
|
/* Print IPv4 header for debugging */
|
515
|
|
- DBG ( "IPv4 RX %s<-", inet_ntoa ( iphdr->dest ) );
|
516
|
|
- DBG ( "%s len %d proto %d id %04x csum %04x\n",
|
517
|
|
- inet_ntoa ( iphdr->src ), ntohs ( iphdr->len ), iphdr->protocol,
|
518
|
|
- ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
|
|
521
|
+ DBGC2 ( iphdr->src, "IPv4 RX %s<-", inet_ntoa ( iphdr->dest ) );
|
|
522
|
+ DBGC2 ( iphdr->src, "%s len %d proto %d id %04x csum %04x\n",
|
|
523
|
+ inet_ntoa ( iphdr->src ), ntohs ( iphdr->len ), iphdr->protocol,
|
|
524
|
+ ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
|
519
|
525
|
|
520
|
526
|
/* Discard unicast packets not destined for us */
|
521
|
527
|
if ( ( ! ( flags & LL_MULTICAST ) ) &&
|
522
|
528
|
ipv4_has_any_addr ( netdev ) &&
|
523
|
529
|
( ! ipv4_has_addr ( netdev, iphdr->dest ) ) ) {
|
524
|
|
- DBG ( "IPv4 discarding non-local unicast packet for %s\n",
|
525
|
|
- inet_ntoa ( iphdr->dest ) );
|
|
530
|
+ DBGC ( iphdr->src, "IPv4 discarding non-local unicast packet "
|
|
531
|
+ "for %s\n", inet_ntoa ( iphdr->dest ) );
|
526
|
532
|
goto err;
|
527
|
533
|
}
|
528
|
534
|
|
|
@@ -551,8 +557,8 @@ static int ipv4_rx ( struct io_buffer *iobuf,
|
551
|
557
|
iob_pull ( iobuf, hdrlen );
|
552
|
558
|
if ( ( rc = tcpip_rx ( iobuf, iphdr->protocol, &src.st,
|
553
|
559
|
&dest.st, pshdr_csum ) ) != 0 ) {
|
554
|
|
- DBG ( "IPv4 received packet rejected by stack: %s\n",
|
555
|
|
- strerror ( rc ) );
|
|
560
|
+ DBGC ( src.sin.sin_addr, "IPv4 received packet rejected by "
|
|
561
|
+ "stack: %s\n", strerror ( rc ) );
|
556
|
562
|
return rc;
|
557
|
563
|
}
|
558
|
564
|
|