2006-04-24 15:33:06 +00:00
|
|
|
#ifndef _GPXE_PKBUFF_H
|
|
|
|
#define _GPXE_PKBUFF_H
|
2006-04-18 17:47:01 +00: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 15:33:06 +00:00
|
|
|
#include <gpxe/list.h>
|
|
|
|
|
|
|
|
struct net_protocol;
|
|
|
|
struct ll_protocol;
|
2006-04-18 17:47:01 +00:00
|
|
|
|
2006-04-25 12:11:36 +00: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-04-18 17:47:01 +00:00
|
|
|
/** A packet buffer
|
|
|
|
*
|
|
|
|
* This structure is used to represent a network packet within gPXE.
|
|
|
|
*/
|
|
|
|
struct pk_buff {
|
2006-04-28 14:09:31 +00:00
|
|
|
/** Start of the buffer */
|
2006-04-18 17:47:01 +00:00
|
|
|
void *head;
|
|
|
|
/** Start of data */
|
|
|
|
void *data;
|
|
|
|
/** End of data */
|
|
|
|
void *tail;
|
|
|
|
/** End of the buffer */
|
|
|
|
void *end;
|
2006-04-19 11:32:24 +00:00
|
|
|
|
2006-04-24 15:33:06 +00:00
|
|
|
/** List of which this buffer is a member */
|
|
|
|
struct list_head list;
|
2006-04-19 11:32:24 +00:00
|
|
|
|
2006-04-24 15:33:06 +00:00
|
|
|
/** The network-layer protocol */
|
|
|
|
struct net_protocol *net_protocol;
|
|
|
|
/** The link-layer protocol */
|
|
|
|
struct ll_protocol *ll_protocol;
|
|
|
|
};
|
2006-04-19 11:32:24 +00:00
|
|
|
|
2006-04-24 19:34:51 +00: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 17:47:01 +00: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 14:09:31 +00:00
|
|
|
assert ( pkb->data <= pkb->tail );
|
2006-04-18 17:47:01 +00: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 01:54:24 +00: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 17:47:01 +00: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 01:54:24 +00: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-04-24 15:33:06 +00:00
|
|
|
extern struct pk_buff * alloc_pkb ( size_t len );
|
|
|
|
extern void free_pkb ( struct pk_buff *pkb );
|
|
|
|
|
|
|
|
#endif /* _GPXE_PKBUFF_H */
|