summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--trafgen_proto.c19
-rw-r--r--trafgen_proto.h3
2 files changed, 9 insertions, 13 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c
index f55c1b7..8baacbe 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -27,7 +27,7 @@ struct ctx {
};
static struct ctx ctx;
-static struct proto_hdr *registered;
+static const struct proto_hdr *registered[__PROTO_MAX];
struct proto_hdr *proto_lower_header(struct proto_hdr *hdr)
{
@@ -52,21 +52,16 @@ uint8_t *proto_header_ptr(struct proto_hdr *hdr)
return &packet_get(hdr->pkt_id)->payload[hdr->pkt_offset];
}
-static struct proto_hdr *proto_header_by_id(enum proto_id id)
+static const struct proto_hdr *proto_header_by_id(enum proto_id id)
{
- struct proto_hdr *p = registered;
-
- for (; p; p = p->next)
- if (p->id == id)
- return p;
-
- panic("Can't lookup proto by id %u\n", id);
+ bug_on(id >= __PROTO_MAX);
+ return registered[id];
}
void proto_header_register(struct proto_hdr *hdr)
{
- hdr->next = registered;
- registered = hdr;
+ bug_on(hdr->id >= __PROTO_MAX);
+ registered[hdr->id] = hdr;
hdr->fields = NULL;
hdr->fields_count = 0;
@@ -128,7 +123,7 @@ bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid)
struct proto_hdr *proto_header_init(enum proto_id pid)
{
struct proto_hdr **headers = current_packet()->headers;
- struct proto_hdr *hdr = proto_header_by_id(pid);
+ const struct proto_hdr *hdr = proto_header_by_id(pid);
struct proto_hdr *new_hdr;
bug_on(current_packet()->headers_count >= PROTO_MAX_LAYERS);
diff --git a/trafgen_proto.h b/trafgen_proto.h
index f25078a..a66f8d3 100644
--- a/trafgen_proto.h
+++ b/trafgen_proto.h
@@ -6,7 +6,7 @@
#include <stdbool.h>
enum proto_id {
- PROTO_NONE,
+ PROTO_NONE = 0,
PROTO_ETH,
PROTO_VLAN,
PROTO_ARP,
@@ -17,6 +17,7 @@ enum proto_id {
PROTO_ICMP6,
PROTO_UDP,
PROTO_TCP,
+ __PROTO_MAX,
};
enum proto_layer {