Browse Source

pkbuff->iobuf changeover

Achieved via Perl using:

perl -pi -e 's/pk_buff/io_buffer/g; s/Packet buffer/I\/O buffer/ig; ' \
	-e 's/pkbuff\.h/iobuf.h/g; s/pkb_/iob_/g; s/_pkb/_iob/g; ' \
	-e 's/pkb/iobuf/g; s/PKB/IOB/g;'
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
3e2c6b6736

+ 27
- 27
src/arch/i386/drivers/net/undinet.c View File

22
 #include <pic8259.h>
22
 #include <pic8259.h>
23
 #include <biosint.h>
23
 #include <biosint.h>
24
 #include <pnpbios.h>
24
 #include <pnpbios.h>
25
-#include <gpxe/pkbuff.h>
25
+#include <gpxe/iobuf.h>
26
 #include <gpxe/netdevice.h>
26
 #include <gpxe/netdevice.h>
27
 #include <gpxe/if_ether.h>
27
 #include <gpxe/if_ether.h>
28
 #include <gpxe/ethernet.h>
28
 #include <gpxe/ethernet.h>
315
  */
315
  */
316
 
316
 
317
 /** Maximum length of a packet transmitted via the UNDI API */
317
 /** Maximum length of a packet transmitted via the UNDI API */
318
-#define UNDI_PKB_LEN 1514
318
+#define UNDI_IOB_LEN 1514
319
 
319
 
320
-/** UNDI packet buffer */
321
-static char __data16_array ( undinet_pkb, [UNDI_PKB_LEN] );
322
-#define undinet_pkb __use_data16 ( undinet_pkb )
320
+/** UNDI I/O buffer */
321
+static char __data16_array ( undinet_iob, [UNDI_IOB_LEN] );
322
+#define undinet_iob __use_data16 ( undinet_iob )
323
 
323
 
324
 /** UNDI transmit buffer descriptor */
324
 /** UNDI transmit buffer descriptor */
325
 static struct s_PXENV_UNDI_TBD __data16 ( undinet_tbd );
325
 static struct s_PXENV_UNDI_TBD __data16 ( undinet_tbd );
329
  * Transmit packet
329
  * Transmit packet
330
  *
330
  *
331
  * @v netdev		Network device
331
  * @v netdev		Network device
332
- * @v pkb		Packet buffer
332
+ * @v iobuf		I/O buffer
333
  * @ret rc		Return status code
333
  * @ret rc		Return status code
334
  */
334
  */
335
 static int undinet_transmit ( struct net_device *netdev,
335
 static int undinet_transmit ( struct net_device *netdev,
336
-			      struct pk_buff *pkb ) {
336
+			      struct io_buffer *iobuf ) {
337
 	struct undi_nic *undinic = netdev->priv;
337
 	struct undi_nic *undinic = netdev->priv;
338
 	struct s_PXENV_UNDI_TRANSMIT undi_transmit;
338
 	struct s_PXENV_UNDI_TRANSMIT undi_transmit;
339
-	size_t len = pkb_len ( pkb );
339
+	size_t len = iob_len ( iobuf );
340
 	int rc;
340
 	int rc;
341
 
341
 
342
-	/* Copy packet to UNDI packet buffer */
343
-	if ( len > sizeof ( undinet_pkb ) )
344
-		len = sizeof ( undinet_pkb );
345
-	memcpy ( &undinet_pkb, pkb->data, len );
342
+	/* Copy packet to UNDI I/O buffer */
343
+	if ( len > sizeof ( undinet_iob ) )
344
+		len = sizeof ( undinet_iob );
345
+	memcpy ( &undinet_iob, iobuf->data, len );
346
 
346
 
347
 	/* Create PXENV_UNDI_TRANSMIT data structure */
347
 	/* Create PXENV_UNDI_TRANSMIT data structure */
348
 	memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
348
 	memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
357
 	undinet_tbd.ImmedLength = len;
357
 	undinet_tbd.ImmedLength = len;
358
 	undinet_tbd.Xmit.segment = rm_ds;
358
 	undinet_tbd.Xmit.segment = rm_ds;
359
 	undinet_tbd.Xmit.offset 
359
 	undinet_tbd.Xmit.offset 
360
-		= ( ( unsigned ) & __from_data16 ( undinet_pkb ) );
360
+		= ( ( unsigned ) & __from_data16 ( undinet_iob ) );
361
 
361
 
362
 	/* Issue PXE API call */
362
 	/* Issue PXE API call */
363
 	if ( ( rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT,
363
 	if ( ( rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT,
365
 				   sizeof ( undi_transmit ) ) ) != 0 )
365
 				   sizeof ( undi_transmit ) ) ) != 0 )
366
 		goto done;
366
 		goto done;
367
 
367
 
368
-	/* Free packet buffer */
369
-	netdev_tx_complete ( netdev, pkb );
368
+	/* Free I/O buffer */
369
+	netdev_tx_complete ( netdev, iobuf );
370
 
370
 
371
  done:
371
  done:
372
 	return rc;
372
 	return rc;
397
 static void undinet_poll ( struct net_device *netdev, unsigned int rx_quota ) {
397
 static void undinet_poll ( struct net_device *netdev, unsigned int rx_quota ) {
398
 	struct undi_nic *undinic = netdev->priv;
398
 	struct undi_nic *undinic = netdev->priv;
399
 	struct s_PXENV_UNDI_ISR undi_isr;
399
 	struct s_PXENV_UNDI_ISR undi_isr;
400
-	struct pk_buff *pkb = NULL;
400
+	struct io_buffer *iobuf = NULL;
401
 	size_t len;
401
 	size_t len;
402
 	size_t frag_len;
402
 	size_t frag_len;
403
 	int rc;
403
 	int rc;
448
 			/* Packet fragment received */
448
 			/* Packet fragment received */
449
 			len = undi_isr.FrameLength;
449
 			len = undi_isr.FrameLength;
450
 			frag_len = undi_isr.BufferLength;
450
 			frag_len = undi_isr.BufferLength;
451
-			if ( ! pkb )
452
-				pkb = alloc_pkb ( len );
453
-			if ( ! pkb ) {
451
+			if ( ! iobuf )
452
+				iobuf = alloc_iob ( len );
453
+			if ( ! iobuf ) {
454
 				DBGC ( undinic, "UNDINIC %p could not "
454
 				DBGC ( undinic, "UNDINIC %p could not "
455
 				       "allocate %zd bytes for RX buffer\n",
455
 				       "allocate %zd bytes for RX buffer\n",
456
 				       undinic, len );
456
 				       undinic, len );
457
 				/* Fragment will be dropped */
457
 				/* Fragment will be dropped */
458
 				goto done;
458
 				goto done;
459
 			}
459
 			}
460
-			if ( frag_len > pkb_tailroom ( pkb ) ) {
460
+			if ( frag_len > iob_tailroom ( iobuf ) ) {
461
 				DBGC ( undinic, "UNDINIC %p fragment too "
461
 				DBGC ( undinic, "UNDINIC %p fragment too "
462
 				       "large\n", undinic );
462
 				       "large\n", undinic );
463
-				frag_len = pkb_tailroom ( pkb );
463
+				frag_len = iob_tailroom ( iobuf );
464
 			}
464
 			}
465
-			copy_from_real ( pkb_put ( pkb, frag_len ),
465
+			copy_from_real ( iob_put ( iobuf, frag_len ),
466
 					 undi_isr.Frame.segment,
466
 					 undi_isr.Frame.segment,
467
 					 undi_isr.Frame.offset, frag_len );
467
 					 undi_isr.Frame.offset, frag_len );
468
-			if ( pkb_len ( pkb ) == len ) {
469
-				netdev_rx ( netdev, pkb );
470
-				pkb = NULL;
468
+			if ( iob_len ( iobuf ) == len ) {
469
+				netdev_rx ( netdev, iobuf );
470
+				iobuf = NULL;
471
 				--rx_quota;
471
 				--rx_quota;
472
 			}
472
 			}
473
 			break;
473
 			break;
486
 	}
486
 	}
487
 
487
 
488
  done:
488
  done:
489
-	if ( pkb ) {
489
+	if ( iobuf ) {
490
 		DBGC ( undinic, "UNDINIC %p returned incomplete packet\n",
490
 		DBGC ( undinic, "UNDINIC %p returned incomplete packet\n",
491
 		       undinic );
491
 		       undinic );
492
-		netdev_rx ( netdev, pkb );
492
+		netdev_rx ( netdev, iobuf );
493
 	}
493
 	}
494
 }
494
 }
495
 
495
 

+ 15
- 15
src/drivers/net/legacy.c View File

4
 #include <gpxe/if_ether.h>
4
 #include <gpxe/if_ether.h>
5
 #include <gpxe/netdevice.h>
5
 #include <gpxe/netdevice.h>
6
 #include <gpxe/ethernet.h>
6
 #include <gpxe/ethernet.h>
7
-#include <gpxe/pkbuff.h>
7
+#include <gpxe/iobuf.h>
8
 #include <nic.h>
8
 #include <nic.h>
9
 
9
 
10
 /*
10
 /*
21
 
21
 
22
 static int legacy_registered = 0;
22
 static int legacy_registered = 0;
23
 
23
 
24
-static int legacy_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
24
+static int legacy_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
25
 	struct nic *nic = netdev->priv;
25
 	struct nic *nic = netdev->priv;
26
-	struct ethhdr *ethhdr = pkb->data;
26
+	struct ethhdr *ethhdr = iobuf->data;
27
 
27
 
28
-	DBG ( "Transmitting %d bytes\n", pkb_len ( pkb ) );
29
-	pkb_pad ( pkb, ETH_ZLEN );
30
-	pkb_pull ( pkb, sizeof ( *ethhdr ) );
28
+	DBG ( "Transmitting %d bytes\n", iob_len ( iobuf ) );
29
+	iob_pad ( iobuf, ETH_ZLEN );
30
+	iob_pull ( iobuf, sizeof ( *ethhdr ) );
31
 	nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
31
 	nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
32
 				ntohs ( ethhdr->h_protocol ),
32
 				ntohs ( ethhdr->h_protocol ),
33
-				pkb_len ( pkb ), pkb->data );
34
-	netdev_tx_complete ( netdev, pkb );
33
+				iob_len ( iobuf ), iobuf->data );
34
+	netdev_tx_complete ( netdev, iobuf );
35
 	return 0;
35
 	return 0;
36
 }
36
 }
37
 
37
 
38
 static void legacy_poll ( struct net_device *netdev, unsigned int rx_quota ) {
38
 static void legacy_poll ( struct net_device *netdev, unsigned int rx_quota ) {
39
 	struct nic *nic = netdev->priv;
39
 	struct nic *nic = netdev->priv;
40
-	struct pk_buff *pkb;
40
+	struct io_buffer *iobuf;
41
 
41
 
42
 	if ( ! rx_quota )
42
 	if ( ! rx_quota )
43
 		return;
43
 		return;
44
 
44
 
45
-	pkb = alloc_pkb ( ETH_FRAME_LEN );
46
-	if ( ! pkb )
45
+	iobuf = alloc_iob ( ETH_FRAME_LEN );
46
+	if ( ! iobuf )
47
 		return;
47
 		return;
48
 
48
 
49
-	nic->packet = pkb->data;
49
+	nic->packet = iobuf->data;
50
 	if ( nic->nic_op->poll ( nic, 1 ) ) {
50
 	if ( nic->nic_op->poll ( nic, 1 ) ) {
51
 		DBG ( "Received %d bytes\n", nic->packetlen );
51
 		DBG ( "Received %d bytes\n", nic->packetlen );
52
-		pkb_put ( pkb, nic->packetlen );
53
-		netdev_rx ( netdev, pkb );
52
+		iob_put ( iobuf, nic->packetlen );
53
+		netdev_rx ( netdev, iobuf );
54
 	} else {
54
 	} else {
55
-		free_pkb ( pkb );
55
+		free_iob ( iobuf );
56
 	}
56
 	}
57
 }
57
 }
58
 
58
 

+ 12
- 12
src/drivers/net/pnic.c View File

19
 #include <gpxe/pci.h>
19
 #include <gpxe/pci.h>
20
 #include <gpxe/if_ether.h>
20
 #include <gpxe/if_ether.h>
21
 #include <gpxe/ethernet.h>
21
 #include <gpxe/ethernet.h>
22
-#include <gpxe/pkbuff.h>
22
+#include <gpxe/iobuf.h>
23
 #include <gpxe/netdevice.h>
23
 #include <gpxe/netdevice.h>
24
 
24
 
25
 #include "pnic_api.h"
25
 #include "pnic_api.h"
114
 ***************************************************************************/
114
 ***************************************************************************/
115
 static void pnic_poll ( struct net_device *netdev, unsigned int rx_quota ) {
115
 static void pnic_poll ( struct net_device *netdev, unsigned int rx_quota ) {
116
 	struct pnic *pnic = netdev->priv;
116
 	struct pnic *pnic = netdev->priv;
117
-	struct pk_buff *pkb;
117
+	struct io_buffer *iobuf;
118
 	uint16_t length;
118
 	uint16_t length;
119
 	uint16_t qlen;
119
 	uint16_t qlen;
120
 
120
 
126
 			break;
126
 			break;
127
 		if ( qlen == 0 )
127
 		if ( qlen == 0 )
128
 			break;
128
 			break;
129
-		pkb = alloc_pkb ( ETH_FRAME_LEN );
130
-		if ( ! pkb ) {
129
+		iobuf = alloc_iob ( ETH_FRAME_LEN );
130
+		if ( ! iobuf ) {
131
 			printf ( "could not allocate buffer\n" );
131
 			printf ( "could not allocate buffer\n" );
132
 			break;
132
 			break;
133
 		}
133
 		}
134
 		if ( pnic_command ( pnic, PNIC_CMD_RECV, NULL, 0,
134
 		if ( pnic_command ( pnic, PNIC_CMD_RECV, NULL, 0,
135
-				    pkb->data, ETH_FRAME_LEN, &length )
135
+				    iobuf->data, ETH_FRAME_LEN, &length )
136
 		     != PNIC_STATUS_OK ) {
136
 		     != PNIC_STATUS_OK ) {
137
-			free_pkb ( pkb );
137
+			free_iob ( iobuf );
138
 			break;
138
 			break;
139
 		}
139
 		}
140
-		pkb_put ( pkb, length );
141
-		netdev_rx ( netdev, pkb );
140
+		iob_put ( iobuf, length );
141
+		netdev_rx ( netdev, iobuf );
142
 		--rx_quota;
142
 		--rx_quota;
143
 	}
143
 	}
144
 }
144
 }
146
 /**************************************************************************
146
 /**************************************************************************
147
 TRANSMIT - Transmit a frame
147
 TRANSMIT - Transmit a frame
148
 ***************************************************************************/
148
 ***************************************************************************/
149
-static int pnic_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
149
+static int pnic_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
150
 	struct pnic *pnic = netdev->priv;
150
 	struct pnic *pnic = netdev->priv;
151
 
151
 
152
 	/* Pad the packet */
152
 	/* Pad the packet */
153
-	pkb_pad ( pkb, ETH_ZLEN );
153
+	iob_pad ( iobuf, ETH_ZLEN );
154
 
154
 
155
 	/* Send packet */
155
 	/* Send packet */
156
-	pnic_command ( pnic, PNIC_CMD_XMIT, pkb->data, pkb_len ( pkb ),
156
+	pnic_command ( pnic, PNIC_CMD_XMIT, iobuf->data, iob_len ( iobuf ),
157
 		       NULL, 0, NULL );
157
 		       NULL, 0, NULL );
158
 
158
 
159
-	netdev_tx_complete ( netdev, pkb );
159
+	netdev_tx_complete ( netdev, iobuf );
160
 	return 0;
160
 	return 0;
161
 }
161
 }
162
 
162
 

+ 19
- 19
src/drivers/net/rtl8139.c View File

76
 #include <gpxe/pci.h>
76
 #include <gpxe/pci.h>
77
 #include <gpxe/if_ether.h>
77
 #include <gpxe/if_ether.h>
78
 #include <gpxe/ethernet.h>
78
 #include <gpxe/ethernet.h>
79
-#include <gpxe/pkbuff.h>
79
+#include <gpxe/iobuf.h>
80
 #include <gpxe/netdevice.h>
80
 #include <gpxe/netdevice.h>
81
 #include <gpxe/spi_bit.h>
81
 #include <gpxe/spi_bit.h>
82
 #include <gpxe/threewire.h>
82
 #include <gpxe/threewire.h>
86
 
86
 
87
 struct rtl8139_tx {
87
 struct rtl8139_tx {
88
 	unsigned int next;
88
 	unsigned int next;
89
-	struct pk_buff *pkb[TX_RING_SIZE];
89
+	struct io_buffer *iobuf[TX_RING_SIZE];
90
 };
90
 };
91
 
91
 
