summaryrefslogtreecommitdiffhomepage
path: root/proto.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-03-29 01:16:59 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-03-29 01:16:59 +0200
commitd5202486636818e3ff48ede9d3e06c886c659c0a (patch)
tree9cefcabc1a153efd38dcb295bf386e4cd5dfc37c /proto.c
parentf62eea9492a669bcf96464e85f04ae5e80190a76 (diff)
add rudimentary protocol handling
Diffstat (limited to 'proto.c')
-rw-r--r--proto.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/proto.c b/proto.c
new file mode 100644
index 0000000..a345b35
--- /dev/null
+++ b/proto.c
@@ -0,0 +1,42 @@
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "netifd.h"
+#include "proto.h"
+
+static void
+default_proto_free(struct interface_proto_state *proto)
+{
+ free(proto);
+}
+
+static int
+default_proto_handler(struct interface_proto_state *proto,
+ enum interface_proto_cmd cmd, bool force)
+{
+ enum interface_event ev;
+
+ switch(cmd) {
+ case PROTO_CMD_SETUP:
+ ev = IFEV_UP;
+ break;
+ case PROTO_CMD_TEARDOWN:
+ ev = IFEV_DOWN;
+ break;
+ default:
+ return -EINVAL;
+ }
+ proto->proto_event(proto, ev);
+ return 0;
+}
+
+struct interface_proto_state *get_default_proto(void)
+{
+ struct interface_proto_state *proto;
+
+ proto = calloc(1, sizeof(*proto));
+ proto->handler = default_proto_handler;
+ proto->free = default_proto_free;
+ return proto;
+}