move immediate protocol state transitions to a wrapper function
[project/netifd.git] / proto.c
diff --git a/proto.c b/proto.c
index 287eae5f95fe2f807e54a26b51b192e786f72323..b16600ce749ab06ed2bbce301faddc99049d4d5a 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -15,8 +15,31 @@ default_proto_free(struct interface_proto_state *proto)
 static int
 default_proto_handler(struct interface_proto_state *proto,
                      enum interface_proto_cmd cmd, bool force)
+{
+       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;
+       proto->flags = PROTO_FLAG_IMMEDIATE;
+
+       return proto;
+}
+
+int interface_proto_event(struct interface_proto_state *proto,
+                         enum interface_proto_cmd cmd, bool force)
 {
        enum interface_event ev;
+       int ret;
+
+       ret = proto->handler(proto, cmd, force);
+       if (ret || !(proto->flags & PROTO_FLAG_IMMEDIATE))
+               goto out;
 
        switch(cmd) {
        case PROTO_CMD_SETUP:
@@ -29,15 +52,7 @@ default_proto_handler(struct interface_proto_state *proto,
                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;
+out:
+       return ret;
 }