92
 struct rtl8139_rx {
92
 struct rtl8139_rx {
363
  * Transmit packet
363
  * Transmit packet
364
  *
364
  *
365
  * @v netdev	Network device
365
  * @v netdev	Network device
366
- * @v pkb	Packet buffer
366
+ * @v iobuf	I/O buffer
367
  * @ret rc	Return status code
367
  * @ret rc	Return status code
368
  */
368
  */
369
-static int rtl_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
369
+static int rtl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
370
 	struct rtl8139_nic *rtl = netdev->priv;
370
 	struct rtl8139_nic *rtl = netdev->priv;
371
 
371
 
372
 	/* Check for space in TX ring */
372
 	/* Check for space in TX ring */
373
-	if ( rtl->tx.pkb[rtl->tx.next] != NULL ) {
373
+	if ( rtl->tx.iobuf[rtl->tx.next] != NULL ) {
374
 		printf ( "TX overflow\n" );
374
 		printf ( "TX overflow\n" );
375
 		return -ENOBUFS;
375
 		return -ENOBUFS;
376
 	}
376
 	}
377
 
377
 
378
 	/* Pad and align packet */
378
 	/* Pad and align packet */
379
-	pkb_pad ( pkb, ETH_ZLEN );
379
+	iob_pad ( iobuf, ETH_ZLEN );
380
 
380
 
381
 	/* Add to TX ring */
381
 	/* Add to TX ring */
382
 	DBG ( "TX id %d at %lx+%x\n", rtl->tx.next,
382
 	DBG ( "TX id %d at %lx+%x\n", rtl->tx.next,
383
-	      virt_to_bus ( pkb->data ), pkb_len ( pkb ) );
384
-	rtl->tx.pkb[rtl->tx.next] = pkb;
385
-	outl ( virt_to_bus ( pkb->data ),
383
+	      virt_to_bus ( iobuf->data ), iob_len ( iobuf ) );
384
+	rtl->tx.iobuf[rtl->tx.next] = iobuf;
385
+	outl ( virt_to_bus ( iobuf->data ),
386
 	       rtl->ioaddr + TxAddr0 + 4 * rtl->tx.next );
386
 	       rtl->ioaddr + TxAddr0 + 4 * rtl->tx.next );
387
-	outl ( ( ( ( TX_FIFO_THRESH & 0x7e0 ) << 11 ) | pkb_len ( pkb ) ),
387
+	outl ( ( ( ( TX_FIFO_THRESH & 0x7e0 ) << 11 ) | iob_len ( iobuf ) ),
388
 	       rtl->ioaddr + TxStatus0 + 4 * rtl->tx.next );
388
 	       rtl->ioaddr + TxStatus0 + 4 * rtl->tx.next );
389
 	rtl->tx.next = ( rtl->tx.next + 1 ) % TX_RING_SIZE;
389
 	rtl->tx.next = ( rtl->tx.next + 1 ) % TX_RING_SIZE;
390
 
390
 
403
 	unsigned int tsad;
403
 	unsigned int tsad;
404
 	unsigned int rx_status;
404
 	unsigned int rx_status;
405
 	unsigned int rx_len;
405
 	unsigned int rx_len;
406
-	struct pk_buff *rx_pkb;
406
+	struct io_buffer *rx_iob;
407
 	int wrapped_len;
407
 	int wrapped_len;
408
 	int i;
408
 	int i;
409
 
409
 
416
 	/* Handle TX completions */
416
 	/* Handle TX completions */
417
 	tsad = inw ( rtl->ioaddr + TxSummary );
417
 	tsad = inw ( rtl->ioaddr + TxSummary );
418
 	for ( i = 0 ; i < TX_RING_SIZE ; i++ ) {
418
 	for ( i = 0 ; i < TX_RING_SIZE ; i++ ) {
419
-		if ( ( rtl->tx.pkb[i] != NULL ) && ( tsad & ( 1 << i ) ) ) {
419
+		if ( ( rtl->tx.iobuf[i] != NULL ) && ( tsad & ( 1 << i ) ) ) {
420
 			DBG ( "TX id %d complete\n", i );
420
 			DBG ( "TX id %d complete\n", i );
421
-			netdev_tx_complete ( netdev, rtl->tx.pkb[i] );
422
-			rtl->tx.pkb[i] = NULL;
421
+			netdev_tx_complete ( netdev, rtl->tx.iobuf[i] );
422
+			rtl->tx.iobuf[i] = NULL;
423
 		}
423
 		}
424
 	}
424
 	}
425
 
425
 
433
 			DBG ( "RX packet at offset %x+%x\n", rtl->rx.offset,
433
 			DBG ( "RX packet at offset %x+%x\n", rtl->rx.offset,
434
 			      rx_len );
434
 			      rx_len );
435
 
435
 
436
-			rx_pkb = alloc_pkb ( rx_len );
437
-			if ( ! rx_pkb ) {
436
+			rx_iob = alloc_iob ( rx_len );
437
+			if ( ! rx_iob ) {
438
 				/* Leave packet for next call to poll() */
438
 				/* Leave packet for next call to poll() */
439
 				break;
439
 				break;
440
 			}
440
 			}
444
 			if ( wrapped_len < 0 )
444
 			if ( wrapped_len < 0 )
445
 				wrapped_len = 0;
445
 				wrapped_len = 0;
446
 
446
 
447
-			memcpy ( pkb_put ( rx_pkb, rx_len - wrapped_len ),
447
+			memcpy ( iob_put ( rx_iob, rx_len - wrapped_len ),
448
 				 rtl->rx.ring + rtl->rx.offset + 4,
448
 				 rtl->rx.ring + rtl->rx.offset + 4,
449
 				 rx_len - wrapped_len );
449
 				 rx_len - wrapped_len );
450
-			memcpy ( pkb_put ( rx_pkb, wrapped_len ),
450
+			memcpy ( iob_put ( rx_iob, wrapped_len ),
451
 				 rtl->rx.ring, wrapped_len );
451
 				 rtl->rx.ring, wrapped_len );
452
 
452
 
453
-			netdev_rx ( netdev, rx_pkb );
453
+			netdev_rx ( netdev, rx_iob );
454
 			rx_quota--;
454
 			rx_quota--;
455
 		} else {
455
 		} else {
456
 			DBG ( "RX bad packet (status %#04x len %d)\n",
456
 			DBG ( "RX bad packet (status %#04x len %d)\n",

+ 4
- 4
src/include/gpxe/ip.h View File

25
 #define IP_TOS		0
25
 #define IP_TOS		0
26
 #define IP_TTL		64
26
 #define IP_TTL		64
27
 
27
 
28
-#define IP_FRAG_PKB_SIZE	1500
28
+#define IP_FRAG_IOB_SIZE	1500
29
 #define IP_FRAG_TIMEOUT		50
29
 #define IP_FRAG_TIMEOUT		50
30
 
30
 
31
 /* IP4 pseudo header */
31
 /* IP4 pseudo header */
63
 	struct in_addr src;
63
 	struct in_addr src;
64
 	/* Destination network address */
64
 	/* Destination network address */
65
 	struct in_addr dest;
65
 	struct in_addr dest;
66
-	/* Reassembled packet buffer */
67
-	struct pk_buff *frag_pkb;
66
+	/* Reassembled I/O buffer */
67
+	struct io_buffer *frag_iob;
68
 	/* Reassembly timer */
68
 	/* Reassembly timer */
69
 	struct retry_timer frag_timer;
69
 	struct retry_timer frag_timer;
70
 	/* List of fragment reassembly buffers */
70
 	/* List of fragment reassembly buffers */
71
 	struct list_head list;
71
 	struct list_head list;
72
 };
72
 };
73
 
73
 
74
-struct pk_buff;
74
+struct io_buffer;
75
 struct net_device;
75
 struct net_device;
76
 struct net_protocol;
76
 struct net_protocol;
77
 struct tcpip_protocol;
77
 struct tcpip_protocol;

+ 5
- 5
src/include/gpxe/ip6.h View File

16
 #define IP6_HOP_LIMIT	255
16
 #define IP6_HOP_LIMIT	255
17
 
17
 
18
 /**
18
 /**
19
- * Packet buffer contents
20
- * This is duplicated in tcp.h and here. Ideally it should go into pkbuff.h
19
+ * I/O buffer contents
20
+ * This is duplicated in tcp.h and here. Ideally it should go into iobuf.h
21
  */
21
  */
22
 #define MAX_HDR_LEN	100
22
 #define MAX_HDR_LEN	100
23
-#define MAX_PKB_LEN	1500
24
-#define MIN_PKB_LEN	MAX_HDR_LEN + 100 /* To account for padding by LL */
23
+#define MAX_IOB_LEN	1500
24
+#define MIN_IOB_LEN	MAX_HDR_LEN + 100 /* To account for padding by LL */
25
 
25
 
26
 #define IP6_EQUAL( in6_addr1, in6_addr2 ) \
26
 #define IP6_EQUAL( in6_addr1, in6_addr2 ) \
27
         ( strncmp ( ( char* ) &( in6_addr1 ), ( char* ) &( in6_addr2 ),\
27
         ( strncmp ( ( char* ) &( in6_addr1 ), ( char* ) &( in6_addr2 ),\
61
 #define IP6_ICMP6		0x58
61
 #define IP6_ICMP6		0x58
62
 #define IP6_NO_HEADER		0x59
62
 #define IP6_NO_HEADER		0x59
63
 
63
 
64
-struct pk_buff;
64
+struct io_buffer;
65
 struct net_device;
65
 struct net_device;
66
 struct net_protocol;
66
 struct net_protocol;
67
 
67
 

+ 2
- 2
src/include/gpxe/ndp.h View File

6
 #include <gpxe/ip6.h>
6
 #include <gpxe/ip6.h>
7
 #include <gpxe/in.h>
7
 #include <gpxe/in.h>
8
 #include <gpxe/netdevice.h>
8
 #include <gpxe/netdevice.h>
9
-#include <gpxe/pkbuff.h>
9
+#include <gpxe/iobuf.h>
10
 #include <gpxe/tcpip.h>
10
 #include <gpxe/tcpip.h>
11
 
11
 
12
 #define NDP_STATE_INVALID 0
12
 #define NDP_STATE_INVALID 0
19
 static struct ndp_entry * ndp_find_entry ( struct in6_addr *in6 );
19
 static struct ndp_entry * ndp_find_entry ( struct in6_addr *in6 );
20
 int ndp_resolve ( struct net_device *netdev, struct in6_addr *src,
20
 int ndp_resolve ( struct net_device *netdev, struct in6_addr *src,
21
 		  struct in6_addr *dest, void *dest_ll_addr );
21
 		  struct in6_addr *dest, void *dest_ll_addr );
22
-int ndp_process_advert ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
22
+int ndp_process_advert ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src,
23
 			 struct sockaddr_tcpip *st_dest );
23
 			 struct sockaddr_tcpip *st_dest );

+ 21
- 21
src/include/gpxe/netdevice.h View File

12
 #include <gpxe/tables.h>
12
 #include <gpxe/tables.h>
13
 #include <gpxe/hotplug.h>
13
 #include <gpxe/hotplug.h>
14
 
14
 
15
-struct pk_buff;
15
+struct io_buffer;
16
 struct net_device;
16
 struct net_device;
17
 struct net_protocol;
17
 struct net_protocol;
18
 struct ll_protocol;
18
 struct ll_protocol;
37
 	/**
37
 	/**
38
 	 * Process received packet
38
 	 * Process received packet
39
 	 *
39
 	 *
40
-	 * @v pkb	Packet buffer
40
+	 * @v iobuf	I/O buffer
41
 	 * @v netdev	Network device
41
 	 * @v netdev	Network device
42
 	 * @v ll_source	Link-layer source address
42
 	 * @v ll_source	Link-layer source address
43
 	 *
43
 	 *
44
-	 * This method takes ownership of the packet buffer.
44
+	 * This method takes ownership of the I/O buffer.
45
 	 */
45
 	 */
46
-	int ( * rx ) ( struct pk_buff *pkb, struct net_device *netdev,
46
+	int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
47
 		       const void *ll_source );
47
 		       const void *ll_source );
48
 	/**
48
 	/**
49
 	 * Transcribe network-layer address
49
 	 * Transcribe network-layer address
77
 	/**
77
 	/**
78
 	 * Transmit network-layer packet via network device
78
 	 * Transmit network-layer packet via network device
79
 	 *
79
 	 *
80
-	 * @v pkb		Packet buffer
80
+	 * @v iobuf		I/O buffer
81
 	 * @v netdev		Network device
81
 	 * @v netdev		Network device
82
 	 * @v net_protocol	Network-layer protocol
82
 	 * @v net_protocol	Network-layer protocol
83
 	 * @v ll_dest		Link-layer destination address
83
 	 * @v ll_dest		Link-layer destination address
85
 	 *
85
 	 *
86
 	 * This method should prepend in the link-layer header
86
 	 * This method should prepend in the link-layer header
87
 	 * (e.g. the Ethernet DIX header) and transmit the packet.
87
 	 * (e.g. the Ethernet DIX header) and transmit the packet.
88
-	 * This method takes ownership of the packet buffer.
88
+	 * This method takes ownership of the I/O buffer.
89
 	 */
89
 	 */
90
-	int ( * tx ) ( struct pk_buff *pkb, struct net_device *netdev,
90
+	int ( * tx ) ( struct io_buffer *iobuf, struct net_device *netdev,
91
 		       struct net_protocol *net_protocol,
91
 		       struct net_protocol *net_protocol,
92
 		       const void *ll_dest );
92
 		       const void *ll_dest );
93
 	/**
93
 	/**
94
 	 * Handle received packet
94
 	 * Handle received packet
95
 	 *
95
 	 *
96
-	 * @v pkb	Packet buffer
96
+	 * @v iobuf	I/O buffer
97
 	 * @v netdev	Network device
97
 	 * @v netdev	Network device
98
 	 *
98
 	 *
99
 	 * This method should strip off the link-layer header
99
 	 * This method should strip off the link-layer header
101
 	 * net_rx().  This method takes ownership of the packet
101
 	 * net_rx().  This method takes ownership of the packet
102
 	 * buffer.
102
 	 * buffer.
103
 	 */
103
 	 */
104
-	int ( * rx ) ( struct pk_buff *pkb, struct net_device *netdev );
104
+	int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev );
105
 	/**
105
 	/**
106
 	 * Transcribe link-layer address
106
 	 * Transcribe link-layer address
107
 	 *
107
 	 *
151
 	 * @v netdev	Network device
151
 	 * @v netdev	Network device
152
 	 * @ret rc	Return status code
152
 	 * @ret rc	Return status code
153
 	 *
153
 	 *
154
-	 * This method should allocate RX packet buffers and enable
154
+	 * This method should allocate RX I/O buffers and enable
155
 	 * the hardware to start transmitting and receiving packets.
155
 	 * the hardware to start transmitting and receiving packets.
156
 	 */
156
 	 */
157
 	int ( * open ) ( struct net_device *netdev );
157
 	int ( * open ) ( struct net_device *netdev );
166
 	/** Transmit packet
166
 	/** Transmit packet
167
 	 *
167
 	 *
168
 	 * @v netdev	Network device
168
 	 * @v netdev	Network device
169
-	 * @v pkb	Packet buffer
169
+	 * @v iobuf	I/O buffer
170
 	 * @ret rc	Return status code
170
 	 * @ret rc	Return status code
171
 	 *
171
 	 *
172
 	 * This method should cause the hardware to initiate
172
 	 * This method should cause the hardware to initiate
173
-	 * transmission of the packet buffer.
173
+	 * transmission of the I/O buffer.
174
 	 *
174
 	 *
175
-	 * If this method returns success, the packet buffer remains
175
+	 * If this method returns success, the I/O buffer remains
176
 	 * owned by the net device's TX queue, and the net device must
176
 	 * owned by the net device's TX queue, and the net device must
177
 	 * eventually call netdev_tx_complete() to free the buffer.
177
 	 * eventually call netdev_tx_complete() to free the buffer.
178
-	 * If this method returns failure, the packet buffer is
178
+	 * If this method returns failure, the I/O buffer is
179
 	 * immediately released.
179
 	 * immediately released.
180
 	 *
180
 	 *
181
 	 * This method is guaranteed to be called only when the device
181
 	 * This method is guaranteed to be called only when the device
182
 	 * is open.
182
 	 * is open.
183
 	 */
183
 	 */
184
-	int ( * transmit ) ( struct net_device *netdev, struct pk_buff *pkb );
184
+	int ( * transmit ) ( struct net_device *netdev, struct io_buffer *iobuf );
185
 	/** Poll for received packet
185
 	/** Poll for received packet
186
 	 *
186
 	 *
187
 	 * @v netdev	Network device
187
 	 * @v netdev	Network device
251
 	return ( ! list_empty ( &net_devices ) );
251
 	return ( ! list_empty ( &net_devices ) );
252
 }
252
 }
253
 
253
 
254
-extern int netdev_tx ( struct net_device *netdev, struct pk_buff *pkb );
255
-void netdev_tx_complete ( struct net_device *netdev, struct pk_buff *pkb );
254
+extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
255
+void netdev_tx_complete ( struct net_device *netdev, struct io_buffer *iobuf );
256
 void netdev_tx_complete_next ( struct net_device *netdev );
256
 void netdev_tx_complete_next ( struct net_device *netdev );
257
-extern void netdev_rx ( struct net_device *netdev, struct pk_buff *pkb );
257
+extern void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf );
258
 extern int netdev_poll ( struct net_device *netdev, unsigned int rx_quota );
258
 extern int netdev_poll ( struct net_device *netdev, unsigned int rx_quota );
259
-extern struct pk_buff * netdev_rx_dequeue ( struct net_device *netdev );
259
+extern struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev );
260
 extern struct net_device * alloc_netdev ( size_t priv_size );
260
 extern struct net_device * alloc_netdev ( size_t priv_size );
261
 extern int register_netdev ( struct net_device *netdev );
261
 extern int register_netdev ( struct net_device *netdev );
262
 extern int netdev_open ( struct net_device *netdev );
262
 extern int netdev_open ( struct net_device *netdev );
266
 struct net_device * find_netdev ( const char *name );
266
 struct net_device * find_netdev ( const char *name );
267
 struct net_device * find_pci_netdev ( unsigned int busdevfn );
267
 struct net_device * find_pci_netdev ( unsigned int busdevfn );
268
 
268
 
269
-extern int net_tx ( struct pk_buff *pkb, struct net_device *netdev,
269
+extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
270
 		    struct net_protocol *net_protocol, const void *ll_dest );
270
 		    struct net_protocol *net_protocol, const void *ll_dest );
271
-extern int net_rx ( struct pk_buff *pkb, struct net_device *netdev,
271
+extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
272
 		    uint16_t net_proto, const void *ll_source );
272
 		    uint16_t net_proto, const void *ll_source );
273
 
273
 
274
 #endif /* _GPXE_NETDEVICE_H */
274
 #endif /* _GPXE_NETDEVICE_H */

+ 0
- 163
src/include/gpxe/pkbuff.h View File

1
-#ifndef _GPXE_PKBUFF_H
2
-#define _GPXE_PKBUFF_H
3
-
4
-/** @file
5
- *
6
- * Packet buffers
7
- *
8
- * Packet buffers are used to contain network packets.  Methods are
9
- * provided for appending, prepending, etc. data.
10
- *
11
- */
12
-
13
-#include <stdint.h>
14
-#include <assert.h>
15
-#include <gpxe/list.h>
16
-
17
-/**
18
- * Packet buffer alignment
19
- *
20
- * Packet buffers allocated via alloc_pkb() are guaranteed to be
21
- * physically aligned to this boundary.  Some cards cannot DMA across
22
- * a 4kB boundary.  With a standard Ethernet MTU, aligning to a 2kB
23
- * boundary is sufficient to guarantee no 4kB boundary crossings.  For
24
- * a jumbo Ethernet MTU, a packet may be larger than 4kB anyway.
25
- */
26
-#define PKBUFF_ALIGN 2048
27
-
28
-/**
29
- * Minimum packet buffer length
30
- *
31
- * alloc_pkb() will round up the allocated length to this size if
32
- * necessary.  This is used on behalf of hardware that is not capable
33
- * of auto-padding.
34
- */
35
-#define PKB_ZLEN 64
36
-
37
-/** A packet buffer
38
- *
39
- * This structure is used to represent a network packet within gPXE.
40
- */
41
-struct pk_buff {
42
-	/** List of which this buffer is a member */
43
-	struct list_head list;
44
-
45
-	/** Start of the buffer */
46
-	void *head;
47
-	/** Start of data */
48
-	void *data;
49
-	/** End of data */
50
-	void *tail;
51
-	/** End of the buffer */
52
-        void *end;
53
-};
54
-
55
-/**
56
- * Reserve space at start of packet buffer
57
- *
58
- * @v pkb	Packet buffer
59
- * @v len	Length to reserve
60
- * @ret data	Pointer to new start of buffer
61
- */
62
-static inline void * pkb_reserve ( struct pk_buff *pkb, size_t len ) {
63
-	pkb->data += len;
64
-	pkb->tail += len;
65
-	assert ( pkb->tail <= pkb->end );
66
-	return pkb->data;
67
-}
68
-
69
-/**
70
- * Add data to start of packet buffer
71
- *
72
- * @v pkb	Packet buffer
73
- * @v len	Length to add
74
- * @ret data	Pointer to new start of buffer
75
- */
76
-static inline void * pkb_push ( struct pk_buff *pkb, size_t len ) {
77
-	pkb->data -= len;
78
-	assert ( pkb->data >= pkb->head );
79
-	return pkb->data;
80
-}
81
-
82
-/**
83
- * Remove data from start of packet buffer
84
- *
85
- * @v pkb	Packet buffer
86
- * @v len	Length to remove
87
- * @ret data	Pointer to new start of buffer
88
- */
89
-static inline void * pkb_pull ( struct pk_buff *pkb, size_t len ) {
90
-	pkb->data += len;
91
-	assert ( pkb->data <= pkb->tail );
92
-	return pkb->data;
93
-}
94
-
95
-/**
96
- * Add data to end of packet buffer
97
- *
98
- * @v pkb	Packet buffer
99
- * @v len	Length to add
100
- * @ret data	Pointer to newly added space
101
- */
102
-static inline void * pkb_put ( struct pk_buff *pkb, size_t len ) {
103
-	void *old_tail = pkb->tail;
104
-	pkb->tail += len;
105
-	assert ( pkb->tail <= pkb->end );
106
-	return old_tail;
107
-}
108
-
109
-/**
110
- * Remove data from end of packet buffer
111
- *
112
- * @v pkb	Packet buffer
113
- * @v len	Length to remove
114
- */
115
-static inline void pkb_unput ( struct pk_buff *pkb, size_t len ) {
116
-	pkb->tail -= len;
117
-	assert ( pkb->tail >= pkb->data );
118
-}
119
-
120
-/**
121
- * Empty a packet buffer
122
- *
123
- * @v pkb	Packet buffer
124
- */
125
-static inline void pkb_empty ( struct pk_buff *pkb ) {
126
-	pkb->tail = pkb->data;
127
-}
128
-
129
-/**
130
- * Calculate length of data in a packet buffer
131
- *
132
- * @v pkb	Packet buffer
133
- * @ret len	Length of data in buffer
134
- */
135
-static inline size_t pkb_len ( struct pk_buff *pkb ) {
136
-	return ( pkb->tail - pkb->data );
137
-}
138
-
139
-/**
140
- * Calculate available space at start of a packet buffer
141
- *
142
- * @v pkb	Packet buffer
143
- * @ret len	Length of data available at start of buffer
144
- */
145
-static inline size_t pkb_headroom ( struct pk_buff *pkb ) {
146
-	return ( pkb->data - pkb->head );
147
-}
148
-
149
-/**
150
- * Calculate available space at end of a packet buffer
151
- *
152
- * @v pkb	Packet buffer
153
- * @ret len	Length of data available at end of buffer
154
- */
155
-static inline size_t pkb_tailroom ( struct pk_buff *pkb ) {
156
-	return ( pkb->end - pkb->tail );
157
-}
158
-
159
-extern struct pk_buff * alloc_pkb ( size_t len );
160
-extern void free_pkb ( struct pk_buff *pkb );
161
-extern void pkb_pad ( struct pk_buff *pkb, size_t min_len );
162
-
163
-#endif /* _GPXE_PKBUFF_H */

+ 3
- 3
src/include/gpxe/tcp.h View File

206
 /** Smallest port number on which a TCP connection can listen */
206
 /** Smallest port number on which a TCP connection can listen */
207
 #define TCP_MIN_PORT 1
207
 #define TCP_MIN_PORT 1
208
 
208
 
209
-/* Some PKB constants */
209
+/* Some IOB constants */
210
 #define MAX_HDR_LEN	100
210
 #define MAX_HDR_LEN	100
211
-#define MAX_PKB_LEN	1500
212
-#define MIN_PKB_LEN	MAX_HDR_LEN + 100 /* To account for padding by LL */
211
+#define MAX_IOB_LEN	1500
212
+#define MIN_IOB_LEN	MAX_HDR_LEN + 100 /* To account for padding by LL */
213
 
213
 
214
 /**
214
 /**
215
  * Maxmimum advertised TCP window size
215
  * Maxmimum advertised TCP window size

+ 9
- 9
src/include/gpxe/tcpip.h View File

12
 #include <gpxe/in.h>
12
 #include <gpxe/in.h>
13
 #include <gpxe/tables.h>
13
 #include <gpxe/tables.h>
14
 
14
 
15
-struct pk_buff;
15
+struct io_buffer;
16
 struct net_device;
16
 struct net_device;
17
 
17
 
18
 /** Empty checksum value
18
 /** Empty checksum value
51
        	/**
51
        	/**
52
          * Process received packet
52
          * Process received packet
53
          *
53
          *
54
-         * @v pkb		Packet buffer
54
+         * @v iobuf		I/O buffer
55
 	 * @v st_src		Partially-filled source address
55
 	 * @v st_src		Partially-filled source address
56
 	 * @v st_dest		Partially-filled destination address
56
 	 * @v st_dest		Partially-filled destination address
57
 	 * @v pshdr_csum	Pseudo-header checksum
57
 	 * @v pshdr_csum	Pseudo-header checksum
58
 	 * @ret rc		Return status code
58
 	 * @ret rc		Return status code
59
          *
59
          *
60
-         * This method takes ownership of the packet buffer.
60
+         * This method takes ownership of the I/O buffer.
61
          */
61
          */
62
-        int ( * rx ) ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
62
+        int ( * rx ) ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src,
63
 		       struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
63
 		       struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
64
         /** 
64
         /** 
65
 	 * Transport-layer protocol number
65
 	 * Transport-layer protocol number
80
 	/**
80
 	/**
81
 	 * Transmit packet
81
 	 * Transmit packet
82
 	 *
82
 	 *
83
-	 * @v pkb		Packet buffer
83
+	 * @v iobuf		I/O buffer
84
 	 * @v tcpip_protocol	Transport-layer protocol
84
 	 * @v tcpip_protocol	Transport-layer protocol
85
 	 * @v st_dest		Destination address
85
 	 * @v st_dest		Destination address
86
 	 * @v netdev		Network device (or NULL to route automatically)
86
 	 * @v netdev		Network device (or NULL to route automatically)
87
 	 * @v trans_csum	Transport-layer checksum to complete, or NULL
87
 	 * @v trans_csum	Transport-layer checksum to complete, or NULL
88
 	 * @ret rc		Return status code
88
 	 * @ret rc		Return status code
89
 	 *
89
 	 *
90
-	 * This function takes ownership of the packet buffer.
90
+	 * This function takes ownership of the I/O buffer.
91
 	 */
91
 	 */
92
-	int ( * tx ) ( struct pk_buff *pkb,
92
+	int ( * tx ) ( struct io_buffer *iobuf,
93
 		       struct tcpip_protocol *tcpip_protocol,
93
 		       struct tcpip_protocol *tcpip_protocol,
94
 		       struct sockaddr_tcpip *st_dest,
94
 		       struct sockaddr_tcpip *st_dest,
95
 		       struct net_device *netdev,
95
 		       struct net_device *netdev,
104
 #define	__tcpip_net_protocol \
104
 #define	__tcpip_net_protocol \
105
 	__table ( struct tcpip_net_protocol, tcpip_net_protocols, 01 )
105
 	__table ( struct tcpip_net_protocol, tcpip_net_protocols, 01 )
106
 
106
 
107
-extern int tcpip_rx ( struct pk_buff *pkb, uint8_t tcpip_proto,
107
+extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
108
 		      struct sockaddr_tcpip *st_src,
108
 		      struct sockaddr_tcpip *st_src,
109
 		      struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
109
 		      struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
110
-extern int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip, 
110
+extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip, 
111
 		      struct sockaddr_tcpip *st_dest,
111
 		      struct sockaddr_tcpip *st_dest,
112
 		      struct net_device *netdev,
112
 		      struct net_device *netdev,
113
 		      uint16_t *trans_csum );
113
 		      uint16_t *trans_csum );

+ 4
- 4
src/include/gpxe/udp.h View File

10
  */
10
  */
11
 
11
 
12
 #include <stddef.h>
12
 #include <stddef.h>
13
-#include <gpxe/pkbuff.h>
13
+#include <gpxe/iobuf.h>
14
 #include <gpxe/tcpip.h>
14
 #include <gpxe/tcpip.h>
15
 #include <gpxe/if_ether.h>
15
 #include <gpxe/if_ether.h>
16
 
16
 
21
  */
21
  */
22
 
22
 
23
 #define UDP_MAX_HLEN	72
23
 #define UDP_MAX_HLEN	72
24
-#define UDP_MAX_TXPKB	ETH_MAX_MTU
25
-#define UDP_MIN_TXPKB	ETH_ZLEN
24
+#define UDP_MAX_TXIOB	ETH_MAX_MTU
25
+#define UDP_MIN_TXIOB	ETH_ZLEN
26
 
26
 
27
 typedef uint16_t port_t;
27
 typedef uint16_t port_t;
28
 
28
 
86
 	/** Local port on which the connection receives packets */
86
 	/** Local port on which the connection receives packets */
87
 	port_t local_port;
87
 	port_t local_port;
88
 	/** Transmit buffer */
88
 	/** Transmit buffer */
89
-	struct pk_buff *tx_pkb;
89
+	struct io_buffer *tx_iob;
90
 	/** List of registered connections */
90
 	/** List of registered connections */
91
 	struct list_head list;
91
 	struct list_head list;
92
 	/** Operations table for this connection */
92
 	/** Operations table for this connection */

+ 15
- 15
src/net/aoe.c View File

25
 #include <gpxe/list.h>
25
 #include <gpxe/list.h>
26
 #include <gpxe/if_ether.h>
26
 #include <gpxe/if_ether.h>
27
 #include <gpxe/ethernet.h>
27
 #include <gpxe/ethernet.h>
28
-#include <gpxe/pkbuff.h>
28
+#include <gpxe/iobuf.h>
29
 #include <gpxe/uaccess.h>
29
 #include <gpxe/uaccess.h>
30
 #include <gpxe/ata.h>
30
 #include <gpxe/ata.h>
31
 #include <gpxe/netdevice.h>
31
 #include <gpxe/netdevice.h>
70
  */
70
  */
71
 static int aoe_send_command ( struct aoe_session *aoe ) {
71
 static int aoe_send_command ( struct aoe_session *aoe ) {
72
 	struct ata_command *command = aoe->command;
72
 	struct ata_command *command = aoe->command;
73
-	struct pk_buff *pkb;
73
+	struct io_buffer *iobuf;
74
 	struct aoehdr *aoehdr;
74
 	struct aoehdr *aoehdr;
75
 	struct aoecmd *aoecmd;
75
 	struct aoecmd *aoecmd;
76
 	unsigned int count;
76
 	unsigned int count;
88
 		count = AOE_MAX_COUNT;
88
 		count = AOE_MAX_COUNT;
89
 	data_out_len = ( command->data_out ? ( count * ATA_SECTOR_SIZE ) : 0 );
89
 	data_out_len = ( command->data_out ? ( count * ATA_SECTOR_SIZE ) : 0 );
90
 
90
 
91
-	/* Create outgoing packet buffer */
92
-	pkb = alloc_pkb ( ETH_HLEN + sizeof ( *aoehdr ) + sizeof ( *aoecmd ) +
91
+	/* Create outgoing I/O buffer */
92
+	iobuf = alloc_iob ( ETH_HLEN + sizeof ( *aoehdr ) + sizeof ( *aoecmd ) +
93
 			  data_out_len );
93
 			  data_out_len );
94
-	if ( ! pkb )
94
+	if ( ! iobuf )
95
 		return -ENOMEM;
95
 		return -ENOMEM;
96
-	pkb_reserve ( pkb, ETH_HLEN );
97
-	aoehdr = pkb_put ( pkb, sizeof ( *aoehdr ) );
98
-	aoecmd = pkb_put ( pkb, sizeof ( *aoecmd ) );
96
+	iob_reserve ( iobuf, ETH_HLEN );
97
+	aoehdr = iob_put ( iobuf, sizeof ( *aoehdr ) );
98
+	aoecmd = iob_put ( iobuf, sizeof ( *aoecmd ) );
99
 	memset ( aoehdr, 0, ( sizeof ( *aoehdr ) + sizeof ( *aoecmd ) ) );
99
 	memset ( aoehdr, 0, ( sizeof ( *aoehdr ) + sizeof ( *aoecmd ) ) );
100
 
100
 
101
 	/* Fill AoE header */
101
 	/* Fill AoE header */
117
 		aoecmd->lba.bytes[3] |= ( command->cb.device & ATA_DEV_MASK );
117
 		aoecmd->lba.bytes[3] |= ( command->cb.device & ATA_DEV_MASK );
118
 
118
 
119
 	/* Fill data payload */
119
 	/* Fill data payload */
120
-	copy_from_user ( pkb_put ( pkb, data_out_len ), command->data_out,
120
+	copy_from_user ( iob_put ( iobuf, data_out_len ), command->data_out,
121
 			 aoe->command_offset, data_out_len );
121
 			 aoe->command_offset, data_out_len );
122
 
122
 
123
 	/* Send packet */
123
 	/* Send packet */
124
 	start_timer ( &aoe->timer );
124
 	start_timer ( &aoe->timer );
125
-	return net_tx ( pkb, aoe->netdev, &aoe_protocol, aoe->target );
125
+	return net_tx ( iobuf, aoe->netdev, &aoe_protocol, aoe->target );
126
 }
126
 }
127
 
127
 
128
 /**
128
 /**
213
 /**
213
 /**
214
  * Process incoming AoE packets
214
  * Process incoming AoE packets
215
  *
215
  *
216
- * @v pkb		Packet buffer
216
+ * @v iobuf		I/O buffer
217
  * @v netdev		Network device
217
  * @v netdev		Network device
218
  * @v ll_source		Link-layer source address
218
  * @v ll_source		Link-layer source address
219
  * @ret rc		Return status code
219
  * @ret rc		Return status code
220
  *
220
  *
221
  */
221
  */
222
-static int aoe_rx ( struct pk_buff *pkb, struct net_device *netdev __unused,
222
+static int aoe_rx ( struct io_buffer *iobuf, struct net_device *netdev __unused,
223
 		    const void *ll_source ) {
223
 		    const void *ll_source ) {
224
-	struct aoehdr *aoehdr = pkb->data;
225
-	unsigned int len = pkb_len ( pkb );
224
+	struct aoehdr *aoehdr = iobuf->data;
225
+	unsigned int len = iob_len ( iobuf );
226
 	struct aoe_session *aoe;
226
 	struct aoe_session *aoe;
227
 	int rc = 0;
227
 	int rc = 0;
228
 
228
 
254
 	}
254
 	}
255
 
255
 
256
  done:
256
  done:
257
-	free_pkb ( pkb );
257
+	free_iob ( iobuf );
258
 	return rc;
258
 	return rc;
259
 }
259
 }
260
 
260
 

+ 17
- 17
src/net/arp.c View File

22
 #include <errno.h>
22
 #include <errno.h>
23
 #include <gpxe/if_ether.h>
23
 #include <gpxe/if_ether.h>
24
 #include <gpxe/if_arp.h>
24
 #include <gpxe/if_arp.h>
25
-#include <gpxe/pkbuff.h>
25
+#include <gpxe/iobuf.h>
26
 #include <gpxe/netdevice.h>
26
 #include <gpxe/netdevice.h>
27
 #include <gpxe/arp.h>
27
 #include <gpxe/arp.h>
28
 
28
 
119
 		  void *dest_ll_addr ) {
119
 		  void *dest_ll_addr ) {
120
 	struct ll_protocol *ll_protocol = netdev->ll_protocol;
120
 	struct ll_protocol *ll_protocol = netdev->ll_protocol;
121
 	const struct arp_entry *arp;
121
 	const struct arp_entry *arp;
122
-	struct pk_buff *pkb;
122
+	struct io_buffer *iobuf;
123
 	struct arphdr *arphdr;
123
 	struct arphdr *arphdr;
124
 	int rc;
124
 	int rc;
125
 
125
 
136
 	      net_protocol->ntoa ( dest_net_addr ) );
