interface: report link up events for force_link interfaces
[project/netifd.git] / proto.c
diff --git a/proto.c b/proto.c
index 64be308..45eeb4b 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -101,6 +101,9 @@ alloc_device_addr(bool v6, bool ext)
        struct device_addr *addr;
 
        addr = calloc(1, sizeof(*addr));
+       if (!addr)
+               return NULL;
+
        addr->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
        if (ext)
                addr->flags |= DEVADDR_EXTERNAL;
@@ -262,6 +265,9 @@ parse_gateway_option(struct interface *iface, struct blob_attr *attr, bool v6)
        int af = v6 ? AF_INET6 : AF_INET;
 
        route = calloc(1, sizeof(*route));
+       if (!route)
+               return NULL;
+
        if (!inet_pton(af, str, &route->nexthop)) {
                interface_add_error(iface, "proto", "INVALID_GATEWAY", &str, 1);
                free(route);
@@ -270,6 +276,7 @@ parse_gateway_option(struct interface *iface, struct blob_attr *attr, bool v6)
 
        route->mask = 0;
        route->flags = (v6 ? DEVADDR_INET6 : DEVADDR_INET4);
+       route->metric = iface->metric;
 
        unsigned int table = (v6) ? iface->ip6table : iface->ip4table;
        if (table) {
@@ -286,7 +293,7 @@ static bool
 parse_prefix_option(struct interface *iface, const char *str, size_t len)
 {
        char buf[128] = {0}, *saveptr;
-       if (len > sizeof(buf))
+       if (len >= sizeof(buf))
                return false;
 
        memcpy(buf, str, len);
@@ -513,6 +520,9 @@ default_proto_attach(const struct proto_handler *h,
        struct interface_proto_state *proto;
 
        proto = calloc(1, sizeof(*proto));
+       if (!proto)
+               return NULL;
+
        proto->free = default_proto_free;
        proto->cb = no_proto_handler;
 
@@ -585,16 +595,20 @@ void
 proto_attach_interface(struct interface *iface, const char *proto_name)
 {
        const struct proto_handler *proto = &no_proto;
+       const char *error = NULL;
 
        if (proto_name) {
                proto = get_proto_handler(proto_name);
                if (!proto) {
-                       interface_add_error(iface, "proto", "INVALID_PROTO", NULL, 0);
+                       error = "INVALID_PROTO";
                        proto = &no_proto;
                }
        }
 
        iface->proto_handler = proto;
+
+       if (error)
+               interface_add_error(iface, "proto", error, NULL, 0);
 }
 
 int
@@ -615,6 +629,9 @@ interface_proto_event(struct interface_proto_state *proto,
        case PROTO_CMD_TEARDOWN:
                ev = IFPEV_DOWN;
                break;
+       case PROTO_CMD_RENEW:
+               ev = IFPEV_RENEW;
+               break;
        default:
                return -EINVAL;
        }