Skip to content
Draft
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
3 changes: 3 additions & 0 deletions common/lpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ lpm_lookup(const struct lpm *lpm, uint8_t key_size, const uint8_t *key) {
page = ADDR_OF(&value->page);
}

if (value->value == LPM_VALUE_INVALID)
return LPM_VALUE_INVALID;

return LPM_VALUE_GET(value->value);
}

Expand Down
11 changes: 0 additions & 11 deletions common/range_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ range_index_insert(
return 0;
}

static inline void
range_index_remap(
struct range_index *range_index, struct value_table *value_table
) {
uint32_t *values = ADDR_OF(&range_index->values);

for (uint32_t idx = 0; idx < range_index->count; ++idx) {
values[idx] = value_table_get(value_table, 0, values[idx]);
}
}

static inline void
range_index_free(struct range_index *range_index) {
uint64_t capacity = 1 << uint64_log_up(range_index->count);
Expand Down
4 changes: 1 addition & 3 deletions common/remap.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ remap_table_new_key(struct remap_table *table, uint32_t *key) {

static inline int
remap_table_touch(struct remap_table *table, uint32_t key, uint32_t *value) {
int res = 0;
struct remap_item *item = remap_table_item(table, key);

if (item->gen != table->gen) {
Expand All @@ -218,7 +217,6 @@ remap_table_touch(struct remap_table *table, uint32_t key, uint32_t *value) {
return -1;
item->gen = table->gen;
item->value = new_key;
res = 1;
}

struct remap_item *new_item = remap_table_item(table, item->value);
Expand All @@ -235,7 +233,7 @@ remap_table_touch(struct remap_table *table, uint32_t key, uint32_t *value) {
table->free_list = key;
}

return res;
return 0;
}

/*
Expand Down
14 changes: 7 additions & 7 deletions common/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

struct value_table {
struct memory_context *memory_context;
uint32_t h_dim;
uint32_t v_dim;
uint32_t h_dim;
uint32_t **values;
};

Expand Down Expand Up @@ -48,13 +48,13 @@ static inline int
value_table_init(
struct value_table *value_table,
struct memory_context *memory_context,
uint32_t h_dim,
uint32_t v_dim
uint32_t v_dim,
uint32_t h_dim
) {
SET_OFFSET_OF(&value_table->memory_context, memory_context);

value_table->h_dim = h_dim;
value_table->v_dim = v_dim;
value_table->h_dim = h_dim;

uint64_t value_count = h_dim;
value_count *= v_dim;
Expand Down Expand Up @@ -89,7 +89,7 @@ value_table_init(

static inline uint32_t *
value_table_get_ptr(
struct value_table *value_table, uint32_t h_idx, uint32_t v_idx
const struct value_table *value_table, uint32_t v_idx, uint32_t h_idx
) {
uint32_t **values = ADDR_OF(&value_table->values);
uint64_t idx = (v_idx * value_table->h_dim) + h_idx;
Expand All @@ -100,9 +100,9 @@ value_table_get_ptr(

static inline uint32_t
value_table_get(
struct value_table *value_table, uint32_t h_idx, uint32_t v_idx
const struct value_table *value_table, uint32_t v_idx, uint32_t h_idx
) {
return *value_table_get_ptr(value_table, h_idx, v_idx);
return *value_table_get_ptr(value_table, v_idx, h_idx);
}

static inline void
Expand Down
27 changes: 27 additions & 0 deletions filter/classifiers/device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "common/container_of.h"
#include "common/memory.h"
#include "common/value.h"

#include "filter/filter.h"

struct filter_query_attr_device {
struct filter_query_attr attr;
struct value_table value_table;
};

static inline void
filter_query_attr_device_free(
struct memory_context *memory_context, struct filter_query_attr *attr
) {
struct filter_query_attr_device *device_attr =
container_of(attr, struct filter_query_attr_device, attr);

value_table_free(&device_attr->value_table);
memory_bfree(
memory_context,
device_attr,
sizeof(struct filter_query_attr_device)
);
}
24 changes: 24 additions & 0 deletions filter/classifiers/net4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "common/container_of.h"
#include "common/lpm.h"
#include "common/memory.h"
#include "filter/filter.h"

struct filter_query_attr_net4 {
struct filter_query_attr attr;
struct lpm lpm;
};

static inline void
filter_query_attr_net4_free(
struct memory_context *memory_context, struct filter_query_attr *attr
) {
struct filter_query_attr_net4 *net4_attr =
container_of(attr, struct filter_query_attr_net4, attr);

lpm_free(&net4_attr->lpm);
memory_bfree(
memory_context, net4_attr, sizeof(struct filter_query_attr_net4)
);
}
22 changes: 20 additions & 2 deletions filter/classifiers/net6.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
#pragma once

#include "common/container_of.h"
#include "common/lpm.h"
#include "common/value.h"
#include "filter/filter.h"

struct net6_classifier {
struct filter_query_attr_net6 {
struct filter_query_attr attr;
struct lpm hi;
struct lpm lo;
struct value_table comb;
};
};

static inline void
filter_query_attr_net6_free(
struct memory_context *memory_context, struct filter_query_attr *attr
) {
struct filter_query_attr_net6 *net6_attr =
container_of(attr, struct filter_query_attr_net6, attr);

lpm_free(&net6_attr->hi);
lpm_free(&net6_attr->lo);
value_table_free(&net6_attr->comb);
memory_bfree(
memory_context, net6_attr, sizeof(struct filter_query_attr_net6)
);
}
23 changes: 23 additions & 0 deletions filter/classifiers/port.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "common/container_of.h"

#include "filter/filter.h"

struct filter_query_attr_port {
struct filter_query_attr attr;
struct value_table value_table;
};

static inline void
filter_query_attr_port_free(
struct memory_context *memory_context, struct filter_query_attr *attr
) {
struct filter_query_attr_port *port_attr =
container_of(attr, struct filter_query_attr_port, attr);

value_table_free(&port_attr->value_table);
memory_bfree(
memory_context, port_attr, sizeof(struct filter_query_attr_port)
);
}
26 changes: 23 additions & 3 deletions filter/classifiers/proto_range.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
#pragma once

#include "common/container_of.h"
#include "common/value.h"

#include "filter/filter.h"

#include "segments.h"

struct proto_range_classifier {
struct value_table table;
struct filter_query_attr_proto_range {
struct filter_query_attr attr;
struct value_table value_table;
};

static inline void
filter_query_attr_proto_range_free(
struct memory_context *memory_context, struct filter_query_attr *attr
) {
struct filter_query_attr_proto_range *proto_range_attr =
container_of(attr, struct filter_query_attr_proto_range, attr);

value_table_free(&proto_range_attr->value_table);
memory_bfree(
memory_context,
proto_range_attr,
sizeof(struct filter_query_attr_proto_range)
);
}

struct proto_range_fast_classifier {
struct segment_u16_classifier classifier;
};
};
23 changes: 23 additions & 0 deletions filter/classifiers/vlan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "common/container_of.h"

#include "filter/filter.h"

struct filter_query_attr_vlan {
struct filter_query_attr attr;
struct value_table value_table;
};

static inline void
filter_query_attr_vlan_free(
struct memory_context *memory_context, struct filter_query_attr *attr
) {
struct filter_query_attr_vlan *vlan_attr =
container_of(attr, struct filter_query_attr_vlan, attr);

value_table_free(&vlan_attr->value_table);
memory_bfree(
memory_context, vlan_attr, sizeof(struct filter_query_attr_vlan)
);
}
Loading
Loading