136
 	      net_protocol->ntoa ( dest_net_addr ) );
137
 
137
 
138
 	/* Allocate ARP packet */
138
 	/* Allocate ARP packet */
139
-	pkb = alloc_pkb ( MAX_LL_HEADER_LEN + sizeof ( *arphdr ) +
139
+	iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( *arphdr ) +
140
 			  2 * ( MAX_LL_ADDR_LEN + MAX_NET_ADDR_LEN ) );
140
 			  2 * ( MAX_LL_ADDR_LEN + MAX_NET_ADDR_LEN ) );
141
-	if ( ! pkb )
141
+	if ( ! iobuf )
142
 		return -ENOMEM;
142
 		return -ENOMEM;
143
-	pkb_reserve ( pkb, MAX_LL_HEADER_LEN );
143
+	iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
144
 
144
 
145
 	/* Build up ARP request */
145
 	/* Build up ARP request */
146
-	arphdr = pkb_put ( pkb, sizeof ( *arphdr ) );
146
+	arphdr = iob_put ( iobuf, sizeof ( *arphdr ) );
147
 	arphdr->ar_hrd = ll_protocol->ll_proto;
147
 	arphdr->ar_hrd = ll_protocol->ll_proto;
148
 	arphdr->ar_hln = ll_protocol->ll_addr_len;
148
 	arphdr->ar_hln = ll_protocol->ll_addr_len;
149
 	arphdr->ar_pro = net_protocol->net_proto;
149
 	arphdr->ar_pro = net_protocol->net_proto;
150
 	arphdr->ar_pln = net_protocol->net_addr_len;
150
 	arphdr->ar_pln = net_protocol->net_addr_len;
151
 	arphdr->ar_op = htons ( ARPOP_REQUEST );
151
 	arphdr->ar_op = htons ( ARPOP_REQUEST );
152
-	memcpy ( pkb_put ( pkb, ll_protocol->ll_addr_len ),
152
+	memcpy ( iob_put ( iobuf, ll_protocol->ll_addr_len ),
153
 		 netdev->ll_addr, ll_protocol->ll_addr_len );
153
 		 netdev->ll_addr, ll_protocol->ll_addr_len );
154
-	memcpy ( pkb_put ( pkb, net_protocol->net_addr_len ),
154
+	memcpy ( iob_put ( iobuf, net_protocol->net_addr_len ),
155
 		 source_net_addr, net_protocol->net_addr_len );
155
 		 source_net_addr, net_protocol->net_addr_len );
156
-	memset ( pkb_put ( pkb, ll_protocol->ll_addr_len ),
156
+	memset ( iob_put ( iobuf, ll_protocol->ll_addr_len ),
157
 		 0, ll_protocol->ll_addr_len );
157
 		 0, ll_protocol->ll_addr_len );
158
-	memcpy ( pkb_put ( pkb, net_protocol->net_addr_len ),
158
+	memcpy ( iob_put ( iobuf, net_protocol->net_addr_len ),
159
 		 dest_net_addr, net_protocol->net_addr_len );
159
 		 dest_net_addr, net_protocol->net_addr_len );
160
 
160
 
161
 	/* Transmit ARP request */
161
 	/* Transmit ARP request */
162
-	if ( ( rc = net_tx ( pkb, netdev, &arp_protocol, 
162
+	if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol, 
163
 			     ll_protocol->ll_broadcast ) ) != 0 )
163
 			     ll_protocol->ll_broadcast ) ) != 0 )
164
 		return rc;
164
 		return rc;
165
 
165
 
188
 /**
188
 /**
189
  * Process incoming ARP packets
189
  * Process incoming ARP packets
190
  *
190
  *
191
- * @v pkb		Packet buffer
191
+ * @v iobuf		I/O buffer
192
  * @v netdev		Network device
192
  * @v netdev		Network device
193
  * @v ll_source		Link-layer source address
193
  * @v ll_source		Link-layer source address
194
  * @ret rc		Return status code
194
  * @ret rc		Return status code
199
  * avoiding the need for extraneous ARP requests; read the RFC for
199
  * avoiding the need for extraneous ARP requests; read the RFC for
200
  * details.
200
  * details.
201
  */
201
  */
202
-static int arp_rx ( struct pk_buff *pkb, struct net_device *netdev,
202
+static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,
203
 		    const void *ll_source __unused ) {
203
 		    const void *ll_source __unused ) {
204
-	struct arphdr *arphdr = pkb->data;
204
+	struct arphdr *arphdr = iobuf->data;
205
 	struct arp_net_protocol *arp_net_protocol;
205
 	struct arp_net_protocol *arp_net_protocol;
206
 	struct net_protocol *net_protocol;
206
 	struct net_protocol *net_protocol;
207
 	struct ll_protocol *ll_protocol;
207
 	struct ll_protocol *ll_protocol;
265
 	memcpy ( arp_sender_ha ( arphdr ), netdev->ll_addr, arphdr->ar_hln );
265
 	memcpy ( arp_sender_ha ( arphdr ), netdev->ll_addr, arphdr->ar_hln );
266
 
266
 
267
 	/* Send reply */
267
 	/* Send reply */
268
-	net_tx ( pkb, netdev, &arp_protocol, arp_target_ha (arphdr ) );
269
-	pkb = NULL;
268
+	net_tx ( iobuf, netdev, &arp_protocol, arp_target_ha (arphdr ) );
269
+	iobuf = NULL;
270
 
270
 
271
  done:
271
  done:
272
-	free_pkb ( pkb );
272
+	free_iob ( iobuf );
273
 	return 0;
273
 	return 0;
274
 }
274
 }
275
 
