Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement sk_buff #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 21 additions & 52 deletions pkg/list/list.go → pkg/skb/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,34 @@
* SOFTWARE.
*/

package list

// ProbeList is Linked list routines
type ProbeList struct {
next, prev *ProbeList
}

// ProbeListInit Initialises a new list (A Linked list implementation)
// \param[in] head A probe_list/linked list context
func ProbeListInit(head *ProbeList) {

}
package skb

// ProbeListAdd take the value for the new node and adds that to the linklist chain.
//
// \param[in] new A probe list context to refer new node to be added
// \param[in] head A probe list context
func ProbeListAdd(new *ProbeList, head *ProbeList) {

func ProbeListAdd(newsk *ProbeSkbuff, prev *ProbeSkbuff, next *ProbeSkbuff, list *probeSkbuffHead) {
newsk.next = next
newsk.prev = prev
next.prev = newsk
prev.next = newsk
list.qlen++
}

// ProbeListDelete delete's a probe list node according to the node context passed.
//
// \param[in] ctx A probe list context
func ProbeListDelete(*ProbeList) {

}

// ProbeListAddEnd Take the value for the new node and attaches that to the end of the linklist chain.
//
// \param[in] new A probe list context to refer new node that need to be added
// \param[in] head A probe list context
func ProbeListAddEnd(new *ProbeList, head *ProbeList) {
func ProbeListDelete(skb *ProbeSkbuff, list *probeSkbuffHead) {
var next, prev *ProbeSkbuff

list.qlen--
next = skb.next
prev = skb.prev
skb.next = nil
skb.prev = nil
next.prev = prev
prev.next = next
}

// ProbeListCheckEmpty checks whether the list is empty. Returns True if the list is empty.
//
// \param[in] head A probe list context
func ProbeListCheckEmpty(head *ProbeList) {

}

func _listHead() {

}

func _listEntry() {

}

func _listFirstEntry() {

}

func _listEach() {

}

func _listForEachSafe() {

func ProbeListCheckEmpty(head *probeSkbuffHead) int {
if head.next == nil {
return 1
}
return 0
}
13 changes: 13 additions & 0 deletions pkg/skb/sk_buff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# sk_buff

The socket buffer, or "SKB", is the most fundamental data structure in the Linux networking code. Every packet sent or received is handled using this data structure.

![sk_buff representation](http://www.embeddedlinux.org.cn/linux_net/0596002556/images/understandlni_0201.jpg)

The above image is a simple representation of the `sk_buff` data structure coupled with the `sk_buff_head` structure. The SKBs are stored on a list whose head is implemented by `struct sk_buff_head`. Next we have queue management functions that which are done using the `sk_buff_head` which has pointers pointing to the first and last `sk_buff` in the list.

## Resources
* Read this for an overview on SKB. [https://wiki.linuxfoundation.org/networking/sk_buff](https://wiki.linuxfoundation.org/networking/sk_buff)

* Read this to understand how the SKB is a doubly linked list and a queue implemented together. [http://vger.kernel.org/~davem/skb_list.html](http://vger.kernel.org/~davem/skb_list.html)
* Read this to get an overview on the various fields in `struct sk_buff`. [http://vger.kernel.org/~davem/skb.html](http://vger.kernel.org/~davem/skb.html)
101 changes: 61 additions & 40 deletions pkg/skb/skbuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,81 +23,102 @@
* SOFTWARE.
*/

package skb

import (
linkedList "github.com/Aniketh01/probe/pkg/list"
)

// ProbeSkbuff sk_buff routines
type ProbeSkbuff struct {
list linkedList.ProbeList
head, end, data, tail, payload *uint8
protocol uint16
len, dlen, seq, endseq uint32
refcount int
}

type probeSkbuffHead struct {
list linkedList.ProbeList
qlen uint32
}

// ProbeSkbuffInit Initialises a sk_buff.
func ProbeSkbuffInit(size uint) *ProbeSkbuff {
}
package skb

func ProbeSkbuffPeek(head *probeSkbuffHead) *ProbeSkbuff {
type probeSkbuffHead struct {
next, prev *ProbeSkbuff
qlen uint
}

// ProbeSkbuff is the implementation of sk_buff
type ProbeSkbuff struct {
next, prev *ProbeSkbuff
head, end, data, tail, payload uint
protocol uint
len, dlen, seq, endseq uint
refcount int
}

func ProbeSkBuffDeinit(skb *ProbeSkbuff) {
// ProbeSkbuffInit initialises a sk_buff
func ProbeSkbuffInit(size uint) *ProbeSkbuff {
return &ProbeSkbuff{
len: size,
}
}

// ProbeSkbuffPeek returns nil for an empty list or a pointer to the head element
func ProbeSkbuffPeek(head *probeSkbuffHead) *ProbeSkbuff {
skb := head.next
if skb == nil {
return nil
}
return skb
}

func ProbeSkbuffPush(skb *ProbeSkbuff, len uint) uint8 {
func ProbeSkbuffDeinit(skb *ProbeSkbuff) {
skb = nil
}

func ProbeSkbuffPush(skb *ProbeSkbuff, len uint) uint {
skb.data -= len
skb.len += len
return skb.data
}

func ProbeSkbuffReserve(skb *ProbeSkbuff, len uint) {

skb.data += len
skb.tail += len
}

func ProbeSkbuffResetHead(skb *ProbeSkbuff) {

skb.head = 0
}

func ProbeSkbuffGetHead(skb *ProbeSkbuff) uint8 {

func ProbeSkbuffGetHead(skb *ProbeSkbuff) uint {
return skb.head
}

/*
* Probe sk buff datagram/head queue function design
*/
*/

func ProbeSkbuffQueueInit(head *probeSkbuffHead) {

head.next = nil
head.prev = nil
head.qlen = 0
}

func ProbSkbuffQueueDeinit(head *probeSkbuffHead) {
head.next = nil
head.prev = nil
head.qlen = 0
}

// ProbeSkbuffDequeue is used to remove the first SKB from the queue
func ProbeSkbuffDequeue(head *probeSkbuffHead) *ProbeSkbuff {

skb := ProbeSkbuffPeek(head)
if skb != nil {
ProbeListDelete(skb, head)
}
return skb
}

func ProbeSkbuffQueueAdd(head *probeSkbuffHead, new *ProbeSkbuff, next *ProbeSkbuff) {

// ProbeSkbuffQueueAddBefore is used to add 'new' SKB before 'next' SKB
func ProbeSkbuffQueueAddBefore(head *probeSkbuffHead, new *ProbeSkbuff, next *ProbeSkbuff) {
ProbeListAdd(new, next.prev, next, head)
}

// ProbeSkbuffQueueAddEnd is used to add 'new' SKB to the end of the list
func ProbeSkbuffQueueAddEnd(head *probeSkbuffHead, new *ProbeSkbuff) {

ProbeSkbuffQueueAddBefore(head, new, head.prev)
}

// ProbeSkbuffQueueCheckEmpty return 1 if the queue is empty, 0 otherwise
func ProbeSkbuffQueueCheckEmpty(head *probeSkbuffHead) int {

return ProbeListCheckEmpty(head)
}

func ProbeSkbuffQueueGetLen(head *probeSkbuffHead) uint32 {

}
// ProbeSkbuffQueueGetLen returns the length of the sk_buff queue
func ProbeSkbuffQueueGetLen(head *probeSkbuffHead) uint {
return head.qlen
}