interface: don't segfault with an unknown protocol
[project/netifd.git] / interface.c
index 72ecf4d..60efc7e 100644 (file)
@@ -185,6 +185,13 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
 
                mark_interface_down(iface);
                break;
+       case IFPEV_LINK_LOST:
+               if (iface->state != IFS_UP)
+                       return;
+
+               iface->state = IFS_SETUP;
+               interface_event(iface, IFEV_DOWN);
+               break;
        }
 }
 
@@ -234,7 +241,8 @@ interface_alloc(const char *name, struct blob_attr *attr)
 
        proto_attach_interface(iface, proto_name);
 
-       if (!(iface->proto_handler->flags & PROTO_FLAG_NODEV) &&
+       if (iface->proto_handler &&
+           !(iface->proto_handler->flags & PROTO_FLAG_NODEV) &&
            (cur = tb[IFACE_ATTR_IFNAME])) {
                dev = device_get(blobmsg_data(cur), true);
                if (dev)