275
 

+ 13
- 13
src/net/ethernet.c View File

25
 #include <gpxe/if_arp.h>
25
 #include <gpxe/if_arp.h>
26
 #include <gpxe/if_ether.h>
26
 #include <gpxe/if_ether.h>
27
 #include <gpxe/netdevice.h>
27
 #include <gpxe/netdevice.h>
28
-#include <gpxe/pkbuff.h>
28
+#include <gpxe/iobuf.h>
29
 #include <gpxe/ethernet.h>
29
 #include <gpxe/ethernet.h>
30
 
30
 
31
 /** @file
31
 /** @file
40
 /**
40
 /**
41
  * Transmit Ethernet packet
41
  * Transmit Ethernet packet
42
  *
42
  *
43
- * @v pkb		Packet buffer
43
+ * @v iobuf		I/O buffer
44
  * @v netdev		Network device
44
  * @v netdev		Network device
45
  * @v net_protocol	Network-layer protocol
45
  * @v net_protocol	Network-layer protocol
46
  * @v ll_dest		Link-layer destination address
46
  * @v ll_dest		Link-layer destination address
47
  *
47
  *
48
  * Prepends the Ethernet link-layer header and transmits the packet.
48
  * Prepends the Ethernet link-layer header and transmits the packet.
49
  */
49
  */
50
-static int eth_tx ( struct pk_buff *pkb, struct net_device *netdev,
50
+static int eth_tx ( struct io_buffer *iobuf, struct net_device *netdev,
51
 		    struct net_protocol *net_protocol, const void *ll_dest ) {
51
 		    struct net_protocol *net_protocol, const void *ll_dest ) {
52
-	struct ethhdr *ethhdr = pkb_push ( pkb, sizeof ( *ethhdr ) );
52
+	struct ethhdr *ethhdr = iob_push ( iobuf, sizeof ( *ethhdr ) );
53
 
53
 
54
 	/* Build Ethernet header */
54
 	/* Build Ethernet header */
55
 	memcpy ( ethhdr->h_dest, ll_dest, ETH_ALEN );
55
 	memcpy ( ethhdr->h_dest, ll_dest, ETH_ALEN );
57
 	ethhdr->h_protocol = net_protocol->net_proto;
57
 	ethhdr->h_protocol = net_protocol->net_proto;
58
 
58
 
59
 	/* Hand off to network device */
59
 	/* Hand off to network device */
60
-	return netdev_tx ( netdev, pkb );
60
+	return netdev_tx ( netdev, iobuf );
61
 }
61
 }
62
 
62
 
63
 /**
63
 /**
64
  * Process received Ethernet packet
64
  * Process received Ethernet packet
65
  *
65
  *
66
- * @v pkb	Packet buffer
66
+ * @v iobuf	I/O buffer
67
  * @v netdev	Network device
67
  * @v netdev	Network device
68
  *
68
  *
69
  * Strips off the Ethernet link-layer header and passes up to the
69
  * Strips off the Ethernet link-layer header and passes up to the
70
  * network-layer protocol.
70
  * network-layer protocol.
71
  */
71
  */
72
-static int eth_rx ( struct pk_buff *pkb, struct net_device *netdev ) {
73
-	struct ethhdr *ethhdr = pkb->data;
72
+static int eth_rx ( struct io_buffer *iobuf, struct net_device *netdev ) {
73
+	struct ethhdr *ethhdr = iobuf->data;
74
 
74
 
75
 	/* Sanity check */
75
 	/* Sanity check */
76
-	if ( pkb_len ( pkb ) < sizeof ( *ethhdr ) ) {
76
+	if ( iob_len ( iobuf ) < sizeof ( *ethhdr ) ) {
77
 		DBG ( "Ethernet packet too short (%d bytes)\n",
77
 		DBG ( "Ethernet packet too short (%d bytes)\n",
78
-		      pkb_len ( pkb ) );
79
-		free_pkb ( pkb );
78
+		      iob_len ( iobuf ) );
79
+		free_iob ( iobuf );
80
 		return -EINVAL;
80
 		return -EINVAL;
81
 	}
81
 	}
82
 
82
 
83
 	/* Strip off Ethernet header */
83
 	/* Strip off Ethernet header */
84
-	pkb_pull ( pkb, sizeof ( *ethhdr ) );
84
+	iob_pull ( iobuf, sizeof ( *ethhdr ) );
85
 
85
 
86
 	/* Hand off to network-layer protocol */
86
 	/* Hand off to network-layer protocol */
87
-	return net_rx ( pkb, netdev, ethhdr->h_protocol, ethhdr->h_source );
87
+	return net_rx ( iobuf, netdev, ethhdr->h_protocol, ethhdr->h_source );
88
 }
88
 }
89
 
89
 
90
 /**
90
 /**

+ 18
- 18
src/net/icmpv6.c View File

5
 #include <gpxe/in.h>
5
 #include <gpxe/in.h>
6
 #include <gpxe/ip6.h>
6
 #include <gpxe/ip6.h>
7
 #include <gpxe/if_ether.h>
7
 #include <gpxe/if_ether.h>
8
-#include <gpxe/pkbuff.h>
8
+#include <gpxe/iobuf.h>
9
 #include <gpxe/ndp.h>
9
 #include <gpxe/ndp.h>
10
 #include <gpxe/icmp6.h>
10
 #include <gpxe/icmp6.h>
11
 #include <gpxe/tcpip.h>
11
 #include <gpxe/tcpip.h>
31
 	} st_dest;
31
 	} st_dest;
32
 	struct ll_protocol *ll_protocol = netdev->ll_protocol;
32
 	struct ll_protocol *ll_protocol = netdev->ll_protocol;
33
 	struct neighbour_solicit *nsolicit;
33
 	struct neighbour_solicit *nsolicit;
34
-	struct pk_buff *pkb = alloc_pkb ( sizeof ( *nsolicit ) + MIN_PKB_LEN );
35
-	pkb_reserve ( pkb, MAX_HDR_LEN );
36
-	nsolicit = pkb_put ( pkb, sizeof ( *nsolicit ) );
34
+	struct io_buffer *iobuf = alloc_iob ( sizeof ( *nsolicit ) + MIN_IOB_LEN );
35
+	iob_reserve ( iobuf, MAX_HDR_LEN );
36
+	nsolicit = iob_put ( iobuf, sizeof ( *nsolicit ) );
37
 
37
 
38
 	/* Fill up the headers */
38
 	/* Fill up the headers */
39
 	memset ( nsolicit, 0, sizeof ( *nsolicit ) );
39
 	memset ( nsolicit, 0, sizeof ( *nsolicit ) );
60
 	st_dest.sin6.sin6_addr.in6_u.u6_addr8[13] = 0xff;
60
 	st_dest.sin6.sin6_addr.in6_u.u6_addr8[13] = 0xff;
61
 	
61
 	
62
 	/* Send packet over IP6 */
62
 	/* Send packet over IP6 */
63
-	return tcpip_tx ( pkb, &icmp6_protocol, &st_dest.st,
63
+	return tcpip_tx ( iobuf, &icmp6_protocol, &st_dest.st,
64
 			  NULL, &nsolicit->csum );
64
 			  NULL, &nsolicit->csum );
65
 }
65
 }
66
 
66
 
67
 /**
67
 /**
68
  * Process ICMP6 headers
68
  * Process ICMP6 headers
69
  *
69
  *
70
- * @v pkb	Packet buffer
70
+ * @v iobuf	I/O buffer
71
  * @v st_src	Source address
71
  * @v st_src	Source address
72
  * @v st_dest	Destination address
72
  * @v st_dest	Destination address
73
  */
73
  */
74
-static int icmp6_rx ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
74
+static int icmp6_rx ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src,
75
 		      struct sockaddr_tcpip *st_dest ) {
75
 		      struct sockaddr_tcpip *st_dest ) {
76
-	struct icmp6_header *icmp6hdr = pkb->data;
76
+	struct icmp6_header *icmp6hdr = iobuf->data;
77
 
77
 
78
 	/* Sanity check */
78
 	/* Sanity check */
79
-	if ( pkb_len ( pkb ) < sizeof ( *icmp6hdr ) ) {
80
-		DBG ( "Packet too short (%d bytes)\n", pkb_len ( pkb ) );
81
-		free_pkb ( pkb );
79
+	if ( iob_len ( iobuf ) < sizeof ( *icmp6hdr ) ) {
80
+		DBG ( "Packet too short (%d bytes)\n", iob_len ( iobuf ) );
81
+		free_iob ( iobuf );
82
 		return -EINVAL;
82
 		return -EINVAL;
83
 	}
83
 	}
84
 
84
 
87
 	/* Process the ICMP header */
87
 	/* Process the ICMP header */
88
 	switch ( icmp6hdr->type ) {
88
 	switch ( icmp6hdr->type ) {
89
 	case ICMP6_NADVERT:
89
 	case ICMP6_NADVERT:
90
-		return ndp_process_advert ( pkb, st_src, st_dest );
90
+		return ndp_process_advert ( iobuf, st_src, st_dest );
91
 	}
91
 	}
92
 	return -ENOSYS;
92
 	return -ENOSYS;
93
 }
93
 }
97
 
97
 
98
 		struct sockaddr_in6 server;
98
 		struct sockaddr_in6 server;
99
 		memcpy ( &server, server_p, sizeof ( server ) );
99
 		memcpy ( &server, server_p, sizeof ( server ) );
100
-                struct pk_buff *rxpkb = alloc_pkb ( 500 );
101
-                pkb_reserve ( rxpkb, MAX_HDR_LEN );
102
-                struct neighbour_advert *nadvert = pkb_put ( rxpkb, sizeof ( *nadvert ) );
100
+                struct io_buffer *rxiobuf = alloc_iob ( 500 );
101
+                iob_reserve ( rxiobuf, MAX_HDR_LEN );
102
+                struct neighbour_advert *nadvert = iob_put ( rxiobuf, sizeof ( *nadvert ) );
103
                 nadvert->type = 136;
103
                 nadvert->type = 136;
104
                 nadvert->code = 0;
104
                 nadvert->code = 0;
105
                 nadvert->flags = ICMP6_FLAGS_SOLICITED;
105
                 nadvert->flags = ICMP6_FLAGS_SOLICITED;
108
                 nadvert->opt_type = 2;
108
                 nadvert->opt_type = 2;
109
                 nadvert->opt_len = 1;
109
                 nadvert->opt_len = 1;
110
                 memcpy ( nadvert->opt_ll_addr, ll_addr, 6 );
110
                 memcpy ( nadvert->opt_ll_addr, ll_addr, 6 );
111
-                struct ip6_header *ip6hdr = pkb_push ( rxpkb, sizeof ( *ip6hdr ) );
111
+                struct ip6_header *ip6hdr = iob_push ( rxiobuf, sizeof ( *ip6hdr ) );
112
                 ip6hdr->ver_traffic_class_flow_label = htonl ( 0x60000000 );
112
                 ip6hdr->ver_traffic_class_flow_label = htonl ( 0x60000000 );
113
 		ip6hdr->hop_limit = 255;
113
 		ip6hdr->hop_limit = 255;
114
 		ip6hdr->nxt_hdr = 58;
114
 		ip6hdr->nxt_hdr = 58;
115
 		ip6hdr->payload_len = htons ( sizeof ( *nadvert ) );
115
 		ip6hdr->payload_len = htons ( sizeof ( *nadvert ) );
116
                 ip6hdr->src = server.sin6_addr;
116
                 ip6hdr->src = server.sin6_addr;
117
                 ip6hdr->dest = server.sin6_addr;
117
                 ip6hdr->dest = server.sin6_addr;
118
-		hex_dump ( rxpkb->data, pkb_len ( rxpkb ) );
119
-                net_rx ( rxpkb, netdev, htons ( ETH_P_IPV6 ), ll_addr );
118
+		hex_dump ( rxiobuf->data, iob_len ( rxiobuf ) );
119
+                net_rx ( rxiobuf, netdev, htons ( ETH_P_IPV6 ), ll_addr );
120
 }
120
 }
121
 #endif
121
 #endif
122
 
122
 

+ 50
- 50
src/net/ipv4.c View File

8
 #include <gpxe/in.h>
8
 #include <gpxe/in.h>
9
 #include <gpxe/arp.h>
9
 #include <gpxe/arp.h>
10
 #include <gpxe/if_ether.h>
10
 #include <gpxe/if_ether.h>
11
-#include <gpxe/pkbuff.h>
11
+#include <gpxe/iobuf.h>
12
 #include <gpxe/netdevice.h>
12
 #include <gpxe/netdevice.h>
13
 #include <gpxe/ip.h>
13
 #include <gpxe/ip.h>
14
 #include <gpxe/tcpip.h>
14
 #include <gpxe/tcpip.h>
205
 /**
205
 /**
206
  * Fragment reassembler
206
  * Fragment reassembler
207
  *
207
  *
208
- * @v pkb		Packet buffer, fragment of the datagram
209
- * @ret frag_pkb	Reassembled packet, or NULL
208
+ * @v iobuf		I/O buffer, fragment of the datagram
209
+ * @ret frag_iob	Reassembled packet, or NULL
210
  */
210
  */
211
-static struct pk_buff * ipv4_reassemble ( struct pk_buff * pkb ) {
212
-	struct iphdr *iphdr = pkb->data;
211
+static struct io_buffer * ipv4_reassemble ( struct io_buffer * iobuf ) {
212
+	struct iphdr *iphdr = iobuf->data;
213
 	struct frag_buffer *fragbuf;
213
 	struct frag_buffer *fragbuf;
214
 	
214
 	
215
 	/**
215
 	/**
223
 			 * 
223
 			 * 
224
 			 * The offset of the new packet must be equal to the
224
 			 * The offset of the new packet must be equal to the
225
 			 * length of the data accumulated so far (the length of
225
 			 * length of the data accumulated so far (the length of
226
-			 * the reassembled packet buffer
226
+			 * the reassembled I/O buffer
227
 			 */
227
 			 */
228
-			if ( pkb_len ( fragbuf->frag_pkb ) == 
228
+			if ( iob_len ( fragbuf->frag_iob ) == 
229
 			      ( iphdr->frags & IP_MASK_OFFSET ) ) {
229
 			      ( iphdr->frags & IP_MASK_OFFSET ) ) {
230
 				/**
230
 				/**
231
 				 * Append the contents of the fragment to the
231
 				 * Append the contents of the fragment to the
232
-				 * reassembled packet buffer
232
+				 * reassembled I/O buffer
233
 				 */
233
 				 */
234
-				pkb_pull ( pkb, sizeof ( *iphdr ) );
235
-				memcpy ( pkb_put ( fragbuf->frag_pkb,
236
-							pkb_len ( pkb ) ),
237
-					 pkb->data, pkb_len ( pkb ) );
238
-				free_pkb ( pkb );
234
+				iob_pull ( iobuf, sizeof ( *iphdr ) );
235
+				memcpy ( iob_put ( fragbuf->frag_iob,
236
+							iob_len ( iobuf ) ),
237
+					 iobuf->data, iob_len ( iobuf ) );
238
+				free_iob ( iobuf );
239
 
239
 
240
 				/** Check if the fragment series is over */
240
 				/** Check if the fragment series is over */
241
 				if ( !iphdr->frags & IP_MASK_MOREFRAGS ) {
241
 				if ( !iphdr->frags & IP_MASK_MOREFRAGS ) {
242
-					pkb = fragbuf->frag_pkb;
242
+					iobuf = fragbuf->frag_iob;
243
 					free_fragbuf ( fragbuf );
243
 					free_fragbuf ( fragbuf );
244
-					return pkb;
244
+					return iobuf;
245
 				}
245
 				}
246
 
246
 
247
 			} else {
247
 			} else {
248
 				/* Discard the fragment series */
248
 				/* Discard the fragment series */
249
 				free_fragbuf ( fragbuf );
249
 				free_fragbuf ( fragbuf );
250
-				free_pkb ( pkb );
250
+				free_iob ( iobuf );
251
 			}
251
 			}
252
 			return NULL;
252
 			return NULL;
253
 		}
253
 		}
262
 		fragbuf->ident = iphdr->ident;
262
 		fragbuf->ident = iphdr->ident;
263
 		fragbuf->src = iphdr->src;
263
 		fragbuf->src = iphdr->src;
264
 
264
 
265
-		/* Set up the reassembly packet buffer */
266
-		fragbuf->frag_pkb = alloc_pkb ( IP_FRAG_PKB_SIZE );
267
-		pkb_pull ( pkb, sizeof ( *iphdr ) );
268
-		memcpy ( pkb_put ( fragbuf->frag_pkb, pkb_len ( pkb ) ),
269
-			 pkb->data, pkb_len ( pkb ) );
270
-		free_pkb ( pkb );
265
+		/* Set up the reassembly I/O buffer */
266
+		fragbuf->frag_iob = alloc_iob ( IP_FRAG_IOB_SIZE );
267
+		iob_pull ( iobuf, sizeof ( *iphdr ) );
268
+		memcpy ( iob_put ( fragbuf->frag_iob, iob_len ( iobuf ) ),
269
+			 iobuf->data, iob_len ( iobuf ) );
270
+		free_iob ( iobuf );
271
 
271
 
272
 		/* Set the reassembly timer */
272
 		/* Set the reassembly timer */
273
 		fragbuf->frag_timer.timeout = IP_FRAG_TIMEOUT;
273
 		fragbuf->frag_timer.timeout = IP_FRAG_TIMEOUT;
284
 /**
284
 /**
285
  * Add IPv4 pseudo-header checksum to existing checksum
285
  * Add IPv4 pseudo-header checksum to existing checksum
286
  *
286
  *
287
- * @v pkb		Packet buffer
287
+ * @v iobuf		I/O buffer
288
  * @v csum		Existing checksum
288
  * @v csum		Existing checksum
289
  * @ret csum		Updated checksum
289
  * @ret csum		Updated checksum
290
  */
290
  */
