MEDIUM: protocol: use a family array to index the protocol handlers
Instead of walking over a list, we now have a direct mapping between
protocol families and their respective handlers. This will allow fast
lookups.
diff --git a/include/proto/protocol.h b/include/proto/protocol.h
index 1842faf..13a3c0a 100644
--- a/include/proto/protocol.h
+++ b/include/proto/protocol.h
@@ -22,8 +22,11 @@
#ifndef _PROTO_PROTOCOL_H
#define _PROTO_PROTOCOL_H
+#include <sys/socket.h>
#include <types/protocol.h>
+extern struct protocol *__protocol_by_family[AF_MAX];
+
/* Registers the protocol <proto> */
void protocol_register(struct protocol *proto);
@@ -51,7 +54,12 @@
int protocol_enable_all(void);
/* returns the protocol associated to family <family> or NULL if not found */
-struct protocol *protocol_by_family(int family);
+static inline struct protocol *protocol_by_family(int family)
+{
+ if (family >= 0 && family < AF_MAX)
+ return __protocol_by_family[family];
+ return NULL;
+}
#endif /* _PROTO_PROTOCOL_H */