move protocol flags to the handler, add a pointer to the handler in the proto state...
authorFelix Fietkau <nbd@openwrt.org>
Sun, 11 Sep 2011 10:31:50 +0000 (12:31 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 11 Sep 2011 10:31:50 +0000 (12:31 +0200)
proto-shell.c
proto-static.c
proto.c
proto.h

index 281debc..d014b43 100644 (file)
@@ -111,7 +111,7 @@ proto_shell_attach(const struct proto_handler *h, struct interface *iface,
 
        memcpy(state->config, attr, blob_pad_len(attr));
        state->proto.free = proto_shell_free;
 
        memcpy(state->config, attr, blob_pad_len(attr));
        state->proto.free = proto_shell_free;
-       state->proto.handler = proto_shell_handler;
+       state->proto.cb = proto_shell_handler;
        state->handler = container_of(h, struct proto_shell_handler, proto);
 
        return &state->proto;
        state->handler = container_of(h, struct proto_shell_handler, proto);
 
        return &state->proto;
index 3734f09..bbe304b 100644 (file)
@@ -241,8 +241,7 @@ static_attach(const struct proto_handler *h, struct interface *iface,
 
        memcpy(state->config, attr, blob_pad_len(attr));
        state->proto.free = static_free;
 
        memcpy(state->config, attr, blob_pad_len(attr));
        state->proto.free = static_free;
-       state->proto.handler = static_handler;
-       state->proto.flags = PROTO_FLAG_IMMEDIATE;
+       state->proto.cb = static_handler;
 
        return &state->proto;
 
 
        return &state->proto;
 
@@ -253,6 +252,7 @@ error:
 
 static struct proto_handler static_proto = {
        .name = "static",
 
 static struct proto_handler static_proto = {
        .name = "static",
+       .flags = PROTO_FLAG_IMMEDIATE,
        .config_params = &static_attr_list,
        .attach = static_attach,
 };
        .config_params = &static_attr_list,
        .attach = static_attach,
 };
diff --git a/proto.c b/proto.c
index 278fb0c..d8f16b3 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -48,14 +48,14 @@ default_proto_attach(const struct proto_handler *h,
 
        proto = calloc(1, sizeof(*proto));
        proto->free = default_proto_free;
 
        proto = calloc(1, sizeof(*proto));
        proto->free = default_proto_free;
-       proto->flags = PROTO_FLAG_IMMEDIATE;
-       proto->handler = no_proto_handler;
+       proto->cb = no_proto_handler;
 
        return proto;
 }
 
 static const struct proto_handler no_proto = {
        .name = "none",
 
        return proto;
 }
 
 static const struct proto_handler no_proto = {
        .name = "none",
+       .flags = PROTO_FLAG_IMMEDIATE,
        .attach = default_proto_attach,
 };
 
        .attach = default_proto_attach,
 };
 
@@ -84,9 +84,10 @@ proto_init_interface(struct interface *iface, struct blob_attr *attr)
 
        if (!state) {
                state = no_proto.attach(&no_proto, iface, attr);
 
        if (!state) {
                state = no_proto.attach(&no_proto, iface, attr);
-               state->handler = invalid_proto_handler;
+               state->cb = invalid_proto_handler;
        }
 
        }
 
+       state->handler = proto;
        interface_set_proto_state(iface, state);
 }
 
        interface_set_proto_state(iface, state);
 }
 
@@ -114,8 +115,8 @@ interface_proto_event(struct interface_proto_state *proto,
        enum interface_event ev;
        int ret;
 
        enum interface_event ev;
        int ret;
 
-       ret = proto->handler(proto, cmd, force);
-       if (ret || !(proto->flags & PROTO_FLAG_IMMEDIATE))
+       ret = proto->cb(proto, cmd, force);
+       if (ret || !(proto->handler->flags & PROTO_FLAG_IMMEDIATE))
                goto out;
 
        switch(cmd) {
                goto out;
 
        switch(cmd) {
diff --git a/proto.h b/proto.h
index 273ec94..e066b43 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -17,17 +17,18 @@ enum interface_proto_cmd {
 
 enum {
        PROTO_FLAG_IMMEDIATE = (1 << 0),
 
 enum {
        PROTO_FLAG_IMMEDIATE = (1 << 0),
+       PROTO_FLAG_NODEV = (1 << 1),
 };
 
 struct interface_proto_state {
 };
 
 struct interface_proto_state {
+       const struct proto_handler *handler;
        struct interface *iface;
        struct interface *iface;
-       unsigned int flags;
 
        /* filled in by the protocol user */
        void (*proto_event)(struct interface_proto_state *, enum interface_proto_event ev);
 
        /* filled in by the protocol handler */
 
        /* filled in by the protocol user */
        void (*proto_event)(struct interface_proto_state *, enum interface_proto_event ev);
 
        /* filled in by the protocol handler */
-       int (*handler)(struct interface_proto_state *, enum interface_proto_cmd cmd, bool force);
+       int (*cb)(struct interface_proto_state *, enum interface_proto_cmd cmd, bool force);
        void (*free)(struct interface_proto_state *);
 };
 
        void (*free)(struct interface_proto_state *);
 };
 
@@ -35,6 +36,8 @@ struct interface_proto_state {
 struct proto_handler {
        struct avl_node avl;
 
 struct proto_handler {
        struct avl_node avl;
 
+       unsigned int flags;
+
        const char *name;
        const struct config_param_list *config_params;
 
        const char *name;
        const struct config_param_list *config_params;