291
-static uint16_t ipv4_pshdr_chksum ( struct pk_buff *pkb, uint16_t csum ) {
291
+static uint16_t ipv4_pshdr_chksum ( struct io_buffer *iobuf, uint16_t csum ) {
292
 	struct ipv4_pseudo_header pshdr;
292
 	struct ipv4_pseudo_header pshdr;
293
-	struct iphdr *iphdr = pkb->data;
293
+	struct iphdr *iphdr = iobuf->data;
294
 	size_t hdrlen = ( ( iphdr->verhdrlen & IP_MASK_HLEN ) * 4 );
294
 	size_t hdrlen = ( ( iphdr->verhdrlen & IP_MASK_HLEN ) * 4 );
295
 
295
 
296
 	/* Build pseudo-header */
296
 	/* Build pseudo-header */
298
 	pshdr.dest = iphdr->dest;
298
 	pshdr.dest = iphdr->dest;
299
 	pshdr.zero_padding = 0x00;
299
 	pshdr.zero_padding = 0x00;
300
 	pshdr.protocol = iphdr->protocol;
300
 	pshdr.protocol = iphdr->protocol;
301
-	pshdr.len = htons ( pkb_len ( pkb ) - hdrlen );
301
+	pshdr.len = htons ( iob_len ( iobuf ) - hdrlen );
302
 
302
 
303
 	/* Update the checksum value */
303
 	/* Update the checksum value */
304
 	return tcpip_continue_chksum ( csum, &pshdr, sizeof ( pshdr ) );
304
 	return tcpip_continue_chksum ( csum, &pshdr, sizeof ( pshdr ) );
345
 /**
345
 /**
346
  * Transmit IP packet
346
  * Transmit IP packet
347
  *
347
  *
348
- * @v pkb		Packet buffer
348
+ * @v iobuf		I/O buffer
349
  * @v tcpip		Transport-layer protocol
349
  * @v tcpip		Transport-layer protocol
350
  * @v st_dest		Destination network-layer address
350
  * @v st_dest		Destination network-layer address
351
  * @v netdev		Network device to use if no route found, or NULL
351
  * @v netdev		Network device to use if no route found, or NULL
354
  *
354
  *
355
  * This function expects a transport-layer segment and prepends the IP header
355
  * This function expects a transport-layer segment and prepends the IP header
356
  */
356
  */
357
-static int ipv4_tx ( struct pk_buff *pkb,
357
+static int ipv4_tx ( struct io_buffer *iobuf,
358
 		     struct tcpip_protocol *tcpip_protocol,
358
 		     struct tcpip_protocol *tcpip_protocol,
359
 		     struct sockaddr_tcpip *st_dest,
359
 		     struct sockaddr_tcpip *st_dest,
360
 		     struct net_device *netdev,
360
 		     struct net_device *netdev,
361
 		     uint16_t *trans_csum ) {
361
 		     uint16_t *trans_csum ) {
362
-	struct iphdr *iphdr = pkb_push ( pkb, sizeof ( *iphdr ) );
362
+	struct iphdr *iphdr = iob_push ( iobuf, sizeof ( *iphdr ) );
363
 	struct sockaddr_in *sin_dest = ( ( struct sockaddr_in * ) st_dest );
363
 	struct sockaddr_in *sin_dest = ( ( struct sockaddr_in * ) st_dest );
364
 	struct ipv4_miniroute *miniroute;
364
 	struct ipv4_miniroute *miniroute;
365
 	struct in_addr next_hop;
365
 	struct in_addr next_hop;
370
 	memset ( iphdr, 0, sizeof ( *iphdr ) );
370
 	memset ( iphdr, 0, sizeof ( *iphdr ) );
371
 	iphdr->verhdrlen = ( IP_VER | ( sizeof ( *iphdr ) / 4 ) );
371
 	iphdr->verhdrlen = ( IP_VER | ( sizeof ( *iphdr ) / 4 ) );
372
 	iphdr->service = IP_TOS;
372
 	iphdr->service = IP_TOS;
373
-	iphdr->len = htons ( pkb_len ( pkb ) );	
373
+	iphdr->len = htons ( iob_len ( iobuf ) );	
374
 	iphdr->ident = htons ( ++next_ident );
374
 	iphdr->ident = htons ( ++next_ident );
375
 	iphdr->ttl = IP_TTL;
375
 	iphdr->ttl = IP_TTL;
376
 	iphdr->protocol = tcpip_protocol->tcpip_proto;
376
 	iphdr->protocol = tcpip_protocol->tcpip_proto;
398
 
398
 
399
 	/* Fix up checksums */
399
 	/* Fix up checksums */
400
 	if ( trans_csum )
400
 	if ( trans_csum )
401
-		*trans_csum = ipv4_pshdr_chksum ( pkb, *trans_csum );
401
+		*trans_csum = ipv4_pshdr_chksum ( iobuf, *trans_csum );
402
 	iphdr->chksum = tcpip_chksum ( iphdr, sizeof ( *iphdr ) );
402
 	iphdr->chksum = tcpip_chksum ( iphdr, sizeof ( *iphdr ) );
403
 
403
 
404
 	/* Print IP4 header for debugging */
404
 	/* Print IP4 header for debugging */
408
 	      ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
408
 	      ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
409
 
409
 
410
 	/* Hand off to link layer */
410
 	/* Hand off to link layer */
411
-	if ( ( rc = net_tx ( pkb, netdev, &ipv4_protocol, ll_dest ) ) != 0 ) {
411
+	if ( ( rc = net_tx ( iobuf, netdev, &ipv4_protocol, ll_dest ) ) != 0 ) {
412
 		DBG ( "IPv4 could not transmit packet via %s: %s\n",
412
 		DBG ( "IPv4 could not transmit packet via %s: %s\n",
413
 		      netdev->name, strerror ( rc ) );
413
 		      netdev->name, strerror ( rc ) );
414
 		return rc;
414
 		return rc;
417
 	return 0;
417
 	return 0;
418
 
418
 
419
  err:
419
  err:
420
-	free_pkb ( pkb );
420
+	free_iob ( iobuf );
421
 	return rc;
421
 	return rc;
422
 }
422
 }
423
 
423
 
424
 /**
424
 /**
425
  * Process incoming packets
425
  * Process incoming packets
426
  *
426
  *
427
- * @v pkb	Packet buffer
427
+ * @v iobuf	I/O buffer
428
  * @v netdev	Network device
428
  * @v netdev	Network device
429
  * @v ll_source	Link-layer destination source
429
  * @v ll_source	Link-layer destination source
430
  *
430
  *
431
  * This function expects an IP4 network datagram. It processes the headers 
431
  * This function expects an IP4 network datagram. It processes the headers 
432
  * and sends it to the transport layer.
432
  * and sends it to the transport layer.
433
  */
433
  */
434
-static int ipv4_rx ( struct pk_buff *pkb, struct net_device *netdev __unused,
434
+static int ipv4_rx ( struct io_buffer *iobuf, struct net_device *netdev __unused,
435
 		     const void *ll_source __unused ) {
435
 		     const void *ll_source __unused ) {
436
-	struct iphdr *iphdr = pkb->data;
436
+	struct iphdr *iphdr = iobuf->data;
437
 	size_t hdrlen;
437
 	size_t hdrlen;
438
 	size_t len;
438
 	size_t len;
439
 	union {
439
 	union {
445
 	int rc;
445
 	int rc;
446
 
446
 
447
 	/* Sanity check the IPv4 header */
447
 	/* Sanity check the IPv4 header */
448
-	if ( pkb_len ( pkb ) < sizeof ( *iphdr ) ) {
448
+	if ( iob_len ( iobuf ) < sizeof ( *iphdr ) ) {
449
 		DBG ( "IPv4 packet too short at %d bytes (min %d bytes)\n",
449
 		DBG ( "IPv4 packet too short at %d bytes (min %d bytes)\n",
450
-		      pkb_len ( pkb ), sizeof ( *iphdr ) );
450
+		      iob_len ( iobuf ), sizeof ( *iphdr ) );
451
 		goto err;
451
 		goto err;
452
 	}
452
 	}
453
 	if ( ( iphdr->verhdrlen & IP_MASK_VER ) != IP_VER ) {
453
 	if ( ( iphdr->verhdrlen & IP_MASK_VER ) != IP_VER ) {
460
 		      hdrlen, sizeof ( *iphdr ) );
460
 		      hdrlen, sizeof ( *iphdr ) );
461
 		goto err;
461
 		goto err;
462
 	}
462
 	}
463
-	if ( hdrlen > pkb_len ( pkb ) ) {
463
+	if ( hdrlen > iob_len ( iobuf ) ) {
464
 		DBG ( "IPv4 header too long at %d bytes "
464
 		DBG ( "IPv4 header too long at %d bytes "
465
-		      "(packet is %d bytes)\n", hdrlen, pkb_len ( pkb ) );
465
+		      "(packet is %d bytes)\n", hdrlen, iob_len ( iobuf ) );
466
 		goto err;
466
 		goto err;
467
 	}
467
 	}
468
 	if ( ( csum = tcpip_chksum ( iphdr, hdrlen ) ) != 0 ) {
468
 	if ( ( csum = tcpip_chksum ( iphdr, hdrlen ) ) != 0 ) {
476
 		      "(header is %d bytes)\n", len, hdrlen );
476
 		      "(header is %d bytes)\n", len, hdrlen );
477
 		goto err;
477
 		goto err;
478
 	}
478
 	}
479
-	if ( len > pkb_len ( pkb ) ) {
479
+	if ( len > iob_len ( iobuf ) ) {
480
 		DBG ( "IPv4 length too long at %d bytes "
480
 		DBG ( "IPv4 length too long at %d bytes "
481
-		      "(packet is %d bytes)\n", len, pkb_len ( pkb ) );
481
+		      "(packet is %d bytes)\n", len, iob_len ( iobuf ) );
482
 		goto err;
482
 		goto err;
483
 	}
483
 	}
484
 
484
 
491
 	/* Truncate packet to correct length, calculate pseudo-header
491
 	/* Truncate packet to correct length, calculate pseudo-header
492
 	 * checksum and then strip off the IPv4 header.
492
 	 * checksum and then strip off the IPv4 header.
493
 	 */
493
 	 */
494
-	pkb_unput ( pkb, ( pkb_len ( pkb ) - len ) );
495
-	pshdr_csum = ipv4_pshdr_chksum ( pkb, TCPIP_EMPTY_CSUM );
496
-	pkb_pull ( pkb, hdrlen );
494
+	iob_unput ( iobuf, ( iob_len ( iobuf ) - len ) );
495
+	pshdr_csum = ipv4_pshdr_chksum ( iobuf, TCPIP_EMPTY_CSUM );
496
+	iob_pull ( iobuf, hdrlen );
497
 
497
 
498
 	/* Fragment reassembly */
498
 	/* Fragment reassembly */
499
 	if ( ( iphdr->frags & htons ( IP_MASK_MOREFRAGS ) ) || 
499
 	if ( ( iphdr->frags & htons ( IP_MASK_MOREFRAGS ) ) || 
500
 	     ( ( iphdr->frags & htons ( IP_MASK_OFFSET ) ) != 0 ) ) {
500
 	     ( ( iphdr->frags & htons ( IP_MASK_OFFSET ) ) != 0 ) ) {
501
 		/* Pass the fragment to ipv4_reassemble() which either
501
 		/* Pass the fragment to ipv4_reassemble() which either
502
-		 * returns a fully reassembled packet buffer or NULL.
502
+		 * returns a fully reassembled I/O buffer or NULL.
503
 		 */
503
 		 */
504
-		pkb = ipv4_reassemble ( pkb );
505
-		if ( ! pkb )
504
+		iobuf = ipv4_reassemble ( iobuf );
505
+		if ( ! iobuf )
506
 			return 0;
506
 			return 0;
507
 	}
507
 	}
508
 
508
 
513
 	memset ( &dest, 0, sizeof ( dest ) );
513
 	memset ( &dest, 0, sizeof ( dest ) );
514
 	dest.sin.sin_family = AF_INET;
514
 	dest.sin.sin_family = AF_INET;
515
 	dest.sin.sin_addr = iphdr->dest;
515
 	dest.sin.sin_addr = iphdr->dest;
516
-	if ( ( rc = tcpip_rx ( pkb, iphdr->protocol, &src.st,
516
+	if ( ( rc = tcpip_rx ( iobuf, iphdr->protocol, &src.st,
517
 			       &dest.st, pshdr_csum ) ) != 0 ) {
517
 			       &dest.st, pshdr_csum ) ) != 0 ) {
518
 		DBG ( "IPv4 received packet rejected by stack: %s\n",
518
 		DBG ( "IPv4 received packet rejected by stack: %s\n",
519
 		      strerror ( rc ) );
519
 		      strerror ( rc ) );
523
 	return 0;
523
 	return 0;
524
 
524
 
525
  err:
525
  err:
526
-	free_pkb ( pkb );
526
+	free_iob ( iobuf );
527
 	return -EINVAL;
527
 	return -EINVAL;
528
 }
528
 }
529
 
529
 

+ 25
- 25
src/net/ipv6.c View File

11
 #include <gpxe/icmp6.h>
11
 #include <gpxe/icmp6.h>
12
 #include <gpxe/tcpip.h>
12
 #include <gpxe/tcpip.h>
13
 #include <gpxe/socket.h>
13
 #include <gpxe/socket.h>
14
-#include <gpxe/pkbuff.h>
14
+#include <gpxe/iobuf.h>
15
 #include <gpxe/netdevice.h>
15
 #include <gpxe/netdevice.h>
16
 #include <gpxe/if_ether.h>
16
 #include <gpxe/if_ether.h>
17
 
17
 
157
 /**
157
 /**
158
  * Calculate TCPIP checksum
158
  * Calculate TCPIP checksum
159
  *
159
  *
160
- * @v pkb	Packet buffer
160
+ * @v iobuf	I/O buffer
161
  * @v tcpip	TCP/IP protocol
161
  * @v tcpip	TCP/IP protocol
162
  *
162
  *
163
  * This function constructs the pseudo header and completes the checksum in the
163
  * This function constructs the pseudo header and completes the checksum in the
164
  * upper layer header.
164
  * upper layer header.
165
  */
165
  */
166
-static uint16_t ipv6_tx_csum ( struct pk_buff *pkb, uint16_t csum ) {
167
-	struct ip6_header *ip6hdr = pkb->data;
166
+static uint16_t ipv6_tx_csum ( struct io_buffer *iobuf, uint16_t csum ) {
167
+	struct ip6_header *ip6hdr = iobuf->data;
168
 	struct ipv6_pseudo_header pshdr;
168
 	struct ipv6_pseudo_header pshdr;
169
 
169
 
170
 	/* Calculate pseudo header */
170
 	/* Calculate pseudo header */
171
 	memset ( &pshdr, 0, sizeof ( pshdr ) );
171
 	memset ( &pshdr, 0, sizeof ( pshdr ) );
172
 	pshdr.src = ip6hdr->src;
172
 	pshdr.src = ip6hdr->src;
173
 	pshdr.dest = ip6hdr->dest;
173
 	pshdr.dest = ip6hdr->dest;
174
-	pshdr.len = htons ( pkb_len ( pkb ) - sizeof ( *ip6hdr ) );
174
+	pshdr.len = htons ( iob_len ( iobuf ) - sizeof ( *ip6hdr ) );
175
 	pshdr.nxt_hdr = ip6hdr->nxt_hdr;
175
 	pshdr.nxt_hdr = ip6hdr->nxt_hdr;
176
 
176
 
177
 	/* Update checksum value */
177
 	/* Update checksum value */
192
 /**
192
 /**
193
  * Transmit IP6 packet
193
  * Transmit IP6 packet
194
  *
194
  *
195
- * pkb		Packet buffer
195
+ * iobuf		I/O buffer
196
  * tcpip	TCP/IP protocol
196
  * tcpip	TCP/IP protocol
197
  * st_dest	Destination socket address
197
  * st_dest	Destination socket address
198
  *
198
  *
199
  * This function prepends the IPv6 headers to the payload an transmits it.
199
  * This function prepends the IPv6 headers to the payload an transmits it.
200
  */
200
  */
201
-static int ipv6_tx ( struct pk_buff *pkb,
201
+static int ipv6_tx ( struct io_buffer *iobuf,
202
 		     struct tcpip_protocol *tcpip,
202
 		     struct tcpip_protocol *tcpip,
203
 		     struct sockaddr_tcpip *st_dest,
203
 		     struct sockaddr_tcpip *st_dest,
204
 		     struct net_device *netdev,
204
 		     struct net_device *netdev,
211
 	int rc;
211
 	int rc;
212
 
212
 
213
 	/* Construct the IPv6 packet */
213
 	/* Construct the IPv6 packet */
214
-	struct ip6_header *ip6hdr = pkb_push ( pkb, sizeof ( *ip6hdr ) );
214
+	struct ip6_header *ip6hdr = iob_push ( iobuf, sizeof ( *ip6hdr ) );
215
 	memset ( ip6hdr, 0, sizeof ( *ip6hdr) );
215
 	memset ( ip6hdr, 0, sizeof ( *ip6hdr) );
216
 	ip6hdr->ver_traffic_class_flow_label = htonl ( 0x60000000 );//IP6_VERSION;
216
 	ip6hdr->ver_traffic_class_flow_label = htonl ( 0x60000000 );//IP6_VERSION;
217
-	ip6hdr->payload_len = htons ( pkb_len ( pkb ) - sizeof ( *ip6hdr ) );
217
+	ip6hdr->payload_len = htons ( iob_len ( iobuf ) - sizeof ( *ip6hdr ) );
218
 	ip6hdr->nxt_hdr = tcpip->tcpip_proto;
218
 	ip6hdr->nxt_hdr = tcpip->tcpip_proto;
219
 	ip6hdr->hop_limit = IP6_HOP_LIMIT; // 255
219
 	ip6hdr->hop_limit = IP6_HOP_LIMIT; // 255
220
 
220
 
244
 
244
 
245
 	/* Complete the transport layer checksum */
245
 	/* Complete the transport layer checksum */
246
 	if ( trans_csum )
246
 	if ( trans_csum )
247
-		*trans_csum = ipv6_tx_csum ( pkb, *trans_csum );
247
+		*trans_csum = ipv6_tx_csum ( iobuf, *trans_csum );
248
 
248
 
249
 	/* Print IPv6 header */
249
 	/* Print IPv6 header */
250
 	ipv6_dump ( ip6hdr );
250
 	ipv6_dump ( ip6hdr );
267
 	}
267
 	}
268
 
268
 
269
 	/* Transmit packet */
269
 	/* Transmit packet */
270
-	return net_tx ( pkb, netdev, &ipv6_protocol, ll_dest );
270
+	return net_tx ( iobuf, netdev, &ipv6_protocol, ll_dest );
271
 
271
 
272
   err:
272
   err:
273
-	free_pkb ( pkb );
273
+	free_iob ( iobuf );
274
 	return rc;
274
 	return rc;
275
 }
275
 }
276
 
276
 
277
 /**
277
 /**
278
  * Process next IP6 header
278
  * Process next IP6 header
279
  *
279
  *
280
- * @v pkb	Packet buffer
280
+ * @v iobuf	I/O buffer
281
  * @v nxt_hdr	Next header number
281
  * @v nxt_hdr	Next header number
282
  * @v src	Source socket address
282
  * @v src	Source socket address
283
  * @v dest	Destination socket address
283
  * @v dest	Destination socket address
284
  *
284
  *
285
  * Refer http://www.iana.org/assignments/ipv6-parameters for the numbers
285
  * Refer http://www.iana.org/assignments/ipv6-parameters for the numbers
286
  */
286
  */
287
-static int ipv6_process_nxt_hdr ( struct pk_buff *pkb, uint8_t nxt_hdr,
287
+static int ipv6_process_nxt_hdr ( struct io_buffer *iobuf, uint8_t nxt_hdr,
288
 		struct sockaddr_tcpip *src, struct sockaddr_tcpip *dest ) {
288
 		struct sockaddr_tcpip *src, struct sockaddr_tcpip *dest ) {
289
 	switch ( nxt_hdr ) {
289
 	switch ( nxt_hdr ) {
290
 	case IP6_HOPBYHOP: 
290
 	case IP6_HOPBYHOP: 
302
 		return 0;
302
 		return 0;
303
 	}
303
 	}
304
 	/* Next header is not a IPv6 extension header */
304
 	/* Next header is not a IPv6 extension header */
305
-	return tcpip_rx ( pkb, nxt_hdr, src, dest, 0 /* fixme */ );
305
+	return tcpip_rx ( iobuf, nxt_hdr, src, dest, 0 /* fixme */ );
306
 }
306
 }
307
 
307
 
308
 /**
308
 /**
309
  * Process incoming IP6 packets
309
  * Process incoming IP6 packets
310
  *
310
  *
311
- * @v pkb		Packet buffer
311
+ * @v iobuf		I/O buffer
312
  * @v netdev		Network device
312
  * @v netdev		Network device
313
  * @v ll_source		Link-layer source address
313
  * @v ll_source		Link-layer source address
314
  *
314
  *
315
  * This function processes a IPv6 packet
315
  * This function processes a IPv6 packet
316
  */
316
  */
317
-static int ipv6_rx ( struct pk_buff *pkb,
317
+static int ipv6_rx ( struct io_buffer *iobuf,
318
 		     struct net_device *netdev,
318
 		     struct net_device *netdev,
319
 		     const void *ll_source ) {
319
 		     const void *ll_source ) {
320
 
320
 
321
-	struct ip6_header *ip6hdr = pkb->data;
321
+	struct ip6_header *ip6hdr = iobuf->data;
322
 	union {
322
 	union {
323
 		struct sockaddr_in6 sin6;
323
 		struct sockaddr_in6 sin6;
324
 		struct sockaddr_tcpip st;
324
 		struct sockaddr_tcpip st;
325
 	} src, dest;
325
 	} src, dest;
326
 
326
 
327
 	/* Sanity check */
327
 	/* Sanity check */
328
-	if ( pkb_len ( pkb ) < sizeof ( *ip6hdr ) ) {
329
-		DBG ( "Packet too short (%d bytes)\n", pkb_len ( pkb ) );
328
+	if ( iob_len ( iobuf ) < sizeof ( *ip6hdr ) ) {
329
+		DBG ( "Packet too short (%d bytes)\n", iob_len ( iobuf ) );
330
 		goto drop;
330
 		goto drop;
331
 	}
331
 	}
332
 
332
 
342
 	}
342
 	}
343
 
343
 
344
 	/* Check the payload length */
344
 	/* Check the payload length */
345
-	if ( ntohs ( ip6hdr->payload_len ) > pkb_len ( pkb ) ) {
345
+	if ( ntohs ( ip6hdr->payload_len ) > iob_len ( iobuf ) ) {
346
 		DBG ( "Inconsistent packet length (%d bytes)\n",
346
 		DBG ( "Inconsistent packet length (%d bytes)\n",
347
 			ip6hdr->payload_len );
347
 			ip6hdr->payload_len );
348
 		goto drop;
348
 		goto drop;
359
 	dest.sin6.sin6_addr = ip6hdr->dest;
359
 	dest.sin6.sin6_addr = ip6hdr->dest;
360
 
360
 
361
 	/* Strip header */
361
 	/* Strip header */
362
-	pkb_unput ( pkb, pkb_len ( pkb ) - ntohs ( ip6hdr->payload_len ) -
362
+	iob_unput ( iobuf, iob_len ( iobuf ) - ntohs ( ip6hdr->payload_len ) -
363
 							sizeof ( *ip6hdr ) );
363
 							sizeof ( *ip6hdr ) );
364
-	pkb_pull ( pkb, sizeof ( *ip6hdr ) );
364
+	iob_pull ( iobuf, sizeof ( *ip6hdr ) );
365
 
365
 
366
 	/* Send it to the transport layer */
366
 	/* Send it to the transport layer */
367
-	return ipv6_process_nxt_hdr ( pkb, ip6hdr->nxt_hdr, &src.st, &dest.st );
367
+	return ipv6_process_nxt_hdr ( iobuf, ip6hdr->nxt_hdr, &src.st, &dest.st );
368
 
368
 
369
   drop:
369
   drop:
370
 	DBG ( "Packet dropped\n" );
370
 	DBG ( "Packet dropped\n" );
371
-	free_pkb ( pkb );
371
+	free_iob ( iobuf );
372
 	return -1;
372
 	return -1;
373
 }
373
 }
374
 
374
 

+ 6
- 6
src/net/ndp.c View File

3
 #include <byteswap.h>
3
 #include <byteswap.h>
4
 #include <errno.h>
4
 #include <errno.h>
5
 #include <gpxe/if_ether.h>
5
 #include <gpxe/if_ether.h>
6
-#include <gpxe/pkbuff.h>
6
+#include <gpxe/iobuf.h>
7
 #include <gpxe/ndp.h>
7
 #include <gpxe/ndp.h>
8
 #include <gpxe/icmp6.h>
8
 #include <gpxe/icmp6.h>
9
 #include <gpxe/ip6.h>
9
 #include <gpxe/ip6.h>
143
 /**
143
 /**
144
  * Process neighbour advertisement
144
  * Process neighbour advertisement
145
  *
145
  *
146
- * @v pkb	Packet buffer
146
+ * @v iobuf	I/O buffer
147
  * @v st_src	Source address
147
  * @v st_src	Source address
148
  * @v st_dest	Destination address 
148
  * @v st_dest	Destination address 
149
  */
149
  */
150
-int ndp_process_advert ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src __unused,
150
+int ndp_process_advert ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src __unused,
151
 			   struct sockaddr_tcpip *st_dest __unused ) {
151
 			   struct sockaddr_tcpip *st_dest __unused ) {
152
-	struct neighbour_advert *nadvert = pkb->data;
152
+	struct neighbour_advert *nadvert = iobuf->data;
153
 	struct ndp_entry *ndp;
153
 	struct ndp_entry *ndp;
154
 
154
 
155
 	/* Sanity check */
155
 	/* Sanity check */
156
-	if ( pkb_len ( pkb ) < sizeof ( *nadvert ) ) {
157
-		DBG ( "Packet too short (%d bytes)\n", pkb_len ( pkb ) );
156
+	if ( iob_len ( iobuf ) < sizeof ( *nadvert ) ) {
157
+		DBG ( "Packet too short (%d bytes)\n", iob_len ( iobuf ) );
158
 		return -EINVAL;
158
 		return -EINVAL;
159
 	}
159
 	}
160
 
160
 

+ 47
- 47
src/net/netdevice.c View File

23
 #include <string.h>
23
 #include <string.h>
24
 #include <errno.h>
24
 #include <errno.h>
25
 #include <gpxe/if_ether.h>
25
 #include <gpxe/if_ether.h>
26
-#include <gpxe/pkbuff.h>
26
+#include <gpxe/iobuf.h>
27
 #include <gpxe/tables.h>
27
 #include <gpxe/tables.h>
28
 #include <gpxe/process.h>
28
 #include <gpxe/process.h>
29
 #include <gpxe/init.h>
29
 #include <gpxe/init.h>
49
  * Transmit raw packet via network device
49
  * Transmit raw packet via network device
50
  *
50
  *
51
  * @v netdev		Network device
51
  * @v netdev		Network device
52
- * @v pkb		Packet buffer
52
+ * @v iobuf		I/O buffer
53
  * @ret rc		Return status code
53
  * @ret rc		Return status code
54
  *
54
  *
55
  * Transmits the packet via the specified network device.  This
55
  * Transmits the packet via the specified network device.  This
56
- * function takes ownership of the packet buffer.
56
+ * function takes ownership of the I/O buffer.
57
  */
57
  */
58
-int netdev_tx ( struct net_device *netdev, struct pk_buff *pkb ) {
58
+int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ) {
59
 	int rc;
59
 	int rc;
60
 
60
 
61
 	DBGC ( netdev, "NETDEV %p transmitting %p (%p+%zx)\n",
61
 	DBGC ( netdev, "NETDEV %p transmitting %p (%p+%zx)\n",
62
-	       netdev, pkb, pkb->data, pkb_len ( pkb ) );
62
+	       netdev, iobuf, iobuf->data, iob_len ( iobuf ) );
63
 
63
 
64
-	list_add_tail ( &pkb->list, &netdev->tx_queue );
64
+	list_add_tail ( &iobuf->list, &netdev->tx_queue );
65
 
65
 
66
 	if ( ! ( netdev->state & NETDEV_OPEN ) ) {
66
 	if ( ! ( netdev->state & NETDEV_OPEN ) ) {
67
 		rc = -ENETUNREACH;
67
 		rc = -ENETUNREACH;
68
 		goto err;
68
 		goto err;
69
 	}
69
 	}
70
 		
70
 		
71
-	if ( ( rc = netdev->transmit ( netdev, pkb ) ) != 0 )
71
+	if ( ( rc = netdev->transmit ( netdev, iobuf ) ) != 0 )
72
 		goto err;
72
 		goto err;
73
 
73
 
74
 	return 0;
74
 	return 0;
75
 
75
 
76
  err:
76
  err:
77
 	DBGC ( netdev, "NETDEV %p transmission %p failed: %s\n",
77
 	DBGC ( netdev, "NETDEV %p transmission %p failed: %s\n",
78
-	       netdev, pkb, strerror ( rc ) );
79
-	netdev_tx_complete ( netdev, pkb );
78
+	       netdev, iobuf, strerror ( rc ) );
79
+	netdev_tx_complete ( netdev, iobuf );
80
 	return rc;
80
 	return rc;
81
 }
81
 }
82
 
82
 
84
  * Complete network transmission
84
  * Complete network transmission
85
  *
85
  *
86
  * @v netdev		Network device
86
  * @v netdev		Network device
87
- * @v pkb		Packet buffer
87
+ * @v iobuf		I/O buffer
88
  *
88
  *
89
  * The packet must currently be in the network device's TX queue.
89
  * The packet must currently be in the network device's TX queue.
90
  */
90
  */
91
-void netdev_tx_complete ( struct net_device *netdev, struct pk_buff *pkb ) {
92
-	DBGC ( netdev, "NETDEV %p transmission %p complete\n", netdev, pkb );
91
+void netdev_tx_complete ( struct net_device *netdev, struct io_buffer *iobuf ) {
92
+	DBGC ( netdev, "NETDEV %p transmission %p complete\n", netdev, iobuf );
93
 
93
 
94
 	/* Catch data corruption as early as possible */
94
 	/* Catch data corruption as early as possible */
95
-	assert ( pkb->list.next != NULL );
96
-	assert ( pkb->list.prev != NULL );
95
+	assert ( iobuf->list.next != NULL );
96
+	assert ( iobuf->list.prev != NULL );
97
 
97
 
98
-	list_del ( &pkb->list );
99
-	free_pkb ( pkb );
98
+	list_del ( &iobuf->list );
99
+	free_iob ( iobuf );
100
 }
100
 }
101
 
101
 
102
 /**
102
 /**
107
  * Completes the oldest outstanding packet in the TX queue.
107
  * Completes the oldest outstanding packet in the TX queue.
108
  */
108
  */
109
 void netdev_tx_complete_next ( struct net_device *netdev ) {
109
 void netdev_tx_complete_next ( struct net_device *netdev ) {
110
-	struct pk_buff *pkb;
110
+	struct io_buffer *iobuf;
111
 
111
 
112
-	list_for_each_entry ( pkb, &netdev->tx_queue, list ) {
113
-		netdev_tx_complete ( netdev, pkb );
112
+	list_for_each_entry ( iobuf, &netdev->tx_queue, list ) {
113
+		netdev_tx_complete ( netdev, iobuf );
114
 		return;
114
 		return;
115
 	}
115
 	}
116
 }
116
 }
119
  * Add packet to receive queue
119
  * Add packet to receive queue
120
  *
120
  *
121
  * @v netdev		Network device
121
  * @v netdev		Network device
122
- * @v pkb		Packet buffer
122
+ * @v iobuf		I/O buffer
123
  *
123
  *
124
  * The packet is added to the network device's RX queue.  This
124
  * The packet is added to the network device's RX queue.  This
125
- * function takes ownership of the packet buffer.
125
+ * function takes ownership of the I/O buffer.
126
  */
126
  */
127
-void netdev_rx ( struct net_device *netdev, struct pk_buff *pkb ) {
127
+void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf ) {
128
 	DBGC ( netdev, "NETDEV %p received %p (%p+%zx)\n",
128
 	DBGC ( netdev, "NETDEV %p received %p (%p+%zx)\n",
129
-	       netdev, pkb, pkb->data, pkb_len ( pkb ) );
130
-	list_add_tail ( &pkb->list, &netdev->rx_queue );
129
+	       netdev, iobuf, iobuf->data, iob_len ( iobuf ) );
130
+	list_add_tail ( &iobuf->list, &netdev->rx_queue );
131
 }
131
 }
132
 
132
 
133
 /**
133
 /**
153
  * Remove packet from device's receive queue
153
  * Remove packet from device's receive queue
154
  *
154
  *
155
  * @v netdev		Network device
155
  * @v netdev		Network device
156
- * @ret pkb		Packet buffer, or NULL
156
+ * @ret iobuf		I/O buffer, or NULL
157
  *
157
  *
158
  * Removes the first packet from the device's RX queue and returns it.
158
  * Removes the first packet from the device's RX queue and returns it.
159
  * Ownership of the packet is transferred to the caller.
159
  * Ownership of the packet is transferred to the caller.
160
  */
160
  */
161
-struct pk_buff * netdev_rx_dequeue ( struct net_device *netdev ) {
162
-	struct pk_buff *pkb;
161
+struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev ) {
162
+	struct io_buffer *iobuf;
163
 
163
 
164
-	list_for_each_entry ( pkb, &netdev->rx_queue, list ) {
165
-		list_del ( &pkb->list );
166
-		return pkb;
164
+	list_for_each_entry ( iobuf, &netdev->rx_queue, list ) {
165
+		list_del ( &iobuf->list );
166
+		return iobuf;
167
 	}
167
 	}
168
 	return NULL;
168
 	return NULL;
169
 }
169
 }
247
  * @v netdev		Network device
247
  * @v netdev		Network device
248
  */
248
  */
249
 void netdev_close ( struct net_device *netdev ) {
249
 void netdev_close ( struct net_device *netdev ) {
250
-	struct pk_buff *pkb;
250
+	struct io_buffer *iobuf;
251
 
251
 
252
 	/* Do nothing if device is already closed */
252
 	/* Do nothing if device is already closed */
253
 	if ( ! ( netdev->state & NETDEV_OPEN ) )
253
 	if ( ! ( netdev->state & NETDEV_OPEN ) )
264
 	}
264
 	}
265
 
265
 
266
 	/* Discard any packets in the RX queue */
266
 	/* Discard any packets in the RX queue */
267
-	while ( ( pkb = netdev_rx_dequeue ( netdev ) ) ) {
267
+	while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
268
 		DBGC ( netdev, "NETDEV %p discarding received %p\n",
268
 		DBGC ( netdev, "NETDEV %p discarding received %p\n",
269
-		       netdev, pkb );
270
-		free_pkb ( pkb );
269
+		       netdev, iobuf );
270
+		free_iob ( iobuf );
271
 	}
271
 	}
