Skip to content
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
8 changes: 4 additions & 4 deletions dataplane/forwarding/fwdtable/prefix/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (t *Table) match(in []byte) (*key, fwdaction.Actions) {

// Strip out the prefix and check if the 0 or 1 child is a prefix for
// the new key.
key.TrimPrefix(curr.prefix)
key = key.TrimPrefix(curr.prefix)
curr = curr.child[key.Bit(0)]
if curr == nil {
break
Expand All @@ -160,7 +160,7 @@ func (t *Table) add(pre *key, actions fwdaction.Actions) {
}

// Strip out the prefix and determine the next level based on the 0th bit.
key.TrimPrefix(curr.prefix)
key = key.TrimPrefix(curr.prefix)
child := curr.child[key.Bit(0)]

// If the child does not exist, add the new level for the result.
Expand All @@ -183,7 +183,7 @@ func (t *Table) add(pre *key, actions fwdaction.Actions) {
// common prefix.
p := prefixKey(child.prefix, key)
curr = newLevel(p, curr)
child.prefix.TrimPrefix(p)
child.prefix = child.prefix.TrimPrefix(p)
curr.child[child.prefix.Bit(0)] = child
child.parent = curr
}
Expand All @@ -205,7 +205,7 @@ func (t *Table) remove(prefix *key) error {

// Strip out the prefix and check if the 0 or 1 child is a prefix for
// the new key.
key.TrimPrefix(curr.prefix)
key = key.TrimPrefix(curr.prefix)
if curr = curr.child[key.Bit(0)]; curr == nil {
return fmt.Errorf("prefix: Unable to find entry for prefix %v", key)
}
Expand Down
11 changes: 7 additions & 4 deletions dataplane/forwarding/fwdtable/prefix/prefixkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ func (s *key) Set(bitpos int, v byte) {
s.bytes.set(s.bitStart+bitpos, v)
}

// TrimPrefix removes a key which is known to be a prefix.
func (s *key) TrimPrefix(q *key) {
s.bitCount -= q.bitCount
s.bitStart += q.bitCount
// TrimPrefix removes a key which is known to be a prefix and returns a new key.
func (s *key) TrimPrefix(q *key) *key {
return &key{
bytes: s.bytes,
bitCount: s.bitCount - q.bitCount,
bitStart: s.bitStart + q.bitCount,
}
}

// BitCount returns the number of bits in the key.
Expand Down