2006-04-24 17:33:06 +02:00
|
|
|
#ifndef _GPXE_PKBUFF_H
|
|
|
|
#define _GPXE_PKBUFF_H
|
2006-04-18 19:47:01 +02:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Packet buffers
|
|
|
|
*
|
|
|
|
* Packet buffers are used to contain network packets. Methods are
|
|
|
|
* provided for appending, prepending, etc. data.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <assert.h>
|
2006-04-24 17:33:06 +02:00
|
|
|
#include <gpxe/list.h>
|
|
|
|
|
2006-04-25 14:11:36 +02:00
|
|
|
/**
|
|
|
|
* Packet buffer alignment
|
|
|
|
*
|
|
|
|
* Packet buffers allocated via alloc_pkb() are guaranteed to be
|
|
|
|
* physically aligned to this boundary. Some cards cannot DMA across
|
|
|
|
* a 4kB boundary. With a standard Ethernet MTU, aligning to a 2kB
|
|
|
|
* boundary is sufficient to guarantee no 4kB boundary crossings. For
|
|
|
|
* a jumbo Ethernet MTU, a packet may be larger than 4kB anyway.
|
|
|
|
*/
|
|
|
|
#define PKBUFF_ALIGN 2048
|
|
|
|
|
2006-05-27 15:39:45 +02:00
|
|
|
/**
|
|
|
|
* Minimum packet buffer length
|
|
|
|
*
|
|
|
|
* alloc_pkb() will round up the allocated length to this size if
|
|
|
|
* necessary. This is used on behalf of hardware that is not capable
|
|
|
|
* of auto-padding.
|
|
|
|
*/
|
|
|
|
#define PKB_ZLEN 64
|
|
|
|
|
2006-04-18 19:47:01 +02:00
|
|
|
/** A packet buffer
|
|
|
|
*
|
|
|
|
* This structure is used to represent a network packet within gPXE.
|
|
|
|
*/
|
|
|
|
struct pk_buff {
|
2006-06-18 00:36:27 +02:00
|
|
|
/** List of which this buffer is a member */
|
|
|
|
struct list_head list;
|
|
|
|
|
2006-04-28 16:09:31 +02:00
|
|
|
/** Start of the buffer */
|
2006-04-18 19:47:01 +02:00
|
|
|
void *head;
|
|
|
|
/** Start of data */
|
|
|
|
void *data;
|
|
|
|
/** End of data */
|
|
|
|
void *tail;
|
|
|
|
/** End of the buffer */
|
|
|
|
void *end;
|
2006-04-24 17:33:06 +02:00
|
|
|
};
|
2006-04-19 13:32:24 +02:00
|
|
|
|
2006-04-24 21:34:51 +02:00
|
|
|
/**
|
|
|
|
* Reserve space at start of packet buffer
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
|
|
|
* @v len Length to reserve
|
|
|
|
* @ret data Pointer to new start of buffer
|
|
|
|
*/
|
|
|
|
static inline void * pkb_reserve ( struct pk_buff *pkb, size_t len ) {
|
|
|
|
pkb->data += len;
|
|
|
|
pkb->tail += len;
|
|
|
|
assert ( pkb->tail <= pkb->end );
|
|
|
|
return pkb->data;
|
|
|
|
}
|
|
|
|
|
2006-04-18 19:47:01 +02:00
|
|
|
/**
|
|
|
|
* Add data to start of packet buffer
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
|
|
|
* @v len Length to add
|
|
|
|
* @ret data Pointer to new start of buffer
|
|
|
|
*/
|
|
|
|
static inline void * pkb_push ( struct pk_buff *pkb, size_t len ) {
|
|
|
|
pkb->data -= len;
|
|
|
|
assert ( pkb->data >= pkb->head );
|
|
|
|
return pkb->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove data from start of packet buffer
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
|
|
|
* @v len Length to remove
|
|
|
|
* @ret data Pointer to new start of buffer
|
|
|
|
*/
|
|
|
|
static inline void * pkb_pull ( struct pk_buff *pkb, size_t len ) {
|
|
|
|
pkb->data += len;
|
2006-04-28 16:09:31 +02:00
|
|
|
assert ( pkb->data <= pkb->tail );
|
2006-04-18 19:47:01 +02:00
|
|
|
return pkb->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add data to end of packet buffer
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
|
|
|
* @v len Length to add
|
|
|
|
* @ret data Pointer to newly added space
|
|
|
|
*/
|
|
|
|
static inline void * pkb_put ( struct pk_buff *pkb, size_t len ) {
|
|
|
|
void *old_tail = pkb->tail;
|
|
|
|
pkb->tail += len;
|
|
|
|
assert ( pkb->tail <= pkb->end );
|
|
|
|
return old_tail;
|
|
|
|
}
|
|
|
|
|
2006-04-19 03:54:24 +02:00
|
|
|
/**
|
|
|
|
* Remove data from end of packet buffer
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
|
|
|
* @v len Length to remove
|
|
|
|
*/
|
|
|
|
static inline void pkb_unput ( struct pk_buff *pkb, size_t len ) {
|
|
|
|
pkb->tail -= len;
|
|
|
|
assert ( pkb->tail >= pkb->data );
|
|
|
|
}
|
|
|
|
|
2006-04-18 19:47:01 +02:00
|
|
|
/**
|
|
|
|
* Empty a packet buffer
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
|
|
|
*/
|
|
|
|
static inline void pkb_empty ( struct pk_buff *pkb ) {
|
|
|
|
pkb->tail = pkb->data;
|
|
|
|
}
|
|
|
|
|
2006-04-19 03:54:24 +02:00
|
|
|
/**
|
|
|
|
* Calculate length of data in a packet buffer
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
|
|
|
* @ret len Length of data in buffer
|
|
|
|
*/
|
|
|
|
static inline size_t pkb_len ( struct pk_buff *pkb ) {
|
|
|
|
return ( pkb->tail - pkb->data );
|
|
|
|
}
|
|
|
|
|
2006-07-19 20:16:48 +02:00
|
|
|
/**
|
2007-01-09 21:56:31 +01:00
|
|
|
* Calculate available space at start of a packet buffer
|
2006-07-19 20:16:48 +02:00
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
2007-01-09 21:56:31 +01:00
|
|
|
* @ret len Length of data available at start of buffer
|
2006-07-19 20:16:48 +02:00
|
|
|
*/
|
2007-01-09 21:56:31 +01:00
|
|
|
static inline size_t pkb_headroom ( struct pk_buff *pkb ) {
|
|
|
|
return ( pkb->data - pkb->head );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate available space at end of a packet buffer
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
|
|
|
* @ret len Length of data available at end of buffer
|
|
|
|
*/
|
|
|
|
static inline size_t pkb_tailroom ( struct pk_buff *pkb ) {
|
2006-07-19 20:16:48 +02:00
|
|
|
return ( pkb->end - pkb->tail );
|
|
|
|
}
|
|
|
|
|
2006-04-24 17:33:06 +02:00
|
|
|
extern struct pk_buff * alloc_pkb ( size_t len );
|
|
|
|
extern void free_pkb ( struct pk_buff *pkb );
|
2007-01-11 06:25:50 +01:00
|
|
|
extern void pkb_pad ( struct pk_buff *pkb, size_t min_len );
|
2006-04-24 17:33:06 +02:00
|
|
|
|
|
|
|
#endif /* _GPXE_PKBUFF_H */
|