272
 
272
 
273
 	/* Mark as closed */
273
 	/* Mark as closed */
341
 /**
341
 /**
342
  * Transmit network-layer packet
342
  * Transmit network-layer packet
343
  *
343
  *
344
- * @v pkb		Packet buffer
344
+ * @v iobuf		I/O buffer
345
  * @v netdev		Network device
345
  * @v netdev		Network device
346
  * @v net_protocol	Network-layer protocol
346
  * @v net_protocol	Network-layer protocol
347
  * @v ll_dest		Destination link-layer address
347
  * @v ll_dest		Destination link-layer address
348
  * @ret rc		Return status code
348
  * @ret rc		Return status code
349
  *
349
  *
350
- * Prepends link-layer headers to the packet buffer and transmits the
350
+ * Prepends link-layer headers to the I/O buffer and transmits the
351
  * packet via the specified network device.  This function takes
351
  * packet via the specified network device.  This function takes
352
- * ownership of the packet buffer.
352
+ * ownership of the I/O buffer.
353
  */
353
  */
354
-int net_tx ( struct pk_buff *pkb, struct net_device *netdev,
354
+int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
355
 	     struct net_protocol *net_protocol, const void *ll_dest ) {
355
 	     struct net_protocol *net_protocol, const void *ll_dest ) {
356
-	return netdev->ll_protocol->tx ( pkb, netdev, net_protocol, ll_dest );
356
+	return netdev->ll_protocol->tx ( iobuf, netdev, net_protocol, ll_dest );
357
 }
357
 }
358
 
358
 
359
 /**
359
 /**
360
  * Process received network-layer packet
360
  * Process received network-layer packet
361
  *
361
  *
362
- * @v pkb		Packet buffer
362
+ * @v iobuf		I/O buffer
363
  * @v netdev		Network device
363
  * @v netdev		Network device
364
  * @v net_proto		Network-layer protocol, in network-byte order
364
  * @v net_proto		Network-layer protocol, in network-byte order
365
  * @v ll_source		Source link-layer address
365
  * @v ll_source		Source link-layer address
366
  * @ret rc		Return status code
366
  * @ret rc		Return status code
367
  */
367
  */
368
-int net_rx ( struct pk_buff *pkb, struct net_device *netdev,
368
+int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
369
 	     uint16_t net_proto, const void *ll_source ) {
369
 	     uint16_t net_proto, const void *ll_source ) {
370
 	struct net_protocol *net_protocol;
370
 	struct net_protocol *net_protocol;
371
 
371
 
373
 	for ( net_protocol = net_protocols ; net_protocol < net_protocols_end ;
373
 	for ( net_protocol = net_protocols ; net_protocol < net_protocols_end ;
374
 	      net_protocol++ ) {
374
 	      net_protocol++ ) {
375
 		if ( net_protocol->net_proto == net_proto ) {
375
 		if ( net_protocol->net_proto == net_proto ) {
376
-			return net_protocol->rx ( pkb, netdev, ll_source );
376
+			return net_protocol->rx ( iobuf, netdev, ll_source );
377
 		}
377
 		}
378
 	}
378
 	}
379
-	free_pkb ( pkb );
379
+	free_iob ( iobuf );
380
 	return 0;
380
 	return 0;
381
 }
381
 }
382
 
382
 
390
  */
390
  */
