Browse Source

First version, based on the concepts in linux/skbuff.h

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
0864a73347
1 changed files with 80 additions and 0 deletions
  1. 80
    0
      src/include/gpxe/pkbuff.h

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

@@ -0,0 +1,80 @@
1
+#ifndef _PKBUFF_H
2
+#define _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
+
16
+/** A packet buffer
17
+ *
18
+ * This structure is used to represent a network packet within gPXE.
19
+ */
20
+struct pk_buff {
21
+	/** Head of the buffer */
22
+	void *head;
23
+	/** Start of data */
24
+	void *data;
25
+	/** End of data */
26
+	void *tail;
27
+	/** End of the buffer */
28
+        void *end;
29
+};
30
+
31
+/**
32
+ * Add data to start of packet buffer
33
+ *
34
+ * @v pkb	Packet buffer
35
+ * @v len	Length to add
36
+ * @ret data	Pointer to new start of buffer
37
+ */
38
+static inline void * pkb_push ( struct pk_buff *pkb, size_t len ) {
39
+	pkb->data -= len;
40
+	assert ( pkb->data >= pkb->head );
41
+	return pkb->data;
42
+}
43
+
44
+/**
45
+ * Remove data from start of packet buffer
46
+ *
47
+ * @v pkb	Packet buffer
48
+ * @v len	Length to remove
49
+ * @ret data	Pointer to new start of buffer
50
+ */
51
+static inline void * pkb_pull ( struct pk_buff *pkb, size_t len ) {
52
+	pkb->data += len;
53
+	assert ( pkb->data >= pkb->tail );
54
+	return pkb->data;
55
+}
56
+
57
+/**
58
+ * Add data to end of packet buffer
59
+ *
60
+ * @v pkb	Packet buffer
61
+ * @v len	Length to add
62
+ * @ret data	Pointer to newly added space
63
+ */
64
+static inline void * pkb_put ( struct pk_buff *pkb, size_t len ) {
65
+	void *old_tail = pkb->tail;
66
+	pkb->tail += len;
67
+	assert ( pkb->tail <= pkb->end );
68
+	return old_tail;
69
+}
70
+
71
+/**
72
+ * Empty a packet buffer
73
+ *
74
+ * @v pkb	Packet buffer
75
+ */
76
+static inline void pkb_empty ( struct pk_buff *pkb ) {
77
+	pkb->tail = pkb->data;
78
+}
79
+
80
+#endif /* _PKBUFF_H */

Loading…
Cancel
Save