diff options
author | Felix Fietkau <nbd@openwrt.org> | 2011-09-11 12:31:50 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2011-09-11 12:31:50 +0200 |
commit | bbfa8c18c8ae086b6fd941e950c466f25c134c17 (patch) | |
tree | 208e77fd95237c1d6e525861179826d445012766 | |
parent | e32103ad7e944ccbebef4335333481e565311f5c (diff) |
move protocol flags to the handler, add a pointer to the handler in the proto state, add PROTO_FLAG_NODEV
-rw-r--r-- | proto-shell.c | 2 | ||||
-rw-r--r-- | proto-static.c | 4 | ||||
-rw-r--r-- | proto.c | 11 | ||||
-rw-r--r-- | proto.h | 7 |
4 files changed, 14 insertions, 10 deletions
diff --git a/proto-shell.c b/proto-shell.c index 281debc..d014b43 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -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; - 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; diff --git a/proto-static.c b/proto-static.c index 3734f09..bbe304b 100644 --- a/proto-static.c +++ b/proto-static.c @@ -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; - state->proto.handler = static_handler; - state->proto.flags = PROTO_FLAG_IMMEDIATE; + state->proto.cb = static_handler; return &state->proto; @@ -253,6 +252,7 @@ error: static struct proto_handler static_proto = { .name = "static", + .flags = PROTO_FLAG_IMMEDIATE, .config_params = &static_attr_list, .attach = static_attach, }; @@ -48,14 +48,14 @@ default_proto_attach(const struct proto_handler *h, 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", + .flags = PROTO_FLAG_IMMEDIATE, .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); - state->handler = invalid_proto_handler; + state->cb = invalid_proto_handler; } + state->handler = proto; interface_set_proto_state(iface, state); } @@ -114,8 +115,8 @@ interface_proto_event(struct interface_proto_state *proto, 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) { @@ -17,17 +17,18 @@ enum interface_proto_cmd { enum { PROTO_FLAG_IMMEDIATE = (1 << 0), + PROTO_FLAG_NODEV = (1 << 1), }; struct interface_proto_state { + const struct proto_handler *handler; 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 */ - 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 *); }; @@ -35,6 +36,8 @@ struct interface_proto_state { struct proto_handler { struct avl_node avl; + unsigned int flags; + const char *name; const struct config_param_list *config_params; |