391
 static void net_step ( struct process *process ) {
391
 static void net_step ( struct process *process ) {
392
 	struct net_device *netdev;
392
 	struct net_device *netdev;
393
-	struct pk_buff *pkb;
393
+	struct io_buffer *iobuf;
394
 
394
 
395
 	/* Poll and process each network device */
395
 	/* Poll and process each network device */
396
 	list_for_each_entry ( netdev, &net_devices, list ) {
396
 	list_for_each_entry ( netdev, &net_devices, list ) {
404
 		 * that assumes that we can receive packets from the
404
 		 * that assumes that we can receive packets from the
405
 		 * NIC faster than they arrive.
405
 		 * NIC faster than they arrive.
406
 		 */
406
 		 */
407
-		if ( ( pkb = netdev_rx_dequeue ( netdev ) ) ) {
407
+		if ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
408
 			DBGC ( netdev, "NETDEV %p processing %p\n",
408
 			DBGC ( netdev, "NETDEV %p processing %p\n",
409
-			       netdev, pkb );
410
-			netdev->ll_protocol->rx ( pkb, netdev );
409
+			       netdev, iobuf );
410
+			netdev->ll_protocol->rx ( iobuf, netdev );
411
 		}
411
 		}
412
 	}
412
 	}
413
 
413
 

+ 20
- 20
src/net/pkbpad.c View File

19
 /**
19
 /**
20
  * @file
20
  * @file
21
  *
21
  *
22
- * Packet buffer padding
22
+ * I/O buffer padding
23
  *
23
  *
24
  */
24
  */
25
 
25
 
26
 #include <string.h>
26
 #include <string.h>
27
-#include <gpxe/pkbuff.h>
27
+#include <gpxe/iobuf.h>
28
 
28
 
29
 /**
29
 /**
30
- * Pad packet buffer
30
+ * Pad I/O buffer
31
  *
31
  *
32
- * @v pkb		Packet buffer
32
+ * @v iobuf		I/O buffer
33
  * @v min_len		Minimum length
33
  * @v min_len		Minimum length
34
  *
34
  *
35
- * This function pads and aligns packet buffers, for devices that
35
+ * This function pads and aligns I/O buffers, for devices that
36
  * aren't capable of padding in hardware, or that require specific
36
  * aren't capable of padding in hardware, or that require specific
37
  * alignment in TX buffers.  The packet data will end up aligned to a
37
  * alignment in TX buffers.  The packet data will end up aligned to a
38
- * multiple of @c PKB_ALIGN.
38
+ * multiple of @c IOB_ALIGN.
39
  *
39
  *
40
- * @c min_len must not exceed @v PKB_ZLEN.
40
+ * @c min_len must not exceed @v IOB_ZLEN.
41
  */
41
  */
42
-void pkb_pad ( struct pk_buff *pkb, size_t min_len ) {
42
+void iob_pad ( struct io_buffer *iobuf, size_t min_len ) {
43
 	void *data;
43
 	void *data;
44
 	size_t len;
44
 	size_t len;
45
 	size_t headroom;
45
 	size_t headroom;
46
 	signed int pad_len;
46
 	signed int pad_len;
47
 
47
 
48
-	assert ( min_len <= PKB_ZLEN );
48
+	assert ( min_len <= IOB_ZLEN );
49
 
49
 
50
-	/* Move packet data to start of packet buffer.  This will both
51
-	 * align the data (since packet buffers are aligned to
52
-	 * PKB_ALIGN) and give us sufficient space for the
50
+	/* Move packet data to start of I/O buffer.  This will both
51
+	 * align the data (since I/O buffers are aligned to
52
+	 * IOB_ALIGN) and give us sufficient space for the
53
 	 * zero-padding
53
 	 * zero-padding
54
 	 */
54
 	 */
55
-	data = pkb->data;
56
-	len = pkb_len ( pkb );
57
-	headroom = pkb_headroom ( pkb );
58
-	pkb_push ( pkb, headroom );
59
-	memmove ( pkb->data, data, len );
60
-	pkb_unput ( pkb, headroom );
55
+	data = iobuf->data;
56
+	len = iob_len ( iobuf );
57
+	headroom = iob_headroom ( iobuf );
58
+	iob_push ( iobuf, headroom );
59
+	memmove ( iobuf->data, data, len );
60
+	iob_unput ( iobuf, headroom );
61
 
61
 
62
 	/* Pad to minimum packet length */
62
 	/* Pad to minimum packet length */
63
-	pad_len = ( min_len - pkb_len ( pkb ) );
63
+	pad_len = ( min_len - iob_len ( iobuf ) );
64
 	if ( pad_len > 0 )
64
 	if ( pad_len > 0 )
65
-		memset ( pkb_put ( pkb, pad_len ), 0, pad_len );
65
+		memset ( iob_put ( iobuf, pad_len ), 0, pad_len );
66
 }
66
 }

+ 0
- 73
src/net/pkbuff.c View File

1
-/*
2
- * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as
6
- * published by the Free Software Foundation; either version 2 of the
7
- * License, or any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
- * General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, write to the Free Software
16
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
- */
18
-
19
-#include <stdint.h>
20
-#include <gpxe/malloc.h>
21
-#include <gpxe/pkbuff.h>
22
-
23
-/** @file
24
- *
25
- * Packet buffers
26
- *
27
- */
28
-
29
-/**
30
- * Allocate packet buffer
31
- *
32
- * @v len	Required length of buffer
33
- * @ret pkb	Packet buffer, or NULL if none available
34
- *
35
- * The packet buffer will be physically aligned to a multiple of
36
- * @c PKBUFF_SIZE.
37
- */
38
-struct pk_buff * alloc_pkb ( size_t len ) {
39
-	struct pk_buff *pkb = NULL;
40
-	void *data;
41
-
42
-	/* Pad to minimum length */
43
-	if ( len < PKB_ZLEN )
44
-		len = PKB_ZLEN;
45
-
46
-	/* Align buffer length */
47
-	len = ( len + __alignof__( *pkb ) - 1 ) & ~( __alignof__( *pkb ) - 1 );
48
-	
49
-	/* Allocate memory for buffer plus descriptor */
50
-	data = malloc_dma ( len + sizeof ( *pkb ), PKBUFF_ALIGN );
51
-	if ( ! data )
52
-		return NULL;
53
-
54
-	pkb = ( struct pk_buff * ) ( data + len );
55
-	pkb->head = pkb->data = pkb->tail = data;
56
-	pkb->end = pkb;
57
-	return pkb;
58
-}
59
-
60
-/**
61
- * Free packet buffer
62
- *
63
- * @v pkb	Packet buffer
64
- */
65
-void free_pkb ( struct pk_buff *pkb ) {
66
-	if ( pkb ) {
67
-		assert ( pkb->head <= pkb->data );
68
-		assert ( pkb->data <= pkb->tail );
69
-		assert ( pkb->tail <= pkb->end );
70
-		free_dma ( pkb->head,
71
-			   ( pkb->end - pkb->head ) + sizeof ( *pkb ) );
72
-	}
73
-}

+ 46
- 46
src/net/tcp.c View File

5
 #include <errno.h>
5
 #include <errno.h>
6
 #include <byteswap.h>
6
 #include <byteswap.h>
7
 #include <timer.h>
7
 #include <timer.h>
8
-#include <gpxe/pkbuff.h>
8
+#include <gpxe/iobuf.h>
9
 #include <gpxe/malloc.h>
9
 #include <gpxe/malloc.h>
10
 #include <gpxe/retry.h>
10
 #include <gpxe/retry.h>
11
 #include <gpxe/stream.h>
11
 #include <gpxe/stream.h>
68
 	 */
68
 	 */
69
 	uint32_t rcv_ack;
69
 	uint32_t rcv_ack;
70
 
70
 
71
-	/** Transmit packet buffer
71
+	/** Transmit I/O buffer
72
 	 *
72
 	 *
73
 	 * This buffer is allocated prior to calling the application's
73
 	 * This buffer is allocated prior to calling the application's
74
 	 * senddata() method, to provide temporary storage space.
74
 	 * senddata() method, to provide temporary storage space.
75
 	 */
75
 	 */
76
-	struct pk_buff *tx_pkb;
76
+	struct io_buffer *tx_iob;
77
 	/** Retransmission timer */
77
 	/** Retransmission timer */
78
 	struct retry_timer timer;
78
 	struct retry_timer timer;
79
 };
79
 };
222
  * eventually attempt to retransmit the failed packet.
222
  * eventually attempt to retransmit the failed packet.
223
  */
223
  */
224
 static int tcp_senddata_conn ( struct tcp_connection *tcp, int force_send ) {
224
 static int tcp_senddata_conn ( struct tcp_connection *tcp, int force_send ) {
225
-	struct pk_buff *pkb;
225
+	struct io_buffer *iobuf;
226
 	struct tcp_header *tcphdr;
226
 	struct tcp_header *tcphdr;
227
 	struct tcp_mss_option *mssopt;
227
 	struct tcp_mss_option *mssopt;
228
 	void *payload;
228
 	void *payload;
233
 	int rc;
233
 	int rc;
234
 
234
 
235
 	/* Allocate space to the TX buffer */
235
 	/* Allocate space to the TX buffer */
236
-	pkb = alloc_pkb ( MAX_PKB_LEN );
237
-	if ( ! pkb ) {
236
+	iobuf = alloc_iob ( MAX_IOB_LEN );
237
+	if ( ! iobuf ) {
238
 		DBGC ( tcp, "TCP %p could not allocate data buffer\n", tcp );
238
 		DBGC ( tcp, "TCP %p could not allocate data buffer\n", tcp );
239
 		/* Start the retry timer so that we attempt to
239
 		/* Start the retry timer so that we attempt to
240
 		 * retransmit this packet later.  (Start it
240
 		 * retransmit this packet later.  (Start it
241
-		 * unconditionally, since without a packet buffer we
241
+		 * unconditionally, since without a I/O buffer we
242
 		 * can't call the senddata() callback, and so may not
242
 		 * can't call the senddata() callback, and so may not
243
 		 * be able to tell whether or not we have something
243
 		 * be able to tell whether or not we have something
244
 		 * that actually needs to be retransmitted).
244
 		 * that actually needs to be retransmitted).
246
 		start_timer ( &tcp->timer );
246
 		start_timer ( &tcp->timer );
247
 		return -ENOMEM;
247
 		return -ENOMEM;
248
 	}
248
 	}
249
-	pkb_reserve ( pkb, MAX_HDR_LEN );
249
+	iob_reserve ( iobuf, MAX_HDR_LEN );
250
 
250
 
251
 	/* If we are connected, call the senddata() method, which may
251
 	/* If we are connected, call the senddata() method, which may
252
 	 * call tcp_send() to queue up a data payload.
252
 	 * call tcp_send() to queue up a data payload.
253
 	 */
253
 	 */
254
 	if ( TCP_CAN_SEND_DATA ( tcp->tcp_state ) ) {
254
 	if ( TCP_CAN_SEND_DATA ( tcp->tcp_state ) ) {
255
-		tcp->tx_pkb = pkb;
256
-		stream_senddata ( &tcp->stream, pkb->data,
257
-				  pkb_tailroom ( pkb ) );
258
-		tcp->tx_pkb = NULL;
255
+		tcp->tx_iob = iobuf;
256
+		stream_senddata ( &tcp->stream, iobuf->data,
257
+				  iob_tailroom ( iobuf ) );
258
+		tcp->tx_iob = NULL;
259
 	}
259
 	}
260
 
260
 
261
 	/* Truncate payload length to fit transmit window */
261
 	/* Truncate payload length to fit transmit window */
262
-	len = pkb_len ( pkb );
262
+	len = iob_len ( iobuf );
263
 	if ( len > tcp->snd_win )
263
 	if ( len > tcp->snd_win )
264
 		len = tcp->snd_win;
264
 		len = tcp->snd_win;
265
 
265
 
276
 
276
 
277
 	/* If we have nothing to transmit, drop the packet */
277
 	/* If we have nothing to transmit, drop the packet */
278
 	if ( ( seq_len == 0 ) && ! force_send ) {
278
 	if ( ( seq_len == 0 ) && ! force_send ) {
279
-		free_pkb ( pkb );
279
+		free_iob ( iobuf );
280
 		return 0;
280
 		return 0;
281
 	}
281
 	}
282
 
282
 
294
 	window &= ~0x03; /* Keep everything dword-aligned */
294
 	window &= ~0x03; /* Keep everything dword-aligned */
295
 
295
 
296
 	/* Fill up the TCP header */
296
 	/* Fill up the TCP header */
297
-	payload = pkb->data;
297
+	payload = iobuf->data;
298
 	if ( flags & TCP_SYN ) {
298
 	if ( flags & TCP_SYN ) {
299
-		mssopt = pkb_push ( pkb, sizeof ( *mssopt ) );
299
+		mssopt = iob_push ( iobuf, sizeof ( *mssopt ) );
300
 		mssopt->kind = TCP_OPTION_MSS;
300
 		mssopt->kind = TCP_OPTION_MSS;
301
 		mssopt->length = sizeof ( *mssopt );
301
 		mssopt->length = sizeof ( *mssopt );
302
 		mssopt->mss = htons ( TCP_MSS );
302
 		mssopt->mss = htons ( TCP_MSS );
303
 	}
303
 	}
304
-	tcphdr = pkb_push ( pkb, sizeof ( *tcphdr ) );
304
+	tcphdr = iob_push ( iobuf, sizeof ( *tcphdr ) );
305
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
305
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
306
 	tcphdr->src = tcp->local_port;
306
 	tcphdr->src = tcp->local_port;
307
 	tcphdr->dest = tcp->peer.st_port;
307
 	tcphdr->dest = tcp->peer.st_port;
308
 	tcphdr->seq = htonl ( tcp->snd_seq );
308
 	tcphdr->seq = htonl ( tcp->snd_seq );
309
 	tcphdr->ack = htonl ( tcp->rcv_ack );
309
 	tcphdr->ack = htonl ( tcp->rcv_ack );
310
-	tcphdr->hlen = ( ( payload - pkb->data ) << 2 );
310
+	tcphdr->hlen = ( ( payload - iobuf->data ) << 2 );
311
 	tcphdr->flags = flags;
311
 	tcphdr->flags = flags;
312
 	tcphdr->win = htons ( window );
312
 	tcphdr->win = htons ( window );
313
-	tcphdr->csum = tcpip_chksum ( pkb->data, pkb_len ( pkb ) );
313
+	tcphdr->csum = tcpip_chksum ( iobuf->data, iob_len ( iobuf ) );
314
 
314
 
315
 	/* Dump header */
315
 	/* Dump header */
316
 	DBGC ( tcp, "TCP %p TX %d->%d %08lx..%08lx           %08lx %4zd",
316
 	DBGC ( tcp, "TCP %p TX %d->%d %08lx..%08lx           %08lx %4zd",
321
 	DBGC ( tcp, "\n" );
321
 	DBGC ( tcp, "\n" );
322
 
322
 
323
 	/* Transmit packet */
323
 	/* Transmit packet */
324
-	rc = tcpip_tx ( pkb, &tcp_protocol, &tcp->peer, NULL, &tcphdr->csum );
324
+	rc = tcpip_tx ( iobuf, &tcp_protocol, &tcp->peer, NULL, &tcphdr->csum );
325
 
325
 
326
 	/* If we got -ENETUNREACH, kill the connection immediately
326
 	/* If we got -ENETUNREACH, kill the connection immediately
327
 	 * because there is no point retrying.  This isn't strictly
327
 	 * because there is no point retrying.  This isn't strictly
372
 		      const void *data, size_t len ) {
372
 		      const void *data, size_t len ) {
373
 	struct tcp_connection *tcp =
373
 	struct tcp_connection *tcp =
374
 		container_of ( stream, struct tcp_connection, stream );
374
 		container_of ( stream, struct tcp_connection, stream );
375
-	struct pk_buff *pkb;
375
+	struct io_buffer *iobuf;
376
 
376
 
377
-	/* Check that we have a packet buffer to fill */
378
-	pkb = tcp->tx_pkb;
379
-	if ( ! pkb ) {
377
+	/* Check that we have a I/O buffer to fill */
378
+	iobuf = tcp->tx_iob;
379
+	if ( ! iobuf ) {
380
 		DBGC ( tcp, "TCP %p tried to send data outside of the "
380
 		DBGC ( tcp, "TCP %p tried to send data outside of the "
381
 		       "senddata() method\n", tcp );
381
 		       "senddata() method\n", tcp );
382
 		return -EINVAL;
382
 		return -EINVAL;
383
 	}
383
 	}
384
 
384
 
385
-	/* Truncate length to fit packet buffer */
386
-	if ( len > pkb_tailroom ( pkb ) )
387
-		len = pkb_tailroom ( pkb );
385
+	/* Truncate length to fit I/O buffer */
386
+	if ( len > iob_tailroom ( iobuf ) )
387
+		len = iob_tailroom ( iobuf );
388
 
388
 
389
 	/* Copy payload */
389
 	/* Copy payload */
390
-	memmove ( pkb_put ( pkb, len ), data, len );
390
+	memmove ( iob_put ( iobuf, len ), data, len );
391
 
391
 
392
 	return 0;
392
 	return 0;
393
 }
393
 }
434
  */
434
  */
435
 static int tcp_send_reset ( struct tcp_connection *tcp,
435
 static int tcp_send_reset ( struct tcp_connection *tcp,
436
 			    struct tcp_header *in_tcphdr ) {
436
 			    struct tcp_header *in_tcphdr ) {
437
-	struct pk_buff *pkb;
437
+	struct io_buffer *iobuf;
438
 	struct tcp_header *tcphdr;
438
 	struct tcp_header *tcphdr;
439
 
439
 
440
 	/* Allocate space for dataless TX buffer */
440
 	/* Allocate space for dataless TX buffer */
441
-	pkb = alloc_pkb ( MAX_HDR_LEN );
442
-	if ( ! pkb ) {
441
+	iobuf = alloc_iob ( MAX_HDR_LEN );
442
+	if ( ! iobuf ) {
443
 		DBGC ( tcp, "TCP %p could not allocate data buffer\n", tcp );
443
 		DBGC ( tcp, "TCP %p could not allocate data buffer\n", tcp );
444
 		return -ENOMEM;
444
 		return -ENOMEM;
445
 	}
445
 	}
446
-	pkb_reserve ( pkb, MAX_HDR_LEN );
446
+	iob_reserve ( iobuf, MAX_HDR_LEN );
447
 
447
 
448
 	/* Construct RST response */
448
 	/* Construct RST response */
449
-	tcphdr = pkb_push ( pkb, sizeof ( *tcphdr ) );
449
+	tcphdr = iob_push ( iobuf, sizeof ( *tcphdr ) );
450
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
450
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
451
 	tcphdr->src = in_tcphdr->dest;
451
 	tcphdr->src = in_tcphdr->dest;
452
 	tcphdr->dest = in_tcphdr->src;
452
 	tcphdr->dest = in_tcphdr->src;
455
 	tcphdr->hlen = ( ( sizeof ( *tcphdr ) / 4 ) << 4 );
455
 	tcphdr->hlen = ( ( sizeof ( *tcphdr ) / 4 ) << 4 );
456
 	tcphdr->flags = ( TCP_RST | TCP_ACK );
456
 	tcphdr->flags = ( TCP_RST | TCP_ACK );
457
 	tcphdr->win = htons ( TCP_MAX_WINDOW_SIZE );
457
 	tcphdr->win = htons ( TCP_MAX_WINDOW_SIZE );
458
-	tcphdr->csum = tcpip_chksum ( pkb->data, pkb_len ( pkb ) );
458
+	tcphdr->csum = tcpip_chksum ( iobuf->data, iob_len ( iobuf ) );
459
 
459
 
460
 	/* Dump header */
460
 	/* Dump header */
461
 	DBGC ( tcp, "TCP %p TX %d->%d %08lx..%08lx           %08lx %4zd",
461
 	DBGC ( tcp, "TCP %p TX %d->%d %08lx..%08lx           %08lx %4zd",
466
 	DBGC ( tcp, "\n" );
466
 	DBGC ( tcp, "\n" );
467
 
467
 
468
 	/* Transmit packet */
468
 	/* Transmit packet */
469
-	return tcpip_tx ( pkb, &tcp_protocol, &tcp->peer,
469
+	return tcpip_tx ( iobuf, &tcp_protocol, &tcp->peer,
470
 			  NULL, &tcphdr->csum );
470
 			  NULL, &tcphdr->csum );
471
 }
471
 }
472
 
472
 
662
 /**
662
 /**
663
  * Process received packet
663
  * Process received packet
664
  *
664
  *
665
- * @v pkb		Packet buffer
665
+ * @v iobuf		I/O buffer
666
  * @v st_src		Partially-filled source address
666
  * @v st_src		Partially-filled source address
667
  * @v st_dest		Partially-filled destination address
667
  * @v st_dest		Partially-filled destination address
668
  * @v pshdr_csum	Pseudo-header checksum
668
  * @v pshdr_csum	Pseudo-header checksum
669
  * @ret rc		Return status code
669
  * @ret rc		Return status code
670
   */
670
   */
671
-static int tcp_rx ( struct pk_buff *pkb,
671
+static int tcp_rx ( struct io_buffer *iobuf,
672
 		    struct sockaddr_tcpip *st_src __unused,
672
 		    struct sockaddr_tcpip *st_src __unused,
673
 		    struct sockaddr_tcpip *st_dest __unused,
673
 		    struct sockaddr_tcpip *st_dest __unused,
674
 		    uint16_t pshdr_csum ) {
674
 		    uint16_t pshdr_csum ) {
675
-	struct tcp_header *tcphdr = pkb->data;
675
+	struct tcp_header *tcphdr = iobuf->data;
676
 	struct tcp_connection *tcp;
676
 	struct tcp_connection *tcp;
677
 	unsigned int hlen;
677
 	unsigned int hlen;
678
 	uint16_t csum;
678
 	uint16_t csum;
686
 	int rc;
686
 	int rc;
687
 
687
 
688
 	/* Sanity check packet */
688
 	/* Sanity check packet */
689
-	if ( pkb_len ( pkb ) < sizeof ( *tcphdr ) ) {
689
+	if ( iob_len ( iobuf ) < sizeof ( *tcphdr ) ) {
690
 		DBG ( "TCP packet too short at %d bytes (min %d bytes)\n",
690
 		DBG ( "TCP packet too short at %d bytes (min %d bytes)\n",
691
-		      pkb_len ( pkb ), sizeof ( *tcphdr ) );
691
+		      iob_len ( iobuf ), sizeof ( *tcphdr ) );
692
 		rc = -EINVAL;
692
 		rc = -EINVAL;
693
 		goto done;
693
 		goto done;
694
 	}
694
 	}
699
 		rc = -EINVAL;
699
 		rc = -EINVAL;
700
 		goto done;
700
 		goto done;
701
 	}
701
 	}
702
-	if ( hlen > pkb_len ( pkb ) ) {
702
+	if ( hlen > iob_len ( iobuf ) ) {
703
 		DBG ( "TCP header too long at %d bytes (max %d bytes)\n",
703
 		DBG ( "TCP header too long at %d bytes (max %d bytes)\n",
704
-		      hlen, pkb_len ( pkb ) );
704
+		      hlen, iob_len ( iobuf ) );
705
 		rc = -EINVAL;
705
 		rc = -EINVAL;
706
 		goto done;
706
 		goto done;
707
 	}
707
 	}
708
-	csum = tcpip_continue_chksum ( pshdr_csum, pkb->data, pkb_len ( pkb ));
708
+	csum = tcpip_continue_chksum ( pshdr_csum, iobuf->data, iob_len ( iobuf ));
709
 	if ( csum != 0 ) {
709
 	if ( csum != 0 ) {
710
 		DBG ( "TCP checksum incorrect (is %04x including checksum "
710
 		DBG ( "TCP checksum incorrect (is %04x including checksum "
711
 		      "field, should be 0000)\n", csum );
711
 		      "field, should be 0000)\n", csum );
719
 	ack = ntohl ( tcphdr->ack );
719
 	ack = ntohl ( tcphdr->ack );
720
 	win = ntohs ( tcphdr->win );
720
 	win = ntohs ( tcphdr->win );
721
 	flags = tcphdr->flags;
721
 	flags = tcphdr->flags;
722
-	data = pkb_pull ( pkb, hlen );
723
-	len = pkb_len ( pkb );
722
+	data = iob_pull ( iobuf, hlen );
723
+	len = iob_len ( iobuf );
724
 
724
 
725
 	/* Dump header */
725
 	/* Dump header */
726
 	DBGC ( tcp, "TCP %p RX %d<-%d           %08lx %08lx..%08lx %4zd",
726
 	DBGC ( tcp, "TCP %p RX %d<-%d           %08lx %08lx..%08lx %4zd",
787
 	rc = 0;
787
 	rc = 0;
788
  done:
788
  done:
789
 	/* Free received packet */
789
 	/* Free received packet */
790
-	free_pkb ( pkb );
790
+	free_iob ( iobuf );
791
 	return rc;
791
 	return rc;
792
 }
792
 }
793
 
793
 

+ 9
- 9
src/net/tcpip.c View File

2
 #include <string.h>
2
 #include <string.h>
3
 #include <errno.h>
3
 #include <errno.h>
4
 #include <byteswap.h>
4
 #include <byteswap.h>
5
-#include <gpxe/pkbuff.h>
5
+#include <gpxe/iobuf.h>
6
 #include <gpxe/tables.h>
6
 #include <gpxe/tables.h>
7
 #include <gpxe/tcpip.h>
7
 #include <gpxe/tcpip.h>
8
 
8
 
28
 
28
 
29
 /** Process a received TCP/IP packet
29
 /** Process a received TCP/IP packet
30
  *
30
  *
31
- * @v pkb		Packet buffer
31
+ * @v iobuf		I/O buffer
32
  * @v tcpip_proto	Transport-layer protocol number
32
  * @v tcpip_proto	Transport-layer protocol number
33
  * @v st_src		Partially-filled source address
33
  * @v st_src		Partially-filled source address
34
  * @v st_dest		Partially-filled destination address
34
  * @v st_dest		Partially-filled destination address
41
  * address family and the network-layer addresses, but leave the ports
41
  * address family and the network-layer addresses, but leave the ports
42
  * and the rest of the structures as zero).
42
  * and the rest of the structures as zero).
43
  */
43
  */
44
-int tcpip_rx ( struct pk_buff *pkb, uint8_t tcpip_proto, 
44
+int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto, 
45
 	       struct sockaddr_tcpip *st_src,
45
 	       struct sockaddr_tcpip *st_src,
46
 	       struct sockaddr_tcpip *st_dest,
46
 	       struct sockaddr_tcpip *st_dest,
47
 	       uint16_t pshdr_csum ) {
47
 	       uint16_t pshdr_csum ) {
51
 	for ( tcpip = tcpip_protocols; tcpip < tcpip_protocols_end; tcpip++ ) {
51
 	for ( tcpip = tcpip_protocols; tcpip < tcpip_protocols_end; tcpip++ ) {
52
 		if ( tcpip->tcpip_proto == tcpip_proto ) {
52
 		if ( tcpip->tcpip_proto == tcpip_proto ) {
53
 			DBG ( "TCP/IP received %s packet\n", tcpip->name );
53
 			DBG ( "TCP/IP received %s packet\n", tcpip->name );
54
-			return tcpip->rx ( pkb, st_src, st_dest, pshdr_csum );
54
+			return tcpip->rx ( iobuf, st_src, st_dest, pshdr_csum );
55
 		}
55
 		}
56
 	}
56
 	}
57
 
57
 
58
 	DBG ( "Unrecognised TCP/IP protocol %d\n", tcpip_proto );
58
 	DBG ( "Unrecognised TCP/IP protocol %d\n", tcpip_proto );
59
-	free_pkb ( pkb );
59
+	free_iob ( iobuf );
60
 	return -EPROTONOSUPPORT;
60
 	return -EPROTONOSUPPORT;
61
 }
61
 }
62
 
62
 
63
 /** Transmit a TCP/IP packet
63
 /** Transmit a TCP/IP packet
64
  *
64
  *
65
- * @v pkb		Packet buffer
65
+ * @v iobuf		I/O buffer
66
  * @v tcpip_protocol	Transport-layer protocol
66
  * @v tcpip_protocol	Transport-layer protocol
67
  * @v st_dest		Destination address
67
  * @v st_dest		Destination address
68
  * @v netdev		Network device to use if no route found, or NULL
68
  * @v netdev		Network device to use if no route found, or NULL
69
  * @v trans_csum	Transport-layer checksum to complete, or NULL
69
  * @v trans_csum	Transport-layer checksum to complete, or NULL
70
  * @ret rc		Return status code
70
  * @ret rc		Return status code
71
  */
71
  */
72
-int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip_protocol,
72
+int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol,
73
 	       struct sockaddr_tcpip *st_dest, struct net_device *netdev,
73
 	       struct sockaddr_tcpip *st_dest, struct net_device *netdev,
74
 	       uint16_t *trans_csum ) {
74
 	       uint16_t *trans_csum ) {
75
 	struct tcpip_net_protocol *tcpip_net;
75
 	struct tcpip_net_protocol *tcpip_net;
79
 	      tcpip_net < tcpip_net_protocols_end ; tcpip_net++ ) {
79
 	      tcpip_net < tcpip_net_protocols_end ; tcpip_net++ ) {
80
 		if ( tcpip_net->sa_family == st_dest->st_family ) {
80
 		if ( tcpip_net->sa_family == st_dest->st_family ) {
81
 			DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
81
 			DBG ( "TCP/IP sending %s packet\n", tcpip_net->name );
82
-			return tcpip_net->tx ( pkb, tcpip_protocol, st_dest,
82
+			return tcpip_net->tx ( iobuf, tcpip_protocol, st_dest,
83
 					       netdev, trans_csum );
83
 					       netdev, trans_csum );
84
 		}
84
 		}
85
 	}
85
 	}
86
 	
86
 	
87
 	DBG ( "Unrecognised TCP/IP address family %d\n", st_dest->st_family );
87
 	DBG ( "Unrecognised TCP/IP address family %d\n", st_dest->st_family );
88
-	free_pkb ( pkb );
88
+	free_iob ( iobuf );
89
 	return -EAFNOSUPPORT;
89
 	return -EAFNOSUPPORT;
90
 }
90
 }
91
 
91
 

+ 42
- 42
src/net/udp.c View File

4
 #include <byteswap.h>
4
 #include <byteswap.h>
5
 #include <errno.h>
5
 #include <errno.h>
6
 #include <gpxe/tcpip.h>
6
 #include <gpxe/tcpip.h>
7
-#include <gpxe/pkbuff.h>
7
+#include <gpxe/iobuf.h>
8
 #include <gpxe/netdevice.h>
8
 #include <gpxe/netdevice.h>
9
 #include <gpxe/udp.h>
9
 #include <gpxe/udp.h>
10
 
10
 
89
 }
89
 }
90
 
90
 
91
 /**
91
 /**
92
- * Allocate packet buffer for UDP
92
+ * Allocate I/O buffer for UDP
93
  *
93
  *
94
  * @v conn		UDP connection
94
  * @v conn		UDP connection
95
- * @ret pkb		Packet buffer, or NULL
95
+ * @ret iobuf		I/O buffer, or NULL
96
  */
96
  */
97
-static struct pk_buff * udp_alloc_pkb ( struct udp_connection *conn ) {
98
-	struct pk_buff *pkb;
97
+static struct io_buffer * udp_alloc_iob ( struct udp_connection *conn ) {
98
+	struct io_buffer *iobuf;
99
 
99
 
100
-	pkb = alloc_pkb ( UDP_MAX_TXPKB );
101
-	if ( ! pkb ) {
100
+	iobuf = alloc_iob ( UDP_MAX_TXIOB );
101
+	if ( ! iobuf ) {
102
 		DBGC ( conn, "UDP %p cannot allocate buffer of length %d\n",
102
 		DBGC ( conn, "UDP %p cannot allocate buffer of length %d\n",
103
-		       conn, UDP_MAX_TXPKB );
103
+		       conn, UDP_MAX_TXIOB );
104
 		return NULL;
104
 		return NULL;
105
 	}
105
 	}
106
-	pkb_reserve ( pkb, UDP_MAX_HLEN );
107
-	return pkb;
106
+	iob_reserve ( iobuf, UDP_MAX_HLEN );
107
+	return iobuf;
108
 }
108
 }
109
 
109
 
110
 /**
110
 /**
119
 int udp_senddata ( struct udp_connection *conn ) {
119
 int udp_senddata ( struct udp_connection *conn ) {
120
 	int rc;
120
 	int rc;
121
 
121
 
122
-	conn->tx_pkb = udp_alloc_pkb ( conn );
123
-	if ( ! conn->tx_pkb )
122
+	conn->tx_iob = udp_alloc_iob ( conn );
123
+	if ( ! conn->tx_iob )
124
 		return -ENOMEM;
124
 		return -ENOMEM;
125
 
125
 
126
-	rc = conn->udp_op->senddata ( conn, conn->tx_pkb->data, 
127
-				      pkb_tailroom ( conn->tx_pkb ) );
126
+	rc = conn->udp_op->senddata ( conn, conn->tx_iob->data, 
127
+				      iob_tailroom ( conn->tx_iob ) );
128
 	if ( rc != 0 ) {
128
 	if ( rc != 0 ) {
129
 		DBGC ( conn, "UDP %p application could not send packet: %s\n",
129
 		DBGC ( conn, "UDP %p application could not send packet: %s\n",
130
 		       conn, strerror ( rc ) );
130
 		       conn, strerror ( rc ) );
131
 	}
131
 	}
132
 
132
 
133
-	if ( conn->tx_pkb ) {
134
-		free_pkb ( conn->tx_pkb );
135
-		conn->tx_pkb = NULL;
133
+	if ( conn->tx_iob ) {
134
+		free_iob ( conn->tx_iob );
135
+		conn->tx_iob = NULL;
136
 	}
136
 	}
137
 
137
 
138
 	return rc;
138
 	return rc;
152
 		     struct net_device *netdev, const void *data,
152
 		     struct net_device *netdev, const void *data,
153
 		     size_t len ) {
153
 		     size_t len ) {
154
        	struct udp_header *udphdr;
154
        	struct udp_header *udphdr;
155
-	struct pk_buff *pkb;
155
+	struct io_buffer *iobuf;
156
 	int rc;
156
 	int rc;
157
 
157
 
158
-	/* Use precreated packet buffer if one is available */
159
-	if ( conn->tx_pkb ) {
160
-		pkb = conn->tx_pkb;
161
-		conn->tx_pkb = NULL;
158
+	/* Use precreated I/O buffer if one is available */
159
+	if ( conn->tx_iob ) {
160
+		iobuf = conn->tx_iob;
161
+		conn->tx_iob = NULL;
162
 	} else {
162
 	} else {
163
-		pkb = udp_alloc_pkb ( conn );
164
-		if ( ! pkb )
163
+		iobuf = udp_alloc_iob ( conn );
164
+		if ( ! iobuf )
165
 			return -ENOMEM;
165
 			return -ENOMEM;
166
 	}
166
 	}
167
 
167
 
168
 	/* Avoid overflowing TX buffer */
168
 	/* Avoid overflowing TX buffer */
169
-	if ( len > pkb_tailroom ( pkb ) )
170
-		len = pkb_tailroom ( pkb );
169
+	if ( len > iob_tailroom ( iobuf ) )
170
+		len = iob_tailroom ( iobuf );
171
 
171
 
172
 	/* Copy payload */
172
 	/* Copy payload */
173
-	memmove ( pkb_put ( pkb, len ), data, len );
173
+	memmove ( iob_put ( iobuf, len ), data, len );
174
 
174
 
175
 	/*
175
 	/*
176
 	 * Add the UDP header
176
 	 * Add the UDP header
178
 	 * Covert all 16- and 32- bit integers into network btye order before
178
 	 * Covert all 16- and 32- bit integers into network btye order before
179
 	 * sending it over the network
179
 	 * sending it over the network
180
 	 */
180
 	 */
181
-	udphdr = pkb_push ( pkb, sizeof ( *udphdr ) );
181
+	udphdr = iob_push ( iobuf, sizeof ( *udphdr ) );
182
 	udphdr->dest_port = peer->st_port;
182
 	udphdr->dest_port = peer->st_port;
183
 	udphdr->source_port = conn->local_port;
183
 	udphdr->source_port = conn->local_port;
184
-	udphdr->len = htons ( pkb_len ( pkb ) );
184
+	udphdr->len = htons ( iob_len ( iobuf ) );
185
 	udphdr->chksum = 0;
185
 	udphdr->chksum = 0;
186
 	udphdr->chksum = tcpip_chksum ( udphdr, sizeof ( *udphdr ) + len );
186
 	udphdr->chksum = tcpip_chksum ( udphdr, sizeof ( *udphdr ) + len );
187
 
187
 
191
 	       ntohs ( udphdr->len ) );
191
 	       ntohs ( udphdr->len ) );
192
 
192
 
193
 	/* Send it to the next layer for processing */
193
 	/* Send it to the next layer for processing */
194
-	if ( ( rc = tcpip_tx ( pkb, &udp_protocol, peer, netdev,
194
+	if ( ( rc = tcpip_tx ( iobuf, &udp_protocol, peer, netdev,
195
 			       &udphdr->chksum ) ) != 0 ) {
195
 			       &udphdr->chksum ) ) != 0 ) {
196
 		DBGC ( conn, "UDP %p could not transmit packet: %s\n",
196
 		DBGC ( conn, "UDP %p could not transmit packet: %s\n",
197
 		       conn, strerror ( rc ) );
197
 		       conn, strerror ( rc ) );
248
 /**
248
 /**
249
  * Process a received packet
249
  * Process a received packet
250
  *
250
  *
251
- * @v pkb		Packet buffer
251
+ * @v iobuf		I/O buffer
252
  * @v st_src		Partially-filled source address
252
  * @v st_src		Partially-filled source address
253
  * @v st_dest		Partially-filled destination address
253
  * @v st_dest		Partially-filled destination address
254
  * @v pshdr_csum	Pseudo-header checksum
254
  * @v pshdr_csum	Pseudo-header checksum
255
  * @ret rc		Return status code
255
  * @ret rc		Return status code
256
  */
256
  */
257
-static int udp_rx ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
257
+static int udp_rx ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src,
258
 		    struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum ) {
258
 		    struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum ) {
259
-	struct udp_header *udphdr = pkb->data;
259
+	struct udp_header *udphdr = iobuf->data;
260
 	struct udp_connection *conn;
260
 	struct udp_connection *conn;
261
 	size_t ulen;
261
 	size_t ulen;
262
 	uint16_t csum;
262
 	uint16_t csum;
263
 	int rc = 0;
263
 	int rc = 0;
264
 
264
 
265
 	/* Sanity check packet */
265
 	/* Sanity check packet */
266
-	if ( pkb_len ( pkb ) < sizeof ( *udphdr ) ) {
266
+	if ( iob_len ( iobuf ) < sizeof ( *udphdr ) ) {
267
 		DBG ( "UDP packet too short at %d bytes (min %d bytes)\n",
267
 		DBG ( "UDP packet too short at %d bytes (min %d bytes)\n",
268
-		      pkb_len ( pkb ), sizeof ( *udphdr ) );
268
+		      iob_len ( iobuf ), sizeof ( *udphdr ) );
269
 		
269
 		
270
 		rc = -EINVAL;
270
 		rc = -EINVAL;
271
 		goto done;
271
 		goto done;
277
 		rc = -EINVAL;
277
 		rc = -EINVAL;
278
 		goto done;
278
 		goto done;
279
 	}
279
 	}
280
-	if ( ulen > pkb_len ( pkb ) ) {
280
+	if ( ulen > iob_len ( iobuf ) ) {
281
 		DBG ( "UDP length too long at %d bytes (packet is %d bytes)\n",
281
 		DBG ( "UDP length too long at %d bytes (packet is %d bytes)\n",
282
-		      ulen, pkb_len ( pkb ) );
282
+		      ulen, iob_len ( iobuf ) );
283
 		rc = -EINVAL;
283
 		rc = -EINVAL;
284
 		goto done;
284
 		goto done;
285
 	}
285
 	}
286
 	if ( udphdr->chksum ) {
286
 	if ( udphdr->chksum ) {
287
-		csum = tcpip_continue_chksum ( pshdr_csum, pkb->data, ulen );
287
+		csum = tcpip_continue_chksum ( pshdr_csum, iobuf->data, ulen );
288
 		if ( csum != 0 ) {
288
 		if ( csum != 0 ) {
289
 			DBG ( "UDP checksum incorrect (is %04x including "
289
 			DBG ( "UDP checksum incorrect (is %04x including "
290
 			      "checksum field, should be 0000)\n", csum );
290
 			      "checksum field, should be 0000)\n", csum );
297
 	st_src->st_port = udphdr->source_port;
297
 	st_src->st_port = udphdr->source_port;
298
 	st_dest->st_port = udphdr->dest_port;
298
 	st_dest->st_port = udphdr->dest_port;
299
 	conn = udp_demux ( udphdr->dest_port );
299
 	conn = udp_demux ( udphdr->dest_port );
300
-	pkb_unput ( pkb, ( pkb_len ( pkb ) - ulen ) );
301
-	pkb_pull ( pkb, sizeof ( *udphdr ) );
300
+	iob_unput ( iobuf, ( iob_len ( iobuf ) - ulen ) );
301
+	iob_pull ( iobuf, sizeof ( *udphdr ) );
302
 
302
 
303
 	/* Dump debugging information */
303
 	/* Dump debugging information */
304
 	DBGC ( conn, "UDP %p RX %d<-%d len %zd\n", conn,
304
 	DBGC ( conn, "UDP %p RX %d<-%d len %zd\n", conn,
315
 
315
 
316
 	/* Pass data to application */
316
 	/* Pass data to application */
317
 	if ( conn->udp_op->newdata ) {
317
 	if ( conn->udp_op->newdata ) {
318
-		rc = conn->udp_op->newdata ( conn, pkb->data, pkb_len ( pkb ),
318
+		rc = conn->udp_op->newdata ( conn, iobuf->data, iob_len ( iobuf ),
319
 				     st_src, st_dest );
319
 				     st_src, st_dest );
320
 		if ( rc != 0 ) {
320
 		if ( rc != 0 ) {
321
 			DBGC ( conn, "UDP %p application rejected packet: %s\n",
321
 			DBGC ( conn, "UDP %p application rejected packet: %s\n",
327
 	}
327
 	}
328
 
328
 
329
  done:
329
  done:
330
-	free_pkb ( pkb );
330
+	free_iob ( iobuf );
331
 	return rc;
331
 	return rc;
332
 }
332
 }
333
 
333
 

Loading…
Cancel
Save